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 const char always_inserted_auto[] = "auto";
391 static const char always_inserted_on[] = "on";
392 static const char always_inserted_off[] = "off";
393 static const char *const always_inserted_enums[] = {
394 always_inserted_auto,
399 static const char *always_inserted_mode = always_inserted_auto;
401 show_always_inserted_mode (struct ui_file *file, int from_tty,
402 struct cmd_list_element *c, const char *value)
404 if (always_inserted_mode == always_inserted_auto)
405 fprintf_filtered (file,
406 _("Always inserted breakpoint "
407 "mode is %s (currently %s).\n"),
409 breakpoints_always_inserted_mode () ? "on" : "off");
411 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
416 breakpoints_always_inserted_mode (void)
418 return (always_inserted_mode == always_inserted_on
419 || (always_inserted_mode == always_inserted_auto && non_stop));
422 static const char condition_evaluation_both[] = "host or target";
424 /* Modes for breakpoint condition evaluation. */
425 static const char condition_evaluation_auto[] = "auto";
426 static const char condition_evaluation_host[] = "host";
427 static const char condition_evaluation_target[] = "target";
428 static const char *const condition_evaluation_enums[] = {
429 condition_evaluation_auto,
430 condition_evaluation_host,
431 condition_evaluation_target,
435 /* Global that holds the current mode for breakpoint condition evaluation. */
436 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
438 /* Global that we use to display information to the user (gets its value from
439 condition_evaluation_mode_1. */
440 static const char *condition_evaluation_mode = condition_evaluation_auto;
442 /* Translate a condition evaluation mode MODE into either "host"
443 or "target". This is used mostly to translate from "auto" to the
444 real setting that is being used. It returns the translated
448 translate_condition_evaluation_mode (const char *mode)
450 if (mode == condition_evaluation_auto)
452 if (target_supports_evaluation_of_breakpoint_conditions ())
453 return condition_evaluation_target;
455 return condition_evaluation_host;
461 /* Discovers what condition_evaluation_auto translates to. */
464 breakpoint_condition_evaluation_mode (void)
466 return translate_condition_evaluation_mode (condition_evaluation_mode);
469 /* Return true if GDB should evaluate breakpoint conditions or false
473 gdb_evaluates_breakpoint_condition_p (void)
475 const char *mode = breakpoint_condition_evaluation_mode ();
477 return (mode == condition_evaluation_host);
480 void _initialize_breakpoint (void);
482 /* Are we executing breakpoint commands? */
483 static int executing_breakpoint_commands;
485 /* Are overlay event breakpoints enabled? */
486 static int overlay_events_enabled;
488 /* See description in breakpoint.h. */
489 int target_exact_watchpoints = 0;
491 /* Walk the following statement or block through all breakpoints.
492 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
493 current breakpoint. */
495 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
497 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
498 for (B = breakpoint_chain; \
499 B ? (TMP=B->next, 1): 0; \
502 /* Similar iterator for the low-level breakpoints. SAFE variant is
503 not provided so update_global_location_list must not be called
504 while executing the block of ALL_BP_LOCATIONS. */
506 #define ALL_BP_LOCATIONS(B,BP_TMP) \
507 for (BP_TMP = bp_location; \
508 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
511 /* Iterates through locations with address ADDRESS for the currently selected
512 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
513 to where the loop should start from.
514 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
515 appropriate location to start with. */
517 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
518 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
519 BP_LOCP_TMP = BP_LOCP_START; \
521 && (BP_LOCP_TMP < bp_location + bp_location_count \
522 && (*BP_LOCP_TMP)->address == ADDRESS); \
525 /* Iterator for tracepoints only. */
527 #define ALL_TRACEPOINTS(B) \
528 for (B = breakpoint_chain; B; B = B->next) \
529 if (is_tracepoint (B))
531 /* Chains of all breakpoints defined. */
533 struct breakpoint *breakpoint_chain;
535 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
537 static struct bp_location **bp_location;
539 /* Number of elements of BP_LOCATION. */
541 static unsigned bp_location_count;
543 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
544 ADDRESS for the current elements of BP_LOCATION which get a valid
545 result from bp_location_has_shadow. You can use it for roughly
546 limiting the subrange of BP_LOCATION to scan for shadow bytes for
547 an address you need to read. */
549 static CORE_ADDR bp_location_placed_address_before_address_max;
551 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
552 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
553 BP_LOCATION which get a valid result from bp_location_has_shadow.
554 You can use it for roughly limiting the subrange of BP_LOCATION to
555 scan for shadow bytes for an address you need to read. */
557 static CORE_ADDR bp_location_shadow_len_after_address_max;
559 /* The locations that no longer correspond to any breakpoint, unlinked
560 from bp_location array, but for which a hit may still be reported
562 VEC(bp_location_p) *moribund_locations = NULL;
564 /* Number of last breakpoint made. */
566 static int breakpoint_count;
568 /* The value of `breakpoint_count' before the last command that
569 created breakpoints. If the last (break-like) command created more
570 than one breakpoint, then the difference between BREAKPOINT_COUNT
571 and PREV_BREAKPOINT_COUNT is more than one. */
572 static int prev_breakpoint_count;
574 /* Number of last tracepoint made. */
576 static int tracepoint_count;
578 static struct cmd_list_element *breakpoint_set_cmdlist;
579 static struct cmd_list_element *breakpoint_show_cmdlist;
580 struct cmd_list_element *save_cmdlist;
582 /* Return whether a breakpoint is an active enabled breakpoint. */
584 breakpoint_enabled (struct breakpoint *b)
586 return (b->enable_state == bp_enabled);
589 /* Set breakpoint count to NUM. */
592 set_breakpoint_count (int num)
594 prev_breakpoint_count = breakpoint_count;
595 breakpoint_count = num;
596 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
599 /* Used by `start_rbreak_breakpoints' below, to record the current
600 breakpoint count before "rbreak" creates any breakpoint. */
601 static int rbreak_start_breakpoint_count;
603 /* Called at the start an "rbreak" command to record the first
607 start_rbreak_breakpoints (void)
609 rbreak_start_breakpoint_count = breakpoint_count;
612 /* Called at the end of an "rbreak" command to record the last
616 end_rbreak_breakpoints (void)
618 prev_breakpoint_count = rbreak_start_breakpoint_count;
621 /* Used in run_command to zero the hit count when a new run starts. */
624 clear_breakpoint_hit_counts (void)
626 struct breakpoint *b;
632 /* Allocate a new counted_command_line with reference count of 1.
633 The new structure owns COMMANDS. */
635 static struct counted_command_line *
636 alloc_counted_command_line (struct command_line *commands)
638 struct counted_command_line *result
639 = xmalloc (sizeof (struct counted_command_line));
642 result->commands = commands;
646 /* Increment reference count. This does nothing if CMD is NULL. */
649 incref_counted_command_line (struct counted_command_line *cmd)
655 /* Decrement reference count. If the reference count reaches 0,
656 destroy the counted_command_line. Sets *CMDP to NULL. This does
657 nothing if *CMDP is NULL. */
660 decref_counted_command_line (struct counted_command_line **cmdp)
664 if (--(*cmdp)->refc == 0)
666 free_command_lines (&(*cmdp)->commands);
673 /* A cleanup function that calls decref_counted_command_line. */
676 do_cleanup_counted_command_line (void *arg)
678 decref_counted_command_line (arg);
681 /* Create a cleanup that calls decref_counted_command_line on the
684 static struct cleanup *
685 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
687 return make_cleanup (do_cleanup_counted_command_line, cmdp);
691 /* Return the breakpoint with the specified number, or NULL
692 if the number does not refer to an existing breakpoint. */
695 get_breakpoint (int num)
697 struct breakpoint *b;
700 if (b->number == num)
708 /* Mark locations as "conditions have changed" in case the target supports
709 evaluating conditions on its side. */
712 mark_breakpoint_modified (struct breakpoint *b)
714 struct bp_location *loc;
716 /* This is only meaningful if the target is
717 evaluating conditions and if the user has
718 opted for condition evaluation on the target's
720 if (gdb_evaluates_breakpoint_condition_p ()
721 || !target_supports_evaluation_of_breakpoint_conditions ())
724 if (!is_breakpoint (b))
727 for (loc = b->loc; loc; loc = loc->next)
728 loc->condition_changed = condition_modified;
731 /* Mark location as "conditions have changed" in case the target supports
732 evaluating conditions on its side. */
735 mark_breakpoint_location_modified (struct bp_location *loc)
737 /* This is only meaningful if the target is
738 evaluating conditions and if the user has
739 opted for condition evaluation on the target's
741 if (gdb_evaluates_breakpoint_condition_p ()
742 || !target_supports_evaluation_of_breakpoint_conditions ())
746 if (!is_breakpoint (loc->owner))
749 loc->condition_changed = condition_modified;
752 /* Sets the condition-evaluation mode using the static global
753 condition_evaluation_mode. */
756 set_condition_evaluation_mode (char *args, int from_tty,
757 struct cmd_list_element *c)
759 const char *old_mode, *new_mode;
761 if ((condition_evaluation_mode_1 == condition_evaluation_target)
762 && !target_supports_evaluation_of_breakpoint_conditions ())
764 condition_evaluation_mode_1 = condition_evaluation_mode;
765 warning (_("Target does not support breakpoint condition evaluation.\n"
766 "Using host evaluation mode instead."));
770 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
771 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
773 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
774 settings was "auto". */
775 condition_evaluation_mode = condition_evaluation_mode_1;
777 /* Only update the mode if the user picked a different one. */
778 if (new_mode != old_mode)
780 struct bp_location *loc, **loc_tmp;
781 /* If the user switched to a different evaluation mode, we
782 need to synch the changes with the target as follows:
784 "host" -> "target": Send all (valid) conditions to the target.
785 "target" -> "host": Remove all the conditions from the target.
788 if (new_mode == condition_evaluation_target)
790 /* Mark everything modified and synch conditions with the
792 ALL_BP_LOCATIONS (loc, loc_tmp)
793 mark_breakpoint_location_modified (loc);
797 /* Manually mark non-duplicate locations to synch conditions
798 with the target. We do this to remove all the conditions the
799 target knows about. */
800 ALL_BP_LOCATIONS (loc, loc_tmp)
801 if (is_breakpoint (loc->owner) && loc->inserted)
802 loc->needs_update = 1;
806 update_global_location_list (1);
812 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
813 what "auto" is translating to. */
816 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
817 struct cmd_list_element *c, const char *value)
819 if (condition_evaluation_mode == condition_evaluation_auto)
820 fprintf_filtered (file,
821 _("Breakpoint condition evaluation "
822 "mode is %s (currently %s).\n"),
824 breakpoint_condition_evaluation_mode ());
826 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
830 /* A comparison function for bp_location AP and BP that is used by
831 bsearch. This comparison function only cares about addresses, unlike
832 the more general bp_location_compare function. */
835 bp_location_compare_addrs (const void *ap, const void *bp)
837 struct bp_location *a = *(void **) ap;
838 struct bp_location *b = *(void **) bp;
840 if (a->address == b->address)
843 return ((a->address > b->address) - (a->address < b->address));
846 /* Helper function to skip all bp_locations with addresses
847 less than ADDRESS. It returns the first bp_location that
848 is greater than or equal to ADDRESS. If none is found, just
851 static struct bp_location **
852 get_first_locp_gte_addr (CORE_ADDR address)
854 struct bp_location dummy_loc;
855 struct bp_location *dummy_locp = &dummy_loc;
856 struct bp_location **locp_found = NULL;
858 /* Initialize the dummy location's address field. */
859 memset (&dummy_loc, 0, sizeof (struct bp_location));
860 dummy_loc.address = address;
862 /* Find a close match to the first location at ADDRESS. */
863 locp_found = bsearch (&dummy_locp, bp_location, bp_location_count,
864 sizeof (struct bp_location **),
865 bp_location_compare_addrs);
867 /* Nothing was found, nothing left to do. */
868 if (locp_found == NULL)
871 /* We may have found a location that is at ADDRESS but is not the first in the
872 location's list. Go backwards (if possible) and locate the first one. */
873 while ((locp_found - 1) >= bp_location
874 && (*(locp_found - 1))->address == address)
881 set_breakpoint_condition (struct breakpoint *b, char *exp,
884 xfree (b->cond_string);
885 b->cond_string = NULL;
887 if (is_watchpoint (b))
889 struct watchpoint *w = (struct watchpoint *) b;
896 struct bp_location *loc;
898 for (loc = b->loc; loc; loc = loc->next)
903 /* No need to free the condition agent expression
904 bytecode (if we have one). We will handle this
905 when we go through update_global_location_list. */
912 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
918 /* I don't know if it matters whether this is the string the user
919 typed in or the decompiled expression. */
920 b->cond_string = xstrdup (arg);
921 b->condition_not_parsed = 0;
923 if (is_watchpoint (b))
925 struct watchpoint *w = (struct watchpoint *) b;
927 innermost_block = NULL;
929 w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
931 error (_("Junk at end of expression"));
932 w->cond_exp_valid_block = innermost_block;
936 struct bp_location *loc;
938 for (loc = b->loc; loc; loc = loc->next)
942 parse_exp_1 (&arg, loc->address,
943 block_for_pc (loc->address), 0);
945 error (_("Junk at end of expression"));
949 mark_breakpoint_modified (b);
951 breakpoints_changed ();
952 observer_notify_breakpoint_modified (b);
955 /* Completion for the "condition" command. */
957 static VEC (char_ptr) *
958 condition_completer (struct cmd_list_element *cmd, char *text, char *word)
962 text = skip_spaces (text);
963 space = skip_to_space (text);
967 struct breakpoint *b;
968 VEC (char_ptr) *result = NULL;
972 /* We don't support completion of history indices. */
973 if (isdigit (text[1]))
975 return complete_internalvar (&text[1]);
978 /* We're completing the breakpoint number. */
983 int single = b->loc->next == NULL;
984 struct bp_location *loc;
987 for (loc = b->loc; loc; loc = loc->next)
992 sprintf (location, "%d", b->number);
994 sprintf (location, "%d.%d", b->number, count);
996 if (strncmp (location, text, len) == 0)
997 VEC_safe_push (char_ptr, result, xstrdup (location));
1006 /* We're completing the expression part. */
1007 text = skip_spaces (space);
1008 return expression_completer (cmd, text, word);
1011 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1014 condition_command (char *arg, int from_tty)
1016 struct breakpoint *b;
1021 error_no_arg (_("breakpoint number"));
1024 bnum = get_number (&p);
1026 error (_("Bad breakpoint argument: '%s'"), arg);
1029 if (b->number == bnum)
1031 /* Check if this breakpoint has a Python object assigned to
1032 it, and if it has a definition of the "stop"
1033 method. This method and conditions entered into GDB from
1034 the CLI are mutually exclusive. */
1036 && gdbpy_breakpoint_has_py_cond (b->py_bp_object))
1037 error (_("Cannot set a condition where a Python 'stop' "
1038 "method has been defined in the breakpoint."));
1039 set_breakpoint_condition (b, p, from_tty);
1041 if (is_breakpoint (b))
1042 update_global_location_list (1);
1047 error (_("No breakpoint number %d."), bnum);
1050 /* Check that COMMAND do not contain commands that are suitable
1051 only for tracepoints and not suitable for ordinary breakpoints.
1052 Throw if any such commands is found. */
1055 check_no_tracepoint_commands (struct command_line *commands)
1057 struct command_line *c;
1059 for (c = commands; c; c = c->next)
1063 if (c->control_type == while_stepping_control)
1064 error (_("The 'while-stepping' command can "
1065 "only be used for tracepoints"));
1067 for (i = 0; i < c->body_count; ++i)
1068 check_no_tracepoint_commands ((c->body_list)[i]);
1070 /* Not that command parsing removes leading whitespace and comment
1071 lines and also empty lines. So, we only need to check for
1072 command directly. */
1073 if (strstr (c->line, "collect ") == c->line)
1074 error (_("The 'collect' command can only be used for tracepoints"));
1076 if (strstr (c->line, "teval ") == c->line)
1077 error (_("The 'teval' command can only be used for tracepoints"));
1081 /* Encapsulate tests for different types of tracepoints. */
1084 is_tracepoint_type (enum bptype type)
1086 return (type == bp_tracepoint
1087 || type == bp_fast_tracepoint
1088 || type == bp_static_tracepoint);
1092 is_tracepoint (const struct breakpoint *b)
1094 return is_tracepoint_type (b->type);
1097 /* A helper function that validates that COMMANDS are valid for a
1098 breakpoint. This function will throw an exception if a problem is
1102 validate_commands_for_breakpoint (struct breakpoint *b,
1103 struct command_line *commands)
1105 if (is_tracepoint (b))
1107 /* We need to verify that each top-level element of commands is
1108 valid for tracepoints, that there's at most one
1109 while-stepping element, and that while-stepping's body has
1110 valid tracing commands excluding nested while-stepping. */
1111 struct command_line *c;
1112 struct command_line *while_stepping = 0;
1113 for (c = commands; c; c = c->next)
1115 if (c->control_type == while_stepping_control)
1117 if (b->type == bp_fast_tracepoint)
1118 error (_("The 'while-stepping' command "
1119 "cannot be used for fast tracepoint"));
1120 else if (b->type == bp_static_tracepoint)
1121 error (_("The 'while-stepping' command "
1122 "cannot be used for static tracepoint"));
1125 error (_("The 'while-stepping' command "
1126 "can be used only once"));
1133 struct command_line *c2;
1135 gdb_assert (while_stepping->body_count == 1);
1136 c2 = while_stepping->body_list[0];
1137 for (; c2; c2 = c2->next)
1139 if (c2->control_type == while_stepping_control)
1140 error (_("The 'while-stepping' command cannot be nested"));
1146 check_no_tracepoint_commands (commands);
1150 /* Return a vector of all the static tracepoints set at ADDR. The
1151 caller is responsible for releasing the vector. */
1154 static_tracepoints_here (CORE_ADDR addr)
1156 struct breakpoint *b;
1157 VEC(breakpoint_p) *found = 0;
1158 struct bp_location *loc;
1161 if (b->type == bp_static_tracepoint)
1163 for (loc = b->loc; loc; loc = loc->next)
1164 if (loc->address == addr)
1165 VEC_safe_push(breakpoint_p, found, b);
1171 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1172 validate that only allowed commands are included. */
1175 breakpoint_set_commands (struct breakpoint *b,
1176 struct command_line *commands)
1178 validate_commands_for_breakpoint (b, commands);
1180 decref_counted_command_line (&b->commands);
1181 b->commands = alloc_counted_command_line (commands);
1182 breakpoints_changed ();
1183 observer_notify_breakpoint_modified (b);
1186 /* Set the internal `silent' flag on the breakpoint. Note that this
1187 is not the same as the "silent" that may appear in the breakpoint's
1191 breakpoint_set_silent (struct breakpoint *b, int silent)
1193 int old_silent = b->silent;
1196 if (old_silent != silent)
1197 observer_notify_breakpoint_modified (b);
1200 /* Set the thread for this breakpoint. If THREAD is -1, make the
1201 breakpoint work for any thread. */
1204 breakpoint_set_thread (struct breakpoint *b, int thread)
1206 int old_thread = b->thread;
1209 if (old_thread != thread)
1210 observer_notify_breakpoint_modified (b);
1213 /* Set the task for this breakpoint. If TASK is 0, make the
1214 breakpoint work for any task. */
1217 breakpoint_set_task (struct breakpoint *b, int task)
1219 int old_task = b->task;
1222 if (old_task != task)
1223 observer_notify_breakpoint_modified (b);
1227 check_tracepoint_command (char *line, void *closure)
1229 struct breakpoint *b = closure;
1231 validate_actionline (&line, b);
1234 /* A structure used to pass information through
1235 map_breakpoint_numbers. */
1237 struct commands_info
1239 /* True if the command was typed at a tty. */
1242 /* The breakpoint range spec. */
1245 /* Non-NULL if the body of the commands are being read from this
1246 already-parsed command. */
1247 struct command_line *control;
1249 /* The command lines read from the user, or NULL if they have not
1251 struct counted_command_line *cmd;
1254 /* A callback for map_breakpoint_numbers that sets the commands for
1255 commands_command. */
1258 do_map_commands_command (struct breakpoint *b, void *data)
1260 struct commands_info *info = data;
1262 if (info->cmd == NULL)
1264 struct command_line *l;
1266 if (info->control != NULL)
1267 l = copy_command_lines (info->control->body_list[0]);
1270 struct cleanup *old_chain;
1273 str = xstrprintf (_("Type commands for breakpoint(s) "
1274 "%s, one per line."),
1277 old_chain = make_cleanup (xfree, str);
1279 l = read_command_lines (str,
1282 ? check_tracepoint_command : 0),
1285 do_cleanups (old_chain);
1288 info->cmd = alloc_counted_command_line (l);
1291 /* If a breakpoint was on the list more than once, we don't need to
1293 if (b->commands != info->cmd)
1295 validate_commands_for_breakpoint (b, info->cmd->commands);
1296 incref_counted_command_line (info->cmd);
1297 decref_counted_command_line (&b->commands);
1298 b->commands = info->cmd;
1299 breakpoints_changed ();
1300 observer_notify_breakpoint_modified (b);
1305 commands_command_1 (char *arg, int from_tty,
1306 struct command_line *control)
1308 struct cleanup *cleanups;
1309 struct commands_info info;
1311 info.from_tty = from_tty;
1312 info.control = control;
1314 /* If we read command lines from the user, then `info' will hold an
1315 extra reference to the commands that we must clean up. */
1316 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1318 if (arg == NULL || !*arg)
1320 if (breakpoint_count - prev_breakpoint_count > 1)
1321 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1323 else if (breakpoint_count > 0)
1324 arg = xstrprintf ("%d", breakpoint_count);
1327 /* So that we don't try to free the incoming non-NULL
1328 argument in the cleanup below. Mapping breakpoint
1329 numbers will fail in this case. */
1334 /* The command loop has some static state, so we need to preserve
1336 arg = xstrdup (arg);
1339 make_cleanup (xfree, arg);
1343 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1345 if (info.cmd == NULL)
1346 error (_("No breakpoints specified."));
1348 do_cleanups (cleanups);
1352 commands_command (char *arg, int from_tty)
1354 commands_command_1 (arg, from_tty, NULL);
1357 /* Like commands_command, but instead of reading the commands from
1358 input stream, takes them from an already parsed command structure.
1360 This is used by cli-script.c to DTRT with breakpoint commands
1361 that are part of if and while bodies. */
1362 enum command_control_type
1363 commands_from_control_command (char *arg, struct command_line *cmd)
1365 commands_command_1 (arg, 0, cmd);
1366 return simple_control;
1369 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1372 bp_location_has_shadow (struct bp_location *bl)
1374 if (bl->loc_type != bp_loc_software_breakpoint)
1378 if (bl->target_info.shadow_len == 0)
1379 /* BL isn't valid, or doesn't shadow memory. */
1384 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1385 by replacing any memory breakpoints with their shadowed contents.
1387 If READBUF is not NULL, this buffer must not overlap with any of
1388 the breakpoint location's shadow_contents buffers. Otherwise,
1389 a failed assertion internal error will be raised.
1391 The range of shadowed area by each bp_location is:
1392 bl->address - bp_location_placed_address_before_address_max
1393 up to bl->address + bp_location_shadow_len_after_address_max
1394 The range we were requested to resolve shadows for is:
1395 memaddr ... memaddr + len
1396 Thus the safe cutoff boundaries for performance optimization are
1397 memaddr + len <= (bl->address
1398 - bp_location_placed_address_before_address_max)
1400 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1403 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1404 const gdb_byte *writebuf_org,
1405 ULONGEST memaddr, LONGEST len)
1407 /* Left boundary, right boundary and median element of our binary
1409 unsigned bc_l, bc_r, bc;
1411 /* Find BC_L which is a leftmost element which may affect BUF
1412 content. It is safe to report lower value but a failure to
1413 report higher one. */
1416 bc_r = bp_location_count;
1417 while (bc_l + 1 < bc_r)
1419 struct bp_location *bl;
1421 bc = (bc_l + bc_r) / 2;
1422 bl = bp_location[bc];
1424 /* Check first BL->ADDRESS will not overflow due to the added
1425 constant. Then advance the left boundary only if we are sure
1426 the BC element can in no way affect the BUF content (MEMADDR
1427 to MEMADDR + LEN range).
1429 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1430 offset so that we cannot miss a breakpoint with its shadow
1431 range tail still reaching MEMADDR. */
1433 if ((bl->address + bp_location_shadow_len_after_address_max
1435 && (bl->address + bp_location_shadow_len_after_address_max
1442 /* Due to the binary search above, we need to make sure we pick the
1443 first location that's at BC_L's address. E.g., if there are
1444 multiple locations at the same address, BC_L may end up pointing
1445 at a duplicate location, and miss the "master"/"inserted"
1446 location. Say, given locations L1, L2 and L3 at addresses A and
1449 L1@A, L2@A, L3@B, ...
1451 BC_L could end up pointing at location L2, while the "master"
1452 location could be L1. Since the `loc->inserted' flag is only set
1453 on "master" locations, we'd forget to restore the shadow of L1
1456 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1459 /* Now do full processing of the found relevant range of elements. */
1461 for (bc = bc_l; bc < bp_location_count; bc++)
1463 struct bp_location *bl = bp_location[bc];
1464 CORE_ADDR bp_addr = 0;
1468 /* bp_location array has BL->OWNER always non-NULL. */
1469 if (bl->owner->type == bp_none)
1470 warning (_("reading through apparently deleted breakpoint #%d?"),
1473 /* Performance optimization: any further element can no longer affect BUF
1476 if (bl->address >= bp_location_placed_address_before_address_max
1477 && memaddr + len <= (bl->address
1478 - bp_location_placed_address_before_address_max))
1481 if (!bp_location_has_shadow (bl))
1483 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0,
1484 current_program_space->aspace, 0))
1487 /* Addresses and length of the part of the breakpoint that
1489 bp_addr = bl->target_info.placed_address;
1490 bp_size = bl->target_info.shadow_len;
1492 if (bp_addr + bp_size <= memaddr)
1493 /* The breakpoint is entirely before the chunk of memory we
1497 if (bp_addr >= memaddr + len)
1498 /* The breakpoint is entirely after the chunk of memory we are
1502 /* Offset within shadow_contents. */
1503 if (bp_addr < memaddr)
1505 /* Only copy the second part of the breakpoint. */
1506 bp_size -= memaddr - bp_addr;
1507 bptoffset = memaddr - bp_addr;
1511 if (bp_addr + bp_size > memaddr + len)
1513 /* Only copy the first part of the breakpoint. */
1514 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1517 if (readbuf != NULL)
1519 /* Verify that the readbuf buffer does not overlap with
1520 the shadow_contents buffer. */
1521 gdb_assert (bl->target_info.shadow_contents >= readbuf + len
1522 || readbuf >= (bl->target_info.shadow_contents
1523 + bl->target_info.shadow_len));
1525 /* Update the read buffer with this inserted breakpoint's
1527 memcpy (readbuf + bp_addr - memaddr,
1528 bl->target_info.shadow_contents + bptoffset, bp_size);
1532 struct gdbarch *gdbarch = bl->gdbarch;
1533 const unsigned char *bp;
1534 CORE_ADDR placed_address = bl->target_info.placed_address;
1535 unsigned placed_size = bl->target_info.placed_size;
1537 /* Update the shadow with what we want to write to memory. */
1538 memcpy (bl->target_info.shadow_contents + bptoffset,
1539 writebuf_org + bp_addr - memaddr, bp_size);
1541 /* Determine appropriate breakpoint contents and size for this
1543 bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size);
1545 /* Update the final write buffer with this inserted
1546 breakpoint's INSN. */
1547 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1553 /* Return true if BPT is either a software breakpoint or a hardware
1557 is_breakpoint (const struct breakpoint *bpt)
1559 return (bpt->type == bp_breakpoint
1560 || bpt->type == bp_hardware_breakpoint
1561 || bpt->type == bp_dprintf);
1564 /* Return true if BPT is of any hardware watchpoint kind. */
1567 is_hardware_watchpoint (const struct breakpoint *bpt)
1569 return (bpt->type == bp_hardware_watchpoint
1570 || bpt->type == bp_read_watchpoint
1571 || bpt->type == bp_access_watchpoint);
1574 /* Return true if BPT is of any watchpoint kind, hardware or
1578 is_watchpoint (const struct breakpoint *bpt)
1580 return (is_hardware_watchpoint (bpt)
1581 || bpt->type == bp_watchpoint);
1584 /* Returns true if the current thread and its running state are safe
1585 to evaluate or update watchpoint B. Watchpoints on local
1586 expressions need to be evaluated in the context of the thread that
1587 was current when the watchpoint was created, and, that thread needs
1588 to be stopped to be able to select the correct frame context.
1589 Watchpoints on global expressions can be evaluated on any thread,
1590 and in any state. It is presently left to the target allowing
1591 memory accesses when threads are running. */
1594 watchpoint_in_thread_scope (struct watchpoint *b)
1596 return (b->base.pspace == current_program_space
1597 && (ptid_equal (b->watchpoint_thread, null_ptid)
1598 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1599 && !is_executing (inferior_ptid))));
1602 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1603 associated bp_watchpoint_scope breakpoint. */
1606 watchpoint_del_at_next_stop (struct watchpoint *w)
1608 struct breakpoint *b = &w->base;
1610 if (b->related_breakpoint != b)
1612 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1613 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1614 b->related_breakpoint->disposition = disp_del_at_next_stop;
1615 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1616 b->related_breakpoint = b;
1618 b->disposition = disp_del_at_next_stop;
1621 /* Assuming that B is a watchpoint:
1622 - Reparse watchpoint expression, if REPARSE is non-zero
1623 - Evaluate expression and store the result in B->val
1624 - Evaluate the condition if there is one, and store the result
1626 - Update the list of values that must be watched in B->loc.
1628 If the watchpoint disposition is disp_del_at_next_stop, then do
1629 nothing. If this is local watchpoint that is out of scope, delete
1632 Even with `set breakpoint always-inserted on' the watchpoints are
1633 removed + inserted on each stop here. Normal breakpoints must
1634 never be removed because they might be missed by a running thread
1635 when debugging in non-stop mode. On the other hand, hardware
1636 watchpoints (is_hardware_watchpoint; processed here) are specific
1637 to each LWP since they are stored in each LWP's hardware debug
1638 registers. Therefore, such LWP must be stopped first in order to
1639 be able to modify its hardware watchpoints.
1641 Hardware watchpoints must be reset exactly once after being
1642 presented to the user. It cannot be done sooner, because it would
1643 reset the data used to present the watchpoint hit to the user. And
1644 it must not be done later because it could display the same single
1645 watchpoint hit during multiple GDB stops. Note that the latter is
1646 relevant only to the hardware watchpoint types bp_read_watchpoint
1647 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1648 not user-visible - its hit is suppressed if the memory content has
1651 The following constraints influence the location where we can reset
1652 hardware watchpoints:
1654 * target_stopped_by_watchpoint and target_stopped_data_address are
1655 called several times when GDB stops.
1658 * Multiple hardware watchpoints can be hit at the same time,
1659 causing GDB to stop. GDB only presents one hardware watchpoint
1660 hit at a time as the reason for stopping, and all the other hits
1661 are presented later, one after the other, each time the user
1662 requests the execution to be resumed. Execution is not resumed
1663 for the threads still having pending hit event stored in
1664 LWP_INFO->STATUS. While the watchpoint is already removed from
1665 the inferior on the first stop the thread hit event is kept being
1666 reported from its cached value by linux_nat_stopped_data_address
1667 until the real thread resume happens after the watchpoint gets
1668 presented and thus its LWP_INFO->STATUS gets reset.
1670 Therefore the hardware watchpoint hit can get safely reset on the
1671 watchpoint removal from inferior. */
1674 update_watchpoint (struct watchpoint *b, int reparse)
1676 int within_current_scope;
1677 struct frame_id saved_frame_id;
1680 /* If this is a local watchpoint, we only want to check if the
1681 watchpoint frame is in scope if the current thread is the thread
1682 that was used to create the watchpoint. */
1683 if (!watchpoint_in_thread_scope (b))
1686 if (b->base.disposition == disp_del_at_next_stop)
1691 /* Determine if the watchpoint is within scope. */
1692 if (b->exp_valid_block == NULL)
1693 within_current_scope = 1;
1696 struct frame_info *fi = get_current_frame ();
1697 struct gdbarch *frame_arch = get_frame_arch (fi);
1698 CORE_ADDR frame_pc = get_frame_pc (fi);
1700 /* If we're in a function epilogue, unwinding may not work
1701 properly, so do not attempt to recreate locations at this
1702 point. See similar comments in watchpoint_check. */
1703 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1706 /* Save the current frame's ID so we can restore it after
1707 evaluating the watchpoint expression on its own frame. */
1708 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1709 took a frame parameter, so that we didn't have to change the
1712 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1714 fi = frame_find_by_id (b->watchpoint_frame);
1715 within_current_scope = (fi != NULL);
1716 if (within_current_scope)
1720 /* We don't free locations. They are stored in the bp_location array
1721 and update_global_location_list will eventually delete them and
1722 remove breakpoints if needed. */
1725 if (within_current_scope && reparse)
1734 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1735 b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
1736 /* If the meaning of expression itself changed, the old value is
1737 no longer relevant. We don't want to report a watchpoint hit
1738 to the user when the old value and the new value may actually
1739 be completely different objects. */
1740 value_free (b->val);
1744 /* Note that unlike with breakpoints, the watchpoint's condition
1745 expression is stored in the breakpoint object, not in the
1746 locations (re)created below. */
1747 if (b->base.cond_string != NULL)
1749 if (b->cond_exp != NULL)
1751 xfree (b->cond_exp);
1755 s = b->base.cond_string;
1756 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1760 /* If we failed to parse the expression, for example because
1761 it refers to a global variable in a not-yet-loaded shared library,
1762 don't try to insert watchpoint. We don't automatically delete
1763 such watchpoint, though, since failure to parse expression
1764 is different from out-of-scope watchpoint. */
1765 if ( !target_has_execution)
1767 /* Without execution, memory can't change. No use to try and
1768 set watchpoint locations. The watchpoint will be reset when
1769 the target gains execution, through breakpoint_re_set. */
1771 else if (within_current_scope && b->exp)
1774 struct value *val_chain, *v, *result, *next;
1775 struct program_space *frame_pspace;
1777 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain);
1779 /* Avoid setting b->val if it's already set. The meaning of
1780 b->val is 'the last value' user saw, and we should update
1781 it only if we reported that last value to user. As it
1782 happens, the code that reports it updates b->val directly.
1783 We don't keep track of the memory value for masked
1785 if (!b->val_valid && !is_masked_watchpoint (&b->base))
1791 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1793 /* Look at each value on the value chain. */
1794 for (v = val_chain; v; v = value_next (v))
1796 /* If it's a memory location, and GDB actually needed
1797 its contents to evaluate the expression, then we
1798 must watch it. If the first value returned is
1799 still lazy, that means an error occurred reading it;
1800 watch it anyway in case it becomes readable. */
1801 if (VALUE_LVAL (v) == lval_memory
1802 && (v == val_chain || ! value_lazy (v)))
1804 struct type *vtype = check_typedef (value_type (v));
1806 /* We only watch structs and arrays if user asked
1807 for it explicitly, never if they just happen to
1808 appear in the middle of some value chain. */
1810 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1811 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1815 struct bp_location *loc, **tmp;
1817 addr = value_address (v);
1818 len = TYPE_LENGTH (value_type (v));
1820 if (b->base.type == bp_read_watchpoint)
1822 else if (b->base.type == bp_access_watchpoint)
1825 loc = allocate_bp_location (&b->base);
1826 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
1829 loc->gdbarch = get_type_arch (value_type (v));
1831 loc->pspace = frame_pspace;
1832 loc->address = addr;
1834 loc->watchpoint_type = type;
1839 /* Change the type of breakpoint between hardware assisted or
1840 an ordinary watchpoint depending on the hardware support
1841 and free hardware slots. REPARSE is set when the inferior
1846 enum bp_loc_type loc_type;
1847 struct bp_location *bl;
1849 reg_cnt = can_use_hardware_watchpoint (val_chain);
1853 int i, target_resources_ok, other_type_used;
1856 /* Use an exact watchpoint when there's only one memory region to be
1857 watched, and only one debug register is needed to watch it. */
1858 b->exact = target_exact_watchpoints && reg_cnt == 1;
1860 /* We need to determine how many resources are already
1861 used for all other hardware watchpoints plus this one
1862 to see if we still have enough resources to also fit
1863 this watchpoint in as well. */
1865 /* If this is a software watchpoint, we try to turn it
1866 to a hardware one -- count resources as if B was of
1867 hardware watchpoint type. */
1868 type = b->base.type;
1869 if (type == bp_watchpoint)
1870 type = bp_hardware_watchpoint;
1872 /* This watchpoint may or may not have been placed on
1873 the list yet at this point (it won't be in the list
1874 if we're trying to create it for the first time,
1875 through watch_command), so always account for it
1878 /* Count resources used by all watchpoints except B. */
1879 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
1881 /* Add in the resources needed for B. */
1882 i += hw_watchpoint_use_count (&b->base);
1885 = target_can_use_hardware_watchpoint (type, i, other_type_used);
1886 if (target_resources_ok <= 0)
1888 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
1890 if (target_resources_ok == 0 && !sw_mode)
1891 error (_("Target does not support this type of "
1892 "hardware watchpoint."));
1893 else if (target_resources_ok < 0 && !sw_mode)
1894 error (_("There are not enough available hardware "
1895 "resources for this watchpoint."));
1897 /* Downgrade to software watchpoint. */
1898 b->base.type = bp_watchpoint;
1902 /* If this was a software watchpoint, we've just
1903 found we have enough resources to turn it to a
1904 hardware watchpoint. Otherwise, this is a
1906 b->base.type = type;
1909 else if (!b->base.ops->works_in_software_mode (&b->base))
1910 error (_("Expression cannot be implemented with "
1911 "read/access watchpoint."));
1913 b->base.type = bp_watchpoint;
1915 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
1916 : bp_loc_hardware_watchpoint);
1917 for (bl = b->base.loc; bl; bl = bl->next)
1918 bl->loc_type = loc_type;
1921 for (v = val_chain; v; v = next)
1923 next = value_next (v);
1928 /* If a software watchpoint is not watching any memory, then the
1929 above left it without any location set up. But,
1930 bpstat_stop_status requires a location to be able to report
1931 stops, so make sure there's at least a dummy one. */
1932 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
1934 struct breakpoint *base = &b->base;
1935 base->loc = allocate_bp_location (base);
1936 base->loc->pspace = frame_pspace;
1937 base->loc->address = -1;
1938 base->loc->length = -1;
1939 base->loc->watchpoint_type = -1;
1942 else if (!within_current_scope)
1944 printf_filtered (_("\
1945 Watchpoint %d deleted because the program has left the block\n\
1946 in which its expression is valid.\n"),
1948 watchpoint_del_at_next_stop (b);
1951 /* Restore the selected frame. */
1953 select_frame (frame_find_by_id (saved_frame_id));
1957 /* Returns 1 iff breakpoint location should be
1958 inserted in the inferior. We don't differentiate the type of BL's owner
1959 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1960 breakpoint_ops is not defined, because in insert_bp_location,
1961 tracepoint's insert_location will not be called. */
1963 should_be_inserted (struct bp_location *bl)
1965 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
1968 if (bl->owner->disposition == disp_del_at_next_stop)
1971 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
1974 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
1977 /* This is set for example, when we're attached to the parent of a
1978 vfork, and have detached from the child. The child is running
1979 free, and we expect it to do an exec or exit, at which point the
1980 OS makes the parent schedulable again (and the target reports
1981 that the vfork is done). Until the child is done with the shared
1982 memory region, do not insert breakpoints in the parent, otherwise
1983 the child could still trip on the parent's breakpoints. Since
1984 the parent is blocked anyway, it won't miss any breakpoint. */
1985 if (bl->pspace->breakpoints_not_allowed)
1991 /* Same as should_be_inserted but does the check assuming
1992 that the location is not duplicated. */
1995 unduplicated_should_be_inserted (struct bp_location *bl)
1998 const int save_duplicate = bl->duplicate;
2001 result = should_be_inserted (bl);
2002 bl->duplicate = save_duplicate;
2006 /* Parses a conditional described by an expression COND into an
2007 agent expression bytecode suitable for evaluation
2008 by the bytecode interpreter. Return NULL if there was
2009 any error during parsing. */
2011 static struct agent_expr *
2012 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2014 struct agent_expr *aexpr = NULL;
2015 struct cleanup *old_chain = NULL;
2016 volatile struct gdb_exception ex;
2021 /* We don't want to stop processing, so catch any errors
2022 that may show up. */
2023 TRY_CATCH (ex, RETURN_MASK_ERROR)
2025 aexpr = gen_eval_for_expr (scope, cond);
2030 /* If we got here, it means the condition could not be parsed to a valid
2031 bytecode expression and thus can't be evaluated on the target's side.
2032 It's no use iterating through the conditions. */
2036 /* We have a valid agent expression. */
2040 /* Based on location BL, create a list of breakpoint conditions to be
2041 passed on to the target. If we have duplicated locations with different
2042 conditions, we will add such conditions to the list. The idea is that the
2043 target will evaluate the list of conditions and will only notify GDB when
2044 one of them is true. */
2047 build_target_condition_list (struct bp_location *bl)
2049 struct bp_location **locp = NULL, **loc2p;
2050 int null_condition_or_parse_error = 0;
2051 int modified = bl->needs_update;
2052 struct bp_location *loc;
2054 /* This is only meaningful if the target is
2055 evaluating conditions and if the user has
2056 opted for condition evaluation on the target's
2058 if (gdb_evaluates_breakpoint_condition_p ()
2059 || !target_supports_evaluation_of_breakpoint_conditions ())
2062 /* Do a first pass to check for locations with no assigned
2063 conditions or conditions that fail to parse to a valid agent expression
2064 bytecode. If any of these happen, then it's no use to send conditions
2065 to the target since this location will always trigger and generate a
2066 response back to GDB. */
2067 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2070 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2074 struct agent_expr *aexpr;
2076 /* Re-parse the conditions since something changed. In that
2077 case we already freed the condition bytecodes (see
2078 force_breakpoint_reinsertion). We just
2079 need to parse the condition to bytecodes again. */
2080 aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2081 loc->cond_bytecode = aexpr;
2083 /* Check if we managed to parse the conditional expression
2084 correctly. If not, we will not send this condition
2090 /* If we have a NULL bytecode expression, it means something
2091 went wrong or we have a null condition expression. */
2092 if (!loc->cond_bytecode)
2094 null_condition_or_parse_error = 1;
2100 /* If any of these happened, it means we will have to evaluate the conditions
2101 for the location's address on gdb's side. It is no use keeping bytecodes
2102 for all the other duplicate locations, thus we free all of them here.
2104 This is so we have a finer control over which locations' conditions are
2105 being evaluated by GDB or the remote stub. */
2106 if (null_condition_or_parse_error)
2108 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2111 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2113 /* Only go as far as the first NULL bytecode is
2115 if (!loc->cond_bytecode)
2118 free_agent_expr (loc->cond_bytecode);
2119 loc->cond_bytecode = NULL;
2124 /* No NULL conditions or failed bytecode generation. Build a condition list
2125 for this location's address. */
2126 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2130 && is_breakpoint (loc->owner)
2131 && loc->pspace->num == bl->pspace->num
2132 && loc->owner->enable_state == bp_enabled
2134 /* Add the condition to the vector. This will be used later to send the
2135 conditions to the target. */
2136 VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2137 loc->cond_bytecode);
2143 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2144 location. Any error messages are printed to TMP_ERROR_STREAM; and
2145 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2146 Returns 0 for success, 1 if the bp_location type is not supported or
2149 NOTE drow/2003-09-09: This routine could be broken down to an
2150 object-style method for each breakpoint or catchpoint type. */
2152 insert_bp_location (struct bp_location *bl,
2153 struct ui_file *tmp_error_stream,
2154 int *disabled_breaks,
2155 int *hw_breakpoint_error)
2159 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2162 /* Note we don't initialize bl->target_info, as that wipes out
2163 the breakpoint location's shadow_contents if the breakpoint
2164 is still inserted at that location. This in turn breaks
2165 target_read_memory which depends on these buffers when
2166 a memory read is requested at the breakpoint location:
2167 Once the target_info has been wiped, we fail to see that
2168 we have a breakpoint inserted at that address and thus
2169 read the breakpoint instead of returning the data saved in
2170 the breakpoint location's shadow contents. */
2171 bl->target_info.placed_address = bl->address;
2172 bl->target_info.placed_address_space = bl->pspace->aspace;
2173 bl->target_info.length = bl->length;
2175 /* When working with target-side conditions, we must pass all the conditions
2176 for the same breakpoint address down to the target since GDB will not
2177 insert those locations. With a list of breakpoint conditions, the target
2178 can decide when to stop and notify GDB. */
2180 if (is_breakpoint (bl->owner))
2182 build_target_condition_list (bl);
2183 /* Reset the condition modification marker. */
2184 bl->needs_update = 0;
2187 if (bl->loc_type == bp_loc_software_breakpoint
2188 || bl->loc_type == bp_loc_hardware_breakpoint)
2190 if (bl->owner->type != bp_hardware_breakpoint)
2192 /* If the explicitly specified breakpoint type
2193 is not hardware breakpoint, check the memory map to see
2194 if the breakpoint address is in read only memory or not.
2196 Two important cases are:
2197 - location type is not hardware breakpoint, memory
2198 is readonly. We change the type of the location to
2199 hardware breakpoint.
2200 - location type is hardware breakpoint, memory is
2201 read-write. This means we've previously made the
2202 location hardware one, but then the memory map changed,
2205 When breakpoints are removed, remove_breakpoints will use
2206 location types we've just set here, the only possible
2207 problem is that memory map has changed during running
2208 program, but it's not going to work anyway with current
2210 struct mem_region *mr
2211 = lookup_mem_region (bl->target_info.placed_address);
2215 if (automatic_hardware_breakpoints)
2217 enum bp_loc_type new_type;
2219 if (mr->attrib.mode != MEM_RW)
2220 new_type = bp_loc_hardware_breakpoint;
2222 new_type = bp_loc_software_breakpoint;
2224 if (new_type != bl->loc_type)
2226 static int said = 0;
2228 bl->loc_type = new_type;
2231 fprintf_filtered (gdb_stdout,
2232 _("Note: automatically using "
2233 "hardware breakpoints for "
2234 "read-only addresses.\n"));
2239 else if (bl->loc_type == bp_loc_software_breakpoint
2240 && mr->attrib.mode != MEM_RW)
2241 warning (_("cannot set software breakpoint "
2242 "at readonly address %s"),
2243 paddress (bl->gdbarch, bl->address));
2247 /* First check to see if we have to handle an overlay. */
2248 if (overlay_debugging == ovly_off
2249 || bl->section == NULL
2250 || !(section_is_overlay (bl->section)))
2252 /* No overlay handling: just set the breakpoint. */
2254 val = bl->owner->ops->insert_location (bl);
2258 /* This breakpoint is in an overlay section.
2259 Shall we set a breakpoint at the LMA? */
2260 if (!overlay_events_enabled)
2262 /* Yes -- overlay event support is not active,
2263 so we must try to set a breakpoint at the LMA.
2264 This will not work for a hardware breakpoint. */
2265 if (bl->loc_type == bp_loc_hardware_breakpoint)
2266 warning (_("hardware breakpoint %d not supported in overlay!"),
2270 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2272 /* Set a software (trap) breakpoint at the LMA. */
2273 bl->overlay_target_info = bl->target_info;
2274 bl->overlay_target_info.placed_address = addr;
2275 val = target_insert_breakpoint (bl->gdbarch,
2276 &bl->overlay_target_info);
2278 fprintf_unfiltered (tmp_error_stream,
2279 "Overlay breakpoint %d "
2280 "failed: in ROM?\n",
2284 /* Shall we set a breakpoint at the VMA? */
2285 if (section_is_mapped (bl->section))
2287 /* Yes. This overlay section is mapped into memory. */
2288 val = bl->owner->ops->insert_location (bl);
2292 /* No. This breakpoint will not be inserted.
2293 No error, but do not mark the bp as 'inserted'. */
2300 /* Can't set the breakpoint. */
2301 if (solib_name_from_address (bl->pspace, bl->address))
2303 /* See also: disable_breakpoints_in_shlibs. */
2305 bl->shlib_disabled = 1;
2306 observer_notify_breakpoint_modified (bl->owner);
2307 if (!*disabled_breaks)
2309 fprintf_unfiltered (tmp_error_stream,
2310 "Cannot insert breakpoint %d.\n",
2312 fprintf_unfiltered (tmp_error_stream,
2313 "Temporarily disabling shared "
2314 "library breakpoints:\n");
2316 *disabled_breaks = 1;
2317 fprintf_unfiltered (tmp_error_stream,
2318 "breakpoint #%d\n", bl->owner->number);
2322 if (bl->loc_type == bp_loc_hardware_breakpoint)
2324 *hw_breakpoint_error = 1;
2325 fprintf_unfiltered (tmp_error_stream,
2326 "Cannot insert hardware "
2332 fprintf_unfiltered (tmp_error_stream,
2333 "Cannot insert breakpoint %d.\n",
2335 fprintf_filtered (tmp_error_stream,
2336 "Error accessing memory address ");
2337 fputs_filtered (paddress (bl->gdbarch, bl->address),
2339 fprintf_filtered (tmp_error_stream, ": %s.\n",
2340 safe_strerror (val));
2351 else if (bl->loc_type == bp_loc_hardware_watchpoint
2352 /* NOTE drow/2003-09-08: This state only exists for removing
2353 watchpoints. It's not clear that it's necessary... */
2354 && bl->owner->disposition != disp_del_at_next_stop)
2356 gdb_assert (bl->owner->ops != NULL
2357 && bl->owner->ops->insert_location != NULL);
2359 val = bl->owner->ops->insert_location (bl);
2361 /* If trying to set a read-watchpoint, and it turns out it's not
2362 supported, try emulating one with an access watchpoint. */
2363 if (val == 1 && bl->watchpoint_type == hw_read)
2365 struct bp_location *loc, **loc_temp;
2367 /* But don't try to insert it, if there's already another
2368 hw_access location that would be considered a duplicate
2370 ALL_BP_LOCATIONS (loc, loc_temp)
2372 && loc->watchpoint_type == hw_access
2373 && watchpoint_locations_match (bl, loc))
2377 bl->target_info = loc->target_info;
2378 bl->watchpoint_type = hw_access;
2385 bl->watchpoint_type = hw_access;
2386 val = bl->owner->ops->insert_location (bl);
2389 /* Back to the original value. */
2390 bl->watchpoint_type = hw_read;
2394 bl->inserted = (val == 0);
2397 else if (bl->owner->type == bp_catchpoint)
2399 gdb_assert (bl->owner->ops != NULL
2400 && bl->owner->ops->insert_location != NULL);
2402 val = bl->owner->ops->insert_location (bl);
2405 bl->owner->enable_state = bp_disabled;
2409 Error inserting catchpoint %d: Your system does not support this type\n\
2410 of catchpoint."), bl->owner->number);
2412 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2415 bl->inserted = (val == 0);
2417 /* We've already printed an error message if there was a problem
2418 inserting this catchpoint, and we've disabled the catchpoint,
2419 so just return success. */
2426 /* This function is called when program space PSPACE is about to be
2427 deleted. It takes care of updating breakpoints to not reference
2431 breakpoint_program_space_exit (struct program_space *pspace)
2433 struct breakpoint *b, *b_temp;
2434 struct bp_location *loc, **loc_temp;
2436 /* Remove any breakpoint that was set through this program space. */
2437 ALL_BREAKPOINTS_SAFE (b, b_temp)
2439 if (b->pspace == pspace)
2440 delete_breakpoint (b);
2443 /* Breakpoints set through other program spaces could have locations
2444 bound to PSPACE as well. Remove those. */
2445 ALL_BP_LOCATIONS (loc, loc_temp)
2447 struct bp_location *tmp;
2449 if (loc->pspace == pspace)
2451 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2452 if (loc->owner->loc == loc)
2453 loc->owner->loc = loc->next;
2455 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2456 if (tmp->next == loc)
2458 tmp->next = loc->next;
2464 /* Now update the global location list to permanently delete the
2465 removed locations above. */
2466 update_global_location_list (0);
2469 /* Make sure all breakpoints are inserted in inferior.
2470 Throws exception on any error.
2471 A breakpoint that is already inserted won't be inserted
2472 again, so calling this function twice is safe. */
2474 insert_breakpoints (void)
2476 struct breakpoint *bpt;
2478 ALL_BREAKPOINTS (bpt)
2479 if (is_hardware_watchpoint (bpt))
2481 struct watchpoint *w = (struct watchpoint *) bpt;
2483 update_watchpoint (w, 0 /* don't reparse. */);
2486 update_global_location_list (1);
2488 /* update_global_location_list does not insert breakpoints when
2489 always_inserted_mode is not enabled. Explicitly insert them
2491 if (!breakpoints_always_inserted_mode ())
2492 insert_breakpoint_locations ();
2495 /* Invoke CALLBACK for each of bp_location. */
2498 iterate_over_bp_locations (walk_bp_location_callback callback)
2500 struct bp_location *loc, **loc_tmp;
2502 ALL_BP_LOCATIONS (loc, loc_tmp)
2504 callback (loc, NULL);
2508 /* This is used when we need to synch breakpoint conditions between GDB and the
2509 target. It is the case with deleting and disabling of breakpoints when using
2510 always-inserted mode. */
2513 update_inserted_breakpoint_locations (void)
2515 struct bp_location *bl, **blp_tmp;
2518 int disabled_breaks = 0;
2519 int hw_breakpoint_error = 0;
2521 struct ui_file *tmp_error_stream = mem_fileopen ();
2522 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2524 /* Explicitly mark the warning -- this will only be printed if
2525 there was an error. */
2526 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2528 save_current_space_and_thread ();
2530 ALL_BP_LOCATIONS (bl, blp_tmp)
2532 /* We only want to update software breakpoints and hardware
2534 if (!is_breakpoint (bl->owner))
2537 /* We only want to update locations that are already inserted
2538 and need updating. This is to avoid unwanted insertion during
2539 deletion of breakpoints. */
2540 if (!bl->inserted || (bl->inserted && !bl->needs_update))
2543 switch_to_program_space_and_thread (bl->pspace);
2545 /* For targets that support global breakpoints, there's no need
2546 to select an inferior to insert breakpoint to. In fact, even
2547 if we aren't attached to any process yet, we should still
2548 insert breakpoints. */
2549 if (!gdbarch_has_global_breakpoints (target_gdbarch)
2550 && ptid_equal (inferior_ptid, null_ptid))
2553 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2554 &hw_breakpoint_error);
2561 target_terminal_ours_for_output ();
2562 error_stream (tmp_error_stream);
2565 do_cleanups (cleanups);
2568 /* Used when starting or continuing the program. */
2571 insert_breakpoint_locations (void)
2573 struct breakpoint *bpt;
2574 struct bp_location *bl, **blp_tmp;
2577 int disabled_breaks = 0;
2578 int hw_breakpoint_error = 0;
2580 struct ui_file *tmp_error_stream = mem_fileopen ();
2581 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2583 /* Explicitly mark the warning -- this will only be printed if
2584 there was an error. */
2585 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2587 save_current_space_and_thread ();
2589 ALL_BP_LOCATIONS (bl, blp_tmp)
2591 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2594 /* There is no point inserting thread-specific breakpoints if
2595 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2596 has BL->OWNER always non-NULL. */
2597 if (bl->owner->thread != -1
2598 && !valid_thread_id (bl->owner->thread))
2601 switch_to_program_space_and_thread (bl->pspace);
2603 /* For targets that support global breakpoints, there's no need
2604 to select an inferior to insert breakpoint to. In fact, even
2605 if we aren't attached to any process yet, we should still
2606 insert breakpoints. */
2607 if (!gdbarch_has_global_breakpoints (target_gdbarch)
2608 && ptid_equal (inferior_ptid, null_ptid))
2611 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2612 &hw_breakpoint_error);
2617 /* If we failed to insert all locations of a watchpoint, remove
2618 them, as half-inserted watchpoint is of limited use. */
2619 ALL_BREAKPOINTS (bpt)
2621 int some_failed = 0;
2622 struct bp_location *loc;
2624 if (!is_hardware_watchpoint (bpt))
2627 if (!breakpoint_enabled (bpt))
2630 if (bpt->disposition == disp_del_at_next_stop)
2633 for (loc = bpt->loc; loc; loc = loc->next)
2634 if (!loc->inserted && should_be_inserted (loc))
2641 for (loc = bpt->loc; loc; loc = loc->next)
2643 remove_breakpoint (loc, mark_uninserted);
2645 hw_breakpoint_error = 1;
2646 fprintf_unfiltered (tmp_error_stream,
2647 "Could not insert hardware watchpoint %d.\n",
2655 /* If a hardware breakpoint or watchpoint was inserted, add a
2656 message about possibly exhausted resources. */
2657 if (hw_breakpoint_error)
2659 fprintf_unfiltered (tmp_error_stream,
2660 "Could not insert hardware breakpoints:\n\
2661 You may have requested too many hardware breakpoints/watchpoints.\n");
2663 target_terminal_ours_for_output ();
2664 error_stream (tmp_error_stream);
2667 do_cleanups (cleanups);
2670 /* Used when the program stops.
2671 Returns zero if successful, or non-zero if there was a problem
2672 removing a breakpoint location. */
2675 remove_breakpoints (void)
2677 struct bp_location *bl, **blp_tmp;
2680 ALL_BP_LOCATIONS (bl, blp_tmp)
2682 if (bl->inserted && !is_tracepoint (bl->owner))
2683 val |= remove_breakpoint (bl, mark_uninserted);
2688 /* Remove breakpoints of process PID. */
2691 remove_breakpoints_pid (int pid)
2693 struct bp_location *bl, **blp_tmp;
2695 struct inferior *inf = find_inferior_pid (pid);
2697 ALL_BP_LOCATIONS (bl, blp_tmp)
2699 if (bl->pspace != inf->pspace)
2704 val = remove_breakpoint (bl, mark_uninserted);
2713 reattach_breakpoints (int pid)
2715 struct cleanup *old_chain;
2716 struct bp_location *bl, **blp_tmp;
2718 struct ui_file *tmp_error_stream;
2719 int dummy1 = 0, dummy2 = 0;
2720 struct inferior *inf;
2721 struct thread_info *tp;
2723 tp = any_live_thread_of_process (pid);
2727 inf = find_inferior_pid (pid);
2728 old_chain = save_inferior_ptid ();
2730 inferior_ptid = tp->ptid;
2732 tmp_error_stream = mem_fileopen ();
2733 make_cleanup_ui_file_delete (tmp_error_stream);
2735 ALL_BP_LOCATIONS (bl, blp_tmp)
2737 if (bl->pspace != inf->pspace)
2743 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2);
2746 do_cleanups (old_chain);
2751 do_cleanups (old_chain);
2755 static int internal_breakpoint_number = -1;
2757 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2758 If INTERNAL is non-zero, the breakpoint number will be populated
2759 from internal_breakpoint_number and that variable decremented.
2760 Otherwise the breakpoint number will be populated from
2761 breakpoint_count and that value incremented. Internal breakpoints
2762 do not set the internal var bpnum. */
2764 set_breakpoint_number (int internal, struct breakpoint *b)
2767 b->number = internal_breakpoint_number--;
2770 set_breakpoint_count (breakpoint_count + 1);
2771 b->number = breakpoint_count;
2775 static struct breakpoint *
2776 create_internal_breakpoint (struct gdbarch *gdbarch,
2777 CORE_ADDR address, enum bptype type,
2778 const struct breakpoint_ops *ops)
2780 struct symtab_and_line sal;
2781 struct breakpoint *b;
2783 init_sal (&sal); /* Initialize to zeroes. */
2786 sal.section = find_pc_overlay (sal.pc);
2787 sal.pspace = current_program_space;
2789 b = set_raw_breakpoint (gdbarch, sal, type, ops);
2790 b->number = internal_breakpoint_number--;
2791 b->disposition = disp_donttouch;
2796 static const char *const longjmp_names[] =
2798 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2800 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2802 /* Per-objfile data private to breakpoint.c. */
2803 struct breakpoint_objfile_data
2805 /* Minimal symbol for "_ovly_debug_event" (if any). */
2806 struct minimal_symbol *overlay_msym;
2808 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2809 struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES];
2811 /* True if we have looked for longjmp probes. */
2812 int longjmp_searched;
2814 /* SystemTap probe points for longjmp (if any). */
2815 VEC (probe_p) *longjmp_probes;
2817 /* Minimal symbol for "std::terminate()" (if any). */
2818 struct minimal_symbol *terminate_msym;
2820 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2821 struct minimal_symbol *exception_msym;
2823 /* True if we have looked for exception probes. */
2824 int exception_searched;
2826 /* SystemTap probe points for unwinding (if any). */
2827 VEC (probe_p) *exception_probes;
2830 static const struct objfile_data *breakpoint_objfile_key;
2832 /* Minimal symbol not found sentinel. */
2833 static struct minimal_symbol msym_not_found;
2835 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2838 msym_not_found_p (const struct minimal_symbol *msym)
2840 return msym == &msym_not_found;
2843 /* Return per-objfile data needed by breakpoint.c.
2844 Allocate the data if necessary. */
2846 static struct breakpoint_objfile_data *
2847 get_breakpoint_objfile_data (struct objfile *objfile)
2849 struct breakpoint_objfile_data *bp_objfile_data;
2851 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
2852 if (bp_objfile_data == NULL)
2854 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
2855 sizeof (*bp_objfile_data));
2857 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
2858 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
2860 return bp_objfile_data;
2864 free_breakpoint_probes (struct objfile *obj, void *data)
2866 struct breakpoint_objfile_data *bp_objfile_data = data;
2868 VEC_free (probe_p, bp_objfile_data->longjmp_probes);
2869 VEC_free (probe_p, bp_objfile_data->exception_probes);
2873 create_overlay_event_breakpoint (void)
2875 struct objfile *objfile;
2876 const char *const func_name = "_ovly_debug_event";
2878 ALL_OBJFILES (objfile)
2880 struct breakpoint *b;
2881 struct breakpoint_objfile_data *bp_objfile_data;
2884 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2886 if (msym_not_found_p (bp_objfile_data->overlay_msym))
2889 if (bp_objfile_data->overlay_msym == NULL)
2891 struct minimal_symbol *m;
2893 m = lookup_minimal_symbol_text (func_name, objfile);
2896 /* Avoid future lookups in this objfile. */
2897 bp_objfile_data->overlay_msym = &msym_not_found;
2900 bp_objfile_data->overlay_msym = m;
2903 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
2904 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
2906 &internal_breakpoint_ops);
2907 b->addr_string = xstrdup (func_name);
2909 if (overlay_debugging == ovly_auto)
2911 b->enable_state = bp_enabled;
2912 overlay_events_enabled = 1;
2916 b->enable_state = bp_disabled;
2917 overlay_events_enabled = 0;
2920 update_global_location_list (1);
2924 create_longjmp_master_breakpoint (void)
2926 struct program_space *pspace;
2927 struct cleanup *old_chain;
2929 old_chain = save_current_program_space ();
2931 ALL_PSPACES (pspace)
2933 struct objfile *objfile;
2935 set_current_program_space (pspace);
2937 ALL_OBJFILES (objfile)
2940 struct gdbarch *gdbarch;
2941 struct breakpoint_objfile_data *bp_objfile_data;
2943 gdbarch = get_objfile_arch (objfile);
2944 if (!gdbarch_get_longjmp_target_p (gdbarch))
2947 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2949 if (!bp_objfile_data->longjmp_searched)
2951 bp_objfile_data->longjmp_probes
2952 = find_probes_in_objfile (objfile, "libc", "longjmp");
2953 bp_objfile_data->longjmp_searched = 1;
2956 if (bp_objfile_data->longjmp_probes != NULL)
2959 struct probe *probe;
2960 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2963 VEC_iterate (probe_p,
2964 bp_objfile_data->longjmp_probes,
2968 struct breakpoint *b;
2970 b = create_internal_breakpoint (gdbarch, probe->address,
2972 &internal_breakpoint_ops);
2973 b->addr_string = xstrdup ("-probe-stap libc:longjmp");
2974 b->enable_state = bp_disabled;
2980 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
2982 struct breakpoint *b;
2983 const char *func_name;
2986 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i]))
2989 func_name = longjmp_names[i];
2990 if (bp_objfile_data->longjmp_msym[i] == NULL)
2992 struct minimal_symbol *m;
2994 m = lookup_minimal_symbol_text (func_name, objfile);
2997 /* Prevent future lookups in this objfile. */
2998 bp_objfile_data->longjmp_msym[i] = &msym_not_found;
3001 bp_objfile_data->longjmp_msym[i] = m;
3004 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
3005 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
3006 &internal_breakpoint_ops);
3007 b->addr_string = xstrdup (func_name);
3008 b->enable_state = bp_disabled;
3012 update_global_location_list (1);
3014 do_cleanups (old_chain);
3017 /* Create a master std::terminate breakpoint. */
3019 create_std_terminate_master_breakpoint (void)
3021 struct program_space *pspace;
3022 struct cleanup *old_chain;
3023 const char *const func_name = "std::terminate()";
3025 old_chain = save_current_program_space ();
3027 ALL_PSPACES (pspace)
3029 struct objfile *objfile;
3032 set_current_program_space (pspace);
3034 ALL_OBJFILES (objfile)
3036 struct breakpoint *b;
3037 struct breakpoint_objfile_data *bp_objfile_data;
3039 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3041 if (msym_not_found_p (bp_objfile_data->terminate_msym))
3044 if (bp_objfile_data->terminate_msym == NULL)
3046 struct minimal_symbol *m;
3048 m = lookup_minimal_symbol (func_name, NULL, objfile);
3049 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
3050 && MSYMBOL_TYPE (m) != mst_file_text))
3052 /* Prevent future lookups in this objfile. */
3053 bp_objfile_data->terminate_msym = &msym_not_found;
3056 bp_objfile_data->terminate_msym = m;
3059 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3060 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3061 bp_std_terminate_master,
3062 &internal_breakpoint_ops);
3063 b->addr_string = xstrdup (func_name);
3064 b->enable_state = bp_disabled;
3068 update_global_location_list (1);
3070 do_cleanups (old_chain);
3073 /* Install a master breakpoint on the unwinder's debug hook. */
3076 create_exception_master_breakpoint (void)
3078 struct objfile *objfile;
3079 const char *const func_name = "_Unwind_DebugHook";
3081 ALL_OBJFILES (objfile)
3083 struct breakpoint *b;
3084 struct gdbarch *gdbarch;
3085 struct breakpoint_objfile_data *bp_objfile_data;
3088 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3090 /* We prefer the SystemTap probe point if it exists. */
3091 if (!bp_objfile_data->exception_searched)
3093 bp_objfile_data->exception_probes
3094 = find_probes_in_objfile (objfile, "libgcc", "unwind");
3095 bp_objfile_data->exception_searched = 1;
3098 if (bp_objfile_data->exception_probes != NULL)
3100 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3102 struct probe *probe;
3105 VEC_iterate (probe_p,
3106 bp_objfile_data->exception_probes,
3110 struct breakpoint *b;
3112 b = create_internal_breakpoint (gdbarch, probe->address,
3113 bp_exception_master,
3114 &internal_breakpoint_ops);
3115 b->addr_string = xstrdup ("-probe-stap libgcc:unwind");
3116 b->enable_state = bp_disabled;
3122 /* Otherwise, try the hook function. */
3124 if (msym_not_found_p (bp_objfile_data->exception_msym))
3127 gdbarch = get_objfile_arch (objfile);
3129 if (bp_objfile_data->exception_msym == NULL)
3131 struct minimal_symbol *debug_hook;
3133 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3134 if (debug_hook == NULL)
3136 bp_objfile_data->exception_msym = &msym_not_found;
3140 bp_objfile_data->exception_msym = debug_hook;
3143 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3144 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3146 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3147 &internal_breakpoint_ops);
3148 b->addr_string = xstrdup (func_name);
3149 b->enable_state = bp_disabled;
3152 update_global_location_list (1);
3156 update_breakpoints_after_exec (void)
3158 struct breakpoint *b, *b_tmp;
3159 struct bp_location *bploc, **bplocp_tmp;
3161 /* We're about to delete breakpoints from GDB's lists. If the
3162 INSERTED flag is true, GDB will try to lift the breakpoints by
3163 writing the breakpoints' "shadow contents" back into memory. The
3164 "shadow contents" are NOT valid after an exec, so GDB should not
3165 do that. Instead, the target is responsible from marking
3166 breakpoints out as soon as it detects an exec. We don't do that
3167 here instead, because there may be other attempts to delete
3168 breakpoints after detecting an exec and before reaching here. */
3169 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3170 if (bploc->pspace == current_program_space)
3171 gdb_assert (!bploc->inserted);
3173 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3175 if (b->pspace != current_program_space)
3178 /* Solib breakpoints must be explicitly reset after an exec(). */
3179 if (b->type == bp_shlib_event)
3181 delete_breakpoint (b);
3185 /* JIT breakpoints must be explicitly reset after an exec(). */
3186 if (b->type == bp_jit_event)
3188 delete_breakpoint (b);
3192 /* Thread event breakpoints must be set anew after an exec(),
3193 as must overlay event and longjmp master breakpoints. */
3194 if (b->type == bp_thread_event || b->type == bp_overlay_event
3195 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3196 || b->type == bp_exception_master)
3198 delete_breakpoint (b);
3202 /* Step-resume breakpoints are meaningless after an exec(). */
3203 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3205 delete_breakpoint (b);
3209 /* Longjmp and longjmp-resume breakpoints are also meaningless
3211 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3212 || b->type == bp_longjmp_call_dummy
3213 || b->type == bp_exception || b->type == bp_exception_resume)
3215 delete_breakpoint (b);
3219 if (b->type == bp_catchpoint)
3221 /* For now, none of the bp_catchpoint breakpoints need to
3222 do anything at this point. In the future, if some of
3223 the catchpoints need to something, we will need to add
3224 a new method, and call this method from here. */
3228 /* bp_finish is a special case. The only way we ought to be able
3229 to see one of these when an exec() has happened, is if the user
3230 caught a vfork, and then said "finish". Ordinarily a finish just
3231 carries them to the call-site of the current callee, by setting
3232 a temporary bp there and resuming. But in this case, the finish
3233 will carry them entirely through the vfork & exec.
3235 We don't want to allow a bp_finish to remain inserted now. But
3236 we can't safely delete it, 'cause finish_command has a handle to
3237 the bp on a bpstat, and will later want to delete it. There's a
3238 chance (and I've seen it happen) that if we delete the bp_finish
3239 here, that its storage will get reused by the time finish_command
3240 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3241 We really must allow finish_command to delete a bp_finish.
3243 In the absence of a general solution for the "how do we know
3244 it's safe to delete something others may have handles to?"
3245 problem, what we'll do here is just uninsert the bp_finish, and
3246 let finish_command delete it.
3248 (We know the bp_finish is "doomed" in the sense that it's
3249 momentary, and will be deleted as soon as finish_command sees
3250 the inferior stopped. So it doesn't matter that the bp's
3251 address is probably bogus in the new a.out, unlike e.g., the
3252 solib breakpoints.) */
3254 if (b->type == bp_finish)
3259 /* Without a symbolic address, we have little hope of the
3260 pre-exec() address meaning the same thing in the post-exec()
3262 if (b->addr_string == NULL)
3264 delete_breakpoint (b);
3268 /* FIXME what about longjmp breakpoints? Re-create them here? */
3269 create_overlay_event_breakpoint ();
3270 create_longjmp_master_breakpoint ();
3271 create_std_terminate_master_breakpoint ();
3272 create_exception_master_breakpoint ();
3276 detach_breakpoints (int pid)
3278 struct bp_location *bl, **blp_tmp;
3280 struct cleanup *old_chain = save_inferior_ptid ();
3281 struct inferior *inf = current_inferior ();
3283 if (pid == PIDGET (inferior_ptid))
3284 error (_("Cannot detach breakpoints of inferior_ptid"));
3286 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3287 inferior_ptid = pid_to_ptid (pid);
3288 ALL_BP_LOCATIONS (bl, blp_tmp)
3290 if (bl->pspace != inf->pspace)
3294 val |= remove_breakpoint_1 (bl, mark_inserted);
3297 /* Detach single-step breakpoints as well. */
3298 detach_single_step_breakpoints ();
3300 do_cleanups (old_chain);
3304 /* Remove the breakpoint location BL from the current address space.
3305 Note that this is used to detach breakpoints from a child fork.
3306 When we get here, the child isn't in the inferior list, and neither
3307 do we have objects to represent its address space --- we should
3308 *not* look at bl->pspace->aspace here. */
3311 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
3315 /* BL is never in moribund_locations by our callers. */
3316 gdb_assert (bl->owner != NULL);
3318 if (bl->owner->enable_state == bp_permanent)
3319 /* Permanent breakpoints cannot be inserted or removed. */
3322 /* The type of none suggests that owner is actually deleted.
3323 This should not ever happen. */
3324 gdb_assert (bl->owner->type != bp_none);
3326 if (bl->loc_type == bp_loc_software_breakpoint
3327 || bl->loc_type == bp_loc_hardware_breakpoint)
3329 /* "Normal" instruction breakpoint: either the standard
3330 trap-instruction bp (bp_breakpoint), or a
3331 bp_hardware_breakpoint. */
3333 /* First check to see if we have to handle an overlay. */
3334 if (overlay_debugging == ovly_off
3335 || bl->section == NULL
3336 || !(section_is_overlay (bl->section)))
3338 /* No overlay handling: just remove the breakpoint. */
3339 val = bl->owner->ops->remove_location (bl);
3343 /* This breakpoint is in an overlay section.
3344 Did we set a breakpoint at the LMA? */
3345 if (!overlay_events_enabled)
3347 /* Yes -- overlay event support is not active, so we
3348 should have set a breakpoint at the LMA. Remove it.
3350 /* Ignore any failures: if the LMA is in ROM, we will
3351 have already warned when we failed to insert it. */
3352 if (bl->loc_type == bp_loc_hardware_breakpoint)
3353 target_remove_hw_breakpoint (bl->gdbarch,
3354 &bl->overlay_target_info);
3356 target_remove_breakpoint (bl->gdbarch,
3357 &bl->overlay_target_info);
3359 /* Did we set a breakpoint at the VMA?
3360 If so, we will have marked the breakpoint 'inserted'. */
3363 /* Yes -- remove it. Previously we did not bother to
3364 remove the breakpoint if the section had been
3365 unmapped, but let's not rely on that being safe. We
3366 don't know what the overlay manager might do. */
3368 /* However, we should remove *software* breakpoints only
3369 if the section is still mapped, or else we overwrite
3370 wrong code with the saved shadow contents. */
3371 if (bl->loc_type == bp_loc_hardware_breakpoint
3372 || section_is_mapped (bl->section))
3373 val = bl->owner->ops->remove_location (bl);
3379 /* No -- not inserted, so no need to remove. No error. */
3384 /* In some cases, we might not be able to remove a breakpoint
3385 in a shared library that has already been removed, but we
3386 have not yet processed the shlib unload event. */
3387 if (val && solib_name_from_address (bl->pspace, bl->address))
3392 bl->inserted = (is == mark_inserted);
3394 else if (bl->loc_type == bp_loc_hardware_watchpoint)
3396 gdb_assert (bl->owner->ops != NULL
3397 && bl->owner->ops->remove_location != NULL);
3399 bl->inserted = (is == mark_inserted);
3400 bl->owner->ops->remove_location (bl);
3402 /* Failure to remove any of the hardware watchpoints comes here. */
3403 if ((is == mark_uninserted) && (bl->inserted))
3404 warning (_("Could not remove hardware watchpoint %d."),
3407 else if (bl->owner->type == bp_catchpoint
3408 && breakpoint_enabled (bl->owner)
3411 gdb_assert (bl->owner->ops != NULL
3412 && bl->owner->ops->remove_location != NULL);
3414 val = bl->owner->ops->remove_location (bl);
3418 bl->inserted = (is == mark_inserted);
3425 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
3428 struct cleanup *old_chain;
3430 /* BL is never in moribund_locations by our callers. */
3431 gdb_assert (bl->owner != NULL);
3433 if (bl->owner->enable_state == bp_permanent)
3434 /* Permanent breakpoints cannot be inserted or removed. */
3437 /* The type of none suggests that owner is actually deleted.
3438 This should not ever happen. */
3439 gdb_assert (bl->owner->type != bp_none);
3441 old_chain = save_current_space_and_thread ();
3443 switch_to_program_space_and_thread (bl->pspace);
3445 ret = remove_breakpoint_1 (bl, is);
3447 do_cleanups (old_chain);
3451 /* Clear the "inserted" flag in all breakpoints. */
3454 mark_breakpoints_out (void)
3456 struct bp_location *bl, **blp_tmp;
3458 ALL_BP_LOCATIONS (bl, blp_tmp)
3459 if (bl->pspace == current_program_space)
3463 /* Clear the "inserted" flag in all breakpoints and delete any
3464 breakpoints which should go away between runs of the program.
3466 Plus other such housekeeping that has to be done for breakpoints
3469 Note: this function gets called at the end of a run (by
3470 generic_mourn_inferior) and when a run begins (by
3471 init_wait_for_inferior). */
3476 breakpoint_init_inferior (enum inf_context context)
3478 struct breakpoint *b, *b_tmp;
3479 struct bp_location *bl, **blp_tmp;
3481 struct program_space *pspace = current_program_space;
3483 /* If breakpoint locations are shared across processes, then there's
3485 if (gdbarch_has_global_breakpoints (target_gdbarch))
3488 ALL_BP_LOCATIONS (bl, blp_tmp)
3490 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3491 if (bl->pspace == pspace
3492 && bl->owner->enable_state != bp_permanent)
3496 ALL_BREAKPOINTS_SAFE (b, b_tmp)
3498 if (b->loc && b->loc->pspace != pspace)
3504 case bp_longjmp_call_dummy:
3506 /* If the call dummy breakpoint is at the entry point it will
3507 cause problems when the inferior is rerun, so we better get
3510 case bp_watchpoint_scope:
3512 /* Also get rid of scope breakpoints. */
3514 case bp_shlib_event:
3516 /* Also remove solib event breakpoints. Their addresses may
3517 have changed since the last time we ran the program.
3518 Actually we may now be debugging against different target;
3519 and so the solib backend that installed this breakpoint may
3520 not be used in by the target. E.g.,
3522 (gdb) file prog-linux
3523 (gdb) run # native linux target
3526 (gdb) file prog-win.exe
3527 (gdb) tar rem :9999 # remote Windows gdbserver.
3530 case bp_step_resume:
3532 /* Also remove step-resume breakpoints. */
3534 delete_breakpoint (b);
3538 case bp_hardware_watchpoint:
3539 case bp_read_watchpoint:
3540 case bp_access_watchpoint:
3542 struct watchpoint *w = (struct watchpoint *) b;
3544 /* Likewise for watchpoints on local expressions. */
3545 if (w->exp_valid_block != NULL)
3546 delete_breakpoint (b);
3547 else if (context == inf_starting)
3549 /* Reset val field to force reread of starting value in
3550 insert_breakpoints. */
3552 value_free (w->val);
3563 /* Get rid of the moribund locations. */
3564 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
3565 decref_bp_location (&bl);
3566 VEC_free (bp_location_p, moribund_locations);
3569 /* These functions concern about actual breakpoints inserted in the
3570 target --- to e.g. check if we need to do decr_pc adjustment or if
3571 we need to hop over the bkpt --- so we check for address space
3572 match, not program space. */
3574 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3575 exists at PC. It returns ordinary_breakpoint_here if it's an
3576 ordinary breakpoint, or permanent_breakpoint_here if it's a
3577 permanent breakpoint.
3578 - When continuing from a location with an ordinary breakpoint, we
3579 actually single step once before calling insert_breakpoints.
3580 - When continuing from a location with a permanent breakpoint, we
3581 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3582 the target, to advance the PC past the breakpoint. */
3584 enum breakpoint_here
3585 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
3587 struct bp_location *bl, **blp_tmp;
3588 int any_breakpoint_here = 0;
3590 ALL_BP_LOCATIONS (bl, blp_tmp)
3592 if (bl->loc_type != bp_loc_software_breakpoint
3593 && bl->loc_type != bp_loc_hardware_breakpoint)
3596 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3597 if ((breakpoint_enabled (bl->owner)
3598 || bl->owner->enable_state == bp_permanent)
3599 && breakpoint_location_address_match (bl, aspace, pc))
3601 if (overlay_debugging
3602 && section_is_overlay (bl->section)
3603 && !section_is_mapped (bl->section))
3604 continue; /* unmapped overlay -- can't be a match */
3605 else if (bl->owner->enable_state == bp_permanent)
3606 return permanent_breakpoint_here;
3608 any_breakpoint_here = 1;
3612 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
3615 /* Return true if there's a moribund breakpoint at PC. */
3618 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
3620 struct bp_location *loc;
3623 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
3624 if (breakpoint_location_address_match (loc, aspace, pc))
3630 /* Returns non-zero if there's a breakpoint inserted at PC, which is
3631 inserted using regular breakpoint_chain / bp_location array
3632 mechanism. This does not check for single-step breakpoints, which
3633 are inserted and removed using direct target manipulation. */
3636 regular_breakpoint_inserted_here_p (struct address_space *aspace,
3639 struct bp_location *bl, **blp_tmp;
3641 ALL_BP_LOCATIONS (bl, blp_tmp)
3643 if (bl->loc_type != bp_loc_software_breakpoint
3644 && bl->loc_type != bp_loc_hardware_breakpoint)
3648 && breakpoint_location_address_match (bl, aspace, pc))
3650 if (overlay_debugging
3651 && section_is_overlay (bl->section)
3652 && !section_is_mapped (bl->section))
3653 continue; /* unmapped overlay -- can't be a match */
3661 /* Returns non-zero iff there's either regular breakpoint
3662 or a single step breakpoint inserted at PC. */
3665 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
3667 if (regular_breakpoint_inserted_here_p (aspace, pc))
3670 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3676 /* This function returns non-zero iff there is a software breakpoint
3680 software_breakpoint_inserted_here_p (struct address_space *aspace,
3683 struct bp_location *bl, **blp_tmp;
3685 ALL_BP_LOCATIONS (bl, blp_tmp)
3687 if (bl->loc_type != bp_loc_software_breakpoint)
3691 && breakpoint_address_match (bl->pspace->aspace, bl->address,
3694 if (overlay_debugging
3695 && section_is_overlay (bl->section)
3696 && !section_is_mapped (bl->section))
3697 continue; /* unmapped overlay -- can't be a match */
3703 /* Also check for software single-step breakpoints. */
3704 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3711 hardware_watchpoint_inserted_in_range (struct address_space *aspace,
3712 CORE_ADDR addr, ULONGEST len)
3714 struct breakpoint *bpt;
3716 ALL_BREAKPOINTS (bpt)
3718 struct bp_location *loc;
3720 if (bpt->type != bp_hardware_watchpoint
3721 && bpt->type != bp_access_watchpoint)
3724 if (!breakpoint_enabled (bpt))
3727 for (loc = bpt->loc; loc; loc = loc->next)
3728 if (loc->pspace->aspace == aspace && loc->inserted)
3732 /* Check for intersection. */
3733 l = max (loc->address, addr);
3734 h = min (loc->address + loc->length, addr + len);
3742 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3743 PC is valid for process/thread PTID. */
3746 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
3749 struct bp_location *bl, **blp_tmp;
3750 /* The thread and task IDs associated to PTID, computed lazily. */
3754 ALL_BP_LOCATIONS (bl, blp_tmp)
3756 if (bl->loc_type != bp_loc_software_breakpoint
3757 && bl->loc_type != bp_loc_hardware_breakpoint)
3760 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3761 if (!breakpoint_enabled (bl->owner)
3762 && bl->owner->enable_state != bp_permanent)
3765 if (!breakpoint_location_address_match (bl, aspace, pc))
3768 if (bl->owner->thread != -1)
3770 /* This is a thread-specific breakpoint. Check that ptid
3771 matches that thread. If thread hasn't been computed yet,
3772 it is now time to do so. */
3774 thread = pid_to_thread_id (ptid);
3775 if (bl->owner->thread != thread)
3779 if (bl->owner->task != 0)
3781 /* This is a task-specific breakpoint. Check that ptid
3782 matches that task. If task hasn't been computed yet,
3783 it is now time to do so. */
3785 task = ada_get_task_number (ptid);
3786 if (bl->owner->task != task)
3790 if (overlay_debugging
3791 && section_is_overlay (bl->section)
3792 && !section_is_mapped (bl->section))
3793 continue; /* unmapped overlay -- can't be a match */
3802 /* bpstat stuff. External routines' interfaces are documented
3806 is_catchpoint (struct breakpoint *ep)
3808 return (ep->type == bp_catchpoint);
3811 /* Frees any storage that is part of a bpstat. Does not walk the
3815 bpstat_free (bpstat bs)
3817 if (bs->old_val != NULL)
3818 value_free (bs->old_val);
3819 decref_counted_command_line (&bs->commands);
3820 decref_bp_location (&bs->bp_location_at);
3824 /* Clear a bpstat so that it says we are not at any breakpoint.
3825 Also free any storage that is part of a bpstat. */
3828 bpstat_clear (bpstat *bsp)
3845 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3846 is part of the bpstat is copied as well. */
3849 bpstat_copy (bpstat bs)
3853 bpstat retval = NULL;
3858 for (; bs != NULL; bs = bs->next)
3860 tmp = (bpstat) xmalloc (sizeof (*tmp));
3861 memcpy (tmp, bs, sizeof (*tmp));
3862 incref_counted_command_line (tmp->commands);
3863 incref_bp_location (tmp->bp_location_at);
3864 if (bs->old_val != NULL)
3866 tmp->old_val = value_copy (bs->old_val);
3867 release_value (tmp->old_val);
3871 /* This is the first thing in the chain. */
3881 /* Find the bpstat associated with this breakpoint. */
3884 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
3889 for (; bsp != NULL; bsp = bsp->next)
3891 if (bsp->breakpoint_at == breakpoint)
3897 /* Put in *NUM the breakpoint number of the first breakpoint we are
3898 stopped at. *BSP upon return is a bpstat which points to the
3899 remaining breakpoints stopped at (but which is not guaranteed to be
3900 good for anything but further calls to bpstat_num).
3902 Return 0 if passed a bpstat which does not indicate any breakpoints.
3903 Return -1 if stopped at a breakpoint that has been deleted since
3905 Return 1 otherwise. */
3908 bpstat_num (bpstat *bsp, int *num)
3910 struct breakpoint *b;
3913 return 0; /* No more breakpoint values */
3915 /* We assume we'll never have several bpstats that correspond to a
3916 single breakpoint -- otherwise, this function might return the
3917 same number more than once and this will look ugly. */
3918 b = (*bsp)->breakpoint_at;
3919 *bsp = (*bsp)->next;
3921 return -1; /* breakpoint that's been deleted since */
3923 *num = b->number; /* We have its number */
3927 /* See breakpoint.h. */
3930 bpstat_clear_actions (void)
3932 struct thread_info *tp;
3935 if (ptid_equal (inferior_ptid, null_ptid))
3938 tp = find_thread_ptid (inferior_ptid);
3942 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
3944 decref_counted_command_line (&bs->commands);
3946 if (bs->old_val != NULL)
3948 value_free (bs->old_val);
3954 /* Called when a command is about to proceed the inferior. */
3957 breakpoint_about_to_proceed (void)
3959 if (!ptid_equal (inferior_ptid, null_ptid))
3961 struct thread_info *tp = inferior_thread ();
3963 /* Allow inferior function calls in breakpoint commands to not
3964 interrupt the command list. When the call finishes
3965 successfully, the inferior will be standing at the same
3966 breakpoint as if nothing happened. */
3967 if (tp->control.in_infcall)
3971 breakpoint_proceeded = 1;
3974 /* Stub for cleaning up our state if we error-out of a breakpoint
3977 cleanup_executing_breakpoints (void *ignore)
3979 executing_breakpoint_commands = 0;
3982 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3983 or its equivalent. */
3986 command_line_is_silent (struct command_line *cmd)
3988 return cmd && (strcmp ("silent", cmd->line) == 0
3989 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
3992 /* Execute all the commands associated with all the breakpoints at
3993 this location. Any of these commands could cause the process to
3994 proceed beyond this point, etc. We look out for such changes by
3995 checking the global "breakpoint_proceeded" after each command.
3997 Returns true if a breakpoint command resumed the inferior. In that
3998 case, it is the caller's responsibility to recall it again with the
3999 bpstat of the current thread. */
4002 bpstat_do_actions_1 (bpstat *bsp)
4005 struct cleanup *old_chain;
4008 /* Avoid endless recursion if a `source' command is contained
4010 if (executing_breakpoint_commands)
4013 executing_breakpoint_commands = 1;
4014 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
4016 prevent_dont_repeat ();
4018 /* This pointer will iterate over the list of bpstat's. */
4021 breakpoint_proceeded = 0;
4022 for (; bs != NULL; bs = bs->next)
4024 struct counted_command_line *ccmd;
4025 struct command_line *cmd;
4026 struct cleanup *this_cmd_tree_chain;
4028 /* Take ownership of the BSP's command tree, if it has one.
4030 The command tree could legitimately contain commands like
4031 'step' and 'next', which call clear_proceed_status, which
4032 frees stop_bpstat's command tree. To make sure this doesn't
4033 free the tree we're executing out from under us, we need to
4034 take ownership of the tree ourselves. Since a given bpstat's
4035 commands are only executed once, we don't need to copy it; we
4036 can clear the pointer in the bpstat, and make sure we free
4037 the tree when we're done. */
4038 ccmd = bs->commands;
4039 bs->commands = NULL;
4040 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
4041 cmd = ccmd ? ccmd->commands : NULL;
4042 if (command_line_is_silent (cmd))
4044 /* The action has been already done by bpstat_stop_status. */
4050 execute_control_command (cmd);
4052 if (breakpoint_proceeded)
4058 /* We can free this command tree now. */
4059 do_cleanups (this_cmd_tree_chain);
4061 if (breakpoint_proceeded)
4063 if (target_can_async_p ())
4064 /* If we are in async mode, then the target might be still
4065 running, not stopped at any breakpoint, so nothing for
4066 us to do here -- just return to the event loop. */
4069 /* In sync mode, when execute_control_command returns
4070 we're already standing on the next breakpoint.
4071 Breakpoint commands for that stop were not run, since
4072 execute_command does not run breakpoint commands --
4073 only command_line_handler does, but that one is not
4074 involved in execution of breakpoint commands. So, we
4075 can now execute breakpoint commands. It should be
4076 noted that making execute_command do bpstat actions is
4077 not an option -- in this case we'll have recursive
4078 invocation of bpstat for each breakpoint with a
4079 command, and can easily blow up GDB stack. Instead, we
4080 return true, which will trigger the caller to recall us
4081 with the new stop_bpstat. */
4086 do_cleanups (old_chain);
4091 bpstat_do_actions (void)
4093 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4095 /* Do any commands attached to breakpoint we are stopped at. */
4096 while (!ptid_equal (inferior_ptid, null_ptid)
4097 && target_has_execution
4098 && !is_exited (inferior_ptid)
4099 && !is_executing (inferior_ptid))
4100 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4101 and only return when it is stopped at the next breakpoint, we
4102 keep doing breakpoint actions until it returns false to
4103 indicate the inferior was not resumed. */
4104 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
4107 discard_cleanups (cleanup_if_error);
4110 /* Print out the (old or new) value associated with a watchpoint. */
4113 watchpoint_value_print (struct value *val, struct ui_file *stream)
4116 fprintf_unfiltered (stream, _("<unreadable>"));
4119 struct value_print_options opts;
4120 get_user_print_options (&opts);
4121 value_print (val, stream, &opts);
4125 /* Generic routine for printing messages indicating why we
4126 stopped. The behavior of this function depends on the value
4127 'print_it' in the bpstat structure. Under some circumstances we
4128 may decide not to print anything here and delegate the task to
4131 static enum print_stop_action
4132 print_bp_stop_message (bpstat bs)
4134 switch (bs->print_it)
4137 /* Nothing should be printed for this bpstat entry. */
4138 return PRINT_UNKNOWN;
4142 /* We still want to print the frame, but we already printed the
4143 relevant messages. */
4144 return PRINT_SRC_AND_LOC;
4147 case print_it_normal:
4149 struct breakpoint *b = bs->breakpoint_at;
4151 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4152 which has since been deleted. */
4154 return PRINT_UNKNOWN;
4156 /* Normal case. Call the breakpoint's print_it method. */
4157 return b->ops->print_it (bs);
4162 internal_error (__FILE__, __LINE__,
4163 _("print_bp_stop_message: unrecognized enum value"));
4168 /* A helper function that prints a shared library stopped event. */
4171 print_solib_event (int is_catchpoint)
4174 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4176 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4180 if (any_added || any_deleted)
4181 ui_out_text (current_uiout,
4182 _("Stopped due to shared library event:\n"));
4184 ui_out_text (current_uiout,
4185 _("Stopped due to shared library event (no "
4186 "libraries added or removed)\n"));
4189 if (ui_out_is_mi_like_p (current_uiout))
4190 ui_out_field_string (current_uiout, "reason",
4191 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4195 struct cleanup *cleanup;
4199 ui_out_text (current_uiout, _(" Inferior unloaded "));
4200 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4203 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4208 ui_out_text (current_uiout, " ");
4209 ui_out_field_string (current_uiout, "library", name);
4210 ui_out_text (current_uiout, "\n");
4213 do_cleanups (cleanup);
4218 struct so_list *iter;
4220 struct cleanup *cleanup;
4222 ui_out_text (current_uiout, _(" Inferior loaded "));
4223 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4226 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4231 ui_out_text (current_uiout, " ");
4232 ui_out_field_string (current_uiout, "library", iter->so_name);
4233 ui_out_text (current_uiout, "\n");
4236 do_cleanups (cleanup);
4240 /* Print a message indicating what happened. This is called from
4241 normal_stop(). The input to this routine is the head of the bpstat
4242 list - a list of the eventpoints that caused this stop. KIND is
4243 the target_waitkind for the stopping event. This
4244 routine calls the generic print routine for printing a message
4245 about reasons for stopping. This will print (for example) the
4246 "Breakpoint n," part of the output. The return value of this
4249 PRINT_UNKNOWN: Means we printed nothing.
4250 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4251 code to print the location. An example is
4252 "Breakpoint 1, " which should be followed by
4254 PRINT_SRC_ONLY: Means we printed something, but there is no need
4255 to also print the location part of the message.
4256 An example is the catch/throw messages, which
4257 don't require a location appended to the end.
4258 PRINT_NOTHING: We have done some printing and we don't need any
4259 further info to be printed. */
4261 enum print_stop_action
4262 bpstat_print (bpstat bs, int kind)
4266 /* Maybe another breakpoint in the chain caused us to stop.
4267 (Currently all watchpoints go on the bpstat whether hit or not.
4268 That probably could (should) be changed, provided care is taken
4269 with respect to bpstat_explains_signal). */
4270 for (; bs; bs = bs->next)
4272 val = print_bp_stop_message (bs);
4273 if (val == PRINT_SRC_ONLY
4274 || val == PRINT_SRC_AND_LOC
4275 || val == PRINT_NOTHING)
4279 /* If we had hit a shared library event breakpoint,
4280 print_bp_stop_message would print out this message. If we hit an
4281 OS-level shared library event, do the same thing. */
4282 if (kind == TARGET_WAITKIND_LOADED)
4284 print_solib_event (0);
4285 return PRINT_NOTHING;
4288 /* We reached the end of the chain, or we got a null BS to start
4289 with and nothing was printed. */
4290 return PRINT_UNKNOWN;
4293 /* Evaluate the expression EXP and return 1 if value is zero. This is
4294 used inside a catch_errors to evaluate the breakpoint condition.
4295 The argument is a "struct expression *" that has been cast to a
4296 "char *" to make it pass through catch_errors. */
4299 breakpoint_cond_eval (void *exp)
4301 struct value *mark = value_mark ();
4302 int i = !value_true (evaluate_expression ((struct expression *) exp));
4304 value_free_to_mark (mark);
4308 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4311 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
4315 bs = (bpstat) xmalloc (sizeof (*bs));
4317 **bs_link_pointer = bs;
4318 *bs_link_pointer = &bs->next;
4319 bs->breakpoint_at = bl->owner;
4320 bs->bp_location_at = bl;
4321 incref_bp_location (bl);
4322 /* If the condition is false, etc., don't do the commands. */
4323 bs->commands = NULL;
4325 bs->print_it = print_it_normal;
4329 /* The target has stopped with waitstatus WS. Check if any hardware
4330 watchpoints have triggered, according to the target. */
4333 watchpoints_triggered (struct target_waitstatus *ws)
4335 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
4337 struct breakpoint *b;
4339 if (!stopped_by_watchpoint)
4341 /* We were not stopped by a watchpoint. Mark all watchpoints
4342 as not triggered. */
4344 if (is_hardware_watchpoint (b))
4346 struct watchpoint *w = (struct watchpoint *) b;
4348 w->watchpoint_triggered = watch_triggered_no;
4354 if (!target_stopped_data_address (¤t_target, &addr))
4356 /* We were stopped by a watchpoint, but we don't know where.
4357 Mark all watchpoints as unknown. */
4359 if (is_hardware_watchpoint (b))
4361 struct watchpoint *w = (struct watchpoint *) b;
4363 w->watchpoint_triggered = watch_triggered_unknown;
4366 return stopped_by_watchpoint;
4369 /* The target could report the data address. Mark watchpoints
4370 affected by this data address as triggered, and all others as not
4374 if (is_hardware_watchpoint (b))
4376 struct watchpoint *w = (struct watchpoint *) b;
4377 struct bp_location *loc;
4379 w->watchpoint_triggered = watch_triggered_no;
4380 for (loc = b->loc; loc; loc = loc->next)
4382 if (is_masked_watchpoint (b))
4384 CORE_ADDR newaddr = addr & w->hw_wp_mask;
4385 CORE_ADDR start = loc->address & w->hw_wp_mask;
4387 if (newaddr == start)
4389 w->watchpoint_triggered = watch_triggered_yes;
4393 /* Exact match not required. Within range is sufficient. */
4394 else if (target_watchpoint_addr_within_range (¤t_target,
4398 w->watchpoint_triggered = watch_triggered_yes;
4407 /* Possible return values for watchpoint_check (this can't be an enum
4408 because of check_errors). */
4409 /* The watchpoint has been deleted. */
4410 #define WP_DELETED 1
4411 /* The value has changed. */
4412 #define WP_VALUE_CHANGED 2
4413 /* The value has not changed. */
4414 #define WP_VALUE_NOT_CHANGED 3
4415 /* Ignore this watchpoint, no matter if the value changed or not. */
4418 #define BP_TEMPFLAG 1
4419 #define BP_HARDWAREFLAG 2
4421 /* Evaluate watchpoint condition expression and check if its value
4424 P should be a pointer to struct bpstat, but is defined as a void *
4425 in order for this function to be usable with catch_errors. */
4428 watchpoint_check (void *p)
4430 bpstat bs = (bpstat) p;
4431 struct watchpoint *b;
4432 struct frame_info *fr;
4433 int within_current_scope;
4435 /* BS is built from an existing struct breakpoint. */
4436 gdb_assert (bs->breakpoint_at != NULL);
4437 b = (struct watchpoint *) bs->breakpoint_at;
4439 /* If this is a local watchpoint, we only want to check if the
4440 watchpoint frame is in scope if the current thread is the thread
4441 that was used to create the watchpoint. */
4442 if (!watchpoint_in_thread_scope (b))
4445 if (b->exp_valid_block == NULL)
4446 within_current_scope = 1;
4449 struct frame_info *frame = get_current_frame ();
4450 struct gdbarch *frame_arch = get_frame_arch (frame);
4451 CORE_ADDR frame_pc = get_frame_pc (frame);
4453 /* in_function_epilogue_p() returns a non-zero value if we're
4454 still in the function but the stack frame has already been
4455 invalidated. Since we can't rely on the values of local
4456 variables after the stack has been destroyed, we are treating
4457 the watchpoint in that state as `not changed' without further
4458 checking. Don't mark watchpoints as changed if the current
4459 frame is in an epilogue - even if they are in some other
4460 frame, our view of the stack is likely to be wrong and
4461 frame_find_by_id could error out. */
4462 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
4465 fr = frame_find_by_id (b->watchpoint_frame);
4466 within_current_scope = (fr != NULL);
4468 /* If we've gotten confused in the unwinder, we might have
4469 returned a frame that can't describe this variable. */
4470 if (within_current_scope)
4472 struct symbol *function;
4474 function = get_frame_function (fr);
4475 if (function == NULL
4476 || !contained_in (b->exp_valid_block,
4477 SYMBOL_BLOCK_VALUE (function)))
4478 within_current_scope = 0;
4481 if (within_current_scope)
4482 /* If we end up stopping, the current frame will get selected
4483 in normal_stop. So this call to select_frame won't affect
4488 if (within_current_scope)
4490 /* We use value_{,free_to_}mark because it could be a *long*
4491 time before we return to the command level and call
4492 free_all_values. We can't call free_all_values because we
4493 might be in the middle of evaluating a function call. */
4497 struct value *new_val;
4499 if (is_masked_watchpoint (&b->base))
4500 /* Since we don't know the exact trigger address (from
4501 stopped_data_address), just tell the user we've triggered
4502 a mask watchpoint. */
4503 return WP_VALUE_CHANGED;
4505 mark = value_mark ();
4506 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
4508 /* We use value_equal_contents instead of value_equal because
4509 the latter coerces an array to a pointer, thus comparing just
4510 the address of the array instead of its contents. This is
4511 not what we want. */
4512 if ((b->val != NULL) != (new_val != NULL)
4513 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
4515 if (new_val != NULL)
4517 release_value (new_val);
4518 value_free_to_mark (mark);
4520 bs->old_val = b->val;
4523 return WP_VALUE_CHANGED;
4527 /* Nothing changed. */
4528 value_free_to_mark (mark);
4529 return WP_VALUE_NOT_CHANGED;
4534 struct ui_out *uiout = current_uiout;
4536 /* This seems like the only logical thing to do because
4537 if we temporarily ignored the watchpoint, then when
4538 we reenter the block in which it is valid it contains
4539 garbage (in the case of a function, it may have two
4540 garbage values, one before and one after the prologue).
4541 So we can't even detect the first assignment to it and
4542 watch after that (since the garbage may or may not equal
4543 the first value assigned). */
4544 /* We print all the stop information in
4545 breakpoint_ops->print_it, but in this case, by the time we
4546 call breakpoint_ops->print_it this bp will be deleted
4547 already. So we have no choice but print the information
4549 if (ui_out_is_mi_like_p (uiout))
4551 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
4552 ui_out_text (uiout, "\nWatchpoint ");
4553 ui_out_field_int (uiout, "wpnum", b->base.number);
4555 " deleted because the program has left the block in\n\
4556 which its expression is valid.\n");
4558 /* Make sure the watchpoint's commands aren't executed. */
4559 decref_counted_command_line (&b->base.commands);
4560 watchpoint_del_at_next_stop (b);
4566 /* Return true if it looks like target has stopped due to hitting
4567 breakpoint location BL. This function does not check if we should
4568 stop, only if BL explains the stop. */
4571 bpstat_check_location (const struct bp_location *bl,
4572 struct address_space *aspace, CORE_ADDR bp_addr,
4573 const struct target_waitstatus *ws)
4575 struct breakpoint *b = bl->owner;
4577 /* BL is from an existing breakpoint. */
4578 gdb_assert (b != NULL);
4580 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
4583 /* Determine if the watched values have actually changed, and we
4584 should stop. If not, set BS->stop to 0. */
4587 bpstat_check_watchpoint (bpstat bs)
4589 const struct bp_location *bl;
4590 struct watchpoint *b;
4592 /* BS is built for existing struct breakpoint. */
4593 bl = bs->bp_location_at;
4594 gdb_assert (bl != NULL);
4595 b = (struct watchpoint *) bs->breakpoint_at;
4596 gdb_assert (b != NULL);
4599 int must_check_value = 0;
4601 if (b->base.type == bp_watchpoint)
4602 /* For a software watchpoint, we must always check the
4604 must_check_value = 1;
4605 else if (b->watchpoint_triggered == watch_triggered_yes)
4606 /* We have a hardware watchpoint (read, write, or access)
4607 and the target earlier reported an address watched by
4609 must_check_value = 1;
4610 else if (b->watchpoint_triggered == watch_triggered_unknown
4611 && b->base.type == bp_hardware_watchpoint)
4612 /* We were stopped by a hardware watchpoint, but the target could
4613 not report the data address. We must check the watchpoint's
4614 value. Access and read watchpoints are out of luck; without
4615 a data address, we can't figure it out. */
4616 must_check_value = 1;
4618 if (must_check_value)
4621 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4623 struct cleanup *cleanups = make_cleanup (xfree, message);
4624 int e = catch_errors (watchpoint_check, bs, message,
4626 do_cleanups (cleanups);
4630 /* We've already printed what needs to be printed. */
4631 bs->print_it = print_it_done;
4635 bs->print_it = print_it_noop;
4638 case WP_VALUE_CHANGED:
4639 if (b->base.type == bp_read_watchpoint)
4641 /* There are two cases to consider here:
4643 1. We're watching the triggered memory for reads.
4644 In that case, trust the target, and always report
4645 the watchpoint hit to the user. Even though
4646 reads don't cause value changes, the value may
4647 have changed since the last time it was read, and
4648 since we're not trapping writes, we will not see
4649 those, and as such we should ignore our notion of
4652 2. We're watching the triggered memory for both
4653 reads and writes. There are two ways this may
4656 2.1. This is a target that can't break on data
4657 reads only, but can break on accesses (reads or
4658 writes), such as e.g., x86. We detect this case
4659 at the time we try to insert read watchpoints.
4661 2.2. Otherwise, the target supports read
4662 watchpoints, but, the user set an access or write
4663 watchpoint watching the same memory as this read
4666 If we're watching memory writes as well as reads,
4667 ignore watchpoint hits when we find that the
4668 value hasn't changed, as reads don't cause
4669 changes. This still gives false positives when
4670 the program writes the same value to memory as
4671 what there was already in memory (we will confuse
4672 it for a read), but it's much better than
4675 int other_write_watchpoint = 0;
4677 if (bl->watchpoint_type == hw_read)
4679 struct breakpoint *other_b;
4681 ALL_BREAKPOINTS (other_b)
4682 if (other_b->type == bp_hardware_watchpoint
4683 || other_b->type == bp_access_watchpoint)
4685 struct watchpoint *other_w =
4686 (struct watchpoint *) other_b;
4688 if (other_w->watchpoint_triggered
4689 == watch_triggered_yes)
4691 other_write_watchpoint = 1;
4697 if (other_write_watchpoint
4698 || bl->watchpoint_type == hw_access)
4700 /* We're watching the same memory for writes,
4701 and the value changed since the last time we
4702 updated it, so this trap must be for a write.
4704 bs->print_it = print_it_noop;
4709 case WP_VALUE_NOT_CHANGED:
4710 if (b->base.type == bp_hardware_watchpoint
4711 || b->base.type == bp_watchpoint)
4713 /* Don't stop: write watchpoints shouldn't fire if
4714 the value hasn't changed. */
4715 bs->print_it = print_it_noop;
4723 /* Error from catch_errors. */
4724 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
4725 watchpoint_del_at_next_stop (b);
4726 /* We've already printed what needs to be printed. */
4727 bs->print_it = print_it_done;
4731 else /* must_check_value == 0 */
4733 /* This is a case where some watchpoint(s) triggered, but
4734 not at the address of this watchpoint, or else no
4735 watchpoint triggered after all. So don't print
4736 anything for this watchpoint. */
4737 bs->print_it = print_it_noop;
4744 /* Check conditions (condition proper, frame, thread and ignore count)
4745 of breakpoint referred to by BS. If we should not stop for this
4746 breakpoint, set BS->stop to 0. */
4749 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
4751 int thread_id = pid_to_thread_id (ptid);
4752 const struct bp_location *bl;
4753 struct breakpoint *b;
4755 /* BS is built for existing struct breakpoint. */
4756 bl = bs->bp_location_at;
4757 gdb_assert (bl != NULL);
4758 b = bs->breakpoint_at;
4759 gdb_assert (b != NULL);
4761 /* Even if the target evaluated the condition on its end and notified GDB, we
4762 need to do so again since GDB does not know if we stopped due to a
4763 breakpoint or a single step breakpoint. */
4765 if (frame_id_p (b->frame_id)
4766 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
4770 int value_is_zero = 0;
4771 struct expression *cond;
4773 /* Evaluate Python breakpoints that have a "stop"
4774 method implemented. */
4775 if (b->py_bp_object)
4776 bs->stop = gdbpy_should_stop (b->py_bp_object);
4778 if (is_watchpoint (b))
4780 struct watchpoint *w = (struct watchpoint *) b;
4787 if (cond && b->disposition != disp_del_at_next_stop)
4789 int within_current_scope = 1;
4790 struct watchpoint * w;
4792 /* We use value_mark and value_free_to_mark because it could
4793 be a long time before we return to the command level and
4794 call free_all_values. We can't call free_all_values
4795 because we might be in the middle of evaluating a
4797 struct value *mark = value_mark ();
4799 if (is_watchpoint (b))
4800 w = (struct watchpoint *) b;
4804 /* Need to select the frame, with all that implies so that
4805 the conditions will have the right context. Because we
4806 use the frame, we will not see an inlined function's
4807 variables when we arrive at a breakpoint at the start
4808 of the inlined function; the current frame will be the
4810 if (w == NULL || w->cond_exp_valid_block == NULL)
4811 select_frame (get_current_frame ());
4814 struct frame_info *frame;
4816 /* For local watchpoint expressions, which particular
4817 instance of a local is being watched matters, so we
4818 keep track of the frame to evaluate the expression
4819 in. To evaluate the condition however, it doesn't
4820 really matter which instantiation of the function
4821 where the condition makes sense triggers the
4822 watchpoint. This allows an expression like "watch
4823 global if q > 10" set in `func', catch writes to
4824 global on all threads that call `func', or catch
4825 writes on all recursive calls of `func' by a single
4826 thread. We simply always evaluate the condition in
4827 the innermost frame that's executing where it makes
4828 sense to evaluate the condition. It seems
4830 frame = block_innermost_frame (w->cond_exp_valid_block);
4832 select_frame (frame);
4834 within_current_scope = 0;
4836 if (within_current_scope)
4838 = catch_errors (breakpoint_cond_eval, cond,
4839 "Error in testing breakpoint condition:\n",
4843 warning (_("Watchpoint condition cannot be tested "
4844 "in the current scope"));
4845 /* If we failed to set the right context for this
4846 watchpoint, unconditionally report it. */
4849 /* FIXME-someday, should give breakpoint #. */
4850 value_free_to_mark (mark);
4853 if (cond && value_is_zero)
4857 else if (b->thread != -1 && b->thread != thread_id)
4861 else if (b->ignore_count > 0)
4864 annotate_ignore_count_change ();
4866 /* Increase the hit count even though we don't stop. */
4868 observer_notify_breakpoint_modified (b);
4874 /* Get a bpstat associated with having just stopped at address
4875 BP_ADDR in thread PTID.
4877 Determine whether we stopped at a breakpoint, etc, or whether we
4878 don't understand this stop. Result is a chain of bpstat's such
4881 if we don't understand the stop, the result is a null pointer.
4883 if we understand why we stopped, the result is not null.
4885 Each element of the chain refers to a particular breakpoint or
4886 watchpoint at which we have stopped. (We may have stopped for
4887 several reasons concurrently.)
4889 Each element of the chain has valid next, breakpoint_at,
4890 commands, FIXME??? fields. */
4893 bpstat_stop_status (struct address_space *aspace,
4894 CORE_ADDR bp_addr, ptid_t ptid,
4895 const struct target_waitstatus *ws)
4897 struct breakpoint *b = NULL;
4898 struct bp_location *bl;
4899 struct bp_location *loc;
4900 /* First item of allocated bpstat's. */
4901 bpstat bs_head = NULL, *bs_link = &bs_head;
4902 /* Pointer to the last thing in the chain currently. */
4905 int need_remove_insert;
4908 /* First, build the bpstat chain with locations that explain a
4909 target stop, while being careful to not set the target running,
4910 as that may invalidate locations (in particular watchpoint
4911 locations are recreated). Resuming will happen here with
4912 breakpoint conditions or watchpoint expressions that include
4913 inferior function calls. */
4917 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
4920 for (bl = b->loc; bl != NULL; bl = bl->next)
4922 /* For hardware watchpoints, we look only at the first
4923 location. The watchpoint_check function will work on the
4924 entire expression, not the individual locations. For
4925 read watchpoints, the watchpoints_triggered function has
4926 checked all locations already. */
4927 if (b->type == bp_hardware_watchpoint && bl != b->loc)
4930 if (bl->shlib_disabled)
4933 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
4936 /* Come here if it's a watchpoint, or if the break address
4939 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
4942 /* Assume we stop. Should we find a watchpoint that is not
4943 actually triggered, or if the condition of the breakpoint
4944 evaluates as false, we'll reset 'stop' to 0. */
4948 /* If this is a scope breakpoint, mark the associated
4949 watchpoint as triggered so that we will handle the
4950 out-of-scope event. We'll get to the watchpoint next
4952 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
4954 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
4956 w->watchpoint_triggered = watch_triggered_yes;
4961 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4963 if (breakpoint_location_address_match (loc, aspace, bp_addr))
4965 bs = bpstat_alloc (loc, &bs_link);
4966 /* For hits of moribund locations, we should just proceed. */
4969 bs->print_it = print_it_noop;
4973 /* A bit of special processing for shlib breakpoints. We need to
4974 process solib loading here, so that the lists of loaded and
4975 unloaded libraries are correct before we handle "catch load" and
4977 for (bs = bs_head; bs != NULL; bs = bs->next)
4979 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
4981 handle_solib_event ();
4986 /* Now go through the locations that caused the target to stop, and
4987 check whether we're interested in reporting this stop to higher
4988 layers, or whether we should resume the target transparently. */
4992 for (bs = bs_head; bs != NULL; bs = bs->next)
4997 b = bs->breakpoint_at;
4998 b->ops->check_status (bs);
5001 bpstat_check_breakpoint_conditions (bs, ptid);
5006 observer_notify_breakpoint_modified (b);
5008 /* We will stop here. */
5009 if (b->disposition == disp_disable)
5011 --(b->enable_count);
5012 if (b->enable_count <= 0
5013 && b->enable_state != bp_permanent)
5014 b->enable_state = bp_disabled;
5019 bs->commands = b->commands;
5020 incref_counted_command_line (bs->commands);
5021 if (command_line_is_silent (bs->commands
5022 ? bs->commands->commands : NULL))
5028 /* Print nothing for this entry if we don't stop or don't
5030 if (!bs->stop || !bs->print)
5031 bs->print_it = print_it_noop;
5034 /* If we aren't stopping, the value of some hardware watchpoint may
5035 not have changed, but the intermediate memory locations we are
5036 watching may have. Don't bother if we're stopping; this will get
5038 need_remove_insert = 0;
5039 if (! bpstat_causes_stop (bs_head))
5040 for (bs = bs_head; bs != NULL; bs = bs->next)
5042 && bs->breakpoint_at
5043 && is_hardware_watchpoint (bs->breakpoint_at))
5045 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5047 update_watchpoint (w, 0 /* don't reparse. */);
5048 need_remove_insert = 1;
5051 if (need_remove_insert)
5052 update_global_location_list (1);
5053 else if (removed_any)
5054 update_global_location_list (0);
5060 handle_jit_event (void)
5062 struct frame_info *frame;
5063 struct gdbarch *gdbarch;
5065 /* Switch terminal for any messages produced by
5066 breakpoint_re_set. */
5067 target_terminal_ours_for_output ();
5069 frame = get_current_frame ();
5070 gdbarch = get_frame_arch (frame);
5072 jit_event_handler (gdbarch);
5074 target_terminal_inferior ();
5077 /* Handle an solib event by calling solib_add. */
5080 handle_solib_event (void)
5082 clear_program_space_solib_cache (current_inferior ()->pspace);
5084 /* Check for any newly added shared libraries if we're supposed to
5085 be adding them automatically. Switch terminal for any messages
5086 produced by breakpoint_re_set. */
5087 target_terminal_ours_for_output ();
5089 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
5091 solib_add (NULL, 0, ¤t_target, auto_solib_add);
5093 target_terminal_inferior ();
5096 /* Prepare WHAT final decision for infrun. */
5098 /* Decide what infrun needs to do with this bpstat. */
5101 bpstat_what (bpstat bs_head)
5103 struct bpstat_what retval;
5107 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5108 retval.call_dummy = STOP_NONE;
5109 retval.is_longjmp = 0;
5111 for (bs = bs_head; bs != NULL; bs = bs->next)
5113 /* Extract this BS's action. After processing each BS, we check
5114 if its action overrides all we've seem so far. */
5115 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5118 if (bs->breakpoint_at == NULL)
5120 /* I suspect this can happen if it was a momentary
5121 breakpoint which has since been deleted. */
5125 bptype = bs->breakpoint_at->type;
5132 case bp_hardware_breakpoint:
5135 case bp_shlib_event:
5139 this_action = BPSTAT_WHAT_STOP_NOISY;
5141 this_action = BPSTAT_WHAT_STOP_SILENT;
5144 this_action = BPSTAT_WHAT_SINGLE;
5147 case bp_hardware_watchpoint:
5148 case bp_read_watchpoint:
5149 case bp_access_watchpoint:
5153 this_action = BPSTAT_WHAT_STOP_NOISY;
5155 this_action = BPSTAT_WHAT_STOP_SILENT;
5159 /* There was a watchpoint, but we're not stopping.
5160 This requires no further action. */
5164 case bp_longjmp_call_dummy:
5166 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5167 retval.is_longjmp = bptype != bp_exception;
5169 case bp_longjmp_resume:
5170 case bp_exception_resume:
5171 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5172 retval.is_longjmp = bptype == bp_longjmp_resume;
5174 case bp_step_resume:
5176 this_action = BPSTAT_WHAT_STEP_RESUME;
5179 /* It is for the wrong frame. */
5180 this_action = BPSTAT_WHAT_SINGLE;
5183 case bp_hp_step_resume:
5185 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5188 /* It is for the wrong frame. */
5189 this_action = BPSTAT_WHAT_SINGLE;
5192 case bp_watchpoint_scope:
5193 case bp_thread_event:
5194 case bp_overlay_event:
5195 case bp_longjmp_master:
5196 case bp_std_terminate_master:
5197 case bp_exception_master:
5198 this_action = BPSTAT_WHAT_SINGLE;
5204 this_action = BPSTAT_WHAT_STOP_NOISY;
5206 this_action = BPSTAT_WHAT_STOP_SILENT;
5210 /* There was a catchpoint, but we're not stopping.
5211 This requires no further action. */
5216 this_action = BPSTAT_WHAT_SINGLE;
5219 /* Make sure the action is stop (silent or noisy),
5220 so infrun.c pops the dummy frame. */
5221 retval.call_dummy = STOP_STACK_DUMMY;
5222 this_action = BPSTAT_WHAT_STOP_SILENT;
5224 case bp_std_terminate:
5225 /* Make sure the action is stop (silent or noisy),
5226 so infrun.c pops the dummy frame. */
5227 retval.call_dummy = STOP_STD_TERMINATE;
5228 this_action = BPSTAT_WHAT_STOP_SILENT;
5231 case bp_fast_tracepoint:
5232 case bp_static_tracepoint:
5233 /* Tracepoint hits should not be reported back to GDB, and
5234 if one got through somehow, it should have been filtered
5236 internal_error (__FILE__, __LINE__,
5237 _("bpstat_what: tracepoint encountered"));
5239 case bp_gnu_ifunc_resolver:
5240 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5241 this_action = BPSTAT_WHAT_SINGLE;
5243 case bp_gnu_ifunc_resolver_return:
5244 /* The breakpoint will be removed, execution will restart from the
5245 PC of the former breakpoint. */
5246 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5250 this_action = BPSTAT_WHAT_STOP_SILENT;
5254 internal_error (__FILE__, __LINE__,
5255 _("bpstat_what: unhandled bptype %d"), (int) bptype);
5258 retval.main_action = max (retval.main_action, this_action);
5261 /* These operations may affect the bs->breakpoint_at state so they are
5262 delayed after MAIN_ACTION is decided above. */
5267 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
5269 handle_jit_event ();
5272 for (bs = bs_head; bs != NULL; bs = bs->next)
5274 struct breakpoint *b = bs->breakpoint_at;
5280 case bp_gnu_ifunc_resolver:
5281 gnu_ifunc_resolver_stop (b);
5283 case bp_gnu_ifunc_resolver_return:
5284 gnu_ifunc_resolver_return_stop (b);
5292 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5293 without hardware support). This isn't related to a specific bpstat,
5294 just to things like whether watchpoints are set. */
5297 bpstat_should_step (void)
5299 struct breakpoint *b;
5302 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
5308 bpstat_causes_stop (bpstat bs)
5310 for (; bs != NULL; bs = bs->next)
5319 /* Compute a string of spaces suitable to indent the next line
5320 so it starts at the position corresponding to the table column
5321 named COL_NAME in the currently active table of UIOUT. */
5324 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5326 static char wrap_indent[80];
5327 int i, total_width, width, align;
5331 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
5333 if (strcmp (text, col_name) == 0)
5335 gdb_assert (total_width < sizeof wrap_indent);
5336 memset (wrap_indent, ' ', total_width);
5337 wrap_indent[total_width] = 0;
5342 total_width += width + 1;
5348 /* Determine if the locations of this breakpoint will have their conditions
5349 evaluated by the target, host or a mix of both. Returns the following:
5351 "host": Host evals condition.
5352 "host or target": Host or Target evals condition.
5353 "target": Target evals condition.
5357 bp_condition_evaluator (struct breakpoint *b)
5359 struct bp_location *bl;
5360 char host_evals = 0;
5361 char target_evals = 0;
5366 if (!is_breakpoint (b))
5369 if (gdb_evaluates_breakpoint_condition_p ()
5370 || !target_supports_evaluation_of_breakpoint_conditions ())
5371 return condition_evaluation_host;
5373 for (bl = b->loc; bl; bl = bl->next)
5375 if (bl->cond_bytecode)
5381 if (host_evals && target_evals)
5382 return condition_evaluation_both;
5383 else if (target_evals)
5384 return condition_evaluation_target;
5386 return condition_evaluation_host;
5389 /* Determine the breakpoint location's condition evaluator. This is
5390 similar to bp_condition_evaluator, but for locations. */
5393 bp_location_condition_evaluator (struct bp_location *bl)
5395 if (bl && !is_breakpoint (bl->owner))
5398 if (gdb_evaluates_breakpoint_condition_p ()
5399 || !target_supports_evaluation_of_breakpoint_conditions ())
5400 return condition_evaluation_host;
5402 if (bl && bl->cond_bytecode)
5403 return condition_evaluation_target;
5405 return condition_evaluation_host;
5408 /* Print the LOC location out of the list of B->LOC locations. */
5411 print_breakpoint_location (struct breakpoint *b,
5412 struct bp_location *loc)
5414 struct ui_out *uiout = current_uiout;
5415 struct cleanup *old_chain = save_current_program_space ();
5417 if (loc != NULL && loc->shlib_disabled)
5421 set_current_program_space (loc->pspace);
5423 if (b->display_canonical)
5424 ui_out_field_string (uiout, "what", b->addr_string);
5425 else if (loc && loc->source_file)
5428 = find_pc_sect_function (loc->address, loc->section);
5431 ui_out_text (uiout, "in ");
5432 ui_out_field_string (uiout, "func",
5433 SYMBOL_PRINT_NAME (sym));
5434 ui_out_text (uiout, " ");
5435 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
5436 ui_out_text (uiout, "at ");
5438 ui_out_field_string (uiout, "file", loc->source_file);
5439 ui_out_text (uiout, ":");
5441 if (ui_out_is_mi_like_p (uiout))
5443 struct symtab_and_line sal = find_pc_line (loc->address, 0);
5444 char *fullname = symtab_to_fullname (sal.symtab);
5447 ui_out_field_string (uiout, "fullname", fullname);
5450 ui_out_field_int (uiout, "line", loc->line_number);
5454 struct ui_file *stb = mem_fileopen ();
5455 struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
5457 print_address_symbolic (loc->gdbarch, loc->address, stb,
5459 ui_out_field_stream (uiout, "at", stb);
5461 do_cleanups (stb_chain);
5464 ui_out_field_string (uiout, "pending", b->addr_string);
5466 if (loc && is_breakpoint (b)
5467 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5468 && bp_condition_evaluator (b) == condition_evaluation_both)
5470 ui_out_text (uiout, " (");
5471 ui_out_field_string (uiout, "evaluated-by",
5472 bp_location_condition_evaluator (loc));
5473 ui_out_text (uiout, ")");
5476 do_cleanups (old_chain);
5480 bptype_string (enum bptype type)
5482 struct ep_type_description
5487 static struct ep_type_description bptypes[] =
5489 {bp_none, "?deleted?"},
5490 {bp_breakpoint, "breakpoint"},
5491 {bp_hardware_breakpoint, "hw breakpoint"},
5492 {bp_until, "until"},
5493 {bp_finish, "finish"},
5494 {bp_watchpoint, "watchpoint"},
5495 {bp_hardware_watchpoint, "hw watchpoint"},
5496 {bp_read_watchpoint, "read watchpoint"},
5497 {bp_access_watchpoint, "acc watchpoint"},
5498 {bp_longjmp, "longjmp"},
5499 {bp_longjmp_resume, "longjmp resume"},
5500 {bp_longjmp_call_dummy, "longjmp for call dummy"},
5501 {bp_exception, "exception"},
5502 {bp_exception_resume, "exception resume"},
5503 {bp_step_resume, "step resume"},
5504 {bp_hp_step_resume, "high-priority step resume"},
5505 {bp_watchpoint_scope, "watchpoint scope"},
5506 {bp_call_dummy, "call dummy"},
5507 {bp_std_terminate, "std::terminate"},
5508 {bp_shlib_event, "shlib events"},
5509 {bp_thread_event, "thread events"},
5510 {bp_overlay_event, "overlay events"},
5511 {bp_longjmp_master, "longjmp master"},
5512 {bp_std_terminate_master, "std::terminate master"},
5513 {bp_exception_master, "exception master"},
5514 {bp_catchpoint, "catchpoint"},
5515 {bp_tracepoint, "tracepoint"},
5516 {bp_fast_tracepoint, "fast tracepoint"},
5517 {bp_static_tracepoint, "static tracepoint"},
5518 {bp_dprintf, "dprintf"},
5519 {bp_jit_event, "jit events"},
5520 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
5521 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
5524 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
5525 || ((int) type != bptypes[(int) type].type))
5526 internal_error (__FILE__, __LINE__,
5527 _("bptypes table does not describe type #%d."),
5530 return bptypes[(int) type].description;
5533 /* Print B to gdb_stdout. */
5536 print_one_breakpoint_location (struct breakpoint *b,
5537 struct bp_location *loc,
5539 struct bp_location **last_loc,
5542 struct command_line *l;
5543 static char bpenables[] = "nynny";
5545 struct ui_out *uiout = current_uiout;
5546 int header_of_multiple = 0;
5547 int part_of_multiple = (loc != NULL);
5548 struct value_print_options opts;
5550 get_user_print_options (&opts);
5552 gdb_assert (!loc || loc_number != 0);
5553 /* See comment in print_one_breakpoint concerning treatment of
5554 breakpoints with single disabled location. */
5557 && (b->loc->next != NULL || !b->loc->enabled)))
5558 header_of_multiple = 1;
5566 if (part_of_multiple)
5569 formatted = xstrprintf ("%d.%d", b->number, loc_number);
5570 ui_out_field_string (uiout, "number", formatted);
5575 ui_out_field_int (uiout, "number", b->number);
5580 if (part_of_multiple)
5581 ui_out_field_skip (uiout, "type");
5583 ui_out_field_string (uiout, "type", bptype_string (b->type));
5587 if (part_of_multiple)
5588 ui_out_field_skip (uiout, "disp");
5590 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
5595 if (part_of_multiple)
5596 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
5598 ui_out_field_fmt (uiout, "enabled", "%c",
5599 bpenables[(int) b->enable_state]);
5600 ui_out_spaces (uiout, 2);
5604 if (b->ops != NULL && b->ops->print_one != NULL)
5606 /* Although the print_one can possibly print all locations,
5607 calling it here is not likely to get any nice result. So,
5608 make sure there's just one location. */
5609 gdb_assert (b->loc == NULL || b->loc->next == NULL);
5610 b->ops->print_one (b, last_loc);
5616 internal_error (__FILE__, __LINE__,
5617 _("print_one_breakpoint: bp_none encountered\n"));
5621 case bp_hardware_watchpoint:
5622 case bp_read_watchpoint:
5623 case bp_access_watchpoint:
5625 struct watchpoint *w = (struct watchpoint *) b;
5627 /* Field 4, the address, is omitted (which makes the columns
5628 not line up too nicely with the headers, but the effect
5629 is relatively readable). */
5630 if (opts.addressprint)
5631 ui_out_field_skip (uiout, "addr");
5633 ui_out_field_string (uiout, "what", w->exp_string);
5638 case bp_hardware_breakpoint:
5642 case bp_longjmp_resume:
5643 case bp_longjmp_call_dummy:
5645 case bp_exception_resume:
5646 case bp_step_resume:
5647 case bp_hp_step_resume:
5648 case bp_watchpoint_scope:
5650 case bp_std_terminate:
5651 case bp_shlib_event:
5652 case bp_thread_event:
5653 case bp_overlay_event:
5654 case bp_longjmp_master:
5655 case bp_std_terminate_master:
5656 case bp_exception_master:
5658 case bp_fast_tracepoint:
5659 case bp_static_tracepoint:
5662 case bp_gnu_ifunc_resolver:
5663 case bp_gnu_ifunc_resolver_return:
5664 if (opts.addressprint)
5667 if (header_of_multiple)
5668 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
5669 else if (b->loc == NULL || loc->shlib_disabled)
5670 ui_out_field_string (uiout, "addr", "<PENDING>");
5672 ui_out_field_core_addr (uiout, "addr",
5673 loc->gdbarch, loc->address);
5676 if (!header_of_multiple)
5677 print_breakpoint_location (b, loc);
5684 /* For backward compatibility, don't display inferiors unless there
5687 && !header_of_multiple
5689 || (!gdbarch_has_global_breakpoints (target_gdbarch)
5690 && (number_of_program_spaces () > 1
5691 || number_of_inferiors () > 1)
5692 /* LOC is for existing B, it cannot be in
5693 moribund_locations and thus having NULL OWNER. */
5694 && loc->owner->type != bp_catchpoint)))
5696 struct inferior *inf;
5699 for (inf = inferior_list; inf != NULL; inf = inf->next)
5701 if (inf->pspace == loc->pspace)
5706 ui_out_text (uiout, " inf ");
5709 ui_out_text (uiout, ", ");
5710 ui_out_text (uiout, plongest (inf->num));
5715 if (!part_of_multiple)
5717 if (b->thread != -1)
5719 /* FIXME: This seems to be redundant and lost here; see the
5720 "stop only in" line a little further down. */
5721 ui_out_text (uiout, " thread ");
5722 ui_out_field_int (uiout, "thread", b->thread);
5724 else if (b->task != 0)
5726 ui_out_text (uiout, " task ");
5727 ui_out_field_int (uiout, "task", b->task);
5731 ui_out_text (uiout, "\n");
5733 if (!part_of_multiple)
5734 b->ops->print_one_detail (b, uiout);
5736 if (part_of_multiple && frame_id_p (b->frame_id))
5739 ui_out_text (uiout, "\tstop only in stack frame at ");
5740 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
5742 ui_out_field_core_addr (uiout, "frame",
5743 b->gdbarch, b->frame_id.stack_addr);
5744 ui_out_text (uiout, "\n");
5747 if (!part_of_multiple && b->cond_string)
5750 if (is_tracepoint (b))
5751 ui_out_text (uiout, "\ttrace only if ");
5753 ui_out_text (uiout, "\tstop only if ");
5754 ui_out_field_string (uiout, "cond", b->cond_string);
5756 /* Print whether the target is doing the breakpoint's condition
5757 evaluation. If GDB is doing the evaluation, don't print anything. */
5758 if (is_breakpoint (b)
5759 && breakpoint_condition_evaluation_mode ()
5760 == condition_evaluation_target)
5762 ui_out_text (uiout, " (");
5763 ui_out_field_string (uiout, "evaluated-by",
5764 bp_condition_evaluator (b));
5765 ui_out_text (uiout, " evals)");
5767 ui_out_text (uiout, "\n");
5770 if (!part_of_multiple && b->thread != -1)
5772 /* FIXME should make an annotation for this. */
5773 ui_out_text (uiout, "\tstop only in thread ");
5774 ui_out_field_int (uiout, "thread", b->thread);
5775 ui_out_text (uiout, "\n");
5778 if (!part_of_multiple && b->hit_count)
5780 /* FIXME should make an annotation for this. */
5781 if (is_catchpoint (b))
5782 ui_out_text (uiout, "\tcatchpoint");
5783 else if (is_tracepoint (b))
5784 ui_out_text (uiout, "\ttracepoint");
5786 ui_out_text (uiout, "\tbreakpoint");
5787 ui_out_text (uiout, " already hit ");
5788 ui_out_field_int (uiout, "times", b->hit_count);
5789 if (b->hit_count == 1)
5790 ui_out_text (uiout, " time\n");
5792 ui_out_text (uiout, " times\n");
5795 /* Output the count also if it is zero, but only if this is mi.
5796 FIXME: Should have a better test for this. */
5797 if (ui_out_is_mi_like_p (uiout))
5798 if (!part_of_multiple && b->hit_count == 0)
5799 ui_out_field_int (uiout, "times", b->hit_count);
5801 if (!part_of_multiple && b->ignore_count)
5804 ui_out_text (uiout, "\tignore next ");
5805 ui_out_field_int (uiout, "ignore", b->ignore_count);
5806 ui_out_text (uiout, " hits\n");
5809 /* Note that an enable count of 1 corresponds to "enable once"
5810 behavior, which is reported by the combination of enablement and
5811 disposition, so we don't need to mention it here. */
5812 if (!part_of_multiple && b->enable_count > 1)
5815 ui_out_text (uiout, "\tdisable after ");
5816 /* Tweak the wording to clarify that ignore and enable counts
5817 are distinct, and have additive effect. */
5818 if (b->ignore_count)
5819 ui_out_text (uiout, "additional ");
5821 ui_out_text (uiout, "next ");
5822 ui_out_field_int (uiout, "enable", b->enable_count);
5823 ui_out_text (uiout, " hits\n");
5826 if (!part_of_multiple && is_tracepoint (b))
5828 struct tracepoint *tp = (struct tracepoint *) b;
5830 if (tp->traceframe_usage)
5832 ui_out_text (uiout, "\ttrace buffer usage ");
5833 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
5834 ui_out_text (uiout, " bytes\n");
5838 l = b->commands ? b->commands->commands : NULL;
5839 if (!part_of_multiple && l)
5841 struct cleanup *script_chain;
5844 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
5845 print_command_lines (uiout, l, 4);
5846 do_cleanups (script_chain);
5849 if (is_tracepoint (b))
5851 struct tracepoint *t = (struct tracepoint *) b;
5853 if (!part_of_multiple && t->pass_count)
5855 annotate_field (10);
5856 ui_out_text (uiout, "\tpass count ");
5857 ui_out_field_int (uiout, "pass", t->pass_count);
5858 ui_out_text (uiout, " \n");
5862 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
5864 if (is_watchpoint (b))
5866 struct watchpoint *w = (struct watchpoint *) b;
5868 ui_out_field_string (uiout, "original-location", w->exp_string);
5870 else if (b->addr_string)
5871 ui_out_field_string (uiout, "original-location", b->addr_string);
5876 print_one_breakpoint (struct breakpoint *b,
5877 struct bp_location **last_loc,
5880 struct cleanup *bkpt_chain;
5881 struct ui_out *uiout = current_uiout;
5883 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
5885 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
5886 do_cleanups (bkpt_chain);
5888 /* If this breakpoint has custom print function,
5889 it's already printed. Otherwise, print individual
5890 locations, if any. */
5891 if (b->ops == NULL || b->ops->print_one == NULL)
5893 /* If breakpoint has a single location that is disabled, we
5894 print it as if it had several locations, since otherwise it's
5895 hard to represent "breakpoint enabled, location disabled"
5898 Note that while hardware watchpoints have several locations
5899 internally, that's not a property exposed to user. */
5901 && !is_hardware_watchpoint (b)
5902 && (b->loc->next || !b->loc->enabled))
5904 struct bp_location *loc;
5907 for (loc = b->loc; loc; loc = loc->next, ++n)
5909 struct cleanup *inner2 =
5910 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
5911 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
5912 do_cleanups (inner2);
5919 breakpoint_address_bits (struct breakpoint *b)
5921 int print_address_bits = 0;
5922 struct bp_location *loc;
5924 for (loc = b->loc; loc; loc = loc->next)
5928 /* Software watchpoints that aren't watching memory don't have
5929 an address to print. */
5930 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
5933 addr_bit = gdbarch_addr_bit (loc->gdbarch);
5934 if (addr_bit > print_address_bits)
5935 print_address_bits = addr_bit;
5938 return print_address_bits;
5941 struct captured_breakpoint_query_args
5947 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
5949 struct captured_breakpoint_query_args *args = data;
5950 struct breakpoint *b;
5951 struct bp_location *dummy_loc = NULL;
5955 if (args->bnum == b->number)
5957 print_one_breakpoint (b, &dummy_loc, 0);
5965 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
5966 char **error_message)
5968 struct captured_breakpoint_query_args args;
5971 /* For the moment we don't trust print_one_breakpoint() to not throw
5973 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
5974 error_message, RETURN_MASK_ALL) < 0)
5980 /* Return true if this breakpoint was set by the user, false if it is
5981 internal or momentary. */
5984 user_breakpoint_p (struct breakpoint *b)
5986 return b->number > 0;
5989 /* Print information on user settable breakpoint (watchpoint, etc)
5990 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5991 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5992 FILTER is non-NULL, call it on each breakpoint and only include the
5993 ones for which it returns non-zero. Return the total number of
5994 breakpoints listed. */
5997 breakpoint_1 (char *args, int allflag,
5998 int (*filter) (const struct breakpoint *))
6000 struct breakpoint *b;
6001 struct bp_location *last_loc = NULL;
6002 int nr_printable_breakpoints;
6003 struct cleanup *bkpttbl_chain;
6004 struct value_print_options opts;
6005 int print_address_bits = 0;
6006 int print_type_col_width = 14;
6007 struct ui_out *uiout = current_uiout;
6009 get_user_print_options (&opts);
6011 /* Compute the number of rows in the table, as well as the size
6012 required for address fields. */
6013 nr_printable_breakpoints = 0;
6016 /* If we have a filter, only list the breakpoints it accepts. */
6017 if (filter && !filter (b))
6020 /* If we have an "args" string, it is a list of breakpoints to
6021 accept. Skip the others. */
6022 if (args != NULL && *args != '\0')
6024 if (allflag && parse_and_eval_long (args) != b->number)
6026 if (!allflag && !number_is_in_list (args, b->number))
6030 if (allflag || user_breakpoint_p (b))
6032 int addr_bit, type_len;
6034 addr_bit = breakpoint_address_bits (b);
6035 if (addr_bit > print_address_bits)
6036 print_address_bits = addr_bit;
6038 type_len = strlen (bptype_string (b->type));
6039 if (type_len > print_type_col_width)
6040 print_type_col_width = type_len;
6042 nr_printable_breakpoints++;
6046 if (opts.addressprint)
6048 = make_cleanup_ui_out_table_begin_end (uiout, 6,
6049 nr_printable_breakpoints,
6053 = make_cleanup_ui_out_table_begin_end (uiout, 5,
6054 nr_printable_breakpoints,
6057 if (nr_printable_breakpoints > 0)
6058 annotate_breakpoints_headers ();
6059 if (nr_printable_breakpoints > 0)
6061 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
6062 if (nr_printable_breakpoints > 0)
6064 ui_out_table_header (uiout, print_type_col_width, ui_left,
6065 "type", "Type"); /* 2 */
6066 if (nr_printable_breakpoints > 0)
6068 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
6069 if (nr_printable_breakpoints > 0)
6071 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
6072 if (opts.addressprint)
6074 if (nr_printable_breakpoints > 0)
6076 if (print_address_bits <= 32)
6077 ui_out_table_header (uiout, 10, ui_left,
6078 "addr", "Address"); /* 5 */
6080 ui_out_table_header (uiout, 18, ui_left,
6081 "addr", "Address"); /* 5 */
6083 if (nr_printable_breakpoints > 0)
6085 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
6086 ui_out_table_body (uiout);
6087 if (nr_printable_breakpoints > 0)
6088 annotate_breakpoints_table ();
6093 /* If we have a filter, only list the breakpoints it accepts. */
6094 if (filter && !filter (b))
6097 /* If we have an "args" string, it is a list of breakpoints to
6098 accept. Skip the others. */
6100 if (args != NULL && *args != '\0')
6102 if (allflag) /* maintenance info breakpoint */
6104 if (parse_and_eval_long (args) != b->number)
6107 else /* all others */
6109 if (!number_is_in_list (args, b->number))
6113 /* We only print out user settable breakpoints unless the
6115 if (allflag || user_breakpoint_p (b))
6116 print_one_breakpoint (b, &last_loc, allflag);
6119 do_cleanups (bkpttbl_chain);
6121 if (nr_printable_breakpoints == 0)
6123 /* If there's a filter, let the caller decide how to report
6127 if (args == NULL || *args == '\0')
6128 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
6130 ui_out_message (uiout, 0,
6131 "No breakpoint or watchpoint matching '%s'.\n",
6137 if (last_loc && !server_command)
6138 set_next_address (last_loc->gdbarch, last_loc->address);
6141 /* FIXME? Should this be moved up so that it is only called when
6142 there have been breakpoints? */
6143 annotate_breakpoints_table_end ();
6145 return nr_printable_breakpoints;
6148 /* Display the value of default-collect in a way that is generally
6149 compatible with the breakpoint list. */
6152 default_collect_info (void)
6154 struct ui_out *uiout = current_uiout;
6156 /* If it has no value (which is frequently the case), say nothing; a
6157 message like "No default-collect." gets in user's face when it's
6159 if (!*default_collect)
6162 /* The following phrase lines up nicely with per-tracepoint collect
6164 ui_out_text (uiout, "default collect ");
6165 ui_out_field_string (uiout, "default-collect", default_collect);
6166 ui_out_text (uiout, " \n");
6170 breakpoints_info (char *args, int from_tty)
6172 breakpoint_1 (args, 0, NULL);
6174 default_collect_info ();
6178 watchpoints_info (char *args, int from_tty)
6180 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6181 struct ui_out *uiout = current_uiout;
6183 if (num_printed == 0)
6185 if (args == NULL || *args == '\0')
6186 ui_out_message (uiout, 0, "No watchpoints.\n");
6188 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
6193 maintenance_info_breakpoints (char *args, int from_tty)
6195 breakpoint_1 (args, 1, NULL);
6197 default_collect_info ();
6201 breakpoint_has_pc (struct breakpoint *b,
6202 struct program_space *pspace,
6203 CORE_ADDR pc, struct obj_section *section)
6205 struct bp_location *bl = b->loc;
6207 for (; bl; bl = bl->next)
6209 if (bl->pspace == pspace
6210 && bl->address == pc
6211 && (!overlay_debugging || bl->section == section))
6217 /* Print a message describing any user-breakpoints set at PC. This
6218 concerns with logical breakpoints, so we match program spaces, not
6222 describe_other_breakpoints (struct gdbarch *gdbarch,
6223 struct program_space *pspace, CORE_ADDR pc,
6224 struct obj_section *section, int thread)
6227 struct breakpoint *b;
6230 others += (user_breakpoint_p (b)
6231 && breakpoint_has_pc (b, pspace, pc, section));
6235 printf_filtered (_("Note: breakpoint "));
6236 else /* if (others == ???) */
6237 printf_filtered (_("Note: breakpoints "));
6239 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
6242 printf_filtered ("%d", b->number);
6243 if (b->thread == -1 && thread != -1)
6244 printf_filtered (" (all threads)");
6245 else if (b->thread != -1)
6246 printf_filtered (" (thread %d)", b->thread);
6247 printf_filtered ("%s%s ",
6248 ((b->enable_state == bp_disabled
6249 || b->enable_state == bp_call_disabled)
6251 : b->enable_state == bp_permanent
6255 : ((others == 1) ? " and" : ""));
6257 printf_filtered (_("also set at pc "));
6258 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
6259 printf_filtered (".\n");
6264 /* Return true iff it is meaningful to use the address member of
6265 BPT. For some breakpoint types, the address member is irrelevant
6266 and it makes no sense to attempt to compare it to other addresses
6267 (or use it for any other purpose either).
6269 More specifically, each of the following breakpoint types will
6270 always have a zero valued address and we don't want to mark
6271 breakpoints of any of these types to be a duplicate of an actual
6272 breakpoint at address zero:
6280 breakpoint_address_is_meaningful (struct breakpoint *bpt)
6282 enum bptype type = bpt->type;
6284 return (type != bp_watchpoint && type != bp_catchpoint);
6287 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6288 true if LOC1 and LOC2 represent the same watchpoint location. */
6291 watchpoint_locations_match (struct bp_location *loc1,
6292 struct bp_location *loc2)
6294 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6295 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6297 /* Both of them must exist. */
6298 gdb_assert (w1 != NULL);
6299 gdb_assert (w2 != NULL);
6301 /* If the target can evaluate the condition expression in hardware,
6302 then we we need to insert both watchpoints even if they are at
6303 the same place. Otherwise the watchpoint will only trigger when
6304 the condition of whichever watchpoint was inserted evaluates to
6305 true, not giving a chance for GDB to check the condition of the
6306 other watchpoint. */
6308 && target_can_accel_watchpoint_condition (loc1->address,
6310 loc1->watchpoint_type,
6313 && target_can_accel_watchpoint_condition (loc2->address,
6315 loc2->watchpoint_type,
6319 /* Note that this checks the owner's type, not the location's. In
6320 case the target does not support read watchpoints, but does
6321 support access watchpoints, we'll have bp_read_watchpoint
6322 watchpoints with hw_access locations. Those should be considered
6323 duplicates of hw_read locations. The hw_read locations will
6324 become hw_access locations later. */
6325 return (loc1->owner->type == loc2->owner->type
6326 && loc1->pspace->aspace == loc2->pspace->aspace
6327 && loc1->address == loc2->address
6328 && loc1->length == loc2->length);
6331 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6332 same breakpoint location. In most targets, this can only be true
6333 if ASPACE1 matches ASPACE2. On targets that have global
6334 breakpoints, the address space doesn't really matter. */
6337 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
6338 struct address_space *aspace2, CORE_ADDR addr2)
6340 return ((gdbarch_has_global_breakpoints (target_gdbarch)
6341 || aspace1 == aspace2)
6345 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6346 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6347 matches ASPACE2. On targets that have global breakpoints, the address
6348 space doesn't really matter. */
6351 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
6352 int len1, struct address_space *aspace2,
6355 return ((gdbarch_has_global_breakpoints (target_gdbarch)
6356 || aspace1 == aspace2)
6357 && addr2 >= addr1 && addr2 < addr1 + len1);
6360 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6361 a ranged breakpoint. In most targets, a match happens only if ASPACE
6362 matches the breakpoint's address space. On targets that have global
6363 breakpoints, the address space doesn't really matter. */
6366 breakpoint_location_address_match (struct bp_location *bl,
6367 struct address_space *aspace,
6370 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
6373 && breakpoint_address_match_range (bl->pspace->aspace,
6374 bl->address, bl->length,
6378 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6379 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6380 true, otherwise returns false. */
6383 tracepoint_locations_match (struct bp_location *loc1,
6384 struct bp_location *loc2)
6386 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
6387 /* Since tracepoint locations are never duplicated with others', tracepoint
6388 locations at the same address of different tracepoints are regarded as
6389 different locations. */
6390 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
6395 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6396 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6397 represent the same location. */
6400 breakpoint_locations_match (struct bp_location *loc1,
6401 struct bp_location *loc2)
6403 int hw_point1, hw_point2;
6405 /* Both of them must not be in moribund_locations. */
6406 gdb_assert (loc1->owner != NULL);
6407 gdb_assert (loc2->owner != NULL);
6409 hw_point1 = is_hardware_watchpoint (loc1->owner);
6410 hw_point2 = is_hardware_watchpoint (loc2->owner);
6412 if (hw_point1 != hw_point2)
6415 return watchpoint_locations_match (loc1, loc2);
6416 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
6417 return tracepoint_locations_match (loc1, loc2);
6419 /* We compare bp_location.length in order to cover ranged breakpoints. */
6420 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
6421 loc2->pspace->aspace, loc2->address)
6422 && loc1->length == loc2->length);
6426 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
6427 int bnum, int have_bnum)
6429 /* The longest string possibly returned by hex_string_custom
6430 is 50 chars. These must be at least that big for safety. */
6434 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
6435 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
6437 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6438 bnum, astr1, astr2);
6440 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
6443 /* Adjust a breakpoint's address to account for architectural
6444 constraints on breakpoint placement. Return the adjusted address.
6445 Note: Very few targets require this kind of adjustment. For most
6446 targets, this function is simply the identity function. */
6449 adjust_breakpoint_address (struct gdbarch *gdbarch,
6450 CORE_ADDR bpaddr, enum bptype bptype)
6452 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
6454 /* Very few targets need any kind of breakpoint adjustment. */
6457 else if (bptype == bp_watchpoint
6458 || bptype == bp_hardware_watchpoint
6459 || bptype == bp_read_watchpoint
6460 || bptype == bp_access_watchpoint
6461 || bptype == bp_catchpoint)
6463 /* Watchpoints and the various bp_catch_* eventpoints should not
6464 have their addresses modified. */
6469 CORE_ADDR adjusted_bpaddr;
6471 /* Some targets have architectural constraints on the placement
6472 of breakpoint instructions. Obtain the adjusted address. */
6473 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
6475 /* An adjusted breakpoint address can significantly alter
6476 a user's expectations. Print a warning if an adjustment
6478 if (adjusted_bpaddr != bpaddr)
6479 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
6481 return adjusted_bpaddr;
6486 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
6487 struct breakpoint *owner)
6489 memset (loc, 0, sizeof (*loc));
6491 gdb_assert (ops != NULL);
6496 loc->cond_bytecode = NULL;
6497 loc->shlib_disabled = 0;
6500 switch (owner->type)
6506 case bp_longjmp_resume:
6507 case bp_longjmp_call_dummy:
6509 case bp_exception_resume:
6510 case bp_step_resume:
6511 case bp_hp_step_resume:
6512 case bp_watchpoint_scope:
6514 case bp_std_terminate:
6515 case bp_shlib_event:
6516 case bp_thread_event:
6517 case bp_overlay_event:
6519 case bp_longjmp_master:
6520 case bp_std_terminate_master:
6521 case bp_exception_master:
6522 case bp_gnu_ifunc_resolver:
6523 case bp_gnu_ifunc_resolver_return:
6525 loc->loc_type = bp_loc_software_breakpoint;
6526 mark_breakpoint_location_modified (loc);
6528 case bp_hardware_breakpoint:
6529 loc->loc_type = bp_loc_hardware_breakpoint;
6530 mark_breakpoint_location_modified (loc);
6532 case bp_hardware_watchpoint:
6533 case bp_read_watchpoint:
6534 case bp_access_watchpoint:
6535 loc->loc_type = bp_loc_hardware_watchpoint;
6540 case bp_fast_tracepoint:
6541 case bp_static_tracepoint:
6542 loc->loc_type = bp_loc_other;
6545 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
6551 /* Allocate a struct bp_location. */
6553 static struct bp_location *
6554 allocate_bp_location (struct breakpoint *bpt)
6556 return bpt->ops->allocate_location (bpt);
6560 free_bp_location (struct bp_location *loc)
6562 loc->ops->dtor (loc);
6566 /* Increment reference count. */
6569 incref_bp_location (struct bp_location *bl)
6574 /* Decrement reference count. If the reference count reaches 0,
6575 destroy the bp_location. Sets *BLP to NULL. */
6578 decref_bp_location (struct bp_location **blp)
6580 gdb_assert ((*blp)->refc > 0);
6582 if (--(*blp)->refc == 0)
6583 free_bp_location (*blp);
6587 /* Add breakpoint B at the end of the global breakpoint chain. */
6590 add_to_breakpoint_chain (struct breakpoint *b)
6592 struct breakpoint *b1;
6594 /* Add this breakpoint to the end of the chain so that a list of
6595 breakpoints will come out in order of increasing numbers. */
6597 b1 = breakpoint_chain;
6599 breakpoint_chain = b;
6608 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
6611 init_raw_breakpoint_without_location (struct breakpoint *b,
6612 struct gdbarch *gdbarch,
6614 const struct breakpoint_ops *ops)
6616 memset (b, 0, sizeof (*b));
6618 gdb_assert (ops != NULL);
6622 b->gdbarch = gdbarch;
6623 b->language = current_language->la_language;
6624 b->input_radix = input_radix;
6626 b->enable_state = bp_enabled;
6629 b->ignore_count = 0;
6631 b->frame_id = null_frame_id;
6632 b->condition_not_parsed = 0;
6633 b->py_bp_object = NULL;
6634 b->related_breakpoint = b;
6637 /* Helper to set_raw_breakpoint below. Creates a breakpoint
6638 that has type BPTYPE and has no locations as yet. */
6640 static struct breakpoint *
6641 set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
6643 const struct breakpoint_ops *ops)
6645 struct breakpoint *b = XNEW (struct breakpoint);
6647 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
6648 add_to_breakpoint_chain (b);
6652 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
6653 resolutions should be made as the user specified the location explicitly
6657 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
6659 gdb_assert (loc->owner != NULL);
6661 if (loc->owner->type == bp_breakpoint
6662 || loc->owner->type == bp_hardware_breakpoint
6663 || is_tracepoint (loc->owner))
6666 const char *function_name;
6667 CORE_ADDR func_addr;
6669 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
6670 &func_addr, NULL, &is_gnu_ifunc);
6672 if (is_gnu_ifunc && !explicit_loc)
6674 struct breakpoint *b = loc->owner;
6676 gdb_assert (loc->pspace == current_program_space);
6677 if (gnu_ifunc_resolve_name (function_name,
6678 &loc->requested_address))
6680 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
6681 loc->address = adjust_breakpoint_address (loc->gdbarch,
6682 loc->requested_address,
6685 else if (b->type == bp_breakpoint && b->loc == loc
6686 && loc->next == NULL && b->related_breakpoint == b)
6688 /* Create only the whole new breakpoint of this type but do not
6689 mess more complicated breakpoints with multiple locations. */
6690 b->type = bp_gnu_ifunc_resolver;
6691 /* Remember the resolver's address for use by the return
6693 loc->related_address = func_addr;
6698 loc->function_name = xstrdup (function_name);
6702 /* Attempt to determine architecture of location identified by SAL. */
6704 get_sal_arch (struct symtab_and_line sal)
6707 return get_objfile_arch (sal.section->objfile);
6709 return get_objfile_arch (sal.symtab->objfile);
6714 /* Low level routine for partially initializing a breakpoint of type
6715 BPTYPE. The newly created breakpoint's address, section, source
6716 file name, and line number are provided by SAL.
6718 It is expected that the caller will complete the initialization of
6719 the newly created breakpoint struct as well as output any status
6720 information regarding the creation of a new breakpoint. */
6723 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
6724 struct symtab_and_line sal, enum bptype bptype,
6725 const struct breakpoint_ops *ops)
6727 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
6729 add_location_to_breakpoint (b, &sal);
6731 if (bptype != bp_catchpoint)
6732 gdb_assert (sal.pspace != NULL);
6734 /* Store the program space that was used to set the breakpoint,
6735 except for ordinary breakpoints, which are independent of the
6737 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
6738 b->pspace = sal.pspace;
6740 breakpoints_changed ();
6743 /* set_raw_breakpoint is a low level routine for allocating and
6744 partially initializing a breakpoint of type BPTYPE. The newly
6745 created breakpoint's address, section, source file name, and line
6746 number are provided by SAL. The newly created and partially
6747 initialized breakpoint is added to the breakpoint chain and
6748 is also returned as the value of this function.
6750 It is expected that the caller will complete the initialization of
6751 the newly created breakpoint struct as well as output any status
6752 information regarding the creation of a new breakpoint. In
6753 particular, set_raw_breakpoint does NOT set the breakpoint
6754 number! Care should be taken to not allow an error to occur
6755 prior to completing the initialization of the breakpoint. If this
6756 should happen, a bogus breakpoint will be left on the chain. */
6759 set_raw_breakpoint (struct gdbarch *gdbarch,
6760 struct symtab_and_line sal, enum bptype bptype,
6761 const struct breakpoint_ops *ops)
6763 struct breakpoint *b = XNEW (struct breakpoint);
6765 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
6766 add_to_breakpoint_chain (b);
6771 /* Note that the breakpoint object B describes a permanent breakpoint
6772 instruction, hard-wired into the inferior's code. */
6774 make_breakpoint_permanent (struct breakpoint *b)
6776 struct bp_location *bl;
6778 b->enable_state = bp_permanent;
6780 /* By definition, permanent breakpoints are already present in the
6781 code. Mark all locations as inserted. For now,
6782 make_breakpoint_permanent is called in just one place, so it's
6783 hard to say if it's reasonable to have permanent breakpoint with
6784 multiple locations or not, but it's easy to implement. */
6785 for (bl = b->loc; bl; bl = bl->next)
6789 /* Call this routine when stepping and nexting to enable a breakpoint
6790 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
6791 initiated the operation. */
6794 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
6796 struct breakpoint *b, *b_tmp;
6797 int thread = tp->num;
6799 /* To avoid having to rescan all objfile symbols at every step,
6800 we maintain a list of continually-inserted but always disabled
6801 longjmp "master" breakpoints. Here, we simply create momentary
6802 clones of those and enable them for the requested thread. */
6803 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6804 if (b->pspace == current_program_space
6805 && (b->type == bp_longjmp_master
6806 || b->type == bp_exception_master))
6808 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
6809 struct breakpoint *clone;
6811 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
6812 after their removal. */
6813 clone = momentary_breakpoint_from_master (b, type,
6814 &longjmp_breakpoint_ops);
6815 clone->thread = thread;
6818 tp->initiating_frame = frame;
6821 /* Delete all longjmp breakpoints from THREAD. */
6823 delete_longjmp_breakpoint (int thread)
6825 struct breakpoint *b, *b_tmp;
6827 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6828 if (b->type == bp_longjmp || b->type == bp_exception)
6830 if (b->thread == thread)
6831 delete_breakpoint (b);
6836 delete_longjmp_breakpoint_at_next_stop (int thread)
6838 struct breakpoint *b, *b_tmp;
6840 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6841 if (b->type == bp_longjmp || b->type == bp_exception)
6843 if (b->thread == thread)
6844 b->disposition = disp_del_at_next_stop;
6848 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
6849 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
6850 pointer to any of them. Return NULL if this system cannot place longjmp
6854 set_longjmp_breakpoint_for_call_dummy (void)
6856 struct breakpoint *b, *retval = NULL;
6859 if (b->pspace == current_program_space && b->type == bp_longjmp_master)
6861 struct breakpoint *new_b;
6863 new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
6864 &momentary_breakpoint_ops);
6865 new_b->thread = pid_to_thread_id (inferior_ptid);
6867 /* Link NEW_B into the chain of RETVAL breakpoints. */
6869 gdb_assert (new_b->related_breakpoint == new_b);
6872 new_b->related_breakpoint = retval;
6873 while (retval->related_breakpoint != new_b->related_breakpoint)
6874 retval = retval->related_breakpoint;
6875 retval->related_breakpoint = new_b;
6881 /* Verify all existing dummy frames and their associated breakpoints for
6882 THREAD. Remove those which can no longer be found in the current frame
6885 You should call this function only at places where it is safe to currently
6886 unwind the whole stack. Failed stack unwind would discard live dummy
6890 check_longjmp_breakpoint_for_call_dummy (int thread)
6892 struct breakpoint *b, *b_tmp;
6894 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6895 if (b->type == bp_longjmp_call_dummy && b->thread == thread)
6897 struct breakpoint *dummy_b = b->related_breakpoint;
6899 while (dummy_b != b && dummy_b->type != bp_call_dummy)
6900 dummy_b = dummy_b->related_breakpoint;
6901 if (dummy_b->type != bp_call_dummy
6902 || frame_find_by_id (dummy_b->frame_id) != NULL)
6905 dummy_frame_discard (dummy_b->frame_id);
6907 while (b->related_breakpoint != b)
6909 if (b_tmp == b->related_breakpoint)
6910 b_tmp = b->related_breakpoint->next;
6911 delete_breakpoint (b->related_breakpoint);
6913 delete_breakpoint (b);
6918 enable_overlay_breakpoints (void)
6920 struct breakpoint *b;
6923 if (b->type == bp_overlay_event)
6925 b->enable_state = bp_enabled;
6926 update_global_location_list (1);
6927 overlay_events_enabled = 1;
6932 disable_overlay_breakpoints (void)
6934 struct breakpoint *b;
6937 if (b->type == bp_overlay_event)
6939 b->enable_state = bp_disabled;
6940 update_global_location_list (0);
6941 overlay_events_enabled = 0;
6945 /* Set an active std::terminate breakpoint for each std::terminate
6946 master breakpoint. */
6948 set_std_terminate_breakpoint (void)
6950 struct breakpoint *b, *b_tmp;
6952 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6953 if (b->pspace == current_program_space
6954 && b->type == bp_std_terminate_master)
6956 momentary_breakpoint_from_master (b, bp_std_terminate,
6957 &momentary_breakpoint_ops);
6961 /* Delete all the std::terminate breakpoints. */
6963 delete_std_terminate_breakpoint (void)
6965 struct breakpoint *b, *b_tmp;
6967 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6968 if (b->type == bp_std_terminate)
6969 delete_breakpoint (b);
6973 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6975 struct breakpoint *b;
6977 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
6978 &internal_breakpoint_ops);
6980 b->enable_state = bp_enabled;
6981 /* addr_string has to be used or breakpoint_re_set will delete me. */
6983 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
6985 update_global_location_list_nothrow (1);
6991 remove_thread_event_breakpoints (void)
6993 struct breakpoint *b, *b_tmp;
6995 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6996 if (b->type == bp_thread_event
6997 && b->loc->pspace == current_program_space)
6998 delete_breakpoint (b);
7001 struct lang_and_radix
7007 /* Create a breakpoint for JIT code registration and unregistration. */
7010 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7012 struct breakpoint *b;
7014 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
7015 &internal_breakpoint_ops);
7016 update_global_location_list_nothrow (1);
7020 /* Remove JIT code registration and unregistration breakpoint(s). */
7023 remove_jit_event_breakpoints (void)
7025 struct breakpoint *b, *b_tmp;
7027 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7028 if (b->type == bp_jit_event
7029 && b->loc->pspace == current_program_space)
7030 delete_breakpoint (b);
7034 remove_solib_event_breakpoints (void)
7036 struct breakpoint *b, *b_tmp;
7038 ALL_BREAKPOINTS_SAFE (b, b_tmp)
7039 if (b->type == bp_shlib_event
7040 && b->loc->pspace == current_program_space)
7041 delete_breakpoint (b);
7045 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
7047 struct breakpoint *b;
7049 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7050 &internal_breakpoint_ops);
7051 update_global_location_list_nothrow (1);
7055 /* Disable any breakpoints that are on code in shared libraries. Only
7056 apply to enabled breakpoints, disabled ones can just stay disabled. */
7059 disable_breakpoints_in_shlibs (void)
7061 struct bp_location *loc, **locp_tmp;
7063 ALL_BP_LOCATIONS (loc, locp_tmp)
7065 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7066 struct breakpoint *b = loc->owner;
7068 /* We apply the check to all breakpoints, including disabled for
7069 those with loc->duplicate set. This is so that when breakpoint
7070 becomes enabled, or the duplicate is removed, gdb will try to
7071 insert all breakpoints. If we don't set shlib_disabled here,
7072 we'll try to insert those breakpoints and fail. */
7073 if (((b->type == bp_breakpoint)
7074 || (b->type == bp_jit_event)
7075 || (b->type == bp_hardware_breakpoint)
7076 || (is_tracepoint (b)))
7077 && loc->pspace == current_program_space
7078 && !loc->shlib_disabled
7080 && PC_SOLIB (loc->address)
7082 && solib_name_from_address (loc->pspace, loc->address)
7086 loc->shlib_disabled = 1;
7091 /* Disable any breakpoints and tracepoints that are in an unloaded shared
7092 library. Only apply to enabled breakpoints, disabled ones can just stay
7096 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
7098 struct bp_location *loc, **locp_tmp;
7099 int disabled_shlib_breaks = 0;
7101 /* SunOS a.out shared libraries are always mapped, so do not
7102 disable breakpoints; they will only be reported as unloaded
7103 through clear_solib when GDB discards its shared library
7104 list. See clear_solib for more information. */
7105 if (exec_bfd != NULL
7106 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
7109 ALL_BP_LOCATIONS (loc, locp_tmp)
7111 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7112 struct breakpoint *b = loc->owner;
7114 if (solib->pspace == loc->pspace
7115 && !loc->shlib_disabled
7116 && (((b->type == bp_breakpoint
7117 || b->type == bp_jit_event
7118 || b->type == bp_hardware_breakpoint)
7119 && (loc->loc_type == bp_loc_hardware_breakpoint
7120 || loc->loc_type == bp_loc_software_breakpoint))
7121 || is_tracepoint (b))
7122 && solib_contains_address_p (solib, loc->address))
7124 loc->shlib_disabled = 1;
7125 /* At this point, we cannot rely on remove_breakpoint
7126 succeeding so we must mark the breakpoint as not inserted
7127 to prevent future errors occurring in remove_breakpoints. */
7130 /* This may cause duplicate notifications for the same breakpoint. */
7131 observer_notify_breakpoint_modified (b);
7133 if (!disabled_shlib_breaks)
7135 target_terminal_ours_for_output ();
7136 warning (_("Temporarily disabling breakpoints "
7137 "for unloaded shared library \"%s\""),
7140 disabled_shlib_breaks = 1;
7145 /* FORK & VFORK catchpoints. */
7147 /* An instance of this type is used to represent a fork or vfork
7148 catchpoint. It includes a "struct breakpoint" as a kind of base
7149 class; users downcast to "struct breakpoint *" when needed. A
7150 breakpoint is really of this type iff its ops pointer points to
7151 CATCH_FORK_BREAKPOINT_OPS. */
7153 struct fork_catchpoint
7155 /* The base class. */
7156 struct breakpoint base;
7158 /* Process id of a child process whose forking triggered this
7159 catchpoint. This field is only valid immediately after this
7160 catchpoint has triggered. */
7161 ptid_t forked_inferior_pid;
7164 /* Implement the "insert" breakpoint_ops method for fork
7168 insert_catch_fork (struct bp_location *bl)
7170 return target_insert_fork_catchpoint (PIDGET (inferior_ptid));
7173 /* Implement the "remove" breakpoint_ops method for fork
7177 remove_catch_fork (struct bp_location *bl)
7179 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
7182 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7186 breakpoint_hit_catch_fork (const struct bp_location *bl,
7187 struct address_space *aspace, CORE_ADDR bp_addr,
7188 const struct target_waitstatus *ws)
7190 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7192 if (ws->kind != TARGET_WAITKIND_FORKED)
7195 c->forked_inferior_pid = ws->value.related_pid;
7199 /* Implement the "print_it" breakpoint_ops method for fork
7202 static enum print_stop_action
7203 print_it_catch_fork (bpstat bs)
7205 struct ui_out *uiout = current_uiout;
7206 struct breakpoint *b = bs->breakpoint_at;
7207 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
7209 annotate_catchpoint (b->number);
7210 if (b->disposition == disp_del)
7211 ui_out_text (uiout, "\nTemporary catchpoint ");
7213 ui_out_text (uiout, "\nCatchpoint ");
7214 if (ui_out_is_mi_like_p (uiout))
7216 ui_out_field_string (uiout, "reason",
7217 async_reason_lookup (EXEC_ASYNC_FORK));
7218 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7220 ui_out_field_int (uiout, "bkptno", b->number);
7221 ui_out_text (uiout, " (forked process ");
7222 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7223 ui_out_text (uiout, "), ");
7224 return PRINT_SRC_AND_LOC;
7227 /* Implement the "print_one" breakpoint_ops method for fork
7231 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
7233 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7234 struct value_print_options opts;
7235 struct ui_out *uiout = current_uiout;
7237 get_user_print_options (&opts);
7239 /* Field 4, the address, is omitted (which makes the columns not
7240 line up too nicely with the headers, but the effect is relatively
7242 if (opts.addressprint)
7243 ui_out_field_skip (uiout, "addr");
7245 ui_out_text (uiout, "fork");
7246 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7248 ui_out_text (uiout, ", process ");
7249 ui_out_field_int (uiout, "what",
7250 ptid_get_pid (c->forked_inferior_pid));
7251 ui_out_spaces (uiout, 1);
7255 /* Implement the "print_mention" breakpoint_ops method for fork
7259 print_mention_catch_fork (struct breakpoint *b)
7261 printf_filtered (_("Catchpoint %d (fork)"), b->number);
7264 /* Implement the "print_recreate" breakpoint_ops method for fork
7268 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
7270 fprintf_unfiltered (fp, "catch fork");
7271 print_recreate_thread (b, fp);
7274 /* The breakpoint_ops structure to be used in fork catchpoints. */
7276 static struct breakpoint_ops catch_fork_breakpoint_ops;
7278 /* Implement the "insert" breakpoint_ops method for vfork
7282 insert_catch_vfork (struct bp_location *bl)
7284 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
7287 /* Implement the "remove" breakpoint_ops method for vfork
7291 remove_catch_vfork (struct bp_location *bl)
7293 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
7296 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7300 breakpoint_hit_catch_vfork (const struct bp_location *bl,
7301 struct address_space *aspace, CORE_ADDR bp_addr,
7302 const struct target_waitstatus *ws)
7304 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7306 if (ws->kind != TARGET_WAITKIND_VFORKED)
7309 c->forked_inferior_pid = ws->value.related_pid;
7313 /* Implement the "print_it" breakpoint_ops method for vfork
7316 static enum print_stop_action
7317 print_it_catch_vfork (bpstat bs)
7319 struct ui_out *uiout = current_uiout;
7320 struct breakpoint *b = bs->breakpoint_at;
7321 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7323 annotate_catchpoint (b->number);
7324 if (b->disposition == disp_del)
7325 ui_out_text (uiout, "\nTemporary catchpoint ");
7327 ui_out_text (uiout, "\nCatchpoint ");
7328 if (ui_out_is_mi_like_p (uiout))
7330 ui_out_field_string (uiout, "reason",
7331 async_reason_lookup (EXEC_ASYNC_VFORK));
7332 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7334 ui_out_field_int (uiout, "bkptno", b->number);
7335 ui_out_text (uiout, " (vforked process ");
7336 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7337 ui_out_text (uiout, "), ");
7338 return PRINT_SRC_AND_LOC;
7341 /* Implement the "print_one" breakpoint_ops method for vfork
7345 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
7347 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7348 struct value_print_options opts;
7349 struct ui_out *uiout = current_uiout;
7351 get_user_print_options (&opts);
7352 /* Field 4, the address, is omitted (which makes the columns not
7353 line up too nicely with the headers, but the effect is relatively
7355 if (opts.addressprint)
7356 ui_out_field_skip (uiout, "addr");
7358 ui_out_text (uiout, "vfork");
7359 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
7361 ui_out_text (uiout, ", process ");
7362 ui_out_field_int (uiout, "what",
7363 ptid_get_pid (c->forked_inferior_pid));
7364 ui_out_spaces (uiout, 1);
7368 /* Implement the "print_mention" breakpoint_ops method for vfork
7372 print_mention_catch_vfork (struct breakpoint *b)
7374 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
7377 /* Implement the "print_recreate" breakpoint_ops method for vfork
7381 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
7383 fprintf_unfiltered (fp, "catch vfork");
7384 print_recreate_thread (b, fp);
7387 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7389 static struct breakpoint_ops catch_vfork_breakpoint_ops;
7391 /* An instance of this type is used to represent an solib catchpoint.
7392 It includes a "struct breakpoint" as a kind of base class; users
7393 downcast to "struct breakpoint *" when needed. A breakpoint is
7394 really of this type iff its ops pointer points to
7395 CATCH_SOLIB_BREAKPOINT_OPS. */
7397 struct solib_catchpoint
7399 /* The base class. */
7400 struct breakpoint base;
7402 /* True for "catch load", false for "catch unload". */
7403 unsigned char is_load;
7405 /* Regular expression to match, if any. COMPILED is only valid when
7406 REGEX is non-NULL. */
7412 dtor_catch_solib (struct breakpoint *b)
7414 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7417 regfree (&self->compiled);
7418 xfree (self->regex);
7420 base_breakpoint_ops.dtor (b);
7424 insert_catch_solib (struct bp_location *ignore)
7430 remove_catch_solib (struct bp_location *ignore)
7436 breakpoint_hit_catch_solib (const struct bp_location *bl,
7437 struct address_space *aspace,
7439 const struct target_waitstatus *ws)
7441 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
7442 struct breakpoint *other;
7444 if (ws->kind == TARGET_WAITKIND_LOADED)
7447 ALL_BREAKPOINTS (other)
7449 struct bp_location *other_bl;
7451 if (other == bl->owner)
7454 if (other->type != bp_shlib_event)
7457 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
7460 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
7462 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
7471 check_status_catch_solib (struct bpstats *bs)
7473 struct solib_catchpoint *self
7474 = (struct solib_catchpoint *) bs->breakpoint_at;
7479 struct so_list *iter;
7482 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
7487 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
7496 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
7501 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
7507 bs->print_it = print_it_noop;
7510 static enum print_stop_action
7511 print_it_catch_solib (bpstat bs)
7513 struct breakpoint *b = bs->breakpoint_at;
7514 struct ui_out *uiout = current_uiout;
7516 annotate_catchpoint (b->number);
7517 if (b->disposition == disp_del)
7518 ui_out_text (uiout, "\nTemporary catchpoint ");
7520 ui_out_text (uiout, "\nCatchpoint ");
7521 ui_out_field_int (uiout, "bkptno", b->number);
7522 ui_out_text (uiout, "\n");
7523 if (ui_out_is_mi_like_p (uiout))
7524 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7525 print_solib_event (1);
7526 return PRINT_SRC_AND_LOC;
7530 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
7532 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7533 struct value_print_options opts;
7534 struct ui_out *uiout = current_uiout;
7537 get_user_print_options (&opts);
7538 /* Field 4, the address, is omitted (which makes the columns not
7539 line up too nicely with the headers, but the effect is relatively
7541 if (opts.addressprint)
7544 ui_out_field_skip (uiout, "addr");
7551 msg = xstrprintf (_("load of library matching %s"), self->regex);
7553 msg = xstrdup (_("load of library"));
7558 msg = xstrprintf (_("unload of library matching %s"), self->regex);
7560 msg = xstrdup (_("unload of library"));
7562 ui_out_field_string (uiout, "what", msg);
7567 print_mention_catch_solib (struct breakpoint *b)
7569 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7571 printf_filtered (_("Catchpoint %d (%s)"), b->number,
7572 self->is_load ? "load" : "unload");
7576 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
7578 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7580 fprintf_unfiltered (fp, "%s %s",
7581 b->disposition == disp_del ? "tcatch" : "catch",
7582 self->is_load ? "load" : "unload");
7584 fprintf_unfiltered (fp, " %s", self->regex);
7585 fprintf_unfiltered (fp, "\n");
7588 static struct breakpoint_ops catch_solib_breakpoint_ops;
7590 /* A helper function that does all the work for "catch load" and
7594 catch_load_or_unload (char *arg, int from_tty, int is_load,
7595 struct cmd_list_element *command)
7597 struct solib_catchpoint *c;
7598 struct gdbarch *gdbarch = get_current_arch ();
7600 struct cleanup *cleanup;
7602 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
7606 arg = skip_spaces (arg);
7608 c = XCNEW (struct solib_catchpoint);
7609 cleanup = make_cleanup (xfree, c);
7615 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
7618 char *err = get_regcomp_error (errcode, &c->compiled);
7620 make_cleanup (xfree, err);
7621 error (_("Invalid regexp (%s): %s"), err, arg);
7623 c->regex = xstrdup (arg);
7626 c->is_load = is_load;
7627 init_catchpoint (&c->base, gdbarch, tempflag, NULL,
7628 &catch_solib_breakpoint_ops);
7630 discard_cleanups (cleanup);
7631 install_breakpoint (0, &c->base, 1);
7635 catch_load_command_1 (char *arg, int from_tty,
7636 struct cmd_list_element *command)
7638 catch_load_or_unload (arg, from_tty, 1, command);
7642 catch_unload_command_1 (char *arg, int from_tty,
7643 struct cmd_list_element *command)
7645 catch_load_or_unload (arg, from_tty, 0, command);
7650 /* An instance of this type is used to represent a syscall catchpoint.
7651 It includes a "struct breakpoint" as a kind of base class; users
7652 downcast to "struct breakpoint *" when needed. A breakpoint is
7653 really of this type iff its ops pointer points to
7654 CATCH_SYSCALL_BREAKPOINT_OPS. */
7656 struct syscall_catchpoint
7658 /* The base class. */
7659 struct breakpoint base;
7661 /* Syscall numbers used for the 'catch syscall' feature. If no
7662 syscall has been specified for filtering, its value is NULL.
7663 Otherwise, it holds a list of all syscalls to be caught. The
7664 list elements are allocated with xmalloc. */
7665 VEC(int) *syscalls_to_be_caught;
7668 /* Implement the "dtor" breakpoint_ops method for syscall
7672 dtor_catch_syscall (struct breakpoint *b)
7674 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7676 VEC_free (int, c->syscalls_to_be_caught);
7678 base_breakpoint_ops.dtor (b);
7681 static const struct inferior_data *catch_syscall_inferior_data = NULL;
7683 struct catch_syscall_inferior_data
7685 /* We keep a count of the number of times the user has requested a
7686 particular syscall to be tracked, and pass this information to the
7687 target. This lets capable targets implement filtering directly. */
7689 /* Number of times that "any" syscall is requested. */
7690 int any_syscall_count;
7692 /* Count of each system call. */
7693 VEC(int) *syscalls_counts;
7695 /* This counts all syscall catch requests, so we can readily determine
7696 if any catching is necessary. */
7697 int total_syscalls_count;
7700 static struct catch_syscall_inferior_data*
7701 get_catch_syscall_inferior_data (struct inferior *inf)
7703 struct catch_syscall_inferior_data *inf_data;
7705 inf_data = inferior_data (inf, catch_syscall_inferior_data);
7706 if (inf_data == NULL)
7708 inf_data = XZALLOC (struct catch_syscall_inferior_data);
7709 set_inferior_data (inf, catch_syscall_inferior_data, inf_data);
7716 catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg)
7722 /* Implement the "insert" breakpoint_ops method for syscall
7726 insert_catch_syscall (struct bp_location *bl)
7728 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
7729 struct inferior *inf = current_inferior ();
7730 struct catch_syscall_inferior_data *inf_data
7731 = get_catch_syscall_inferior_data (inf);
7733 ++inf_data->total_syscalls_count;
7734 if (!c->syscalls_to_be_caught)
7735 ++inf_data->any_syscall_count;
7741 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7746 if (iter >= VEC_length (int, inf_data->syscalls_counts))
7748 int old_size = VEC_length (int, inf_data->syscalls_counts);
7749 uintptr_t vec_addr_offset
7750 = old_size * ((uintptr_t) sizeof (int));
7752 VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1);
7753 vec_addr = ((uintptr_t) VEC_address (int,
7754 inf_data->syscalls_counts)
7756 memset ((void *) vec_addr, 0,
7757 (iter + 1 - old_size) * sizeof (int));
7759 elem = VEC_index (int, inf_data->syscalls_counts, iter);
7760 VEC_replace (int, inf_data->syscalls_counts, iter, ++elem);
7764 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
7765 inf_data->total_syscalls_count != 0,
7766 inf_data->any_syscall_count,
7768 inf_data->syscalls_counts),
7770 inf_data->syscalls_counts));
7773 /* Implement the "remove" breakpoint_ops method for syscall
7777 remove_catch_syscall (struct bp_location *bl)
7779 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
7780 struct inferior *inf = current_inferior ();
7781 struct catch_syscall_inferior_data *inf_data
7782 = get_catch_syscall_inferior_data (inf);
7784 --inf_data->total_syscalls_count;
7785 if (!c->syscalls_to_be_caught)
7786 --inf_data->any_syscall_count;
7792 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7796 if (iter >= VEC_length (int, inf_data->syscalls_counts))
7797 /* Shouldn't happen. */
7799 elem = VEC_index (int, inf_data->syscalls_counts, iter);
7800 VEC_replace (int, inf_data->syscalls_counts, iter, --elem);
7804 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
7805 inf_data->total_syscalls_count != 0,
7806 inf_data->any_syscall_count,
7808 inf_data->syscalls_counts),
7810 inf_data->syscalls_counts));
7813 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
7817 breakpoint_hit_catch_syscall (const struct bp_location *bl,
7818 struct address_space *aspace, CORE_ADDR bp_addr,
7819 const struct target_waitstatus *ws)
7821 /* We must check if we are catching specific syscalls in this
7822 breakpoint. If we are, then we must guarantee that the called
7823 syscall is the same syscall we are catching. */
7824 int syscall_number = 0;
7825 const struct syscall_catchpoint *c
7826 = (const struct syscall_catchpoint *) bl->owner;
7828 if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY
7829 && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN)
7832 syscall_number = ws->value.syscall_number;
7834 /* Now, checking if the syscall is the same. */
7835 if (c->syscalls_to_be_caught)
7840 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7842 if (syscall_number == iter)
7852 /* Implement the "print_it" breakpoint_ops method for syscall
7855 static enum print_stop_action
7856 print_it_catch_syscall (bpstat bs)
7858 struct ui_out *uiout = current_uiout;
7859 struct breakpoint *b = bs->breakpoint_at;
7860 /* These are needed because we want to know in which state a
7861 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
7862 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
7863 must print "called syscall" or "returned from syscall". */
7865 struct target_waitstatus last;
7868 get_last_target_status (&ptid, &last);
7870 get_syscall_by_number (last.value.syscall_number, &s);
7872 annotate_catchpoint (b->number);
7874 if (b->disposition == disp_del)
7875 ui_out_text (uiout, "\nTemporary catchpoint ");
7877 ui_out_text (uiout, "\nCatchpoint ");
7878 if (ui_out_is_mi_like_p (uiout))
7880 ui_out_field_string (uiout, "reason",
7881 async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY
7882 ? EXEC_ASYNC_SYSCALL_ENTRY
7883 : EXEC_ASYNC_SYSCALL_RETURN));
7884 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7886 ui_out_field_int (uiout, "bkptno", b->number);
7888 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
7889 ui_out_text (uiout, " (call to syscall ");
7891 ui_out_text (uiout, " (returned from syscall ");
7893 if (s.name == NULL || ui_out_is_mi_like_p (uiout))
7894 ui_out_field_int (uiout, "syscall-number", last.value.syscall_number);
7896 ui_out_field_string (uiout, "syscall-name", s.name);
7898 ui_out_text (uiout, "), ");
7900 return PRINT_SRC_AND_LOC;
7903 /* Implement the "print_one" breakpoint_ops method for syscall
7907 print_one_catch_syscall (struct breakpoint *b,
7908 struct bp_location **last_loc)
7910 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7911 struct value_print_options opts;
7912 struct ui_out *uiout = current_uiout;
7914 get_user_print_options (&opts);
7915 /* Field 4, the address, is omitted (which makes the columns not
7916 line up too nicely with the headers, but the effect is relatively
7918 if (opts.addressprint)
7919 ui_out_field_skip (uiout, "addr");
7922 if (c->syscalls_to_be_caught
7923 && VEC_length (int, c->syscalls_to_be_caught) > 1)
7924 ui_out_text (uiout, "syscalls \"");
7926 ui_out_text (uiout, "syscall \"");
7928 if (c->syscalls_to_be_caught)
7931 char *text = xstrprintf ("%s", "");
7934 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7939 get_syscall_by_number (iter, &s);
7942 text = xstrprintf ("%s%s, ", text, s.name);
7944 text = xstrprintf ("%s%d, ", text, iter);
7946 /* We have to xfree the last 'text' (now stored at 'x')
7947 because xstrprintf dynamically allocates new space for it
7951 /* Remove the last comma. */
7952 text[strlen (text) - 2] = '\0';
7953 ui_out_field_string (uiout, "what", text);
7956 ui_out_field_string (uiout, "what", "<any syscall>");
7957 ui_out_text (uiout, "\" ");
7960 /* Implement the "print_mention" breakpoint_ops method for syscall
7964 print_mention_catch_syscall (struct breakpoint *b)
7966 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7968 if (c->syscalls_to_be_caught)
7972 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
7973 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
7975 printf_filtered (_("Catchpoint %d (syscall"), b->number);
7978 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
7982 get_syscall_by_number (iter, &s);
7985 printf_filtered (" '%s' [%d]", s.name, s.number);
7987 printf_filtered (" %d", s.number);
7989 printf_filtered (")");
7992 printf_filtered (_("Catchpoint %d (any syscall)"),
7996 /* Implement the "print_recreate" breakpoint_ops method for syscall
8000 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
8002 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8004 fprintf_unfiltered (fp, "catch syscall");
8006 if (c->syscalls_to_be_caught)
8011 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8016 get_syscall_by_number (iter, &s);
8018 fprintf_unfiltered (fp, " %s", s.name);
8020 fprintf_unfiltered (fp, " %d", s.number);
8023 print_recreate_thread (b, fp);
8026 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8028 static struct breakpoint_ops catch_syscall_breakpoint_ops;
8030 /* Returns non-zero if 'b' is a syscall catchpoint. */
8033 syscall_catchpoint_p (struct breakpoint *b)
8035 return (b->ops == &catch_syscall_breakpoint_ops);
8038 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8039 is non-zero, then make the breakpoint temporary. If COND_STRING is
8040 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8041 the breakpoint_ops structure associated to the catchpoint. */
8044 init_catchpoint (struct breakpoint *b,
8045 struct gdbarch *gdbarch, int tempflag,
8047 const struct breakpoint_ops *ops)
8049 struct symtab_and_line sal;
8052 sal.pspace = current_program_space;
8054 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
8056 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
8057 b->disposition = tempflag ? disp_del : disp_donttouch;
8061 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
8063 add_to_breakpoint_chain (b);
8064 set_breakpoint_number (internal, b);
8067 observer_notify_breakpoint_created (b);
8070 update_global_location_list (1);
8074 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
8075 int tempflag, char *cond_string,
8076 const struct breakpoint_ops *ops)
8078 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
8080 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
8082 c->forked_inferior_pid = null_ptid;
8084 install_breakpoint (0, &c->base, 1);
8087 /* Exec catchpoints. */
8089 /* An instance of this type is used to represent an exec catchpoint.
8090 It includes a "struct breakpoint" as a kind of base class; users
8091 downcast to "struct breakpoint *" when needed. A breakpoint is
8092 really of this type iff its ops pointer points to
8093 CATCH_EXEC_BREAKPOINT_OPS. */
8095 struct exec_catchpoint
8097 /* The base class. */
8098 struct breakpoint base;
8100 /* Filename of a program whose exec triggered this catchpoint.
8101 This field is only valid immediately after this catchpoint has
8103 char *exec_pathname;
8106 /* Implement the "dtor" breakpoint_ops method for exec
8110 dtor_catch_exec (struct breakpoint *b)
8112 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8114 xfree (c->exec_pathname);
8116 base_breakpoint_ops.dtor (b);
8120 insert_catch_exec (struct bp_location *bl)
8122 return target_insert_exec_catchpoint (PIDGET (inferior_ptid));
8126 remove_catch_exec (struct bp_location *bl)
8128 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
8132 breakpoint_hit_catch_exec (const struct bp_location *bl,
8133 struct address_space *aspace, CORE_ADDR bp_addr,
8134 const struct target_waitstatus *ws)
8136 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8138 if (ws->kind != TARGET_WAITKIND_EXECD)
8141 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8145 static enum print_stop_action
8146 print_it_catch_exec (bpstat bs)
8148 struct ui_out *uiout = current_uiout;
8149 struct breakpoint *b = bs->breakpoint_at;
8150 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8152 annotate_catchpoint (b->number);
8153 if (b->disposition == disp_del)
8154 ui_out_text (uiout, "\nTemporary catchpoint ");
8156 ui_out_text (uiout, "\nCatchpoint ");
8157 if (ui_out_is_mi_like_p (uiout))
8159 ui_out_field_string (uiout, "reason",
8160 async_reason_lookup (EXEC_ASYNC_EXEC));
8161 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8163 ui_out_field_int (uiout, "bkptno", b->number);
8164 ui_out_text (uiout, " (exec'd ");
8165 ui_out_field_string (uiout, "new-exec", c->exec_pathname);
8166 ui_out_text (uiout, "), ");
8168 return PRINT_SRC_AND_LOC;
8172 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8174 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8175 struct value_print_options opts;
8176 struct ui_out *uiout = current_uiout;
8178 get_user_print_options (&opts);
8180 /* Field 4, the address, is omitted (which makes the columns
8181 not line up too nicely with the headers, but the effect
8182 is relatively readable). */
8183 if (opts.addressprint)
8184 ui_out_field_skip (uiout, "addr");
8186 ui_out_text (uiout, "exec");
8187 if (c->exec_pathname != NULL)
8189 ui_out_text (uiout, ", program \"");
8190 ui_out_field_string (uiout, "what", c->exec_pathname);
8191 ui_out_text (uiout, "\" ");
8196 print_mention_catch_exec (struct breakpoint *b)
8198 printf_filtered (_("Catchpoint %d (exec)"), b->number);
8201 /* Implement the "print_recreate" breakpoint_ops method for exec
8205 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
8207 fprintf_unfiltered (fp, "catch exec");
8208 print_recreate_thread (b, fp);
8211 static struct breakpoint_ops catch_exec_breakpoint_ops;
8214 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
8215 const struct breakpoint_ops *ops)
8217 struct syscall_catchpoint *c;
8218 struct gdbarch *gdbarch = get_current_arch ();
8220 c = XNEW (struct syscall_catchpoint);
8221 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
8222 c->syscalls_to_be_caught = filter;
8224 install_breakpoint (0, &c->base, 1);
8228 hw_breakpoint_used_count (void)
8231 struct breakpoint *b;
8232 struct bp_location *bl;
8236 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
8237 for (bl = b->loc; bl; bl = bl->next)
8239 /* Special types of hardware breakpoints may use more than
8241 i += b->ops->resources_needed (bl);
8248 /* Returns the resources B would use if it were a hardware
8252 hw_watchpoint_use_count (struct breakpoint *b)
8255 struct bp_location *bl;
8257 if (!breakpoint_enabled (b))
8260 for (bl = b->loc; bl; bl = bl->next)
8262 /* Special types of hardware watchpoints may use more than
8264 i += b->ops->resources_needed (bl);
8270 /* Returns the sum the used resources of all hardware watchpoints of
8271 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8272 the sum of the used resources of all hardware watchpoints of other
8273 types _not_ TYPE. */
8276 hw_watchpoint_used_count_others (struct breakpoint *except,
8277 enum bptype type, int *other_type_used)
8280 struct breakpoint *b;
8282 *other_type_used = 0;
8287 if (!breakpoint_enabled (b))
8290 if (b->type == type)
8291 i += hw_watchpoint_use_count (b);
8292 else if (is_hardware_watchpoint (b))
8293 *other_type_used = 1;
8300 disable_watchpoints_before_interactive_call_start (void)
8302 struct breakpoint *b;
8306 if (is_watchpoint (b) && breakpoint_enabled (b))
8308 b->enable_state = bp_call_disabled;
8309 update_global_location_list (0);
8315 enable_watchpoints_after_interactive_call_stop (void)
8317 struct breakpoint *b;
8321 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
8323 b->enable_state = bp_enabled;
8324 update_global_location_list (1);
8330 disable_breakpoints_before_startup (void)
8332 current_program_space->executing_startup = 1;
8333 update_global_location_list (0);
8337 enable_breakpoints_after_startup (void)
8339 current_program_space->executing_startup = 0;
8340 breakpoint_re_set ();
8344 /* Set a breakpoint that will evaporate an end of command
8345 at address specified by SAL.
8346 Restrict it to frame FRAME if FRAME is nonzero. */
8349 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
8350 struct frame_id frame_id, enum bptype type)
8352 struct breakpoint *b;
8354 /* If FRAME_ID is valid, it should be a real frame, not an inlined
8356 gdb_assert (!frame_id_inlined_p (frame_id));
8358 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
8359 b->enable_state = bp_enabled;
8360 b->disposition = disp_donttouch;
8361 b->frame_id = frame_id;
8363 /* If we're debugging a multi-threaded program, then we want
8364 momentary breakpoints to be active in only a single thread of
8366 if (in_thread_list (inferior_ptid))
8367 b->thread = pid_to_thread_id (inferior_ptid);
8369 update_global_location_list_nothrow (1);
8374 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8375 The new breakpoint will have type TYPE, and use OPS as it
8378 static struct breakpoint *
8379 momentary_breakpoint_from_master (struct breakpoint *orig,
8381 const struct breakpoint_ops *ops)
8383 struct breakpoint *copy;
8385 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
8386 copy->loc = allocate_bp_location (copy);
8387 set_breakpoint_location_function (copy->loc, 1);
8389 copy->loc->gdbarch = orig->loc->gdbarch;
8390 copy->loc->requested_address = orig->loc->requested_address;
8391 copy->loc->address = orig->loc->address;
8392 copy->loc->section = orig->loc->section;
8393 copy->loc->pspace = orig->loc->pspace;
8394 copy->loc->probe = orig->loc->probe;
8396 if (orig->loc->source_file != NULL)
8397 copy->loc->source_file = xstrdup (orig->loc->source_file);
8399 copy->loc->line_number = orig->loc->line_number;
8400 copy->frame_id = orig->frame_id;
8401 copy->thread = orig->thread;
8402 copy->pspace = orig->pspace;
8404 copy->enable_state = bp_enabled;
8405 copy->disposition = disp_donttouch;
8406 copy->number = internal_breakpoint_number--;
8408 update_global_location_list_nothrow (0);
8412 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8416 clone_momentary_breakpoint (struct breakpoint *orig)
8418 /* If there's nothing to clone, then return nothing. */
8422 return momentary_breakpoint_from_master (orig, orig->type, orig->ops);
8426 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
8429 struct symtab_and_line sal;
8431 sal = find_pc_line (pc, 0);
8433 sal.section = find_pc_overlay (pc);
8434 sal.explicit_pc = 1;
8436 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
8440 /* Tell the user we have just set a breakpoint B. */
8443 mention (struct breakpoint *b)
8445 b->ops->print_mention (b);
8446 if (ui_out_is_mi_like_p (current_uiout))
8448 printf_filtered ("\n");
8452 static struct bp_location *
8453 add_location_to_breakpoint (struct breakpoint *b,
8454 const struct symtab_and_line *sal)
8456 struct bp_location *loc, **tmp;
8457 CORE_ADDR adjusted_address;
8458 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
8460 if (loc_gdbarch == NULL)
8461 loc_gdbarch = b->gdbarch;
8463 /* Adjust the breakpoint's address prior to allocating a location.
8464 Once we call allocate_bp_location(), that mostly uninitialized
8465 location will be placed on the location chain. Adjustment of the
8466 breakpoint may cause target_read_memory() to be called and we do
8467 not want its scan of the location chain to find a breakpoint and
8468 location that's only been partially initialized. */
8469 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
8472 loc = allocate_bp_location (b);
8473 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
8477 loc->requested_address = sal->pc;
8478 loc->address = adjusted_address;
8479 loc->pspace = sal->pspace;
8480 loc->probe = sal->probe;
8481 gdb_assert (loc->pspace != NULL);
8482 loc->section = sal->section;
8483 loc->gdbarch = loc_gdbarch;
8485 if (sal->symtab != NULL)
8486 loc->source_file = xstrdup (sal->symtab->filename);
8487 loc->line_number = sal->line;
8489 set_breakpoint_location_function (loc,
8490 sal->explicit_pc || sal->explicit_line);
8495 /* Return 1 if LOC is pointing to a permanent breakpoint,
8496 return 0 otherwise. */
8499 bp_loc_is_permanent (struct bp_location *loc)
8503 const gdb_byte *bpoint;
8504 gdb_byte *target_mem;
8505 struct cleanup *cleanup;
8508 gdb_assert (loc != NULL);
8510 addr = loc->address;
8511 bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
8513 /* Software breakpoints unsupported? */
8517 target_mem = alloca (len);
8519 /* Enable the automatic memory restoration from breakpoints while
8520 we read the memory. Otherwise we could say about our temporary
8521 breakpoints they are permanent. */
8522 cleanup = save_current_space_and_thread ();
8524 switch_to_program_space_and_thread (loc->pspace);
8525 make_show_memory_breakpoints_cleanup (0);
8527 if (target_read_memory (loc->address, target_mem, len) == 0
8528 && memcmp (target_mem, bpoint, len) == 0)
8531 do_cleanups (cleanup);
8536 /* The style in which to perform a dynamic printf. This is a user
8537 option because different output options have different tradeoffs;
8538 if GDB does the printing, there is better error handling if there
8539 is a problem with any of the arguments, but using an inferior
8540 function lets you have special-purpose printers and sending of
8541 output to the same place as compiled-in print functions. (Future
8542 styles may include the ability to do a target-side printf.) */
8544 static const char dprintf_style_gdb[] = "gdb";
8545 static const char dprintf_style_call[] = "call";
8546 static const char *const dprintf_style_enums[] = {
8551 static const char *dprintf_style = dprintf_style_gdb;
8553 /* The function to use for dynamic printf if the preferred style is to
8554 call into the inferior. The value is simply a string that is
8555 copied into the command, so it can be anything that GDB can
8556 evaluate to a callable address, not necessarily a function name. */
8558 static char *dprintf_function = "";
8560 /* The channel to use for dynamic printf if the preferred style is to
8561 call into the inferior; if a nonempty string, it will be passed to
8562 the call as the first argument, with the format string as the
8563 second. As with the dprintf function, this can be anything that
8564 GDB knows how to evaluate, so in addition to common choices like
8565 "stderr", this could be an app-specific expression like
8566 "mystreams[curlogger]". */
8568 static char *dprintf_channel = "";
8570 /* Build a command list for the dprintf corresponding to the current
8571 settings of the dprintf style options. */
8574 update_dprintf_command_list (struct breakpoint *b)
8576 char *dprintf_args = b->extra_string;
8577 char *printf_line = NULL;
8582 dprintf_args = skip_spaces (dprintf_args);
8584 /* Allow a comma, as it may have terminated a location, but don't
8586 if (*dprintf_args == ',')
8588 dprintf_args = skip_spaces (dprintf_args);
8590 if (*dprintf_args != '"')
8591 error (_("Bad format string, missing '\"'."));
8593 if (strcmp (dprintf_style, "gdb") == 0)
8594 printf_line = xstrprintf ("printf %s", dprintf_args);
8595 else if (strcmp (dprintf_style, "call") == 0)
8597 if (!dprintf_function)
8598 error (_("No function supplied for dprintf call"));
8600 if (dprintf_channel && strlen (dprintf_channel) > 0)
8601 printf_line = xstrprintf ("call (void) %s (%s,%s)",
8606 printf_line = xstrprintf ("call (void) %s (%s)",
8611 internal_error (__FILE__, __LINE__,
8612 _("Invalid dprintf style."));
8614 /* Manufacture a printf/continue sequence. */
8617 struct command_line *printf_cmd_line, *cont_cmd_line = NULL;
8619 cont_cmd_line = xmalloc (sizeof (struct command_line));
8620 cont_cmd_line->control_type = simple_control;
8621 cont_cmd_line->body_count = 0;
8622 cont_cmd_line->body_list = NULL;
8623 cont_cmd_line->next = NULL;
8624 cont_cmd_line->line = xstrdup ("continue");
8626 printf_cmd_line = xmalloc (sizeof (struct command_line));
8627 printf_cmd_line->control_type = simple_control;
8628 printf_cmd_line->body_count = 0;
8629 printf_cmd_line->body_list = NULL;
8630 printf_cmd_line->next = cont_cmd_line;
8631 printf_cmd_line->line = printf_line;
8633 breakpoint_set_commands (b, printf_cmd_line);
8637 /* Update all dprintf commands, making their command lists reflect
8638 current style settings. */
8641 update_dprintf_commands (char *args, int from_tty,
8642 struct cmd_list_element *c)
8644 struct breakpoint *b;
8648 if (b->type == bp_dprintf)
8649 update_dprintf_command_list (b);
8653 /* Create a breakpoint with SAL as location. Use ADDR_STRING
8654 as textual description of the location, and COND_STRING
8655 as condition expression. */
8658 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
8659 struct symtabs_and_lines sals, char *addr_string,
8660 char *filter, char *cond_string,
8662 enum bptype type, enum bpdisp disposition,
8663 int thread, int task, int ignore_count,
8664 const struct breakpoint_ops *ops, int from_tty,
8665 int enabled, int internal, unsigned flags,
8666 int display_canonical)
8670 if (type == bp_hardware_breakpoint)
8672 int target_resources_ok;
8674 i = hw_breakpoint_used_count ();
8675 target_resources_ok =
8676 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
8678 if (target_resources_ok == 0)
8679 error (_("No hardware breakpoint support in the target."));
8680 else if (target_resources_ok < 0)
8681 error (_("Hardware breakpoints used exceeds limit."));
8684 gdb_assert (sals.nelts > 0);
8686 for (i = 0; i < sals.nelts; ++i)
8688 struct symtab_and_line sal = sals.sals[i];
8689 struct bp_location *loc;
8693 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
8695 loc_gdbarch = gdbarch;
8697 describe_other_breakpoints (loc_gdbarch,
8698 sal.pspace, sal.pc, sal.section, thread);
8703 init_raw_breakpoint (b, gdbarch, sal, type, ops);
8707 b->cond_string = cond_string;
8708 b->extra_string = extra_string;
8709 b->ignore_count = ignore_count;
8710 b->enable_state = enabled ? bp_enabled : bp_disabled;
8711 b->disposition = disposition;
8713 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
8714 b->loc->inserted = 1;
8716 if (type == bp_static_tracepoint)
8718 struct tracepoint *t = (struct tracepoint *) b;
8719 struct static_tracepoint_marker marker;
8721 if (strace_marker_p (b))
8723 /* We already know the marker exists, otherwise, we
8724 wouldn't see a sal for it. */
8725 char *p = &addr_string[3];
8729 p = skip_spaces (p);
8731 endp = skip_to_space (p);
8733 marker_str = savestring (p, endp - p);
8734 t->static_trace_marker_id = marker_str;
8736 printf_filtered (_("Probed static tracepoint "
8738 t->static_trace_marker_id);
8740 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
8742 t->static_trace_marker_id = xstrdup (marker.str_id);
8743 release_static_tracepoint_marker (&marker);
8745 printf_filtered (_("Probed static tracepoint "
8747 t->static_trace_marker_id);
8750 warning (_("Couldn't determine the static "
8751 "tracepoint marker to probe"));
8758 loc = add_location_to_breakpoint (b, &sal);
8759 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
8763 if (bp_loc_is_permanent (loc))
8764 make_breakpoint_permanent (b);
8768 char *arg = b->cond_string;
8769 loc->cond = parse_exp_1 (&arg, loc->address,
8770 block_for_pc (loc->address), 0);
8772 error (_("Garbage '%s' follows condition"), arg);
8775 /* Dynamic printf requires and uses additional arguments on the
8776 command line, otherwise it's an error. */
8777 if (type == bp_dprintf)
8779 if (b->extra_string)
8780 update_dprintf_command_list (b);
8782 error (_("Format string required"));
8784 else if (b->extra_string)
8785 error (_("Garbage '%s' at end of command"), b->extra_string);
8788 b->display_canonical = display_canonical;
8790 b->addr_string = addr_string;
8792 /* addr_string has to be used or breakpoint_re_set will delete
8795 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
8800 create_breakpoint_sal (struct gdbarch *gdbarch,
8801 struct symtabs_and_lines sals, char *addr_string,
8802 char *filter, char *cond_string,
8804 enum bptype type, enum bpdisp disposition,
8805 int thread, int task, int ignore_count,
8806 const struct breakpoint_ops *ops, int from_tty,
8807 int enabled, int internal, unsigned flags,
8808 int display_canonical)
8810 struct breakpoint *b;
8811 struct cleanup *old_chain;
8813 if (is_tracepoint_type (type))
8815 struct tracepoint *t;
8817 t = XCNEW (struct tracepoint);
8821 b = XNEW (struct breakpoint);
8823 old_chain = make_cleanup (xfree, b);
8825 init_breakpoint_sal (b, gdbarch,
8827 filter, cond_string, extra_string,
8829 thread, task, ignore_count,
8831 enabled, internal, flags,
8833 discard_cleanups (old_chain);
8835 install_breakpoint (internal, b, 0);
8838 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8839 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8840 value. COND_STRING, if not NULL, specified the condition to be
8841 used for all breakpoints. Essentially the only case where
8842 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8843 function. In that case, it's still not possible to specify
8844 separate conditions for different overloaded functions, so
8845 we take just a single condition string.
8847 NOTE: If the function succeeds, the caller is expected to cleanup
8848 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8849 array contents). If the function fails (error() is called), the
8850 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8851 COND and SALS arrays and each of those arrays contents. */
8854 create_breakpoints_sal (struct gdbarch *gdbarch,
8855 struct linespec_result *canonical,
8856 char *cond_string, char *extra_string,
8857 enum bptype type, enum bpdisp disposition,
8858 int thread, int task, int ignore_count,
8859 const struct breakpoint_ops *ops, int from_tty,
8860 int enabled, int internal, unsigned flags)
8863 struct linespec_sals *lsal;
8865 if (canonical->pre_expanded)
8866 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
8868 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
8870 /* Note that 'addr_string' can be NULL in the case of a plain
8871 'break', without arguments. */
8872 char *addr_string = (canonical->addr_string
8873 ? xstrdup (canonical->addr_string)
8875 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
8876 struct cleanup *inner = make_cleanup (xfree, addr_string);
8878 make_cleanup (xfree, filter_string);
8879 create_breakpoint_sal (gdbarch, lsal->sals,
8882 cond_string, extra_string,
8884 thread, task, ignore_count, ops,
8885 from_tty, enabled, internal, flags,
8886 canonical->special_display);
8887 discard_cleanups (inner);
8891 /* Parse ADDRESS which is assumed to be a SAL specification possibly
8892 followed by conditionals. On return, SALS contains an array of SAL
8893 addresses found. ADDR_STRING contains a vector of (canonical)
8894 address strings. ADDRESS points to the end of the SAL.
8896 The array and the line spec strings are allocated on the heap, it is
8897 the caller's responsibility to free them. */
8900 parse_breakpoint_sals (char **address,
8901 struct linespec_result *canonical)
8903 char *addr_start = *address;
8905 /* If no arg given, or if first arg is 'if ', use the default
8907 if ((*address) == NULL
8908 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
8910 /* The last displayed codepoint, if it's valid, is our default breakpoint
8912 if (last_displayed_sal_is_valid ())
8914 struct linespec_sals lsal;
8915 struct symtab_and_line sal;
8917 init_sal (&sal); /* Initialize to zeroes. */
8918 lsal.sals.sals = (struct symtab_and_line *)
8919 xmalloc (sizeof (struct symtab_and_line));
8921 /* Set sal's pspace, pc, symtab, and line to the values
8922 corresponding to the last call to print_frame_info. */
8923 get_last_displayed_sal (&sal);
8924 sal.section = find_pc_overlay (sal.pc);
8926 /* "break" without arguments is equivalent to "break *PC"
8927 where PC is the last displayed codepoint's address. So
8928 make sure to set sal.explicit_pc to prevent GDB from
8929 trying to expand the list of sals to include all other
8930 instances with the same symtab and line. */
8931 sal.explicit_pc = 1;
8933 lsal.sals.sals[0] = sal;
8934 lsal.sals.nelts = 1;
8935 lsal.canonical = NULL;
8937 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
8940 error (_("No default breakpoint address now."));
8944 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
8946 /* Force almost all breakpoints to be in terms of the
8947 current_source_symtab (which is decode_line_1's default).
8948 This should produce the results we want almost all of the
8949 time while leaving default_breakpoint_* alone.
8951 ObjC: However, don't match an Objective-C method name which
8952 may have a '+' or '-' succeeded by a '['. */
8953 if (last_displayed_sal_is_valid ()
8955 || ((strchr ("+-", (*address)[0]) != NULL)
8956 && ((*address)[1] != '['))))
8957 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
8958 get_last_displayed_symtab (),
8959 get_last_displayed_line (),
8960 canonical, NULL, NULL);
8962 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
8963 cursal.symtab, cursal.line, canonical, NULL, NULL);
8968 /* Convert each SAL into a real PC. Verify that the PC can be
8969 inserted as a breakpoint. If it can't throw an error. */
8972 breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
8976 for (i = 0; i < sals->nelts; i++)
8977 resolve_sal_pc (&sals->sals[i]);
8980 /* Fast tracepoints may have restrictions on valid locations. For
8981 instance, a fast tracepoint using a jump instead of a trap will
8982 likely have to overwrite more bytes than a trap would, and so can
8983 only be placed where the instruction is longer than the jump, or a
8984 multi-instruction sequence does not have a jump into the middle of
8988 check_fast_tracepoint_sals (struct gdbarch *gdbarch,
8989 struct symtabs_and_lines *sals)
8992 struct symtab_and_line *sal;
8994 struct cleanup *old_chain;
8996 for (i = 0; i < sals->nelts; i++)
8998 struct gdbarch *sarch;
9000 sal = &sals->sals[i];
9002 sarch = get_sal_arch (*sal);
9003 /* We fall back to GDBARCH if there is no architecture
9004 associated with SAL. */
9007 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc,
9009 old_chain = make_cleanup (xfree, msg);
9012 error (_("May not have a fast tracepoint at 0x%s%s"),
9013 paddress (sarch, sal->pc), (msg ? msg : ""));
9015 do_cleanups (old_chain);
9019 /* Given TOK, a string specification of condition and thread, as
9020 accepted by the 'break' command, extract the condition
9021 string and thread number and set *COND_STRING and *THREAD.
9022 PC identifies the context at which the condition should be parsed.
9023 If no condition is found, *COND_STRING is set to NULL.
9024 If no thread is found, *THREAD is set to -1. */
9027 find_condition_and_thread (char *tok, CORE_ADDR pc,
9028 char **cond_string, int *thread, int *task,
9031 *cond_string = NULL;
9037 char *cond_start = NULL;
9038 char *cond_end = NULL;
9040 tok = skip_spaces (tok);
9042 if ((*tok == '"' || *tok == ',') && rest)
9044 *rest = savestring (tok, strlen (tok));
9048 end_tok = skip_to_space (tok);
9050 toklen = end_tok - tok;
9052 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9054 struct expression *expr;
9056 tok = cond_start = end_tok + 1;
9057 expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
9060 *cond_string = savestring (cond_start, cond_end - cond_start);
9062 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9068 *thread = strtol (tok, &tok, 0);
9070 error (_("Junk after thread keyword."));
9071 if (!valid_thread_id (*thread))
9072 error (_("Unknown thread %d."), *thread);
9074 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9080 *task = strtol (tok, &tok, 0);
9082 error (_("Junk after task keyword."));
9083 if (!valid_task_id (*task))
9084 error (_("Unknown task %d."), *task);
9088 *rest = savestring (tok, strlen (tok));
9092 error (_("Junk at end of arguments."));
9096 /* Decode a static tracepoint marker spec. */
9098 static struct symtabs_and_lines
9099 decode_static_tracepoint_spec (char **arg_p)
9101 VEC(static_tracepoint_marker_p) *markers = NULL;
9102 struct symtabs_and_lines sals;
9103 struct cleanup *old_chain;
9104 char *p = &(*arg_p)[3];
9109 p = skip_spaces (p);
9111 endp = skip_to_space (p);
9113 marker_str = savestring (p, endp - p);
9114 old_chain = make_cleanup (xfree, marker_str);
9116 markers = target_static_tracepoint_markers_by_strid (marker_str);
9117 if (VEC_empty(static_tracepoint_marker_p, markers))
9118 error (_("No known static tracepoint marker named %s"), marker_str);
9120 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
9121 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
9123 for (i = 0; i < sals.nelts; i++)
9125 struct static_tracepoint_marker *marker;
9127 marker = VEC_index (static_tracepoint_marker_p, markers, i);
9129 init_sal (&sals.sals[i]);
9131 sals.sals[i] = find_pc_line (marker->address, 0);
9132 sals.sals[i].pc = marker->address;
9134 release_static_tracepoint_marker (marker);
9137 do_cleanups (old_chain);
9143 /* Set a breakpoint. This function is shared between CLI and MI
9144 functions for setting a breakpoint. This function has two major
9145 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
9146 parameter. If non-zero, the function will parse arg, extracting
9147 breakpoint location, address and thread. Otherwise, ARG is just
9148 the location of breakpoint, with condition and thread specified by
9149 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
9150 the breakpoint number will be allocated from the internal
9151 breakpoint count. Returns true if any breakpoint was created;
9155 create_breakpoint (struct gdbarch *gdbarch,
9156 char *arg, char *cond_string,
9157 int thread, char *extra_string,
9158 int parse_condition_and_thread,
9159 int tempflag, enum bptype type_wanted,
9161 enum auto_boolean pending_break_support,
9162 const struct breakpoint_ops *ops,
9163 int from_tty, int enabled, int internal,
9166 volatile struct gdb_exception e;
9167 char *copy_arg = NULL;
9168 char *addr_start = arg;
9169 struct linespec_result canonical;
9170 struct cleanup *old_chain;
9171 struct cleanup *bkpt_chain = NULL;
9174 int prev_bkpt_count = breakpoint_count;
9176 gdb_assert (ops != NULL);
9178 init_linespec_result (&canonical);
9180 TRY_CATCH (e, RETURN_MASK_ALL)
9182 ops->create_sals_from_address (&arg, &canonical, type_wanted,
9183 addr_start, ©_arg);
9186 /* If caller is interested in rc value from parse, set value. */
9190 if (VEC_empty (linespec_sals, canonical.sals))
9196 case NOT_FOUND_ERROR:
9198 /* If pending breakpoint support is turned off, throw
9201 if (pending_break_support == AUTO_BOOLEAN_FALSE)
9202 throw_exception (e);
9204 exception_print (gdb_stderr, e);
9206 /* If pending breakpoint support is auto query and the user
9207 selects no, then simply return the error code. */
9208 if (pending_break_support == AUTO_BOOLEAN_AUTO
9209 && !nquery (_("Make %s pending on future shared library load? "),
9210 bptype_string (type_wanted)))
9213 /* At this point, either the user was queried about setting
9214 a pending breakpoint and selected yes, or pending
9215 breakpoint behavior is on and thus a pending breakpoint
9216 is defaulted on behalf of the user. */
9218 struct linespec_sals lsal;
9220 copy_arg = xstrdup (addr_start);
9221 lsal.canonical = xstrdup (copy_arg);
9222 lsal.sals.nelts = 1;
9223 lsal.sals.sals = XNEW (struct symtab_and_line);
9224 init_sal (&lsal.sals.sals[0]);
9226 VEC_safe_push (linespec_sals, canonical.sals, &lsal);
9230 throw_exception (e);
9234 throw_exception (e);
9237 /* Create a chain of things that always need to be cleaned up. */
9238 old_chain = make_cleanup_destroy_linespec_result (&canonical);
9240 /* ----------------------------- SNIP -----------------------------
9241 Anything added to the cleanup chain beyond this point is assumed
9242 to be part of a breakpoint. If the breakpoint create succeeds
9243 then the memory is not reclaimed. */
9244 bkpt_chain = make_cleanup (null_cleanup, 0);
9246 /* Resolve all line numbers to PC's and verify that the addresses
9247 are ok for the target. */
9251 struct linespec_sals *iter;
9253 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9254 breakpoint_sals_to_pc (&iter->sals);
9257 /* Fast tracepoints may have additional restrictions on location. */
9258 if (!pending && type_wanted == bp_fast_tracepoint)
9261 struct linespec_sals *iter;
9263 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9264 check_fast_tracepoint_sals (gdbarch, &iter->sals);
9267 /* Verify that condition can be parsed, before setting any
9268 breakpoints. Allocate a separate condition expression for each
9272 struct linespec_sals *lsal;
9274 lsal = VEC_index (linespec_sals, canonical.sals, 0);
9276 if (parse_condition_and_thread)
9279 /* Here we only parse 'arg' to separate condition
9280 from thread number, so parsing in context of first
9281 sal is OK. When setting the breakpoint we'll
9282 re-parse it in context of each sal. */
9286 find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string,
9287 &thread, &task, &rest);
9289 make_cleanup (xfree, cond_string);
9291 make_cleanup (xfree, rest);
9293 extra_string = rest;
9297 /* Create a private copy of condition string. */
9300 cond_string = xstrdup (cond_string);
9301 make_cleanup (xfree, cond_string);
9303 /* Create a private copy of any extra string. */
9306 extra_string = xstrdup (extra_string);
9307 make_cleanup (xfree, extra_string);
9311 ops->create_breakpoints_sal (gdbarch, &canonical, lsal,
9312 cond_string, extra_string, type_wanted,
9313 tempflag ? disp_del : disp_donttouch,
9314 thread, task, ignore_count, ops,
9315 from_tty, enabled, internal, flags);
9319 struct breakpoint *b;
9321 make_cleanup (xfree, copy_arg);
9323 if (is_tracepoint_type (type_wanted))
9325 struct tracepoint *t;
9327 t = XCNEW (struct tracepoint);
9331 b = XNEW (struct breakpoint);
9333 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
9335 b->addr_string = copy_arg;
9336 b->cond_string = NULL;
9337 b->extra_string = NULL;
9338 b->ignore_count = ignore_count;
9339 b->disposition = tempflag ? disp_del : disp_donttouch;
9340 b->condition_not_parsed = 1;
9341 b->enable_state = enabled ? bp_enabled : bp_disabled;
9342 if ((type_wanted != bp_breakpoint
9343 && type_wanted != bp_hardware_breakpoint) || thread != -1)
9344 b->pspace = current_program_space;
9346 install_breakpoint (internal, b, 0);
9349 if (VEC_length (linespec_sals, canonical.sals) > 1)
9351 warning (_("Multiple breakpoints were set.\nUse the "
9352 "\"delete\" command to delete unwanted breakpoints."));
9353 prev_breakpoint_count = prev_bkpt_count;
9356 /* That's it. Discard the cleanups for data inserted into the
9358 discard_cleanups (bkpt_chain);
9359 /* But cleanup everything else. */
9360 do_cleanups (old_chain);
9362 /* error call may happen here - have BKPT_CHAIN already discarded. */
9363 update_global_location_list (1);
9368 /* Set a breakpoint.
9369 ARG is a string describing breakpoint address,
9370 condition, and thread.
9371 FLAG specifies if a breakpoint is hardware on,
9372 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9376 break_command_1 (char *arg, int flag, int from_tty)
9378 int tempflag = flag & BP_TEMPFLAG;
9379 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9380 ? bp_hardware_breakpoint
9382 struct breakpoint_ops *ops;
9383 const char *arg_cp = arg;
9385 /* Matching breakpoints on probes. */
9386 if (arg && probe_linespec_to_ops (&arg_cp) != NULL)
9387 ops = &bkpt_probe_breakpoint_ops;
9389 ops = &bkpt_breakpoint_ops;
9391 create_breakpoint (get_current_arch (),
9393 NULL, 0, NULL, 1 /* parse arg */,
9394 tempflag, type_wanted,
9395 0 /* Ignore count */,
9396 pending_break_support,
9404 /* Helper function for break_command_1 and disassemble_command. */
9407 resolve_sal_pc (struct symtab_and_line *sal)
9411 if (sal->pc == 0 && sal->symtab != NULL)
9413 if (!find_line_pc (sal->symtab, sal->line, &pc))
9414 error (_("No line %d in file \"%s\"."),
9415 sal->line, sal->symtab->filename);
9418 /* If this SAL corresponds to a breakpoint inserted using a line
9419 number, then skip the function prologue if necessary. */
9420 if (sal->explicit_line)
9421 skip_prologue_sal (sal);
9424 if (sal->section == 0 && sal->symtab != NULL)
9426 struct blockvector *bv;
9430 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
9433 sym = block_linkage_function (b);
9436 fixup_symbol_section (sym, sal->symtab->objfile);
9437 sal->section = SYMBOL_OBJ_SECTION (sym);
9441 /* It really is worthwhile to have the section, so we'll
9442 just have to look harder. This case can be executed
9443 if we have line numbers but no functions (as can
9444 happen in assembly source). */
9446 struct minimal_symbol *msym;
9447 struct cleanup *old_chain = save_current_space_and_thread ();
9449 switch_to_program_space_and_thread (sal->pspace);
9451 msym = lookup_minimal_symbol_by_pc (sal->pc);
9453 sal->section = SYMBOL_OBJ_SECTION (msym);
9455 do_cleanups (old_chain);
9462 break_command (char *arg, int from_tty)
9464 break_command_1 (arg, 0, from_tty);
9468 tbreak_command (char *arg, int from_tty)
9470 break_command_1 (arg, BP_TEMPFLAG, from_tty);
9474 hbreak_command (char *arg, int from_tty)
9476 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
9480 thbreak_command (char *arg, int from_tty)
9482 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
9486 stop_command (char *arg, int from_tty)
9488 printf_filtered (_("Specify the type of breakpoint to set.\n\
9489 Usage: stop in <function | address>\n\
9490 stop at <line>\n"));
9494 stopin_command (char *arg, int from_tty)
9498 if (arg == (char *) NULL)
9500 else if (*arg != '*')
9505 /* Look for a ':'. If this is a line number specification, then
9506 say it is bad, otherwise, it should be an address or
9507 function/method name. */
9508 while (*argptr && !hasColon)
9510 hasColon = (*argptr == ':');
9515 badInput = (*argptr != ':'); /* Not a class::method */
9517 badInput = isdigit (*arg); /* a simple line number */
9521 printf_filtered (_("Usage: stop in <function | address>\n"));
9523 break_command_1 (arg, 0, from_tty);
9527 stopat_command (char *arg, int from_tty)
9531 if (arg == (char *) NULL || *arg == '*') /* no line number */
9538 /* Look for a ':'. If there is a '::' then get out, otherwise
9539 it is probably a line number. */
9540 while (*argptr && !hasColon)
9542 hasColon = (*argptr == ':');
9547 badInput = (*argptr == ':'); /* we have class::method */
9549 badInput = !isdigit (*arg); /* not a line number */
9553 printf_filtered (_("Usage: stop at <line>\n"));
9555 break_command_1 (arg, 0, from_tty);
9558 void dprintf_command (char *arg, int from_tty);
9560 /* The dynamic printf command is mostly like a regular breakpoint, but
9561 with a prewired command list consisting of a single output command,
9562 built from extra arguments supplied on the dprintf command
9566 dprintf_command (char *arg, int from_tty)
9568 create_breakpoint (get_current_arch (),
9570 NULL, 0, NULL, 1 /* parse arg */,
9572 0 /* Ignore count */,
9573 pending_break_support,
9574 &dprintf_breakpoint_ops,
9581 /* Implement the "breakpoint_hit" breakpoint_ops method for
9582 ranged breakpoints. */
9585 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
9586 struct address_space *aspace,
9588 const struct target_waitstatus *ws)
9590 if (ws->kind != TARGET_WAITKIND_STOPPED
9591 || ws->value.sig != GDB_SIGNAL_TRAP)
9594 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
9595 bl->length, aspace, bp_addr);
9598 /* Implement the "resources_needed" breakpoint_ops method for
9599 ranged breakpoints. */
9602 resources_needed_ranged_breakpoint (const struct bp_location *bl)
9604 return target_ranged_break_num_registers ();
9607 /* Implement the "print_it" breakpoint_ops method for
9608 ranged breakpoints. */
9610 static enum print_stop_action
9611 print_it_ranged_breakpoint (bpstat bs)
9613 struct breakpoint *b = bs->breakpoint_at;
9614 struct bp_location *bl = b->loc;
9615 struct ui_out *uiout = current_uiout;
9617 gdb_assert (b->type == bp_hardware_breakpoint);
9619 /* Ranged breakpoints have only one location. */
9620 gdb_assert (bl && bl->next == NULL);
9622 annotate_breakpoint (b->number);
9623 if (b->disposition == disp_del)
9624 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
9626 ui_out_text (uiout, "\nRanged breakpoint ");
9627 if (ui_out_is_mi_like_p (uiout))
9629 ui_out_field_string (uiout, "reason",
9630 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
9631 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
9633 ui_out_field_int (uiout, "bkptno", b->number);
9634 ui_out_text (uiout, ", ");
9636 return PRINT_SRC_AND_LOC;
9639 /* Implement the "print_one" breakpoint_ops method for
9640 ranged breakpoints. */
9643 print_one_ranged_breakpoint (struct breakpoint *b,
9644 struct bp_location **last_loc)
9646 struct bp_location *bl = b->loc;
9647 struct value_print_options opts;
9648 struct ui_out *uiout = current_uiout;
9650 /* Ranged breakpoints have only one location. */
9651 gdb_assert (bl && bl->next == NULL);
9653 get_user_print_options (&opts);
9655 if (opts.addressprint)
9656 /* We don't print the address range here, it will be printed later
9657 by print_one_detail_ranged_breakpoint. */
9658 ui_out_field_skip (uiout, "addr");
9660 print_breakpoint_location (b, bl);
9664 /* Implement the "print_one_detail" breakpoint_ops method for
9665 ranged breakpoints. */
9668 print_one_detail_ranged_breakpoint (const struct breakpoint *b,
9669 struct ui_out *uiout)
9671 CORE_ADDR address_start, address_end;
9672 struct bp_location *bl = b->loc;
9673 struct ui_file *stb = mem_fileopen ();
9674 struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
9678 address_start = bl->address;
9679 address_end = address_start + bl->length - 1;
9681 ui_out_text (uiout, "\taddress range: ");
9682 fprintf_unfiltered (stb, "[%s, %s]",
9683 print_core_address (bl->gdbarch, address_start),
9684 print_core_address (bl->gdbarch, address_end));
9685 ui_out_field_stream (uiout, "addr", stb);
9686 ui_out_text (uiout, "\n");
9688 do_cleanups (cleanup);
9691 /* Implement the "print_mention" breakpoint_ops method for
9692 ranged breakpoints. */
9695 print_mention_ranged_breakpoint (struct breakpoint *b)
9697 struct bp_location *bl = b->loc;
9698 struct ui_out *uiout = current_uiout;
9701 gdb_assert (b->type == bp_hardware_breakpoint);
9703 if (ui_out_is_mi_like_p (uiout))
9706 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9707 b->number, paddress (bl->gdbarch, bl->address),
9708 paddress (bl->gdbarch, bl->address + bl->length - 1));
9711 /* Implement the "print_recreate" breakpoint_ops method for
9712 ranged breakpoints. */
9715 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
9717 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
9718 b->addr_string_range_end);
9719 print_recreate_thread (b, fp);
9722 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9724 static struct breakpoint_ops ranged_breakpoint_ops;
9726 /* Find the address where the end of the breakpoint range should be
9727 placed, given the SAL of the end of the range. This is so that if
9728 the user provides a line number, the end of the range is set to the
9729 last instruction of the given line. */
9732 find_breakpoint_range_end (struct symtab_and_line sal)
9736 /* If the user provided a PC value, use it. Otherwise,
9737 find the address of the end of the given location. */
9738 if (sal.explicit_pc)
9745 ret = find_line_pc_range (sal, &start, &end);
9747 error (_("Could not find location of the end of the range."));
9749 /* find_line_pc_range returns the start of the next line. */
9756 /* Implement the "break-range" CLI command. */
9759 break_range_command (char *arg, int from_tty)
9761 char *arg_start, *addr_string_start, *addr_string_end;
9762 struct linespec_result canonical_start, canonical_end;
9763 int bp_count, can_use_bp, length;
9765 struct breakpoint *b;
9766 struct symtab_and_line sal_start, sal_end;
9767 struct cleanup *cleanup_bkpt;
9768 struct linespec_sals *lsal_start, *lsal_end;
9770 /* We don't support software ranged breakpoints. */
9771 if (target_ranged_break_num_registers () < 0)
9772 error (_("This target does not support hardware ranged breakpoints."));
9774 bp_count = hw_breakpoint_used_count ();
9775 bp_count += target_ranged_break_num_registers ();
9776 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9779 error (_("Hardware breakpoints used exceeds limit."));
9781 arg = skip_spaces (arg);
9782 if (arg == NULL || arg[0] == '\0')
9783 error(_("No address range specified."));
9785 init_linespec_result (&canonical_start);
9788 parse_breakpoint_sals (&arg, &canonical_start);
9790 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
9793 error (_("Too few arguments."));
9794 else if (VEC_empty (linespec_sals, canonical_start.sals))
9795 error (_("Could not find location of the beginning of the range."));
9797 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
9799 if (VEC_length (linespec_sals, canonical_start.sals) > 1
9800 || lsal_start->sals.nelts != 1)
9801 error (_("Cannot create a ranged breakpoint with multiple locations."));
9803 sal_start = lsal_start->sals.sals[0];
9804 addr_string_start = savestring (arg_start, arg - arg_start);
9805 make_cleanup (xfree, addr_string_start);
9807 arg++; /* Skip the comma. */
9808 arg = skip_spaces (arg);
9810 /* Parse the end location. */
9812 init_linespec_result (&canonical_end);
9815 /* We call decode_line_full directly here instead of using
9816 parse_breakpoint_sals because we need to specify the start location's
9817 symtab and line as the default symtab and line for the end of the
9818 range. This makes it possible to have ranges like "foo.c:27, +14",
9819 where +14 means 14 lines from the start location. */
9820 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
9821 sal_start.symtab, sal_start.line,
9822 &canonical_end, NULL, NULL);
9824 make_cleanup_destroy_linespec_result (&canonical_end);
9826 if (VEC_empty (linespec_sals, canonical_end.sals))
9827 error (_("Could not find location of the end of the range."));
9829 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
9830 if (VEC_length (linespec_sals, canonical_end.sals) > 1
9831 || lsal_end->sals.nelts != 1)
9832 error (_("Cannot create a ranged breakpoint with multiple locations."));
9834 sal_end = lsal_end->sals.sals[0];
9835 addr_string_end = savestring (arg_start, arg - arg_start);
9836 make_cleanup (xfree, addr_string_end);
9838 end = find_breakpoint_range_end (sal_end);
9839 if (sal_start.pc > end)
9840 error (_("Invalid address range, end precedes start."));
9842 length = end - sal_start.pc + 1;
9844 /* Length overflowed. */
9845 error (_("Address range too large."));
9846 else if (length == 1)
9848 /* This range is simple enough to be handled by
9849 the `hbreak' command. */
9850 hbreak_command (addr_string_start, 1);
9852 do_cleanups (cleanup_bkpt);
9857 /* Now set up the breakpoint. */
9858 b = set_raw_breakpoint (get_current_arch (), sal_start,
9859 bp_hardware_breakpoint, &ranged_breakpoint_ops);
9860 set_breakpoint_count (breakpoint_count + 1);
9861 b->number = breakpoint_count;
9862 b->disposition = disp_donttouch;
9863 b->addr_string = xstrdup (addr_string_start);
9864 b->addr_string_range_end = xstrdup (addr_string_end);
9865 b->loc->length = length;
9867 do_cleanups (cleanup_bkpt);
9870 observer_notify_breakpoint_created (b);
9871 update_global_location_list (1);
9874 /* Return non-zero if EXP is verified as constant. Returned zero
9875 means EXP is variable. Also the constant detection may fail for
9876 some constant expressions and in such case still falsely return
9880 watchpoint_exp_is_const (const struct expression *exp)
9888 /* We are only interested in the descriptor of each element. */
9889 operator_length (exp, i, &oplenp, &argsp);
9892 switch (exp->elts[i].opcode)
9902 case BINOP_LOGICAL_AND:
9903 case BINOP_LOGICAL_OR:
9904 case BINOP_BITWISE_AND:
9905 case BINOP_BITWISE_IOR:
9906 case BINOP_BITWISE_XOR:
9908 case BINOP_NOTEQUAL:
9924 case TERNOP_SLICE_COUNT:
9936 case OP_OBJC_NSSTRING:
9939 case UNOP_LOGICAL_NOT:
9940 case UNOP_COMPLEMENT:
9944 /* Unary, binary and ternary operators: We have to check
9945 their operands. If they are constant, then so is the
9946 result of that operation. For instance, if A and B are
9947 determined to be constants, then so is "A + B".
9949 UNOP_IND is one exception to the rule above, because the
9950 value of *ADDR is not necessarily a constant, even when
9955 /* Check whether the associated symbol is a constant.
9957 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9958 possible that a buggy compiler could mark a variable as
9959 constant even when it is not, and TYPE_CONST would return
9960 true in this case, while SYMBOL_CLASS wouldn't.
9962 We also have to check for function symbols because they
9963 are always constant. */
9965 struct symbol *s = exp->elts[i + 2].symbol;
9967 if (SYMBOL_CLASS (s) != LOC_BLOCK
9968 && SYMBOL_CLASS (s) != LOC_CONST
9969 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
9974 /* The default action is to return 0 because we are using
9975 the optimistic approach here: If we don't know something,
9976 then it is not a constant. */
9985 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
9988 dtor_watchpoint (struct breakpoint *self)
9990 struct watchpoint *w = (struct watchpoint *) self;
9992 xfree (w->cond_exp);
9994 xfree (w->exp_string);
9995 xfree (w->exp_string_reparse);
9996 value_free (w->val);
9998 base_breakpoint_ops.dtor (self);
10001 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10004 re_set_watchpoint (struct breakpoint *b)
10006 struct watchpoint *w = (struct watchpoint *) b;
10008 /* Watchpoint can be either on expression using entirely global
10009 variables, or it can be on local variables.
10011 Watchpoints of the first kind are never auto-deleted, and even
10012 persist across program restarts. Since they can use variables
10013 from shared libraries, we need to reparse expression as libraries
10014 are loaded and unloaded.
10016 Watchpoints on local variables can also change meaning as result
10017 of solib event. For example, if a watchpoint uses both a local
10018 and a global variables in expression, it's a local watchpoint,
10019 but unloading of a shared library will make the expression
10020 invalid. This is not a very common use case, but we still
10021 re-evaluate expression, to avoid surprises to the user.
10023 Note that for local watchpoints, we re-evaluate it only if
10024 watchpoints frame id is still valid. If it's not, it means the
10025 watchpoint is out of scope and will be deleted soon. In fact,
10026 I'm not sure we'll ever be called in this case.
10028 If a local watchpoint's frame id is still valid, then
10029 w->exp_valid_block is likewise valid, and we can safely use it.
10031 Don't do anything about disabled watchpoints, since they will be
10032 reevaluated again when enabled. */
10033 update_watchpoint (w, 1 /* reparse */);
10036 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10039 insert_watchpoint (struct bp_location *bl)
10041 struct watchpoint *w = (struct watchpoint *) bl->owner;
10042 int length = w->exact ? 1 : bl->length;
10044 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10048 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10051 remove_watchpoint (struct bp_location *bl)
10053 struct watchpoint *w = (struct watchpoint *) bl->owner;
10054 int length = w->exact ? 1 : bl->length;
10056 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10061 breakpoint_hit_watchpoint (const struct bp_location *bl,
10062 struct address_space *aspace, CORE_ADDR bp_addr,
10063 const struct target_waitstatus *ws)
10065 struct breakpoint *b = bl->owner;
10066 struct watchpoint *w = (struct watchpoint *) b;
10068 /* Continuable hardware watchpoints are treated as non-existent if the
10069 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10070 some data address). Otherwise gdb won't stop on a break instruction
10071 in the code (not from a breakpoint) when a hardware watchpoint has
10072 been defined. Also skip watchpoints which we know did not trigger
10073 (did not match the data address). */
10074 if (is_hardware_watchpoint (b)
10075 && w->watchpoint_triggered == watch_triggered_no)
10082 check_status_watchpoint (bpstat bs)
10084 gdb_assert (is_watchpoint (bs->breakpoint_at));
10086 bpstat_check_watchpoint (bs);
10089 /* Implement the "resources_needed" breakpoint_ops method for
10090 hardware watchpoints. */
10093 resources_needed_watchpoint (const struct bp_location *bl)
10095 struct watchpoint *w = (struct watchpoint *) bl->owner;
10096 int length = w->exact? 1 : bl->length;
10098 return target_region_ok_for_hw_watchpoint (bl->address, length);
10101 /* Implement the "works_in_software_mode" breakpoint_ops method for
10102 hardware watchpoints. */
10105 works_in_software_mode_watchpoint (const struct breakpoint *b)
10107 /* Read and access watchpoints only work with hardware support. */
10108 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10111 static enum print_stop_action
10112 print_it_watchpoint (bpstat bs)
10114 struct cleanup *old_chain;
10115 struct breakpoint *b;
10116 const struct bp_location *bl;
10117 struct ui_file *stb;
10118 enum print_stop_action result;
10119 struct watchpoint *w;
10120 struct ui_out *uiout = current_uiout;
10122 gdb_assert (bs->bp_location_at != NULL);
10124 bl = bs->bp_location_at;
10125 b = bs->breakpoint_at;
10126 w = (struct watchpoint *) b;
10128 stb = mem_fileopen ();
10129 old_chain = make_cleanup_ui_file_delete (stb);
10133 case bp_watchpoint:
10134 case bp_hardware_watchpoint:
10135 annotate_watchpoint (b->number);
10136 if (ui_out_is_mi_like_p (uiout))
10137 ui_out_field_string
10139 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10141 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10142 ui_out_text (uiout, "\nOld value = ");
10143 watchpoint_value_print (bs->old_val, stb);
10144 ui_out_field_stream (uiout, "old", stb);
10145 ui_out_text (uiout, "\nNew value = ");
10146 watchpoint_value_print (w->val, stb);
10147 ui_out_field_stream (uiout, "new", stb);
10148 ui_out_text (uiout, "\n");
10149 /* More than one watchpoint may have been triggered. */
10150 result = PRINT_UNKNOWN;
10153 case bp_read_watchpoint:
10154 if (ui_out_is_mi_like_p (uiout))
10155 ui_out_field_string
10157 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10159 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10160 ui_out_text (uiout, "\nValue = ");
10161 watchpoint_value_print (w->val, stb);
10162 ui_out_field_stream (uiout, "value", stb);
10163 ui_out_text (uiout, "\n");
10164 result = PRINT_UNKNOWN;
10167 case bp_access_watchpoint:
10168 if (bs->old_val != NULL)
10170 annotate_watchpoint (b->number);
10171 if (ui_out_is_mi_like_p (uiout))
10172 ui_out_field_string
10174 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10176 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10177 ui_out_text (uiout, "\nOld value = ");
10178 watchpoint_value_print (bs->old_val, stb);
10179 ui_out_field_stream (uiout, "old", stb);
10180 ui_out_text (uiout, "\nNew value = ");
10185 if (ui_out_is_mi_like_p (uiout))
10186 ui_out_field_string
10188 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10189 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10190 ui_out_text (uiout, "\nValue = ");
10192 watchpoint_value_print (w->val, stb);
10193 ui_out_field_stream (uiout, "new", stb);
10194 ui_out_text (uiout, "\n");
10195 result = PRINT_UNKNOWN;
10198 result = PRINT_UNKNOWN;
10201 do_cleanups (old_chain);
10205 /* Implement the "print_mention" breakpoint_ops method for hardware
10209 print_mention_watchpoint (struct breakpoint *b)
10211 struct cleanup *ui_out_chain;
10212 struct watchpoint *w = (struct watchpoint *) b;
10213 struct ui_out *uiout = current_uiout;
10217 case bp_watchpoint:
10218 ui_out_text (uiout, "Watchpoint ");
10219 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10221 case bp_hardware_watchpoint:
10222 ui_out_text (uiout, "Hardware watchpoint ");
10223 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10225 case bp_read_watchpoint:
10226 ui_out_text (uiout, "Hardware read watchpoint ");
10227 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10229 case bp_access_watchpoint:
10230 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
10231 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10234 internal_error (__FILE__, __LINE__,
10235 _("Invalid hardware watchpoint type."));
10238 ui_out_field_int (uiout, "number", b->number);
10239 ui_out_text (uiout, ": ");
10240 ui_out_field_string (uiout, "exp", w->exp_string);
10241 do_cleanups (ui_out_chain);
10244 /* Implement the "print_recreate" breakpoint_ops method for
10248 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10250 struct watchpoint *w = (struct watchpoint *) b;
10254 case bp_watchpoint:
10255 case bp_hardware_watchpoint:
10256 fprintf_unfiltered (fp, "watch");
10258 case bp_read_watchpoint:
10259 fprintf_unfiltered (fp, "rwatch");
10261 case bp_access_watchpoint:
10262 fprintf_unfiltered (fp, "awatch");
10265 internal_error (__FILE__, __LINE__,
10266 _("Invalid watchpoint type."));
10269 fprintf_unfiltered (fp, " %s", w->exp_string);
10270 print_recreate_thread (b, fp);
10273 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10275 static struct breakpoint_ops watchpoint_breakpoint_ops;
10277 /* Implement the "insert" breakpoint_ops method for
10278 masked hardware watchpoints. */
10281 insert_masked_watchpoint (struct bp_location *bl)
10283 struct watchpoint *w = (struct watchpoint *) bl->owner;
10285 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
10286 bl->watchpoint_type);
10289 /* Implement the "remove" breakpoint_ops method for
10290 masked hardware watchpoints. */
10293 remove_masked_watchpoint (struct bp_location *bl)
10295 struct watchpoint *w = (struct watchpoint *) bl->owner;
10297 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
10298 bl->watchpoint_type);
10301 /* Implement the "resources_needed" breakpoint_ops method for
10302 masked hardware watchpoints. */
10305 resources_needed_masked_watchpoint (const struct bp_location *bl)
10307 struct watchpoint *w = (struct watchpoint *) bl->owner;
10309 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
10312 /* Implement the "works_in_software_mode" breakpoint_ops method for
10313 masked hardware watchpoints. */
10316 works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
10321 /* Implement the "print_it" breakpoint_ops method for
10322 masked hardware watchpoints. */
10324 static enum print_stop_action
10325 print_it_masked_watchpoint (bpstat bs)
10327 struct breakpoint *b = bs->breakpoint_at;
10328 struct ui_out *uiout = current_uiout;
10330 /* Masked watchpoints have only one location. */
10331 gdb_assert (b->loc && b->loc->next == NULL);
10335 case bp_hardware_watchpoint:
10336 annotate_watchpoint (b->number);
10337 if (ui_out_is_mi_like_p (uiout))
10338 ui_out_field_string
10340 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10343 case bp_read_watchpoint:
10344 if (ui_out_is_mi_like_p (uiout))
10345 ui_out_field_string
10347 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10350 case bp_access_watchpoint:
10351 if (ui_out_is_mi_like_p (uiout))
10352 ui_out_field_string
10354 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10357 internal_error (__FILE__, __LINE__,
10358 _("Invalid hardware watchpoint type."));
10362 ui_out_text (uiout, _("\n\
10363 Check the underlying instruction at PC for the memory\n\
10364 address and value which triggered this watchpoint.\n"));
10365 ui_out_text (uiout, "\n");
10367 /* More than one watchpoint may have been triggered. */
10368 return PRINT_UNKNOWN;
10371 /* Implement the "print_one_detail" breakpoint_ops method for
10372 masked hardware watchpoints. */
10375 print_one_detail_masked_watchpoint (const struct breakpoint *b,
10376 struct ui_out *uiout)
10378 struct watchpoint *w = (struct watchpoint *) b;
10380 /* Masked watchpoints have only one location. */
10381 gdb_assert (b->loc && b->loc->next == NULL);
10383 ui_out_text (uiout, "\tmask ");
10384 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
10385 ui_out_text (uiout, "\n");
10388 /* Implement the "print_mention" breakpoint_ops method for
10389 masked hardware watchpoints. */
10392 print_mention_masked_watchpoint (struct breakpoint *b)
10394 struct watchpoint *w = (struct watchpoint *) b;
10395 struct ui_out *uiout = current_uiout;
10396 struct cleanup *ui_out_chain;
10400 case bp_hardware_watchpoint:
10401 ui_out_text (uiout, "Masked hardware watchpoint ");
10402 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10404 case bp_read_watchpoint:
10405 ui_out_text (uiout, "Masked hardware read watchpoint ");
10406 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10408 case bp_access_watchpoint:
10409 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
10410 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10413 internal_error (__FILE__, __LINE__,
10414 _("Invalid hardware watchpoint type."));
10417 ui_out_field_int (uiout, "number", b->number);
10418 ui_out_text (uiout, ": ");
10419 ui_out_field_string (uiout, "exp", w->exp_string);
10420 do_cleanups (ui_out_chain);
10423 /* Implement the "print_recreate" breakpoint_ops method for
10424 masked hardware watchpoints. */
10427 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
10429 struct watchpoint *w = (struct watchpoint *) b;
10434 case bp_hardware_watchpoint:
10435 fprintf_unfiltered (fp, "watch");
10437 case bp_read_watchpoint:
10438 fprintf_unfiltered (fp, "rwatch");
10440 case bp_access_watchpoint:
10441 fprintf_unfiltered (fp, "awatch");
10444 internal_error (__FILE__, __LINE__,
10445 _("Invalid hardware watchpoint type."));
10448 sprintf_vma (tmp, w->hw_wp_mask);
10449 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
10450 print_recreate_thread (b, fp);
10453 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10455 static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
10457 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10460 is_masked_watchpoint (const struct breakpoint *b)
10462 return b->ops == &masked_watchpoint_breakpoint_ops;
10465 /* accessflag: hw_write: watch write,
10466 hw_read: watch read,
10467 hw_access: watch access (read or write) */
10469 watch_command_1 (char *arg, int accessflag, int from_tty,
10470 int just_location, int internal)
10472 volatile struct gdb_exception e;
10473 struct breakpoint *b, *scope_breakpoint = NULL;
10474 struct expression *exp;
10475 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
10476 struct value *val, *mark, *result;
10477 struct frame_info *frame;
10478 char *exp_start = NULL;
10479 char *exp_end = NULL;
10480 char *tok, *end_tok;
10482 char *cond_start = NULL;
10483 char *cond_end = NULL;
10484 enum bptype bp_type;
10487 /* Flag to indicate whether we are going to use masks for
10488 the hardware watchpoint. */
10490 CORE_ADDR mask = 0;
10491 struct watchpoint *w;
10493 /* Make sure that we actually have parameters to parse. */
10494 if (arg != NULL && arg[0] != '\0')
10498 /* Look for "parameter value" pairs at the end
10499 of the arguments string. */
10500 for (tok = arg + strlen (arg) - 1; tok > arg; tok--)
10502 /* Skip whitespace at the end of the argument list. */
10503 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10506 /* Find the beginning of the last token.
10507 This is the value of the parameter. */
10508 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10510 value_start = tok + 1;
10512 /* Skip whitespace. */
10513 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10518 /* Find the beginning of the second to last token.
10519 This is the parameter itself. */
10520 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10523 toklen = end_tok - tok + 1;
10525 if (toklen == 6 && !strncmp (tok, "thread", 6))
10527 /* At this point we've found a "thread" token, which means
10528 the user is trying to set a watchpoint that triggers
10529 only in a specific thread. */
10533 error(_("You can specify only one thread."));
10535 /* Extract the thread ID from the next token. */
10536 thread = strtol (value_start, &endp, 0);
10538 /* Check if the user provided a valid numeric value for the
10540 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
10541 error (_("Invalid thread ID specification %s."), value_start);
10543 /* Check if the thread actually exists. */
10544 if (!valid_thread_id (thread))
10545 error (_("Unknown thread %d."), thread);
10547 else if (toklen == 4 && !strncmp (tok, "mask", 4))
10549 /* We've found a "mask" token, which means the user wants to
10550 create a hardware watchpoint that is going to have the mask
10552 struct value *mask_value, *mark;
10555 error(_("You can specify only one mask."));
10557 use_mask = just_location = 1;
10559 mark = value_mark ();
10560 mask_value = parse_to_comma_and_eval (&value_start);
10561 mask = value_as_address (mask_value);
10562 value_free_to_mark (mark);
10565 /* We didn't recognize what we found. We should stop here. */
10568 /* Truncate the string and get rid of the "parameter value" pair before
10569 the arguments string is parsed by the parse_exp_1 function. */
10574 /* Parse the rest of the arguments. */
10575 innermost_block = NULL;
10577 exp = parse_exp_1 (&arg, 0, 0, 0);
10579 /* Remove trailing whitespace from the expression before saving it.
10580 This makes the eventual display of the expression string a bit
10582 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
10585 /* Checking if the expression is not constant. */
10586 if (watchpoint_exp_is_const (exp))
10590 len = exp_end - exp_start;
10591 while (len > 0 && isspace (exp_start[len - 1]))
10593 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
10596 exp_valid_block = innermost_block;
10597 mark = value_mark ();
10598 fetch_subexp_value (exp, &pc, &val, &result, NULL);
10604 exp_valid_block = NULL;
10605 val = value_addr (result);
10606 release_value (val);
10607 value_free_to_mark (mark);
10611 ret = target_masked_watch_num_registers (value_as_address (val),
10614 error (_("This target does not support masked watchpoints."));
10615 else if (ret == -2)
10616 error (_("Invalid mask or memory region."));
10619 else if (val != NULL)
10620 release_value (val);
10622 tok = skip_spaces (arg);
10623 end_tok = skip_to_space (tok);
10625 toklen = end_tok - tok;
10626 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
10628 struct expression *cond;
10630 innermost_block = NULL;
10631 tok = cond_start = end_tok + 1;
10632 cond = parse_exp_1 (&tok, 0, 0, 0);
10634 /* The watchpoint expression may not be local, but the condition
10635 may still be. E.g.: `watch global if local > 0'. */
10636 cond_exp_valid_block = innermost_block;
10642 error (_("Junk at end of command."));
10644 if (accessflag == hw_read)
10645 bp_type = bp_read_watchpoint;
10646 else if (accessflag == hw_access)
10647 bp_type = bp_access_watchpoint;
10649 bp_type = bp_hardware_watchpoint;
10651 frame = block_innermost_frame (exp_valid_block);
10653 /* If the expression is "local", then set up a "watchpoint scope"
10654 breakpoint at the point where we've left the scope of the watchpoint
10655 expression. Create the scope breakpoint before the watchpoint, so
10656 that we will encounter it first in bpstat_stop_status. */
10657 if (exp_valid_block && frame)
10659 if (frame_id_p (frame_unwind_caller_id (frame)))
10662 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
10663 frame_unwind_caller_pc (frame),
10664 bp_watchpoint_scope,
10665 &momentary_breakpoint_ops);
10667 scope_breakpoint->enable_state = bp_enabled;
10669 /* Automatically delete the breakpoint when it hits. */
10670 scope_breakpoint->disposition = disp_del;
10672 /* Only break in the proper frame (help with recursion). */
10673 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
10675 /* Set the address at which we will stop. */
10676 scope_breakpoint->loc->gdbarch
10677 = frame_unwind_caller_arch (frame);
10678 scope_breakpoint->loc->requested_address
10679 = frame_unwind_caller_pc (frame);
10680 scope_breakpoint->loc->address
10681 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
10682 scope_breakpoint->loc->requested_address,
10683 scope_breakpoint->type);
10687 /* Now set up the breakpoint. */
10689 w = XCNEW (struct watchpoint);
10692 init_raw_breakpoint_without_location (b, NULL, bp_type,
10693 &masked_watchpoint_breakpoint_ops);
10695 init_raw_breakpoint_without_location (b, NULL, bp_type,
10696 &watchpoint_breakpoint_ops);
10697 b->thread = thread;
10698 b->disposition = disp_donttouch;
10699 b->pspace = current_program_space;
10701 w->exp_valid_block = exp_valid_block;
10702 w->cond_exp_valid_block = cond_exp_valid_block;
10705 struct type *t = value_type (val);
10706 CORE_ADDR addr = value_as_address (val);
10709 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
10710 name = type_to_string (t);
10712 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
10713 core_addr_to_string (addr));
10716 w->exp_string = xstrprintf ("-location %.*s",
10717 (int) (exp_end - exp_start), exp_start);
10719 /* The above expression is in C. */
10720 b->language = language_c;
10723 w->exp_string = savestring (exp_start, exp_end - exp_start);
10727 w->hw_wp_mask = mask;
10736 b->cond_string = savestring (cond_start, cond_end - cond_start);
10738 b->cond_string = 0;
10742 w->watchpoint_frame = get_frame_id (frame);
10743 w->watchpoint_thread = inferior_ptid;
10747 w->watchpoint_frame = null_frame_id;
10748 w->watchpoint_thread = null_ptid;
10751 if (scope_breakpoint != NULL)
10753 /* The scope breakpoint is related to the watchpoint. We will
10754 need to act on them together. */
10755 b->related_breakpoint = scope_breakpoint;
10756 scope_breakpoint->related_breakpoint = b;
10759 if (!just_location)
10760 value_free_to_mark (mark);
10762 TRY_CATCH (e, RETURN_MASK_ALL)
10764 /* Finally update the new watchpoint. This creates the locations
10765 that should be inserted. */
10766 update_watchpoint (w, 1);
10770 delete_breakpoint (b);
10771 throw_exception (e);
10774 install_breakpoint (internal, b, 1);
10777 /* Return count of debug registers needed to watch the given expression.
10778 If the watchpoint cannot be handled in hardware return zero. */
10781 can_use_hardware_watchpoint (struct value *v)
10783 int found_memory_cnt = 0;
10784 struct value *head = v;
10786 /* Did the user specifically forbid us to use hardware watchpoints? */
10787 if (!can_use_hw_watchpoints)
10790 /* Make sure that the value of the expression depends only upon
10791 memory contents, and values computed from them within GDB. If we
10792 find any register references or function calls, we can't use a
10793 hardware watchpoint.
10795 The idea here is that evaluating an expression generates a series
10796 of values, one holding the value of every subexpression. (The
10797 expression a*b+c has five subexpressions: a, b, a*b, c, and
10798 a*b+c.) GDB's values hold almost enough information to establish
10799 the criteria given above --- they identify memory lvalues,
10800 register lvalues, computed values, etcetera. So we can evaluate
10801 the expression, and then scan the chain of values that leaves
10802 behind to decide whether we can detect any possible change to the
10803 expression's final value using only hardware watchpoints.
10805 However, I don't think that the values returned by inferior
10806 function calls are special in any way. So this function may not
10807 notice that an expression involving an inferior function call
10808 can't be watched with hardware watchpoints. FIXME. */
10809 for (; v; v = value_next (v))
10811 if (VALUE_LVAL (v) == lval_memory)
10813 if (v != head && value_lazy (v))
10814 /* A lazy memory lvalue in the chain is one that GDB never
10815 needed to fetch; we either just used its address (e.g.,
10816 `a' in `a.b') or we never needed it at all (e.g., `a'
10817 in `a,b'). This doesn't apply to HEAD; if that is
10818 lazy then it was not readable, but watch it anyway. */
10822 /* Ahh, memory we actually used! Check if we can cover
10823 it with hardware watchpoints. */
10824 struct type *vtype = check_typedef (value_type (v));
10826 /* We only watch structs and arrays if user asked for it
10827 explicitly, never if they just happen to appear in a
10828 middle of some value chain. */
10830 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
10831 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
10833 CORE_ADDR vaddr = value_address (v);
10837 len = (target_exact_watchpoints
10838 && is_scalar_type_recursive (vtype))?
10839 1 : TYPE_LENGTH (value_type (v));
10841 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
10845 found_memory_cnt += num_regs;
10849 else if (VALUE_LVAL (v) != not_lval
10850 && deprecated_value_modifiable (v) == 0)
10851 return 0; /* These are values from the history (e.g., $1). */
10852 else if (VALUE_LVAL (v) == lval_register)
10853 return 0; /* Cannot watch a register with a HW watchpoint. */
10856 /* The expression itself looks suitable for using a hardware
10857 watchpoint, but give the target machine a chance to reject it. */
10858 return found_memory_cnt;
10862 watch_command_wrapper (char *arg, int from_tty, int internal)
10864 watch_command_1 (arg, hw_write, from_tty, 0, internal);
10867 /* A helper function that looks for an argument at the start of a
10868 string. The argument must also either be at the end of the string,
10869 or be followed by whitespace. Returns 1 if it finds the argument,
10870 0 otherwise. If the argument is found, it updates *STR. */
10873 check_for_argument (char **str, char *arg, int arg_len)
10875 if (strncmp (*str, arg, arg_len) == 0
10876 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
10884 /* A helper function that looks for the "-location" argument and then
10885 calls watch_command_1. */
10888 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
10890 int just_location = 0;
10893 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
10894 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
10896 arg = skip_spaces (arg);
10900 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
10904 watch_command (char *arg, int from_tty)
10906 watch_maybe_just_location (arg, hw_write, from_tty);
10910 rwatch_command_wrapper (char *arg, int from_tty, int internal)
10912 watch_command_1 (arg, hw_read, from_tty, 0, internal);
10916 rwatch_command (char *arg, int from_tty)
10918 watch_maybe_just_location (arg, hw_read, from_tty);
10922 awatch_command_wrapper (char *arg, int from_tty, int internal)
10924 watch_command_1 (arg, hw_access, from_tty, 0, internal);
10928 awatch_command (char *arg, int from_tty)
10930 watch_maybe_just_location (arg, hw_access, from_tty);
10934 /* Helper routines for the until_command routine in infcmd.c. Here
10935 because it uses the mechanisms of breakpoints. */
10937 struct until_break_command_continuation_args
10939 struct breakpoint *breakpoint;
10940 struct breakpoint *breakpoint2;
10944 /* This function is called by fetch_inferior_event via the
10945 cmd_continuation pointer, to complete the until command. It takes
10946 care of cleaning up the temporary breakpoints set up by the until
10949 until_break_command_continuation (void *arg, int err)
10951 struct until_break_command_continuation_args *a = arg;
10953 delete_breakpoint (a->breakpoint);
10954 if (a->breakpoint2)
10955 delete_breakpoint (a->breakpoint2);
10956 delete_longjmp_breakpoint (a->thread_num);
10960 until_break_command (char *arg, int from_tty, int anywhere)
10962 struct symtabs_and_lines sals;
10963 struct symtab_and_line sal;
10964 struct frame_info *frame;
10965 struct gdbarch *frame_gdbarch;
10966 struct frame_id stack_frame_id;
10967 struct frame_id caller_frame_id;
10968 struct breakpoint *breakpoint;
10969 struct breakpoint *breakpoint2 = NULL;
10970 struct cleanup *old_chain;
10972 struct thread_info *tp;
10974 clear_proceed_status ();
10976 /* Set a breakpoint where the user wants it and at return from
10979 if (last_displayed_sal_is_valid ())
10980 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
10981 get_last_displayed_symtab (),
10982 get_last_displayed_line ());
10984 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
10985 (struct symtab *) NULL, 0);
10987 if (sals.nelts != 1)
10988 error (_("Couldn't get information on specified line."));
10990 sal = sals.sals[0];
10991 xfree (sals.sals); /* malloc'd, so freed. */
10994 error (_("Junk at end of arguments."));
10996 resolve_sal_pc (&sal);
10998 tp = inferior_thread ();
11001 old_chain = make_cleanup (null_cleanup, NULL);
11003 /* Note linespec handling above invalidates the frame chain.
11004 Installing a breakpoint also invalidates the frame chain (as it
11005 may need to switch threads), so do any frame handling before
11008 frame = get_selected_frame (NULL);
11009 frame_gdbarch = get_frame_arch (frame);
11010 stack_frame_id = get_stack_frame_id (frame);
11011 caller_frame_id = frame_unwind_caller_id (frame);
11013 /* Keep within the current frame, or in frames called by the current
11016 if (frame_id_p (caller_frame_id))
11018 struct symtab_and_line sal2;
11020 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11021 sal2.pc = frame_unwind_caller_pc (frame);
11022 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
11026 make_cleanup_delete_breakpoint (breakpoint2);
11028 set_longjmp_breakpoint (tp, caller_frame_id);
11029 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11032 /* set_momentary_breakpoint could invalidate FRAME. */
11036 /* If the user told us to continue until a specified location,
11037 we don't specify a frame at which we need to stop. */
11038 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11039 null_frame_id, bp_until);
11041 /* Otherwise, specify the selected frame, because we want to stop
11042 only at the very same frame. */
11043 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11044 stack_frame_id, bp_until);
11045 make_cleanup_delete_breakpoint (breakpoint);
11047 proceed (-1, GDB_SIGNAL_DEFAULT, 0);
11049 /* If we are running asynchronously, and proceed call above has
11050 actually managed to start the target, arrange for breakpoints to
11051 be deleted when the target stops. Otherwise, we're already
11052 stopped and delete breakpoints via cleanup chain. */
11054 if (target_can_async_p () && is_running (inferior_ptid))
11056 struct until_break_command_continuation_args *args;
11057 args = xmalloc (sizeof (*args));
11059 args->breakpoint = breakpoint;
11060 args->breakpoint2 = breakpoint2;
11061 args->thread_num = thread;
11063 discard_cleanups (old_chain);
11064 add_continuation (inferior_thread (),
11065 until_break_command_continuation, args,
11069 do_cleanups (old_chain);
11072 /* This function attempts to parse an optional "if <cond>" clause
11073 from the arg string. If one is not found, it returns NULL.
11075 Else, it returns a pointer to the condition string. (It does not
11076 attempt to evaluate the string against a particular block.) And,
11077 it updates arg to point to the first character following the parsed
11078 if clause in the arg string. */
11081 ep_parse_optional_if_clause (char **arg)
11085 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11088 /* Skip the "if" keyword. */
11091 /* Skip any extra leading whitespace, and record the start of the
11092 condition string. */
11093 *arg = skip_spaces (*arg);
11094 cond_string = *arg;
11096 /* Assume that the condition occupies the remainder of the arg
11098 (*arg) += strlen (cond_string);
11100 return cond_string;
11103 /* Commands to deal with catching events, such as signals, exceptions,
11104 process start/exit, etc. */
11108 catch_fork_temporary, catch_vfork_temporary,
11109 catch_fork_permanent, catch_vfork_permanent
11114 catch_fork_command_1 (char *arg, int from_tty,
11115 struct cmd_list_element *command)
11117 struct gdbarch *gdbarch = get_current_arch ();
11118 char *cond_string = NULL;
11119 catch_fork_kind fork_kind;
11122 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
11123 tempflag = (fork_kind == catch_fork_temporary
11124 || fork_kind == catch_vfork_temporary);
11128 arg = skip_spaces (arg);
11130 /* The allowed syntax is:
11132 catch [v]fork if <cond>
11134 First, check if there's an if clause. */
11135 cond_string = ep_parse_optional_if_clause (&arg);
11137 if ((*arg != '\0') && !isspace (*arg))
11138 error (_("Junk at end of arguments."));
11140 /* If this target supports it, create a fork or vfork catchpoint
11141 and enable reporting of such events. */
11144 case catch_fork_temporary:
11145 case catch_fork_permanent:
11146 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11147 &catch_fork_breakpoint_ops);
11149 case catch_vfork_temporary:
11150 case catch_vfork_permanent:
11151 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11152 &catch_vfork_breakpoint_ops);
11155 error (_("unsupported or unknown fork kind; cannot catch it"));
11161 catch_exec_command_1 (char *arg, int from_tty,
11162 struct cmd_list_element *command)
11164 struct exec_catchpoint *c;
11165 struct gdbarch *gdbarch = get_current_arch ();
11167 char *cond_string = NULL;
11169 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11173 arg = skip_spaces (arg);
11175 /* The allowed syntax is:
11177 catch exec if <cond>
11179 First, check if there's an if clause. */
11180 cond_string = ep_parse_optional_if_clause (&arg);
11182 if ((*arg != '\0') && !isspace (*arg))
11183 error (_("Junk at end of arguments."));
11185 c = XNEW (struct exec_catchpoint);
11186 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
11187 &catch_exec_breakpoint_ops);
11188 c->exec_pathname = NULL;
11190 install_breakpoint (0, &c->base, 1);
11193 static enum print_stop_action
11194 print_it_exception_catchpoint (bpstat bs)
11196 struct ui_out *uiout = current_uiout;
11197 struct breakpoint *b = bs->breakpoint_at;
11198 int bp_temp, bp_throw;
11200 annotate_catchpoint (b->number);
11202 bp_throw = strstr (b->addr_string, "throw") != NULL;
11203 if (b->loc->address != b->loc->requested_address)
11204 breakpoint_adjustment_warning (b->loc->requested_address,
11207 bp_temp = b->disposition == disp_del;
11208 ui_out_text (uiout,
11209 bp_temp ? "Temporary catchpoint "
11211 if (!ui_out_is_mi_like_p (uiout))
11212 ui_out_field_int (uiout, "bkptno", b->number);
11213 ui_out_text (uiout,
11214 bp_throw ? " (exception thrown), "
11215 : " (exception caught), ");
11216 if (ui_out_is_mi_like_p (uiout))
11218 ui_out_field_string (uiout, "reason",
11219 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
11220 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
11221 ui_out_field_int (uiout, "bkptno", b->number);
11223 return PRINT_SRC_AND_LOC;
11227 print_one_exception_catchpoint (struct breakpoint *b,
11228 struct bp_location **last_loc)
11230 struct value_print_options opts;
11231 struct ui_out *uiout = current_uiout;
11233 get_user_print_options (&opts);
11234 if (opts.addressprint)
11236 annotate_field (4);
11237 if (b->loc == NULL || b->loc->shlib_disabled)
11238 ui_out_field_string (uiout, "addr", "<PENDING>");
11240 ui_out_field_core_addr (uiout, "addr",
11241 b->loc->gdbarch, b->loc->address);
11243 annotate_field (5);
11245 *last_loc = b->loc;
11246 if (strstr (b->addr_string, "throw") != NULL)
11247 ui_out_field_string (uiout, "what", "exception throw");
11249 ui_out_field_string (uiout, "what", "exception catch");
11253 print_mention_exception_catchpoint (struct breakpoint *b)
11255 struct ui_out *uiout = current_uiout;
11259 bp_temp = b->disposition == disp_del;
11260 bp_throw = strstr (b->addr_string, "throw") != NULL;
11261 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
11262 : _("Catchpoint "));
11263 ui_out_field_int (uiout, "bkptno", b->number);
11264 ui_out_text (uiout, bp_throw ? _(" (throw)")
11268 /* Implement the "print_recreate" breakpoint_ops method for throw and
11269 catch catchpoints. */
11272 print_recreate_exception_catchpoint (struct breakpoint *b,
11273 struct ui_file *fp)
11278 bp_temp = b->disposition == disp_del;
11279 bp_throw = strstr (b->addr_string, "throw") != NULL;
11280 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
11281 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
11282 print_recreate_thread (b, fp);
11285 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
11288 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
11289 enum exception_event_kind ex_event, int from_tty)
11291 char *trigger_func_name;
11293 if (ex_event == EX_EVENT_CATCH)
11294 trigger_func_name = "__cxa_begin_catch";
11296 trigger_func_name = "__cxa_throw";
11298 create_breakpoint (get_current_arch (),
11299 trigger_func_name, cond_string, -1, NULL,
11300 0 /* condition and thread are valid. */,
11301 tempflag, bp_breakpoint,
11303 AUTO_BOOLEAN_TRUE /* pending */,
11304 &gnu_v3_exception_catchpoint_ops, from_tty,
11312 /* Deal with "catch catch" and "catch throw" commands. */
11315 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
11316 int tempflag, int from_tty)
11318 char *cond_string = NULL;
11322 arg = skip_spaces (arg);
11324 cond_string = ep_parse_optional_if_clause (&arg);
11326 if ((*arg != '\0') && !isspace (*arg))
11327 error (_("Junk at end of arguments."));
11329 if (ex_event != EX_EVENT_THROW
11330 && ex_event != EX_EVENT_CATCH)
11331 error (_("Unsupported or unknown exception event; cannot catch it"));
11333 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
11336 warning (_("Unsupported with this platform/compiler combination."));
11339 /* Implementation of "catch catch" command. */
11342 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
11344 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11346 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
11349 /* Implementation of "catch throw" command. */
11352 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
11354 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11356 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
11360 init_ada_exception_breakpoint (struct breakpoint *b,
11361 struct gdbarch *gdbarch,
11362 struct symtab_and_line sal,
11364 const struct breakpoint_ops *ops,
11370 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11372 loc_gdbarch = gdbarch;
11374 describe_other_breakpoints (loc_gdbarch,
11375 sal.pspace, sal.pc, sal.section, -1);
11376 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11377 version for exception catchpoints, because two catchpoints
11378 used for different exception names will use the same address.
11379 In this case, a "breakpoint ... also set at..." warning is
11380 unproductive. Besides, the warning phrasing is also a bit
11381 inappropriate, we should use the word catchpoint, and tell
11382 the user what type of catchpoint it is. The above is good
11383 enough for now, though. */
11386 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
11388 b->enable_state = bp_enabled;
11389 b->disposition = tempflag ? disp_del : disp_donttouch;
11390 b->addr_string = addr_string;
11391 b->language = language_ada;
11394 /* Splits the argument using space as delimiter. Returns an xmalloc'd
11395 filter list, or NULL if no filtering is required. */
11397 catch_syscall_split_args (char *arg)
11399 VEC(int) *result = NULL;
11400 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
11402 while (*arg != '\0')
11404 int i, syscall_number;
11406 char cur_name[128];
11409 /* Skip whitespace. */
11410 while (isspace (*arg))
11413 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
11414 cur_name[i] = arg[i];
11415 cur_name[i] = '\0';
11418 /* Check if the user provided a syscall name or a number. */
11419 syscall_number = (int) strtol (cur_name, &endptr, 0);
11420 if (*endptr == '\0')
11421 get_syscall_by_number (syscall_number, &s);
11424 /* We have a name. Let's check if it's valid and convert it
11426 get_syscall_by_name (cur_name, &s);
11428 if (s.number == UNKNOWN_SYSCALL)
11429 /* Here we have to issue an error instead of a warning,
11430 because GDB cannot do anything useful if there's no
11431 syscall number to be caught. */
11432 error (_("Unknown syscall name '%s'."), cur_name);
11435 /* Ok, it's valid. */
11436 VEC_safe_push (int, result, s.number);
11439 discard_cleanups (cleanup);
11443 /* Implement the "catch syscall" command. */
11446 catch_syscall_command_1 (char *arg, int from_tty,
11447 struct cmd_list_element *command)
11452 struct gdbarch *gdbarch = get_current_arch ();
11454 /* Checking if the feature if supported. */
11455 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
11456 error (_("The feature 'catch syscall' is not supported on \
11457 this architecture yet."));
11459 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11461 arg = skip_spaces (arg);
11463 /* We need to do this first "dummy" translation in order
11464 to get the syscall XML file loaded or, most important,
11465 to display a warning to the user if there's no XML file
11466 for his/her architecture. */
11467 get_syscall_by_number (0, &s);
11469 /* The allowed syntax is:
11471 catch syscall <name | number> [<name | number> ... <name | number>]
11473 Let's check if there's a syscall name. */
11476 filter = catch_syscall_split_args (arg);
11480 create_syscall_event_catchpoint (tempflag, filter,
11481 &catch_syscall_breakpoint_ops);
11485 catch_command (char *arg, int from_tty)
11487 error (_("Catch requires an event name."));
11492 tcatch_command (char *arg, int from_tty)
11494 error (_("Catch requires an event name."));
11497 /* A qsort comparison function that sorts breakpoints in order. */
11500 compare_breakpoints (const void *a, const void *b)
11502 const breakpoint_p *ba = a;
11503 uintptr_t ua = (uintptr_t) *ba;
11504 const breakpoint_p *bb = b;
11505 uintptr_t ub = (uintptr_t) *bb;
11507 if ((*ba)->number < (*bb)->number)
11509 else if ((*ba)->number > (*bb)->number)
11512 /* Now sort by address, in case we see, e..g, two breakpoints with
11516 return ub > ub ? 1 : 0;
11519 /* Delete breakpoints by address or line. */
11522 clear_command (char *arg, int from_tty)
11524 struct breakpoint *b, *prev;
11525 VEC(breakpoint_p) *found = 0;
11528 struct symtabs_and_lines sals;
11529 struct symtab_and_line sal;
11531 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
11535 sals = decode_line_with_current_source (arg,
11536 (DECODE_LINE_FUNFIRSTLINE
11537 | DECODE_LINE_LIST_MODE));
11542 sals.sals = (struct symtab_and_line *)
11543 xmalloc (sizeof (struct symtab_and_line));
11544 make_cleanup (xfree, sals.sals);
11545 init_sal (&sal); /* Initialize to zeroes. */
11547 /* Set sal's line, symtab, pc, and pspace to the values
11548 corresponding to the last call to print_frame_info. If the
11549 codepoint is not valid, this will set all the fields to 0. */
11550 get_last_displayed_sal (&sal);
11551 if (sal.symtab == 0)
11552 error (_("No source file specified."));
11554 sals.sals[0] = sal;
11560 /* We don't call resolve_sal_pc here. That's not as bad as it
11561 seems, because all existing breakpoints typically have both
11562 file/line and pc set. So, if clear is given file/line, we can
11563 match this to existing breakpoint without obtaining pc at all.
11565 We only support clearing given the address explicitly
11566 present in breakpoint table. Say, we've set breakpoint
11567 at file:line. There were several PC values for that file:line,
11568 due to optimization, all in one block.
11570 We've picked one PC value. If "clear" is issued with another
11571 PC corresponding to the same file:line, the breakpoint won't
11572 be cleared. We probably can still clear the breakpoint, but
11573 since the other PC value is never presented to user, user
11574 can only find it by guessing, and it does not seem important
11575 to support that. */
11577 /* For each line spec given, delete bps which correspond to it. Do
11578 it in two passes, solely to preserve the current behavior that
11579 from_tty is forced true if we delete more than one
11583 make_cleanup (VEC_cleanup (breakpoint_p), &found);
11584 for (i = 0; i < sals.nelts; i++)
11586 int is_abs, sal_name_len;
11588 /* If exact pc given, clear bpts at that pc.
11589 If line given (pc == 0), clear all bpts on specified line.
11590 If defaulting, clear all bpts on default line
11593 defaulting sal.pc != 0 tests to do
11598 1 0 <can't happen> */
11600 sal = sals.sals[i];
11601 is_abs = sal.symtab == NULL ? 1 : IS_ABSOLUTE_PATH (sal.symtab->filename);
11602 sal_name_len = is_abs ? 0 : strlen (sal.symtab->filename);
11604 /* Find all matching breakpoints and add them to 'found'. */
11605 ALL_BREAKPOINTS (b)
11608 /* Are we going to delete b? */
11609 if (b->type != bp_none && !is_watchpoint (b))
11611 struct bp_location *loc = b->loc;
11612 for (; loc; loc = loc->next)
11614 /* If the user specified file:line, don't allow a PC
11615 match. This matches historical gdb behavior. */
11616 int pc_match = (!sal.explicit_line
11618 && (loc->pspace == sal.pspace)
11619 && (loc->address == sal.pc)
11620 && (!section_is_overlay (loc->section)
11621 || loc->section == sal.section));
11622 int line_match = 0;
11624 if ((default_match || sal.explicit_line)
11625 && loc->source_file != NULL
11626 && sal.symtab != NULL
11627 && sal.pspace == loc->pspace
11628 && loc->line_number == sal.line)
11630 if (filename_cmp (loc->source_file,
11631 sal.symtab->filename) == 0)
11633 else if (!IS_ABSOLUTE_PATH (sal.symtab->filename)
11634 && compare_filenames_for_search (loc->source_file,
11635 sal.symtab->filename,
11640 if (pc_match || line_match)
11649 VEC_safe_push(breakpoint_p, found, b);
11653 /* Now go thru the 'found' chain and delete them. */
11654 if (VEC_empty(breakpoint_p, found))
11657 error (_("No breakpoint at %s."), arg);
11659 error (_("No breakpoint at this line."));
11662 /* Remove duplicates from the vec. */
11663 qsort (VEC_address (breakpoint_p, found),
11664 VEC_length (breakpoint_p, found),
11665 sizeof (breakpoint_p),
11666 compare_breakpoints);
11667 prev = VEC_index (breakpoint_p, found, 0);
11668 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
11672 VEC_ordered_remove (breakpoint_p, found, ix);
11677 if (VEC_length(breakpoint_p, found) > 1)
11678 from_tty = 1; /* Always report if deleted more than one. */
11681 if (VEC_length(breakpoint_p, found) == 1)
11682 printf_unfiltered (_("Deleted breakpoint "));
11684 printf_unfiltered (_("Deleted breakpoints "));
11686 breakpoints_changed ();
11688 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
11691 printf_unfiltered ("%d ", b->number);
11692 delete_breakpoint (b);
11695 putchar_unfiltered ('\n');
11697 do_cleanups (cleanups);
11700 /* Delete breakpoint in BS if they are `delete' breakpoints and
11701 all breakpoints that are marked for deletion, whether hit or not.
11702 This is called after any breakpoint is hit, or after errors. */
11705 breakpoint_auto_delete (bpstat bs)
11707 struct breakpoint *b, *b_tmp;
11709 for (; bs; bs = bs->next)
11710 if (bs->breakpoint_at
11711 && bs->breakpoint_at->disposition == disp_del
11713 delete_breakpoint (bs->breakpoint_at);
11715 ALL_BREAKPOINTS_SAFE (b, b_tmp)
11717 if (b->disposition == disp_del_at_next_stop)
11718 delete_breakpoint (b);
11722 /* A comparison function for bp_location AP and BP being interfaced to
11723 qsort. Sort elements primarily by their ADDRESS (no matter what
11724 does breakpoint_address_is_meaningful say for its OWNER),
11725 secondarily by ordering first bp_permanent OWNERed elements and
11726 terciarily just ensuring the array is sorted stable way despite
11727 qsort being an unstable algorithm. */
11730 bp_location_compare (const void *ap, const void *bp)
11732 struct bp_location *a = *(void **) ap;
11733 struct bp_location *b = *(void **) bp;
11734 /* A and B come from existing breakpoints having non-NULL OWNER. */
11735 int a_perm = a->owner->enable_state == bp_permanent;
11736 int b_perm = b->owner->enable_state == bp_permanent;
11738 if (a->address != b->address)
11739 return (a->address > b->address) - (a->address < b->address);
11741 /* Sort locations at the same address by their pspace number, keeping
11742 locations of the same inferior (in a multi-inferior environment)
11745 if (a->pspace->num != b->pspace->num)
11746 return ((a->pspace->num > b->pspace->num)
11747 - (a->pspace->num < b->pspace->num));
11749 /* Sort permanent breakpoints first. */
11750 if (a_perm != b_perm)
11751 return (a_perm < b_perm) - (a_perm > b_perm);
11753 /* Make the internal GDB representation stable across GDB runs
11754 where A and B memory inside GDB can differ. Breakpoint locations of
11755 the same type at the same address can be sorted in arbitrary order. */
11757 if (a->owner->number != b->owner->number)
11758 return ((a->owner->number > b->owner->number)
11759 - (a->owner->number < b->owner->number));
11761 return (a > b) - (a < b);
11764 /* Set bp_location_placed_address_before_address_max and
11765 bp_location_shadow_len_after_address_max according to the current
11766 content of the bp_location array. */
11769 bp_location_target_extensions_update (void)
11771 struct bp_location *bl, **blp_tmp;
11773 bp_location_placed_address_before_address_max = 0;
11774 bp_location_shadow_len_after_address_max = 0;
11776 ALL_BP_LOCATIONS (bl, blp_tmp)
11778 CORE_ADDR start, end, addr;
11780 if (!bp_location_has_shadow (bl))
11783 start = bl->target_info.placed_address;
11784 end = start + bl->target_info.shadow_len;
11786 gdb_assert (bl->address >= start);
11787 addr = bl->address - start;
11788 if (addr > bp_location_placed_address_before_address_max)
11789 bp_location_placed_address_before_address_max = addr;
11791 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11793 gdb_assert (bl->address < end);
11794 addr = end - bl->address;
11795 if (addr > bp_location_shadow_len_after_address_max)
11796 bp_location_shadow_len_after_address_max = addr;
11800 /* Download tracepoint locations if they haven't been. */
11803 download_tracepoint_locations (void)
11805 struct bp_location *bl, **blp_tmp;
11806 struct cleanup *old_chain;
11808 if (!target_can_download_tracepoint ())
11811 old_chain = save_current_space_and_thread ();
11813 ALL_BP_LOCATIONS (bl, blp_tmp)
11815 struct tracepoint *t;
11817 if (!is_tracepoint (bl->owner))
11820 if ((bl->owner->type == bp_fast_tracepoint
11821 ? !may_insert_fast_tracepoints
11822 : !may_insert_tracepoints))
11825 /* In tracepoint, locations are _never_ duplicated, so
11826 should_be_inserted is equivalent to
11827 unduplicated_should_be_inserted. */
11828 if (!should_be_inserted (bl) || bl->inserted)
11831 switch_to_program_space_and_thread (bl->pspace);
11833 target_download_tracepoint (bl);
11836 t = (struct tracepoint *) bl->owner;
11837 t->number_on_target = bl->owner->number;
11840 do_cleanups (old_chain);
11843 /* Swap the insertion/duplication state between two locations. */
11846 swap_insertion (struct bp_location *left, struct bp_location *right)
11848 const int left_inserted = left->inserted;
11849 const int left_duplicate = left->duplicate;
11850 const int left_needs_update = left->needs_update;
11851 const struct bp_target_info left_target_info = left->target_info;
11853 /* Locations of tracepoints can never be duplicated. */
11854 if (is_tracepoint (left->owner))
11855 gdb_assert (!left->duplicate);
11856 if (is_tracepoint (right->owner))
11857 gdb_assert (!right->duplicate);
11859 left->inserted = right->inserted;
11860 left->duplicate = right->duplicate;
11861 left->needs_update = right->needs_update;
11862 left->target_info = right->target_info;
11863 right->inserted = left_inserted;
11864 right->duplicate = left_duplicate;
11865 right->needs_update = left_needs_update;
11866 right->target_info = left_target_info;
11869 /* Force the re-insertion of the locations at ADDRESS. This is called
11870 once a new/deleted/modified duplicate location is found and we are evaluating
11871 conditions on the target's side. Such conditions need to be updated on
11875 force_breakpoint_reinsertion (struct bp_location *bl)
11877 struct bp_location **locp = NULL, **loc2p;
11878 struct bp_location *loc;
11879 CORE_ADDR address = 0;
11882 address = bl->address;
11883 pspace_num = bl->pspace->num;
11885 /* This is only meaningful if the target is
11886 evaluating conditions and if the user has
11887 opted for condition evaluation on the target's
11889 if (gdb_evaluates_breakpoint_condition_p ()
11890 || !target_supports_evaluation_of_breakpoint_conditions ())
11893 /* Flag all breakpoint locations with this address and
11894 the same program space as the location
11895 as "its condition has changed". We need to
11896 update the conditions on the target's side. */
11897 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
11901 if (!is_breakpoint (loc->owner)
11902 || pspace_num != loc->pspace->num)
11905 /* Flag the location appropriately. We use a different state to
11906 let everyone know that we already updated the set of locations
11907 with addr bl->address and program space bl->pspace. This is so
11908 we don't have to keep calling these functions just to mark locations
11909 that have already been marked. */
11910 loc->condition_changed = condition_updated;
11912 /* Free the agent expression bytecode as well. We will compute
11914 if (loc->cond_bytecode)
11916 free_agent_expr (loc->cond_bytecode);
11917 loc->cond_bytecode = NULL;
11922 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
11923 into the inferior, only remove already-inserted locations that no
11924 longer should be inserted. Functions that delete a breakpoint or
11925 breakpoints should pass false, so that deleting a breakpoint
11926 doesn't have the side effect of inserting the locations of other
11927 breakpoints that are marked not-inserted, but should_be_inserted
11928 returns true on them.
11930 This behaviour is useful is situations close to tear-down -- e.g.,
11931 after an exec, while the target still has execution, but breakpoint
11932 shadows of the previous executable image should *NOT* be restored
11933 to the new image; or before detaching, where the target still has
11934 execution and wants to delete breakpoints from GDB's lists, and all
11935 breakpoints had already been removed from the inferior. */
11938 update_global_location_list (int should_insert)
11940 struct breakpoint *b;
11941 struct bp_location **locp, *loc;
11942 struct cleanup *cleanups;
11943 /* Last breakpoint location address that was marked for update. */
11944 CORE_ADDR last_addr = 0;
11945 /* Last breakpoint location program space that was marked for update. */
11946 int last_pspace_num = -1;
11948 /* Used in the duplicates detection below. When iterating over all
11949 bp_locations, points to the first bp_location of a given address.
11950 Breakpoints and watchpoints of different types are never
11951 duplicates of each other. Keep one pointer for each type of
11952 breakpoint/watchpoint, so we only need to loop over all locations
11954 struct bp_location *bp_loc_first; /* breakpoint */
11955 struct bp_location *wp_loc_first; /* hardware watchpoint */
11956 struct bp_location *awp_loc_first; /* access watchpoint */
11957 struct bp_location *rwp_loc_first; /* read watchpoint */
11959 /* Saved former bp_location array which we compare against the newly
11960 built bp_location from the current state of ALL_BREAKPOINTS. */
11961 struct bp_location **old_location, **old_locp;
11962 unsigned old_location_count;
11964 old_location = bp_location;
11965 old_location_count = bp_location_count;
11966 bp_location = NULL;
11967 bp_location_count = 0;
11968 cleanups = make_cleanup (xfree, old_location);
11970 ALL_BREAKPOINTS (b)
11971 for (loc = b->loc; loc; loc = loc->next)
11972 bp_location_count++;
11974 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
11975 locp = bp_location;
11976 ALL_BREAKPOINTS (b)
11977 for (loc = b->loc; loc; loc = loc->next)
11979 qsort (bp_location, bp_location_count, sizeof (*bp_location),
11980 bp_location_compare);
11982 bp_location_target_extensions_update ();
11984 /* Identify bp_location instances that are no longer present in the
11985 new list, and therefore should be freed. Note that it's not
11986 necessary that those locations should be removed from inferior --
11987 if there's another location at the same address (previously
11988 marked as duplicate), we don't need to remove/insert the
11991 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11992 and former bp_location array state respectively. */
11994 locp = bp_location;
11995 for (old_locp = old_location; old_locp < old_location + old_location_count;
11998 struct bp_location *old_loc = *old_locp;
11999 struct bp_location **loc2p;
12001 /* Tells if 'old_loc' is found among the new locations. If
12002 not, we have to free it. */
12003 int found_object = 0;
12004 /* Tells if the location should remain inserted in the target. */
12005 int keep_in_target = 0;
12008 /* Skip LOCP entries which will definitely never be needed.
12009 Stop either at or being the one matching OLD_LOC. */
12010 while (locp < bp_location + bp_location_count
12011 && (*locp)->address < old_loc->address)
12015 (loc2p < bp_location + bp_location_count
12016 && (*loc2p)->address == old_loc->address);
12019 /* Check if this is a new/duplicated location or a duplicated
12020 location that had its condition modified. If so, we want to send
12021 its condition to the target if evaluation of conditions is taking
12023 if ((*loc2p)->condition_changed == condition_modified
12024 && (last_addr != old_loc->address
12025 || last_pspace_num != old_loc->pspace->num))
12027 force_breakpoint_reinsertion (*loc2p);
12028 last_pspace_num = old_loc->pspace->num;
12031 if (*loc2p == old_loc)
12035 /* We have already handled this address, update it so that we don't
12036 have to go through updates again. */
12037 last_addr = old_loc->address;
12039 /* Target-side condition evaluation: Handle deleted locations. */
12041 force_breakpoint_reinsertion (old_loc);
12043 /* If this location is no longer present, and inserted, look if
12044 there's maybe a new location at the same address. If so,
12045 mark that one inserted, and don't remove this one. This is
12046 needed so that we don't have a time window where a breakpoint
12047 at certain location is not inserted. */
12049 if (old_loc->inserted)
12051 /* If the location is inserted now, we might have to remove
12054 if (found_object && should_be_inserted (old_loc))
12056 /* The location is still present in the location list,
12057 and still should be inserted. Don't do anything. */
12058 keep_in_target = 1;
12062 /* This location still exists, but it won't be kept in the
12063 target since it may have been disabled. We proceed to
12064 remove its target-side condition. */
12066 /* The location is either no longer present, or got
12067 disabled. See if there's another location at the
12068 same address, in which case we don't need to remove
12069 this one from the target. */
12071 /* OLD_LOC comes from existing struct breakpoint. */
12072 if (breakpoint_address_is_meaningful (old_loc->owner))
12075 (loc2p < bp_location + bp_location_count
12076 && (*loc2p)->address == old_loc->address);
12079 struct bp_location *loc2 = *loc2p;
12081 if (breakpoint_locations_match (loc2, old_loc))
12083 /* Read watchpoint locations are switched to
12084 access watchpoints, if the former are not
12085 supported, but the latter are. */
12086 if (is_hardware_watchpoint (old_loc->owner))
12088 gdb_assert (is_hardware_watchpoint (loc2->owner));
12089 loc2->watchpoint_type = old_loc->watchpoint_type;
12092 /* loc2 is a duplicated location. We need to check
12093 if it should be inserted in case it will be
12095 if (loc2 != old_loc
12096 && unduplicated_should_be_inserted (loc2))
12098 swap_insertion (old_loc, loc2);
12099 keep_in_target = 1;
12107 if (!keep_in_target)
12109 if (remove_breakpoint (old_loc, mark_uninserted))
12111 /* This is just about all we can do. We could keep
12112 this location on the global list, and try to
12113 remove it next time, but there's no particular
12114 reason why we will succeed next time.
12116 Note that at this point, old_loc->owner is still
12117 valid, as delete_breakpoint frees the breakpoint
12118 only after calling us. */
12119 printf_filtered (_("warning: Error removing "
12120 "breakpoint %d\n"),
12121 old_loc->owner->number);
12129 if (removed && non_stop
12130 && breakpoint_address_is_meaningful (old_loc->owner)
12131 && !is_hardware_watchpoint (old_loc->owner))
12133 /* This location was removed from the target. In
12134 non-stop mode, a race condition is possible where
12135 we've removed a breakpoint, but stop events for that
12136 breakpoint are already queued and will arrive later.
12137 We apply an heuristic to be able to distinguish such
12138 SIGTRAPs from other random SIGTRAPs: we keep this
12139 breakpoint location for a bit, and will retire it
12140 after we see some number of events. The theory here
12141 is that reporting of events should, "on the average",
12142 be fair, so after a while we'll see events from all
12143 threads that have anything of interest, and no longer
12144 need to keep this breakpoint location around. We
12145 don't hold locations forever so to reduce chances of
12146 mistaking a non-breakpoint SIGTRAP for a breakpoint
12149 The heuristic failing can be disastrous on
12150 decr_pc_after_break targets.
12152 On decr_pc_after_break targets, like e.g., x86-linux,
12153 if we fail to recognize a late breakpoint SIGTRAP,
12154 because events_till_retirement has reached 0 too
12155 soon, we'll fail to do the PC adjustment, and report
12156 a random SIGTRAP to the user. When the user resumes
12157 the inferior, it will most likely immediately crash
12158 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12159 corrupted, because of being resumed e.g., in the
12160 middle of a multi-byte instruction, or skipped a
12161 one-byte instruction. This was actually seen happen
12162 on native x86-linux, and should be less rare on
12163 targets that do not support new thread events, like
12164 remote, due to the heuristic depending on
12167 Mistaking a random SIGTRAP for a breakpoint trap
12168 causes similar symptoms (PC adjustment applied when
12169 it shouldn't), but then again, playing with SIGTRAPs
12170 behind the debugger's back is asking for trouble.
12172 Since hardware watchpoint traps are always
12173 distinguishable from other traps, so we don't need to
12174 apply keep hardware watchpoint moribund locations
12175 around. We simply always ignore hardware watchpoint
12176 traps we can no longer explain. */
12178 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12179 old_loc->owner = NULL;
12181 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12185 old_loc->owner = NULL;
12186 decref_bp_location (&old_loc);
12191 /* Rescan breakpoints at the same address and section, marking the
12192 first one as "first" and any others as "duplicates". This is so
12193 that the bpt instruction is only inserted once. If we have a
12194 permanent breakpoint at the same place as BPT, make that one the
12195 official one, and the rest as duplicates. Permanent breakpoints
12196 are sorted first for the same address.
12198 Do the same for hardware watchpoints, but also considering the
12199 watchpoint's type (regular/access/read) and length. */
12201 bp_loc_first = NULL;
12202 wp_loc_first = NULL;
12203 awp_loc_first = NULL;
12204 rwp_loc_first = NULL;
12205 ALL_BP_LOCATIONS (loc, locp)
12207 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12209 struct bp_location **loc_first_p;
12212 if (!should_be_inserted (loc)
12213 || !breakpoint_address_is_meaningful (b)
12214 /* Don't detect duplicate for tracepoint locations because they are
12215 never duplicated. See the comments in field `duplicate' of
12216 `struct bp_location'. */
12217 || is_tracepoint (b))
12219 /* Clear the condition modification flag. */
12220 loc->condition_changed = condition_unchanged;
12224 /* Permanent breakpoint should always be inserted. */
12225 if (b->enable_state == bp_permanent && ! loc->inserted)
12226 internal_error (__FILE__, __LINE__,
12227 _("allegedly permanent breakpoint is not "
12228 "actually inserted"));
12230 if (b->type == bp_hardware_watchpoint)
12231 loc_first_p = &wp_loc_first;
12232 else if (b->type == bp_read_watchpoint)
12233 loc_first_p = &rwp_loc_first;
12234 else if (b->type == bp_access_watchpoint)
12235 loc_first_p = &awp_loc_first;
12237 loc_first_p = &bp_loc_first;
12239 if (*loc_first_p == NULL
12240 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12241 || !breakpoint_locations_match (loc, *loc_first_p))
12243 *loc_first_p = loc;
12244 loc->duplicate = 0;
12246 if (is_breakpoint (loc->owner) && loc->condition_changed)
12248 loc->needs_update = 1;
12249 /* Clear the condition modification flag. */
12250 loc->condition_changed = condition_unchanged;
12256 /* This and the above ensure the invariant that the first location
12257 is not duplicated, and is the inserted one.
12258 All following are marked as duplicated, and are not inserted. */
12260 swap_insertion (loc, *loc_first_p);
12261 loc->duplicate = 1;
12263 /* Clear the condition modification flag. */
12264 loc->condition_changed = condition_unchanged;
12266 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
12267 && b->enable_state != bp_permanent)
12268 internal_error (__FILE__, __LINE__,
12269 _("another breakpoint was inserted on top of "
12270 "a permanent breakpoint"));
12273 if (breakpoints_always_inserted_mode ()
12274 && (have_live_inferiors ()
12275 || (gdbarch_has_global_breakpoints (target_gdbarch))))
12278 insert_breakpoint_locations ();
12281 /* Though should_insert is false, we may need to update conditions
12282 on the target's side if it is evaluating such conditions. We
12283 only update conditions for locations that are marked
12285 update_inserted_breakpoint_locations ();
12290 download_tracepoint_locations ();
12292 do_cleanups (cleanups);
12296 breakpoint_retire_moribund (void)
12298 struct bp_location *loc;
12301 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12302 if (--(loc->events_till_retirement) == 0)
12304 decref_bp_location (&loc);
12305 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12311 update_global_location_list_nothrow (int inserting)
12313 volatile struct gdb_exception e;
12315 TRY_CATCH (e, RETURN_MASK_ERROR)
12316 update_global_location_list (inserting);
12319 /* Clear BKP from a BPS. */
12322 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12326 for (bs = bps; bs; bs = bs->next)
12327 if (bs->breakpoint_at == bpt)
12329 bs->breakpoint_at = NULL;
12330 bs->old_val = NULL;
12331 /* bs->commands will be freed later. */
12335 /* Callback for iterate_over_threads. */
12337 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12339 struct breakpoint *bpt = data;
12341 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12345 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12349 say_where (struct breakpoint *b)
12351 struct ui_out *uiout = current_uiout;
12352 struct value_print_options opts;
12354 get_user_print_options (&opts);
12356 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12358 if (b->loc == NULL)
12360 printf_filtered (_(" (%s) pending."), b->addr_string);
12364 if (opts.addressprint || b->loc->source_file == NULL)
12366 printf_filtered (" at ");
12367 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
12370 if (b->loc->source_file)
12372 /* If there is a single location, we can print the location
12374 if (b->loc->next == NULL)
12375 printf_filtered (": file %s, line %d.",
12376 b->loc->source_file, b->loc->line_number);
12378 /* This is not ideal, but each location may have a
12379 different file name, and this at least reflects the
12380 real situation somewhat. */
12381 printf_filtered (": %s.", b->addr_string);
12386 struct bp_location *loc = b->loc;
12388 for (; loc; loc = loc->next)
12390 printf_filtered (" (%d locations)", n);
12395 /* Default bp_location_ops methods. */
12398 bp_location_dtor (struct bp_location *self)
12400 xfree (self->cond);
12401 if (self->cond_bytecode)
12402 free_agent_expr (self->cond_bytecode);
12403 xfree (self->function_name);
12404 xfree (self->source_file);
12407 static const struct bp_location_ops bp_location_ops =
12412 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12416 base_breakpoint_dtor (struct breakpoint *self)
12418 decref_counted_command_line (&self->commands);
12419 xfree (self->cond_string);
12420 xfree (self->addr_string);
12421 xfree (self->filter);
12422 xfree (self->addr_string_range_end);
12425 static struct bp_location *
12426 base_breakpoint_allocate_location (struct breakpoint *self)
12428 struct bp_location *loc;
12430 loc = XNEW (struct bp_location);
12431 init_bp_location (loc, &bp_location_ops, self);
12436 base_breakpoint_re_set (struct breakpoint *b)
12438 /* Nothing to re-set. */
12441 #define internal_error_pure_virtual_called() \
12442 gdb_assert_not_reached ("pure virtual function called")
12445 base_breakpoint_insert_location (struct bp_location *bl)
12447 internal_error_pure_virtual_called ();
12451 base_breakpoint_remove_location (struct bp_location *bl)
12453 internal_error_pure_virtual_called ();
12457 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12458 struct address_space *aspace,
12460 const struct target_waitstatus *ws)
12462 internal_error_pure_virtual_called ();
12466 base_breakpoint_check_status (bpstat bs)
12471 /* A "works_in_software_mode" breakpoint_ops method that just internal
12475 base_breakpoint_works_in_software_mode (const struct breakpoint *b)
12477 internal_error_pure_virtual_called ();
12480 /* A "resources_needed" breakpoint_ops method that just internal
12484 base_breakpoint_resources_needed (const struct bp_location *bl)
12486 internal_error_pure_virtual_called ();
12489 static enum print_stop_action
12490 base_breakpoint_print_it (bpstat bs)
12492 internal_error_pure_virtual_called ();
12496 base_breakpoint_print_one_detail (const struct breakpoint *self,
12497 struct ui_out *uiout)
12503 base_breakpoint_print_mention (struct breakpoint *b)
12505 internal_error_pure_virtual_called ();
12509 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
12511 internal_error_pure_virtual_called ();
12515 base_breakpoint_create_sals_from_address (char **arg,
12516 struct linespec_result *canonical,
12517 enum bptype type_wanted,
12521 internal_error_pure_virtual_called ();
12525 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12526 struct linespec_result *c,
12527 struct linespec_sals *lsal,
12529 char *extra_string,
12530 enum bptype type_wanted,
12531 enum bpdisp disposition,
12533 int task, int ignore_count,
12534 const struct breakpoint_ops *o,
12535 int from_tty, int enabled,
12536 int internal, unsigned flags)
12538 internal_error_pure_virtual_called ();
12542 base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
12543 struct symtabs_and_lines *sals)
12545 internal_error_pure_virtual_called ();
12548 static struct breakpoint_ops base_breakpoint_ops =
12550 base_breakpoint_dtor,
12551 base_breakpoint_allocate_location,
12552 base_breakpoint_re_set,
12553 base_breakpoint_insert_location,
12554 base_breakpoint_remove_location,
12555 base_breakpoint_breakpoint_hit,
12556 base_breakpoint_check_status,
12557 base_breakpoint_resources_needed,
12558 base_breakpoint_works_in_software_mode,
12559 base_breakpoint_print_it,
12561 base_breakpoint_print_one_detail,
12562 base_breakpoint_print_mention,
12563 base_breakpoint_print_recreate,
12564 base_breakpoint_create_sals_from_address,
12565 base_breakpoint_create_breakpoints_sal,
12566 base_breakpoint_decode_linespec,
12569 /* Default breakpoint_ops methods. */
12572 bkpt_re_set (struct breakpoint *b)
12574 /* FIXME: is this still reachable? */
12575 if (b->addr_string == NULL)
12577 /* Anything without a string can't be re-set. */
12578 delete_breakpoint (b);
12582 breakpoint_re_set_default (b);
12586 bkpt_insert_location (struct bp_location *bl)
12588 if (bl->loc_type == bp_loc_hardware_breakpoint)
12589 return target_insert_hw_breakpoint (bl->gdbarch,
12592 return target_insert_breakpoint (bl->gdbarch,
12597 bkpt_remove_location (struct bp_location *bl)
12599 if (bl->loc_type == bp_loc_hardware_breakpoint)
12600 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
12602 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
12606 bkpt_breakpoint_hit (const struct bp_location *bl,
12607 struct address_space *aspace, CORE_ADDR bp_addr,
12608 const struct target_waitstatus *ws)
12610 struct breakpoint *b = bl->owner;
12612 if (ws->kind != TARGET_WAITKIND_STOPPED
12613 || ws->value.sig != GDB_SIGNAL_TRAP)
12616 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
12620 if (overlay_debugging /* unmapped overlay section */
12621 && section_is_overlay (bl->section)
12622 && !section_is_mapped (bl->section))
12629 bkpt_resources_needed (const struct bp_location *bl)
12631 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
12636 static enum print_stop_action
12637 bkpt_print_it (bpstat bs)
12639 struct breakpoint *b;
12640 const struct bp_location *bl;
12642 struct ui_out *uiout = current_uiout;
12644 gdb_assert (bs->bp_location_at != NULL);
12646 bl = bs->bp_location_at;
12647 b = bs->breakpoint_at;
12649 bp_temp = b->disposition == disp_del;
12650 if (bl->address != bl->requested_address)
12651 breakpoint_adjustment_warning (bl->requested_address,
12654 annotate_breakpoint (b->number);
12656 ui_out_text (uiout, "\nTemporary breakpoint ");
12658 ui_out_text (uiout, "\nBreakpoint ");
12659 if (ui_out_is_mi_like_p (uiout))
12661 ui_out_field_string (uiout, "reason",
12662 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
12663 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
12665 ui_out_field_int (uiout, "bkptno", b->number);
12666 ui_out_text (uiout, ", ");
12668 return PRINT_SRC_AND_LOC;
12672 bkpt_print_mention (struct breakpoint *b)
12674 if (ui_out_is_mi_like_p (current_uiout))
12679 case bp_breakpoint:
12680 case bp_gnu_ifunc_resolver:
12681 if (b->disposition == disp_del)
12682 printf_filtered (_("Temporary breakpoint"));
12684 printf_filtered (_("Breakpoint"));
12685 printf_filtered (_(" %d"), b->number);
12686 if (b->type == bp_gnu_ifunc_resolver)
12687 printf_filtered (_(" at gnu-indirect-function resolver"));
12689 case bp_hardware_breakpoint:
12690 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
12693 printf_filtered (_("Dprintf %d"), b->number);
12701 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
12703 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
12704 fprintf_unfiltered (fp, "tbreak");
12705 else if (tp->type == bp_breakpoint)
12706 fprintf_unfiltered (fp, "break");
12707 else if (tp->type == bp_hardware_breakpoint
12708 && tp->disposition == disp_del)
12709 fprintf_unfiltered (fp, "thbreak");
12710 else if (tp->type == bp_hardware_breakpoint)
12711 fprintf_unfiltered (fp, "hbreak");
12713 internal_error (__FILE__, __LINE__,
12714 _("unhandled breakpoint type %d"), (int) tp->type);
12716 fprintf_unfiltered (fp, " %s", tp->addr_string);
12717 print_recreate_thread (tp, fp);
12721 bkpt_create_sals_from_address (char **arg,
12722 struct linespec_result *canonical,
12723 enum bptype type_wanted,
12724 char *addr_start, char **copy_arg)
12726 create_sals_from_address_default (arg, canonical, type_wanted,
12727 addr_start, copy_arg);
12731 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
12732 struct linespec_result *canonical,
12733 struct linespec_sals *lsal,
12735 char *extra_string,
12736 enum bptype type_wanted,
12737 enum bpdisp disposition,
12739 int task, int ignore_count,
12740 const struct breakpoint_ops *ops,
12741 int from_tty, int enabled,
12742 int internal, unsigned flags)
12744 create_breakpoints_sal_default (gdbarch, canonical, lsal,
12745 cond_string, extra_string,
12747 disposition, thread, task,
12748 ignore_count, ops, from_tty,
12749 enabled, internal, flags);
12753 bkpt_decode_linespec (struct breakpoint *b, char **s,
12754 struct symtabs_and_lines *sals)
12756 decode_linespec_default (b, s, sals);
12759 /* Virtual table for internal breakpoints. */
12762 internal_bkpt_re_set (struct breakpoint *b)
12766 /* Delete overlay event and longjmp master breakpoints; they
12767 will be reset later by breakpoint_re_set. */
12768 case bp_overlay_event:
12769 case bp_longjmp_master:
12770 case bp_std_terminate_master:
12771 case bp_exception_master:
12772 delete_breakpoint (b);
12775 /* This breakpoint is special, it's set up when the inferior
12776 starts and we really don't want to touch it. */
12777 case bp_shlib_event:
12779 /* Like bp_shlib_event, this breakpoint type is special. Once
12780 it is set up, we do not want to touch it. */
12781 case bp_thread_event:
12787 internal_bkpt_check_status (bpstat bs)
12789 if (bs->breakpoint_at->type == bp_shlib_event)
12791 /* If requested, stop when the dynamic linker notifies GDB of
12792 events. This allows the user to get control and place
12793 breakpoints in initializer routines for dynamically loaded
12794 objects (among other things). */
12795 bs->stop = stop_on_solib_events;
12796 bs->print = stop_on_solib_events;
12802 static enum print_stop_action
12803 internal_bkpt_print_it (bpstat bs)
12805 struct ui_out *uiout = current_uiout;
12806 struct breakpoint *b;
12808 b = bs->breakpoint_at;
12812 case bp_shlib_event:
12813 /* Did we stop because the user set the stop_on_solib_events
12814 variable? (If so, we report this as a generic, "Stopped due
12815 to shlib event" message.) */
12816 print_solib_event (0);
12819 case bp_thread_event:
12820 /* Not sure how we will get here.
12821 GDB should not stop for these breakpoints. */
12822 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12825 case bp_overlay_event:
12826 /* By analogy with the thread event, GDB should not stop for these. */
12827 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12830 case bp_longjmp_master:
12831 /* These should never be enabled. */
12832 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12835 case bp_std_terminate_master:
12836 /* These should never be enabled. */
12837 printf_filtered (_("std::terminate Master Breakpoint: "
12838 "gdb should not stop!\n"));
12841 case bp_exception_master:
12842 /* These should never be enabled. */
12843 printf_filtered (_("Exception Master Breakpoint: "
12844 "gdb should not stop!\n"));
12848 return PRINT_NOTHING;
12852 internal_bkpt_print_mention (struct breakpoint *b)
12854 /* Nothing to mention. These breakpoints are internal. */
12857 /* Virtual table for momentary breakpoints */
12860 momentary_bkpt_re_set (struct breakpoint *b)
12862 /* Keep temporary breakpoints, which can be encountered when we step
12863 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
12864 Otherwise these should have been blown away via the cleanup chain
12865 or by breakpoint_init_inferior when we rerun the executable. */
12869 momentary_bkpt_check_status (bpstat bs)
12871 /* Nothing. The point of these breakpoints is causing a stop. */
12874 static enum print_stop_action
12875 momentary_bkpt_print_it (bpstat bs)
12877 struct ui_out *uiout = current_uiout;
12879 if (ui_out_is_mi_like_p (uiout))
12881 struct breakpoint *b = bs->breakpoint_at;
12886 ui_out_field_string
12888 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
12892 ui_out_field_string
12894 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
12899 return PRINT_UNKNOWN;
12903 momentary_bkpt_print_mention (struct breakpoint *b)
12905 /* Nothing to mention. These breakpoints are internal. */
12908 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12910 It gets cleared already on the removal of the first one of such placed
12911 breakpoints. This is OK as they get all removed altogether. */
12914 longjmp_bkpt_dtor (struct breakpoint *self)
12916 struct thread_info *tp = find_thread_id (self->thread);
12919 tp->initiating_frame = null_frame_id;
12921 momentary_breakpoint_ops.dtor (self);
12924 /* Specific methods for probe breakpoints. */
12927 bkpt_probe_insert_location (struct bp_location *bl)
12929 int v = bkpt_insert_location (bl);
12933 /* The insertion was successful, now let's set the probe's semaphore
12935 bl->probe->pops->set_semaphore (bl->probe, bl->gdbarch);
12942 bkpt_probe_remove_location (struct bp_location *bl)
12944 /* Let's clear the semaphore before removing the location. */
12945 bl->probe->pops->clear_semaphore (bl->probe, bl->gdbarch);
12947 return bkpt_remove_location (bl);
12951 bkpt_probe_create_sals_from_address (char **arg,
12952 struct linespec_result *canonical,
12953 enum bptype type_wanted,
12954 char *addr_start, char **copy_arg)
12956 struct linespec_sals lsal;
12958 lsal.sals = parse_probes (arg, canonical);
12960 *copy_arg = xstrdup (canonical->addr_string);
12961 lsal.canonical = xstrdup (*copy_arg);
12963 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
12967 bkpt_probe_decode_linespec (struct breakpoint *b, char **s,
12968 struct symtabs_and_lines *sals)
12970 *sals = parse_probes (s, NULL);
12972 error (_("probe not found"));
12975 /* The breakpoint_ops structure to be used in tracepoints. */
12978 tracepoint_re_set (struct breakpoint *b)
12980 breakpoint_re_set_default (b);
12984 tracepoint_breakpoint_hit (const struct bp_location *bl,
12985 struct address_space *aspace, CORE_ADDR bp_addr,
12986 const struct target_waitstatus *ws)
12988 /* By definition, the inferior does not report stops at
12994 tracepoint_print_one_detail (const struct breakpoint *self,
12995 struct ui_out *uiout)
12997 struct tracepoint *tp = (struct tracepoint *) self;
12998 if (tp->static_trace_marker_id)
13000 gdb_assert (self->type == bp_static_tracepoint);
13002 ui_out_text (uiout, "\tmarker id is ");
13003 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
13004 tp->static_trace_marker_id);
13005 ui_out_text (uiout, "\n");
13010 tracepoint_print_mention (struct breakpoint *b)
13012 if (ui_out_is_mi_like_p (current_uiout))
13017 case bp_tracepoint:
13018 printf_filtered (_("Tracepoint"));
13019 printf_filtered (_(" %d"), b->number);
13021 case bp_fast_tracepoint:
13022 printf_filtered (_("Fast tracepoint"));
13023 printf_filtered (_(" %d"), b->number);
13025 case bp_static_tracepoint:
13026 printf_filtered (_("Static tracepoint"));
13027 printf_filtered (_(" %d"), b->number);
13030 internal_error (__FILE__, __LINE__,
13031 _("unhandled tracepoint type %d"), (int) b->type);
13038 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
13040 struct tracepoint *tp = (struct tracepoint *) self;
13042 if (self->type == bp_fast_tracepoint)
13043 fprintf_unfiltered (fp, "ftrace");
13044 if (self->type == bp_static_tracepoint)
13045 fprintf_unfiltered (fp, "strace");
13046 else if (self->type == bp_tracepoint)
13047 fprintf_unfiltered (fp, "trace");
13049 internal_error (__FILE__, __LINE__,
13050 _("unhandled tracepoint type %d"), (int) self->type);
13052 fprintf_unfiltered (fp, " %s", self->addr_string);
13053 print_recreate_thread (self, fp);
13055 if (tp->pass_count)
13056 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
13060 tracepoint_create_sals_from_address (char **arg,
13061 struct linespec_result *canonical,
13062 enum bptype type_wanted,
13063 char *addr_start, char **copy_arg)
13065 create_sals_from_address_default (arg, canonical, type_wanted,
13066 addr_start, copy_arg);
13070 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13071 struct linespec_result *canonical,
13072 struct linespec_sals *lsal,
13074 char *extra_string,
13075 enum bptype type_wanted,
13076 enum bpdisp disposition,
13078 int task, int ignore_count,
13079 const struct breakpoint_ops *ops,
13080 int from_tty, int enabled,
13081 int internal, unsigned flags)
13083 create_breakpoints_sal_default (gdbarch, canonical, lsal,
13084 cond_string, extra_string,
13086 disposition, thread, task,
13087 ignore_count, ops, from_tty,
13088 enabled, internal, flags);
13092 tracepoint_decode_linespec (struct breakpoint *b, char **s,
13093 struct symtabs_and_lines *sals)
13095 decode_linespec_default (b, s, sals);
13098 struct breakpoint_ops tracepoint_breakpoint_ops;
13100 /* The breakpoint_ops structure to be use on tracepoints placed in a
13104 tracepoint_probe_create_sals_from_address (char **arg,
13105 struct linespec_result *canonical,
13106 enum bptype type_wanted,
13107 char *addr_start, char **copy_arg)
13109 /* We use the same method for breakpoint on probes. */
13110 bkpt_probe_create_sals_from_address (arg, canonical, type_wanted,
13111 addr_start, copy_arg);
13115 tracepoint_probe_decode_linespec (struct breakpoint *b, char **s,
13116 struct symtabs_and_lines *sals)
13118 /* We use the same method for breakpoint on probes. */
13119 bkpt_probe_decode_linespec (b, s, sals);
13122 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
13124 /* The breakpoint_ops structure to be used on static tracepoints with
13128 strace_marker_create_sals_from_address (char **arg,
13129 struct linespec_result *canonical,
13130 enum bptype type_wanted,
13131 char *addr_start, char **copy_arg)
13133 struct linespec_sals lsal;
13135 lsal.sals = decode_static_tracepoint_spec (arg);
13137 *copy_arg = savestring (addr_start, *arg - addr_start);
13139 canonical->addr_string = xstrdup (*copy_arg);
13140 lsal.canonical = xstrdup (*copy_arg);
13141 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13145 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13146 struct linespec_result *canonical,
13147 struct linespec_sals *lsal,
13149 char *extra_string,
13150 enum bptype type_wanted,
13151 enum bpdisp disposition,
13153 int task, int ignore_count,
13154 const struct breakpoint_ops *ops,
13155 int from_tty, int enabled,
13156 int internal, unsigned flags)
13160 /* If the user is creating a static tracepoint by marker id
13161 (strace -m MARKER_ID), then store the sals index, so that
13162 breakpoint_re_set can try to match up which of the newly
13163 found markers corresponds to this one, and, don't try to
13164 expand multiple locations for each sal, given than SALS
13165 already should contain all sals for MARKER_ID. */
13167 for (i = 0; i < lsal->sals.nelts; ++i)
13169 struct symtabs_and_lines expanded;
13170 struct tracepoint *tp;
13171 struct cleanup *old_chain;
13174 expanded.nelts = 1;
13175 expanded.sals = &lsal->sals.sals[i];
13177 addr_string = xstrdup (canonical->addr_string);
13178 old_chain = make_cleanup (xfree, addr_string);
13180 tp = XCNEW (struct tracepoint);
13181 init_breakpoint_sal (&tp->base, gdbarch, expanded,
13183 cond_string, extra_string,
13184 type_wanted, disposition,
13185 thread, task, ignore_count, ops,
13186 from_tty, enabled, internal, flags,
13187 canonical->special_display);
13188 /* Given that its possible to have multiple markers with
13189 the same string id, if the user is creating a static
13190 tracepoint by marker id ("strace -m MARKER_ID"), then
13191 store the sals index, so that breakpoint_re_set can
13192 try to match up which of the newly found markers
13193 corresponds to this one */
13194 tp->static_trace_marker_id_idx = i;
13196 install_breakpoint (internal, &tp->base, 0);
13198 discard_cleanups (old_chain);
13203 strace_marker_decode_linespec (struct breakpoint *b, char **s,
13204 struct symtabs_and_lines *sals)
13206 struct tracepoint *tp = (struct tracepoint *) b;
13208 *sals = decode_static_tracepoint_spec (s);
13209 if (sals->nelts > tp->static_trace_marker_id_idx)
13211 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
13215 error (_("marker %s not found"), tp->static_trace_marker_id);
13218 static struct breakpoint_ops strace_marker_breakpoint_ops;
13221 strace_marker_p (struct breakpoint *b)
13223 return b->ops == &strace_marker_breakpoint_ops;
13226 /* Delete a breakpoint and clean up all traces of it in the data
13230 delete_breakpoint (struct breakpoint *bpt)
13232 struct breakpoint *b;
13234 gdb_assert (bpt != NULL);
13236 /* Has this bp already been deleted? This can happen because
13237 multiple lists can hold pointers to bp's. bpstat lists are
13240 One example of this happening is a watchpoint's scope bp. When
13241 the scope bp triggers, we notice that the watchpoint is out of
13242 scope, and delete it. We also delete its scope bp. But the
13243 scope bp is marked "auto-deleting", and is already on a bpstat.
13244 That bpstat is then checked for auto-deleting bp's, which are
13247 A real solution to this problem might involve reference counts in
13248 bp's, and/or giving them pointers back to their referencing
13249 bpstat's, and teaching delete_breakpoint to only free a bp's
13250 storage when no more references were extent. A cheaper bandaid
13252 if (bpt->type == bp_none)
13255 /* At least avoid this stale reference until the reference counting
13256 of breakpoints gets resolved. */
13257 if (bpt->related_breakpoint != bpt)
13259 struct breakpoint *related;
13260 struct watchpoint *w;
13262 if (bpt->type == bp_watchpoint_scope)
13263 w = (struct watchpoint *) bpt->related_breakpoint;
13264 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
13265 w = (struct watchpoint *) bpt;
13269 watchpoint_del_at_next_stop (w);
13271 /* Unlink bpt from the bpt->related_breakpoint ring. */
13272 for (related = bpt; related->related_breakpoint != bpt;
13273 related = related->related_breakpoint);
13274 related->related_breakpoint = bpt->related_breakpoint;
13275 bpt->related_breakpoint = bpt;
13278 /* watch_command_1 creates a watchpoint but only sets its number if
13279 update_watchpoint succeeds in creating its bp_locations. If there's
13280 a problem in that process, we'll be asked to delete the half-created
13281 watchpoint. In that case, don't announce the deletion. */
13283 observer_notify_breakpoint_deleted (bpt);
13285 if (breakpoint_chain == bpt)
13286 breakpoint_chain = bpt->next;
13288 ALL_BREAKPOINTS (b)
13289 if (b->next == bpt)
13291 b->next = bpt->next;
13295 /* Be sure no bpstat's are pointing at the breakpoint after it's
13297 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13298 in all threads for now. Note that we cannot just remove bpstats
13299 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13300 commands are associated with the bpstat; if we remove it here,
13301 then the later call to bpstat_do_actions (&stop_bpstat); in
13302 event-top.c won't do anything, and temporary breakpoints with
13303 commands won't work. */
13305 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13307 /* Now that breakpoint is removed from breakpoint list, update the
13308 global location list. This will remove locations that used to
13309 belong to this breakpoint. Do this before freeing the breakpoint
13310 itself, since remove_breakpoint looks at location's owner. It
13311 might be better design to have location completely
13312 self-contained, but it's not the case now. */
13313 update_global_location_list (0);
13315 bpt->ops->dtor (bpt);
13316 /* On the chance that someone will soon try again to delete this
13317 same bp, we mark it as deleted before freeing its storage. */
13318 bpt->type = bp_none;
13323 do_delete_breakpoint_cleanup (void *b)
13325 delete_breakpoint (b);
13329 make_cleanup_delete_breakpoint (struct breakpoint *b)
13331 return make_cleanup (do_delete_breakpoint_cleanup, b);
13334 /* Iterator function to call a user-provided callback function once
13335 for each of B and its related breakpoints. */
13338 iterate_over_related_breakpoints (struct breakpoint *b,
13339 void (*function) (struct breakpoint *,
13343 struct breakpoint *related;
13348 struct breakpoint *next;
13350 /* FUNCTION may delete RELATED. */
13351 next = related->related_breakpoint;
13353 if (next == related)
13355 /* RELATED is the last ring entry. */
13356 function (related, data);
13358 /* FUNCTION may have deleted it, so we'd never reach back to
13359 B. There's nothing left to do anyway, so just break
13364 function (related, data);
13368 while (related != b);
13372 do_delete_breakpoint (struct breakpoint *b, void *ignore)
13374 delete_breakpoint (b);
13377 /* A callback for map_breakpoint_numbers that calls
13378 delete_breakpoint. */
13381 do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
13383 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
13387 delete_command (char *arg, int from_tty)
13389 struct breakpoint *b, *b_tmp;
13395 int breaks_to_delete = 0;
13397 /* Delete all breakpoints if no argument. Do not delete
13398 internal breakpoints, these have to be deleted with an
13399 explicit breakpoint number argument. */
13400 ALL_BREAKPOINTS (b)
13401 if (user_breakpoint_p (b))
13403 breaks_to_delete = 1;
13407 /* Ask user only if there are some breakpoints to delete. */
13409 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
13411 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13412 if (user_breakpoint_p (b))
13413 delete_breakpoint (b);
13417 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
13421 all_locations_are_pending (struct bp_location *loc)
13423 for (; loc; loc = loc->next)
13424 if (!loc->shlib_disabled
13425 && !loc->pspace->executing_startup)
13430 /* Subroutine of update_breakpoint_locations to simplify it.
13431 Return non-zero if multiple fns in list LOC have the same name.
13432 Null names are ignored. */
13435 ambiguous_names_p (struct bp_location *loc)
13437 struct bp_location *l;
13438 htab_t htab = htab_create_alloc (13, htab_hash_string,
13439 (int (*) (const void *,
13440 const void *)) streq,
13441 NULL, xcalloc, xfree);
13443 for (l = loc; l != NULL; l = l->next)
13446 const char *name = l->function_name;
13448 /* Allow for some names to be NULL, ignore them. */
13452 slot = (const char **) htab_find_slot (htab, (const void *) name,
13454 /* NOTE: We can assume slot != NULL here because xcalloc never
13458 htab_delete (htab);
13464 htab_delete (htab);
13468 /* When symbols change, it probably means the sources changed as well,
13469 and it might mean the static tracepoint markers are no longer at
13470 the same address or line numbers they used to be at last we
13471 checked. Losing your static tracepoints whenever you rebuild is
13472 undesirable. This function tries to resync/rematch gdb static
13473 tracepoints with the markers on the target, for static tracepoints
13474 that have not been set by marker id. Static tracepoint that have
13475 been set by marker id are reset by marker id in breakpoint_re_set.
13478 1) For a tracepoint set at a specific address, look for a marker at
13479 the old PC. If one is found there, assume to be the same marker.
13480 If the name / string id of the marker found is different from the
13481 previous known name, assume that means the user renamed the marker
13482 in the sources, and output a warning.
13484 2) For a tracepoint set at a given line number, look for a marker
13485 at the new address of the old line number. If one is found there,
13486 assume to be the same marker. If the name / string id of the
13487 marker found is different from the previous known name, assume that
13488 means the user renamed the marker in the sources, and output a
13491 3) If a marker is no longer found at the same address or line, it
13492 may mean the marker no longer exists. But it may also just mean
13493 the code changed a bit. Maybe the user added a few lines of code
13494 that made the marker move up or down (in line number terms). Ask
13495 the target for info about the marker with the string id as we knew
13496 it. If found, update line number and address in the matching
13497 static tracepoint. This will get confused if there's more than one
13498 marker with the same ID (possible in UST, although unadvised
13499 precisely because it confuses tools). */
13501 static struct symtab_and_line
13502 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
13504 struct tracepoint *tp = (struct tracepoint *) b;
13505 struct static_tracepoint_marker marker;
13510 find_line_pc (sal.symtab, sal.line, &pc);
13512 if (target_static_tracepoint_marker_at (pc, &marker))
13514 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
13515 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13517 tp->static_trace_marker_id, marker.str_id);
13519 xfree (tp->static_trace_marker_id);
13520 tp->static_trace_marker_id = xstrdup (marker.str_id);
13521 release_static_tracepoint_marker (&marker);
13526 /* Old marker wasn't found on target at lineno. Try looking it up
13528 if (!sal.explicit_pc
13530 && sal.symtab != NULL
13531 && tp->static_trace_marker_id != NULL)
13533 VEC(static_tracepoint_marker_p) *markers;
13536 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
13538 if (!VEC_empty(static_tracepoint_marker_p, markers))
13540 struct symtab_and_line sal2;
13541 struct symbol *sym;
13542 struct static_tracepoint_marker *tpmarker;
13543 struct ui_out *uiout = current_uiout;
13545 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
13547 xfree (tp->static_trace_marker_id);
13548 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
13550 warning (_("marker for static tracepoint %d (%s) not "
13551 "found at previous line number"),
13552 b->number, tp->static_trace_marker_id);
13556 sal2.pc = tpmarker->address;
13558 sal2 = find_pc_line (tpmarker->address, 0);
13559 sym = find_pc_sect_function (tpmarker->address, NULL);
13560 ui_out_text (uiout, "Now in ");
13563 ui_out_field_string (uiout, "func",
13564 SYMBOL_PRINT_NAME (sym));
13565 ui_out_text (uiout, " at ");
13567 ui_out_field_string (uiout, "file", sal2.symtab->filename);
13568 ui_out_text (uiout, ":");
13570 if (ui_out_is_mi_like_p (uiout))
13572 char *fullname = symtab_to_fullname (sal2.symtab);
13575 ui_out_field_string (uiout, "fullname", fullname);
13578 ui_out_field_int (uiout, "line", sal2.line);
13579 ui_out_text (uiout, "\n");
13581 b->loc->line_number = sal2.line;
13583 xfree (b->loc->source_file);
13585 b->loc->source_file = xstrdup (sal2.symtab->filename);
13587 b->loc->source_file = NULL;
13589 xfree (b->addr_string);
13590 b->addr_string = xstrprintf ("%s:%d",
13591 sal2.symtab->filename,
13592 b->loc->line_number);
13594 /* Might be nice to check if function changed, and warn if
13597 release_static_tracepoint_marker (tpmarker);
13603 /* Returns 1 iff locations A and B are sufficiently same that
13604 we don't need to report breakpoint as changed. */
13607 locations_are_equal (struct bp_location *a, struct bp_location *b)
13611 if (a->address != b->address)
13614 if (a->shlib_disabled != b->shlib_disabled)
13617 if (a->enabled != b->enabled)
13624 if ((a == NULL) != (b == NULL))
13630 /* Create new breakpoint locations for B (a hardware or software breakpoint)
13631 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
13632 a ranged breakpoint. */
13635 update_breakpoint_locations (struct breakpoint *b,
13636 struct symtabs_and_lines sals,
13637 struct symtabs_and_lines sals_end)
13640 struct bp_location *existing_locations = b->loc;
13642 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
13644 /* Ranged breakpoints have only one start location and one end
13646 b->enable_state = bp_disabled;
13647 update_global_location_list (1);
13648 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13649 "multiple locations found\n"),
13654 /* If there's no new locations, and all existing locations are
13655 pending, don't do anything. This optimizes the common case where
13656 all locations are in the same shared library, that was unloaded.
13657 We'd like to retain the location, so that when the library is
13658 loaded again, we don't loose the enabled/disabled status of the
13659 individual locations. */
13660 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
13665 for (i = 0; i < sals.nelts; ++i)
13667 struct bp_location *new_loc;
13669 switch_to_program_space_and_thread (sals.sals[i].pspace);
13671 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
13673 /* Reparse conditions, they might contain references to the
13675 if (b->cond_string != NULL)
13678 volatile struct gdb_exception e;
13680 s = b->cond_string;
13681 TRY_CATCH (e, RETURN_MASK_ERROR)
13683 new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
13684 block_for_pc (sals.sals[i].pc),
13689 warning (_("failed to reevaluate condition "
13690 "for breakpoint %d: %s"),
13691 b->number, e.message);
13692 new_loc->enabled = 0;
13696 if (sals_end.nelts)
13698 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
13700 new_loc->length = end - sals.sals[0].pc + 1;
13704 /* Update locations of permanent breakpoints. */
13705 if (b->enable_state == bp_permanent)
13706 make_breakpoint_permanent (b);
13708 /* If possible, carry over 'disable' status from existing
13711 struct bp_location *e = existing_locations;
13712 /* If there are multiple breakpoints with the same function name,
13713 e.g. for inline functions, comparing function names won't work.
13714 Instead compare pc addresses; this is just a heuristic as things
13715 may have moved, but in practice it gives the correct answer
13716 often enough until a better solution is found. */
13717 int have_ambiguous_names = ambiguous_names_p (b->loc);
13719 for (; e; e = e->next)
13721 if (!e->enabled && e->function_name)
13723 struct bp_location *l = b->loc;
13724 if (have_ambiguous_names)
13726 for (; l; l = l->next)
13727 if (breakpoint_locations_match (e, l))
13735 for (; l; l = l->next)
13736 if (l->function_name
13737 && strcmp (e->function_name, l->function_name) == 0)
13747 if (!locations_are_equal (existing_locations, b->loc))
13748 observer_notify_breakpoint_modified (b);
13750 update_global_location_list (1);
13753 /* Find the SaL locations corresponding to the given ADDR_STRING.
13754 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13756 static struct symtabs_and_lines
13757 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
13760 struct symtabs_and_lines sals = {0};
13761 volatile struct gdb_exception e;
13763 gdb_assert (b->ops != NULL);
13766 TRY_CATCH (e, RETURN_MASK_ERROR)
13768 b->ops->decode_linespec (b, &s, &sals);
13772 int not_found_and_ok = 0;
13773 /* For pending breakpoints, it's expected that parsing will
13774 fail until the right shared library is loaded. User has
13775 already told to create pending breakpoints and don't need
13776 extra messages. If breakpoint is in bp_shlib_disabled
13777 state, then user already saw the message about that
13778 breakpoint being disabled, and don't want to see more
13780 if (e.error == NOT_FOUND_ERROR
13781 && (b->condition_not_parsed
13782 || (b->loc && b->loc->shlib_disabled)
13783 || (b->loc && b->loc->pspace->executing_startup)
13784 || b->enable_state == bp_disabled))
13785 not_found_and_ok = 1;
13787 if (!not_found_and_ok)
13789 /* We surely don't want to warn about the same breakpoint
13790 10 times. One solution, implemented here, is disable
13791 the breakpoint on error. Another solution would be to
13792 have separate 'warning emitted' flag. Since this
13793 happens only when a binary has changed, I don't know
13794 which approach is better. */
13795 b->enable_state = bp_disabled;
13796 throw_exception (e);
13800 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
13804 for (i = 0; i < sals.nelts; ++i)
13805 resolve_sal_pc (&sals.sals[i]);
13806 if (b->condition_not_parsed && s && s[0])
13808 char *cond_string = 0;
13811 char *extra_string = NULL;
13813 find_condition_and_thread (s, sals.sals[0].pc,
13814 &cond_string, &thread, &task,
13817 b->cond_string = cond_string;
13818 b->thread = thread;
13821 b->extra_string = extra_string;
13822 b->condition_not_parsed = 0;
13825 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
13826 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
13836 /* The default re_set method, for typical hardware or software
13837 breakpoints. Reevaluate the breakpoint and recreate its
13841 breakpoint_re_set_default (struct breakpoint *b)
13844 struct symtabs_and_lines sals, sals_end;
13845 struct symtabs_and_lines expanded = {0};
13846 struct symtabs_and_lines expanded_end = {0};
13848 sals = addr_string_to_sals (b, b->addr_string, &found);
13851 make_cleanup (xfree, sals.sals);
13855 if (b->addr_string_range_end)
13857 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
13860 make_cleanup (xfree, sals_end.sals);
13861 expanded_end = sals_end;
13865 update_breakpoint_locations (b, expanded, expanded_end);
13868 /* Default method for creating SALs from an address string. It basically
13869 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13872 create_sals_from_address_default (char **arg,
13873 struct linespec_result *canonical,
13874 enum bptype type_wanted,
13875 char *addr_start, char **copy_arg)
13877 parse_breakpoint_sals (arg, canonical);
13880 /* Call create_breakpoints_sal for the given arguments. This is the default
13881 function for the `create_breakpoints_sal' method of
13885 create_breakpoints_sal_default (struct gdbarch *gdbarch,
13886 struct linespec_result *canonical,
13887 struct linespec_sals *lsal,
13889 char *extra_string,
13890 enum bptype type_wanted,
13891 enum bpdisp disposition,
13893 int task, int ignore_count,
13894 const struct breakpoint_ops *ops,
13895 int from_tty, int enabled,
13896 int internal, unsigned flags)
13898 create_breakpoints_sal (gdbarch, canonical, cond_string,
13900 type_wanted, disposition,
13901 thread, task, ignore_count, ops, from_tty,
13902 enabled, internal, flags);
13905 /* Decode the line represented by S by calling decode_line_full. This is the
13906 default function for the `decode_linespec' method of breakpoint_ops. */
13909 decode_linespec_default (struct breakpoint *b, char **s,
13910 struct symtabs_and_lines *sals)
13912 struct linespec_result canonical;
13914 init_linespec_result (&canonical);
13915 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
13916 (struct symtab *) NULL, 0,
13917 &canonical, multiple_symbols_all,
13920 /* We should get 0 or 1 resulting SALs. */
13921 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
13923 if (VEC_length (linespec_sals, canonical.sals) > 0)
13925 struct linespec_sals *lsal;
13927 lsal = VEC_index (linespec_sals, canonical.sals, 0);
13928 *sals = lsal->sals;
13929 /* Arrange it so the destructor does not free the
13931 lsal->sals.sals = NULL;
13934 destroy_linespec_result (&canonical);
13937 /* Prepare the global context for a re-set of breakpoint B. */
13939 static struct cleanup *
13940 prepare_re_set_context (struct breakpoint *b)
13942 struct cleanup *cleanups;
13944 input_radix = b->input_radix;
13945 cleanups = save_current_space_and_thread ();
13946 if (b->pspace != NULL)
13947 switch_to_program_space_and_thread (b->pspace);
13948 set_language (b->language);
13953 /* Reset a breakpoint given it's struct breakpoint * BINT.
13954 The value we return ends up being the return value from catch_errors.
13955 Unused in this case. */
13958 breakpoint_re_set_one (void *bint)
13960 /* Get past catch_errs. */
13961 struct breakpoint *b = (struct breakpoint *) bint;
13962 struct cleanup *cleanups;
13964 cleanups = prepare_re_set_context (b);
13965 b->ops->re_set (b);
13966 do_cleanups (cleanups);
13970 /* Re-set all breakpoints after symbols have been re-loaded. */
13972 breakpoint_re_set (void)
13974 struct breakpoint *b, *b_tmp;
13975 enum language save_language;
13976 int save_input_radix;
13977 struct cleanup *old_chain;
13979 save_language = current_language->la_language;
13980 save_input_radix = input_radix;
13981 old_chain = save_current_program_space ();
13983 ALL_BREAKPOINTS_SAFE (b, b_tmp)
13985 /* Format possible error msg. */
13986 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
13988 struct cleanup *cleanups = make_cleanup (xfree, message);
13989 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
13990 do_cleanups (cleanups);
13992 set_language (save_language);
13993 input_radix = save_input_radix;
13995 jit_breakpoint_re_set ();
13997 do_cleanups (old_chain);
13999 create_overlay_event_breakpoint ();
14000 create_longjmp_master_breakpoint ();
14001 create_std_terminate_master_breakpoint ();
14002 create_exception_master_breakpoint ();
14004 /* While we're at it, reset the skip list too. */
14008 /* Reset the thread number of this breakpoint:
14010 - If the breakpoint is for all threads, leave it as-is.
14011 - Else, reset it to the current thread for inferior_ptid. */
14013 breakpoint_re_set_thread (struct breakpoint *b)
14015 if (b->thread != -1)
14017 if (in_thread_list (inferior_ptid))
14018 b->thread = pid_to_thread_id (inferior_ptid);
14020 /* We're being called after following a fork. The new fork is
14021 selected as current, and unless this was a vfork will have a
14022 different program space from the original thread. Reset that
14024 b->loc->pspace = current_program_space;
14028 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14029 If from_tty is nonzero, it prints a message to that effect,
14030 which ends with a period (no newline). */
14033 set_ignore_count (int bptnum, int count, int from_tty)
14035 struct breakpoint *b;
14040 ALL_BREAKPOINTS (b)
14041 if (b->number == bptnum)
14043 if (is_tracepoint (b))
14045 if (from_tty && count != 0)
14046 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14051 b->ignore_count = count;
14055 printf_filtered (_("Will stop next time "
14056 "breakpoint %d is reached."),
14058 else if (count == 1)
14059 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14062 printf_filtered (_("Will ignore next %d "
14063 "crossings of breakpoint %d."),
14066 breakpoints_changed ();
14067 observer_notify_breakpoint_modified (b);
14071 error (_("No breakpoint number %d."), bptnum);
14074 /* Command to set ignore-count of breakpoint N to COUNT. */
14077 ignore_command (char *args, int from_tty)
14083 error_no_arg (_("a breakpoint number"));
14085 num = get_number (&p);
14087 error (_("bad breakpoint number: '%s'"), args);
14089 error (_("Second argument (specified ignore-count) is missing."));
14091 set_ignore_count (num,
14092 longest_to_int (value_as_long (parse_and_eval (p))),
14095 printf_filtered ("\n");
14098 /* Call FUNCTION on each of the breakpoints
14099 whose numbers are given in ARGS. */
14102 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
14107 struct breakpoint *b, *tmp;
14109 struct get_number_or_range_state state;
14112 error_no_arg (_("one or more breakpoint numbers"));
14114 init_number_or_range (&state, args);
14116 while (!state.finished)
14118 char *p = state.string;
14122 num = get_number_or_range (&state);
14125 warning (_("bad breakpoint number at or near '%s'"), p);
14129 ALL_BREAKPOINTS_SAFE (b, tmp)
14130 if (b->number == num)
14133 function (b, data);
14137 printf_unfiltered (_("No breakpoint number %d.\n"), num);
14142 static struct bp_location *
14143 find_location_by_number (char *number)
14145 char *dot = strchr (number, '.');
14149 struct breakpoint *b;
14150 struct bp_location *loc;
14155 bp_num = get_number (&p1);
14157 error (_("Bad breakpoint number '%s'"), number);
14159 ALL_BREAKPOINTS (b)
14160 if (b->number == bp_num)
14165 if (!b || b->number != bp_num)
14166 error (_("Bad breakpoint number '%s'"), number);
14169 loc_num = get_number (&p1);
14171 error (_("Bad breakpoint location number '%s'"), number);
14175 for (;loc_num && loc; --loc_num, loc = loc->next)
14178 error (_("Bad breakpoint location number '%s'"), dot+1);
14184 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14185 If from_tty is nonzero, it prints a message to that effect,
14186 which ends with a period (no newline). */
14189 disable_breakpoint (struct breakpoint *bpt)
14191 /* Never disable a watchpoint scope breakpoint; we want to
14192 hit them when we leave scope so we can delete both the
14193 watchpoint and its scope breakpoint at that time. */
14194 if (bpt->type == bp_watchpoint_scope)
14197 /* You can't disable permanent breakpoints. */
14198 if (bpt->enable_state == bp_permanent)
14201 bpt->enable_state = bp_disabled;
14203 /* Mark breakpoint locations modified. */
14204 mark_breakpoint_modified (bpt);
14206 if (target_supports_enable_disable_tracepoint ()
14207 && current_trace_status ()->running && is_tracepoint (bpt))
14209 struct bp_location *location;
14211 for (location = bpt->loc; location; location = location->next)
14212 target_disable_tracepoint (location);
14215 update_global_location_list (0);
14217 observer_notify_breakpoint_modified (bpt);
14220 /* A callback for iterate_over_related_breakpoints. */
14223 do_disable_breakpoint (struct breakpoint *b, void *ignore)
14225 disable_breakpoint (b);
14228 /* A callback for map_breakpoint_numbers that calls
14229 disable_breakpoint. */
14232 do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
14234 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
14238 disable_command (char *args, int from_tty)
14242 struct breakpoint *bpt;
14244 ALL_BREAKPOINTS (bpt)
14245 if (user_breakpoint_p (bpt))
14246 disable_breakpoint (bpt);
14248 else if (strchr (args, '.'))
14250 struct bp_location *loc = find_location_by_number (args);
14256 mark_breakpoint_location_modified (loc);
14258 if (target_supports_enable_disable_tracepoint ()
14259 && current_trace_status ()->running && loc->owner
14260 && is_tracepoint (loc->owner))
14261 target_disable_tracepoint (loc);
14263 update_global_location_list (0);
14266 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
14270 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14273 int target_resources_ok;
14275 if (bpt->type == bp_hardware_breakpoint)
14278 i = hw_breakpoint_used_count ();
14279 target_resources_ok =
14280 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
14282 if (target_resources_ok == 0)
14283 error (_("No hardware breakpoint support in the target."));
14284 else if (target_resources_ok < 0)
14285 error (_("Hardware breakpoints used exceeds limit."));
14288 if (is_watchpoint (bpt))
14290 /* Initialize it just to avoid a GCC false warning. */
14291 enum enable_state orig_enable_state = 0;
14292 volatile struct gdb_exception e;
14294 TRY_CATCH (e, RETURN_MASK_ALL)
14296 struct watchpoint *w = (struct watchpoint *) bpt;
14298 orig_enable_state = bpt->enable_state;
14299 bpt->enable_state = bp_enabled;
14300 update_watchpoint (w, 1 /* reparse */);
14304 bpt->enable_state = orig_enable_state;
14305 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
14311 if (bpt->enable_state != bp_permanent)
14312 bpt->enable_state = bp_enabled;
14314 bpt->enable_state = bp_enabled;
14316 /* Mark breakpoint locations modified. */
14317 mark_breakpoint_modified (bpt);
14319 if (target_supports_enable_disable_tracepoint ()
14320 && current_trace_status ()->running && is_tracepoint (bpt))
14322 struct bp_location *location;
14324 for (location = bpt->loc; location; location = location->next)
14325 target_enable_tracepoint (location);
14328 bpt->disposition = disposition;
14329 bpt->enable_count = count;
14330 update_global_location_list (1);
14331 breakpoints_changed ();
14333 observer_notify_breakpoint_modified (bpt);
14338 enable_breakpoint (struct breakpoint *bpt)
14340 enable_breakpoint_disp (bpt, bpt->disposition, 0);
14344 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
14346 enable_breakpoint (bpt);
14349 /* A callback for map_breakpoint_numbers that calls
14350 enable_breakpoint. */
14353 do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
14355 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
14358 /* The enable command enables the specified breakpoints (or all defined
14359 breakpoints) so they once again become (or continue to be) effective
14360 in stopping the inferior. */
14363 enable_command (char *args, int from_tty)
14367 struct breakpoint *bpt;
14369 ALL_BREAKPOINTS (bpt)
14370 if (user_breakpoint_p (bpt))
14371 enable_breakpoint (bpt);
14373 else if (strchr (args, '.'))
14375 struct bp_location *loc = find_location_by_number (args);
14381 mark_breakpoint_location_modified (loc);
14383 if (target_supports_enable_disable_tracepoint ()
14384 && current_trace_status ()->running && loc->owner
14385 && is_tracepoint (loc->owner))
14386 target_enable_tracepoint (loc);
14388 update_global_location_list (1);
14391 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
14394 /* This struct packages up disposition data for application to multiple
14404 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
14406 struct disp_data disp_data = *(struct disp_data *) arg;
14408 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
14412 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
14414 struct disp_data disp = { disp_disable, 1 };
14416 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14420 enable_once_command (char *args, int from_tty)
14422 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
14426 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
14428 struct disp_data disp = { disp_disable, *(int *) countptr };
14430 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14434 enable_count_command (char *args, int from_tty)
14436 int count = get_number (&args);
14438 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
14442 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
14444 struct disp_data disp = { disp_del, 1 };
14446 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14450 enable_delete_command (char *args, int from_tty)
14452 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
14456 set_breakpoint_cmd (char *args, int from_tty)
14461 show_breakpoint_cmd (char *args, int from_tty)
14465 /* Invalidate last known value of any hardware watchpoint if
14466 the memory which that value represents has been written to by
14470 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
14471 const bfd_byte *data)
14473 struct breakpoint *bp;
14475 ALL_BREAKPOINTS (bp)
14476 if (bp->enable_state == bp_enabled
14477 && bp->type == bp_hardware_watchpoint)
14479 struct watchpoint *wp = (struct watchpoint *) bp;
14481 if (wp->val_valid && wp->val)
14483 struct bp_location *loc;
14485 for (loc = bp->loc; loc != NULL; loc = loc->next)
14486 if (loc->loc_type == bp_loc_hardware_watchpoint
14487 && loc->address + loc->length > addr
14488 && addr + len > loc->address)
14490 value_free (wp->val);
14498 /* Create and insert a raw software breakpoint at PC. Return an
14499 identifier, which should be used to remove the breakpoint later.
14500 In general, places which call this should be using something on the
14501 breakpoint chain instead; this function should be eliminated
14505 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
14506 struct address_space *aspace, CORE_ADDR pc)
14508 struct bp_target_info *bp_tgt;
14510 bp_tgt = XZALLOC (struct bp_target_info);
14512 bp_tgt->placed_address_space = aspace;
14513 bp_tgt->placed_address = pc;
14515 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
14517 /* Could not insert the breakpoint. */
14525 /* Remove a breakpoint BP inserted by
14526 deprecated_insert_raw_breakpoint. */
14529 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
14531 struct bp_target_info *bp_tgt = bp;
14534 ret = target_remove_breakpoint (gdbarch, bp_tgt);
14540 /* One (or perhaps two) breakpoints used for software single
14543 static void *single_step_breakpoints[2];
14544 static struct gdbarch *single_step_gdbarch[2];
14546 /* Create and insert a breakpoint for software single step. */
14549 insert_single_step_breakpoint (struct gdbarch *gdbarch,
14550 struct address_space *aspace,
14555 if (single_step_breakpoints[0] == NULL)
14557 bpt_p = &single_step_breakpoints[0];
14558 single_step_gdbarch[0] = gdbarch;
14562 gdb_assert (single_step_breakpoints[1] == NULL);
14563 bpt_p = &single_step_breakpoints[1];
14564 single_step_gdbarch[1] = gdbarch;
14567 /* NOTE drow/2006-04-11: A future improvement to this function would
14568 be to only create the breakpoints once, and actually put them on
14569 the breakpoint chain. That would let us use set_raw_breakpoint.
14570 We could adjust the addresses each time they were needed. Doing
14571 this requires corresponding changes elsewhere where single step
14572 breakpoints are handled, however. So, for now, we use this. */
14574 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
14575 if (*bpt_p == NULL)
14576 error (_("Could not insert single-step breakpoint at %s"),
14577 paddress (gdbarch, next_pc));
14580 /* Check if the breakpoints used for software single stepping
14581 were inserted or not. */
14584 single_step_breakpoints_inserted (void)
14586 return (single_step_breakpoints[0] != NULL
14587 || single_step_breakpoints[1] != NULL);
14590 /* Remove and delete any breakpoints used for software single step. */
14593 remove_single_step_breakpoints (void)
14595 gdb_assert (single_step_breakpoints[0] != NULL);
14597 /* See insert_single_step_breakpoint for more about this deprecated
14599 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
14600 single_step_breakpoints[0]);
14601 single_step_gdbarch[0] = NULL;
14602 single_step_breakpoints[0] = NULL;
14604 if (single_step_breakpoints[1] != NULL)
14606 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
14607 single_step_breakpoints[1]);
14608 single_step_gdbarch[1] = NULL;
14609 single_step_breakpoints[1] = NULL;
14613 /* Delete software single step breakpoints without removing them from
14614 the inferior. This is intended to be used if the inferior's address
14615 space where they were inserted is already gone, e.g. after exit or
14619 cancel_single_step_breakpoints (void)
14623 for (i = 0; i < 2; i++)
14624 if (single_step_breakpoints[i])
14626 xfree (single_step_breakpoints[i]);
14627 single_step_breakpoints[i] = NULL;
14628 single_step_gdbarch[i] = NULL;
14632 /* Detach software single-step breakpoints from INFERIOR_PTID without
14636 detach_single_step_breakpoints (void)
14640 for (i = 0; i < 2; i++)
14641 if (single_step_breakpoints[i])
14642 target_remove_breakpoint (single_step_gdbarch[i],
14643 single_step_breakpoints[i]);
14646 /* Check whether a software single-step breakpoint is inserted at
14650 single_step_breakpoint_inserted_here_p (struct address_space *aspace,
14655 for (i = 0; i < 2; i++)
14657 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
14659 && breakpoint_address_match (bp_tgt->placed_address_space,
14660 bp_tgt->placed_address,
14668 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
14669 non-zero otherwise. */
14671 is_syscall_catchpoint_enabled (struct breakpoint *bp)
14673 if (syscall_catchpoint_p (bp)
14674 && bp->enable_state != bp_disabled
14675 && bp->enable_state != bp_call_disabled)
14682 catch_syscall_enabled (void)
14684 struct catch_syscall_inferior_data *inf_data
14685 = get_catch_syscall_inferior_data (current_inferior ());
14687 return inf_data->total_syscalls_count != 0;
14691 catching_syscall_number (int syscall_number)
14693 struct breakpoint *bp;
14695 ALL_BREAKPOINTS (bp)
14696 if (is_syscall_catchpoint_enabled (bp))
14698 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
14700 if (c->syscalls_to_be_caught)
14704 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
14706 if (syscall_number == iter)
14716 /* Complete syscall names. Used by "catch syscall". */
14717 static VEC (char_ptr) *
14718 catch_syscall_completer (struct cmd_list_element *cmd,
14719 char *text, char *word)
14721 const char **list = get_syscall_names ();
14722 VEC (char_ptr) *retlist
14723 = (list == NULL) ? NULL : complete_on_enum (list, text, word);
14729 /* Tracepoint-specific operations. */
14731 /* Set tracepoint count to NUM. */
14733 set_tracepoint_count (int num)
14735 tracepoint_count = num;
14736 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
14740 trace_command (char *arg, int from_tty)
14742 struct breakpoint_ops *ops;
14743 const char *arg_cp = arg;
14745 if (arg && probe_linespec_to_ops (&arg_cp))
14746 ops = &tracepoint_probe_breakpoint_ops;
14748 ops = &tracepoint_breakpoint_ops;
14750 if (create_breakpoint (get_current_arch (),
14752 NULL, 0, NULL, 1 /* parse arg */,
14754 bp_tracepoint /* type_wanted */,
14755 0 /* Ignore count */,
14756 pending_break_support,
14760 0 /* internal */, 0))
14761 set_tracepoint_count (breakpoint_count);
14765 ftrace_command (char *arg, int from_tty)
14767 if (create_breakpoint (get_current_arch (),
14769 NULL, 0, NULL, 1 /* parse arg */,
14771 bp_fast_tracepoint /* type_wanted */,
14772 0 /* Ignore count */,
14773 pending_break_support,
14774 &tracepoint_breakpoint_ops,
14777 0 /* internal */, 0))
14778 set_tracepoint_count (breakpoint_count);
14781 /* strace command implementation. Creates a static tracepoint. */
14784 strace_command (char *arg, int from_tty)
14786 struct breakpoint_ops *ops;
14788 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14789 or with a normal static tracepoint. */
14790 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
14791 ops = &strace_marker_breakpoint_ops;
14793 ops = &tracepoint_breakpoint_ops;
14795 if (create_breakpoint (get_current_arch (),
14797 NULL, 0, NULL, 1 /* parse arg */,
14799 bp_static_tracepoint /* type_wanted */,
14800 0 /* Ignore count */,
14801 pending_break_support,
14805 0 /* internal */, 0))
14806 set_tracepoint_count (breakpoint_count);
14809 /* Set up a fake reader function that gets command lines from a linked
14810 list that was acquired during tracepoint uploading. */
14812 static struct uploaded_tp *this_utp;
14813 static int next_cmd;
14816 read_uploaded_action (void)
14820 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
14827 /* Given information about a tracepoint as recorded on a target (which
14828 can be either a live system or a trace file), attempt to create an
14829 equivalent GDB tracepoint. This is not a reliable process, since
14830 the target does not necessarily have all the information used when
14831 the tracepoint was originally defined. */
14833 struct tracepoint *
14834 create_tracepoint_from_upload (struct uploaded_tp *utp)
14836 char *addr_str, small_buf[100];
14837 struct tracepoint *tp;
14839 if (utp->at_string)
14840 addr_str = utp->at_string;
14843 /* In the absence of a source location, fall back to raw
14844 address. Since there is no way to confirm that the address
14845 means the same thing as when the trace was started, warn the
14847 warning (_("Uploaded tracepoint %d has no "
14848 "source location, using raw address"),
14850 sprintf (small_buf, "*%s", hex_string (utp->addr));
14851 addr_str = small_buf;
14854 /* There's not much we can do with a sequence of bytecodes. */
14855 if (utp->cond && !utp->cond_string)
14856 warning (_("Uploaded tracepoint %d condition "
14857 "has no source form, ignoring it"),
14860 if (!create_breakpoint (get_current_arch (),
14862 utp->cond_string, -1, NULL,
14863 0 /* parse cond/thread */,
14865 utp->type /* type_wanted */,
14866 0 /* Ignore count */,
14867 pending_break_support,
14868 &tracepoint_breakpoint_ops,
14870 utp->enabled /* enabled */,
14872 CREATE_BREAKPOINT_FLAGS_INSERTED))
14875 set_tracepoint_count (breakpoint_count);
14877 /* Get the tracepoint we just created. */
14878 tp = get_tracepoint (tracepoint_count);
14879 gdb_assert (tp != NULL);
14883 sprintf (small_buf, "%d %d", utp->pass, tp->base.number);
14885 trace_pass_command (small_buf, 0);
14888 /* If we have uploaded versions of the original commands, set up a
14889 special-purpose "reader" function and call the usual command line
14890 reader, then pass the result to the breakpoint command-setting
14892 if (!VEC_empty (char_ptr, utp->cmd_strings))
14894 struct command_line *cmd_list;
14899 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
14901 breakpoint_set_commands (&tp->base, cmd_list);
14903 else if (!VEC_empty (char_ptr, utp->actions)
14904 || !VEC_empty (char_ptr, utp->step_actions))
14905 warning (_("Uploaded tracepoint %d actions "
14906 "have no source form, ignoring them"),
14909 /* Copy any status information that might be available. */
14910 tp->base.hit_count = utp->hit_count;
14911 tp->traceframe_usage = utp->traceframe_usage;
14916 /* Print information on tracepoint number TPNUM_EXP, or all if
14920 tracepoints_info (char *args, int from_tty)
14922 struct ui_out *uiout = current_uiout;
14925 num_printed = breakpoint_1 (args, 0, is_tracepoint);
14927 if (num_printed == 0)
14929 if (args == NULL || *args == '\0')
14930 ui_out_message (uiout, 0, "No tracepoints.\n");
14932 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
14935 default_collect_info ();
14938 /* The 'enable trace' command enables tracepoints.
14939 Not supported by all targets. */
14941 enable_trace_command (char *args, int from_tty)
14943 enable_command (args, from_tty);
14946 /* The 'disable trace' command disables tracepoints.
14947 Not supported by all targets. */
14949 disable_trace_command (char *args, int from_tty)
14951 disable_command (args, from_tty);
14954 /* Remove a tracepoint (or all if no argument). */
14956 delete_trace_command (char *arg, int from_tty)
14958 struct breakpoint *b, *b_tmp;
14964 int breaks_to_delete = 0;
14966 /* Delete all breakpoints if no argument.
14967 Do not delete internal or call-dummy breakpoints, these
14968 have to be deleted with an explicit breakpoint number
14970 ALL_TRACEPOINTS (b)
14971 if (is_tracepoint (b) && user_breakpoint_p (b))
14973 breaks_to_delete = 1;
14977 /* Ask user only if there are some breakpoints to delete. */
14979 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
14981 ALL_BREAKPOINTS_SAFE (b, b_tmp)
14982 if (is_tracepoint (b) && user_breakpoint_p (b))
14983 delete_breakpoint (b);
14987 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
14990 /* Helper function for trace_pass_command. */
14993 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
14995 tp->pass_count = count;
14996 observer_notify_tracepoint_modified (tp->base.number);
14998 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14999 tp->base.number, count);
15002 /* Set passcount for tracepoint.
15004 First command argument is passcount, second is tracepoint number.
15005 If tracepoint number omitted, apply to most recently defined.
15006 Also accepts special argument "all". */
15009 trace_pass_command (char *args, int from_tty)
15011 struct tracepoint *t1;
15012 unsigned int count;
15014 if (args == 0 || *args == 0)
15015 error (_("passcount command requires an "
15016 "argument (count + optional TP num)"));
15018 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
15020 while (*args && isspace ((int) *args))
15023 if (*args && strncasecmp (args, "all", 3) == 0)
15025 struct breakpoint *b;
15027 args += 3; /* Skip special argument "all". */
15029 error (_("Junk at end of arguments."));
15031 ALL_TRACEPOINTS (b)
15033 t1 = (struct tracepoint *) b;
15034 trace_pass_set_count (t1, count, from_tty);
15037 else if (*args == '\0')
15039 t1 = get_tracepoint_by_number (&args, NULL, 1);
15041 trace_pass_set_count (t1, count, from_tty);
15045 struct get_number_or_range_state state;
15047 init_number_or_range (&state, args);
15048 while (!state.finished)
15050 t1 = get_tracepoint_by_number (&args, &state, 1);
15052 trace_pass_set_count (t1, count, from_tty);
15057 struct tracepoint *
15058 get_tracepoint (int num)
15060 struct breakpoint *t;
15062 ALL_TRACEPOINTS (t)
15063 if (t->number == num)
15064 return (struct tracepoint *) t;
15069 /* Find the tracepoint with the given target-side number (which may be
15070 different from the tracepoint number after disconnecting and
15073 struct tracepoint *
15074 get_tracepoint_by_number_on_target (int num)
15076 struct breakpoint *b;
15078 ALL_TRACEPOINTS (b)
15080 struct tracepoint *t = (struct tracepoint *) b;
15082 if (t->number_on_target == num)
15089 /* Utility: parse a tracepoint number and look it up in the list.
15090 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15091 If OPTIONAL_P is true, then if the argument is missing, the most
15092 recent tracepoint (tracepoint_count) is returned. */
15093 struct tracepoint *
15094 get_tracepoint_by_number (char **arg,
15095 struct get_number_or_range_state *state,
15098 extern int tracepoint_count;
15099 struct breakpoint *t;
15101 char *instring = arg == NULL ? NULL : *arg;
15105 gdb_assert (!state->finished);
15106 tpnum = get_number_or_range (state);
15108 else if (arg == NULL || *arg == NULL || ! **arg)
15111 tpnum = tracepoint_count;
15113 error_no_arg (_("tracepoint number"));
15116 tpnum = get_number (arg);
15120 if (instring && *instring)
15121 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15124 printf_filtered (_("Tracepoint argument missing "
15125 "and no previous tracepoint\n"));
15129 ALL_TRACEPOINTS (t)
15130 if (t->number == tpnum)
15132 return (struct tracepoint *) t;
15135 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
15140 print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
15142 if (b->thread != -1)
15143 fprintf_unfiltered (fp, " thread %d", b->thread);
15146 fprintf_unfiltered (fp, " task %d", b->task);
15148 fprintf_unfiltered (fp, "\n");
15151 /* Save information on user settable breakpoints (watchpoints, etc) to
15152 a new script file named FILENAME. If FILTER is non-NULL, call it
15153 on each breakpoint and only include the ones for which it returns
15157 save_breakpoints (char *filename, int from_tty,
15158 int (*filter) (const struct breakpoint *))
15160 struct breakpoint *tp;
15163 struct cleanup *cleanup;
15164 struct ui_file *fp;
15165 int extra_trace_bits = 0;
15167 if (filename == 0 || *filename == 0)
15168 error (_("Argument required (file name in which to save)"));
15170 /* See if we have anything to save. */
15171 ALL_BREAKPOINTS (tp)
15173 /* Skip internal and momentary breakpoints. */
15174 if (!user_breakpoint_p (tp))
15177 /* If we have a filter, only save the breakpoints it accepts. */
15178 if (filter && !filter (tp))
15183 if (is_tracepoint (tp))
15185 extra_trace_bits = 1;
15187 /* We can stop searching. */
15194 warning (_("Nothing to save."));
15198 pathname = tilde_expand (filename);
15199 cleanup = make_cleanup (xfree, pathname);
15200 fp = gdb_fopen (pathname, "w");
15202 error (_("Unable to open file '%s' for saving (%s)"),
15203 filename, safe_strerror (errno));
15204 make_cleanup_ui_file_delete (fp);
15206 if (extra_trace_bits)
15207 save_trace_state_variables (fp);
15209 ALL_BREAKPOINTS (tp)
15211 /* Skip internal and momentary breakpoints. */
15212 if (!user_breakpoint_p (tp))
15215 /* If we have a filter, only save the breakpoints it accepts. */
15216 if (filter && !filter (tp))
15219 tp->ops->print_recreate (tp, fp);
15221 /* Note, we can't rely on tp->number for anything, as we can't
15222 assume the recreated breakpoint numbers will match. Use $bpnum
15225 if (tp->cond_string)
15226 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
15228 if (tp->ignore_count)
15229 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
15233 volatile struct gdb_exception ex;
15235 fprintf_unfiltered (fp, " commands\n");
15237 ui_out_redirect (current_uiout, fp);
15238 TRY_CATCH (ex, RETURN_MASK_ALL)
15240 print_command_lines (current_uiout, tp->commands->commands, 2);
15242 ui_out_redirect (current_uiout, NULL);
15245 throw_exception (ex);
15247 fprintf_unfiltered (fp, " end\n");
15250 if (tp->enable_state == bp_disabled)
15251 fprintf_unfiltered (fp, "disable\n");
15253 /* If this is a multi-location breakpoint, check if the locations
15254 should be individually disabled. Watchpoint locations are
15255 special, and not user visible. */
15256 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15258 struct bp_location *loc;
15261 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15263 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
15267 if (extra_trace_bits && *default_collect)
15268 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
15270 do_cleanups (cleanup);
15272 printf_filtered (_("Saved to file '%s'.\n"), filename);
15275 /* The `save breakpoints' command. */
15278 save_breakpoints_command (char *args, int from_tty)
15280 save_breakpoints (args, from_tty, NULL);
15283 /* The `save tracepoints' command. */
15286 save_tracepoints_command (char *args, int from_tty)
15288 save_breakpoints (args, from_tty, is_tracepoint);
15291 /* Create a vector of all tracepoints. */
15293 VEC(breakpoint_p) *
15294 all_tracepoints (void)
15296 VEC(breakpoint_p) *tp_vec = 0;
15297 struct breakpoint *tp;
15299 ALL_TRACEPOINTS (tp)
15301 VEC_safe_push (breakpoint_p, tp_vec, tp);
15308 /* This help string is used for the break, hbreak, tbreak and thbreak
15309 commands. It is defined as a macro to prevent duplication.
15310 COMMAND should be a string constant containing the name of the
15312 #define BREAK_ARGS_HELP(command) \
15313 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15314 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15315 If a line number is specified, break at start of code for that line.\n\
15316 If a function is specified, break at start of code for that function.\n\
15317 If an address is specified, break at that exact address.\n\
15318 With no LOCATION, uses current execution address of the selected\n\
15319 stack frame. This is useful for breaking on return to a stack frame.\n\
15321 THREADNUM is the number from \"info threads\".\n\
15322 CONDITION is a boolean expression.\n\
15324 Multiple breakpoints at one place are permitted, and useful if their\n\
15325 conditions are different.\n\
15327 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15329 /* List of subcommands for "catch". */
15330 static struct cmd_list_element *catch_cmdlist;
15332 /* List of subcommands for "tcatch". */
15333 static struct cmd_list_element *tcatch_cmdlist;
15336 add_catch_command (char *name, char *docstring,
15337 void (*sfunc) (char *args, int from_tty,
15338 struct cmd_list_element *command),
15339 completer_ftype *completer,
15340 void *user_data_catch,
15341 void *user_data_tcatch)
15343 struct cmd_list_element *command;
15345 command = add_cmd (name, class_breakpoint, NULL, docstring,
15347 set_cmd_sfunc (command, sfunc);
15348 set_cmd_context (command, user_data_catch);
15349 set_cmd_completer (command, completer);
15351 command = add_cmd (name, class_breakpoint, NULL, docstring,
15353 set_cmd_sfunc (command, sfunc);
15354 set_cmd_context (command, user_data_tcatch);
15355 set_cmd_completer (command, completer);
15359 clear_syscall_counts (struct inferior *inf)
15361 struct catch_syscall_inferior_data *inf_data
15362 = get_catch_syscall_inferior_data (inf);
15364 inf_data->total_syscalls_count = 0;
15365 inf_data->any_syscall_count = 0;
15366 VEC_free (int, inf_data->syscalls_counts);
15370 save_command (char *arg, int from_tty)
15372 printf_unfiltered (_("\"save\" must be followed by "
15373 "the name of a save subcommand.\n"));
15374 help_list (save_cmdlist, "save ", -1, gdb_stdout);
15377 struct breakpoint *
15378 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15381 struct breakpoint *b, *b_tmp;
15383 ALL_BREAKPOINTS_SAFE (b, b_tmp)
15385 if ((*callback) (b, data))
15392 /* Zero if any of the breakpoint's locations could be a location where
15393 functions have been inlined, nonzero otherwise. */
15396 is_non_inline_function (struct breakpoint *b)
15398 /* The shared library event breakpoint is set on the address of a
15399 non-inline function. */
15400 if (b->type == bp_shlib_event)
15406 /* Nonzero if the specified PC cannot be a location where functions
15407 have been inlined. */
15410 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
15411 const struct target_waitstatus *ws)
15413 struct breakpoint *b;
15414 struct bp_location *bl;
15416 ALL_BREAKPOINTS (b)
15418 if (!is_non_inline_function (b))
15421 for (bl = b->loc; bl != NULL; bl = bl->next)
15423 if (!bl->shlib_disabled
15424 && bpstat_check_location (bl, aspace, pc, ws))
15433 initialize_breakpoint_ops (void)
15435 static int initialized = 0;
15437 struct breakpoint_ops *ops;
15443 /* The breakpoint_ops structure to be inherit by all kinds of
15444 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15445 internal and momentary breakpoints, etc.). */
15446 ops = &bkpt_base_breakpoint_ops;
15447 *ops = base_breakpoint_ops;
15448 ops->re_set = bkpt_re_set;
15449 ops->insert_location = bkpt_insert_location;
15450 ops->remove_location = bkpt_remove_location;
15451 ops->breakpoint_hit = bkpt_breakpoint_hit;
15452 ops->create_sals_from_address = bkpt_create_sals_from_address;
15453 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
15454 ops->decode_linespec = bkpt_decode_linespec;
15456 /* The breakpoint_ops structure to be used in regular breakpoints. */
15457 ops = &bkpt_breakpoint_ops;
15458 *ops = bkpt_base_breakpoint_ops;
15459 ops->re_set = bkpt_re_set;
15460 ops->resources_needed = bkpt_resources_needed;
15461 ops->print_it = bkpt_print_it;
15462 ops->print_mention = bkpt_print_mention;
15463 ops->print_recreate = bkpt_print_recreate;
15465 /* Ranged breakpoints. */
15466 ops = &ranged_breakpoint_ops;
15467 *ops = bkpt_breakpoint_ops;
15468 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
15469 ops->resources_needed = resources_needed_ranged_breakpoint;
15470 ops->print_it = print_it_ranged_breakpoint;
15471 ops->print_one = print_one_ranged_breakpoint;
15472 ops->print_one_detail = print_one_detail_ranged_breakpoint;
15473 ops->print_mention = print_mention_ranged_breakpoint;
15474 ops->print_recreate = print_recreate_ranged_breakpoint;
15476 /* Internal breakpoints. */
15477 ops = &internal_breakpoint_ops;
15478 *ops = bkpt_base_breakpoint_ops;
15479 ops->re_set = internal_bkpt_re_set;
15480 ops->check_status = internal_bkpt_check_status;
15481 ops->print_it = internal_bkpt_print_it;
15482 ops->print_mention = internal_bkpt_print_mention;
15484 /* Momentary breakpoints. */
15485 ops = &momentary_breakpoint_ops;
15486 *ops = bkpt_base_breakpoint_ops;
15487 ops->re_set = momentary_bkpt_re_set;
15488 ops->check_status = momentary_bkpt_check_status;
15489 ops->print_it = momentary_bkpt_print_it;
15490 ops->print_mention = momentary_bkpt_print_mention;
15492 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15493 ops = &longjmp_breakpoint_ops;
15494 *ops = momentary_breakpoint_ops;
15495 ops->dtor = longjmp_bkpt_dtor;
15497 /* Probe breakpoints. */
15498 ops = &bkpt_probe_breakpoint_ops;
15499 *ops = bkpt_breakpoint_ops;
15500 ops->insert_location = bkpt_probe_insert_location;
15501 ops->remove_location = bkpt_probe_remove_location;
15502 ops->create_sals_from_address = bkpt_probe_create_sals_from_address;
15503 ops->decode_linespec = bkpt_probe_decode_linespec;
15505 /* GNU v3 exception catchpoints. */
15506 ops = &gnu_v3_exception_catchpoint_ops;
15507 *ops = bkpt_breakpoint_ops;
15508 ops->print_it = print_it_exception_catchpoint;
15509 ops->print_one = print_one_exception_catchpoint;
15510 ops->print_mention = print_mention_exception_catchpoint;
15511 ops->print_recreate = print_recreate_exception_catchpoint;
15514 ops = &watchpoint_breakpoint_ops;
15515 *ops = base_breakpoint_ops;
15516 ops->dtor = dtor_watchpoint;
15517 ops->re_set = re_set_watchpoint;
15518 ops->insert_location = insert_watchpoint;
15519 ops->remove_location = remove_watchpoint;
15520 ops->breakpoint_hit = breakpoint_hit_watchpoint;
15521 ops->check_status = check_status_watchpoint;
15522 ops->resources_needed = resources_needed_watchpoint;
15523 ops->works_in_software_mode = works_in_software_mode_watchpoint;
15524 ops->print_it = print_it_watchpoint;
15525 ops->print_mention = print_mention_watchpoint;
15526 ops->print_recreate = print_recreate_watchpoint;
15528 /* Masked watchpoints. */
15529 ops = &masked_watchpoint_breakpoint_ops;
15530 *ops = watchpoint_breakpoint_ops;
15531 ops->insert_location = insert_masked_watchpoint;
15532 ops->remove_location = remove_masked_watchpoint;
15533 ops->resources_needed = resources_needed_masked_watchpoint;
15534 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
15535 ops->print_it = print_it_masked_watchpoint;
15536 ops->print_one_detail = print_one_detail_masked_watchpoint;
15537 ops->print_mention = print_mention_masked_watchpoint;
15538 ops->print_recreate = print_recreate_masked_watchpoint;
15541 ops = &tracepoint_breakpoint_ops;
15542 *ops = base_breakpoint_ops;
15543 ops->re_set = tracepoint_re_set;
15544 ops->breakpoint_hit = tracepoint_breakpoint_hit;
15545 ops->print_one_detail = tracepoint_print_one_detail;
15546 ops->print_mention = tracepoint_print_mention;
15547 ops->print_recreate = tracepoint_print_recreate;
15548 ops->create_sals_from_address = tracepoint_create_sals_from_address;
15549 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
15550 ops->decode_linespec = tracepoint_decode_linespec;
15552 /* Probe tracepoints. */
15553 ops = &tracepoint_probe_breakpoint_ops;
15554 *ops = tracepoint_breakpoint_ops;
15555 ops->create_sals_from_address = tracepoint_probe_create_sals_from_address;
15556 ops->decode_linespec = tracepoint_probe_decode_linespec;
15558 /* Static tracepoints with marker (`-m'). */
15559 ops = &strace_marker_breakpoint_ops;
15560 *ops = tracepoint_breakpoint_ops;
15561 ops->create_sals_from_address = strace_marker_create_sals_from_address;
15562 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
15563 ops->decode_linespec = strace_marker_decode_linespec;
15565 /* Fork catchpoints. */
15566 ops = &catch_fork_breakpoint_ops;
15567 *ops = base_breakpoint_ops;
15568 ops->insert_location = insert_catch_fork;
15569 ops->remove_location = remove_catch_fork;
15570 ops->breakpoint_hit = breakpoint_hit_catch_fork;
15571 ops->print_it = print_it_catch_fork;
15572 ops->print_one = print_one_catch_fork;
15573 ops->print_mention = print_mention_catch_fork;
15574 ops->print_recreate = print_recreate_catch_fork;
15576 /* Vfork catchpoints. */
15577 ops = &catch_vfork_breakpoint_ops;
15578 *ops = base_breakpoint_ops;
15579 ops->insert_location = insert_catch_vfork;
15580 ops->remove_location = remove_catch_vfork;
15581 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
15582 ops->print_it = print_it_catch_vfork;
15583 ops->print_one = print_one_catch_vfork;
15584 ops->print_mention = print_mention_catch_vfork;
15585 ops->print_recreate = print_recreate_catch_vfork;
15587 /* Exec catchpoints. */
15588 ops = &catch_exec_breakpoint_ops;
15589 *ops = base_breakpoint_ops;
15590 ops->dtor = dtor_catch_exec;
15591 ops->insert_location = insert_catch_exec;
15592 ops->remove_location = remove_catch_exec;
15593 ops->breakpoint_hit = breakpoint_hit_catch_exec;
15594 ops->print_it = print_it_catch_exec;
15595 ops->print_one = print_one_catch_exec;
15596 ops->print_mention = print_mention_catch_exec;
15597 ops->print_recreate = print_recreate_catch_exec;
15599 /* Syscall catchpoints. */
15600 ops = &catch_syscall_breakpoint_ops;
15601 *ops = base_breakpoint_ops;
15602 ops->dtor = dtor_catch_syscall;
15603 ops->insert_location = insert_catch_syscall;
15604 ops->remove_location = remove_catch_syscall;
15605 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
15606 ops->print_it = print_it_catch_syscall;
15607 ops->print_one = print_one_catch_syscall;
15608 ops->print_mention = print_mention_catch_syscall;
15609 ops->print_recreate = print_recreate_catch_syscall;
15611 /* Solib-related catchpoints. */
15612 ops = &catch_solib_breakpoint_ops;
15613 *ops = base_breakpoint_ops;
15614 ops->dtor = dtor_catch_solib;
15615 ops->insert_location = insert_catch_solib;
15616 ops->remove_location = remove_catch_solib;
15617 ops->breakpoint_hit = breakpoint_hit_catch_solib;
15618 ops->check_status = check_status_catch_solib;
15619 ops->print_it = print_it_catch_solib;
15620 ops->print_one = print_one_catch_solib;
15621 ops->print_mention = print_mention_catch_solib;
15622 ops->print_recreate = print_recreate_catch_solib;
15624 ops = &dprintf_breakpoint_ops;
15625 *ops = bkpt_base_breakpoint_ops;
15626 ops->re_set = bkpt_re_set;
15627 ops->resources_needed = bkpt_resources_needed;
15628 ops->print_it = bkpt_print_it;
15629 ops->print_mention = bkpt_print_mention;
15630 ops->print_recreate = bkpt_print_recreate;
15634 _initialize_breakpoint (void)
15636 struct cmd_list_element *c;
15638 initialize_breakpoint_ops ();
15640 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
15641 observer_attach_inferior_exit (clear_syscall_counts);
15642 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
15644 breakpoint_objfile_key
15645 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
15647 catch_syscall_inferior_data
15648 = register_inferior_data_with_cleanup (catch_syscall_inferior_data_cleanup);
15650 breakpoint_chain = 0;
15651 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15652 before a breakpoint is set. */
15653 breakpoint_count = 0;
15655 tracepoint_count = 0;
15657 add_com ("ignore", class_breakpoint, ignore_command, _("\
15658 Set ignore-count of breakpoint number N to COUNT.\n\
15659 Usage is `ignore N COUNT'."));
15661 add_com_alias ("bc", "ignore", class_breakpoint, 1);
15663 add_com ("commands", class_breakpoint, commands_command, _("\
15664 Set commands to be executed when a breakpoint is hit.\n\
15665 Give breakpoint number as argument after \"commands\".\n\
15666 With no argument, the targeted breakpoint is the last one set.\n\
15667 The commands themselves follow starting on the next line.\n\
15668 Type a line containing \"end\" to indicate the end of them.\n\
15669 Give \"silent\" as the first line to make the breakpoint silent;\n\
15670 then no output is printed when it is hit, except what the commands print."));
15672 c = add_com ("condition", class_breakpoint, condition_command, _("\
15673 Specify breakpoint number N to break only if COND is true.\n\
15674 Usage is `condition N COND', where N is an integer and COND is an\n\
15675 expression to be evaluated whenever breakpoint N is reached."));
15676 set_cmd_completer (c, condition_completer);
15678 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
15679 Set a temporary breakpoint.\n\
15680 Like \"break\" except the breakpoint is only temporary,\n\
15681 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15682 by using \"enable delete\" on the breakpoint number.\n\
15684 BREAK_ARGS_HELP ("tbreak")));
15685 set_cmd_completer (c, location_completer);
15687 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
15688 Set a hardware assisted breakpoint.\n\
15689 Like \"break\" except the breakpoint requires hardware support,\n\
15690 some target hardware may not have this support.\n\
15692 BREAK_ARGS_HELP ("hbreak")));
15693 set_cmd_completer (c, location_completer);
15695 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
15696 Set a temporary hardware assisted breakpoint.\n\
15697 Like \"hbreak\" except the breakpoint is only temporary,\n\
15698 so it will be deleted when hit.\n\
15700 BREAK_ARGS_HELP ("thbreak")));
15701 set_cmd_completer (c, location_completer);
15703 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
15704 Enable some breakpoints.\n\
15705 Give breakpoint numbers (separated by spaces) as arguments.\n\
15706 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15707 This is used to cancel the effect of the \"disable\" command.\n\
15708 With a subcommand you can enable temporarily."),
15709 &enablelist, "enable ", 1, &cmdlist);
15711 add_com ("ab", class_breakpoint, enable_command, _("\
15712 Enable some breakpoints.\n\
15713 Give breakpoint numbers (separated by spaces) as arguments.\n\
15714 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15715 This is used to cancel the effect of the \"disable\" command.\n\
15716 With a subcommand you can enable temporarily."));
15718 add_com_alias ("en", "enable", class_breakpoint, 1);
15720 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
15721 Enable some breakpoints.\n\
15722 Give breakpoint numbers (separated by spaces) as arguments.\n\
15723 This is used to cancel the effect of the \"disable\" command.\n\
15724 May be abbreviated to simply \"enable\".\n"),
15725 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
15727 add_cmd ("once", no_class, enable_once_command, _("\
15728 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15729 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15732 add_cmd ("delete", no_class, enable_delete_command, _("\
15733 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15734 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15737 add_cmd ("count", no_class, enable_count_command, _("\
15738 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15739 If a breakpoint is hit while enabled in this fashion,\n\
15740 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15743 add_cmd ("delete", no_class, enable_delete_command, _("\
15744 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15745 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15748 add_cmd ("once", no_class, enable_once_command, _("\
15749 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15750 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15753 add_cmd ("count", no_class, enable_count_command, _("\
15754 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15755 If a breakpoint is hit while enabled in this fashion,\n\
15756 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15759 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
15760 Disable some breakpoints.\n\
15761 Arguments are breakpoint numbers with spaces in between.\n\
15762 To disable all breakpoints, give no argument.\n\
15763 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15764 &disablelist, "disable ", 1, &cmdlist);
15765 add_com_alias ("dis", "disable", class_breakpoint, 1);
15766 add_com_alias ("disa", "disable", class_breakpoint, 1);
15768 add_com ("sb", class_breakpoint, disable_command, _("\
15769 Disable some breakpoints.\n\
15770 Arguments are breakpoint numbers with spaces in between.\n\
15771 To disable all breakpoints, give no argument.\n\
15772 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
15774 add_cmd ("breakpoints", class_alias, disable_command, _("\
15775 Disable some breakpoints.\n\
15776 Arguments are breakpoint numbers with spaces in between.\n\
15777 To disable all breakpoints, give no argument.\n\
15778 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15779 This command may be abbreviated \"disable\"."),
15782 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
15783 Delete some breakpoints or auto-display expressions.\n\
15784 Arguments are breakpoint numbers with spaces in between.\n\
15785 To delete all breakpoints, give no argument.\n\
15787 Also a prefix command for deletion of other GDB objects.\n\
15788 The \"unset\" command is also an alias for \"delete\"."),
15789 &deletelist, "delete ", 1, &cmdlist);
15790 add_com_alias ("d", "delete", class_breakpoint, 1);
15791 add_com_alias ("del", "delete", class_breakpoint, 1);
15793 add_com ("db", class_breakpoint, delete_command, _("\
15794 Delete some breakpoints.\n\
15795 Arguments are breakpoint numbers with spaces in between.\n\
15796 To delete all breakpoints, give no argument.\n"));
15798 add_cmd ("breakpoints", class_alias, delete_command, _("\
15799 Delete some breakpoints or auto-display expressions.\n\
15800 Arguments are breakpoint numbers with spaces in between.\n\
15801 To delete all breakpoints, give no argument.\n\
15802 This command may be abbreviated \"delete\"."),
15805 add_com ("clear", class_breakpoint, clear_command, _("\
15806 Clear breakpoint at specified line or function.\n\
15807 Argument may be line number, function name, or \"*\" and an address.\n\
15808 If line number is specified, all breakpoints in that line are cleared.\n\
15809 If function is specified, breakpoints at beginning of function are cleared.\n\
15810 If an address is specified, breakpoints at that address are cleared.\n\
15812 With no argument, clears all breakpoints in the line that the selected frame\n\
15813 is executing in.\n\
15815 See also the \"delete\" command which clears breakpoints by number."));
15816 add_com_alias ("cl", "clear", class_breakpoint, 1);
15818 c = add_com ("break", class_breakpoint, break_command, _("\
15819 Set breakpoint at specified line or function.\n"
15820 BREAK_ARGS_HELP ("break")));
15821 set_cmd_completer (c, location_completer);
15823 add_com_alias ("b", "break", class_run, 1);
15824 add_com_alias ("br", "break", class_run, 1);
15825 add_com_alias ("bre", "break", class_run, 1);
15826 add_com_alias ("brea", "break", class_run, 1);
15829 add_com_alias ("ba", "break", class_breakpoint, 1);
15833 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
15834 Break in function/address or break at a line in the current file."),
15835 &stoplist, "stop ", 1, &cmdlist);
15836 add_cmd ("in", class_breakpoint, stopin_command,
15837 _("Break in function or address."), &stoplist);
15838 add_cmd ("at", class_breakpoint, stopat_command,
15839 _("Break at a line in the current file."), &stoplist);
15840 add_com ("status", class_info, breakpoints_info, _("\
15841 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15842 The \"Type\" column indicates one of:\n\
15843 \tbreakpoint - normal breakpoint\n\
15844 \twatchpoint - watchpoint\n\
15845 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15846 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15847 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15848 address and file/line number respectively.\n\
15850 Convenience variable \"$_\" and default examine address for \"x\"\n\
15851 are set to the address of the last breakpoint listed unless the command\n\
15852 is prefixed with \"server \".\n\n\
15853 Convenience variable \"$bpnum\" contains the number of the last\n\
15854 breakpoint set."));
15857 add_info ("breakpoints", breakpoints_info, _("\
15858 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15859 The \"Type\" column indicates one of:\n\
15860 \tbreakpoint - normal breakpoint\n\
15861 \twatchpoint - watchpoint\n\
15862 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15863 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15864 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15865 address and file/line number respectively.\n\
15867 Convenience variable \"$_\" and default examine address for \"x\"\n\
15868 are set to the address of the last breakpoint listed unless the command\n\
15869 is prefixed with \"server \".\n\n\
15870 Convenience variable \"$bpnum\" contains the number of the last\n\
15871 breakpoint set."));
15873 add_info_alias ("b", "breakpoints", 1);
15876 add_com ("lb", class_breakpoint, breakpoints_info, _("\
15877 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15878 The \"Type\" column indicates one of:\n\
15879 \tbreakpoint - normal breakpoint\n\
15880 \twatchpoint - watchpoint\n\
15881 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15882 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15883 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15884 address and file/line number respectively.\n\
15886 Convenience variable \"$_\" and default examine address for \"x\"\n\
15887 are set to the address of the last breakpoint listed unless the command\n\
15888 is prefixed with \"server \".\n\n\
15889 Convenience variable \"$bpnum\" contains the number of the last\n\
15890 breakpoint set."));
15892 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
15893 Status of all breakpoints, or breakpoint number NUMBER.\n\
15894 The \"Type\" column indicates one of:\n\
15895 \tbreakpoint - normal breakpoint\n\
15896 \twatchpoint - watchpoint\n\
15897 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15898 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15899 \tuntil - internal breakpoint used by the \"until\" command\n\
15900 \tfinish - internal breakpoint used by the \"finish\" command\n\
15901 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15902 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15903 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15904 address and file/line number respectively.\n\
15906 Convenience variable \"$_\" and default examine address for \"x\"\n\
15907 are set to the address of the last breakpoint listed unless the command\n\
15908 is prefixed with \"server \".\n\n\
15909 Convenience variable \"$bpnum\" contains the number of the last\n\
15911 &maintenanceinfolist);
15913 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
15914 Set catchpoints to catch events."),
15915 &catch_cmdlist, "catch ",
15916 0/*allow-unknown*/, &cmdlist);
15918 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
15919 Set temporary catchpoints to catch events."),
15920 &tcatch_cmdlist, "tcatch ",
15921 0/*allow-unknown*/, &cmdlist);
15923 /* Add catch and tcatch sub-commands. */
15924 add_catch_command ("catch", _("\
15925 Catch an exception, when caught."),
15926 catch_catch_command,
15930 add_catch_command ("throw", _("\
15931 Catch an exception, when thrown."),
15932 catch_throw_command,
15936 add_catch_command ("fork", _("Catch calls to fork."),
15937 catch_fork_command_1,
15939 (void *) (uintptr_t) catch_fork_permanent,
15940 (void *) (uintptr_t) catch_fork_temporary);
15941 add_catch_command ("vfork", _("Catch calls to vfork."),
15942 catch_fork_command_1,
15944 (void *) (uintptr_t) catch_vfork_permanent,
15945 (void *) (uintptr_t) catch_vfork_temporary);
15946 add_catch_command ("exec", _("Catch calls to exec."),
15947 catch_exec_command_1,
15951 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15952 Usage: catch load [REGEX]\n\
15953 If REGEX is given, only stop for libraries matching the regular expression."),
15954 catch_load_command_1,
15958 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15959 Usage: catch unload [REGEX]\n\
15960 If REGEX is given, only stop for libraries matching the regular expression."),
15961 catch_unload_command_1,
15965 add_catch_command ("syscall", _("\
15966 Catch system calls by their names and/or numbers.\n\
15967 Arguments say which system calls to catch. If no arguments\n\
15968 are given, every system call will be caught.\n\
15969 Arguments, if given, should be one or more system call names\n\
15970 (if your system supports that), or system call numbers."),
15971 catch_syscall_command_1,
15972 catch_syscall_completer,
15976 c = add_com ("watch", class_breakpoint, watch_command, _("\
15977 Set a watchpoint for an expression.\n\
15978 Usage: watch [-l|-location] EXPRESSION\n\
15979 A watchpoint stops execution of your program whenever the value of\n\
15980 an expression changes.\n\
15981 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15982 the memory to which it refers."));
15983 set_cmd_completer (c, expression_completer);
15985 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
15986 Set a read watchpoint for an expression.\n\
15987 Usage: rwatch [-l|-location] EXPRESSION\n\
15988 A watchpoint stops execution of your program whenever the value of\n\
15989 an expression is read.\n\
15990 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15991 the memory to which it refers."));
15992 set_cmd_completer (c, expression_completer);
15994 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
15995 Set a watchpoint for an expression.\n\
15996 Usage: awatch [-l|-location] EXPRESSION\n\
15997 A watchpoint stops execution of your program whenever the value of\n\
15998 an expression is either read or written.\n\
15999 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16000 the memory to which it refers."));
16001 set_cmd_completer (c, expression_completer);
16003 add_info ("watchpoints", watchpoints_info, _("\
16004 Status of specified watchpoints (all watchpoints if no argument)."));
16006 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16007 respond to changes - contrary to the description. */
16008 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
16009 &can_use_hw_watchpoints, _("\
16010 Set debugger's willingness to use watchpoint hardware."), _("\
16011 Show debugger's willingness to use watchpoint hardware."), _("\
16012 If zero, gdb will not use hardware for new watchpoints, even if\n\
16013 such is available. (However, any hardware watchpoints that were\n\
16014 created before setting this to nonzero, will continue to use watchpoint\n\
16017 show_can_use_hw_watchpoints,
16018 &setlist, &showlist);
16020 can_use_hw_watchpoints = 1;
16022 /* Tracepoint manipulation commands. */
16024 c = add_com ("trace", class_breakpoint, trace_command, _("\
16025 Set a tracepoint at specified line or function.\n\
16027 BREAK_ARGS_HELP ("trace") "\n\
16028 Do \"help tracepoints\" for info on other tracepoint commands."));
16029 set_cmd_completer (c, location_completer);
16031 add_com_alias ("tp", "trace", class_alias, 0);
16032 add_com_alias ("tr", "trace", class_alias, 1);
16033 add_com_alias ("tra", "trace", class_alias, 1);
16034 add_com_alias ("trac", "trace", class_alias, 1);
16036 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
16037 Set a fast tracepoint at specified line or function.\n\
16039 BREAK_ARGS_HELP ("ftrace") "\n\
16040 Do \"help tracepoints\" for info on other tracepoint commands."));
16041 set_cmd_completer (c, location_completer);
16043 c = add_com ("strace", class_breakpoint, strace_command, _("\
16044 Set a static tracepoint at specified line, function or marker.\n\
16046 strace [LOCATION] [if CONDITION]\n\
16047 LOCATION may be a line number, function name, \"*\" and an address,\n\
16048 or -m MARKER_ID.\n\
16049 If a line number is specified, probe the marker at start of code\n\
16050 for that line. If a function is specified, probe the marker at start\n\
16051 of code for that function. If an address is specified, probe the marker\n\
16052 at that exact address. If a marker id is specified, probe the marker\n\
16053 with that name. With no LOCATION, uses current execution address of\n\
16054 the selected stack frame.\n\
16055 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16056 This collects arbitrary user data passed in the probe point call to the\n\
16057 tracing library. You can inspect it when analyzing the trace buffer,\n\
16058 by printing the $_sdata variable like any other convenience variable.\n\
16060 CONDITION is a boolean expression.\n\
16062 Multiple tracepoints at one place are permitted, and useful if their\n\
16063 conditions are different.\n\
16065 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16066 Do \"help tracepoints\" for info on other tracepoint commands."));
16067 set_cmd_completer (c, location_completer);
16069 add_info ("tracepoints", tracepoints_info, _("\
16070 Status of specified tracepoints (all tracepoints if no argument).\n\
16071 Convenience variable \"$tpnum\" contains the number of the\n\
16072 last tracepoint set."));
16074 add_info_alias ("tp", "tracepoints", 1);
16076 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
16077 Delete specified tracepoints.\n\
16078 Arguments are tracepoint numbers, separated by spaces.\n\
16079 No argument means delete all tracepoints."),
16082 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
16083 Disable specified tracepoints.\n\
16084 Arguments are tracepoint numbers, separated by spaces.\n\
16085 No argument means disable all tracepoints."),
16087 deprecate_cmd (c, "disable");
16089 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
16090 Enable specified tracepoints.\n\
16091 Arguments are tracepoint numbers, separated by spaces.\n\
16092 No argument means enable all tracepoints."),
16094 deprecate_cmd (c, "enable");
16096 add_com ("passcount", class_trace, trace_pass_command, _("\
16097 Set the passcount for a tracepoint.\n\
16098 The trace will end when the tracepoint has been passed 'count' times.\n\
16099 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16100 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16102 add_prefix_cmd ("save", class_breakpoint, save_command,
16103 _("Save breakpoint definitions as a script."),
16104 &save_cmdlist, "save ",
16105 0/*allow-unknown*/, &cmdlist);
16107 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
16108 Save current breakpoint definitions as a script.\n\
16109 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16110 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16111 session to restore them."),
16113 set_cmd_completer (c, filename_completer);
16115 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
16116 Save current tracepoint definitions as a script.\n\
16117 Use the 'source' command in another debug session to restore them."),
16119 set_cmd_completer (c, filename_completer);
16121 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
16122 deprecate_cmd (c, "save tracepoints");
16124 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
16125 Breakpoint specific settings\n\
16126 Configure various breakpoint-specific variables such as\n\
16127 pending breakpoint behavior"),
16128 &breakpoint_set_cmdlist, "set breakpoint ",
16129 0/*allow-unknown*/, &setlist);
16130 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
16131 Breakpoint specific settings\n\
16132 Configure various breakpoint-specific variables such as\n\
16133 pending breakpoint behavior"),
16134 &breakpoint_show_cmdlist, "show breakpoint ",
16135 0/*allow-unknown*/, &showlist);
16137 add_setshow_auto_boolean_cmd ("pending", no_class,
16138 &pending_break_support, _("\
16139 Set debugger's behavior regarding pending breakpoints."), _("\
16140 Show debugger's behavior regarding pending breakpoints."), _("\
16141 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16142 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16143 an error. If auto, an unrecognized breakpoint location results in a\n\
16144 user-query to see if a pending breakpoint should be created."),
16146 show_pending_break_support,
16147 &breakpoint_set_cmdlist,
16148 &breakpoint_show_cmdlist);
16150 pending_break_support = AUTO_BOOLEAN_AUTO;
16152 add_setshow_boolean_cmd ("auto-hw", no_class,
16153 &automatic_hardware_breakpoints, _("\
16154 Set automatic usage of hardware breakpoints."), _("\
16155 Show automatic usage of hardware breakpoints."), _("\
16156 If set, the debugger will automatically use hardware breakpoints for\n\
16157 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16158 a warning will be emitted for such breakpoints."),
16160 show_automatic_hardware_breakpoints,
16161 &breakpoint_set_cmdlist,
16162 &breakpoint_show_cmdlist);
16164 add_setshow_enum_cmd ("always-inserted", class_support,
16165 always_inserted_enums, &always_inserted_mode, _("\
16166 Set mode for inserting breakpoints."), _("\
16167 Show mode for inserting breakpoints."), _("\
16168 When this mode is off, breakpoints are inserted in inferior when it is\n\
16169 resumed, and removed when execution stops. When this mode is on,\n\
16170 breakpoints are inserted immediately and removed only when the user\n\
16171 deletes the breakpoint. When this mode is auto (which is the default),\n\
16172 the behaviour depends on the non-stop setting (see help set non-stop).\n\
16173 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
16174 behaves as if always-inserted mode is on; if gdb is controlling the\n\
16175 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
16177 &show_always_inserted_mode,
16178 &breakpoint_set_cmdlist,
16179 &breakpoint_show_cmdlist);
16181 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16182 condition_evaluation_enums,
16183 &condition_evaluation_mode_1, _("\
16184 Set mode of breakpoint condition evaluation."), _("\
16185 Show mode of breakpoint condition evaluation."), _("\
16186 When this is set to \"host\", breakpoint conditions will be\n\
16187 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16188 breakpoint conditions will be downloaded to the target (if the target\n\
16189 supports such feature) and conditions will be evaluated on the target's side.\n\
16190 If this is set to \"auto\" (default), this will be automatically set to\n\
16191 \"target\" if it supports condition evaluation, otherwise it will\n\
16192 be set to \"gdb\""),
16193 &set_condition_evaluation_mode,
16194 &show_condition_evaluation_mode,
16195 &breakpoint_set_cmdlist,
16196 &breakpoint_show_cmdlist);
16198 add_com ("break-range", class_breakpoint, break_range_command, _("\
16199 Set a breakpoint for an address range.\n\
16200 break-range START-LOCATION, END-LOCATION\n\
16201 where START-LOCATION and END-LOCATION can be one of the following:\n\
16202 LINENUM, for that line in the current file,\n\
16203 FILE:LINENUM, for that line in that file,\n\
16204 +OFFSET, for that number of lines after the current line\n\
16205 or the start of the range\n\
16206 FUNCTION, for the first line in that function,\n\
16207 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16208 *ADDRESS, for the instruction at that address.\n\
16210 The breakpoint will stop execution of the inferior whenever it executes\n\
16211 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16212 range (including START-LOCATION and END-LOCATION)."));
16214 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16215 Set a dynamic printf at specified line or function.\n\
16216 dprintf location,format string,arg1,arg2,...\n\
16217 location may be a line number, function name, or \"*\" and an address.\n\
16218 If a line number is specified, break at start of code for that line.\n\
16219 If a function is specified, break at start of code for that function.\n\
16221 set_cmd_completer (c, location_completer);
16223 add_setshow_enum_cmd ("dprintf-style", class_support,
16224 dprintf_style_enums, &dprintf_style, _("\
16225 Set the style of usage for dynamic printf."), _("\
16226 Show the style of usage for dynamic printf."), _("\
16227 This setting chooses how GDB will do a dynamic printf.\n\
16228 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16229 console, as with the \"printf\" command.\n\
16230 If the value is \"call\", the print is done by calling a function in your\n\
16231 program; by default printf(), but you can choose a different function or\n\
16232 output stream by setting dprintf-function and dprintf-channel."),
16233 update_dprintf_commands, NULL,
16234 &setlist, &showlist);
16236 dprintf_function = xstrdup ("printf");
16237 add_setshow_string_cmd ("dprintf-function", class_support,
16238 &dprintf_function, _("\
16239 Set the function to use for dynamic printf"), _("\
16240 Show the function to use for dynamic printf"), NULL,
16241 update_dprintf_commands, NULL,
16242 &setlist, &showlist);
16244 dprintf_channel = xstrdup ("");
16245 add_setshow_string_cmd ("dprintf-channel", class_support,
16246 &dprintf_channel, _("\
16247 Set the channel to use for dynamic printf"), _("\
16248 Show the channel to use for dynamic printf"), NULL,
16249 update_dprintf_commands, NULL,
16250 &setlist, &showlist);
16252 automatic_hardware_breakpoints = 1;
16254 observer_attach_about_to_proceed (breakpoint_about_to_proceed);