1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2015 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
59 #include "parser-defs.h"
60 #include "gdb_regex.h"
62 #include "cli/cli-utils.h"
63 #include "continuations.h"
67 #include "dummy-frame.h"
72 /* readline include files */
73 #include "readline/readline.h"
74 #include "readline/history.h"
76 /* readline defines this. */
79 #include "mi/mi-common.h"
80 #include "extension.h"
82 /* Enums for exception-handling support. */
83 enum exception_event_kind
90 /* Prototypes for local functions. */
92 static void enable_delete_command (char *, int);
94 static void enable_once_command (char *, int);
96 static void enable_count_command (char *, int);
98 static void disable_command (char *, int);
100 static void enable_command (char *, int);
102 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
106 static void ignore_command (char *, int);
108 static int breakpoint_re_set_one (void *);
110 static void breakpoint_re_set_default (struct breakpoint
*);
113 create_sals_from_location_default (const struct event_location
*location
,
114 struct linespec_result
*canonical
,
115 enum bptype type_wanted
);
117 static void create_breakpoints_sal_default (struct gdbarch
*,
118 struct linespec_result
*,
119 char *, char *, enum bptype
,
120 enum bpdisp
, int, int,
122 const struct breakpoint_ops
*,
123 int, int, int, unsigned);
125 static void decode_location_default (struct breakpoint
*b
,
126 const struct event_location
*location
,
127 struct symtabs_and_lines
*sals
);
129 static void clear_command (char *, int);
131 static void catch_command (char *, int);
133 static int can_use_hardware_watchpoint (struct value
*);
135 static void break_command_1 (char *, int, int);
137 static void mention (struct breakpoint
*);
139 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
141 const struct breakpoint_ops
*);
142 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
143 const struct symtab_and_line
*);
145 /* This function is used in gdbtk sources and thus can not be made
147 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
148 struct symtab_and_line
,
150 const struct breakpoint_ops
*);
152 static struct breakpoint
*
153 momentary_breakpoint_from_master (struct breakpoint
*orig
,
155 const struct breakpoint_ops
*ops
,
158 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
160 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
164 static void describe_other_breakpoints (struct gdbarch
*,
165 struct program_space
*, CORE_ADDR
,
166 struct obj_section
*, int);
168 static int watchpoint_locations_match (struct bp_location
*loc1
,
169 struct bp_location
*loc2
);
171 static int breakpoint_location_address_match (struct bp_location
*bl
,
172 struct address_space
*aspace
,
175 static void breakpoints_info (char *, int);
177 static void watchpoints_info (char *, int);
179 static int breakpoint_1 (char *, int,
180 int (*) (const struct breakpoint
*));
182 static int breakpoint_cond_eval (void *);
184 static void cleanup_executing_breakpoints (void *);
186 static void commands_command (char *, int);
188 static void condition_command (char *, int);
197 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
198 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
200 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
202 static int watchpoint_check (void *);
204 static void maintenance_info_breakpoints (char *, int);
206 static int hw_breakpoint_used_count (void);
208 static int hw_watchpoint_use_count (struct breakpoint
*);
210 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
212 int *other_type_used
);
214 static void hbreak_command (char *, int);
216 static void thbreak_command (char *, int);
218 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
221 static void stop_command (char *arg
, int from_tty
);
223 static void stopin_command (char *arg
, int from_tty
);
225 static void stopat_command (char *arg
, int from_tty
);
227 static void tcatch_command (char *arg
, int from_tty
);
229 static void free_bp_location (struct bp_location
*loc
);
230 static void incref_bp_location (struct bp_location
*loc
);
231 static void decref_bp_location (struct bp_location
**loc
);
233 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
235 /* update_global_location_list's modes of operation wrt to whether to
236 insert locations now. */
237 enum ugll_insert_mode
239 /* Don't insert any breakpoint locations into the inferior, only
240 remove already-inserted locations that no longer should be
241 inserted. Functions that delete a breakpoint or breakpoints
242 should specify this mode, so that deleting a breakpoint doesn't
243 have the side effect of inserting the locations of other
244 breakpoints that are marked not-inserted, but should_be_inserted
245 returns true on them.
247 This behavior is useful is situations close to tear-down -- e.g.,
248 after an exec, while the target still has execution, but
249 breakpoint shadows of the previous executable image should *NOT*
250 be restored to the new image; or before detaching, where the
251 target still has execution and wants to delete breakpoints from
252 GDB's lists, and all breakpoints had already been removed from
256 /* May insert breakpoints iff breakpoints_should_be_inserted_now
257 claims breakpoints should be inserted now. */
260 /* Insert locations now, irrespective of
261 breakpoints_should_be_inserted_now. E.g., say all threads are
262 stopped right now, and the user did "continue". We need to
263 insert breakpoints _before_ resuming the target, but
264 UGLL_MAY_INSERT wouldn't insert them, because
265 breakpoints_should_be_inserted_now returns false at that point,
266 as no thread is running yet. */
270 static void update_global_location_list (enum ugll_insert_mode
);
272 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
274 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
276 static void insert_breakpoint_locations (void);
278 static void tracepoints_info (char *, int);
280 static void delete_trace_command (char *, int);
282 static void enable_trace_command (char *, int);
284 static void disable_trace_command (char *, int);
286 static void trace_pass_command (char *, int);
288 static void set_tracepoint_count (int num
);
290 static int is_masked_watchpoint (const struct breakpoint
*b
);
292 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
294 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
297 static int strace_marker_p (struct breakpoint
*b
);
299 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
300 that are implemented on top of software or hardware breakpoints
301 (user breakpoints, internal and momentary breakpoints, etc.). */
302 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
304 /* Internal breakpoints class type. */
305 static struct breakpoint_ops internal_breakpoint_ops
;
307 /* Momentary breakpoints class type. */
308 static struct breakpoint_ops momentary_breakpoint_ops
;
310 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
311 static struct breakpoint_ops longjmp_breakpoint_ops
;
313 /* The breakpoint_ops structure to be used in regular user created
315 struct breakpoint_ops bkpt_breakpoint_ops
;
317 /* Breakpoints set on probes. */
318 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
320 /* Dynamic printf class type. */
321 struct breakpoint_ops dprintf_breakpoint_ops
;
323 /* The style in which to perform a dynamic printf. This is a user
324 option because different output options have different tradeoffs;
325 if GDB does the printing, there is better error handling if there
326 is a problem with any of the arguments, but using an inferior
327 function lets you have special-purpose printers and sending of
328 output to the same place as compiled-in print functions. */
330 static const char dprintf_style_gdb
[] = "gdb";
331 static const char dprintf_style_call
[] = "call";
332 static const char dprintf_style_agent
[] = "agent";
333 static const char *const dprintf_style_enums
[] = {
339 static const char *dprintf_style
= dprintf_style_gdb
;
341 /* The function to use for dynamic printf if the preferred style is to
342 call into the inferior. The value is simply a string that is
343 copied into the command, so it can be anything that GDB can
344 evaluate to a callable address, not necessarily a function name. */
346 static char *dprintf_function
= "";
348 /* The channel to use for dynamic printf if the preferred style is to
349 call into the inferior; if a nonempty string, it will be passed to
350 the call as the first argument, with the format string as the
351 second. As with the dprintf function, this can be anything that
352 GDB knows how to evaluate, so in addition to common choices like
353 "stderr", this could be an app-specific expression like
354 "mystreams[curlogger]". */
356 static char *dprintf_channel
= "";
358 /* True if dprintf commands should continue to operate even if GDB
360 static int disconnected_dprintf
= 1;
362 /* A reference-counted struct command_line. This lets multiple
363 breakpoints share a single command list. */
364 struct counted_command_line
366 /* The reference count. */
369 /* The command list. */
370 struct command_line
*commands
;
373 struct command_line
*
374 breakpoint_commands (struct breakpoint
*b
)
376 return b
->commands
? b
->commands
->commands
: NULL
;
379 /* Flag indicating that a command has proceeded the inferior past the
380 current breakpoint. */
382 static int breakpoint_proceeded
;
385 bpdisp_text (enum bpdisp disp
)
387 /* NOTE: the following values are a part of MI protocol and
388 represent values of 'disp' field returned when inferior stops at
390 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
392 return bpdisps
[(int) disp
];
395 /* Prototypes for exported functions. */
396 /* If FALSE, gdb will not use hardware support for watchpoints, even
397 if such is available. */
398 static int can_use_hw_watchpoints
;
401 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
402 struct cmd_list_element
*c
,
405 fprintf_filtered (file
,
406 _("Debugger's willingness to use "
407 "watchpoint hardware is %s.\n"),
411 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
412 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
413 for unrecognized breakpoint locations.
414 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
415 static enum auto_boolean pending_break_support
;
417 show_pending_break_support (struct ui_file
*file
, int from_tty
,
418 struct cmd_list_element
*c
,
421 fprintf_filtered (file
,
422 _("Debugger's behavior regarding "
423 "pending breakpoints is %s.\n"),
427 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
428 set with "break" but falling in read-only memory.
429 If 0, gdb will warn about such breakpoints, but won't automatically
430 use hardware breakpoints. */
431 static int automatic_hardware_breakpoints
;
433 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
434 struct cmd_list_element
*c
,
437 fprintf_filtered (file
,
438 _("Automatic usage of hardware breakpoints is %s.\n"),
442 /* If on, GDB keeps breakpoints inserted even if the inferior is
443 stopped, and immediately inserts any new breakpoints as soon as
444 they're created. If off (default), GDB keeps breakpoints off of
445 the target as long as possible. That is, it delays inserting
446 breakpoints until the next resume, and removes them again when the
447 target fully stops. This is a bit safer in case GDB crashes while
448 processing user input. */
449 static int always_inserted_mode
= 0;
452 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
453 struct cmd_list_element
*c
, const char *value
)
455 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
459 /* See breakpoint.h. */
462 breakpoints_should_be_inserted_now (void)
464 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
466 /* If breakpoints are global, they should be inserted even if no
467 thread under gdb's control is running, or even if there are
468 no threads under GDB's control yet. */
471 else if (target_has_execution
)
473 struct thread_info
*tp
;
475 if (always_inserted_mode
)
477 /* The user wants breakpoints inserted even if all threads
482 if (threads_are_executing ())
485 /* Don't remove breakpoints yet if, even though all threads are
486 stopped, we still have events to process. */
487 ALL_NON_EXITED_THREADS (tp
)
489 && tp
->suspend
.waitstatus_pending_p
)
495 static const char condition_evaluation_both
[] = "host or target";
497 /* Modes for breakpoint condition evaluation. */
498 static const char condition_evaluation_auto
[] = "auto";
499 static const char condition_evaluation_host
[] = "host";
500 static const char condition_evaluation_target
[] = "target";
501 static const char *const condition_evaluation_enums
[] = {
502 condition_evaluation_auto
,
503 condition_evaluation_host
,
504 condition_evaluation_target
,
508 /* Global that holds the current mode for breakpoint condition evaluation. */
509 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
511 /* Global that we use to display information to the user (gets its value from
512 condition_evaluation_mode_1. */
513 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
515 /* Translate a condition evaluation mode MODE into either "host"
516 or "target". This is used mostly to translate from "auto" to the
517 real setting that is being used. It returns the translated
521 translate_condition_evaluation_mode (const char *mode
)
523 if (mode
== condition_evaluation_auto
)
525 if (target_supports_evaluation_of_breakpoint_conditions ())
526 return condition_evaluation_target
;
528 return condition_evaluation_host
;
534 /* Discovers what condition_evaluation_auto translates to. */
537 breakpoint_condition_evaluation_mode (void)
539 return translate_condition_evaluation_mode (condition_evaluation_mode
);
542 /* Return true if GDB should evaluate breakpoint conditions or false
546 gdb_evaluates_breakpoint_condition_p (void)
548 const char *mode
= breakpoint_condition_evaluation_mode ();
550 return (mode
== condition_evaluation_host
);
553 void _initialize_breakpoint (void);
555 /* Are we executing breakpoint commands? */
556 static int executing_breakpoint_commands
;
558 /* Are overlay event breakpoints enabled? */
559 static int overlay_events_enabled
;
561 /* See description in breakpoint.h. */
562 int target_exact_watchpoints
= 0;
564 /* Walk the following statement or block through all breakpoints.
565 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
566 current breakpoint. */
568 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
570 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
571 for (B = breakpoint_chain; \
572 B ? (TMP=B->next, 1): 0; \
575 /* Similar iterator for the low-level breakpoints. SAFE variant is
576 not provided so update_global_location_list must not be called
577 while executing the block of ALL_BP_LOCATIONS. */
579 #define ALL_BP_LOCATIONS(B,BP_TMP) \
580 for (BP_TMP = bp_location; \
581 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
584 /* Iterates through locations with address ADDRESS for the currently selected
585 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
586 to where the loop should start from.
587 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
588 appropriate location to start with. */
590 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
591 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
592 BP_LOCP_TMP = BP_LOCP_START; \
594 && (BP_LOCP_TMP < bp_location + bp_location_count \
595 && (*BP_LOCP_TMP)->address == ADDRESS); \
598 /* Iterator for tracepoints only. */
600 #define ALL_TRACEPOINTS(B) \
601 for (B = breakpoint_chain; B; B = B->next) \
602 if (is_tracepoint (B))
604 /* Chains of all breakpoints defined. */
606 struct breakpoint
*breakpoint_chain
;
608 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
610 static struct bp_location
**bp_location
;
612 /* Number of elements of BP_LOCATION. */
614 static unsigned bp_location_count
;
616 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
617 ADDRESS for the current elements of BP_LOCATION which get a valid
618 result from bp_location_has_shadow. You can use it for roughly
619 limiting the subrange of BP_LOCATION to scan for shadow bytes for
620 an address you need to read. */
622 static CORE_ADDR bp_location_placed_address_before_address_max
;
624 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
625 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
626 BP_LOCATION which get a valid result from bp_location_has_shadow.
627 You can use it for roughly limiting the subrange of BP_LOCATION to
628 scan for shadow bytes for an address you need to read. */
630 static CORE_ADDR bp_location_shadow_len_after_address_max
;
632 /* The locations that no longer correspond to any breakpoint, unlinked
633 from bp_location array, but for which a hit may still be reported
635 VEC(bp_location_p
) *moribund_locations
= NULL
;
637 /* Number of last breakpoint made. */
639 static int breakpoint_count
;
641 /* The value of `breakpoint_count' before the last command that
642 created breakpoints. If the last (break-like) command created more
643 than one breakpoint, then the difference between BREAKPOINT_COUNT
644 and PREV_BREAKPOINT_COUNT is more than one. */
645 static int prev_breakpoint_count
;
647 /* Number of last tracepoint made. */
649 static int tracepoint_count
;
651 static struct cmd_list_element
*breakpoint_set_cmdlist
;
652 static struct cmd_list_element
*breakpoint_show_cmdlist
;
653 struct cmd_list_element
*save_cmdlist
;
655 /* See declaration at breakpoint.h. */
658 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
661 struct breakpoint
*b
= NULL
;
665 if (func (b
, user_data
) != 0)
672 /* Return whether a breakpoint is an active enabled breakpoint. */
674 breakpoint_enabled (struct breakpoint
*b
)
676 return (b
->enable_state
== bp_enabled
);
679 /* Set breakpoint count to NUM. */
682 set_breakpoint_count (int num
)
684 prev_breakpoint_count
= breakpoint_count
;
685 breakpoint_count
= num
;
686 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
689 /* Used by `start_rbreak_breakpoints' below, to record the current
690 breakpoint count before "rbreak" creates any breakpoint. */
691 static int rbreak_start_breakpoint_count
;
693 /* Called at the start an "rbreak" command to record the first
697 start_rbreak_breakpoints (void)
699 rbreak_start_breakpoint_count
= breakpoint_count
;
702 /* Called at the end of an "rbreak" command to record the last
706 end_rbreak_breakpoints (void)
708 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
711 /* Used in run_command to zero the hit count when a new run starts. */
714 clear_breakpoint_hit_counts (void)
716 struct breakpoint
*b
;
722 /* Allocate a new counted_command_line with reference count of 1.
723 The new structure owns COMMANDS. */
725 static struct counted_command_line
*
726 alloc_counted_command_line (struct command_line
*commands
)
728 struct counted_command_line
*result
= XNEW (struct counted_command_line
);
731 result
->commands
= commands
;
736 /* Increment reference count. This does nothing if CMD is NULL. */
739 incref_counted_command_line (struct counted_command_line
*cmd
)
745 /* Decrement reference count. If the reference count reaches 0,
746 destroy the counted_command_line. Sets *CMDP to NULL. This does
747 nothing if *CMDP is NULL. */
750 decref_counted_command_line (struct counted_command_line
**cmdp
)
754 if (--(*cmdp
)->refc
== 0)
756 free_command_lines (&(*cmdp
)->commands
);
763 /* A cleanup function that calls decref_counted_command_line. */
766 do_cleanup_counted_command_line (void *arg
)
768 decref_counted_command_line (arg
);
771 /* Create a cleanup that calls decref_counted_command_line on the
774 static struct cleanup
*
775 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
777 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
781 /* Return the breakpoint with the specified number, or NULL
782 if the number does not refer to an existing breakpoint. */
785 get_breakpoint (int num
)
787 struct breakpoint
*b
;
790 if (b
->number
== num
)
798 /* Mark locations as "conditions have changed" in case the target supports
799 evaluating conditions on its side. */
802 mark_breakpoint_modified (struct breakpoint
*b
)
804 struct bp_location
*loc
;
806 /* This is only meaningful if the target is
807 evaluating conditions and if the user has
808 opted for condition evaluation on the target's
810 if (gdb_evaluates_breakpoint_condition_p ()
811 || !target_supports_evaluation_of_breakpoint_conditions ())
814 if (!is_breakpoint (b
))
817 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
818 loc
->condition_changed
= condition_modified
;
821 /* Mark location as "conditions have changed" in case the target supports
822 evaluating conditions on its side. */
825 mark_breakpoint_location_modified (struct bp_location
*loc
)
827 /* This is only meaningful if the target is
828 evaluating conditions and if the user has
829 opted for condition evaluation on the target's
831 if (gdb_evaluates_breakpoint_condition_p ()
832 || !target_supports_evaluation_of_breakpoint_conditions ())
836 if (!is_breakpoint (loc
->owner
))
839 loc
->condition_changed
= condition_modified
;
842 /* Sets the condition-evaluation mode using the static global
843 condition_evaluation_mode. */
846 set_condition_evaluation_mode (char *args
, int from_tty
,
847 struct cmd_list_element
*c
)
849 const char *old_mode
, *new_mode
;
851 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
852 && !target_supports_evaluation_of_breakpoint_conditions ())
854 condition_evaluation_mode_1
= condition_evaluation_mode
;
855 warning (_("Target does not support breakpoint condition evaluation.\n"
856 "Using host evaluation mode instead."));
860 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
861 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
863 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
864 settings was "auto". */
865 condition_evaluation_mode
= condition_evaluation_mode_1
;
867 /* Only update the mode if the user picked a different one. */
868 if (new_mode
!= old_mode
)
870 struct bp_location
*loc
, **loc_tmp
;
871 /* If the user switched to a different evaluation mode, we
872 need to synch the changes with the target as follows:
874 "host" -> "target": Send all (valid) conditions to the target.
875 "target" -> "host": Remove all the conditions from the target.
878 if (new_mode
== condition_evaluation_target
)
880 /* Mark everything modified and synch conditions with the
882 ALL_BP_LOCATIONS (loc
, loc_tmp
)
883 mark_breakpoint_location_modified (loc
);
887 /* Manually mark non-duplicate locations to synch conditions
888 with the target. We do this to remove all the conditions the
889 target knows about. */
890 ALL_BP_LOCATIONS (loc
, loc_tmp
)
891 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
892 loc
->needs_update
= 1;
896 update_global_location_list (UGLL_MAY_INSERT
);
902 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
903 what "auto" is translating to. */
906 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
907 struct cmd_list_element
*c
, const char *value
)
909 if (condition_evaluation_mode
== condition_evaluation_auto
)
910 fprintf_filtered (file
,
911 _("Breakpoint condition evaluation "
912 "mode is %s (currently %s).\n"),
914 breakpoint_condition_evaluation_mode ());
916 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
920 /* A comparison function for bp_location AP and BP that is used by
921 bsearch. This comparison function only cares about addresses, unlike
922 the more general bp_location_compare function. */
925 bp_location_compare_addrs (const void *ap
, const void *bp
)
927 struct bp_location
*a
= *(void **) ap
;
928 struct bp_location
*b
= *(void **) bp
;
930 if (a
->address
== b
->address
)
933 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
936 /* Helper function to skip all bp_locations with addresses
937 less than ADDRESS. It returns the first bp_location that
938 is greater than or equal to ADDRESS. If none is found, just
941 static struct bp_location
**
942 get_first_locp_gte_addr (CORE_ADDR address
)
944 struct bp_location dummy_loc
;
945 struct bp_location
*dummy_locp
= &dummy_loc
;
946 struct bp_location
**locp_found
= NULL
;
948 /* Initialize the dummy location's address field. */
949 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
950 dummy_loc
.address
= address
;
952 /* Find a close match to the first location at ADDRESS. */
953 locp_found
= bsearch (&dummy_locp
, bp_location
, bp_location_count
,
954 sizeof (struct bp_location
**),
955 bp_location_compare_addrs
);
957 /* Nothing was found, nothing left to do. */
958 if (locp_found
== NULL
)
961 /* We may have found a location that is at ADDRESS but is not the first in the
962 location's list. Go backwards (if possible) and locate the first one. */
963 while ((locp_found
- 1) >= bp_location
964 && (*(locp_found
- 1))->address
== address
)
971 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
974 xfree (b
->cond_string
);
975 b
->cond_string
= NULL
;
977 if (is_watchpoint (b
))
979 struct watchpoint
*w
= (struct watchpoint
*) b
;
986 struct bp_location
*loc
;
988 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
993 /* No need to free the condition agent expression
994 bytecode (if we have one). We will handle this
995 when we go through update_global_location_list. */
1002 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
1006 const char *arg
= exp
;
1008 /* I don't know if it matters whether this is the string the user
1009 typed in or the decompiled expression. */
1010 b
->cond_string
= xstrdup (arg
);
1011 b
->condition_not_parsed
= 0;
1013 if (is_watchpoint (b
))
1015 struct watchpoint
*w
= (struct watchpoint
*) b
;
1017 innermost_block
= NULL
;
1019 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
1021 error (_("Junk at end of expression"));
1022 w
->cond_exp_valid_block
= innermost_block
;
1026 struct bp_location
*loc
;
1028 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1032 parse_exp_1 (&arg
, loc
->address
,
1033 block_for_pc (loc
->address
), 0);
1035 error (_("Junk at end of expression"));
1039 mark_breakpoint_modified (b
);
1041 observer_notify_breakpoint_modified (b
);
1044 /* Completion for the "condition" command. */
1046 static VEC (char_ptr
) *
1047 condition_completer (struct cmd_list_element
*cmd
,
1048 const char *text
, const char *word
)
1052 text
= skip_spaces_const (text
);
1053 space
= skip_to_space_const (text
);
1057 struct breakpoint
*b
;
1058 VEC (char_ptr
) *result
= NULL
;
1062 /* We don't support completion of history indices. */
1063 if (isdigit (text
[1]))
1065 return complete_internalvar (&text
[1]);
1068 /* We're completing the breakpoint number. */
1069 len
= strlen (text
);
1075 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1077 if (strncmp (number
, text
, len
) == 0)
1078 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1084 /* We're completing the expression part. */
1085 text
= skip_spaces_const (space
);
1086 return expression_completer (cmd
, text
, word
);
1089 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1092 condition_command (char *arg
, int from_tty
)
1094 struct breakpoint
*b
;
1099 error_no_arg (_("breakpoint number"));
1102 bnum
= get_number (&p
);
1104 error (_("Bad breakpoint argument: '%s'"), arg
);
1107 if (b
->number
== bnum
)
1109 /* Check if this breakpoint has a "stop" method implemented in an
1110 extension language. This method and conditions entered into GDB
1111 from the CLI are mutually exclusive. */
1112 const struct extension_language_defn
*extlang
1113 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1115 if (extlang
!= NULL
)
1117 error (_("Only one stop condition allowed. There is currently"
1118 " a %s stop condition defined for this breakpoint."),
1119 ext_lang_capitalized_name (extlang
));
1121 set_breakpoint_condition (b
, p
, from_tty
);
1123 if (is_breakpoint (b
))
1124 update_global_location_list (UGLL_MAY_INSERT
);
1129 error (_("No breakpoint number %d."), bnum
);
1132 /* Check that COMMAND do not contain commands that are suitable
1133 only for tracepoints and not suitable for ordinary breakpoints.
1134 Throw if any such commands is found. */
1137 check_no_tracepoint_commands (struct command_line
*commands
)
1139 struct command_line
*c
;
1141 for (c
= commands
; c
; c
= c
->next
)
1145 if (c
->control_type
== while_stepping_control
)
1146 error (_("The 'while-stepping' command can "
1147 "only be used for tracepoints"));
1149 for (i
= 0; i
< c
->body_count
; ++i
)
1150 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1152 /* Not that command parsing removes leading whitespace and comment
1153 lines and also empty lines. So, we only need to check for
1154 command directly. */
1155 if (strstr (c
->line
, "collect ") == c
->line
)
1156 error (_("The 'collect' command can only be used for tracepoints"));
1158 if (strstr (c
->line
, "teval ") == c
->line
)
1159 error (_("The 'teval' command can only be used for tracepoints"));
1163 /* Encapsulate tests for different types of tracepoints. */
1166 is_tracepoint_type (enum bptype type
)
1168 return (type
== bp_tracepoint
1169 || type
== bp_fast_tracepoint
1170 || type
== bp_static_tracepoint
);
1174 is_tracepoint (const struct breakpoint
*b
)
1176 return is_tracepoint_type (b
->type
);
1179 /* A helper function that validates that COMMANDS are valid for a
1180 breakpoint. This function will throw an exception if a problem is
1184 validate_commands_for_breakpoint (struct breakpoint
*b
,
1185 struct command_line
*commands
)
1187 if (is_tracepoint (b
))
1189 struct tracepoint
*t
= (struct tracepoint
*) b
;
1190 struct command_line
*c
;
1191 struct command_line
*while_stepping
= 0;
1193 /* Reset the while-stepping step count. The previous commands
1194 might have included a while-stepping action, while the new
1198 /* We need to verify that each top-level element of commands is
1199 valid for tracepoints, that there's at most one
1200 while-stepping element, and that the while-stepping's body
1201 has valid tracing commands excluding nested while-stepping.
1202 We also need to validate the tracepoint action line in the
1203 context of the tracepoint --- validate_actionline actually
1204 has side effects, like setting the tracepoint's
1205 while-stepping STEP_COUNT, in addition to checking if the
1206 collect/teval actions parse and make sense in the
1207 tracepoint's context. */
1208 for (c
= commands
; c
; c
= c
->next
)
1210 if (c
->control_type
== while_stepping_control
)
1212 if (b
->type
== bp_fast_tracepoint
)
1213 error (_("The 'while-stepping' command "
1214 "cannot be used for fast tracepoint"));
1215 else if (b
->type
== bp_static_tracepoint
)
1216 error (_("The 'while-stepping' command "
1217 "cannot be used for static tracepoint"));
1220 error (_("The 'while-stepping' command "
1221 "can be used only once"));
1226 validate_actionline (c
->line
, b
);
1230 struct command_line
*c2
;
1232 gdb_assert (while_stepping
->body_count
== 1);
1233 c2
= while_stepping
->body_list
[0];
1234 for (; c2
; c2
= c2
->next
)
1236 if (c2
->control_type
== while_stepping_control
)
1237 error (_("The 'while-stepping' command cannot be nested"));
1243 check_no_tracepoint_commands (commands
);
1247 /* Return a vector of all the static tracepoints set at ADDR. The
1248 caller is responsible for releasing the vector. */
1251 static_tracepoints_here (CORE_ADDR addr
)
1253 struct breakpoint
*b
;
1254 VEC(breakpoint_p
) *found
= 0;
1255 struct bp_location
*loc
;
1258 if (b
->type
== bp_static_tracepoint
)
1260 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1261 if (loc
->address
== addr
)
1262 VEC_safe_push(breakpoint_p
, found
, b
);
1268 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1269 validate that only allowed commands are included. */
1272 breakpoint_set_commands (struct breakpoint
*b
,
1273 struct command_line
*commands
)
1275 validate_commands_for_breakpoint (b
, commands
);
1277 decref_counted_command_line (&b
->commands
);
1278 b
->commands
= alloc_counted_command_line (commands
);
1279 observer_notify_breakpoint_modified (b
);
1282 /* Set the internal `silent' flag on the breakpoint. Note that this
1283 is not the same as the "silent" that may appear in the breakpoint's
1287 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1289 int old_silent
= b
->silent
;
1292 if (old_silent
!= silent
)
1293 observer_notify_breakpoint_modified (b
);
1296 /* Set the thread for this breakpoint. If THREAD is -1, make the
1297 breakpoint work for any thread. */
1300 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1302 int old_thread
= b
->thread
;
1305 if (old_thread
!= thread
)
1306 observer_notify_breakpoint_modified (b
);
1309 /* Set the task for this breakpoint. If TASK is 0, make the
1310 breakpoint work for any task. */
1313 breakpoint_set_task (struct breakpoint
*b
, int task
)
1315 int old_task
= b
->task
;
1318 if (old_task
!= task
)
1319 observer_notify_breakpoint_modified (b
);
1323 check_tracepoint_command (char *line
, void *closure
)
1325 struct breakpoint
*b
= closure
;
1327 validate_actionline (line
, b
);
1330 /* A structure used to pass information through
1331 map_breakpoint_numbers. */
1333 struct commands_info
1335 /* True if the command was typed at a tty. */
1338 /* The breakpoint range spec. */
1341 /* Non-NULL if the body of the commands are being read from this
1342 already-parsed command. */
1343 struct command_line
*control
;
1345 /* The command lines read from the user, or NULL if they have not
1347 struct counted_command_line
*cmd
;
1350 /* A callback for map_breakpoint_numbers that sets the commands for
1351 commands_command. */
1354 do_map_commands_command (struct breakpoint
*b
, void *data
)
1356 struct commands_info
*info
= data
;
1358 if (info
->cmd
== NULL
)
1360 struct command_line
*l
;
1362 if (info
->control
!= NULL
)
1363 l
= copy_command_lines (info
->control
->body_list
[0]);
1366 struct cleanup
*old_chain
;
1369 str
= xstrprintf (_("Type commands for breakpoint(s) "
1370 "%s, one per line."),
1373 old_chain
= make_cleanup (xfree
, str
);
1375 l
= read_command_lines (str
,
1378 ? check_tracepoint_command
: 0),
1381 do_cleanups (old_chain
);
1384 info
->cmd
= alloc_counted_command_line (l
);
1387 /* If a breakpoint was on the list more than once, we don't need to
1389 if (b
->commands
!= info
->cmd
)
1391 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1392 incref_counted_command_line (info
->cmd
);
1393 decref_counted_command_line (&b
->commands
);
1394 b
->commands
= info
->cmd
;
1395 observer_notify_breakpoint_modified (b
);
1400 commands_command_1 (char *arg
, int from_tty
,
1401 struct command_line
*control
)
1403 struct cleanup
*cleanups
;
1404 struct commands_info info
;
1406 info
.from_tty
= from_tty
;
1407 info
.control
= control
;
1409 /* If we read command lines from the user, then `info' will hold an
1410 extra reference to the commands that we must clean up. */
1411 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1413 if (arg
== NULL
|| !*arg
)
1415 if (breakpoint_count
- prev_breakpoint_count
> 1)
1416 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1418 else if (breakpoint_count
> 0)
1419 arg
= xstrprintf ("%d", breakpoint_count
);
1422 /* So that we don't try to free the incoming non-NULL
1423 argument in the cleanup below. Mapping breakpoint
1424 numbers will fail in this case. */
1429 /* The command loop has some static state, so we need to preserve
1431 arg
= xstrdup (arg
);
1434 make_cleanup (xfree
, arg
);
1438 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1440 if (info
.cmd
== NULL
)
1441 error (_("No breakpoints specified."));
1443 do_cleanups (cleanups
);
1447 commands_command (char *arg
, int from_tty
)
1449 commands_command_1 (arg
, from_tty
, NULL
);
1452 /* Like commands_command, but instead of reading the commands from
1453 input stream, takes them from an already parsed command structure.
1455 This is used by cli-script.c to DTRT with breakpoint commands
1456 that are part of if and while bodies. */
1457 enum command_control_type
1458 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1460 commands_command_1 (arg
, 0, cmd
);
1461 return simple_control
;
1464 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1467 bp_location_has_shadow (struct bp_location
*bl
)
1469 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1473 if (bl
->target_info
.shadow_len
== 0)
1474 /* BL isn't valid, or doesn't shadow memory. */
1479 /* Update BUF, which is LEN bytes read from the target address
1480 MEMADDR, by replacing a memory breakpoint with its shadowed
1483 If READBUF is not NULL, this buffer must not overlap with the of
1484 the breakpoint location's shadow_contents buffer. Otherwise, a
1485 failed assertion internal error will be raised. */
1488 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1489 const gdb_byte
*writebuf_org
,
1490 ULONGEST memaddr
, LONGEST len
,
1491 struct bp_target_info
*target_info
,
1492 struct gdbarch
*gdbarch
)
1494 /* Now do full processing of the found relevant range of elements. */
1495 CORE_ADDR bp_addr
= 0;
1499 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1500 current_program_space
->aspace
, 0))
1502 /* The breakpoint is inserted in a different address space. */
1506 /* Addresses and length of the part of the breakpoint that
1508 bp_addr
= target_info
->placed_address
;
1509 bp_size
= target_info
->shadow_len
;
1511 if (bp_addr
+ bp_size
<= memaddr
)
1513 /* The breakpoint is entirely before the chunk of memory we are
1518 if (bp_addr
>= memaddr
+ len
)
1520 /* The breakpoint is entirely after the chunk of memory we are
1525 /* Offset within shadow_contents. */
1526 if (bp_addr
< memaddr
)
1528 /* Only copy the second part of the breakpoint. */
1529 bp_size
-= memaddr
- bp_addr
;
1530 bptoffset
= memaddr
- bp_addr
;
1534 if (bp_addr
+ bp_size
> memaddr
+ len
)
1536 /* Only copy the first part of the breakpoint. */
1537 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1540 if (readbuf
!= NULL
)
1542 /* Verify that the readbuf buffer does not overlap with the
1543 shadow_contents buffer. */
1544 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1545 || readbuf
>= (target_info
->shadow_contents
1546 + target_info
->shadow_len
));
1548 /* Update the read buffer with this inserted breakpoint's
1550 memcpy (readbuf
+ bp_addr
- memaddr
,
1551 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1555 const unsigned char *bp
;
1556 CORE_ADDR addr
= target_info
->reqstd_address
;
1559 /* Update the shadow with what we want to write to memory. */
1560 memcpy (target_info
->shadow_contents
+ bptoffset
,
1561 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1563 /* Determine appropriate breakpoint contents and size for this
1565 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1567 /* Update the final write buffer with this inserted
1568 breakpoint's INSN. */
1569 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1573 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1574 by replacing any memory breakpoints with their shadowed contents.
1576 If READBUF is not NULL, this buffer must not overlap with any of
1577 the breakpoint location's shadow_contents buffers. Otherwise,
1578 a failed assertion internal error will be raised.
1580 The range of shadowed area by each bp_location is:
1581 bl->address - bp_location_placed_address_before_address_max
1582 up to bl->address + bp_location_shadow_len_after_address_max
1583 The range we were requested to resolve shadows for is:
1584 memaddr ... memaddr + len
1585 Thus the safe cutoff boundaries for performance optimization are
1586 memaddr + len <= (bl->address
1587 - bp_location_placed_address_before_address_max)
1589 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1592 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1593 const gdb_byte
*writebuf_org
,
1594 ULONGEST memaddr
, LONGEST len
)
1596 /* Left boundary, right boundary and median element of our binary
1598 unsigned bc_l
, bc_r
, bc
;
1601 /* Find BC_L which is a leftmost element which may affect BUF
1602 content. It is safe to report lower value but a failure to
1603 report higher one. */
1606 bc_r
= bp_location_count
;
1607 while (bc_l
+ 1 < bc_r
)
1609 struct bp_location
*bl
;
1611 bc
= (bc_l
+ bc_r
) / 2;
1612 bl
= bp_location
[bc
];
1614 /* Check first BL->ADDRESS will not overflow due to the added
1615 constant. Then advance the left boundary only if we are sure
1616 the BC element can in no way affect the BUF content (MEMADDR
1617 to MEMADDR + LEN range).
1619 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1620 offset so that we cannot miss a breakpoint with its shadow
1621 range tail still reaching MEMADDR. */
1623 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1625 && (bl
->address
+ bp_location_shadow_len_after_address_max
1632 /* Due to the binary search above, we need to make sure we pick the
1633 first location that's at BC_L's address. E.g., if there are
1634 multiple locations at the same address, BC_L may end up pointing
1635 at a duplicate location, and miss the "master"/"inserted"
1636 location. Say, given locations L1, L2 and L3 at addresses A and
1639 L1@A, L2@A, L3@B, ...
1641 BC_L could end up pointing at location L2, while the "master"
1642 location could be L1. Since the `loc->inserted' flag is only set
1643 on "master" locations, we'd forget to restore the shadow of L1
1646 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1649 /* Now do full processing of the found relevant range of elements. */
1651 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1653 struct bp_location
*bl
= bp_location
[bc
];
1654 CORE_ADDR bp_addr
= 0;
1658 /* bp_location array has BL->OWNER always non-NULL. */
1659 if (bl
->owner
->type
== bp_none
)
1660 warning (_("reading through apparently deleted breakpoint #%d?"),
1663 /* Performance optimization: any further element can no longer affect BUF
1666 if (bl
->address
>= bp_location_placed_address_before_address_max
1667 && memaddr
+ len
<= (bl
->address
1668 - bp_location_placed_address_before_address_max
))
1671 if (!bp_location_has_shadow (bl
))
1674 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1675 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1681 /* Return true if BPT is either a software breakpoint or a hardware
1685 is_breakpoint (const struct breakpoint
*bpt
)
1687 return (bpt
->type
== bp_breakpoint
1688 || bpt
->type
== bp_hardware_breakpoint
1689 || bpt
->type
== bp_dprintf
);
1692 /* Return true if BPT is of any hardware watchpoint kind. */
1695 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1697 return (bpt
->type
== bp_hardware_watchpoint
1698 || bpt
->type
== bp_read_watchpoint
1699 || bpt
->type
== bp_access_watchpoint
);
1702 /* Return true if BPT is of any watchpoint kind, hardware or
1706 is_watchpoint (const struct breakpoint
*bpt
)
1708 return (is_hardware_watchpoint (bpt
)
1709 || bpt
->type
== bp_watchpoint
);
1712 /* Returns true if the current thread and its running state are safe
1713 to evaluate or update watchpoint B. Watchpoints on local
1714 expressions need to be evaluated in the context of the thread that
1715 was current when the watchpoint was created, and, that thread needs
1716 to be stopped to be able to select the correct frame context.
1717 Watchpoints on global expressions can be evaluated on any thread,
1718 and in any state. It is presently left to the target allowing
1719 memory accesses when threads are running. */
1722 watchpoint_in_thread_scope (struct watchpoint
*b
)
1724 return (b
->base
.pspace
== current_program_space
1725 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1726 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1727 && !is_executing (inferior_ptid
))));
1730 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1731 associated bp_watchpoint_scope breakpoint. */
1734 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1736 struct breakpoint
*b
= &w
->base
;
1738 if (b
->related_breakpoint
!= b
)
1740 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1741 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1742 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1743 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1744 b
->related_breakpoint
= b
;
1746 b
->disposition
= disp_del_at_next_stop
;
1749 /* Extract a bitfield value from value VAL using the bit parameters contained in
1752 static struct value
*
1753 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1755 struct value
*bit_val
;
1760 bit_val
= allocate_value (value_type (val
));
1762 unpack_value_bitfield (bit_val
,
1765 value_contents_for_printing (val
),
1772 /* Assuming that B is a watchpoint:
1773 - Reparse watchpoint expression, if REPARSE is non-zero
1774 - Evaluate expression and store the result in B->val
1775 - Evaluate the condition if there is one, and store the result
1777 - Update the list of values that must be watched in B->loc.
1779 If the watchpoint disposition is disp_del_at_next_stop, then do
1780 nothing. If this is local watchpoint that is out of scope, delete
1783 Even with `set breakpoint always-inserted on' the watchpoints are
1784 removed + inserted on each stop here. Normal breakpoints must
1785 never be removed because they might be missed by a running thread
1786 when debugging in non-stop mode. On the other hand, hardware
1787 watchpoints (is_hardware_watchpoint; processed here) are specific
1788 to each LWP since they are stored in each LWP's hardware debug
1789 registers. Therefore, such LWP must be stopped first in order to
1790 be able to modify its hardware watchpoints.
1792 Hardware watchpoints must be reset exactly once after being
1793 presented to the user. It cannot be done sooner, because it would
1794 reset the data used to present the watchpoint hit to the user. And
1795 it must not be done later because it could display the same single
1796 watchpoint hit during multiple GDB stops. Note that the latter is
1797 relevant only to the hardware watchpoint types bp_read_watchpoint
1798 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1799 not user-visible - its hit is suppressed if the memory content has
1802 The following constraints influence the location where we can reset
1803 hardware watchpoints:
1805 * target_stopped_by_watchpoint and target_stopped_data_address are
1806 called several times when GDB stops.
1809 * Multiple hardware watchpoints can be hit at the same time,
1810 causing GDB to stop. GDB only presents one hardware watchpoint
1811 hit at a time as the reason for stopping, and all the other hits
1812 are presented later, one after the other, each time the user
1813 requests the execution to be resumed. Execution is not resumed
1814 for the threads still having pending hit event stored in
1815 LWP_INFO->STATUS. While the watchpoint is already removed from
1816 the inferior on the first stop the thread hit event is kept being
1817 reported from its cached value by linux_nat_stopped_data_address
1818 until the real thread resume happens after the watchpoint gets
1819 presented and thus its LWP_INFO->STATUS gets reset.
1821 Therefore the hardware watchpoint hit can get safely reset on the
1822 watchpoint removal from inferior. */
1825 update_watchpoint (struct watchpoint
*b
, int reparse
)
1827 int within_current_scope
;
1828 struct frame_id saved_frame_id
;
1831 /* If this is a local watchpoint, we only want to check if the
1832 watchpoint frame is in scope if the current thread is the thread
1833 that was used to create the watchpoint. */
1834 if (!watchpoint_in_thread_scope (b
))
1837 if (b
->base
.disposition
== disp_del_at_next_stop
)
1842 /* Determine if the watchpoint is within scope. */
1843 if (b
->exp_valid_block
== NULL
)
1844 within_current_scope
= 1;
1847 struct frame_info
*fi
= get_current_frame ();
1848 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1849 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1851 /* If we're at a point where the stack has been destroyed
1852 (e.g. in a function epilogue), unwinding may not work
1853 properly. Do not attempt to recreate locations at this
1854 point. See similar comments in watchpoint_check. */
1855 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1858 /* Save the current frame's ID so we can restore it after
1859 evaluating the watchpoint expression on its own frame. */
1860 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1861 took a frame parameter, so that we didn't have to change the
1864 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1866 fi
= frame_find_by_id (b
->watchpoint_frame
);
1867 within_current_scope
= (fi
!= NULL
);
1868 if (within_current_scope
)
1872 /* We don't free locations. They are stored in the bp_location array
1873 and update_global_location_list will eventually delete them and
1874 remove breakpoints if needed. */
1877 if (within_current_scope
&& reparse
)
1886 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1887 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1888 /* If the meaning of expression itself changed, the old value is
1889 no longer relevant. We don't want to report a watchpoint hit
1890 to the user when the old value and the new value may actually
1891 be completely different objects. */
1892 value_free (b
->val
);
1896 /* Note that unlike with breakpoints, the watchpoint's condition
1897 expression is stored in the breakpoint object, not in the
1898 locations (re)created below. */
1899 if (b
->base
.cond_string
!= NULL
)
1901 if (b
->cond_exp
!= NULL
)
1903 xfree (b
->cond_exp
);
1907 s
= b
->base
.cond_string
;
1908 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1912 /* If we failed to parse the expression, for example because
1913 it refers to a global variable in a not-yet-loaded shared library,
1914 don't try to insert watchpoint. We don't automatically delete
1915 such watchpoint, though, since failure to parse expression
1916 is different from out-of-scope watchpoint. */
1917 if (!target_has_execution
)
1919 /* Without execution, memory can't change. No use to try and
1920 set watchpoint locations. The watchpoint will be reset when
1921 the target gains execution, through breakpoint_re_set. */
1922 if (!can_use_hw_watchpoints
)
1924 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1925 b
->base
.type
= bp_watchpoint
;
1927 error (_("Can't set read/access watchpoint when "
1928 "hardware watchpoints are disabled."));
1931 else if (within_current_scope
&& b
->exp
)
1934 struct value
*val_chain
, *v
, *result
, *next
;
1935 struct program_space
*frame_pspace
;
1937 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
, 0);
1939 /* Avoid setting b->val if it's already set. The meaning of
1940 b->val is 'the last value' user saw, and we should update
1941 it only if we reported that last value to user. As it
1942 happens, the code that reports it updates b->val directly.
1943 We don't keep track of the memory value for masked
1945 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1947 if (b
->val_bitsize
!= 0)
1949 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1957 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1959 /* Look at each value on the value chain. */
1960 for (v
= val_chain
; v
; v
= value_next (v
))
1962 /* If it's a memory location, and GDB actually needed
1963 its contents to evaluate the expression, then we
1964 must watch it. If the first value returned is
1965 still lazy, that means an error occurred reading it;
1966 watch it anyway in case it becomes readable. */
1967 if (VALUE_LVAL (v
) == lval_memory
1968 && (v
== val_chain
|| ! value_lazy (v
)))
1970 struct type
*vtype
= check_typedef (value_type (v
));
1972 /* We only watch structs and arrays if user asked
1973 for it explicitly, never if they just happen to
1974 appear in the middle of some value chain. */
1976 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1977 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1980 enum target_hw_bp_type type
;
1981 struct bp_location
*loc
, **tmp
;
1982 int bitpos
= 0, bitsize
= 0;
1984 if (value_bitsize (v
) != 0)
1986 /* Extract the bit parameters out from the bitfield
1988 bitpos
= value_bitpos (v
);
1989 bitsize
= value_bitsize (v
);
1991 else if (v
== result
&& b
->val_bitsize
!= 0)
1993 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1994 lvalue whose bit parameters are saved in the fields
1995 VAL_BITPOS and VAL_BITSIZE. */
1996 bitpos
= b
->val_bitpos
;
1997 bitsize
= b
->val_bitsize
;
2000 addr
= value_address (v
);
2003 /* Skip the bytes that don't contain the bitfield. */
2008 if (b
->base
.type
== bp_read_watchpoint
)
2010 else if (b
->base
.type
== bp_access_watchpoint
)
2013 loc
= allocate_bp_location (&b
->base
);
2014 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2017 loc
->gdbarch
= get_type_arch (value_type (v
));
2019 loc
->pspace
= frame_pspace
;
2020 loc
->address
= addr
;
2024 /* Just cover the bytes that make up the bitfield. */
2025 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2028 loc
->length
= TYPE_LENGTH (value_type (v
));
2030 loc
->watchpoint_type
= type
;
2035 /* Change the type of breakpoint between hardware assisted or
2036 an ordinary watchpoint depending on the hardware support
2037 and free hardware slots. REPARSE is set when the inferior
2042 enum bp_loc_type loc_type
;
2043 struct bp_location
*bl
;
2045 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2049 int i
, target_resources_ok
, other_type_used
;
2052 /* Use an exact watchpoint when there's only one memory region to be
2053 watched, and only one debug register is needed to watch it. */
2054 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2056 /* We need to determine how many resources are already
2057 used for all other hardware watchpoints plus this one
2058 to see if we still have enough resources to also fit
2059 this watchpoint in as well. */
2061 /* If this is a software watchpoint, we try to turn it
2062 to a hardware one -- count resources as if B was of
2063 hardware watchpoint type. */
2064 type
= b
->base
.type
;
2065 if (type
== bp_watchpoint
)
2066 type
= bp_hardware_watchpoint
;
2068 /* This watchpoint may or may not have been placed on
2069 the list yet at this point (it won't be in the list
2070 if we're trying to create it for the first time,
2071 through watch_command), so always account for it
2074 /* Count resources used by all watchpoints except B. */
2075 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
2077 /* Add in the resources needed for B. */
2078 i
+= hw_watchpoint_use_count (&b
->base
);
2081 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2082 if (target_resources_ok
<= 0)
2084 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
2086 if (target_resources_ok
== 0 && !sw_mode
)
2087 error (_("Target does not support this type of "
2088 "hardware watchpoint."));
2089 else if (target_resources_ok
< 0 && !sw_mode
)
2090 error (_("There are not enough available hardware "
2091 "resources for this watchpoint."));
2093 /* Downgrade to software watchpoint. */
2094 b
->base
.type
= bp_watchpoint
;
2098 /* If this was a software watchpoint, we've just
2099 found we have enough resources to turn it to a
2100 hardware watchpoint. Otherwise, this is a
2102 b
->base
.type
= type
;
2105 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
2107 if (!can_use_hw_watchpoints
)
2108 error (_("Can't set read/access watchpoint when "
2109 "hardware watchpoints are disabled."));
2111 error (_("Expression cannot be implemented with "
2112 "read/access watchpoint."));
2115 b
->base
.type
= bp_watchpoint
;
2117 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
2118 : bp_loc_hardware_watchpoint
);
2119 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
2120 bl
->loc_type
= loc_type
;
2123 for (v
= val_chain
; v
; v
= next
)
2125 next
= value_next (v
);
2130 /* If a software watchpoint is not watching any memory, then the
2131 above left it without any location set up. But,
2132 bpstat_stop_status requires a location to be able to report
2133 stops, so make sure there's at least a dummy one. */
2134 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
2136 struct breakpoint
*base
= &b
->base
;
2137 base
->loc
= allocate_bp_location (base
);
2138 base
->loc
->pspace
= frame_pspace
;
2139 base
->loc
->address
= -1;
2140 base
->loc
->length
= -1;
2141 base
->loc
->watchpoint_type
= -1;
2144 else if (!within_current_scope
)
2146 printf_filtered (_("\
2147 Watchpoint %d deleted because the program has left the block\n\
2148 in which its expression is valid.\n"),
2150 watchpoint_del_at_next_stop (b
);
2153 /* Restore the selected frame. */
2155 select_frame (frame_find_by_id (saved_frame_id
));
2159 /* Returns 1 iff breakpoint location should be
2160 inserted in the inferior. We don't differentiate the type of BL's owner
2161 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2162 breakpoint_ops is not defined, because in insert_bp_location,
2163 tracepoint's insert_location will not be called. */
2165 should_be_inserted (struct bp_location
*bl
)
2167 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2170 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2173 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2176 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2179 /* This is set for example, when we're attached to the parent of a
2180 vfork, and have detached from the child. The child is running
2181 free, and we expect it to do an exec or exit, at which point the
2182 OS makes the parent schedulable again (and the target reports
2183 that the vfork is done). Until the child is done with the shared
2184 memory region, do not insert breakpoints in the parent, otherwise
2185 the child could still trip on the parent's breakpoints. Since
2186 the parent is blocked anyway, it won't miss any breakpoint. */
2187 if (bl
->pspace
->breakpoints_not_allowed
)
2190 /* Don't insert a breakpoint if we're trying to step past its
2192 if ((bl
->loc_type
== bp_loc_software_breakpoint
2193 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2194 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2199 fprintf_unfiltered (gdb_stdlog
,
2200 "infrun: skipping breakpoint: "
2201 "stepping past insn at: %s\n",
2202 paddress (bl
->gdbarch
, bl
->address
));
2207 /* Don't insert watchpoints if we're trying to step past the
2208 instruction that triggered one. */
2209 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2210 && stepping_past_nonsteppable_watchpoint ())
2214 fprintf_unfiltered (gdb_stdlog
,
2215 "infrun: stepping past non-steppable watchpoint. "
2216 "skipping watchpoint at %s:%d\n",
2217 paddress (bl
->gdbarch
, bl
->address
),
2226 /* Same as should_be_inserted but does the check assuming
2227 that the location is not duplicated. */
2230 unduplicated_should_be_inserted (struct bp_location
*bl
)
2233 const int save_duplicate
= bl
->duplicate
;
2236 result
= should_be_inserted (bl
);
2237 bl
->duplicate
= save_duplicate
;
2241 /* Parses a conditional described by an expression COND into an
2242 agent expression bytecode suitable for evaluation
2243 by the bytecode interpreter. Return NULL if there was
2244 any error during parsing. */
2246 static struct agent_expr
*
2247 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2249 struct agent_expr
*aexpr
= NULL
;
2254 /* We don't want to stop processing, so catch any errors
2255 that may show up. */
2258 aexpr
= gen_eval_for_expr (scope
, cond
);
2261 CATCH (ex
, RETURN_MASK_ERROR
)
2263 /* If we got here, it means the condition could not be parsed to a valid
2264 bytecode expression and thus can't be evaluated on the target's side.
2265 It's no use iterating through the conditions. */
2270 /* We have a valid agent expression. */
2274 /* Based on location BL, create a list of breakpoint conditions to be
2275 passed on to the target. If we have duplicated locations with different
2276 conditions, we will add such conditions to the list. The idea is that the
2277 target will evaluate the list of conditions and will only notify GDB when
2278 one of them is true. */
2281 build_target_condition_list (struct bp_location
*bl
)
2283 struct bp_location
**locp
= NULL
, **loc2p
;
2284 int null_condition_or_parse_error
= 0;
2285 int modified
= bl
->needs_update
;
2286 struct bp_location
*loc
;
2288 /* Release conditions left over from a previous insert. */
2289 VEC_free (agent_expr_p
, bl
->target_info
.conditions
);
2291 /* This is only meaningful if the target is
2292 evaluating conditions and if the user has
2293 opted for condition evaluation on the target's
2295 if (gdb_evaluates_breakpoint_condition_p ()
2296 || !target_supports_evaluation_of_breakpoint_conditions ())
2299 /* Do a first pass to check for locations with no assigned
2300 conditions or conditions that fail to parse to a valid agent expression
2301 bytecode. If any of these happen, then it's no use to send conditions
2302 to the target since this location will always trigger and generate a
2303 response back to GDB. */
2304 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2307 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2311 struct agent_expr
*aexpr
;
2313 /* Re-parse the conditions since something changed. In that
2314 case we already freed the condition bytecodes (see
2315 force_breakpoint_reinsertion). We just
2316 need to parse the condition to bytecodes again. */
2317 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2318 loc
->cond_bytecode
= aexpr
;
2320 /* Check if we managed to parse the conditional expression
2321 correctly. If not, we will not send this condition
2327 /* If we have a NULL bytecode expression, it means something
2328 went wrong or we have a null condition expression. */
2329 if (!loc
->cond_bytecode
)
2331 null_condition_or_parse_error
= 1;
2337 /* If any of these happened, it means we will have to evaluate the conditions
2338 for the location's address on gdb's side. It is no use keeping bytecodes
2339 for all the other duplicate locations, thus we free all of them here.
2341 This is so we have a finer control over which locations' conditions are
2342 being evaluated by GDB or the remote stub. */
2343 if (null_condition_or_parse_error
)
2345 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2348 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2350 /* Only go as far as the first NULL bytecode is
2352 if (!loc
->cond_bytecode
)
2355 free_agent_expr (loc
->cond_bytecode
);
2356 loc
->cond_bytecode
= NULL
;
2361 /* No NULL conditions or failed bytecode generation. Build a condition list
2362 for this location's address. */
2363 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2367 && is_breakpoint (loc
->owner
)
2368 && loc
->pspace
->num
== bl
->pspace
->num
2369 && loc
->owner
->enable_state
== bp_enabled
2371 /* Add the condition to the vector. This will be used later to send the
2372 conditions to the target. */
2373 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2374 loc
->cond_bytecode
);
2380 /* Parses a command described by string CMD into an agent expression
2381 bytecode suitable for evaluation by the bytecode interpreter.
2382 Return NULL if there was any error during parsing. */
2384 static struct agent_expr
*
2385 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2387 struct cleanup
*old_cleanups
= 0;
2388 struct expression
*expr
, **argvec
;
2389 struct agent_expr
*aexpr
= NULL
;
2390 const char *cmdrest
;
2391 const char *format_start
, *format_end
;
2392 struct format_piece
*fpieces
;
2394 struct gdbarch
*gdbarch
= get_current_arch ();
2401 if (*cmdrest
== ',')
2403 cmdrest
= skip_spaces_const (cmdrest
);
2405 if (*cmdrest
++ != '"')
2406 error (_("No format string following the location"));
2408 format_start
= cmdrest
;
2410 fpieces
= parse_format_string (&cmdrest
);
2412 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2414 format_end
= cmdrest
;
2416 if (*cmdrest
++ != '"')
2417 error (_("Bad format string, non-terminated '\"'."));
2419 cmdrest
= skip_spaces_const (cmdrest
);
2421 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2422 error (_("Invalid argument syntax"));
2424 if (*cmdrest
== ',')
2426 cmdrest
= skip_spaces_const (cmdrest
);
2428 /* For each argument, make an expression. */
2430 argvec
= (struct expression
**) alloca (strlen (cmd
)
2431 * sizeof (struct expression
*));
2434 while (*cmdrest
!= '\0')
2439 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2440 argvec
[nargs
++] = expr
;
2442 if (*cmdrest
== ',')
2446 /* We don't want to stop processing, so catch any errors
2447 that may show up. */
2450 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2451 format_start
, format_end
- format_start
,
2452 fpieces
, nargs
, argvec
);
2454 CATCH (ex
, RETURN_MASK_ERROR
)
2456 /* If we got here, it means the command could not be parsed to a valid
2457 bytecode expression and thus can't be evaluated on the target's side.
2458 It's no use iterating through the other commands. */
2463 do_cleanups (old_cleanups
);
2465 /* We have a valid agent expression, return it. */
2469 /* Based on location BL, create a list of breakpoint commands to be
2470 passed on to the target. If we have duplicated locations with
2471 different commands, we will add any such to the list. */
2474 build_target_command_list (struct bp_location
*bl
)
2476 struct bp_location
**locp
= NULL
, **loc2p
;
2477 int null_command_or_parse_error
= 0;
2478 int modified
= bl
->needs_update
;
2479 struct bp_location
*loc
;
2481 /* Release commands left over from a previous insert. */
2482 VEC_free (agent_expr_p
, bl
->target_info
.tcommands
);
2484 if (!target_can_run_breakpoint_commands ())
2487 /* For now, limit to agent-style dprintf breakpoints. */
2488 if (dprintf_style
!= dprintf_style_agent
)
2491 /* For now, if we have any duplicate location that isn't a dprintf,
2492 don't install the target-side commands, as that would make the
2493 breakpoint not be reported to the core, and we'd lose
2495 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2498 if (is_breakpoint (loc
->owner
)
2499 && loc
->pspace
->num
== bl
->pspace
->num
2500 && loc
->owner
->type
!= bp_dprintf
)
2504 /* Do a first pass to check for locations with no assigned
2505 conditions or conditions that fail to parse to a valid agent expression
2506 bytecode. If any of these happen, then it's no use to send conditions
2507 to the target since this location will always trigger and generate a
2508 response back to GDB. */
2509 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2512 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2516 struct agent_expr
*aexpr
;
2518 /* Re-parse the commands since something changed. In that
2519 case we already freed the command bytecodes (see
2520 force_breakpoint_reinsertion). We just
2521 need to parse the command to bytecodes again. */
2522 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2523 loc
->owner
->extra_string
);
2524 loc
->cmd_bytecode
= aexpr
;
2530 /* If we have a NULL bytecode expression, it means something
2531 went wrong or we have a null command expression. */
2532 if (!loc
->cmd_bytecode
)
2534 null_command_or_parse_error
= 1;
2540 /* If anything failed, then we're not doing target-side commands,
2542 if (null_command_or_parse_error
)
2544 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2547 if (is_breakpoint (loc
->owner
)
2548 && loc
->pspace
->num
== bl
->pspace
->num
)
2550 /* Only go as far as the first NULL bytecode is
2552 if (loc
->cmd_bytecode
== NULL
)
2555 free_agent_expr (loc
->cmd_bytecode
);
2556 loc
->cmd_bytecode
= NULL
;
2561 /* No NULL commands or failed bytecode generation. Build a command list
2562 for this location's address. */
2563 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2566 if (loc
->owner
->extra_string
2567 && is_breakpoint (loc
->owner
)
2568 && loc
->pspace
->num
== bl
->pspace
->num
2569 && loc
->owner
->enable_state
== bp_enabled
2571 /* Add the command to the vector. This will be used later
2572 to send the commands to the target. */
2573 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2577 bl
->target_info
.persist
= 0;
2578 /* Maybe flag this location as persistent. */
2579 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2580 bl
->target_info
.persist
= 1;
2583 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2584 location. Any error messages are printed to TMP_ERROR_STREAM; and
2585 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2586 Returns 0 for success, 1 if the bp_location type is not supported or
2589 NOTE drow/2003-09-09: This routine could be broken down to an
2590 object-style method for each breakpoint or catchpoint type. */
2592 insert_bp_location (struct bp_location
*bl
,
2593 struct ui_file
*tmp_error_stream
,
2594 int *disabled_breaks
,
2595 int *hw_breakpoint_error
,
2596 int *hw_bp_error_explained_already
)
2598 enum errors bp_err
= GDB_NO_ERROR
;
2599 const char *bp_err_message
= NULL
;
2601 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2604 /* Note we don't initialize bl->target_info, as that wipes out
2605 the breakpoint location's shadow_contents if the breakpoint
2606 is still inserted at that location. This in turn breaks
2607 target_read_memory which depends on these buffers when
2608 a memory read is requested at the breakpoint location:
2609 Once the target_info has been wiped, we fail to see that
2610 we have a breakpoint inserted at that address and thus
2611 read the breakpoint instead of returning the data saved in
2612 the breakpoint location's shadow contents. */
2613 bl
->target_info
.reqstd_address
= bl
->address
;
2614 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2615 bl
->target_info
.length
= bl
->length
;
2617 /* When working with target-side conditions, we must pass all the conditions
2618 for the same breakpoint address down to the target since GDB will not
2619 insert those locations. With a list of breakpoint conditions, the target
2620 can decide when to stop and notify GDB. */
2622 if (is_breakpoint (bl
->owner
))
2624 build_target_condition_list (bl
);
2625 build_target_command_list (bl
);
2626 /* Reset the modification marker. */
2627 bl
->needs_update
= 0;
2630 if (bl
->loc_type
== bp_loc_software_breakpoint
2631 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2633 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2635 /* If the explicitly specified breakpoint type
2636 is not hardware breakpoint, check the memory map to see
2637 if the breakpoint address is in read only memory or not.
2639 Two important cases are:
2640 - location type is not hardware breakpoint, memory
2641 is readonly. We change the type of the location to
2642 hardware breakpoint.
2643 - location type is hardware breakpoint, memory is
2644 read-write. This means we've previously made the
2645 location hardware one, but then the memory map changed,
2648 When breakpoints are removed, remove_breakpoints will use
2649 location types we've just set here, the only possible
2650 problem is that memory map has changed during running
2651 program, but it's not going to work anyway with current
2653 struct mem_region
*mr
2654 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2658 if (automatic_hardware_breakpoints
)
2660 enum bp_loc_type new_type
;
2662 if (mr
->attrib
.mode
!= MEM_RW
)
2663 new_type
= bp_loc_hardware_breakpoint
;
2665 new_type
= bp_loc_software_breakpoint
;
2667 if (new_type
!= bl
->loc_type
)
2669 static int said
= 0;
2671 bl
->loc_type
= new_type
;
2674 fprintf_filtered (gdb_stdout
,
2675 _("Note: automatically using "
2676 "hardware breakpoints for "
2677 "read-only addresses.\n"));
2682 else if (bl
->loc_type
== bp_loc_software_breakpoint
2683 && mr
->attrib
.mode
!= MEM_RW
)
2685 fprintf_unfiltered (tmp_error_stream
,
2686 _("Cannot insert breakpoint %d.\n"
2687 "Cannot set software breakpoint "
2688 "at read-only address %s\n"),
2690 paddress (bl
->gdbarch
, bl
->address
));
2696 /* First check to see if we have to handle an overlay. */
2697 if (overlay_debugging
== ovly_off
2698 || bl
->section
== NULL
2699 || !(section_is_overlay (bl
->section
)))
2701 /* No overlay handling: just set the breakpoint. */
2706 val
= bl
->owner
->ops
->insert_location (bl
);
2708 bp_err
= GENERIC_ERROR
;
2710 CATCH (e
, RETURN_MASK_ALL
)
2713 bp_err_message
= e
.message
;
2719 /* This breakpoint is in an overlay section.
2720 Shall we set a breakpoint at the LMA? */
2721 if (!overlay_events_enabled
)
2723 /* Yes -- overlay event support is not active,
2724 so we must try to set a breakpoint at the LMA.
2725 This will not work for a hardware breakpoint. */
2726 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2727 warning (_("hardware breakpoint %d not supported in overlay!"),
2731 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2733 /* Set a software (trap) breakpoint at the LMA. */
2734 bl
->overlay_target_info
= bl
->target_info
;
2735 bl
->overlay_target_info
.reqstd_address
= addr
;
2737 /* No overlay handling: just set the breakpoint. */
2742 val
= target_insert_breakpoint (bl
->gdbarch
,
2743 &bl
->overlay_target_info
);
2745 bp_err
= GENERIC_ERROR
;
2747 CATCH (e
, RETURN_MASK_ALL
)
2750 bp_err_message
= e
.message
;
2754 if (bp_err
!= GDB_NO_ERROR
)
2755 fprintf_unfiltered (tmp_error_stream
,
2756 "Overlay breakpoint %d "
2757 "failed: in ROM?\n",
2761 /* Shall we set a breakpoint at the VMA? */
2762 if (section_is_mapped (bl
->section
))
2764 /* Yes. This overlay section is mapped into memory. */
2769 val
= bl
->owner
->ops
->insert_location (bl
);
2771 bp_err
= GENERIC_ERROR
;
2773 CATCH (e
, RETURN_MASK_ALL
)
2776 bp_err_message
= e
.message
;
2782 /* No. This breakpoint will not be inserted.
2783 No error, but do not mark the bp as 'inserted'. */
2788 if (bp_err
!= GDB_NO_ERROR
)
2790 /* Can't set the breakpoint. */
2792 /* In some cases, we might not be able to insert a
2793 breakpoint in a shared library that has already been
2794 removed, but we have not yet processed the shlib unload
2795 event. Unfortunately, some targets that implement
2796 breakpoint insertion themselves can't tell why the
2797 breakpoint insertion failed (e.g., the remote target
2798 doesn't define error codes), so we must treat generic
2799 errors as memory errors. */
2800 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2801 && bl
->loc_type
== bp_loc_software_breakpoint
2802 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2803 || shared_objfile_contains_address_p (bl
->pspace
,
2806 /* See also: disable_breakpoints_in_shlibs. */
2807 bl
->shlib_disabled
= 1;
2808 observer_notify_breakpoint_modified (bl
->owner
);
2809 if (!*disabled_breaks
)
2811 fprintf_unfiltered (tmp_error_stream
,
2812 "Cannot insert breakpoint %d.\n",
2814 fprintf_unfiltered (tmp_error_stream
,
2815 "Temporarily disabling shared "
2816 "library breakpoints:\n");
2818 *disabled_breaks
= 1;
2819 fprintf_unfiltered (tmp_error_stream
,
2820 "breakpoint #%d\n", bl
->owner
->number
);
2825 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2827 *hw_breakpoint_error
= 1;
2828 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2829 fprintf_unfiltered (tmp_error_stream
,
2830 "Cannot insert hardware breakpoint %d%s",
2831 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2832 if (bp_err_message
!= NULL
)
2833 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2837 if (bp_err_message
== NULL
)
2840 = memory_error_message (TARGET_XFER_E_IO
,
2841 bl
->gdbarch
, bl
->address
);
2842 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2844 fprintf_unfiltered (tmp_error_stream
,
2845 "Cannot insert breakpoint %d.\n"
2847 bl
->owner
->number
, message
);
2848 do_cleanups (old_chain
);
2852 fprintf_unfiltered (tmp_error_stream
,
2853 "Cannot insert breakpoint %d: %s\n",
2868 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2869 /* NOTE drow/2003-09-08: This state only exists for removing
2870 watchpoints. It's not clear that it's necessary... */
2871 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2875 gdb_assert (bl
->owner
->ops
!= NULL
2876 && bl
->owner
->ops
->insert_location
!= NULL
);
2878 val
= bl
->owner
->ops
->insert_location (bl
);
2880 /* If trying to set a read-watchpoint, and it turns out it's not
2881 supported, try emulating one with an access watchpoint. */
2882 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2884 struct bp_location
*loc
, **loc_temp
;
2886 /* But don't try to insert it, if there's already another
2887 hw_access location that would be considered a duplicate
2889 ALL_BP_LOCATIONS (loc
, loc_temp
)
2891 && loc
->watchpoint_type
== hw_access
2892 && watchpoint_locations_match (bl
, loc
))
2896 bl
->target_info
= loc
->target_info
;
2897 bl
->watchpoint_type
= hw_access
;
2904 bl
->watchpoint_type
= hw_access
;
2905 val
= bl
->owner
->ops
->insert_location (bl
);
2908 /* Back to the original value. */
2909 bl
->watchpoint_type
= hw_read
;
2913 bl
->inserted
= (val
== 0);
2916 else if (bl
->owner
->type
== bp_catchpoint
)
2920 gdb_assert (bl
->owner
->ops
!= NULL
2921 && bl
->owner
->ops
->insert_location
!= NULL
);
2923 val
= bl
->owner
->ops
->insert_location (bl
);
2926 bl
->owner
->enable_state
= bp_disabled
;
2930 Error inserting catchpoint %d: Your system does not support this type\n\
2931 of catchpoint."), bl
->owner
->number
);
2933 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2936 bl
->inserted
= (val
== 0);
2938 /* We've already printed an error message if there was a problem
2939 inserting this catchpoint, and we've disabled the catchpoint,
2940 so just return success. */
2947 /* This function is called when program space PSPACE is about to be
2948 deleted. It takes care of updating breakpoints to not reference
2952 breakpoint_program_space_exit (struct program_space
*pspace
)
2954 struct breakpoint
*b
, *b_temp
;
2955 struct bp_location
*loc
, **loc_temp
;
2957 /* Remove any breakpoint that was set through this program space. */
2958 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2960 if (b
->pspace
== pspace
)
2961 delete_breakpoint (b
);
2964 /* Breakpoints set through other program spaces could have locations
2965 bound to PSPACE as well. Remove those. */
2966 ALL_BP_LOCATIONS (loc
, loc_temp
)
2968 struct bp_location
*tmp
;
2970 if (loc
->pspace
== pspace
)
2972 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2973 if (loc
->owner
->loc
== loc
)
2974 loc
->owner
->loc
= loc
->next
;
2976 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2977 if (tmp
->next
== loc
)
2979 tmp
->next
= loc
->next
;
2985 /* Now update the global location list to permanently delete the
2986 removed locations above. */
2987 update_global_location_list (UGLL_DONT_INSERT
);
2990 /* Make sure all breakpoints are inserted in inferior.
2991 Throws exception on any error.
2992 A breakpoint that is already inserted won't be inserted
2993 again, so calling this function twice is safe. */
2995 insert_breakpoints (void)
2997 struct breakpoint
*bpt
;
2999 ALL_BREAKPOINTS (bpt
)
3000 if (is_hardware_watchpoint (bpt
))
3002 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3004 update_watchpoint (w
, 0 /* don't reparse. */);
3007 /* Updating watchpoints creates new locations, so update the global
3008 location list. Explicitly tell ugll to insert locations and
3009 ignore breakpoints_always_inserted_mode. */
3010 update_global_location_list (UGLL_INSERT
);
3013 /* Invoke CALLBACK for each of bp_location. */
3016 iterate_over_bp_locations (walk_bp_location_callback callback
)
3018 struct bp_location
*loc
, **loc_tmp
;
3020 ALL_BP_LOCATIONS (loc
, loc_tmp
)
3022 callback (loc
, NULL
);
3026 /* This is used when we need to synch breakpoint conditions between GDB and the
3027 target. It is the case with deleting and disabling of breakpoints when using
3028 always-inserted mode. */
3031 update_inserted_breakpoint_locations (void)
3033 struct bp_location
*bl
, **blp_tmp
;
3036 int disabled_breaks
= 0;
3037 int hw_breakpoint_error
= 0;
3038 int hw_bp_details_reported
= 0;
3040 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3041 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3043 /* Explicitly mark the warning -- this will only be printed if
3044 there was an error. */
3045 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3047 save_current_space_and_thread ();
3049 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3051 /* We only want to update software breakpoints and hardware
3053 if (!is_breakpoint (bl
->owner
))
3056 /* We only want to update locations that are already inserted
3057 and need updating. This is to avoid unwanted insertion during
3058 deletion of breakpoints. */
3059 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3062 switch_to_program_space_and_thread (bl
->pspace
);
3064 /* For targets that support global breakpoints, there's no need
3065 to select an inferior to insert breakpoint to. In fact, even
3066 if we aren't attached to any process yet, we should still
3067 insert breakpoints. */
3068 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3069 && ptid_equal (inferior_ptid
, null_ptid
))
3072 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3073 &hw_breakpoint_error
, &hw_bp_details_reported
);
3080 target_terminal_ours_for_output ();
3081 error_stream (tmp_error_stream
);
3084 do_cleanups (cleanups
);
3087 /* Used when starting or continuing the program. */
3090 insert_breakpoint_locations (void)
3092 struct breakpoint
*bpt
;
3093 struct bp_location
*bl
, **blp_tmp
;
3096 int disabled_breaks
= 0;
3097 int hw_breakpoint_error
= 0;
3098 int hw_bp_error_explained_already
= 0;
3100 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3101 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3103 /* Explicitly mark the warning -- this will only be printed if
3104 there was an error. */
3105 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3107 save_current_space_and_thread ();
3109 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3111 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3114 /* There is no point inserting thread-specific breakpoints if
3115 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3116 has BL->OWNER always non-NULL. */
3117 if (bl
->owner
->thread
!= -1
3118 && !valid_thread_id (bl
->owner
->thread
))
3121 switch_to_program_space_and_thread (bl
->pspace
);
3123 /* For targets that support global breakpoints, there's no need
3124 to select an inferior to insert breakpoint to. In fact, even
3125 if we aren't attached to any process yet, we should still
3126 insert breakpoints. */
3127 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3128 && ptid_equal (inferior_ptid
, null_ptid
))
3131 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3132 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3137 /* If we failed to insert all locations of a watchpoint, remove
3138 them, as half-inserted watchpoint is of limited use. */
3139 ALL_BREAKPOINTS (bpt
)
3141 int some_failed
= 0;
3142 struct bp_location
*loc
;
3144 if (!is_hardware_watchpoint (bpt
))
3147 if (!breakpoint_enabled (bpt
))
3150 if (bpt
->disposition
== disp_del_at_next_stop
)
3153 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3154 if (!loc
->inserted
&& should_be_inserted (loc
))
3161 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3163 remove_breakpoint (loc
, mark_uninserted
);
3165 hw_breakpoint_error
= 1;
3166 fprintf_unfiltered (tmp_error_stream
,
3167 "Could not insert hardware watchpoint %d.\n",
3175 /* If a hardware breakpoint or watchpoint was inserted, add a
3176 message about possibly exhausted resources. */
3177 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3179 fprintf_unfiltered (tmp_error_stream
,
3180 "Could not insert hardware breakpoints:\n\
3181 You may have requested too many hardware breakpoints/watchpoints.\n");
3183 target_terminal_ours_for_output ();
3184 error_stream (tmp_error_stream
);
3187 do_cleanups (cleanups
);
3190 /* Used when the program stops.
3191 Returns zero if successful, or non-zero if there was a problem
3192 removing a breakpoint location. */
3195 remove_breakpoints (void)
3197 struct bp_location
*bl
, **blp_tmp
;
3200 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3202 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3203 val
|= remove_breakpoint (bl
, mark_uninserted
);
3208 /* When a thread exits, remove breakpoints that are related to
3212 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3214 struct breakpoint
*b
, *b_tmp
;
3216 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3218 if (b
->thread
== tp
->num
&& user_breakpoint_p (b
))
3220 b
->disposition
= disp_del_at_next_stop
;
3222 printf_filtered (_("\
3223 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3224 b
->number
, tp
->num
);
3226 /* Hide it from the user. */
3232 /* Remove breakpoints of process PID. */
3235 remove_breakpoints_pid (int pid
)
3237 struct bp_location
*bl
, **blp_tmp
;
3239 struct inferior
*inf
= find_inferior_pid (pid
);
3241 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3243 if (bl
->pspace
!= inf
->pspace
)
3246 if (bl
->inserted
&& !bl
->target_info
.persist
)
3248 val
= remove_breakpoint (bl
, mark_uninserted
);
3257 reattach_breakpoints (int pid
)
3259 struct cleanup
*old_chain
;
3260 struct bp_location
*bl
, **blp_tmp
;
3262 struct ui_file
*tmp_error_stream
;
3263 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3264 struct inferior
*inf
;
3265 struct thread_info
*tp
;
3267 tp
= any_live_thread_of_process (pid
);
3271 inf
= find_inferior_pid (pid
);
3272 old_chain
= save_inferior_ptid ();
3274 inferior_ptid
= tp
->ptid
;
3276 tmp_error_stream
= mem_fileopen ();
3277 make_cleanup_ui_file_delete (tmp_error_stream
);
3279 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3281 if (bl
->pspace
!= inf
->pspace
)
3287 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3290 do_cleanups (old_chain
);
3295 do_cleanups (old_chain
);
3299 static int internal_breakpoint_number
= -1;
3301 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3302 If INTERNAL is non-zero, the breakpoint number will be populated
3303 from internal_breakpoint_number and that variable decremented.
3304 Otherwise the breakpoint number will be populated from
3305 breakpoint_count and that value incremented. Internal breakpoints
3306 do not set the internal var bpnum. */
3308 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3311 b
->number
= internal_breakpoint_number
--;
3314 set_breakpoint_count (breakpoint_count
+ 1);
3315 b
->number
= breakpoint_count
;
3319 static struct breakpoint
*
3320 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3321 CORE_ADDR address
, enum bptype type
,
3322 const struct breakpoint_ops
*ops
)
3324 struct symtab_and_line sal
;
3325 struct breakpoint
*b
;
3327 init_sal (&sal
); /* Initialize to zeroes. */
3330 sal
.section
= find_pc_overlay (sal
.pc
);
3331 sal
.pspace
= current_program_space
;
3333 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3334 b
->number
= internal_breakpoint_number
--;
3335 b
->disposition
= disp_donttouch
;
3340 static const char *const longjmp_names
[] =
3342 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3344 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3346 /* Per-objfile data private to breakpoint.c. */
3347 struct breakpoint_objfile_data
3349 /* Minimal symbol for "_ovly_debug_event" (if any). */
3350 struct bound_minimal_symbol overlay_msym
;
3352 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3353 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3355 /* True if we have looked for longjmp probes. */
3356 int longjmp_searched
;
3358 /* SystemTap probe points for longjmp (if any). */
3359 VEC (probe_p
) *longjmp_probes
;
3361 /* Minimal symbol for "std::terminate()" (if any). */
3362 struct bound_minimal_symbol terminate_msym
;
3364 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3365 struct bound_minimal_symbol exception_msym
;
3367 /* True if we have looked for exception probes. */
3368 int exception_searched
;
3370 /* SystemTap probe points for unwinding (if any). */
3371 VEC (probe_p
) *exception_probes
;
3374 static const struct objfile_data
*breakpoint_objfile_key
;
3376 /* Minimal symbol not found sentinel. */
3377 static struct minimal_symbol msym_not_found
;
3379 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3382 msym_not_found_p (const struct minimal_symbol
*msym
)
3384 return msym
== &msym_not_found
;
3387 /* Return per-objfile data needed by breakpoint.c.
3388 Allocate the data if necessary. */
3390 static struct breakpoint_objfile_data
*
3391 get_breakpoint_objfile_data (struct objfile
*objfile
)
3393 struct breakpoint_objfile_data
*bp_objfile_data
;
3395 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
3396 if (bp_objfile_data
== NULL
)
3399 XOBNEW (&objfile
->objfile_obstack
, struct breakpoint_objfile_data
);
3401 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3402 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3404 return bp_objfile_data
;
3408 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3410 struct breakpoint_objfile_data
*bp_objfile_data
= data
;
3412 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3413 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3417 create_overlay_event_breakpoint (void)
3419 struct objfile
*objfile
;
3420 const char *const func_name
= "_ovly_debug_event";
3422 ALL_OBJFILES (objfile
)
3424 struct breakpoint
*b
;
3425 struct breakpoint_objfile_data
*bp_objfile_data
;
3427 struct explicit_location explicit_loc
;
3429 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3431 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3434 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3436 struct bound_minimal_symbol m
;
3438 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3439 if (m
.minsym
== NULL
)
3441 /* Avoid future lookups in this objfile. */
3442 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3445 bp_objfile_data
->overlay_msym
= m
;
3448 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3449 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3451 &internal_breakpoint_ops
);
3452 initialize_explicit_location (&explicit_loc
);
3453 explicit_loc
.function_name
= ASTRDUP (func_name
);
3454 b
->location
= new_explicit_location (&explicit_loc
);
3456 if (overlay_debugging
== ovly_auto
)
3458 b
->enable_state
= bp_enabled
;
3459 overlay_events_enabled
= 1;
3463 b
->enable_state
= bp_disabled
;
3464 overlay_events_enabled
= 0;
3467 update_global_location_list (UGLL_MAY_INSERT
);
3471 create_longjmp_master_breakpoint (void)
3473 struct program_space
*pspace
;
3474 struct cleanup
*old_chain
;
3476 old_chain
= save_current_program_space ();
3478 ALL_PSPACES (pspace
)
3480 struct objfile
*objfile
;
3482 set_current_program_space (pspace
);
3484 ALL_OBJFILES (objfile
)
3487 struct gdbarch
*gdbarch
;
3488 struct breakpoint_objfile_data
*bp_objfile_data
;
3490 gdbarch
= get_objfile_arch (objfile
);
3492 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3494 if (!bp_objfile_data
->longjmp_searched
)
3498 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3501 /* We are only interested in checking one element. */
3502 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3504 if (!can_evaluate_probe_arguments (p
))
3506 /* We cannot use the probe interface here, because it does
3507 not know how to evaluate arguments. */
3508 VEC_free (probe_p
, ret
);
3512 bp_objfile_data
->longjmp_probes
= ret
;
3513 bp_objfile_data
->longjmp_searched
= 1;
3516 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3519 struct probe
*probe
;
3520 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3523 VEC_iterate (probe_p
,
3524 bp_objfile_data
->longjmp_probes
,
3528 struct breakpoint
*b
;
3530 b
= create_internal_breakpoint (gdbarch
,
3531 get_probe_address (probe
,
3534 &internal_breakpoint_ops
);
3536 = new_probe_location ("-probe-stap libc:longjmp");
3537 b
->enable_state
= bp_disabled
;
3543 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3546 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3548 struct breakpoint
*b
;
3549 const char *func_name
;
3551 struct explicit_location explicit_loc
;
3553 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3556 func_name
= longjmp_names
[i
];
3557 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3559 struct bound_minimal_symbol m
;
3561 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3562 if (m
.minsym
== NULL
)
3564 /* Prevent future lookups in this objfile. */
3565 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3568 bp_objfile_data
->longjmp_msym
[i
] = m
;
3571 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3572 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3573 &internal_breakpoint_ops
);
3574 initialize_explicit_location (&explicit_loc
);
3575 explicit_loc
.function_name
= ASTRDUP (func_name
);
3576 b
->location
= new_explicit_location (&explicit_loc
);
3577 b
->enable_state
= bp_disabled
;
3581 update_global_location_list (UGLL_MAY_INSERT
);
3583 do_cleanups (old_chain
);
3586 /* Create a master std::terminate breakpoint. */
3588 create_std_terminate_master_breakpoint (void)
3590 struct program_space
*pspace
;
3591 struct cleanup
*old_chain
;
3592 const char *const func_name
= "std::terminate()";
3594 old_chain
= save_current_program_space ();
3596 ALL_PSPACES (pspace
)
3598 struct objfile
*objfile
;
3601 set_current_program_space (pspace
);
3603 ALL_OBJFILES (objfile
)
3605 struct breakpoint
*b
;
3606 struct breakpoint_objfile_data
*bp_objfile_data
;
3607 struct explicit_location explicit_loc
;
3609 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3611 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3614 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3616 struct bound_minimal_symbol m
;
3618 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3619 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3620 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3622 /* Prevent future lookups in this objfile. */
3623 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3626 bp_objfile_data
->terminate_msym
= m
;
3629 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3630 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3631 bp_std_terminate_master
,
3632 &internal_breakpoint_ops
);
3633 initialize_explicit_location (&explicit_loc
);
3634 explicit_loc
.function_name
= ASTRDUP (func_name
);
3635 b
->location
= new_explicit_location (&explicit_loc
);
3636 b
->enable_state
= bp_disabled
;
3640 update_global_location_list (UGLL_MAY_INSERT
);
3642 do_cleanups (old_chain
);
3645 /* Install a master breakpoint on the unwinder's debug hook. */
3648 create_exception_master_breakpoint (void)
3650 struct objfile
*objfile
;
3651 const char *const func_name
= "_Unwind_DebugHook";
3653 ALL_OBJFILES (objfile
)
3655 struct breakpoint
*b
;
3656 struct gdbarch
*gdbarch
;
3657 struct breakpoint_objfile_data
*bp_objfile_data
;
3659 struct explicit_location explicit_loc
;
3661 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3663 /* We prefer the SystemTap probe point if it exists. */
3664 if (!bp_objfile_data
->exception_searched
)
3668 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3672 /* We are only interested in checking one element. */
3673 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3675 if (!can_evaluate_probe_arguments (p
))
3677 /* We cannot use the probe interface here, because it does
3678 not know how to evaluate arguments. */
3679 VEC_free (probe_p
, ret
);
3683 bp_objfile_data
->exception_probes
= ret
;
3684 bp_objfile_data
->exception_searched
= 1;
3687 if (bp_objfile_data
->exception_probes
!= NULL
)
3689 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3691 struct probe
*probe
;
3694 VEC_iterate (probe_p
,
3695 bp_objfile_data
->exception_probes
,
3699 struct breakpoint
*b
;
3701 b
= create_internal_breakpoint (gdbarch
,
3702 get_probe_address (probe
,
3704 bp_exception_master
,
3705 &internal_breakpoint_ops
);
3707 = new_probe_location ("-probe-stap libgcc:unwind");
3708 b
->enable_state
= bp_disabled
;
3714 /* Otherwise, try the hook function. */
3716 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3719 gdbarch
= get_objfile_arch (objfile
);
3721 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3723 struct bound_minimal_symbol debug_hook
;
3725 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3726 if (debug_hook
.minsym
== NULL
)
3728 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3732 bp_objfile_data
->exception_msym
= debug_hook
;
3735 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3736 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3738 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3739 &internal_breakpoint_ops
);
3740 initialize_explicit_location (&explicit_loc
);
3741 explicit_loc
.function_name
= ASTRDUP (func_name
);
3742 b
->location
= new_explicit_location (&explicit_loc
);
3743 b
->enable_state
= bp_disabled
;
3746 update_global_location_list (UGLL_MAY_INSERT
);
3750 update_breakpoints_after_exec (void)
3752 struct breakpoint
*b
, *b_tmp
;
3753 struct bp_location
*bploc
, **bplocp_tmp
;
3755 /* We're about to delete breakpoints from GDB's lists. If the
3756 INSERTED flag is true, GDB will try to lift the breakpoints by
3757 writing the breakpoints' "shadow contents" back into memory. The
3758 "shadow contents" are NOT valid after an exec, so GDB should not
3759 do that. Instead, the target is responsible from marking
3760 breakpoints out as soon as it detects an exec. We don't do that
3761 here instead, because there may be other attempts to delete
3762 breakpoints after detecting an exec and before reaching here. */
3763 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3764 if (bploc
->pspace
== current_program_space
)
3765 gdb_assert (!bploc
->inserted
);
3767 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3769 if (b
->pspace
!= current_program_space
)
3772 /* Solib breakpoints must be explicitly reset after an exec(). */
3773 if (b
->type
== bp_shlib_event
)
3775 delete_breakpoint (b
);
3779 /* JIT breakpoints must be explicitly reset after an exec(). */
3780 if (b
->type
== bp_jit_event
)
3782 delete_breakpoint (b
);
3786 /* Thread event breakpoints must be set anew after an exec(),
3787 as must overlay event and longjmp master breakpoints. */
3788 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3789 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3790 || b
->type
== bp_exception_master
)
3792 delete_breakpoint (b
);
3796 /* Step-resume breakpoints are meaningless after an exec(). */
3797 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3799 delete_breakpoint (b
);
3803 /* Just like single-step breakpoints. */
3804 if (b
->type
== bp_single_step
)
3806 delete_breakpoint (b
);
3810 /* Longjmp and longjmp-resume breakpoints are also meaningless
3812 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3813 || b
->type
== bp_longjmp_call_dummy
3814 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3816 delete_breakpoint (b
);
3820 if (b
->type
== bp_catchpoint
)
3822 /* For now, none of the bp_catchpoint breakpoints need to
3823 do anything at this point. In the future, if some of
3824 the catchpoints need to something, we will need to add
3825 a new method, and call this method from here. */
3829 /* bp_finish is a special case. The only way we ought to be able
3830 to see one of these when an exec() has happened, is if the user
3831 caught a vfork, and then said "finish". Ordinarily a finish just
3832 carries them to the call-site of the current callee, by setting
3833 a temporary bp there and resuming. But in this case, the finish
3834 will carry them entirely through the vfork & exec.
3836 We don't want to allow a bp_finish to remain inserted now. But
3837 we can't safely delete it, 'cause finish_command has a handle to
3838 the bp on a bpstat, and will later want to delete it. There's a
3839 chance (and I've seen it happen) that if we delete the bp_finish
3840 here, that its storage will get reused by the time finish_command
3841 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3842 We really must allow finish_command to delete a bp_finish.
3844 In the absence of a general solution for the "how do we know
3845 it's safe to delete something others may have handles to?"
3846 problem, what we'll do here is just uninsert the bp_finish, and
3847 let finish_command delete it.
3849 (We know the bp_finish is "doomed" in the sense that it's
3850 momentary, and will be deleted as soon as finish_command sees
3851 the inferior stopped. So it doesn't matter that the bp's
3852 address is probably bogus in the new a.out, unlike e.g., the
3853 solib breakpoints.) */
3855 if (b
->type
== bp_finish
)
3860 /* Without a symbolic address, we have little hope of the
3861 pre-exec() address meaning the same thing in the post-exec()
3863 if (event_location_empty_p (b
->location
))
3865 delete_breakpoint (b
);
3872 detach_breakpoints (ptid_t ptid
)
3874 struct bp_location
*bl
, **blp_tmp
;
3876 struct cleanup
*old_chain
= save_inferior_ptid ();
3877 struct inferior
*inf
= current_inferior ();
3879 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3880 error (_("Cannot detach breakpoints of inferior_ptid"));
3882 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3883 inferior_ptid
= ptid
;
3884 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3886 if (bl
->pspace
!= inf
->pspace
)
3889 /* This function must physically remove breakpoints locations
3890 from the specified ptid, without modifying the breakpoint
3891 package's state. Locations of type bp_loc_other are only
3892 maintained at GDB side. So, there is no need to remove
3893 these bp_loc_other locations. Moreover, removing these
3894 would modify the breakpoint package's state. */
3895 if (bl
->loc_type
== bp_loc_other
)
3899 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3902 do_cleanups (old_chain
);
3906 /* Remove the breakpoint location BL from the current address space.
3907 Note that this is used to detach breakpoints from a child fork.
3908 When we get here, the child isn't in the inferior list, and neither
3909 do we have objects to represent its address space --- we should
3910 *not* look at bl->pspace->aspace here. */
3913 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3917 /* BL is never in moribund_locations by our callers. */
3918 gdb_assert (bl
->owner
!= NULL
);
3920 /* The type of none suggests that owner is actually deleted.
3921 This should not ever happen. */
3922 gdb_assert (bl
->owner
->type
!= bp_none
);
3924 if (bl
->loc_type
== bp_loc_software_breakpoint
3925 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3927 /* "Normal" instruction breakpoint: either the standard
3928 trap-instruction bp (bp_breakpoint), or a
3929 bp_hardware_breakpoint. */
3931 /* First check to see if we have to handle an overlay. */
3932 if (overlay_debugging
== ovly_off
3933 || bl
->section
== NULL
3934 || !(section_is_overlay (bl
->section
)))
3936 /* No overlay handling: just remove the breakpoint. */
3938 /* If we're trying to uninsert a memory breakpoint that we
3939 know is set in a dynamic object that is marked
3940 shlib_disabled, then either the dynamic object was
3941 removed with "remove-symbol-file" or with
3942 "nosharedlibrary". In the former case, we don't know
3943 whether another dynamic object might have loaded over the
3944 breakpoint's address -- the user might well let us know
3945 about it next with add-symbol-file (the whole point of
3946 add-symbol-file is letting the user manually maintain a
3947 list of dynamically loaded objects). If we have the
3948 breakpoint's shadow memory, that is, this is a software
3949 breakpoint managed by GDB, check whether the breakpoint
3950 is still inserted in memory, to avoid overwriting wrong
3951 code with stale saved shadow contents. Note that HW
3952 breakpoints don't have shadow memory, as they're
3953 implemented using a mechanism that is not dependent on
3954 being able to modify the target's memory, and as such
3955 they should always be removed. */
3956 if (bl
->shlib_disabled
3957 && bl
->target_info
.shadow_len
!= 0
3958 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3961 val
= bl
->owner
->ops
->remove_location (bl
);
3965 /* This breakpoint is in an overlay section.
3966 Did we set a breakpoint at the LMA? */
3967 if (!overlay_events_enabled
)
3969 /* Yes -- overlay event support is not active, so we
3970 should have set a breakpoint at the LMA. Remove it.
3972 /* Ignore any failures: if the LMA is in ROM, we will
3973 have already warned when we failed to insert it. */
3974 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3975 target_remove_hw_breakpoint (bl
->gdbarch
,
3976 &bl
->overlay_target_info
);
3978 target_remove_breakpoint (bl
->gdbarch
,
3979 &bl
->overlay_target_info
);
3981 /* Did we set a breakpoint at the VMA?
3982 If so, we will have marked the breakpoint 'inserted'. */
3985 /* Yes -- remove it. Previously we did not bother to
3986 remove the breakpoint if the section had been
3987 unmapped, but let's not rely on that being safe. We
3988 don't know what the overlay manager might do. */
3990 /* However, we should remove *software* breakpoints only
3991 if the section is still mapped, or else we overwrite
3992 wrong code with the saved shadow contents. */
3993 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3994 || section_is_mapped (bl
->section
))
3995 val
= bl
->owner
->ops
->remove_location (bl
);
4001 /* No -- not inserted, so no need to remove. No error. */
4006 /* In some cases, we might not be able to remove a breakpoint in
4007 a shared library that has already been removed, but we have
4008 not yet processed the shlib unload event. Similarly for an
4009 unloaded add-symbol-file object - the user might not yet have
4010 had the chance to remove-symbol-file it. shlib_disabled will
4011 be set if the library/object has already been removed, but
4012 the breakpoint hasn't been uninserted yet, e.g., after
4013 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4014 always-inserted mode. */
4016 && (bl
->loc_type
== bp_loc_software_breakpoint
4017 && (bl
->shlib_disabled
4018 || solib_name_from_address (bl
->pspace
, bl
->address
)
4019 || shared_objfile_contains_address_p (bl
->pspace
,
4025 bl
->inserted
= (is
== mark_inserted
);
4027 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4029 gdb_assert (bl
->owner
->ops
!= NULL
4030 && bl
->owner
->ops
->remove_location
!= NULL
);
4032 bl
->inserted
= (is
== mark_inserted
);
4033 bl
->owner
->ops
->remove_location (bl
);
4035 /* Failure to remove any of the hardware watchpoints comes here. */
4036 if ((is
== mark_uninserted
) && (bl
->inserted
))
4037 warning (_("Could not remove hardware watchpoint %d."),
4040 else if (bl
->owner
->type
== bp_catchpoint
4041 && breakpoint_enabled (bl
->owner
)
4044 gdb_assert (bl
->owner
->ops
!= NULL
4045 && bl
->owner
->ops
->remove_location
!= NULL
);
4047 val
= bl
->owner
->ops
->remove_location (bl
);
4051 bl
->inserted
= (is
== mark_inserted
);
4058 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
4061 struct cleanup
*old_chain
;
4063 /* BL is never in moribund_locations by our callers. */
4064 gdb_assert (bl
->owner
!= NULL
);
4066 /* The type of none suggests that owner is actually deleted.
4067 This should not ever happen. */
4068 gdb_assert (bl
->owner
->type
!= bp_none
);
4070 old_chain
= save_current_space_and_thread ();
4072 switch_to_program_space_and_thread (bl
->pspace
);
4074 ret
= remove_breakpoint_1 (bl
, is
);
4076 do_cleanups (old_chain
);
4080 /* Clear the "inserted" flag in all breakpoints. */
4083 mark_breakpoints_out (void)
4085 struct bp_location
*bl
, **blp_tmp
;
4087 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4088 if (bl
->pspace
== current_program_space
)
4092 /* Clear the "inserted" flag in all breakpoints and delete any
4093 breakpoints which should go away between runs of the program.
4095 Plus other such housekeeping that has to be done for breakpoints
4098 Note: this function gets called at the end of a run (by
4099 generic_mourn_inferior) and when a run begins (by
4100 init_wait_for_inferior). */
4105 breakpoint_init_inferior (enum inf_context context
)
4107 struct breakpoint
*b
, *b_tmp
;
4108 struct bp_location
*bl
, **blp_tmp
;
4110 struct program_space
*pspace
= current_program_space
;
4112 /* If breakpoint locations are shared across processes, then there's
4114 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4117 mark_breakpoints_out ();
4119 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4121 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4127 case bp_longjmp_call_dummy
:
4129 /* If the call dummy breakpoint is at the entry point it will
4130 cause problems when the inferior is rerun, so we better get
4133 case bp_watchpoint_scope
:
4135 /* Also get rid of scope breakpoints. */
4137 case bp_shlib_event
:
4139 /* Also remove solib event breakpoints. Their addresses may
4140 have changed since the last time we ran the program.
4141 Actually we may now be debugging against different target;
4142 and so the solib backend that installed this breakpoint may
4143 not be used in by the target. E.g.,
4145 (gdb) file prog-linux
4146 (gdb) run # native linux target
4149 (gdb) file prog-win.exe
4150 (gdb) tar rem :9999 # remote Windows gdbserver.
4153 case bp_step_resume
:
4155 /* Also remove step-resume breakpoints. */
4157 case bp_single_step
:
4159 /* Also remove single-step breakpoints. */
4161 delete_breakpoint (b
);
4165 case bp_hardware_watchpoint
:
4166 case bp_read_watchpoint
:
4167 case bp_access_watchpoint
:
4169 struct watchpoint
*w
= (struct watchpoint
*) b
;
4171 /* Likewise for watchpoints on local expressions. */
4172 if (w
->exp_valid_block
!= NULL
)
4173 delete_breakpoint (b
);
4174 else if (context
== inf_starting
)
4176 /* Reset val field to force reread of starting value in
4177 insert_breakpoints. */
4179 value_free (w
->val
);
4190 /* Get rid of the moribund locations. */
4191 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4192 decref_bp_location (&bl
);
4193 VEC_free (bp_location_p
, moribund_locations
);
4196 /* These functions concern about actual breakpoints inserted in the
4197 target --- to e.g. check if we need to do decr_pc adjustment or if
4198 we need to hop over the bkpt --- so we check for address space
4199 match, not program space. */
4201 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4202 exists at PC. It returns ordinary_breakpoint_here if it's an
4203 ordinary breakpoint, or permanent_breakpoint_here if it's a
4204 permanent breakpoint.
4205 - When continuing from a location with an ordinary breakpoint, we
4206 actually single step once before calling insert_breakpoints.
4207 - When continuing from a location with a permanent breakpoint, we
4208 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4209 the target, to advance the PC past the breakpoint. */
4211 enum breakpoint_here
4212 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4214 struct bp_location
*bl
, **blp_tmp
;
4215 int any_breakpoint_here
= 0;
4217 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4219 if (bl
->loc_type
!= bp_loc_software_breakpoint
4220 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4223 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4224 if ((breakpoint_enabled (bl
->owner
)
4226 && breakpoint_location_address_match (bl
, aspace
, pc
))
4228 if (overlay_debugging
4229 && section_is_overlay (bl
->section
)
4230 && !section_is_mapped (bl
->section
))
4231 continue; /* unmapped overlay -- can't be a match */
4232 else if (bl
->permanent
)
4233 return permanent_breakpoint_here
;
4235 any_breakpoint_here
= 1;
4239 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4242 /* Return true if there's a moribund breakpoint at PC. */
4245 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4247 struct bp_location
*loc
;
4250 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4251 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4257 /* Returns non-zero iff BL is inserted at PC, in address space
4261 bp_location_inserted_here_p (struct bp_location
*bl
,
4262 struct address_space
*aspace
, CORE_ADDR pc
)
4265 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4268 if (overlay_debugging
4269 && section_is_overlay (bl
->section
)
4270 && !section_is_mapped (bl
->section
))
4271 return 0; /* unmapped overlay -- can't be a match */
4278 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4281 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4283 struct bp_location
**blp
, **blp_tmp
= NULL
;
4284 struct bp_location
*bl
;
4286 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4288 struct bp_location
*bl
= *blp
;
4290 if (bl
->loc_type
!= bp_loc_software_breakpoint
4291 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4294 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4300 /* This function returns non-zero iff there is a software breakpoint
4304 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4307 struct bp_location
**blp
, **blp_tmp
= NULL
;
4308 struct bp_location
*bl
;
4310 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4312 struct bp_location
*bl
= *blp
;
4314 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4317 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4324 /* See breakpoint.h. */
4327 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4330 struct bp_location
**blp
, **blp_tmp
= NULL
;
4331 struct bp_location
*bl
;
4333 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4335 struct bp_location
*bl
= *blp
;
4337 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4340 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4348 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4349 CORE_ADDR addr
, ULONGEST len
)
4351 struct breakpoint
*bpt
;
4353 ALL_BREAKPOINTS (bpt
)
4355 struct bp_location
*loc
;
4357 if (bpt
->type
!= bp_hardware_watchpoint
4358 && bpt
->type
!= bp_access_watchpoint
)
4361 if (!breakpoint_enabled (bpt
))
4364 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4365 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4369 /* Check for intersection. */
4370 l
= max (loc
->address
, addr
);
4371 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
4380 /* bpstat stuff. External routines' interfaces are documented
4384 is_catchpoint (struct breakpoint
*ep
)
4386 return (ep
->type
== bp_catchpoint
);
4389 /* Frees any storage that is part of a bpstat. Does not walk the
4393 bpstat_free (bpstat bs
)
4395 if (bs
->old_val
!= NULL
)
4396 value_free (bs
->old_val
);
4397 decref_counted_command_line (&bs
->commands
);
4398 decref_bp_location (&bs
->bp_location_at
);
4402 /* Clear a bpstat so that it says we are not at any breakpoint.
4403 Also free any storage that is part of a bpstat. */
4406 bpstat_clear (bpstat
*bsp
)
4423 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4424 is part of the bpstat is copied as well. */
4427 bpstat_copy (bpstat bs
)
4431 bpstat retval
= NULL
;
4436 for (; bs
!= NULL
; bs
= bs
->next
)
4438 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4439 memcpy (tmp
, bs
, sizeof (*tmp
));
4440 incref_counted_command_line (tmp
->commands
);
4441 incref_bp_location (tmp
->bp_location_at
);
4442 if (bs
->old_val
!= NULL
)
4444 tmp
->old_val
= value_copy (bs
->old_val
);
4445 release_value (tmp
->old_val
);
4449 /* This is the first thing in the chain. */
4459 /* Find the bpstat associated with this breakpoint. */
4462 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4467 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4469 if (bsp
->breakpoint_at
== breakpoint
)
4475 /* See breakpoint.h. */
4478 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4480 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4482 if (bsp
->breakpoint_at
== NULL
)
4484 /* A moribund location can never explain a signal other than
4486 if (sig
== GDB_SIGNAL_TRAP
)
4491 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4500 /* Put in *NUM the breakpoint number of the first breakpoint we are
4501 stopped at. *BSP upon return is a bpstat which points to the
4502 remaining breakpoints stopped at (but which is not guaranteed to be
4503 good for anything but further calls to bpstat_num).
4505 Return 0 if passed a bpstat which does not indicate any breakpoints.
4506 Return -1 if stopped at a breakpoint that has been deleted since
4508 Return 1 otherwise. */
4511 bpstat_num (bpstat
*bsp
, int *num
)
4513 struct breakpoint
*b
;
4516 return 0; /* No more breakpoint values */
4518 /* We assume we'll never have several bpstats that correspond to a
4519 single breakpoint -- otherwise, this function might return the
4520 same number more than once and this will look ugly. */
4521 b
= (*bsp
)->breakpoint_at
;
4522 *bsp
= (*bsp
)->next
;
4524 return -1; /* breakpoint that's been deleted since */
4526 *num
= b
->number
; /* We have its number */
4530 /* See breakpoint.h. */
4533 bpstat_clear_actions (void)
4535 struct thread_info
*tp
;
4538 if (ptid_equal (inferior_ptid
, null_ptid
))
4541 tp
= find_thread_ptid (inferior_ptid
);
4545 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4547 decref_counted_command_line (&bs
->commands
);
4549 if (bs
->old_val
!= NULL
)
4551 value_free (bs
->old_val
);
4557 /* Called when a command is about to proceed the inferior. */
4560 breakpoint_about_to_proceed (void)
4562 if (!ptid_equal (inferior_ptid
, null_ptid
))
4564 struct thread_info
*tp
= inferior_thread ();
4566 /* Allow inferior function calls in breakpoint commands to not
4567 interrupt the command list. When the call finishes
4568 successfully, the inferior will be standing at the same
4569 breakpoint as if nothing happened. */
4570 if (tp
->control
.in_infcall
)
4574 breakpoint_proceeded
= 1;
4577 /* Stub for cleaning up our state if we error-out of a breakpoint
4580 cleanup_executing_breakpoints (void *ignore
)
4582 executing_breakpoint_commands
= 0;
4585 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4586 or its equivalent. */
4589 command_line_is_silent (struct command_line
*cmd
)
4591 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4594 /* Execute all the commands associated with all the breakpoints at
4595 this location. Any of these commands could cause the process to
4596 proceed beyond this point, etc. We look out for such changes by
4597 checking the global "breakpoint_proceeded" after each command.
4599 Returns true if a breakpoint command resumed the inferior. In that
4600 case, it is the caller's responsibility to recall it again with the
4601 bpstat of the current thread. */
4604 bpstat_do_actions_1 (bpstat
*bsp
)
4607 struct cleanup
*old_chain
;
4610 /* Avoid endless recursion if a `source' command is contained
4612 if (executing_breakpoint_commands
)
4615 executing_breakpoint_commands
= 1;
4616 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4618 prevent_dont_repeat ();
4620 /* This pointer will iterate over the list of bpstat's. */
4623 breakpoint_proceeded
= 0;
4624 for (; bs
!= NULL
; bs
= bs
->next
)
4626 struct counted_command_line
*ccmd
;
4627 struct command_line
*cmd
;
4628 struct cleanup
*this_cmd_tree_chain
;
4630 /* Take ownership of the BSP's command tree, if it has one.
4632 The command tree could legitimately contain commands like
4633 'step' and 'next', which call clear_proceed_status, which
4634 frees stop_bpstat's command tree. To make sure this doesn't
4635 free the tree we're executing out from under us, we need to
4636 take ownership of the tree ourselves. Since a given bpstat's
4637 commands are only executed once, we don't need to copy it; we
4638 can clear the pointer in the bpstat, and make sure we free
4639 the tree when we're done. */
4640 ccmd
= bs
->commands
;
4641 bs
->commands
= NULL
;
4642 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4643 cmd
= ccmd
? ccmd
->commands
: NULL
;
4644 if (command_line_is_silent (cmd
))
4646 /* The action has been already done by bpstat_stop_status. */
4652 execute_control_command (cmd
);
4654 if (breakpoint_proceeded
)
4660 /* We can free this command tree now. */
4661 do_cleanups (this_cmd_tree_chain
);
4663 if (breakpoint_proceeded
)
4665 if (interpreter_async
)
4666 /* If we are in async mode, then the target might be still
4667 running, not stopped at any breakpoint, so nothing for
4668 us to do here -- just return to the event loop. */
4671 /* In sync mode, when execute_control_command returns
4672 we're already standing on the next breakpoint.
4673 Breakpoint commands for that stop were not run, since
4674 execute_command does not run breakpoint commands --
4675 only command_line_handler does, but that one is not
4676 involved in execution of breakpoint commands. So, we
4677 can now execute breakpoint commands. It should be
4678 noted that making execute_command do bpstat actions is
4679 not an option -- in this case we'll have recursive
4680 invocation of bpstat for each breakpoint with a
4681 command, and can easily blow up GDB stack. Instead, we
4682 return true, which will trigger the caller to recall us
4683 with the new stop_bpstat. */
4688 do_cleanups (old_chain
);
4693 bpstat_do_actions (void)
4695 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4697 /* Do any commands attached to breakpoint we are stopped at. */
4698 while (!ptid_equal (inferior_ptid
, null_ptid
)
4699 && target_has_execution
4700 && !is_exited (inferior_ptid
)
4701 && !is_executing (inferior_ptid
))
4702 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4703 and only return when it is stopped at the next breakpoint, we
4704 keep doing breakpoint actions until it returns false to
4705 indicate the inferior was not resumed. */
4706 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4709 discard_cleanups (cleanup_if_error
);
4712 /* Print out the (old or new) value associated with a watchpoint. */
4715 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4718 fprintf_unfiltered (stream
, _("<unreadable>"));
4721 struct value_print_options opts
;
4722 get_user_print_options (&opts
);
4723 value_print (val
, stream
, &opts
);
4727 /* Generic routine for printing messages indicating why we
4728 stopped. The behavior of this function depends on the value
4729 'print_it' in the bpstat structure. Under some circumstances we
4730 may decide not to print anything here and delegate the task to
4733 static enum print_stop_action
4734 print_bp_stop_message (bpstat bs
)
4736 switch (bs
->print_it
)
4739 /* Nothing should be printed for this bpstat entry. */
4740 return PRINT_UNKNOWN
;
4744 /* We still want to print the frame, but we already printed the
4745 relevant messages. */
4746 return PRINT_SRC_AND_LOC
;
4749 case print_it_normal
:
4751 struct breakpoint
*b
= bs
->breakpoint_at
;
4753 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4754 which has since been deleted. */
4756 return PRINT_UNKNOWN
;
4758 /* Normal case. Call the breakpoint's print_it method. */
4759 return b
->ops
->print_it (bs
);
4764 internal_error (__FILE__
, __LINE__
,
4765 _("print_bp_stop_message: unrecognized enum value"));
4770 /* A helper function that prints a shared library stopped event. */
4773 print_solib_event (int is_catchpoint
)
4776 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4778 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4782 if (any_added
|| any_deleted
)
4783 ui_out_text (current_uiout
,
4784 _("Stopped due to shared library event:\n"));
4786 ui_out_text (current_uiout
,
4787 _("Stopped due to shared library event (no "
4788 "libraries added or removed)\n"));
4791 if (ui_out_is_mi_like_p (current_uiout
))
4792 ui_out_field_string (current_uiout
, "reason",
4793 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4797 struct cleanup
*cleanup
;
4801 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4802 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4805 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4810 ui_out_text (current_uiout
, " ");
4811 ui_out_field_string (current_uiout
, "library", name
);
4812 ui_out_text (current_uiout
, "\n");
4815 do_cleanups (cleanup
);
4820 struct so_list
*iter
;
4822 struct cleanup
*cleanup
;
4824 ui_out_text (current_uiout
, _(" Inferior loaded "));
4825 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4828 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4833 ui_out_text (current_uiout
, " ");
4834 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4835 ui_out_text (current_uiout
, "\n");
4838 do_cleanups (cleanup
);
4842 /* Print a message indicating what happened. This is called from
4843 normal_stop(). The input to this routine is the head of the bpstat
4844 list - a list of the eventpoints that caused this stop. KIND is
4845 the target_waitkind for the stopping event. This
4846 routine calls the generic print routine for printing a message
4847 about reasons for stopping. This will print (for example) the
4848 "Breakpoint n," part of the output. The return value of this
4851 PRINT_UNKNOWN: Means we printed nothing.
4852 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4853 code to print the location. An example is
4854 "Breakpoint 1, " which should be followed by
4856 PRINT_SRC_ONLY: Means we printed something, but there is no need
4857 to also print the location part of the message.
4858 An example is the catch/throw messages, which
4859 don't require a location appended to the end.
4860 PRINT_NOTHING: We have done some printing and we don't need any
4861 further info to be printed. */
4863 enum print_stop_action
4864 bpstat_print (bpstat bs
, int kind
)
4866 enum print_stop_action val
;
4868 /* Maybe another breakpoint in the chain caused us to stop.
4869 (Currently all watchpoints go on the bpstat whether hit or not.
4870 That probably could (should) be changed, provided care is taken
4871 with respect to bpstat_explains_signal). */
4872 for (; bs
; bs
= bs
->next
)
4874 val
= print_bp_stop_message (bs
);
4875 if (val
== PRINT_SRC_ONLY
4876 || val
== PRINT_SRC_AND_LOC
4877 || val
== PRINT_NOTHING
)
4881 /* If we had hit a shared library event breakpoint,
4882 print_bp_stop_message would print out this message. If we hit an
4883 OS-level shared library event, do the same thing. */
4884 if (kind
== TARGET_WAITKIND_LOADED
)
4886 print_solib_event (0);
4887 return PRINT_NOTHING
;
4890 /* We reached the end of the chain, or we got a null BS to start
4891 with and nothing was printed. */
4892 return PRINT_UNKNOWN
;
4895 /* Evaluate the expression EXP and return 1 if value is zero.
4896 This returns the inverse of the condition because it is called
4897 from catch_errors which returns 0 if an exception happened, and if an
4898 exception happens we want execution to stop.
4899 The argument is a "struct expression *" that has been cast to a
4900 "void *" to make it pass through catch_errors. */
4903 breakpoint_cond_eval (void *exp
)
4905 struct value
*mark
= value_mark ();
4906 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4908 value_free_to_mark (mark
);
4912 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4915 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4919 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4921 **bs_link_pointer
= bs
;
4922 *bs_link_pointer
= &bs
->next
;
4923 bs
->breakpoint_at
= bl
->owner
;
4924 bs
->bp_location_at
= bl
;
4925 incref_bp_location (bl
);
4926 /* If the condition is false, etc., don't do the commands. */
4927 bs
->commands
= NULL
;
4929 bs
->print_it
= print_it_normal
;
4933 /* The target has stopped with waitstatus WS. Check if any hardware
4934 watchpoints have triggered, according to the target. */
4937 watchpoints_triggered (struct target_waitstatus
*ws
)
4939 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4941 struct breakpoint
*b
;
4943 if (!stopped_by_watchpoint
)
4945 /* We were not stopped by a watchpoint. Mark all watchpoints
4946 as not triggered. */
4948 if (is_hardware_watchpoint (b
))
4950 struct watchpoint
*w
= (struct watchpoint
*) b
;
4952 w
->watchpoint_triggered
= watch_triggered_no
;
4958 if (!target_stopped_data_address (¤t_target
, &addr
))
4960 /* We were stopped by a watchpoint, but we don't know where.
4961 Mark all watchpoints as unknown. */
4963 if (is_hardware_watchpoint (b
))
4965 struct watchpoint
*w
= (struct watchpoint
*) b
;
4967 w
->watchpoint_triggered
= watch_triggered_unknown
;
4973 /* The target could report the data address. Mark watchpoints
4974 affected by this data address as triggered, and all others as not
4978 if (is_hardware_watchpoint (b
))
4980 struct watchpoint
*w
= (struct watchpoint
*) b
;
4981 struct bp_location
*loc
;
4983 w
->watchpoint_triggered
= watch_triggered_no
;
4984 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4986 if (is_masked_watchpoint (b
))
4988 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4989 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4991 if (newaddr
== start
)
4993 w
->watchpoint_triggered
= watch_triggered_yes
;
4997 /* Exact match not required. Within range is sufficient. */
4998 else if (target_watchpoint_addr_within_range (¤t_target
,
5002 w
->watchpoint_triggered
= watch_triggered_yes
;
5011 /* Possible return values for watchpoint_check (this can't be an enum
5012 because of check_errors). */
5013 /* The watchpoint has been deleted. */
5014 #define WP_DELETED 1
5015 /* The value has changed. */
5016 #define WP_VALUE_CHANGED 2
5017 /* The value has not changed. */
5018 #define WP_VALUE_NOT_CHANGED 3
5019 /* Ignore this watchpoint, no matter if the value changed or not. */
5022 #define BP_TEMPFLAG 1
5023 #define BP_HARDWAREFLAG 2
5025 /* Evaluate watchpoint condition expression and check if its value
5028 P should be a pointer to struct bpstat, but is defined as a void *
5029 in order for this function to be usable with catch_errors. */
5032 watchpoint_check (void *p
)
5034 bpstat bs
= (bpstat
) p
;
5035 struct watchpoint
*b
;
5036 struct frame_info
*fr
;
5037 int within_current_scope
;
5039 /* BS is built from an existing struct breakpoint. */
5040 gdb_assert (bs
->breakpoint_at
!= NULL
);
5041 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5043 /* If this is a local watchpoint, we only want to check if the
5044 watchpoint frame is in scope if the current thread is the thread
5045 that was used to create the watchpoint. */
5046 if (!watchpoint_in_thread_scope (b
))
5049 if (b
->exp_valid_block
== NULL
)
5050 within_current_scope
= 1;
5053 struct frame_info
*frame
= get_current_frame ();
5054 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5055 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5057 /* stack_frame_destroyed_p() returns a non-zero value if we're
5058 still in the function but the stack frame has already been
5059 invalidated. Since we can't rely on the values of local
5060 variables after the stack has been destroyed, we are treating
5061 the watchpoint in that state as `not changed' without further
5062 checking. Don't mark watchpoints as changed if the current
5063 frame is in an epilogue - even if they are in some other
5064 frame, our view of the stack is likely to be wrong and
5065 frame_find_by_id could error out. */
5066 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5069 fr
= frame_find_by_id (b
->watchpoint_frame
);
5070 within_current_scope
= (fr
!= NULL
);
5072 /* If we've gotten confused in the unwinder, we might have
5073 returned a frame that can't describe this variable. */
5074 if (within_current_scope
)
5076 struct symbol
*function
;
5078 function
= get_frame_function (fr
);
5079 if (function
== NULL
5080 || !contained_in (b
->exp_valid_block
,
5081 SYMBOL_BLOCK_VALUE (function
)))
5082 within_current_scope
= 0;
5085 if (within_current_scope
)
5086 /* If we end up stopping, the current frame will get selected
5087 in normal_stop. So this call to select_frame won't affect
5092 if (within_current_scope
)
5094 /* We use value_{,free_to_}mark because it could be a *long*
5095 time before we return to the command level and call
5096 free_all_values. We can't call free_all_values because we
5097 might be in the middle of evaluating a function call. */
5101 struct value
*new_val
;
5103 if (is_masked_watchpoint (&b
->base
))
5104 /* Since we don't know the exact trigger address (from
5105 stopped_data_address), just tell the user we've triggered
5106 a mask watchpoint. */
5107 return WP_VALUE_CHANGED
;
5109 mark
= value_mark ();
5110 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
, 0);
5112 if (b
->val_bitsize
!= 0)
5113 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5115 /* We use value_equal_contents instead of value_equal because
5116 the latter coerces an array to a pointer, thus comparing just
5117 the address of the array instead of its contents. This is
5118 not what we want. */
5119 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5120 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5122 if (new_val
!= NULL
)
5124 release_value (new_val
);
5125 value_free_to_mark (mark
);
5127 bs
->old_val
= b
->val
;
5130 return WP_VALUE_CHANGED
;
5134 /* Nothing changed. */
5135 value_free_to_mark (mark
);
5136 return WP_VALUE_NOT_CHANGED
;
5141 struct ui_out
*uiout
= current_uiout
;
5143 /* This seems like the only logical thing to do because
5144 if we temporarily ignored the watchpoint, then when
5145 we reenter the block in which it is valid it contains
5146 garbage (in the case of a function, it may have two
5147 garbage values, one before and one after the prologue).
5148 So we can't even detect the first assignment to it and
5149 watch after that (since the garbage may or may not equal
5150 the first value assigned). */
5151 /* We print all the stop information in
5152 breakpoint_ops->print_it, but in this case, by the time we
5153 call breakpoint_ops->print_it this bp will be deleted
5154 already. So we have no choice but print the information
5156 if (ui_out_is_mi_like_p (uiout
))
5158 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5159 ui_out_text (uiout
, "\nWatchpoint ");
5160 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
5162 " deleted because the program has left the block in\n\
5163 which its expression is valid.\n");
5165 /* Make sure the watchpoint's commands aren't executed. */
5166 decref_counted_command_line (&b
->base
.commands
);
5167 watchpoint_del_at_next_stop (b
);
5173 /* Return true if it looks like target has stopped due to hitting
5174 breakpoint location BL. This function does not check if we should
5175 stop, only if BL explains the stop. */
5178 bpstat_check_location (const struct bp_location
*bl
,
5179 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5180 const struct target_waitstatus
*ws
)
5182 struct breakpoint
*b
= bl
->owner
;
5184 /* BL is from an existing breakpoint. */
5185 gdb_assert (b
!= NULL
);
5187 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5190 /* Determine if the watched values have actually changed, and we
5191 should stop. If not, set BS->stop to 0. */
5194 bpstat_check_watchpoint (bpstat bs
)
5196 const struct bp_location
*bl
;
5197 struct watchpoint
*b
;
5199 /* BS is built for existing struct breakpoint. */
5200 bl
= bs
->bp_location_at
;
5201 gdb_assert (bl
!= NULL
);
5202 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5203 gdb_assert (b
!= NULL
);
5206 int must_check_value
= 0;
5208 if (b
->base
.type
== bp_watchpoint
)
5209 /* For a software watchpoint, we must always check the
5211 must_check_value
= 1;
5212 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5213 /* We have a hardware watchpoint (read, write, or access)
5214 and the target earlier reported an address watched by
5216 must_check_value
= 1;
5217 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5218 && b
->base
.type
== bp_hardware_watchpoint
)
5219 /* We were stopped by a hardware watchpoint, but the target could
5220 not report the data address. We must check the watchpoint's
5221 value. Access and read watchpoints are out of luck; without
5222 a data address, we can't figure it out. */
5223 must_check_value
= 1;
5225 if (must_check_value
)
5228 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5230 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5231 int e
= catch_errors (watchpoint_check
, bs
, message
,
5233 do_cleanups (cleanups
);
5237 /* We've already printed what needs to be printed. */
5238 bs
->print_it
= print_it_done
;
5242 bs
->print_it
= print_it_noop
;
5245 case WP_VALUE_CHANGED
:
5246 if (b
->base
.type
== bp_read_watchpoint
)
5248 /* There are two cases to consider here:
5250 1. We're watching the triggered memory for reads.
5251 In that case, trust the target, and always report
5252 the watchpoint hit to the user. Even though
5253 reads don't cause value changes, the value may
5254 have changed since the last time it was read, and
5255 since we're not trapping writes, we will not see
5256 those, and as such we should ignore our notion of
5259 2. We're watching the triggered memory for both
5260 reads and writes. There are two ways this may
5263 2.1. This is a target that can't break on data
5264 reads only, but can break on accesses (reads or
5265 writes), such as e.g., x86. We detect this case
5266 at the time we try to insert read watchpoints.
5268 2.2. Otherwise, the target supports read
5269 watchpoints, but, the user set an access or write
5270 watchpoint watching the same memory as this read
5273 If we're watching memory writes as well as reads,
5274 ignore watchpoint hits when we find that the
5275 value hasn't changed, as reads don't cause
5276 changes. This still gives false positives when
5277 the program writes the same value to memory as
5278 what there was already in memory (we will confuse
5279 it for a read), but it's much better than
5282 int other_write_watchpoint
= 0;
5284 if (bl
->watchpoint_type
== hw_read
)
5286 struct breakpoint
*other_b
;
5288 ALL_BREAKPOINTS (other_b
)
5289 if (other_b
->type
== bp_hardware_watchpoint
5290 || other_b
->type
== bp_access_watchpoint
)
5292 struct watchpoint
*other_w
=
5293 (struct watchpoint
*) other_b
;
5295 if (other_w
->watchpoint_triggered
5296 == watch_triggered_yes
)
5298 other_write_watchpoint
= 1;
5304 if (other_write_watchpoint
5305 || bl
->watchpoint_type
== hw_access
)
5307 /* We're watching the same memory for writes,
5308 and the value changed since the last time we
5309 updated it, so this trap must be for a write.
5311 bs
->print_it
= print_it_noop
;
5316 case WP_VALUE_NOT_CHANGED
:
5317 if (b
->base
.type
== bp_hardware_watchpoint
5318 || b
->base
.type
== bp_watchpoint
)
5320 /* Don't stop: write watchpoints shouldn't fire if
5321 the value hasn't changed. */
5322 bs
->print_it
= print_it_noop
;
5330 /* Error from catch_errors. */
5331 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
5332 watchpoint_del_at_next_stop (b
);
5333 /* We've already printed what needs to be printed. */
5334 bs
->print_it
= print_it_done
;
5338 else /* must_check_value == 0 */
5340 /* This is a case where some watchpoint(s) triggered, but
5341 not at the address of this watchpoint, or else no
5342 watchpoint triggered after all. So don't print
5343 anything for this watchpoint. */
5344 bs
->print_it
= print_it_noop
;
5350 /* For breakpoints that are currently marked as telling gdb to stop,
5351 check conditions (condition proper, frame, thread and ignore count)
5352 of breakpoint referred to by BS. If we should not stop for this
5353 breakpoint, set BS->stop to 0. */
5356 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5358 const struct bp_location
*bl
;
5359 struct breakpoint
*b
;
5360 int value_is_zero
= 0;
5361 struct expression
*cond
;
5363 gdb_assert (bs
->stop
);
5365 /* BS is built for existing struct breakpoint. */
5366 bl
= bs
->bp_location_at
;
5367 gdb_assert (bl
!= NULL
);
5368 b
= bs
->breakpoint_at
;
5369 gdb_assert (b
!= NULL
);
5371 /* Even if the target evaluated the condition on its end and notified GDB, we
5372 need to do so again since GDB does not know if we stopped due to a
5373 breakpoint or a single step breakpoint. */
5375 if (frame_id_p (b
->frame_id
)
5376 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5382 /* If this is a thread/task-specific breakpoint, don't waste cpu
5383 evaluating the condition if this isn't the specified
5385 if ((b
->thread
!= -1 && b
->thread
!= pid_to_thread_id (ptid
))
5386 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5393 /* Evaluate extension language breakpoints that have a "stop" method
5395 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5397 if (is_watchpoint (b
))
5399 struct watchpoint
*w
= (struct watchpoint
*) b
;
5406 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5408 int within_current_scope
= 1;
5409 struct watchpoint
* w
;
5411 /* We use value_mark and value_free_to_mark because it could
5412 be a long time before we return to the command level and
5413 call free_all_values. We can't call free_all_values
5414 because we might be in the middle of evaluating a
5416 struct value
*mark
= value_mark ();
5418 if (is_watchpoint (b
))
5419 w
= (struct watchpoint
*) b
;
5423 /* Need to select the frame, with all that implies so that
5424 the conditions will have the right context. Because we
5425 use the frame, we will not see an inlined function's
5426 variables when we arrive at a breakpoint at the start
5427 of the inlined function; the current frame will be the
5429 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5430 select_frame (get_current_frame ());
5433 struct frame_info
*frame
;
5435 /* For local watchpoint expressions, which particular
5436 instance of a local is being watched matters, so we
5437 keep track of the frame to evaluate the expression
5438 in. To evaluate the condition however, it doesn't
5439 really matter which instantiation of the function
5440 where the condition makes sense triggers the
5441 watchpoint. This allows an expression like "watch
5442 global if q > 10" set in `func', catch writes to
5443 global on all threads that call `func', or catch
5444 writes on all recursive calls of `func' by a single
5445 thread. We simply always evaluate the condition in
5446 the innermost frame that's executing where it makes
5447 sense to evaluate the condition. It seems
5449 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5451 select_frame (frame
);
5453 within_current_scope
= 0;
5455 if (within_current_scope
)
5457 = catch_errors (breakpoint_cond_eval
, cond
,
5458 "Error in testing breakpoint condition:\n",
5462 warning (_("Watchpoint condition cannot be tested "
5463 "in the current scope"));
5464 /* If we failed to set the right context for this
5465 watchpoint, unconditionally report it. */
5468 /* FIXME-someday, should give breakpoint #. */
5469 value_free_to_mark (mark
);
5472 if (cond
&& value_is_zero
)
5476 else if (b
->ignore_count
> 0)
5480 /* Increase the hit count even though we don't stop. */
5482 observer_notify_breakpoint_modified (b
);
5486 /* Returns true if we need to track moribund locations of LOC's type
5487 on the current target. */
5490 need_moribund_for_location_type (struct bp_location
*loc
)
5492 return ((loc
->loc_type
== bp_loc_software_breakpoint
5493 && !target_supports_stopped_by_sw_breakpoint ())
5494 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5495 && !target_supports_stopped_by_hw_breakpoint ()));
5499 /* Get a bpstat associated with having just stopped at address
5500 BP_ADDR in thread PTID.
5502 Determine whether we stopped at a breakpoint, etc, or whether we
5503 don't understand this stop. Result is a chain of bpstat's such
5506 if we don't understand the stop, the result is a null pointer.
5508 if we understand why we stopped, the result is not null.
5510 Each element of the chain refers to a particular breakpoint or
5511 watchpoint at which we have stopped. (We may have stopped for
5512 several reasons concurrently.)
5514 Each element of the chain has valid next, breakpoint_at,
5515 commands, FIXME??? fields. */
5518 bpstat_stop_status (struct address_space
*aspace
,
5519 CORE_ADDR bp_addr
, ptid_t ptid
,
5520 const struct target_waitstatus
*ws
)
5522 struct breakpoint
*b
= NULL
;
5523 struct bp_location
*bl
;
5524 struct bp_location
*loc
;
5525 /* First item of allocated bpstat's. */
5526 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5527 /* Pointer to the last thing in the chain currently. */
5530 int need_remove_insert
;
5533 /* First, build the bpstat chain with locations that explain a
5534 target stop, while being careful to not set the target running,
5535 as that may invalidate locations (in particular watchpoint
5536 locations are recreated). Resuming will happen here with
5537 breakpoint conditions or watchpoint expressions that include
5538 inferior function calls. */
5542 if (!breakpoint_enabled (b
))
5545 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5547 /* For hardware watchpoints, we look only at the first
5548 location. The watchpoint_check function will work on the
5549 entire expression, not the individual locations. For
5550 read watchpoints, the watchpoints_triggered function has
5551 checked all locations already. */
5552 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5555 if (!bl
->enabled
|| bl
->shlib_disabled
)
5558 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5561 /* Come here if it's a watchpoint, or if the break address
5564 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5567 /* Assume we stop. Should we find a watchpoint that is not
5568 actually triggered, or if the condition of the breakpoint
5569 evaluates as false, we'll reset 'stop' to 0. */
5573 /* If this is a scope breakpoint, mark the associated
5574 watchpoint as triggered so that we will handle the
5575 out-of-scope event. We'll get to the watchpoint next
5577 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5579 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5581 w
->watchpoint_triggered
= watch_triggered_yes
;
5586 /* Check if a moribund breakpoint explains the stop. */
5587 if (!target_supports_stopped_by_sw_breakpoint ()
5588 || !target_supports_stopped_by_hw_breakpoint ())
5590 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5592 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5593 && need_moribund_for_location_type (loc
))
5595 bs
= bpstat_alloc (loc
, &bs_link
);
5596 /* For hits of moribund locations, we should just proceed. */
5599 bs
->print_it
= print_it_noop
;
5604 /* A bit of special processing for shlib breakpoints. We need to
5605 process solib loading here, so that the lists of loaded and
5606 unloaded libraries are correct before we handle "catch load" and
5608 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5610 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5612 handle_solib_event ();
5617 /* Now go through the locations that caused the target to stop, and
5618 check whether we're interested in reporting this stop to higher
5619 layers, or whether we should resume the target transparently. */
5623 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5628 b
= bs
->breakpoint_at
;
5629 b
->ops
->check_status (bs
);
5632 bpstat_check_breakpoint_conditions (bs
, ptid
);
5637 observer_notify_breakpoint_modified (b
);
5639 /* We will stop here. */
5640 if (b
->disposition
== disp_disable
)
5642 --(b
->enable_count
);
5643 if (b
->enable_count
<= 0)
5644 b
->enable_state
= bp_disabled
;
5649 bs
->commands
= b
->commands
;
5650 incref_counted_command_line (bs
->commands
);
5651 if (command_line_is_silent (bs
->commands
5652 ? bs
->commands
->commands
: NULL
))
5655 b
->ops
->after_condition_true (bs
);
5660 /* Print nothing for this entry if we don't stop or don't
5662 if (!bs
->stop
|| !bs
->print
)
5663 bs
->print_it
= print_it_noop
;
5666 /* If we aren't stopping, the value of some hardware watchpoint may
5667 not have changed, but the intermediate memory locations we are
5668 watching may have. Don't bother if we're stopping; this will get
5670 need_remove_insert
= 0;
5671 if (! bpstat_causes_stop (bs_head
))
5672 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5674 && bs
->breakpoint_at
5675 && is_hardware_watchpoint (bs
->breakpoint_at
))
5677 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5679 update_watchpoint (w
, 0 /* don't reparse. */);
5680 need_remove_insert
= 1;
5683 if (need_remove_insert
)
5684 update_global_location_list (UGLL_MAY_INSERT
);
5685 else if (removed_any
)
5686 update_global_location_list (UGLL_DONT_INSERT
);
5692 handle_jit_event (void)
5694 struct frame_info
*frame
;
5695 struct gdbarch
*gdbarch
;
5697 /* Switch terminal for any messages produced by
5698 breakpoint_re_set. */
5699 target_terminal_ours_for_output ();
5701 frame
= get_current_frame ();
5702 gdbarch
= get_frame_arch (frame
);
5704 jit_event_handler (gdbarch
);
5706 target_terminal_inferior ();
5709 /* Prepare WHAT final decision for infrun. */
5711 /* Decide what infrun needs to do with this bpstat. */
5714 bpstat_what (bpstat bs_head
)
5716 struct bpstat_what retval
;
5720 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5721 retval
.call_dummy
= STOP_NONE
;
5722 retval
.is_longjmp
= 0;
5724 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5726 /* Extract this BS's action. After processing each BS, we check
5727 if its action overrides all we've seem so far. */
5728 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5731 if (bs
->breakpoint_at
== NULL
)
5733 /* I suspect this can happen if it was a momentary
5734 breakpoint which has since been deleted. */
5738 bptype
= bs
->breakpoint_at
->type
;
5745 case bp_hardware_breakpoint
:
5746 case bp_single_step
:
5749 case bp_shlib_event
:
5753 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5755 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5758 this_action
= BPSTAT_WHAT_SINGLE
;
5761 case bp_hardware_watchpoint
:
5762 case bp_read_watchpoint
:
5763 case bp_access_watchpoint
:
5767 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5769 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5773 /* There was a watchpoint, but we're not stopping.
5774 This requires no further action. */
5778 case bp_longjmp_call_dummy
:
5782 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5783 retval
.is_longjmp
= bptype
!= bp_exception
;
5786 this_action
= BPSTAT_WHAT_SINGLE
;
5788 case bp_longjmp_resume
:
5789 case bp_exception_resume
:
5792 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5793 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5796 this_action
= BPSTAT_WHAT_SINGLE
;
5798 case bp_step_resume
:
5800 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5803 /* It is for the wrong frame. */
5804 this_action
= BPSTAT_WHAT_SINGLE
;
5807 case bp_hp_step_resume
:
5809 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5812 /* It is for the wrong frame. */
5813 this_action
= BPSTAT_WHAT_SINGLE
;
5816 case bp_watchpoint_scope
:
5817 case bp_thread_event
:
5818 case bp_overlay_event
:
5819 case bp_longjmp_master
:
5820 case bp_std_terminate_master
:
5821 case bp_exception_master
:
5822 this_action
= BPSTAT_WHAT_SINGLE
;
5828 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5830 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5834 /* There was a catchpoint, but we're not stopping.
5835 This requires no further action. */
5840 this_action
= BPSTAT_WHAT_SINGLE
;
5843 /* Make sure the action is stop (silent or noisy),
5844 so infrun.c pops the dummy frame. */
5845 retval
.call_dummy
= STOP_STACK_DUMMY
;
5846 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5848 case bp_std_terminate
:
5849 /* Make sure the action is stop (silent or noisy),
5850 so infrun.c pops the dummy frame. */
5851 retval
.call_dummy
= STOP_STD_TERMINATE
;
5852 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5855 case bp_fast_tracepoint
:
5856 case bp_static_tracepoint
:
5857 /* Tracepoint hits should not be reported back to GDB, and
5858 if one got through somehow, it should have been filtered
5860 internal_error (__FILE__
, __LINE__
,
5861 _("bpstat_what: tracepoint encountered"));
5863 case bp_gnu_ifunc_resolver
:
5864 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5865 this_action
= BPSTAT_WHAT_SINGLE
;
5867 case bp_gnu_ifunc_resolver_return
:
5868 /* The breakpoint will be removed, execution will restart from the
5869 PC of the former breakpoint. */
5870 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5875 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5877 this_action
= BPSTAT_WHAT_SINGLE
;
5881 internal_error (__FILE__
, __LINE__
,
5882 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5885 retval
.main_action
= max (retval
.main_action
, this_action
);
5888 /* These operations may affect the bs->breakpoint_at state so they are
5889 delayed after MAIN_ACTION is decided above. */
5894 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5896 handle_jit_event ();
5899 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5901 struct breakpoint
*b
= bs
->breakpoint_at
;
5907 case bp_gnu_ifunc_resolver
:
5908 gnu_ifunc_resolver_stop (b
);
5910 case bp_gnu_ifunc_resolver_return
:
5911 gnu_ifunc_resolver_return_stop (b
);
5919 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5920 without hardware support). This isn't related to a specific bpstat,
5921 just to things like whether watchpoints are set. */
5924 bpstat_should_step (void)
5926 struct breakpoint
*b
;
5929 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5935 bpstat_causes_stop (bpstat bs
)
5937 for (; bs
!= NULL
; bs
= bs
->next
)
5946 /* Compute a string of spaces suitable to indent the next line
5947 so it starts at the position corresponding to the table column
5948 named COL_NAME in the currently active table of UIOUT. */
5951 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5953 static char wrap_indent
[80];
5954 int i
, total_width
, width
, align
;
5958 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5960 if (strcmp (text
, col_name
) == 0)
5962 gdb_assert (total_width
< sizeof wrap_indent
);
5963 memset (wrap_indent
, ' ', total_width
);
5964 wrap_indent
[total_width
] = 0;
5969 total_width
+= width
+ 1;
5975 /* Determine if the locations of this breakpoint will have their conditions
5976 evaluated by the target, host or a mix of both. Returns the following:
5978 "host": Host evals condition.
5979 "host or target": Host or Target evals condition.
5980 "target": Target evals condition.
5984 bp_condition_evaluator (struct breakpoint
*b
)
5986 struct bp_location
*bl
;
5987 char host_evals
= 0;
5988 char target_evals
= 0;
5993 if (!is_breakpoint (b
))
5996 if (gdb_evaluates_breakpoint_condition_p ()
5997 || !target_supports_evaluation_of_breakpoint_conditions ())
5998 return condition_evaluation_host
;
6000 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6002 if (bl
->cond_bytecode
)
6008 if (host_evals
&& target_evals
)
6009 return condition_evaluation_both
;
6010 else if (target_evals
)
6011 return condition_evaluation_target
;
6013 return condition_evaluation_host
;
6016 /* Determine the breakpoint location's condition evaluator. This is
6017 similar to bp_condition_evaluator, but for locations. */
6020 bp_location_condition_evaluator (struct bp_location
*bl
)
6022 if (bl
&& !is_breakpoint (bl
->owner
))
6025 if (gdb_evaluates_breakpoint_condition_p ()
6026 || !target_supports_evaluation_of_breakpoint_conditions ())
6027 return condition_evaluation_host
;
6029 if (bl
&& bl
->cond_bytecode
)
6030 return condition_evaluation_target
;
6032 return condition_evaluation_host
;
6035 /* Print the LOC location out of the list of B->LOC locations. */
6038 print_breakpoint_location (struct breakpoint
*b
,
6039 struct bp_location
*loc
)
6041 struct ui_out
*uiout
= current_uiout
;
6042 struct cleanup
*old_chain
= save_current_program_space ();
6044 if (loc
!= NULL
&& loc
->shlib_disabled
)
6048 set_current_program_space (loc
->pspace
);
6050 if (b
->display_canonical
)
6051 ui_out_field_string (uiout
, "what",
6052 event_location_to_string (b
->location
));
6053 else if (loc
&& loc
->symtab
)
6056 = find_pc_sect_function (loc
->address
, loc
->section
);
6059 ui_out_text (uiout
, "in ");
6060 ui_out_field_string (uiout
, "func",
6061 SYMBOL_PRINT_NAME (sym
));
6062 ui_out_text (uiout
, " ");
6063 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
6064 ui_out_text (uiout
, "at ");
6066 ui_out_field_string (uiout
, "file",
6067 symtab_to_filename_for_display (loc
->symtab
));
6068 ui_out_text (uiout
, ":");
6070 if (ui_out_is_mi_like_p (uiout
))
6071 ui_out_field_string (uiout
, "fullname",
6072 symtab_to_fullname (loc
->symtab
));
6074 ui_out_field_int (uiout
, "line", loc
->line_number
);
6078 struct ui_file
*stb
= mem_fileopen ();
6079 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
6081 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
6083 ui_out_field_stream (uiout
, "at", stb
);
6085 do_cleanups (stb_chain
);
6089 ui_out_field_string (uiout
, "pending",
6090 event_location_to_string (b
->location
));
6091 /* If extra_string is available, it could be holding a condition
6092 or dprintf arguments. In either case, make sure it is printed,
6093 too, but only for non-MI streams. */
6094 if (!ui_out_is_mi_like_p (uiout
) && b
->extra_string
!= NULL
)
6096 if (b
->type
== bp_dprintf
)
6097 ui_out_text (uiout
, ",");
6099 ui_out_text (uiout
, " ");
6100 ui_out_text (uiout
, b
->extra_string
);
6104 if (loc
&& is_breakpoint (b
)
6105 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6106 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6108 ui_out_text (uiout
, " (");
6109 ui_out_field_string (uiout
, "evaluated-by",
6110 bp_location_condition_evaluator (loc
));
6111 ui_out_text (uiout
, ")");
6114 do_cleanups (old_chain
);
6118 bptype_string (enum bptype type
)
6120 struct ep_type_description
6125 static struct ep_type_description bptypes
[] =
6127 {bp_none
, "?deleted?"},
6128 {bp_breakpoint
, "breakpoint"},
6129 {bp_hardware_breakpoint
, "hw breakpoint"},
6130 {bp_single_step
, "sw single-step"},
6131 {bp_until
, "until"},
6132 {bp_finish
, "finish"},
6133 {bp_watchpoint
, "watchpoint"},
6134 {bp_hardware_watchpoint
, "hw watchpoint"},
6135 {bp_read_watchpoint
, "read watchpoint"},
6136 {bp_access_watchpoint
, "acc watchpoint"},
6137 {bp_longjmp
, "longjmp"},
6138 {bp_longjmp_resume
, "longjmp resume"},
6139 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6140 {bp_exception
, "exception"},
6141 {bp_exception_resume
, "exception resume"},
6142 {bp_step_resume
, "step resume"},
6143 {bp_hp_step_resume
, "high-priority step resume"},
6144 {bp_watchpoint_scope
, "watchpoint scope"},
6145 {bp_call_dummy
, "call dummy"},
6146 {bp_std_terminate
, "std::terminate"},
6147 {bp_shlib_event
, "shlib events"},
6148 {bp_thread_event
, "thread events"},
6149 {bp_overlay_event
, "overlay events"},
6150 {bp_longjmp_master
, "longjmp master"},
6151 {bp_std_terminate_master
, "std::terminate master"},
6152 {bp_exception_master
, "exception master"},
6153 {bp_catchpoint
, "catchpoint"},
6154 {bp_tracepoint
, "tracepoint"},
6155 {bp_fast_tracepoint
, "fast tracepoint"},
6156 {bp_static_tracepoint
, "static tracepoint"},
6157 {bp_dprintf
, "dprintf"},
6158 {bp_jit_event
, "jit events"},
6159 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6160 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6163 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6164 || ((int) type
!= bptypes
[(int) type
].type
))
6165 internal_error (__FILE__
, __LINE__
,
6166 _("bptypes table does not describe type #%d."),
6169 return bptypes
[(int) type
].description
;
6172 /* For MI, output a field named 'thread-groups' with a list as the value.
6173 For CLI, prefix the list with the string 'inf'. */
6176 output_thread_groups (struct ui_out
*uiout
,
6177 const char *field_name
,
6181 struct cleanup
*back_to
;
6182 int is_mi
= ui_out_is_mi_like_p (uiout
);
6186 /* For backward compatibility, don't display inferiors in CLI unless
6187 there are several. Always display them for MI. */
6188 if (!is_mi
&& mi_only
)
6191 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
6193 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6199 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6200 ui_out_field_string (uiout
, NULL
, mi_group
);
6205 ui_out_text (uiout
, " inf ");
6207 ui_out_text (uiout
, ", ");
6209 ui_out_text (uiout
, plongest (inf
));
6213 do_cleanups (back_to
);
6216 /* Print B to gdb_stdout. */
6219 print_one_breakpoint_location (struct breakpoint
*b
,
6220 struct bp_location
*loc
,
6222 struct bp_location
**last_loc
,
6225 struct command_line
*l
;
6226 static char bpenables
[] = "nynny";
6228 struct ui_out
*uiout
= current_uiout
;
6229 int header_of_multiple
= 0;
6230 int part_of_multiple
= (loc
!= NULL
);
6231 struct value_print_options opts
;
6233 get_user_print_options (&opts
);
6235 gdb_assert (!loc
|| loc_number
!= 0);
6236 /* See comment in print_one_breakpoint concerning treatment of
6237 breakpoints with single disabled location. */
6240 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6241 header_of_multiple
= 1;
6249 if (part_of_multiple
)
6252 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6253 ui_out_field_string (uiout
, "number", formatted
);
6258 ui_out_field_int (uiout
, "number", b
->number
);
6263 if (part_of_multiple
)
6264 ui_out_field_skip (uiout
, "type");
6266 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
6270 if (part_of_multiple
)
6271 ui_out_field_skip (uiout
, "disp");
6273 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6278 if (part_of_multiple
)
6279 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
6281 ui_out_field_fmt (uiout
, "enabled", "%c",
6282 bpenables
[(int) b
->enable_state
]);
6283 ui_out_spaces (uiout
, 2);
6287 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6289 /* Although the print_one can possibly print all locations,
6290 calling it here is not likely to get any nice result. So,
6291 make sure there's just one location. */
6292 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6293 b
->ops
->print_one (b
, last_loc
);
6299 internal_error (__FILE__
, __LINE__
,
6300 _("print_one_breakpoint: bp_none encountered\n"));
6304 case bp_hardware_watchpoint
:
6305 case bp_read_watchpoint
:
6306 case bp_access_watchpoint
:
6308 struct watchpoint
*w
= (struct watchpoint
*) b
;
6310 /* Field 4, the address, is omitted (which makes the columns
6311 not line up too nicely with the headers, but the effect
6312 is relatively readable). */
6313 if (opts
.addressprint
)
6314 ui_out_field_skip (uiout
, "addr");
6316 ui_out_field_string (uiout
, "what", w
->exp_string
);
6321 case bp_hardware_breakpoint
:
6322 case bp_single_step
:
6326 case bp_longjmp_resume
:
6327 case bp_longjmp_call_dummy
:
6329 case bp_exception_resume
:
6330 case bp_step_resume
:
6331 case bp_hp_step_resume
:
6332 case bp_watchpoint_scope
:
6334 case bp_std_terminate
:
6335 case bp_shlib_event
:
6336 case bp_thread_event
:
6337 case bp_overlay_event
:
6338 case bp_longjmp_master
:
6339 case bp_std_terminate_master
:
6340 case bp_exception_master
:
6342 case bp_fast_tracepoint
:
6343 case bp_static_tracepoint
:
6346 case bp_gnu_ifunc_resolver
:
6347 case bp_gnu_ifunc_resolver_return
:
6348 if (opts
.addressprint
)
6351 if (header_of_multiple
)
6352 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6353 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6354 ui_out_field_string (uiout
, "addr", "<PENDING>");
6356 ui_out_field_core_addr (uiout
, "addr",
6357 loc
->gdbarch
, loc
->address
);
6360 if (!header_of_multiple
)
6361 print_breakpoint_location (b
, loc
);
6368 if (loc
!= NULL
&& !header_of_multiple
)
6370 struct inferior
*inf
;
6371 VEC(int) *inf_num
= NULL
;
6376 if (inf
->pspace
== loc
->pspace
)
6377 VEC_safe_push (int, inf_num
, inf
->num
);
6380 /* For backward compatibility, don't display inferiors in CLI unless
6381 there are several. Always display for MI. */
6383 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6384 && (number_of_program_spaces () > 1
6385 || number_of_inferiors () > 1)
6386 /* LOC is for existing B, it cannot be in
6387 moribund_locations and thus having NULL OWNER. */
6388 && loc
->owner
->type
!= bp_catchpoint
))
6390 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6391 VEC_free (int, inf_num
);
6394 if (!part_of_multiple
)
6396 if (b
->thread
!= -1)
6398 /* FIXME: This seems to be redundant and lost here; see the
6399 "stop only in" line a little further down. */
6400 ui_out_text (uiout
, " thread ");
6401 ui_out_field_int (uiout
, "thread", b
->thread
);
6403 else if (b
->task
!= 0)
6405 ui_out_text (uiout
, " task ");
6406 ui_out_field_int (uiout
, "task", b
->task
);
6410 ui_out_text (uiout
, "\n");
6412 if (!part_of_multiple
)
6413 b
->ops
->print_one_detail (b
, uiout
);
6415 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6418 ui_out_text (uiout
, "\tstop only in stack frame at ");
6419 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6421 ui_out_field_core_addr (uiout
, "frame",
6422 b
->gdbarch
, b
->frame_id
.stack_addr
);
6423 ui_out_text (uiout
, "\n");
6426 if (!part_of_multiple
&& b
->cond_string
)
6429 if (is_tracepoint (b
))
6430 ui_out_text (uiout
, "\ttrace only if ");
6432 ui_out_text (uiout
, "\tstop only if ");
6433 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6435 /* Print whether the target is doing the breakpoint's condition
6436 evaluation. If GDB is doing the evaluation, don't print anything. */
6437 if (is_breakpoint (b
)
6438 && breakpoint_condition_evaluation_mode ()
6439 == condition_evaluation_target
)
6441 ui_out_text (uiout
, " (");
6442 ui_out_field_string (uiout
, "evaluated-by",
6443 bp_condition_evaluator (b
));
6444 ui_out_text (uiout
, " evals)");
6446 ui_out_text (uiout
, "\n");
6449 if (!part_of_multiple
&& b
->thread
!= -1)
6451 /* FIXME should make an annotation for this. */
6452 ui_out_text (uiout
, "\tstop only in thread ");
6453 ui_out_field_int (uiout
, "thread", b
->thread
);
6454 ui_out_text (uiout
, "\n");
6457 if (!part_of_multiple
)
6461 /* FIXME should make an annotation for this. */
6462 if (is_catchpoint (b
))
6463 ui_out_text (uiout
, "\tcatchpoint");
6464 else if (is_tracepoint (b
))
6465 ui_out_text (uiout
, "\ttracepoint");
6467 ui_out_text (uiout
, "\tbreakpoint");
6468 ui_out_text (uiout
, " already hit ");
6469 ui_out_field_int (uiout
, "times", b
->hit_count
);
6470 if (b
->hit_count
== 1)
6471 ui_out_text (uiout
, " time\n");
6473 ui_out_text (uiout
, " times\n");
6477 /* Output the count also if it is zero, but only if this is mi. */
6478 if (ui_out_is_mi_like_p (uiout
))
6479 ui_out_field_int (uiout
, "times", b
->hit_count
);
6483 if (!part_of_multiple
&& b
->ignore_count
)
6486 ui_out_text (uiout
, "\tignore next ");
6487 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6488 ui_out_text (uiout
, " hits\n");
6491 /* Note that an enable count of 1 corresponds to "enable once"
6492 behavior, which is reported by the combination of enablement and
6493 disposition, so we don't need to mention it here. */
6494 if (!part_of_multiple
&& b
->enable_count
> 1)
6497 ui_out_text (uiout
, "\tdisable after ");
6498 /* Tweak the wording to clarify that ignore and enable counts
6499 are distinct, and have additive effect. */
6500 if (b
->ignore_count
)
6501 ui_out_text (uiout
, "additional ");
6503 ui_out_text (uiout
, "next ");
6504 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6505 ui_out_text (uiout
, " hits\n");
6508 if (!part_of_multiple
&& is_tracepoint (b
))
6510 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6512 if (tp
->traceframe_usage
)
6514 ui_out_text (uiout
, "\ttrace buffer usage ");
6515 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6516 ui_out_text (uiout
, " bytes\n");
6520 l
= b
->commands
? b
->commands
->commands
: NULL
;
6521 if (!part_of_multiple
&& l
)
6523 struct cleanup
*script_chain
;
6526 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6527 print_command_lines (uiout
, l
, 4);
6528 do_cleanups (script_chain
);
6531 if (is_tracepoint (b
))
6533 struct tracepoint
*t
= (struct tracepoint
*) b
;
6535 if (!part_of_multiple
&& t
->pass_count
)
6537 annotate_field (10);
6538 ui_out_text (uiout
, "\tpass count ");
6539 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6540 ui_out_text (uiout
, " \n");
6543 /* Don't display it when tracepoint or tracepoint location is
6545 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6547 annotate_field (11);
6549 if (ui_out_is_mi_like_p (uiout
))
6550 ui_out_field_string (uiout
, "installed",
6551 loc
->inserted
? "y" : "n");
6555 ui_out_text (uiout
, "\t");
6557 ui_out_text (uiout
, "\tnot ");
6558 ui_out_text (uiout
, "installed on target\n");
6563 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6565 if (is_watchpoint (b
))
6567 struct watchpoint
*w
= (struct watchpoint
*) b
;
6569 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6571 else if (b
->location
!= NULL
6572 && event_location_to_string (b
->location
) != NULL
)
6573 ui_out_field_string (uiout
, "original-location",
6574 event_location_to_string (b
->location
));
6579 print_one_breakpoint (struct breakpoint
*b
,
6580 struct bp_location
**last_loc
,
6583 struct cleanup
*bkpt_chain
;
6584 struct ui_out
*uiout
= current_uiout
;
6586 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6588 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6589 do_cleanups (bkpt_chain
);
6591 /* If this breakpoint has custom print function,
6592 it's already printed. Otherwise, print individual
6593 locations, if any. */
6594 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6596 /* If breakpoint has a single location that is disabled, we
6597 print it as if it had several locations, since otherwise it's
6598 hard to represent "breakpoint enabled, location disabled"
6601 Note that while hardware watchpoints have several locations
6602 internally, that's not a property exposed to user. */
6604 && !is_hardware_watchpoint (b
)
6605 && (b
->loc
->next
|| !b
->loc
->enabled
))
6607 struct bp_location
*loc
;
6610 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6612 struct cleanup
*inner2
=
6613 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6614 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6615 do_cleanups (inner2
);
6622 breakpoint_address_bits (struct breakpoint
*b
)
6624 int print_address_bits
= 0;
6625 struct bp_location
*loc
;
6627 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6631 /* Software watchpoints that aren't watching memory don't have
6632 an address to print. */
6633 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
6636 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6637 if (addr_bit
> print_address_bits
)
6638 print_address_bits
= addr_bit
;
6641 return print_address_bits
;
6644 struct captured_breakpoint_query_args
6650 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6652 struct captured_breakpoint_query_args
*args
= data
;
6653 struct breakpoint
*b
;
6654 struct bp_location
*dummy_loc
= NULL
;
6658 if (args
->bnum
== b
->number
)
6660 print_one_breakpoint (b
, &dummy_loc
, 0);
6668 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6669 char **error_message
)
6671 struct captured_breakpoint_query_args args
;
6674 /* For the moment we don't trust print_one_breakpoint() to not throw
6676 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6677 error_message
, RETURN_MASK_ALL
) < 0)
6683 /* Return true if this breakpoint was set by the user, false if it is
6684 internal or momentary. */
6687 user_breakpoint_p (struct breakpoint
*b
)
6689 return b
->number
> 0;
6692 /* Print information on user settable breakpoint (watchpoint, etc)
6693 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6694 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6695 FILTER is non-NULL, call it on each breakpoint and only include the
6696 ones for which it returns non-zero. Return the total number of
6697 breakpoints listed. */
6700 breakpoint_1 (char *args
, int allflag
,
6701 int (*filter
) (const struct breakpoint
*))
6703 struct breakpoint
*b
;
6704 struct bp_location
*last_loc
= NULL
;
6705 int nr_printable_breakpoints
;
6706 struct cleanup
*bkpttbl_chain
;
6707 struct value_print_options opts
;
6708 int print_address_bits
= 0;
6709 int print_type_col_width
= 14;
6710 struct ui_out
*uiout
= current_uiout
;
6712 get_user_print_options (&opts
);
6714 /* Compute the number of rows in the table, as well as the size
6715 required for address fields. */
6716 nr_printable_breakpoints
= 0;
6719 /* If we have a filter, only list the breakpoints it accepts. */
6720 if (filter
&& !filter (b
))
6723 /* If we have an "args" string, it is a list of breakpoints to
6724 accept. Skip the others. */
6725 if (args
!= NULL
&& *args
!= '\0')
6727 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6729 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6733 if (allflag
|| user_breakpoint_p (b
))
6735 int addr_bit
, type_len
;
6737 addr_bit
= breakpoint_address_bits (b
);
6738 if (addr_bit
> print_address_bits
)
6739 print_address_bits
= addr_bit
;
6741 type_len
= strlen (bptype_string (b
->type
));
6742 if (type_len
> print_type_col_width
)
6743 print_type_col_width
= type_len
;
6745 nr_printable_breakpoints
++;
6749 if (opts
.addressprint
)
6751 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6752 nr_printable_breakpoints
,
6756 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6757 nr_printable_breakpoints
,
6760 if (nr_printable_breakpoints
> 0)
6761 annotate_breakpoints_headers ();
6762 if (nr_printable_breakpoints
> 0)
6764 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6765 if (nr_printable_breakpoints
> 0)
6767 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6768 "type", "Type"); /* 2 */
6769 if (nr_printable_breakpoints
> 0)
6771 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6772 if (nr_printable_breakpoints
> 0)
6774 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6775 if (opts
.addressprint
)
6777 if (nr_printable_breakpoints
> 0)
6779 if (print_address_bits
<= 32)
6780 ui_out_table_header (uiout
, 10, ui_left
,
6781 "addr", "Address"); /* 5 */
6783 ui_out_table_header (uiout
, 18, ui_left
,
6784 "addr", "Address"); /* 5 */
6786 if (nr_printable_breakpoints
> 0)
6788 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6789 ui_out_table_body (uiout
);
6790 if (nr_printable_breakpoints
> 0)
6791 annotate_breakpoints_table ();
6796 /* If we have a filter, only list the breakpoints it accepts. */
6797 if (filter
&& !filter (b
))
6800 /* If we have an "args" string, it is a list of breakpoints to
6801 accept. Skip the others. */
6803 if (args
!= NULL
&& *args
!= '\0')
6805 if (allflag
) /* maintenance info breakpoint */
6807 if (parse_and_eval_long (args
) != b
->number
)
6810 else /* all others */
6812 if (!number_is_in_list (args
, b
->number
))
6816 /* We only print out user settable breakpoints unless the
6818 if (allflag
|| user_breakpoint_p (b
))
6819 print_one_breakpoint (b
, &last_loc
, allflag
);
6822 do_cleanups (bkpttbl_chain
);
6824 if (nr_printable_breakpoints
== 0)
6826 /* If there's a filter, let the caller decide how to report
6830 if (args
== NULL
|| *args
== '\0')
6831 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6833 ui_out_message (uiout
, 0,
6834 "No breakpoint or watchpoint matching '%s'.\n",
6840 if (last_loc
&& !server_command
)
6841 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6844 /* FIXME? Should this be moved up so that it is only called when
6845 there have been breakpoints? */
6846 annotate_breakpoints_table_end ();
6848 return nr_printable_breakpoints
;
6851 /* Display the value of default-collect in a way that is generally
6852 compatible with the breakpoint list. */
6855 default_collect_info (void)
6857 struct ui_out
*uiout
= current_uiout
;
6859 /* If it has no value (which is frequently the case), say nothing; a
6860 message like "No default-collect." gets in user's face when it's
6862 if (!*default_collect
)
6865 /* The following phrase lines up nicely with per-tracepoint collect
6867 ui_out_text (uiout
, "default collect ");
6868 ui_out_field_string (uiout
, "default-collect", default_collect
);
6869 ui_out_text (uiout
, " \n");
6873 breakpoints_info (char *args
, int from_tty
)
6875 breakpoint_1 (args
, 0, NULL
);
6877 default_collect_info ();
6881 watchpoints_info (char *args
, int from_tty
)
6883 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6884 struct ui_out
*uiout
= current_uiout
;
6886 if (num_printed
== 0)
6888 if (args
== NULL
|| *args
== '\0')
6889 ui_out_message (uiout
, 0, "No watchpoints.\n");
6891 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6896 maintenance_info_breakpoints (char *args
, int from_tty
)
6898 breakpoint_1 (args
, 1, NULL
);
6900 default_collect_info ();
6904 breakpoint_has_pc (struct breakpoint
*b
,
6905 struct program_space
*pspace
,
6906 CORE_ADDR pc
, struct obj_section
*section
)
6908 struct bp_location
*bl
= b
->loc
;
6910 for (; bl
; bl
= bl
->next
)
6912 if (bl
->pspace
== pspace
6913 && bl
->address
== pc
6914 && (!overlay_debugging
|| bl
->section
== section
))
6920 /* Print a message describing any user-breakpoints set at PC. This
6921 concerns with logical breakpoints, so we match program spaces, not
6925 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6926 struct program_space
*pspace
, CORE_ADDR pc
,
6927 struct obj_section
*section
, int thread
)
6930 struct breakpoint
*b
;
6933 others
+= (user_breakpoint_p (b
)
6934 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6938 printf_filtered (_("Note: breakpoint "));
6939 else /* if (others == ???) */
6940 printf_filtered (_("Note: breakpoints "));
6942 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6945 printf_filtered ("%d", b
->number
);
6946 if (b
->thread
== -1 && thread
!= -1)
6947 printf_filtered (" (all threads)");
6948 else if (b
->thread
!= -1)
6949 printf_filtered (" (thread %d)", b
->thread
);
6950 printf_filtered ("%s%s ",
6951 ((b
->enable_state
== bp_disabled
6952 || b
->enable_state
== bp_call_disabled
)
6956 : ((others
== 1) ? " and" : ""));
6958 printf_filtered (_("also set at pc "));
6959 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6960 printf_filtered (".\n");
6965 /* Return true iff it is meaningful to use the address member of
6966 BPT locations. For some breakpoint types, the locations' address members
6967 are irrelevant and it makes no sense to attempt to compare them to other
6968 addresses (or use them for any other purpose either).
6970 More specifically, each of the following breakpoint types will
6971 always have a zero valued location address and we don't want to mark
6972 breakpoints of any of these types to be a duplicate of an actual
6973 breakpoint location at address zero:
6981 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6983 enum bptype type
= bpt
->type
;
6985 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6988 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6989 true if LOC1 and LOC2 represent the same watchpoint location. */
6992 watchpoint_locations_match (struct bp_location
*loc1
,
6993 struct bp_location
*loc2
)
6995 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6996 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6998 /* Both of them must exist. */
6999 gdb_assert (w1
!= NULL
);
7000 gdb_assert (w2
!= NULL
);
7002 /* If the target can evaluate the condition expression in hardware,
7003 then we we need to insert both watchpoints even if they are at
7004 the same place. Otherwise the watchpoint will only trigger when
7005 the condition of whichever watchpoint was inserted evaluates to
7006 true, not giving a chance for GDB to check the condition of the
7007 other watchpoint. */
7009 && target_can_accel_watchpoint_condition (loc1
->address
,
7011 loc1
->watchpoint_type
,
7014 && target_can_accel_watchpoint_condition (loc2
->address
,
7016 loc2
->watchpoint_type
,
7020 /* Note that this checks the owner's type, not the location's. In
7021 case the target does not support read watchpoints, but does
7022 support access watchpoints, we'll have bp_read_watchpoint
7023 watchpoints with hw_access locations. Those should be considered
7024 duplicates of hw_read locations. The hw_read locations will
7025 become hw_access locations later. */
7026 return (loc1
->owner
->type
== loc2
->owner
->type
7027 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7028 && loc1
->address
== loc2
->address
7029 && loc1
->length
== loc2
->length
);
7032 /* See breakpoint.h. */
7035 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
7036 struct address_space
*aspace2
, CORE_ADDR addr2
)
7038 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7039 || aspace1
== aspace2
)
7043 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7044 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7045 matches ASPACE2. On targets that have global breakpoints, the address
7046 space doesn't really matter. */
7049 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7050 int len1
, struct address_space
*aspace2
,
7053 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7054 || aspace1
== aspace2
)
7055 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7058 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7059 a ranged breakpoint. In most targets, a match happens only if ASPACE
7060 matches the breakpoint's address space. On targets that have global
7061 breakpoints, the address space doesn't really matter. */
7064 breakpoint_location_address_match (struct bp_location
*bl
,
7065 struct address_space
*aspace
,
7068 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7071 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7072 bl
->address
, bl
->length
,
7076 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7077 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7078 true, otherwise returns false. */
7081 tracepoint_locations_match (struct bp_location
*loc1
,
7082 struct bp_location
*loc2
)
7084 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7085 /* Since tracepoint locations are never duplicated with others', tracepoint
7086 locations at the same address of different tracepoints are regarded as
7087 different locations. */
7088 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7093 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7094 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7095 represent the same location. */
7098 breakpoint_locations_match (struct bp_location
*loc1
,
7099 struct bp_location
*loc2
)
7101 int hw_point1
, hw_point2
;
7103 /* Both of them must not be in moribund_locations. */
7104 gdb_assert (loc1
->owner
!= NULL
);
7105 gdb_assert (loc2
->owner
!= NULL
);
7107 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7108 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7110 if (hw_point1
!= hw_point2
)
7113 return watchpoint_locations_match (loc1
, loc2
);
7114 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7115 return tracepoint_locations_match (loc1
, loc2
);
7117 /* We compare bp_location.length in order to cover ranged breakpoints. */
7118 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7119 loc2
->pspace
->aspace
, loc2
->address
)
7120 && loc1
->length
== loc2
->length
);
7124 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7125 int bnum
, int have_bnum
)
7127 /* The longest string possibly returned by hex_string_custom
7128 is 50 chars. These must be at least that big for safety. */
7132 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7133 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7135 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7136 bnum
, astr1
, astr2
);
7138 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7141 /* Adjust a breakpoint's address to account for architectural
7142 constraints on breakpoint placement. Return the adjusted address.
7143 Note: Very few targets require this kind of adjustment. For most
7144 targets, this function is simply the identity function. */
7147 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7148 CORE_ADDR bpaddr
, enum bptype bptype
)
7150 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7152 /* Very few targets need any kind of breakpoint adjustment. */
7155 else if (bptype
== bp_watchpoint
7156 || bptype
== bp_hardware_watchpoint
7157 || bptype
== bp_read_watchpoint
7158 || bptype
== bp_access_watchpoint
7159 || bptype
== bp_catchpoint
)
7161 /* Watchpoints and the various bp_catch_* eventpoints should not
7162 have their addresses modified. */
7165 else if (bptype
== bp_single_step
)
7167 /* Single-step breakpoints should not have their addresses
7168 modified. If there's any architectural constrain that
7169 applies to this address, then it should have already been
7170 taken into account when the breakpoint was created in the
7171 first place. If we didn't do this, stepping through e.g.,
7172 Thumb-2 IT blocks would break. */
7177 CORE_ADDR adjusted_bpaddr
;
7179 /* Some targets have architectural constraints on the placement
7180 of breakpoint instructions. Obtain the adjusted address. */
7181 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7183 /* An adjusted breakpoint address can significantly alter
7184 a user's expectations. Print a warning if an adjustment
7186 if (adjusted_bpaddr
!= bpaddr
)
7187 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7189 return adjusted_bpaddr
;
7194 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
7195 struct breakpoint
*owner
)
7197 memset (loc
, 0, sizeof (*loc
));
7199 gdb_assert (ops
!= NULL
);
7204 loc
->cond_bytecode
= NULL
;
7205 loc
->shlib_disabled
= 0;
7208 switch (owner
->type
)
7211 case bp_single_step
:
7215 case bp_longjmp_resume
:
7216 case bp_longjmp_call_dummy
:
7218 case bp_exception_resume
:
7219 case bp_step_resume
:
7220 case bp_hp_step_resume
:
7221 case bp_watchpoint_scope
:
7223 case bp_std_terminate
:
7224 case bp_shlib_event
:
7225 case bp_thread_event
:
7226 case bp_overlay_event
:
7228 case bp_longjmp_master
:
7229 case bp_std_terminate_master
:
7230 case bp_exception_master
:
7231 case bp_gnu_ifunc_resolver
:
7232 case bp_gnu_ifunc_resolver_return
:
7234 loc
->loc_type
= bp_loc_software_breakpoint
;
7235 mark_breakpoint_location_modified (loc
);
7237 case bp_hardware_breakpoint
:
7238 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7239 mark_breakpoint_location_modified (loc
);
7241 case bp_hardware_watchpoint
:
7242 case bp_read_watchpoint
:
7243 case bp_access_watchpoint
:
7244 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7249 case bp_fast_tracepoint
:
7250 case bp_static_tracepoint
:
7251 loc
->loc_type
= bp_loc_other
;
7254 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7260 /* Allocate a struct bp_location. */
7262 static struct bp_location
*
7263 allocate_bp_location (struct breakpoint
*bpt
)
7265 return bpt
->ops
->allocate_location (bpt
);
7269 free_bp_location (struct bp_location
*loc
)
7271 loc
->ops
->dtor (loc
);
7275 /* Increment reference count. */
7278 incref_bp_location (struct bp_location
*bl
)
7283 /* Decrement reference count. If the reference count reaches 0,
7284 destroy the bp_location. Sets *BLP to NULL. */
7287 decref_bp_location (struct bp_location
**blp
)
7289 gdb_assert ((*blp
)->refc
> 0);
7291 if (--(*blp
)->refc
== 0)
7292 free_bp_location (*blp
);
7296 /* Add breakpoint B at the end of the global breakpoint chain. */
7299 add_to_breakpoint_chain (struct breakpoint
*b
)
7301 struct breakpoint
*b1
;
7303 /* Add this breakpoint to the end of the chain so that a list of
7304 breakpoints will come out in order of increasing numbers. */
7306 b1
= breakpoint_chain
;
7308 breakpoint_chain
= b
;
7317 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7320 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7321 struct gdbarch
*gdbarch
,
7323 const struct breakpoint_ops
*ops
)
7325 memset (b
, 0, sizeof (*b
));
7327 gdb_assert (ops
!= NULL
);
7331 b
->gdbarch
= gdbarch
;
7332 b
->language
= current_language
->la_language
;
7333 b
->input_radix
= input_radix
;
7335 b
->enable_state
= bp_enabled
;
7338 b
->ignore_count
= 0;
7340 b
->frame_id
= null_frame_id
;
7341 b
->condition_not_parsed
= 0;
7342 b
->py_bp_object
= NULL
;
7343 b
->related_breakpoint
= b
;
7347 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7348 that has type BPTYPE and has no locations as yet. */
7350 static struct breakpoint
*
7351 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7353 const struct breakpoint_ops
*ops
)
7355 struct breakpoint
*b
= XNEW (struct breakpoint
);
7357 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7358 add_to_breakpoint_chain (b
);
7362 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7363 resolutions should be made as the user specified the location explicitly
7367 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7369 gdb_assert (loc
->owner
!= NULL
);
7371 if (loc
->owner
->type
== bp_breakpoint
7372 || loc
->owner
->type
== bp_hardware_breakpoint
7373 || is_tracepoint (loc
->owner
))
7376 const char *function_name
;
7377 CORE_ADDR func_addr
;
7379 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7380 &func_addr
, NULL
, &is_gnu_ifunc
);
7382 if (is_gnu_ifunc
&& !explicit_loc
)
7384 struct breakpoint
*b
= loc
->owner
;
7386 gdb_assert (loc
->pspace
== current_program_space
);
7387 if (gnu_ifunc_resolve_name (function_name
,
7388 &loc
->requested_address
))
7390 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7391 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7392 loc
->requested_address
,
7395 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7396 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7398 /* Create only the whole new breakpoint of this type but do not
7399 mess more complicated breakpoints with multiple locations. */
7400 b
->type
= bp_gnu_ifunc_resolver
;
7401 /* Remember the resolver's address for use by the return
7403 loc
->related_address
= func_addr
;
7408 loc
->function_name
= xstrdup (function_name
);
7412 /* Attempt to determine architecture of location identified by SAL. */
7414 get_sal_arch (struct symtab_and_line sal
)
7417 return get_objfile_arch (sal
.section
->objfile
);
7419 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7424 /* Low level routine for partially initializing a breakpoint of type
7425 BPTYPE. The newly created breakpoint's address, section, source
7426 file name, and line number are provided by SAL.
7428 It is expected that the caller will complete the initialization of
7429 the newly created breakpoint struct as well as output any status
7430 information regarding the creation of a new breakpoint. */
7433 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7434 struct symtab_and_line sal
, enum bptype bptype
,
7435 const struct breakpoint_ops
*ops
)
7437 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7439 add_location_to_breakpoint (b
, &sal
);
7441 if (bptype
!= bp_catchpoint
)
7442 gdb_assert (sal
.pspace
!= NULL
);
7444 /* Store the program space that was used to set the breakpoint,
7445 except for ordinary breakpoints, which are independent of the
7447 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7448 b
->pspace
= sal
.pspace
;
7451 /* set_raw_breakpoint is a low level routine for allocating and
7452 partially initializing a breakpoint of type BPTYPE. The newly
7453 created breakpoint's address, section, source file name, and line
7454 number are provided by SAL. The newly created and partially
7455 initialized breakpoint is added to the breakpoint chain and
7456 is also returned as the value of this function.
7458 It is expected that the caller will complete the initialization of
7459 the newly created breakpoint struct as well as output any status
7460 information regarding the creation of a new breakpoint. In
7461 particular, set_raw_breakpoint does NOT set the breakpoint
7462 number! Care should be taken to not allow an error to occur
7463 prior to completing the initialization of the breakpoint. If this
7464 should happen, a bogus breakpoint will be left on the chain. */
7467 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7468 struct symtab_and_line sal
, enum bptype bptype
,
7469 const struct breakpoint_ops
*ops
)
7471 struct breakpoint
*b
= XNEW (struct breakpoint
);
7473 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7474 add_to_breakpoint_chain (b
);
7478 /* Call this routine when stepping and nexting to enable a breakpoint
7479 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7480 initiated the operation. */
7483 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7485 struct breakpoint
*b
, *b_tmp
;
7486 int thread
= tp
->num
;
7488 /* To avoid having to rescan all objfile symbols at every step,
7489 we maintain a list of continually-inserted but always disabled
7490 longjmp "master" breakpoints. Here, we simply create momentary
7491 clones of those and enable them for the requested thread. */
7492 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7493 if (b
->pspace
== current_program_space
7494 && (b
->type
== bp_longjmp_master
7495 || b
->type
== bp_exception_master
))
7497 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7498 struct breakpoint
*clone
;
7500 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7501 after their removal. */
7502 clone
= momentary_breakpoint_from_master (b
, type
,
7503 &longjmp_breakpoint_ops
, 1);
7504 clone
->thread
= thread
;
7507 tp
->initiating_frame
= frame
;
7510 /* Delete all longjmp breakpoints from THREAD. */
7512 delete_longjmp_breakpoint (int thread
)
7514 struct breakpoint
*b
, *b_tmp
;
7516 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7517 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7519 if (b
->thread
== thread
)
7520 delete_breakpoint (b
);
7525 delete_longjmp_breakpoint_at_next_stop (int thread
)
7527 struct breakpoint
*b
, *b_tmp
;
7529 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7530 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7532 if (b
->thread
== thread
)
7533 b
->disposition
= disp_del_at_next_stop
;
7537 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7538 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7539 pointer to any of them. Return NULL if this system cannot place longjmp
7543 set_longjmp_breakpoint_for_call_dummy (void)
7545 struct breakpoint
*b
, *retval
= NULL
;
7548 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7550 struct breakpoint
*new_b
;
7552 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7553 &momentary_breakpoint_ops
,
7555 new_b
->thread
= pid_to_thread_id (inferior_ptid
);
7557 /* Link NEW_B into the chain of RETVAL breakpoints. */
7559 gdb_assert (new_b
->related_breakpoint
== new_b
);
7562 new_b
->related_breakpoint
= retval
;
7563 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7564 retval
= retval
->related_breakpoint
;
7565 retval
->related_breakpoint
= new_b
;
7571 /* Verify all existing dummy frames and their associated breakpoints for
7572 TP. Remove those which can no longer be found in the current frame
7575 You should call this function only at places where it is safe to currently
7576 unwind the whole stack. Failed stack unwind would discard live dummy
7580 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7582 struct breakpoint
*b
, *b_tmp
;
7584 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7585 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->num
)
7587 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7589 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7590 dummy_b
= dummy_b
->related_breakpoint
;
7591 if (dummy_b
->type
!= bp_call_dummy
7592 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7595 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7597 while (b
->related_breakpoint
!= b
)
7599 if (b_tmp
== b
->related_breakpoint
)
7600 b_tmp
= b
->related_breakpoint
->next
;
7601 delete_breakpoint (b
->related_breakpoint
);
7603 delete_breakpoint (b
);
7608 enable_overlay_breakpoints (void)
7610 struct breakpoint
*b
;
7613 if (b
->type
== bp_overlay_event
)
7615 b
->enable_state
= bp_enabled
;
7616 update_global_location_list (UGLL_MAY_INSERT
);
7617 overlay_events_enabled
= 1;
7622 disable_overlay_breakpoints (void)
7624 struct breakpoint
*b
;
7627 if (b
->type
== bp_overlay_event
)
7629 b
->enable_state
= bp_disabled
;
7630 update_global_location_list (UGLL_DONT_INSERT
);
7631 overlay_events_enabled
= 0;
7635 /* Set an active std::terminate breakpoint for each std::terminate
7636 master breakpoint. */
7638 set_std_terminate_breakpoint (void)
7640 struct breakpoint
*b
, *b_tmp
;
7642 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7643 if (b
->pspace
== current_program_space
7644 && b
->type
== bp_std_terminate_master
)
7646 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7647 &momentary_breakpoint_ops
, 1);
7651 /* Delete all the std::terminate breakpoints. */
7653 delete_std_terminate_breakpoint (void)
7655 struct breakpoint
*b
, *b_tmp
;
7657 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7658 if (b
->type
== bp_std_terminate
)
7659 delete_breakpoint (b
);
7663 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7665 struct breakpoint
*b
;
7667 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7668 &internal_breakpoint_ops
);
7670 b
->enable_state
= bp_enabled
;
7671 /* location has to be used or breakpoint_re_set will delete me. */
7672 b
->location
= new_address_location (b
->loc
->address
);
7674 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7680 remove_thread_event_breakpoints (void)
7682 struct breakpoint
*b
, *b_tmp
;
7684 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7685 if (b
->type
== bp_thread_event
7686 && b
->loc
->pspace
== current_program_space
)
7687 delete_breakpoint (b
);
7690 struct lang_and_radix
7696 /* Create a breakpoint for JIT code registration and unregistration. */
7699 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7701 struct breakpoint
*b
;
7703 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7704 &internal_breakpoint_ops
);
7705 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7709 /* Remove JIT code registration and unregistration breakpoint(s). */
7712 remove_jit_event_breakpoints (void)
7714 struct breakpoint
*b
, *b_tmp
;
7716 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7717 if (b
->type
== bp_jit_event
7718 && b
->loc
->pspace
== current_program_space
)
7719 delete_breakpoint (b
);
7723 remove_solib_event_breakpoints (void)
7725 struct breakpoint
*b
, *b_tmp
;
7727 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7728 if (b
->type
== bp_shlib_event
7729 && b
->loc
->pspace
== current_program_space
)
7730 delete_breakpoint (b
);
7733 /* See breakpoint.h. */
7736 remove_solib_event_breakpoints_at_next_stop (void)
7738 struct breakpoint
*b
, *b_tmp
;
7740 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7741 if (b
->type
== bp_shlib_event
7742 && b
->loc
->pspace
== current_program_space
)
7743 b
->disposition
= disp_del_at_next_stop
;
7746 /* Helper for create_solib_event_breakpoint /
7747 create_and_insert_solib_event_breakpoint. Allows specifying which
7748 INSERT_MODE to pass through to update_global_location_list. */
7750 static struct breakpoint
*
7751 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7752 enum ugll_insert_mode insert_mode
)
7754 struct breakpoint
*b
;
7756 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7757 &internal_breakpoint_ops
);
7758 update_global_location_list_nothrow (insert_mode
);
7763 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7765 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7768 /* See breakpoint.h. */
7771 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7773 struct breakpoint
*b
;
7775 /* Explicitly tell update_global_location_list to insert
7777 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7778 if (!b
->loc
->inserted
)
7780 delete_breakpoint (b
);
7786 /* Disable any breakpoints that are on code in shared libraries. Only
7787 apply to enabled breakpoints, disabled ones can just stay disabled. */
7790 disable_breakpoints_in_shlibs (void)
7792 struct bp_location
*loc
, **locp_tmp
;
7794 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7796 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7797 struct breakpoint
*b
= loc
->owner
;
7799 /* We apply the check to all breakpoints, including disabled for
7800 those with loc->duplicate set. This is so that when breakpoint
7801 becomes enabled, or the duplicate is removed, gdb will try to
7802 insert all breakpoints. If we don't set shlib_disabled here,
7803 we'll try to insert those breakpoints and fail. */
7804 if (((b
->type
== bp_breakpoint
)
7805 || (b
->type
== bp_jit_event
)
7806 || (b
->type
== bp_hardware_breakpoint
)
7807 || (is_tracepoint (b
)))
7808 && loc
->pspace
== current_program_space
7809 && !loc
->shlib_disabled
7810 && solib_name_from_address (loc
->pspace
, loc
->address
)
7813 loc
->shlib_disabled
= 1;
7818 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7819 notification of unloaded_shlib. Only apply to enabled breakpoints,
7820 disabled ones can just stay disabled. */
7823 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7825 struct bp_location
*loc
, **locp_tmp
;
7826 int disabled_shlib_breaks
= 0;
7828 /* SunOS a.out shared libraries are always mapped, so do not
7829 disable breakpoints; they will only be reported as unloaded
7830 through clear_solib when GDB discards its shared library
7831 list. See clear_solib for more information. */
7832 if (exec_bfd
!= NULL
7833 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7836 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7838 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7839 struct breakpoint
*b
= loc
->owner
;
7841 if (solib
->pspace
== loc
->pspace
7842 && !loc
->shlib_disabled
7843 && (((b
->type
== bp_breakpoint
7844 || b
->type
== bp_jit_event
7845 || b
->type
== bp_hardware_breakpoint
)
7846 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7847 || loc
->loc_type
== bp_loc_software_breakpoint
))
7848 || is_tracepoint (b
))
7849 && solib_contains_address_p (solib
, loc
->address
))
7851 loc
->shlib_disabled
= 1;
7852 /* At this point, we cannot rely on remove_breakpoint
7853 succeeding so we must mark the breakpoint as not inserted
7854 to prevent future errors occurring in remove_breakpoints. */
7857 /* This may cause duplicate notifications for the same breakpoint. */
7858 observer_notify_breakpoint_modified (b
);
7860 if (!disabled_shlib_breaks
)
7862 target_terminal_ours_for_output ();
7863 warning (_("Temporarily disabling breakpoints "
7864 "for unloaded shared library \"%s\""),
7867 disabled_shlib_breaks
= 1;
7872 /* Disable any breakpoints and tracepoints in OBJFILE upon
7873 notification of free_objfile. Only apply to enabled breakpoints,
7874 disabled ones can just stay disabled. */
7877 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7879 struct breakpoint
*b
;
7881 if (objfile
== NULL
)
7884 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7885 managed by the user with add-symbol-file/remove-symbol-file.
7886 Similarly to how breakpoints in shared libraries are handled in
7887 response to "nosharedlibrary", mark breakpoints in such modules
7888 shlib_disabled so they end up uninserted on the next global
7889 location list update. Shared libraries not loaded by the user
7890 aren't handled here -- they're already handled in
7891 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7892 solib_unloaded observer. We skip objfiles that are not
7893 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7895 if ((objfile
->flags
& OBJF_SHARED
) == 0
7896 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7901 struct bp_location
*loc
;
7902 int bp_modified
= 0;
7904 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7907 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7909 CORE_ADDR loc_addr
= loc
->address
;
7911 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7912 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7915 if (loc
->shlib_disabled
!= 0)
7918 if (objfile
->pspace
!= loc
->pspace
)
7921 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7922 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7925 if (is_addr_in_objfile (loc_addr
, objfile
))
7927 loc
->shlib_disabled
= 1;
7928 /* At this point, we don't know whether the object was
7929 unmapped from the inferior or not, so leave the
7930 inserted flag alone. We'll handle failure to
7931 uninsert quietly, in case the object was indeed
7934 mark_breakpoint_location_modified (loc
);
7941 observer_notify_breakpoint_modified (b
);
7945 /* FORK & VFORK catchpoints. */
7947 /* An instance of this type is used to represent a fork or vfork
7948 catchpoint. It includes a "struct breakpoint" as a kind of base
7949 class; users downcast to "struct breakpoint *" when needed. A
7950 breakpoint is really of this type iff its ops pointer points to
7951 CATCH_FORK_BREAKPOINT_OPS. */
7953 struct fork_catchpoint
7955 /* The base class. */
7956 struct breakpoint base
;
7958 /* Process id of a child process whose forking triggered this
7959 catchpoint. This field is only valid immediately after this
7960 catchpoint has triggered. */
7961 ptid_t forked_inferior_pid
;
7964 /* Implement the "insert" breakpoint_ops method for fork
7968 insert_catch_fork (struct bp_location
*bl
)
7970 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7973 /* Implement the "remove" breakpoint_ops method for fork
7977 remove_catch_fork (struct bp_location
*bl
)
7979 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7982 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7986 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7987 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7988 const struct target_waitstatus
*ws
)
7990 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7992 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7995 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7999 /* Implement the "print_it" breakpoint_ops method for fork
8002 static enum print_stop_action
8003 print_it_catch_fork (bpstat bs
)
8005 struct ui_out
*uiout
= current_uiout
;
8006 struct breakpoint
*b
= bs
->breakpoint_at
;
8007 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
8009 annotate_catchpoint (b
->number
);
8010 if (b
->disposition
== disp_del
)
8011 ui_out_text (uiout
, "\nTemporary catchpoint ");
8013 ui_out_text (uiout
, "\nCatchpoint ");
8014 if (ui_out_is_mi_like_p (uiout
))
8016 ui_out_field_string (uiout
, "reason",
8017 async_reason_lookup (EXEC_ASYNC_FORK
));
8018 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8020 ui_out_field_int (uiout
, "bkptno", b
->number
);
8021 ui_out_text (uiout
, " (forked process ");
8022 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8023 ui_out_text (uiout
, "), ");
8024 return PRINT_SRC_AND_LOC
;
8027 /* Implement the "print_one" breakpoint_ops method for fork
8031 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8033 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8034 struct value_print_options opts
;
8035 struct ui_out
*uiout
= current_uiout
;
8037 get_user_print_options (&opts
);
8039 /* Field 4, the address, is omitted (which makes the columns not
8040 line up too nicely with the headers, but the effect is relatively
8042 if (opts
.addressprint
)
8043 ui_out_field_skip (uiout
, "addr");
8045 ui_out_text (uiout
, "fork");
8046 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8048 ui_out_text (uiout
, ", process ");
8049 ui_out_field_int (uiout
, "what",
8050 ptid_get_pid (c
->forked_inferior_pid
));
8051 ui_out_spaces (uiout
, 1);
8054 if (ui_out_is_mi_like_p (uiout
))
8055 ui_out_field_string (uiout
, "catch-type", "fork");
8058 /* Implement the "print_mention" breakpoint_ops method for fork
8062 print_mention_catch_fork (struct breakpoint
*b
)
8064 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8067 /* Implement the "print_recreate" breakpoint_ops method for fork
8071 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8073 fprintf_unfiltered (fp
, "catch fork");
8074 print_recreate_thread (b
, fp
);
8077 /* The breakpoint_ops structure to be used in fork catchpoints. */
8079 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8081 /* Implement the "insert" breakpoint_ops method for vfork
8085 insert_catch_vfork (struct bp_location
*bl
)
8087 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8090 /* Implement the "remove" breakpoint_ops method for vfork
8094 remove_catch_vfork (struct bp_location
*bl
)
8096 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8099 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8103 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8104 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8105 const struct target_waitstatus
*ws
)
8107 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8109 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8112 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8116 /* Implement the "print_it" breakpoint_ops method for vfork
8119 static enum print_stop_action
8120 print_it_catch_vfork (bpstat bs
)
8122 struct ui_out
*uiout
= current_uiout
;
8123 struct breakpoint
*b
= bs
->breakpoint_at
;
8124 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8126 annotate_catchpoint (b
->number
);
8127 if (b
->disposition
== disp_del
)
8128 ui_out_text (uiout
, "\nTemporary catchpoint ");
8130 ui_out_text (uiout
, "\nCatchpoint ");
8131 if (ui_out_is_mi_like_p (uiout
))
8133 ui_out_field_string (uiout
, "reason",
8134 async_reason_lookup (EXEC_ASYNC_VFORK
));
8135 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8137 ui_out_field_int (uiout
, "bkptno", b
->number
);
8138 ui_out_text (uiout
, " (vforked process ");
8139 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8140 ui_out_text (uiout
, "), ");
8141 return PRINT_SRC_AND_LOC
;
8144 /* Implement the "print_one" breakpoint_ops method for vfork
8148 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8150 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8151 struct value_print_options opts
;
8152 struct ui_out
*uiout
= current_uiout
;
8154 get_user_print_options (&opts
);
8155 /* Field 4, the address, is omitted (which makes the columns not
8156 line up too nicely with the headers, but the effect is relatively
8158 if (opts
.addressprint
)
8159 ui_out_field_skip (uiout
, "addr");
8161 ui_out_text (uiout
, "vfork");
8162 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8164 ui_out_text (uiout
, ", process ");
8165 ui_out_field_int (uiout
, "what",
8166 ptid_get_pid (c
->forked_inferior_pid
));
8167 ui_out_spaces (uiout
, 1);
8170 if (ui_out_is_mi_like_p (uiout
))
8171 ui_out_field_string (uiout
, "catch-type", "vfork");
8174 /* Implement the "print_mention" breakpoint_ops method for vfork
8178 print_mention_catch_vfork (struct breakpoint
*b
)
8180 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8183 /* Implement the "print_recreate" breakpoint_ops method for vfork
8187 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8189 fprintf_unfiltered (fp
, "catch vfork");
8190 print_recreate_thread (b
, fp
);
8193 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8195 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8197 /* An instance of this type is used to represent an solib catchpoint.
8198 It includes a "struct breakpoint" as a kind of base class; users
8199 downcast to "struct breakpoint *" when needed. A breakpoint is
8200 really of this type iff its ops pointer points to
8201 CATCH_SOLIB_BREAKPOINT_OPS. */
8203 struct solib_catchpoint
8205 /* The base class. */
8206 struct breakpoint base
;
8208 /* True for "catch load", false for "catch unload". */
8209 unsigned char is_load
;
8211 /* Regular expression to match, if any. COMPILED is only valid when
8212 REGEX is non-NULL. */
8218 dtor_catch_solib (struct breakpoint
*b
)
8220 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8223 regfree (&self
->compiled
);
8224 xfree (self
->regex
);
8226 base_breakpoint_ops
.dtor (b
);
8230 insert_catch_solib (struct bp_location
*ignore
)
8236 remove_catch_solib (struct bp_location
*ignore
)
8242 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8243 struct address_space
*aspace
,
8245 const struct target_waitstatus
*ws
)
8247 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8248 struct breakpoint
*other
;
8250 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8253 ALL_BREAKPOINTS (other
)
8255 struct bp_location
*other_bl
;
8257 if (other
== bl
->owner
)
8260 if (other
->type
!= bp_shlib_event
)
8263 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8266 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8268 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8277 check_status_catch_solib (struct bpstats
*bs
)
8279 struct solib_catchpoint
*self
8280 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8285 struct so_list
*iter
;
8288 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8293 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8302 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8307 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8313 bs
->print_it
= print_it_noop
;
8316 static enum print_stop_action
8317 print_it_catch_solib (bpstat bs
)
8319 struct breakpoint
*b
= bs
->breakpoint_at
;
8320 struct ui_out
*uiout
= current_uiout
;
8322 annotate_catchpoint (b
->number
);
8323 if (b
->disposition
== disp_del
)
8324 ui_out_text (uiout
, "\nTemporary catchpoint ");
8326 ui_out_text (uiout
, "\nCatchpoint ");
8327 ui_out_field_int (uiout
, "bkptno", b
->number
);
8328 ui_out_text (uiout
, "\n");
8329 if (ui_out_is_mi_like_p (uiout
))
8330 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8331 print_solib_event (1);
8332 return PRINT_SRC_AND_LOC
;
8336 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8338 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8339 struct value_print_options opts
;
8340 struct ui_out
*uiout
= current_uiout
;
8343 get_user_print_options (&opts
);
8344 /* Field 4, the address, is omitted (which makes the columns not
8345 line up too nicely with the headers, but the effect is relatively
8347 if (opts
.addressprint
)
8350 ui_out_field_skip (uiout
, "addr");
8357 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8359 msg
= xstrdup (_("load of library"));
8364 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8366 msg
= xstrdup (_("unload of library"));
8368 ui_out_field_string (uiout
, "what", msg
);
8371 if (ui_out_is_mi_like_p (uiout
))
8372 ui_out_field_string (uiout
, "catch-type",
8373 self
->is_load
? "load" : "unload");
8377 print_mention_catch_solib (struct breakpoint
*b
)
8379 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8381 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8382 self
->is_load
? "load" : "unload");
8386 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8388 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8390 fprintf_unfiltered (fp
, "%s %s",
8391 b
->disposition
== disp_del
? "tcatch" : "catch",
8392 self
->is_load
? "load" : "unload");
8394 fprintf_unfiltered (fp
, " %s", self
->regex
);
8395 fprintf_unfiltered (fp
, "\n");
8398 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8400 /* Shared helper function (MI and CLI) for creating and installing
8401 a shared object event catchpoint. If IS_LOAD is non-zero then
8402 the events to be caught are load events, otherwise they are
8403 unload events. If IS_TEMP is non-zero the catchpoint is a
8404 temporary one. If ENABLED is non-zero the catchpoint is
8405 created in an enabled state. */
8408 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8410 struct solib_catchpoint
*c
;
8411 struct gdbarch
*gdbarch
= get_current_arch ();
8412 struct cleanup
*cleanup
;
8416 arg
= skip_spaces (arg
);
8418 c
= XCNEW (struct solib_catchpoint
);
8419 cleanup
= make_cleanup (xfree
, c
);
8425 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8428 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8430 make_cleanup (xfree
, err
);
8431 error (_("Invalid regexp (%s): %s"), err
, arg
);
8433 c
->regex
= xstrdup (arg
);
8436 c
->is_load
= is_load
;
8437 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8438 &catch_solib_breakpoint_ops
);
8440 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8442 discard_cleanups (cleanup
);
8443 install_breakpoint (0, &c
->base
, 1);
8446 /* A helper function that does all the work for "catch load" and
8450 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8451 struct cmd_list_element
*command
)
8454 const int enabled
= 1;
8456 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8458 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8462 catch_load_command_1 (char *arg
, int from_tty
,
8463 struct cmd_list_element
*command
)
8465 catch_load_or_unload (arg
, from_tty
, 1, command
);
8469 catch_unload_command_1 (char *arg
, int from_tty
,
8470 struct cmd_list_element
*command
)
8472 catch_load_or_unload (arg
, from_tty
, 0, command
);
8475 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8476 is non-zero, then make the breakpoint temporary. If COND_STRING is
8477 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8478 the breakpoint_ops structure associated to the catchpoint. */
8481 init_catchpoint (struct breakpoint
*b
,
8482 struct gdbarch
*gdbarch
, int tempflag
,
8484 const struct breakpoint_ops
*ops
)
8486 struct symtab_and_line sal
;
8489 sal
.pspace
= current_program_space
;
8491 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8493 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8494 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8498 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8500 add_to_breakpoint_chain (b
);
8501 set_breakpoint_number (internal
, b
);
8502 if (is_tracepoint (b
))
8503 set_tracepoint_count (breakpoint_count
);
8506 observer_notify_breakpoint_created (b
);
8509 update_global_location_list (UGLL_MAY_INSERT
);
8513 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8514 int tempflag
, char *cond_string
,
8515 const struct breakpoint_ops
*ops
)
8517 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8519 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8521 c
->forked_inferior_pid
= null_ptid
;
8523 install_breakpoint (0, &c
->base
, 1);
8526 /* Exec catchpoints. */
8528 /* An instance of this type is used to represent an exec catchpoint.
8529 It includes a "struct breakpoint" as a kind of base class; users
8530 downcast to "struct breakpoint *" when needed. A breakpoint is
8531 really of this type iff its ops pointer points to
8532 CATCH_EXEC_BREAKPOINT_OPS. */
8534 struct exec_catchpoint
8536 /* The base class. */
8537 struct breakpoint base
;
8539 /* Filename of a program whose exec triggered this catchpoint.
8540 This field is only valid immediately after this catchpoint has
8542 char *exec_pathname
;
8545 /* Implement the "dtor" breakpoint_ops method for exec
8549 dtor_catch_exec (struct breakpoint
*b
)
8551 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8553 xfree (c
->exec_pathname
);
8555 base_breakpoint_ops
.dtor (b
);
8559 insert_catch_exec (struct bp_location
*bl
)
8561 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8565 remove_catch_exec (struct bp_location
*bl
)
8567 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8571 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8572 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8573 const struct target_waitstatus
*ws
)
8575 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8577 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8580 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8584 static enum print_stop_action
8585 print_it_catch_exec (bpstat bs
)
8587 struct ui_out
*uiout
= current_uiout
;
8588 struct breakpoint
*b
= bs
->breakpoint_at
;
8589 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8591 annotate_catchpoint (b
->number
);
8592 if (b
->disposition
== disp_del
)
8593 ui_out_text (uiout
, "\nTemporary catchpoint ");
8595 ui_out_text (uiout
, "\nCatchpoint ");
8596 if (ui_out_is_mi_like_p (uiout
))
8598 ui_out_field_string (uiout
, "reason",
8599 async_reason_lookup (EXEC_ASYNC_EXEC
));
8600 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8602 ui_out_field_int (uiout
, "bkptno", b
->number
);
8603 ui_out_text (uiout
, " (exec'd ");
8604 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8605 ui_out_text (uiout
, "), ");
8607 return PRINT_SRC_AND_LOC
;
8611 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8613 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8614 struct value_print_options opts
;
8615 struct ui_out
*uiout
= current_uiout
;
8617 get_user_print_options (&opts
);
8619 /* Field 4, the address, is omitted (which makes the columns
8620 not line up too nicely with the headers, but the effect
8621 is relatively readable). */
8622 if (opts
.addressprint
)
8623 ui_out_field_skip (uiout
, "addr");
8625 ui_out_text (uiout
, "exec");
8626 if (c
->exec_pathname
!= NULL
)
8628 ui_out_text (uiout
, ", program \"");
8629 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8630 ui_out_text (uiout
, "\" ");
8633 if (ui_out_is_mi_like_p (uiout
))
8634 ui_out_field_string (uiout
, "catch-type", "exec");
8638 print_mention_catch_exec (struct breakpoint
*b
)
8640 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8643 /* Implement the "print_recreate" breakpoint_ops method for exec
8647 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8649 fprintf_unfiltered (fp
, "catch exec");
8650 print_recreate_thread (b
, fp
);
8653 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8656 hw_breakpoint_used_count (void)
8659 struct breakpoint
*b
;
8660 struct bp_location
*bl
;
8664 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8665 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8667 /* Special types of hardware breakpoints may use more than
8669 i
+= b
->ops
->resources_needed (bl
);
8676 /* Returns the resources B would use if it were a hardware
8680 hw_watchpoint_use_count (struct breakpoint
*b
)
8683 struct bp_location
*bl
;
8685 if (!breakpoint_enabled (b
))
8688 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8690 /* Special types of hardware watchpoints may use more than
8692 i
+= b
->ops
->resources_needed (bl
);
8698 /* Returns the sum the used resources of all hardware watchpoints of
8699 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8700 the sum of the used resources of all hardware watchpoints of other
8701 types _not_ TYPE. */
8704 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8705 enum bptype type
, int *other_type_used
)
8708 struct breakpoint
*b
;
8710 *other_type_used
= 0;
8715 if (!breakpoint_enabled (b
))
8718 if (b
->type
== type
)
8719 i
+= hw_watchpoint_use_count (b
);
8720 else if (is_hardware_watchpoint (b
))
8721 *other_type_used
= 1;
8728 disable_watchpoints_before_interactive_call_start (void)
8730 struct breakpoint
*b
;
8734 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8736 b
->enable_state
= bp_call_disabled
;
8737 update_global_location_list (UGLL_DONT_INSERT
);
8743 enable_watchpoints_after_interactive_call_stop (void)
8745 struct breakpoint
*b
;
8749 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8751 b
->enable_state
= bp_enabled
;
8752 update_global_location_list (UGLL_MAY_INSERT
);
8758 disable_breakpoints_before_startup (void)
8760 current_program_space
->executing_startup
= 1;
8761 update_global_location_list (UGLL_DONT_INSERT
);
8765 enable_breakpoints_after_startup (void)
8767 current_program_space
->executing_startup
= 0;
8768 breakpoint_re_set ();
8771 /* Create a new single-step breakpoint for thread THREAD, with no
8774 static struct breakpoint
*
8775 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8777 struct breakpoint
*b
= XNEW (struct breakpoint
);
8779 init_raw_breakpoint_without_location (b
, gdbarch
, bp_single_step
,
8780 &momentary_breakpoint_ops
);
8782 b
->disposition
= disp_donttouch
;
8783 b
->frame_id
= null_frame_id
;
8786 gdb_assert (b
->thread
!= 0);
8788 add_to_breakpoint_chain (b
);
8793 /* Set a momentary breakpoint of type TYPE at address specified by
8794 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8798 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8799 struct frame_id frame_id
, enum bptype type
)
8801 struct breakpoint
*b
;
8803 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8805 gdb_assert (!frame_id_artificial_p (frame_id
));
8807 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8808 b
->enable_state
= bp_enabled
;
8809 b
->disposition
= disp_donttouch
;
8810 b
->frame_id
= frame_id
;
8812 /* If we're debugging a multi-threaded program, then we want
8813 momentary breakpoints to be active in only a single thread of
8815 if (in_thread_list (inferior_ptid
))
8816 b
->thread
= pid_to_thread_id (inferior_ptid
);
8818 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8823 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8824 The new breakpoint will have type TYPE, use OPS as its
8825 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8827 static struct breakpoint
*
8828 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8830 const struct breakpoint_ops
*ops
,
8833 struct breakpoint
*copy
;
8835 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8836 copy
->loc
= allocate_bp_location (copy
);
8837 set_breakpoint_location_function (copy
->loc
, 1);
8839 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8840 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8841 copy
->loc
->address
= orig
->loc
->address
;
8842 copy
->loc
->section
= orig
->loc
->section
;
8843 copy
->loc
->pspace
= orig
->loc
->pspace
;
8844 copy
->loc
->probe
= orig
->loc
->probe
;
8845 copy
->loc
->line_number
= orig
->loc
->line_number
;
8846 copy
->loc
->symtab
= orig
->loc
->symtab
;
8847 copy
->loc
->enabled
= loc_enabled
;
8848 copy
->frame_id
= orig
->frame_id
;
8849 copy
->thread
= orig
->thread
;
8850 copy
->pspace
= orig
->pspace
;
8852 copy
->enable_state
= bp_enabled
;
8853 copy
->disposition
= disp_donttouch
;
8854 copy
->number
= internal_breakpoint_number
--;
8856 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8860 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8864 clone_momentary_breakpoint (struct breakpoint
*orig
)
8866 /* If there's nothing to clone, then return nothing. */
8870 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8874 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8877 struct symtab_and_line sal
;
8879 sal
= find_pc_line (pc
, 0);
8881 sal
.section
= find_pc_overlay (pc
);
8882 sal
.explicit_pc
= 1;
8884 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8888 /* Tell the user we have just set a breakpoint B. */
8891 mention (struct breakpoint
*b
)
8893 b
->ops
->print_mention (b
);
8894 if (ui_out_is_mi_like_p (current_uiout
))
8896 printf_filtered ("\n");
8900 static int bp_loc_is_permanent (struct bp_location
*loc
);
8902 static struct bp_location
*
8903 add_location_to_breakpoint (struct breakpoint
*b
,
8904 const struct symtab_and_line
*sal
)
8906 struct bp_location
*loc
, **tmp
;
8907 CORE_ADDR adjusted_address
;
8908 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8910 if (loc_gdbarch
== NULL
)
8911 loc_gdbarch
= b
->gdbarch
;
8913 /* Adjust the breakpoint's address prior to allocating a location.
8914 Once we call allocate_bp_location(), that mostly uninitialized
8915 location will be placed on the location chain. Adjustment of the
8916 breakpoint may cause target_read_memory() to be called and we do
8917 not want its scan of the location chain to find a breakpoint and
8918 location that's only been partially initialized. */
8919 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8922 /* Sort the locations by their ADDRESS. */
8923 loc
= allocate_bp_location (b
);
8924 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8925 tmp
= &((*tmp
)->next
))
8930 loc
->requested_address
= sal
->pc
;
8931 loc
->address
= adjusted_address
;
8932 loc
->pspace
= sal
->pspace
;
8933 loc
->probe
.probe
= sal
->probe
;
8934 loc
->probe
.objfile
= sal
->objfile
;
8935 gdb_assert (loc
->pspace
!= NULL
);
8936 loc
->section
= sal
->section
;
8937 loc
->gdbarch
= loc_gdbarch
;
8938 loc
->line_number
= sal
->line
;
8939 loc
->symtab
= sal
->symtab
;
8941 set_breakpoint_location_function (loc
,
8942 sal
->explicit_pc
|| sal
->explicit_line
);
8944 /* While by definition, permanent breakpoints are already present in the
8945 code, we don't mark the location as inserted. Normally one would expect
8946 that GDB could rely on that breakpoint instruction to stop the program,
8947 thus removing the need to insert its own breakpoint, except that executing
8948 the breakpoint instruction can kill the target instead of reporting a
8949 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8950 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8951 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8952 breakpoint be inserted normally results in QEMU knowing about the GDB
8953 breakpoint, and thus trap before the breakpoint instruction is executed.
8954 (If GDB later needs to continue execution past the permanent breakpoint,
8955 it manually increments the PC, thus avoiding executing the breakpoint
8957 if (bp_loc_is_permanent (loc
))
8964 /* See breakpoint.h. */
8967 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8971 const gdb_byte
*bpoint
;
8972 gdb_byte
*target_mem
;
8973 struct cleanup
*cleanup
;
8977 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
8979 /* Software breakpoints unsupported? */
8983 target_mem
= alloca (len
);
8985 /* Enable the automatic memory restoration from breakpoints while
8986 we read the memory. Otherwise we could say about our temporary
8987 breakpoints they are permanent. */
8988 cleanup
= make_show_memory_breakpoints_cleanup (0);
8990 if (target_read_memory (address
, target_mem
, len
) == 0
8991 && memcmp (target_mem
, bpoint
, len
) == 0)
8994 do_cleanups (cleanup
);
8999 /* Return 1 if LOC is pointing to a permanent breakpoint,
9000 return 0 otherwise. */
9003 bp_loc_is_permanent (struct bp_location
*loc
)
9005 struct cleanup
*cleanup
;
9008 gdb_assert (loc
!= NULL
);
9010 /* If we have a catchpoint or a watchpoint, just return 0. We should not
9011 attempt to read from the addresses the locations of these breakpoint types
9012 point to. program_breakpoint_here_p, below, will attempt to read
9014 if (!breakpoint_address_is_meaningful (loc
->owner
))
9017 cleanup
= save_current_space_and_thread ();
9018 switch_to_program_space_and_thread (loc
->pspace
);
9020 retval
= program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
9022 do_cleanups (cleanup
);
9027 /* Build a command list for the dprintf corresponding to the current
9028 settings of the dprintf style options. */
9031 update_dprintf_command_list (struct breakpoint
*b
)
9033 char *dprintf_args
= b
->extra_string
;
9034 char *printf_line
= NULL
;
9039 dprintf_args
= skip_spaces (dprintf_args
);
9041 /* Allow a comma, as it may have terminated a location, but don't
9043 if (*dprintf_args
== ',')
9045 dprintf_args
= skip_spaces (dprintf_args
);
9047 if (*dprintf_args
!= '"')
9048 error (_("Bad format string, missing '\"'."));
9050 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9051 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9052 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9054 if (!dprintf_function
)
9055 error (_("No function supplied for dprintf call"));
9057 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9058 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9063 printf_line
= xstrprintf ("call (void) %s (%s)",
9067 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9069 if (target_can_run_breakpoint_commands ())
9070 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9073 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9074 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9078 internal_error (__FILE__
, __LINE__
,
9079 _("Invalid dprintf style."));
9081 gdb_assert (printf_line
!= NULL
);
9082 /* Manufacture a printf sequence. */
9084 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
9086 printf_cmd_line
->control_type
= simple_control
;
9087 printf_cmd_line
->body_count
= 0;
9088 printf_cmd_line
->body_list
= NULL
;
9089 printf_cmd_line
->next
= NULL
;
9090 printf_cmd_line
->line
= printf_line
;
9092 breakpoint_set_commands (b
, printf_cmd_line
);
9096 /* Update all dprintf commands, making their command lists reflect
9097 current style settings. */
9100 update_dprintf_commands (char *args
, int from_tty
,
9101 struct cmd_list_element
*c
)
9103 struct breakpoint
*b
;
9107 if (b
->type
== bp_dprintf
)
9108 update_dprintf_command_list (b
);
9112 /* Create a breakpoint with SAL as location. Use LOCATION
9113 as a description of the location, and COND_STRING
9114 as condition expression. */
9117 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9118 struct symtabs_and_lines sals
,
9119 struct event_location
*location
,
9120 char *filter
, char *cond_string
,
9122 enum bptype type
, enum bpdisp disposition
,
9123 int thread
, int task
, int ignore_count
,
9124 const struct breakpoint_ops
*ops
, int from_tty
,
9125 int enabled
, int internal
, unsigned flags
,
9126 int display_canonical
)
9130 if (type
== bp_hardware_breakpoint
)
9132 int target_resources_ok
;
9134 i
= hw_breakpoint_used_count ();
9135 target_resources_ok
=
9136 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9138 if (target_resources_ok
== 0)
9139 error (_("No hardware breakpoint support in the target."));
9140 else if (target_resources_ok
< 0)
9141 error (_("Hardware breakpoints used exceeds limit."));
9144 gdb_assert (sals
.nelts
> 0);
9146 for (i
= 0; i
< sals
.nelts
; ++i
)
9148 struct symtab_and_line sal
= sals
.sals
[i
];
9149 struct bp_location
*loc
;
9153 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9155 loc_gdbarch
= gdbarch
;
9157 describe_other_breakpoints (loc_gdbarch
,
9158 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9163 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9167 b
->cond_string
= cond_string
;
9168 b
->extra_string
= extra_string
;
9169 b
->ignore_count
= ignore_count
;
9170 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9171 b
->disposition
= disposition
;
9173 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9174 b
->loc
->inserted
= 1;
9176 if (type
== bp_static_tracepoint
)
9178 struct tracepoint
*t
= (struct tracepoint
*) b
;
9179 struct static_tracepoint_marker marker
;
9181 if (strace_marker_p (b
))
9183 /* We already know the marker exists, otherwise, we
9184 wouldn't see a sal for it. */
9185 const char *p
= &event_location_to_string (b
->location
)[3];
9189 p
= skip_spaces_const (p
);
9191 endp
= skip_to_space_const (p
);
9193 marker_str
= savestring (p
, endp
- p
);
9194 t
->static_trace_marker_id
= marker_str
;
9196 printf_filtered (_("Probed static tracepoint "
9198 t
->static_trace_marker_id
);
9200 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9202 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9203 release_static_tracepoint_marker (&marker
);
9205 printf_filtered (_("Probed static tracepoint "
9207 t
->static_trace_marker_id
);
9210 warning (_("Couldn't determine the static "
9211 "tracepoint marker to probe"));
9218 loc
= add_location_to_breakpoint (b
, &sal
);
9219 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9225 const char *arg
= b
->cond_string
;
9227 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9228 block_for_pc (loc
->address
), 0);
9230 error (_("Garbage '%s' follows condition"), arg
);
9233 /* Dynamic printf requires and uses additional arguments on the
9234 command line, otherwise it's an error. */
9235 if (type
== bp_dprintf
)
9237 if (b
->extra_string
)
9238 update_dprintf_command_list (b
);
9240 error (_("Format string required"));
9242 else if (b
->extra_string
)
9243 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9246 b
->display_canonical
= display_canonical
;
9247 if (location
!= NULL
)
9248 b
->location
= location
;
9250 b
->location
= new_address_location (b
->loc
->address
);
9255 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9256 struct symtabs_and_lines sals
,
9257 struct event_location
*location
,
9258 char *filter
, char *cond_string
,
9260 enum bptype type
, enum bpdisp disposition
,
9261 int thread
, int task
, int ignore_count
,
9262 const struct breakpoint_ops
*ops
, int from_tty
,
9263 int enabled
, int internal
, unsigned flags
,
9264 int display_canonical
)
9266 struct breakpoint
*b
;
9267 struct cleanup
*old_chain
;
9269 if (is_tracepoint_type (type
))
9271 struct tracepoint
*t
;
9273 t
= XCNEW (struct tracepoint
);
9277 b
= XNEW (struct breakpoint
);
9279 old_chain
= make_cleanup (xfree
, b
);
9281 init_breakpoint_sal (b
, gdbarch
,
9283 filter
, cond_string
, extra_string
,
9285 thread
, task
, ignore_count
,
9287 enabled
, internal
, flags
,
9289 discard_cleanups (old_chain
);
9291 install_breakpoint (internal
, b
, 0);
9294 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9295 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9296 value. COND_STRING, if not NULL, specified the condition to be
9297 used for all breakpoints. Essentially the only case where
9298 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9299 function. In that case, it's still not possible to specify
9300 separate conditions for different overloaded functions, so
9301 we take just a single condition string.
9303 NOTE: If the function succeeds, the caller is expected to cleanup
9304 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9305 array contents). If the function fails (error() is called), the
9306 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9307 COND and SALS arrays and each of those arrays contents. */
9310 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9311 struct linespec_result
*canonical
,
9312 char *cond_string
, char *extra_string
,
9313 enum bptype type
, enum bpdisp disposition
,
9314 int thread
, int task
, int ignore_count
,
9315 const struct breakpoint_ops
*ops
, int from_tty
,
9316 int enabled
, int internal
, unsigned flags
)
9319 struct linespec_sals
*lsal
;
9321 if (canonical
->pre_expanded
)
9322 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9324 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9326 /* Note that 'location' can be NULL in the case of a plain
9327 'break', without arguments. */
9328 struct event_location
*location
9329 = (canonical
->location
!= NULL
9330 ? copy_event_location (canonical
->location
) : NULL
);
9331 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9332 struct cleanup
*inner
= make_cleanup_delete_event_location (location
);
9334 make_cleanup (xfree
, filter_string
);
9335 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9338 cond_string
, extra_string
,
9340 thread
, task
, ignore_count
, ops
,
9341 from_tty
, enabled
, internal
, flags
,
9342 canonical
->special_display
);
9343 discard_cleanups (inner
);
9347 /* Parse LOCATION which is assumed to be a SAL specification possibly
9348 followed by conditionals. On return, SALS contains an array of SAL
9349 addresses found. LOCATION points to the end of the SAL (for
9350 linespec locations).
9352 The array and the line spec strings are allocated on the heap, it is
9353 the caller's responsibility to free them. */
9356 parse_breakpoint_sals (const struct event_location
*location
,
9357 struct linespec_result
*canonical
)
9359 struct symtab_and_line cursal
;
9361 if (event_location_type (location
) == LINESPEC_LOCATION
)
9363 const char *address
= get_linespec_location (location
);
9365 if (address
== NULL
)
9367 /* The last displayed codepoint, if it's valid, is our default
9368 breakpoint address. */
9369 if (last_displayed_sal_is_valid ())
9371 struct linespec_sals lsal
;
9372 struct symtab_and_line sal
;
9375 init_sal (&sal
); /* Initialize to zeroes. */
9376 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9378 /* Set sal's pspace, pc, symtab, and line to the values
9379 corresponding to the last call to print_frame_info.
9380 Be sure to reinitialize LINE with NOTCURRENT == 0
9381 as the breakpoint line number is inappropriate otherwise.
9382 find_pc_line would adjust PC, re-set it back. */
9383 get_last_displayed_sal (&sal
);
9385 sal
= find_pc_line (pc
, 0);
9387 /* "break" without arguments is equivalent to "break *PC"
9388 where PC is the last displayed codepoint's address. So
9389 make sure to set sal.explicit_pc to prevent GDB from
9390 trying to expand the list of sals to include all other
9391 instances with the same symtab and line. */
9393 sal
.explicit_pc
= 1;
9395 lsal
.sals
.sals
[0] = sal
;
9396 lsal
.sals
.nelts
= 1;
9397 lsal
.canonical
= NULL
;
9399 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9403 error (_("No default breakpoint address now."));
9407 /* Force almost all breakpoints to be in terms of the
9408 current_source_symtab (which is decode_line_1's default).
9409 This should produce the results we want almost all of the
9410 time while leaving default_breakpoint_* alone.
9412 ObjC: However, don't match an Objective-C method name which
9413 may have a '+' or '-' succeeded by a '['. */
9414 cursal
= get_current_source_symtab_and_line ();
9415 if (last_displayed_sal_is_valid ())
9417 const char *address
= NULL
;
9419 if (event_location_type (location
) == LINESPEC_LOCATION
)
9420 address
= get_linespec_location (location
);
9424 && strchr ("+-", address
[0]) != NULL
9425 && address
[1] != '['))
9427 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
,
9428 get_last_displayed_symtab (),
9429 get_last_displayed_line (),
9430 canonical
, NULL
, NULL
);
9435 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
,
9436 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9440 /* Convert each SAL into a real PC. Verify that the PC can be
9441 inserted as a breakpoint. If it can't throw an error. */
9444 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9448 for (i
= 0; i
< sals
->nelts
; i
++)
9449 resolve_sal_pc (&sals
->sals
[i
]);
9452 /* Fast tracepoints may have restrictions on valid locations. For
9453 instance, a fast tracepoint using a jump instead of a trap will
9454 likely have to overwrite more bytes than a trap would, and so can
9455 only be placed where the instruction is longer than the jump, or a
9456 multi-instruction sequence does not have a jump into the middle of
9460 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9461 struct symtabs_and_lines
*sals
)
9464 struct symtab_and_line
*sal
;
9466 struct cleanup
*old_chain
;
9468 for (i
= 0; i
< sals
->nelts
; i
++)
9470 struct gdbarch
*sarch
;
9472 sal
= &sals
->sals
[i
];
9474 sarch
= get_sal_arch (*sal
);
9475 /* We fall back to GDBARCH if there is no architecture
9476 associated with SAL. */
9479 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
, &msg
);
9480 old_chain
= make_cleanup (xfree
, msg
);
9483 error (_("May not have a fast tracepoint at 0x%s%s"),
9484 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9486 do_cleanups (old_chain
);
9490 /* Issue an invalid thread ID error. */
9492 static void ATTRIBUTE_NORETURN
9493 invalid_thread_id_error (int id
)
9495 error (_("Unknown thread %d."), id
);
9498 /* Given TOK, a string specification of condition and thread, as
9499 accepted by the 'break' command, extract the condition
9500 string and thread number and set *COND_STRING and *THREAD.
9501 PC identifies the context at which the condition should be parsed.
9502 If no condition is found, *COND_STRING is set to NULL.
9503 If no thread is found, *THREAD is set to -1. */
9506 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9507 char **cond_string
, int *thread
, int *task
,
9510 *cond_string
= NULL
;
9517 const char *end_tok
;
9519 const char *cond_start
= NULL
;
9520 const char *cond_end
= NULL
;
9522 tok
= skip_spaces_const (tok
);
9524 if ((*tok
== '"' || *tok
== ',') && rest
)
9526 *rest
= savestring (tok
, strlen (tok
));
9530 end_tok
= skip_to_space_const (tok
);
9532 toklen
= end_tok
- tok
;
9534 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9536 struct expression
*expr
;
9538 tok
= cond_start
= end_tok
+ 1;
9539 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9542 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9544 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9549 *thread
= strtol (tok
, &tmptok
, 0);
9551 error (_("Junk after thread keyword."));
9552 if (!valid_thread_id (*thread
))
9553 invalid_thread_id_error (*thread
);
9556 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9561 *task
= strtol (tok
, &tmptok
, 0);
9563 error (_("Junk after task keyword."));
9564 if (!valid_task_id (*task
))
9565 error (_("Unknown task %d."), *task
);
9570 *rest
= savestring (tok
, strlen (tok
));
9574 error (_("Junk at end of arguments."));
9578 /* Decode a static tracepoint marker spec. */
9580 static struct symtabs_and_lines
9581 decode_static_tracepoint_spec (const char **arg_p
)
9583 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9584 struct symtabs_and_lines sals
;
9585 struct cleanup
*old_chain
;
9586 const char *p
= &(*arg_p
)[3];
9591 p
= skip_spaces_const (p
);
9593 endp
= skip_to_space_const (p
);
9595 marker_str
= savestring (p
, endp
- p
);
9596 old_chain
= make_cleanup (xfree
, marker_str
);
9598 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9599 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9600 error (_("No known static tracepoint marker named %s"), marker_str
);
9602 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9603 sals
.sals
= XNEWVEC (struct symtab_and_line
, sals
.nelts
);
9605 for (i
= 0; i
< sals
.nelts
; i
++)
9607 struct static_tracepoint_marker
*marker
;
9609 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9611 init_sal (&sals
.sals
[i
]);
9613 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9614 sals
.sals
[i
].pc
= marker
->address
;
9616 release_static_tracepoint_marker (marker
);
9619 do_cleanups (old_chain
);
9625 /* See breakpoint.h. */
9628 create_breakpoint (struct gdbarch
*gdbarch
,
9629 const struct event_location
*location
, char *cond_string
,
9630 int thread
, char *extra_string
,
9632 int tempflag
, enum bptype type_wanted
,
9634 enum auto_boolean pending_break_support
,
9635 const struct breakpoint_ops
*ops
,
9636 int from_tty
, int enabled
, int internal
,
9639 struct linespec_result canonical
;
9640 struct cleanup
*old_chain
;
9641 struct cleanup
*bkpt_chain
= NULL
;
9644 int prev_bkpt_count
= breakpoint_count
;
9646 gdb_assert (ops
!= NULL
);
9648 /* If extra_string isn't useful, set it to NULL. */
9649 if (extra_string
!= NULL
&& *extra_string
== '\0')
9650 extra_string
= NULL
;
9652 init_linespec_result (&canonical
);
9656 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9658 CATCH (e
, RETURN_MASK_ERROR
)
9660 /* If caller is interested in rc value from parse, set
9662 if (e
.error
== NOT_FOUND_ERROR
)
9664 /* If pending breakpoint support is turned off, throw
9667 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9668 throw_exception (e
);
9670 exception_print (gdb_stderr
, e
);
9672 /* If pending breakpoint support is auto query and the user
9673 selects no, then simply return the error code. */
9674 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9675 && !nquery (_("Make %s pending on future shared library load? "),
9676 bptype_string (type_wanted
)))
9679 /* At this point, either the user was queried about setting
9680 a pending breakpoint and selected yes, or pending
9681 breakpoint behavior is on and thus a pending breakpoint
9682 is defaulted on behalf of the user. */
9686 throw_exception (e
);
9690 if (!pending
&& VEC_empty (linespec_sals
, canonical
.sals
))
9693 /* Create a chain of things that always need to be cleaned up. */
9694 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
9696 /* ----------------------------- SNIP -----------------------------
9697 Anything added to the cleanup chain beyond this point is assumed
9698 to be part of a breakpoint. If the breakpoint create succeeds
9699 then the memory is not reclaimed. */
9700 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9702 /* Resolve all line numbers to PC's and verify that the addresses
9703 are ok for the target. */
9707 struct linespec_sals
*iter
;
9709 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9710 breakpoint_sals_to_pc (&iter
->sals
);
9713 /* Fast tracepoints may have additional restrictions on location. */
9714 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9717 struct linespec_sals
*iter
;
9719 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9720 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9723 /* Verify that condition can be parsed, before setting any
9724 breakpoints. Allocate a separate condition expression for each
9731 struct linespec_sals
*lsal
;
9733 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9735 /* Here we only parse 'arg' to separate condition
9736 from thread number, so parsing in context of first
9737 sal is OK. When setting the breakpoint we'll
9738 re-parse it in context of each sal. */
9740 find_condition_and_thread (extra_string
, lsal
->sals
.sals
[0].pc
,
9741 &cond_string
, &thread
, &task
, &rest
);
9743 make_cleanup (xfree
, cond_string
);
9745 make_cleanup (xfree
, rest
);
9747 extra_string
= rest
;
9749 extra_string
= NULL
;
9753 if (type_wanted
!= bp_dprintf
9754 && extra_string
!= NULL
&& *extra_string
!= '\0')
9755 error (_("Garbage '%s' at end of location"), extra_string
);
9757 /* Create a private copy of condition string. */
9760 cond_string
= xstrdup (cond_string
);
9761 make_cleanup (xfree
, cond_string
);
9763 /* Create a private copy of any extra string. */
9766 extra_string
= xstrdup (extra_string
);
9767 make_cleanup (xfree
, extra_string
);
9771 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9772 cond_string
, extra_string
, type_wanted
,
9773 tempflag
? disp_del
: disp_donttouch
,
9774 thread
, task
, ignore_count
, ops
,
9775 from_tty
, enabled
, internal
, flags
);
9779 struct breakpoint
*b
;
9781 if (is_tracepoint_type (type_wanted
))
9783 struct tracepoint
*t
;
9785 t
= XCNEW (struct tracepoint
);
9789 b
= XNEW (struct breakpoint
);
9791 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9792 b
->location
= copy_event_location (location
);
9795 b
->cond_string
= NULL
;
9798 /* Create a private copy of condition string. */
9801 cond_string
= xstrdup (cond_string
);
9802 make_cleanup (xfree
, cond_string
);
9804 b
->cond_string
= cond_string
;
9808 /* Create a private copy of any extra string. */
9809 if (extra_string
!= NULL
)
9811 extra_string
= xstrdup (extra_string
);
9812 make_cleanup (xfree
, extra_string
);
9814 b
->extra_string
= extra_string
;
9815 b
->ignore_count
= ignore_count
;
9816 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9817 b
->condition_not_parsed
= 1;
9818 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9819 if ((type_wanted
!= bp_breakpoint
9820 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9821 b
->pspace
= current_program_space
;
9823 install_breakpoint (internal
, b
, 0);
9826 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9828 warning (_("Multiple breakpoints were set.\nUse the "
9829 "\"delete\" command to delete unwanted breakpoints."));
9830 prev_breakpoint_count
= prev_bkpt_count
;
9833 /* That's it. Discard the cleanups for data inserted into the
9835 discard_cleanups (bkpt_chain
);
9836 /* But cleanup everything else. */
9837 do_cleanups (old_chain
);
9839 /* error call may happen here - have BKPT_CHAIN already discarded. */
9840 update_global_location_list (UGLL_MAY_INSERT
);
9845 /* Set a breakpoint.
9846 ARG is a string describing breakpoint address,
9847 condition, and thread.
9848 FLAG specifies if a breakpoint is hardware on,
9849 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9853 break_command_1 (char *arg
, int flag
, int from_tty
)
9855 int tempflag
= flag
& BP_TEMPFLAG
;
9856 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9857 ? bp_hardware_breakpoint
9859 struct breakpoint_ops
*ops
;
9860 struct event_location
*location
;
9861 struct cleanup
*cleanup
;
9863 location
= string_to_event_location (&arg
, current_language
);
9864 cleanup
= make_cleanup_delete_event_location (location
);
9866 /* Matching breakpoints on probes. */
9867 if (location
!= NULL
9868 && event_location_type (location
) == PROBE_LOCATION
)
9869 ops
= &bkpt_probe_breakpoint_ops
;
9871 ops
= &bkpt_breakpoint_ops
;
9873 create_breakpoint (get_current_arch (),
9875 NULL
, 0, arg
, 1 /* parse arg */,
9876 tempflag
, type_wanted
,
9877 0 /* Ignore count */,
9878 pending_break_support
,
9884 do_cleanups (cleanup
);
9887 /* Helper function for break_command_1 and disassemble_command. */
9890 resolve_sal_pc (struct symtab_and_line
*sal
)
9894 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9896 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9897 error (_("No line %d in file \"%s\"."),
9898 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9901 /* If this SAL corresponds to a breakpoint inserted using a line
9902 number, then skip the function prologue if necessary. */
9903 if (sal
->explicit_line
)
9904 skip_prologue_sal (sal
);
9907 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9909 const struct blockvector
*bv
;
9910 const struct block
*b
;
9913 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9914 SYMTAB_COMPUNIT (sal
->symtab
));
9917 sym
= block_linkage_function (b
);
9920 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9921 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9926 /* It really is worthwhile to have the section, so we'll
9927 just have to look harder. This case can be executed
9928 if we have line numbers but no functions (as can
9929 happen in assembly source). */
9931 struct bound_minimal_symbol msym
;
9932 struct cleanup
*old_chain
= save_current_space_and_thread ();
9934 switch_to_program_space_and_thread (sal
->pspace
);
9936 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9938 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9940 do_cleanups (old_chain
);
9947 break_command (char *arg
, int from_tty
)
9949 break_command_1 (arg
, 0, from_tty
);
9953 tbreak_command (char *arg
, int from_tty
)
9955 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9959 hbreak_command (char *arg
, int from_tty
)
9961 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9965 thbreak_command (char *arg
, int from_tty
)
9967 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9971 stop_command (char *arg
, int from_tty
)
9973 printf_filtered (_("Specify the type of breakpoint to set.\n\
9974 Usage: stop in <function | address>\n\
9975 stop at <line>\n"));
9979 stopin_command (char *arg
, int from_tty
)
9983 if (arg
== (char *) NULL
)
9985 else if (*arg
!= '*')
9990 /* Look for a ':'. If this is a line number specification, then
9991 say it is bad, otherwise, it should be an address or
9992 function/method name. */
9993 while (*argptr
&& !hasColon
)
9995 hasColon
= (*argptr
== ':');
10000 badInput
= (*argptr
!= ':'); /* Not a class::method */
10002 badInput
= isdigit (*arg
); /* a simple line number */
10006 printf_filtered (_("Usage: stop in <function | address>\n"));
10008 break_command_1 (arg
, 0, from_tty
);
10012 stopat_command (char *arg
, int from_tty
)
10016 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10020 char *argptr
= arg
;
10023 /* Look for a ':'. If there is a '::' then get out, otherwise
10024 it is probably a line number. */
10025 while (*argptr
&& !hasColon
)
10027 hasColon
= (*argptr
== ':');
10032 badInput
= (*argptr
== ':'); /* we have class::method */
10034 badInput
= !isdigit (*arg
); /* not a line number */
10038 printf_filtered (_("Usage: stop at <line>\n"));
10040 break_command_1 (arg
, 0, from_tty
);
10043 /* The dynamic printf command is mostly like a regular breakpoint, but
10044 with a prewired command list consisting of a single output command,
10045 built from extra arguments supplied on the dprintf command
10049 dprintf_command (char *arg
, int from_tty
)
10051 struct event_location
*location
;
10052 struct cleanup
*cleanup
;
10054 location
= string_to_event_location (&arg
, current_language
);
10055 cleanup
= make_cleanup_delete_event_location (location
);
10057 /* If non-NULL, ARG should have been advanced past the location;
10058 the next character must be ','. */
10061 if (arg
[0] != ',' || arg
[1] == '\0')
10062 error (_("Format string required"));
10065 /* Skip the comma. */
10070 create_breakpoint (get_current_arch (),
10072 NULL
, 0, arg
, 1 /* parse arg */,
10074 0 /* Ignore count */,
10075 pending_break_support
,
10076 &dprintf_breakpoint_ops
,
10081 do_cleanups (cleanup
);
10085 agent_printf_command (char *arg
, int from_tty
)
10087 error (_("May only run agent-printf on the target"));
10090 /* Implement the "breakpoint_hit" breakpoint_ops method for
10091 ranged breakpoints. */
10094 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10095 struct address_space
*aspace
,
10097 const struct target_waitstatus
*ws
)
10099 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10100 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10103 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10104 bl
->length
, aspace
, bp_addr
);
10107 /* Implement the "resources_needed" breakpoint_ops method for
10108 ranged breakpoints. */
10111 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10113 return target_ranged_break_num_registers ();
10116 /* Implement the "print_it" breakpoint_ops method for
10117 ranged breakpoints. */
10119 static enum print_stop_action
10120 print_it_ranged_breakpoint (bpstat bs
)
10122 struct breakpoint
*b
= bs
->breakpoint_at
;
10123 struct bp_location
*bl
= b
->loc
;
10124 struct ui_out
*uiout
= current_uiout
;
10126 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10128 /* Ranged breakpoints have only one location. */
10129 gdb_assert (bl
&& bl
->next
== NULL
);
10131 annotate_breakpoint (b
->number
);
10132 if (b
->disposition
== disp_del
)
10133 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
10135 ui_out_text (uiout
, "\nRanged breakpoint ");
10136 if (ui_out_is_mi_like_p (uiout
))
10138 ui_out_field_string (uiout
, "reason",
10139 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10140 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10142 ui_out_field_int (uiout
, "bkptno", b
->number
);
10143 ui_out_text (uiout
, ", ");
10145 return PRINT_SRC_AND_LOC
;
10148 /* Implement the "print_one" breakpoint_ops method for
10149 ranged breakpoints. */
10152 print_one_ranged_breakpoint (struct breakpoint
*b
,
10153 struct bp_location
**last_loc
)
10155 struct bp_location
*bl
= b
->loc
;
10156 struct value_print_options opts
;
10157 struct ui_out
*uiout
= current_uiout
;
10159 /* Ranged breakpoints have only one location. */
10160 gdb_assert (bl
&& bl
->next
== NULL
);
10162 get_user_print_options (&opts
);
10164 if (opts
.addressprint
)
10165 /* We don't print the address range here, it will be printed later
10166 by print_one_detail_ranged_breakpoint. */
10167 ui_out_field_skip (uiout
, "addr");
10168 annotate_field (5);
10169 print_breakpoint_location (b
, bl
);
10173 /* Implement the "print_one_detail" breakpoint_ops method for
10174 ranged breakpoints. */
10177 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10178 struct ui_out
*uiout
)
10180 CORE_ADDR address_start
, address_end
;
10181 struct bp_location
*bl
= b
->loc
;
10182 struct ui_file
*stb
= mem_fileopen ();
10183 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10187 address_start
= bl
->address
;
10188 address_end
= address_start
+ bl
->length
- 1;
10190 ui_out_text (uiout
, "\taddress range: ");
10191 fprintf_unfiltered (stb
, "[%s, %s]",
10192 print_core_address (bl
->gdbarch
, address_start
),
10193 print_core_address (bl
->gdbarch
, address_end
));
10194 ui_out_field_stream (uiout
, "addr", stb
);
10195 ui_out_text (uiout
, "\n");
10197 do_cleanups (cleanup
);
10200 /* Implement the "print_mention" breakpoint_ops method for
10201 ranged breakpoints. */
10204 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10206 struct bp_location
*bl
= b
->loc
;
10207 struct ui_out
*uiout
= current_uiout
;
10210 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10212 if (ui_out_is_mi_like_p (uiout
))
10215 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10216 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10217 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10220 /* Implement the "print_recreate" breakpoint_ops method for
10221 ranged breakpoints. */
10224 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10226 fprintf_unfiltered (fp
, "break-range %s, %s",
10227 event_location_to_string (b
->location
),
10228 event_location_to_string (b
->location_range_end
));
10229 print_recreate_thread (b
, fp
);
10232 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10234 static struct breakpoint_ops ranged_breakpoint_ops
;
10236 /* Find the address where the end of the breakpoint range should be
10237 placed, given the SAL of the end of the range. This is so that if
10238 the user provides a line number, the end of the range is set to the
10239 last instruction of the given line. */
10242 find_breakpoint_range_end (struct symtab_and_line sal
)
10246 /* If the user provided a PC value, use it. Otherwise,
10247 find the address of the end of the given location. */
10248 if (sal
.explicit_pc
)
10255 ret
= find_line_pc_range (sal
, &start
, &end
);
10257 error (_("Could not find location of the end of the range."));
10259 /* find_line_pc_range returns the start of the next line. */
10266 /* Implement the "break-range" CLI command. */
10269 break_range_command (char *arg
, int from_tty
)
10271 char *arg_start
, *addr_string_start
, *addr_string_end
;
10272 struct linespec_result canonical_start
, canonical_end
;
10273 int bp_count
, can_use_bp
, length
;
10275 struct breakpoint
*b
;
10276 struct symtab_and_line sal_start
, sal_end
;
10277 struct cleanup
*cleanup_bkpt
;
10278 struct linespec_sals
*lsal_start
, *lsal_end
;
10279 struct event_location
*start_location
, *end_location
;
10281 /* We don't support software ranged breakpoints. */
10282 if (target_ranged_break_num_registers () < 0)
10283 error (_("This target does not support hardware ranged breakpoints."));
10285 bp_count
= hw_breakpoint_used_count ();
10286 bp_count
+= target_ranged_break_num_registers ();
10287 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10289 if (can_use_bp
< 0)
10290 error (_("Hardware breakpoints used exceeds limit."));
10292 arg
= skip_spaces (arg
);
10293 if (arg
== NULL
|| arg
[0] == '\0')
10294 error(_("No address range specified."));
10296 init_linespec_result (&canonical_start
);
10299 start_location
= string_to_event_location (&arg
, current_language
);
10300 cleanup_bkpt
= make_cleanup_delete_event_location (start_location
);
10301 parse_breakpoint_sals (start_location
, &canonical_start
);
10302 make_cleanup_destroy_linespec_result (&canonical_start
);
10305 error (_("Too few arguments."));
10306 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10307 error (_("Could not find location of the beginning of the range."));
10309 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10311 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10312 || lsal_start
->sals
.nelts
!= 1)
10313 error (_("Cannot create a ranged breakpoint with multiple locations."));
10315 sal_start
= lsal_start
->sals
.sals
[0];
10316 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10317 make_cleanup (xfree
, addr_string_start
);
10319 arg
++; /* Skip the comma. */
10320 arg
= skip_spaces (arg
);
10322 /* Parse the end location. */
10324 init_linespec_result (&canonical_end
);
10327 /* We call decode_line_full directly here instead of using
10328 parse_breakpoint_sals because we need to specify the start location's
10329 symtab and line as the default symtab and line for the end of the
10330 range. This makes it possible to have ranges like "foo.c:27, +14",
10331 where +14 means 14 lines from the start location. */
10332 end_location
= string_to_event_location (&arg
, current_language
);
10333 make_cleanup_delete_event_location (end_location
);
10334 decode_line_full (end_location
, DECODE_LINE_FUNFIRSTLINE
,
10335 sal_start
.symtab
, sal_start
.line
,
10336 &canonical_end
, NULL
, NULL
);
10338 make_cleanup_destroy_linespec_result (&canonical_end
);
10340 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10341 error (_("Could not find location of the end of the range."));
10343 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10344 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10345 || lsal_end
->sals
.nelts
!= 1)
10346 error (_("Cannot create a ranged breakpoint with multiple locations."));
10348 sal_end
= lsal_end
->sals
.sals
[0];
10350 end
= find_breakpoint_range_end (sal_end
);
10351 if (sal_start
.pc
> end
)
10352 error (_("Invalid address range, end precedes start."));
10354 length
= end
- sal_start
.pc
+ 1;
10356 /* Length overflowed. */
10357 error (_("Address range too large."));
10358 else if (length
== 1)
10360 /* This range is simple enough to be handled by
10361 the `hbreak' command. */
10362 hbreak_command (addr_string_start
, 1);
10364 do_cleanups (cleanup_bkpt
);
10369 /* Now set up the breakpoint. */
10370 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10371 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10372 set_breakpoint_count (breakpoint_count
+ 1);
10373 b
->number
= breakpoint_count
;
10374 b
->disposition
= disp_donttouch
;
10375 b
->location
= copy_event_location (start_location
);
10376 b
->location_range_end
= copy_event_location (end_location
);
10377 b
->loc
->length
= length
;
10379 do_cleanups (cleanup_bkpt
);
10382 observer_notify_breakpoint_created (b
);
10383 update_global_location_list (UGLL_MAY_INSERT
);
10386 /* Return non-zero if EXP is verified as constant. Returned zero
10387 means EXP is variable. Also the constant detection may fail for
10388 some constant expressions and in such case still falsely return
10392 watchpoint_exp_is_const (const struct expression
*exp
)
10394 int i
= exp
->nelts
;
10400 /* We are only interested in the descriptor of each element. */
10401 operator_length (exp
, i
, &oplenp
, &argsp
);
10404 switch (exp
->elts
[i
].opcode
)
10414 case BINOP_LOGICAL_AND
:
10415 case BINOP_LOGICAL_OR
:
10416 case BINOP_BITWISE_AND
:
10417 case BINOP_BITWISE_IOR
:
10418 case BINOP_BITWISE_XOR
:
10420 case BINOP_NOTEQUAL
:
10447 case OP_OBJC_NSSTRING
:
10450 case UNOP_LOGICAL_NOT
:
10451 case UNOP_COMPLEMENT
:
10456 case UNOP_CAST_TYPE
:
10457 case UNOP_REINTERPRET_CAST
:
10458 case UNOP_DYNAMIC_CAST
:
10459 /* Unary, binary and ternary operators: We have to check
10460 their operands. If they are constant, then so is the
10461 result of that operation. For instance, if A and B are
10462 determined to be constants, then so is "A + B".
10464 UNOP_IND is one exception to the rule above, because the
10465 value of *ADDR is not necessarily a constant, even when
10470 /* Check whether the associated symbol is a constant.
10472 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10473 possible that a buggy compiler could mark a variable as
10474 constant even when it is not, and TYPE_CONST would return
10475 true in this case, while SYMBOL_CLASS wouldn't.
10477 We also have to check for function symbols because they
10478 are always constant. */
10480 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10482 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10483 && SYMBOL_CLASS (s
) != LOC_CONST
10484 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10489 /* The default action is to return 0 because we are using
10490 the optimistic approach here: If we don't know something,
10491 then it is not a constant. */
10500 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10503 dtor_watchpoint (struct breakpoint
*self
)
10505 struct watchpoint
*w
= (struct watchpoint
*) self
;
10507 xfree (w
->cond_exp
);
10509 xfree (w
->exp_string
);
10510 xfree (w
->exp_string_reparse
);
10511 value_free (w
->val
);
10513 base_breakpoint_ops
.dtor (self
);
10516 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10519 re_set_watchpoint (struct breakpoint
*b
)
10521 struct watchpoint
*w
= (struct watchpoint
*) b
;
10523 /* Watchpoint can be either on expression using entirely global
10524 variables, or it can be on local variables.
10526 Watchpoints of the first kind are never auto-deleted, and even
10527 persist across program restarts. Since they can use variables
10528 from shared libraries, we need to reparse expression as libraries
10529 are loaded and unloaded.
10531 Watchpoints on local variables can also change meaning as result
10532 of solib event. For example, if a watchpoint uses both a local
10533 and a global variables in expression, it's a local watchpoint,
10534 but unloading of a shared library will make the expression
10535 invalid. This is not a very common use case, but we still
10536 re-evaluate expression, to avoid surprises to the user.
10538 Note that for local watchpoints, we re-evaluate it only if
10539 watchpoints frame id is still valid. If it's not, it means the
10540 watchpoint is out of scope and will be deleted soon. In fact,
10541 I'm not sure we'll ever be called in this case.
10543 If a local watchpoint's frame id is still valid, then
10544 w->exp_valid_block is likewise valid, and we can safely use it.
10546 Don't do anything about disabled watchpoints, since they will be
10547 reevaluated again when enabled. */
10548 update_watchpoint (w
, 1 /* reparse */);
10551 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10554 insert_watchpoint (struct bp_location
*bl
)
10556 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10557 int length
= w
->exact
? 1 : bl
->length
;
10559 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10563 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10566 remove_watchpoint (struct bp_location
*bl
)
10568 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10569 int length
= w
->exact
? 1 : bl
->length
;
10571 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10576 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10577 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10578 const struct target_waitstatus
*ws
)
10580 struct breakpoint
*b
= bl
->owner
;
10581 struct watchpoint
*w
= (struct watchpoint
*) b
;
10583 /* Continuable hardware watchpoints are treated as non-existent if the
10584 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10585 some data address). Otherwise gdb won't stop on a break instruction
10586 in the code (not from a breakpoint) when a hardware watchpoint has
10587 been defined. Also skip watchpoints which we know did not trigger
10588 (did not match the data address). */
10589 if (is_hardware_watchpoint (b
)
10590 && w
->watchpoint_triggered
== watch_triggered_no
)
10597 check_status_watchpoint (bpstat bs
)
10599 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10601 bpstat_check_watchpoint (bs
);
10604 /* Implement the "resources_needed" breakpoint_ops method for
10605 hardware watchpoints. */
10608 resources_needed_watchpoint (const struct bp_location
*bl
)
10610 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10611 int length
= w
->exact
? 1 : bl
->length
;
10613 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10616 /* Implement the "works_in_software_mode" breakpoint_ops method for
10617 hardware watchpoints. */
10620 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10622 /* Read and access watchpoints only work with hardware support. */
10623 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10626 static enum print_stop_action
10627 print_it_watchpoint (bpstat bs
)
10629 struct cleanup
*old_chain
;
10630 struct breakpoint
*b
;
10631 struct ui_file
*stb
;
10632 enum print_stop_action result
;
10633 struct watchpoint
*w
;
10634 struct ui_out
*uiout
= current_uiout
;
10636 gdb_assert (bs
->bp_location_at
!= NULL
);
10638 b
= bs
->breakpoint_at
;
10639 w
= (struct watchpoint
*) b
;
10641 stb
= mem_fileopen ();
10642 old_chain
= make_cleanup_ui_file_delete (stb
);
10646 case bp_watchpoint
:
10647 case bp_hardware_watchpoint
:
10648 annotate_watchpoint (b
->number
);
10649 if (ui_out_is_mi_like_p (uiout
))
10650 ui_out_field_string
10652 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10654 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10655 ui_out_text (uiout
, "\nOld value = ");
10656 watchpoint_value_print (bs
->old_val
, stb
);
10657 ui_out_field_stream (uiout
, "old", stb
);
10658 ui_out_text (uiout
, "\nNew value = ");
10659 watchpoint_value_print (w
->val
, stb
);
10660 ui_out_field_stream (uiout
, "new", stb
);
10661 ui_out_text (uiout
, "\n");
10662 /* More than one watchpoint may have been triggered. */
10663 result
= PRINT_UNKNOWN
;
10666 case bp_read_watchpoint
:
10667 if (ui_out_is_mi_like_p (uiout
))
10668 ui_out_field_string
10670 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10672 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10673 ui_out_text (uiout
, "\nValue = ");
10674 watchpoint_value_print (w
->val
, stb
);
10675 ui_out_field_stream (uiout
, "value", stb
);
10676 ui_out_text (uiout
, "\n");
10677 result
= PRINT_UNKNOWN
;
10680 case bp_access_watchpoint
:
10681 if (bs
->old_val
!= NULL
)
10683 annotate_watchpoint (b
->number
);
10684 if (ui_out_is_mi_like_p (uiout
))
10685 ui_out_field_string
10687 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10689 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10690 ui_out_text (uiout
, "\nOld value = ");
10691 watchpoint_value_print (bs
->old_val
, stb
);
10692 ui_out_field_stream (uiout
, "old", stb
);
10693 ui_out_text (uiout
, "\nNew value = ");
10698 if (ui_out_is_mi_like_p (uiout
))
10699 ui_out_field_string
10701 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10702 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10703 ui_out_text (uiout
, "\nValue = ");
10705 watchpoint_value_print (w
->val
, stb
);
10706 ui_out_field_stream (uiout
, "new", stb
);
10707 ui_out_text (uiout
, "\n");
10708 result
= PRINT_UNKNOWN
;
10711 result
= PRINT_UNKNOWN
;
10714 do_cleanups (old_chain
);
10718 /* Implement the "print_mention" breakpoint_ops method for hardware
10722 print_mention_watchpoint (struct breakpoint
*b
)
10724 struct cleanup
*ui_out_chain
;
10725 struct watchpoint
*w
= (struct watchpoint
*) b
;
10726 struct ui_out
*uiout
= current_uiout
;
10730 case bp_watchpoint
:
10731 ui_out_text (uiout
, "Watchpoint ");
10732 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10734 case bp_hardware_watchpoint
:
10735 ui_out_text (uiout
, "Hardware watchpoint ");
10736 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10738 case bp_read_watchpoint
:
10739 ui_out_text (uiout
, "Hardware read watchpoint ");
10740 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10742 case bp_access_watchpoint
:
10743 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
10744 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10747 internal_error (__FILE__
, __LINE__
,
10748 _("Invalid hardware watchpoint type."));
10751 ui_out_field_int (uiout
, "number", b
->number
);
10752 ui_out_text (uiout
, ": ");
10753 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10754 do_cleanups (ui_out_chain
);
10757 /* Implement the "print_recreate" breakpoint_ops method for
10761 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10763 struct watchpoint
*w
= (struct watchpoint
*) b
;
10767 case bp_watchpoint
:
10768 case bp_hardware_watchpoint
:
10769 fprintf_unfiltered (fp
, "watch");
10771 case bp_read_watchpoint
:
10772 fprintf_unfiltered (fp
, "rwatch");
10774 case bp_access_watchpoint
:
10775 fprintf_unfiltered (fp
, "awatch");
10778 internal_error (__FILE__
, __LINE__
,
10779 _("Invalid watchpoint type."));
10782 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10783 print_recreate_thread (b
, fp
);
10786 /* Implement the "explains_signal" breakpoint_ops method for
10790 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10792 /* A software watchpoint cannot cause a signal other than
10793 GDB_SIGNAL_TRAP. */
10794 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10800 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10802 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10804 /* Implement the "insert" breakpoint_ops method for
10805 masked hardware watchpoints. */
10808 insert_masked_watchpoint (struct bp_location
*bl
)
10810 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10812 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10813 bl
->watchpoint_type
);
10816 /* Implement the "remove" breakpoint_ops method for
10817 masked hardware watchpoints. */
10820 remove_masked_watchpoint (struct bp_location
*bl
)
10822 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10824 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10825 bl
->watchpoint_type
);
10828 /* Implement the "resources_needed" breakpoint_ops method for
10829 masked hardware watchpoints. */
10832 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10834 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10836 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10839 /* Implement the "works_in_software_mode" breakpoint_ops method for
10840 masked hardware watchpoints. */
10843 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10848 /* Implement the "print_it" breakpoint_ops method for
10849 masked hardware watchpoints. */
10851 static enum print_stop_action
10852 print_it_masked_watchpoint (bpstat bs
)
10854 struct breakpoint
*b
= bs
->breakpoint_at
;
10855 struct ui_out
*uiout
= current_uiout
;
10857 /* Masked watchpoints have only one location. */
10858 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10862 case bp_hardware_watchpoint
:
10863 annotate_watchpoint (b
->number
);
10864 if (ui_out_is_mi_like_p (uiout
))
10865 ui_out_field_string
10867 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10870 case bp_read_watchpoint
:
10871 if (ui_out_is_mi_like_p (uiout
))
10872 ui_out_field_string
10874 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10877 case bp_access_watchpoint
:
10878 if (ui_out_is_mi_like_p (uiout
))
10879 ui_out_field_string
10881 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10884 internal_error (__FILE__
, __LINE__
,
10885 _("Invalid hardware watchpoint type."));
10889 ui_out_text (uiout
, _("\n\
10890 Check the underlying instruction at PC for the memory\n\
10891 address and value which triggered this watchpoint.\n"));
10892 ui_out_text (uiout
, "\n");
10894 /* More than one watchpoint may have been triggered. */
10895 return PRINT_UNKNOWN
;
10898 /* Implement the "print_one_detail" breakpoint_ops method for
10899 masked hardware watchpoints. */
10902 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10903 struct ui_out
*uiout
)
10905 struct watchpoint
*w
= (struct watchpoint
*) b
;
10907 /* Masked watchpoints have only one location. */
10908 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10910 ui_out_text (uiout
, "\tmask ");
10911 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10912 ui_out_text (uiout
, "\n");
10915 /* Implement the "print_mention" breakpoint_ops method for
10916 masked hardware watchpoints. */
10919 print_mention_masked_watchpoint (struct breakpoint
*b
)
10921 struct watchpoint
*w
= (struct watchpoint
*) b
;
10922 struct ui_out
*uiout
= current_uiout
;
10923 struct cleanup
*ui_out_chain
;
10927 case bp_hardware_watchpoint
:
10928 ui_out_text (uiout
, "Masked hardware watchpoint ");
10929 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10931 case bp_read_watchpoint
:
10932 ui_out_text (uiout
, "Masked hardware read watchpoint ");
10933 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10935 case bp_access_watchpoint
:
10936 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
10937 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10940 internal_error (__FILE__
, __LINE__
,
10941 _("Invalid hardware watchpoint type."));
10944 ui_out_field_int (uiout
, "number", b
->number
);
10945 ui_out_text (uiout
, ": ");
10946 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10947 do_cleanups (ui_out_chain
);
10950 /* Implement the "print_recreate" breakpoint_ops method for
10951 masked hardware watchpoints. */
10954 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10956 struct watchpoint
*w
= (struct watchpoint
*) b
;
10961 case bp_hardware_watchpoint
:
10962 fprintf_unfiltered (fp
, "watch");
10964 case bp_read_watchpoint
:
10965 fprintf_unfiltered (fp
, "rwatch");
10967 case bp_access_watchpoint
:
10968 fprintf_unfiltered (fp
, "awatch");
10971 internal_error (__FILE__
, __LINE__
,
10972 _("Invalid hardware watchpoint type."));
10975 sprintf_vma (tmp
, w
->hw_wp_mask
);
10976 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10977 print_recreate_thread (b
, fp
);
10980 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10982 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10984 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10987 is_masked_watchpoint (const struct breakpoint
*b
)
10989 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10992 /* accessflag: hw_write: watch write,
10993 hw_read: watch read,
10994 hw_access: watch access (read or write) */
10996 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10997 int just_location
, int internal
)
10999 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
11000 struct expression
*exp
;
11001 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
11002 struct value
*val
, *mark
, *result
;
11003 int saved_bitpos
= 0, saved_bitsize
= 0;
11004 struct frame_info
*frame
;
11005 const char *exp_start
= NULL
;
11006 const char *exp_end
= NULL
;
11007 const char *tok
, *end_tok
;
11009 const char *cond_start
= NULL
;
11010 const char *cond_end
= NULL
;
11011 enum bptype bp_type
;
11014 /* Flag to indicate whether we are going to use masks for
11015 the hardware watchpoint. */
11017 CORE_ADDR mask
= 0;
11018 struct watchpoint
*w
;
11020 struct cleanup
*back_to
;
11022 /* Make sure that we actually have parameters to parse. */
11023 if (arg
!= NULL
&& arg
[0] != '\0')
11025 const char *value_start
;
11027 exp_end
= arg
+ strlen (arg
);
11029 /* Look for "parameter value" pairs at the end
11030 of the arguments string. */
11031 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11033 /* Skip whitespace at the end of the argument list. */
11034 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11037 /* Find the beginning of the last token.
11038 This is the value of the parameter. */
11039 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11041 value_start
= tok
+ 1;
11043 /* Skip whitespace. */
11044 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11049 /* Find the beginning of the second to last token.
11050 This is the parameter itself. */
11051 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11054 toklen
= end_tok
- tok
+ 1;
11056 if (toklen
== 6 && startswith (tok
, "thread"))
11058 /* At this point we've found a "thread" token, which means
11059 the user is trying to set a watchpoint that triggers
11060 only in a specific thread. */
11064 error(_("You can specify only one thread."));
11066 /* Extract the thread ID from the next token. */
11067 thread
= strtol (value_start
, &endp
, 0);
11069 /* Check if the user provided a valid numeric value for the
11071 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11072 error (_("Invalid thread ID specification %s."), value_start
);
11074 /* Check if the thread actually exists. */
11075 if (!valid_thread_id (thread
))
11076 invalid_thread_id_error (thread
);
11078 else if (toklen
== 4 && startswith (tok
, "mask"))
11080 /* We've found a "mask" token, which means the user wants to
11081 create a hardware watchpoint that is going to have the mask
11083 struct value
*mask_value
, *mark
;
11086 error(_("You can specify only one mask."));
11088 use_mask
= just_location
= 1;
11090 mark
= value_mark ();
11091 mask_value
= parse_to_comma_and_eval (&value_start
);
11092 mask
= value_as_address (mask_value
);
11093 value_free_to_mark (mark
);
11096 /* We didn't recognize what we found. We should stop here. */
11099 /* Truncate the string and get rid of the "parameter value" pair before
11100 the arguments string is parsed by the parse_exp_1 function. */
11107 /* Parse the rest of the arguments. From here on out, everything
11108 is in terms of a newly allocated string instead of the original
11110 innermost_block
= NULL
;
11111 expression
= savestring (arg
, exp_end
- arg
);
11112 back_to
= make_cleanup (xfree
, expression
);
11113 exp_start
= arg
= expression
;
11114 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11116 /* Remove trailing whitespace from the expression before saving it.
11117 This makes the eventual display of the expression string a bit
11119 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11122 /* Checking if the expression is not constant. */
11123 if (watchpoint_exp_is_const (exp
))
11127 len
= exp_end
- exp_start
;
11128 while (len
> 0 && isspace (exp_start
[len
- 1]))
11130 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11133 exp_valid_block
= innermost_block
;
11134 mark
= value_mark ();
11135 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11137 if (val
!= NULL
&& just_location
)
11139 saved_bitpos
= value_bitpos (val
);
11140 saved_bitsize
= value_bitsize (val
);
11147 exp_valid_block
= NULL
;
11148 val
= value_addr (result
);
11149 release_value (val
);
11150 value_free_to_mark (mark
);
11154 ret
= target_masked_watch_num_registers (value_as_address (val
),
11157 error (_("This target does not support masked watchpoints."));
11158 else if (ret
== -2)
11159 error (_("Invalid mask or memory region."));
11162 else if (val
!= NULL
)
11163 release_value (val
);
11165 tok
= skip_spaces_const (arg
);
11166 end_tok
= skip_to_space_const (tok
);
11168 toklen
= end_tok
- tok
;
11169 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11171 struct expression
*cond
;
11173 innermost_block
= NULL
;
11174 tok
= cond_start
= end_tok
+ 1;
11175 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11177 /* The watchpoint expression may not be local, but the condition
11178 may still be. E.g.: `watch global if local > 0'. */
11179 cond_exp_valid_block
= innermost_block
;
11185 error (_("Junk at end of command."));
11187 frame
= block_innermost_frame (exp_valid_block
);
11189 /* If the expression is "local", then set up a "watchpoint scope"
11190 breakpoint at the point where we've left the scope of the watchpoint
11191 expression. Create the scope breakpoint before the watchpoint, so
11192 that we will encounter it first in bpstat_stop_status. */
11193 if (exp_valid_block
&& frame
)
11195 if (frame_id_p (frame_unwind_caller_id (frame
)))
11198 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11199 frame_unwind_caller_pc (frame
),
11200 bp_watchpoint_scope
,
11201 &momentary_breakpoint_ops
);
11203 scope_breakpoint
->enable_state
= bp_enabled
;
11205 /* Automatically delete the breakpoint when it hits. */
11206 scope_breakpoint
->disposition
= disp_del
;
11208 /* Only break in the proper frame (help with recursion). */
11209 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11211 /* Set the address at which we will stop. */
11212 scope_breakpoint
->loc
->gdbarch
11213 = frame_unwind_caller_arch (frame
);
11214 scope_breakpoint
->loc
->requested_address
11215 = frame_unwind_caller_pc (frame
);
11216 scope_breakpoint
->loc
->address
11217 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11218 scope_breakpoint
->loc
->requested_address
,
11219 scope_breakpoint
->type
);
11223 /* Now set up the breakpoint. We create all watchpoints as hardware
11224 watchpoints here even if hardware watchpoints are turned off, a call
11225 to update_watchpoint later in this function will cause the type to
11226 drop back to bp_watchpoint (software watchpoint) if required. */
11228 if (accessflag
== hw_read
)
11229 bp_type
= bp_read_watchpoint
;
11230 else if (accessflag
== hw_access
)
11231 bp_type
= bp_access_watchpoint
;
11233 bp_type
= bp_hardware_watchpoint
;
11235 w
= XCNEW (struct watchpoint
);
11238 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11239 &masked_watchpoint_breakpoint_ops
);
11241 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11242 &watchpoint_breakpoint_ops
);
11243 b
->thread
= thread
;
11244 b
->disposition
= disp_donttouch
;
11245 b
->pspace
= current_program_space
;
11247 w
->exp_valid_block
= exp_valid_block
;
11248 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11251 struct type
*t
= value_type (val
);
11252 CORE_ADDR addr
= value_as_address (val
);
11255 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11256 name
= type_to_string (t
);
11258 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11259 core_addr_to_string (addr
));
11262 w
->exp_string
= xstrprintf ("-location %.*s",
11263 (int) (exp_end
- exp_start
), exp_start
);
11265 /* The above expression is in C. */
11266 b
->language
= language_c
;
11269 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11273 w
->hw_wp_mask
= mask
;
11278 w
->val_bitpos
= saved_bitpos
;
11279 w
->val_bitsize
= saved_bitsize
;
11284 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11286 b
->cond_string
= 0;
11290 w
->watchpoint_frame
= get_frame_id (frame
);
11291 w
->watchpoint_thread
= inferior_ptid
;
11295 w
->watchpoint_frame
= null_frame_id
;
11296 w
->watchpoint_thread
= null_ptid
;
11299 if (scope_breakpoint
!= NULL
)
11301 /* The scope breakpoint is related to the watchpoint. We will
11302 need to act on them together. */
11303 b
->related_breakpoint
= scope_breakpoint
;
11304 scope_breakpoint
->related_breakpoint
= b
;
11307 if (!just_location
)
11308 value_free_to_mark (mark
);
11312 /* Finally update the new watchpoint. This creates the locations
11313 that should be inserted. */
11314 update_watchpoint (w
, 1);
11316 CATCH (e
, RETURN_MASK_ALL
)
11318 delete_breakpoint (b
);
11319 throw_exception (e
);
11323 install_breakpoint (internal
, b
, 1);
11324 do_cleanups (back_to
);
11327 /* Return count of debug registers needed to watch the given expression.
11328 If the watchpoint cannot be handled in hardware return zero. */
11331 can_use_hardware_watchpoint (struct value
*v
)
11333 int found_memory_cnt
= 0;
11334 struct value
*head
= v
;
11336 /* Did the user specifically forbid us to use hardware watchpoints? */
11337 if (!can_use_hw_watchpoints
)
11340 /* Make sure that the value of the expression depends only upon
11341 memory contents, and values computed from them within GDB. If we
11342 find any register references or function calls, we can't use a
11343 hardware watchpoint.
11345 The idea here is that evaluating an expression generates a series
11346 of values, one holding the value of every subexpression. (The
11347 expression a*b+c has five subexpressions: a, b, a*b, c, and
11348 a*b+c.) GDB's values hold almost enough information to establish
11349 the criteria given above --- they identify memory lvalues,
11350 register lvalues, computed values, etcetera. So we can evaluate
11351 the expression, and then scan the chain of values that leaves
11352 behind to decide whether we can detect any possible change to the
11353 expression's final value using only hardware watchpoints.
11355 However, I don't think that the values returned by inferior
11356 function calls are special in any way. So this function may not
11357 notice that an expression involving an inferior function call
11358 can't be watched with hardware watchpoints. FIXME. */
11359 for (; v
; v
= value_next (v
))
11361 if (VALUE_LVAL (v
) == lval_memory
)
11363 if (v
!= head
&& value_lazy (v
))
11364 /* A lazy memory lvalue in the chain is one that GDB never
11365 needed to fetch; we either just used its address (e.g.,
11366 `a' in `a.b') or we never needed it at all (e.g., `a'
11367 in `a,b'). This doesn't apply to HEAD; if that is
11368 lazy then it was not readable, but watch it anyway. */
11372 /* Ahh, memory we actually used! Check if we can cover
11373 it with hardware watchpoints. */
11374 struct type
*vtype
= check_typedef (value_type (v
));
11376 /* We only watch structs and arrays if user asked for it
11377 explicitly, never if they just happen to appear in a
11378 middle of some value chain. */
11380 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11381 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11383 CORE_ADDR vaddr
= value_address (v
);
11387 len
= (target_exact_watchpoints
11388 && is_scalar_type_recursive (vtype
))?
11389 1 : TYPE_LENGTH (value_type (v
));
11391 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11395 found_memory_cnt
+= num_regs
;
11399 else if (VALUE_LVAL (v
) != not_lval
11400 && deprecated_value_modifiable (v
) == 0)
11401 return 0; /* These are values from the history (e.g., $1). */
11402 else if (VALUE_LVAL (v
) == lval_register
)
11403 return 0; /* Cannot watch a register with a HW watchpoint. */
11406 /* The expression itself looks suitable for using a hardware
11407 watchpoint, but give the target machine a chance to reject it. */
11408 return found_memory_cnt
;
11412 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11414 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11417 /* A helper function that looks for the "-location" argument and then
11418 calls watch_command_1. */
11421 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11423 int just_location
= 0;
11426 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11427 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11429 arg
= skip_spaces (arg
);
11433 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11437 watch_command (char *arg
, int from_tty
)
11439 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11443 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11445 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11449 rwatch_command (char *arg
, int from_tty
)
11451 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11455 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11457 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11461 awatch_command (char *arg
, int from_tty
)
11463 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11467 /* Helper routines for the until_command routine in infcmd.c. Here
11468 because it uses the mechanisms of breakpoints. */
11470 struct until_break_command_continuation_args
11472 struct breakpoint
*breakpoint
;
11473 struct breakpoint
*breakpoint2
;
11477 /* This function is called by fetch_inferior_event via the
11478 cmd_continuation pointer, to complete the until command. It takes
11479 care of cleaning up the temporary breakpoints set up by the until
11482 until_break_command_continuation (void *arg
, int err
)
11484 struct until_break_command_continuation_args
*a
= arg
;
11486 delete_breakpoint (a
->breakpoint
);
11487 if (a
->breakpoint2
)
11488 delete_breakpoint (a
->breakpoint2
);
11489 delete_longjmp_breakpoint (a
->thread_num
);
11493 until_break_command (char *arg
, int from_tty
, int anywhere
)
11495 struct symtabs_and_lines sals
;
11496 struct symtab_and_line sal
;
11497 struct frame_info
*frame
;
11498 struct gdbarch
*frame_gdbarch
;
11499 struct frame_id stack_frame_id
;
11500 struct frame_id caller_frame_id
;
11501 struct breakpoint
*breakpoint
;
11502 struct breakpoint
*breakpoint2
= NULL
;
11503 struct cleanup
*old_chain
, *cleanup
;
11505 struct thread_info
*tp
;
11506 struct event_location
*location
;
11508 clear_proceed_status (0);
11510 /* Set a breakpoint where the user wants it and at return from
11513 location
= string_to_event_location (&arg
, current_language
);
11514 cleanup
= make_cleanup_delete_event_location (location
);
11516 if (last_displayed_sal_is_valid ())
11517 sals
= decode_line_1 (location
, DECODE_LINE_FUNFIRSTLINE
,
11518 get_last_displayed_symtab (),
11519 get_last_displayed_line ());
11521 sals
= decode_line_1 (location
, DECODE_LINE_FUNFIRSTLINE
,
11522 (struct symtab
*) NULL
, 0);
11524 if (sals
.nelts
!= 1)
11525 error (_("Couldn't get information on specified line."));
11527 sal
= sals
.sals
[0];
11528 xfree (sals
.sals
); /* malloc'd, so freed. */
11531 error (_("Junk at end of arguments."));
11533 resolve_sal_pc (&sal
);
11535 tp
= inferior_thread ();
11538 old_chain
= make_cleanup (null_cleanup
, NULL
);
11540 /* Note linespec handling above invalidates the frame chain.
11541 Installing a breakpoint also invalidates the frame chain (as it
11542 may need to switch threads), so do any frame handling before
11545 frame
= get_selected_frame (NULL
);
11546 frame_gdbarch
= get_frame_arch (frame
);
11547 stack_frame_id
= get_stack_frame_id (frame
);
11548 caller_frame_id
= frame_unwind_caller_id (frame
);
11550 /* Keep within the current frame, or in frames called by the current
11553 if (frame_id_p (caller_frame_id
))
11555 struct symtab_and_line sal2
;
11557 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11558 sal2
.pc
= frame_unwind_caller_pc (frame
);
11559 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
11563 make_cleanup_delete_breakpoint (breakpoint2
);
11565 set_longjmp_breakpoint (tp
, caller_frame_id
);
11566 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11569 /* set_momentary_breakpoint could invalidate FRAME. */
11573 /* If the user told us to continue until a specified location,
11574 we don't specify a frame at which we need to stop. */
11575 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11576 null_frame_id
, bp_until
);
11578 /* Otherwise, specify the selected frame, because we want to stop
11579 only at the very same frame. */
11580 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11581 stack_frame_id
, bp_until
);
11582 make_cleanup_delete_breakpoint (breakpoint
);
11584 proceed (-1, GDB_SIGNAL_DEFAULT
);
11586 /* If we are running asynchronously, and proceed call above has
11587 actually managed to start the target, arrange for breakpoints to
11588 be deleted when the target stops. Otherwise, we're already
11589 stopped and delete breakpoints via cleanup chain. */
11591 if (is_running (inferior_ptid
))
11593 struct until_break_command_continuation_args
*args
=
11594 XNEW (struct until_break_command_continuation_args
);
11596 args
->breakpoint
= breakpoint
;
11597 args
->breakpoint2
= breakpoint2
;
11598 args
->thread_num
= thread
;
11600 discard_cleanups (old_chain
);
11601 add_continuation (inferior_thread (),
11602 until_break_command_continuation
, args
,
11606 do_cleanups (old_chain
);
11608 do_cleanups (cleanup
);
11611 /* This function attempts to parse an optional "if <cond>" clause
11612 from the arg string. If one is not found, it returns NULL.
11614 Else, it returns a pointer to the condition string. (It does not
11615 attempt to evaluate the string against a particular block.) And,
11616 it updates arg to point to the first character following the parsed
11617 if clause in the arg string. */
11620 ep_parse_optional_if_clause (char **arg
)
11624 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11627 /* Skip the "if" keyword. */
11630 /* Skip any extra leading whitespace, and record the start of the
11631 condition string. */
11632 *arg
= skip_spaces (*arg
);
11633 cond_string
= *arg
;
11635 /* Assume that the condition occupies the remainder of the arg
11637 (*arg
) += strlen (cond_string
);
11639 return cond_string
;
11642 /* Commands to deal with catching events, such as signals, exceptions,
11643 process start/exit, etc. */
11647 catch_fork_temporary
, catch_vfork_temporary
,
11648 catch_fork_permanent
, catch_vfork_permanent
11653 catch_fork_command_1 (char *arg
, int from_tty
,
11654 struct cmd_list_element
*command
)
11656 struct gdbarch
*gdbarch
= get_current_arch ();
11657 char *cond_string
= NULL
;
11658 catch_fork_kind fork_kind
;
11661 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11662 tempflag
= (fork_kind
== catch_fork_temporary
11663 || fork_kind
== catch_vfork_temporary
);
11667 arg
= skip_spaces (arg
);
11669 /* The allowed syntax is:
11671 catch [v]fork if <cond>
11673 First, check if there's an if clause. */
11674 cond_string
= ep_parse_optional_if_clause (&arg
);
11676 if ((*arg
!= '\0') && !isspace (*arg
))
11677 error (_("Junk at end of arguments."));
11679 /* If this target supports it, create a fork or vfork catchpoint
11680 and enable reporting of such events. */
11683 case catch_fork_temporary
:
11684 case catch_fork_permanent
:
11685 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11686 &catch_fork_breakpoint_ops
);
11688 case catch_vfork_temporary
:
11689 case catch_vfork_permanent
:
11690 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11691 &catch_vfork_breakpoint_ops
);
11694 error (_("unsupported or unknown fork kind; cannot catch it"));
11700 catch_exec_command_1 (char *arg
, int from_tty
,
11701 struct cmd_list_element
*command
)
11703 struct exec_catchpoint
*c
;
11704 struct gdbarch
*gdbarch
= get_current_arch ();
11706 char *cond_string
= NULL
;
11708 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11712 arg
= skip_spaces (arg
);
11714 /* The allowed syntax is:
11716 catch exec if <cond>
11718 First, check if there's an if clause. */
11719 cond_string
= ep_parse_optional_if_clause (&arg
);
11721 if ((*arg
!= '\0') && !isspace (*arg
))
11722 error (_("Junk at end of arguments."));
11724 c
= XNEW (struct exec_catchpoint
);
11725 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11726 &catch_exec_breakpoint_ops
);
11727 c
->exec_pathname
= NULL
;
11729 install_breakpoint (0, &c
->base
, 1);
11733 init_ada_exception_breakpoint (struct breakpoint
*b
,
11734 struct gdbarch
*gdbarch
,
11735 struct symtab_and_line sal
,
11737 const struct breakpoint_ops
*ops
,
11744 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11746 loc_gdbarch
= gdbarch
;
11748 describe_other_breakpoints (loc_gdbarch
,
11749 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11750 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11751 version for exception catchpoints, because two catchpoints
11752 used for different exception names will use the same address.
11753 In this case, a "breakpoint ... also set at..." warning is
11754 unproductive. Besides, the warning phrasing is also a bit
11755 inappropriate, we should use the word catchpoint, and tell
11756 the user what type of catchpoint it is. The above is good
11757 enough for now, though. */
11760 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11762 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11763 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11764 b
->location
= string_to_event_location (&addr_string
,
11765 language_def (language_ada
));
11766 b
->language
= language_ada
;
11770 catch_command (char *arg
, int from_tty
)
11772 error (_("Catch requires an event name."));
11777 tcatch_command (char *arg
, int from_tty
)
11779 error (_("Catch requires an event name."));
11782 /* A qsort comparison function that sorts breakpoints in order. */
11785 compare_breakpoints (const void *a
, const void *b
)
11787 const breakpoint_p
*ba
= a
;
11788 uintptr_t ua
= (uintptr_t) *ba
;
11789 const breakpoint_p
*bb
= b
;
11790 uintptr_t ub
= (uintptr_t) *bb
;
11792 if ((*ba
)->number
< (*bb
)->number
)
11794 else if ((*ba
)->number
> (*bb
)->number
)
11797 /* Now sort by address, in case we see, e..g, two breakpoints with
11801 return ua
> ub
? 1 : 0;
11804 /* Delete breakpoints by address or line. */
11807 clear_command (char *arg
, int from_tty
)
11809 struct breakpoint
*b
, *prev
;
11810 VEC(breakpoint_p
) *found
= 0;
11813 struct symtabs_and_lines sals
;
11814 struct symtab_and_line sal
;
11816 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11820 sals
= decode_line_with_current_source (arg
,
11821 (DECODE_LINE_FUNFIRSTLINE
11822 | DECODE_LINE_LIST_MODE
));
11823 make_cleanup (xfree
, sals
.sals
);
11828 sals
.sals
= XNEW (struct symtab_and_line
);
11829 make_cleanup (xfree
, sals
.sals
);
11830 init_sal (&sal
); /* Initialize to zeroes. */
11832 /* Set sal's line, symtab, pc, and pspace to the values
11833 corresponding to the last call to print_frame_info. If the
11834 codepoint is not valid, this will set all the fields to 0. */
11835 get_last_displayed_sal (&sal
);
11836 if (sal
.symtab
== 0)
11837 error (_("No source file specified."));
11839 sals
.sals
[0] = sal
;
11845 /* We don't call resolve_sal_pc here. That's not as bad as it
11846 seems, because all existing breakpoints typically have both
11847 file/line and pc set. So, if clear is given file/line, we can
11848 match this to existing breakpoint without obtaining pc at all.
11850 We only support clearing given the address explicitly
11851 present in breakpoint table. Say, we've set breakpoint
11852 at file:line. There were several PC values for that file:line,
11853 due to optimization, all in one block.
11855 We've picked one PC value. If "clear" is issued with another
11856 PC corresponding to the same file:line, the breakpoint won't
11857 be cleared. We probably can still clear the breakpoint, but
11858 since the other PC value is never presented to user, user
11859 can only find it by guessing, and it does not seem important
11860 to support that. */
11862 /* For each line spec given, delete bps which correspond to it. Do
11863 it in two passes, solely to preserve the current behavior that
11864 from_tty is forced true if we delete more than one
11868 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11869 for (i
= 0; i
< sals
.nelts
; i
++)
11871 const char *sal_fullname
;
11873 /* If exact pc given, clear bpts at that pc.
11874 If line given (pc == 0), clear all bpts on specified line.
11875 If defaulting, clear all bpts on default line
11878 defaulting sal.pc != 0 tests to do
11883 1 0 <can't happen> */
11885 sal
= sals
.sals
[i
];
11886 sal_fullname
= (sal
.symtab
== NULL
11887 ? NULL
: symtab_to_fullname (sal
.symtab
));
11889 /* Find all matching breakpoints and add them to 'found'. */
11890 ALL_BREAKPOINTS (b
)
11893 /* Are we going to delete b? */
11894 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11896 struct bp_location
*loc
= b
->loc
;
11897 for (; loc
; loc
= loc
->next
)
11899 /* If the user specified file:line, don't allow a PC
11900 match. This matches historical gdb behavior. */
11901 int pc_match
= (!sal
.explicit_line
11903 && (loc
->pspace
== sal
.pspace
)
11904 && (loc
->address
== sal
.pc
)
11905 && (!section_is_overlay (loc
->section
)
11906 || loc
->section
== sal
.section
));
11907 int line_match
= 0;
11909 if ((default_match
|| sal
.explicit_line
)
11910 && loc
->symtab
!= NULL
11911 && sal_fullname
!= NULL
11912 && sal
.pspace
== loc
->pspace
11913 && loc
->line_number
== sal
.line
11914 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11915 sal_fullname
) == 0)
11918 if (pc_match
|| line_match
)
11927 VEC_safe_push(breakpoint_p
, found
, b
);
11931 /* Now go thru the 'found' chain and delete them. */
11932 if (VEC_empty(breakpoint_p
, found
))
11935 error (_("No breakpoint at %s."), arg
);
11937 error (_("No breakpoint at this line."));
11940 /* Remove duplicates from the vec. */
11941 qsort (VEC_address (breakpoint_p
, found
),
11942 VEC_length (breakpoint_p
, found
),
11943 sizeof (breakpoint_p
),
11944 compare_breakpoints
);
11945 prev
= VEC_index (breakpoint_p
, found
, 0);
11946 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
11950 VEC_ordered_remove (breakpoint_p
, found
, ix
);
11955 if (VEC_length(breakpoint_p
, found
) > 1)
11956 from_tty
= 1; /* Always report if deleted more than one. */
11959 if (VEC_length(breakpoint_p
, found
) == 1)
11960 printf_unfiltered (_("Deleted breakpoint "));
11962 printf_unfiltered (_("Deleted breakpoints "));
11965 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
11968 printf_unfiltered ("%d ", b
->number
);
11969 delete_breakpoint (b
);
11972 putchar_unfiltered ('\n');
11974 do_cleanups (cleanups
);
11977 /* Delete breakpoint in BS if they are `delete' breakpoints and
11978 all breakpoints that are marked for deletion, whether hit or not.
11979 This is called after any breakpoint is hit, or after errors. */
11982 breakpoint_auto_delete (bpstat bs
)
11984 struct breakpoint
*b
, *b_tmp
;
11986 for (; bs
; bs
= bs
->next
)
11987 if (bs
->breakpoint_at
11988 && bs
->breakpoint_at
->disposition
== disp_del
11990 delete_breakpoint (bs
->breakpoint_at
);
11992 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11994 if (b
->disposition
== disp_del_at_next_stop
)
11995 delete_breakpoint (b
);
11999 /* A comparison function for bp_location AP and BP being interfaced to
12000 qsort. Sort elements primarily by their ADDRESS (no matter what
12001 does breakpoint_address_is_meaningful say for its OWNER),
12002 secondarily by ordering first permanent elements and
12003 terciarily just ensuring the array is sorted stable way despite
12004 qsort being an unstable algorithm. */
12007 bp_location_compare (const void *ap
, const void *bp
)
12009 struct bp_location
*a
= *(void **) ap
;
12010 struct bp_location
*b
= *(void **) bp
;
12012 if (a
->address
!= b
->address
)
12013 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12015 /* Sort locations at the same address by their pspace number, keeping
12016 locations of the same inferior (in a multi-inferior environment)
12019 if (a
->pspace
->num
!= b
->pspace
->num
)
12020 return ((a
->pspace
->num
> b
->pspace
->num
)
12021 - (a
->pspace
->num
< b
->pspace
->num
));
12023 /* Sort permanent breakpoints first. */
12024 if (a
->permanent
!= b
->permanent
)
12025 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
12027 /* Make the internal GDB representation stable across GDB runs
12028 where A and B memory inside GDB can differ. Breakpoint locations of
12029 the same type at the same address can be sorted in arbitrary order. */
12031 if (a
->owner
->number
!= b
->owner
->number
)
12032 return ((a
->owner
->number
> b
->owner
->number
)
12033 - (a
->owner
->number
< b
->owner
->number
));
12035 return (a
> b
) - (a
< b
);
12038 /* Set bp_location_placed_address_before_address_max and
12039 bp_location_shadow_len_after_address_max according to the current
12040 content of the bp_location array. */
12043 bp_location_target_extensions_update (void)
12045 struct bp_location
*bl
, **blp_tmp
;
12047 bp_location_placed_address_before_address_max
= 0;
12048 bp_location_shadow_len_after_address_max
= 0;
12050 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12052 CORE_ADDR start
, end
, addr
;
12054 if (!bp_location_has_shadow (bl
))
12057 start
= bl
->target_info
.placed_address
;
12058 end
= start
+ bl
->target_info
.shadow_len
;
12060 gdb_assert (bl
->address
>= start
);
12061 addr
= bl
->address
- start
;
12062 if (addr
> bp_location_placed_address_before_address_max
)
12063 bp_location_placed_address_before_address_max
= addr
;
12065 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12067 gdb_assert (bl
->address
< end
);
12068 addr
= end
- bl
->address
;
12069 if (addr
> bp_location_shadow_len_after_address_max
)
12070 bp_location_shadow_len_after_address_max
= addr
;
12074 /* Download tracepoint locations if they haven't been. */
12077 download_tracepoint_locations (void)
12079 struct breakpoint
*b
;
12080 struct cleanup
*old_chain
;
12082 if (!target_can_download_tracepoint ())
12085 old_chain
= save_current_space_and_thread ();
12087 ALL_TRACEPOINTS (b
)
12089 struct bp_location
*bl
;
12090 struct tracepoint
*t
;
12091 int bp_location_downloaded
= 0;
12093 if ((b
->type
== bp_fast_tracepoint
12094 ? !may_insert_fast_tracepoints
12095 : !may_insert_tracepoints
))
12098 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12100 /* In tracepoint, locations are _never_ duplicated, so
12101 should_be_inserted is equivalent to
12102 unduplicated_should_be_inserted. */
12103 if (!should_be_inserted (bl
) || bl
->inserted
)
12106 switch_to_program_space_and_thread (bl
->pspace
);
12108 target_download_tracepoint (bl
);
12111 bp_location_downloaded
= 1;
12113 t
= (struct tracepoint
*) b
;
12114 t
->number_on_target
= b
->number
;
12115 if (bp_location_downloaded
)
12116 observer_notify_breakpoint_modified (b
);
12119 do_cleanups (old_chain
);
12122 /* Swap the insertion/duplication state between two locations. */
12125 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12127 const int left_inserted
= left
->inserted
;
12128 const int left_duplicate
= left
->duplicate
;
12129 const int left_needs_update
= left
->needs_update
;
12130 const struct bp_target_info left_target_info
= left
->target_info
;
12132 /* Locations of tracepoints can never be duplicated. */
12133 if (is_tracepoint (left
->owner
))
12134 gdb_assert (!left
->duplicate
);
12135 if (is_tracepoint (right
->owner
))
12136 gdb_assert (!right
->duplicate
);
12138 left
->inserted
= right
->inserted
;
12139 left
->duplicate
= right
->duplicate
;
12140 left
->needs_update
= right
->needs_update
;
12141 left
->target_info
= right
->target_info
;
12142 right
->inserted
= left_inserted
;
12143 right
->duplicate
= left_duplicate
;
12144 right
->needs_update
= left_needs_update
;
12145 right
->target_info
= left_target_info
;
12148 /* Force the re-insertion of the locations at ADDRESS. This is called
12149 once a new/deleted/modified duplicate location is found and we are evaluating
12150 conditions on the target's side. Such conditions need to be updated on
12154 force_breakpoint_reinsertion (struct bp_location
*bl
)
12156 struct bp_location
**locp
= NULL
, **loc2p
;
12157 struct bp_location
*loc
;
12158 CORE_ADDR address
= 0;
12161 address
= bl
->address
;
12162 pspace_num
= bl
->pspace
->num
;
12164 /* This is only meaningful if the target is
12165 evaluating conditions and if the user has
12166 opted for condition evaluation on the target's
12168 if (gdb_evaluates_breakpoint_condition_p ()
12169 || !target_supports_evaluation_of_breakpoint_conditions ())
12172 /* Flag all breakpoint locations with this address and
12173 the same program space as the location
12174 as "its condition has changed". We need to
12175 update the conditions on the target's side. */
12176 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12180 if (!is_breakpoint (loc
->owner
)
12181 || pspace_num
!= loc
->pspace
->num
)
12184 /* Flag the location appropriately. We use a different state to
12185 let everyone know that we already updated the set of locations
12186 with addr bl->address and program space bl->pspace. This is so
12187 we don't have to keep calling these functions just to mark locations
12188 that have already been marked. */
12189 loc
->condition_changed
= condition_updated
;
12191 /* Free the agent expression bytecode as well. We will compute
12193 if (loc
->cond_bytecode
)
12195 free_agent_expr (loc
->cond_bytecode
);
12196 loc
->cond_bytecode
= NULL
;
12200 /* Called whether new breakpoints are created, or existing breakpoints
12201 deleted, to update the global location list and recompute which
12202 locations are duplicate of which.
12204 The INSERT_MODE flag determines whether locations may not, may, or
12205 shall be inserted now. See 'enum ugll_insert_mode' for more
12209 update_global_location_list (enum ugll_insert_mode insert_mode
)
12211 struct breakpoint
*b
;
12212 struct bp_location
**locp
, *loc
;
12213 struct cleanup
*cleanups
;
12214 /* Last breakpoint location address that was marked for update. */
12215 CORE_ADDR last_addr
= 0;
12216 /* Last breakpoint location program space that was marked for update. */
12217 int last_pspace_num
= -1;
12219 /* Used in the duplicates detection below. When iterating over all
12220 bp_locations, points to the first bp_location of a given address.
12221 Breakpoints and watchpoints of different types are never
12222 duplicates of each other. Keep one pointer for each type of
12223 breakpoint/watchpoint, so we only need to loop over all locations
12225 struct bp_location
*bp_loc_first
; /* breakpoint */
12226 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12227 struct bp_location
*awp_loc_first
; /* access watchpoint */
12228 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12230 /* Saved former bp_location array which we compare against the newly
12231 built bp_location from the current state of ALL_BREAKPOINTS. */
12232 struct bp_location
**old_location
, **old_locp
;
12233 unsigned old_location_count
;
12235 old_location
= bp_location
;
12236 old_location_count
= bp_location_count
;
12237 bp_location
= NULL
;
12238 bp_location_count
= 0;
12239 cleanups
= make_cleanup (xfree
, old_location
);
12241 ALL_BREAKPOINTS (b
)
12242 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12243 bp_location_count
++;
12245 bp_location
= XNEWVEC (struct bp_location
*, bp_location_count
);
12246 locp
= bp_location
;
12247 ALL_BREAKPOINTS (b
)
12248 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12250 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12251 bp_location_compare
);
12253 bp_location_target_extensions_update ();
12255 /* Identify bp_location instances that are no longer present in the
12256 new list, and therefore should be freed. Note that it's not
12257 necessary that those locations should be removed from inferior --
12258 if there's another location at the same address (previously
12259 marked as duplicate), we don't need to remove/insert the
12262 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12263 and former bp_location array state respectively. */
12265 locp
= bp_location
;
12266 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12269 struct bp_location
*old_loc
= *old_locp
;
12270 struct bp_location
**loc2p
;
12272 /* Tells if 'old_loc' is found among the new locations. If
12273 not, we have to free it. */
12274 int found_object
= 0;
12275 /* Tells if the location should remain inserted in the target. */
12276 int keep_in_target
= 0;
12279 /* Skip LOCP entries which will definitely never be needed.
12280 Stop either at or being the one matching OLD_LOC. */
12281 while (locp
< bp_location
+ bp_location_count
12282 && (*locp
)->address
< old_loc
->address
)
12286 (loc2p
< bp_location
+ bp_location_count
12287 && (*loc2p
)->address
== old_loc
->address
);
12290 /* Check if this is a new/duplicated location or a duplicated
12291 location that had its condition modified. If so, we want to send
12292 its condition to the target if evaluation of conditions is taking
12294 if ((*loc2p
)->condition_changed
== condition_modified
12295 && (last_addr
!= old_loc
->address
12296 || last_pspace_num
!= old_loc
->pspace
->num
))
12298 force_breakpoint_reinsertion (*loc2p
);
12299 last_pspace_num
= old_loc
->pspace
->num
;
12302 if (*loc2p
== old_loc
)
12306 /* We have already handled this address, update it so that we don't
12307 have to go through updates again. */
12308 last_addr
= old_loc
->address
;
12310 /* Target-side condition evaluation: Handle deleted locations. */
12312 force_breakpoint_reinsertion (old_loc
);
12314 /* If this location is no longer present, and inserted, look if
12315 there's maybe a new location at the same address. If so,
12316 mark that one inserted, and don't remove this one. This is
12317 needed so that we don't have a time window where a breakpoint
12318 at certain location is not inserted. */
12320 if (old_loc
->inserted
)
12322 /* If the location is inserted now, we might have to remove
12325 if (found_object
&& should_be_inserted (old_loc
))
12327 /* The location is still present in the location list,
12328 and still should be inserted. Don't do anything. */
12329 keep_in_target
= 1;
12333 /* This location still exists, but it won't be kept in the
12334 target since it may have been disabled. We proceed to
12335 remove its target-side condition. */
12337 /* The location is either no longer present, or got
12338 disabled. See if there's another location at the
12339 same address, in which case we don't need to remove
12340 this one from the target. */
12342 /* OLD_LOC comes from existing struct breakpoint. */
12343 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12346 (loc2p
< bp_location
+ bp_location_count
12347 && (*loc2p
)->address
== old_loc
->address
);
12350 struct bp_location
*loc2
= *loc2p
;
12352 if (breakpoint_locations_match (loc2
, old_loc
))
12354 /* Read watchpoint locations are switched to
12355 access watchpoints, if the former are not
12356 supported, but the latter are. */
12357 if (is_hardware_watchpoint (old_loc
->owner
))
12359 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12360 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12363 /* loc2 is a duplicated location. We need to check
12364 if it should be inserted in case it will be
12366 if (loc2
!= old_loc
12367 && unduplicated_should_be_inserted (loc2
))
12369 swap_insertion (old_loc
, loc2
);
12370 keep_in_target
= 1;
12378 if (!keep_in_target
)
12380 if (remove_breakpoint (old_loc
, mark_uninserted
))
12382 /* This is just about all we can do. We could keep
12383 this location on the global list, and try to
12384 remove it next time, but there's no particular
12385 reason why we will succeed next time.
12387 Note that at this point, old_loc->owner is still
12388 valid, as delete_breakpoint frees the breakpoint
12389 only after calling us. */
12390 printf_filtered (_("warning: Error removing "
12391 "breakpoint %d\n"),
12392 old_loc
->owner
->number
);
12400 if (removed
&& target_is_non_stop_p ()
12401 && need_moribund_for_location_type (old_loc
))
12403 /* This location was removed from the target. In
12404 non-stop mode, a race condition is possible where
12405 we've removed a breakpoint, but stop events for that
12406 breakpoint are already queued and will arrive later.
12407 We apply an heuristic to be able to distinguish such
12408 SIGTRAPs from other random SIGTRAPs: we keep this
12409 breakpoint location for a bit, and will retire it
12410 after we see some number of events. The theory here
12411 is that reporting of events should, "on the average",
12412 be fair, so after a while we'll see events from all
12413 threads that have anything of interest, and no longer
12414 need to keep this breakpoint location around. We
12415 don't hold locations forever so to reduce chances of
12416 mistaking a non-breakpoint SIGTRAP for a breakpoint
12419 The heuristic failing can be disastrous on
12420 decr_pc_after_break targets.
12422 On decr_pc_after_break targets, like e.g., x86-linux,
12423 if we fail to recognize a late breakpoint SIGTRAP,
12424 because events_till_retirement has reached 0 too
12425 soon, we'll fail to do the PC adjustment, and report
12426 a random SIGTRAP to the user. When the user resumes
12427 the inferior, it will most likely immediately crash
12428 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12429 corrupted, because of being resumed e.g., in the
12430 middle of a multi-byte instruction, or skipped a
12431 one-byte instruction. This was actually seen happen
12432 on native x86-linux, and should be less rare on
12433 targets that do not support new thread events, like
12434 remote, due to the heuristic depending on
12437 Mistaking a random SIGTRAP for a breakpoint trap
12438 causes similar symptoms (PC adjustment applied when
12439 it shouldn't), but then again, playing with SIGTRAPs
12440 behind the debugger's back is asking for trouble.
12442 Since hardware watchpoint traps are always
12443 distinguishable from other traps, so we don't need to
12444 apply keep hardware watchpoint moribund locations
12445 around. We simply always ignore hardware watchpoint
12446 traps we can no longer explain. */
12448 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12449 old_loc
->owner
= NULL
;
12451 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12455 old_loc
->owner
= NULL
;
12456 decref_bp_location (&old_loc
);
12461 /* Rescan breakpoints at the same address and section, marking the
12462 first one as "first" and any others as "duplicates". This is so
12463 that the bpt instruction is only inserted once. If we have a
12464 permanent breakpoint at the same place as BPT, make that one the
12465 official one, and the rest as duplicates. Permanent breakpoints
12466 are sorted first for the same address.
12468 Do the same for hardware watchpoints, but also considering the
12469 watchpoint's type (regular/access/read) and length. */
12471 bp_loc_first
= NULL
;
12472 wp_loc_first
= NULL
;
12473 awp_loc_first
= NULL
;
12474 rwp_loc_first
= NULL
;
12475 ALL_BP_LOCATIONS (loc
, locp
)
12477 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12479 struct bp_location
**loc_first_p
;
12482 if (!unduplicated_should_be_inserted (loc
)
12483 || !breakpoint_address_is_meaningful (b
)
12484 /* Don't detect duplicate for tracepoint locations because they are
12485 never duplicated. See the comments in field `duplicate' of
12486 `struct bp_location'. */
12487 || is_tracepoint (b
))
12489 /* Clear the condition modification flag. */
12490 loc
->condition_changed
= condition_unchanged
;
12494 if (b
->type
== bp_hardware_watchpoint
)
12495 loc_first_p
= &wp_loc_first
;
12496 else if (b
->type
== bp_read_watchpoint
)
12497 loc_first_p
= &rwp_loc_first
;
12498 else if (b
->type
== bp_access_watchpoint
)
12499 loc_first_p
= &awp_loc_first
;
12501 loc_first_p
= &bp_loc_first
;
12503 if (*loc_first_p
== NULL
12504 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12505 || !breakpoint_locations_match (loc
, *loc_first_p
))
12507 *loc_first_p
= loc
;
12508 loc
->duplicate
= 0;
12510 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12512 loc
->needs_update
= 1;
12513 /* Clear the condition modification flag. */
12514 loc
->condition_changed
= condition_unchanged
;
12520 /* This and the above ensure the invariant that the first location
12521 is not duplicated, and is the inserted one.
12522 All following are marked as duplicated, and are not inserted. */
12524 swap_insertion (loc
, *loc_first_p
);
12525 loc
->duplicate
= 1;
12527 /* Clear the condition modification flag. */
12528 loc
->condition_changed
= condition_unchanged
;
12531 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12533 if (insert_mode
!= UGLL_DONT_INSERT
)
12534 insert_breakpoint_locations ();
12537 /* Even though the caller told us to not insert new
12538 locations, we may still need to update conditions on the
12539 target's side of breakpoints that were already inserted
12540 if the target is evaluating breakpoint conditions. We
12541 only update conditions for locations that are marked
12543 update_inserted_breakpoint_locations ();
12547 if (insert_mode
!= UGLL_DONT_INSERT
)
12548 download_tracepoint_locations ();
12550 do_cleanups (cleanups
);
12554 breakpoint_retire_moribund (void)
12556 struct bp_location
*loc
;
12559 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12560 if (--(loc
->events_till_retirement
) == 0)
12562 decref_bp_location (&loc
);
12563 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12569 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12574 update_global_location_list (insert_mode
);
12576 CATCH (e
, RETURN_MASK_ERROR
)
12582 /* Clear BKP from a BPS. */
12585 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12589 for (bs
= bps
; bs
; bs
= bs
->next
)
12590 if (bs
->breakpoint_at
== bpt
)
12592 bs
->breakpoint_at
= NULL
;
12593 bs
->old_val
= NULL
;
12594 /* bs->commands will be freed later. */
12598 /* Callback for iterate_over_threads. */
12600 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12602 struct breakpoint
*bpt
= data
;
12604 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12608 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12612 say_where (struct breakpoint
*b
)
12614 struct value_print_options opts
;
12616 get_user_print_options (&opts
);
12618 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12620 if (b
->loc
== NULL
)
12622 /* For pending locations, the output differs slightly based
12623 on b->extra_string. If this is non-NULL, it contains either
12624 a condition or dprintf arguments. */
12625 if (b
->extra_string
== NULL
)
12627 printf_filtered (_(" (%s) pending."),
12628 event_location_to_string (b
->location
));
12630 else if (b
->type
== bp_dprintf
)
12632 printf_filtered (_(" (%s,%s) pending."),
12633 event_location_to_string (b
->location
),
12638 printf_filtered (_(" (%s %s) pending."),
12639 event_location_to_string (b
->location
),
12645 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12647 printf_filtered (" at ");
12648 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12651 if (b
->loc
->symtab
!= NULL
)
12653 /* If there is a single location, we can print the location
12655 if (b
->loc
->next
== NULL
)
12656 printf_filtered (": file %s, line %d.",
12657 symtab_to_filename_for_display (b
->loc
->symtab
),
12658 b
->loc
->line_number
);
12660 /* This is not ideal, but each location may have a
12661 different file name, and this at least reflects the
12662 real situation somewhat. */
12663 printf_filtered (": %s.",
12664 event_location_to_string (b
->location
));
12669 struct bp_location
*loc
= b
->loc
;
12671 for (; loc
; loc
= loc
->next
)
12673 printf_filtered (" (%d locations)", n
);
12678 /* Default bp_location_ops methods. */
12681 bp_location_dtor (struct bp_location
*self
)
12683 xfree (self
->cond
);
12684 if (self
->cond_bytecode
)
12685 free_agent_expr (self
->cond_bytecode
);
12686 xfree (self
->function_name
);
12688 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
12689 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
12692 static const struct bp_location_ops bp_location_ops
=
12697 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12701 base_breakpoint_dtor (struct breakpoint
*self
)
12703 decref_counted_command_line (&self
->commands
);
12704 xfree (self
->cond_string
);
12705 xfree (self
->extra_string
);
12706 xfree (self
->filter
);
12707 delete_event_location (self
->location
);
12708 delete_event_location (self
->location_range_end
);
12711 static struct bp_location
*
12712 base_breakpoint_allocate_location (struct breakpoint
*self
)
12714 struct bp_location
*loc
;
12716 loc
= XNEW (struct bp_location
);
12717 init_bp_location (loc
, &bp_location_ops
, self
);
12722 base_breakpoint_re_set (struct breakpoint
*b
)
12724 /* Nothing to re-set. */
12727 #define internal_error_pure_virtual_called() \
12728 gdb_assert_not_reached ("pure virtual function called")
12731 base_breakpoint_insert_location (struct bp_location
*bl
)
12733 internal_error_pure_virtual_called ();
12737 base_breakpoint_remove_location (struct bp_location
*bl
)
12739 internal_error_pure_virtual_called ();
12743 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12744 struct address_space
*aspace
,
12746 const struct target_waitstatus
*ws
)
12748 internal_error_pure_virtual_called ();
12752 base_breakpoint_check_status (bpstat bs
)
12757 /* A "works_in_software_mode" breakpoint_ops method that just internal
12761 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12763 internal_error_pure_virtual_called ();
12766 /* A "resources_needed" breakpoint_ops method that just internal
12770 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12772 internal_error_pure_virtual_called ();
12775 static enum print_stop_action
12776 base_breakpoint_print_it (bpstat bs
)
12778 internal_error_pure_virtual_called ();
12782 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12783 struct ui_out
*uiout
)
12789 base_breakpoint_print_mention (struct breakpoint
*b
)
12791 internal_error_pure_virtual_called ();
12795 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12797 internal_error_pure_virtual_called ();
12801 base_breakpoint_create_sals_from_location
12802 (const struct event_location
*location
,
12803 struct linespec_result
*canonical
,
12804 enum bptype type_wanted
)
12806 internal_error_pure_virtual_called ();
12810 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12811 struct linespec_result
*c
,
12813 char *extra_string
,
12814 enum bptype type_wanted
,
12815 enum bpdisp disposition
,
12817 int task
, int ignore_count
,
12818 const struct breakpoint_ops
*o
,
12819 int from_tty
, int enabled
,
12820 int internal
, unsigned flags
)
12822 internal_error_pure_virtual_called ();
12826 base_breakpoint_decode_location (struct breakpoint
*b
,
12827 const struct event_location
*location
,
12828 struct symtabs_and_lines
*sals
)
12830 internal_error_pure_virtual_called ();
12833 /* The default 'explains_signal' method. */
12836 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12841 /* The default "after_condition_true" method. */
12844 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12846 /* Nothing to do. */
12849 struct breakpoint_ops base_breakpoint_ops
=
12851 base_breakpoint_dtor
,
12852 base_breakpoint_allocate_location
,
12853 base_breakpoint_re_set
,
12854 base_breakpoint_insert_location
,
12855 base_breakpoint_remove_location
,
12856 base_breakpoint_breakpoint_hit
,
12857 base_breakpoint_check_status
,
12858 base_breakpoint_resources_needed
,
12859 base_breakpoint_works_in_software_mode
,
12860 base_breakpoint_print_it
,
12862 base_breakpoint_print_one_detail
,
12863 base_breakpoint_print_mention
,
12864 base_breakpoint_print_recreate
,
12865 base_breakpoint_create_sals_from_location
,
12866 base_breakpoint_create_breakpoints_sal
,
12867 base_breakpoint_decode_location
,
12868 base_breakpoint_explains_signal
,
12869 base_breakpoint_after_condition_true
,
12872 /* Default breakpoint_ops methods. */
12875 bkpt_re_set (struct breakpoint
*b
)
12877 /* FIXME: is this still reachable? */
12878 if (event_location_empty_p (b
->location
))
12880 /* Anything without a location can't be re-set. */
12881 delete_breakpoint (b
);
12885 breakpoint_re_set_default (b
);
12889 bkpt_insert_location (struct bp_location
*bl
)
12891 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12892 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12894 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12898 bkpt_remove_location (struct bp_location
*bl
)
12900 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12901 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12903 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12907 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12908 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12909 const struct target_waitstatus
*ws
)
12911 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12912 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12915 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12919 if (overlay_debugging
/* unmapped overlay section */
12920 && section_is_overlay (bl
->section
)
12921 && !section_is_mapped (bl
->section
))
12928 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12929 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12930 const struct target_waitstatus
*ws
)
12932 if (dprintf_style
== dprintf_style_agent
12933 && target_can_run_breakpoint_commands ())
12935 /* An agent-style dprintf never causes a stop. If we see a trap
12936 for this address it must be for a breakpoint that happens to
12937 be set at the same address. */
12941 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12945 bkpt_resources_needed (const struct bp_location
*bl
)
12947 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12952 static enum print_stop_action
12953 bkpt_print_it (bpstat bs
)
12955 struct breakpoint
*b
;
12956 const struct bp_location
*bl
;
12958 struct ui_out
*uiout
= current_uiout
;
12960 gdb_assert (bs
->bp_location_at
!= NULL
);
12962 bl
= bs
->bp_location_at
;
12963 b
= bs
->breakpoint_at
;
12965 bp_temp
= b
->disposition
== disp_del
;
12966 if (bl
->address
!= bl
->requested_address
)
12967 breakpoint_adjustment_warning (bl
->requested_address
,
12970 annotate_breakpoint (b
->number
);
12972 ui_out_text (uiout
, "\nTemporary breakpoint ");
12974 ui_out_text (uiout
, "\nBreakpoint ");
12975 if (ui_out_is_mi_like_p (uiout
))
12977 ui_out_field_string (uiout
, "reason",
12978 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12979 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
12981 ui_out_field_int (uiout
, "bkptno", b
->number
);
12982 ui_out_text (uiout
, ", ");
12984 return PRINT_SRC_AND_LOC
;
12988 bkpt_print_mention (struct breakpoint
*b
)
12990 if (ui_out_is_mi_like_p (current_uiout
))
12995 case bp_breakpoint
:
12996 case bp_gnu_ifunc_resolver
:
12997 if (b
->disposition
== disp_del
)
12998 printf_filtered (_("Temporary breakpoint"));
13000 printf_filtered (_("Breakpoint"));
13001 printf_filtered (_(" %d"), b
->number
);
13002 if (b
->type
== bp_gnu_ifunc_resolver
)
13003 printf_filtered (_(" at gnu-indirect-function resolver"));
13005 case bp_hardware_breakpoint
:
13006 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13009 printf_filtered (_("Dprintf %d"), b
->number
);
13017 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13019 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13020 fprintf_unfiltered (fp
, "tbreak");
13021 else if (tp
->type
== bp_breakpoint
)
13022 fprintf_unfiltered (fp
, "break");
13023 else if (tp
->type
== bp_hardware_breakpoint
13024 && tp
->disposition
== disp_del
)
13025 fprintf_unfiltered (fp
, "thbreak");
13026 else if (tp
->type
== bp_hardware_breakpoint
)
13027 fprintf_unfiltered (fp
, "hbreak");
13029 internal_error (__FILE__
, __LINE__
,
13030 _("unhandled breakpoint type %d"), (int) tp
->type
);
13032 fprintf_unfiltered (fp
, " %s",
13033 event_location_to_string (tp
->location
));
13035 /* Print out extra_string if this breakpoint is pending. It might
13036 contain, for example, conditions that were set by the user. */
13037 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
13038 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
13040 print_recreate_thread (tp
, fp
);
13044 bkpt_create_sals_from_location (const struct event_location
*location
,
13045 struct linespec_result
*canonical
,
13046 enum bptype type_wanted
)
13048 create_sals_from_location_default (location
, canonical
, type_wanted
);
13052 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13053 struct linespec_result
*canonical
,
13055 char *extra_string
,
13056 enum bptype type_wanted
,
13057 enum bpdisp disposition
,
13059 int task
, int ignore_count
,
13060 const struct breakpoint_ops
*ops
,
13061 int from_tty
, int enabled
,
13062 int internal
, unsigned flags
)
13064 create_breakpoints_sal_default (gdbarch
, canonical
,
13065 cond_string
, extra_string
,
13067 disposition
, thread
, task
,
13068 ignore_count
, ops
, from_tty
,
13069 enabled
, internal
, flags
);
13073 bkpt_decode_location (struct breakpoint
*b
,
13074 const struct event_location
*location
,
13075 struct symtabs_and_lines
*sals
)
13077 decode_location_default (b
, location
, sals
);
13080 /* Virtual table for internal breakpoints. */
13083 internal_bkpt_re_set (struct breakpoint
*b
)
13087 /* Delete overlay event and longjmp master breakpoints; they
13088 will be reset later by breakpoint_re_set. */
13089 case bp_overlay_event
:
13090 case bp_longjmp_master
:
13091 case bp_std_terminate_master
:
13092 case bp_exception_master
:
13093 delete_breakpoint (b
);
13096 /* This breakpoint is special, it's set up when the inferior
13097 starts and we really don't want to touch it. */
13098 case bp_shlib_event
:
13100 /* Like bp_shlib_event, this breakpoint type is special. Once
13101 it is set up, we do not want to touch it. */
13102 case bp_thread_event
:
13108 internal_bkpt_check_status (bpstat bs
)
13110 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13112 /* If requested, stop when the dynamic linker notifies GDB of
13113 events. This allows the user to get control and place
13114 breakpoints in initializer routines for dynamically loaded
13115 objects (among other things). */
13116 bs
->stop
= stop_on_solib_events
;
13117 bs
->print
= stop_on_solib_events
;
13123 static enum print_stop_action
13124 internal_bkpt_print_it (bpstat bs
)
13126 struct breakpoint
*b
;
13128 b
= bs
->breakpoint_at
;
13132 case bp_shlib_event
:
13133 /* Did we stop because the user set the stop_on_solib_events
13134 variable? (If so, we report this as a generic, "Stopped due
13135 to shlib event" message.) */
13136 print_solib_event (0);
13139 case bp_thread_event
:
13140 /* Not sure how we will get here.
13141 GDB should not stop for these breakpoints. */
13142 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13145 case bp_overlay_event
:
13146 /* By analogy with the thread event, GDB should not stop for these. */
13147 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13150 case bp_longjmp_master
:
13151 /* These should never be enabled. */
13152 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13155 case bp_std_terminate_master
:
13156 /* These should never be enabled. */
13157 printf_filtered (_("std::terminate Master Breakpoint: "
13158 "gdb should not stop!\n"));
13161 case bp_exception_master
:
13162 /* These should never be enabled. */
13163 printf_filtered (_("Exception Master Breakpoint: "
13164 "gdb should not stop!\n"));
13168 return PRINT_NOTHING
;
13172 internal_bkpt_print_mention (struct breakpoint
*b
)
13174 /* Nothing to mention. These breakpoints are internal. */
13177 /* Virtual table for momentary breakpoints */
13180 momentary_bkpt_re_set (struct breakpoint
*b
)
13182 /* Keep temporary breakpoints, which can be encountered when we step
13183 over a dlopen call and solib_add is resetting the breakpoints.
13184 Otherwise these should have been blown away via the cleanup chain
13185 or by breakpoint_init_inferior when we rerun the executable. */
13189 momentary_bkpt_check_status (bpstat bs
)
13191 /* Nothing. The point of these breakpoints is causing a stop. */
13194 static enum print_stop_action
13195 momentary_bkpt_print_it (bpstat bs
)
13197 struct ui_out
*uiout
= current_uiout
;
13199 if (ui_out_is_mi_like_p (uiout
))
13201 struct breakpoint
*b
= bs
->breakpoint_at
;
13206 ui_out_field_string
13208 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
13212 ui_out_field_string
13214 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
13219 return PRINT_UNKNOWN
;
13223 momentary_bkpt_print_mention (struct breakpoint
*b
)
13225 /* Nothing to mention. These breakpoints are internal. */
13228 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13230 It gets cleared already on the removal of the first one of such placed
13231 breakpoints. This is OK as they get all removed altogether. */
13234 longjmp_bkpt_dtor (struct breakpoint
*self
)
13236 struct thread_info
*tp
= find_thread_id (self
->thread
);
13239 tp
->initiating_frame
= null_frame_id
;
13241 momentary_breakpoint_ops
.dtor (self
);
13244 /* Specific methods for probe breakpoints. */
13247 bkpt_probe_insert_location (struct bp_location
*bl
)
13249 int v
= bkpt_insert_location (bl
);
13253 /* The insertion was successful, now let's set the probe's semaphore
13255 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13256 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13265 bkpt_probe_remove_location (struct bp_location
*bl
)
13267 /* Let's clear the semaphore before removing the location. */
13268 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13269 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13273 return bkpt_remove_location (bl
);
13277 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
13278 struct linespec_result
*canonical
,
13279 enum bptype type_wanted
)
13281 struct linespec_sals lsal
;
13283 lsal
.sals
= parse_probes (location
, canonical
);
13284 lsal
.canonical
= xstrdup (event_location_to_string (canonical
->location
));
13285 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13289 bkpt_probe_decode_location (struct breakpoint
*b
,
13290 const struct event_location
*location
,
13291 struct symtabs_and_lines
*sals
)
13293 *sals
= parse_probes (location
, NULL
);
13295 error (_("probe not found"));
13298 /* The breakpoint_ops structure to be used in tracepoints. */
13301 tracepoint_re_set (struct breakpoint
*b
)
13303 breakpoint_re_set_default (b
);
13307 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13308 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13309 const struct target_waitstatus
*ws
)
13311 /* By definition, the inferior does not report stops at
13317 tracepoint_print_one_detail (const struct breakpoint
*self
,
13318 struct ui_out
*uiout
)
13320 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13321 if (tp
->static_trace_marker_id
)
13323 gdb_assert (self
->type
== bp_static_tracepoint
);
13325 ui_out_text (uiout
, "\tmarker id is ");
13326 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13327 tp
->static_trace_marker_id
);
13328 ui_out_text (uiout
, "\n");
13333 tracepoint_print_mention (struct breakpoint
*b
)
13335 if (ui_out_is_mi_like_p (current_uiout
))
13340 case bp_tracepoint
:
13341 printf_filtered (_("Tracepoint"));
13342 printf_filtered (_(" %d"), b
->number
);
13344 case bp_fast_tracepoint
:
13345 printf_filtered (_("Fast tracepoint"));
13346 printf_filtered (_(" %d"), b
->number
);
13348 case bp_static_tracepoint
:
13349 printf_filtered (_("Static tracepoint"));
13350 printf_filtered (_(" %d"), b
->number
);
13353 internal_error (__FILE__
, __LINE__
,
13354 _("unhandled tracepoint type %d"), (int) b
->type
);
13361 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13363 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13365 if (self
->type
== bp_fast_tracepoint
)
13366 fprintf_unfiltered (fp
, "ftrace");
13367 if (self
->type
== bp_static_tracepoint
)
13368 fprintf_unfiltered (fp
, "strace");
13369 else if (self
->type
== bp_tracepoint
)
13370 fprintf_unfiltered (fp
, "trace");
13372 internal_error (__FILE__
, __LINE__
,
13373 _("unhandled tracepoint type %d"), (int) self
->type
);
13375 fprintf_unfiltered (fp
, " %s",
13376 event_location_to_string (self
->location
));
13377 print_recreate_thread (self
, fp
);
13379 if (tp
->pass_count
)
13380 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13384 tracepoint_create_sals_from_location (const struct event_location
*location
,
13385 struct linespec_result
*canonical
,
13386 enum bptype type_wanted
)
13388 create_sals_from_location_default (location
, canonical
, type_wanted
);
13392 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13393 struct linespec_result
*canonical
,
13395 char *extra_string
,
13396 enum bptype type_wanted
,
13397 enum bpdisp disposition
,
13399 int task
, int ignore_count
,
13400 const struct breakpoint_ops
*ops
,
13401 int from_tty
, int enabled
,
13402 int internal
, unsigned flags
)
13404 create_breakpoints_sal_default (gdbarch
, canonical
,
13405 cond_string
, extra_string
,
13407 disposition
, thread
, task
,
13408 ignore_count
, ops
, from_tty
,
13409 enabled
, internal
, flags
);
13413 tracepoint_decode_location (struct breakpoint
*b
,
13414 const struct event_location
*location
,
13415 struct symtabs_and_lines
*sals
)
13417 decode_location_default (b
, location
, sals
);
13420 struct breakpoint_ops tracepoint_breakpoint_ops
;
13422 /* The breakpoint_ops structure to be use on tracepoints placed in a
13426 tracepoint_probe_create_sals_from_location
13427 (const struct event_location
*location
,
13428 struct linespec_result
*canonical
,
13429 enum bptype type_wanted
)
13431 /* We use the same method for breakpoint on probes. */
13432 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13436 tracepoint_probe_decode_location (struct breakpoint
*b
,
13437 const struct event_location
*location
,
13438 struct symtabs_and_lines
*sals
)
13440 /* We use the same method for breakpoint on probes. */
13441 bkpt_probe_decode_location (b
, location
, sals
);
13444 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13446 /* Dprintf breakpoint_ops methods. */
13449 dprintf_re_set (struct breakpoint
*b
)
13451 breakpoint_re_set_default (b
);
13453 /* extra_string should never be non-NULL for dprintf. */
13454 gdb_assert (b
->extra_string
!= NULL
);
13456 /* 1 - connect to target 1, that can run breakpoint commands.
13457 2 - create a dprintf, which resolves fine.
13458 3 - disconnect from target 1
13459 4 - connect to target 2, that can NOT run breakpoint commands.
13461 After steps #3/#4, you'll want the dprintf command list to
13462 be updated, because target 1 and 2 may well return different
13463 answers for target_can_run_breakpoint_commands().
13464 Given absence of finer grained resetting, we get to do
13465 it all the time. */
13466 if (b
->extra_string
!= NULL
)
13467 update_dprintf_command_list (b
);
13470 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13473 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13475 fprintf_unfiltered (fp
, "dprintf %s,%s",
13476 event_location_to_string (tp
->location
),
13478 print_recreate_thread (tp
, fp
);
13481 /* Implement the "after_condition_true" breakpoint_ops method for
13484 dprintf's are implemented with regular commands in their command
13485 list, but we run the commands here instead of before presenting the
13486 stop to the user, as dprintf's don't actually cause a stop. This
13487 also makes it so that the commands of multiple dprintfs at the same
13488 address are all handled. */
13491 dprintf_after_condition_true (struct bpstats
*bs
)
13493 struct cleanup
*old_chain
;
13494 struct bpstats tmp_bs
= { NULL
};
13495 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13497 /* dprintf's never cause a stop. This wasn't set in the
13498 check_status hook instead because that would make the dprintf's
13499 condition not be evaluated. */
13502 /* Run the command list here. Take ownership of it instead of
13503 copying. We never want these commands to run later in
13504 bpstat_do_actions, if a breakpoint that causes a stop happens to
13505 be set at same address as this dprintf, or even if running the
13506 commands here throws. */
13507 tmp_bs
.commands
= bs
->commands
;
13508 bs
->commands
= NULL
;
13509 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13511 bpstat_do_actions_1 (&tmp_bs_p
);
13513 /* 'tmp_bs.commands' will usually be NULL by now, but
13514 bpstat_do_actions_1 may return early without processing the whole
13516 do_cleanups (old_chain
);
13519 /* The breakpoint_ops structure to be used on static tracepoints with
13523 strace_marker_create_sals_from_location (const struct event_location
*location
,
13524 struct linespec_result
*canonical
,
13525 enum bptype type_wanted
)
13527 struct linespec_sals lsal
;
13528 const char *arg_start
, *arg
;
13530 struct cleanup
*cleanup
;
13532 arg
= arg_start
= get_linespec_location (location
);
13533 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13535 str
= savestring (arg_start
, arg
- arg_start
);
13536 cleanup
= make_cleanup (xfree
, str
);
13537 canonical
->location
= new_linespec_location (&str
);
13538 do_cleanups (cleanup
);
13540 lsal
.canonical
= xstrdup (event_location_to_string (canonical
->location
));
13541 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13545 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13546 struct linespec_result
*canonical
,
13548 char *extra_string
,
13549 enum bptype type_wanted
,
13550 enum bpdisp disposition
,
13552 int task
, int ignore_count
,
13553 const struct breakpoint_ops
*ops
,
13554 int from_tty
, int enabled
,
13555 int internal
, unsigned flags
)
13558 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13559 canonical
->sals
, 0);
13561 /* If the user is creating a static tracepoint by marker id
13562 (strace -m MARKER_ID), then store the sals index, so that
13563 breakpoint_re_set can try to match up which of the newly
13564 found markers corresponds to this one, and, don't try to
13565 expand multiple locations for each sal, given than SALS
13566 already should contain all sals for MARKER_ID. */
13568 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13570 struct symtabs_and_lines expanded
;
13571 struct tracepoint
*tp
;
13572 struct cleanup
*old_chain
;
13573 struct event_location
*location
;
13575 expanded
.nelts
= 1;
13576 expanded
.sals
= &lsal
->sals
.sals
[i
];
13578 location
= copy_event_location (canonical
->location
);
13579 old_chain
= make_cleanup_delete_event_location (location
);
13581 tp
= XCNEW (struct tracepoint
);
13582 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13584 cond_string
, extra_string
,
13585 type_wanted
, disposition
,
13586 thread
, task
, ignore_count
, ops
,
13587 from_tty
, enabled
, internal
, flags
,
13588 canonical
->special_display
);
13589 /* Given that its possible to have multiple markers with
13590 the same string id, if the user is creating a static
13591 tracepoint by marker id ("strace -m MARKER_ID"), then
13592 store the sals index, so that breakpoint_re_set can
13593 try to match up which of the newly found markers
13594 corresponds to this one */
13595 tp
->static_trace_marker_id_idx
= i
;
13597 install_breakpoint (internal
, &tp
->base
, 0);
13599 discard_cleanups (old_chain
);
13604 strace_marker_decode_location (struct breakpoint
*b
,
13605 const struct event_location
*location
,
13606 struct symtabs_and_lines
*sals
)
13608 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13609 const char *s
= get_linespec_location (location
);
13611 *sals
= decode_static_tracepoint_spec (&s
);
13612 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13614 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13618 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13621 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13624 strace_marker_p (struct breakpoint
*b
)
13626 return b
->ops
== &strace_marker_breakpoint_ops
;
13629 /* Delete a breakpoint and clean up all traces of it in the data
13633 delete_breakpoint (struct breakpoint
*bpt
)
13635 struct breakpoint
*b
;
13637 gdb_assert (bpt
!= NULL
);
13639 /* Has this bp already been deleted? This can happen because
13640 multiple lists can hold pointers to bp's. bpstat lists are
13643 One example of this happening is a watchpoint's scope bp. When
13644 the scope bp triggers, we notice that the watchpoint is out of
13645 scope, and delete it. We also delete its scope bp. But the
13646 scope bp is marked "auto-deleting", and is already on a bpstat.
13647 That bpstat is then checked for auto-deleting bp's, which are
13650 A real solution to this problem might involve reference counts in
13651 bp's, and/or giving them pointers back to their referencing
13652 bpstat's, and teaching delete_breakpoint to only free a bp's
13653 storage when no more references were extent. A cheaper bandaid
13655 if (bpt
->type
== bp_none
)
13658 /* At least avoid this stale reference until the reference counting
13659 of breakpoints gets resolved. */
13660 if (bpt
->related_breakpoint
!= bpt
)
13662 struct breakpoint
*related
;
13663 struct watchpoint
*w
;
13665 if (bpt
->type
== bp_watchpoint_scope
)
13666 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13667 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13668 w
= (struct watchpoint
*) bpt
;
13672 watchpoint_del_at_next_stop (w
);
13674 /* Unlink bpt from the bpt->related_breakpoint ring. */
13675 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13676 related
= related
->related_breakpoint
);
13677 related
->related_breakpoint
= bpt
->related_breakpoint
;
13678 bpt
->related_breakpoint
= bpt
;
13681 /* watch_command_1 creates a watchpoint but only sets its number if
13682 update_watchpoint succeeds in creating its bp_locations. If there's
13683 a problem in that process, we'll be asked to delete the half-created
13684 watchpoint. In that case, don't announce the deletion. */
13686 observer_notify_breakpoint_deleted (bpt
);
13688 if (breakpoint_chain
== bpt
)
13689 breakpoint_chain
= bpt
->next
;
13691 ALL_BREAKPOINTS (b
)
13692 if (b
->next
== bpt
)
13694 b
->next
= bpt
->next
;
13698 /* Be sure no bpstat's are pointing at the breakpoint after it's
13700 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13701 in all threads for now. Note that we cannot just remove bpstats
13702 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13703 commands are associated with the bpstat; if we remove it here,
13704 then the later call to bpstat_do_actions (&stop_bpstat); in
13705 event-top.c won't do anything, and temporary breakpoints with
13706 commands won't work. */
13708 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13710 /* Now that breakpoint is removed from breakpoint list, update the
13711 global location list. This will remove locations that used to
13712 belong to this breakpoint. Do this before freeing the breakpoint
13713 itself, since remove_breakpoint looks at location's owner. It
13714 might be better design to have location completely
13715 self-contained, but it's not the case now. */
13716 update_global_location_list (UGLL_DONT_INSERT
);
13718 bpt
->ops
->dtor (bpt
);
13719 /* On the chance that someone will soon try again to delete this
13720 same bp, we mark it as deleted before freeing its storage. */
13721 bpt
->type
= bp_none
;
13726 do_delete_breakpoint_cleanup (void *b
)
13728 delete_breakpoint (b
);
13732 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13734 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13737 /* Iterator function to call a user-provided callback function once
13738 for each of B and its related breakpoints. */
13741 iterate_over_related_breakpoints (struct breakpoint
*b
,
13742 void (*function
) (struct breakpoint
*,
13746 struct breakpoint
*related
;
13751 struct breakpoint
*next
;
13753 /* FUNCTION may delete RELATED. */
13754 next
= related
->related_breakpoint
;
13756 if (next
== related
)
13758 /* RELATED is the last ring entry. */
13759 function (related
, data
);
13761 /* FUNCTION may have deleted it, so we'd never reach back to
13762 B. There's nothing left to do anyway, so just break
13767 function (related
, data
);
13771 while (related
!= b
);
13775 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13777 delete_breakpoint (b
);
13780 /* A callback for map_breakpoint_numbers that calls
13781 delete_breakpoint. */
13784 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13786 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13790 delete_command (char *arg
, int from_tty
)
13792 struct breakpoint
*b
, *b_tmp
;
13798 int breaks_to_delete
= 0;
13800 /* Delete all breakpoints if no argument. Do not delete
13801 internal breakpoints, these have to be deleted with an
13802 explicit breakpoint number argument. */
13803 ALL_BREAKPOINTS (b
)
13804 if (user_breakpoint_p (b
))
13806 breaks_to_delete
= 1;
13810 /* Ask user only if there are some breakpoints to delete. */
13812 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13814 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13815 if (user_breakpoint_p (b
))
13816 delete_breakpoint (b
);
13820 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13824 all_locations_are_pending (struct bp_location
*loc
)
13826 for (; loc
; loc
= loc
->next
)
13827 if (!loc
->shlib_disabled
13828 && !loc
->pspace
->executing_startup
)
13833 /* Subroutine of update_breakpoint_locations to simplify it.
13834 Return non-zero if multiple fns in list LOC have the same name.
13835 Null names are ignored. */
13838 ambiguous_names_p (struct bp_location
*loc
)
13840 struct bp_location
*l
;
13841 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13842 (int (*) (const void *,
13843 const void *)) streq
,
13844 NULL
, xcalloc
, xfree
);
13846 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13849 const char *name
= l
->function_name
;
13851 /* Allow for some names to be NULL, ignore them. */
13855 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13857 /* NOTE: We can assume slot != NULL here because xcalloc never
13861 htab_delete (htab
);
13867 htab_delete (htab
);
13871 /* When symbols change, it probably means the sources changed as well,
13872 and it might mean the static tracepoint markers are no longer at
13873 the same address or line numbers they used to be at last we
13874 checked. Losing your static tracepoints whenever you rebuild is
13875 undesirable. This function tries to resync/rematch gdb static
13876 tracepoints with the markers on the target, for static tracepoints
13877 that have not been set by marker id. Static tracepoint that have
13878 been set by marker id are reset by marker id in breakpoint_re_set.
13881 1) For a tracepoint set at a specific address, look for a marker at
13882 the old PC. If one is found there, assume to be the same marker.
13883 If the name / string id of the marker found is different from the
13884 previous known name, assume that means the user renamed the marker
13885 in the sources, and output a warning.
13887 2) For a tracepoint set at a given line number, look for a marker
13888 at the new address of the old line number. If one is found there,
13889 assume to be the same marker. If the name / string id of the
13890 marker found is different from the previous known name, assume that
13891 means the user renamed the marker in the sources, and output a
13894 3) If a marker is no longer found at the same address or line, it
13895 may mean the marker no longer exists. But it may also just mean
13896 the code changed a bit. Maybe the user added a few lines of code
13897 that made the marker move up or down (in line number terms). Ask
13898 the target for info about the marker with the string id as we knew
13899 it. If found, update line number and address in the matching
13900 static tracepoint. This will get confused if there's more than one
13901 marker with the same ID (possible in UST, although unadvised
13902 precisely because it confuses tools). */
13904 static struct symtab_and_line
13905 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13907 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13908 struct static_tracepoint_marker marker
;
13913 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13915 if (target_static_tracepoint_marker_at (pc
, &marker
))
13917 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13918 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13920 tp
->static_trace_marker_id
, marker
.str_id
);
13922 xfree (tp
->static_trace_marker_id
);
13923 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13924 release_static_tracepoint_marker (&marker
);
13929 /* Old marker wasn't found on target at lineno. Try looking it up
13931 if (!sal
.explicit_pc
13933 && sal
.symtab
!= NULL
13934 && tp
->static_trace_marker_id
!= NULL
)
13936 VEC(static_tracepoint_marker_p
) *markers
;
13939 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13941 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13943 struct symtab_and_line sal2
;
13944 struct symbol
*sym
;
13945 struct static_tracepoint_marker
*tpmarker
;
13946 struct ui_out
*uiout
= current_uiout
;
13947 struct explicit_location explicit_loc
;
13949 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13951 xfree (tp
->static_trace_marker_id
);
13952 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13954 warning (_("marker for static tracepoint %d (%s) not "
13955 "found at previous line number"),
13956 b
->number
, tp
->static_trace_marker_id
);
13960 sal2
.pc
= tpmarker
->address
;
13962 sal2
= find_pc_line (tpmarker
->address
, 0);
13963 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13964 ui_out_text (uiout
, "Now in ");
13967 ui_out_field_string (uiout
, "func",
13968 SYMBOL_PRINT_NAME (sym
));
13969 ui_out_text (uiout
, " at ");
13971 ui_out_field_string (uiout
, "file",
13972 symtab_to_filename_for_display (sal2
.symtab
));
13973 ui_out_text (uiout
, ":");
13975 if (ui_out_is_mi_like_p (uiout
))
13977 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13979 ui_out_field_string (uiout
, "fullname", fullname
);
13982 ui_out_field_int (uiout
, "line", sal2
.line
);
13983 ui_out_text (uiout
, "\n");
13985 b
->loc
->line_number
= sal2
.line
;
13986 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13988 delete_event_location (b
->location
);
13989 initialize_explicit_location (&explicit_loc
);
13990 explicit_loc
.source_filename
13991 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13992 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13993 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13994 b
->location
= new_explicit_location (&explicit_loc
);
13996 /* Might be nice to check if function changed, and warn if
13999 release_static_tracepoint_marker (tpmarker
);
14005 /* Returns 1 iff locations A and B are sufficiently same that
14006 we don't need to report breakpoint as changed. */
14009 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14013 if (a
->address
!= b
->address
)
14016 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14019 if (a
->enabled
!= b
->enabled
)
14026 if ((a
== NULL
) != (b
== NULL
))
14032 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14033 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14034 a ranged breakpoint. */
14037 update_breakpoint_locations (struct breakpoint
*b
,
14038 struct symtabs_and_lines sals
,
14039 struct symtabs_and_lines sals_end
)
14042 struct bp_location
*existing_locations
= b
->loc
;
14044 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14046 /* Ranged breakpoints have only one start location and one end
14048 b
->enable_state
= bp_disabled
;
14049 update_global_location_list (UGLL_MAY_INSERT
);
14050 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14051 "multiple locations found\n"),
14056 /* If there's no new locations, and all existing locations are
14057 pending, don't do anything. This optimizes the common case where
14058 all locations are in the same shared library, that was unloaded.
14059 We'd like to retain the location, so that when the library is
14060 loaded again, we don't loose the enabled/disabled status of the
14061 individual locations. */
14062 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
14067 for (i
= 0; i
< sals
.nelts
; ++i
)
14069 struct bp_location
*new_loc
;
14071 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14073 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14075 /* Reparse conditions, they might contain references to the
14077 if (b
->cond_string
!= NULL
)
14081 s
= b
->cond_string
;
14084 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14085 block_for_pc (sals
.sals
[i
].pc
),
14088 CATCH (e
, RETURN_MASK_ERROR
)
14090 warning (_("failed to reevaluate condition "
14091 "for breakpoint %d: %s"),
14092 b
->number
, e
.message
);
14093 new_loc
->enabled
= 0;
14098 if (sals_end
.nelts
)
14100 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14102 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14106 /* If possible, carry over 'disable' status from existing
14109 struct bp_location
*e
= existing_locations
;
14110 /* If there are multiple breakpoints with the same function name,
14111 e.g. for inline functions, comparing function names won't work.
14112 Instead compare pc addresses; this is just a heuristic as things
14113 may have moved, but in practice it gives the correct answer
14114 often enough until a better solution is found. */
14115 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14117 for (; e
; e
= e
->next
)
14119 if (!e
->enabled
&& e
->function_name
)
14121 struct bp_location
*l
= b
->loc
;
14122 if (have_ambiguous_names
)
14124 for (; l
; l
= l
->next
)
14125 if (breakpoint_locations_match (e
, l
))
14133 for (; l
; l
= l
->next
)
14134 if (l
->function_name
14135 && strcmp (e
->function_name
, l
->function_name
) == 0)
14145 if (!locations_are_equal (existing_locations
, b
->loc
))
14146 observer_notify_breakpoint_modified (b
);
14148 update_global_location_list (UGLL_MAY_INSERT
);
14151 /* Find the SaL locations corresponding to the given LOCATION.
14152 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14154 static struct symtabs_and_lines
14155 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
14158 struct symtabs_and_lines sals
= {0};
14159 struct gdb_exception exception
= exception_none
;
14161 gdb_assert (b
->ops
!= NULL
);
14165 b
->ops
->decode_location (b
, location
, &sals
);
14167 CATCH (e
, RETURN_MASK_ERROR
)
14169 int not_found_and_ok
= 0;
14173 /* For pending breakpoints, it's expected that parsing will
14174 fail until the right shared library is loaded. User has
14175 already told to create pending breakpoints and don't need
14176 extra messages. If breakpoint is in bp_shlib_disabled
14177 state, then user already saw the message about that
14178 breakpoint being disabled, and don't want to see more
14180 if (e
.error
== NOT_FOUND_ERROR
14181 && (b
->condition_not_parsed
14182 || (b
->loc
&& b
->loc
->shlib_disabled
)
14183 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14184 || b
->enable_state
== bp_disabled
))
14185 not_found_and_ok
= 1;
14187 if (!not_found_and_ok
)
14189 /* We surely don't want to warn about the same breakpoint
14190 10 times. One solution, implemented here, is disable
14191 the breakpoint on error. Another solution would be to
14192 have separate 'warning emitted' flag. Since this
14193 happens only when a binary has changed, I don't know
14194 which approach is better. */
14195 b
->enable_state
= bp_disabled
;
14196 throw_exception (e
);
14201 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14205 for (i
= 0; i
< sals
.nelts
; ++i
)
14206 resolve_sal_pc (&sals
.sals
[i
]);
14207 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
14209 char *cond_string
, *extra_string
;
14212 find_condition_and_thread (b
->extra_string
, sals
.sals
[0].pc
,
14213 &cond_string
, &thread
, &task
,
14215 gdb_assert (b
->cond_string
== NULL
);
14217 b
->cond_string
= cond_string
;
14218 b
->thread
= thread
;
14222 xfree (b
->extra_string
);
14223 b
->extra_string
= extra_string
;
14225 b
->condition_not_parsed
= 0;
14228 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14229 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14239 /* The default re_set method, for typical hardware or software
14240 breakpoints. Reevaluate the breakpoint and recreate its
14244 breakpoint_re_set_default (struct breakpoint
*b
)
14247 struct symtabs_and_lines sals
, sals_end
;
14248 struct symtabs_and_lines expanded
= {0};
14249 struct symtabs_and_lines expanded_end
= {0};
14251 sals
= location_to_sals (b
, b
->location
, &found
);
14254 make_cleanup (xfree
, sals
.sals
);
14258 if (b
->location_range_end
!= NULL
)
14260 sals_end
= location_to_sals (b
, b
->location_range_end
, &found
);
14263 make_cleanup (xfree
, sals_end
.sals
);
14264 expanded_end
= sals_end
;
14268 update_breakpoint_locations (b
, expanded
, expanded_end
);
14271 /* Default method for creating SALs from an address string. It basically
14272 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14275 create_sals_from_location_default (const struct event_location
*location
,
14276 struct linespec_result
*canonical
,
14277 enum bptype type_wanted
)
14279 parse_breakpoint_sals (location
, canonical
);
14282 /* Call create_breakpoints_sal for the given arguments. This is the default
14283 function for the `create_breakpoints_sal' method of
14287 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14288 struct linespec_result
*canonical
,
14290 char *extra_string
,
14291 enum bptype type_wanted
,
14292 enum bpdisp disposition
,
14294 int task
, int ignore_count
,
14295 const struct breakpoint_ops
*ops
,
14296 int from_tty
, int enabled
,
14297 int internal
, unsigned flags
)
14299 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14301 type_wanted
, disposition
,
14302 thread
, task
, ignore_count
, ops
, from_tty
,
14303 enabled
, internal
, flags
);
14306 /* Decode the line represented by S by calling decode_line_full. This is the
14307 default function for the `decode_location' method of breakpoint_ops. */
14310 decode_location_default (struct breakpoint
*b
,
14311 const struct event_location
*location
,
14312 struct symtabs_and_lines
*sals
)
14314 struct linespec_result canonical
;
14316 init_linespec_result (&canonical
);
14317 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
,
14318 (struct symtab
*) NULL
, 0,
14319 &canonical
, multiple_symbols_all
,
14322 /* We should get 0 or 1 resulting SALs. */
14323 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14325 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14327 struct linespec_sals
*lsal
;
14329 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14330 *sals
= lsal
->sals
;
14331 /* Arrange it so the destructor does not free the
14333 lsal
->sals
.sals
= NULL
;
14336 destroy_linespec_result (&canonical
);
14339 /* Prepare the global context for a re-set of breakpoint B. */
14341 static struct cleanup
*
14342 prepare_re_set_context (struct breakpoint
*b
)
14344 struct cleanup
*cleanups
;
14346 input_radix
= b
->input_radix
;
14347 cleanups
= save_current_space_and_thread ();
14348 if (b
->pspace
!= NULL
)
14349 switch_to_program_space_and_thread (b
->pspace
);
14350 set_language (b
->language
);
14355 /* Reset a breakpoint given it's struct breakpoint * BINT.
14356 The value we return ends up being the return value from catch_errors.
14357 Unused in this case. */
14360 breakpoint_re_set_one (void *bint
)
14362 /* Get past catch_errs. */
14363 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14364 struct cleanup
*cleanups
;
14366 cleanups
= prepare_re_set_context (b
);
14367 b
->ops
->re_set (b
);
14368 do_cleanups (cleanups
);
14372 /* Re-set all breakpoints after symbols have been re-loaded. */
14374 breakpoint_re_set (void)
14376 struct breakpoint
*b
, *b_tmp
;
14377 enum language save_language
;
14378 int save_input_radix
;
14379 struct cleanup
*old_chain
;
14381 save_language
= current_language
->la_language
;
14382 save_input_radix
= input_radix
;
14383 old_chain
= save_current_program_space ();
14385 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14387 /* Format possible error msg. */
14388 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14390 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14391 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14392 do_cleanups (cleanups
);
14394 set_language (save_language
);
14395 input_radix
= save_input_radix
;
14397 jit_breakpoint_re_set ();
14399 do_cleanups (old_chain
);
14401 create_overlay_event_breakpoint ();
14402 create_longjmp_master_breakpoint ();
14403 create_std_terminate_master_breakpoint ();
14404 create_exception_master_breakpoint ();
14407 /* Reset the thread number of this breakpoint:
14409 - If the breakpoint is for all threads, leave it as-is.
14410 - Else, reset it to the current thread for inferior_ptid. */
14412 breakpoint_re_set_thread (struct breakpoint
*b
)
14414 if (b
->thread
!= -1)
14416 if (in_thread_list (inferior_ptid
))
14417 b
->thread
= pid_to_thread_id (inferior_ptid
);
14419 /* We're being called after following a fork. The new fork is
14420 selected as current, and unless this was a vfork will have a
14421 different program space from the original thread. Reset that
14423 b
->loc
->pspace
= current_program_space
;
14427 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14428 If from_tty is nonzero, it prints a message to that effect,
14429 which ends with a period (no newline). */
14432 set_ignore_count (int bptnum
, int count
, int from_tty
)
14434 struct breakpoint
*b
;
14439 ALL_BREAKPOINTS (b
)
14440 if (b
->number
== bptnum
)
14442 if (is_tracepoint (b
))
14444 if (from_tty
&& count
!= 0)
14445 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14450 b
->ignore_count
= count
;
14454 printf_filtered (_("Will stop next time "
14455 "breakpoint %d is reached."),
14457 else if (count
== 1)
14458 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14461 printf_filtered (_("Will ignore next %d "
14462 "crossings of breakpoint %d."),
14465 observer_notify_breakpoint_modified (b
);
14469 error (_("No breakpoint number %d."), bptnum
);
14472 /* Command to set ignore-count of breakpoint N to COUNT. */
14475 ignore_command (char *args
, int from_tty
)
14481 error_no_arg (_("a breakpoint number"));
14483 num
= get_number (&p
);
14485 error (_("bad breakpoint number: '%s'"), args
);
14487 error (_("Second argument (specified ignore-count) is missing."));
14489 set_ignore_count (num
,
14490 longest_to_int (value_as_long (parse_and_eval (p
))),
14493 printf_filtered ("\n");
14496 /* Call FUNCTION on each of the breakpoints
14497 whose numbers are given in ARGS. */
14500 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14505 struct breakpoint
*b
, *tmp
;
14507 struct get_number_or_range_state state
;
14509 if (args
== 0 || *args
== '\0')
14510 error_no_arg (_("one or more breakpoint numbers"));
14512 init_number_or_range (&state
, args
);
14514 while (!state
.finished
)
14516 const char *p
= state
.string
;
14520 num
= get_number_or_range (&state
);
14523 warning (_("bad breakpoint number at or near '%s'"), p
);
14527 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14528 if (b
->number
== num
)
14531 function (b
, data
);
14535 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14540 static struct bp_location
*
14541 find_location_by_number (char *number
)
14543 char *dot
= strchr (number
, '.');
14547 struct breakpoint
*b
;
14548 struct bp_location
*loc
;
14553 bp_num
= get_number (&p1
);
14555 error (_("Bad breakpoint number '%s'"), number
);
14557 ALL_BREAKPOINTS (b
)
14558 if (b
->number
== bp_num
)
14563 if (!b
|| b
->number
!= bp_num
)
14564 error (_("Bad breakpoint number '%s'"), number
);
14567 loc_num
= get_number (&p1
);
14569 error (_("Bad breakpoint location number '%s'"), number
);
14573 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14576 error (_("Bad breakpoint location number '%s'"), dot
+1);
14582 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14583 If from_tty is nonzero, it prints a message to that effect,
14584 which ends with a period (no newline). */
14587 disable_breakpoint (struct breakpoint
*bpt
)
14589 /* Never disable a watchpoint scope breakpoint; we want to
14590 hit them when we leave scope so we can delete both the
14591 watchpoint and its scope breakpoint at that time. */
14592 if (bpt
->type
== bp_watchpoint_scope
)
14595 bpt
->enable_state
= bp_disabled
;
14597 /* Mark breakpoint locations modified. */
14598 mark_breakpoint_modified (bpt
);
14600 if (target_supports_enable_disable_tracepoint ()
14601 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14603 struct bp_location
*location
;
14605 for (location
= bpt
->loc
; location
; location
= location
->next
)
14606 target_disable_tracepoint (location
);
14609 update_global_location_list (UGLL_DONT_INSERT
);
14611 observer_notify_breakpoint_modified (bpt
);
14614 /* A callback for iterate_over_related_breakpoints. */
14617 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14619 disable_breakpoint (b
);
14622 /* A callback for map_breakpoint_numbers that calls
14623 disable_breakpoint. */
14626 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14628 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14632 disable_command (char *args
, int from_tty
)
14636 struct breakpoint
*bpt
;
14638 ALL_BREAKPOINTS (bpt
)
14639 if (user_breakpoint_p (bpt
))
14640 disable_breakpoint (bpt
);
14644 char *num
= extract_arg (&args
);
14648 if (strchr (num
, '.'))
14650 struct bp_location
*loc
= find_location_by_number (num
);
14657 mark_breakpoint_location_modified (loc
);
14659 if (target_supports_enable_disable_tracepoint ()
14660 && current_trace_status ()->running
&& loc
->owner
14661 && is_tracepoint (loc
->owner
))
14662 target_disable_tracepoint (loc
);
14664 update_global_location_list (UGLL_DONT_INSERT
);
14667 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14668 num
= extract_arg (&args
);
14674 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14677 int target_resources_ok
;
14679 if (bpt
->type
== bp_hardware_breakpoint
)
14682 i
= hw_breakpoint_used_count ();
14683 target_resources_ok
=
14684 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14686 if (target_resources_ok
== 0)
14687 error (_("No hardware breakpoint support in the target."));
14688 else if (target_resources_ok
< 0)
14689 error (_("Hardware breakpoints used exceeds limit."));
14692 if (is_watchpoint (bpt
))
14694 /* Initialize it just to avoid a GCC false warning. */
14695 enum enable_state orig_enable_state
= bp_disabled
;
14699 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14701 orig_enable_state
= bpt
->enable_state
;
14702 bpt
->enable_state
= bp_enabled
;
14703 update_watchpoint (w
, 1 /* reparse */);
14705 CATCH (e
, RETURN_MASK_ALL
)
14707 bpt
->enable_state
= orig_enable_state
;
14708 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14715 bpt
->enable_state
= bp_enabled
;
14717 /* Mark breakpoint locations modified. */
14718 mark_breakpoint_modified (bpt
);
14720 if (target_supports_enable_disable_tracepoint ()
14721 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14723 struct bp_location
*location
;
14725 for (location
= bpt
->loc
; location
; location
= location
->next
)
14726 target_enable_tracepoint (location
);
14729 bpt
->disposition
= disposition
;
14730 bpt
->enable_count
= count
;
14731 update_global_location_list (UGLL_MAY_INSERT
);
14733 observer_notify_breakpoint_modified (bpt
);
14738 enable_breakpoint (struct breakpoint
*bpt
)
14740 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14744 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14746 enable_breakpoint (bpt
);
14749 /* A callback for map_breakpoint_numbers that calls
14750 enable_breakpoint. */
14753 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14755 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14758 /* The enable command enables the specified breakpoints (or all defined
14759 breakpoints) so they once again become (or continue to be) effective
14760 in stopping the inferior. */
14763 enable_command (char *args
, int from_tty
)
14767 struct breakpoint
*bpt
;
14769 ALL_BREAKPOINTS (bpt
)
14770 if (user_breakpoint_p (bpt
))
14771 enable_breakpoint (bpt
);
14775 char *num
= extract_arg (&args
);
14779 if (strchr (num
, '.'))
14781 struct bp_location
*loc
= find_location_by_number (num
);
14788 mark_breakpoint_location_modified (loc
);
14790 if (target_supports_enable_disable_tracepoint ()
14791 && current_trace_status ()->running
&& loc
->owner
14792 && is_tracepoint (loc
->owner
))
14793 target_enable_tracepoint (loc
);
14795 update_global_location_list (UGLL_MAY_INSERT
);
14798 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
14799 num
= extract_arg (&args
);
14804 /* This struct packages up disposition data for application to multiple
14814 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14816 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14818 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14822 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14824 struct disp_data disp
= { disp_disable
, 1 };
14826 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14830 enable_once_command (char *args
, int from_tty
)
14832 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14836 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14838 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14840 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14844 enable_count_command (char *args
, int from_tty
)
14849 error_no_arg (_("hit count"));
14851 count
= get_number (&args
);
14853 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
14857 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14859 struct disp_data disp
= { disp_del
, 1 };
14861 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14865 enable_delete_command (char *args
, int from_tty
)
14867 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
14871 set_breakpoint_cmd (char *args
, int from_tty
)
14876 show_breakpoint_cmd (char *args
, int from_tty
)
14880 /* Invalidate last known value of any hardware watchpoint if
14881 the memory which that value represents has been written to by
14885 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14886 CORE_ADDR addr
, ssize_t len
,
14887 const bfd_byte
*data
)
14889 struct breakpoint
*bp
;
14891 ALL_BREAKPOINTS (bp
)
14892 if (bp
->enable_state
== bp_enabled
14893 && bp
->type
== bp_hardware_watchpoint
)
14895 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14897 if (wp
->val_valid
&& wp
->val
)
14899 struct bp_location
*loc
;
14901 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14902 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14903 && loc
->address
+ loc
->length
> addr
14904 && addr
+ len
> loc
->address
)
14906 value_free (wp
->val
);
14914 /* Create and insert a breakpoint for software single step. */
14917 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14918 struct address_space
*aspace
,
14921 struct thread_info
*tp
= inferior_thread ();
14922 struct symtab_and_line sal
;
14923 CORE_ADDR pc
= next_pc
;
14925 if (tp
->control
.single_step_breakpoints
== NULL
)
14927 tp
->control
.single_step_breakpoints
14928 = new_single_step_breakpoint (tp
->num
, gdbarch
);
14931 sal
= find_pc_line (pc
, 0);
14933 sal
.section
= find_pc_overlay (pc
);
14934 sal
.explicit_pc
= 1;
14935 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14937 update_global_location_list (UGLL_INSERT
);
14940 /* See breakpoint.h. */
14943 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14944 struct address_space
*aspace
,
14947 struct bp_location
*loc
;
14949 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14951 && breakpoint_location_address_match (loc
, aspace
, pc
))
14957 /* Check whether a software single-step breakpoint is inserted at
14961 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
14964 struct breakpoint
*bpt
;
14966 ALL_BREAKPOINTS (bpt
)
14968 if (bpt
->type
== bp_single_step
14969 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14975 /* Tracepoint-specific operations. */
14977 /* Set tracepoint count to NUM. */
14979 set_tracepoint_count (int num
)
14981 tracepoint_count
= num
;
14982 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14986 trace_command (char *arg
, int from_tty
)
14988 struct breakpoint_ops
*ops
;
14989 struct event_location
*location
;
14990 struct cleanup
*back_to
;
14992 location
= string_to_event_location (&arg
, current_language
);
14993 back_to
= make_cleanup_delete_event_location (location
);
14994 if (location
!= NULL
14995 && event_location_type (location
) == PROBE_LOCATION
)
14996 ops
= &tracepoint_probe_breakpoint_ops
;
14998 ops
= &tracepoint_breakpoint_ops
;
15000 create_breakpoint (get_current_arch (),
15002 NULL
, 0, arg
, 1 /* parse arg */,
15004 bp_tracepoint
/* type_wanted */,
15005 0 /* Ignore count */,
15006 pending_break_support
,
15010 0 /* internal */, 0);
15011 do_cleanups (back_to
);
15015 ftrace_command (char *arg
, int from_tty
)
15017 struct event_location
*location
;
15018 struct cleanup
*back_to
;
15020 location
= string_to_event_location (&arg
, current_language
);
15021 back_to
= make_cleanup_delete_event_location (location
);
15022 create_breakpoint (get_current_arch (),
15024 NULL
, 0, arg
, 1 /* parse arg */,
15026 bp_fast_tracepoint
/* type_wanted */,
15027 0 /* Ignore count */,
15028 pending_break_support
,
15029 &tracepoint_breakpoint_ops
,
15032 0 /* internal */, 0);
15033 do_cleanups (back_to
);
15036 /* strace command implementation. Creates a static tracepoint. */
15039 strace_command (char *arg
, int from_tty
)
15041 struct breakpoint_ops
*ops
;
15042 struct event_location
*location
;
15043 struct cleanup
*back_to
;
15045 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15046 or with a normal static tracepoint. */
15047 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
15049 ops
= &strace_marker_breakpoint_ops
;
15050 location
= new_linespec_location (&arg
);
15054 ops
= &tracepoint_breakpoint_ops
;
15055 location
= string_to_event_location (&arg
, current_language
);
15058 back_to
= make_cleanup_delete_event_location (location
);
15059 create_breakpoint (get_current_arch (),
15061 NULL
, 0, arg
, 1 /* parse arg */,
15063 bp_static_tracepoint
/* type_wanted */,
15064 0 /* Ignore count */,
15065 pending_break_support
,
15069 0 /* internal */, 0);
15070 do_cleanups (back_to
);
15073 /* Set up a fake reader function that gets command lines from a linked
15074 list that was acquired during tracepoint uploading. */
15076 static struct uploaded_tp
*this_utp
;
15077 static int next_cmd
;
15080 read_uploaded_action (void)
15084 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15091 /* Given information about a tracepoint as recorded on a target (which
15092 can be either a live system or a trace file), attempt to create an
15093 equivalent GDB tracepoint. This is not a reliable process, since
15094 the target does not necessarily have all the information used when
15095 the tracepoint was originally defined. */
15097 struct tracepoint
*
15098 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15100 char *addr_str
, small_buf
[100];
15101 struct tracepoint
*tp
;
15102 struct event_location
*location
;
15103 struct cleanup
*cleanup
;
15105 if (utp
->at_string
)
15106 addr_str
= utp
->at_string
;
15109 /* In the absence of a source location, fall back to raw
15110 address. Since there is no way to confirm that the address
15111 means the same thing as when the trace was started, warn the
15113 warning (_("Uploaded tracepoint %d has no "
15114 "source location, using raw address"),
15116 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15117 addr_str
= small_buf
;
15120 /* There's not much we can do with a sequence of bytecodes. */
15121 if (utp
->cond
&& !utp
->cond_string
)
15122 warning (_("Uploaded tracepoint %d condition "
15123 "has no source form, ignoring it"),
15126 location
= string_to_event_location (&addr_str
, current_language
);
15127 cleanup
= make_cleanup_delete_event_location (location
);
15128 if (!create_breakpoint (get_current_arch (),
15130 utp
->cond_string
, -1, addr_str
,
15131 0 /* parse cond/thread */,
15133 utp
->type
/* type_wanted */,
15134 0 /* Ignore count */,
15135 pending_break_support
,
15136 &tracepoint_breakpoint_ops
,
15138 utp
->enabled
/* enabled */,
15140 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15142 do_cleanups (cleanup
);
15146 do_cleanups (cleanup
);
15148 /* Get the tracepoint we just created. */
15149 tp
= get_tracepoint (tracepoint_count
);
15150 gdb_assert (tp
!= NULL
);
15154 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15157 trace_pass_command (small_buf
, 0);
15160 /* If we have uploaded versions of the original commands, set up a
15161 special-purpose "reader" function and call the usual command line
15162 reader, then pass the result to the breakpoint command-setting
15164 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15166 struct command_line
*cmd_list
;
15171 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15173 breakpoint_set_commands (&tp
->base
, cmd_list
);
15175 else if (!VEC_empty (char_ptr
, utp
->actions
)
15176 || !VEC_empty (char_ptr
, utp
->step_actions
))
15177 warning (_("Uploaded tracepoint %d actions "
15178 "have no source form, ignoring them"),
15181 /* Copy any status information that might be available. */
15182 tp
->base
.hit_count
= utp
->hit_count
;
15183 tp
->traceframe_usage
= utp
->traceframe_usage
;
15188 /* Print information on tracepoint number TPNUM_EXP, or all if
15192 tracepoints_info (char *args
, int from_tty
)
15194 struct ui_out
*uiout
= current_uiout
;
15197 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15199 if (num_printed
== 0)
15201 if (args
== NULL
|| *args
== '\0')
15202 ui_out_message (uiout
, 0, "No tracepoints.\n");
15204 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15207 default_collect_info ();
15210 /* The 'enable trace' command enables tracepoints.
15211 Not supported by all targets. */
15213 enable_trace_command (char *args
, int from_tty
)
15215 enable_command (args
, from_tty
);
15218 /* The 'disable trace' command disables tracepoints.
15219 Not supported by all targets. */
15221 disable_trace_command (char *args
, int from_tty
)
15223 disable_command (args
, from_tty
);
15226 /* Remove a tracepoint (or all if no argument). */
15228 delete_trace_command (char *arg
, int from_tty
)
15230 struct breakpoint
*b
, *b_tmp
;
15236 int breaks_to_delete
= 0;
15238 /* Delete all breakpoints if no argument.
15239 Do not delete internal or call-dummy breakpoints, these
15240 have to be deleted with an explicit breakpoint number
15242 ALL_TRACEPOINTS (b
)
15243 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15245 breaks_to_delete
= 1;
15249 /* Ask user only if there are some breakpoints to delete. */
15251 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15253 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15254 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15255 delete_breakpoint (b
);
15259 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15262 /* Helper function for trace_pass_command. */
15265 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15267 tp
->pass_count
= count
;
15268 observer_notify_breakpoint_modified (&tp
->base
);
15270 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15271 tp
->base
.number
, count
);
15274 /* Set passcount for tracepoint.
15276 First command argument is passcount, second is tracepoint number.
15277 If tracepoint number omitted, apply to most recently defined.
15278 Also accepts special argument "all". */
15281 trace_pass_command (char *args
, int from_tty
)
15283 struct tracepoint
*t1
;
15284 unsigned int count
;
15286 if (args
== 0 || *args
== 0)
15287 error (_("passcount command requires an "
15288 "argument (count + optional TP num)"));
15290 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15292 args
= skip_spaces (args
);
15293 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15295 struct breakpoint
*b
;
15297 args
+= 3; /* Skip special argument "all". */
15299 error (_("Junk at end of arguments."));
15301 ALL_TRACEPOINTS (b
)
15303 t1
= (struct tracepoint
*) b
;
15304 trace_pass_set_count (t1
, count
, from_tty
);
15307 else if (*args
== '\0')
15309 t1
= get_tracepoint_by_number (&args
, NULL
);
15311 trace_pass_set_count (t1
, count
, from_tty
);
15315 struct get_number_or_range_state state
;
15317 init_number_or_range (&state
, args
);
15318 while (!state
.finished
)
15320 t1
= get_tracepoint_by_number (&args
, &state
);
15322 trace_pass_set_count (t1
, count
, from_tty
);
15327 struct tracepoint
*
15328 get_tracepoint (int num
)
15330 struct breakpoint
*t
;
15332 ALL_TRACEPOINTS (t
)
15333 if (t
->number
== num
)
15334 return (struct tracepoint
*) t
;
15339 /* Find the tracepoint with the given target-side number (which may be
15340 different from the tracepoint number after disconnecting and
15343 struct tracepoint
*
15344 get_tracepoint_by_number_on_target (int num
)
15346 struct breakpoint
*b
;
15348 ALL_TRACEPOINTS (b
)
15350 struct tracepoint
*t
= (struct tracepoint
*) b
;
15352 if (t
->number_on_target
== num
)
15359 /* Utility: parse a tracepoint number and look it up in the list.
15360 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15361 If the argument is missing, the most recent tracepoint
15362 (tracepoint_count) is returned. */
15364 struct tracepoint
*
15365 get_tracepoint_by_number (char **arg
,
15366 struct get_number_or_range_state
*state
)
15368 struct breakpoint
*t
;
15370 char *instring
= arg
== NULL
? NULL
: *arg
;
15374 gdb_assert (!state
->finished
);
15375 tpnum
= get_number_or_range (state
);
15377 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15378 tpnum
= tracepoint_count
;
15380 tpnum
= get_number (arg
);
15384 if (instring
&& *instring
)
15385 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15388 printf_filtered (_("No previous tracepoint\n"));
15392 ALL_TRACEPOINTS (t
)
15393 if (t
->number
== tpnum
)
15395 return (struct tracepoint
*) t
;
15398 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15403 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15405 if (b
->thread
!= -1)
15406 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15409 fprintf_unfiltered (fp
, " task %d", b
->task
);
15411 fprintf_unfiltered (fp
, "\n");
15414 /* Save information on user settable breakpoints (watchpoints, etc) to
15415 a new script file named FILENAME. If FILTER is non-NULL, call it
15416 on each breakpoint and only include the ones for which it returns
15420 save_breakpoints (char *filename
, int from_tty
,
15421 int (*filter
) (const struct breakpoint
*))
15423 struct breakpoint
*tp
;
15425 struct cleanup
*cleanup
;
15426 struct ui_file
*fp
;
15427 int extra_trace_bits
= 0;
15429 if (filename
== 0 || *filename
== 0)
15430 error (_("Argument required (file name in which to save)"));
15432 /* See if we have anything to save. */
15433 ALL_BREAKPOINTS (tp
)
15435 /* Skip internal and momentary breakpoints. */
15436 if (!user_breakpoint_p (tp
))
15439 /* If we have a filter, only save the breakpoints it accepts. */
15440 if (filter
&& !filter (tp
))
15445 if (is_tracepoint (tp
))
15447 extra_trace_bits
= 1;
15449 /* We can stop searching. */
15456 warning (_("Nothing to save."));
15460 filename
= tilde_expand (filename
);
15461 cleanup
= make_cleanup (xfree
, filename
);
15462 fp
= gdb_fopen (filename
, "w");
15464 error (_("Unable to open file '%s' for saving (%s)"),
15465 filename
, safe_strerror (errno
));
15466 make_cleanup_ui_file_delete (fp
);
15468 if (extra_trace_bits
)
15469 save_trace_state_variables (fp
);
15471 ALL_BREAKPOINTS (tp
)
15473 /* Skip internal and momentary breakpoints. */
15474 if (!user_breakpoint_p (tp
))
15477 /* If we have a filter, only save the breakpoints it accepts. */
15478 if (filter
&& !filter (tp
))
15481 tp
->ops
->print_recreate (tp
, fp
);
15483 /* Note, we can't rely on tp->number for anything, as we can't
15484 assume the recreated breakpoint numbers will match. Use $bpnum
15487 if (tp
->cond_string
)
15488 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15490 if (tp
->ignore_count
)
15491 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15493 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15495 struct gdb_exception exception
;
15497 fprintf_unfiltered (fp
, " commands\n");
15499 ui_out_redirect (current_uiout
, fp
);
15502 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15504 CATCH (ex
, RETURN_MASK_ALL
)
15506 ui_out_redirect (current_uiout
, NULL
);
15507 throw_exception (ex
);
15511 ui_out_redirect (current_uiout
, NULL
);
15512 fprintf_unfiltered (fp
, " end\n");
15515 if (tp
->enable_state
== bp_disabled
)
15516 fprintf_unfiltered (fp
, "disable $bpnum\n");
15518 /* If this is a multi-location breakpoint, check if the locations
15519 should be individually disabled. Watchpoint locations are
15520 special, and not user visible. */
15521 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15523 struct bp_location
*loc
;
15526 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15528 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15532 if (extra_trace_bits
&& *default_collect
)
15533 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15536 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15537 do_cleanups (cleanup
);
15540 /* The `save breakpoints' command. */
15543 save_breakpoints_command (char *args
, int from_tty
)
15545 save_breakpoints (args
, from_tty
, NULL
);
15548 /* The `save tracepoints' command. */
15551 save_tracepoints_command (char *args
, int from_tty
)
15553 save_breakpoints (args
, from_tty
, is_tracepoint
);
15556 /* Create a vector of all tracepoints. */
15558 VEC(breakpoint_p
) *
15559 all_tracepoints (void)
15561 VEC(breakpoint_p
) *tp_vec
= 0;
15562 struct breakpoint
*tp
;
15564 ALL_TRACEPOINTS (tp
)
15566 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15573 /* This help string is used to consolidate all the help string for specifying
15574 locations used by several commands. */
15576 #define LOCATION_HELP_STRING \
15577 "Linespecs are colon-separated lists of location parameters, such as\n\
15578 source filename, function name, label name, and line number.\n\
15579 Example: To specify the start of a label named \"the_top\" in the\n\
15580 function \"fact\" in the file \"factorial.c\", use\n\
15581 \"factorial.c:fact:the_top\".\n\
15583 Address locations begin with \"*\" and specify an exact address in the\n\
15584 program. Example: To specify the fourth byte past the start function\n\
15585 \"main\", use \"*main + 4\".\n\
15587 Explicit locations are similar to linespecs but use an option/argument\n\
15588 syntax to specify location parameters.\n\
15589 Example: To specify the start of the label named \"the_top\" in the\n\
15590 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15591 -function fact -label the_top\".\n"
15593 /* This help string is used for the break, hbreak, tbreak and thbreak
15594 commands. It is defined as a macro to prevent duplication.
15595 COMMAND should be a string constant containing the name of the
15598 #define BREAK_ARGS_HELP(command) \
15599 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15600 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15601 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15602 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15603 `-probe-dtrace' (for a DTrace probe).\n\
15604 LOCATION may be a linespec, address, or explicit location as described\n\
15607 With no LOCATION, uses current execution address of the selected\n\
15608 stack frame. This is useful for breaking on return to a stack frame.\n\
15610 THREADNUM is the number from \"info threads\".\n\
15611 CONDITION is a boolean expression.\n\
15612 \n" LOCATION_HELP_STRING "\n\
15613 Multiple breakpoints at one place are permitted, and useful if their\n\
15614 conditions are different.\n\
15616 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15618 /* List of subcommands for "catch". */
15619 static struct cmd_list_element
*catch_cmdlist
;
15621 /* List of subcommands for "tcatch". */
15622 static struct cmd_list_element
*tcatch_cmdlist
;
15625 add_catch_command (char *name
, char *docstring
,
15626 cmd_sfunc_ftype
*sfunc
,
15627 completer_ftype
*completer
,
15628 void *user_data_catch
,
15629 void *user_data_tcatch
)
15631 struct cmd_list_element
*command
;
15633 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15635 set_cmd_sfunc (command
, sfunc
);
15636 set_cmd_context (command
, user_data_catch
);
15637 set_cmd_completer (command
, completer
);
15639 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15641 set_cmd_sfunc (command
, sfunc
);
15642 set_cmd_context (command
, user_data_tcatch
);
15643 set_cmd_completer (command
, completer
);
15647 save_command (char *arg
, int from_tty
)
15649 printf_unfiltered (_("\"save\" must be followed by "
15650 "the name of a save subcommand.\n"));
15651 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15654 struct breakpoint
*
15655 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15658 struct breakpoint
*b
, *b_tmp
;
15660 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15662 if ((*callback
) (b
, data
))
15669 /* Zero if any of the breakpoint's locations could be a location where
15670 functions have been inlined, nonzero otherwise. */
15673 is_non_inline_function (struct breakpoint
*b
)
15675 /* The shared library event breakpoint is set on the address of a
15676 non-inline function. */
15677 if (b
->type
== bp_shlib_event
)
15683 /* Nonzero if the specified PC cannot be a location where functions
15684 have been inlined. */
15687 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15688 const struct target_waitstatus
*ws
)
15690 struct breakpoint
*b
;
15691 struct bp_location
*bl
;
15693 ALL_BREAKPOINTS (b
)
15695 if (!is_non_inline_function (b
))
15698 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15700 if (!bl
->shlib_disabled
15701 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15709 /* Remove any references to OBJFILE which is going to be freed. */
15712 breakpoint_free_objfile (struct objfile
*objfile
)
15714 struct bp_location
**locp
, *loc
;
15716 ALL_BP_LOCATIONS (loc
, locp
)
15717 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15718 loc
->symtab
= NULL
;
15722 initialize_breakpoint_ops (void)
15724 static int initialized
= 0;
15726 struct breakpoint_ops
*ops
;
15732 /* The breakpoint_ops structure to be inherit by all kinds of
15733 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15734 internal and momentary breakpoints, etc.). */
15735 ops
= &bkpt_base_breakpoint_ops
;
15736 *ops
= base_breakpoint_ops
;
15737 ops
->re_set
= bkpt_re_set
;
15738 ops
->insert_location
= bkpt_insert_location
;
15739 ops
->remove_location
= bkpt_remove_location
;
15740 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15741 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15742 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15743 ops
->decode_location
= bkpt_decode_location
;
15745 /* The breakpoint_ops structure to be used in regular breakpoints. */
15746 ops
= &bkpt_breakpoint_ops
;
15747 *ops
= bkpt_base_breakpoint_ops
;
15748 ops
->re_set
= bkpt_re_set
;
15749 ops
->resources_needed
= bkpt_resources_needed
;
15750 ops
->print_it
= bkpt_print_it
;
15751 ops
->print_mention
= bkpt_print_mention
;
15752 ops
->print_recreate
= bkpt_print_recreate
;
15754 /* Ranged breakpoints. */
15755 ops
= &ranged_breakpoint_ops
;
15756 *ops
= bkpt_breakpoint_ops
;
15757 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15758 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15759 ops
->print_it
= print_it_ranged_breakpoint
;
15760 ops
->print_one
= print_one_ranged_breakpoint
;
15761 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15762 ops
->print_mention
= print_mention_ranged_breakpoint
;
15763 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15765 /* Internal breakpoints. */
15766 ops
= &internal_breakpoint_ops
;
15767 *ops
= bkpt_base_breakpoint_ops
;
15768 ops
->re_set
= internal_bkpt_re_set
;
15769 ops
->check_status
= internal_bkpt_check_status
;
15770 ops
->print_it
= internal_bkpt_print_it
;
15771 ops
->print_mention
= internal_bkpt_print_mention
;
15773 /* Momentary breakpoints. */
15774 ops
= &momentary_breakpoint_ops
;
15775 *ops
= bkpt_base_breakpoint_ops
;
15776 ops
->re_set
= momentary_bkpt_re_set
;
15777 ops
->check_status
= momentary_bkpt_check_status
;
15778 ops
->print_it
= momentary_bkpt_print_it
;
15779 ops
->print_mention
= momentary_bkpt_print_mention
;
15781 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15782 ops
= &longjmp_breakpoint_ops
;
15783 *ops
= momentary_breakpoint_ops
;
15784 ops
->dtor
= longjmp_bkpt_dtor
;
15786 /* Probe breakpoints. */
15787 ops
= &bkpt_probe_breakpoint_ops
;
15788 *ops
= bkpt_breakpoint_ops
;
15789 ops
->insert_location
= bkpt_probe_insert_location
;
15790 ops
->remove_location
= bkpt_probe_remove_location
;
15791 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15792 ops
->decode_location
= bkpt_probe_decode_location
;
15795 ops
= &watchpoint_breakpoint_ops
;
15796 *ops
= base_breakpoint_ops
;
15797 ops
->dtor
= dtor_watchpoint
;
15798 ops
->re_set
= re_set_watchpoint
;
15799 ops
->insert_location
= insert_watchpoint
;
15800 ops
->remove_location
= remove_watchpoint
;
15801 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15802 ops
->check_status
= check_status_watchpoint
;
15803 ops
->resources_needed
= resources_needed_watchpoint
;
15804 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15805 ops
->print_it
= print_it_watchpoint
;
15806 ops
->print_mention
= print_mention_watchpoint
;
15807 ops
->print_recreate
= print_recreate_watchpoint
;
15808 ops
->explains_signal
= explains_signal_watchpoint
;
15810 /* Masked watchpoints. */
15811 ops
= &masked_watchpoint_breakpoint_ops
;
15812 *ops
= watchpoint_breakpoint_ops
;
15813 ops
->insert_location
= insert_masked_watchpoint
;
15814 ops
->remove_location
= remove_masked_watchpoint
;
15815 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15816 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15817 ops
->print_it
= print_it_masked_watchpoint
;
15818 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15819 ops
->print_mention
= print_mention_masked_watchpoint
;
15820 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15823 ops
= &tracepoint_breakpoint_ops
;
15824 *ops
= base_breakpoint_ops
;
15825 ops
->re_set
= tracepoint_re_set
;
15826 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15827 ops
->print_one_detail
= tracepoint_print_one_detail
;
15828 ops
->print_mention
= tracepoint_print_mention
;
15829 ops
->print_recreate
= tracepoint_print_recreate
;
15830 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15831 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15832 ops
->decode_location
= tracepoint_decode_location
;
15834 /* Probe tracepoints. */
15835 ops
= &tracepoint_probe_breakpoint_ops
;
15836 *ops
= tracepoint_breakpoint_ops
;
15837 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15838 ops
->decode_location
= tracepoint_probe_decode_location
;
15840 /* Static tracepoints with marker (`-m'). */
15841 ops
= &strace_marker_breakpoint_ops
;
15842 *ops
= tracepoint_breakpoint_ops
;
15843 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15844 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15845 ops
->decode_location
= strace_marker_decode_location
;
15847 /* Fork catchpoints. */
15848 ops
= &catch_fork_breakpoint_ops
;
15849 *ops
= base_breakpoint_ops
;
15850 ops
->insert_location
= insert_catch_fork
;
15851 ops
->remove_location
= remove_catch_fork
;
15852 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15853 ops
->print_it
= print_it_catch_fork
;
15854 ops
->print_one
= print_one_catch_fork
;
15855 ops
->print_mention
= print_mention_catch_fork
;
15856 ops
->print_recreate
= print_recreate_catch_fork
;
15858 /* Vfork catchpoints. */
15859 ops
= &catch_vfork_breakpoint_ops
;
15860 *ops
= base_breakpoint_ops
;
15861 ops
->insert_location
= insert_catch_vfork
;
15862 ops
->remove_location
= remove_catch_vfork
;
15863 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15864 ops
->print_it
= print_it_catch_vfork
;
15865 ops
->print_one
= print_one_catch_vfork
;
15866 ops
->print_mention
= print_mention_catch_vfork
;
15867 ops
->print_recreate
= print_recreate_catch_vfork
;
15869 /* Exec catchpoints. */
15870 ops
= &catch_exec_breakpoint_ops
;
15871 *ops
= base_breakpoint_ops
;
15872 ops
->dtor
= dtor_catch_exec
;
15873 ops
->insert_location
= insert_catch_exec
;
15874 ops
->remove_location
= remove_catch_exec
;
15875 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15876 ops
->print_it
= print_it_catch_exec
;
15877 ops
->print_one
= print_one_catch_exec
;
15878 ops
->print_mention
= print_mention_catch_exec
;
15879 ops
->print_recreate
= print_recreate_catch_exec
;
15881 /* Solib-related catchpoints. */
15882 ops
= &catch_solib_breakpoint_ops
;
15883 *ops
= base_breakpoint_ops
;
15884 ops
->dtor
= dtor_catch_solib
;
15885 ops
->insert_location
= insert_catch_solib
;
15886 ops
->remove_location
= remove_catch_solib
;
15887 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15888 ops
->check_status
= check_status_catch_solib
;
15889 ops
->print_it
= print_it_catch_solib
;
15890 ops
->print_one
= print_one_catch_solib
;
15891 ops
->print_mention
= print_mention_catch_solib
;
15892 ops
->print_recreate
= print_recreate_catch_solib
;
15894 ops
= &dprintf_breakpoint_ops
;
15895 *ops
= bkpt_base_breakpoint_ops
;
15896 ops
->re_set
= dprintf_re_set
;
15897 ops
->resources_needed
= bkpt_resources_needed
;
15898 ops
->print_it
= bkpt_print_it
;
15899 ops
->print_mention
= bkpt_print_mention
;
15900 ops
->print_recreate
= dprintf_print_recreate
;
15901 ops
->after_condition_true
= dprintf_after_condition_true
;
15902 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15905 /* Chain containing all defined "enable breakpoint" subcommands. */
15907 static struct cmd_list_element
*enablebreaklist
= NULL
;
15910 _initialize_breakpoint (void)
15912 struct cmd_list_element
*c
;
15914 initialize_breakpoint_ops ();
15916 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15917 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
15918 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15920 breakpoint_objfile_key
15921 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
15923 breakpoint_chain
= 0;
15924 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15925 before a breakpoint is set. */
15926 breakpoint_count
= 0;
15928 tracepoint_count
= 0;
15930 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15931 Set ignore-count of breakpoint number N to COUNT.\n\
15932 Usage is `ignore N COUNT'."));
15934 add_com ("commands", class_breakpoint
, commands_command
, _("\
15935 Set commands to be executed when a breakpoint is hit.\n\
15936 Give breakpoint number as argument after \"commands\".\n\
15937 With no argument, the targeted breakpoint is the last one set.\n\
15938 The commands themselves follow starting on the next line.\n\
15939 Type a line containing \"end\" to indicate the end of them.\n\
15940 Give \"silent\" as the first line to make the breakpoint silent;\n\
15941 then no output is printed when it is hit, except what the commands print."));
15943 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15944 Specify breakpoint number N to break only if COND is true.\n\
15945 Usage is `condition N COND', where N is an integer and COND is an\n\
15946 expression to be evaluated whenever breakpoint N is reached."));
15947 set_cmd_completer (c
, condition_completer
);
15949 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15950 Set a temporary breakpoint.\n\
15951 Like \"break\" except the breakpoint is only temporary,\n\
15952 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15953 by using \"enable delete\" on the breakpoint number.\n\
15955 BREAK_ARGS_HELP ("tbreak")));
15956 set_cmd_completer (c
, location_completer
);
15958 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15959 Set a hardware assisted breakpoint.\n\
15960 Like \"break\" except the breakpoint requires hardware support,\n\
15961 some target hardware may not have this support.\n\
15963 BREAK_ARGS_HELP ("hbreak")));
15964 set_cmd_completer (c
, location_completer
);
15966 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15967 Set a temporary hardware assisted breakpoint.\n\
15968 Like \"hbreak\" except the breakpoint is only temporary,\n\
15969 so it will be deleted when hit.\n\
15971 BREAK_ARGS_HELP ("thbreak")));
15972 set_cmd_completer (c
, location_completer
);
15974 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15975 Enable some breakpoints.\n\
15976 Give breakpoint numbers (separated by spaces) as arguments.\n\
15977 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15978 This is used to cancel the effect of the \"disable\" command.\n\
15979 With a subcommand you can enable temporarily."),
15980 &enablelist
, "enable ", 1, &cmdlist
);
15982 add_com_alias ("en", "enable", class_breakpoint
, 1);
15984 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15985 Enable some breakpoints.\n\
15986 Give breakpoint numbers (separated by spaces) as arguments.\n\
15987 This is used to cancel the effect of the \"disable\" command.\n\
15988 May be abbreviated to simply \"enable\".\n"),
15989 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15991 add_cmd ("once", no_class
, enable_once_command
, _("\
15992 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15993 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15996 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15997 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15998 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16001 add_cmd ("count", no_class
, enable_count_command
, _("\
16002 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16003 If a breakpoint is hit while enabled in this fashion,\n\
16004 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16007 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16008 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16009 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16012 add_cmd ("once", no_class
, enable_once_command
, _("\
16013 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16014 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16017 add_cmd ("count", no_class
, enable_count_command
, _("\
16018 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16019 If a breakpoint is hit while enabled in this fashion,\n\
16020 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16023 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16024 Disable some breakpoints.\n\
16025 Arguments are breakpoint numbers with spaces in between.\n\
16026 To disable all breakpoints, give no argument.\n\
16027 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16028 &disablelist
, "disable ", 1, &cmdlist
);
16029 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16030 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16032 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16033 Disable some breakpoints.\n\
16034 Arguments are breakpoint numbers with spaces in between.\n\
16035 To disable all breakpoints, give no argument.\n\
16036 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16037 This command may be abbreviated \"disable\"."),
16040 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16041 Delete some breakpoints or auto-display expressions.\n\
16042 Arguments are breakpoint numbers with spaces in between.\n\
16043 To delete all breakpoints, give no argument.\n\
16045 Also a prefix command for deletion of other GDB objects.\n\
16046 The \"unset\" command is also an alias for \"delete\"."),
16047 &deletelist
, "delete ", 1, &cmdlist
);
16048 add_com_alias ("d", "delete", class_breakpoint
, 1);
16049 add_com_alias ("del", "delete", class_breakpoint
, 1);
16051 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16052 Delete some breakpoints or auto-display expressions.\n\
16053 Arguments are breakpoint numbers with spaces in between.\n\
16054 To delete all breakpoints, give no argument.\n\
16055 This command may be abbreviated \"delete\"."),
16058 add_com ("clear", class_breakpoint
, clear_command
, _("\
16059 Clear breakpoint at specified location.\n\
16060 Argument may be a linespec, explicit, or address location as described below.\n\
16062 With no argument, clears all breakpoints in the line that the selected frame\n\
16063 is executing in.\n"
16064 "\n" LOCATION_HELP_STRING
"\n\
16065 See also the \"delete\" command which clears breakpoints by number."));
16066 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16068 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16069 Set breakpoint at specified location.\n"
16070 BREAK_ARGS_HELP ("break")));
16071 set_cmd_completer (c
, location_completer
);
16073 add_com_alias ("b", "break", class_run
, 1);
16074 add_com_alias ("br", "break", class_run
, 1);
16075 add_com_alias ("bre", "break", class_run
, 1);
16076 add_com_alias ("brea", "break", class_run
, 1);
16080 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16081 Break in function/address or break at a line in the current file."),
16082 &stoplist
, "stop ", 1, &cmdlist
);
16083 add_cmd ("in", class_breakpoint
, stopin_command
,
16084 _("Break in function or address."), &stoplist
);
16085 add_cmd ("at", class_breakpoint
, stopat_command
,
16086 _("Break at a line in the current file."), &stoplist
);
16087 add_com ("status", class_info
, breakpoints_info
, _("\
16088 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16089 The \"Type\" column indicates one of:\n\
16090 \tbreakpoint - normal breakpoint\n\
16091 \twatchpoint - watchpoint\n\
16092 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16093 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16094 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16095 address and file/line number respectively.\n\
16097 Convenience variable \"$_\" and default examine address for \"x\"\n\
16098 are set to the address of the last breakpoint listed unless the command\n\
16099 is prefixed with \"server \".\n\n\
16100 Convenience variable \"$bpnum\" contains the number of the last\n\
16101 breakpoint set."));
16104 add_info ("breakpoints", breakpoints_info
, _("\
16105 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16106 The \"Type\" column indicates one of:\n\
16107 \tbreakpoint - normal breakpoint\n\
16108 \twatchpoint - watchpoint\n\
16109 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16110 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16111 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16112 address and file/line number respectively.\n\
16114 Convenience variable \"$_\" and default examine address for \"x\"\n\
16115 are set to the address of the last breakpoint listed unless the command\n\
16116 is prefixed with \"server \".\n\n\
16117 Convenience variable \"$bpnum\" contains the number of the last\n\
16118 breakpoint set."));
16120 add_info_alias ("b", "breakpoints", 1);
16122 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16123 Status of all breakpoints, or breakpoint number NUMBER.\n\
16124 The \"Type\" column indicates one of:\n\
16125 \tbreakpoint - normal breakpoint\n\
16126 \twatchpoint - watchpoint\n\
16127 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16128 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16129 \tuntil - internal breakpoint used by the \"until\" command\n\
16130 \tfinish - internal breakpoint used by the \"finish\" command\n\
16131 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16132 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16133 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16134 address and file/line number respectively.\n\
16136 Convenience variable \"$_\" and default examine address for \"x\"\n\
16137 are set to the address of the last breakpoint listed unless the command\n\
16138 is prefixed with \"server \".\n\n\
16139 Convenience variable \"$bpnum\" contains the number of the last\n\
16141 &maintenanceinfolist
);
16143 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16144 Set catchpoints to catch events."),
16145 &catch_cmdlist
, "catch ",
16146 0/*allow-unknown*/, &cmdlist
);
16148 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16149 Set temporary catchpoints to catch events."),
16150 &tcatch_cmdlist
, "tcatch ",
16151 0/*allow-unknown*/, &cmdlist
);
16153 add_catch_command ("fork", _("Catch calls to fork."),
16154 catch_fork_command_1
,
16156 (void *) (uintptr_t) catch_fork_permanent
,
16157 (void *) (uintptr_t) catch_fork_temporary
);
16158 add_catch_command ("vfork", _("Catch calls to vfork."),
16159 catch_fork_command_1
,
16161 (void *) (uintptr_t) catch_vfork_permanent
,
16162 (void *) (uintptr_t) catch_vfork_temporary
);
16163 add_catch_command ("exec", _("Catch calls to exec."),
16164 catch_exec_command_1
,
16168 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16169 Usage: catch load [REGEX]\n\
16170 If REGEX is given, only stop for libraries matching the regular expression."),
16171 catch_load_command_1
,
16175 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16176 Usage: catch unload [REGEX]\n\
16177 If REGEX is given, only stop for libraries matching the regular expression."),
16178 catch_unload_command_1
,
16183 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16184 Set a watchpoint for an expression.\n\
16185 Usage: watch [-l|-location] EXPRESSION\n\
16186 A watchpoint stops execution of your program whenever the value of\n\
16187 an expression changes.\n\
16188 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16189 the memory to which it refers."));
16190 set_cmd_completer (c
, expression_completer
);
16192 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16193 Set a read watchpoint for an expression.\n\
16194 Usage: rwatch [-l|-location] EXPRESSION\n\
16195 A watchpoint stops execution of your program whenever the value of\n\
16196 an expression is read.\n\
16197 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16198 the memory to which it refers."));
16199 set_cmd_completer (c
, expression_completer
);
16201 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16202 Set a watchpoint for an expression.\n\
16203 Usage: awatch [-l|-location] EXPRESSION\n\
16204 A watchpoint stops execution of your program whenever the value of\n\
16205 an expression is either read or written.\n\
16206 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16207 the memory to which it refers."));
16208 set_cmd_completer (c
, expression_completer
);
16210 add_info ("watchpoints", watchpoints_info
, _("\
16211 Status of specified watchpoints (all watchpoints if no argument)."));
16213 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16214 respond to changes - contrary to the description. */
16215 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16216 &can_use_hw_watchpoints
, _("\
16217 Set debugger's willingness to use watchpoint hardware."), _("\
16218 Show debugger's willingness to use watchpoint hardware."), _("\
16219 If zero, gdb will not use hardware for new watchpoints, even if\n\
16220 such is available. (However, any hardware watchpoints that were\n\
16221 created before setting this to nonzero, will continue to use watchpoint\n\
16224 show_can_use_hw_watchpoints
,
16225 &setlist
, &showlist
);
16227 can_use_hw_watchpoints
= 1;
16229 /* Tracepoint manipulation commands. */
16231 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16232 Set a tracepoint at specified location.\n\
16234 BREAK_ARGS_HELP ("trace") "\n\
16235 Do \"help tracepoints\" for info on other tracepoint commands."));
16236 set_cmd_completer (c
, location_completer
);
16238 add_com_alias ("tp", "trace", class_alias
, 0);
16239 add_com_alias ("tr", "trace", class_alias
, 1);
16240 add_com_alias ("tra", "trace", class_alias
, 1);
16241 add_com_alias ("trac", "trace", class_alias
, 1);
16243 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16244 Set a fast tracepoint at specified location.\n\
16246 BREAK_ARGS_HELP ("ftrace") "\n\
16247 Do \"help tracepoints\" for info on other tracepoint commands."));
16248 set_cmd_completer (c
, location_completer
);
16250 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16251 Set a static tracepoint at location or marker.\n\
16253 strace [LOCATION] [if CONDITION]\n\
16254 LOCATION may be a linespec, explicit, or address location (described below) \n\
16255 or -m MARKER_ID.\n\n\
16256 If a marker id is specified, probe the marker with that name. With\n\
16257 no LOCATION, uses current execution address of the selected stack frame.\n\
16258 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16259 This collects arbitrary user data passed in the probe point call to the\n\
16260 tracing library. You can inspect it when analyzing the trace buffer,\n\
16261 by printing the $_sdata variable like any other convenience variable.\n\
16263 CONDITION is a boolean expression.\n\
16264 \n" LOCATION_HELP_STRING
"\n\
16265 Multiple tracepoints at one place are permitted, and useful if their\n\
16266 conditions are different.\n\
16268 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16269 Do \"help tracepoints\" for info on other tracepoint commands."));
16270 set_cmd_completer (c
, location_completer
);
16272 add_info ("tracepoints", tracepoints_info
, _("\
16273 Status of specified tracepoints (all tracepoints if no argument).\n\
16274 Convenience variable \"$tpnum\" contains the number of the\n\
16275 last tracepoint set."));
16277 add_info_alias ("tp", "tracepoints", 1);
16279 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16280 Delete specified tracepoints.\n\
16281 Arguments are tracepoint numbers, separated by spaces.\n\
16282 No argument means delete all tracepoints."),
16284 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16286 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16287 Disable specified tracepoints.\n\
16288 Arguments are tracepoint numbers, separated by spaces.\n\
16289 No argument means disable all tracepoints."),
16291 deprecate_cmd (c
, "disable");
16293 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16294 Enable specified tracepoints.\n\
16295 Arguments are tracepoint numbers, separated by spaces.\n\
16296 No argument means enable all tracepoints."),
16298 deprecate_cmd (c
, "enable");
16300 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16301 Set the passcount for a tracepoint.\n\
16302 The trace will end when the tracepoint has been passed 'count' times.\n\
16303 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16304 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16306 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16307 _("Save breakpoint definitions as a script."),
16308 &save_cmdlist
, "save ",
16309 0/*allow-unknown*/, &cmdlist
);
16311 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16312 Save current breakpoint definitions as a script.\n\
16313 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16314 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16315 session to restore them."),
16317 set_cmd_completer (c
, filename_completer
);
16319 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16320 Save current tracepoint definitions as a script.\n\
16321 Use the 'source' command in another debug session to restore them."),
16323 set_cmd_completer (c
, filename_completer
);
16325 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16326 deprecate_cmd (c
, "save tracepoints");
16328 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16329 Breakpoint specific settings\n\
16330 Configure various breakpoint-specific variables such as\n\
16331 pending breakpoint behavior"),
16332 &breakpoint_set_cmdlist
, "set breakpoint ",
16333 0/*allow-unknown*/, &setlist
);
16334 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16335 Breakpoint specific settings\n\
16336 Configure various breakpoint-specific variables such as\n\
16337 pending breakpoint behavior"),
16338 &breakpoint_show_cmdlist
, "show breakpoint ",
16339 0/*allow-unknown*/, &showlist
);
16341 add_setshow_auto_boolean_cmd ("pending", no_class
,
16342 &pending_break_support
, _("\
16343 Set debugger's behavior regarding pending breakpoints."), _("\
16344 Show debugger's behavior regarding pending breakpoints."), _("\
16345 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16346 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16347 an error. If auto, an unrecognized breakpoint location results in a\n\
16348 user-query to see if a pending breakpoint should be created."),
16350 show_pending_break_support
,
16351 &breakpoint_set_cmdlist
,
16352 &breakpoint_show_cmdlist
);
16354 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16356 add_setshow_boolean_cmd ("auto-hw", no_class
,
16357 &automatic_hardware_breakpoints
, _("\
16358 Set automatic usage of hardware breakpoints."), _("\
16359 Show automatic usage of hardware breakpoints."), _("\
16360 If set, the debugger will automatically use hardware breakpoints for\n\
16361 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16362 a warning will be emitted for such breakpoints."),
16364 show_automatic_hardware_breakpoints
,
16365 &breakpoint_set_cmdlist
,
16366 &breakpoint_show_cmdlist
);
16368 add_setshow_boolean_cmd ("always-inserted", class_support
,
16369 &always_inserted_mode
, _("\
16370 Set mode for inserting breakpoints."), _("\
16371 Show mode for inserting breakpoints."), _("\
16372 When this mode is on, breakpoints are inserted immediately as soon as\n\
16373 they're created, kept inserted even when execution stops, and removed\n\
16374 only when the user deletes them. When this mode is off (the default),\n\
16375 breakpoints are inserted only when execution continues, and removed\n\
16376 when execution stops."),
16378 &show_always_inserted_mode
,
16379 &breakpoint_set_cmdlist
,
16380 &breakpoint_show_cmdlist
);
16382 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16383 condition_evaluation_enums
,
16384 &condition_evaluation_mode_1
, _("\
16385 Set mode of breakpoint condition evaluation."), _("\
16386 Show mode of breakpoint condition evaluation."), _("\
16387 When this is set to \"host\", breakpoint conditions will be\n\
16388 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16389 breakpoint conditions will be downloaded to the target (if the target\n\
16390 supports such feature) and conditions will be evaluated on the target's side.\n\
16391 If this is set to \"auto\" (default), this will be automatically set to\n\
16392 \"target\" if it supports condition evaluation, otherwise it will\n\
16393 be set to \"gdb\""),
16394 &set_condition_evaluation_mode
,
16395 &show_condition_evaluation_mode
,
16396 &breakpoint_set_cmdlist
,
16397 &breakpoint_show_cmdlist
);
16399 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16400 Set a breakpoint for an address range.\n\
16401 break-range START-LOCATION, END-LOCATION\n\
16402 where START-LOCATION and END-LOCATION can be one of the following:\n\
16403 LINENUM, for that line in the current file,\n\
16404 FILE:LINENUM, for that line in that file,\n\
16405 +OFFSET, for that number of lines after the current line\n\
16406 or the start of the range\n\
16407 FUNCTION, for the first line in that function,\n\
16408 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16409 *ADDRESS, for the instruction at that address.\n\
16411 The breakpoint will stop execution of the inferior whenever it executes\n\
16412 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16413 range (including START-LOCATION and END-LOCATION)."));
16415 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16416 Set a dynamic printf at specified location.\n\
16417 dprintf location,format string,arg1,arg2,...\n\
16418 location may be a linespec, explicit, or address location.\n"
16419 "\n" LOCATION_HELP_STRING
));
16420 set_cmd_completer (c
, location_completer
);
16422 add_setshow_enum_cmd ("dprintf-style", class_support
,
16423 dprintf_style_enums
, &dprintf_style
, _("\
16424 Set the style of usage for dynamic printf."), _("\
16425 Show the style of usage for dynamic printf."), _("\
16426 This setting chooses how GDB will do a dynamic printf.\n\
16427 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16428 console, as with the \"printf\" command.\n\
16429 If the value is \"call\", the print is done by calling a function in your\n\
16430 program; by default printf(), but you can choose a different function or\n\
16431 output stream by setting dprintf-function and dprintf-channel."),
16432 update_dprintf_commands
, NULL
,
16433 &setlist
, &showlist
);
16435 dprintf_function
= xstrdup ("printf");
16436 add_setshow_string_cmd ("dprintf-function", class_support
,
16437 &dprintf_function
, _("\
16438 Set the function to use for dynamic printf"), _("\
16439 Show the function to use for dynamic printf"), NULL
,
16440 update_dprintf_commands
, NULL
,
16441 &setlist
, &showlist
);
16443 dprintf_channel
= xstrdup ("");
16444 add_setshow_string_cmd ("dprintf-channel", class_support
,
16445 &dprintf_channel
, _("\
16446 Set the channel to use for dynamic printf"), _("\
16447 Show the channel to use for dynamic printf"), NULL
,
16448 update_dprintf_commands
, NULL
,
16449 &setlist
, &showlist
);
16451 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16452 &disconnected_dprintf
, _("\
16453 Set whether dprintf continues after GDB disconnects."), _("\
16454 Show whether dprintf continues after GDB disconnects."), _("\
16455 Use this to let dprintf commands continue to hit and produce output\n\
16456 even if GDB disconnects or detaches from the target."),
16459 &setlist
, &showlist
);
16461 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16462 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16463 (target agent only) This is useful for formatted output in user-defined commands."));
16465 automatic_hardware_breakpoints
= 1;
16467 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16468 observer_attach_thread_exit (remove_threaded_breakpoints
);