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 const char *old_mode, *new_mode;
757 if ((condition_evaluation_mode_1 == condition_evaluation_target)
758 && !target_supports_evaluation_of_breakpoint_conditions ())
760 condition_evaluation_mode_1 = condition_evaluation_mode;
761 warning (_("Target does not support breakpoint condition evaluation.\n"
762 "Using host evaluation mode instead."));
766 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
767 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
769 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
770 settings was "auto". */
771 condition_evaluation_mode = condition_evaluation_mode_1;
773 /* Only update the mode if the user picked a different one. */
774 if (new_mode != old_mode)
776 struct bp_location *loc, **loc_tmp;
777 /* If the user switched to a different evaluation mode, we
778 need to synch the changes with the target as follows:
780 "host" -> "target": Send all (valid) conditions to the target.
781 "target" -> "host": Remove all the conditions from the target.
784 if (new_mode == condition_evaluation_target)
786 /* Mark everything modified and synch conditions with the
788 ALL_BP_LOCATIONS (loc, loc_tmp)
789 mark_breakpoint_location_modified (loc);
793 /* Manually mark non-duplicate locations to synch conditions
794 with the target. We do this to remove all the conditions the
795 target knows about. */
796 ALL_BP_LOCATIONS (loc, loc_tmp)
797 if (is_breakpoint (loc->owner) && loc->inserted)
798 loc->needs_update = 1;
802 update_global_location_list (1);
808 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
809 what "auto" is translating to. */
812 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
813 struct cmd_list_element *c, const char *value)
815 if (condition_evaluation_mode == condition_evaluation_auto)
816 fprintf_filtered (file,
817 _("Breakpoint condition evaluation "
818 "mode is %s (currently %s).\n"),
820 breakpoint_condition_evaluation_mode ());
822 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
826 /* A comparison function for bp_location AP and BP that is used by
827 bsearch. This comparison function only cares about addresses, unlike
828 the more general bp_location_compare function. */
831 bp_location_compare_addrs (const void *ap, const void *bp)
833 struct bp_location *a = *(void **) ap;
834 struct bp_location *b = *(void **) bp;
836 if (a->address == b->address)
839 return ((a->address > b->address) - (a->address < b->address));
842 /* Helper function to skip all bp_locations with addresses
843 less than ADDRESS. It returns the first bp_location that
844 is greater than or equal to ADDRESS. If none is found, just
847 static struct bp_location **
848 get_first_locp_gte_addr (CORE_ADDR address)
850 struct bp_location dummy_loc;
851 struct bp_location *dummy_locp = &dummy_loc;
852 struct bp_location **locp_found = NULL;
854 /* Initialize the dummy location's address field. */
855 memset (&dummy_loc, 0, sizeof (struct bp_location));
856 dummy_loc.address = address;
858 /* Find a close match to the first location at ADDRESS. */
859 locp_found = bsearch (&dummy_locp, bp_location, bp_location_count,
860 sizeof (struct bp_location **),
861 bp_location_compare_addrs);
863 /* Nothing was found, nothing left to do. */
864 if (locp_found == NULL)
867 /* We may have found a location that is at ADDRESS but is not the first in the
868 location's list. Go backwards (if possible) and locate the first one. */
869 while ((locp_found - 1) >= bp_location
870 && (*(locp_found - 1))->address == address)
877 set_breakpoint_condition (struct breakpoint *b, char *exp,
880 xfree (b->cond_string);
881 b->cond_string = NULL;
883 if (is_watchpoint (b))
885 struct watchpoint *w = (struct watchpoint *) b;
892 struct bp_location *loc;
894 for (loc = b->loc; loc; loc = loc->next)
899 /* No need to free the condition agent expression
900 bytecode (if we have one). We will handle this
901 when we go through update_global_location_list. */
908 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
914 /* I don't know if it matters whether this is the string the user
915 typed in or the decompiled expression. */
916 b->cond_string = xstrdup (arg);
917 b->condition_not_parsed = 0;
919 if (is_watchpoint (b))
921 struct watchpoint *w = (struct watchpoint *) b;
923 innermost_block = NULL;
925 w->cond_exp = parse_exp_1 (&arg, 0, 0);
927 error (_("Junk at end of expression"));
928 w->cond_exp_valid_block = innermost_block;
932 struct bp_location *loc;
934 for (loc = b->loc; loc; loc = loc->next)
938 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
940 error (_("Junk at end of expression"));
944 mark_breakpoint_modified (b);
946 breakpoints_changed ();
947 observer_notify_breakpoint_modified (b);
950 /* condition N EXP -- set break condition of breakpoint N to EXP. */
953 condition_command (char *arg, int from_tty)
955 struct breakpoint *b;
960 error_no_arg (_("breakpoint number"));
963 bnum = get_number (&p);
965 error (_("Bad breakpoint argument: '%s'"), arg);
968 if (b->number == bnum)
970 /* Check if this breakpoint has a Python object assigned to
971 it, and if it has a definition of the "stop"
972 method. This method and conditions entered into GDB from
973 the CLI are mutually exclusive. */
975 && gdbpy_breakpoint_has_py_cond (b->py_bp_object))
976 error (_("Cannot set a condition where a Python 'stop' "
977 "method has been defined in the breakpoint."));
978 set_breakpoint_condition (b, p, from_tty);
980 if (is_breakpoint (b))
981 update_global_location_list (1);
986 error (_("No breakpoint number %d."), bnum);
989 /* Check that COMMAND do not contain commands that are suitable
990 only for tracepoints and not suitable for ordinary breakpoints.
991 Throw if any such commands is found. */
994 check_no_tracepoint_commands (struct command_line *commands)
996 struct command_line *c;
998 for (c = commands; c; c = c->next)
1002 if (c->control_type == while_stepping_control)
1003 error (_("The 'while-stepping' command can "
1004 "only be used for tracepoints"));
1006 for (i = 0; i < c->body_count; ++i)
1007 check_no_tracepoint_commands ((c->body_list)[i]);
1009 /* Not that command parsing removes leading whitespace and comment
1010 lines and also empty lines. So, we only need to check for
1011 command directly. */
1012 if (strstr (c->line, "collect ") == c->line)
1013 error (_("The 'collect' command can only be used for tracepoints"));
1015 if (strstr (c->line, "teval ") == c->line)
1016 error (_("The 'teval' command can only be used for tracepoints"));
1020 /* Encapsulate tests for different types of tracepoints. */
1023 is_tracepoint_type (enum bptype type)
1025 return (type == bp_tracepoint
1026 || type == bp_fast_tracepoint
1027 || type == bp_static_tracepoint);
1031 is_tracepoint (const struct breakpoint *b)
1033 return is_tracepoint_type (b->type);
1036 /* A helper function that validates that COMMANDS are valid for a
1037 breakpoint. This function will throw an exception if a problem is
1041 validate_commands_for_breakpoint (struct breakpoint *b,
1042 struct command_line *commands)
1044 if (is_tracepoint (b))
1046 /* We need to verify that each top-level element of commands is
1047 valid for tracepoints, that there's at most one
1048 while-stepping element, and that while-stepping's body has
1049 valid tracing commands excluding nested while-stepping. */
1050 struct command_line *c;
1051 struct command_line *while_stepping = 0;
1052 for (c = commands; c; c = c->next)
1054 if (c->control_type == while_stepping_control)
1056 if (b->type == bp_fast_tracepoint)
1057 error (_("The 'while-stepping' command "
1058 "cannot be used for fast tracepoint"));
1059 else if (b->type == bp_static_tracepoint)
1060 error (_("The 'while-stepping' command "
1061 "cannot be used for static tracepoint"));
1064 error (_("The 'while-stepping' command "
1065 "can be used only once"));
1072 struct command_line *c2;
1074 gdb_assert (while_stepping->body_count == 1);
1075 c2 = while_stepping->body_list[0];
1076 for (; c2; c2 = c2->next)
1078 if (c2->control_type == while_stepping_control)
1079 error (_("The 'while-stepping' command cannot be nested"));
1085 check_no_tracepoint_commands (commands);
1089 /* Return a vector of all the static tracepoints set at ADDR. The
1090 caller is responsible for releasing the vector. */
1093 static_tracepoints_here (CORE_ADDR addr)
1095 struct breakpoint *b;
1096 VEC(breakpoint_p) *found = 0;
1097 struct bp_location *loc;
1100 if (b->type == bp_static_tracepoint)
1102 for (loc = b->loc; loc; loc = loc->next)
1103 if (loc->address == addr)
1104 VEC_safe_push(breakpoint_p, found, b);
1110 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1111 validate that only allowed commands are included. */
1114 breakpoint_set_commands (struct breakpoint *b,
1115 struct command_line *commands)
1117 validate_commands_for_breakpoint (b, commands);
1119 decref_counted_command_line (&b->commands);
1120 b->commands = alloc_counted_command_line (commands);
1121 breakpoints_changed ();
1122 observer_notify_breakpoint_modified (b);
1125 /* Set the internal `silent' flag on the breakpoint. Note that this
1126 is not the same as the "silent" that may appear in the breakpoint's
1130 breakpoint_set_silent (struct breakpoint *b, int silent)
1132 int old_silent = b->silent;
1135 if (old_silent != silent)
1136 observer_notify_breakpoint_modified (b);
1139 /* Set the thread for this breakpoint. If THREAD is -1, make the
1140 breakpoint work for any thread. */
1143 breakpoint_set_thread (struct breakpoint *b, int thread)
1145 int old_thread = b->thread;
1148 if (old_thread != thread)
1149 observer_notify_breakpoint_modified (b);
1152 /* Set the task for this breakpoint. If TASK is 0, make the
1153 breakpoint work for any task. */
1156 breakpoint_set_task (struct breakpoint *b, int task)
1158 int old_task = b->task;
1161 if (old_task != task)
1162 observer_notify_breakpoint_modified (b);
1166 check_tracepoint_command (char *line, void *closure)
1168 struct breakpoint *b = closure;
1170 validate_actionline (&line, b);
1173 /* A structure used to pass information through
1174 map_breakpoint_numbers. */
1176 struct commands_info
1178 /* True if the command was typed at a tty. */
1181 /* The breakpoint range spec. */
1184 /* Non-NULL if the body of the commands are being read from this
1185 already-parsed command. */
1186 struct command_line *control;
1188 /* The command lines read from the user, or NULL if they have not
1190 struct counted_command_line *cmd;
1193 /* A callback for map_breakpoint_numbers that sets the commands for
1194 commands_command. */
1197 do_map_commands_command (struct breakpoint *b, void *data)
1199 struct commands_info *info = data;
1201 if (info->cmd == NULL)
1203 struct command_line *l;
1205 if (info->control != NULL)
1206 l = copy_command_lines (info->control->body_list[0]);
1209 struct cleanup *old_chain;
1212 str = xstrprintf (_("Type commands for breakpoint(s) "
1213 "%s, one per line."),
1216 old_chain = make_cleanup (xfree, str);
1218 l = read_command_lines (str,
1221 ? check_tracepoint_command : 0),
1224 do_cleanups (old_chain);
1227 info->cmd = alloc_counted_command_line (l);
1230 /* If a breakpoint was on the list more than once, we don't need to
1232 if (b->commands != info->cmd)
1234 validate_commands_for_breakpoint (b, info->cmd->commands);
1235 incref_counted_command_line (info->cmd);
1236 decref_counted_command_line (&b->commands);
1237 b->commands = info->cmd;
1238 breakpoints_changed ();
1239 observer_notify_breakpoint_modified (b);
1244 commands_command_1 (char *arg, int from_tty,
1245 struct command_line *control)
1247 struct cleanup *cleanups;
1248 struct commands_info info;
1250 info.from_tty = from_tty;
1251 info.control = control;
1253 /* If we read command lines from the user, then `info' will hold an
1254 extra reference to the commands that we must clean up. */
1255 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1257 if (arg == NULL || !*arg)
1259 if (breakpoint_count - prev_breakpoint_count > 1)
1260 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1262 else if (breakpoint_count > 0)
1263 arg = xstrprintf ("%d", breakpoint_count);
1266 /* So that we don't try to free the incoming non-NULL
1267 argument in the cleanup below. Mapping breakpoint
1268 numbers will fail in this case. */
1273 /* The command loop has some static state, so we need to preserve
1275 arg = xstrdup (arg);
1278 make_cleanup (xfree, arg);
1282 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1284 if (info.cmd == NULL)
1285 error (_("No breakpoints specified."));
1287 do_cleanups (cleanups);
1291 commands_command (char *arg, int from_tty)
1293 commands_command_1 (arg, from_tty, NULL);
1296 /* Like commands_command, but instead of reading the commands from
1297 input stream, takes them from an already parsed command structure.
1299 This is used by cli-script.c to DTRT with breakpoint commands
1300 that are part of if and while bodies. */
1301 enum command_control_type
1302 commands_from_control_command (char *arg, struct command_line *cmd)
1304 commands_command_1 (arg, 0, cmd);
1305 return simple_control;
1308 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1311 bp_location_has_shadow (struct bp_location *bl)
1313 if (bl->loc_type != bp_loc_software_breakpoint)
1317 if (bl->target_info.shadow_len == 0)
1318 /* BL isn't valid, or doesn't shadow memory. */
1323 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1324 by replacing any memory breakpoints with their shadowed contents.
1326 If READBUF is not NULL, this buffer must not overlap with any of
1327 the breakpoint location's shadow_contents buffers. Otherwise,
1328 a failed assertion internal error will be raised.
1330 The range of shadowed area by each bp_location is:
1331 bl->address - bp_location_placed_address_before_address_max
1332 up to bl->address + bp_location_shadow_len_after_address_max
1333 The range we were requested to resolve shadows for is:
1334 memaddr ... memaddr + len
1335 Thus the safe cutoff boundaries for performance optimization are
1336 memaddr + len <= (bl->address
1337 - bp_location_placed_address_before_address_max)
1339 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1342 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1343 const gdb_byte *writebuf_org,
1344 ULONGEST memaddr, LONGEST len)
1346 /* Left boundary, right boundary and median element of our binary
1348 unsigned bc_l, bc_r, bc;
1350 /* Find BC_L which is a leftmost element which may affect BUF
1351 content. It is safe to report lower value but a failure to
1352 report higher one. */
1355 bc_r = bp_location_count;
1356 while (bc_l + 1 < bc_r)
1358 struct bp_location *bl;
1360 bc = (bc_l + bc_r) / 2;
1361 bl = bp_location[bc];
1363 /* Check first BL->ADDRESS will not overflow due to the added
1364 constant. Then advance the left boundary only if we are sure
1365 the BC element can in no way affect the BUF content (MEMADDR
1366 to MEMADDR + LEN range).
1368 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1369 offset so that we cannot miss a breakpoint with its shadow
1370 range tail still reaching MEMADDR. */
1372 if ((bl->address + bp_location_shadow_len_after_address_max
1374 && (bl->address + bp_location_shadow_len_after_address_max
1381 /* Due to the binary search above, we need to make sure we pick the
1382 first location that's at BC_L's address. E.g., if there are
1383 multiple locations at the same address, BC_L may end up pointing
1384 at a duplicate location, and miss the "master"/"inserted"
1385 location. Say, given locations L1, L2 and L3 at addresses A and
1388 L1@A, L2@A, L3@B, ...
1390 BC_L could end up pointing at location L2, while the "master"
1391 location could be L1. Since the `loc->inserted' flag is only set
1392 on "master" locations, we'd forget to restore the shadow of L1
1395 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1398 /* Now do full processing of the found relevant range of elements. */
1400 for (bc = bc_l; bc < bp_location_count; bc++)
1402 struct bp_location *bl = bp_location[bc];
1403 CORE_ADDR bp_addr = 0;
1407 /* bp_location array has BL->OWNER always non-NULL. */
1408 if (bl->owner->type == bp_none)
1409 warning (_("reading through apparently deleted breakpoint #%d?"),
1412 /* Performance optimization: any further element can no longer affect BUF
1415 if (bl->address >= bp_location_placed_address_before_address_max
1416 && memaddr + len <= (bl->address
1417 - bp_location_placed_address_before_address_max))
1420 if (!bp_location_has_shadow (bl))
1422 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0,
1423 current_program_space->aspace, 0))
1426 /* Addresses and length of the part of the breakpoint that
1428 bp_addr = bl->target_info.placed_address;
1429 bp_size = bl->target_info.shadow_len;
1431 if (bp_addr + bp_size <= memaddr)
1432 /* The breakpoint is entirely before the chunk of memory we
1436 if (bp_addr >= memaddr + len)
1437 /* The breakpoint is entirely after the chunk of memory we are
1441 /* Offset within shadow_contents. */
1442 if (bp_addr < memaddr)
1444 /* Only copy the second part of the breakpoint. */
1445 bp_size -= memaddr - bp_addr;
1446 bptoffset = memaddr - bp_addr;
1450 if (bp_addr + bp_size > memaddr + len)
1452 /* Only copy the first part of the breakpoint. */
1453 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1456 if (readbuf != NULL)
1458 /* Verify that the readbuf buffer does not overlap with
1459 the shadow_contents buffer. */
1460 gdb_assert (bl->target_info.shadow_contents >= readbuf + len
1461 || readbuf >= (bl->target_info.shadow_contents
1462 + bl->target_info.shadow_len));
1464 /* Update the read buffer with this inserted breakpoint's
1466 memcpy (readbuf + bp_addr - memaddr,
1467 bl->target_info.shadow_contents + bptoffset, bp_size);
1471 struct gdbarch *gdbarch = bl->gdbarch;
1472 const unsigned char *bp;
1473 CORE_ADDR placed_address = bl->target_info.placed_address;
1474 unsigned placed_size = bl->target_info.placed_size;
1476 /* Update the shadow with what we want to write to memory. */
1477 memcpy (bl->target_info.shadow_contents + bptoffset,
1478 writebuf_org + bp_addr - memaddr, bp_size);
1480 /* Determine appropriate breakpoint contents and size for this
1482 bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size);
1484 /* Update the final write buffer with this inserted
1485 breakpoint's INSN. */
1486 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1492 /* Return true if BPT is either a software breakpoint or a hardware
1496 is_breakpoint (const struct breakpoint *bpt)
1498 return (bpt->type == bp_breakpoint
1499 || bpt->type == bp_hardware_breakpoint
1500 || bpt->type == bp_dprintf);
1503 /* Return true if BPT is of any hardware watchpoint kind. */
1506 is_hardware_watchpoint (const struct breakpoint *bpt)
1508 return (bpt->type == bp_hardware_watchpoint
1509 || bpt->type == bp_read_watchpoint
1510 || bpt->type == bp_access_watchpoint);
1513 /* Return true if BPT is of any watchpoint kind, hardware or
1517 is_watchpoint (const struct breakpoint *bpt)
1519 return (is_hardware_watchpoint (bpt)
1520 || bpt->type == bp_watchpoint);
1523 /* Returns true if the current thread and its running state are safe
1524 to evaluate or update watchpoint B. Watchpoints on local
1525 expressions need to be evaluated in the context of the thread that
1526 was current when the watchpoint was created, and, that thread needs
1527 to be stopped to be able to select the correct frame context.
1528 Watchpoints on global expressions can be evaluated on any thread,
1529 and in any state. It is presently left to the target allowing
1530 memory accesses when threads are running. */
1533 watchpoint_in_thread_scope (struct watchpoint *b)
1535 return (b->base.pspace == current_program_space
1536 && (ptid_equal (b->watchpoint_thread, null_ptid)
1537 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1538 && !is_executing (inferior_ptid))));
1541 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1542 associated bp_watchpoint_scope breakpoint. */
1545 watchpoint_del_at_next_stop (struct watchpoint *w)
1547 struct breakpoint *b = &w->base;
1549 if (b->related_breakpoint != b)
1551 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1552 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1553 b->related_breakpoint->disposition = disp_del_at_next_stop;
1554 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1555 b->related_breakpoint = b;
1557 b->disposition = disp_del_at_next_stop;
1560 /* Assuming that B is a watchpoint:
1561 - Reparse watchpoint expression, if REPARSE is non-zero
1562 - Evaluate expression and store the result in B->val
1563 - Evaluate the condition if there is one, and store the result
1565 - Update the list of values that must be watched in B->loc.
1567 If the watchpoint disposition is disp_del_at_next_stop, then do
1568 nothing. If this is local watchpoint that is out of scope, delete
1571 Even with `set breakpoint always-inserted on' the watchpoints are
1572 removed + inserted on each stop here. Normal breakpoints must
1573 never be removed because they might be missed by a running thread
1574 when debugging in non-stop mode. On the other hand, hardware
1575 watchpoints (is_hardware_watchpoint; processed here) are specific
1576 to each LWP since they are stored in each LWP's hardware debug
1577 registers. Therefore, such LWP must be stopped first in order to
1578 be able to modify its hardware watchpoints.
1580 Hardware watchpoints must be reset exactly once after being
1581 presented to the user. It cannot be done sooner, because it would
1582 reset the data used to present the watchpoint hit to the user. And
1583 it must not be done later because it could display the same single
1584 watchpoint hit during multiple GDB stops. Note that the latter is
1585 relevant only to the hardware watchpoint types bp_read_watchpoint
1586 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1587 not user-visible - its hit is suppressed if the memory content has
1590 The following constraints influence the location where we can reset
1591 hardware watchpoints:
1593 * target_stopped_by_watchpoint and target_stopped_data_address are
1594 called several times when GDB stops.
1597 * Multiple hardware watchpoints can be hit at the same time,
1598 causing GDB to stop. GDB only presents one hardware watchpoint
1599 hit at a time as the reason for stopping, and all the other hits
1600 are presented later, one after the other, each time the user
1601 requests the execution to be resumed. Execution is not resumed
1602 for the threads still having pending hit event stored in
1603 LWP_INFO->STATUS. While the watchpoint is already removed from
1604 the inferior on the first stop the thread hit event is kept being
1605 reported from its cached value by linux_nat_stopped_data_address
1606 until the real thread resume happens after the watchpoint gets
1607 presented and thus its LWP_INFO->STATUS gets reset.
1609 Therefore the hardware watchpoint hit can get safely reset on the
1610 watchpoint removal from inferior. */
1613 update_watchpoint (struct watchpoint *b, int reparse)
1615 int within_current_scope;
1616 struct frame_id saved_frame_id;
1619 /* If this is a local watchpoint, we only want to check if the
1620 watchpoint frame is in scope if the current thread is the thread
1621 that was used to create the watchpoint. */
1622 if (!watchpoint_in_thread_scope (b))
1625 if (b->base.disposition == disp_del_at_next_stop)
1630 /* Determine if the watchpoint is within scope. */
1631 if (b->exp_valid_block == NULL)
1632 within_current_scope = 1;
1635 struct frame_info *fi = get_current_frame ();
1636 struct gdbarch *frame_arch = get_frame_arch (fi);
1637 CORE_ADDR frame_pc = get_frame_pc (fi);
1639 /* If we're in a function epilogue, unwinding may not work
1640 properly, so do not attempt to recreate locations at this
1641 point. See similar comments in watchpoint_check. */
1642 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1645 /* Save the current frame's ID so we can restore it after
1646 evaluating the watchpoint expression on its own frame. */
1647 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1648 took a frame parameter, so that we didn't have to change the
1651 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1653 fi = frame_find_by_id (b->watchpoint_frame);
1654 within_current_scope = (fi != NULL);
1655 if (within_current_scope)
1659 /* We don't free locations. They are stored in the bp_location array
1660 and update_global_location_list will eventually delete them and
1661 remove breakpoints if needed. */
1664 if (within_current_scope && reparse)
1673 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1674 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
1675 /* If the meaning of expression itself changed, the old value is
1676 no longer relevant. We don't want to report a watchpoint hit
1677 to the user when the old value and the new value may actually
1678 be completely different objects. */
1679 value_free (b->val);
1683 /* Note that unlike with breakpoints, the watchpoint's condition
1684 expression is stored in the breakpoint object, not in the
1685 locations (re)created below. */
1686 if (b->base.cond_string != NULL)
1688 if (b->cond_exp != NULL)
1690 xfree (b->cond_exp);
1694 s = b->base.cond_string;
1695 b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0);
1699 /* If we failed to parse the expression, for example because
1700 it refers to a global variable in a not-yet-loaded shared library,
1701 don't try to insert watchpoint. We don't automatically delete
1702 such watchpoint, though, since failure to parse expression
1703 is different from out-of-scope watchpoint. */
1704 if ( !target_has_execution)
1706 /* Without execution, memory can't change. No use to try and
1707 set watchpoint locations. The watchpoint will be reset when
1708 the target gains execution, through breakpoint_re_set. */
1710 else if (within_current_scope && b->exp)
1713 struct value *val_chain, *v, *result, *next;
1714 struct program_space *frame_pspace;
1716 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain);
1718 /* Avoid setting b->val if it's already set. The meaning of
1719 b->val is 'the last value' user saw, and we should update
1720 it only if we reported that last value to user. As it
1721 happens, the code that reports it updates b->val directly.
1722 We don't keep track of the memory value for masked
1724 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1730 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1732 /* Look at each value on the value chain. */
1733 for (v = val_chain; v; v = value_next (v))
1735 /* If it's a memory location, and GDB actually needed
1736 its contents to evaluate the expression, then we
1737 must watch it. If the first value returned is
1738 still lazy, that means an error occurred reading it;
1739 watch it anyway in case it becomes readable. */
1740 if (VALUE_LVAL (v) == lval_memory
1741 && (v == val_chain || ! value_lazy (v)))
1743 struct type *vtype = check_typedef (value_type (v));
1745 /* We only watch structs and arrays if user asked
1746 for it explicitly, never if they just happen to
1747 appear in the middle of some value chain. */
1749 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1750 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1754 struct bp_location *loc, **tmp;
1756 addr = value_address (v);
1757 len = TYPE_LENGTH (value_type (v));
1759 if (b->base.type == bp_read_watchpoint)
1761 else if (b->base.type == bp_access_watchpoint)
1764 loc = allocate_bp_location (&b->base);
1765 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
1768 loc->gdbarch = get_type_arch (value_type (v));
1770 loc->pspace = frame_pspace;
1771 loc->address = addr;
1773 loc->watchpoint_type = type;
1778 /* Change the type of breakpoint between hardware assisted or
1779 an ordinary watchpoint depending on the hardware support
1780 and free hardware slots. REPARSE is set when the inferior
1785 enum bp_loc_type loc_type;
1786 struct bp_location *bl;
1788 reg_cnt = can_use_hardware_watchpoint (val_chain);
1792 int i, target_resources_ok, other_type_used;
1795 /* Use an exact watchpoint when there's only one memory region to be
1796 watched, and only one debug register is needed to watch it. */
1797 b->exact = target_exact_watchpoints && reg_cnt == 1;
1799 /* We need to determine how many resources are already
1800 used for all other hardware watchpoints plus this one
1801 to see if we still have enough resources to also fit
1802 this watchpoint in as well. */
1804 /* If this is a software watchpoint, we try to turn it
1805 to a hardware one -- count resources as if B was of
1806 hardware watchpoint type. */
1807 type = b->base.type;
1808 if (type == bp_watchpoint)
1809 type = bp_hardware_watchpoint;
1811 /* This watchpoint may or may not have been placed on
1812 the list yet at this point (it won't be in the list
1813 if we're trying to create it for the first time,
1814 through watch_command), so always account for it
1817 /* Count resources used by all watchpoints except B. */
1818 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
1820 /* Add in the resources needed for B. */
1821 i += hw_watchpoint_use_count (&b->base);
1824 = target_can_use_hardware_watchpoint (type, i, other_type_used);
1825 if (target_resources_ok <= 0)
1827 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
1829 if (target_resources_ok == 0 && !sw_mode)
1830 error (_("Target does not support this type of "
1831 "hardware watchpoint."));
1832 else if (target_resources_ok < 0 && !sw_mode)
1833 error (_("There are not enough available hardware "
1834 "resources for this watchpoint."));
1836 /* Downgrade to software watchpoint. */
1837 b->base.type = bp_watchpoint;
1841 /* If this was a software watchpoint, we've just
1842 found we have enough resources to turn it to a
1843 hardware watchpoint. Otherwise, this is a
1845 b->base.type = type;
1848 else if (!b->base.ops->works_in_software_mode (&b->base))
1849 error (_("Expression cannot be implemented with "
1850 "read/access watchpoint."));
1852 b->base.type = bp_watchpoint;
1854 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
1855 : bp_loc_hardware_watchpoint);
1856 for (bl = b->base.loc; bl; bl = bl->next)
1857 bl->loc_type = loc_type;
1860 for (v = val_chain; v; v = next)
1862 next = value_next (v);
1867 /* If a software watchpoint is not watching any memory, then the
1868 above left it without any location set up. But,
1869 bpstat_stop_status requires a location to be able to report
1870 stops, so make sure there's at least a dummy one. */
1871 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
1873 struct breakpoint *base = &b->base;
1874 base->loc = allocate_bp_location (base);
1875 base->loc->pspace = frame_pspace;
1876 base->loc->address = -1;
1877 base->loc->length = -1;
1878 base->loc->watchpoint_type = -1;
1881 else if (!within_current_scope)
1883 printf_filtered (_("\
1884 Watchpoint %d deleted because the program has left the block\n\
1885 in which its expression is valid.\n"),
1887 watchpoint_del_at_next_stop (b);
1890 /* Restore the selected frame. */
1892 select_frame (frame_find_by_id (saved_frame_id));
1896 /* Returns 1 iff breakpoint location should be
1897 inserted in the inferior. We don't differentiate the type of BL's owner
1898 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1899 breakpoint_ops is not defined, because in insert_bp_location,
1900 tracepoint's insert_location will not be called. */
1902 should_be_inserted (struct bp_location *bl)
1904 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
1907 if (bl->owner->disposition == disp_del_at_next_stop)
1910 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
1913 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
1916 /* This is set for example, when we're attached to the parent of a
1917 vfork, and have detached from the child. The child is running
1918 free, and we expect it to do an exec or exit, at which point the
1919 OS makes the parent schedulable again (and the target reports
1920 that the vfork is done). Until the child is done with the shared
1921 memory region, do not insert breakpoints in the parent, otherwise
1922 the child could still trip on the parent's breakpoints. Since
1923 the parent is blocked anyway, it won't miss any breakpoint. */
1924 if (bl->pspace->breakpoints_not_allowed)
1930 /* Same as should_be_inserted but does the check assuming
1931 that the location is not duplicated. */
1934 unduplicated_should_be_inserted (struct bp_location *bl)
1937 const int save_duplicate = bl->duplicate;
1940 result = should_be_inserted (bl);
1941 bl->duplicate = save_duplicate;
1945 /* Parses a conditional described by an expression COND into an
1946 agent expression bytecode suitable for evaluation
1947 by the bytecode interpreter. Return NULL if there was
1948 any error during parsing. */
1950 static struct agent_expr *
1951 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
1953 struct agent_expr *aexpr = NULL;
1954 struct cleanup *old_chain = NULL;
1955 volatile struct gdb_exception ex;
1960 /* We don't want to stop processing, so catch any errors
1961 that may show up. */
1962 TRY_CATCH (ex, RETURN_MASK_ERROR)
1964 aexpr = gen_eval_for_expr (scope, cond);
1969 /* If we got here, it means the condition could not be parsed to a valid
1970 bytecode expression and thus can't be evaluated on the target's side.
1971 It's no use iterating through the conditions. */
1975 /* We have a valid agent expression. */
1979 /* Based on location BL, create a list of breakpoint conditions to be
1980 passed on to the target. If we have duplicated locations with different
1981 conditions, we will add such conditions to the list. The idea is that the
1982 target will evaluate the list of conditions and will only notify GDB when
1983 one of them is true. */
1986 build_target_condition_list (struct bp_location *bl)
1988 struct bp_location **locp = NULL, **loc2p;
1989 int null_condition_or_parse_error = 0;
1990 int modified = bl->needs_update;
1991 struct bp_location *loc;
1993 /* This is only meaningful if the target is
1994 evaluating conditions and if the user has
1995 opted for condition evaluation on the target's
1997 if (gdb_evaluates_breakpoint_condition_p ()
1998 || !target_supports_evaluation_of_breakpoint_conditions ())
2001 /* Do a first pass to check for locations with no assigned
2002 conditions or conditions that fail to parse to a valid agent expression
2003 bytecode. If any of these happen, then it's no use to send conditions
2004 to the target since this location will always trigger and generate a
2005 response back to GDB. */
2006 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2009 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2013 struct agent_expr *aexpr;
2015 /* Re-parse the conditions since something changed. In that
2016 case we already freed the condition bytecodes (see
2017 force_breakpoint_reinsertion). We just
2018 need to parse the condition to bytecodes again. */
2019 aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2020 loc->cond_bytecode = aexpr;
2022 /* Check if we managed to parse the conditional expression
2023 correctly. If not, we will not send this condition
2029 /* If we have a NULL bytecode expression, it means something
2030 went wrong or we have a null condition expression. */
2031 if (!loc->cond_bytecode)
2033 null_condition_or_parse_error = 1;
2039 /* If any of these happened, it means we will have to evaluate the conditions
2040 for the location's address on gdb's side. It is no use keeping bytecodes
2041 for all the other duplicate locations, thus we free all of them here.
2043 This is so we have a finer control over which locations' conditions are
2044 being evaluated by GDB or the remote stub. */
2045 if (null_condition_or_parse_error)
2047 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2050 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2052 /* Only go as far as the first NULL bytecode is
2054 if (!loc->cond_bytecode)
2057 free_agent_expr (loc->cond_bytecode);
2058 loc->cond_bytecode = NULL;
2063 /* No NULL conditions or failed bytecode generation. Build a condition list
2064 for this location's address. */
2065 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2069 && is_breakpoint (loc->owner)
2070 && loc->pspace->num == bl->pspace->num
2071 && loc->owner->enable_state == bp_enabled
2073 /* Add the condition to the vector. This will be used later to send the
2074 conditions to the target. */
2075 VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2076 loc->cond_bytecode);
2082 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2083 location. Any error messages are printed to TMP_ERROR_STREAM; and
2084 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2085 Returns 0 for success, 1 if the bp_location type is not supported or
2088 NOTE drow/2003-09-09: This routine could be broken down to an
2089 object-style method for each breakpoint or catchpoint type. */
2091 insert_bp_location (struct bp_location *bl,
2092 struct ui_file *tmp_error_stream,
2093 int *disabled_breaks,
2094 int *hw_breakpoint_error)
2098 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2101 /* Note we don't initialize bl->target_info, as that wipes out
2102 the breakpoint location's shadow_contents if the breakpoint
2103 is still inserted at that location. This in turn breaks
2104 target_read_memory which depends on these buffers when
2105 a memory read is requested at the breakpoint location:
2106 Once the target_info has been wiped, we fail to see that
2107 we have a breakpoint inserted at that address and thus
2108 read the breakpoint instead of returning the data saved in
2109 the breakpoint location's shadow contents. */
2110 bl->target_info.placed_address = bl->address;
2111 bl->target_info.placed_address_space = bl->pspace->aspace;
2112 bl->target_info.length = bl->length;
2114 /* When working with target-side conditions, we must pass all the conditions
2115 for the same breakpoint address down to the target since GDB will not
2116 insert those locations. With a list of breakpoint conditions, the target
2117 can decide when to stop and notify GDB. */
2119 if (is_breakpoint (bl->owner))
2121 build_target_condition_list (bl);
2122 /* Reset the condition modification marker. */
2123 bl->needs_update = 0;
2126 if (bl->loc_type == bp_loc_software_breakpoint
2127 || bl->loc_type == bp_loc_hardware_breakpoint)
2129 if (bl->owner->type != bp_hardware_breakpoint)
2131 /* If the explicitly specified breakpoint type
2132 is not hardware breakpoint, check the memory map to see
2133 if the breakpoint address is in read only memory or not.
2135 Two important cases are:
2136 - location type is not hardware breakpoint, memory
2137 is readonly. We change the type of the location to
2138 hardware breakpoint.
2139 - location type is hardware breakpoint, memory is
2140 read-write. This means we've previously made the
2141 location hardware one, but then the memory map changed,
2144 When breakpoints are removed, remove_breakpoints will use
2145 location types we've just set here, the only possible
2146 problem is that memory map has changed during running
2147 program, but it's not going to work anyway with current
2149 struct mem_region *mr
2150 = lookup_mem_region (bl->target_info.placed_address);
2154 if (automatic_hardware_breakpoints)
2156 enum bp_loc_type new_type;
2158 if (mr->attrib.mode != MEM_RW)
2159 new_type = bp_loc_hardware_breakpoint;
2161 new_type = bp_loc_software_breakpoint;
2163 if (new_type != bl->loc_type)
2165 static int said = 0;
2167 bl->loc_type = new_type;
2170 fprintf_filtered (gdb_stdout,
2171 _("Note: automatically using "
2172 "hardware breakpoints for "
2173 "read-only addresses.\n"));
2178 else if (bl->loc_type == bp_loc_software_breakpoint
2179 && mr->attrib.mode != MEM_RW)
2180 warning (_("cannot set software breakpoint "
2181 "at readonly address %s"),
2182 paddress (bl->gdbarch, bl->address));
2186 /* First check to see if we have to handle an overlay. */
2187 if (overlay_debugging == ovly_off
2188 || bl->section == NULL
2189 || !(section_is_overlay (bl->section)))
2191 /* No overlay handling: just set the breakpoint. */
2193 val = bl->owner->ops->insert_location (bl);
2197 /* This breakpoint is in an overlay section.
2198 Shall we set a breakpoint at the LMA? */
2199 if (!overlay_events_enabled)
2201 /* Yes -- overlay event support is not active,
2202 so we must try to set a breakpoint at the LMA.
2203 This will not work for a hardware breakpoint. */
2204 if (bl->loc_type == bp_loc_hardware_breakpoint)
2205 warning (_("hardware breakpoint %d not supported in overlay!"),
2209 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2211 /* Set a software (trap) breakpoint at the LMA. */
2212 bl->overlay_target_info = bl->target_info;
2213 bl->overlay_target_info.placed_address = addr;
2214 val = target_insert_breakpoint (bl->gdbarch,
2215 &bl->overlay_target_info);
2217 fprintf_unfiltered (tmp_error_stream,
2218 "Overlay breakpoint %d "
2219 "failed: in ROM?\n",
2223 /* Shall we set a breakpoint at the VMA? */
2224 if (section_is_mapped (bl->section))
2226 /* Yes. This overlay section is mapped into memory. */
2227 val = bl->owner->ops->insert_location (bl);
2231 /* No. This breakpoint will not be inserted.
2232 No error, but do not mark the bp as 'inserted'. */
2239 /* Can't set the breakpoint. */
2240 if (solib_name_from_address (bl->pspace, bl->address))
2242 /* See also: disable_breakpoints_in_shlibs. */
2244 bl->shlib_disabled = 1;
2245 observer_notify_breakpoint_modified (bl->owner);
2246 if (!*disabled_breaks)
2248 fprintf_unfiltered (tmp_error_stream,
2249 "Cannot insert breakpoint %d.\n",
2251 fprintf_unfiltered (tmp_error_stream,
2252 "Temporarily disabling shared "
2253 "library breakpoints:\n");
2255 *disabled_breaks = 1;
2256 fprintf_unfiltered (tmp_error_stream,
2257 "breakpoint #%d\n", bl->owner->number);
2261 if (bl->loc_type == bp_loc_hardware_breakpoint)
2263 *hw_breakpoint_error = 1;
2264 fprintf_unfiltered (tmp_error_stream,
2265 "Cannot insert hardware "
2271 fprintf_unfiltered (tmp_error_stream,
2272 "Cannot insert breakpoint %d.\n",
2274 fprintf_filtered (tmp_error_stream,
2275 "Error accessing memory address ");
2276 fputs_filtered (paddress (bl->gdbarch, bl->address),
2278 fprintf_filtered (tmp_error_stream, ": %s.\n",
2279 safe_strerror (val));
2290 else if (bl->loc_type == bp_loc_hardware_watchpoint
2291 /* NOTE drow/2003-09-08: This state only exists for removing
2292 watchpoints. It's not clear that it's necessary... */
2293 && bl->owner->disposition != disp_del_at_next_stop)
2295 gdb_assert (bl->owner->ops != NULL
2296 && bl->owner->ops->insert_location != NULL);
2298 val = bl->owner->ops->insert_location (bl);
2300 /* If trying to set a read-watchpoint, and it turns out it's not
2301 supported, try emulating one with an access watchpoint. */
2302 if (val == 1 && bl->watchpoint_type == hw_read)
2304 struct bp_location *loc, **loc_temp;
2306 /* But don't try to insert it, if there's already another
2307 hw_access location that would be considered a duplicate
2309 ALL_BP_LOCATIONS (loc, loc_temp)
2311 && loc->watchpoint_type == hw_access
2312 && watchpoint_locations_match (bl, loc))
2316 bl->target_info = loc->target_info;
2317 bl->watchpoint_type = hw_access;
2324 bl->watchpoint_type = hw_access;
2325 val = bl->owner->ops->insert_location (bl);
2328 /* Back to the original value. */
2329 bl->watchpoint_type = hw_read;
2333 bl->inserted = (val == 0);
2336 else if (bl->owner->type == bp_catchpoint)
2338 gdb_assert (bl->owner->ops != NULL
2339 && bl->owner->ops->insert_location != NULL);
2341 val = bl->owner->ops->insert_location (bl);
2344 bl->owner->enable_state = bp_disabled;
2348 Error inserting catchpoint %d: Your system does not support this type\n\
2349 of catchpoint."), bl->owner->number);
2351 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2354 bl->inserted = (val == 0);
2356 /* We've already printed an error message if there was a problem
2357 inserting this catchpoint, and we've disabled the catchpoint,
2358 so just return success. */
2365 /* This function is called when program space PSPACE is about to be
2366 deleted. It takes care of updating breakpoints to not reference
2370 breakpoint_program_space_exit (struct program_space *pspace)
2372 struct breakpoint *b, *b_temp;
2373 struct bp_location *loc, **loc_temp;
2375 /* Remove any breakpoint that was set through this program space. */
2376 ALL_BREAKPOINTS_SAFE (b, b_temp)
2378 if (b->pspace == pspace)
2379 delete_breakpoint (b);
2382 /* Breakpoints set through other program spaces could have locations
2383 bound to PSPACE as well. Remove those. */
2384 ALL_BP_LOCATIONS (loc, loc_temp)
2386 struct bp_location *tmp;
2388 if (loc->pspace == pspace)
2390 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2391 if (loc->owner->loc == loc)
2392 loc->owner->loc = loc->next;
2394 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2395 if (tmp->next == loc)
2397 tmp->next = loc->next;
2403 /* Now update the global location list to permanently delete the
2404 removed locations above. */
2405 update_global_location_list (0);
2408 /* Make sure all breakpoints are inserted in inferior.
2409 Throws exception on any error.
2410 A breakpoint that is already inserted won't be inserted
2411 again, so calling this function twice is safe. */
2413 insert_breakpoints (void)
2415 struct breakpoint *bpt;
2417 ALL_BREAKPOINTS (bpt)
2418 if (is_hardware_watchpoint (bpt))
2420 struct watchpoint *w = (struct watchpoint *) bpt;
2422 update_watchpoint (w, 0 /* don't reparse. */);
2425 update_global_location_list (1);
2427 /* update_global_location_list does not insert breakpoints when
2428 always_inserted_mode is not enabled. Explicitly insert them
2430 if (!breakpoints_always_inserted_mode ())
2431 insert_breakpoint_locations ();
2434 /* Invoke CALLBACK for each of bp_location. */
2437 iterate_over_bp_locations (walk_bp_location_callback callback)
2439 struct bp_location *loc, **loc_tmp;
2441 ALL_BP_LOCATIONS (loc, loc_tmp)
2443 callback (loc, NULL);
2447 /* This is used when we need to synch breakpoint conditions between GDB and the
2448 target. It is the case with deleting and disabling of breakpoints when using
2449 always-inserted mode. */
2452 update_inserted_breakpoint_locations (void)
2454 struct bp_location *bl, **blp_tmp;
2457 int disabled_breaks = 0;
2458 int hw_breakpoint_error = 0;
2460 struct ui_file *tmp_error_stream = mem_fileopen ();
2461 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2463 /* Explicitly mark the warning -- this will only be printed if
2464 there was an error. */
2465 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2467 save_current_space_and_thread ();
2469 ALL_BP_LOCATIONS (bl, blp_tmp)
2471 /* We only want to update software breakpoints and hardware
2473 if (!is_breakpoint (bl->owner))
2476 /* We only want to update locations that are already inserted
2477 and need updating. This is to avoid unwanted insertion during
2478 deletion of breakpoints. */
2479 if (!bl->inserted || (bl->inserted && !bl->needs_update))
2482 switch_to_program_space_and_thread (bl->pspace);
2484 /* For targets that support global breakpoints, there's no need
2485 to select an inferior to insert breakpoint to. In fact, even
2486 if we aren't attached to any process yet, we should still
2487 insert breakpoints. */
2488 if (!gdbarch_has_global_breakpoints (target_gdbarch)
2489 && ptid_equal (inferior_ptid, null_ptid))
2492 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2493 &hw_breakpoint_error);
2500 target_terminal_ours_for_output ();
2501 error_stream (tmp_error_stream);
2504 do_cleanups (cleanups);
2507 /* Used when starting or continuing the program. */
2510 insert_breakpoint_locations (void)
2512 struct breakpoint *bpt;
2513 struct bp_location *bl, **blp_tmp;
2516 int disabled_breaks = 0;
2517 int hw_breakpoint_error = 0;
2519 struct ui_file *tmp_error_stream = mem_fileopen ();
2520 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2522 /* Explicitly mark the warning -- this will only be printed if
2523 there was an error. */
2524 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2526 save_current_space_and_thread ();
2528 ALL_BP_LOCATIONS (bl, blp_tmp)
2530 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2533 /* There is no point inserting thread-specific breakpoints if
2534 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2535 has BL->OWNER always non-NULL. */
2536 if (bl->owner->thread != -1
2537 && !valid_thread_id (bl->owner->thread))
2540 switch_to_program_space_and_thread (bl->pspace);
2542 /* For targets that support global breakpoints, there's no need
2543 to select an inferior to insert breakpoint to. In fact, even
2544 if we aren't attached to any process yet, we should still
2545 insert breakpoints. */
2546 if (!gdbarch_has_global_breakpoints (target_gdbarch)
2547 && ptid_equal (inferior_ptid, null_ptid))
2550 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2551 &hw_breakpoint_error);
2556 /* If we failed to insert all locations of a watchpoint, remove
2557 them, as half-inserted watchpoint is of limited use. */
2558 ALL_BREAKPOINTS (bpt)
2560 int some_failed = 0;
2561 struct bp_location *loc;
2563 if (!is_hardware_watchpoint (bpt))
2566 if (!breakpoint_enabled (bpt))
2569 if (bpt->disposition == disp_del_at_next_stop)
2572 for (loc = bpt->loc; loc; loc = loc->next)
2573 if (!loc->inserted && should_be_inserted (loc))
2580 for (loc = bpt->loc; loc; loc = loc->next)
2582 remove_breakpoint (loc, mark_uninserted);
2584 hw_breakpoint_error = 1;
2585 fprintf_unfiltered (tmp_error_stream,
2586 "Could not insert hardware watchpoint %d.\n",
2594 /* If a hardware breakpoint or watchpoint was inserted, add a
2595 message about possibly exhausted resources. */
2596 if (hw_breakpoint_error)
2598 fprintf_unfiltered (tmp_error_stream,
2599 "Could not insert hardware breakpoints:\n\
2600 You may have requested too many hardware breakpoints/watchpoints.\n");
2602 target_terminal_ours_for_output ();
2603 error_stream (tmp_error_stream);
2606 do_cleanups (cleanups);
2609 /* Used when the program stops.
2610 Returns zero if successful, or non-zero if there was a problem
2611 removing a breakpoint location. */
2614 remove_breakpoints (void)
2616 struct bp_location *bl, **blp_tmp;
2619 ALL_BP_LOCATIONS (bl, blp_tmp)
2621 if (bl->inserted && !is_tracepoint (bl->owner))
2622 val |= remove_breakpoint (bl, mark_uninserted);
2627 /* Remove breakpoints of process PID. */
2630 remove_breakpoints_pid (int pid)
2632 struct bp_location *bl, **blp_tmp;
2634 struct inferior *inf = find_inferior_pid (pid);
2636 ALL_BP_LOCATIONS (bl, blp_tmp)
2638 if (bl->pspace != inf->pspace)
2643 val = remove_breakpoint (bl, mark_uninserted);
2652 reattach_breakpoints (int pid)
2654 struct cleanup *old_chain;
2655 struct bp_location *bl, **blp_tmp;
2657 struct ui_file *tmp_error_stream;
2658 int dummy1 = 0, dummy2 = 0;
2659 struct inferior *inf;
2660 struct thread_info *tp;
2662 tp = any_live_thread_of_process (pid);
2666 inf = find_inferior_pid (pid);
2667 old_chain = save_inferior_ptid ();
2669 inferior_ptid = tp->ptid;
2671 tmp_error_stream = mem_fileopen ();
2672 make_cleanup_ui_file_delete (tmp_error_stream);
2674 ALL_BP_LOCATIONS (bl, blp_tmp)
2676 if (bl->pspace != inf->pspace)
2682 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2);
2685 do_cleanups (old_chain);
2690 do_cleanups (old_chain);
2694 static int internal_breakpoint_number = -1;
2696 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2697 If INTERNAL is non-zero, the breakpoint number will be populated
2698 from internal_breakpoint_number and that variable decremented.
2699 Otherwise the breakpoint number will be populated from
2700 breakpoint_count and that value incremented. Internal breakpoints
2701 do not set the internal var bpnum. */
2703 set_breakpoint_number (int internal, struct breakpoint *b)
2706 b->number = internal_breakpoint_number--;
2709 set_breakpoint_count (breakpoint_count + 1);
2710 b->number = breakpoint_count;
2714 static struct breakpoint *
2715 create_internal_breakpoint (struct gdbarch *gdbarch,
2716 CORE_ADDR address, enum bptype type,
2717 const struct breakpoint_ops *ops)
2719 struct symtab_and_line sal;
2720 struct breakpoint *b;
2722 init_sal (&sal); /* Initialize to zeroes. */
2725 sal.section = find_pc_overlay (sal.pc);
2726 sal.pspace = current_program_space;
2728 b = set_raw_breakpoint (gdbarch, sal, type, ops);
2729 b->number = internal_breakpoint_number--;
2730 b->disposition = disp_donttouch;
2735 static const char *const longjmp_names[] =
2737 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2739 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2741 /* Per-objfile data private to breakpoint.c. */
2742 struct breakpoint_objfile_data
2744 /* Minimal symbol for "_ovly_debug_event" (if any). */
2745 struct minimal_symbol *overlay_msym;
2747 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2748 struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES];
2750 /* True if we have looked for longjmp probes. */
2751 int longjmp_searched;
2753 /* SystemTap probe points for longjmp (if any). */
2754 VEC (probe_p) *longjmp_probes;
2756 /* Minimal symbol for "std::terminate()" (if any). */
2757 struct minimal_symbol *terminate_msym;
2759 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2760 struct minimal_symbol *exception_msym;
2762 /* True if we have looked for exception probes. */
2763 int exception_searched;
2765 /* SystemTap probe points for unwinding (if any). */
2766 VEC (probe_p) *exception_probes;
2769 static const struct objfile_data *breakpoint_objfile_key;
2771 /* Minimal symbol not found sentinel. */
2772 static struct minimal_symbol msym_not_found;
2774 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2777 msym_not_found_p (const struct minimal_symbol *msym)
2779 return msym == &msym_not_found;
2782 /* Return per-objfile data needed by breakpoint.c.
2783 Allocate the data if necessary. */
2785 static struct breakpoint_objfile_data *
2786 get_breakpoint_objfile_data (struct objfile *objfile)
2788 struct breakpoint_objfile_data *bp_objfile_data;
2790 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
2791 if (bp_objfile_data == NULL)
2793 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
2794 sizeof (*bp_objfile_data));
2796 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
2797 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
2799 return bp_objfile_data;
2803 free_breakpoint_probes (struct objfile *obj, void *data)
2805 struct breakpoint_objfile_data *bp_objfile_data = data;
2807 VEC_free (probe_p, bp_objfile_data->longjmp_probes);
2808 VEC_free (probe_p, bp_objfile_data->exception_probes);
2812 create_overlay_event_breakpoint (void)
2814 struct objfile *objfile;
2815 const char *const func_name = "_ovly_debug_event";
2817 ALL_OBJFILES (objfile)
2819 struct breakpoint *b;
2820 struct breakpoint_objfile_data *bp_objfile_data;
2823 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2825 if (msym_not_found_p (bp_objfile_data->overlay_msym))
2828 if (bp_objfile_data->overlay_msym == NULL)
2830 struct minimal_symbol *m;
2832 m = lookup_minimal_symbol_text (func_name, objfile);
2835 /* Avoid future lookups in this objfile. */
2836 bp_objfile_data->overlay_msym = &msym_not_found;
2839 bp_objfile_data->overlay_msym = m;
2842 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
2843 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2845 &internal_breakpoint_ops);
2846 b->addr_string = xstrdup (func_name);
2848 if (overlay_debugging == ovly_auto)
2850 b->enable_state = bp_enabled;
2851 overlay_events_enabled = 1;
2855 b->enable_state = bp_disabled;
2856 overlay_events_enabled = 0;
2859 update_global_location_list (1);
2863 create_longjmp_master_breakpoint (void)
2865 struct program_space *pspace;
2866 struct cleanup *old_chain;
2868 old_chain = save_current_program_space ();
2870 ALL_PSPACES (pspace)
2872 struct objfile *objfile;
2874 set_current_program_space (pspace);
2876 ALL_OBJFILES (objfile)
2879 struct gdbarch *gdbarch;
2880 struct breakpoint_objfile_data *bp_objfile_data;
2882 gdbarch = get_objfile_arch (objfile);
2883 if (!gdbarch_get_longjmp_target_p (gdbarch))
2886 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2888 if (!bp_objfile_data->longjmp_searched)
2890 bp_objfile_data->longjmp_probes
2891 = find_probes_in_objfile (objfile, "libc", "longjmp");
2892 bp_objfile_data->longjmp_searched = 1;
2895 if (bp_objfile_data->longjmp_probes != NULL)
2898 struct probe *probe;
2899 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2902 VEC_iterate (probe_p,
2903 bp_objfile_data->longjmp_probes,
2907 struct breakpoint *b;
2909 b = create_internal_breakpoint (gdbarch, probe->address,
2911 &internal_breakpoint_ops);
2912 b->addr_string = xstrdup ("-probe-stap libc:longjmp");
2913 b->enable_state = bp_disabled;
2919 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
2921 struct breakpoint *b;
2922 const char *func_name;
2925 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i]))
2928 func_name = longjmp_names[i];
2929 if (bp_objfile_data->longjmp_msym[i] == NULL)
2931 struct minimal_symbol *m;
2933 m = lookup_minimal_symbol_text (func_name, objfile);
2936 /* Prevent future lookups in this objfile. */
2937 bp_objfile_data->longjmp_msym[i] = &msym_not_found;
2940 bp_objfile_data->longjmp_msym[i] = m;
2943 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
2944 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
2945 &internal_breakpoint_ops);
2946 b->addr_string = xstrdup (func_name);
2947 b->enable_state = bp_disabled;
2951 update_global_location_list (1);
2953 do_cleanups (old_chain);
2956 /* Create a master std::terminate breakpoint. */
2958 create_std_terminate_master_breakpoint (void)
2960 struct program_space *pspace;
2961 struct cleanup *old_chain;
2962 const char *const func_name = "std::terminate()";
2964 old_chain = save_current_program_space ();
2966 ALL_PSPACES (pspace)
2968 struct objfile *objfile;
2971 set_current_program_space (pspace);
2973 ALL_OBJFILES (objfile)
2975 struct breakpoint *b;
2976 struct breakpoint_objfile_data *bp_objfile_data;
2978 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2980 if (msym_not_found_p (bp_objfile_data->terminate_msym))
2983 if (bp_objfile_data->terminate_msym == NULL)
2985 struct minimal_symbol *m;
2987 m = lookup_minimal_symbol (func_name, NULL, objfile);
2988 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
2989 && MSYMBOL_TYPE (m) != mst_file_text))
2991 /* Prevent future lookups in this objfile. */
2992 bp_objfile_data->terminate_msym = &msym_not_found;
2995 bp_objfile_data->terminate_msym = m;
2998 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
2999 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3000 bp_std_terminate_master,
3001 &internal_breakpoint_ops);
3002 b->addr_string = xstrdup (func_name);
3003 b->enable_state = bp_disabled;
3007 update_global_location_list (1);
3009 do_cleanups (old_chain);
3012 /* Install a master breakpoint on the unwinder's debug hook. */
3015 create_exception_master_breakpoint (void)
3017 struct objfile *objfile;
3018 const char *const func_name = "_Unwind_DebugHook";
3020 ALL_OBJFILES (objfile)
3022 struct breakpoint *b;
3023 struct gdbarch *gdbarch;
3024 struct breakpoint_objfile_data *bp_objfile_data;
3027 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3029 /* We prefer the SystemTap probe point if it exists. */
3030 if (!bp_objfile_data->exception_searched)
3032 bp_objfile_data->exception_probes
3033 = find_probes_in_objfile (objfile, "libgcc", "unwind");
3034 bp_objfile_data->exception_searched = 1;
3037 if (bp_objfile_data->exception_probes != NULL)
3039 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3041 struct probe *probe;
3044 VEC_iterate (probe_p,
3045 bp_objfile_data->exception_probes,
3049 struct breakpoint *b;
3051 b = create_internal_breakpoint (gdbarch, probe->address,
3052 bp_exception_master,
3053 &internal_breakpoint_ops);
3054 b->addr_string = xstrdup ("-probe-stap libgcc:unwind");
3055 b->enable_state = bp_disabled;
3061 /* Otherwise, try the hook function. */
3063 if (msym_not_found_p (bp_objfile_data->exception_msym))
3066 gdbarch = get_objfile_arch (objfile);
3068 if (bp_objfile_data->exception_msym == NULL)
3070 struct minimal_symbol *debug_hook;
3072 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3073 if (debug_hook == NULL)
3075 bp_objfile_data->exception_msym = &msym_not_found;
3079 bp_objfile_data->exception_msym = debug_hook;
3082 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3083 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3085 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3086 &internal_breakpoint_ops);
3087 b->addr_string = xstrdup (func_name);
3088 b->enable_state = bp_disabled;
3091 update_global_location_list (1);
3095 update_breakpoints_after_exec (void)
3097 struct breakpoint *b, *b_tmp;
3098 struct bp_location *bploc, **bplocp_tmp;
3100 /* We're about to delete breakpoints from GDB's lists. If the
3101 INSERTED flag is true, GDB will try to lift the breakpoints by
3102 writing the breakpoints' "shadow contents" back into memory. The
3103 "shadow contents" are NOT valid after an exec, so GDB should not
3104 do that. Instead, the target is responsible from marking
3105 breakpoints out as soon as it detects an exec. We don't do that
3106 here instead, because there may be other attempts to delete
3107 breakpoints after detecting an exec and before reaching here. */
3108 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3109 if (bploc->pspace == current_program_space)
3110 gdb_assert (!bploc->inserted);
3112 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3114 if (b->pspace != current_program_space)
3117 /* Solib breakpoints must be explicitly reset after an exec(). */
3118 if (b->type == bp_shlib_event)
3120 delete_breakpoint (b);
3124 /* JIT breakpoints must be explicitly reset after an exec(). */
3125 if (b->type == bp_jit_event)
3127 delete_breakpoint (b);
3131 /* Thread event breakpoints must be set anew after an exec(),
3132 as must overlay event and longjmp master breakpoints. */
3133 if (b->type == bp_thread_event || b->type == bp_overlay_event
3134 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3135 || b->type == bp_exception_master)
3137 delete_breakpoint (b);
3141 /* Step-resume breakpoints are meaningless after an exec(). */
3142 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3144 delete_breakpoint (b);
3148 /* Longjmp and longjmp-resume breakpoints are also meaningless
3150 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3151 || b->type == bp_exception || b->type == bp_exception_resume)
3153 delete_breakpoint (b);
3157 if (b->type == bp_catchpoint)
3159 /* For now, none of the bp_catchpoint breakpoints need to
3160 do anything at this point. In the future, if some of
3161 the catchpoints need to something, we will need to add
3162 a new method, and call this method from here. */
3166 /* bp_finish is a special case. The only way we ought to be able
3167 to see one of these when an exec() has happened, is if the user
3168 caught a vfork, and then said "finish". Ordinarily a finish just
3169 carries them to the call-site of the current callee, by setting
3170 a temporary bp there and resuming. But in this case, the finish
3171 will carry them entirely through the vfork & exec.
3173 We don't want to allow a bp_finish to remain inserted now. But
3174 we can't safely delete it, 'cause finish_command has a handle to
3175 the bp on a bpstat, and will later want to delete it. There's a
3176 chance (and I've seen it happen) that if we delete the bp_finish
3177 here, that its storage will get reused by the time finish_command
3178 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3179 We really must allow finish_command to delete a bp_finish.
3181 In the absence of a general solution for the "how do we know
3182 it's safe to delete something others may have handles to?"
3183 problem, what we'll do here is just uninsert the bp_finish, and
3184 let finish_command delete it.
3186 (We know the bp_finish is "doomed" in the sense that it's
3187 momentary, and will be deleted as soon as finish_command sees
3188 the inferior stopped. So it doesn't matter that the bp's
3189 address is probably bogus in the new a.out, unlike e.g., the
3190 solib breakpoints.) */
3192 if (b->type == bp_finish)
3197 /* Without a symbolic address, we have little hope of the
3198 pre-exec() address meaning the same thing in the post-exec()
3200 if (b->addr_string == NULL)
3202 delete_breakpoint (b);
3206 /* FIXME what about longjmp breakpoints? Re-create them here? */
3207 create_overlay_event_breakpoint ();
3208 create_longjmp_master_breakpoint ();
3209 create_std_terminate_master_breakpoint ();
3210 create_exception_master_breakpoint ();
3214 detach_breakpoints (int pid)
3216 struct bp_location *bl, **blp_tmp;
3218 struct cleanup *old_chain = save_inferior_ptid ();
3219 struct inferior *inf = current_inferior ();
3221 if (pid == PIDGET (inferior_ptid))
3222 error (_("Cannot detach breakpoints of inferior_ptid"));
3224 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3225 inferior_ptid = pid_to_ptid (pid);
3226 ALL_BP_LOCATIONS (bl, blp_tmp)
3228 if (bl->pspace != inf->pspace)
3232 val |= remove_breakpoint_1 (bl, mark_inserted);
3235 /* Detach single-step breakpoints as well. */
3236 detach_single_step_breakpoints ();
3238 do_cleanups (old_chain);
3242 /* Remove the breakpoint location BL from the current address space.
3243 Note that this is used to detach breakpoints from a child fork.
3244 When we get here, the child isn't in the inferior list, and neither
3245 do we have objects to represent its address space --- we should
3246 *not* look at bl->pspace->aspace here. */
3249 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
3253 /* BL is never in moribund_locations by our callers. */
3254 gdb_assert (bl->owner != NULL);
3256 if (bl->owner->enable_state == bp_permanent)
3257 /* Permanent breakpoints cannot be inserted or removed. */
3260 /* The type of none suggests that owner is actually deleted.
3261 This should not ever happen. */
3262 gdb_assert (bl->owner->type != bp_none);
3264 if (bl->loc_type == bp_loc_software_breakpoint
3265 || bl->loc_type == bp_loc_hardware_breakpoint)
3267 /* "Normal" instruction breakpoint: either the standard
3268 trap-instruction bp (bp_breakpoint), or a
3269 bp_hardware_breakpoint. */
3271 /* First check to see if we have to handle an overlay. */
3272 if (overlay_debugging == ovly_off
3273 || bl->section == NULL
3274 || !(section_is_overlay (bl->section)))
3276 /* No overlay handling: just remove the breakpoint. */
3277 val = bl->owner->ops->remove_location (bl);
3281 /* This breakpoint is in an overlay section.
3282 Did we set a breakpoint at the LMA? */
3283 if (!overlay_events_enabled)
3285 /* Yes -- overlay event support is not active, so we
3286 should have set a breakpoint at the LMA. Remove it.
3288 /* Ignore any failures: if the LMA is in ROM, we will
3289 have already warned when we failed to insert it. */
3290 if (bl->loc_type == bp_loc_hardware_breakpoint)
3291 target_remove_hw_breakpoint (bl->gdbarch,
3292 &bl->overlay_target_info);
3294 target_remove_breakpoint (bl->gdbarch,
3295 &bl->overlay_target_info);
3297 /* Did we set a breakpoint at the VMA?
3298 If so, we will have marked the breakpoint 'inserted'. */
3301 /* Yes -- remove it. Previously we did not bother to
3302 remove the breakpoint if the section had been
3303 unmapped, but let's not rely on that being safe. We
3304 don't know what the overlay manager might do. */
3306 /* However, we should remove *software* breakpoints only
3307 if the section is still mapped, or else we overwrite
3308 wrong code with the saved shadow contents. */
3309 if (bl->loc_type == bp_loc_hardware_breakpoint
3310 || section_is_mapped (bl->section))
3311 val = bl->owner->ops->remove_location (bl);
3317 /* No -- not inserted, so no need to remove. No error. */
3322 /* In some cases, we might not be able to remove a breakpoint
3323 in a shared library that has already been removed, but we
3324 have not yet processed the shlib unload event. */
3325 if (val && solib_name_from_address (bl->pspace, bl->address))
3330 bl->inserted = (is == mark_inserted);
3332 else if (bl->loc_type == bp_loc_hardware_watchpoint)
3334 gdb_assert (bl->owner->ops != NULL
3335 && bl->owner->ops->remove_location != NULL);
3337 bl->inserted = (is == mark_inserted);
3338 bl->owner->ops->remove_location (bl);
3340 /* Failure to remove any of the hardware watchpoints comes here. */
3341 if ((is == mark_uninserted) && (bl->inserted))
3342 warning (_("Could not remove hardware watchpoint %d."),
3345 else if (bl->owner->type == bp_catchpoint
3346 && breakpoint_enabled (bl->owner)
3349 gdb_assert (bl->owner->ops != NULL
3350 && bl->owner->ops->remove_location != NULL);
3352 val = bl->owner->ops->remove_location (bl);
3356 bl->inserted = (is == mark_inserted);
3363 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
3366 struct cleanup *old_chain;
3368 /* BL is never in moribund_locations by our callers. */
3369 gdb_assert (bl->owner != NULL);
3371 if (bl->owner->enable_state == bp_permanent)
3372 /* Permanent breakpoints cannot be inserted or removed. */
3375 /* The type of none suggests that owner is actually deleted.
3376 This should not ever happen. */
3377 gdb_assert (bl->owner->type != bp_none);
3379 old_chain = save_current_space_and_thread ();
3381 switch_to_program_space_and_thread (bl->pspace);
3383 ret = remove_breakpoint_1 (bl, is);
3385 do_cleanups (old_chain);
3389 /* Clear the "inserted" flag in all breakpoints. */
3392 mark_breakpoints_out (void)
3394 struct bp_location *bl, **blp_tmp;
3396 ALL_BP_LOCATIONS (bl, blp_tmp)
3397 if (bl->pspace == current_program_space)
3401 /* Clear the "inserted" flag in all breakpoints and delete any
3402 breakpoints which should go away between runs of the program.
3404 Plus other such housekeeping that has to be done for breakpoints
3407 Note: this function gets called at the end of a run (by
3408 generic_mourn_inferior) and when a run begins (by
3409 init_wait_for_inferior). */
3414 breakpoint_init_inferior (enum inf_context context)
3416 struct breakpoint *b, *b_tmp;
3417 struct bp_location *bl, **blp_tmp;
3419 struct program_space *pspace = current_program_space;
3421 /* If breakpoint locations are shared across processes, then there's
3423 if (gdbarch_has_global_breakpoints (target_gdbarch))
3426 ALL_BP_LOCATIONS (bl, blp_tmp)
3428 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3429 if (bl->pspace == pspace
3430 && bl->owner->enable_state != bp_permanent)
3434 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3436 if (b->loc && b->loc->pspace != pspace)
3443 /* If the call dummy breakpoint is at the entry point it will
3444 cause problems when the inferior is rerun, so we better get
3447 case bp_watchpoint_scope:
3449 /* Also get rid of scope breakpoints. */
3451 case bp_shlib_event:
3453 /* Also remove solib event breakpoints. Their addresses may
3454 have changed since the last time we ran the program.
3455 Actually we may now be debugging against different target;
3456 and so the solib backend that installed this breakpoint may
3457 not be used in by the target. E.g.,
3459 (gdb) file prog-linux
3460 (gdb) run # native linux target
3463 (gdb) file prog-win.exe
3464 (gdb) tar rem :9999 # remote Windows gdbserver.
3467 case bp_step_resume:
3469 /* Also remove step-resume breakpoints. */
3471 delete_breakpoint (b);
3475 case bp_hardware_watchpoint:
3476 case bp_read_watchpoint:
3477 case bp_access_watchpoint:
3479 struct watchpoint *w = (struct watchpoint *) b;
3481 /* Likewise for watchpoints on local expressions. */
3482 if (w->exp_valid_block != NULL)
3483 delete_breakpoint (b);
3484 else if (context == inf_starting)
3486 /* Reset val field to force reread of starting value in
3487 insert_breakpoints. */
3489 value_free (w->val);
3500 /* Get rid of the moribund locations. */
3501 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
3502 decref_bp_location (&bl);
3503 VEC_free (bp_location_p, moribund_locations);
3506 /* These functions concern about actual breakpoints inserted in the
3507 target --- to e.g. check if we need to do decr_pc adjustment or if
3508 we need to hop over the bkpt --- so we check for address space
3509 match, not program space. */
3511 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3512 exists at PC. It returns ordinary_breakpoint_here if it's an
3513 ordinary breakpoint, or permanent_breakpoint_here if it's a
3514 permanent breakpoint.
3515 - When continuing from a location with an ordinary breakpoint, we
3516 actually single step once before calling insert_breakpoints.
3517 - When continuing from a location with a permanent breakpoint, we
3518 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3519 the target, to advance the PC past the breakpoint. */
3521 enum breakpoint_here
3522 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
3524 struct bp_location *bl, **blp_tmp;
3525 int any_breakpoint_here = 0;
3527 ALL_BP_LOCATIONS (bl, blp_tmp)
3529 if (bl->loc_type != bp_loc_software_breakpoint
3530 && bl->loc_type != bp_loc_hardware_breakpoint)
3533 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3534 if ((breakpoint_enabled (bl->owner)
3535 || bl->owner->enable_state == bp_permanent)
3536 && breakpoint_location_address_match (bl, aspace, pc))
3538 if (overlay_debugging
3539 && section_is_overlay (bl->section)
3540 && !section_is_mapped (bl->section))
3541 continue; /* unmapped overlay -- can't be a match */
3542 else if (bl->owner->enable_state == bp_permanent)
3543 return permanent_breakpoint_here;
3545 any_breakpoint_here = 1;
3549 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
3552 /* Return true if there's a moribund breakpoint at PC. */
3555 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
3557 struct bp_location *loc;
3560 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
3561 if (breakpoint_location_address_match (loc, aspace, pc))
3567 /* Returns non-zero if there's a breakpoint inserted at PC, which is
3568 inserted using regular breakpoint_chain / bp_location array
3569 mechanism. This does not check for single-step breakpoints, which
3570 are inserted and removed using direct target manipulation. */
3573 regular_breakpoint_inserted_here_p (struct address_space *aspace,
3576 struct bp_location *bl, **blp_tmp;
3578 ALL_BP_LOCATIONS (bl, blp_tmp)
3580 if (bl->loc_type != bp_loc_software_breakpoint
3581 && bl->loc_type != bp_loc_hardware_breakpoint)
3585 && breakpoint_location_address_match (bl, aspace, pc))
3587 if (overlay_debugging
3588 && section_is_overlay (bl->section)
3589 && !section_is_mapped (bl->section))
3590 continue; /* unmapped overlay -- can't be a match */
3598 /* Returns non-zero iff there's either regular breakpoint
3599 or a single step breakpoint inserted at PC. */
3602 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
3604 if (regular_breakpoint_inserted_here_p (aspace, pc))
3607 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3613 /* This function returns non-zero iff there is a software breakpoint
3617 software_breakpoint_inserted_here_p (struct address_space *aspace,
3620 struct bp_location *bl, **blp_tmp;
3622 ALL_BP_LOCATIONS (bl, blp_tmp)
3624 if (bl->loc_type != bp_loc_software_breakpoint)
3628 && breakpoint_address_match (bl->pspace->aspace, bl->address,
3631 if (overlay_debugging
3632 && section_is_overlay (bl->section)
3633 && !section_is_mapped (bl->section))
3634 continue; /* unmapped overlay -- can't be a match */
3640 /* Also check for software single-step breakpoints. */
3641 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3648 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
3649 CORE_ADDR addr, ULONGEST len)
3651 struct breakpoint *bpt;
3653 ALL_BREAKPOINTS (bpt)
3655 struct bp_location *loc;
3657 if (bpt->type != bp_hardware_watchpoint
3658 && bpt->type != bp_access_watchpoint)
3661 if (!breakpoint_enabled (bpt))
3664 for (loc = bpt->loc; loc; loc = loc->next)
3665 if (loc->pspace->aspace == aspace && loc->inserted)
3669 /* Check for intersection. */
3670 l = max (loc->address, addr);
3671 h = min (loc->address + loc->length, addr + len);
3679 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3680 PC is valid for process/thread PTID. */
3683 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
3686 struct bp_location *bl, **blp_tmp;
3687 /* The thread and task IDs associated to PTID, computed lazily. */
3691 ALL_BP_LOCATIONS (bl, blp_tmp)
3693 if (bl->loc_type != bp_loc_software_breakpoint
3694 && bl->loc_type != bp_loc_hardware_breakpoint)
3697 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3698 if (!breakpoint_enabled (bl->owner)
3699 && bl->owner->enable_state != bp_permanent)
3702 if (!breakpoint_location_address_match (bl, aspace, pc))
3705 if (bl->owner->thread != -1)
3707 /* This is a thread-specific breakpoint. Check that ptid
3708 matches that thread. If thread hasn't been computed yet,
3709 it is now time to do so. */
3711 thread = pid_to_thread_id (ptid);
3712 if (bl->owner->thread != thread)
3716 if (bl->owner->task != 0)
3718 /* This is a task-specific breakpoint. Check that ptid
3719 matches that task. If task hasn't been computed yet,
3720 it is now time to do so. */
3722 task = ada_get_task_number (ptid);
3723 if (bl->owner->task != task)
3727 if (overlay_debugging
3728 && section_is_overlay (bl->section)
3729 && !section_is_mapped (bl->section))
3730 continue; /* unmapped overlay -- can't be a match */
3739 /* bpstat stuff. External routines' interfaces are documented
3743 is_catchpoint (struct breakpoint *ep)
3745 return (ep->type == bp_catchpoint);
3748 /* Frees any storage that is part of a bpstat. Does not walk the
3752 bpstat_free (bpstat bs)
3754 if (bs->old_val != NULL)
3755 value_free (bs->old_val);
3756 decref_counted_command_line (&bs->commands);
3757 decref_bp_location (&bs->bp_location_at);
3761 /* Clear a bpstat so that it says we are not at any breakpoint.
3762 Also free any storage that is part of a bpstat. */
3765 bpstat_clear (bpstat *bsp)
3782 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3783 is part of the bpstat is copied as well. */
3786 bpstat_copy (bpstat bs)
3790 bpstat retval = NULL;
3795 for (; bs != NULL; bs = bs->next)
3797 tmp = (bpstat) xmalloc (sizeof (*tmp));
3798 memcpy (tmp, bs, sizeof (*tmp));
3799 incref_counted_command_line (tmp->commands);
3800 incref_bp_location (tmp->bp_location_at);
3801 if (bs->old_val != NULL)
3803 tmp->old_val = value_copy (bs->old_val);
3804 release_value (tmp->old_val);
3808 /* This is the first thing in the chain. */
3818 /* Find the bpstat associated with this breakpoint. */
3821 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
3826 for (; bsp != NULL; bsp = bsp->next)
3828 if (bsp->breakpoint_at == breakpoint)
3834 /* Put in *NUM the breakpoint number of the first breakpoint we are
3835 stopped at. *BSP upon return is a bpstat which points to the
3836 remaining breakpoints stopped at (but which is not guaranteed to be
3837 good for anything but further calls to bpstat_num).
3839 Return 0 if passed a bpstat which does not indicate any breakpoints.
3840 Return -1 if stopped at a breakpoint that has been deleted since
3842 Return 1 otherwise. */
3845 bpstat_num (bpstat *bsp, int *num)
3847 struct breakpoint *b;
3850 return 0; /* No more breakpoint values */
3852 /* We assume we'll never have several bpstats that correspond to a
3853 single breakpoint -- otherwise, this function might return the
3854 same number more than once and this will look ugly. */
3855 b = (*bsp)->breakpoint_at;
3856 *bsp = (*bsp)->next;
3858 return -1; /* breakpoint that's been deleted since */
3860 *num = b->number; /* We have its number */
3864 /* See breakpoint.h. */
3867 bpstat_clear_actions (void)
3869 struct thread_info *tp;
3872 if (ptid_equal (inferior_ptid, null_ptid))
3875 tp = find_thread_ptid (inferior_ptid);
3879 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
3881 decref_counted_command_line (&bs->commands);
3883 if (bs->old_val != NULL)
3885 value_free (bs->old_val);
3891 /* Called when a command is about to proceed the inferior. */
3894 breakpoint_about_to_proceed (void)
3896 if (!ptid_equal (inferior_ptid, null_ptid))
3898 struct thread_info *tp = inferior_thread ();
3900 /* Allow inferior function calls in breakpoint commands to not
3901 interrupt the command list. When the call finishes
3902 successfully, the inferior will be standing at the same
3903 breakpoint as if nothing happened. */
3904 if (tp->control.in_infcall)
3908 breakpoint_proceeded = 1;
3911 /* Stub for cleaning up our state if we error-out of a breakpoint
3914 cleanup_executing_breakpoints (void *ignore)
3916 executing_breakpoint_commands = 0;
3919 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3920 or its equivalent. */
3923 command_line_is_silent (struct command_line *cmd)
3925 return cmd && (strcmp ("silent", cmd->line) == 0
3926 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
3929 /* Execute all the commands associated with all the breakpoints at
3930 this location. Any of these commands could cause the process to
3931 proceed beyond this point, etc. We look out for such changes by
3932 checking the global "breakpoint_proceeded" after each command.
3934 Returns true if a breakpoint command resumed the inferior. In that
3935 case, it is the caller's responsibility to recall it again with the
3936 bpstat of the current thread. */
3939 bpstat_do_actions_1 (bpstat *bsp)
3942 struct cleanup *old_chain;
3945 /* Avoid endless recursion if a `source' command is contained
3947 if (executing_breakpoint_commands)
3950 executing_breakpoint_commands = 1;
3951 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
3953 prevent_dont_repeat ();
3955 /* This pointer will iterate over the list of bpstat's. */
3958 breakpoint_proceeded = 0;
3959 for (; bs != NULL; bs = bs->next)
3961 struct counted_command_line *ccmd;
3962 struct command_line *cmd;
3963 struct cleanup *this_cmd_tree_chain;
3965 /* Take ownership of the BSP's command tree, if it has one.
3967 The command tree could legitimately contain commands like
3968 'step' and 'next', which call clear_proceed_status, which
3969 frees stop_bpstat's command tree. To make sure this doesn't
3970 free the tree we're executing out from under us, we need to
3971 take ownership of the tree ourselves. Since a given bpstat's
3972 commands are only executed once, we don't need to copy it; we
3973 can clear the pointer in the bpstat, and make sure we free
3974 the tree when we're done. */
3975 ccmd = bs->commands;
3976 bs->commands = NULL;
3977 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
3978 cmd = ccmd ? ccmd->commands : NULL;
3979 if (command_line_is_silent (cmd))
3981 /* The action has been already done by bpstat_stop_status. */
3987 execute_control_command (cmd);
3989 if (breakpoint_proceeded)
3995 /* We can free this command tree now. */
3996 do_cleanups (this_cmd_tree_chain);
3998 if (breakpoint_proceeded)
4000 if (target_can_async_p ())
4001 /* If we are in async mode, then the target might be still
4002 running, not stopped at any breakpoint, so nothing for
4003 us to do here -- just return to the event loop. */
4006 /* In sync mode, when execute_control_command returns
4007 we're already standing on the next breakpoint.
4008 Breakpoint commands for that stop were not run, since
4009 execute_command does not run breakpoint commands --
4010 only command_line_handler does, but that one is not
4011 involved in execution of breakpoint commands. So, we
4012 can now execute breakpoint commands. It should be
4013 noted that making execute_command do bpstat actions is
4014 not an option -- in this case we'll have recursive
4015 invocation of bpstat for each breakpoint with a
4016 command, and can easily blow up GDB stack. Instead, we
4017 return true, which will trigger the caller to recall us
4018 with the new stop_bpstat. */
4023 do_cleanups (old_chain);
4028 bpstat_do_actions (void)
4030 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4032 /* Do any commands attached to breakpoint we are stopped at. */
4033 while (!ptid_equal (inferior_ptid, null_ptid)
4034 && target_has_execution
4035 && !is_exited (inferior_ptid)
4036 && !is_executing (inferior_ptid))
4037 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4038 and only return when it is stopped at the next breakpoint, we
4039 keep doing breakpoint actions until it returns false to
4040 indicate the inferior was not resumed. */
4041 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
4044 discard_cleanups (cleanup_if_error);
4047 /* Print out the (old or new) value associated with a watchpoint. */
4050 watchpoint_value_print (struct value *val, struct ui_file *stream)
4053 fprintf_unfiltered (stream, _("<unreadable>"));
4056 struct value_print_options opts;
4057 get_user_print_options (&opts);
4058 value_print (val, stream, &opts);
4062 /* Generic routine for printing messages indicating why we
4063 stopped. The behavior of this function depends on the value
4064 'print_it' in the bpstat structure. Under some circumstances we
4065 may decide not to print anything here and delegate the task to
4068 static enum print_stop_action
4069 print_bp_stop_message (bpstat bs)
4071 switch (bs->print_it)
4074 /* Nothing should be printed for this bpstat entry. */
4075 return PRINT_UNKNOWN;
4079 /* We still want to print the frame, but we already printed the
4080 relevant messages. */
4081 return PRINT_SRC_AND_LOC;
4084 case print_it_normal:
4086 struct breakpoint *b = bs->breakpoint_at;
4088 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4089 which has since been deleted. */
4091 return PRINT_UNKNOWN;
4093 /* Normal case. Call the breakpoint's print_it method. */
4094 return b->ops->print_it (bs);
4099 internal_error (__FILE__, __LINE__,
4100 _("print_bp_stop_message: unrecognized enum value"));
4105 /* A helper function that prints a shared library stopped event. */
4108 print_solib_event (int is_catchpoint)
4111 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4113 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4117 if (any_added || any_deleted)
4118 ui_out_text (current_uiout,
4119 _("Stopped due to shared library event:\n"));
4121 ui_out_text (current_uiout,
4122 _("Stopped due to shared library event (no "
4123 "libraries added or removed)\n"));
4126 if (ui_out_is_mi_like_p (current_uiout))
4127 ui_out_field_string (current_uiout, "reason",
4128 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4132 struct cleanup *cleanup;
4136 ui_out_text (current_uiout, _(" Inferior unloaded "));
4137 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4140 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4145 ui_out_text (current_uiout, " ");
4146 ui_out_field_string (current_uiout, "library", name);
4147 ui_out_text (current_uiout, "\n");
4150 do_cleanups (cleanup);
4155 struct so_list *iter;
4157 struct cleanup *cleanup;
4159 ui_out_text (current_uiout, _(" Inferior loaded "));
4160 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4163 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4168 ui_out_text (current_uiout, " ");
4169 ui_out_field_string (current_uiout, "library", iter->so_name);
4170 ui_out_text (current_uiout, "\n");
4173 do_cleanups (cleanup);
4177 /* Print a message indicating what happened. This is called from
4178 normal_stop(). The input to this routine is the head of the bpstat
4179 list - a list of the eventpoints that caused this stop. KIND is
4180 the target_waitkind for the stopping event. This
4181 routine calls the generic print routine for printing a message
4182 about reasons for stopping. This will print (for example) the
4183 "Breakpoint n," part of the output. The return value of this
4186 PRINT_UNKNOWN: Means we printed nothing.
4187 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4188 code to print the location. An example is
4189 "Breakpoint 1, " which should be followed by
4191 PRINT_SRC_ONLY: Means we printed something, but there is no need
4192 to also print the location part of the message.
4193 An example is the catch/throw messages, which
4194 don't require a location appended to the end.
4195 PRINT_NOTHING: We have done some printing and we don't need any
4196 further info to be printed. */
4198 enum print_stop_action
4199 bpstat_print (bpstat bs, int kind)
4203 /* Maybe another breakpoint in the chain caused us to stop.
4204 (Currently all watchpoints go on the bpstat whether hit or not.
4205 That probably could (should) be changed, provided care is taken
4206 with respect to bpstat_explains_signal). */
4207 for (; bs; bs = bs->next)
4209 val = print_bp_stop_message (bs);
4210 if (val == PRINT_SRC_ONLY
4211 || val == PRINT_SRC_AND_LOC
4212 || val == PRINT_NOTHING)
4216 /* If we had hit a shared library event breakpoint,
4217 print_bp_stop_message would print out this message. If we hit an
4218 OS-level shared library event, do the same thing. */
4219 if (kind == TARGET_WAITKIND_LOADED)
4221 print_solib_event (0);
4222 return PRINT_NOTHING;
4225 /* We reached the end of the chain, or we got a null BS to start
4226 with and nothing was printed. */
4227 return PRINT_UNKNOWN;
4230 /* Evaluate the expression EXP and return 1 if value is zero. This is
4231 used inside a catch_errors to evaluate the breakpoint condition.
4232 The argument is a "struct expression *" that has been cast to a
4233 "char *" to make it pass through catch_errors. */
4236 breakpoint_cond_eval (void *exp)
4238 struct value *mark = value_mark ();
4239 int i = !value_true (evaluate_expression ((struct expression *) exp));
4241 value_free_to_mark (mark);
4245 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4248 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
4252 bs = (bpstat) xmalloc (sizeof (*bs));
4254 **bs_link_pointer = bs;
4255 *bs_link_pointer = &bs->next;
4256 bs->breakpoint_at = bl->owner;
4257 bs->bp_location_at = bl;
4258 incref_bp_location (bl);
4259 /* If the condition is false, etc., don't do the commands. */
4260 bs->commands = NULL;
4262 bs->print_it = print_it_normal;
4266 /* The target has stopped with waitstatus WS. Check if any hardware
4267 watchpoints have triggered, according to the target. */
4270 watchpoints_triggered (struct target_waitstatus *ws)
4272 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
4274 struct breakpoint *b;
4276 if (!stopped_by_watchpoint)
4278 /* We were not stopped by a watchpoint. Mark all watchpoints
4279 as not triggered. */
4281 if (is_hardware_watchpoint (b))
4283 struct watchpoint *w = (struct watchpoint *) b;
4285 w->watchpoint_triggered = watch_triggered_no;
4291 if (!target_stopped_data_address (¤t_target, &addr))
4293 /* We were stopped by a watchpoint, but we don't know where.
4294 Mark all watchpoints as unknown. */
4296 if (is_hardware_watchpoint (b))
4298 struct watchpoint *w = (struct watchpoint *) b;
4300 w->watchpoint_triggered = watch_triggered_unknown;
4303 return stopped_by_watchpoint;
4306 /* The target could report the data address. Mark watchpoints
4307 affected by this data address as triggered, and all others as not
4311 if (is_hardware_watchpoint (b))
4313 struct watchpoint *w = (struct watchpoint *) b;
4314 struct bp_location *loc;
4316 w->watchpoint_triggered = watch_triggered_no;
4317 for (loc = b->loc; loc; loc = loc->next)
4319 if (is_masked_watchpoint (b))
4321 CORE_ADDR newaddr = addr & w->hw_wp_mask;
4322 CORE_ADDR start = loc->address & w->hw_wp_mask;
4324 if (newaddr == start)
4326 w->watchpoint_triggered = watch_triggered_yes;
4330 /* Exact match not required. Within range is sufficient. */
4331 else if (target_watchpoint_addr_within_range (¤t_target,
4335 w->watchpoint_triggered = watch_triggered_yes;
4344 /* Possible return values for watchpoint_check (this can't be an enum
4345 because of check_errors). */
4346 /* The watchpoint has been deleted. */
4347 #define WP_DELETED 1
4348 /* The value has changed. */
4349 #define WP_VALUE_CHANGED 2
4350 /* The value has not changed. */
4351 #define WP_VALUE_NOT_CHANGED 3
4352 /* Ignore this watchpoint, no matter if the value changed or not. */
4355 #define BP_TEMPFLAG 1
4356 #define BP_HARDWAREFLAG 2
4358 /* Evaluate watchpoint condition expression and check if its value
4361 P should be a pointer to struct bpstat, but is defined as a void *
4362 in order for this function to be usable with catch_errors. */
4365 watchpoint_check (void *p)
4367 bpstat bs = (bpstat) p;
4368 struct watchpoint *b;
4369 struct frame_info *fr;
4370 int within_current_scope;
4372 /* BS is built from an existing struct breakpoint. */
4373 gdb_assert (bs->breakpoint_at != NULL);
4374 b = (struct watchpoint *) bs->breakpoint_at;
4376 /* If this is a local watchpoint, we only want to check if the
4377 watchpoint frame is in scope if the current thread is the thread
4378 that was used to create the watchpoint. */
4379 if (!watchpoint_in_thread_scope (b))
4382 if (b->exp_valid_block == NULL)
4383 within_current_scope = 1;
4386 struct frame_info *frame = get_current_frame ();
4387 struct gdbarch *frame_arch = get_frame_arch (frame);
4388 CORE_ADDR frame_pc = get_frame_pc (frame);
4390 /* in_function_epilogue_p() returns a non-zero value if we're
4391 still in the function but the stack frame has already been
4392 invalidated. Since we can't rely on the values of local
4393 variables after the stack has been destroyed, we are treating
4394 the watchpoint in that state as `not changed' without further
4395 checking. Don't mark watchpoints as changed if the current
4396 frame is in an epilogue - even if they are in some other
4397 frame, our view of the stack is likely to be wrong and
4398 frame_find_by_id could error out. */
4399 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
4402 fr = frame_find_by_id (b->watchpoint_frame);
4403 within_current_scope = (fr != NULL);
4405 /* If we've gotten confused in the unwinder, we might have
4406 returned a frame that can't describe this variable. */
4407 if (within_current_scope)
4409 struct symbol *function;
4411 function = get_frame_function (fr);
4412 if (function == NULL
4413 || !contained_in (b->exp_valid_block,
4414 SYMBOL_BLOCK_VALUE (function)))
4415 within_current_scope = 0;
4418 if (within_current_scope)
4419 /* If we end up stopping, the current frame will get selected
4420 in normal_stop. So this call to select_frame won't affect
4425 if (within_current_scope)
4427 /* We use value_{,free_to_}mark because it could be a *long*
4428 time before we return to the command level and call
4429 free_all_values. We can't call free_all_values because we
4430 might be in the middle of evaluating a function call. */
4434 struct value *new_val;
4436 if (is_masked_watchpoint (&b->base))
4437 /* Since we don't know the exact trigger address (from
4438 stopped_data_address), just tell the user we've triggered
4439 a mask watchpoint. */
4440 return WP_VALUE_CHANGED;
4442 mark = value_mark ();
4443 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
4445 /* We use value_equal_contents instead of value_equal because
4446 the latter coerces an array to a pointer, thus comparing just
4447 the address of the array instead of its contents. This is
4448 not what we want. */
4449 if ((b->val != NULL) != (new_val != NULL)
4450 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
4452 if (new_val != NULL)
4454 release_value (new_val);
4455 value_free_to_mark (mark);
4457 bs->old_val = b->val;
4460 return WP_VALUE_CHANGED;
4464 /* Nothing changed. */
4465 value_free_to_mark (mark);
4466 return WP_VALUE_NOT_CHANGED;
4471 struct ui_out *uiout = current_uiout;
4473 /* This seems like the only logical thing to do because
4474 if we temporarily ignored the watchpoint, then when
4475 we reenter the block in which it is valid it contains
4476 garbage (in the case of a function, it may have two
4477 garbage values, one before and one after the prologue).
4478 So we can't even detect the first assignment to it and
4479 watch after that (since the garbage may or may not equal
4480 the first value assigned). */
4481 /* We print all the stop information in
4482 breakpoint_ops->print_it, but in this case, by the time we
4483 call breakpoint_ops->print_it this bp will be deleted
4484 already. So we have no choice but print the information
4486 if (ui_out_is_mi_like_p (uiout))
4488 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
4489 ui_out_text (uiout, "\nWatchpoint ");
4490 ui_out_field_int (uiout, "wpnum", b->base.number);
4492 " deleted because the program has left the block in\n\
4493 which its expression is valid.\n");
4495 /* Make sure the watchpoint's commands aren't executed. */
4496 decref_counted_command_line (&b->base.commands);
4497 watchpoint_del_at_next_stop (b);
4503 /* Return true if it looks like target has stopped due to hitting
4504 breakpoint location BL. This function does not check if we should
4505 stop, only if BL explains the stop. */
4508 bpstat_check_location (const struct bp_location *bl,
4509 struct address_space *aspace, CORE_ADDR bp_addr,
4510 const struct target_waitstatus *ws)
4512 struct breakpoint *b = bl->owner;
4514 /* BL is from an existing breakpoint. */
4515 gdb_assert (b != NULL);
4517 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
4520 /* Determine if the watched values have actually changed, and we
4521 should stop. If not, set BS->stop to 0. */
4524 bpstat_check_watchpoint (bpstat bs)
4526 const struct bp_location *bl;
4527 struct watchpoint *b;
4529 /* BS is built for existing struct breakpoint. */
4530 bl = bs->bp_location_at;
4531 gdb_assert (bl != NULL);
4532 b = (struct watchpoint *) bs->breakpoint_at;
4533 gdb_assert (b != NULL);
4536 int must_check_value = 0;
4538 if (b->base.type == bp_watchpoint)
4539 /* For a software watchpoint, we must always check the
4541 must_check_value = 1;
4542 else if (b->watchpoint_triggered == watch_triggered_yes)
4543 /* We have a hardware watchpoint (read, write, or access)
4544 and the target earlier reported an address watched by
4546 must_check_value = 1;
4547 else if (b->watchpoint_triggered == watch_triggered_unknown
4548 && b->base.type == bp_hardware_watchpoint)
4549 /* We were stopped by a hardware watchpoint, but the target could
4550 not report the data address. We must check the watchpoint's
4551 value. Access and read watchpoints are out of luck; without
4552 a data address, we can't figure it out. */
4553 must_check_value = 1;
4555 if (must_check_value)
4558 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4560 struct cleanup *cleanups = make_cleanup (xfree, message);
4561 int e = catch_errors (watchpoint_check, bs, message,
4563 do_cleanups (cleanups);
4567 /* We've already printed what needs to be printed. */
4568 bs->print_it = print_it_done;
4572 bs->print_it = print_it_noop;
4575 case WP_VALUE_CHANGED:
4576 if (b->base.type == bp_read_watchpoint)
4578 /* There are two cases to consider here:
4580 1. We're watching the triggered memory for reads.
4581 In that case, trust the target, and always report
4582 the watchpoint hit to the user. Even though
4583 reads don't cause value changes, the value may
4584 have changed since the last time it was read, and
4585 since we're not trapping writes, we will not see
4586 those, and as such we should ignore our notion of
4589 2. We're watching the triggered memory for both
4590 reads and writes. There are two ways this may
4593 2.1. This is a target that can't break on data
4594 reads only, but can break on accesses (reads or
4595 writes), such as e.g., x86. We detect this case
4596 at the time we try to insert read watchpoints.
4598 2.2. Otherwise, the target supports read
4599 watchpoints, but, the user set an access or write
4600 watchpoint watching the same memory as this read
4603 If we're watching memory writes as well as reads,
4604 ignore watchpoint hits when we find that the
4605 value hasn't changed, as reads don't cause
4606 changes. This still gives false positives when
4607 the program writes the same value to memory as
4608 what there was already in memory (we will confuse
4609 it for a read), but it's much better than
4612 int other_write_watchpoint = 0;
4614 if (bl->watchpoint_type == hw_read)
4616 struct breakpoint *other_b;
4618 ALL_BREAKPOINTS (other_b)
4619 if (other_b->type == bp_hardware_watchpoint
4620 || other_b->type == bp_access_watchpoint)
4622 struct watchpoint *other_w =
4623 (struct watchpoint *) other_b;
4625 if (other_w->watchpoint_triggered
4626 == watch_triggered_yes)
4628 other_write_watchpoint = 1;
4634 if (other_write_watchpoint
4635 || bl->watchpoint_type == hw_access)
4637 /* We're watching the same memory for writes,
4638 and the value changed since the last time we
4639 updated it, so this trap must be for a write.
4641 bs->print_it = print_it_noop;
4646 case WP_VALUE_NOT_CHANGED:
4647 if (b->base.type == bp_hardware_watchpoint
4648 || b->base.type == bp_watchpoint)
4650 /* Don't stop: write watchpoints shouldn't fire if
4651 the value hasn't changed. */
4652 bs->print_it = print_it_noop;
4660 /* Error from catch_errors. */
4661 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
4662 watchpoint_del_at_next_stop (b);
4663 /* We've already printed what needs to be printed. */
4664 bs->print_it = print_it_done;
4668 else /* must_check_value == 0 */
4670 /* This is a case where some watchpoint(s) triggered, but
4671 not at the address of this watchpoint, or else no
4672 watchpoint triggered after all. So don't print
4673 anything for this watchpoint. */
4674 bs->print_it = print_it_noop;
4681 /* Check conditions (condition proper, frame, thread and ignore count)
4682 of breakpoint referred to by BS. If we should not stop for this
4683 breakpoint, set BS->stop to 0. */
4686 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
4688 int thread_id = pid_to_thread_id (ptid);
4689 const struct bp_location *bl;
4690 struct breakpoint *b;
4692 /* BS is built for existing struct breakpoint. */
4693 bl = bs->bp_location_at;
4694 gdb_assert (bl != NULL);
4695 b = bs->breakpoint_at;
4696 gdb_assert (b != NULL);
4698 /* Even if the target evaluated the condition on its end and notified GDB, we
4699 need to do so again since GDB does not know if we stopped due to a
4700 breakpoint or a single step breakpoint. */
4702 if (frame_id_p (b->frame_id)
4703 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
4707 int value_is_zero = 0;
4708 struct expression *cond;
4710 /* Evaluate Python breakpoints that have a "stop"
4711 method implemented. */
4712 if (b->py_bp_object)
4713 bs->stop = gdbpy_should_stop (b->py_bp_object);
4715 if (is_watchpoint (b))
4717 struct watchpoint *w = (struct watchpoint *) b;
4724 if (cond && b->disposition != disp_del_at_next_stop)
4726 int within_current_scope = 1;
4727 struct watchpoint * w;
4729 /* We use value_mark and value_free_to_mark because it could
4730 be a long time before we return to the command level and
4731 call free_all_values. We can't call free_all_values
4732 because we might be in the middle of evaluating a
4734 struct value *mark = value_mark ();
4736 if (is_watchpoint (b))
4737 w = (struct watchpoint *) b;
4741 /* Need to select the frame, with all that implies so that
4742 the conditions will have the right context. Because we
4743 use the frame, we will not see an inlined function's
4744 variables when we arrive at a breakpoint at the start
4745 of the inlined function; the current frame will be the
4747 if (w == NULL || w->cond_exp_valid_block == NULL)
4748 select_frame (get_current_frame ());
4751 struct frame_info *frame;
4753 /* For local watchpoint expressions, which particular
4754 instance of a local is being watched matters, so we
4755 keep track of the frame to evaluate the expression
4756 in. To evaluate the condition however, it doesn't
4757 really matter which instantiation of the function
4758 where the condition makes sense triggers the
4759 watchpoint. This allows an expression like "watch
4760 global if q > 10" set in `func', catch writes to
4761 global on all threads that call `func', or catch
4762 writes on all recursive calls of `func' by a single
4763 thread. We simply always evaluate the condition in
4764 the innermost frame that's executing where it makes
4765 sense to evaluate the condition. It seems
4767 frame = block_innermost_frame (w->cond_exp_valid_block);
4769 select_frame (frame);
4771 within_current_scope = 0;
4773 if (within_current_scope)
4775 = catch_errors (breakpoint_cond_eval, cond,
4776 "Error in testing breakpoint condition:\n",
4780 warning (_("Watchpoint condition cannot be tested "
4781 "in the current scope"));
4782 /* If we failed to set the right context for this
4783 watchpoint, unconditionally report it. */
4786 /* FIXME-someday, should give breakpoint #. */
4787 value_free_to_mark (mark);
4790 if (cond && value_is_zero)
4794 else if (b->thread != -1 && b->thread != thread_id)
4798 else if (b->ignore_count > 0)
4801 annotate_ignore_count_change ();
4803 /* Increase the hit count even though we don't stop. */
4805 observer_notify_breakpoint_modified (b);
4811 /* Get a bpstat associated with having just stopped at address
4812 BP_ADDR in thread PTID.
4814 Determine whether we stopped at a breakpoint, etc, or whether we
4815 don't understand this stop. Result is a chain of bpstat's such
4818 if we don't understand the stop, the result is a null pointer.
4820 if we understand why we stopped, the result is not null.
4822 Each element of the chain refers to a particular breakpoint or
4823 watchpoint at which we have stopped. (We may have stopped for
4824 several reasons concurrently.)
4826 Each element of the chain has valid next, breakpoint_at,
4827 commands, FIXME??? fields. */
4830 bpstat_stop_status (struct address_space *aspace,
4831 CORE_ADDR bp_addr, ptid_t ptid,
4832 const struct target_waitstatus *ws)
4834 struct breakpoint *b = NULL;
4835 struct bp_location *bl;
4836 struct bp_location *loc;
4837 /* First item of allocated bpstat's. */
4838 bpstat bs_head = NULL, *bs_link = &bs_head;
4839 /* Pointer to the last thing in the chain currently. */
4842 int need_remove_insert;
4845 /* First, build the bpstat chain with locations that explain a
4846 target stop, while being careful to not set the target running,
4847 as that may invalidate locations (in particular watchpoint
4848 locations are recreated). Resuming will happen here with
4849 breakpoint conditions or watchpoint expressions that include
4850 inferior function calls. */
4854 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
4857 for (bl = b->loc; bl != NULL; bl = bl->next)
4859 /* For hardware watchpoints, we look only at the first
4860 location. The watchpoint_check function will work on the
4861 entire expression, not the individual locations. For
4862 read watchpoints, the watchpoints_triggered function has
4863 checked all locations already. */
4864 if (b->type == bp_hardware_watchpoint && bl != b->loc)
4867 if (bl->shlib_disabled)
4870 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
4873 /* Come here if it's a watchpoint, or if the break address
4876 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
4879 /* Assume we stop. Should we find a watchpoint that is not
4880 actually triggered, or if the condition of the breakpoint
4881 evaluates as false, we'll reset 'stop' to 0. */
4885 /* If this is a scope breakpoint, mark the associated
4886 watchpoint as triggered so that we will handle the
4887 out-of-scope event. We'll get to the watchpoint next
4889 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
4891 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
4893 w->watchpoint_triggered = watch_triggered_yes;
4898 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4900 if (breakpoint_location_address_match (loc, aspace, bp_addr))
4902 bs = bpstat_alloc (loc, &bs_link);
4903 /* For hits of moribund locations, we should just proceed. */
4906 bs->print_it = print_it_noop;
4910 /* A bit of special processing for shlib breakpoints. We need to
4911 process solib loading here, so that the lists of loaded and
4912 unloaded libraries are correct before we handle "catch load" and
4914 for (bs = bs_head; bs != NULL; bs = bs->next)
4916 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
4918 handle_solib_event ();
4923 /* Now go through the locations that caused the target to stop, and
4924 check whether we're interested in reporting this stop to higher
4925 layers, or whether we should resume the target transparently. */
4929 for (bs = bs_head; bs != NULL; bs = bs->next)
4934 b = bs->breakpoint_at;
4935 b->ops->check_status (bs);
4938 bpstat_check_breakpoint_conditions (bs, ptid);
4943 observer_notify_breakpoint_modified (b);
4945 /* We will stop here. */
4946 if (b->disposition == disp_disable)
4948 --(b->enable_count);
4949 if (b->enable_count <= 0
4950 && b->enable_state != bp_permanent)
4951 b->enable_state = bp_disabled;
4956 bs->commands = b->commands;
4957 incref_counted_command_line (bs->commands);
4958 if (command_line_is_silent (bs->commands
4959 ? bs->commands->commands : NULL))
4965 /* Print nothing for this entry if we don't stop or don't
4967 if (!bs->stop || !bs->print)
4968 bs->print_it = print_it_noop;
4971 /* If we aren't stopping, the value of some hardware watchpoint may
4972 not have changed, but the intermediate memory locations we are
4973 watching may have. Don't bother if we're stopping; this will get
4975 need_remove_insert = 0;
4976 if (! bpstat_causes_stop (bs_head))
4977 for (bs = bs_head; bs != NULL; bs = bs->next)
4979 && bs->breakpoint_at
4980 && is_hardware_watchpoint (bs->breakpoint_at))
4982 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
4984 update_watchpoint (w, 0 /* don't reparse. */);
4985 need_remove_insert = 1;
4988 if (need_remove_insert)
4989 update_global_location_list (1);
4990 else if (removed_any)
4991 update_global_location_list (0);
4997 handle_jit_event (void)
4999 struct frame_info *frame;
5000 struct gdbarch *gdbarch;
5002 /* Switch terminal for any messages produced by
5003 breakpoint_re_set. */
5004 target_terminal_ours_for_output ();
5006 frame = get_current_frame ();
5007 gdbarch = get_frame_arch (frame);
5009 jit_event_handler (gdbarch);
5011 target_terminal_inferior ();
5014 /* Handle an solib event by calling solib_add. */
5017 handle_solib_event (void)
5019 clear_program_space_solib_cache (current_inferior ()->pspace);
5021 /* Check for any newly added shared libraries if we're supposed to
5022 be adding them automatically. Switch terminal for any messages
5023 produced by breakpoint_re_set. */
5024 target_terminal_ours_for_output ();
5026 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
5028 solib_add (NULL, 0, ¤t_target, auto_solib_add);
5030 target_terminal_inferior ();
5033 /* Prepare WHAT final decision for infrun. */
5035 /* Decide what infrun needs to do with this bpstat. */
5038 bpstat_what (bpstat bs_head)
5040 struct bpstat_what retval;
5044 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5045 retval.call_dummy = STOP_NONE;
5046 retval.is_longjmp = 0;
5048 for (bs = bs_head; bs != NULL; bs = bs->next)
5050 /* Extract this BS's action. After processing each BS, we check
5051 if its action overrides all we've seem so far. */
5052 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5055 if (bs->breakpoint_at == NULL)
5057 /* I suspect this can happen if it was a momentary
5058 breakpoint which has since been deleted. */
5062 bptype = bs->breakpoint_at->type;
5069 case bp_hardware_breakpoint:
5072 case bp_shlib_event:
5076 this_action = BPSTAT_WHAT_STOP_NOISY;
5078 this_action = BPSTAT_WHAT_STOP_SILENT;
5081 this_action = BPSTAT_WHAT_SINGLE;
5084 case bp_hardware_watchpoint:
5085 case bp_read_watchpoint:
5086 case bp_access_watchpoint:
5090 this_action = BPSTAT_WHAT_STOP_NOISY;
5092 this_action = BPSTAT_WHAT_STOP_SILENT;
5096 /* There was a watchpoint, but we're not stopping.
5097 This requires no further action. */
5102 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5103 retval.is_longjmp = bptype == bp_longjmp;
5105 case bp_longjmp_resume:
5106 case bp_exception_resume:
5107 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5108 retval.is_longjmp = bptype == bp_longjmp_resume;
5110 case bp_step_resume:
5112 this_action = BPSTAT_WHAT_STEP_RESUME;
5115 /* It is for the wrong frame. */
5116 this_action = BPSTAT_WHAT_SINGLE;
5119 case bp_hp_step_resume:
5121 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5124 /* It is for the wrong frame. */
5125 this_action = BPSTAT_WHAT_SINGLE;
5128 case bp_watchpoint_scope:
5129 case bp_thread_event:
5130 case bp_overlay_event:
5131 case bp_longjmp_master:
5132 case bp_std_terminate_master:
5133 case bp_exception_master:
5134 this_action = BPSTAT_WHAT_SINGLE;
5140 this_action = BPSTAT_WHAT_STOP_NOISY;
5142 this_action = BPSTAT_WHAT_STOP_SILENT;
5146 /* There was a catchpoint, but we're not stopping.
5147 This requires no further action. */
5152 this_action = BPSTAT_WHAT_SINGLE;
5155 /* Make sure the action is stop (silent or noisy),
5156 so infrun.c pops the dummy frame. */
5157 retval.call_dummy = STOP_STACK_DUMMY;
5158 this_action = BPSTAT_WHAT_STOP_SILENT;
5160 case bp_std_terminate:
5161 /* Make sure the action is stop (silent or noisy),
5162 so infrun.c pops the dummy frame. */
5163 retval.call_dummy = STOP_STD_TERMINATE;
5164 this_action = BPSTAT_WHAT_STOP_SILENT;
5167 case bp_fast_tracepoint:
5168 case bp_static_tracepoint:
5169 /* Tracepoint hits should not be reported back to GDB, and
5170 if one got through somehow, it should have been filtered
5172 internal_error (__FILE__, __LINE__,
5173 _("bpstat_what: tracepoint encountered"));
5175 case bp_gnu_ifunc_resolver:
5176 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5177 this_action = BPSTAT_WHAT_SINGLE;
5179 case bp_gnu_ifunc_resolver_return:
5180 /* The breakpoint will be removed, execution will restart from the
5181 PC of the former breakpoint. */
5182 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5186 this_action = BPSTAT_WHAT_STOP_SILENT;
5190 internal_error (__FILE__, __LINE__,
5191 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5194 retval.main_action = max (retval.main_action, this_action);
5197 /* These operations may affect the bs->breakpoint_at state so they are
5198 delayed after MAIN_ACTION is decided above. */
5203 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
5205 handle_jit_event ();
5208 for (bs = bs_head; bs != NULL; bs = bs->next)
5210 struct breakpoint *b = bs->breakpoint_at;
5216 case bp_gnu_ifunc_resolver:
5217 gnu_ifunc_resolver_stop (b);
5219 case bp_gnu_ifunc_resolver_return:
5220 gnu_ifunc_resolver_return_stop (b);
5228 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5229 without hardware support). This isn't related to a specific bpstat,
5230 just to things like whether watchpoints are set. */
5233 bpstat_should_step (void)
5235 struct breakpoint *b;
5238 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
5244 bpstat_causes_stop (bpstat bs)
5246 for (; bs != NULL; bs = bs->next)
5255 /* Compute a string of spaces suitable to indent the next line
5256 so it starts at the position corresponding to the table column
5257 named COL_NAME in the currently active table of UIOUT. */
5260 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5262 static char wrap_indent[80];
5263 int i, total_width, width, align;
5267 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
5269 if (strcmp (text, col_name) == 0)
5271 gdb_assert (total_width < sizeof wrap_indent);
5272 memset (wrap_indent, ' ', total_width);
5273 wrap_indent[total_width] = 0;
5278 total_width += width + 1;
5284 /* Determine if the locations of this breakpoint will have their conditions
5285 evaluated by the target, host or a mix of both. Returns the following:
5287 "host": Host evals condition.
5288 "host or target": Host or Target evals condition.
5289 "target": Target evals condition.
5293 bp_condition_evaluator (struct breakpoint *b)
5295 struct bp_location *bl;
5296 char host_evals = 0;
5297 char target_evals = 0;
5302 if (!is_breakpoint (b))
5305 if (gdb_evaluates_breakpoint_condition_p ()
5306 || !target_supports_evaluation_of_breakpoint_conditions ())
5307 return condition_evaluation_host;
5309 for (bl = b->loc; bl; bl = bl->next)
5311 if (bl->cond_bytecode)
5317 if (host_evals && target_evals)
5318 return condition_evaluation_both;
5319 else if (target_evals)
5320 return condition_evaluation_target;
5322 return condition_evaluation_host;
5325 /* Determine the breakpoint location's condition evaluator. This is
5326 similar to bp_condition_evaluator, but for locations. */
5329 bp_location_condition_evaluator (struct bp_location *bl)
5331 if (bl && !is_breakpoint (bl->owner))
5334 if (gdb_evaluates_breakpoint_condition_p ()
5335 || !target_supports_evaluation_of_breakpoint_conditions ())
5336 return condition_evaluation_host;
5338 if (bl && bl->cond_bytecode)
5339 return condition_evaluation_target;
5341 return condition_evaluation_host;
5344 /* Print the LOC location out of the list of B->LOC locations. */
5347 print_breakpoint_location (struct breakpoint *b,
5348 struct bp_location *loc)
5350 struct ui_out *uiout = current_uiout;
5351 struct cleanup *old_chain = save_current_program_space ();
5353 if (loc != NULL && loc->shlib_disabled)
5357 set_current_program_space (loc->pspace);
5359 if (b->display_canonical)
5360 ui_out_field_string (uiout, "what", b->addr_string);
5361 else if (loc && loc->source_file)
5364 = find_pc_sect_function (loc->address, loc->section);
5367 ui_out_text (uiout, "in ");
5368 ui_out_field_string (uiout, "func",
5369 SYMBOL_PRINT_NAME (sym));
5370 ui_out_text (uiout, " ");
5371 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
5372 ui_out_text (uiout, "at ");
5374 ui_out_field_string (uiout, "file", loc->source_file);
5375 ui_out_text (uiout, ":");
5377 if (ui_out_is_mi_like_p (uiout))
5379 struct symtab_and_line sal = find_pc_line (loc->address, 0);
5380 char *fullname = symtab_to_fullname (sal.symtab);
5383 ui_out_field_string (uiout, "fullname", fullname);
5386 ui_out_field_int (uiout, "line", loc->line_number);
5390 struct ui_file *stb = mem_fileopen ();
5391 struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
5393 print_address_symbolic (loc->gdbarch, loc->address, stb,
5395 ui_out_field_stream (uiout, "at", stb);
5397 do_cleanups (stb_chain);
5400 ui_out_field_string (uiout, "pending", b->addr_string);
5402 if (loc && is_breakpoint (b)
5403 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5404 && bp_condition_evaluator (b) == condition_evaluation_both)
5406 ui_out_text (uiout, " (");
5407 ui_out_field_string (uiout, "evaluated-by",
5408 bp_location_condition_evaluator (loc));
5409 ui_out_text (uiout, ")");
5412 do_cleanups (old_chain);
5416 bptype_string (enum bptype type)
5418 struct ep_type_description
5423 static struct ep_type_description bptypes[] =
5425 {bp_none, "?deleted?"},
5426 {bp_breakpoint, "breakpoint"},
5427 {bp_hardware_breakpoint, "hw breakpoint"},
5428 {bp_until, "until"},
5429 {bp_finish, "finish"},
5430 {bp_watchpoint, "watchpoint"},
5431 {bp_hardware_watchpoint, "hw watchpoint"},
5432 {bp_read_watchpoint, "read watchpoint"},
5433 {bp_access_watchpoint, "acc watchpoint"},
5434 {bp_longjmp, "longjmp"},
5435 {bp_longjmp_resume, "longjmp resume"},
5436 {bp_exception, "exception"},
5437 {bp_exception_resume, "exception resume"},
5438 {bp_step_resume, "step resume"},
5439 {bp_hp_step_resume, "high-priority step resume"},
5440 {bp_watchpoint_scope, "watchpoint scope"},
5441 {bp_call_dummy, "call dummy"},
5442 {bp_std_terminate, "std::terminate"},
5443 {bp_shlib_event, "shlib events"},
5444 {bp_thread_event, "thread events"},
5445 {bp_overlay_event, "overlay events"},
5446 {bp_longjmp_master, "longjmp master"},
5447 {bp_std_terminate_master, "std::terminate master"},
5448 {bp_exception_master, "exception master"},
5449 {bp_catchpoint, "catchpoint"},
5450 {bp_tracepoint, "tracepoint"},
5451 {bp_fast_tracepoint, "fast tracepoint"},
5452 {bp_static_tracepoint, "static tracepoint"},
5453 {bp_dprintf, "dprintf"},
5454 {bp_jit_event, "jit events"},
5455 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
5456 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
5459 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
5460 || ((int) type != bptypes[(int) type].type))
5461 internal_error (__FILE__, __LINE__,
5462 _("bptypes table does not describe type #%d."),
5465 return bptypes[(int) type].description;
5468 /* Print B to gdb_stdout. */
5471 print_one_breakpoint_location (struct breakpoint *b,
5472 struct bp_location *loc,
5474 struct bp_location **last_loc,
5477 struct command_line *l;
5478 static char bpenables[] = "nynny";
5480 struct ui_out *uiout = current_uiout;
5481 int header_of_multiple = 0;
5482 int part_of_multiple = (loc != NULL);
5483 struct value_print_options opts;
5485 get_user_print_options (&opts);
5487 gdb_assert (!loc || loc_number != 0);
5488 /* See comment in print_one_breakpoint concerning treatment of
5489 breakpoints with single disabled location. */
5492 && (b->loc->next != NULL || !b->loc->enabled)))
5493 header_of_multiple = 1;
5501 if (part_of_multiple)
5504 formatted = xstrprintf ("%d.%d", b->number, loc_number);
5505 ui_out_field_string (uiout, "number", formatted);
5510 ui_out_field_int (uiout, "number", b->number);
5515 if (part_of_multiple)
5516 ui_out_field_skip (uiout, "type");
5518 ui_out_field_string (uiout, "type", bptype_string (b->type));
5522 if (part_of_multiple)
5523 ui_out_field_skip (uiout, "disp");
5525 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
5530 if (part_of_multiple)
5531 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
5533 ui_out_field_fmt (uiout, "enabled", "%c",
5534 bpenables[(int) b->enable_state]);
5535 ui_out_spaces (uiout, 2);
5539 if (b->ops != NULL && b->ops->print_one != NULL)
5541 /* Although the print_one can possibly print all locations,
5542 calling it here is not likely to get any nice result. So,
5543 make sure there's just one location. */
5544 gdb_assert (b->loc == NULL || b->loc->next == NULL);
5545 b->ops->print_one (b, last_loc);
5551 internal_error (__FILE__, __LINE__,
5552 _("print_one_breakpoint: bp_none encountered\n"));
5556 case bp_hardware_watchpoint:
5557 case bp_read_watchpoint:
5558 case bp_access_watchpoint:
5560 struct watchpoint *w = (struct watchpoint *) b;
5562 /* Field 4, the address, is omitted (which makes the columns
5563 not line up too nicely with the headers, but the effect
5564 is relatively readable). */
5565 if (opts.addressprint)
5566 ui_out_field_skip (uiout, "addr");
5568 ui_out_field_string (uiout, "what", w->exp_string);
5573 case bp_hardware_breakpoint:
5577 case bp_longjmp_resume:
5579 case bp_exception_resume:
5580 case bp_step_resume:
5581 case bp_hp_step_resume:
5582 case bp_watchpoint_scope:
5584 case bp_std_terminate:
5585 case bp_shlib_event:
5586 case bp_thread_event:
5587 case bp_overlay_event:
5588 case bp_longjmp_master:
5589 case bp_std_terminate_master:
5590 case bp_exception_master:
5592 case bp_fast_tracepoint:
5593 case bp_static_tracepoint:
5596 case bp_gnu_ifunc_resolver:
5597 case bp_gnu_ifunc_resolver_return:
5598 if (opts.addressprint)
5601 if (header_of_multiple)
5602 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
5603 else if (b->loc == NULL || loc->shlib_disabled)
5604 ui_out_field_string (uiout, "addr", "<PENDING>");
5606 ui_out_field_core_addr (uiout, "addr",
5607 loc->gdbarch, loc->address);
5610 if (!header_of_multiple)
5611 print_breakpoint_location (b, loc);
5618 /* For backward compatibility, don't display inferiors unless there
5621 && !header_of_multiple
5623 || (!gdbarch_has_global_breakpoints (target_gdbarch)
5624 && (number_of_program_spaces () > 1
5625 || number_of_inferiors () > 1)
5626 /* LOC is for existing B, it cannot be in
5627 moribund_locations and thus having NULL OWNER. */
5628 && loc->owner->type != bp_catchpoint)))
5630 struct inferior *inf;
5633 for (inf = inferior_list; inf != NULL; inf = inf->next)
5635 if (inf->pspace == loc->pspace)
5640 ui_out_text (uiout, " inf ");
5643 ui_out_text (uiout, ", ");
5644 ui_out_text (uiout, plongest (inf->num));
5649 if (!part_of_multiple)
5651 if (b->thread != -1)
5653 /* FIXME: This seems to be redundant and lost here; see the
5654 "stop only in" line a little further down. */
5655 ui_out_text (uiout, " thread ");
5656 ui_out_field_int (uiout, "thread", b->thread);
5658 else if (b->task != 0)
5660 ui_out_text (uiout, " task ");
5661 ui_out_field_int (uiout, "task", b->task);
5665 ui_out_text (uiout, "\n");
5667 if (!part_of_multiple)
5668 b->ops->print_one_detail (b, uiout);
5670 if (part_of_multiple && frame_id_p (b->frame_id))
5673 ui_out_text (uiout, "\tstop only in stack frame at ");
5674 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
5676 ui_out_field_core_addr (uiout, "frame",
5677 b->gdbarch, b->frame_id.stack_addr);
5678 ui_out_text (uiout, "\n");
5681 if (!part_of_multiple && b->cond_string)
5684 if (is_tracepoint (b))
5685 ui_out_text (uiout, "\ttrace only if ");
5687 ui_out_text (uiout, "\tstop only if ");
5688 ui_out_field_string (uiout, "cond", b->cond_string);
5690 /* Print whether the target is doing the breakpoint's condition
5691 evaluation. If GDB is doing the evaluation, don't print anything. */
5692 if (is_breakpoint (b)
5693 && breakpoint_condition_evaluation_mode ()
5694 == condition_evaluation_target)
5696 ui_out_text (uiout, " (");
5697 ui_out_field_string (uiout, "evaluated-by",
5698 bp_condition_evaluator (b));
5699 ui_out_text (uiout, " evals)");
5701 ui_out_text (uiout, "\n");
5704 if (!part_of_multiple && b->thread != -1)
5706 /* FIXME should make an annotation for this. */
5707 ui_out_text (uiout, "\tstop only in thread ");
5708 ui_out_field_int (uiout, "thread", b->thread);
5709 ui_out_text (uiout, "\n");
5712 if (!part_of_multiple && b->hit_count)
5714 /* FIXME should make an annotation for this. */
5715 if (is_catchpoint (b))
5716 ui_out_text (uiout, "\tcatchpoint");
5717 else if (is_tracepoint (b))
5718 ui_out_text (uiout, "\ttracepoint");
5720 ui_out_text (uiout, "\tbreakpoint");
5721 ui_out_text (uiout, " already hit ");
5722 ui_out_field_int (uiout, "times", b->hit_count);
5723 if (b->hit_count == 1)
5724 ui_out_text (uiout, " time\n");
5726 ui_out_text (uiout, " times\n");
5729 /* Output the count also if it is zero, but only if this is mi.
5730 FIXME: Should have a better test for this. */
5731 if (ui_out_is_mi_like_p (uiout))
5732 if (!part_of_multiple && b->hit_count == 0)
5733 ui_out_field_int (uiout, "times", b->hit_count);
5735 if (!part_of_multiple && b->ignore_count)
5738 ui_out_text (uiout, "\tignore next ");
5739 ui_out_field_int (uiout, "ignore", b->ignore_count);
5740 ui_out_text (uiout, " hits\n");
5743 /* Note that an enable count of 1 corresponds to "enable once"
5744 behavior, which is reported by the combination of enablement and
5745 disposition, so we don't need to mention it here. */
5746 if (!part_of_multiple && b->enable_count > 1)
5749 ui_out_text (uiout, "\tdisable after ");
5750 /* Tweak the wording to clarify that ignore and enable counts
5751 are distinct, and have additive effect. */
5752 if (b->ignore_count)
5753 ui_out_text (uiout, "additional ");
5755 ui_out_text (uiout, "next ");
5756 ui_out_field_int (uiout, "enable", b->enable_count);
5757 ui_out_text (uiout, " hits\n");
5760 if (!part_of_multiple && is_tracepoint (b))
5762 struct tracepoint *tp = (struct tracepoint *) b;
5764 if (tp->traceframe_usage)
5766 ui_out_text (uiout, "\ttrace buffer usage ");
5767 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
5768 ui_out_text (uiout, " bytes\n");
5772 l = b->commands ? b->commands->commands : NULL;
5773 if (!part_of_multiple && l)
5775 struct cleanup *script_chain;
5778 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
5779 print_command_lines (uiout, l, 4);
5780 do_cleanups (script_chain);
5783 if (is_tracepoint (b))
5785 struct tracepoint *t = (struct tracepoint *) b;
5787 if (!part_of_multiple && t->pass_count)
5789 annotate_field (10);
5790 ui_out_text (uiout, "\tpass count ");
5791 ui_out_field_int (uiout, "pass", t->pass_count);
5792 ui_out_text (uiout, " \n");
5796 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
5798 if (is_watchpoint (b))
5800 struct watchpoint *w = (struct watchpoint *) b;
5802 ui_out_field_string (uiout, "original-location", w->exp_string);
5804 else if (b->addr_string)
5805 ui_out_field_string (uiout, "original-location", b->addr_string);
5810 print_one_breakpoint (struct breakpoint *b,
5811 struct bp_location **last_loc,
5814 struct cleanup *bkpt_chain;
5815 struct ui_out *uiout = current_uiout;
5817 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
5819 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
5820 do_cleanups (bkpt_chain);
5822 /* If this breakpoint has custom print function,
5823 it's already printed. Otherwise, print individual
5824 locations, if any. */
5825 if (b->ops == NULL || b->ops->print_one == NULL)
5827 /* If breakpoint has a single location that is disabled, we
5828 print it as if it had several locations, since otherwise it's
5829 hard to represent "breakpoint enabled, location disabled"
5832 Note that while hardware watchpoints have several locations
5833 internally, that's not a property exposed to user. */
5835 && !is_hardware_watchpoint (b)
5836 && (b->loc->next || !b->loc->enabled))
5838 struct bp_location *loc;
5841 for (loc = b->loc; loc; loc = loc->next, ++n)
5843 struct cleanup *inner2 =
5844 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
5845 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
5846 do_cleanups (inner2);
5853 breakpoint_address_bits (struct breakpoint *b)
5855 int print_address_bits = 0;
5856 struct bp_location *loc;
5858 for (loc = b->loc; loc; loc = loc->next)
5862 /* Software watchpoints that aren't watching memory don't have
5863 an address to print. */
5864 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
5867 addr_bit = gdbarch_addr_bit (loc->gdbarch);
5868 if (addr_bit > print_address_bits)
5869 print_address_bits = addr_bit;
5872 return print_address_bits;
5875 struct captured_breakpoint_query_args
5881 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
5883 struct captured_breakpoint_query_args *args = data;
5884 struct breakpoint *b;
5885 struct bp_location *dummy_loc = NULL;
5889 if (args->bnum == b->number)
5891 print_one_breakpoint (b, &dummy_loc, 0);
5899 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
5900 char **error_message)
5902 struct captured_breakpoint_query_args args;
5905 /* For the moment we don't trust print_one_breakpoint() to not throw
5907 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
5908 error_message, RETURN_MASK_ALL) < 0)
5914 /* Return true if this breakpoint was set by the user, false if it is
5915 internal or momentary. */
5918 user_breakpoint_p (struct breakpoint *b)
5920 return b->number > 0;
5923 /* Print information on user settable breakpoint (watchpoint, etc)
5924 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5925 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5926 FILTER is non-NULL, call it on each breakpoint and only include the
5927 ones for which it returns non-zero. Return the total number of
5928 breakpoints listed. */
5931 breakpoint_1 (char *args, int allflag,
5932 int (*filter) (const struct breakpoint *))
5934 struct breakpoint *b;
5935 struct bp_location *last_loc = NULL;
5936 int nr_printable_breakpoints;
5937 struct cleanup *bkpttbl_chain;
5938 struct value_print_options opts;
5939 int print_address_bits = 0;
5940 int print_type_col_width = 14;
5941 struct ui_out *uiout = current_uiout;
5943 get_user_print_options (&opts);
5945 /* Compute the number of rows in the table, as well as the size
5946 required for address fields. */
5947 nr_printable_breakpoints = 0;
5950 /* If we have a filter, only list the breakpoints it accepts. */
5951 if (filter && !filter (b))
5954 /* If we have an "args" string, it is a list of breakpoints to
5955 accept. Skip the others. */
5956 if (args != NULL && *args != '\0')
5958 if (allflag && parse_and_eval_long (args) != b->number)
5960 if (!allflag && !number_is_in_list (args, b->number))
5964 if (allflag || user_breakpoint_p (b))
5966 int addr_bit, type_len;
5968 addr_bit = breakpoint_address_bits (b);
5969 if (addr_bit > print_address_bits)
5970 print_address_bits = addr_bit;
5972 type_len = strlen (bptype_string (b->type));
5973 if (type_len > print_type_col_width)
5974 print_type_col_width = type_len;
5976 nr_printable_breakpoints++;
5980 if (opts.addressprint)
5982 = make_cleanup_ui_out_table_begin_end (uiout, 6,
5983 nr_printable_breakpoints,
5987 = make_cleanup_ui_out_table_begin_end (uiout, 5,
5988 nr_printable_breakpoints,
5991 if (nr_printable_breakpoints > 0)
5992 annotate_breakpoints_headers ();
5993 if (nr_printable_breakpoints > 0)
5995 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
5996 if (nr_printable_breakpoints > 0)
5998 ui_out_table_header (uiout, print_type_col_width, ui_left,
5999 "type", "Type"); /* 2 */
6000 if (nr_printable_breakpoints > 0)
6002 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
6003 if (nr_printable_breakpoints > 0)
6005 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
6006 if (opts.addressprint)
6008 if (nr_printable_breakpoints > 0)
6010 if (print_address_bits <= 32)
6011 ui_out_table_header (uiout, 10, ui_left,
6012 "addr", "Address"); /* 5 */
6014 ui_out_table_header (uiout, 18, ui_left,
6015 "addr", "Address"); /* 5 */
6017 if (nr_printable_breakpoints > 0)
6019 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
6020 ui_out_table_body (uiout);
6021 if (nr_printable_breakpoints > 0)
6022 annotate_breakpoints_table ();
6027 /* If we have a filter, only list the breakpoints it accepts. */
6028 if (filter && !filter (b))
6031 /* If we have an "args" string, it is a list of breakpoints to
6032 accept. Skip the others. */
6034 if (args != NULL && *args != '\0')
6036 if (allflag) /* maintenance info breakpoint */
6038 if (parse_and_eval_long (args) != b->number)
6041 else /* all others */
6043 if (!number_is_in_list (args, b->number))
6047 /* We only print out user settable breakpoints unless the
6049 if (allflag || user_breakpoint_p (b))
6050 print_one_breakpoint (b, &last_loc, allflag);
6053 do_cleanups (bkpttbl_chain);
6055 if (nr_printable_breakpoints == 0)
6057 /* If there's a filter, let the caller decide how to report
6061 if (args == NULL || *args == '\0')
6062 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
6064 ui_out_message (uiout, 0,
6065 "No breakpoint or watchpoint matching '%s'.\n",
6071 if (last_loc && !server_command)
6072 set_next_address (last_loc->gdbarch, last_loc->address);
6075 /* FIXME? Should this be moved up so that it is only called when
6076 there have been breakpoints? */
6077 annotate_breakpoints_table_end ();
6079 return nr_printable_breakpoints;
6082 /* Display the value of default-collect in a way that is generally
6083 compatible with the breakpoint list. */
6086 default_collect_info (void)
6088 struct ui_out *uiout = current_uiout;
6090 /* If it has no value (which is frequently the case), say nothing; a
6091 message like "No default-collect." gets in user's face when it's
6093 if (!*default_collect)
6096 /* The following phrase lines up nicely with per-tracepoint collect
6098 ui_out_text (uiout, "default collect ");
6099 ui_out_field_string (uiout, "default-collect", default_collect);
6100 ui_out_text (uiout, " \n");
6104 breakpoints_info (char *args, int from_tty)
6106 breakpoint_1 (args, 0, NULL);
6108 default_collect_info ();
6112 watchpoints_info (char *args, int from_tty)
6114 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6115 struct ui_out *uiout = current_uiout;
6117 if (num_printed == 0)
6119 if (args == NULL || *args == '\0')
6120 ui_out_message (uiout, 0, "No watchpoints.\n");
6122 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
6127 maintenance_info_breakpoints (char *args, int from_tty)
6129 breakpoint_1 (args, 1, NULL);
6131 default_collect_info ();
6135 breakpoint_has_pc (struct breakpoint *b,
6136 struct program_space *pspace,
6137 CORE_ADDR pc, struct obj_section *section)
6139 struct bp_location *bl = b->loc;
6141 for (; bl; bl = bl->next)
6143 if (bl->pspace == pspace
6144 && bl->address == pc
6145 && (!overlay_debugging || bl->section == section))
6151 /* Print a message describing any user-breakpoints set at PC. This
6152 concerns with logical breakpoints, so we match program spaces, not
6156 describe_other_breakpoints (struct gdbarch *gdbarch,
6157 struct program_space *pspace, CORE_ADDR pc,
6158 struct obj_section *section, int thread)
6161 struct breakpoint *b;
6164 others += (user_breakpoint_p (b)
6165 && breakpoint_has_pc (b, pspace, pc, section));
6169 printf_filtered (_("Note: breakpoint "));
6170 else /* if (others == ???) */
6171 printf_filtered (_("Note: breakpoints "));
6173 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
6176 printf_filtered ("%d", b->number);
6177 if (b->thread == -1 && thread != -1)
6178 printf_filtered (" (all threads)");
6179 else if (b->thread != -1)
6180 printf_filtered (" (thread %d)", b->thread);
6181 printf_filtered ("%s%s ",
6182 ((b->enable_state == bp_disabled
6183 || b->enable_state == bp_call_disabled)
6185 : b->enable_state == bp_permanent
6189 : ((others == 1) ? " and" : ""));
6191 printf_filtered (_("also set at pc "));
6192 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
6193 printf_filtered (".\n");
6198 /* Return true iff it is meaningful to use the address member of
6199 BPT. For some breakpoint types, the address member is irrelevant
6200 and it makes no sense to attempt to compare it to other addresses
6201 (or use it for any other purpose either).
6203 More specifically, each of the following breakpoint types will
6204 always have a zero valued address and we don't want to mark
6205 breakpoints of any of these types to be a duplicate of an actual
6206 breakpoint at address zero:
6214 breakpoint_address_is_meaningful (struct breakpoint *bpt)
6216 enum bptype type = bpt->type;
6218 return (type != bp_watchpoint && type != bp_catchpoint);
6221 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6222 true if LOC1 and LOC2 represent the same watchpoint location. */
6225 watchpoint_locations_match (struct bp_location *loc1,
6226 struct bp_location *loc2)
6228 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6229 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6231 /* Both of them must exist. */
6232 gdb_assert (w1 != NULL);
6233 gdb_assert (w2 != NULL);
6235 /* If the target can evaluate the condition expression in hardware,
6236 then we we need to insert both watchpoints even if they are at
6237 the same place. Otherwise the watchpoint will only trigger when
6238 the condition of whichever watchpoint was inserted evaluates to
6239 true, not giving a chance for GDB to check the condition of the
6240 other watchpoint. */
6242 && target_can_accel_watchpoint_condition (loc1->address,
6244 loc1->watchpoint_type,
6247 && target_can_accel_watchpoint_condition (loc2->address,
6249 loc2->watchpoint_type,
6253 /* Note that this checks the owner's type, not the location's. In
6254 case the target does not support read watchpoints, but does
6255 support access watchpoints, we'll have bp_read_watchpoint
6256 watchpoints with hw_access locations. Those should be considered
6257 duplicates of hw_read locations. The hw_read locations will
6258 become hw_access locations later. */
6259 return (loc1->owner->type == loc2->owner->type
6260 && loc1->pspace->aspace == loc2->pspace->aspace
6261 && loc1->address == loc2->address
6262 && loc1->length == loc2->length);
6265 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6266 same breakpoint location. In most targets, this can only be true
6267 if ASPACE1 matches ASPACE2. On targets that have global
6268 breakpoints, the address space doesn't really matter. */
6271 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
6272 struct address_space *aspace2, CORE_ADDR addr2)
6274 return ((gdbarch_has_global_breakpoints (target_gdbarch)
6275 || aspace1 == aspace2)
6279 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6280 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6281 matches ASPACE2. On targets that have global breakpoints, the address
6282 space doesn't really matter. */
6285 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
6286 int len1, struct address_space *aspace2,
6289 return ((gdbarch_has_global_breakpoints (target_gdbarch)
6290 || aspace1 == aspace2)
6291 && addr2 >= addr1 && addr2 < addr1 + len1);
6294 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6295 a ranged breakpoint. In most targets, a match happens only if ASPACE
6296 matches the breakpoint's address space. On targets that have global
6297 breakpoints, the address space doesn't really matter. */
6300 breakpoint_location_address_match (struct bp_location *bl,
6301 struct address_space *aspace,
6304 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
6307 && breakpoint_address_match_range (bl->pspace->aspace,
6308 bl->address, bl->length,
6312 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6313 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6314 true, otherwise returns false. */
6317 tracepoint_locations_match (struct bp_location *loc1,
6318 struct bp_location *loc2)
6320 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
6321 /* Since tracepoint locations are never duplicated with others', tracepoint
6322 locations at the same address of different tracepoints are regarded as
6323 different locations. */
6324 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
6329 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6330 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6331 represent the same location. */
6334 breakpoint_locations_match (struct bp_location *loc1,
6335 struct bp_location *loc2)
6337 int hw_point1, hw_point2;
6339 /* Both of them must not be in moribund_locations. */
6340 gdb_assert (loc1->owner != NULL);
6341 gdb_assert (loc2->owner != NULL);
6343 hw_point1 = is_hardware_watchpoint (loc1->owner);
6344 hw_point2 = is_hardware_watchpoint (loc2->owner);
6346 if (hw_point1 != hw_point2)
6349 return watchpoint_locations_match (loc1, loc2);
6350 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
6351 return tracepoint_locations_match (loc1, loc2);
6353 /* We compare bp_location.length in order to cover ranged breakpoints. */
6354 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
6355 loc2->pspace->aspace, loc2->address)
6356 && loc1->length == loc2->length);
6360 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
6361 int bnum, int have_bnum)
6363 /* The longest string possibly returned by hex_string_custom
6364 is 50 chars. These must be at least that big for safety. */
6368 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
6369 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
6371 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6372 bnum, astr1, astr2);
6374 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
6377 /* Adjust a breakpoint's address to account for architectural
6378 constraints on breakpoint placement. Return the adjusted address.
6379 Note: Very few targets require this kind of adjustment. For most
6380 targets, this function is simply the identity function. */
6383 adjust_breakpoint_address (struct gdbarch *gdbarch,
6384 CORE_ADDR bpaddr, enum bptype bptype)
6386 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
6388 /* Very few targets need any kind of breakpoint adjustment. */
6391 else if (bptype == bp_watchpoint
6392 || bptype == bp_hardware_watchpoint
6393 || bptype == bp_read_watchpoint
6394 || bptype == bp_access_watchpoint
6395 || bptype == bp_catchpoint)
6397 /* Watchpoints and the various bp_catch_* eventpoints should not
6398 have their addresses modified. */
6403 CORE_ADDR adjusted_bpaddr;
6405 /* Some targets have architectural constraints on the placement
6406 of breakpoint instructions. Obtain the adjusted address. */
6407 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
6409 /* An adjusted breakpoint address can significantly alter
6410 a user's expectations. Print a warning if an adjustment
6412 if (adjusted_bpaddr != bpaddr)
6413 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
6415 return adjusted_bpaddr;
6420 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
6421 struct breakpoint *owner)
6423 memset (loc, 0, sizeof (*loc));
6425 gdb_assert (ops != NULL);
6430 loc->cond_bytecode = NULL;
6431 loc->shlib_disabled = 0;
6434 switch (owner->type)
6440 case bp_longjmp_resume:
6442 case bp_exception_resume:
6443 case bp_step_resume:
6444 case bp_hp_step_resume:
6445 case bp_watchpoint_scope:
6447 case bp_std_terminate:
6448 case bp_shlib_event:
6449 case bp_thread_event:
6450 case bp_overlay_event:
6452 case bp_longjmp_master:
6453 case bp_std_terminate_master:
6454 case bp_exception_master:
6455 case bp_gnu_ifunc_resolver:
6456 case bp_gnu_ifunc_resolver_return:
6458 loc->loc_type = bp_loc_software_breakpoint;
6459 mark_breakpoint_location_modified (loc);
6461 case bp_hardware_breakpoint:
6462 loc->loc_type = bp_loc_hardware_breakpoint;
6463 mark_breakpoint_location_modified (loc);
6465 case bp_hardware_watchpoint:
6466 case bp_read_watchpoint:
6467 case bp_access_watchpoint:
6468 loc->loc_type = bp_loc_hardware_watchpoint;
6473 case bp_fast_tracepoint:
6474 case bp_static_tracepoint:
6475 loc->loc_type = bp_loc_other;
6478 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
6484 /* Allocate a struct bp_location. */
6486 static struct bp_location *
6487 allocate_bp_location (struct breakpoint *bpt)
6489 return bpt->ops->allocate_location (bpt);
6493 free_bp_location (struct bp_location *loc)
6495 loc->ops->dtor (loc);
6499 /* Increment reference count. */
6502 incref_bp_location (struct bp_location *bl)
6507 /* Decrement reference count. If the reference count reaches 0,
6508 destroy the bp_location. Sets *BLP to NULL. */
6511 decref_bp_location (struct bp_location **blp)
6513 gdb_assert ((*blp)->refc > 0);
6515 if (--(*blp)->refc == 0)
6516 free_bp_location (*blp);
6520 /* Add breakpoint B at the end of the global breakpoint chain. */
6523 add_to_breakpoint_chain (struct breakpoint *b)
6525 struct breakpoint *b1;
6527 /* Add this breakpoint to the end of the chain so that a list of
6528 breakpoints will come out in order of increasing numbers. */
6530 b1 = breakpoint_chain;
6532 breakpoint_chain = b;
6541 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
6544 init_raw_breakpoint_without_location (struct breakpoint *b,
6545 struct gdbarch *gdbarch,
6547 const struct breakpoint_ops *ops)
6549 memset (b, 0, sizeof (*b));
6551 gdb_assert (ops != NULL);
6555 b->gdbarch = gdbarch;
6556 b->language = current_language->la_language;
6557 b->input_radix = input_radix;
6559 b->enable_state = bp_enabled;
6562 b->ignore_count = 0;
6564 b->frame_id = null_frame_id;
6565 b->condition_not_parsed = 0;
6566 b->py_bp_object = NULL;
6567 b->related_breakpoint = b;
6570 /* Helper to set_raw_breakpoint below. Creates a breakpoint
6571 that has type BPTYPE and has no locations as yet. */
6573 static struct breakpoint *
6574 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
6576 const struct breakpoint_ops *ops)
6578 struct breakpoint *b = XNEW (struct breakpoint);
6580 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
6581 add_to_breakpoint_chain (b);
6585 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
6586 resolutions should be made as the user specified the location explicitly
6590 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
6592 gdb_assert (loc->owner != NULL);
6594 if (loc->owner->type == bp_breakpoint
6595 || loc->owner->type == bp_hardware_breakpoint
6596 || is_tracepoint (loc->owner))
6599 const char *function_name;
6600 CORE_ADDR func_addr;
6602 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
6603 &func_addr, NULL, &is_gnu_ifunc);
6605 if (is_gnu_ifunc && !explicit_loc)
6607 struct breakpoint *b = loc->owner;
6609 gdb_assert (loc->pspace == current_program_space);
6610 if (gnu_ifunc_resolve_name (function_name,
6611 &loc->requested_address))
6613 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
6614 loc->address = adjust_breakpoint_address (loc->gdbarch,
6615 loc->requested_address,
6618 else if (b->type == bp_breakpoint && b->loc == loc
6619 && loc->next == NULL && b->related_breakpoint == b)
6621 /* Create only the whole new breakpoint of this type but do not
6622 mess more complicated breakpoints with multiple locations. */
6623 b->type = bp_gnu_ifunc_resolver;
6624 /* Remember the resolver's address for use by the return
6626 loc->related_address = func_addr;
6631 loc->function_name = xstrdup (function_name);
6635 /* Attempt to determine architecture of location identified by SAL. */
6637 get_sal_arch (struct symtab_and_line sal)
6640 return get_objfile_arch (sal.section->objfile);
6642 return get_objfile_arch (sal.symtab->objfile);
6647 /* Low level routine for partially initializing a breakpoint of type
6648 BPTYPE. The newly created breakpoint's address, section, source
6649 file name, and line number are provided by SAL.
6651 It is expected that the caller will complete the initialization of
6652 the newly created breakpoint struct as well as output any status
6653 information regarding the creation of a new breakpoint. */
6656 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
6657 struct symtab_and_line sal, enum bptype bptype,
6658 const struct breakpoint_ops *ops)
6660 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
6662 add_location_to_breakpoint (b, &sal);
6664 if (bptype != bp_catchpoint)
6665 gdb_assert (sal.pspace != NULL);
6667 /* Store the program space that was used to set the breakpoint,
6668 except for ordinary breakpoints, which are independent of the
6670 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
6671 b->pspace = sal.pspace;
6673 breakpoints_changed ();
6676 /* set_raw_breakpoint is a low level routine for allocating and
6677 partially initializing a breakpoint of type BPTYPE. The newly
6678 created breakpoint's address, section, source file name, and line
6679 number are provided by SAL. The newly created and partially
6680 initialized breakpoint is added to the breakpoint chain and
6681 is also returned as the value of this function.
6683 It is expected that the caller will complete the initialization of
6684 the newly created breakpoint struct as well as output any status
6685 information regarding the creation of a new breakpoint. In
6686 particular, set_raw_breakpoint does NOT set the breakpoint
6687 number! Care should be taken to not allow an error to occur
6688 prior to completing the initialization of the breakpoint. If this
6689 should happen, a bogus breakpoint will be left on the chain. */
6692 set_raw_breakpoint (struct gdbarch *gdbarch,
6693 struct symtab_and_line sal, enum bptype bptype,
6694 const struct breakpoint_ops *ops)
6696 struct breakpoint *b = XNEW (struct breakpoint);
6698 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
6699 add_to_breakpoint_chain (b);
6704 /* Note that the breakpoint object B describes a permanent breakpoint
6705 instruction, hard-wired into the inferior's code. */
6707 make_breakpoint_permanent (struct breakpoint *b)
6709 struct bp_location *bl;
6711 b->enable_state = bp_permanent;
6713 /* By definition, permanent breakpoints are already present in the
6714 code. Mark all locations as inserted. For now,
6715 make_breakpoint_permanent is called in just one place, so it's
6716 hard to say if it's reasonable to have permanent breakpoint with
6717 multiple locations or not, but it's easy to implement. */
6718 for (bl = b->loc; bl; bl = bl->next)
6722 /* Call this routine when stepping and nexting to enable a breakpoint
6723 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
6724 initiated the operation. */
6727 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
6729 struct breakpoint *b, *b_tmp;
6730 int thread = tp->num;
6732 /* To avoid having to rescan all objfile symbols at every step,
6733 we maintain a list of continually-inserted but always disabled
6734 longjmp "master" breakpoints. Here, we simply create momentary
6735 clones of those and enable them for the requested thread. */
6736 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6737 if (b->pspace == current_program_space
6738 && (b->type == bp_longjmp_master
6739 || b->type == bp_exception_master))
6741 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
6742 struct breakpoint *clone;
6744 clone = momentary_breakpoint_from_master (b, type,
6745 &momentary_breakpoint_ops);
6746 clone->thread = thread;
6749 tp->initiating_frame = frame;
6752 /* Delete all longjmp breakpoints from THREAD. */
6754 delete_longjmp_breakpoint (int thread)
6756 struct breakpoint *b, *b_tmp;
6758 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6759 if (b->type == bp_longjmp || b->type == bp_exception)
6761 if (b->thread == thread)
6762 delete_breakpoint (b);
6767 delete_longjmp_breakpoint_at_next_stop (int thread)
6769 struct breakpoint *b, *b_tmp;
6771 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6772 if (b->type == bp_longjmp || b->type == bp_exception)
6774 if (b->thread == thread)
6775 b->disposition = disp_del_at_next_stop;
6780 enable_overlay_breakpoints (void)
6782 struct breakpoint *b;
6785 if (b->type == bp_overlay_event)
6787 b->enable_state = bp_enabled;
6788 update_global_location_list (1);
6789 overlay_events_enabled = 1;
6794 disable_overlay_breakpoints (void)
6796 struct breakpoint *b;
6799 if (b->type == bp_overlay_event)
6801 b->enable_state = bp_disabled;
6802 update_global_location_list (0);
6803 overlay_events_enabled = 0;
6807 /* Set an active std::terminate breakpoint for each std::terminate
6808 master breakpoint. */
6810 set_std_terminate_breakpoint (void)
6812 struct breakpoint *b, *b_tmp;
6814 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6815 if (b->pspace == current_program_space
6816 && b->type == bp_std_terminate_master)
6818 momentary_breakpoint_from_master (b, bp_std_terminate,
6819 &momentary_breakpoint_ops);
6823 /* Delete all the std::terminate breakpoints. */
6825 delete_std_terminate_breakpoint (void)
6827 struct breakpoint *b, *b_tmp;
6829 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6830 if (b->type == bp_std_terminate)
6831 delete_breakpoint (b);
6835 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6837 struct breakpoint *b;
6839 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
6840 &internal_breakpoint_ops);
6842 b->enable_state = bp_enabled;
6843 /* addr_string has to be used or breakpoint_re_set will delete me. */
6845 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
6847 update_global_location_list_nothrow (1);
6853 remove_thread_event_breakpoints (void)
6855 struct breakpoint *b, *b_tmp;
6857 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6858 if (b->type == bp_thread_event
6859 && b->loc->pspace == current_program_space)
6860 delete_breakpoint (b);
6863 struct lang_and_radix
6869 /* Create a breakpoint for JIT code registration and unregistration. */
6872 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6874 struct breakpoint *b;
6876 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
6877 &internal_breakpoint_ops);
6878 update_global_location_list_nothrow (1);
6882 /* Remove JIT code registration and unregistration breakpoint(s). */
6885 remove_jit_event_breakpoints (void)
6887 struct breakpoint *b, *b_tmp;
6889 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6890 if (b->type == bp_jit_event
6891 && b->loc->pspace == current_program_space)
6892 delete_breakpoint (b);
6896 remove_solib_event_breakpoints (void)
6898 struct breakpoint *b, *b_tmp;
6900 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6901 if (b->type == bp_shlib_event
6902 && b->loc->pspace == current_program_space)
6903 delete_breakpoint (b);
6907 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6909 struct breakpoint *b;
6911 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
6912 &internal_breakpoint_ops);
6913 update_global_location_list_nothrow (1);
6917 /* Disable any breakpoints that are on code in shared libraries. Only
6918 apply to enabled breakpoints, disabled ones can just stay disabled. */
6921 disable_breakpoints_in_shlibs (void)
6923 struct bp_location *loc, **locp_tmp;
6925 ALL_BP_LOCATIONS (loc, locp_tmp)
6927 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6928 struct breakpoint *b = loc->owner;
6930 /* We apply the check to all breakpoints, including disabled for
6931 those with loc->duplicate set. This is so that when breakpoint
6932 becomes enabled, or the duplicate is removed, gdb will try to
6933 insert all breakpoints. If we don't set shlib_disabled here,
6934 we'll try to insert those breakpoints and fail. */
6935 if (((b->type == bp_breakpoint)
6936 || (b->type == bp_jit_event)
6937 || (b->type == bp_hardware_breakpoint)
6938 || (is_tracepoint (b)))
6939 && loc->pspace == current_program_space
6940 && !loc->shlib_disabled
6942 && PC_SOLIB (loc->address)
6944 && solib_name_from_address (loc->pspace, loc->address)
6948 loc->shlib_disabled = 1;
6953 /* Disable any breakpoints and tracepoints that are in an unloaded shared
6954 library. Only apply to enabled breakpoints, disabled ones can just stay
6958 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
6960 struct bp_location *loc, **locp_tmp;
6961 int disabled_shlib_breaks = 0;
6963 /* SunOS a.out shared libraries are always mapped, so do not
6964 disable breakpoints; they will only be reported as unloaded
6965 through clear_solib when GDB discards its shared library
6966 list. See clear_solib for more information. */
6967 if (exec_bfd != NULL
6968 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
6971 ALL_BP_LOCATIONS (loc, locp_tmp)
6973 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6974 struct breakpoint *b = loc->owner;
6976 if (solib->pspace == loc->pspace
6977 && !loc->shlib_disabled
6978 && (((b->type == bp_breakpoint
6979 || b->type == bp_jit_event
6980 || b->type == bp_hardware_breakpoint)
6981 && (loc->loc_type == bp_loc_hardware_breakpoint
6982 || loc->loc_type == bp_loc_software_breakpoint))
6983 || is_tracepoint (b))
6984 && solib_contains_address_p (solib, loc->address))
6986 loc->shlib_disabled = 1;
6987 /* At this point, we cannot rely on remove_breakpoint
6988 succeeding so we must mark the breakpoint as not inserted
6989 to prevent future errors occurring in remove_breakpoints. */
6992 /* This may cause duplicate notifications for the same breakpoint. */
6993 observer_notify_breakpoint_modified (b);
6995 if (!disabled_shlib_breaks)
6997 target_terminal_ours_for_output ();
6998 warning (_("Temporarily disabling breakpoints "
6999 "for unloaded shared library \"%s\""),
7002 disabled_shlib_breaks = 1;
7007 /* FORK & VFORK catchpoints. */
7009 /* An instance of this type is used to represent a fork or vfork
7010 catchpoint. It includes a "struct breakpoint" as a kind of base
7011 class; users downcast to "struct breakpoint *" when needed. A
7012 breakpoint is really of this type iff its ops pointer points to
7013 CATCH_FORK_BREAKPOINT_OPS. */
7015 struct fork_catchpoint
7017 /* The base class. */
7018 struct breakpoint base;
7020 /* Process id of a child process whose forking triggered this
7021 catchpoint. This field is only valid immediately after this
7022 catchpoint has triggered. */
7023 ptid_t forked_inferior_pid;
7026 /* Implement the "insert" breakpoint_ops method for fork
7030 insert_catch_fork (struct bp_location *bl)
7032 return target_insert_fork_catchpoint (PIDGET (inferior_ptid));
7035 /* Implement the "remove" breakpoint_ops method for fork
7039 remove_catch_fork (struct bp_location *bl)
7041 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
7044 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7048 breakpoint_hit_catch_fork (const struct bp_location *bl,
7049 struct address_space *aspace, CORE_ADDR bp_addr,
7050 const struct target_waitstatus *ws)
7052 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7054 if (ws->kind != TARGET_WAITKIND_FORKED)
7057 c->forked_inferior_pid = ws->value.related_pid;
7061 /* Implement the "print_it" breakpoint_ops method for fork
7064 static enum print_stop_action
7065 print_it_catch_fork (bpstat bs)
7067 struct ui_out *uiout = current_uiout;
7068 struct breakpoint *b = bs->breakpoint_at;
7069 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
7071 annotate_catchpoint (b->number);
7072 if (b->disposition == disp_del)
7073 ui_out_text (uiout, "\nTemporary catchpoint ");
7075 ui_out_text (uiout, "\nCatchpoint ");
7076 if (ui_out_is_mi_like_p (uiout))
7078 ui_out_field_string (uiout, "reason",
7079 async_reason_lookup (EXEC_ASYNC_FORK));
7080 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7082 ui_out_field_int (uiout, "bkptno", b->number);
7083 ui_out_text (uiout, " (forked process ");
7084 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7085 ui_out_text (uiout, "), ");
7086 return PRINT_SRC_AND_LOC;
7089 /* Implement the "print_one" breakpoint_ops method for fork
7093 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
7095 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7096 struct value_print_options opts;
7097 struct ui_out *uiout = current_uiout;
7099 get_user_print_options (&opts);
7101 /* Field 4, the address, is omitted (which makes the columns not
7102 line up too nicely with the headers, but the effect is relatively
7104 if (opts.addressprint)
7105 ui_out_field_skip (uiout, "addr");
7107 ui_out_text (uiout, "fork");
7108 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7110 ui_out_text (uiout, ", process ");
7111 ui_out_field_int (uiout, "what",
7112 ptid_get_pid (c->forked_inferior_pid));
7113 ui_out_spaces (uiout, 1);
7117 /* Implement the "print_mention" breakpoint_ops method for fork
7121 print_mention_catch_fork (struct breakpoint *b)
7123 printf_filtered (_("Catchpoint %d (fork)"), b->number);
7126 /* Implement the "print_recreate" breakpoint_ops method for fork
7130 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
7132 fprintf_unfiltered (fp, "catch fork");
7133 print_recreate_thread (b, fp);
7136 /* The breakpoint_ops structure to be used in fork catchpoints. */
7138 static struct breakpoint_ops catch_fork_breakpoint_ops;
7140 /* Implement the "insert" breakpoint_ops method for vfork
7144 insert_catch_vfork (struct bp_location *bl)
7146 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
7149 /* Implement the "remove" breakpoint_ops method for vfork
7153 remove_catch_vfork (struct bp_location *bl)
7155 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
7158 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7162 breakpoint_hit_catch_vfork (const struct bp_location *bl,
7163 struct address_space *aspace, CORE_ADDR bp_addr,
7164 const struct target_waitstatus *ws)
7166 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7168 if (ws->kind != TARGET_WAITKIND_VFORKED)
7171 c->forked_inferior_pid = ws->value.related_pid;
7175 /* Implement the "print_it" breakpoint_ops method for vfork
7178 static enum print_stop_action
7179 print_it_catch_vfork (bpstat bs)
7181 struct ui_out *uiout = current_uiout;
7182 struct breakpoint *b = bs->breakpoint_at;
7183 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7185 annotate_catchpoint (b->number);
7186 if (b->disposition == disp_del)
7187 ui_out_text (uiout, "\nTemporary catchpoint ");
7189 ui_out_text (uiout, "\nCatchpoint ");
7190 if (ui_out_is_mi_like_p (uiout))
7192 ui_out_field_string (uiout, "reason",
7193 async_reason_lookup (EXEC_ASYNC_VFORK));
7194 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7196 ui_out_field_int (uiout, "bkptno", b->number);
7197 ui_out_text (uiout, " (vforked process ");
7198 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7199 ui_out_text (uiout, "), ");
7200 return PRINT_SRC_AND_LOC;
7203 /* Implement the "print_one" breakpoint_ops method for vfork
7207 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
7209 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7210 struct value_print_options opts;
7211 struct ui_out *uiout = current_uiout;
7213 get_user_print_options (&opts);
7214 /* Field 4, the address, is omitted (which makes the columns not
7215 line up too nicely with the headers, but the effect is relatively
7217 if (opts.addressprint)
7218 ui_out_field_skip (uiout, "addr");
7220 ui_out_text (uiout, "vfork");
7221 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7223 ui_out_text (uiout, ", process ");
7224 ui_out_field_int (uiout, "what",
7225 ptid_get_pid (c->forked_inferior_pid));
7226 ui_out_spaces (uiout, 1);
7230 /* Implement the "print_mention" breakpoint_ops method for vfork
7234 print_mention_catch_vfork (struct breakpoint *b)
7236 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
7239 /* Implement the "print_recreate" breakpoint_ops method for vfork
7243 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
7245 fprintf_unfiltered (fp, "catch vfork");
7246 print_recreate_thread (b, fp);
7249 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7251 static struct breakpoint_ops catch_vfork_breakpoint_ops;
7253 /* An instance of this type is used to represent an solib catchpoint.
7254 It includes a "struct breakpoint" as a kind of base class; users
7255 downcast to "struct breakpoint *" when needed. A breakpoint is
7256 really of this type iff its ops pointer points to
7257 CATCH_SOLIB_BREAKPOINT_OPS. */
7259 struct solib_catchpoint
7261 /* The base class. */
7262 struct breakpoint base;
7264 /* True for "catch load", false for "catch unload". */
7265 unsigned char is_load;
7267 /* Regular expression to match, if any. COMPILED is only valid when
7268 REGEX is non-NULL. */
7274 dtor_catch_solib (struct breakpoint *b)
7276 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7279 regfree (&self->compiled);
7280 xfree (self->regex);
7282 base_breakpoint_ops.dtor (b);
7286 insert_catch_solib (struct bp_location *ignore)
7292 remove_catch_solib (struct bp_location *ignore)
7298 breakpoint_hit_catch_solib (const struct bp_location *bl,
7299 struct address_space *aspace,
7301 const struct target_waitstatus *ws)
7303 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
7304 struct breakpoint *other;
7306 if (ws->kind == TARGET_WAITKIND_LOADED)
7309 ALL_BREAKPOINTS (other)
7311 struct bp_location *other_bl;
7313 if (other == bl->owner)
7316 if (other->type != bp_shlib_event)
7319 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
7322 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
7324 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
7333 check_status_catch_solib (struct bpstats *bs)
7335 struct solib_catchpoint *self
7336 = (struct solib_catchpoint *) bs->breakpoint_at;
7341 struct so_list *iter;
7344 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
7349 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
7358 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
7363 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
7369 bs->print_it = print_it_noop;
7372 static enum print_stop_action
7373 print_it_catch_solib (bpstat bs)
7375 struct breakpoint *b = bs->breakpoint_at;
7376 struct ui_out *uiout = current_uiout;
7378 annotate_catchpoint (b->number);
7379 if (b->disposition == disp_del)
7380 ui_out_text (uiout, "\nTemporary catchpoint ");
7382 ui_out_text (uiout, "\nCatchpoint ");
7383 ui_out_field_int (uiout, "bkptno", b->number);
7384 ui_out_text (uiout, "\n");
7385 if (ui_out_is_mi_like_p (uiout))
7386 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7387 print_solib_event (1);
7388 return PRINT_SRC_AND_LOC;
7392 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
7394 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7395 struct value_print_options opts;
7396 struct ui_out *uiout = current_uiout;
7399 get_user_print_options (&opts);
7400 /* Field 4, the address, is omitted (which makes the columns not
7401 line up too nicely with the headers, but the effect is relatively
7403 if (opts.addressprint)
7406 ui_out_field_skip (uiout, "addr");
7413 msg = xstrprintf (_("load of library matching %s"), self->regex);
7415 msg = xstrdup (_("load of library"));
7420 msg = xstrprintf (_("unload of library matching %s"), self->regex);
7422 msg = xstrdup (_("unload of library"));
7424 ui_out_field_string (uiout, "what", msg);
7429 print_mention_catch_solib (struct breakpoint *b)
7431 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7433 printf_filtered (_("Catchpoint %d (%s)"), b->number,
7434 self->is_load ? "load" : "unload");
7438 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
7440 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7442 fprintf_unfiltered (fp, "%s %s",
7443 b->disposition == disp_del ? "tcatch" : "catch",
7444 self->is_load ? "load" : "unload");
7446 fprintf_unfiltered (fp, " %s", self->regex);
7447 fprintf_unfiltered (fp, "\n");
7450 static struct breakpoint_ops catch_solib_breakpoint_ops;
7452 /* A helper function that does all the work for "catch load" and
7456 catch_load_or_unload (char *arg, int from_tty, int is_load,
7457 struct cmd_list_element *command)
7459 struct solib_catchpoint *c;
7460 struct gdbarch *gdbarch = get_current_arch ();
7462 struct cleanup *cleanup;
7464 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
7468 arg = skip_spaces (arg);
7470 c = XCNEW (struct solib_catchpoint);
7471 cleanup = make_cleanup (xfree, c);
7477 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
7480 char *err = get_regcomp_error (errcode, &c->compiled);
7482 make_cleanup (xfree, err);
7483 error (_("Invalid regexp (%s): %s"), err, arg);
7485 c->regex = xstrdup (arg);
7488 c->is_load = is_load;
7489 init_catchpoint (&c->base, gdbarch, tempflag, NULL,
7490 &catch_solib_breakpoint_ops);
7492 discard_cleanups (cleanup);
7493 install_breakpoint (0, &c->base, 1);
7497 catch_load_command_1 (char *arg, int from_tty,
7498 struct cmd_list_element *command)
7500 catch_load_or_unload (arg, from_tty, 1, command);
7504 catch_unload_command_1 (char *arg, int from_tty,
7505 struct cmd_list_element *command)
7507 catch_load_or_unload (arg, from_tty, 0, command);
7512 /* An instance of this type is used to represent a syscall catchpoint.
7513 It includes a "struct breakpoint" as a kind of base class; users
7514 downcast to "struct breakpoint *" when needed. A breakpoint is
7515 really of this type iff its ops pointer points to
7516 CATCH_SYSCALL_BREAKPOINT_OPS. */
7518 struct syscall_catchpoint
7520 /* The base class. */
7521 struct breakpoint base;
7523 /* Syscall numbers used for the 'catch syscall' feature. If no
7524 syscall has been specified for filtering, its value is NULL.
7525 Otherwise, it holds a list of all syscalls to be caught. The
7526 list elements are allocated with xmalloc. */
7527 VEC(int) *syscalls_to_be_caught;
7530 /* Implement the "dtor" breakpoint_ops method for syscall
7534 dtor_catch_syscall (struct breakpoint *b)
7536 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7538 VEC_free (int, c->syscalls_to_be_caught);
7540 base_breakpoint_ops.dtor (b);
7543 static const struct inferior_data *catch_syscall_inferior_data = NULL;
7545 struct catch_syscall_inferior_data
7547 /* We keep a count of the number of times the user has requested a
7548 particular syscall to be tracked, and pass this information to the
7549 target. This lets capable targets implement filtering directly. */
7551 /* Number of times that "any" syscall is requested. */
7552 int any_syscall_count;
7554 /* Count of each system call. */
7555 VEC(int) *syscalls_counts;
7557 /* This counts all syscall catch requests, so we can readily determine
7558 if any catching is necessary. */
7559 int total_syscalls_count;
7562 static struct catch_syscall_inferior_data*
7563 get_catch_syscall_inferior_data (struct inferior *inf)
7565 struct catch_syscall_inferior_data *inf_data;
7567 inf_data = inferior_data (inf, catch_syscall_inferior_data);
7568 if (inf_data == NULL)
7570 inf_data = XZALLOC (struct catch_syscall_inferior_data);
7571 set_inferior_data (inf, catch_syscall_inferior_data, inf_data);
7578 catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg)
7584 /* Implement the "insert" breakpoint_ops method for syscall
7588 insert_catch_syscall (struct bp_location *bl)
7590 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
7591 struct inferior *inf = current_inferior ();
7592 struct catch_syscall_inferior_data *inf_data
7593 = get_catch_syscall_inferior_data (inf);
7595 ++inf_data->total_syscalls_count;
7596 if (!c->syscalls_to_be_caught)
7597 ++inf_data->any_syscall_count;
7603 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7608 if (iter >= VEC_length (int, inf_data->syscalls_counts))
7610 int old_size = VEC_length (int, inf_data->syscalls_counts);
7611 uintptr_t vec_addr_offset
7612 = old_size * ((uintptr_t) sizeof (int));
7614 VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1);
7615 vec_addr = ((uintptr_t) VEC_address (int,
7616 inf_data->syscalls_counts)
7618 memset ((void *) vec_addr, 0,
7619 (iter + 1 - old_size) * sizeof (int));
7621 elem = VEC_index (int, inf_data->syscalls_counts, iter);
7622 VEC_replace (int, inf_data->syscalls_counts, iter, ++elem);
7626 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
7627 inf_data->total_syscalls_count != 0,
7628 inf_data->any_syscall_count,
7630 inf_data->syscalls_counts),
7632 inf_data->syscalls_counts));
7635 /* Implement the "remove" breakpoint_ops method for syscall
7639 remove_catch_syscall (struct bp_location *bl)
7641 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
7642 struct inferior *inf = current_inferior ();
7643 struct catch_syscall_inferior_data *inf_data
7644 = get_catch_syscall_inferior_data (inf);
7646 --inf_data->total_syscalls_count;
7647 if (!c->syscalls_to_be_caught)
7648 --inf_data->any_syscall_count;
7654 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7658 if (iter >= VEC_length (int, inf_data->syscalls_counts))
7659 /* Shouldn't happen. */
7661 elem = VEC_index (int, inf_data->syscalls_counts, iter);
7662 VEC_replace (int, inf_data->syscalls_counts, iter, --elem);
7666 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
7667 inf_data->total_syscalls_count != 0,
7668 inf_data->any_syscall_count,
7670 inf_data->syscalls_counts),
7672 inf_data->syscalls_counts));
7675 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
7679 breakpoint_hit_catch_syscall (const struct bp_location *bl,
7680 struct address_space *aspace, CORE_ADDR bp_addr,
7681 const struct target_waitstatus *ws)
7683 /* We must check if we are catching specific syscalls in this
7684 breakpoint. If we are, then we must guarantee that the called
7685 syscall is the same syscall we are catching. */
7686 int syscall_number = 0;
7687 const struct syscall_catchpoint *c
7688 = (const struct syscall_catchpoint *) bl->owner;
7690 if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY
7691 && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN)
7694 syscall_number = ws->value.syscall_number;
7696 /* Now, checking if the syscall is the same. */
7697 if (c->syscalls_to_be_caught)
7702 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7704 if (syscall_number == iter)
7714 /* Implement the "print_it" breakpoint_ops method for syscall
7717 static enum print_stop_action
7718 print_it_catch_syscall (bpstat bs)
7720 struct ui_out *uiout = current_uiout;
7721 struct breakpoint *b = bs->breakpoint_at;
7722 /* These are needed because we want to know in which state a
7723 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
7724 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
7725 must print "called syscall" or "returned from syscall". */
7727 struct target_waitstatus last;
7730 get_last_target_status (&ptid, &last);
7732 get_syscall_by_number (last.value.syscall_number, &s);
7734 annotate_catchpoint (b->number);
7736 if (b->disposition == disp_del)
7737 ui_out_text (uiout, "\nTemporary catchpoint ");
7739 ui_out_text (uiout, "\nCatchpoint ");
7740 if (ui_out_is_mi_like_p (uiout))
7742 ui_out_field_string (uiout, "reason",
7743 async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY
7744 ? EXEC_ASYNC_SYSCALL_ENTRY
7745 : EXEC_ASYNC_SYSCALL_RETURN));
7746 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7748 ui_out_field_int (uiout, "bkptno", b->number);
7750 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
7751 ui_out_text (uiout, " (call to syscall ");
7753 ui_out_text (uiout, " (returned from syscall ");
7755 if (s.name == NULL || ui_out_is_mi_like_p (uiout))
7756 ui_out_field_int (uiout, "syscall-number", last.value.syscall_number);
7758 ui_out_field_string (uiout, "syscall-name", s.name);
7760 ui_out_text (uiout, "), ");
7762 return PRINT_SRC_AND_LOC;
7765 /* Implement the "print_one" breakpoint_ops method for syscall
7769 print_one_catch_syscall (struct breakpoint *b,
7770 struct bp_location **last_loc)
7772 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7773 struct value_print_options opts;
7774 struct ui_out *uiout = current_uiout;
7776 get_user_print_options (&opts);
7777 /* Field 4, the address, is omitted (which makes the columns not
7778 line up too nicely with the headers, but the effect is relatively
7780 if (opts.addressprint)
7781 ui_out_field_skip (uiout, "addr");
7784 if (c->syscalls_to_be_caught
7785 && VEC_length (int, c->syscalls_to_be_caught) > 1)
7786 ui_out_text (uiout, "syscalls \"");
7788 ui_out_text (uiout, "syscall \"");
7790 if (c->syscalls_to_be_caught)
7793 char *text = xstrprintf ("%s", "");
7796 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7801 get_syscall_by_number (iter, &s);
7804 text = xstrprintf ("%s%s, ", text, s.name);
7806 text = xstrprintf ("%s%d, ", text, iter);
7808 /* We have to xfree the last 'text' (now stored at 'x')
7809 because xstrprintf dynamically allocates new space for it
7813 /* Remove the last comma. */
7814 text[strlen (text) - 2] = '\0';
7815 ui_out_field_string (uiout, "what", text);
7818 ui_out_field_string (uiout, "what", "<any syscall>");
7819 ui_out_text (uiout, "\" ");
7822 /* Implement the "print_mention" breakpoint_ops method for syscall
7826 print_mention_catch_syscall (struct breakpoint *b)
7828 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7830 if (c->syscalls_to_be_caught)
7834 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
7835 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
7837 printf_filtered (_("Catchpoint %d (syscall"), b->number);
7840 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7844 get_syscall_by_number (iter, &s);
7847 printf_filtered (" '%s' [%d]", s.name, s.number);
7849 printf_filtered (" %d", s.number);
7851 printf_filtered (")");
7854 printf_filtered (_("Catchpoint %d (any syscall)"),
7858 /* Implement the "print_recreate" breakpoint_ops method for syscall
7862 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
7864 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7866 fprintf_unfiltered (fp, "catch syscall");
7868 if (c->syscalls_to_be_caught)
7873 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7878 get_syscall_by_number (iter, &s);
7880 fprintf_unfiltered (fp, " %s", s.name);
7882 fprintf_unfiltered (fp, " %d", s.number);
7885 print_recreate_thread (b, fp);
7888 /* The breakpoint_ops structure to be used in syscall catchpoints. */
7890 static struct breakpoint_ops catch_syscall_breakpoint_ops;
7892 /* Returns non-zero if 'b' is a syscall catchpoint. */
7895 syscall_catchpoint_p (struct breakpoint *b)
7897 return (b->ops == &catch_syscall_breakpoint_ops);
7900 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
7901 is non-zero, then make the breakpoint temporary. If COND_STRING is
7902 not NULL, then store it in the breakpoint. OPS, if not NULL, is
7903 the breakpoint_ops structure associated to the catchpoint. */
7906 init_catchpoint (struct breakpoint *b,
7907 struct gdbarch *gdbarch, int tempflag,
7909 const struct breakpoint_ops *ops)
7911 struct symtab_and_line sal;
7914 sal.pspace = current_program_space;
7916 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
7918 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
7919 b->disposition = tempflag ? disp_del : disp_donttouch;
7923 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
7925 add_to_breakpoint_chain (b);
7926 set_breakpoint_number (internal, b);
7929 observer_notify_breakpoint_created (b);
7932 update_global_location_list (1);
7936 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
7937 int tempflag, char *cond_string,
7938 const struct breakpoint_ops *ops)
7940 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
7942 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
7944 c->forked_inferior_pid = null_ptid;
7946 install_breakpoint (0, &c->base, 1);
7949 /* Exec catchpoints. */
7951 /* An instance of this type is used to represent an exec catchpoint.
7952 It includes a "struct breakpoint" as a kind of base class; users
7953 downcast to "struct breakpoint *" when needed. A breakpoint is
7954 really of this type iff its ops pointer points to
7955 CATCH_EXEC_BREAKPOINT_OPS. */
7957 struct exec_catchpoint
7959 /* The base class. */
7960 struct breakpoint base;
7962 /* Filename of a program whose exec triggered this catchpoint.
7963 This field is only valid immediately after this catchpoint has
7965 char *exec_pathname;
7968 /* Implement the "dtor" breakpoint_ops method for exec
7972 dtor_catch_exec (struct breakpoint *b)
7974 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
7976 xfree (c->exec_pathname);
7978 base_breakpoint_ops.dtor (b);
7982 insert_catch_exec (struct bp_location *bl)
7984 return target_insert_exec_catchpoint (PIDGET (inferior_ptid));
7988 remove_catch_exec (struct bp_location *bl)
7990 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
7994 breakpoint_hit_catch_exec (const struct bp_location *bl,
7995 struct address_space *aspace, CORE_ADDR bp_addr,
7996 const struct target_waitstatus *ws)
7998 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8000 if (ws->kind != TARGET_WAITKIND_EXECD)
8003 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8007 static enum print_stop_action
8008 print_it_catch_exec (bpstat bs)
8010 struct ui_out *uiout = current_uiout;
8011 struct breakpoint *b = bs->breakpoint_at;
8012 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8014 annotate_catchpoint (b->number);
8015 if (b->disposition == disp_del)
8016 ui_out_text (uiout, "\nTemporary catchpoint ");
8018 ui_out_text (uiout, "\nCatchpoint ");
8019 if (ui_out_is_mi_like_p (uiout))
8021 ui_out_field_string (uiout, "reason",
8022 async_reason_lookup (EXEC_ASYNC_EXEC));
8023 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8025 ui_out_field_int (uiout, "bkptno", b->number);
8026 ui_out_text (uiout, " (exec'd ");
8027 ui_out_field_string (uiout, "new-exec", c->exec_pathname);
8028 ui_out_text (uiout, "), ");
8030 return PRINT_SRC_AND_LOC;
8034 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8036 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8037 struct value_print_options opts;
8038 struct ui_out *uiout = current_uiout;
8040 get_user_print_options (&opts);
8042 /* Field 4, the address, is omitted (which makes the columns
8043 not line up too nicely with the headers, but the effect
8044 is relatively readable). */
8045 if (opts.addressprint)
8046 ui_out_field_skip (uiout, "addr");
8048 ui_out_text (uiout, "exec");
8049 if (c->exec_pathname != NULL)
8051 ui_out_text (uiout, ", program \"");
8052 ui_out_field_string (uiout, "what", c->exec_pathname);
8053 ui_out_text (uiout, "\" ");
8058 print_mention_catch_exec (struct breakpoint *b)
8060 printf_filtered (_("Catchpoint %d (exec)"), b->number);
8063 /* Implement the "print_recreate" breakpoint_ops method for exec
8067 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
8069 fprintf_unfiltered (fp, "catch exec");
8070 print_recreate_thread (b, fp);
8073 static struct breakpoint_ops catch_exec_breakpoint_ops;
8076 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
8077 const struct breakpoint_ops *ops)
8079 struct syscall_catchpoint *c;
8080 struct gdbarch *gdbarch = get_current_arch ();
8082 c = XNEW (struct syscall_catchpoint);
8083 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
8084 c->syscalls_to_be_caught = filter;
8086 install_breakpoint (0, &c->base, 1);
8090 hw_breakpoint_used_count (void)
8093 struct breakpoint *b;
8094 struct bp_location *bl;
8098 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
8099 for (bl = b->loc; bl; bl = bl->next)
8101 /* Special types of hardware breakpoints may use more than
8103 i += b->ops->resources_needed (bl);
8110 /* Returns the resources B would use if it were a hardware
8114 hw_watchpoint_use_count (struct breakpoint *b)
8117 struct bp_location *bl;
8119 if (!breakpoint_enabled (b))
8122 for (bl = b->loc; bl; bl = bl->next)
8124 /* Special types of hardware watchpoints may use more than
8126 i += b->ops->resources_needed (bl);
8132 /* Returns the sum the used resources of all hardware watchpoints of
8133 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8134 the sum of the used resources of all hardware watchpoints of other
8135 types _not_ TYPE. */
8138 hw_watchpoint_used_count_others (struct breakpoint *except,
8139 enum bptype type, int *other_type_used)
8142 struct breakpoint *b;
8144 *other_type_used = 0;
8149 if (!breakpoint_enabled (b))
8152 if (b->type == type)
8153 i += hw_watchpoint_use_count (b);
8154 else if (is_hardware_watchpoint (b))
8155 *other_type_used = 1;
8162 disable_watchpoints_before_interactive_call_start (void)
8164 struct breakpoint *b;
8168 if (is_watchpoint (b) && breakpoint_enabled (b))
8170 b->enable_state = bp_call_disabled;
8171 update_global_location_list (0);
8177 enable_watchpoints_after_interactive_call_stop (void)
8179 struct breakpoint *b;
8183 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
8185 b->enable_state = bp_enabled;
8186 update_global_location_list (1);
8192 disable_breakpoints_before_startup (void)
8194 current_program_space->executing_startup = 1;
8195 update_global_location_list (0);
8199 enable_breakpoints_after_startup (void)
8201 current_program_space->executing_startup = 0;
8202 breakpoint_re_set ();
8206 /* Set a breakpoint that will evaporate an end of command
8207 at address specified by SAL.
8208 Restrict it to frame FRAME if FRAME is nonzero. */
8211 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
8212 struct frame_id frame_id, enum bptype type)
8214 struct breakpoint *b;
8216 /* If FRAME_ID is valid, it should be a real frame, not an inlined
8218 gdb_assert (!frame_id_inlined_p (frame_id));
8220 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
8221 b->enable_state = bp_enabled;
8222 b->disposition = disp_donttouch;
8223 b->frame_id = frame_id;
8225 /* If we're debugging a multi-threaded program, then we want
8226 momentary breakpoints to be active in only a single thread of
8228 if (in_thread_list (inferior_ptid))
8229 b->thread = pid_to_thread_id (inferior_ptid);
8231 update_global_location_list_nothrow (1);
8236 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8237 The new breakpoint will have type TYPE, and use OPS as it
8240 static struct breakpoint *
8241 momentary_breakpoint_from_master (struct breakpoint *orig,
8243 const struct breakpoint_ops *ops)
8245 struct breakpoint *copy;
8247 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
8248 copy->loc = allocate_bp_location (copy);
8249 set_breakpoint_location_function (copy->loc, 1);
8251 copy->loc->gdbarch = orig->loc->gdbarch;
8252 copy->loc->requested_address = orig->loc->requested_address;
8253 copy->loc->address = orig->loc->address;
8254 copy->loc->section = orig->loc->section;
8255 copy->loc->pspace = orig->loc->pspace;
8256 copy->loc->probe = orig->loc->probe;
8258 if (orig->loc->source_file != NULL)
8259 copy->loc->source_file = xstrdup (orig->loc->source_file);
8261 copy->loc->line_number = orig->loc->line_number;
8262 copy->frame_id = orig->frame_id;
8263 copy->thread = orig->thread;
8264 copy->pspace = orig->pspace;
8266 copy->enable_state = bp_enabled;
8267 copy->disposition = disp_donttouch;
8268 copy->number = internal_breakpoint_number--;
8270 update_global_location_list_nothrow (0);
8274 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8278 clone_momentary_breakpoint (struct breakpoint *orig)
8280 /* If there's nothing to clone, then return nothing. */
8284 return momentary_breakpoint_from_master (orig, orig->type, orig->ops);
8288 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
8291 struct symtab_and_line sal;
8293 sal = find_pc_line (pc, 0);
8295 sal.section = find_pc_overlay (pc);
8296 sal.explicit_pc = 1;
8298 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
8302 /* Tell the user we have just set a breakpoint B. */
8305 mention (struct breakpoint *b)
8307 b->ops->print_mention (b);
8308 if (ui_out_is_mi_like_p (current_uiout))
8310 printf_filtered ("\n");
8314 static struct bp_location *
8315 add_location_to_breakpoint (struct breakpoint *b,
8316 const struct symtab_and_line *sal)
8318 struct bp_location *loc, **tmp;
8319 CORE_ADDR adjusted_address;
8320 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
8322 if (loc_gdbarch == NULL)
8323 loc_gdbarch = b->gdbarch;
8325 /* Adjust the breakpoint's address prior to allocating a location.
8326 Once we call allocate_bp_location(), that mostly uninitialized
8327 location will be placed on the location chain. Adjustment of the
8328 breakpoint may cause target_read_memory() to be called and we do
8329 not want its scan of the location chain to find a breakpoint and
8330 location that's only been partially initialized. */
8331 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
8334 loc = allocate_bp_location (b);
8335 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
8339 loc->requested_address = sal->pc;
8340 loc->address = adjusted_address;
8341 loc->pspace = sal->pspace;
8342 loc->probe = sal->probe;
8343 gdb_assert (loc->pspace != NULL);
8344 loc->section = sal->section;
8345 loc->gdbarch = loc_gdbarch;
8347 if (sal->symtab != NULL)
8348 loc->source_file = xstrdup (sal->symtab->filename);
8349 loc->line_number = sal->line;
8351 set_breakpoint_location_function (loc,
8352 sal->explicit_pc || sal->explicit_line);
8357 /* Return 1 if LOC is pointing to a permanent breakpoint,
8358 return 0 otherwise. */
8361 bp_loc_is_permanent (struct bp_location *loc)
8365 const gdb_byte *bpoint;
8366 gdb_byte *target_mem;
8367 struct cleanup *cleanup;
8370 gdb_assert (loc != NULL);
8372 addr = loc->address;
8373 bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
8375 /* Software breakpoints unsupported? */
8379 target_mem = alloca (len);
8381 /* Enable the automatic memory restoration from breakpoints while
8382 we read the memory. Otherwise we could say about our temporary
8383 breakpoints they are permanent. */
8384 cleanup = save_current_space_and_thread ();
8386 switch_to_program_space_and_thread (loc->pspace);
8387 make_show_memory_breakpoints_cleanup (0);
8389 if (target_read_memory (loc->address, target_mem, len) == 0
8390 && memcmp (target_mem, bpoint, len) == 0)
8393 do_cleanups (cleanup);
8398 /* The style in which to perform a dynamic printf. This is a user
8399 option because different output options have different tradeoffs;
8400 if GDB does the printing, there is better error handling if there
8401 is a problem with any of the arguments, but using an inferior
8402 function lets you have special-purpose printers and sending of
8403 output to the same place as compiled-in print functions. (Future
8404 styles may include the ability to do a target-side printf.) */
8406 static const char dprintf_style_gdb[] = "gdb";
8407 static const char dprintf_style_call[] = "call";
8408 static const char *const dprintf_style_enums[] = {
8413 static const char *dprintf_style = dprintf_style_gdb;
8415 /* The function to use for dynamic printf if the preferred style is to
8416 call into the inferior. The value is simply a string that is
8417 copied into the command, so it can be anything that GDB can
8418 evaluate to a callable address, not necessarily a function name. */
8420 static char *dprintf_function = "";
8422 /* The channel to use for dynamic printf if the preferred style is to
8423 call into the inferior; if a nonempty string, it will be passed to
8424 the call as the first argument, with the format string as the
8425 second. As with the dprintf function, this can be anything that
8426 GDB knows how to evaluate, so in addition to common choices like
8427 "stderr", this could be an app-specific expression like
8428 "mystreams[curlogger]". */
8430 static char *dprintf_channel = "";
8432 /* Build a command list for the dprintf corresponding to the current
8433 settings of the dprintf style options. */
8436 update_dprintf_command_list (struct breakpoint *b)
8438 char *dprintf_args = b->extra_string;
8439 char *printf_line = NULL;
8444 dprintf_args = skip_spaces (dprintf_args);
8446 /* Allow a comma, as it may have terminated a location, but don't
8448 if (*dprintf_args == ',')
8450 dprintf_args = skip_spaces (dprintf_args);
8452 if (*dprintf_args != '"')
8453 error (_("Bad format string, missing '\"'."));
8455 if (strcmp (dprintf_style, "gdb") == 0)
8456 printf_line = xstrprintf ("printf %s", dprintf_args);
8457 else if (strcmp (dprintf_style, "call") == 0)
8459 if (!dprintf_function)
8460 error (_("No function supplied for dprintf call"));
8462 if (dprintf_channel && strlen (dprintf_channel) > 0)
8463 printf_line = xstrprintf ("call (void) %s (%s,%s)",
8468 printf_line = xstrprintf ("call (void) %s (%s)",
8473 internal_error (__FILE__, __LINE__,
8474 _("Invalid dprintf style."));
8476 /* Manufacture a printf/continue sequence. */
8479 struct command_line *printf_cmd_line, *cont_cmd_line = NULL;
8481 cont_cmd_line = xmalloc (sizeof (struct command_line));
8482 cont_cmd_line->control_type = simple_control;
8483 cont_cmd_line->body_count = 0;
8484 cont_cmd_line->body_list = NULL;
8485 cont_cmd_line->next = NULL;
8486 cont_cmd_line->line = xstrdup ("continue");
8488 printf_cmd_line = xmalloc (sizeof (struct command_line));
8489 printf_cmd_line->control_type = simple_control;
8490 printf_cmd_line->body_count = 0;
8491 printf_cmd_line->body_list = NULL;
8492 printf_cmd_line->next = cont_cmd_line;
8493 printf_cmd_line->line = printf_line;
8495 breakpoint_set_commands (b, printf_cmd_line);
8499 /* Update all dprintf commands, making their command lists reflect
8500 current style settings. */
8503 update_dprintf_commands (char *args, int from_tty,
8504 struct cmd_list_element *c)
8506 struct breakpoint *b;
8510 if (b->type == bp_dprintf)
8511 update_dprintf_command_list (b);
8515 /* Create a breakpoint with SAL as location. Use ADDR_STRING
8516 as textual description of the location, and COND_STRING
8517 as condition expression. */
8520 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
8521 struct symtabs_and_lines sals, char *addr_string,
8522 char *filter, char *cond_string,
8524 enum bptype type, enum bpdisp disposition,
8525 int thread, int task, int ignore_count,
8526 const struct breakpoint_ops *ops, int from_tty,
8527 int enabled, int internal, unsigned flags,
8528 int display_canonical)
8532 if (type == bp_hardware_breakpoint)
8534 int target_resources_ok;
8536 i = hw_breakpoint_used_count ();
8537 target_resources_ok =
8538 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
8540 if (target_resources_ok == 0)
8541 error (_("No hardware breakpoint support in the target."));
8542 else if (target_resources_ok < 0)
8543 error (_("Hardware breakpoints used exceeds limit."));
8546 gdb_assert (sals.nelts > 0);
8548 for (i = 0; i < sals.nelts; ++i)
8550 struct symtab_and_line sal = sals.sals[i];
8551 struct bp_location *loc;
8555 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
8557 loc_gdbarch = gdbarch;
8559 describe_other_breakpoints (loc_gdbarch,
8560 sal.pspace, sal.pc, sal.section, thread);
8565 init_raw_breakpoint (b, gdbarch, sal, type, ops);
8569 b->cond_string = cond_string;
8570 b->extra_string = extra_string;
8571 b->ignore_count = ignore_count;
8572 b->enable_state = enabled ? bp_enabled : bp_disabled;
8573 b->disposition = disposition;
8575 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
8576 b->loc->inserted = 1;
8578 if (type == bp_static_tracepoint)
8580 struct tracepoint *t = (struct tracepoint *) b;
8581 struct static_tracepoint_marker marker;
8583 if (strace_marker_p (b))
8585 /* We already know the marker exists, otherwise, we
8586 wouldn't see a sal for it. */
8587 char *p = &addr_string[3];
8591 p = skip_spaces (p);
8593 endp = skip_to_space (p);
8595 marker_str = savestring (p, endp - p);
8596 t->static_trace_marker_id = marker_str;
8598 printf_filtered (_("Probed static tracepoint "
8600 t->static_trace_marker_id);
8602 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
8604 t->static_trace_marker_id = xstrdup (marker.str_id);
8605 release_static_tracepoint_marker (&marker);
8607 printf_filtered (_("Probed static tracepoint "
8609 t->static_trace_marker_id);
8612 warning (_("Couldn't determine the static "
8613 "tracepoint marker to probe"));
8620 loc = add_location_to_breakpoint (b, &sal);
8621 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
8625 if (bp_loc_is_permanent (loc))
8626 make_breakpoint_permanent (b);
8630 char *arg = b->cond_string;
8631 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
8633 error (_("Garbage '%s' follows condition"), arg);
8636 /* Dynamic printf requires and uses additional arguments on the
8637 command line, otherwise it's an error. */
8638 if (type == bp_dprintf)
8640 if (b->extra_string)
8641 update_dprintf_command_list (b);
8643 error (_("Format string required"));
8645 else if (b->extra_string)
8646 error (_("Garbage '%s' at end of command"), b->extra_string);
8649 b->display_canonical = display_canonical;
8651 b->addr_string = addr_string;
8653 /* addr_string has to be used or breakpoint_re_set will delete
8656 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
8661 create_breakpoint_sal (struct gdbarch *gdbarch,
8662 struct symtabs_and_lines sals, char *addr_string,
8663 char *filter, char *cond_string,
8665 enum bptype type, enum bpdisp disposition,
8666 int thread, int task, int ignore_count,
8667 const struct breakpoint_ops *ops, int from_tty,
8668 int enabled, int internal, unsigned flags,
8669 int display_canonical)
8671 struct breakpoint *b;
8672 struct cleanup *old_chain;
8674 if (is_tracepoint_type (type))
8676 struct tracepoint *t;
8678 t = XCNEW (struct tracepoint);
8682 b = XNEW (struct breakpoint);
8684 old_chain = make_cleanup (xfree, b);
8686 init_breakpoint_sal (b, gdbarch,
8688 filter, cond_string, extra_string,
8690 thread, task, ignore_count,
8692 enabled, internal, flags,
8694 discard_cleanups (old_chain);
8696 install_breakpoint (internal, b, 0);
8699 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8700 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8701 value. COND_STRING, if not NULL, specified the condition to be
8702 used for all breakpoints. Essentially the only case where
8703 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8704 function. In that case, it's still not possible to specify
8705 separate conditions for different overloaded functions, so
8706 we take just a single condition string.
8708 NOTE: If the function succeeds, the caller is expected to cleanup
8709 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8710 array contents). If the function fails (error() is called), the
8711 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8712 COND and SALS arrays and each of those arrays contents. */
8715 create_breakpoints_sal (struct gdbarch *gdbarch,
8716 struct linespec_result *canonical,
8717 char *cond_string, char *extra_string,
8718 enum bptype type, enum bpdisp disposition,
8719 int thread, int task, int ignore_count,
8720 const struct breakpoint_ops *ops, int from_tty,
8721 int enabled, int internal, unsigned flags)
8724 struct linespec_sals *lsal;
8726 if (canonical->pre_expanded)
8727 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
8729 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
8731 /* Note that 'addr_string' can be NULL in the case of a plain
8732 'break', without arguments. */
8733 char *addr_string = (canonical->addr_string
8734 ? xstrdup (canonical->addr_string)
8736 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
8737 struct cleanup *inner = make_cleanup (xfree, addr_string);
8739 make_cleanup (xfree, filter_string);
8740 create_breakpoint_sal (gdbarch, lsal->sals,
8743 cond_string, extra_string,
8745 thread, task, ignore_count, ops,
8746 from_tty, enabled, internal, flags,
8747 canonical->special_display);
8748 discard_cleanups (inner);
8752 /* Parse ADDRESS which is assumed to be a SAL specification possibly
8753 followed by conditionals. On return, SALS contains an array of SAL
8754 addresses found. ADDR_STRING contains a vector of (canonical)
8755 address strings. ADDRESS points to the end of the SAL.
8757 The array and the line spec strings are allocated on the heap, it is
8758 the caller's responsibility to free them. */
8761 parse_breakpoint_sals (char **address,
8762 struct linespec_result *canonical)
8764 char *addr_start = *address;
8766 /* If no arg given, or if first arg is 'if ', use the default
8768 if ((*address) == NULL
8769 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
8771 /* The last displayed codepoint, if it's valid, is our default breakpoint
8773 if (last_displayed_sal_is_valid ())
8775 struct linespec_sals lsal;
8776 struct symtab_and_line sal;
8778 init_sal (&sal); /* Initialize to zeroes. */
8779 lsal.sals.sals = (struct symtab_and_line *)
8780 xmalloc (sizeof (struct symtab_and_line));
8782 /* Set sal's pspace, pc, symtab, and line to the values
8783 corresponding to the last call to print_frame_info. */
8784 get_last_displayed_sal (&sal);
8785 sal.section = find_pc_overlay (sal.pc);
8787 /* "break" without arguments is equivalent to "break *PC"
8788 where PC is the last displayed codepoint's address. So
8789 make sure to set sal.explicit_pc to prevent GDB from
8790 trying to expand the list of sals to include all other
8791 instances with the same symtab and line. */
8792 sal.explicit_pc = 1;
8794 lsal.sals.sals[0] = sal;
8795 lsal.sals.nelts = 1;
8796 lsal.canonical = NULL;
8798 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
8801 error (_("No default breakpoint address now."));
8805 /* Force almost all breakpoints to be in terms of the
8806 current_source_symtab (which is decode_line_1's default).
8807 This should produce the results we want almost all of the
8808 time while leaving default_breakpoint_* alone. */
8809 if (last_displayed_sal_is_valid ())
8810 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
8811 get_last_displayed_symtab (),
8812 get_last_displayed_line (),
8813 canonical, NULL, NULL);
8815 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
8816 (struct symtab *) NULL, 0,
8817 canonical, NULL, NULL);
8822 /* Convert each SAL into a real PC. Verify that the PC can be
8823 inserted as a breakpoint. If it can't throw an error. */
8826 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
8830 for (i = 0; i < sals->nelts; i++)
8831 resolve_sal_pc (&sals->sals[i]);
8834 /* Fast tracepoints may have restrictions on valid locations. For
8835 instance, a fast tracepoint using a jump instead of a trap will
8836 likely have to overwrite more bytes than a trap would, and so can
8837 only be placed where the instruction is longer than the jump, or a
8838 multi-instruction sequence does not have a jump into the middle of
8842 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
8843 struct symtabs_and_lines *sals)
8846 struct symtab_and_line *sal;
8848 struct cleanup *old_chain;
8850 for (i = 0; i < sals->nelts; i++)
8852 struct gdbarch *sarch;
8854 sal = &sals->sals[i];
8856 sarch = get_sal_arch (*sal);
8857 /* We fall back to GDBARCH if there is no architecture
8858 associated with SAL. */
8861 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc,
8863 old_chain = make_cleanup (xfree, msg);
8866 error (_("May not have a fast tracepoint at 0x%s%s"),
8867 paddress (sarch, sal->pc), (msg ? msg : ""));
8869 do_cleanups (old_chain);
8873 /* Given TOK, a string specification of condition and thread, as
8874 accepted by the 'break' command, extract the condition
8875 string and thread number and set *COND_STRING and *THREAD.
8876 PC identifies the context at which the condition should be parsed.
8877 If no condition is found, *COND_STRING is set to NULL.
8878 If no thread is found, *THREAD is set to -1. */
8881 find_condition_and_thread (char *tok, CORE_ADDR pc,
8882 char **cond_string, int *thread, int *task,
8885 *cond_string = NULL;
8891 char *cond_start = NULL;
8892 char *cond_end = NULL;
8894 tok = skip_spaces (tok);
8896 if ((*tok == '"' || *tok == ',') && rest)
8898 *rest = savestring (tok, strlen (tok));
8902 end_tok = skip_to_space (tok);
8904 toklen = end_tok - tok;
8906 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
8908 struct expression *expr;
8910 tok = cond_start = end_tok + 1;
8911 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
8914 *cond_string = savestring (cond_start, cond_end - cond_start);
8916 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
8922 *thread = strtol (tok, &tok, 0);
8924 error (_("Junk after thread keyword."));
8925 if (!valid_thread_id (*thread))
8926 error (_("Unknown thread %d."), *thread);
8928 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
8934 *task = strtol (tok, &tok, 0);
8936 error (_("Junk after task keyword."));
8937 if (!valid_task_id (*task))
8938 error (_("Unknown task %d."), *task);
8942 *rest = savestring (tok, strlen (tok));
8946 error (_("Junk at end of arguments."));
8950 /* Decode a static tracepoint marker spec. */
8952 static struct symtabs_and_lines
8953 decode_static_tracepoint_spec (char **arg_p)
8955 VEC(static_tracepoint_marker_p) *markers = NULL;
8956 struct symtabs_and_lines sals;
8957 struct cleanup *old_chain;
8958 char *p = &(*arg_p)[3];
8963 p = skip_spaces (p);
8965 endp = skip_to_space (p);
8967 marker_str = savestring (p, endp - p);
8968 old_chain = make_cleanup (xfree, marker_str);
8970 markers = target_static_tracepoint_markers_by_strid (marker_str);
8971 if (VEC_empty(static_tracepoint_marker_p, markers))
8972 error (_("No known static tracepoint marker named %s"), marker_str);
8974 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
8975 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
8977 for (i = 0; i < sals.nelts; i++)
8979 struct static_tracepoint_marker *marker;
8981 marker = VEC_index (static_tracepoint_marker_p, markers, i);
8983 init_sal (&sals.sals[i]);
8985 sals.sals[i] = find_pc_line (marker->address, 0);
8986 sals.sals[i].pc = marker->address;
8988 release_static_tracepoint_marker (marker);
8991 do_cleanups (old_chain);
8997 /* Set a breakpoint. This function is shared between CLI and MI
8998 functions for setting a breakpoint. This function has two major
8999 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
9000 parameter. If non-zero, the function will parse arg, extracting
9001 breakpoint location, address and thread. Otherwise, ARG is just
9002 the location of breakpoint, with condition and thread specified by
9003 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
9004 the breakpoint number will be allocated from the internal
9005 breakpoint count. Returns true if any breakpoint was created;
9009 create_breakpoint (struct gdbarch *gdbarch,
9010 char *arg, char *cond_string,
9011 int thread, char *extra_string,
9012 int parse_condition_and_thread,
9013 int tempflag, enum bptype type_wanted,
9015 enum auto_boolean pending_break_support,
9016 const struct breakpoint_ops *ops,
9017 int from_tty, int enabled, int internal,
9020 volatile struct gdb_exception e;
9021 char *copy_arg = NULL;
9022 char *addr_start = arg;
9023 struct linespec_result canonical;
9024 struct cleanup *old_chain;
9025 struct cleanup *bkpt_chain = NULL;
9028 int prev_bkpt_count = breakpoint_count;
9030 gdb_assert (ops != NULL);
9032 init_linespec_result (&canonical);
9034 TRY_CATCH (e, RETURN_MASK_ALL)
9036 ops->create_sals_from_address (&arg, &canonical, type_wanted,
9037 addr_start, ©_arg);
9040 /* If caller is interested in rc value from parse, set value. */
9044 if (VEC_empty (linespec_sals, canonical.sals))
9050 case NOT_FOUND_ERROR:
9052 /* If pending breakpoint support is turned off, throw
9055 if (pending_break_support == AUTO_BOOLEAN_FALSE)
9056 throw_exception (e);
9058 exception_print (gdb_stderr, e);
9060 /* If pending breakpoint support is auto query and the user
9061 selects no, then simply return the error code. */
9062 if (pending_break_support == AUTO_BOOLEAN_AUTO
9063 && !nquery (_("Make %s pending on future shared library load? "),
9064 bptype_string (type_wanted)))
9067 /* At this point, either the user was queried about setting
9068 a pending breakpoint and selected yes, or pending
9069 breakpoint behavior is on and thus a pending breakpoint
9070 is defaulted on behalf of the user. */
9072 struct linespec_sals lsal;
9074 copy_arg = xstrdup (addr_start);
9075 lsal.canonical = xstrdup (copy_arg);
9076 lsal.sals.nelts = 1;
9077 lsal.sals.sals = XNEW (struct symtab_and_line);
9078 init_sal (&lsal.sals.sals[0]);
9080 VEC_safe_push (linespec_sals, canonical.sals, &lsal);
9084 throw_exception (e);
9088 throw_exception (e);
9091 /* Create a chain of things that always need to be cleaned up. */
9092 old_chain = make_cleanup_destroy_linespec_result (&canonical);
9094 /* ----------------------------- SNIP -----------------------------
9095 Anything added to the cleanup chain beyond this point is assumed
9096 to be part of a breakpoint. If the breakpoint create succeeds
9097 then the memory is not reclaimed. */
9098 bkpt_chain = make_cleanup (null_cleanup, 0);
9100 /* Resolve all line numbers to PC's and verify that the addresses
9101 are ok for the target. */
9105 struct linespec_sals *iter;
9107 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9108 breakpoint_sals_to_pc (&iter->sals);
9111 /* Fast tracepoints may have additional restrictions on location. */
9112 if (!pending && type_wanted == bp_fast_tracepoint)
9115 struct linespec_sals *iter;
9117 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9118 check_fast_tracepoint_sals (gdbarch, &iter->sals);
9121 /* Verify that condition can be parsed, before setting any
9122 breakpoints. Allocate a separate condition expression for each
9126 struct linespec_sals *lsal;
9128 lsal = VEC_index (linespec_sals, canonical.sals, 0);
9130 if (parse_condition_and_thread)
9133 /* Here we only parse 'arg' to separate condition
9134 from thread number, so parsing in context of first
9135 sal is OK. When setting the breakpoint we'll
9136 re-parse it in context of each sal. */
9140 find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string,
9141 &thread, &task, &rest);
9143 make_cleanup (xfree, cond_string);
9145 make_cleanup (xfree, rest);
9147 extra_string = rest;
9151 /* Create a private copy of condition string. */
9154 cond_string = xstrdup (cond_string);
9155 make_cleanup (xfree, cond_string);
9157 /* Create a private copy of any extra string. */
9160 extra_string = xstrdup (extra_string);
9161 make_cleanup (xfree, extra_string);
9165 ops->create_breakpoints_sal (gdbarch, &canonical, lsal,
9166 cond_string, extra_string, type_wanted,
9167 tempflag ? disp_del : disp_donttouch,
9168 thread, task, ignore_count, ops,
9169 from_tty, enabled, internal, flags);
9173 struct breakpoint *b;
9175 make_cleanup (xfree, copy_arg);
9177 if (is_tracepoint_type (type_wanted))
9179 struct tracepoint *t;
9181 t = XCNEW (struct tracepoint);
9185 b = XNEW (struct breakpoint);
9187 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
9189 b->addr_string = copy_arg;
9190 b->cond_string = NULL;
9191 b->extra_string = NULL;
9192 b->ignore_count = ignore_count;
9193 b->disposition = tempflag ? disp_del : disp_donttouch;
9194 b->condition_not_parsed = 1;
9195 b->enable_state = enabled ? bp_enabled : bp_disabled;
9196 if ((type_wanted != bp_breakpoint
9197 && type_wanted != bp_hardware_breakpoint) || thread != -1)
9198 b->pspace = current_program_space;
9200 install_breakpoint (internal, b, 0);
9203 if (VEC_length (linespec_sals, canonical.sals) > 1)
9205 warning (_("Multiple breakpoints were set.\nUse the "
9206 "\"delete\" command to delete unwanted breakpoints."));
9207 prev_breakpoint_count = prev_bkpt_count;
9210 /* That's it. Discard the cleanups for data inserted into the
9212 discard_cleanups (bkpt_chain);
9213 /* But cleanup everything else. */
9214 do_cleanups (old_chain);
9216 /* error call may happen here - have BKPT_CHAIN already discarded. */
9217 update_global_location_list (1);
9222 /* Set a breakpoint.
9223 ARG is a string describing breakpoint address,
9224 condition, and thread.
9225 FLAG specifies if a breakpoint is hardware on,
9226 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9230 break_command_1 (char *arg, int flag, int from_tty)
9232 int tempflag = flag & BP_TEMPFLAG;
9233 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9234 ? bp_hardware_breakpoint
9236 struct breakpoint_ops *ops;
9237 const char *arg_cp = arg;
9239 /* Matching breakpoints on probes. */
9240 if (arg && probe_linespec_to_ops (&arg_cp) != NULL)
9241 ops = &bkpt_probe_breakpoint_ops;
9243 ops = &bkpt_breakpoint_ops;
9245 create_breakpoint (get_current_arch (),
9247 NULL, 0, NULL, 1 /* parse arg */,
9248 tempflag, type_wanted,
9249 0 /* Ignore count */,
9250 pending_break_support,
9258 /* Helper function for break_command_1 and disassemble_command. */
9261 resolve_sal_pc (struct symtab_and_line *sal)
9265 if (sal->pc == 0 && sal->symtab != NULL)
9267 if (!find_line_pc (sal->symtab, sal->line, &pc))
9268 error (_("No line %d in file \"%s\"."),
9269 sal->line, sal->symtab->filename);
9272 /* If this SAL corresponds to a breakpoint inserted using a line
9273 number, then skip the function prologue if necessary. */
9274 if (sal->explicit_line)
9275 skip_prologue_sal (sal);
9278 if (sal->section == 0 && sal->symtab != NULL)
9280 struct blockvector *bv;
9284 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
9287 sym = block_linkage_function (b);
9290 fixup_symbol_section (sym, sal->symtab->objfile);
9291 sal->section = SYMBOL_OBJ_SECTION (sym);
9295 /* It really is worthwhile to have the section, so we'll
9296 just have to look harder. This case can be executed
9297 if we have line numbers but no functions (as can
9298 happen in assembly source). */
9300 struct minimal_symbol *msym;
9301 struct cleanup *old_chain = save_current_space_and_thread ();
9303 switch_to_program_space_and_thread (sal->pspace);
9305 msym = lookup_minimal_symbol_by_pc (sal->pc);
9307 sal->section = SYMBOL_OBJ_SECTION (msym);
9309 do_cleanups (old_chain);
9316 break_command (char *arg, int from_tty)
9318 break_command_1 (arg, 0, from_tty);
9322 tbreak_command (char *arg, int from_tty)
9324 break_command_1 (arg, BP_TEMPFLAG, from_tty);
9328 hbreak_command (char *arg, int from_tty)
9330 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
9334 thbreak_command (char *arg, int from_tty)
9336 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
9340 stop_command (char *arg, int from_tty)
9342 printf_filtered (_("Specify the type of breakpoint to set.\n\
9343 Usage: stop in <function | address>\n\
9344 stop at <line>\n"));
9348 stopin_command (char *arg, int from_tty)
9352 if (arg == (char *) NULL)
9354 else if (*arg != '*')
9359 /* Look for a ':'. If this is a line number specification, then
9360 say it is bad, otherwise, it should be an address or
9361 function/method name. */
9362 while (*argptr && !hasColon)
9364 hasColon = (*argptr == ':');
9369 badInput = (*argptr != ':'); /* Not a class::method */
9371 badInput = isdigit (*arg); /* a simple line number */
9375 printf_filtered (_("Usage: stop in <function | address>\n"));
9377 break_command_1 (arg, 0, from_tty);
9381 stopat_command (char *arg, int from_tty)
9385 if (arg == (char *) NULL || *arg == '*') /* no line number */
9392 /* Look for a ':'. If there is a '::' then get out, otherwise
9393 it is probably a line number. */
9394 while (*argptr && !hasColon)
9396 hasColon = (*argptr == ':');
9401 badInput = (*argptr == ':'); /* we have class::method */
9403 badInput = !isdigit (*arg); /* not a line number */
9407 printf_filtered (_("Usage: stop at <line>\n"));
9409 break_command_1 (arg, 0, from_tty);
9412 void dprintf_command (char *arg, int from_tty);
9414 /* The dynamic printf command is mostly like a regular breakpoint, but
9415 with a prewired command list consisting of a single output command,
9416 built from extra arguments supplied on the dprintf command
9420 dprintf_command (char *arg, int from_tty)
9422 create_breakpoint (get_current_arch (),
9424 NULL, 0, NULL, 1 /* parse arg */,
9426 0 /* Ignore count */,
9427 pending_break_support,
9428 &dprintf_breakpoint_ops,
9435 /* Implement the "breakpoint_hit" breakpoint_ops method for
9436 ranged breakpoints. */
9439 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
9440 struct address_space *aspace,
9442 const struct target_waitstatus *ws)
9444 if (ws->kind != TARGET_WAITKIND_STOPPED
9445 || ws->value.sig != TARGET_SIGNAL_TRAP)
9448 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
9449 bl->length, aspace, bp_addr);
9452 /* Implement the "resources_needed" breakpoint_ops method for
9453 ranged breakpoints. */
9456 resources_needed_ranged_breakpoint (const struct bp_location *bl)
9458 return target_ranged_break_num_registers ();
9461 /* Implement the "print_it" breakpoint_ops method for
9462 ranged breakpoints. */
9464 static enum print_stop_action
9465 print_it_ranged_breakpoint (bpstat bs)
9467 struct breakpoint *b = bs->breakpoint_at;
9468 struct bp_location *bl = b->loc;
9469 struct ui_out *uiout = current_uiout;
9471 gdb_assert (b->type == bp_hardware_breakpoint);
9473 /* Ranged breakpoints have only one location. */
9474 gdb_assert (bl && bl->next == NULL);
9476 annotate_breakpoint (b->number);
9477 if (b->disposition == disp_del)
9478 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
9480 ui_out_text (uiout, "\nRanged breakpoint ");
9481 if (ui_out_is_mi_like_p (uiout))
9483 ui_out_field_string (uiout, "reason",
9484 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
9485 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
9487 ui_out_field_int (uiout, "bkptno", b->number);
9488 ui_out_text (uiout, ", ");
9490 return PRINT_SRC_AND_LOC;
9493 /* Implement the "print_one" breakpoint_ops method for
9494 ranged breakpoints. */
9497 print_one_ranged_breakpoint (struct breakpoint *b,
9498 struct bp_location **last_loc)
9500 struct bp_location *bl = b->loc;
9501 struct value_print_options opts;
9502 struct ui_out *uiout = current_uiout;
9504 /* Ranged breakpoints have only one location. */
9505 gdb_assert (bl && bl->next == NULL);
9507 get_user_print_options (&opts);
9509 if (opts.addressprint)
9510 /* We don't print the address range here, it will be printed later
9511 by print_one_detail_ranged_breakpoint. */
9512 ui_out_field_skip (uiout, "addr");
9514 print_breakpoint_location (b, bl);
9518 /* Implement the "print_one_detail" breakpoint_ops method for
9519 ranged breakpoints. */
9522 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
9523 struct ui_out *uiout)
9525 CORE_ADDR address_start, address_end;
9526 struct bp_location *bl = b->loc;
9527 struct ui_file *stb = mem_fileopen ();
9528 struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
9532 address_start = bl->address;
9533 address_end = address_start + bl->length - 1;
9535 ui_out_text (uiout, "\taddress range: ");
9536 fprintf_unfiltered (stb, "[%s, %s]",
9537 print_core_address (bl->gdbarch, address_start),
9538 print_core_address (bl->gdbarch, address_end));
9539 ui_out_field_stream (uiout, "addr", stb);
9540 ui_out_text (uiout, "\n");
9542 do_cleanups (cleanup);
9545 /* Implement the "print_mention" breakpoint_ops method for
9546 ranged breakpoints. */
9549 print_mention_ranged_breakpoint (struct breakpoint *b)
9551 struct bp_location *bl = b->loc;
9552 struct ui_out *uiout = current_uiout;
9555 gdb_assert (b->type == bp_hardware_breakpoint);
9557 if (ui_out_is_mi_like_p (uiout))
9560 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9561 b->number, paddress (bl->gdbarch, bl->address),
9562 paddress (bl->gdbarch, bl->address + bl->length - 1));
9565 /* Implement the "print_recreate" breakpoint_ops method for
9566 ranged breakpoints. */
9569 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
9571 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
9572 b->addr_string_range_end);
9573 print_recreate_thread (b, fp);
9576 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9578 static struct breakpoint_ops ranged_breakpoint_ops;
9580 /* Find the address where the end of the breakpoint range should be
9581 placed, given the SAL of the end of the range. This is so that if
9582 the user provides a line number, the end of the range is set to the
9583 last instruction of the given line. */
9586 find_breakpoint_range_end (struct symtab_and_line sal)
9590 /* If the user provided a PC value, use it. Otherwise,
9591 find the address of the end of the given location. */
9592 if (sal.explicit_pc)
9599 ret = find_line_pc_range (sal, &start, &end);
9601 error (_("Could not find location of the end of the range."));
9603 /* find_line_pc_range returns the start of the next line. */
9610 /* Implement the "break-range" CLI command. */
9613 break_range_command (char *arg, int from_tty)
9615 char *arg_start, *addr_string_start, *addr_string_end;
9616 struct linespec_result canonical_start, canonical_end;
9617 int bp_count, can_use_bp, length;
9619 struct breakpoint *b;
9620 struct symtab_and_line sal_start, sal_end;
9621 struct cleanup *cleanup_bkpt;
9622 struct linespec_sals *lsal_start, *lsal_end;
9624 /* We don't support software ranged breakpoints. */
9625 if (target_ranged_break_num_registers () < 0)
9626 error (_("This target does not support hardware ranged breakpoints."));
9628 bp_count = hw_breakpoint_used_count ();
9629 bp_count += target_ranged_break_num_registers ();
9630 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9633 error (_("Hardware breakpoints used exceeds limit."));
9635 arg = skip_spaces (arg);
9636 if (arg == NULL || arg[0] == '\0')
9637 error(_("No address range specified."));
9639 init_linespec_result (&canonical_start);
9642 parse_breakpoint_sals (&arg, &canonical_start);
9644 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
9647 error (_("Too few arguments."));
9648 else if (VEC_empty (linespec_sals, canonical_start.sals))
9649 error (_("Could not find location of the beginning of the range."));
9651 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
9653 if (VEC_length (linespec_sals, canonical_start.sals) > 1
9654 || lsal_start->sals.nelts != 1)
9655 error (_("Cannot create a ranged breakpoint with multiple locations."));
9657 sal_start = lsal_start->sals.sals[0];
9658 addr_string_start = savestring (arg_start, arg - arg_start);
9659 make_cleanup (xfree, addr_string_start);
9661 arg++; /* Skip the comma. */
9662 arg = skip_spaces (arg);
9664 /* Parse the end location. */
9666 init_linespec_result (&canonical_end);
9669 /* We call decode_line_full directly here instead of using
9670 parse_breakpoint_sals because we need to specify the start location's
9671 symtab and line as the default symtab and line for the end of the
9672 range. This makes it possible to have ranges like "foo.c:27, +14",
9673 where +14 means 14 lines from the start location. */
9674 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
9675 sal_start.symtab, sal_start.line,
9676 &canonical_end, NULL, NULL);
9678 make_cleanup_destroy_linespec_result (&canonical_end);
9680 if (VEC_empty (linespec_sals, canonical_end.sals))
9681 error (_("Could not find location of the end of the range."));
9683 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
9684 if (VEC_length (linespec_sals, canonical_end.sals) > 1
9685 || lsal_end->sals.nelts != 1)
9686 error (_("Cannot create a ranged breakpoint with multiple locations."));
9688 sal_end = lsal_end->sals.sals[0];
9689 addr_string_end = savestring (arg_start, arg - arg_start);
9690 make_cleanup (xfree, addr_string_end);
9692 end = find_breakpoint_range_end (sal_end);
9693 if (sal_start.pc > end)
9694 error (_("Invalid address range, end precedes start."));
9696 length = end - sal_start.pc + 1;
9698 /* Length overflowed. */
9699 error (_("Address range too large."));
9700 else if (length == 1)
9702 /* This range is simple enough to be handled by
9703 the `hbreak' command. */
9704 hbreak_command (addr_string_start, 1);
9706 do_cleanups (cleanup_bkpt);
9711 /* Now set up the breakpoint. */
9712 b = set_raw_breakpoint (get_current_arch (), sal_start,
9713 bp_hardware_breakpoint, &ranged_breakpoint_ops);
9714 set_breakpoint_count (breakpoint_count + 1);
9715 b->number = breakpoint_count;
9716 b->disposition = disp_donttouch;
9717 b->addr_string = xstrdup (addr_string_start);
9718 b->addr_string_range_end = xstrdup (addr_string_end);
9719 b->loc->length = length;
9721 do_cleanups (cleanup_bkpt);
9724 observer_notify_breakpoint_created (b);
9725 update_global_location_list (1);
9728 /* Return non-zero if EXP is verified as constant. Returned zero
9729 means EXP is variable. Also the constant detection may fail for
9730 some constant expressions and in such case still falsely return
9734 watchpoint_exp_is_const (const struct expression *exp)
9742 /* We are only interested in the descriptor of each element. */
9743 operator_length (exp, i, &oplenp, &argsp);
9746 switch (exp->elts[i].opcode)
9756 case BINOP_LOGICAL_AND:
9757 case BINOP_LOGICAL_OR:
9758 case BINOP_BITWISE_AND:
9759 case BINOP_BITWISE_IOR:
9760 case BINOP_BITWISE_XOR:
9762 case BINOP_NOTEQUAL:
9778 case TERNOP_SLICE_COUNT:
9790 case OP_OBJC_NSSTRING:
9793 case UNOP_LOGICAL_NOT:
9794 case UNOP_COMPLEMENT:
9798 /* Unary, binary and ternary operators: We have to check
9799 their operands. If they are constant, then so is the
9800 result of that operation. For instance, if A and B are
9801 determined to be constants, then so is "A + B".
9803 UNOP_IND is one exception to the rule above, because the
9804 value of *ADDR is not necessarily a constant, even when
9809 /* Check whether the associated symbol is a constant.
9811 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9812 possible that a buggy compiler could mark a variable as
9813 constant even when it is not, and TYPE_CONST would return
9814 true in this case, while SYMBOL_CLASS wouldn't.
9816 We also have to check for function symbols because they
9817 are always constant. */
9819 struct symbol *s = exp->elts[i + 2].symbol;
9821 if (SYMBOL_CLASS (s) != LOC_BLOCK
9822 && SYMBOL_CLASS (s) != LOC_CONST
9823 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
9828 /* The default action is to return 0 because we are using
9829 the optimistic approach here: If we don't know something,
9830 then it is not a constant. */
9839 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
9842 dtor_watchpoint (struct breakpoint *self)
9844 struct watchpoint *w = (struct watchpoint *) self;
9846 xfree (w->cond_exp);
9848 xfree (w->exp_string);
9849 xfree (w->exp_string_reparse);
9850 value_free (w->val);
9852 base_breakpoint_ops.dtor (self);
9855 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
9858 re_set_watchpoint (struct breakpoint *b)
9860 struct watchpoint *w = (struct watchpoint *) b;
9862 /* Watchpoint can be either on expression using entirely global
9863 variables, or it can be on local variables.
9865 Watchpoints of the first kind are never auto-deleted, and even
9866 persist across program restarts. Since they can use variables
9867 from shared libraries, we need to reparse expression as libraries
9868 are loaded and unloaded.
9870 Watchpoints on local variables can also change meaning as result
9871 of solib event. For example, if a watchpoint uses both a local
9872 and a global variables in expression, it's a local watchpoint,
9873 but unloading of a shared library will make the expression
9874 invalid. This is not a very common use case, but we still
9875 re-evaluate expression, to avoid surprises to the user.
9877 Note that for local watchpoints, we re-evaluate it only if
9878 watchpoints frame id is still valid. If it's not, it means the
9879 watchpoint is out of scope and will be deleted soon. In fact,
9880 I'm not sure we'll ever be called in this case.
9882 If a local watchpoint's frame id is still valid, then
9883 w->exp_valid_block is likewise valid, and we can safely use it.
9885 Don't do anything about disabled watchpoints, since they will be
9886 reevaluated again when enabled. */
9887 update_watchpoint (w, 1 /* reparse */);
9890 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
9893 insert_watchpoint (struct bp_location *bl)
9895 struct watchpoint *w = (struct watchpoint *) bl->owner;
9896 int length = w->exact ? 1 : bl->length;
9898 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
9902 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
9905 remove_watchpoint (struct bp_location *bl)
9907 struct watchpoint *w = (struct watchpoint *) bl->owner;
9908 int length = w->exact ? 1 : bl->length;
9910 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
9915 breakpoint_hit_watchpoint (const struct bp_location *bl,
9916 struct address_space *aspace, CORE_ADDR bp_addr,
9917 const struct target_waitstatus *ws)
9919 struct breakpoint *b = bl->owner;
9920 struct watchpoint *w = (struct watchpoint *) b;
9922 /* Continuable hardware watchpoints are treated as non-existent if the
9923 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9924 some data address). Otherwise gdb won't stop on a break instruction
9925 in the code (not from a breakpoint) when a hardware watchpoint has
9926 been defined. Also skip watchpoints which we know did not trigger
9927 (did not match the data address). */
9928 if (is_hardware_watchpoint (b)
9929 && w->watchpoint_triggered == watch_triggered_no)
9936 check_status_watchpoint (bpstat bs)
9938 gdb_assert (is_watchpoint (bs->breakpoint_at));
9940 bpstat_check_watchpoint (bs);
9943 /* Implement the "resources_needed" breakpoint_ops method for
9944 hardware watchpoints. */
9947 resources_needed_watchpoint (const struct bp_location *bl)
9949 struct watchpoint *w = (struct watchpoint *) bl->owner;
9950 int length = w->exact? 1 : bl->length;
9952 return target_region_ok_for_hw_watchpoint (bl->address, length);
9955 /* Implement the "works_in_software_mode" breakpoint_ops method for
9956 hardware watchpoints. */
9959 works_in_software_mode_watchpoint (const struct breakpoint *b)
9961 /* Read and access watchpoints only work with hardware support. */
9962 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
9965 static enum print_stop_action
9966 print_it_watchpoint (bpstat bs)
9968 struct cleanup *old_chain;
9969 struct breakpoint *b;
9970 const struct bp_location *bl;
9971 struct ui_file *stb;
9972 enum print_stop_action result;
9973 struct watchpoint *w;
9974 struct ui_out *uiout = current_uiout;
9976 gdb_assert (bs->bp_location_at != NULL);
9978 bl = bs->bp_location_at;
9979 b = bs->breakpoint_at;
9980 w = (struct watchpoint *) b;
9982 stb = mem_fileopen ();
9983 old_chain = make_cleanup_ui_file_delete (stb);
9988 case bp_hardware_watchpoint:
9989 annotate_watchpoint (b->number);
9990 if (ui_out_is_mi_like_p (uiout))
9993 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
9995 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
9996 ui_out_text (uiout, "\nOld value = ");
9997 watchpoint_value_print (bs->old_val, stb);
9998 ui_out_field_stream (uiout, "old", stb);
9999 ui_out_text (uiout, "\nNew value = ");
10000 watchpoint_value_print (w->val, stb);
10001 ui_out_field_stream (uiout, "new", stb);
10002 ui_out_text (uiout, "\n");
10003 /* More than one watchpoint may have been triggered. */
10004 result = PRINT_UNKNOWN;
10007 case bp_read_watchpoint:
10008 if (ui_out_is_mi_like_p (uiout))
10009 ui_out_field_string
10011 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10013 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10014 ui_out_text (uiout, "\nValue = ");
10015 watchpoint_value_print (w->val, stb);
10016 ui_out_field_stream (uiout, "value", stb);
10017 ui_out_text (uiout, "\n");
10018 result = PRINT_UNKNOWN;
10021 case bp_access_watchpoint:
10022 if (bs->old_val != NULL)
10024 annotate_watchpoint (b->number);
10025 if (ui_out_is_mi_like_p (uiout))
10026 ui_out_field_string
10028 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10030 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10031 ui_out_text (uiout, "\nOld value = ");
10032 watchpoint_value_print (bs->old_val, stb);
10033 ui_out_field_stream (uiout, "old", stb);
10034 ui_out_text (uiout, "\nNew value = ");
10039 if (ui_out_is_mi_like_p (uiout))
10040 ui_out_field_string
10042 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10043 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10044 ui_out_text (uiout, "\nValue = ");
10046 watchpoint_value_print (w->val, stb);
10047 ui_out_field_stream (uiout, "new", stb);
10048 ui_out_text (uiout, "\n");
10049 result = PRINT_UNKNOWN;
10052 result = PRINT_UNKNOWN;
10055 do_cleanups (old_chain);
10059 /* Implement the "print_mention" breakpoint_ops method for hardware
10063 print_mention_watchpoint (struct breakpoint *b)
10065 struct cleanup *ui_out_chain;
10066 struct watchpoint *w = (struct watchpoint *) b;
10067 struct ui_out *uiout = current_uiout;
10071 case bp_watchpoint:
10072 ui_out_text (uiout, "Watchpoint ");
10073 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10075 case bp_hardware_watchpoint:
10076 ui_out_text (uiout, "Hardware watchpoint ");
10077 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10079 case bp_read_watchpoint:
10080 ui_out_text (uiout, "Hardware read watchpoint ");
10081 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10083 case bp_access_watchpoint:
10084 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
10085 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10088 internal_error (__FILE__, __LINE__,
10089 _("Invalid hardware watchpoint type."));
10092 ui_out_field_int (uiout, "number", b->number);
10093 ui_out_text (uiout, ": ");
10094 ui_out_field_string (uiout, "exp", w->exp_string);
10095 do_cleanups (ui_out_chain);
10098 /* Implement the "print_recreate" breakpoint_ops method for
10102 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10104 struct watchpoint *w = (struct watchpoint *) b;
10108 case bp_watchpoint:
10109 case bp_hardware_watchpoint:
10110 fprintf_unfiltered (fp, "watch");
10112 case bp_read_watchpoint:
10113 fprintf_unfiltered (fp, "rwatch");
10115 case bp_access_watchpoint:
10116 fprintf_unfiltered (fp, "awatch");
10119 internal_error (__FILE__, __LINE__,
10120 _("Invalid watchpoint type."));
10123 fprintf_unfiltered (fp, " %s", w->exp_string);
10124 print_recreate_thread (b, fp);
10127 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10129 static struct breakpoint_ops watchpoint_breakpoint_ops;
10131 /* Implement the "insert" breakpoint_ops method for
10132 masked hardware watchpoints. */
10135 insert_masked_watchpoint (struct bp_location *bl)
10137 struct watchpoint *w = (struct watchpoint *) bl->owner;
10139 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
10140 bl->watchpoint_type);
10143 /* Implement the "remove" breakpoint_ops method for
10144 masked hardware watchpoints. */
10147 remove_masked_watchpoint (struct bp_location *bl)
10149 struct watchpoint *w = (struct watchpoint *) bl->owner;
10151 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
10152 bl->watchpoint_type);
10155 /* Implement the "resources_needed" breakpoint_ops method for
10156 masked hardware watchpoints. */
10159 resources_needed_masked_watchpoint (const struct bp_location *bl)
10161 struct watchpoint *w = (struct watchpoint *) bl->owner;
10163 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
10166 /* Implement the "works_in_software_mode" breakpoint_ops method for
10167 masked hardware watchpoints. */
10170 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
10175 /* Implement the "print_it" breakpoint_ops method for
10176 masked hardware watchpoints. */
10178 static enum print_stop_action
10179 print_it_masked_watchpoint (bpstat bs)
10181 struct breakpoint *b = bs->breakpoint_at;
10182 struct ui_out *uiout = current_uiout;
10184 /* Masked watchpoints have only one location. */
10185 gdb_assert (b->loc && b->loc->next == NULL);
10189 case bp_hardware_watchpoint:
10190 annotate_watchpoint (b->number);
10191 if (ui_out_is_mi_like_p (uiout))
10192 ui_out_field_string
10194 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10197 case bp_read_watchpoint:
10198 if (ui_out_is_mi_like_p (uiout))
10199 ui_out_field_string
10201 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10204 case bp_access_watchpoint:
10205 if (ui_out_is_mi_like_p (uiout))
10206 ui_out_field_string
10208 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10211 internal_error (__FILE__, __LINE__,
10212 _("Invalid hardware watchpoint type."));
10216 ui_out_text (uiout, _("\n\
10217 Check the underlying instruction at PC for the memory\n\
10218 address and value which triggered this watchpoint.\n"));
10219 ui_out_text (uiout, "\n");
10221 /* More than one watchpoint may have been triggered. */
10222 return PRINT_UNKNOWN;
10225 /* Implement the "print_one_detail" breakpoint_ops method for
10226 masked hardware watchpoints. */
10229 print_one_detail_masked_watchpoint (const struct breakpoint *b,
10230 struct ui_out *uiout)
10232 struct watchpoint *w = (struct watchpoint *) b;
10234 /* Masked watchpoints have only one location. */
10235 gdb_assert (b->loc && b->loc->next == NULL);
10237 ui_out_text (uiout, "\tmask ");
10238 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
10239 ui_out_text (uiout, "\n");
10242 /* Implement the "print_mention" breakpoint_ops method for
10243 masked hardware watchpoints. */
10246 print_mention_masked_watchpoint (struct breakpoint *b)
10248 struct watchpoint *w = (struct watchpoint *) b;
10249 struct ui_out *uiout = current_uiout;
10250 struct cleanup *ui_out_chain;
10254 case bp_hardware_watchpoint:
10255 ui_out_text (uiout, "Masked hardware watchpoint ");
10256 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10258 case bp_read_watchpoint:
10259 ui_out_text (uiout, "Masked hardware read watchpoint ");
10260 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10262 case bp_access_watchpoint:
10263 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
10264 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10267 internal_error (__FILE__, __LINE__,
10268 _("Invalid hardware watchpoint type."));
10271 ui_out_field_int (uiout, "number", b->number);
10272 ui_out_text (uiout, ": ");
10273 ui_out_field_string (uiout, "exp", w->exp_string);
10274 do_cleanups (ui_out_chain);
10277 /* Implement the "print_recreate" breakpoint_ops method for
10278 masked hardware watchpoints. */
10281 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
10283 struct watchpoint *w = (struct watchpoint *) b;
10288 case bp_hardware_watchpoint:
10289 fprintf_unfiltered (fp, "watch");
10291 case bp_read_watchpoint:
10292 fprintf_unfiltered (fp, "rwatch");
10294 case bp_access_watchpoint:
10295 fprintf_unfiltered (fp, "awatch");
10298 internal_error (__FILE__, __LINE__,
10299 _("Invalid hardware watchpoint type."));
10302 sprintf_vma (tmp, w->hw_wp_mask);
10303 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
10304 print_recreate_thread (b, fp);
10307 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10309 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
10311 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10314 is_masked_watchpoint (const struct breakpoint *b)
10316 return b->ops == &masked_watchpoint_breakpoint_ops;
10319 /* accessflag: hw_write: watch write,
10320 hw_read: watch read,
10321 hw_access: watch access (read or write) */
10323 watch_command_1 (char *arg, int accessflag, int from_tty,
10324 int just_location, int internal)
10326 volatile struct gdb_exception e;
10327 struct breakpoint *b, *scope_breakpoint = NULL;
10328 struct expression *exp;
10329 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
10330 struct value *val, *mark, *result;
10331 struct frame_info *frame;
10332 char *exp_start = NULL;
10333 char *exp_end = NULL;
10334 char *tok, *end_tok;
10336 char *cond_start = NULL;
10337 char *cond_end = NULL;
10338 enum bptype bp_type;
10341 /* Flag to indicate whether we are going to use masks for
10342 the hardware watchpoint. */
10344 CORE_ADDR mask = 0;
10345 struct watchpoint *w;
10347 /* Make sure that we actually have parameters to parse. */
10348 if (arg != NULL && arg[0] != '\0')
10352 /* Look for "parameter value" pairs at the end
10353 of the arguments string. */
10354 for (tok = arg + strlen (arg) - 1; tok > arg; tok--)
10356 /* Skip whitespace at the end of the argument list. */
10357 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10360 /* Find the beginning of the last token.
10361 This is the value of the parameter. */
10362 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10364 value_start = tok + 1;
10366 /* Skip whitespace. */
10367 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10372 /* Find the beginning of the second to last token.
10373 This is the parameter itself. */
10374 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10377 toklen = end_tok - tok + 1;
10379 if (toklen == 6 && !strncmp (tok, "thread", 6))
10381 /* At this point we've found a "thread" token, which means
10382 the user is trying to set a watchpoint that triggers
10383 only in a specific thread. */
10387 error(_("You can specify only one thread."));
10389 /* Extract the thread ID from the next token. */
10390 thread = strtol (value_start, &endp, 0);
10392 /* Check if the user provided a valid numeric value for the
10394 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
10395 error (_("Invalid thread ID specification %s."), value_start);
10397 /* Check if the thread actually exists. */
10398 if (!valid_thread_id (thread))
10399 error (_("Unknown thread %d."), thread);
10401 else if (toklen == 4 && !strncmp (tok, "mask", 4))
10403 /* We've found a "mask" token, which means the user wants to
10404 create a hardware watchpoint that is going to have the mask
10406 struct value *mask_value, *mark;
10409 error(_("You can specify only one mask."));
10411 use_mask = just_location = 1;
10413 mark = value_mark ();
10414 mask_value = parse_to_comma_and_eval (&value_start);
10415 mask = value_as_address (mask_value);
10416 value_free_to_mark (mark);
10419 /* We didn't recognize what we found. We should stop here. */
10422 /* Truncate the string and get rid of the "parameter value" pair before
10423 the arguments string is parsed by the parse_exp_1 function. */
10428 /* Parse the rest of the arguments. */
10429 innermost_block = NULL;
10431 exp = parse_exp_1 (&arg, 0, 0);
10433 /* Remove trailing whitespace from the expression before saving it.
10434 This makes the eventual display of the expression string a bit
10436 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
10439 /* Checking if the expression is not constant. */
10440 if (watchpoint_exp_is_const (exp))
10444 len = exp_end - exp_start;
10445 while (len > 0 && isspace (exp_start[len - 1]))
10447 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
10450 exp_valid_block = innermost_block;
10451 mark = value_mark ();
10452 fetch_subexp_value (exp, &pc, &val, &result, NULL);
10458 exp_valid_block = NULL;
10459 val = value_addr (result);
10460 release_value (val);
10461 value_free_to_mark (mark);
10465 ret = target_masked_watch_num_registers (value_as_address (val),
10468 error (_("This target does not support masked watchpoints."));
10469 else if (ret == -2)
10470 error (_("Invalid mask or memory region."));
10473 else if (val != NULL)
10474 release_value (val);
10476 tok = skip_spaces (arg);
10477 end_tok = skip_to_space (tok);
10479 toklen = end_tok - tok;
10480 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
10482 struct expression *cond;
10484 innermost_block = NULL;
10485 tok = cond_start = end_tok + 1;
10486 cond = parse_exp_1 (&tok, 0, 0);
10488 /* The watchpoint expression may not be local, but the condition
10489 may still be. E.g.: `watch global if local > 0'. */
10490 cond_exp_valid_block = innermost_block;
10496 error (_("Junk at end of command."));
10498 if (accessflag == hw_read)
10499 bp_type = bp_read_watchpoint;
10500 else if (accessflag == hw_access)
10501 bp_type = bp_access_watchpoint;
10503 bp_type = bp_hardware_watchpoint;
10505 frame = block_innermost_frame (exp_valid_block);
10507 /* If the expression is "local", then set up a "watchpoint scope"
10508 breakpoint at the point where we've left the scope of the watchpoint
10509 expression. Create the scope breakpoint before the watchpoint, so
10510 that we will encounter it first in bpstat_stop_status. */
10511 if (exp_valid_block && frame)
10513 if (frame_id_p (frame_unwind_caller_id (frame)))
10516 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
10517 frame_unwind_caller_pc (frame),
10518 bp_watchpoint_scope,
10519 &momentary_breakpoint_ops);
10521 scope_breakpoint->enable_state = bp_enabled;
10523 /* Automatically delete the breakpoint when it hits. */
10524 scope_breakpoint->disposition = disp_del;
10526 /* Only break in the proper frame (help with recursion). */
10527 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
10529 /* Set the address at which we will stop. */
10530 scope_breakpoint->loc->gdbarch
10531 = frame_unwind_caller_arch (frame);
10532 scope_breakpoint->loc->requested_address
10533 = frame_unwind_caller_pc (frame);
10534 scope_breakpoint->loc->address
10535 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
10536 scope_breakpoint->loc->requested_address,
10537 scope_breakpoint->type);
10541 /* Now set up the breakpoint. */
10543 w = XCNEW (struct watchpoint);
10546 init_raw_breakpoint_without_location (b, NULL, bp_type,
10547 &masked_watchpoint_breakpoint_ops);
10549 init_raw_breakpoint_without_location (b, NULL, bp_type,
10550 &watchpoint_breakpoint_ops);
10551 b->thread = thread;
10552 b->disposition = disp_donttouch;
10553 b->pspace = current_program_space;
10555 w->exp_valid_block = exp_valid_block;
10556 w->cond_exp_valid_block = cond_exp_valid_block;
10559 struct type *t = value_type (val);
10560 CORE_ADDR addr = value_as_address (val);
10563 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
10564 name = type_to_string (t);
10566 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
10567 core_addr_to_string (addr));
10570 w->exp_string = xstrprintf ("-location %.*s",
10571 (int) (exp_end - exp_start), exp_start);
10573 /* The above expression is in C. */
10574 b->language = language_c;
10577 w->exp_string = savestring (exp_start, exp_end - exp_start);
10581 w->hw_wp_mask = mask;
10590 b->cond_string = savestring (cond_start, cond_end - cond_start);
10592 b->cond_string = 0;
10596 w->watchpoint_frame = get_frame_id (frame);
10597 w->watchpoint_thread = inferior_ptid;
10601 w->watchpoint_frame = null_frame_id;
10602 w->watchpoint_thread = null_ptid;
10605 if (scope_breakpoint != NULL)
10607 /* The scope breakpoint is related to the watchpoint. We will
10608 need to act on them together. */
10609 b->related_breakpoint = scope_breakpoint;
10610 scope_breakpoint->related_breakpoint = b;
10613 if (!just_location)
10614 value_free_to_mark (mark);
10616 TRY_CATCH (e, RETURN_MASK_ALL)
10618 /* Finally update the new watchpoint. This creates the locations
10619 that should be inserted. */
10620 update_watchpoint (w, 1);
10624 delete_breakpoint (b);
10625 throw_exception (e);
10628 install_breakpoint (internal, b, 1);
10631 /* Return count of debug registers needed to watch the given expression.
10632 If the watchpoint cannot be handled in hardware return zero. */
10635 can_use_hardware_watchpoint (struct value *v)
10637 int found_memory_cnt = 0;
10638 struct value *head = v;
10640 /* Did the user specifically forbid us to use hardware watchpoints? */
10641 if (!can_use_hw_watchpoints)
10644 /* Make sure that the value of the expression depends only upon
10645 memory contents, and values computed from them within GDB. If we
10646 find any register references or function calls, we can't use a
10647 hardware watchpoint.
10649 The idea here is that evaluating an expression generates a series
10650 of values, one holding the value of every subexpression. (The
10651 expression a*b+c has five subexpressions: a, b, a*b, c, and
10652 a*b+c.) GDB's values hold almost enough information to establish
10653 the criteria given above --- they identify memory lvalues,
10654 register lvalues, computed values, etcetera. So we can evaluate
10655 the expression, and then scan the chain of values that leaves
10656 behind to decide whether we can detect any possible change to the
10657 expression's final value using only hardware watchpoints.
10659 However, I don't think that the values returned by inferior
10660 function calls are special in any way. So this function may not
10661 notice that an expression involving an inferior function call
10662 can't be watched with hardware watchpoints. FIXME. */
10663 for (; v; v = value_next (v))
10665 if (VALUE_LVAL (v) == lval_memory)
10667 if (v != head && value_lazy (v))
10668 /* A lazy memory lvalue in the chain is one that GDB never
10669 needed to fetch; we either just used its address (e.g.,
10670 `a' in `a.b') or we never needed it at all (e.g., `a'
10671 in `a,b'). This doesn't apply to HEAD; if that is
10672 lazy then it was not readable, but watch it anyway. */
10676 /* Ahh, memory we actually used! Check if we can cover
10677 it with hardware watchpoints. */
10678 struct type *vtype = check_typedef (value_type (v));
10680 /* We only watch structs and arrays if user asked for it
10681 explicitly, never if they just happen to appear in a
10682 middle of some value chain. */
10684 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
10685 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
10687 CORE_ADDR vaddr = value_address (v);
10691 len = (target_exact_watchpoints
10692 && is_scalar_type_recursive (vtype))?
10693 1 : TYPE_LENGTH (value_type (v));
10695 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
10699 found_memory_cnt += num_regs;
10703 else if (VALUE_LVAL (v) != not_lval
10704 && deprecated_value_modifiable (v) == 0)
10705 return 0; /* These are values from the history (e.g., $1). */
10706 else if (VALUE_LVAL (v) == lval_register)
10707 return 0; /* Cannot watch a register with a HW watchpoint. */
10710 /* The expression itself looks suitable for using a hardware
10711 watchpoint, but give the target machine a chance to reject it. */
10712 return found_memory_cnt;
10716 watch_command_wrapper (char *arg, int from_tty, int internal)
10718 watch_command_1 (arg, hw_write, from_tty, 0, internal);
10721 /* A helper function that looks for an argument at the start of a
10722 string. The argument must also either be at the end of the string,
10723 or be followed by whitespace. Returns 1 if it finds the argument,
10724 0 otherwise. If the argument is found, it updates *STR. */
10727 check_for_argument (char **str, char *arg, int arg_len)
10729 if (strncmp (*str, arg, arg_len) == 0
10730 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
10738 /* A helper function that looks for the "-location" argument and then
10739 calls watch_command_1. */
10742 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
10744 int just_location = 0;
10747 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
10748 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
10750 arg = skip_spaces (arg);
10754 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
10758 watch_command (char *arg, int from_tty)
10760 watch_maybe_just_location (arg, hw_write, from_tty);
10764 rwatch_command_wrapper (char *arg, int from_tty, int internal)
10766 watch_command_1 (arg, hw_read, from_tty, 0, internal);
10770 rwatch_command (char *arg, int from_tty)
10772 watch_maybe_just_location (arg, hw_read, from_tty);
10776 awatch_command_wrapper (char *arg, int from_tty, int internal)
10778 watch_command_1 (arg, hw_access, from_tty, 0, internal);
10782 awatch_command (char *arg, int from_tty)
10784 watch_maybe_just_location (arg, hw_access, from_tty);
10788 /* Helper routines for the until_command routine in infcmd.c. Here
10789 because it uses the mechanisms of breakpoints. */
10791 struct until_break_command_continuation_args
10793 struct breakpoint *breakpoint;
10794 struct breakpoint *breakpoint2;
10798 /* This function is called by fetch_inferior_event via the
10799 cmd_continuation pointer, to complete the until command. It takes
10800 care of cleaning up the temporary breakpoints set up by the until
10803 until_break_command_continuation (void *arg, int err)
10805 struct until_break_command_continuation_args *a = arg;
10807 delete_breakpoint (a->breakpoint);
10808 if (a->breakpoint2)
10809 delete_breakpoint (a->breakpoint2);
10810 delete_longjmp_breakpoint (a->thread_num);
10814 until_break_command (char *arg, int from_tty, int anywhere)
10816 struct symtabs_and_lines sals;
10817 struct symtab_and_line sal;
10818 struct frame_info *frame = get_selected_frame (NULL);
10819 struct gdbarch *frame_gdbarch = get_frame_arch (frame);
10820 struct frame_id stack_frame_id = get_stack_frame_id (frame);
10821 struct frame_id caller_frame_id = frame_unwind_caller_id (frame);
10822 struct breakpoint *breakpoint;
10823 struct breakpoint *breakpoint2 = NULL;
10824 struct cleanup *old_chain;
10826 struct thread_info *tp;
10828 clear_proceed_status ();
10830 /* Set a breakpoint where the user wants it and at return from
10833 if (last_displayed_sal_is_valid ())
10834 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
10835 get_last_displayed_symtab (),
10836 get_last_displayed_line ());
10838 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
10839 (struct symtab *) NULL, 0);
10841 if (sals.nelts != 1)
10842 error (_("Couldn't get information on specified line."));
10844 sal = sals.sals[0];
10845 xfree (sals.sals); /* malloc'd, so freed. */
10848 error (_("Junk at end of arguments."));
10850 resolve_sal_pc (&sal);
10852 tp = inferior_thread ();
10855 old_chain = make_cleanup (null_cleanup, NULL);
10857 /* Installing a breakpoint invalidates the frame chain (as it may
10858 need to switch threads), so do any frame handling first. */
10860 /* Keep within the current frame, or in frames called by the current
10863 if (frame_id_p (caller_frame_id))
10865 struct symtab_and_line sal2;
10867 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
10868 sal2.pc = frame_unwind_caller_pc (frame);
10869 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
10873 make_cleanup_delete_breakpoint (breakpoint2);
10875 set_longjmp_breakpoint (tp, caller_frame_id);
10876 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
10879 /* set_momentary_breakpoint could invalidate FRAME. */
10883 /* If the user told us to continue until a specified location,
10884 we don't specify a frame at which we need to stop. */
10885 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
10886 null_frame_id, bp_until);
10888 /* Otherwise, specify the selected frame, because we want to stop
10889 only at the very same frame. */
10890 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
10891 stack_frame_id, bp_until);
10892 make_cleanup_delete_breakpoint (breakpoint);
10894 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
10896 /* If we are running asynchronously, and proceed call above has
10897 actually managed to start the target, arrange for breakpoints to
10898 be deleted when the target stops. Otherwise, we're already
10899 stopped and delete breakpoints via cleanup chain. */
10901 if (target_can_async_p () && is_running (inferior_ptid))
10903 struct until_break_command_continuation_args *args;
10904 args = xmalloc (sizeof (*args));
10906 args->breakpoint = breakpoint;
10907 args->breakpoint2 = breakpoint2;
10908 args->thread_num = thread;
10910 discard_cleanups (old_chain);
10911 add_continuation (inferior_thread (),
10912 until_break_command_continuation, args,
10916 do_cleanups (old_chain);
10919 /* This function attempts to parse an optional "if <cond>" clause
10920 from the arg string. If one is not found, it returns NULL.
10922 Else, it returns a pointer to the condition string. (It does not
10923 attempt to evaluate the string against a particular block.) And,
10924 it updates arg to point to the first character following the parsed
10925 if clause in the arg string. */
10928 ep_parse_optional_if_clause (char **arg)
10932 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
10935 /* Skip the "if" keyword. */
10938 /* Skip any extra leading whitespace, and record the start of the
10939 condition string. */
10940 *arg = skip_spaces (*arg);
10941 cond_string = *arg;
10943 /* Assume that the condition occupies the remainder of the arg
10945 (*arg) += strlen (cond_string);
10947 return cond_string;
10950 /* Commands to deal with catching events, such as signals, exceptions,
10951 process start/exit, etc. */
10955 catch_fork_temporary, catch_vfork_temporary,
10956 catch_fork_permanent, catch_vfork_permanent
10961 catch_fork_command_1 (char *arg, int from_tty,
10962 struct cmd_list_element *command)
10964 struct gdbarch *gdbarch = get_current_arch ();
10965 char *cond_string = NULL;
10966 catch_fork_kind fork_kind;
10969 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
10970 tempflag = (fork_kind == catch_fork_temporary
10971 || fork_kind == catch_vfork_temporary);
10975 arg = skip_spaces (arg);
10977 /* The allowed syntax is:
10979 catch [v]fork if <cond>
10981 First, check if there's an if clause. */
10982 cond_string = ep_parse_optional_if_clause (&arg);
10984 if ((*arg != '\0') && !isspace (*arg))
10985 error (_("Junk at end of arguments."));
10987 /* If this target supports it, create a fork or vfork catchpoint
10988 and enable reporting of such events. */
10991 case catch_fork_temporary:
10992 case catch_fork_permanent:
10993 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
10994 &catch_fork_breakpoint_ops);
10996 case catch_vfork_temporary:
10997 case catch_vfork_permanent:
10998 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
10999 &catch_vfork_breakpoint_ops);
11002 error (_("unsupported or unknown fork kind; cannot catch it"));
11008 catch_exec_command_1 (char *arg, int from_tty,
11009 struct cmd_list_element *command)
11011 struct exec_catchpoint *c;
11012 struct gdbarch *gdbarch = get_current_arch ();
11014 char *cond_string = NULL;
11016 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11020 arg = skip_spaces (arg);
11022 /* The allowed syntax is:
11024 catch exec if <cond>
11026 First, check if there's an if clause. */
11027 cond_string = ep_parse_optional_if_clause (&arg);
11029 if ((*arg != '\0') && !isspace (*arg))
11030 error (_("Junk at end of arguments."));
11032 c = XNEW (struct exec_catchpoint);
11033 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
11034 &catch_exec_breakpoint_ops);
11035 c->exec_pathname = NULL;
11037 install_breakpoint (0, &c->base, 1);
11040 static enum print_stop_action
11041 print_it_exception_catchpoint (bpstat bs)
11043 struct ui_out *uiout = current_uiout;
11044 struct breakpoint *b = bs->breakpoint_at;
11045 int bp_temp, bp_throw;
11047 annotate_catchpoint (b->number);
11049 bp_throw = strstr (b->addr_string, "throw") != NULL;
11050 if (b->loc->address != b->loc->requested_address)
11051 breakpoint_adjustment_warning (b->loc->requested_address,
11054 bp_temp = b->disposition == disp_del;
11055 ui_out_text (uiout,
11056 bp_temp ? "Temporary catchpoint "
11058 if (!ui_out_is_mi_like_p (uiout))
11059 ui_out_field_int (uiout, "bkptno", b->number);
11060 ui_out_text (uiout,
11061 bp_throw ? " (exception thrown), "
11062 : " (exception caught), ");
11063 if (ui_out_is_mi_like_p (uiout))
11065 ui_out_field_string (uiout, "reason",
11066 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
11067 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
11068 ui_out_field_int (uiout, "bkptno", b->number);
11070 return PRINT_SRC_AND_LOC;
11074 print_one_exception_catchpoint (struct breakpoint *b,
11075 struct bp_location **last_loc)
11077 struct value_print_options opts;
11078 struct ui_out *uiout = current_uiout;
11080 get_user_print_options (&opts);
11081 if (opts.addressprint)
11083 annotate_field (4);
11084 if (b->loc == NULL || b->loc->shlib_disabled)
11085 ui_out_field_string (uiout, "addr", "<PENDING>");
11087 ui_out_field_core_addr (uiout, "addr",
11088 b->loc->gdbarch, b->loc->address);
11090 annotate_field (5);
11092 *last_loc = b->loc;
11093 if (strstr (b->addr_string, "throw") != NULL)
11094 ui_out_field_string (uiout, "what", "exception throw");
11096 ui_out_field_string (uiout, "what", "exception catch");
11100 print_mention_exception_catchpoint (struct breakpoint *b)
11102 struct ui_out *uiout = current_uiout;
11106 bp_temp = b->disposition == disp_del;
11107 bp_throw = strstr (b->addr_string, "throw") != NULL;
11108 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
11109 : _("Catchpoint "));
11110 ui_out_field_int (uiout, "bkptno", b->number);
11111 ui_out_text (uiout, bp_throw ? _(" (throw)")
11115 /* Implement the "print_recreate" breakpoint_ops method for throw and
11116 catch catchpoints. */
11119 print_recreate_exception_catchpoint (struct breakpoint *b,
11120 struct ui_file *fp)
11125 bp_temp = b->disposition == disp_del;
11126 bp_throw = strstr (b->addr_string, "throw") != NULL;
11127 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
11128 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
11129 print_recreate_thread (b, fp);
11132 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
11135 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
11136 enum exception_event_kind ex_event, int from_tty)
11138 char *trigger_func_name;
11140 if (ex_event == EX_EVENT_CATCH)
11141 trigger_func_name = "__cxa_begin_catch";
11143 trigger_func_name = "__cxa_throw";
11145 create_breakpoint (get_current_arch (),
11146 trigger_func_name, cond_string, -1, NULL,
11147 0 /* condition and thread are valid. */,
11148 tempflag, bp_breakpoint,
11150 AUTO_BOOLEAN_TRUE /* pending */,
11151 &gnu_v3_exception_catchpoint_ops, from_tty,
11159 /* Deal with "catch catch" and "catch throw" commands. */
11162 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
11163 int tempflag, int from_tty)
11165 char *cond_string = NULL;
11169 arg = skip_spaces (arg);
11171 cond_string = ep_parse_optional_if_clause (&arg);
11173 if ((*arg != '\0') && !isspace (*arg))
11174 error (_("Junk at end of arguments."));
11176 if (ex_event != EX_EVENT_THROW
11177 && ex_event != EX_EVENT_CATCH)
11178 error (_("Unsupported or unknown exception event; cannot catch it"));
11180 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
11183 warning (_("Unsupported with this platform/compiler combination."));
11186 /* Implementation of "catch catch" command. */
11189 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
11191 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11193 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
11196 /* Implementation of "catch throw" command. */
11199 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
11201 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11203 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
11207 init_ada_exception_breakpoint (struct breakpoint *b,
11208 struct gdbarch *gdbarch,
11209 struct symtab_and_line sal,
11211 const struct breakpoint_ops *ops,
11217 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11219 loc_gdbarch = gdbarch;
11221 describe_other_breakpoints (loc_gdbarch,
11222 sal.pspace, sal.pc, sal.section, -1);
11223 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11224 version for exception catchpoints, because two catchpoints
11225 used for different exception names will use the same address.
11226 In this case, a "breakpoint ... also set at..." warning is
11227 unproductive. Besides, the warning phrasing is also a bit
11228 inappropriate, we should use the word catchpoint, and tell
11229 the user what type of catchpoint it is. The above is good
11230 enough for now, though. */
11233 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
11235 b->enable_state = bp_enabled;
11236 b->disposition = tempflag ? disp_del : disp_donttouch;
11237 b->addr_string = addr_string;
11238 b->language = language_ada;
11241 /* Splits the argument using space as delimiter. Returns an xmalloc'd
11242 filter list, or NULL if no filtering is required. */
11244 catch_syscall_split_args (char *arg)
11246 VEC(int) *result = NULL;
11247 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
11249 while (*arg != '\0')
11251 int i, syscall_number;
11253 char cur_name[128];
11256 /* Skip whitespace. */
11257 while (isspace (*arg))
11260 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
11261 cur_name[i] = arg[i];
11262 cur_name[i] = '\0';
11265 /* Check if the user provided a syscall name or a number. */
11266 syscall_number = (int) strtol (cur_name, &endptr, 0);
11267 if (*endptr == '\0')
11268 get_syscall_by_number (syscall_number, &s);
11271 /* We have a name. Let's check if it's valid and convert it
11273 get_syscall_by_name (cur_name, &s);
11275 if (s.number == UNKNOWN_SYSCALL)
11276 /* Here we have to issue an error instead of a warning,
11277 because GDB cannot do anything useful if there's no
11278 syscall number to be caught. */
11279 error (_("Unknown syscall name '%s'."), cur_name);
11282 /* Ok, it's valid. */
11283 VEC_safe_push (int, result, s.number);
11286 discard_cleanups (cleanup);
11290 /* Implement the "catch syscall" command. */
11293 catch_syscall_command_1 (char *arg, int from_tty,
11294 struct cmd_list_element *command)
11299 struct gdbarch *gdbarch = get_current_arch ();
11301 /* Checking if the feature if supported. */
11302 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
11303 error (_("The feature 'catch syscall' is not supported on \
11304 this architecture yet."));
11306 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11308 arg = skip_spaces (arg);
11310 /* We need to do this first "dummy" translation in order
11311 to get the syscall XML file loaded or, most important,
11312 to display a warning to the user if there's no XML file
11313 for his/her architecture. */
11314 get_syscall_by_number (0, &s);
11316 /* The allowed syntax is:
11318 catch syscall <name | number> [<name | number> ... <name | number>]
11320 Let's check if there's a syscall name. */
11323 filter = catch_syscall_split_args (arg);
11327 create_syscall_event_catchpoint (tempflag, filter,
11328 &catch_syscall_breakpoint_ops);
11332 catch_command (char *arg, int from_tty)
11334 error (_("Catch requires an event name."));
11339 tcatch_command (char *arg, int from_tty)
11341 error (_("Catch requires an event name."));
11344 /* A qsort comparison function that sorts breakpoints in order. */
11347 compare_breakpoints (const void *a, const void *b)
11349 const breakpoint_p *ba = a;
11350 uintptr_t ua = (uintptr_t) *ba;
11351 const breakpoint_p *bb = b;
11352 uintptr_t ub = (uintptr_t) *bb;
11354 if ((*ba)->number < (*bb)->number)
11356 else if ((*ba)->number > (*bb)->number)
11359 /* Now sort by address, in case we see, e..g, two breakpoints with
11363 return ub > ub ? 1 : 0;
11366 /* Delete breakpoints by address or line. */
11369 clear_command (char *arg, int from_tty)
11371 struct breakpoint *b, *prev;
11372 VEC(breakpoint_p) *found = 0;
11375 struct symtabs_and_lines sals;
11376 struct symtab_and_line sal;
11378 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
11382 sals = decode_line_spec (arg, (DECODE_LINE_FUNFIRSTLINE
11383 | DECODE_LINE_LIST_MODE));
11388 sals.sals = (struct symtab_and_line *)
11389 xmalloc (sizeof (struct symtab_and_line));
11390 make_cleanup (xfree, sals.sals);
11391 init_sal (&sal); /* Initialize to zeroes. */
11393 /* Set sal's line, symtab, pc, and pspace to the values
11394 corresponding to the last call to print_frame_info. If the
11395 codepoint is not valid, this will set all the fields to 0. */
11396 get_last_displayed_sal (&sal);
11397 if (sal.symtab == 0)
11398 error (_("No source file specified."));
11400 sals.sals[0] = sal;
11406 /* We don't call resolve_sal_pc here. That's not as bad as it
11407 seems, because all existing breakpoints typically have both
11408 file/line and pc set. So, if clear is given file/line, we can
11409 match this to existing breakpoint without obtaining pc at all.
11411 We only support clearing given the address explicitly
11412 present in breakpoint table. Say, we've set breakpoint
11413 at file:line. There were several PC values for that file:line,
11414 due to optimization, all in one block.
11416 We've picked one PC value. If "clear" is issued with another
11417 PC corresponding to the same file:line, the breakpoint won't
11418 be cleared. We probably can still clear the breakpoint, but
11419 since the other PC value is never presented to user, user
11420 can only find it by guessing, and it does not seem important
11421 to support that. */
11423 /* For each line spec given, delete bps which correspond to it. Do
11424 it in two passes, solely to preserve the current behavior that
11425 from_tty is forced true if we delete more than one
11429 make_cleanup (VEC_cleanup (breakpoint_p), &found);
11430 for (i = 0; i < sals.nelts; i++)
11432 int is_abs, sal_name_len;
11434 /* If exact pc given, clear bpts at that pc.
11435 If line given (pc == 0), clear all bpts on specified line.
11436 If defaulting, clear all bpts on default line
11439 defaulting sal.pc != 0 tests to do
11444 1 0 <can't happen> */
11446 sal = sals.sals[i];
11447 is_abs = sal.symtab == NULL ? 1 : IS_ABSOLUTE_PATH (sal.symtab->filename);
11448 sal_name_len = is_abs ? 0 : strlen (sal.symtab->filename);
11450 /* Find all matching breakpoints and add them to 'found'. */
11451 ALL_BREAKPOINTS (b)
11454 /* Are we going to delete b? */
11455 if (b->type != bp_none && !is_watchpoint (b))
11457 struct bp_location *loc = b->loc;
11458 for (; loc; loc = loc->next)
11460 /* If the user specified file:line, don't allow a PC
11461 match. This matches historical gdb behavior. */
11462 int pc_match = (!sal.explicit_line
11464 && (loc->pspace == sal.pspace)
11465 && (loc->address == sal.pc)
11466 && (!section_is_overlay (loc->section)
11467 || loc->section == sal.section));
11468 int line_match = 0;
11470 if ((default_match || sal.explicit_line)
11471 && loc->source_file != NULL
11472 && sal.symtab != NULL
11473 && sal.pspace == loc->pspace
11474 && loc->line_number == sal.line)
11476 if (filename_cmp (loc->source_file,
11477 sal.symtab->filename) == 0)
11479 else if (!IS_ABSOLUTE_PATH (sal.symtab->filename)
11480 && compare_filenames_for_search (loc->source_file,
11481 sal.symtab->filename,
11486 if (pc_match || line_match)
11495 VEC_safe_push(breakpoint_p, found, b);
11499 /* Now go thru the 'found' chain and delete them. */
11500 if (VEC_empty(breakpoint_p, found))
11503 error (_("No breakpoint at %s."), arg);
11505 error (_("No breakpoint at this line."));
11508 /* Remove duplicates from the vec. */
11509 qsort (VEC_address (breakpoint_p, found),
11510 VEC_length (breakpoint_p, found),
11511 sizeof (breakpoint_p),
11512 compare_breakpoints);
11513 prev = VEC_index (breakpoint_p, found, 0);
11514 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
11518 VEC_ordered_remove (breakpoint_p, found, ix);
11523 if (VEC_length(breakpoint_p, found) > 1)
11524 from_tty = 1; /* Always report if deleted more than one. */
11527 if (VEC_length(breakpoint_p, found) == 1)
11528 printf_unfiltered (_("Deleted breakpoint "));
11530 printf_unfiltered (_("Deleted breakpoints "));
11532 breakpoints_changed ();
11534 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
11537 printf_unfiltered ("%d ", b->number);
11538 delete_breakpoint (b);
11541 putchar_unfiltered ('\n');
11543 do_cleanups (cleanups);
11546 /* Delete breakpoint in BS if they are `delete' breakpoints and
11547 all breakpoints that are marked for deletion, whether hit or not.
11548 This is called after any breakpoint is hit, or after errors. */
11551 breakpoint_auto_delete (bpstat bs)
11553 struct breakpoint *b, *b_tmp;
11555 for (; bs; bs = bs->next)
11556 if (bs->breakpoint_at
11557 && bs->breakpoint_at->disposition == disp_del
11559 delete_breakpoint (bs->breakpoint_at);
11561 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11563 if (b->disposition == disp_del_at_next_stop)
11564 delete_breakpoint (b);
11568 /* A comparison function for bp_location AP and BP being interfaced to
11569 qsort. Sort elements primarily by their ADDRESS (no matter what
11570 does breakpoint_address_is_meaningful say for its OWNER),
11571 secondarily by ordering first bp_permanent OWNERed elements and
11572 terciarily just ensuring the array is sorted stable way despite
11573 qsort being an unstable algorithm. */
11576 bp_location_compare (const void *ap, const void *bp)
11578 struct bp_location *a = *(void **) ap;
11579 struct bp_location *b = *(void **) bp;
11580 /* A and B come from existing breakpoints having non-NULL OWNER. */
11581 int a_perm = a->owner->enable_state == bp_permanent;
11582 int b_perm = b->owner->enable_state == bp_permanent;
11584 if (a->address != b->address)
11585 return (a->address > b->address) - (a->address < b->address);
11587 /* Sort locations at the same address by their pspace number, keeping
11588 locations of the same inferior (in a multi-inferior environment)
11591 if (a->pspace->num != b->pspace->num)
11592 return ((a->pspace->num > b->pspace->num)
11593 - (a->pspace->num < b->pspace->num));
11595 /* Sort permanent breakpoints first. */
11596 if (a_perm != b_perm)
11597 return (a_perm < b_perm) - (a_perm > b_perm);
11599 /* Make the internal GDB representation stable across GDB runs
11600 where A and B memory inside GDB can differ. Breakpoint locations of
11601 the same type at the same address can be sorted in arbitrary order. */
11603 if (a->owner->number != b->owner->number)
11604 return ((a->owner->number > b->owner->number)
11605 - (a->owner->number < b->owner->number));
11607 return (a > b) - (a < b);
11610 /* Set bp_location_placed_address_before_address_max and
11611 bp_location_shadow_len_after_address_max according to the current
11612 content of the bp_location array. */
11615 bp_location_target_extensions_update (void)
11617 struct bp_location *bl, **blp_tmp;
11619 bp_location_placed_address_before_address_max = 0;
11620 bp_location_shadow_len_after_address_max = 0;
11622 ALL_BP_LOCATIONS (bl, blp_tmp)
11624 CORE_ADDR start, end, addr;
11626 if (!bp_location_has_shadow (bl))
11629 start = bl->target_info.placed_address;
11630 end = start + bl->target_info.shadow_len;
11632 gdb_assert (bl->address >= start);
11633 addr = bl->address - start;
11634 if (addr > bp_location_placed_address_before_address_max)
11635 bp_location_placed_address_before_address_max = addr;
11637 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11639 gdb_assert (bl->address < end);
11640 addr = end - bl->address;
11641 if (addr > bp_location_shadow_len_after_address_max)
11642 bp_location_shadow_len_after_address_max = addr;
11646 /* Download tracepoint locations if they haven't been. */
11649 download_tracepoint_locations (void)
11651 struct bp_location *bl, **blp_tmp;
11652 struct cleanup *old_chain;
11654 if (!target_can_download_tracepoint ())
11657 old_chain = save_current_space_and_thread ();
11659 ALL_BP_LOCATIONS (bl, blp_tmp)
11661 struct tracepoint *t;
11663 if (!is_tracepoint (bl->owner))
11666 if ((bl->owner->type == bp_fast_tracepoint
11667 ? !may_insert_fast_tracepoints
11668 : !may_insert_tracepoints))
11671 /* In tracepoint, locations are _never_ duplicated, so
11672 should_be_inserted is equivalent to
11673 unduplicated_should_be_inserted. */
11674 if (!should_be_inserted (bl) || bl->inserted)
11677 switch_to_program_space_and_thread (bl->pspace);
11679 target_download_tracepoint (bl);
11682 t = (struct tracepoint *) bl->owner;
11683 t->number_on_target = bl->owner->number;
11686 do_cleanups (old_chain);
11689 /* Swap the insertion/duplication state between two locations. */
11692 swap_insertion (struct bp_location *left, struct bp_location *right)
11694 const int left_inserted = left->inserted;
11695 const int left_duplicate = left->duplicate;
11696 const int left_needs_update = left->needs_update;
11697 const struct bp_target_info left_target_info = left->target_info;
11699 /* Locations of tracepoints can never be duplicated. */
11700 if (is_tracepoint (left->owner))
11701 gdb_assert (!left->duplicate);
11702 if (is_tracepoint (right->owner))
11703 gdb_assert (!right->duplicate);
11705 left->inserted = right->inserted;
11706 left->duplicate = right->duplicate;
11707 left->needs_update = right->needs_update;
11708 left->target_info = right->target_info;
11709 right->inserted = left_inserted;
11710 right->duplicate = left_duplicate;
11711 right->needs_update = left_needs_update;
11712 right->target_info = left_target_info;
11715 /* Force the re-insertion of the locations at ADDRESS. This is called
11716 once a new/deleted/modified duplicate location is found and we are evaluating
11717 conditions on the target's side. Such conditions need to be updated on
11721 force_breakpoint_reinsertion (struct bp_location *bl)
11723 struct bp_location **locp = NULL, **loc2p;
11724 struct bp_location *loc;
11725 CORE_ADDR address = 0;
11728 address = bl->address;
11729 pspace_num = bl->pspace->num;
11731 /* This is only meaningful if the target is
11732 evaluating conditions and if the user has
11733 opted for condition evaluation on the target's
11735 if (gdb_evaluates_breakpoint_condition_p ()
11736 || !target_supports_evaluation_of_breakpoint_conditions ())
11739 /* Flag all breakpoint locations with this address and
11740 the same program space as the location
11741 as "its condition has changed". We need to
11742 update the conditions on the target's side. */
11743 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
11747 if (!is_breakpoint (loc->owner)
11748 || pspace_num != loc->pspace->num)
11751 /* Flag the location appropriately. We use a different state to
11752 let everyone know that we already updated the set of locations
11753 with addr bl->address and program space bl->pspace. This is so
11754 we don't have to keep calling these functions just to mark locations
11755 that have already been marked. */
11756 loc->condition_changed = condition_updated;
11758 /* Free the agent expression bytecode as well. We will compute
11760 if (loc->cond_bytecode)
11762 free_agent_expr (loc->cond_bytecode);
11763 loc->cond_bytecode = NULL;
11768 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
11769 into the inferior, only remove already-inserted locations that no
11770 longer should be inserted. Functions that delete a breakpoint or
11771 breakpoints should pass false, so that deleting a breakpoint
11772 doesn't have the side effect of inserting the locations of other
11773 breakpoints that are marked not-inserted, but should_be_inserted
11774 returns true on them.
11776 This behaviour is useful is situations close to tear-down -- e.g.,
11777 after an exec, while the target still has execution, but breakpoint
11778 shadows of the previous executable image should *NOT* be restored
11779 to the new image; or before detaching, where the target still has
11780 execution and wants to delete breakpoints from GDB's lists, and all
11781 breakpoints had already been removed from the inferior. */
11784 update_global_location_list (int should_insert)
11786 struct breakpoint *b;
11787 struct bp_location **locp, *loc;
11788 struct cleanup *cleanups;
11789 /* Last breakpoint location address that was marked for update. */
11790 CORE_ADDR last_addr = 0;
11791 /* Last breakpoint location program space that was marked for update. */
11792 int last_pspace_num = -1;
11794 /* Used in the duplicates detection below. When iterating over all
11795 bp_locations, points to the first bp_location of a given address.
11796 Breakpoints and watchpoints of different types are never
11797 duplicates of each other. Keep one pointer for each type of
11798 breakpoint/watchpoint, so we only need to loop over all locations
11800 struct bp_location *bp_loc_first; /* breakpoint */
11801 struct bp_location *wp_loc_first; /* hardware watchpoint */
11802 struct bp_location *awp_loc_first; /* access watchpoint */
11803 struct bp_location *rwp_loc_first; /* read watchpoint */
11805 /* Saved former bp_location array which we compare against the newly
11806 built bp_location from the current state of ALL_BREAKPOINTS. */
11807 struct bp_location **old_location, **old_locp;
11808 unsigned old_location_count;
11810 old_location = bp_location;
11811 old_location_count = bp_location_count;
11812 bp_location = NULL;
11813 bp_location_count = 0;
11814 cleanups = make_cleanup (xfree, old_location);
11816 ALL_BREAKPOINTS (b)
11817 for (loc = b->loc; loc; loc = loc->next)
11818 bp_location_count++;
11820 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
11821 locp = bp_location;
11822 ALL_BREAKPOINTS (b)
11823 for (loc = b->loc; loc; loc = loc->next)
11825 qsort (bp_location, bp_location_count, sizeof (*bp_location),
11826 bp_location_compare);
11828 bp_location_target_extensions_update ();
11830 /* Identify bp_location instances that are no longer present in the
11831 new list, and therefore should be freed. Note that it's not
11832 necessary that those locations should be removed from inferior --
11833 if there's another location at the same address (previously
11834 marked as duplicate), we don't need to remove/insert the
11837 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11838 and former bp_location array state respectively. */
11840 locp = bp_location;
11841 for (old_locp = old_location; old_locp < old_location + old_location_count;
11844 struct bp_location *old_loc = *old_locp;
11845 struct bp_location **loc2p;
11847 /* Tells if 'old_loc' is found among the new locations. If
11848 not, we have to free it. */
11849 int found_object = 0;
11850 /* Tells if the location should remain inserted in the target. */
11851 int keep_in_target = 0;
11854 /* Skip LOCP entries which will definitely never be needed.
11855 Stop either at or being the one matching OLD_LOC. */
11856 while (locp < bp_location + bp_location_count
11857 && (*locp)->address < old_loc->address)
11861 (loc2p < bp_location + bp_location_count
11862 && (*loc2p)->address == old_loc->address);
11865 /* Check if this is a new/duplicated location or a duplicated
11866 location that had its condition modified. If so, we want to send
11867 its condition to the target if evaluation of conditions is taking
11869 if ((*loc2p)->condition_changed == condition_modified
11870 && (last_addr != old_loc->address
11871 || last_pspace_num != old_loc->pspace->num))
11873 force_breakpoint_reinsertion (*loc2p);
11874 last_pspace_num = old_loc->pspace->num;
11877 if (*loc2p == old_loc)
11881 /* We have already handled this address, update it so that we don't
11882 have to go through updates again. */
11883 last_addr = old_loc->address;
11885 /* Target-side condition evaluation: Handle deleted locations. */
11887 force_breakpoint_reinsertion (old_loc);
11889 /* If this location is no longer present, and inserted, look if
11890 there's maybe a new location at the same address. If so,
11891 mark that one inserted, and don't remove this one. This is
11892 needed so that we don't have a time window where a breakpoint
11893 at certain location is not inserted. */
11895 if (old_loc->inserted)
11897 /* If the location is inserted now, we might have to remove
11900 if (found_object && should_be_inserted (old_loc))
11902 /* The location is still present in the location list,
11903 and still should be inserted. Don't do anything. */
11904 keep_in_target = 1;
11908 /* This location still exists, but it won't be kept in the
11909 target since it may have been disabled. We proceed to
11910 remove its target-side condition. */
11912 /* The location is either no longer present, or got
11913 disabled. See if there's another location at the
11914 same address, in which case we don't need to remove
11915 this one from the target. */
11917 /* OLD_LOC comes from existing struct breakpoint. */
11918 if (breakpoint_address_is_meaningful (old_loc->owner))
11921 (loc2p < bp_location + bp_location_count
11922 && (*loc2p)->address == old_loc->address);
11925 struct bp_location *loc2 = *loc2p;
11927 if (breakpoint_locations_match (loc2, old_loc))
11929 /* Read watchpoint locations are switched to
11930 access watchpoints, if the former are not
11931 supported, but the latter are. */
11932 if (is_hardware_watchpoint (old_loc->owner))
11934 gdb_assert (is_hardware_watchpoint (loc2->owner));
11935 loc2->watchpoint_type = old_loc->watchpoint_type;
11938 /* loc2 is a duplicated location. We need to check
11939 if it should be inserted in case it will be
11941 if (loc2 != old_loc
11942 && unduplicated_should_be_inserted (loc2))
11944 swap_insertion (old_loc, loc2);
11945 keep_in_target = 1;
11953 if (!keep_in_target)
11955 if (remove_breakpoint (old_loc, mark_uninserted))
11957 /* This is just about all we can do. We could keep
11958 this location on the global list, and try to
11959 remove it next time, but there's no particular
11960 reason why we will succeed next time.
11962 Note that at this point, old_loc->owner is still
11963 valid, as delete_breakpoint frees the breakpoint
11964 only after calling us. */
11965 printf_filtered (_("warning: Error removing "
11966 "breakpoint %d\n"),
11967 old_loc->owner->number);
11975 if (removed && non_stop
11976 && breakpoint_address_is_meaningful (old_loc->owner)
11977 && !is_hardware_watchpoint (old_loc->owner))
11979 /* This location was removed from the target. In
11980 non-stop mode, a race condition is possible where
11981 we've removed a breakpoint, but stop events for that
11982 breakpoint are already queued and will arrive later.
11983 We apply an heuristic to be able to distinguish such
11984 SIGTRAPs from other random SIGTRAPs: we keep this
11985 breakpoint location for a bit, and will retire it
11986 after we see some number of events. The theory here
11987 is that reporting of events should, "on the average",
11988 be fair, so after a while we'll see events from all
11989 threads that have anything of interest, and no longer
11990 need to keep this breakpoint location around. We
11991 don't hold locations forever so to reduce chances of
11992 mistaking a non-breakpoint SIGTRAP for a breakpoint
11995 The heuristic failing can be disastrous on
11996 decr_pc_after_break targets.
11998 On decr_pc_after_break targets, like e.g., x86-linux,
11999 if we fail to recognize a late breakpoint SIGTRAP,
12000 because events_till_retirement has reached 0 too
12001 soon, we'll fail to do the PC adjustment, and report
12002 a random SIGTRAP to the user. When the user resumes
12003 the inferior, it will most likely immediately crash
12004 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12005 corrupted, because of being resumed e.g., in the
12006 middle of a multi-byte instruction, or skipped a
12007 one-byte instruction. This was actually seen happen
12008 on native x86-linux, and should be less rare on
12009 targets that do not support new thread events, like
12010 remote, due to the heuristic depending on
12013 Mistaking a random SIGTRAP for a breakpoint trap
12014 causes similar symptoms (PC adjustment applied when
12015 it shouldn't), but then again, playing with SIGTRAPs
12016 behind the debugger's back is asking for trouble.
12018 Since hardware watchpoint traps are always
12019 distinguishable from other traps, so we don't need to
12020 apply keep hardware watchpoint moribund locations
12021 around. We simply always ignore hardware watchpoint
12022 traps we can no longer explain. */
12024 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12025 old_loc->owner = NULL;
12027 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12031 old_loc->owner = NULL;
12032 decref_bp_location (&old_loc);
12037 /* Rescan breakpoints at the same address and section, marking the
12038 first one as "first" and any others as "duplicates". This is so
12039 that the bpt instruction is only inserted once. If we have a
12040 permanent breakpoint at the same place as BPT, make that one the
12041 official one, and the rest as duplicates. Permanent breakpoints
12042 are sorted first for the same address.
12044 Do the same for hardware watchpoints, but also considering the
12045 watchpoint's type (regular/access/read) and length. */
12047 bp_loc_first = NULL;
12048 wp_loc_first = NULL;
12049 awp_loc_first = NULL;
12050 rwp_loc_first = NULL;
12051 ALL_BP_LOCATIONS (loc, locp)
12053 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12055 struct bp_location **loc_first_p;
12058 if (!should_be_inserted (loc)
12059 || !breakpoint_address_is_meaningful (b)
12060 /* Don't detect duplicate for tracepoint locations because they are
12061 never duplicated. See the comments in field `duplicate' of
12062 `struct bp_location'. */
12063 || is_tracepoint (b))
12065 /* Clear the condition modification flag. */
12066 loc->condition_changed = condition_unchanged;
12070 /* Permanent breakpoint should always be inserted. */
12071 if (b->enable_state == bp_permanent && ! loc->inserted)
12072 internal_error (__FILE__, __LINE__,
12073 _("allegedly permanent breakpoint is not "
12074 "actually inserted"));
12076 if (b->type == bp_hardware_watchpoint)
12077 loc_first_p = &wp_loc_first;
12078 else if (b->type == bp_read_watchpoint)
12079 loc_first_p = &rwp_loc_first;
12080 else if (b->type == bp_access_watchpoint)
12081 loc_first_p = &awp_loc_first;
12083 loc_first_p = &bp_loc_first;
12085 if (*loc_first_p == NULL
12086 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12087 || !breakpoint_locations_match (loc, *loc_first_p))
12089 *loc_first_p = loc;
12090 loc->duplicate = 0;
12092 if (is_breakpoint (loc->owner) && loc->condition_changed)
12094 loc->needs_update = 1;
12095 /* Clear the condition modification flag. */
12096 loc->condition_changed = condition_unchanged;
12102 /* This and the above ensure the invariant that the first location
12103 is not duplicated, and is the inserted one.
12104 All following are marked as duplicated, and are not inserted. */
12106 swap_insertion (loc, *loc_first_p);
12107 loc->duplicate = 1;
12109 /* Clear the condition modification flag. */
12110 loc->condition_changed = condition_unchanged;
12112 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
12113 && b->enable_state != bp_permanent)
12114 internal_error (__FILE__, __LINE__,
12115 _("another breakpoint was inserted on top of "
12116 "a permanent breakpoint"));
12119 if (breakpoints_always_inserted_mode ()
12120 && (have_live_inferiors ()
12121 || (gdbarch_has_global_breakpoints (target_gdbarch))))
12124 insert_breakpoint_locations ();
12127 /* Though should_insert is false, we may need to update conditions
12128 on the target's side if it is evaluating such conditions. We
12129 only update conditions for locations that are marked
12131 update_inserted_breakpoint_locations ();
12136 download_tracepoint_locations ();
12138 do_cleanups (cleanups);
12142 breakpoint_retire_moribund (void)
12144 struct bp_location *loc;
12147 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12148 if (--(loc->events_till_retirement) == 0)
12150 decref_bp_location (&loc);
12151 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12157 update_global_location_list_nothrow (int inserting)
12159 volatile struct gdb_exception e;
12161 TRY_CATCH (e, RETURN_MASK_ERROR)
12162 update_global_location_list (inserting);
12165 /* Clear BKP from a BPS. */
12168 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12172 for (bs = bps; bs; bs = bs->next)
12173 if (bs->breakpoint_at == bpt)
12175 bs->breakpoint_at = NULL;
12176 bs->old_val = NULL;
12177 /* bs->commands will be freed later. */
12181 /* Callback for iterate_over_threads. */
12183 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12185 struct breakpoint *bpt = data;
12187 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12191 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12195 say_where (struct breakpoint *b)
12197 struct ui_out *uiout = current_uiout;
12198 struct value_print_options opts;
12200 get_user_print_options (&opts);
12202 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12204 if (b->loc == NULL)
12206 printf_filtered (_(" (%s) pending."), b->addr_string);
12210 if (opts.addressprint || b->loc->source_file == NULL)
12212 printf_filtered (" at ");
12213 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
12216 if (b->loc->source_file)
12218 /* If there is a single location, we can print the location
12220 if (b->loc->next == NULL)
12221 printf_filtered (": file %s, line %d.",
12222 b->loc->source_file, b->loc->line_number);
12224 /* This is not ideal, but each location may have a
12225 different file name, and this at least reflects the
12226 real situation somewhat. */
12227 printf_filtered (": %s.", b->addr_string);
12232 struct bp_location *loc = b->loc;
12234 for (; loc; loc = loc->next)
12236 printf_filtered (" (%d locations)", n);
12241 /* Default bp_location_ops methods. */
12244 bp_location_dtor (struct bp_location *self)
12246 xfree (self->cond);
12247 if (self->cond_bytecode)
12248 free_agent_expr (self->cond_bytecode);
12249 xfree (self->function_name);
12250 xfree (self->source_file);
12253 static const struct bp_location_ops bp_location_ops =
12258 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12262 base_breakpoint_dtor (struct breakpoint *self)
12264 decref_counted_command_line (&self->commands);
12265 xfree (self->cond_string);
12266 xfree (self->addr_string);
12267 xfree (self->filter);
12268 xfree (self->addr_string_range_end);
12271 static struct bp_location *
12272 base_breakpoint_allocate_location (struct breakpoint *self)
12274 struct bp_location *loc;
12276 loc = XNEW (struct bp_location);
12277 init_bp_location (loc, &bp_location_ops, self);
12282 base_breakpoint_re_set (struct breakpoint *b)
12284 /* Nothing to re-set. */
12287 #define internal_error_pure_virtual_called() \
12288 gdb_assert_not_reached ("pure virtual function called")
12291 base_breakpoint_insert_location (struct bp_location *bl)
12293 internal_error_pure_virtual_called ();
12297 base_breakpoint_remove_location (struct bp_location *bl)
12299 internal_error_pure_virtual_called ();
12303 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12304 struct address_space *aspace,
12306 const struct target_waitstatus *ws)
12308 internal_error_pure_virtual_called ();
12312 base_breakpoint_check_status (bpstat bs)
12317 /* A "works_in_software_mode" breakpoint_ops method that just internal
12321 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
12323 internal_error_pure_virtual_called ();
12326 /* A "resources_needed" breakpoint_ops method that just internal
12330 base_breakpoint_resources_needed (const struct bp_location *bl)
12332 internal_error_pure_virtual_called ();
12335 static enum print_stop_action
12336 base_breakpoint_print_it (bpstat bs)
12338 internal_error_pure_virtual_called ();
12342 base_breakpoint_print_one_detail (const struct breakpoint *self,
12343 struct ui_out *uiout)
12349 base_breakpoint_print_mention (struct breakpoint *b)
12351 internal_error_pure_virtual_called ();
12355 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
12357 internal_error_pure_virtual_called ();
12361 base_breakpoint_create_sals_from_address (char **arg,
12362 struct linespec_result *canonical,
12363 enum bptype type_wanted,
12367 internal_error_pure_virtual_called ();
12371 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12372 struct linespec_result *c,
12373 struct linespec_sals *lsal,
12375 char *extra_string,
12376 enum bptype type_wanted,
12377 enum bpdisp disposition,
12379 int task, int ignore_count,
12380 const struct breakpoint_ops *o,
12381 int from_tty, int enabled,
12382 int internal, unsigned flags)
12384 internal_error_pure_virtual_called ();
12388 base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
12389 struct symtabs_and_lines *sals)
12391 internal_error_pure_virtual_called ();
12394 static struct breakpoint_ops base_breakpoint_ops =
12396 base_breakpoint_dtor,
12397 base_breakpoint_allocate_location,
12398 base_breakpoint_re_set,
12399 base_breakpoint_insert_location,
12400 base_breakpoint_remove_location,
12401 base_breakpoint_breakpoint_hit,
12402 base_breakpoint_check_status,
12403 base_breakpoint_resources_needed,
12404 base_breakpoint_works_in_software_mode,
12405 base_breakpoint_print_it,
12407 base_breakpoint_print_one_detail,
12408 base_breakpoint_print_mention,
12409 base_breakpoint_print_recreate,
12410 base_breakpoint_create_sals_from_address,
12411 base_breakpoint_create_breakpoints_sal,
12412 base_breakpoint_decode_linespec,
12415 /* Default breakpoint_ops methods. */
12418 bkpt_re_set (struct breakpoint *b)
12420 /* FIXME: is this still reachable? */
12421 if (b->addr_string == NULL)
12423 /* Anything without a string can't be re-set. */
12424 delete_breakpoint (b);
12428 breakpoint_re_set_default (b);
12432 bkpt_insert_location (struct bp_location *bl)
12434 if (bl->loc_type == bp_loc_hardware_breakpoint)
12435 return target_insert_hw_breakpoint (bl->gdbarch,
12438 return target_insert_breakpoint (bl->gdbarch,
12443 bkpt_remove_location (struct bp_location *bl)
12445 if (bl->loc_type == bp_loc_hardware_breakpoint)
12446 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
12448 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
12452 bkpt_breakpoint_hit (const struct bp_location *bl,
12453 struct address_space *aspace, CORE_ADDR bp_addr,
12454 const struct target_waitstatus *ws)
12456 struct breakpoint *b = bl->owner;
12458 if (ws->kind != TARGET_WAITKIND_STOPPED
12459 || ws->value.sig != TARGET_SIGNAL_TRAP)
12462 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
12466 if (overlay_debugging /* unmapped overlay section */
12467 && section_is_overlay (bl->section)
12468 && !section_is_mapped (bl->section))
12475 bkpt_resources_needed (const struct bp_location *bl)
12477 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
12482 static enum print_stop_action
12483 bkpt_print_it (bpstat bs)
12485 struct breakpoint *b;
12486 const struct bp_location *bl;
12488 struct ui_out *uiout = current_uiout;
12490 gdb_assert (bs->bp_location_at != NULL);
12492 bl = bs->bp_location_at;
12493 b = bs->breakpoint_at;
12495 bp_temp = b->disposition == disp_del;
12496 if (bl->address != bl->requested_address)
12497 breakpoint_adjustment_warning (bl->requested_address,
12500 annotate_breakpoint (b->number);
12502 ui_out_text (uiout, "\nTemporary breakpoint ");
12504 ui_out_text (uiout, "\nBreakpoint ");
12505 if (ui_out_is_mi_like_p (uiout))
12507 ui_out_field_string (uiout, "reason",
12508 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
12509 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
12511 ui_out_field_int (uiout, "bkptno", b->number);
12512 ui_out_text (uiout, ", ");
12514 return PRINT_SRC_AND_LOC;
12518 bkpt_print_mention (struct breakpoint *b)
12520 if (ui_out_is_mi_like_p (current_uiout))
12525 case bp_breakpoint:
12526 case bp_gnu_ifunc_resolver:
12527 if (b->disposition == disp_del)
12528 printf_filtered (_("Temporary breakpoint"));
12530 printf_filtered (_("Breakpoint"));
12531 printf_filtered (_(" %d"), b->number);
12532 if (b->type == bp_gnu_ifunc_resolver)
12533 printf_filtered (_(" at gnu-indirect-function resolver"));
12535 case bp_hardware_breakpoint:
12536 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
12539 printf_filtered (_("Dprintf %d"), b->number);
12547 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
12549 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
12550 fprintf_unfiltered (fp, "tbreak");
12551 else if (tp->type == bp_breakpoint)
12552 fprintf_unfiltered (fp, "break");
12553 else if (tp->type == bp_hardware_breakpoint
12554 && tp->disposition == disp_del)
12555 fprintf_unfiltered (fp, "thbreak");
12556 else if (tp->type == bp_hardware_breakpoint)
12557 fprintf_unfiltered (fp, "hbreak");
12559 internal_error (__FILE__, __LINE__,
12560 _("unhandled breakpoint type %d"), (int) tp->type);
12562 fprintf_unfiltered (fp, " %s", tp->addr_string);
12563 print_recreate_thread (tp, fp);
12567 bkpt_create_sals_from_address (char **arg,
12568 struct linespec_result *canonical,
12569 enum bptype type_wanted,
12570 char *addr_start, char **copy_arg)
12572 create_sals_from_address_default (arg, canonical, type_wanted,
12573 addr_start, copy_arg);
12577 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
12578 struct linespec_result *canonical,
12579 struct linespec_sals *lsal,
12581 char *extra_string,
12582 enum bptype type_wanted,
12583 enum bpdisp disposition,
12585 int task, int ignore_count,
12586 const struct breakpoint_ops *ops,
12587 int from_tty, int enabled,
12588 int internal, unsigned flags)
12590 create_breakpoints_sal_default (gdbarch, canonical, lsal,
12591 cond_string, extra_string,
12593 disposition, thread, task,
12594 ignore_count, ops, from_tty,
12595 enabled, internal, flags);
12599 bkpt_decode_linespec (struct breakpoint *b, char **s,
12600 struct symtabs_and_lines *sals)
12602 decode_linespec_default (b, s, sals);
12605 /* Virtual table for internal breakpoints. */
12608 internal_bkpt_re_set (struct breakpoint *b)
12612 /* Delete overlay event and longjmp master breakpoints; they
12613 will be reset later by breakpoint_re_set. */
12614 case bp_overlay_event:
12615 case bp_longjmp_master:
12616 case bp_std_terminate_master:
12617 case bp_exception_master:
12618 delete_breakpoint (b);
12621 /* This breakpoint is special, it's set up when the inferior
12622 starts and we really don't want to touch it. */
12623 case bp_shlib_event:
12625 /* Like bp_shlib_event, this breakpoint type is special. Once
12626 it is set up, we do not want to touch it. */
12627 case bp_thread_event:
12633 internal_bkpt_check_status (bpstat bs)
12635 if (bs->breakpoint_at->type == bp_shlib_event)
12637 /* If requested, stop when the dynamic linker notifies GDB of
12638 events. This allows the user to get control and place
12639 breakpoints in initializer routines for dynamically loaded
12640 objects (among other things). */
12641 bs->stop = stop_on_solib_events;
12642 bs->print = stop_on_solib_events;
12648 static enum print_stop_action
12649 internal_bkpt_print_it (bpstat bs)
12651 struct ui_out *uiout = current_uiout;
12652 struct breakpoint *b;
12654 b = bs->breakpoint_at;
12658 case bp_shlib_event:
12659 /* Did we stop because the user set the stop_on_solib_events
12660 variable? (If so, we report this as a generic, "Stopped due
12661 to shlib event" message.) */
12662 print_solib_event (0);
12665 case bp_thread_event:
12666 /* Not sure how we will get here.
12667 GDB should not stop for these breakpoints. */
12668 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12671 case bp_overlay_event:
12672 /* By analogy with the thread event, GDB should not stop for these. */
12673 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12676 case bp_longjmp_master:
12677 /* These should never be enabled. */
12678 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12681 case bp_std_terminate_master:
12682 /* These should never be enabled. */
12683 printf_filtered (_("std::terminate Master Breakpoint: "
12684 "gdb should not stop!\n"));
12687 case bp_exception_master:
12688 /* These should never be enabled. */
12689 printf_filtered (_("Exception Master Breakpoint: "
12690 "gdb should not stop!\n"));
12694 return PRINT_NOTHING;
12698 internal_bkpt_print_mention (struct breakpoint *b)
12700 /* Nothing to mention. These breakpoints are internal. */
12703 /* Virtual table for momentary breakpoints */
12706 momentary_bkpt_re_set (struct breakpoint *b)
12708 /* Keep temporary breakpoints, which can be encountered when we step
12709 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
12710 Otherwise these should have been blown away via the cleanup chain
12711 or by breakpoint_init_inferior when we rerun the executable. */
12715 momentary_bkpt_check_status (bpstat bs)
12717 /* Nothing. The point of these breakpoints is causing a stop. */
12720 static enum print_stop_action
12721 momentary_bkpt_print_it (bpstat bs)
12723 struct ui_out *uiout = current_uiout;
12725 if (ui_out_is_mi_like_p (uiout))
12727 struct breakpoint *b = bs->breakpoint_at;
12732 ui_out_field_string
12734 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
12738 ui_out_field_string
12740 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
12745 return PRINT_UNKNOWN;
12749 momentary_bkpt_print_mention (struct breakpoint *b)
12751 /* Nothing to mention. These breakpoints are internal. */
12754 /* Specific methods for probe breakpoints. */
12757 bkpt_probe_insert_location (struct bp_location *bl)
12759 int v = bkpt_insert_location (bl);
12763 /* The insertion was successful, now let's set the probe's semaphore
12765 bl->probe->pops->set_semaphore (bl->probe, bl->gdbarch);
12772 bkpt_probe_remove_location (struct bp_location *bl)
12774 /* Let's clear the semaphore before removing the location. */
12775 bl->probe->pops->clear_semaphore (bl->probe, bl->gdbarch);
12777 return bkpt_remove_location (bl);
12781 bkpt_probe_create_sals_from_address (char **arg,
12782 struct linespec_result *canonical,
12783 enum bptype type_wanted,
12784 char *addr_start, char **copy_arg)
12786 struct linespec_sals lsal;
12788 lsal.sals = parse_probes (arg, canonical);
12790 *copy_arg = xstrdup (canonical->addr_string);
12791 lsal.canonical = xstrdup (*copy_arg);
12793 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
12797 bkpt_probe_decode_linespec (struct breakpoint *b, char **s,
12798 struct symtabs_and_lines *sals)
12800 *sals = parse_probes (s, NULL);
12802 error (_("probe not found"));
12805 /* The breakpoint_ops structure to be used in tracepoints. */
12808 tracepoint_re_set (struct breakpoint *b)
12810 breakpoint_re_set_default (b);
12814 tracepoint_breakpoint_hit (const struct bp_location *bl,
12815 struct address_space *aspace, CORE_ADDR bp_addr,
12816 const struct target_waitstatus *ws)
12818 /* By definition, the inferior does not report stops at
12824 tracepoint_print_one_detail (const struct breakpoint *self,
12825 struct ui_out *uiout)
12827 struct tracepoint *tp = (struct tracepoint *) self;
12828 if (tp->static_trace_marker_id)
12830 gdb_assert (self->type == bp_static_tracepoint);
12832 ui_out_text (uiout, "\tmarker id is ");
12833 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
12834 tp->static_trace_marker_id);
12835 ui_out_text (uiout, "\n");
12840 tracepoint_print_mention (struct breakpoint *b)
12842 if (ui_out_is_mi_like_p (current_uiout))
12847 case bp_tracepoint:
12848 printf_filtered (_("Tracepoint"));
12849 printf_filtered (_(" %d"), b->number);
12851 case bp_fast_tracepoint:
12852 printf_filtered (_("Fast tracepoint"));
12853 printf_filtered (_(" %d"), b->number);
12855 case bp_static_tracepoint:
12856 printf_filtered (_("Static tracepoint"));
12857 printf_filtered (_(" %d"), b->number);
12860 internal_error (__FILE__, __LINE__,
12861 _("unhandled tracepoint type %d"), (int) b->type);
12868 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
12870 struct tracepoint *tp = (struct tracepoint *) self;
12872 if (self->type == bp_fast_tracepoint)
12873 fprintf_unfiltered (fp, "ftrace");
12874 if (self->type == bp_static_tracepoint)
12875 fprintf_unfiltered (fp, "strace");
12876 else if (self->type == bp_tracepoint)
12877 fprintf_unfiltered (fp, "trace");
12879 internal_error (__FILE__, __LINE__,
12880 _("unhandled tracepoint type %d"), (int) self->type);
12882 fprintf_unfiltered (fp, " %s", self->addr_string);
12883 print_recreate_thread (self, fp);
12885 if (tp->pass_count)
12886 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
12890 tracepoint_create_sals_from_address (char **arg,
12891 struct linespec_result *canonical,
12892 enum bptype type_wanted,
12893 char *addr_start, char **copy_arg)
12895 create_sals_from_address_default (arg, canonical, type_wanted,
12896 addr_start, copy_arg);
12900 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12901 struct linespec_result *canonical,
12902 struct linespec_sals *lsal,
12904 char *extra_string,
12905 enum bptype type_wanted,
12906 enum bpdisp disposition,
12908 int task, int ignore_count,
12909 const struct breakpoint_ops *ops,
12910 int from_tty, int enabled,
12911 int internal, unsigned flags)
12913 create_breakpoints_sal_default (gdbarch, canonical, lsal,
12914 cond_string, extra_string,
12916 disposition, thread, task,
12917 ignore_count, ops, from_tty,
12918 enabled, internal, flags);
12922 tracepoint_decode_linespec (struct breakpoint *b, char **s,
12923 struct symtabs_and_lines *sals)
12925 decode_linespec_default (b, s, sals);
12928 struct breakpoint_ops tracepoint_breakpoint_ops;
12930 /* The breakpoint_ops structure to be use on tracepoints placed in a
12934 tracepoint_probe_create_sals_from_address (char **arg,
12935 struct linespec_result *canonical,
12936 enum bptype type_wanted,
12937 char *addr_start, char **copy_arg)
12939 /* We use the same method for breakpoint on probes. */
12940 bkpt_probe_create_sals_from_address (arg, canonical, type_wanted,
12941 addr_start, copy_arg);
12945 tracepoint_probe_decode_linespec (struct breakpoint *b, char **s,
12946 struct symtabs_and_lines *sals)
12948 /* We use the same method for breakpoint on probes. */
12949 bkpt_probe_decode_linespec (b, s, sals);
12952 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
12954 /* The breakpoint_ops structure to be used on static tracepoints with
12958 strace_marker_create_sals_from_address (char **arg,
12959 struct linespec_result *canonical,
12960 enum bptype type_wanted,
12961 char *addr_start, char **copy_arg)
12963 struct linespec_sals lsal;
12965 lsal.sals = decode_static_tracepoint_spec (arg);
12967 *copy_arg = savestring (addr_start, *arg - addr_start);
12969 canonical->addr_string = xstrdup (*copy_arg);
12970 lsal.canonical = xstrdup (*copy_arg);
12971 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
12975 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
12976 struct linespec_result *canonical,
12977 struct linespec_sals *lsal,
12979 char *extra_string,
12980 enum bptype type_wanted,
12981 enum bpdisp disposition,
12983 int task, int ignore_count,
12984 const struct breakpoint_ops *ops,
12985 int from_tty, int enabled,
12986 int internal, unsigned flags)
12990 /* If the user is creating a static tracepoint by marker id
12991 (strace -m MARKER_ID), then store the sals index, so that
12992 breakpoint_re_set can try to match up which of the newly
12993 found markers corresponds to this one, and, don't try to
12994 expand multiple locations for each sal, given than SALS
12995 already should contain all sals for MARKER_ID. */
12997 for (i = 0; i < lsal->sals.nelts; ++i)
12999 struct symtabs_and_lines expanded;
13000 struct tracepoint *tp;
13001 struct cleanup *old_chain;
13004 expanded.nelts = 1;
13005 expanded.sals = &lsal->sals.sals[i];
13007 addr_string = xstrdup (canonical->addr_string);
13008 old_chain = make_cleanup (xfree, addr_string);
13010 tp = XCNEW (struct tracepoint);
13011 init_breakpoint_sal (&tp->base, gdbarch, expanded,
13013 cond_string, extra_string,
13014 type_wanted, disposition,
13015 thread, task, ignore_count, ops,
13016 from_tty, enabled, internal, flags,
13017 canonical->special_display);
13018 /* Given that its possible to have multiple markers with
13019 the same string id, if the user is creating a static
13020 tracepoint by marker id ("strace -m MARKER_ID"), then
13021 store the sals index, so that breakpoint_re_set can
13022 try to match up which of the newly found markers
13023 corresponds to this one */
13024 tp->static_trace_marker_id_idx = i;
13026 install_breakpoint (internal, &tp->base, 0);
13028 discard_cleanups (old_chain);
13033 strace_marker_decode_linespec (struct breakpoint *b, char **s,
13034 struct symtabs_and_lines *sals)
13036 struct tracepoint *tp = (struct tracepoint *) b;
13038 *sals = decode_static_tracepoint_spec (s);
13039 if (sals->nelts > tp->static_trace_marker_id_idx)
13041 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
13045 error (_("marker %s not found"), tp->static_trace_marker_id);
13048 static struct breakpoint_ops strace_marker_breakpoint_ops;
13051 strace_marker_p (struct breakpoint *b)
13053 return b->ops == &strace_marker_breakpoint_ops;
13056 /* Delete a breakpoint and clean up all traces of it in the data
13060 delete_breakpoint (struct breakpoint *bpt)
13062 struct breakpoint *b;
13064 gdb_assert (bpt != NULL);
13066 /* Has this bp already been deleted? This can happen because
13067 multiple lists can hold pointers to bp's. bpstat lists are
13070 One example of this happening is a watchpoint's scope bp. When
13071 the scope bp triggers, we notice that the watchpoint is out of
13072 scope, and delete it. We also delete its scope bp. But the
13073 scope bp is marked "auto-deleting", and is already on a bpstat.
13074 That bpstat is then checked for auto-deleting bp's, which are
13077 A real solution to this problem might involve reference counts in
13078 bp's, and/or giving them pointers back to their referencing
13079 bpstat's, and teaching delete_breakpoint to only free a bp's
13080 storage when no more references were extent. A cheaper bandaid
13082 if (bpt->type == bp_none)
13085 /* At least avoid this stale reference until the reference counting
13086 of breakpoints gets resolved. */
13087 if (bpt->related_breakpoint != bpt)
13089 struct breakpoint *related;
13090 struct watchpoint *w;
13092 if (bpt->type == bp_watchpoint_scope)
13093 w = (struct watchpoint *) bpt->related_breakpoint;
13094 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
13095 w = (struct watchpoint *) bpt;
13099 watchpoint_del_at_next_stop (w);
13101 /* Unlink bpt from the bpt->related_breakpoint ring. */
13102 for (related = bpt; related->related_breakpoint != bpt;
13103 related = related->related_breakpoint);
13104 related->related_breakpoint = bpt->related_breakpoint;
13105 bpt->related_breakpoint = bpt;
13108 /* watch_command_1 creates a watchpoint but only sets its number if
13109 update_watchpoint succeeds in creating its bp_locations. If there's
13110 a problem in that process, we'll be asked to delete the half-created
13111 watchpoint. In that case, don't announce the deletion. */
13113 observer_notify_breakpoint_deleted (bpt);
13115 if (breakpoint_chain == bpt)
13116 breakpoint_chain = bpt->next;
13118 ALL_BREAKPOINTS (b)
13119 if (b->next == bpt)
13121 b->next = bpt->next;
13125 /* Be sure no bpstat's are pointing at the breakpoint after it's
13127 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13128 in all threads for now. Note that we cannot just remove bpstats
13129 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13130 commands are associated with the bpstat; if we remove it here,
13131 then the later call to bpstat_do_actions (&stop_bpstat); in
13132 event-top.c won't do anything, and temporary breakpoints with
13133 commands won't work. */
13135 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13137 /* Now that breakpoint is removed from breakpoint list, update the
13138 global location list. This will remove locations that used to
13139 belong to this breakpoint. Do this before freeing the breakpoint
13140 itself, since remove_breakpoint looks at location's owner. It
13141 might be better design to have location completely
13142 self-contained, but it's not the case now. */
13143 update_global_location_list (0);
13145 bpt->ops->dtor (bpt);
13146 /* On the chance that someone will soon try again to delete this
13147 same bp, we mark it as deleted before freeing its storage. */
13148 bpt->type = bp_none;
13153 do_delete_breakpoint_cleanup (void *b)
13155 delete_breakpoint (b);
13159 make_cleanup_delete_breakpoint (struct breakpoint *b)
13161 return make_cleanup (do_delete_breakpoint_cleanup, b);
13164 /* Iterator function to call a user-provided callback function once
13165 for each of B and its related breakpoints. */
13168 iterate_over_related_breakpoints (struct breakpoint *b,
13169 void (*function) (struct breakpoint *,
13173 struct breakpoint *related;
13178 struct breakpoint *next;
13180 /* FUNCTION may delete RELATED. */
13181 next = related->related_breakpoint;
13183 if (next == related)
13185 /* RELATED is the last ring entry. */
13186 function (related, data);
13188 /* FUNCTION may have deleted it, so we'd never reach back to
13189 B. There's nothing left to do anyway, so just break
13194 function (related, data);
13198 while (related != b);
13202 do_delete_breakpoint (struct breakpoint *b, void *ignore)
13204 delete_breakpoint (b);
13207 /* A callback for map_breakpoint_numbers that calls
13208 delete_breakpoint. */
13211 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
13213 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
13217 delete_command (char *arg, int from_tty)
13219 struct breakpoint *b, *b_tmp;
13225 int breaks_to_delete = 0;
13227 /* Delete all breakpoints if no argument. Do not delete
13228 internal breakpoints, these have to be deleted with an
13229 explicit breakpoint number argument. */
13230 ALL_BREAKPOINTS (b)
13231 if (user_breakpoint_p (b))
13233 breaks_to_delete = 1;
13237 /* Ask user only if there are some breakpoints to delete. */
13239 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
13241 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13242 if (user_breakpoint_p (b))
13243 delete_breakpoint (b);
13247 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
13251 all_locations_are_pending (struct bp_location *loc)
13253 for (; loc; loc = loc->next)
13254 if (!loc->shlib_disabled
13255 && !loc->pspace->executing_startup)
13260 /* Subroutine of update_breakpoint_locations to simplify it.
13261 Return non-zero if multiple fns in list LOC have the same name.
13262 Null names are ignored. */
13265 ambiguous_names_p (struct bp_location *loc)
13267 struct bp_location *l;
13268 htab_t htab = htab_create_alloc (13, htab_hash_string,
13269 (int (*) (const void *,
13270 const void *)) streq,
13271 NULL, xcalloc, xfree);
13273 for (l = loc; l != NULL; l = l->next)
13276 const char *name = l->function_name;
13278 /* Allow for some names to be NULL, ignore them. */
13282 slot = (const char **) htab_find_slot (htab, (const void *) name,
13284 /* NOTE: We can assume slot != NULL here because xcalloc never
13288 htab_delete (htab);
13294 htab_delete (htab);
13298 /* When symbols change, it probably means the sources changed as well,
13299 and it might mean the static tracepoint markers are no longer at
13300 the same address or line numbers they used to be at last we
13301 checked. Losing your static tracepoints whenever you rebuild is
13302 undesirable. This function tries to resync/rematch gdb static
13303 tracepoints with the markers on the target, for static tracepoints
13304 that have not been set by marker id. Static tracepoint that have
13305 been set by marker id are reset by marker id in breakpoint_re_set.
13308 1) For a tracepoint set at a specific address, look for a marker at
13309 the old PC. If one is found there, assume to be the same marker.
13310 If the name / string id of the marker found is different from the
13311 previous known name, assume that means the user renamed the marker
13312 in the sources, and output a warning.
13314 2) For a tracepoint set at a given line number, look for a marker
13315 at the new address of the old line number. If one is found there,
13316 assume to be the same marker. If the name / string id of the
13317 marker found is different from the previous known name, assume that
13318 means the user renamed the marker in the sources, and output a
13321 3) If a marker is no longer found at the same address or line, it
13322 may mean the marker no longer exists. But it may also just mean
13323 the code changed a bit. Maybe the user added a few lines of code
13324 that made the marker move up or down (in line number terms). Ask
13325 the target for info about the marker with the string id as we knew
13326 it. If found, update line number and address in the matching
13327 static tracepoint. This will get confused if there's more than one
13328 marker with the same ID (possible in UST, although unadvised
13329 precisely because it confuses tools). */
13331 static struct symtab_and_line
13332 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
13334 struct tracepoint *tp = (struct tracepoint *) b;
13335 struct static_tracepoint_marker marker;
13340 find_line_pc (sal.symtab, sal.line, &pc);
13342 if (target_static_tracepoint_marker_at (pc, &marker))
13344 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
13345 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13347 tp->static_trace_marker_id, marker.str_id);
13349 xfree (tp->static_trace_marker_id);
13350 tp->static_trace_marker_id = xstrdup (marker.str_id);
13351 release_static_tracepoint_marker (&marker);
13356 /* Old marker wasn't found on target at lineno. Try looking it up
13358 if (!sal.explicit_pc
13360 && sal.symtab != NULL
13361 && tp->static_trace_marker_id != NULL)
13363 VEC(static_tracepoint_marker_p) *markers;
13366 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
13368 if (!VEC_empty(static_tracepoint_marker_p, markers))
13370 struct symtab_and_line sal2;
13371 struct symbol *sym;
13372 struct static_tracepoint_marker *tpmarker;
13373 struct ui_out *uiout = current_uiout;
13375 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
13377 xfree (tp->static_trace_marker_id);
13378 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
13380 warning (_("marker for static tracepoint %d (%s) not "
13381 "found at previous line number"),
13382 b->number, tp->static_trace_marker_id);
13386 sal2.pc = tpmarker->address;
13388 sal2 = find_pc_line (tpmarker->address, 0);
13389 sym = find_pc_sect_function (tpmarker->address, NULL);
13390 ui_out_text (uiout, "Now in ");
13393 ui_out_field_string (uiout, "func",
13394 SYMBOL_PRINT_NAME (sym));
13395 ui_out_text (uiout, " at ");
13397 ui_out_field_string (uiout, "file", sal2.symtab->filename);
13398 ui_out_text (uiout, ":");
13400 if (ui_out_is_mi_like_p (uiout))
13402 char *fullname = symtab_to_fullname (sal2.symtab);
13405 ui_out_field_string (uiout, "fullname", fullname);
13408 ui_out_field_int (uiout, "line", sal2.line);
13409 ui_out_text (uiout, "\n");
13411 b->loc->line_number = sal2.line;
13413 xfree (b->loc->source_file);
13415 b->loc->source_file = xstrdup (sal2.symtab->filename);
13417 b->loc->source_file = NULL;
13419 xfree (b->addr_string);
13420 b->addr_string = xstrprintf ("%s:%d",
13421 sal2.symtab->filename,
13422 b->loc->line_number);
13424 /* Might be nice to check if function changed, and warn if
13427 release_static_tracepoint_marker (tpmarker);
13433 /* Returns 1 iff locations A and B are sufficiently same that
13434 we don't need to report breakpoint as changed. */
13437 locations_are_equal (struct bp_location *a, struct bp_location *b)
13441 if (a->address != b->address)
13444 if (a->shlib_disabled != b->shlib_disabled)
13447 if (a->enabled != b->enabled)
13454 if ((a == NULL) != (b == NULL))
13460 /* Create new breakpoint locations for B (a hardware or software breakpoint)
13461 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
13462 a ranged breakpoint. */
13465 update_breakpoint_locations (struct breakpoint *b,
13466 struct symtabs_and_lines sals,
13467 struct symtabs_and_lines sals_end)
13470 struct bp_location *existing_locations = b->loc;
13472 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
13474 /* Ranged breakpoints have only one start location and one end
13476 b->enable_state = bp_disabled;
13477 update_global_location_list (1);
13478 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13479 "multiple locations found\n"),
13484 /* If there's no new locations, and all existing locations are
13485 pending, don't do anything. This optimizes the common case where
13486 all locations are in the same shared library, that was unloaded.
13487 We'd like to retain the location, so that when the library is
13488 loaded again, we don't loose the enabled/disabled status of the
13489 individual locations. */
13490 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
13495 for (i = 0; i < sals.nelts; ++i)
13497 struct bp_location *new_loc;
13499 switch_to_program_space_and_thread (sals.sals[i].pspace);
13501 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
13503 /* Reparse conditions, they might contain references to the
13505 if (b->cond_string != NULL)
13508 volatile struct gdb_exception e;
13510 s = b->cond_string;
13511 TRY_CATCH (e, RETURN_MASK_ERROR)
13513 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
13518 warning (_("failed to reevaluate condition "
13519 "for breakpoint %d: %s"),
13520 b->number, e.message);
13521 new_loc->enabled = 0;
13525 if (sals_end.nelts)
13527 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
13529 new_loc->length = end - sals.sals[0].pc + 1;
13533 /* Update locations of permanent breakpoints. */
13534 if (b->enable_state == bp_permanent)
13535 make_breakpoint_permanent (b);
13537 /* If possible, carry over 'disable' status from existing
13540 struct bp_location *e = existing_locations;
13541 /* If there are multiple breakpoints with the same function name,
13542 e.g. for inline functions, comparing function names won't work.
13543 Instead compare pc addresses; this is just a heuristic as things
13544 may have moved, but in practice it gives the correct answer
13545 often enough until a better solution is found. */
13546 int have_ambiguous_names = ambiguous_names_p (b->loc);
13548 for (; e; e = e->next)
13550 if (!e->enabled && e->function_name)
13552 struct bp_location *l = b->loc;
13553 if (have_ambiguous_names)
13555 for (; l; l = l->next)
13556 if (breakpoint_locations_match (e, l))
13564 for (; l; l = l->next)
13565 if (l->function_name
13566 && strcmp (e->function_name, l->function_name) == 0)
13576 if (!locations_are_equal (existing_locations, b->loc))
13577 observer_notify_breakpoint_modified (b);
13579 update_global_location_list (1);
13582 /* Find the SaL locations corresponding to the given ADDR_STRING.
13583 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13585 static struct symtabs_and_lines
13586 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
13589 struct symtabs_and_lines sals = {0};
13590 volatile struct gdb_exception e;
13592 gdb_assert (b->ops != NULL);
13595 TRY_CATCH (e, RETURN_MASK_ERROR)
13597 b->ops->decode_linespec (b, &s, &sals);
13601 int not_found_and_ok = 0;
13602 /* For pending breakpoints, it's expected that parsing will
13603 fail until the right shared library is loaded. User has
13604 already told to create pending breakpoints and don't need
13605 extra messages. If breakpoint is in bp_shlib_disabled
13606 state, then user already saw the message about that
13607 breakpoint being disabled, and don't want to see more
13609 if (e.error == NOT_FOUND_ERROR
13610 && (b->condition_not_parsed
13611 || (b->loc && b->loc->shlib_disabled)
13612 || (b->loc && b->loc->pspace->executing_startup)
13613 || b->enable_state == bp_disabled))
13614 not_found_and_ok = 1;
13616 if (!not_found_and_ok)
13618 /* We surely don't want to warn about the same breakpoint
13619 10 times. One solution, implemented here, is disable
13620 the breakpoint on error. Another solution would be to
13621 have separate 'warning emitted' flag. Since this
13622 happens only when a binary has changed, I don't know
13623 which approach is better. */
13624 b->enable_state = bp_disabled;
13625 throw_exception (e);
13629 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
13633 for (i = 0; i < sals.nelts; ++i)
13634 resolve_sal_pc (&sals.sals[i]);
13635 if (b->condition_not_parsed && s && s[0])
13637 char *cond_string = 0;
13640 char *extra_string = NULL;
13642 find_condition_and_thread (s, sals.sals[0].pc,
13643 &cond_string, &thread, &task,
13646 b->cond_string = cond_string;
13647 b->thread = thread;
13650 b->extra_string = extra_string;
13651 b->condition_not_parsed = 0;
13654 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
13655 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
13665 /* The default re_set method, for typical hardware or software
13666 breakpoints. Reevaluate the breakpoint and recreate its
13670 breakpoint_re_set_default (struct breakpoint *b)
13673 struct symtabs_and_lines sals, sals_end;
13674 struct symtabs_and_lines expanded = {0};
13675 struct symtabs_and_lines expanded_end = {0};
13677 sals = addr_string_to_sals (b, b->addr_string, &found);
13680 make_cleanup (xfree, sals.sals);
13684 if (b->addr_string_range_end)
13686 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
13689 make_cleanup (xfree, sals_end.sals);
13690 expanded_end = sals_end;
13694 update_breakpoint_locations (b, expanded, expanded_end);
13697 /* Default method for creating SALs from an address string. It basically
13698 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13701 create_sals_from_address_default (char **arg,
13702 struct linespec_result *canonical,
13703 enum bptype type_wanted,
13704 char *addr_start, char **copy_arg)
13706 parse_breakpoint_sals (arg, canonical);
13709 /* Call create_breakpoints_sal for the given arguments. This is the default
13710 function for the `create_breakpoints_sal' method of
13714 create_breakpoints_sal_default (struct gdbarch *gdbarch,
13715 struct linespec_result *canonical,
13716 struct linespec_sals *lsal,
13718 char *extra_string,
13719 enum bptype type_wanted,
13720 enum bpdisp disposition,
13722 int task, int ignore_count,
13723 const struct breakpoint_ops *ops,
13724 int from_tty, int enabled,
13725 int internal, unsigned flags)
13727 create_breakpoints_sal (gdbarch, canonical, cond_string,
13729 type_wanted, disposition,
13730 thread, task, ignore_count, ops, from_tty,
13731 enabled, internal, flags);
13734 /* Decode the line represented by S by calling decode_line_full. This is the
13735 default function for the `decode_linespec' method of breakpoint_ops. */
13738 decode_linespec_default (struct breakpoint *b, char **s,
13739 struct symtabs_and_lines *sals)
13741 struct linespec_result canonical;
13743 init_linespec_result (&canonical);
13744 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
13745 (struct symtab *) NULL, 0,
13746 &canonical, multiple_symbols_all,
13749 /* We should get 0 or 1 resulting SALs. */
13750 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
13752 if (VEC_length (linespec_sals, canonical.sals) > 0)
13754 struct linespec_sals *lsal;
13756 lsal = VEC_index (linespec_sals, canonical.sals, 0);
13757 *sals = lsal->sals;
13758 /* Arrange it so the destructor does not free the
13760 lsal->sals.sals = NULL;
13763 destroy_linespec_result (&canonical);
13766 /* Prepare the global context for a re-set of breakpoint B. */
13768 static struct cleanup *
13769 prepare_re_set_context (struct breakpoint *b)
13771 struct cleanup *cleanups;
13773 input_radix = b->input_radix;
13774 cleanups = save_current_space_and_thread ();
13775 if (b->pspace != NULL)
13776 switch_to_program_space_and_thread (b->pspace);
13777 set_language (b->language);
13782 /* Reset a breakpoint given it's struct breakpoint * BINT.
13783 The value we return ends up being the return value from catch_errors.
13784 Unused in this case. */
13787 breakpoint_re_set_one (void *bint)
13789 /* Get past catch_errs. */
13790 struct breakpoint *b = (struct breakpoint *) bint;
13791 struct cleanup *cleanups;
13793 cleanups = prepare_re_set_context (b);
13794 b->ops->re_set (b);
13795 do_cleanups (cleanups);
13799 /* Re-set all breakpoints after symbols have been re-loaded. */
13801 breakpoint_re_set (void)
13803 struct breakpoint *b, *b_tmp;
13804 enum language save_language;
13805 int save_input_radix;
13806 struct cleanup *old_chain;
13808 save_language = current_language->la_language;
13809 save_input_radix = input_radix;
13810 old_chain = save_current_program_space ();
13812 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13814 /* Format possible error msg. */
13815 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
13817 struct cleanup *cleanups = make_cleanup (xfree, message);
13818 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
13819 do_cleanups (cleanups);
13821 set_language (save_language);
13822 input_radix = save_input_radix;
13824 jit_breakpoint_re_set ();
13826 do_cleanups (old_chain);
13828 create_overlay_event_breakpoint ();
13829 create_longjmp_master_breakpoint ();
13830 create_std_terminate_master_breakpoint ();
13831 create_exception_master_breakpoint ();
13833 /* While we're at it, reset the skip list too. */
13837 /* Reset the thread number of this breakpoint:
13839 - If the breakpoint is for all threads, leave it as-is.
13840 - Else, reset it to the current thread for inferior_ptid. */
13842 breakpoint_re_set_thread (struct breakpoint *b)
13844 if (b->thread != -1)
13846 if (in_thread_list (inferior_ptid))
13847 b->thread = pid_to_thread_id (inferior_ptid);
13849 /* We're being called after following a fork. The new fork is
13850 selected as current, and unless this was a vfork will have a
13851 different program space from the original thread. Reset that
13853 b->loc->pspace = current_program_space;
13857 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13858 If from_tty is nonzero, it prints a message to that effect,
13859 which ends with a period (no newline). */
13862 set_ignore_count (int bptnum, int count, int from_tty)
13864 struct breakpoint *b;
13869 ALL_BREAKPOINTS (b)
13870 if (b->number == bptnum)
13872 if (is_tracepoint (b))
13874 if (from_tty && count != 0)
13875 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13880 b->ignore_count = count;
13884 printf_filtered (_("Will stop next time "
13885 "breakpoint %d is reached."),
13887 else if (count == 1)
13888 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13891 printf_filtered (_("Will ignore next %d "
13892 "crossings of breakpoint %d."),
13895 breakpoints_changed ();
13896 observer_notify_breakpoint_modified (b);
13900 error (_("No breakpoint number %d."), bptnum);
13903 /* Command to set ignore-count of breakpoint N to COUNT. */
13906 ignore_command (char *args, int from_tty)
13912 error_no_arg (_("a breakpoint number"));
13914 num = get_number (&p);
13916 error (_("bad breakpoint number: '%s'"), args);
13918 error (_("Second argument (specified ignore-count) is missing."));
13920 set_ignore_count (num,
13921 longest_to_int (value_as_long (parse_and_eval (p))),
13924 printf_filtered ("\n");
13927 /* Call FUNCTION on each of the breakpoints
13928 whose numbers are given in ARGS. */
13931 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
13936 struct breakpoint *b, *tmp;
13938 struct get_number_or_range_state state;
13941 error_no_arg (_("one or more breakpoint numbers"));
13943 init_number_or_range (&state, args);
13945 while (!state.finished)
13947 char *p = state.string;
13951 num = get_number_or_range (&state);
13954 warning (_("bad breakpoint number at or near '%s'"), p);
13958 ALL_BREAKPOINTS_SAFE (b, tmp)
13959 if (b->number == num)
13962 function (b, data);
13966 printf_unfiltered (_("No breakpoint number %d.\n"), num);
13971 static struct bp_location *
13972 find_location_by_number (char *number)
13974 char *dot = strchr (number, '.');
13978 struct breakpoint *b;
13979 struct bp_location *loc;
13984 bp_num = get_number (&p1);
13986 error (_("Bad breakpoint number '%s'"), number);
13988 ALL_BREAKPOINTS (b)
13989 if (b->number == bp_num)
13994 if (!b || b->number != bp_num)
13995 error (_("Bad breakpoint number '%s'"), number);
13998 loc_num = get_number (&p1);
14000 error (_("Bad breakpoint location number '%s'"), number);
14004 for (;loc_num && loc; --loc_num, loc = loc->next)
14007 error (_("Bad breakpoint location number '%s'"), dot+1);
14013 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14014 If from_tty is nonzero, it prints a message to that effect,
14015 which ends with a period (no newline). */
14018 disable_breakpoint (struct breakpoint *bpt)
14020 /* Never disable a watchpoint scope breakpoint; we want to
14021 hit them when we leave scope so we can delete both the
14022 watchpoint and its scope breakpoint at that time. */
14023 if (bpt->type == bp_watchpoint_scope)
14026 /* You can't disable permanent breakpoints. */
14027 if (bpt->enable_state == bp_permanent)
14030 bpt->enable_state = bp_disabled;
14032 /* Mark breakpoint locations modified. */
14033 mark_breakpoint_modified (bpt);
14035 if (target_supports_enable_disable_tracepoint ()
14036 && current_trace_status ()->running && is_tracepoint (bpt))
14038 struct bp_location *location;
14040 for (location = bpt->loc; location; location = location->next)
14041 target_disable_tracepoint (location);
14044 update_global_location_list (0);
14046 observer_notify_breakpoint_modified (bpt);
14049 /* A callback for iterate_over_related_breakpoints. */
14052 do_disable_breakpoint (struct breakpoint *b, void *ignore)
14054 disable_breakpoint (b);
14057 /* A callback for map_breakpoint_numbers that calls
14058 disable_breakpoint. */
14061 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
14063 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
14067 disable_command (char *args, int from_tty)
14071 struct breakpoint *bpt;
14073 ALL_BREAKPOINTS (bpt)
14074 if (user_breakpoint_p (bpt))
14075 disable_breakpoint (bpt);
14077 else if (strchr (args, '.'))
14079 struct bp_location *loc = find_location_by_number (args);
14085 mark_breakpoint_location_modified (loc);
14087 if (target_supports_enable_disable_tracepoint ()
14088 && current_trace_status ()->running && loc->owner
14089 && is_tracepoint (loc->owner))
14090 target_disable_tracepoint (loc);
14092 update_global_location_list (0);
14095 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
14099 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14102 int target_resources_ok;
14104 if (bpt->type == bp_hardware_breakpoint)
14107 i = hw_breakpoint_used_count ();
14108 target_resources_ok =
14109 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
14111 if (target_resources_ok == 0)
14112 error (_("No hardware breakpoint support in the target."));
14113 else if (target_resources_ok < 0)
14114 error (_("Hardware breakpoints used exceeds limit."));
14117 if (is_watchpoint (bpt))
14119 /* Initialize it just to avoid a GCC false warning. */
14120 enum enable_state orig_enable_state = 0;
14121 volatile struct gdb_exception e;
14123 TRY_CATCH (e, RETURN_MASK_ALL)
14125 struct watchpoint *w = (struct watchpoint *) bpt;
14127 orig_enable_state = bpt->enable_state;
14128 bpt->enable_state = bp_enabled;
14129 update_watchpoint (w, 1 /* reparse */);
14133 bpt->enable_state = orig_enable_state;
14134 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
14140 if (bpt->enable_state != bp_permanent)
14141 bpt->enable_state = bp_enabled;
14143 bpt->enable_state = bp_enabled;
14145 /* Mark breakpoint locations modified. */
14146 mark_breakpoint_modified (bpt);
14148 if (target_supports_enable_disable_tracepoint ()
14149 && current_trace_status ()->running && is_tracepoint (bpt))
14151 struct bp_location *location;
14153 for (location = bpt->loc; location; location = location->next)
14154 target_enable_tracepoint (location);
14157 bpt->disposition = disposition;
14158 bpt->enable_count = count;
14159 update_global_location_list (1);
14160 breakpoints_changed ();
14162 observer_notify_breakpoint_modified (bpt);
14167 enable_breakpoint (struct breakpoint *bpt)
14169 enable_breakpoint_disp (bpt, bpt->disposition, 0);
14173 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
14175 enable_breakpoint (bpt);
14178 /* A callback for map_breakpoint_numbers that calls
14179 enable_breakpoint. */
14182 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
14184 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
14187 /* The enable command enables the specified breakpoints (or all defined
14188 breakpoints) so they once again become (or continue to be) effective
14189 in stopping the inferior. */
14192 enable_command (char *args, int from_tty)
14196 struct breakpoint *bpt;
14198 ALL_BREAKPOINTS (bpt)
14199 if (user_breakpoint_p (bpt))
14200 enable_breakpoint (bpt);
14202 else if (strchr (args, '.'))
14204 struct bp_location *loc = find_location_by_number (args);
14210 mark_breakpoint_location_modified (loc);
14212 if (target_supports_enable_disable_tracepoint ()
14213 && current_trace_status ()->running && loc->owner
14214 && is_tracepoint (loc->owner))
14215 target_enable_tracepoint (loc);
14217 update_global_location_list (1);
14220 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
14223 /* This struct packages up disposition data for application to multiple
14233 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
14235 struct disp_data disp_data = *(struct disp_data *) arg;
14237 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
14241 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
14243 struct disp_data disp = { disp_disable, 1 };
14245 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14249 enable_once_command (char *args, int from_tty)
14251 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
14255 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
14257 struct disp_data disp = { disp_disable, *(int *) countptr };
14259 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14263 enable_count_command (char *args, int from_tty)
14265 int count = get_number (&args);
14267 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
14271 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
14273 struct disp_data disp = { disp_del, 1 };
14275 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14279 enable_delete_command (char *args, int from_tty)
14281 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
14285 set_breakpoint_cmd (char *args, int from_tty)
14290 show_breakpoint_cmd (char *args, int from_tty)
14294 /* Invalidate last known value of any hardware watchpoint if
14295 the memory which that value represents has been written to by
14299 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
14300 const bfd_byte *data)
14302 struct breakpoint *bp;
14304 ALL_BREAKPOINTS (bp)
14305 if (bp->enable_state == bp_enabled
14306 && bp->type == bp_hardware_watchpoint)
14308 struct watchpoint *wp = (struct watchpoint *) bp;
14310 if (wp->val_valid && wp->val)
14312 struct bp_location *loc;
14314 for (loc = bp->loc; loc != NULL; loc = loc->next)
14315 if (loc->loc_type == bp_loc_hardware_watchpoint
14316 && loc->address + loc->length > addr
14317 && addr + len > loc->address)
14319 value_free (wp->val);
14327 /* Use the last displayed codepoint's values, or nothing
14328 if they aren't valid. */
14330 struct symtabs_and_lines
14331 decode_line_spec_1 (char *string, int flags)
14333 struct symtabs_and_lines sals;
14336 error (_("Empty line specification."));
14337 if (last_displayed_sal_is_valid ())
14338 sals = decode_line_1 (&string, flags,
14339 get_last_displayed_symtab (),
14340 get_last_displayed_line ());
14342 sals = decode_line_1 (&string, flags, (struct symtab *) NULL, 0);
14344 error (_("Junk at end of line specification: %s"), string);
14348 /* Create and insert a raw software breakpoint at PC. Return an
14349 identifier, which should be used to remove the breakpoint later.
14350 In general, places which call this should be using something on the
14351 breakpoint chain instead; this function should be eliminated
14355 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
14356 struct address_space *aspace, CORE_ADDR pc)
14358 struct bp_target_info *bp_tgt;
14360 bp_tgt = XZALLOC (struct bp_target_info);
14362 bp_tgt->placed_address_space = aspace;
14363 bp_tgt->placed_address = pc;
14365 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
14367 /* Could not insert the breakpoint. */
14375 /* Remove a breakpoint BP inserted by
14376 deprecated_insert_raw_breakpoint. */
14379 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
14381 struct bp_target_info *bp_tgt = bp;
14384 ret = target_remove_breakpoint (gdbarch, bp_tgt);
14390 /* One (or perhaps two) breakpoints used for software single
14393 static void *single_step_breakpoints[2];
14394 static struct gdbarch *single_step_gdbarch[2];
14396 /* Create and insert a breakpoint for software single step. */
14399 insert_single_step_breakpoint (struct gdbarch *gdbarch,
14400 struct address_space *aspace,
14405 if (single_step_breakpoints[0] == NULL)
14407 bpt_p = &single_step_breakpoints[0];
14408 single_step_gdbarch[0] = gdbarch;
14412 gdb_assert (single_step_breakpoints[1] == NULL);
14413 bpt_p = &single_step_breakpoints[1];
14414 single_step_gdbarch[1] = gdbarch;
14417 /* NOTE drow/2006-04-11: A future improvement to this function would
14418 be to only create the breakpoints once, and actually put them on
14419 the breakpoint chain. That would let us use set_raw_breakpoint.
14420 We could adjust the addresses each time they were needed. Doing
14421 this requires corresponding changes elsewhere where single step
14422 breakpoints are handled, however. So, for now, we use this. */
14424 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
14425 if (*bpt_p == NULL)
14426 error (_("Could not insert single-step breakpoint at %s"),
14427 paddress (gdbarch, next_pc));
14430 /* Check if the breakpoints used for software single stepping
14431 were inserted or not. */
14434 single_step_breakpoints_inserted (void)
14436 return (single_step_breakpoints[0] != NULL
14437 || single_step_breakpoints[1] != NULL);
14440 /* Remove and delete any breakpoints used for software single step. */
14443 remove_single_step_breakpoints (void)
14445 gdb_assert (single_step_breakpoints[0] != NULL);
14447 /* See insert_single_step_breakpoint for more about this deprecated
14449 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
14450 single_step_breakpoints[0]);
14451 single_step_gdbarch[0] = NULL;
14452 single_step_breakpoints[0] = NULL;
14454 if (single_step_breakpoints[1] != NULL)
14456 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
14457 single_step_breakpoints[1]);
14458 single_step_gdbarch[1] = NULL;
14459 single_step_breakpoints[1] = NULL;
14463 /* Delete software single step breakpoints without removing them from
14464 the inferior. This is intended to be used if the inferior's address
14465 space where they were inserted is already gone, e.g. after exit or
14469 cancel_single_step_breakpoints (void)
14473 for (i = 0; i < 2; i++)
14474 if (single_step_breakpoints[i])
14476 xfree (single_step_breakpoints[i]);
14477 single_step_breakpoints[i] = NULL;
14478 single_step_gdbarch[i] = NULL;
14482 /* Detach software single-step breakpoints from INFERIOR_PTID without
14486 detach_single_step_breakpoints (void)
14490 for (i = 0; i < 2; i++)
14491 if (single_step_breakpoints[i])
14492 target_remove_breakpoint (single_step_gdbarch[i],
14493 single_step_breakpoints[i]);
14496 /* Check whether a software single-step breakpoint is inserted at
14500 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
14505 for (i = 0; i < 2; i++)
14507 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
14509 && breakpoint_address_match (bp_tgt->placed_address_space,
14510 bp_tgt->placed_address,
14518 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
14519 non-zero otherwise. */
14521 is_syscall_catchpoint_enabled (struct breakpoint *bp)
14523 if (syscall_catchpoint_p (bp)
14524 && bp->enable_state != bp_disabled
14525 && bp->enable_state != bp_call_disabled)
14532 catch_syscall_enabled (void)
14534 struct catch_syscall_inferior_data *inf_data
14535 = get_catch_syscall_inferior_data (current_inferior ());
14537 return inf_data->total_syscalls_count != 0;
14541 catching_syscall_number (int syscall_number)
14543 struct breakpoint *bp;
14545 ALL_BREAKPOINTS (bp)
14546 if (is_syscall_catchpoint_enabled (bp))
14548 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
14550 if (c->syscalls_to_be_caught)
14554 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
14556 if (syscall_number == iter)
14566 /* Complete syscall names. Used by "catch syscall". */
14568 catch_syscall_completer (struct cmd_list_element *cmd,
14569 char *text, char *word)
14571 const char **list = get_syscall_names ();
14573 = (list == NULL) ? NULL : complete_on_enum (list, text, word);
14579 /* Tracepoint-specific operations. */
14581 /* Set tracepoint count to NUM. */
14583 set_tracepoint_count (int num)
14585 tracepoint_count = num;
14586 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
14590 trace_command (char *arg, int from_tty)
14592 struct breakpoint_ops *ops;
14593 const char *arg_cp = arg;
14595 if (arg && probe_linespec_to_ops (&arg_cp))
14596 ops = &tracepoint_probe_breakpoint_ops;
14598 ops = &tracepoint_breakpoint_ops;
14600 if (create_breakpoint (get_current_arch (),
14602 NULL, 0, NULL, 1 /* parse arg */,
14604 bp_tracepoint /* type_wanted */,
14605 0 /* Ignore count */,
14606 pending_break_support,
14610 0 /* internal */, 0))
14611 set_tracepoint_count (breakpoint_count);
14615 ftrace_command (char *arg, int from_tty)
14617 if (create_breakpoint (get_current_arch (),
14619 NULL, 0, NULL, 1 /* parse arg */,
14621 bp_fast_tracepoint /* type_wanted */,
14622 0 /* Ignore count */,
14623 pending_break_support,
14624 &tracepoint_breakpoint_ops,
14627 0 /* internal */, 0))
14628 set_tracepoint_count (breakpoint_count);
14631 /* strace command implementation. Creates a static tracepoint. */
14634 strace_command (char *arg, int from_tty)
14636 struct breakpoint_ops *ops;
14638 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14639 or with a normal static tracepoint. */
14640 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
14641 ops = &strace_marker_breakpoint_ops;
14643 ops = &tracepoint_breakpoint_ops;
14645 if (create_breakpoint (get_current_arch (),
14647 NULL, 0, NULL, 1 /* parse arg */,
14649 bp_static_tracepoint /* type_wanted */,
14650 0 /* Ignore count */,
14651 pending_break_support,
14655 0 /* internal */, 0))
14656 set_tracepoint_count (breakpoint_count);
14659 /* Set up a fake reader function that gets command lines from a linked
14660 list that was acquired during tracepoint uploading. */
14662 static struct uploaded_tp *this_utp;
14663 static int next_cmd;
14666 read_uploaded_action (void)
14670 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
14677 /* Given information about a tracepoint as recorded on a target (which
14678 can be either a live system or a trace file), attempt to create an
14679 equivalent GDB tracepoint. This is not a reliable process, since
14680 the target does not necessarily have all the information used when
14681 the tracepoint was originally defined. */
14683 struct tracepoint *
14684 create_tracepoint_from_upload (struct uploaded_tp *utp)
14686 char *addr_str, small_buf[100];
14687 struct tracepoint *tp;
14689 if (utp->at_string)
14690 addr_str = utp->at_string;
14693 /* In the absence of a source location, fall back to raw
14694 address. Since there is no way to confirm that the address
14695 means the same thing as when the trace was started, warn the
14697 warning (_("Uploaded tracepoint %d has no "
14698 "source location, using raw address"),
14700 sprintf (small_buf, "*%s", hex_string (utp->addr));
14701 addr_str = small_buf;
14704 /* There's not much we can do with a sequence of bytecodes. */
14705 if (utp->cond && !utp->cond_string)
14706 warning (_("Uploaded tracepoint %d condition "
14707 "has no source form, ignoring it"),
14710 if (!create_breakpoint (get_current_arch (),
14712 utp->cond_string, -1, NULL,
14713 0 /* parse cond/thread */,
14715 utp->type /* type_wanted */,
14716 0 /* Ignore count */,
14717 pending_break_support,
14718 &tracepoint_breakpoint_ops,
14720 utp->enabled /* enabled */,
14722 CREATE_BREAKPOINT_FLAGS_INSERTED))
14725 set_tracepoint_count (breakpoint_count);
14727 /* Get the tracepoint we just created. */
14728 tp = get_tracepoint (tracepoint_count);
14729 gdb_assert (tp != NULL);
14733 sprintf (small_buf, "%d %d", utp->pass, tp->base.number);
14735 trace_pass_command (small_buf, 0);
14738 /* If we have uploaded versions of the original commands, set up a
14739 special-purpose "reader" function and call the usual command line
14740 reader, then pass the result to the breakpoint command-setting
14742 if (!VEC_empty (char_ptr, utp->cmd_strings))
14744 struct command_line *cmd_list;
14749 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
14751 breakpoint_set_commands (&tp->base, cmd_list);
14753 else if (!VEC_empty (char_ptr, utp->actions)
14754 || !VEC_empty (char_ptr, utp->step_actions))
14755 warning (_("Uploaded tracepoint %d actions "
14756 "have no source form, ignoring them"),
14759 /* Copy any status information that might be available. */
14760 tp->base.hit_count = utp->hit_count;
14761 tp->traceframe_usage = utp->traceframe_usage;
14766 /* Print information on tracepoint number TPNUM_EXP, or all if
14770 tracepoints_info (char *args, int from_tty)
14772 struct ui_out *uiout = current_uiout;
14775 num_printed = breakpoint_1 (args, 0, is_tracepoint);
14777 if (num_printed == 0)
14779 if (args == NULL || *args == '\0')
14780 ui_out_message (uiout, 0, "No tracepoints.\n");
14782 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
14785 default_collect_info ();
14788 /* The 'enable trace' command enables tracepoints.
14789 Not supported by all targets. */
14791 enable_trace_command (char *args, int from_tty)
14793 enable_command (args, from_tty);
14796 /* The 'disable trace' command disables tracepoints.
14797 Not supported by all targets. */
14799 disable_trace_command (char *args, int from_tty)
14801 disable_command (args, from_tty);
14804 /* Remove a tracepoint (or all if no argument). */
14806 delete_trace_command (char *arg, int from_tty)
14808 struct breakpoint *b, *b_tmp;
14814 int breaks_to_delete = 0;
14816 /* Delete all breakpoints if no argument.
14817 Do not delete internal or call-dummy breakpoints, these
14818 have to be deleted with an explicit breakpoint number
14820 ALL_TRACEPOINTS (b)
14821 if (is_tracepoint (b) && user_breakpoint_p (b))
14823 breaks_to_delete = 1;
14827 /* Ask user only if there are some breakpoints to delete. */
14829 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
14831 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14832 if (is_tracepoint (b) && user_breakpoint_p (b))
14833 delete_breakpoint (b);
14837 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
14840 /* Helper function for trace_pass_command. */
14843 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
14845 tp->pass_count = count;
14846 observer_notify_tracepoint_modified (tp->base.number);
14848 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14849 tp->base.number, count);
14852 /* Set passcount for tracepoint.
14854 First command argument is passcount, second is tracepoint number.
14855 If tracepoint number omitted, apply to most recently defined.
14856 Also accepts special argument "all". */
14859 trace_pass_command (char *args, int from_tty)
14861 struct tracepoint *t1;
14862 unsigned int count;
14864 if (args == 0 || *args == 0)
14865 error (_("passcount command requires an "
14866 "argument (count + optional TP num)"));
14868 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
14870 while (*args && isspace ((int) *args))
14873 if (*args && strncasecmp (args, "all", 3) == 0)
14875 struct breakpoint *b;
14877 args += 3; /* Skip special argument "all". */
14879 error (_("Junk at end of arguments."));
14881 ALL_TRACEPOINTS (b)
14883 t1 = (struct tracepoint *) b;
14884 trace_pass_set_count (t1, count, from_tty);
14887 else if (*args == '\0')
14889 t1 = get_tracepoint_by_number (&args, NULL, 1);
14891 trace_pass_set_count (t1, count, from_tty);
14895 struct get_number_or_range_state state;
14897 init_number_or_range (&state, args);
14898 while (!state.finished)
14900 t1 = get_tracepoint_by_number (&args, &state, 1);
14902 trace_pass_set_count (t1, count, from_tty);
14907 struct tracepoint *
14908 get_tracepoint (int num)
14910 struct breakpoint *t;
14912 ALL_TRACEPOINTS (t)
14913 if (t->number == num)
14914 return (struct tracepoint *) t;
14919 /* Find the tracepoint with the given target-side number (which may be
14920 different from the tracepoint number after disconnecting and
14923 struct tracepoint *
14924 get_tracepoint_by_number_on_target (int num)
14926 struct breakpoint *b;
14928 ALL_TRACEPOINTS (b)
14930 struct tracepoint *t = (struct tracepoint *) b;
14932 if (t->number_on_target == num)
14939 /* Utility: parse a tracepoint number and look it up in the list.
14940 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14941 If OPTIONAL_P is true, then if the argument is missing, the most
14942 recent tracepoint (tracepoint_count) is returned. */
14943 struct tracepoint *
14944 get_tracepoint_by_number (char **arg,
14945 struct get_number_or_range_state *state,
14948 extern int tracepoint_count;
14949 struct breakpoint *t;
14951 char *instring = arg == NULL ? NULL : *arg;
14955 gdb_assert (!state->finished);
14956 tpnum = get_number_or_range (state);
14958 else if (arg == NULL || *arg == NULL || ! **arg)
14961 tpnum = tracepoint_count;
14963 error_no_arg (_("tracepoint number"));
14966 tpnum = get_number (arg);
14970 if (instring && *instring)
14971 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14974 printf_filtered (_("Tracepoint argument missing "
14975 "and no previous tracepoint\n"));
14979 ALL_TRACEPOINTS (t)
14980 if (t->number == tpnum)
14982 return (struct tracepoint *) t;
14985 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
14990 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
14992 if (b->thread != -1)
14993 fprintf_unfiltered (fp, " thread %d", b->thread);
14996 fprintf_unfiltered (fp, " task %d", b->task);
14998 fprintf_unfiltered (fp, "\n");
15001 /* Save information on user settable breakpoints (watchpoints, etc) to
15002 a new script file named FILENAME. If FILTER is non-NULL, call it
15003 on each breakpoint and only include the ones for which it returns
15007 save_breakpoints (char *filename, int from_tty,
15008 int (*filter) (const struct breakpoint *))
15010 struct breakpoint *tp;
15013 struct cleanup *cleanup;
15014 struct ui_file *fp;
15015 int extra_trace_bits = 0;
15017 if (filename == 0 || *filename == 0)
15018 error (_("Argument required (file name in which to save)"));
15020 /* See if we have anything to save. */
15021 ALL_BREAKPOINTS (tp)
15023 /* Skip internal and momentary breakpoints. */
15024 if (!user_breakpoint_p (tp))
15027 /* If we have a filter, only save the breakpoints it accepts. */
15028 if (filter && !filter (tp))
15033 if (is_tracepoint (tp))
15035 extra_trace_bits = 1;
15037 /* We can stop searching. */
15044 warning (_("Nothing to save."));
15048 pathname = tilde_expand (filename);
15049 cleanup = make_cleanup (xfree, pathname);
15050 fp = gdb_fopen (pathname, "w");
15052 error (_("Unable to open file '%s' for saving (%s)"),
15053 filename, safe_strerror (errno));
15054 make_cleanup_ui_file_delete (fp);
15056 if (extra_trace_bits)
15057 save_trace_state_variables (fp);
15059 ALL_BREAKPOINTS (tp)
15061 /* Skip internal and momentary breakpoints. */
15062 if (!user_breakpoint_p (tp))
15065 /* If we have a filter, only save the breakpoints it accepts. */
15066 if (filter && !filter (tp))
15069 tp->ops->print_recreate (tp, fp);
15071 /* Note, we can't rely on tp->number for anything, as we can't
15072 assume the recreated breakpoint numbers will match. Use $bpnum
15075 if (tp->cond_string)
15076 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
15078 if (tp->ignore_count)
15079 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
15083 volatile struct gdb_exception ex;
15085 fprintf_unfiltered (fp, " commands\n");
15087 ui_out_redirect (current_uiout, fp);
15088 TRY_CATCH (ex, RETURN_MASK_ALL)
15090 print_command_lines (current_uiout, tp->commands->commands, 2);
15092 ui_out_redirect (current_uiout, NULL);
15095 throw_exception (ex);
15097 fprintf_unfiltered (fp, " end\n");
15100 if (tp->enable_state == bp_disabled)
15101 fprintf_unfiltered (fp, "disable\n");
15103 /* If this is a multi-location breakpoint, check if the locations
15104 should be individually disabled. Watchpoint locations are
15105 special, and not user visible. */
15106 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15108 struct bp_location *loc;
15111 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15113 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
15117 if (extra_trace_bits && *default_collect)
15118 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
15120 do_cleanups (cleanup);
15122 printf_filtered (_("Saved to file '%s'.\n"), filename);
15125 /* The `save breakpoints' command. */
15128 save_breakpoints_command (char *args, int from_tty)
15130 save_breakpoints (args, from_tty, NULL);
15133 /* The `save tracepoints' command. */
15136 save_tracepoints_command (char *args, int from_tty)
15138 save_breakpoints (args, from_tty, is_tracepoint);
15141 /* Create a vector of all tracepoints. */
15143 VEC(breakpoint_p) *
15144 all_tracepoints (void)
15146 VEC(breakpoint_p) *tp_vec = 0;
15147 struct breakpoint *tp;
15149 ALL_TRACEPOINTS (tp)
15151 VEC_safe_push (breakpoint_p, tp_vec, tp);
15158 /* This help string is used for the break, hbreak, tbreak and thbreak
15159 commands. It is defined as a macro to prevent duplication.
15160 COMMAND should be a string constant containing the name of the
15162 #define BREAK_ARGS_HELP(command) \
15163 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15164 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15165 If a line number is specified, break at start of code for that line.\n\
15166 If a function is specified, break at start of code for that function.\n\
15167 If an address is specified, break at that exact address.\n\
15168 With no LOCATION, uses current execution address of the selected\n\
15169 stack frame. This is useful for breaking on return to a stack frame.\n\
15171 THREADNUM is the number from \"info threads\".\n\
15172 CONDITION is a boolean expression.\n\
15174 Multiple breakpoints at one place are permitted, and useful if their\n\
15175 conditions are different.\n\
15177 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15179 /* List of subcommands for "catch". */
15180 static struct cmd_list_element *catch_cmdlist;
15182 /* List of subcommands for "tcatch". */
15183 static struct cmd_list_element *tcatch_cmdlist;
15186 add_catch_command (char *name, char *docstring,
15187 void (*sfunc) (char *args, int from_tty,
15188 struct cmd_list_element *command),
15189 char **(*completer) (struct cmd_list_element *cmd,
15190 char *text, char *word),
15191 void *user_data_catch,
15192 void *user_data_tcatch)
15194 struct cmd_list_element *command;
15196 command = add_cmd (name, class_breakpoint, NULL, docstring,
15198 set_cmd_sfunc (command, sfunc);
15199 set_cmd_context (command, user_data_catch);
15200 set_cmd_completer (command, completer);
15202 command = add_cmd (name, class_breakpoint, NULL, docstring,
15204 set_cmd_sfunc (command, sfunc);
15205 set_cmd_context (command, user_data_tcatch);
15206 set_cmd_completer (command, completer);
15210 clear_syscall_counts (struct inferior *inf)
15212 struct catch_syscall_inferior_data *inf_data
15213 = get_catch_syscall_inferior_data (inf);
15215 inf_data->total_syscalls_count = 0;
15216 inf_data->any_syscall_count = 0;
15217 VEC_free (int, inf_data->syscalls_counts);
15221 save_command (char *arg, int from_tty)
15223 printf_unfiltered (_("\"save\" must be followed by "
15224 "the name of a save subcommand.\n"));
15225 help_list (save_cmdlist, "save ", -1, gdb_stdout);
15228 struct breakpoint *
15229 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15232 struct breakpoint *b, *b_tmp;
15234 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15236 if ((*callback) (b, data))
15243 /* Zero if any of the breakpoint's locations could be a location where
15244 functions have been inlined, nonzero otherwise. */
15247 is_non_inline_function (struct breakpoint *b)
15249 /* The shared library event breakpoint is set on the address of a
15250 non-inline function. */
15251 if (b->type == bp_shlib_event)
15257 /* Nonzero if the specified PC cannot be a location where functions
15258 have been inlined. */
15261 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
15262 const struct target_waitstatus *ws)
15264 struct breakpoint *b;
15265 struct bp_location *bl;
15267 ALL_BREAKPOINTS (b)
15269 if (!is_non_inline_function (b))
15272 for (bl = b->loc; bl != NULL; bl = bl->next)
15274 if (!bl->shlib_disabled
15275 && bpstat_check_location (bl, aspace, pc, ws))
15284 initialize_breakpoint_ops (void)
15286 static int initialized = 0;
15288 struct breakpoint_ops *ops;
15294 /* The breakpoint_ops structure to be inherit by all kinds of
15295 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15296 internal and momentary breakpoints, etc.). */
15297 ops = &bkpt_base_breakpoint_ops;
15298 *ops = base_breakpoint_ops;
15299 ops->re_set = bkpt_re_set;
15300 ops->insert_location = bkpt_insert_location;
15301 ops->remove_location = bkpt_remove_location;
15302 ops->breakpoint_hit = bkpt_breakpoint_hit;
15303 ops->create_sals_from_address = bkpt_create_sals_from_address;
15304 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
15305 ops->decode_linespec = bkpt_decode_linespec;
15307 /* The breakpoint_ops structure to be used in regular breakpoints. */
15308 ops = &bkpt_breakpoint_ops;
15309 *ops = bkpt_base_breakpoint_ops;
15310 ops->re_set = bkpt_re_set;
15311 ops->resources_needed = bkpt_resources_needed;
15312 ops->print_it = bkpt_print_it;
15313 ops->print_mention = bkpt_print_mention;
15314 ops->print_recreate = bkpt_print_recreate;
15316 /* Ranged breakpoints. */
15317 ops = &ranged_breakpoint_ops;
15318 *ops = bkpt_breakpoint_ops;
15319 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
15320 ops->resources_needed = resources_needed_ranged_breakpoint;
15321 ops->print_it = print_it_ranged_breakpoint;
15322 ops->print_one = print_one_ranged_breakpoint;
15323 ops->print_one_detail = print_one_detail_ranged_breakpoint;
15324 ops->print_mention = print_mention_ranged_breakpoint;
15325 ops->print_recreate = print_recreate_ranged_breakpoint;
15327 /* Internal breakpoints. */
15328 ops = &internal_breakpoint_ops;
15329 *ops = bkpt_base_breakpoint_ops;
15330 ops->re_set = internal_bkpt_re_set;
15331 ops->check_status = internal_bkpt_check_status;
15332 ops->print_it = internal_bkpt_print_it;
15333 ops->print_mention = internal_bkpt_print_mention;
15335 /* Momentary breakpoints. */
15336 ops = &momentary_breakpoint_ops;
15337 *ops = bkpt_base_breakpoint_ops;
15338 ops->re_set = momentary_bkpt_re_set;
15339 ops->check_status = momentary_bkpt_check_status;
15340 ops->print_it = momentary_bkpt_print_it;
15341 ops->print_mention = momentary_bkpt_print_mention;
15343 /* Probe breakpoints. */
15344 ops = &bkpt_probe_breakpoint_ops;
15345 *ops = bkpt_breakpoint_ops;
15346 ops->insert_location = bkpt_probe_insert_location;
15347 ops->remove_location = bkpt_probe_remove_location;
15348 ops->create_sals_from_address = bkpt_probe_create_sals_from_address;
15349 ops->decode_linespec = bkpt_probe_decode_linespec;
15351 /* GNU v3 exception catchpoints. */
15352 ops = &gnu_v3_exception_catchpoint_ops;
15353 *ops = bkpt_breakpoint_ops;
15354 ops->print_it = print_it_exception_catchpoint;
15355 ops->print_one = print_one_exception_catchpoint;
15356 ops->print_mention = print_mention_exception_catchpoint;
15357 ops->print_recreate = print_recreate_exception_catchpoint;
15360 ops = &watchpoint_breakpoint_ops;
15361 *ops = base_breakpoint_ops;
15362 ops->dtor = dtor_watchpoint;
15363 ops->re_set = re_set_watchpoint;
15364 ops->insert_location = insert_watchpoint;
15365 ops->remove_location = remove_watchpoint;
15366 ops->breakpoint_hit = breakpoint_hit_watchpoint;
15367 ops->check_status = check_status_watchpoint;
15368 ops->resources_needed = resources_needed_watchpoint;
15369 ops->works_in_software_mode = works_in_software_mode_watchpoint;
15370 ops->print_it = print_it_watchpoint;
15371 ops->print_mention = print_mention_watchpoint;
15372 ops->print_recreate = print_recreate_watchpoint;
15374 /* Masked watchpoints. */
15375 ops = &masked_watchpoint_breakpoint_ops;
15376 *ops = watchpoint_breakpoint_ops;
15377 ops->insert_location = insert_masked_watchpoint;
15378 ops->remove_location = remove_masked_watchpoint;
15379 ops->resources_needed = resources_needed_masked_watchpoint;
15380 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
15381 ops->print_it = print_it_masked_watchpoint;
15382 ops->print_one_detail = print_one_detail_masked_watchpoint;
15383 ops->print_mention = print_mention_masked_watchpoint;
15384 ops->print_recreate = print_recreate_masked_watchpoint;
15387 ops = &tracepoint_breakpoint_ops;
15388 *ops = base_breakpoint_ops;
15389 ops->re_set = tracepoint_re_set;
15390 ops->breakpoint_hit = tracepoint_breakpoint_hit;
15391 ops->print_one_detail = tracepoint_print_one_detail;
15392 ops->print_mention = tracepoint_print_mention;
15393 ops->print_recreate = tracepoint_print_recreate;
15394 ops->create_sals_from_address = tracepoint_create_sals_from_address;
15395 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
15396 ops->decode_linespec = tracepoint_decode_linespec;
15398 /* Probe tracepoints. */
15399 ops = &tracepoint_probe_breakpoint_ops;
15400 *ops = tracepoint_breakpoint_ops;
15401 ops->create_sals_from_address = tracepoint_probe_create_sals_from_address;
15402 ops->decode_linespec = tracepoint_probe_decode_linespec;
15404 /* Static tracepoints with marker (`-m'). */
15405 ops = &strace_marker_breakpoint_ops;
15406 *ops = tracepoint_breakpoint_ops;
15407 ops->create_sals_from_address = strace_marker_create_sals_from_address;
15408 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
15409 ops->decode_linespec = strace_marker_decode_linespec;
15411 /* Fork catchpoints. */
15412 ops = &catch_fork_breakpoint_ops;
15413 *ops = base_breakpoint_ops;
15414 ops->insert_location = insert_catch_fork;
15415 ops->remove_location = remove_catch_fork;
15416 ops->breakpoint_hit = breakpoint_hit_catch_fork;
15417 ops->print_it = print_it_catch_fork;
15418 ops->print_one = print_one_catch_fork;
15419 ops->print_mention = print_mention_catch_fork;
15420 ops->print_recreate = print_recreate_catch_fork;
15422 /* Vfork catchpoints. */
15423 ops = &catch_vfork_breakpoint_ops;
15424 *ops = base_breakpoint_ops;
15425 ops->insert_location = insert_catch_vfork;
15426 ops->remove_location = remove_catch_vfork;
15427 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
15428 ops->print_it = print_it_catch_vfork;
15429 ops->print_one = print_one_catch_vfork;
15430 ops->print_mention = print_mention_catch_vfork;
15431 ops->print_recreate = print_recreate_catch_vfork;
15433 /* Exec catchpoints. */
15434 ops = &catch_exec_breakpoint_ops;
15435 *ops = base_breakpoint_ops;
15436 ops->dtor = dtor_catch_exec;
15437 ops->insert_location = insert_catch_exec;
15438 ops->remove_location = remove_catch_exec;
15439 ops->breakpoint_hit = breakpoint_hit_catch_exec;
15440 ops->print_it = print_it_catch_exec;
15441 ops->print_one = print_one_catch_exec;
15442 ops->print_mention = print_mention_catch_exec;
15443 ops->print_recreate = print_recreate_catch_exec;
15445 /* Syscall catchpoints. */
15446 ops = &catch_syscall_breakpoint_ops;
15447 *ops = base_breakpoint_ops;
15448 ops->dtor = dtor_catch_syscall;
15449 ops->insert_location = insert_catch_syscall;
15450 ops->remove_location = remove_catch_syscall;
15451 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
15452 ops->print_it = print_it_catch_syscall;
15453 ops->print_one = print_one_catch_syscall;
15454 ops->print_mention = print_mention_catch_syscall;
15455 ops->print_recreate = print_recreate_catch_syscall;
15457 /* Solib-related catchpoints. */
15458 ops = &catch_solib_breakpoint_ops;
15459 *ops = base_breakpoint_ops;
15460 ops->dtor = dtor_catch_solib;
15461 ops->insert_location = insert_catch_solib;
15462 ops->remove_location = remove_catch_solib;
15463 ops->breakpoint_hit = breakpoint_hit_catch_solib;
15464 ops->check_status = check_status_catch_solib;
15465 ops->print_it = print_it_catch_solib;
15466 ops->print_one = print_one_catch_solib;
15467 ops->print_mention = print_mention_catch_solib;
15468 ops->print_recreate = print_recreate_catch_solib;
15470 ops = &dprintf_breakpoint_ops;
15471 *ops = bkpt_base_breakpoint_ops;
15472 ops->re_set = bkpt_re_set;
15473 ops->resources_needed = bkpt_resources_needed;
15474 ops->print_it = bkpt_print_it;
15475 ops->print_mention = bkpt_print_mention;
15476 ops->print_recreate = bkpt_print_recreate;
15480 _initialize_breakpoint (void)
15482 struct cmd_list_element *c;
15484 initialize_breakpoint_ops ();
15486 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
15487 observer_attach_inferior_exit (clear_syscall_counts);
15488 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
15490 breakpoint_objfile_key
15491 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
15493 catch_syscall_inferior_data
15494 = register_inferior_data_with_cleanup (catch_syscall_inferior_data_cleanup);
15496 breakpoint_chain = 0;
15497 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15498 before a breakpoint is set. */
15499 breakpoint_count = 0;
15501 tracepoint_count = 0;
15503 add_com ("ignore", class_breakpoint, ignore_command, _("\
15504 Set ignore-count of breakpoint number N to COUNT.\n\
15505 Usage is `ignore N COUNT'."));
15507 add_com_alias ("bc", "ignore", class_breakpoint, 1);
15509 add_com ("commands", class_breakpoint, commands_command, _("\
15510 Set commands to be executed when a breakpoint is hit.\n\
15511 Give breakpoint number as argument after \"commands\".\n\
15512 With no argument, the targeted breakpoint is the last one set.\n\
15513 The commands themselves follow starting on the next line.\n\
15514 Type a line containing \"end\" to indicate the end of them.\n\
15515 Give \"silent\" as the first line to make the breakpoint silent;\n\
15516 then no output is printed when it is hit, except what the commands print."));
15518 add_com ("condition", class_breakpoint, condition_command, _("\
15519 Specify breakpoint number N to break only if COND is true.\n\
15520 Usage is `condition N COND', where N is an integer and COND is an\n\
15521 expression to be evaluated whenever breakpoint N is reached."));
15523 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
15524 Set a temporary breakpoint.\n\
15525 Like \"break\" except the breakpoint is only temporary,\n\
15526 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15527 by using \"enable delete\" on the breakpoint number.\n\
15529 BREAK_ARGS_HELP ("tbreak")));
15530 set_cmd_completer (c, location_completer);
15532 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
15533 Set a hardware assisted breakpoint.\n\
15534 Like \"break\" except the breakpoint requires hardware support,\n\
15535 some target hardware may not have this support.\n\
15537 BREAK_ARGS_HELP ("hbreak")));
15538 set_cmd_completer (c, location_completer);
15540 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
15541 Set a temporary hardware assisted breakpoint.\n\
15542 Like \"hbreak\" except the breakpoint is only temporary,\n\
15543 so it will be deleted when hit.\n\
15545 BREAK_ARGS_HELP ("thbreak")));
15546 set_cmd_completer (c, location_completer);
15548 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
15549 Enable some breakpoints.\n\
15550 Give breakpoint numbers (separated by spaces) as arguments.\n\
15551 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15552 This is used to cancel the effect of the \"disable\" command.\n\
15553 With a subcommand you can enable temporarily."),
15554 &enablelist, "enable ", 1, &cmdlist);
15556 add_com ("ab", class_breakpoint, enable_command, _("\
15557 Enable some breakpoints.\n\
15558 Give breakpoint numbers (separated by spaces) as arguments.\n\
15559 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15560 This is used to cancel the effect of the \"disable\" command.\n\
15561 With a subcommand you can enable temporarily."));
15563 add_com_alias ("en", "enable", class_breakpoint, 1);
15565 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
15566 Enable some breakpoints.\n\
15567 Give breakpoint numbers (separated by spaces) as arguments.\n\
15568 This is used to cancel the effect of the \"disable\" command.\n\
15569 May be abbreviated to simply \"enable\".\n"),
15570 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
15572 add_cmd ("once", no_class, enable_once_command, _("\
15573 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15574 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15577 add_cmd ("delete", no_class, enable_delete_command, _("\
15578 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15579 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15582 add_cmd ("count", no_class, enable_count_command, _("\
15583 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15584 If a breakpoint is hit while enabled in this fashion,\n\
15585 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15588 add_cmd ("delete", no_class, enable_delete_command, _("\
15589 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15590 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15593 add_cmd ("once", no_class, enable_once_command, _("\
15594 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15595 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15598 add_cmd ("count", no_class, enable_count_command, _("\
15599 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15600 If a breakpoint is hit while enabled in this fashion,\n\
15601 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15604 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
15605 Disable some breakpoints.\n\
15606 Arguments are breakpoint numbers with spaces in between.\n\
15607 To disable all breakpoints, give no argument.\n\
15608 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15609 &disablelist, "disable ", 1, &cmdlist);
15610 add_com_alias ("dis", "disable", class_breakpoint, 1);
15611 add_com_alias ("disa", "disable", class_breakpoint, 1);
15613 add_com ("sb", class_breakpoint, disable_command, _("\
15614 Disable some breakpoints.\n\
15615 Arguments are breakpoint numbers with spaces in between.\n\
15616 To disable all breakpoints, give no argument.\n\
15617 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
15619 add_cmd ("breakpoints", class_alias, disable_command, _("\
15620 Disable some breakpoints.\n\
15621 Arguments are breakpoint numbers with spaces in between.\n\
15622 To disable all breakpoints, give no argument.\n\
15623 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15624 This command may be abbreviated \"disable\"."),
15627 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
15628 Delete some breakpoints or auto-display expressions.\n\
15629 Arguments are breakpoint numbers with spaces in between.\n\
15630 To delete all breakpoints, give no argument.\n\
15632 Also a prefix command for deletion of other GDB objects.\n\
15633 The \"unset\" command is also an alias for \"delete\"."),
15634 &deletelist, "delete ", 1, &cmdlist);
15635 add_com_alias ("d", "delete", class_breakpoint, 1);
15636 add_com_alias ("del", "delete", class_breakpoint, 1);
15638 add_com ("db", class_breakpoint, delete_command, _("\
15639 Delete some breakpoints.\n\
15640 Arguments are breakpoint numbers with spaces in between.\n\
15641 To delete all breakpoints, give no argument.\n"));
15643 add_cmd ("breakpoints", class_alias, delete_command, _("\
15644 Delete some breakpoints or auto-display expressions.\n\
15645 Arguments are breakpoint numbers with spaces in between.\n\
15646 To delete all breakpoints, give no argument.\n\
15647 This command may be abbreviated \"delete\"."),
15650 add_com ("clear", class_breakpoint, clear_command, _("\
15651 Clear breakpoint at specified line or function.\n\
15652 Argument may be line number, function name, or \"*\" and an address.\n\
15653 If line number is specified, all breakpoints in that line are cleared.\n\
15654 If function is specified, breakpoints at beginning of function are cleared.\n\
15655 If an address is specified, breakpoints at that address are cleared.\n\
15657 With no argument, clears all breakpoints in the line that the selected frame\n\
15658 is executing in.\n\
15660 See also the \"delete\" command which clears breakpoints by number."));
15661 add_com_alias ("cl", "clear", class_breakpoint, 1);
15663 c = add_com ("break", class_breakpoint, break_command, _("\
15664 Set breakpoint at specified line or function.\n"
15665 BREAK_ARGS_HELP ("break")));
15666 set_cmd_completer (c, location_completer);
15668 add_com_alias ("b", "break", class_run, 1);
15669 add_com_alias ("br", "break", class_run, 1);
15670 add_com_alias ("bre", "break", class_run, 1);
15671 add_com_alias ("brea", "break", class_run, 1);
15674 add_com_alias ("ba", "break", class_breakpoint, 1);
15678 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
15679 Break in function/address or break at a line in the current file."),
15680 &stoplist, "stop ", 1, &cmdlist);
15681 add_cmd ("in", class_breakpoint, stopin_command,
15682 _("Break in function or address."), &stoplist);
15683 add_cmd ("at", class_breakpoint, stopat_command,
15684 _("Break at a line in the current file."), &stoplist);
15685 add_com ("status", class_info, breakpoints_info, _("\
15686 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15687 The \"Type\" column indicates one of:\n\
15688 \tbreakpoint - normal breakpoint\n\
15689 \twatchpoint - watchpoint\n\
15690 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15691 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15692 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15693 address and file/line number respectively.\n\
15695 Convenience variable \"$_\" and default examine address for \"x\"\n\
15696 are set to the address of the last breakpoint listed unless the command\n\
15697 is prefixed with \"server \".\n\n\
15698 Convenience variable \"$bpnum\" contains the number of the last\n\
15699 breakpoint set."));
15702 add_info ("breakpoints", breakpoints_info, _("\
15703 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15704 The \"Type\" column indicates one of:\n\
15705 \tbreakpoint - normal breakpoint\n\
15706 \twatchpoint - watchpoint\n\
15707 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15708 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15709 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15710 address and file/line number respectively.\n\
15712 Convenience variable \"$_\" and default examine address for \"x\"\n\
15713 are set to the address of the last breakpoint listed unless the command\n\
15714 is prefixed with \"server \".\n\n\
15715 Convenience variable \"$bpnum\" contains the number of the last\n\
15716 breakpoint set."));
15718 add_info_alias ("b", "breakpoints", 1);
15721 add_com ("lb", class_breakpoint, breakpoints_info, _("\
15722 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15723 The \"Type\" column indicates one of:\n\
15724 \tbreakpoint - normal breakpoint\n\
15725 \twatchpoint - watchpoint\n\
15726 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15727 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15728 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15729 address and file/line number respectively.\n\
15731 Convenience variable \"$_\" and default examine address for \"x\"\n\
15732 are set to the address of the last breakpoint listed unless the command\n\
15733 is prefixed with \"server \".\n\n\
15734 Convenience variable \"$bpnum\" contains the number of the last\n\
15735 breakpoint set."));
15737 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
15738 Status of all breakpoints, or breakpoint number NUMBER.\n\
15739 The \"Type\" column indicates one of:\n\
15740 \tbreakpoint - normal breakpoint\n\
15741 \twatchpoint - watchpoint\n\
15742 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15743 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15744 \tuntil - internal breakpoint used by the \"until\" command\n\
15745 \tfinish - internal breakpoint used by the \"finish\" command\n\
15746 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15747 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15748 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15749 address and file/line number respectively.\n\
15751 Convenience variable \"$_\" and default examine address for \"x\"\n\
15752 are set to the address of the last breakpoint listed unless the command\n\
15753 is prefixed with \"server \".\n\n\
15754 Convenience variable \"$bpnum\" contains the number of the last\n\
15756 &maintenanceinfolist);
15758 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
15759 Set catchpoints to catch events."),
15760 &catch_cmdlist, "catch ",
15761 0/*allow-unknown*/, &cmdlist);
15763 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
15764 Set temporary catchpoints to catch events."),
15765 &tcatch_cmdlist, "tcatch ",
15766 0/*allow-unknown*/, &cmdlist);
15768 /* Add catch and tcatch sub-commands. */
15769 add_catch_command ("catch", _("\
15770 Catch an exception, when caught."),
15771 catch_catch_command,
15775 add_catch_command ("throw", _("\
15776 Catch an exception, when thrown."),
15777 catch_throw_command,
15781 add_catch_command ("fork", _("Catch calls to fork."),
15782 catch_fork_command_1,
15784 (void *) (uintptr_t) catch_fork_permanent,
15785 (void *) (uintptr_t) catch_fork_temporary);
15786 add_catch_command ("vfork", _("Catch calls to vfork."),
15787 catch_fork_command_1,
15789 (void *) (uintptr_t) catch_vfork_permanent,
15790 (void *) (uintptr_t) catch_vfork_temporary);
15791 add_catch_command ("exec", _("Catch calls to exec."),
15792 catch_exec_command_1,
15796 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15797 Usage: catch load [REGEX]\n\
15798 If REGEX is given, only stop for libraries matching the regular expression."),
15799 catch_load_command_1,
15803 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15804 Usage: catch unload [REGEX]\n\
15805 If REGEX is given, only stop for libraries matching the regular expression."),
15806 catch_unload_command_1,
15810 add_catch_command ("syscall", _("\
15811 Catch system calls by their names and/or numbers.\n\
15812 Arguments say which system calls to catch. If no arguments\n\
15813 are given, every system call will be caught.\n\
15814 Arguments, if given, should be one or more system call names\n\
15815 (if your system supports that), or system call numbers."),
15816 catch_syscall_command_1,
15817 catch_syscall_completer,
15821 c = add_com ("watch", class_breakpoint, watch_command, _("\
15822 Set a watchpoint for an expression.\n\
15823 Usage: watch [-l|-location] EXPRESSION\n\
15824 A watchpoint stops execution of your program whenever the value of\n\
15825 an expression changes.\n\
15826 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15827 the memory to which it refers."));
15828 set_cmd_completer (c, expression_completer);
15830 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
15831 Set a read watchpoint for an expression.\n\
15832 Usage: rwatch [-l|-location] EXPRESSION\n\
15833 A watchpoint stops execution of your program whenever the value of\n\
15834 an expression is read.\n\
15835 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15836 the memory to which it refers."));
15837 set_cmd_completer (c, expression_completer);
15839 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
15840 Set a watchpoint for an expression.\n\
15841 Usage: awatch [-l|-location] EXPRESSION\n\
15842 A watchpoint stops execution of your program whenever the value of\n\
15843 an expression is either read or written.\n\
15844 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15845 the memory to which it refers."));
15846 set_cmd_completer (c, expression_completer);
15848 add_info ("watchpoints", watchpoints_info, _("\
15849 Status of specified watchpoints (all watchpoints if no argument)."));
15851 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15852 respond to changes - contrary to the description. */
15853 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
15854 &can_use_hw_watchpoints, _("\
15855 Set debugger's willingness to use watchpoint hardware."), _("\
15856 Show debugger's willingness to use watchpoint hardware."), _("\
15857 If zero, gdb will not use hardware for new watchpoints, even if\n\
15858 such is available. (However, any hardware watchpoints that were\n\
15859 created before setting this to nonzero, will continue to use watchpoint\n\
15862 show_can_use_hw_watchpoints,
15863 &setlist, &showlist);
15865 can_use_hw_watchpoints = 1;
15867 /* Tracepoint manipulation commands. */
15869 c = add_com ("trace", class_breakpoint, trace_command, _("\
15870 Set a tracepoint at specified line or function.\n\
15872 BREAK_ARGS_HELP ("trace") "\n\
15873 Do \"help tracepoints\" for info on other tracepoint commands."));
15874 set_cmd_completer (c, location_completer);
15876 add_com_alias ("tp", "trace", class_alias, 0);
15877 add_com_alias ("tr", "trace", class_alias, 1);
15878 add_com_alias ("tra", "trace", class_alias, 1);
15879 add_com_alias ("trac", "trace", class_alias, 1);
15881 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
15882 Set a fast tracepoint at specified line or function.\n\
15884 BREAK_ARGS_HELP ("ftrace") "\n\
15885 Do \"help tracepoints\" for info on other tracepoint commands."));
15886 set_cmd_completer (c, location_completer);
15888 c = add_com ("strace", class_breakpoint, strace_command, _("\
15889 Set a static tracepoint at specified line, function or marker.\n\
15891 strace [LOCATION] [if CONDITION]\n\
15892 LOCATION may be a line number, function name, \"*\" and an address,\n\
15893 or -m MARKER_ID.\n\
15894 If a line number is specified, probe the marker at start of code\n\
15895 for that line. If a function is specified, probe the marker at start\n\
15896 of code for that function. If an address is specified, probe the marker\n\
15897 at that exact address. If a marker id is specified, probe the marker\n\
15898 with that name. With no LOCATION, uses current execution address of\n\
15899 the selected stack frame.\n\
15900 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15901 This collects arbitrary user data passed in the probe point call to the\n\
15902 tracing library. You can inspect it when analyzing the trace buffer,\n\
15903 by printing the $_sdata variable like any other convenience variable.\n\
15905 CONDITION is a boolean expression.\n\
15907 Multiple tracepoints at one place are permitted, and useful if their\n\
15908 conditions are different.\n\
15910 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15911 Do \"help tracepoints\" for info on other tracepoint commands."));
15912 set_cmd_completer (c, location_completer);
15914 add_info ("tracepoints", tracepoints_info, _("\
15915 Status of specified tracepoints (all tracepoints if no argument).\n\
15916 Convenience variable \"$tpnum\" contains the number of the\n\
15917 last tracepoint set."));
15919 add_info_alias ("tp", "tracepoints", 1);
15921 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
15922 Delete specified tracepoints.\n\
15923 Arguments are tracepoint numbers, separated by spaces.\n\
15924 No argument means delete all tracepoints."),
15927 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
15928 Disable specified tracepoints.\n\
15929 Arguments are tracepoint numbers, separated by spaces.\n\
15930 No argument means disable all tracepoints."),
15932 deprecate_cmd (c, "disable");
15934 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
15935 Enable specified tracepoints.\n\
15936 Arguments are tracepoint numbers, separated by spaces.\n\
15937 No argument means enable all tracepoints."),
15939 deprecate_cmd (c, "enable");
15941 add_com ("passcount", class_trace, trace_pass_command, _("\
15942 Set the passcount for a tracepoint.\n\
15943 The trace will end when the tracepoint has been passed 'count' times.\n\
15944 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15945 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15947 add_prefix_cmd ("save", class_breakpoint, save_command,
15948 _("Save breakpoint definitions as a script."),
15949 &save_cmdlist, "save ",
15950 0/*allow-unknown*/, &cmdlist);
15952 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
15953 Save current breakpoint definitions as a script.\n\
15954 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15955 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15956 session to restore them."),
15958 set_cmd_completer (c, filename_completer);
15960 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
15961 Save current tracepoint definitions as a script.\n\
15962 Use the 'source' command in another debug session to restore them."),
15964 set_cmd_completer (c, filename_completer);
15966 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
15967 deprecate_cmd (c, "save tracepoints");
15969 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
15970 Breakpoint specific settings\n\
15971 Configure various breakpoint-specific variables such as\n\
15972 pending breakpoint behavior"),
15973 &breakpoint_set_cmdlist, "set breakpoint ",
15974 0/*allow-unknown*/, &setlist);
15975 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
15976 Breakpoint specific settings\n\
15977 Configure various breakpoint-specific variables such as\n\
15978 pending breakpoint behavior"),
15979 &breakpoint_show_cmdlist, "show breakpoint ",
15980 0/*allow-unknown*/, &showlist);
15982 add_setshow_auto_boolean_cmd ("pending", no_class,
15983 &pending_break_support, _("\
15984 Set debugger's behavior regarding pending breakpoints."), _("\
15985 Show debugger's behavior regarding pending breakpoints."), _("\
15986 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15987 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15988 an error. If auto, an unrecognized breakpoint location results in a\n\
15989 user-query to see if a pending breakpoint should be created."),
15991 show_pending_break_support,
15992 &breakpoint_set_cmdlist,
15993 &breakpoint_show_cmdlist);
15995 pending_break_support = AUTO_BOOLEAN_AUTO;
15997 add_setshow_boolean_cmd ("auto-hw", no_class,
15998 &automatic_hardware_breakpoints, _("\
15999 Set automatic usage of hardware breakpoints."), _("\
16000 Show automatic usage of hardware breakpoints."), _("\
16001 If set, the debugger will automatically use hardware breakpoints for\n\
16002 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16003 a warning will be emitted for such breakpoints."),
16005 show_automatic_hardware_breakpoints,
16006 &breakpoint_set_cmdlist,
16007 &breakpoint_show_cmdlist);
16009 add_setshow_enum_cmd ("always-inserted", class_support,
16010 always_inserted_enums, &always_inserted_mode, _("\
16011 Set mode for inserting breakpoints."), _("\
16012 Show mode for inserting breakpoints."), _("\
16013 When this mode is off, breakpoints are inserted in inferior when it is\n\
16014 resumed, and removed when execution stops. When this mode is on,\n\
16015 breakpoints are inserted immediately and removed only when the user\n\
16016 deletes the breakpoint. When this mode is auto (which is the default),\n\
16017 the behaviour depends on the non-stop setting (see help set non-stop).\n\
16018 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
16019 behaves as if always-inserted mode is on; if gdb is controlling the\n\
16020 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
16022 &show_always_inserted_mode,
16023 &breakpoint_set_cmdlist,
16024 &breakpoint_show_cmdlist);
16026 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16027 condition_evaluation_enums,
16028 &condition_evaluation_mode_1, _("\
16029 Set mode of breakpoint condition evaluation."), _("\
16030 Show mode of breakpoint condition evaluation."), _("\
16031 When this is set to \"host\", breakpoint conditions will be\n\
16032 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16033 breakpoint conditions will be downloaded to the target (if the target\n\
16034 supports such feature) and conditions will be evaluated on the target's side.\n\
16035 If this is set to \"auto\" (default), this will be automatically set to\n\
16036 \"target\" if it supports condition evaluation, otherwise it will\n\
16037 be set to \"gdb\""),
16038 &set_condition_evaluation_mode,
16039 &show_condition_evaluation_mode,
16040 &breakpoint_set_cmdlist,
16041 &breakpoint_show_cmdlist);
16043 add_com ("break-range", class_breakpoint, break_range_command, _("\
16044 Set a breakpoint for an address range.\n\
16045 break-range START-LOCATION, END-LOCATION\n\
16046 where START-LOCATION and END-LOCATION can be one of the following:\n\
16047 LINENUM, for that line in the current file,\n\
16048 FILE:LINENUM, for that line in that file,\n\
16049 +OFFSET, for that number of lines after the current line\n\
16050 or the start of the range\n\
16051 FUNCTION, for the first line in that function,\n\
16052 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16053 *ADDRESS, for the instruction at that address.\n\
16055 The breakpoint will stop execution of the inferior whenever it executes\n\
16056 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16057 range (including START-LOCATION and END-LOCATION)."));
16059 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16060 Set a dynamic printf at specified line or function.\n\
16061 dprintf location,format string,arg1,arg2,...\n\
16062 location may be a line number, function name, or \"*\" and an address.\n\
16063 If a line number is specified, break at start of code for that line.\n\
16064 If a function is specified, break at start of code for that function.\n\
16066 set_cmd_completer (c, location_completer);
16068 add_setshow_enum_cmd ("dprintf-style", class_support,
16069 dprintf_style_enums, &dprintf_style, _("\
16070 Set the style of usage for dynamic printf."), _("\
16071 Show the style of usage for dynamic printf."), _("\
16072 This setting chooses how GDB will do a dynamic printf.\n\
16073 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16074 console, as with the \"printf\" command.\n\
16075 If the value is \"call\", the print is done by calling a function in your\n\
16076 program; by default printf(), but you can choose a different function or\n\
16077 output stream by setting dprintf-function and dprintf-channel."),
16078 update_dprintf_commands, NULL,
16079 &setlist, &showlist);
16081 dprintf_function = xstrdup ("printf");
16082 add_setshow_string_cmd ("dprintf-function", class_support,
16083 &dprintf_function, _("\
16084 Set the function to use for dynamic printf"), _("\
16085 Show the function to use for dynamic printf"), NULL,
16086 update_dprintf_commands, NULL,
16087 &setlist, &showlist);
16089 dprintf_channel = xstrdup ("");
16090 add_setshow_string_cmd ("dprintf-channel", class_support,
16091 &dprintf_channel, _("\
16092 Set the channel to use for dynamic printf"), _("\
16093 Show the channel to use for dynamic printf"), NULL,
16094 update_dprintf_commands, NULL,
16095 &setlist, &showlist);
16097 automatic_hardware_breakpoints = 1;
16099 observer_attach_about_to_proceed (breakpoint_about_to_proceed);