1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2012 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
55 #include "exceptions.h"
61 #include "xml-syscall.h"
62 #include "parser-defs.h"
63 #include "gdb_regex.h"
65 #include "cli/cli-utils.h"
66 #include "continuations.h"
69 #include "gdb_regex.h"
71 #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 "python/python.h"
83 /* Prototypes for local functions. */
85 static void enable_delete_command (char *, int);
87 static void enable_once_command (char *, int);
89 static void enable_count_command (char *, int);
91 static void disable_command (char *, int);
93 static void enable_command (char *, int);
95 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
99 static void ignore_command (char *, int);
101 static int breakpoint_re_set_one (void *);
103 static void breakpoint_re_set_default (struct breakpoint *);
105 static void create_sals_from_address_default (char **,
106 struct linespec_result *,
110 static void create_breakpoints_sal_default (struct gdbarch *,
111 struct linespec_result *,
112 struct linespec_sals *,
113 char *, char *, enum bptype,
114 enum bpdisp, int, int,
116 const struct breakpoint_ops *,
117 int, int, int, unsigned);
119 static void decode_linespec_default (struct breakpoint *, char **,
120 struct symtabs_and_lines *);
122 static void clear_command (char *, int);
124 static void catch_command (char *, int);
126 static int can_use_hardware_watchpoint (struct value *);
128 static void break_command_1 (char *, int, int);
130 static void mention (struct breakpoint *);
132 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
134 const struct breakpoint_ops *);
135 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
136 const struct symtab_and_line *);
138 /* This function is used in gdbtk sources and thus can not be made
140 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
141 struct symtab_and_line,
143 const struct breakpoint_ops *);
145 static struct breakpoint *
146 momentary_breakpoint_from_master (struct breakpoint *orig,
148 const struct breakpoint_ops *ops);
150 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
152 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
156 static void describe_other_breakpoints (struct gdbarch *,
157 struct program_space *, CORE_ADDR,
158 struct obj_section *, int);
160 static int breakpoint_address_match (struct address_space *aspace1,
162 struct address_space *aspace2,
165 static int watchpoint_locations_match (struct bp_location *loc1,
166 struct bp_location *loc2);
168 static int breakpoint_location_address_match (struct bp_location *bl,
169 struct address_space *aspace,
172 static void breakpoints_info (char *, int);
174 static void watchpoints_info (char *, int);
176 static int breakpoint_1 (char *, int,
177 int (*) (const struct breakpoint *));
179 static int breakpoint_cond_eval (void *);
181 static void cleanup_executing_breakpoints (void *);
183 static void commands_command (char *, int);
185 static void condition_command (char *, int);
194 static int remove_breakpoint (struct bp_location *, insertion_state_t);
195 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
197 static enum print_stop_action print_bp_stop_message (bpstat bs);
199 static int watchpoint_check (void *);
201 static void maintenance_info_breakpoints (char *, int);
203 static int hw_breakpoint_used_count (void);
205 static int hw_watchpoint_use_count (struct breakpoint *);
207 static int hw_watchpoint_used_count_others (struct breakpoint *except,
209 int *other_type_used);
211 static void hbreak_command (char *, int);
213 static void thbreak_command (char *, int);
215 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
218 static void stop_command (char *arg, int from_tty);
220 static void stopin_command (char *arg, int from_tty);
222 static void stopat_command (char *arg, int from_tty);
224 static char *ep_parse_optional_if_clause (char **arg);
226 static void catch_exception_command_1 (enum exception_event_kind ex_event,
227 char *arg, int tempflag, int from_tty);
229 static void tcatch_command (char *arg, int from_tty);
231 static void detach_single_step_breakpoints (void);
233 static int single_step_breakpoint_inserted_here_p (struct address_space *,
236 static void free_bp_location (struct bp_location *loc);
237 static void incref_bp_location (struct bp_location *loc);
238 static void decref_bp_location (struct bp_location **loc);
240 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
242 static void update_global_location_list (int);
244 static void update_global_location_list_nothrow (int);
246 static int is_hardware_watchpoint (const struct breakpoint *bpt);
248 static void insert_breakpoint_locations (void);
250 static int syscall_catchpoint_p (struct breakpoint *b);
252 static void tracepoints_info (char *, int);
254 static void delete_trace_command (char *, int);
256 static void enable_trace_command (char *, int);
258 static void disable_trace_command (char *, int);
260 static void trace_pass_command (char *, int);
262 static int is_masked_watchpoint (const struct breakpoint *b);
264 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
266 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
269 static int strace_marker_p (struct breakpoint *b);
271 static void init_catchpoint (struct breakpoint *b,
272 struct gdbarch *gdbarch, int tempflag,
274 const struct breakpoint_ops *ops);
276 /* The abstract base class all breakpoint_ops structures inherit
278 static struct breakpoint_ops base_breakpoint_ops;
280 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
281 that are implemented on top of software or hardware breakpoints
282 (user breakpoints, internal and momentary breakpoints, etc.). */
283 static struct breakpoint_ops bkpt_base_breakpoint_ops;
285 /* Internal breakpoints class type. */
286 static struct breakpoint_ops internal_breakpoint_ops;
288 /* Momentary breakpoints class type. */
289 static struct breakpoint_ops momentary_breakpoint_ops;
291 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
292 static struct breakpoint_ops longjmp_breakpoint_ops;
294 /* The breakpoint_ops structure to be used in regular user created
296 struct breakpoint_ops bkpt_breakpoint_ops;
298 /* Breakpoints set on probes. */
299 static struct breakpoint_ops bkpt_probe_breakpoint_ops;
301 /* Dynamic printf class type. */
302 static struct breakpoint_ops dprintf_breakpoint_ops;
304 /* A reference-counted struct command_line. This lets multiple
305 breakpoints share a single command list. */
306 struct counted_command_line
308 /* The reference count. */
311 /* The command list. */
312 struct command_line *commands;
315 struct command_line *
316 breakpoint_commands (struct breakpoint *b)
318 return b->commands ? b->commands->commands : NULL;
321 /* Flag indicating that a command has proceeded the inferior past the
322 current breakpoint. */
324 static int breakpoint_proceeded;
327 bpdisp_text (enum bpdisp disp)
329 /* NOTE: the following values are a part of MI protocol and
330 represent values of 'disp' field returned when inferior stops at
332 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
334 return bpdisps[(int) disp];
337 /* Prototypes for exported functions. */
338 /* If FALSE, gdb will not use hardware support for watchpoints, even
339 if such is available. */
340 static int can_use_hw_watchpoints;
343 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
344 struct cmd_list_element *c,
347 fprintf_filtered (file,
348 _("Debugger's willingness to use "
349 "watchpoint hardware is %s.\n"),
353 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
354 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
355 for unrecognized breakpoint locations.
356 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
357 static enum auto_boolean pending_break_support;
359 show_pending_break_support (struct ui_file *file, int from_tty,
360 struct cmd_list_element *c,
363 fprintf_filtered (file,
364 _("Debugger's behavior regarding "
365 "pending breakpoints is %s.\n"),
369 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
370 set with "break" but falling in read-only memory.
371 If 0, gdb will warn about such breakpoints, but won't automatically
372 use hardware breakpoints. */
373 static int automatic_hardware_breakpoints;
375 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
376 struct cmd_list_element *c,
379 fprintf_filtered (file,
380 _("Automatic usage of hardware breakpoints is %s.\n"),
384 /* If on, gdb will keep breakpoints inserted even as inferior is
385 stopped, and immediately insert any new breakpoints. If off, gdb
386 will insert breakpoints into inferior only when resuming it, and
387 will remove breakpoints upon stop. If auto, GDB will behave as ON
388 if in non-stop mode, and as OFF if all-stop mode.*/
390 static enum auto_boolean always_inserted_mode = AUTO_BOOLEAN_AUTO;
393 show_always_inserted_mode (struct ui_file *file, int from_tty,
394 struct cmd_list_element *c, const char *value)
396 if (always_inserted_mode == AUTO_BOOLEAN_AUTO)
397 fprintf_filtered (file,
398 _("Always inserted breakpoint "
399 "mode is %s (currently %s).\n"),
401 breakpoints_always_inserted_mode () ? "on" : "off");
403 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
408 breakpoints_always_inserted_mode (void)
410 return (always_inserted_mode == AUTO_BOOLEAN_TRUE
411 || (always_inserted_mode == AUTO_BOOLEAN_AUTO && non_stop));
414 static const char condition_evaluation_both[] = "host or target";
416 /* Modes for breakpoint condition evaluation. */
417 static const char condition_evaluation_auto[] = "auto";
418 static const char condition_evaluation_host[] = "host";
419 static const char condition_evaluation_target[] = "target";
420 static const char *const condition_evaluation_enums[] = {
421 condition_evaluation_auto,
422 condition_evaluation_host,
423 condition_evaluation_target,
427 /* Global that holds the current mode for breakpoint condition evaluation. */
428 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
430 /* Global that we use to display information to the user (gets its value from
431 condition_evaluation_mode_1. */
432 static const char *condition_evaluation_mode = condition_evaluation_auto;
434 /* Translate a condition evaluation mode MODE into either "host"
435 or "target". This is used mostly to translate from "auto" to the
436 real setting that is being used. It returns the translated
440 translate_condition_evaluation_mode (const char *mode)
442 if (mode == condition_evaluation_auto)
444 if (target_supports_evaluation_of_breakpoint_conditions ())
445 return condition_evaluation_target;
447 return condition_evaluation_host;
453 /* Discovers what condition_evaluation_auto translates to. */
456 breakpoint_condition_evaluation_mode (void)
458 return translate_condition_evaluation_mode (condition_evaluation_mode);
461 /* Return true if GDB should evaluate breakpoint conditions or false
465 gdb_evaluates_breakpoint_condition_p (void)
467 const char *mode = breakpoint_condition_evaluation_mode ();
469 return (mode == condition_evaluation_host);
472 void _initialize_breakpoint (void);
474 /* Are we executing breakpoint commands? */
475 static int executing_breakpoint_commands;
477 /* Are overlay event breakpoints enabled? */
478 static int overlay_events_enabled;
480 /* See description in breakpoint.h. */
481 int target_exact_watchpoints = 0;
483 /* Walk the following statement or block through all breakpoints.
484 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
485 current breakpoint. */
487 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
489 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
490 for (B = breakpoint_chain; \
491 B ? (TMP=B->next, 1): 0; \
494 /* Similar iterator for the low-level breakpoints. SAFE variant is
495 not provided so update_global_location_list must not be called
496 while executing the block of ALL_BP_LOCATIONS. */
498 #define ALL_BP_LOCATIONS(B,BP_TMP) \
499 for (BP_TMP = bp_location; \
500 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
503 /* Iterates through locations with address ADDRESS for the currently selected
504 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
505 to where the loop should start from.
506 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
507 appropriate location to start with. */
509 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
510 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
511 BP_LOCP_TMP = BP_LOCP_START; \
513 && (BP_LOCP_TMP < bp_location + bp_location_count \
514 && (*BP_LOCP_TMP)->address == ADDRESS); \
517 /* Iterator for tracepoints only. */
519 #define ALL_TRACEPOINTS(B) \
520 for (B = breakpoint_chain; B; B = B->next) \
521 if (is_tracepoint (B))
523 /* Chains of all breakpoints defined. */
525 struct breakpoint *breakpoint_chain;
527 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
529 static struct bp_location **bp_location;
531 /* Number of elements of BP_LOCATION. */
533 static unsigned bp_location_count;
535 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
536 ADDRESS for the current elements of BP_LOCATION which get a valid
537 result from bp_location_has_shadow. You can use it for roughly
538 limiting the subrange of BP_LOCATION to scan for shadow bytes for
539 an address you need to read. */
541 static CORE_ADDR bp_location_placed_address_before_address_max;
543 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
544 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
545 BP_LOCATION which get a valid result from bp_location_has_shadow.
546 You can use it for roughly limiting the subrange of BP_LOCATION to
547 scan for shadow bytes for an address you need to read. */
549 static CORE_ADDR bp_location_shadow_len_after_address_max;
551 /* The locations that no longer correspond to any breakpoint, unlinked
552 from bp_location array, but for which a hit may still be reported
554 VEC(bp_location_p) *moribund_locations = NULL;
556 /* Number of last breakpoint made. */
558 static int breakpoint_count;
560 /* The value of `breakpoint_count' before the last command that
561 created breakpoints. If the last (break-like) command created more
562 than one breakpoint, then the difference between BREAKPOINT_COUNT
563 and PREV_BREAKPOINT_COUNT is more than one. */
564 static int prev_breakpoint_count;
566 /* Number of last tracepoint made. */
568 static int tracepoint_count;
570 static struct cmd_list_element *breakpoint_set_cmdlist;
571 static struct cmd_list_element *breakpoint_show_cmdlist;
572 struct cmd_list_element *save_cmdlist;
574 /* Return whether a breakpoint is an active enabled breakpoint. */
576 breakpoint_enabled (struct breakpoint *b)
578 return (b->enable_state == bp_enabled);
581 /* Set breakpoint count to NUM. */
584 set_breakpoint_count (int num)
586 prev_breakpoint_count = breakpoint_count;
587 breakpoint_count = num;
588 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
591 /* Used by `start_rbreak_breakpoints' below, to record the current
592 breakpoint count before "rbreak" creates any breakpoint. */
593 static int rbreak_start_breakpoint_count;
595 /* Called at the start an "rbreak" command to record the first
599 start_rbreak_breakpoints (void)
601 rbreak_start_breakpoint_count = breakpoint_count;
604 /* Called at the end of an "rbreak" command to record the last
608 end_rbreak_breakpoints (void)
610 prev_breakpoint_count = rbreak_start_breakpoint_count;
613 /* Used in run_command to zero the hit count when a new run starts. */
616 clear_breakpoint_hit_counts (void)
618 struct breakpoint *b;
624 /* Allocate a new counted_command_line with reference count of 1.
625 The new structure owns COMMANDS. */
627 static struct counted_command_line *
628 alloc_counted_command_line (struct command_line *commands)
630 struct counted_command_line *result
631 = xmalloc (sizeof (struct counted_command_line));
634 result->commands = commands;
638 /* Increment reference count. This does nothing if CMD is NULL. */
641 incref_counted_command_line (struct counted_command_line *cmd)
647 /* Decrement reference count. If the reference count reaches 0,
648 destroy the counted_command_line. Sets *CMDP to NULL. This does
649 nothing if *CMDP is NULL. */
652 decref_counted_command_line (struct counted_command_line **cmdp)
656 if (--(*cmdp)->refc == 0)
658 free_command_lines (&(*cmdp)->commands);
665 /* A cleanup function that calls decref_counted_command_line. */
668 do_cleanup_counted_command_line (void *arg)
670 decref_counted_command_line (arg);
673 /* Create a cleanup that calls decref_counted_command_line on the
676 static struct cleanup *
677 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
679 return make_cleanup (do_cleanup_counted_command_line, cmdp);
683 /* Return the breakpoint with the specified number, or NULL
684 if the number does not refer to an existing breakpoint. */
687 get_breakpoint (int num)
689 struct breakpoint *b;
692 if (b->number == num)
700 /* Mark locations as "conditions have changed" in case the target supports
701 evaluating conditions on its side. */
704 mark_breakpoint_modified (struct breakpoint *b)
706 struct bp_location *loc;
708 /* This is only meaningful if the target is
709 evaluating conditions and if the user has
710 opted for condition evaluation on the target's
712 if (gdb_evaluates_breakpoint_condition_p ()
713 || !target_supports_evaluation_of_breakpoint_conditions ())
716 if (!is_breakpoint (b))
719 for (loc = b->loc; loc; loc = loc->next)
720 loc->condition_changed = condition_modified;
723 /* Mark location as "conditions have changed" in case the target supports
724 evaluating conditions on its side. */
727 mark_breakpoint_location_modified (struct bp_location *loc)
729 /* This is only meaningful if the target is
730 evaluating conditions and if the user has
731 opted for condition evaluation on the target's
733 if (gdb_evaluates_breakpoint_condition_p ()
734 || !target_supports_evaluation_of_breakpoint_conditions ())
738 if (!is_breakpoint (loc->owner))
741 loc->condition_changed = condition_modified;
744 /* Sets the condition-evaluation mode using the static global
745 condition_evaluation_mode. */
748 set_condition_evaluation_mode (char *args, int from_tty,
749 struct cmd_list_element *c)
751 const char *old_mode, *new_mode;
753 if ((condition_evaluation_mode_1 == condition_evaluation_target)
754 && !target_supports_evaluation_of_breakpoint_conditions ())
756 condition_evaluation_mode_1 = condition_evaluation_mode;
757 warning (_("Target does not support breakpoint condition evaluation.\n"
758 "Using host evaluation mode instead."));
762 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
763 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
765 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
766 settings was "auto". */
767 condition_evaluation_mode = condition_evaluation_mode_1;
769 /* Only update the mode if the user picked a different one. */
770 if (new_mode != old_mode)
772 struct bp_location *loc, **loc_tmp;
773 /* If the user switched to a different evaluation mode, we
774 need to synch the changes with the target as follows:
776 "host" -> "target": Send all (valid) conditions to the target.
777 "target" -> "host": Remove all the conditions from the target.
780 if (new_mode == condition_evaluation_target)
782 /* Mark everything modified and synch conditions with the
784 ALL_BP_LOCATIONS (loc, loc_tmp)
785 mark_breakpoint_location_modified (loc);
789 /* Manually mark non-duplicate locations to synch conditions
790 with the target. We do this to remove all the conditions the
791 target knows about. */
792 ALL_BP_LOCATIONS (loc, loc_tmp)
793 if (is_breakpoint (loc->owner) && loc->inserted)
794 loc->needs_update = 1;
798 update_global_location_list (1);
804 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
805 what "auto" is translating to. */
808 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
809 struct cmd_list_element *c, const char *value)
811 if (condition_evaluation_mode == condition_evaluation_auto)
812 fprintf_filtered (file,
813 _("Breakpoint condition evaluation "
814 "mode is %s (currently %s).\n"),
816 breakpoint_condition_evaluation_mode ());
818 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
822 /* A comparison function for bp_location AP and BP that is used by
823 bsearch. This comparison function only cares about addresses, unlike
824 the more general bp_location_compare function. */
827 bp_location_compare_addrs (const void *ap, const void *bp)
829 struct bp_location *a = *(void **) ap;
830 struct bp_location *b = *(void **) bp;
832 if (a->address == b->address)
835 return ((a->address > b->address) - (a->address < b->address));
838 /* Helper function to skip all bp_locations with addresses
839 less than ADDRESS. It returns the first bp_location that
840 is greater than or equal to ADDRESS. If none is found, just
843 static struct bp_location **
844 get_first_locp_gte_addr (CORE_ADDR address)
846 struct bp_location dummy_loc;
847 struct bp_location *dummy_locp = &dummy_loc;
848 struct bp_location **locp_found = NULL;
850 /* Initialize the dummy location's address field. */
851 memset (&dummy_loc, 0, sizeof (struct bp_location));
852 dummy_loc.address = address;
854 /* Find a close match to the first location at ADDRESS. */
855 locp_found = bsearch (&dummy_locp, bp_location, bp_location_count,
856 sizeof (struct bp_location **),
857 bp_location_compare_addrs);
859 /* Nothing was found, nothing left to do. */
860 if (locp_found == NULL)
863 /* We may have found a location that is at ADDRESS but is not the first in the
864 location's list. Go backwards (if possible) and locate the first one. */
865 while ((locp_found - 1) >= bp_location
866 && (*(locp_found - 1))->address == address)
873 set_breakpoint_condition (struct breakpoint *b, char *exp,
876 xfree (b->cond_string);
877 b->cond_string = NULL;
879 if (is_watchpoint (b))
881 struct watchpoint *w = (struct watchpoint *) b;
888 struct bp_location *loc;
890 for (loc = b->loc; loc; loc = loc->next)
895 /* No need to free the condition agent expression
896 bytecode (if we have one). We will handle this
897 when we go through update_global_location_list. */
904 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
910 /* I don't know if it matters whether this is the string the user
911 typed in or the decompiled expression. */
912 b->cond_string = xstrdup (arg);
913 b->condition_not_parsed = 0;
915 if (is_watchpoint (b))
917 struct watchpoint *w = (struct watchpoint *) b;
919 innermost_block = NULL;
921 w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
923 error (_("Junk at end of expression"));
924 w->cond_exp_valid_block = innermost_block;
928 struct bp_location *loc;
930 for (loc = b->loc; loc; loc = loc->next)
934 parse_exp_1 (&arg, loc->address,
935 block_for_pc (loc->address), 0);
937 error (_("Junk at end of expression"));
941 mark_breakpoint_modified (b);
943 breakpoints_changed ();
944 observer_notify_breakpoint_modified (b);
947 /* Completion for the "condition" command. */
949 static VEC (char_ptr) *
950 condition_completer (struct cmd_list_element *cmd, char *text, char *word)
954 text = skip_spaces (text);
955 space = skip_to_space (text);
959 struct breakpoint *b;
960 VEC (char_ptr) *result = NULL;
964 /* We don't support completion of history indices. */
965 if (isdigit (text[1]))
967 return complete_internalvar (&text[1]);
970 /* We're completing the breakpoint number. */
975 int single = b->loc->next == NULL;
976 struct bp_location *loc;
979 for (loc = b->loc; loc; loc = loc->next)
984 sprintf (location, "%d", b->number);
986 sprintf (location, "%d.%d", b->number, count);
988 if (strncmp (location, text, len) == 0)
989 VEC_safe_push (char_ptr, result, xstrdup (location));
998 /* We're completing the expression part. */
999 text = skip_spaces (space);
1000 return expression_completer (cmd, text, word);
1003 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1006 condition_command (char *arg, int from_tty)
1008 struct breakpoint *b;
1013 error_no_arg (_("breakpoint number"));
1016 bnum = get_number (&p);
1018 error (_("Bad breakpoint argument: '%s'"), arg);
1021 if (b->number == bnum)
1023 /* Check if this breakpoint has a Python object assigned to
1024 it, and if it has a definition of the "stop"
1025 method. This method and conditions entered into GDB from
1026 the CLI are mutually exclusive. */
1028 && gdbpy_breakpoint_has_py_cond (b->py_bp_object))
1029 error (_("Cannot set a condition where a Python 'stop' "
1030 "method has been defined in the breakpoint."));
1031 set_breakpoint_condition (b, p, from_tty);
1033 if (is_breakpoint (b))
1034 update_global_location_list (1);
1039 error (_("No breakpoint number %d."), bnum);
1042 /* Check that COMMAND do not contain commands that are suitable
1043 only for tracepoints and not suitable for ordinary breakpoints.
1044 Throw if any such commands is found. */
1047 check_no_tracepoint_commands (struct command_line *commands)
1049 struct command_line *c;
1051 for (c = commands; c; c = c->next)
1055 if (c->control_type == while_stepping_control)
1056 error (_("The 'while-stepping' command can "
1057 "only be used for tracepoints"));
1059 for (i = 0; i < c->body_count; ++i)
1060 check_no_tracepoint_commands ((c->body_list)[i]);
1062 /* Not that command parsing removes leading whitespace and comment
1063 lines and also empty lines. So, we only need to check for
1064 command directly. */
1065 if (strstr (c->line, "collect ") == c->line)
1066 error (_("The 'collect' command can only be used for tracepoints"));
1068 if (strstr (c->line, "teval ") == c->line)
1069 error (_("The 'teval' command can only be used for tracepoints"));
1073 /* Encapsulate tests for different types of tracepoints. */
1076 is_tracepoint_type (enum bptype type)
1078 return (type == bp_tracepoint
1079 || type == bp_fast_tracepoint
1080 || type == bp_static_tracepoint);
1084 is_tracepoint (const struct breakpoint *b)
1086 return is_tracepoint_type (b->type);
1089 /* A helper function that validates that COMMANDS are valid for a
1090 breakpoint. This function will throw an exception if a problem is
1094 validate_commands_for_breakpoint (struct breakpoint *b,
1095 struct command_line *commands)
1097 if (is_tracepoint (b))
1099 /* We need to verify that each top-level element of commands is
1100 valid for tracepoints, that there's at most one
1101 while-stepping element, and that while-stepping's body has
1102 valid tracing commands excluding nested while-stepping. */
1103 struct command_line *c;
1104 struct command_line *while_stepping = 0;
1105 for (c = commands; c; c = c->next)
1107 if (c->control_type == while_stepping_control)
1109 if (b->type == bp_fast_tracepoint)
1110 error (_("The 'while-stepping' command "
1111 "cannot be used for fast tracepoint"));
1112 else if (b->type == bp_static_tracepoint)
1113 error (_("The 'while-stepping' command "
1114 "cannot be used for static tracepoint"));
1117 error (_("The 'while-stepping' command "
1118 "can be used only once"));
1125 struct command_line *c2;
1127 gdb_assert (while_stepping->body_count == 1);
1128 c2 = while_stepping->body_list[0];
1129 for (; c2; c2 = c2->next)
1131 if (c2->control_type == while_stepping_control)
1132 error (_("The 'while-stepping' command cannot be nested"));
1138 check_no_tracepoint_commands (commands);
1142 /* Return a vector of all the static tracepoints set at ADDR. The
1143 caller is responsible for releasing the vector. */
1146 static_tracepoints_here (CORE_ADDR addr)
1148 struct breakpoint *b;
1149 VEC(breakpoint_p) *found = 0;
1150 struct bp_location *loc;
1153 if (b->type == bp_static_tracepoint)
1155 for (loc = b->loc; loc; loc = loc->next)
1156 if (loc->address == addr)
1157 VEC_safe_push(breakpoint_p, found, b);
1163 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1164 validate that only allowed commands are included. */
1167 breakpoint_set_commands (struct breakpoint *b,
1168 struct command_line *commands)
1170 validate_commands_for_breakpoint (b, commands);
1172 decref_counted_command_line (&b->commands);
1173 b->commands = alloc_counted_command_line (commands);
1174 breakpoints_changed ();
1175 observer_notify_breakpoint_modified (b);
1178 /* Set the internal `silent' flag on the breakpoint. Note that this
1179 is not the same as the "silent" that may appear in the breakpoint's
1183 breakpoint_set_silent (struct breakpoint *b, int silent)
1185 int old_silent = b->silent;
1188 if (old_silent != silent)
1189 observer_notify_breakpoint_modified (b);
1192 /* Set the thread for this breakpoint. If THREAD is -1, make the
1193 breakpoint work for any thread. */
1196 breakpoint_set_thread (struct breakpoint *b, int thread)
1198 int old_thread = b->thread;
1201 if (old_thread != thread)
1202 observer_notify_breakpoint_modified (b);
1205 /* Set the task for this breakpoint. If TASK is 0, make the
1206 breakpoint work for any task. */
1209 breakpoint_set_task (struct breakpoint *b, int task)
1211 int old_task = b->task;
1214 if (old_task != task)
1215 observer_notify_breakpoint_modified (b);
1219 check_tracepoint_command (char *line, void *closure)
1221 struct breakpoint *b = closure;
1223 validate_actionline (&line, b);
1226 /* A structure used to pass information through
1227 map_breakpoint_numbers. */
1229 struct commands_info
1231 /* True if the command was typed at a tty. */
1234 /* The breakpoint range spec. */
1237 /* Non-NULL if the body of the commands are being read from this
1238 already-parsed command. */
1239 struct command_line *control;
1241 /* The command lines read from the user, or NULL if they have not
1243 struct counted_command_line *cmd;
1246 /* A callback for map_breakpoint_numbers that sets the commands for
1247 commands_command. */
1250 do_map_commands_command (struct breakpoint *b, void *data)
1252 struct commands_info *info = data;
1254 if (info->cmd == NULL)
1256 struct command_line *l;
1258 if (info->control != NULL)
1259 l = copy_command_lines (info->control->body_list[0]);
1262 struct cleanup *old_chain;
1265 str = xstrprintf (_("Type commands for breakpoint(s) "
1266 "%s, one per line."),
1269 old_chain = make_cleanup (xfree, str);
1271 l = read_command_lines (str,
1274 ? check_tracepoint_command : 0),
1277 do_cleanups (old_chain);
1280 info->cmd = alloc_counted_command_line (l);
1283 /* If a breakpoint was on the list more than once, we don't need to
1285 if (b->commands != info->cmd)
1287 validate_commands_for_breakpoint (b, info->cmd->commands);
1288 incref_counted_command_line (info->cmd);
1289 decref_counted_command_line (&b->commands);
1290 b->commands = info->cmd;
1291 breakpoints_changed ();
1292 observer_notify_breakpoint_modified (b);
1297 commands_command_1 (char *arg, int from_tty,
1298 struct command_line *control)
1300 struct cleanup *cleanups;
1301 struct commands_info info;
1303 info.from_tty = from_tty;
1304 info.control = control;
1306 /* If we read command lines from the user, then `info' will hold an
1307 extra reference to the commands that we must clean up. */
1308 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1310 if (arg == NULL || !*arg)
1312 if (breakpoint_count - prev_breakpoint_count > 1)
1313 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1315 else if (breakpoint_count > 0)
1316 arg = xstrprintf ("%d", breakpoint_count);
1319 /* So that we don't try to free the incoming non-NULL
1320 argument in the cleanup below. Mapping breakpoint
1321 numbers will fail in this case. */
1326 /* The command loop has some static state, so we need to preserve
1328 arg = xstrdup (arg);
1331 make_cleanup (xfree, arg);
1335 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1337 if (info.cmd == NULL)
1338 error (_("No breakpoints specified."));
1340 do_cleanups (cleanups);
1344 commands_command (char *arg, int from_tty)
1346 commands_command_1 (arg, from_tty, NULL);
1349 /* Like commands_command, but instead of reading the commands from
1350 input stream, takes them from an already parsed command structure.
1352 This is used by cli-script.c to DTRT with breakpoint commands
1353 that are part of if and while bodies. */
1354 enum command_control_type
1355 commands_from_control_command (char *arg, struct command_line *cmd)
1357 commands_command_1 (arg, 0, cmd);
1358 return simple_control;
1361 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1364 bp_location_has_shadow (struct bp_location *bl)
1366 if (bl->loc_type != bp_loc_software_breakpoint)
1370 if (bl->target_info.shadow_len == 0)
1371 /* BL isn't valid, or doesn't shadow memory. */
1376 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1377 by replacing any memory breakpoints with their shadowed contents.
1379 If READBUF is not NULL, this buffer must not overlap with any of
1380 the breakpoint location's shadow_contents buffers. Otherwise,
1381 a failed assertion internal error will be raised.
1383 The range of shadowed area by each bp_location is:
1384 bl->address - bp_location_placed_address_before_address_max
1385 up to bl->address + bp_location_shadow_len_after_address_max
1386 The range we were requested to resolve shadows for is:
1387 memaddr ... memaddr + len
1388 Thus the safe cutoff boundaries for performance optimization are
1389 memaddr + len <= (bl->address
1390 - bp_location_placed_address_before_address_max)
1392 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1395 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1396 const gdb_byte *writebuf_org,
1397 ULONGEST memaddr, LONGEST len)
1399 /* Left boundary, right boundary and median element of our binary
1401 unsigned bc_l, bc_r, bc;
1403 /* Find BC_L which is a leftmost element which may affect BUF
1404 content. It is safe to report lower value but a failure to
1405 report higher one. */
1408 bc_r = bp_location_count;
1409 while (bc_l + 1 < bc_r)
1411 struct bp_location *bl;
1413 bc = (bc_l + bc_r) / 2;
1414 bl = bp_location[bc];
1416 /* Check first BL->ADDRESS will not overflow due to the added
1417 constant. Then advance the left boundary only if we are sure
1418 the BC element can in no way affect the BUF content (MEMADDR
1419 to MEMADDR + LEN range).
1421 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1422 offset so that we cannot miss a breakpoint with its shadow
1423 range tail still reaching MEMADDR. */
1425 if ((bl->address + bp_location_shadow_len_after_address_max
1427 && (bl->address + bp_location_shadow_len_after_address_max
1434 /* Due to the binary search above, we need to make sure we pick the
1435 first location that's at BC_L's address. E.g., if there are
1436 multiple locations at the same address, BC_L may end up pointing
1437 at a duplicate location, and miss the "master"/"inserted"
1438 location. Say, given locations L1, L2 and L3 at addresses A and
1441 L1@A, L2@A, L3@B, ...
1443 BC_L could end up pointing at location L2, while the "master"
1444 location could be L1. Since the `loc->inserted' flag is only set
1445 on "master" locations, we'd forget to restore the shadow of L1
1448 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1451 /* Now do full processing of the found relevant range of elements. */
1453 for (bc = bc_l; bc < bp_location_count; bc++)
1455 struct bp_location *bl = bp_location[bc];
1456 CORE_ADDR bp_addr = 0;
1460 /* bp_location array has BL->OWNER always non-NULL. */
1461 if (bl->owner->type == bp_none)
1462 warning (_("reading through apparently deleted breakpoint #%d?"),
1465 /* Performance optimization: any further element can no longer affect BUF
1468 if (bl->address >= bp_location_placed_address_before_address_max
1469 && memaddr + len <= (bl->address
1470 - bp_location_placed_address_before_address_max))
1473 if (!bp_location_has_shadow (bl))
1475 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0,
1476 current_program_space->aspace, 0))
1479 /* Addresses and length of the part of the breakpoint that
1481 bp_addr = bl->target_info.placed_address;
1482 bp_size = bl->target_info.shadow_len;
1484 if (bp_addr + bp_size <= memaddr)
1485 /* The breakpoint is entirely before the chunk of memory we
1489 if (bp_addr >= memaddr + len)
1490 /* The breakpoint is entirely after the chunk of memory we are
1494 /* Offset within shadow_contents. */
1495 if (bp_addr < memaddr)
1497 /* Only copy the second part of the breakpoint. */
1498 bp_size -= memaddr - bp_addr;
1499 bptoffset = memaddr - bp_addr;
1503 if (bp_addr + bp_size > memaddr + len)
1505 /* Only copy the first part of the breakpoint. */
1506 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1509 if (readbuf != NULL)
1511 /* Verify that the readbuf buffer does not overlap with
1512 the shadow_contents buffer. */
1513 gdb_assert (bl->target_info.shadow_contents >= readbuf + len
1514 || readbuf >= (bl->target_info.shadow_contents
1515 + bl->target_info.shadow_len));
1517 /* Update the read buffer with this inserted breakpoint's
1519 memcpy (readbuf + bp_addr - memaddr,
1520 bl->target_info.shadow_contents + bptoffset, bp_size);
1524 struct gdbarch *gdbarch = bl->gdbarch;
1525 const unsigned char *bp;
1526 CORE_ADDR placed_address = bl->target_info.placed_address;
1527 unsigned placed_size = bl->target_info.placed_size;
1529 /* Update the shadow with what we want to write to memory. */
1530 memcpy (bl->target_info.shadow_contents + bptoffset,
1531 writebuf_org + bp_addr - memaddr, bp_size);
1533 /* Determine appropriate breakpoint contents and size for this
1535 bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size);
1537 /* Update the final write buffer with this inserted
1538 breakpoint's INSN. */
1539 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1545 /* Return true if BPT is either a software breakpoint or a hardware
1549 is_breakpoint (const struct breakpoint *bpt)
1551 return (bpt->type == bp_breakpoint
1552 || bpt->type == bp_hardware_breakpoint
1553 || bpt->type == bp_dprintf);
1556 /* Return true if BPT is of any hardware watchpoint kind. */
1559 is_hardware_watchpoint (const struct breakpoint *bpt)
1561 return (bpt->type == bp_hardware_watchpoint
1562 || bpt->type == bp_read_watchpoint
1563 || bpt->type == bp_access_watchpoint);
1566 /* Return true if BPT is of any watchpoint kind, hardware or
1570 is_watchpoint (const struct breakpoint *bpt)
1572 return (is_hardware_watchpoint (bpt)
1573 || bpt->type == bp_watchpoint);
1576 /* Returns true if the current thread and its running state are safe
1577 to evaluate or update watchpoint B. Watchpoints on local
1578 expressions need to be evaluated in the context of the thread that
1579 was current when the watchpoint was created, and, that thread needs
1580 to be stopped to be able to select the correct frame context.
1581 Watchpoints on global expressions can be evaluated on any thread,
1582 and in any state. It is presently left to the target allowing
1583 memory accesses when threads are running. */
1586 watchpoint_in_thread_scope (struct watchpoint *b)
1588 return (b->base.pspace == current_program_space
1589 && (ptid_equal (b->watchpoint_thread, null_ptid)
1590 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1591 && !is_executing (inferior_ptid))));
1594 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1595 associated bp_watchpoint_scope breakpoint. */
1598 watchpoint_del_at_next_stop (struct watchpoint *w)
1600 struct breakpoint *b = &w->base;
1602 if (b->related_breakpoint != b)
1604 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1605 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1606 b->related_breakpoint->disposition = disp_del_at_next_stop;
1607 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1608 b->related_breakpoint = b;
1610 b->disposition = disp_del_at_next_stop;
1613 /* Assuming that B is a watchpoint:
1614 - Reparse watchpoint expression, if REPARSE is non-zero
1615 - Evaluate expression and store the result in B->val
1616 - Evaluate the condition if there is one, and store the result
1618 - Update the list of values that must be watched in B->loc.
1620 If the watchpoint disposition is disp_del_at_next_stop, then do
1621 nothing. If this is local watchpoint that is out of scope, delete
1624 Even with `set breakpoint always-inserted on' the watchpoints are
1625 removed + inserted on each stop here. Normal breakpoints must
1626 never be removed because they might be missed by a running thread
1627 when debugging in non-stop mode. On the other hand, hardware
1628 watchpoints (is_hardware_watchpoint; processed here) are specific
1629 to each LWP since they are stored in each LWP's hardware debug
1630 registers. Therefore, such LWP must be stopped first in order to
1631 be able to modify its hardware watchpoints.
1633 Hardware watchpoints must be reset exactly once after being
1634 presented to the user. It cannot be done sooner, because it would
1635 reset the data used to present the watchpoint hit to the user. And
1636 it must not be done later because it could display the same single
1637 watchpoint hit during multiple GDB stops. Note that the latter is
1638 relevant only to the hardware watchpoint types bp_read_watchpoint
1639 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1640 not user-visible - its hit is suppressed if the memory content has
1643 The following constraints influence the location where we can reset
1644 hardware watchpoints:
1646 * target_stopped_by_watchpoint and target_stopped_data_address are
1647 called several times when GDB stops.
1650 * Multiple hardware watchpoints can be hit at the same time,
1651 causing GDB to stop. GDB only presents one hardware watchpoint
1652 hit at a time as the reason for stopping, and all the other hits
1653 are presented later, one after the other, each time the user
1654 requests the execution to be resumed. Execution is not resumed
1655 for the threads still having pending hit event stored in
1656 LWP_INFO->STATUS. While the watchpoint is already removed from
1657 the inferior on the first stop the thread hit event is kept being
1658 reported from its cached value by linux_nat_stopped_data_address
1659 until the real thread resume happens after the watchpoint gets
1660 presented and thus its LWP_INFO->STATUS gets reset.
1662 Therefore the hardware watchpoint hit can get safely reset on the
1663 watchpoint removal from inferior. */
1666 update_watchpoint (struct watchpoint *b, int reparse)
1668 int within_current_scope;
1669 struct frame_id saved_frame_id;
1672 /* If this is a local watchpoint, we only want to check if the
1673 watchpoint frame is in scope if the current thread is the thread
1674 that was used to create the watchpoint. */
1675 if (!watchpoint_in_thread_scope (b))
1678 if (b->base.disposition == disp_del_at_next_stop)
1683 /* Determine if the watchpoint is within scope. */
1684 if (b->exp_valid_block == NULL)
1685 within_current_scope = 1;
1688 struct frame_info *fi = get_current_frame ();
1689 struct gdbarch *frame_arch = get_frame_arch (fi);
1690 CORE_ADDR frame_pc = get_frame_pc (fi);
1692 /* If we're in a function epilogue, unwinding may not work
1693 properly, so do not attempt to recreate locations at this
1694 point. See similar comments in watchpoint_check. */
1695 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1698 /* Save the current frame's ID so we can restore it after
1699 evaluating the watchpoint expression on its own frame. */
1700 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1701 took a frame parameter, so that we didn't have to change the
1704 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1706 fi = frame_find_by_id (b->watchpoint_frame);
1707 within_current_scope = (fi != NULL);
1708 if (within_current_scope)
1712 /* We don't free locations. They are stored in the bp_location array
1713 and update_global_location_list will eventually delete them and
1714 remove breakpoints if needed. */
1717 if (within_current_scope && reparse)
1726 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1727 b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
1728 /* If the meaning of expression itself changed, the old value is
1729 no longer relevant. We don't want to report a watchpoint hit
1730 to the user when the old value and the new value may actually
1731 be completely different objects. */
1732 value_free (b->val);
1736 /* Note that unlike with breakpoints, the watchpoint's condition
1737 expression is stored in the breakpoint object, not in the
1738 locations (re)created below. */
1739 if (b->base.cond_string != NULL)
1741 if (b->cond_exp != NULL)
1743 xfree (b->cond_exp);
1747 s = b->base.cond_string;
1748 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1752 /* If we failed to parse the expression, for example because
1753 it refers to a global variable in a not-yet-loaded shared library,
1754 don't try to insert watchpoint. We don't automatically delete
1755 such watchpoint, though, since failure to parse expression
1756 is different from out-of-scope watchpoint. */
1757 if ( !target_has_execution)
1759 /* Without execution, memory can't change. No use to try and
1760 set watchpoint locations. The watchpoint will be reset when
1761 the target gains execution, through breakpoint_re_set. */
1763 else if (within_current_scope && b->exp)
1766 struct value *val_chain, *v, *result, *next;
1767 struct program_space *frame_pspace;
1769 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain);
1771 /* Avoid setting b->val if it's already set. The meaning of
1772 b->val is 'the last value' user saw, and we should update
1773 it only if we reported that last value to user. As it
1774 happens, the code that reports it updates b->val directly.
1775 We don't keep track of the memory value for masked
1777 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1783 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1785 /* Look at each value on the value chain. */
1786 for (v = val_chain; v; v = value_next (v))
1788 /* If it's a memory location, and GDB actually needed
1789 its contents to evaluate the expression, then we
1790 must watch it. If the first value returned is
1791 still lazy, that means an error occurred reading it;
1792 watch it anyway in case it becomes readable. */
1793 if (VALUE_LVAL (v) == lval_memory
1794 && (v == val_chain || ! value_lazy (v)))
1796 struct type *vtype = check_typedef (value_type (v));
1798 /* We only watch structs and arrays if user asked
1799 for it explicitly, never if they just happen to
1800 appear in the middle of some value chain. */
1802 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1803 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1807 struct bp_location *loc, **tmp;
1809 addr = value_address (v);
1810 len = TYPE_LENGTH (value_type (v));
1812 if (b->base.type == bp_read_watchpoint)
1814 else if (b->base.type == bp_access_watchpoint)
1817 loc = allocate_bp_location (&b->base);
1818 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
1821 loc->gdbarch = get_type_arch (value_type (v));
1823 loc->pspace = frame_pspace;
1824 loc->address = addr;
1826 loc->watchpoint_type = type;
1831 /* Change the type of breakpoint between hardware assisted or
1832 an ordinary watchpoint depending on the hardware support
1833 and free hardware slots. REPARSE is set when the inferior
1838 enum bp_loc_type loc_type;
1839 struct bp_location *bl;
1841 reg_cnt = can_use_hardware_watchpoint (val_chain);
1845 int i, target_resources_ok, other_type_used;
1848 /* Use an exact watchpoint when there's only one memory region to be
1849 watched, and only one debug register is needed to watch it. */
1850 b->exact = target_exact_watchpoints && reg_cnt == 1;
1852 /* We need to determine how many resources are already
1853 used for all other hardware watchpoints plus this one
1854 to see if we still have enough resources to also fit
1855 this watchpoint in as well. */
1857 /* If this is a software watchpoint, we try to turn it
1858 to a hardware one -- count resources as if B was of
1859 hardware watchpoint type. */
1860 type = b->base.type;
1861 if (type == bp_watchpoint)
1862 type = bp_hardware_watchpoint;
1864 /* This watchpoint may or may not have been placed on
1865 the list yet at this point (it won't be in the list
1866 if we're trying to create it for the first time,
1867 through watch_command), so always account for it
1870 /* Count resources used by all watchpoints except B. */
1871 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
1873 /* Add in the resources needed for B. */
1874 i += hw_watchpoint_use_count (&b->base);
1877 = target_can_use_hardware_watchpoint (type, i, other_type_used);
1878 if (target_resources_ok <= 0)
1880 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
1882 if (target_resources_ok == 0 && !sw_mode)
1883 error (_("Target does not support this type of "
1884 "hardware watchpoint."));
1885 else if (target_resources_ok < 0 && !sw_mode)
1886 error (_("There are not enough available hardware "
1887 "resources for this watchpoint."));
1889 /* Downgrade to software watchpoint. */
1890 b->base.type = bp_watchpoint;
1894 /* If this was a software watchpoint, we've just
1895 found we have enough resources to turn it to a
1896 hardware watchpoint. Otherwise, this is a
1898 b->base.type = type;
1901 else if (!b->base.ops->works_in_software_mode (&b->base))
1902 error (_("Expression cannot be implemented with "
1903 "read/access watchpoint."));
1905 b->base.type = bp_watchpoint;
1907 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
1908 : bp_loc_hardware_watchpoint);
1909 for (bl = b->base.loc; bl; bl = bl->next)
1910 bl->loc_type = loc_type;
1913 for (v = val_chain; v; v = next)
1915 next = value_next (v);
1920 /* If a software watchpoint is not watching any memory, then the
1921 above left it without any location set up. But,
1922 bpstat_stop_status requires a location to be able to report
1923 stops, so make sure there's at least a dummy one. */
1924 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
1926 struct breakpoint *base = &b->base;
1927 base->loc = allocate_bp_location (base);
1928 base->loc->pspace = frame_pspace;
1929 base->loc->address = -1;
1930 base->loc->length = -1;
1931 base->loc->watchpoint_type = -1;
1934 else if (!within_current_scope)
1936 printf_filtered (_("\
1937 Watchpoint %d deleted because the program has left the block\n\
1938 in which its expression is valid.\n"),
1940 watchpoint_del_at_next_stop (b);
1943 /* Restore the selected frame. */
1945 select_frame (frame_find_by_id (saved_frame_id));
1949 /* Returns 1 iff breakpoint location should be
1950 inserted in the inferior. We don't differentiate the type of BL's owner
1951 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1952 breakpoint_ops is not defined, because in insert_bp_location,
1953 tracepoint's insert_location will not be called. */
1955 should_be_inserted (struct bp_location *bl)
1957 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
1960 if (bl->owner->disposition == disp_del_at_next_stop)
1963 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
1966 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
1969 /* This is set for example, when we're attached to the parent of a
1970 vfork, and have detached from the child. The child is running
1971 free, and we expect it to do an exec or exit, at which point the
1972 OS makes the parent schedulable again (and the target reports
1973 that the vfork is done). Until the child is done with the shared
1974 memory region, do not insert breakpoints in the parent, otherwise
1975 the child could still trip on the parent's breakpoints. Since
1976 the parent is blocked anyway, it won't miss any breakpoint. */
1977 if (bl->pspace->breakpoints_not_allowed)
1983 /* Same as should_be_inserted but does the check assuming
1984 that the location is not duplicated. */
1987 unduplicated_should_be_inserted (struct bp_location *bl)
1990 const int save_duplicate = bl->duplicate;
1993 result = should_be_inserted (bl);
1994 bl->duplicate = save_duplicate;
1998 /* Parses a conditional described by an expression COND into an
1999 agent expression bytecode suitable for evaluation
2000 by the bytecode interpreter. Return NULL if there was
2001 any error during parsing. */
2003 static struct agent_expr *
2004 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2006 struct agent_expr *aexpr = NULL;
2007 struct cleanup *old_chain = NULL;
2008 volatile struct gdb_exception ex;
2013 /* We don't want to stop processing, so catch any errors
2014 that may show up. */
2015 TRY_CATCH (ex, RETURN_MASK_ERROR)
2017 aexpr = gen_eval_for_expr (scope, cond);
2022 /* If we got here, it means the condition could not be parsed to a valid
2023 bytecode expression and thus can't be evaluated on the target's side.
2024 It's no use iterating through the conditions. */
2028 /* We have a valid agent expression. */
2032 /* Based on location BL, create a list of breakpoint conditions to be
2033 passed on to the target. If we have duplicated locations with different
2034 conditions, we will add such conditions to the list. The idea is that the
2035 target will evaluate the list of conditions and will only notify GDB when
2036 one of them is true. */
2039 build_target_condition_list (struct bp_location *bl)
2041 struct bp_location **locp = NULL, **loc2p;
2042 int null_condition_or_parse_error = 0;
2043 int modified = bl->needs_update;
2044 struct bp_location *loc;
2046 /* This is only meaningful if the target is
2047 evaluating conditions and if the user has
2048 opted for condition evaluation on the target's
2050 if (gdb_evaluates_breakpoint_condition_p ()
2051 || !target_supports_evaluation_of_breakpoint_conditions ())
2054 /* Do a first pass to check for locations with no assigned
2055 conditions or conditions that fail to parse to a valid agent expression
2056 bytecode. If any of these happen, then it's no use to send conditions
2057 to the target since this location will always trigger and generate a
2058 response back to GDB. */
2059 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2062 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2066 struct agent_expr *aexpr;
2068 /* Re-parse the conditions since something changed. In that
2069 case we already freed the condition bytecodes (see
2070 force_breakpoint_reinsertion). We just
2071 need to parse the condition to bytecodes again. */
2072 aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2073 loc->cond_bytecode = aexpr;
2075 /* Check if we managed to parse the conditional expression
2076 correctly. If not, we will not send this condition
2082 /* If we have a NULL bytecode expression, it means something
2083 went wrong or we have a null condition expression. */
2084 if (!loc->cond_bytecode)
2086 null_condition_or_parse_error = 1;
2092 /* If any of these happened, it means we will have to evaluate the conditions
2093 for the location's address on gdb's side. It is no use keeping bytecodes
2094 for all the other duplicate locations, thus we free all of them here.
2096 This is so we have a finer control over which locations' conditions are
2097 being evaluated by GDB or the remote stub. */
2098 if (null_condition_or_parse_error)
2100 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2103 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2105 /* Only go as far as the first NULL bytecode is
2107 if (!loc->cond_bytecode)
2110 free_agent_expr (loc->cond_bytecode);
2111 loc->cond_bytecode = NULL;
2116 /* No NULL conditions or failed bytecode generation. Build a condition list
2117 for this location's address. */
2118 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2122 && is_breakpoint (loc->owner)
2123 && loc->pspace->num == bl->pspace->num
2124 && loc->owner->enable_state == bp_enabled
2126 /* Add the condition to the vector. This will be used later to send the
2127 conditions to the target. */
2128 VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2129 loc->cond_bytecode);
2135 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2136 location. Any error messages are printed to TMP_ERROR_STREAM; and
2137 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2138 Returns 0 for success, 1 if the bp_location type is not supported or
2141 NOTE drow/2003-09-09: This routine could be broken down to an
2142 object-style method for each breakpoint or catchpoint type. */
2144 insert_bp_location (struct bp_location *bl,
2145 struct ui_file *tmp_error_stream,
2146 int *disabled_breaks,
2147 int *hw_breakpoint_error)
2151 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2154 /* Note we don't initialize bl->target_info, as that wipes out
2155 the breakpoint location's shadow_contents if the breakpoint
2156 is still inserted at that location. This in turn breaks
2157 target_read_memory which depends on these buffers when
2158 a memory read is requested at the breakpoint location:
2159 Once the target_info has been wiped, we fail to see that
2160 we have a breakpoint inserted at that address and thus
2161 read the breakpoint instead of returning the data saved in
2162 the breakpoint location's shadow contents. */
2163 bl->target_info.placed_address = bl->address;
2164 bl->target_info.placed_address_space = bl->pspace->aspace;
2165 bl->target_info.length = bl->length;
2167 /* When working with target-side conditions, we must pass all the conditions
2168 for the same breakpoint address down to the target since GDB will not
2169 insert those locations. With a list of breakpoint conditions, the target
2170 can decide when to stop and notify GDB. */
2172 if (is_breakpoint (bl->owner))
2174 build_target_condition_list (bl);
2175 /* Reset the condition modification marker. */
2176 bl->needs_update = 0;
2179 if (bl->loc_type == bp_loc_software_breakpoint
2180 || bl->loc_type == bp_loc_hardware_breakpoint)
2182 if (bl->owner->type != bp_hardware_breakpoint)
2184 /* If the explicitly specified breakpoint type
2185 is not hardware breakpoint, check the memory map to see
2186 if the breakpoint address is in read only memory or not.
2188 Two important cases are:
2189 - location type is not hardware breakpoint, memory
2190 is readonly. We change the type of the location to
2191 hardware breakpoint.
2192 - location type is hardware breakpoint, memory is
2193 read-write. This means we've previously made the
2194 location hardware one, but then the memory map changed,
2197 When breakpoints are removed, remove_breakpoints will use
2198 location types we've just set here, the only possible
2199 problem is that memory map has changed during running
2200 program, but it's not going to work anyway with current
2202 struct mem_region *mr
2203 = lookup_mem_region (bl->target_info.placed_address);
2207 if (automatic_hardware_breakpoints)
2209 enum bp_loc_type new_type;
2211 if (mr->attrib.mode != MEM_RW)
2212 new_type = bp_loc_hardware_breakpoint;
2214 new_type = bp_loc_software_breakpoint;
2216 if (new_type != bl->loc_type)
2218 static int said = 0;
2220 bl->loc_type = new_type;
2223 fprintf_filtered (gdb_stdout,
2224 _("Note: automatically using "
2225 "hardware breakpoints for "
2226 "read-only addresses.\n"));
2231 else if (bl->loc_type == bp_loc_software_breakpoint
2232 && mr->attrib.mode != MEM_RW)
2233 warning (_("cannot set software breakpoint "
2234 "at readonly address %s"),
2235 paddress (bl->gdbarch, bl->address));
2239 /* First check to see if we have to handle an overlay. */
2240 if (overlay_debugging == ovly_off
2241 || bl->section == NULL
2242 || !(section_is_overlay (bl->section)))
2244 /* No overlay handling: just set the breakpoint. */
2246 val = bl->owner->ops->insert_location (bl);
2250 /* This breakpoint is in an overlay section.
2251 Shall we set a breakpoint at the LMA? */
2252 if (!overlay_events_enabled)
2254 /* Yes -- overlay event support is not active,
2255 so we must try to set a breakpoint at the LMA.
2256 This will not work for a hardware breakpoint. */
2257 if (bl->loc_type == bp_loc_hardware_breakpoint)
2258 warning (_("hardware breakpoint %d not supported in overlay!"),
2262 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2264 /* Set a software (trap) breakpoint at the LMA. */
2265 bl->overlay_target_info = bl->target_info;
2266 bl->overlay_target_info.placed_address = addr;
2267 val = target_insert_breakpoint (bl->gdbarch,
2268 &bl->overlay_target_info);
2270 fprintf_unfiltered (tmp_error_stream,
2271 "Overlay breakpoint %d "
2272 "failed: in ROM?\n",
2276 /* Shall we set a breakpoint at the VMA? */
2277 if (section_is_mapped (bl->section))
2279 /* Yes. This overlay section is mapped into memory. */
2280 val = bl->owner->ops->insert_location (bl);
2284 /* No. This breakpoint will not be inserted.
2285 No error, but do not mark the bp as 'inserted'. */
2292 /* Can't set the breakpoint. */
2293 if (solib_name_from_address (bl->pspace, bl->address))
2295 /* See also: disable_breakpoints_in_shlibs. */
2297 bl->shlib_disabled = 1;
2298 observer_notify_breakpoint_modified (bl->owner);
2299 if (!*disabled_breaks)
2301 fprintf_unfiltered (tmp_error_stream,
2302 "Cannot insert breakpoint %d.\n",
2304 fprintf_unfiltered (tmp_error_stream,
2305 "Temporarily disabling shared "
2306 "library breakpoints:\n");
2308 *disabled_breaks = 1;
2309 fprintf_unfiltered (tmp_error_stream,
2310 "breakpoint #%d\n", bl->owner->number);
2314 if (bl->loc_type == bp_loc_hardware_breakpoint)
2316 *hw_breakpoint_error = 1;
2317 fprintf_unfiltered (tmp_error_stream,
2318 "Cannot insert hardware "
2324 fprintf_unfiltered (tmp_error_stream,
2325 "Cannot insert breakpoint %d.\n",
2327 fprintf_filtered (tmp_error_stream,
2328 "Error accessing memory address ");
2329 fputs_filtered (paddress (bl->gdbarch, bl->address),
2331 fprintf_filtered (tmp_error_stream, ": %s.\n",
2332 safe_strerror (val));
2343 else if (bl->loc_type == bp_loc_hardware_watchpoint
2344 /* NOTE drow/2003-09-08: This state only exists for removing
2345 watchpoints. It's not clear that it's necessary... */
2346 && bl->owner->disposition != disp_del_at_next_stop)
2348 gdb_assert (bl->owner->ops != NULL
2349 && bl->owner->ops->insert_location != NULL);
2351 val = bl->owner->ops->insert_location (bl);
2353 /* If trying to set a read-watchpoint, and it turns out it's not
2354 supported, try emulating one with an access watchpoint. */
2355 if (val == 1 && bl->watchpoint_type == hw_read)
2357 struct bp_location *loc, **loc_temp;
2359 /* But don't try to insert it, if there's already another
2360 hw_access location that would be considered a duplicate
2362 ALL_BP_LOCATIONS (loc, loc_temp)
2364 && loc->watchpoint_type == hw_access
2365 && watchpoint_locations_match (bl, loc))
2369 bl->target_info = loc->target_info;
2370 bl->watchpoint_type = hw_access;
2377 bl->watchpoint_type = hw_access;
2378 val = bl->owner->ops->insert_location (bl);
2381 /* Back to the original value. */
2382 bl->watchpoint_type = hw_read;
2386 bl->inserted = (val == 0);
2389 else if (bl->owner->type == bp_catchpoint)
2391 gdb_assert (bl->owner->ops != NULL
2392 && bl->owner->ops->insert_location != NULL);
2394 val = bl->owner->ops->insert_location (bl);
2397 bl->owner->enable_state = bp_disabled;
2401 Error inserting catchpoint %d: Your system does not support this type\n\
2402 of catchpoint."), bl->owner->number);
2404 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2407 bl->inserted = (val == 0);
2409 /* We've already printed an error message if there was a problem
2410 inserting this catchpoint, and we've disabled the catchpoint,
2411 so just return success. */
2418 /* This function is called when program space PSPACE is about to be
2419 deleted. It takes care of updating breakpoints to not reference
2423 breakpoint_program_space_exit (struct program_space *pspace)
2425 struct breakpoint *b, *b_temp;
2426 struct bp_location *loc, **loc_temp;
2428 /* Remove any breakpoint that was set through this program space. */
2429 ALL_BREAKPOINTS_SAFE (b, b_temp)
2431 if (b->pspace == pspace)
2432 delete_breakpoint (b);
2435 /* Breakpoints set through other program spaces could have locations
2436 bound to PSPACE as well. Remove those. */
2437 ALL_BP_LOCATIONS (loc, loc_temp)
2439 struct bp_location *tmp;
2441 if (loc->pspace == pspace)
2443 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2444 if (loc->owner->loc == loc)
2445 loc->owner->loc = loc->next;
2447 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2448 if (tmp->next == loc)
2450 tmp->next = loc->next;
2456 /* Now update the global location list to permanently delete the
2457 removed locations above. */
2458 update_global_location_list (0);
2461 /* Make sure all breakpoints are inserted in inferior.
2462 Throws exception on any error.
2463 A breakpoint that is already inserted won't be inserted
2464 again, so calling this function twice is safe. */
2466 insert_breakpoints (void)
2468 struct breakpoint *bpt;
2470 ALL_BREAKPOINTS (bpt)
2471 if (is_hardware_watchpoint (bpt))
2473 struct watchpoint *w = (struct watchpoint *) bpt;
2475 update_watchpoint (w, 0 /* don't reparse. */);
2478 update_global_location_list (1);
2480 /* update_global_location_list does not insert breakpoints when
2481 always_inserted_mode is not enabled. Explicitly insert them
2483 if (!breakpoints_always_inserted_mode ())
2484 insert_breakpoint_locations ();
2487 /* Invoke CALLBACK for each of bp_location. */
2490 iterate_over_bp_locations (walk_bp_location_callback callback)
2492 struct bp_location *loc, **loc_tmp;
2494 ALL_BP_LOCATIONS (loc, loc_tmp)
2496 callback (loc, NULL);
2500 /* This is used when we need to synch breakpoint conditions between GDB and the
2501 target. It is the case with deleting and disabling of breakpoints when using
2502 always-inserted mode. */
2505 update_inserted_breakpoint_locations (void)
2507 struct bp_location *bl, **blp_tmp;
2510 int disabled_breaks = 0;
2511 int hw_breakpoint_error = 0;
2513 struct ui_file *tmp_error_stream = mem_fileopen ();
2514 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2516 /* Explicitly mark the warning -- this will only be printed if
2517 there was an error. */
2518 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2520 save_current_space_and_thread ();
2522 ALL_BP_LOCATIONS (bl, blp_tmp)
2524 /* We only want to update software breakpoints and hardware
2526 if (!is_breakpoint (bl->owner))
2529 /* We only want to update locations that are already inserted
2530 and need updating. This is to avoid unwanted insertion during
2531 deletion of breakpoints. */
2532 if (!bl->inserted || (bl->inserted && !bl->needs_update))
2535 switch_to_program_space_and_thread (bl->pspace);
2537 /* For targets that support global breakpoints, there's no need
2538 to select an inferior to insert breakpoint to. In fact, even
2539 if we aren't attached to any process yet, we should still
2540 insert breakpoints. */
2541 if (!gdbarch_has_global_breakpoints (target_gdbarch)
2542 && ptid_equal (inferior_ptid, null_ptid))
2545 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2546 &hw_breakpoint_error);
2553 target_terminal_ours_for_output ();
2554 error_stream (tmp_error_stream);
2557 do_cleanups (cleanups);
2560 /* Used when starting or continuing the program. */
2563 insert_breakpoint_locations (void)
2565 struct breakpoint *bpt;
2566 struct bp_location *bl, **blp_tmp;
2569 int disabled_breaks = 0;
2570 int hw_breakpoint_error = 0;
2572 struct ui_file *tmp_error_stream = mem_fileopen ();
2573 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2575 /* Explicitly mark the warning -- this will only be printed if
2576 there was an error. */
2577 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2579 save_current_space_and_thread ();
2581 ALL_BP_LOCATIONS (bl, blp_tmp)
2583 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2586 /* There is no point inserting thread-specific breakpoints if
2587 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2588 has BL->OWNER always non-NULL. */
2589 if (bl->owner->thread != -1
2590 && !valid_thread_id (bl->owner->thread))
2593 switch_to_program_space_and_thread (bl->pspace);
2595 /* For targets that support global breakpoints, there's no need
2596 to select an inferior to insert breakpoint to. In fact, even
2597 if we aren't attached to any process yet, we should still
2598 insert breakpoints. */
2599 if (!gdbarch_has_global_breakpoints (target_gdbarch)
2600 && ptid_equal (inferior_ptid, null_ptid))
2603 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2604 &hw_breakpoint_error);
2609 /* If we failed to insert all locations of a watchpoint, remove
2610 them, as half-inserted watchpoint is of limited use. */
2611 ALL_BREAKPOINTS (bpt)
2613 int some_failed = 0;
2614 struct bp_location *loc;
2616 if (!is_hardware_watchpoint (bpt))
2619 if (!breakpoint_enabled (bpt))
2622 if (bpt->disposition == disp_del_at_next_stop)
2625 for (loc = bpt->loc; loc; loc = loc->next)
2626 if (!loc->inserted && should_be_inserted (loc))
2633 for (loc = bpt->loc; loc; loc = loc->next)
2635 remove_breakpoint (loc, mark_uninserted);
2637 hw_breakpoint_error = 1;
2638 fprintf_unfiltered (tmp_error_stream,
2639 "Could not insert hardware watchpoint %d.\n",
2647 /* If a hardware breakpoint or watchpoint was inserted, add a
2648 message about possibly exhausted resources. */
2649 if (hw_breakpoint_error)
2651 fprintf_unfiltered (tmp_error_stream,
2652 "Could not insert hardware breakpoints:\n\
2653 You may have requested too many hardware breakpoints/watchpoints.\n");
2655 target_terminal_ours_for_output ();
2656 error_stream (tmp_error_stream);
2659 do_cleanups (cleanups);
2662 /* Used when the program stops.
2663 Returns zero if successful, or non-zero if there was a problem
2664 removing a breakpoint location. */
2667 remove_breakpoints (void)
2669 struct bp_location *bl, **blp_tmp;
2672 ALL_BP_LOCATIONS (bl, blp_tmp)
2674 if (bl->inserted && !is_tracepoint (bl->owner))
2675 val |= remove_breakpoint (bl, mark_uninserted);
2680 /* Remove breakpoints of process PID. */
2683 remove_breakpoints_pid (int pid)
2685 struct bp_location *bl, **blp_tmp;
2687 struct inferior *inf = find_inferior_pid (pid);
2689 ALL_BP_LOCATIONS (bl, blp_tmp)
2691 if (bl->pspace != inf->pspace)
2696 val = remove_breakpoint (bl, mark_uninserted);
2705 reattach_breakpoints (int pid)
2707 struct cleanup *old_chain;
2708 struct bp_location *bl, **blp_tmp;
2710 struct ui_file *tmp_error_stream;
2711 int dummy1 = 0, dummy2 = 0;
2712 struct inferior *inf;
2713 struct thread_info *tp;
2715 tp = any_live_thread_of_process (pid);
2719 inf = find_inferior_pid (pid);
2720 old_chain = save_inferior_ptid ();
2722 inferior_ptid = tp->ptid;
2724 tmp_error_stream = mem_fileopen ();
2725 make_cleanup_ui_file_delete (tmp_error_stream);
2727 ALL_BP_LOCATIONS (bl, blp_tmp)
2729 if (bl->pspace != inf->pspace)
2735 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2);
2738 do_cleanups (old_chain);
2743 do_cleanups (old_chain);
2747 static int internal_breakpoint_number = -1;
2749 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2750 If INTERNAL is non-zero, the breakpoint number will be populated
2751 from internal_breakpoint_number and that variable decremented.
2752 Otherwise the breakpoint number will be populated from
2753 breakpoint_count and that value incremented. Internal breakpoints
2754 do not set the internal var bpnum. */
2756 set_breakpoint_number (int internal, struct breakpoint *b)
2759 b->number = internal_breakpoint_number--;
2762 set_breakpoint_count (breakpoint_count + 1);
2763 b->number = breakpoint_count;
2767 static struct breakpoint *
2768 create_internal_breakpoint (struct gdbarch *gdbarch,
2769 CORE_ADDR address, enum bptype type,
2770 const struct breakpoint_ops *ops)
2772 struct symtab_and_line sal;
2773 struct breakpoint *b;
2775 init_sal (&sal); /* Initialize to zeroes. */
2778 sal.section = find_pc_overlay (sal.pc);
2779 sal.pspace = current_program_space;
2781 b = set_raw_breakpoint (gdbarch, sal, type, ops);
2782 b->number = internal_breakpoint_number--;
2783 b->disposition = disp_donttouch;
2788 static const char *const longjmp_names[] =
2790 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2792 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2794 /* Per-objfile data private to breakpoint.c. */
2795 struct breakpoint_objfile_data
2797 /* Minimal symbol for "_ovly_debug_event" (if any). */
2798 struct minimal_symbol *overlay_msym;
2800 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2801 struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES];
2803 /* True if we have looked for longjmp probes. */
2804 int longjmp_searched;
2806 /* SystemTap probe points for longjmp (if any). */
2807 VEC (probe_p) *longjmp_probes;
2809 /* Minimal symbol for "std::terminate()" (if any). */
2810 struct minimal_symbol *terminate_msym;
2812 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2813 struct minimal_symbol *exception_msym;
2815 /* True if we have looked for exception probes. */
2816 int exception_searched;
2818 /* SystemTap probe points for unwinding (if any). */
2819 VEC (probe_p) *exception_probes;
2822 static const struct objfile_data *breakpoint_objfile_key;
2824 /* Minimal symbol not found sentinel. */
2825 static struct minimal_symbol msym_not_found;
2827 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2830 msym_not_found_p (const struct minimal_symbol *msym)
2832 return msym == &msym_not_found;
2835 /* Return per-objfile data needed by breakpoint.c.
2836 Allocate the data if necessary. */
2838 static struct breakpoint_objfile_data *
2839 get_breakpoint_objfile_data (struct objfile *objfile)
2841 struct breakpoint_objfile_data *bp_objfile_data;
2843 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
2844 if (bp_objfile_data == NULL)
2846 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
2847 sizeof (*bp_objfile_data));
2849 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
2850 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
2852 return bp_objfile_data;
2856 free_breakpoint_probes (struct objfile *obj, void *data)
2858 struct breakpoint_objfile_data *bp_objfile_data = data;
2860 VEC_free (probe_p, bp_objfile_data->longjmp_probes);
2861 VEC_free (probe_p, bp_objfile_data->exception_probes);
2865 create_overlay_event_breakpoint (void)
2867 struct objfile *objfile;
2868 const char *const func_name = "_ovly_debug_event";
2870 ALL_OBJFILES (objfile)
2872 struct breakpoint *b;
2873 struct breakpoint_objfile_data *bp_objfile_data;
2876 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2878 if (msym_not_found_p (bp_objfile_data->overlay_msym))
2881 if (bp_objfile_data->overlay_msym == NULL)
2883 struct minimal_symbol *m;
2885 m = lookup_minimal_symbol_text (func_name, objfile);
2888 /* Avoid future lookups in this objfile. */
2889 bp_objfile_data->overlay_msym = &msym_not_found;
2892 bp_objfile_data->overlay_msym = m;
2895 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
2896 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2898 &internal_breakpoint_ops);
2899 b->addr_string = xstrdup (func_name);
2901 if (overlay_debugging == ovly_auto)
2903 b->enable_state = bp_enabled;
2904 overlay_events_enabled = 1;
2908 b->enable_state = bp_disabled;
2909 overlay_events_enabled = 0;
2912 update_global_location_list (1);
2916 create_longjmp_master_breakpoint (void)
2918 struct program_space *pspace;
2919 struct cleanup *old_chain;
2921 old_chain = save_current_program_space ();
2923 ALL_PSPACES (pspace)
2925 struct objfile *objfile;
2927 set_current_program_space (pspace);
2929 ALL_OBJFILES (objfile)
2932 struct gdbarch *gdbarch;
2933 struct breakpoint_objfile_data *bp_objfile_data;
2935 gdbarch = get_objfile_arch (objfile);
2936 if (!gdbarch_get_longjmp_target_p (gdbarch))
2939 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2941 if (!bp_objfile_data->longjmp_searched)
2943 bp_objfile_data->longjmp_probes
2944 = find_probes_in_objfile (objfile, "libc", "longjmp");
2945 bp_objfile_data->longjmp_searched = 1;
2948 if (bp_objfile_data->longjmp_probes != NULL)
2951 struct probe *probe;
2952 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2955 VEC_iterate (probe_p,
2956 bp_objfile_data->longjmp_probes,
2960 struct breakpoint *b;
2962 b = create_internal_breakpoint (gdbarch, probe->address,
2964 &internal_breakpoint_ops);
2965 b->addr_string = xstrdup ("-probe-stap libc:longjmp");
2966 b->enable_state = bp_disabled;
2972 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
2974 struct breakpoint *b;
2975 const char *func_name;
2978 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i]))
2981 func_name = longjmp_names[i];
2982 if (bp_objfile_data->longjmp_msym[i] == NULL)
2984 struct minimal_symbol *m;
2986 m = lookup_minimal_symbol_text (func_name, objfile);
2989 /* Prevent future lookups in this objfile. */
2990 bp_objfile_data->longjmp_msym[i] = &msym_not_found;
2993 bp_objfile_data->longjmp_msym[i] = m;
2996 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
2997 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
2998 &internal_breakpoint_ops);
2999 b->addr_string = xstrdup (func_name);
3000 b->enable_state = bp_disabled;
3004 update_global_location_list (1);
3006 do_cleanups (old_chain);
3009 /* Create a master std::terminate breakpoint. */
3011 create_std_terminate_master_breakpoint (void)
3013 struct program_space *pspace;
3014 struct cleanup *old_chain;
3015 const char *const func_name = "std::terminate()";
3017 old_chain = save_current_program_space ();
3019 ALL_PSPACES (pspace)
3021 struct objfile *objfile;
3024 set_current_program_space (pspace);
3026 ALL_OBJFILES (objfile)
3028 struct breakpoint *b;
3029 struct breakpoint_objfile_data *bp_objfile_data;
3031 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3033 if (msym_not_found_p (bp_objfile_data->terminate_msym))
3036 if (bp_objfile_data->terminate_msym == NULL)
3038 struct minimal_symbol *m;
3040 m = lookup_minimal_symbol (func_name, NULL, objfile);
3041 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
3042 && MSYMBOL_TYPE (m) != mst_file_text))
3044 /* Prevent future lookups in this objfile. */
3045 bp_objfile_data->terminate_msym = &msym_not_found;
3048 bp_objfile_data->terminate_msym = m;
3051 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3052 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3053 bp_std_terminate_master,
3054 &internal_breakpoint_ops);
3055 b->addr_string = xstrdup (func_name);
3056 b->enable_state = bp_disabled;
3060 update_global_location_list (1);
3062 do_cleanups (old_chain);
3065 /* Install a master breakpoint on the unwinder's debug hook. */
3068 create_exception_master_breakpoint (void)
3070 struct objfile *objfile;
3071 const char *const func_name = "_Unwind_DebugHook";
3073 ALL_OBJFILES (objfile)
3075 struct breakpoint *b;
3076 struct gdbarch *gdbarch;
3077 struct breakpoint_objfile_data *bp_objfile_data;
3080 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3082 /* We prefer the SystemTap probe point if it exists. */
3083 if (!bp_objfile_data->exception_searched)
3085 bp_objfile_data->exception_probes
3086 = find_probes_in_objfile (objfile, "libgcc", "unwind");
3087 bp_objfile_data->exception_searched = 1;
3090 if (bp_objfile_data->exception_probes != NULL)
3092 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3094 struct probe *probe;
3097 VEC_iterate (probe_p,
3098 bp_objfile_data->exception_probes,
3102 struct breakpoint *b;
3104 b = create_internal_breakpoint (gdbarch, probe->address,
3105 bp_exception_master,
3106 &internal_breakpoint_ops);
3107 b->addr_string = xstrdup ("-probe-stap libgcc:unwind");
3108 b->enable_state = bp_disabled;
3114 /* Otherwise, try the hook function. */
3116 if (msym_not_found_p (bp_objfile_data->exception_msym))
3119 gdbarch = get_objfile_arch (objfile);
3121 if (bp_objfile_data->exception_msym == NULL)
3123 struct minimal_symbol *debug_hook;
3125 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3126 if (debug_hook == NULL)
3128 bp_objfile_data->exception_msym = &msym_not_found;
3132 bp_objfile_data->exception_msym = debug_hook;
3135 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3136 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3138 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3139 &internal_breakpoint_ops);
3140 b->addr_string = xstrdup (func_name);
3141 b->enable_state = bp_disabled;
3144 update_global_location_list (1);
3148 update_breakpoints_after_exec (void)
3150 struct breakpoint *b, *b_tmp;
3151 struct bp_location *bploc, **bplocp_tmp;
3153 /* We're about to delete breakpoints from GDB's lists. If the
3154 INSERTED flag is true, GDB will try to lift the breakpoints by
3155 writing the breakpoints' "shadow contents" back into memory. The
3156 "shadow contents" are NOT valid after an exec, so GDB should not
3157 do that. Instead, the target is responsible from marking
3158 breakpoints out as soon as it detects an exec. We don't do that
3159 here instead, because there may be other attempts to delete
3160 breakpoints after detecting an exec and before reaching here. */
3161 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3162 if (bploc->pspace == current_program_space)
3163 gdb_assert (!bploc->inserted);
3165 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3167 if (b->pspace != current_program_space)
3170 /* Solib breakpoints must be explicitly reset after an exec(). */
3171 if (b->type == bp_shlib_event)
3173 delete_breakpoint (b);
3177 /* JIT breakpoints must be explicitly reset after an exec(). */
3178 if (b->type == bp_jit_event)
3180 delete_breakpoint (b);
3184 /* Thread event breakpoints must be set anew after an exec(),
3185 as must overlay event and longjmp master breakpoints. */
3186 if (b->type == bp_thread_event || b->type == bp_overlay_event
3187 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3188 || b->type == bp_exception_master)
3190 delete_breakpoint (b);
3194 /* Step-resume breakpoints are meaningless after an exec(). */
3195 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3197 delete_breakpoint (b);
3201 /* Longjmp and longjmp-resume breakpoints are also meaningless
3203 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3204 || b->type == bp_longjmp_call_dummy
3205 || b->type == bp_exception || b->type == bp_exception_resume)
3207 delete_breakpoint (b);
3211 if (b->type == bp_catchpoint)
3213 /* For now, none of the bp_catchpoint breakpoints need to
3214 do anything at this point. In the future, if some of
3215 the catchpoints need to something, we will need to add
3216 a new method, and call this method from here. */
3220 /* bp_finish is a special case. The only way we ought to be able
3221 to see one of these when an exec() has happened, is if the user
3222 caught a vfork, and then said "finish". Ordinarily a finish just
3223 carries them to the call-site of the current callee, by setting
3224 a temporary bp there and resuming. But in this case, the finish
3225 will carry them entirely through the vfork & exec.
3227 We don't want to allow a bp_finish to remain inserted now. But
3228 we can't safely delete it, 'cause finish_command has a handle to
3229 the bp on a bpstat, and will later want to delete it. There's a
3230 chance (and I've seen it happen) that if we delete the bp_finish
3231 here, that its storage will get reused by the time finish_command
3232 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3233 We really must allow finish_command to delete a bp_finish.
3235 In the absence of a general solution for the "how do we know
3236 it's safe to delete something others may have handles to?"
3237 problem, what we'll do here is just uninsert the bp_finish, and
3238 let finish_command delete it.
3240 (We know the bp_finish is "doomed" in the sense that it's
3241 momentary, and will be deleted as soon as finish_command sees
3242 the inferior stopped. So it doesn't matter that the bp's
3243 address is probably bogus in the new a.out, unlike e.g., the
3244 solib breakpoints.) */
3246 if (b->type == bp_finish)
3251 /* Without a symbolic address, we have little hope of the
3252 pre-exec() address meaning the same thing in the post-exec()
3254 if (b->addr_string == NULL)
3256 delete_breakpoint (b);
3260 /* FIXME what about longjmp breakpoints? Re-create them here? */
3261 create_overlay_event_breakpoint ();
3262 create_longjmp_master_breakpoint ();
3263 create_std_terminate_master_breakpoint ();
3264 create_exception_master_breakpoint ();
3268 detach_breakpoints (int pid)
3270 struct bp_location *bl, **blp_tmp;
3272 struct cleanup *old_chain = save_inferior_ptid ();
3273 struct inferior *inf = current_inferior ();
3275 if (pid == PIDGET (inferior_ptid))
3276 error (_("Cannot detach breakpoints of inferior_ptid"));
3278 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3279 inferior_ptid = pid_to_ptid (pid);
3280 ALL_BP_LOCATIONS (bl, blp_tmp)
3282 if (bl->pspace != inf->pspace)
3286 val |= remove_breakpoint_1 (bl, mark_inserted);
3289 /* Detach single-step breakpoints as well. */
3290 detach_single_step_breakpoints ();
3292 do_cleanups (old_chain);
3296 /* Remove the breakpoint location BL from the current address space.
3297 Note that this is used to detach breakpoints from a child fork.
3298 When we get here, the child isn't in the inferior list, and neither
3299 do we have objects to represent its address space --- we should
3300 *not* look at bl->pspace->aspace here. */
3303 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
3307 /* BL is never in moribund_locations by our callers. */
3308 gdb_assert (bl->owner != NULL);
3310 if (bl->owner->enable_state == bp_permanent)
3311 /* Permanent breakpoints cannot be inserted or removed. */
3314 /* The type of none suggests that owner is actually deleted.
3315 This should not ever happen. */
3316 gdb_assert (bl->owner->type != bp_none);
3318 if (bl->loc_type == bp_loc_software_breakpoint
3319 || bl->loc_type == bp_loc_hardware_breakpoint)
3321 /* "Normal" instruction breakpoint: either the standard
3322 trap-instruction bp (bp_breakpoint), or a
3323 bp_hardware_breakpoint. */
3325 /* First check to see if we have to handle an overlay. */
3326 if (overlay_debugging == ovly_off
3327 || bl->section == NULL
3328 || !(section_is_overlay (bl->section)))
3330 /* No overlay handling: just remove the breakpoint. */
3331 val = bl->owner->ops->remove_location (bl);
3335 /* This breakpoint is in an overlay section.
3336 Did we set a breakpoint at the LMA? */
3337 if (!overlay_events_enabled)
3339 /* Yes -- overlay event support is not active, so we
3340 should have set a breakpoint at the LMA. Remove it.
3342 /* Ignore any failures: if the LMA is in ROM, we will
3343 have already warned when we failed to insert it. */
3344 if (bl->loc_type == bp_loc_hardware_breakpoint)
3345 target_remove_hw_breakpoint (bl->gdbarch,
3346 &bl->overlay_target_info);
3348 target_remove_breakpoint (bl->gdbarch,
3349 &bl->overlay_target_info);
3351 /* Did we set a breakpoint at the VMA?
3352 If so, we will have marked the breakpoint 'inserted'. */
3355 /* Yes -- remove it. Previously we did not bother to
3356 remove the breakpoint if the section had been
3357 unmapped, but let's not rely on that being safe. We
3358 don't know what the overlay manager might do. */
3360 /* However, we should remove *software* breakpoints only
3361 if the section is still mapped, or else we overwrite
3362 wrong code with the saved shadow contents. */
3363 if (bl->loc_type == bp_loc_hardware_breakpoint
3364 || section_is_mapped (bl->section))
3365 val = bl->owner->ops->remove_location (bl);
3371 /* No -- not inserted, so no need to remove. No error. */
3376 /* In some cases, we might not be able to remove a breakpoint
3377 in a shared library that has already been removed, but we
3378 have not yet processed the shlib unload event. */
3379 if (val && solib_name_from_address (bl->pspace, bl->address))
3384 bl->inserted = (is == mark_inserted);
3386 else if (bl->loc_type == bp_loc_hardware_watchpoint)
3388 gdb_assert (bl->owner->ops != NULL
3389 && bl->owner->ops->remove_location != NULL);
3391 bl->inserted = (is == mark_inserted);
3392 bl->owner->ops->remove_location (bl);
3394 /* Failure to remove any of the hardware watchpoints comes here. */
3395 if ((is == mark_uninserted) && (bl->inserted))
3396 warning (_("Could not remove hardware watchpoint %d."),
3399 else if (bl->owner->type == bp_catchpoint
3400 && breakpoint_enabled (bl->owner)
3403 gdb_assert (bl->owner->ops != NULL
3404 && bl->owner->ops->remove_location != NULL);
3406 val = bl->owner->ops->remove_location (bl);
3410 bl->inserted = (is == mark_inserted);
3417 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
3420 struct cleanup *old_chain;
3422 /* BL is never in moribund_locations by our callers. */
3423 gdb_assert (bl->owner != NULL);
3425 if (bl->owner->enable_state == bp_permanent)
3426 /* Permanent breakpoints cannot be inserted or removed. */
3429 /* The type of none suggests that owner is actually deleted.
3430 This should not ever happen. */
3431 gdb_assert (bl->owner->type != bp_none);
3433 old_chain = save_current_space_and_thread ();
3435 switch_to_program_space_and_thread (bl->pspace);
3437 ret = remove_breakpoint_1 (bl, is);
3439 do_cleanups (old_chain);
3443 /* Clear the "inserted" flag in all breakpoints. */
3446 mark_breakpoints_out (void)
3448 struct bp_location *bl, **blp_tmp;
3450 ALL_BP_LOCATIONS (bl, blp_tmp)
3451 if (bl->pspace == current_program_space)
3455 /* Clear the "inserted" flag in all breakpoints and delete any
3456 breakpoints which should go away between runs of the program.
3458 Plus other such housekeeping that has to be done for breakpoints
3461 Note: this function gets called at the end of a run (by
3462 generic_mourn_inferior) and when a run begins (by
3463 init_wait_for_inferior). */
3468 breakpoint_init_inferior (enum inf_context context)
3470 struct breakpoint *b, *b_tmp;
3471 struct bp_location *bl, **blp_tmp;
3473 struct program_space *pspace = current_program_space;
3475 /* If breakpoint locations are shared across processes, then there's
3477 if (gdbarch_has_global_breakpoints (target_gdbarch))
3480 ALL_BP_LOCATIONS (bl, blp_tmp)
3482 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3483 if (bl->pspace == pspace
3484 && bl->owner->enable_state != bp_permanent)
3488 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3490 if (b->loc && b->loc->pspace != pspace)
3496 case bp_longjmp_call_dummy:
3498 /* If the call dummy breakpoint is at the entry point it will
3499 cause problems when the inferior is rerun, so we better get
3502 case bp_watchpoint_scope:
3504 /* Also get rid of scope breakpoints. */
3506 case bp_shlib_event:
3508 /* Also remove solib event breakpoints. Their addresses may
3509 have changed since the last time we ran the program.
3510 Actually we may now be debugging against different target;
3511 and so the solib backend that installed this breakpoint may
3512 not be used in by the target. E.g.,
3514 (gdb) file prog-linux
3515 (gdb) run # native linux target
3518 (gdb) file prog-win.exe
3519 (gdb) tar rem :9999 # remote Windows gdbserver.
3522 case bp_step_resume:
3524 /* Also remove step-resume breakpoints. */
3526 delete_breakpoint (b);
3530 case bp_hardware_watchpoint:
3531 case bp_read_watchpoint:
3532 case bp_access_watchpoint:
3534 struct watchpoint *w = (struct watchpoint *) b;
3536 /* Likewise for watchpoints on local expressions. */
3537 if (w->exp_valid_block != NULL)
3538 delete_breakpoint (b);
3539 else if (context == inf_starting)
3541 /* Reset val field to force reread of starting value in
3542 insert_breakpoints. */
3544 value_free (w->val);
3555 /* Get rid of the moribund locations. */
3556 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
3557 decref_bp_location (&bl);
3558 VEC_free (bp_location_p, moribund_locations);
3561 /* These functions concern about actual breakpoints inserted in the
3562 target --- to e.g. check if we need to do decr_pc adjustment or if
3563 we need to hop over the bkpt --- so we check for address space
3564 match, not program space. */
3566 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3567 exists at PC. It returns ordinary_breakpoint_here if it's an
3568 ordinary breakpoint, or permanent_breakpoint_here if it's a
3569 permanent breakpoint.
3570 - When continuing from a location with an ordinary breakpoint, we
3571 actually single step once before calling insert_breakpoints.
3572 - When continuing from a location with a permanent breakpoint, we
3573 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3574 the target, to advance the PC past the breakpoint. */
3576 enum breakpoint_here
3577 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
3579 struct bp_location *bl, **blp_tmp;
3580 int any_breakpoint_here = 0;
3582 ALL_BP_LOCATIONS (bl, blp_tmp)
3584 if (bl->loc_type != bp_loc_software_breakpoint
3585 && bl->loc_type != bp_loc_hardware_breakpoint)
3588 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3589 if ((breakpoint_enabled (bl->owner)
3590 || bl->owner->enable_state == bp_permanent)
3591 && breakpoint_location_address_match (bl, aspace, pc))
3593 if (overlay_debugging
3594 && section_is_overlay (bl->section)
3595 && !section_is_mapped (bl->section))
3596 continue; /* unmapped overlay -- can't be a match */
3597 else if (bl->owner->enable_state == bp_permanent)
3598 return permanent_breakpoint_here;
3600 any_breakpoint_here = 1;
3604 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
3607 /* Return true if there's a moribund breakpoint at PC. */
3610 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
3612 struct bp_location *loc;
3615 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
3616 if (breakpoint_location_address_match (loc, aspace, pc))
3622 /* Returns non-zero if there's a breakpoint inserted at PC, which is
3623 inserted using regular breakpoint_chain / bp_location array
3624 mechanism. This does not check for single-step breakpoints, which
3625 are inserted and removed using direct target manipulation. */
3628 regular_breakpoint_inserted_here_p (struct address_space *aspace,
3631 struct bp_location *bl, **blp_tmp;
3633 ALL_BP_LOCATIONS (bl, blp_tmp)
3635 if (bl->loc_type != bp_loc_software_breakpoint
3636 && bl->loc_type != bp_loc_hardware_breakpoint)
3640 && breakpoint_location_address_match (bl, aspace, pc))
3642 if (overlay_debugging
3643 && section_is_overlay (bl->section)
3644 && !section_is_mapped (bl->section))
3645 continue; /* unmapped overlay -- can't be a match */
3653 /* Returns non-zero iff there's either regular breakpoint
3654 or a single step breakpoint inserted at PC. */
3657 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
3659 if (regular_breakpoint_inserted_here_p (aspace, pc))
3662 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3668 /* This function returns non-zero iff there is a software breakpoint
3672 software_breakpoint_inserted_here_p (struct address_space *aspace,
3675 struct bp_location *bl, **blp_tmp;
3677 ALL_BP_LOCATIONS (bl, blp_tmp)
3679 if (bl->loc_type != bp_loc_software_breakpoint)
3683 && breakpoint_address_match (bl->pspace->aspace, bl->address,
3686 if (overlay_debugging
3687 && section_is_overlay (bl->section)
3688 && !section_is_mapped (bl->section))
3689 continue; /* unmapped overlay -- can't be a match */
3695 /* Also check for software single-step breakpoints. */
3696 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3703 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
3704 CORE_ADDR addr, ULONGEST len)
3706 struct breakpoint *bpt;
3708 ALL_BREAKPOINTS (bpt)
3710 struct bp_location *loc;
3712 if (bpt->type != bp_hardware_watchpoint
3713 && bpt->type != bp_access_watchpoint)
3716 if (!breakpoint_enabled (bpt))
3719 for (loc = bpt->loc; loc; loc = loc->next)
3720 if (loc->pspace->aspace == aspace && loc->inserted)
3724 /* Check for intersection. */
3725 l = max (loc->address, addr);
3726 h = min (loc->address + loc->length, addr + len);
3734 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3735 PC is valid for process/thread PTID. */
3738 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
3741 struct bp_location *bl, **blp_tmp;
3742 /* The thread and task IDs associated to PTID, computed lazily. */
3746 ALL_BP_LOCATIONS (bl, blp_tmp)
3748 if (bl->loc_type != bp_loc_software_breakpoint
3749 && bl->loc_type != bp_loc_hardware_breakpoint)
3752 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3753 if (!breakpoint_enabled (bl->owner)
3754 && bl->owner->enable_state != bp_permanent)
3757 if (!breakpoint_location_address_match (bl, aspace, pc))
3760 if (bl->owner->thread != -1)
3762 /* This is a thread-specific breakpoint. Check that ptid
3763 matches that thread. If thread hasn't been computed yet,
3764 it is now time to do so. */
3766 thread = pid_to_thread_id (ptid);
3767 if (bl->owner->thread != thread)
3771 if (bl->owner->task != 0)
3773 /* This is a task-specific breakpoint. Check that ptid
3774 matches that task. If task hasn't been computed yet,
3775 it is now time to do so. */
3777 task = ada_get_task_number (ptid);
3778 if (bl->owner->task != task)
3782 if (overlay_debugging
3783 && section_is_overlay (bl->section)
3784 && !section_is_mapped (bl->section))
3785 continue; /* unmapped overlay -- can't be a match */
3794 /* bpstat stuff. External routines' interfaces are documented
3798 is_catchpoint (struct breakpoint *ep)
3800 return (ep->type == bp_catchpoint);
3803 /* Frees any storage that is part of a bpstat. Does not walk the
3807 bpstat_free (bpstat bs)
3809 if (bs->old_val != NULL)
3810 value_free (bs->old_val);
3811 decref_counted_command_line (&bs->commands);
3812 decref_bp_location (&bs->bp_location_at);
3816 /* Clear a bpstat so that it says we are not at any breakpoint.
3817 Also free any storage that is part of a bpstat. */
3820 bpstat_clear (bpstat *bsp)
3837 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3838 is part of the bpstat is copied as well. */
3841 bpstat_copy (bpstat bs)
3845 bpstat retval = NULL;
3850 for (; bs != NULL; bs = bs->next)
3852 tmp = (bpstat) xmalloc (sizeof (*tmp));
3853 memcpy (tmp, bs, sizeof (*tmp));
3854 incref_counted_command_line (tmp->commands);
3855 incref_bp_location (tmp->bp_location_at);
3856 if (bs->old_val != NULL)
3858 tmp->old_val = value_copy (bs->old_val);
3859 release_value (tmp->old_val);
3863 /* This is the first thing in the chain. */
3873 /* Find the bpstat associated with this breakpoint. */
3876 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
3881 for (; bsp != NULL; bsp = bsp->next)
3883 if (bsp->breakpoint_at == breakpoint)
3889 /* Put in *NUM the breakpoint number of the first breakpoint we are
3890 stopped at. *BSP upon return is a bpstat which points to the
3891 remaining breakpoints stopped at (but which is not guaranteed to be
3892 good for anything but further calls to bpstat_num).
3894 Return 0 if passed a bpstat which does not indicate any breakpoints.
3895 Return -1 if stopped at a breakpoint that has been deleted since
3897 Return 1 otherwise. */
3900 bpstat_num (bpstat *bsp, int *num)
3902 struct breakpoint *b;
3905 return 0; /* No more breakpoint values */
3907 /* We assume we'll never have several bpstats that correspond to a
3908 single breakpoint -- otherwise, this function might return the
3909 same number more than once and this will look ugly. */
3910 b = (*bsp)->breakpoint_at;
3911 *bsp = (*bsp)->next;
3913 return -1; /* breakpoint that's been deleted since */
3915 *num = b->number; /* We have its number */
3919 /* See breakpoint.h. */
3922 bpstat_clear_actions (void)
3924 struct thread_info *tp;
3927 if (ptid_equal (inferior_ptid, null_ptid))
3930 tp = find_thread_ptid (inferior_ptid);
3934 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
3936 decref_counted_command_line (&bs->commands);
3938 if (bs->old_val != NULL)
3940 value_free (bs->old_val);
3946 /* Called when a command is about to proceed the inferior. */
3949 breakpoint_about_to_proceed (void)
3951 if (!ptid_equal (inferior_ptid, null_ptid))
3953 struct thread_info *tp = inferior_thread ();
3955 /* Allow inferior function calls in breakpoint commands to not
3956 interrupt the command list. When the call finishes
3957 successfully, the inferior will be standing at the same
3958 breakpoint as if nothing happened. */
3959 if (tp->control.in_infcall)
3963 breakpoint_proceeded = 1;
3966 /* Stub for cleaning up our state if we error-out of a breakpoint
3969 cleanup_executing_breakpoints (void *ignore)
3971 executing_breakpoint_commands = 0;
3974 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3975 or its equivalent. */
3978 command_line_is_silent (struct command_line *cmd)
3980 return cmd && (strcmp ("silent", cmd->line) == 0
3981 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
3984 /* Execute all the commands associated with all the breakpoints at
3985 this location. Any of these commands could cause the process to
3986 proceed beyond this point, etc. We look out for such changes by
3987 checking the global "breakpoint_proceeded" after each command.
3989 Returns true if a breakpoint command resumed the inferior. In that
3990 case, it is the caller's responsibility to recall it again with the
3991 bpstat of the current thread. */
3994 bpstat_do_actions_1 (bpstat *bsp)
3997 struct cleanup *old_chain;
4000 /* Avoid endless recursion if a `source' command is contained
4002 if (executing_breakpoint_commands)
4005 executing_breakpoint_commands = 1;
4006 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
4008 prevent_dont_repeat ();
4010 /* This pointer will iterate over the list of bpstat's. */
4013 breakpoint_proceeded = 0;
4014 for (; bs != NULL; bs = bs->next)
4016 struct counted_command_line *ccmd;
4017 struct command_line *cmd;
4018 struct cleanup *this_cmd_tree_chain;
4020 /* Take ownership of the BSP's command tree, if it has one.
4022 The command tree could legitimately contain commands like
4023 'step' and 'next', which call clear_proceed_status, which
4024 frees stop_bpstat's command tree. To make sure this doesn't
4025 free the tree we're executing out from under us, we need to
4026 take ownership of the tree ourselves. Since a given bpstat's
4027 commands are only executed once, we don't need to copy it; we
4028 can clear the pointer in the bpstat, and make sure we free
4029 the tree when we're done. */
4030 ccmd = bs->commands;
4031 bs->commands = NULL;
4032 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
4033 cmd = ccmd ? ccmd->commands : NULL;
4034 if (command_line_is_silent (cmd))
4036 /* The action has been already done by bpstat_stop_status. */
4042 execute_control_command (cmd);
4044 if (breakpoint_proceeded)
4050 /* We can free this command tree now. */
4051 do_cleanups (this_cmd_tree_chain);
4053 if (breakpoint_proceeded)
4055 if (target_can_async_p ())
4056 /* If we are in async mode, then the target might be still
4057 running, not stopped at any breakpoint, so nothing for
4058 us to do here -- just return to the event loop. */
4061 /* In sync mode, when execute_control_command returns
4062 we're already standing on the next breakpoint.
4063 Breakpoint commands for that stop were not run, since
4064 execute_command does not run breakpoint commands --
4065 only command_line_handler does, but that one is not
4066 involved in execution of breakpoint commands. So, we
4067 can now execute breakpoint commands. It should be
4068 noted that making execute_command do bpstat actions is
4069 not an option -- in this case we'll have recursive
4070 invocation of bpstat for each breakpoint with a
4071 command, and can easily blow up GDB stack. Instead, we
4072 return true, which will trigger the caller to recall us
4073 with the new stop_bpstat. */
4078 do_cleanups (old_chain);
4083 bpstat_do_actions (void)
4085 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4087 /* Do any commands attached to breakpoint we are stopped at. */
4088 while (!ptid_equal (inferior_ptid, null_ptid)
4089 && target_has_execution
4090 && !is_exited (inferior_ptid)
4091 && !is_executing (inferior_ptid))
4092 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4093 and only return when it is stopped at the next breakpoint, we
4094 keep doing breakpoint actions until it returns false to
4095 indicate the inferior was not resumed. */
4096 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
4099 discard_cleanups (cleanup_if_error);
4102 /* Print out the (old or new) value associated with a watchpoint. */
4105 watchpoint_value_print (struct value *val, struct ui_file *stream)
4108 fprintf_unfiltered (stream, _("<unreadable>"));
4111 struct value_print_options opts;
4112 get_user_print_options (&opts);
4113 value_print (val, stream, &opts);
4117 /* Generic routine for printing messages indicating why we
4118 stopped. The behavior of this function depends on the value
4119 'print_it' in the bpstat structure. Under some circumstances we
4120 may decide not to print anything here and delegate the task to
4123 static enum print_stop_action
4124 print_bp_stop_message (bpstat bs)
4126 switch (bs->print_it)
4129 /* Nothing should be printed for this bpstat entry. */
4130 return PRINT_UNKNOWN;
4134 /* We still want to print the frame, but we already printed the
4135 relevant messages. */
4136 return PRINT_SRC_AND_LOC;
4139 case print_it_normal:
4141 struct breakpoint *b = bs->breakpoint_at;
4143 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4144 which has since been deleted. */
4146 return PRINT_UNKNOWN;
4148 /* Normal case. Call the breakpoint's print_it method. */
4149 return b->ops->print_it (bs);
4154 internal_error (__FILE__, __LINE__,
4155 _("print_bp_stop_message: unrecognized enum value"));
4160 /* A helper function that prints a shared library stopped event. */
4163 print_solib_event (int is_catchpoint)
4166 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4168 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4172 if (any_added || any_deleted)
4173 ui_out_text (current_uiout,
4174 _("Stopped due to shared library event:\n"));
4176 ui_out_text (current_uiout,
4177 _("Stopped due to shared library event (no "
4178 "libraries added or removed)\n"));
4181 if (ui_out_is_mi_like_p (current_uiout))
4182 ui_out_field_string (current_uiout, "reason",
4183 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4187 struct cleanup *cleanup;
4191 ui_out_text (current_uiout, _(" Inferior unloaded "));
4192 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4195 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4200 ui_out_text (current_uiout, " ");
4201 ui_out_field_string (current_uiout, "library", name);
4202 ui_out_text (current_uiout, "\n");
4205 do_cleanups (cleanup);
4210 struct so_list *iter;
4212 struct cleanup *cleanup;
4214 ui_out_text (current_uiout, _(" Inferior loaded "));
4215 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4218 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4223 ui_out_text (current_uiout, " ");
4224 ui_out_field_string (current_uiout, "library", iter->so_name);
4225 ui_out_text (current_uiout, "\n");
4228 do_cleanups (cleanup);
4232 /* Print a message indicating what happened. This is called from
4233 normal_stop(). The input to this routine is the head of the bpstat
4234 list - a list of the eventpoints that caused this stop. KIND is
4235 the target_waitkind for the stopping event. This
4236 routine calls the generic print routine for printing a message
4237 about reasons for stopping. This will print (for example) the
4238 "Breakpoint n," part of the output. The return value of this
4241 PRINT_UNKNOWN: Means we printed nothing.
4242 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4243 code to print the location. An example is
4244 "Breakpoint 1, " which should be followed by
4246 PRINT_SRC_ONLY: Means we printed something, but there is no need
4247 to also print the location part of the message.
4248 An example is the catch/throw messages, which
4249 don't require a location appended to the end.
4250 PRINT_NOTHING: We have done some printing and we don't need any
4251 further info to be printed. */
4253 enum print_stop_action
4254 bpstat_print (bpstat bs, int kind)
4258 /* Maybe another breakpoint in the chain caused us to stop.
4259 (Currently all watchpoints go on the bpstat whether hit or not.
4260 That probably could (should) be changed, provided care is taken
4261 with respect to bpstat_explains_signal). */
4262 for (; bs; bs = bs->next)
4264 val = print_bp_stop_message (bs);
4265 if (val == PRINT_SRC_ONLY
4266 || val == PRINT_SRC_AND_LOC
4267 || val == PRINT_NOTHING)
4271 /* If we had hit a shared library event breakpoint,
4272 print_bp_stop_message would print out this message. If we hit an
4273 OS-level shared library event, do the same thing. */
4274 if (kind == TARGET_WAITKIND_LOADED)
4276 print_solib_event (0);
4277 return PRINT_NOTHING;
4280 /* We reached the end of the chain, or we got a null BS to start
4281 with and nothing was printed. */
4282 return PRINT_UNKNOWN;
4285 /* Evaluate the expression EXP and return 1 if value is zero. This is
4286 used inside a catch_errors to evaluate the breakpoint condition.
4287 The argument is a "struct expression *" that has been cast to a
4288 "char *" to make it pass through catch_errors. */
4291 breakpoint_cond_eval (void *exp)
4293 struct value *mark = value_mark ();
4294 int i = !value_true (evaluate_expression ((struct expression *) exp));
4296 value_free_to_mark (mark);
4300 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4303 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
4307 bs = (bpstat) xmalloc (sizeof (*bs));
4309 **bs_link_pointer = bs;
4310 *bs_link_pointer = &bs->next;
4311 bs->breakpoint_at = bl->owner;
4312 bs->bp_location_at = bl;
4313 incref_bp_location (bl);
4314 /* If the condition is false, etc., don't do the commands. */
4315 bs->commands = NULL;
4317 bs->print_it = print_it_normal;
4321 /* The target has stopped with waitstatus WS. Check if any hardware
4322 watchpoints have triggered, according to the target. */
4325 watchpoints_triggered (struct target_waitstatus *ws)
4327 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
4329 struct breakpoint *b;
4331 if (!stopped_by_watchpoint)
4333 /* We were not stopped by a watchpoint. Mark all watchpoints
4334 as not triggered. */
4336 if (is_hardware_watchpoint (b))
4338 struct watchpoint *w = (struct watchpoint *) b;
4340 w->watchpoint_triggered = watch_triggered_no;
4346 if (!target_stopped_data_address (¤t_target, &addr))
4348 /* We were stopped by a watchpoint, but we don't know where.
4349 Mark all watchpoints as unknown. */
4351 if (is_hardware_watchpoint (b))
4353 struct watchpoint *w = (struct watchpoint *) b;
4355 w->watchpoint_triggered = watch_triggered_unknown;
4358 return stopped_by_watchpoint;
4361 /* The target could report the data address. Mark watchpoints
4362 affected by this data address as triggered, and all others as not
4366 if (is_hardware_watchpoint (b))
4368 struct watchpoint *w = (struct watchpoint *) b;
4369 struct bp_location *loc;
4371 w->watchpoint_triggered = watch_triggered_no;
4372 for (loc = b->loc; loc; loc = loc->next)
4374 if (is_masked_watchpoint (b))
4376 CORE_ADDR newaddr = addr & w->hw_wp_mask;
4377 CORE_ADDR start = loc->address & w->hw_wp_mask;
4379 if (newaddr == start)
4381 w->watchpoint_triggered = watch_triggered_yes;
4385 /* Exact match not required. Within range is sufficient. */
4386 else if (target_watchpoint_addr_within_range (¤t_target,
4390 w->watchpoint_triggered = watch_triggered_yes;
4399 /* Possible return values for watchpoint_check (this can't be an enum
4400 because of check_errors). */
4401 /* The watchpoint has been deleted. */
4402 #define WP_DELETED 1
4403 /* The value has changed. */
4404 #define WP_VALUE_CHANGED 2
4405 /* The value has not changed. */
4406 #define WP_VALUE_NOT_CHANGED 3
4407 /* Ignore this watchpoint, no matter if the value changed or not. */
4410 #define BP_TEMPFLAG 1
4411 #define BP_HARDWAREFLAG 2
4413 /* Evaluate watchpoint condition expression and check if its value
4416 P should be a pointer to struct bpstat, but is defined as a void *
4417 in order for this function to be usable with catch_errors. */
4420 watchpoint_check (void *p)
4422 bpstat bs = (bpstat) p;
4423 struct watchpoint *b;
4424 struct frame_info *fr;
4425 int within_current_scope;
4427 /* BS is built from an existing struct breakpoint. */
4428 gdb_assert (bs->breakpoint_at != NULL);
4429 b = (struct watchpoint *) bs->breakpoint_at;
4431 /* If this is a local watchpoint, we only want to check if the
4432 watchpoint frame is in scope if the current thread is the thread
4433 that was used to create the watchpoint. */
4434 if (!watchpoint_in_thread_scope (b))
4437 if (b->exp_valid_block == NULL)
4438 within_current_scope = 1;
4441 struct frame_info *frame = get_current_frame ();
4442 struct gdbarch *frame_arch = get_frame_arch (frame);
4443 CORE_ADDR frame_pc = get_frame_pc (frame);
4445 /* in_function_epilogue_p() returns a non-zero value if we're
4446 still in the function but the stack frame has already been
4447 invalidated. Since we can't rely on the values of local
4448 variables after the stack has been destroyed, we are treating
4449 the watchpoint in that state as `not changed' without further
4450 checking. Don't mark watchpoints as changed if the current
4451 frame is in an epilogue - even if they are in some other
4452 frame, our view of the stack is likely to be wrong and
4453 frame_find_by_id could error out. */
4454 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
4457 fr = frame_find_by_id (b->watchpoint_frame);
4458 within_current_scope = (fr != NULL);
4460 /* If we've gotten confused in the unwinder, we might have
4461 returned a frame that can't describe this variable. */
4462 if (within_current_scope)
4464 struct symbol *function;
4466 function = get_frame_function (fr);
4467 if (function == NULL
4468 || !contained_in (b->exp_valid_block,
4469 SYMBOL_BLOCK_VALUE (function)))
4470 within_current_scope = 0;
4473 if (within_current_scope)
4474 /* If we end up stopping, the current frame will get selected
4475 in normal_stop. So this call to select_frame won't affect
4480 if (within_current_scope)
4482 /* We use value_{,free_to_}mark because it could be a *long*
4483 time before we return to the command level and call
4484 free_all_values. We can't call free_all_values because we
4485 might be in the middle of evaluating a function call. */
4489 struct value *new_val;
4491 if (is_masked_watchpoint (&b->base))
4492 /* Since we don't know the exact trigger address (from
4493 stopped_data_address), just tell the user we've triggered
4494 a mask watchpoint. */
4495 return WP_VALUE_CHANGED;
4497 mark = value_mark ();
4498 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
4500 /* We use value_equal_contents instead of value_equal because
4501 the latter coerces an array to a pointer, thus comparing just
4502 the address of the array instead of its contents. This is
4503 not what we want. */
4504 if ((b->val != NULL) != (new_val != NULL)
4505 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
4507 if (new_val != NULL)
4509 release_value (new_val);
4510 value_free_to_mark (mark);
4512 bs->old_val = b->val;
4515 return WP_VALUE_CHANGED;
4519 /* Nothing changed. */
4520 value_free_to_mark (mark);
4521 return WP_VALUE_NOT_CHANGED;
4526 struct ui_out *uiout = current_uiout;
4528 /* This seems like the only logical thing to do because
4529 if we temporarily ignored the watchpoint, then when
4530 we reenter the block in which it is valid it contains
4531 garbage (in the case of a function, it may have two
4532 garbage values, one before and one after the prologue).
4533 So we can't even detect the first assignment to it and
4534 watch after that (since the garbage may or may not equal
4535 the first value assigned). */
4536 /* We print all the stop information in
4537 breakpoint_ops->print_it, but in this case, by the time we
4538 call breakpoint_ops->print_it this bp will be deleted
4539 already. So we have no choice but print the information
4541 if (ui_out_is_mi_like_p (uiout))
4543 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
4544 ui_out_text (uiout, "\nWatchpoint ");
4545 ui_out_field_int (uiout, "wpnum", b->base.number);
4547 " deleted because the program has left the block in\n\
4548 which its expression is valid.\n");
4550 /* Make sure the watchpoint's commands aren't executed. */
4551 decref_counted_command_line (&b->base.commands);
4552 watchpoint_del_at_next_stop (b);
4558 /* Return true if it looks like target has stopped due to hitting
4559 breakpoint location BL. This function does not check if we should
4560 stop, only if BL explains the stop. */
4563 bpstat_check_location (const struct bp_location *bl,
4564 struct address_space *aspace, CORE_ADDR bp_addr,
4565 const struct target_waitstatus *ws)
4567 struct breakpoint *b = bl->owner;
4569 /* BL is from an existing breakpoint. */
4570 gdb_assert (b != NULL);
4572 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
4575 /* Determine if the watched values have actually changed, and we
4576 should stop. If not, set BS->stop to 0. */
4579 bpstat_check_watchpoint (bpstat bs)
4581 const struct bp_location *bl;
4582 struct watchpoint *b;
4584 /* BS is built for existing struct breakpoint. */
4585 bl = bs->bp_location_at;
4586 gdb_assert (bl != NULL);
4587 b = (struct watchpoint *) bs->breakpoint_at;
4588 gdb_assert (b != NULL);
4591 int must_check_value = 0;
4593 if (b->base.type == bp_watchpoint)
4594 /* For a software watchpoint, we must always check the
4596 must_check_value = 1;
4597 else if (b->watchpoint_triggered == watch_triggered_yes)
4598 /* We have a hardware watchpoint (read, write, or access)
4599 and the target earlier reported an address watched by
4601 must_check_value = 1;
4602 else if (b->watchpoint_triggered == watch_triggered_unknown
4603 && b->base.type == bp_hardware_watchpoint)
4604 /* We were stopped by a hardware watchpoint, but the target could
4605 not report the data address. We must check the watchpoint's
4606 value. Access and read watchpoints are out of luck; without
4607 a data address, we can't figure it out. */
4608 must_check_value = 1;
4610 if (must_check_value)
4613 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4615 struct cleanup *cleanups = make_cleanup (xfree, message);
4616 int e = catch_errors (watchpoint_check, bs, message,
4618 do_cleanups (cleanups);
4622 /* We've already printed what needs to be printed. */
4623 bs->print_it = print_it_done;
4627 bs->print_it = print_it_noop;
4630 case WP_VALUE_CHANGED:
4631 if (b->base.type == bp_read_watchpoint)
4633 /* There are two cases to consider here:
4635 1. We're watching the triggered memory for reads.
4636 In that case, trust the target, and always report
4637 the watchpoint hit to the user. Even though
4638 reads don't cause value changes, the value may
4639 have changed since the last time it was read, and
4640 since we're not trapping writes, we will not see
4641 those, and as such we should ignore our notion of
4644 2. We're watching the triggered memory for both
4645 reads and writes. There are two ways this may
4648 2.1. This is a target that can't break on data
4649 reads only, but can break on accesses (reads or
4650 writes), such as e.g., x86. We detect this case
4651 at the time we try to insert read watchpoints.
4653 2.2. Otherwise, the target supports read
4654 watchpoints, but, the user set an access or write
4655 watchpoint watching the same memory as this read
4658 If we're watching memory writes as well as reads,
4659 ignore watchpoint hits when we find that the
4660 value hasn't changed, as reads don't cause
4661 changes. This still gives false positives when
4662 the program writes the same value to memory as
4663 what there was already in memory (we will confuse
4664 it for a read), but it's much better than
4667 int other_write_watchpoint = 0;
4669 if (bl->watchpoint_type == hw_read)
4671 struct breakpoint *other_b;
4673 ALL_BREAKPOINTS (other_b)
4674 if (other_b->type == bp_hardware_watchpoint
4675 || other_b->type == bp_access_watchpoint)
4677 struct watchpoint *other_w =
4678 (struct watchpoint *) other_b;
4680 if (other_w->watchpoint_triggered
4681 == watch_triggered_yes)
4683 other_write_watchpoint = 1;
4689 if (other_write_watchpoint
4690 || bl->watchpoint_type == hw_access)
4692 /* We're watching the same memory for writes,
4693 and the value changed since the last time we
4694 updated it, so this trap must be for a write.
4696 bs->print_it = print_it_noop;
4701 case WP_VALUE_NOT_CHANGED:
4702 if (b->base.type == bp_hardware_watchpoint
4703 || b->base.type == bp_watchpoint)
4705 /* Don't stop: write watchpoints shouldn't fire if
4706 the value hasn't changed. */
4707 bs->print_it = print_it_noop;
4715 /* Error from catch_errors. */
4716 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
4717 watchpoint_del_at_next_stop (b);
4718 /* We've already printed what needs to be printed. */
4719 bs->print_it = print_it_done;
4723 else /* must_check_value == 0 */
4725 /* This is a case where some watchpoint(s) triggered, but
4726 not at the address of this watchpoint, or else no
4727 watchpoint triggered after all. So don't print
4728 anything for this watchpoint. */
4729 bs->print_it = print_it_noop;
4736 /* Check conditions (condition proper, frame, thread and ignore count)
4737 of breakpoint referred to by BS. If we should not stop for this
4738 breakpoint, set BS->stop to 0. */
4741 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
4743 int thread_id = pid_to_thread_id (ptid);
4744 const struct bp_location *bl;
4745 struct breakpoint *b;
4747 /* BS is built for existing struct breakpoint. */
4748 bl = bs->bp_location_at;
4749 gdb_assert (bl != NULL);
4750 b = bs->breakpoint_at;
4751 gdb_assert (b != NULL);
4753 /* Even if the target evaluated the condition on its end and notified GDB, we
4754 need to do so again since GDB does not know if we stopped due to a
4755 breakpoint or a single step breakpoint. */
4757 if (frame_id_p (b->frame_id)
4758 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
4762 int value_is_zero = 0;
4763 struct expression *cond;
4765 /* Evaluate Python breakpoints that have a "stop"
4766 method implemented. */
4767 if (b->py_bp_object)
4768 bs->stop = gdbpy_should_stop (b->py_bp_object);
4770 if (is_watchpoint (b))
4772 struct watchpoint *w = (struct watchpoint *) b;
4779 if (cond && b->disposition != disp_del_at_next_stop)
4781 int within_current_scope = 1;
4782 struct watchpoint * w;
4784 /* We use value_mark and value_free_to_mark because it could
4785 be a long time before we return to the command level and
4786 call free_all_values. We can't call free_all_values
4787 because we might be in the middle of evaluating a
4789 struct value *mark = value_mark ();
4791 if (is_watchpoint (b))
4792 w = (struct watchpoint *) b;
4796 /* Need to select the frame, with all that implies so that
4797 the conditions will have the right context. Because we
4798 use the frame, we will not see an inlined function's
4799 variables when we arrive at a breakpoint at the start
4800 of the inlined function; the current frame will be the
4802 if (w == NULL || w->cond_exp_valid_block == NULL)
4803 select_frame (get_current_frame ());
4806 struct frame_info *frame;
4808 /* For local watchpoint expressions, which particular
4809 instance of a local is being watched matters, so we
4810 keep track of the frame to evaluate the expression
4811 in. To evaluate the condition however, it doesn't
4812 really matter which instantiation of the function
4813 where the condition makes sense triggers the
4814 watchpoint. This allows an expression like "watch
4815 global if q > 10" set in `func', catch writes to
4816 global on all threads that call `func', or catch
4817 writes on all recursive calls of `func' by a single
4818 thread. We simply always evaluate the condition in
4819 the innermost frame that's executing where it makes
4820 sense to evaluate the condition. It seems
4822 frame = block_innermost_frame (w->cond_exp_valid_block);
4824 select_frame (frame);
4826 within_current_scope = 0;
4828 if (within_current_scope)
4830 = catch_errors (breakpoint_cond_eval, cond,
4831 "Error in testing breakpoint condition:\n",
4835 warning (_("Watchpoint condition cannot be tested "
4836 "in the current scope"));
4837 /* If we failed to set the right context for this
4838 watchpoint, unconditionally report it. */
4841 /* FIXME-someday, should give breakpoint #. */
4842 value_free_to_mark (mark);
4845 if (cond && value_is_zero)
4849 else if (b->thread != -1 && b->thread != thread_id)
4853 else if (b->ignore_count > 0)
4856 annotate_ignore_count_change ();
4858 /* Increase the hit count even though we don't stop. */
4860 observer_notify_breakpoint_modified (b);
4866 /* Get a bpstat associated with having just stopped at address
4867 BP_ADDR in thread PTID.
4869 Determine whether we stopped at a breakpoint, etc, or whether we
4870 don't understand this stop. Result is a chain of bpstat's such
4873 if we don't understand the stop, the result is a null pointer.
4875 if we understand why we stopped, the result is not null.
4877 Each element of the chain refers to a particular breakpoint or
4878 watchpoint at which we have stopped. (We may have stopped for
4879 several reasons concurrently.)
4881 Each element of the chain has valid next, breakpoint_at,
4882 commands, FIXME??? fields. */
4885 bpstat_stop_status (struct address_space *aspace,
4886 CORE_ADDR bp_addr, ptid_t ptid,
4887 const struct target_waitstatus *ws)
4889 struct breakpoint *b = NULL;
4890 struct bp_location *bl;
4891 struct bp_location *loc;
4892 /* First item of allocated bpstat's. */
4893 bpstat bs_head = NULL, *bs_link = &bs_head;
4894 /* Pointer to the last thing in the chain currently. */
4897 int need_remove_insert;
4900 /* First, build the bpstat chain with locations that explain a
4901 target stop, while being careful to not set the target running,
4902 as that may invalidate locations (in particular watchpoint
4903 locations are recreated). Resuming will happen here with
4904 breakpoint conditions or watchpoint expressions that include
4905 inferior function calls. */
4909 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
4912 for (bl = b->loc; bl != NULL; bl = bl->next)
4914 /* For hardware watchpoints, we look only at the first
4915 location. The watchpoint_check function will work on the
4916 entire expression, not the individual locations. For
4917 read watchpoints, the watchpoints_triggered function has
4918 checked all locations already. */
4919 if (b->type == bp_hardware_watchpoint && bl != b->loc)
4922 if (bl->shlib_disabled)
4925 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
4928 /* Come here if it's a watchpoint, or if the break address
4931 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
4934 /* Assume we stop. Should we find a watchpoint that is not
4935 actually triggered, or if the condition of the breakpoint
4936 evaluates as false, we'll reset 'stop' to 0. */
4940 /* If this is a scope breakpoint, mark the associated
4941 watchpoint as triggered so that we will handle the
4942 out-of-scope event. We'll get to the watchpoint next
4944 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
4946 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
4948 w->watchpoint_triggered = watch_triggered_yes;
4953 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4955 if (breakpoint_location_address_match (loc, aspace, bp_addr))
4957 bs = bpstat_alloc (loc, &bs_link);
4958 /* For hits of moribund locations, we should just proceed. */
4961 bs->print_it = print_it_noop;
4965 /* A bit of special processing for shlib breakpoints. We need to
4966 process solib loading here, so that the lists of loaded and
4967 unloaded libraries are correct before we handle "catch load" and
4969 for (bs = bs_head; bs != NULL; bs = bs->next)
4971 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
4973 handle_solib_event ();
4978 /* Now go through the locations that caused the target to stop, and
4979 check whether we're interested in reporting this stop to higher
4980 layers, or whether we should resume the target transparently. */
4984 for (bs = bs_head; bs != NULL; bs = bs->next)
4989 b = bs->breakpoint_at;
4990 b->ops->check_status (bs);
4993 bpstat_check_breakpoint_conditions (bs, ptid);
4998 observer_notify_breakpoint_modified (b);
5000 /* We will stop here. */
5001 if (b->disposition == disp_disable)
5003 --(b->enable_count);
5004 if (b->enable_count <= 0
5005 && b->enable_state != bp_permanent)
5006 b->enable_state = bp_disabled;
5011 bs->commands = b->commands;
5012 incref_counted_command_line (bs->commands);
5013 if (command_line_is_silent (bs->commands
5014 ? bs->commands->commands : NULL))
5020 /* Print nothing for this entry if we don't stop or don't
5022 if (!bs->stop || !bs->print)
5023 bs->print_it = print_it_noop;
5026 /* If we aren't stopping, the value of some hardware watchpoint may
5027 not have changed, but the intermediate memory locations we are
5028 watching may have. Don't bother if we're stopping; this will get
5030 need_remove_insert = 0;
5031 if (! bpstat_causes_stop (bs_head))
5032 for (bs = bs_head; bs != NULL; bs = bs->next)
5034 && bs->breakpoint_at
5035 && is_hardware_watchpoint (bs->breakpoint_at))
5037 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5039 update_watchpoint (w, 0 /* don't reparse. */);
5040 need_remove_insert = 1;
5043 if (need_remove_insert)
5044 update_global_location_list (1);
5045 else if (removed_any)
5046 update_global_location_list (0);
5052 handle_jit_event (void)
5054 struct frame_info *frame;
5055 struct gdbarch *gdbarch;
5057 /* Switch terminal for any messages produced by
5058 breakpoint_re_set. */
5059 target_terminal_ours_for_output ();
5061 frame = get_current_frame ();
5062 gdbarch = get_frame_arch (frame);
5064 jit_event_handler (gdbarch);
5066 target_terminal_inferior ();
5069 /* Handle an solib event by calling solib_add. */
5072 handle_solib_event (void)
5074 clear_program_space_solib_cache (current_inferior ()->pspace);
5076 /* Check for any newly added shared libraries if we're supposed to
5077 be adding them automatically. Switch terminal for any messages
5078 produced by breakpoint_re_set. */
5079 target_terminal_ours_for_output ();
5081 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
5083 solib_add (NULL, 0, ¤t_target, auto_solib_add);
5085 target_terminal_inferior ();
5088 /* Prepare WHAT final decision for infrun. */
5090 /* Decide what infrun needs to do with this bpstat. */
5093 bpstat_what (bpstat bs_head)
5095 struct bpstat_what retval;
5099 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5100 retval.call_dummy = STOP_NONE;
5101 retval.is_longjmp = 0;
5103 for (bs = bs_head; bs != NULL; bs = bs->next)
5105 /* Extract this BS's action. After processing each BS, we check
5106 if its action overrides all we've seem so far. */
5107 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5110 if (bs->breakpoint_at == NULL)
5112 /* I suspect this can happen if it was a momentary
5113 breakpoint which has since been deleted. */
5117 bptype = bs->breakpoint_at->type;
5124 case bp_hardware_breakpoint:
5127 case bp_shlib_event:
5131 this_action = BPSTAT_WHAT_STOP_NOISY;
5133 this_action = BPSTAT_WHAT_STOP_SILENT;
5136 this_action = BPSTAT_WHAT_SINGLE;
5139 case bp_hardware_watchpoint:
5140 case bp_read_watchpoint:
5141 case bp_access_watchpoint:
5145 this_action = BPSTAT_WHAT_STOP_NOISY;
5147 this_action = BPSTAT_WHAT_STOP_SILENT;
5151 /* There was a watchpoint, but we're not stopping.
5152 This requires no further action. */
5156 case bp_longjmp_call_dummy:
5158 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5159 retval.is_longjmp = bptype != bp_exception;
5161 case bp_longjmp_resume:
5162 case bp_exception_resume:
5163 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5164 retval.is_longjmp = bptype == bp_longjmp_resume;
5166 case bp_step_resume:
5168 this_action = BPSTAT_WHAT_STEP_RESUME;
5171 /* It is for the wrong frame. */
5172 this_action = BPSTAT_WHAT_SINGLE;
5175 case bp_hp_step_resume:
5177 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5180 /* It is for the wrong frame. */
5181 this_action = BPSTAT_WHAT_SINGLE;
5184 case bp_watchpoint_scope:
5185 case bp_thread_event:
5186 case bp_overlay_event:
5187 case bp_longjmp_master:
5188 case bp_std_terminate_master:
5189 case bp_exception_master:
5190 this_action = BPSTAT_WHAT_SINGLE;
5196 this_action = BPSTAT_WHAT_STOP_NOISY;
5198 this_action = BPSTAT_WHAT_STOP_SILENT;
5202 /* There was a catchpoint, but we're not stopping.
5203 This requires no further action. */
5208 this_action = BPSTAT_WHAT_SINGLE;
5211 /* Make sure the action is stop (silent or noisy),
5212 so infrun.c pops the dummy frame. */
5213 retval.call_dummy = STOP_STACK_DUMMY;
5214 this_action = BPSTAT_WHAT_STOP_SILENT;
5216 case bp_std_terminate:
5217 /* Make sure the action is stop (silent or noisy),
5218 so infrun.c pops the dummy frame. */
5219 retval.call_dummy = STOP_STD_TERMINATE;
5220 this_action = BPSTAT_WHAT_STOP_SILENT;
5223 case bp_fast_tracepoint:
5224 case bp_static_tracepoint:
5225 /* Tracepoint hits should not be reported back to GDB, and
5226 if one got through somehow, it should have been filtered
5228 internal_error (__FILE__, __LINE__,
5229 _("bpstat_what: tracepoint encountered"));
5231 case bp_gnu_ifunc_resolver:
5232 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5233 this_action = BPSTAT_WHAT_SINGLE;
5235 case bp_gnu_ifunc_resolver_return:
5236 /* The breakpoint will be removed, execution will restart from the
5237 PC of the former breakpoint. */
5238 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5242 this_action = BPSTAT_WHAT_STOP_SILENT;
5246 internal_error (__FILE__, __LINE__,
5247 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5250 retval.main_action = max (retval.main_action, this_action);
5253 /* These operations may affect the bs->breakpoint_at state so they are
5254 delayed after MAIN_ACTION is decided above. */
5259 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
5261 handle_jit_event ();
5264 for (bs = bs_head; bs != NULL; bs = bs->next)
5266 struct breakpoint *b = bs->breakpoint_at;
5272 case bp_gnu_ifunc_resolver:
5273 gnu_ifunc_resolver_stop (b);
5275 case bp_gnu_ifunc_resolver_return:
5276 gnu_ifunc_resolver_return_stop (b);
5284 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5285 without hardware support). This isn't related to a specific bpstat,
5286 just to things like whether watchpoints are set. */
5289 bpstat_should_step (void)
5291 struct breakpoint *b;
5294 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
5300 bpstat_causes_stop (bpstat bs)
5302 for (; bs != NULL; bs = bs->next)
5311 /* Compute a string of spaces suitable to indent the next line
5312 so it starts at the position corresponding to the table column
5313 named COL_NAME in the currently active table of UIOUT. */
5316 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5318 static char wrap_indent[80];
5319 int i, total_width, width, align;
5323 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
5325 if (strcmp (text, col_name) == 0)
5327 gdb_assert (total_width < sizeof wrap_indent);
5328 memset (wrap_indent, ' ', total_width);
5329 wrap_indent[total_width] = 0;
5334 total_width += width + 1;
5340 /* Determine if the locations of this breakpoint will have their conditions
5341 evaluated by the target, host or a mix of both. Returns the following:
5343 "host": Host evals condition.
5344 "host or target": Host or Target evals condition.
5345 "target": Target evals condition.
5349 bp_condition_evaluator (struct breakpoint *b)
5351 struct bp_location *bl;
5352 char host_evals = 0;
5353 char target_evals = 0;
5358 if (!is_breakpoint (b))
5361 if (gdb_evaluates_breakpoint_condition_p ()
5362 || !target_supports_evaluation_of_breakpoint_conditions ())
5363 return condition_evaluation_host;
5365 for (bl = b->loc; bl; bl = bl->next)
5367 if (bl->cond_bytecode)
5373 if (host_evals && target_evals)
5374 return condition_evaluation_both;
5375 else if (target_evals)
5376 return condition_evaluation_target;
5378 return condition_evaluation_host;
5381 /* Determine the breakpoint location's condition evaluator. This is
5382 similar to bp_condition_evaluator, but for locations. */
5385 bp_location_condition_evaluator (struct bp_location *bl)
5387 if (bl && !is_breakpoint (bl->owner))
5390 if (gdb_evaluates_breakpoint_condition_p ()
5391 || !target_supports_evaluation_of_breakpoint_conditions ())
5392 return condition_evaluation_host;
5394 if (bl && bl->cond_bytecode)
5395 return condition_evaluation_target;
5397 return condition_evaluation_host;
5400 /* Print the LOC location out of the list of B->LOC locations. */
5403 print_breakpoint_location (struct breakpoint *b,
5404 struct bp_location *loc)
5406 struct ui_out *uiout = current_uiout;
5407 struct cleanup *old_chain = save_current_program_space ();
5409 if (loc != NULL && loc->shlib_disabled)
5413 set_current_program_space (loc->pspace);
5415 if (b->display_canonical)
5416 ui_out_field_string (uiout, "what", b->addr_string);
5417 else if (loc && loc->source_file)
5420 = find_pc_sect_function (loc->address, loc->section);
5423 ui_out_text (uiout, "in ");
5424 ui_out_field_string (uiout, "func",
5425 SYMBOL_PRINT_NAME (sym));
5426 ui_out_text (uiout, " ");
5427 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
5428 ui_out_text (uiout, "at ");
5430 ui_out_field_string (uiout, "file", loc->source_file);
5431 ui_out_text (uiout, ":");
5433 if (ui_out_is_mi_like_p (uiout))
5435 struct symtab_and_line sal = find_pc_line (loc->address, 0);
5436 char *fullname = symtab_to_fullname (sal.symtab);
5439 ui_out_field_string (uiout, "fullname", fullname);
5442 ui_out_field_int (uiout, "line", loc->line_number);
5446 struct ui_file *stb = mem_fileopen ();
5447 struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
5449 print_address_symbolic (loc->gdbarch, loc->address, stb,
5451 ui_out_field_stream (uiout, "at", stb);
5453 do_cleanups (stb_chain);
5456 ui_out_field_string (uiout, "pending", b->addr_string);
5458 if (loc && is_breakpoint (b)
5459 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5460 && bp_condition_evaluator (b) == condition_evaluation_both)
5462 ui_out_text (uiout, " (");
5463 ui_out_field_string (uiout, "evaluated-by",
5464 bp_location_condition_evaluator (loc));
5465 ui_out_text (uiout, ")");
5468 do_cleanups (old_chain);
5472 bptype_string (enum bptype type)
5474 struct ep_type_description
5479 static struct ep_type_description bptypes[] =
5481 {bp_none, "?deleted?"},
5482 {bp_breakpoint, "breakpoint"},
5483 {bp_hardware_breakpoint, "hw breakpoint"},
5484 {bp_until, "until"},
5485 {bp_finish, "finish"},
5486 {bp_watchpoint, "watchpoint"},
5487 {bp_hardware_watchpoint, "hw watchpoint"},
5488 {bp_read_watchpoint, "read watchpoint"},
5489 {bp_access_watchpoint, "acc watchpoint"},
5490 {bp_longjmp, "longjmp"},
5491 {bp_longjmp_resume, "longjmp resume"},
5492 {bp_longjmp_call_dummy, "longjmp for call dummy"},
5493 {bp_exception, "exception"},
5494 {bp_exception_resume, "exception resume"},
5495 {bp_step_resume, "step resume"},
5496 {bp_hp_step_resume, "high-priority step resume"},
5497 {bp_watchpoint_scope, "watchpoint scope"},
5498 {bp_call_dummy, "call dummy"},
5499 {bp_std_terminate, "std::terminate"},
5500 {bp_shlib_event, "shlib events"},
5501 {bp_thread_event, "thread events"},
5502 {bp_overlay_event, "overlay events"},
5503 {bp_longjmp_master, "longjmp master"},
5504 {bp_std_terminate_master, "std::terminate master"},
5505 {bp_exception_master, "exception master"},
5506 {bp_catchpoint, "catchpoint"},
5507 {bp_tracepoint, "tracepoint"},
5508 {bp_fast_tracepoint, "fast tracepoint"},
5509 {bp_static_tracepoint, "static tracepoint"},
5510 {bp_dprintf, "dprintf"},
5511 {bp_jit_event, "jit events"},
5512 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
5513 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
5516 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
5517 || ((int) type != bptypes[(int) type].type))
5518 internal_error (__FILE__, __LINE__,
5519 _("bptypes table does not describe type #%d."),
5522 return bptypes[(int) type].description;
5525 /* Print B to gdb_stdout. */
5528 print_one_breakpoint_location (struct breakpoint *b,
5529 struct bp_location *loc,
5531 struct bp_location **last_loc,
5534 struct command_line *l;
5535 static char bpenables[] = "nynny";
5537 struct ui_out *uiout = current_uiout;
5538 int header_of_multiple = 0;
5539 int part_of_multiple = (loc != NULL);
5540 struct value_print_options opts;
5542 get_user_print_options (&opts);
5544 gdb_assert (!loc || loc_number != 0);
5545 /* See comment in print_one_breakpoint concerning treatment of
5546 breakpoints with single disabled location. */
5549 && (b->loc->next != NULL || !b->loc->enabled)))
5550 header_of_multiple = 1;
5558 if (part_of_multiple)
5561 formatted = xstrprintf ("%d.%d", b->number, loc_number);
5562 ui_out_field_string (uiout, "number", formatted);
5567 ui_out_field_int (uiout, "number", b->number);
5572 if (part_of_multiple)
5573 ui_out_field_skip (uiout, "type");
5575 ui_out_field_string (uiout, "type", bptype_string (b->type));
5579 if (part_of_multiple)
5580 ui_out_field_skip (uiout, "disp");
5582 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
5587 if (part_of_multiple)
5588 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
5590 ui_out_field_fmt (uiout, "enabled", "%c",
5591 bpenables[(int) b->enable_state]);
5592 ui_out_spaces (uiout, 2);
5596 if (b->ops != NULL && b->ops->print_one != NULL)
5598 /* Although the print_one can possibly print all locations,
5599 calling it here is not likely to get any nice result. So,
5600 make sure there's just one location. */
5601 gdb_assert (b->loc == NULL || b->loc->next == NULL);
5602 b->ops->print_one (b, last_loc);
5608 internal_error (__FILE__, __LINE__,
5609 _("print_one_breakpoint: bp_none encountered\n"));
5613 case bp_hardware_watchpoint:
5614 case bp_read_watchpoint:
5615 case bp_access_watchpoint:
5617 struct watchpoint *w = (struct watchpoint *) b;
5619 /* Field 4, the address, is omitted (which makes the columns
5620 not line up too nicely with the headers, but the effect
5621 is relatively readable). */
5622 if (opts.addressprint)
5623 ui_out_field_skip (uiout, "addr");
5625 ui_out_field_string (uiout, "what", w->exp_string);
5630 case bp_hardware_breakpoint:
5634 case bp_longjmp_resume:
5635 case bp_longjmp_call_dummy:
5637 case bp_exception_resume:
5638 case bp_step_resume:
5639 case bp_hp_step_resume:
5640 case bp_watchpoint_scope:
5642 case bp_std_terminate:
5643 case bp_shlib_event:
5644 case bp_thread_event:
5645 case bp_overlay_event:
5646 case bp_longjmp_master:
5647 case bp_std_terminate_master:
5648 case bp_exception_master:
5650 case bp_fast_tracepoint:
5651 case bp_static_tracepoint:
5654 case bp_gnu_ifunc_resolver:
5655 case bp_gnu_ifunc_resolver_return:
5656 if (opts.addressprint)
5659 if (header_of_multiple)
5660 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
5661 else if (b->loc == NULL || loc->shlib_disabled)
5662 ui_out_field_string (uiout, "addr", "<PENDING>");
5664 ui_out_field_core_addr (uiout, "addr",
5665 loc->gdbarch, loc->address);
5668 if (!header_of_multiple)
5669 print_breakpoint_location (b, loc);
5676 /* For backward compatibility, don't display inferiors unless there
5679 && !header_of_multiple
5681 || (!gdbarch_has_global_breakpoints (target_gdbarch)
5682 && (number_of_program_spaces () > 1
5683 || number_of_inferiors () > 1)
5684 /* LOC is for existing B, it cannot be in
5685 moribund_locations and thus having NULL OWNER. */
5686 && loc->owner->type != bp_catchpoint)))
5688 struct inferior *inf;
5691 for (inf = inferior_list; inf != NULL; inf = inf->next)
5693 if (inf->pspace == loc->pspace)
5698 ui_out_text (uiout, " inf ");
5701 ui_out_text (uiout, ", ");
5702 ui_out_text (uiout, plongest (inf->num));
5707 if (!part_of_multiple)
5709 if (b->thread != -1)
5711 /* FIXME: This seems to be redundant and lost here; see the
5712 "stop only in" line a little further down. */
5713 ui_out_text (uiout, " thread ");
5714 ui_out_field_int (uiout, "thread", b->thread);
5716 else if (b->task != 0)
5718 ui_out_text (uiout, " task ");
5719 ui_out_field_int (uiout, "task", b->task);
5723 ui_out_text (uiout, "\n");
5725 if (!part_of_multiple)
5726 b->ops->print_one_detail (b, uiout);
5728 if (part_of_multiple && frame_id_p (b->frame_id))
5731 ui_out_text (uiout, "\tstop only in stack frame at ");
5732 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
5734 ui_out_field_core_addr (uiout, "frame",
5735 b->gdbarch, b->frame_id.stack_addr);
5736 ui_out_text (uiout, "\n");
5739 if (!part_of_multiple && b->cond_string)
5742 if (is_tracepoint (b))
5743 ui_out_text (uiout, "\ttrace only if ");
5745 ui_out_text (uiout, "\tstop only if ");
5746 ui_out_field_string (uiout, "cond", b->cond_string);
5748 /* Print whether the target is doing the breakpoint's condition
5749 evaluation. If GDB is doing the evaluation, don't print anything. */
5750 if (is_breakpoint (b)
5751 && breakpoint_condition_evaluation_mode ()
5752 == condition_evaluation_target)
5754 ui_out_text (uiout, " (");
5755 ui_out_field_string (uiout, "evaluated-by",
5756 bp_condition_evaluator (b));
5757 ui_out_text (uiout, " evals)");
5759 ui_out_text (uiout, "\n");
5762 if (!part_of_multiple && b->thread != -1)
5764 /* FIXME should make an annotation for this. */
5765 ui_out_text (uiout, "\tstop only in thread ");
5766 ui_out_field_int (uiout, "thread", b->thread);
5767 ui_out_text (uiout, "\n");
5770 if (!part_of_multiple && b->hit_count)
5772 /* FIXME should make an annotation for this. */
5773 if (is_catchpoint (b))
5774 ui_out_text (uiout, "\tcatchpoint");
5775 else if (is_tracepoint (b))
5776 ui_out_text (uiout, "\ttracepoint");
5778 ui_out_text (uiout, "\tbreakpoint");
5779 ui_out_text (uiout, " already hit ");
5780 ui_out_field_int (uiout, "times", b->hit_count);
5781 if (b->hit_count == 1)
5782 ui_out_text (uiout, " time\n");
5784 ui_out_text (uiout, " times\n");
5787 /* Output the count also if it is zero, but only if this is mi.
5788 FIXME: Should have a better test for this. */
5789 if (ui_out_is_mi_like_p (uiout))
5790 if (!part_of_multiple && b->hit_count == 0)
5791 ui_out_field_int (uiout, "times", b->hit_count);
5793 if (!part_of_multiple && b->ignore_count)
5796 ui_out_text (uiout, "\tignore next ");
5797 ui_out_field_int (uiout, "ignore", b->ignore_count);
5798 ui_out_text (uiout, " hits\n");
5801 /* Note that an enable count of 1 corresponds to "enable once"
5802 behavior, which is reported by the combination of enablement and
5803 disposition, so we don't need to mention it here. */
5804 if (!part_of_multiple && b->enable_count > 1)
5807 ui_out_text (uiout, "\tdisable after ");
5808 /* Tweak the wording to clarify that ignore and enable counts
5809 are distinct, and have additive effect. */
5810 if (b->ignore_count)
5811 ui_out_text (uiout, "additional ");
5813 ui_out_text (uiout, "next ");
5814 ui_out_field_int (uiout, "enable", b->enable_count);
5815 ui_out_text (uiout, " hits\n");
5818 if (!part_of_multiple && is_tracepoint (b))
5820 struct tracepoint *tp = (struct tracepoint *) b;
5822 if (tp->traceframe_usage)
5824 ui_out_text (uiout, "\ttrace buffer usage ");
5825 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
5826 ui_out_text (uiout, " bytes\n");
5830 l = b->commands ? b->commands->commands : NULL;
5831 if (!part_of_multiple && l)
5833 struct cleanup *script_chain;
5836 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
5837 print_command_lines (uiout, l, 4);
5838 do_cleanups (script_chain);
5841 if (is_tracepoint (b))
5843 struct tracepoint *t = (struct tracepoint *) b;
5845 if (!part_of_multiple && t->pass_count)
5847 annotate_field (10);
5848 ui_out_text (uiout, "\tpass count ");
5849 ui_out_field_int (uiout, "pass", t->pass_count);
5850 ui_out_text (uiout, " \n");
5854 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
5856 if (is_watchpoint (b))
5858 struct watchpoint *w = (struct watchpoint *) b;
5860 ui_out_field_string (uiout, "original-location", w->exp_string);
5862 else if (b->addr_string)
5863 ui_out_field_string (uiout, "original-location", b->addr_string);
5868 print_one_breakpoint (struct breakpoint *b,
5869 struct bp_location **last_loc,
5872 struct cleanup *bkpt_chain;
5873 struct ui_out *uiout = current_uiout;
5875 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
5877 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
5878 do_cleanups (bkpt_chain);
5880 /* If this breakpoint has custom print function,
5881 it's already printed. Otherwise, print individual
5882 locations, if any. */
5883 if (b->ops == NULL || b->ops->print_one == NULL)
5885 /* If breakpoint has a single location that is disabled, we
5886 print it as if it had several locations, since otherwise it's
5887 hard to represent "breakpoint enabled, location disabled"
5890 Note that while hardware watchpoints have several locations
5891 internally, that's not a property exposed to user. */
5893 && !is_hardware_watchpoint (b)
5894 && (b->loc->next || !b->loc->enabled))
5896 struct bp_location *loc;
5899 for (loc = b->loc; loc; loc = loc->next, ++n)
5901 struct cleanup *inner2 =
5902 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
5903 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
5904 do_cleanups (inner2);
5911 breakpoint_address_bits (struct breakpoint *b)
5913 int print_address_bits = 0;
5914 struct bp_location *loc;
5916 for (loc = b->loc; loc; loc = loc->next)
5920 /* Software watchpoints that aren't watching memory don't have
5921 an address to print. */
5922 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
5925 addr_bit = gdbarch_addr_bit (loc->gdbarch);
5926 if (addr_bit > print_address_bits)
5927 print_address_bits = addr_bit;
5930 return print_address_bits;
5933 struct captured_breakpoint_query_args
5939 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
5941 struct captured_breakpoint_query_args *args = data;
5942 struct breakpoint *b;
5943 struct bp_location *dummy_loc = NULL;
5947 if (args->bnum == b->number)
5949 print_one_breakpoint (b, &dummy_loc, 0);
5957 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
5958 char **error_message)
5960 struct captured_breakpoint_query_args args;
5963 /* For the moment we don't trust print_one_breakpoint() to not throw
5965 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
5966 error_message, RETURN_MASK_ALL) < 0)
5972 /* Return true if this breakpoint was set by the user, false if it is
5973 internal or momentary. */
5976 user_breakpoint_p (struct breakpoint *b)
5978 return b->number > 0;
5981 /* Print information on user settable breakpoint (watchpoint, etc)
5982 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5983 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5984 FILTER is non-NULL, call it on each breakpoint and only include the
5985 ones for which it returns non-zero. Return the total number of
5986 breakpoints listed. */
5989 breakpoint_1 (char *args, int allflag,
5990 int (*filter) (const struct breakpoint *))
5992 struct breakpoint *b;
5993 struct bp_location *last_loc = NULL;
5994 int nr_printable_breakpoints;
5995 struct cleanup *bkpttbl_chain;
5996 struct value_print_options opts;
5997 int print_address_bits = 0;
5998 int print_type_col_width = 14;
5999 struct ui_out *uiout = current_uiout;
6001 get_user_print_options (&opts);
6003 /* Compute the number of rows in the table, as well as the size
6004 required for address fields. */
6005 nr_printable_breakpoints = 0;
6008 /* If we have a filter, only list the breakpoints it accepts. */
6009 if (filter && !filter (b))
6012 /* If we have an "args" string, it is a list of breakpoints to
6013 accept. Skip the others. */
6014 if (args != NULL && *args != '\0')
6016 if (allflag && parse_and_eval_long (args) != b->number)
6018 if (!allflag && !number_is_in_list (args, b->number))
6022 if (allflag || user_breakpoint_p (b))
6024 int addr_bit, type_len;
6026 addr_bit = breakpoint_address_bits (b);
6027 if (addr_bit > print_address_bits)
6028 print_address_bits = addr_bit;
6030 type_len = strlen (bptype_string (b->type));
6031 if (type_len > print_type_col_width)
6032 print_type_col_width = type_len;
6034 nr_printable_breakpoints++;
6038 if (opts.addressprint)
6040 = make_cleanup_ui_out_table_begin_end (uiout, 6,
6041 nr_printable_breakpoints,
6045 = make_cleanup_ui_out_table_begin_end (uiout, 5,
6046 nr_printable_breakpoints,
6049 if (nr_printable_breakpoints > 0)
6050 annotate_breakpoints_headers ();
6051 if (nr_printable_breakpoints > 0)
6053 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
6054 if (nr_printable_breakpoints > 0)
6056 ui_out_table_header (uiout, print_type_col_width, ui_left,
6057 "type", "Type"); /* 2 */
6058 if (nr_printable_breakpoints > 0)
6060 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
6061 if (nr_printable_breakpoints > 0)
6063 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
6064 if (opts.addressprint)
6066 if (nr_printable_breakpoints > 0)
6068 if (print_address_bits <= 32)
6069 ui_out_table_header (uiout, 10, ui_left,
6070 "addr", "Address"); /* 5 */
6072 ui_out_table_header (uiout, 18, ui_left,
6073 "addr", "Address"); /* 5 */
6075 if (nr_printable_breakpoints > 0)
6077 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
6078 ui_out_table_body (uiout);
6079 if (nr_printable_breakpoints > 0)
6080 annotate_breakpoints_table ();
6085 /* If we have a filter, only list the breakpoints it accepts. */
6086 if (filter && !filter (b))
6089 /* If we have an "args" string, it is a list of breakpoints to
6090 accept. Skip the others. */
6092 if (args != NULL && *args != '\0')
6094 if (allflag) /* maintenance info breakpoint */
6096 if (parse_and_eval_long (args) != b->number)
6099 else /* all others */
6101 if (!number_is_in_list (args, b->number))
6105 /* We only print out user settable breakpoints unless the
6107 if (allflag || user_breakpoint_p (b))
6108 print_one_breakpoint (b, &last_loc, allflag);
6111 do_cleanups (bkpttbl_chain);
6113 if (nr_printable_breakpoints == 0)
6115 /* If there's a filter, let the caller decide how to report
6119 if (args == NULL || *args == '\0')
6120 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
6122 ui_out_message (uiout, 0,
6123 "No breakpoint or watchpoint matching '%s'.\n",
6129 if (last_loc && !server_command)
6130 set_next_address (last_loc->gdbarch, last_loc->address);
6133 /* FIXME? Should this be moved up so that it is only called when
6134 there have been breakpoints? */
6135 annotate_breakpoints_table_end ();
6137 return nr_printable_breakpoints;
6140 /* Display the value of default-collect in a way that is generally
6141 compatible with the breakpoint list. */
6144 default_collect_info (void)
6146 struct ui_out *uiout = current_uiout;
6148 /* If it has no value (which is frequently the case), say nothing; a
6149 message like "No default-collect." gets in user's face when it's
6151 if (!*default_collect)
6154 /* The following phrase lines up nicely with per-tracepoint collect
6156 ui_out_text (uiout, "default collect ");
6157 ui_out_field_string (uiout, "default-collect", default_collect);
6158 ui_out_text (uiout, " \n");
6162 breakpoints_info (char *args, int from_tty)
6164 breakpoint_1 (args, 0, NULL);
6166 default_collect_info ();
6170 watchpoints_info (char *args, int from_tty)
6172 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6173 struct ui_out *uiout = current_uiout;
6175 if (num_printed == 0)
6177 if (args == NULL || *args == '\0')
6178 ui_out_message (uiout, 0, "No watchpoints.\n");
6180 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
6185 maintenance_info_breakpoints (char *args, int from_tty)
6187 breakpoint_1 (args, 1, NULL);
6189 default_collect_info ();
6193 breakpoint_has_pc (struct breakpoint *b,
6194 struct program_space *pspace,
6195 CORE_ADDR pc, struct obj_section *section)
6197 struct bp_location *bl = b->loc;
6199 for (; bl; bl = bl->next)
6201 if (bl->pspace == pspace
6202 && bl->address == pc
6203 && (!overlay_debugging || bl->section == section))
6209 /* Print a message describing any user-breakpoints set at PC. This
6210 concerns with logical breakpoints, so we match program spaces, not
6214 describe_other_breakpoints (struct gdbarch *gdbarch,
6215 struct program_space *pspace, CORE_ADDR pc,
6216 struct obj_section *section, int thread)
6219 struct breakpoint *b;
6222 others += (user_breakpoint_p (b)
6223 && breakpoint_has_pc (b, pspace, pc, section));
6227 printf_filtered (_("Note: breakpoint "));
6228 else /* if (others == ???) */
6229 printf_filtered (_("Note: breakpoints "));
6231 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
6234 printf_filtered ("%d", b->number);
6235 if (b->thread == -1 && thread != -1)
6236 printf_filtered (" (all threads)");
6237 else if (b->thread != -1)
6238 printf_filtered (" (thread %d)", b->thread);
6239 printf_filtered ("%s%s ",
6240 ((b->enable_state == bp_disabled
6241 || b->enable_state == bp_call_disabled)
6243 : b->enable_state == bp_permanent
6247 : ((others == 1) ? " and" : ""));
6249 printf_filtered (_("also set at pc "));
6250 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
6251 printf_filtered (".\n");
6256 /* Return true iff it is meaningful to use the address member of
6257 BPT. For some breakpoint types, the address member is irrelevant
6258 and it makes no sense to attempt to compare it to other addresses
6259 (or use it for any other purpose either).
6261 More specifically, each of the following breakpoint types will
6262 always have a zero valued address and we don't want to mark
6263 breakpoints of any of these types to be a duplicate of an actual
6264 breakpoint at address zero:
6272 breakpoint_address_is_meaningful (struct breakpoint *bpt)
6274 enum bptype type = bpt->type;
6276 return (type != bp_watchpoint && type != bp_catchpoint);
6279 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6280 true if LOC1 and LOC2 represent the same watchpoint location. */
6283 watchpoint_locations_match (struct bp_location *loc1,
6284 struct bp_location *loc2)
6286 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6287 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6289 /* Both of them must exist. */
6290 gdb_assert (w1 != NULL);
6291 gdb_assert (w2 != NULL);
6293 /* If the target can evaluate the condition expression in hardware,
6294 then we we need to insert both watchpoints even if they are at
6295 the same place. Otherwise the watchpoint will only trigger when
6296 the condition of whichever watchpoint was inserted evaluates to
6297 true, not giving a chance for GDB to check the condition of the
6298 other watchpoint. */
6300 && target_can_accel_watchpoint_condition (loc1->address,
6302 loc1->watchpoint_type,
6305 && target_can_accel_watchpoint_condition (loc2->address,
6307 loc2->watchpoint_type,
6311 /* Note that this checks the owner's type, not the location's. In
6312 case the target does not support read watchpoints, but does
6313 support access watchpoints, we'll have bp_read_watchpoint
6314 watchpoints with hw_access locations. Those should be considered
6315 duplicates of hw_read locations. The hw_read locations will
6316 become hw_access locations later. */
6317 return (loc1->owner->type == loc2->owner->type
6318 && loc1->pspace->aspace == loc2->pspace->aspace
6319 && loc1->address == loc2->address
6320 && loc1->length == loc2->length);
6323 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6324 same breakpoint location. In most targets, this can only be true
6325 if ASPACE1 matches ASPACE2. On targets that have global
6326 breakpoints, the address space doesn't really matter. */
6329 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
6330 struct address_space *aspace2, CORE_ADDR addr2)
6332 return ((gdbarch_has_global_breakpoints (target_gdbarch)
6333 || aspace1 == aspace2)
6337 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6338 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6339 matches ASPACE2. On targets that have global breakpoints, the address
6340 space doesn't really matter. */
6343 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
6344 int len1, struct address_space *aspace2,
6347 return ((gdbarch_has_global_breakpoints (target_gdbarch)
6348 || aspace1 == aspace2)
6349 && addr2 >= addr1 && addr2 < addr1 + len1);
6352 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6353 a ranged breakpoint. In most targets, a match happens only if ASPACE
6354 matches the breakpoint's address space. On targets that have global
6355 breakpoints, the address space doesn't really matter. */
6358 breakpoint_location_address_match (struct bp_location *bl,
6359 struct address_space *aspace,
6362 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
6365 && breakpoint_address_match_range (bl->pspace->aspace,
6366 bl->address, bl->length,
6370 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6371 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6372 true, otherwise returns false. */
6375 tracepoint_locations_match (struct bp_location *loc1,
6376 struct bp_location *loc2)
6378 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
6379 /* Since tracepoint locations are never duplicated with others', tracepoint
6380 locations at the same address of different tracepoints are regarded as
6381 different locations. */
6382 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
6387 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6388 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6389 represent the same location. */
6392 breakpoint_locations_match (struct bp_location *loc1,
6393 struct bp_location *loc2)
6395 int hw_point1, hw_point2;
6397 /* Both of them must not be in moribund_locations. */
6398 gdb_assert (loc1->owner != NULL);
6399 gdb_assert (loc2->owner != NULL);
6401 hw_point1 = is_hardware_watchpoint (loc1->owner);
6402 hw_point2 = is_hardware_watchpoint (loc2->owner);
6404 if (hw_point1 != hw_point2)
6407 return watchpoint_locations_match (loc1, loc2);
6408 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
6409 return tracepoint_locations_match (loc1, loc2);
6411 /* We compare bp_location.length in order to cover ranged breakpoints. */
6412 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
6413 loc2->pspace->aspace, loc2->address)
6414 && loc1->length == loc2->length);
6418 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
6419 int bnum, int have_bnum)
6421 /* The longest string possibly returned by hex_string_custom
6422 is 50 chars. These must be at least that big for safety. */
6426 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
6427 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
6429 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6430 bnum, astr1, astr2);
6432 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
6435 /* Adjust a breakpoint's address to account for architectural
6436 constraints on breakpoint placement. Return the adjusted address.
6437 Note: Very few targets require this kind of adjustment. For most
6438 targets, this function is simply the identity function. */
6441 adjust_breakpoint_address (struct gdbarch *gdbarch,
6442 CORE_ADDR bpaddr, enum bptype bptype)
6444 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
6446 /* Very few targets need any kind of breakpoint adjustment. */
6449 else if (bptype == bp_watchpoint
6450 || bptype == bp_hardware_watchpoint
6451 || bptype == bp_read_watchpoint
6452 || bptype == bp_access_watchpoint
6453 || bptype == bp_catchpoint)
6455 /* Watchpoints and the various bp_catch_* eventpoints should not
6456 have their addresses modified. */
6461 CORE_ADDR adjusted_bpaddr;
6463 /* Some targets have architectural constraints on the placement
6464 of breakpoint instructions. Obtain the adjusted address. */
6465 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
6467 /* An adjusted breakpoint address can significantly alter
6468 a user's expectations. Print a warning if an adjustment
6470 if (adjusted_bpaddr != bpaddr)
6471 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
6473 return adjusted_bpaddr;
6478 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
6479 struct breakpoint *owner)
6481 memset (loc, 0, sizeof (*loc));
6483 gdb_assert (ops != NULL);
6488 loc->cond_bytecode = NULL;
6489 loc->shlib_disabled = 0;
6492 switch (owner->type)
6498 case bp_longjmp_resume:
6499 case bp_longjmp_call_dummy:
6501 case bp_exception_resume:
6502 case bp_step_resume:
6503 case bp_hp_step_resume:
6504 case bp_watchpoint_scope:
6506 case bp_std_terminate:
6507 case bp_shlib_event:
6508 case bp_thread_event:
6509 case bp_overlay_event:
6511 case bp_longjmp_master:
6512 case bp_std_terminate_master:
6513 case bp_exception_master:
6514 case bp_gnu_ifunc_resolver:
6515 case bp_gnu_ifunc_resolver_return:
6517 loc->loc_type = bp_loc_software_breakpoint;
6518 mark_breakpoint_location_modified (loc);
6520 case bp_hardware_breakpoint:
6521 loc->loc_type = bp_loc_hardware_breakpoint;
6522 mark_breakpoint_location_modified (loc);
6524 case bp_hardware_watchpoint:
6525 case bp_read_watchpoint:
6526 case bp_access_watchpoint:
6527 loc->loc_type = bp_loc_hardware_watchpoint;
6532 case bp_fast_tracepoint:
6533 case bp_static_tracepoint:
6534 loc->loc_type = bp_loc_other;
6537 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
6543 /* Allocate a struct bp_location. */
6545 static struct bp_location *
6546 allocate_bp_location (struct breakpoint *bpt)
6548 return bpt->ops->allocate_location (bpt);
6552 free_bp_location (struct bp_location *loc)
6554 loc->ops->dtor (loc);
6558 /* Increment reference count. */
6561 incref_bp_location (struct bp_location *bl)
6566 /* Decrement reference count. If the reference count reaches 0,
6567 destroy the bp_location. Sets *BLP to NULL. */
6570 decref_bp_location (struct bp_location **blp)
6572 gdb_assert ((*blp)->refc > 0);
6574 if (--(*blp)->refc == 0)
6575 free_bp_location (*blp);
6579 /* Add breakpoint B at the end of the global breakpoint chain. */
6582 add_to_breakpoint_chain (struct breakpoint *b)
6584 struct breakpoint *b1;
6586 /* Add this breakpoint to the end of the chain so that a list of
6587 breakpoints will come out in order of increasing numbers. */
6589 b1 = breakpoint_chain;
6591 breakpoint_chain = b;
6600 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
6603 init_raw_breakpoint_without_location (struct breakpoint *b,
6604 struct gdbarch *gdbarch,
6606 const struct breakpoint_ops *ops)
6608 memset (b, 0, sizeof (*b));
6610 gdb_assert (ops != NULL);
6614 b->gdbarch = gdbarch;
6615 b->language = current_language->la_language;
6616 b->input_radix = input_radix;
6618 b->enable_state = bp_enabled;
6621 b->ignore_count = 0;
6623 b->frame_id = null_frame_id;
6624 b->condition_not_parsed = 0;
6625 b->py_bp_object = NULL;
6626 b->related_breakpoint = b;
6629 /* Helper to set_raw_breakpoint below. Creates a breakpoint
6630 that has type BPTYPE and has no locations as yet. */
6632 static struct breakpoint *
6633 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
6635 const struct breakpoint_ops *ops)
6637 struct breakpoint *b = XNEW (struct breakpoint);
6639 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
6640 add_to_breakpoint_chain (b);
6644 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
6645 resolutions should be made as the user specified the location explicitly
6649 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
6651 gdb_assert (loc->owner != NULL);
6653 if (loc->owner->type == bp_breakpoint
6654 || loc->owner->type == bp_hardware_breakpoint
6655 || is_tracepoint (loc->owner))
6658 const char *function_name;
6659 CORE_ADDR func_addr;
6661 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
6662 &func_addr, NULL, &is_gnu_ifunc);
6664 if (is_gnu_ifunc && !explicit_loc)
6666 struct breakpoint *b = loc->owner;
6668 gdb_assert (loc->pspace == current_program_space);
6669 if (gnu_ifunc_resolve_name (function_name,
6670 &loc->requested_address))
6672 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
6673 loc->address = adjust_breakpoint_address (loc->gdbarch,
6674 loc->requested_address,
6677 else if (b->type == bp_breakpoint && b->loc == loc
6678 && loc->next == NULL && b->related_breakpoint == b)
6680 /* Create only the whole new breakpoint of this type but do not
6681 mess more complicated breakpoints with multiple locations. */
6682 b->type = bp_gnu_ifunc_resolver;
6683 /* Remember the resolver's address for use by the return
6685 loc->related_address = func_addr;
6690 loc->function_name = xstrdup (function_name);
6694 /* Attempt to determine architecture of location identified by SAL. */
6696 get_sal_arch (struct symtab_and_line sal)
6699 return get_objfile_arch (sal.section->objfile);
6701 return get_objfile_arch (sal.symtab->objfile);
6706 /* Low level routine for partially initializing a breakpoint of type
6707 BPTYPE. The newly created breakpoint's address, section, source
6708 file name, and line number are provided by SAL.
6710 It is expected that the caller will complete the initialization of
6711 the newly created breakpoint struct as well as output any status
6712 information regarding the creation of a new breakpoint. */
6715 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
6716 struct symtab_and_line sal, enum bptype bptype,
6717 const struct breakpoint_ops *ops)
6719 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
6721 add_location_to_breakpoint (b, &sal);
6723 if (bptype != bp_catchpoint)
6724 gdb_assert (sal.pspace != NULL);
6726 /* Store the program space that was used to set the breakpoint,
6727 except for ordinary breakpoints, which are independent of the
6729 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
6730 b->pspace = sal.pspace;
6732 breakpoints_changed ();
6735 /* set_raw_breakpoint is a low level routine for allocating and
6736 partially initializing a breakpoint of type BPTYPE. The newly
6737 created breakpoint's address, section, source file name, and line
6738 number are provided by SAL. The newly created and partially
6739 initialized breakpoint is added to the breakpoint chain and
6740 is also returned as the value of this function.
6742 It is expected that the caller will complete the initialization of
6743 the newly created breakpoint struct as well as output any status
6744 information regarding the creation of a new breakpoint. In
6745 particular, set_raw_breakpoint does NOT set the breakpoint
6746 number! Care should be taken to not allow an error to occur
6747 prior to completing the initialization of the breakpoint. If this
6748 should happen, a bogus breakpoint will be left on the chain. */
6751 set_raw_breakpoint (struct gdbarch *gdbarch,
6752 struct symtab_and_line sal, enum bptype bptype,
6753 const struct breakpoint_ops *ops)
6755 struct breakpoint *b = XNEW (struct breakpoint);
6757 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
6758 add_to_breakpoint_chain (b);
6763 /* Note that the breakpoint object B describes a permanent breakpoint
6764 instruction, hard-wired into the inferior's code. */
6766 make_breakpoint_permanent (struct breakpoint *b)
6768 struct bp_location *bl;
6770 b->enable_state = bp_permanent;
6772 /* By definition, permanent breakpoints are already present in the
6773 code. Mark all locations as inserted. For now,
6774 make_breakpoint_permanent is called in just one place, so it's
6775 hard to say if it's reasonable to have permanent breakpoint with
6776 multiple locations or not, but it's easy to implement. */
6777 for (bl = b->loc; bl; bl = bl->next)
6781 /* Call this routine when stepping and nexting to enable a breakpoint
6782 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
6783 initiated the operation. */
6786 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
6788 struct breakpoint *b, *b_tmp;
6789 int thread = tp->num;
6791 /* To avoid having to rescan all objfile symbols at every step,
6792 we maintain a list of continually-inserted but always disabled
6793 longjmp "master" breakpoints. Here, we simply create momentary
6794 clones of those and enable them for the requested thread. */
6795 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6796 if (b->pspace == current_program_space
6797 && (b->type == bp_longjmp_master
6798 || b->type == bp_exception_master))
6800 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
6801 struct breakpoint *clone;
6803 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
6804 after their removal. */
6805 clone = momentary_breakpoint_from_master (b, type,
6806 &longjmp_breakpoint_ops);
6807 clone->thread = thread;
6810 tp->initiating_frame = frame;
6813 /* Delete all longjmp breakpoints from THREAD. */
6815 delete_longjmp_breakpoint (int thread)
6817 struct breakpoint *b, *b_tmp;
6819 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6820 if (b->type == bp_longjmp || b->type == bp_exception)
6822 if (b->thread == thread)
6823 delete_breakpoint (b);
6828 delete_longjmp_breakpoint_at_next_stop (int thread)
6830 struct breakpoint *b, *b_tmp;
6832 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6833 if (b->type == bp_longjmp || b->type == bp_exception)
6835 if (b->thread == thread)
6836 b->disposition = disp_del_at_next_stop;
6840 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
6841 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
6842 pointer to any of them. Return NULL if this system cannot place longjmp
6846 set_longjmp_breakpoint_for_call_dummy (void)
6848 struct breakpoint *b, *retval = NULL;
6851 if (b->pspace == current_program_space && b->type == bp_longjmp_master)
6853 struct breakpoint *new_b;
6855 new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
6856 &momentary_breakpoint_ops);
6857 new_b->thread = pid_to_thread_id (inferior_ptid);
6859 /* Link NEW_B into the chain of RETVAL breakpoints. */
6861 gdb_assert (new_b->related_breakpoint == new_b);
6864 new_b->related_breakpoint = retval;
6865 while (retval->related_breakpoint != new_b->related_breakpoint)
6866 retval = retval->related_breakpoint;
6867 retval->related_breakpoint = new_b;
6873 /* Verify all existing dummy frames and their associated breakpoints for
6874 THREAD. Remove those which can no longer be found in the current frame
6877 You should call this function only at places where it is safe to currently
6878 unwind the whole stack. Failed stack unwind would discard live dummy
6882 check_longjmp_breakpoint_for_call_dummy (int thread)
6884 struct breakpoint *b, *b_tmp;
6886 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6887 if (b->type == bp_longjmp_call_dummy && b->thread == thread)
6889 struct breakpoint *dummy_b = b->related_breakpoint;
6891 while (dummy_b != b && dummy_b->type != bp_call_dummy)
6892 dummy_b = dummy_b->related_breakpoint;
6893 if (dummy_b->type != bp_call_dummy
6894 || frame_find_by_id (dummy_b->frame_id) != NULL)
6897 dummy_frame_discard (dummy_b->frame_id);
6899 while (b->related_breakpoint != b)
6901 if (b_tmp == b->related_breakpoint)
6902 b_tmp = b->related_breakpoint->next;
6903 delete_breakpoint (b->related_breakpoint);
6905 delete_breakpoint (b);
6910 enable_overlay_breakpoints (void)
6912 struct breakpoint *b;
6915 if (b->type == bp_overlay_event)
6917 b->enable_state = bp_enabled;
6918 update_global_location_list (1);
6919 overlay_events_enabled = 1;
6924 disable_overlay_breakpoints (void)
6926 struct breakpoint *b;
6929 if (b->type == bp_overlay_event)
6931 b->enable_state = bp_disabled;
6932 update_global_location_list (0);
6933 overlay_events_enabled = 0;
6937 /* Set an active std::terminate breakpoint for each std::terminate
6938 master breakpoint. */
6940 set_std_terminate_breakpoint (void)
6942 struct breakpoint *b, *b_tmp;
6944 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6945 if (b->pspace == current_program_space
6946 && b->type == bp_std_terminate_master)
6948 momentary_breakpoint_from_master (b, bp_std_terminate,
6949 &momentary_breakpoint_ops);
6953 /* Delete all the std::terminate breakpoints. */
6955 delete_std_terminate_breakpoint (void)
6957 struct breakpoint *b, *b_tmp;
6959 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6960 if (b->type == bp_std_terminate)
6961 delete_breakpoint (b);
6965 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6967 struct breakpoint *b;
6969 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
6970 &internal_breakpoint_ops);
6972 b->enable_state = bp_enabled;
6973 /* addr_string has to be used or breakpoint_re_set will delete me. */
6975 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
6977 update_global_location_list_nothrow (1);
6983 remove_thread_event_breakpoints (void)
6985 struct breakpoint *b, *b_tmp;
6987 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6988 if (b->type == bp_thread_event
6989 && b->loc->pspace == current_program_space)
6990 delete_breakpoint (b);
6993 struct lang_and_radix
6999 /* Create a breakpoint for JIT code registration and unregistration. */
7002 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7004 struct breakpoint *b;
7006 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
7007 &internal_breakpoint_ops);
7008 update_global_location_list_nothrow (1);
7012 /* Remove JIT code registration and unregistration breakpoint(s). */
7015 remove_jit_event_breakpoints (void)
7017 struct breakpoint *b, *b_tmp;
7019 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7020 if (b->type == bp_jit_event
7021 && b->loc->pspace == current_program_space)
7022 delete_breakpoint (b);
7026 remove_solib_event_breakpoints (void)
7028 struct breakpoint *b, *b_tmp;
7030 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7031 if (b->type == bp_shlib_event
7032 && b->loc->pspace == current_program_space)
7033 delete_breakpoint (b);
7037 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7039 struct breakpoint *b;
7041 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7042 &internal_breakpoint_ops);
7043 update_global_location_list_nothrow (1);
7047 /* Disable any breakpoints that are on code in shared libraries. Only
7048 apply to enabled breakpoints, disabled ones can just stay disabled. */
7051 disable_breakpoints_in_shlibs (void)
7053 struct bp_location *loc, **locp_tmp;
7055 ALL_BP_LOCATIONS (loc, locp_tmp)
7057 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7058 struct breakpoint *b = loc->owner;
7060 /* We apply the check to all breakpoints, including disabled for
7061 those with loc->duplicate set. This is so that when breakpoint
7062 becomes enabled, or the duplicate is removed, gdb will try to
7063 insert all breakpoints. If we don't set shlib_disabled here,
7064 we'll try to insert those breakpoints and fail. */
7065 if (((b->type == bp_breakpoint)
7066 || (b->type == bp_jit_event)
7067 || (b->type == bp_hardware_breakpoint)
7068 || (is_tracepoint (b)))
7069 && loc->pspace == current_program_space
7070 && !loc->shlib_disabled
7072 && PC_SOLIB (loc->address)
7074 && solib_name_from_address (loc->pspace, loc->address)
7078 loc->shlib_disabled = 1;
7083 /* Disable any breakpoints and tracepoints that are in an unloaded shared
7084 library. Only apply to enabled breakpoints, disabled ones can just stay
7088 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
7090 struct bp_location *loc, **locp_tmp;
7091 int disabled_shlib_breaks = 0;
7093 /* SunOS a.out shared libraries are always mapped, so do not
7094 disable breakpoints; they will only be reported as unloaded
7095 through clear_solib when GDB discards its shared library
7096 list. See clear_solib for more information. */
7097 if (exec_bfd != NULL
7098 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
7101 ALL_BP_LOCATIONS (loc, locp_tmp)
7103 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7104 struct breakpoint *b = loc->owner;
7106 if (solib->pspace == loc->pspace
7107 && !loc->shlib_disabled
7108 && (((b->type == bp_breakpoint
7109 || b->type == bp_jit_event
7110 || b->type == bp_hardware_breakpoint)
7111 && (loc->loc_type == bp_loc_hardware_breakpoint
7112 || loc->loc_type == bp_loc_software_breakpoint))
7113 || is_tracepoint (b))
7114 && solib_contains_address_p (solib, loc->address))
7116 loc->shlib_disabled = 1;
7117 /* At this point, we cannot rely on remove_breakpoint
7118 succeeding so we must mark the breakpoint as not inserted
7119 to prevent future errors occurring in remove_breakpoints. */
7122 /* This may cause duplicate notifications for the same breakpoint. */
7123 observer_notify_breakpoint_modified (b);
7125 if (!disabled_shlib_breaks)
7127 target_terminal_ours_for_output ();
7128 warning (_("Temporarily disabling breakpoints "
7129 "for unloaded shared library \"%s\""),
7132 disabled_shlib_breaks = 1;
7137 /* FORK & VFORK catchpoints. */
7139 /* An instance of this type is used to represent a fork or vfork
7140 catchpoint. It includes a "struct breakpoint" as a kind of base
7141 class; users downcast to "struct breakpoint *" when needed. A
7142 breakpoint is really of this type iff its ops pointer points to
7143 CATCH_FORK_BREAKPOINT_OPS. */
7145 struct fork_catchpoint
7147 /* The base class. */
7148 struct breakpoint base;
7150 /* Process id of a child process whose forking triggered this
7151 catchpoint. This field is only valid immediately after this
7152 catchpoint has triggered. */
7153 ptid_t forked_inferior_pid;
7156 /* Implement the "insert" breakpoint_ops method for fork
7160 insert_catch_fork (struct bp_location *bl)
7162 return target_insert_fork_catchpoint (PIDGET (inferior_ptid));
7165 /* Implement the "remove" breakpoint_ops method for fork
7169 remove_catch_fork (struct bp_location *bl)
7171 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
7174 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7178 breakpoint_hit_catch_fork (const struct bp_location *bl,
7179 struct address_space *aspace, CORE_ADDR bp_addr,
7180 const struct target_waitstatus *ws)
7182 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7184 if (ws->kind != TARGET_WAITKIND_FORKED)
7187 c->forked_inferior_pid = ws->value.related_pid;
7191 /* Implement the "print_it" breakpoint_ops method for fork
7194 static enum print_stop_action
7195 print_it_catch_fork (bpstat bs)
7197 struct ui_out *uiout = current_uiout;
7198 struct breakpoint *b = bs->breakpoint_at;
7199 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
7201 annotate_catchpoint (b->number);
7202 if (b->disposition == disp_del)
7203 ui_out_text (uiout, "\nTemporary catchpoint ");
7205 ui_out_text (uiout, "\nCatchpoint ");
7206 if (ui_out_is_mi_like_p (uiout))
7208 ui_out_field_string (uiout, "reason",
7209 async_reason_lookup (EXEC_ASYNC_FORK));
7210 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7212 ui_out_field_int (uiout, "bkptno", b->number);
7213 ui_out_text (uiout, " (forked process ");
7214 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7215 ui_out_text (uiout, "), ");
7216 return PRINT_SRC_AND_LOC;
7219 /* Implement the "print_one" breakpoint_ops method for fork
7223 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
7225 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7226 struct value_print_options opts;
7227 struct ui_out *uiout = current_uiout;
7229 get_user_print_options (&opts);
7231 /* Field 4, the address, is omitted (which makes the columns not
7232 line up too nicely with the headers, but the effect is relatively
7234 if (opts.addressprint)
7235 ui_out_field_skip (uiout, "addr");
7237 ui_out_text (uiout, "fork");
7238 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7240 ui_out_text (uiout, ", process ");
7241 ui_out_field_int (uiout, "what",
7242 ptid_get_pid (c->forked_inferior_pid));
7243 ui_out_spaces (uiout, 1);
7247 /* Implement the "print_mention" breakpoint_ops method for fork
7251 print_mention_catch_fork (struct breakpoint *b)
7253 printf_filtered (_("Catchpoint %d (fork)"), b->number);
7256 /* Implement the "print_recreate" breakpoint_ops method for fork
7260 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
7262 fprintf_unfiltered (fp, "catch fork");
7263 print_recreate_thread (b, fp);
7266 /* The breakpoint_ops structure to be used in fork catchpoints. */
7268 static struct breakpoint_ops catch_fork_breakpoint_ops;
7270 /* Implement the "insert" breakpoint_ops method for vfork
7274 insert_catch_vfork (struct bp_location *bl)
7276 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
7279 /* Implement the "remove" breakpoint_ops method for vfork
7283 remove_catch_vfork (struct bp_location *bl)
7285 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
7288 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7292 breakpoint_hit_catch_vfork (const struct bp_location *bl,
7293 struct address_space *aspace, CORE_ADDR bp_addr,
7294 const struct target_waitstatus *ws)
7296 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7298 if (ws->kind != TARGET_WAITKIND_VFORKED)
7301 c->forked_inferior_pid = ws->value.related_pid;
7305 /* Implement the "print_it" breakpoint_ops method for vfork
7308 static enum print_stop_action
7309 print_it_catch_vfork (bpstat bs)
7311 struct ui_out *uiout = current_uiout;
7312 struct breakpoint *b = bs->breakpoint_at;
7313 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7315 annotate_catchpoint (b->number);
7316 if (b->disposition == disp_del)
7317 ui_out_text (uiout, "\nTemporary catchpoint ");
7319 ui_out_text (uiout, "\nCatchpoint ");
7320 if (ui_out_is_mi_like_p (uiout))
7322 ui_out_field_string (uiout, "reason",
7323 async_reason_lookup (EXEC_ASYNC_VFORK));
7324 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7326 ui_out_field_int (uiout, "bkptno", b->number);
7327 ui_out_text (uiout, " (vforked process ");
7328 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7329 ui_out_text (uiout, "), ");
7330 return PRINT_SRC_AND_LOC;
7333 /* Implement the "print_one" breakpoint_ops method for vfork
7337 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
7339 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7340 struct value_print_options opts;
7341 struct ui_out *uiout = current_uiout;
7343 get_user_print_options (&opts);
7344 /* Field 4, the address, is omitted (which makes the columns not
7345 line up too nicely with the headers, but the effect is relatively
7347 if (opts.addressprint)
7348 ui_out_field_skip (uiout, "addr");
7350 ui_out_text (uiout, "vfork");
7351 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7353 ui_out_text (uiout, ", process ");
7354 ui_out_field_int (uiout, "what",
7355 ptid_get_pid (c->forked_inferior_pid));
7356 ui_out_spaces (uiout, 1);
7360 /* Implement the "print_mention" breakpoint_ops method for vfork
7364 print_mention_catch_vfork (struct breakpoint *b)
7366 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
7369 /* Implement the "print_recreate" breakpoint_ops method for vfork
7373 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
7375 fprintf_unfiltered (fp, "catch vfork");
7376 print_recreate_thread (b, fp);
7379 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7381 static struct breakpoint_ops catch_vfork_breakpoint_ops;
7383 /* An instance of this type is used to represent an solib catchpoint.
7384 It includes a "struct breakpoint" as a kind of base class; users
7385 downcast to "struct breakpoint *" when needed. A breakpoint is
7386 really of this type iff its ops pointer points to
7387 CATCH_SOLIB_BREAKPOINT_OPS. */
7389 struct solib_catchpoint
7391 /* The base class. */
7392 struct breakpoint base;
7394 /* True for "catch load", false for "catch unload". */
7395 unsigned char is_load;
7397 /* Regular expression to match, if any. COMPILED is only valid when
7398 REGEX is non-NULL. */
7404 dtor_catch_solib (struct breakpoint *b)
7406 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7409 regfree (&self->compiled);
7410 xfree (self->regex);
7412 base_breakpoint_ops.dtor (b);
7416 insert_catch_solib (struct bp_location *ignore)
7422 remove_catch_solib (struct bp_location *ignore)
7428 breakpoint_hit_catch_solib (const struct bp_location *bl,
7429 struct address_space *aspace,
7431 const struct target_waitstatus *ws)
7433 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
7434 struct breakpoint *other;
7436 if (ws->kind == TARGET_WAITKIND_LOADED)
7439 ALL_BREAKPOINTS (other)
7441 struct bp_location *other_bl;
7443 if (other == bl->owner)
7446 if (other->type != bp_shlib_event)
7449 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
7452 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
7454 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
7463 check_status_catch_solib (struct bpstats *bs)
7465 struct solib_catchpoint *self
7466 = (struct solib_catchpoint *) bs->breakpoint_at;
7471 struct so_list *iter;
7474 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
7479 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
7488 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
7493 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
7499 bs->print_it = print_it_noop;
7502 static enum print_stop_action
7503 print_it_catch_solib (bpstat bs)
7505 struct breakpoint *b = bs->breakpoint_at;
7506 struct ui_out *uiout = current_uiout;
7508 annotate_catchpoint (b->number);
7509 if (b->disposition == disp_del)
7510 ui_out_text (uiout, "\nTemporary catchpoint ");
7512 ui_out_text (uiout, "\nCatchpoint ");
7513 ui_out_field_int (uiout, "bkptno", b->number);
7514 ui_out_text (uiout, "\n");
7515 if (ui_out_is_mi_like_p (uiout))
7516 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7517 print_solib_event (1);
7518 return PRINT_SRC_AND_LOC;
7522 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
7524 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7525 struct value_print_options opts;
7526 struct ui_out *uiout = current_uiout;
7529 get_user_print_options (&opts);
7530 /* Field 4, the address, is omitted (which makes the columns not
7531 line up too nicely with the headers, but the effect is relatively
7533 if (opts.addressprint)
7536 ui_out_field_skip (uiout, "addr");
7543 msg = xstrprintf (_("load of library matching %s"), self->regex);
7545 msg = xstrdup (_("load of library"));
7550 msg = xstrprintf (_("unload of library matching %s"), self->regex);
7552 msg = xstrdup (_("unload of library"));
7554 ui_out_field_string (uiout, "what", msg);
7559 print_mention_catch_solib (struct breakpoint *b)
7561 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7563 printf_filtered (_("Catchpoint %d (%s)"), b->number,
7564 self->is_load ? "load" : "unload");
7568 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
7570 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7572 fprintf_unfiltered (fp, "%s %s",
7573 b->disposition == disp_del ? "tcatch" : "catch",
7574 self->is_load ? "load" : "unload");
7576 fprintf_unfiltered (fp, " %s", self->regex);
7577 fprintf_unfiltered (fp, "\n");
7580 static struct breakpoint_ops catch_solib_breakpoint_ops;
7582 /* A helper function that does all the work for "catch load" and
7586 catch_load_or_unload (char *arg, int from_tty, int is_load,
7587 struct cmd_list_element *command)
7589 struct solib_catchpoint *c;
7590 struct gdbarch *gdbarch = get_current_arch ();
7592 struct cleanup *cleanup;
7594 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
7598 arg = skip_spaces (arg);
7600 c = XCNEW (struct solib_catchpoint);
7601 cleanup = make_cleanup (xfree, c);
7607 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
7610 char *err = get_regcomp_error (errcode, &c->compiled);
7612 make_cleanup (xfree, err);
7613 error (_("Invalid regexp (%s): %s"), err, arg);
7615 c->regex = xstrdup (arg);
7618 c->is_load = is_load;
7619 init_catchpoint (&c->base, gdbarch, tempflag, NULL,
7620 &catch_solib_breakpoint_ops);
7622 discard_cleanups (cleanup);
7623 install_breakpoint (0, &c->base, 1);
7627 catch_load_command_1 (char *arg, int from_tty,
7628 struct cmd_list_element *command)
7630 catch_load_or_unload (arg, from_tty, 1, command);
7634 catch_unload_command_1 (char *arg, int from_tty,
7635 struct cmd_list_element *command)
7637 catch_load_or_unload (arg, from_tty, 0, command);
7642 /* An instance of this type is used to represent a syscall catchpoint.
7643 It includes a "struct breakpoint" as a kind of base class; users
7644 downcast to "struct breakpoint *" when needed. A breakpoint is
7645 really of this type iff its ops pointer points to
7646 CATCH_SYSCALL_BREAKPOINT_OPS. */
7648 struct syscall_catchpoint
7650 /* The base class. */
7651 struct breakpoint base;
7653 /* Syscall numbers used for the 'catch syscall' feature. If no
7654 syscall has been specified for filtering, its value is NULL.
7655 Otherwise, it holds a list of all syscalls to be caught. The
7656 list elements are allocated with xmalloc. */
7657 VEC(int) *syscalls_to_be_caught;
7660 /* Implement the "dtor" breakpoint_ops method for syscall
7664 dtor_catch_syscall (struct breakpoint *b)
7666 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7668 VEC_free (int, c->syscalls_to_be_caught);
7670 base_breakpoint_ops.dtor (b);
7673 static const struct inferior_data *catch_syscall_inferior_data = NULL;
7675 struct catch_syscall_inferior_data
7677 /* We keep a count of the number of times the user has requested a
7678 particular syscall to be tracked, and pass this information to the
7679 target. This lets capable targets implement filtering directly. */
7681 /* Number of times that "any" syscall is requested. */
7682 int any_syscall_count;
7684 /* Count of each system call. */
7685 VEC(int) *syscalls_counts;
7687 /* This counts all syscall catch requests, so we can readily determine
7688 if any catching is necessary. */
7689 int total_syscalls_count;
7692 static struct catch_syscall_inferior_data*
7693 get_catch_syscall_inferior_data (struct inferior *inf)
7695 struct catch_syscall_inferior_data *inf_data;
7697 inf_data = inferior_data (inf, catch_syscall_inferior_data);
7698 if (inf_data == NULL)
7700 inf_data = XZALLOC (struct catch_syscall_inferior_data);
7701 set_inferior_data (inf, catch_syscall_inferior_data, inf_data);
7708 catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg)
7714 /* Implement the "insert" breakpoint_ops method for syscall
7718 insert_catch_syscall (struct bp_location *bl)
7720 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
7721 struct inferior *inf = current_inferior ();
7722 struct catch_syscall_inferior_data *inf_data
7723 = get_catch_syscall_inferior_data (inf);
7725 ++inf_data->total_syscalls_count;
7726 if (!c->syscalls_to_be_caught)
7727 ++inf_data->any_syscall_count;
7733 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7738 if (iter >= VEC_length (int, inf_data->syscalls_counts))
7740 int old_size = VEC_length (int, inf_data->syscalls_counts);
7741 uintptr_t vec_addr_offset
7742 = old_size * ((uintptr_t) sizeof (int));
7744 VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1);
7745 vec_addr = ((uintptr_t) VEC_address (int,
7746 inf_data->syscalls_counts)
7748 memset ((void *) vec_addr, 0,
7749 (iter + 1 - old_size) * sizeof (int));
7751 elem = VEC_index (int, inf_data->syscalls_counts, iter);
7752 VEC_replace (int, inf_data->syscalls_counts, iter, ++elem);
7756 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
7757 inf_data->total_syscalls_count != 0,
7758 inf_data->any_syscall_count,
7760 inf_data->syscalls_counts),
7762 inf_data->syscalls_counts));
7765 /* Implement the "remove" breakpoint_ops method for syscall
7769 remove_catch_syscall (struct bp_location *bl)
7771 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
7772 struct inferior *inf = current_inferior ();
7773 struct catch_syscall_inferior_data *inf_data
7774 = get_catch_syscall_inferior_data (inf);
7776 --inf_data->total_syscalls_count;
7777 if (!c->syscalls_to_be_caught)
7778 --inf_data->any_syscall_count;
7784 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7788 if (iter >= VEC_length (int, inf_data->syscalls_counts))
7789 /* Shouldn't happen. */
7791 elem = VEC_index (int, inf_data->syscalls_counts, iter);
7792 VEC_replace (int, inf_data->syscalls_counts, iter, --elem);
7796 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
7797 inf_data->total_syscalls_count != 0,
7798 inf_data->any_syscall_count,
7800 inf_data->syscalls_counts),
7802 inf_data->syscalls_counts));
7805 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
7809 breakpoint_hit_catch_syscall (const struct bp_location *bl,
7810 struct address_space *aspace, CORE_ADDR bp_addr,
7811 const struct target_waitstatus *ws)
7813 /* We must check if we are catching specific syscalls in this
7814 breakpoint. If we are, then we must guarantee that the called
7815 syscall is the same syscall we are catching. */
7816 int syscall_number = 0;
7817 const struct syscall_catchpoint *c
7818 = (const struct syscall_catchpoint *) bl->owner;
7820 if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY
7821 && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN)
7824 syscall_number = ws->value.syscall_number;
7826 /* Now, checking if the syscall is the same. */
7827 if (c->syscalls_to_be_caught)
7832 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7834 if (syscall_number == iter)
7844 /* Implement the "print_it" breakpoint_ops method for syscall
7847 static enum print_stop_action
7848 print_it_catch_syscall (bpstat bs)
7850 struct ui_out *uiout = current_uiout;
7851 struct breakpoint *b = bs->breakpoint_at;
7852 /* These are needed because we want to know in which state a
7853 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
7854 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
7855 must print "called syscall" or "returned from syscall". */
7857 struct target_waitstatus last;
7860 get_last_target_status (&ptid, &last);
7862 get_syscall_by_number (last.value.syscall_number, &s);
7864 annotate_catchpoint (b->number);
7866 if (b->disposition == disp_del)
7867 ui_out_text (uiout, "\nTemporary catchpoint ");
7869 ui_out_text (uiout, "\nCatchpoint ");
7870 if (ui_out_is_mi_like_p (uiout))
7872 ui_out_field_string (uiout, "reason",
7873 async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY
7874 ? EXEC_ASYNC_SYSCALL_ENTRY
7875 : EXEC_ASYNC_SYSCALL_RETURN));
7876 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7878 ui_out_field_int (uiout, "bkptno", b->number);
7880 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
7881 ui_out_text (uiout, " (call to syscall ");
7883 ui_out_text (uiout, " (returned from syscall ");
7885 if (s.name == NULL || ui_out_is_mi_like_p (uiout))
7886 ui_out_field_int (uiout, "syscall-number", last.value.syscall_number);
7888 ui_out_field_string (uiout, "syscall-name", s.name);
7890 ui_out_text (uiout, "), ");
7892 return PRINT_SRC_AND_LOC;
7895 /* Implement the "print_one" breakpoint_ops method for syscall
7899 print_one_catch_syscall (struct breakpoint *b,
7900 struct bp_location **last_loc)
7902 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7903 struct value_print_options opts;
7904 struct ui_out *uiout = current_uiout;
7906 get_user_print_options (&opts);
7907 /* Field 4, the address, is omitted (which makes the columns not
7908 line up too nicely with the headers, but the effect is relatively
7910 if (opts.addressprint)
7911 ui_out_field_skip (uiout, "addr");
7914 if (c->syscalls_to_be_caught
7915 && VEC_length (int, c->syscalls_to_be_caught) > 1)
7916 ui_out_text (uiout, "syscalls \"");
7918 ui_out_text (uiout, "syscall \"");
7920 if (c->syscalls_to_be_caught)
7923 char *text = xstrprintf ("%s", "");
7926 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7931 get_syscall_by_number (iter, &s);
7934 text = xstrprintf ("%s%s, ", text, s.name);
7936 text = xstrprintf ("%s%d, ", text, iter);
7938 /* We have to xfree the last 'text' (now stored at 'x')
7939 because xstrprintf dynamically allocates new space for it
7943 /* Remove the last comma. */
7944 text[strlen (text) - 2] = '\0';
7945 ui_out_field_string (uiout, "what", text);
7948 ui_out_field_string (uiout, "what", "<any syscall>");
7949 ui_out_text (uiout, "\" ");
7952 /* Implement the "print_mention" breakpoint_ops method for syscall
7956 print_mention_catch_syscall (struct breakpoint *b)
7958 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7960 if (c->syscalls_to_be_caught)
7964 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
7965 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
7967 printf_filtered (_("Catchpoint %d (syscall"), b->number);
7970 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7974 get_syscall_by_number (iter, &s);
7977 printf_filtered (" '%s' [%d]", s.name, s.number);
7979 printf_filtered (" %d", s.number);
7981 printf_filtered (")");
7984 printf_filtered (_("Catchpoint %d (any syscall)"),
7988 /* Implement the "print_recreate" breakpoint_ops method for syscall
7992 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
7994 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7996 fprintf_unfiltered (fp, "catch syscall");
7998 if (c->syscalls_to_be_caught)
8003 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8008 get_syscall_by_number (iter, &s);
8010 fprintf_unfiltered (fp, " %s", s.name);
8012 fprintf_unfiltered (fp, " %d", s.number);
8015 print_recreate_thread (b, fp);
8018 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8020 static struct breakpoint_ops catch_syscall_breakpoint_ops;
8022 /* Returns non-zero if 'b' is a syscall catchpoint. */
8025 syscall_catchpoint_p (struct breakpoint *b)
8027 return (b->ops == &catch_syscall_breakpoint_ops);
8030 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8031 is non-zero, then make the breakpoint temporary. If COND_STRING is
8032 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8033 the breakpoint_ops structure associated to the catchpoint. */
8036 init_catchpoint (struct breakpoint *b,
8037 struct gdbarch *gdbarch, int tempflag,
8039 const struct breakpoint_ops *ops)
8041 struct symtab_and_line sal;
8044 sal.pspace = current_program_space;
8046 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
8048 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
8049 b->disposition = tempflag ? disp_del : disp_donttouch;
8053 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
8055 add_to_breakpoint_chain (b);
8056 set_breakpoint_number (internal, b);
8059 observer_notify_breakpoint_created (b);
8062 update_global_location_list (1);
8066 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
8067 int tempflag, char *cond_string,
8068 const struct breakpoint_ops *ops)
8070 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
8072 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
8074 c->forked_inferior_pid = null_ptid;
8076 install_breakpoint (0, &c->base, 1);
8079 /* Exec catchpoints. */
8081 /* An instance of this type is used to represent an exec catchpoint.
8082 It includes a "struct breakpoint" as a kind of base class; users
8083 downcast to "struct breakpoint *" when needed. A breakpoint is
8084 really of this type iff its ops pointer points to
8085 CATCH_EXEC_BREAKPOINT_OPS. */
8087 struct exec_catchpoint
8089 /* The base class. */
8090 struct breakpoint base;
8092 /* Filename of a program whose exec triggered this catchpoint.
8093 This field is only valid immediately after this catchpoint has
8095 char *exec_pathname;
8098 /* Implement the "dtor" breakpoint_ops method for exec
8102 dtor_catch_exec (struct breakpoint *b)
8104 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8106 xfree (c->exec_pathname);
8108 base_breakpoint_ops.dtor (b);
8112 insert_catch_exec (struct bp_location *bl)
8114 return target_insert_exec_catchpoint (PIDGET (inferior_ptid));
8118 remove_catch_exec (struct bp_location *bl)
8120 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
8124 breakpoint_hit_catch_exec (const struct bp_location *bl,
8125 struct address_space *aspace, CORE_ADDR bp_addr,
8126 const struct target_waitstatus *ws)
8128 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8130 if (ws->kind != TARGET_WAITKIND_EXECD)
8133 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8137 static enum print_stop_action
8138 print_it_catch_exec (bpstat bs)
8140 struct ui_out *uiout = current_uiout;
8141 struct breakpoint *b = bs->breakpoint_at;
8142 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8144 annotate_catchpoint (b->number);
8145 if (b->disposition == disp_del)
8146 ui_out_text (uiout, "\nTemporary catchpoint ");
8148 ui_out_text (uiout, "\nCatchpoint ");
8149 if (ui_out_is_mi_like_p (uiout))
8151 ui_out_field_string (uiout, "reason",
8152 async_reason_lookup (EXEC_ASYNC_EXEC));
8153 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8155 ui_out_field_int (uiout, "bkptno", b->number);
8156 ui_out_text (uiout, " (exec'd ");
8157 ui_out_field_string (uiout, "new-exec", c->exec_pathname);
8158 ui_out_text (uiout, "), ");
8160 return PRINT_SRC_AND_LOC;
8164 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8166 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8167 struct value_print_options opts;
8168 struct ui_out *uiout = current_uiout;
8170 get_user_print_options (&opts);
8172 /* Field 4, the address, is omitted (which makes the columns
8173 not line up too nicely with the headers, but the effect
8174 is relatively readable). */
8175 if (opts.addressprint)
8176 ui_out_field_skip (uiout, "addr");
8178 ui_out_text (uiout, "exec");
8179 if (c->exec_pathname != NULL)
8181 ui_out_text (uiout, ", program \"");
8182 ui_out_field_string (uiout, "what", c->exec_pathname);
8183 ui_out_text (uiout, "\" ");
8188 print_mention_catch_exec (struct breakpoint *b)
8190 printf_filtered (_("Catchpoint %d (exec)"), b->number);
8193 /* Implement the "print_recreate" breakpoint_ops method for exec
8197 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
8199 fprintf_unfiltered (fp, "catch exec");
8200 print_recreate_thread (b, fp);
8203 static struct breakpoint_ops catch_exec_breakpoint_ops;
8206 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
8207 const struct breakpoint_ops *ops)
8209 struct syscall_catchpoint *c;
8210 struct gdbarch *gdbarch = get_current_arch ();
8212 c = XNEW (struct syscall_catchpoint);
8213 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
8214 c->syscalls_to_be_caught = filter;
8216 install_breakpoint (0, &c->base, 1);
8220 hw_breakpoint_used_count (void)
8223 struct breakpoint *b;
8224 struct bp_location *bl;
8228 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
8229 for (bl = b->loc; bl; bl = bl->next)
8231 /* Special types of hardware breakpoints may use more than
8233 i += b->ops->resources_needed (bl);
8240 /* Returns the resources B would use if it were a hardware
8244 hw_watchpoint_use_count (struct breakpoint *b)
8247 struct bp_location *bl;
8249 if (!breakpoint_enabled (b))
8252 for (bl = b->loc; bl; bl = bl->next)
8254 /* Special types of hardware watchpoints may use more than
8256 i += b->ops->resources_needed (bl);
8262 /* Returns the sum the used resources of all hardware watchpoints of
8263 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8264 the sum of the used resources of all hardware watchpoints of other
8265 types _not_ TYPE. */
8268 hw_watchpoint_used_count_others (struct breakpoint *except,
8269 enum bptype type, int *other_type_used)
8272 struct breakpoint *b;
8274 *other_type_used = 0;
8279 if (!breakpoint_enabled (b))
8282 if (b->type == type)
8283 i += hw_watchpoint_use_count (b);
8284 else if (is_hardware_watchpoint (b))
8285 *other_type_used = 1;
8292 disable_watchpoints_before_interactive_call_start (void)
8294 struct breakpoint *b;
8298 if (is_watchpoint (b) && breakpoint_enabled (b))
8300 b->enable_state = bp_call_disabled;
8301 update_global_location_list (0);
8307 enable_watchpoints_after_interactive_call_stop (void)
8309 struct breakpoint *b;
8313 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
8315 b->enable_state = bp_enabled;
8316 update_global_location_list (1);
8322 disable_breakpoints_before_startup (void)
8324 current_program_space->executing_startup = 1;
8325 update_global_location_list (0);
8329 enable_breakpoints_after_startup (void)
8331 current_program_space->executing_startup = 0;
8332 breakpoint_re_set ();
8336 /* Set a breakpoint that will evaporate an end of command
8337 at address specified by SAL.
8338 Restrict it to frame FRAME if FRAME is nonzero. */
8341 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
8342 struct frame_id frame_id, enum bptype type)
8344 struct breakpoint *b;
8346 /* If FRAME_ID is valid, it should be a real frame, not an inlined
8348 gdb_assert (!frame_id_inlined_p (frame_id));
8350 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
8351 b->enable_state = bp_enabled;
8352 b->disposition = disp_donttouch;
8353 b->frame_id = frame_id;
8355 /* If we're debugging a multi-threaded program, then we want
8356 momentary breakpoints to be active in only a single thread of
8358 if (in_thread_list (inferior_ptid))
8359 b->thread = pid_to_thread_id (inferior_ptid);
8361 update_global_location_list_nothrow (1);
8366 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8367 The new breakpoint will have type TYPE, and use OPS as it
8370 static struct breakpoint *
8371 momentary_breakpoint_from_master (struct breakpoint *orig,
8373 const struct breakpoint_ops *ops)
8375 struct breakpoint *copy;
8377 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
8378 copy->loc = allocate_bp_location (copy);
8379 set_breakpoint_location_function (copy->loc, 1);
8381 copy->loc->gdbarch = orig->loc->gdbarch;
8382 copy->loc->requested_address = orig->loc->requested_address;
8383 copy->loc->address = orig->loc->address;
8384 copy->loc->section = orig->loc->section;
8385 copy->loc->pspace = orig->loc->pspace;
8386 copy->loc->probe = orig->loc->probe;
8388 if (orig->loc->source_file != NULL)
8389 copy->loc->source_file = xstrdup (orig->loc->source_file);
8391 copy->loc->line_number = orig->loc->line_number;
8392 copy->frame_id = orig->frame_id;
8393 copy->thread = orig->thread;
8394 copy->pspace = orig->pspace;
8396 copy->enable_state = bp_enabled;
8397 copy->disposition = disp_donttouch;
8398 copy->number = internal_breakpoint_number--;
8400 update_global_location_list_nothrow (0);
8404 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8408 clone_momentary_breakpoint (struct breakpoint *orig)
8410 /* If there's nothing to clone, then return nothing. */
8414 return momentary_breakpoint_from_master (orig, orig->type, orig->ops);
8418 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
8421 struct symtab_and_line sal;
8423 sal = find_pc_line (pc, 0);
8425 sal.section = find_pc_overlay (pc);
8426 sal.explicit_pc = 1;
8428 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
8432 /* Tell the user we have just set a breakpoint B. */
8435 mention (struct breakpoint *b)
8437 b->ops->print_mention (b);
8438 if (ui_out_is_mi_like_p (current_uiout))
8440 printf_filtered ("\n");
8444 static struct bp_location *
8445 add_location_to_breakpoint (struct breakpoint *b,
8446 const struct symtab_and_line *sal)
8448 struct bp_location *loc, **tmp;
8449 CORE_ADDR adjusted_address;
8450 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
8452 if (loc_gdbarch == NULL)
8453 loc_gdbarch = b->gdbarch;
8455 /* Adjust the breakpoint's address prior to allocating a location.
8456 Once we call allocate_bp_location(), that mostly uninitialized
8457 location will be placed on the location chain. Adjustment of the
8458 breakpoint may cause target_read_memory() to be called and we do
8459 not want its scan of the location chain to find a breakpoint and
8460 location that's only been partially initialized. */
8461 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
8464 loc = allocate_bp_location (b);
8465 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
8469 loc->requested_address = sal->pc;
8470 loc->address = adjusted_address;
8471 loc->pspace = sal->pspace;
8472 loc->probe = sal->probe;
8473 gdb_assert (loc->pspace != NULL);
8474 loc->section = sal->section;
8475 loc->gdbarch = loc_gdbarch;
8477 if (sal->symtab != NULL)
8478 loc->source_file = xstrdup (sal->symtab->filename);
8479 loc->line_number = sal->line;
8481 set_breakpoint_location_function (loc,
8482 sal->explicit_pc || sal->explicit_line);
8487 /* Return 1 if LOC is pointing to a permanent breakpoint,
8488 return 0 otherwise. */
8491 bp_loc_is_permanent (struct bp_location *loc)
8495 const gdb_byte *bpoint;
8496 gdb_byte *target_mem;
8497 struct cleanup *cleanup;
8500 gdb_assert (loc != NULL);
8502 addr = loc->address;
8503 bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
8505 /* Software breakpoints unsupported? */
8509 target_mem = alloca (len);
8511 /* Enable the automatic memory restoration from breakpoints while
8512 we read the memory. Otherwise we could say about our temporary
8513 breakpoints they are permanent. */
8514 cleanup = save_current_space_and_thread ();
8516 switch_to_program_space_and_thread (loc->pspace);
8517 make_show_memory_breakpoints_cleanup (0);
8519 if (target_read_memory (loc->address, target_mem, len) == 0
8520 && memcmp (target_mem, bpoint, len) == 0)
8523 do_cleanups (cleanup);
8528 /* The style in which to perform a dynamic printf. This is a user
8529 option because different output options have different tradeoffs;
8530 if GDB does the printing, there is better error handling if there
8531 is a problem with any of the arguments, but using an inferior
8532 function lets you have special-purpose printers and sending of
8533 output to the same place as compiled-in print functions. (Future
8534 styles may include the ability to do a target-side printf.) */
8536 static const char dprintf_style_gdb[] = "gdb";
8537 static const char dprintf_style_call[] = "call";
8538 static const char *const dprintf_style_enums[] = {
8543 static const char *dprintf_style = dprintf_style_gdb;
8545 /* The function to use for dynamic printf if the preferred style is to
8546 call into the inferior. The value is simply a string that is
8547 copied into the command, so it can be anything that GDB can
8548 evaluate to a callable address, not necessarily a function name. */
8550 static char *dprintf_function = "";
8552 /* The channel to use for dynamic printf if the preferred style is to
8553 call into the inferior; if a nonempty string, it will be passed to
8554 the call as the first argument, with the format string as the
8555 second. As with the dprintf function, this can be anything that
8556 GDB knows how to evaluate, so in addition to common choices like
8557 "stderr", this could be an app-specific expression like
8558 "mystreams[curlogger]". */
8560 static char *dprintf_channel = "";
8562 /* Build a command list for the dprintf corresponding to the current
8563 settings of the dprintf style options. */
8566 update_dprintf_command_list (struct breakpoint *b)
8568 char *dprintf_args = b->extra_string;
8569 char *printf_line = NULL;
8574 dprintf_args = skip_spaces (dprintf_args);
8576 /* Allow a comma, as it may have terminated a location, but don't
8578 if (*dprintf_args == ',')
8580 dprintf_args = skip_spaces (dprintf_args);
8582 if (*dprintf_args != '"')
8583 error (_("Bad format string, missing '\"'."));
8585 if (strcmp (dprintf_style, "gdb") == 0)
8586 printf_line = xstrprintf ("printf %s", dprintf_args);
8587 else if (strcmp (dprintf_style, "call") == 0)
8589 if (!dprintf_function)
8590 error (_("No function supplied for dprintf call"));
8592 if (dprintf_channel && strlen (dprintf_channel) > 0)
8593 printf_line = xstrprintf ("call (void) %s (%s,%s)",
8598 printf_line = xstrprintf ("call (void) %s (%s)",
8603 internal_error (__FILE__, __LINE__,
8604 _("Invalid dprintf style."));
8606 /* Manufacture a printf/continue sequence. */
8609 struct command_line *printf_cmd_line, *cont_cmd_line = NULL;
8611 cont_cmd_line = xmalloc (sizeof (struct command_line));
8612 cont_cmd_line->control_type = simple_control;
8613 cont_cmd_line->body_count = 0;
8614 cont_cmd_line->body_list = NULL;
8615 cont_cmd_line->next = NULL;
8616 cont_cmd_line->line = xstrdup ("continue");
8618 printf_cmd_line = xmalloc (sizeof (struct command_line));
8619 printf_cmd_line->control_type = simple_control;
8620 printf_cmd_line->body_count = 0;
8621 printf_cmd_line->body_list = NULL;
8622 printf_cmd_line->next = cont_cmd_line;
8623 printf_cmd_line->line = printf_line;
8625 breakpoint_set_commands (b, printf_cmd_line);
8629 /* Update all dprintf commands, making their command lists reflect
8630 current style settings. */
8633 update_dprintf_commands (char *args, int from_tty,
8634 struct cmd_list_element *c)
8636 struct breakpoint *b;
8640 if (b->type == bp_dprintf)
8641 update_dprintf_command_list (b);
8645 /* Create a breakpoint with SAL as location. Use ADDR_STRING
8646 as textual description of the location, and COND_STRING
8647 as condition expression. */
8650 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
8651 struct symtabs_and_lines sals, char *addr_string,
8652 char *filter, char *cond_string,
8654 enum bptype type, enum bpdisp disposition,
8655 int thread, int task, int ignore_count,
8656 const struct breakpoint_ops *ops, int from_tty,
8657 int enabled, int internal, unsigned flags,
8658 int display_canonical)
8662 if (type == bp_hardware_breakpoint)
8664 int target_resources_ok;
8666 i = hw_breakpoint_used_count ();
8667 target_resources_ok =
8668 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
8670 if (target_resources_ok == 0)
8671 error (_("No hardware breakpoint support in the target."));
8672 else if (target_resources_ok < 0)
8673 error (_("Hardware breakpoints used exceeds limit."));
8676 gdb_assert (sals.nelts > 0);
8678 for (i = 0; i < sals.nelts; ++i)
8680 struct symtab_and_line sal = sals.sals[i];
8681 struct bp_location *loc;
8685 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
8687 loc_gdbarch = gdbarch;
8689 describe_other_breakpoints (loc_gdbarch,
8690 sal.pspace, sal.pc, sal.section, thread);
8695 init_raw_breakpoint (b, gdbarch, sal, type, ops);
8699 b->cond_string = cond_string;
8700 b->extra_string = extra_string;
8701 b->ignore_count = ignore_count;
8702 b->enable_state = enabled ? bp_enabled : bp_disabled;
8703 b->disposition = disposition;
8705 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
8706 b->loc->inserted = 1;
8708 if (type == bp_static_tracepoint)
8710 struct tracepoint *t = (struct tracepoint *) b;
8711 struct static_tracepoint_marker marker;
8713 if (strace_marker_p (b))
8715 /* We already know the marker exists, otherwise, we
8716 wouldn't see a sal for it. */
8717 char *p = &addr_string[3];
8721 p = skip_spaces (p);
8723 endp = skip_to_space (p);
8725 marker_str = savestring (p, endp - p);
8726 t->static_trace_marker_id = marker_str;
8728 printf_filtered (_("Probed static tracepoint "
8730 t->static_trace_marker_id);
8732 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
8734 t->static_trace_marker_id = xstrdup (marker.str_id);
8735 release_static_tracepoint_marker (&marker);
8737 printf_filtered (_("Probed static tracepoint "
8739 t->static_trace_marker_id);
8742 warning (_("Couldn't determine the static "
8743 "tracepoint marker to probe"));
8750 loc = add_location_to_breakpoint (b, &sal);
8751 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
8755 if (bp_loc_is_permanent (loc))
8756 make_breakpoint_permanent (b);
8760 char *arg = b->cond_string;
8761 loc->cond = parse_exp_1 (&arg, loc->address,
8762 block_for_pc (loc->address), 0);
8764 error (_("Garbage '%s' follows condition"), arg);
8767 /* Dynamic printf requires and uses additional arguments on the
8768 command line, otherwise it's an error. */
8769 if (type == bp_dprintf)
8771 if (b->extra_string)
8772 update_dprintf_command_list (b);
8774 error (_("Format string required"));
8776 else if (b->extra_string)
8777 error (_("Garbage '%s' at end of command"), b->extra_string);
8780 b->display_canonical = display_canonical;
8782 b->addr_string = addr_string;
8784 /* addr_string has to be used or breakpoint_re_set will delete
8787 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
8792 create_breakpoint_sal (struct gdbarch *gdbarch,
8793 struct symtabs_and_lines sals, char *addr_string,
8794 char *filter, char *cond_string,
8796 enum bptype type, enum bpdisp disposition,
8797 int thread, int task, int ignore_count,
8798 const struct breakpoint_ops *ops, int from_tty,
8799 int enabled, int internal, unsigned flags,
8800 int display_canonical)
8802 struct breakpoint *b;
8803 struct cleanup *old_chain;
8805 if (is_tracepoint_type (type))
8807 struct tracepoint *t;
8809 t = XCNEW (struct tracepoint);
8813 b = XNEW (struct breakpoint);
8815 old_chain = make_cleanup (xfree, b);
8817 init_breakpoint_sal (b, gdbarch,
8819 filter, cond_string, extra_string,
8821 thread, task, ignore_count,
8823 enabled, internal, flags,
8825 discard_cleanups (old_chain);
8827 install_breakpoint (internal, b, 0);
8830 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8831 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8832 value. COND_STRING, if not NULL, specified the condition to be
8833 used for all breakpoints. Essentially the only case where
8834 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8835 function. In that case, it's still not possible to specify
8836 separate conditions for different overloaded functions, so
8837 we take just a single condition string.
8839 NOTE: If the function succeeds, the caller is expected to cleanup
8840 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8841 array contents). If the function fails (error() is called), the
8842 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8843 COND and SALS arrays and each of those arrays contents. */
8846 create_breakpoints_sal (struct gdbarch *gdbarch,
8847 struct linespec_result *canonical,
8848 char *cond_string, char *extra_string,
8849 enum bptype type, enum bpdisp disposition,
8850 int thread, int task, int ignore_count,
8851 const struct breakpoint_ops *ops, int from_tty,
8852 int enabled, int internal, unsigned flags)
8855 struct linespec_sals *lsal;
8857 if (canonical->pre_expanded)
8858 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
8860 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
8862 /* Note that 'addr_string' can be NULL in the case of a plain
8863 'break', without arguments. */
8864 char *addr_string = (canonical->addr_string
8865 ? xstrdup (canonical->addr_string)
8867 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
8868 struct cleanup *inner = make_cleanup (xfree, addr_string);
8870 make_cleanup (xfree, filter_string);
8871 create_breakpoint_sal (gdbarch, lsal->sals,
8874 cond_string, extra_string,
8876 thread, task, ignore_count, ops,
8877 from_tty, enabled, internal, flags,
8878 canonical->special_display);
8879 discard_cleanups (inner);
8883 /* Parse ADDRESS which is assumed to be a SAL specification possibly
8884 followed by conditionals. On return, SALS contains an array of SAL
8885 addresses found. ADDR_STRING contains a vector of (canonical)
8886 address strings. ADDRESS points to the end of the SAL.
8888 The array and the line spec strings are allocated on the heap, it is
8889 the caller's responsibility to free them. */
8892 parse_breakpoint_sals (char **address,
8893 struct linespec_result *canonical)
8895 char *addr_start = *address;
8897 /* If no arg given, or if first arg is 'if ', use the default
8899 if ((*address) == NULL
8900 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
8902 /* The last displayed codepoint, if it's valid, is our default breakpoint
8904 if (last_displayed_sal_is_valid ())
8906 struct linespec_sals lsal;
8907 struct symtab_and_line sal;
8909 init_sal (&sal); /* Initialize to zeroes. */
8910 lsal.sals.sals = (struct symtab_and_line *)
8911 xmalloc (sizeof (struct symtab_and_line));
8913 /* Set sal's pspace, pc, symtab, and line to the values
8914 corresponding to the last call to print_frame_info. */
8915 get_last_displayed_sal (&sal);
8916 sal.section = find_pc_overlay (sal.pc);
8918 /* "break" without arguments is equivalent to "break *PC"
8919 where PC is the last displayed codepoint's address. So
8920 make sure to set sal.explicit_pc to prevent GDB from
8921 trying to expand the list of sals to include all other
8922 instances with the same symtab and line. */
8923 sal.explicit_pc = 1;
8925 lsal.sals.sals[0] = sal;
8926 lsal.sals.nelts = 1;
8927 lsal.canonical = NULL;
8929 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
8932 error (_("No default breakpoint address now."));
8936 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
8938 /* Force almost all breakpoints to be in terms of the
8939 current_source_symtab (which is decode_line_1's default).
8940 This should produce the results we want almost all of the
8941 time while leaving default_breakpoint_* alone.
8943 ObjC: However, don't match an Objective-C method name which
8944 may have a '+' or '-' succeeded by a '['. */
8945 if (last_displayed_sal_is_valid ()
8947 || ((strchr ("+-", (*address)[0]) != NULL)
8948 && ((*address)[1] != '['))))
8949 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
8950 get_last_displayed_symtab (),
8951 get_last_displayed_line (),
8952 canonical, NULL, NULL);
8954 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
8955 cursal.symtab, cursal.line, canonical, NULL, NULL);
8960 /* Convert each SAL into a real PC. Verify that the PC can be
8961 inserted as a breakpoint. If it can't throw an error. */
8964 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
8968 for (i = 0; i < sals->nelts; i++)
8969 resolve_sal_pc (&sals->sals[i]);
8972 /* Fast tracepoints may have restrictions on valid locations. For
8973 instance, a fast tracepoint using a jump instead of a trap will
8974 likely have to overwrite more bytes than a trap would, and so can
8975 only be placed where the instruction is longer than the jump, or a
8976 multi-instruction sequence does not have a jump into the middle of
8980 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
8981 struct symtabs_and_lines *sals)
8984 struct symtab_and_line *sal;
8986 struct cleanup *old_chain;
8988 for (i = 0; i < sals->nelts; i++)
8990 struct gdbarch *sarch;
8992 sal = &sals->sals[i];
8994 sarch = get_sal_arch (*sal);
8995 /* We fall back to GDBARCH if there is no architecture
8996 associated with SAL. */
8999 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc,
9001 old_chain = make_cleanup (xfree, msg);
9004 error (_("May not have a fast tracepoint at 0x%s%s"),
9005 paddress (sarch, sal->pc), (msg ? msg : ""));
9007 do_cleanups (old_chain);
9011 /* Given TOK, a string specification of condition and thread, as
9012 accepted by the 'break' command, extract the condition
9013 string and thread number and set *COND_STRING and *THREAD.
9014 PC identifies the context at which the condition should be parsed.
9015 If no condition is found, *COND_STRING is set to NULL.
9016 If no thread is found, *THREAD is set to -1. */
9019 find_condition_and_thread (char *tok, CORE_ADDR pc,
9020 char **cond_string, int *thread, int *task,
9023 *cond_string = NULL;
9029 char *cond_start = NULL;
9030 char *cond_end = NULL;
9032 tok = skip_spaces (tok);
9034 if ((*tok == '"' || *tok == ',') && rest)
9036 *rest = savestring (tok, strlen (tok));
9040 end_tok = skip_to_space (tok);
9042 toklen = end_tok - tok;
9044 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9046 struct expression *expr;
9048 tok = cond_start = end_tok + 1;
9049 expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
9052 *cond_string = savestring (cond_start, cond_end - cond_start);
9054 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9060 *thread = strtol (tok, &tok, 0);
9062 error (_("Junk after thread keyword."));
9063 if (!valid_thread_id (*thread))
9064 error (_("Unknown thread %d."), *thread);
9066 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9072 *task = strtol (tok, &tok, 0);
9074 error (_("Junk after task keyword."));
9075 if (!valid_task_id (*task))
9076 error (_("Unknown task %d."), *task);
9080 *rest = savestring (tok, strlen (tok));
9084 error (_("Junk at end of arguments."));
9088 /* Decode a static tracepoint marker spec. */
9090 static struct symtabs_and_lines
9091 decode_static_tracepoint_spec (char **arg_p)
9093 VEC(static_tracepoint_marker_p) *markers = NULL;
9094 struct symtabs_and_lines sals;
9095 struct cleanup *old_chain;
9096 char *p = &(*arg_p)[3];
9101 p = skip_spaces (p);
9103 endp = skip_to_space (p);
9105 marker_str = savestring (p, endp - p);
9106 old_chain = make_cleanup (xfree, marker_str);
9108 markers = target_static_tracepoint_markers_by_strid (marker_str);
9109 if (VEC_empty(static_tracepoint_marker_p, markers))
9110 error (_("No known static tracepoint marker named %s"), marker_str);
9112 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
9113 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
9115 for (i = 0; i < sals.nelts; i++)
9117 struct static_tracepoint_marker *marker;
9119 marker = VEC_index (static_tracepoint_marker_p, markers, i);
9121 init_sal (&sals.sals[i]);
9123 sals.sals[i] = find_pc_line (marker->address, 0);
9124 sals.sals[i].pc = marker->address;
9126 release_static_tracepoint_marker (marker);
9129 do_cleanups (old_chain);
9135 /* Set a breakpoint. This function is shared between CLI and MI
9136 functions for setting a breakpoint. This function has two major
9137 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
9138 parameter. If non-zero, the function will parse arg, extracting
9139 breakpoint location, address and thread. Otherwise, ARG is just
9140 the location of breakpoint, with condition and thread specified by
9141 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
9142 the breakpoint number will be allocated from the internal
9143 breakpoint count. Returns true if any breakpoint was created;
9147 create_breakpoint (struct gdbarch *gdbarch,
9148 char *arg, char *cond_string,
9149 int thread, char *extra_string,
9150 int parse_condition_and_thread,
9151 int tempflag, enum bptype type_wanted,
9153 enum auto_boolean pending_break_support,
9154 const struct breakpoint_ops *ops,
9155 int from_tty, int enabled, int internal,
9158 volatile struct gdb_exception e;
9159 char *copy_arg = NULL;
9160 char *addr_start = arg;
9161 struct linespec_result canonical;
9162 struct cleanup *old_chain;
9163 struct cleanup *bkpt_chain = NULL;
9166 int prev_bkpt_count = breakpoint_count;
9168 gdb_assert (ops != NULL);
9170 init_linespec_result (&canonical);
9172 TRY_CATCH (e, RETURN_MASK_ALL)
9174 ops->create_sals_from_address (&arg, &canonical, type_wanted,
9175 addr_start, ©_arg);
9178 /* If caller is interested in rc value from parse, set value. */
9182 if (VEC_empty (linespec_sals, canonical.sals))
9188 case NOT_FOUND_ERROR:
9190 /* If pending breakpoint support is turned off, throw
9193 if (pending_break_support == AUTO_BOOLEAN_FALSE)
9194 throw_exception (e);
9196 exception_print (gdb_stderr, e);
9198 /* If pending breakpoint support is auto query and the user
9199 selects no, then simply return the error code. */
9200 if (pending_break_support == AUTO_BOOLEAN_AUTO
9201 && !nquery (_("Make %s pending on future shared library load? "),
9202 bptype_string (type_wanted)))
9205 /* At this point, either the user was queried about setting
9206 a pending breakpoint and selected yes, or pending
9207 breakpoint behavior is on and thus a pending breakpoint
9208 is defaulted on behalf of the user. */
9210 struct linespec_sals lsal;
9212 copy_arg = xstrdup (addr_start);
9213 lsal.canonical = xstrdup (copy_arg);
9214 lsal.sals.nelts = 1;
9215 lsal.sals.sals = XNEW (struct symtab_and_line);
9216 init_sal (&lsal.sals.sals[0]);
9218 VEC_safe_push (linespec_sals, canonical.sals, &lsal);
9222 throw_exception (e);
9226 throw_exception (e);
9229 /* Create a chain of things that always need to be cleaned up. */
9230 old_chain = make_cleanup_destroy_linespec_result (&canonical);
9232 /* ----------------------------- SNIP -----------------------------
9233 Anything added to the cleanup chain beyond this point is assumed
9234 to be part of a breakpoint. If the breakpoint create succeeds
9235 then the memory is not reclaimed. */
9236 bkpt_chain = make_cleanup (null_cleanup, 0);
9238 /* Resolve all line numbers to PC's and verify that the addresses
9239 are ok for the target. */
9243 struct linespec_sals *iter;
9245 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9246 breakpoint_sals_to_pc (&iter->sals);
9249 /* Fast tracepoints may have additional restrictions on location. */
9250 if (!pending && type_wanted == bp_fast_tracepoint)
9253 struct linespec_sals *iter;
9255 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9256 check_fast_tracepoint_sals (gdbarch, &iter->sals);
9259 /* Verify that condition can be parsed, before setting any
9260 breakpoints. Allocate a separate condition expression for each
9264 struct linespec_sals *lsal;
9266 lsal = VEC_index (linespec_sals, canonical.sals, 0);
9268 if (parse_condition_and_thread)
9271 /* Here we only parse 'arg' to separate condition
9272 from thread number, so parsing in context of first
9273 sal is OK. When setting the breakpoint we'll
9274 re-parse it in context of each sal. */
9278 find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string,
9279 &thread, &task, &rest);
9281 make_cleanup (xfree, cond_string);
9283 make_cleanup (xfree, rest);
9285 extra_string = rest;
9289 /* Create a private copy of condition string. */
9292 cond_string = xstrdup (cond_string);
9293 make_cleanup (xfree, cond_string);
9295 /* Create a private copy of any extra string. */
9298 extra_string = xstrdup (extra_string);
9299 make_cleanup (xfree, extra_string);
9303 ops->create_breakpoints_sal (gdbarch, &canonical, lsal,
9304 cond_string, extra_string, type_wanted,
9305 tempflag ? disp_del : disp_donttouch,
9306 thread, task, ignore_count, ops,
9307 from_tty, enabled, internal, flags);
9311 struct breakpoint *b;
9313 make_cleanup (xfree, copy_arg);
9315 if (is_tracepoint_type (type_wanted))
9317 struct tracepoint *t;
9319 t = XCNEW (struct tracepoint);
9323 b = XNEW (struct breakpoint);
9325 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
9327 b->addr_string = copy_arg;
9328 b->cond_string = NULL;
9329 b->extra_string = NULL;
9330 b->ignore_count = ignore_count;
9331 b->disposition = tempflag ? disp_del : disp_donttouch;
9332 b->condition_not_parsed = 1;
9333 b->enable_state = enabled ? bp_enabled : bp_disabled;
9334 if ((type_wanted != bp_breakpoint
9335 && type_wanted != bp_hardware_breakpoint) || thread != -1)
9336 b->pspace = current_program_space;
9338 install_breakpoint (internal, b, 0);
9341 if (VEC_length (linespec_sals, canonical.sals) > 1)
9343 warning (_("Multiple breakpoints were set.\nUse the "
9344 "\"delete\" command to delete unwanted breakpoints."));
9345 prev_breakpoint_count = prev_bkpt_count;
9348 /* That's it. Discard the cleanups for data inserted into the
9350 discard_cleanups (bkpt_chain);
9351 /* But cleanup everything else. */
9352 do_cleanups (old_chain);
9354 /* error call may happen here - have BKPT_CHAIN already discarded. */
9355 update_global_location_list (1);
9360 /* Set a breakpoint.
9361 ARG is a string describing breakpoint address,
9362 condition, and thread.
9363 FLAG specifies if a breakpoint is hardware on,
9364 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9368 break_command_1 (char *arg, int flag, int from_tty)
9370 int tempflag = flag & BP_TEMPFLAG;
9371 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9372 ? bp_hardware_breakpoint
9374 struct breakpoint_ops *ops;
9375 const char *arg_cp = arg;
9377 /* Matching breakpoints on probes. */
9378 if (arg && probe_linespec_to_ops (&arg_cp) != NULL)
9379 ops = &bkpt_probe_breakpoint_ops;
9381 ops = &bkpt_breakpoint_ops;
9383 create_breakpoint (get_current_arch (),
9385 NULL, 0, NULL, 1 /* parse arg */,
9386 tempflag, type_wanted,
9387 0 /* Ignore count */,
9388 pending_break_support,
9396 /* Helper function for break_command_1 and disassemble_command. */
9399 resolve_sal_pc (struct symtab_and_line *sal)
9403 if (sal->pc == 0 && sal->symtab != NULL)
9405 if (!find_line_pc (sal->symtab, sal->line, &pc))
9406 error (_("No line %d in file \"%s\"."),
9407 sal->line, sal->symtab->filename);
9410 /* If this SAL corresponds to a breakpoint inserted using a line
9411 number, then skip the function prologue if necessary. */
9412 if (sal->explicit_line)
9413 skip_prologue_sal (sal);
9416 if (sal->section == 0 && sal->symtab != NULL)
9418 struct blockvector *bv;
9422 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
9425 sym = block_linkage_function (b);
9428 fixup_symbol_section (sym, sal->symtab->objfile);
9429 sal->section = SYMBOL_OBJ_SECTION (sym);
9433 /* It really is worthwhile to have the section, so we'll
9434 just have to look harder. This case can be executed
9435 if we have line numbers but no functions (as can
9436 happen in assembly source). */
9438 struct minimal_symbol *msym;
9439 struct cleanup *old_chain = save_current_space_and_thread ();
9441 switch_to_program_space_and_thread (sal->pspace);
9443 msym = lookup_minimal_symbol_by_pc (sal->pc);
9445 sal->section = SYMBOL_OBJ_SECTION (msym);
9447 do_cleanups (old_chain);
9454 break_command (char *arg, int from_tty)
9456 break_command_1 (arg, 0, from_tty);
9460 tbreak_command (char *arg, int from_tty)
9462 break_command_1 (arg, BP_TEMPFLAG, from_tty);
9466 hbreak_command (char *arg, int from_tty)
9468 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
9472 thbreak_command (char *arg, int from_tty)
9474 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
9478 stop_command (char *arg, int from_tty)
9480 printf_filtered (_("Specify the type of breakpoint to set.\n\
9481 Usage: stop in <function | address>\n\
9482 stop at <line>\n"));
9486 stopin_command (char *arg, int from_tty)
9490 if (arg == (char *) NULL)
9492 else if (*arg != '*')
9497 /* Look for a ':'. If this is a line number specification, then
9498 say it is bad, otherwise, it should be an address or
9499 function/method name. */
9500 while (*argptr && !hasColon)
9502 hasColon = (*argptr == ':');
9507 badInput = (*argptr != ':'); /* Not a class::method */
9509 badInput = isdigit (*arg); /* a simple line number */
9513 printf_filtered (_("Usage: stop in <function | address>\n"));
9515 break_command_1 (arg, 0, from_tty);
9519 stopat_command (char *arg, int from_tty)
9523 if (arg == (char *) NULL || *arg == '*') /* no line number */
9530 /* Look for a ':'. If there is a '::' then get out, otherwise
9531 it is probably a line number. */
9532 while (*argptr && !hasColon)
9534 hasColon = (*argptr == ':');
9539 badInput = (*argptr == ':'); /* we have class::method */
9541 badInput = !isdigit (*arg); /* not a line number */
9545 printf_filtered (_("Usage: stop at <line>\n"));
9547 break_command_1 (arg, 0, from_tty);
9550 void dprintf_command (char *arg, int from_tty);
9552 /* The dynamic printf command is mostly like a regular breakpoint, but
9553 with a prewired command list consisting of a single output command,
9554 built from extra arguments supplied on the dprintf command
9558 dprintf_command (char *arg, int from_tty)
9560 create_breakpoint (get_current_arch (),
9562 NULL, 0, NULL, 1 /* parse arg */,
9564 0 /* Ignore count */,
9565 pending_break_support,
9566 &dprintf_breakpoint_ops,
9573 /* Implement the "breakpoint_hit" breakpoint_ops method for
9574 ranged breakpoints. */
9577 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
9578 struct address_space *aspace,
9580 const struct target_waitstatus *ws)
9582 if (ws->kind != TARGET_WAITKIND_STOPPED
9583 || ws->value.sig != GDB_SIGNAL_TRAP)
9586 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
9587 bl->length, aspace, bp_addr);
9590 /* Implement the "resources_needed" breakpoint_ops method for
9591 ranged breakpoints. */
9594 resources_needed_ranged_breakpoint (const struct bp_location *bl)
9596 return target_ranged_break_num_registers ();
9599 /* Implement the "print_it" breakpoint_ops method for
9600 ranged breakpoints. */
9602 static enum print_stop_action
9603 print_it_ranged_breakpoint (bpstat bs)
9605 struct breakpoint *b = bs->breakpoint_at;
9606 struct bp_location *bl = b->loc;
9607 struct ui_out *uiout = current_uiout;
9609 gdb_assert (b->type == bp_hardware_breakpoint);
9611 /* Ranged breakpoints have only one location. */
9612 gdb_assert (bl && bl->next == NULL);
9614 annotate_breakpoint (b->number);
9615 if (b->disposition == disp_del)
9616 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
9618 ui_out_text (uiout, "\nRanged breakpoint ");
9619 if (ui_out_is_mi_like_p (uiout))
9621 ui_out_field_string (uiout, "reason",
9622 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
9623 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
9625 ui_out_field_int (uiout, "bkptno", b->number);
9626 ui_out_text (uiout, ", ");
9628 return PRINT_SRC_AND_LOC;
9631 /* Implement the "print_one" breakpoint_ops method for
9632 ranged breakpoints. */
9635 print_one_ranged_breakpoint (struct breakpoint *b,
9636 struct bp_location **last_loc)
9638 struct bp_location *bl = b->loc;
9639 struct value_print_options opts;
9640 struct ui_out *uiout = current_uiout;
9642 /* Ranged breakpoints have only one location. */
9643 gdb_assert (bl && bl->next == NULL);
9645 get_user_print_options (&opts);
9647 if (opts.addressprint)
9648 /* We don't print the address range here, it will be printed later
9649 by print_one_detail_ranged_breakpoint. */
9650 ui_out_field_skip (uiout, "addr");
9652 print_breakpoint_location (b, bl);
9656 /* Implement the "print_one_detail" breakpoint_ops method for
9657 ranged breakpoints. */
9660 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
9661 struct ui_out *uiout)
9663 CORE_ADDR address_start, address_end;
9664 struct bp_location *bl = b->loc;
9665 struct ui_file *stb = mem_fileopen ();
9666 struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
9670 address_start = bl->address;
9671 address_end = address_start + bl->length - 1;
9673 ui_out_text (uiout, "\taddress range: ");
9674 fprintf_unfiltered (stb, "[%s, %s]",
9675 print_core_address (bl->gdbarch, address_start),
9676 print_core_address (bl->gdbarch, address_end));
9677 ui_out_field_stream (uiout, "addr", stb);
9678 ui_out_text (uiout, "\n");
9680 do_cleanups (cleanup);
9683 /* Implement the "print_mention" breakpoint_ops method for
9684 ranged breakpoints. */
9687 print_mention_ranged_breakpoint (struct breakpoint *b)
9689 struct bp_location *bl = b->loc;
9690 struct ui_out *uiout = current_uiout;
9693 gdb_assert (b->type == bp_hardware_breakpoint);
9695 if (ui_out_is_mi_like_p (uiout))
9698 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9699 b->number, paddress (bl->gdbarch, bl->address),
9700 paddress (bl->gdbarch, bl->address + bl->length - 1));
9703 /* Implement the "print_recreate" breakpoint_ops method for
9704 ranged breakpoints. */
9707 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
9709 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
9710 b->addr_string_range_end);
9711 print_recreate_thread (b, fp);
9714 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9716 static struct breakpoint_ops ranged_breakpoint_ops;
9718 /* Find the address where the end of the breakpoint range should be
9719 placed, given the SAL of the end of the range. This is so that if
9720 the user provides a line number, the end of the range is set to the
9721 last instruction of the given line. */
9724 find_breakpoint_range_end (struct symtab_and_line sal)
9728 /* If the user provided a PC value, use it. Otherwise,
9729 find the address of the end of the given location. */
9730 if (sal.explicit_pc)
9737 ret = find_line_pc_range (sal, &start, &end);
9739 error (_("Could not find location of the end of the range."));
9741 /* find_line_pc_range returns the start of the next line. */
9748 /* Implement the "break-range" CLI command. */
9751 break_range_command (char *arg, int from_tty)
9753 char *arg_start, *addr_string_start, *addr_string_end;
9754 struct linespec_result canonical_start, canonical_end;
9755 int bp_count, can_use_bp, length;
9757 struct breakpoint *b;
9758 struct symtab_and_line sal_start, sal_end;
9759 struct cleanup *cleanup_bkpt;
9760 struct linespec_sals *lsal_start, *lsal_end;
9762 /* We don't support software ranged breakpoints. */
9763 if (target_ranged_break_num_registers () < 0)
9764 error (_("This target does not support hardware ranged breakpoints."));
9766 bp_count = hw_breakpoint_used_count ();
9767 bp_count += target_ranged_break_num_registers ();
9768 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9771 error (_("Hardware breakpoints used exceeds limit."));
9773 arg = skip_spaces (arg);
9774 if (arg == NULL || arg[0] == '\0')
9775 error(_("No address range specified."));
9777 init_linespec_result (&canonical_start);
9780 parse_breakpoint_sals (&arg, &canonical_start);
9782 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
9785 error (_("Too few arguments."));
9786 else if (VEC_empty (linespec_sals, canonical_start.sals))
9787 error (_("Could not find location of the beginning of the range."));
9789 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
9791 if (VEC_length (linespec_sals, canonical_start.sals) > 1
9792 || lsal_start->sals.nelts != 1)
9793 error (_("Cannot create a ranged breakpoint with multiple locations."));
9795 sal_start = lsal_start->sals.sals[0];
9796 addr_string_start = savestring (arg_start, arg - arg_start);
9797 make_cleanup (xfree, addr_string_start);
9799 arg++; /* Skip the comma. */
9800 arg = skip_spaces (arg);
9802 /* Parse the end location. */
9804 init_linespec_result (&canonical_end);
9807 /* We call decode_line_full directly here instead of using
9808 parse_breakpoint_sals because we need to specify the start location's
9809 symtab and line as the default symtab and line for the end of the
9810 range. This makes it possible to have ranges like "foo.c:27, +14",
9811 where +14 means 14 lines from the start location. */
9812 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
9813 sal_start.symtab, sal_start.line,
9814 &canonical_end, NULL, NULL);
9816 make_cleanup_destroy_linespec_result (&canonical_end);
9818 if (VEC_empty (linespec_sals, canonical_end.sals))
9819 error (_("Could not find location of the end of the range."));
9821 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
9822 if (VEC_length (linespec_sals, canonical_end.sals) > 1
9823 || lsal_end->sals.nelts != 1)
9824 error (_("Cannot create a ranged breakpoint with multiple locations."));
9826 sal_end = lsal_end->sals.sals[0];
9827 addr_string_end = savestring (arg_start, arg - arg_start);
9828 make_cleanup (xfree, addr_string_end);
9830 end = find_breakpoint_range_end (sal_end);
9831 if (sal_start.pc > end)
9832 error (_("Invalid address range, end precedes start."));
9834 length = end - sal_start.pc + 1;
9836 /* Length overflowed. */
9837 error (_("Address range too large."));
9838 else if (length == 1)
9840 /* This range is simple enough to be handled by
9841 the `hbreak' command. */
9842 hbreak_command (addr_string_start, 1);
9844 do_cleanups (cleanup_bkpt);
9849 /* Now set up the breakpoint. */
9850 b = set_raw_breakpoint (get_current_arch (), sal_start,
9851 bp_hardware_breakpoint, &ranged_breakpoint_ops);
9852 set_breakpoint_count (breakpoint_count + 1);
9853 b->number = breakpoint_count;
9854 b->disposition = disp_donttouch;
9855 b->addr_string = xstrdup (addr_string_start);
9856 b->addr_string_range_end = xstrdup (addr_string_end);
9857 b->loc->length = length;
9859 do_cleanups (cleanup_bkpt);
9862 observer_notify_breakpoint_created (b);
9863 update_global_location_list (1);
9866 /* Return non-zero if EXP is verified as constant. Returned zero
9867 means EXP is variable. Also the constant detection may fail for
9868 some constant expressions and in such case still falsely return
9872 watchpoint_exp_is_const (const struct expression *exp)
9880 /* We are only interested in the descriptor of each element. */
9881 operator_length (exp, i, &oplenp, &argsp);
9884 switch (exp->elts[i].opcode)
9894 case BINOP_LOGICAL_AND:
9895 case BINOP_LOGICAL_OR:
9896 case BINOP_BITWISE_AND:
9897 case BINOP_BITWISE_IOR:
9898 case BINOP_BITWISE_XOR:
9900 case BINOP_NOTEQUAL:
9916 case TERNOP_SLICE_COUNT:
9928 case OP_OBJC_NSSTRING:
9931 case UNOP_LOGICAL_NOT:
9932 case UNOP_COMPLEMENT:
9936 /* Unary, binary and ternary operators: We have to check
9937 their operands. If they are constant, then so is the
9938 result of that operation. For instance, if A and B are
9939 determined to be constants, then so is "A + B".
9941 UNOP_IND is one exception to the rule above, because the
9942 value of *ADDR is not necessarily a constant, even when
9947 /* Check whether the associated symbol is a constant.
9949 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9950 possible that a buggy compiler could mark a variable as
9951 constant even when it is not, and TYPE_CONST would return
9952 true in this case, while SYMBOL_CLASS wouldn't.
9954 We also have to check for function symbols because they
9955 are always constant. */
9957 struct symbol *s = exp->elts[i + 2].symbol;
9959 if (SYMBOL_CLASS (s) != LOC_BLOCK
9960 && SYMBOL_CLASS (s) != LOC_CONST
9961 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
9966 /* The default action is to return 0 because we are using
9967 the optimistic approach here: If we don't know something,
9968 then it is not a constant. */
9977 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
9980 dtor_watchpoint (struct breakpoint *self)
9982 struct watchpoint *w = (struct watchpoint *) self;
9984 xfree (w->cond_exp);
9986 xfree (w->exp_string);
9987 xfree (w->exp_string_reparse);
9988 value_free (w->val);
9990 base_breakpoint_ops.dtor (self);
9993 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
9996 re_set_watchpoint (struct breakpoint *b)
9998 struct watchpoint *w = (struct watchpoint *) b;
10000 /* Watchpoint can be either on expression using entirely global
10001 variables, or it can be on local variables.
10003 Watchpoints of the first kind are never auto-deleted, and even
10004 persist across program restarts. Since they can use variables
10005 from shared libraries, we need to reparse expression as libraries
10006 are loaded and unloaded.
10008 Watchpoints on local variables can also change meaning as result
10009 of solib event. For example, if a watchpoint uses both a local
10010 and a global variables in expression, it's a local watchpoint,
10011 but unloading of a shared library will make the expression
10012 invalid. This is not a very common use case, but we still
10013 re-evaluate expression, to avoid surprises to the user.
10015 Note that for local watchpoints, we re-evaluate it only if
10016 watchpoints frame id is still valid. If it's not, it means the
10017 watchpoint is out of scope and will be deleted soon. In fact,
10018 I'm not sure we'll ever be called in this case.
10020 If a local watchpoint's frame id is still valid, then
10021 w->exp_valid_block is likewise valid, and we can safely use it.
10023 Don't do anything about disabled watchpoints, since they will be
10024 reevaluated again when enabled. */
10025 update_watchpoint (w, 1 /* reparse */);
10028 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10031 insert_watchpoint (struct bp_location *bl)
10033 struct watchpoint *w = (struct watchpoint *) bl->owner;
10034 int length = w->exact ? 1 : bl->length;
10036 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10040 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10043 remove_watchpoint (struct bp_location *bl)
10045 struct watchpoint *w = (struct watchpoint *) bl->owner;
10046 int length = w->exact ? 1 : bl->length;
10048 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10053 breakpoint_hit_watchpoint (const struct bp_location *bl,
10054 struct address_space *aspace, CORE_ADDR bp_addr,
10055 const struct target_waitstatus *ws)
10057 struct breakpoint *b = bl->owner;
10058 struct watchpoint *w = (struct watchpoint *) b;
10060 /* Continuable hardware watchpoints are treated as non-existent if the
10061 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10062 some data address). Otherwise gdb won't stop on a break instruction
10063 in the code (not from a breakpoint) when a hardware watchpoint has
10064 been defined. Also skip watchpoints which we know did not trigger
10065 (did not match the data address). */
10066 if (is_hardware_watchpoint (b)
10067 && w->watchpoint_triggered == watch_triggered_no)
10074 check_status_watchpoint (bpstat bs)
10076 gdb_assert (is_watchpoint (bs->breakpoint_at));
10078 bpstat_check_watchpoint (bs);
10081 /* Implement the "resources_needed" breakpoint_ops method for
10082 hardware watchpoints. */
10085 resources_needed_watchpoint (const struct bp_location *bl)
10087 struct watchpoint *w = (struct watchpoint *) bl->owner;
10088 int length = w->exact? 1 : bl->length;
10090 return target_region_ok_for_hw_watchpoint (bl->address, length);
10093 /* Implement the "works_in_software_mode" breakpoint_ops method for
10094 hardware watchpoints. */
10097 works_in_software_mode_watchpoint (const struct breakpoint *b)
10099 /* Read and access watchpoints only work with hardware support. */
10100 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10103 static enum print_stop_action
10104 print_it_watchpoint (bpstat bs)
10106 struct cleanup *old_chain;
10107 struct breakpoint *b;
10108 const struct bp_location *bl;
10109 struct ui_file *stb;
10110 enum print_stop_action result;
10111 struct watchpoint *w;
10112 struct ui_out *uiout = current_uiout;
10114 gdb_assert (bs->bp_location_at != NULL);
10116 bl = bs->bp_location_at;
10117 b = bs->breakpoint_at;
10118 w = (struct watchpoint *) b;
10120 stb = mem_fileopen ();
10121 old_chain = make_cleanup_ui_file_delete (stb);
10125 case bp_watchpoint:
10126 case bp_hardware_watchpoint:
10127 annotate_watchpoint (b->number);
10128 if (ui_out_is_mi_like_p (uiout))
10129 ui_out_field_string
10131 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10133 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10134 ui_out_text (uiout, "\nOld value = ");
10135 watchpoint_value_print (bs->old_val, stb);
10136 ui_out_field_stream (uiout, "old", stb);
10137 ui_out_text (uiout, "\nNew value = ");
10138 watchpoint_value_print (w->val, stb);
10139 ui_out_field_stream (uiout, "new", stb);
10140 ui_out_text (uiout, "\n");
10141 /* More than one watchpoint may have been triggered. */
10142 result = PRINT_UNKNOWN;
10145 case bp_read_watchpoint:
10146 if (ui_out_is_mi_like_p (uiout))
10147 ui_out_field_string
10149 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10151 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10152 ui_out_text (uiout, "\nValue = ");
10153 watchpoint_value_print (w->val, stb);
10154 ui_out_field_stream (uiout, "value", stb);
10155 ui_out_text (uiout, "\n");
10156 result = PRINT_UNKNOWN;
10159 case bp_access_watchpoint:
10160 if (bs->old_val != NULL)
10162 annotate_watchpoint (b->number);
10163 if (ui_out_is_mi_like_p (uiout))
10164 ui_out_field_string
10166 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10168 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10169 ui_out_text (uiout, "\nOld value = ");
10170 watchpoint_value_print (bs->old_val, stb);
10171 ui_out_field_stream (uiout, "old", stb);
10172 ui_out_text (uiout, "\nNew value = ");
10177 if (ui_out_is_mi_like_p (uiout))
10178 ui_out_field_string
10180 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10181 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10182 ui_out_text (uiout, "\nValue = ");
10184 watchpoint_value_print (w->val, stb);
10185 ui_out_field_stream (uiout, "new", stb);
10186 ui_out_text (uiout, "\n");
10187 result = PRINT_UNKNOWN;
10190 result = PRINT_UNKNOWN;
10193 do_cleanups (old_chain);
10197 /* Implement the "print_mention" breakpoint_ops method for hardware
10201 print_mention_watchpoint (struct breakpoint *b)
10203 struct cleanup *ui_out_chain;
10204 struct watchpoint *w = (struct watchpoint *) b;
10205 struct ui_out *uiout = current_uiout;
10209 case bp_watchpoint:
10210 ui_out_text (uiout, "Watchpoint ");
10211 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10213 case bp_hardware_watchpoint:
10214 ui_out_text (uiout, "Hardware watchpoint ");
10215 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10217 case bp_read_watchpoint:
10218 ui_out_text (uiout, "Hardware read watchpoint ");
10219 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10221 case bp_access_watchpoint:
10222 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
10223 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10226 internal_error (__FILE__, __LINE__,
10227 _("Invalid hardware watchpoint type."));
10230 ui_out_field_int (uiout, "number", b->number);
10231 ui_out_text (uiout, ": ");
10232 ui_out_field_string (uiout, "exp", w->exp_string);
10233 do_cleanups (ui_out_chain);
10236 /* Implement the "print_recreate" breakpoint_ops method for
10240 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10242 struct watchpoint *w = (struct watchpoint *) b;
10246 case bp_watchpoint:
10247 case bp_hardware_watchpoint:
10248 fprintf_unfiltered (fp, "watch");
10250 case bp_read_watchpoint:
10251 fprintf_unfiltered (fp, "rwatch");
10253 case bp_access_watchpoint:
10254 fprintf_unfiltered (fp, "awatch");
10257 internal_error (__FILE__, __LINE__,
10258 _("Invalid watchpoint type."));
10261 fprintf_unfiltered (fp, " %s", w->exp_string);
10262 print_recreate_thread (b, fp);
10265 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10267 static struct breakpoint_ops watchpoint_breakpoint_ops;
10269 /* Implement the "insert" breakpoint_ops method for
10270 masked hardware watchpoints. */
10273 insert_masked_watchpoint (struct bp_location *bl)
10275 struct watchpoint *w = (struct watchpoint *) bl->owner;
10277 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
10278 bl->watchpoint_type);
10281 /* Implement the "remove" breakpoint_ops method for
10282 masked hardware watchpoints. */
10285 remove_masked_watchpoint (struct bp_location *bl)
10287 struct watchpoint *w = (struct watchpoint *) bl->owner;
10289 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
10290 bl->watchpoint_type);
10293 /* Implement the "resources_needed" breakpoint_ops method for
10294 masked hardware watchpoints. */
10297 resources_needed_masked_watchpoint (const struct bp_location *bl)
10299 struct watchpoint *w = (struct watchpoint *) bl->owner;
10301 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
10304 /* Implement the "works_in_software_mode" breakpoint_ops method for
10305 masked hardware watchpoints. */
10308 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
10313 /* Implement the "print_it" breakpoint_ops method for
10314 masked hardware watchpoints. */
10316 static enum print_stop_action
10317 print_it_masked_watchpoint (bpstat bs)
10319 struct breakpoint *b = bs->breakpoint_at;
10320 struct ui_out *uiout = current_uiout;
10322 /* Masked watchpoints have only one location. */
10323 gdb_assert (b->loc && b->loc->next == NULL);
10327 case bp_hardware_watchpoint:
10328 annotate_watchpoint (b->number);
10329 if (ui_out_is_mi_like_p (uiout))
10330 ui_out_field_string
10332 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10335 case bp_read_watchpoint:
10336 if (ui_out_is_mi_like_p (uiout))
10337 ui_out_field_string
10339 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10342 case bp_access_watchpoint:
10343 if (ui_out_is_mi_like_p (uiout))
10344 ui_out_field_string
10346 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10349 internal_error (__FILE__, __LINE__,
10350 _("Invalid hardware watchpoint type."));
10354 ui_out_text (uiout, _("\n\
10355 Check the underlying instruction at PC for the memory\n\
10356 address and value which triggered this watchpoint.\n"));
10357 ui_out_text (uiout, "\n");
10359 /* More than one watchpoint may have been triggered. */
10360 return PRINT_UNKNOWN;
10363 /* Implement the "print_one_detail" breakpoint_ops method for
10364 masked hardware watchpoints. */
10367 print_one_detail_masked_watchpoint (const struct breakpoint *b,
10368 struct ui_out *uiout)
10370 struct watchpoint *w = (struct watchpoint *) b;
10372 /* Masked watchpoints have only one location. */
10373 gdb_assert (b->loc && b->loc->next == NULL);
10375 ui_out_text (uiout, "\tmask ");
10376 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
10377 ui_out_text (uiout, "\n");
10380 /* Implement the "print_mention" breakpoint_ops method for
10381 masked hardware watchpoints. */
10384 print_mention_masked_watchpoint (struct breakpoint *b)
10386 struct watchpoint *w = (struct watchpoint *) b;
10387 struct ui_out *uiout = current_uiout;
10388 struct cleanup *ui_out_chain;
10392 case bp_hardware_watchpoint:
10393 ui_out_text (uiout, "Masked hardware watchpoint ");
10394 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10396 case bp_read_watchpoint:
10397 ui_out_text (uiout, "Masked hardware read watchpoint ");
10398 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10400 case bp_access_watchpoint:
10401 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
10402 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10405 internal_error (__FILE__, __LINE__,
10406 _("Invalid hardware watchpoint type."));
10409 ui_out_field_int (uiout, "number", b->number);
10410 ui_out_text (uiout, ": ");
10411 ui_out_field_string (uiout, "exp", w->exp_string);
10412 do_cleanups (ui_out_chain);
10415 /* Implement the "print_recreate" breakpoint_ops method for
10416 masked hardware watchpoints. */
10419 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
10421 struct watchpoint *w = (struct watchpoint *) b;
10426 case bp_hardware_watchpoint:
10427 fprintf_unfiltered (fp, "watch");
10429 case bp_read_watchpoint:
10430 fprintf_unfiltered (fp, "rwatch");
10432 case bp_access_watchpoint:
10433 fprintf_unfiltered (fp, "awatch");
10436 internal_error (__FILE__, __LINE__,
10437 _("Invalid hardware watchpoint type."));
10440 sprintf_vma (tmp, w->hw_wp_mask);
10441 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
10442 print_recreate_thread (b, fp);
10445 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10447 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
10449 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10452 is_masked_watchpoint (const struct breakpoint *b)
10454 return b->ops == &masked_watchpoint_breakpoint_ops;
10457 /* accessflag: hw_write: watch write,
10458 hw_read: watch read,
10459 hw_access: watch access (read or write) */
10461 watch_command_1 (char *arg, int accessflag, int from_tty,
10462 int just_location, int internal)
10464 volatile struct gdb_exception e;
10465 struct breakpoint *b, *scope_breakpoint = NULL;
10466 struct expression *exp;
10467 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
10468 struct value *val, *mark, *result;
10469 struct frame_info *frame;
10470 char *exp_start = NULL;
10471 char *exp_end = NULL;
10472 char *tok, *end_tok;
10474 char *cond_start = NULL;
10475 char *cond_end = NULL;
10476 enum bptype bp_type;
10479 /* Flag to indicate whether we are going to use masks for
10480 the hardware watchpoint. */
10482 CORE_ADDR mask = 0;
10483 struct watchpoint *w;
10485 /* Make sure that we actually have parameters to parse. */
10486 if (arg != NULL && arg[0] != '\0')
10490 /* Look for "parameter value" pairs at the end
10491 of the arguments string. */
10492 for (tok = arg + strlen (arg) - 1; tok > arg; tok--)
10494 /* Skip whitespace at the end of the argument list. */
10495 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10498 /* Find the beginning of the last token.
10499 This is the value of the parameter. */
10500 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10502 value_start = tok + 1;
10504 /* Skip whitespace. */
10505 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10510 /* Find the beginning of the second to last token.
10511 This is the parameter itself. */
10512 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10515 toklen = end_tok - tok + 1;
10517 if (toklen == 6 && !strncmp (tok, "thread", 6))
10519 /* At this point we've found a "thread" token, which means
10520 the user is trying to set a watchpoint that triggers
10521 only in a specific thread. */
10525 error(_("You can specify only one thread."));
10527 /* Extract the thread ID from the next token. */
10528 thread = strtol (value_start, &endp, 0);
10530 /* Check if the user provided a valid numeric value for the
10532 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
10533 error (_("Invalid thread ID specification %s."), value_start);
10535 /* Check if the thread actually exists. */
10536 if (!valid_thread_id (thread))
10537 error (_("Unknown thread %d."), thread);
10539 else if (toklen == 4 && !strncmp (tok, "mask", 4))
10541 /* We've found a "mask" token, which means the user wants to
10542 create a hardware watchpoint that is going to have the mask
10544 struct value *mask_value, *mark;
10547 error(_("You can specify only one mask."));
10549 use_mask = just_location = 1;
10551 mark = value_mark ();
10552 mask_value = parse_to_comma_and_eval (&value_start);
10553 mask = value_as_address (mask_value);
10554 value_free_to_mark (mark);
10557 /* We didn't recognize what we found. We should stop here. */
10560 /* Truncate the string and get rid of the "parameter value" pair before
10561 the arguments string is parsed by the parse_exp_1 function. */
10566 /* Parse the rest of the arguments. */
10567 innermost_block = NULL;
10569 exp = parse_exp_1 (&arg, 0, 0, 0);
10571 /* Remove trailing whitespace from the expression before saving it.
10572 This makes the eventual display of the expression string a bit
10574 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
10577 /* Checking if the expression is not constant. */
10578 if (watchpoint_exp_is_const (exp))
10582 len = exp_end - exp_start;
10583 while (len > 0 && isspace (exp_start[len - 1]))
10585 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
10588 exp_valid_block = innermost_block;
10589 mark = value_mark ();
10590 fetch_subexp_value (exp, &pc, &val, &result, NULL);
10596 exp_valid_block = NULL;
10597 val = value_addr (result);
10598 release_value (val);
10599 value_free_to_mark (mark);
10603 ret = target_masked_watch_num_registers (value_as_address (val),
10606 error (_("This target does not support masked watchpoints."));
10607 else if (ret == -2)
10608 error (_("Invalid mask or memory region."));
10611 else if (val != NULL)
10612 release_value (val);
10614 tok = skip_spaces (arg);
10615 end_tok = skip_to_space (tok);
10617 toklen = end_tok - tok;
10618 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
10620 struct expression *cond;
10622 innermost_block = NULL;
10623 tok = cond_start = end_tok + 1;
10624 cond = parse_exp_1 (&tok, 0, 0, 0);
10626 /* The watchpoint expression may not be local, but the condition
10627 may still be. E.g.: `watch global if local > 0'. */
10628 cond_exp_valid_block = innermost_block;
10634 error (_("Junk at end of command."));
10636 if (accessflag == hw_read)
10637 bp_type = bp_read_watchpoint;
10638 else if (accessflag == hw_access)
10639 bp_type = bp_access_watchpoint;
10641 bp_type = bp_hardware_watchpoint;
10643 frame = block_innermost_frame (exp_valid_block);
10645 /* If the expression is "local", then set up a "watchpoint scope"
10646 breakpoint at the point where we've left the scope of the watchpoint
10647 expression. Create the scope breakpoint before the watchpoint, so
10648 that we will encounter it first in bpstat_stop_status. */
10649 if (exp_valid_block && frame)
10651 if (frame_id_p (frame_unwind_caller_id (frame)))
10654 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
10655 frame_unwind_caller_pc (frame),
10656 bp_watchpoint_scope,
10657 &momentary_breakpoint_ops);
10659 scope_breakpoint->enable_state = bp_enabled;
10661 /* Automatically delete the breakpoint when it hits. */
10662 scope_breakpoint->disposition = disp_del;
10664 /* Only break in the proper frame (help with recursion). */
10665 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
10667 /* Set the address at which we will stop. */
10668 scope_breakpoint->loc->gdbarch
10669 = frame_unwind_caller_arch (frame);
10670 scope_breakpoint->loc->requested_address
10671 = frame_unwind_caller_pc (frame);
10672 scope_breakpoint->loc->address
10673 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
10674 scope_breakpoint->loc->requested_address,
10675 scope_breakpoint->type);
10679 /* Now set up the breakpoint. */
10681 w = XCNEW (struct watchpoint);
10684 init_raw_breakpoint_without_location (b, NULL, bp_type,
10685 &masked_watchpoint_breakpoint_ops);
10687 init_raw_breakpoint_without_location (b, NULL, bp_type,
10688 &watchpoint_breakpoint_ops);
10689 b->thread = thread;
10690 b->disposition = disp_donttouch;
10691 b->pspace = current_program_space;
10693 w->exp_valid_block = exp_valid_block;
10694 w->cond_exp_valid_block = cond_exp_valid_block;
10697 struct type *t = value_type (val);
10698 CORE_ADDR addr = value_as_address (val);
10701 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
10702 name = type_to_string (t);
10704 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
10705 core_addr_to_string (addr));
10708 w->exp_string = xstrprintf ("-location %.*s",
10709 (int) (exp_end - exp_start), exp_start);
10711 /* The above expression is in C. */
10712 b->language = language_c;
10715 w->exp_string = savestring (exp_start, exp_end - exp_start);
10719 w->hw_wp_mask = mask;
10728 b->cond_string = savestring (cond_start, cond_end - cond_start);
10730 b->cond_string = 0;
10734 w->watchpoint_frame = get_frame_id (frame);
10735 w->watchpoint_thread = inferior_ptid;
10739 w->watchpoint_frame = null_frame_id;
10740 w->watchpoint_thread = null_ptid;
10743 if (scope_breakpoint != NULL)
10745 /* The scope breakpoint is related to the watchpoint. We will
10746 need to act on them together. */
10747 b->related_breakpoint = scope_breakpoint;
10748 scope_breakpoint->related_breakpoint = b;
10751 if (!just_location)
10752 value_free_to_mark (mark);
10754 TRY_CATCH (e, RETURN_MASK_ALL)
10756 /* Finally update the new watchpoint. This creates the locations
10757 that should be inserted. */
10758 update_watchpoint (w, 1);
10762 delete_breakpoint (b);
10763 throw_exception (e);
10766 install_breakpoint (internal, b, 1);
10769 /* Return count of debug registers needed to watch the given expression.
10770 If the watchpoint cannot be handled in hardware return zero. */
10773 can_use_hardware_watchpoint (struct value *v)
10775 int found_memory_cnt = 0;
10776 struct value *head = v;
10778 /* Did the user specifically forbid us to use hardware watchpoints? */
10779 if (!can_use_hw_watchpoints)
10782 /* Make sure that the value of the expression depends only upon
10783 memory contents, and values computed from them within GDB. If we
10784 find any register references or function calls, we can't use a
10785 hardware watchpoint.
10787 The idea here is that evaluating an expression generates a series
10788 of values, one holding the value of every subexpression. (The
10789 expression a*b+c has five subexpressions: a, b, a*b, c, and
10790 a*b+c.) GDB's values hold almost enough information to establish
10791 the criteria given above --- they identify memory lvalues,
10792 register lvalues, computed values, etcetera. So we can evaluate
10793 the expression, and then scan the chain of values that leaves
10794 behind to decide whether we can detect any possible change to the
10795 expression's final value using only hardware watchpoints.
10797 However, I don't think that the values returned by inferior
10798 function calls are special in any way. So this function may not
10799 notice that an expression involving an inferior function call
10800 can't be watched with hardware watchpoints. FIXME. */
10801 for (; v; v = value_next (v))
10803 if (VALUE_LVAL (v) == lval_memory)
10805 if (v != head && value_lazy (v))
10806 /* A lazy memory lvalue in the chain is one that GDB never
10807 needed to fetch; we either just used its address (e.g.,
10808 `a' in `a.b') or we never needed it at all (e.g., `a'
10809 in `a,b'). This doesn't apply to HEAD; if that is
10810 lazy then it was not readable, but watch it anyway. */
10814 /* Ahh, memory we actually used! Check if we can cover
10815 it with hardware watchpoints. */
10816 struct type *vtype = check_typedef (value_type (v));
10818 /* We only watch structs and arrays if user asked for it
10819 explicitly, never if they just happen to appear in a
10820 middle of some value chain. */
10822 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
10823 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
10825 CORE_ADDR vaddr = value_address (v);
10829 len = (target_exact_watchpoints
10830 && is_scalar_type_recursive (vtype))?
10831 1 : TYPE_LENGTH (value_type (v));
10833 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
10837 found_memory_cnt += num_regs;
10841 else if (VALUE_LVAL (v) != not_lval
10842 && deprecated_value_modifiable (v) == 0)
10843 return 0; /* These are values from the history (e.g., $1). */
10844 else if (VALUE_LVAL (v) == lval_register)
10845 return 0; /* Cannot watch a register with a HW watchpoint. */
10848 /* The expression itself looks suitable for using a hardware
10849 watchpoint, but give the target machine a chance to reject it. */
10850 return found_memory_cnt;
10854 watch_command_wrapper (char *arg, int from_tty, int internal)
10856 watch_command_1 (arg, hw_write, from_tty, 0, internal);
10859 /* A helper function that looks for an argument at the start of a
10860 string. The argument must also either be at the end of the string,
10861 or be followed by whitespace. Returns 1 if it finds the argument,
10862 0 otherwise. If the argument is found, it updates *STR. */
10865 check_for_argument (char **str, char *arg, int arg_len)
10867 if (strncmp (*str, arg, arg_len) == 0
10868 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
10876 /* A helper function that looks for the "-location" argument and then
10877 calls watch_command_1. */
10880 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
10882 int just_location = 0;
10885 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
10886 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
10888 arg = skip_spaces (arg);
10892 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
10896 watch_command (char *arg, int from_tty)
10898 watch_maybe_just_location (arg, hw_write, from_tty);
10902 rwatch_command_wrapper (char *arg, int from_tty, int internal)
10904 watch_command_1 (arg, hw_read, from_tty, 0, internal);
10908 rwatch_command (char *arg, int from_tty)
10910 watch_maybe_just_location (arg, hw_read, from_tty);
10914 awatch_command_wrapper (char *arg, int from_tty, int internal)
10916 watch_command_1 (arg, hw_access, from_tty, 0, internal);
10920 awatch_command (char *arg, int from_tty)
10922 watch_maybe_just_location (arg, hw_access, from_tty);
10926 /* Helper routines for the until_command routine in infcmd.c. Here
10927 because it uses the mechanisms of breakpoints. */
10929 struct until_break_command_continuation_args
10931 struct breakpoint *breakpoint;
10932 struct breakpoint *breakpoint2;
10936 /* This function is called by fetch_inferior_event via the
10937 cmd_continuation pointer, to complete the until command. It takes
10938 care of cleaning up the temporary breakpoints set up by the until
10941 until_break_command_continuation (void *arg, int err)
10943 struct until_break_command_continuation_args *a = arg;
10945 delete_breakpoint (a->breakpoint);
10946 if (a->breakpoint2)
10947 delete_breakpoint (a->breakpoint2);
10948 delete_longjmp_breakpoint (a->thread_num);
10952 until_break_command (char *arg, int from_tty, int anywhere)
10954 struct symtabs_and_lines sals;
10955 struct symtab_and_line sal;
10956 struct frame_info *frame;
10957 struct gdbarch *frame_gdbarch;
10958 struct frame_id stack_frame_id;
10959 struct frame_id caller_frame_id;
10960 struct breakpoint *breakpoint;
10961 struct breakpoint *breakpoint2 = NULL;
10962 struct cleanup *old_chain;
10964 struct thread_info *tp;
10966 clear_proceed_status ();
10968 /* Set a breakpoint where the user wants it and at return from
10971 if (last_displayed_sal_is_valid ())
10972 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
10973 get_last_displayed_symtab (),
10974 get_last_displayed_line ());
10976 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
10977 (struct symtab *) NULL, 0);
10979 if (sals.nelts != 1)
10980 error (_("Couldn't get information on specified line."));
10982 sal = sals.sals[0];
10983 xfree (sals.sals); /* malloc'd, so freed. */
10986 error (_("Junk at end of arguments."));
10988 resolve_sal_pc (&sal);
10990 tp = inferior_thread ();
10993 old_chain = make_cleanup (null_cleanup, NULL);
10995 /* Note linespec handling above invalidates the frame chain.
10996 Installing a breakpoint also invalidates the frame chain (as it
10997 may need to switch threads), so do any frame handling before
11000 frame = get_selected_frame (NULL);
11001 frame_gdbarch = get_frame_arch (frame);
11002 stack_frame_id = get_stack_frame_id (frame);
11003 caller_frame_id = frame_unwind_caller_id (frame);
11005 /* Keep within the current frame, or in frames called by the current
11008 if (frame_id_p (caller_frame_id))
11010 struct symtab_and_line sal2;
11012 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11013 sal2.pc = frame_unwind_caller_pc (frame);
11014 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
11018 make_cleanup_delete_breakpoint (breakpoint2);
11020 set_longjmp_breakpoint (tp, caller_frame_id);
11021 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11024 /* set_momentary_breakpoint could invalidate FRAME. */
11028 /* If the user told us to continue until a specified location,
11029 we don't specify a frame at which we need to stop. */
11030 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11031 null_frame_id, bp_until);
11033 /* Otherwise, specify the selected frame, because we want to stop
11034 only at the very same frame. */
11035 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11036 stack_frame_id, bp_until);
11037 make_cleanup_delete_breakpoint (breakpoint);
11039 proceed (-1, GDB_SIGNAL_DEFAULT, 0);
11041 /* If we are running asynchronously, and proceed call above has
11042 actually managed to start the target, arrange for breakpoints to
11043 be deleted when the target stops. Otherwise, we're already
11044 stopped and delete breakpoints via cleanup chain. */
11046 if (target_can_async_p () && is_running (inferior_ptid))
11048 struct until_break_command_continuation_args *args;
11049 args = xmalloc (sizeof (*args));
11051 args->breakpoint = breakpoint;
11052 args->breakpoint2 = breakpoint2;
11053 args->thread_num = thread;
11055 discard_cleanups (old_chain);
11056 add_continuation (inferior_thread (),
11057 until_break_command_continuation, args,
11061 do_cleanups (old_chain);
11064 /* This function attempts to parse an optional "if <cond>" clause
11065 from the arg string. If one is not found, it returns NULL.
11067 Else, it returns a pointer to the condition string. (It does not
11068 attempt to evaluate the string against a particular block.) And,
11069 it updates arg to point to the first character following the parsed
11070 if clause in the arg string. */
11073 ep_parse_optional_if_clause (char **arg)
11077 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11080 /* Skip the "if" keyword. */
11083 /* Skip any extra leading whitespace, and record the start of the
11084 condition string. */
11085 *arg = skip_spaces (*arg);
11086 cond_string = *arg;
11088 /* Assume that the condition occupies the remainder of the arg
11090 (*arg) += strlen (cond_string);
11092 return cond_string;
11095 /* Commands to deal with catching events, such as signals, exceptions,
11096 process start/exit, etc. */
11100 catch_fork_temporary, catch_vfork_temporary,
11101 catch_fork_permanent, catch_vfork_permanent
11106 catch_fork_command_1 (char *arg, int from_tty,
11107 struct cmd_list_element *command)
11109 struct gdbarch *gdbarch = get_current_arch ();
11110 char *cond_string = NULL;
11111 catch_fork_kind fork_kind;
11114 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
11115 tempflag = (fork_kind == catch_fork_temporary
11116 || fork_kind == catch_vfork_temporary);
11120 arg = skip_spaces (arg);
11122 /* The allowed syntax is:
11124 catch [v]fork if <cond>
11126 First, check if there's an if clause. */
11127 cond_string = ep_parse_optional_if_clause (&arg);
11129 if ((*arg != '\0') && !isspace (*arg))
11130 error (_("Junk at end of arguments."));
11132 /* If this target supports it, create a fork or vfork catchpoint
11133 and enable reporting of such events. */
11136 case catch_fork_temporary:
11137 case catch_fork_permanent:
11138 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11139 &catch_fork_breakpoint_ops);
11141 case catch_vfork_temporary:
11142 case catch_vfork_permanent:
11143 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11144 &catch_vfork_breakpoint_ops);
11147 error (_("unsupported or unknown fork kind; cannot catch it"));
11153 catch_exec_command_1 (char *arg, int from_tty,
11154 struct cmd_list_element *command)
11156 struct exec_catchpoint *c;
11157 struct gdbarch *gdbarch = get_current_arch ();
11159 char *cond_string = NULL;
11161 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11165 arg = skip_spaces (arg);
11167 /* The allowed syntax is:
11169 catch exec if <cond>
11171 First, check if there's an if clause. */
11172 cond_string = ep_parse_optional_if_clause (&arg);
11174 if ((*arg != '\0') && !isspace (*arg))
11175 error (_("Junk at end of arguments."));
11177 c = XNEW (struct exec_catchpoint);
11178 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
11179 &catch_exec_breakpoint_ops);
11180 c->exec_pathname = NULL;
11182 install_breakpoint (0, &c->base, 1);
11185 static enum print_stop_action
11186 print_it_exception_catchpoint (bpstat bs)
11188 struct ui_out *uiout = current_uiout;
11189 struct breakpoint *b = bs->breakpoint_at;
11190 int bp_temp, bp_throw;
11192 annotate_catchpoint (b->number);
11194 bp_throw = strstr (b->addr_string, "throw") != NULL;
11195 if (b->loc->address != b->loc->requested_address)
11196 breakpoint_adjustment_warning (b->loc->requested_address,
11199 bp_temp = b->disposition == disp_del;
11200 ui_out_text (uiout,
11201 bp_temp ? "Temporary catchpoint "
11203 if (!ui_out_is_mi_like_p (uiout))
11204 ui_out_field_int (uiout, "bkptno", b->number);
11205 ui_out_text (uiout,
11206 bp_throw ? " (exception thrown), "
11207 : " (exception caught), ");
11208 if (ui_out_is_mi_like_p (uiout))
11210 ui_out_field_string (uiout, "reason",
11211 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
11212 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
11213 ui_out_field_int (uiout, "bkptno", b->number);
11215 return PRINT_SRC_AND_LOC;
11219 print_one_exception_catchpoint (struct breakpoint *b,
11220 struct bp_location **last_loc)
11222 struct value_print_options opts;
11223 struct ui_out *uiout = current_uiout;
11225 get_user_print_options (&opts);
11226 if (opts.addressprint)
11228 annotate_field (4);
11229 if (b->loc == NULL || b->loc->shlib_disabled)
11230 ui_out_field_string (uiout, "addr", "<PENDING>");
11232 ui_out_field_core_addr (uiout, "addr",
11233 b->loc->gdbarch, b->loc->address);
11235 annotate_field (5);
11237 *last_loc = b->loc;
11238 if (strstr (b->addr_string, "throw") != NULL)
11239 ui_out_field_string (uiout, "what", "exception throw");
11241 ui_out_field_string (uiout, "what", "exception catch");
11245 print_mention_exception_catchpoint (struct breakpoint *b)
11247 struct ui_out *uiout = current_uiout;
11251 bp_temp = b->disposition == disp_del;
11252 bp_throw = strstr (b->addr_string, "throw") != NULL;
11253 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
11254 : _("Catchpoint "));
11255 ui_out_field_int (uiout, "bkptno", b->number);
11256 ui_out_text (uiout, bp_throw ? _(" (throw)")
11260 /* Implement the "print_recreate" breakpoint_ops method for throw and
11261 catch catchpoints. */
11264 print_recreate_exception_catchpoint (struct breakpoint *b,
11265 struct ui_file *fp)
11270 bp_temp = b->disposition == disp_del;
11271 bp_throw = strstr (b->addr_string, "throw") != NULL;
11272 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
11273 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
11274 print_recreate_thread (b, fp);
11277 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
11280 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
11281 enum exception_event_kind ex_event, int from_tty)
11283 char *trigger_func_name;
11285 if (ex_event == EX_EVENT_CATCH)
11286 trigger_func_name = "__cxa_begin_catch";
11288 trigger_func_name = "__cxa_throw";
11290 create_breakpoint (get_current_arch (),
11291 trigger_func_name, cond_string, -1, NULL,
11292 0 /* condition and thread are valid. */,
11293 tempflag, bp_breakpoint,
11295 AUTO_BOOLEAN_TRUE /* pending */,
11296 &gnu_v3_exception_catchpoint_ops, from_tty,
11304 /* Deal with "catch catch" and "catch throw" commands. */
11307 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
11308 int tempflag, int from_tty)
11310 char *cond_string = NULL;
11314 arg = skip_spaces (arg);
11316 cond_string = ep_parse_optional_if_clause (&arg);
11318 if ((*arg != '\0') && !isspace (*arg))
11319 error (_("Junk at end of arguments."));
11321 if (ex_event != EX_EVENT_THROW
11322 && ex_event != EX_EVENT_CATCH)
11323 error (_("Unsupported or unknown exception event; cannot catch it"));
11325 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
11328 warning (_("Unsupported with this platform/compiler combination."));
11331 /* Implementation of "catch catch" command. */
11334 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
11336 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11338 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
11341 /* Implementation of "catch throw" command. */
11344 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
11346 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11348 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
11352 init_ada_exception_breakpoint (struct breakpoint *b,
11353 struct gdbarch *gdbarch,
11354 struct symtab_and_line sal,
11356 const struct breakpoint_ops *ops,
11362 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11364 loc_gdbarch = gdbarch;
11366 describe_other_breakpoints (loc_gdbarch,
11367 sal.pspace, sal.pc, sal.section, -1);
11368 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11369 version for exception catchpoints, because two catchpoints
11370 used for different exception names will use the same address.
11371 In this case, a "breakpoint ... also set at..." warning is
11372 unproductive. Besides, the warning phrasing is also a bit
11373 inappropriate, we should use the word catchpoint, and tell
11374 the user what type of catchpoint it is. The above is good
11375 enough for now, though. */
11378 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
11380 b->enable_state = bp_enabled;
11381 b->disposition = tempflag ? disp_del : disp_donttouch;
11382 b->addr_string = addr_string;
11383 b->language = language_ada;
11386 /* Splits the argument using space as delimiter. Returns an xmalloc'd
11387 filter list, or NULL if no filtering is required. */
11389 catch_syscall_split_args (char *arg)
11391 VEC(int) *result = NULL;
11392 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
11394 while (*arg != '\0')
11396 int i, syscall_number;
11398 char cur_name[128];
11401 /* Skip whitespace. */
11402 while (isspace (*arg))
11405 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
11406 cur_name[i] = arg[i];
11407 cur_name[i] = '\0';
11410 /* Check if the user provided a syscall name or a number. */
11411 syscall_number = (int) strtol (cur_name, &endptr, 0);
11412 if (*endptr == '\0')
11413 get_syscall_by_number (syscall_number, &s);
11416 /* We have a name. Let's check if it's valid and convert it
11418 get_syscall_by_name (cur_name, &s);
11420 if (s.number == UNKNOWN_SYSCALL)
11421 /* Here we have to issue an error instead of a warning,
11422 because GDB cannot do anything useful if there's no
11423 syscall number to be caught. */
11424 error (_("Unknown syscall name '%s'."), cur_name);
11427 /* Ok, it's valid. */
11428 VEC_safe_push (int, result, s.number);
11431 discard_cleanups (cleanup);
11435 /* Implement the "catch syscall" command. */
11438 catch_syscall_command_1 (char *arg, int from_tty,
11439 struct cmd_list_element *command)
11444 struct gdbarch *gdbarch = get_current_arch ();
11446 /* Checking if the feature if supported. */
11447 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
11448 error (_("The feature 'catch syscall' is not supported on \
11449 this architecture yet."));
11451 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11453 arg = skip_spaces (arg);
11455 /* We need to do this first "dummy" translation in order
11456 to get the syscall XML file loaded or, most important,
11457 to display a warning to the user if there's no XML file
11458 for his/her architecture. */
11459 get_syscall_by_number (0, &s);
11461 /* The allowed syntax is:
11463 catch syscall <name | number> [<name | number> ... <name | number>]
11465 Let's check if there's a syscall name. */
11468 filter = catch_syscall_split_args (arg);
11472 create_syscall_event_catchpoint (tempflag, filter,
11473 &catch_syscall_breakpoint_ops);
11477 catch_command (char *arg, int from_tty)
11479 error (_("Catch requires an event name."));
11484 tcatch_command (char *arg, int from_tty)
11486 error (_("Catch requires an event name."));
11489 /* A qsort comparison function that sorts breakpoints in order. */
11492 compare_breakpoints (const void *a, const void *b)
11494 const breakpoint_p *ba = a;
11495 uintptr_t ua = (uintptr_t) *ba;
11496 const breakpoint_p *bb = b;
11497 uintptr_t ub = (uintptr_t) *bb;
11499 if ((*ba)->number < (*bb)->number)
11501 else if ((*ba)->number > (*bb)->number)
11504 /* Now sort by address, in case we see, e..g, two breakpoints with
11508 return ub > ub ? 1 : 0;
11511 /* Delete breakpoints by address or line. */
11514 clear_command (char *arg, int from_tty)
11516 struct breakpoint *b, *prev;
11517 VEC(breakpoint_p) *found = 0;
11520 struct symtabs_and_lines sals;
11521 struct symtab_and_line sal;
11523 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
11527 sals = decode_line_with_current_source (arg,
11528 (DECODE_LINE_FUNFIRSTLINE
11529 | DECODE_LINE_LIST_MODE));
11534 sals.sals = (struct symtab_and_line *)
11535 xmalloc (sizeof (struct symtab_and_line));
11536 make_cleanup (xfree, sals.sals);
11537 init_sal (&sal); /* Initialize to zeroes. */
11539 /* Set sal's line, symtab, pc, and pspace to the values
11540 corresponding to the last call to print_frame_info. If the
11541 codepoint is not valid, this will set all the fields to 0. */
11542 get_last_displayed_sal (&sal);
11543 if (sal.symtab == 0)
11544 error (_("No source file specified."));
11546 sals.sals[0] = sal;
11552 /* We don't call resolve_sal_pc here. That's not as bad as it
11553 seems, because all existing breakpoints typically have both
11554 file/line and pc set. So, if clear is given file/line, we can
11555 match this to existing breakpoint without obtaining pc at all.
11557 We only support clearing given the address explicitly
11558 present in breakpoint table. Say, we've set breakpoint
11559 at file:line. There were several PC values for that file:line,
11560 due to optimization, all in one block.
11562 We've picked one PC value. If "clear" is issued with another
11563 PC corresponding to the same file:line, the breakpoint won't
11564 be cleared. We probably can still clear the breakpoint, but
11565 since the other PC value is never presented to user, user
11566 can only find it by guessing, and it does not seem important
11567 to support that. */
11569 /* For each line spec given, delete bps which correspond to it. Do
11570 it in two passes, solely to preserve the current behavior that
11571 from_tty is forced true if we delete more than one
11575 make_cleanup (VEC_cleanup (breakpoint_p), &found);
11576 for (i = 0; i < sals.nelts; i++)
11578 int is_abs, sal_name_len;
11580 /* If exact pc given, clear bpts at that pc.
11581 If line given (pc == 0), clear all bpts on specified line.
11582 If defaulting, clear all bpts on default line
11585 defaulting sal.pc != 0 tests to do
11590 1 0 <can't happen> */
11592 sal = sals.sals[i];
11593 is_abs = sal.symtab == NULL ? 1 : IS_ABSOLUTE_PATH (sal.symtab->filename);
11594 sal_name_len = is_abs ? 0 : strlen (sal.symtab->filename);
11596 /* Find all matching breakpoints and add them to 'found'. */
11597 ALL_BREAKPOINTS (b)
11600 /* Are we going to delete b? */
11601 if (b->type != bp_none && !is_watchpoint (b))
11603 struct bp_location *loc = b->loc;
11604 for (; loc; loc = loc->next)
11606 /* If the user specified file:line, don't allow a PC
11607 match. This matches historical gdb behavior. */
11608 int pc_match = (!sal.explicit_line
11610 && (loc->pspace == sal.pspace)
11611 && (loc->address == sal.pc)
11612 && (!section_is_overlay (loc->section)
11613 || loc->section == sal.section));
11614 int line_match = 0;
11616 if ((default_match || sal.explicit_line)
11617 && loc->source_file != NULL
11618 && sal.symtab != NULL
11619 && sal.pspace == loc->pspace
11620 && loc->line_number == sal.line)
11622 if (filename_cmp (loc->source_file,
11623 sal.symtab->filename) == 0)
11625 else if (!IS_ABSOLUTE_PATH (sal.symtab->filename)
11626 && compare_filenames_for_search (loc->source_file,
11627 sal.symtab->filename,
11632 if (pc_match || line_match)
11641 VEC_safe_push(breakpoint_p, found, b);
11645 /* Now go thru the 'found' chain and delete them. */
11646 if (VEC_empty(breakpoint_p, found))
11649 error (_("No breakpoint at %s."), arg);
11651 error (_("No breakpoint at this line."));
11654 /* Remove duplicates from the vec. */
11655 qsort (VEC_address (breakpoint_p, found),
11656 VEC_length (breakpoint_p, found),
11657 sizeof (breakpoint_p),
11658 compare_breakpoints);
11659 prev = VEC_index (breakpoint_p, found, 0);
11660 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
11664 VEC_ordered_remove (breakpoint_p, found, ix);
11669 if (VEC_length(breakpoint_p, found) > 1)
11670 from_tty = 1; /* Always report if deleted more than one. */
11673 if (VEC_length(breakpoint_p, found) == 1)
11674 printf_unfiltered (_("Deleted breakpoint "));
11676 printf_unfiltered (_("Deleted breakpoints "));
11678 breakpoints_changed ();
11680 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
11683 printf_unfiltered ("%d ", b->number);
11684 delete_breakpoint (b);
11687 putchar_unfiltered ('\n');
11689 do_cleanups (cleanups);
11692 /* Delete breakpoint in BS if they are `delete' breakpoints and
11693 all breakpoints that are marked for deletion, whether hit or not.
11694 This is called after any breakpoint is hit, or after errors. */
11697 breakpoint_auto_delete (bpstat bs)
11699 struct breakpoint *b, *b_tmp;
11701 for (; bs; bs = bs->next)
11702 if (bs->breakpoint_at
11703 && bs->breakpoint_at->disposition == disp_del
11705 delete_breakpoint (bs->breakpoint_at);
11707 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11709 if (b->disposition == disp_del_at_next_stop)
11710 delete_breakpoint (b);
11714 /* A comparison function for bp_location AP and BP being interfaced to
11715 qsort. Sort elements primarily by their ADDRESS (no matter what
11716 does breakpoint_address_is_meaningful say for its OWNER),
11717 secondarily by ordering first bp_permanent OWNERed elements and
11718 terciarily just ensuring the array is sorted stable way despite
11719 qsort being an unstable algorithm. */
11722 bp_location_compare (const void *ap, const void *bp)
11724 struct bp_location *a = *(void **) ap;
11725 struct bp_location *b = *(void **) bp;
11726 /* A and B come from existing breakpoints having non-NULL OWNER. */
11727 int a_perm = a->owner->enable_state == bp_permanent;
11728 int b_perm = b->owner->enable_state == bp_permanent;
11730 if (a->address != b->address)
11731 return (a->address > b->address) - (a->address < b->address);
11733 /* Sort locations at the same address by their pspace number, keeping
11734 locations of the same inferior (in a multi-inferior environment)
11737 if (a->pspace->num != b->pspace->num)
11738 return ((a->pspace->num > b->pspace->num)
11739 - (a->pspace->num < b->pspace->num));
11741 /* Sort permanent breakpoints first. */
11742 if (a_perm != b_perm)
11743 return (a_perm < b_perm) - (a_perm > b_perm);
11745 /* Make the internal GDB representation stable across GDB runs
11746 where A and B memory inside GDB can differ. Breakpoint locations of
11747 the same type at the same address can be sorted in arbitrary order. */
11749 if (a->owner->number != b->owner->number)
11750 return ((a->owner->number > b->owner->number)
11751 - (a->owner->number < b->owner->number));
11753 return (a > b) - (a < b);
11756 /* Set bp_location_placed_address_before_address_max and
11757 bp_location_shadow_len_after_address_max according to the current
11758 content of the bp_location array. */
11761 bp_location_target_extensions_update (void)
11763 struct bp_location *bl, **blp_tmp;
11765 bp_location_placed_address_before_address_max = 0;
11766 bp_location_shadow_len_after_address_max = 0;
11768 ALL_BP_LOCATIONS (bl, blp_tmp)
11770 CORE_ADDR start, end, addr;
11772 if (!bp_location_has_shadow (bl))
11775 start = bl->target_info.placed_address;
11776 end = start + bl->target_info.shadow_len;
11778 gdb_assert (bl->address >= start);
11779 addr = bl->address - start;
11780 if (addr > bp_location_placed_address_before_address_max)
11781 bp_location_placed_address_before_address_max = addr;
11783 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11785 gdb_assert (bl->address < end);
11786 addr = end - bl->address;
11787 if (addr > bp_location_shadow_len_after_address_max)
11788 bp_location_shadow_len_after_address_max = addr;
11792 /* Download tracepoint locations if they haven't been. */
11795 download_tracepoint_locations (void)
11797 struct bp_location *bl, **blp_tmp;
11798 struct cleanup *old_chain;
11800 if (!target_can_download_tracepoint ())
11803 old_chain = save_current_space_and_thread ();
11805 ALL_BP_LOCATIONS (bl, blp_tmp)
11807 struct tracepoint *t;
11809 if (!is_tracepoint (bl->owner))
11812 if ((bl->owner->type == bp_fast_tracepoint
11813 ? !may_insert_fast_tracepoints
11814 : !may_insert_tracepoints))
11817 /* In tracepoint, locations are _never_ duplicated, so
11818 should_be_inserted is equivalent to
11819 unduplicated_should_be_inserted. */
11820 if (!should_be_inserted (bl) || bl->inserted)
11823 switch_to_program_space_and_thread (bl->pspace);
11825 target_download_tracepoint (bl);
11828 t = (struct tracepoint *) bl->owner;
11829 t->number_on_target = bl->owner->number;
11832 do_cleanups (old_chain);
11835 /* Swap the insertion/duplication state between two locations. */
11838 swap_insertion (struct bp_location *left, struct bp_location *right)
11840 const int left_inserted = left->inserted;
11841 const int left_duplicate = left->duplicate;
11842 const int left_needs_update = left->needs_update;
11843 const struct bp_target_info left_target_info = left->target_info;
11845 /* Locations of tracepoints can never be duplicated. */
11846 if (is_tracepoint (left->owner))
11847 gdb_assert (!left->duplicate);
11848 if (is_tracepoint (right->owner))
11849 gdb_assert (!right->duplicate);
11851 left->inserted = right->inserted;
11852 left->duplicate = right->duplicate;
11853 left->needs_update = right->needs_update;
11854 left->target_info = right->target_info;
11855 right->inserted = left_inserted;
11856 right->duplicate = left_duplicate;
11857 right->needs_update = left_needs_update;
11858 right->target_info = left_target_info;
11861 /* Force the re-insertion of the locations at ADDRESS. This is called
11862 once a new/deleted/modified duplicate location is found and we are evaluating
11863 conditions on the target's side. Such conditions need to be updated on
11867 force_breakpoint_reinsertion (struct bp_location *bl)
11869 struct bp_location **locp = NULL, **loc2p;
11870 struct bp_location *loc;
11871 CORE_ADDR address = 0;
11874 address = bl->address;
11875 pspace_num = bl->pspace->num;
11877 /* This is only meaningful if the target is
11878 evaluating conditions and if the user has
11879 opted for condition evaluation on the target's
11881 if (gdb_evaluates_breakpoint_condition_p ()
11882 || !target_supports_evaluation_of_breakpoint_conditions ())
11885 /* Flag all breakpoint locations with this address and
11886 the same program space as the location
11887 as "its condition has changed". We need to
11888 update the conditions on the target's side. */
11889 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
11893 if (!is_breakpoint (loc->owner)
11894 || pspace_num != loc->pspace->num)
11897 /* Flag the location appropriately. We use a different state to
11898 let everyone know that we already updated the set of locations
11899 with addr bl->address and program space bl->pspace. This is so
11900 we don't have to keep calling these functions just to mark locations
11901 that have already been marked. */
11902 loc->condition_changed = condition_updated;
11904 /* Free the agent expression bytecode as well. We will compute
11906 if (loc->cond_bytecode)
11908 free_agent_expr (loc->cond_bytecode);
11909 loc->cond_bytecode = NULL;
11914 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
11915 into the inferior, only remove already-inserted locations that no
11916 longer should be inserted. Functions that delete a breakpoint or
11917 breakpoints should pass false, so that deleting a breakpoint
11918 doesn't have the side effect of inserting the locations of other
11919 breakpoints that are marked not-inserted, but should_be_inserted
11920 returns true on them.
11922 This behaviour is useful is situations close to tear-down -- e.g.,
11923 after an exec, while the target still has execution, but breakpoint
11924 shadows of the previous executable image should *NOT* be restored
11925 to the new image; or before detaching, where the target still has
11926 execution and wants to delete breakpoints from GDB's lists, and all
11927 breakpoints had already been removed from the inferior. */
11930 update_global_location_list (int should_insert)
11932 struct breakpoint *b;
11933 struct bp_location **locp, *loc;
11934 struct cleanup *cleanups;
11935 /* Last breakpoint location address that was marked for update. */
11936 CORE_ADDR last_addr = 0;
11937 /* Last breakpoint location program space that was marked for update. */
11938 int last_pspace_num = -1;
11940 /* Used in the duplicates detection below. When iterating over all
11941 bp_locations, points to the first bp_location of a given address.
11942 Breakpoints and watchpoints of different types are never
11943 duplicates of each other. Keep one pointer for each type of
11944 breakpoint/watchpoint, so we only need to loop over all locations
11946 struct bp_location *bp_loc_first; /* breakpoint */
11947 struct bp_location *wp_loc_first; /* hardware watchpoint */
11948 struct bp_location *awp_loc_first; /* access watchpoint */
11949 struct bp_location *rwp_loc_first; /* read watchpoint */
11951 /* Saved former bp_location array which we compare against the newly
11952 built bp_location from the current state of ALL_BREAKPOINTS. */
11953 struct bp_location **old_location, **old_locp;
11954 unsigned old_location_count;
11956 old_location = bp_location;
11957 old_location_count = bp_location_count;
11958 bp_location = NULL;
11959 bp_location_count = 0;
11960 cleanups = make_cleanup (xfree, old_location);
11962 ALL_BREAKPOINTS (b)
11963 for (loc = b->loc; loc; loc = loc->next)
11964 bp_location_count++;
11966 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
11967 locp = bp_location;
11968 ALL_BREAKPOINTS (b)
11969 for (loc = b->loc; loc; loc = loc->next)
11971 qsort (bp_location, bp_location_count, sizeof (*bp_location),
11972 bp_location_compare);
11974 bp_location_target_extensions_update ();
11976 /* Identify bp_location instances that are no longer present in the
11977 new list, and therefore should be freed. Note that it's not
11978 necessary that those locations should be removed from inferior --
11979 if there's another location at the same address (previously
11980 marked as duplicate), we don't need to remove/insert the
11983 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11984 and former bp_location array state respectively. */
11986 locp = bp_location;
11987 for (old_locp = old_location; old_locp < old_location + old_location_count;
11990 struct bp_location *old_loc = *old_locp;
11991 struct bp_location **loc2p;
11993 /* Tells if 'old_loc' is found among the new locations. If
11994 not, we have to free it. */
11995 int found_object = 0;
11996 /* Tells if the location should remain inserted in the target. */
11997 int keep_in_target = 0;
12000 /* Skip LOCP entries which will definitely never be needed.
12001 Stop either at or being the one matching OLD_LOC. */
12002 while (locp < bp_location + bp_location_count
12003 && (*locp)->address < old_loc->address)
12007 (loc2p < bp_location + bp_location_count
12008 && (*loc2p)->address == old_loc->address);
12011 /* Check if this is a new/duplicated location or a duplicated
12012 location that had its condition modified. If so, we want to send
12013 its condition to the target if evaluation of conditions is taking
12015 if ((*loc2p)->condition_changed == condition_modified
12016 && (last_addr != old_loc->address
12017 || last_pspace_num != old_loc->pspace->num))
12019 force_breakpoint_reinsertion (*loc2p);
12020 last_pspace_num = old_loc->pspace->num;
12023 if (*loc2p == old_loc)
12027 /* We have already handled this address, update it so that we don't
12028 have to go through updates again. */
12029 last_addr = old_loc->address;
12031 /* Target-side condition evaluation: Handle deleted locations. */
12033 force_breakpoint_reinsertion (old_loc);
12035 /* If this location is no longer present, and inserted, look if
12036 there's maybe a new location at the same address. If so,
12037 mark that one inserted, and don't remove this one. This is
12038 needed so that we don't have a time window where a breakpoint
12039 at certain location is not inserted. */
12041 if (old_loc->inserted)
12043 /* If the location is inserted now, we might have to remove
12046 if (found_object && should_be_inserted (old_loc))
12048 /* The location is still present in the location list,
12049 and still should be inserted. Don't do anything. */
12050 keep_in_target = 1;
12054 /* This location still exists, but it won't be kept in the
12055 target since it may have been disabled. We proceed to
12056 remove its target-side condition. */
12058 /* The location is either no longer present, or got
12059 disabled. See if there's another location at the
12060 same address, in which case we don't need to remove
12061 this one from the target. */
12063 /* OLD_LOC comes from existing struct breakpoint. */
12064 if (breakpoint_address_is_meaningful (old_loc->owner))
12067 (loc2p < bp_location + bp_location_count
12068 && (*loc2p)->address == old_loc->address);
12071 struct bp_location *loc2 = *loc2p;
12073 if (breakpoint_locations_match (loc2, old_loc))
12075 /* Read watchpoint locations are switched to
12076 access watchpoints, if the former are not
12077 supported, but the latter are. */
12078 if (is_hardware_watchpoint (old_loc->owner))
12080 gdb_assert (is_hardware_watchpoint (loc2->owner));
12081 loc2->watchpoint_type = old_loc->watchpoint_type;
12084 /* loc2 is a duplicated location. We need to check
12085 if it should be inserted in case it will be
12087 if (loc2 != old_loc
12088 && unduplicated_should_be_inserted (loc2))
12090 swap_insertion (old_loc, loc2);
12091 keep_in_target = 1;
12099 if (!keep_in_target)
12101 if (remove_breakpoint (old_loc, mark_uninserted))
12103 /* This is just about all we can do. We could keep
12104 this location on the global list, and try to
12105 remove it next time, but there's no particular
12106 reason why we will succeed next time.
12108 Note that at this point, old_loc->owner is still
12109 valid, as delete_breakpoint frees the breakpoint
12110 only after calling us. */
12111 printf_filtered (_("warning: Error removing "
12112 "breakpoint %d\n"),
12113 old_loc->owner->number);
12121 if (removed && non_stop
12122 && breakpoint_address_is_meaningful (old_loc->owner)
12123 && !is_hardware_watchpoint (old_loc->owner))
12125 /* This location was removed from the target. In
12126 non-stop mode, a race condition is possible where
12127 we've removed a breakpoint, but stop events for that
12128 breakpoint are already queued and will arrive later.
12129 We apply an heuristic to be able to distinguish such
12130 SIGTRAPs from other random SIGTRAPs: we keep this
12131 breakpoint location for a bit, and will retire it
12132 after we see some number of events. The theory here
12133 is that reporting of events should, "on the average",
12134 be fair, so after a while we'll see events from all
12135 threads that have anything of interest, and no longer
12136 need to keep this breakpoint location around. We
12137 don't hold locations forever so to reduce chances of
12138 mistaking a non-breakpoint SIGTRAP for a breakpoint
12141 The heuristic failing can be disastrous on
12142 decr_pc_after_break targets.
12144 On decr_pc_after_break targets, like e.g., x86-linux,
12145 if we fail to recognize a late breakpoint SIGTRAP,
12146 because events_till_retirement has reached 0 too
12147 soon, we'll fail to do the PC adjustment, and report
12148 a random SIGTRAP to the user. When the user resumes
12149 the inferior, it will most likely immediately crash
12150 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12151 corrupted, because of being resumed e.g., in the
12152 middle of a multi-byte instruction, or skipped a
12153 one-byte instruction. This was actually seen happen
12154 on native x86-linux, and should be less rare on
12155 targets that do not support new thread events, like
12156 remote, due to the heuristic depending on
12159 Mistaking a random SIGTRAP for a breakpoint trap
12160 causes similar symptoms (PC adjustment applied when
12161 it shouldn't), but then again, playing with SIGTRAPs
12162 behind the debugger's back is asking for trouble.
12164 Since hardware watchpoint traps are always
12165 distinguishable from other traps, so we don't need to
12166 apply keep hardware watchpoint moribund locations
12167 around. We simply always ignore hardware watchpoint
12168 traps we can no longer explain. */
12170 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12171 old_loc->owner = NULL;
12173 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12177 old_loc->owner = NULL;
12178 decref_bp_location (&old_loc);
12183 /* Rescan breakpoints at the same address and section, marking the
12184 first one as "first" and any others as "duplicates". This is so
12185 that the bpt instruction is only inserted once. If we have a
12186 permanent breakpoint at the same place as BPT, make that one the
12187 official one, and the rest as duplicates. Permanent breakpoints
12188 are sorted first for the same address.
12190 Do the same for hardware watchpoints, but also considering the
12191 watchpoint's type (regular/access/read) and length. */
12193 bp_loc_first = NULL;
12194 wp_loc_first = NULL;
12195 awp_loc_first = NULL;
12196 rwp_loc_first = NULL;
12197 ALL_BP_LOCATIONS (loc, locp)
12199 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12201 struct bp_location **loc_first_p;
12204 if (!should_be_inserted (loc)
12205 || !breakpoint_address_is_meaningful (b)
12206 /* Don't detect duplicate for tracepoint locations because they are
12207 never duplicated. See the comments in field `duplicate' of
12208 `struct bp_location'. */
12209 || is_tracepoint (b))
12211 /* Clear the condition modification flag. */
12212 loc->condition_changed = condition_unchanged;
12216 /* Permanent breakpoint should always be inserted. */
12217 if (b->enable_state == bp_permanent && ! loc->inserted)
12218 internal_error (__FILE__, __LINE__,
12219 _("allegedly permanent breakpoint is not "
12220 "actually inserted"));
12222 if (b->type == bp_hardware_watchpoint)
12223 loc_first_p = &wp_loc_first;
12224 else if (b->type == bp_read_watchpoint)
12225 loc_first_p = &rwp_loc_first;
12226 else if (b->type == bp_access_watchpoint)
12227 loc_first_p = &awp_loc_first;
12229 loc_first_p = &bp_loc_first;
12231 if (*loc_first_p == NULL
12232 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12233 || !breakpoint_locations_match (loc, *loc_first_p))
12235 *loc_first_p = loc;
12236 loc->duplicate = 0;
12238 if (is_breakpoint (loc->owner) && loc->condition_changed)
12240 loc->needs_update = 1;
12241 /* Clear the condition modification flag. */
12242 loc->condition_changed = condition_unchanged;
12248 /* This and the above ensure the invariant that the first location
12249 is not duplicated, and is the inserted one.
12250 All following are marked as duplicated, and are not inserted. */
12252 swap_insertion (loc, *loc_first_p);
12253 loc->duplicate = 1;
12255 /* Clear the condition modification flag. */
12256 loc->condition_changed = condition_unchanged;
12258 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
12259 && b->enable_state != bp_permanent)
12260 internal_error (__FILE__, __LINE__,
12261 _("another breakpoint was inserted on top of "
12262 "a permanent breakpoint"));
12265 if (breakpoints_always_inserted_mode ()
12266 && (have_live_inferiors ()
12267 || (gdbarch_has_global_breakpoints (target_gdbarch))))
12270 insert_breakpoint_locations ();
12273 /* Though should_insert is false, we may need to update conditions
12274 on the target's side if it is evaluating such conditions. We
12275 only update conditions for locations that are marked
12277 update_inserted_breakpoint_locations ();
12282 download_tracepoint_locations ();
12284 do_cleanups (cleanups);
12288 breakpoint_retire_moribund (void)
12290 struct bp_location *loc;
12293 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12294 if (--(loc->events_till_retirement) == 0)
12296 decref_bp_location (&loc);
12297 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12303 update_global_location_list_nothrow (int inserting)
12305 volatile struct gdb_exception e;
12307 TRY_CATCH (e, RETURN_MASK_ERROR)
12308 update_global_location_list (inserting);
12311 /* Clear BKP from a BPS. */
12314 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12318 for (bs = bps; bs; bs = bs->next)
12319 if (bs->breakpoint_at == bpt)
12321 bs->breakpoint_at = NULL;
12322 bs->old_val = NULL;
12323 /* bs->commands will be freed later. */
12327 /* Callback for iterate_over_threads. */
12329 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12331 struct breakpoint *bpt = data;
12333 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12337 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12341 say_where (struct breakpoint *b)
12343 struct ui_out *uiout = current_uiout;
12344 struct value_print_options opts;
12346 get_user_print_options (&opts);
12348 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12350 if (b->loc == NULL)
12352 printf_filtered (_(" (%s) pending."), b->addr_string);
12356 if (opts.addressprint || b->loc->source_file == NULL)
12358 printf_filtered (" at ");
12359 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
12362 if (b->loc->source_file)
12364 /* If there is a single location, we can print the location
12366 if (b->loc->next == NULL)
12367 printf_filtered (": file %s, line %d.",
12368 b->loc->source_file, b->loc->line_number);
12370 /* This is not ideal, but each location may have a
12371 different file name, and this at least reflects the
12372 real situation somewhat. */
12373 printf_filtered (": %s.", b->addr_string);
12378 struct bp_location *loc = b->loc;
12380 for (; loc; loc = loc->next)
12382 printf_filtered (" (%d locations)", n);
12387 /* Default bp_location_ops methods. */
12390 bp_location_dtor (struct bp_location *self)
12392 xfree (self->cond);
12393 if (self->cond_bytecode)
12394 free_agent_expr (self->cond_bytecode);
12395 xfree (self->function_name);
12396 xfree (self->source_file);
12399 static const struct bp_location_ops bp_location_ops =
12404 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12408 base_breakpoint_dtor (struct breakpoint *self)
12410 decref_counted_command_line (&self->commands);
12411 xfree (self->cond_string);
12412 xfree (self->addr_string);
12413 xfree (self->filter);
12414 xfree (self->addr_string_range_end);
12417 static struct bp_location *
12418 base_breakpoint_allocate_location (struct breakpoint *self)
12420 struct bp_location *loc;
12422 loc = XNEW (struct bp_location);
12423 init_bp_location (loc, &bp_location_ops, self);
12428 base_breakpoint_re_set (struct breakpoint *b)
12430 /* Nothing to re-set. */
12433 #define internal_error_pure_virtual_called() \
12434 gdb_assert_not_reached ("pure virtual function called")
12437 base_breakpoint_insert_location (struct bp_location *bl)
12439 internal_error_pure_virtual_called ();
12443 base_breakpoint_remove_location (struct bp_location *bl)
12445 internal_error_pure_virtual_called ();
12449 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12450 struct address_space *aspace,
12452 const struct target_waitstatus *ws)
12454 internal_error_pure_virtual_called ();
12458 base_breakpoint_check_status (bpstat bs)
12463 /* A "works_in_software_mode" breakpoint_ops method that just internal
12467 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
12469 internal_error_pure_virtual_called ();
12472 /* A "resources_needed" breakpoint_ops method that just internal
12476 base_breakpoint_resources_needed (const struct bp_location *bl)
12478 internal_error_pure_virtual_called ();
12481 static enum print_stop_action
12482 base_breakpoint_print_it (bpstat bs)
12484 internal_error_pure_virtual_called ();
12488 base_breakpoint_print_one_detail (const struct breakpoint *self,
12489 struct ui_out *uiout)
12495 base_breakpoint_print_mention (struct breakpoint *b)
12497 internal_error_pure_virtual_called ();
12501 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
12503 internal_error_pure_virtual_called ();
12507 base_breakpoint_create_sals_from_address (char **arg,
12508 struct linespec_result *canonical,
12509 enum bptype type_wanted,
12513 internal_error_pure_virtual_called ();
12517 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12518 struct linespec_result *c,
12519 struct linespec_sals *lsal,
12521 char *extra_string,
12522 enum bptype type_wanted,
12523 enum bpdisp disposition,
12525 int task, int ignore_count,
12526 const struct breakpoint_ops *o,
12527 int from_tty, int enabled,
12528 int internal, unsigned flags)
12530 internal_error_pure_virtual_called ();
12534 base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
12535 struct symtabs_and_lines *sals)
12537 internal_error_pure_virtual_called ();
12540 static struct breakpoint_ops base_breakpoint_ops =
12542 base_breakpoint_dtor,
12543 base_breakpoint_allocate_location,
12544 base_breakpoint_re_set,
12545 base_breakpoint_insert_location,
12546 base_breakpoint_remove_location,
12547 base_breakpoint_breakpoint_hit,
12548 base_breakpoint_check_status,
12549 base_breakpoint_resources_needed,
12550 base_breakpoint_works_in_software_mode,
12551 base_breakpoint_print_it,
12553 base_breakpoint_print_one_detail,
12554 base_breakpoint_print_mention,
12555 base_breakpoint_print_recreate,
12556 base_breakpoint_create_sals_from_address,
12557 base_breakpoint_create_breakpoints_sal,
12558 base_breakpoint_decode_linespec,
12561 /* Default breakpoint_ops methods. */
12564 bkpt_re_set (struct breakpoint *b)
12566 /* FIXME: is this still reachable? */
12567 if (b->addr_string == NULL)
12569 /* Anything without a string can't be re-set. */
12570 delete_breakpoint (b);
12574 breakpoint_re_set_default (b);
12578 bkpt_insert_location (struct bp_location *bl)
12580 if (bl->loc_type == bp_loc_hardware_breakpoint)
12581 return target_insert_hw_breakpoint (bl->gdbarch,
12584 return target_insert_breakpoint (bl->gdbarch,
12589 bkpt_remove_location (struct bp_location *bl)
12591 if (bl->loc_type == bp_loc_hardware_breakpoint)
12592 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
12594 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
12598 bkpt_breakpoint_hit (const struct bp_location *bl,
12599 struct address_space *aspace, CORE_ADDR bp_addr,
12600 const struct target_waitstatus *ws)
12602 struct breakpoint *b = bl->owner;
12604 if (ws->kind != TARGET_WAITKIND_STOPPED
12605 || ws->value.sig != GDB_SIGNAL_TRAP)
12608 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
12612 if (overlay_debugging /* unmapped overlay section */
12613 && section_is_overlay (bl->section)
12614 && !section_is_mapped (bl->section))
12621 bkpt_resources_needed (const struct bp_location *bl)
12623 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
12628 static enum print_stop_action
12629 bkpt_print_it (bpstat bs)
12631 struct breakpoint *b;
12632 const struct bp_location *bl;
12634 struct ui_out *uiout = current_uiout;
12636 gdb_assert (bs->bp_location_at != NULL);
12638 bl = bs->bp_location_at;
12639 b = bs->breakpoint_at;
12641 bp_temp = b->disposition == disp_del;
12642 if (bl->address != bl->requested_address)
12643 breakpoint_adjustment_warning (bl->requested_address,
12646 annotate_breakpoint (b->number);
12648 ui_out_text (uiout, "\nTemporary breakpoint ");
12650 ui_out_text (uiout, "\nBreakpoint ");
12651 if (ui_out_is_mi_like_p (uiout))
12653 ui_out_field_string (uiout, "reason",
12654 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
12655 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
12657 ui_out_field_int (uiout, "bkptno", b->number);
12658 ui_out_text (uiout, ", ");
12660 return PRINT_SRC_AND_LOC;
12664 bkpt_print_mention (struct breakpoint *b)
12666 if (ui_out_is_mi_like_p (current_uiout))
12671 case bp_breakpoint:
12672 case bp_gnu_ifunc_resolver:
12673 if (b->disposition == disp_del)
12674 printf_filtered (_("Temporary breakpoint"));
12676 printf_filtered (_("Breakpoint"));
12677 printf_filtered (_(" %d"), b->number);
12678 if (b->type == bp_gnu_ifunc_resolver)
12679 printf_filtered (_(" at gnu-indirect-function resolver"));
12681 case bp_hardware_breakpoint:
12682 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
12685 printf_filtered (_("Dprintf %d"), b->number);
12693 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
12695 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
12696 fprintf_unfiltered (fp, "tbreak");
12697 else if (tp->type == bp_breakpoint)
12698 fprintf_unfiltered (fp, "break");
12699 else if (tp->type == bp_hardware_breakpoint
12700 && tp->disposition == disp_del)
12701 fprintf_unfiltered (fp, "thbreak");
12702 else if (tp->type == bp_hardware_breakpoint)
12703 fprintf_unfiltered (fp, "hbreak");
12705 internal_error (__FILE__, __LINE__,
12706 _("unhandled breakpoint type %d"), (int) tp->type);
12708 fprintf_unfiltered (fp, " %s", tp->addr_string);
12709 print_recreate_thread (tp, fp);
12713 bkpt_create_sals_from_address (char **arg,
12714 struct linespec_result *canonical,
12715 enum bptype type_wanted,
12716 char *addr_start, char **copy_arg)
12718 create_sals_from_address_default (arg, canonical, type_wanted,
12719 addr_start, copy_arg);
12723 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
12724 struct linespec_result *canonical,
12725 struct linespec_sals *lsal,
12727 char *extra_string,
12728 enum bptype type_wanted,
12729 enum bpdisp disposition,
12731 int task, int ignore_count,
12732 const struct breakpoint_ops *ops,
12733 int from_tty, int enabled,
12734 int internal, unsigned flags)
12736 create_breakpoints_sal_default (gdbarch, canonical, lsal,
12737 cond_string, extra_string,
12739 disposition, thread, task,
12740 ignore_count, ops, from_tty,
12741 enabled, internal, flags);
12745 bkpt_decode_linespec (struct breakpoint *b, char **s,
12746 struct symtabs_and_lines *sals)
12748 decode_linespec_default (b, s, sals);
12751 /* Virtual table for internal breakpoints. */
12754 internal_bkpt_re_set (struct breakpoint *b)
12758 /* Delete overlay event and longjmp master breakpoints; they
12759 will be reset later by breakpoint_re_set. */
12760 case bp_overlay_event:
12761 case bp_longjmp_master:
12762 case bp_std_terminate_master:
12763 case bp_exception_master:
12764 delete_breakpoint (b);
12767 /* This breakpoint is special, it's set up when the inferior
12768 starts and we really don't want to touch it. */
12769 case bp_shlib_event:
12771 /* Like bp_shlib_event, this breakpoint type is special. Once
12772 it is set up, we do not want to touch it. */
12773 case bp_thread_event:
12779 internal_bkpt_check_status (bpstat bs)
12781 if (bs->breakpoint_at->type == bp_shlib_event)
12783 /* If requested, stop when the dynamic linker notifies GDB of
12784 events. This allows the user to get control and place
12785 breakpoints in initializer routines for dynamically loaded
12786 objects (among other things). */
12787 bs->stop = stop_on_solib_events;
12788 bs->print = stop_on_solib_events;
12794 static enum print_stop_action
12795 internal_bkpt_print_it (bpstat bs)
12797 struct ui_out *uiout = current_uiout;
12798 struct breakpoint *b;
12800 b = bs->breakpoint_at;
12804 case bp_shlib_event:
12805 /* Did we stop because the user set the stop_on_solib_events
12806 variable? (If so, we report this as a generic, "Stopped due
12807 to shlib event" message.) */
12808 print_solib_event (0);
12811 case bp_thread_event:
12812 /* Not sure how we will get here.
12813 GDB should not stop for these breakpoints. */
12814 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12817 case bp_overlay_event:
12818 /* By analogy with the thread event, GDB should not stop for these. */
12819 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12822 case bp_longjmp_master:
12823 /* These should never be enabled. */
12824 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12827 case bp_std_terminate_master:
12828 /* These should never be enabled. */
12829 printf_filtered (_("std::terminate Master Breakpoint: "
12830 "gdb should not stop!\n"));
12833 case bp_exception_master:
12834 /* These should never be enabled. */
12835 printf_filtered (_("Exception Master Breakpoint: "
12836 "gdb should not stop!\n"));
12840 return PRINT_NOTHING;
12844 internal_bkpt_print_mention (struct breakpoint *b)
12846 /* Nothing to mention. These breakpoints are internal. */
12849 /* Virtual table for momentary breakpoints */
12852 momentary_bkpt_re_set (struct breakpoint *b)
12854 /* Keep temporary breakpoints, which can be encountered when we step
12855 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
12856 Otherwise these should have been blown away via the cleanup chain
12857 or by breakpoint_init_inferior when we rerun the executable. */
12861 momentary_bkpt_check_status (bpstat bs)
12863 /* Nothing. The point of these breakpoints is causing a stop. */
12866 static enum print_stop_action
12867 momentary_bkpt_print_it (bpstat bs)
12869 struct ui_out *uiout = current_uiout;
12871 if (ui_out_is_mi_like_p (uiout))
12873 struct breakpoint *b = bs->breakpoint_at;
12878 ui_out_field_string
12880 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
12884 ui_out_field_string
12886 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
12891 return PRINT_UNKNOWN;
12895 momentary_bkpt_print_mention (struct breakpoint *b)
12897 /* Nothing to mention. These breakpoints are internal. */
12900 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12902 It gets cleared already on the removal of the first one of such placed
12903 breakpoints. This is OK as they get all removed altogether. */
12906 longjmp_bkpt_dtor (struct breakpoint *self)
12908 struct thread_info *tp = find_thread_id (self->thread);
12911 tp->initiating_frame = null_frame_id;
12913 momentary_breakpoint_ops.dtor (self);
12916 /* Specific methods for probe breakpoints. */
12919 bkpt_probe_insert_location (struct bp_location *bl)
12921 int v = bkpt_insert_location (bl);
12925 /* The insertion was successful, now let's set the probe's semaphore
12927 bl->probe->pops->set_semaphore (bl->probe, bl->gdbarch);
12934 bkpt_probe_remove_location (struct bp_location *bl)
12936 /* Let's clear the semaphore before removing the location. */
12937 bl->probe->pops->clear_semaphore (bl->probe, bl->gdbarch);
12939 return bkpt_remove_location (bl);
12943 bkpt_probe_create_sals_from_address (char **arg,
12944 struct linespec_result *canonical,
12945 enum bptype type_wanted,
12946 char *addr_start, char **copy_arg)
12948 struct linespec_sals lsal;
12950 lsal.sals = parse_probes (arg, canonical);
12952 *copy_arg = xstrdup (canonical->addr_string);
12953 lsal.canonical = xstrdup (*copy_arg);
12955 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
12959 bkpt_probe_decode_linespec (struct breakpoint *b, char **s,
12960 struct symtabs_and_lines *sals)
12962 *sals = parse_probes (s, NULL);
12964 error (_("probe not found"));
12967 /* The breakpoint_ops structure to be used in tracepoints. */
12970 tracepoint_re_set (struct breakpoint *b)
12972 breakpoint_re_set_default (b);
12976 tracepoint_breakpoint_hit (const struct bp_location *bl,
12977 struct address_space *aspace, CORE_ADDR bp_addr,
12978 const struct target_waitstatus *ws)
12980 /* By definition, the inferior does not report stops at
12986 tracepoint_print_one_detail (const struct breakpoint *self,
12987 struct ui_out *uiout)
12989 struct tracepoint *tp = (struct tracepoint *) self;
12990 if (tp->static_trace_marker_id)
12992 gdb_assert (self->type == bp_static_tracepoint);
12994 ui_out_text (uiout, "\tmarker id is ");
12995 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
12996 tp->static_trace_marker_id);
12997 ui_out_text (uiout, "\n");
13002 tracepoint_print_mention (struct breakpoint *b)
13004 if (ui_out_is_mi_like_p (current_uiout))
13009 case bp_tracepoint:
13010 printf_filtered (_("Tracepoint"));
13011 printf_filtered (_(" %d"), b->number);
13013 case bp_fast_tracepoint:
13014 printf_filtered (_("Fast tracepoint"));
13015 printf_filtered (_(" %d"), b->number);
13017 case bp_static_tracepoint:
13018 printf_filtered (_("Static tracepoint"));
13019 printf_filtered (_(" %d"), b->number);
13022 internal_error (__FILE__, __LINE__,
13023 _("unhandled tracepoint type %d"), (int) b->type);
13030 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
13032 struct tracepoint *tp = (struct tracepoint *) self;
13034 if (self->type == bp_fast_tracepoint)
13035 fprintf_unfiltered (fp, "ftrace");
13036 if (self->type == bp_static_tracepoint)
13037 fprintf_unfiltered (fp, "strace");
13038 else if (self->type == bp_tracepoint)
13039 fprintf_unfiltered (fp, "trace");
13041 internal_error (__FILE__, __LINE__,
13042 _("unhandled tracepoint type %d"), (int) self->type);
13044 fprintf_unfiltered (fp, " %s", self->addr_string);
13045 print_recreate_thread (self, fp);
13047 if (tp->pass_count)
13048 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
13052 tracepoint_create_sals_from_address (char **arg,
13053 struct linespec_result *canonical,
13054 enum bptype type_wanted,
13055 char *addr_start, char **copy_arg)
13057 create_sals_from_address_default (arg, canonical, type_wanted,
13058 addr_start, copy_arg);
13062 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13063 struct linespec_result *canonical,
13064 struct linespec_sals *lsal,
13066 char *extra_string,
13067 enum bptype type_wanted,
13068 enum bpdisp disposition,
13070 int task, int ignore_count,
13071 const struct breakpoint_ops *ops,
13072 int from_tty, int enabled,
13073 int internal, unsigned flags)
13075 create_breakpoints_sal_default (gdbarch, canonical, lsal,
13076 cond_string, extra_string,
13078 disposition, thread, task,
13079 ignore_count, ops, from_tty,
13080 enabled, internal, flags);
13084 tracepoint_decode_linespec (struct breakpoint *b, char **s,
13085 struct symtabs_and_lines *sals)
13087 decode_linespec_default (b, s, sals);
13090 struct breakpoint_ops tracepoint_breakpoint_ops;
13092 /* The breakpoint_ops structure to be use on tracepoints placed in a
13096 tracepoint_probe_create_sals_from_address (char **arg,
13097 struct linespec_result *canonical,
13098 enum bptype type_wanted,
13099 char *addr_start, char **copy_arg)
13101 /* We use the same method for breakpoint on probes. */
13102 bkpt_probe_create_sals_from_address (arg, canonical, type_wanted,
13103 addr_start, copy_arg);
13107 tracepoint_probe_decode_linespec (struct breakpoint *b, char **s,
13108 struct symtabs_and_lines *sals)
13110 /* We use the same method for breakpoint on probes. */
13111 bkpt_probe_decode_linespec (b, s, sals);
13114 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
13116 /* The breakpoint_ops structure to be used on static tracepoints with
13120 strace_marker_create_sals_from_address (char **arg,
13121 struct linespec_result *canonical,
13122 enum bptype type_wanted,
13123 char *addr_start, char **copy_arg)
13125 struct linespec_sals lsal;
13127 lsal.sals = decode_static_tracepoint_spec (arg);
13129 *copy_arg = savestring (addr_start, *arg - addr_start);
13131 canonical->addr_string = xstrdup (*copy_arg);
13132 lsal.canonical = xstrdup (*copy_arg);
13133 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13137 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13138 struct linespec_result *canonical,
13139 struct linespec_sals *lsal,
13141 char *extra_string,
13142 enum bptype type_wanted,
13143 enum bpdisp disposition,
13145 int task, int ignore_count,
13146 const struct breakpoint_ops *ops,
13147 int from_tty, int enabled,
13148 int internal, unsigned flags)
13152 /* If the user is creating a static tracepoint by marker id
13153 (strace -m MARKER_ID), then store the sals index, so that
13154 breakpoint_re_set can try to match up which of the newly
13155 found markers corresponds to this one, and, don't try to
13156 expand multiple locations for each sal, given than SALS
13157 already should contain all sals for MARKER_ID. */
13159 for (i = 0; i < lsal->sals.nelts; ++i)
13161 struct symtabs_and_lines expanded;
13162 struct tracepoint *tp;
13163 struct cleanup *old_chain;
13166 expanded.nelts = 1;
13167 expanded.sals = &lsal->sals.sals[i];
13169 addr_string = xstrdup (canonical->addr_string);
13170 old_chain = make_cleanup (xfree, addr_string);
13172 tp = XCNEW (struct tracepoint);
13173 init_breakpoint_sal (&tp->base, gdbarch, expanded,
13175 cond_string, extra_string,
13176 type_wanted, disposition,
13177 thread, task, ignore_count, ops,
13178 from_tty, enabled, internal, flags,
13179 canonical->special_display);
13180 /* Given that its possible to have multiple markers with
13181 the same string id, if the user is creating a static
13182 tracepoint by marker id ("strace -m MARKER_ID"), then
13183 store the sals index, so that breakpoint_re_set can
13184 try to match up which of the newly found markers
13185 corresponds to this one */
13186 tp->static_trace_marker_id_idx = i;
13188 install_breakpoint (internal, &tp->base, 0);
13190 discard_cleanups (old_chain);
13195 strace_marker_decode_linespec (struct breakpoint *b, char **s,
13196 struct symtabs_and_lines *sals)
13198 struct tracepoint *tp = (struct tracepoint *) b;
13200 *sals = decode_static_tracepoint_spec (s);
13201 if (sals->nelts > tp->static_trace_marker_id_idx)
13203 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
13207 error (_("marker %s not found"), tp->static_trace_marker_id);
13210 static struct breakpoint_ops strace_marker_breakpoint_ops;
13213 strace_marker_p (struct breakpoint *b)
13215 return b->ops == &strace_marker_breakpoint_ops;
13218 /* Delete a breakpoint and clean up all traces of it in the data
13222 delete_breakpoint (struct breakpoint *bpt)
13224 struct breakpoint *b;
13226 gdb_assert (bpt != NULL);
13228 /* Has this bp already been deleted? This can happen because
13229 multiple lists can hold pointers to bp's. bpstat lists are
13232 One example of this happening is a watchpoint's scope bp. When
13233 the scope bp triggers, we notice that the watchpoint is out of
13234 scope, and delete it. We also delete its scope bp. But the
13235 scope bp is marked "auto-deleting", and is already on a bpstat.
13236 That bpstat is then checked for auto-deleting bp's, which are
13239 A real solution to this problem might involve reference counts in
13240 bp's, and/or giving them pointers back to their referencing
13241 bpstat's, and teaching delete_breakpoint to only free a bp's
13242 storage when no more references were extent. A cheaper bandaid
13244 if (bpt->type == bp_none)
13247 /* At least avoid this stale reference until the reference counting
13248 of breakpoints gets resolved. */
13249 if (bpt->related_breakpoint != bpt)
13251 struct breakpoint *related;
13252 struct watchpoint *w;
13254 if (bpt->type == bp_watchpoint_scope)
13255 w = (struct watchpoint *) bpt->related_breakpoint;
13256 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
13257 w = (struct watchpoint *) bpt;
13261 watchpoint_del_at_next_stop (w);
13263 /* Unlink bpt from the bpt->related_breakpoint ring. */
13264 for (related = bpt; related->related_breakpoint != bpt;
13265 related = related->related_breakpoint);
13266 related->related_breakpoint = bpt->related_breakpoint;
13267 bpt->related_breakpoint = bpt;
13270 /* watch_command_1 creates a watchpoint but only sets its number if
13271 update_watchpoint succeeds in creating its bp_locations. If there's
13272 a problem in that process, we'll be asked to delete the half-created
13273 watchpoint. In that case, don't announce the deletion. */
13275 observer_notify_breakpoint_deleted (bpt);
13277 if (breakpoint_chain == bpt)
13278 breakpoint_chain = bpt->next;
13280 ALL_BREAKPOINTS (b)
13281 if (b->next == bpt)
13283 b->next = bpt->next;
13287 /* Be sure no bpstat's are pointing at the breakpoint after it's
13289 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13290 in all threads for now. Note that we cannot just remove bpstats
13291 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13292 commands are associated with the bpstat; if we remove it here,
13293 then the later call to bpstat_do_actions (&stop_bpstat); in
13294 event-top.c won't do anything, and temporary breakpoints with
13295 commands won't work. */
13297 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13299 /* Now that breakpoint is removed from breakpoint list, update the
13300 global location list. This will remove locations that used to
13301 belong to this breakpoint. Do this before freeing the breakpoint
13302 itself, since remove_breakpoint looks at location's owner. It
13303 might be better design to have location completely
13304 self-contained, but it's not the case now. */
13305 update_global_location_list (0);
13307 bpt->ops->dtor (bpt);
13308 /* On the chance that someone will soon try again to delete this
13309 same bp, we mark it as deleted before freeing its storage. */
13310 bpt->type = bp_none;
13315 do_delete_breakpoint_cleanup (void *b)
13317 delete_breakpoint (b);
13321 make_cleanup_delete_breakpoint (struct breakpoint *b)
13323 return make_cleanup (do_delete_breakpoint_cleanup, b);
13326 /* Iterator function to call a user-provided callback function once
13327 for each of B and its related breakpoints. */
13330 iterate_over_related_breakpoints (struct breakpoint *b,
13331 void (*function) (struct breakpoint *,
13335 struct breakpoint *related;
13340 struct breakpoint *next;
13342 /* FUNCTION may delete RELATED. */
13343 next = related->related_breakpoint;
13345 if (next == related)
13347 /* RELATED is the last ring entry. */
13348 function (related, data);
13350 /* FUNCTION may have deleted it, so we'd never reach back to
13351 B. There's nothing left to do anyway, so just break
13356 function (related, data);
13360 while (related != b);
13364 do_delete_breakpoint (struct breakpoint *b, void *ignore)
13366 delete_breakpoint (b);
13369 /* A callback for map_breakpoint_numbers that calls
13370 delete_breakpoint. */
13373 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
13375 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
13379 delete_command (char *arg, int from_tty)
13381 struct breakpoint *b, *b_tmp;
13387 int breaks_to_delete = 0;
13389 /* Delete all breakpoints if no argument. Do not delete
13390 internal breakpoints, these have to be deleted with an
13391 explicit breakpoint number argument. */
13392 ALL_BREAKPOINTS (b)
13393 if (user_breakpoint_p (b))
13395 breaks_to_delete = 1;
13399 /* Ask user only if there are some breakpoints to delete. */
13401 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
13403 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13404 if (user_breakpoint_p (b))
13405 delete_breakpoint (b);
13409 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
13413 all_locations_are_pending (struct bp_location *loc)
13415 for (; loc; loc = loc->next)
13416 if (!loc->shlib_disabled
13417 && !loc->pspace->executing_startup)
13422 /* Subroutine of update_breakpoint_locations to simplify it.
13423 Return non-zero if multiple fns in list LOC have the same name.
13424 Null names are ignored. */
13427 ambiguous_names_p (struct bp_location *loc)
13429 struct bp_location *l;
13430 htab_t htab = htab_create_alloc (13, htab_hash_string,
13431 (int (*) (const void *,
13432 const void *)) streq,
13433 NULL, xcalloc, xfree);
13435 for (l = loc; l != NULL; l = l->next)
13438 const char *name = l->function_name;
13440 /* Allow for some names to be NULL, ignore them. */
13444 slot = (const char **) htab_find_slot (htab, (const void *) name,
13446 /* NOTE: We can assume slot != NULL here because xcalloc never
13450 htab_delete (htab);
13456 htab_delete (htab);
13460 /* When symbols change, it probably means the sources changed as well,
13461 and it might mean the static tracepoint markers are no longer at
13462 the same address or line numbers they used to be at last we
13463 checked. Losing your static tracepoints whenever you rebuild is
13464 undesirable. This function tries to resync/rematch gdb static
13465 tracepoints with the markers on the target, for static tracepoints
13466 that have not been set by marker id. Static tracepoint that have
13467 been set by marker id are reset by marker id in breakpoint_re_set.
13470 1) For a tracepoint set at a specific address, look for a marker at
13471 the old PC. If one is found there, assume to be the same marker.
13472 If the name / string id of the marker found is different from the
13473 previous known name, assume that means the user renamed the marker
13474 in the sources, and output a warning.
13476 2) For a tracepoint set at a given line number, look for a marker
13477 at the new address of the old line number. If one is found there,
13478 assume to be the same marker. If the name / string id of the
13479 marker found is different from the previous known name, assume that
13480 means the user renamed the marker in the sources, and output a
13483 3) If a marker is no longer found at the same address or line, it
13484 may mean the marker no longer exists. But it may also just mean
13485 the code changed a bit. Maybe the user added a few lines of code
13486 that made the marker move up or down (in line number terms). Ask
13487 the target for info about the marker with the string id as we knew
13488 it. If found, update line number and address in the matching
13489 static tracepoint. This will get confused if there's more than one
13490 marker with the same ID (possible in UST, although unadvised
13491 precisely because it confuses tools). */
13493 static struct symtab_and_line
13494 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
13496 struct tracepoint *tp = (struct tracepoint *) b;
13497 struct static_tracepoint_marker marker;
13502 find_line_pc (sal.symtab, sal.line, &pc);
13504 if (target_static_tracepoint_marker_at (pc, &marker))
13506 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
13507 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13509 tp->static_trace_marker_id, marker.str_id);
13511 xfree (tp->static_trace_marker_id);
13512 tp->static_trace_marker_id = xstrdup (marker.str_id);
13513 release_static_tracepoint_marker (&marker);
13518 /* Old marker wasn't found on target at lineno. Try looking it up
13520 if (!sal.explicit_pc
13522 && sal.symtab != NULL
13523 && tp->static_trace_marker_id != NULL)
13525 VEC(static_tracepoint_marker_p) *markers;
13528 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
13530 if (!VEC_empty(static_tracepoint_marker_p, markers))
13532 struct symtab_and_line sal2;
13533 struct symbol *sym;
13534 struct static_tracepoint_marker *tpmarker;
13535 struct ui_out *uiout = current_uiout;
13537 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
13539 xfree (tp->static_trace_marker_id);
13540 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
13542 warning (_("marker for static tracepoint %d (%s) not "
13543 "found at previous line number"),
13544 b->number, tp->static_trace_marker_id);
13548 sal2.pc = tpmarker->address;
13550 sal2 = find_pc_line (tpmarker->address, 0);
13551 sym = find_pc_sect_function (tpmarker->address, NULL);
13552 ui_out_text (uiout, "Now in ");
13555 ui_out_field_string (uiout, "func",
13556 SYMBOL_PRINT_NAME (sym));
13557 ui_out_text (uiout, " at ");
13559 ui_out_field_string (uiout, "file", sal2.symtab->filename);
13560 ui_out_text (uiout, ":");
13562 if (ui_out_is_mi_like_p (uiout))
13564 char *fullname = symtab_to_fullname (sal2.symtab);
13567 ui_out_field_string (uiout, "fullname", fullname);
13570 ui_out_field_int (uiout, "line", sal2.line);
13571 ui_out_text (uiout, "\n");
13573 b->loc->line_number = sal2.line;
13575 xfree (b->loc->source_file);
13577 b->loc->source_file = xstrdup (sal2.symtab->filename);
13579 b->loc->source_file = NULL;
13581 xfree (b->addr_string);
13582 b->addr_string = xstrprintf ("%s:%d",
13583 sal2.symtab->filename,
13584 b->loc->line_number);
13586 /* Might be nice to check if function changed, and warn if
13589 release_static_tracepoint_marker (tpmarker);
13595 /* Returns 1 iff locations A and B are sufficiently same that
13596 we don't need to report breakpoint as changed. */
13599 locations_are_equal (struct bp_location *a, struct bp_location *b)
13603 if (a->address != b->address)
13606 if (a->shlib_disabled != b->shlib_disabled)
13609 if (a->enabled != b->enabled)
13616 if ((a == NULL) != (b == NULL))
13622 /* Create new breakpoint locations for B (a hardware or software breakpoint)
13623 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
13624 a ranged breakpoint. */
13627 update_breakpoint_locations (struct breakpoint *b,
13628 struct symtabs_and_lines sals,
13629 struct symtabs_and_lines sals_end)
13632 struct bp_location *existing_locations = b->loc;
13634 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
13636 /* Ranged breakpoints have only one start location and one end
13638 b->enable_state = bp_disabled;
13639 update_global_location_list (1);
13640 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13641 "multiple locations found\n"),
13646 /* If there's no new locations, and all existing locations are
13647 pending, don't do anything. This optimizes the common case where
13648 all locations are in the same shared library, that was unloaded.
13649 We'd like to retain the location, so that when the library is
13650 loaded again, we don't loose the enabled/disabled status of the
13651 individual locations. */
13652 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
13657 for (i = 0; i < sals.nelts; ++i)
13659 struct bp_location *new_loc;
13661 switch_to_program_space_and_thread (sals.sals[i].pspace);
13663 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
13665 /* Reparse conditions, they might contain references to the
13667 if (b->cond_string != NULL)
13670 volatile struct gdb_exception e;
13672 s = b->cond_string;
13673 TRY_CATCH (e, RETURN_MASK_ERROR)
13675 new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
13676 block_for_pc (sals.sals[i].pc),
13681 warning (_("failed to reevaluate condition "
13682 "for breakpoint %d: %s"),
13683 b->number, e.message);
13684 new_loc->enabled = 0;
13688 if (sals_end.nelts)
13690 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
13692 new_loc->length = end - sals.sals[0].pc + 1;
13696 /* Update locations of permanent breakpoints. */
13697 if (b->enable_state == bp_permanent)
13698 make_breakpoint_permanent (b);
13700 /* If possible, carry over 'disable' status from existing
13703 struct bp_location *e = existing_locations;
13704 /* If there are multiple breakpoints with the same function name,
13705 e.g. for inline functions, comparing function names won't work.
13706 Instead compare pc addresses; this is just a heuristic as things
13707 may have moved, but in practice it gives the correct answer
13708 often enough until a better solution is found. */
13709 int have_ambiguous_names = ambiguous_names_p (b->loc);
13711 for (; e; e = e->next)
13713 if (!e->enabled && e->function_name)
13715 struct bp_location *l = b->loc;
13716 if (have_ambiguous_names)
13718 for (; l; l = l->next)
13719 if (breakpoint_locations_match (e, l))
13727 for (; l; l = l->next)
13728 if (l->function_name
13729 && strcmp (e->function_name, l->function_name) == 0)
13739 if (!locations_are_equal (existing_locations, b->loc))
13740 observer_notify_breakpoint_modified (b);
13742 update_global_location_list (1);
13745 /* Find the SaL locations corresponding to the given ADDR_STRING.
13746 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13748 static struct symtabs_and_lines
13749 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
13752 struct symtabs_and_lines sals = {0};
13753 volatile struct gdb_exception e;
13755 gdb_assert (b->ops != NULL);
13758 TRY_CATCH (e, RETURN_MASK_ERROR)
13760 b->ops->decode_linespec (b, &s, &sals);
13764 int not_found_and_ok = 0;
13765 /* For pending breakpoints, it's expected that parsing will
13766 fail until the right shared library is loaded. User has
13767 already told to create pending breakpoints and don't need
13768 extra messages. If breakpoint is in bp_shlib_disabled
13769 state, then user already saw the message about that
13770 breakpoint being disabled, and don't want to see more
13772 if (e.error == NOT_FOUND_ERROR
13773 && (b->condition_not_parsed
13774 || (b->loc && b->loc->shlib_disabled)
13775 || (b->loc && b->loc->pspace->executing_startup)
13776 || b->enable_state == bp_disabled))
13777 not_found_and_ok = 1;
13779 if (!not_found_and_ok)
13781 /* We surely don't want to warn about the same breakpoint
13782 10 times. One solution, implemented here, is disable
13783 the breakpoint on error. Another solution would be to
13784 have separate 'warning emitted' flag. Since this
13785 happens only when a binary has changed, I don't know
13786 which approach is better. */
13787 b->enable_state = bp_disabled;
13788 throw_exception (e);
13792 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
13796 for (i = 0; i < sals.nelts; ++i)
13797 resolve_sal_pc (&sals.sals[i]);
13798 if (b->condition_not_parsed && s && s[0])
13800 char *cond_string = 0;
13803 char *extra_string = NULL;
13805 find_condition_and_thread (s, sals.sals[0].pc,
13806 &cond_string, &thread, &task,
13809 b->cond_string = cond_string;
13810 b->thread = thread;
13813 b->extra_string = extra_string;
13814 b->condition_not_parsed = 0;
13817 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
13818 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
13828 /* The default re_set method, for typical hardware or software
13829 breakpoints. Reevaluate the breakpoint and recreate its
13833 breakpoint_re_set_default (struct breakpoint *b)
13836 struct symtabs_and_lines sals, sals_end;
13837 struct symtabs_and_lines expanded = {0};
13838 struct symtabs_and_lines expanded_end = {0};
13840 sals = addr_string_to_sals (b, b->addr_string, &found);
13843 make_cleanup (xfree, sals.sals);
13847 if (b->addr_string_range_end)
13849 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
13852 make_cleanup (xfree, sals_end.sals);
13853 expanded_end = sals_end;
13857 update_breakpoint_locations (b, expanded, expanded_end);
13860 /* Default method for creating SALs from an address string. It basically
13861 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13864 create_sals_from_address_default (char **arg,
13865 struct linespec_result *canonical,
13866 enum bptype type_wanted,
13867 char *addr_start, char **copy_arg)
13869 parse_breakpoint_sals (arg, canonical);
13872 /* Call create_breakpoints_sal for the given arguments. This is the default
13873 function for the `create_breakpoints_sal' method of
13877 create_breakpoints_sal_default (struct gdbarch *gdbarch,
13878 struct linespec_result *canonical,
13879 struct linespec_sals *lsal,
13881 char *extra_string,
13882 enum bptype type_wanted,
13883 enum bpdisp disposition,
13885 int task, int ignore_count,
13886 const struct breakpoint_ops *ops,
13887 int from_tty, int enabled,
13888 int internal, unsigned flags)
13890 create_breakpoints_sal (gdbarch, canonical, cond_string,
13892 type_wanted, disposition,
13893 thread, task, ignore_count, ops, from_tty,
13894 enabled, internal, flags);
13897 /* Decode the line represented by S by calling decode_line_full. This is the
13898 default function for the `decode_linespec' method of breakpoint_ops. */
13901 decode_linespec_default (struct breakpoint *b, char **s,
13902 struct symtabs_and_lines *sals)
13904 struct linespec_result canonical;
13906 init_linespec_result (&canonical);
13907 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
13908 (struct symtab *) NULL, 0,
13909 &canonical, multiple_symbols_all,
13912 /* We should get 0 or 1 resulting SALs. */
13913 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
13915 if (VEC_length (linespec_sals, canonical.sals) > 0)
13917 struct linespec_sals *lsal;
13919 lsal = VEC_index (linespec_sals, canonical.sals, 0);
13920 *sals = lsal->sals;
13921 /* Arrange it so the destructor does not free the
13923 lsal->sals.sals = NULL;
13926 destroy_linespec_result (&canonical);
13929 /* Prepare the global context for a re-set of breakpoint B. */
13931 static struct cleanup *
13932 prepare_re_set_context (struct breakpoint *b)
13934 struct cleanup *cleanups;
13936 input_radix = b->input_radix;
13937 cleanups = save_current_space_and_thread ();
13938 if (b->pspace != NULL)
13939 switch_to_program_space_and_thread (b->pspace);
13940 set_language (b->language);
13945 /* Reset a breakpoint given it's struct breakpoint * BINT.
13946 The value we return ends up being the return value from catch_errors.
13947 Unused in this case. */
13950 breakpoint_re_set_one (void *bint)
13952 /* Get past catch_errs. */
13953 struct breakpoint *b = (struct breakpoint *) bint;
13954 struct cleanup *cleanups;
13956 cleanups = prepare_re_set_context (b);
13957 b->ops->re_set (b);
13958 do_cleanups (cleanups);
13962 /* Re-set all breakpoints after symbols have been re-loaded. */
13964 breakpoint_re_set (void)
13966 struct breakpoint *b, *b_tmp;
13967 enum language save_language;
13968 int save_input_radix;
13969 struct cleanup *old_chain;
13971 save_language = current_language->la_language;
13972 save_input_radix = input_radix;
13973 old_chain = save_current_program_space ();
13975 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13977 /* Format possible error msg. */
13978 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
13980 struct cleanup *cleanups = make_cleanup (xfree, message);
13981 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
13982 do_cleanups (cleanups);
13984 set_language (save_language);
13985 input_radix = save_input_radix;
13987 jit_breakpoint_re_set ();
13989 do_cleanups (old_chain);
13991 create_overlay_event_breakpoint ();
13992 create_longjmp_master_breakpoint ();
13993 create_std_terminate_master_breakpoint ();
13994 create_exception_master_breakpoint ();
13996 /* While we're at it, reset the skip list too. */
14000 /* Reset the thread number of this breakpoint:
14002 - If the breakpoint is for all threads, leave it as-is.
14003 - Else, reset it to the current thread for inferior_ptid. */
14005 breakpoint_re_set_thread (struct breakpoint *b)
14007 if (b->thread != -1)
14009 if (in_thread_list (inferior_ptid))
14010 b->thread = pid_to_thread_id (inferior_ptid);
14012 /* We're being called after following a fork. The new fork is
14013 selected as current, and unless this was a vfork will have a
14014 different program space from the original thread. Reset that
14016 b->loc->pspace = current_program_space;
14020 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14021 If from_tty is nonzero, it prints a message to that effect,
14022 which ends with a period (no newline). */
14025 set_ignore_count (int bptnum, int count, int from_tty)
14027 struct breakpoint *b;
14032 ALL_BREAKPOINTS (b)
14033 if (b->number == bptnum)
14035 if (is_tracepoint (b))
14037 if (from_tty && count != 0)
14038 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14043 b->ignore_count = count;
14047 printf_filtered (_("Will stop next time "
14048 "breakpoint %d is reached."),
14050 else if (count == 1)
14051 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14054 printf_filtered (_("Will ignore next %d "
14055 "crossings of breakpoint %d."),
14058 breakpoints_changed ();
14059 observer_notify_breakpoint_modified (b);
14063 error (_("No breakpoint number %d."), bptnum);
14066 /* Command to set ignore-count of breakpoint N to COUNT. */
14069 ignore_command (char *args, int from_tty)
14075 error_no_arg (_("a breakpoint number"));
14077 num = get_number (&p);
14079 error (_("bad breakpoint number: '%s'"), args);
14081 error (_("Second argument (specified ignore-count) is missing."));
14083 set_ignore_count (num,
14084 longest_to_int (value_as_long (parse_and_eval (p))),
14087 printf_filtered ("\n");
14090 /* Call FUNCTION on each of the breakpoints
14091 whose numbers are given in ARGS. */
14094 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
14099 struct breakpoint *b, *tmp;
14101 struct get_number_or_range_state state;
14104 error_no_arg (_("one or more breakpoint numbers"));
14106 init_number_or_range (&state, args);
14108 while (!state.finished)
14110 char *p = state.string;
14114 num = get_number_or_range (&state);
14117 warning (_("bad breakpoint number at or near '%s'"), p);
14121 ALL_BREAKPOINTS_SAFE (b, tmp)
14122 if (b->number == num)
14125 function (b, data);
14129 printf_unfiltered (_("No breakpoint number %d.\n"), num);
14134 static struct bp_location *
14135 find_location_by_number (char *number)
14137 char *dot = strchr (number, '.');
14141 struct breakpoint *b;
14142 struct bp_location *loc;
14147 bp_num = get_number (&p1);
14149 error (_("Bad breakpoint number '%s'"), number);
14151 ALL_BREAKPOINTS (b)
14152 if (b->number == bp_num)
14157 if (!b || b->number != bp_num)
14158 error (_("Bad breakpoint number '%s'"), number);
14161 loc_num = get_number (&p1);
14163 error (_("Bad breakpoint location number '%s'"), number);
14167 for (;loc_num && loc; --loc_num, loc = loc->next)
14170 error (_("Bad breakpoint location number '%s'"), dot+1);
14176 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14177 If from_tty is nonzero, it prints a message to that effect,
14178 which ends with a period (no newline). */
14181 disable_breakpoint (struct breakpoint *bpt)
14183 /* Never disable a watchpoint scope breakpoint; we want to
14184 hit them when we leave scope so we can delete both the
14185 watchpoint and its scope breakpoint at that time. */
14186 if (bpt->type == bp_watchpoint_scope)
14189 /* You can't disable permanent breakpoints. */
14190 if (bpt->enable_state == bp_permanent)
14193 bpt->enable_state = bp_disabled;
14195 /* Mark breakpoint locations modified. */
14196 mark_breakpoint_modified (bpt);
14198 if (target_supports_enable_disable_tracepoint ()
14199 && current_trace_status ()->running && is_tracepoint (bpt))
14201 struct bp_location *location;
14203 for (location = bpt->loc; location; location = location->next)
14204 target_disable_tracepoint (location);
14207 update_global_location_list (0);
14209 observer_notify_breakpoint_modified (bpt);
14212 /* A callback for iterate_over_related_breakpoints. */
14215 do_disable_breakpoint (struct breakpoint *b, void *ignore)
14217 disable_breakpoint (b);
14220 /* A callback for map_breakpoint_numbers that calls
14221 disable_breakpoint. */
14224 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
14226 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
14230 disable_command (char *args, int from_tty)
14234 struct breakpoint *bpt;
14236 ALL_BREAKPOINTS (bpt)
14237 if (user_breakpoint_p (bpt))
14238 disable_breakpoint (bpt);
14240 else if (strchr (args, '.'))
14242 struct bp_location *loc = find_location_by_number (args);
14248 mark_breakpoint_location_modified (loc);
14250 if (target_supports_enable_disable_tracepoint ()
14251 && current_trace_status ()->running && loc->owner
14252 && is_tracepoint (loc->owner))
14253 target_disable_tracepoint (loc);
14255 update_global_location_list (0);
14258 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
14262 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14265 int target_resources_ok;
14267 if (bpt->type == bp_hardware_breakpoint)
14270 i = hw_breakpoint_used_count ();
14271 target_resources_ok =
14272 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
14274 if (target_resources_ok == 0)
14275 error (_("No hardware breakpoint support in the target."));
14276 else if (target_resources_ok < 0)
14277 error (_("Hardware breakpoints used exceeds limit."));
14280 if (is_watchpoint (bpt))
14282 /* Initialize it just to avoid a GCC false warning. */
14283 enum enable_state orig_enable_state = 0;
14284 volatile struct gdb_exception e;
14286 TRY_CATCH (e, RETURN_MASK_ALL)
14288 struct watchpoint *w = (struct watchpoint *) bpt;
14290 orig_enable_state = bpt->enable_state;
14291 bpt->enable_state = bp_enabled;
14292 update_watchpoint (w, 1 /* reparse */);
14296 bpt->enable_state = orig_enable_state;
14297 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
14303 if (bpt->enable_state != bp_permanent)
14304 bpt->enable_state = bp_enabled;
14306 bpt->enable_state = bp_enabled;
14308 /* Mark breakpoint locations modified. */
14309 mark_breakpoint_modified (bpt);
14311 if (target_supports_enable_disable_tracepoint ()
14312 && current_trace_status ()->running && is_tracepoint (bpt))
14314 struct bp_location *location;
14316 for (location = bpt->loc; location; location = location->next)
14317 target_enable_tracepoint (location);
14320 bpt->disposition = disposition;
14321 bpt->enable_count = count;
14322 update_global_location_list (1);
14323 breakpoints_changed ();
14325 observer_notify_breakpoint_modified (bpt);
14330 enable_breakpoint (struct breakpoint *bpt)
14332 enable_breakpoint_disp (bpt, bpt->disposition, 0);
14336 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
14338 enable_breakpoint (bpt);
14341 /* A callback for map_breakpoint_numbers that calls
14342 enable_breakpoint. */
14345 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
14347 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
14350 /* The enable command enables the specified breakpoints (or all defined
14351 breakpoints) so they once again become (or continue to be) effective
14352 in stopping the inferior. */
14355 enable_command (char *args, int from_tty)
14359 struct breakpoint *bpt;
14361 ALL_BREAKPOINTS (bpt)
14362 if (user_breakpoint_p (bpt))
14363 enable_breakpoint (bpt);
14365 else if (strchr (args, '.'))
14367 struct bp_location *loc = find_location_by_number (args);
14373 mark_breakpoint_location_modified (loc);
14375 if (target_supports_enable_disable_tracepoint ()
14376 && current_trace_status ()->running && loc->owner
14377 && is_tracepoint (loc->owner))
14378 target_enable_tracepoint (loc);
14380 update_global_location_list (1);
14383 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
14386 /* This struct packages up disposition data for application to multiple
14396 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
14398 struct disp_data disp_data = *(struct disp_data *) arg;
14400 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
14404 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
14406 struct disp_data disp = { disp_disable, 1 };
14408 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14412 enable_once_command (char *args, int from_tty)
14414 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
14418 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
14420 struct disp_data disp = { disp_disable, *(int *) countptr };
14422 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14426 enable_count_command (char *args, int from_tty)
14428 int count = get_number (&args);
14430 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
14434 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
14436 struct disp_data disp = { disp_del, 1 };
14438 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14442 enable_delete_command (char *args, int from_tty)
14444 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
14448 set_breakpoint_cmd (char *args, int from_tty)
14453 show_breakpoint_cmd (char *args, int from_tty)
14457 /* Invalidate last known value of any hardware watchpoint if
14458 the memory which that value represents has been written to by
14462 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
14463 const bfd_byte *data)
14465 struct breakpoint *bp;
14467 ALL_BREAKPOINTS (bp)
14468 if (bp->enable_state == bp_enabled
14469 && bp->type == bp_hardware_watchpoint)
14471 struct watchpoint *wp = (struct watchpoint *) bp;
14473 if (wp->val_valid && wp->val)
14475 struct bp_location *loc;
14477 for (loc = bp->loc; loc != NULL; loc = loc->next)
14478 if (loc->loc_type == bp_loc_hardware_watchpoint
14479 && loc->address + loc->length > addr
14480 && addr + len > loc->address)
14482 value_free (wp->val);
14490 /* Create and insert a raw software breakpoint at PC. Return an
14491 identifier, which should be used to remove the breakpoint later.
14492 In general, places which call this should be using something on the
14493 breakpoint chain instead; this function should be eliminated
14497 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
14498 struct address_space *aspace, CORE_ADDR pc)
14500 struct bp_target_info *bp_tgt;
14502 bp_tgt = XZALLOC (struct bp_target_info);
14504 bp_tgt->placed_address_space = aspace;
14505 bp_tgt->placed_address = pc;
14507 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
14509 /* Could not insert the breakpoint. */
14517 /* Remove a breakpoint BP inserted by
14518 deprecated_insert_raw_breakpoint. */
14521 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
14523 struct bp_target_info *bp_tgt = bp;
14526 ret = target_remove_breakpoint (gdbarch, bp_tgt);
14532 /* One (or perhaps two) breakpoints used for software single
14535 static void *single_step_breakpoints[2];
14536 static struct gdbarch *single_step_gdbarch[2];
14538 /* Create and insert a breakpoint for software single step. */
14541 insert_single_step_breakpoint (struct gdbarch *gdbarch,
14542 struct address_space *aspace,
14547 if (single_step_breakpoints[0] == NULL)
14549 bpt_p = &single_step_breakpoints[0];
14550 single_step_gdbarch[0] = gdbarch;
14554 gdb_assert (single_step_breakpoints[1] == NULL);
14555 bpt_p = &single_step_breakpoints[1];
14556 single_step_gdbarch[1] = gdbarch;
14559 /* NOTE drow/2006-04-11: A future improvement to this function would
14560 be to only create the breakpoints once, and actually put them on
14561 the breakpoint chain. That would let us use set_raw_breakpoint.
14562 We could adjust the addresses each time they were needed. Doing
14563 this requires corresponding changes elsewhere where single step
14564 breakpoints are handled, however. So, for now, we use this. */
14566 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
14567 if (*bpt_p == NULL)
14568 error (_("Could not insert single-step breakpoint at %s"),
14569 paddress (gdbarch, next_pc));
14572 /* Check if the breakpoints used for software single stepping
14573 were inserted or not. */
14576 single_step_breakpoints_inserted (void)
14578 return (single_step_breakpoints[0] != NULL
14579 || single_step_breakpoints[1] != NULL);
14582 /* Remove and delete any breakpoints used for software single step. */
14585 remove_single_step_breakpoints (void)
14587 gdb_assert (single_step_breakpoints[0] != NULL);
14589 /* See insert_single_step_breakpoint for more about this deprecated
14591 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
14592 single_step_breakpoints[0]);
14593 single_step_gdbarch[0] = NULL;
14594 single_step_breakpoints[0] = NULL;
14596 if (single_step_breakpoints[1] != NULL)
14598 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
14599 single_step_breakpoints[1]);
14600 single_step_gdbarch[1] = NULL;
14601 single_step_breakpoints[1] = NULL;
14605 /* Delete software single step breakpoints without removing them from
14606 the inferior. This is intended to be used if the inferior's address
14607 space where they were inserted is already gone, e.g. after exit or
14611 cancel_single_step_breakpoints (void)
14615 for (i = 0; i < 2; i++)
14616 if (single_step_breakpoints[i])
14618 xfree (single_step_breakpoints[i]);
14619 single_step_breakpoints[i] = NULL;
14620 single_step_gdbarch[i] = NULL;
14624 /* Detach software single-step breakpoints from INFERIOR_PTID without
14628 detach_single_step_breakpoints (void)
14632 for (i = 0; i < 2; i++)
14633 if (single_step_breakpoints[i])
14634 target_remove_breakpoint (single_step_gdbarch[i],
14635 single_step_breakpoints[i]);
14638 /* Check whether a software single-step breakpoint is inserted at
14642 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
14647 for (i = 0; i < 2; i++)
14649 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
14651 && breakpoint_address_match (bp_tgt->placed_address_space,
14652 bp_tgt->placed_address,
14660 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
14661 non-zero otherwise. */
14663 is_syscall_catchpoint_enabled (struct breakpoint *bp)
14665 if (syscall_catchpoint_p (bp)
14666 && bp->enable_state != bp_disabled
14667 && bp->enable_state != bp_call_disabled)
14674 catch_syscall_enabled (void)
14676 struct catch_syscall_inferior_data *inf_data
14677 = get_catch_syscall_inferior_data (current_inferior ());
14679 return inf_data->total_syscalls_count != 0;
14683 catching_syscall_number (int syscall_number)
14685 struct breakpoint *bp;
14687 ALL_BREAKPOINTS (bp)
14688 if (is_syscall_catchpoint_enabled (bp))
14690 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
14692 if (c->syscalls_to_be_caught)
14696 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
14698 if (syscall_number == iter)
14708 /* Complete syscall names. Used by "catch syscall". */
14709 static VEC (char_ptr) *
14710 catch_syscall_completer (struct cmd_list_element *cmd,
14711 char *text, char *word)
14713 const char **list = get_syscall_names ();
14714 VEC (char_ptr) *retlist
14715 = (list == NULL) ? NULL : complete_on_enum (list, text, word);
14721 /* Tracepoint-specific operations. */
14723 /* Set tracepoint count to NUM. */
14725 set_tracepoint_count (int num)
14727 tracepoint_count = num;
14728 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
14732 trace_command (char *arg, int from_tty)
14734 struct breakpoint_ops *ops;
14735 const char *arg_cp = arg;
14737 if (arg && probe_linespec_to_ops (&arg_cp))
14738 ops = &tracepoint_probe_breakpoint_ops;
14740 ops = &tracepoint_breakpoint_ops;
14742 if (create_breakpoint (get_current_arch (),
14744 NULL, 0, NULL, 1 /* parse arg */,
14746 bp_tracepoint /* type_wanted */,
14747 0 /* Ignore count */,
14748 pending_break_support,
14752 0 /* internal */, 0))
14753 set_tracepoint_count (breakpoint_count);
14757 ftrace_command (char *arg, int from_tty)
14759 if (create_breakpoint (get_current_arch (),
14761 NULL, 0, NULL, 1 /* parse arg */,
14763 bp_fast_tracepoint /* type_wanted */,
14764 0 /* Ignore count */,
14765 pending_break_support,
14766 &tracepoint_breakpoint_ops,
14769 0 /* internal */, 0))
14770 set_tracepoint_count (breakpoint_count);
14773 /* strace command implementation. Creates a static tracepoint. */
14776 strace_command (char *arg, int from_tty)
14778 struct breakpoint_ops *ops;
14780 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14781 or with a normal static tracepoint. */
14782 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
14783 ops = &strace_marker_breakpoint_ops;
14785 ops = &tracepoint_breakpoint_ops;
14787 if (create_breakpoint (get_current_arch (),
14789 NULL, 0, NULL, 1 /* parse arg */,
14791 bp_static_tracepoint /* type_wanted */,
14792 0 /* Ignore count */,
14793 pending_break_support,
14797 0 /* internal */, 0))
14798 set_tracepoint_count (breakpoint_count);
14801 /* Set up a fake reader function that gets command lines from a linked
14802 list that was acquired during tracepoint uploading. */
14804 static struct uploaded_tp *this_utp;
14805 static int next_cmd;
14808 read_uploaded_action (void)
14812 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
14819 /* Given information about a tracepoint as recorded on a target (which
14820 can be either a live system or a trace file), attempt to create an
14821 equivalent GDB tracepoint. This is not a reliable process, since
14822 the target does not necessarily have all the information used when
14823 the tracepoint was originally defined. */
14825 struct tracepoint *
14826 create_tracepoint_from_upload (struct uploaded_tp *utp)
14828 char *addr_str, small_buf[100];
14829 struct tracepoint *tp;
14831 if (utp->at_string)
14832 addr_str = utp->at_string;
14835 /* In the absence of a source location, fall back to raw
14836 address. Since there is no way to confirm that the address
14837 means the same thing as when the trace was started, warn the
14839 warning (_("Uploaded tracepoint %d has no "
14840 "source location, using raw address"),
14842 sprintf (small_buf, "*%s", hex_string (utp->addr));
14843 addr_str = small_buf;
14846 /* There's not much we can do with a sequence of bytecodes. */
14847 if (utp->cond && !utp->cond_string)
14848 warning (_("Uploaded tracepoint %d condition "
14849 "has no source form, ignoring it"),
14852 if (!create_breakpoint (get_current_arch (),
14854 utp->cond_string, -1, NULL,
14855 0 /* parse cond/thread */,
14857 utp->type /* type_wanted */,
14858 0 /* Ignore count */,
14859 pending_break_support,
14860 &tracepoint_breakpoint_ops,
14862 utp->enabled /* enabled */,
14864 CREATE_BREAKPOINT_FLAGS_INSERTED))
14867 set_tracepoint_count (breakpoint_count);
14869 /* Get the tracepoint we just created. */
14870 tp = get_tracepoint (tracepoint_count);
14871 gdb_assert (tp != NULL);
14875 sprintf (small_buf, "%d %d", utp->pass, tp->base.number);
14877 trace_pass_command (small_buf, 0);
14880 /* If we have uploaded versions of the original commands, set up a
14881 special-purpose "reader" function and call the usual command line
14882 reader, then pass the result to the breakpoint command-setting
14884 if (!VEC_empty (char_ptr, utp->cmd_strings))
14886 struct command_line *cmd_list;
14891 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
14893 breakpoint_set_commands (&tp->base, cmd_list);
14895 else if (!VEC_empty (char_ptr, utp->actions)
14896 || !VEC_empty (char_ptr, utp->step_actions))
14897 warning (_("Uploaded tracepoint %d actions "
14898 "have no source form, ignoring them"),
14901 /* Copy any status information that might be available. */
14902 tp->base.hit_count = utp->hit_count;
14903 tp->traceframe_usage = utp->traceframe_usage;
14908 /* Print information on tracepoint number TPNUM_EXP, or all if
14912 tracepoints_info (char *args, int from_tty)
14914 struct ui_out *uiout = current_uiout;
14917 num_printed = breakpoint_1 (args, 0, is_tracepoint);
14919 if (num_printed == 0)
14921 if (args == NULL || *args == '\0')
14922 ui_out_message (uiout, 0, "No tracepoints.\n");
14924 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
14927 default_collect_info ();
14930 /* The 'enable trace' command enables tracepoints.
14931 Not supported by all targets. */
14933 enable_trace_command (char *args, int from_tty)
14935 enable_command (args, from_tty);
14938 /* The 'disable trace' command disables tracepoints.
14939 Not supported by all targets. */
14941 disable_trace_command (char *args, int from_tty)
14943 disable_command (args, from_tty);
14946 /* Remove a tracepoint (or all if no argument). */
14948 delete_trace_command (char *arg, int from_tty)
14950 struct breakpoint *b, *b_tmp;
14956 int breaks_to_delete = 0;
14958 /* Delete all breakpoints if no argument.
14959 Do not delete internal or call-dummy breakpoints, these
14960 have to be deleted with an explicit breakpoint number
14962 ALL_TRACEPOINTS (b)
14963 if (is_tracepoint (b) && user_breakpoint_p (b))
14965 breaks_to_delete = 1;
14969 /* Ask user only if there are some breakpoints to delete. */
14971 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
14973 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14974 if (is_tracepoint (b) && user_breakpoint_p (b))
14975 delete_breakpoint (b);
14979 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
14982 /* Helper function for trace_pass_command. */
14985 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
14987 tp->pass_count = count;
14988 observer_notify_tracepoint_modified (tp->base.number);
14990 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14991 tp->base.number, count);
14994 /* Set passcount for tracepoint.
14996 First command argument is passcount, second is tracepoint number.
14997 If tracepoint number omitted, apply to most recently defined.
14998 Also accepts special argument "all". */
15001 trace_pass_command (char *args, int from_tty)
15003 struct tracepoint *t1;
15004 unsigned int count;
15006 if (args == 0 || *args == 0)
15007 error (_("passcount command requires an "
15008 "argument (count + optional TP num)"));
15010 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
15012 while (*args && isspace ((int) *args))
15015 if (*args && strncasecmp (args, "all", 3) == 0)
15017 struct breakpoint *b;
15019 args += 3; /* Skip special argument "all". */
15021 error (_("Junk at end of arguments."));
15023 ALL_TRACEPOINTS (b)
15025 t1 = (struct tracepoint *) b;
15026 trace_pass_set_count (t1, count, from_tty);
15029 else if (*args == '\0')
15031 t1 = get_tracepoint_by_number (&args, NULL, 1);
15033 trace_pass_set_count (t1, count, from_tty);
15037 struct get_number_or_range_state state;
15039 init_number_or_range (&state, args);
15040 while (!state.finished)
15042 t1 = get_tracepoint_by_number (&args, &state, 1);
15044 trace_pass_set_count (t1, count, from_tty);
15049 struct tracepoint *
15050 get_tracepoint (int num)
15052 struct breakpoint *t;
15054 ALL_TRACEPOINTS (t)
15055 if (t->number == num)
15056 return (struct tracepoint *) t;
15061 /* Find the tracepoint with the given target-side number (which may be
15062 different from the tracepoint number after disconnecting and
15065 struct tracepoint *
15066 get_tracepoint_by_number_on_target (int num)
15068 struct breakpoint *b;
15070 ALL_TRACEPOINTS (b)
15072 struct tracepoint *t = (struct tracepoint *) b;
15074 if (t->number_on_target == num)
15081 /* Utility: parse a tracepoint number and look it up in the list.
15082 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15083 If OPTIONAL_P is true, then if the argument is missing, the most
15084 recent tracepoint (tracepoint_count) is returned. */
15085 struct tracepoint *
15086 get_tracepoint_by_number (char **arg,
15087 struct get_number_or_range_state *state,
15090 extern int tracepoint_count;
15091 struct breakpoint *t;
15093 char *instring = arg == NULL ? NULL : *arg;
15097 gdb_assert (!state->finished);
15098 tpnum = get_number_or_range (state);
15100 else if (arg == NULL || *arg == NULL || ! **arg)
15103 tpnum = tracepoint_count;
15105 error_no_arg (_("tracepoint number"));
15108 tpnum = get_number (arg);
15112 if (instring && *instring)
15113 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15116 printf_filtered (_("Tracepoint argument missing "
15117 "and no previous tracepoint\n"));
15121 ALL_TRACEPOINTS (t)
15122 if (t->number == tpnum)
15124 return (struct tracepoint *) t;
15127 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
15132 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
15134 if (b->thread != -1)
15135 fprintf_unfiltered (fp, " thread %d", b->thread);
15138 fprintf_unfiltered (fp, " task %d", b->task);
15140 fprintf_unfiltered (fp, "\n");
15143 /* Save information on user settable breakpoints (watchpoints, etc) to
15144 a new script file named FILENAME. If FILTER is non-NULL, call it
15145 on each breakpoint and only include the ones for which it returns
15149 save_breakpoints (char *filename, int from_tty,
15150 int (*filter) (const struct breakpoint *))
15152 struct breakpoint *tp;
15155 struct cleanup *cleanup;
15156 struct ui_file *fp;
15157 int extra_trace_bits = 0;
15159 if (filename == 0 || *filename == 0)
15160 error (_("Argument required (file name in which to save)"));
15162 /* See if we have anything to save. */
15163 ALL_BREAKPOINTS (tp)
15165 /* Skip internal and momentary breakpoints. */
15166 if (!user_breakpoint_p (tp))
15169 /* If we have a filter, only save the breakpoints it accepts. */
15170 if (filter && !filter (tp))
15175 if (is_tracepoint (tp))
15177 extra_trace_bits = 1;
15179 /* We can stop searching. */
15186 warning (_("Nothing to save."));
15190 pathname = tilde_expand (filename);
15191 cleanup = make_cleanup (xfree, pathname);
15192 fp = gdb_fopen (pathname, "w");
15194 error (_("Unable to open file '%s' for saving (%s)"),
15195 filename, safe_strerror (errno));
15196 make_cleanup_ui_file_delete (fp);
15198 if (extra_trace_bits)
15199 save_trace_state_variables (fp);
15201 ALL_BREAKPOINTS (tp)
15203 /* Skip internal and momentary breakpoints. */
15204 if (!user_breakpoint_p (tp))
15207 /* If we have a filter, only save the breakpoints it accepts. */
15208 if (filter && !filter (tp))
15211 tp->ops->print_recreate (tp, fp);
15213 /* Note, we can't rely on tp->number for anything, as we can't
15214 assume the recreated breakpoint numbers will match. Use $bpnum
15217 if (tp->cond_string)
15218 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
15220 if (tp->ignore_count)
15221 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
15225 volatile struct gdb_exception ex;
15227 fprintf_unfiltered (fp, " commands\n");
15229 ui_out_redirect (current_uiout, fp);
15230 TRY_CATCH (ex, RETURN_MASK_ALL)
15232 print_command_lines (current_uiout, tp->commands->commands, 2);
15234 ui_out_redirect (current_uiout, NULL);
15237 throw_exception (ex);
15239 fprintf_unfiltered (fp, " end\n");
15242 if (tp->enable_state == bp_disabled)
15243 fprintf_unfiltered (fp, "disable\n");
15245 /* If this is a multi-location breakpoint, check if the locations
15246 should be individually disabled. Watchpoint locations are
15247 special, and not user visible. */
15248 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15250 struct bp_location *loc;
15253 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15255 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
15259 if (extra_trace_bits && *default_collect)
15260 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
15262 do_cleanups (cleanup);
15264 printf_filtered (_("Saved to file '%s'.\n"), filename);
15267 /* The `save breakpoints' command. */
15270 save_breakpoints_command (char *args, int from_tty)
15272 save_breakpoints (args, from_tty, NULL);
15275 /* The `save tracepoints' command. */
15278 save_tracepoints_command (char *args, int from_tty)
15280 save_breakpoints (args, from_tty, is_tracepoint);
15283 /* Create a vector of all tracepoints. */
15285 VEC(breakpoint_p) *
15286 all_tracepoints (void)
15288 VEC(breakpoint_p) *tp_vec = 0;
15289 struct breakpoint *tp;
15291 ALL_TRACEPOINTS (tp)
15293 VEC_safe_push (breakpoint_p, tp_vec, tp);
15300 /* This help string is used for the break, hbreak, tbreak and thbreak
15301 commands. It is defined as a macro to prevent duplication.
15302 COMMAND should be a string constant containing the name of the
15304 #define BREAK_ARGS_HELP(command) \
15305 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15306 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15307 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15308 guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
15309 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15310 If a line number is specified, break at start of code for that line.\n\
15311 If a function is specified, break at start of code for that function.\n\
15312 If an address is specified, break at that exact address.\n\
15313 With no LOCATION, uses current execution address of the selected\n\
15314 stack frame. This is useful for breaking on return to a stack frame.\n\
15316 THREADNUM is the number from \"info threads\".\n\
15317 CONDITION is a boolean expression.\n\
15319 Multiple breakpoints at one place are permitted, and useful if their\n\
15320 conditions are different.\n\
15322 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15324 /* List of subcommands for "catch". */
15325 static struct cmd_list_element *catch_cmdlist;
15327 /* List of subcommands for "tcatch". */
15328 static struct cmd_list_element *tcatch_cmdlist;
15331 add_catch_command (char *name, char *docstring,
15332 void (*sfunc) (char *args, int from_tty,
15333 struct cmd_list_element *command),
15334 completer_ftype *completer,
15335 void *user_data_catch,
15336 void *user_data_tcatch)
15338 struct cmd_list_element *command;
15340 command = add_cmd (name, class_breakpoint, NULL, docstring,
15342 set_cmd_sfunc (command, sfunc);
15343 set_cmd_context (command, user_data_catch);
15344 set_cmd_completer (command, completer);
15346 command = add_cmd (name, class_breakpoint, NULL, docstring,
15348 set_cmd_sfunc (command, sfunc);
15349 set_cmd_context (command, user_data_tcatch);
15350 set_cmd_completer (command, completer);
15354 clear_syscall_counts (struct inferior *inf)
15356 struct catch_syscall_inferior_data *inf_data
15357 = get_catch_syscall_inferior_data (inf);
15359 inf_data->total_syscalls_count = 0;
15360 inf_data->any_syscall_count = 0;
15361 VEC_free (int, inf_data->syscalls_counts);
15365 save_command (char *arg, int from_tty)
15367 printf_unfiltered (_("\"save\" must be followed by "
15368 "the name of a save subcommand.\n"));
15369 help_list (save_cmdlist, "save ", -1, gdb_stdout);
15372 struct breakpoint *
15373 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15376 struct breakpoint *b, *b_tmp;
15378 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15380 if ((*callback) (b, data))
15387 /* Zero if any of the breakpoint's locations could be a location where
15388 functions have been inlined, nonzero otherwise. */
15391 is_non_inline_function (struct breakpoint *b)
15393 /* The shared library event breakpoint is set on the address of a
15394 non-inline function. */
15395 if (b->type == bp_shlib_event)
15401 /* Nonzero if the specified PC cannot be a location where functions
15402 have been inlined. */
15405 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
15406 const struct target_waitstatus *ws)
15408 struct breakpoint *b;
15409 struct bp_location *bl;
15411 ALL_BREAKPOINTS (b)
15413 if (!is_non_inline_function (b))
15416 for (bl = b->loc; bl != NULL; bl = bl->next)
15418 if (!bl->shlib_disabled
15419 && bpstat_check_location (bl, aspace, pc, ws))
15428 initialize_breakpoint_ops (void)
15430 static int initialized = 0;
15432 struct breakpoint_ops *ops;
15438 /* The breakpoint_ops structure to be inherit by all kinds of
15439 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15440 internal and momentary breakpoints, etc.). */
15441 ops = &bkpt_base_breakpoint_ops;
15442 *ops = base_breakpoint_ops;
15443 ops->re_set = bkpt_re_set;
15444 ops->insert_location = bkpt_insert_location;
15445 ops->remove_location = bkpt_remove_location;
15446 ops->breakpoint_hit = bkpt_breakpoint_hit;
15447 ops->create_sals_from_address = bkpt_create_sals_from_address;
15448 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
15449 ops->decode_linespec = bkpt_decode_linespec;
15451 /* The breakpoint_ops structure to be used in regular breakpoints. */
15452 ops = &bkpt_breakpoint_ops;
15453 *ops = bkpt_base_breakpoint_ops;
15454 ops->re_set = bkpt_re_set;
15455 ops->resources_needed = bkpt_resources_needed;
15456 ops->print_it = bkpt_print_it;
15457 ops->print_mention = bkpt_print_mention;
15458 ops->print_recreate = bkpt_print_recreate;
15460 /* Ranged breakpoints. */
15461 ops = &ranged_breakpoint_ops;
15462 *ops = bkpt_breakpoint_ops;
15463 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
15464 ops->resources_needed = resources_needed_ranged_breakpoint;
15465 ops->print_it = print_it_ranged_breakpoint;
15466 ops->print_one = print_one_ranged_breakpoint;
15467 ops->print_one_detail = print_one_detail_ranged_breakpoint;
15468 ops->print_mention = print_mention_ranged_breakpoint;
15469 ops->print_recreate = print_recreate_ranged_breakpoint;
15471 /* Internal breakpoints. */
15472 ops = &internal_breakpoint_ops;
15473 *ops = bkpt_base_breakpoint_ops;
15474 ops->re_set = internal_bkpt_re_set;
15475 ops->check_status = internal_bkpt_check_status;
15476 ops->print_it = internal_bkpt_print_it;
15477 ops->print_mention = internal_bkpt_print_mention;
15479 /* Momentary breakpoints. */
15480 ops = &momentary_breakpoint_ops;
15481 *ops = bkpt_base_breakpoint_ops;
15482 ops->re_set = momentary_bkpt_re_set;
15483 ops->check_status = momentary_bkpt_check_status;
15484 ops->print_it = momentary_bkpt_print_it;
15485 ops->print_mention = momentary_bkpt_print_mention;
15487 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15488 ops = &longjmp_breakpoint_ops;
15489 *ops = momentary_breakpoint_ops;
15490 ops->dtor = longjmp_bkpt_dtor;
15492 /* Probe breakpoints. */
15493 ops = &bkpt_probe_breakpoint_ops;
15494 *ops = bkpt_breakpoint_ops;
15495 ops->insert_location = bkpt_probe_insert_location;
15496 ops->remove_location = bkpt_probe_remove_location;
15497 ops->create_sals_from_address = bkpt_probe_create_sals_from_address;
15498 ops->decode_linespec = bkpt_probe_decode_linespec;
15500 /* GNU v3 exception catchpoints. */
15501 ops = &gnu_v3_exception_catchpoint_ops;
15502 *ops = bkpt_breakpoint_ops;
15503 ops->print_it = print_it_exception_catchpoint;
15504 ops->print_one = print_one_exception_catchpoint;
15505 ops->print_mention = print_mention_exception_catchpoint;
15506 ops->print_recreate = print_recreate_exception_catchpoint;
15509 ops = &watchpoint_breakpoint_ops;
15510 *ops = base_breakpoint_ops;
15511 ops->dtor = dtor_watchpoint;
15512 ops->re_set = re_set_watchpoint;
15513 ops->insert_location = insert_watchpoint;
15514 ops->remove_location = remove_watchpoint;
15515 ops->breakpoint_hit = breakpoint_hit_watchpoint;
15516 ops->check_status = check_status_watchpoint;
15517 ops->resources_needed = resources_needed_watchpoint;
15518 ops->works_in_software_mode = works_in_software_mode_watchpoint;
15519 ops->print_it = print_it_watchpoint;
15520 ops->print_mention = print_mention_watchpoint;
15521 ops->print_recreate = print_recreate_watchpoint;
15523 /* Masked watchpoints. */
15524 ops = &masked_watchpoint_breakpoint_ops;
15525 *ops = watchpoint_breakpoint_ops;
15526 ops->insert_location = insert_masked_watchpoint;
15527 ops->remove_location = remove_masked_watchpoint;
15528 ops->resources_needed = resources_needed_masked_watchpoint;
15529 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
15530 ops->print_it = print_it_masked_watchpoint;
15531 ops->print_one_detail = print_one_detail_masked_watchpoint;
15532 ops->print_mention = print_mention_masked_watchpoint;
15533 ops->print_recreate = print_recreate_masked_watchpoint;
15536 ops = &tracepoint_breakpoint_ops;
15537 *ops = base_breakpoint_ops;
15538 ops->re_set = tracepoint_re_set;
15539 ops->breakpoint_hit = tracepoint_breakpoint_hit;
15540 ops->print_one_detail = tracepoint_print_one_detail;
15541 ops->print_mention = tracepoint_print_mention;
15542 ops->print_recreate = tracepoint_print_recreate;
15543 ops->create_sals_from_address = tracepoint_create_sals_from_address;
15544 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
15545 ops->decode_linespec = tracepoint_decode_linespec;
15547 /* Probe tracepoints. */
15548 ops = &tracepoint_probe_breakpoint_ops;
15549 *ops = tracepoint_breakpoint_ops;
15550 ops->create_sals_from_address = tracepoint_probe_create_sals_from_address;
15551 ops->decode_linespec = tracepoint_probe_decode_linespec;
15553 /* Static tracepoints with marker (`-m'). */
15554 ops = &strace_marker_breakpoint_ops;
15555 *ops = tracepoint_breakpoint_ops;
15556 ops->create_sals_from_address = strace_marker_create_sals_from_address;
15557 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
15558 ops->decode_linespec = strace_marker_decode_linespec;
15560 /* Fork catchpoints. */
15561 ops = &catch_fork_breakpoint_ops;
15562 *ops = base_breakpoint_ops;
15563 ops->insert_location = insert_catch_fork;
15564 ops->remove_location = remove_catch_fork;
15565 ops->breakpoint_hit = breakpoint_hit_catch_fork;
15566 ops->print_it = print_it_catch_fork;
15567 ops->print_one = print_one_catch_fork;
15568 ops->print_mention = print_mention_catch_fork;
15569 ops->print_recreate = print_recreate_catch_fork;
15571 /* Vfork catchpoints. */
15572 ops = &catch_vfork_breakpoint_ops;
15573 *ops = base_breakpoint_ops;
15574 ops->insert_location = insert_catch_vfork;
15575 ops->remove_location = remove_catch_vfork;
15576 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
15577 ops->print_it = print_it_catch_vfork;
15578 ops->print_one = print_one_catch_vfork;
15579 ops->print_mention = print_mention_catch_vfork;
15580 ops->print_recreate = print_recreate_catch_vfork;
15582 /* Exec catchpoints. */
15583 ops = &catch_exec_breakpoint_ops;
15584 *ops = base_breakpoint_ops;
15585 ops->dtor = dtor_catch_exec;
15586 ops->insert_location = insert_catch_exec;
15587 ops->remove_location = remove_catch_exec;
15588 ops->breakpoint_hit = breakpoint_hit_catch_exec;
15589 ops->print_it = print_it_catch_exec;
15590 ops->print_one = print_one_catch_exec;
15591 ops->print_mention = print_mention_catch_exec;
15592 ops->print_recreate = print_recreate_catch_exec;
15594 /* Syscall catchpoints. */
15595 ops = &catch_syscall_breakpoint_ops;
15596 *ops = base_breakpoint_ops;
15597 ops->dtor = dtor_catch_syscall;
15598 ops->insert_location = insert_catch_syscall;
15599 ops->remove_location = remove_catch_syscall;
15600 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
15601 ops->print_it = print_it_catch_syscall;
15602 ops->print_one = print_one_catch_syscall;
15603 ops->print_mention = print_mention_catch_syscall;
15604 ops->print_recreate = print_recreate_catch_syscall;
15606 /* Solib-related catchpoints. */
15607 ops = &catch_solib_breakpoint_ops;
15608 *ops = base_breakpoint_ops;
15609 ops->dtor = dtor_catch_solib;
15610 ops->insert_location = insert_catch_solib;
15611 ops->remove_location = remove_catch_solib;
15612 ops->breakpoint_hit = breakpoint_hit_catch_solib;
15613 ops->check_status = check_status_catch_solib;
15614 ops->print_it = print_it_catch_solib;
15615 ops->print_one = print_one_catch_solib;
15616 ops->print_mention = print_mention_catch_solib;
15617 ops->print_recreate = print_recreate_catch_solib;
15619 ops = &dprintf_breakpoint_ops;
15620 *ops = bkpt_base_breakpoint_ops;
15621 ops->re_set = bkpt_re_set;
15622 ops->resources_needed = bkpt_resources_needed;
15623 ops->print_it = bkpt_print_it;
15624 ops->print_mention = bkpt_print_mention;
15625 ops->print_recreate = bkpt_print_recreate;
15629 _initialize_breakpoint (void)
15631 struct cmd_list_element *c;
15633 initialize_breakpoint_ops ();
15635 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
15636 observer_attach_inferior_exit (clear_syscall_counts);
15637 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
15639 breakpoint_objfile_key
15640 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
15642 catch_syscall_inferior_data
15643 = register_inferior_data_with_cleanup (catch_syscall_inferior_data_cleanup);
15645 breakpoint_chain = 0;
15646 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15647 before a breakpoint is set. */
15648 breakpoint_count = 0;
15650 tracepoint_count = 0;
15652 add_com ("ignore", class_breakpoint, ignore_command, _("\
15653 Set ignore-count of breakpoint number N to COUNT.\n\
15654 Usage is `ignore N COUNT'."));
15656 add_com_alias ("bc", "ignore", class_breakpoint, 1);
15658 add_com ("commands", class_breakpoint, commands_command, _("\
15659 Set commands to be executed when a breakpoint is hit.\n\
15660 Give breakpoint number as argument after \"commands\".\n\
15661 With no argument, the targeted breakpoint is the last one set.\n\
15662 The commands themselves follow starting on the next line.\n\
15663 Type a line containing \"end\" to indicate the end of them.\n\
15664 Give \"silent\" as the first line to make the breakpoint silent;\n\
15665 then no output is printed when it is hit, except what the commands print."));
15667 c = add_com ("condition", class_breakpoint, condition_command, _("\
15668 Specify breakpoint number N to break only if COND is true.\n\
15669 Usage is `condition N COND', where N is an integer and COND is an\n\
15670 expression to be evaluated whenever breakpoint N is reached."));
15671 set_cmd_completer (c, condition_completer);
15673 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
15674 Set a temporary breakpoint.\n\
15675 Like \"break\" except the breakpoint is only temporary,\n\
15676 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15677 by using \"enable delete\" on the breakpoint number.\n\
15679 BREAK_ARGS_HELP ("tbreak")));
15680 set_cmd_completer (c, location_completer);
15682 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
15683 Set a hardware assisted breakpoint.\n\
15684 Like \"break\" except the breakpoint requires hardware support,\n\
15685 some target hardware may not have this support.\n\
15687 BREAK_ARGS_HELP ("hbreak")));
15688 set_cmd_completer (c, location_completer);
15690 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
15691 Set a temporary hardware assisted breakpoint.\n\
15692 Like \"hbreak\" except the breakpoint is only temporary,\n\
15693 so it will be deleted when hit.\n\
15695 BREAK_ARGS_HELP ("thbreak")));
15696 set_cmd_completer (c, location_completer);
15698 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
15699 Enable some breakpoints.\n\
15700 Give breakpoint numbers (separated by spaces) as arguments.\n\
15701 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15702 This is used to cancel the effect of the \"disable\" command.\n\
15703 With a subcommand you can enable temporarily."),
15704 &enablelist, "enable ", 1, &cmdlist);
15706 add_com ("ab", class_breakpoint, enable_command, _("\
15707 Enable some breakpoints.\n\
15708 Give breakpoint numbers (separated by spaces) as arguments.\n\
15709 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15710 This is used to cancel the effect of the \"disable\" command.\n\
15711 With a subcommand you can enable temporarily."));
15713 add_com_alias ("en", "enable", class_breakpoint, 1);
15715 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
15716 Enable some breakpoints.\n\
15717 Give breakpoint numbers (separated by spaces) as arguments.\n\
15718 This is used to cancel the effect of the \"disable\" command.\n\
15719 May be abbreviated to simply \"enable\".\n"),
15720 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
15722 add_cmd ("once", no_class, enable_once_command, _("\
15723 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15724 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15727 add_cmd ("delete", no_class, enable_delete_command, _("\
15728 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15729 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15732 add_cmd ("count", no_class, enable_count_command, _("\
15733 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15734 If a breakpoint is hit while enabled in this fashion,\n\
15735 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15738 add_cmd ("delete", no_class, enable_delete_command, _("\
15739 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15740 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15743 add_cmd ("once", no_class, enable_once_command, _("\
15744 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15745 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15748 add_cmd ("count", no_class, enable_count_command, _("\
15749 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15750 If a breakpoint is hit while enabled in this fashion,\n\
15751 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15754 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
15755 Disable some breakpoints.\n\
15756 Arguments are breakpoint numbers with spaces in between.\n\
15757 To disable all breakpoints, give no argument.\n\
15758 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15759 &disablelist, "disable ", 1, &cmdlist);
15760 add_com_alias ("dis", "disable", class_breakpoint, 1);
15761 add_com_alias ("disa", "disable", class_breakpoint, 1);
15763 add_com ("sb", class_breakpoint, disable_command, _("\
15764 Disable some breakpoints.\n\
15765 Arguments are breakpoint numbers with spaces in between.\n\
15766 To disable all breakpoints, give no argument.\n\
15767 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
15769 add_cmd ("breakpoints", class_alias, disable_command, _("\
15770 Disable some breakpoints.\n\
15771 Arguments are breakpoint numbers with spaces in between.\n\
15772 To disable all breakpoints, give no argument.\n\
15773 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15774 This command may be abbreviated \"disable\"."),
15777 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
15778 Delete some breakpoints or auto-display expressions.\n\
15779 Arguments are breakpoint numbers with spaces in between.\n\
15780 To delete all breakpoints, give no argument.\n\
15782 Also a prefix command for deletion of other GDB objects.\n\
15783 The \"unset\" command is also an alias for \"delete\"."),
15784 &deletelist, "delete ", 1, &cmdlist);
15785 add_com_alias ("d", "delete", class_breakpoint, 1);
15786 add_com_alias ("del", "delete", class_breakpoint, 1);
15788 add_com ("db", class_breakpoint, delete_command, _("\
15789 Delete some breakpoints.\n\
15790 Arguments are breakpoint numbers with spaces in between.\n\
15791 To delete all breakpoints, give no argument.\n"));
15793 add_cmd ("breakpoints", class_alias, delete_command, _("\
15794 Delete some breakpoints or auto-display expressions.\n\
15795 Arguments are breakpoint numbers with spaces in between.\n\
15796 To delete all breakpoints, give no argument.\n\
15797 This command may be abbreviated \"delete\"."),
15800 add_com ("clear", class_breakpoint, clear_command, _("\
15801 Clear breakpoint at specified line or function.\n\
15802 Argument may be line number, function name, or \"*\" and an address.\n\
15803 If line number is specified, all breakpoints in that line are cleared.\n\
15804 If function is specified, breakpoints at beginning of function are cleared.\n\
15805 If an address is specified, breakpoints at that address are cleared.\n\
15807 With no argument, clears all breakpoints in the line that the selected frame\n\
15808 is executing in.\n\
15810 See also the \"delete\" command which clears breakpoints by number."));
15811 add_com_alias ("cl", "clear", class_breakpoint, 1);
15813 c = add_com ("break", class_breakpoint, break_command, _("\
15814 Set breakpoint at specified line or function.\n"
15815 BREAK_ARGS_HELP ("break")));
15816 set_cmd_completer (c, location_completer);
15818 add_com_alias ("b", "break", class_run, 1);
15819 add_com_alias ("br", "break", class_run, 1);
15820 add_com_alias ("bre", "break", class_run, 1);
15821 add_com_alias ("brea", "break", class_run, 1);
15824 add_com_alias ("ba", "break", class_breakpoint, 1);
15828 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
15829 Break in function/address or break at a line in the current file."),
15830 &stoplist, "stop ", 1, &cmdlist);
15831 add_cmd ("in", class_breakpoint, stopin_command,
15832 _("Break in function or address."), &stoplist);
15833 add_cmd ("at", class_breakpoint, stopat_command,
15834 _("Break at a line in the current file."), &stoplist);
15835 add_com ("status", class_info, breakpoints_info, _("\
15836 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15837 The \"Type\" column indicates one of:\n\
15838 \tbreakpoint - normal breakpoint\n\
15839 \twatchpoint - watchpoint\n\
15840 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15841 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15842 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15843 address and file/line number respectively.\n\
15845 Convenience variable \"$_\" and default examine address for \"x\"\n\
15846 are set to the address of the last breakpoint listed unless the command\n\
15847 is prefixed with \"server \".\n\n\
15848 Convenience variable \"$bpnum\" contains the number of the last\n\
15849 breakpoint set."));
15852 add_info ("breakpoints", breakpoints_info, _("\
15853 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15854 The \"Type\" column indicates one of:\n\
15855 \tbreakpoint - normal breakpoint\n\
15856 \twatchpoint - watchpoint\n\
15857 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15858 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15859 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15860 address and file/line number respectively.\n\
15862 Convenience variable \"$_\" and default examine address for \"x\"\n\
15863 are set to the address of the last breakpoint listed unless the command\n\
15864 is prefixed with \"server \".\n\n\
15865 Convenience variable \"$bpnum\" contains the number of the last\n\
15866 breakpoint set."));
15868 add_info_alias ("b", "breakpoints", 1);
15871 add_com ("lb", class_breakpoint, breakpoints_info, _("\
15872 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15873 The \"Type\" column indicates one of:\n\
15874 \tbreakpoint - normal breakpoint\n\
15875 \twatchpoint - watchpoint\n\
15876 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15877 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15878 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15879 address and file/line number respectively.\n\
15881 Convenience variable \"$_\" and default examine address for \"x\"\n\
15882 are set to the address of the last breakpoint listed unless the command\n\
15883 is prefixed with \"server \".\n\n\
15884 Convenience variable \"$bpnum\" contains the number of the last\n\
15885 breakpoint set."));
15887 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
15888 Status of all breakpoints, or breakpoint number NUMBER.\n\
15889 The \"Type\" column indicates one of:\n\
15890 \tbreakpoint - normal breakpoint\n\
15891 \twatchpoint - watchpoint\n\
15892 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15893 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15894 \tuntil - internal breakpoint used by the \"until\" command\n\
15895 \tfinish - internal breakpoint used by the \"finish\" command\n\
15896 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15897 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15898 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15899 address and file/line number respectively.\n\
15901 Convenience variable \"$_\" and default examine address for \"x\"\n\
15902 are set to the address of the last breakpoint listed unless the command\n\
15903 is prefixed with \"server \".\n\n\
15904 Convenience variable \"$bpnum\" contains the number of the last\n\
15906 &maintenanceinfolist);
15908 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
15909 Set catchpoints to catch events."),
15910 &catch_cmdlist, "catch ",
15911 0/*allow-unknown*/, &cmdlist);
15913 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
15914 Set temporary catchpoints to catch events."),
15915 &tcatch_cmdlist, "tcatch ",
15916 0/*allow-unknown*/, &cmdlist);
15918 /* Add catch and tcatch sub-commands. */
15919 add_catch_command ("catch", _("\
15920 Catch an exception, when caught."),
15921 catch_catch_command,
15925 add_catch_command ("throw", _("\
15926 Catch an exception, when thrown."),
15927 catch_throw_command,
15931 add_catch_command ("fork", _("Catch calls to fork."),
15932 catch_fork_command_1,
15934 (void *) (uintptr_t) catch_fork_permanent,
15935 (void *) (uintptr_t) catch_fork_temporary);
15936 add_catch_command ("vfork", _("Catch calls to vfork."),
15937 catch_fork_command_1,
15939 (void *) (uintptr_t) catch_vfork_permanent,
15940 (void *) (uintptr_t) catch_vfork_temporary);
15941 add_catch_command ("exec", _("Catch calls to exec."),
15942 catch_exec_command_1,
15946 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15947 Usage: catch load [REGEX]\n\
15948 If REGEX is given, only stop for libraries matching the regular expression."),
15949 catch_load_command_1,
15953 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15954 Usage: catch unload [REGEX]\n\
15955 If REGEX is given, only stop for libraries matching the regular expression."),
15956 catch_unload_command_1,
15960 add_catch_command ("syscall", _("\
15961 Catch system calls by their names and/or numbers.\n\
15962 Arguments say which system calls to catch. If no arguments\n\
15963 are given, every system call will be caught.\n\
15964 Arguments, if given, should be one or more system call names\n\
15965 (if your system supports that), or system call numbers."),
15966 catch_syscall_command_1,
15967 catch_syscall_completer,
15971 c = add_com ("watch", class_breakpoint, watch_command, _("\
15972 Set a watchpoint for an expression.\n\
15973 Usage: watch [-l|-location] EXPRESSION\n\
15974 A watchpoint stops execution of your program whenever the value of\n\
15975 an expression changes.\n\
15976 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15977 the memory to which it refers."));
15978 set_cmd_completer (c, expression_completer);
15980 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
15981 Set a read watchpoint for an expression.\n\
15982 Usage: rwatch [-l|-location] EXPRESSION\n\
15983 A watchpoint stops execution of your program whenever the value of\n\
15984 an expression is read.\n\
15985 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15986 the memory to which it refers."));
15987 set_cmd_completer (c, expression_completer);
15989 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
15990 Set a watchpoint for an expression.\n\
15991 Usage: awatch [-l|-location] EXPRESSION\n\
15992 A watchpoint stops execution of your program whenever the value of\n\
15993 an expression is either read or written.\n\
15994 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15995 the memory to which it refers."));
15996 set_cmd_completer (c, expression_completer);
15998 add_info ("watchpoints", watchpoints_info, _("\
15999 Status of specified watchpoints (all watchpoints if no argument)."));
16001 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16002 respond to changes - contrary to the description. */
16003 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
16004 &can_use_hw_watchpoints, _("\
16005 Set debugger's willingness to use watchpoint hardware."), _("\
16006 Show debugger's willingness to use watchpoint hardware."), _("\
16007 If zero, gdb will not use hardware for new watchpoints, even if\n\
16008 such is available. (However, any hardware watchpoints that were\n\
16009 created before setting this to nonzero, will continue to use watchpoint\n\
16012 show_can_use_hw_watchpoints,
16013 &setlist, &showlist);
16015 can_use_hw_watchpoints = 1;
16017 /* Tracepoint manipulation commands. */
16019 c = add_com ("trace", class_breakpoint, trace_command, _("\
16020 Set a tracepoint at specified line or function.\n\
16022 BREAK_ARGS_HELP ("trace") "\n\
16023 Do \"help tracepoints\" for info on other tracepoint commands."));
16024 set_cmd_completer (c, location_completer);
16026 add_com_alias ("tp", "trace", class_alias, 0);
16027 add_com_alias ("tr", "trace", class_alias, 1);
16028 add_com_alias ("tra", "trace", class_alias, 1);
16029 add_com_alias ("trac", "trace", class_alias, 1);
16031 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
16032 Set a fast tracepoint at specified line or function.\n\
16034 BREAK_ARGS_HELP ("ftrace") "\n\
16035 Do \"help tracepoints\" for info on other tracepoint commands."));
16036 set_cmd_completer (c, location_completer);
16038 c = add_com ("strace", class_breakpoint, strace_command, _("\
16039 Set a static tracepoint at specified line, function or marker.\n\
16041 strace [LOCATION] [if CONDITION]\n\
16042 LOCATION may be a line number, function name, \"*\" and an address,\n\
16043 or -m MARKER_ID.\n\
16044 If a line number is specified, probe the marker at start of code\n\
16045 for that line. If a function is specified, probe the marker at start\n\
16046 of code for that function. If an address is specified, probe the marker\n\
16047 at that exact address. If a marker id is specified, probe the marker\n\
16048 with that name. With no LOCATION, uses current execution address of\n\
16049 the selected stack frame.\n\
16050 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16051 This collects arbitrary user data passed in the probe point call to the\n\
16052 tracing library. You can inspect it when analyzing the trace buffer,\n\
16053 by printing the $_sdata variable like any other convenience variable.\n\
16055 CONDITION is a boolean expression.\n\
16057 Multiple tracepoints at one place are permitted, and useful if their\n\
16058 conditions are different.\n\
16060 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16061 Do \"help tracepoints\" for info on other tracepoint commands."));
16062 set_cmd_completer (c, location_completer);
16064 add_info ("tracepoints", tracepoints_info, _("\
16065 Status of specified tracepoints (all tracepoints if no argument).\n\
16066 Convenience variable \"$tpnum\" contains the number of the\n\
16067 last tracepoint set."));
16069 add_info_alias ("tp", "tracepoints", 1);
16071 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
16072 Delete specified tracepoints.\n\
16073 Arguments are tracepoint numbers, separated by spaces.\n\
16074 No argument means delete all tracepoints."),
16077 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
16078 Disable specified tracepoints.\n\
16079 Arguments are tracepoint numbers, separated by spaces.\n\
16080 No argument means disable all tracepoints."),
16082 deprecate_cmd (c, "disable");
16084 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
16085 Enable specified tracepoints.\n\
16086 Arguments are tracepoint numbers, separated by spaces.\n\
16087 No argument means enable all tracepoints."),
16089 deprecate_cmd (c, "enable");
16091 add_com ("passcount", class_trace, trace_pass_command, _("\
16092 Set the passcount for a tracepoint.\n\
16093 The trace will end when the tracepoint has been passed 'count' times.\n\
16094 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16095 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16097 add_prefix_cmd ("save", class_breakpoint, save_command,
16098 _("Save breakpoint definitions as a script."),
16099 &save_cmdlist, "save ",
16100 0/*allow-unknown*/, &cmdlist);
16102 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
16103 Save current breakpoint definitions as a script.\n\
16104 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16105 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16106 session to restore them."),
16108 set_cmd_completer (c, filename_completer);
16110 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
16111 Save current tracepoint definitions as a script.\n\
16112 Use the 'source' command in another debug session to restore them."),
16114 set_cmd_completer (c, filename_completer);
16116 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
16117 deprecate_cmd (c, "save tracepoints");
16119 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
16120 Breakpoint specific settings\n\
16121 Configure various breakpoint-specific variables such as\n\
16122 pending breakpoint behavior"),
16123 &breakpoint_set_cmdlist, "set breakpoint ",
16124 0/*allow-unknown*/, &setlist);
16125 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
16126 Breakpoint specific settings\n\
16127 Configure various breakpoint-specific variables such as\n\
16128 pending breakpoint behavior"),
16129 &breakpoint_show_cmdlist, "show breakpoint ",
16130 0/*allow-unknown*/, &showlist);
16132 add_setshow_auto_boolean_cmd ("pending", no_class,
16133 &pending_break_support, _("\
16134 Set debugger's behavior regarding pending breakpoints."), _("\
16135 Show debugger's behavior regarding pending breakpoints."), _("\
16136 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16137 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16138 an error. If auto, an unrecognized breakpoint location results in a\n\
16139 user-query to see if a pending breakpoint should be created."),
16141 show_pending_break_support,
16142 &breakpoint_set_cmdlist,
16143 &breakpoint_show_cmdlist);
16145 pending_break_support = AUTO_BOOLEAN_AUTO;
16147 add_setshow_boolean_cmd ("auto-hw", no_class,
16148 &automatic_hardware_breakpoints, _("\
16149 Set automatic usage of hardware breakpoints."), _("\
16150 Show automatic usage of hardware breakpoints."), _("\
16151 If set, the debugger will automatically use hardware breakpoints for\n\
16152 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16153 a warning will be emitted for such breakpoints."),
16155 show_automatic_hardware_breakpoints,
16156 &breakpoint_set_cmdlist,
16157 &breakpoint_show_cmdlist);
16159 add_setshow_auto_boolean_cmd ("always-inserted", class_support,
16160 &always_inserted_mode, _("\
16161 Set mode for inserting breakpoints."), _("\
16162 Show mode for inserting breakpoints."), _("\
16163 When this mode is off, breakpoints are inserted in inferior when it is\n\
16164 resumed, and removed when execution stops. When this mode is on,\n\
16165 breakpoints are inserted immediately and removed only when the user\n\
16166 deletes the breakpoint. When this mode is auto (which is the default),\n\
16167 the behaviour depends on the non-stop setting (see help set non-stop).\n\
16168 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
16169 behaves as if always-inserted mode is on; if gdb is controlling the\n\
16170 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
16172 &show_always_inserted_mode,
16173 &breakpoint_set_cmdlist,
16174 &breakpoint_show_cmdlist);
16176 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16177 condition_evaluation_enums,
16178 &condition_evaluation_mode_1, _("\
16179 Set mode of breakpoint condition evaluation."), _("\
16180 Show mode of breakpoint condition evaluation."), _("\
16181 When this is set to \"host\", breakpoint conditions will be\n\
16182 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16183 breakpoint conditions will be downloaded to the target (if the target\n\
16184 supports such feature) and conditions will be evaluated on the target's side.\n\
16185 If this is set to \"auto\" (default), this will be automatically set to\n\
16186 \"target\" if it supports condition evaluation, otherwise it will\n\
16187 be set to \"gdb\""),
16188 &set_condition_evaluation_mode,
16189 &show_condition_evaluation_mode,
16190 &breakpoint_set_cmdlist,
16191 &breakpoint_show_cmdlist);
16193 add_com ("break-range", class_breakpoint, break_range_command, _("\
16194 Set a breakpoint for an address range.\n\
16195 break-range START-LOCATION, END-LOCATION\n\
16196 where START-LOCATION and END-LOCATION can be one of the following:\n\
16197 LINENUM, for that line in the current file,\n\
16198 FILE:LINENUM, for that line in that file,\n\
16199 +OFFSET, for that number of lines after the current line\n\
16200 or the start of the range\n\
16201 FUNCTION, for the first line in that function,\n\
16202 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16203 *ADDRESS, for the instruction at that address.\n\
16205 The breakpoint will stop execution of the inferior whenever it executes\n\
16206 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16207 range (including START-LOCATION and END-LOCATION)."));
16209 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16210 Set a dynamic printf at specified line or function.\n\
16211 dprintf location,format string,arg1,arg2,...\n\
16212 location may be a line number, function name, or \"*\" and an address.\n\
16213 If a line number is specified, break at start of code for that line.\n\
16214 If a function is specified, break at start of code for that function.\n\
16216 set_cmd_completer (c, location_completer);
16218 add_setshow_enum_cmd ("dprintf-style", class_support,
16219 dprintf_style_enums, &dprintf_style, _("\
16220 Set the style of usage for dynamic printf."), _("\
16221 Show the style of usage for dynamic printf."), _("\
16222 This setting chooses how GDB will do a dynamic printf.\n\
16223 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16224 console, as with the \"printf\" command.\n\
16225 If the value is \"call\", the print is done by calling a function in your\n\
16226 program; by default printf(), but you can choose a different function or\n\
16227 output stream by setting dprintf-function and dprintf-channel."),
16228 update_dprintf_commands, NULL,
16229 &setlist, &showlist);
16231 dprintf_function = xstrdup ("printf");
16232 add_setshow_string_cmd ("dprintf-function", class_support,
16233 &dprintf_function, _("\
16234 Set the function to use for dynamic printf"), _("\
16235 Show the function to use for dynamic printf"), NULL,
16236 update_dprintf_commands, NULL,
16237 &setlist, &showlist);
16239 dprintf_channel = xstrdup ("");
16240 add_setshow_string_cmd ("dprintf-channel", class_support,
16241 &dprintf_channel, _("\
16242 Set the channel to use for dynamic printf"), _("\
16243 Show the channel to use for dynamic printf"), NULL,
16244 update_dprintf_commands, NULL,
16245 &setlist, &showlist);
16247 automatic_hardware_breakpoints = 1;
16249 observer_attach_about_to_proceed (breakpoint_about_to_proceed);