1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008, 2009 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
28 #include "breakpoint.h"
29 #include "tracepoint.h"
31 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb_string.h"
47 #include "completer.h"
50 #include "cli/cli-script.h"
51 #include "gdb_assert.h"
56 #include "exceptions.h"
63 /* readline include files */
64 #include "readline/readline.h"
65 #include "readline/history.h"
67 /* readline defines this. */
70 #include "mi/mi-common.h"
72 /* Arguments to pass as context to some catch command handlers. */
73 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
74 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
76 /* Prototypes for local functions. */
78 static void enable_delete_command (char *, int);
80 static void enable_delete_breakpoint (struct breakpoint
*);
82 static void enable_once_command (char *, int);
84 static void enable_once_breakpoint (struct breakpoint
*);
86 static void disable_command (char *, int);
88 static void enable_command (char *, int);
90 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
92 static void ignore_command (char *, int);
94 static int breakpoint_re_set_one (void *);
96 static void clear_command (char *, int);
98 static void catch_command (char *, int);
100 static void watch_command (char *, int);
102 static int can_use_hardware_watchpoint (struct value
*);
104 static void break_command_1 (char *, int, int);
106 static void mention (struct breakpoint
*);
108 /* This function is used in gdbtk sources and thus can not be made static. */
109 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
110 struct symtab_and_line
,
113 static void check_duplicates (struct breakpoint
*);
115 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
117 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
121 static void describe_other_breakpoints (struct gdbarch
*, CORE_ADDR
,
122 struct obj_section
*, int);
124 static void breakpoints_info (char *, int);
126 static void breakpoint_1 (int, int);
128 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
130 static int breakpoint_cond_eval (void *);
132 static void cleanup_executing_breakpoints (void *);
134 static void commands_command (char *, int);
136 static void condition_command (char *, int);
138 static int get_number_trailer (char **, int);
140 void set_breakpoint_count (int);
149 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
151 static enum print_stop_action
print_it_typical (bpstat
);
153 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
155 static int watchpoint_check (void *);
157 static void maintenance_info_breakpoints (char *, int);
159 static int hw_breakpoint_used_count (void);
161 static int hw_watchpoint_used_count (enum bptype
, int *);
163 static void hbreak_command (char *, int);
165 static void thbreak_command (char *, int);
167 static void watch_command_1 (char *, int, int);
169 static void rwatch_command (char *, int);
171 static void awatch_command (char *, int);
173 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
175 static void stop_command (char *arg
, int from_tty
);
177 static void stopin_command (char *arg
, int from_tty
);
179 static void stopat_command (char *arg
, int from_tty
);
181 static char *ep_parse_optional_if_clause (char **arg
);
183 static char *ep_parse_optional_filename (char **arg
);
185 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
186 char *arg
, int tempflag
, int from_tty
);
188 static void tcatch_command (char *arg
, int from_tty
);
190 static void ep_skip_leading_whitespace (char **s
);
192 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
194 static void free_bp_location (struct bp_location
*loc
);
196 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
198 static void update_global_location_list (int);
200 static void update_global_location_list_nothrow (int);
202 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
204 static void insert_breakpoint_locations (void);
206 static void tracepoints_info (char *, int);
208 static void delete_trace_command (char *, int);
210 static void enable_trace_command (char *, int);
212 static void disable_trace_command (char *, int);
214 static void trace_pass_command (char *, int);
216 static void skip_prologue_sal (struct symtab_and_line
*sal
);
219 /* Flag indicating that a command has proceeded the inferior past the
220 current breakpoint. */
222 static int breakpoint_proceeded
;
225 bpdisp_text (enum bpdisp disp
)
227 /* NOTE: the following values are a part of MI protocol and represent
228 values of 'disp' field returned when inferior stops at a breakpoint. */
229 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
230 return bpdisps
[(int) disp
];
233 /* Prototypes for exported functions. */
234 /* If FALSE, gdb will not use hardware support for watchpoints, even
235 if such is available. */
236 static int can_use_hw_watchpoints
;
239 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
240 struct cmd_list_element
*c
,
243 fprintf_filtered (file
, _("\
244 Debugger's willingness to use watchpoint hardware is %s.\n"),
248 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
249 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
250 for unrecognized breakpoint locations.
251 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
252 static enum auto_boolean pending_break_support
;
254 show_pending_break_support (struct ui_file
*file
, int from_tty
,
255 struct cmd_list_element
*c
,
258 fprintf_filtered (file
, _("\
259 Debugger's behavior regarding pending breakpoints is %s.\n"),
263 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
264 set with "break" but falling in read-only memory.
265 If 0, gdb will warn about such breakpoints, but won't automatically
266 use hardware breakpoints. */
267 static int automatic_hardware_breakpoints
;
269 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
270 struct cmd_list_element
*c
,
273 fprintf_filtered (file
, _("\
274 Automatic usage of hardware breakpoints is %s.\n"),
278 /* If on, gdb will keep breakpoints inserted even as inferior is
279 stopped, and immediately insert any new breakpoints. If off, gdb
280 will insert breakpoints into inferior only when resuming it, and
281 will remove breakpoints upon stop. If auto, GDB will behave as ON
282 if in non-stop mode, and as OFF if all-stop mode.*/
284 static const char always_inserted_auto
[] = "auto";
285 static const char always_inserted_on
[] = "on";
286 static const char always_inserted_off
[] = "off";
287 static const char *always_inserted_enums
[] = {
288 always_inserted_auto
,
293 static const char *always_inserted_mode
= always_inserted_auto
;
295 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
296 struct cmd_list_element
*c
, const char *value
)
298 if (always_inserted_mode
== always_inserted_auto
)
299 fprintf_filtered (file
, _("\
300 Always inserted breakpoint mode is %s (currently %s).\n"),
302 breakpoints_always_inserted_mode () ? "on" : "off");
304 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
308 breakpoints_always_inserted_mode (void)
310 return (always_inserted_mode
== always_inserted_on
311 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
314 void _initialize_breakpoint (void);
316 /* Are we executing breakpoint commands? */
317 static int executing_breakpoint_commands
;
319 /* Are overlay event breakpoints enabled? */
320 static int overlay_events_enabled
;
322 /* Are we executing startup code? */
323 static int executing_startup
;
325 /* Walk the following statement or block through all breakpoints.
326 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
329 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
331 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
332 for (B = breakpoint_chain; \
333 B ? (TMP=B->next, 1): 0; \
336 /* Similar iterators for the low-level breakpoints. */
338 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
340 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
341 for (B = bp_location_chain; \
342 B ? (TMP=B->global_next, 1): 0; \
345 /* Iterator for tracepoints only. */
347 #define ALL_TRACEPOINTS(B) \
348 for (B = breakpoint_chain; B; B = B->next) \
349 if ((B)->type == bp_tracepoint)
351 /* Chains of all breakpoints defined. */
353 struct breakpoint
*breakpoint_chain
;
355 struct bp_location
*bp_location_chain
;
357 /* The locations that no longer correspond to any breakpoint,
358 unlinked from bp_location_chain, but for which a hit
359 may still be reported by a target. */
360 VEC(bp_location_p
) *moribund_locations
= NULL
;
362 /* Number of last breakpoint made. */
364 int breakpoint_count
;
366 /* Number of last tracepoint made. */
368 int tracepoint_count
;
370 /* Return whether a breakpoint is an active enabled breakpoint. */
372 breakpoint_enabled (struct breakpoint
*b
)
374 return (b
->enable_state
== bp_enabled
);
377 /* Set breakpoint count to NUM. */
380 set_breakpoint_count (int num
)
382 breakpoint_count
= num
;
383 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
386 /* Used in run_command to zero the hit count when a new run starts. */
389 clear_breakpoint_hit_counts (void)
391 struct breakpoint
*b
;
397 /* Default address, symtab and line to put a breakpoint at
398 for "break" command with no arg.
399 if default_breakpoint_valid is zero, the other three are
400 not valid, and "break" with no arg is an error.
402 This set by print_stack_frame, which calls set_default_breakpoint. */
404 int default_breakpoint_valid
;
405 CORE_ADDR default_breakpoint_address
;
406 struct symtab
*default_breakpoint_symtab
;
407 int default_breakpoint_line
;
409 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
410 Advance *PP after the string and any trailing whitespace.
412 Currently the string can either be a number or "$" followed by the name
413 of a convenience variable. Making it an expression wouldn't work well
414 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
416 If the string is a NULL pointer, that denotes the last breakpoint.
418 TRAILER is a character which can be found after the number; most
419 commonly this is `-'. If you don't want a trailer, use \0. */
421 get_number_trailer (char **pp
, int trailer
)
423 int retval
= 0; /* default */
427 /* Empty line means refer to the last breakpoint. */
428 return breakpoint_count
;
431 /* Make a copy of the name, so we can null-terminate it
432 to pass to lookup_internalvar(). */
437 while (isalnum (*p
) || *p
== '_')
439 varname
= (char *) alloca (p
- start
+ 1);
440 strncpy (varname
, start
, p
- start
);
441 varname
[p
- start
] = '\0';
442 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
446 printf_filtered (_("Convenience variable must have integer value.\n"));
454 while (*p
>= '0' && *p
<= '9')
457 /* There is no number here. (e.g. "cond a == b"). */
459 /* Skip non-numeric token */
460 while (*p
&& !isspace((int) *p
))
462 /* Return zero, which caller must interpret as error. */
468 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
470 /* Trailing junk: return 0 and let caller print error msg. */
471 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
482 /* Like get_number_trailer, but don't allow a trailer. */
484 get_number (char **pp
)
486 return get_number_trailer (pp
, '\0');
489 /* Parse a number or a range.
490 * A number will be of the form handled by get_number.
491 * A range will be of the form <number1> - <number2>, and
492 * will represent all the integers between number1 and number2,
495 * While processing a range, this fuction is called iteratively;
496 * At each call it will return the next value in the range.
498 * At the beginning of parsing a range, the char pointer PP will
499 * be advanced past <number1> and left pointing at the '-' token.
500 * Subsequent calls will not advance the pointer until the range
501 * is completed. The call that completes the range will advance
502 * pointer PP past <number2>.
506 get_number_or_range (char **pp
)
508 static int last_retval
, end_value
;
509 static char *end_ptr
;
510 static int in_range
= 0;
514 /* Default case: pp is pointing either to a solo number,
515 or to the first number of a range. */
516 last_retval
= get_number_trailer (pp
, '-');
521 /* This is the start of a range (<number1> - <number2>).
522 Skip the '-', parse and remember the second number,
523 and also remember the end of the final token. */
527 while (isspace ((int) *end_ptr
))
528 end_ptr
++; /* skip white space */
529 end_value
= get_number (temp
);
530 if (end_value
< last_retval
)
532 error (_("inverted range"));
534 else if (end_value
== last_retval
)
536 /* degenerate range (number1 == number2). Advance the
537 token pointer so that the range will be treated as a
546 error (_("negative value"));
549 /* pp points to the '-' that betokens a range. All
550 number-parsing has already been done. Return the next
551 integer value (one greater than the saved previous value).
552 Do not advance the token pointer 'pp' until the end of range
555 if (++last_retval
== end_value
)
557 /* End of range reached; advance token pointer. */
567 /* condition N EXP -- set break condition of breakpoint N to EXP. */
570 condition_command (char *arg
, int from_tty
)
572 struct breakpoint
*b
;
577 error_no_arg (_("breakpoint number"));
580 bnum
= get_number (&p
);
582 error (_("Bad breakpoint argument: '%s'"), arg
);
585 if (b
->number
== bnum
)
587 struct bp_location
*loc
= b
->loc
;
588 for (; loc
; loc
= loc
->next
)
596 if (b
->cond_string
!= NULL
)
597 xfree (b
->cond_string
);
601 b
->cond_string
= NULL
;
603 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
608 /* I don't know if it matters whether this is the string the user
609 typed in or the decompiled expression. */
610 b
->cond_string
= xstrdup (arg
);
611 b
->condition_not_parsed
= 0;
612 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
616 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
618 error (_("Junk at end of expression"));
621 breakpoints_changed ();
622 observer_notify_breakpoint_modified (b
->number
);
626 error (_("No breakpoint number %d."), bnum
);
630 commands_command (char *arg
, int from_tty
)
632 struct breakpoint
*b
;
635 struct command_line
*l
;
637 /* If we allowed this, we would have problems with when to
638 free the storage, if we change the commands currently
641 if (executing_breakpoint_commands
)
642 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
645 bnum
= get_number (&p
);
648 error (_("Unexpected extra arguments following breakpoint number."));
651 if (b
->number
== bnum
)
653 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
655 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
656 l
= read_command_lines (tmpbuf
, from_tty
, 1);
657 do_cleanups (cleanups
);
658 free_command_lines (&b
->commands
);
660 breakpoints_changed ();
661 observer_notify_breakpoint_modified (b
->number
);
664 error (_("No breakpoint number %d."), bnum
);
667 /* Like commands_command, but instead of reading the commands from
668 input stream, takes them from an already parsed command structure.
670 This is used by cli-script.c to DTRT with breakpoint commands
671 that are part of if and while bodies. */
672 enum command_control_type
673 commands_from_control_command (char *arg
, struct command_line
*cmd
)
675 struct breakpoint
*b
;
679 /* If we allowed this, we would have problems with when to
680 free the storage, if we change the commands currently
683 if (executing_breakpoint_commands
)
684 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
686 /* An empty string for the breakpoint number means the last
687 breakpoint, but get_number expects a NULL pointer. */
692 bnum
= get_number (&p
);
695 error (_("Unexpected extra arguments following breakpoint number."));
698 if (b
->number
== bnum
)
700 free_command_lines (&b
->commands
);
701 if (cmd
->body_count
!= 1)
702 error (_("Invalid \"commands\" block structure."));
703 /* We need to copy the commands because if/while will free the
704 list after it finishes execution. */
705 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
706 breakpoints_changed ();
707 observer_notify_breakpoint_modified (b
->number
);
708 return simple_control
;
710 error (_("No breakpoint number %d."), bnum
);
713 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
714 by replacing any memory breakpoints with their shadowed contents. */
717 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
719 struct bp_location
*b
;
720 CORE_ADDR bp_addr
= 0;
726 if (b
->owner
->type
== bp_none
)
727 warning (_("reading through apparently deleted breakpoint #%d?"),
730 if (b
->loc_type
!= bp_loc_software_breakpoint
)
734 /* Addresses and length of the part of the breakpoint that
736 bp_addr
= b
->target_info
.placed_address
;
737 bp_size
= b
->target_info
.shadow_len
;
739 /* bp isn't valid, or doesn't shadow memory. */
742 if (bp_addr
+ bp_size
<= memaddr
)
743 /* The breakpoint is entirely before the chunk of memory we
747 if (bp_addr
>= memaddr
+ len
)
748 /* The breakpoint is entirely after the chunk of memory we are
752 /* Offset within shadow_contents. */
753 if (bp_addr
< memaddr
)
755 /* Only copy the second part of the breakpoint. */
756 bp_size
-= memaddr
- bp_addr
;
757 bptoffset
= memaddr
- bp_addr
;
761 if (bp_addr
+ bp_size
> memaddr
+ len
)
763 /* Only copy the first part of the breakpoint. */
764 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
767 memcpy (buf
+ bp_addr
- memaddr
,
768 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
773 /* A wrapper function for inserting catchpoints. */
775 insert_catchpoint (struct ui_out
*uo
, void *args
)
777 struct breakpoint
*b
= (struct breakpoint
*) args
;
780 gdb_assert (b
->type
== bp_catchpoint
);
781 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
787 is_hardware_watchpoint (struct breakpoint
*bpt
)
789 return (bpt
->type
== bp_hardware_watchpoint
790 || bpt
->type
== bp_read_watchpoint
791 || bpt
->type
== bp_access_watchpoint
);
794 /* Find the current value of a watchpoint on EXP. Return the value in
795 *VALP and *RESULTP and the chain of intermediate and final values
796 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
799 If a memory error occurs while evaluating the expression, *RESULTP will
800 be set to NULL. *RESULTP may be a lazy value, if the result could
801 not be read from memory. It is used to determine whether a value
802 is user-specified (we should watch the whole value) or intermediate
803 (we should watch only the bit used to locate the final value).
805 If the final value, or any intermediate value, could not be read
806 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
807 set to any referenced values. *VALP will never be a lazy value.
808 This is the value which we store in struct breakpoint.
810 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
811 value chain. The caller must free the values individually. If
812 VAL_CHAIN is NULL, all generated values will be left on the value
816 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
817 struct value
**resultp
, struct value
**val_chain
)
819 struct value
*mark
, *new_mark
, *result
;
820 volatile struct gdb_exception ex
;
828 /* Evaluate the expression. */
829 mark
= value_mark ();
832 TRY_CATCH (ex
, RETURN_MASK_ALL
)
834 result
= evaluate_expression (exp
);
838 /* Ignore memory errors, we want watchpoints pointing at
839 inaccessible memory to still be created; otherwise, throw the
840 error to some higher catcher. */
846 throw_exception (ex
);
851 new_mark
= value_mark ();
852 if (mark
== new_mark
)
857 /* Make sure it's not lazy, so that after the target stops again we
858 have a non-lazy previous value to compare with. */
860 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
865 /* Return the chain of intermediate values. We use this to
866 decide which addresses to watch. */
867 *val_chain
= new_mark
;
868 value_release_to_mark (mark
);
872 /* Assuming that B is a watchpoint:
873 - Reparse watchpoint expression, if REPARSE is non-zero
874 - Evaluate expression and store the result in B->val
875 - Evaluate the condition if there is one, and store the result
877 - Update the list of values that must be watched in B->loc.
879 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
880 If this is local watchpoint that is out of scope, delete it. */
882 update_watchpoint (struct breakpoint
*b
, int reparse
)
884 int within_current_scope
;
885 struct frame_id saved_frame_id
;
886 struct bp_location
*loc
;
889 /* We don't free locations. They are stored in bp_location_chain and
890 update_global_locations will eventually delete them and remove
891 breakpoints if needed. */
894 if (b
->disposition
== disp_del_at_next_stop
)
897 /* Save the current frame's ID so we can restore it after
898 evaluating the watchpoint expression on its own frame. */
899 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
900 took a frame parameter, so that we didn't have to change the
902 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
904 /* Determine if the watchpoint is within scope. */
905 if (b
->exp_valid_block
== NULL
)
906 within_current_scope
= 1;
909 struct frame_info
*fi
;
910 fi
= frame_find_by_id (b
->watchpoint_frame
);
911 within_current_scope
= (fi
!= NULL
);
912 if (within_current_scope
)
916 if (within_current_scope
&& reparse
)
925 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
926 /* If the meaning of expression itself changed, the old value is
927 no longer relevant. We don't want to report a watchpoint hit
928 to the user when the old value and the new value may actually
929 be completely different objects. */
935 /* If we failed to parse the expression, for example because
936 it refers to a global variable in a not-yet-loaded shared library,
937 don't try to insert watchpoint. We don't automatically delete
938 such watchpoint, though, since failure to parse expression
939 is different from out-of-scope watchpoint. */
940 if (within_current_scope
&& b
->exp
)
942 struct value
*val_chain
, *v
, *result
, *next
;
944 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
946 /* Avoid setting b->val if it's already set. The meaning of
947 b->val is 'the last value' user saw, and we should update
948 it only if we reported that last value to user. As it
949 happens, the code that reports it updates b->val directly. */
956 /* Change the type of breakpoint between hardware assisted or an
957 ordinary watchpoint depending on the hardware support and free
958 hardware slots. REPARSE is set when the inferior is started. */
959 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
962 int i
, mem_cnt
, other_type_used
;
964 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
966 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
969 b
->type
= bp_watchpoint
;
972 int target_resources_ok
= target_can_use_hardware_watchpoint
973 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
974 if (target_resources_ok
<= 0)
975 b
->type
= bp_watchpoint
;
977 b
->type
= bp_hardware_watchpoint
;
981 /* Look at each value on the value chain. */
982 for (v
= val_chain
; v
; v
= next
)
984 /* If it's a memory location, and GDB actually needed
985 its contents to evaluate the expression, then we
986 must watch it. If the first value returned is
987 still lazy, that means an error occurred reading it;
988 watch it anyway in case it becomes readable. */
989 if (VALUE_LVAL (v
) == lval_memory
990 && (v
== val_chain
|| ! value_lazy (v
)))
992 struct type
*vtype
= check_typedef (value_type (v
));
994 /* We only watch structs and arrays if user asked
995 for it explicitly, never if they just happen to
996 appear in the middle of some value chain. */
998 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
999 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1003 struct bp_location
*loc
, **tmp
;
1005 addr
= value_address (v
);
1006 len
= TYPE_LENGTH (value_type (v
));
1008 if (b
->type
== bp_read_watchpoint
)
1010 else if (b
->type
== bp_access_watchpoint
)
1013 loc
= allocate_bp_location (b
);
1014 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1017 loc
->gdbarch
= get_type_arch (value_type (v
));
1018 loc
->address
= addr
;
1020 loc
->watchpoint_type
= type
;
1024 next
= value_next (v
);
1029 /* We just regenerated the list of breakpoint locations.
1030 The new location does not have its condition field set to anything
1031 and therefore, we must always reparse the cond_string, independently
1032 of the value of the reparse flag. */
1033 if (b
->cond_string
!= NULL
)
1035 char *s
= b
->cond_string
;
1036 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1039 else if (!within_current_scope
)
1041 printf_filtered (_("\
1042 Watchpoint %d deleted because the program has left the block \n\
1043 in which its expression is valid.\n"),
1045 if (b
->related_breakpoint
)
1046 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1047 b
->disposition
= disp_del_at_next_stop
;
1050 /* Restore the selected frame. */
1051 select_frame (frame_find_by_id (saved_frame_id
));
1055 /* Returns 1 iff breakpoint location should be
1056 inserted in the inferior. */
1058 should_be_inserted (struct bp_location
*bpt
)
1060 if (!breakpoint_enabled (bpt
->owner
))
1063 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1066 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1069 /* Tracepoints are inserted by the target at a time of its choosing,
1071 if (bpt
->owner
->type
== bp_tracepoint
)
1077 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1078 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1079 and HW_BREAKPOINT_ERROR are used to report problems.
1081 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1082 method for each breakpoint or catchpoint type. */
1084 insert_bp_location (struct bp_location
*bpt
,
1085 struct ui_file
*tmp_error_stream
,
1086 int *disabled_breaks
,
1087 int *hw_breakpoint_error
)
1091 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1094 /* Initialize the target-specific information. */
1095 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1096 bpt
->target_info
.placed_address
= bpt
->address
;
1098 if (bpt
->loc_type
== bp_loc_software_breakpoint
1099 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1101 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1103 /* If the explicitly specified breakpoint type
1104 is not hardware breakpoint, check the memory map to see
1105 if the breakpoint address is in read only memory or not.
1106 Two important cases are:
1107 - location type is not hardware breakpoint, memory
1108 is readonly. We change the type of the location to
1109 hardware breakpoint.
1110 - location type is hardware breakpoint, memory is read-write.
1111 This means we've previously made the location hardware one, but
1112 then the memory map changed, so we undo.
1114 When breakpoints are removed, remove_breakpoints will
1115 use location types we've just set here, the only possible
1116 problem is that memory map has changed during running program,
1117 but it's not going to work anyway with current gdb. */
1118 struct mem_region
*mr
1119 = lookup_mem_region (bpt
->target_info
.placed_address
);
1123 if (automatic_hardware_breakpoints
)
1126 enum bp_loc_type new_type
;
1128 if (mr
->attrib
.mode
!= MEM_RW
)
1129 new_type
= bp_loc_hardware_breakpoint
;
1131 new_type
= bp_loc_software_breakpoint
;
1133 if (new_type
!= bpt
->loc_type
)
1135 static int said
= 0;
1136 bpt
->loc_type
= new_type
;
1139 fprintf_filtered (gdb_stdout
, _("\
1140 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1145 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1146 && mr
->attrib
.mode
!= MEM_RW
)
1147 warning (_("cannot set software breakpoint at readonly address %s"),
1148 paddress (bpt
->gdbarch
, bpt
->address
));
1152 /* First check to see if we have to handle an overlay. */
1153 if (overlay_debugging
== ovly_off
1154 || bpt
->section
== NULL
1155 || !(section_is_overlay (bpt
->section
)))
1157 /* No overlay handling: just set the breakpoint. */
1159 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1160 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1163 val
= target_insert_breakpoint (bpt
->gdbarch
,
1168 /* This breakpoint is in an overlay section.
1169 Shall we set a breakpoint at the LMA? */
1170 if (!overlay_events_enabled
)
1172 /* Yes -- overlay event support is not active,
1173 so we must try to set a breakpoint at the LMA.
1174 This will not work for a hardware breakpoint. */
1175 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1176 warning (_("hardware breakpoint %d not supported in overlay!"),
1177 bpt
->owner
->number
);
1180 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1182 /* Set a software (trap) breakpoint at the LMA. */
1183 bpt
->overlay_target_info
= bpt
->target_info
;
1184 bpt
->overlay_target_info
.placed_address
= addr
;
1185 val
= target_insert_breakpoint (bpt
->gdbarch
,
1186 &bpt
->overlay_target_info
);
1188 fprintf_unfiltered (tmp_error_stream
,
1189 "Overlay breakpoint %d failed: in ROM?\n",
1190 bpt
->owner
->number
);
1193 /* Shall we set a breakpoint at the VMA? */
1194 if (section_is_mapped (bpt
->section
))
1196 /* Yes. This overlay section is mapped into memory. */
1197 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1198 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1201 val
= target_insert_breakpoint (bpt
->gdbarch
,
1206 /* No. This breakpoint will not be inserted.
1207 No error, but do not mark the bp as 'inserted'. */
1214 /* Can't set the breakpoint. */
1215 if (solib_name_from_address (bpt
->address
))
1217 /* See also: disable_breakpoints_in_shlibs. */
1219 bpt
->shlib_disabled
= 1;
1220 if (!*disabled_breaks
)
1222 fprintf_unfiltered (tmp_error_stream
,
1223 "Cannot insert breakpoint %d.\n",
1224 bpt
->owner
->number
);
1225 fprintf_unfiltered (tmp_error_stream
,
1226 "Temporarily disabling shared library breakpoints:\n");
1228 *disabled_breaks
= 1;
1229 fprintf_unfiltered (tmp_error_stream
,
1230 "breakpoint #%d\n", bpt
->owner
->number
);
1234 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1236 *hw_breakpoint_error
= 1;
1237 fprintf_unfiltered (tmp_error_stream
,
1238 "Cannot insert hardware breakpoint %d.\n",
1239 bpt
->owner
->number
);
1243 fprintf_unfiltered (tmp_error_stream
,
1244 "Cannot insert breakpoint %d.\n",
1245 bpt
->owner
->number
);
1246 fprintf_filtered (tmp_error_stream
,
1247 "Error accessing memory address ");
1248 fputs_filtered (paddress (bpt
->gdbarch
, bpt
->address
),
1250 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1251 safe_strerror (val
));
1262 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1263 /* NOTE drow/2003-09-08: This state only exists for removing
1264 watchpoints. It's not clear that it's necessary... */
1265 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1267 val
= target_insert_watchpoint (bpt
->address
,
1269 bpt
->watchpoint_type
);
1270 bpt
->inserted
= (val
!= -1);
1273 else if (bpt
->owner
->type
== bp_catchpoint
)
1275 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1276 bpt
->owner
, RETURN_MASK_ERROR
);
1277 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1278 bpt
->owner
->number
);
1280 bpt
->owner
->enable_state
= bp_disabled
;
1284 /* We've already printed an error message if there was a problem
1285 inserting this catchpoint, and we've disabled the catchpoint,
1286 so just return success. */
1293 /* Make sure all breakpoints are inserted in inferior.
1294 Throws exception on any error.
1295 A breakpoint that is already inserted won't be inserted
1296 again, so calling this function twice is safe. */
1298 insert_breakpoints (void)
1300 struct breakpoint
*bpt
;
1302 ALL_BREAKPOINTS (bpt
)
1303 if (is_hardware_watchpoint (bpt
))
1304 update_watchpoint (bpt
, 0 /* don't reparse. */);
1306 update_global_location_list (1);
1308 /* update_global_location_list does not insert breakpoints when
1309 always_inserted_mode is not enabled. Explicitly insert them
1311 if (!breakpoints_always_inserted_mode ())
1312 insert_breakpoint_locations ();
1315 /* insert_breakpoints is used when starting or continuing the program.
1316 remove_breakpoints is used when the program stops.
1317 Both return zero if successful,
1318 or an `errno' value if could not write the inferior. */
1321 insert_breakpoint_locations (void)
1323 struct breakpoint
*bpt
;
1324 struct bp_location
*b
, *temp
;
1327 int disabled_breaks
= 0;
1328 int hw_breakpoint_error
= 0;
1330 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1331 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1333 /* Explicitly mark the warning -- this will only be printed if
1334 there was an error. */
1335 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1337 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1339 if (!should_be_inserted (b
) || b
->inserted
)
1342 /* There is no point inserting thread-specific breakpoints if the
1343 thread no longer exists. */
1344 if (b
->owner
->thread
!= -1
1345 && !valid_thread_id (b
->owner
->thread
))
1348 val
= insert_bp_location (b
, tmp_error_stream
,
1350 &hw_breakpoint_error
);
1355 /* If we failed to insert all locations of a watchpoint,
1356 remove them, as half-inserted watchpoint is of limited use. */
1357 ALL_BREAKPOINTS (bpt
)
1359 int some_failed
= 0;
1360 struct bp_location
*loc
;
1362 if (!is_hardware_watchpoint (bpt
))
1365 if (!breakpoint_enabled (bpt
))
1368 if (bpt
->disposition
== disp_del_at_next_stop
)
1371 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1379 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1381 remove_breakpoint (loc
, mark_uninserted
);
1383 hw_breakpoint_error
= 1;
1384 fprintf_unfiltered (tmp_error_stream
,
1385 "Could not insert hardware watchpoint %d.\n",
1393 /* If a hardware breakpoint or watchpoint was inserted, add a
1394 message about possibly exhausted resources. */
1395 if (hw_breakpoint_error
)
1397 fprintf_unfiltered (tmp_error_stream
,
1398 "Could not insert hardware breakpoints:\n\
1399 You may have requested too many hardware breakpoints/watchpoints.\n");
1401 target_terminal_ours_for_output ();
1402 error_stream (tmp_error_stream
);
1405 do_cleanups (cleanups
);
1409 remove_breakpoints (void)
1411 struct bp_location
*b
;
1414 ALL_BP_LOCATIONS (b
)
1417 val
|= remove_breakpoint (b
, mark_uninserted
);
1423 remove_hw_watchpoints (void)
1425 struct bp_location
*b
;
1428 ALL_BP_LOCATIONS (b
)
1430 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1431 val
|= remove_breakpoint (b
, mark_uninserted
);
1437 reattach_breakpoints (int pid
)
1439 struct bp_location
*b
;
1441 struct cleanup
*old_chain
= save_inferior_ptid ();
1442 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1443 int dummy1
= 0, dummy2
= 0;
1445 make_cleanup_ui_file_delete (tmp_error_stream
);
1447 inferior_ptid
= pid_to_ptid (pid
);
1448 ALL_BP_LOCATIONS (b
)
1453 val
= insert_bp_location (b
, tmp_error_stream
,
1457 do_cleanups (old_chain
);
1462 do_cleanups (old_chain
);
1466 static int internal_breakpoint_number
= -1;
1468 static struct breakpoint
*
1469 create_internal_breakpoint (struct gdbarch
*gdbarch
,
1470 CORE_ADDR address
, enum bptype type
)
1472 struct symtab_and_line sal
;
1473 struct breakpoint
*b
;
1475 init_sal (&sal
); /* initialize to zeroes */
1478 sal
.section
= find_pc_overlay (sal
.pc
);
1480 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
1481 b
->number
= internal_breakpoint_number
--;
1482 b
->disposition
= disp_donttouch
;
1488 create_overlay_event_breakpoint (char *func_name
)
1490 struct objfile
*objfile
;
1492 ALL_OBJFILES (objfile
)
1494 struct breakpoint
*b
;
1495 struct minimal_symbol
*m
;
1497 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1501 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1502 SYMBOL_VALUE_ADDRESS (m
),
1504 b
->addr_string
= xstrdup (func_name
);
1506 if (overlay_debugging
== ovly_auto
)
1508 b
->enable_state
= bp_enabled
;
1509 overlay_events_enabled
= 1;
1513 b
->enable_state
= bp_disabled
;
1514 overlay_events_enabled
= 0;
1517 update_global_location_list (1);
1521 create_longjmp_master_breakpoint (char *func_name
)
1523 struct objfile
*objfile
;
1525 ALL_OBJFILES (objfile
)
1527 struct breakpoint
*b
;
1528 struct minimal_symbol
*m
;
1530 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
1533 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1537 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1538 SYMBOL_VALUE_ADDRESS (m
),
1540 b
->addr_string
= xstrdup (func_name
);
1541 b
->enable_state
= bp_disabled
;
1543 update_global_location_list (1);
1547 update_breakpoints_after_exec (void)
1549 struct breakpoint
*b
;
1550 struct breakpoint
*temp
;
1551 struct bp_location
*bploc
;
1553 /* We're about to delete breakpoints from GDB's lists. If the
1554 INSERTED flag is true, GDB will try to lift the breakpoints by
1555 writing the breakpoints' "shadow contents" back into memory. The
1556 "shadow contents" are NOT valid after an exec, so GDB should not
1557 do that. Instead, the target is responsible from marking
1558 breakpoints out as soon as it detects an exec. We don't do that
1559 here instead, because there may be other attempts to delete
1560 breakpoints after detecting an exec and before reaching here. */
1561 ALL_BP_LOCATIONS (bploc
)
1562 gdb_assert (!bploc
->inserted
);
1564 ALL_BREAKPOINTS_SAFE (b
, temp
)
1566 /* Solib breakpoints must be explicitly reset after an exec(). */
1567 if (b
->type
== bp_shlib_event
)
1569 delete_breakpoint (b
);
1573 /* Thread event breakpoints must be set anew after an exec(),
1574 as must overlay event and longjmp master breakpoints. */
1575 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
1576 || b
->type
== bp_longjmp_master
)
1578 delete_breakpoint (b
);
1582 /* Step-resume breakpoints are meaningless after an exec(). */
1583 if (b
->type
== bp_step_resume
)
1585 delete_breakpoint (b
);
1589 /* Longjmp and longjmp-resume breakpoints are also meaningless
1591 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1593 delete_breakpoint (b
);
1597 if (b
->type
== bp_catchpoint
)
1599 /* For now, none of the bp_catchpoint breakpoints need to
1600 do anything at this point. In the future, if some of
1601 the catchpoints need to something, we will need to add
1602 a new method, and call this method from here. */
1606 /* bp_finish is a special case. The only way we ought to be able
1607 to see one of these when an exec() has happened, is if the user
1608 caught a vfork, and then said "finish". Ordinarily a finish just
1609 carries them to the call-site of the current callee, by setting
1610 a temporary bp there and resuming. But in this case, the finish
1611 will carry them entirely through the vfork & exec.
1613 We don't want to allow a bp_finish to remain inserted now. But
1614 we can't safely delete it, 'cause finish_command has a handle to
1615 the bp on a bpstat, and will later want to delete it. There's a
1616 chance (and I've seen it happen) that if we delete the bp_finish
1617 here, that its storage will get reused by the time finish_command
1618 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1619 We really must allow finish_command to delete a bp_finish.
1621 In the absense of a general solution for the "how do we know
1622 it's safe to delete something others may have handles to?"
1623 problem, what we'll do here is just uninsert the bp_finish, and
1624 let finish_command delete it.
1626 (We know the bp_finish is "doomed" in the sense that it's
1627 momentary, and will be deleted as soon as finish_command sees
1628 the inferior stopped. So it doesn't matter that the bp's
1629 address is probably bogus in the new a.out, unlike e.g., the
1630 solib breakpoints.) */
1632 if (b
->type
== bp_finish
)
1637 /* Without a symbolic address, we have little hope of the
1638 pre-exec() address meaning the same thing in the post-exec()
1640 if (b
->addr_string
== NULL
)
1642 delete_breakpoint (b
);
1646 /* FIXME what about longjmp breakpoints? Re-create them here? */
1647 create_overlay_event_breakpoint ("_ovly_debug_event");
1648 create_longjmp_master_breakpoint ("longjmp");
1649 create_longjmp_master_breakpoint ("_longjmp");
1650 create_longjmp_master_breakpoint ("siglongjmp");
1651 create_longjmp_master_breakpoint ("_siglongjmp");
1655 detach_breakpoints (int pid
)
1657 struct bp_location
*b
;
1659 struct cleanup
*old_chain
= save_inferior_ptid ();
1661 if (pid
== PIDGET (inferior_ptid
))
1662 error (_("Cannot detach breakpoints of inferior_ptid"));
1664 /* Set inferior_ptid; remove_breakpoint uses this global. */
1665 inferior_ptid
= pid_to_ptid (pid
);
1666 ALL_BP_LOCATIONS (b
)
1669 val
|= remove_breakpoint (b
, mark_inserted
);
1671 do_cleanups (old_chain
);
1676 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1680 if (b
->owner
->enable_state
== bp_permanent
)
1681 /* Permanent breakpoints cannot be inserted or removed. */
1684 /* The type of none suggests that owner is actually deleted.
1685 This should not ever happen. */
1686 gdb_assert (b
->owner
->type
!= bp_none
);
1688 if (b
->loc_type
== bp_loc_software_breakpoint
1689 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1691 /* "Normal" instruction breakpoint: either the standard
1692 trap-instruction bp (bp_breakpoint), or a
1693 bp_hardware_breakpoint. */
1695 /* First check to see if we have to handle an overlay. */
1696 if (overlay_debugging
== ovly_off
1697 || b
->section
== NULL
1698 || !(section_is_overlay (b
->section
)))
1700 /* No overlay handling: just remove the breakpoint. */
1702 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1703 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
1705 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
1709 /* This breakpoint is in an overlay section.
1710 Did we set a breakpoint at the LMA? */
1711 if (!overlay_events_enabled
)
1713 /* Yes -- overlay event support is not active, so we
1714 should have set a breakpoint at the LMA. Remove it.
1716 /* Ignore any failures: if the LMA is in ROM, we will
1717 have already warned when we failed to insert it. */
1718 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1719 target_remove_hw_breakpoint (b
->gdbarch
,
1720 &b
->overlay_target_info
);
1722 target_remove_breakpoint (b
->gdbarch
,
1723 &b
->overlay_target_info
);
1725 /* Did we set a breakpoint at the VMA?
1726 If so, we will have marked the breakpoint 'inserted'. */
1729 /* Yes -- remove it. Previously we did not bother to
1730 remove the breakpoint if the section had been
1731 unmapped, but let's not rely on that being safe. We
1732 don't know what the overlay manager might do. */
1733 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1734 val
= target_remove_hw_breakpoint (b
->gdbarch
,
1737 /* However, we should remove *software* breakpoints only
1738 if the section is still mapped, or else we overwrite
1739 wrong code with the saved shadow contents. */
1740 else if (section_is_mapped (b
->section
))
1741 val
= target_remove_breakpoint (b
->gdbarch
,
1748 /* No -- not inserted, so no need to remove. No error. */
1753 /* In some cases, we might not be able to remove a breakpoint
1754 in a shared library that has already been removed, but we
1755 have not yet processed the shlib unload event. */
1756 if (val
&& solib_name_from_address (b
->address
))
1761 b
->inserted
= (is
== mark_inserted
);
1763 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1768 b
->inserted
= (is
== mark_inserted
);
1769 val
= target_remove_watchpoint (b
->address
, b
->length
,
1770 b
->watchpoint_type
);
1772 /* Failure to remove any of the hardware watchpoints comes here. */
1773 if ((is
== mark_uninserted
) && (b
->inserted
))
1774 warning (_("Could not remove hardware watchpoint %d."),
1777 else if (b
->owner
->type
== bp_catchpoint
1778 && breakpoint_enabled (b
->owner
)
1781 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
1783 val
= b
->owner
->ops
->remove (b
->owner
);
1786 b
->inserted
= (is
== mark_inserted
);
1792 /* Clear the "inserted" flag in all breakpoints. */
1795 mark_breakpoints_out (void)
1797 struct bp_location
*bpt
;
1799 ALL_BP_LOCATIONS (bpt
)
1803 /* Clear the "inserted" flag in all breakpoints and delete any
1804 breakpoints which should go away between runs of the program.
1806 Plus other such housekeeping that has to be done for breakpoints
1809 Note: this function gets called at the end of a run (by
1810 generic_mourn_inferior) and when a run begins (by
1811 init_wait_for_inferior). */
1816 breakpoint_init_inferior (enum inf_context context
)
1818 struct breakpoint
*b
, *temp
;
1819 struct bp_location
*bpt
;
1822 /* If breakpoint locations are shared across processes, then there's
1824 if (gdbarch_has_global_breakpoints (target_gdbarch
))
1827 ALL_BP_LOCATIONS (bpt
)
1828 if (bpt
->owner
->enable_state
!= bp_permanent
)
1831 ALL_BREAKPOINTS_SAFE (b
, temp
)
1836 case bp_watchpoint_scope
:
1838 /* If the call dummy breakpoint is at the entry point it will
1839 cause problems when the inferior is rerun, so we better
1842 Also get rid of scope breakpoints. */
1843 delete_breakpoint (b
);
1847 case bp_hardware_watchpoint
:
1848 case bp_read_watchpoint
:
1849 case bp_access_watchpoint
:
1851 /* Likewise for watchpoints on local expressions. */
1852 if (b
->exp_valid_block
!= NULL
)
1853 delete_breakpoint (b
);
1854 else if (context
== inf_starting
)
1856 /* Reset val field to force reread of starting value
1857 in insert_breakpoints. */
1859 value_free (b
->val
);
1869 /* Get rid of the moribund locations. */
1870 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
1871 free_bp_location (bpt
);
1872 VEC_free (bp_location_p
, moribund_locations
);
1875 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1876 exists at PC. It returns ordinary_breakpoint_here if it's an
1877 ordinary breakpoint, or permanent_breakpoint_here if it's a
1878 permanent breakpoint.
1879 - When continuing from a location with an ordinary breakpoint, we
1880 actually single step once before calling insert_breakpoints.
1881 - When continuing from a localion with a permanent breakpoint, we
1882 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1883 the target, to advance the PC past the breakpoint. */
1885 enum breakpoint_here
1886 breakpoint_here_p (CORE_ADDR pc
)
1888 const struct bp_location
*bpt
;
1889 int any_breakpoint_here
= 0;
1891 ALL_BP_LOCATIONS (bpt
)
1893 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1894 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1897 if ((breakpoint_enabled (bpt
->owner
)
1898 || bpt
->owner
->enable_state
== bp_permanent
)
1899 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1901 if (overlay_debugging
1902 && section_is_overlay (bpt
->section
)
1903 && !section_is_mapped (bpt
->section
))
1904 continue; /* unmapped overlay -- can't be a match */
1905 else if (bpt
->owner
->enable_state
== bp_permanent
)
1906 return permanent_breakpoint_here
;
1908 any_breakpoint_here
= 1;
1912 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1915 /* Return true if there's a moribund breakpoint at PC. */
1918 moribund_breakpoint_here_p (CORE_ADDR pc
)
1920 struct bp_location
*loc
;
1923 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
1924 if (loc
->address
== pc
)
1930 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1931 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1932 This does not check for single-step breakpoints, which are
1933 inserted and removed using direct target manipulation. */
1936 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1938 const struct bp_location
*bpt
;
1940 ALL_BP_LOCATIONS (bpt
)
1942 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1943 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1947 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1949 if (overlay_debugging
1950 && section_is_overlay (bpt
->section
)
1951 && !section_is_mapped (bpt
->section
))
1952 continue; /* unmapped overlay -- can't be a match */
1960 /* Returns non-zero iff there's either regular breakpoint
1961 or a single step breakpoint inserted at PC. */
1964 breakpoint_inserted_here_p (CORE_ADDR pc
)
1966 if (regular_breakpoint_inserted_here_p (pc
))
1969 if (single_step_breakpoint_inserted_here_p (pc
))
1975 /* This function returns non-zero iff there is a software breakpoint
1979 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1981 const struct bp_location
*bpt
;
1982 int any_breakpoint_here
= 0;
1984 ALL_BP_LOCATIONS (bpt
)
1986 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1990 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1992 if (overlay_debugging
1993 && section_is_overlay (bpt
->section
)
1994 && !section_is_mapped (bpt
->section
))
1995 continue; /* unmapped overlay -- can't be a match */
2001 /* Also check for software single-step breakpoints. */
2002 if (single_step_breakpoint_inserted_here_p (pc
))
2008 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2009 PC is valid for process/thread PTID. */
2012 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
2014 const struct bp_location
*bpt
;
2015 /* The thread and task IDs associated to PTID, computed lazily. */
2019 ALL_BP_LOCATIONS (bpt
)
2021 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2022 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2025 if (!breakpoint_enabled (bpt
->owner
)
2026 && bpt
->owner
->enable_state
!= bp_permanent
)
2029 if (bpt
->address
!= pc
)
2032 if (bpt
->owner
->thread
!= -1)
2034 /* This is a thread-specific breakpoint. Check that ptid
2035 matches that thread. If thread hasn't been computed yet,
2036 it is now time to do so. */
2038 thread
= pid_to_thread_id (ptid
);
2039 if (bpt
->owner
->thread
!= thread
)
2043 if (bpt
->owner
->task
!= 0)
2045 /* This is a task-specific breakpoint. Check that ptid
2046 matches that task. If task hasn't been computed yet,
2047 it is now time to do so. */
2049 task
= ada_get_task_number (ptid
);
2050 if (bpt
->owner
->task
!= task
)
2054 if (overlay_debugging
2055 && section_is_overlay (bpt
->section
)
2056 && !section_is_mapped (bpt
->section
))
2057 continue; /* unmapped overlay -- can't be a match */
2066 /* bpstat stuff. External routines' interfaces are documented
2070 ep_is_catchpoint (struct breakpoint
*ep
)
2072 return (ep
->type
== bp_catchpoint
);
2076 bpstat_free (bpstat bs
)
2078 if (bs
->old_val
!= NULL
)
2079 value_free (bs
->old_val
);
2080 free_command_lines (&bs
->commands
);
2084 /* Clear a bpstat so that it says we are not at any breakpoint.
2085 Also free any storage that is part of a bpstat. */
2088 bpstat_clear (bpstat
*bsp
)
2105 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2106 is part of the bpstat is copied as well. */
2109 bpstat_copy (bpstat bs
)
2113 bpstat retval
= NULL
;
2118 for (; bs
!= NULL
; bs
= bs
->next
)
2120 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2121 memcpy (tmp
, bs
, sizeof (*tmp
));
2122 if (bs
->commands
!= NULL
)
2123 tmp
->commands
= copy_command_lines (bs
->commands
);
2124 if (bs
->old_val
!= NULL
)
2126 tmp
->old_val
= value_copy (bs
->old_val
);
2127 release_value (tmp
->old_val
);
2131 /* This is the first thing in the chain. */
2141 /* Find the bpstat associated with this breakpoint */
2144 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2149 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2151 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2157 /* Find a step_resume breakpoint associated with this bpstat.
2158 (If there are multiple step_resume bp's on the list, this function
2159 will arbitrarily pick one.)
2161 It is an error to use this function if BPSTAT doesn't contain a
2162 step_resume breakpoint.
2164 See wait_for_inferior's use of this function. */
2166 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2170 gdb_assert (bsp
!= NULL
);
2172 current_thread
= pid_to_thread_id (inferior_ptid
);
2174 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2176 if ((bsp
->breakpoint_at
!= NULL
)
2177 && (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
)
2178 && (bsp
->breakpoint_at
->owner
->thread
== current_thread
2179 || bsp
->breakpoint_at
->owner
->thread
== -1))
2180 return bsp
->breakpoint_at
->owner
;
2183 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2187 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2188 at. *BSP upon return is a bpstat which points to the remaining
2189 breakpoints stopped at (but which is not guaranteed to be good for
2190 anything but further calls to bpstat_num).
2191 Return 0 if passed a bpstat which does not indicate any breakpoints.
2192 Return -1 if stopped at a breakpoint that has been deleted since
2194 Return 1 otherwise. */
2197 bpstat_num (bpstat
*bsp
, int *num
)
2199 struct breakpoint
*b
;
2202 return 0; /* No more breakpoint values */
2204 /* We assume we'll never have several bpstats that
2205 correspond to a single breakpoint -- otherwise,
2206 this function might return the same number more
2207 than once and this will look ugly. */
2208 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2209 *bsp
= (*bsp
)->next
;
2211 return -1; /* breakpoint that's been deleted since */
2213 *num
= b
->number
; /* We have its number */
2217 /* Modify BS so that the actions will not be performed. */
2220 bpstat_clear_actions (bpstat bs
)
2222 for (; bs
!= NULL
; bs
= bs
->next
)
2224 free_command_lines (&bs
->commands
);
2225 if (bs
->old_val
!= NULL
)
2227 value_free (bs
->old_val
);
2233 /* Called when a command is about to proceed the inferior. */
2236 breakpoint_about_to_proceed (void)
2238 if (!ptid_equal (inferior_ptid
, null_ptid
))
2240 struct thread_info
*tp
= inferior_thread ();
2242 /* Allow inferior function calls in breakpoint commands to not
2243 interrupt the command list. When the call finishes
2244 successfully, the inferior will be standing at the same
2245 breakpoint as if nothing happened. */
2250 breakpoint_proceeded
= 1;
2253 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2255 cleanup_executing_breakpoints (void *ignore
)
2257 executing_breakpoint_commands
= 0;
2260 /* Execute all the commands associated with all the breakpoints at this
2261 location. Any of these commands could cause the process to proceed
2262 beyond this point, etc. We look out for such changes by checking
2263 the global "breakpoint_proceeded" after each command.
2265 Returns true if a breakpoint command resumed the inferior. In that
2266 case, it is the caller's responsibility to recall it again with the
2267 bpstat of the current thread. */
2270 bpstat_do_actions_1 (bpstat
*bsp
)
2273 struct cleanup
*old_chain
;
2276 /* Avoid endless recursion if a `source' command is contained
2278 if (executing_breakpoint_commands
)
2281 executing_breakpoint_commands
= 1;
2282 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2284 /* This pointer will iterate over the list of bpstat's. */
2287 breakpoint_proceeded
= 0;
2288 for (; bs
!= NULL
; bs
= bs
->next
)
2290 struct command_line
*cmd
;
2291 struct cleanup
*this_cmd_tree_chain
;
2293 /* Take ownership of the BSP's command tree, if it has one.
2295 The command tree could legitimately contain commands like
2296 'step' and 'next', which call clear_proceed_status, which
2297 frees stop_bpstat's command tree. To make sure this doesn't
2298 free the tree we're executing out from under us, we need to
2299 take ownership of the tree ourselves. Since a given bpstat's
2300 commands are only executed once, we don't need to copy it; we
2301 can clear the pointer in the bpstat, and make sure we free
2302 the tree when we're done. */
2305 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2309 execute_control_command (cmd
);
2311 if (breakpoint_proceeded
)
2317 /* We can free this command tree now. */
2318 do_cleanups (this_cmd_tree_chain
);
2320 if (breakpoint_proceeded
)
2322 if (target_can_async_p ())
2323 /* If we are in async mode, then the target might be still
2324 running, not stopped at any breakpoint, so nothing for
2325 us to do here -- just return to the event loop. */
2328 /* In sync mode, when execute_control_command returns
2329 we're already standing on the next breakpoint.
2330 Breakpoint commands for that stop were not run, since
2331 execute_command does not run breakpoint commands --
2332 only command_line_handler does, but that one is not
2333 involved in execution of breakpoint commands. So, we
2334 can now execute breakpoint commands. It should be
2335 noted that making execute_command do bpstat actions is
2336 not an option -- in this case we'll have recursive
2337 invocation of bpstat for each breakpoint with a
2338 command, and can easily blow up GDB stack. Instead, we
2339 return true, which will trigger the caller to recall us
2340 with the new stop_bpstat. */
2345 do_cleanups (old_chain
);
2350 bpstat_do_actions (void)
2352 /* Do any commands attached to breakpoint we are stopped at. */
2353 while (!ptid_equal (inferior_ptid
, null_ptid
)
2354 && target_has_execution
2355 && !is_exited (inferior_ptid
)
2356 && !is_executing (inferior_ptid
))
2357 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2358 and only return when it is stopped at the next breakpoint, we
2359 keep doing breakpoint actions until it returns false to
2360 indicate the inferior was not resumed. */
2361 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2365 /* Print out the (old or new) value associated with a watchpoint. */
2368 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2371 fprintf_unfiltered (stream
, _("<unreadable>"));
2374 struct value_print_options opts
;
2375 get_user_print_options (&opts
);
2376 value_print (val
, stream
, &opts
);
2380 /* This is the normal print function for a bpstat. In the future,
2381 much of this logic could (should?) be moved to bpstat_stop_status,
2382 by having it set different print_it values.
2384 Current scheme: When we stop, bpstat_print() is called. It loops
2385 through the bpstat list of things causing this stop, calling the
2386 print_bp_stop_message function on each one. The behavior of the
2387 print_bp_stop_message function depends on the print_it field of
2388 bpstat. If such field so indicates, call this function here.
2390 Return values from this routine (ultimately used by bpstat_print()
2391 and normal_stop() to decide what to do):
2392 PRINT_NOTHING: Means we already printed all we needed to print,
2393 don't print anything else.
2394 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2395 that something to be followed by a location.
2396 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2397 that something to be followed by a location.
2398 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2401 static enum print_stop_action
2402 print_it_typical (bpstat bs
)
2404 struct cleanup
*old_chain
;
2405 struct breakpoint
*b
;
2406 const struct bp_location
*bl
;
2407 struct ui_stream
*stb
;
2409 enum print_stop_action result
;
2411 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2412 which has since been deleted. */
2413 if (bs
->breakpoint_at
== NULL
)
2414 return PRINT_UNKNOWN
;
2415 bl
= bs
->breakpoint_at
;
2418 stb
= ui_out_stream_new (uiout
);
2419 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2424 case bp_hardware_breakpoint
:
2425 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2426 if (bl
->address
!= bl
->requested_address
)
2427 breakpoint_adjustment_warning (bl
->requested_address
,
2430 annotate_breakpoint (b
->number
);
2432 ui_out_text (uiout
, "\nTemporary breakpoint ");
2434 ui_out_text (uiout
, "\nBreakpoint ");
2435 if (ui_out_is_mi_like_p (uiout
))
2437 ui_out_field_string (uiout
, "reason",
2438 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2439 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2441 ui_out_field_int (uiout
, "bkptno", b
->number
);
2442 ui_out_text (uiout
, ", ");
2443 result
= PRINT_SRC_AND_LOC
;
2446 case bp_shlib_event
:
2447 /* Did we stop because the user set the stop_on_solib_events
2448 variable? (If so, we report this as a generic, "Stopped due
2449 to shlib event" message.) */
2450 printf_filtered (_("Stopped due to shared library event\n"));
2451 result
= PRINT_NOTHING
;
2454 case bp_thread_event
:
2455 /* Not sure how we will get here.
2456 GDB should not stop for these breakpoints. */
2457 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2458 result
= PRINT_NOTHING
;
2461 case bp_overlay_event
:
2462 /* By analogy with the thread event, GDB should not stop for these. */
2463 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2464 result
= PRINT_NOTHING
;
2467 case bp_longjmp_master
:
2468 /* These should never be enabled. */
2469 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
2470 result
= PRINT_NOTHING
;
2474 case bp_hardware_watchpoint
:
2475 annotate_watchpoint (b
->number
);
2476 if (ui_out_is_mi_like_p (uiout
))
2479 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2481 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2482 ui_out_text (uiout
, "\nOld value = ");
2483 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2484 ui_out_field_stream (uiout
, "old", stb
);
2485 ui_out_text (uiout
, "\nNew value = ");
2486 watchpoint_value_print (b
->val
, stb
->stream
);
2487 ui_out_field_stream (uiout
, "new", stb
);
2488 ui_out_text (uiout
, "\n");
2489 /* More than one watchpoint may have been triggered. */
2490 result
= PRINT_UNKNOWN
;
2493 case bp_read_watchpoint
:
2494 if (ui_out_is_mi_like_p (uiout
))
2497 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2499 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2500 ui_out_text (uiout
, "\nValue = ");
2501 watchpoint_value_print (b
->val
, stb
->stream
);
2502 ui_out_field_stream (uiout
, "value", stb
);
2503 ui_out_text (uiout
, "\n");
2504 result
= PRINT_UNKNOWN
;
2507 case bp_access_watchpoint
:
2508 if (bs
->old_val
!= NULL
)
2510 annotate_watchpoint (b
->number
);
2511 if (ui_out_is_mi_like_p (uiout
))
2514 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2516 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2517 ui_out_text (uiout
, "\nOld value = ");
2518 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2519 ui_out_field_stream (uiout
, "old", stb
);
2520 ui_out_text (uiout
, "\nNew value = ");
2525 if (ui_out_is_mi_like_p (uiout
))
2528 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2529 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2530 ui_out_text (uiout
, "\nValue = ");
2532 watchpoint_value_print (b
->val
, stb
->stream
);
2533 ui_out_field_stream (uiout
, "new", stb
);
2534 ui_out_text (uiout
, "\n");
2535 result
= PRINT_UNKNOWN
;
2538 /* Fall through, we don't deal with these types of breakpoints
2542 if (ui_out_is_mi_like_p (uiout
))
2545 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2546 result
= PRINT_UNKNOWN
;
2550 if (ui_out_is_mi_like_p (uiout
))
2553 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2554 result
= PRINT_UNKNOWN
;
2559 case bp_longjmp_resume
:
2560 case bp_step_resume
:
2561 case bp_watchpoint_scope
:
2565 result
= PRINT_UNKNOWN
;
2569 do_cleanups (old_chain
);
2573 /* Generic routine for printing messages indicating why we
2574 stopped. The behavior of this function depends on the value
2575 'print_it' in the bpstat structure. Under some circumstances we
2576 may decide not to print anything here and delegate the task to
2579 static enum print_stop_action
2580 print_bp_stop_message (bpstat bs
)
2582 switch (bs
->print_it
)
2585 /* Nothing should be printed for this bpstat entry. */
2586 return PRINT_UNKNOWN
;
2590 /* We still want to print the frame, but we already printed the
2591 relevant messages. */
2592 return PRINT_SRC_AND_LOC
;
2595 case print_it_normal
:
2597 const struct bp_location
*bl
= bs
->breakpoint_at
;
2598 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2600 /* Normal case. Call the breakpoint's print_it method, or
2601 print_it_typical. */
2602 /* FIXME: how breakpoint can ever be NULL here? */
2603 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2604 return b
->ops
->print_it (b
);
2606 return print_it_typical (bs
);
2611 internal_error (__FILE__
, __LINE__
,
2612 _("print_bp_stop_message: unrecognized enum value"));
2617 /* Print a message indicating what happened. This is called from
2618 normal_stop(). The input to this routine is the head of the bpstat
2619 list - a list of the eventpoints that caused this stop. This
2620 routine calls the generic print routine for printing a message
2621 about reasons for stopping. This will print (for example) the
2622 "Breakpoint n," part of the output. The return value of this
2625 PRINT_UNKNOWN: Means we printed nothing
2626 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2627 code to print the location. An example is
2628 "Breakpoint 1, " which should be followed by
2630 PRINT_SRC_ONLY: Means we printed something, but there is no need
2631 to also print the location part of the message.
2632 An example is the catch/throw messages, which
2633 don't require a location appended to the end.
2634 PRINT_NOTHING: We have done some printing and we don't need any
2635 further info to be printed.*/
2637 enum print_stop_action
2638 bpstat_print (bpstat bs
)
2642 /* Maybe another breakpoint in the chain caused us to stop.
2643 (Currently all watchpoints go on the bpstat whether hit or not.
2644 That probably could (should) be changed, provided care is taken
2645 with respect to bpstat_explains_signal). */
2646 for (; bs
; bs
= bs
->next
)
2648 val
= print_bp_stop_message (bs
);
2649 if (val
== PRINT_SRC_ONLY
2650 || val
== PRINT_SRC_AND_LOC
2651 || val
== PRINT_NOTHING
)
2655 /* We reached the end of the chain, or we got a null BS to start
2656 with and nothing was printed. */
2657 return PRINT_UNKNOWN
;
2660 /* Evaluate the expression EXP and return 1 if value is zero.
2661 This is used inside a catch_errors to evaluate the breakpoint condition.
2662 The argument is a "struct expression *" that has been cast to char * to
2663 make it pass through catch_errors. */
2666 breakpoint_cond_eval (void *exp
)
2668 struct value
*mark
= value_mark ();
2669 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2670 value_free_to_mark (mark
);
2674 /* Allocate a new bpstat and chain it to the current one. */
2677 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2681 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2683 bs
->breakpoint_at
= bl
;
2684 /* If the condition is false, etc., don't do the commands. */
2685 bs
->commands
= NULL
;
2687 bs
->print_it
= print_it_normal
;
2691 /* The target has stopped with waitstatus WS. Check if any hardware
2692 watchpoints have triggered, according to the target. */
2695 watchpoints_triggered (struct target_waitstatus
*ws
)
2697 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
2699 struct breakpoint
*b
;
2701 if (!stopped_by_watchpoint
)
2703 /* We were not stopped by a watchpoint. Mark all watchpoints
2704 as not triggered. */
2706 if (b
->type
== bp_hardware_watchpoint
2707 || b
->type
== bp_read_watchpoint
2708 || b
->type
== bp_access_watchpoint
)
2709 b
->watchpoint_triggered
= watch_triggered_no
;
2714 if (!target_stopped_data_address (¤t_target
, &addr
))
2716 /* We were stopped by a watchpoint, but we don't know where.
2717 Mark all watchpoints as unknown. */
2719 if (b
->type
== bp_hardware_watchpoint
2720 || b
->type
== bp_read_watchpoint
2721 || b
->type
== bp_access_watchpoint
)
2722 b
->watchpoint_triggered
= watch_triggered_unknown
;
2724 return stopped_by_watchpoint
;
2727 /* The target could report the data address. Mark watchpoints
2728 affected by this data address as triggered, and all others as not
2732 if (b
->type
== bp_hardware_watchpoint
2733 || b
->type
== bp_read_watchpoint
2734 || b
->type
== bp_access_watchpoint
)
2736 struct bp_location
*loc
;
2739 b
->watchpoint_triggered
= watch_triggered_no
;
2740 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2741 /* Exact match not required. Within range is
2743 if (target_watchpoint_addr_within_range (¤t_target
,
2747 b
->watchpoint_triggered
= watch_triggered_yes
;
2755 /* Possible return values for watchpoint_check (this can't be an enum
2756 because of check_errors). */
2757 /* The watchpoint has been deleted. */
2758 #define WP_DELETED 1
2759 /* The value has changed. */
2760 #define WP_VALUE_CHANGED 2
2761 /* The value has not changed. */
2762 #define WP_VALUE_NOT_CHANGED 3
2764 #define BP_TEMPFLAG 1
2765 #define BP_HARDWAREFLAG 2
2767 /* Check watchpoint condition. */
2770 watchpoint_check (void *p
)
2772 bpstat bs
= (bpstat
) p
;
2773 struct breakpoint
*b
;
2774 struct frame_info
*fr
;
2775 int within_current_scope
;
2777 b
= bs
->breakpoint_at
->owner
;
2779 if (b
->exp_valid_block
== NULL
)
2780 within_current_scope
= 1;
2783 struct frame_info
*frame
= get_current_frame ();
2784 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
2785 CORE_ADDR frame_pc
= get_frame_pc (frame
);
2787 fr
= frame_find_by_id (b
->watchpoint_frame
);
2788 within_current_scope
= (fr
!= NULL
);
2790 /* If we've gotten confused in the unwinder, we might have
2791 returned a frame that can't describe this variable. */
2792 if (within_current_scope
)
2794 struct symbol
*function
;
2796 function
= get_frame_function (fr
);
2797 if (function
== NULL
2798 || !contained_in (b
->exp_valid_block
,
2799 SYMBOL_BLOCK_VALUE (function
)))
2800 within_current_scope
= 0;
2803 /* in_function_epilogue_p() returns a non-zero value if we're still
2804 in the function but the stack frame has already been invalidated.
2805 Since we can't rely on the values of local variables after the
2806 stack has been destroyed, we are treating the watchpoint in that
2807 state as `not changed' without further checking. Don't mark
2808 watchpoints as changed if the current frame is in an epilogue -
2809 even if they are in some other frame, our view of the stack
2810 is likely to be wrong. */
2811 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
2812 return WP_VALUE_NOT_CHANGED
;
2814 if (within_current_scope
)
2815 /* If we end up stopping, the current frame will get selected
2816 in normal_stop. So this call to select_frame won't affect
2821 if (within_current_scope
)
2823 /* We use value_{,free_to_}mark because it could be a
2824 *long* time before we return to the command level and
2825 call free_all_values. We can't call free_all_values because
2826 we might be in the middle of evaluating a function call. */
2828 struct value
*mark
= value_mark ();
2829 struct value
*new_val
;
2831 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2832 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2833 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2835 if (new_val
!= NULL
)
2837 release_value (new_val
);
2838 value_free_to_mark (mark
);
2840 bs
->old_val
= b
->val
;
2843 /* We will stop here */
2844 return WP_VALUE_CHANGED
;
2848 /* Nothing changed, don't do anything. */
2849 value_free_to_mark (mark
);
2850 /* We won't stop here */
2851 return WP_VALUE_NOT_CHANGED
;
2856 /* This seems like the only logical thing to do because
2857 if we temporarily ignored the watchpoint, then when
2858 we reenter the block in which it is valid it contains
2859 garbage (in the case of a function, it may have two
2860 garbage values, one before and one after the prologue).
2861 So we can't even detect the first assignment to it and
2862 watch after that (since the garbage may or may not equal
2863 the first value assigned). */
2864 /* We print all the stop information in print_it_typical(), but
2865 in this case, by the time we call print_it_typical() this bp
2866 will be deleted already. So we have no choice but print the
2867 information here. */
2868 if (ui_out_is_mi_like_p (uiout
))
2870 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2871 ui_out_text (uiout
, "\nWatchpoint ");
2872 ui_out_field_int (uiout
, "wpnum", b
->number
);
2873 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2874 which its expression is valid.\n");
2876 if (b
->related_breakpoint
)
2877 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2878 b
->disposition
= disp_del_at_next_stop
;
2884 /* Return true if it looks like target has stopped due to hitting
2885 breakpoint location BL. This function does not check if we
2886 should stop, only if BL explains the stop. */
2888 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2890 struct breakpoint
*b
= bl
->owner
;
2892 if (b
->type
!= bp_watchpoint
2893 && b
->type
!= bp_hardware_watchpoint
2894 && b
->type
!= bp_read_watchpoint
2895 && b
->type
!= bp_access_watchpoint
2896 && b
->type
!= bp_hardware_breakpoint
2897 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
2899 if (bl
->address
!= bp_addr
) /* address doesn't match */
2901 if (overlay_debugging
/* unmapped overlay section */
2902 && section_is_overlay (bl
->section
)
2903 && !section_is_mapped (bl
->section
))
2907 /* Continuable hardware watchpoints are treated as non-existent if the
2908 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2909 some data address). Otherwise gdb won't stop on a break instruction
2910 in the code (not from a breakpoint) when a hardware watchpoint has
2911 been defined. Also skip watchpoints which we know did not trigger
2912 (did not match the data address). */
2914 if ((b
->type
== bp_hardware_watchpoint
2915 || b
->type
== bp_read_watchpoint
2916 || b
->type
== bp_access_watchpoint
)
2917 && b
->watchpoint_triggered
== watch_triggered_no
)
2920 if (b
->type
== bp_hardware_breakpoint
)
2922 if (bl
->address
!= bp_addr
)
2924 if (overlay_debugging
/* unmapped overlay section */
2925 && section_is_overlay (bl
->section
)
2926 && !section_is_mapped (bl
->section
))
2930 if (b
->type
== bp_catchpoint
)
2932 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2933 if (!b
->ops
->breakpoint_hit (b
))
2940 /* If BS refers to a watchpoint, determine if the watched values
2941 has actually changed, and we should stop. If not, set BS->stop
2944 bpstat_check_watchpoint (bpstat bs
)
2946 const struct bp_location
*bl
= bs
->breakpoint_at
;
2947 struct breakpoint
*b
= bl
->owner
;
2949 if (b
->type
== bp_watchpoint
2950 || b
->type
== bp_read_watchpoint
2951 || b
->type
== bp_access_watchpoint
2952 || b
->type
== bp_hardware_watchpoint
)
2956 int must_check_value
= 0;
2958 if (b
->type
== bp_watchpoint
)
2959 /* For a software watchpoint, we must always check the
2961 must_check_value
= 1;
2962 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2963 /* We have a hardware watchpoint (read, write, or access)
2964 and the target earlier reported an address watched by
2966 must_check_value
= 1;
2967 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2968 && b
->type
== bp_hardware_watchpoint
)
2969 /* We were stopped by a hardware watchpoint, but the target could
2970 not report the data address. We must check the watchpoint's
2971 value. Access and read watchpoints are out of luck; without
2972 a data address, we can't figure it out. */
2973 must_check_value
= 1;
2975 if (must_check_value
)
2977 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2979 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2980 int e
= catch_errors (watchpoint_check
, bs
, message
,
2982 do_cleanups (cleanups
);
2986 /* We've already printed what needs to be printed. */
2987 bs
->print_it
= print_it_done
;
2990 case WP_VALUE_CHANGED
:
2991 if (b
->type
== bp_read_watchpoint
)
2993 /* Don't stop: read watchpoints shouldn't fire if
2994 the value has changed. This is for targets
2995 which cannot set read-only watchpoints. */
2996 bs
->print_it
= print_it_noop
;
3000 case WP_VALUE_NOT_CHANGED
:
3001 if (b
->type
== bp_hardware_watchpoint
3002 || b
->type
== bp_watchpoint
)
3004 /* Don't stop: write watchpoints shouldn't fire if
3005 the value hasn't changed. */
3006 bs
->print_it
= print_it_noop
;
3014 /* Error from catch_errors. */
3015 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3016 if (b
->related_breakpoint
)
3017 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3018 b
->disposition
= disp_del_at_next_stop
;
3019 /* We've already printed what needs to be printed. */
3020 bs
->print_it
= print_it_done
;
3024 else /* must_check_value == 0 */
3026 /* This is a case where some watchpoint(s) triggered, but
3027 not at the address of this watchpoint, or else no
3028 watchpoint triggered after all. So don't print
3029 anything for this watchpoint. */
3030 bs
->print_it
= print_it_noop
;
3037 /* Check conditions (condition proper, frame, thread and ignore count)
3038 of breakpoint referred to by BS. If we should not stop for this
3039 breakpoint, set BS->stop to 0. */
3041 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3043 int thread_id
= pid_to_thread_id (ptid
);
3044 const struct bp_location
*bl
= bs
->breakpoint_at
;
3045 struct breakpoint
*b
= bl
->owner
;
3047 if (frame_id_p (b
->frame_id
)
3048 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3052 int value_is_zero
= 0;
3054 /* If this is a scope breakpoint, mark the associated
3055 watchpoint as triggered so that we will handle the
3056 out-of-scope event. We'll get to the watchpoint next
3058 if (b
->type
== bp_watchpoint_scope
)
3059 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3061 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3063 /* We use value_mark and value_free_to_mark because it could
3064 be a long time before we return to the command level and
3065 call free_all_values. We can't call free_all_values
3066 because we might be in the middle of evaluating a
3068 struct value
*mark
= value_mark ();
3070 /* Need to select the frame, with all that implies so that
3071 the conditions will have the right context. Because we
3072 use the frame, we will not see an inlined function's
3073 variables when we arrive at a breakpoint at the start
3074 of the inlined function; the current frame will be the
3076 select_frame (get_current_frame ());
3078 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
3079 "Error in testing breakpoint condition:\n",
3081 /* FIXME-someday, should give breakpoint # */
3082 value_free_to_mark (mark
);
3084 if (bl
->cond
&& value_is_zero
)
3088 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3092 else if (b
->ignore_count
> 0)
3095 annotate_ignore_count_change ();
3097 /* Increase the hit count even though we don't
3105 /* Get a bpstat associated with having just stopped at address
3106 BP_ADDR in thread PTID.
3108 Determine whether we stopped at a breakpoint, etc, or whether we
3109 don't understand this stop. Result is a chain of bpstat's such that:
3111 if we don't understand the stop, the result is a null pointer.
3113 if we understand why we stopped, the result is not null.
3115 Each element of the chain refers to a particular breakpoint or
3116 watchpoint at which we have stopped. (We may have stopped for
3117 several reasons concurrently.)
3119 Each element of the chain has valid next, breakpoint_at,
3120 commands, FIXME??? fields. */
3123 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3125 struct breakpoint
*b
= NULL
;
3126 const struct bp_location
*bl
;
3127 struct bp_location
*loc
;
3128 /* Root of the chain of bpstat's */
3129 struct bpstats root_bs
[1];
3130 /* Pointer to the last thing in the chain currently. */
3131 bpstat bs
= root_bs
;
3133 int need_remove_insert
;
3135 ALL_BP_LOCATIONS (bl
)
3139 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3142 /* For hardware watchpoints, we look only at the first location.
3143 The watchpoint_check function will work on entire expression,
3144 not the individual locations. For read watchopints, the
3145 watchpoints_triggered function have checked all locations
3148 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3151 if (!bpstat_check_location (bl
, bp_addr
))
3154 /* Come here if it's a watchpoint, or if the break address matches */
3156 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3158 /* Assume we stop. Should we find watchpoint that is not actually
3159 triggered, or if condition of breakpoint is false, we'll reset
3164 bpstat_check_watchpoint (bs
);
3168 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3169 || b
->type
== bp_longjmp_master
)
3170 /* We do not stop for these. */
3173 bpstat_check_breakpoint_conditions (bs
, ptid
);
3179 /* We will stop here */
3180 if (b
->disposition
== disp_disable
)
3182 if (b
->enable_state
!= bp_permanent
)
3183 b
->enable_state
= bp_disabled
;
3184 update_global_location_list (0);
3188 bs
->commands
= b
->commands
;
3190 && (strcmp ("silent", bs
->commands
->line
) == 0
3191 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3193 bs
->commands
= bs
->commands
->next
;
3196 bs
->commands
= copy_command_lines (bs
->commands
);
3199 /* Print nothing for this entry if we dont stop or if we dont print. */
3200 if (bs
->stop
== 0 || bs
->print
== 0)
3201 bs
->print_it
= print_it_noop
;
3204 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3206 if (loc
->address
== bp_addr
)
3208 bs
= bpstat_alloc (loc
, bs
);
3209 /* For hits of moribund locations, we should just proceed. */
3212 bs
->print_it
= print_it_noop
;
3216 bs
->next
= NULL
; /* Terminate the chain */
3217 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3219 /* If we aren't stopping, the value of some hardware watchpoint may
3220 not have changed, but the intermediate memory locations we are
3221 watching may have. Don't bother if we're stopping; this will get
3223 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3227 need_remove_insert
= 0;
3229 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3231 && bs
->breakpoint_at
->owner
3232 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3233 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3234 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3236 /* remove/insert can invalidate bs->breakpoint_at, if this
3237 location is no longer used by the watchpoint. Prevent
3238 further code from trying to use it. */
3239 bs
->breakpoint_at
= NULL
;
3240 need_remove_insert
= 1;
3243 if (need_remove_insert
)
3245 remove_breakpoints ();
3246 insert_breakpoints ();
3249 return root_bs
->next
;
3252 /* Tell what to do about this bpstat. */
3254 bpstat_what (bpstat bs
)
3256 /* Classify each bpstat as one of the following. */
3259 /* This bpstat element has no effect on the main_action. */
3262 /* There was a watchpoint, stop but don't print. */
3265 /* There was a watchpoint, stop and print. */
3268 /* There was a breakpoint but we're not stopping. */
3271 /* There was a breakpoint, stop but don't print. */
3274 /* There was a breakpoint, stop and print. */
3277 /* We hit the longjmp breakpoint. */
3280 /* We hit the longjmp_resume breakpoint. */
3283 /* We hit the step_resume breakpoint. */
3286 /* We hit the shared library event breakpoint. */
3289 /* This is just used to count how many enums there are. */
3293 /* Here is the table which drives this routine. So that we can
3294 format it pretty, we define some abbreviations for the
3295 enum bpstat_what codes. */
3296 #define kc BPSTAT_WHAT_KEEP_CHECKING
3297 #define ss BPSTAT_WHAT_STOP_SILENT
3298 #define sn BPSTAT_WHAT_STOP_NOISY
3299 #define sgl BPSTAT_WHAT_SINGLE
3300 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3301 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3302 #define sr BPSTAT_WHAT_STEP_RESUME
3303 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3305 /* "Can't happen." Might want to print an error message.
3306 abort() is not out of the question, but chances are GDB is just
3307 a bit confused, not unusable. */
3308 #define err BPSTAT_WHAT_STOP_NOISY
3310 /* Given an old action and a class, come up with a new action. */
3311 /* One interesting property of this table is that wp_silent is the same
3312 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3313 after stopping, the check for whether to step over a breakpoint
3314 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3315 reference to how we stopped. We retain separate wp_silent and
3316 bp_silent codes in case we want to change that someday.
3318 Another possibly interesting property of this table is that
3319 there's a partial ordering, priority-like, of the actions. Once
3320 you've decided that some action is appropriate, you'll never go
3321 back and decide something of a lower priority is better. The
3324 kc < clr sgl shl slr sn sr ss
3325 sgl < shl slr sn sr ss
3326 slr < err shl sn sr ss
3327 clr < err shl sn sr ss
3333 What I think this means is that we don't need a damned table
3334 here. If you just put the rows and columns in the right order,
3335 it'd look awfully regular. We could simply walk the bpstat list
3336 and choose the highest priority action we find, with a little
3337 logic to handle the 'err' cases. */
3339 /* step_resume entries: a step resume breakpoint overrides another
3340 breakpoint of signal handling (see comment in wait_for_inferior
3341 at where we set the step_resume breakpoint). */
3343 static const enum bpstat_what_main_action
3344 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3347 /* kc ss sn sgl slr clr sr shl
3350 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
},
3352 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3354 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3356 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
},
3358 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3360 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3362 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
},
3364 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
},
3366 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3368 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
}
3381 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3382 struct bpstat_what retval
;
3384 retval
.call_dummy
= 0;
3385 for (; bs
!= NULL
; bs
= bs
->next
)
3387 enum class bs_class
= no_effect
;
3388 if (bs
->breakpoint_at
== NULL
)
3389 /* I suspect this can happen if it was a momentary breakpoint
3390 which has since been deleted. */
3392 if (bs
->breakpoint_at
->owner
== NULL
)
3393 bs_class
= bp_nostop
;
3395 switch (bs
->breakpoint_at
->owner
->type
)
3401 case bp_hardware_breakpoint
:
3407 bs_class
= bp_noisy
;
3409 bs_class
= bp_silent
;
3412 bs_class
= bp_nostop
;
3415 case bp_hardware_watchpoint
:
3416 case bp_read_watchpoint
:
3417 case bp_access_watchpoint
:
3421 bs_class
= wp_noisy
;
3423 bs_class
= wp_silent
;
3426 /* There was a watchpoint, but we're not stopping.
3427 This requires no further action. */
3428 bs_class
= no_effect
;
3431 bs_class
= long_jump
;
3433 case bp_longjmp_resume
:
3434 bs_class
= long_resume
;
3436 case bp_step_resume
:
3439 bs_class
= step_resume
;
3442 /* It is for the wrong frame. */
3443 bs_class
= bp_nostop
;
3445 case bp_watchpoint_scope
:
3446 bs_class
= bp_nostop
;
3448 case bp_shlib_event
:
3449 bs_class
= shlib_event
;
3451 case bp_thread_event
:
3452 case bp_overlay_event
:
3453 case bp_longjmp_master
:
3454 bs_class
= bp_nostop
;
3460 bs_class
= bp_noisy
;
3462 bs_class
= bp_silent
;
3465 /* There was a catchpoint, but we're not stopping.
3466 This requires no further action. */
3467 bs_class
= no_effect
;
3470 /* Make sure the action is stop (silent or noisy),
3471 so infrun.c pops the dummy frame. */
3472 bs_class
= bp_silent
;
3473 retval
.call_dummy
= 1;
3476 /* Tracepoint hits should not be reported back to GDB, and
3477 if one got through somehow, it should have been filtered
3479 internal_error (__FILE__
, __LINE__
,
3480 _("bpstat_what: bp_tracepoint encountered"));
3483 current_action
= table
[(int) bs_class
][(int) current_action
];
3485 retval
.main_action
= current_action
;
3489 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3490 without hardware support). This isn't related to a specific bpstat,
3491 just to things like whether watchpoints are set. */
3494 bpstat_should_step (void)
3496 struct breakpoint
*b
;
3498 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
3505 static void print_breakpoint_location (struct breakpoint
*b
,
3506 struct bp_location
*loc
,
3508 struct ui_stream
*stb
)
3513 = find_pc_sect_function (loc
->address
, loc
->section
);
3516 ui_out_text (uiout
, "in ");
3517 ui_out_field_string (uiout
, "func",
3518 SYMBOL_PRINT_NAME (sym
));
3519 ui_out_wrap_hint (uiout
, wrap_indent
);
3520 ui_out_text (uiout
, " at ");
3522 ui_out_field_string (uiout
, "file", b
->source_file
);
3523 ui_out_text (uiout
, ":");
3525 if (ui_out_is_mi_like_p (uiout
))
3527 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3528 char *fullname
= symtab_to_fullname (sal
.symtab
);
3531 ui_out_field_string (uiout
, "fullname", fullname
);
3534 ui_out_field_int (uiout
, "line", b
->line_number
);
3538 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3542 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3543 ui_out_field_stream (uiout
, "at", stb
);
3547 /* Print B to gdb_stdout. */
3549 print_one_breakpoint_location (struct breakpoint
*b
,
3550 struct bp_location
*loc
,
3552 struct bp_location
**last_loc
,
3553 int print_address_bits
)
3555 struct command_line
*l
;
3557 struct ep_type_description
3562 static struct ep_type_description bptypes
[] =
3564 {bp_none
, "?deleted?"},
3565 {bp_breakpoint
, "breakpoint"},
3566 {bp_hardware_breakpoint
, "hw breakpoint"},
3567 {bp_until
, "until"},
3568 {bp_finish
, "finish"},
3569 {bp_watchpoint
, "watchpoint"},
3570 {bp_hardware_watchpoint
, "hw watchpoint"},
3571 {bp_read_watchpoint
, "read watchpoint"},
3572 {bp_access_watchpoint
, "acc watchpoint"},
3573 {bp_longjmp
, "longjmp"},
3574 {bp_longjmp_resume
, "longjmp resume"},
3575 {bp_step_resume
, "step resume"},
3576 {bp_watchpoint_scope
, "watchpoint scope"},
3577 {bp_call_dummy
, "call dummy"},
3578 {bp_shlib_event
, "shlib events"},
3579 {bp_thread_event
, "thread events"},
3580 {bp_overlay_event
, "overlay events"},
3581 {bp_longjmp_master
, "longjmp master"},
3582 {bp_catchpoint
, "catchpoint"},
3583 {bp_tracepoint
, "tracepoint"},
3586 static char bpenables
[] = "nynny";
3587 char wrap_indent
[80];
3588 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3589 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3590 struct cleanup
*bkpt_chain
;
3592 int header_of_multiple
= 0;
3593 int part_of_multiple
= (loc
!= NULL
);
3594 struct value_print_options opts
;
3596 get_user_print_options (&opts
);
3598 gdb_assert (!loc
|| loc_number
!= 0);
3599 /* See comment in print_one_breakpoint concerning
3600 treatment of breakpoints with single disabled
3604 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3605 header_of_multiple
= 1;
3610 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3614 if (part_of_multiple
)
3617 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3618 ui_out_field_string (uiout
, "number", formatted
);
3623 ui_out_field_int (uiout
, "number", b
->number
);
3628 if (part_of_multiple
)
3629 ui_out_field_skip (uiout
, "type");
3632 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3633 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3634 internal_error (__FILE__
, __LINE__
,
3635 _("bptypes table does not describe type #%d."),
3637 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3642 if (part_of_multiple
)
3643 ui_out_field_skip (uiout
, "disp");
3645 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3650 if (part_of_multiple
)
3651 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3653 ui_out_field_fmt (uiout
, "enabled", "%c",
3654 bpenables
[(int) b
->enable_state
]);
3655 ui_out_spaces (uiout
, 2);
3659 strcpy (wrap_indent
, " ");
3660 if (opts
.addressprint
)
3662 if (print_address_bits
<= 32)
3663 strcat (wrap_indent
, " ");
3665 strcat (wrap_indent
, " ");
3668 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3670 /* Although the print_one can possibly print
3671 all locations, calling it here is not likely
3672 to get any nice result. So, make sure there's
3673 just one location. */
3674 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3675 b
->ops
->print_one (b
, last_loc
);
3681 internal_error (__FILE__
, __LINE__
,
3682 _("print_one_breakpoint: bp_none encountered\n"));
3686 case bp_hardware_watchpoint
:
3687 case bp_read_watchpoint
:
3688 case bp_access_watchpoint
:
3689 /* Field 4, the address, is omitted (which makes the columns
3690 not line up too nicely with the headers, but the effect
3691 is relatively readable). */
3692 if (opts
.addressprint
)
3693 ui_out_field_skip (uiout
, "addr");
3695 ui_out_field_string (uiout
, "what", b
->exp_string
);
3699 case bp_hardware_breakpoint
:
3703 case bp_longjmp_resume
:
3704 case bp_step_resume
:
3705 case bp_watchpoint_scope
:
3707 case bp_shlib_event
:
3708 case bp_thread_event
:
3709 case bp_overlay_event
:
3710 case bp_longjmp_master
:
3712 if (opts
.addressprint
)
3715 if (header_of_multiple
)
3716 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3717 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3718 ui_out_field_string (uiout
, "addr", "<PENDING>");
3720 ui_out_field_core_addr (uiout
, "addr",
3721 loc
->gdbarch
, loc
->address
);
3724 if (!header_of_multiple
)
3725 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3731 if (!part_of_multiple
)
3733 if (b
->thread
!= -1)
3735 /* FIXME: This seems to be redundant and lost here; see the
3736 "stop only in" line a little further down. */
3737 ui_out_text (uiout
, " thread ");
3738 ui_out_field_int (uiout
, "thread", b
->thread
);
3740 else if (b
->task
!= 0)
3742 ui_out_text (uiout
, " task ");
3743 ui_out_field_int (uiout
, "task", b
->task
);
3747 ui_out_text (uiout
, "\n");
3749 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3752 ui_out_text (uiout
, "\tstop only in stack frame at ");
3753 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3755 ui_out_field_core_addr (uiout
, "frame",
3756 b
->gdbarch
, b
->frame_id
.stack_addr
);
3757 ui_out_text (uiout
, "\n");
3760 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3762 /* We do not print the condition for Ada exception catchpoints
3763 because the condition is an internal implementation detail
3764 that we do not want to expose to the user. */
3766 if (b
->type
== bp_tracepoint
)
3767 ui_out_text (uiout
, "\ttrace only if ");
3769 ui_out_text (uiout
, "\tstop only if ");
3770 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3771 ui_out_text (uiout
, "\n");
3774 if (!part_of_multiple
&& b
->thread
!= -1)
3776 /* FIXME should make an annotation for this */
3777 ui_out_text (uiout
, "\tstop only in thread ");
3778 ui_out_field_int (uiout
, "thread", b
->thread
);
3779 ui_out_text (uiout
, "\n");
3782 if (!part_of_multiple
&& b
->hit_count
)
3784 /* FIXME should make an annotation for this */
3785 if (ep_is_catchpoint (b
))
3786 ui_out_text (uiout
, "\tcatchpoint");
3788 ui_out_text (uiout
, "\tbreakpoint");
3789 ui_out_text (uiout
, " already hit ");
3790 ui_out_field_int (uiout
, "times", b
->hit_count
);
3791 if (b
->hit_count
== 1)
3792 ui_out_text (uiout
, " time\n");
3794 ui_out_text (uiout
, " times\n");
3797 /* Output the count also if it is zero, but only if this is
3798 mi. FIXME: Should have a better test for this. */
3799 if (ui_out_is_mi_like_p (uiout
))
3800 if (!part_of_multiple
&& b
->hit_count
== 0)
3801 ui_out_field_int (uiout
, "times", b
->hit_count
);
3803 if (!part_of_multiple
&& b
->ignore_count
)
3806 ui_out_text (uiout
, "\tignore next ");
3807 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3808 ui_out_text (uiout
, " hits\n");
3812 if (!part_of_multiple
&& l
)
3814 struct cleanup
*script_chain
;
3817 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3818 print_command_lines (uiout
, l
, 4);
3819 do_cleanups (script_chain
);
3822 if (!part_of_multiple
&& b
->pass_count
)
3824 annotate_field (10);
3825 ui_out_text (uiout
, "\tpass count ");
3826 ui_out_field_int (uiout
, "pass", b
->pass_count
);
3827 ui_out_text (uiout
, " \n");
3830 if (!part_of_multiple
&& b
->step_count
)
3832 annotate_field (11);
3833 ui_out_text (uiout
, "\tstep count ");
3834 ui_out_field_int (uiout
, "step", b
->step_count
);
3835 ui_out_text (uiout
, " \n");
3838 if (!part_of_multiple
&& b
->actions
)
3840 struct action_line
*action
;
3841 annotate_field (12);
3842 for (action
= b
->actions
; action
; action
= action
->next
)
3844 ui_out_text (uiout
, " A\t");
3845 ui_out_text (uiout
, action
->action
);
3846 ui_out_text (uiout
, "\n");
3850 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3853 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3854 else if (b
->exp_string
)
3855 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3858 do_cleanups (bkpt_chain
);
3859 do_cleanups (old_chain
);
3863 print_one_breakpoint (struct breakpoint
*b
,
3864 struct bp_location
**last_loc
, int print_address_bits
)
3866 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, print_address_bits
);
3868 /* If this breakpoint has custom print function,
3869 it's already printed. Otherwise, print individual
3870 locations, if any. */
3871 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3873 /* If breakpoint has a single location that is
3874 disabled, we print it as if it had
3875 several locations, since otherwise it's hard to
3876 represent "breakpoint enabled, location disabled"
3878 Note that while hardware watchpoints have
3879 several locations internally, that's no a property
3882 && !is_hardware_watchpoint (b
)
3883 && (b
->loc
->next
|| !b
->loc
->enabled
)
3884 && !ui_out_is_mi_like_p (uiout
))
3886 struct bp_location
*loc
;
3888 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3889 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
3890 print_address_bits
);
3896 breakpoint_address_bits (struct breakpoint
*b
)
3898 int print_address_bits
= 0;
3899 struct bp_location
*loc
;
3901 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3903 int addr_bit
= gdbarch_addr_bit (b
->gdbarch
);
3904 if (addr_bit
> print_address_bits
)
3905 print_address_bits
= addr_bit
;
3908 return print_address_bits
;
3911 struct captured_breakpoint_query_args
3917 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3919 struct captured_breakpoint_query_args
*args
= data
;
3920 struct breakpoint
*b
;
3921 struct bp_location
*dummy_loc
= NULL
;
3924 if (args
->bnum
== b
->number
)
3926 int print_address_bits
= breakpoint_address_bits (b
);
3927 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
);
3935 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3937 struct captured_breakpoint_query_args args
;
3939 /* For the moment we don't trust print_one_breakpoint() to not throw
3941 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3942 error_message
, RETURN_MASK_ALL
) < 0)
3948 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3949 catchpoints, et.al.). */
3952 user_settable_breakpoint (const struct breakpoint
*b
)
3954 return (b
->type
== bp_breakpoint
3955 || b
->type
== bp_catchpoint
3956 || b
->type
== bp_hardware_breakpoint
3957 || b
->type
== bp_tracepoint
3958 || b
->type
== bp_watchpoint
3959 || b
->type
== bp_read_watchpoint
3960 || b
->type
== bp_access_watchpoint
3961 || b
->type
== bp_hardware_watchpoint
);
3964 /* Print information on user settable breakpoint (watchpoint, etc)
3965 number BNUM. If BNUM is -1 print all user settable breakpoints.
3966 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3969 breakpoint_1 (int bnum
, int allflag
)
3971 struct breakpoint
*b
;
3972 struct bp_location
*last_loc
= NULL
;
3973 int nr_printable_breakpoints
;
3974 struct cleanup
*bkpttbl_chain
;
3975 struct value_print_options opts
;
3976 int print_address_bits
= 0;
3978 get_user_print_options (&opts
);
3980 /* Compute the number of rows in the table, as well as the
3981 size required for address fields. */
3982 nr_printable_breakpoints
= 0;
3985 || bnum
== b
->number
)
3987 if (allflag
|| user_settable_breakpoint (b
))
3989 int addr_bit
= breakpoint_address_bits (b
);
3990 if (addr_bit
> print_address_bits
)
3991 print_address_bits
= addr_bit
;
3993 nr_printable_breakpoints
++;
3997 if (opts
.addressprint
)
3999 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4003 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4006 if (nr_printable_breakpoints
> 0)
4007 annotate_breakpoints_headers ();
4008 if (nr_printable_breakpoints
> 0)
4010 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4011 if (nr_printable_breakpoints
> 0)
4013 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4014 if (nr_printable_breakpoints
> 0)
4016 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4017 if (nr_printable_breakpoints
> 0)
4019 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4020 if (opts
.addressprint
)
4022 if (nr_printable_breakpoints
> 0)
4024 if (print_address_bits
<= 32)
4025 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4027 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4029 if (nr_printable_breakpoints
> 0)
4031 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4032 ui_out_table_body (uiout
);
4033 if (nr_printable_breakpoints
> 0)
4034 annotate_breakpoints_table ();
4038 || bnum
== b
->number
)
4040 /* We only print out user settable breakpoints unless the
4042 if (allflag
|| user_settable_breakpoint (b
))
4043 print_one_breakpoint (b
, &last_loc
, print_address_bits
);
4046 do_cleanups (bkpttbl_chain
);
4048 if (nr_printable_breakpoints
== 0)
4051 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
4053 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
4058 if (last_loc
&& !server_command
)
4059 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
4062 /* FIXME? Should this be moved up so that it is only called when
4063 there have been breakpoints? */
4064 annotate_breakpoints_table_end ();
4068 breakpoints_info (char *bnum_exp
, int from_tty
)
4073 bnum
= parse_and_eval_long (bnum_exp
);
4075 breakpoint_1 (bnum
, 0);
4079 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4084 bnum
= parse_and_eval_long (bnum_exp
);
4086 breakpoint_1 (bnum
, 1);
4090 breakpoint_has_pc (struct breakpoint
*b
,
4091 CORE_ADDR pc
, struct obj_section
*section
)
4093 struct bp_location
*bl
= b
->loc
;
4094 for (; bl
; bl
= bl
->next
)
4096 if (bl
->address
== pc
4097 && (!overlay_debugging
|| bl
->section
== section
))
4103 /* Print a message describing any breakpoints set at PC. */
4106 describe_other_breakpoints (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
4107 struct obj_section
*section
, int thread
)
4110 struct breakpoint
*b
;
4113 others
+= breakpoint_has_pc (b
, pc
, section
);
4117 printf_filtered (_("Note: breakpoint "));
4118 else /* if (others == ???) */
4119 printf_filtered (_("Note: breakpoints "));
4121 if (breakpoint_has_pc (b
, pc
, section
))
4124 printf_filtered ("%d", b
->number
);
4125 if (b
->thread
== -1 && thread
!= -1)
4126 printf_filtered (" (all threads)");
4127 else if (b
->thread
!= -1)
4128 printf_filtered (" (thread %d)", b
->thread
);
4129 printf_filtered ("%s%s ",
4130 ((b
->enable_state
== bp_disabled
4131 || b
->enable_state
== bp_call_disabled
4132 || b
->enable_state
== bp_startup_disabled
)
4134 : b
->enable_state
== bp_permanent
4138 : ((others
== 1) ? " and" : ""));
4140 printf_filtered (_("also set at pc "));
4141 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
4142 printf_filtered (".\n");
4146 /* Set the default place to put a breakpoint
4147 for the `break' command with no arguments. */
4150 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4153 default_breakpoint_valid
= valid
;
4154 default_breakpoint_address
= addr
;
4155 default_breakpoint_symtab
= symtab
;
4156 default_breakpoint_line
= line
;
4159 /* Return true iff it is meaningful to use the address member of
4160 BPT. For some breakpoint types, the address member is irrelevant
4161 and it makes no sense to attempt to compare it to other addresses
4162 (or use it for any other purpose either).
4164 More specifically, each of the following breakpoint types will always
4165 have a zero valued address and we don't want check_duplicates() to mark
4166 breakpoints of any of these types to be a duplicate of an actual
4167 breakpoint at address zero:
4170 bp_hardware_watchpoint
4172 bp_access_watchpoint
4176 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4178 enum bptype type
= bpt
->type
;
4180 return (type
!= bp_watchpoint
4181 && type
!= bp_hardware_watchpoint
4182 && type
!= bp_read_watchpoint
4183 && type
!= bp_access_watchpoint
4184 && type
!= bp_catchpoint
);
4187 /* Rescan breakpoints at the same address and section as BPT,
4188 marking the first one as "first" and any others as "duplicates".
4189 This is so that the bpt instruction is only inserted once.
4190 If we have a permanent breakpoint at the same place as BPT, make
4191 that one the official one, and the rest as duplicates. */
4194 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
4196 struct bp_location
*b
;
4198 struct bp_location
*perm_bp
= 0;
4200 ALL_BP_LOCATIONS (b
)
4201 if (b
->owner
->enable_state
!= bp_disabled
4202 && b
->owner
->enable_state
!= bp_call_disabled
4203 && b
->owner
->enable_state
!= bp_startup_disabled
4205 && !b
->shlib_disabled
4206 && b
->address
== address
/* address / overlay match */
4207 && (!overlay_debugging
|| b
->section
== section
)
4208 && breakpoint_address_is_meaningful (b
->owner
))
4210 /* Have we found a permanent breakpoint? */
4211 if (b
->owner
->enable_state
== bp_permanent
)
4218 b
->duplicate
= count
> 1;
4221 /* If we found a permanent breakpoint at this address, go over the
4222 list again and declare all the other breakpoints there (except
4223 other permanent breakpoints) to be the duplicates. */
4226 perm_bp
->duplicate
= 0;
4228 /* Permanent breakpoint should always be inserted. */
4229 if (! perm_bp
->inserted
)
4230 internal_error (__FILE__
, __LINE__
,
4231 _("allegedly permanent breakpoint is not "
4232 "actually inserted"));
4234 ALL_BP_LOCATIONS (b
)
4237 if (b
->owner
->enable_state
!= bp_permanent
4238 && b
->owner
->enable_state
!= bp_disabled
4239 && b
->owner
->enable_state
!= bp_call_disabled
4240 && b
->owner
->enable_state
!= bp_startup_disabled
4241 && b
->enabled
&& !b
->shlib_disabled
4242 && b
->address
== address
/* address / overlay match */
4243 && (!overlay_debugging
|| b
->section
== section
)
4244 && breakpoint_address_is_meaningful (b
->owner
))
4247 internal_error (__FILE__
, __LINE__
,
4248 _("another breakpoint was inserted on top of "
4249 "a permanent breakpoint"));
4258 check_duplicates (struct breakpoint
*bpt
)
4260 struct bp_location
*bl
= bpt
->loc
;
4262 if (! breakpoint_address_is_meaningful (bpt
))
4265 for (; bl
; bl
= bl
->next
)
4266 check_duplicates_for (bl
->address
, bl
->section
);
4270 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4271 int bnum
, int have_bnum
)
4276 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4277 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4279 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4280 bnum
, astr1
, astr2
);
4282 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4285 /* Adjust a breakpoint's address to account for architectural constraints
4286 on breakpoint placement. Return the adjusted address. Note: Very
4287 few targets require this kind of adjustment. For most targets,
4288 this function is simply the identity function. */
4291 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
4292 CORE_ADDR bpaddr
, enum bptype bptype
)
4294 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
4296 /* Very few targets need any kind of breakpoint adjustment. */
4299 else if (bptype
== bp_watchpoint
4300 || bptype
== bp_hardware_watchpoint
4301 || bptype
== bp_read_watchpoint
4302 || bptype
== bp_access_watchpoint
4303 || bptype
== bp_catchpoint
)
4305 /* Watchpoints and the various bp_catch_* eventpoints should not
4306 have their addresses modified. */
4311 CORE_ADDR adjusted_bpaddr
;
4313 /* Some targets have architectural constraints on the placement
4314 of breakpoint instructions. Obtain the adjusted address. */
4315 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
4317 /* An adjusted breakpoint address can significantly alter
4318 a user's expectations. Print a warning if an adjustment
4320 if (adjusted_bpaddr
!= bpaddr
)
4321 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4323 return adjusted_bpaddr
;
4327 /* Allocate a struct bp_location. */
4329 static struct bp_location
*
4330 allocate_bp_location (struct breakpoint
*bpt
)
4332 struct bp_location
*loc
, *loc_p
;
4334 loc
= xmalloc (sizeof (struct bp_location
));
4335 memset (loc
, 0, sizeof (*loc
));
4339 loc
->shlib_disabled
= 0;
4349 case bp_longjmp_resume
:
4350 case bp_step_resume
:
4351 case bp_watchpoint_scope
:
4353 case bp_shlib_event
:
4354 case bp_thread_event
:
4355 case bp_overlay_event
:
4356 case bp_longjmp_master
:
4357 loc
->loc_type
= bp_loc_software_breakpoint
;
4359 case bp_hardware_breakpoint
:
4360 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4362 case bp_hardware_watchpoint
:
4363 case bp_read_watchpoint
:
4364 case bp_access_watchpoint
:
4365 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4369 loc
->loc_type
= bp_loc_other
;
4372 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4378 static void free_bp_location (struct bp_location
*loc
)
4383 if (loc
->function_name
)
4384 xfree (loc
->function_name
);
4389 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4390 that has type BPTYPE and has no locations as yet. */
4391 /* This function is used in gdbtk sources and thus can not be made static. */
4393 static struct breakpoint
*
4394 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
4397 struct breakpoint
*b
, *b1
;
4399 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4400 memset (b
, 0, sizeof (*b
));
4403 b
->gdbarch
= gdbarch
;
4404 b
->language
= current_language
->la_language
;
4405 b
->input_radix
= input_radix
;
4407 b
->enable_state
= bp_enabled
;
4410 b
->ignore_count
= 0;
4412 b
->frame_id
= null_frame_id
;
4413 b
->forked_inferior_pid
= null_ptid
;
4414 b
->exec_pathname
= NULL
;
4416 b
->condition_not_parsed
= 0;
4418 /* Add this breakpoint to the end of the chain
4419 so that a list of breakpoints will come out in order
4420 of increasing numbers. */
4422 b1
= breakpoint_chain
;
4424 breakpoint_chain
= b
;
4434 /* Initialize loc->function_name. */
4436 set_breakpoint_location_function (struct bp_location
*loc
)
4438 if (loc
->owner
->type
== bp_breakpoint
4439 || loc
->owner
->type
== bp_hardware_breakpoint
4440 || loc
->owner
->type
== bp_tracepoint
)
4442 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4444 if (loc
->function_name
)
4445 loc
->function_name
= xstrdup (loc
->function_name
);
4449 /* Attempt to determine architecture of location identified by SAL. */
4450 static struct gdbarch
*
4451 get_sal_arch (struct symtab_and_line sal
)
4454 return get_objfile_arch (sal
.section
->objfile
);
4456 return get_objfile_arch (sal
.symtab
->objfile
);
4461 /* set_raw_breakpoint is a low level routine for allocating and
4462 partially initializing a breakpoint of type BPTYPE. The newly
4463 created breakpoint's address, section, source file name, and line
4464 number are provided by SAL. The newly created and partially
4465 initialized breakpoint is added to the breakpoint chain and
4466 is also returned as the value of this function.
4468 It is expected that the caller will complete the initialization of
4469 the newly created breakpoint struct as well as output any status
4470 information regarding the creation of a new breakpoint. In
4471 particular, set_raw_breakpoint does NOT set the breakpoint
4472 number! Care should be taken to not allow an error to occur
4473 prior to completing the initialization of the breakpoint. If this
4474 should happen, a bogus breakpoint will be left on the chain. */
4477 set_raw_breakpoint (struct gdbarch
*gdbarch
,
4478 struct symtab_and_line sal
, enum bptype bptype
)
4480 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
4481 CORE_ADDR adjusted_address
;
4482 struct gdbarch
*loc_gdbarch
;
4484 loc_gdbarch
= get_sal_arch (sal
);
4486 loc_gdbarch
= b
->gdbarch
;
4488 /* Adjust the breakpoint's address prior to allocating a location.
4489 Once we call allocate_bp_location(), that mostly uninitialized
4490 location will be placed on the location chain. Adjustment of the
4491 breakpoint may cause target_read_memory() to be called and we do
4492 not want its scan of the location chain to find a breakpoint and
4493 location that's only been partially initialized. */
4494 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
4496 b
->loc
= allocate_bp_location (b
);
4497 b
->loc
->gdbarch
= loc_gdbarch
;
4498 b
->loc
->requested_address
= sal
.pc
;
4499 b
->loc
->address
= adjusted_address
;
4501 if (sal
.symtab
== NULL
)
4502 b
->source_file
= NULL
;
4504 b
->source_file
= xstrdup (sal
.symtab
->filename
);
4505 b
->loc
->section
= sal
.section
;
4506 b
->line_number
= sal
.line
;
4508 set_breakpoint_location_function (b
->loc
);
4510 breakpoints_changed ();
4516 /* Note that the breakpoint object B describes a permanent breakpoint
4517 instruction, hard-wired into the inferior's code. */
4519 make_breakpoint_permanent (struct breakpoint
*b
)
4521 struct bp_location
*bl
;
4522 b
->enable_state
= bp_permanent
;
4524 /* By definition, permanent breakpoints are already present in the code.
4525 Mark all locations as inserted. For now, make_breakpoint_permanent
4526 is called in just one place, so it's hard to say if it's reasonable
4527 to have permanent breakpoint with multiple locations or not,
4528 but it's easy to implmement. */
4529 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4533 /* Call this routine when stepping and nexting to enable a breakpoint
4534 if we do a longjmp() in THREAD. When we hit that breakpoint, call
4535 set_longjmp_resume_breakpoint() to figure out where we are going. */
4538 set_longjmp_breakpoint (int thread
)
4540 struct breakpoint
*b
, *temp
;
4542 /* To avoid having to rescan all objfile symbols at every step,
4543 we maintain a list of continually-inserted but always disabled
4544 longjmp "master" breakpoints. Here, we simply create momentary
4545 clones of those and enable them for the requested thread. */
4546 ALL_BREAKPOINTS_SAFE (b
, temp
)
4547 if (b
->type
== bp_longjmp_master
)
4549 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
4550 clone
->type
= bp_longjmp
;
4551 clone
->thread
= thread
;
4555 /* Delete all longjmp breakpoints from THREAD. */
4557 delete_longjmp_breakpoint (int thread
)
4559 struct breakpoint
*b
, *temp
;
4561 ALL_BREAKPOINTS_SAFE (b
, temp
)
4562 if (b
->type
== bp_longjmp
)
4564 if (b
->thread
== thread
)
4565 delete_breakpoint (b
);
4570 enable_overlay_breakpoints (void)
4572 struct breakpoint
*b
;
4575 if (b
->type
== bp_overlay_event
)
4577 b
->enable_state
= bp_enabled
;
4578 update_global_location_list (1);
4579 overlay_events_enabled
= 1;
4584 disable_overlay_breakpoints (void)
4586 struct breakpoint
*b
;
4589 if (b
->type
== bp_overlay_event
)
4591 b
->enable_state
= bp_disabled
;
4592 update_global_location_list (0);
4593 overlay_events_enabled
= 0;
4598 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
4600 struct breakpoint
*b
;
4602 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
4604 b
->enable_state
= bp_enabled
;
4605 /* addr_string has to be used or breakpoint_re_set will delete me. */
4607 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
4609 update_global_location_list_nothrow (1);
4615 remove_thread_event_breakpoints (void)
4617 struct breakpoint
*b
, *temp
;
4619 ALL_BREAKPOINTS_SAFE (b
, temp
)
4620 if (b
->type
== bp_thread_event
)
4621 delete_breakpoint (b
);
4624 struct captured_parse_breakpoint_args
4627 struct symtabs_and_lines
*sals_p
;
4628 char ***addr_string_p
;
4632 struct lang_and_radix
4640 remove_solib_event_breakpoints (void)
4642 struct breakpoint
*b
, *temp
;
4644 ALL_BREAKPOINTS_SAFE (b
, temp
)
4645 if (b
->type
== bp_shlib_event
)
4646 delete_breakpoint (b
);
4650 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
4652 struct breakpoint
*b
;
4654 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
4655 update_global_location_list_nothrow (1);
4659 /* Disable any breakpoints that are on code in shared libraries. Only
4660 apply to enabled breakpoints, disabled ones can just stay disabled. */
4663 disable_breakpoints_in_shlibs (void)
4665 struct bp_location
*loc
;
4667 ALL_BP_LOCATIONS (loc
)
4669 struct breakpoint
*b
= loc
->owner
;
4670 /* We apply the check to all breakpoints, including disabled
4671 for those with loc->duplicate set. This is so that when breakpoint
4672 becomes enabled, or the duplicate is removed, gdb will try to insert
4673 all breakpoints. If we don't set shlib_disabled here, we'll try
4674 to insert those breakpoints and fail. */
4675 if (((b
->type
== bp_breakpoint
)
4676 || (b
->type
== bp_hardware_breakpoint
)
4677 || (b
->type
== bp_tracepoint
))
4678 && !loc
->shlib_disabled
4680 && PC_SOLIB (loc
->address
)
4682 && solib_name_from_address (loc
->address
)
4686 loc
->shlib_disabled
= 1;
4691 /* Disable any breakpoints that are in in an unloaded shared library. Only
4692 apply to enabled breakpoints, disabled ones can just stay disabled. */
4695 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4697 struct bp_location
*loc
;
4698 int disabled_shlib_breaks
= 0;
4700 /* SunOS a.out shared libraries are always mapped, so do not
4701 disable breakpoints; they will only be reported as unloaded
4702 through clear_solib when GDB discards its shared library
4703 list. See clear_solib for more information. */
4704 if (exec_bfd
!= NULL
4705 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
4708 ALL_BP_LOCATIONS (loc
)
4710 struct breakpoint
*b
= loc
->owner
;
4711 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4712 || loc
->loc_type
== bp_loc_software_breakpoint
)
4713 && !loc
->shlib_disabled
4714 && (b
->type
== bp_breakpoint
|| b
->type
== bp_hardware_breakpoint
)
4715 && solib_contains_address_p (solib
, loc
->address
))
4717 loc
->shlib_disabled
= 1;
4718 /* At this point, we cannot rely on remove_breakpoint
4719 succeeding so we must mark the breakpoint as not inserted
4720 to prevent future errors occurring in remove_breakpoints. */
4722 if (!disabled_shlib_breaks
)
4724 target_terminal_ours_for_output ();
4725 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4728 disabled_shlib_breaks
= 1;
4733 /* FORK & VFORK catchpoints. */
4735 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4738 insert_catch_fork (struct breakpoint
*b
)
4740 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4743 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4746 remove_catch_fork (struct breakpoint
*b
)
4748 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4751 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4755 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4757 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4760 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4762 static enum print_stop_action
4763 print_it_catch_fork (struct breakpoint
*b
)
4765 annotate_catchpoint (b
->number
);
4766 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4767 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4768 return PRINT_SRC_AND_LOC
;
4771 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4774 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
4776 struct value_print_options opts
;
4778 get_user_print_options (&opts
);
4780 /* Field 4, the address, is omitted (which makes the columns
4781 not line up too nicely with the headers, but the effect
4782 is relatively readable). */
4783 if (opts
.addressprint
)
4784 ui_out_field_skip (uiout
, "addr");
4786 ui_out_text (uiout
, "fork");
4787 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4789 ui_out_text (uiout
, ", process ");
4790 ui_out_field_int (uiout
, "what",
4791 ptid_get_pid (b
->forked_inferior_pid
));
4792 ui_out_spaces (uiout
, 1);
4796 /* Implement the "print_mention" breakpoint_ops method for fork
4800 print_mention_catch_fork (struct breakpoint
*b
)
4802 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4805 /* The breakpoint_ops structure to be used in fork catchpoints. */
4807 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4811 breakpoint_hit_catch_fork
,
4812 print_it_catch_fork
,
4813 print_one_catch_fork
,
4814 print_mention_catch_fork
4817 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4820 insert_catch_vfork (struct breakpoint
*b
)
4822 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4825 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4828 remove_catch_vfork (struct breakpoint
*b
)
4830 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4833 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4837 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4839 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4842 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4844 static enum print_stop_action
4845 print_it_catch_vfork (struct breakpoint
*b
)
4847 annotate_catchpoint (b
->number
);
4848 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4849 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4850 return PRINT_SRC_AND_LOC
;
4853 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4856 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
4858 struct value_print_options opts
;
4860 get_user_print_options (&opts
);
4861 /* Field 4, the address, is omitted (which makes the columns
4862 not line up too nicely with the headers, but the effect
4863 is relatively readable). */
4864 if (opts
.addressprint
)
4865 ui_out_field_skip (uiout
, "addr");
4867 ui_out_text (uiout
, "vfork");
4868 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4870 ui_out_text (uiout
, ", process ");
4871 ui_out_field_int (uiout
, "what",
4872 ptid_get_pid (b
->forked_inferior_pid
));
4873 ui_out_spaces (uiout
, 1);
4877 /* Implement the "print_mention" breakpoint_ops method for vfork
4881 print_mention_catch_vfork (struct breakpoint
*b
)
4883 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4886 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4888 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4892 breakpoint_hit_catch_vfork
,
4893 print_it_catch_vfork
,
4894 print_one_catch_vfork
,
4895 print_mention_catch_vfork
4898 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4900 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4901 If COND_STRING is not NULL, then store it in the breakpoint.
4902 OPS, if not NULL, is the breakpoint_ops structure associated
4903 to the catchpoint. */
4905 static struct breakpoint
*
4906 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
4907 char *cond_string
, struct breakpoint_ops
*ops
)
4909 struct symtab_and_line sal
;
4910 struct breakpoint
*b
;
4917 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
4918 set_breakpoint_count (breakpoint_count
+ 1);
4919 b
->number
= breakpoint_count
;
4921 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
4923 b
->addr_string
= NULL
;
4924 b
->enable_state
= bp_enabled
;
4925 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4929 update_global_location_list (1);
4935 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
4936 int tempflag
, char *cond_string
,
4937 struct breakpoint_ops
*ops
)
4939 struct breakpoint
*b
4940 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
4942 /* FIXME: We should put this information in a breakpoint private data
4944 b
->forked_inferior_pid
= null_ptid
;
4947 /* Exec catchpoints. */
4950 insert_catch_exec (struct breakpoint
*b
)
4952 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
4956 remove_catch_exec (struct breakpoint
*b
)
4958 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
4962 breakpoint_hit_catch_exec (struct breakpoint
*b
)
4964 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
4967 static enum print_stop_action
4968 print_it_catch_exec (struct breakpoint
*b
)
4970 annotate_catchpoint (b
->number
);
4971 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
4973 return PRINT_SRC_AND_LOC
;
4977 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
4979 struct value_print_options opts
;
4981 get_user_print_options (&opts
);
4983 /* Field 4, the address, is omitted (which makes the columns
4984 not line up too nicely with the headers, but the effect
4985 is relatively readable). */
4986 if (opts
.addressprint
)
4987 ui_out_field_skip (uiout
, "addr");
4989 ui_out_text (uiout
, "exec");
4990 if (b
->exec_pathname
!= NULL
)
4992 ui_out_text (uiout
, ", program \"");
4993 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
4994 ui_out_text (uiout
, "\" ");
4999 print_mention_catch_exec (struct breakpoint
*b
)
5001 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
5004 static struct breakpoint_ops catch_exec_breakpoint_ops
=
5008 breakpoint_hit_catch_exec
,
5009 print_it_catch_exec
,
5010 print_one_catch_exec
,
5011 print_mention_catch_exec
5015 hw_breakpoint_used_count (void)
5017 struct breakpoint
*b
;
5022 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
5030 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
5032 struct breakpoint
*b
;
5035 *other_type_used
= 0;
5038 if (breakpoint_enabled (b
))
5040 if (b
->type
== type
)
5042 else if ((b
->type
== bp_hardware_watchpoint
5043 || b
->type
== bp_read_watchpoint
5044 || b
->type
== bp_access_watchpoint
))
5045 *other_type_used
= 1;
5052 disable_watchpoints_before_interactive_call_start (void)
5054 struct breakpoint
*b
;
5058 if (((b
->type
== bp_watchpoint
)
5059 || (b
->type
== bp_hardware_watchpoint
)
5060 || (b
->type
== bp_read_watchpoint
)
5061 || (b
->type
== bp_access_watchpoint
))
5062 && breakpoint_enabled (b
))
5064 b
->enable_state
= bp_call_disabled
;
5065 update_global_location_list (0);
5071 enable_watchpoints_after_interactive_call_stop (void)
5073 struct breakpoint
*b
;
5077 if (((b
->type
== bp_watchpoint
)
5078 || (b
->type
== bp_hardware_watchpoint
)
5079 || (b
->type
== bp_read_watchpoint
)
5080 || (b
->type
== bp_access_watchpoint
))
5081 && (b
->enable_state
== bp_call_disabled
))
5083 b
->enable_state
= bp_enabled
;
5084 update_global_location_list (1);
5090 disable_breakpoints_before_startup (void)
5092 struct breakpoint
*b
;
5097 if ((b
->type
== bp_breakpoint
5098 || b
->type
== bp_hardware_breakpoint
)
5099 && breakpoint_enabled (b
))
5101 b
->enable_state
= bp_startup_disabled
;
5107 update_global_location_list (0);
5109 executing_startup
= 1;
5113 enable_breakpoints_after_startup (void)
5115 struct breakpoint
*b
;
5118 executing_startup
= 0;
5122 if ((b
->type
== bp_breakpoint
5123 || b
->type
== bp_hardware_breakpoint
)
5124 && b
->enable_state
== bp_startup_disabled
)
5126 b
->enable_state
= bp_enabled
;
5132 breakpoint_re_set ();
5136 /* Set a breakpoint that will evaporate an end of command
5137 at address specified by SAL.
5138 Restrict it to frame FRAME if FRAME is nonzero. */
5141 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
5142 struct frame_id frame_id
, enum bptype type
)
5144 struct breakpoint
*b
;
5146 /* If FRAME_ID is valid, it should be a real frame, not an inlined
5148 gdb_assert (!frame_id_inlined_p (frame_id
));
5150 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
5151 b
->enable_state
= bp_enabled
;
5152 b
->disposition
= disp_donttouch
;
5153 b
->frame_id
= frame_id
;
5155 /* If we're debugging a multi-threaded program, then we
5156 want momentary breakpoints to be active in only a
5157 single thread of control. */
5158 if (in_thread_list (inferior_ptid
))
5159 b
->thread
= pid_to_thread_id (inferior_ptid
);
5161 update_global_location_list_nothrow (1);
5166 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
5170 clone_momentary_breakpoint (struct breakpoint
*orig
)
5172 struct breakpoint
*copy
;
5174 /* If there's nothing to clone, then return nothing. */
5178 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
5179 copy
->loc
= allocate_bp_location (copy
);
5180 set_breakpoint_location_function (copy
->loc
);
5182 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
5183 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
5184 copy
->loc
->address
= orig
->loc
->address
;
5185 copy
->loc
->section
= orig
->loc
->section
;
5187 if (orig
->source_file
== NULL
)
5188 copy
->source_file
= NULL
;
5190 copy
->source_file
= xstrdup (orig
->source_file
);
5192 copy
->line_number
= orig
->line_number
;
5193 copy
->frame_id
= orig
->frame_id
;
5194 copy
->thread
= orig
->thread
;
5196 copy
->enable_state
= bp_enabled
;
5197 copy
->disposition
= disp_donttouch
;
5198 copy
->number
= internal_breakpoint_number
--;
5200 update_global_location_list_nothrow (0);
5205 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
5208 struct symtab_and_line sal
;
5210 sal
= find_pc_line (pc
, 0);
5212 sal
.section
= find_pc_overlay (pc
);
5213 sal
.explicit_pc
= 1;
5215 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
5219 /* Tell the user we have just set a breakpoint B. */
5222 mention (struct breakpoint
*b
)
5225 struct cleanup
*ui_out_chain
;
5226 struct value_print_options opts
;
5228 get_user_print_options (&opts
);
5230 /* FIXME: This is misplaced; mention() is called by things (like
5231 hitting a watchpoint) other than breakpoint creation. It should
5232 be possible to clean this up and at the same time replace the
5233 random calls to breakpoint_changed with this hook. */
5234 observer_notify_breakpoint_created (b
->number
);
5236 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
5237 b
->ops
->print_mention (b
);
5242 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
5245 ui_out_text (uiout
, "Watchpoint ");
5246 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5247 ui_out_field_int (uiout
, "number", b
->number
);
5248 ui_out_text (uiout
, ": ");
5249 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5250 do_cleanups (ui_out_chain
);
5252 case bp_hardware_watchpoint
:
5253 ui_out_text (uiout
, "Hardware watchpoint ");
5254 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5255 ui_out_field_int (uiout
, "number", b
->number
);
5256 ui_out_text (uiout
, ": ");
5257 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5258 do_cleanups (ui_out_chain
);
5260 case bp_read_watchpoint
:
5261 ui_out_text (uiout
, "Hardware read watchpoint ");
5262 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
5263 ui_out_field_int (uiout
, "number", b
->number
);
5264 ui_out_text (uiout
, ": ");
5265 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5266 do_cleanups (ui_out_chain
);
5268 case bp_access_watchpoint
:
5269 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
5270 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
5271 ui_out_field_int (uiout
, "number", b
->number
);
5272 ui_out_text (uiout
, ": ");
5273 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5274 do_cleanups (ui_out_chain
);
5277 if (ui_out_is_mi_like_p (uiout
))
5282 if (b
->disposition
== disp_del
)
5283 printf_filtered (_("Temporary breakpoint"));
5285 printf_filtered (_("Breakpoint"));
5286 printf_filtered (_(" %d"), b
->number
);
5289 case bp_hardware_breakpoint
:
5290 if (ui_out_is_mi_like_p (uiout
))
5295 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
5299 if (ui_out_is_mi_like_p (uiout
))
5304 printf_filtered (_("Tracepoint"));
5305 printf_filtered (_(" %d"), b
->number
);
5312 case bp_longjmp_resume
:
5313 case bp_step_resume
:
5315 case bp_watchpoint_scope
:
5316 case bp_shlib_event
:
5317 case bp_thread_event
:
5318 case bp_overlay_event
:
5319 case bp_longjmp_master
:
5325 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5329 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5333 if (opts
.addressprint
|| b
->source_file
== NULL
)
5335 printf_filtered (" at ");
5336 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
5340 printf_filtered (": file %s, line %d.",
5341 b
->source_file
, b
->line_number
);
5345 struct bp_location
*loc
= b
->loc
;
5347 for (; loc
; loc
= loc
->next
)
5349 printf_filtered (" (%d locations)", n
);
5354 if (ui_out_is_mi_like_p (uiout
))
5356 printf_filtered ("\n");
5360 static struct bp_location
*
5361 add_location_to_breakpoint (struct breakpoint
*b
,
5362 const struct symtab_and_line
*sal
)
5364 struct bp_location
*loc
, **tmp
;
5366 loc
= allocate_bp_location (b
);
5367 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5370 loc
->gdbarch
= get_sal_arch (*sal
);
5372 loc
->gdbarch
= b
->gdbarch
;
5373 loc
->requested_address
= sal
->pc
;
5374 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
5375 loc
->requested_address
, b
->type
);
5376 loc
->section
= sal
->section
;
5378 set_breakpoint_location_function (loc
);
5383 /* Return 1 if LOC is pointing to a permanent breakpoint,
5384 return 0 otherwise. */
5387 bp_loc_is_permanent (struct bp_location
*loc
)
5391 const gdb_byte
*brk
;
5392 gdb_byte
*target_mem
;
5393 struct cleanup
*cleanup
;
5396 gdb_assert (loc
!= NULL
);
5398 addr
= loc
->address
;
5399 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
5401 /* Software breakpoints unsupported? */
5405 target_mem
= alloca (len
);
5407 /* Enable the automatic memory restoration from breakpoints while
5408 we read the memory. Otherwise we could say about our temporary
5409 breakpoints they are permanent. */
5410 cleanup
= make_show_memory_breakpoints_cleanup (0);
5412 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5413 && memcmp (target_mem
, brk
, len
) == 0)
5416 do_cleanups (cleanup
);
5423 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5424 as textual description of the location, and COND_STRING
5425 as condition expression. */
5428 create_breakpoint (struct gdbarch
*gdbarch
,
5429 struct symtabs_and_lines sals
, char *addr_string
,
5431 enum bptype type
, enum bpdisp disposition
,
5432 int thread
, int task
, int ignore_count
,
5433 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
5435 struct breakpoint
*b
= NULL
;
5438 if (type
== bp_hardware_breakpoint
)
5440 int i
= hw_breakpoint_used_count ();
5441 int target_resources_ok
=
5442 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
5444 if (target_resources_ok
== 0)
5445 error (_("No hardware breakpoint support in the target."));
5446 else if (target_resources_ok
< 0)
5447 error (_("Hardware breakpoints used exceeds limit."));
5450 for (i
= 0; i
< sals
.nelts
; ++i
)
5452 struct symtab_and_line sal
= sals
.sals
[i
];
5453 struct bp_location
*loc
;
5457 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
5459 loc_gdbarch
= gdbarch
;
5461 describe_other_breakpoints (loc_gdbarch
,
5462 sal
.pc
, sal
.section
, thread
);
5467 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
5468 set_breakpoint_count (breakpoint_count
+ 1);
5469 b
->number
= breakpoint_count
;
5473 b
->cond_string
= cond_string
;
5474 b
->ignore_count
= ignore_count
;
5475 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
5476 b
->disposition
= disposition
;
5478 if (enabled
&& executing_startup
5479 && (b
->type
== bp_breakpoint
5480 || b
->type
== bp_hardware_breakpoint
))
5481 b
->enable_state
= bp_startup_disabled
;
5487 loc
= add_location_to_breakpoint (b
, &sal
);
5490 if (bp_loc_is_permanent (loc
))
5491 make_breakpoint_permanent (b
);
5495 char *arg
= b
->cond_string
;
5496 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5498 error (_("Garbage %s follows condition"), arg
);
5503 b
->addr_string
= addr_string
;
5505 /* addr_string has to be used or breakpoint_re_set will delete
5508 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5514 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5515 elements to fill the void space. */
5517 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5519 int i
= index_to_remove
+1;
5520 int last_index
= sal
->nelts
-1;
5522 for (;i
<= last_index
; ++i
)
5523 sal
->sals
[i
-1] = sal
->sals
[i
];
5528 /* If appropriate, obtains all sals that correspond
5529 to the same file and line as SAL. This is done
5530 only if SAL does not have explicit PC and has
5531 line and file information. If we got just a single
5532 expanded sal, return the original.
5534 Otherwise, if SAL.explicit_line is not set, filter out
5535 all sals for which the name of enclosing function
5536 is different from SAL. This makes sure that if we have
5537 breakpoint originally set in template instantiation, say
5538 foo<int>(), we won't expand SAL to locations at the same
5539 line in all existing instantiations of 'foo'.
5542 static struct symtabs_and_lines
5543 expand_line_sal_maybe (struct symtab_and_line sal
)
5545 struct symtabs_and_lines expanded
;
5546 CORE_ADDR original_pc
= sal
.pc
;
5547 char *original_function
= NULL
;
5551 /* If we have explicit pc, don't expand.
5552 If we have no line number, we can't expand. */
5553 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5556 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5557 expanded
.sals
[0] = sal
;
5562 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5564 expanded
= expand_line_sal (sal
);
5565 if (expanded
.nelts
== 1)
5567 /* We had one sal, we got one sal. Without futher
5568 processing, just return the original sal. */
5569 xfree (expanded
.sals
);
5571 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5572 sal
.pc
= original_pc
;
5573 expanded
.sals
[0] = sal
;
5577 if (!sal
.explicit_line
)
5579 CORE_ADDR func_addr
, func_end
;
5580 for (i
= 0; i
< expanded
.nelts
; ++i
)
5582 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5583 char *this_function
;
5584 if (find_pc_partial_function (pc
, &this_function
,
5585 &func_addr
, &func_end
))
5588 && strcmp (this_function
, original_function
) != 0)
5590 remove_sal (&expanded
, i
);
5593 else if (func_addr
== pc
)
5595 /* We're at beginning of a function, and should
5597 struct symbol
*sym
= find_pc_function (pc
);
5599 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5602 /* Since find_pc_partial_function returned true,
5603 we should really always find the section here. */
5604 struct obj_section
*section
= find_pc_section (pc
);
5607 struct gdbarch
*gdbarch
5608 = get_objfile_arch (section
->objfile
);
5610 = gdbarch_skip_prologue (gdbarch
, pc
);
5619 for (i
= 0; i
< expanded
.nelts
; ++i
)
5621 /* If this SAL corresponds to a breakpoint inserted using a
5622 line number, then skip the function prologue if necessary. */
5623 skip_prologue_sal (&expanded
.sals
[i
]);
5628 if (expanded
.nelts
<= 1)
5630 /* This is un ugly workaround. If we get zero
5631 expanded sals then something is really wrong.
5632 Fix that by returnign the original sal. */
5633 xfree (expanded
.sals
);
5635 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5636 sal
.pc
= original_pc
;
5637 expanded
.sals
[0] = sal
;
5644 for (i
= 0; i
< expanded
.nelts
; ++i
)
5645 if (expanded
.sals
[i
].pc
== original_pc
)
5656 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5657 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5658 value. COND_STRING, if not NULL, specified the condition to be
5659 used for all breakpoints. Essentially the only case where
5660 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5661 function. In that case, it's still not possible to specify
5662 separate conditions for different overloaded functions, so
5663 we take just a single condition string.
5665 NOTE: If the function succeeds, the caller is expected to cleanup
5666 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5667 array contents). If the function fails (error() is called), the
5668 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5669 COND and SALS arrays and each of those arrays contents. */
5672 create_breakpoints (struct gdbarch
*gdbarch
,
5673 struct symtabs_and_lines sals
, char **addr_string
,
5675 enum bptype type
, enum bpdisp disposition
,
5676 int thread
, int task
, int ignore_count
,
5677 struct breakpoint_ops
*ops
, int from_tty
,
5681 for (i
= 0; i
< sals
.nelts
; ++i
)
5683 struct symtabs_and_lines expanded
=
5684 expand_line_sal_maybe (sals
.sals
[i
]);
5686 create_breakpoint (gdbarch
, expanded
, addr_string
[i
],
5687 cond_string
, type
, disposition
,
5688 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
5692 /* Parse ARG which is assumed to be a SAL specification possibly
5693 followed by conditionals. On return, SALS contains an array of SAL
5694 addresses found. ADDR_STRING contains a vector of (canonical)
5695 address strings. ARG points to the end of the SAL. */
5698 parse_breakpoint_sals (char **address
,
5699 struct symtabs_and_lines
*sals
,
5700 char ***addr_string
,
5703 char *addr_start
= *address
;
5704 *addr_string
= NULL
;
5705 /* If no arg given, or if first arg is 'if ', use the default
5707 if ((*address
) == NULL
5708 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5710 if (default_breakpoint_valid
)
5712 struct symtab_and_line sal
;
5713 init_sal (&sal
); /* initialize to zeroes */
5714 sals
->sals
= (struct symtab_and_line
*)
5715 xmalloc (sizeof (struct symtab_and_line
));
5716 sal
.pc
= default_breakpoint_address
;
5717 sal
.line
= default_breakpoint_line
;
5718 sal
.symtab
= default_breakpoint_symtab
;
5719 sal
.section
= find_pc_overlay (sal
.pc
);
5721 /* "break" without arguments is equivalent to "break *PC" where PC is
5722 the default_breakpoint_address. So make sure to set
5723 sal.explicit_pc to prevent GDB from trying to expand the list of
5724 sals to include all other instances with the same symtab and line.
5726 sal
.explicit_pc
= 1;
5728 sals
->sals
[0] = sal
;
5732 error (_("No default breakpoint address now."));
5736 /* Force almost all breakpoints to be in terms of the
5737 current_source_symtab (which is decode_line_1's default). This
5738 should produce the results we want almost all of the time while
5739 leaving default_breakpoint_* alone.
5740 ObjC: However, don't match an Objective-C method name which
5741 may have a '+' or '-' succeeded by a '[' */
5743 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5745 if (default_breakpoint_valid
5747 || ((strchr ("+-", (*address
)[0]) != NULL
)
5748 && ((*address
)[1] != '['))))
5749 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5750 default_breakpoint_line
, addr_string
,
5753 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5754 addr_string
, not_found_ptr
);
5756 /* For any SAL that didn't have a canonical string, fill one in. */
5757 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5758 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5759 if (addr_start
!= (*address
))
5762 for (i
= 0; i
< sals
->nelts
; i
++)
5764 /* Add the string if not present. */
5765 if ((*addr_string
)[i
] == NULL
)
5766 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5772 /* Convert each SAL into a real PC. Verify that the PC can be
5773 inserted as a breakpoint. If it can't throw an error. */
5776 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5780 for (i
= 0; i
< sals
->nelts
; i
++)
5781 resolve_sal_pc (&sals
->sals
[i
]);
5785 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5787 struct captured_parse_breakpoint_args
*args
= data
;
5789 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5790 args
->not_found_ptr
);
5793 /* Given TOK, a string specification of condition and thread, as
5794 accepted by the 'break' command, extract the condition
5795 string and thread number and set *COND_STRING and *THREAD.
5796 PC identifies the context at which the condition should be parsed.
5797 If no condition is found, *COND_STRING is set to NULL.
5798 If no thread is found, *THREAD is set to -1. */
5800 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5801 char **cond_string
, int *thread
, int *task
)
5803 *cond_string
= NULL
;
5809 char *cond_start
= NULL
;
5810 char *cond_end
= NULL
;
5811 while (*tok
== ' ' || *tok
== '\t')
5816 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5819 toklen
= end_tok
- tok
;
5821 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5823 struct expression
*expr
;
5825 tok
= cond_start
= end_tok
+ 1;
5826 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5829 *cond_string
= savestring (cond_start
,
5830 cond_end
- cond_start
);
5832 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5838 *thread
= strtol (tok
, &tok
, 0);
5840 error (_("Junk after thread keyword."));
5841 if (!valid_thread_id (*thread
))
5842 error (_("Unknown thread %d."), *thread
);
5844 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
5850 *task
= strtol (tok
, &tok
, 0);
5852 error (_("Junk after task keyword."));
5853 if (!valid_task_id (*task
))
5854 error (_("Unknown task %d\n"), *task
);
5857 error (_("Junk at end of arguments."));
5861 /* Set a breakpoint. This function is shared between
5862 CLI and MI functions for setting a breakpoint.
5863 This function has two major modes of operations,
5864 selected by the PARSE_CONDITION_AND_THREAD parameter.
5865 If non-zero, the function will parse arg, extracting
5866 breakpoint location, address and thread. Otherwise,
5867 ARG is just the location of breakpoint, with condition
5868 and thread specified by the COND_STRING and THREAD
5872 break_command_really (struct gdbarch
*gdbarch
,
5873 char *arg
, char *cond_string
, int thread
,
5874 int parse_condition_and_thread
,
5875 int tempflag
, int hardwareflag
, int traceflag
,
5877 enum auto_boolean pending_break_support
,
5878 struct breakpoint_ops
*ops
,
5882 struct gdb_exception e
;
5883 struct symtabs_and_lines sals
;
5884 struct symtab_and_line pending_sal
;
5887 char *addr_start
= arg
;
5889 struct cleanup
*old_chain
;
5890 struct cleanup
*bkpt_chain
= NULL
;
5891 struct captured_parse_breakpoint_args parse_args
;
5895 enum bptype type_wanted
;
5902 parse_args
.arg_p
= &arg
;
5903 parse_args
.sals_p
= &sals
;
5904 parse_args
.addr_string_p
= &addr_string
;
5905 parse_args
.not_found_ptr
= ¬_found
;
5907 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5908 &parse_args
, RETURN_MASK_ALL
);
5910 /* If caller is interested in rc value from parse, set value. */
5914 throw_exception (e
);
5918 case NOT_FOUND_ERROR
:
5920 /* If pending breakpoint support is turned off, throw
5923 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5924 throw_exception (e
);
5926 exception_print (gdb_stderr
, e
);
5928 /* If pending breakpoint support is auto query and the user
5929 selects no, then simply return the error code. */
5930 if (pending_break_support
== AUTO_BOOLEAN_AUTO
5931 && !nquery ("Make breakpoint pending on future shared library load? "))
5934 /* At this point, either the user was queried about setting
5935 a pending breakpoint and selected yes, or pending
5936 breakpoint behavior is on and thus a pending breakpoint
5937 is defaulted on behalf of the user. */
5938 copy_arg
= xstrdup (addr_start
);
5939 addr_string
= ©_arg
;
5941 sals
.sals
= &pending_sal
;
5946 throw_exception (e
);
5953 /* Create a chain of things that always need to be cleaned up. */
5954 old_chain
= make_cleanup (null_cleanup
, 0);
5958 /* Make sure that all storage allocated to SALS gets freed. */
5959 make_cleanup (xfree
, sals
.sals
);
5961 /* Cleanup the addr_string array but not its contents. */
5962 make_cleanup (xfree
, addr_string
);
5965 /* ----------------------------- SNIP -----------------------------
5966 Anything added to the cleanup chain beyond this point is assumed
5967 to be part of a breakpoint. If the breakpoint create succeeds
5968 then the memory is not reclaimed. */
5969 bkpt_chain
= make_cleanup (null_cleanup
, 0);
5971 /* Mark the contents of the addr_string for cleanup. These go on
5972 the bkpt_chain and only occur if the breakpoint create fails. */
5973 for (i
= 0; i
< sals
.nelts
; i
++)
5975 if (addr_string
[i
] != NULL
)
5976 make_cleanup (xfree
, addr_string
[i
]);
5979 /* Resolve all line numbers to PC's and verify that the addresses
5980 are ok for the target. */
5982 breakpoint_sals_to_pc (&sals
, addr_start
);
5984 type_wanted
= (traceflag
5986 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
5988 /* Verify that condition can be parsed, before setting any
5989 breakpoints. Allocate a separate condition expression for each
5993 if (parse_condition_and_thread
)
5995 /* Here we only parse 'arg' to separate condition
5996 from thread number, so parsing in context of first
5997 sal is OK. When setting the breakpoint we'll
5998 re-parse it in context of each sal. */
6001 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
6004 make_cleanup (xfree
, cond_string
);
6008 /* Create a private copy of condition string. */
6011 cond_string
= xstrdup (cond_string
);
6012 make_cleanup (xfree
, cond_string
);
6015 create_breakpoints (gdbarch
, sals
, addr_string
, cond_string
, type_wanted
,
6016 tempflag
? disp_del
: disp_donttouch
,
6017 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
6021 struct symtab_and_line sal
= {0};
6022 struct breakpoint
*b
;
6024 make_cleanup (xfree
, copy_arg
);
6026 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
6027 set_breakpoint_count (breakpoint_count
+ 1);
6028 b
->number
= breakpoint_count
;
6030 b
->addr_string
= addr_string
[0];
6031 b
->cond_string
= NULL
;
6032 b
->ignore_count
= ignore_count
;
6033 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6034 b
->condition_not_parsed
= 1;
6036 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6038 if (enabled
&& executing_startup
6039 && (b
->type
== bp_breakpoint
6040 || b
->type
== bp_hardware_breakpoint
))
6041 b
->enable_state
= bp_startup_disabled
;
6047 warning (_("Multiple breakpoints were set.\n"
6048 "Use the \"delete\" command to delete unwanted breakpoints."));
6049 /* That's it. Discard the cleanups for data inserted into the
6051 discard_cleanups (bkpt_chain
);
6052 /* But cleanup everything else. */
6053 do_cleanups (old_chain
);
6055 /* error call may happen here - have BKPT_CHAIN already discarded. */
6056 update_global_location_list (1);
6059 /* Set a breakpoint.
6060 ARG is a string describing breakpoint address,
6061 condition, and thread.
6062 FLAG specifies if a breakpoint is hardware on,
6063 and if breakpoint is temporary, using BP_HARDWARE_FLAG
6067 break_command_1 (char *arg
, int flag
, int from_tty
)
6069 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
6070 int tempflag
= flag
& BP_TEMPFLAG
;
6072 break_command_really (get_current_arch (),
6074 NULL
, 0, 1 /* parse arg */,
6075 tempflag
, hardwareflag
, 0 /* traceflag */,
6076 0 /* Ignore count */,
6077 pending_break_support
,
6078 NULL
/* breakpoint_ops */,
6085 set_breakpoint (struct gdbarch
*gdbarch
,
6086 char *address
, char *condition
,
6087 int hardwareflag
, int tempflag
,
6088 int thread
, int ignore_count
,
6089 int pending
, int enabled
)
6091 break_command_really (gdbarch
,
6092 address
, condition
, thread
,
6093 0 /* condition and thread are valid. */,
6094 tempflag
, hardwareflag
, 0 /* traceflag */,
6097 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
6101 /* Adjust SAL to the first instruction past the function prologue.
6102 The end of the prologue is determined using the line table from
6103 the debugging information. explicit_pc and explicit_line are
6106 If SAL is already past the prologue, then do nothing. */
6109 skip_prologue_sal (struct symtab_and_line
*sal
)
6111 struct symbol
*sym
= find_pc_function (sal
->pc
);
6112 struct symtab_and_line start_sal
;
6117 start_sal
= find_function_start_sal (sym
, 1);
6118 if (sal
->pc
< start_sal
.pc
)
6120 start_sal
.explicit_line
= sal
->explicit_line
;
6121 start_sal
.explicit_pc
= sal
->explicit_pc
;
6126 /* Helper function for break_command_1 and disassemble_command. */
6129 resolve_sal_pc (struct symtab_and_line
*sal
)
6133 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
6135 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
6136 error (_("No line %d in file \"%s\"."),
6137 sal
->line
, sal
->symtab
->filename
);
6140 /* If this SAL corresponds to a breakpoint inserted using
6141 a line number, then skip the function prologue if necessary. */
6142 if (sal
->explicit_line
)
6144 /* Preserve the original line number. */
6145 int saved_line
= sal
->line
;
6146 skip_prologue_sal (sal
);
6147 sal
->line
= saved_line
;
6151 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
6153 struct blockvector
*bv
;
6157 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
6160 sym
= block_linkage_function (b
);
6163 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
6164 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
6168 /* It really is worthwhile to have the section, so we'll just
6169 have to look harder. This case can be executed if we have
6170 line numbers but no functions (as can happen in assembly
6173 struct minimal_symbol
*msym
;
6175 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
6177 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
6184 break_command (char *arg
, int from_tty
)
6186 break_command_1 (arg
, 0, from_tty
);
6190 tbreak_command (char *arg
, int from_tty
)
6192 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
6196 hbreak_command (char *arg
, int from_tty
)
6198 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
6202 thbreak_command (char *arg
, int from_tty
)
6204 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
6208 stop_command (char *arg
, int from_tty
)
6210 printf_filtered (_("Specify the type of breakpoint to set.\n\
6211 Usage: stop in <function | address>\n\
6212 stop at <line>\n"));
6216 stopin_command (char *arg
, int from_tty
)
6220 if (arg
== (char *) NULL
)
6222 else if (*arg
!= '*')
6227 /* look for a ':'. If this is a line number specification, then
6228 say it is bad, otherwise, it should be an address or
6229 function/method name */
6230 while (*argptr
&& !hasColon
)
6232 hasColon
= (*argptr
== ':');
6237 badInput
= (*argptr
!= ':'); /* Not a class::method */
6239 badInput
= isdigit (*arg
); /* a simple line number */
6243 printf_filtered (_("Usage: stop in <function | address>\n"));
6245 break_command_1 (arg
, 0, from_tty
);
6249 stopat_command (char *arg
, int from_tty
)
6253 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
6260 /* look for a ':'. If there is a '::' then get out, otherwise
6261 it is probably a line number. */
6262 while (*argptr
&& !hasColon
)
6264 hasColon
= (*argptr
== ':');
6269 badInput
= (*argptr
== ':'); /* we have class::method */
6271 badInput
= !isdigit (*arg
); /* not a line number */
6275 printf_filtered (_("Usage: stop at <line>\n"));
6277 break_command_1 (arg
, 0, from_tty
);
6280 /* accessflag: hw_write: watch write,
6281 hw_read: watch read,
6282 hw_access: watch access (read or write) */
6284 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
6286 struct gdbarch
*gdbarch
= get_current_arch ();
6287 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
6288 struct symtab_and_line sal
;
6289 struct expression
*exp
;
6290 struct block
*exp_valid_block
;
6291 struct value
*val
, *mark
;
6292 struct frame_info
*frame
;
6293 char *exp_start
= NULL
;
6294 char *exp_end
= NULL
;
6295 char *tok
, *id_tok_start
, *end_tok
;
6297 char *cond_start
= NULL
;
6298 char *cond_end
= NULL
;
6299 struct expression
*cond
= NULL
;
6300 int i
, other_type_used
, target_resources_ok
= 0;
6301 enum bptype bp_type
;
6305 init_sal (&sal
); /* initialize to zeroes */
6307 /* Make sure that we actually have parameters to parse. */
6308 if (arg
!= NULL
&& arg
[0] != '\0')
6310 toklen
= strlen (arg
); /* Size of argument list. */
6312 /* Points tok to the end of the argument list. */
6313 tok
= arg
+ toklen
- 1;
6315 /* Go backwards in the parameters list. Skip the last parameter.
6316 If we're expecting a 'thread <thread_num>' parameter, this should
6317 be the thread identifier. */
6318 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6320 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6323 /* Points end_tok to the beginning of the last token. */
6324 id_tok_start
= tok
+ 1;
6326 /* Go backwards in the parameters list. Skip one more parameter.
6327 If we're expecting a 'thread <thread_num>' parameter, we should
6328 reach a "thread" token. */
6329 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6334 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6337 /* Move the pointer forward to skip the whitespace and
6338 calculate the length of the token. */
6340 toklen
= end_tok
- tok
;
6342 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
6344 /* At this point we've found a "thread" token, which means
6345 the user is trying to set a watchpoint that triggers
6346 only in a specific thread. */
6349 /* Extract the thread ID from the next token. */
6350 thread
= strtol (id_tok_start
, &endp
, 0);
6352 /* Check if the user provided a valid numeric value for the
6354 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
6355 error (_("Invalid thread ID specification %s."), id_tok_start
);
6357 /* Check if the thread actually exists. */
6358 if (!valid_thread_id (thread
))
6359 error (_("Unknown thread %d."), thread
);
6361 /* Truncate the string and get rid of the thread <thread_num>
6362 parameter before the parameter list is parsed by the
6363 evaluate_expression() function. */
6368 /* Parse the rest of the arguments. */
6369 innermost_block
= NULL
;
6371 exp
= parse_exp_1 (&arg
, 0, 0);
6373 /* Remove trailing whitespace from the expression before saving it.
6374 This makes the eventual display of the expression string a bit
6376 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
6379 exp_valid_block
= innermost_block
;
6380 mark
= value_mark ();
6381 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
6383 release_value (val
);
6386 while (*tok
== ' ' || *tok
== '\t')
6390 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6393 toklen
= end_tok
- tok
;
6394 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6396 tok
= cond_start
= end_tok
+ 1;
6397 cond
= parse_exp_1 (&tok
, 0, 0);
6401 error (_("Junk at end of command."));
6403 if (accessflag
== hw_read
)
6404 bp_type
= bp_read_watchpoint
;
6405 else if (accessflag
== hw_access
)
6406 bp_type
= bp_access_watchpoint
;
6408 bp_type
= bp_hardware_watchpoint
;
6410 mem_cnt
= can_use_hardware_watchpoint (val
);
6411 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
6412 error (_("Expression cannot be implemented with read/access watchpoint."));
6415 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
6416 target_resources_ok
=
6417 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
6419 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
6420 error (_("Target does not support this type of hardware watchpoint."));
6422 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
6423 error (_("Target can only support one kind of HW watchpoint at a time."));
6426 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6427 watchpoint could not be set. */
6428 if (!mem_cnt
|| target_resources_ok
<= 0)
6429 bp_type
= bp_watchpoint
;
6431 frame
= block_innermost_frame (exp_valid_block
);
6433 /* If the expression is "local", then set up a "watchpoint scope"
6434 breakpoint at the point where we've left the scope of the watchpoint
6435 expression. Create the scope breakpoint before the watchpoint, so
6436 that we will encounter it first in bpstat_stop_status. */
6437 if (innermost_block
&& frame
)
6439 if (frame_id_p (frame_unwind_caller_id (frame
)))
6442 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
6443 frame_unwind_caller_pc (frame
),
6444 bp_watchpoint_scope
);
6446 scope_breakpoint
->enable_state
= bp_enabled
;
6448 /* Automatically delete the breakpoint when it hits. */
6449 scope_breakpoint
->disposition
= disp_del
;
6451 /* Only break in the proper frame (help with recursion). */
6452 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
6454 /* Set the address at which we will stop. */
6455 scope_breakpoint
->loc
->gdbarch
6456 = frame_unwind_caller_arch (frame
);
6457 scope_breakpoint
->loc
->requested_address
6458 = frame_unwind_caller_pc (frame
);
6459 scope_breakpoint
->loc
->address
6460 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
6461 scope_breakpoint
->loc
->requested_address
,
6462 scope_breakpoint
->type
);
6466 /* Now set up the breakpoint. */
6467 b
= set_raw_breakpoint (gdbarch
, sal
, bp_type
);
6468 set_breakpoint_count (breakpoint_count
+ 1);
6469 b
->number
= breakpoint_count
;
6471 b
->disposition
= disp_donttouch
;
6473 b
->exp_valid_block
= exp_valid_block
;
6474 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6477 b
->loc
->cond
= cond
;
6479 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6484 b
->watchpoint_frame
= get_frame_id (frame
);
6486 b
->watchpoint_frame
= null_frame_id
;
6488 if (scope_breakpoint
!= NULL
)
6490 /* The scope breakpoint is related to the watchpoint. We will
6491 need to act on them together. */
6492 b
->related_breakpoint
= scope_breakpoint
;
6493 scope_breakpoint
->related_breakpoint
= b
;
6496 value_free_to_mark (mark
);
6498 update_global_location_list (1);
6501 /* Return count of locations need to be watched and can be handled
6502 in hardware. If the watchpoint can not be handled
6503 in hardware return zero. */
6506 can_use_hardware_watchpoint (struct value
*v
)
6508 int found_memory_cnt
= 0;
6509 struct value
*head
= v
;
6511 /* Did the user specifically forbid us to use hardware watchpoints? */
6512 if (!can_use_hw_watchpoints
)
6515 /* Make sure that the value of the expression depends only upon
6516 memory contents, and values computed from them within GDB. If we
6517 find any register references or function calls, we can't use a
6518 hardware watchpoint.
6520 The idea here is that evaluating an expression generates a series
6521 of values, one holding the value of every subexpression. (The
6522 expression a*b+c has five subexpressions: a, b, a*b, c, and
6523 a*b+c.) GDB's values hold almost enough information to establish
6524 the criteria given above --- they identify memory lvalues,
6525 register lvalues, computed values, etcetera. So we can evaluate
6526 the expression, and then scan the chain of values that leaves
6527 behind to decide whether we can detect any possible change to the
6528 expression's final value using only hardware watchpoints.
6530 However, I don't think that the values returned by inferior
6531 function calls are special in any way. So this function may not
6532 notice that an expression involving an inferior function call
6533 can't be watched with hardware watchpoints. FIXME. */
6534 for (; v
; v
= value_next (v
))
6536 if (VALUE_LVAL (v
) == lval_memory
)
6539 /* A lazy memory lvalue is one that GDB never needed to fetch;
6540 we either just used its address (e.g., `a' in `a.b') or
6541 we never needed it at all (e.g., `a' in `a,b'). */
6545 /* Ahh, memory we actually used! Check if we can cover
6546 it with hardware watchpoints. */
6547 struct type
*vtype
= check_typedef (value_type (v
));
6549 /* We only watch structs and arrays if user asked for it
6550 explicitly, never if they just happen to appear in a
6551 middle of some value chain. */
6553 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6554 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6556 CORE_ADDR vaddr
= value_address (v
);
6557 int len
= TYPE_LENGTH (value_type (v
));
6559 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
6566 else if (VALUE_LVAL (v
) != not_lval
6567 && deprecated_value_modifiable (v
) == 0)
6568 return 0; /* ??? What does this represent? */
6569 else if (VALUE_LVAL (v
) == lval_register
)
6570 return 0; /* cannot watch a register with a HW watchpoint */
6573 /* The expression itself looks suitable for using a hardware
6574 watchpoint, but give the target machine a chance to reject it. */
6575 return found_memory_cnt
;
6579 watch_command_wrapper (char *arg
, int from_tty
)
6581 watch_command (arg
, from_tty
);
6585 watch_command (char *arg
, int from_tty
)
6587 watch_command_1 (arg
, hw_write
, from_tty
);
6591 rwatch_command_wrapper (char *arg
, int from_tty
)
6593 rwatch_command (arg
, from_tty
);
6597 rwatch_command (char *arg
, int from_tty
)
6599 watch_command_1 (arg
, hw_read
, from_tty
);
6603 awatch_command_wrapper (char *arg
, int from_tty
)
6605 awatch_command (arg
, from_tty
);
6609 awatch_command (char *arg
, int from_tty
)
6611 watch_command_1 (arg
, hw_access
, from_tty
);
6615 /* Helper routines for the until_command routine in infcmd.c. Here
6616 because it uses the mechanisms of breakpoints. */
6618 struct until_break_command_continuation_args
6620 struct breakpoint
*breakpoint
;
6621 struct breakpoint
*breakpoint2
;
6624 /* This function is called by fetch_inferior_event via the
6625 cmd_continuation pointer, to complete the until command. It takes
6626 care of cleaning up the temporary breakpoints set up by the until
6629 until_break_command_continuation (void *arg
)
6631 struct until_break_command_continuation_args
*a
= arg
;
6633 delete_breakpoint (a
->breakpoint
);
6635 delete_breakpoint (a
->breakpoint2
);
6639 until_break_command (char *arg
, int from_tty
, int anywhere
)
6641 struct symtabs_and_lines sals
;
6642 struct symtab_and_line sal
;
6643 struct frame_info
*frame
= get_selected_frame (NULL
);
6644 struct breakpoint
*breakpoint
;
6645 struct breakpoint
*breakpoint2
= NULL
;
6646 struct cleanup
*old_chain
;
6648 clear_proceed_status ();
6650 /* Set a breakpoint where the user wants it and at return from
6653 if (default_breakpoint_valid
)
6654 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6655 default_breakpoint_line
, (char ***) NULL
, NULL
);
6657 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6658 0, (char ***) NULL
, NULL
);
6660 if (sals
.nelts
!= 1)
6661 error (_("Couldn't get information on specified line."));
6664 xfree (sals
.sals
); /* malloc'd, so freed */
6667 error (_("Junk at end of arguments."));
6669 resolve_sal_pc (&sal
);
6672 /* If the user told us to continue until a specified location,
6673 we don't specify a frame at which we need to stop. */
6674 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
6675 null_frame_id
, bp_until
);
6677 /* Otherwise, specify the selected frame, because we want to stop only
6678 at the very same frame. */
6679 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
6680 get_stack_frame_id (frame
),
6683 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6685 /* Keep within the current frame, or in frames called by the current
6688 if (frame_id_p (frame_unwind_caller_id (frame
)))
6690 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
6691 sal
.pc
= frame_unwind_caller_pc (frame
);
6692 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
6694 frame_unwind_caller_id (frame
),
6696 make_cleanup_delete_breakpoint (breakpoint2
);
6699 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6701 /* If we are running asynchronously, and proceed call above has actually
6702 managed to start the target, arrange for breakpoints to be
6703 deleted when the target stops. Otherwise, we're already stopped and
6704 delete breakpoints via cleanup chain. */
6706 if (target_can_async_p () && is_running (inferior_ptid
))
6708 struct until_break_command_continuation_args
*args
;
6709 args
= xmalloc (sizeof (*args
));
6711 args
->breakpoint
= breakpoint
;
6712 args
->breakpoint2
= breakpoint2
;
6714 discard_cleanups (old_chain
);
6715 add_continuation (inferior_thread (),
6716 until_break_command_continuation
, args
,
6720 do_cleanups (old_chain
);
6724 ep_skip_leading_whitespace (char **s
)
6726 if ((s
== NULL
) || (*s
== NULL
))
6728 while (isspace (**s
))
6732 /* This function attempts to parse an optional "if <cond>" clause
6733 from the arg string. If one is not found, it returns NULL.
6735 Else, it returns a pointer to the condition string. (It does not
6736 attempt to evaluate the string against a particular block.) And,
6737 it updates arg to point to the first character following the parsed
6738 if clause in the arg string. */
6741 ep_parse_optional_if_clause (char **arg
)
6745 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6748 /* Skip the "if" keyword. */
6751 /* Skip any extra leading whitespace, and record the start of the
6752 condition string. */
6753 ep_skip_leading_whitespace (arg
);
6756 /* Assume that the condition occupies the remainder of the arg string. */
6757 (*arg
) += strlen (cond_string
);
6762 /* This function attempts to parse an optional filename from the arg
6763 string. If one is not found, it returns NULL.
6765 Else, it returns a pointer to the parsed filename. (This function
6766 makes no attempt to verify that a file of that name exists, or is
6767 accessible.) And, it updates arg to point to the first character
6768 following the parsed filename in the arg string.
6770 Note that clients needing to preserve the returned filename for
6771 future access should copy it to their own buffers. */
6773 ep_parse_optional_filename (char **arg
)
6775 static char filename
[1024];
6780 if ((*arg_p
== '\0') || isspace (*arg_p
))
6798 /* Commands to deal with catching events, such as signals, exceptions,
6799 process start/exit, etc. */
6803 catch_fork_temporary
, catch_vfork_temporary
,
6804 catch_fork_permanent
, catch_vfork_permanent
6809 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6811 struct gdbarch
*gdbarch
= get_current_arch ();
6812 char *cond_string
= NULL
;
6813 catch_fork_kind fork_kind
;
6816 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6817 tempflag
= (fork_kind
== catch_fork_temporary
6818 || fork_kind
== catch_vfork_temporary
);
6822 ep_skip_leading_whitespace (&arg
);
6824 /* The allowed syntax is:
6826 catch [v]fork if <cond>
6828 First, check if there's an if clause. */
6829 cond_string
= ep_parse_optional_if_clause (&arg
);
6831 if ((*arg
!= '\0') && !isspace (*arg
))
6832 error (_("Junk at end of arguments."));
6834 /* If this target supports it, create a fork or vfork catchpoint
6835 and enable reporting of such events. */
6838 case catch_fork_temporary
:
6839 case catch_fork_permanent
:
6840 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
6841 &catch_fork_breakpoint_ops
);
6843 case catch_vfork_temporary
:
6844 case catch_vfork_permanent
:
6845 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
6846 &catch_vfork_breakpoint_ops
);
6849 error (_("unsupported or unknown fork kind; cannot catch it"));
6855 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6857 struct gdbarch
*gdbarch
= get_current_arch ();
6859 char *cond_string
= NULL
;
6861 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6865 ep_skip_leading_whitespace (&arg
);
6867 /* The allowed syntax is:
6869 catch exec if <cond>
6871 First, check if there's an if clause. */
6872 cond_string
= ep_parse_optional_if_clause (&arg
);
6874 if ((*arg
!= '\0') && !isspace (*arg
))
6875 error (_("Junk at end of arguments."));
6877 /* If this target supports it, create an exec catchpoint
6878 and enable reporting of such events. */
6879 create_catchpoint (gdbarch
, tempflag
, cond_string
,
6880 &catch_exec_breakpoint_ops
);
6883 static enum print_stop_action
6884 print_exception_catchpoint (struct breakpoint
*b
)
6886 int bp_temp
, bp_throw
;
6888 annotate_catchpoint (b
->number
);
6890 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6891 if (b
->loc
->address
!= b
->loc
->requested_address
)
6892 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6895 bp_temp
= b
->disposition
== disp_del
;
6897 bp_temp
? "Temporary catchpoint "
6899 if (!ui_out_is_mi_like_p (uiout
))
6900 ui_out_field_int (uiout
, "bkptno", b
->number
);
6902 bp_throw
? " (exception thrown), "
6903 : " (exception caught), ");
6904 if (ui_out_is_mi_like_p (uiout
))
6906 ui_out_field_string (uiout
, "reason",
6907 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6908 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6909 ui_out_field_int (uiout
, "bkptno", b
->number
);
6911 return PRINT_SRC_AND_LOC
;
6915 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
6917 struct value_print_options opts
;
6918 get_user_print_options (&opts
);
6919 if (opts
.addressprint
)
6922 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6923 ui_out_field_string (uiout
, "addr", "<PENDING>");
6925 ui_out_field_core_addr (uiout
, "addr",
6926 b
->loc
->gdbarch
, b
->loc
->address
);
6931 if (strstr (b
->addr_string
, "throw") != NULL
)
6932 ui_out_field_string (uiout
, "what", "exception throw");
6934 ui_out_field_string (uiout
, "what", "exception catch");
6938 print_mention_exception_catchpoint (struct breakpoint
*b
)
6943 bp_temp
= b
->disposition
== disp_del
;
6944 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6945 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6946 : _("Catchpoint "));
6947 ui_out_field_int (uiout
, "bkptno", b
->number
);
6948 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6952 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6955 NULL
, /* breakpoint_hit */
6956 print_exception_catchpoint
,
6957 print_one_exception_catchpoint
,
6958 print_mention_exception_catchpoint
6962 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6963 enum exception_event_kind ex_event
, int from_tty
)
6965 char *trigger_func_name
;
6967 if (ex_event
== EX_EVENT_CATCH
)
6968 trigger_func_name
= "__cxa_begin_catch";
6970 trigger_func_name
= "__cxa_throw";
6972 break_command_really (get_current_arch (),
6973 trigger_func_name
, cond_string
, -1,
6974 0 /* condition and thread are valid. */,
6977 AUTO_BOOLEAN_TRUE
/* pending */,
6978 &gnu_v3_exception_catchpoint_ops
, from_tty
,
6984 /* Deal with "catch catch" and "catch throw" commands */
6987 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6988 int tempflag
, int from_tty
)
6990 char *cond_string
= NULL
;
6991 struct symtab_and_line
*sal
= NULL
;
6995 ep_skip_leading_whitespace (&arg
);
6997 cond_string
= ep_parse_optional_if_clause (&arg
);
6999 if ((*arg
!= '\0') && !isspace (*arg
))
7000 error (_("Junk at end of arguments."));
7002 if (ex_event
!= EX_EVENT_THROW
7003 && ex_event
!= EX_EVENT_CATCH
)
7004 error (_("Unsupported or unknown exception event; cannot catch it"));
7006 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
7009 warning (_("Unsupported with this platform/compiler combination."));
7012 /* Implementation of "catch catch" command. */
7015 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7017 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7018 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
7021 /* Implementation of "catch throw" command. */
7024 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7026 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7027 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
7030 /* Create a breakpoint struct for Ada exception catchpoints. */
7033 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
7034 struct symtab_and_line sal
,
7038 struct expression
*cond
,
7039 struct breakpoint_ops
*ops
,
7043 struct breakpoint
*b
;
7047 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7049 loc_gdbarch
= gdbarch
;
7051 describe_other_breakpoints (loc_gdbarch
, sal
.pc
, sal
.section
, -1);
7052 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
7053 version for exception catchpoints, because two catchpoints
7054 used for different exception names will use the same address.
7055 In this case, a "breakpoint ... also set at..." warning is
7056 unproductive. Besides. the warning phrasing is also a bit
7057 inapropriate, we should use the word catchpoint, and tell
7058 the user what type of catchpoint it is. The above is good
7059 enough for now, though. */
7062 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
7063 set_breakpoint_count (breakpoint_count
+ 1);
7065 b
->enable_state
= bp_enabled
;
7066 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7067 b
->number
= breakpoint_count
;
7068 b
->ignore_count
= 0;
7069 b
->loc
->cond
= cond
;
7070 b
->addr_string
= addr_string
;
7071 b
->language
= language_ada
;
7072 b
->cond_string
= cond_string
;
7073 b
->exp_string
= exp_string
;
7078 update_global_location_list (1);
7081 /* Implement the "catch exception" command. */
7084 catch_ada_exception_command (char *arg
, int from_tty
,
7085 struct cmd_list_element
*command
)
7087 struct gdbarch
*gdbarch
= get_current_arch ();
7089 struct symtab_and_line sal
;
7091 char *addr_string
= NULL
;
7092 char *exp_string
= NULL
;
7093 char *cond_string
= NULL
;
7094 struct expression
*cond
= NULL
;
7095 struct breakpoint_ops
*ops
= NULL
;
7097 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7101 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
7102 &cond_string
, &cond
, &ops
);
7103 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
7104 cond_string
, cond
, ops
, tempflag
,
7108 /* Implement the "catch assert" command. */
7111 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7113 struct gdbarch
*gdbarch
= get_current_arch ();
7115 struct symtab_and_line sal
;
7116 char *addr_string
= NULL
;
7117 struct breakpoint_ops
*ops
= NULL
;
7119 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7123 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
7124 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
7125 ops
, tempflag
, from_tty
);
7129 catch_command (char *arg
, int from_tty
)
7131 error (_("Catch requires an event name."));
7136 tcatch_command (char *arg
, int from_tty
)
7138 error (_("Catch requires an event name."));
7141 /* Delete breakpoints by address or line. */
7144 clear_command (char *arg
, int from_tty
)
7146 struct breakpoint
*b
;
7147 VEC(breakpoint_p
) *found
= 0;
7150 struct symtabs_and_lines sals
;
7151 struct symtab_and_line sal
;
7156 sals
= decode_line_spec (arg
, 1);
7161 sals
.sals
= (struct symtab_and_line
*)
7162 xmalloc (sizeof (struct symtab_and_line
));
7163 make_cleanup (xfree
, sals
.sals
);
7164 init_sal (&sal
); /* initialize to zeroes */
7165 sal
.line
= default_breakpoint_line
;
7166 sal
.symtab
= default_breakpoint_symtab
;
7167 sal
.pc
= default_breakpoint_address
;
7168 if (sal
.symtab
== 0)
7169 error (_("No source file specified."));
7177 /* We don't call resolve_sal_pc here. That's not
7178 as bad as it seems, because all existing breakpoints
7179 typically have both file/line and pc set. So, if
7180 clear is given file/line, we can match this to existing
7181 breakpoint without obtaining pc at all.
7183 We only support clearing given the address explicitly
7184 present in breakpoint table. Say, we've set breakpoint
7185 at file:line. There were several PC values for that file:line,
7186 due to optimization, all in one block.
7187 We've picked one PC value. If "clear" is issued with another
7188 PC corresponding to the same file:line, the breakpoint won't
7189 be cleared. We probably can still clear the breakpoint, but
7190 since the other PC value is never presented to user, user
7191 can only find it by guessing, and it does not seem important
7194 /* For each line spec given, delete bps which correspond
7195 to it. Do it in two passes, solely to preserve the current
7196 behavior that from_tty is forced true if we delete more than
7200 for (i
= 0; i
< sals
.nelts
; i
++)
7202 /* If exact pc given, clear bpts at that pc.
7203 If line given (pc == 0), clear all bpts on specified line.
7204 If defaulting, clear all bpts on default line
7207 defaulting sal.pc != 0 tests to do
7212 1 0 <can't happen> */
7216 /* Find all matching breakpoints and add them to
7221 /* Are we going to delete b? */
7222 if (b
->type
!= bp_none
7223 && b
->type
!= bp_watchpoint
7224 && b
->type
!= bp_hardware_watchpoint
7225 && b
->type
!= bp_read_watchpoint
7226 && b
->type
!= bp_access_watchpoint
)
7228 struct bp_location
*loc
= b
->loc
;
7229 for (; loc
; loc
= loc
->next
)
7231 int pc_match
= sal
.pc
7232 && (loc
->address
== sal
.pc
)
7233 && (!section_is_overlay (loc
->section
)
7234 || loc
->section
== sal
.section
);
7235 int line_match
= ((default_match
|| (0 == sal
.pc
))
7236 && b
->source_file
!= NULL
7237 && sal
.symtab
!= NULL
7238 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
7239 && b
->line_number
== sal
.line
);
7240 if (pc_match
|| line_match
)
7249 VEC_safe_push(breakpoint_p
, found
, b
);
7252 /* Now go thru the 'found' chain and delete them. */
7253 if (VEC_empty(breakpoint_p
, found
))
7256 error (_("No breakpoint at %s."), arg
);
7258 error (_("No breakpoint at this line."));
7261 if (VEC_length(breakpoint_p
, found
) > 1)
7262 from_tty
= 1; /* Always report if deleted more than one */
7265 if (VEC_length(breakpoint_p
, found
) == 1)
7266 printf_unfiltered (_("Deleted breakpoint "));
7268 printf_unfiltered (_("Deleted breakpoints "));
7270 breakpoints_changed ();
7272 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
7275 printf_unfiltered ("%d ", b
->number
);
7276 delete_breakpoint (b
);
7279 putchar_unfiltered ('\n');
7282 /* Delete breakpoint in BS if they are `delete' breakpoints and
7283 all breakpoints that are marked for deletion, whether hit or not.
7284 This is called after any breakpoint is hit, or after errors. */
7287 breakpoint_auto_delete (bpstat bs
)
7289 struct breakpoint
*b
, *temp
;
7291 for (; bs
; bs
= bs
->next
)
7292 if (bs
->breakpoint_at
7293 && bs
->breakpoint_at
->owner
7294 && bs
->breakpoint_at
->owner
->disposition
== disp_del
7296 delete_breakpoint (bs
->breakpoint_at
->owner
);
7298 ALL_BREAKPOINTS_SAFE (b
, temp
)
7300 if (b
->disposition
== disp_del_at_next_stop
)
7301 delete_breakpoint (b
);
7305 /* A cleanup function which destroys a vector. */
7308 do_vec_free (void *p
)
7310 VEC(bp_location_p
) **vec
= p
;
7312 VEC_free (bp_location_p
, *vec
);
7315 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
7316 into the inferior, only remove already-inserted locations that no
7317 longer should be inserted. Functions that delete a breakpoint or
7318 breakpoints should pass false, so that deleting a breakpoint
7319 doesn't have the side effect of inserting the locations of other
7320 breakpoints that are marked not-inserted, but should_be_inserted
7321 returns true on them.
7323 This behaviour is useful is situations close to tear-down -- e.g.,
7324 after an exec, while the target still has execution, but breakpoint
7325 shadows of the previous executable image should *NOT* be restored
7326 to the new image; or before detaching, where the target still has
7327 execution and wants to delete breakpoints from GDB's lists, and all
7328 breakpoints had already been removed from the inferior. */
7331 update_global_location_list (int should_insert
)
7333 struct breakpoint
*b
;
7334 struct bp_location
**next
= &bp_location_chain
;
7335 struct bp_location
*loc
;
7336 struct bp_location
*loc2
;
7337 VEC(bp_location_p
) *old_locations
= NULL
;
7340 struct cleanup
*cleanups
;
7342 cleanups
= make_cleanup (do_vec_free
, &old_locations
);
7343 /* Store old locations for future reference. */
7344 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7345 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7347 bp_location_chain
= NULL
;
7350 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7353 next
= &(loc
->global_next
);
7358 /* Identify bp_location instances that are no longer present in the new
7359 list, and therefore should be freed. Note that it's not necessary that
7360 those locations should be removed from inferior -- if there's another
7361 location at the same address (previously marked as duplicate),
7362 we don't need to remove/insert the location. */
7363 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7365 /* Tells if 'loc' is found amoung the new locations. If not, we
7367 int found_object
= 0;
7368 /* Tells if the location should remain inserted in the target. */
7369 int keep_in_target
= 0;
7371 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7378 /* If this location is no longer present, and inserted, look if there's
7379 maybe a new location at the same address. If so, mark that one
7380 inserted, and don't remove this one. This is needed so that we
7381 don't have a time window where a breakpoint at certain location is not
7386 /* If the location is inserted now, we might have to remove it. */
7388 if (found_object
&& should_be_inserted (loc
))
7390 /* The location is still present in the location list, and still
7391 should be inserted. Don't do anything. */
7396 /* The location is either no longer present, or got disabled.
7397 See if there's another location at the same address, in which
7398 case we don't need to remove this one from the target. */
7399 if (breakpoint_address_is_meaningful (loc
->owner
))
7400 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7402 /* For the sake of should_insert_location. The
7403 call to check_duplicates will fix up this later. */
7404 loc2
->duplicate
= 0;
7405 if (should_be_inserted (loc2
)
7406 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7409 loc2
->target_info
= loc
->target_info
;
7416 if (!keep_in_target
)
7418 if (remove_breakpoint (loc
, mark_uninserted
))
7420 /* This is just about all we can do. We could keep this
7421 location on the global list, and try to remove it next
7422 time, but there's no particular reason why we will
7425 Note that at this point, loc->owner is still valid,
7426 as delete_breakpoint frees the breakpoint only
7427 after calling us. */
7428 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7429 loc
->owner
->number
);
7437 if (removed
&& non_stop
)
7439 /* This location was removed from the targets. In non-stop mode,
7440 a race condition is possible where we've removed a breakpoint,
7441 but stop events for that breakpoint are already queued and will
7442 arrive later. To suppress spurious SIGTRAPs reported to user,
7443 we keep this breakpoint location for a bit, and will retire it
7444 after we see 3 * thread_count events.
7445 The theory here is that reporting of events should,
7446 "on the average", be fair, so after that many event we'll see
7447 events from all threads that have anything of interest, and no
7448 longer need to keep this breakpoint. This is just a
7449 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7450 which is usability issue, but not a correctness problem. */
7451 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7454 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
7457 free_bp_location (loc
);
7463 check_duplicates (b
);
7466 if (breakpoints_always_inserted_mode () && should_insert
7467 && (have_live_inferiors ()
7468 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
7469 insert_breakpoint_locations ();
7471 do_cleanups (cleanups
);
7475 breakpoint_retire_moribund (void)
7477 struct bp_location
*loc
;
7480 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7481 if (--(loc
->events_till_retirement
) == 0)
7483 free_bp_location (loc
);
7484 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7490 update_global_location_list_nothrow (int inserting
)
7492 struct gdb_exception e
;
7493 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7494 update_global_location_list (inserting
);
7497 /* Clear BPT from a BPS. */
7499 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7502 for (bs
= bps
; bs
; bs
= bs
->next
)
7503 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7505 bs
->breakpoint_at
= NULL
;
7507 /* bs->commands will be freed later. */
7511 /* Callback for iterate_over_threads. */
7513 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7515 struct breakpoint
*bpt
= data
;
7516 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7520 /* Delete a breakpoint and clean up all traces of it in the data
7524 delete_breakpoint (struct breakpoint
*bpt
)
7526 struct breakpoint
*b
;
7527 struct bp_location
*loc
, *next
;
7529 gdb_assert (bpt
!= NULL
);
7531 /* Has this bp already been deleted? This can happen because multiple
7532 lists can hold pointers to bp's. bpstat lists are especial culprits.
7534 One example of this happening is a watchpoint's scope bp. When the
7535 scope bp triggers, we notice that the watchpoint is out of scope, and
7536 delete it. We also delete its scope bp. But the scope bp is marked
7537 "auto-deleting", and is already on a bpstat. That bpstat is then
7538 checked for auto-deleting bp's, which are deleted.
7540 A real solution to this problem might involve reference counts in bp's,
7541 and/or giving them pointers back to their referencing bpstat's, and
7542 teaching delete_breakpoint to only free a bp's storage when no more
7543 references were extent. A cheaper bandaid was chosen. */
7544 if (bpt
->type
== bp_none
)
7547 observer_notify_breakpoint_deleted (bpt
->number
);
7549 if (breakpoint_chain
== bpt
)
7550 breakpoint_chain
= bpt
->next
;
7555 b
->next
= bpt
->next
;
7559 free_command_lines (&bpt
->commands
);
7560 if (bpt
->cond_string
!= NULL
)
7561 xfree (bpt
->cond_string
);
7562 if (bpt
->addr_string
!= NULL
)
7563 xfree (bpt
->addr_string
);
7564 if (bpt
->exp
!= NULL
)
7566 if (bpt
->exp_string
!= NULL
)
7567 xfree (bpt
->exp_string
);
7568 if (bpt
->val
!= NULL
)
7569 value_free (bpt
->val
);
7570 if (bpt
->source_file
!= NULL
)
7571 xfree (bpt
->source_file
);
7572 if (bpt
->exec_pathname
!= NULL
)
7573 xfree (bpt
->exec_pathname
);
7575 /* Be sure no bpstat's are pointing at it after it's been freed. */
7576 /* FIXME, how can we find all bpstat's?
7577 We just check stop_bpstat for now. Note that we cannot just
7578 remove bpstats pointing at bpt from the stop_bpstat list
7579 entirely, as breakpoint commands are associated with the bpstat;
7580 if we remove it here, then the later call to
7581 bpstat_do_actions (&stop_bpstat);
7582 in event-top.c won't do anything, and temporary breakpoints
7583 with commands won't work. */
7585 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7587 /* Now that breakpoint is removed from breakpoint
7588 list, update the global location list. This
7589 will remove locations that used to belong to
7590 this breakpoint. Do this before freeing
7591 the breakpoint itself, since remove_breakpoint
7592 looks at location's owner. It might be better
7593 design to have location completely self-contained,
7594 but it's not the case now. */
7595 update_global_location_list (0);
7598 /* On the chance that someone will soon try again to delete this same
7599 bp, we mark it as deleted before freeing its storage. */
7600 bpt
->type
= bp_none
;
7606 do_delete_breakpoint_cleanup (void *b
)
7608 delete_breakpoint (b
);
7612 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7614 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7618 delete_command (char *arg
, int from_tty
)
7620 struct breakpoint
*b
, *temp
;
7626 int breaks_to_delete
= 0;
7628 /* Delete all breakpoints if no argument.
7629 Do not delete internal or call-dummy breakpoints, these
7630 have to be deleted with an explicit breakpoint number argument. */
7633 if (b
->type
!= bp_call_dummy
7634 && b
->type
!= bp_shlib_event
7635 && b
->type
!= bp_thread_event
7636 && b
->type
!= bp_overlay_event
7637 && b
->type
!= bp_longjmp_master
7640 breaks_to_delete
= 1;
7645 /* Ask user only if there are some breakpoints to delete. */
7647 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7649 ALL_BREAKPOINTS_SAFE (b
, temp
)
7651 if (b
->type
!= bp_call_dummy
7652 && b
->type
!= bp_shlib_event
7653 && b
->type
!= bp_thread_event
7654 && b
->type
!= bp_overlay_event
7655 && b
->type
!= bp_longjmp_master
7657 delete_breakpoint (b
);
7662 map_breakpoint_numbers (arg
, delete_breakpoint
);
7666 all_locations_are_pending (struct bp_location
*loc
)
7668 for (; loc
; loc
= loc
->next
)
7669 if (!loc
->shlib_disabled
)
7674 /* Subroutine of update_breakpoint_locations to simplify it.
7675 Return non-zero if multiple fns in list LOC have the same name.
7676 Null names are ignored. */
7679 ambiguous_names_p (struct bp_location
*loc
)
7681 struct bp_location
*l
;
7682 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7683 (int (*) (const void *, const void *)) streq
,
7684 NULL
, xcalloc
, xfree
);
7686 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7689 const char *name
= l
->function_name
;
7691 /* Allow for some names to be NULL, ignore them. */
7695 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7697 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7712 update_breakpoint_locations (struct breakpoint
*b
,
7713 struct symtabs_and_lines sals
)
7717 struct bp_location
*existing_locations
= b
->loc
;
7719 /* If there's no new locations, and all existing locations
7720 are pending, don't do anything. This optimizes
7721 the common case where all locations are in the same
7722 shared library, that was unloaded. We'd like to
7723 retain the location, so that when the library
7724 is loaded again, we don't loose the enabled/disabled
7725 status of the individual locations. */
7726 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7731 for (i
= 0; i
< sals
.nelts
; ++i
)
7733 struct bp_location
*new_loc
=
7734 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
7736 /* Reparse conditions, they might contain references to the
7738 if (b
->cond_string
!= NULL
)
7740 struct gdb_exception e
;
7743 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7745 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7750 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7751 b
->number
, e
.message
);
7752 new_loc
->enabled
= 0;
7756 if (b
->source_file
!= NULL
)
7757 xfree (b
->source_file
);
7758 if (sals
.sals
[i
].symtab
== NULL
)
7759 b
->source_file
= NULL
;
7761 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
7763 if (b
->line_number
== 0)
7764 b
->line_number
= sals
.sals
[i
].line
;
7767 /* Update locations of permanent breakpoints. */
7768 if (b
->enable_state
== bp_permanent
)
7769 make_breakpoint_permanent (b
);
7771 /* If possible, carry over 'disable' status from existing breakpoints. */
7773 struct bp_location
*e
= existing_locations
;
7774 /* If there are multiple breakpoints with the same function name,
7775 e.g. for inline functions, comparing function names won't work.
7776 Instead compare pc addresses; this is just a heuristic as things
7777 may have moved, but in practice it gives the correct answer
7778 often enough until a better solution is found. */
7779 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7781 for (; e
; e
= e
->next
)
7783 if (!e
->enabled
&& e
->function_name
)
7785 struct bp_location
*l
= b
->loc
;
7786 if (have_ambiguous_names
)
7788 for (; l
; l
= l
->next
)
7789 if (e
->address
== l
->address
)
7797 for (; l
; l
= l
->next
)
7798 if (l
->function_name
7799 && strcmp (e
->function_name
, l
->function_name
) == 0)
7809 update_global_location_list (1);
7813 /* Reset a breakpoint given it's struct breakpoint * BINT.
7814 The value we return ends up being the return value from catch_errors.
7815 Unused in this case. */
7818 breakpoint_re_set_one (void *bint
)
7820 /* get past catch_errs */
7821 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7825 int *not_found_ptr
= ¬_found
;
7826 struct symtabs_and_lines sals
= {};
7827 struct symtabs_and_lines expanded
;
7829 enum enable_state save_enable
;
7830 struct gdb_exception e
;
7831 struct cleanup
*cleanups
;
7836 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7840 case bp_hardware_breakpoint
:
7842 /* Do not attempt to re-set breakpoints disabled during startup. */
7843 if (b
->enable_state
== bp_startup_disabled
)
7846 if (b
->addr_string
== NULL
)
7848 /* Anything without a string can't be re-set. */
7849 delete_breakpoint (b
);
7853 set_language (b
->language
);
7854 input_radix
= b
->input_radix
;
7856 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7858 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7863 int not_found_and_ok
= 0;
7864 /* For pending breakpoints, it's expected that parsing
7865 will fail until the right shared library is loaded.
7866 User has already told to create pending breakpoints and
7867 don't need extra messages. If breakpoint is in bp_shlib_disabled
7868 state, then user already saw the message about that breakpoint
7869 being disabled, and don't want to see more errors. */
7871 && (b
->condition_not_parsed
7872 || (b
->loc
&& b
->loc
->shlib_disabled
)
7873 || b
->enable_state
== bp_disabled
))
7874 not_found_and_ok
= 1;
7876 if (!not_found_and_ok
)
7878 /* We surely don't want to warn about the same breakpoint
7879 10 times. One solution, implemented here, is disable
7880 the breakpoint on error. Another solution would be to
7881 have separate 'warning emitted' flag. Since this
7882 happens only when a binary has changed, I don't know
7883 which approach is better. */
7884 b
->enable_state
= bp_disabled
;
7885 throw_exception (e
);
7892 gdb_assert (sals
.nelts
== 1);
7893 resolve_sal_pc (&sals
.sals
[0]);
7894 if (b
->condition_not_parsed
&& s
&& s
[0])
7896 char *cond_string
= 0;
7900 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7901 &cond_string
, &thread
, &task
);
7903 b
->cond_string
= cond_string
;
7906 b
->condition_not_parsed
= 0;
7908 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7909 cleanups
= make_cleanup (xfree
, sals
.sals
);
7910 update_breakpoint_locations (b
, expanded
);
7911 do_cleanups (cleanups
);
7915 case bp_hardware_watchpoint
:
7916 case bp_read_watchpoint
:
7917 case bp_access_watchpoint
:
7918 /* Watchpoint can be either on expression using entirely global variables,
7919 or it can be on local variables.
7921 Watchpoints of the first kind are never auto-deleted, and even persist
7922 across program restarts. Since they can use variables from shared
7923 libraries, we need to reparse expression as libraries are loaded
7926 Watchpoints on local variables can also change meaning as result
7927 of solib event. For example, if a watchpoint uses both a local and
7928 a global variables in expression, it's a local watchpoint, but
7929 unloading of a shared library will make the expression invalid.
7930 This is not a very common use case, but we still re-evaluate
7931 expression, to avoid surprises to the user.
7933 Note that for local watchpoints, we re-evaluate it only if
7934 watchpoints frame id is still valid. If it's not, it means
7935 the watchpoint is out of scope and will be deleted soon. In fact,
7936 I'm not sure we'll ever be called in this case.
7938 If a local watchpoint's frame id is still valid, then
7939 b->exp_valid_block is likewise valid, and we can safely use it.
7941 Don't do anything about disabled watchpoints, since they will
7942 be reevaluated again when enabled. */
7943 update_watchpoint (b
, 1 /* reparse */);
7945 /* We needn't really do anything to reset these, since the mask
7946 that requests them is unaffected by e.g., new libraries being
7952 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7954 /* Delete overlay event and longjmp master breakpoints; they will be
7955 reset later by breakpoint_re_set. */
7956 case bp_overlay_event
:
7957 case bp_longjmp_master
:
7958 delete_breakpoint (b
);
7961 /* This breakpoint is special, it's set up when the inferior
7962 starts and we really don't want to touch it. */
7963 case bp_shlib_event
:
7965 /* Like bp_shlib_event, this breakpoint type is special.
7966 Once it is set up, we do not want to touch it. */
7967 case bp_thread_event
:
7969 /* Keep temporary breakpoints, which can be encountered when we step
7970 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7971 Otherwise these should have been blown away via the cleanup chain
7972 or by breakpoint_init_inferior when we rerun the executable. */
7975 case bp_watchpoint_scope
:
7977 case bp_step_resume
:
7979 case bp_longjmp_resume
:
7986 /* Re-set all breakpoints after symbols have been re-loaded. */
7988 breakpoint_re_set (void)
7990 struct breakpoint
*b
, *temp
;
7991 enum language save_language
;
7992 int save_input_radix
;
7994 save_language
= current_language
->la_language
;
7995 save_input_radix
= input_radix
;
7996 ALL_BREAKPOINTS_SAFE (b
, temp
)
7998 /* Format possible error msg */
7999 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
8001 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
8002 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
8003 do_cleanups (cleanups
);
8005 set_language (save_language
);
8006 input_radix
= save_input_radix
;
8008 create_overlay_event_breakpoint ("_ovly_debug_event");
8009 create_longjmp_master_breakpoint ("longjmp");
8010 create_longjmp_master_breakpoint ("_longjmp");
8011 create_longjmp_master_breakpoint ("siglongjmp");
8012 create_longjmp_master_breakpoint ("_siglongjmp");
8015 /* Reset the thread number of this breakpoint:
8017 - If the breakpoint is for all threads, leave it as-is.
8018 - Else, reset it to the current thread for inferior_ptid. */
8020 breakpoint_re_set_thread (struct breakpoint
*b
)
8022 if (b
->thread
!= -1)
8024 if (in_thread_list (inferior_ptid
))
8025 b
->thread
= pid_to_thread_id (inferior_ptid
);
8029 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
8030 If from_tty is nonzero, it prints a message to that effect,
8031 which ends with a period (no newline). */
8034 set_ignore_count (int bptnum
, int count
, int from_tty
)
8036 struct breakpoint
*b
;
8042 if (b
->number
== bptnum
)
8044 b
->ignore_count
= count
;
8048 printf_filtered (_("Will stop next time breakpoint %d is reached."),
8050 else if (count
== 1)
8051 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
8054 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
8057 breakpoints_changed ();
8058 observer_notify_breakpoint_modified (b
->number
);
8062 error (_("No breakpoint number %d."), bptnum
);
8066 make_breakpoint_silent (struct breakpoint
*b
)
8068 /* Silence the breakpoint. */
8072 /* Command to set ignore-count of breakpoint N to COUNT. */
8075 ignore_command (char *args
, int from_tty
)
8081 error_no_arg (_("a breakpoint number"));
8083 num
= get_number (&p
);
8085 error (_("bad breakpoint number: '%s'"), args
);
8087 error (_("Second argument (specified ignore-count) is missing."));
8089 set_ignore_count (num
,
8090 longest_to_int (value_as_long (parse_and_eval (p
))),
8093 printf_filtered ("\n");
8096 /* Call FUNCTION on each of the breakpoints
8097 whose numbers are given in ARGS. */
8100 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
8105 struct breakpoint
*b
, *tmp
;
8109 error_no_arg (_("one or more breakpoint numbers"));
8116 num
= get_number_or_range (&p1
);
8119 warning (_("bad breakpoint number at or near '%s'"), p
);
8123 ALL_BREAKPOINTS_SAFE (b
, tmp
)
8124 if (b
->number
== num
)
8126 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
8129 if (related_breakpoint
)
8130 function (related_breakpoint
);
8134 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
8140 static struct bp_location
*
8141 find_location_by_number (char *number
)
8143 char *dot
= strchr (number
, '.');
8147 struct breakpoint
*b
;
8148 struct bp_location
*loc
;
8153 bp_num
= get_number_or_range (&p1
);
8155 error (_("Bad breakpoint number '%s'"), number
);
8158 if (b
->number
== bp_num
)
8163 if (!b
|| b
->number
!= bp_num
)
8164 error (_("Bad breakpoint number '%s'"), number
);
8167 loc_num
= get_number_or_range (&p1
);
8169 error (_("Bad breakpoint location number '%s'"), number
);
8173 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
8176 error (_("Bad breakpoint location number '%s'"), dot
+1);
8182 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
8183 If from_tty is nonzero, it prints a message to that effect,
8184 which ends with a period (no newline). */
8187 disable_breakpoint (struct breakpoint
*bpt
)
8189 /* Never disable a watchpoint scope breakpoint; we want to
8190 hit them when we leave scope so we can delete both the
8191 watchpoint and its scope breakpoint at that time. */
8192 if (bpt
->type
== bp_watchpoint_scope
)
8195 /* You can't disable permanent breakpoints. */
8196 if (bpt
->enable_state
== bp_permanent
)
8199 bpt
->enable_state
= bp_disabled
;
8201 update_global_location_list (0);
8203 observer_notify_breakpoint_modified (bpt
->number
);
8207 disable_command (char *args
, int from_tty
)
8209 struct breakpoint
*bpt
;
8211 ALL_BREAKPOINTS (bpt
)
8215 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
8221 case bp_hardware_breakpoint
:
8223 case bp_hardware_watchpoint
:
8224 case bp_read_watchpoint
:
8225 case bp_access_watchpoint
:
8226 disable_breakpoint (bpt
);
8230 else if (strchr (args
, '.'))
8232 struct bp_location
*loc
= find_location_by_number (args
);
8235 update_global_location_list (0);
8238 map_breakpoint_numbers (args
, disable_breakpoint
);
8242 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
8244 int target_resources_ok
, other_type_used
;
8247 if (bpt
->type
== bp_hardware_breakpoint
)
8250 i
= hw_breakpoint_used_count ();
8251 target_resources_ok
=
8252 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8254 if (target_resources_ok
== 0)
8255 error (_("No hardware breakpoint support in the target."));
8256 else if (target_resources_ok
< 0)
8257 error (_("Hardware breakpoints used exceeds limit."));
8260 if (bpt
->type
== bp_watchpoint
8261 || bpt
->type
== bp_hardware_watchpoint
8262 || bpt
->type
== bp_read_watchpoint
8263 || bpt
->type
== bp_access_watchpoint
)
8265 struct gdb_exception e
;
8267 TRY_CATCH (e
, RETURN_MASK_ALL
)
8269 update_watchpoint (bpt
, 1 /* reparse */);
8273 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
8279 if (bpt
->enable_state
!= bp_permanent
)
8280 bpt
->enable_state
= bp_enabled
;
8281 bpt
->disposition
= disposition
;
8282 update_global_location_list (1);
8283 breakpoints_changed ();
8285 observer_notify_breakpoint_modified (bpt
->number
);
8290 enable_breakpoint (struct breakpoint
*bpt
)
8292 do_enable_breakpoint (bpt
, bpt
->disposition
);
8295 /* The enable command enables the specified breakpoints (or all defined
8296 breakpoints) so they once again become (or continue to be) effective
8297 in stopping the inferior. */
8300 enable_command (char *args
, int from_tty
)
8302 struct breakpoint
*bpt
;
8304 ALL_BREAKPOINTS (bpt
)
8308 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8314 case bp_hardware_breakpoint
:
8316 case bp_hardware_watchpoint
:
8317 case bp_read_watchpoint
:
8318 case bp_access_watchpoint
:
8319 enable_breakpoint (bpt
);
8323 else if (strchr (args
, '.'))
8325 struct bp_location
*loc
= find_location_by_number (args
);
8328 update_global_location_list (1);
8331 map_breakpoint_numbers (args
, enable_breakpoint
);
8335 enable_once_breakpoint (struct breakpoint
*bpt
)
8337 do_enable_breakpoint (bpt
, disp_disable
);
8341 enable_once_command (char *args
, int from_tty
)
8343 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8347 enable_delete_breakpoint (struct breakpoint
*bpt
)
8349 do_enable_breakpoint (bpt
, disp_del
);
8353 enable_delete_command (char *args
, int from_tty
)
8355 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8359 set_breakpoint_cmd (char *args
, int from_tty
)
8364 show_breakpoint_cmd (char *args
, int from_tty
)
8368 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8370 struct symtabs_and_lines
8371 decode_line_spec_1 (char *string
, int funfirstline
)
8373 struct symtabs_and_lines sals
;
8375 error (_("Empty line specification."));
8376 if (default_breakpoint_valid
)
8377 sals
= decode_line_1 (&string
, funfirstline
,
8378 default_breakpoint_symtab
,
8379 default_breakpoint_line
,
8380 (char ***) NULL
, NULL
);
8382 sals
= decode_line_1 (&string
, funfirstline
,
8383 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8385 error (_("Junk at end of line specification: %s"), string
);
8389 /* Create and insert a raw software breakpoint at PC. Return an
8390 identifier, which should be used to remove the breakpoint later.
8391 In general, places which call this should be using something on the
8392 breakpoint chain instead; this function should be eliminated
8396 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
8398 struct bp_target_info
*bp_tgt
;
8400 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8401 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8403 bp_tgt
->placed_address
= pc
;
8404 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
8406 /* Could not insert the breakpoint. */
8414 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8417 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
8419 struct bp_target_info
*bp_tgt
= bp
;
8422 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
8428 /* One (or perhaps two) breakpoints used for software single stepping. */
8430 static void *single_step_breakpoints
[2];
8431 static struct gdbarch
*single_step_gdbarch
[2];
8433 /* Create and insert a breakpoint for software single step. */
8436 insert_single_step_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR next_pc
)
8440 if (single_step_breakpoints
[0] == NULL
)
8442 bpt_p
= &single_step_breakpoints
[0];
8443 single_step_gdbarch
[0] = gdbarch
;
8447 gdb_assert (single_step_breakpoints
[1] == NULL
);
8448 bpt_p
= &single_step_breakpoints
[1];
8449 single_step_gdbarch
[1] = gdbarch
;
8452 /* NOTE drow/2006-04-11: A future improvement to this function would be
8453 to only create the breakpoints once, and actually put them on the
8454 breakpoint chain. That would let us use set_raw_breakpoint. We could
8455 adjust the addresses each time they were needed. Doing this requires
8456 corresponding changes elsewhere where single step breakpoints are
8457 handled, however. So, for now, we use this. */
8459 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, next_pc
);
8461 error (_("Could not insert single-step breakpoint at %s"),
8462 paddress (gdbarch
, next_pc
));
8465 /* Remove and delete any breakpoints used for software single step. */
8468 remove_single_step_breakpoints (void)
8470 gdb_assert (single_step_breakpoints
[0] != NULL
);
8472 /* See insert_single_step_breakpoint for more about this deprecated
8474 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
8475 single_step_breakpoints
[0]);
8476 single_step_gdbarch
[0] = NULL
;
8477 single_step_breakpoints
[0] = NULL
;
8479 if (single_step_breakpoints
[1] != NULL
)
8481 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
8482 single_step_breakpoints
[1]);
8483 single_step_gdbarch
[1] = NULL
;
8484 single_step_breakpoints
[1] = NULL
;
8488 /* Check whether a software single-step breakpoint is inserted at PC. */
8491 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8495 for (i
= 0; i
< 2; i
++)
8497 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8498 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8505 /* Tracepoint-specific operations. */
8507 /* Set tracepoint count to NUM. */
8509 set_tracepoint_count (int num
)
8511 tracepoint_count
= num
;
8512 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
8516 trace_command (char *arg
, int from_tty
)
8518 break_command_really (get_current_arch (),
8520 NULL
, 0, 1 /* parse arg */,
8521 0 /* tempflag */, 0 /* hardwareflag */,
8523 0 /* Ignore count */,
8524 pending_break_support
,
8528 set_tracepoint_count (breakpoint_count
);
8531 /* Print information on tracepoint number TPNUM_EXP, or all if
8535 tracepoints_info (char *tpnum_exp
, int from_tty
)
8537 struct breakpoint
*b
;
8538 int tps_to_list
= 0;
8540 /* In the no-arguments case, say "No tracepoints" if none found. */
8553 ui_out_message (uiout
, 0, "No tracepoints.\n");
8558 /* Otherwise be the same as "info break". */
8559 breakpoints_info (tpnum_exp
, from_tty
);
8562 /* The 'enable trace' command enables tracepoints.
8563 Not supported by all targets. */
8565 enable_trace_command (char *args
, int from_tty
)
8567 enable_command (args
, from_tty
);
8570 /* The 'disable trace' command disables tracepoints.
8571 Not supported by all targets. */
8573 disable_trace_command (char *args
, int from_tty
)
8575 disable_command (args
, from_tty
);
8578 /* Remove a tracepoint (or all if no argument) */
8580 delete_trace_command (char *arg
, int from_tty
)
8582 struct breakpoint
*b
, *temp
;
8588 int breaks_to_delete
= 0;
8590 /* Delete all breakpoints if no argument.
8591 Do not delete internal or call-dummy breakpoints, these
8592 have to be deleted with an explicit breakpoint number argument. */
8597 breaks_to_delete
= 1;
8602 /* Ask user only if there are some breakpoints to delete. */
8604 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
8606 ALL_BREAKPOINTS_SAFE (b
, temp
)
8608 if (b
->type
== bp_tracepoint
8610 delete_breakpoint (b
);
8615 map_breakpoint_numbers (arg
, delete_breakpoint
);
8618 /* Set passcount for tracepoint.
8620 First command argument is passcount, second is tracepoint number.
8621 If tracepoint number omitted, apply to most recently defined.
8622 Also accepts special argument "all". */
8625 trace_pass_command (char *args
, int from_tty
)
8627 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
8631 if (args
== 0 || *args
== 0)
8632 error (_("passcount command requires an argument (count + optional TP num)"));
8634 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
8636 while (*args
&& isspace ((int) *args
))
8639 if (*args
&& strncasecmp (args
, "all", 3) == 0)
8641 args
+= 3; /* Skip special argument "all". */
8644 error (_("Junk at end of arguments."));
8647 t1
= get_tracepoint_by_number (&args
, 1, 1);
8653 ALL_TRACEPOINTS (t2
)
8654 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
8656 t2
->pass_count
= count
;
8657 observer_notify_tracepoint_modified (t2
->number
);
8659 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
8663 t1
= get_tracepoint_by_number (&args
, 1, 0);
8670 get_tracepoint (int num
)
8672 struct breakpoint
*t
;
8675 if (t
->number
== num
)
8681 /* Utility: parse a tracepoint number and look it up in the list.
8682 If MULTI_P is true, there might be a range of tracepoints in ARG.
8683 if OPTIONAL_P is true, then if the argument is missing, the most
8684 recent tracepoint (tracepoint_count) is returned. */
8686 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
8688 extern int tracepoint_count
;
8689 struct breakpoint
*t
;
8691 char *instring
= arg
== NULL
? NULL
: *arg
;
8693 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
8696 tpnum
= tracepoint_count
;
8698 error_no_arg (_("tracepoint number"));
8701 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
8705 if (instring
&& *instring
)
8706 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
8709 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
8714 if (t
->number
== tpnum
)
8719 /* FIXME: if we are in the middle of a range we don't want to give
8720 a message. The current interface to get_number_or_range doesn't
8721 allow us to discover this. */
8722 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
8726 /* save-tracepoints command */
8728 tracepoint_save_command (char *args
, int from_tty
)
8730 struct breakpoint
*tp
;
8732 struct action_line
*line
;
8734 char *i1
= " ", *i2
= " ";
8735 char *indent
, *actionline
, *pathname
;
8737 struct cleanup
*cleanup
;
8739 if (args
== 0 || *args
== 0)
8740 error (_("Argument required (file name in which to save tracepoints)"));
8742 /* See if we have anything to save. */
8743 ALL_TRACEPOINTS (tp
)
8750 warning (_("save-tracepoints: no tracepoints to save."));
8754 pathname
= tilde_expand (args
);
8755 cleanup
= make_cleanup (xfree
, pathname
);
8756 fp
= fopen (pathname
, "w");
8758 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
8759 args
, safe_strerror (errno
));
8760 make_cleanup_fclose (fp
);
8762 ALL_TRACEPOINTS (tp
)
8764 if (tp
->addr_string
)
8765 fprintf (fp
, "trace %s\n", tp
->addr_string
);
8768 sprintf_vma (tmp
, tp
->loc
->address
);
8769 fprintf (fp
, "trace *0x%s\n", tmp
);
8773 fprintf (fp
, " passcount %d\n", tp
->pass_count
);
8777 fprintf (fp
, " actions\n");
8779 for (line
= tp
->actions
; line
; line
= line
->next
)
8781 struct cmd_list_element
*cmd
;
8783 QUIT
; /* allow user to bail out with ^C */
8784 actionline
= line
->action
;
8785 while (isspace ((int) *actionline
))
8788 fprintf (fp
, "%s%s\n", indent
, actionline
);
8789 if (*actionline
!= '#') /* skip for comment lines */
8791 cmd
= lookup_cmd (&actionline
, cmdlist
, "", -1, 1);
8793 error (_("Bad action list item: %s"), actionline
);
8794 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
8796 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
8802 do_cleanups (cleanup
);
8804 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
8808 /* Create a vector of all tracepoints. */
8813 VEC(breakpoint_p
) *tp_vec
= 0;
8814 struct breakpoint
*tp
;
8816 ALL_TRACEPOINTS (tp
)
8818 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
8825 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8826 It is defined as a macro to prevent duplication.
8827 COMMAND should be a string constant containing the name of the command. */
8828 #define BREAK_ARGS_HELP(command) \
8829 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8830 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8831 If a line number is specified, break at start of code for that line.\n\
8832 If a function is specified, break at start of code for that function.\n\
8833 If an address is specified, break at that exact address.\n\
8834 With no LOCATION, uses current execution address of selected stack frame.\n\
8835 This is useful for breaking on return to a stack frame.\n\
8837 THREADNUM is the number from \"info threads\".\n\
8838 CONDITION is a boolean expression.\n\
8840 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8842 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8844 /* List of subcommands for "catch". */
8845 static struct cmd_list_element
*catch_cmdlist
;
8847 /* List of subcommands for "tcatch". */
8848 static struct cmd_list_element
*tcatch_cmdlist
;
8850 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8851 lists, and pass some additional user data to the command function. */
8853 add_catch_command (char *name
, char *docstring
,
8854 void (*sfunc
) (char *args
, int from_tty
,
8855 struct cmd_list_element
*command
),
8856 void *user_data_catch
,
8857 void *user_data_tcatch
)
8859 struct cmd_list_element
*command
;
8861 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8863 set_cmd_sfunc (command
, sfunc
);
8864 set_cmd_context (command
, user_data_catch
);
8866 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8868 set_cmd_sfunc (command
, sfunc
);
8869 set_cmd_context (command
, user_data_tcatch
);
8873 _initialize_breakpoint (void)
8875 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8876 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8877 struct cmd_list_element
*c
;
8879 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8881 breakpoint_chain
= 0;
8882 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8883 before a breakpoint is set. */
8884 breakpoint_count
= 0;
8886 tracepoint_count
= 0;
8888 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8889 Set ignore-count of breakpoint number N to COUNT.\n\
8890 Usage is `ignore N COUNT'."));
8892 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8894 add_com ("commands", class_breakpoint
, commands_command
, _("\
8895 Set commands to be executed when a breakpoint is hit.\n\
8896 Give breakpoint number as argument after \"commands\".\n\
8897 With no argument, the targeted breakpoint is the last one set.\n\
8898 The commands themselves follow starting on the next line.\n\
8899 Type a line containing \"end\" to indicate the end of them.\n\
8900 Give \"silent\" as the first line to make the breakpoint silent;\n\
8901 then no output is printed when it is hit, except what the commands print."));
8903 add_com ("condition", class_breakpoint
, condition_command
, _("\
8904 Specify breakpoint number N to break only if COND is true.\n\
8905 Usage is `condition N COND', where N is an integer and COND is an\n\
8906 expression to be evaluated whenever breakpoint N is reached."));
8908 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8909 Set a temporary breakpoint.\n\
8910 Like \"break\" except the breakpoint is only temporary,\n\
8911 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8912 by using \"enable delete\" on the breakpoint number.\n\
8914 BREAK_ARGS_HELP ("tbreak")));
8915 set_cmd_completer (c
, location_completer
);
8917 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8918 Set a hardware assisted breakpoint.\n\
8919 Like \"break\" except the breakpoint requires hardware support,\n\
8920 some target hardware may not have this support.\n\
8922 BREAK_ARGS_HELP ("hbreak")));
8923 set_cmd_completer (c
, location_completer
);
8925 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8926 Set a temporary hardware assisted breakpoint.\n\
8927 Like \"hbreak\" except the breakpoint is only temporary,\n\
8928 so it will be deleted when hit.\n\
8930 BREAK_ARGS_HELP ("thbreak")));
8931 set_cmd_completer (c
, location_completer
);
8933 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8934 Enable some breakpoints.\n\
8935 Give breakpoint numbers (separated by spaces) as arguments.\n\
8936 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8937 This is used to cancel the effect of the \"disable\" command.\n\
8938 With a subcommand you can enable temporarily."),
8939 &enablelist
, "enable ", 1, &cmdlist
);
8941 add_com ("ab", class_breakpoint
, enable_command
, _("\
8942 Enable some breakpoints.\n\
8943 Give breakpoint numbers (separated by spaces) as arguments.\n\
8944 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8945 This is used to cancel the effect of the \"disable\" command.\n\
8946 With a subcommand you can enable temporarily."));
8948 add_com_alias ("en", "enable", class_breakpoint
, 1);
8950 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8951 Enable some breakpoints.\n\
8952 Give breakpoint numbers (separated by spaces) as arguments.\n\
8953 This is used to cancel the effect of the \"disable\" command.\n\
8954 May be abbreviated to simply \"enable\".\n"),
8955 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8957 add_cmd ("once", no_class
, enable_once_command
, _("\
8958 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8959 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8962 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8963 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8964 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8967 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8968 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8969 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8972 add_cmd ("once", no_class
, enable_once_command
, _("\
8973 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8974 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8977 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8978 Disable some breakpoints.\n\
8979 Arguments are breakpoint numbers with spaces in between.\n\
8980 To disable all breakpoints, give no argument.\n\
8981 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8982 &disablelist
, "disable ", 1, &cmdlist
);
8983 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8984 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8986 add_com ("sb", class_breakpoint
, disable_command
, _("\
8987 Disable some breakpoints.\n\
8988 Arguments are breakpoint numbers with spaces in between.\n\
8989 To disable all breakpoints, give no argument.\n\
8990 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8992 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8993 Disable some breakpoints.\n\
8994 Arguments are breakpoint numbers with spaces in between.\n\
8995 To disable all breakpoints, give no argument.\n\
8996 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8997 This command may be abbreviated \"disable\"."),
9000 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
9001 Delete some breakpoints or auto-display expressions.\n\
9002 Arguments are breakpoint numbers with spaces in between.\n\
9003 To delete all breakpoints, give no argument.\n\
9005 Also a prefix command for deletion of other GDB objects.\n\
9006 The \"unset\" command is also an alias for \"delete\"."),
9007 &deletelist
, "delete ", 1, &cmdlist
);
9008 add_com_alias ("d", "delete", class_breakpoint
, 1);
9009 add_com_alias ("del", "delete", class_breakpoint
, 1);
9011 add_com ("db", class_breakpoint
, delete_command
, _("\
9012 Delete some breakpoints.\n\
9013 Arguments are breakpoint numbers with spaces in between.\n\
9014 To delete all breakpoints, give no argument.\n"));
9016 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
9017 Delete some breakpoints or auto-display expressions.\n\
9018 Arguments are breakpoint numbers with spaces in between.\n\
9019 To delete all breakpoints, give no argument.\n\
9020 This command may be abbreviated \"delete\"."),
9023 add_com ("clear", class_breakpoint
, clear_command
, _("\
9024 Clear breakpoint at specified line or function.\n\
9025 Argument may be line number, function name, or \"*\" and an address.\n\
9026 If line number is specified, all breakpoints in that line are cleared.\n\
9027 If function is specified, breakpoints at beginning of function are cleared.\n\
9028 If an address is specified, breakpoints at that address are cleared.\n\
9030 With no argument, clears all breakpoints in the line that the selected frame\n\
9033 See also the \"delete\" command which clears breakpoints by number."));
9035 c
= add_com ("break", class_breakpoint
, break_command
, _("\
9036 Set breakpoint at specified line or function.\n"
9037 BREAK_ARGS_HELP ("break")));
9038 set_cmd_completer (c
, location_completer
);
9040 add_com_alias ("b", "break", class_run
, 1);
9041 add_com_alias ("br", "break", class_run
, 1);
9042 add_com_alias ("bre", "break", class_run
, 1);
9043 add_com_alias ("brea", "break", class_run
, 1);
9046 add_com_alias ("ba", "break", class_breakpoint
, 1);
9050 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
9051 Break in function/address or break at a line in the current file."),
9052 &stoplist
, "stop ", 1, &cmdlist
);
9053 add_cmd ("in", class_breakpoint
, stopin_command
,
9054 _("Break in function or address."), &stoplist
);
9055 add_cmd ("at", class_breakpoint
, stopat_command
,
9056 _("Break at a line in the current file."), &stoplist
);
9057 add_com ("status", class_info
, breakpoints_info
, _("\
9058 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9059 The \"Type\" column indicates one of:\n\
9060 \tbreakpoint - normal breakpoint\n\
9061 \twatchpoint - watchpoint\n\
9062 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9063 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9064 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9065 address and file/line number respectively.\n\
9067 Convenience variable \"$_\" and default examine address for \"x\"\n\
9068 are set to the address of the last breakpoint listed unless the command\n\
9069 is prefixed with \"server \".\n\n\
9070 Convenience variable \"$bpnum\" contains the number of the last\n\
9074 add_info ("breakpoints", breakpoints_info
, _("\
9075 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9076 The \"Type\" column indicates one of:\n\
9077 \tbreakpoint - normal breakpoint\n\
9078 \twatchpoint - watchpoint\n\
9079 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9080 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9081 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9082 address and file/line number respectively.\n\
9084 Convenience variable \"$_\" and default examine address for \"x\"\n\
9085 are set to the address of the last breakpoint listed unless the command\n\
9086 is prefixed with \"server \".\n\n\
9087 Convenience variable \"$bpnum\" contains the number of the last\n\
9091 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
9092 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9093 The \"Type\" column indicates one of:\n\
9094 \tbreakpoint - normal breakpoint\n\
9095 \twatchpoint - watchpoint\n\
9096 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9097 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9098 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9099 address and file/line number respectively.\n\
9101 Convenience variable \"$_\" and default examine address for \"x\"\n\
9102 are set to the address of the last breakpoint listed unless the command\n\
9103 is prefixed with \"server \".\n\n\
9104 Convenience variable \"$bpnum\" contains the number of the last\n\
9107 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
9108 Status of all breakpoints, or breakpoint number NUMBER.\n\
9109 The \"Type\" column indicates one of:\n\
9110 \tbreakpoint - normal breakpoint\n\
9111 \twatchpoint - watchpoint\n\
9112 \tlongjmp - internal breakpoint used to step through longjmp()\n\
9113 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
9114 \tuntil - internal breakpoint used by the \"until\" command\n\
9115 \tfinish - internal breakpoint used by the \"finish\" command\n\
9116 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9117 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9118 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9119 address and file/line number respectively.\n\
9121 Convenience variable \"$_\" and default examine address for \"x\"\n\
9122 are set to the address of the last breakpoint listed unless the command\n\
9123 is prefixed with \"server \".\n\n\
9124 Convenience variable \"$bpnum\" contains the number of the last\n\
9126 &maintenanceinfolist
);
9128 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
9129 Set catchpoints to catch events."),
9130 &catch_cmdlist
, "catch ",
9131 0/*allow-unknown*/, &cmdlist
);
9133 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
9134 Set temporary catchpoints to catch events."),
9135 &tcatch_cmdlist
, "tcatch ",
9136 0/*allow-unknown*/, &cmdlist
);
9138 /* Add catch and tcatch sub-commands. */
9139 add_catch_command ("catch", _("\
9140 Catch an exception, when caught.\n\
9141 With an argument, catch only exceptions with the given name."),
9142 catch_catch_command
,
9145 add_catch_command ("throw", _("\
9146 Catch an exception, when thrown.\n\
9147 With an argument, catch only exceptions with the given name."),
9148 catch_throw_command
,
9151 add_catch_command ("fork", _("Catch calls to fork."),
9152 catch_fork_command_1
,
9153 (void *) (uintptr_t) catch_fork_permanent
,
9154 (void *) (uintptr_t) catch_fork_temporary
);
9155 add_catch_command ("vfork", _("Catch calls to vfork."),
9156 catch_fork_command_1
,
9157 (void *) (uintptr_t) catch_vfork_permanent
,
9158 (void *) (uintptr_t) catch_vfork_temporary
);
9159 add_catch_command ("exec", _("Catch calls to exec."),
9160 catch_exec_command_1
,
9163 add_catch_command ("exception", _("\
9164 Catch Ada exceptions, when raised.\n\
9165 With an argument, catch only exceptions with the given name."),
9166 catch_ada_exception_command
,
9169 add_catch_command ("assert", _("\
9170 Catch failed Ada assertions, when raised.\n\
9171 With an argument, catch only exceptions with the given name."),
9172 catch_assert_command
,
9176 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
9177 Set a watchpoint for an expression.\n\
9178 A watchpoint stops execution of your program whenever the value of\n\
9179 an expression changes."));
9180 set_cmd_completer (c
, expression_completer
);
9182 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
9183 Set a read watchpoint for an expression.\n\
9184 A watchpoint stops execution of your program whenever the value of\n\
9185 an expression is read."));
9186 set_cmd_completer (c
, expression_completer
);
9188 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
9189 Set a watchpoint for an expression.\n\
9190 A watchpoint stops execution of your program whenever the value of\n\
9191 an expression is either read or written."));
9192 set_cmd_completer (c
, expression_completer
);
9194 add_info ("watchpoints", breakpoints_info
,
9195 _("Synonym for ``info breakpoints''."));
9198 /* XXX: cagney/2005-02-23: This should be a boolean, and should
9199 respond to changes - contrary to the description. */
9200 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
9201 &can_use_hw_watchpoints
, _("\
9202 Set debugger's willingness to use watchpoint hardware."), _("\
9203 Show debugger's willingness to use watchpoint hardware."), _("\
9204 If zero, gdb will not use hardware for new watchpoints, even if\n\
9205 such is available. (However, any hardware watchpoints that were\n\
9206 created before setting this to nonzero, will continue to use watchpoint\n\
9209 show_can_use_hw_watchpoints
,
9210 &setlist
, &showlist
);
9212 can_use_hw_watchpoints
= 1;
9214 /* Tracepoint manipulation commands. */
9216 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
9217 Set a tracepoint at specified line or function.\n\
9219 BREAK_ARGS_HELP ("trace") "\n\
9220 Do \"help tracepoints\" for info on other tracepoint commands."));
9221 set_cmd_completer (c
, location_completer
);
9223 add_com_alias ("tp", "trace", class_alias
, 0);
9224 add_com_alias ("tr", "trace", class_alias
, 1);
9225 add_com_alias ("tra", "trace", class_alias
, 1);
9226 add_com_alias ("trac", "trace", class_alias
, 1);
9228 add_info ("tracepoints", tracepoints_info
, _("\
9229 Status of tracepoints, or tracepoint number NUMBER.\n\
9230 Convenience variable \"$tpnum\" contains the number of the\n\
9231 last tracepoint set."));
9233 add_info_alias ("tp", "tracepoints", 1);
9235 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
9236 Delete specified tracepoints.\n\
9237 Arguments are tracepoint numbers, separated by spaces.\n\
9238 No argument means delete all tracepoints."),
9241 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
9242 Disable specified tracepoints.\n\
9243 Arguments are tracepoint numbers, separated by spaces.\n\
9244 No argument means disable all tracepoints."),
9246 deprecate_cmd (c
, "disable");
9248 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
9249 Enable specified tracepoints.\n\
9250 Arguments are tracepoint numbers, separated by spaces.\n\
9251 No argument means enable all tracepoints."),
9253 deprecate_cmd (c
, "enable");
9255 add_com ("passcount", class_trace
, trace_pass_command
, _("\
9256 Set the passcount for a tracepoint.\n\
9257 The trace will end when the tracepoint has been passed 'count' times.\n\
9258 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
9259 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
9261 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
9262 Save current tracepoint definitions as a script.\n\
9263 Use the 'source' command in another debug session to restore them."));
9264 set_cmd_completer (c
, filename_completer
);
9266 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
9267 Breakpoint specific settings\n\
9268 Configure various breakpoint-specific variables such as\n\
9269 pending breakpoint behavior"),
9270 &breakpoint_set_cmdlist
, "set breakpoint ",
9271 0/*allow-unknown*/, &setlist
);
9272 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
9273 Breakpoint specific settings\n\
9274 Configure various breakpoint-specific variables such as\n\
9275 pending breakpoint behavior"),
9276 &breakpoint_show_cmdlist
, "show breakpoint ",
9277 0/*allow-unknown*/, &showlist
);
9279 add_setshow_auto_boolean_cmd ("pending", no_class
,
9280 &pending_break_support
, _("\
9281 Set debugger's behavior regarding pending breakpoints."), _("\
9282 Show debugger's behavior regarding pending breakpoints."), _("\
9283 If on, an unrecognized breakpoint location will cause gdb to create a\n\
9284 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
9285 an error. If auto, an unrecognized breakpoint location results in a\n\
9286 user-query to see if a pending breakpoint should be created."),
9288 show_pending_break_support
,
9289 &breakpoint_set_cmdlist
,
9290 &breakpoint_show_cmdlist
);
9292 pending_break_support
= AUTO_BOOLEAN_AUTO
;
9294 add_setshow_boolean_cmd ("auto-hw", no_class
,
9295 &automatic_hardware_breakpoints
, _("\
9296 Set automatic usage of hardware breakpoints."), _("\
9297 Show automatic usage of hardware breakpoints."), _("\
9298 If set, the debugger will automatically use hardware breakpoints for\n\
9299 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
9300 a warning will be emitted for such breakpoints."),
9302 show_automatic_hardware_breakpoints
,
9303 &breakpoint_set_cmdlist
,
9304 &breakpoint_show_cmdlist
);
9306 add_setshow_enum_cmd ("always-inserted", class_support
,
9307 always_inserted_enums
, &always_inserted_mode
, _("\
9308 Set mode for inserting breakpoints."), _("\
9309 Show mode for inserting breakpoints."), _("\
9310 When this mode is off, breakpoints are inserted in inferior when it is\n\
9311 resumed, and removed when execution stops. When this mode is on,\n\
9312 breakpoints are inserted immediately and removed only when the user\n\
9313 deletes the breakpoint. When this mode is auto (which is the default),\n\
9314 the behaviour depends on the non-stop setting (see help set non-stop).\n\
9315 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
9316 behaves as if always-inserted mode is on; if gdb is controlling the\n\
9317 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
9319 &show_always_inserted_mode
,
9320 &breakpoint_set_cmdlist
,
9321 &breakpoint_show_cmdlist
);
9323 automatic_hardware_breakpoints
= 1;
9325 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);