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
)
1418 val
= remove_breakpoint (b
, mark_uninserted
);
1427 remove_hw_watchpoints (void)
1429 struct bp_location
*b
;
1432 ALL_BP_LOCATIONS (b
)
1434 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1436 val
= remove_breakpoint (b
, mark_uninserted
);
1445 reattach_breakpoints (int pid
)
1447 struct bp_location
*b
;
1449 struct cleanup
*old_chain
= save_inferior_ptid ();
1450 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1451 int dummy1
= 0, dummy2
= 0;
1453 make_cleanup_ui_file_delete (tmp_error_stream
);
1455 inferior_ptid
= pid_to_ptid (pid
);
1456 ALL_BP_LOCATIONS (b
)
1461 val
= insert_bp_location (b
, tmp_error_stream
,
1465 do_cleanups (old_chain
);
1470 do_cleanups (old_chain
);
1474 static int internal_breakpoint_number
= -1;
1476 static struct breakpoint
*
1477 create_internal_breakpoint (struct gdbarch
*gdbarch
,
1478 CORE_ADDR address
, enum bptype type
)
1480 struct symtab_and_line sal
;
1481 struct breakpoint
*b
;
1483 init_sal (&sal
); /* initialize to zeroes */
1486 sal
.section
= find_pc_overlay (sal
.pc
);
1488 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
1489 b
->number
= internal_breakpoint_number
--;
1490 b
->disposition
= disp_donttouch
;
1496 create_overlay_event_breakpoint (char *func_name
)
1498 struct objfile
*objfile
;
1500 ALL_OBJFILES (objfile
)
1502 struct breakpoint
*b
;
1503 struct minimal_symbol
*m
;
1505 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1509 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1510 SYMBOL_VALUE_ADDRESS (m
),
1512 b
->addr_string
= xstrdup (func_name
);
1514 if (overlay_debugging
== ovly_auto
)
1516 b
->enable_state
= bp_enabled
;
1517 overlay_events_enabled
= 1;
1521 b
->enable_state
= bp_disabled
;
1522 overlay_events_enabled
= 0;
1525 update_global_location_list (1);
1529 create_longjmp_master_breakpoint (char *func_name
)
1531 struct objfile
*objfile
;
1533 ALL_OBJFILES (objfile
)
1535 struct breakpoint
*b
;
1536 struct minimal_symbol
*m
;
1538 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
1541 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1545 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1546 SYMBOL_VALUE_ADDRESS (m
),
1548 b
->addr_string
= xstrdup (func_name
);
1549 b
->enable_state
= bp_disabled
;
1551 update_global_location_list (1);
1555 update_breakpoints_after_exec (void)
1557 struct breakpoint
*b
;
1558 struct breakpoint
*temp
;
1559 struct bp_location
*bploc
;
1561 /* We're about to delete breakpoints from GDB's lists. If the
1562 INSERTED flag is true, GDB will try to lift the breakpoints by
1563 writing the breakpoints' "shadow contents" back into memory. The
1564 "shadow contents" are NOT valid after an exec, so GDB should not
1565 do that. Instead, the target is responsible from marking
1566 breakpoints out as soon as it detects an exec. We don't do that
1567 here instead, because there may be other attempts to delete
1568 breakpoints after detecting an exec and before reaching here. */
1569 ALL_BP_LOCATIONS (bploc
)
1570 gdb_assert (!bploc
->inserted
);
1572 ALL_BREAKPOINTS_SAFE (b
, temp
)
1574 /* Solib breakpoints must be explicitly reset after an exec(). */
1575 if (b
->type
== bp_shlib_event
)
1577 delete_breakpoint (b
);
1581 /* Thread event breakpoints must be set anew after an exec(),
1582 as must overlay event and longjmp master breakpoints. */
1583 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
1584 || b
->type
== bp_longjmp_master
)
1586 delete_breakpoint (b
);
1590 /* Step-resume breakpoints are meaningless after an exec(). */
1591 if (b
->type
== bp_step_resume
)
1593 delete_breakpoint (b
);
1597 /* Longjmp and longjmp-resume breakpoints are also meaningless
1599 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1601 delete_breakpoint (b
);
1605 if (b
->type
== bp_catchpoint
)
1607 /* For now, none of the bp_catchpoint breakpoints need to
1608 do anything at this point. In the future, if some of
1609 the catchpoints need to something, we will need to add
1610 a new method, and call this method from here. */
1614 /* bp_finish is a special case. The only way we ought to be able
1615 to see one of these when an exec() has happened, is if the user
1616 caught a vfork, and then said "finish". Ordinarily a finish just
1617 carries them to the call-site of the current callee, by setting
1618 a temporary bp there and resuming. But in this case, the finish
1619 will carry them entirely through the vfork & exec.
1621 We don't want to allow a bp_finish to remain inserted now. But
1622 we can't safely delete it, 'cause finish_command has a handle to
1623 the bp on a bpstat, and will later want to delete it. There's a
1624 chance (and I've seen it happen) that if we delete the bp_finish
1625 here, that its storage will get reused by the time finish_command
1626 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1627 We really must allow finish_command to delete a bp_finish.
1629 In the absense of a general solution for the "how do we know
1630 it's safe to delete something others may have handles to?"
1631 problem, what we'll do here is just uninsert the bp_finish, and
1632 let finish_command delete it.
1634 (We know the bp_finish is "doomed" in the sense that it's
1635 momentary, and will be deleted as soon as finish_command sees
1636 the inferior stopped. So it doesn't matter that the bp's
1637 address is probably bogus in the new a.out, unlike e.g., the
1638 solib breakpoints.) */
1640 if (b
->type
== bp_finish
)
1645 /* Without a symbolic address, we have little hope of the
1646 pre-exec() address meaning the same thing in the post-exec()
1648 if (b
->addr_string
== NULL
)
1650 delete_breakpoint (b
);
1654 /* FIXME what about longjmp breakpoints? Re-create them here? */
1655 create_overlay_event_breakpoint ("_ovly_debug_event");
1656 create_longjmp_master_breakpoint ("longjmp");
1657 create_longjmp_master_breakpoint ("_longjmp");
1658 create_longjmp_master_breakpoint ("siglongjmp");
1659 create_longjmp_master_breakpoint ("_siglongjmp");
1663 detach_breakpoints (int pid
)
1665 struct bp_location
*b
;
1667 struct cleanup
*old_chain
= save_inferior_ptid ();
1669 if (pid
== PIDGET (inferior_ptid
))
1670 error (_("Cannot detach breakpoints of inferior_ptid"));
1672 /* Set inferior_ptid; remove_breakpoint uses this global. */
1673 inferior_ptid
= pid_to_ptid (pid
);
1674 ALL_BP_LOCATIONS (b
)
1678 val
= remove_breakpoint (b
, mark_inserted
);
1681 do_cleanups (old_chain
);
1686 do_cleanups (old_chain
);
1691 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1695 if (b
->owner
->enable_state
== bp_permanent
)
1696 /* Permanent breakpoints cannot be inserted or removed. */
1699 /* The type of none suggests that owner is actually deleted.
1700 This should not ever happen. */
1701 gdb_assert (b
->owner
->type
!= bp_none
);
1703 if (b
->loc_type
== bp_loc_software_breakpoint
1704 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1706 /* "Normal" instruction breakpoint: either the standard
1707 trap-instruction bp (bp_breakpoint), or a
1708 bp_hardware_breakpoint. */
1710 /* First check to see if we have to handle an overlay. */
1711 if (overlay_debugging
== ovly_off
1712 || b
->section
== NULL
1713 || !(section_is_overlay (b
->section
)))
1715 /* No overlay handling: just remove the breakpoint. */
1717 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1718 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
1720 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
1724 /* This breakpoint is in an overlay section.
1725 Did we set a breakpoint at the LMA? */
1726 if (!overlay_events_enabled
)
1728 /* Yes -- overlay event support is not active, so we
1729 should have set a breakpoint at the LMA. Remove it.
1731 /* Ignore any failures: if the LMA is in ROM, we will
1732 have already warned when we failed to insert it. */
1733 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1734 target_remove_hw_breakpoint (b
->gdbarch
,
1735 &b
->overlay_target_info
);
1737 target_remove_breakpoint (b
->gdbarch
,
1738 &b
->overlay_target_info
);
1740 /* Did we set a breakpoint at the VMA?
1741 If so, we will have marked the breakpoint 'inserted'. */
1744 /* Yes -- remove it. Previously we did not bother to
1745 remove the breakpoint if the section had been
1746 unmapped, but let's not rely on that being safe. We
1747 don't know what the overlay manager might do. */
1748 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1749 val
= target_remove_hw_breakpoint (b
->gdbarch
,
1752 /* However, we should remove *software* breakpoints only
1753 if the section is still mapped, or else we overwrite
1754 wrong code with the saved shadow contents. */
1755 else if (section_is_mapped (b
->section
))
1756 val
= target_remove_breakpoint (b
->gdbarch
,
1763 /* No -- not inserted, so no need to remove. No error. */
1768 /* In some cases, we might not be able to remove a breakpoint
1769 in a shared library that has already been removed, but we
1770 have not yet processed the shlib unload event. */
1771 if (val
&& solib_name_from_address (b
->address
))
1776 b
->inserted
= (is
== mark_inserted
);
1778 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1783 b
->inserted
= (is
== mark_inserted
);
1784 val
= target_remove_watchpoint (b
->address
, b
->length
,
1785 b
->watchpoint_type
);
1787 /* Failure to remove any of the hardware watchpoints comes here. */
1788 if ((is
== mark_uninserted
) && (b
->inserted
))
1789 warning (_("Could not remove hardware watchpoint %d."),
1792 else if (b
->owner
->type
== bp_catchpoint
1793 && breakpoint_enabled (b
->owner
)
1796 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
1798 val
= b
->owner
->ops
->remove (b
->owner
);
1801 b
->inserted
= (is
== mark_inserted
);
1807 /* Clear the "inserted" flag in all breakpoints. */
1810 mark_breakpoints_out (void)
1812 struct bp_location
*bpt
;
1814 ALL_BP_LOCATIONS (bpt
)
1818 /* Clear the "inserted" flag in all breakpoints and delete any
1819 breakpoints which should go away between runs of the program.
1821 Plus other such housekeeping that has to be done for breakpoints
1824 Note: this function gets called at the end of a run (by
1825 generic_mourn_inferior) and when a run begins (by
1826 init_wait_for_inferior). */
1831 breakpoint_init_inferior (enum inf_context context
)
1833 struct breakpoint
*b
, *temp
;
1834 struct bp_location
*bpt
;
1837 /* If breakpoint locations are shared across processes, then there's
1839 if (gdbarch_has_global_breakpoints (target_gdbarch
))
1842 ALL_BP_LOCATIONS (bpt
)
1843 if (bpt
->owner
->enable_state
!= bp_permanent
)
1846 ALL_BREAKPOINTS_SAFE (b
, temp
)
1851 case bp_watchpoint_scope
:
1853 /* If the call dummy breakpoint is at the entry point it will
1854 cause problems when the inferior is rerun, so we better
1857 Also get rid of scope breakpoints. */
1858 delete_breakpoint (b
);
1862 case bp_hardware_watchpoint
:
1863 case bp_read_watchpoint
:
1864 case bp_access_watchpoint
:
1866 /* Likewise for watchpoints on local expressions. */
1867 if (b
->exp_valid_block
!= NULL
)
1868 delete_breakpoint (b
);
1869 else if (context
== inf_starting
)
1871 /* Reset val field to force reread of starting value
1872 in insert_breakpoints. */
1874 value_free (b
->val
);
1884 /* Get rid of the moribund locations. */
1885 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
1886 free_bp_location (bpt
);
1887 VEC_free (bp_location_p
, moribund_locations
);
1890 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1891 exists at PC. It returns ordinary_breakpoint_here if it's an
1892 ordinary breakpoint, or permanent_breakpoint_here if it's a
1893 permanent breakpoint.
1894 - When continuing from a location with an ordinary breakpoint, we
1895 actually single step once before calling insert_breakpoints.
1896 - When continuing from a localion with a permanent breakpoint, we
1897 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1898 the target, to advance the PC past the breakpoint. */
1900 enum breakpoint_here
1901 breakpoint_here_p (CORE_ADDR pc
)
1903 const struct bp_location
*bpt
;
1904 int any_breakpoint_here
= 0;
1906 ALL_BP_LOCATIONS (bpt
)
1908 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1909 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1912 if ((breakpoint_enabled (bpt
->owner
)
1913 || bpt
->owner
->enable_state
== bp_permanent
)
1914 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1916 if (overlay_debugging
1917 && section_is_overlay (bpt
->section
)
1918 && !section_is_mapped (bpt
->section
))
1919 continue; /* unmapped overlay -- can't be a match */
1920 else if (bpt
->owner
->enable_state
== bp_permanent
)
1921 return permanent_breakpoint_here
;
1923 any_breakpoint_here
= 1;
1927 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1930 /* Return true if there's a moribund breakpoint at PC. */
1933 moribund_breakpoint_here_p (CORE_ADDR pc
)
1935 struct bp_location
*loc
;
1938 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
1939 if (loc
->address
== pc
)
1945 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1946 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1947 This does not check for single-step breakpoints, which are
1948 inserted and removed using direct target manipulation. */
1951 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1953 const struct bp_location
*bpt
;
1955 ALL_BP_LOCATIONS (bpt
)
1957 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1958 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1962 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1964 if (overlay_debugging
1965 && section_is_overlay (bpt
->section
)
1966 && !section_is_mapped (bpt
->section
))
1967 continue; /* unmapped overlay -- can't be a match */
1975 /* Returns non-zero iff there's either regular breakpoint
1976 or a single step breakpoint inserted at PC. */
1979 breakpoint_inserted_here_p (CORE_ADDR pc
)
1981 if (regular_breakpoint_inserted_here_p (pc
))
1984 if (single_step_breakpoint_inserted_here_p (pc
))
1990 /* This function returns non-zero iff there is a software breakpoint
1994 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1996 const struct bp_location
*bpt
;
1997 int any_breakpoint_here
= 0;
1999 ALL_BP_LOCATIONS (bpt
)
2001 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2005 && bpt
->address
== pc
) /* bp is enabled and matches pc */
2007 if (overlay_debugging
2008 && section_is_overlay (bpt
->section
)
2009 && !section_is_mapped (bpt
->section
))
2010 continue; /* unmapped overlay -- can't be a match */
2016 /* Also check for software single-step breakpoints. */
2017 if (single_step_breakpoint_inserted_here_p (pc
))
2023 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2024 PC is valid for process/thread PTID. */
2027 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
2029 const struct bp_location
*bpt
;
2030 /* The thread and task IDs associated to PTID, computed lazily. */
2034 ALL_BP_LOCATIONS (bpt
)
2036 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2037 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2040 if (!breakpoint_enabled (bpt
->owner
)
2041 && bpt
->owner
->enable_state
!= bp_permanent
)
2044 if (bpt
->address
!= pc
)
2047 if (bpt
->owner
->thread
!= -1)
2049 /* This is a thread-specific breakpoint. Check that ptid
2050 matches that thread. If thread hasn't been computed yet,
2051 it is now time to do so. */
2053 thread
= pid_to_thread_id (ptid
);
2054 if (bpt
->owner
->thread
!= thread
)
2058 if (bpt
->owner
->task
!= 0)
2060 /* This is a task-specific breakpoint. Check that ptid
2061 matches that task. If task hasn't been computed yet,
2062 it is now time to do so. */
2064 task
= ada_get_task_number (ptid
);
2065 if (bpt
->owner
->task
!= task
)
2069 if (overlay_debugging
2070 && section_is_overlay (bpt
->section
)
2071 && !section_is_mapped (bpt
->section
))
2072 continue; /* unmapped overlay -- can't be a match */
2081 /* bpstat stuff. External routines' interfaces are documented
2085 ep_is_catchpoint (struct breakpoint
*ep
)
2087 return (ep
->type
== bp_catchpoint
);
2091 bpstat_free (bpstat bs
)
2093 if (bs
->old_val
!= NULL
)
2094 value_free (bs
->old_val
);
2095 free_command_lines (&bs
->commands
);
2099 /* Clear a bpstat so that it says we are not at any breakpoint.
2100 Also free any storage that is part of a bpstat. */
2103 bpstat_clear (bpstat
*bsp
)
2120 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2121 is part of the bpstat is copied as well. */
2124 bpstat_copy (bpstat bs
)
2128 bpstat retval
= NULL
;
2133 for (; bs
!= NULL
; bs
= bs
->next
)
2135 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2136 memcpy (tmp
, bs
, sizeof (*tmp
));
2137 if (bs
->commands
!= NULL
)
2138 tmp
->commands
= copy_command_lines (bs
->commands
);
2139 if (bs
->old_val
!= NULL
)
2141 tmp
->old_val
= value_copy (bs
->old_val
);
2142 release_value (tmp
->old_val
);
2146 /* This is the first thing in the chain. */
2156 /* Find the bpstat associated with this breakpoint */
2159 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2164 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2166 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2172 /* Find a step_resume breakpoint associated with this bpstat.
2173 (If there are multiple step_resume bp's on the list, this function
2174 will arbitrarily pick one.)
2176 It is an error to use this function if BPSTAT doesn't contain a
2177 step_resume breakpoint.
2179 See wait_for_inferior's use of this function. */
2181 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2185 gdb_assert (bsp
!= NULL
);
2187 current_thread
= pid_to_thread_id (inferior_ptid
);
2189 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2191 if ((bsp
->breakpoint_at
!= NULL
)
2192 && (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
)
2193 && (bsp
->breakpoint_at
->owner
->thread
== current_thread
2194 || bsp
->breakpoint_at
->owner
->thread
== -1))
2195 return bsp
->breakpoint_at
->owner
;
2198 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2202 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2203 at. *BSP upon return is a bpstat which points to the remaining
2204 breakpoints stopped at (but which is not guaranteed to be good for
2205 anything but further calls to bpstat_num).
2206 Return 0 if passed a bpstat which does not indicate any breakpoints.
2207 Return -1 if stopped at a breakpoint that has been deleted since
2209 Return 1 otherwise. */
2212 bpstat_num (bpstat
*bsp
, int *num
)
2214 struct breakpoint
*b
;
2217 return 0; /* No more breakpoint values */
2219 /* We assume we'll never have several bpstats that
2220 correspond to a single breakpoint -- otherwise,
2221 this function might return the same number more
2222 than once and this will look ugly. */
2223 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2224 *bsp
= (*bsp
)->next
;
2226 return -1; /* breakpoint that's been deleted since */
2228 *num
= b
->number
; /* We have its number */
2232 /* Modify BS so that the actions will not be performed. */
2235 bpstat_clear_actions (bpstat bs
)
2237 for (; bs
!= NULL
; bs
= bs
->next
)
2239 free_command_lines (&bs
->commands
);
2240 if (bs
->old_val
!= NULL
)
2242 value_free (bs
->old_val
);
2248 /* Called when a command is about to proceed the inferior. */
2251 breakpoint_about_to_proceed (void)
2253 if (!ptid_equal (inferior_ptid
, null_ptid
))
2255 struct thread_info
*tp
= inferior_thread ();
2257 /* Allow inferior function calls in breakpoint commands to not
2258 interrupt the command list. When the call finishes
2259 successfully, the inferior will be standing at the same
2260 breakpoint as if nothing happened. */
2265 breakpoint_proceeded
= 1;
2268 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2270 cleanup_executing_breakpoints (void *ignore
)
2272 executing_breakpoint_commands
= 0;
2275 /* Execute all the commands associated with all the breakpoints at this
2276 location. Any of these commands could cause the process to proceed
2277 beyond this point, etc. We look out for such changes by checking
2278 the global "breakpoint_proceeded" after each command.
2280 Returns true if a breakpoint command resumed the inferior. In that
2281 case, it is the caller's responsibility to recall it again with the
2282 bpstat of the current thread. */
2285 bpstat_do_actions_1 (bpstat
*bsp
)
2288 struct cleanup
*old_chain
;
2291 /* Avoid endless recursion if a `source' command is contained
2293 if (executing_breakpoint_commands
)
2296 executing_breakpoint_commands
= 1;
2297 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2299 /* This pointer will iterate over the list of bpstat's. */
2302 breakpoint_proceeded
= 0;
2303 for (; bs
!= NULL
; bs
= bs
->next
)
2305 struct command_line
*cmd
;
2306 struct cleanup
*this_cmd_tree_chain
;
2308 /* Take ownership of the BSP's command tree, if it has one.
2310 The command tree could legitimately contain commands like
2311 'step' and 'next', which call clear_proceed_status, which
2312 frees stop_bpstat's command tree. To make sure this doesn't
2313 free the tree we're executing out from under us, we need to
2314 take ownership of the tree ourselves. Since a given bpstat's
2315 commands are only executed once, we don't need to copy it; we
2316 can clear the pointer in the bpstat, and make sure we free
2317 the tree when we're done. */
2320 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2324 execute_control_command (cmd
);
2326 if (breakpoint_proceeded
)
2332 /* We can free this command tree now. */
2333 do_cleanups (this_cmd_tree_chain
);
2335 if (breakpoint_proceeded
)
2337 if (target_can_async_p ())
2338 /* If we are in async mode, then the target might be still
2339 running, not stopped at any breakpoint, so nothing for
2340 us to do here -- just return to the event loop. */
2343 /* In sync mode, when execute_control_command returns
2344 we're already standing on the next breakpoint.
2345 Breakpoint commands for that stop were not run, since
2346 execute_command does not run breakpoint commands --
2347 only command_line_handler does, but that one is not
2348 involved in execution of breakpoint commands. So, we
2349 can now execute breakpoint commands. It should be
2350 noted that making execute_command do bpstat actions is
2351 not an option -- in this case we'll have recursive
2352 invocation of bpstat for each breakpoint with a
2353 command, and can easily blow up GDB stack. Instead, we
2354 return true, which will trigger the caller to recall us
2355 with the new stop_bpstat. */
2360 do_cleanups (old_chain
);
2365 bpstat_do_actions (void)
2367 /* Do any commands attached to breakpoint we are stopped at. */
2368 while (!ptid_equal (inferior_ptid
, null_ptid
)
2369 && target_has_execution
2370 && !is_exited (inferior_ptid
)
2371 && !is_executing (inferior_ptid
))
2372 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2373 and only return when it is stopped at the next breakpoint, we
2374 keep doing breakpoint actions until it returns false to
2375 indicate the inferior was not resumed. */
2376 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2380 /* Print out the (old or new) value associated with a watchpoint. */
2383 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2386 fprintf_unfiltered (stream
, _("<unreadable>"));
2389 struct value_print_options opts
;
2390 get_user_print_options (&opts
);
2391 value_print (val
, stream
, &opts
);
2395 /* This is the normal print function for a bpstat. In the future,
2396 much of this logic could (should?) be moved to bpstat_stop_status,
2397 by having it set different print_it values.
2399 Current scheme: When we stop, bpstat_print() is called. It loops
2400 through the bpstat list of things causing this stop, calling the
2401 print_bp_stop_message function on each one. The behavior of the
2402 print_bp_stop_message function depends on the print_it field of
2403 bpstat. If such field so indicates, call this function here.
2405 Return values from this routine (ultimately used by bpstat_print()
2406 and normal_stop() to decide what to do):
2407 PRINT_NOTHING: Means we already printed all we needed to print,
2408 don't print anything else.
2409 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2410 that something to be followed by a location.
2411 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2412 that something to be followed by a location.
2413 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2416 static enum print_stop_action
2417 print_it_typical (bpstat bs
)
2419 struct cleanup
*old_chain
;
2420 struct breakpoint
*b
;
2421 const struct bp_location
*bl
;
2422 struct ui_stream
*stb
;
2424 enum print_stop_action result
;
2426 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2427 which has since been deleted. */
2428 if (bs
->breakpoint_at
== NULL
)
2429 return PRINT_UNKNOWN
;
2430 bl
= bs
->breakpoint_at
;
2433 stb
= ui_out_stream_new (uiout
);
2434 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2439 case bp_hardware_breakpoint
:
2440 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2441 if (bl
->address
!= bl
->requested_address
)
2442 breakpoint_adjustment_warning (bl
->requested_address
,
2445 annotate_breakpoint (b
->number
);
2447 ui_out_text (uiout
, "\nTemporary breakpoint ");
2449 ui_out_text (uiout
, "\nBreakpoint ");
2450 if (ui_out_is_mi_like_p (uiout
))
2452 ui_out_field_string (uiout
, "reason",
2453 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2454 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2456 ui_out_field_int (uiout
, "bkptno", b
->number
);
2457 ui_out_text (uiout
, ", ");
2458 result
= PRINT_SRC_AND_LOC
;
2461 case bp_shlib_event
:
2462 /* Did we stop because the user set the stop_on_solib_events
2463 variable? (If so, we report this as a generic, "Stopped due
2464 to shlib event" message.) */
2465 printf_filtered (_("Stopped due to shared library event\n"));
2466 result
= PRINT_NOTHING
;
2469 case bp_thread_event
:
2470 /* Not sure how we will get here.
2471 GDB should not stop for these breakpoints. */
2472 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2473 result
= PRINT_NOTHING
;
2476 case bp_overlay_event
:
2477 /* By analogy with the thread event, GDB should not stop for these. */
2478 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2479 result
= PRINT_NOTHING
;
2482 case bp_longjmp_master
:
2483 /* These should never be enabled. */
2484 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
2485 result
= PRINT_NOTHING
;
2489 case bp_hardware_watchpoint
:
2490 annotate_watchpoint (b
->number
);
2491 if (ui_out_is_mi_like_p (uiout
))
2494 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2496 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2497 ui_out_text (uiout
, "\nOld value = ");
2498 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2499 ui_out_field_stream (uiout
, "old", stb
);
2500 ui_out_text (uiout
, "\nNew value = ");
2501 watchpoint_value_print (b
->val
, stb
->stream
);
2502 ui_out_field_stream (uiout
, "new", stb
);
2503 ui_out_text (uiout
, "\n");
2504 /* More than one watchpoint may have been triggered. */
2505 result
= PRINT_UNKNOWN
;
2508 case bp_read_watchpoint
:
2509 if (ui_out_is_mi_like_p (uiout
))
2512 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2514 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2515 ui_out_text (uiout
, "\nValue = ");
2516 watchpoint_value_print (b
->val
, stb
->stream
);
2517 ui_out_field_stream (uiout
, "value", stb
);
2518 ui_out_text (uiout
, "\n");
2519 result
= PRINT_UNKNOWN
;
2522 case bp_access_watchpoint
:
2523 if (bs
->old_val
!= NULL
)
2525 annotate_watchpoint (b
->number
);
2526 if (ui_out_is_mi_like_p (uiout
))
2529 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2531 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2532 ui_out_text (uiout
, "\nOld value = ");
2533 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2534 ui_out_field_stream (uiout
, "old", stb
);
2535 ui_out_text (uiout
, "\nNew value = ");
2540 if (ui_out_is_mi_like_p (uiout
))
2543 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2544 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2545 ui_out_text (uiout
, "\nValue = ");
2547 watchpoint_value_print (b
->val
, stb
->stream
);
2548 ui_out_field_stream (uiout
, "new", stb
);
2549 ui_out_text (uiout
, "\n");
2550 result
= PRINT_UNKNOWN
;
2553 /* Fall through, we don't deal with these types of breakpoints
2557 if (ui_out_is_mi_like_p (uiout
))
2560 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2561 result
= PRINT_UNKNOWN
;
2565 if (ui_out_is_mi_like_p (uiout
))
2568 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2569 result
= PRINT_UNKNOWN
;
2574 case bp_longjmp_resume
:
2575 case bp_step_resume
:
2576 case bp_watchpoint_scope
:
2580 result
= PRINT_UNKNOWN
;
2584 do_cleanups (old_chain
);
2588 /* Generic routine for printing messages indicating why we
2589 stopped. The behavior of this function depends on the value
2590 'print_it' in the bpstat structure. Under some circumstances we
2591 may decide not to print anything here and delegate the task to
2594 static enum print_stop_action
2595 print_bp_stop_message (bpstat bs
)
2597 switch (bs
->print_it
)
2600 /* Nothing should be printed for this bpstat entry. */
2601 return PRINT_UNKNOWN
;
2605 /* We still want to print the frame, but we already printed the
2606 relevant messages. */
2607 return PRINT_SRC_AND_LOC
;
2610 case print_it_normal
:
2612 const struct bp_location
*bl
= bs
->breakpoint_at
;
2613 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2615 /* Normal case. Call the breakpoint's print_it method, or
2616 print_it_typical. */
2617 /* FIXME: how breakpoint can ever be NULL here? */
2618 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2619 return b
->ops
->print_it (b
);
2621 return print_it_typical (bs
);
2626 internal_error (__FILE__
, __LINE__
,
2627 _("print_bp_stop_message: unrecognized enum value"));
2632 /* Print a message indicating what happened. This is called from
2633 normal_stop(). The input to this routine is the head of the bpstat
2634 list - a list of the eventpoints that caused this stop. This
2635 routine calls the generic print routine for printing a message
2636 about reasons for stopping. This will print (for example) the
2637 "Breakpoint n," part of the output. The return value of this
2640 PRINT_UNKNOWN: Means we printed nothing
2641 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2642 code to print the location. An example is
2643 "Breakpoint 1, " which should be followed by
2645 PRINT_SRC_ONLY: Means we printed something, but there is no need
2646 to also print the location part of the message.
2647 An example is the catch/throw messages, which
2648 don't require a location appended to the end.
2649 PRINT_NOTHING: We have done some printing and we don't need any
2650 further info to be printed.*/
2652 enum print_stop_action
2653 bpstat_print (bpstat bs
)
2657 /* Maybe another breakpoint in the chain caused us to stop.
2658 (Currently all watchpoints go on the bpstat whether hit or not.
2659 That probably could (should) be changed, provided care is taken
2660 with respect to bpstat_explains_signal). */
2661 for (; bs
; bs
= bs
->next
)
2663 val
= print_bp_stop_message (bs
);
2664 if (val
== PRINT_SRC_ONLY
2665 || val
== PRINT_SRC_AND_LOC
2666 || val
== PRINT_NOTHING
)
2670 /* We reached the end of the chain, or we got a null BS to start
2671 with and nothing was printed. */
2672 return PRINT_UNKNOWN
;
2675 /* Evaluate the expression EXP and return 1 if value is zero.
2676 This is used inside a catch_errors to evaluate the breakpoint condition.
2677 The argument is a "struct expression *" that has been cast to char * to
2678 make it pass through catch_errors. */
2681 breakpoint_cond_eval (void *exp
)
2683 struct value
*mark
= value_mark ();
2684 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2685 value_free_to_mark (mark
);
2689 /* Allocate a new bpstat and chain it to the current one. */
2692 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2696 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2698 bs
->breakpoint_at
= bl
;
2699 /* If the condition is false, etc., don't do the commands. */
2700 bs
->commands
= NULL
;
2702 bs
->print_it
= print_it_normal
;
2706 /* The target has stopped with waitstatus WS. Check if any hardware
2707 watchpoints have triggered, according to the target. */
2710 watchpoints_triggered (struct target_waitstatus
*ws
)
2712 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
2714 struct breakpoint
*b
;
2716 if (!stopped_by_watchpoint
)
2718 /* We were not stopped by a watchpoint. Mark all watchpoints
2719 as not triggered. */
2721 if (b
->type
== bp_hardware_watchpoint
2722 || b
->type
== bp_read_watchpoint
2723 || b
->type
== bp_access_watchpoint
)
2724 b
->watchpoint_triggered
= watch_triggered_no
;
2729 if (!target_stopped_data_address (¤t_target
, &addr
))
2731 /* We were stopped by a watchpoint, but we don't know where.
2732 Mark all watchpoints as unknown. */
2734 if (b
->type
== bp_hardware_watchpoint
2735 || b
->type
== bp_read_watchpoint
2736 || b
->type
== bp_access_watchpoint
)
2737 b
->watchpoint_triggered
= watch_triggered_unknown
;
2739 return stopped_by_watchpoint
;
2742 /* The target could report the data address. Mark watchpoints
2743 affected by this data address as triggered, and all others as not
2747 if (b
->type
== bp_hardware_watchpoint
2748 || b
->type
== bp_read_watchpoint
2749 || b
->type
== bp_access_watchpoint
)
2751 struct bp_location
*loc
;
2754 b
->watchpoint_triggered
= watch_triggered_no
;
2755 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2756 /* Exact match not required. Within range is
2758 if (target_watchpoint_addr_within_range (¤t_target
,
2762 b
->watchpoint_triggered
= watch_triggered_yes
;
2770 /* Possible return values for watchpoint_check (this can't be an enum
2771 because of check_errors). */
2772 /* The watchpoint has been deleted. */
2773 #define WP_DELETED 1
2774 /* The value has changed. */
2775 #define WP_VALUE_CHANGED 2
2776 /* The value has not changed. */
2777 #define WP_VALUE_NOT_CHANGED 3
2779 #define BP_TEMPFLAG 1
2780 #define BP_HARDWAREFLAG 2
2782 /* Check watchpoint condition. */
2785 watchpoint_check (void *p
)
2787 bpstat bs
= (bpstat
) p
;
2788 struct breakpoint
*b
;
2789 struct frame_info
*fr
;
2790 int within_current_scope
;
2792 b
= bs
->breakpoint_at
->owner
;
2794 if (b
->exp_valid_block
== NULL
)
2795 within_current_scope
= 1;
2798 struct frame_info
*frame
= get_current_frame ();
2799 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
2800 CORE_ADDR frame_pc
= get_frame_pc (frame
);
2802 fr
= frame_find_by_id (b
->watchpoint_frame
);
2803 within_current_scope
= (fr
!= NULL
);
2805 /* If we've gotten confused in the unwinder, we might have
2806 returned a frame that can't describe this variable. */
2807 if (within_current_scope
)
2809 struct symbol
*function
;
2811 function
= get_frame_function (fr
);
2812 if (function
== NULL
2813 || !contained_in (b
->exp_valid_block
,
2814 SYMBOL_BLOCK_VALUE (function
)))
2815 within_current_scope
= 0;
2818 /* in_function_epilogue_p() returns a non-zero value if we're still
2819 in the function but the stack frame has already been invalidated.
2820 Since we can't rely on the values of local variables after the
2821 stack has been destroyed, we are treating the watchpoint in that
2822 state as `not changed' without further checking. Don't mark
2823 watchpoints as changed if the current frame is in an epilogue -
2824 even if they are in some other frame, our view of the stack
2825 is likely to be wrong. */
2826 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
2827 return WP_VALUE_NOT_CHANGED
;
2829 if (within_current_scope
)
2830 /* If we end up stopping, the current frame will get selected
2831 in normal_stop. So this call to select_frame won't affect
2836 if (within_current_scope
)
2838 /* We use value_{,free_to_}mark because it could be a
2839 *long* time before we return to the command level and
2840 call free_all_values. We can't call free_all_values because
2841 we might be in the middle of evaluating a function call. */
2843 struct value
*mark
= value_mark ();
2844 struct value
*new_val
;
2846 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2847 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2848 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2850 if (new_val
!= NULL
)
2852 release_value (new_val
);
2853 value_free_to_mark (mark
);
2855 bs
->old_val
= b
->val
;
2858 /* We will stop here */
2859 return WP_VALUE_CHANGED
;
2863 /* Nothing changed, don't do anything. */
2864 value_free_to_mark (mark
);
2865 /* We won't stop here */
2866 return WP_VALUE_NOT_CHANGED
;
2871 /* This seems like the only logical thing to do because
2872 if we temporarily ignored the watchpoint, then when
2873 we reenter the block in which it is valid it contains
2874 garbage (in the case of a function, it may have two
2875 garbage values, one before and one after the prologue).
2876 So we can't even detect the first assignment to it and
2877 watch after that (since the garbage may or may not equal
2878 the first value assigned). */
2879 /* We print all the stop information in print_it_typical(), but
2880 in this case, by the time we call print_it_typical() this bp
2881 will be deleted already. So we have no choice but print the
2882 information here. */
2883 if (ui_out_is_mi_like_p (uiout
))
2885 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2886 ui_out_text (uiout
, "\nWatchpoint ");
2887 ui_out_field_int (uiout
, "wpnum", b
->number
);
2888 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2889 which its expression is valid.\n");
2891 if (b
->related_breakpoint
)
2892 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2893 b
->disposition
= disp_del_at_next_stop
;
2899 /* Return true if it looks like target has stopped due to hitting
2900 breakpoint location BL. This function does not check if we
2901 should stop, only if BL explains the stop. */
2903 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2905 struct breakpoint
*b
= bl
->owner
;
2907 if (b
->type
!= bp_watchpoint
2908 && b
->type
!= bp_hardware_watchpoint
2909 && b
->type
!= bp_read_watchpoint
2910 && b
->type
!= bp_access_watchpoint
2911 && b
->type
!= bp_hardware_breakpoint
2912 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
2914 if (bl
->address
!= bp_addr
) /* address doesn't match */
2916 if (overlay_debugging
/* unmapped overlay section */
2917 && section_is_overlay (bl
->section
)
2918 && !section_is_mapped (bl
->section
))
2922 /* Continuable hardware watchpoints are treated as non-existent if the
2923 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2924 some data address). Otherwise gdb won't stop on a break instruction
2925 in the code (not from a breakpoint) when a hardware watchpoint has
2926 been defined. Also skip watchpoints which we know did not trigger
2927 (did not match the data address). */
2929 if ((b
->type
== bp_hardware_watchpoint
2930 || b
->type
== bp_read_watchpoint
2931 || b
->type
== bp_access_watchpoint
)
2932 && b
->watchpoint_triggered
== watch_triggered_no
)
2935 if (b
->type
== bp_hardware_breakpoint
)
2937 if (bl
->address
!= bp_addr
)
2939 if (overlay_debugging
/* unmapped overlay section */
2940 && section_is_overlay (bl
->section
)
2941 && !section_is_mapped (bl
->section
))
2945 if (b
->type
== bp_catchpoint
)
2947 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2948 if (!b
->ops
->breakpoint_hit (b
))
2955 /* If BS refers to a watchpoint, determine if the watched values
2956 has actually changed, and we should stop. If not, set BS->stop
2959 bpstat_check_watchpoint (bpstat bs
)
2961 const struct bp_location
*bl
= bs
->breakpoint_at
;
2962 struct breakpoint
*b
= bl
->owner
;
2964 if (b
->type
== bp_watchpoint
2965 || b
->type
== bp_read_watchpoint
2966 || b
->type
== bp_access_watchpoint
2967 || b
->type
== bp_hardware_watchpoint
)
2971 int must_check_value
= 0;
2973 if (b
->type
== bp_watchpoint
)
2974 /* For a software watchpoint, we must always check the
2976 must_check_value
= 1;
2977 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2978 /* We have a hardware watchpoint (read, write, or access)
2979 and the target earlier reported an address watched by
2981 must_check_value
= 1;
2982 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2983 && b
->type
== bp_hardware_watchpoint
)
2984 /* We were stopped by a hardware watchpoint, but the target could
2985 not report the data address. We must check the watchpoint's
2986 value. Access and read watchpoints are out of luck; without
2987 a data address, we can't figure it out. */
2988 must_check_value
= 1;
2990 if (must_check_value
)
2992 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2994 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2995 int e
= catch_errors (watchpoint_check
, bs
, message
,
2997 do_cleanups (cleanups
);
3001 /* We've already printed what needs to be printed. */
3002 bs
->print_it
= print_it_done
;
3005 case WP_VALUE_CHANGED
:
3006 if (b
->type
== bp_read_watchpoint
)
3008 /* Don't stop: read watchpoints shouldn't fire if
3009 the value has changed. This is for targets
3010 which cannot set read-only watchpoints. */
3011 bs
->print_it
= print_it_noop
;
3015 case WP_VALUE_NOT_CHANGED
:
3016 if (b
->type
== bp_hardware_watchpoint
3017 || b
->type
== bp_watchpoint
)
3019 /* Don't stop: write watchpoints shouldn't fire if
3020 the value hasn't changed. */
3021 bs
->print_it
= print_it_noop
;
3029 /* Error from catch_errors. */
3030 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3031 if (b
->related_breakpoint
)
3032 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3033 b
->disposition
= disp_del_at_next_stop
;
3034 /* We've already printed what needs to be printed. */
3035 bs
->print_it
= print_it_done
;
3039 else /* must_check_value == 0 */
3041 /* This is a case where some watchpoint(s) triggered, but
3042 not at the address of this watchpoint, or else no
3043 watchpoint triggered after all. So don't print
3044 anything for this watchpoint. */
3045 bs
->print_it
= print_it_noop
;
3052 /* Check conditions (condition proper, frame, thread and ignore count)
3053 of breakpoint referred to by BS. If we should not stop for this
3054 breakpoint, set BS->stop to 0. */
3056 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3058 int thread_id
= pid_to_thread_id (ptid
);
3059 const struct bp_location
*bl
= bs
->breakpoint_at
;
3060 struct breakpoint
*b
= bl
->owner
;
3062 if (frame_id_p (b
->frame_id
)
3063 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3067 int value_is_zero
= 0;
3069 /* If this is a scope breakpoint, mark the associated
3070 watchpoint as triggered so that we will handle the
3071 out-of-scope event. We'll get to the watchpoint next
3073 if (b
->type
== bp_watchpoint_scope
)
3074 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3076 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3078 /* We use value_mark and value_free_to_mark because it could
3079 be a long time before we return to the command level and
3080 call free_all_values. We can't call free_all_values
3081 because we might be in the middle of evaluating a
3083 struct value
*mark
= value_mark ();
3085 /* Need to select the frame, with all that implies so that
3086 the conditions will have the right context. Because we
3087 use the frame, we will not see an inlined function's
3088 variables when we arrive at a breakpoint at the start
3089 of the inlined function; the current frame will be the
3091 select_frame (get_current_frame ());
3093 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
3094 "Error in testing breakpoint condition:\n",
3096 /* FIXME-someday, should give breakpoint # */
3097 value_free_to_mark (mark
);
3099 if (bl
->cond
&& value_is_zero
)
3103 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3107 else if (b
->ignore_count
> 0)
3110 annotate_ignore_count_change ();
3112 /* Increase the hit count even though we don't
3120 /* Get a bpstat associated with having just stopped at address
3121 BP_ADDR in thread PTID.
3123 Determine whether we stopped at a breakpoint, etc, or whether we
3124 don't understand this stop. Result is a chain of bpstat's such that:
3126 if we don't understand the stop, the result is a null pointer.
3128 if we understand why we stopped, the result is not null.
3130 Each element of the chain refers to a particular breakpoint or
3131 watchpoint at which we have stopped. (We may have stopped for
3132 several reasons concurrently.)
3134 Each element of the chain has valid next, breakpoint_at,
3135 commands, FIXME??? fields. */
3138 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3140 struct breakpoint
*b
= NULL
;
3141 const struct bp_location
*bl
;
3142 struct bp_location
*loc
;
3143 /* Root of the chain of bpstat's */
3144 struct bpstats root_bs
[1];
3145 /* Pointer to the last thing in the chain currently. */
3146 bpstat bs
= root_bs
;
3148 int need_remove_insert
;
3150 ALL_BP_LOCATIONS (bl
)
3154 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3157 /* For hardware watchpoints, we look only at the first location.
3158 The watchpoint_check function will work on entire expression,
3159 not the individual locations. For read watchopints, the
3160 watchpoints_triggered function have checked all locations
3163 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3166 if (!bpstat_check_location (bl
, bp_addr
))
3169 /* Come here if it's a watchpoint, or if the break address matches */
3171 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3173 /* Assume we stop. Should we find watchpoint that is not actually
3174 triggered, or if condition of breakpoint is false, we'll reset
3179 bpstat_check_watchpoint (bs
);
3183 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3184 || b
->type
== bp_longjmp_master
)
3185 /* We do not stop for these. */
3188 bpstat_check_breakpoint_conditions (bs
, ptid
);
3194 /* We will stop here */
3195 if (b
->disposition
== disp_disable
)
3197 if (b
->enable_state
!= bp_permanent
)
3198 b
->enable_state
= bp_disabled
;
3199 update_global_location_list (0);
3203 bs
->commands
= b
->commands
;
3205 && (strcmp ("silent", bs
->commands
->line
) == 0
3206 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3208 bs
->commands
= bs
->commands
->next
;
3211 bs
->commands
= copy_command_lines (bs
->commands
);
3214 /* Print nothing for this entry if we dont stop or if we dont print. */
3215 if (bs
->stop
== 0 || bs
->print
== 0)
3216 bs
->print_it
= print_it_noop
;
3219 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3221 if (loc
->address
== bp_addr
)
3223 bs
= bpstat_alloc (loc
, bs
);
3224 /* For hits of moribund locations, we should just proceed. */
3227 bs
->print_it
= print_it_noop
;
3231 bs
->next
= NULL
; /* Terminate the chain */
3232 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3234 /* If we aren't stopping, the value of some hardware watchpoint may
3235 not have changed, but the intermediate memory locations we are
3236 watching may have. Don't bother if we're stopping; this will get
3238 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3242 need_remove_insert
= 0;
3244 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3246 && bs
->breakpoint_at
->owner
3247 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3248 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3249 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3251 /* remove/insert can invalidate bs->breakpoint_at, if this
3252 location is no longer used by the watchpoint. Prevent
3253 further code from trying to use it. */
3254 bs
->breakpoint_at
= NULL
;
3255 need_remove_insert
= 1;
3258 if (need_remove_insert
)
3260 remove_breakpoints ();
3261 insert_breakpoints ();
3264 return root_bs
->next
;
3267 /* Tell what to do about this bpstat. */
3269 bpstat_what (bpstat bs
)
3271 /* Classify each bpstat as one of the following. */
3274 /* This bpstat element has no effect on the main_action. */
3277 /* There was a watchpoint, stop but don't print. */
3280 /* There was a watchpoint, stop and print. */
3283 /* There was a breakpoint but we're not stopping. */
3286 /* There was a breakpoint, stop but don't print. */
3289 /* There was a breakpoint, stop and print. */
3292 /* We hit the longjmp breakpoint. */
3295 /* We hit the longjmp_resume breakpoint. */
3298 /* We hit the step_resume breakpoint. */
3301 /* We hit the shared library event breakpoint. */
3304 /* This is just used to count how many enums there are. */
3308 /* Here is the table which drives this routine. So that we can
3309 format it pretty, we define some abbreviations for the
3310 enum bpstat_what codes. */
3311 #define kc BPSTAT_WHAT_KEEP_CHECKING
3312 #define ss BPSTAT_WHAT_STOP_SILENT
3313 #define sn BPSTAT_WHAT_STOP_NOISY
3314 #define sgl BPSTAT_WHAT_SINGLE
3315 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3316 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3317 #define sr BPSTAT_WHAT_STEP_RESUME
3318 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3320 /* "Can't happen." Might want to print an error message.
3321 abort() is not out of the question, but chances are GDB is just
3322 a bit confused, not unusable. */
3323 #define err BPSTAT_WHAT_STOP_NOISY
3325 /* Given an old action and a class, come up with a new action. */
3326 /* One interesting property of this table is that wp_silent is the same
3327 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3328 after stopping, the check for whether to step over a breakpoint
3329 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3330 reference to how we stopped. We retain separate wp_silent and
3331 bp_silent codes in case we want to change that someday.
3333 Another possibly interesting property of this table is that
3334 there's a partial ordering, priority-like, of the actions. Once
3335 you've decided that some action is appropriate, you'll never go
3336 back and decide something of a lower priority is better. The
3339 kc < clr sgl shl slr sn sr ss
3340 sgl < shl slr sn sr ss
3341 slr < err shl sn sr ss
3342 clr < err shl sn sr ss
3348 What I think this means is that we don't need a damned table
3349 here. If you just put the rows and columns in the right order,
3350 it'd look awfully regular. We could simply walk the bpstat list
3351 and choose the highest priority action we find, with a little
3352 logic to handle the 'err' cases. */
3354 /* step_resume entries: a step resume breakpoint overrides another
3355 breakpoint of signal handling (see comment in wait_for_inferior
3356 at where we set the step_resume breakpoint). */
3358 static const enum bpstat_what_main_action
3359 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3362 /* kc ss sn sgl slr clr sr shl
3365 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
},
3367 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3369 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3371 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
},
3373 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3375 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3377 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
},
3379 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
},
3381 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3383 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
}
3396 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3397 struct bpstat_what retval
;
3399 retval
.call_dummy
= 0;
3400 for (; bs
!= NULL
; bs
= bs
->next
)
3402 enum class bs_class
= no_effect
;
3403 if (bs
->breakpoint_at
== NULL
)
3404 /* I suspect this can happen if it was a momentary breakpoint
3405 which has since been deleted. */
3407 if (bs
->breakpoint_at
->owner
== NULL
)
3408 bs_class
= bp_nostop
;
3410 switch (bs
->breakpoint_at
->owner
->type
)
3416 case bp_hardware_breakpoint
:
3422 bs_class
= bp_noisy
;
3424 bs_class
= bp_silent
;
3427 bs_class
= bp_nostop
;
3430 case bp_hardware_watchpoint
:
3431 case bp_read_watchpoint
:
3432 case bp_access_watchpoint
:
3436 bs_class
= wp_noisy
;
3438 bs_class
= wp_silent
;
3441 /* There was a watchpoint, but we're not stopping.
3442 This requires no further action. */
3443 bs_class
= no_effect
;
3446 bs_class
= long_jump
;
3448 case bp_longjmp_resume
:
3449 bs_class
= long_resume
;
3451 case bp_step_resume
:
3454 bs_class
= step_resume
;
3457 /* It is for the wrong frame. */
3458 bs_class
= bp_nostop
;
3460 case bp_watchpoint_scope
:
3461 bs_class
= bp_nostop
;
3463 case bp_shlib_event
:
3464 bs_class
= shlib_event
;
3466 case bp_thread_event
:
3467 case bp_overlay_event
:
3468 case bp_longjmp_master
:
3469 bs_class
= bp_nostop
;
3475 bs_class
= bp_noisy
;
3477 bs_class
= bp_silent
;
3480 /* There was a catchpoint, but we're not stopping.
3481 This requires no further action. */
3482 bs_class
= no_effect
;
3485 /* Make sure the action is stop (silent or noisy),
3486 so infrun.c pops the dummy frame. */
3487 bs_class
= bp_silent
;
3488 retval
.call_dummy
= 1;
3491 /* Tracepoint hits should not be reported back to GDB, and
3492 if one got through somehow, it should have been filtered
3494 internal_error (__FILE__
, __LINE__
,
3495 _("bpstat_what: bp_tracepoint encountered"));
3498 current_action
= table
[(int) bs_class
][(int) current_action
];
3500 retval
.main_action
= current_action
;
3504 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3505 without hardware support). This isn't related to a specific bpstat,
3506 just to things like whether watchpoints are set. */
3509 bpstat_should_step (void)
3511 struct breakpoint
*b
;
3513 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
3520 static void print_breakpoint_location (struct breakpoint
*b
,
3521 struct bp_location
*loc
,
3523 struct ui_stream
*stb
)
3528 = find_pc_sect_function (loc
->address
, loc
->section
);
3531 ui_out_text (uiout
, "in ");
3532 ui_out_field_string (uiout
, "func",
3533 SYMBOL_PRINT_NAME (sym
));
3534 ui_out_wrap_hint (uiout
, wrap_indent
);
3535 ui_out_text (uiout
, " at ");
3537 ui_out_field_string (uiout
, "file", b
->source_file
);
3538 ui_out_text (uiout
, ":");
3540 if (ui_out_is_mi_like_p (uiout
))
3542 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3543 char *fullname
= symtab_to_fullname (sal
.symtab
);
3546 ui_out_field_string (uiout
, "fullname", fullname
);
3549 ui_out_field_int (uiout
, "line", b
->line_number
);
3553 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3557 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3558 ui_out_field_stream (uiout
, "at", stb
);
3562 /* Print B to gdb_stdout. */
3564 print_one_breakpoint_location (struct breakpoint
*b
,
3565 struct bp_location
*loc
,
3567 struct bp_location
**last_loc
,
3568 int print_address_bits
)
3570 struct command_line
*l
;
3572 struct ep_type_description
3577 static struct ep_type_description bptypes
[] =
3579 {bp_none
, "?deleted?"},
3580 {bp_breakpoint
, "breakpoint"},
3581 {bp_hardware_breakpoint
, "hw breakpoint"},
3582 {bp_until
, "until"},
3583 {bp_finish
, "finish"},
3584 {bp_watchpoint
, "watchpoint"},
3585 {bp_hardware_watchpoint
, "hw watchpoint"},
3586 {bp_read_watchpoint
, "read watchpoint"},
3587 {bp_access_watchpoint
, "acc watchpoint"},
3588 {bp_longjmp
, "longjmp"},
3589 {bp_longjmp_resume
, "longjmp resume"},
3590 {bp_step_resume
, "step resume"},
3591 {bp_watchpoint_scope
, "watchpoint scope"},
3592 {bp_call_dummy
, "call dummy"},
3593 {bp_shlib_event
, "shlib events"},
3594 {bp_thread_event
, "thread events"},
3595 {bp_overlay_event
, "overlay events"},
3596 {bp_longjmp_master
, "longjmp master"},
3597 {bp_catchpoint
, "catchpoint"},
3598 {bp_tracepoint
, "tracepoint"},
3601 static char bpenables
[] = "nynny";
3602 char wrap_indent
[80];
3603 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3604 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3605 struct cleanup
*bkpt_chain
;
3607 int header_of_multiple
= 0;
3608 int part_of_multiple
= (loc
!= NULL
);
3609 struct value_print_options opts
;
3611 get_user_print_options (&opts
);
3613 gdb_assert (!loc
|| loc_number
!= 0);
3614 /* See comment in print_one_breakpoint concerning
3615 treatment of breakpoints with single disabled
3619 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3620 header_of_multiple
= 1;
3625 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3629 if (part_of_multiple
)
3632 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3633 ui_out_field_string (uiout
, "number", formatted
);
3638 ui_out_field_int (uiout
, "number", b
->number
);
3643 if (part_of_multiple
)
3644 ui_out_field_skip (uiout
, "type");
3647 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3648 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3649 internal_error (__FILE__
, __LINE__
,
3650 _("bptypes table does not describe type #%d."),
3652 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3657 if (part_of_multiple
)
3658 ui_out_field_skip (uiout
, "disp");
3660 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3665 if (part_of_multiple
)
3666 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3668 ui_out_field_fmt (uiout
, "enabled", "%c",
3669 bpenables
[(int) b
->enable_state
]);
3670 ui_out_spaces (uiout
, 2);
3674 strcpy (wrap_indent
, " ");
3675 if (opts
.addressprint
)
3677 if (print_address_bits
<= 32)
3678 strcat (wrap_indent
, " ");
3680 strcat (wrap_indent
, " ");
3683 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3685 /* Although the print_one can possibly print
3686 all locations, calling it here is not likely
3687 to get any nice result. So, make sure there's
3688 just one location. */
3689 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3690 b
->ops
->print_one (b
, last_loc
);
3696 internal_error (__FILE__
, __LINE__
,
3697 _("print_one_breakpoint: bp_none encountered\n"));
3701 case bp_hardware_watchpoint
:
3702 case bp_read_watchpoint
:
3703 case bp_access_watchpoint
:
3704 /* Field 4, the address, is omitted (which makes the columns
3705 not line up too nicely with the headers, but the effect
3706 is relatively readable). */
3707 if (opts
.addressprint
)
3708 ui_out_field_skip (uiout
, "addr");
3710 ui_out_field_string (uiout
, "what", b
->exp_string
);
3714 case bp_hardware_breakpoint
:
3718 case bp_longjmp_resume
:
3719 case bp_step_resume
:
3720 case bp_watchpoint_scope
:
3722 case bp_shlib_event
:
3723 case bp_thread_event
:
3724 case bp_overlay_event
:
3725 case bp_longjmp_master
:
3727 if (opts
.addressprint
)
3730 if (header_of_multiple
)
3731 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3732 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3733 ui_out_field_string (uiout
, "addr", "<PENDING>");
3735 ui_out_field_core_addr (uiout
, "addr",
3736 loc
->gdbarch
, loc
->address
);
3739 if (!header_of_multiple
)
3740 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3746 if (!part_of_multiple
)
3748 if (b
->thread
!= -1)
3750 /* FIXME: This seems to be redundant and lost here; see the
3751 "stop only in" line a little further down. */
3752 ui_out_text (uiout
, " thread ");
3753 ui_out_field_int (uiout
, "thread", b
->thread
);
3755 else if (b
->task
!= 0)
3757 ui_out_text (uiout
, " task ");
3758 ui_out_field_int (uiout
, "task", b
->task
);
3762 ui_out_text (uiout
, "\n");
3764 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3767 ui_out_text (uiout
, "\tstop only in stack frame at ");
3768 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3770 ui_out_field_core_addr (uiout
, "frame",
3771 b
->gdbarch
, b
->frame_id
.stack_addr
);
3772 ui_out_text (uiout
, "\n");
3775 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3777 /* We do not print the condition for Ada exception catchpoints
3778 because the condition is an internal implementation detail
3779 that we do not want to expose to the user. */
3781 if (b
->type
== bp_tracepoint
)
3782 ui_out_text (uiout
, "\ttrace only if ");
3784 ui_out_text (uiout
, "\tstop only if ");
3785 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3786 ui_out_text (uiout
, "\n");
3789 if (!part_of_multiple
&& b
->thread
!= -1)
3791 /* FIXME should make an annotation for this */
3792 ui_out_text (uiout
, "\tstop only in thread ");
3793 ui_out_field_int (uiout
, "thread", b
->thread
);
3794 ui_out_text (uiout
, "\n");
3797 if (!part_of_multiple
&& b
->hit_count
)
3799 /* FIXME should make an annotation for this */
3800 if (ep_is_catchpoint (b
))
3801 ui_out_text (uiout
, "\tcatchpoint");
3803 ui_out_text (uiout
, "\tbreakpoint");
3804 ui_out_text (uiout
, " already hit ");
3805 ui_out_field_int (uiout
, "times", b
->hit_count
);
3806 if (b
->hit_count
== 1)
3807 ui_out_text (uiout
, " time\n");
3809 ui_out_text (uiout
, " times\n");
3812 /* Output the count also if it is zero, but only if this is
3813 mi. FIXME: Should have a better test for this. */
3814 if (ui_out_is_mi_like_p (uiout
))
3815 if (!part_of_multiple
&& b
->hit_count
== 0)
3816 ui_out_field_int (uiout
, "times", b
->hit_count
);
3818 if (!part_of_multiple
&& b
->ignore_count
)
3821 ui_out_text (uiout
, "\tignore next ");
3822 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3823 ui_out_text (uiout
, " hits\n");
3827 if (!part_of_multiple
&& l
)
3829 struct cleanup
*script_chain
;
3832 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3833 print_command_lines (uiout
, l
, 4);
3834 do_cleanups (script_chain
);
3837 if (!part_of_multiple
&& b
->pass_count
)
3839 annotate_field (10);
3840 ui_out_text (uiout
, "\tpass count ");
3841 ui_out_field_int (uiout
, "pass", b
->pass_count
);
3842 ui_out_text (uiout
, " \n");
3845 if (!part_of_multiple
&& b
->step_count
)
3847 annotate_field (11);
3848 ui_out_text (uiout
, "\tstep count ");
3849 ui_out_field_int (uiout
, "step", b
->step_count
);
3850 ui_out_text (uiout
, " \n");
3853 if (!part_of_multiple
&& b
->actions
)
3855 struct action_line
*action
;
3856 annotate_field (12);
3857 for (action
= b
->actions
; action
; action
= action
->next
)
3859 ui_out_text (uiout
, " A\t");
3860 ui_out_text (uiout
, action
->action
);
3861 ui_out_text (uiout
, "\n");
3865 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3868 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3869 else if (b
->exp_string
)
3870 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3873 do_cleanups (bkpt_chain
);
3874 do_cleanups (old_chain
);
3878 print_one_breakpoint (struct breakpoint
*b
,
3879 struct bp_location
**last_loc
, int print_address_bits
)
3881 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, print_address_bits
);
3883 /* If this breakpoint has custom print function,
3884 it's already printed. Otherwise, print individual
3885 locations, if any. */
3886 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3888 /* If breakpoint has a single location that is
3889 disabled, we print it as if it had
3890 several locations, since otherwise it's hard to
3891 represent "breakpoint enabled, location disabled"
3893 Note that while hardware watchpoints have
3894 several locations internally, that's no a property
3897 && !is_hardware_watchpoint (b
)
3898 && (b
->loc
->next
|| !b
->loc
->enabled
)
3899 && !ui_out_is_mi_like_p (uiout
))
3901 struct bp_location
*loc
;
3903 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3904 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
3905 print_address_bits
);
3911 breakpoint_address_bits (struct breakpoint
*b
)
3913 int print_address_bits
= 0;
3914 struct bp_location
*loc
;
3916 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3918 int addr_bit
= gdbarch_addr_bit (b
->gdbarch
);
3919 if (addr_bit
> print_address_bits
)
3920 print_address_bits
= addr_bit
;
3923 return print_address_bits
;
3926 struct captured_breakpoint_query_args
3932 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3934 struct captured_breakpoint_query_args
*args
= data
;
3935 struct breakpoint
*b
;
3936 struct bp_location
*dummy_loc
= NULL
;
3939 if (args
->bnum
== b
->number
)
3941 int print_address_bits
= breakpoint_address_bits (b
);
3942 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
);
3950 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3952 struct captured_breakpoint_query_args args
;
3954 /* For the moment we don't trust print_one_breakpoint() to not throw
3956 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3957 error_message
, RETURN_MASK_ALL
) < 0)
3963 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3964 catchpoints, et.al.). */
3967 user_settable_breakpoint (const struct breakpoint
*b
)
3969 return (b
->type
== bp_breakpoint
3970 || b
->type
== bp_catchpoint
3971 || b
->type
== bp_hardware_breakpoint
3972 || b
->type
== bp_tracepoint
3973 || b
->type
== bp_watchpoint
3974 || b
->type
== bp_read_watchpoint
3975 || b
->type
== bp_access_watchpoint
3976 || b
->type
== bp_hardware_watchpoint
);
3979 /* Print information on user settable breakpoint (watchpoint, etc)
3980 number BNUM. If BNUM is -1 print all user settable breakpoints.
3981 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3984 breakpoint_1 (int bnum
, int allflag
)
3986 struct breakpoint
*b
;
3987 struct bp_location
*last_loc
= NULL
;
3988 int nr_printable_breakpoints
;
3989 struct cleanup
*bkpttbl_chain
;
3990 struct value_print_options opts
;
3991 int print_address_bits
= 0;
3993 get_user_print_options (&opts
);
3995 /* Compute the number of rows in the table, as well as the
3996 size required for address fields. */
3997 nr_printable_breakpoints
= 0;
4000 || bnum
== b
->number
)
4002 if (allflag
|| user_settable_breakpoint (b
))
4004 int addr_bit
= breakpoint_address_bits (b
);
4005 if (addr_bit
> print_address_bits
)
4006 print_address_bits
= addr_bit
;
4008 nr_printable_breakpoints
++;
4012 if (opts
.addressprint
)
4014 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4018 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4021 if (nr_printable_breakpoints
> 0)
4022 annotate_breakpoints_headers ();
4023 if (nr_printable_breakpoints
> 0)
4025 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4026 if (nr_printable_breakpoints
> 0)
4028 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4029 if (nr_printable_breakpoints
> 0)
4031 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4032 if (nr_printable_breakpoints
> 0)
4034 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4035 if (opts
.addressprint
)
4037 if (nr_printable_breakpoints
> 0)
4039 if (print_address_bits
<= 32)
4040 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4042 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4044 if (nr_printable_breakpoints
> 0)
4046 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4047 ui_out_table_body (uiout
);
4048 if (nr_printable_breakpoints
> 0)
4049 annotate_breakpoints_table ();
4053 || bnum
== b
->number
)
4055 /* We only print out user settable breakpoints unless the
4057 if (allflag
|| user_settable_breakpoint (b
))
4058 print_one_breakpoint (b
, &last_loc
, print_address_bits
);
4061 do_cleanups (bkpttbl_chain
);
4063 if (nr_printable_breakpoints
== 0)
4066 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
4068 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
4073 if (last_loc
&& !server_command
)
4074 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
4077 /* FIXME? Should this be moved up so that it is only called when
4078 there have been breakpoints? */
4079 annotate_breakpoints_table_end ();
4083 breakpoints_info (char *bnum_exp
, int from_tty
)
4088 bnum
= parse_and_eval_long (bnum_exp
);
4090 breakpoint_1 (bnum
, 0);
4094 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4099 bnum
= parse_and_eval_long (bnum_exp
);
4101 breakpoint_1 (bnum
, 1);
4105 breakpoint_has_pc (struct breakpoint
*b
,
4106 CORE_ADDR pc
, struct obj_section
*section
)
4108 struct bp_location
*bl
= b
->loc
;
4109 for (; bl
; bl
= bl
->next
)
4111 if (bl
->address
== pc
4112 && (!overlay_debugging
|| bl
->section
== section
))
4118 /* Print a message describing any breakpoints set at PC. */
4121 describe_other_breakpoints (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
4122 struct obj_section
*section
, int thread
)
4125 struct breakpoint
*b
;
4128 others
+= breakpoint_has_pc (b
, pc
, section
);
4132 printf_filtered (_("Note: breakpoint "));
4133 else /* if (others == ???) */
4134 printf_filtered (_("Note: breakpoints "));
4136 if (breakpoint_has_pc (b
, pc
, section
))
4139 printf_filtered ("%d", b
->number
);
4140 if (b
->thread
== -1 && thread
!= -1)
4141 printf_filtered (" (all threads)");
4142 else if (b
->thread
!= -1)
4143 printf_filtered (" (thread %d)", b
->thread
);
4144 printf_filtered ("%s%s ",
4145 ((b
->enable_state
== bp_disabled
4146 || b
->enable_state
== bp_call_disabled
4147 || b
->enable_state
== bp_startup_disabled
)
4149 : b
->enable_state
== bp_permanent
4153 : ((others
== 1) ? " and" : ""));
4155 printf_filtered (_("also set at pc "));
4156 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
4157 printf_filtered (".\n");
4161 /* Set the default place to put a breakpoint
4162 for the `break' command with no arguments. */
4165 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4168 default_breakpoint_valid
= valid
;
4169 default_breakpoint_address
= addr
;
4170 default_breakpoint_symtab
= symtab
;
4171 default_breakpoint_line
= line
;
4174 /* Return true iff it is meaningful to use the address member of
4175 BPT. For some breakpoint types, the address member is irrelevant
4176 and it makes no sense to attempt to compare it to other addresses
4177 (or use it for any other purpose either).
4179 More specifically, each of the following breakpoint types will always
4180 have a zero valued address and we don't want check_duplicates() to mark
4181 breakpoints of any of these types to be a duplicate of an actual
4182 breakpoint at address zero:
4185 bp_hardware_watchpoint
4187 bp_access_watchpoint
4191 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4193 enum bptype type
= bpt
->type
;
4195 return (type
!= bp_watchpoint
4196 && type
!= bp_hardware_watchpoint
4197 && type
!= bp_read_watchpoint
4198 && type
!= bp_access_watchpoint
4199 && type
!= bp_catchpoint
);
4202 /* Rescan breakpoints at the same address and section as BPT,
4203 marking the first one as "first" and any others as "duplicates".
4204 This is so that the bpt instruction is only inserted once.
4205 If we have a permanent breakpoint at the same place as BPT, make
4206 that one the official one, and the rest as duplicates. */
4209 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
4211 struct bp_location
*b
;
4213 struct bp_location
*perm_bp
= 0;
4215 ALL_BP_LOCATIONS (b
)
4216 if (b
->owner
->enable_state
!= bp_disabled
4217 && b
->owner
->enable_state
!= bp_call_disabled
4218 && b
->owner
->enable_state
!= bp_startup_disabled
4220 && !b
->shlib_disabled
4221 && b
->address
== address
/* address / overlay match */
4222 && (!overlay_debugging
|| b
->section
== section
)
4223 && breakpoint_address_is_meaningful (b
->owner
))
4225 /* Have we found a permanent breakpoint? */
4226 if (b
->owner
->enable_state
== bp_permanent
)
4233 b
->duplicate
= count
> 1;
4236 /* If we found a permanent breakpoint at this address, go over the
4237 list again and declare all the other breakpoints there (except
4238 other permanent breakpoints) to be the duplicates. */
4241 perm_bp
->duplicate
= 0;
4243 /* Permanent breakpoint should always be inserted. */
4244 if (! perm_bp
->inserted
)
4245 internal_error (__FILE__
, __LINE__
,
4246 _("allegedly permanent breakpoint is not "
4247 "actually inserted"));
4249 ALL_BP_LOCATIONS (b
)
4252 if (b
->owner
->enable_state
!= bp_permanent
4253 && b
->owner
->enable_state
!= bp_disabled
4254 && b
->owner
->enable_state
!= bp_call_disabled
4255 && b
->owner
->enable_state
!= bp_startup_disabled
4256 && b
->enabled
&& !b
->shlib_disabled
4257 && b
->address
== address
/* address / overlay match */
4258 && (!overlay_debugging
|| b
->section
== section
)
4259 && breakpoint_address_is_meaningful (b
->owner
))
4262 internal_error (__FILE__
, __LINE__
,
4263 _("another breakpoint was inserted on top of "
4264 "a permanent breakpoint"));
4273 check_duplicates (struct breakpoint
*bpt
)
4275 struct bp_location
*bl
= bpt
->loc
;
4277 if (! breakpoint_address_is_meaningful (bpt
))
4280 for (; bl
; bl
= bl
->next
)
4281 check_duplicates_for (bl
->address
, bl
->section
);
4285 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4286 int bnum
, int have_bnum
)
4291 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4292 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4294 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4295 bnum
, astr1
, astr2
);
4297 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4300 /* Adjust a breakpoint's address to account for architectural constraints
4301 on breakpoint placement. Return the adjusted address. Note: Very
4302 few targets require this kind of adjustment. For most targets,
4303 this function is simply the identity function. */
4306 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
4307 CORE_ADDR bpaddr
, enum bptype bptype
)
4309 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
4311 /* Very few targets need any kind of breakpoint adjustment. */
4314 else if (bptype
== bp_watchpoint
4315 || bptype
== bp_hardware_watchpoint
4316 || bptype
== bp_read_watchpoint
4317 || bptype
== bp_access_watchpoint
4318 || bptype
== bp_catchpoint
)
4320 /* Watchpoints and the various bp_catch_* eventpoints should not
4321 have their addresses modified. */
4326 CORE_ADDR adjusted_bpaddr
;
4328 /* Some targets have architectural constraints on the placement
4329 of breakpoint instructions. Obtain the adjusted address. */
4330 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
4332 /* An adjusted breakpoint address can significantly alter
4333 a user's expectations. Print a warning if an adjustment
4335 if (adjusted_bpaddr
!= bpaddr
)
4336 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4338 return adjusted_bpaddr
;
4342 /* Allocate a struct bp_location. */
4344 static struct bp_location
*
4345 allocate_bp_location (struct breakpoint
*bpt
)
4347 struct bp_location
*loc
, *loc_p
;
4349 loc
= xmalloc (sizeof (struct bp_location
));
4350 memset (loc
, 0, sizeof (*loc
));
4354 loc
->shlib_disabled
= 0;
4364 case bp_longjmp_resume
:
4365 case bp_step_resume
:
4366 case bp_watchpoint_scope
:
4368 case bp_shlib_event
:
4369 case bp_thread_event
:
4370 case bp_overlay_event
:
4371 case bp_longjmp_master
:
4372 loc
->loc_type
= bp_loc_software_breakpoint
;
4374 case bp_hardware_breakpoint
:
4375 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4377 case bp_hardware_watchpoint
:
4378 case bp_read_watchpoint
:
4379 case bp_access_watchpoint
:
4380 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4384 loc
->loc_type
= bp_loc_other
;
4387 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4393 static void free_bp_location (struct bp_location
*loc
)
4398 if (loc
->function_name
)
4399 xfree (loc
->function_name
);
4404 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4405 that has type BPTYPE and has no locations as yet. */
4406 /* This function is used in gdbtk sources and thus can not be made static. */
4408 static struct breakpoint
*
4409 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
4412 struct breakpoint
*b
, *b1
;
4414 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4415 memset (b
, 0, sizeof (*b
));
4418 b
->gdbarch
= gdbarch
;
4419 b
->language
= current_language
->la_language
;
4420 b
->input_radix
= input_radix
;
4422 b
->enable_state
= bp_enabled
;
4425 b
->ignore_count
= 0;
4427 b
->frame_id
= null_frame_id
;
4428 b
->forked_inferior_pid
= null_ptid
;
4429 b
->exec_pathname
= NULL
;
4431 b
->condition_not_parsed
= 0;
4433 /* Add this breakpoint to the end of the chain
4434 so that a list of breakpoints will come out in order
4435 of increasing numbers. */
4437 b1
= breakpoint_chain
;
4439 breakpoint_chain
= b
;
4449 /* Initialize loc->function_name. */
4451 set_breakpoint_location_function (struct bp_location
*loc
)
4453 if (loc
->owner
->type
== bp_breakpoint
4454 || loc
->owner
->type
== bp_hardware_breakpoint
4455 || loc
->owner
->type
== bp_tracepoint
)
4457 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4459 if (loc
->function_name
)
4460 loc
->function_name
= xstrdup (loc
->function_name
);
4464 /* Attempt to determine architecture of location identified by SAL. */
4465 static struct gdbarch
*
4466 get_sal_arch (struct symtab_and_line sal
)
4469 return get_objfile_arch (sal
.section
->objfile
);
4471 return get_objfile_arch (sal
.symtab
->objfile
);
4476 /* set_raw_breakpoint is a low level routine for allocating and
4477 partially initializing a breakpoint of type BPTYPE. The newly
4478 created breakpoint's address, section, source file name, and line
4479 number are provided by SAL. The newly created and partially
4480 initialized breakpoint is added to the breakpoint chain and
4481 is also returned as the value of this function.
4483 It is expected that the caller will complete the initialization of
4484 the newly created breakpoint struct as well as output any status
4485 information regarding the creation of a new breakpoint. In
4486 particular, set_raw_breakpoint does NOT set the breakpoint
4487 number! Care should be taken to not allow an error to occur
4488 prior to completing the initialization of the breakpoint. If this
4489 should happen, a bogus breakpoint will be left on the chain. */
4492 set_raw_breakpoint (struct gdbarch
*gdbarch
,
4493 struct symtab_and_line sal
, enum bptype bptype
)
4495 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
4496 CORE_ADDR adjusted_address
;
4497 struct gdbarch
*loc_gdbarch
;
4499 loc_gdbarch
= get_sal_arch (sal
);
4501 loc_gdbarch
= b
->gdbarch
;
4503 /* Adjust the breakpoint's address prior to allocating a location.
4504 Once we call allocate_bp_location(), that mostly uninitialized
4505 location will be placed on the location chain. Adjustment of the
4506 breakpoint may cause target_read_memory() to be called and we do
4507 not want its scan of the location chain to find a breakpoint and
4508 location that's only been partially initialized. */
4509 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
4511 b
->loc
= allocate_bp_location (b
);
4512 b
->loc
->gdbarch
= loc_gdbarch
;
4513 b
->loc
->requested_address
= sal
.pc
;
4514 b
->loc
->address
= adjusted_address
;
4516 if (sal
.symtab
== NULL
)
4517 b
->source_file
= NULL
;
4519 b
->source_file
= xstrdup (sal
.symtab
->filename
);
4520 b
->loc
->section
= sal
.section
;
4521 b
->line_number
= sal
.line
;
4523 set_breakpoint_location_function (b
->loc
);
4525 breakpoints_changed ();
4531 /* Note that the breakpoint object B describes a permanent breakpoint
4532 instruction, hard-wired into the inferior's code. */
4534 make_breakpoint_permanent (struct breakpoint
*b
)
4536 struct bp_location
*bl
;
4537 b
->enable_state
= bp_permanent
;
4539 /* By definition, permanent breakpoints are already present in the code.
4540 Mark all locations as inserted. For now, make_breakpoint_permanent
4541 is called in just one place, so it's hard to say if it's reasonable
4542 to have permanent breakpoint with multiple locations or not,
4543 but it's easy to implmement. */
4544 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4548 /* Call this routine when stepping and nexting to enable a breakpoint
4549 if we do a longjmp() in THREAD. When we hit that breakpoint, call
4550 set_longjmp_resume_breakpoint() to figure out where we are going. */
4553 set_longjmp_breakpoint (int thread
)
4555 struct breakpoint
*b
, *temp
;
4557 /* To avoid having to rescan all objfile symbols at every step,
4558 we maintain a list of continually-inserted but always disabled
4559 longjmp "master" breakpoints. Here, we simply create momentary
4560 clones of those and enable them for the requested thread. */
4561 ALL_BREAKPOINTS_SAFE (b
, temp
)
4562 if (b
->type
== bp_longjmp_master
)
4564 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
4565 clone
->type
= bp_longjmp
;
4566 clone
->thread
= thread
;
4570 /* Delete all longjmp breakpoints from THREAD. */
4572 delete_longjmp_breakpoint (int thread
)
4574 struct breakpoint
*b
, *temp
;
4576 ALL_BREAKPOINTS_SAFE (b
, temp
)
4577 if (b
->type
== bp_longjmp
)
4579 if (b
->thread
== thread
)
4580 delete_breakpoint (b
);
4585 enable_overlay_breakpoints (void)
4587 struct breakpoint
*b
;
4590 if (b
->type
== bp_overlay_event
)
4592 b
->enable_state
= bp_enabled
;
4593 update_global_location_list (1);
4594 overlay_events_enabled
= 1;
4599 disable_overlay_breakpoints (void)
4601 struct breakpoint
*b
;
4604 if (b
->type
== bp_overlay_event
)
4606 b
->enable_state
= bp_disabled
;
4607 update_global_location_list (0);
4608 overlay_events_enabled
= 0;
4613 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
4615 struct breakpoint
*b
;
4617 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
4619 b
->enable_state
= bp_enabled
;
4620 /* addr_string has to be used or breakpoint_re_set will delete me. */
4622 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
4624 update_global_location_list_nothrow (1);
4630 remove_thread_event_breakpoints (void)
4632 struct breakpoint
*b
, *temp
;
4634 ALL_BREAKPOINTS_SAFE (b
, temp
)
4635 if (b
->type
== bp_thread_event
)
4636 delete_breakpoint (b
);
4639 struct captured_parse_breakpoint_args
4642 struct symtabs_and_lines
*sals_p
;
4643 char ***addr_string_p
;
4647 struct lang_and_radix
4655 remove_solib_event_breakpoints (void)
4657 struct breakpoint
*b
, *temp
;
4659 ALL_BREAKPOINTS_SAFE (b
, temp
)
4660 if (b
->type
== bp_shlib_event
)
4661 delete_breakpoint (b
);
4665 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
4667 struct breakpoint
*b
;
4669 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
4670 update_global_location_list_nothrow (1);
4674 /* Disable any breakpoints that are on code in shared libraries. Only
4675 apply to enabled breakpoints, disabled ones can just stay disabled. */
4678 disable_breakpoints_in_shlibs (void)
4680 struct bp_location
*loc
;
4682 ALL_BP_LOCATIONS (loc
)
4684 struct breakpoint
*b
= loc
->owner
;
4685 /* We apply the check to all breakpoints, including disabled
4686 for those with loc->duplicate set. This is so that when breakpoint
4687 becomes enabled, or the duplicate is removed, gdb will try to insert
4688 all breakpoints. If we don't set shlib_disabled here, we'll try
4689 to insert those breakpoints and fail. */
4690 if (((b
->type
== bp_breakpoint
)
4691 || (b
->type
== bp_hardware_breakpoint
)
4692 || (b
->type
== bp_tracepoint
))
4693 && !loc
->shlib_disabled
4695 && PC_SOLIB (loc
->address
)
4697 && solib_name_from_address (loc
->address
)
4701 loc
->shlib_disabled
= 1;
4706 /* Disable any breakpoints that are in in an unloaded shared library. Only
4707 apply to enabled breakpoints, disabled ones can just stay disabled. */
4710 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4712 struct bp_location
*loc
;
4713 int disabled_shlib_breaks
= 0;
4715 /* SunOS a.out shared libraries are always mapped, so do not
4716 disable breakpoints; they will only be reported as unloaded
4717 through clear_solib when GDB discards its shared library
4718 list. See clear_solib for more information. */
4719 if (exec_bfd
!= NULL
4720 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
4723 ALL_BP_LOCATIONS (loc
)
4725 struct breakpoint
*b
= loc
->owner
;
4726 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4727 || loc
->loc_type
== bp_loc_software_breakpoint
)
4728 && !loc
->shlib_disabled
4729 && (b
->type
== bp_breakpoint
|| b
->type
== bp_hardware_breakpoint
)
4730 && solib_contains_address_p (solib
, loc
->address
))
4732 loc
->shlib_disabled
= 1;
4733 /* At this point, we cannot rely on remove_breakpoint
4734 succeeding so we must mark the breakpoint as not inserted
4735 to prevent future errors occurring in remove_breakpoints. */
4737 if (!disabled_shlib_breaks
)
4739 target_terminal_ours_for_output ();
4740 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4743 disabled_shlib_breaks
= 1;
4748 /* FORK & VFORK catchpoints. */
4750 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4753 insert_catch_fork (struct breakpoint
*b
)
4755 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4758 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4761 remove_catch_fork (struct breakpoint
*b
)
4763 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4766 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4770 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4772 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4775 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4777 static enum print_stop_action
4778 print_it_catch_fork (struct breakpoint
*b
)
4780 annotate_catchpoint (b
->number
);
4781 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4782 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4783 return PRINT_SRC_AND_LOC
;
4786 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4789 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
4791 struct value_print_options opts
;
4793 get_user_print_options (&opts
);
4795 /* Field 4, the address, is omitted (which makes the columns
4796 not line up too nicely with the headers, but the effect
4797 is relatively readable). */
4798 if (opts
.addressprint
)
4799 ui_out_field_skip (uiout
, "addr");
4801 ui_out_text (uiout
, "fork");
4802 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4804 ui_out_text (uiout
, ", process ");
4805 ui_out_field_int (uiout
, "what",
4806 ptid_get_pid (b
->forked_inferior_pid
));
4807 ui_out_spaces (uiout
, 1);
4811 /* Implement the "print_mention" breakpoint_ops method for fork
4815 print_mention_catch_fork (struct breakpoint
*b
)
4817 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4820 /* The breakpoint_ops structure to be used in fork catchpoints. */
4822 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4826 breakpoint_hit_catch_fork
,
4827 print_it_catch_fork
,
4828 print_one_catch_fork
,
4829 print_mention_catch_fork
4832 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4835 insert_catch_vfork (struct breakpoint
*b
)
4837 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4840 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4843 remove_catch_vfork (struct breakpoint
*b
)
4845 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4848 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4852 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4854 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4857 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4859 static enum print_stop_action
4860 print_it_catch_vfork (struct breakpoint
*b
)
4862 annotate_catchpoint (b
->number
);
4863 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4864 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4865 return PRINT_SRC_AND_LOC
;
4868 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4871 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
4873 struct value_print_options opts
;
4875 get_user_print_options (&opts
);
4876 /* Field 4, the address, is omitted (which makes the columns
4877 not line up too nicely with the headers, but the effect
4878 is relatively readable). */
4879 if (opts
.addressprint
)
4880 ui_out_field_skip (uiout
, "addr");
4882 ui_out_text (uiout
, "vfork");
4883 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4885 ui_out_text (uiout
, ", process ");
4886 ui_out_field_int (uiout
, "what",
4887 ptid_get_pid (b
->forked_inferior_pid
));
4888 ui_out_spaces (uiout
, 1);
4892 /* Implement the "print_mention" breakpoint_ops method for vfork
4896 print_mention_catch_vfork (struct breakpoint
*b
)
4898 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4901 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4903 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4907 breakpoint_hit_catch_vfork
,
4908 print_it_catch_vfork
,
4909 print_one_catch_vfork
,
4910 print_mention_catch_vfork
4913 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4915 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4916 If COND_STRING is not NULL, then store it in the breakpoint.
4917 OPS, if not NULL, is the breakpoint_ops structure associated
4918 to the catchpoint. */
4920 static struct breakpoint
*
4921 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
4922 char *cond_string
, struct breakpoint_ops
*ops
)
4924 struct symtab_and_line sal
;
4925 struct breakpoint
*b
;
4932 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
4933 set_breakpoint_count (breakpoint_count
+ 1);
4934 b
->number
= breakpoint_count
;
4936 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
4938 b
->addr_string
= NULL
;
4939 b
->enable_state
= bp_enabled
;
4940 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4944 update_global_location_list (1);
4950 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
4951 int tempflag
, char *cond_string
,
4952 struct breakpoint_ops
*ops
)
4954 struct breakpoint
*b
4955 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
4957 /* FIXME: We should put this information in a breakpoint private data
4959 b
->forked_inferior_pid
= null_ptid
;
4962 /* Exec catchpoints. */
4965 insert_catch_exec (struct breakpoint
*b
)
4967 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
4971 remove_catch_exec (struct breakpoint
*b
)
4973 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
4977 breakpoint_hit_catch_exec (struct breakpoint
*b
)
4979 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
4982 static enum print_stop_action
4983 print_it_catch_exec (struct breakpoint
*b
)
4985 annotate_catchpoint (b
->number
);
4986 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
4988 return PRINT_SRC_AND_LOC
;
4992 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
4994 struct value_print_options opts
;
4996 get_user_print_options (&opts
);
4998 /* Field 4, the address, is omitted (which makes the columns
4999 not line up too nicely with the headers, but the effect
5000 is relatively readable). */
5001 if (opts
.addressprint
)
5002 ui_out_field_skip (uiout
, "addr");
5004 ui_out_text (uiout
, "exec");
5005 if (b
->exec_pathname
!= NULL
)
5007 ui_out_text (uiout
, ", program \"");
5008 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
5009 ui_out_text (uiout
, "\" ");
5014 print_mention_catch_exec (struct breakpoint
*b
)
5016 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
5019 static struct breakpoint_ops catch_exec_breakpoint_ops
=
5023 breakpoint_hit_catch_exec
,
5024 print_it_catch_exec
,
5025 print_one_catch_exec
,
5026 print_mention_catch_exec
5030 hw_breakpoint_used_count (void)
5032 struct breakpoint
*b
;
5037 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
5045 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
5047 struct breakpoint
*b
;
5050 *other_type_used
= 0;
5053 if (breakpoint_enabled (b
))
5055 if (b
->type
== type
)
5057 else if ((b
->type
== bp_hardware_watchpoint
5058 || b
->type
== bp_read_watchpoint
5059 || b
->type
== bp_access_watchpoint
))
5060 *other_type_used
= 1;
5067 disable_watchpoints_before_interactive_call_start (void)
5069 struct breakpoint
*b
;
5073 if (((b
->type
== bp_watchpoint
)
5074 || (b
->type
== bp_hardware_watchpoint
)
5075 || (b
->type
== bp_read_watchpoint
)
5076 || (b
->type
== bp_access_watchpoint
))
5077 && breakpoint_enabled (b
))
5079 b
->enable_state
= bp_call_disabled
;
5080 update_global_location_list (0);
5086 enable_watchpoints_after_interactive_call_stop (void)
5088 struct breakpoint
*b
;
5092 if (((b
->type
== bp_watchpoint
)
5093 || (b
->type
== bp_hardware_watchpoint
)
5094 || (b
->type
== bp_read_watchpoint
)
5095 || (b
->type
== bp_access_watchpoint
))
5096 && (b
->enable_state
== bp_call_disabled
))
5098 b
->enable_state
= bp_enabled
;
5099 update_global_location_list (1);
5105 disable_breakpoints_before_startup (void)
5107 struct breakpoint
*b
;
5112 if ((b
->type
== bp_breakpoint
5113 || b
->type
== bp_hardware_breakpoint
)
5114 && breakpoint_enabled (b
))
5116 b
->enable_state
= bp_startup_disabled
;
5122 update_global_location_list (0);
5124 executing_startup
= 1;
5128 enable_breakpoints_after_startup (void)
5130 struct breakpoint
*b
;
5133 executing_startup
= 0;
5137 if ((b
->type
== bp_breakpoint
5138 || b
->type
== bp_hardware_breakpoint
)
5139 && b
->enable_state
== bp_startup_disabled
)
5141 b
->enable_state
= bp_enabled
;
5147 breakpoint_re_set ();
5151 /* Set a breakpoint that will evaporate an end of command
5152 at address specified by SAL.
5153 Restrict it to frame FRAME if FRAME is nonzero. */
5156 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
5157 struct frame_id frame_id
, enum bptype type
)
5159 struct breakpoint
*b
;
5161 /* If FRAME_ID is valid, it should be a real frame, not an inlined
5163 gdb_assert (!frame_id_inlined_p (frame_id
));
5165 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
5166 b
->enable_state
= bp_enabled
;
5167 b
->disposition
= disp_donttouch
;
5168 b
->frame_id
= frame_id
;
5170 /* If we're debugging a multi-threaded program, then we
5171 want momentary breakpoints to be active in only a
5172 single thread of control. */
5173 if (in_thread_list (inferior_ptid
))
5174 b
->thread
= pid_to_thread_id (inferior_ptid
);
5176 update_global_location_list_nothrow (1);
5181 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
5185 clone_momentary_breakpoint (struct breakpoint
*orig
)
5187 struct breakpoint
*copy
;
5189 /* If there's nothing to clone, then return nothing. */
5193 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
5194 copy
->loc
= allocate_bp_location (copy
);
5195 set_breakpoint_location_function (copy
->loc
);
5197 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
5198 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
5199 copy
->loc
->address
= orig
->loc
->address
;
5200 copy
->loc
->section
= orig
->loc
->section
;
5202 if (orig
->source_file
== NULL
)
5203 copy
->source_file
= NULL
;
5205 copy
->source_file
= xstrdup (orig
->source_file
);
5207 copy
->line_number
= orig
->line_number
;
5208 copy
->frame_id
= orig
->frame_id
;
5209 copy
->thread
= orig
->thread
;
5211 copy
->enable_state
= bp_enabled
;
5212 copy
->disposition
= disp_donttouch
;
5213 copy
->number
= internal_breakpoint_number
--;
5215 update_global_location_list_nothrow (0);
5220 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
5223 struct symtab_and_line sal
;
5225 sal
= find_pc_line (pc
, 0);
5227 sal
.section
= find_pc_overlay (pc
);
5228 sal
.explicit_pc
= 1;
5230 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
5234 /* Tell the user we have just set a breakpoint B. */
5237 mention (struct breakpoint
*b
)
5240 struct cleanup
*ui_out_chain
;
5241 struct value_print_options opts
;
5243 get_user_print_options (&opts
);
5245 /* FIXME: This is misplaced; mention() is called by things (like
5246 hitting a watchpoint) other than breakpoint creation. It should
5247 be possible to clean this up and at the same time replace the
5248 random calls to breakpoint_changed with this hook. */
5249 observer_notify_breakpoint_created (b
->number
);
5251 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
5252 b
->ops
->print_mention (b
);
5257 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
5260 ui_out_text (uiout
, "Watchpoint ");
5261 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5262 ui_out_field_int (uiout
, "number", b
->number
);
5263 ui_out_text (uiout
, ": ");
5264 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5265 do_cleanups (ui_out_chain
);
5267 case bp_hardware_watchpoint
:
5268 ui_out_text (uiout
, "Hardware watchpoint ");
5269 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5270 ui_out_field_int (uiout
, "number", b
->number
);
5271 ui_out_text (uiout
, ": ");
5272 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5273 do_cleanups (ui_out_chain
);
5275 case bp_read_watchpoint
:
5276 ui_out_text (uiout
, "Hardware read watchpoint ");
5277 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
5278 ui_out_field_int (uiout
, "number", b
->number
);
5279 ui_out_text (uiout
, ": ");
5280 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5281 do_cleanups (ui_out_chain
);
5283 case bp_access_watchpoint
:
5284 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
5285 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
5286 ui_out_field_int (uiout
, "number", b
->number
);
5287 ui_out_text (uiout
, ": ");
5288 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5289 do_cleanups (ui_out_chain
);
5292 if (ui_out_is_mi_like_p (uiout
))
5297 if (b
->disposition
== disp_del
)
5298 printf_filtered (_("Temporary breakpoint"));
5300 printf_filtered (_("Breakpoint"));
5301 printf_filtered (_(" %d"), b
->number
);
5304 case bp_hardware_breakpoint
:
5305 if (ui_out_is_mi_like_p (uiout
))
5310 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
5314 if (ui_out_is_mi_like_p (uiout
))
5319 printf_filtered (_("Tracepoint"));
5320 printf_filtered (_(" %d"), b
->number
);
5327 case bp_longjmp_resume
:
5328 case bp_step_resume
:
5330 case bp_watchpoint_scope
:
5331 case bp_shlib_event
:
5332 case bp_thread_event
:
5333 case bp_overlay_event
:
5334 case bp_longjmp_master
:
5340 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5344 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5348 if (opts
.addressprint
|| b
->source_file
== NULL
)
5350 printf_filtered (" at ");
5351 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
5355 printf_filtered (": file %s, line %d.",
5356 b
->source_file
, b
->line_number
);
5360 struct bp_location
*loc
= b
->loc
;
5362 for (; loc
; loc
= loc
->next
)
5364 printf_filtered (" (%d locations)", n
);
5369 if (ui_out_is_mi_like_p (uiout
))
5371 printf_filtered ("\n");
5375 static struct bp_location
*
5376 add_location_to_breakpoint (struct breakpoint
*b
,
5377 const struct symtab_and_line
*sal
)
5379 struct bp_location
*loc
, **tmp
;
5381 loc
= allocate_bp_location (b
);
5382 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5385 loc
->gdbarch
= get_sal_arch (*sal
);
5387 loc
->gdbarch
= b
->gdbarch
;
5388 loc
->requested_address
= sal
->pc
;
5389 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
5390 loc
->requested_address
, b
->type
);
5391 loc
->section
= sal
->section
;
5393 set_breakpoint_location_function (loc
);
5398 /* Return 1 if LOC is pointing to a permanent breakpoint,
5399 return 0 otherwise. */
5402 bp_loc_is_permanent (struct bp_location
*loc
)
5406 const gdb_byte
*brk
;
5407 gdb_byte
*target_mem
;
5408 struct cleanup
*cleanup
;
5411 gdb_assert (loc
!= NULL
);
5413 addr
= loc
->address
;
5414 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
5416 /* Software breakpoints unsupported? */
5420 target_mem
= alloca (len
);
5422 /* Enable the automatic memory restoration from breakpoints while
5423 we read the memory. Otherwise we could say about our temporary
5424 breakpoints they are permanent. */
5425 cleanup
= make_show_memory_breakpoints_cleanup (0);
5427 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5428 && memcmp (target_mem
, brk
, len
) == 0)
5431 do_cleanups (cleanup
);
5438 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5439 as textual description of the location, and COND_STRING
5440 as condition expression. */
5443 create_breakpoint (struct gdbarch
*gdbarch
,
5444 struct symtabs_and_lines sals
, char *addr_string
,
5446 enum bptype type
, enum bpdisp disposition
,
5447 int thread
, int task
, int ignore_count
,
5448 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
5450 struct breakpoint
*b
= NULL
;
5453 if (type
== bp_hardware_breakpoint
)
5455 int i
= hw_breakpoint_used_count ();
5456 int target_resources_ok
=
5457 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
5459 if (target_resources_ok
== 0)
5460 error (_("No hardware breakpoint support in the target."));
5461 else if (target_resources_ok
< 0)
5462 error (_("Hardware breakpoints used exceeds limit."));
5465 for (i
= 0; i
< sals
.nelts
; ++i
)
5467 struct symtab_and_line sal
= sals
.sals
[i
];
5468 struct bp_location
*loc
;
5472 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
5474 loc_gdbarch
= gdbarch
;
5476 describe_other_breakpoints (loc_gdbarch
,
5477 sal
.pc
, sal
.section
, thread
);
5482 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
5483 set_breakpoint_count (breakpoint_count
+ 1);
5484 b
->number
= breakpoint_count
;
5488 b
->cond_string
= cond_string
;
5489 b
->ignore_count
= ignore_count
;
5490 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
5491 b
->disposition
= disposition
;
5493 if (enabled
&& executing_startup
5494 && (b
->type
== bp_breakpoint
5495 || b
->type
== bp_hardware_breakpoint
))
5496 b
->enable_state
= bp_startup_disabled
;
5502 loc
= add_location_to_breakpoint (b
, &sal
);
5505 if (bp_loc_is_permanent (loc
))
5506 make_breakpoint_permanent (b
);
5510 char *arg
= b
->cond_string
;
5511 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5513 error (_("Garbage %s follows condition"), arg
);
5518 b
->addr_string
= addr_string
;
5520 /* addr_string has to be used or breakpoint_re_set will delete
5523 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5529 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5530 elements to fill the void space. */
5532 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5534 int i
= index_to_remove
+1;
5535 int last_index
= sal
->nelts
-1;
5537 for (;i
<= last_index
; ++i
)
5538 sal
->sals
[i
-1] = sal
->sals
[i
];
5543 /* If appropriate, obtains all sals that correspond
5544 to the same file and line as SAL. This is done
5545 only if SAL does not have explicit PC and has
5546 line and file information. If we got just a single
5547 expanded sal, return the original.
5549 Otherwise, if SAL.explicit_line is not set, filter out
5550 all sals for which the name of enclosing function
5551 is different from SAL. This makes sure that if we have
5552 breakpoint originally set in template instantiation, say
5553 foo<int>(), we won't expand SAL to locations at the same
5554 line in all existing instantiations of 'foo'.
5557 static struct symtabs_and_lines
5558 expand_line_sal_maybe (struct symtab_and_line sal
)
5560 struct symtabs_and_lines expanded
;
5561 CORE_ADDR original_pc
= sal
.pc
;
5562 char *original_function
= NULL
;
5566 /* If we have explicit pc, don't expand.
5567 If we have no line number, we can't expand. */
5568 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5571 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5572 expanded
.sals
[0] = sal
;
5577 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5579 expanded
= expand_line_sal (sal
);
5580 if (expanded
.nelts
== 1)
5582 /* We had one sal, we got one sal. Without futher
5583 processing, just return the original sal. */
5584 xfree (expanded
.sals
);
5586 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5587 sal
.pc
= original_pc
;
5588 expanded
.sals
[0] = sal
;
5592 if (!sal
.explicit_line
)
5594 CORE_ADDR func_addr
, func_end
;
5595 for (i
= 0; i
< expanded
.nelts
; ++i
)
5597 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5598 char *this_function
;
5599 if (find_pc_partial_function (pc
, &this_function
,
5600 &func_addr
, &func_end
))
5603 && strcmp (this_function
, original_function
) != 0)
5605 remove_sal (&expanded
, i
);
5608 else if (func_addr
== pc
)
5610 /* We're at beginning of a function, and should
5612 struct symbol
*sym
= find_pc_function (pc
);
5614 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5617 /* Since find_pc_partial_function returned true,
5618 we should really always find the section here. */
5619 struct obj_section
*section
= find_pc_section (pc
);
5622 struct gdbarch
*gdbarch
5623 = get_objfile_arch (section
->objfile
);
5625 = gdbarch_skip_prologue (gdbarch
, pc
);
5634 for (i
= 0; i
< expanded
.nelts
; ++i
)
5636 /* If this SAL corresponds to a breakpoint inserted using a
5637 line number, then skip the function prologue if necessary. */
5638 skip_prologue_sal (&expanded
.sals
[i
]);
5643 if (expanded
.nelts
<= 1)
5645 /* This is un ugly workaround. If we get zero
5646 expanded sals then something is really wrong.
5647 Fix that by returnign the original sal. */
5648 xfree (expanded
.sals
);
5650 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5651 sal
.pc
= original_pc
;
5652 expanded
.sals
[0] = sal
;
5659 for (i
= 0; i
< expanded
.nelts
; ++i
)
5660 if (expanded
.sals
[i
].pc
== original_pc
)
5671 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5672 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5673 value. COND_STRING, if not NULL, specified the condition to be
5674 used for all breakpoints. Essentially the only case where
5675 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5676 function. In that case, it's still not possible to specify
5677 separate conditions for different overloaded functions, so
5678 we take just a single condition string.
5680 NOTE: If the function succeeds, the caller is expected to cleanup
5681 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5682 array contents). If the function fails (error() is called), the
5683 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5684 COND and SALS arrays and each of those arrays contents. */
5687 create_breakpoints (struct gdbarch
*gdbarch
,
5688 struct symtabs_and_lines sals
, char **addr_string
,
5690 enum bptype type
, enum bpdisp disposition
,
5691 int thread
, int task
, int ignore_count
,
5692 struct breakpoint_ops
*ops
, int from_tty
,
5696 for (i
= 0; i
< sals
.nelts
; ++i
)
5698 struct symtabs_and_lines expanded
=
5699 expand_line_sal_maybe (sals
.sals
[i
]);
5701 create_breakpoint (gdbarch
, expanded
, addr_string
[i
],
5702 cond_string
, type
, disposition
,
5703 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
5707 /* Parse ARG which is assumed to be a SAL specification possibly
5708 followed by conditionals. On return, SALS contains an array of SAL
5709 addresses found. ADDR_STRING contains a vector of (canonical)
5710 address strings. ARG points to the end of the SAL. */
5713 parse_breakpoint_sals (char **address
,
5714 struct symtabs_and_lines
*sals
,
5715 char ***addr_string
,
5718 char *addr_start
= *address
;
5719 *addr_string
= NULL
;
5720 /* If no arg given, or if first arg is 'if ', use the default
5722 if ((*address
) == NULL
5723 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5725 if (default_breakpoint_valid
)
5727 struct symtab_and_line sal
;
5728 init_sal (&sal
); /* initialize to zeroes */
5729 sals
->sals
= (struct symtab_and_line
*)
5730 xmalloc (sizeof (struct symtab_and_line
));
5731 sal
.pc
= default_breakpoint_address
;
5732 sal
.line
= default_breakpoint_line
;
5733 sal
.symtab
= default_breakpoint_symtab
;
5734 sal
.section
= find_pc_overlay (sal
.pc
);
5736 /* "break" without arguments is equivalent to "break *PC" where PC is
5737 the default_breakpoint_address. So make sure to set
5738 sal.explicit_pc to prevent GDB from trying to expand the list of
5739 sals to include all other instances with the same symtab and line.
5741 sal
.explicit_pc
= 1;
5743 sals
->sals
[0] = sal
;
5747 error (_("No default breakpoint address now."));
5751 /* Force almost all breakpoints to be in terms of the
5752 current_source_symtab (which is decode_line_1's default). This
5753 should produce the results we want almost all of the time while
5754 leaving default_breakpoint_* alone.
5755 ObjC: However, don't match an Objective-C method name which
5756 may have a '+' or '-' succeeded by a '[' */
5758 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5760 if (default_breakpoint_valid
5762 || ((strchr ("+-", (*address
)[0]) != NULL
)
5763 && ((*address
)[1] != '['))))
5764 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5765 default_breakpoint_line
, addr_string
,
5768 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5769 addr_string
, not_found_ptr
);
5771 /* For any SAL that didn't have a canonical string, fill one in. */
5772 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5773 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5774 if (addr_start
!= (*address
))
5777 for (i
= 0; i
< sals
->nelts
; i
++)
5779 /* Add the string if not present. */
5780 if ((*addr_string
)[i
] == NULL
)
5781 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5787 /* Convert each SAL into a real PC. Verify that the PC can be
5788 inserted as a breakpoint. If it can't throw an error. */
5791 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5795 for (i
= 0; i
< sals
->nelts
; i
++)
5796 resolve_sal_pc (&sals
->sals
[i
]);
5800 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5802 struct captured_parse_breakpoint_args
*args
= data
;
5804 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5805 args
->not_found_ptr
);
5808 /* Given TOK, a string specification of condition and thread, as
5809 accepted by the 'break' command, extract the condition
5810 string and thread number and set *COND_STRING and *THREAD.
5811 PC identifies the context at which the condition should be parsed.
5812 If no condition is found, *COND_STRING is set to NULL.
5813 If no thread is found, *THREAD is set to -1. */
5815 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5816 char **cond_string
, int *thread
, int *task
)
5818 *cond_string
= NULL
;
5824 char *cond_start
= NULL
;
5825 char *cond_end
= NULL
;
5826 while (*tok
== ' ' || *tok
== '\t')
5831 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5834 toklen
= end_tok
- tok
;
5836 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5838 struct expression
*expr
;
5840 tok
= cond_start
= end_tok
+ 1;
5841 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5844 *cond_string
= savestring (cond_start
,
5845 cond_end
- cond_start
);
5847 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5853 *thread
= strtol (tok
, &tok
, 0);
5855 error (_("Junk after thread keyword."));
5856 if (!valid_thread_id (*thread
))
5857 error (_("Unknown thread %d."), *thread
);
5859 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
5865 *task
= strtol (tok
, &tok
, 0);
5867 error (_("Junk after task keyword."));
5868 if (!valid_task_id (*task
))
5869 error (_("Unknown task %d\n"), *task
);
5872 error (_("Junk at end of arguments."));
5876 /* Set a breakpoint. This function is shared between
5877 CLI and MI functions for setting a breakpoint.
5878 This function has two major modes of operations,
5879 selected by the PARSE_CONDITION_AND_THREAD parameter.
5880 If non-zero, the function will parse arg, extracting
5881 breakpoint location, address and thread. Otherwise,
5882 ARG is just the location of breakpoint, with condition
5883 and thread specified by the COND_STRING and THREAD
5887 break_command_really (struct gdbarch
*gdbarch
,
5888 char *arg
, char *cond_string
, int thread
,
5889 int parse_condition_and_thread
,
5890 int tempflag
, int hardwareflag
, int traceflag
,
5892 enum auto_boolean pending_break_support
,
5893 struct breakpoint_ops
*ops
,
5897 struct gdb_exception e
;
5898 struct symtabs_and_lines sals
;
5899 struct symtab_and_line pending_sal
;
5902 char *addr_start
= arg
;
5904 struct cleanup
*old_chain
;
5905 struct cleanup
*bkpt_chain
= NULL
;
5906 struct captured_parse_breakpoint_args parse_args
;
5910 enum bptype type_wanted
;
5917 parse_args
.arg_p
= &arg
;
5918 parse_args
.sals_p
= &sals
;
5919 parse_args
.addr_string_p
= &addr_string
;
5920 parse_args
.not_found_ptr
= ¬_found
;
5922 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5923 &parse_args
, RETURN_MASK_ALL
);
5925 /* If caller is interested in rc value from parse, set value. */
5929 throw_exception (e
);
5933 case NOT_FOUND_ERROR
:
5935 /* If pending breakpoint support is turned off, throw
5938 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5939 throw_exception (e
);
5941 exception_print (gdb_stderr
, e
);
5943 /* If pending breakpoint support is auto query and the user
5944 selects no, then simply return the error code. */
5945 if (pending_break_support
== AUTO_BOOLEAN_AUTO
5946 && !nquery ("Make breakpoint pending on future shared library load? "))
5949 /* At this point, either the user was queried about setting
5950 a pending breakpoint and selected yes, or pending
5951 breakpoint behavior is on and thus a pending breakpoint
5952 is defaulted on behalf of the user. */
5953 copy_arg
= xstrdup (addr_start
);
5954 addr_string
= ©_arg
;
5956 sals
.sals
= &pending_sal
;
5961 throw_exception (e
);
5968 /* Create a chain of things that always need to be cleaned up. */
5969 old_chain
= make_cleanup (null_cleanup
, 0);
5973 /* Make sure that all storage allocated to SALS gets freed. */
5974 make_cleanup (xfree
, sals
.sals
);
5976 /* Cleanup the addr_string array but not its contents. */
5977 make_cleanup (xfree
, addr_string
);
5980 /* ----------------------------- SNIP -----------------------------
5981 Anything added to the cleanup chain beyond this point is assumed
5982 to be part of a breakpoint. If the breakpoint create succeeds
5983 then the memory is not reclaimed. */
5984 bkpt_chain
= make_cleanup (null_cleanup
, 0);
5986 /* Mark the contents of the addr_string for cleanup. These go on
5987 the bkpt_chain and only occur if the breakpoint create fails. */
5988 for (i
= 0; i
< sals
.nelts
; i
++)
5990 if (addr_string
[i
] != NULL
)
5991 make_cleanup (xfree
, addr_string
[i
]);
5994 /* Resolve all line numbers to PC's and verify that the addresses
5995 are ok for the target. */
5997 breakpoint_sals_to_pc (&sals
, addr_start
);
5999 type_wanted
= (traceflag
6001 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
6003 /* Verify that condition can be parsed, before setting any
6004 breakpoints. Allocate a separate condition expression for each
6008 if (parse_condition_and_thread
)
6010 /* Here we only parse 'arg' to separate condition
6011 from thread number, so parsing in context of first
6012 sal is OK. When setting the breakpoint we'll
6013 re-parse it in context of each sal. */
6016 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
6019 make_cleanup (xfree
, cond_string
);
6023 /* Create a private copy of condition string. */
6026 cond_string
= xstrdup (cond_string
);
6027 make_cleanup (xfree
, cond_string
);
6030 create_breakpoints (gdbarch
, sals
, addr_string
, cond_string
, type_wanted
,
6031 tempflag
? disp_del
: disp_donttouch
,
6032 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
6036 struct symtab_and_line sal
= {0};
6037 struct breakpoint
*b
;
6039 make_cleanup (xfree
, copy_arg
);
6041 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
6042 set_breakpoint_count (breakpoint_count
+ 1);
6043 b
->number
= breakpoint_count
;
6045 b
->addr_string
= addr_string
[0];
6046 b
->cond_string
= NULL
;
6047 b
->ignore_count
= ignore_count
;
6048 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6049 b
->condition_not_parsed
= 1;
6051 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6053 if (enabled
&& executing_startup
6054 && (b
->type
== bp_breakpoint
6055 || b
->type
== bp_hardware_breakpoint
))
6056 b
->enable_state
= bp_startup_disabled
;
6062 warning (_("Multiple breakpoints were set.\n"
6063 "Use the \"delete\" command to delete unwanted breakpoints."));
6064 /* That's it. Discard the cleanups for data inserted into the
6066 discard_cleanups (bkpt_chain
);
6067 /* But cleanup everything else. */
6068 do_cleanups (old_chain
);
6070 /* error call may happen here - have BKPT_CHAIN already discarded. */
6071 update_global_location_list (1);
6074 /* Set a breakpoint.
6075 ARG is a string describing breakpoint address,
6076 condition, and thread.
6077 FLAG specifies if a breakpoint is hardware on,
6078 and if breakpoint is temporary, using BP_HARDWARE_FLAG
6082 break_command_1 (char *arg
, int flag
, int from_tty
)
6084 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
6085 int tempflag
= flag
& BP_TEMPFLAG
;
6087 break_command_really (get_current_arch (),
6089 NULL
, 0, 1 /* parse arg */,
6090 tempflag
, hardwareflag
, 0 /* traceflag */,
6091 0 /* Ignore count */,
6092 pending_break_support
,
6093 NULL
/* breakpoint_ops */,
6100 set_breakpoint (struct gdbarch
*gdbarch
,
6101 char *address
, char *condition
,
6102 int hardwareflag
, int tempflag
,
6103 int thread
, int ignore_count
,
6104 int pending
, int enabled
)
6106 break_command_really (gdbarch
,
6107 address
, condition
, thread
,
6108 0 /* condition and thread are valid. */,
6109 tempflag
, hardwareflag
, 0 /* traceflag */,
6112 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
6116 /* Adjust SAL to the first instruction past the function prologue.
6117 The end of the prologue is determined using the line table from
6118 the debugging information. explicit_pc and explicit_line are
6121 If SAL is already past the prologue, then do nothing. */
6124 skip_prologue_sal (struct symtab_and_line
*sal
)
6126 struct symbol
*sym
= find_pc_function (sal
->pc
);
6127 struct symtab_and_line start_sal
;
6132 start_sal
= find_function_start_sal (sym
, 1);
6133 if (sal
->pc
< start_sal
.pc
)
6135 start_sal
.explicit_line
= sal
->explicit_line
;
6136 start_sal
.explicit_pc
= sal
->explicit_pc
;
6141 /* Helper function for break_command_1 and disassemble_command. */
6144 resolve_sal_pc (struct symtab_and_line
*sal
)
6148 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
6150 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
6151 error (_("No line %d in file \"%s\"."),
6152 sal
->line
, sal
->symtab
->filename
);
6155 /* If this SAL corresponds to a breakpoint inserted using
6156 a line number, then skip the function prologue if necessary. */
6157 if (sal
->explicit_line
)
6159 /* Preserve the original line number. */
6160 int saved_line
= sal
->line
;
6161 skip_prologue_sal (sal
);
6162 sal
->line
= saved_line
;
6166 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
6168 struct blockvector
*bv
;
6172 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
6175 sym
= block_linkage_function (b
);
6178 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
6179 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
6183 /* It really is worthwhile to have the section, so we'll just
6184 have to look harder. This case can be executed if we have
6185 line numbers but no functions (as can happen in assembly
6188 struct minimal_symbol
*msym
;
6190 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
6192 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
6199 break_command (char *arg
, int from_tty
)
6201 break_command_1 (arg
, 0, from_tty
);
6205 tbreak_command (char *arg
, int from_tty
)
6207 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
6211 hbreak_command (char *arg
, int from_tty
)
6213 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
6217 thbreak_command (char *arg
, int from_tty
)
6219 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
6223 stop_command (char *arg
, int from_tty
)
6225 printf_filtered (_("Specify the type of breakpoint to set.\n\
6226 Usage: stop in <function | address>\n\
6227 stop at <line>\n"));
6231 stopin_command (char *arg
, int from_tty
)
6235 if (arg
== (char *) NULL
)
6237 else if (*arg
!= '*')
6242 /* look for a ':'. If this is a line number specification, then
6243 say it is bad, otherwise, it should be an address or
6244 function/method name */
6245 while (*argptr
&& !hasColon
)
6247 hasColon
= (*argptr
== ':');
6252 badInput
= (*argptr
!= ':'); /* Not a class::method */
6254 badInput
= isdigit (*arg
); /* a simple line number */
6258 printf_filtered (_("Usage: stop in <function | address>\n"));
6260 break_command_1 (arg
, 0, from_tty
);
6264 stopat_command (char *arg
, int from_tty
)
6268 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
6275 /* look for a ':'. If there is a '::' then get out, otherwise
6276 it is probably a line number. */
6277 while (*argptr
&& !hasColon
)
6279 hasColon
= (*argptr
== ':');
6284 badInput
= (*argptr
== ':'); /* we have class::method */
6286 badInput
= !isdigit (*arg
); /* not a line number */
6290 printf_filtered (_("Usage: stop at <line>\n"));
6292 break_command_1 (arg
, 0, from_tty
);
6295 /* accessflag: hw_write: watch write,
6296 hw_read: watch read,
6297 hw_access: watch access (read or write) */
6299 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
6301 struct gdbarch
*gdbarch
= get_current_arch ();
6302 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
6303 struct symtab_and_line sal
;
6304 struct expression
*exp
;
6305 struct block
*exp_valid_block
;
6306 struct value
*val
, *mark
;
6307 struct frame_info
*frame
;
6308 char *exp_start
= NULL
;
6309 char *exp_end
= NULL
;
6310 char *tok
, *id_tok_start
, *end_tok
;
6312 char *cond_start
= NULL
;
6313 char *cond_end
= NULL
;
6314 struct expression
*cond
= NULL
;
6315 int i
, other_type_used
, target_resources_ok
= 0;
6316 enum bptype bp_type
;
6320 init_sal (&sal
); /* initialize to zeroes */
6322 /* Make sure that we actually have parameters to parse. */
6323 if (arg
!= NULL
&& arg
[0] != '\0')
6325 toklen
= strlen (arg
); /* Size of argument list. */
6327 /* Points tok to the end of the argument list. */
6328 tok
= arg
+ toklen
- 1;
6330 /* Go backwards in the parameters list. Skip the last parameter.
6331 If we're expecting a 'thread <thread_num>' parameter, this should
6332 be the thread identifier. */
6333 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6335 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6338 /* Points end_tok to the beginning of the last token. */
6339 id_tok_start
= tok
+ 1;
6341 /* Go backwards in the parameters list. Skip one more parameter.
6342 If we're expecting a 'thread <thread_num>' parameter, we should
6343 reach a "thread" token. */
6344 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6349 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6352 /* Move the pointer forward to skip the whitespace and
6353 calculate the length of the token. */
6355 toklen
= end_tok
- tok
;
6357 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
6359 /* At this point we've found a "thread" token, which means
6360 the user is trying to set a watchpoint that triggers
6361 only in a specific thread. */
6364 /* Extract the thread ID from the next token. */
6365 thread
= strtol (id_tok_start
, &endp
, 0);
6367 /* Check if the user provided a valid numeric value for the
6369 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
6370 error (_("Invalid thread ID specification %s."), id_tok_start
);
6372 /* Check if the thread actually exists. */
6373 if (!valid_thread_id (thread
))
6374 error (_("Unknown thread %d."), thread
);
6376 /* Truncate the string and get rid of the thread <thread_num>
6377 parameter before the parameter list is parsed by the
6378 evaluate_expression() function. */
6383 /* Parse the rest of the arguments. */
6384 innermost_block
= NULL
;
6386 exp
= parse_exp_1 (&arg
, 0, 0);
6388 /* Remove trailing whitespace from the expression before saving it.
6389 This makes the eventual display of the expression string a bit
6391 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
6394 exp_valid_block
= innermost_block
;
6395 mark
= value_mark ();
6396 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
6398 release_value (val
);
6401 while (*tok
== ' ' || *tok
== '\t')
6405 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6408 toklen
= end_tok
- tok
;
6409 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6411 tok
= cond_start
= end_tok
+ 1;
6412 cond
= parse_exp_1 (&tok
, 0, 0);
6416 error (_("Junk at end of command."));
6418 if (accessflag
== hw_read
)
6419 bp_type
= bp_read_watchpoint
;
6420 else if (accessflag
== hw_access
)
6421 bp_type
= bp_access_watchpoint
;
6423 bp_type
= bp_hardware_watchpoint
;
6425 mem_cnt
= can_use_hardware_watchpoint (val
);
6426 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
6427 error (_("Expression cannot be implemented with read/access watchpoint."));
6430 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
6431 target_resources_ok
=
6432 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
6434 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
6435 error (_("Target does not support this type of hardware watchpoint."));
6437 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
6438 error (_("Target can only support one kind of HW watchpoint at a time."));
6441 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6442 watchpoint could not be set. */
6443 if (!mem_cnt
|| target_resources_ok
<= 0)
6444 bp_type
= bp_watchpoint
;
6446 frame
= block_innermost_frame (exp_valid_block
);
6448 /* If the expression is "local", then set up a "watchpoint scope"
6449 breakpoint at the point where we've left the scope of the watchpoint
6450 expression. Create the scope breakpoint before the watchpoint, so
6451 that we will encounter it first in bpstat_stop_status. */
6452 if (innermost_block
&& frame
)
6454 if (frame_id_p (frame_unwind_caller_id (frame
)))
6457 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
6458 frame_unwind_caller_pc (frame
),
6459 bp_watchpoint_scope
);
6461 scope_breakpoint
->enable_state
= bp_enabled
;
6463 /* Automatically delete the breakpoint when it hits. */
6464 scope_breakpoint
->disposition
= disp_del
;
6466 /* Only break in the proper frame (help with recursion). */
6467 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
6469 /* Set the address at which we will stop. */
6470 scope_breakpoint
->loc
->gdbarch
6471 = frame_unwind_caller_arch (frame
);
6472 scope_breakpoint
->loc
->requested_address
6473 = frame_unwind_caller_pc (frame
);
6474 scope_breakpoint
->loc
->address
6475 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
6476 scope_breakpoint
->loc
->requested_address
,
6477 scope_breakpoint
->type
);
6481 /* Now set up the breakpoint. */
6482 b
= set_raw_breakpoint (gdbarch
, sal
, bp_type
);
6483 set_breakpoint_count (breakpoint_count
+ 1);
6484 b
->number
= breakpoint_count
;
6486 b
->disposition
= disp_donttouch
;
6488 b
->exp_valid_block
= exp_valid_block
;
6489 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6492 b
->loc
->cond
= cond
;
6494 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6499 b
->watchpoint_frame
= get_frame_id (frame
);
6501 b
->watchpoint_frame
= null_frame_id
;
6503 if (scope_breakpoint
!= NULL
)
6505 /* The scope breakpoint is related to the watchpoint. We will
6506 need to act on them together. */
6507 b
->related_breakpoint
= scope_breakpoint
;
6508 scope_breakpoint
->related_breakpoint
= b
;
6511 value_free_to_mark (mark
);
6513 update_global_location_list (1);
6516 /* Return count of locations need to be watched and can be handled
6517 in hardware. If the watchpoint can not be handled
6518 in hardware return zero. */
6521 can_use_hardware_watchpoint (struct value
*v
)
6523 int found_memory_cnt
= 0;
6524 struct value
*head
= v
;
6526 /* Did the user specifically forbid us to use hardware watchpoints? */
6527 if (!can_use_hw_watchpoints
)
6530 /* Make sure that the value of the expression depends only upon
6531 memory contents, and values computed from them within GDB. If we
6532 find any register references or function calls, we can't use a
6533 hardware watchpoint.
6535 The idea here is that evaluating an expression generates a series
6536 of values, one holding the value of every subexpression. (The
6537 expression a*b+c has five subexpressions: a, b, a*b, c, and
6538 a*b+c.) GDB's values hold almost enough information to establish
6539 the criteria given above --- they identify memory lvalues,
6540 register lvalues, computed values, etcetera. So we can evaluate
6541 the expression, and then scan the chain of values that leaves
6542 behind to decide whether we can detect any possible change to the
6543 expression's final value using only hardware watchpoints.
6545 However, I don't think that the values returned by inferior
6546 function calls are special in any way. So this function may not
6547 notice that an expression involving an inferior function call
6548 can't be watched with hardware watchpoints. FIXME. */
6549 for (; v
; v
= value_next (v
))
6551 if (VALUE_LVAL (v
) == lval_memory
)
6554 /* A lazy memory lvalue is one that GDB never needed to fetch;
6555 we either just used its address (e.g., `a' in `a.b') or
6556 we never needed it at all (e.g., `a' in `a,b'). */
6560 /* Ahh, memory we actually used! Check if we can cover
6561 it with hardware watchpoints. */
6562 struct type
*vtype
= check_typedef (value_type (v
));
6564 /* We only watch structs and arrays if user asked for it
6565 explicitly, never if they just happen to appear in a
6566 middle of some value chain. */
6568 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6569 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6571 CORE_ADDR vaddr
= value_address (v
);
6572 int len
= TYPE_LENGTH (value_type (v
));
6574 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
6581 else if (VALUE_LVAL (v
) != not_lval
6582 && deprecated_value_modifiable (v
) == 0)
6583 return 0; /* ??? What does this represent? */
6584 else if (VALUE_LVAL (v
) == lval_register
)
6585 return 0; /* cannot watch a register with a HW watchpoint */
6588 /* The expression itself looks suitable for using a hardware
6589 watchpoint, but give the target machine a chance to reject it. */
6590 return found_memory_cnt
;
6594 watch_command_wrapper (char *arg
, int from_tty
)
6596 watch_command (arg
, from_tty
);
6600 watch_command (char *arg
, int from_tty
)
6602 watch_command_1 (arg
, hw_write
, from_tty
);
6606 rwatch_command_wrapper (char *arg
, int from_tty
)
6608 rwatch_command (arg
, from_tty
);
6612 rwatch_command (char *arg
, int from_tty
)
6614 watch_command_1 (arg
, hw_read
, from_tty
);
6618 awatch_command_wrapper (char *arg
, int from_tty
)
6620 awatch_command (arg
, from_tty
);
6624 awatch_command (char *arg
, int from_tty
)
6626 watch_command_1 (arg
, hw_access
, from_tty
);
6630 /* Helper routines for the until_command routine in infcmd.c. Here
6631 because it uses the mechanisms of breakpoints. */
6633 struct until_break_command_continuation_args
6635 struct breakpoint
*breakpoint
;
6636 struct breakpoint
*breakpoint2
;
6639 /* This function is called by fetch_inferior_event via the
6640 cmd_continuation pointer, to complete the until command. It takes
6641 care of cleaning up the temporary breakpoints set up by the until
6644 until_break_command_continuation (void *arg
)
6646 struct until_break_command_continuation_args
*a
= arg
;
6648 delete_breakpoint (a
->breakpoint
);
6650 delete_breakpoint (a
->breakpoint2
);
6654 until_break_command (char *arg
, int from_tty
, int anywhere
)
6656 struct symtabs_and_lines sals
;
6657 struct symtab_and_line sal
;
6658 struct frame_info
*frame
= get_selected_frame (NULL
);
6659 struct breakpoint
*breakpoint
;
6660 struct breakpoint
*breakpoint2
= NULL
;
6661 struct cleanup
*old_chain
;
6663 clear_proceed_status ();
6665 /* Set a breakpoint where the user wants it and at return from
6668 if (default_breakpoint_valid
)
6669 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6670 default_breakpoint_line
, (char ***) NULL
, NULL
);
6672 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6673 0, (char ***) NULL
, NULL
);
6675 if (sals
.nelts
!= 1)
6676 error (_("Couldn't get information on specified line."));
6679 xfree (sals
.sals
); /* malloc'd, so freed */
6682 error (_("Junk at end of arguments."));
6684 resolve_sal_pc (&sal
);
6687 /* If the user told us to continue until a specified location,
6688 we don't specify a frame at which we need to stop. */
6689 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
6690 null_frame_id
, bp_until
);
6692 /* Otherwise, specify the selected frame, because we want to stop only
6693 at the very same frame. */
6694 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
6695 get_stack_frame_id (frame
),
6698 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6700 /* Keep within the current frame, or in frames called by the current
6703 if (frame_id_p (frame_unwind_caller_id (frame
)))
6705 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
6706 sal
.pc
= frame_unwind_caller_pc (frame
);
6707 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
6709 frame_unwind_caller_id (frame
),
6711 make_cleanup_delete_breakpoint (breakpoint2
);
6714 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6716 /* If we are running asynchronously, and proceed call above has actually
6717 managed to start the target, arrange for breakpoints to be
6718 deleted when the target stops. Otherwise, we're already stopped and
6719 delete breakpoints via cleanup chain. */
6721 if (target_can_async_p () && is_running (inferior_ptid
))
6723 struct until_break_command_continuation_args
*args
;
6724 args
= xmalloc (sizeof (*args
));
6726 args
->breakpoint
= breakpoint
;
6727 args
->breakpoint2
= breakpoint2
;
6729 discard_cleanups (old_chain
);
6730 add_continuation (inferior_thread (),
6731 until_break_command_continuation
, args
,
6735 do_cleanups (old_chain
);
6739 ep_skip_leading_whitespace (char **s
)
6741 if ((s
== NULL
) || (*s
== NULL
))
6743 while (isspace (**s
))
6747 /* This function attempts to parse an optional "if <cond>" clause
6748 from the arg string. If one is not found, it returns NULL.
6750 Else, it returns a pointer to the condition string. (It does not
6751 attempt to evaluate the string against a particular block.) And,
6752 it updates arg to point to the first character following the parsed
6753 if clause in the arg string. */
6756 ep_parse_optional_if_clause (char **arg
)
6760 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6763 /* Skip the "if" keyword. */
6766 /* Skip any extra leading whitespace, and record the start of the
6767 condition string. */
6768 ep_skip_leading_whitespace (arg
);
6771 /* Assume that the condition occupies the remainder of the arg string. */
6772 (*arg
) += strlen (cond_string
);
6777 /* This function attempts to parse an optional filename from the arg
6778 string. If one is not found, it returns NULL.
6780 Else, it returns a pointer to the parsed filename. (This function
6781 makes no attempt to verify that a file of that name exists, or is
6782 accessible.) And, it updates arg to point to the first character
6783 following the parsed filename in the arg string.
6785 Note that clients needing to preserve the returned filename for
6786 future access should copy it to their own buffers. */
6788 ep_parse_optional_filename (char **arg
)
6790 static char filename
[1024];
6795 if ((*arg_p
== '\0') || isspace (*arg_p
))
6813 /* Commands to deal with catching events, such as signals, exceptions,
6814 process start/exit, etc. */
6818 catch_fork_temporary
, catch_vfork_temporary
,
6819 catch_fork_permanent
, catch_vfork_permanent
6824 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6826 struct gdbarch
*gdbarch
= get_current_arch ();
6827 char *cond_string
= NULL
;
6828 catch_fork_kind fork_kind
;
6831 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6832 tempflag
= (fork_kind
== catch_fork_temporary
6833 || fork_kind
== catch_vfork_temporary
);
6837 ep_skip_leading_whitespace (&arg
);
6839 /* The allowed syntax is:
6841 catch [v]fork if <cond>
6843 First, check if there's an if clause. */
6844 cond_string
= ep_parse_optional_if_clause (&arg
);
6846 if ((*arg
!= '\0') && !isspace (*arg
))
6847 error (_("Junk at end of arguments."));
6849 /* If this target supports it, create a fork or vfork catchpoint
6850 and enable reporting of such events. */
6853 case catch_fork_temporary
:
6854 case catch_fork_permanent
:
6855 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
6856 &catch_fork_breakpoint_ops
);
6858 case catch_vfork_temporary
:
6859 case catch_vfork_permanent
:
6860 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
6861 &catch_vfork_breakpoint_ops
);
6864 error (_("unsupported or unknown fork kind; cannot catch it"));
6870 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6872 struct gdbarch
*gdbarch
= get_current_arch ();
6874 char *cond_string
= NULL
;
6876 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6880 ep_skip_leading_whitespace (&arg
);
6882 /* The allowed syntax is:
6884 catch exec if <cond>
6886 First, check if there's an if clause. */
6887 cond_string
= ep_parse_optional_if_clause (&arg
);
6889 if ((*arg
!= '\0') && !isspace (*arg
))
6890 error (_("Junk at end of arguments."));
6892 /* If this target supports it, create an exec catchpoint
6893 and enable reporting of such events. */
6894 create_catchpoint (gdbarch
, tempflag
, cond_string
,
6895 &catch_exec_breakpoint_ops
);
6898 static enum print_stop_action
6899 print_exception_catchpoint (struct breakpoint
*b
)
6901 int bp_temp
, bp_throw
;
6903 annotate_catchpoint (b
->number
);
6905 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6906 if (b
->loc
->address
!= b
->loc
->requested_address
)
6907 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6910 bp_temp
= b
->disposition
== disp_del
;
6912 bp_temp
? "Temporary catchpoint "
6914 if (!ui_out_is_mi_like_p (uiout
))
6915 ui_out_field_int (uiout
, "bkptno", b
->number
);
6917 bp_throw
? " (exception thrown), "
6918 : " (exception caught), ");
6919 if (ui_out_is_mi_like_p (uiout
))
6921 ui_out_field_string (uiout
, "reason",
6922 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6923 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6924 ui_out_field_int (uiout
, "bkptno", b
->number
);
6926 return PRINT_SRC_AND_LOC
;
6930 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
6932 struct value_print_options opts
;
6933 get_user_print_options (&opts
);
6934 if (opts
.addressprint
)
6937 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6938 ui_out_field_string (uiout
, "addr", "<PENDING>");
6940 ui_out_field_core_addr (uiout
, "addr",
6941 b
->loc
->gdbarch
, b
->loc
->address
);
6946 if (strstr (b
->addr_string
, "throw") != NULL
)
6947 ui_out_field_string (uiout
, "what", "exception throw");
6949 ui_out_field_string (uiout
, "what", "exception catch");
6953 print_mention_exception_catchpoint (struct breakpoint
*b
)
6958 bp_temp
= b
->disposition
== disp_del
;
6959 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6960 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6961 : _("Catchpoint "));
6962 ui_out_field_int (uiout
, "bkptno", b
->number
);
6963 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6967 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6970 NULL
, /* breakpoint_hit */
6971 print_exception_catchpoint
,
6972 print_one_exception_catchpoint
,
6973 print_mention_exception_catchpoint
6977 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6978 enum exception_event_kind ex_event
, int from_tty
)
6980 char *trigger_func_name
;
6982 if (ex_event
== EX_EVENT_CATCH
)
6983 trigger_func_name
= "__cxa_begin_catch";
6985 trigger_func_name
= "__cxa_throw";
6987 break_command_really (get_current_arch (),
6988 trigger_func_name
, cond_string
, -1,
6989 0 /* condition and thread are valid. */,
6992 AUTO_BOOLEAN_TRUE
/* pending */,
6993 &gnu_v3_exception_catchpoint_ops
, from_tty
,
6999 /* Deal with "catch catch" and "catch throw" commands */
7002 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
7003 int tempflag
, int from_tty
)
7005 char *cond_string
= NULL
;
7006 struct symtab_and_line
*sal
= NULL
;
7010 ep_skip_leading_whitespace (&arg
);
7012 cond_string
= ep_parse_optional_if_clause (&arg
);
7014 if ((*arg
!= '\0') && !isspace (*arg
))
7015 error (_("Junk at end of arguments."));
7017 if (ex_event
!= EX_EVENT_THROW
7018 && ex_event
!= EX_EVENT_CATCH
)
7019 error (_("Unsupported or unknown exception event; cannot catch it"));
7021 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
7024 warning (_("Unsupported with this platform/compiler combination."));
7027 /* Implementation of "catch catch" command. */
7030 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7032 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7033 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
7036 /* Implementation of "catch throw" command. */
7039 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7041 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7042 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
7045 /* Create a breakpoint struct for Ada exception catchpoints. */
7048 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
7049 struct symtab_and_line sal
,
7053 struct expression
*cond
,
7054 struct breakpoint_ops
*ops
,
7058 struct breakpoint
*b
;
7062 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7064 loc_gdbarch
= gdbarch
;
7066 describe_other_breakpoints (loc_gdbarch
, sal
.pc
, sal
.section
, -1);
7067 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
7068 version for exception catchpoints, because two catchpoints
7069 used for different exception names will use the same address.
7070 In this case, a "breakpoint ... also set at..." warning is
7071 unproductive. Besides. the warning phrasing is also a bit
7072 inapropriate, we should use the word catchpoint, and tell
7073 the user what type of catchpoint it is. The above is good
7074 enough for now, though. */
7077 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
7078 set_breakpoint_count (breakpoint_count
+ 1);
7080 b
->enable_state
= bp_enabled
;
7081 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7082 b
->number
= breakpoint_count
;
7083 b
->ignore_count
= 0;
7084 b
->loc
->cond
= cond
;
7085 b
->addr_string
= addr_string
;
7086 b
->language
= language_ada
;
7087 b
->cond_string
= cond_string
;
7088 b
->exp_string
= exp_string
;
7093 update_global_location_list (1);
7096 /* Implement the "catch exception" command. */
7099 catch_ada_exception_command (char *arg
, int from_tty
,
7100 struct cmd_list_element
*command
)
7102 struct gdbarch
*gdbarch
= get_current_arch ();
7104 struct symtab_and_line sal
;
7106 char *addr_string
= NULL
;
7107 char *exp_string
= NULL
;
7108 char *cond_string
= NULL
;
7109 struct expression
*cond
= NULL
;
7110 struct breakpoint_ops
*ops
= NULL
;
7112 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7116 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
7117 &cond_string
, &cond
, &ops
);
7118 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
7119 cond_string
, cond
, ops
, tempflag
,
7123 /* Implement the "catch assert" command. */
7126 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7128 struct gdbarch
*gdbarch
= get_current_arch ();
7130 struct symtab_and_line sal
;
7131 char *addr_string
= NULL
;
7132 struct breakpoint_ops
*ops
= NULL
;
7134 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7138 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
7139 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
7140 ops
, tempflag
, from_tty
);
7144 catch_command (char *arg
, int from_tty
)
7146 error (_("Catch requires an event name."));
7151 tcatch_command (char *arg
, int from_tty
)
7153 error (_("Catch requires an event name."));
7156 /* Delete breakpoints by address or line. */
7159 clear_command (char *arg
, int from_tty
)
7161 struct breakpoint
*b
;
7162 VEC(breakpoint_p
) *found
= 0;
7165 struct symtabs_and_lines sals
;
7166 struct symtab_and_line sal
;
7171 sals
= decode_line_spec (arg
, 1);
7176 sals
.sals
= (struct symtab_and_line
*)
7177 xmalloc (sizeof (struct symtab_and_line
));
7178 make_cleanup (xfree
, sals
.sals
);
7179 init_sal (&sal
); /* initialize to zeroes */
7180 sal
.line
= default_breakpoint_line
;
7181 sal
.symtab
= default_breakpoint_symtab
;
7182 sal
.pc
= default_breakpoint_address
;
7183 if (sal
.symtab
== 0)
7184 error (_("No source file specified."));
7192 /* We don't call resolve_sal_pc here. That's not
7193 as bad as it seems, because all existing breakpoints
7194 typically have both file/line and pc set. So, if
7195 clear is given file/line, we can match this to existing
7196 breakpoint without obtaining pc at all.
7198 We only support clearing given the address explicitly
7199 present in breakpoint table. Say, we've set breakpoint
7200 at file:line. There were several PC values for that file:line,
7201 due to optimization, all in one block.
7202 We've picked one PC value. If "clear" is issued with another
7203 PC corresponding to the same file:line, the breakpoint won't
7204 be cleared. We probably can still clear the breakpoint, but
7205 since the other PC value is never presented to user, user
7206 can only find it by guessing, and it does not seem important
7209 /* For each line spec given, delete bps which correspond
7210 to it. Do it in two passes, solely to preserve the current
7211 behavior that from_tty is forced true if we delete more than
7215 for (i
= 0; i
< sals
.nelts
; i
++)
7217 /* If exact pc given, clear bpts at that pc.
7218 If line given (pc == 0), clear all bpts on specified line.
7219 If defaulting, clear all bpts on default line
7222 defaulting sal.pc != 0 tests to do
7227 1 0 <can't happen> */
7231 /* Find all matching breakpoints and add them to
7236 /* Are we going to delete b? */
7237 if (b
->type
!= bp_none
7238 && b
->type
!= bp_watchpoint
7239 && b
->type
!= bp_hardware_watchpoint
7240 && b
->type
!= bp_read_watchpoint
7241 && b
->type
!= bp_access_watchpoint
)
7243 struct bp_location
*loc
= b
->loc
;
7244 for (; loc
; loc
= loc
->next
)
7246 int pc_match
= sal
.pc
7247 && (loc
->address
== sal
.pc
)
7248 && (!section_is_overlay (loc
->section
)
7249 || loc
->section
== sal
.section
);
7250 int line_match
= ((default_match
|| (0 == sal
.pc
))
7251 && b
->source_file
!= NULL
7252 && sal
.symtab
!= NULL
7253 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
7254 && b
->line_number
== sal
.line
);
7255 if (pc_match
|| line_match
)
7264 VEC_safe_push(breakpoint_p
, found
, b
);
7267 /* Now go thru the 'found' chain and delete them. */
7268 if (VEC_empty(breakpoint_p
, found
))
7271 error (_("No breakpoint at %s."), arg
);
7273 error (_("No breakpoint at this line."));
7276 if (VEC_length(breakpoint_p
, found
) > 1)
7277 from_tty
= 1; /* Always report if deleted more than one */
7280 if (VEC_length(breakpoint_p
, found
) == 1)
7281 printf_unfiltered (_("Deleted breakpoint "));
7283 printf_unfiltered (_("Deleted breakpoints "));
7285 breakpoints_changed ();
7287 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
7290 printf_unfiltered ("%d ", b
->number
);
7291 delete_breakpoint (b
);
7294 putchar_unfiltered ('\n');
7297 /* Delete breakpoint in BS if they are `delete' breakpoints and
7298 all breakpoints that are marked for deletion, whether hit or not.
7299 This is called after any breakpoint is hit, or after errors. */
7302 breakpoint_auto_delete (bpstat bs
)
7304 struct breakpoint
*b
, *temp
;
7306 for (; bs
; bs
= bs
->next
)
7307 if (bs
->breakpoint_at
7308 && bs
->breakpoint_at
->owner
7309 && bs
->breakpoint_at
->owner
->disposition
== disp_del
7311 delete_breakpoint (bs
->breakpoint_at
->owner
);
7313 ALL_BREAKPOINTS_SAFE (b
, temp
)
7315 if (b
->disposition
== disp_del_at_next_stop
)
7316 delete_breakpoint (b
);
7320 /* A cleanup function which destroys a vector. */
7323 do_vec_free (void *p
)
7325 VEC(bp_location_p
) **vec
= p
;
7327 VEC_free (bp_location_p
, *vec
);
7330 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
7331 into the inferior, only remove already-inserted locations that no
7332 longer should be inserted. Functions that delete a breakpoint or
7333 breakpoints should pass false, so that deleting a breakpoint
7334 doesn't have the side effect of inserting the locations of other
7335 breakpoints that are marked not-inserted, but should_be_inserted
7336 returns true on them.
7338 This behaviour is useful is situations close to tear-down -- e.g.,
7339 after an exec, while the target still has execution, but breakpoint
7340 shadows of the previous executable image should *NOT* be restored
7341 to the new image; or before detaching, where the target still has
7342 execution and wants to delete breakpoints from GDB's lists, and all
7343 breakpoints had already been removed from the inferior. */
7346 update_global_location_list (int should_insert
)
7348 struct breakpoint
*b
;
7349 struct bp_location
**next
= &bp_location_chain
;
7350 struct bp_location
*loc
;
7351 struct bp_location
*loc2
;
7352 VEC(bp_location_p
) *old_locations
= NULL
;
7355 struct cleanup
*cleanups
;
7357 cleanups
= make_cleanup (do_vec_free
, &old_locations
);
7358 /* Store old locations for future reference. */
7359 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7360 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7362 bp_location_chain
= NULL
;
7365 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7368 next
= &(loc
->global_next
);
7373 /* Identify bp_location instances that are no longer present in the new
7374 list, and therefore should be freed. Note that it's not necessary that
7375 those locations should be removed from inferior -- if there's another
7376 location at the same address (previously marked as duplicate),
7377 we don't need to remove/insert the location. */
7378 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7380 /* Tells if 'loc' is found amoung the new locations. If not, we
7382 int found_object
= 0;
7383 /* Tells if the location should remain inserted in the target. */
7384 int keep_in_target
= 0;
7386 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7393 /* If this location is no longer present, and inserted, look if there's
7394 maybe a new location at the same address. If so, mark that one
7395 inserted, and don't remove this one. This is needed so that we
7396 don't have a time window where a breakpoint at certain location is not
7401 /* If the location is inserted now, we might have to remove it. */
7403 if (found_object
&& should_be_inserted (loc
))
7405 /* The location is still present in the location list, and still
7406 should be inserted. Don't do anything. */
7411 /* The location is either no longer present, or got disabled.
7412 See if there's another location at the same address, in which
7413 case we don't need to remove this one from the target. */
7414 if (breakpoint_address_is_meaningful (loc
->owner
))
7415 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7417 /* For the sake of should_insert_location. The
7418 call to check_duplicates will fix up this later. */
7419 loc2
->duplicate
= 0;
7420 if (should_be_inserted (loc2
)
7421 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7424 loc2
->target_info
= loc
->target_info
;
7431 if (!keep_in_target
)
7433 if (remove_breakpoint (loc
, mark_uninserted
))
7435 /* This is just about all we can do. We could keep this
7436 location on the global list, and try to remove it next
7437 time, but there's no particular reason why we will
7440 Note that at this point, loc->owner is still valid,
7441 as delete_breakpoint frees the breakpoint only
7442 after calling us. */
7443 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7444 loc
->owner
->number
);
7452 if (removed
&& non_stop
)
7454 /* This location was removed from the targets. In non-stop mode,
7455 a race condition is possible where we've removed a breakpoint,
7456 but stop events for that breakpoint are already queued and will
7457 arrive later. To suppress spurious SIGTRAPs reported to user,
7458 we keep this breakpoint location for a bit, and will retire it
7459 after we see 3 * thread_count events.
7460 The theory here is that reporting of events should,
7461 "on the average", be fair, so after that many event we'll see
7462 events from all threads that have anything of interest, and no
7463 longer need to keep this breakpoint. This is just a
7464 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7465 which is usability issue, but not a correctness problem. */
7466 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7469 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
7472 free_bp_location (loc
);
7478 check_duplicates (b
);
7481 if (breakpoints_always_inserted_mode () && should_insert
7482 && (have_live_inferiors ()
7483 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
7484 insert_breakpoint_locations ();
7486 do_cleanups (cleanups
);
7490 breakpoint_retire_moribund (void)
7492 struct bp_location
*loc
;
7495 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7496 if (--(loc
->events_till_retirement
) == 0)
7498 free_bp_location (loc
);
7499 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7505 update_global_location_list_nothrow (int inserting
)
7507 struct gdb_exception e
;
7508 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7509 update_global_location_list (inserting
);
7512 /* Clear BPT from a BPS. */
7514 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7517 for (bs
= bps
; bs
; bs
= bs
->next
)
7518 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7520 bs
->breakpoint_at
= NULL
;
7522 /* bs->commands will be freed later. */
7526 /* Callback for iterate_over_threads. */
7528 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7530 struct breakpoint
*bpt
= data
;
7531 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7535 /* Delete a breakpoint and clean up all traces of it in the data
7539 delete_breakpoint (struct breakpoint
*bpt
)
7541 struct breakpoint
*b
;
7542 struct bp_location
*loc
, *next
;
7544 gdb_assert (bpt
!= NULL
);
7546 /* Has this bp already been deleted? This can happen because multiple
7547 lists can hold pointers to bp's. bpstat lists are especial culprits.
7549 One example of this happening is a watchpoint's scope bp. When the
7550 scope bp triggers, we notice that the watchpoint is out of scope, and
7551 delete it. We also delete its scope bp. But the scope bp is marked
7552 "auto-deleting", and is already on a bpstat. That bpstat is then
7553 checked for auto-deleting bp's, which are deleted.
7555 A real solution to this problem might involve reference counts in bp's,
7556 and/or giving them pointers back to their referencing bpstat's, and
7557 teaching delete_breakpoint to only free a bp's storage when no more
7558 references were extent. A cheaper bandaid was chosen. */
7559 if (bpt
->type
== bp_none
)
7562 observer_notify_breakpoint_deleted (bpt
->number
);
7564 if (breakpoint_chain
== bpt
)
7565 breakpoint_chain
= bpt
->next
;
7570 b
->next
= bpt
->next
;
7574 free_command_lines (&bpt
->commands
);
7575 if (bpt
->cond_string
!= NULL
)
7576 xfree (bpt
->cond_string
);
7577 if (bpt
->addr_string
!= NULL
)
7578 xfree (bpt
->addr_string
);
7579 if (bpt
->exp
!= NULL
)
7581 if (bpt
->exp_string
!= NULL
)
7582 xfree (bpt
->exp_string
);
7583 if (bpt
->val
!= NULL
)
7584 value_free (bpt
->val
);
7585 if (bpt
->source_file
!= NULL
)
7586 xfree (bpt
->source_file
);
7587 if (bpt
->exec_pathname
!= NULL
)
7588 xfree (bpt
->exec_pathname
);
7590 /* Be sure no bpstat's are pointing at it after it's been freed. */
7591 /* FIXME, how can we find all bpstat's?
7592 We just check stop_bpstat for now. Note that we cannot just
7593 remove bpstats pointing at bpt from the stop_bpstat list
7594 entirely, as breakpoint commands are associated with the bpstat;
7595 if we remove it here, then the later call to
7596 bpstat_do_actions (&stop_bpstat);
7597 in event-top.c won't do anything, and temporary breakpoints
7598 with commands won't work. */
7600 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7602 /* Now that breakpoint is removed from breakpoint
7603 list, update the global location list. This
7604 will remove locations that used to belong to
7605 this breakpoint. Do this before freeing
7606 the breakpoint itself, since remove_breakpoint
7607 looks at location's owner. It might be better
7608 design to have location completely self-contained,
7609 but it's not the case now. */
7610 update_global_location_list (0);
7613 /* On the chance that someone will soon try again to delete this same
7614 bp, we mark it as deleted before freeing its storage. */
7615 bpt
->type
= bp_none
;
7621 do_delete_breakpoint_cleanup (void *b
)
7623 delete_breakpoint (b
);
7627 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7629 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7633 delete_command (char *arg
, int from_tty
)
7635 struct breakpoint
*b
, *temp
;
7641 int breaks_to_delete
= 0;
7643 /* Delete all breakpoints if no argument.
7644 Do not delete internal or call-dummy breakpoints, these
7645 have to be deleted with an explicit breakpoint number argument. */
7648 if (b
->type
!= bp_call_dummy
7649 && b
->type
!= bp_shlib_event
7650 && b
->type
!= bp_thread_event
7651 && b
->type
!= bp_overlay_event
7652 && b
->type
!= bp_longjmp_master
7655 breaks_to_delete
= 1;
7660 /* Ask user only if there are some breakpoints to delete. */
7662 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7664 ALL_BREAKPOINTS_SAFE (b
, temp
)
7666 if (b
->type
!= bp_call_dummy
7667 && b
->type
!= bp_shlib_event
7668 && b
->type
!= bp_thread_event
7669 && b
->type
!= bp_overlay_event
7670 && b
->type
!= bp_longjmp_master
7672 delete_breakpoint (b
);
7677 map_breakpoint_numbers (arg
, delete_breakpoint
);
7681 all_locations_are_pending (struct bp_location
*loc
)
7683 for (; loc
; loc
= loc
->next
)
7684 if (!loc
->shlib_disabled
)
7689 /* Subroutine of update_breakpoint_locations to simplify it.
7690 Return non-zero if multiple fns in list LOC have the same name.
7691 Null names are ignored. */
7694 ambiguous_names_p (struct bp_location
*loc
)
7696 struct bp_location
*l
;
7697 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7698 (int (*) (const void *, const void *)) streq
,
7699 NULL
, xcalloc
, xfree
);
7701 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7704 const char *name
= l
->function_name
;
7706 /* Allow for some names to be NULL, ignore them. */
7710 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7712 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7727 update_breakpoint_locations (struct breakpoint
*b
,
7728 struct symtabs_and_lines sals
)
7732 struct bp_location
*existing_locations
= b
->loc
;
7734 /* If there's no new locations, and all existing locations
7735 are pending, don't do anything. This optimizes
7736 the common case where all locations are in the same
7737 shared library, that was unloaded. We'd like to
7738 retain the location, so that when the library
7739 is loaded again, we don't loose the enabled/disabled
7740 status of the individual locations. */
7741 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7746 for (i
= 0; i
< sals
.nelts
; ++i
)
7748 struct bp_location
*new_loc
=
7749 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
7751 /* Reparse conditions, they might contain references to the
7753 if (b
->cond_string
!= NULL
)
7755 struct gdb_exception e
;
7758 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7760 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7765 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7766 b
->number
, e
.message
);
7767 new_loc
->enabled
= 0;
7771 if (b
->source_file
!= NULL
)
7772 xfree (b
->source_file
);
7773 if (sals
.sals
[i
].symtab
== NULL
)
7774 b
->source_file
= NULL
;
7776 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
7778 if (b
->line_number
== 0)
7779 b
->line_number
= sals
.sals
[i
].line
;
7782 /* Update locations of permanent breakpoints. */
7783 if (b
->enable_state
== bp_permanent
)
7784 make_breakpoint_permanent (b
);
7786 /* If possible, carry over 'disable' status from existing breakpoints. */
7788 struct bp_location
*e
= existing_locations
;
7789 /* If there are multiple breakpoints with the same function name,
7790 e.g. for inline functions, comparing function names won't work.
7791 Instead compare pc addresses; this is just a heuristic as things
7792 may have moved, but in practice it gives the correct answer
7793 often enough until a better solution is found. */
7794 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7796 for (; e
; e
= e
->next
)
7798 if (!e
->enabled
&& e
->function_name
)
7800 struct bp_location
*l
= b
->loc
;
7801 if (have_ambiguous_names
)
7803 for (; l
; l
= l
->next
)
7804 if (e
->address
== l
->address
)
7812 for (; l
; l
= l
->next
)
7813 if (l
->function_name
7814 && strcmp (e
->function_name
, l
->function_name
) == 0)
7824 update_global_location_list (1);
7828 /* Reset a breakpoint given it's struct breakpoint * BINT.
7829 The value we return ends up being the return value from catch_errors.
7830 Unused in this case. */
7833 breakpoint_re_set_one (void *bint
)
7835 /* get past catch_errs */
7836 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7840 int *not_found_ptr
= ¬_found
;
7841 struct symtabs_and_lines sals
= {};
7842 struct symtabs_and_lines expanded
;
7844 enum enable_state save_enable
;
7845 struct gdb_exception e
;
7846 struct cleanup
*cleanups
;
7851 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7855 case bp_hardware_breakpoint
:
7857 /* Do not attempt to re-set breakpoints disabled during startup. */
7858 if (b
->enable_state
== bp_startup_disabled
)
7861 if (b
->addr_string
== NULL
)
7863 /* Anything without a string can't be re-set. */
7864 delete_breakpoint (b
);
7868 set_language (b
->language
);
7869 input_radix
= b
->input_radix
;
7871 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7873 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7878 int not_found_and_ok
= 0;
7879 /* For pending breakpoints, it's expected that parsing
7880 will fail until the right shared library is loaded.
7881 User has already told to create pending breakpoints and
7882 don't need extra messages. If breakpoint is in bp_shlib_disabled
7883 state, then user already saw the message about that breakpoint
7884 being disabled, and don't want to see more errors. */
7886 && (b
->condition_not_parsed
7887 || (b
->loc
&& b
->loc
->shlib_disabled
)
7888 || b
->enable_state
== bp_disabled
))
7889 not_found_and_ok
= 1;
7891 if (!not_found_and_ok
)
7893 /* We surely don't want to warn about the same breakpoint
7894 10 times. One solution, implemented here, is disable
7895 the breakpoint on error. Another solution would be to
7896 have separate 'warning emitted' flag. Since this
7897 happens only when a binary has changed, I don't know
7898 which approach is better. */
7899 b
->enable_state
= bp_disabled
;
7900 throw_exception (e
);
7907 gdb_assert (sals
.nelts
== 1);
7908 resolve_sal_pc (&sals
.sals
[0]);
7909 if (b
->condition_not_parsed
&& s
&& s
[0])
7911 char *cond_string
= 0;
7915 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7916 &cond_string
, &thread
, &task
);
7918 b
->cond_string
= cond_string
;
7921 b
->condition_not_parsed
= 0;
7923 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7924 cleanups
= make_cleanup (xfree
, sals
.sals
);
7925 update_breakpoint_locations (b
, expanded
);
7926 do_cleanups (cleanups
);
7930 case bp_hardware_watchpoint
:
7931 case bp_read_watchpoint
:
7932 case bp_access_watchpoint
:
7933 /* Watchpoint can be either on expression using entirely global variables,
7934 or it can be on local variables.
7936 Watchpoints of the first kind are never auto-deleted, and even persist
7937 across program restarts. Since they can use variables from shared
7938 libraries, we need to reparse expression as libraries are loaded
7941 Watchpoints on local variables can also change meaning as result
7942 of solib event. For example, if a watchpoint uses both a local and
7943 a global variables in expression, it's a local watchpoint, but
7944 unloading of a shared library will make the expression invalid.
7945 This is not a very common use case, but we still re-evaluate
7946 expression, to avoid surprises to the user.
7948 Note that for local watchpoints, we re-evaluate it only if
7949 watchpoints frame id is still valid. If it's not, it means
7950 the watchpoint is out of scope and will be deleted soon. In fact,
7951 I'm not sure we'll ever be called in this case.
7953 If a local watchpoint's frame id is still valid, then
7954 b->exp_valid_block is likewise valid, and we can safely use it.
7956 Don't do anything about disabled watchpoints, since they will
7957 be reevaluated again when enabled. */
7958 update_watchpoint (b
, 1 /* reparse */);
7960 /* We needn't really do anything to reset these, since the mask
7961 that requests them is unaffected by e.g., new libraries being
7967 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7969 /* Delete overlay event and longjmp master breakpoints; they will be
7970 reset later by breakpoint_re_set. */
7971 case bp_overlay_event
:
7972 case bp_longjmp_master
:
7973 delete_breakpoint (b
);
7976 /* This breakpoint is special, it's set up when the inferior
7977 starts and we really don't want to touch it. */
7978 case bp_shlib_event
:
7980 /* Like bp_shlib_event, this breakpoint type is special.
7981 Once it is set up, we do not want to touch it. */
7982 case bp_thread_event
:
7984 /* Keep temporary breakpoints, which can be encountered when we step
7985 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7986 Otherwise these should have been blown away via the cleanup chain
7987 or by breakpoint_init_inferior when we rerun the executable. */
7990 case bp_watchpoint_scope
:
7992 case bp_step_resume
:
7994 case bp_longjmp_resume
:
8001 /* Re-set all breakpoints after symbols have been re-loaded. */
8003 breakpoint_re_set (void)
8005 struct breakpoint
*b
, *temp
;
8006 enum language save_language
;
8007 int save_input_radix
;
8009 save_language
= current_language
->la_language
;
8010 save_input_radix
= input_radix
;
8011 ALL_BREAKPOINTS_SAFE (b
, temp
)
8013 /* Format possible error msg */
8014 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
8016 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
8017 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
8018 do_cleanups (cleanups
);
8020 set_language (save_language
);
8021 input_radix
= save_input_radix
;
8023 create_overlay_event_breakpoint ("_ovly_debug_event");
8024 create_longjmp_master_breakpoint ("longjmp");
8025 create_longjmp_master_breakpoint ("_longjmp");
8026 create_longjmp_master_breakpoint ("siglongjmp");
8027 create_longjmp_master_breakpoint ("_siglongjmp");
8030 /* Reset the thread number of this breakpoint:
8032 - If the breakpoint is for all threads, leave it as-is.
8033 - Else, reset it to the current thread for inferior_ptid. */
8035 breakpoint_re_set_thread (struct breakpoint
*b
)
8037 if (b
->thread
!= -1)
8039 if (in_thread_list (inferior_ptid
))
8040 b
->thread
= pid_to_thread_id (inferior_ptid
);
8044 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
8045 If from_tty is nonzero, it prints a message to that effect,
8046 which ends with a period (no newline). */
8049 set_ignore_count (int bptnum
, int count
, int from_tty
)
8051 struct breakpoint
*b
;
8057 if (b
->number
== bptnum
)
8059 b
->ignore_count
= count
;
8063 printf_filtered (_("Will stop next time breakpoint %d is reached."),
8065 else if (count
== 1)
8066 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
8069 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
8072 breakpoints_changed ();
8073 observer_notify_breakpoint_modified (b
->number
);
8077 error (_("No breakpoint number %d."), bptnum
);
8081 make_breakpoint_silent (struct breakpoint
*b
)
8083 /* Silence the breakpoint. */
8087 /* Command to set ignore-count of breakpoint N to COUNT. */
8090 ignore_command (char *args
, int from_tty
)
8096 error_no_arg (_("a breakpoint number"));
8098 num
= get_number (&p
);
8100 error (_("bad breakpoint number: '%s'"), args
);
8102 error (_("Second argument (specified ignore-count) is missing."));
8104 set_ignore_count (num
,
8105 longest_to_int (value_as_long (parse_and_eval (p
))),
8108 printf_filtered ("\n");
8111 /* Call FUNCTION on each of the breakpoints
8112 whose numbers are given in ARGS. */
8115 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
8120 struct breakpoint
*b
, *tmp
;
8124 error_no_arg (_("one or more breakpoint numbers"));
8131 num
= get_number_or_range (&p1
);
8134 warning (_("bad breakpoint number at or near '%s'"), p
);
8138 ALL_BREAKPOINTS_SAFE (b
, tmp
)
8139 if (b
->number
== num
)
8141 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
8144 if (related_breakpoint
)
8145 function (related_breakpoint
);
8149 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
8155 static struct bp_location
*
8156 find_location_by_number (char *number
)
8158 char *dot
= strchr (number
, '.');
8162 struct breakpoint
*b
;
8163 struct bp_location
*loc
;
8168 bp_num
= get_number_or_range (&p1
);
8170 error (_("Bad breakpoint number '%s'"), number
);
8173 if (b
->number
== bp_num
)
8178 if (!b
|| b
->number
!= bp_num
)
8179 error (_("Bad breakpoint number '%s'"), number
);
8182 loc_num
= get_number_or_range (&p1
);
8184 error (_("Bad breakpoint location number '%s'"), number
);
8188 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
8191 error (_("Bad breakpoint location number '%s'"), dot
+1);
8197 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
8198 If from_tty is nonzero, it prints a message to that effect,
8199 which ends with a period (no newline). */
8202 disable_breakpoint (struct breakpoint
*bpt
)
8204 /* Never disable a watchpoint scope breakpoint; we want to
8205 hit them when we leave scope so we can delete both the
8206 watchpoint and its scope breakpoint at that time. */
8207 if (bpt
->type
== bp_watchpoint_scope
)
8210 /* You can't disable permanent breakpoints. */
8211 if (bpt
->enable_state
== bp_permanent
)
8214 bpt
->enable_state
= bp_disabled
;
8216 update_global_location_list (0);
8218 observer_notify_breakpoint_modified (bpt
->number
);
8222 disable_command (char *args
, int from_tty
)
8224 struct breakpoint
*bpt
;
8226 ALL_BREAKPOINTS (bpt
)
8230 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
8236 case bp_hardware_breakpoint
:
8238 case bp_hardware_watchpoint
:
8239 case bp_read_watchpoint
:
8240 case bp_access_watchpoint
:
8241 disable_breakpoint (bpt
);
8245 else if (strchr (args
, '.'))
8247 struct bp_location
*loc
= find_location_by_number (args
);
8250 update_global_location_list (0);
8253 map_breakpoint_numbers (args
, disable_breakpoint
);
8257 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
8259 int target_resources_ok
, other_type_used
;
8262 if (bpt
->type
== bp_hardware_breakpoint
)
8265 i
= hw_breakpoint_used_count ();
8266 target_resources_ok
=
8267 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8269 if (target_resources_ok
== 0)
8270 error (_("No hardware breakpoint support in the target."));
8271 else if (target_resources_ok
< 0)
8272 error (_("Hardware breakpoints used exceeds limit."));
8275 if (bpt
->type
== bp_watchpoint
8276 || bpt
->type
== bp_hardware_watchpoint
8277 || bpt
->type
== bp_read_watchpoint
8278 || bpt
->type
== bp_access_watchpoint
)
8280 struct gdb_exception e
;
8282 TRY_CATCH (e
, RETURN_MASK_ALL
)
8284 update_watchpoint (bpt
, 1 /* reparse */);
8288 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
8294 if (bpt
->enable_state
!= bp_permanent
)
8295 bpt
->enable_state
= bp_enabled
;
8296 bpt
->disposition
= disposition
;
8297 update_global_location_list (1);
8298 breakpoints_changed ();
8300 observer_notify_breakpoint_modified (bpt
->number
);
8305 enable_breakpoint (struct breakpoint
*bpt
)
8307 do_enable_breakpoint (bpt
, bpt
->disposition
);
8310 /* The enable command enables the specified breakpoints (or all defined
8311 breakpoints) so they once again become (or continue to be) effective
8312 in stopping the inferior. */
8315 enable_command (char *args
, int from_tty
)
8317 struct breakpoint
*bpt
;
8319 ALL_BREAKPOINTS (bpt
)
8323 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8329 case bp_hardware_breakpoint
:
8331 case bp_hardware_watchpoint
:
8332 case bp_read_watchpoint
:
8333 case bp_access_watchpoint
:
8334 enable_breakpoint (bpt
);
8338 else if (strchr (args
, '.'))
8340 struct bp_location
*loc
= find_location_by_number (args
);
8343 update_global_location_list (1);
8346 map_breakpoint_numbers (args
, enable_breakpoint
);
8350 enable_once_breakpoint (struct breakpoint
*bpt
)
8352 do_enable_breakpoint (bpt
, disp_disable
);
8356 enable_once_command (char *args
, int from_tty
)
8358 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8362 enable_delete_breakpoint (struct breakpoint
*bpt
)
8364 do_enable_breakpoint (bpt
, disp_del
);
8368 enable_delete_command (char *args
, int from_tty
)
8370 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8374 set_breakpoint_cmd (char *args
, int from_tty
)
8379 show_breakpoint_cmd (char *args
, int from_tty
)
8383 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8385 struct symtabs_and_lines
8386 decode_line_spec_1 (char *string
, int funfirstline
)
8388 struct symtabs_and_lines sals
;
8390 error (_("Empty line specification."));
8391 if (default_breakpoint_valid
)
8392 sals
= decode_line_1 (&string
, funfirstline
,
8393 default_breakpoint_symtab
,
8394 default_breakpoint_line
,
8395 (char ***) NULL
, NULL
);
8397 sals
= decode_line_1 (&string
, funfirstline
,
8398 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8400 error (_("Junk at end of line specification: %s"), string
);
8404 /* Create and insert a raw software breakpoint at PC. Return an
8405 identifier, which should be used to remove the breakpoint later.
8406 In general, places which call this should be using something on the
8407 breakpoint chain instead; this function should be eliminated
8411 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
8413 struct bp_target_info
*bp_tgt
;
8415 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8416 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8418 bp_tgt
->placed_address
= pc
;
8419 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
8421 /* Could not insert the breakpoint. */
8429 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8432 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
8434 struct bp_target_info
*bp_tgt
= bp
;
8437 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
8443 /* One (or perhaps two) breakpoints used for software single stepping. */
8445 static void *single_step_breakpoints
[2];
8446 static struct gdbarch
*single_step_gdbarch
[2];
8448 /* Create and insert a breakpoint for software single step. */
8451 insert_single_step_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR next_pc
)
8455 if (single_step_breakpoints
[0] == NULL
)
8457 bpt_p
= &single_step_breakpoints
[0];
8458 single_step_gdbarch
[0] = gdbarch
;
8462 gdb_assert (single_step_breakpoints
[1] == NULL
);
8463 bpt_p
= &single_step_breakpoints
[1];
8464 single_step_gdbarch
[1] = gdbarch
;
8467 /* NOTE drow/2006-04-11: A future improvement to this function would be
8468 to only create the breakpoints once, and actually put them on the
8469 breakpoint chain. That would let us use set_raw_breakpoint. We could
8470 adjust the addresses each time they were needed. Doing this requires
8471 corresponding changes elsewhere where single step breakpoints are
8472 handled, however. So, for now, we use this. */
8474 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, next_pc
);
8476 error (_("Could not insert single-step breakpoint at %s"),
8477 paddress (gdbarch
, next_pc
));
8480 /* Remove and delete any breakpoints used for software single step. */
8483 remove_single_step_breakpoints (void)
8485 gdb_assert (single_step_breakpoints
[0] != NULL
);
8487 /* See insert_single_step_breakpoint for more about this deprecated
8489 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
8490 single_step_breakpoints
[0]);
8491 single_step_gdbarch
[0] = NULL
;
8492 single_step_breakpoints
[0] = NULL
;
8494 if (single_step_breakpoints
[1] != NULL
)
8496 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
8497 single_step_breakpoints
[1]);
8498 single_step_gdbarch
[1] = NULL
;
8499 single_step_breakpoints
[1] = NULL
;
8503 /* Check whether a software single-step breakpoint is inserted at PC. */
8506 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8510 for (i
= 0; i
< 2; i
++)
8512 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8513 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8520 /* Tracepoint-specific operations. */
8522 /* Set tracepoint count to NUM. */
8524 set_tracepoint_count (int num
)
8526 tracepoint_count
= num
;
8527 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
8531 trace_command (char *arg
, int from_tty
)
8533 break_command_really (get_current_arch (),
8535 NULL
, 0, 1 /* parse arg */,
8536 0 /* tempflag */, 0 /* hardwareflag */,
8538 0 /* Ignore count */,
8539 pending_break_support
,
8543 set_tracepoint_count (breakpoint_count
);
8546 /* Print information on tracepoint number TPNUM_EXP, or all if
8550 tracepoints_info (char *tpnum_exp
, int from_tty
)
8552 struct breakpoint
*b
;
8553 int tps_to_list
= 0;
8555 /* In the no-arguments case, say "No tracepoints" if none found. */
8568 ui_out_message (uiout
, 0, "No tracepoints.\n");
8573 /* Otherwise be the same as "info break". */
8574 breakpoints_info (tpnum_exp
, from_tty
);
8577 /* The 'enable trace' command enables tracepoints.
8578 Not supported by all targets. */
8580 enable_trace_command (char *args
, int from_tty
)
8582 enable_command (args
, from_tty
);
8585 /* The 'disable trace' command disables tracepoints.
8586 Not supported by all targets. */
8588 disable_trace_command (char *args
, int from_tty
)
8590 disable_command (args
, from_tty
);
8593 /* Remove a tracepoint (or all if no argument) */
8595 delete_trace_command (char *arg
, int from_tty
)
8597 struct breakpoint
*b
, *temp
;
8603 int breaks_to_delete
= 0;
8605 /* Delete all breakpoints if no argument.
8606 Do not delete internal or call-dummy breakpoints, these
8607 have to be deleted with an explicit breakpoint number argument. */
8612 breaks_to_delete
= 1;
8617 /* Ask user only if there are some breakpoints to delete. */
8619 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
8621 ALL_BREAKPOINTS_SAFE (b
, temp
)
8623 if (b
->type
== bp_tracepoint
8625 delete_breakpoint (b
);
8630 map_breakpoint_numbers (arg
, delete_breakpoint
);
8633 /* Set passcount for tracepoint.
8635 First command argument is passcount, second is tracepoint number.
8636 If tracepoint number omitted, apply to most recently defined.
8637 Also accepts special argument "all". */
8640 trace_pass_command (char *args
, int from_tty
)
8642 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
8646 if (args
== 0 || *args
== 0)
8647 error (_("passcount command requires an argument (count + optional TP num)"));
8649 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
8651 while (*args
&& isspace ((int) *args
))
8654 if (*args
&& strncasecmp (args
, "all", 3) == 0)
8656 args
+= 3; /* Skip special argument "all". */
8659 error (_("Junk at end of arguments."));
8662 t1
= get_tracepoint_by_number (&args
, 1, 1);
8668 ALL_TRACEPOINTS (t2
)
8669 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
8671 t2
->pass_count
= count
;
8672 observer_notify_tracepoint_modified (t2
->number
);
8674 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
8678 t1
= get_tracepoint_by_number (&args
, 1, 0);
8685 get_tracepoint (int num
)
8687 struct breakpoint
*t
;
8690 if (t
->number
== num
)
8696 /* Utility: parse a tracepoint number and look it up in the list.
8697 If MULTI_P is true, there might be a range of tracepoints in ARG.
8698 if OPTIONAL_P is true, then if the argument is missing, the most
8699 recent tracepoint (tracepoint_count) is returned. */
8701 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
8703 extern int tracepoint_count
;
8704 struct breakpoint
*t
;
8706 char *instring
= arg
== NULL
? NULL
: *arg
;
8708 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
8711 tpnum
= tracepoint_count
;
8713 error_no_arg (_("tracepoint number"));
8716 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
8720 if (instring
&& *instring
)
8721 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
8724 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
8729 if (t
->number
== tpnum
)
8734 /* FIXME: if we are in the middle of a range we don't want to give
8735 a message. The current interface to get_number_or_range doesn't
8736 allow us to discover this. */
8737 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
8741 /* save-tracepoints command */
8743 tracepoint_save_command (char *args
, int from_tty
)
8745 struct breakpoint
*tp
;
8747 struct action_line
*line
;
8749 char *i1
= " ", *i2
= " ";
8750 char *indent
, *actionline
, *pathname
;
8752 struct cleanup
*cleanup
;
8754 if (args
== 0 || *args
== 0)
8755 error (_("Argument required (file name in which to save tracepoints)"));
8757 /* See if we have anything to save. */
8758 ALL_TRACEPOINTS (tp
)
8765 warning (_("save-tracepoints: no tracepoints to save."));
8769 pathname
= tilde_expand (args
);
8770 cleanup
= make_cleanup (xfree
, pathname
);
8771 fp
= fopen (pathname
, "w");
8773 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
8774 args
, safe_strerror (errno
));
8775 make_cleanup_fclose (fp
);
8777 ALL_TRACEPOINTS (tp
)
8779 if (tp
->addr_string
)
8780 fprintf (fp
, "trace %s\n", tp
->addr_string
);
8783 sprintf_vma (tmp
, tp
->loc
->address
);
8784 fprintf (fp
, "trace *0x%s\n", tmp
);
8788 fprintf (fp
, " passcount %d\n", tp
->pass_count
);
8792 fprintf (fp
, " actions\n");
8794 for (line
= tp
->actions
; line
; line
= line
->next
)
8796 struct cmd_list_element
*cmd
;
8798 QUIT
; /* allow user to bail out with ^C */
8799 actionline
= line
->action
;
8800 while (isspace ((int) *actionline
))
8803 fprintf (fp
, "%s%s\n", indent
, actionline
);
8804 if (*actionline
!= '#') /* skip for comment lines */
8806 cmd
= lookup_cmd (&actionline
, cmdlist
, "", -1, 1);
8808 error (_("Bad action list item: %s"), actionline
);
8809 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
8811 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
8817 do_cleanups (cleanup
);
8819 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
8823 /* Create a vector of all tracepoints. */
8828 VEC(breakpoint_p
) *tp_vec
= 0;
8829 struct breakpoint
*tp
;
8831 ALL_TRACEPOINTS (tp
)
8833 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
8840 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8841 It is defined as a macro to prevent duplication.
8842 COMMAND should be a string constant containing the name of the command. */
8843 #define BREAK_ARGS_HELP(command) \
8844 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8845 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8846 If a line number is specified, break at start of code for that line.\n\
8847 If a function is specified, break at start of code for that function.\n\
8848 If an address is specified, break at that exact address.\n\
8849 With no LOCATION, uses current execution address of selected stack frame.\n\
8850 This is useful for breaking on return to a stack frame.\n\
8852 THREADNUM is the number from \"info threads\".\n\
8853 CONDITION is a boolean expression.\n\
8855 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8857 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8859 /* List of subcommands for "catch". */
8860 static struct cmd_list_element
*catch_cmdlist
;
8862 /* List of subcommands for "tcatch". */
8863 static struct cmd_list_element
*tcatch_cmdlist
;
8865 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8866 lists, and pass some additional user data to the command function. */
8868 add_catch_command (char *name
, char *docstring
,
8869 void (*sfunc
) (char *args
, int from_tty
,
8870 struct cmd_list_element
*command
),
8871 void *user_data_catch
,
8872 void *user_data_tcatch
)
8874 struct cmd_list_element
*command
;
8876 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8878 set_cmd_sfunc (command
, sfunc
);
8879 set_cmd_context (command
, user_data_catch
);
8881 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8883 set_cmd_sfunc (command
, sfunc
);
8884 set_cmd_context (command
, user_data_tcatch
);
8888 _initialize_breakpoint (void)
8890 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8891 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8892 struct cmd_list_element
*c
;
8894 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8896 breakpoint_chain
= 0;
8897 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8898 before a breakpoint is set. */
8899 breakpoint_count
= 0;
8901 tracepoint_count
= 0;
8903 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8904 Set ignore-count of breakpoint number N to COUNT.\n\
8905 Usage is `ignore N COUNT'."));
8907 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8909 add_com ("commands", class_breakpoint
, commands_command
, _("\
8910 Set commands to be executed when a breakpoint is hit.\n\
8911 Give breakpoint number as argument after \"commands\".\n\
8912 With no argument, the targeted breakpoint is the last one set.\n\
8913 The commands themselves follow starting on the next line.\n\
8914 Type a line containing \"end\" to indicate the end of them.\n\
8915 Give \"silent\" as the first line to make the breakpoint silent;\n\
8916 then no output is printed when it is hit, except what the commands print."));
8918 add_com ("condition", class_breakpoint
, condition_command
, _("\
8919 Specify breakpoint number N to break only if COND is true.\n\
8920 Usage is `condition N COND', where N is an integer and COND is an\n\
8921 expression to be evaluated whenever breakpoint N is reached."));
8923 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8924 Set a temporary breakpoint.\n\
8925 Like \"break\" except the breakpoint is only temporary,\n\
8926 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8927 by using \"enable delete\" on the breakpoint number.\n\
8929 BREAK_ARGS_HELP ("tbreak")));
8930 set_cmd_completer (c
, location_completer
);
8932 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8933 Set a hardware assisted breakpoint.\n\
8934 Like \"break\" except the breakpoint requires hardware support,\n\
8935 some target hardware may not have this support.\n\
8937 BREAK_ARGS_HELP ("hbreak")));
8938 set_cmd_completer (c
, location_completer
);
8940 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8941 Set a temporary hardware assisted breakpoint.\n\
8942 Like \"hbreak\" except the breakpoint is only temporary,\n\
8943 so it will be deleted when hit.\n\
8945 BREAK_ARGS_HELP ("thbreak")));
8946 set_cmd_completer (c
, location_completer
);
8948 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8949 Enable some breakpoints.\n\
8950 Give breakpoint numbers (separated by spaces) as arguments.\n\
8951 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8952 This is used to cancel the effect of the \"disable\" command.\n\
8953 With a subcommand you can enable temporarily."),
8954 &enablelist
, "enable ", 1, &cmdlist
);
8956 add_com ("ab", class_breakpoint
, enable_command
, _("\
8957 Enable some breakpoints.\n\
8958 Give breakpoint numbers (separated by spaces) as arguments.\n\
8959 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8960 This is used to cancel the effect of the \"disable\" command.\n\
8961 With a subcommand you can enable temporarily."));
8963 add_com_alias ("en", "enable", class_breakpoint
, 1);
8965 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8966 Enable some breakpoints.\n\
8967 Give breakpoint numbers (separated by spaces) as arguments.\n\
8968 This is used to cancel the effect of the \"disable\" command.\n\
8969 May be abbreviated to simply \"enable\".\n"),
8970 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
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_cmd ("delete", no_class
, enable_delete_command
, _("\
8978 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8979 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8982 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8983 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8984 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8987 add_cmd ("once", no_class
, enable_once_command
, _("\
8988 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8989 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8992 add_prefix_cmd ("disable", class_breakpoint
, 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."),
8997 &disablelist
, "disable ", 1, &cmdlist
);
8998 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8999 add_com_alias ("disa", "disable", class_breakpoint
, 1);
9001 add_com ("sb", class_breakpoint
, disable_command
, _("\
9002 Disable some breakpoints.\n\
9003 Arguments are breakpoint numbers with spaces in between.\n\
9004 To disable all breakpoints, give no argument.\n\
9005 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
9007 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
9008 Disable some breakpoints.\n\
9009 Arguments are breakpoint numbers with spaces in between.\n\
9010 To disable all breakpoints, give no argument.\n\
9011 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
9012 This command may be abbreviated \"disable\"."),
9015 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
9016 Delete some breakpoints or auto-display expressions.\n\
9017 Arguments are breakpoint numbers with spaces in between.\n\
9018 To delete all breakpoints, give no argument.\n\
9020 Also a prefix command for deletion of other GDB objects.\n\
9021 The \"unset\" command is also an alias for \"delete\"."),
9022 &deletelist
, "delete ", 1, &cmdlist
);
9023 add_com_alias ("d", "delete", class_breakpoint
, 1);
9024 add_com_alias ("del", "delete", class_breakpoint
, 1);
9026 add_com ("db", class_breakpoint
, delete_command
, _("\
9027 Delete some breakpoints.\n\
9028 Arguments are breakpoint numbers with spaces in between.\n\
9029 To delete all breakpoints, give no argument.\n"));
9031 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
9032 Delete some breakpoints or auto-display expressions.\n\
9033 Arguments are breakpoint numbers with spaces in between.\n\
9034 To delete all breakpoints, give no argument.\n\
9035 This command may be abbreviated \"delete\"."),
9038 add_com ("clear", class_breakpoint
, clear_command
, _("\
9039 Clear breakpoint at specified line or function.\n\
9040 Argument may be line number, function name, or \"*\" and an address.\n\
9041 If line number is specified, all breakpoints in that line are cleared.\n\
9042 If function is specified, breakpoints at beginning of function are cleared.\n\
9043 If an address is specified, breakpoints at that address are cleared.\n\
9045 With no argument, clears all breakpoints in the line that the selected frame\n\
9048 See also the \"delete\" command which clears breakpoints by number."));
9050 c
= add_com ("break", class_breakpoint
, break_command
, _("\
9051 Set breakpoint at specified line or function.\n"
9052 BREAK_ARGS_HELP ("break")));
9053 set_cmd_completer (c
, location_completer
);
9055 add_com_alias ("b", "break", class_run
, 1);
9056 add_com_alias ("br", "break", class_run
, 1);
9057 add_com_alias ("bre", "break", class_run
, 1);
9058 add_com_alias ("brea", "break", class_run
, 1);
9061 add_com_alias ("ba", "break", class_breakpoint
, 1);
9065 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
9066 Break in function/address or break at a line in the current file."),
9067 &stoplist
, "stop ", 1, &cmdlist
);
9068 add_cmd ("in", class_breakpoint
, stopin_command
,
9069 _("Break in function or address."), &stoplist
);
9070 add_cmd ("at", class_breakpoint
, stopat_command
,
9071 _("Break at a line in the current file."), &stoplist
);
9072 add_com ("status", class_info
, breakpoints_info
, _("\
9073 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9074 The \"Type\" column indicates one of:\n\
9075 \tbreakpoint - normal breakpoint\n\
9076 \twatchpoint - watchpoint\n\
9077 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9078 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9079 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9080 address and file/line number respectively.\n\
9082 Convenience variable \"$_\" and default examine address for \"x\"\n\
9083 are set to the address of the last breakpoint listed unless the command\n\
9084 is prefixed with \"server \".\n\n\
9085 Convenience variable \"$bpnum\" contains the number of the last\n\
9089 add_info ("breakpoints", breakpoints_info
, _("\
9090 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9091 The \"Type\" column indicates one of:\n\
9092 \tbreakpoint - normal breakpoint\n\
9093 \twatchpoint - watchpoint\n\
9094 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9095 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9096 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9097 address and file/line number respectively.\n\
9099 Convenience variable \"$_\" and default examine address for \"x\"\n\
9100 are set to the address of the last breakpoint listed unless the command\n\
9101 is prefixed with \"server \".\n\n\
9102 Convenience variable \"$bpnum\" contains the number of the last\n\
9106 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
9107 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9108 The \"Type\" column indicates one of:\n\
9109 \tbreakpoint - normal breakpoint\n\
9110 \twatchpoint - watchpoint\n\
9111 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9112 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9113 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9114 address and file/line number respectively.\n\
9116 Convenience variable \"$_\" and default examine address for \"x\"\n\
9117 are set to the address of the last breakpoint listed unless the command\n\
9118 is prefixed with \"server \".\n\n\
9119 Convenience variable \"$bpnum\" contains the number of the last\n\
9122 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
9123 Status of all breakpoints, or breakpoint number NUMBER.\n\
9124 The \"Type\" column indicates one of:\n\
9125 \tbreakpoint - normal breakpoint\n\
9126 \twatchpoint - watchpoint\n\
9127 \tlongjmp - internal breakpoint used to step through longjmp()\n\
9128 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
9129 \tuntil - internal breakpoint used by the \"until\" command\n\
9130 \tfinish - internal breakpoint used by the \"finish\" command\n\
9131 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9132 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9133 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9134 address and file/line number respectively.\n\
9136 Convenience variable \"$_\" and default examine address for \"x\"\n\
9137 are set to the address of the last breakpoint listed unless the command\n\
9138 is prefixed with \"server \".\n\n\
9139 Convenience variable \"$bpnum\" contains the number of the last\n\
9141 &maintenanceinfolist
);
9143 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
9144 Set catchpoints to catch events."),
9145 &catch_cmdlist
, "catch ",
9146 0/*allow-unknown*/, &cmdlist
);
9148 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
9149 Set temporary catchpoints to catch events."),
9150 &tcatch_cmdlist
, "tcatch ",
9151 0/*allow-unknown*/, &cmdlist
);
9153 /* Add catch and tcatch sub-commands. */
9154 add_catch_command ("catch", _("\
9155 Catch an exception, when caught.\n\
9156 With an argument, catch only exceptions with the given name."),
9157 catch_catch_command
,
9160 add_catch_command ("throw", _("\
9161 Catch an exception, when thrown.\n\
9162 With an argument, catch only exceptions with the given name."),
9163 catch_throw_command
,
9166 add_catch_command ("fork", _("Catch calls to fork."),
9167 catch_fork_command_1
,
9168 (void *) (uintptr_t) catch_fork_permanent
,
9169 (void *) (uintptr_t) catch_fork_temporary
);
9170 add_catch_command ("vfork", _("Catch calls to vfork."),
9171 catch_fork_command_1
,
9172 (void *) (uintptr_t) catch_vfork_permanent
,
9173 (void *) (uintptr_t) catch_vfork_temporary
);
9174 add_catch_command ("exec", _("Catch calls to exec."),
9175 catch_exec_command_1
,
9178 add_catch_command ("exception", _("\
9179 Catch Ada exceptions, when raised.\n\
9180 With an argument, catch only exceptions with the given name."),
9181 catch_ada_exception_command
,
9184 add_catch_command ("assert", _("\
9185 Catch failed Ada assertions, when raised.\n\
9186 With an argument, catch only exceptions with the given name."),
9187 catch_assert_command
,
9191 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
9192 Set a watchpoint for an expression.\n\
9193 A watchpoint stops execution of your program whenever the value of\n\
9194 an expression changes."));
9195 set_cmd_completer (c
, expression_completer
);
9197 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
9198 Set a read watchpoint for an expression.\n\
9199 A watchpoint stops execution of your program whenever the value of\n\
9200 an expression is read."));
9201 set_cmd_completer (c
, expression_completer
);
9203 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
9204 Set a watchpoint for an expression.\n\
9205 A watchpoint stops execution of your program whenever the value of\n\
9206 an expression is either read or written."));
9207 set_cmd_completer (c
, expression_completer
);
9209 add_info ("watchpoints", breakpoints_info
,
9210 _("Synonym for ``info breakpoints''."));
9213 /* XXX: cagney/2005-02-23: This should be a boolean, and should
9214 respond to changes - contrary to the description. */
9215 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
9216 &can_use_hw_watchpoints
, _("\
9217 Set debugger's willingness to use watchpoint hardware."), _("\
9218 Show debugger's willingness to use watchpoint hardware."), _("\
9219 If zero, gdb will not use hardware for new watchpoints, even if\n\
9220 such is available. (However, any hardware watchpoints that were\n\
9221 created before setting this to nonzero, will continue to use watchpoint\n\
9224 show_can_use_hw_watchpoints
,
9225 &setlist
, &showlist
);
9227 can_use_hw_watchpoints
= 1;
9229 /* Tracepoint manipulation commands. */
9231 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
9232 Set a tracepoint at specified line or function.\n\
9234 BREAK_ARGS_HELP ("trace") "\n\
9235 Do \"help tracepoints\" for info on other tracepoint commands."));
9236 set_cmd_completer (c
, location_completer
);
9238 add_com_alias ("tp", "trace", class_alias
, 0);
9239 add_com_alias ("tr", "trace", class_alias
, 1);
9240 add_com_alias ("tra", "trace", class_alias
, 1);
9241 add_com_alias ("trac", "trace", class_alias
, 1);
9243 add_info ("tracepoints", tracepoints_info
, _("\
9244 Status of tracepoints, or tracepoint number NUMBER.\n\
9245 Convenience variable \"$tpnum\" contains the number of the\n\
9246 last tracepoint set."));
9248 add_info_alias ("tp", "tracepoints", 1);
9250 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
9251 Delete specified tracepoints.\n\
9252 Arguments are tracepoint numbers, separated by spaces.\n\
9253 No argument means delete all tracepoints."),
9256 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
9257 Disable specified tracepoints.\n\
9258 Arguments are tracepoint numbers, separated by spaces.\n\
9259 No argument means disable all tracepoints."),
9261 deprecate_cmd (c
, "disable");
9263 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
9264 Enable specified tracepoints.\n\
9265 Arguments are tracepoint numbers, separated by spaces.\n\
9266 No argument means enable all tracepoints."),
9268 deprecate_cmd (c
, "enable");
9270 add_com ("passcount", class_trace
, trace_pass_command
, _("\
9271 Set the passcount for a tracepoint.\n\
9272 The trace will end when the tracepoint has been passed 'count' times.\n\
9273 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
9274 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
9276 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
9277 Save current tracepoint definitions as a script.\n\
9278 Use the 'source' command in another debug session to restore them."));
9279 set_cmd_completer (c
, filename_completer
);
9281 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
9282 Breakpoint specific settings\n\
9283 Configure various breakpoint-specific variables such as\n\
9284 pending breakpoint behavior"),
9285 &breakpoint_set_cmdlist
, "set breakpoint ",
9286 0/*allow-unknown*/, &setlist
);
9287 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
9288 Breakpoint specific settings\n\
9289 Configure various breakpoint-specific variables such as\n\
9290 pending breakpoint behavior"),
9291 &breakpoint_show_cmdlist
, "show breakpoint ",
9292 0/*allow-unknown*/, &showlist
);
9294 add_setshow_auto_boolean_cmd ("pending", no_class
,
9295 &pending_break_support
, _("\
9296 Set debugger's behavior regarding pending breakpoints."), _("\
9297 Show debugger's behavior regarding pending breakpoints."), _("\
9298 If on, an unrecognized breakpoint location will cause gdb to create a\n\
9299 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
9300 an error. If auto, an unrecognized breakpoint location results in a\n\
9301 user-query to see if a pending breakpoint should be created."),
9303 show_pending_break_support
,
9304 &breakpoint_set_cmdlist
,
9305 &breakpoint_show_cmdlist
);
9307 pending_break_support
= AUTO_BOOLEAN_AUTO
;
9309 add_setshow_boolean_cmd ("auto-hw", no_class
,
9310 &automatic_hardware_breakpoints
, _("\
9311 Set automatic usage of hardware breakpoints."), _("\
9312 Show automatic usage of hardware breakpoints."), _("\
9313 If set, the debugger will automatically use hardware breakpoints for\n\
9314 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
9315 a warning will be emitted for such breakpoints."),
9317 show_automatic_hardware_breakpoints
,
9318 &breakpoint_set_cmdlist
,
9319 &breakpoint_show_cmdlist
);
9321 add_setshow_enum_cmd ("always-inserted", class_support
,
9322 always_inserted_enums
, &always_inserted_mode
, _("\
9323 Set mode for inserting breakpoints."), _("\
9324 Show mode for inserting breakpoints."), _("\
9325 When this mode is off, breakpoints are inserted in inferior when it is\n\
9326 resumed, and removed when execution stops. When this mode is on,\n\
9327 breakpoints are inserted immediately and removed only when the user\n\
9328 deletes the breakpoint. When this mode is auto (which is the default),\n\
9329 the behaviour depends on the non-stop setting (see help set non-stop).\n\
9330 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
9331 behaves as if always-inserted mode is on; if gdb is controlling the\n\
9332 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
9334 &show_always_inserted_mode
,
9335 &breakpoint_set_cmdlist
,
9336 &breakpoint_show_cmdlist
);
9338 automatic_hardware_breakpoints
= 1;
9340 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);