1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2014 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"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
54 #include "exceptions.h"
60 #include "xml-syscall.h"
61 #include "parser-defs.h"
62 #include "gdb_regex.h"
64 #include "cli/cli-utils.h"
65 #include "continuations.h"
69 #include "dummy-frame.h"
73 /* readline include files */
74 #include "readline/readline.h"
75 #include "readline/history.h"
77 /* readline defines this. */
80 #include "mi/mi-common.h"
81 #include "extension.h"
83 /* Enums for exception-handling support. */
84 enum exception_event_kind
91 /* Prototypes for local functions. */
93 static void enable_delete_command (char *, int);
95 static void enable_once_command (char *, int);
97 static void enable_count_command (char *, int);
99 static void disable_command (char *, int);
101 static void enable_command (char *, int);
103 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
107 static void ignore_command (char *, int);
109 static int breakpoint_re_set_one (void *);
111 static void breakpoint_re_set_default (struct breakpoint *);
113 static void create_sals_from_address_default (char **,
114 struct linespec_result *,
118 static void create_breakpoints_sal_default (struct gdbarch *,
119 struct linespec_result *,
120 char *, char *, enum bptype,
121 enum bpdisp, int, int,
123 const struct breakpoint_ops *,
124 int, int, int, unsigned);
126 static void decode_linespec_default (struct breakpoint *, char **,
127 struct symtabs_and_lines *);
129 static void clear_command (char *, int);
131 static void catch_command (char *, int);
133 static int can_use_hardware_watchpoint (struct value *);
135 static void break_command_1 (char *, int, int);
137 static void mention (struct breakpoint *);
139 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
141 const struct breakpoint_ops *);
142 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
143 const struct symtab_and_line *);
145 /* This function is used in gdbtk sources and thus can not be made
147 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
148 struct symtab_and_line,
150 const struct breakpoint_ops *);
152 static struct breakpoint *
153 momentary_breakpoint_from_master (struct breakpoint *orig,
155 const struct breakpoint_ops *ops,
158 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
160 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
164 static void describe_other_breakpoints (struct gdbarch *,
165 struct program_space *, CORE_ADDR,
166 struct obj_section *, int);
168 static int watchpoint_locations_match (struct bp_location *loc1,
169 struct bp_location *loc2);
171 static int breakpoint_location_address_match (struct bp_location *bl,
172 struct address_space *aspace,
175 static void breakpoints_info (char *, int);
177 static void watchpoints_info (char *, int);
179 static int breakpoint_1 (char *, int,
180 int (*) (const struct breakpoint *));
182 static int breakpoint_cond_eval (void *);
184 static void cleanup_executing_breakpoints (void *);
186 static void commands_command (char *, int);
188 static void condition_command (char *, int);
197 static int remove_breakpoint (struct bp_location *, insertion_state_t);
198 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
200 static enum print_stop_action print_bp_stop_message (bpstat bs);
202 static int watchpoint_check (void *);
204 static void maintenance_info_breakpoints (char *, int);
206 static int hw_breakpoint_used_count (void);
208 static int hw_watchpoint_use_count (struct breakpoint *);
210 static int hw_watchpoint_used_count_others (struct breakpoint *except,
212 int *other_type_used);
214 static void hbreak_command (char *, int);
216 static void thbreak_command (char *, int);
218 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
221 static void stop_command (char *arg, int from_tty);
223 static void stopin_command (char *arg, int from_tty);
225 static void stopat_command (char *arg, int from_tty);
227 static void tcatch_command (char *arg, int from_tty);
229 static void detach_single_step_breakpoints (void);
231 static int find_single_step_breakpoint (struct address_space *aspace,
234 static void free_bp_location (struct bp_location *loc);
235 static void incref_bp_location (struct bp_location *loc);
236 static void decref_bp_location (struct bp_location **loc);
238 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
240 /* update_global_location_list's modes of operation wrt to whether to
241 insert locations now. */
242 enum ugll_insert_mode
244 /* Don't insert any breakpoint locations into the inferior, only
245 remove already-inserted locations that no longer should be
246 inserted. Functions that delete a breakpoint or breakpoints
247 should specify this mode, so that deleting a breakpoint doesn't
248 have the side effect of inserting the locations of other
249 breakpoints that are marked not-inserted, but should_be_inserted
250 returns true on them.
252 This behavior is useful is situations close to tear-down -- e.g.,
253 after an exec, while the target still has execution, but
254 breakpoint shadows of the previous executable image should *NOT*
255 be restored to the new image; or before detaching, where the
256 target still has execution and wants to delete breakpoints from
257 GDB's lists, and all breakpoints had already been removed from
261 /* May insert breakpoints if breakpoints_always_inserted_mode is
266 static void update_global_location_list (enum ugll_insert_mode);
268 static void update_global_location_list_nothrow (enum ugll_insert_mode);
270 static int is_hardware_watchpoint (const struct breakpoint *bpt);
272 static void insert_breakpoint_locations (void);
274 static int syscall_catchpoint_p (struct breakpoint *b);
276 static void tracepoints_info (char *, int);
278 static void delete_trace_command (char *, int);
280 static void enable_trace_command (char *, int);
282 static void disable_trace_command (char *, int);
284 static void trace_pass_command (char *, int);
286 static void set_tracepoint_count (int num);
288 static int is_masked_watchpoint (const struct breakpoint *b);
290 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
292 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
295 static int strace_marker_p (struct breakpoint *b);
297 /* The abstract base class all breakpoint_ops structures inherit
299 struct breakpoint_ops base_breakpoint_ops;
301 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
302 that are implemented on top of software or hardware breakpoints
303 (user breakpoints, internal and momentary breakpoints, etc.). */
304 static struct breakpoint_ops bkpt_base_breakpoint_ops;
306 /* Internal breakpoints class type. */
307 static struct breakpoint_ops internal_breakpoint_ops;
309 /* Momentary breakpoints class type. */
310 static struct breakpoint_ops momentary_breakpoint_ops;
312 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
313 static struct breakpoint_ops longjmp_breakpoint_ops;
315 /* The breakpoint_ops structure to be used in regular user created
317 struct breakpoint_ops bkpt_breakpoint_ops;
319 /* Breakpoints set on probes. */
320 static struct breakpoint_ops bkpt_probe_breakpoint_ops;
322 /* Dynamic printf class type. */
323 struct breakpoint_ops dprintf_breakpoint_ops;
325 /* One (or perhaps two) breakpoints used for software single
328 static void *single_step_breakpoints[2];
329 static struct gdbarch *single_step_gdbarch[2];
331 /* The style in which to perform a dynamic printf. This is a user
332 option because different output options have different tradeoffs;
333 if GDB does the printing, there is better error handling if there
334 is a problem with any of the arguments, but using an inferior
335 function lets you have special-purpose printers and sending of
336 output to the same place as compiled-in print functions. */
338 static const char dprintf_style_gdb[] = "gdb";
339 static const char dprintf_style_call[] = "call";
340 static const char dprintf_style_agent[] = "agent";
341 static const char *const dprintf_style_enums[] = {
347 static const char *dprintf_style = dprintf_style_gdb;
349 /* The function to use for dynamic printf if the preferred style is to
350 call into the inferior. The value is simply a string that is
351 copied into the command, so it can be anything that GDB can
352 evaluate to a callable address, not necessarily a function name. */
354 static char *dprintf_function = "";
356 /* The channel to use for dynamic printf if the preferred style is to
357 call into the inferior; if a nonempty string, it will be passed to
358 the call as the first argument, with the format string as the
359 second. As with the dprintf function, this can be anything that
360 GDB knows how to evaluate, so in addition to common choices like
361 "stderr", this could be an app-specific expression like
362 "mystreams[curlogger]". */
364 static char *dprintf_channel = "";
366 /* True if dprintf commands should continue to operate even if GDB
368 static int disconnected_dprintf = 1;
370 /* A reference-counted struct command_line. This lets multiple
371 breakpoints share a single command list. */
372 struct counted_command_line
374 /* The reference count. */
377 /* The command list. */
378 struct command_line *commands;
381 struct command_line *
382 breakpoint_commands (struct breakpoint *b)
384 return b->commands ? b->commands->commands : NULL;
387 /* Flag indicating that a command has proceeded the inferior past the
388 current breakpoint. */
390 static int breakpoint_proceeded;
393 bpdisp_text (enum bpdisp disp)
395 /* NOTE: the following values are a part of MI protocol and
396 represent values of 'disp' field returned when inferior stops at
398 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
400 return bpdisps[(int) disp];
403 /* Prototypes for exported functions. */
404 /* If FALSE, gdb will not use hardware support for watchpoints, even
405 if such is available. */
406 static int can_use_hw_watchpoints;
409 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
410 struct cmd_list_element *c,
413 fprintf_filtered (file,
414 _("Debugger's willingness to use "
415 "watchpoint hardware is %s.\n"),
419 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
420 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
421 for unrecognized breakpoint locations.
422 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
423 static enum auto_boolean pending_break_support;
425 show_pending_break_support (struct ui_file *file, int from_tty,
426 struct cmd_list_element *c,
429 fprintf_filtered (file,
430 _("Debugger's behavior regarding "
431 "pending breakpoints is %s.\n"),
435 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
436 set with "break" but falling in read-only memory.
437 If 0, gdb will warn about such breakpoints, but won't automatically
438 use hardware breakpoints. */
439 static int automatic_hardware_breakpoints;
441 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
442 struct cmd_list_element *c,
445 fprintf_filtered (file,
446 _("Automatic usage of hardware breakpoints is %s.\n"),
450 /* If on, gdb will keep breakpoints inserted even as inferior is
451 stopped, and immediately insert any new breakpoints. If off, gdb
452 will insert breakpoints into inferior only when resuming it, and
453 will remove breakpoints upon stop. If auto, GDB will behave as ON
454 if in non-stop mode, and as OFF if all-stop mode.*/
456 static enum auto_boolean always_inserted_mode = AUTO_BOOLEAN_AUTO;
459 show_always_inserted_mode (struct ui_file *file, int from_tty,
460 struct cmd_list_element *c, const char *value)
462 if (always_inserted_mode == AUTO_BOOLEAN_AUTO)
463 fprintf_filtered (file,
464 _("Always inserted breakpoint "
465 "mode is %s (currently %s).\n"),
467 breakpoints_always_inserted_mode () ? "on" : "off");
469 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
474 breakpoints_always_inserted_mode (void)
476 return (always_inserted_mode == AUTO_BOOLEAN_TRUE
477 || (always_inserted_mode == AUTO_BOOLEAN_AUTO && non_stop));
480 static const char condition_evaluation_both[] = "host or target";
482 /* Modes for breakpoint condition evaluation. */
483 static const char condition_evaluation_auto[] = "auto";
484 static const char condition_evaluation_host[] = "host";
485 static const char condition_evaluation_target[] = "target";
486 static const char *const condition_evaluation_enums[] = {
487 condition_evaluation_auto,
488 condition_evaluation_host,
489 condition_evaluation_target,
493 /* Global that holds the current mode for breakpoint condition evaluation. */
494 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
496 /* Global that we use to display information to the user (gets its value from
497 condition_evaluation_mode_1. */
498 static const char *condition_evaluation_mode = condition_evaluation_auto;
500 /* Translate a condition evaluation mode MODE into either "host"
501 or "target". This is used mostly to translate from "auto" to the
502 real setting that is being used. It returns the translated
506 translate_condition_evaluation_mode (const char *mode)
508 if (mode == condition_evaluation_auto)
510 if (target_supports_evaluation_of_breakpoint_conditions ())
511 return condition_evaluation_target;
513 return condition_evaluation_host;
519 /* Discovers what condition_evaluation_auto translates to. */
522 breakpoint_condition_evaluation_mode (void)
524 return translate_condition_evaluation_mode (condition_evaluation_mode);
527 /* Return true if GDB should evaluate breakpoint conditions or false
531 gdb_evaluates_breakpoint_condition_p (void)
533 const char *mode = breakpoint_condition_evaluation_mode ();
535 return (mode == condition_evaluation_host);
538 void _initialize_breakpoint (void);
540 /* Are we executing breakpoint commands? */
541 static int executing_breakpoint_commands;
543 /* Are overlay event breakpoints enabled? */
544 static int overlay_events_enabled;
546 /* See description in breakpoint.h. */
547 int target_exact_watchpoints = 0;
549 /* Walk the following statement or block through all breakpoints.
550 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
551 current breakpoint. */
553 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
555 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
556 for (B = breakpoint_chain; \
557 B ? (TMP=B->next, 1): 0; \
560 /* Similar iterator for the low-level breakpoints. SAFE variant is
561 not provided so update_global_location_list must not be called
562 while executing the block of ALL_BP_LOCATIONS. */
564 #define ALL_BP_LOCATIONS(B,BP_TMP) \
565 for (BP_TMP = bp_location; \
566 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
569 /* Iterates through locations with address ADDRESS for the currently selected
570 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
571 to where the loop should start from.
572 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
573 appropriate location to start with. */
575 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
576 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
577 BP_LOCP_TMP = BP_LOCP_START; \
579 && (BP_LOCP_TMP < bp_location + bp_location_count \
580 && (*BP_LOCP_TMP)->address == ADDRESS); \
583 /* Iterator for tracepoints only. */
585 #define ALL_TRACEPOINTS(B) \
586 for (B = breakpoint_chain; B; B = B->next) \
587 if (is_tracepoint (B))
589 /* Chains of all breakpoints defined. */
591 struct breakpoint *breakpoint_chain;
593 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
595 static struct bp_location **bp_location;
597 /* Number of elements of BP_LOCATION. */
599 static unsigned bp_location_count;
601 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
602 ADDRESS for the current elements of BP_LOCATION which get a valid
603 result from bp_location_has_shadow. You can use it for roughly
604 limiting the subrange of BP_LOCATION to scan for shadow bytes for
605 an address you need to read. */
607 static CORE_ADDR bp_location_placed_address_before_address_max;
609 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
610 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
611 BP_LOCATION which get a valid result from bp_location_has_shadow.
612 You can use it for roughly limiting the subrange of BP_LOCATION to
613 scan for shadow bytes for an address you need to read. */
615 static CORE_ADDR bp_location_shadow_len_after_address_max;
617 /* The locations that no longer correspond to any breakpoint, unlinked
618 from bp_location array, but for which a hit may still be reported
620 VEC(bp_location_p) *moribund_locations = NULL;
622 /* Number of last breakpoint made. */
624 static int breakpoint_count;
626 /* The value of `breakpoint_count' before the last command that
627 created breakpoints. If the last (break-like) command created more
628 than one breakpoint, then the difference between BREAKPOINT_COUNT
629 and PREV_BREAKPOINT_COUNT is more than one. */
630 static int prev_breakpoint_count;
632 /* Number of last tracepoint made. */
634 static int tracepoint_count;
636 static struct cmd_list_element *breakpoint_set_cmdlist;
637 static struct cmd_list_element *breakpoint_show_cmdlist;
638 struct cmd_list_element *save_cmdlist;
640 /* Return whether a breakpoint is an active enabled breakpoint. */
642 breakpoint_enabled (struct breakpoint *b)
644 return (b->enable_state == bp_enabled);
647 /* Set breakpoint count to NUM. */
650 set_breakpoint_count (int num)
652 prev_breakpoint_count = breakpoint_count;
653 breakpoint_count = num;
654 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
657 /* Used by `start_rbreak_breakpoints' below, to record the current
658 breakpoint count before "rbreak" creates any breakpoint. */
659 static int rbreak_start_breakpoint_count;
661 /* Called at the start an "rbreak" command to record the first
665 start_rbreak_breakpoints (void)
667 rbreak_start_breakpoint_count = breakpoint_count;
670 /* Called at the end of an "rbreak" command to record the last
674 end_rbreak_breakpoints (void)
676 prev_breakpoint_count = rbreak_start_breakpoint_count;
679 /* Used in run_command to zero the hit count when a new run starts. */
682 clear_breakpoint_hit_counts (void)
684 struct breakpoint *b;
690 /* Allocate a new counted_command_line with reference count of 1.
691 The new structure owns COMMANDS. */
693 static struct counted_command_line *
694 alloc_counted_command_line (struct command_line *commands)
696 struct counted_command_line *result
697 = xmalloc (sizeof (struct counted_command_line));
700 result->commands = commands;
704 /* Increment reference count. This does nothing if CMD is NULL. */
707 incref_counted_command_line (struct counted_command_line *cmd)
713 /* Decrement reference count. If the reference count reaches 0,
714 destroy the counted_command_line. Sets *CMDP to NULL. This does
715 nothing if *CMDP is NULL. */
718 decref_counted_command_line (struct counted_command_line **cmdp)
722 if (--(*cmdp)->refc == 0)
724 free_command_lines (&(*cmdp)->commands);
731 /* A cleanup function that calls decref_counted_command_line. */
734 do_cleanup_counted_command_line (void *arg)
736 decref_counted_command_line (arg);
739 /* Create a cleanup that calls decref_counted_command_line on the
742 static struct cleanup *
743 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
745 return make_cleanup (do_cleanup_counted_command_line, cmdp);
749 /* Return the breakpoint with the specified number, or NULL
750 if the number does not refer to an existing breakpoint. */
753 get_breakpoint (int num)
755 struct breakpoint *b;
758 if (b->number == num)
766 /* Mark locations as "conditions have changed" in case the target supports
767 evaluating conditions on its side. */
770 mark_breakpoint_modified (struct breakpoint *b)
772 struct bp_location *loc;
774 /* This is only meaningful if the target is
775 evaluating conditions and if the user has
776 opted for condition evaluation on the target's
778 if (gdb_evaluates_breakpoint_condition_p ()
779 || !target_supports_evaluation_of_breakpoint_conditions ())
782 if (!is_breakpoint (b))
785 for (loc = b->loc; loc; loc = loc->next)
786 loc->condition_changed = condition_modified;
789 /* Mark location as "conditions have changed" in case the target supports
790 evaluating conditions on its side. */
793 mark_breakpoint_location_modified (struct bp_location *loc)
795 /* This is only meaningful if the target is
796 evaluating conditions and if the user has
797 opted for condition evaluation on the target's
799 if (gdb_evaluates_breakpoint_condition_p ()
800 || !target_supports_evaluation_of_breakpoint_conditions ())
804 if (!is_breakpoint (loc->owner))
807 loc->condition_changed = condition_modified;
810 /* Sets the condition-evaluation mode using the static global
811 condition_evaluation_mode. */
814 set_condition_evaluation_mode (char *args, int from_tty,
815 struct cmd_list_element *c)
817 const char *old_mode, *new_mode;
819 if ((condition_evaluation_mode_1 == condition_evaluation_target)
820 && !target_supports_evaluation_of_breakpoint_conditions ())
822 condition_evaluation_mode_1 = condition_evaluation_mode;
823 warning (_("Target does not support breakpoint condition evaluation.\n"
824 "Using host evaluation mode instead."));
828 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
829 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
831 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
832 settings was "auto". */
833 condition_evaluation_mode = condition_evaluation_mode_1;
835 /* Only update the mode if the user picked a different one. */
836 if (new_mode != old_mode)
838 struct bp_location *loc, **loc_tmp;
839 /* If the user switched to a different evaluation mode, we
840 need to synch the changes with the target as follows:
842 "host" -> "target": Send all (valid) conditions to the target.
843 "target" -> "host": Remove all the conditions from the target.
846 if (new_mode == condition_evaluation_target)
848 /* Mark everything modified and synch conditions with the
850 ALL_BP_LOCATIONS (loc, loc_tmp)
851 mark_breakpoint_location_modified (loc);
855 /* Manually mark non-duplicate locations to synch conditions
856 with the target. We do this to remove all the conditions the
857 target knows about. */
858 ALL_BP_LOCATIONS (loc, loc_tmp)
859 if (is_breakpoint (loc->owner) && loc->inserted)
860 loc->needs_update = 1;
864 update_global_location_list (UGLL_MAY_INSERT);
870 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
871 what "auto" is translating to. */
874 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
875 struct cmd_list_element *c, const char *value)
877 if (condition_evaluation_mode == condition_evaluation_auto)
878 fprintf_filtered (file,
879 _("Breakpoint condition evaluation "
880 "mode is %s (currently %s).\n"),
882 breakpoint_condition_evaluation_mode ());
884 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
888 /* A comparison function for bp_location AP and BP that is used by
889 bsearch. This comparison function only cares about addresses, unlike
890 the more general bp_location_compare function. */
893 bp_location_compare_addrs (const void *ap, const void *bp)
895 struct bp_location *a = *(void **) ap;
896 struct bp_location *b = *(void **) bp;
898 if (a->address == b->address)
901 return ((a->address > b->address) - (a->address < b->address));
904 /* Helper function to skip all bp_locations with addresses
905 less than ADDRESS. It returns the first bp_location that
906 is greater than or equal to ADDRESS. If none is found, just
909 static struct bp_location **
910 get_first_locp_gte_addr (CORE_ADDR address)
912 struct bp_location dummy_loc;
913 struct bp_location *dummy_locp = &dummy_loc;
914 struct bp_location **locp_found = NULL;
916 /* Initialize the dummy location's address field. */
917 memset (&dummy_loc, 0, sizeof (struct bp_location));
918 dummy_loc.address = address;
920 /* Find a close match to the first location at ADDRESS. */
921 locp_found = bsearch (&dummy_locp, bp_location, bp_location_count,
922 sizeof (struct bp_location **),
923 bp_location_compare_addrs);
925 /* Nothing was found, nothing left to do. */
926 if (locp_found == NULL)
929 /* We may have found a location that is at ADDRESS but is not the first in the
930 location's list. Go backwards (if possible) and locate the first one. */
931 while ((locp_found - 1) >= bp_location
932 && (*(locp_found - 1))->address == address)
939 set_breakpoint_condition (struct breakpoint *b, char *exp,
942 xfree (b->cond_string);
943 b->cond_string = NULL;
945 if (is_watchpoint (b))
947 struct watchpoint *w = (struct watchpoint *) b;
954 struct bp_location *loc;
956 for (loc = b->loc; loc; loc = loc->next)
961 /* No need to free the condition agent expression
962 bytecode (if we have one). We will handle this
963 when we go through update_global_location_list. */
970 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
974 const char *arg = exp;
976 /* I don't know if it matters whether this is the string the user
977 typed in or the decompiled expression. */
978 b->cond_string = xstrdup (arg);
979 b->condition_not_parsed = 0;
981 if (is_watchpoint (b))
983 struct watchpoint *w = (struct watchpoint *) b;
985 innermost_block = NULL;
987 w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
989 error (_("Junk at end of expression"));
990 w->cond_exp_valid_block = innermost_block;
994 struct bp_location *loc;
996 for (loc = b->loc; loc; loc = loc->next)
1000 parse_exp_1 (&arg, loc->address,
1001 block_for_pc (loc->address), 0);
1003 error (_("Junk at end of expression"));
1007 mark_breakpoint_modified (b);
1009 observer_notify_breakpoint_modified (b);
1012 /* Completion for the "condition" command. */
1014 static VEC (char_ptr) *
1015 condition_completer (struct cmd_list_element *cmd,
1016 const char *text, const char *word)
1020 text = skip_spaces_const (text);
1021 space = skip_to_space_const (text);
1025 struct breakpoint *b;
1026 VEC (char_ptr) *result = NULL;
1030 /* We don't support completion of history indices. */
1031 if (isdigit (text[1]))
1033 return complete_internalvar (&text[1]);
1036 /* We're completing the breakpoint number. */
1037 len = strlen (text);
1043 xsnprintf (number, sizeof (number), "%d", b->number);
1045 if (strncmp (number, text, len) == 0)
1046 VEC_safe_push (char_ptr, result, xstrdup (number));
1052 /* We're completing the expression part. */
1053 text = skip_spaces_const (space);
1054 return expression_completer (cmd, text, word);
1057 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1060 condition_command (char *arg, int from_tty)
1062 struct breakpoint *b;
1067 error_no_arg (_("breakpoint number"));
1070 bnum = get_number (&p);
1072 error (_("Bad breakpoint argument: '%s'"), arg);
1075 if (b->number == bnum)
1077 /* Check if this breakpoint has a "stop" method implemented in an
1078 extension language. This method and conditions entered into GDB
1079 from the CLI are mutually exclusive. */
1080 const struct extension_language_defn *extlang
1081 = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE);
1083 if (extlang != NULL)
1085 error (_("Only one stop condition allowed. There is currently"
1086 " a %s stop condition defined for this breakpoint."),
1087 ext_lang_capitalized_name (extlang));
1089 set_breakpoint_condition (b, p, from_tty);
1091 if (is_breakpoint (b))
1092 update_global_location_list (UGLL_MAY_INSERT);
1097 error (_("No breakpoint number %d."), bnum);
1100 /* Check that COMMAND do not contain commands that are suitable
1101 only for tracepoints and not suitable for ordinary breakpoints.
1102 Throw if any such commands is found. */
1105 check_no_tracepoint_commands (struct command_line *commands)
1107 struct command_line *c;
1109 for (c = commands; c; c = c->next)
1113 if (c->control_type == while_stepping_control)
1114 error (_("The 'while-stepping' command can "
1115 "only be used for tracepoints"));
1117 for (i = 0; i < c->body_count; ++i)
1118 check_no_tracepoint_commands ((c->body_list)[i]);
1120 /* Not that command parsing removes leading whitespace and comment
1121 lines and also empty lines. So, we only need to check for
1122 command directly. */
1123 if (strstr (c->line, "collect ") == c->line)
1124 error (_("The 'collect' command can only be used for tracepoints"));
1126 if (strstr (c->line, "teval ") == c->line)
1127 error (_("The 'teval' command can only be used for tracepoints"));
1131 /* Encapsulate tests for different types of tracepoints. */
1134 is_tracepoint_type (enum bptype type)
1136 return (type == bp_tracepoint
1137 || type == bp_fast_tracepoint
1138 || type == bp_static_tracepoint);
1142 is_tracepoint (const struct breakpoint *b)
1144 return is_tracepoint_type (b->type);
1147 /* A helper function that validates that COMMANDS are valid for a
1148 breakpoint. This function will throw an exception if a problem is
1152 validate_commands_for_breakpoint (struct breakpoint *b,
1153 struct command_line *commands)
1155 if (is_tracepoint (b))
1157 struct tracepoint *t = (struct tracepoint *) b;
1158 struct command_line *c;
1159 struct command_line *while_stepping = 0;
1161 /* Reset the while-stepping step count. The previous commands
1162 might have included a while-stepping action, while the new
1166 /* We need to verify that each top-level element of commands is
1167 valid for tracepoints, that there's at most one
1168 while-stepping element, and that the while-stepping's body
1169 has valid tracing commands excluding nested while-stepping.
1170 We also need to validate the tracepoint action line in the
1171 context of the tracepoint --- validate_actionline actually
1172 has side effects, like setting the tracepoint's
1173 while-stepping STEP_COUNT, in addition to checking if the
1174 collect/teval actions parse and make sense in the
1175 tracepoint's context. */
1176 for (c = commands; c; c = c->next)
1178 if (c->control_type == while_stepping_control)
1180 if (b->type == bp_fast_tracepoint)
1181 error (_("The 'while-stepping' command "
1182 "cannot be used for fast tracepoint"));
1183 else if (b->type == bp_static_tracepoint)
1184 error (_("The 'while-stepping' command "
1185 "cannot be used for static tracepoint"));
1188 error (_("The 'while-stepping' command "
1189 "can be used only once"));
1194 validate_actionline (c->line, b);
1198 struct command_line *c2;
1200 gdb_assert (while_stepping->body_count == 1);
1201 c2 = while_stepping->body_list[0];
1202 for (; c2; c2 = c2->next)
1204 if (c2->control_type == while_stepping_control)
1205 error (_("The 'while-stepping' command cannot be nested"));
1211 check_no_tracepoint_commands (commands);
1215 /* Return a vector of all the static tracepoints set at ADDR. The
1216 caller is responsible for releasing the vector. */
1219 static_tracepoints_here (CORE_ADDR addr)
1221 struct breakpoint *b;
1222 VEC(breakpoint_p) *found = 0;
1223 struct bp_location *loc;
1226 if (b->type == bp_static_tracepoint)
1228 for (loc = b->loc; loc; loc = loc->next)
1229 if (loc->address == addr)
1230 VEC_safe_push(breakpoint_p, found, b);
1236 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1237 validate that only allowed commands are included. */
1240 breakpoint_set_commands (struct breakpoint *b,
1241 struct command_line *commands)
1243 validate_commands_for_breakpoint (b, commands);
1245 decref_counted_command_line (&b->commands);
1246 b->commands = alloc_counted_command_line (commands);
1247 observer_notify_breakpoint_modified (b);
1250 /* Set the internal `silent' flag on the breakpoint. Note that this
1251 is not the same as the "silent" that may appear in the breakpoint's
1255 breakpoint_set_silent (struct breakpoint *b, int silent)
1257 int old_silent = b->silent;
1260 if (old_silent != silent)
1261 observer_notify_breakpoint_modified (b);
1264 /* Set the thread for this breakpoint. If THREAD is -1, make the
1265 breakpoint work for any thread. */
1268 breakpoint_set_thread (struct breakpoint *b, int thread)
1270 int old_thread = b->thread;
1273 if (old_thread != thread)
1274 observer_notify_breakpoint_modified (b);
1277 /* Set the task for this breakpoint. If TASK is 0, make the
1278 breakpoint work for any task. */
1281 breakpoint_set_task (struct breakpoint *b, int task)
1283 int old_task = b->task;
1286 if (old_task != task)
1287 observer_notify_breakpoint_modified (b);
1291 check_tracepoint_command (char *line, void *closure)
1293 struct breakpoint *b = closure;
1295 validate_actionline (line, b);
1298 /* A structure used to pass information through
1299 map_breakpoint_numbers. */
1301 struct commands_info
1303 /* True if the command was typed at a tty. */
1306 /* The breakpoint range spec. */
1309 /* Non-NULL if the body of the commands are being read from this
1310 already-parsed command. */
1311 struct command_line *control;
1313 /* The command lines read from the user, or NULL if they have not
1315 struct counted_command_line *cmd;
1318 /* A callback for map_breakpoint_numbers that sets the commands for
1319 commands_command. */
1322 do_map_commands_command (struct breakpoint *b, void *data)
1324 struct commands_info *info = data;
1326 if (info->cmd == NULL)
1328 struct command_line *l;
1330 if (info->control != NULL)
1331 l = copy_command_lines (info->control->body_list[0]);
1334 struct cleanup *old_chain;
1337 str = xstrprintf (_("Type commands for breakpoint(s) "
1338 "%s, one per line."),
1341 old_chain = make_cleanup (xfree, str);
1343 l = read_command_lines (str,
1346 ? check_tracepoint_command : 0),
1349 do_cleanups (old_chain);
1352 info->cmd = alloc_counted_command_line (l);
1355 /* If a breakpoint was on the list more than once, we don't need to
1357 if (b->commands != info->cmd)
1359 validate_commands_for_breakpoint (b, info->cmd->commands);
1360 incref_counted_command_line (info->cmd);
1361 decref_counted_command_line (&b->commands);
1362 b->commands = info->cmd;
1363 observer_notify_breakpoint_modified (b);
1368 commands_command_1 (char *arg, int from_tty,
1369 struct command_line *control)
1371 struct cleanup *cleanups;
1372 struct commands_info info;
1374 info.from_tty = from_tty;
1375 info.control = control;
1377 /* If we read command lines from the user, then `info' will hold an
1378 extra reference to the commands that we must clean up. */
1379 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1381 if (arg == NULL || !*arg)
1383 if (breakpoint_count - prev_breakpoint_count > 1)
1384 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1386 else if (breakpoint_count > 0)
1387 arg = xstrprintf ("%d", breakpoint_count);
1390 /* So that we don't try to free the incoming non-NULL
1391 argument in the cleanup below. Mapping breakpoint
1392 numbers will fail in this case. */
1397 /* The command loop has some static state, so we need to preserve
1399 arg = xstrdup (arg);
1402 make_cleanup (xfree, arg);
1406 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1408 if (info.cmd == NULL)
1409 error (_("No breakpoints specified."));
1411 do_cleanups (cleanups);
1415 commands_command (char *arg, int from_tty)
1417 commands_command_1 (arg, from_tty, NULL);
1420 /* Like commands_command, but instead of reading the commands from
1421 input stream, takes them from an already parsed command structure.
1423 This is used by cli-script.c to DTRT with breakpoint commands
1424 that are part of if and while bodies. */
1425 enum command_control_type
1426 commands_from_control_command (char *arg, struct command_line *cmd)
1428 commands_command_1 (arg, 0, cmd);
1429 return simple_control;
1432 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1435 bp_location_has_shadow (struct bp_location *bl)
1437 if (bl->loc_type != bp_loc_software_breakpoint)
1441 if (bl->target_info.shadow_len == 0)
1442 /* BL isn't valid, or doesn't shadow memory. */
1447 /* Update BUF, which is LEN bytes read from the target address
1448 MEMADDR, by replacing a memory breakpoint with its shadowed
1451 If READBUF is not NULL, this buffer must not overlap with the of
1452 the breakpoint location's shadow_contents buffer. Otherwise, a
1453 failed assertion internal error will be raised. */
1456 one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1457 const gdb_byte *writebuf_org,
1458 ULONGEST memaddr, LONGEST len,
1459 struct bp_target_info *target_info,
1460 struct gdbarch *gdbarch)
1462 /* Now do full processing of the found relevant range of elements. */
1463 CORE_ADDR bp_addr = 0;
1467 if (!breakpoint_address_match (target_info->placed_address_space, 0,
1468 current_program_space->aspace, 0))
1470 /* The breakpoint is inserted in a different address space. */
1474 /* Addresses and length of the part of the breakpoint that
1476 bp_addr = target_info->placed_address;
1477 bp_size = target_info->shadow_len;
1479 if (bp_addr + bp_size <= memaddr)
1481 /* The breakpoint is entirely before the chunk of memory we are
1486 if (bp_addr >= memaddr + len)
1488 /* The breakpoint is entirely after the chunk of memory we are
1493 /* Offset within shadow_contents. */
1494 if (bp_addr < memaddr)
1496 /* Only copy the second part of the breakpoint. */
1497 bp_size -= memaddr - bp_addr;
1498 bptoffset = memaddr - bp_addr;
1502 if (bp_addr + bp_size > memaddr + len)
1504 /* Only copy the first part of the breakpoint. */
1505 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1508 if (readbuf != NULL)
1510 /* Verify that the readbuf buffer does not overlap with the
1511 shadow_contents buffer. */
1512 gdb_assert (target_info->shadow_contents >= readbuf + len
1513 || readbuf >= (target_info->shadow_contents
1514 + target_info->shadow_len));
1516 /* Update the read buffer with this inserted breakpoint's
1518 memcpy (readbuf + bp_addr - memaddr,
1519 target_info->shadow_contents + bptoffset, bp_size);
1523 const unsigned char *bp;
1524 CORE_ADDR placed_address = target_info->placed_address;
1525 int placed_size = target_info->placed_size;
1527 /* Update the shadow with what we want to write to memory. */
1528 memcpy (target_info->shadow_contents + bptoffset,
1529 writebuf_org + bp_addr - memaddr, bp_size);
1531 /* Determine appropriate breakpoint contents and size for this
1533 bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size);
1535 /* Update the final write buffer with this inserted
1536 breakpoint's INSN. */
1537 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1541 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1542 by replacing any memory breakpoints with their shadowed contents.
1544 If READBUF is not NULL, this buffer must not overlap with any of
1545 the breakpoint location's shadow_contents buffers. Otherwise,
1546 a failed assertion internal error will be raised.
1548 The range of shadowed area by each bp_location is:
1549 bl->address - bp_location_placed_address_before_address_max
1550 up to bl->address + bp_location_shadow_len_after_address_max
1551 The range we were requested to resolve shadows for is:
1552 memaddr ... memaddr + len
1553 Thus the safe cutoff boundaries for performance optimization are
1554 memaddr + len <= (bl->address
1555 - bp_location_placed_address_before_address_max)
1557 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1560 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1561 const gdb_byte *writebuf_org,
1562 ULONGEST memaddr, LONGEST len)
1564 /* Left boundary, right boundary and median element of our binary
1566 unsigned bc_l, bc_r, bc;
1569 /* Find BC_L which is a leftmost element which may affect BUF
1570 content. It is safe to report lower value but a failure to
1571 report higher one. */
1574 bc_r = bp_location_count;
1575 while (bc_l + 1 < bc_r)
1577 struct bp_location *bl;
1579 bc = (bc_l + bc_r) / 2;
1580 bl = bp_location[bc];
1582 /* Check first BL->ADDRESS will not overflow due to the added
1583 constant. Then advance the left boundary only if we are sure
1584 the BC element can in no way affect the BUF content (MEMADDR
1585 to MEMADDR + LEN range).
1587 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1588 offset so that we cannot miss a breakpoint with its shadow
1589 range tail still reaching MEMADDR. */
1591 if ((bl->address + bp_location_shadow_len_after_address_max
1593 && (bl->address + bp_location_shadow_len_after_address_max
1600 /* Due to the binary search above, we need to make sure we pick the
1601 first location that's at BC_L's address. E.g., if there are
1602 multiple locations at the same address, BC_L may end up pointing
1603 at a duplicate location, and miss the "master"/"inserted"
1604 location. Say, given locations L1, L2 and L3 at addresses A and
1607 L1@A, L2@A, L3@B, ...
1609 BC_L could end up pointing at location L2, while the "master"
1610 location could be L1. Since the `loc->inserted' flag is only set
1611 on "master" locations, we'd forget to restore the shadow of L1
1614 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1617 /* Now do full processing of the found relevant range of elements. */
1619 for (bc = bc_l; bc < bp_location_count; bc++)
1621 struct bp_location *bl = bp_location[bc];
1622 CORE_ADDR bp_addr = 0;
1626 /* bp_location array has BL->OWNER always non-NULL. */
1627 if (bl->owner->type == bp_none)
1628 warning (_("reading through apparently deleted breakpoint #%d?"),
1631 /* Performance optimization: any further element can no longer affect BUF
1634 if (bl->address >= bp_location_placed_address_before_address_max
1635 && memaddr + len <= (bl->address
1636 - bp_location_placed_address_before_address_max))
1639 if (!bp_location_has_shadow (bl))
1642 one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
1643 memaddr, len, &bl->target_info, bl->gdbarch);
1646 /* Now process single-step breakpoints. These are not found in the
1647 bp_location array. */
1648 for (i = 0; i < 2; i++)
1650 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
1654 struct gdbarch *gdbarch = single_step_gdbarch[i];
1656 one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
1657 memaddr, len, bp_tgt, gdbarch);
1664 /* Return true if BPT is either a software breakpoint or a hardware
1668 is_breakpoint (const struct breakpoint *bpt)
1670 return (bpt->type == bp_breakpoint
1671 || bpt->type == bp_hardware_breakpoint
1672 || bpt->type == bp_dprintf);
1675 /* Return true if BPT is of any hardware watchpoint kind. */
1678 is_hardware_watchpoint (const struct breakpoint *bpt)
1680 return (bpt->type == bp_hardware_watchpoint
1681 || bpt->type == bp_read_watchpoint
1682 || bpt->type == bp_access_watchpoint);
1685 /* Return true if BPT is of any watchpoint kind, hardware or
1689 is_watchpoint (const struct breakpoint *bpt)
1691 return (is_hardware_watchpoint (bpt)
1692 || bpt->type == bp_watchpoint);
1695 /* Returns true if the current thread and its running state are safe
1696 to evaluate or update watchpoint B. Watchpoints on local
1697 expressions need to be evaluated in the context of the thread that
1698 was current when the watchpoint was created, and, that thread needs
1699 to be stopped to be able to select the correct frame context.
1700 Watchpoints on global expressions can be evaluated on any thread,
1701 and in any state. It is presently left to the target allowing
1702 memory accesses when threads are running. */
1705 watchpoint_in_thread_scope (struct watchpoint *b)
1707 return (b->base.pspace == current_program_space
1708 && (ptid_equal (b->watchpoint_thread, null_ptid)
1709 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1710 && !is_executing (inferior_ptid))));
1713 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1714 associated bp_watchpoint_scope breakpoint. */
1717 watchpoint_del_at_next_stop (struct watchpoint *w)
1719 struct breakpoint *b = &w->base;
1721 if (b->related_breakpoint != b)
1723 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1724 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1725 b->related_breakpoint->disposition = disp_del_at_next_stop;
1726 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1727 b->related_breakpoint = b;
1729 b->disposition = disp_del_at_next_stop;
1732 /* Extract a bitfield value from value VAL using the bit parameters contained in
1735 static struct value *
1736 extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val)
1738 struct value *bit_val;
1743 bit_val = allocate_value (value_type (val));
1745 unpack_value_bitfield (bit_val,
1748 value_contents_for_printing (val),
1755 /* Assuming that B is a watchpoint:
1756 - Reparse watchpoint expression, if REPARSE is non-zero
1757 - Evaluate expression and store the result in B->val
1758 - Evaluate the condition if there is one, and store the result
1760 - Update the list of values that must be watched in B->loc.
1762 If the watchpoint disposition is disp_del_at_next_stop, then do
1763 nothing. If this is local watchpoint that is out of scope, delete
1766 Even with `set breakpoint always-inserted on' the watchpoints are
1767 removed + inserted on each stop here. Normal breakpoints must
1768 never be removed because they might be missed by a running thread
1769 when debugging in non-stop mode. On the other hand, hardware
1770 watchpoints (is_hardware_watchpoint; processed here) are specific
1771 to each LWP since they are stored in each LWP's hardware debug
1772 registers. Therefore, such LWP must be stopped first in order to
1773 be able to modify its hardware watchpoints.
1775 Hardware watchpoints must be reset exactly once after being
1776 presented to the user. It cannot be done sooner, because it would
1777 reset the data used to present the watchpoint hit to the user. And
1778 it must not be done later because it could display the same single
1779 watchpoint hit during multiple GDB stops. Note that the latter is
1780 relevant only to the hardware watchpoint types bp_read_watchpoint
1781 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1782 not user-visible - its hit is suppressed if the memory content has
1785 The following constraints influence the location where we can reset
1786 hardware watchpoints:
1788 * target_stopped_by_watchpoint and target_stopped_data_address are
1789 called several times when GDB stops.
1792 * Multiple hardware watchpoints can be hit at the same time,
1793 causing GDB to stop. GDB only presents one hardware watchpoint
1794 hit at a time as the reason for stopping, and all the other hits
1795 are presented later, one after the other, each time the user
1796 requests the execution to be resumed. Execution is not resumed
1797 for the threads still having pending hit event stored in
1798 LWP_INFO->STATUS. While the watchpoint is already removed from
1799 the inferior on the first stop the thread hit event is kept being
1800 reported from its cached value by linux_nat_stopped_data_address
1801 until the real thread resume happens after the watchpoint gets
1802 presented and thus its LWP_INFO->STATUS gets reset.
1804 Therefore the hardware watchpoint hit can get safely reset on the
1805 watchpoint removal from inferior. */
1808 update_watchpoint (struct watchpoint *b, int reparse)
1810 int within_current_scope;
1811 struct frame_id saved_frame_id;
1814 /* If this is a local watchpoint, we only want to check if the
1815 watchpoint frame is in scope if the current thread is the thread
1816 that was used to create the watchpoint. */
1817 if (!watchpoint_in_thread_scope (b))
1820 if (b->base.disposition == disp_del_at_next_stop)
1825 /* Determine if the watchpoint is within scope. */
1826 if (b->exp_valid_block == NULL)
1827 within_current_scope = 1;
1830 struct frame_info *fi = get_current_frame ();
1831 struct gdbarch *frame_arch = get_frame_arch (fi);
1832 CORE_ADDR frame_pc = get_frame_pc (fi);
1834 /* If we're in a function epilogue, unwinding may not work
1835 properly, so do not attempt to recreate locations at this
1836 point. See similar comments in watchpoint_check. */
1837 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1840 /* Save the current frame's ID so we can restore it after
1841 evaluating the watchpoint expression on its own frame. */
1842 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1843 took a frame parameter, so that we didn't have to change the
1846 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1848 fi = frame_find_by_id (b->watchpoint_frame);
1849 within_current_scope = (fi != NULL);
1850 if (within_current_scope)
1854 /* We don't free locations. They are stored in the bp_location array
1855 and update_global_location_list will eventually delete them and
1856 remove breakpoints if needed. */
1859 if (within_current_scope && reparse)
1868 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1869 b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
1870 /* If the meaning of expression itself changed, the old value is
1871 no longer relevant. We don't want to report a watchpoint hit
1872 to the user when the old value and the new value may actually
1873 be completely different objects. */
1874 value_free (b->val);
1878 /* Note that unlike with breakpoints, the watchpoint's condition
1879 expression is stored in the breakpoint object, not in the
1880 locations (re)created below. */
1881 if (b->base.cond_string != NULL)
1883 if (b->cond_exp != NULL)
1885 xfree (b->cond_exp);
1889 s = b->base.cond_string;
1890 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1894 /* If we failed to parse the expression, for example because
1895 it refers to a global variable in a not-yet-loaded shared library,
1896 don't try to insert watchpoint. We don't automatically delete
1897 such watchpoint, though, since failure to parse expression
1898 is different from out-of-scope watchpoint. */
1899 if (!target_has_execution)
1901 /* Without execution, memory can't change. No use to try and
1902 set watchpoint locations. The watchpoint will be reset when
1903 the target gains execution, through breakpoint_re_set. */
1904 if (!can_use_hw_watchpoints)
1906 if (b->base.ops->works_in_software_mode (&b->base))
1907 b->base.type = bp_watchpoint;
1909 error (_("Can't set read/access watchpoint when "
1910 "hardware watchpoints are disabled."));
1913 else if (within_current_scope && b->exp)
1916 struct value *val_chain, *v, *result, *next;
1917 struct program_space *frame_pspace;
1919 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0);
1921 /* Avoid setting b->val if it's already set. The meaning of
1922 b->val is 'the last value' user saw, and we should update
1923 it only if we reported that last value to user. As it
1924 happens, the code that reports it updates b->val directly.
1925 We don't keep track of the memory value for masked
1927 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1929 if (b->val_bitsize != 0)
1931 v = extract_bitfield_from_watchpoint_value (b, v);
1939 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1941 /* Look at each value on the value chain. */
1942 for (v = val_chain; v; v = value_next (v))
1944 /* If it's a memory location, and GDB actually needed
1945 its contents to evaluate the expression, then we
1946 must watch it. If the first value returned is
1947 still lazy, that means an error occurred reading it;
1948 watch it anyway in case it becomes readable. */
1949 if (VALUE_LVAL (v) == lval_memory
1950 && (v == val_chain || ! value_lazy (v)))
1952 struct type *vtype = check_typedef (value_type (v));
1954 /* We only watch structs and arrays if user asked
1955 for it explicitly, never if they just happen to
1956 appear in the middle of some value chain. */
1958 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1959 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1963 struct bp_location *loc, **tmp;
1964 int bitpos = 0, bitsize = 0;
1966 if (value_bitsize (v) != 0)
1968 /* Extract the bit parameters out from the bitfield
1970 bitpos = value_bitpos (v);
1971 bitsize = value_bitsize (v);
1973 else if (v == result && b->val_bitsize != 0)
1975 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1976 lvalue whose bit parameters are saved in the fields
1977 VAL_BITPOS and VAL_BITSIZE. */
1978 bitpos = b->val_bitpos;
1979 bitsize = b->val_bitsize;
1982 addr = value_address (v);
1985 /* Skip the bytes that don't contain the bitfield. */
1990 if (b->base.type == bp_read_watchpoint)
1992 else if (b->base.type == bp_access_watchpoint)
1995 loc = allocate_bp_location (&b->base);
1996 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
1999 loc->gdbarch = get_type_arch (value_type (v));
2001 loc->pspace = frame_pspace;
2002 loc->address = addr;
2006 /* Just cover the bytes that make up the bitfield. */
2007 loc->length = ((bitpos % 8) + bitsize + 7) / 8;
2010 loc->length = TYPE_LENGTH (value_type (v));
2012 loc->watchpoint_type = type;
2017 /* Change the type of breakpoint between hardware assisted or
2018 an ordinary watchpoint depending on the hardware support
2019 and free hardware slots. REPARSE is set when the inferior
2024 enum bp_loc_type loc_type;
2025 struct bp_location *bl;
2027 reg_cnt = can_use_hardware_watchpoint (val_chain);
2031 int i, target_resources_ok, other_type_used;
2034 /* Use an exact watchpoint when there's only one memory region to be
2035 watched, and only one debug register is needed to watch it. */
2036 b->exact = target_exact_watchpoints && reg_cnt == 1;
2038 /* We need to determine how many resources are already
2039 used for all other hardware watchpoints plus this one
2040 to see if we still have enough resources to also fit
2041 this watchpoint in as well. */
2043 /* If this is a software watchpoint, we try to turn it
2044 to a hardware one -- count resources as if B was of
2045 hardware watchpoint type. */
2046 type = b->base.type;
2047 if (type == bp_watchpoint)
2048 type = bp_hardware_watchpoint;
2050 /* This watchpoint may or may not have been placed on
2051 the list yet at this point (it won't be in the list
2052 if we're trying to create it for the first time,
2053 through watch_command), so always account for it
2056 /* Count resources used by all watchpoints except B. */
2057 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
2059 /* Add in the resources needed for B. */
2060 i += hw_watchpoint_use_count (&b->base);
2063 = target_can_use_hardware_watchpoint (type, i, other_type_used);
2064 if (target_resources_ok <= 0)
2066 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
2068 if (target_resources_ok == 0 && !sw_mode)
2069 error (_("Target does not support this type of "
2070 "hardware watchpoint."));
2071 else if (target_resources_ok < 0 && !sw_mode)
2072 error (_("There are not enough available hardware "
2073 "resources for this watchpoint."));
2075 /* Downgrade to software watchpoint. */
2076 b->base.type = bp_watchpoint;
2080 /* If this was a software watchpoint, we've just
2081 found we have enough resources to turn it to a
2082 hardware watchpoint. Otherwise, this is a
2084 b->base.type = type;
2087 else if (!b->base.ops->works_in_software_mode (&b->base))
2089 if (!can_use_hw_watchpoints)
2090 error (_("Can't set read/access watchpoint when "
2091 "hardware watchpoints are disabled."));
2093 error (_("Expression cannot be implemented with "
2094 "read/access watchpoint."));
2097 b->base.type = bp_watchpoint;
2099 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
2100 : bp_loc_hardware_watchpoint);
2101 for (bl = b->base.loc; bl; bl = bl->next)
2102 bl->loc_type = loc_type;
2105 for (v = val_chain; v; v = next)
2107 next = value_next (v);
2112 /* If a software watchpoint is not watching any memory, then the
2113 above left it without any location set up. But,
2114 bpstat_stop_status requires a location to be able to report
2115 stops, so make sure there's at least a dummy one. */
2116 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
2118 struct breakpoint *base = &b->base;
2119 base->loc = allocate_bp_location (base);
2120 base->loc->pspace = frame_pspace;
2121 base->loc->address = -1;
2122 base->loc->length = -1;
2123 base->loc->watchpoint_type = -1;
2126 else if (!within_current_scope)
2128 printf_filtered (_("\
2129 Watchpoint %d deleted because the program has left the block\n\
2130 in which its expression is valid.\n"),
2132 watchpoint_del_at_next_stop (b);
2135 /* Restore the selected frame. */
2137 select_frame (frame_find_by_id (saved_frame_id));
2141 /* Returns 1 iff breakpoint location should be
2142 inserted in the inferior. We don't differentiate the type of BL's owner
2143 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2144 breakpoint_ops is not defined, because in insert_bp_location,
2145 tracepoint's insert_location will not be called. */
2147 should_be_inserted (struct bp_location *bl)
2149 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
2152 if (bl->owner->disposition == disp_del_at_next_stop)
2155 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
2158 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
2161 /* This is set for example, when we're attached to the parent of a
2162 vfork, and have detached from the child. The child is running
2163 free, and we expect it to do an exec or exit, at which point the
2164 OS makes the parent schedulable again (and the target reports
2165 that the vfork is done). Until the child is done with the shared
2166 memory region, do not insert breakpoints in the parent, otherwise
2167 the child could still trip on the parent's breakpoints. Since
2168 the parent is blocked anyway, it won't miss any breakpoint. */
2169 if (bl->pspace->breakpoints_not_allowed)
2172 /* Don't insert a breakpoint if we're trying to step past its
2174 if ((bl->loc_type == bp_loc_software_breakpoint
2175 || bl->loc_type == bp_loc_hardware_breakpoint)
2176 && stepping_past_instruction_at (bl->pspace->aspace,
2183 /* Same as should_be_inserted but does the check assuming
2184 that the location is not duplicated. */
2187 unduplicated_should_be_inserted (struct bp_location *bl)
2190 const int save_duplicate = bl->duplicate;
2193 result = should_be_inserted (bl);
2194 bl->duplicate = save_duplicate;
2198 /* Parses a conditional described by an expression COND into an
2199 agent expression bytecode suitable for evaluation
2200 by the bytecode interpreter. Return NULL if there was
2201 any error during parsing. */
2203 static struct agent_expr *
2204 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2206 struct agent_expr *aexpr = NULL;
2207 volatile struct gdb_exception ex;
2212 /* We don't want to stop processing, so catch any errors
2213 that may show up. */
2214 TRY_CATCH (ex, RETURN_MASK_ERROR)
2216 aexpr = gen_eval_for_expr (scope, cond);
2221 /* If we got here, it means the condition could not be parsed to a valid
2222 bytecode expression and thus can't be evaluated on the target's side.
2223 It's no use iterating through the conditions. */
2227 /* We have a valid agent expression. */
2231 /* Based on location BL, create a list of breakpoint conditions to be
2232 passed on to the target. If we have duplicated locations with different
2233 conditions, we will add such conditions to the list. The idea is that the
2234 target will evaluate the list of conditions and will only notify GDB when
2235 one of them is true. */
2238 build_target_condition_list (struct bp_location *bl)
2240 struct bp_location **locp = NULL, **loc2p;
2241 int null_condition_or_parse_error = 0;
2242 int modified = bl->needs_update;
2243 struct bp_location *loc;
2245 /* Release conditions left over from a previous insert. */
2246 VEC_free (agent_expr_p, bl->target_info.conditions);
2248 /* This is only meaningful if the target is
2249 evaluating conditions and if the user has
2250 opted for condition evaluation on the target's
2252 if (gdb_evaluates_breakpoint_condition_p ()
2253 || !target_supports_evaluation_of_breakpoint_conditions ())
2256 /* Do a first pass to check for locations with no assigned
2257 conditions or conditions that fail to parse to a valid agent expression
2258 bytecode. If any of these happen, then it's no use to send conditions
2259 to the target since this location will always trigger and generate a
2260 response back to GDB. */
2261 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2264 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2268 struct agent_expr *aexpr;
2270 /* Re-parse the conditions since something changed. In that
2271 case we already freed the condition bytecodes (see
2272 force_breakpoint_reinsertion). We just
2273 need to parse the condition to bytecodes again. */
2274 aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2275 loc->cond_bytecode = aexpr;
2277 /* Check if we managed to parse the conditional expression
2278 correctly. If not, we will not send this condition
2284 /* If we have a NULL bytecode expression, it means something
2285 went wrong or we have a null condition expression. */
2286 if (!loc->cond_bytecode)
2288 null_condition_or_parse_error = 1;
2294 /* If any of these happened, it means we will have to evaluate the conditions
2295 for the location's address on gdb's side. It is no use keeping bytecodes
2296 for all the other duplicate locations, thus we free all of them here.
2298 This is so we have a finer control over which locations' conditions are
2299 being evaluated by GDB or the remote stub. */
2300 if (null_condition_or_parse_error)
2302 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2305 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2307 /* Only go as far as the first NULL bytecode is
2309 if (!loc->cond_bytecode)
2312 free_agent_expr (loc->cond_bytecode);
2313 loc->cond_bytecode = NULL;
2318 /* No NULL conditions or failed bytecode generation. Build a condition list
2319 for this location's address. */
2320 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2324 && is_breakpoint (loc->owner)
2325 && loc->pspace->num == bl->pspace->num
2326 && loc->owner->enable_state == bp_enabled
2328 /* Add the condition to the vector. This will be used later to send the
2329 conditions to the target. */
2330 VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2331 loc->cond_bytecode);
2337 /* Parses a command described by string CMD into an agent expression
2338 bytecode suitable for evaluation by the bytecode interpreter.
2339 Return NULL if there was any error during parsing. */
2341 static struct agent_expr *
2342 parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
2344 struct cleanup *old_cleanups = 0;
2345 struct expression *expr, **argvec;
2346 struct agent_expr *aexpr = NULL;
2347 volatile struct gdb_exception ex;
2348 const char *cmdrest;
2349 const char *format_start, *format_end;
2350 struct format_piece *fpieces;
2352 struct gdbarch *gdbarch = get_current_arch ();
2359 if (*cmdrest == ',')
2361 cmdrest = skip_spaces_const (cmdrest);
2363 if (*cmdrest++ != '"')
2364 error (_("No format string following the location"));
2366 format_start = cmdrest;
2368 fpieces = parse_format_string (&cmdrest);
2370 old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces);
2372 format_end = cmdrest;
2374 if (*cmdrest++ != '"')
2375 error (_("Bad format string, non-terminated '\"'."));
2377 cmdrest = skip_spaces_const (cmdrest);
2379 if (!(*cmdrest == ',' || *cmdrest == '\0'))
2380 error (_("Invalid argument syntax"));
2382 if (*cmdrest == ',')
2384 cmdrest = skip_spaces_const (cmdrest);
2386 /* For each argument, make an expression. */
2388 argvec = (struct expression **) alloca (strlen (cmd)
2389 * sizeof (struct expression *));
2392 while (*cmdrest != '\0')
2397 expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
2398 argvec[nargs++] = expr;
2400 if (*cmdrest == ',')
2404 /* We don't want to stop processing, so catch any errors
2405 that may show up. */
2406 TRY_CATCH (ex, RETURN_MASK_ERROR)
2408 aexpr = gen_printf (scope, gdbarch, 0, 0,
2409 format_start, format_end - format_start,
2410 fpieces, nargs, argvec);
2413 do_cleanups (old_cleanups);
2417 /* If we got here, it means the command could not be parsed to a valid
2418 bytecode expression and thus can't be evaluated on the target's side.
2419 It's no use iterating through the other commands. */
2423 /* We have a valid agent expression, return it. */
2427 /* Based on location BL, create a list of breakpoint commands to be
2428 passed on to the target. If we have duplicated locations with
2429 different commands, we will add any such to the list. */
2432 build_target_command_list (struct bp_location *bl)
2434 struct bp_location **locp = NULL, **loc2p;
2435 int null_command_or_parse_error = 0;
2436 int modified = bl->needs_update;
2437 struct bp_location *loc;
2439 /* Release commands left over from a previous insert. */
2440 VEC_free (agent_expr_p, bl->target_info.tcommands);
2442 if (!target_can_run_breakpoint_commands ())
2445 /* For now, limit to agent-style dprintf breakpoints. */
2446 if (dprintf_style != dprintf_style_agent)
2449 /* For now, if we have any duplicate location that isn't a dprintf,
2450 don't install the target-side commands, as that would make the
2451 breakpoint not be reported to the core, and we'd lose
2453 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2456 if (is_breakpoint (loc->owner)
2457 && loc->pspace->num == bl->pspace->num
2458 && loc->owner->type != bp_dprintf)
2462 /* Do a first pass to check for locations with no assigned
2463 conditions or conditions that fail to parse to a valid agent expression
2464 bytecode. If any of these happen, then it's no use to send conditions
2465 to the target since this location will always trigger and generate a
2466 response back to GDB. */
2467 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2470 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2474 struct agent_expr *aexpr;
2476 /* Re-parse the commands since something changed. In that
2477 case we already freed the command bytecodes (see
2478 force_breakpoint_reinsertion). We just
2479 need to parse the command to bytecodes again. */
2480 aexpr = parse_cmd_to_aexpr (bl->address,
2481 loc->owner->extra_string);
2482 loc->cmd_bytecode = aexpr;
2488 /* If we have a NULL bytecode expression, it means something
2489 went wrong or we have a null command expression. */
2490 if (!loc->cmd_bytecode)
2492 null_command_or_parse_error = 1;
2498 /* If anything failed, then we're not doing target-side commands,
2500 if (null_command_or_parse_error)
2502 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2505 if (is_breakpoint (loc->owner)
2506 && loc->pspace->num == bl->pspace->num)
2508 /* Only go as far as the first NULL bytecode is
2510 if (loc->cmd_bytecode == NULL)
2513 free_agent_expr (loc->cmd_bytecode);
2514 loc->cmd_bytecode = NULL;
2519 /* No NULL commands or failed bytecode generation. Build a command list
2520 for this location's address. */
2521 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2524 if (loc->owner->extra_string
2525 && is_breakpoint (loc->owner)
2526 && loc->pspace->num == bl->pspace->num
2527 && loc->owner->enable_state == bp_enabled
2529 /* Add the command to the vector. This will be used later
2530 to send the commands to the target. */
2531 VEC_safe_push (agent_expr_p, bl->target_info.tcommands,
2535 bl->target_info.persist = 0;
2536 /* Maybe flag this location as persistent. */
2537 if (bl->owner->type == bp_dprintf && disconnected_dprintf)
2538 bl->target_info.persist = 1;
2541 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2542 location. Any error messages are printed to TMP_ERROR_STREAM; and
2543 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2544 Returns 0 for success, 1 if the bp_location type is not supported or
2547 NOTE drow/2003-09-09: This routine could be broken down to an
2548 object-style method for each breakpoint or catchpoint type. */
2550 insert_bp_location (struct bp_location *bl,
2551 struct ui_file *tmp_error_stream,
2552 int *disabled_breaks,
2553 int *hw_breakpoint_error,
2554 int *hw_bp_error_explained_already)
2556 enum errors bp_err = GDB_NO_ERROR;
2557 const char *bp_err_message = NULL;
2558 volatile struct gdb_exception e;
2560 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2563 /* Note we don't initialize bl->target_info, as that wipes out
2564 the breakpoint location's shadow_contents if the breakpoint
2565 is still inserted at that location. This in turn breaks
2566 target_read_memory which depends on these buffers when
2567 a memory read is requested at the breakpoint location:
2568 Once the target_info has been wiped, we fail to see that
2569 we have a breakpoint inserted at that address and thus
2570 read the breakpoint instead of returning the data saved in
2571 the breakpoint location's shadow contents. */
2572 bl->target_info.placed_address = bl->address;
2573 bl->target_info.placed_address_space = bl->pspace->aspace;
2574 bl->target_info.length = bl->length;
2576 /* When working with target-side conditions, we must pass all the conditions
2577 for the same breakpoint address down to the target since GDB will not
2578 insert those locations. With a list of breakpoint conditions, the target
2579 can decide when to stop and notify GDB. */
2581 if (is_breakpoint (bl->owner))
2583 build_target_condition_list (bl);
2584 build_target_command_list (bl);
2585 /* Reset the modification marker. */
2586 bl->needs_update = 0;
2589 if (bl->loc_type == bp_loc_software_breakpoint
2590 || bl->loc_type == bp_loc_hardware_breakpoint)
2592 if (bl->owner->type != bp_hardware_breakpoint)
2594 /* If the explicitly specified breakpoint type
2595 is not hardware breakpoint, check the memory map to see
2596 if the breakpoint address is in read only memory or not.
2598 Two important cases are:
2599 - location type is not hardware breakpoint, memory
2600 is readonly. We change the type of the location to
2601 hardware breakpoint.
2602 - location type is hardware breakpoint, memory is
2603 read-write. This means we've previously made the
2604 location hardware one, but then the memory map changed,
2607 When breakpoints are removed, remove_breakpoints will use
2608 location types we've just set here, the only possible
2609 problem is that memory map has changed during running
2610 program, but it's not going to work anyway with current
2612 struct mem_region *mr
2613 = lookup_mem_region (bl->target_info.placed_address);
2617 if (automatic_hardware_breakpoints)
2619 enum bp_loc_type new_type;
2621 if (mr->attrib.mode != MEM_RW)
2622 new_type = bp_loc_hardware_breakpoint;
2624 new_type = bp_loc_software_breakpoint;
2626 if (new_type != bl->loc_type)
2628 static int said = 0;
2630 bl->loc_type = new_type;
2633 fprintf_filtered (gdb_stdout,
2634 _("Note: automatically using "
2635 "hardware breakpoints for "
2636 "read-only addresses.\n"));
2641 else if (bl->loc_type == bp_loc_software_breakpoint
2642 && mr->attrib.mode != MEM_RW)
2643 warning (_("cannot set software breakpoint "
2644 "at readonly address %s"),
2645 paddress (bl->gdbarch, bl->address));
2649 /* First check to see if we have to handle an overlay. */
2650 if (overlay_debugging == ovly_off
2651 || bl->section == NULL
2652 || !(section_is_overlay (bl->section)))
2654 /* No overlay handling: just set the breakpoint. */
2655 TRY_CATCH (e, RETURN_MASK_ALL)
2659 val = bl->owner->ops->insert_location (bl);
2661 bp_err = GENERIC_ERROR;
2666 bp_err_message = e.message;
2671 /* This breakpoint is in an overlay section.
2672 Shall we set a breakpoint at the LMA? */
2673 if (!overlay_events_enabled)
2675 /* Yes -- overlay event support is not active,
2676 so we must try to set a breakpoint at the LMA.
2677 This will not work for a hardware breakpoint. */
2678 if (bl->loc_type == bp_loc_hardware_breakpoint)
2679 warning (_("hardware breakpoint %d not supported in overlay!"),
2683 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2685 /* Set a software (trap) breakpoint at the LMA. */
2686 bl->overlay_target_info = bl->target_info;
2687 bl->overlay_target_info.placed_address = addr;
2689 /* No overlay handling: just set the breakpoint. */
2690 TRY_CATCH (e, RETURN_MASK_ALL)
2694 val = target_insert_breakpoint (bl->gdbarch,
2695 &bl->overlay_target_info);
2697 bp_err = GENERIC_ERROR;
2702 bp_err_message = e.message;
2705 if (bp_err != GDB_NO_ERROR)
2706 fprintf_unfiltered (tmp_error_stream,
2707 "Overlay breakpoint %d "
2708 "failed: in ROM?\n",
2712 /* Shall we set a breakpoint at the VMA? */
2713 if (section_is_mapped (bl->section))
2715 /* Yes. This overlay section is mapped into memory. */
2716 TRY_CATCH (e, RETURN_MASK_ALL)
2720 val = bl->owner->ops->insert_location (bl);
2722 bp_err = GENERIC_ERROR;
2727 bp_err_message = e.message;
2732 /* No. This breakpoint will not be inserted.
2733 No error, but do not mark the bp as 'inserted'. */
2738 if (bp_err != GDB_NO_ERROR)
2740 /* Can't set the breakpoint. */
2742 /* In some cases, we might not be able to insert a
2743 breakpoint in a shared library that has already been
2744 removed, but we have not yet processed the shlib unload
2745 event. Unfortunately, some targets that implement
2746 breakpoint insertion themselves can't tell why the
2747 breakpoint insertion failed (e.g., the remote target
2748 doesn't define error codes), so we must treat generic
2749 errors as memory errors. */
2750 if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR)
2751 && bl->loc_type == bp_loc_software_breakpoint
2752 && (solib_name_from_address (bl->pspace, bl->address)
2753 || shared_objfile_contains_address_p (bl->pspace,
2756 /* See also: disable_breakpoints_in_shlibs. */
2757 bl->shlib_disabled = 1;
2758 observer_notify_breakpoint_modified (bl->owner);
2759 if (!*disabled_breaks)
2761 fprintf_unfiltered (tmp_error_stream,
2762 "Cannot insert breakpoint %d.\n",
2764 fprintf_unfiltered (tmp_error_stream,
2765 "Temporarily disabling shared "
2766 "library breakpoints:\n");
2768 *disabled_breaks = 1;
2769 fprintf_unfiltered (tmp_error_stream,
2770 "breakpoint #%d\n", bl->owner->number);
2775 if (bl->loc_type == bp_loc_hardware_breakpoint)
2777 *hw_breakpoint_error = 1;
2778 *hw_bp_error_explained_already = bp_err_message != NULL;
2779 fprintf_unfiltered (tmp_error_stream,
2780 "Cannot insert hardware breakpoint %d%s",
2781 bl->owner->number, bp_err_message ? ":" : ".\n");
2782 if (bp_err_message != NULL)
2783 fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message);
2787 if (bp_err_message == NULL)
2790 = memory_error_message (TARGET_XFER_E_IO,
2791 bl->gdbarch, bl->address);
2792 struct cleanup *old_chain = make_cleanup (xfree, message);
2794 fprintf_unfiltered (tmp_error_stream,
2795 "Cannot insert breakpoint %d.\n"
2797 bl->owner->number, message);
2798 do_cleanups (old_chain);
2802 fprintf_unfiltered (tmp_error_stream,
2803 "Cannot insert breakpoint %d: %s\n",
2818 else if (bl->loc_type == bp_loc_hardware_watchpoint
2819 /* NOTE drow/2003-09-08: This state only exists for removing
2820 watchpoints. It's not clear that it's necessary... */
2821 && bl->owner->disposition != disp_del_at_next_stop)
2825 gdb_assert (bl->owner->ops != NULL
2826 && bl->owner->ops->insert_location != NULL);
2828 val = bl->owner->ops->insert_location (bl);
2830 /* If trying to set a read-watchpoint, and it turns out it's not
2831 supported, try emulating one with an access watchpoint. */
2832 if (val == 1 && bl->watchpoint_type == hw_read)
2834 struct bp_location *loc, **loc_temp;
2836 /* But don't try to insert it, if there's already another
2837 hw_access location that would be considered a duplicate
2839 ALL_BP_LOCATIONS (loc, loc_temp)
2841 && loc->watchpoint_type == hw_access
2842 && watchpoint_locations_match (bl, loc))
2846 bl->target_info = loc->target_info;
2847 bl->watchpoint_type = hw_access;
2854 bl->watchpoint_type = hw_access;
2855 val = bl->owner->ops->insert_location (bl);
2858 /* Back to the original value. */
2859 bl->watchpoint_type = hw_read;
2863 bl->inserted = (val == 0);
2866 else if (bl->owner->type == bp_catchpoint)
2870 gdb_assert (bl->owner->ops != NULL
2871 && bl->owner->ops->insert_location != NULL);
2873 val = bl->owner->ops->insert_location (bl);
2876 bl->owner->enable_state = bp_disabled;
2880 Error inserting catchpoint %d: Your system does not support this type\n\
2881 of catchpoint."), bl->owner->number);
2883 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2886 bl->inserted = (val == 0);
2888 /* We've already printed an error message if there was a problem
2889 inserting this catchpoint, and we've disabled the catchpoint,
2890 so just return success. */
2897 /* This function is called when program space PSPACE is about to be
2898 deleted. It takes care of updating breakpoints to not reference
2902 breakpoint_program_space_exit (struct program_space *pspace)
2904 struct breakpoint *b, *b_temp;
2905 struct bp_location *loc, **loc_temp;
2907 /* Remove any breakpoint that was set through this program space. */
2908 ALL_BREAKPOINTS_SAFE (b, b_temp)
2910 if (b->pspace == pspace)
2911 delete_breakpoint (b);
2914 /* Breakpoints set through other program spaces could have locations
2915 bound to PSPACE as well. Remove those. */
2916 ALL_BP_LOCATIONS (loc, loc_temp)
2918 struct bp_location *tmp;
2920 if (loc->pspace == pspace)
2922 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2923 if (loc->owner->loc == loc)
2924 loc->owner->loc = loc->next;
2926 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2927 if (tmp->next == loc)
2929 tmp->next = loc->next;
2935 /* Now update the global location list to permanently delete the
2936 removed locations above. */
2937 update_global_location_list (UGLL_DONT_INSERT);
2940 /* Make sure all breakpoints are inserted in inferior.
2941 Throws exception on any error.
2942 A breakpoint that is already inserted won't be inserted
2943 again, so calling this function twice is safe. */
2945 insert_breakpoints (void)
2947 struct breakpoint *bpt;
2949 ALL_BREAKPOINTS (bpt)
2950 if (is_hardware_watchpoint (bpt))
2952 struct watchpoint *w = (struct watchpoint *) bpt;
2954 update_watchpoint (w, 0 /* don't reparse. */);
2957 update_global_location_list (UGLL_MAY_INSERT);
2959 /* update_global_location_list does not insert breakpoints when
2960 always_inserted_mode is not enabled. Explicitly insert them
2962 if (!breakpoints_always_inserted_mode ())
2963 insert_breakpoint_locations ();
2966 /* Invoke CALLBACK for each of bp_location. */
2969 iterate_over_bp_locations (walk_bp_location_callback callback)
2971 struct bp_location *loc, **loc_tmp;
2973 ALL_BP_LOCATIONS (loc, loc_tmp)
2975 callback (loc, NULL);
2979 /* This is used when we need to synch breakpoint conditions between GDB and the
2980 target. It is the case with deleting and disabling of breakpoints when using
2981 always-inserted mode. */
2984 update_inserted_breakpoint_locations (void)
2986 struct bp_location *bl, **blp_tmp;
2989 int disabled_breaks = 0;
2990 int hw_breakpoint_error = 0;
2991 int hw_bp_details_reported = 0;
2993 struct ui_file *tmp_error_stream = mem_fileopen ();
2994 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2996 /* Explicitly mark the warning -- this will only be printed if
2997 there was an error. */
2998 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
3000 save_current_space_and_thread ();
3002 ALL_BP_LOCATIONS (bl, blp_tmp)
3004 /* We only want to update software breakpoints and hardware
3006 if (!is_breakpoint (bl->owner))
3009 /* We only want to update locations that are already inserted
3010 and need updating. This is to avoid unwanted insertion during
3011 deletion of breakpoints. */
3012 if (!bl->inserted || (bl->inserted && !bl->needs_update))
3015 switch_to_program_space_and_thread (bl->pspace);
3017 /* For targets that support global breakpoints, there's no need
3018 to select an inferior to insert breakpoint to. In fact, even
3019 if we aren't attached to any process yet, we should still
3020 insert breakpoints. */
3021 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3022 && ptid_equal (inferior_ptid, null_ptid))
3025 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
3026 &hw_breakpoint_error, &hw_bp_details_reported);
3033 target_terminal_ours_for_output ();
3034 error_stream (tmp_error_stream);
3037 do_cleanups (cleanups);
3040 /* Used when starting or continuing the program. */
3043 insert_breakpoint_locations (void)
3045 struct breakpoint *bpt;
3046 struct bp_location *bl, **blp_tmp;
3049 int disabled_breaks = 0;
3050 int hw_breakpoint_error = 0;
3051 int hw_bp_error_explained_already = 0;
3053 struct ui_file *tmp_error_stream = mem_fileopen ();
3054 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
3056 /* Explicitly mark the warning -- this will only be printed if
3057 there was an error. */
3058 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
3060 save_current_space_and_thread ();
3062 ALL_BP_LOCATIONS (bl, blp_tmp)
3064 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
3067 /* There is no point inserting thread-specific breakpoints if
3068 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3069 has BL->OWNER always non-NULL. */
3070 if (bl->owner->thread != -1
3071 && !valid_thread_id (bl->owner->thread))
3074 switch_to_program_space_and_thread (bl->pspace);
3076 /* For targets that support global breakpoints, there's no need
3077 to select an inferior to insert breakpoint to. In fact, even
3078 if we aren't attached to any process yet, we should still
3079 insert breakpoints. */
3080 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3081 && ptid_equal (inferior_ptid, null_ptid))
3084 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
3085 &hw_breakpoint_error, &hw_bp_error_explained_already);
3090 /* If we failed to insert all locations of a watchpoint, remove
3091 them, as half-inserted watchpoint is of limited use. */
3092 ALL_BREAKPOINTS (bpt)
3094 int some_failed = 0;
3095 struct bp_location *loc;
3097 if (!is_hardware_watchpoint (bpt))
3100 if (!breakpoint_enabled (bpt))
3103 if (bpt->disposition == disp_del_at_next_stop)
3106 for (loc = bpt->loc; loc; loc = loc->next)
3107 if (!loc->inserted && should_be_inserted (loc))
3114 for (loc = bpt->loc; loc; loc = loc->next)
3116 remove_breakpoint (loc, mark_uninserted);
3118 hw_breakpoint_error = 1;
3119 fprintf_unfiltered (tmp_error_stream,
3120 "Could not insert hardware watchpoint %d.\n",
3128 /* If a hardware breakpoint or watchpoint was inserted, add a
3129 message about possibly exhausted resources. */
3130 if (hw_breakpoint_error && !hw_bp_error_explained_already)
3132 fprintf_unfiltered (tmp_error_stream,
3133 "Could not insert hardware breakpoints:\n\
3134 You may have requested too many hardware breakpoints/watchpoints.\n");
3136 target_terminal_ours_for_output ();
3137 error_stream (tmp_error_stream);
3140 do_cleanups (cleanups);
3143 /* Used when the program stops.
3144 Returns zero if successful, or non-zero if there was a problem
3145 removing a breakpoint location. */
3148 remove_breakpoints (void)
3150 struct bp_location *bl, **blp_tmp;
3153 ALL_BP_LOCATIONS (bl, blp_tmp)
3155 if (bl->inserted && !is_tracepoint (bl->owner))
3156 val |= remove_breakpoint (bl, mark_uninserted);
3161 /* When a thread exits, remove breakpoints that are related to
3165 remove_threaded_breakpoints (struct thread_info *tp, int silent)
3167 struct breakpoint *b, *b_tmp;
3169 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3171 if (b->thread == tp->num && user_breakpoint_p (b))
3173 b->disposition = disp_del_at_next_stop;
3175 printf_filtered (_("\
3176 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3177 b->number, tp->num);
3179 /* Hide it from the user. */
3185 /* Remove breakpoints of process PID. */
3188 remove_breakpoints_pid (int pid)
3190 struct bp_location *bl, **blp_tmp;
3192 struct inferior *inf = find_inferior_pid (pid);
3194 ALL_BP_LOCATIONS (bl, blp_tmp)
3196 if (bl->pspace != inf->pspace)
3199 if (bl->owner->type == bp_dprintf)
3204 val = remove_breakpoint (bl, mark_uninserted);
3213 reattach_breakpoints (int pid)
3215 struct cleanup *old_chain;
3216 struct bp_location *bl, **blp_tmp;
3218 struct ui_file *tmp_error_stream;
3219 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
3220 struct inferior *inf;
3221 struct thread_info *tp;
3223 tp = any_live_thread_of_process (pid);
3227 inf = find_inferior_pid (pid);
3228 old_chain = save_inferior_ptid ();
3230 inferior_ptid = tp->ptid;
3232 tmp_error_stream = mem_fileopen ();
3233 make_cleanup_ui_file_delete (tmp_error_stream);
3235 ALL_BP_LOCATIONS (bl, blp_tmp)
3237 if (bl->pspace != inf->pspace)
3243 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3);
3246 do_cleanups (old_chain);
3251 do_cleanups (old_chain);
3255 static int internal_breakpoint_number = -1;
3257 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3258 If INTERNAL is non-zero, the breakpoint number will be populated
3259 from internal_breakpoint_number and that variable decremented.
3260 Otherwise the breakpoint number will be populated from
3261 breakpoint_count and that value incremented. Internal breakpoints
3262 do not set the internal var bpnum. */
3264 set_breakpoint_number (int internal, struct breakpoint *b)
3267 b->number = internal_breakpoint_number--;
3270 set_breakpoint_count (breakpoint_count + 1);
3271 b->number = breakpoint_count;
3275 static struct breakpoint *
3276 create_internal_breakpoint (struct gdbarch *gdbarch,
3277 CORE_ADDR address, enum bptype type,
3278 const struct breakpoint_ops *ops)
3280 struct symtab_and_line sal;
3281 struct breakpoint *b;
3283 init_sal (&sal); /* Initialize to zeroes. */
3286 sal.section = find_pc_overlay (sal.pc);
3287 sal.pspace = current_program_space;
3289 b = set_raw_breakpoint (gdbarch, sal, type, ops);
3290 b->number = internal_breakpoint_number--;
3291 b->disposition = disp_donttouch;
3296 static const char *const longjmp_names[] =
3298 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3300 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3302 /* Per-objfile data private to breakpoint.c. */
3303 struct breakpoint_objfile_data
3305 /* Minimal symbol for "_ovly_debug_event" (if any). */
3306 struct bound_minimal_symbol overlay_msym;
3308 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3309 struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES];
3311 /* True if we have looked for longjmp probes. */
3312 int longjmp_searched;
3314 /* SystemTap probe points for longjmp (if any). */
3315 VEC (probe_p) *longjmp_probes;
3317 /* Minimal symbol for "std::terminate()" (if any). */
3318 struct bound_minimal_symbol terminate_msym;
3320 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3321 struct bound_minimal_symbol exception_msym;
3323 /* True if we have looked for exception probes. */
3324 int exception_searched;
3326 /* SystemTap probe points for unwinding (if any). */
3327 VEC (probe_p) *exception_probes;
3330 static const struct objfile_data *breakpoint_objfile_key;
3332 /* Minimal symbol not found sentinel. */
3333 static struct minimal_symbol msym_not_found;
3335 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3338 msym_not_found_p (const struct minimal_symbol *msym)
3340 return msym == &msym_not_found;
3343 /* Return per-objfile data needed by breakpoint.c.
3344 Allocate the data if necessary. */
3346 static struct breakpoint_objfile_data *
3347 get_breakpoint_objfile_data (struct objfile *objfile)
3349 struct breakpoint_objfile_data *bp_objfile_data;
3351 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
3352 if (bp_objfile_data == NULL)
3354 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
3355 sizeof (*bp_objfile_data));
3357 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
3358 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
3360 return bp_objfile_data;
3364 free_breakpoint_probes (struct objfile *obj, void *data)
3366 struct breakpoint_objfile_data *bp_objfile_data = data;
3368 VEC_free (probe_p, bp_objfile_data->longjmp_probes);
3369 VEC_free (probe_p, bp_objfile_data->exception_probes);
3373 create_overlay_event_breakpoint (void)
3375 struct objfile *objfile;
3376 const char *const func_name = "_ovly_debug_event";
3378 ALL_OBJFILES (objfile)
3380 struct breakpoint *b;
3381 struct breakpoint_objfile_data *bp_objfile_data;
3384 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3386 if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym))
3389 if (bp_objfile_data->overlay_msym.minsym == NULL)
3391 struct bound_minimal_symbol m;
3393 m = lookup_minimal_symbol_text (func_name, objfile);
3394 if (m.minsym == NULL)
3396 /* Avoid future lookups in this objfile. */
3397 bp_objfile_data->overlay_msym.minsym = &msym_not_found;
3400 bp_objfile_data->overlay_msym = m;
3403 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
3404 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3406 &internal_breakpoint_ops);
3407 b->addr_string = xstrdup (func_name);
3409 if (overlay_debugging == ovly_auto)
3411 b->enable_state = bp_enabled;
3412 overlay_events_enabled = 1;
3416 b->enable_state = bp_disabled;
3417 overlay_events_enabled = 0;
3420 update_global_location_list (UGLL_MAY_INSERT);
3424 create_longjmp_master_breakpoint (void)
3426 struct program_space *pspace;
3427 struct cleanup *old_chain;
3429 old_chain = save_current_program_space ();
3431 ALL_PSPACES (pspace)
3433 struct objfile *objfile;
3435 set_current_program_space (pspace);
3437 ALL_OBJFILES (objfile)
3440 struct gdbarch *gdbarch;
3441 struct breakpoint_objfile_data *bp_objfile_data;
3443 gdbarch = get_objfile_arch (objfile);
3445 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3447 if (!bp_objfile_data->longjmp_searched)
3451 ret = find_probes_in_objfile (objfile, "libc", "longjmp");
3454 /* We are only interested in checking one element. */
3455 struct probe *p = VEC_index (probe_p, ret, 0);
3457 if (!can_evaluate_probe_arguments (p))
3459 /* We cannot use the probe interface here, because it does
3460 not know how to evaluate arguments. */
3461 VEC_free (probe_p, ret);
3465 bp_objfile_data->longjmp_probes = ret;
3466 bp_objfile_data->longjmp_searched = 1;
3469 if (bp_objfile_data->longjmp_probes != NULL)
3472 struct probe *probe;
3473 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3476 VEC_iterate (probe_p,
3477 bp_objfile_data->longjmp_probes,
3481 struct breakpoint *b;
3483 b = create_internal_breakpoint (gdbarch,
3484 get_probe_address (probe,
3487 &internal_breakpoint_ops);
3488 b->addr_string = xstrdup ("-probe-stap libc:longjmp");
3489 b->enable_state = bp_disabled;
3495 if (!gdbarch_get_longjmp_target_p (gdbarch))
3498 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
3500 struct breakpoint *b;
3501 const char *func_name;
3504 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
3507 func_name = longjmp_names[i];
3508 if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
3510 struct bound_minimal_symbol m;
3512 m = lookup_minimal_symbol_text (func_name, objfile);
3513 if (m.minsym == NULL)
3515 /* Prevent future lookups in this objfile. */
3516 bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found;
3519 bp_objfile_data->longjmp_msym[i] = m;
3522 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
3523 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
3524 &internal_breakpoint_ops);
3525 b->addr_string = xstrdup (func_name);
3526 b->enable_state = bp_disabled;
3530 update_global_location_list (UGLL_MAY_INSERT);
3532 do_cleanups (old_chain);
3535 /* Create a master std::terminate breakpoint. */
3537 create_std_terminate_master_breakpoint (void)
3539 struct program_space *pspace;
3540 struct cleanup *old_chain;
3541 const char *const func_name = "std::terminate()";
3543 old_chain = save_current_program_space ();
3545 ALL_PSPACES (pspace)
3547 struct objfile *objfile;
3550 set_current_program_space (pspace);
3552 ALL_OBJFILES (objfile)
3554 struct breakpoint *b;
3555 struct breakpoint_objfile_data *bp_objfile_data;
3557 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3559 if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym))
3562 if (bp_objfile_data->terminate_msym.minsym == NULL)
3564 struct bound_minimal_symbol m;
3566 m = lookup_minimal_symbol (func_name, NULL, objfile);
3567 if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text
3568 && MSYMBOL_TYPE (m.minsym) != mst_file_text))
3570 /* Prevent future lookups in this objfile. */
3571 bp_objfile_data->terminate_msym.minsym = &msym_not_found;
3574 bp_objfile_data->terminate_msym = m;
3577 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3578 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3579 bp_std_terminate_master,
3580 &internal_breakpoint_ops);
3581 b->addr_string = xstrdup (func_name);
3582 b->enable_state = bp_disabled;
3586 update_global_location_list (UGLL_MAY_INSERT);
3588 do_cleanups (old_chain);
3591 /* Install a master breakpoint on the unwinder's debug hook. */
3594 create_exception_master_breakpoint (void)
3596 struct objfile *objfile;
3597 const char *const func_name = "_Unwind_DebugHook";
3599 ALL_OBJFILES (objfile)
3601 struct breakpoint *b;
3602 struct gdbarch *gdbarch;
3603 struct breakpoint_objfile_data *bp_objfile_data;
3606 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3608 /* We prefer the SystemTap probe point if it exists. */
3609 if (!bp_objfile_data->exception_searched)
3613 ret = find_probes_in_objfile (objfile, "libgcc", "unwind");
3617 /* We are only interested in checking one element. */
3618 struct probe *p = VEC_index (probe_p, ret, 0);
3620 if (!can_evaluate_probe_arguments (p))
3622 /* We cannot use the probe interface here, because it does
3623 not know how to evaluate arguments. */
3624 VEC_free (probe_p, ret);
3628 bp_objfile_data->exception_probes = ret;
3629 bp_objfile_data->exception_searched = 1;
3632 if (bp_objfile_data->exception_probes != NULL)
3634 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3636 struct probe *probe;
3639 VEC_iterate (probe_p,
3640 bp_objfile_data->exception_probes,
3644 struct breakpoint *b;
3646 b = create_internal_breakpoint (gdbarch,
3647 get_probe_address (probe,
3649 bp_exception_master,
3650 &internal_breakpoint_ops);
3651 b->addr_string = xstrdup ("-probe-stap libgcc:unwind");
3652 b->enable_state = bp_disabled;
3658 /* Otherwise, try the hook function. */
3660 if (msym_not_found_p (bp_objfile_data->exception_msym.minsym))
3663 gdbarch = get_objfile_arch (objfile);
3665 if (bp_objfile_data->exception_msym.minsym == NULL)
3667 struct bound_minimal_symbol debug_hook;
3669 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3670 if (debug_hook.minsym == NULL)
3672 bp_objfile_data->exception_msym.minsym = &msym_not_found;
3676 bp_objfile_data->exception_msym = debug_hook;
3679 addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3680 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3682 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3683 &internal_breakpoint_ops);
3684 b->addr_string = xstrdup (func_name);
3685 b->enable_state = bp_disabled;
3688 update_global_location_list (UGLL_MAY_INSERT);
3692 update_breakpoints_after_exec (void)
3694 struct breakpoint *b, *b_tmp;
3695 struct bp_location *bploc, **bplocp_tmp;
3697 /* We're about to delete breakpoints from GDB's lists. If the
3698 INSERTED flag is true, GDB will try to lift the breakpoints by
3699 writing the breakpoints' "shadow contents" back into memory. The
3700 "shadow contents" are NOT valid after an exec, so GDB should not
3701 do that. Instead, the target is responsible from marking
3702 breakpoints out as soon as it detects an exec. We don't do that
3703 here instead, because there may be other attempts to delete
3704 breakpoints after detecting an exec and before reaching here. */
3705 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3706 if (bploc->pspace == current_program_space)
3707 gdb_assert (!bploc->inserted);
3709 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3711 if (b->pspace != current_program_space)
3714 /* Solib breakpoints must be explicitly reset after an exec(). */
3715 if (b->type == bp_shlib_event)
3717 delete_breakpoint (b);
3721 /* JIT breakpoints must be explicitly reset after an exec(). */
3722 if (b->type == bp_jit_event)
3724 delete_breakpoint (b);
3728 /* Thread event breakpoints must be set anew after an exec(),
3729 as must overlay event and longjmp master breakpoints. */
3730 if (b->type == bp_thread_event || b->type == bp_overlay_event
3731 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3732 || b->type == bp_exception_master)
3734 delete_breakpoint (b);
3738 /* Step-resume breakpoints are meaningless after an exec(). */
3739 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3741 delete_breakpoint (b);
3745 /* Longjmp and longjmp-resume breakpoints are also meaningless
3747 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3748 || b->type == bp_longjmp_call_dummy
3749 || b->type == bp_exception || b->type == bp_exception_resume)
3751 delete_breakpoint (b);
3755 if (b->type == bp_catchpoint)
3757 /* For now, none of the bp_catchpoint breakpoints need to
3758 do anything at this point. In the future, if some of
3759 the catchpoints need to something, we will need to add
3760 a new method, and call this method from here. */
3764 /* bp_finish is a special case. The only way we ought to be able
3765 to see one of these when an exec() has happened, is if the user
3766 caught a vfork, and then said "finish". Ordinarily a finish just
3767 carries them to the call-site of the current callee, by setting
3768 a temporary bp there and resuming. But in this case, the finish
3769 will carry them entirely through the vfork & exec.
3771 We don't want to allow a bp_finish to remain inserted now. But
3772 we can't safely delete it, 'cause finish_command has a handle to
3773 the bp on a bpstat, and will later want to delete it. There's a
3774 chance (and I've seen it happen) that if we delete the bp_finish
3775 here, that its storage will get reused by the time finish_command
3776 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3777 We really must allow finish_command to delete a bp_finish.
3779 In the absence of a general solution for the "how do we know
3780 it's safe to delete something others may have handles to?"
3781 problem, what we'll do here is just uninsert the bp_finish, and
3782 let finish_command delete it.
3784 (We know the bp_finish is "doomed" in the sense that it's
3785 momentary, and will be deleted as soon as finish_command sees
3786 the inferior stopped. So it doesn't matter that the bp's
3787 address is probably bogus in the new a.out, unlike e.g., the
3788 solib breakpoints.) */
3790 if (b->type == bp_finish)
3795 /* Without a symbolic address, we have little hope of the
3796 pre-exec() address meaning the same thing in the post-exec()
3798 if (b->addr_string == NULL)
3800 delete_breakpoint (b);
3804 /* FIXME what about longjmp breakpoints? Re-create them here? */
3805 create_overlay_event_breakpoint ();
3806 create_longjmp_master_breakpoint ();
3807 create_std_terminate_master_breakpoint ();
3808 create_exception_master_breakpoint ();
3812 detach_breakpoints (ptid_t ptid)
3814 struct bp_location *bl, **blp_tmp;
3816 struct cleanup *old_chain = save_inferior_ptid ();
3817 struct inferior *inf = current_inferior ();
3819 if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid))
3820 error (_("Cannot detach breakpoints of inferior_ptid"));
3822 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3823 inferior_ptid = ptid;
3824 ALL_BP_LOCATIONS (bl, blp_tmp)
3826 if (bl->pspace != inf->pspace)
3829 /* This function must physically remove breakpoints locations
3830 from the specified ptid, without modifying the breakpoint
3831 package's state. Locations of type bp_loc_other are only
3832 maintained at GDB side. So, there is no need to remove
3833 these bp_loc_other locations. Moreover, removing these
3834 would modify the breakpoint package's state. */
3835 if (bl->loc_type == bp_loc_other)
3839 val |= remove_breakpoint_1 (bl, mark_inserted);
3842 /* Detach single-step breakpoints as well. */
3843 detach_single_step_breakpoints ();
3845 do_cleanups (old_chain);
3849 /* Remove the breakpoint location BL from the current address space.
3850 Note that this is used to detach breakpoints from a child fork.
3851 When we get here, the child isn't in the inferior list, and neither
3852 do we have objects to represent its address space --- we should
3853 *not* look at bl->pspace->aspace here. */
3856 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
3860 /* BL is never in moribund_locations by our callers. */
3861 gdb_assert (bl->owner != NULL);
3863 if (bl->owner->enable_state == bp_permanent)
3864 /* Permanent breakpoints cannot be inserted or removed. */
3867 /* The type of none suggests that owner is actually deleted.
3868 This should not ever happen. */
3869 gdb_assert (bl->owner->type != bp_none);
3871 if (bl->loc_type == bp_loc_software_breakpoint
3872 || bl->loc_type == bp_loc_hardware_breakpoint)
3874 /* "Normal" instruction breakpoint: either the standard
3875 trap-instruction bp (bp_breakpoint), or a
3876 bp_hardware_breakpoint. */
3878 /* First check to see if we have to handle an overlay. */
3879 if (overlay_debugging == ovly_off
3880 || bl->section == NULL
3881 || !(section_is_overlay (bl->section)))
3883 /* No overlay handling: just remove the breakpoint. */
3885 /* If we're trying to uninsert a memory breakpoint that we
3886 know is set in a dynamic object that is marked
3887 shlib_disabled, then either the dynamic object was
3888 removed with "remove-symbol-file" or with
3889 "nosharedlibrary". In the former case, we don't know
3890 whether another dynamic object might have loaded over the
3891 breakpoint's address -- the user might well let us know
3892 about it next with add-symbol-file (the whole point of
3893 add-symbol-file is letting the user manually maintain a
3894 list of dynamically loaded objects). If we have the
3895 breakpoint's shadow memory, that is, this is a software
3896 breakpoint managed by GDB, check whether the breakpoint
3897 is still inserted in memory, to avoid overwriting wrong
3898 code with stale saved shadow contents. Note that HW
3899 breakpoints don't have shadow memory, as they're
3900 implemented using a mechanism that is not dependent on
3901 being able to modify the target's memory, and as such
3902 they should always be removed. */
3903 if (bl->shlib_disabled
3904 && bl->target_info.shadow_len != 0
3905 && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info))
3908 val = bl->owner->ops->remove_location (bl);
3912 /* This breakpoint is in an overlay section.
3913 Did we set a breakpoint at the LMA? */
3914 if (!overlay_events_enabled)
3916 /* Yes -- overlay event support is not active, so we
3917 should have set a breakpoint at the LMA. Remove it.
3919 /* Ignore any failures: if the LMA is in ROM, we will
3920 have already warned when we failed to insert it. */
3921 if (bl->loc_type == bp_loc_hardware_breakpoint)
3922 target_remove_hw_breakpoint (bl->gdbarch,
3923 &bl->overlay_target_info);
3925 target_remove_breakpoint (bl->gdbarch,
3926 &bl->overlay_target_info);
3928 /* Did we set a breakpoint at the VMA?
3929 If so, we will have marked the breakpoint 'inserted'. */
3932 /* Yes -- remove it. Previously we did not bother to
3933 remove the breakpoint if the section had been
3934 unmapped, but let's not rely on that being safe. We
3935 don't know what the overlay manager might do. */
3937 /* However, we should remove *software* breakpoints only
3938 if the section is still mapped, or else we overwrite
3939 wrong code with the saved shadow contents. */
3940 if (bl->loc_type == bp_loc_hardware_breakpoint
3941 || section_is_mapped (bl->section))
3942 val = bl->owner->ops->remove_location (bl);
3948 /* No -- not inserted, so no need to remove. No error. */
3953 /* In some cases, we might not be able to remove a breakpoint in
3954 a shared library that has already been removed, but we have
3955 not yet processed the shlib unload event. Similarly for an
3956 unloaded add-symbol-file object - the user might not yet have
3957 had the chance to remove-symbol-file it. shlib_disabled will
3958 be set if the library/object has already been removed, but
3959 the breakpoint hasn't been uninserted yet, e.g., after
3960 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3961 always-inserted mode. */
3963 && (bl->loc_type == bp_loc_software_breakpoint
3964 && (bl->shlib_disabled
3965 || solib_name_from_address (bl->pspace, bl->address)
3966 || shared_objfile_contains_address_p (bl->pspace,
3972 bl->inserted = (is == mark_inserted);
3974 else if (bl->loc_type == bp_loc_hardware_watchpoint)
3976 gdb_assert (bl->owner->ops != NULL
3977 && bl->owner->ops->remove_location != NULL);
3979 bl->inserted = (is == mark_inserted);
3980 bl->owner->ops->remove_location (bl);
3982 /* Failure to remove any of the hardware watchpoints comes here. */
3983 if ((is == mark_uninserted) && (bl->inserted))
3984 warning (_("Could not remove hardware watchpoint %d."),
3987 else if (bl->owner->type == bp_catchpoint
3988 && breakpoint_enabled (bl->owner)
3991 gdb_assert (bl->owner->ops != NULL
3992 && bl->owner->ops->remove_location != NULL);
3994 val = bl->owner->ops->remove_location (bl);
3998 bl->inserted = (is == mark_inserted);
4005 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
4008 struct cleanup *old_chain;
4010 /* BL is never in moribund_locations by our callers. */
4011 gdb_assert (bl->owner != NULL);
4013 if (bl->owner->enable_state == bp_permanent)
4014 /* Permanent breakpoints cannot be inserted or removed. */
4017 /* The type of none suggests that owner is actually deleted.
4018 This should not ever happen. */
4019 gdb_assert (bl->owner->type != bp_none);
4021 old_chain = save_current_space_and_thread ();
4023 switch_to_program_space_and_thread (bl->pspace);
4025 ret = remove_breakpoint_1 (bl, is);
4027 do_cleanups (old_chain);
4031 /* Clear the "inserted" flag in all breakpoints. */
4034 mark_breakpoints_out (void)
4036 struct bp_location *bl, **blp_tmp;
4038 ALL_BP_LOCATIONS (bl, blp_tmp)
4039 if (bl->pspace == current_program_space)
4043 /* Clear the "inserted" flag in all breakpoints and delete any
4044 breakpoints which should go away between runs of the program.
4046 Plus other such housekeeping that has to be done for breakpoints
4049 Note: this function gets called at the end of a run (by
4050 generic_mourn_inferior) and when a run begins (by
4051 init_wait_for_inferior). */
4056 breakpoint_init_inferior (enum inf_context context)
4058 struct breakpoint *b, *b_tmp;
4059 struct bp_location *bl, **blp_tmp;
4061 struct program_space *pspace = current_program_space;
4063 /* If breakpoint locations are shared across processes, then there's
4065 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4068 ALL_BP_LOCATIONS (bl, blp_tmp)
4070 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4071 if (bl->pspace == pspace
4072 && bl->owner->enable_state != bp_permanent)
4076 ALL_BREAKPOINTS_SAFE (b, b_tmp)
4078 if (b->loc && b->loc->pspace != pspace)
4084 case bp_longjmp_call_dummy:
4086 /* If the call dummy breakpoint is at the entry point it will
4087 cause problems when the inferior is rerun, so we better get
4090 case bp_watchpoint_scope:
4092 /* Also get rid of scope breakpoints. */
4094 case bp_shlib_event:
4096 /* Also remove solib event breakpoints. Their addresses may
4097 have changed since the last time we ran the program.
4098 Actually we may now be debugging against different target;
4099 and so the solib backend that installed this breakpoint may
4100 not be used in by the target. E.g.,
4102 (gdb) file prog-linux
4103 (gdb) run # native linux target
4106 (gdb) file prog-win.exe
4107 (gdb) tar rem :9999 # remote Windows gdbserver.
4110 case bp_step_resume:
4112 /* Also remove step-resume breakpoints. */
4114 delete_breakpoint (b);
4118 case bp_hardware_watchpoint:
4119 case bp_read_watchpoint:
4120 case bp_access_watchpoint:
4122 struct watchpoint *w = (struct watchpoint *) b;
4124 /* Likewise for watchpoints on local expressions. */
4125 if (w->exp_valid_block != NULL)
4126 delete_breakpoint (b);
4127 else if (context == inf_starting)
4129 /* Reset val field to force reread of starting value in
4130 insert_breakpoints. */
4132 value_free (w->val);
4143 /* Get rid of the moribund locations. */
4144 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
4145 decref_bp_location (&bl);
4146 VEC_free (bp_location_p, moribund_locations);
4149 /* These functions concern about actual breakpoints inserted in the
4150 target --- to e.g. check if we need to do decr_pc adjustment or if
4151 we need to hop over the bkpt --- so we check for address space
4152 match, not program space. */
4154 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4155 exists at PC. It returns ordinary_breakpoint_here if it's an
4156 ordinary breakpoint, or permanent_breakpoint_here if it's a
4157 permanent breakpoint.
4158 - When continuing from a location with an ordinary breakpoint, we
4159 actually single step once before calling insert_breakpoints.
4160 - When continuing from a location with a permanent breakpoint, we
4161 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4162 the target, to advance the PC past the breakpoint. */
4164 enum breakpoint_here
4165 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
4167 struct bp_location *bl, **blp_tmp;
4168 int any_breakpoint_here = 0;
4170 ALL_BP_LOCATIONS (bl, blp_tmp)
4172 if (bl->loc_type != bp_loc_software_breakpoint
4173 && bl->loc_type != bp_loc_hardware_breakpoint)
4176 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4177 if ((breakpoint_enabled (bl->owner)
4178 || bl->owner->enable_state == bp_permanent)
4179 && breakpoint_location_address_match (bl, aspace, pc))
4181 if (overlay_debugging
4182 && section_is_overlay (bl->section)
4183 && !section_is_mapped (bl->section))
4184 continue; /* unmapped overlay -- can't be a match */
4185 else if (bl->owner->enable_state == bp_permanent)
4186 return permanent_breakpoint_here;
4188 any_breakpoint_here = 1;
4192 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
4195 /* Return true if there's a moribund breakpoint at PC. */
4198 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
4200 struct bp_location *loc;
4203 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4204 if (breakpoint_location_address_match (loc, aspace, pc))
4210 /* Returns non-zero if there's a breakpoint inserted at PC, which is
4211 inserted using regular breakpoint_chain / bp_location array
4212 mechanism. This does not check for single-step breakpoints, which
4213 are inserted and removed using direct target manipulation. */
4216 regular_breakpoint_inserted_here_p (struct address_space *aspace,
4219 struct bp_location *bl, **blp_tmp;
4221 ALL_BP_LOCATIONS (bl, blp_tmp)
4223 if (bl->loc_type != bp_loc_software_breakpoint
4224 && bl->loc_type != bp_loc_hardware_breakpoint)
4228 && breakpoint_location_address_match (bl, aspace, pc))
4230 if (overlay_debugging
4231 && section_is_overlay (bl->section)
4232 && !section_is_mapped (bl->section))
4233 continue; /* unmapped overlay -- can't be a match */
4241 /* Returns non-zero iff there's either regular breakpoint
4242 or a single step breakpoint inserted at PC. */
4245 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
4247 if (regular_breakpoint_inserted_here_p (aspace, pc))
4250 if (single_step_breakpoint_inserted_here_p (aspace, pc))
4256 /* Ignoring deprecated raw breakpoints, return non-zero iff there is a
4257 software breakpoint inserted at PC. */
4259 static struct bp_location *
4260 find_non_raw_software_breakpoint_inserted_here (struct address_space *aspace,
4263 struct bp_location *bl, **blp_tmp;
4265 ALL_BP_LOCATIONS (bl, blp_tmp)
4267 if (bl->loc_type != bp_loc_software_breakpoint)
4271 && breakpoint_address_match (bl->pspace->aspace, bl->address,
4274 if (overlay_debugging
4275 && section_is_overlay (bl->section)
4276 && !section_is_mapped (bl->section))
4277 continue; /* unmapped overlay -- can't be a match */
4286 /* This function returns non-zero iff there is a software breakpoint
4290 software_breakpoint_inserted_here_p (struct address_space *aspace,
4293 if (find_non_raw_software_breakpoint_inserted_here (aspace, pc) != NULL)
4296 /* Also check for software single-step breakpoints. */
4297 if (single_step_breakpoint_inserted_here_p (aspace, pc))
4304 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
4305 CORE_ADDR addr, ULONGEST len)
4307 struct breakpoint *bpt;
4309 ALL_BREAKPOINTS (bpt)
4311 struct bp_location *loc;
4313 if (bpt->type != bp_hardware_watchpoint
4314 && bpt->type != bp_access_watchpoint)
4317 if (!breakpoint_enabled (bpt))
4320 for (loc = bpt->loc; loc; loc = loc->next)
4321 if (loc->pspace->aspace == aspace && loc->inserted)
4325 /* Check for intersection. */
4326 l = max (loc->address, addr);
4327 h = min (loc->address + loc->length, addr + len);
4335 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
4336 PC is valid for process/thread PTID. */
4339 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
4342 struct bp_location *bl, **blp_tmp;
4343 /* The thread and task IDs associated to PTID, computed lazily. */
4347 ALL_BP_LOCATIONS (bl, blp_tmp)
4349 if (bl->loc_type != bp_loc_software_breakpoint
4350 && bl->loc_type != bp_loc_hardware_breakpoint)
4353 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
4354 if (!breakpoint_enabled (bl->owner)
4355 && bl->owner->enable_state != bp_permanent)
4358 if (!breakpoint_location_address_match (bl, aspace, pc))
4361 if (bl->owner->thread != -1)
4363 /* This is a thread-specific breakpoint. Check that ptid
4364 matches that thread. If thread hasn't been computed yet,
4365 it is now time to do so. */
4367 thread = pid_to_thread_id (ptid);
4368 if (bl->owner->thread != thread)
4372 if (bl->owner->task != 0)
4374 /* This is a task-specific breakpoint. Check that ptid
4375 matches that task. If task hasn't been computed yet,
4376 it is now time to do so. */
4378 task = ada_get_task_number (ptid);
4379 if (bl->owner->task != task)
4383 if (overlay_debugging
4384 && section_is_overlay (bl->section)
4385 && !section_is_mapped (bl->section))
4386 continue; /* unmapped overlay -- can't be a match */
4395 /* bpstat stuff. External routines' interfaces are documented
4399 is_catchpoint (struct breakpoint *ep)
4401 return (ep->type == bp_catchpoint);
4404 /* Frees any storage that is part of a bpstat. Does not walk the
4408 bpstat_free (bpstat bs)
4410 if (bs->old_val != NULL)
4411 value_free (bs->old_val);
4412 decref_counted_command_line (&bs->commands);
4413 decref_bp_location (&bs->bp_location_at);
4417 /* Clear a bpstat so that it says we are not at any breakpoint.
4418 Also free any storage that is part of a bpstat. */
4421 bpstat_clear (bpstat *bsp)
4438 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4439 is part of the bpstat is copied as well. */
4442 bpstat_copy (bpstat bs)
4446 bpstat retval = NULL;
4451 for (; bs != NULL; bs = bs->next)
4453 tmp = (bpstat) xmalloc (sizeof (*tmp));
4454 memcpy (tmp, bs, sizeof (*tmp));
4455 incref_counted_command_line (tmp->commands);
4456 incref_bp_location (tmp->bp_location_at);
4457 if (bs->old_val != NULL)
4459 tmp->old_val = value_copy (bs->old_val);
4460 release_value (tmp->old_val);
4464 /* This is the first thing in the chain. */
4474 /* Find the bpstat associated with this breakpoint. */
4477 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
4482 for (; bsp != NULL; bsp = bsp->next)
4484 if (bsp->breakpoint_at == breakpoint)
4490 /* See breakpoint.h. */
4493 bpstat_explains_signal (bpstat bsp, enum gdb_signal sig)
4495 for (; bsp != NULL; bsp = bsp->next)
4497 if (bsp->breakpoint_at == NULL)
4499 /* A moribund location can never explain a signal other than
4501 if (sig == GDB_SIGNAL_TRAP)
4506 if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at,
4515 /* Put in *NUM the breakpoint number of the first breakpoint we are
4516 stopped at. *BSP upon return is a bpstat which points to the
4517 remaining breakpoints stopped at (but which is not guaranteed to be
4518 good for anything but further calls to bpstat_num).
4520 Return 0 if passed a bpstat which does not indicate any breakpoints.
4521 Return -1 if stopped at a breakpoint that has been deleted since
4523 Return 1 otherwise. */
4526 bpstat_num (bpstat *bsp, int *num)
4528 struct breakpoint *b;
4531 return 0; /* No more breakpoint values */
4533 /* We assume we'll never have several bpstats that correspond to a
4534 single breakpoint -- otherwise, this function might return the
4535 same number more than once and this will look ugly. */
4536 b = (*bsp)->breakpoint_at;
4537 *bsp = (*bsp)->next;
4539 return -1; /* breakpoint that's been deleted since */
4541 *num = b->number; /* We have its number */
4545 /* See breakpoint.h. */
4548 bpstat_clear_actions (void)
4550 struct thread_info *tp;
4553 if (ptid_equal (inferior_ptid, null_ptid))
4556 tp = find_thread_ptid (inferior_ptid);
4560 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
4562 decref_counted_command_line (&bs->commands);
4564 if (bs->old_val != NULL)
4566 value_free (bs->old_val);
4572 /* Called when a command is about to proceed the inferior. */
4575 breakpoint_about_to_proceed (void)
4577 if (!ptid_equal (inferior_ptid, null_ptid))
4579 struct thread_info *tp = inferior_thread ();
4581 /* Allow inferior function calls in breakpoint commands to not
4582 interrupt the command list. When the call finishes
4583 successfully, the inferior will be standing at the same
4584 breakpoint as if nothing happened. */
4585 if (tp->control.in_infcall)
4589 breakpoint_proceeded = 1;
4592 /* Stub for cleaning up our state if we error-out of a breakpoint
4595 cleanup_executing_breakpoints (void *ignore)
4597 executing_breakpoint_commands = 0;
4600 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4601 or its equivalent. */
4604 command_line_is_silent (struct command_line *cmd)
4606 return cmd && (strcmp ("silent", cmd->line) == 0
4607 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
4610 /* Execute all the commands associated with all the breakpoints at
4611 this location. Any of these commands could cause the process to
4612 proceed beyond this point, etc. We look out for such changes by
4613 checking the global "breakpoint_proceeded" after each command.
4615 Returns true if a breakpoint command resumed the inferior. In that
4616 case, it is the caller's responsibility to recall it again with the
4617 bpstat of the current thread. */
4620 bpstat_do_actions_1 (bpstat *bsp)
4623 struct cleanup *old_chain;
4626 /* Avoid endless recursion if a `source' command is contained
4628 if (executing_breakpoint_commands)
4631 executing_breakpoint_commands = 1;
4632 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
4634 prevent_dont_repeat ();
4636 /* This pointer will iterate over the list of bpstat's. */
4639 breakpoint_proceeded = 0;
4640 for (; bs != NULL; bs = bs->next)
4642 struct counted_command_line *ccmd;
4643 struct command_line *cmd;
4644 struct cleanup *this_cmd_tree_chain;
4646 /* Take ownership of the BSP's command tree, if it has one.
4648 The command tree could legitimately contain commands like
4649 'step' and 'next', which call clear_proceed_status, which
4650 frees stop_bpstat's command tree. To make sure this doesn't
4651 free the tree we're executing out from under us, we need to
4652 take ownership of the tree ourselves. Since a given bpstat's
4653 commands are only executed once, we don't need to copy it; we
4654 can clear the pointer in the bpstat, and make sure we free
4655 the tree when we're done. */
4656 ccmd = bs->commands;
4657 bs->commands = NULL;
4658 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
4659 cmd = ccmd ? ccmd->commands : NULL;
4660 if (command_line_is_silent (cmd))
4662 /* The action has been already done by bpstat_stop_status. */
4668 execute_control_command (cmd);
4670 if (breakpoint_proceeded)
4676 /* We can free this command tree now. */
4677 do_cleanups (this_cmd_tree_chain);
4679 if (breakpoint_proceeded)
4681 if (target_can_async_p ())
4682 /* If we are in async mode, then the target might be still
4683 running, not stopped at any breakpoint, so nothing for
4684 us to do here -- just return to the event loop. */
4687 /* In sync mode, when execute_control_command returns
4688 we're already standing on the next breakpoint.
4689 Breakpoint commands for that stop were not run, since
4690 execute_command does not run breakpoint commands --
4691 only command_line_handler does, but that one is not
4692 involved in execution of breakpoint commands. So, we
4693 can now execute breakpoint commands. It should be
4694 noted that making execute_command do bpstat actions is
4695 not an option -- in this case we'll have recursive
4696 invocation of bpstat for each breakpoint with a
4697 command, and can easily blow up GDB stack. Instead, we
4698 return true, which will trigger the caller to recall us
4699 with the new stop_bpstat. */
4704 do_cleanups (old_chain);
4709 bpstat_do_actions (void)
4711 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4713 /* Do any commands attached to breakpoint we are stopped at. */
4714 while (!ptid_equal (inferior_ptid, null_ptid)
4715 && target_has_execution
4716 && !is_exited (inferior_ptid)
4717 && !is_executing (inferior_ptid))
4718 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4719 and only return when it is stopped at the next breakpoint, we
4720 keep doing breakpoint actions until it returns false to
4721 indicate the inferior was not resumed. */
4722 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
4725 discard_cleanups (cleanup_if_error);
4728 /* Print out the (old or new) value associated with a watchpoint. */
4731 watchpoint_value_print (struct value *val, struct ui_file *stream)
4734 fprintf_unfiltered (stream, _("<unreadable>"));
4737 struct value_print_options opts;
4738 get_user_print_options (&opts);
4739 value_print (val, stream, &opts);
4743 /* Generic routine for printing messages indicating why we
4744 stopped. The behavior of this function depends on the value
4745 'print_it' in the bpstat structure. Under some circumstances we
4746 may decide not to print anything here and delegate the task to
4749 static enum print_stop_action
4750 print_bp_stop_message (bpstat bs)
4752 switch (bs->print_it)
4755 /* Nothing should be printed for this bpstat entry. */
4756 return PRINT_UNKNOWN;
4760 /* We still want to print the frame, but we already printed the
4761 relevant messages. */
4762 return PRINT_SRC_AND_LOC;
4765 case print_it_normal:
4767 struct breakpoint *b = bs->breakpoint_at;
4769 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4770 which has since been deleted. */
4772 return PRINT_UNKNOWN;
4774 /* Normal case. Call the breakpoint's print_it method. */
4775 return b->ops->print_it (bs);
4780 internal_error (__FILE__, __LINE__,
4781 _("print_bp_stop_message: unrecognized enum value"));
4786 /* A helper function that prints a shared library stopped event. */
4789 print_solib_event (int is_catchpoint)
4792 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4794 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4798 if (any_added || any_deleted)
4799 ui_out_text (current_uiout,
4800 _("Stopped due to shared library event:\n"));
4802 ui_out_text (current_uiout,
4803 _("Stopped due to shared library event (no "
4804 "libraries added or removed)\n"));
4807 if (ui_out_is_mi_like_p (current_uiout))
4808 ui_out_field_string (current_uiout, "reason",
4809 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4813 struct cleanup *cleanup;
4817 ui_out_text (current_uiout, _(" Inferior unloaded "));
4818 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4821 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4826 ui_out_text (current_uiout, " ");
4827 ui_out_field_string (current_uiout, "library", name);
4828 ui_out_text (current_uiout, "\n");
4831 do_cleanups (cleanup);
4836 struct so_list *iter;
4838 struct cleanup *cleanup;
4840 ui_out_text (current_uiout, _(" Inferior loaded "));
4841 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4844 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4849 ui_out_text (current_uiout, " ");
4850 ui_out_field_string (current_uiout, "library", iter->so_name);
4851 ui_out_text (current_uiout, "\n");
4854 do_cleanups (cleanup);
4858 /* Print a message indicating what happened. This is called from
4859 normal_stop(). The input to this routine is the head of the bpstat
4860 list - a list of the eventpoints that caused this stop. KIND is
4861 the target_waitkind for the stopping event. This
4862 routine calls the generic print routine for printing a message
4863 about reasons for stopping. This will print (for example) the
4864 "Breakpoint n," part of the output. The return value of this
4867 PRINT_UNKNOWN: Means we printed nothing.
4868 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4869 code to print the location. An example is
4870 "Breakpoint 1, " which should be followed by
4872 PRINT_SRC_ONLY: Means we printed something, but there is no need
4873 to also print the location part of the message.
4874 An example is the catch/throw messages, which
4875 don't require a location appended to the end.
4876 PRINT_NOTHING: We have done some printing and we don't need any
4877 further info to be printed. */
4879 enum print_stop_action
4880 bpstat_print (bpstat bs, int kind)
4884 /* Maybe another breakpoint in the chain caused us to stop.
4885 (Currently all watchpoints go on the bpstat whether hit or not.
4886 That probably could (should) be changed, provided care is taken
4887 with respect to bpstat_explains_signal). */
4888 for (; bs; bs = bs->next)
4890 val = print_bp_stop_message (bs);
4891 if (val == PRINT_SRC_ONLY
4892 || val == PRINT_SRC_AND_LOC
4893 || val == PRINT_NOTHING)
4897 /* If we had hit a shared library event breakpoint,
4898 print_bp_stop_message would print out this message. If we hit an
4899 OS-level shared library event, do the same thing. */
4900 if (kind == TARGET_WAITKIND_LOADED)
4902 print_solib_event (0);
4903 return PRINT_NOTHING;
4906 /* We reached the end of the chain, or we got a null BS to start
4907 with and nothing was printed. */
4908 return PRINT_UNKNOWN;
4911 /* Evaluate the expression EXP and return 1 if value is zero.
4912 This returns the inverse of the condition because it is called
4913 from catch_errors which returns 0 if an exception happened, and if an
4914 exception happens we want execution to stop.
4915 The argument is a "struct expression *" that has been cast to a
4916 "void *" to make it pass through catch_errors. */
4919 breakpoint_cond_eval (void *exp)
4921 struct value *mark = value_mark ();
4922 int i = !value_true (evaluate_expression ((struct expression *) exp));
4924 value_free_to_mark (mark);
4928 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4931 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
4935 bs = (bpstat) xmalloc (sizeof (*bs));
4937 **bs_link_pointer = bs;
4938 *bs_link_pointer = &bs->next;
4939 bs->breakpoint_at = bl->owner;
4940 bs->bp_location_at = bl;
4941 incref_bp_location (bl);
4942 /* If the condition is false, etc., don't do the commands. */
4943 bs->commands = NULL;
4945 bs->print_it = print_it_normal;
4949 /* The target has stopped with waitstatus WS. Check if any hardware
4950 watchpoints have triggered, according to the target. */
4953 watchpoints_triggered (struct target_waitstatus *ws)
4955 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
4957 struct breakpoint *b;
4959 if (!stopped_by_watchpoint)
4961 /* We were not stopped by a watchpoint. Mark all watchpoints
4962 as not triggered. */
4964 if (is_hardware_watchpoint (b))
4966 struct watchpoint *w = (struct watchpoint *) b;
4968 w->watchpoint_triggered = watch_triggered_no;
4974 if (!target_stopped_data_address (¤t_target, &addr))
4976 /* We were stopped by a watchpoint, but we don't know where.
4977 Mark all watchpoints as unknown. */
4979 if (is_hardware_watchpoint (b))
4981 struct watchpoint *w = (struct watchpoint *) b;
4983 w->watchpoint_triggered = watch_triggered_unknown;
4989 /* The target could report the data address. Mark watchpoints
4990 affected by this data address as triggered, and all others as not
4994 if (is_hardware_watchpoint (b))
4996 struct watchpoint *w = (struct watchpoint *) b;
4997 struct bp_location *loc;
4999 w->watchpoint_triggered = watch_triggered_no;
5000 for (loc = b->loc; loc; loc = loc->next)
5002 if (is_masked_watchpoint (b))
5004 CORE_ADDR newaddr = addr & w->hw_wp_mask;
5005 CORE_ADDR start = loc->address & w->hw_wp_mask;
5007 if (newaddr == start)
5009 w->watchpoint_triggered = watch_triggered_yes;
5013 /* Exact match not required. Within range is sufficient. */
5014 else if (target_watchpoint_addr_within_range (¤t_target,
5018 w->watchpoint_triggered = watch_triggered_yes;
5027 /* Possible return values for watchpoint_check (this can't be an enum
5028 because of check_errors). */
5029 /* The watchpoint has been deleted. */
5030 #define WP_DELETED 1
5031 /* The value has changed. */
5032 #define WP_VALUE_CHANGED 2
5033 /* The value has not changed. */
5034 #define WP_VALUE_NOT_CHANGED 3
5035 /* Ignore this watchpoint, no matter if the value changed or not. */
5038 #define BP_TEMPFLAG 1
5039 #define BP_HARDWAREFLAG 2
5041 /* Evaluate watchpoint condition expression and check if its value
5044 P should be a pointer to struct bpstat, but is defined as a void *
5045 in order for this function to be usable with catch_errors. */
5048 watchpoint_check (void *p)
5050 bpstat bs = (bpstat) p;
5051 struct watchpoint *b;
5052 struct frame_info *fr;
5053 int within_current_scope;
5055 /* BS is built from an existing struct breakpoint. */
5056 gdb_assert (bs->breakpoint_at != NULL);
5057 b = (struct watchpoint *) bs->breakpoint_at;
5059 /* If this is a local watchpoint, we only want to check if the
5060 watchpoint frame is in scope if the current thread is the thread
5061 that was used to create the watchpoint. */
5062 if (!watchpoint_in_thread_scope (b))
5065 if (b->exp_valid_block == NULL)
5066 within_current_scope = 1;
5069 struct frame_info *frame = get_current_frame ();
5070 struct gdbarch *frame_arch = get_frame_arch (frame);
5071 CORE_ADDR frame_pc = get_frame_pc (frame);
5073 /* in_function_epilogue_p() returns a non-zero value if we're
5074 still in the function but the stack frame has already been
5075 invalidated. Since we can't rely on the values of local
5076 variables after the stack has been destroyed, we are treating
5077 the watchpoint in that state as `not changed' without further
5078 checking. Don't mark watchpoints as changed if the current
5079 frame is in an epilogue - even if they are in some other
5080 frame, our view of the stack is likely to be wrong and
5081 frame_find_by_id could error out. */
5082 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
5085 fr = frame_find_by_id (b->watchpoint_frame);
5086 within_current_scope = (fr != NULL);
5088 /* If we've gotten confused in the unwinder, we might have
5089 returned a frame that can't describe this variable. */
5090 if (within_current_scope)
5092 struct symbol *function;
5094 function = get_frame_function (fr);
5095 if (function == NULL
5096 || !contained_in (b->exp_valid_block,
5097 SYMBOL_BLOCK_VALUE (function)))
5098 within_current_scope = 0;
5101 if (within_current_scope)
5102 /* If we end up stopping, the current frame will get selected
5103 in normal_stop. So this call to select_frame won't affect
5108 if (within_current_scope)
5110 /* We use value_{,free_to_}mark because it could be a *long*
5111 time before we return to the command level and call
5112 free_all_values. We can't call free_all_values because we
5113 might be in the middle of evaluating a function call. */
5117 struct value *new_val;
5119 if (is_masked_watchpoint (&b->base))
5120 /* Since we don't know the exact trigger address (from
5121 stopped_data_address), just tell the user we've triggered
5122 a mask watchpoint. */
5123 return WP_VALUE_CHANGED;
5125 mark = value_mark ();
5126 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0);
5128 if (b->val_bitsize != 0)
5129 new_val = extract_bitfield_from_watchpoint_value (b, new_val);
5131 /* We use value_equal_contents instead of value_equal because
5132 the latter coerces an array to a pointer, thus comparing just
5133 the address of the array instead of its contents. This is
5134 not what we want. */
5135 if ((b->val != NULL) != (new_val != NULL)
5136 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
5138 if (new_val != NULL)
5140 release_value (new_val);
5141 value_free_to_mark (mark);
5143 bs->old_val = b->val;
5146 return WP_VALUE_CHANGED;
5150 /* Nothing changed. */
5151 value_free_to_mark (mark);
5152 return WP_VALUE_NOT_CHANGED;
5157 struct ui_out *uiout = current_uiout;
5159 /* This seems like the only logical thing to do because
5160 if we temporarily ignored the watchpoint, then when
5161 we reenter the block in which it is valid it contains
5162 garbage (in the case of a function, it may have two
5163 garbage values, one before and one after the prologue).
5164 So we can't even detect the first assignment to it and
5165 watch after that (since the garbage may or may not equal
5166 the first value assigned). */
5167 /* We print all the stop information in
5168 breakpoint_ops->print_it, but in this case, by the time we
5169 call breakpoint_ops->print_it this bp will be deleted
5170 already. So we have no choice but print the information
5172 if (ui_out_is_mi_like_p (uiout))
5174 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
5175 ui_out_text (uiout, "\nWatchpoint ");
5176 ui_out_field_int (uiout, "wpnum", b->base.number);
5178 " deleted because the program has left the block in\n\
5179 which its expression is valid.\n");
5181 /* Make sure the watchpoint's commands aren't executed. */
5182 decref_counted_command_line (&b->base.commands);
5183 watchpoint_del_at_next_stop (b);
5189 /* Return true if it looks like target has stopped due to hitting
5190 breakpoint location BL. This function does not check if we should
5191 stop, only if BL explains the stop. */
5194 bpstat_check_location (const struct bp_location *bl,
5195 struct address_space *aspace, CORE_ADDR bp_addr,
5196 const struct target_waitstatus *ws)
5198 struct breakpoint *b = bl->owner;
5200 /* BL is from an existing breakpoint. */
5201 gdb_assert (b != NULL);
5203 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
5206 /* Determine if the watched values have actually changed, and we
5207 should stop. If not, set BS->stop to 0. */
5210 bpstat_check_watchpoint (bpstat bs)
5212 const struct bp_location *bl;
5213 struct watchpoint *b;
5215 /* BS is built for existing struct breakpoint. */
5216 bl = bs->bp_location_at;
5217 gdb_assert (bl != NULL);
5218 b = (struct watchpoint *) bs->breakpoint_at;
5219 gdb_assert (b != NULL);
5222 int must_check_value = 0;
5224 if (b->base.type == bp_watchpoint)
5225 /* For a software watchpoint, we must always check the
5227 must_check_value = 1;
5228 else if (b->watchpoint_triggered == watch_triggered_yes)
5229 /* We have a hardware watchpoint (read, write, or access)
5230 and the target earlier reported an address watched by
5232 must_check_value = 1;
5233 else if (b->watchpoint_triggered == watch_triggered_unknown
5234 && b->base.type == bp_hardware_watchpoint)
5235 /* We were stopped by a hardware watchpoint, but the target could
5236 not report the data address. We must check the watchpoint's
5237 value. Access and read watchpoints are out of luck; without
5238 a data address, we can't figure it out. */
5239 must_check_value = 1;
5241 if (must_check_value)
5244 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5246 struct cleanup *cleanups = make_cleanup (xfree, message);
5247 int e = catch_errors (watchpoint_check, bs, message,
5249 do_cleanups (cleanups);
5253 /* We've already printed what needs to be printed. */
5254 bs->print_it = print_it_done;
5258 bs->print_it = print_it_noop;
5261 case WP_VALUE_CHANGED:
5262 if (b->base.type == bp_read_watchpoint)
5264 /* There are two cases to consider here:
5266 1. We're watching the triggered memory for reads.
5267 In that case, trust the target, and always report
5268 the watchpoint hit to the user. Even though
5269 reads don't cause value changes, the value may
5270 have changed since the last time it was read, and
5271 since we're not trapping writes, we will not see
5272 those, and as such we should ignore our notion of
5275 2. We're watching the triggered memory for both
5276 reads and writes. There are two ways this may
5279 2.1. This is a target that can't break on data
5280 reads only, but can break on accesses (reads or
5281 writes), such as e.g., x86. We detect this case
5282 at the time we try to insert read watchpoints.
5284 2.2. Otherwise, the target supports read
5285 watchpoints, but, the user set an access or write
5286 watchpoint watching the same memory as this read
5289 If we're watching memory writes as well as reads,
5290 ignore watchpoint hits when we find that the
5291 value hasn't changed, as reads don't cause
5292 changes. This still gives false positives when
5293 the program writes the same value to memory as
5294 what there was already in memory (we will confuse
5295 it for a read), but it's much better than
5298 int other_write_watchpoint = 0;
5300 if (bl->watchpoint_type == hw_read)
5302 struct breakpoint *other_b;
5304 ALL_BREAKPOINTS (other_b)
5305 if (other_b->type == bp_hardware_watchpoint
5306 || other_b->type == bp_access_watchpoint)
5308 struct watchpoint *other_w =
5309 (struct watchpoint *) other_b;
5311 if (other_w->watchpoint_triggered
5312 == watch_triggered_yes)
5314 other_write_watchpoint = 1;
5320 if (other_write_watchpoint
5321 || bl->watchpoint_type == hw_access)
5323 /* We're watching the same memory for writes,
5324 and the value changed since the last time we
5325 updated it, so this trap must be for a write.
5327 bs->print_it = print_it_noop;
5332 case WP_VALUE_NOT_CHANGED:
5333 if (b->base.type == bp_hardware_watchpoint
5334 || b->base.type == bp_watchpoint)
5336 /* Don't stop: write watchpoints shouldn't fire if
5337 the value hasn't changed. */
5338 bs->print_it = print_it_noop;
5346 /* Error from catch_errors. */
5347 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
5348 watchpoint_del_at_next_stop (b);
5349 /* We've already printed what needs to be printed. */
5350 bs->print_it = print_it_done;
5354 else /* must_check_value == 0 */
5356 /* This is a case where some watchpoint(s) triggered, but
5357 not at the address of this watchpoint, or else no
5358 watchpoint triggered after all. So don't print
5359 anything for this watchpoint. */
5360 bs->print_it = print_it_noop;
5366 /* For breakpoints that are currently marked as telling gdb to stop,
5367 check conditions (condition proper, frame, thread and ignore count)
5368 of breakpoint referred to by BS. If we should not stop for this
5369 breakpoint, set BS->stop to 0. */
5372 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
5374 const struct bp_location *bl;
5375 struct breakpoint *b;
5376 int value_is_zero = 0;
5377 struct expression *cond;
5379 gdb_assert (bs->stop);
5381 /* BS is built for existing struct breakpoint. */
5382 bl = bs->bp_location_at;
5383 gdb_assert (bl != NULL);
5384 b = bs->breakpoint_at;
5385 gdb_assert (b != NULL);
5387 /* Even if the target evaluated the condition on its end and notified GDB, we
5388 need to do so again since GDB does not know if we stopped due to a
5389 breakpoint or a single step breakpoint. */
5391 if (frame_id_p (b->frame_id)
5392 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
5398 /* If this is a thread/task-specific breakpoint, don't waste cpu
5399 evaluating the condition if this isn't the specified
5401 if ((b->thread != -1 && b->thread != pid_to_thread_id (ptid))
5402 || (b->task != 0 && b->task != ada_get_task_number (ptid)))
5409 /* Evaluate extension language breakpoints that have a "stop" method
5411 bs->stop = breakpoint_ext_lang_cond_says_stop (b);
5413 if (is_watchpoint (b))
5415 struct watchpoint *w = (struct watchpoint *) b;
5422 if (cond && b->disposition != disp_del_at_next_stop)
5424 int within_current_scope = 1;
5425 struct watchpoint * w;
5427 /* We use value_mark and value_free_to_mark because it could
5428 be a long time before we return to the command level and
5429 call free_all_values. We can't call free_all_values
5430 because we might be in the middle of evaluating a
5432 struct value *mark = value_mark ();
5434 if (is_watchpoint (b))
5435 w = (struct watchpoint *) b;
5439 /* Need to select the frame, with all that implies so that
5440 the conditions will have the right context. Because we
5441 use the frame, we will not see an inlined function's
5442 variables when we arrive at a breakpoint at the start
5443 of the inlined function; the current frame will be the
5445 if (w == NULL || w->cond_exp_valid_block == NULL)
5446 select_frame (get_current_frame ());
5449 struct frame_info *frame;
5451 /* For local watchpoint expressions, which particular
5452 instance of a local is being watched matters, so we
5453 keep track of the frame to evaluate the expression
5454 in. To evaluate the condition however, it doesn't
5455 really matter which instantiation of the function
5456 where the condition makes sense triggers the
5457 watchpoint. This allows an expression like "watch
5458 global if q > 10" set in `func', catch writes to
5459 global on all threads that call `func', or catch
5460 writes on all recursive calls of `func' by a single
5461 thread. We simply always evaluate the condition in
5462 the innermost frame that's executing where it makes
5463 sense to evaluate the condition. It seems
5465 frame = block_innermost_frame (w->cond_exp_valid_block);
5467 select_frame (frame);
5469 within_current_scope = 0;
5471 if (within_current_scope)
5473 = catch_errors (breakpoint_cond_eval, cond,
5474 "Error in testing breakpoint condition:\n",
5478 warning (_("Watchpoint condition cannot be tested "
5479 "in the current scope"));
5480 /* If we failed to set the right context for this
5481 watchpoint, unconditionally report it. */
5484 /* FIXME-someday, should give breakpoint #. */
5485 value_free_to_mark (mark);
5488 if (cond && value_is_zero)
5492 else if (b->ignore_count > 0)
5496 /* Increase the hit count even though we don't stop. */
5498 observer_notify_breakpoint_modified (b);
5503 /* Get a bpstat associated with having just stopped at address
5504 BP_ADDR in thread PTID.
5506 Determine whether we stopped at a breakpoint, etc, or whether we
5507 don't understand this stop. Result is a chain of bpstat's such
5510 if we don't understand the stop, the result is a null pointer.
5512 if we understand why we stopped, the result is not null.
5514 Each element of the chain refers to a particular breakpoint or
5515 watchpoint at which we have stopped. (We may have stopped for
5516 several reasons concurrently.)
5518 Each element of the chain has valid next, breakpoint_at,
5519 commands, FIXME??? fields. */
5522 bpstat_stop_status (struct address_space *aspace,
5523 CORE_ADDR bp_addr, ptid_t ptid,
5524 const struct target_waitstatus *ws)
5526 struct breakpoint *b = NULL;
5527 struct bp_location *bl;
5528 struct bp_location *loc;
5529 /* First item of allocated bpstat's. */
5530 bpstat bs_head = NULL, *bs_link = &bs_head;
5531 /* Pointer to the last thing in the chain currently. */
5534 int need_remove_insert;
5537 /* First, build the bpstat chain with locations that explain a
5538 target stop, while being careful to not set the target running,
5539 as that may invalidate locations (in particular watchpoint
5540 locations are recreated). Resuming will happen here with
5541 breakpoint conditions or watchpoint expressions that include
5542 inferior function calls. */
5546 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
5549 for (bl = b->loc; bl != NULL; bl = bl->next)
5551 /* For hardware watchpoints, we look only at the first
5552 location. The watchpoint_check function will work on the
5553 entire expression, not the individual locations. For
5554 read watchpoints, the watchpoints_triggered function has
5555 checked all locations already. */
5556 if (b->type == bp_hardware_watchpoint && bl != b->loc)
5559 if (!bl->enabled || bl->shlib_disabled)
5562 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
5565 /* Come here if it's a watchpoint, or if the break address
5568 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
5571 /* Assume we stop. Should we find a watchpoint that is not
5572 actually triggered, or if the condition of the breakpoint
5573 evaluates as false, we'll reset 'stop' to 0. */
5577 /* If this is a scope breakpoint, mark the associated
5578 watchpoint as triggered so that we will handle the
5579 out-of-scope event. We'll get to the watchpoint next
5581 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
5583 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
5585 w->watchpoint_triggered = watch_triggered_yes;
5590 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
5592 if (breakpoint_location_address_match (loc, aspace, bp_addr))
5594 bs = bpstat_alloc (loc, &bs_link);
5595 /* For hits of moribund locations, we should just proceed. */
5598 bs->print_it = print_it_noop;
5602 /* A bit of special processing for shlib breakpoints. We need to
5603 process solib loading here, so that the lists of loaded and
5604 unloaded libraries are correct before we handle "catch load" and
5606 for (bs = bs_head; bs != NULL; bs = bs->next)
5608 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
5610 handle_solib_event ();
5615 /* Now go through the locations that caused the target to stop, and
5616 check whether we're interested in reporting this stop to higher
5617 layers, or whether we should resume the target transparently. */
5621 for (bs = bs_head; bs != NULL; bs = bs->next)
5626 b = bs->breakpoint_at;
5627 b->ops->check_status (bs);
5630 bpstat_check_breakpoint_conditions (bs, ptid);
5635 observer_notify_breakpoint_modified (b);
5637 /* We will stop here. */
5638 if (b->disposition == disp_disable)
5640 --(b->enable_count);
5641 if (b->enable_count <= 0
5642 && b->enable_state != bp_permanent)
5643 b->enable_state = bp_disabled;
5648 bs->commands = b->commands;
5649 incref_counted_command_line (bs->commands);
5650 if (command_line_is_silent (bs->commands
5651 ? bs->commands->commands : NULL))
5654 b->ops->after_condition_true (bs);
5659 /* Print nothing for this entry if we don't stop or don't
5661 if (!bs->stop || !bs->print)
5662 bs->print_it = print_it_noop;
5665 /* If we aren't stopping, the value of some hardware watchpoint may
5666 not have changed, but the intermediate memory locations we are
5667 watching may have. Don't bother if we're stopping; this will get
5669 need_remove_insert = 0;
5670 if (! bpstat_causes_stop (bs_head))
5671 for (bs = bs_head; bs != NULL; bs = bs->next)
5673 && bs->breakpoint_at
5674 && is_hardware_watchpoint (bs->breakpoint_at))
5676 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5678 update_watchpoint (w, 0 /* don't reparse. */);
5679 need_remove_insert = 1;
5682 if (need_remove_insert)
5683 update_global_location_list (UGLL_MAY_INSERT);
5684 else if (removed_any)
5685 update_global_location_list (UGLL_DONT_INSERT);
5691 handle_jit_event (void)
5693 struct frame_info *frame;
5694 struct gdbarch *gdbarch;
5696 /* Switch terminal for any messages produced by
5697 breakpoint_re_set. */
5698 target_terminal_ours_for_output ();
5700 frame = get_current_frame ();
5701 gdbarch = get_frame_arch (frame);
5703 jit_event_handler (gdbarch);
5705 target_terminal_inferior ();
5708 /* Prepare WHAT final decision for infrun. */
5710 /* Decide what infrun needs to do with this bpstat. */
5713 bpstat_what (bpstat bs_head)
5715 struct bpstat_what retval;
5719 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5720 retval.call_dummy = STOP_NONE;
5721 retval.is_longjmp = 0;
5723 for (bs = bs_head; bs != NULL; bs = bs->next)
5725 /* Extract this BS's action. After processing each BS, we check
5726 if its action overrides all we've seem so far. */
5727 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5730 if (bs->breakpoint_at == NULL)
5732 /* I suspect this can happen if it was a momentary
5733 breakpoint which has since been deleted. */
5737 bptype = bs->breakpoint_at->type;
5744 case bp_hardware_breakpoint:
5747 case bp_shlib_event:
5751 this_action = BPSTAT_WHAT_STOP_NOISY;
5753 this_action = BPSTAT_WHAT_STOP_SILENT;
5756 this_action = BPSTAT_WHAT_SINGLE;
5759 case bp_hardware_watchpoint:
5760 case bp_read_watchpoint:
5761 case bp_access_watchpoint:
5765 this_action = BPSTAT_WHAT_STOP_NOISY;
5767 this_action = BPSTAT_WHAT_STOP_SILENT;
5771 /* There was a watchpoint, but we're not stopping.
5772 This requires no further action. */
5776 case bp_longjmp_call_dummy:
5778 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5779 retval.is_longjmp = bptype != bp_exception;
5781 case bp_longjmp_resume:
5782 case bp_exception_resume:
5783 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5784 retval.is_longjmp = bptype == bp_longjmp_resume;
5786 case bp_step_resume:
5788 this_action = BPSTAT_WHAT_STEP_RESUME;
5791 /* It is for the wrong frame. */
5792 this_action = BPSTAT_WHAT_SINGLE;
5795 case bp_hp_step_resume:
5797 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5800 /* It is for the wrong frame. */
5801 this_action = BPSTAT_WHAT_SINGLE;
5804 case bp_watchpoint_scope:
5805 case bp_thread_event:
5806 case bp_overlay_event:
5807 case bp_longjmp_master:
5808 case bp_std_terminate_master:
5809 case bp_exception_master:
5810 this_action = BPSTAT_WHAT_SINGLE;
5816 this_action = BPSTAT_WHAT_STOP_NOISY;
5818 this_action = BPSTAT_WHAT_STOP_SILENT;
5822 /* There was a catchpoint, but we're not stopping.
5823 This requires no further action. */
5828 this_action = BPSTAT_WHAT_SINGLE;
5831 /* Make sure the action is stop (silent or noisy),
5832 so infrun.c pops the dummy frame. */
5833 retval.call_dummy = STOP_STACK_DUMMY;
5834 this_action = BPSTAT_WHAT_STOP_SILENT;
5836 case bp_std_terminate:
5837 /* Make sure the action is stop (silent or noisy),
5838 so infrun.c pops the dummy frame. */
5839 retval.call_dummy = STOP_STD_TERMINATE;
5840 this_action = BPSTAT_WHAT_STOP_SILENT;
5843 case bp_fast_tracepoint:
5844 case bp_static_tracepoint:
5845 /* Tracepoint hits should not be reported back to GDB, and
5846 if one got through somehow, it should have been filtered
5848 internal_error (__FILE__, __LINE__,
5849 _("bpstat_what: tracepoint encountered"));
5851 case bp_gnu_ifunc_resolver:
5852 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5853 this_action = BPSTAT_WHAT_SINGLE;
5855 case bp_gnu_ifunc_resolver_return:
5856 /* The breakpoint will be removed, execution will restart from the
5857 PC of the former breakpoint. */
5858 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5863 this_action = BPSTAT_WHAT_STOP_SILENT;
5865 this_action = BPSTAT_WHAT_SINGLE;
5869 internal_error (__FILE__, __LINE__,
5870 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5873 retval.main_action = max (retval.main_action, this_action);
5876 /* These operations may affect the bs->breakpoint_at state so they are
5877 delayed after MAIN_ACTION is decided above. */
5882 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
5884 handle_jit_event ();
5887 for (bs = bs_head; bs != NULL; bs = bs->next)
5889 struct breakpoint *b = bs->breakpoint_at;
5895 case bp_gnu_ifunc_resolver:
5896 gnu_ifunc_resolver_stop (b);
5898 case bp_gnu_ifunc_resolver_return:
5899 gnu_ifunc_resolver_return_stop (b);
5907 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5908 without hardware support). This isn't related to a specific bpstat,
5909 just to things like whether watchpoints are set. */
5912 bpstat_should_step (void)
5914 struct breakpoint *b;
5917 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
5923 bpstat_causes_stop (bpstat bs)
5925 for (; bs != NULL; bs = bs->next)
5934 /* Compute a string of spaces suitable to indent the next line
5935 so it starts at the position corresponding to the table column
5936 named COL_NAME in the currently active table of UIOUT. */
5939 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5941 static char wrap_indent[80];
5942 int i, total_width, width, align;
5946 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
5948 if (strcmp (text, col_name) == 0)
5950 gdb_assert (total_width < sizeof wrap_indent);
5951 memset (wrap_indent, ' ', total_width);
5952 wrap_indent[total_width] = 0;
5957 total_width += width + 1;
5963 /* Determine if the locations of this breakpoint will have their conditions
5964 evaluated by the target, host or a mix of both. Returns the following:
5966 "host": Host evals condition.
5967 "host or target": Host or Target evals condition.
5968 "target": Target evals condition.
5972 bp_condition_evaluator (struct breakpoint *b)
5974 struct bp_location *bl;
5975 char host_evals = 0;
5976 char target_evals = 0;
5981 if (!is_breakpoint (b))
5984 if (gdb_evaluates_breakpoint_condition_p ()
5985 || !target_supports_evaluation_of_breakpoint_conditions ())
5986 return condition_evaluation_host;
5988 for (bl = b->loc; bl; bl = bl->next)
5990 if (bl->cond_bytecode)
5996 if (host_evals && target_evals)
5997 return condition_evaluation_both;
5998 else if (target_evals)
5999 return condition_evaluation_target;
6001 return condition_evaluation_host;
6004 /* Determine the breakpoint location's condition evaluator. This is
6005 similar to bp_condition_evaluator, but for locations. */
6008 bp_location_condition_evaluator (struct bp_location *bl)
6010 if (bl && !is_breakpoint (bl->owner))
6013 if (gdb_evaluates_breakpoint_condition_p ()
6014 || !target_supports_evaluation_of_breakpoint_conditions ())
6015 return condition_evaluation_host;
6017 if (bl && bl->cond_bytecode)
6018 return condition_evaluation_target;
6020 return condition_evaluation_host;
6023 /* Print the LOC location out of the list of B->LOC locations. */
6026 print_breakpoint_location (struct breakpoint *b,
6027 struct bp_location *loc)
6029 struct ui_out *uiout = current_uiout;
6030 struct cleanup *old_chain = save_current_program_space ();
6032 if (loc != NULL && loc->shlib_disabled)
6036 set_current_program_space (loc->pspace);
6038 if (b->display_canonical)
6039 ui_out_field_string (uiout, "what", b->addr_string);
6040 else if (loc && loc->symtab)
6043 = find_pc_sect_function (loc->address, loc->section);
6046 ui_out_text (uiout, "in ");
6047 ui_out_field_string (uiout, "func",
6048 SYMBOL_PRINT_NAME (sym));
6049 ui_out_text (uiout, " ");
6050 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
6051 ui_out_text (uiout, "at ");
6053 ui_out_field_string (uiout, "file",
6054 symtab_to_filename_for_display (loc->symtab));
6055 ui_out_text (uiout, ":");
6057 if (ui_out_is_mi_like_p (uiout))
6058 ui_out_field_string (uiout, "fullname",
6059 symtab_to_fullname (loc->symtab));
6061 ui_out_field_int (uiout, "line", loc->line_number);
6065 struct ui_file *stb = mem_fileopen ();
6066 struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
6068 print_address_symbolic (loc->gdbarch, loc->address, stb,
6070 ui_out_field_stream (uiout, "at", stb);
6072 do_cleanups (stb_chain);
6075 ui_out_field_string (uiout, "pending", b->addr_string);
6077 if (loc && is_breakpoint (b)
6078 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6079 && bp_condition_evaluator (b) == condition_evaluation_both)
6081 ui_out_text (uiout, " (");
6082 ui_out_field_string (uiout, "evaluated-by",
6083 bp_location_condition_evaluator (loc));
6084 ui_out_text (uiout, ")");
6087 do_cleanups (old_chain);
6091 bptype_string (enum bptype type)
6093 struct ep_type_description
6098 static struct ep_type_description bptypes[] =
6100 {bp_none, "?deleted?"},
6101 {bp_breakpoint, "breakpoint"},
6102 {bp_hardware_breakpoint, "hw breakpoint"},
6103 {bp_until, "until"},
6104 {bp_finish, "finish"},
6105 {bp_watchpoint, "watchpoint"},
6106 {bp_hardware_watchpoint, "hw watchpoint"},
6107 {bp_read_watchpoint, "read watchpoint"},
6108 {bp_access_watchpoint, "acc watchpoint"},
6109 {bp_longjmp, "longjmp"},
6110 {bp_longjmp_resume, "longjmp resume"},
6111 {bp_longjmp_call_dummy, "longjmp for call dummy"},
6112 {bp_exception, "exception"},
6113 {bp_exception_resume, "exception resume"},
6114 {bp_step_resume, "step resume"},
6115 {bp_hp_step_resume, "high-priority step resume"},
6116 {bp_watchpoint_scope, "watchpoint scope"},
6117 {bp_call_dummy, "call dummy"},
6118 {bp_std_terminate, "std::terminate"},
6119 {bp_shlib_event, "shlib events"},
6120 {bp_thread_event, "thread events"},
6121 {bp_overlay_event, "overlay events"},
6122 {bp_longjmp_master, "longjmp master"},
6123 {bp_std_terminate_master, "std::terminate master"},
6124 {bp_exception_master, "exception master"},
6125 {bp_catchpoint, "catchpoint"},
6126 {bp_tracepoint, "tracepoint"},
6127 {bp_fast_tracepoint, "fast tracepoint"},
6128 {bp_static_tracepoint, "static tracepoint"},
6129 {bp_dprintf, "dprintf"},
6130 {bp_jit_event, "jit events"},
6131 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
6132 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
6135 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
6136 || ((int) type != bptypes[(int) type].type))
6137 internal_error (__FILE__, __LINE__,
6138 _("bptypes table does not describe type #%d."),
6141 return bptypes[(int) type].description;
6144 /* For MI, output a field named 'thread-groups' with a list as the value.
6145 For CLI, prefix the list with the string 'inf'. */
6148 output_thread_groups (struct ui_out *uiout,
6149 const char *field_name,
6153 struct cleanup *back_to;
6154 int is_mi = ui_out_is_mi_like_p (uiout);
6158 /* For backward compatibility, don't display inferiors in CLI unless
6159 there are several. Always display them for MI. */
6160 if (!is_mi && mi_only)
6163 back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name);
6165 for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i)
6171 xsnprintf (mi_group, sizeof (mi_group), "i%d", inf);
6172 ui_out_field_string (uiout, NULL, mi_group);
6177 ui_out_text (uiout, " inf ");
6179 ui_out_text (uiout, ", ");
6181 ui_out_text (uiout, plongest (inf));
6185 do_cleanups (back_to);
6188 /* Print B to gdb_stdout. */
6191 print_one_breakpoint_location (struct breakpoint *b,
6192 struct bp_location *loc,
6194 struct bp_location **last_loc,
6197 struct command_line *l;
6198 static char bpenables[] = "nynny";
6200 struct ui_out *uiout = current_uiout;
6201 int header_of_multiple = 0;
6202 int part_of_multiple = (loc != NULL);
6203 struct value_print_options opts;
6205 get_user_print_options (&opts);
6207 gdb_assert (!loc || loc_number != 0);
6208 /* See comment in print_one_breakpoint concerning treatment of
6209 breakpoints with single disabled location. */
6212 && (b->loc->next != NULL || !b->loc->enabled)))
6213 header_of_multiple = 1;
6221 if (part_of_multiple)
6224 formatted = xstrprintf ("%d.%d", b->number, loc_number);
6225 ui_out_field_string (uiout, "number", formatted);
6230 ui_out_field_int (uiout, "number", b->number);
6235 if (part_of_multiple)
6236 ui_out_field_skip (uiout, "type");
6238 ui_out_field_string (uiout, "type", bptype_string (b->type));
6242 if (part_of_multiple)
6243 ui_out_field_skip (uiout, "disp");
6245 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6250 if (part_of_multiple)
6251 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
6253 ui_out_field_fmt (uiout, "enabled", "%c",
6254 bpenables[(int) b->enable_state]);
6255 ui_out_spaces (uiout, 2);
6259 if (b->ops != NULL && b->ops->print_one != NULL)
6261 /* Although the print_one can possibly print all locations,
6262 calling it here is not likely to get any nice result. So,
6263 make sure there's just one location. */
6264 gdb_assert (b->loc == NULL || b->loc->next == NULL);
6265 b->ops->print_one (b, last_loc);
6271 internal_error (__FILE__, __LINE__,
6272 _("print_one_breakpoint: bp_none encountered\n"));
6276 case bp_hardware_watchpoint:
6277 case bp_read_watchpoint:
6278 case bp_access_watchpoint:
6280 struct watchpoint *w = (struct watchpoint *) b;
6282 /* Field 4, the address, is omitted (which makes the columns
6283 not line up too nicely with the headers, but the effect
6284 is relatively readable). */
6285 if (opts.addressprint)
6286 ui_out_field_skip (uiout, "addr");
6288 ui_out_field_string (uiout, "what", w->exp_string);
6293 case bp_hardware_breakpoint:
6297 case bp_longjmp_resume:
6298 case bp_longjmp_call_dummy:
6300 case bp_exception_resume:
6301 case bp_step_resume:
6302 case bp_hp_step_resume:
6303 case bp_watchpoint_scope:
6305 case bp_std_terminate:
6306 case bp_shlib_event:
6307 case bp_thread_event:
6308 case bp_overlay_event:
6309 case bp_longjmp_master:
6310 case bp_std_terminate_master:
6311 case bp_exception_master:
6313 case bp_fast_tracepoint:
6314 case bp_static_tracepoint:
6317 case bp_gnu_ifunc_resolver:
6318 case bp_gnu_ifunc_resolver_return:
6319 if (opts.addressprint)
6322 if (header_of_multiple)
6323 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
6324 else if (b->loc == NULL || loc->shlib_disabled)
6325 ui_out_field_string (uiout, "addr", "<PENDING>");
6327 ui_out_field_core_addr (uiout, "addr",
6328 loc->gdbarch, loc->address);
6331 if (!header_of_multiple)
6332 print_breakpoint_location (b, loc);
6339 if (loc != NULL && !header_of_multiple)
6341 struct inferior *inf;
6342 VEC(int) *inf_num = NULL;
6347 if (inf->pspace == loc->pspace)
6348 VEC_safe_push (int, inf_num, inf->num);
6351 /* For backward compatibility, don't display inferiors in CLI unless
6352 there are several. Always display for MI. */
6354 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6355 && (number_of_program_spaces () > 1
6356 || number_of_inferiors () > 1)
6357 /* LOC is for existing B, it cannot be in
6358 moribund_locations and thus having NULL OWNER. */
6359 && loc->owner->type != bp_catchpoint))
6361 output_thread_groups (uiout, "thread-groups", inf_num, mi_only);
6362 VEC_free (int, inf_num);
6365 if (!part_of_multiple)
6367 if (b->thread != -1)
6369 /* FIXME: This seems to be redundant and lost here; see the
6370 "stop only in" line a little further down. */
6371 ui_out_text (uiout, " thread ");
6372 ui_out_field_int (uiout, "thread", b->thread);
6374 else if (b->task != 0)
6376 ui_out_text (uiout, " task ");
6377 ui_out_field_int (uiout, "task", b->task);
6381 ui_out_text (uiout, "\n");
6383 if (!part_of_multiple)
6384 b->ops->print_one_detail (b, uiout);
6386 if (part_of_multiple && frame_id_p (b->frame_id))
6389 ui_out_text (uiout, "\tstop only in stack frame at ");
6390 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6392 ui_out_field_core_addr (uiout, "frame",
6393 b->gdbarch, b->frame_id.stack_addr);
6394 ui_out_text (uiout, "\n");
6397 if (!part_of_multiple && b->cond_string)
6400 if (is_tracepoint (b))
6401 ui_out_text (uiout, "\ttrace only if ");
6403 ui_out_text (uiout, "\tstop only if ");
6404 ui_out_field_string (uiout, "cond", b->cond_string);
6406 /* Print whether the target is doing the breakpoint's condition
6407 evaluation. If GDB is doing the evaluation, don't print anything. */
6408 if (is_breakpoint (b)
6409 && breakpoint_condition_evaluation_mode ()
6410 == condition_evaluation_target)
6412 ui_out_text (uiout, " (");
6413 ui_out_field_string (uiout, "evaluated-by",
6414 bp_condition_evaluator (b));
6415 ui_out_text (uiout, " evals)");
6417 ui_out_text (uiout, "\n");
6420 if (!part_of_multiple && b->thread != -1)
6422 /* FIXME should make an annotation for this. */
6423 ui_out_text (uiout, "\tstop only in thread ");
6424 ui_out_field_int (uiout, "thread", b->thread);
6425 ui_out_text (uiout, "\n");
6428 if (!part_of_multiple)
6432 /* FIXME should make an annotation for this. */
6433 if (is_catchpoint (b))
6434 ui_out_text (uiout, "\tcatchpoint");
6435 else if (is_tracepoint (b))
6436 ui_out_text (uiout, "\ttracepoint");
6438 ui_out_text (uiout, "\tbreakpoint");
6439 ui_out_text (uiout, " already hit ");
6440 ui_out_field_int (uiout, "times", b->hit_count);
6441 if (b->hit_count == 1)
6442 ui_out_text (uiout, " time\n");
6444 ui_out_text (uiout, " times\n");
6448 /* Output the count also if it is zero, but only if this is mi. */
6449 if (ui_out_is_mi_like_p (uiout))
6450 ui_out_field_int (uiout, "times", b->hit_count);
6454 if (!part_of_multiple && b->ignore_count)
6457 ui_out_text (uiout, "\tignore next ");
6458 ui_out_field_int (uiout, "ignore", b->ignore_count);
6459 ui_out_text (uiout, " hits\n");
6462 /* Note that an enable count of 1 corresponds to "enable once"
6463 behavior, which is reported by the combination of enablement and
6464 disposition, so we don't need to mention it here. */
6465 if (!part_of_multiple && b->enable_count > 1)
6468 ui_out_text (uiout, "\tdisable after ");
6469 /* Tweak the wording to clarify that ignore and enable counts
6470 are distinct, and have additive effect. */
6471 if (b->ignore_count)
6472 ui_out_text (uiout, "additional ");
6474 ui_out_text (uiout, "next ");
6475 ui_out_field_int (uiout, "enable", b->enable_count);
6476 ui_out_text (uiout, " hits\n");
6479 if (!part_of_multiple && is_tracepoint (b))
6481 struct tracepoint *tp = (struct tracepoint *) b;
6483 if (tp->traceframe_usage)
6485 ui_out_text (uiout, "\ttrace buffer usage ");
6486 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
6487 ui_out_text (uiout, " bytes\n");
6491 l = b->commands ? b->commands->commands : NULL;
6492 if (!part_of_multiple && l)
6494 struct cleanup *script_chain;
6497 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
6498 print_command_lines (uiout, l, 4);
6499 do_cleanups (script_chain);
6502 if (is_tracepoint (b))
6504 struct tracepoint *t = (struct tracepoint *) b;
6506 if (!part_of_multiple && t->pass_count)
6508 annotate_field (10);
6509 ui_out_text (uiout, "\tpass count ");
6510 ui_out_field_int (uiout, "pass", t->pass_count);
6511 ui_out_text (uiout, " \n");
6514 /* Don't display it when tracepoint or tracepoint location is
6516 if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
6518 annotate_field (11);
6520 if (ui_out_is_mi_like_p (uiout))
6521 ui_out_field_string (uiout, "installed",
6522 loc->inserted ? "y" : "n");
6526 ui_out_text (uiout, "\t");
6528 ui_out_text (uiout, "\tnot ");
6529 ui_out_text (uiout, "installed on target\n");
6534 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
6536 if (is_watchpoint (b))
6538 struct watchpoint *w = (struct watchpoint *) b;
6540 ui_out_field_string (uiout, "original-location", w->exp_string);
6542 else if (b->addr_string)
6543 ui_out_field_string (uiout, "original-location", b->addr_string);
6548 print_one_breakpoint (struct breakpoint *b,
6549 struct bp_location **last_loc,
6552 struct cleanup *bkpt_chain;
6553 struct ui_out *uiout = current_uiout;
6555 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
6557 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
6558 do_cleanups (bkpt_chain);
6560 /* If this breakpoint has custom print function,
6561 it's already printed. Otherwise, print individual
6562 locations, if any. */
6563 if (b->ops == NULL || b->ops->print_one == NULL)
6565 /* If breakpoint has a single location that is disabled, we
6566 print it as if it had several locations, since otherwise it's
6567 hard to represent "breakpoint enabled, location disabled"
6570 Note that while hardware watchpoints have several locations
6571 internally, that's not a property exposed to user. */
6573 && !is_hardware_watchpoint (b)
6574 && (b->loc->next || !b->loc->enabled))
6576 struct bp_location *loc;
6579 for (loc = b->loc; loc; loc = loc->next, ++n)
6581 struct cleanup *inner2 =
6582 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
6583 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
6584 do_cleanups (inner2);
6591 breakpoint_address_bits (struct breakpoint *b)
6593 int print_address_bits = 0;
6594 struct bp_location *loc;
6596 for (loc = b->loc; loc; loc = loc->next)
6600 /* Software watchpoints that aren't watching memory don't have
6601 an address to print. */
6602 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
6605 addr_bit = gdbarch_addr_bit (loc->gdbarch);
6606 if (addr_bit > print_address_bits)
6607 print_address_bits = addr_bit;
6610 return print_address_bits;
6613 struct captured_breakpoint_query_args
6619 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
6621 struct captured_breakpoint_query_args *args = data;
6622 struct breakpoint *b;
6623 struct bp_location *dummy_loc = NULL;
6627 if (args->bnum == b->number)
6629 print_one_breakpoint (b, &dummy_loc, 0);
6637 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
6638 char **error_message)
6640 struct captured_breakpoint_query_args args;
6643 /* For the moment we don't trust print_one_breakpoint() to not throw
6645 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
6646 error_message, RETURN_MASK_ALL) < 0)
6652 /* Return true if this breakpoint was set by the user, false if it is
6653 internal or momentary. */
6656 user_breakpoint_p (struct breakpoint *b)
6658 return b->number > 0;
6661 /* Print information on user settable breakpoint (watchpoint, etc)
6662 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6663 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6664 FILTER is non-NULL, call it on each breakpoint and only include the
6665 ones for which it returns non-zero. Return the total number of
6666 breakpoints listed. */
6669 breakpoint_1 (char *args, int allflag,
6670 int (*filter) (const struct breakpoint *))
6672 struct breakpoint *b;
6673 struct bp_location *last_loc = NULL;
6674 int nr_printable_breakpoints;
6675 struct cleanup *bkpttbl_chain;
6676 struct value_print_options opts;
6677 int print_address_bits = 0;
6678 int print_type_col_width = 14;
6679 struct ui_out *uiout = current_uiout;
6681 get_user_print_options (&opts);
6683 /* Compute the number of rows in the table, as well as the size
6684 required for address fields. */
6685 nr_printable_breakpoints = 0;
6688 /* If we have a filter, only list the breakpoints it accepts. */
6689 if (filter && !filter (b))
6692 /* If we have an "args" string, it is a list of breakpoints to
6693 accept. Skip the others. */
6694 if (args != NULL && *args != '\0')
6696 if (allflag && parse_and_eval_long (args) != b->number)
6698 if (!allflag && !number_is_in_list (args, b->number))
6702 if (allflag || user_breakpoint_p (b))
6704 int addr_bit, type_len;
6706 addr_bit = breakpoint_address_bits (b);
6707 if (addr_bit > print_address_bits)
6708 print_address_bits = addr_bit;
6710 type_len = strlen (bptype_string (b->type));
6711 if (type_len > print_type_col_width)
6712 print_type_col_width = type_len;
6714 nr_printable_breakpoints++;
6718 if (opts.addressprint)
6720 = make_cleanup_ui_out_table_begin_end (uiout, 6,
6721 nr_printable_breakpoints,
6725 = make_cleanup_ui_out_table_begin_end (uiout, 5,
6726 nr_printable_breakpoints,
6729 if (nr_printable_breakpoints > 0)
6730 annotate_breakpoints_headers ();
6731 if (nr_printable_breakpoints > 0)
6733 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
6734 if (nr_printable_breakpoints > 0)
6736 ui_out_table_header (uiout, print_type_col_width, ui_left,
6737 "type", "Type"); /* 2 */
6738 if (nr_printable_breakpoints > 0)
6740 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
6741 if (nr_printable_breakpoints > 0)
6743 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
6744 if (opts.addressprint)
6746 if (nr_printable_breakpoints > 0)
6748 if (print_address_bits <= 32)
6749 ui_out_table_header (uiout, 10, ui_left,
6750 "addr", "Address"); /* 5 */
6752 ui_out_table_header (uiout, 18, ui_left,
6753 "addr", "Address"); /* 5 */
6755 if (nr_printable_breakpoints > 0)
6757 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
6758 ui_out_table_body (uiout);
6759 if (nr_printable_breakpoints > 0)
6760 annotate_breakpoints_table ();
6765 /* If we have a filter, only list the breakpoints it accepts. */
6766 if (filter && !filter (b))
6769 /* If we have an "args" string, it is a list of breakpoints to
6770 accept. Skip the others. */
6772 if (args != NULL && *args != '\0')
6774 if (allflag) /* maintenance info breakpoint */
6776 if (parse_and_eval_long (args) != b->number)
6779 else /* all others */
6781 if (!number_is_in_list (args, b->number))
6785 /* We only print out user settable breakpoints unless the
6787 if (allflag || user_breakpoint_p (b))
6788 print_one_breakpoint (b, &last_loc, allflag);
6791 do_cleanups (bkpttbl_chain);
6793 if (nr_printable_breakpoints == 0)
6795 /* If there's a filter, let the caller decide how to report
6799 if (args == NULL || *args == '\0')
6800 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
6802 ui_out_message (uiout, 0,
6803 "No breakpoint or watchpoint matching '%s'.\n",
6809 if (last_loc && !server_command)
6810 set_next_address (last_loc->gdbarch, last_loc->address);
6813 /* FIXME? Should this be moved up so that it is only called when
6814 there have been breakpoints? */
6815 annotate_breakpoints_table_end ();
6817 return nr_printable_breakpoints;
6820 /* Display the value of default-collect in a way that is generally
6821 compatible with the breakpoint list. */
6824 default_collect_info (void)
6826 struct ui_out *uiout = current_uiout;
6828 /* If it has no value (which is frequently the case), say nothing; a
6829 message like "No default-collect." gets in user's face when it's
6831 if (!*default_collect)
6834 /* The following phrase lines up nicely with per-tracepoint collect
6836 ui_out_text (uiout, "default collect ");
6837 ui_out_field_string (uiout, "default-collect", default_collect);
6838 ui_out_text (uiout, " \n");
6842 breakpoints_info (char *args, int from_tty)
6844 breakpoint_1 (args, 0, NULL);
6846 default_collect_info ();
6850 watchpoints_info (char *args, int from_tty)
6852 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6853 struct ui_out *uiout = current_uiout;
6855 if (num_printed == 0)
6857 if (args == NULL || *args == '\0')
6858 ui_out_message (uiout, 0, "No watchpoints.\n");
6860 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
6865 maintenance_info_breakpoints (char *args, int from_tty)
6867 breakpoint_1 (args, 1, NULL);
6869 default_collect_info ();
6873 breakpoint_has_pc (struct breakpoint *b,
6874 struct program_space *pspace,
6875 CORE_ADDR pc, struct obj_section *section)
6877 struct bp_location *bl = b->loc;
6879 for (; bl; bl = bl->next)
6881 if (bl->pspace == pspace
6882 && bl->address == pc
6883 && (!overlay_debugging || bl->section == section))
6889 /* Print a message describing any user-breakpoints set at PC. This
6890 concerns with logical breakpoints, so we match program spaces, not
6894 describe_other_breakpoints (struct gdbarch *gdbarch,
6895 struct program_space *pspace, CORE_ADDR pc,
6896 struct obj_section *section, int thread)
6899 struct breakpoint *b;
6902 others += (user_breakpoint_p (b)
6903 && breakpoint_has_pc (b, pspace, pc, section));
6907 printf_filtered (_("Note: breakpoint "));
6908 else /* if (others == ???) */
6909 printf_filtered (_("Note: breakpoints "));
6911 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
6914 printf_filtered ("%d", b->number);
6915 if (b->thread == -1 && thread != -1)
6916 printf_filtered (" (all threads)");
6917 else if (b->thread != -1)
6918 printf_filtered (" (thread %d)", b->thread);
6919 printf_filtered ("%s%s ",
6920 ((b->enable_state == bp_disabled
6921 || b->enable_state == bp_call_disabled)
6923 : b->enable_state == bp_permanent
6927 : ((others == 1) ? " and" : ""));
6929 printf_filtered (_("also set at pc "));
6930 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
6931 printf_filtered (".\n");
6936 /* Return true iff it is meaningful to use the address member of
6937 BPT. For some breakpoint types, the address member is irrelevant
6938 and it makes no sense to attempt to compare it to other addresses
6939 (or use it for any other purpose either).
6941 More specifically, each of the following breakpoint types will
6942 always have a zero valued address and we don't want to mark
6943 breakpoints of any of these types to be a duplicate of an actual
6944 breakpoint at address zero:
6952 breakpoint_address_is_meaningful (struct breakpoint *bpt)
6954 enum bptype type = bpt->type;
6956 return (type != bp_watchpoint && type != bp_catchpoint);
6959 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6960 true if LOC1 and LOC2 represent the same watchpoint location. */
6963 watchpoint_locations_match (struct bp_location *loc1,
6964 struct bp_location *loc2)
6966 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6967 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6969 /* Both of them must exist. */
6970 gdb_assert (w1 != NULL);
6971 gdb_assert (w2 != NULL);
6973 /* If the target can evaluate the condition expression in hardware,
6974 then we we need to insert both watchpoints even if they are at
6975 the same place. Otherwise the watchpoint will only trigger when
6976 the condition of whichever watchpoint was inserted evaluates to
6977 true, not giving a chance for GDB to check the condition of the
6978 other watchpoint. */
6980 && target_can_accel_watchpoint_condition (loc1->address,
6982 loc1->watchpoint_type,
6985 && target_can_accel_watchpoint_condition (loc2->address,
6987 loc2->watchpoint_type,
6991 /* Note that this checks the owner's type, not the location's. In
6992 case the target does not support read watchpoints, but does
6993 support access watchpoints, we'll have bp_read_watchpoint
6994 watchpoints with hw_access locations. Those should be considered
6995 duplicates of hw_read locations. The hw_read locations will
6996 become hw_access locations later. */
6997 return (loc1->owner->type == loc2->owner->type
6998 && loc1->pspace->aspace == loc2->pspace->aspace
6999 && loc1->address == loc2->address
7000 && loc1->length == loc2->length);
7003 /* See breakpoint.h. */
7006 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
7007 struct address_space *aspace2, CORE_ADDR addr2)
7009 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7010 || aspace1 == aspace2)
7014 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7015 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7016 matches ASPACE2. On targets that have global breakpoints, the address
7017 space doesn't really matter. */
7020 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
7021 int len1, struct address_space *aspace2,
7024 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7025 || aspace1 == aspace2)
7026 && addr2 >= addr1 && addr2 < addr1 + len1);
7029 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7030 a ranged breakpoint. In most targets, a match happens only if ASPACE
7031 matches the breakpoint's address space. On targets that have global
7032 breakpoints, the address space doesn't really matter. */
7035 breakpoint_location_address_match (struct bp_location *bl,
7036 struct address_space *aspace,
7039 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
7042 && breakpoint_address_match_range (bl->pspace->aspace,
7043 bl->address, bl->length,
7047 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7048 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7049 true, otherwise returns false. */
7052 tracepoint_locations_match (struct bp_location *loc1,
7053 struct bp_location *loc2)
7055 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
7056 /* Since tracepoint locations are never duplicated with others', tracepoint
7057 locations at the same address of different tracepoints are regarded as
7058 different locations. */
7059 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
7064 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7065 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7066 represent the same location. */
7069 breakpoint_locations_match (struct bp_location *loc1,
7070 struct bp_location *loc2)
7072 int hw_point1, hw_point2;
7074 /* Both of them must not be in moribund_locations. */
7075 gdb_assert (loc1->owner != NULL);
7076 gdb_assert (loc2->owner != NULL);
7078 hw_point1 = is_hardware_watchpoint (loc1->owner);
7079 hw_point2 = is_hardware_watchpoint (loc2->owner);
7081 if (hw_point1 != hw_point2)
7084 return watchpoint_locations_match (loc1, loc2);
7085 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
7086 return tracepoint_locations_match (loc1, loc2);
7088 /* We compare bp_location.length in order to cover ranged breakpoints. */
7089 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
7090 loc2->pspace->aspace, loc2->address)
7091 && loc1->length == loc2->length);
7095 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
7096 int bnum, int have_bnum)
7098 /* The longest string possibly returned by hex_string_custom
7099 is 50 chars. These must be at least that big for safety. */
7103 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
7104 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
7106 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7107 bnum, astr1, astr2);
7109 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
7112 /* Adjust a breakpoint's address to account for architectural
7113 constraints on breakpoint placement. Return the adjusted address.
7114 Note: Very few targets require this kind of adjustment. For most
7115 targets, this function is simply the identity function. */
7118 adjust_breakpoint_address (struct gdbarch *gdbarch,
7119 CORE_ADDR bpaddr, enum bptype bptype)
7121 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
7123 /* Very few targets need any kind of breakpoint adjustment. */
7126 else if (bptype == bp_watchpoint
7127 || bptype == bp_hardware_watchpoint
7128 || bptype == bp_read_watchpoint
7129 || bptype == bp_access_watchpoint
7130 || bptype == bp_catchpoint)
7132 /* Watchpoints and the various bp_catch_* eventpoints should not
7133 have their addresses modified. */
7138 CORE_ADDR adjusted_bpaddr;
7140 /* Some targets have architectural constraints on the placement
7141 of breakpoint instructions. Obtain the adjusted address. */
7142 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
7144 /* An adjusted breakpoint address can significantly alter
7145 a user's expectations. Print a warning if an adjustment
7147 if (adjusted_bpaddr != bpaddr)
7148 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
7150 return adjusted_bpaddr;
7155 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
7156 struct breakpoint *owner)
7158 memset (loc, 0, sizeof (*loc));
7160 gdb_assert (ops != NULL);
7165 loc->cond_bytecode = NULL;
7166 loc->shlib_disabled = 0;
7169 switch (owner->type)
7175 case bp_longjmp_resume:
7176 case bp_longjmp_call_dummy:
7178 case bp_exception_resume:
7179 case bp_step_resume:
7180 case bp_hp_step_resume:
7181 case bp_watchpoint_scope:
7183 case bp_std_terminate:
7184 case bp_shlib_event:
7185 case bp_thread_event:
7186 case bp_overlay_event:
7188 case bp_longjmp_master:
7189 case bp_std_terminate_master:
7190 case bp_exception_master:
7191 case bp_gnu_ifunc_resolver:
7192 case bp_gnu_ifunc_resolver_return:
7194 loc->loc_type = bp_loc_software_breakpoint;
7195 mark_breakpoint_location_modified (loc);
7197 case bp_hardware_breakpoint:
7198 loc->loc_type = bp_loc_hardware_breakpoint;
7199 mark_breakpoint_location_modified (loc);
7201 case bp_hardware_watchpoint:
7202 case bp_read_watchpoint:
7203 case bp_access_watchpoint:
7204 loc->loc_type = bp_loc_hardware_watchpoint;
7209 case bp_fast_tracepoint:
7210 case bp_static_tracepoint:
7211 loc->loc_type = bp_loc_other;
7214 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
7220 /* Allocate a struct bp_location. */
7222 static struct bp_location *
7223 allocate_bp_location (struct breakpoint *bpt)
7225 return bpt->ops->allocate_location (bpt);
7229 free_bp_location (struct bp_location *loc)
7231 loc->ops->dtor (loc);
7235 /* Increment reference count. */
7238 incref_bp_location (struct bp_location *bl)
7243 /* Decrement reference count. If the reference count reaches 0,
7244 destroy the bp_location. Sets *BLP to NULL. */
7247 decref_bp_location (struct bp_location **blp)
7249 gdb_assert ((*blp)->refc > 0);
7251 if (--(*blp)->refc == 0)
7252 free_bp_location (*blp);
7256 /* Add breakpoint B at the end of the global breakpoint chain. */
7259 add_to_breakpoint_chain (struct breakpoint *b)
7261 struct breakpoint *b1;
7263 /* Add this breakpoint to the end of the chain so that a list of
7264 breakpoints will come out in order of increasing numbers. */
7266 b1 = breakpoint_chain;
7268 breakpoint_chain = b;
7277 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7280 init_raw_breakpoint_without_location (struct breakpoint *b,
7281 struct gdbarch *gdbarch,
7283 const struct breakpoint_ops *ops)
7285 memset (b, 0, sizeof (*b));
7287 gdb_assert (ops != NULL);
7291 b->gdbarch = gdbarch;
7292 b->language = current_language->la_language;
7293 b->input_radix = input_radix;
7295 b->enable_state = bp_enabled;
7298 b->ignore_count = 0;
7300 b->frame_id = null_frame_id;
7301 b->condition_not_parsed = 0;
7302 b->py_bp_object = NULL;
7303 b->related_breakpoint = b;
7306 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7307 that has type BPTYPE and has no locations as yet. */
7309 static struct breakpoint *
7310 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
7312 const struct breakpoint_ops *ops)
7314 struct breakpoint *b = XNEW (struct breakpoint);
7316 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7317 add_to_breakpoint_chain (b);
7321 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7322 resolutions should be made as the user specified the location explicitly
7326 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
7328 gdb_assert (loc->owner != NULL);
7330 if (loc->owner->type == bp_breakpoint
7331 || loc->owner->type == bp_hardware_breakpoint
7332 || is_tracepoint (loc->owner))
7335 const char *function_name;
7336 CORE_ADDR func_addr;
7338 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
7339 &func_addr, NULL, &is_gnu_ifunc);
7341 if (is_gnu_ifunc && !explicit_loc)
7343 struct breakpoint *b = loc->owner;
7345 gdb_assert (loc->pspace == current_program_space);
7346 if (gnu_ifunc_resolve_name (function_name,
7347 &loc->requested_address))
7349 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7350 loc->address = adjust_breakpoint_address (loc->gdbarch,
7351 loc->requested_address,
7354 else if (b->type == bp_breakpoint && b->loc == loc
7355 && loc->next == NULL && b->related_breakpoint == b)
7357 /* Create only the whole new breakpoint of this type but do not
7358 mess more complicated breakpoints with multiple locations. */
7359 b->type = bp_gnu_ifunc_resolver;
7360 /* Remember the resolver's address for use by the return
7362 loc->related_address = func_addr;
7367 loc->function_name = xstrdup (function_name);
7371 /* Attempt to determine architecture of location identified by SAL. */
7373 get_sal_arch (struct symtab_and_line sal)
7376 return get_objfile_arch (sal.section->objfile);
7378 return get_objfile_arch (sal.symtab->objfile);
7383 /* Low level routine for partially initializing a breakpoint of type
7384 BPTYPE. The newly created breakpoint's address, section, source
7385 file name, and line number are provided by SAL.
7387 It is expected that the caller will complete the initialization of
7388 the newly created breakpoint struct as well as output any status
7389 information regarding the creation of a new breakpoint. */
7392 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
7393 struct symtab_and_line sal, enum bptype bptype,
7394 const struct breakpoint_ops *ops)
7396 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7398 add_location_to_breakpoint (b, &sal);
7400 if (bptype != bp_catchpoint)
7401 gdb_assert (sal.pspace != NULL);
7403 /* Store the program space that was used to set the breakpoint,
7404 except for ordinary breakpoints, which are independent of the
7406 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
7407 b->pspace = sal.pspace;
7410 /* set_raw_breakpoint is a low level routine for allocating and
7411 partially initializing a breakpoint of type BPTYPE. The newly
7412 created breakpoint's address, section, source file name, and line
7413 number are provided by SAL. The newly created and partially
7414 initialized breakpoint is added to the breakpoint chain and
7415 is also returned as the value of this function.
7417 It is expected that the caller will complete the initialization of
7418 the newly created breakpoint struct as well as output any status
7419 information regarding the creation of a new breakpoint. In
7420 particular, set_raw_breakpoint does NOT set the breakpoint
7421 number! Care should be taken to not allow an error to occur
7422 prior to completing the initialization of the breakpoint. If this
7423 should happen, a bogus breakpoint will be left on the chain. */
7426 set_raw_breakpoint (struct gdbarch *gdbarch,
7427 struct symtab_and_line sal, enum bptype bptype,
7428 const struct breakpoint_ops *ops)
7430 struct breakpoint *b = XNEW (struct breakpoint);
7432 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
7433 add_to_breakpoint_chain (b);
7438 /* Note that the breakpoint object B describes a permanent breakpoint
7439 instruction, hard-wired into the inferior's code. */
7441 make_breakpoint_permanent (struct breakpoint *b)
7443 struct bp_location *bl;
7445 b->enable_state = bp_permanent;
7447 /* By definition, permanent breakpoints are already present in the
7448 code. Mark all locations as inserted. For now,
7449 make_breakpoint_permanent is called in just one place, so it's
7450 hard to say if it's reasonable to have permanent breakpoint with
7451 multiple locations or not, but it's easy to implement. */
7452 for (bl = b->loc; bl; bl = bl->next)
7456 /* Call this routine when stepping and nexting to enable a breakpoint
7457 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7458 initiated the operation. */
7461 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
7463 struct breakpoint *b, *b_tmp;
7464 int thread = tp->num;
7466 /* To avoid having to rescan all objfile symbols at every step,
7467 we maintain a list of continually-inserted but always disabled
7468 longjmp "master" breakpoints. Here, we simply create momentary
7469 clones of those and enable them for the requested thread. */
7470 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7471 if (b->pspace == current_program_space
7472 && (b->type == bp_longjmp_master
7473 || b->type == bp_exception_master))
7475 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
7476 struct breakpoint *clone;
7478 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7479 after their removal. */
7480 clone = momentary_breakpoint_from_master (b, type,
7481 &longjmp_breakpoint_ops, 1);
7482 clone->thread = thread;
7485 tp->initiating_frame = frame;
7488 /* Delete all longjmp breakpoints from THREAD. */
7490 delete_longjmp_breakpoint (int thread)
7492 struct breakpoint *b, *b_tmp;
7494 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7495 if (b->type == bp_longjmp || b->type == bp_exception)
7497 if (b->thread == thread)
7498 delete_breakpoint (b);
7503 delete_longjmp_breakpoint_at_next_stop (int thread)
7505 struct breakpoint *b, *b_tmp;
7507 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7508 if (b->type == bp_longjmp || b->type == bp_exception)
7510 if (b->thread == thread)
7511 b->disposition = disp_del_at_next_stop;
7515 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7516 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7517 pointer to any of them. Return NULL if this system cannot place longjmp
7521 set_longjmp_breakpoint_for_call_dummy (void)
7523 struct breakpoint *b, *retval = NULL;
7526 if (b->pspace == current_program_space && b->type == bp_longjmp_master)
7528 struct breakpoint *new_b;
7530 new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
7531 &momentary_breakpoint_ops,
7533 new_b->thread = pid_to_thread_id (inferior_ptid);
7535 /* Link NEW_B into the chain of RETVAL breakpoints. */
7537 gdb_assert (new_b->related_breakpoint == new_b);
7540 new_b->related_breakpoint = retval;
7541 while (retval->related_breakpoint != new_b->related_breakpoint)
7542 retval = retval->related_breakpoint;
7543 retval->related_breakpoint = new_b;
7549 /* Verify all existing dummy frames and their associated breakpoints for
7550 TP. Remove those which can no longer be found in the current frame
7553 You should call this function only at places where it is safe to currently
7554 unwind the whole stack. Failed stack unwind would discard live dummy
7558 check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp)
7560 struct breakpoint *b, *b_tmp;
7562 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7563 if (b->type == bp_longjmp_call_dummy && b->thread == tp->num)
7565 struct breakpoint *dummy_b = b->related_breakpoint;
7567 while (dummy_b != b && dummy_b->type != bp_call_dummy)
7568 dummy_b = dummy_b->related_breakpoint;
7569 if (dummy_b->type != bp_call_dummy
7570 || frame_find_by_id (dummy_b->frame_id) != NULL)
7573 dummy_frame_discard (dummy_b->frame_id, tp->ptid);
7575 while (b->related_breakpoint != b)
7577 if (b_tmp == b->related_breakpoint)
7578 b_tmp = b->related_breakpoint->next;
7579 delete_breakpoint (b->related_breakpoint);
7581 delete_breakpoint (b);
7586 enable_overlay_breakpoints (void)
7588 struct breakpoint *b;
7591 if (b->type == bp_overlay_event)
7593 b->enable_state = bp_enabled;
7594 update_global_location_list (UGLL_MAY_INSERT);
7595 overlay_events_enabled = 1;
7600 disable_overlay_breakpoints (void)
7602 struct breakpoint *b;
7605 if (b->type == bp_overlay_event)
7607 b->enable_state = bp_disabled;
7608 update_global_location_list (UGLL_DONT_INSERT);
7609 overlay_events_enabled = 0;
7613 /* Set an active std::terminate breakpoint for each std::terminate
7614 master breakpoint. */
7616 set_std_terminate_breakpoint (void)
7618 struct breakpoint *b, *b_tmp;
7620 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7621 if (b->pspace == current_program_space
7622 && b->type == bp_std_terminate_master)
7624 momentary_breakpoint_from_master (b, bp_std_terminate,
7625 &momentary_breakpoint_ops, 1);
7629 /* Delete all the std::terminate breakpoints. */
7631 delete_std_terminate_breakpoint (void)
7633 struct breakpoint *b, *b_tmp;
7635 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7636 if (b->type == bp_std_terminate)
7637 delete_breakpoint (b);
7641 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7643 struct breakpoint *b;
7645 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
7646 &internal_breakpoint_ops);
7648 b->enable_state = bp_enabled;
7649 /* addr_string has to be used or breakpoint_re_set will delete me. */
7651 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7653 update_global_location_list_nothrow (UGLL_MAY_INSERT);
7659 remove_thread_event_breakpoints (void)
7661 struct breakpoint *b, *b_tmp;
7663 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7664 if (b->type == bp_thread_event
7665 && b->loc->pspace == current_program_space)
7666 delete_breakpoint (b);
7669 struct lang_and_radix
7675 /* Create a breakpoint for JIT code registration and unregistration. */
7678 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7680 struct breakpoint *b;
7682 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
7683 &internal_breakpoint_ops);
7684 update_global_location_list_nothrow (UGLL_MAY_INSERT);
7688 /* Remove JIT code registration and unregistration breakpoint(s). */
7691 remove_jit_event_breakpoints (void)
7693 struct breakpoint *b, *b_tmp;
7695 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7696 if (b->type == bp_jit_event
7697 && b->loc->pspace == current_program_space)
7698 delete_breakpoint (b);
7702 remove_solib_event_breakpoints (void)
7704 struct breakpoint *b, *b_tmp;
7706 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7707 if (b->type == bp_shlib_event
7708 && b->loc->pspace == current_program_space)
7709 delete_breakpoint (b);
7712 /* See breakpoint.h. */
7715 remove_solib_event_breakpoints_at_next_stop (void)
7717 struct breakpoint *b, *b_tmp;
7719 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7720 if (b->type == bp_shlib_event
7721 && b->loc->pspace == current_program_space)
7722 b->disposition = disp_del_at_next_stop;
7726 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7728 struct breakpoint *b;
7730 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7731 &internal_breakpoint_ops);
7732 update_global_location_list_nothrow (UGLL_MAY_INSERT);
7736 /* See breakpoint.h. */
7739 create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7741 struct breakpoint *b;
7743 b = create_solib_event_breakpoint (gdbarch, address);
7744 if (!breakpoints_always_inserted_mode ())
7745 insert_breakpoint_locations ();
7746 if (!b->loc->inserted)
7748 delete_breakpoint (b);
7754 /* Disable any breakpoints that are on code in shared libraries. Only
7755 apply to enabled breakpoints, disabled ones can just stay disabled. */
7758 disable_breakpoints_in_shlibs (void)
7760 struct bp_location *loc, **locp_tmp;
7762 ALL_BP_LOCATIONS (loc, locp_tmp)
7764 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7765 struct breakpoint *b = loc->owner;
7767 /* We apply the check to all breakpoints, including disabled for
7768 those with loc->duplicate set. This is so that when breakpoint
7769 becomes enabled, or the duplicate is removed, gdb will try to
7770 insert all breakpoints. If we don't set shlib_disabled here,
7771 we'll try to insert those breakpoints and fail. */
7772 if (((b->type == bp_breakpoint)
7773 || (b->type == bp_jit_event)
7774 || (b->type == bp_hardware_breakpoint)
7775 || (is_tracepoint (b)))
7776 && loc->pspace == current_program_space
7777 && !loc->shlib_disabled
7778 && solib_name_from_address (loc->pspace, loc->address)
7781 loc->shlib_disabled = 1;
7786 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7787 notification of unloaded_shlib. Only apply to enabled breakpoints,
7788 disabled ones can just stay disabled. */
7791 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
7793 struct bp_location *loc, **locp_tmp;
7794 int disabled_shlib_breaks = 0;
7796 /* SunOS a.out shared libraries are always mapped, so do not
7797 disable breakpoints; they will only be reported as unloaded
7798 through clear_solib when GDB discards its shared library
7799 list. See clear_solib for more information. */
7800 if (exec_bfd != NULL
7801 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
7804 ALL_BP_LOCATIONS (loc, locp_tmp)
7806 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7807 struct breakpoint *b = loc->owner;
7809 if (solib->pspace == loc->pspace
7810 && !loc->shlib_disabled
7811 && (((b->type == bp_breakpoint
7812 || b->type == bp_jit_event
7813 || b->type == bp_hardware_breakpoint)
7814 && (loc->loc_type == bp_loc_hardware_breakpoint
7815 || loc->loc_type == bp_loc_software_breakpoint))
7816 || is_tracepoint (b))
7817 && solib_contains_address_p (solib, loc->address))
7819 loc->shlib_disabled = 1;
7820 /* At this point, we cannot rely on remove_breakpoint
7821 succeeding so we must mark the breakpoint as not inserted
7822 to prevent future errors occurring in remove_breakpoints. */
7825 /* This may cause duplicate notifications for the same breakpoint. */
7826 observer_notify_breakpoint_modified (b);
7828 if (!disabled_shlib_breaks)
7830 target_terminal_ours_for_output ();
7831 warning (_("Temporarily disabling breakpoints "
7832 "for unloaded shared library \"%s\""),
7835 disabled_shlib_breaks = 1;
7840 /* Disable any breakpoints and tracepoints in OBJFILE upon
7841 notification of free_objfile. Only apply to enabled breakpoints,
7842 disabled ones can just stay disabled. */
7845 disable_breakpoints_in_freed_objfile (struct objfile *objfile)
7847 struct breakpoint *b;
7849 if (objfile == NULL)
7852 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7853 managed by the user with add-symbol-file/remove-symbol-file.
7854 Similarly to how breakpoints in shared libraries are handled in
7855 response to "nosharedlibrary", mark breakpoints in such modules
7856 shlib_disabled so they end up uninserted on the next global
7857 location list update. Shared libraries not loaded by the user
7858 aren't handled here -- they're already handled in
7859 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7860 solib_unloaded observer. We skip objfiles that are not
7861 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7863 if ((objfile->flags & OBJF_SHARED) == 0
7864 || (objfile->flags & OBJF_USERLOADED) == 0)
7869 struct bp_location *loc;
7870 int bp_modified = 0;
7872 if (!is_breakpoint (b) && !is_tracepoint (b))
7875 for (loc = b->loc; loc != NULL; loc = loc->next)
7877 CORE_ADDR loc_addr = loc->address;
7879 if (loc->loc_type != bp_loc_hardware_breakpoint
7880 && loc->loc_type != bp_loc_software_breakpoint)
7883 if (loc->shlib_disabled != 0)
7886 if (objfile->pspace != loc->pspace)
7889 if (loc->loc_type != bp_loc_hardware_breakpoint
7890 && loc->loc_type != bp_loc_software_breakpoint)
7893 if (is_addr_in_objfile (loc_addr, objfile))
7895 loc->shlib_disabled = 1;
7896 /* At this point, we don't know whether the object was
7897 unmapped from the inferior or not, so leave the
7898 inserted flag alone. We'll handle failure to
7899 uninsert quietly, in case the object was indeed
7902 mark_breakpoint_location_modified (loc);
7909 observer_notify_breakpoint_modified (b);
7913 /* FORK & VFORK catchpoints. */
7915 /* An instance of this type is used to represent a fork or vfork
7916 catchpoint. It includes a "struct breakpoint" as a kind of base
7917 class; users downcast to "struct breakpoint *" when needed. A
7918 breakpoint is really of this type iff its ops pointer points to
7919 CATCH_FORK_BREAKPOINT_OPS. */
7921 struct fork_catchpoint
7923 /* The base class. */
7924 struct breakpoint base;
7926 /* Process id of a child process whose forking triggered this
7927 catchpoint. This field is only valid immediately after this
7928 catchpoint has triggered. */
7929 ptid_t forked_inferior_pid;
7932 /* Implement the "insert" breakpoint_ops method for fork
7936 insert_catch_fork (struct bp_location *bl)
7938 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid));
7941 /* Implement the "remove" breakpoint_ops method for fork
7945 remove_catch_fork (struct bp_location *bl)
7947 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid));
7950 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7954 breakpoint_hit_catch_fork (const struct bp_location *bl,
7955 struct address_space *aspace, CORE_ADDR bp_addr,
7956 const struct target_waitstatus *ws)
7958 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7960 if (ws->kind != TARGET_WAITKIND_FORKED)
7963 c->forked_inferior_pid = ws->value.related_pid;
7967 /* Implement the "print_it" breakpoint_ops method for fork
7970 static enum print_stop_action
7971 print_it_catch_fork (bpstat bs)
7973 struct ui_out *uiout = current_uiout;
7974 struct breakpoint *b = bs->breakpoint_at;
7975 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
7977 annotate_catchpoint (b->number);
7978 if (b->disposition == disp_del)
7979 ui_out_text (uiout, "\nTemporary catchpoint ");
7981 ui_out_text (uiout, "\nCatchpoint ");
7982 if (ui_out_is_mi_like_p (uiout))
7984 ui_out_field_string (uiout, "reason",
7985 async_reason_lookup (EXEC_ASYNC_FORK));
7986 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7988 ui_out_field_int (uiout, "bkptno", b->number);
7989 ui_out_text (uiout, " (forked process ");
7990 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7991 ui_out_text (uiout, "), ");
7992 return PRINT_SRC_AND_LOC;
7995 /* Implement the "print_one" breakpoint_ops method for fork
7999 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
8001 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8002 struct value_print_options opts;
8003 struct ui_out *uiout = current_uiout;
8005 get_user_print_options (&opts);
8007 /* Field 4, the address, is omitted (which makes the columns not
8008 line up too nicely with the headers, but the effect is relatively
8010 if (opts.addressprint)
8011 ui_out_field_skip (uiout, "addr");
8013 ui_out_text (uiout, "fork");
8014 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
8016 ui_out_text (uiout, ", process ");
8017 ui_out_field_int (uiout, "what",
8018 ptid_get_pid (c->forked_inferior_pid));
8019 ui_out_spaces (uiout, 1);
8022 if (ui_out_is_mi_like_p (uiout))
8023 ui_out_field_string (uiout, "catch-type", "fork");
8026 /* Implement the "print_mention" breakpoint_ops method for fork
8030 print_mention_catch_fork (struct breakpoint *b)
8032 printf_filtered (_("Catchpoint %d (fork)"), b->number);
8035 /* Implement the "print_recreate" breakpoint_ops method for fork
8039 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
8041 fprintf_unfiltered (fp, "catch fork");
8042 print_recreate_thread (b, fp);
8045 /* The breakpoint_ops structure to be used in fork catchpoints. */
8047 static struct breakpoint_ops catch_fork_breakpoint_ops;
8049 /* Implement the "insert" breakpoint_ops method for vfork
8053 insert_catch_vfork (struct bp_location *bl)
8055 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid));
8058 /* Implement the "remove" breakpoint_ops method for vfork
8062 remove_catch_vfork (struct bp_location *bl)
8064 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid));
8067 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8071 breakpoint_hit_catch_vfork (const struct bp_location *bl,
8072 struct address_space *aspace, CORE_ADDR bp_addr,
8073 const struct target_waitstatus *ws)
8075 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
8077 if (ws->kind != TARGET_WAITKIND_VFORKED)
8080 c->forked_inferior_pid = ws->value.related_pid;
8084 /* Implement the "print_it" breakpoint_ops method for vfork
8087 static enum print_stop_action
8088 print_it_catch_vfork (bpstat bs)
8090 struct ui_out *uiout = current_uiout;
8091 struct breakpoint *b = bs->breakpoint_at;
8092 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8094 annotate_catchpoint (b->number);
8095 if (b->disposition == disp_del)
8096 ui_out_text (uiout, "\nTemporary catchpoint ");
8098 ui_out_text (uiout, "\nCatchpoint ");
8099 if (ui_out_is_mi_like_p (uiout))
8101 ui_out_field_string (uiout, "reason",
8102 async_reason_lookup (EXEC_ASYNC_VFORK));
8103 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8105 ui_out_field_int (uiout, "bkptno", b->number);
8106 ui_out_text (uiout, " (vforked process ");
8107 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
8108 ui_out_text (uiout, "), ");
8109 return PRINT_SRC_AND_LOC;
8112 /* Implement the "print_one" breakpoint_ops method for vfork
8116 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
8118 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8119 struct value_print_options opts;
8120 struct ui_out *uiout = current_uiout;
8122 get_user_print_options (&opts);
8123 /* Field 4, the address, is omitted (which makes the columns not
8124 line up too nicely with the headers, but the effect is relatively
8126 if (opts.addressprint)
8127 ui_out_field_skip (uiout, "addr");
8129 ui_out_text (uiout, "vfork");
8130 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
8132 ui_out_text (uiout, ", process ");
8133 ui_out_field_int (uiout, "what",
8134 ptid_get_pid (c->forked_inferior_pid));
8135 ui_out_spaces (uiout, 1);
8138 if (ui_out_is_mi_like_p (uiout))
8139 ui_out_field_string (uiout, "catch-type", "vfork");
8142 /* Implement the "print_mention" breakpoint_ops method for vfork
8146 print_mention_catch_vfork (struct breakpoint *b)
8148 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
8151 /* Implement the "print_recreate" breakpoint_ops method for vfork
8155 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
8157 fprintf_unfiltered (fp, "catch vfork");
8158 print_recreate_thread (b, fp);
8161 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8163 static struct breakpoint_ops catch_vfork_breakpoint_ops;
8165 /* An instance of this type is used to represent an solib catchpoint.
8166 It includes a "struct breakpoint" as a kind of base class; users
8167 downcast to "struct breakpoint *" when needed. A breakpoint is
8168 really of this type iff its ops pointer points to
8169 CATCH_SOLIB_BREAKPOINT_OPS. */
8171 struct solib_catchpoint
8173 /* The base class. */
8174 struct breakpoint base;
8176 /* True for "catch load", false for "catch unload". */
8177 unsigned char is_load;
8179 /* Regular expression to match, if any. COMPILED is only valid when
8180 REGEX is non-NULL. */
8186 dtor_catch_solib (struct breakpoint *b)
8188 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8191 regfree (&self->compiled);
8192 xfree (self->regex);
8194 base_breakpoint_ops.dtor (b);
8198 insert_catch_solib (struct bp_location *ignore)
8204 remove_catch_solib (struct bp_location *ignore)
8210 breakpoint_hit_catch_solib (const struct bp_location *bl,
8211 struct address_space *aspace,
8213 const struct target_waitstatus *ws)
8215 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
8216 struct breakpoint *other;
8218 if (ws->kind == TARGET_WAITKIND_LOADED)
8221 ALL_BREAKPOINTS (other)
8223 struct bp_location *other_bl;
8225 if (other == bl->owner)
8228 if (other->type != bp_shlib_event)
8231 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
8234 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
8236 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
8245 check_status_catch_solib (struct bpstats *bs)
8247 struct solib_catchpoint *self
8248 = (struct solib_catchpoint *) bs->breakpoint_at;
8253 struct so_list *iter;
8256 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
8261 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
8270 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
8275 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
8281 bs->print_it = print_it_noop;
8284 static enum print_stop_action
8285 print_it_catch_solib (bpstat bs)
8287 struct breakpoint *b = bs->breakpoint_at;
8288 struct ui_out *uiout = current_uiout;
8290 annotate_catchpoint (b->number);
8291 if (b->disposition == disp_del)
8292 ui_out_text (uiout, "\nTemporary catchpoint ");
8294 ui_out_text (uiout, "\nCatchpoint ");
8295 ui_out_field_int (uiout, "bkptno", b->number);
8296 ui_out_text (uiout, "\n");
8297 if (ui_out_is_mi_like_p (uiout))
8298 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8299 print_solib_event (1);
8300 return PRINT_SRC_AND_LOC;
8304 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
8306 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8307 struct value_print_options opts;
8308 struct ui_out *uiout = current_uiout;
8311 get_user_print_options (&opts);
8312 /* Field 4, the address, is omitted (which makes the columns not
8313 line up too nicely with the headers, but the effect is relatively
8315 if (opts.addressprint)
8318 ui_out_field_skip (uiout, "addr");
8325 msg = xstrprintf (_("load of library matching %s"), self->regex);
8327 msg = xstrdup (_("load of library"));
8332 msg = xstrprintf (_("unload of library matching %s"), self->regex);
8334 msg = xstrdup (_("unload of library"));
8336 ui_out_field_string (uiout, "what", msg);
8339 if (ui_out_is_mi_like_p (uiout))
8340 ui_out_field_string (uiout, "catch-type",
8341 self->is_load ? "load" : "unload");
8345 print_mention_catch_solib (struct breakpoint *b)
8347 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8349 printf_filtered (_("Catchpoint %d (%s)"), b->number,
8350 self->is_load ? "load" : "unload");
8354 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
8356 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8358 fprintf_unfiltered (fp, "%s %s",
8359 b->disposition == disp_del ? "tcatch" : "catch",
8360 self->is_load ? "load" : "unload");
8362 fprintf_unfiltered (fp, " %s", self->regex);
8363 fprintf_unfiltered (fp, "\n");
8366 static struct breakpoint_ops catch_solib_breakpoint_ops;
8368 /* Shared helper function (MI and CLI) for creating and installing
8369 a shared object event catchpoint. If IS_LOAD is non-zero then
8370 the events to be caught are load events, otherwise they are
8371 unload events. If IS_TEMP is non-zero the catchpoint is a
8372 temporary one. If ENABLED is non-zero the catchpoint is
8373 created in an enabled state. */
8376 add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled)
8378 struct solib_catchpoint *c;
8379 struct gdbarch *gdbarch = get_current_arch ();
8380 struct cleanup *cleanup;
8384 arg = skip_spaces (arg);
8386 c = XCNEW (struct solib_catchpoint);
8387 cleanup = make_cleanup (xfree, c);
8393 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
8396 char *err = get_regcomp_error (errcode, &c->compiled);
8398 make_cleanup (xfree, err);
8399 error (_("Invalid regexp (%s): %s"), err, arg);
8401 c->regex = xstrdup (arg);
8404 c->is_load = is_load;
8405 init_catchpoint (&c->base, gdbarch, is_temp, NULL,
8406 &catch_solib_breakpoint_ops);
8408 c->base.enable_state = enabled ? bp_enabled : bp_disabled;
8410 discard_cleanups (cleanup);
8411 install_breakpoint (0, &c->base, 1);
8414 /* A helper function that does all the work for "catch load" and
8418 catch_load_or_unload (char *arg, int from_tty, int is_load,
8419 struct cmd_list_element *command)
8422 const int enabled = 1;
8424 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8426 add_solib_catchpoint (arg, is_load, tempflag, enabled);
8430 catch_load_command_1 (char *arg, int from_tty,
8431 struct cmd_list_element *command)
8433 catch_load_or_unload (arg, from_tty, 1, command);
8437 catch_unload_command_1 (char *arg, int from_tty,
8438 struct cmd_list_element *command)
8440 catch_load_or_unload (arg, from_tty, 0, command);
8443 /* An instance of this type is used to represent a syscall catchpoint.
8444 It includes a "struct breakpoint" as a kind of base class; users
8445 downcast to "struct breakpoint *" when needed. A breakpoint is
8446 really of this type iff its ops pointer points to
8447 CATCH_SYSCALL_BREAKPOINT_OPS. */
8449 struct syscall_catchpoint
8451 /* The base class. */
8452 struct breakpoint base;
8454 /* Syscall numbers used for the 'catch syscall' feature. If no
8455 syscall has been specified for filtering, its value is NULL.
8456 Otherwise, it holds a list of all syscalls to be caught. The
8457 list elements are allocated with xmalloc. */
8458 VEC(int) *syscalls_to_be_caught;
8461 /* Implement the "dtor" breakpoint_ops method for syscall
8465 dtor_catch_syscall (struct breakpoint *b)
8467 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8469 VEC_free (int, c->syscalls_to_be_caught);
8471 base_breakpoint_ops.dtor (b);
8474 static const struct inferior_data *catch_syscall_inferior_data = NULL;
8476 struct catch_syscall_inferior_data
8478 /* We keep a count of the number of times the user has requested a
8479 particular syscall to be tracked, and pass this information to the
8480 target. This lets capable targets implement filtering directly. */
8482 /* Number of times that "any" syscall is requested. */
8483 int any_syscall_count;
8485 /* Count of each system call. */
8486 VEC(int) *syscalls_counts;
8488 /* This counts all syscall catch requests, so we can readily determine
8489 if any catching is necessary. */
8490 int total_syscalls_count;
8493 static struct catch_syscall_inferior_data*
8494 get_catch_syscall_inferior_data (struct inferior *inf)
8496 struct catch_syscall_inferior_data *inf_data;
8498 inf_data = inferior_data (inf, catch_syscall_inferior_data);
8499 if (inf_data == NULL)
8501 inf_data = XCNEW (struct catch_syscall_inferior_data);
8502 set_inferior_data (inf, catch_syscall_inferior_data, inf_data);
8509 catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg)
8515 /* Implement the "insert" breakpoint_ops method for syscall
8519 insert_catch_syscall (struct bp_location *bl)
8521 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
8522 struct inferior *inf = current_inferior ();
8523 struct catch_syscall_inferior_data *inf_data
8524 = get_catch_syscall_inferior_data (inf);
8526 ++inf_data->total_syscalls_count;
8527 if (!c->syscalls_to_be_caught)
8528 ++inf_data->any_syscall_count;
8534 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8539 if (iter >= VEC_length (int, inf_data->syscalls_counts))
8541 int old_size = VEC_length (int, inf_data->syscalls_counts);
8542 uintptr_t vec_addr_offset
8543 = old_size * ((uintptr_t) sizeof (int));
8545 VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1);
8546 vec_addr = ((uintptr_t) VEC_address (int,
8547 inf_data->syscalls_counts)
8549 memset ((void *) vec_addr, 0,
8550 (iter + 1 - old_size) * sizeof (int));
8552 elem = VEC_index (int, inf_data->syscalls_counts, iter);
8553 VEC_replace (int, inf_data->syscalls_counts, iter, ++elem);
8557 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid),
8558 inf_data->total_syscalls_count != 0,
8559 inf_data->any_syscall_count,
8561 inf_data->syscalls_counts),
8563 inf_data->syscalls_counts));
8566 /* Implement the "remove" breakpoint_ops method for syscall
8570 remove_catch_syscall (struct bp_location *bl)
8572 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
8573 struct inferior *inf = current_inferior ();
8574 struct catch_syscall_inferior_data *inf_data
8575 = get_catch_syscall_inferior_data (inf);
8577 --inf_data->total_syscalls_count;
8578 if (!c->syscalls_to_be_caught)
8579 --inf_data->any_syscall_count;
8585 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8589 if (iter >= VEC_length (int, inf_data->syscalls_counts))
8590 /* Shouldn't happen. */
8592 elem = VEC_index (int, inf_data->syscalls_counts, iter);
8593 VEC_replace (int, inf_data->syscalls_counts, iter, --elem);
8597 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid),
8598 inf_data->total_syscalls_count != 0,
8599 inf_data->any_syscall_count,
8601 inf_data->syscalls_counts),
8603 inf_data->syscalls_counts));
8606 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
8610 breakpoint_hit_catch_syscall (const struct bp_location *bl,
8611 struct address_space *aspace, CORE_ADDR bp_addr,
8612 const struct target_waitstatus *ws)
8614 /* We must check if we are catching specific syscalls in this
8615 breakpoint. If we are, then we must guarantee that the called
8616 syscall is the same syscall we are catching. */
8617 int syscall_number = 0;
8618 const struct syscall_catchpoint *c
8619 = (const struct syscall_catchpoint *) bl->owner;
8621 if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY
8622 && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN)
8625 syscall_number = ws->value.syscall_number;
8627 /* Now, checking if the syscall is the same. */
8628 if (c->syscalls_to_be_caught)
8633 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8635 if (syscall_number == iter)
8644 /* Implement the "print_it" breakpoint_ops method for syscall
8647 static enum print_stop_action
8648 print_it_catch_syscall (bpstat bs)
8650 struct ui_out *uiout = current_uiout;
8651 struct breakpoint *b = bs->breakpoint_at;
8652 /* These are needed because we want to know in which state a
8653 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
8654 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
8655 must print "called syscall" or "returned from syscall". */
8657 struct target_waitstatus last;
8660 get_last_target_status (&ptid, &last);
8662 get_syscall_by_number (last.value.syscall_number, &s);
8664 annotate_catchpoint (b->number);
8666 if (b->disposition == disp_del)
8667 ui_out_text (uiout, "\nTemporary catchpoint ");
8669 ui_out_text (uiout, "\nCatchpoint ");
8670 if (ui_out_is_mi_like_p (uiout))
8672 ui_out_field_string (uiout, "reason",
8673 async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY
8674 ? EXEC_ASYNC_SYSCALL_ENTRY
8675 : EXEC_ASYNC_SYSCALL_RETURN));
8676 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8678 ui_out_field_int (uiout, "bkptno", b->number);
8680 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
8681 ui_out_text (uiout, " (call to syscall ");
8683 ui_out_text (uiout, " (returned from syscall ");
8685 if (s.name == NULL || ui_out_is_mi_like_p (uiout))
8686 ui_out_field_int (uiout, "syscall-number", last.value.syscall_number);
8688 ui_out_field_string (uiout, "syscall-name", s.name);
8690 ui_out_text (uiout, "), ");
8692 return PRINT_SRC_AND_LOC;
8695 /* Implement the "print_one" breakpoint_ops method for syscall
8699 print_one_catch_syscall (struct breakpoint *b,
8700 struct bp_location **last_loc)
8702 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8703 struct value_print_options opts;
8704 struct ui_out *uiout = current_uiout;
8706 get_user_print_options (&opts);
8707 /* Field 4, the address, is omitted (which makes the columns not
8708 line up too nicely with the headers, but the effect is relatively
8710 if (opts.addressprint)
8711 ui_out_field_skip (uiout, "addr");
8714 if (c->syscalls_to_be_caught
8715 && VEC_length (int, c->syscalls_to_be_caught) > 1)
8716 ui_out_text (uiout, "syscalls \"");
8718 ui_out_text (uiout, "syscall \"");
8720 if (c->syscalls_to_be_caught)
8723 char *text = xstrprintf ("%s", "");
8726 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8731 get_syscall_by_number (iter, &s);
8734 text = xstrprintf ("%s%s, ", text, s.name);
8736 text = xstrprintf ("%s%d, ", text, iter);
8738 /* We have to xfree the last 'text' (now stored at 'x')
8739 because xstrprintf dynamically allocates new space for it
8743 /* Remove the last comma. */
8744 text[strlen (text) - 2] = '\0';
8745 ui_out_field_string (uiout, "what", text);
8748 ui_out_field_string (uiout, "what", "<any syscall>");
8749 ui_out_text (uiout, "\" ");
8751 if (ui_out_is_mi_like_p (uiout))
8752 ui_out_field_string (uiout, "catch-type", "syscall");
8755 /* Implement the "print_mention" breakpoint_ops method for syscall
8759 print_mention_catch_syscall (struct breakpoint *b)
8761 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8763 if (c->syscalls_to_be_caught)
8767 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
8768 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
8770 printf_filtered (_("Catchpoint %d (syscall"), b->number);
8773 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8777 get_syscall_by_number (iter, &s);
8780 printf_filtered (" '%s' [%d]", s.name, s.number);
8782 printf_filtered (" %d", s.number);
8784 printf_filtered (")");
8787 printf_filtered (_("Catchpoint %d (any syscall)"),
8791 /* Implement the "print_recreate" breakpoint_ops method for syscall
8795 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
8797 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8799 fprintf_unfiltered (fp, "catch syscall");
8801 if (c->syscalls_to_be_caught)
8806 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8811 get_syscall_by_number (iter, &s);
8813 fprintf_unfiltered (fp, " %s", s.name);
8815 fprintf_unfiltered (fp, " %d", s.number);
8818 print_recreate_thread (b, fp);
8821 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8823 static struct breakpoint_ops catch_syscall_breakpoint_ops;
8825 /* Returns non-zero if 'b' is a syscall catchpoint. */
8828 syscall_catchpoint_p (struct breakpoint *b)
8830 return (b->ops == &catch_syscall_breakpoint_ops);
8833 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8834 is non-zero, then make the breakpoint temporary. If COND_STRING is
8835 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8836 the breakpoint_ops structure associated to the catchpoint. */
8839 init_catchpoint (struct breakpoint *b,
8840 struct gdbarch *gdbarch, int tempflag,
8842 const struct breakpoint_ops *ops)
8844 struct symtab_and_line sal;
8847 sal.pspace = current_program_space;
8849 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
8851 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
8852 b->disposition = tempflag ? disp_del : disp_donttouch;
8856 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
8858 add_to_breakpoint_chain (b);
8859 set_breakpoint_number (internal, b);
8860 if (is_tracepoint (b))
8861 set_tracepoint_count (breakpoint_count);
8864 observer_notify_breakpoint_created (b);
8867 update_global_location_list (UGLL_MAY_INSERT);
8871 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
8872 int tempflag, char *cond_string,
8873 const struct breakpoint_ops *ops)
8875 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
8877 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
8879 c->forked_inferior_pid = null_ptid;
8881 install_breakpoint (0, &c->base, 1);
8884 /* Exec catchpoints. */
8886 /* An instance of this type is used to represent an exec catchpoint.
8887 It includes a "struct breakpoint" as a kind of base class; users
8888 downcast to "struct breakpoint *" when needed. A breakpoint is
8889 really of this type iff its ops pointer points to
8890 CATCH_EXEC_BREAKPOINT_OPS. */
8892 struct exec_catchpoint
8894 /* The base class. */
8895 struct breakpoint base;
8897 /* Filename of a program whose exec triggered this catchpoint.
8898 This field is only valid immediately after this catchpoint has
8900 char *exec_pathname;
8903 /* Implement the "dtor" breakpoint_ops method for exec
8907 dtor_catch_exec (struct breakpoint *b)
8909 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8911 xfree (c->exec_pathname);
8913 base_breakpoint_ops.dtor (b);
8917 insert_catch_exec (struct bp_location *bl)
8919 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid));
8923 remove_catch_exec (struct bp_location *bl)
8925 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid));
8929 breakpoint_hit_catch_exec (const struct bp_location *bl,
8930 struct address_space *aspace, CORE_ADDR bp_addr,
8931 const struct target_waitstatus *ws)
8933 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8935 if (ws->kind != TARGET_WAITKIND_EXECD)
8938 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8942 static enum print_stop_action
8943 print_it_catch_exec (bpstat bs)
8945 struct ui_out *uiout = current_uiout;
8946 struct breakpoint *b = bs->breakpoint_at;
8947 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8949 annotate_catchpoint (b->number);
8950 if (b->disposition == disp_del)
8951 ui_out_text (uiout, "\nTemporary catchpoint ");
8953 ui_out_text (uiout, "\nCatchpoint ");
8954 if (ui_out_is_mi_like_p (uiout))
8956 ui_out_field_string (uiout, "reason",
8957 async_reason_lookup (EXEC_ASYNC_EXEC));
8958 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8960 ui_out_field_int (uiout, "bkptno", b->number);
8961 ui_out_text (uiout, " (exec'd ");
8962 ui_out_field_string (uiout, "new-exec", c->exec_pathname);
8963 ui_out_text (uiout, "), ");
8965 return PRINT_SRC_AND_LOC;
8969 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8971 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8972 struct value_print_options opts;
8973 struct ui_out *uiout = current_uiout;
8975 get_user_print_options (&opts);
8977 /* Field 4, the address, is omitted (which makes the columns
8978 not line up too nicely with the headers, but the effect
8979 is relatively readable). */
8980 if (opts.addressprint)
8981 ui_out_field_skip (uiout, "addr");
8983 ui_out_text (uiout, "exec");
8984 if (c->exec_pathname != NULL)
8986 ui_out_text (uiout, ", program \"");
8987 ui_out_field_string (uiout, "what", c->exec_pathname);
8988 ui_out_text (uiout, "\" ");
8991 if (ui_out_is_mi_like_p (uiout))
8992 ui_out_field_string (uiout, "catch-type", "exec");
8996 print_mention_catch_exec (struct breakpoint *b)
8998 printf_filtered (_("Catchpoint %d (exec)"), b->number);
9001 /* Implement the "print_recreate" breakpoint_ops method for exec
9005 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
9007 fprintf_unfiltered (fp, "catch exec");
9008 print_recreate_thread (b, fp);
9011 static struct breakpoint_ops catch_exec_breakpoint_ops;
9014 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
9015 const struct breakpoint_ops *ops)
9017 struct syscall_catchpoint *c;
9018 struct gdbarch *gdbarch = get_current_arch ();
9020 c = XNEW (struct syscall_catchpoint);
9021 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
9022 c->syscalls_to_be_caught = filter;
9024 install_breakpoint (0, &c->base, 1);
9028 hw_breakpoint_used_count (void)
9031 struct breakpoint *b;
9032 struct bp_location *bl;
9036 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
9037 for (bl = b->loc; bl; bl = bl->next)
9039 /* Special types of hardware breakpoints may use more than
9041 i += b->ops->resources_needed (bl);
9048 /* Returns the resources B would use if it were a hardware
9052 hw_watchpoint_use_count (struct breakpoint *b)
9055 struct bp_location *bl;
9057 if (!breakpoint_enabled (b))
9060 for (bl = b->loc; bl; bl = bl->next)
9062 /* Special types of hardware watchpoints may use more than
9064 i += b->ops->resources_needed (bl);
9070 /* Returns the sum the used resources of all hardware watchpoints of
9071 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
9072 the sum of the used resources of all hardware watchpoints of other
9073 types _not_ TYPE. */
9076 hw_watchpoint_used_count_others (struct breakpoint *except,
9077 enum bptype type, int *other_type_used)
9080 struct breakpoint *b;
9082 *other_type_used = 0;
9087 if (!breakpoint_enabled (b))
9090 if (b->type == type)
9091 i += hw_watchpoint_use_count (b);
9092 else if (is_hardware_watchpoint (b))
9093 *other_type_used = 1;
9100 disable_watchpoints_before_interactive_call_start (void)
9102 struct breakpoint *b;
9106 if (is_watchpoint (b) && breakpoint_enabled (b))
9108 b->enable_state = bp_call_disabled;
9109 update_global_location_list (UGLL_DONT_INSERT);
9115 enable_watchpoints_after_interactive_call_stop (void)
9117 struct breakpoint *b;
9121 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
9123 b->enable_state = bp_enabled;
9124 update_global_location_list (UGLL_MAY_INSERT);
9130 disable_breakpoints_before_startup (void)
9132 current_program_space->executing_startup = 1;
9133 update_global_location_list (UGLL_DONT_INSERT);
9137 enable_breakpoints_after_startup (void)
9139 current_program_space->executing_startup = 0;
9140 breakpoint_re_set ();
9144 /* Set a breakpoint that will evaporate an end of command
9145 at address specified by SAL.
9146 Restrict it to frame FRAME if FRAME is nonzero. */
9149 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
9150 struct frame_id frame_id, enum bptype type)
9152 struct breakpoint *b;
9154 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
9156 gdb_assert (!frame_id_artificial_p (frame_id));
9158 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
9159 b->enable_state = bp_enabled;
9160 b->disposition = disp_donttouch;
9161 b->frame_id = frame_id;
9163 /* If we're debugging a multi-threaded program, then we want
9164 momentary breakpoints to be active in only a single thread of
9166 if (in_thread_list (inferior_ptid))
9167 b->thread = pid_to_thread_id (inferior_ptid);
9169 update_global_location_list_nothrow (UGLL_MAY_INSERT);
9174 /* Make a momentary breakpoint based on the master breakpoint ORIG.
9175 The new breakpoint will have type TYPE, use OPS as its
9176 breakpoint_ops, and will set enabled to LOC_ENABLED. */
9178 static struct breakpoint *
9179 momentary_breakpoint_from_master (struct breakpoint *orig,
9181 const struct breakpoint_ops *ops,
9184 struct breakpoint *copy;
9186 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
9187 copy->loc = allocate_bp_location (copy);
9188 set_breakpoint_location_function (copy->loc, 1);
9190 copy->loc->gdbarch = orig->loc->gdbarch;
9191 copy->loc->requested_address = orig->loc->requested_address;
9192 copy->loc->address = orig->loc->address;
9193 copy->loc->section = orig->loc->section;
9194 copy->loc->pspace = orig->loc->pspace;
9195 copy->loc->probe = orig->loc->probe;
9196 copy->loc->line_number = orig->loc->line_number;
9197 copy->loc->symtab = orig->loc->symtab;
9198 copy->loc->enabled = loc_enabled;
9199 copy->frame_id = orig->frame_id;
9200 copy->thread = orig->thread;
9201 copy->pspace = orig->pspace;
9203 copy->enable_state = bp_enabled;
9204 copy->disposition = disp_donttouch;
9205 copy->number = internal_breakpoint_number--;
9207 update_global_location_list_nothrow (UGLL_DONT_INSERT);
9211 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
9215 clone_momentary_breakpoint (struct breakpoint *orig)
9217 /* If there's nothing to clone, then return nothing. */
9221 return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
9225 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
9228 struct symtab_and_line sal;
9230 sal = find_pc_line (pc, 0);
9232 sal.section = find_pc_overlay (pc);
9233 sal.explicit_pc = 1;
9235 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
9239 /* Tell the user we have just set a breakpoint B. */
9242 mention (struct breakpoint *b)
9244 b->ops->print_mention (b);
9245 if (ui_out_is_mi_like_p (current_uiout))
9247 printf_filtered ("\n");
9251 static struct bp_location *
9252 add_location_to_breakpoint (struct breakpoint *b,
9253 const struct symtab_and_line *sal)
9255 struct bp_location *loc, **tmp;
9256 CORE_ADDR adjusted_address;
9257 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
9259 if (loc_gdbarch == NULL)
9260 loc_gdbarch = b->gdbarch;
9262 /* Adjust the breakpoint's address prior to allocating a location.
9263 Once we call allocate_bp_location(), that mostly uninitialized
9264 location will be placed on the location chain. Adjustment of the
9265 breakpoint may cause target_read_memory() to be called and we do
9266 not want its scan of the location chain to find a breakpoint and
9267 location that's only been partially initialized. */
9268 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
9271 /* Sort the locations by their ADDRESS. */
9272 loc = allocate_bp_location (b);
9273 for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
9274 tmp = &((*tmp)->next))
9279 loc->requested_address = sal->pc;
9280 loc->address = adjusted_address;
9281 loc->pspace = sal->pspace;
9282 loc->probe.probe = sal->probe;
9283 loc->probe.objfile = sal->objfile;
9284 gdb_assert (loc->pspace != NULL);
9285 loc->section = sal->section;
9286 loc->gdbarch = loc_gdbarch;
9287 loc->line_number = sal->line;
9288 loc->symtab = sal->symtab;
9290 set_breakpoint_location_function (loc,
9291 sal->explicit_pc || sal->explicit_line);
9296 /* Return 1 if LOC is pointing to a permanent breakpoint,
9297 return 0 otherwise. */
9300 bp_loc_is_permanent (struct bp_location *loc)
9304 const gdb_byte *bpoint;
9305 gdb_byte *target_mem;
9306 struct cleanup *cleanup;
9309 gdb_assert (loc != NULL);
9311 addr = loc->address;
9312 bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
9314 /* Software breakpoints unsupported? */
9318 target_mem = alloca (len);
9320 /* Enable the automatic memory restoration from breakpoints while
9321 we read the memory. Otherwise we could say about our temporary
9322 breakpoints they are permanent. */
9323 cleanup = save_current_space_and_thread ();
9325 switch_to_program_space_and_thread (loc->pspace);
9326 make_show_memory_breakpoints_cleanup (0);
9328 if (target_read_memory (loc->address, target_mem, len) == 0
9329 && memcmp (target_mem, bpoint, len) == 0)
9332 do_cleanups (cleanup);
9337 /* Build a command list for the dprintf corresponding to the current
9338 settings of the dprintf style options. */
9341 update_dprintf_command_list (struct breakpoint *b)
9343 char *dprintf_args = b->extra_string;
9344 char *printf_line = NULL;
9349 dprintf_args = skip_spaces (dprintf_args);
9351 /* Allow a comma, as it may have terminated a location, but don't
9353 if (*dprintf_args == ',')
9355 dprintf_args = skip_spaces (dprintf_args);
9357 if (*dprintf_args != '"')
9358 error (_("Bad format string, missing '\"'."));
9360 if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
9361 printf_line = xstrprintf ("printf %s", dprintf_args);
9362 else if (strcmp (dprintf_style, dprintf_style_call) == 0)
9364 if (!dprintf_function)
9365 error (_("No function supplied for dprintf call"));
9367 if (dprintf_channel && strlen (dprintf_channel) > 0)
9368 printf_line = xstrprintf ("call (void) %s (%s,%s)",
9373 printf_line = xstrprintf ("call (void) %s (%s)",
9377 else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
9379 if (target_can_run_breakpoint_commands ())
9380 printf_line = xstrprintf ("agent-printf %s", dprintf_args);
9383 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9384 printf_line = xstrprintf ("printf %s", dprintf_args);
9388 internal_error (__FILE__, __LINE__,
9389 _("Invalid dprintf style."));
9391 gdb_assert (printf_line != NULL);
9392 /* Manufacture a printf sequence. */
9394 struct command_line *printf_cmd_line
9395 = xmalloc (sizeof (struct command_line));
9397 printf_cmd_line = xmalloc (sizeof (struct command_line));
9398 printf_cmd_line->control_type = simple_control;
9399 printf_cmd_line->body_count = 0;
9400 printf_cmd_line->body_list = NULL;
9401 printf_cmd_line->next = NULL;
9402 printf_cmd_line->line = printf_line;
9404 breakpoint_set_commands (b, printf_cmd_line);
9408 /* Update all dprintf commands, making their command lists reflect
9409 current style settings. */
9412 update_dprintf_commands (char *args, int from_tty,
9413 struct cmd_list_element *c)
9415 struct breakpoint *b;
9419 if (b->type == bp_dprintf)
9420 update_dprintf_command_list (b);
9424 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9425 as textual description of the location, and COND_STRING
9426 as condition expression. */
9429 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
9430 struct symtabs_and_lines sals, char *addr_string,
9431 char *filter, char *cond_string,
9433 enum bptype type, enum bpdisp disposition,
9434 int thread, int task, int ignore_count,
9435 const struct breakpoint_ops *ops, int from_tty,
9436 int enabled, int internal, unsigned flags,
9437 int display_canonical)
9441 if (type == bp_hardware_breakpoint)
9443 int target_resources_ok;
9445 i = hw_breakpoint_used_count ();
9446 target_resources_ok =
9447 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9449 if (target_resources_ok == 0)
9450 error (_("No hardware breakpoint support in the target."));
9451 else if (target_resources_ok < 0)
9452 error (_("Hardware breakpoints used exceeds limit."));
9455 gdb_assert (sals.nelts > 0);
9457 for (i = 0; i < sals.nelts; ++i)
9459 struct symtab_and_line sal = sals.sals[i];
9460 struct bp_location *loc;
9464 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
9466 loc_gdbarch = gdbarch;
9468 describe_other_breakpoints (loc_gdbarch,
9469 sal.pspace, sal.pc, sal.section, thread);
9474 init_raw_breakpoint (b, gdbarch, sal, type, ops);
9478 b->cond_string = cond_string;
9479 b->extra_string = extra_string;
9480 b->ignore_count = ignore_count;
9481 b->enable_state = enabled ? bp_enabled : bp_disabled;
9482 b->disposition = disposition;
9484 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9485 b->loc->inserted = 1;
9487 if (type == bp_static_tracepoint)
9489 struct tracepoint *t = (struct tracepoint *) b;
9490 struct static_tracepoint_marker marker;
9492 if (strace_marker_p (b))
9494 /* We already know the marker exists, otherwise, we
9495 wouldn't see a sal for it. */
9496 char *p = &addr_string[3];
9500 p = skip_spaces (p);
9502 endp = skip_to_space (p);
9504 marker_str = savestring (p, endp - p);
9505 t->static_trace_marker_id = marker_str;
9507 printf_filtered (_("Probed static tracepoint "
9509 t->static_trace_marker_id);
9511 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
9513 t->static_trace_marker_id = xstrdup (marker.str_id);
9514 release_static_tracepoint_marker (&marker);
9516 printf_filtered (_("Probed static tracepoint "
9518 t->static_trace_marker_id);
9521 warning (_("Couldn't determine the static "
9522 "tracepoint marker to probe"));
9529 loc = add_location_to_breakpoint (b, &sal);
9530 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9534 if (bp_loc_is_permanent (loc))
9535 make_breakpoint_permanent (b);
9539 const char *arg = b->cond_string;
9541 loc->cond = parse_exp_1 (&arg, loc->address,
9542 block_for_pc (loc->address), 0);
9544 error (_("Garbage '%s' follows condition"), arg);
9547 /* Dynamic printf requires and uses additional arguments on the
9548 command line, otherwise it's an error. */
9549 if (type == bp_dprintf)
9551 if (b->extra_string)
9552 update_dprintf_command_list (b);
9554 error (_("Format string required"));
9556 else if (b->extra_string)
9557 error (_("Garbage '%s' at end of command"), b->extra_string);
9560 b->display_canonical = display_canonical;
9562 b->addr_string = addr_string;
9564 /* addr_string has to be used or breakpoint_re_set will delete
9567 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
9572 create_breakpoint_sal (struct gdbarch *gdbarch,
9573 struct symtabs_and_lines sals, char *addr_string,
9574 char *filter, char *cond_string,
9576 enum bptype type, enum bpdisp disposition,
9577 int thread, int task, int ignore_count,
9578 const struct breakpoint_ops *ops, int from_tty,
9579 int enabled, int internal, unsigned flags,
9580 int display_canonical)
9582 struct breakpoint *b;
9583 struct cleanup *old_chain;
9585 if (is_tracepoint_type (type))
9587 struct tracepoint *t;
9589 t = XCNEW (struct tracepoint);
9593 b = XNEW (struct breakpoint);
9595 old_chain = make_cleanup (xfree, b);
9597 init_breakpoint_sal (b, gdbarch,
9599 filter, cond_string, extra_string,
9601 thread, task, ignore_count,
9603 enabled, internal, flags,
9605 discard_cleanups (old_chain);
9607 install_breakpoint (internal, b, 0);
9610 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9611 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9612 value. COND_STRING, if not NULL, specified the condition to be
9613 used for all breakpoints. Essentially the only case where
9614 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9615 function. In that case, it's still not possible to specify
9616 separate conditions for different overloaded functions, so
9617 we take just a single condition string.
9619 NOTE: If the function succeeds, the caller is expected to cleanup
9620 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9621 array contents). If the function fails (error() is called), the
9622 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9623 COND and SALS arrays and each of those arrays contents. */
9626 create_breakpoints_sal (struct gdbarch *gdbarch,
9627 struct linespec_result *canonical,
9628 char *cond_string, char *extra_string,
9629 enum bptype type, enum bpdisp disposition,
9630 int thread, int task, int ignore_count,
9631 const struct breakpoint_ops *ops, int from_tty,
9632 int enabled, int internal, unsigned flags)
9635 struct linespec_sals *lsal;
9637 if (canonical->pre_expanded)
9638 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
9640 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
9642 /* Note that 'addr_string' can be NULL in the case of a plain
9643 'break', without arguments. */
9644 char *addr_string = (canonical->addr_string
9645 ? xstrdup (canonical->addr_string)
9647 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
9648 struct cleanup *inner = make_cleanup (xfree, addr_string);
9650 make_cleanup (xfree, filter_string);
9651 create_breakpoint_sal (gdbarch, lsal->sals,
9654 cond_string, extra_string,
9656 thread, task, ignore_count, ops,
9657 from_tty, enabled, internal, flags,
9658 canonical->special_display);
9659 discard_cleanups (inner);
9663 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9664 followed by conditionals. On return, SALS contains an array of SAL
9665 addresses found. ADDR_STRING contains a vector of (canonical)
9666 address strings. ADDRESS points to the end of the SAL.
9668 The array and the line spec strings are allocated on the heap, it is
9669 the caller's responsibility to free them. */
9672 parse_breakpoint_sals (char **address,
9673 struct linespec_result *canonical)
9675 /* If no arg given, or if first arg is 'if ', use the default
9677 if ((*address) == NULL
9678 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
9680 /* The last displayed codepoint, if it's valid, is our default breakpoint
9682 if (last_displayed_sal_is_valid ())
9684 struct linespec_sals lsal;
9685 struct symtab_and_line sal;
9688 init_sal (&sal); /* Initialize to zeroes. */
9689 lsal.sals.sals = (struct symtab_and_line *)
9690 xmalloc (sizeof (struct symtab_and_line));
9692 /* Set sal's pspace, pc, symtab, and line to the values
9693 corresponding to the last call to print_frame_info.
9694 Be sure to reinitialize LINE with NOTCURRENT == 0
9695 as the breakpoint line number is inappropriate otherwise.
9696 find_pc_line would adjust PC, re-set it back. */
9697 get_last_displayed_sal (&sal);
9699 sal = find_pc_line (pc, 0);
9701 /* "break" without arguments is equivalent to "break *PC"
9702 where PC is the last displayed codepoint's address. So
9703 make sure to set sal.explicit_pc to prevent GDB from
9704 trying to expand the list of sals to include all other
9705 instances with the same symtab and line. */
9707 sal.explicit_pc = 1;
9709 lsal.sals.sals[0] = sal;
9710 lsal.sals.nelts = 1;
9711 lsal.canonical = NULL;
9713 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
9716 error (_("No default breakpoint address now."));
9720 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
9722 /* Force almost all breakpoints to be in terms of the
9723 current_source_symtab (which is decode_line_1's default).
9724 This should produce the results we want almost all of the
9725 time while leaving default_breakpoint_* alone.
9727 ObjC: However, don't match an Objective-C method name which
9728 may have a '+' or '-' succeeded by a '['. */
9729 if (last_displayed_sal_is_valid ()
9731 || ((strchr ("+-", (*address)[0]) != NULL)
9732 && ((*address)[1] != '['))))
9733 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
9734 get_last_displayed_symtab (),
9735 get_last_displayed_line (),
9736 canonical, NULL, NULL);
9738 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
9739 cursal.symtab, cursal.line, canonical, NULL, NULL);
9744 /* Convert each SAL into a real PC. Verify that the PC can be
9745 inserted as a breakpoint. If it can't throw an error. */
9748 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
9752 for (i = 0; i < sals->nelts; i++)
9753 resolve_sal_pc (&sals->sals[i]);
9756 /* Fast tracepoints may have restrictions on valid locations. For
9757 instance, a fast tracepoint using a jump instead of a trap will
9758 likely have to overwrite more bytes than a trap would, and so can
9759 only be placed where the instruction is longer than the jump, or a
9760 multi-instruction sequence does not have a jump into the middle of
9764 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
9765 struct symtabs_and_lines *sals)
9768 struct symtab_and_line *sal;
9770 struct cleanup *old_chain;
9772 for (i = 0; i < sals->nelts; i++)
9774 struct gdbarch *sarch;
9776 sal = &sals->sals[i];
9778 sarch = get_sal_arch (*sal);
9779 /* We fall back to GDBARCH if there is no architecture
9780 associated with SAL. */
9783 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc,
9785 old_chain = make_cleanup (xfree, msg);
9788 error (_("May not have a fast tracepoint at 0x%s%s"),
9789 paddress (sarch, sal->pc), (msg ? msg : ""));
9791 do_cleanups (old_chain);
9795 /* Issue an invalid thread ID error. */
9797 static void ATTRIBUTE_NORETURN
9798 invalid_thread_id_error (int id)
9800 error (_("Unknown thread %d."), id);
9803 /* Given TOK, a string specification of condition and thread, as
9804 accepted by the 'break' command, extract the condition
9805 string and thread number and set *COND_STRING and *THREAD.
9806 PC identifies the context at which the condition should be parsed.
9807 If no condition is found, *COND_STRING is set to NULL.
9808 If no thread is found, *THREAD is set to -1. */
9811 find_condition_and_thread (const char *tok, CORE_ADDR pc,
9812 char **cond_string, int *thread, int *task,
9815 *cond_string = NULL;
9822 const char *end_tok;
9824 const char *cond_start = NULL;
9825 const char *cond_end = NULL;
9827 tok = skip_spaces_const (tok);
9829 if ((*tok == '"' || *tok == ',') && rest)
9831 *rest = savestring (tok, strlen (tok));
9835 end_tok = skip_to_space_const (tok);
9837 toklen = end_tok - tok;
9839 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9841 struct expression *expr;
9843 tok = cond_start = end_tok + 1;
9844 expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
9847 *cond_string = savestring (cond_start, cond_end - cond_start);
9849 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9854 *thread = strtol (tok, &tmptok, 0);
9856 error (_("Junk after thread keyword."));
9857 if (!valid_thread_id (*thread))
9858 invalid_thread_id_error (*thread);
9861 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9866 *task = strtol (tok, &tmptok, 0);
9868 error (_("Junk after task keyword."));
9869 if (!valid_task_id (*task))
9870 error (_("Unknown task %d."), *task);
9875 *rest = savestring (tok, strlen (tok));
9879 error (_("Junk at end of arguments."));
9883 /* Decode a static tracepoint marker spec. */
9885 static struct symtabs_and_lines
9886 decode_static_tracepoint_spec (char **arg_p)
9888 VEC(static_tracepoint_marker_p) *markers = NULL;
9889 struct symtabs_and_lines sals;
9890 struct cleanup *old_chain;
9891 char *p = &(*arg_p)[3];
9896 p = skip_spaces (p);
9898 endp = skip_to_space (p);
9900 marker_str = savestring (p, endp - p);
9901 old_chain = make_cleanup (xfree, marker_str);
9903 markers = target_static_tracepoint_markers_by_strid (marker_str);
9904 if (VEC_empty(static_tracepoint_marker_p, markers))
9905 error (_("No known static tracepoint marker named %s"), marker_str);
9907 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
9908 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
9910 for (i = 0; i < sals.nelts; i++)
9912 struct static_tracepoint_marker *marker;
9914 marker = VEC_index (static_tracepoint_marker_p, markers, i);
9916 init_sal (&sals.sals[i]);
9918 sals.sals[i] = find_pc_line (marker->address, 0);
9919 sals.sals[i].pc = marker->address;
9921 release_static_tracepoint_marker (marker);
9924 do_cleanups (old_chain);
9930 /* Set a breakpoint. This function is shared between CLI and MI
9931 functions for setting a breakpoint. This function has two major
9932 modes of operations, selected by the PARSE_ARG parameter. If
9933 non-zero, the function will parse ARG, extracting location,
9934 condition, thread and extra string. Otherwise, ARG is just the
9935 breakpoint's location, with condition, thread, and extra string
9936 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9937 If INTERNAL is non-zero, the breakpoint number will be allocated
9938 from the internal breakpoint count. Returns true if any breakpoint
9939 was created; false otherwise. */
9942 create_breakpoint (struct gdbarch *gdbarch,
9943 char *arg, char *cond_string,
9944 int thread, char *extra_string,
9946 int tempflag, enum bptype type_wanted,
9948 enum auto_boolean pending_break_support,
9949 const struct breakpoint_ops *ops,
9950 int from_tty, int enabled, int internal,
9953 volatile struct gdb_exception e;
9954 char *copy_arg = NULL;
9955 char *addr_start = arg;
9956 struct linespec_result canonical;
9957 struct cleanup *old_chain;
9958 struct cleanup *bkpt_chain = NULL;
9961 int prev_bkpt_count = breakpoint_count;
9963 gdb_assert (ops != NULL);
9965 init_linespec_result (&canonical);
9967 TRY_CATCH (e, RETURN_MASK_ALL)
9969 ops->create_sals_from_address (&arg, &canonical, type_wanted,
9970 addr_start, ©_arg);
9973 /* If caller is interested in rc value from parse, set value. */
9977 if (VEC_empty (linespec_sals, canonical.sals))
9983 case NOT_FOUND_ERROR:
9985 /* If pending breakpoint support is turned off, throw
9988 if (pending_break_support == AUTO_BOOLEAN_FALSE)
9989 throw_exception (e);
9991 exception_print (gdb_stderr, e);
9993 /* If pending breakpoint support is auto query and the user
9994 selects no, then simply return the error code. */
9995 if (pending_break_support == AUTO_BOOLEAN_AUTO
9996 && !nquery (_("Make %s pending on future shared library load? "),
9997 bptype_string (type_wanted)))
10000 /* At this point, either the user was queried about setting
10001 a pending breakpoint and selected yes, or pending
10002 breakpoint behavior is on and thus a pending breakpoint
10003 is defaulted on behalf of the user. */
10005 struct linespec_sals lsal;
10007 copy_arg = xstrdup (addr_start);
10008 lsal.canonical = xstrdup (copy_arg);
10009 lsal.sals.nelts = 1;
10010 lsal.sals.sals = XNEW (struct symtab_and_line);
10011 init_sal (&lsal.sals.sals[0]);
10013 VEC_safe_push (linespec_sals, canonical.sals, &lsal);
10017 throw_exception (e);
10021 throw_exception (e);
10024 /* Create a chain of things that always need to be cleaned up. */
10025 old_chain = make_cleanup_destroy_linespec_result (&canonical);
10027 /* ----------------------------- SNIP -----------------------------
10028 Anything added to the cleanup chain beyond this point is assumed
10029 to be part of a breakpoint. If the breakpoint create succeeds
10030 then the memory is not reclaimed. */
10031 bkpt_chain = make_cleanup (null_cleanup, 0);
10033 /* Resolve all line numbers to PC's and verify that the addresses
10034 are ok for the target. */
10038 struct linespec_sals *iter;
10040 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
10041 breakpoint_sals_to_pc (&iter->sals);
10044 /* Fast tracepoints may have additional restrictions on location. */
10045 if (!pending && type_wanted == bp_fast_tracepoint)
10048 struct linespec_sals *iter;
10050 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
10051 check_fast_tracepoint_sals (gdbarch, &iter->sals);
10054 /* Verify that condition can be parsed, before setting any
10055 breakpoints. Allocate a separate condition expression for each
10062 struct linespec_sals *lsal;
10064 lsal = VEC_index (linespec_sals, canonical.sals, 0);
10066 /* Here we only parse 'arg' to separate condition
10067 from thread number, so parsing in context of first
10068 sal is OK. When setting the breakpoint we'll
10069 re-parse it in context of each sal. */
10071 find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string,
10072 &thread, &task, &rest);
10074 make_cleanup (xfree, cond_string);
10076 make_cleanup (xfree, rest);
10078 extra_string = rest;
10083 error (_("Garbage '%s' at end of location"), arg);
10085 /* Create a private copy of condition string. */
10088 cond_string = xstrdup (cond_string);
10089 make_cleanup (xfree, cond_string);
10091 /* Create a private copy of any extra string. */
10094 extra_string = xstrdup (extra_string);
10095 make_cleanup (xfree, extra_string);
10099 ops->create_breakpoints_sal (gdbarch, &canonical,
10100 cond_string, extra_string, type_wanted,
10101 tempflag ? disp_del : disp_donttouch,
10102 thread, task, ignore_count, ops,
10103 from_tty, enabled, internal, flags);
10107 struct breakpoint *b;
10109 make_cleanup (xfree, copy_arg);
10111 if (is_tracepoint_type (type_wanted))
10113 struct tracepoint *t;
10115 t = XCNEW (struct tracepoint);
10119 b = XNEW (struct breakpoint);
10121 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
10123 b->addr_string = copy_arg;
10125 b->cond_string = NULL;
10128 /* Create a private copy of condition string. */
10131 cond_string = xstrdup (cond_string);
10132 make_cleanup (xfree, cond_string);
10134 b->cond_string = cond_string;
10136 b->extra_string = NULL;
10137 b->ignore_count = ignore_count;
10138 b->disposition = tempflag ? disp_del : disp_donttouch;
10139 b->condition_not_parsed = 1;
10140 b->enable_state = enabled ? bp_enabled : bp_disabled;
10141 if ((type_wanted != bp_breakpoint
10142 && type_wanted != bp_hardware_breakpoint) || thread != -1)
10143 b->pspace = current_program_space;
10145 install_breakpoint (internal, b, 0);
10148 if (VEC_length (linespec_sals, canonical.sals) > 1)
10150 warning (_("Multiple breakpoints were set.\nUse the "
10151 "\"delete\" command to delete unwanted breakpoints."));
10152 prev_breakpoint_count = prev_bkpt_count;
10155 /* That's it. Discard the cleanups for data inserted into the
10157 discard_cleanups (bkpt_chain);
10158 /* But cleanup everything else. */
10159 do_cleanups (old_chain);
10161 /* error call may happen here - have BKPT_CHAIN already discarded. */
10162 update_global_location_list (UGLL_MAY_INSERT);
10167 /* Set a breakpoint.
10168 ARG is a string describing breakpoint address,
10169 condition, and thread.
10170 FLAG specifies if a breakpoint is hardware on,
10171 and if breakpoint is temporary, using BP_HARDWARE_FLAG
10172 and BP_TEMPFLAG. */
10175 break_command_1 (char *arg, int flag, int from_tty)
10177 int tempflag = flag & BP_TEMPFLAG;
10178 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
10179 ? bp_hardware_breakpoint
10181 struct breakpoint_ops *ops;
10182 const char *arg_cp = arg;
10184 /* Matching breakpoints on probes. */
10185 if (arg && probe_linespec_to_ops (&arg_cp) != NULL)
10186 ops = &bkpt_probe_breakpoint_ops;
10188 ops = &bkpt_breakpoint_ops;
10190 create_breakpoint (get_current_arch (),
10192 NULL, 0, NULL, 1 /* parse arg */,
10193 tempflag, type_wanted,
10194 0 /* Ignore count */,
10195 pending_break_support,
10203 /* Helper function for break_command_1 and disassemble_command. */
10206 resolve_sal_pc (struct symtab_and_line *sal)
10210 if (sal->pc == 0 && sal->symtab != NULL)
10212 if (!find_line_pc (sal->symtab, sal->line, &pc))
10213 error (_("No line %d in file \"%s\"."),
10214 sal->line, symtab_to_filename_for_display (sal->symtab));
10217 /* If this SAL corresponds to a breakpoint inserted using a line
10218 number, then skip the function prologue if necessary. */
10219 if (sal->explicit_line)
10220 skip_prologue_sal (sal);
10223 if (sal->section == 0 && sal->symtab != NULL)
10225 const struct blockvector *bv;
10226 const struct block *b;
10227 struct symbol *sym;
10229 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
10232 sym = block_linkage_function (b);
10235 fixup_symbol_section (sym, sal->symtab->objfile);
10236 sal->section = SYMBOL_OBJ_SECTION (sal->symtab->objfile, sym);
10240 /* It really is worthwhile to have the section, so we'll
10241 just have to look harder. This case can be executed
10242 if we have line numbers but no functions (as can
10243 happen in assembly source). */
10245 struct bound_minimal_symbol msym;
10246 struct cleanup *old_chain = save_current_space_and_thread ();
10248 switch_to_program_space_and_thread (sal->pspace);
10250 msym = lookup_minimal_symbol_by_pc (sal->pc);
10252 sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
10254 do_cleanups (old_chain);
10261 break_command (char *arg, int from_tty)
10263 break_command_1 (arg, 0, from_tty);
10267 tbreak_command (char *arg, int from_tty)
10269 break_command_1 (arg, BP_TEMPFLAG, from_tty);
10273 hbreak_command (char *arg, int from_tty)
10275 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
10279 thbreak_command (char *arg, int from_tty)
10281 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
10285 stop_command (char *arg, int from_tty)
10287 printf_filtered (_("Specify the type of breakpoint to set.\n\
10288 Usage: stop in <function | address>\n\
10289 stop at <line>\n"));
10293 stopin_command (char *arg, int from_tty)
10297 if (arg == (char *) NULL)
10299 else if (*arg != '*')
10301 char *argptr = arg;
10304 /* Look for a ':'. If this is a line number specification, then
10305 say it is bad, otherwise, it should be an address or
10306 function/method name. */
10307 while (*argptr && !hasColon)
10309 hasColon = (*argptr == ':');
10314 badInput = (*argptr != ':'); /* Not a class::method */
10316 badInput = isdigit (*arg); /* a simple line number */
10320 printf_filtered (_("Usage: stop in <function | address>\n"));
10322 break_command_1 (arg, 0, from_tty);
10326 stopat_command (char *arg, int from_tty)
10330 if (arg == (char *) NULL || *arg == '*') /* no line number */
10334 char *argptr = arg;
10337 /* Look for a ':'. If there is a '::' then get out, otherwise
10338 it is probably a line number. */
10339 while (*argptr && !hasColon)
10341 hasColon = (*argptr == ':');
10346 badInput = (*argptr == ':'); /* we have class::method */
10348 badInput = !isdigit (*arg); /* not a line number */
10352 printf_filtered (_("Usage: stop at <line>\n"));
10354 break_command_1 (arg, 0, from_tty);
10357 /* The dynamic printf command is mostly like a regular breakpoint, but
10358 with a prewired command list consisting of a single output command,
10359 built from extra arguments supplied on the dprintf command
10363 dprintf_command (char *arg, int from_tty)
10365 create_breakpoint (get_current_arch (),
10367 NULL, 0, NULL, 1 /* parse arg */,
10369 0 /* Ignore count */,
10370 pending_break_support,
10371 &dprintf_breakpoint_ops,
10379 agent_printf_command (char *arg, int from_tty)
10381 error (_("May only run agent-printf on the target"));
10384 /* Implement the "breakpoint_hit" breakpoint_ops method for
10385 ranged breakpoints. */
10388 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
10389 struct address_space *aspace,
10391 const struct target_waitstatus *ws)
10393 if (ws->kind != TARGET_WAITKIND_STOPPED
10394 || ws->value.sig != GDB_SIGNAL_TRAP)
10397 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
10398 bl->length, aspace, bp_addr);
10401 /* Implement the "resources_needed" breakpoint_ops method for
10402 ranged breakpoints. */
10405 resources_needed_ranged_breakpoint (const struct bp_location *bl)
10407 return target_ranged_break_num_registers ();
10410 /* Implement the "print_it" breakpoint_ops method for
10411 ranged breakpoints. */
10413 static enum print_stop_action
10414 print_it_ranged_breakpoint (bpstat bs)
10416 struct breakpoint *b = bs->breakpoint_at;
10417 struct bp_location *bl = b->loc;
10418 struct ui_out *uiout = current_uiout;
10420 gdb_assert (b->type == bp_hardware_breakpoint);
10422 /* Ranged breakpoints have only one location. */
10423 gdb_assert (bl && bl->next == NULL);
10425 annotate_breakpoint (b->number);
10426 if (b->disposition == disp_del)
10427 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
10429 ui_out_text (uiout, "\nRanged breakpoint ");
10430 if (ui_out_is_mi_like_p (uiout))
10432 ui_out_field_string (uiout, "reason",
10433 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10434 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10436 ui_out_field_int (uiout, "bkptno", b->number);
10437 ui_out_text (uiout, ", ");
10439 return PRINT_SRC_AND_LOC;
10442 /* Implement the "print_one" breakpoint_ops method for
10443 ranged breakpoints. */
10446 print_one_ranged_breakpoint (struct breakpoint *b,
10447 struct bp_location **last_loc)
10449 struct bp_location *bl = b->loc;
10450 struct value_print_options opts;
10451 struct ui_out *uiout = current_uiout;
10453 /* Ranged breakpoints have only one location. */
10454 gdb_assert (bl && bl->next == NULL);
10456 get_user_print_options (&opts);
10458 if (opts.addressprint)
10459 /* We don't print the address range here, it will be printed later
10460 by print_one_detail_ranged_breakpoint. */
10461 ui_out_field_skip (uiout, "addr");
10462 annotate_field (5);
10463 print_breakpoint_location (b, bl);
10467 /* Implement the "print_one_detail" breakpoint_ops method for
10468 ranged breakpoints. */
10471 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
10472 struct ui_out *uiout)
10474 CORE_ADDR address_start, address_end;
10475 struct bp_location *bl = b->loc;
10476 struct ui_file *stb = mem_fileopen ();
10477 struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
10481 address_start = bl->address;
10482 address_end = address_start + bl->length - 1;
10484 ui_out_text (uiout, "\taddress range: ");
10485 fprintf_unfiltered (stb, "[%s, %s]",
10486 print_core_address (bl->gdbarch, address_start),
10487 print_core_address (bl->gdbarch, address_end));
10488 ui_out_field_stream (uiout, "addr", stb);
10489 ui_out_text (uiout, "\n");
10491 do_cleanups (cleanup);
10494 /* Implement the "print_mention" breakpoint_ops method for
10495 ranged breakpoints. */
10498 print_mention_ranged_breakpoint (struct breakpoint *b)
10500 struct bp_location *bl = b->loc;
10501 struct ui_out *uiout = current_uiout;
10504 gdb_assert (b->type == bp_hardware_breakpoint);
10506 if (ui_out_is_mi_like_p (uiout))
10509 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10510 b->number, paddress (bl->gdbarch, bl->address),
10511 paddress (bl->gdbarch, bl->address + bl->length - 1));
10514 /* Implement the "print_recreate" breakpoint_ops method for
10515 ranged breakpoints. */
10518 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
10520 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
10521 b->addr_string_range_end);
10522 print_recreate_thread (b, fp);
10525 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10527 static struct breakpoint_ops ranged_breakpoint_ops;
10529 /* Find the address where the end of the breakpoint range should be
10530 placed, given the SAL of the end of the range. This is so that if
10531 the user provides a line number, the end of the range is set to the
10532 last instruction of the given line. */
10535 find_breakpoint_range_end (struct symtab_and_line sal)
10539 /* If the user provided a PC value, use it. Otherwise,
10540 find the address of the end of the given location. */
10541 if (sal.explicit_pc)
10548 ret = find_line_pc_range (sal, &start, &end);
10550 error (_("Could not find location of the end of the range."));
10552 /* find_line_pc_range returns the start of the next line. */
10559 /* Implement the "break-range" CLI command. */
10562 break_range_command (char *arg, int from_tty)
10564 char *arg_start, *addr_string_start, *addr_string_end;
10565 struct linespec_result canonical_start, canonical_end;
10566 int bp_count, can_use_bp, length;
10568 struct breakpoint *b;
10569 struct symtab_and_line sal_start, sal_end;
10570 struct cleanup *cleanup_bkpt;
10571 struct linespec_sals *lsal_start, *lsal_end;
10573 /* We don't support software ranged breakpoints. */
10574 if (target_ranged_break_num_registers () < 0)
10575 error (_("This target does not support hardware ranged breakpoints."));
10577 bp_count = hw_breakpoint_used_count ();
10578 bp_count += target_ranged_break_num_registers ();
10579 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10581 if (can_use_bp < 0)
10582 error (_("Hardware breakpoints used exceeds limit."));
10584 arg = skip_spaces (arg);
10585 if (arg == NULL || arg[0] == '\0')
10586 error(_("No address range specified."));
10588 init_linespec_result (&canonical_start);
10591 parse_breakpoint_sals (&arg, &canonical_start);
10593 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
10596 error (_("Too few arguments."));
10597 else if (VEC_empty (linespec_sals, canonical_start.sals))
10598 error (_("Could not find location of the beginning of the range."));
10600 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
10602 if (VEC_length (linespec_sals, canonical_start.sals) > 1
10603 || lsal_start->sals.nelts != 1)
10604 error (_("Cannot create a ranged breakpoint with multiple locations."));
10606 sal_start = lsal_start->sals.sals[0];
10607 addr_string_start = savestring (arg_start, arg - arg_start);
10608 make_cleanup (xfree, addr_string_start);
10610 arg++; /* Skip the comma. */
10611 arg = skip_spaces (arg);
10613 /* Parse the end location. */
10615 init_linespec_result (&canonical_end);
10618 /* We call decode_line_full directly here instead of using
10619 parse_breakpoint_sals because we need to specify the start location's
10620 symtab and line as the default symtab and line for the end of the
10621 range. This makes it possible to have ranges like "foo.c:27, +14",
10622 where +14 means 14 lines from the start location. */
10623 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
10624 sal_start.symtab, sal_start.line,
10625 &canonical_end, NULL, NULL);
10627 make_cleanup_destroy_linespec_result (&canonical_end);
10629 if (VEC_empty (linespec_sals, canonical_end.sals))
10630 error (_("Could not find location of the end of the range."));
10632 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
10633 if (VEC_length (linespec_sals, canonical_end.sals) > 1
10634 || lsal_end->sals.nelts != 1)
10635 error (_("Cannot create a ranged breakpoint with multiple locations."));
10637 sal_end = lsal_end->sals.sals[0];
10638 addr_string_end = savestring (arg_start, arg - arg_start);
10639 make_cleanup (xfree, addr_string_end);
10641 end = find_breakpoint_range_end (sal_end);
10642 if (sal_start.pc > end)
10643 error (_("Invalid address range, end precedes start."));
10645 length = end - sal_start.pc + 1;
10647 /* Length overflowed. */
10648 error (_("Address range too large."));
10649 else if (length == 1)
10651 /* This range is simple enough to be handled by
10652 the `hbreak' command. */
10653 hbreak_command (addr_string_start, 1);
10655 do_cleanups (cleanup_bkpt);
10660 /* Now set up the breakpoint. */
10661 b = set_raw_breakpoint (get_current_arch (), sal_start,
10662 bp_hardware_breakpoint, &ranged_breakpoint_ops);
10663 set_breakpoint_count (breakpoint_count + 1);
10664 b->number = breakpoint_count;
10665 b->disposition = disp_donttouch;
10666 b->addr_string = xstrdup (addr_string_start);
10667 b->addr_string_range_end = xstrdup (addr_string_end);
10668 b->loc->length = length;
10670 do_cleanups (cleanup_bkpt);
10673 observer_notify_breakpoint_created (b);
10674 update_global_location_list (UGLL_MAY_INSERT);
10677 /* Return non-zero if EXP is verified as constant. Returned zero
10678 means EXP is variable. Also the constant detection may fail for
10679 some constant expressions and in such case still falsely return
10683 watchpoint_exp_is_const (const struct expression *exp)
10685 int i = exp->nelts;
10691 /* We are only interested in the descriptor of each element. */
10692 operator_length (exp, i, &oplenp, &argsp);
10695 switch (exp->elts[i].opcode)
10705 case BINOP_LOGICAL_AND:
10706 case BINOP_LOGICAL_OR:
10707 case BINOP_BITWISE_AND:
10708 case BINOP_BITWISE_IOR:
10709 case BINOP_BITWISE_XOR:
10711 case BINOP_NOTEQUAL:
10738 case OP_OBJC_NSSTRING:
10741 case UNOP_LOGICAL_NOT:
10742 case UNOP_COMPLEMENT:
10747 case UNOP_CAST_TYPE:
10748 case UNOP_REINTERPRET_CAST:
10749 case UNOP_DYNAMIC_CAST:
10750 /* Unary, binary and ternary operators: We have to check
10751 their operands. If they are constant, then so is the
10752 result of that operation. For instance, if A and B are
10753 determined to be constants, then so is "A + B".
10755 UNOP_IND is one exception to the rule above, because the
10756 value of *ADDR is not necessarily a constant, even when
10761 /* Check whether the associated symbol is a constant.
10763 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10764 possible that a buggy compiler could mark a variable as
10765 constant even when it is not, and TYPE_CONST would return
10766 true in this case, while SYMBOL_CLASS wouldn't.
10768 We also have to check for function symbols because they
10769 are always constant. */
10771 struct symbol *s = exp->elts[i + 2].symbol;
10773 if (SYMBOL_CLASS (s) != LOC_BLOCK
10774 && SYMBOL_CLASS (s) != LOC_CONST
10775 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
10780 /* The default action is to return 0 because we are using
10781 the optimistic approach here: If we don't know something,
10782 then it is not a constant. */
10791 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10794 dtor_watchpoint (struct breakpoint *self)
10796 struct watchpoint *w = (struct watchpoint *) self;
10798 xfree (w->cond_exp);
10800 xfree (w->exp_string);
10801 xfree (w->exp_string_reparse);
10802 value_free (w->val);
10804 base_breakpoint_ops.dtor (self);
10807 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10810 re_set_watchpoint (struct breakpoint *b)
10812 struct watchpoint *w = (struct watchpoint *) b;
10814 /* Watchpoint can be either on expression using entirely global
10815 variables, or it can be on local variables.
10817 Watchpoints of the first kind are never auto-deleted, and even
10818 persist across program restarts. Since they can use variables
10819 from shared libraries, we need to reparse expression as libraries
10820 are loaded and unloaded.
10822 Watchpoints on local variables can also change meaning as result
10823 of solib event. For example, if a watchpoint uses both a local
10824 and a global variables in expression, it's a local watchpoint,
10825 but unloading of a shared library will make the expression
10826 invalid. This is not a very common use case, but we still
10827 re-evaluate expression, to avoid surprises to the user.
10829 Note that for local watchpoints, we re-evaluate it only if
10830 watchpoints frame id is still valid. If it's not, it means the
10831 watchpoint is out of scope and will be deleted soon. In fact,
10832 I'm not sure we'll ever be called in this case.
10834 If a local watchpoint's frame id is still valid, then
10835 w->exp_valid_block is likewise valid, and we can safely use it.
10837 Don't do anything about disabled watchpoints, since they will be
10838 reevaluated again when enabled. */
10839 update_watchpoint (w, 1 /* reparse */);
10842 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10845 insert_watchpoint (struct bp_location *bl)
10847 struct watchpoint *w = (struct watchpoint *) bl->owner;
10848 int length = w->exact ? 1 : bl->length;
10850 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10854 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10857 remove_watchpoint (struct bp_location *bl)
10859 struct watchpoint *w = (struct watchpoint *) bl->owner;
10860 int length = w->exact ? 1 : bl->length;
10862 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10867 breakpoint_hit_watchpoint (const struct bp_location *bl,
10868 struct address_space *aspace, CORE_ADDR bp_addr,
10869 const struct target_waitstatus *ws)
10871 struct breakpoint *b = bl->owner;
10872 struct watchpoint *w = (struct watchpoint *) b;
10874 /* Continuable hardware watchpoints are treated as non-existent if the
10875 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10876 some data address). Otherwise gdb won't stop on a break instruction
10877 in the code (not from a breakpoint) when a hardware watchpoint has
10878 been defined. Also skip watchpoints which we know did not trigger
10879 (did not match the data address). */
10880 if (is_hardware_watchpoint (b)
10881 && w->watchpoint_triggered == watch_triggered_no)
10888 check_status_watchpoint (bpstat bs)
10890 gdb_assert (is_watchpoint (bs->breakpoint_at));
10892 bpstat_check_watchpoint (bs);
10895 /* Implement the "resources_needed" breakpoint_ops method for
10896 hardware watchpoints. */
10899 resources_needed_watchpoint (const struct bp_location *bl)
10901 struct watchpoint *w = (struct watchpoint *) bl->owner;
10902 int length = w->exact? 1 : bl->length;
10904 return target_region_ok_for_hw_watchpoint (bl->address, length);
10907 /* Implement the "works_in_software_mode" breakpoint_ops method for
10908 hardware watchpoints. */
10911 works_in_software_mode_watchpoint (const struct breakpoint *b)
10913 /* Read and access watchpoints only work with hardware support. */
10914 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10917 static enum print_stop_action
10918 print_it_watchpoint (bpstat bs)
10920 struct cleanup *old_chain;
10921 struct breakpoint *b;
10922 struct ui_file *stb;
10923 enum print_stop_action result;
10924 struct watchpoint *w;
10925 struct ui_out *uiout = current_uiout;
10927 gdb_assert (bs->bp_location_at != NULL);
10929 b = bs->breakpoint_at;
10930 w = (struct watchpoint *) b;
10932 stb = mem_fileopen ();
10933 old_chain = make_cleanup_ui_file_delete (stb);
10937 case bp_watchpoint:
10938 case bp_hardware_watchpoint:
10939 annotate_watchpoint (b->number);
10940 if (ui_out_is_mi_like_p (uiout))
10941 ui_out_field_string
10943 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10945 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10946 ui_out_text (uiout, "\nOld value = ");
10947 watchpoint_value_print (bs->old_val, stb);
10948 ui_out_field_stream (uiout, "old", stb);
10949 ui_out_text (uiout, "\nNew value = ");
10950 watchpoint_value_print (w->val, stb);
10951 ui_out_field_stream (uiout, "new", stb);
10952 ui_out_text (uiout, "\n");
10953 /* More than one watchpoint may have been triggered. */
10954 result = PRINT_UNKNOWN;
10957 case bp_read_watchpoint:
10958 if (ui_out_is_mi_like_p (uiout))
10959 ui_out_field_string
10961 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10963 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10964 ui_out_text (uiout, "\nValue = ");
10965 watchpoint_value_print (w->val, stb);
10966 ui_out_field_stream (uiout, "value", stb);
10967 ui_out_text (uiout, "\n");
10968 result = PRINT_UNKNOWN;
10971 case bp_access_watchpoint:
10972 if (bs->old_val != NULL)
10974 annotate_watchpoint (b->number);
10975 if (ui_out_is_mi_like_p (uiout))
10976 ui_out_field_string
10978 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10980 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10981 ui_out_text (uiout, "\nOld value = ");
10982 watchpoint_value_print (bs->old_val, stb);
10983 ui_out_field_stream (uiout, "old", stb);
10984 ui_out_text (uiout, "\nNew value = ");
10989 if (ui_out_is_mi_like_p (uiout))
10990 ui_out_field_string
10992 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10993 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10994 ui_out_text (uiout, "\nValue = ");
10996 watchpoint_value_print (w->val, stb);
10997 ui_out_field_stream (uiout, "new", stb);
10998 ui_out_text (uiout, "\n");
10999 result = PRINT_UNKNOWN;
11002 result = PRINT_UNKNOWN;
11005 do_cleanups (old_chain);
11009 /* Implement the "print_mention" breakpoint_ops method for hardware
11013 print_mention_watchpoint (struct breakpoint *b)
11015 struct cleanup *ui_out_chain;
11016 struct watchpoint *w = (struct watchpoint *) b;
11017 struct ui_out *uiout = current_uiout;
11021 case bp_watchpoint:
11022 ui_out_text (uiout, "Watchpoint ");
11023 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
11025 case bp_hardware_watchpoint:
11026 ui_out_text (uiout, "Hardware watchpoint ");
11027 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
11029 case bp_read_watchpoint:
11030 ui_out_text (uiout, "Hardware read watchpoint ");
11031 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
11033 case bp_access_watchpoint:
11034 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
11035 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
11038 internal_error (__FILE__, __LINE__,
11039 _("Invalid hardware watchpoint type."));
11042 ui_out_field_int (uiout, "number", b->number);
11043 ui_out_text (uiout, ": ");
11044 ui_out_field_string (uiout, "exp", w->exp_string);
11045 do_cleanups (ui_out_chain);
11048 /* Implement the "print_recreate" breakpoint_ops method for
11052 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
11054 struct watchpoint *w = (struct watchpoint *) b;
11058 case bp_watchpoint:
11059 case bp_hardware_watchpoint:
11060 fprintf_unfiltered (fp, "watch");
11062 case bp_read_watchpoint:
11063 fprintf_unfiltered (fp, "rwatch");
11065 case bp_access_watchpoint:
11066 fprintf_unfiltered (fp, "awatch");
11069 internal_error (__FILE__, __LINE__,
11070 _("Invalid watchpoint type."));
11073 fprintf_unfiltered (fp, " %s", w->exp_string);
11074 print_recreate_thread (b, fp);
11077 /* Implement the "explains_signal" breakpoint_ops method for
11081 explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig)
11083 /* A software watchpoint cannot cause a signal other than
11084 GDB_SIGNAL_TRAP. */
11085 if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
11091 /* The breakpoint_ops structure to be used in hardware watchpoints. */
11093 static struct breakpoint_ops watchpoint_breakpoint_ops;
11095 /* Implement the "insert" breakpoint_ops method for
11096 masked hardware watchpoints. */
11099 insert_masked_watchpoint (struct bp_location *bl)
11101 struct watchpoint *w = (struct watchpoint *) bl->owner;
11103 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
11104 bl->watchpoint_type);
11107 /* Implement the "remove" breakpoint_ops method for
11108 masked hardware watchpoints. */
11111 remove_masked_watchpoint (struct bp_location *bl)
11113 struct watchpoint *w = (struct watchpoint *) bl->owner;
11115 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
11116 bl->watchpoint_type);
11119 /* Implement the "resources_needed" breakpoint_ops method for
11120 masked hardware watchpoints. */
11123 resources_needed_masked_watchpoint (const struct bp_location *bl)
11125 struct watchpoint *w = (struct watchpoint *) bl->owner;
11127 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
11130 /* Implement the "works_in_software_mode" breakpoint_ops method for
11131 masked hardware watchpoints. */
11134 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
11139 /* Implement the "print_it" breakpoint_ops method for
11140 masked hardware watchpoints. */
11142 static enum print_stop_action
11143 print_it_masked_watchpoint (bpstat bs)
11145 struct breakpoint *b = bs->breakpoint_at;
11146 struct ui_out *uiout = current_uiout;
11148 /* Masked watchpoints have only one location. */
11149 gdb_assert (b->loc && b->loc->next == NULL);
11153 case bp_hardware_watchpoint:
11154 annotate_watchpoint (b->number);
11155 if (ui_out_is_mi_like_p (uiout))
11156 ui_out_field_string
11158 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
11161 case bp_read_watchpoint:
11162 if (ui_out_is_mi_like_p (uiout))
11163 ui_out_field_string
11165 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
11168 case bp_access_watchpoint:
11169 if (ui_out_is_mi_like_p (uiout))
11170 ui_out_field_string
11172 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
11175 internal_error (__FILE__, __LINE__,
11176 _("Invalid hardware watchpoint type."));
11180 ui_out_text (uiout, _("\n\
11181 Check the underlying instruction at PC for the memory\n\
11182 address and value which triggered this watchpoint.\n"));
11183 ui_out_text (uiout, "\n");
11185 /* More than one watchpoint may have been triggered. */
11186 return PRINT_UNKNOWN;
11189 /* Implement the "print_one_detail" breakpoint_ops method for
11190 masked hardware watchpoints. */
11193 print_one_detail_masked_watchpoint (const struct breakpoint *b,
11194 struct ui_out *uiout)
11196 struct watchpoint *w = (struct watchpoint *) b;
11198 /* Masked watchpoints have only one location. */
11199 gdb_assert (b->loc && b->loc->next == NULL);
11201 ui_out_text (uiout, "\tmask ");
11202 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
11203 ui_out_text (uiout, "\n");
11206 /* Implement the "print_mention" breakpoint_ops method for
11207 masked hardware watchpoints. */
11210 print_mention_masked_watchpoint (struct breakpoint *b)
11212 struct watchpoint *w = (struct watchpoint *) b;
11213 struct ui_out *uiout = current_uiout;
11214 struct cleanup *ui_out_chain;
11218 case bp_hardware_watchpoint:
11219 ui_out_text (uiout, "Masked hardware watchpoint ");
11220 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
11222 case bp_read_watchpoint:
11223 ui_out_text (uiout, "Masked hardware read watchpoint ");
11224 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
11226 case bp_access_watchpoint:
11227 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
11228 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
11231 internal_error (__FILE__, __LINE__,
11232 _("Invalid hardware watchpoint type."));
11235 ui_out_field_int (uiout, "number", b->number);
11236 ui_out_text (uiout, ": ");
11237 ui_out_field_string (uiout, "exp", w->exp_string);
11238 do_cleanups (ui_out_chain);
11241 /* Implement the "print_recreate" breakpoint_ops method for
11242 masked hardware watchpoints. */
11245 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
11247 struct watchpoint *w = (struct watchpoint *) b;
11252 case bp_hardware_watchpoint:
11253 fprintf_unfiltered (fp, "watch");
11255 case bp_read_watchpoint:
11256 fprintf_unfiltered (fp, "rwatch");
11258 case bp_access_watchpoint:
11259 fprintf_unfiltered (fp, "awatch");
11262 internal_error (__FILE__, __LINE__,
11263 _("Invalid hardware watchpoint type."));
11266 sprintf_vma (tmp, w->hw_wp_mask);
11267 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
11268 print_recreate_thread (b, fp);
11271 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11273 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
11275 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11278 is_masked_watchpoint (const struct breakpoint *b)
11280 return b->ops == &masked_watchpoint_breakpoint_ops;
11283 /* accessflag: hw_write: watch write,
11284 hw_read: watch read,
11285 hw_access: watch access (read or write) */
11287 watch_command_1 (const char *arg, int accessflag, int from_tty,
11288 int just_location, int internal)
11290 volatile struct gdb_exception e;
11291 struct breakpoint *b, *scope_breakpoint = NULL;
11292 struct expression *exp;
11293 const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
11294 struct value *val, *mark, *result;
11295 int saved_bitpos = 0, saved_bitsize = 0;
11296 struct frame_info *frame;
11297 const char *exp_start = NULL;
11298 const char *exp_end = NULL;
11299 const char *tok, *end_tok;
11301 const char *cond_start = NULL;
11302 const char *cond_end = NULL;
11303 enum bptype bp_type;
11306 /* Flag to indicate whether we are going to use masks for
11307 the hardware watchpoint. */
11309 CORE_ADDR mask = 0;
11310 struct watchpoint *w;
11312 struct cleanup *back_to;
11314 /* Make sure that we actually have parameters to parse. */
11315 if (arg != NULL && arg[0] != '\0')
11317 const char *value_start;
11319 exp_end = arg + strlen (arg);
11321 /* Look for "parameter value" pairs at the end
11322 of the arguments string. */
11323 for (tok = exp_end - 1; tok > arg; tok--)
11325 /* Skip whitespace at the end of the argument list. */
11326 while (tok > arg && (*tok == ' ' || *tok == '\t'))
11329 /* Find the beginning of the last token.
11330 This is the value of the parameter. */
11331 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11333 value_start = tok + 1;
11335 /* Skip whitespace. */
11336 while (tok > arg && (*tok == ' ' || *tok == '\t'))
11341 /* Find the beginning of the second to last token.
11342 This is the parameter itself. */
11343 while (tok > arg && (*tok != ' ' && *tok != '\t'))
11346 toklen = end_tok - tok + 1;
11348 if (toklen == 6 && !strncmp (tok, "thread", 6))
11350 /* At this point we've found a "thread" token, which means
11351 the user is trying to set a watchpoint that triggers
11352 only in a specific thread. */
11356 error(_("You can specify only one thread."));
11358 /* Extract the thread ID from the next token. */
11359 thread = strtol (value_start, &endp, 0);
11361 /* Check if the user provided a valid numeric value for the
11363 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
11364 error (_("Invalid thread ID specification %s."), value_start);
11366 /* Check if the thread actually exists. */
11367 if (!valid_thread_id (thread))
11368 invalid_thread_id_error (thread);
11370 else if (toklen == 4 && !strncmp (tok, "mask", 4))
11372 /* We've found a "mask" token, which means the user wants to
11373 create a hardware watchpoint that is going to have the mask
11375 struct value *mask_value, *mark;
11378 error(_("You can specify only one mask."));
11380 use_mask = just_location = 1;
11382 mark = value_mark ();
11383 mask_value = parse_to_comma_and_eval (&value_start);
11384 mask = value_as_address (mask_value);
11385 value_free_to_mark (mark);
11388 /* We didn't recognize what we found. We should stop here. */
11391 /* Truncate the string and get rid of the "parameter value" pair before
11392 the arguments string is parsed by the parse_exp_1 function. */
11399 /* Parse the rest of the arguments. From here on out, everything
11400 is in terms of a newly allocated string instead of the original
11402 innermost_block = NULL;
11403 expression = savestring (arg, exp_end - arg);
11404 back_to = make_cleanup (xfree, expression);
11405 exp_start = arg = expression;
11406 exp = parse_exp_1 (&arg, 0, 0, 0);
11408 /* Remove trailing whitespace from the expression before saving it.
11409 This makes the eventual display of the expression string a bit
11411 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
11414 /* Checking if the expression is not constant. */
11415 if (watchpoint_exp_is_const (exp))
11419 len = exp_end - exp_start;
11420 while (len > 0 && isspace (exp_start[len - 1]))
11422 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
11425 exp_valid_block = innermost_block;
11426 mark = value_mark ();
11427 fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location);
11429 if (val != NULL && just_location)
11431 saved_bitpos = value_bitpos (val);
11432 saved_bitsize = value_bitsize (val);
11439 exp_valid_block = NULL;
11440 val = value_addr (result);
11441 release_value (val);
11442 value_free_to_mark (mark);
11446 ret = target_masked_watch_num_registers (value_as_address (val),
11449 error (_("This target does not support masked watchpoints."));
11450 else if (ret == -2)
11451 error (_("Invalid mask or memory region."));
11454 else if (val != NULL)
11455 release_value (val);
11457 tok = skip_spaces_const (arg);
11458 end_tok = skip_to_space_const (tok);
11460 toklen = end_tok - tok;
11461 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
11463 struct expression *cond;
11465 innermost_block = NULL;
11466 tok = cond_start = end_tok + 1;
11467 cond = parse_exp_1 (&tok, 0, 0, 0);
11469 /* The watchpoint expression may not be local, but the condition
11470 may still be. E.g.: `watch global if local > 0'. */
11471 cond_exp_valid_block = innermost_block;
11477 error (_("Junk at end of command."));
11479 frame = block_innermost_frame (exp_valid_block);
11481 /* If the expression is "local", then set up a "watchpoint scope"
11482 breakpoint at the point where we've left the scope of the watchpoint
11483 expression. Create the scope breakpoint before the watchpoint, so
11484 that we will encounter it first in bpstat_stop_status. */
11485 if (exp_valid_block && frame)
11487 if (frame_id_p (frame_unwind_caller_id (frame)))
11490 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
11491 frame_unwind_caller_pc (frame),
11492 bp_watchpoint_scope,
11493 &momentary_breakpoint_ops);
11495 scope_breakpoint->enable_state = bp_enabled;
11497 /* Automatically delete the breakpoint when it hits. */
11498 scope_breakpoint->disposition = disp_del;
11500 /* Only break in the proper frame (help with recursion). */
11501 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
11503 /* Set the address at which we will stop. */
11504 scope_breakpoint->loc->gdbarch
11505 = frame_unwind_caller_arch (frame);
11506 scope_breakpoint->loc->requested_address
11507 = frame_unwind_caller_pc (frame);
11508 scope_breakpoint->loc->address
11509 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
11510 scope_breakpoint->loc->requested_address,
11511 scope_breakpoint->type);
11515 /* Now set up the breakpoint. We create all watchpoints as hardware
11516 watchpoints here even if hardware watchpoints are turned off, a call
11517 to update_watchpoint later in this function will cause the type to
11518 drop back to bp_watchpoint (software watchpoint) if required. */
11520 if (accessflag == hw_read)
11521 bp_type = bp_read_watchpoint;
11522 else if (accessflag == hw_access)
11523 bp_type = bp_access_watchpoint;
11525 bp_type = bp_hardware_watchpoint;
11527 w = XCNEW (struct watchpoint);
11530 init_raw_breakpoint_without_location (b, NULL, bp_type,
11531 &masked_watchpoint_breakpoint_ops);
11533 init_raw_breakpoint_without_location (b, NULL, bp_type,
11534 &watchpoint_breakpoint_ops);
11535 b->thread = thread;
11536 b->disposition = disp_donttouch;
11537 b->pspace = current_program_space;
11539 w->exp_valid_block = exp_valid_block;
11540 w->cond_exp_valid_block = cond_exp_valid_block;
11543 struct type *t = value_type (val);
11544 CORE_ADDR addr = value_as_address (val);
11547 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
11548 name = type_to_string (t);
11550 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
11551 core_addr_to_string (addr));
11554 w->exp_string = xstrprintf ("-location %.*s",
11555 (int) (exp_end - exp_start), exp_start);
11557 /* The above expression is in C. */
11558 b->language = language_c;
11561 w->exp_string = savestring (exp_start, exp_end - exp_start);
11565 w->hw_wp_mask = mask;
11570 w->val_bitpos = saved_bitpos;
11571 w->val_bitsize = saved_bitsize;
11576 b->cond_string = savestring (cond_start, cond_end - cond_start);
11578 b->cond_string = 0;
11582 w->watchpoint_frame = get_frame_id (frame);
11583 w->watchpoint_thread = inferior_ptid;
11587 w->watchpoint_frame = null_frame_id;
11588 w->watchpoint_thread = null_ptid;
11591 if (scope_breakpoint != NULL)
11593 /* The scope breakpoint is related to the watchpoint. We will
11594 need to act on them together. */
11595 b->related_breakpoint = scope_breakpoint;
11596 scope_breakpoint->related_breakpoint = b;
11599 if (!just_location)
11600 value_free_to_mark (mark);
11602 TRY_CATCH (e, RETURN_MASK_ALL)
11604 /* Finally update the new watchpoint. This creates the locations
11605 that should be inserted. */
11606 update_watchpoint (w, 1);
11610 delete_breakpoint (b);
11611 throw_exception (e);
11614 install_breakpoint (internal, b, 1);
11615 do_cleanups (back_to);
11618 /* Return count of debug registers needed to watch the given expression.
11619 If the watchpoint cannot be handled in hardware return zero. */
11622 can_use_hardware_watchpoint (struct value *v)
11624 int found_memory_cnt = 0;
11625 struct value *head = v;
11627 /* Did the user specifically forbid us to use hardware watchpoints? */
11628 if (!can_use_hw_watchpoints)
11631 /* Make sure that the value of the expression depends only upon
11632 memory contents, and values computed from them within GDB. If we
11633 find any register references or function calls, we can't use a
11634 hardware watchpoint.
11636 The idea here is that evaluating an expression generates a series
11637 of values, one holding the value of every subexpression. (The
11638 expression a*b+c has five subexpressions: a, b, a*b, c, and
11639 a*b+c.) GDB's values hold almost enough information to establish
11640 the criteria given above --- they identify memory lvalues,
11641 register lvalues, computed values, etcetera. So we can evaluate
11642 the expression, and then scan the chain of values that leaves
11643 behind to decide whether we can detect any possible change to the
11644 expression's final value using only hardware watchpoints.
11646 However, I don't think that the values returned by inferior
11647 function calls are special in any way. So this function may not
11648 notice that an expression involving an inferior function call
11649 can't be watched with hardware watchpoints. FIXME. */
11650 for (; v; v = value_next (v))
11652 if (VALUE_LVAL (v) == lval_memory)
11654 if (v != head && value_lazy (v))
11655 /* A lazy memory lvalue in the chain is one that GDB never
11656 needed to fetch; we either just used its address (e.g.,
11657 `a' in `a.b') or we never needed it at all (e.g., `a'
11658 in `a,b'). This doesn't apply to HEAD; if that is
11659 lazy then it was not readable, but watch it anyway. */
11663 /* Ahh, memory we actually used! Check if we can cover
11664 it with hardware watchpoints. */
11665 struct type *vtype = check_typedef (value_type (v));
11667 /* We only watch structs and arrays if user asked for it
11668 explicitly, never if they just happen to appear in a
11669 middle of some value chain. */
11671 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
11672 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
11674 CORE_ADDR vaddr = value_address (v);
11678 len = (target_exact_watchpoints
11679 && is_scalar_type_recursive (vtype))?
11680 1 : TYPE_LENGTH (value_type (v));
11682 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
11686 found_memory_cnt += num_regs;
11690 else if (VALUE_LVAL (v) != not_lval
11691 && deprecated_value_modifiable (v) == 0)
11692 return 0; /* These are values from the history (e.g., $1). */
11693 else if (VALUE_LVAL (v) == lval_register)
11694 return 0; /* Cannot watch a register with a HW watchpoint. */
11697 /* The expression itself looks suitable for using a hardware
11698 watchpoint, but give the target machine a chance to reject it. */
11699 return found_memory_cnt;
11703 watch_command_wrapper (char *arg, int from_tty, int internal)
11705 watch_command_1 (arg, hw_write, from_tty, 0, internal);
11708 /* A helper function that looks for the "-location" argument and then
11709 calls watch_command_1. */
11712 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
11714 int just_location = 0;
11717 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
11718 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
11720 arg = skip_spaces (arg);
11724 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
11728 watch_command (char *arg, int from_tty)
11730 watch_maybe_just_location (arg, hw_write, from_tty);
11734 rwatch_command_wrapper (char *arg, int from_tty, int internal)
11736 watch_command_1 (arg, hw_read, from_tty, 0, internal);
11740 rwatch_command (char *arg, int from_tty)
11742 watch_maybe_just_location (arg, hw_read, from_tty);
11746 awatch_command_wrapper (char *arg, int from_tty, int internal)
11748 watch_command_1 (arg, hw_access, from_tty, 0, internal);
11752 awatch_command (char *arg, int from_tty)
11754 watch_maybe_just_location (arg, hw_access, from_tty);
11758 /* Helper routines for the until_command routine in infcmd.c. Here
11759 because it uses the mechanisms of breakpoints. */
11761 struct until_break_command_continuation_args
11763 struct breakpoint *breakpoint;
11764 struct breakpoint *breakpoint2;
11768 /* This function is called by fetch_inferior_event via the
11769 cmd_continuation pointer, to complete the until command. It takes
11770 care of cleaning up the temporary breakpoints set up by the until
11773 until_break_command_continuation (void *arg, int err)
11775 struct until_break_command_continuation_args *a = arg;
11777 delete_breakpoint (a->breakpoint);
11778 if (a->breakpoint2)
11779 delete_breakpoint (a->breakpoint2);
11780 delete_longjmp_breakpoint (a->thread_num);
11784 until_break_command (char *arg, int from_tty, int anywhere)
11786 struct symtabs_and_lines sals;
11787 struct symtab_and_line sal;
11788 struct frame_info *frame;
11789 struct gdbarch *frame_gdbarch;
11790 struct frame_id stack_frame_id;
11791 struct frame_id caller_frame_id;
11792 struct breakpoint *breakpoint;
11793 struct breakpoint *breakpoint2 = NULL;
11794 struct cleanup *old_chain;
11796 struct thread_info *tp;
11798 clear_proceed_status (0);
11800 /* Set a breakpoint where the user wants it and at return from
11803 if (last_displayed_sal_is_valid ())
11804 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11805 get_last_displayed_symtab (),
11806 get_last_displayed_line ());
11808 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11809 (struct symtab *) NULL, 0);
11811 if (sals.nelts != 1)
11812 error (_("Couldn't get information on specified line."));
11814 sal = sals.sals[0];
11815 xfree (sals.sals); /* malloc'd, so freed. */
11818 error (_("Junk at end of arguments."));
11820 resolve_sal_pc (&sal);
11822 tp = inferior_thread ();
11825 old_chain = make_cleanup (null_cleanup, NULL);
11827 /* Note linespec handling above invalidates the frame chain.
11828 Installing a breakpoint also invalidates the frame chain (as it
11829 may need to switch threads), so do any frame handling before
11832 frame = get_selected_frame (NULL);
11833 frame_gdbarch = get_frame_arch (frame);
11834 stack_frame_id = get_stack_frame_id (frame);
11835 caller_frame_id = frame_unwind_caller_id (frame);
11837 /* Keep within the current frame, or in frames called by the current
11840 if (frame_id_p (caller_frame_id))
11842 struct symtab_and_line sal2;
11844 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11845 sal2.pc = frame_unwind_caller_pc (frame);
11846 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
11850 make_cleanup_delete_breakpoint (breakpoint2);
11852 set_longjmp_breakpoint (tp, caller_frame_id);
11853 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11856 /* set_momentary_breakpoint could invalidate FRAME. */
11860 /* If the user told us to continue until a specified location,
11861 we don't specify a frame at which we need to stop. */
11862 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11863 null_frame_id, bp_until);
11865 /* Otherwise, specify the selected frame, because we want to stop
11866 only at the very same frame. */
11867 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11868 stack_frame_id, bp_until);
11869 make_cleanup_delete_breakpoint (breakpoint);
11871 proceed (-1, GDB_SIGNAL_DEFAULT, 0);
11873 /* If we are running asynchronously, and proceed call above has
11874 actually managed to start the target, arrange for breakpoints to
11875 be deleted when the target stops. Otherwise, we're already
11876 stopped and delete breakpoints via cleanup chain. */
11878 if (target_can_async_p () && is_running (inferior_ptid))
11880 struct until_break_command_continuation_args *args;
11881 args = xmalloc (sizeof (*args));
11883 args->breakpoint = breakpoint;
11884 args->breakpoint2 = breakpoint2;
11885 args->thread_num = thread;
11887 discard_cleanups (old_chain);
11888 add_continuation (inferior_thread (),
11889 until_break_command_continuation, args,
11893 do_cleanups (old_chain);
11896 /* This function attempts to parse an optional "if <cond>" clause
11897 from the arg string. If one is not found, it returns NULL.
11899 Else, it returns a pointer to the condition string. (It does not
11900 attempt to evaluate the string against a particular block.) And,
11901 it updates arg to point to the first character following the parsed
11902 if clause in the arg string. */
11905 ep_parse_optional_if_clause (char **arg)
11909 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11912 /* Skip the "if" keyword. */
11915 /* Skip any extra leading whitespace, and record the start of the
11916 condition string. */
11917 *arg = skip_spaces (*arg);
11918 cond_string = *arg;
11920 /* Assume that the condition occupies the remainder of the arg
11922 (*arg) += strlen (cond_string);
11924 return cond_string;
11927 /* Commands to deal with catching events, such as signals, exceptions,
11928 process start/exit, etc. */
11932 catch_fork_temporary, catch_vfork_temporary,
11933 catch_fork_permanent, catch_vfork_permanent
11938 catch_fork_command_1 (char *arg, int from_tty,
11939 struct cmd_list_element *command)
11941 struct gdbarch *gdbarch = get_current_arch ();
11942 char *cond_string = NULL;
11943 catch_fork_kind fork_kind;
11946 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
11947 tempflag = (fork_kind == catch_fork_temporary
11948 || fork_kind == catch_vfork_temporary);
11952 arg = skip_spaces (arg);
11954 /* The allowed syntax is:
11956 catch [v]fork if <cond>
11958 First, check if there's an if clause. */
11959 cond_string = ep_parse_optional_if_clause (&arg);
11961 if ((*arg != '\0') && !isspace (*arg))
11962 error (_("Junk at end of arguments."));
11964 /* If this target supports it, create a fork or vfork catchpoint
11965 and enable reporting of such events. */
11968 case catch_fork_temporary:
11969 case catch_fork_permanent:
11970 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11971 &catch_fork_breakpoint_ops);
11973 case catch_vfork_temporary:
11974 case catch_vfork_permanent:
11975 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11976 &catch_vfork_breakpoint_ops);
11979 error (_("unsupported or unknown fork kind; cannot catch it"));
11985 catch_exec_command_1 (char *arg, int from_tty,
11986 struct cmd_list_element *command)
11988 struct exec_catchpoint *c;
11989 struct gdbarch *gdbarch = get_current_arch ();
11991 char *cond_string = NULL;
11993 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11997 arg = skip_spaces (arg);
11999 /* The allowed syntax is:
12001 catch exec if <cond>
12003 First, check if there's an if clause. */
12004 cond_string = ep_parse_optional_if_clause (&arg);
12006 if ((*arg != '\0') && !isspace (*arg))
12007 error (_("Junk at end of arguments."));
12009 c = XNEW (struct exec_catchpoint);
12010 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
12011 &catch_exec_breakpoint_ops);
12012 c->exec_pathname = NULL;
12014 install_breakpoint (0, &c->base, 1);
12018 init_ada_exception_breakpoint (struct breakpoint *b,
12019 struct gdbarch *gdbarch,
12020 struct symtab_and_line sal,
12022 const struct breakpoint_ops *ops,
12029 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
12031 loc_gdbarch = gdbarch;
12033 describe_other_breakpoints (loc_gdbarch,
12034 sal.pspace, sal.pc, sal.section, -1);
12035 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
12036 version for exception catchpoints, because two catchpoints
12037 used for different exception names will use the same address.
12038 In this case, a "breakpoint ... also set at..." warning is
12039 unproductive. Besides, the warning phrasing is also a bit
12040 inappropriate, we should use the word catchpoint, and tell
12041 the user what type of catchpoint it is. The above is good
12042 enough for now, though. */
12045 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
12047 b->enable_state = enabled ? bp_enabled : bp_disabled;
12048 b->disposition = tempflag ? disp_del : disp_donttouch;
12049 b->addr_string = addr_string;
12050 b->language = language_ada;
12053 /* Splits the argument using space as delimiter. Returns an xmalloc'd
12054 filter list, or NULL if no filtering is required. */
12056 catch_syscall_split_args (char *arg)
12058 VEC(int) *result = NULL;
12059 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
12061 while (*arg != '\0')
12063 int i, syscall_number;
12065 char cur_name[128];
12068 /* Skip whitespace. */
12069 arg = skip_spaces (arg);
12071 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
12072 cur_name[i] = arg[i];
12073 cur_name[i] = '\0';
12076 /* Check if the user provided a syscall name or a number. */
12077 syscall_number = (int) strtol (cur_name, &endptr, 0);
12078 if (*endptr == '\0')
12079 get_syscall_by_number (syscall_number, &s);
12082 /* We have a name. Let's check if it's valid and convert it
12084 get_syscall_by_name (cur_name, &s);
12086 if (s.number == UNKNOWN_SYSCALL)
12087 /* Here we have to issue an error instead of a warning,
12088 because GDB cannot do anything useful if there's no
12089 syscall number to be caught. */
12090 error (_("Unknown syscall name '%s'."), cur_name);
12093 /* Ok, it's valid. */
12094 VEC_safe_push (int, result, s.number);
12097 discard_cleanups (cleanup);
12101 /* Implement the "catch syscall" command. */
12104 catch_syscall_command_1 (char *arg, int from_tty,
12105 struct cmd_list_element *command)
12110 struct gdbarch *gdbarch = get_current_arch ();
12112 /* Checking if the feature if supported. */
12113 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
12114 error (_("The feature 'catch syscall' is not supported on \
12115 this architecture yet."));
12117 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
12119 arg = skip_spaces (arg);
12121 /* We need to do this first "dummy" translation in order
12122 to get the syscall XML file loaded or, most important,
12123 to display a warning to the user if there's no XML file
12124 for his/her architecture. */
12125 get_syscall_by_number (0, &s);
12127 /* The allowed syntax is:
12129 catch syscall <name | number> [<name | number> ... <name | number>]
12131 Let's check if there's a syscall name. */
12134 filter = catch_syscall_split_args (arg);
12138 create_syscall_event_catchpoint (tempflag, filter,
12139 &catch_syscall_breakpoint_ops);
12143 catch_command (char *arg, int from_tty)
12145 error (_("Catch requires an event name."));
12150 tcatch_command (char *arg, int from_tty)
12152 error (_("Catch requires an event name."));
12155 /* A qsort comparison function that sorts breakpoints in order. */
12158 compare_breakpoints (const void *a, const void *b)
12160 const breakpoint_p *ba = a;
12161 uintptr_t ua = (uintptr_t) *ba;
12162 const breakpoint_p *bb = b;
12163 uintptr_t ub = (uintptr_t) *bb;
12165 if ((*ba)->number < (*bb)->number)
12167 else if ((*ba)->number > (*bb)->number)
12170 /* Now sort by address, in case we see, e..g, two breakpoints with
12174 return ua > ub ? 1 : 0;
12177 /* Delete breakpoints by address or line. */
12180 clear_command (char *arg, int from_tty)
12182 struct breakpoint *b, *prev;
12183 VEC(breakpoint_p) *found = 0;
12186 struct symtabs_and_lines sals;
12187 struct symtab_and_line sal;
12189 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
12193 sals = decode_line_with_current_source (arg,
12194 (DECODE_LINE_FUNFIRSTLINE
12195 | DECODE_LINE_LIST_MODE));
12196 make_cleanup (xfree, sals.sals);
12201 sals.sals = (struct symtab_and_line *)
12202 xmalloc (sizeof (struct symtab_and_line));
12203 make_cleanup (xfree, sals.sals);
12204 init_sal (&sal); /* Initialize to zeroes. */
12206 /* Set sal's line, symtab, pc, and pspace to the values
12207 corresponding to the last call to print_frame_info. If the
12208 codepoint is not valid, this will set all the fields to 0. */
12209 get_last_displayed_sal (&sal);
12210 if (sal.symtab == 0)
12211 error (_("No source file specified."));
12213 sals.sals[0] = sal;
12219 /* We don't call resolve_sal_pc here. That's not as bad as it
12220 seems, because all existing breakpoints typically have both
12221 file/line and pc set. So, if clear is given file/line, we can
12222 match this to existing breakpoint without obtaining pc at all.
12224 We only support clearing given the address explicitly
12225 present in breakpoint table. Say, we've set breakpoint
12226 at file:line. There were several PC values for that file:line,
12227 due to optimization, all in one block.
12229 We've picked one PC value. If "clear" is issued with another
12230 PC corresponding to the same file:line, the breakpoint won't
12231 be cleared. We probably can still clear the breakpoint, but
12232 since the other PC value is never presented to user, user
12233 can only find it by guessing, and it does not seem important
12234 to support that. */
12236 /* For each line spec given, delete bps which correspond to it. Do
12237 it in two passes, solely to preserve the current behavior that
12238 from_tty is forced true if we delete more than one
12242 make_cleanup (VEC_cleanup (breakpoint_p), &found);
12243 for (i = 0; i < sals.nelts; i++)
12245 const char *sal_fullname;
12247 /* If exact pc given, clear bpts at that pc.
12248 If line given (pc == 0), clear all bpts on specified line.
12249 If defaulting, clear all bpts on default line
12252 defaulting sal.pc != 0 tests to do
12257 1 0 <can't happen> */
12259 sal = sals.sals[i];
12260 sal_fullname = (sal.symtab == NULL
12261 ? NULL : symtab_to_fullname (sal.symtab));
12263 /* Find all matching breakpoints and add them to 'found'. */
12264 ALL_BREAKPOINTS (b)
12267 /* Are we going to delete b? */
12268 if (b->type != bp_none && !is_watchpoint (b))
12270 struct bp_location *loc = b->loc;
12271 for (; loc; loc = loc->next)
12273 /* If the user specified file:line, don't allow a PC
12274 match. This matches historical gdb behavior. */
12275 int pc_match = (!sal.explicit_line
12277 && (loc->pspace == sal.pspace)
12278 && (loc->address == sal.pc)
12279 && (!section_is_overlay (loc->section)
12280 || loc->section == sal.section));
12281 int line_match = 0;
12283 if ((default_match || sal.explicit_line)
12284 && loc->symtab != NULL
12285 && sal_fullname != NULL
12286 && sal.pspace == loc->pspace
12287 && loc->line_number == sal.line
12288 && filename_cmp (symtab_to_fullname (loc->symtab),
12289 sal_fullname) == 0)
12292 if (pc_match || line_match)
12301 VEC_safe_push(breakpoint_p, found, b);
12305 /* Now go thru the 'found' chain and delete them. */
12306 if (VEC_empty(breakpoint_p, found))
12309 error (_("No breakpoint at %s."), arg);
12311 error (_("No breakpoint at this line."));
12314 /* Remove duplicates from the vec. */
12315 qsort (VEC_address (breakpoint_p, found),
12316 VEC_length (breakpoint_p, found),
12317 sizeof (breakpoint_p),
12318 compare_breakpoints);
12319 prev = VEC_index (breakpoint_p, found, 0);
12320 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
12324 VEC_ordered_remove (breakpoint_p, found, ix);
12329 if (VEC_length(breakpoint_p, found) > 1)
12330 from_tty = 1; /* Always report if deleted more than one. */
12333 if (VEC_length(breakpoint_p, found) == 1)
12334 printf_unfiltered (_("Deleted breakpoint "));
12336 printf_unfiltered (_("Deleted breakpoints "));
12339 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
12342 printf_unfiltered ("%d ", b->number);
12343 delete_breakpoint (b);
12346 putchar_unfiltered ('\n');
12348 do_cleanups (cleanups);
12351 /* Delete breakpoint in BS if they are `delete' breakpoints and
12352 all breakpoints that are marked for deletion, whether hit or not.
12353 This is called after any breakpoint is hit, or after errors. */
12356 breakpoint_auto_delete (bpstat bs)
12358 struct breakpoint *b, *b_tmp;
12360 for (; bs; bs = bs->next)
12361 if (bs->breakpoint_at
12362 && bs->breakpoint_at->disposition == disp_del
12364 delete_breakpoint (bs->breakpoint_at);
12366 ALL_BREAKPOINTS_SAFE (b, b_tmp)
12368 if (b->disposition == disp_del_at_next_stop)
12369 delete_breakpoint (b);
12373 /* A comparison function for bp_location AP and BP being interfaced to
12374 qsort. Sort elements primarily by their ADDRESS (no matter what
12375 does breakpoint_address_is_meaningful say for its OWNER),
12376 secondarily by ordering first bp_permanent OWNERed elements and
12377 terciarily just ensuring the array is sorted stable way despite
12378 qsort being an unstable algorithm. */
12381 bp_location_compare (const void *ap, const void *bp)
12383 struct bp_location *a = *(void **) ap;
12384 struct bp_location *b = *(void **) bp;
12385 /* A and B come from existing breakpoints having non-NULL OWNER. */
12386 int a_perm = a->owner->enable_state == bp_permanent;
12387 int b_perm = b->owner->enable_state == bp_permanent;
12389 if (a->address != b->address)
12390 return (a->address > b->address) - (a->address < b->address);
12392 /* Sort locations at the same address by their pspace number, keeping
12393 locations of the same inferior (in a multi-inferior environment)
12396 if (a->pspace->num != b->pspace->num)
12397 return ((a->pspace->num > b->pspace->num)
12398 - (a->pspace->num < b->pspace->num));
12400 /* Sort permanent breakpoints first. */
12401 if (a_perm != b_perm)
12402 return (a_perm < b_perm) - (a_perm > b_perm);
12404 /* Make the internal GDB representation stable across GDB runs
12405 where A and B memory inside GDB can differ. Breakpoint locations of
12406 the same type at the same address can be sorted in arbitrary order. */
12408 if (a->owner->number != b->owner->number)
12409 return ((a->owner->number > b->owner->number)
12410 - (a->owner->number < b->owner->number));
12412 return (a > b) - (a < b);
12415 /* Set bp_location_placed_address_before_address_max and
12416 bp_location_shadow_len_after_address_max according to the current
12417 content of the bp_location array. */
12420 bp_location_target_extensions_update (void)
12422 struct bp_location *bl, **blp_tmp;
12424 bp_location_placed_address_before_address_max = 0;
12425 bp_location_shadow_len_after_address_max = 0;
12427 ALL_BP_LOCATIONS (bl, blp_tmp)
12429 CORE_ADDR start, end, addr;
12431 if (!bp_location_has_shadow (bl))
12434 start = bl->target_info.placed_address;
12435 end = start + bl->target_info.shadow_len;
12437 gdb_assert (bl->address >= start);
12438 addr = bl->address - start;
12439 if (addr > bp_location_placed_address_before_address_max)
12440 bp_location_placed_address_before_address_max = addr;
12442 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12444 gdb_assert (bl->address < end);
12445 addr = end - bl->address;
12446 if (addr > bp_location_shadow_len_after_address_max)
12447 bp_location_shadow_len_after_address_max = addr;
12451 /* Download tracepoint locations if they haven't been. */
12454 download_tracepoint_locations (void)
12456 struct breakpoint *b;
12457 struct cleanup *old_chain;
12459 if (!target_can_download_tracepoint ())
12462 old_chain = save_current_space_and_thread ();
12464 ALL_TRACEPOINTS (b)
12466 struct bp_location *bl;
12467 struct tracepoint *t;
12468 int bp_location_downloaded = 0;
12470 if ((b->type == bp_fast_tracepoint
12471 ? !may_insert_fast_tracepoints
12472 : !may_insert_tracepoints))
12475 for (bl = b->loc; bl; bl = bl->next)
12477 /* In tracepoint, locations are _never_ duplicated, so
12478 should_be_inserted is equivalent to
12479 unduplicated_should_be_inserted. */
12480 if (!should_be_inserted (bl) || bl->inserted)
12483 switch_to_program_space_and_thread (bl->pspace);
12485 target_download_tracepoint (bl);
12488 bp_location_downloaded = 1;
12490 t = (struct tracepoint *) b;
12491 t->number_on_target = b->number;
12492 if (bp_location_downloaded)
12493 observer_notify_breakpoint_modified (b);
12496 do_cleanups (old_chain);
12499 /* Swap the insertion/duplication state between two locations. */
12502 swap_insertion (struct bp_location *left, struct bp_location *right)
12504 const int left_inserted = left->inserted;
12505 const int left_duplicate = left->duplicate;
12506 const int left_needs_update = left->needs_update;
12507 const struct bp_target_info left_target_info = left->target_info;
12509 /* Locations of tracepoints can never be duplicated. */
12510 if (is_tracepoint (left->owner))
12511 gdb_assert (!left->duplicate);
12512 if (is_tracepoint (right->owner))
12513 gdb_assert (!right->duplicate);
12515 left->inserted = right->inserted;
12516 left->duplicate = right->duplicate;
12517 left->needs_update = right->needs_update;
12518 left->target_info = right->target_info;
12519 right->inserted = left_inserted;
12520 right->duplicate = left_duplicate;
12521 right->needs_update = left_needs_update;
12522 right->target_info = left_target_info;
12525 /* Force the re-insertion of the locations at ADDRESS. This is called
12526 once a new/deleted/modified duplicate location is found and we are evaluating
12527 conditions on the target's side. Such conditions need to be updated on
12531 force_breakpoint_reinsertion (struct bp_location *bl)
12533 struct bp_location **locp = NULL, **loc2p;
12534 struct bp_location *loc;
12535 CORE_ADDR address = 0;
12538 address = bl->address;
12539 pspace_num = bl->pspace->num;
12541 /* This is only meaningful if the target is
12542 evaluating conditions and if the user has
12543 opted for condition evaluation on the target's
12545 if (gdb_evaluates_breakpoint_condition_p ()
12546 || !target_supports_evaluation_of_breakpoint_conditions ())
12549 /* Flag all breakpoint locations with this address and
12550 the same program space as the location
12551 as "its condition has changed". We need to
12552 update the conditions on the target's side. */
12553 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
12557 if (!is_breakpoint (loc->owner)
12558 || pspace_num != loc->pspace->num)
12561 /* Flag the location appropriately. We use a different state to
12562 let everyone know that we already updated the set of locations
12563 with addr bl->address and program space bl->pspace. This is so
12564 we don't have to keep calling these functions just to mark locations
12565 that have already been marked. */
12566 loc->condition_changed = condition_updated;
12568 /* Free the agent expression bytecode as well. We will compute
12570 if (loc->cond_bytecode)
12572 free_agent_expr (loc->cond_bytecode);
12573 loc->cond_bytecode = NULL;
12577 /* Called whether new breakpoints are created, or existing breakpoints
12578 deleted, to update the global location list and recompute which
12579 locations are duplicate of which.
12581 The INSERT_MODE flag determines whether locations may or may not be
12582 inserted now. See 'enum ugll_insert_mode' for more info. */
12585 update_global_location_list (enum ugll_insert_mode insert_mode)
12587 struct breakpoint *b;
12588 struct bp_location **locp, *loc;
12589 struct cleanup *cleanups;
12590 /* Last breakpoint location address that was marked for update. */
12591 CORE_ADDR last_addr = 0;
12592 /* Last breakpoint location program space that was marked for update. */
12593 int last_pspace_num = -1;
12595 /* Used in the duplicates detection below. When iterating over all
12596 bp_locations, points to the first bp_location of a given address.
12597 Breakpoints and watchpoints of different types are never
12598 duplicates of each other. Keep one pointer for each type of
12599 breakpoint/watchpoint, so we only need to loop over all locations
12601 struct bp_location *bp_loc_first; /* breakpoint */
12602 struct bp_location *wp_loc_first; /* hardware watchpoint */
12603 struct bp_location *awp_loc_first; /* access watchpoint */
12604 struct bp_location *rwp_loc_first; /* read watchpoint */
12606 /* Saved former bp_location array which we compare against the newly
12607 built bp_location from the current state of ALL_BREAKPOINTS. */
12608 struct bp_location **old_location, **old_locp;
12609 unsigned old_location_count;
12611 old_location = bp_location;
12612 old_location_count = bp_location_count;
12613 bp_location = NULL;
12614 bp_location_count = 0;
12615 cleanups = make_cleanup (xfree, old_location);
12617 ALL_BREAKPOINTS (b)
12618 for (loc = b->loc; loc; loc = loc->next)
12619 bp_location_count++;
12621 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
12622 locp = bp_location;
12623 ALL_BREAKPOINTS (b)
12624 for (loc = b->loc; loc; loc = loc->next)
12626 qsort (bp_location, bp_location_count, sizeof (*bp_location),
12627 bp_location_compare);
12629 bp_location_target_extensions_update ();
12631 /* Identify bp_location instances that are no longer present in the
12632 new list, and therefore should be freed. Note that it's not
12633 necessary that those locations should be removed from inferior --
12634 if there's another location at the same address (previously
12635 marked as duplicate), we don't need to remove/insert the
12638 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12639 and former bp_location array state respectively. */
12641 locp = bp_location;
12642 for (old_locp = old_location; old_locp < old_location + old_location_count;
12645 struct bp_location *old_loc = *old_locp;
12646 struct bp_location **loc2p;
12648 /* Tells if 'old_loc' is found among the new locations. If
12649 not, we have to free it. */
12650 int found_object = 0;
12651 /* Tells if the location should remain inserted in the target. */
12652 int keep_in_target = 0;
12655 /* Skip LOCP entries which will definitely never be needed.
12656 Stop either at or being the one matching OLD_LOC. */
12657 while (locp < bp_location + bp_location_count
12658 && (*locp)->address < old_loc->address)
12662 (loc2p < bp_location + bp_location_count
12663 && (*loc2p)->address == old_loc->address);
12666 /* Check if this is a new/duplicated location or a duplicated
12667 location that had its condition modified. If so, we want to send
12668 its condition to the target if evaluation of conditions is taking
12670 if ((*loc2p)->condition_changed == condition_modified
12671 && (last_addr != old_loc->address
12672 || last_pspace_num != old_loc->pspace->num))
12674 force_breakpoint_reinsertion (*loc2p);
12675 last_pspace_num = old_loc->pspace->num;
12678 if (*loc2p == old_loc)
12682 /* We have already handled this address, update it so that we don't
12683 have to go through updates again. */
12684 last_addr = old_loc->address;
12686 /* Target-side condition evaluation: Handle deleted locations. */
12688 force_breakpoint_reinsertion (old_loc);
12690 /* If this location is no longer present, and inserted, look if
12691 there's maybe a new location at the same address. If so,
12692 mark that one inserted, and don't remove this one. This is
12693 needed so that we don't have a time window where a breakpoint
12694 at certain location is not inserted. */
12696 if (old_loc->inserted)
12698 /* If the location is inserted now, we might have to remove
12701 if (found_object && should_be_inserted (old_loc))
12703 /* The location is still present in the location list,
12704 and still should be inserted. Don't do anything. */
12705 keep_in_target = 1;
12709 /* This location still exists, but it won't be kept in the
12710 target since it may have been disabled. We proceed to
12711 remove its target-side condition. */
12713 /* The location is either no longer present, or got
12714 disabled. See if there's another location at the
12715 same address, in which case we don't need to remove
12716 this one from the target. */
12718 /* OLD_LOC comes from existing struct breakpoint. */
12719 if (breakpoint_address_is_meaningful (old_loc->owner))
12722 (loc2p < bp_location + bp_location_count
12723 && (*loc2p)->address == old_loc->address);
12726 struct bp_location *loc2 = *loc2p;
12728 if (breakpoint_locations_match (loc2, old_loc))
12730 /* Read watchpoint locations are switched to
12731 access watchpoints, if the former are not
12732 supported, but the latter are. */
12733 if (is_hardware_watchpoint (old_loc->owner))
12735 gdb_assert (is_hardware_watchpoint (loc2->owner));
12736 loc2->watchpoint_type = old_loc->watchpoint_type;
12739 /* loc2 is a duplicated location. We need to check
12740 if it should be inserted in case it will be
12742 if (loc2 != old_loc
12743 && unduplicated_should_be_inserted (loc2))
12745 swap_insertion (old_loc, loc2);
12746 keep_in_target = 1;
12754 if (!keep_in_target)
12756 if (remove_breakpoint (old_loc, mark_uninserted))
12758 /* This is just about all we can do. We could keep
12759 this location on the global list, and try to
12760 remove it next time, but there's no particular
12761 reason why we will succeed next time.
12763 Note that at this point, old_loc->owner is still
12764 valid, as delete_breakpoint frees the breakpoint
12765 only after calling us. */
12766 printf_filtered (_("warning: Error removing "
12767 "breakpoint %d\n"),
12768 old_loc->owner->number);
12776 if (removed && non_stop
12777 && breakpoint_address_is_meaningful (old_loc->owner)
12778 && !is_hardware_watchpoint (old_loc->owner))
12780 /* This location was removed from the target. In
12781 non-stop mode, a race condition is possible where
12782 we've removed a breakpoint, but stop events for that
12783 breakpoint are already queued and will arrive later.
12784 We apply an heuristic to be able to distinguish such
12785 SIGTRAPs from other random SIGTRAPs: we keep this
12786 breakpoint location for a bit, and will retire it
12787 after we see some number of events. The theory here
12788 is that reporting of events should, "on the average",
12789 be fair, so after a while we'll see events from all
12790 threads that have anything of interest, and no longer
12791 need to keep this breakpoint location around. We
12792 don't hold locations forever so to reduce chances of
12793 mistaking a non-breakpoint SIGTRAP for a breakpoint
12796 The heuristic failing can be disastrous on
12797 decr_pc_after_break targets.
12799 On decr_pc_after_break targets, like e.g., x86-linux,
12800 if we fail to recognize a late breakpoint SIGTRAP,
12801 because events_till_retirement has reached 0 too
12802 soon, we'll fail to do the PC adjustment, and report
12803 a random SIGTRAP to the user. When the user resumes
12804 the inferior, it will most likely immediately crash
12805 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12806 corrupted, because of being resumed e.g., in the
12807 middle of a multi-byte instruction, or skipped a
12808 one-byte instruction. This was actually seen happen
12809 on native x86-linux, and should be less rare on
12810 targets that do not support new thread events, like
12811 remote, due to the heuristic depending on
12814 Mistaking a random SIGTRAP for a breakpoint trap
12815 causes similar symptoms (PC adjustment applied when
12816 it shouldn't), but then again, playing with SIGTRAPs
12817 behind the debugger's back is asking for trouble.
12819 Since hardware watchpoint traps are always
12820 distinguishable from other traps, so we don't need to
12821 apply keep hardware watchpoint moribund locations
12822 around. We simply always ignore hardware watchpoint
12823 traps we can no longer explain. */
12825 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12826 old_loc->owner = NULL;
12828 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12832 old_loc->owner = NULL;
12833 decref_bp_location (&old_loc);
12838 /* Rescan breakpoints at the same address and section, marking the
12839 first one as "first" and any others as "duplicates". This is so
12840 that the bpt instruction is only inserted once. If we have a
12841 permanent breakpoint at the same place as BPT, make that one the
12842 official one, and the rest as duplicates. Permanent breakpoints
12843 are sorted first for the same address.
12845 Do the same for hardware watchpoints, but also considering the
12846 watchpoint's type (regular/access/read) and length. */
12848 bp_loc_first = NULL;
12849 wp_loc_first = NULL;
12850 awp_loc_first = NULL;
12851 rwp_loc_first = NULL;
12852 ALL_BP_LOCATIONS (loc, locp)
12854 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12856 struct bp_location **loc_first_p;
12859 if (!unduplicated_should_be_inserted (loc)
12860 || !breakpoint_address_is_meaningful (b)
12861 /* Don't detect duplicate for tracepoint locations because they are
12862 never duplicated. See the comments in field `duplicate' of
12863 `struct bp_location'. */
12864 || is_tracepoint (b))
12866 /* Clear the condition modification flag. */
12867 loc->condition_changed = condition_unchanged;
12871 /* Permanent breakpoint should always be inserted. */
12872 if (b->enable_state == bp_permanent && ! loc->inserted)
12873 internal_error (__FILE__, __LINE__,
12874 _("allegedly permanent breakpoint is not "
12875 "actually inserted"));
12877 if (b->type == bp_hardware_watchpoint)
12878 loc_first_p = &wp_loc_first;
12879 else if (b->type == bp_read_watchpoint)
12880 loc_first_p = &rwp_loc_first;
12881 else if (b->type == bp_access_watchpoint)
12882 loc_first_p = &awp_loc_first;
12884 loc_first_p = &bp_loc_first;
12886 if (*loc_first_p == NULL
12887 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12888 || !breakpoint_locations_match (loc, *loc_first_p))
12890 *loc_first_p = loc;
12891 loc->duplicate = 0;
12893 if (is_breakpoint (loc->owner) && loc->condition_changed)
12895 loc->needs_update = 1;
12896 /* Clear the condition modification flag. */
12897 loc->condition_changed = condition_unchanged;
12903 /* This and the above ensure the invariant that the first location
12904 is not duplicated, and is the inserted one.
12905 All following are marked as duplicated, and are not inserted. */
12907 swap_insertion (loc, *loc_first_p);
12908 loc->duplicate = 1;
12910 /* Clear the condition modification flag. */
12911 loc->condition_changed = condition_unchanged;
12913 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
12914 && b->enable_state != bp_permanent)
12915 internal_error (__FILE__, __LINE__,
12916 _("another breakpoint was inserted on top of "
12917 "a permanent breakpoint"));
12920 if (breakpoints_always_inserted_mode ()
12921 && (have_live_inferiors ()
12922 || (gdbarch_has_global_breakpoints (target_gdbarch ()))))
12924 if (insert_mode == UGLL_MAY_INSERT)
12925 insert_breakpoint_locations ();
12928 /* Even though the caller told us to not insert new
12929 locations, we may still need to update conditions on the
12930 target's side of breakpoints that were already inserted
12931 if the target is evaluating breakpoint conditions. We
12932 only update conditions for locations that are marked
12934 update_inserted_breakpoint_locations ();
12938 if (insert_mode == UGLL_MAY_INSERT)
12939 download_tracepoint_locations ();
12941 do_cleanups (cleanups);
12945 breakpoint_retire_moribund (void)
12947 struct bp_location *loc;
12950 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12951 if (--(loc->events_till_retirement) == 0)
12953 decref_bp_location (&loc);
12954 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12960 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode)
12962 volatile struct gdb_exception e;
12964 TRY_CATCH (e, RETURN_MASK_ERROR)
12965 update_global_location_list (insert_mode);
12968 /* Clear BKP from a BPS. */
12971 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12975 for (bs = bps; bs; bs = bs->next)
12976 if (bs->breakpoint_at == bpt)
12978 bs->breakpoint_at = NULL;
12979 bs->old_val = NULL;
12980 /* bs->commands will be freed later. */
12984 /* Callback for iterate_over_threads. */
12986 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12988 struct breakpoint *bpt = data;
12990 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12994 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12998 say_where (struct breakpoint *b)
13000 struct value_print_options opts;
13002 get_user_print_options (&opts);
13004 /* i18n: cagney/2005-02-11: Below needs to be merged into a
13006 if (b->loc == NULL)
13008 printf_filtered (_(" (%s) pending."), b->addr_string);
13012 if (opts.addressprint || b->loc->symtab == NULL)
13014 printf_filtered (" at ");
13015 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
13018 if (b->loc->symtab != NULL)
13020 /* If there is a single location, we can print the location
13022 if (b->loc->next == NULL)
13023 printf_filtered (": file %s, line %d.",
13024 symtab_to_filename_for_display (b->loc->symtab),
13025 b->loc->line_number);
13027 /* This is not ideal, but each location may have a
13028 different file name, and this at least reflects the
13029 real situation somewhat. */
13030 printf_filtered (": %s.", b->addr_string);
13035 struct bp_location *loc = b->loc;
13037 for (; loc; loc = loc->next)
13039 printf_filtered (" (%d locations)", n);
13044 /* Default bp_location_ops methods. */
13047 bp_location_dtor (struct bp_location *self)
13049 xfree (self->cond);
13050 if (self->cond_bytecode)
13051 free_agent_expr (self->cond_bytecode);
13052 xfree (self->function_name);
13054 VEC_free (agent_expr_p, self->target_info.conditions);
13055 VEC_free (agent_expr_p, self->target_info.tcommands);
13058 static const struct bp_location_ops bp_location_ops =
13063 /* Default breakpoint_ops methods all breakpoint_ops ultimately
13067 base_breakpoint_dtor (struct breakpoint *self)
13069 decref_counted_command_line (&self->commands);
13070 xfree (self->cond_string);
13071 xfree (self->extra_string);
13072 xfree (self->addr_string);
13073 xfree (self->filter);
13074 xfree (self->addr_string_range_end);
13077 static struct bp_location *
13078 base_breakpoint_allocate_location (struct breakpoint *self)
13080 struct bp_location *loc;
13082 loc = XNEW (struct bp_location);
13083 init_bp_location (loc, &bp_location_ops, self);
13088 base_breakpoint_re_set (struct breakpoint *b)
13090 /* Nothing to re-set. */
13093 #define internal_error_pure_virtual_called() \
13094 gdb_assert_not_reached ("pure virtual function called")
13097 base_breakpoint_insert_location (struct bp_location *bl)
13099 internal_error_pure_virtual_called ();
13103 base_breakpoint_remove_location (struct bp_location *bl)
13105 internal_error_pure_virtual_called ();
13109 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
13110 struct address_space *aspace,
13112 const struct target_waitstatus *ws)
13114 internal_error_pure_virtual_called ();
13118 base_breakpoint_check_status (bpstat bs)
13123 /* A "works_in_software_mode" breakpoint_ops method that just internal
13127 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
13129 internal_error_pure_virtual_called ();
13132 /* A "resources_needed" breakpoint_ops method that just internal
13136 base_breakpoint_resources_needed (const struct bp_location *bl)
13138 internal_error_pure_virtual_called ();
13141 static enum print_stop_action
13142 base_breakpoint_print_it (bpstat bs)
13144 internal_error_pure_virtual_called ();
13148 base_breakpoint_print_one_detail (const struct breakpoint *self,
13149 struct ui_out *uiout)
13155 base_breakpoint_print_mention (struct breakpoint *b)
13157 internal_error_pure_virtual_called ();
13161 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
13163 internal_error_pure_virtual_called ();
13167 base_breakpoint_create_sals_from_address (char **arg,
13168 struct linespec_result *canonical,
13169 enum bptype type_wanted,
13173 internal_error_pure_virtual_called ();
13177 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13178 struct linespec_result *c,
13180 char *extra_string,
13181 enum bptype type_wanted,
13182 enum bpdisp disposition,
13184 int task, int ignore_count,
13185 const struct breakpoint_ops *o,
13186 int from_tty, int enabled,
13187 int internal, unsigned flags)
13189 internal_error_pure_virtual_called ();
13193 base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
13194 struct symtabs_and_lines *sals)
13196 internal_error_pure_virtual_called ();
13199 /* The default 'explains_signal' method. */
13202 base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig)
13207 /* The default "after_condition_true" method. */
13210 base_breakpoint_after_condition_true (struct bpstats *bs)
13212 /* Nothing to do. */
13215 struct breakpoint_ops base_breakpoint_ops =
13217 base_breakpoint_dtor,
13218 base_breakpoint_allocate_location,
13219 base_breakpoint_re_set,
13220 base_breakpoint_insert_location,
13221 base_breakpoint_remove_location,
13222 base_breakpoint_breakpoint_hit,
13223 base_breakpoint_check_status,
13224 base_breakpoint_resources_needed,
13225 base_breakpoint_works_in_software_mode,
13226 base_breakpoint_print_it,
13228 base_breakpoint_print_one_detail,
13229 base_breakpoint_print_mention,
13230 base_breakpoint_print_recreate,
13231 base_breakpoint_create_sals_from_address,
13232 base_breakpoint_create_breakpoints_sal,
13233 base_breakpoint_decode_linespec,
13234 base_breakpoint_explains_signal,
13235 base_breakpoint_after_condition_true,
13238 /* Default breakpoint_ops methods. */
13241 bkpt_re_set (struct breakpoint *b)
13243 /* FIXME: is this still reachable? */
13244 if (b->addr_string == NULL)
13246 /* Anything without a string can't be re-set. */
13247 delete_breakpoint (b);
13251 breakpoint_re_set_default (b);
13254 /* Copy SRC's shadow buffer and whatever else we'd set if we actually
13255 inserted DEST, so we can remove it later, in case SRC is removed
13259 bp_target_info_copy_insertion_state (struct bp_target_info *dest,
13260 const struct bp_target_info *src)
13262 dest->shadow_len = src->shadow_len;
13263 memcpy (dest->shadow_contents, src->shadow_contents, src->shadow_len);
13264 dest->placed_size = src->placed_size;
13268 bkpt_insert_location (struct bp_location *bl)
13270 if (bl->loc_type == bp_loc_hardware_breakpoint)
13271 return target_insert_hw_breakpoint (bl->gdbarch,
13275 struct bp_target_info *bp_tgt = &bl->target_info;
13279 /* There is no need to insert a breakpoint if an unconditional
13280 raw/sss breakpoint is already inserted at that location. */
13281 sss_slot = find_single_step_breakpoint (bp_tgt->placed_address_space,
13282 bp_tgt->placed_address);
13285 struct bp_target_info *sss_bp_tgt = single_step_breakpoints[sss_slot];
13287 bp_target_info_copy_insertion_state (bp_tgt, sss_bp_tgt);
13291 return target_insert_breakpoint (bl->gdbarch, bp_tgt);
13296 bkpt_remove_location (struct bp_location *bl)
13298 if (bl->loc_type == bp_loc_hardware_breakpoint)
13299 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
13302 struct bp_target_info *bp_tgt = &bl->target_info;
13303 struct address_space *aspace = bp_tgt->placed_address_space;
13304 CORE_ADDR address = bp_tgt->placed_address;
13306 /* Only remove the breakpoint if there is no raw/sss breakpoint
13307 still inserted at this location. Otherwise, we would be
13308 effectively disabling the raw/sss breakpoint. */
13309 if (single_step_breakpoint_inserted_here_p (aspace, address))
13312 return target_remove_breakpoint (bl->gdbarch, bp_tgt);
13317 bkpt_breakpoint_hit (const struct bp_location *bl,
13318 struct address_space *aspace, CORE_ADDR bp_addr,
13319 const struct target_waitstatus *ws)
13321 if (ws->kind != TARGET_WAITKIND_STOPPED
13322 || ws->value.sig != GDB_SIGNAL_TRAP)
13325 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
13329 if (overlay_debugging /* unmapped overlay section */
13330 && section_is_overlay (bl->section)
13331 && !section_is_mapped (bl->section))
13338 dprintf_breakpoint_hit (const struct bp_location *bl,
13339 struct address_space *aspace, CORE_ADDR bp_addr,
13340 const struct target_waitstatus *ws)
13342 if (dprintf_style == dprintf_style_agent
13343 && target_can_run_breakpoint_commands ())
13345 /* An agent-style dprintf never causes a stop. If we see a trap
13346 for this address it must be for a breakpoint that happens to
13347 be set at the same address. */
13351 return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws);
13355 bkpt_resources_needed (const struct bp_location *bl)
13357 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
13362 static enum print_stop_action
13363 bkpt_print_it (bpstat bs)
13365 struct breakpoint *b;
13366 const struct bp_location *bl;
13368 struct ui_out *uiout = current_uiout;
13370 gdb_assert (bs->bp_location_at != NULL);
13372 bl = bs->bp_location_at;
13373 b = bs->breakpoint_at;
13375 bp_temp = b->disposition == disp_del;
13376 if (bl->address != bl->requested_address)
13377 breakpoint_adjustment_warning (bl->requested_address,
13380 annotate_breakpoint (b->number);
13382 ui_out_text (uiout, "\nTemporary breakpoint ");
13384 ui_out_text (uiout, "\nBreakpoint ");
13385 if (ui_out_is_mi_like_p (uiout))
13387 ui_out_field_string (uiout, "reason",
13388 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
13389 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
13391 ui_out_field_int (uiout, "bkptno", b->number);
13392 ui_out_text (uiout, ", ");
13394 return PRINT_SRC_AND_LOC;
13398 bkpt_print_mention (struct breakpoint *b)
13400 if (ui_out_is_mi_like_p (current_uiout))
13405 case bp_breakpoint:
13406 case bp_gnu_ifunc_resolver:
13407 if (b->disposition == disp_del)
13408 printf_filtered (_("Temporary breakpoint"));
13410 printf_filtered (_("Breakpoint"));
13411 printf_filtered (_(" %d"), b->number);
13412 if (b->type == bp_gnu_ifunc_resolver)
13413 printf_filtered (_(" at gnu-indirect-function resolver"));
13415 case bp_hardware_breakpoint:
13416 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
13419 printf_filtered (_("Dprintf %d"), b->number);
13427 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13429 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
13430 fprintf_unfiltered (fp, "tbreak");
13431 else if (tp->type == bp_breakpoint)
13432 fprintf_unfiltered (fp, "break");
13433 else if (tp->type == bp_hardware_breakpoint
13434 && tp->disposition == disp_del)
13435 fprintf_unfiltered (fp, "thbreak");
13436 else if (tp->type == bp_hardware_breakpoint)
13437 fprintf_unfiltered (fp, "hbreak");
13439 internal_error (__FILE__, __LINE__,
13440 _("unhandled breakpoint type %d"), (int) tp->type);
13442 fprintf_unfiltered (fp, " %s", tp->addr_string);
13443 print_recreate_thread (tp, fp);
13447 bkpt_create_sals_from_address (char **arg,
13448 struct linespec_result *canonical,
13449 enum bptype type_wanted,
13450 char *addr_start, char **copy_arg)
13452 create_sals_from_address_default (arg, canonical, type_wanted,
13453 addr_start, copy_arg);
13457 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
13458 struct linespec_result *canonical,
13460 char *extra_string,
13461 enum bptype type_wanted,
13462 enum bpdisp disposition,
13464 int task, int ignore_count,
13465 const struct breakpoint_ops *ops,
13466 int from_tty, int enabled,
13467 int internal, unsigned flags)
13469 create_breakpoints_sal_default (gdbarch, canonical,
13470 cond_string, extra_string,
13472 disposition, thread, task,
13473 ignore_count, ops, from_tty,
13474 enabled, internal, flags);
13478 bkpt_decode_linespec (struct breakpoint *b, char **s,
13479 struct symtabs_and_lines *sals)
13481 decode_linespec_default (b, s, sals);
13484 /* Virtual table for internal breakpoints. */
13487 internal_bkpt_re_set (struct breakpoint *b)
13491 /* Delete overlay event and longjmp master breakpoints; they
13492 will be reset later by breakpoint_re_set. */
13493 case bp_overlay_event:
13494 case bp_longjmp_master:
13495 case bp_std_terminate_master:
13496 case bp_exception_master:
13497 delete_breakpoint (b);
13500 /* This breakpoint is special, it's set up when the inferior
13501 starts and we really don't want to touch it. */
13502 case bp_shlib_event:
13504 /* Like bp_shlib_event, this breakpoint type is special. Once
13505 it is set up, we do not want to touch it. */
13506 case bp_thread_event:
13512 internal_bkpt_check_status (bpstat bs)
13514 if (bs->breakpoint_at->type == bp_shlib_event)
13516 /* If requested, stop when the dynamic linker notifies GDB of
13517 events. This allows the user to get control and place
13518 breakpoints in initializer routines for dynamically loaded
13519 objects (among other things). */
13520 bs->stop = stop_on_solib_events;
13521 bs->print = stop_on_solib_events;
13527 static enum print_stop_action
13528 internal_bkpt_print_it (bpstat bs)
13530 struct breakpoint *b;
13532 b = bs->breakpoint_at;
13536 case bp_shlib_event:
13537 /* Did we stop because the user set the stop_on_solib_events
13538 variable? (If so, we report this as a generic, "Stopped due
13539 to shlib event" message.) */
13540 print_solib_event (0);
13543 case bp_thread_event:
13544 /* Not sure how we will get here.
13545 GDB should not stop for these breakpoints. */
13546 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13549 case bp_overlay_event:
13550 /* By analogy with the thread event, GDB should not stop for these. */
13551 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13554 case bp_longjmp_master:
13555 /* These should never be enabled. */
13556 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13559 case bp_std_terminate_master:
13560 /* These should never be enabled. */
13561 printf_filtered (_("std::terminate Master Breakpoint: "
13562 "gdb should not stop!\n"));
13565 case bp_exception_master:
13566 /* These should never be enabled. */
13567 printf_filtered (_("Exception Master Breakpoint: "
13568 "gdb should not stop!\n"));
13572 return PRINT_NOTHING;
13576 internal_bkpt_print_mention (struct breakpoint *b)
13578 /* Nothing to mention. These breakpoints are internal. */
13581 /* Virtual table for momentary breakpoints */
13584 momentary_bkpt_re_set (struct breakpoint *b)
13586 /* Keep temporary breakpoints, which can be encountered when we step
13587 over a dlopen call and solib_add is resetting the breakpoints.
13588 Otherwise these should have been blown away via the cleanup chain
13589 or by breakpoint_init_inferior when we rerun the executable. */
13593 momentary_bkpt_check_status (bpstat bs)
13595 /* Nothing. The point of these breakpoints is causing a stop. */
13598 static enum print_stop_action
13599 momentary_bkpt_print_it (bpstat bs)
13601 struct ui_out *uiout = current_uiout;
13603 if (ui_out_is_mi_like_p (uiout))
13605 struct breakpoint *b = bs->breakpoint_at;
13610 ui_out_field_string
13612 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
13616 ui_out_field_string
13618 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
13623 return PRINT_UNKNOWN;
13627 momentary_bkpt_print_mention (struct breakpoint *b)
13629 /* Nothing to mention. These breakpoints are internal. */
13632 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13634 It gets cleared already on the removal of the first one of such placed
13635 breakpoints. This is OK as they get all removed altogether. */
13638 longjmp_bkpt_dtor (struct breakpoint *self)
13640 struct thread_info *tp = find_thread_id (self->thread);
13643 tp->initiating_frame = null_frame_id;
13645 momentary_breakpoint_ops.dtor (self);
13648 /* Specific methods for probe breakpoints. */
13651 bkpt_probe_insert_location (struct bp_location *bl)
13653 int v = bkpt_insert_location (bl);
13657 /* The insertion was successful, now let's set the probe's semaphore
13659 bl->probe.probe->pops->set_semaphore (bl->probe.probe,
13668 bkpt_probe_remove_location (struct bp_location *bl)
13670 /* Let's clear the semaphore before removing the location. */
13671 bl->probe.probe->pops->clear_semaphore (bl->probe.probe,
13675 return bkpt_remove_location (bl);
13679 bkpt_probe_create_sals_from_address (char **arg,
13680 struct linespec_result *canonical,
13681 enum bptype type_wanted,
13682 char *addr_start, char **copy_arg)
13684 struct linespec_sals lsal;
13686 lsal.sals = parse_probes (arg, canonical);
13688 *copy_arg = xstrdup (canonical->addr_string);
13689 lsal.canonical = xstrdup (*copy_arg);
13691 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13695 bkpt_probe_decode_linespec (struct breakpoint *b, char **s,
13696 struct symtabs_and_lines *sals)
13698 *sals = parse_probes (s, NULL);
13700 error (_("probe not found"));
13703 /* The breakpoint_ops structure to be used in tracepoints. */
13706 tracepoint_re_set (struct breakpoint *b)
13708 breakpoint_re_set_default (b);
13712 tracepoint_breakpoint_hit (const struct bp_location *bl,
13713 struct address_space *aspace, CORE_ADDR bp_addr,
13714 const struct target_waitstatus *ws)
13716 /* By definition, the inferior does not report stops at
13722 tracepoint_print_one_detail (const struct breakpoint *self,
13723 struct ui_out *uiout)
13725 struct tracepoint *tp = (struct tracepoint *) self;
13726 if (tp->static_trace_marker_id)
13728 gdb_assert (self->type == bp_static_tracepoint);
13730 ui_out_text (uiout, "\tmarker id is ");
13731 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
13732 tp->static_trace_marker_id);
13733 ui_out_text (uiout, "\n");
13738 tracepoint_print_mention (struct breakpoint *b)
13740 if (ui_out_is_mi_like_p (current_uiout))
13745 case bp_tracepoint:
13746 printf_filtered (_("Tracepoint"));
13747 printf_filtered (_(" %d"), b->number);
13749 case bp_fast_tracepoint:
13750 printf_filtered (_("Fast tracepoint"));
13751 printf_filtered (_(" %d"), b->number);
13753 case bp_static_tracepoint:
13754 printf_filtered (_("Static tracepoint"));
13755 printf_filtered (_(" %d"), b->number);
13758 internal_error (__FILE__, __LINE__,
13759 _("unhandled tracepoint type %d"), (int) b->type);
13766 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
13768 struct tracepoint *tp = (struct tracepoint *) self;
13770 if (self->type == bp_fast_tracepoint)
13771 fprintf_unfiltered (fp, "ftrace");
13772 if (self->type == bp_static_tracepoint)
13773 fprintf_unfiltered (fp, "strace");
13774 else if (self->type == bp_tracepoint)
13775 fprintf_unfiltered (fp, "trace");
13777 internal_error (__FILE__, __LINE__,
13778 _("unhandled tracepoint type %d"), (int) self->type);
13780 fprintf_unfiltered (fp, " %s", self->addr_string);
13781 print_recreate_thread (self, fp);
13783 if (tp->pass_count)
13784 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
13788 tracepoint_create_sals_from_address (char **arg,
13789 struct linespec_result *canonical,
13790 enum bptype type_wanted,
13791 char *addr_start, char **copy_arg)
13793 create_sals_from_address_default (arg, canonical, type_wanted,
13794 addr_start, copy_arg);
13798 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13799 struct linespec_result *canonical,
13801 char *extra_string,
13802 enum bptype type_wanted,
13803 enum bpdisp disposition,
13805 int task, int ignore_count,
13806 const struct breakpoint_ops *ops,
13807 int from_tty, int enabled,
13808 int internal, unsigned flags)
13810 create_breakpoints_sal_default (gdbarch, canonical,
13811 cond_string, extra_string,
13813 disposition, thread, task,
13814 ignore_count, ops, from_tty,
13815 enabled, internal, flags);
13819 tracepoint_decode_linespec (struct breakpoint *b, char **s,
13820 struct symtabs_and_lines *sals)
13822 decode_linespec_default (b, s, sals);
13825 struct breakpoint_ops tracepoint_breakpoint_ops;
13827 /* The breakpoint_ops structure to be use on tracepoints placed in a
13831 tracepoint_probe_create_sals_from_address (char **arg,
13832 struct linespec_result *canonical,
13833 enum bptype type_wanted,
13834 char *addr_start, char **copy_arg)
13836 /* We use the same method for breakpoint on probes. */
13837 bkpt_probe_create_sals_from_address (arg, canonical, type_wanted,
13838 addr_start, copy_arg);
13842 tracepoint_probe_decode_linespec (struct breakpoint *b, char **s,
13843 struct symtabs_and_lines *sals)
13845 /* We use the same method for breakpoint on probes. */
13846 bkpt_probe_decode_linespec (b, s, sals);
13849 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
13851 /* Dprintf breakpoint_ops methods. */
13854 dprintf_re_set (struct breakpoint *b)
13856 breakpoint_re_set_default (b);
13858 /* This breakpoint could have been pending, and be resolved now, and
13859 if so, we should now have the extra string. If we don't, the
13860 dprintf was malformed when created, but we couldn't tell because
13861 we can't extract the extra string until the location is
13863 if (b->loc != NULL && b->extra_string == NULL)
13864 error (_("Format string required"));
13866 /* 1 - connect to target 1, that can run breakpoint commands.
13867 2 - create a dprintf, which resolves fine.
13868 3 - disconnect from target 1
13869 4 - connect to target 2, that can NOT run breakpoint commands.
13871 After steps #3/#4, you'll want the dprintf command list to
13872 be updated, because target 1 and 2 may well return different
13873 answers for target_can_run_breakpoint_commands().
13874 Given absence of finer grained resetting, we get to do
13875 it all the time. */
13876 if (b->extra_string != NULL)
13877 update_dprintf_command_list (b);
13880 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13883 dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13885 fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string,
13887 print_recreate_thread (tp, fp);
13890 /* Implement the "after_condition_true" breakpoint_ops method for
13893 dprintf's are implemented with regular commands in their command
13894 list, but we run the commands here instead of before presenting the
13895 stop to the user, as dprintf's don't actually cause a stop. This
13896 also makes it so that the commands of multiple dprintfs at the same
13897 address are all handled. */
13900 dprintf_after_condition_true (struct bpstats *bs)
13902 struct cleanup *old_chain;
13903 struct bpstats tmp_bs = { NULL };
13904 struct bpstats *tmp_bs_p = &tmp_bs;
13906 /* dprintf's never cause a stop. This wasn't set in the
13907 check_status hook instead because that would make the dprintf's
13908 condition not be evaluated. */
13911 /* Run the command list here. Take ownership of it instead of
13912 copying. We never want these commands to run later in
13913 bpstat_do_actions, if a breakpoint that causes a stop happens to
13914 be set at same address as this dprintf, or even if running the
13915 commands here throws. */
13916 tmp_bs.commands = bs->commands;
13917 bs->commands = NULL;
13918 old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands);
13920 bpstat_do_actions_1 (&tmp_bs_p);
13922 /* 'tmp_bs.commands' will usually be NULL by now, but
13923 bpstat_do_actions_1 may return early without processing the whole
13925 do_cleanups (old_chain);
13928 /* The breakpoint_ops structure to be used on static tracepoints with
13932 strace_marker_create_sals_from_address (char **arg,
13933 struct linespec_result *canonical,
13934 enum bptype type_wanted,
13935 char *addr_start, char **copy_arg)
13937 struct linespec_sals lsal;
13939 lsal.sals = decode_static_tracepoint_spec (arg);
13941 *copy_arg = savestring (addr_start, *arg - addr_start);
13943 canonical->addr_string = xstrdup (*copy_arg);
13944 lsal.canonical = xstrdup (*copy_arg);
13945 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13949 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13950 struct linespec_result *canonical,
13952 char *extra_string,
13953 enum bptype type_wanted,
13954 enum bpdisp disposition,
13956 int task, int ignore_count,
13957 const struct breakpoint_ops *ops,
13958 int from_tty, int enabled,
13959 int internal, unsigned flags)
13962 struct linespec_sals *lsal = VEC_index (linespec_sals,
13963 canonical->sals, 0);
13965 /* If the user is creating a static tracepoint by marker id
13966 (strace -m MARKER_ID), then store the sals index, so that
13967 breakpoint_re_set can try to match up which of the newly
13968 found markers corresponds to this one, and, don't try to
13969 expand multiple locations for each sal, given than SALS
13970 already should contain all sals for MARKER_ID. */
13972 for (i = 0; i < lsal->sals.nelts; ++i)
13974 struct symtabs_and_lines expanded;
13975 struct tracepoint *tp;
13976 struct cleanup *old_chain;
13979 expanded.nelts = 1;
13980 expanded.sals = &lsal->sals.sals[i];
13982 addr_string = xstrdup (canonical->addr_string);
13983 old_chain = make_cleanup (xfree, addr_string);
13985 tp = XCNEW (struct tracepoint);
13986 init_breakpoint_sal (&tp->base, gdbarch, expanded,
13988 cond_string, extra_string,
13989 type_wanted, disposition,
13990 thread, task, ignore_count, ops,
13991 from_tty, enabled, internal, flags,
13992 canonical->special_display);
13993 /* Given that its possible to have multiple markers with
13994 the same string id, if the user is creating a static
13995 tracepoint by marker id ("strace -m MARKER_ID"), then
13996 store the sals index, so that breakpoint_re_set can
13997 try to match up which of the newly found markers
13998 corresponds to this one */
13999 tp->static_trace_marker_id_idx = i;
14001 install_breakpoint (internal, &tp->base, 0);
14003 discard_cleanups (old_chain);
14008 strace_marker_decode_linespec (struct breakpoint *b, char **s,
14009 struct symtabs_and_lines *sals)
14011 struct tracepoint *tp = (struct tracepoint *) b;
14013 *sals = decode_static_tracepoint_spec (s);
14014 if (sals->nelts > tp->static_trace_marker_id_idx)
14016 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
14020 error (_("marker %s not found"), tp->static_trace_marker_id);
14023 static struct breakpoint_ops strace_marker_breakpoint_ops;
14026 strace_marker_p (struct breakpoint *b)
14028 return b->ops == &strace_marker_breakpoint_ops;
14031 /* Delete a breakpoint and clean up all traces of it in the data
14035 delete_breakpoint (struct breakpoint *bpt)
14037 struct breakpoint *b;
14039 gdb_assert (bpt != NULL);
14041 /* Has this bp already been deleted? This can happen because
14042 multiple lists can hold pointers to bp's. bpstat lists are
14045 One example of this happening is a watchpoint's scope bp. When
14046 the scope bp triggers, we notice that the watchpoint is out of
14047 scope, and delete it. We also delete its scope bp. But the
14048 scope bp is marked "auto-deleting", and is already on a bpstat.
14049 That bpstat is then checked for auto-deleting bp's, which are
14052 A real solution to this problem might involve reference counts in
14053 bp's, and/or giving them pointers back to their referencing
14054 bpstat's, and teaching delete_breakpoint to only free a bp's
14055 storage when no more references were extent. A cheaper bandaid
14057 if (bpt->type == bp_none)
14060 /* At least avoid this stale reference until the reference counting
14061 of breakpoints gets resolved. */
14062 if (bpt->related_breakpoint != bpt)
14064 struct breakpoint *related;
14065 struct watchpoint *w;
14067 if (bpt->type == bp_watchpoint_scope)
14068 w = (struct watchpoint *) bpt->related_breakpoint;
14069 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
14070 w = (struct watchpoint *) bpt;
14074 watchpoint_del_at_next_stop (w);
14076 /* Unlink bpt from the bpt->related_breakpoint ring. */
14077 for (related = bpt; related->related_breakpoint != bpt;
14078 related = related->related_breakpoint);
14079 related->related_breakpoint = bpt->related_breakpoint;
14080 bpt->related_breakpoint = bpt;
14083 /* watch_command_1 creates a watchpoint but only sets its number if
14084 update_watchpoint succeeds in creating its bp_locations. If there's
14085 a problem in that process, we'll be asked to delete the half-created
14086 watchpoint. In that case, don't announce the deletion. */
14088 observer_notify_breakpoint_deleted (bpt);
14090 if (breakpoint_chain == bpt)
14091 breakpoint_chain = bpt->next;
14093 ALL_BREAKPOINTS (b)
14094 if (b->next == bpt)
14096 b->next = bpt->next;
14100 /* Be sure no bpstat's are pointing at the breakpoint after it's
14102 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
14103 in all threads for now. Note that we cannot just remove bpstats
14104 pointing at bpt from the stop_bpstat list entirely, as breakpoint
14105 commands are associated with the bpstat; if we remove it here,
14106 then the later call to bpstat_do_actions (&stop_bpstat); in
14107 event-top.c won't do anything, and temporary breakpoints with
14108 commands won't work. */
14110 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
14112 /* Now that breakpoint is removed from breakpoint list, update the
14113 global location list. This will remove locations that used to
14114 belong to this breakpoint. Do this before freeing the breakpoint
14115 itself, since remove_breakpoint looks at location's owner. It
14116 might be better design to have location completely
14117 self-contained, but it's not the case now. */
14118 update_global_location_list (UGLL_DONT_INSERT);
14120 bpt->ops->dtor (bpt);
14121 /* On the chance that someone will soon try again to delete this
14122 same bp, we mark it as deleted before freeing its storage. */
14123 bpt->type = bp_none;
14128 do_delete_breakpoint_cleanup (void *b)
14130 delete_breakpoint (b);
14134 make_cleanup_delete_breakpoint (struct breakpoint *b)
14136 return make_cleanup (do_delete_breakpoint_cleanup, b);
14139 /* Iterator function to call a user-provided callback function once
14140 for each of B and its related breakpoints. */
14143 iterate_over_related_breakpoints (struct breakpoint *b,
14144 void (*function) (struct breakpoint *,
14148 struct breakpoint *related;
14153 struct breakpoint *next;
14155 /* FUNCTION may delete RELATED. */
14156 next = related->related_breakpoint;
14158 if (next == related)
14160 /* RELATED is the last ring entry. */
14161 function (related, data);
14163 /* FUNCTION may have deleted it, so we'd never reach back to
14164 B. There's nothing left to do anyway, so just break
14169 function (related, data);
14173 while (related != b);
14177 do_delete_breakpoint (struct breakpoint *b, void *ignore)
14179 delete_breakpoint (b);
14182 /* A callback for map_breakpoint_numbers that calls
14183 delete_breakpoint. */
14186 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
14188 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
14192 delete_command (char *arg, int from_tty)
14194 struct breakpoint *b, *b_tmp;
14200 int breaks_to_delete = 0;
14202 /* Delete all breakpoints if no argument. Do not delete
14203 internal breakpoints, these have to be deleted with an
14204 explicit breakpoint number argument. */
14205 ALL_BREAKPOINTS (b)
14206 if (user_breakpoint_p (b))
14208 breaks_to_delete = 1;
14212 /* Ask user only if there are some breakpoints to delete. */
14214 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
14216 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14217 if (user_breakpoint_p (b))
14218 delete_breakpoint (b);
14222 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
14226 all_locations_are_pending (struct bp_location *loc)
14228 for (; loc; loc = loc->next)
14229 if (!loc->shlib_disabled
14230 && !loc->pspace->executing_startup)
14235 /* Subroutine of update_breakpoint_locations to simplify it.
14236 Return non-zero if multiple fns in list LOC have the same name.
14237 Null names are ignored. */
14240 ambiguous_names_p (struct bp_location *loc)
14242 struct bp_location *l;
14243 htab_t htab = htab_create_alloc (13, htab_hash_string,
14244 (int (*) (const void *,
14245 const void *)) streq,
14246 NULL, xcalloc, xfree);
14248 for (l = loc; l != NULL; l = l->next)
14251 const char *name = l->function_name;
14253 /* Allow for some names to be NULL, ignore them. */
14257 slot = (const char **) htab_find_slot (htab, (const void *) name,
14259 /* NOTE: We can assume slot != NULL here because xcalloc never
14263 htab_delete (htab);
14269 htab_delete (htab);
14273 /* When symbols change, it probably means the sources changed as well,
14274 and it might mean the static tracepoint markers are no longer at
14275 the same address or line numbers they used to be at last we
14276 checked. Losing your static tracepoints whenever you rebuild is
14277 undesirable. This function tries to resync/rematch gdb static
14278 tracepoints with the markers on the target, for static tracepoints
14279 that have not been set by marker id. Static tracepoint that have
14280 been set by marker id are reset by marker id in breakpoint_re_set.
14283 1) For a tracepoint set at a specific address, look for a marker at
14284 the old PC. If one is found there, assume to be the same marker.
14285 If the name / string id of the marker found is different from the
14286 previous known name, assume that means the user renamed the marker
14287 in the sources, and output a warning.
14289 2) For a tracepoint set at a given line number, look for a marker
14290 at the new address of the old line number. If one is found there,
14291 assume to be the same marker. If the name / string id of the
14292 marker found is different from the previous known name, assume that
14293 means the user renamed the marker in the sources, and output a
14296 3) If a marker is no longer found at the same address or line, it
14297 may mean the marker no longer exists. But it may also just mean
14298 the code changed a bit. Maybe the user added a few lines of code
14299 that made the marker move up or down (in line number terms). Ask
14300 the target for info about the marker with the string id as we knew
14301 it. If found, update line number and address in the matching
14302 static tracepoint. This will get confused if there's more than one
14303 marker with the same ID (possible in UST, although unadvised
14304 precisely because it confuses tools). */
14306 static struct symtab_and_line
14307 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
14309 struct tracepoint *tp = (struct tracepoint *) b;
14310 struct static_tracepoint_marker marker;
14315 find_line_pc (sal.symtab, sal.line, &pc);
14317 if (target_static_tracepoint_marker_at (pc, &marker))
14319 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
14320 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14322 tp->static_trace_marker_id, marker.str_id);
14324 xfree (tp->static_trace_marker_id);
14325 tp->static_trace_marker_id = xstrdup (marker.str_id);
14326 release_static_tracepoint_marker (&marker);
14331 /* Old marker wasn't found on target at lineno. Try looking it up
14333 if (!sal.explicit_pc
14335 && sal.symtab != NULL
14336 && tp->static_trace_marker_id != NULL)
14338 VEC(static_tracepoint_marker_p) *markers;
14341 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
14343 if (!VEC_empty(static_tracepoint_marker_p, markers))
14345 struct symtab_and_line sal2;
14346 struct symbol *sym;
14347 struct static_tracepoint_marker *tpmarker;
14348 struct ui_out *uiout = current_uiout;
14350 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
14352 xfree (tp->static_trace_marker_id);
14353 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
14355 warning (_("marker for static tracepoint %d (%s) not "
14356 "found at previous line number"),
14357 b->number, tp->static_trace_marker_id);
14361 sal2.pc = tpmarker->address;
14363 sal2 = find_pc_line (tpmarker->address, 0);
14364 sym = find_pc_sect_function (tpmarker->address, NULL);
14365 ui_out_text (uiout, "Now in ");
14368 ui_out_field_string (uiout, "func",
14369 SYMBOL_PRINT_NAME (sym));
14370 ui_out_text (uiout, " at ");
14372 ui_out_field_string (uiout, "file",
14373 symtab_to_filename_for_display (sal2.symtab));
14374 ui_out_text (uiout, ":");
14376 if (ui_out_is_mi_like_p (uiout))
14378 const char *fullname = symtab_to_fullname (sal2.symtab);
14380 ui_out_field_string (uiout, "fullname", fullname);
14383 ui_out_field_int (uiout, "line", sal2.line);
14384 ui_out_text (uiout, "\n");
14386 b->loc->line_number = sal2.line;
14387 b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
14389 xfree (b->addr_string);
14390 b->addr_string = xstrprintf ("%s:%d",
14391 symtab_to_filename_for_display (sal2.symtab),
14392 b->loc->line_number);
14394 /* Might be nice to check if function changed, and warn if
14397 release_static_tracepoint_marker (tpmarker);
14403 /* Returns 1 iff locations A and B are sufficiently same that
14404 we don't need to report breakpoint as changed. */
14407 locations_are_equal (struct bp_location *a, struct bp_location *b)
14411 if (a->address != b->address)
14414 if (a->shlib_disabled != b->shlib_disabled)
14417 if (a->enabled != b->enabled)
14424 if ((a == NULL) != (b == NULL))
14430 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14431 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14432 a ranged breakpoint. */
14435 update_breakpoint_locations (struct breakpoint *b,
14436 struct symtabs_and_lines sals,
14437 struct symtabs_and_lines sals_end)
14440 struct bp_location *existing_locations = b->loc;
14442 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
14444 /* Ranged breakpoints have only one start location and one end
14446 b->enable_state = bp_disabled;
14447 update_global_location_list (UGLL_MAY_INSERT);
14448 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14449 "multiple locations found\n"),
14454 /* If there's no new locations, and all existing locations are
14455 pending, don't do anything. This optimizes the common case where
14456 all locations are in the same shared library, that was unloaded.
14457 We'd like to retain the location, so that when the library is
14458 loaded again, we don't loose the enabled/disabled status of the
14459 individual locations. */
14460 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
14465 for (i = 0; i < sals.nelts; ++i)
14467 struct bp_location *new_loc;
14469 switch_to_program_space_and_thread (sals.sals[i].pspace);
14471 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
14473 /* Reparse conditions, they might contain references to the
14475 if (b->cond_string != NULL)
14478 volatile struct gdb_exception e;
14480 s = b->cond_string;
14481 TRY_CATCH (e, RETURN_MASK_ERROR)
14483 new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
14484 block_for_pc (sals.sals[i].pc),
14489 warning (_("failed to reevaluate condition "
14490 "for breakpoint %d: %s"),
14491 b->number, e.message);
14492 new_loc->enabled = 0;
14496 if (sals_end.nelts)
14498 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
14500 new_loc->length = end - sals.sals[0].pc + 1;
14504 /* Update locations of permanent breakpoints. */
14505 if (b->enable_state == bp_permanent)
14506 make_breakpoint_permanent (b);
14508 /* If possible, carry over 'disable' status from existing
14511 struct bp_location *e = existing_locations;
14512 /* If there are multiple breakpoints with the same function name,
14513 e.g. for inline functions, comparing function names won't work.
14514 Instead compare pc addresses; this is just a heuristic as things
14515 may have moved, but in practice it gives the correct answer
14516 often enough until a better solution is found. */
14517 int have_ambiguous_names = ambiguous_names_p (b->loc);
14519 for (; e; e = e->next)
14521 if (!e->enabled && e->function_name)
14523 struct bp_location *l = b->loc;
14524 if (have_ambiguous_names)
14526 for (; l; l = l->next)
14527 if (breakpoint_locations_match (e, l))
14535 for (; l; l = l->next)
14536 if (l->function_name
14537 && strcmp (e->function_name, l->function_name) == 0)
14547 if (!locations_are_equal (existing_locations, b->loc))
14548 observer_notify_breakpoint_modified (b);
14550 update_global_location_list (UGLL_MAY_INSERT);
14553 /* Find the SaL locations corresponding to the given ADDR_STRING.
14554 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14556 static struct symtabs_and_lines
14557 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
14560 struct symtabs_and_lines sals = {0};
14561 volatile struct gdb_exception e;
14563 gdb_assert (b->ops != NULL);
14566 TRY_CATCH (e, RETURN_MASK_ERROR)
14568 b->ops->decode_linespec (b, &s, &sals);
14572 int not_found_and_ok = 0;
14573 /* For pending breakpoints, it's expected that parsing will
14574 fail until the right shared library is loaded. User has
14575 already told to create pending breakpoints and don't need
14576 extra messages. If breakpoint is in bp_shlib_disabled
14577 state, then user already saw the message about that
14578 breakpoint being disabled, and don't want to see more
14580 if (e.error == NOT_FOUND_ERROR
14581 && (b->condition_not_parsed
14582 || (b->loc && b->loc->shlib_disabled)
14583 || (b->loc && b->loc->pspace->executing_startup)
14584 || b->enable_state == bp_disabled))
14585 not_found_and_ok = 1;
14587 if (!not_found_and_ok)
14589 /* We surely don't want to warn about the same breakpoint
14590 10 times. One solution, implemented here, is disable
14591 the breakpoint on error. Another solution would be to
14592 have separate 'warning emitted' flag. Since this
14593 happens only when a binary has changed, I don't know
14594 which approach is better. */
14595 b->enable_state = bp_disabled;
14596 throw_exception (e);
14600 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
14604 for (i = 0; i < sals.nelts; ++i)
14605 resolve_sal_pc (&sals.sals[i]);
14606 if (b->condition_not_parsed && s && s[0])
14608 char *cond_string, *extra_string;
14611 find_condition_and_thread (s, sals.sals[0].pc,
14612 &cond_string, &thread, &task,
14615 b->cond_string = cond_string;
14616 b->thread = thread;
14619 b->extra_string = extra_string;
14620 b->condition_not_parsed = 0;
14623 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
14624 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
14634 /* The default re_set method, for typical hardware or software
14635 breakpoints. Reevaluate the breakpoint and recreate its
14639 breakpoint_re_set_default (struct breakpoint *b)
14642 struct symtabs_and_lines sals, sals_end;
14643 struct symtabs_and_lines expanded = {0};
14644 struct symtabs_and_lines expanded_end = {0};
14646 sals = addr_string_to_sals (b, b->addr_string, &found);
14649 make_cleanup (xfree, sals.sals);
14653 if (b->addr_string_range_end)
14655 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
14658 make_cleanup (xfree, sals_end.sals);
14659 expanded_end = sals_end;
14663 update_breakpoint_locations (b, expanded, expanded_end);
14666 /* Default method for creating SALs from an address string. It basically
14667 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14670 create_sals_from_address_default (char **arg,
14671 struct linespec_result *canonical,
14672 enum bptype type_wanted,
14673 char *addr_start, char **copy_arg)
14675 parse_breakpoint_sals (arg, canonical);
14678 /* Call create_breakpoints_sal for the given arguments. This is the default
14679 function for the `create_breakpoints_sal' method of
14683 create_breakpoints_sal_default (struct gdbarch *gdbarch,
14684 struct linespec_result *canonical,
14686 char *extra_string,
14687 enum bptype type_wanted,
14688 enum bpdisp disposition,
14690 int task, int ignore_count,
14691 const struct breakpoint_ops *ops,
14692 int from_tty, int enabled,
14693 int internal, unsigned flags)
14695 create_breakpoints_sal (gdbarch, canonical, cond_string,
14697 type_wanted, disposition,
14698 thread, task, ignore_count, ops, from_tty,
14699 enabled, internal, flags);
14702 /* Decode the line represented by S by calling decode_line_full. This is the
14703 default function for the `decode_linespec' method of breakpoint_ops. */
14706 decode_linespec_default (struct breakpoint *b, char **s,
14707 struct symtabs_and_lines *sals)
14709 struct linespec_result canonical;
14711 init_linespec_result (&canonical);
14712 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
14713 (struct symtab *) NULL, 0,
14714 &canonical, multiple_symbols_all,
14717 /* We should get 0 or 1 resulting SALs. */
14718 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
14720 if (VEC_length (linespec_sals, canonical.sals) > 0)
14722 struct linespec_sals *lsal;
14724 lsal = VEC_index (linespec_sals, canonical.sals, 0);
14725 *sals = lsal->sals;
14726 /* Arrange it so the destructor does not free the
14728 lsal->sals.sals = NULL;
14731 destroy_linespec_result (&canonical);
14734 /* Prepare the global context for a re-set of breakpoint B. */
14736 static struct cleanup *
14737 prepare_re_set_context (struct breakpoint *b)
14739 struct cleanup *cleanups;
14741 input_radix = b->input_radix;
14742 cleanups = save_current_space_and_thread ();
14743 if (b->pspace != NULL)
14744 switch_to_program_space_and_thread (b->pspace);
14745 set_language (b->language);
14750 /* Reset a breakpoint given it's struct breakpoint * BINT.
14751 The value we return ends up being the return value from catch_errors.
14752 Unused in this case. */
14755 breakpoint_re_set_one (void *bint)
14757 /* Get past catch_errs. */
14758 struct breakpoint *b = (struct breakpoint *) bint;
14759 struct cleanup *cleanups;
14761 cleanups = prepare_re_set_context (b);
14762 b->ops->re_set (b);
14763 do_cleanups (cleanups);
14767 /* Re-set all breakpoints after symbols have been re-loaded. */
14769 breakpoint_re_set (void)
14771 struct breakpoint *b, *b_tmp;
14772 enum language save_language;
14773 int save_input_radix;
14774 struct cleanup *old_chain;
14776 save_language = current_language->la_language;
14777 save_input_radix = input_radix;
14778 old_chain = save_current_program_space ();
14780 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14782 /* Format possible error msg. */
14783 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
14785 struct cleanup *cleanups = make_cleanup (xfree, message);
14786 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
14787 do_cleanups (cleanups);
14789 set_language (save_language);
14790 input_radix = save_input_radix;
14792 jit_breakpoint_re_set ();
14794 do_cleanups (old_chain);
14796 create_overlay_event_breakpoint ();
14797 create_longjmp_master_breakpoint ();
14798 create_std_terminate_master_breakpoint ();
14799 create_exception_master_breakpoint ();
14802 /* Reset the thread number of this breakpoint:
14804 - If the breakpoint is for all threads, leave it as-is.
14805 - Else, reset it to the current thread for inferior_ptid. */
14807 breakpoint_re_set_thread (struct breakpoint *b)
14809 if (b->thread != -1)
14811 if (in_thread_list (inferior_ptid))
14812 b->thread = pid_to_thread_id (inferior_ptid);
14814 /* We're being called after following a fork. The new fork is
14815 selected as current, and unless this was a vfork will have a
14816 different program space from the original thread. Reset that
14818 b->loc->pspace = current_program_space;
14822 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14823 If from_tty is nonzero, it prints a message to that effect,
14824 which ends with a period (no newline). */
14827 set_ignore_count (int bptnum, int count, int from_tty)
14829 struct breakpoint *b;
14834 ALL_BREAKPOINTS (b)
14835 if (b->number == bptnum)
14837 if (is_tracepoint (b))
14839 if (from_tty && count != 0)
14840 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14845 b->ignore_count = count;
14849 printf_filtered (_("Will stop next time "
14850 "breakpoint %d is reached."),
14852 else if (count == 1)
14853 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14856 printf_filtered (_("Will ignore next %d "
14857 "crossings of breakpoint %d."),
14860 observer_notify_breakpoint_modified (b);
14864 error (_("No breakpoint number %d."), bptnum);
14867 /* Command to set ignore-count of breakpoint N to COUNT. */
14870 ignore_command (char *args, int from_tty)
14876 error_no_arg (_("a breakpoint number"));
14878 num = get_number (&p);
14880 error (_("bad breakpoint number: '%s'"), args);
14882 error (_("Second argument (specified ignore-count) is missing."));
14884 set_ignore_count (num,
14885 longest_to_int (value_as_long (parse_and_eval (p))),
14888 printf_filtered ("\n");
14891 /* Call FUNCTION on each of the breakpoints
14892 whose numbers are given in ARGS. */
14895 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
14900 struct breakpoint *b, *tmp;
14902 struct get_number_or_range_state state;
14905 error_no_arg (_("one or more breakpoint numbers"));
14907 init_number_or_range (&state, args);
14909 while (!state.finished)
14911 const char *p = state.string;
14915 num = get_number_or_range (&state);
14918 warning (_("bad breakpoint number at or near '%s'"), p);
14922 ALL_BREAKPOINTS_SAFE (b, tmp)
14923 if (b->number == num)
14926 function (b, data);
14930 printf_unfiltered (_("No breakpoint number %d.\n"), num);
14935 static struct bp_location *
14936 find_location_by_number (char *number)
14938 char *dot = strchr (number, '.');
14942 struct breakpoint *b;
14943 struct bp_location *loc;
14948 bp_num = get_number (&p1);
14950 error (_("Bad breakpoint number '%s'"), number);
14952 ALL_BREAKPOINTS (b)
14953 if (b->number == bp_num)
14958 if (!b || b->number != bp_num)
14959 error (_("Bad breakpoint number '%s'"), number);
14962 loc_num = get_number (&p1);
14964 error (_("Bad breakpoint location number '%s'"), number);
14968 for (;loc_num && loc; --loc_num, loc = loc->next)
14971 error (_("Bad breakpoint location number '%s'"), dot+1);
14977 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14978 If from_tty is nonzero, it prints a message to that effect,
14979 which ends with a period (no newline). */
14982 disable_breakpoint (struct breakpoint *bpt)
14984 /* Never disable a watchpoint scope breakpoint; we want to
14985 hit them when we leave scope so we can delete both the
14986 watchpoint and its scope breakpoint at that time. */
14987 if (bpt->type == bp_watchpoint_scope)
14990 /* You can't disable permanent breakpoints. */
14991 if (bpt->enable_state == bp_permanent)
14994 bpt->enable_state = bp_disabled;
14996 /* Mark breakpoint locations modified. */
14997 mark_breakpoint_modified (bpt);
14999 if (target_supports_enable_disable_tracepoint ()
15000 && current_trace_status ()->running && is_tracepoint (bpt))
15002 struct bp_location *location;
15004 for (location = bpt->loc; location; location = location->next)
15005 target_disable_tracepoint (location);
15008 update_global_location_list (UGLL_DONT_INSERT);
15010 observer_notify_breakpoint_modified (bpt);
15013 /* A callback for iterate_over_related_breakpoints. */
15016 do_disable_breakpoint (struct breakpoint *b, void *ignore)
15018 disable_breakpoint (b);
15021 /* A callback for map_breakpoint_numbers that calls
15022 disable_breakpoint. */
15025 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
15027 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
15031 disable_command (char *args, int from_tty)
15035 struct breakpoint *bpt;
15037 ALL_BREAKPOINTS (bpt)
15038 if (user_breakpoint_p (bpt))
15039 disable_breakpoint (bpt);
15043 char *num = extract_arg (&args);
15047 if (strchr (num, '.'))
15049 struct bp_location *loc = find_location_by_number (num);
15056 mark_breakpoint_location_modified (loc);
15058 if (target_supports_enable_disable_tracepoint ()
15059 && current_trace_status ()->running && loc->owner
15060 && is_tracepoint (loc->owner))
15061 target_disable_tracepoint (loc);
15063 update_global_location_list (UGLL_DONT_INSERT);
15066 map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL);
15067 num = extract_arg (&args);
15073 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
15076 int target_resources_ok;
15078 if (bpt->type == bp_hardware_breakpoint)
15081 i = hw_breakpoint_used_count ();
15082 target_resources_ok =
15083 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
15085 if (target_resources_ok == 0)
15086 error (_("No hardware breakpoint support in the target."));
15087 else if (target_resources_ok < 0)
15088 error (_("Hardware breakpoints used exceeds limit."));
15091 if (is_watchpoint (bpt))
15093 /* Initialize it just to avoid a GCC false warning. */
15094 enum enable_state orig_enable_state = 0;
15095 volatile struct gdb_exception e;
15097 TRY_CATCH (e, RETURN_MASK_ALL)
15099 struct watchpoint *w = (struct watchpoint *) bpt;
15101 orig_enable_state = bpt->enable_state;
15102 bpt->enable_state = bp_enabled;
15103 update_watchpoint (w, 1 /* reparse */);
15107 bpt->enable_state = orig_enable_state;
15108 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
15114 if (bpt->enable_state != bp_permanent)
15115 bpt->enable_state = bp_enabled;
15117 bpt->enable_state = bp_enabled;
15119 /* Mark breakpoint locations modified. */
15120 mark_breakpoint_modified (bpt);
15122 if (target_supports_enable_disable_tracepoint ()
15123 && current_trace_status ()->running && is_tracepoint (bpt))
15125 struct bp_location *location;
15127 for (location = bpt->loc; location; location = location->next)
15128 target_enable_tracepoint (location);
15131 bpt->disposition = disposition;
15132 bpt->enable_count = count;
15133 update_global_location_list (UGLL_MAY_INSERT);
15135 observer_notify_breakpoint_modified (bpt);
15140 enable_breakpoint (struct breakpoint *bpt)
15142 enable_breakpoint_disp (bpt, bpt->disposition, 0);
15146 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
15148 enable_breakpoint (bpt);
15151 /* A callback for map_breakpoint_numbers that calls
15152 enable_breakpoint. */
15155 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
15157 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
15160 /* The enable command enables the specified breakpoints (or all defined
15161 breakpoints) so they once again become (or continue to be) effective
15162 in stopping the inferior. */
15165 enable_command (char *args, int from_tty)
15169 struct breakpoint *bpt;
15171 ALL_BREAKPOINTS (bpt)
15172 if (user_breakpoint_p (bpt))
15173 enable_breakpoint (bpt);
15177 char *num = extract_arg (&args);
15181 if (strchr (num, '.'))
15183 struct bp_location *loc = find_location_by_number (num);
15190 mark_breakpoint_location_modified (loc);
15192 if (target_supports_enable_disable_tracepoint ()
15193 && current_trace_status ()->running && loc->owner
15194 && is_tracepoint (loc->owner))
15195 target_enable_tracepoint (loc);
15197 update_global_location_list (UGLL_MAY_INSERT);
15200 map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL);
15201 num = extract_arg (&args);
15206 /* This struct packages up disposition data for application to multiple
15216 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
15218 struct disp_data disp_data = *(struct disp_data *) arg;
15220 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
15224 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
15226 struct disp_data disp = { disp_disable, 1 };
15228 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15232 enable_once_command (char *args, int from_tty)
15234 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
15238 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
15240 struct disp_data disp = { disp_disable, *(int *) countptr };
15242 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15246 enable_count_command (char *args, int from_tty)
15248 int count = get_number (&args);
15250 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
15254 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
15256 struct disp_data disp = { disp_del, 1 };
15258 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
15262 enable_delete_command (char *args, int from_tty)
15264 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
15268 set_breakpoint_cmd (char *args, int from_tty)
15273 show_breakpoint_cmd (char *args, int from_tty)
15277 /* Invalidate last known value of any hardware watchpoint if
15278 the memory which that value represents has been written to by
15282 invalidate_bp_value_on_memory_change (struct inferior *inferior,
15283 CORE_ADDR addr, ssize_t len,
15284 const bfd_byte *data)
15286 struct breakpoint *bp;
15288 ALL_BREAKPOINTS (bp)
15289 if (bp->enable_state == bp_enabled
15290 && bp->type == bp_hardware_watchpoint)
15292 struct watchpoint *wp = (struct watchpoint *) bp;
15294 if (wp->val_valid && wp->val)
15296 struct bp_location *loc;
15298 for (loc = bp->loc; loc != NULL; loc = loc->next)
15299 if (loc->loc_type == bp_loc_hardware_watchpoint
15300 && loc->address + loc->length > addr
15301 && addr + len > loc->address)
15303 value_free (wp->val);
15311 /* Create and insert a raw software breakpoint at PC. Return an
15312 identifier, which should be used to remove the breakpoint later.
15313 In general, places which call this should be using something on the
15314 breakpoint chain instead; this function should be eliminated
15318 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
15319 struct address_space *aspace, CORE_ADDR pc)
15321 struct bp_target_info *bp_tgt;
15322 struct bp_location *bl;
15324 bp_tgt = XCNEW (struct bp_target_info);
15326 bp_tgt->placed_address_space = aspace;
15327 bp_tgt->placed_address = pc;
15329 /* If an unconditional non-raw breakpoint is already inserted at
15330 that location, there's no need to insert another. However, with
15331 target-side evaluation of breakpoint conditions, if the
15332 breakpoint that is currently inserted on the target is
15333 conditional, we need to make it unconditional. Note that a
15334 breakpoint with target-side commands is not reported even if
15335 unconditional, so we need to remove the commands from the target
15337 bl = find_non_raw_software_breakpoint_inserted_here (aspace, pc);
15339 && VEC_empty (agent_expr_p, bl->target_info.conditions)
15340 && VEC_empty (agent_expr_p, bl->target_info.tcommands))
15342 bp_target_info_copy_insertion_state (bp_tgt, &bl->target_info);
15346 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
15348 /* Could not insert the breakpoint. */
15356 /* Remove a breakpoint BP inserted by
15357 deprecated_insert_raw_breakpoint. */
15360 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
15362 struct bp_target_info *bp_tgt = bp;
15363 struct address_space *aspace = bp_tgt->placed_address_space;
15364 CORE_ADDR address = bp_tgt->placed_address;
15365 struct bp_location *bl;
15368 bl = find_non_raw_software_breakpoint_inserted_here (aspace, address);
15370 /* Only remove the raw breakpoint if there are no other non-raw
15371 breakpoints still inserted at this location. Otherwise, we would
15372 be effectively disabling those breakpoints. */
15374 ret = target_remove_breakpoint (gdbarch, bp_tgt);
15375 else if (!VEC_empty (agent_expr_p, bl->target_info.conditions)
15376 || !VEC_empty (agent_expr_p, bl->target_info.tcommands))
15378 /* The target is evaluating conditions, and when we inserted the
15379 software single-step breakpoint, we had made the breakpoint
15380 unconditional and command-less on the target side. Reinsert
15381 to restore the conditions/commands. */
15382 ret = target_insert_breakpoint (bl->gdbarch, &bl->target_info);
15392 /* Create and insert a breakpoint for software single step. */
15395 insert_single_step_breakpoint (struct gdbarch *gdbarch,
15396 struct address_space *aspace,
15401 if (single_step_breakpoints[0] == NULL)
15403 bpt_p = &single_step_breakpoints[0];
15404 single_step_gdbarch[0] = gdbarch;
15408 gdb_assert (single_step_breakpoints[1] == NULL);
15409 bpt_p = &single_step_breakpoints[1];
15410 single_step_gdbarch[1] = gdbarch;
15413 /* NOTE drow/2006-04-11: A future improvement to this function would
15414 be to only create the breakpoints once, and actually put them on
15415 the breakpoint chain. That would let us use set_raw_breakpoint.
15416 We could adjust the addresses each time they were needed. Doing
15417 this requires corresponding changes elsewhere where single step
15418 breakpoints are handled, however. So, for now, we use this. */
15420 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
15421 if (*bpt_p == NULL)
15422 error (_("Could not insert single-step breakpoint at %s"),
15423 paddress (gdbarch, next_pc));
15426 /* Check if the breakpoints used for software single stepping
15427 were inserted or not. */
15430 single_step_breakpoints_inserted (void)
15432 return (single_step_breakpoints[0] != NULL
15433 || single_step_breakpoints[1] != NULL);
15436 /* Remove and delete any breakpoints used for software single step. */
15439 remove_single_step_breakpoints (void)
15441 gdb_assert (single_step_breakpoints[0] != NULL);
15443 /* See insert_single_step_breakpoint for more about this deprecated
15445 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
15446 single_step_breakpoints[0]);
15447 single_step_gdbarch[0] = NULL;
15448 single_step_breakpoints[0] = NULL;
15450 if (single_step_breakpoints[1] != NULL)
15452 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
15453 single_step_breakpoints[1]);
15454 single_step_gdbarch[1] = NULL;
15455 single_step_breakpoints[1] = NULL;
15459 /* Delete software single step breakpoints without removing them from
15460 the inferior. This is intended to be used if the inferior's address
15461 space where they were inserted is already gone, e.g. after exit or
15465 cancel_single_step_breakpoints (void)
15469 for (i = 0; i < 2; i++)
15470 if (single_step_breakpoints[i])
15472 xfree (single_step_breakpoints[i]);
15473 single_step_breakpoints[i] = NULL;
15474 single_step_gdbarch[i] = NULL;
15478 /* Detach software single-step breakpoints from INFERIOR_PTID without
15482 detach_single_step_breakpoints (void)
15486 for (i = 0; i < 2; i++)
15487 if (single_step_breakpoints[i])
15488 target_remove_breakpoint (single_step_gdbarch[i],
15489 single_step_breakpoints[i]);
15492 /* Find the software single-step breakpoint that inserted at PC.
15493 Returns its slot if found, and -1 if not found. */
15496 find_single_step_breakpoint (struct address_space *aspace,
15501 for (i = 0; i < 2; i++)
15503 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
15505 && breakpoint_address_match (bp_tgt->placed_address_space,
15506 bp_tgt->placed_address,
15514 /* Check whether a software single-step breakpoint is inserted at
15518 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
15521 return find_single_step_breakpoint (aspace, pc) >= 0;
15524 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
15525 non-zero otherwise. */
15527 is_syscall_catchpoint_enabled (struct breakpoint *bp)
15529 if (syscall_catchpoint_p (bp)
15530 && bp->enable_state != bp_disabled
15531 && bp->enable_state != bp_call_disabled)
15538 catch_syscall_enabled (void)
15540 struct catch_syscall_inferior_data *inf_data
15541 = get_catch_syscall_inferior_data (current_inferior ());
15543 return inf_data->total_syscalls_count != 0;
15547 catching_syscall_number (int syscall_number)
15549 struct breakpoint *bp;
15551 ALL_BREAKPOINTS (bp)
15552 if (is_syscall_catchpoint_enabled (bp))
15554 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
15556 if (c->syscalls_to_be_caught)
15560 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
15562 if (syscall_number == iter)
15572 /* Complete syscall names. Used by "catch syscall". */
15573 static VEC (char_ptr) *
15574 catch_syscall_completer (struct cmd_list_element *cmd,
15575 const char *text, const char *word)
15577 const char **list = get_syscall_names ();
15578 VEC (char_ptr) *retlist
15579 = (list == NULL) ? NULL : complete_on_enum (list, word, word);
15585 /* Tracepoint-specific operations. */
15587 /* Set tracepoint count to NUM. */
15589 set_tracepoint_count (int num)
15591 tracepoint_count = num;
15592 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
15596 trace_command (char *arg, int from_tty)
15598 struct breakpoint_ops *ops;
15599 const char *arg_cp = arg;
15601 if (arg && probe_linespec_to_ops (&arg_cp))
15602 ops = &tracepoint_probe_breakpoint_ops;
15604 ops = &tracepoint_breakpoint_ops;
15606 create_breakpoint (get_current_arch (),
15608 NULL, 0, NULL, 1 /* parse arg */,
15610 bp_tracepoint /* type_wanted */,
15611 0 /* Ignore count */,
15612 pending_break_support,
15616 0 /* internal */, 0);
15620 ftrace_command (char *arg, int from_tty)
15622 create_breakpoint (get_current_arch (),
15624 NULL, 0, NULL, 1 /* parse arg */,
15626 bp_fast_tracepoint /* type_wanted */,
15627 0 /* Ignore count */,
15628 pending_break_support,
15629 &tracepoint_breakpoint_ops,
15632 0 /* internal */, 0);
15635 /* strace command implementation. Creates a static tracepoint. */
15638 strace_command (char *arg, int from_tty)
15640 struct breakpoint_ops *ops;
15642 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15643 or with a normal static tracepoint. */
15644 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
15645 ops = &strace_marker_breakpoint_ops;
15647 ops = &tracepoint_breakpoint_ops;
15649 create_breakpoint (get_current_arch (),
15651 NULL, 0, NULL, 1 /* parse arg */,
15653 bp_static_tracepoint /* type_wanted */,
15654 0 /* Ignore count */,
15655 pending_break_support,
15659 0 /* internal */, 0);
15662 /* Set up a fake reader function that gets command lines from a linked
15663 list that was acquired during tracepoint uploading. */
15665 static struct uploaded_tp *this_utp;
15666 static int next_cmd;
15669 read_uploaded_action (void)
15673 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
15680 /* Given information about a tracepoint as recorded on a target (which
15681 can be either a live system or a trace file), attempt to create an
15682 equivalent GDB tracepoint. This is not a reliable process, since
15683 the target does not necessarily have all the information used when
15684 the tracepoint was originally defined. */
15686 struct tracepoint *
15687 create_tracepoint_from_upload (struct uploaded_tp *utp)
15689 char *addr_str, small_buf[100];
15690 struct tracepoint *tp;
15692 if (utp->at_string)
15693 addr_str = utp->at_string;
15696 /* In the absence of a source location, fall back to raw
15697 address. Since there is no way to confirm that the address
15698 means the same thing as when the trace was started, warn the
15700 warning (_("Uploaded tracepoint %d has no "
15701 "source location, using raw address"),
15703 xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
15704 addr_str = small_buf;
15707 /* There's not much we can do with a sequence of bytecodes. */
15708 if (utp->cond && !utp->cond_string)
15709 warning (_("Uploaded tracepoint %d condition "
15710 "has no source form, ignoring it"),
15713 if (!create_breakpoint (get_current_arch (),
15715 utp->cond_string, -1, NULL,
15716 0 /* parse cond/thread */,
15718 utp->type /* type_wanted */,
15719 0 /* Ignore count */,
15720 pending_break_support,
15721 &tracepoint_breakpoint_ops,
15723 utp->enabled /* enabled */,
15725 CREATE_BREAKPOINT_FLAGS_INSERTED))
15728 /* Get the tracepoint we just created. */
15729 tp = get_tracepoint (tracepoint_count);
15730 gdb_assert (tp != NULL);
15734 xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
15737 trace_pass_command (small_buf, 0);
15740 /* If we have uploaded versions of the original commands, set up a
15741 special-purpose "reader" function and call the usual command line
15742 reader, then pass the result to the breakpoint command-setting
15744 if (!VEC_empty (char_ptr, utp->cmd_strings))
15746 struct command_line *cmd_list;
15751 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
15753 breakpoint_set_commands (&tp->base, cmd_list);
15755 else if (!VEC_empty (char_ptr, utp->actions)
15756 || !VEC_empty (char_ptr, utp->step_actions))
15757 warning (_("Uploaded tracepoint %d actions "
15758 "have no source form, ignoring them"),
15761 /* Copy any status information that might be available. */
15762 tp->base.hit_count = utp->hit_count;
15763 tp->traceframe_usage = utp->traceframe_usage;
15768 /* Print information on tracepoint number TPNUM_EXP, or all if
15772 tracepoints_info (char *args, int from_tty)
15774 struct ui_out *uiout = current_uiout;
15777 num_printed = breakpoint_1 (args, 0, is_tracepoint);
15779 if (num_printed == 0)
15781 if (args == NULL || *args == '\0')
15782 ui_out_message (uiout, 0, "No tracepoints.\n");
15784 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
15787 default_collect_info ();
15790 /* The 'enable trace' command enables tracepoints.
15791 Not supported by all targets. */
15793 enable_trace_command (char *args, int from_tty)
15795 enable_command (args, from_tty);
15798 /* The 'disable trace' command disables tracepoints.
15799 Not supported by all targets. */
15801 disable_trace_command (char *args, int from_tty)
15803 disable_command (args, from_tty);
15806 /* Remove a tracepoint (or all if no argument). */
15808 delete_trace_command (char *arg, int from_tty)
15810 struct breakpoint *b, *b_tmp;
15816 int breaks_to_delete = 0;
15818 /* Delete all breakpoints if no argument.
15819 Do not delete internal or call-dummy breakpoints, these
15820 have to be deleted with an explicit breakpoint number
15822 ALL_TRACEPOINTS (b)
15823 if (is_tracepoint (b) && user_breakpoint_p (b))
15825 breaks_to_delete = 1;
15829 /* Ask user only if there are some breakpoints to delete. */
15831 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
15833 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15834 if (is_tracepoint (b) && user_breakpoint_p (b))
15835 delete_breakpoint (b);
15839 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
15842 /* Helper function for trace_pass_command. */
15845 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
15847 tp->pass_count = count;
15848 observer_notify_breakpoint_modified (&tp->base);
15850 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15851 tp->base.number, count);
15854 /* Set passcount for tracepoint.
15856 First command argument is passcount, second is tracepoint number.
15857 If tracepoint number omitted, apply to most recently defined.
15858 Also accepts special argument "all". */
15861 trace_pass_command (char *args, int from_tty)
15863 struct tracepoint *t1;
15864 unsigned int count;
15866 if (args == 0 || *args == 0)
15867 error (_("passcount command requires an "
15868 "argument (count + optional TP num)"));
15870 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
15872 args = skip_spaces (args);
15873 if (*args && strncasecmp (args, "all", 3) == 0)
15875 struct breakpoint *b;
15877 args += 3; /* Skip special argument "all". */
15879 error (_("Junk at end of arguments."));
15881 ALL_TRACEPOINTS (b)
15883 t1 = (struct tracepoint *) b;
15884 trace_pass_set_count (t1, count, from_tty);
15887 else if (*args == '\0')
15889 t1 = get_tracepoint_by_number (&args, NULL);
15891 trace_pass_set_count (t1, count, from_tty);
15895 struct get_number_or_range_state state;
15897 init_number_or_range (&state, args);
15898 while (!state.finished)
15900 t1 = get_tracepoint_by_number (&args, &state);
15902 trace_pass_set_count (t1, count, from_tty);
15907 struct tracepoint *
15908 get_tracepoint (int num)
15910 struct breakpoint *t;
15912 ALL_TRACEPOINTS (t)
15913 if (t->number == num)
15914 return (struct tracepoint *) t;
15919 /* Find the tracepoint with the given target-side number (which may be
15920 different from the tracepoint number after disconnecting and
15923 struct tracepoint *
15924 get_tracepoint_by_number_on_target (int num)
15926 struct breakpoint *b;
15928 ALL_TRACEPOINTS (b)
15930 struct tracepoint *t = (struct tracepoint *) b;
15932 if (t->number_on_target == num)
15939 /* Utility: parse a tracepoint number and look it up in the list.
15940 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15941 If the argument is missing, the most recent tracepoint
15942 (tracepoint_count) is returned. */
15944 struct tracepoint *
15945 get_tracepoint_by_number (char **arg,
15946 struct get_number_or_range_state *state)
15948 struct breakpoint *t;
15950 char *instring = arg == NULL ? NULL : *arg;
15954 gdb_assert (!state->finished);
15955 tpnum = get_number_or_range (state);
15957 else if (arg == NULL || *arg == NULL || ! **arg)
15958 tpnum = tracepoint_count;
15960 tpnum = get_number (arg);
15964 if (instring && *instring)
15965 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15968 printf_filtered (_("No previous tracepoint\n"));
15972 ALL_TRACEPOINTS (t)
15973 if (t->number == tpnum)
15975 return (struct tracepoint *) t;
15978 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
15983 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
15985 if (b->thread != -1)
15986 fprintf_unfiltered (fp, " thread %d", b->thread);
15989 fprintf_unfiltered (fp, " task %d", b->task);
15991 fprintf_unfiltered (fp, "\n");
15994 /* Save information on user settable breakpoints (watchpoints, etc) to
15995 a new script file named FILENAME. If FILTER is non-NULL, call it
15996 on each breakpoint and only include the ones for which it returns
16000 save_breakpoints (char *filename, int from_tty,
16001 int (*filter) (const struct breakpoint *))
16003 struct breakpoint *tp;
16005 struct cleanup *cleanup;
16006 struct ui_file *fp;
16007 int extra_trace_bits = 0;
16009 if (filename == 0 || *filename == 0)
16010 error (_("Argument required (file name in which to save)"));
16012 /* See if we have anything to save. */
16013 ALL_BREAKPOINTS (tp)
16015 /* Skip internal and momentary breakpoints. */
16016 if (!user_breakpoint_p (tp))
16019 /* If we have a filter, only save the breakpoints it accepts. */
16020 if (filter && !filter (tp))
16025 if (is_tracepoint (tp))
16027 extra_trace_bits = 1;
16029 /* We can stop searching. */
16036 warning (_("Nothing to save."));
16040 filename = tilde_expand (filename);
16041 cleanup = make_cleanup (xfree, filename);
16042 fp = gdb_fopen (filename, "w");
16044 error (_("Unable to open file '%s' for saving (%s)"),
16045 filename, safe_strerror (errno));
16046 make_cleanup_ui_file_delete (fp);
16048 if (extra_trace_bits)
16049 save_trace_state_variables (fp);
16051 ALL_BREAKPOINTS (tp)
16053 /* Skip internal and momentary breakpoints. */
16054 if (!user_breakpoint_p (tp))
16057 /* If we have a filter, only save the breakpoints it accepts. */
16058 if (filter && !filter (tp))
16061 tp->ops->print_recreate (tp, fp);
16063 /* Note, we can't rely on tp->number for anything, as we can't
16064 assume the recreated breakpoint numbers will match. Use $bpnum
16067 if (tp->cond_string)
16068 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
16070 if (tp->ignore_count)
16071 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
16073 if (tp->type != bp_dprintf && tp->commands)
16075 volatile struct gdb_exception ex;
16077 fprintf_unfiltered (fp, " commands\n");
16079 ui_out_redirect (current_uiout, fp);
16080 TRY_CATCH (ex, RETURN_MASK_ALL)
16082 print_command_lines (current_uiout, tp->commands->commands, 2);
16084 ui_out_redirect (current_uiout, NULL);
16087 throw_exception (ex);
16089 fprintf_unfiltered (fp, " end\n");
16092 if (tp->enable_state == bp_disabled)
16093 fprintf_unfiltered (fp, "disable\n");
16095 /* If this is a multi-location breakpoint, check if the locations
16096 should be individually disabled. Watchpoint locations are
16097 special, and not user visible. */
16098 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
16100 struct bp_location *loc;
16103 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
16105 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
16109 if (extra_trace_bits && *default_collect)
16110 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
16113 printf_filtered (_("Saved to file '%s'.\n"), filename);
16114 do_cleanups (cleanup);
16117 /* The `save breakpoints' command. */
16120 save_breakpoints_command (char *args, int from_tty)
16122 save_breakpoints (args, from_tty, NULL);
16125 /* The `save tracepoints' command. */
16128 save_tracepoints_command (char *args, int from_tty)
16130 save_breakpoints (args, from_tty, is_tracepoint);
16133 /* Create a vector of all tracepoints. */
16135 VEC(breakpoint_p) *
16136 all_tracepoints (void)
16138 VEC(breakpoint_p) *tp_vec = 0;
16139 struct breakpoint *tp;
16141 ALL_TRACEPOINTS (tp)
16143 VEC_safe_push (breakpoint_p, tp_vec, tp);
16150 /* This help string is used for the break, hbreak, tbreak and thbreak
16151 commands. It is defined as a macro to prevent duplication.
16152 COMMAND should be a string constant containing the name of the
16154 #define BREAK_ARGS_HELP(command) \
16155 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
16156 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
16157 probe point. Accepted values are `-probe' (for a generic, automatically\n\
16158 guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
16159 LOCATION may be a line number, function name, or \"*\" and an address.\n\
16160 If a line number is specified, break at start of code for that line.\n\
16161 If a function is specified, break at start of code for that function.\n\
16162 If an address is specified, break at that exact address.\n\
16163 With no LOCATION, uses current execution address of the selected\n\
16164 stack frame. This is useful for breaking on return to a stack frame.\n\
16166 THREADNUM is the number from \"info threads\".\n\
16167 CONDITION is a boolean expression.\n\
16169 Multiple breakpoints at one place are permitted, and useful if their\n\
16170 conditions are different.\n\
16172 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
16174 /* List of subcommands for "catch". */
16175 static struct cmd_list_element *catch_cmdlist;
16177 /* List of subcommands for "tcatch". */
16178 static struct cmd_list_element *tcatch_cmdlist;
16181 add_catch_command (char *name, char *docstring,
16182 cmd_sfunc_ftype *sfunc,
16183 completer_ftype *completer,
16184 void *user_data_catch,
16185 void *user_data_tcatch)
16187 struct cmd_list_element *command;
16189 command = add_cmd (name, class_breakpoint, NULL, docstring,
16191 set_cmd_sfunc (command, sfunc);
16192 set_cmd_context (command, user_data_catch);
16193 set_cmd_completer (command, completer);
16195 command = add_cmd (name, class_breakpoint, NULL, docstring,
16197 set_cmd_sfunc (command, sfunc);
16198 set_cmd_context (command, user_data_tcatch);
16199 set_cmd_completer (command, completer);
16203 clear_syscall_counts (struct inferior *inf)
16205 struct catch_syscall_inferior_data *inf_data
16206 = get_catch_syscall_inferior_data (inf);
16208 inf_data->total_syscalls_count = 0;
16209 inf_data->any_syscall_count = 0;
16210 VEC_free (int, inf_data->syscalls_counts);
16214 save_command (char *arg, int from_tty)
16216 printf_unfiltered (_("\"save\" must be followed by "
16217 "the name of a save subcommand.\n"));
16218 help_list (save_cmdlist, "save ", all_commands, gdb_stdout);
16221 struct breakpoint *
16222 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
16225 struct breakpoint *b, *b_tmp;
16227 ALL_BREAKPOINTS_SAFE (b, b_tmp)
16229 if ((*callback) (b, data))
16236 /* Zero if any of the breakpoint's locations could be a location where
16237 functions have been inlined, nonzero otherwise. */
16240 is_non_inline_function (struct breakpoint *b)
16242 /* The shared library event breakpoint is set on the address of a
16243 non-inline function. */
16244 if (b->type == bp_shlib_event)
16250 /* Nonzero if the specified PC cannot be a location where functions
16251 have been inlined. */
16254 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
16255 const struct target_waitstatus *ws)
16257 struct breakpoint *b;
16258 struct bp_location *bl;
16260 ALL_BREAKPOINTS (b)
16262 if (!is_non_inline_function (b))
16265 for (bl = b->loc; bl != NULL; bl = bl->next)
16267 if (!bl->shlib_disabled
16268 && bpstat_check_location (bl, aspace, pc, ws))
16276 /* Remove any references to OBJFILE which is going to be freed. */
16279 breakpoint_free_objfile (struct objfile *objfile)
16281 struct bp_location **locp, *loc;
16283 ALL_BP_LOCATIONS (loc, locp)
16284 if (loc->symtab != NULL && loc->symtab->objfile == objfile)
16285 loc->symtab = NULL;
16289 initialize_breakpoint_ops (void)
16291 static int initialized = 0;
16293 struct breakpoint_ops *ops;
16299 /* The breakpoint_ops structure to be inherit by all kinds of
16300 breakpoints (real breakpoints, i.e., user "break" breakpoints,
16301 internal and momentary breakpoints, etc.). */
16302 ops = &bkpt_base_breakpoint_ops;
16303 *ops = base_breakpoint_ops;
16304 ops->re_set = bkpt_re_set;
16305 ops->insert_location = bkpt_insert_location;
16306 ops->remove_location = bkpt_remove_location;
16307 ops->breakpoint_hit = bkpt_breakpoint_hit;
16308 ops->create_sals_from_address = bkpt_create_sals_from_address;
16309 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
16310 ops->decode_linespec = bkpt_decode_linespec;
16312 /* The breakpoint_ops structure to be used in regular breakpoints. */
16313 ops = &bkpt_breakpoint_ops;
16314 *ops = bkpt_base_breakpoint_ops;
16315 ops->re_set = bkpt_re_set;
16316 ops->resources_needed = bkpt_resources_needed;
16317 ops->print_it = bkpt_print_it;
16318 ops->print_mention = bkpt_print_mention;
16319 ops->print_recreate = bkpt_print_recreate;
16321 /* Ranged breakpoints. */
16322 ops = &ranged_breakpoint_ops;
16323 *ops = bkpt_breakpoint_ops;
16324 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
16325 ops->resources_needed = resources_needed_ranged_breakpoint;
16326 ops->print_it = print_it_ranged_breakpoint;
16327 ops->print_one = print_one_ranged_breakpoint;
16328 ops->print_one_detail = print_one_detail_ranged_breakpoint;
16329 ops->print_mention = print_mention_ranged_breakpoint;
16330 ops->print_recreate = print_recreate_ranged_breakpoint;
16332 /* Internal breakpoints. */
16333 ops = &internal_breakpoint_ops;
16334 *ops = bkpt_base_breakpoint_ops;
16335 ops->re_set = internal_bkpt_re_set;
16336 ops->check_status = internal_bkpt_check_status;
16337 ops->print_it = internal_bkpt_print_it;
16338 ops->print_mention = internal_bkpt_print_mention;
16340 /* Momentary breakpoints. */
16341 ops = &momentary_breakpoint_ops;
16342 *ops = bkpt_base_breakpoint_ops;
16343 ops->re_set = momentary_bkpt_re_set;
16344 ops->check_status = momentary_bkpt_check_status;
16345 ops->print_it = momentary_bkpt_print_it;
16346 ops->print_mention = momentary_bkpt_print_mention;
16348 /* Momentary breakpoints for bp_longjmp and bp_exception. */
16349 ops = &longjmp_breakpoint_ops;
16350 *ops = momentary_breakpoint_ops;
16351 ops->dtor = longjmp_bkpt_dtor;
16353 /* Probe breakpoints. */
16354 ops = &bkpt_probe_breakpoint_ops;
16355 *ops = bkpt_breakpoint_ops;
16356 ops->insert_location = bkpt_probe_insert_location;
16357 ops->remove_location = bkpt_probe_remove_location;
16358 ops->create_sals_from_address = bkpt_probe_create_sals_from_address;
16359 ops->decode_linespec = bkpt_probe_decode_linespec;
16362 ops = &watchpoint_breakpoint_ops;
16363 *ops = base_breakpoint_ops;
16364 ops->dtor = dtor_watchpoint;
16365 ops->re_set = re_set_watchpoint;
16366 ops->insert_location = insert_watchpoint;
16367 ops->remove_location = remove_watchpoint;
16368 ops->breakpoint_hit = breakpoint_hit_watchpoint;
16369 ops->check_status = check_status_watchpoint;
16370 ops->resources_needed = resources_needed_watchpoint;
16371 ops->works_in_software_mode = works_in_software_mode_watchpoint;
16372 ops->print_it = print_it_watchpoint;
16373 ops->print_mention = print_mention_watchpoint;
16374 ops->print_recreate = print_recreate_watchpoint;
16375 ops->explains_signal = explains_signal_watchpoint;
16377 /* Masked watchpoints. */
16378 ops = &masked_watchpoint_breakpoint_ops;
16379 *ops = watchpoint_breakpoint_ops;
16380 ops->insert_location = insert_masked_watchpoint;
16381 ops->remove_location = remove_masked_watchpoint;
16382 ops->resources_needed = resources_needed_masked_watchpoint;
16383 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
16384 ops->print_it = print_it_masked_watchpoint;
16385 ops->print_one_detail = print_one_detail_masked_watchpoint;
16386 ops->print_mention = print_mention_masked_watchpoint;
16387 ops->print_recreate = print_recreate_masked_watchpoint;
16390 ops = &tracepoint_breakpoint_ops;
16391 *ops = base_breakpoint_ops;
16392 ops->re_set = tracepoint_re_set;
16393 ops->breakpoint_hit = tracepoint_breakpoint_hit;
16394 ops->print_one_detail = tracepoint_print_one_detail;
16395 ops->print_mention = tracepoint_print_mention;
16396 ops->print_recreate = tracepoint_print_recreate;
16397 ops->create_sals_from_address = tracepoint_create_sals_from_address;
16398 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
16399 ops->decode_linespec = tracepoint_decode_linespec;
16401 /* Probe tracepoints. */
16402 ops = &tracepoint_probe_breakpoint_ops;
16403 *ops = tracepoint_breakpoint_ops;
16404 ops->create_sals_from_address = tracepoint_probe_create_sals_from_address;
16405 ops->decode_linespec = tracepoint_probe_decode_linespec;
16407 /* Static tracepoints with marker (`-m'). */
16408 ops = &strace_marker_breakpoint_ops;
16409 *ops = tracepoint_breakpoint_ops;
16410 ops->create_sals_from_address = strace_marker_create_sals_from_address;
16411 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
16412 ops->decode_linespec = strace_marker_decode_linespec;
16414 /* Fork catchpoints. */
16415 ops = &catch_fork_breakpoint_ops;
16416 *ops = base_breakpoint_ops;
16417 ops->insert_location = insert_catch_fork;
16418 ops->remove_location = remove_catch_fork;
16419 ops->breakpoint_hit = breakpoint_hit_catch_fork;
16420 ops->print_it = print_it_catch_fork;
16421 ops->print_one = print_one_catch_fork;
16422 ops->print_mention = print_mention_catch_fork;
16423 ops->print_recreate = print_recreate_catch_fork;
16425 /* Vfork catchpoints. */
16426 ops = &catch_vfork_breakpoint_ops;
16427 *ops = base_breakpoint_ops;
16428 ops->insert_location = insert_catch_vfork;
16429 ops->remove_location = remove_catch_vfork;
16430 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
16431 ops->print_it = print_it_catch_vfork;
16432 ops->print_one = print_one_catch_vfork;
16433 ops->print_mention = print_mention_catch_vfork;
16434 ops->print_recreate = print_recreate_catch_vfork;
16436 /* Exec catchpoints. */
16437 ops = &catch_exec_breakpoint_ops;
16438 *ops = base_breakpoint_ops;
16439 ops->dtor = dtor_catch_exec;
16440 ops->insert_location = insert_catch_exec;
16441 ops->remove_location = remove_catch_exec;
16442 ops->breakpoint_hit = breakpoint_hit_catch_exec;
16443 ops->print_it = print_it_catch_exec;
16444 ops->print_one = print_one_catch_exec;
16445 ops->print_mention = print_mention_catch_exec;
16446 ops->print_recreate = print_recreate_catch_exec;
16448 /* Syscall catchpoints. */
16449 ops = &catch_syscall_breakpoint_ops;
16450 *ops = base_breakpoint_ops;
16451 ops->dtor = dtor_catch_syscall;
16452 ops->insert_location = insert_catch_syscall;
16453 ops->remove_location = remove_catch_syscall;
16454 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
16455 ops->print_it = print_it_catch_syscall;
16456 ops->print_one = print_one_catch_syscall;
16457 ops->print_mention = print_mention_catch_syscall;
16458 ops->print_recreate = print_recreate_catch_syscall;
16460 /* Solib-related catchpoints. */
16461 ops = &catch_solib_breakpoint_ops;
16462 *ops = base_breakpoint_ops;
16463 ops->dtor = dtor_catch_solib;
16464 ops->insert_location = insert_catch_solib;
16465 ops->remove_location = remove_catch_solib;
16466 ops->breakpoint_hit = breakpoint_hit_catch_solib;
16467 ops->check_status = check_status_catch_solib;
16468 ops->print_it = print_it_catch_solib;
16469 ops->print_one = print_one_catch_solib;
16470 ops->print_mention = print_mention_catch_solib;
16471 ops->print_recreate = print_recreate_catch_solib;
16473 ops = &dprintf_breakpoint_ops;
16474 *ops = bkpt_base_breakpoint_ops;
16475 ops->re_set = dprintf_re_set;
16476 ops->resources_needed = bkpt_resources_needed;
16477 ops->print_it = bkpt_print_it;
16478 ops->print_mention = bkpt_print_mention;
16479 ops->print_recreate = dprintf_print_recreate;
16480 ops->after_condition_true = dprintf_after_condition_true;
16481 ops->breakpoint_hit = dprintf_breakpoint_hit;
16484 /* Chain containing all defined "enable breakpoint" subcommands. */
16486 static struct cmd_list_element *enablebreaklist = NULL;
16489 _initialize_breakpoint (void)
16491 struct cmd_list_element *c;
16493 initialize_breakpoint_ops ();
16495 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
16496 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile);
16497 observer_attach_inferior_exit (clear_syscall_counts);
16498 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
16500 breakpoint_objfile_key
16501 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
16503 catch_syscall_inferior_data
16504 = register_inferior_data_with_cleanup (NULL,
16505 catch_syscall_inferior_data_cleanup);
16507 breakpoint_chain = 0;
16508 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16509 before a breakpoint is set. */
16510 breakpoint_count = 0;
16512 tracepoint_count = 0;
16514 add_com ("ignore", class_breakpoint, ignore_command, _("\
16515 Set ignore-count of breakpoint number N to COUNT.\n\
16516 Usage is `ignore N COUNT'."));
16518 add_com_alias ("bc", "ignore", class_breakpoint, 1);
16520 add_com ("commands", class_breakpoint, commands_command, _("\
16521 Set commands to be executed when a breakpoint is hit.\n\
16522 Give breakpoint number as argument after \"commands\".\n\
16523 With no argument, the targeted breakpoint is the last one set.\n\
16524 The commands themselves follow starting on the next line.\n\
16525 Type a line containing \"end\" to indicate the end of them.\n\
16526 Give \"silent\" as the first line to make the breakpoint silent;\n\
16527 then no output is printed when it is hit, except what the commands print."));
16529 c = add_com ("condition", class_breakpoint, condition_command, _("\
16530 Specify breakpoint number N to break only if COND is true.\n\
16531 Usage is `condition N COND', where N is an integer and COND is an\n\
16532 expression to be evaluated whenever breakpoint N is reached."));
16533 set_cmd_completer (c, condition_completer);
16535 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
16536 Set a temporary breakpoint.\n\
16537 Like \"break\" except the breakpoint is only temporary,\n\
16538 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16539 by using \"enable delete\" on the breakpoint number.\n\
16541 BREAK_ARGS_HELP ("tbreak")));
16542 set_cmd_completer (c, location_completer);
16544 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
16545 Set a hardware assisted breakpoint.\n\
16546 Like \"break\" except the breakpoint requires hardware support,\n\
16547 some target hardware may not have this support.\n\
16549 BREAK_ARGS_HELP ("hbreak")));
16550 set_cmd_completer (c, location_completer);
16552 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
16553 Set a temporary hardware assisted breakpoint.\n\
16554 Like \"hbreak\" except the breakpoint is only temporary,\n\
16555 so it will be deleted when hit.\n\
16557 BREAK_ARGS_HELP ("thbreak")));
16558 set_cmd_completer (c, location_completer);
16560 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
16561 Enable some breakpoints.\n\
16562 Give breakpoint numbers (separated by spaces) as arguments.\n\
16563 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16564 This is used to cancel the effect of the \"disable\" command.\n\
16565 With a subcommand you can enable temporarily."),
16566 &enablelist, "enable ", 1, &cmdlist);
16568 add_com ("ab", class_breakpoint, enable_command, _("\
16569 Enable some breakpoints.\n\
16570 Give breakpoint numbers (separated by spaces) as arguments.\n\
16571 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16572 This is used to cancel the effect of the \"disable\" command.\n\
16573 With a subcommand you can enable temporarily."));
16575 add_com_alias ("en", "enable", class_breakpoint, 1);
16577 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
16578 Enable some breakpoints.\n\
16579 Give breakpoint numbers (separated by spaces) as arguments.\n\
16580 This is used to cancel the effect of the \"disable\" command.\n\
16581 May be abbreviated to simply \"enable\".\n"),
16582 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
16584 add_cmd ("once", no_class, enable_once_command, _("\
16585 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16586 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16589 add_cmd ("delete", no_class, enable_delete_command, _("\
16590 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16591 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16594 add_cmd ("count", no_class, enable_count_command, _("\
16595 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16596 If a breakpoint is hit while enabled in this fashion,\n\
16597 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16600 add_cmd ("delete", no_class, enable_delete_command, _("\
16601 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16602 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16605 add_cmd ("once", no_class, enable_once_command, _("\
16606 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16607 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16610 add_cmd ("count", no_class, enable_count_command, _("\
16611 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16612 If a breakpoint is hit while enabled in this fashion,\n\
16613 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16616 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
16617 Disable some breakpoints.\n\
16618 Arguments are breakpoint numbers with spaces in between.\n\
16619 To disable all breakpoints, give no argument.\n\
16620 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16621 &disablelist, "disable ", 1, &cmdlist);
16622 add_com_alias ("dis", "disable", class_breakpoint, 1);
16623 add_com_alias ("disa", "disable", class_breakpoint, 1);
16625 add_com ("sb", class_breakpoint, disable_command, _("\
16626 Disable some breakpoints.\n\
16627 Arguments are breakpoint numbers with spaces in between.\n\
16628 To disable all breakpoints, give no argument.\n\
16629 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16631 add_cmd ("breakpoints", class_alias, disable_command, _("\
16632 Disable some breakpoints.\n\
16633 Arguments are breakpoint numbers with spaces in between.\n\
16634 To disable all breakpoints, give no argument.\n\
16635 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16636 This command may be abbreviated \"disable\"."),
16639 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
16640 Delete some breakpoints or auto-display expressions.\n\
16641 Arguments are breakpoint numbers with spaces in between.\n\
16642 To delete all breakpoints, give no argument.\n\
16644 Also a prefix command for deletion of other GDB objects.\n\
16645 The \"unset\" command is also an alias for \"delete\"."),
16646 &deletelist, "delete ", 1, &cmdlist);
16647 add_com_alias ("d", "delete", class_breakpoint, 1);
16648 add_com_alias ("del", "delete", class_breakpoint, 1);
16650 add_com ("db", class_breakpoint, delete_command, _("\
16651 Delete some breakpoints.\n\
16652 Arguments are breakpoint numbers with spaces in between.\n\
16653 To delete all breakpoints, give no argument.\n"));
16655 add_cmd ("breakpoints", class_alias, delete_command, _("\
16656 Delete some breakpoints or auto-display expressions.\n\
16657 Arguments are breakpoint numbers with spaces in between.\n\
16658 To delete all breakpoints, give no argument.\n\
16659 This command may be abbreviated \"delete\"."),
16662 add_com ("clear", class_breakpoint, clear_command, _("\
16663 Clear breakpoint at specified line or function.\n\
16664 Argument may be line number, function name, or \"*\" and an address.\n\
16665 If line number is specified, all breakpoints in that line are cleared.\n\
16666 If function is specified, breakpoints at beginning of function are cleared.\n\
16667 If an address is specified, breakpoints at that address are cleared.\n\
16669 With no argument, clears all breakpoints in the line that the selected frame\n\
16670 is executing in.\n\
16672 See also the \"delete\" command which clears breakpoints by number."));
16673 add_com_alias ("cl", "clear", class_breakpoint, 1);
16675 c = add_com ("break", class_breakpoint, break_command, _("\
16676 Set breakpoint at specified line or function.\n"
16677 BREAK_ARGS_HELP ("break")));
16678 set_cmd_completer (c, location_completer);
16680 add_com_alias ("b", "break", class_run, 1);
16681 add_com_alias ("br", "break", class_run, 1);
16682 add_com_alias ("bre", "break", class_run, 1);
16683 add_com_alias ("brea", "break", class_run, 1);
16686 add_com_alias ("ba", "break", class_breakpoint, 1);
16690 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
16691 Break in function/address or break at a line in the current file."),
16692 &stoplist, "stop ", 1, &cmdlist);
16693 add_cmd ("in", class_breakpoint, stopin_command,
16694 _("Break in function or address."), &stoplist);
16695 add_cmd ("at", class_breakpoint, stopat_command,
16696 _("Break at a line in the current file."), &stoplist);
16697 add_com ("status", class_info, breakpoints_info, _("\
16698 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16699 The \"Type\" column indicates one of:\n\
16700 \tbreakpoint - normal breakpoint\n\
16701 \twatchpoint - watchpoint\n\
16702 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16703 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16704 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16705 address and file/line number respectively.\n\
16707 Convenience variable \"$_\" and default examine address for \"x\"\n\
16708 are set to the address of the last breakpoint listed unless the command\n\
16709 is prefixed with \"server \".\n\n\
16710 Convenience variable \"$bpnum\" contains the number of the last\n\
16711 breakpoint set."));
16714 add_info ("breakpoints", breakpoints_info, _("\
16715 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16716 The \"Type\" column indicates one of:\n\
16717 \tbreakpoint - normal breakpoint\n\
16718 \twatchpoint - watchpoint\n\
16719 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16720 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16721 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16722 address and file/line number respectively.\n\
16724 Convenience variable \"$_\" and default examine address for \"x\"\n\
16725 are set to the address of the last breakpoint listed unless the command\n\
16726 is prefixed with \"server \".\n\n\
16727 Convenience variable \"$bpnum\" contains the number of the last\n\
16728 breakpoint set."));
16730 add_info_alias ("b", "breakpoints", 1);
16733 add_com ("lb", class_breakpoint, breakpoints_info, _("\
16734 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16735 The \"Type\" column indicates one of:\n\
16736 \tbreakpoint - normal breakpoint\n\
16737 \twatchpoint - watchpoint\n\
16738 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16739 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16740 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16741 address and file/line number respectively.\n\
16743 Convenience variable \"$_\" and default examine address for \"x\"\n\
16744 are set to the address of the last breakpoint listed unless the command\n\
16745 is prefixed with \"server \".\n\n\
16746 Convenience variable \"$bpnum\" contains the number of the last\n\
16747 breakpoint set."));
16749 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
16750 Status of all breakpoints, or breakpoint number NUMBER.\n\
16751 The \"Type\" column indicates one of:\n\
16752 \tbreakpoint - normal breakpoint\n\
16753 \twatchpoint - watchpoint\n\
16754 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16755 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16756 \tuntil - internal breakpoint used by the \"until\" command\n\
16757 \tfinish - internal breakpoint used by the \"finish\" command\n\
16758 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16759 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16760 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16761 address and file/line number respectively.\n\
16763 Convenience variable \"$_\" and default examine address for \"x\"\n\
16764 are set to the address of the last breakpoint listed unless the command\n\
16765 is prefixed with \"server \".\n\n\
16766 Convenience variable \"$bpnum\" contains the number of the last\n\
16768 &maintenanceinfolist);
16770 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
16771 Set catchpoints to catch events."),
16772 &catch_cmdlist, "catch ",
16773 0/*allow-unknown*/, &cmdlist);
16775 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
16776 Set temporary catchpoints to catch events."),
16777 &tcatch_cmdlist, "tcatch ",
16778 0/*allow-unknown*/, &cmdlist);
16780 add_catch_command ("fork", _("Catch calls to fork."),
16781 catch_fork_command_1,
16783 (void *) (uintptr_t) catch_fork_permanent,
16784 (void *) (uintptr_t) catch_fork_temporary);
16785 add_catch_command ("vfork", _("Catch calls to vfork."),
16786 catch_fork_command_1,
16788 (void *) (uintptr_t) catch_vfork_permanent,
16789 (void *) (uintptr_t) catch_vfork_temporary);
16790 add_catch_command ("exec", _("Catch calls to exec."),
16791 catch_exec_command_1,
16795 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16796 Usage: catch load [REGEX]\n\
16797 If REGEX is given, only stop for libraries matching the regular expression."),
16798 catch_load_command_1,
16802 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16803 Usage: catch unload [REGEX]\n\
16804 If REGEX is given, only stop for libraries matching the regular expression."),
16805 catch_unload_command_1,
16809 add_catch_command ("syscall", _("\
16810 Catch system calls by their names and/or numbers.\n\
16811 Arguments say which system calls to catch. If no arguments\n\
16812 are given, every system call will be caught.\n\
16813 Arguments, if given, should be one or more system call names\n\
16814 (if your system supports that), or system call numbers."),
16815 catch_syscall_command_1,
16816 catch_syscall_completer,
16820 c = add_com ("watch", class_breakpoint, watch_command, _("\
16821 Set a watchpoint for an expression.\n\
16822 Usage: watch [-l|-location] EXPRESSION\n\
16823 A watchpoint stops execution of your program whenever the value of\n\
16824 an expression changes.\n\
16825 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16826 the memory to which it refers."));
16827 set_cmd_completer (c, expression_completer);
16829 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
16830 Set a read watchpoint for an expression.\n\
16831 Usage: rwatch [-l|-location] EXPRESSION\n\
16832 A watchpoint stops execution of your program whenever the value of\n\
16833 an expression is read.\n\
16834 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16835 the memory to which it refers."));
16836 set_cmd_completer (c, expression_completer);
16838 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
16839 Set a watchpoint for an expression.\n\
16840 Usage: awatch [-l|-location] EXPRESSION\n\
16841 A watchpoint stops execution of your program whenever the value of\n\
16842 an expression is either read or written.\n\
16843 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16844 the memory to which it refers."));
16845 set_cmd_completer (c, expression_completer);
16847 add_info ("watchpoints", watchpoints_info, _("\
16848 Status of specified watchpoints (all watchpoints if no argument)."));
16850 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16851 respond to changes - contrary to the description. */
16852 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
16853 &can_use_hw_watchpoints, _("\
16854 Set debugger's willingness to use watchpoint hardware."), _("\
16855 Show debugger's willingness to use watchpoint hardware."), _("\
16856 If zero, gdb will not use hardware for new watchpoints, even if\n\
16857 such is available. (However, any hardware watchpoints that were\n\
16858 created before setting this to nonzero, will continue to use watchpoint\n\
16861 show_can_use_hw_watchpoints,
16862 &setlist, &showlist);
16864 can_use_hw_watchpoints = 1;
16866 /* Tracepoint manipulation commands. */
16868 c = add_com ("trace", class_breakpoint, trace_command, _("\
16869 Set a tracepoint at specified line or function.\n\
16871 BREAK_ARGS_HELP ("trace") "\n\
16872 Do \"help tracepoints\" for info on other tracepoint commands."));
16873 set_cmd_completer (c, location_completer);
16875 add_com_alias ("tp", "trace", class_alias, 0);
16876 add_com_alias ("tr", "trace", class_alias, 1);
16877 add_com_alias ("tra", "trace", class_alias, 1);
16878 add_com_alias ("trac", "trace", class_alias, 1);
16880 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
16881 Set a fast tracepoint at specified line or function.\n\
16883 BREAK_ARGS_HELP ("ftrace") "\n\
16884 Do \"help tracepoints\" for info on other tracepoint commands."));
16885 set_cmd_completer (c, location_completer);
16887 c = add_com ("strace", class_breakpoint, strace_command, _("\
16888 Set a static tracepoint at specified line, function or marker.\n\
16890 strace [LOCATION] [if CONDITION]\n\
16891 LOCATION may be a line number, function name, \"*\" and an address,\n\
16892 or -m MARKER_ID.\n\
16893 If a line number is specified, probe the marker at start of code\n\
16894 for that line. If a function is specified, probe the marker at start\n\
16895 of code for that function. If an address is specified, probe the marker\n\
16896 at that exact address. If a marker id is specified, probe the marker\n\
16897 with that name. With no LOCATION, uses current execution address of\n\
16898 the selected stack frame.\n\
16899 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16900 This collects arbitrary user data passed in the probe point call to the\n\
16901 tracing library. You can inspect it when analyzing the trace buffer,\n\
16902 by printing the $_sdata variable like any other convenience variable.\n\
16904 CONDITION is a boolean expression.\n\
16906 Multiple tracepoints at one place are permitted, and useful if their\n\
16907 conditions are different.\n\
16909 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16910 Do \"help tracepoints\" for info on other tracepoint commands."));
16911 set_cmd_completer (c, location_completer);
16913 add_info ("tracepoints", tracepoints_info, _("\
16914 Status of specified tracepoints (all tracepoints if no argument).\n\
16915 Convenience variable \"$tpnum\" contains the number of the\n\
16916 last tracepoint set."));
16918 add_info_alias ("tp", "tracepoints", 1);
16920 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
16921 Delete specified tracepoints.\n\
16922 Arguments are tracepoint numbers, separated by spaces.\n\
16923 No argument means delete all tracepoints."),
16925 add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
16927 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
16928 Disable specified tracepoints.\n\
16929 Arguments are tracepoint numbers, separated by spaces.\n\
16930 No argument means disable all tracepoints."),
16932 deprecate_cmd (c, "disable");
16934 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
16935 Enable specified tracepoints.\n\
16936 Arguments are tracepoint numbers, separated by spaces.\n\
16937 No argument means enable all tracepoints."),
16939 deprecate_cmd (c, "enable");
16941 add_com ("passcount", class_trace, trace_pass_command, _("\
16942 Set the passcount for a tracepoint.\n\
16943 The trace will end when the tracepoint has been passed 'count' times.\n\
16944 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16945 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16947 add_prefix_cmd ("save", class_breakpoint, save_command,
16948 _("Save breakpoint definitions as a script."),
16949 &save_cmdlist, "save ",
16950 0/*allow-unknown*/, &cmdlist);
16952 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
16953 Save current breakpoint definitions as a script.\n\
16954 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16955 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16956 session to restore them."),
16958 set_cmd_completer (c, filename_completer);
16960 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
16961 Save current tracepoint definitions as a script.\n\
16962 Use the 'source' command in another debug session to restore them."),
16964 set_cmd_completer (c, filename_completer);
16966 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
16967 deprecate_cmd (c, "save tracepoints");
16969 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
16970 Breakpoint specific settings\n\
16971 Configure various breakpoint-specific variables such as\n\
16972 pending breakpoint behavior"),
16973 &breakpoint_set_cmdlist, "set breakpoint ",
16974 0/*allow-unknown*/, &setlist);
16975 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
16976 Breakpoint specific settings\n\
16977 Configure various breakpoint-specific variables such as\n\
16978 pending breakpoint behavior"),
16979 &breakpoint_show_cmdlist, "show breakpoint ",
16980 0/*allow-unknown*/, &showlist);
16982 add_setshow_auto_boolean_cmd ("pending", no_class,
16983 &pending_break_support, _("\
16984 Set debugger's behavior regarding pending breakpoints."), _("\
16985 Show debugger's behavior regarding pending breakpoints."), _("\
16986 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16987 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16988 an error. If auto, an unrecognized breakpoint location results in a\n\
16989 user-query to see if a pending breakpoint should be created."),
16991 show_pending_break_support,
16992 &breakpoint_set_cmdlist,
16993 &breakpoint_show_cmdlist);
16995 pending_break_support = AUTO_BOOLEAN_AUTO;
16997 add_setshow_boolean_cmd ("auto-hw", no_class,
16998 &automatic_hardware_breakpoints, _("\
16999 Set automatic usage of hardware breakpoints."), _("\
17000 Show automatic usage of hardware breakpoints."), _("\
17001 If set, the debugger will automatically use hardware breakpoints for\n\
17002 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
17003 a warning will be emitted for such breakpoints."),
17005 show_automatic_hardware_breakpoints,
17006 &breakpoint_set_cmdlist,
17007 &breakpoint_show_cmdlist);
17009 add_setshow_auto_boolean_cmd ("always-inserted", class_support,
17010 &always_inserted_mode, _("\
17011 Set mode for inserting breakpoints."), _("\
17012 Show mode for inserting breakpoints."), _("\
17013 When this mode is off, breakpoints are inserted in inferior when it is\n\
17014 resumed, and removed when execution stops. When this mode is on,\n\
17015 breakpoints are inserted immediately and removed only when the user\n\
17016 deletes the breakpoint. When this mode is auto (which is the default),\n\
17017 the behaviour depends on the non-stop setting (see help set non-stop).\n\
17018 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
17019 behaves as if always-inserted mode is on; if gdb is controlling the\n\
17020 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
17022 &show_always_inserted_mode,
17023 &breakpoint_set_cmdlist,
17024 &breakpoint_show_cmdlist);
17026 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
17027 condition_evaluation_enums,
17028 &condition_evaluation_mode_1, _("\
17029 Set mode of breakpoint condition evaluation."), _("\
17030 Show mode of breakpoint condition evaluation."), _("\
17031 When this is set to \"host\", breakpoint conditions will be\n\
17032 evaluated on the host's side by GDB. When it is set to \"target\",\n\
17033 breakpoint conditions will be downloaded to the target (if the target\n\
17034 supports such feature) and conditions will be evaluated on the target's side.\n\
17035 If this is set to \"auto\" (default), this will be automatically set to\n\
17036 \"target\" if it supports condition evaluation, otherwise it will\n\
17037 be set to \"gdb\""),
17038 &set_condition_evaluation_mode,
17039 &show_condition_evaluation_mode,
17040 &breakpoint_set_cmdlist,
17041 &breakpoint_show_cmdlist);
17043 add_com ("break-range", class_breakpoint, break_range_command, _("\
17044 Set a breakpoint for an address range.\n\
17045 break-range START-LOCATION, END-LOCATION\n\
17046 where START-LOCATION and END-LOCATION can be one of the following:\n\
17047 LINENUM, for that line in the current file,\n\
17048 FILE:LINENUM, for that line in that file,\n\
17049 +OFFSET, for that number of lines after the current line\n\
17050 or the start of the range\n\
17051 FUNCTION, for the first line in that function,\n\
17052 FILE:FUNCTION, to distinguish among like-named static functions.\n\
17053 *ADDRESS, for the instruction at that address.\n\
17055 The breakpoint will stop execution of the inferior whenever it executes\n\
17056 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
17057 range (including START-LOCATION and END-LOCATION)."));
17059 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
17060 Set a dynamic printf at specified line or function.\n\
17061 dprintf location,format string,arg1,arg2,...\n\
17062 location may be a line number, function name, or \"*\" and an address.\n\
17063 If a line number is specified, break at start of code for that line.\n\
17064 If a function is specified, break at start of code for that function."));
17065 set_cmd_completer (c, location_completer);
17067 add_setshow_enum_cmd ("dprintf-style", class_support,
17068 dprintf_style_enums, &dprintf_style, _("\
17069 Set the style of usage for dynamic printf."), _("\
17070 Show the style of usage for dynamic printf."), _("\
17071 This setting chooses how GDB will do a dynamic printf.\n\
17072 If the value is \"gdb\", then the printing is done by GDB to its own\n\
17073 console, as with the \"printf\" command.\n\
17074 If the value is \"call\", the print is done by calling a function in your\n\
17075 program; by default printf(), but you can choose a different function or\n\
17076 output stream by setting dprintf-function and dprintf-channel."),
17077 update_dprintf_commands, NULL,
17078 &setlist, &showlist);
17080 dprintf_function = xstrdup ("printf");
17081 add_setshow_string_cmd ("dprintf-function", class_support,
17082 &dprintf_function, _("\
17083 Set the function to use for dynamic printf"), _("\
17084 Show the function to use for dynamic printf"), NULL,
17085 update_dprintf_commands, NULL,
17086 &setlist, &showlist);
17088 dprintf_channel = xstrdup ("");
17089 add_setshow_string_cmd ("dprintf-channel", class_support,
17090 &dprintf_channel, _("\
17091 Set the channel to use for dynamic printf"), _("\
17092 Show the channel to use for dynamic printf"), NULL,
17093 update_dprintf_commands, NULL,
17094 &setlist, &showlist);
17096 add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
17097 &disconnected_dprintf, _("\
17098 Set whether dprintf continues after GDB disconnects."), _("\
17099 Show whether dprintf continues after GDB disconnects."), _("\
17100 Use this to let dprintf commands continue to hit and produce output\n\
17101 even if GDB disconnects or detaches from the target."),
17104 &setlist, &showlist);
17106 add_com ("agent-printf", class_vars, agent_printf_command, _("\
17107 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
17108 (target agent only) This is useful for formatted output in user-defined commands."));
17110 automatic_hardware_breakpoints = 1;
17112 observer_attach_about_to_proceed (breakpoint_about_to_proceed);
17113 observer_attach_thread_exit (remove_threaded_breakpoints);