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. */
565 /* Return the breakpoint with the specified number, or NULL
566 if the number does not refer to an existing breakpoint. */
569 get_breakpoint (int num
)
571 struct breakpoint
*b
;
574 if (b
->number
== num
)
581 /* condition N EXP -- set break condition of breakpoint N to EXP. */
584 condition_command (char *arg
, int from_tty
)
586 struct breakpoint
*b
;
591 error_no_arg (_("breakpoint number"));
594 bnum
= get_number (&p
);
596 error (_("Bad breakpoint argument: '%s'"), arg
);
599 if (b
->number
== bnum
)
601 struct bp_location
*loc
= b
->loc
;
602 for (; loc
; loc
= loc
->next
)
610 if (b
->cond_string
!= NULL
)
611 xfree (b
->cond_string
);
615 b
->cond_string
= NULL
;
617 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
622 /* I don't know if it matters whether this is the string the user
623 typed in or the decompiled expression. */
624 b
->cond_string
= xstrdup (arg
);
625 b
->condition_not_parsed
= 0;
626 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
630 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
632 error (_("Junk at end of expression"));
635 breakpoints_changed ();
636 observer_notify_breakpoint_modified (b
->number
);
640 error (_("No breakpoint number %d."), bnum
);
643 /* Set the command list of B to COMMANDS. */
646 breakpoint_set_commands (struct breakpoint
*b
, struct command_line
*commands
)
648 free_command_lines (&b
->commands
);
649 b
->commands
= commands
;
650 breakpoints_changed ();
651 observer_notify_breakpoint_modified (b
->number
);
655 commands_command (char *arg
, int from_tty
)
657 struct breakpoint
*b
;
660 struct command_line
*l
;
662 /* If we allowed this, we would have problems with when to
663 free the storage, if we change the commands currently
666 if (executing_breakpoint_commands
)
667 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
670 bnum
= get_number (&p
);
673 error (_("Unexpected extra arguments following breakpoint number."));
676 if (b
->number
== bnum
)
678 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
680 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
681 l
= read_command_lines (tmpbuf
, from_tty
, 1);
682 do_cleanups (cleanups
);
683 breakpoint_set_commands (b
, l
);
686 error (_("No breakpoint number %d."), bnum
);
689 /* Like commands_command, but instead of reading the commands from
690 input stream, takes them from an already parsed command structure.
692 This is used by cli-script.c to DTRT with breakpoint commands
693 that are part of if and while bodies. */
694 enum command_control_type
695 commands_from_control_command (char *arg
, struct command_line
*cmd
)
697 struct breakpoint
*b
;
701 /* If we allowed this, we would have problems with when to
702 free the storage, if we change the commands currently
705 if (executing_breakpoint_commands
)
706 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
708 /* An empty string for the breakpoint number means the last
709 breakpoint, but get_number expects a NULL pointer. */
714 bnum
= get_number (&p
);
717 error (_("Unexpected extra arguments following breakpoint number."));
720 if (b
->number
== bnum
)
722 free_command_lines (&b
->commands
);
723 if (cmd
->body_count
!= 1)
724 error (_("Invalid \"commands\" block structure."));
725 /* We need to copy the commands because if/while will free the
726 list after it finishes execution. */
727 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
728 breakpoints_changed ();
729 observer_notify_breakpoint_modified (b
->number
);
730 return simple_control
;
732 error (_("No breakpoint number %d."), bnum
);
735 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
736 by replacing any memory breakpoints with their shadowed contents. */
739 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
741 struct bp_location
*b
;
742 CORE_ADDR bp_addr
= 0;
748 if (b
->owner
->type
== bp_none
)
749 warning (_("reading through apparently deleted breakpoint #%d?"),
752 if (b
->loc_type
!= bp_loc_software_breakpoint
)
756 /* Addresses and length of the part of the breakpoint that
758 bp_addr
= b
->target_info
.placed_address
;
759 bp_size
= b
->target_info
.shadow_len
;
761 /* bp isn't valid, or doesn't shadow memory. */
764 if (bp_addr
+ bp_size
<= memaddr
)
765 /* The breakpoint is entirely before the chunk of memory we
769 if (bp_addr
>= memaddr
+ len
)
770 /* The breakpoint is entirely after the chunk of memory we are
774 /* Offset within shadow_contents. */
775 if (bp_addr
< memaddr
)
777 /* Only copy the second part of the breakpoint. */
778 bp_size
-= memaddr
- bp_addr
;
779 bptoffset
= memaddr
- bp_addr
;
783 if (bp_addr
+ bp_size
> memaddr
+ len
)
785 /* Only copy the first part of the breakpoint. */
786 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
789 memcpy (buf
+ bp_addr
- memaddr
,
790 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
795 /* A wrapper function for inserting catchpoints. */
797 insert_catchpoint (struct ui_out
*uo
, void *args
)
799 struct breakpoint
*b
= (struct breakpoint
*) args
;
802 gdb_assert (b
->type
== bp_catchpoint
);
803 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
809 is_hardware_watchpoint (struct breakpoint
*bpt
)
811 return (bpt
->type
== bp_hardware_watchpoint
812 || bpt
->type
== bp_read_watchpoint
813 || bpt
->type
== bp_access_watchpoint
);
816 /* Find the current value of a watchpoint on EXP. Return the value in
817 *VALP and *RESULTP and the chain of intermediate and final values
818 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
821 If a memory error occurs while evaluating the expression, *RESULTP will
822 be set to NULL. *RESULTP may be a lazy value, if the result could
823 not be read from memory. It is used to determine whether a value
824 is user-specified (we should watch the whole value) or intermediate
825 (we should watch only the bit used to locate the final value).
827 If the final value, or any intermediate value, could not be read
828 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
829 set to any referenced values. *VALP will never be a lazy value.
830 This is the value which we store in struct breakpoint.
832 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
833 value chain. The caller must free the values individually. If
834 VAL_CHAIN is NULL, all generated values will be left on the value
838 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
839 struct value
**resultp
, struct value
**val_chain
)
841 struct value
*mark
, *new_mark
, *result
;
842 volatile struct gdb_exception ex
;
850 /* Evaluate the expression. */
851 mark
= value_mark ();
854 TRY_CATCH (ex
, RETURN_MASK_ALL
)
856 result
= evaluate_expression (exp
);
860 /* Ignore memory errors, we want watchpoints pointing at
861 inaccessible memory to still be created; otherwise, throw the
862 error to some higher catcher. */
868 throw_exception (ex
);
873 new_mark
= value_mark ();
874 if (mark
== new_mark
)
879 /* Make sure it's not lazy, so that after the target stops again we
880 have a non-lazy previous value to compare with. */
882 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
887 /* Return the chain of intermediate values. We use this to
888 decide which addresses to watch. */
889 *val_chain
= new_mark
;
890 value_release_to_mark (mark
);
894 /* Assuming that B is a watchpoint:
895 - Reparse watchpoint expression, if REPARSE is non-zero
896 - Evaluate expression and store the result in B->val
897 - Evaluate the condition if there is one, and store the result
899 - Update the list of values that must be watched in B->loc.
901 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
902 If this is local watchpoint that is out of scope, delete it. */
904 update_watchpoint (struct breakpoint
*b
, int reparse
)
906 int within_current_scope
;
907 struct frame_id saved_frame_id
;
908 struct bp_location
*loc
;
911 /* We don't free locations. They are stored in bp_location_chain and
912 update_global_locations will eventually delete them and remove
913 breakpoints if needed. */
916 if (b
->disposition
== disp_del_at_next_stop
)
919 /* Save the current frame's ID so we can restore it after
920 evaluating the watchpoint expression on its own frame. */
921 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
922 took a frame parameter, so that we didn't have to change the
924 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
926 /* Determine if the watchpoint is within scope. */
927 if (b
->exp_valid_block
== NULL
)
928 within_current_scope
= 1;
931 struct frame_info
*fi
;
932 fi
= frame_find_by_id (b
->watchpoint_frame
);
933 within_current_scope
= (fi
!= NULL
);
934 if (within_current_scope
)
938 if (within_current_scope
&& reparse
)
947 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
948 /* If the meaning of expression itself changed, the old value is
949 no longer relevant. We don't want to report a watchpoint hit
950 to the user when the old value and the new value may actually
951 be completely different objects. */
957 /* If we failed to parse the expression, for example because
958 it refers to a global variable in a not-yet-loaded shared library,
959 don't try to insert watchpoint. We don't automatically delete
960 such watchpoint, though, since failure to parse expression
961 is different from out-of-scope watchpoint. */
962 if (within_current_scope
&& b
->exp
)
964 struct value
*val_chain
, *v
, *result
, *next
;
966 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
968 /* Avoid setting b->val if it's already set. The meaning of
969 b->val is 'the last value' user saw, and we should update
970 it only if we reported that last value to user. As it
971 happens, the code that reports it updates b->val directly. */
978 /* Change the type of breakpoint between hardware assisted or an
979 ordinary watchpoint depending on the hardware support and free
980 hardware slots. REPARSE is set when the inferior is started. */
981 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
984 int i
, mem_cnt
, other_type_used
;
986 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
988 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
991 b
->type
= bp_watchpoint
;
994 int target_resources_ok
= target_can_use_hardware_watchpoint
995 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
996 if (target_resources_ok
<= 0)
997 b
->type
= bp_watchpoint
;
999 b
->type
= bp_hardware_watchpoint
;
1003 /* Look at each value on the value chain. */
1004 for (v
= val_chain
; v
; v
= next
)
1006 /* If it's a memory location, and GDB actually needed
1007 its contents to evaluate the expression, then we
1008 must watch it. If the first value returned is
1009 still lazy, that means an error occurred reading it;
1010 watch it anyway in case it becomes readable. */
1011 if (VALUE_LVAL (v
) == lval_memory
1012 && (v
== val_chain
|| ! value_lazy (v
)))
1014 struct type
*vtype
= check_typedef (value_type (v
));
1016 /* We only watch structs and arrays if user asked
1017 for it explicitly, never if they just happen to
1018 appear in the middle of some value chain. */
1020 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1021 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1025 struct bp_location
*loc
, **tmp
;
1027 addr
= value_address (v
);
1028 len
= TYPE_LENGTH (value_type (v
));
1030 if (b
->type
== bp_read_watchpoint
)
1032 else if (b
->type
== bp_access_watchpoint
)
1035 loc
= allocate_bp_location (b
);
1036 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1039 loc
->gdbarch
= get_type_arch (value_type (v
));
1040 loc
->address
= addr
;
1042 loc
->watchpoint_type
= type
;
1046 next
= value_next (v
);
1051 /* We just regenerated the list of breakpoint locations.
1052 The new location does not have its condition field set to anything
1053 and therefore, we must always reparse the cond_string, independently
1054 of the value of the reparse flag. */
1055 if (b
->cond_string
!= NULL
)
1057 char *s
= b
->cond_string
;
1058 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1061 else if (!within_current_scope
)
1063 printf_filtered (_("\
1064 Watchpoint %d deleted because the program has left the block \n\
1065 in which its expression is valid.\n"),
1067 if (b
->related_breakpoint
)
1068 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1069 b
->disposition
= disp_del_at_next_stop
;
1072 /* Restore the selected frame. */
1073 select_frame (frame_find_by_id (saved_frame_id
));
1077 /* Returns 1 iff breakpoint location should be
1078 inserted in the inferior. */
1080 should_be_inserted (struct bp_location
*bpt
)
1082 if (!breakpoint_enabled (bpt
->owner
))
1085 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1088 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1091 /* Tracepoints are inserted by the target at a time of its choosing,
1093 if (bpt
->owner
->type
== bp_tracepoint
)
1099 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1100 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1101 and HW_BREAKPOINT_ERROR are used to report problems.
1103 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1104 method for each breakpoint or catchpoint type. */
1106 insert_bp_location (struct bp_location
*bpt
,
1107 struct ui_file
*tmp_error_stream
,
1108 int *disabled_breaks
,
1109 int *hw_breakpoint_error
)
1113 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1116 /* Initialize the target-specific information. */
1117 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1118 bpt
->target_info
.placed_address
= bpt
->address
;
1120 if (bpt
->loc_type
== bp_loc_software_breakpoint
1121 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1123 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1125 /* If the explicitly specified breakpoint type
1126 is not hardware breakpoint, check the memory map to see
1127 if the breakpoint address is in read only memory or not.
1128 Two important cases are:
1129 - location type is not hardware breakpoint, memory
1130 is readonly. We change the type of the location to
1131 hardware breakpoint.
1132 - location type is hardware breakpoint, memory is read-write.
1133 This means we've previously made the location hardware one, but
1134 then the memory map changed, so we undo.
1136 When breakpoints are removed, remove_breakpoints will
1137 use location types we've just set here, the only possible
1138 problem is that memory map has changed during running program,
1139 but it's not going to work anyway with current gdb. */
1140 struct mem_region
*mr
1141 = lookup_mem_region (bpt
->target_info
.placed_address
);
1145 if (automatic_hardware_breakpoints
)
1148 enum bp_loc_type new_type
;
1150 if (mr
->attrib
.mode
!= MEM_RW
)
1151 new_type
= bp_loc_hardware_breakpoint
;
1153 new_type
= bp_loc_software_breakpoint
;
1155 if (new_type
!= bpt
->loc_type
)
1157 static int said
= 0;
1158 bpt
->loc_type
= new_type
;
1161 fprintf_filtered (gdb_stdout
, _("\
1162 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1167 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1168 && mr
->attrib
.mode
!= MEM_RW
)
1169 warning (_("cannot set software breakpoint at readonly address %s"),
1170 paddress (bpt
->gdbarch
, bpt
->address
));
1174 /* First check to see if we have to handle an overlay. */
1175 if (overlay_debugging
== ovly_off
1176 || bpt
->section
== NULL
1177 || !(section_is_overlay (bpt
->section
)))
1179 /* No overlay handling: just set the breakpoint. */
1181 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1182 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1185 val
= target_insert_breakpoint (bpt
->gdbarch
,
1190 /* This breakpoint is in an overlay section.
1191 Shall we set a breakpoint at the LMA? */
1192 if (!overlay_events_enabled
)
1194 /* Yes -- overlay event support is not active,
1195 so we must try to set a breakpoint at the LMA.
1196 This will not work for a hardware breakpoint. */
1197 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1198 warning (_("hardware breakpoint %d not supported in overlay!"),
1199 bpt
->owner
->number
);
1202 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1204 /* Set a software (trap) breakpoint at the LMA. */
1205 bpt
->overlay_target_info
= bpt
->target_info
;
1206 bpt
->overlay_target_info
.placed_address
= addr
;
1207 val
= target_insert_breakpoint (bpt
->gdbarch
,
1208 &bpt
->overlay_target_info
);
1210 fprintf_unfiltered (tmp_error_stream
,
1211 "Overlay breakpoint %d failed: in ROM?\n",
1212 bpt
->owner
->number
);
1215 /* Shall we set a breakpoint at the VMA? */
1216 if (section_is_mapped (bpt
->section
))
1218 /* Yes. This overlay section is mapped into memory. */
1219 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1220 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1223 val
= target_insert_breakpoint (bpt
->gdbarch
,
1228 /* No. This breakpoint will not be inserted.
1229 No error, but do not mark the bp as 'inserted'. */
1236 /* Can't set the breakpoint. */
1237 if (solib_name_from_address (bpt
->address
))
1239 /* See also: disable_breakpoints_in_shlibs. */
1241 bpt
->shlib_disabled
= 1;
1242 if (!*disabled_breaks
)
1244 fprintf_unfiltered (tmp_error_stream
,
1245 "Cannot insert breakpoint %d.\n",
1246 bpt
->owner
->number
);
1247 fprintf_unfiltered (tmp_error_stream
,
1248 "Temporarily disabling shared library breakpoints:\n");
1250 *disabled_breaks
= 1;
1251 fprintf_unfiltered (tmp_error_stream
,
1252 "breakpoint #%d\n", bpt
->owner
->number
);
1256 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1258 *hw_breakpoint_error
= 1;
1259 fprintf_unfiltered (tmp_error_stream
,
1260 "Cannot insert hardware breakpoint %d.\n",
1261 bpt
->owner
->number
);
1265 fprintf_unfiltered (tmp_error_stream
,
1266 "Cannot insert breakpoint %d.\n",
1267 bpt
->owner
->number
);
1268 fprintf_filtered (tmp_error_stream
,
1269 "Error accessing memory address ");
1270 fputs_filtered (paddress (bpt
->gdbarch
, bpt
->address
),
1272 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1273 safe_strerror (val
));
1284 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1285 /* NOTE drow/2003-09-08: This state only exists for removing
1286 watchpoints. It's not clear that it's necessary... */
1287 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1289 val
= target_insert_watchpoint (bpt
->address
,
1291 bpt
->watchpoint_type
);
1292 bpt
->inserted
= (val
!= -1);
1295 else if (bpt
->owner
->type
== bp_catchpoint
)
1297 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1298 bpt
->owner
, RETURN_MASK_ERROR
);
1299 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1300 bpt
->owner
->number
);
1302 bpt
->owner
->enable_state
= bp_disabled
;
1306 /* We've already printed an error message if there was a problem
1307 inserting this catchpoint, and we've disabled the catchpoint,
1308 so just return success. */
1315 /* Make sure all breakpoints are inserted in inferior.
1316 Throws exception on any error.
1317 A breakpoint that is already inserted won't be inserted
1318 again, so calling this function twice is safe. */
1320 insert_breakpoints (void)
1322 struct breakpoint
*bpt
;
1324 ALL_BREAKPOINTS (bpt
)
1325 if (is_hardware_watchpoint (bpt
))
1326 update_watchpoint (bpt
, 0 /* don't reparse. */);
1328 update_global_location_list (1);
1330 /* update_global_location_list does not insert breakpoints when
1331 always_inserted_mode is not enabled. Explicitly insert them
1333 if (!breakpoints_always_inserted_mode ())
1334 insert_breakpoint_locations ();
1337 /* insert_breakpoints is used when starting or continuing the program.
1338 remove_breakpoints is used when the program stops.
1339 Both return zero if successful,
1340 or an `errno' value if could not write the inferior. */
1343 insert_breakpoint_locations (void)
1345 struct breakpoint
*bpt
;
1346 struct bp_location
*b
, *temp
;
1349 int disabled_breaks
= 0;
1350 int hw_breakpoint_error
= 0;
1352 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1353 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1355 /* Explicitly mark the warning -- this will only be printed if
1356 there was an error. */
1357 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1359 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1361 if (!should_be_inserted (b
) || b
->inserted
)
1364 /* There is no point inserting thread-specific breakpoints if the
1365 thread no longer exists. */
1366 if (b
->owner
->thread
!= -1
1367 && !valid_thread_id (b
->owner
->thread
))
1370 val
= insert_bp_location (b
, tmp_error_stream
,
1372 &hw_breakpoint_error
);
1377 /* If we failed to insert all locations of a watchpoint,
1378 remove them, as half-inserted watchpoint is of limited use. */
1379 ALL_BREAKPOINTS (bpt
)
1381 int some_failed
= 0;
1382 struct bp_location
*loc
;
1384 if (!is_hardware_watchpoint (bpt
))
1387 if (!breakpoint_enabled (bpt
))
1390 if (bpt
->disposition
== disp_del_at_next_stop
)
1393 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1401 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1403 remove_breakpoint (loc
, mark_uninserted
);
1405 hw_breakpoint_error
= 1;
1406 fprintf_unfiltered (tmp_error_stream
,
1407 "Could not insert hardware watchpoint %d.\n",
1415 /* If a hardware breakpoint or watchpoint was inserted, add a
1416 message about possibly exhausted resources. */
1417 if (hw_breakpoint_error
)
1419 fprintf_unfiltered (tmp_error_stream
,
1420 "Could not insert hardware breakpoints:\n\
1421 You may have requested too many hardware breakpoints/watchpoints.\n");
1423 target_terminal_ours_for_output ();
1424 error_stream (tmp_error_stream
);
1427 do_cleanups (cleanups
);
1431 remove_breakpoints (void)
1433 struct bp_location
*b
;
1436 ALL_BP_LOCATIONS (b
)
1439 val
|= remove_breakpoint (b
, mark_uninserted
);
1445 remove_hw_watchpoints (void)
1447 struct bp_location
*b
;
1450 ALL_BP_LOCATIONS (b
)
1452 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1453 val
|= remove_breakpoint (b
, mark_uninserted
);
1459 reattach_breakpoints (int pid
)
1461 struct bp_location
*b
;
1463 struct cleanup
*old_chain
= save_inferior_ptid ();
1464 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1465 int dummy1
= 0, dummy2
= 0;
1467 make_cleanup_ui_file_delete (tmp_error_stream
);
1469 inferior_ptid
= pid_to_ptid (pid
);
1470 ALL_BP_LOCATIONS (b
)
1475 val
= insert_bp_location (b
, tmp_error_stream
,
1479 do_cleanups (old_chain
);
1484 do_cleanups (old_chain
);
1488 static int internal_breakpoint_number
= -1;
1490 static struct breakpoint
*
1491 create_internal_breakpoint (struct gdbarch
*gdbarch
,
1492 CORE_ADDR address
, enum bptype type
)
1494 struct symtab_and_line sal
;
1495 struct breakpoint
*b
;
1497 init_sal (&sal
); /* initialize to zeroes */
1500 sal
.section
= find_pc_overlay (sal
.pc
);
1502 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
1503 b
->number
= internal_breakpoint_number
--;
1504 b
->disposition
= disp_donttouch
;
1510 create_overlay_event_breakpoint (char *func_name
)
1512 struct objfile
*objfile
;
1514 ALL_OBJFILES (objfile
)
1516 struct breakpoint
*b
;
1517 struct minimal_symbol
*m
;
1519 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1523 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1524 SYMBOL_VALUE_ADDRESS (m
),
1526 b
->addr_string
= xstrdup (func_name
);
1528 if (overlay_debugging
== ovly_auto
)
1530 b
->enable_state
= bp_enabled
;
1531 overlay_events_enabled
= 1;
1535 b
->enable_state
= bp_disabled
;
1536 overlay_events_enabled
= 0;
1539 update_global_location_list (1);
1543 create_longjmp_master_breakpoint (char *func_name
)
1545 struct objfile
*objfile
;
1547 ALL_OBJFILES (objfile
)
1549 struct breakpoint
*b
;
1550 struct minimal_symbol
*m
;
1552 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
1555 m
= lookup_minimal_symbol_text (func_name
, objfile
);
1559 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
1560 SYMBOL_VALUE_ADDRESS (m
),
1562 b
->addr_string
= xstrdup (func_name
);
1563 b
->enable_state
= bp_disabled
;
1565 update_global_location_list (1);
1569 update_breakpoints_after_exec (void)
1571 struct breakpoint
*b
;
1572 struct breakpoint
*temp
;
1573 struct bp_location
*bploc
;
1575 /* We're about to delete breakpoints from GDB's lists. If the
1576 INSERTED flag is true, GDB will try to lift the breakpoints by
1577 writing the breakpoints' "shadow contents" back into memory. The
1578 "shadow contents" are NOT valid after an exec, so GDB should not
1579 do that. Instead, the target is responsible from marking
1580 breakpoints out as soon as it detects an exec. We don't do that
1581 here instead, because there may be other attempts to delete
1582 breakpoints after detecting an exec and before reaching here. */
1583 ALL_BP_LOCATIONS (bploc
)
1584 gdb_assert (!bploc
->inserted
);
1586 ALL_BREAKPOINTS_SAFE (b
, temp
)
1588 /* Solib breakpoints must be explicitly reset after an exec(). */
1589 if (b
->type
== bp_shlib_event
)
1591 delete_breakpoint (b
);
1595 /* Thread event breakpoints must be set anew after an exec(),
1596 as must overlay event and longjmp master breakpoints. */
1597 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
1598 || b
->type
== bp_longjmp_master
)
1600 delete_breakpoint (b
);
1604 /* Step-resume breakpoints are meaningless after an exec(). */
1605 if (b
->type
== bp_step_resume
)
1607 delete_breakpoint (b
);
1611 /* Longjmp and longjmp-resume breakpoints are also meaningless
1613 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1615 delete_breakpoint (b
);
1619 if (b
->type
== bp_catchpoint
)
1621 /* For now, none of the bp_catchpoint breakpoints need to
1622 do anything at this point. In the future, if some of
1623 the catchpoints need to something, we will need to add
1624 a new method, and call this method from here. */
1628 /* bp_finish is a special case. The only way we ought to be able
1629 to see one of these when an exec() has happened, is if the user
1630 caught a vfork, and then said "finish". Ordinarily a finish just
1631 carries them to the call-site of the current callee, by setting
1632 a temporary bp there and resuming. But in this case, the finish
1633 will carry them entirely through the vfork & exec.
1635 We don't want to allow a bp_finish to remain inserted now. But
1636 we can't safely delete it, 'cause finish_command has a handle to
1637 the bp on a bpstat, and will later want to delete it. There's a
1638 chance (and I've seen it happen) that if we delete the bp_finish
1639 here, that its storage will get reused by the time finish_command
1640 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1641 We really must allow finish_command to delete a bp_finish.
1643 In the absense of a general solution for the "how do we know
1644 it's safe to delete something others may have handles to?"
1645 problem, what we'll do here is just uninsert the bp_finish, and
1646 let finish_command delete it.
1648 (We know the bp_finish is "doomed" in the sense that it's
1649 momentary, and will be deleted as soon as finish_command sees
1650 the inferior stopped. So it doesn't matter that the bp's
1651 address is probably bogus in the new a.out, unlike e.g., the
1652 solib breakpoints.) */
1654 if (b
->type
== bp_finish
)
1659 /* Without a symbolic address, we have little hope of the
1660 pre-exec() address meaning the same thing in the post-exec()
1662 if (b
->addr_string
== NULL
)
1664 delete_breakpoint (b
);
1668 /* FIXME what about longjmp breakpoints? Re-create them here? */
1669 create_overlay_event_breakpoint ("_ovly_debug_event");
1670 create_longjmp_master_breakpoint ("longjmp");
1671 create_longjmp_master_breakpoint ("_longjmp");
1672 create_longjmp_master_breakpoint ("siglongjmp");
1673 create_longjmp_master_breakpoint ("_siglongjmp");
1677 detach_breakpoints (int pid
)
1679 struct bp_location
*b
;
1681 struct cleanup
*old_chain
= save_inferior_ptid ();
1683 if (pid
== PIDGET (inferior_ptid
))
1684 error (_("Cannot detach breakpoints of inferior_ptid"));
1686 /* Set inferior_ptid; remove_breakpoint uses this global. */
1687 inferior_ptid
= pid_to_ptid (pid
);
1688 ALL_BP_LOCATIONS (b
)
1691 val
|= remove_breakpoint (b
, mark_inserted
);
1693 do_cleanups (old_chain
);
1698 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1702 if (b
->owner
->enable_state
== bp_permanent
)
1703 /* Permanent breakpoints cannot be inserted or removed. */
1706 /* The type of none suggests that owner is actually deleted.
1707 This should not ever happen. */
1708 gdb_assert (b
->owner
->type
!= bp_none
);
1710 if (b
->loc_type
== bp_loc_software_breakpoint
1711 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1713 /* "Normal" instruction breakpoint: either the standard
1714 trap-instruction bp (bp_breakpoint), or a
1715 bp_hardware_breakpoint. */
1717 /* First check to see if we have to handle an overlay. */
1718 if (overlay_debugging
== ovly_off
1719 || b
->section
== NULL
1720 || !(section_is_overlay (b
->section
)))
1722 /* No overlay handling: just remove the breakpoint. */
1724 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1725 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
1727 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
1731 /* This breakpoint is in an overlay section.
1732 Did we set a breakpoint at the LMA? */
1733 if (!overlay_events_enabled
)
1735 /* Yes -- overlay event support is not active, so we
1736 should have set a breakpoint at the LMA. Remove it.
1738 /* Ignore any failures: if the LMA is in ROM, we will
1739 have already warned when we failed to insert it. */
1740 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1741 target_remove_hw_breakpoint (b
->gdbarch
,
1742 &b
->overlay_target_info
);
1744 target_remove_breakpoint (b
->gdbarch
,
1745 &b
->overlay_target_info
);
1747 /* Did we set a breakpoint at the VMA?
1748 If so, we will have marked the breakpoint 'inserted'. */
1751 /* Yes -- remove it. Previously we did not bother to
1752 remove the breakpoint if the section had been
1753 unmapped, but let's not rely on that being safe. We
1754 don't know what the overlay manager might do. */
1755 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1756 val
= target_remove_hw_breakpoint (b
->gdbarch
,
1759 /* However, we should remove *software* breakpoints only
1760 if the section is still mapped, or else we overwrite
1761 wrong code with the saved shadow contents. */
1762 else if (section_is_mapped (b
->section
))
1763 val
= target_remove_breakpoint (b
->gdbarch
,
1770 /* No -- not inserted, so no need to remove. No error. */
1775 /* In some cases, we might not be able to remove a breakpoint
1776 in a shared library that has already been removed, but we
1777 have not yet processed the shlib unload event. */
1778 if (val
&& solib_name_from_address (b
->address
))
1783 b
->inserted
= (is
== mark_inserted
);
1785 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1790 b
->inserted
= (is
== mark_inserted
);
1791 val
= target_remove_watchpoint (b
->address
, b
->length
,
1792 b
->watchpoint_type
);
1794 /* Failure to remove any of the hardware watchpoints comes here. */
1795 if ((is
== mark_uninserted
) && (b
->inserted
))
1796 warning (_("Could not remove hardware watchpoint %d."),
1799 else if (b
->owner
->type
== bp_catchpoint
1800 && breakpoint_enabled (b
->owner
)
1803 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
1805 val
= b
->owner
->ops
->remove (b
->owner
);
1808 b
->inserted
= (is
== mark_inserted
);
1814 /* Clear the "inserted" flag in all breakpoints. */
1817 mark_breakpoints_out (void)
1819 struct bp_location
*bpt
;
1821 ALL_BP_LOCATIONS (bpt
)
1825 /* Clear the "inserted" flag in all breakpoints and delete any
1826 breakpoints which should go away between runs of the program.
1828 Plus other such housekeeping that has to be done for breakpoints
1831 Note: this function gets called at the end of a run (by
1832 generic_mourn_inferior) and when a run begins (by
1833 init_wait_for_inferior). */
1838 breakpoint_init_inferior (enum inf_context context
)
1840 struct breakpoint
*b
, *temp
;
1841 struct bp_location
*bpt
;
1844 /* If breakpoint locations are shared across processes, then there's
1846 if (gdbarch_has_global_breakpoints (target_gdbarch
))
1849 ALL_BP_LOCATIONS (bpt
)
1850 if (bpt
->owner
->enable_state
!= bp_permanent
)
1853 ALL_BREAKPOINTS_SAFE (b
, temp
)
1858 case bp_watchpoint_scope
:
1860 /* If the call dummy breakpoint is at the entry point it will
1861 cause problems when the inferior is rerun, so we better
1864 Also get rid of scope breakpoints. */
1865 delete_breakpoint (b
);
1869 case bp_hardware_watchpoint
:
1870 case bp_read_watchpoint
:
1871 case bp_access_watchpoint
:
1873 /* Likewise for watchpoints on local expressions. */
1874 if (b
->exp_valid_block
!= NULL
)
1875 delete_breakpoint (b
);
1876 else if (context
== inf_starting
)
1878 /* Reset val field to force reread of starting value
1879 in insert_breakpoints. */
1881 value_free (b
->val
);
1891 /* Get rid of the moribund locations. */
1892 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
1893 free_bp_location (bpt
);
1894 VEC_free (bp_location_p
, moribund_locations
);
1897 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1898 exists at PC. It returns ordinary_breakpoint_here if it's an
1899 ordinary breakpoint, or permanent_breakpoint_here if it's a
1900 permanent breakpoint.
1901 - When continuing from a location with an ordinary breakpoint, we
1902 actually single step once before calling insert_breakpoints.
1903 - When continuing from a localion with a permanent breakpoint, we
1904 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1905 the target, to advance the PC past the breakpoint. */
1907 enum breakpoint_here
1908 breakpoint_here_p (CORE_ADDR pc
)
1910 const struct bp_location
*bpt
;
1911 int any_breakpoint_here
= 0;
1913 ALL_BP_LOCATIONS (bpt
)
1915 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1916 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1919 if ((breakpoint_enabled (bpt
->owner
)
1920 || bpt
->owner
->enable_state
== bp_permanent
)
1921 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1923 if (overlay_debugging
1924 && section_is_overlay (bpt
->section
)
1925 && !section_is_mapped (bpt
->section
))
1926 continue; /* unmapped overlay -- can't be a match */
1927 else if (bpt
->owner
->enable_state
== bp_permanent
)
1928 return permanent_breakpoint_here
;
1930 any_breakpoint_here
= 1;
1934 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1937 /* Return true if there's a moribund breakpoint at PC. */
1940 moribund_breakpoint_here_p (CORE_ADDR pc
)
1942 struct bp_location
*loc
;
1945 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
1946 if (loc
->address
== pc
)
1952 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1953 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1954 This does not check for single-step breakpoints, which are
1955 inserted and removed using direct target manipulation. */
1958 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1960 const struct bp_location
*bpt
;
1962 ALL_BP_LOCATIONS (bpt
)
1964 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1965 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1969 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1971 if (overlay_debugging
1972 && section_is_overlay (bpt
->section
)
1973 && !section_is_mapped (bpt
->section
))
1974 continue; /* unmapped overlay -- can't be a match */
1982 /* Returns non-zero iff there's either regular breakpoint
1983 or a single step breakpoint inserted at PC. */
1986 breakpoint_inserted_here_p (CORE_ADDR pc
)
1988 if (regular_breakpoint_inserted_here_p (pc
))
1991 if (single_step_breakpoint_inserted_here_p (pc
))
1997 /* This function returns non-zero iff there is a software breakpoint
2001 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
2003 const struct bp_location
*bpt
;
2004 int any_breakpoint_here
= 0;
2006 ALL_BP_LOCATIONS (bpt
)
2008 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2012 && bpt
->address
== pc
) /* bp is enabled and matches pc */
2014 if (overlay_debugging
2015 && section_is_overlay (bpt
->section
)
2016 && !section_is_mapped (bpt
->section
))
2017 continue; /* unmapped overlay -- can't be a match */
2023 /* Also check for software single-step breakpoints. */
2024 if (single_step_breakpoint_inserted_here_p (pc
))
2030 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2031 PC is valid for process/thread PTID. */
2034 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
2036 const struct bp_location
*bpt
;
2037 /* The thread and task IDs associated to PTID, computed lazily. */
2041 ALL_BP_LOCATIONS (bpt
)
2043 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2044 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2047 if (!breakpoint_enabled (bpt
->owner
)
2048 && bpt
->owner
->enable_state
!= bp_permanent
)
2051 if (bpt
->address
!= pc
)
2054 if (bpt
->owner
->thread
!= -1)
2056 /* This is a thread-specific breakpoint. Check that ptid
2057 matches that thread. If thread hasn't been computed yet,
2058 it is now time to do so. */
2060 thread
= pid_to_thread_id (ptid
);
2061 if (bpt
->owner
->thread
!= thread
)
2065 if (bpt
->owner
->task
!= 0)
2067 /* This is a task-specific breakpoint. Check that ptid
2068 matches that task. If task hasn't been computed yet,
2069 it is now time to do so. */
2071 task
= ada_get_task_number (ptid
);
2072 if (bpt
->owner
->task
!= task
)
2076 if (overlay_debugging
2077 && section_is_overlay (bpt
->section
)
2078 && !section_is_mapped (bpt
->section
))
2079 continue; /* unmapped overlay -- can't be a match */
2088 /* bpstat stuff. External routines' interfaces are documented
2092 ep_is_catchpoint (struct breakpoint
*ep
)
2094 return (ep
->type
== bp_catchpoint
);
2098 bpstat_free (bpstat bs
)
2100 if (bs
->old_val
!= NULL
)
2101 value_free (bs
->old_val
);
2102 free_command_lines (&bs
->commands
);
2106 /* Clear a bpstat so that it says we are not at any breakpoint.
2107 Also free any storage that is part of a bpstat. */
2110 bpstat_clear (bpstat
*bsp
)
2127 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2128 is part of the bpstat is copied as well. */
2131 bpstat_copy (bpstat bs
)
2135 bpstat retval
= NULL
;
2140 for (; bs
!= NULL
; bs
= bs
->next
)
2142 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2143 memcpy (tmp
, bs
, sizeof (*tmp
));
2144 if (bs
->commands
!= NULL
)
2145 tmp
->commands
= copy_command_lines (bs
->commands
);
2146 if (bs
->old_val
!= NULL
)
2148 tmp
->old_val
= value_copy (bs
->old_val
);
2149 release_value (tmp
->old_val
);
2153 /* This is the first thing in the chain. */
2163 /* Find the bpstat associated with this breakpoint */
2166 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2171 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2173 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2179 /* Find a step_resume breakpoint associated with this bpstat.
2180 (If there are multiple step_resume bp's on the list, this function
2181 will arbitrarily pick one.)
2183 It is an error to use this function if BPSTAT doesn't contain a
2184 step_resume breakpoint.
2186 See wait_for_inferior's use of this function. */
2188 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2192 gdb_assert (bsp
!= NULL
);
2194 current_thread
= pid_to_thread_id (inferior_ptid
);
2196 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2198 if ((bsp
->breakpoint_at
!= NULL
)
2199 && (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
)
2200 && (bsp
->breakpoint_at
->owner
->thread
== current_thread
2201 || bsp
->breakpoint_at
->owner
->thread
== -1))
2202 return bsp
->breakpoint_at
->owner
;
2205 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2209 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2210 at. *BSP upon return is a bpstat which points to the remaining
2211 breakpoints stopped at (but which is not guaranteed to be good for
2212 anything but further calls to bpstat_num).
2213 Return 0 if passed a bpstat which does not indicate any breakpoints.
2214 Return -1 if stopped at a breakpoint that has been deleted since
2216 Return 1 otherwise. */
2219 bpstat_num (bpstat
*bsp
, int *num
)
2221 struct breakpoint
*b
;
2224 return 0; /* No more breakpoint values */
2226 /* We assume we'll never have several bpstats that
2227 correspond to a single breakpoint -- otherwise,
2228 this function might return the same number more
2229 than once and this will look ugly. */
2230 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2231 *bsp
= (*bsp
)->next
;
2233 return -1; /* breakpoint that's been deleted since */
2235 *num
= b
->number
; /* We have its number */
2239 /* Modify BS so that the actions will not be performed. */
2242 bpstat_clear_actions (bpstat bs
)
2244 for (; bs
!= NULL
; bs
= bs
->next
)
2246 free_command_lines (&bs
->commands
);
2247 if (bs
->old_val
!= NULL
)
2249 value_free (bs
->old_val
);
2255 /* Called when a command is about to proceed the inferior. */
2258 breakpoint_about_to_proceed (void)
2260 if (!ptid_equal (inferior_ptid
, null_ptid
))
2262 struct thread_info
*tp
= inferior_thread ();
2264 /* Allow inferior function calls in breakpoint commands to not
2265 interrupt the command list. When the call finishes
2266 successfully, the inferior will be standing at the same
2267 breakpoint as if nothing happened. */
2272 breakpoint_proceeded
= 1;
2275 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2277 cleanup_executing_breakpoints (void *ignore
)
2279 executing_breakpoint_commands
= 0;
2282 /* Execute all the commands associated with all the breakpoints at this
2283 location. Any of these commands could cause the process to proceed
2284 beyond this point, etc. We look out for such changes by checking
2285 the global "breakpoint_proceeded" after each command.
2287 Returns true if a breakpoint command resumed the inferior. In that
2288 case, it is the caller's responsibility to recall it again with the
2289 bpstat of the current thread. */
2292 bpstat_do_actions_1 (bpstat
*bsp
)
2295 struct cleanup
*old_chain
;
2298 /* Avoid endless recursion if a `source' command is contained
2300 if (executing_breakpoint_commands
)
2303 executing_breakpoint_commands
= 1;
2304 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2306 /* This pointer will iterate over the list of bpstat's. */
2309 breakpoint_proceeded
= 0;
2310 for (; bs
!= NULL
; bs
= bs
->next
)
2312 struct command_line
*cmd
;
2313 struct cleanup
*this_cmd_tree_chain
;
2315 /* Take ownership of the BSP's command tree, if it has one.
2317 The command tree could legitimately contain commands like
2318 'step' and 'next', which call clear_proceed_status, which
2319 frees stop_bpstat's command tree. To make sure this doesn't
2320 free the tree we're executing out from under us, we need to
2321 take ownership of the tree ourselves. Since a given bpstat's
2322 commands are only executed once, we don't need to copy it; we
2323 can clear the pointer in the bpstat, and make sure we free
2324 the tree when we're done. */
2327 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2331 execute_control_command (cmd
);
2333 if (breakpoint_proceeded
)
2339 /* We can free this command tree now. */
2340 do_cleanups (this_cmd_tree_chain
);
2342 if (breakpoint_proceeded
)
2344 if (target_can_async_p ())
2345 /* If we are in async mode, then the target might be still
2346 running, not stopped at any breakpoint, so nothing for
2347 us to do here -- just return to the event loop. */
2350 /* In sync mode, when execute_control_command returns
2351 we're already standing on the next breakpoint.
2352 Breakpoint commands for that stop were not run, since
2353 execute_command does not run breakpoint commands --
2354 only command_line_handler does, but that one is not
2355 involved in execution of breakpoint commands. So, we
2356 can now execute breakpoint commands. It should be
2357 noted that making execute_command do bpstat actions is
2358 not an option -- in this case we'll have recursive
2359 invocation of bpstat for each breakpoint with a
2360 command, and can easily blow up GDB stack. Instead, we
2361 return true, which will trigger the caller to recall us
2362 with the new stop_bpstat. */
2367 do_cleanups (old_chain
);
2372 bpstat_do_actions (void)
2374 /* Do any commands attached to breakpoint we are stopped at. */
2375 while (!ptid_equal (inferior_ptid
, null_ptid
)
2376 && target_has_execution
2377 && !is_exited (inferior_ptid
)
2378 && !is_executing (inferior_ptid
))
2379 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2380 and only return when it is stopped at the next breakpoint, we
2381 keep doing breakpoint actions until it returns false to
2382 indicate the inferior was not resumed. */
2383 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2387 /* Print out the (old or new) value associated with a watchpoint. */
2390 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2393 fprintf_unfiltered (stream
, _("<unreadable>"));
2396 struct value_print_options opts
;
2397 get_user_print_options (&opts
);
2398 value_print (val
, stream
, &opts
);
2402 /* This is the normal print function for a bpstat. In the future,
2403 much of this logic could (should?) be moved to bpstat_stop_status,
2404 by having it set different print_it values.
2406 Current scheme: When we stop, bpstat_print() is called. It loops
2407 through the bpstat list of things causing this stop, calling the
2408 print_bp_stop_message function on each one. The behavior of the
2409 print_bp_stop_message function depends on the print_it field of
2410 bpstat. If such field so indicates, call this function here.
2412 Return values from this routine (ultimately used by bpstat_print()
2413 and normal_stop() to decide what to do):
2414 PRINT_NOTHING: Means we already printed all we needed to print,
2415 don't print anything else.
2416 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2417 that something to be followed by a location.
2418 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2419 that something to be followed by a location.
2420 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2423 static enum print_stop_action
2424 print_it_typical (bpstat bs
)
2426 struct cleanup
*old_chain
;
2427 struct breakpoint
*b
;
2428 const struct bp_location
*bl
;
2429 struct ui_stream
*stb
;
2431 enum print_stop_action result
;
2433 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2434 which has since been deleted. */
2435 if (bs
->breakpoint_at
== NULL
)
2436 return PRINT_UNKNOWN
;
2437 bl
= bs
->breakpoint_at
;
2440 stb
= ui_out_stream_new (uiout
);
2441 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2446 case bp_hardware_breakpoint
:
2447 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2448 if (bl
->address
!= bl
->requested_address
)
2449 breakpoint_adjustment_warning (bl
->requested_address
,
2452 annotate_breakpoint (b
->number
);
2454 ui_out_text (uiout
, "\nTemporary breakpoint ");
2456 ui_out_text (uiout
, "\nBreakpoint ");
2457 if (ui_out_is_mi_like_p (uiout
))
2459 ui_out_field_string (uiout
, "reason",
2460 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2461 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2463 ui_out_field_int (uiout
, "bkptno", b
->number
);
2464 ui_out_text (uiout
, ", ");
2465 result
= PRINT_SRC_AND_LOC
;
2468 case bp_shlib_event
:
2469 /* Did we stop because the user set the stop_on_solib_events
2470 variable? (If so, we report this as a generic, "Stopped due
2471 to shlib event" message.) */
2472 printf_filtered (_("Stopped due to shared library event\n"));
2473 result
= PRINT_NOTHING
;
2476 case bp_thread_event
:
2477 /* Not sure how we will get here.
2478 GDB should not stop for these breakpoints. */
2479 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2480 result
= PRINT_NOTHING
;
2483 case bp_overlay_event
:
2484 /* By analogy with the thread event, GDB should not stop for these. */
2485 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2486 result
= PRINT_NOTHING
;
2489 case bp_longjmp_master
:
2490 /* These should never be enabled. */
2491 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
2492 result
= PRINT_NOTHING
;
2496 case bp_hardware_watchpoint
:
2497 annotate_watchpoint (b
->number
);
2498 if (ui_out_is_mi_like_p (uiout
))
2501 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2503 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2504 ui_out_text (uiout
, "\nOld value = ");
2505 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2506 ui_out_field_stream (uiout
, "old", stb
);
2507 ui_out_text (uiout
, "\nNew value = ");
2508 watchpoint_value_print (b
->val
, stb
->stream
);
2509 ui_out_field_stream (uiout
, "new", stb
);
2510 ui_out_text (uiout
, "\n");
2511 /* More than one watchpoint may have been triggered. */
2512 result
= PRINT_UNKNOWN
;
2515 case bp_read_watchpoint
:
2516 if (ui_out_is_mi_like_p (uiout
))
2519 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2521 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2522 ui_out_text (uiout
, "\nValue = ");
2523 watchpoint_value_print (b
->val
, stb
->stream
);
2524 ui_out_field_stream (uiout
, "value", stb
);
2525 ui_out_text (uiout
, "\n");
2526 result
= PRINT_UNKNOWN
;
2529 case bp_access_watchpoint
:
2530 if (bs
->old_val
!= NULL
)
2532 annotate_watchpoint (b
->number
);
2533 if (ui_out_is_mi_like_p (uiout
))
2536 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2538 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2539 ui_out_text (uiout
, "\nOld value = ");
2540 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2541 ui_out_field_stream (uiout
, "old", stb
);
2542 ui_out_text (uiout
, "\nNew value = ");
2547 if (ui_out_is_mi_like_p (uiout
))
2550 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2551 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2552 ui_out_text (uiout
, "\nValue = ");
2554 watchpoint_value_print (b
->val
, stb
->stream
);
2555 ui_out_field_stream (uiout
, "new", stb
);
2556 ui_out_text (uiout
, "\n");
2557 result
= PRINT_UNKNOWN
;
2560 /* Fall through, we don't deal with these types of breakpoints
2564 if (ui_out_is_mi_like_p (uiout
))
2567 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2568 result
= PRINT_UNKNOWN
;
2572 if (ui_out_is_mi_like_p (uiout
))
2575 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2576 result
= PRINT_UNKNOWN
;
2581 case bp_longjmp_resume
:
2582 case bp_step_resume
:
2583 case bp_watchpoint_scope
:
2587 result
= PRINT_UNKNOWN
;
2591 do_cleanups (old_chain
);
2595 /* Generic routine for printing messages indicating why we
2596 stopped. The behavior of this function depends on the value
2597 'print_it' in the bpstat structure. Under some circumstances we
2598 may decide not to print anything here and delegate the task to
2601 static enum print_stop_action
2602 print_bp_stop_message (bpstat bs
)
2604 switch (bs
->print_it
)
2607 /* Nothing should be printed for this bpstat entry. */
2608 return PRINT_UNKNOWN
;
2612 /* We still want to print the frame, but we already printed the
2613 relevant messages. */
2614 return PRINT_SRC_AND_LOC
;
2617 case print_it_normal
:
2619 const struct bp_location
*bl
= bs
->breakpoint_at
;
2620 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2622 /* Normal case. Call the breakpoint's print_it method, or
2623 print_it_typical. */
2624 /* FIXME: how breakpoint can ever be NULL here? */
2625 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2626 return b
->ops
->print_it (b
);
2628 return print_it_typical (bs
);
2633 internal_error (__FILE__
, __LINE__
,
2634 _("print_bp_stop_message: unrecognized enum value"));
2639 /* Print a message indicating what happened. This is called from
2640 normal_stop(). The input to this routine is the head of the bpstat
2641 list - a list of the eventpoints that caused this stop. This
2642 routine calls the generic print routine for printing a message
2643 about reasons for stopping. This will print (for example) the
2644 "Breakpoint n," part of the output. The return value of this
2647 PRINT_UNKNOWN: Means we printed nothing
2648 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2649 code to print the location. An example is
2650 "Breakpoint 1, " which should be followed by
2652 PRINT_SRC_ONLY: Means we printed something, but there is no need
2653 to also print the location part of the message.
2654 An example is the catch/throw messages, which
2655 don't require a location appended to the end.
2656 PRINT_NOTHING: We have done some printing and we don't need any
2657 further info to be printed.*/
2659 enum print_stop_action
2660 bpstat_print (bpstat bs
)
2664 /* Maybe another breakpoint in the chain caused us to stop.
2665 (Currently all watchpoints go on the bpstat whether hit or not.
2666 That probably could (should) be changed, provided care is taken
2667 with respect to bpstat_explains_signal). */
2668 for (; bs
; bs
= bs
->next
)
2670 val
= print_bp_stop_message (bs
);
2671 if (val
== PRINT_SRC_ONLY
2672 || val
== PRINT_SRC_AND_LOC
2673 || val
== PRINT_NOTHING
)
2677 /* We reached the end of the chain, or we got a null BS to start
2678 with and nothing was printed. */
2679 return PRINT_UNKNOWN
;
2682 /* Evaluate the expression EXP and return 1 if value is zero.
2683 This is used inside a catch_errors to evaluate the breakpoint condition.
2684 The argument is a "struct expression *" that has been cast to char * to
2685 make it pass through catch_errors. */
2688 breakpoint_cond_eval (void *exp
)
2690 struct value
*mark
= value_mark ();
2691 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2692 value_free_to_mark (mark
);
2696 /* Allocate a new bpstat and chain it to the current one. */
2699 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2703 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2705 bs
->breakpoint_at
= bl
;
2706 /* If the condition is false, etc., don't do the commands. */
2707 bs
->commands
= NULL
;
2709 bs
->print_it
= print_it_normal
;
2713 /* The target has stopped with waitstatus WS. Check if any hardware
2714 watchpoints have triggered, according to the target. */
2717 watchpoints_triggered (struct target_waitstatus
*ws
)
2719 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
2721 struct breakpoint
*b
;
2723 if (!stopped_by_watchpoint
)
2725 /* We were not stopped by a watchpoint. Mark all watchpoints
2726 as not triggered. */
2728 if (b
->type
== bp_hardware_watchpoint
2729 || b
->type
== bp_read_watchpoint
2730 || b
->type
== bp_access_watchpoint
)
2731 b
->watchpoint_triggered
= watch_triggered_no
;
2736 if (!target_stopped_data_address (¤t_target
, &addr
))
2738 /* We were stopped by a watchpoint, but we don't know where.
2739 Mark all watchpoints as unknown. */
2741 if (b
->type
== bp_hardware_watchpoint
2742 || b
->type
== bp_read_watchpoint
2743 || b
->type
== bp_access_watchpoint
)
2744 b
->watchpoint_triggered
= watch_triggered_unknown
;
2746 return stopped_by_watchpoint
;
2749 /* The target could report the data address. Mark watchpoints
2750 affected by this data address as triggered, and all others as not
2754 if (b
->type
== bp_hardware_watchpoint
2755 || b
->type
== bp_read_watchpoint
2756 || b
->type
== bp_access_watchpoint
)
2758 struct bp_location
*loc
;
2761 b
->watchpoint_triggered
= watch_triggered_no
;
2762 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2763 /* Exact match not required. Within range is
2765 if (target_watchpoint_addr_within_range (¤t_target
,
2769 b
->watchpoint_triggered
= watch_triggered_yes
;
2777 /* Possible return values for watchpoint_check (this can't be an enum
2778 because of check_errors). */
2779 /* The watchpoint has been deleted. */
2780 #define WP_DELETED 1
2781 /* The value has changed. */
2782 #define WP_VALUE_CHANGED 2
2783 /* The value has not changed. */
2784 #define WP_VALUE_NOT_CHANGED 3
2786 #define BP_TEMPFLAG 1
2787 #define BP_HARDWAREFLAG 2
2789 /* Check watchpoint condition. */
2792 watchpoint_check (void *p
)
2794 bpstat bs
= (bpstat
) p
;
2795 struct breakpoint
*b
;
2796 struct frame_info
*fr
;
2797 int within_current_scope
;
2799 b
= bs
->breakpoint_at
->owner
;
2801 if (b
->exp_valid_block
== NULL
)
2802 within_current_scope
= 1;
2805 struct frame_info
*frame
= get_current_frame ();
2806 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
2807 CORE_ADDR frame_pc
= get_frame_pc (frame
);
2809 fr
= frame_find_by_id (b
->watchpoint_frame
);
2810 within_current_scope
= (fr
!= NULL
);
2812 /* If we've gotten confused in the unwinder, we might have
2813 returned a frame that can't describe this variable. */
2814 if (within_current_scope
)
2816 struct symbol
*function
;
2818 function
= get_frame_function (fr
);
2819 if (function
== NULL
2820 || !contained_in (b
->exp_valid_block
,
2821 SYMBOL_BLOCK_VALUE (function
)))
2822 within_current_scope
= 0;
2825 /* in_function_epilogue_p() returns a non-zero value if we're still
2826 in the function but the stack frame has already been invalidated.
2827 Since we can't rely on the values of local variables after the
2828 stack has been destroyed, we are treating the watchpoint in that
2829 state as `not changed' without further checking. Don't mark
2830 watchpoints as changed if the current frame is in an epilogue -
2831 even if they are in some other frame, our view of the stack
2832 is likely to be wrong. */
2833 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
2834 return WP_VALUE_NOT_CHANGED
;
2836 if (within_current_scope
)
2837 /* If we end up stopping, the current frame will get selected
2838 in normal_stop. So this call to select_frame won't affect
2843 if (within_current_scope
)
2845 /* We use value_{,free_to_}mark because it could be a
2846 *long* time before we return to the command level and
2847 call free_all_values. We can't call free_all_values because
2848 we might be in the middle of evaluating a function call. */
2850 struct value
*mark
= value_mark ();
2851 struct value
*new_val
;
2853 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2854 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2855 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2857 if (new_val
!= NULL
)
2859 release_value (new_val
);
2860 value_free_to_mark (mark
);
2862 bs
->old_val
= b
->val
;
2865 /* We will stop here */
2866 return WP_VALUE_CHANGED
;
2870 /* Nothing changed, don't do anything. */
2871 value_free_to_mark (mark
);
2872 /* We won't stop here */
2873 return WP_VALUE_NOT_CHANGED
;
2878 /* This seems like the only logical thing to do because
2879 if we temporarily ignored the watchpoint, then when
2880 we reenter the block in which it is valid it contains
2881 garbage (in the case of a function, it may have two
2882 garbage values, one before and one after the prologue).
2883 So we can't even detect the first assignment to it and
2884 watch after that (since the garbage may or may not equal
2885 the first value assigned). */
2886 /* We print all the stop information in print_it_typical(), but
2887 in this case, by the time we call print_it_typical() this bp
2888 will be deleted already. So we have no choice but print the
2889 information here. */
2890 if (ui_out_is_mi_like_p (uiout
))
2892 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2893 ui_out_text (uiout
, "\nWatchpoint ");
2894 ui_out_field_int (uiout
, "wpnum", b
->number
);
2895 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2896 which its expression is valid.\n");
2898 if (b
->related_breakpoint
)
2899 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2900 b
->disposition
= disp_del_at_next_stop
;
2906 /* Return true if it looks like target has stopped due to hitting
2907 breakpoint location BL. This function does not check if we
2908 should stop, only if BL explains the stop. */
2910 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2912 struct breakpoint
*b
= bl
->owner
;
2914 if (b
->type
!= bp_watchpoint
2915 && b
->type
!= bp_hardware_watchpoint
2916 && b
->type
!= bp_read_watchpoint
2917 && b
->type
!= bp_access_watchpoint
2918 && b
->type
!= bp_hardware_breakpoint
2919 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
2921 if (bl
->address
!= bp_addr
) /* address doesn't match */
2923 if (overlay_debugging
/* unmapped overlay section */
2924 && section_is_overlay (bl
->section
)
2925 && !section_is_mapped (bl
->section
))
2929 /* Continuable hardware watchpoints are treated as non-existent if the
2930 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2931 some data address). Otherwise gdb won't stop on a break instruction
2932 in the code (not from a breakpoint) when a hardware watchpoint has
2933 been defined. Also skip watchpoints which we know did not trigger
2934 (did not match the data address). */
2936 if ((b
->type
== bp_hardware_watchpoint
2937 || b
->type
== bp_read_watchpoint
2938 || b
->type
== bp_access_watchpoint
)
2939 && b
->watchpoint_triggered
== watch_triggered_no
)
2942 if (b
->type
== bp_hardware_breakpoint
)
2944 if (bl
->address
!= bp_addr
)
2946 if (overlay_debugging
/* unmapped overlay section */
2947 && section_is_overlay (bl
->section
)
2948 && !section_is_mapped (bl
->section
))
2952 if (b
->type
== bp_catchpoint
)
2954 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2955 if (!b
->ops
->breakpoint_hit (b
))
2962 /* If BS refers to a watchpoint, determine if the watched values
2963 has actually changed, and we should stop. If not, set BS->stop
2966 bpstat_check_watchpoint (bpstat bs
)
2968 const struct bp_location
*bl
= bs
->breakpoint_at
;
2969 struct breakpoint
*b
= bl
->owner
;
2971 if (b
->type
== bp_watchpoint
2972 || b
->type
== bp_read_watchpoint
2973 || b
->type
== bp_access_watchpoint
2974 || b
->type
== bp_hardware_watchpoint
)
2978 int must_check_value
= 0;
2980 if (b
->type
== bp_watchpoint
)
2981 /* For a software watchpoint, we must always check the
2983 must_check_value
= 1;
2984 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2985 /* We have a hardware watchpoint (read, write, or access)
2986 and the target earlier reported an address watched by
2988 must_check_value
= 1;
2989 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2990 && b
->type
== bp_hardware_watchpoint
)
2991 /* We were stopped by a hardware watchpoint, but the target could
2992 not report the data address. We must check the watchpoint's
2993 value. Access and read watchpoints are out of luck; without
2994 a data address, we can't figure it out. */
2995 must_check_value
= 1;
2997 if (must_check_value
)
2999 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3001 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3002 int e
= catch_errors (watchpoint_check
, bs
, message
,
3004 do_cleanups (cleanups
);
3008 /* We've already printed what needs to be printed. */
3009 bs
->print_it
= print_it_done
;
3012 case WP_VALUE_CHANGED
:
3013 if (b
->type
== bp_read_watchpoint
)
3015 /* Don't stop: read watchpoints shouldn't fire if
3016 the value has changed. This is for targets
3017 which cannot set read-only watchpoints. */
3018 bs
->print_it
= print_it_noop
;
3022 case WP_VALUE_NOT_CHANGED
:
3023 if (b
->type
== bp_hardware_watchpoint
3024 || b
->type
== bp_watchpoint
)
3026 /* Don't stop: write watchpoints shouldn't fire if
3027 the value hasn't changed. */
3028 bs
->print_it
= print_it_noop
;
3036 /* Error from catch_errors. */
3037 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3038 if (b
->related_breakpoint
)
3039 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3040 b
->disposition
= disp_del_at_next_stop
;
3041 /* We've already printed what needs to be printed. */
3042 bs
->print_it
= print_it_done
;
3046 else /* must_check_value == 0 */
3048 /* This is a case where some watchpoint(s) triggered, but
3049 not at the address of this watchpoint, or else no
3050 watchpoint triggered after all. So don't print
3051 anything for this watchpoint. */
3052 bs
->print_it
= print_it_noop
;
3059 /* Check conditions (condition proper, frame, thread and ignore count)
3060 of breakpoint referred to by BS. If we should not stop for this
3061 breakpoint, set BS->stop to 0. */
3063 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3065 int thread_id
= pid_to_thread_id (ptid
);
3066 const struct bp_location
*bl
= bs
->breakpoint_at
;
3067 struct breakpoint
*b
= bl
->owner
;
3069 if (frame_id_p (b
->frame_id
)
3070 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3074 int value_is_zero
= 0;
3076 /* If this is a scope breakpoint, mark the associated
3077 watchpoint as triggered so that we will handle the
3078 out-of-scope event. We'll get to the watchpoint next
3080 if (b
->type
== bp_watchpoint_scope
)
3081 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3083 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3085 /* We use value_mark and value_free_to_mark because it could
3086 be a long time before we return to the command level and
3087 call free_all_values. We can't call free_all_values
3088 because we might be in the middle of evaluating a
3090 struct value
*mark
= value_mark ();
3092 /* Need to select the frame, with all that implies so that
3093 the conditions will have the right context. Because we
3094 use the frame, we will not see an inlined function's
3095 variables when we arrive at a breakpoint at the start
3096 of the inlined function; the current frame will be the
3098 select_frame (get_current_frame ());
3100 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
3101 "Error in testing breakpoint condition:\n",
3103 /* FIXME-someday, should give breakpoint # */
3104 value_free_to_mark (mark
);
3106 if (bl
->cond
&& value_is_zero
)
3110 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3114 else if (b
->ignore_count
> 0)
3117 annotate_ignore_count_change ();
3119 /* Increase the hit count even though we don't
3127 /* Get a bpstat associated with having just stopped at address
3128 BP_ADDR in thread PTID.
3130 Determine whether we stopped at a breakpoint, etc, or whether we
3131 don't understand this stop. Result is a chain of bpstat's such that:
3133 if we don't understand the stop, the result is a null pointer.
3135 if we understand why we stopped, the result is not null.
3137 Each element of the chain refers to a particular breakpoint or
3138 watchpoint at which we have stopped. (We may have stopped for
3139 several reasons concurrently.)
3141 Each element of the chain has valid next, breakpoint_at,
3142 commands, FIXME??? fields. */
3145 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3147 struct breakpoint
*b
= NULL
;
3148 const struct bp_location
*bl
;
3149 struct bp_location
*loc
;
3150 /* Root of the chain of bpstat's */
3151 struct bpstats root_bs
[1];
3152 /* Pointer to the last thing in the chain currently. */
3153 bpstat bs
= root_bs
;
3155 int need_remove_insert
;
3157 ALL_BP_LOCATIONS (bl
)
3161 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3164 /* For hardware watchpoints, we look only at the first location.
3165 The watchpoint_check function will work on entire expression,
3166 not the individual locations. For read watchopints, the
3167 watchpoints_triggered function have checked all locations
3170 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3173 if (!bpstat_check_location (bl
, bp_addr
))
3176 /* Come here if it's a watchpoint, or if the break address matches */
3178 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3180 /* Assume we stop. Should we find watchpoint that is not actually
3181 triggered, or if condition of breakpoint is false, we'll reset
3186 bpstat_check_watchpoint (bs
);
3190 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3191 || b
->type
== bp_longjmp_master
)
3192 /* We do not stop for these. */
3195 bpstat_check_breakpoint_conditions (bs
, ptid
);
3201 /* We will stop here */
3202 if (b
->disposition
== disp_disable
)
3204 if (b
->enable_state
!= bp_permanent
)
3205 b
->enable_state
= bp_disabled
;
3206 update_global_location_list (0);
3210 bs
->commands
= b
->commands
;
3212 && (strcmp ("silent", bs
->commands
->line
) == 0
3213 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3215 bs
->commands
= bs
->commands
->next
;
3218 bs
->commands
= copy_command_lines (bs
->commands
);
3221 /* Print nothing for this entry if we dont stop or if we dont print. */
3222 if (bs
->stop
== 0 || bs
->print
== 0)
3223 bs
->print_it
= print_it_noop
;
3226 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3228 if (loc
->address
== bp_addr
)
3230 bs
= bpstat_alloc (loc
, bs
);
3231 /* For hits of moribund locations, we should just proceed. */
3234 bs
->print_it
= print_it_noop
;
3238 bs
->next
= NULL
; /* Terminate the chain */
3239 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3241 /* If we aren't stopping, the value of some hardware watchpoint may
3242 not have changed, but the intermediate memory locations we are
3243 watching may have. Don't bother if we're stopping; this will get
3245 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3249 need_remove_insert
= 0;
3251 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3253 && bs
->breakpoint_at
->owner
3254 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3255 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3256 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3258 /* remove/insert can invalidate bs->breakpoint_at, if this
3259 location is no longer used by the watchpoint. Prevent
3260 further code from trying to use it. */
3261 bs
->breakpoint_at
= NULL
;
3262 need_remove_insert
= 1;
3265 if (need_remove_insert
)
3267 remove_breakpoints ();
3268 insert_breakpoints ();
3271 return root_bs
->next
;
3274 /* Tell what to do about this bpstat. */
3276 bpstat_what (bpstat bs
)
3278 /* Classify each bpstat as one of the following. */
3281 /* This bpstat element has no effect on the main_action. */
3284 /* There was a watchpoint, stop but don't print. */
3287 /* There was a watchpoint, stop and print. */
3290 /* There was a breakpoint but we're not stopping. */
3293 /* There was a breakpoint, stop but don't print. */
3296 /* There was a breakpoint, stop and print. */
3299 /* We hit the longjmp breakpoint. */
3302 /* We hit the longjmp_resume breakpoint. */
3305 /* We hit the step_resume breakpoint. */
3308 /* We hit the shared library event breakpoint. */
3311 /* This is just used to count how many enums there are. */
3315 /* Here is the table which drives this routine. So that we can
3316 format it pretty, we define some abbreviations for the
3317 enum bpstat_what codes. */
3318 #define kc BPSTAT_WHAT_KEEP_CHECKING
3319 #define ss BPSTAT_WHAT_STOP_SILENT
3320 #define sn BPSTAT_WHAT_STOP_NOISY
3321 #define sgl BPSTAT_WHAT_SINGLE
3322 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3323 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3324 #define sr BPSTAT_WHAT_STEP_RESUME
3325 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3327 /* "Can't happen." Might want to print an error message.
3328 abort() is not out of the question, but chances are GDB is just
3329 a bit confused, not unusable. */
3330 #define err BPSTAT_WHAT_STOP_NOISY
3332 /* Given an old action and a class, come up with a new action. */
3333 /* One interesting property of this table is that wp_silent is the same
3334 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3335 after stopping, the check for whether to step over a breakpoint
3336 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3337 reference to how we stopped. We retain separate wp_silent and
3338 bp_silent codes in case we want to change that someday.
3340 Another possibly interesting property of this table is that
3341 there's a partial ordering, priority-like, of the actions. Once
3342 you've decided that some action is appropriate, you'll never go
3343 back and decide something of a lower priority is better. The
3346 kc < clr sgl shl slr sn sr ss
3347 sgl < shl slr sn sr ss
3348 slr < err shl sn sr ss
3349 clr < err shl sn sr ss
3355 What I think this means is that we don't need a damned table
3356 here. If you just put the rows and columns in the right order,
3357 it'd look awfully regular. We could simply walk the bpstat list
3358 and choose the highest priority action we find, with a little
3359 logic to handle the 'err' cases. */
3361 /* step_resume entries: a step resume breakpoint overrides another
3362 breakpoint of signal handling (see comment in wait_for_inferior
3363 at where we set the step_resume breakpoint). */
3365 static const enum bpstat_what_main_action
3366 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3369 /* kc ss sn sgl slr clr sr shl
3372 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
},
3374 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3376 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3378 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
},
3380 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
},
3382 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
},
3384 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
},
3386 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
},
3388 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3390 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
}
3403 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3404 struct bpstat_what retval
;
3406 retval
.call_dummy
= 0;
3407 for (; bs
!= NULL
; bs
= bs
->next
)
3409 enum class bs_class
= no_effect
;
3410 if (bs
->breakpoint_at
== NULL
)
3411 /* I suspect this can happen if it was a momentary breakpoint
3412 which has since been deleted. */
3414 if (bs
->breakpoint_at
->owner
== NULL
)
3415 bs_class
= bp_nostop
;
3417 switch (bs
->breakpoint_at
->owner
->type
)
3423 case bp_hardware_breakpoint
:
3429 bs_class
= bp_noisy
;
3431 bs_class
= bp_silent
;
3434 bs_class
= bp_nostop
;
3437 case bp_hardware_watchpoint
:
3438 case bp_read_watchpoint
:
3439 case bp_access_watchpoint
:
3443 bs_class
= wp_noisy
;
3445 bs_class
= wp_silent
;
3448 /* There was a watchpoint, but we're not stopping.
3449 This requires no further action. */
3450 bs_class
= no_effect
;
3453 bs_class
= long_jump
;
3455 case bp_longjmp_resume
:
3456 bs_class
= long_resume
;
3458 case bp_step_resume
:
3461 bs_class
= step_resume
;
3464 /* It is for the wrong frame. */
3465 bs_class
= bp_nostop
;
3467 case bp_watchpoint_scope
:
3468 bs_class
= bp_nostop
;
3470 case bp_shlib_event
:
3471 bs_class
= shlib_event
;
3473 case bp_thread_event
:
3474 case bp_overlay_event
:
3475 case bp_longjmp_master
:
3476 bs_class
= bp_nostop
;
3482 bs_class
= bp_noisy
;
3484 bs_class
= bp_silent
;
3487 /* There was a catchpoint, but we're not stopping.
3488 This requires no further action. */
3489 bs_class
= no_effect
;
3492 /* Make sure the action is stop (silent or noisy),
3493 so infrun.c pops the dummy frame. */
3494 bs_class
= bp_silent
;
3495 retval
.call_dummy
= 1;
3498 /* Tracepoint hits should not be reported back to GDB, and
3499 if one got through somehow, it should have been filtered
3501 internal_error (__FILE__
, __LINE__
,
3502 _("bpstat_what: bp_tracepoint encountered"));
3505 current_action
= table
[(int) bs_class
][(int) current_action
];
3507 retval
.main_action
= current_action
;
3511 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3512 without hardware support). This isn't related to a specific bpstat,
3513 just to things like whether watchpoints are set. */
3516 bpstat_should_step (void)
3518 struct breakpoint
*b
;
3520 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
3527 static void print_breakpoint_location (struct breakpoint
*b
,
3528 struct bp_location
*loc
,
3530 struct ui_stream
*stb
)
3535 = find_pc_sect_function (loc
->address
, loc
->section
);
3538 ui_out_text (uiout
, "in ");
3539 ui_out_field_string (uiout
, "func",
3540 SYMBOL_PRINT_NAME (sym
));
3541 ui_out_wrap_hint (uiout
, wrap_indent
);
3542 ui_out_text (uiout
, " at ");
3544 ui_out_field_string (uiout
, "file", b
->source_file
);
3545 ui_out_text (uiout
, ":");
3547 if (ui_out_is_mi_like_p (uiout
))
3549 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3550 char *fullname
= symtab_to_fullname (sal
.symtab
);
3553 ui_out_field_string (uiout
, "fullname", fullname
);
3556 ui_out_field_int (uiout
, "line", b
->line_number
);
3560 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3564 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3565 ui_out_field_stream (uiout
, "at", stb
);
3569 /* Print B to gdb_stdout. */
3571 print_one_breakpoint_location (struct breakpoint
*b
,
3572 struct bp_location
*loc
,
3574 struct bp_location
**last_loc
,
3575 int print_address_bits
)
3577 struct command_line
*l
;
3579 struct ep_type_description
3584 static struct ep_type_description bptypes
[] =
3586 {bp_none
, "?deleted?"},
3587 {bp_breakpoint
, "breakpoint"},
3588 {bp_hardware_breakpoint
, "hw breakpoint"},
3589 {bp_until
, "until"},
3590 {bp_finish
, "finish"},
3591 {bp_watchpoint
, "watchpoint"},
3592 {bp_hardware_watchpoint
, "hw watchpoint"},
3593 {bp_read_watchpoint
, "read watchpoint"},
3594 {bp_access_watchpoint
, "acc watchpoint"},
3595 {bp_longjmp
, "longjmp"},
3596 {bp_longjmp_resume
, "longjmp resume"},
3597 {bp_step_resume
, "step resume"},
3598 {bp_watchpoint_scope
, "watchpoint scope"},
3599 {bp_call_dummy
, "call dummy"},
3600 {bp_shlib_event
, "shlib events"},
3601 {bp_thread_event
, "thread events"},
3602 {bp_overlay_event
, "overlay events"},
3603 {bp_longjmp_master
, "longjmp master"},
3604 {bp_catchpoint
, "catchpoint"},
3605 {bp_tracepoint
, "tracepoint"},
3608 static char bpenables
[] = "nynny";
3609 char wrap_indent
[80];
3610 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3611 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3612 struct cleanup
*bkpt_chain
;
3614 int header_of_multiple
= 0;
3615 int part_of_multiple
= (loc
!= NULL
);
3616 struct value_print_options opts
;
3618 get_user_print_options (&opts
);
3620 gdb_assert (!loc
|| loc_number
!= 0);
3621 /* See comment in print_one_breakpoint concerning
3622 treatment of breakpoints with single disabled
3626 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3627 header_of_multiple
= 1;
3632 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3636 if (part_of_multiple
)
3639 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3640 ui_out_field_string (uiout
, "number", formatted
);
3645 ui_out_field_int (uiout
, "number", b
->number
);
3650 if (part_of_multiple
)
3651 ui_out_field_skip (uiout
, "type");
3654 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3655 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3656 internal_error (__FILE__
, __LINE__
,
3657 _("bptypes table does not describe type #%d."),
3659 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3664 if (part_of_multiple
)
3665 ui_out_field_skip (uiout
, "disp");
3667 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3672 if (part_of_multiple
)
3673 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3675 ui_out_field_fmt (uiout
, "enabled", "%c",
3676 bpenables
[(int) b
->enable_state
]);
3677 ui_out_spaces (uiout
, 2);
3681 strcpy (wrap_indent
, " ");
3682 if (opts
.addressprint
)
3684 if (print_address_bits
<= 32)
3685 strcat (wrap_indent
, " ");
3687 strcat (wrap_indent
, " ");
3690 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3692 /* Although the print_one can possibly print
3693 all locations, calling it here is not likely
3694 to get any nice result. So, make sure there's
3695 just one location. */
3696 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3697 b
->ops
->print_one (b
, last_loc
);
3703 internal_error (__FILE__
, __LINE__
,
3704 _("print_one_breakpoint: bp_none encountered\n"));
3708 case bp_hardware_watchpoint
:
3709 case bp_read_watchpoint
:
3710 case bp_access_watchpoint
:
3711 /* Field 4, the address, is omitted (which makes the columns
3712 not line up too nicely with the headers, but the effect
3713 is relatively readable). */
3714 if (opts
.addressprint
)
3715 ui_out_field_skip (uiout
, "addr");
3717 ui_out_field_string (uiout
, "what", b
->exp_string
);
3721 case bp_hardware_breakpoint
:
3725 case bp_longjmp_resume
:
3726 case bp_step_resume
:
3727 case bp_watchpoint_scope
:
3729 case bp_shlib_event
:
3730 case bp_thread_event
:
3731 case bp_overlay_event
:
3732 case bp_longjmp_master
:
3734 if (opts
.addressprint
)
3737 if (header_of_multiple
)
3738 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3739 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3740 ui_out_field_string (uiout
, "addr", "<PENDING>");
3742 ui_out_field_core_addr (uiout
, "addr",
3743 loc
->gdbarch
, loc
->address
);
3746 if (!header_of_multiple
)
3747 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3753 if (!part_of_multiple
)
3755 if (b
->thread
!= -1)
3757 /* FIXME: This seems to be redundant and lost here; see the
3758 "stop only in" line a little further down. */
3759 ui_out_text (uiout
, " thread ");
3760 ui_out_field_int (uiout
, "thread", b
->thread
);
3762 else if (b
->task
!= 0)
3764 ui_out_text (uiout
, " task ");
3765 ui_out_field_int (uiout
, "task", b
->task
);
3769 ui_out_text (uiout
, "\n");
3771 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3774 ui_out_text (uiout
, "\tstop only in stack frame at ");
3775 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3777 ui_out_field_core_addr (uiout
, "frame",
3778 b
->gdbarch
, b
->frame_id
.stack_addr
);
3779 ui_out_text (uiout
, "\n");
3782 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3784 /* We do not print the condition for Ada exception catchpoints
3785 because the condition is an internal implementation detail
3786 that we do not want to expose to the user. */
3788 if (b
->type
== bp_tracepoint
)
3789 ui_out_text (uiout
, "\ttrace only if ");
3791 ui_out_text (uiout
, "\tstop only if ");
3792 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3793 ui_out_text (uiout
, "\n");
3796 if (!part_of_multiple
&& b
->thread
!= -1)
3798 /* FIXME should make an annotation for this */
3799 ui_out_text (uiout
, "\tstop only in thread ");
3800 ui_out_field_int (uiout
, "thread", b
->thread
);
3801 ui_out_text (uiout
, "\n");
3804 if (!part_of_multiple
&& b
->hit_count
)
3806 /* FIXME should make an annotation for this */
3807 if (ep_is_catchpoint (b
))
3808 ui_out_text (uiout
, "\tcatchpoint");
3810 ui_out_text (uiout
, "\tbreakpoint");
3811 ui_out_text (uiout
, " already hit ");
3812 ui_out_field_int (uiout
, "times", b
->hit_count
);
3813 if (b
->hit_count
== 1)
3814 ui_out_text (uiout
, " time\n");
3816 ui_out_text (uiout
, " times\n");
3819 /* Output the count also if it is zero, but only if this is
3820 mi. FIXME: Should have a better test for this. */
3821 if (ui_out_is_mi_like_p (uiout
))
3822 if (!part_of_multiple
&& b
->hit_count
== 0)
3823 ui_out_field_int (uiout
, "times", b
->hit_count
);
3825 if (!part_of_multiple
&& b
->ignore_count
)
3828 ui_out_text (uiout
, "\tignore next ");
3829 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3830 ui_out_text (uiout
, " hits\n");
3834 if (!part_of_multiple
&& l
)
3836 struct cleanup
*script_chain
;
3839 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3840 print_command_lines (uiout
, l
, 4);
3841 do_cleanups (script_chain
);
3844 if (!part_of_multiple
&& b
->pass_count
)
3846 annotate_field (10);
3847 ui_out_text (uiout
, "\tpass count ");
3848 ui_out_field_int (uiout
, "pass", b
->pass_count
);
3849 ui_out_text (uiout
, " \n");
3852 if (!part_of_multiple
&& b
->step_count
)
3854 annotate_field (11);
3855 ui_out_text (uiout
, "\tstep count ");
3856 ui_out_field_int (uiout
, "step", b
->step_count
);
3857 ui_out_text (uiout
, " \n");
3860 if (!part_of_multiple
&& b
->actions
)
3862 struct action_line
*action
;
3863 annotate_field (12);
3864 for (action
= b
->actions
; action
; action
= action
->next
)
3866 ui_out_text (uiout
, " A\t");
3867 ui_out_text (uiout
, action
->action
);
3868 ui_out_text (uiout
, "\n");
3872 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3875 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3876 else if (b
->exp_string
)
3877 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3880 do_cleanups (bkpt_chain
);
3881 do_cleanups (old_chain
);
3885 print_one_breakpoint (struct breakpoint
*b
,
3886 struct bp_location
**last_loc
, int print_address_bits
)
3888 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, print_address_bits
);
3890 /* If this breakpoint has custom print function,
3891 it's already printed. Otherwise, print individual
3892 locations, if any. */
3893 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3895 /* If breakpoint has a single location that is
3896 disabled, we print it as if it had
3897 several locations, since otherwise it's hard to
3898 represent "breakpoint enabled, location disabled"
3900 Note that while hardware watchpoints have
3901 several locations internally, that's no a property
3904 && !is_hardware_watchpoint (b
)
3905 && (b
->loc
->next
|| !b
->loc
->enabled
)
3906 && !ui_out_is_mi_like_p (uiout
))
3908 struct bp_location
*loc
;
3910 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3911 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
3912 print_address_bits
);
3918 breakpoint_address_bits (struct breakpoint
*b
)
3920 int print_address_bits
= 0;
3921 struct bp_location
*loc
;
3923 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3925 int addr_bit
= gdbarch_addr_bit (b
->gdbarch
);
3926 if (addr_bit
> print_address_bits
)
3927 print_address_bits
= addr_bit
;
3930 return print_address_bits
;
3933 struct captured_breakpoint_query_args
3939 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3941 struct captured_breakpoint_query_args
*args
= data
;
3942 struct breakpoint
*b
;
3943 struct bp_location
*dummy_loc
= NULL
;
3946 if (args
->bnum
== b
->number
)
3948 int print_address_bits
= breakpoint_address_bits (b
);
3949 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
);
3957 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3959 struct captured_breakpoint_query_args args
;
3961 /* For the moment we don't trust print_one_breakpoint() to not throw
3963 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3964 error_message
, RETURN_MASK_ALL
) < 0)
3970 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3971 catchpoints, et.al.). */
3974 user_settable_breakpoint (const struct breakpoint
*b
)
3976 return (b
->type
== bp_breakpoint
3977 || b
->type
== bp_catchpoint
3978 || b
->type
== bp_hardware_breakpoint
3979 || b
->type
== bp_tracepoint
3980 || b
->type
== bp_watchpoint
3981 || b
->type
== bp_read_watchpoint
3982 || b
->type
== bp_access_watchpoint
3983 || b
->type
== bp_hardware_watchpoint
);
3986 /* Print information on user settable breakpoint (watchpoint, etc)
3987 number BNUM. If BNUM is -1 print all user settable breakpoints.
3988 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3991 breakpoint_1 (int bnum
, int allflag
)
3993 struct breakpoint
*b
;
3994 struct bp_location
*last_loc
= NULL
;
3995 int nr_printable_breakpoints
;
3996 struct cleanup
*bkpttbl_chain
;
3997 struct value_print_options opts
;
3998 int print_address_bits
= 0;
4000 get_user_print_options (&opts
);
4002 /* Compute the number of rows in the table, as well as the
4003 size required for address fields. */
4004 nr_printable_breakpoints
= 0;
4007 || bnum
== b
->number
)
4009 if (allflag
|| user_settable_breakpoint (b
))
4011 int addr_bit
= breakpoint_address_bits (b
);
4012 if (addr_bit
> print_address_bits
)
4013 print_address_bits
= addr_bit
;
4015 nr_printable_breakpoints
++;
4019 if (opts
.addressprint
)
4021 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4025 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4028 if (nr_printable_breakpoints
> 0)
4029 annotate_breakpoints_headers ();
4030 if (nr_printable_breakpoints
> 0)
4032 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4033 if (nr_printable_breakpoints
> 0)
4035 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4036 if (nr_printable_breakpoints
> 0)
4038 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4039 if (nr_printable_breakpoints
> 0)
4041 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4042 if (opts
.addressprint
)
4044 if (nr_printable_breakpoints
> 0)
4046 if (print_address_bits
<= 32)
4047 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4049 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4051 if (nr_printable_breakpoints
> 0)
4053 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4054 ui_out_table_body (uiout
);
4055 if (nr_printable_breakpoints
> 0)
4056 annotate_breakpoints_table ();
4060 || bnum
== b
->number
)
4062 /* We only print out user settable breakpoints unless the
4064 if (allflag
|| user_settable_breakpoint (b
))
4065 print_one_breakpoint (b
, &last_loc
, print_address_bits
);
4068 do_cleanups (bkpttbl_chain
);
4070 if (nr_printable_breakpoints
== 0)
4073 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
4075 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
4080 if (last_loc
&& !server_command
)
4081 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
4084 /* FIXME? Should this be moved up so that it is only called when
4085 there have been breakpoints? */
4086 annotate_breakpoints_table_end ();
4090 breakpoints_info (char *bnum_exp
, int from_tty
)
4095 bnum
= parse_and_eval_long (bnum_exp
);
4097 breakpoint_1 (bnum
, 0);
4101 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4106 bnum
= parse_and_eval_long (bnum_exp
);
4108 breakpoint_1 (bnum
, 1);
4112 breakpoint_has_pc (struct breakpoint
*b
,
4113 CORE_ADDR pc
, struct obj_section
*section
)
4115 struct bp_location
*bl
= b
->loc
;
4116 for (; bl
; bl
= bl
->next
)
4118 if (bl
->address
== pc
4119 && (!overlay_debugging
|| bl
->section
== section
))
4125 /* Print a message describing any breakpoints set at PC. */
4128 describe_other_breakpoints (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
4129 struct obj_section
*section
, int thread
)
4132 struct breakpoint
*b
;
4135 others
+= breakpoint_has_pc (b
, pc
, section
);
4139 printf_filtered (_("Note: breakpoint "));
4140 else /* if (others == ???) */
4141 printf_filtered (_("Note: breakpoints "));
4143 if (breakpoint_has_pc (b
, pc
, section
))
4146 printf_filtered ("%d", b
->number
);
4147 if (b
->thread
== -1 && thread
!= -1)
4148 printf_filtered (" (all threads)");
4149 else if (b
->thread
!= -1)
4150 printf_filtered (" (thread %d)", b
->thread
);
4151 printf_filtered ("%s%s ",
4152 ((b
->enable_state
== bp_disabled
4153 || b
->enable_state
== bp_call_disabled
4154 || b
->enable_state
== bp_startup_disabled
)
4156 : b
->enable_state
== bp_permanent
4160 : ((others
== 1) ? " and" : ""));
4162 printf_filtered (_("also set at pc "));
4163 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
4164 printf_filtered (".\n");
4168 /* Set the default place to put a breakpoint
4169 for the `break' command with no arguments. */
4172 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4175 default_breakpoint_valid
= valid
;
4176 default_breakpoint_address
= addr
;
4177 default_breakpoint_symtab
= symtab
;
4178 default_breakpoint_line
= line
;
4181 /* Return true iff it is meaningful to use the address member of
4182 BPT. For some breakpoint types, the address member is irrelevant
4183 and it makes no sense to attempt to compare it to other addresses
4184 (or use it for any other purpose either).
4186 More specifically, each of the following breakpoint types will always
4187 have a zero valued address and we don't want check_duplicates() to mark
4188 breakpoints of any of these types to be a duplicate of an actual
4189 breakpoint at address zero:
4192 bp_hardware_watchpoint
4194 bp_access_watchpoint
4198 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4200 enum bptype type
= bpt
->type
;
4202 return (type
!= bp_watchpoint
4203 && type
!= bp_hardware_watchpoint
4204 && type
!= bp_read_watchpoint
4205 && type
!= bp_access_watchpoint
4206 && type
!= bp_catchpoint
);
4209 /* Rescan breakpoints at the same address and section as BPT,
4210 marking the first one as "first" and any others as "duplicates".
4211 This is so that the bpt instruction is only inserted once.
4212 If we have a permanent breakpoint at the same place as BPT, make
4213 that one the official one, and the rest as duplicates. */
4216 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
4218 struct bp_location
*b
;
4220 struct bp_location
*perm_bp
= 0;
4222 ALL_BP_LOCATIONS (b
)
4223 if (b
->owner
->enable_state
!= bp_disabled
4224 && b
->owner
->enable_state
!= bp_call_disabled
4225 && b
->owner
->enable_state
!= bp_startup_disabled
4227 && !b
->shlib_disabled
4228 && b
->address
== address
/* address / overlay match */
4229 && (!overlay_debugging
|| b
->section
== section
)
4230 && breakpoint_address_is_meaningful (b
->owner
))
4232 /* Have we found a permanent breakpoint? */
4233 if (b
->owner
->enable_state
== bp_permanent
)
4240 b
->duplicate
= count
> 1;
4243 /* If we found a permanent breakpoint at this address, go over the
4244 list again and declare all the other breakpoints there (except
4245 other permanent breakpoints) to be the duplicates. */
4248 perm_bp
->duplicate
= 0;
4250 /* Permanent breakpoint should always be inserted. */
4251 if (! perm_bp
->inserted
)
4252 internal_error (__FILE__
, __LINE__
,
4253 _("allegedly permanent breakpoint is not "
4254 "actually inserted"));
4256 ALL_BP_LOCATIONS (b
)
4259 if (b
->owner
->enable_state
!= bp_permanent
4260 && b
->owner
->enable_state
!= bp_disabled
4261 && b
->owner
->enable_state
!= bp_call_disabled
4262 && b
->owner
->enable_state
!= bp_startup_disabled
4263 && b
->enabled
&& !b
->shlib_disabled
4264 && b
->address
== address
/* address / overlay match */
4265 && (!overlay_debugging
|| b
->section
== section
)
4266 && breakpoint_address_is_meaningful (b
->owner
))
4269 internal_error (__FILE__
, __LINE__
,
4270 _("another breakpoint was inserted on top of "
4271 "a permanent breakpoint"));
4280 check_duplicates (struct breakpoint
*bpt
)
4282 struct bp_location
*bl
= bpt
->loc
;
4284 if (! breakpoint_address_is_meaningful (bpt
))
4287 for (; bl
; bl
= bl
->next
)
4288 check_duplicates_for (bl
->address
, bl
->section
);
4292 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4293 int bnum
, int have_bnum
)
4298 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4299 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4301 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4302 bnum
, astr1
, astr2
);
4304 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4307 /* Adjust a breakpoint's address to account for architectural constraints
4308 on breakpoint placement. Return the adjusted address. Note: Very
4309 few targets require this kind of adjustment. For most targets,
4310 this function is simply the identity function. */
4313 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
4314 CORE_ADDR bpaddr
, enum bptype bptype
)
4316 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
4318 /* Very few targets need any kind of breakpoint adjustment. */
4321 else if (bptype
== bp_watchpoint
4322 || bptype
== bp_hardware_watchpoint
4323 || bptype
== bp_read_watchpoint
4324 || bptype
== bp_access_watchpoint
4325 || bptype
== bp_catchpoint
)
4327 /* Watchpoints and the various bp_catch_* eventpoints should not
4328 have their addresses modified. */
4333 CORE_ADDR adjusted_bpaddr
;
4335 /* Some targets have architectural constraints on the placement
4336 of breakpoint instructions. Obtain the adjusted address. */
4337 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
4339 /* An adjusted breakpoint address can significantly alter
4340 a user's expectations. Print a warning if an adjustment
4342 if (adjusted_bpaddr
!= bpaddr
)
4343 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4345 return adjusted_bpaddr
;
4349 /* Allocate a struct bp_location. */
4351 static struct bp_location
*
4352 allocate_bp_location (struct breakpoint
*bpt
)
4354 struct bp_location
*loc
, *loc_p
;
4356 loc
= xmalloc (sizeof (struct bp_location
));
4357 memset (loc
, 0, sizeof (*loc
));
4361 loc
->shlib_disabled
= 0;
4371 case bp_longjmp_resume
:
4372 case bp_step_resume
:
4373 case bp_watchpoint_scope
:
4375 case bp_shlib_event
:
4376 case bp_thread_event
:
4377 case bp_overlay_event
:
4378 case bp_longjmp_master
:
4379 loc
->loc_type
= bp_loc_software_breakpoint
;
4381 case bp_hardware_breakpoint
:
4382 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4384 case bp_hardware_watchpoint
:
4385 case bp_read_watchpoint
:
4386 case bp_access_watchpoint
:
4387 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4391 loc
->loc_type
= bp_loc_other
;
4394 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4400 static void free_bp_location (struct bp_location
*loc
)
4405 if (loc
->function_name
)
4406 xfree (loc
->function_name
);
4411 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4412 that has type BPTYPE and has no locations as yet. */
4413 /* This function is used in gdbtk sources and thus can not be made static. */
4415 static struct breakpoint
*
4416 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
4419 struct breakpoint
*b
, *b1
;
4421 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4422 memset (b
, 0, sizeof (*b
));
4425 b
->gdbarch
= gdbarch
;
4426 b
->language
= current_language
->la_language
;
4427 b
->input_radix
= input_radix
;
4429 b
->enable_state
= bp_enabled
;
4432 b
->ignore_count
= 0;
4434 b
->frame_id
= null_frame_id
;
4435 b
->forked_inferior_pid
= null_ptid
;
4436 b
->exec_pathname
= NULL
;
4438 b
->condition_not_parsed
= 0;
4440 /* Add this breakpoint to the end of the chain
4441 so that a list of breakpoints will come out in order
4442 of increasing numbers. */
4444 b1
= breakpoint_chain
;
4446 breakpoint_chain
= b
;
4456 /* Initialize loc->function_name. */
4458 set_breakpoint_location_function (struct bp_location
*loc
)
4460 if (loc
->owner
->type
== bp_breakpoint
4461 || loc
->owner
->type
== bp_hardware_breakpoint
4462 || loc
->owner
->type
== bp_tracepoint
)
4464 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4466 if (loc
->function_name
)
4467 loc
->function_name
= xstrdup (loc
->function_name
);
4471 /* Attempt to determine architecture of location identified by SAL. */
4472 static struct gdbarch
*
4473 get_sal_arch (struct symtab_and_line sal
)
4476 return get_objfile_arch (sal
.section
->objfile
);
4478 return get_objfile_arch (sal
.symtab
->objfile
);
4483 /* set_raw_breakpoint is a low level routine for allocating and
4484 partially initializing a breakpoint of type BPTYPE. The newly
4485 created breakpoint's address, section, source file name, and line
4486 number are provided by SAL. The newly created and partially
4487 initialized breakpoint is added to the breakpoint chain and
4488 is also returned as the value of this function.
4490 It is expected that the caller will complete the initialization of
4491 the newly created breakpoint struct as well as output any status
4492 information regarding the creation of a new breakpoint. In
4493 particular, set_raw_breakpoint does NOT set the breakpoint
4494 number! Care should be taken to not allow an error to occur
4495 prior to completing the initialization of the breakpoint. If this
4496 should happen, a bogus breakpoint will be left on the chain. */
4499 set_raw_breakpoint (struct gdbarch
*gdbarch
,
4500 struct symtab_and_line sal
, enum bptype bptype
)
4502 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
4503 CORE_ADDR adjusted_address
;
4504 struct gdbarch
*loc_gdbarch
;
4506 loc_gdbarch
= get_sal_arch (sal
);
4508 loc_gdbarch
= b
->gdbarch
;
4510 /* Adjust the breakpoint's address prior to allocating a location.
4511 Once we call allocate_bp_location(), that mostly uninitialized
4512 location will be placed on the location chain. Adjustment of the
4513 breakpoint may cause target_read_memory() to be called and we do
4514 not want its scan of the location chain to find a breakpoint and
4515 location that's only been partially initialized. */
4516 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
4518 b
->loc
= allocate_bp_location (b
);
4519 b
->loc
->gdbarch
= loc_gdbarch
;
4520 b
->loc
->requested_address
= sal
.pc
;
4521 b
->loc
->address
= adjusted_address
;
4523 if (sal
.symtab
== NULL
)
4524 b
->source_file
= NULL
;
4526 b
->source_file
= xstrdup (sal
.symtab
->filename
);
4527 b
->loc
->section
= sal
.section
;
4528 b
->line_number
= sal
.line
;
4530 set_breakpoint_location_function (b
->loc
);
4532 breakpoints_changed ();
4538 /* Note that the breakpoint object B describes a permanent breakpoint
4539 instruction, hard-wired into the inferior's code. */
4541 make_breakpoint_permanent (struct breakpoint
*b
)
4543 struct bp_location
*bl
;
4544 b
->enable_state
= bp_permanent
;
4546 /* By definition, permanent breakpoints are already present in the code.
4547 Mark all locations as inserted. For now, make_breakpoint_permanent
4548 is called in just one place, so it's hard to say if it's reasonable
4549 to have permanent breakpoint with multiple locations or not,
4550 but it's easy to implmement. */
4551 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4555 /* Call this routine when stepping and nexting to enable a breakpoint
4556 if we do a longjmp() in THREAD. When we hit that breakpoint, call
4557 set_longjmp_resume_breakpoint() to figure out where we are going. */
4560 set_longjmp_breakpoint (int thread
)
4562 struct breakpoint
*b
, *temp
;
4564 /* To avoid having to rescan all objfile symbols at every step,
4565 we maintain a list of continually-inserted but always disabled
4566 longjmp "master" breakpoints. Here, we simply create momentary
4567 clones of those and enable them for the requested thread. */
4568 ALL_BREAKPOINTS_SAFE (b
, temp
)
4569 if (b
->type
== bp_longjmp_master
)
4571 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
4572 clone
->type
= bp_longjmp
;
4573 clone
->thread
= thread
;
4577 /* Delete all longjmp breakpoints from THREAD. */
4579 delete_longjmp_breakpoint (int thread
)
4581 struct breakpoint
*b
, *temp
;
4583 ALL_BREAKPOINTS_SAFE (b
, temp
)
4584 if (b
->type
== bp_longjmp
)
4586 if (b
->thread
== thread
)
4587 delete_breakpoint (b
);
4592 enable_overlay_breakpoints (void)
4594 struct breakpoint
*b
;
4597 if (b
->type
== bp_overlay_event
)
4599 b
->enable_state
= bp_enabled
;
4600 update_global_location_list (1);
4601 overlay_events_enabled
= 1;
4606 disable_overlay_breakpoints (void)
4608 struct breakpoint
*b
;
4611 if (b
->type
== bp_overlay_event
)
4613 b
->enable_state
= bp_disabled
;
4614 update_global_location_list (0);
4615 overlay_events_enabled
= 0;
4620 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
4622 struct breakpoint
*b
;
4624 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
4626 b
->enable_state
= bp_enabled
;
4627 /* addr_string has to be used or breakpoint_re_set will delete me. */
4629 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
4631 update_global_location_list_nothrow (1);
4637 remove_thread_event_breakpoints (void)
4639 struct breakpoint
*b
, *temp
;
4641 ALL_BREAKPOINTS_SAFE (b
, temp
)
4642 if (b
->type
== bp_thread_event
)
4643 delete_breakpoint (b
);
4646 struct captured_parse_breakpoint_args
4649 struct symtabs_and_lines
*sals_p
;
4650 char ***addr_string_p
;
4654 struct lang_and_radix
4662 remove_solib_event_breakpoints (void)
4664 struct breakpoint
*b
, *temp
;
4666 ALL_BREAKPOINTS_SAFE (b
, temp
)
4667 if (b
->type
== bp_shlib_event
)
4668 delete_breakpoint (b
);
4672 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
4674 struct breakpoint
*b
;
4676 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
4677 update_global_location_list_nothrow (1);
4681 /* Disable any breakpoints that are on code in shared libraries. Only
4682 apply to enabled breakpoints, disabled ones can just stay disabled. */
4685 disable_breakpoints_in_shlibs (void)
4687 struct bp_location
*loc
;
4689 ALL_BP_LOCATIONS (loc
)
4691 struct breakpoint
*b
= loc
->owner
;
4692 /* We apply the check to all breakpoints, including disabled
4693 for those with loc->duplicate set. This is so that when breakpoint
4694 becomes enabled, or the duplicate is removed, gdb will try to insert
4695 all breakpoints. If we don't set shlib_disabled here, we'll try
4696 to insert those breakpoints and fail. */
4697 if (((b
->type
== bp_breakpoint
)
4698 || (b
->type
== bp_hardware_breakpoint
)
4699 || (b
->type
== bp_tracepoint
))
4700 && !loc
->shlib_disabled
4702 && PC_SOLIB (loc
->address
)
4704 && solib_name_from_address (loc
->address
)
4708 loc
->shlib_disabled
= 1;
4713 /* Disable any breakpoints that are in in an unloaded shared library. Only
4714 apply to enabled breakpoints, disabled ones can just stay disabled. */
4717 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4719 struct bp_location
*loc
;
4720 int disabled_shlib_breaks
= 0;
4722 /* SunOS a.out shared libraries are always mapped, so do not
4723 disable breakpoints; they will only be reported as unloaded
4724 through clear_solib when GDB discards its shared library
4725 list. See clear_solib for more information. */
4726 if (exec_bfd
!= NULL
4727 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
4730 ALL_BP_LOCATIONS (loc
)
4732 struct breakpoint
*b
= loc
->owner
;
4733 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4734 || loc
->loc_type
== bp_loc_software_breakpoint
)
4735 && !loc
->shlib_disabled
4736 && (b
->type
== bp_breakpoint
|| b
->type
== bp_hardware_breakpoint
)
4737 && solib_contains_address_p (solib
, loc
->address
))
4739 loc
->shlib_disabled
= 1;
4740 /* At this point, we cannot rely on remove_breakpoint
4741 succeeding so we must mark the breakpoint as not inserted
4742 to prevent future errors occurring in remove_breakpoints. */
4744 if (!disabled_shlib_breaks
)
4746 target_terminal_ours_for_output ();
4747 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4750 disabled_shlib_breaks
= 1;
4755 /* FORK & VFORK catchpoints. */
4757 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4760 insert_catch_fork (struct breakpoint
*b
)
4762 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4765 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4768 remove_catch_fork (struct breakpoint
*b
)
4770 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4773 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4777 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4779 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4782 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4784 static enum print_stop_action
4785 print_it_catch_fork (struct breakpoint
*b
)
4787 annotate_catchpoint (b
->number
);
4788 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4789 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4790 return PRINT_SRC_AND_LOC
;
4793 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4796 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
4798 struct value_print_options opts
;
4800 get_user_print_options (&opts
);
4802 /* Field 4, the address, is omitted (which makes the columns
4803 not line up too nicely with the headers, but the effect
4804 is relatively readable). */
4805 if (opts
.addressprint
)
4806 ui_out_field_skip (uiout
, "addr");
4808 ui_out_text (uiout
, "fork");
4809 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4811 ui_out_text (uiout
, ", process ");
4812 ui_out_field_int (uiout
, "what",
4813 ptid_get_pid (b
->forked_inferior_pid
));
4814 ui_out_spaces (uiout
, 1);
4818 /* Implement the "print_mention" breakpoint_ops method for fork
4822 print_mention_catch_fork (struct breakpoint
*b
)
4824 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4827 /* The breakpoint_ops structure to be used in fork catchpoints. */
4829 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4833 breakpoint_hit_catch_fork
,
4834 print_it_catch_fork
,
4835 print_one_catch_fork
,
4836 print_mention_catch_fork
4839 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4842 insert_catch_vfork (struct breakpoint
*b
)
4844 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4847 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4850 remove_catch_vfork (struct breakpoint
*b
)
4852 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4855 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4859 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4861 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4864 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4866 static enum print_stop_action
4867 print_it_catch_vfork (struct breakpoint
*b
)
4869 annotate_catchpoint (b
->number
);
4870 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4871 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4872 return PRINT_SRC_AND_LOC
;
4875 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4878 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
4880 struct value_print_options opts
;
4882 get_user_print_options (&opts
);
4883 /* Field 4, the address, is omitted (which makes the columns
4884 not line up too nicely with the headers, but the effect
4885 is relatively readable). */
4886 if (opts
.addressprint
)
4887 ui_out_field_skip (uiout
, "addr");
4889 ui_out_text (uiout
, "vfork");
4890 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4892 ui_out_text (uiout
, ", process ");
4893 ui_out_field_int (uiout
, "what",
4894 ptid_get_pid (b
->forked_inferior_pid
));
4895 ui_out_spaces (uiout
, 1);
4899 /* Implement the "print_mention" breakpoint_ops method for vfork
4903 print_mention_catch_vfork (struct breakpoint
*b
)
4905 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4908 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4910 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4914 breakpoint_hit_catch_vfork
,
4915 print_it_catch_vfork
,
4916 print_one_catch_vfork
,
4917 print_mention_catch_vfork
4920 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4922 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4923 If COND_STRING is not NULL, then store it in the breakpoint.
4924 OPS, if not NULL, is the breakpoint_ops structure associated
4925 to the catchpoint. */
4927 static struct breakpoint
*
4928 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
4929 char *cond_string
, struct breakpoint_ops
*ops
)
4931 struct symtab_and_line sal
;
4932 struct breakpoint
*b
;
4939 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
4940 set_breakpoint_count (breakpoint_count
+ 1);
4941 b
->number
= breakpoint_count
;
4943 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
4945 b
->addr_string
= NULL
;
4946 b
->enable_state
= bp_enabled
;
4947 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4951 update_global_location_list (1);
4957 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
4958 int tempflag
, char *cond_string
,
4959 struct breakpoint_ops
*ops
)
4961 struct breakpoint
*b
4962 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
4964 /* FIXME: We should put this information in a breakpoint private data
4966 b
->forked_inferior_pid
= null_ptid
;
4969 /* Exec catchpoints. */
4972 insert_catch_exec (struct breakpoint
*b
)
4974 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
4978 remove_catch_exec (struct breakpoint
*b
)
4980 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
4984 breakpoint_hit_catch_exec (struct breakpoint
*b
)
4986 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
4989 static enum print_stop_action
4990 print_it_catch_exec (struct breakpoint
*b
)
4992 annotate_catchpoint (b
->number
);
4993 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
4995 return PRINT_SRC_AND_LOC
;
4999 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
5001 struct value_print_options opts
;
5003 get_user_print_options (&opts
);
5005 /* Field 4, the address, is omitted (which makes the columns
5006 not line up too nicely with the headers, but the effect
5007 is relatively readable). */
5008 if (opts
.addressprint
)
5009 ui_out_field_skip (uiout
, "addr");
5011 ui_out_text (uiout
, "exec");
5012 if (b
->exec_pathname
!= NULL
)
5014 ui_out_text (uiout
, ", program \"");
5015 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
5016 ui_out_text (uiout
, "\" ");
5021 print_mention_catch_exec (struct breakpoint
*b
)
5023 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
5026 static struct breakpoint_ops catch_exec_breakpoint_ops
=
5030 breakpoint_hit_catch_exec
,
5031 print_it_catch_exec
,
5032 print_one_catch_exec
,
5033 print_mention_catch_exec
5037 hw_breakpoint_used_count (void)
5039 struct breakpoint
*b
;
5044 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
5052 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
5054 struct breakpoint
*b
;
5057 *other_type_used
= 0;
5060 if (breakpoint_enabled (b
))
5062 if (b
->type
== type
)
5064 else if ((b
->type
== bp_hardware_watchpoint
5065 || b
->type
== bp_read_watchpoint
5066 || b
->type
== bp_access_watchpoint
))
5067 *other_type_used
= 1;
5074 disable_watchpoints_before_interactive_call_start (void)
5076 struct breakpoint
*b
;
5080 if (((b
->type
== bp_watchpoint
)
5081 || (b
->type
== bp_hardware_watchpoint
)
5082 || (b
->type
== bp_read_watchpoint
)
5083 || (b
->type
== bp_access_watchpoint
))
5084 && breakpoint_enabled (b
))
5086 b
->enable_state
= bp_call_disabled
;
5087 update_global_location_list (0);
5093 enable_watchpoints_after_interactive_call_stop (void)
5095 struct breakpoint
*b
;
5099 if (((b
->type
== bp_watchpoint
)
5100 || (b
->type
== bp_hardware_watchpoint
)
5101 || (b
->type
== bp_read_watchpoint
)
5102 || (b
->type
== bp_access_watchpoint
))
5103 && (b
->enable_state
== bp_call_disabled
))
5105 b
->enable_state
= bp_enabled
;
5106 update_global_location_list (1);
5112 disable_breakpoints_before_startup (void)
5114 struct breakpoint
*b
;
5119 if ((b
->type
== bp_breakpoint
5120 || b
->type
== bp_hardware_breakpoint
)
5121 && breakpoint_enabled (b
))
5123 b
->enable_state
= bp_startup_disabled
;
5129 update_global_location_list (0);
5131 executing_startup
= 1;
5135 enable_breakpoints_after_startup (void)
5137 struct breakpoint
*b
;
5140 executing_startup
= 0;
5144 if ((b
->type
== bp_breakpoint
5145 || b
->type
== bp_hardware_breakpoint
)
5146 && b
->enable_state
== bp_startup_disabled
)
5148 b
->enable_state
= bp_enabled
;
5154 breakpoint_re_set ();
5158 /* Set a breakpoint that will evaporate an end of command
5159 at address specified by SAL.
5160 Restrict it to frame FRAME if FRAME is nonzero. */
5163 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
5164 struct frame_id frame_id
, enum bptype type
)
5166 struct breakpoint
*b
;
5168 /* If FRAME_ID is valid, it should be a real frame, not an inlined
5170 gdb_assert (!frame_id_inlined_p (frame_id
));
5172 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
5173 b
->enable_state
= bp_enabled
;
5174 b
->disposition
= disp_donttouch
;
5175 b
->frame_id
= frame_id
;
5177 /* If we're debugging a multi-threaded program, then we
5178 want momentary breakpoints to be active in only a
5179 single thread of control. */
5180 if (in_thread_list (inferior_ptid
))
5181 b
->thread
= pid_to_thread_id (inferior_ptid
);
5183 update_global_location_list_nothrow (1);
5188 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
5192 clone_momentary_breakpoint (struct breakpoint
*orig
)
5194 struct breakpoint
*copy
;
5196 /* If there's nothing to clone, then return nothing. */
5200 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
5201 copy
->loc
= allocate_bp_location (copy
);
5202 set_breakpoint_location_function (copy
->loc
);
5204 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
5205 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
5206 copy
->loc
->address
= orig
->loc
->address
;
5207 copy
->loc
->section
= orig
->loc
->section
;
5209 if (orig
->source_file
== NULL
)
5210 copy
->source_file
= NULL
;
5212 copy
->source_file
= xstrdup (orig
->source_file
);
5214 copy
->line_number
= orig
->line_number
;
5215 copy
->frame_id
= orig
->frame_id
;
5216 copy
->thread
= orig
->thread
;
5218 copy
->enable_state
= bp_enabled
;
5219 copy
->disposition
= disp_donttouch
;
5220 copy
->number
= internal_breakpoint_number
--;
5222 update_global_location_list_nothrow (0);
5227 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
5230 struct symtab_and_line sal
;
5232 sal
= find_pc_line (pc
, 0);
5234 sal
.section
= find_pc_overlay (pc
);
5235 sal
.explicit_pc
= 1;
5237 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
5241 /* Tell the user we have just set a breakpoint B. */
5244 mention (struct breakpoint
*b
)
5247 struct cleanup
*ui_out_chain
;
5248 struct value_print_options opts
;
5250 get_user_print_options (&opts
);
5252 /* FIXME: This is misplaced; mention() is called by things (like
5253 hitting a watchpoint) other than breakpoint creation. It should
5254 be possible to clean this up and at the same time replace the
5255 random calls to breakpoint_changed with this hook. */
5256 observer_notify_breakpoint_created (b
->number
);
5258 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
5259 b
->ops
->print_mention (b
);
5264 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
5267 ui_out_text (uiout
, "Watchpoint ");
5268 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5269 ui_out_field_int (uiout
, "number", b
->number
);
5270 ui_out_text (uiout
, ": ");
5271 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5272 do_cleanups (ui_out_chain
);
5274 case bp_hardware_watchpoint
:
5275 ui_out_text (uiout
, "Hardware watchpoint ");
5276 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5277 ui_out_field_int (uiout
, "number", b
->number
);
5278 ui_out_text (uiout
, ": ");
5279 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5280 do_cleanups (ui_out_chain
);
5282 case bp_read_watchpoint
:
5283 ui_out_text (uiout
, "Hardware read watchpoint ");
5284 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
5285 ui_out_field_int (uiout
, "number", b
->number
);
5286 ui_out_text (uiout
, ": ");
5287 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5288 do_cleanups (ui_out_chain
);
5290 case bp_access_watchpoint
:
5291 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
5292 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
5293 ui_out_field_int (uiout
, "number", b
->number
);
5294 ui_out_text (uiout
, ": ");
5295 ui_out_field_string (uiout
, "exp", b
->exp_string
);
5296 do_cleanups (ui_out_chain
);
5299 if (ui_out_is_mi_like_p (uiout
))
5304 if (b
->disposition
== disp_del
)
5305 printf_filtered (_("Temporary breakpoint"));
5307 printf_filtered (_("Breakpoint"));
5308 printf_filtered (_(" %d"), b
->number
);
5311 case bp_hardware_breakpoint
:
5312 if (ui_out_is_mi_like_p (uiout
))
5317 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
5321 if (ui_out_is_mi_like_p (uiout
))
5326 printf_filtered (_("Tracepoint"));
5327 printf_filtered (_(" %d"), b
->number
);
5334 case bp_longjmp_resume
:
5335 case bp_step_resume
:
5337 case bp_watchpoint_scope
:
5338 case bp_shlib_event
:
5339 case bp_thread_event
:
5340 case bp_overlay_event
:
5341 case bp_longjmp_master
:
5347 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5351 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5355 if (opts
.addressprint
|| b
->source_file
== NULL
)
5357 printf_filtered (" at ");
5358 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
5362 printf_filtered (": file %s, line %d.",
5363 b
->source_file
, b
->line_number
);
5367 struct bp_location
*loc
= b
->loc
;
5369 for (; loc
; loc
= loc
->next
)
5371 printf_filtered (" (%d locations)", n
);
5376 if (ui_out_is_mi_like_p (uiout
))
5378 printf_filtered ("\n");
5382 static struct bp_location
*
5383 add_location_to_breakpoint (struct breakpoint
*b
,
5384 const struct symtab_and_line
*sal
)
5386 struct bp_location
*loc
, **tmp
;
5388 loc
= allocate_bp_location (b
);
5389 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5392 loc
->gdbarch
= get_sal_arch (*sal
);
5394 loc
->gdbarch
= b
->gdbarch
;
5395 loc
->requested_address
= sal
->pc
;
5396 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
5397 loc
->requested_address
, b
->type
);
5398 loc
->section
= sal
->section
;
5400 set_breakpoint_location_function (loc
);
5405 /* Return 1 if LOC is pointing to a permanent breakpoint,
5406 return 0 otherwise. */
5409 bp_loc_is_permanent (struct bp_location
*loc
)
5413 const gdb_byte
*brk
;
5414 gdb_byte
*target_mem
;
5415 struct cleanup
*cleanup
;
5418 gdb_assert (loc
!= NULL
);
5420 addr
= loc
->address
;
5421 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
5423 /* Software breakpoints unsupported? */
5427 target_mem
= alloca (len
);
5429 /* Enable the automatic memory restoration from breakpoints while
5430 we read the memory. Otherwise we could say about our temporary
5431 breakpoints they are permanent. */
5432 cleanup
= make_show_memory_breakpoints_cleanup (0);
5434 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5435 && memcmp (target_mem
, brk
, len
) == 0)
5438 do_cleanups (cleanup
);
5445 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5446 as textual description of the location, and COND_STRING
5447 as condition expression. */
5450 create_breakpoint (struct gdbarch
*gdbarch
,
5451 struct symtabs_and_lines sals
, char *addr_string
,
5453 enum bptype type
, enum bpdisp disposition
,
5454 int thread
, int task
, int ignore_count
,
5455 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
5457 struct breakpoint
*b
= NULL
;
5460 if (type
== bp_hardware_breakpoint
)
5462 int i
= hw_breakpoint_used_count ();
5463 int target_resources_ok
=
5464 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
5466 if (target_resources_ok
== 0)
5467 error (_("No hardware breakpoint support in the target."));
5468 else if (target_resources_ok
< 0)
5469 error (_("Hardware breakpoints used exceeds limit."));
5472 for (i
= 0; i
< sals
.nelts
; ++i
)
5474 struct symtab_and_line sal
= sals
.sals
[i
];
5475 struct bp_location
*loc
;
5479 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
5481 loc_gdbarch
= gdbarch
;
5483 describe_other_breakpoints (loc_gdbarch
,
5484 sal
.pc
, sal
.section
, thread
);
5489 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
5490 set_breakpoint_count (breakpoint_count
+ 1);
5491 b
->number
= breakpoint_count
;
5495 b
->cond_string
= cond_string
;
5496 b
->ignore_count
= ignore_count
;
5497 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
5498 b
->disposition
= disposition
;
5500 if (enabled
&& executing_startup
5501 && (b
->type
== bp_breakpoint
5502 || b
->type
== bp_hardware_breakpoint
))
5503 b
->enable_state
= bp_startup_disabled
;
5509 loc
= add_location_to_breakpoint (b
, &sal
);
5512 if (bp_loc_is_permanent (loc
))
5513 make_breakpoint_permanent (b
);
5517 char *arg
= b
->cond_string
;
5518 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5520 error (_("Garbage %s follows condition"), arg
);
5525 b
->addr_string
= addr_string
;
5527 /* addr_string has to be used or breakpoint_re_set will delete
5530 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5536 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5537 elements to fill the void space. */
5539 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5541 int i
= index_to_remove
+1;
5542 int last_index
= sal
->nelts
-1;
5544 for (;i
<= last_index
; ++i
)
5545 sal
->sals
[i
-1] = sal
->sals
[i
];
5550 /* If appropriate, obtains all sals that correspond
5551 to the same file and line as SAL. This is done
5552 only if SAL does not have explicit PC and has
5553 line and file information. If we got just a single
5554 expanded sal, return the original.
5556 Otherwise, if SAL.explicit_line is not set, filter out
5557 all sals for which the name of enclosing function
5558 is different from SAL. This makes sure that if we have
5559 breakpoint originally set in template instantiation, say
5560 foo<int>(), we won't expand SAL to locations at the same
5561 line in all existing instantiations of 'foo'.
5564 static struct symtabs_and_lines
5565 expand_line_sal_maybe (struct symtab_and_line sal
)
5567 struct symtabs_and_lines expanded
;
5568 CORE_ADDR original_pc
= sal
.pc
;
5569 char *original_function
= NULL
;
5573 /* If we have explicit pc, don't expand.
5574 If we have no line number, we can't expand. */
5575 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5578 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5579 expanded
.sals
[0] = sal
;
5584 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5586 expanded
= expand_line_sal (sal
);
5587 if (expanded
.nelts
== 1)
5589 /* We had one sal, we got one sal. Without futher
5590 processing, just return the original sal. */
5591 xfree (expanded
.sals
);
5593 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5594 sal
.pc
= original_pc
;
5595 expanded
.sals
[0] = sal
;
5599 if (!sal
.explicit_line
)
5601 CORE_ADDR func_addr
, func_end
;
5602 for (i
= 0; i
< expanded
.nelts
; ++i
)
5604 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5605 char *this_function
;
5606 if (find_pc_partial_function (pc
, &this_function
,
5607 &func_addr
, &func_end
))
5610 && strcmp (this_function
, original_function
) != 0)
5612 remove_sal (&expanded
, i
);
5615 else if (func_addr
== pc
)
5617 /* We're at beginning of a function, and should
5619 struct symbol
*sym
= find_pc_function (pc
);
5621 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5624 /* Since find_pc_partial_function returned true,
5625 we should really always find the section here. */
5626 struct obj_section
*section
= find_pc_section (pc
);
5629 struct gdbarch
*gdbarch
5630 = get_objfile_arch (section
->objfile
);
5632 = gdbarch_skip_prologue (gdbarch
, pc
);
5641 for (i
= 0; i
< expanded
.nelts
; ++i
)
5643 /* If this SAL corresponds to a breakpoint inserted using a
5644 line number, then skip the function prologue if necessary. */
5645 skip_prologue_sal (&expanded
.sals
[i
]);
5650 if (expanded
.nelts
<= 1)
5652 /* This is un ugly workaround. If we get zero
5653 expanded sals then something is really wrong.
5654 Fix that by returnign the original sal. */
5655 xfree (expanded
.sals
);
5657 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5658 sal
.pc
= original_pc
;
5659 expanded
.sals
[0] = sal
;
5666 for (i
= 0; i
< expanded
.nelts
; ++i
)
5667 if (expanded
.sals
[i
].pc
== original_pc
)
5678 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5679 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5680 value. COND_STRING, if not NULL, specified the condition to be
5681 used for all breakpoints. Essentially the only case where
5682 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5683 function. In that case, it's still not possible to specify
5684 separate conditions for different overloaded functions, so
5685 we take just a single condition string.
5687 NOTE: If the function succeeds, the caller is expected to cleanup
5688 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5689 array contents). If the function fails (error() is called), the
5690 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5691 COND and SALS arrays and each of those arrays contents. */
5694 create_breakpoints (struct gdbarch
*gdbarch
,
5695 struct symtabs_and_lines sals
, char **addr_string
,
5697 enum bptype type
, enum bpdisp disposition
,
5698 int thread
, int task
, int ignore_count
,
5699 struct breakpoint_ops
*ops
, int from_tty
,
5703 for (i
= 0; i
< sals
.nelts
; ++i
)
5705 struct symtabs_and_lines expanded
=
5706 expand_line_sal_maybe (sals
.sals
[i
]);
5708 create_breakpoint (gdbarch
, expanded
, addr_string
[i
],
5709 cond_string
, type
, disposition
,
5710 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
5714 /* Parse ARG which is assumed to be a SAL specification possibly
5715 followed by conditionals. On return, SALS contains an array of SAL
5716 addresses found. ADDR_STRING contains a vector of (canonical)
5717 address strings. ARG points to the end of the SAL. */
5720 parse_breakpoint_sals (char **address
,
5721 struct symtabs_and_lines
*sals
,
5722 char ***addr_string
,
5725 char *addr_start
= *address
;
5726 *addr_string
= NULL
;
5727 /* If no arg given, or if first arg is 'if ', use the default
5729 if ((*address
) == NULL
5730 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5732 if (default_breakpoint_valid
)
5734 struct symtab_and_line sal
;
5735 init_sal (&sal
); /* initialize to zeroes */
5736 sals
->sals
= (struct symtab_and_line
*)
5737 xmalloc (sizeof (struct symtab_and_line
));
5738 sal
.pc
= default_breakpoint_address
;
5739 sal
.line
= default_breakpoint_line
;
5740 sal
.symtab
= default_breakpoint_symtab
;
5741 sal
.section
= find_pc_overlay (sal
.pc
);
5743 /* "break" without arguments is equivalent to "break *PC" where PC is
5744 the default_breakpoint_address. So make sure to set
5745 sal.explicit_pc to prevent GDB from trying to expand the list of
5746 sals to include all other instances with the same symtab and line.
5748 sal
.explicit_pc
= 1;
5750 sals
->sals
[0] = sal
;
5754 error (_("No default breakpoint address now."));
5758 /* Force almost all breakpoints to be in terms of the
5759 current_source_symtab (which is decode_line_1's default). This
5760 should produce the results we want almost all of the time while
5761 leaving default_breakpoint_* alone.
5762 ObjC: However, don't match an Objective-C method name which
5763 may have a '+' or '-' succeeded by a '[' */
5765 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5767 if (default_breakpoint_valid
5769 || ((strchr ("+-", (*address
)[0]) != NULL
)
5770 && ((*address
)[1] != '['))))
5771 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5772 default_breakpoint_line
, addr_string
,
5775 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5776 addr_string
, not_found_ptr
);
5778 /* For any SAL that didn't have a canonical string, fill one in. */
5779 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5780 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5781 if (addr_start
!= (*address
))
5784 for (i
= 0; i
< sals
->nelts
; i
++)
5786 /* Add the string if not present. */
5787 if ((*addr_string
)[i
] == NULL
)
5788 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5794 /* Convert each SAL into a real PC. Verify that the PC can be
5795 inserted as a breakpoint. If it can't throw an error. */
5798 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5802 for (i
= 0; i
< sals
->nelts
; i
++)
5803 resolve_sal_pc (&sals
->sals
[i
]);
5807 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5809 struct captured_parse_breakpoint_args
*args
= data
;
5811 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5812 args
->not_found_ptr
);
5815 /* Given TOK, a string specification of condition and thread, as
5816 accepted by the 'break' command, extract the condition
5817 string and thread number and set *COND_STRING and *THREAD.
5818 PC identifies the context at which the condition should be parsed.
5819 If no condition is found, *COND_STRING is set to NULL.
5820 If no thread is found, *THREAD is set to -1. */
5822 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5823 char **cond_string
, int *thread
, int *task
)
5825 *cond_string
= NULL
;
5831 char *cond_start
= NULL
;
5832 char *cond_end
= NULL
;
5833 while (*tok
== ' ' || *tok
== '\t')
5838 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5841 toklen
= end_tok
- tok
;
5843 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5845 struct expression
*expr
;
5847 tok
= cond_start
= end_tok
+ 1;
5848 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5851 *cond_string
= savestring (cond_start
,
5852 cond_end
- cond_start
);
5854 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5860 *thread
= strtol (tok
, &tok
, 0);
5862 error (_("Junk after thread keyword."));
5863 if (!valid_thread_id (*thread
))
5864 error (_("Unknown thread %d."), *thread
);
5866 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
5872 *task
= strtol (tok
, &tok
, 0);
5874 error (_("Junk after task keyword."));
5875 if (!valid_task_id (*task
))
5876 error (_("Unknown task %d\n"), *task
);
5879 error (_("Junk at end of arguments."));
5883 /* Set a breakpoint. This function is shared between
5884 CLI and MI functions for setting a breakpoint.
5885 This function has two major modes of operations,
5886 selected by the PARSE_CONDITION_AND_THREAD parameter.
5887 If non-zero, the function will parse arg, extracting
5888 breakpoint location, address and thread. Otherwise,
5889 ARG is just the location of breakpoint, with condition
5890 and thread specified by the COND_STRING and THREAD
5894 break_command_really (struct gdbarch
*gdbarch
,
5895 char *arg
, char *cond_string
, int thread
,
5896 int parse_condition_and_thread
,
5897 int tempflag
, int hardwareflag
, int traceflag
,
5899 enum auto_boolean pending_break_support
,
5900 struct breakpoint_ops
*ops
,
5904 struct gdb_exception e
;
5905 struct symtabs_and_lines sals
;
5906 struct symtab_and_line pending_sal
;
5909 char *addr_start
= arg
;
5911 struct cleanup
*old_chain
;
5912 struct cleanup
*bkpt_chain
= NULL
;
5913 struct captured_parse_breakpoint_args parse_args
;
5917 enum bptype type_wanted
;
5924 parse_args
.arg_p
= &arg
;
5925 parse_args
.sals_p
= &sals
;
5926 parse_args
.addr_string_p
= &addr_string
;
5927 parse_args
.not_found_ptr
= ¬_found
;
5929 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5930 &parse_args
, RETURN_MASK_ALL
);
5932 /* If caller is interested in rc value from parse, set value. */
5936 throw_exception (e
);
5940 case NOT_FOUND_ERROR
:
5942 /* If pending breakpoint support is turned off, throw
5945 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5946 throw_exception (e
);
5948 exception_print (gdb_stderr
, e
);
5950 /* If pending breakpoint support is auto query and the user
5951 selects no, then simply return the error code. */
5952 if (pending_break_support
== AUTO_BOOLEAN_AUTO
5953 && !nquery ("Make breakpoint pending on future shared library load? "))
5956 /* At this point, either the user was queried about setting
5957 a pending breakpoint and selected yes, or pending
5958 breakpoint behavior is on and thus a pending breakpoint
5959 is defaulted on behalf of the user. */
5960 copy_arg
= xstrdup (addr_start
);
5961 addr_string
= ©_arg
;
5963 sals
.sals
= &pending_sal
;
5968 throw_exception (e
);
5975 /* Create a chain of things that always need to be cleaned up. */
5976 old_chain
= make_cleanup (null_cleanup
, 0);
5980 /* Make sure that all storage allocated to SALS gets freed. */
5981 make_cleanup (xfree
, sals
.sals
);
5983 /* Cleanup the addr_string array but not its contents. */
5984 make_cleanup (xfree
, addr_string
);
5987 /* ----------------------------- SNIP -----------------------------
5988 Anything added to the cleanup chain beyond this point is assumed
5989 to be part of a breakpoint. If the breakpoint create succeeds
5990 then the memory is not reclaimed. */
5991 bkpt_chain
= make_cleanup (null_cleanup
, 0);
5993 /* Mark the contents of the addr_string for cleanup. These go on
5994 the bkpt_chain and only occur if the breakpoint create fails. */
5995 for (i
= 0; i
< sals
.nelts
; i
++)
5997 if (addr_string
[i
] != NULL
)
5998 make_cleanup (xfree
, addr_string
[i
]);
6001 /* Resolve all line numbers to PC's and verify that the addresses
6002 are ok for the target. */
6004 breakpoint_sals_to_pc (&sals
, addr_start
);
6006 type_wanted
= (traceflag
6008 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
6010 /* Verify that condition can be parsed, before setting any
6011 breakpoints. Allocate a separate condition expression for each
6015 if (parse_condition_and_thread
)
6017 /* Here we only parse 'arg' to separate condition
6018 from thread number, so parsing in context of first
6019 sal is OK. When setting the breakpoint we'll
6020 re-parse it in context of each sal. */
6023 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
6026 make_cleanup (xfree
, cond_string
);
6030 /* Create a private copy of condition string. */
6033 cond_string
= xstrdup (cond_string
);
6034 make_cleanup (xfree
, cond_string
);
6037 create_breakpoints (gdbarch
, sals
, addr_string
, cond_string
, type_wanted
,
6038 tempflag
? disp_del
: disp_donttouch
,
6039 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
6043 struct symtab_and_line sal
= {0};
6044 struct breakpoint
*b
;
6046 make_cleanup (xfree
, copy_arg
);
6048 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
6049 set_breakpoint_count (breakpoint_count
+ 1);
6050 b
->number
= breakpoint_count
;
6052 b
->addr_string
= addr_string
[0];
6053 b
->cond_string
= NULL
;
6054 b
->ignore_count
= ignore_count
;
6055 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6056 b
->condition_not_parsed
= 1;
6058 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6060 if (enabled
&& executing_startup
6061 && (b
->type
== bp_breakpoint
6062 || b
->type
== bp_hardware_breakpoint
))
6063 b
->enable_state
= bp_startup_disabled
;
6069 warning (_("Multiple breakpoints were set.\n"
6070 "Use the \"delete\" command to delete unwanted breakpoints."));
6071 /* That's it. Discard the cleanups for data inserted into the
6073 discard_cleanups (bkpt_chain
);
6074 /* But cleanup everything else. */
6075 do_cleanups (old_chain
);
6077 /* error call may happen here - have BKPT_CHAIN already discarded. */
6078 update_global_location_list (1);
6081 /* Set a breakpoint.
6082 ARG is a string describing breakpoint address,
6083 condition, and thread.
6084 FLAG specifies if a breakpoint is hardware on,
6085 and if breakpoint is temporary, using BP_HARDWARE_FLAG
6089 break_command_1 (char *arg
, int flag
, int from_tty
)
6091 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
6092 int tempflag
= flag
& BP_TEMPFLAG
;
6094 break_command_really (get_current_arch (),
6096 NULL
, 0, 1 /* parse arg */,
6097 tempflag
, hardwareflag
, 0 /* traceflag */,
6098 0 /* Ignore count */,
6099 pending_break_support
,
6100 NULL
/* breakpoint_ops */,
6107 set_breakpoint (struct gdbarch
*gdbarch
,
6108 char *address
, char *condition
,
6109 int hardwareflag
, int tempflag
,
6110 int thread
, int ignore_count
,
6111 int pending
, int enabled
)
6113 break_command_really (gdbarch
,
6114 address
, condition
, thread
,
6115 0 /* condition and thread are valid. */,
6116 tempflag
, hardwareflag
, 0 /* traceflag */,
6119 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
6123 /* Adjust SAL to the first instruction past the function prologue.
6124 The end of the prologue is determined using the line table from
6125 the debugging information. explicit_pc and explicit_line are
6128 If SAL is already past the prologue, then do nothing. */
6131 skip_prologue_sal (struct symtab_and_line
*sal
)
6133 struct symbol
*sym
= find_pc_function (sal
->pc
);
6134 struct symtab_and_line start_sal
;
6139 start_sal
= find_function_start_sal (sym
, 1);
6140 if (sal
->pc
< start_sal
.pc
)
6142 start_sal
.explicit_line
= sal
->explicit_line
;
6143 start_sal
.explicit_pc
= sal
->explicit_pc
;
6148 /* Helper function for break_command_1 and disassemble_command. */
6151 resolve_sal_pc (struct symtab_and_line
*sal
)
6155 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
6157 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
6158 error (_("No line %d in file \"%s\"."),
6159 sal
->line
, sal
->symtab
->filename
);
6162 /* If this SAL corresponds to a breakpoint inserted using
6163 a line number, then skip the function prologue if necessary. */
6164 if (sal
->explicit_line
)
6166 /* Preserve the original line number. */
6167 int saved_line
= sal
->line
;
6168 skip_prologue_sal (sal
);
6169 sal
->line
= saved_line
;
6173 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
6175 struct blockvector
*bv
;
6179 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
6182 sym
= block_linkage_function (b
);
6185 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
6186 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
6190 /* It really is worthwhile to have the section, so we'll just
6191 have to look harder. This case can be executed if we have
6192 line numbers but no functions (as can happen in assembly
6195 struct minimal_symbol
*msym
;
6197 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
6199 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
6206 break_command (char *arg
, int from_tty
)
6208 break_command_1 (arg
, 0, from_tty
);
6212 tbreak_command (char *arg
, int from_tty
)
6214 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
6218 hbreak_command (char *arg
, int from_tty
)
6220 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
6224 thbreak_command (char *arg
, int from_tty
)
6226 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
6230 stop_command (char *arg
, int from_tty
)
6232 printf_filtered (_("Specify the type of breakpoint to set.\n\
6233 Usage: stop in <function | address>\n\
6234 stop at <line>\n"));
6238 stopin_command (char *arg
, int from_tty
)
6242 if (arg
== (char *) NULL
)
6244 else if (*arg
!= '*')
6249 /* look for a ':'. If this is a line number specification, then
6250 say it is bad, otherwise, it should be an address or
6251 function/method name */
6252 while (*argptr
&& !hasColon
)
6254 hasColon
= (*argptr
== ':');
6259 badInput
= (*argptr
!= ':'); /* Not a class::method */
6261 badInput
= isdigit (*arg
); /* a simple line number */
6265 printf_filtered (_("Usage: stop in <function | address>\n"));
6267 break_command_1 (arg
, 0, from_tty
);
6271 stopat_command (char *arg
, int from_tty
)
6275 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
6282 /* look for a ':'. If there is a '::' then get out, otherwise
6283 it is probably a line number. */
6284 while (*argptr
&& !hasColon
)
6286 hasColon
= (*argptr
== ':');
6291 badInput
= (*argptr
== ':'); /* we have class::method */
6293 badInput
= !isdigit (*arg
); /* not a line number */
6297 printf_filtered (_("Usage: stop at <line>\n"));
6299 break_command_1 (arg
, 0, from_tty
);
6302 /* accessflag: hw_write: watch write,
6303 hw_read: watch read,
6304 hw_access: watch access (read or write) */
6306 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
6308 struct gdbarch
*gdbarch
= get_current_arch ();
6309 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
6310 struct symtab_and_line sal
;
6311 struct expression
*exp
;
6312 struct block
*exp_valid_block
;
6313 struct value
*val
, *mark
;
6314 struct frame_info
*frame
;
6315 char *exp_start
= NULL
;
6316 char *exp_end
= NULL
;
6317 char *tok
, *id_tok_start
, *end_tok
;
6319 char *cond_start
= NULL
;
6320 char *cond_end
= NULL
;
6321 struct expression
*cond
= NULL
;
6322 int i
, other_type_used
, target_resources_ok
= 0;
6323 enum bptype bp_type
;
6327 init_sal (&sal
); /* initialize to zeroes */
6329 /* Make sure that we actually have parameters to parse. */
6330 if (arg
!= NULL
&& arg
[0] != '\0')
6332 toklen
= strlen (arg
); /* Size of argument list. */
6334 /* Points tok to the end of the argument list. */
6335 tok
= arg
+ toklen
- 1;
6337 /* Go backwards in the parameters list. Skip the last parameter.
6338 If we're expecting a 'thread <thread_num>' parameter, this should
6339 be the thread identifier. */
6340 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6342 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6345 /* Points end_tok to the beginning of the last token. */
6346 id_tok_start
= tok
+ 1;
6348 /* Go backwards in the parameters list. Skip one more parameter.
6349 If we're expecting a 'thread <thread_num>' parameter, we should
6350 reach a "thread" token. */
6351 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6356 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6359 /* Move the pointer forward to skip the whitespace and
6360 calculate the length of the token. */
6362 toklen
= end_tok
- tok
;
6364 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
6366 /* At this point we've found a "thread" token, which means
6367 the user is trying to set a watchpoint that triggers
6368 only in a specific thread. */
6371 /* Extract the thread ID from the next token. */
6372 thread
= strtol (id_tok_start
, &endp
, 0);
6374 /* Check if the user provided a valid numeric value for the
6376 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
6377 error (_("Invalid thread ID specification %s."), id_tok_start
);
6379 /* Check if the thread actually exists. */
6380 if (!valid_thread_id (thread
))
6381 error (_("Unknown thread %d."), thread
);
6383 /* Truncate the string and get rid of the thread <thread_num>
6384 parameter before the parameter list is parsed by the
6385 evaluate_expression() function. */
6390 /* Parse the rest of the arguments. */
6391 innermost_block
= NULL
;
6393 exp
= parse_exp_1 (&arg
, 0, 0);
6395 /* Remove trailing whitespace from the expression before saving it.
6396 This makes the eventual display of the expression string a bit
6398 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
6401 exp_valid_block
= innermost_block
;
6402 mark
= value_mark ();
6403 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
6405 release_value (val
);
6408 while (*tok
== ' ' || *tok
== '\t')
6412 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6415 toklen
= end_tok
- tok
;
6416 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6418 tok
= cond_start
= end_tok
+ 1;
6419 cond
= parse_exp_1 (&tok
, 0, 0);
6423 error (_("Junk at end of command."));
6425 if (accessflag
== hw_read
)
6426 bp_type
= bp_read_watchpoint
;
6427 else if (accessflag
== hw_access
)
6428 bp_type
= bp_access_watchpoint
;
6430 bp_type
= bp_hardware_watchpoint
;
6432 mem_cnt
= can_use_hardware_watchpoint (val
);
6433 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
6434 error (_("Expression cannot be implemented with read/access watchpoint."));
6437 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
6438 target_resources_ok
=
6439 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
6441 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
6442 error (_("Target does not support this type of hardware watchpoint."));
6444 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
6445 error (_("Target can only support one kind of HW watchpoint at a time."));
6448 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6449 watchpoint could not be set. */
6450 if (!mem_cnt
|| target_resources_ok
<= 0)
6451 bp_type
= bp_watchpoint
;
6453 frame
= block_innermost_frame (exp_valid_block
);
6455 /* If the expression is "local", then set up a "watchpoint scope"
6456 breakpoint at the point where we've left the scope of the watchpoint
6457 expression. Create the scope breakpoint before the watchpoint, so
6458 that we will encounter it first in bpstat_stop_status. */
6459 if (innermost_block
&& frame
)
6461 if (frame_id_p (frame_unwind_caller_id (frame
)))
6464 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
6465 frame_unwind_caller_pc (frame
),
6466 bp_watchpoint_scope
);
6468 scope_breakpoint
->enable_state
= bp_enabled
;
6470 /* Automatically delete the breakpoint when it hits. */
6471 scope_breakpoint
->disposition
= disp_del
;
6473 /* Only break in the proper frame (help with recursion). */
6474 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
6476 /* Set the address at which we will stop. */
6477 scope_breakpoint
->loc
->gdbarch
6478 = frame_unwind_caller_arch (frame
);
6479 scope_breakpoint
->loc
->requested_address
6480 = frame_unwind_caller_pc (frame
);
6481 scope_breakpoint
->loc
->address
6482 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
6483 scope_breakpoint
->loc
->requested_address
,
6484 scope_breakpoint
->type
);
6488 /* Now set up the breakpoint. */
6489 b
= set_raw_breakpoint (gdbarch
, sal
, bp_type
);
6490 set_breakpoint_count (breakpoint_count
+ 1);
6491 b
->number
= breakpoint_count
;
6493 b
->disposition
= disp_donttouch
;
6495 b
->exp_valid_block
= exp_valid_block
;
6496 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6499 b
->loc
->cond
= cond
;
6501 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6506 b
->watchpoint_frame
= get_frame_id (frame
);
6508 b
->watchpoint_frame
= null_frame_id
;
6510 if (scope_breakpoint
!= NULL
)
6512 /* The scope breakpoint is related to the watchpoint. We will
6513 need to act on them together. */
6514 b
->related_breakpoint
= scope_breakpoint
;
6515 scope_breakpoint
->related_breakpoint
= b
;
6518 value_free_to_mark (mark
);
6520 update_global_location_list (1);
6523 /* Return count of locations need to be watched and can be handled
6524 in hardware. If the watchpoint can not be handled
6525 in hardware return zero. */
6528 can_use_hardware_watchpoint (struct value
*v
)
6530 int found_memory_cnt
= 0;
6531 struct value
*head
= v
;
6533 /* Did the user specifically forbid us to use hardware watchpoints? */
6534 if (!can_use_hw_watchpoints
)
6537 /* Make sure that the value of the expression depends only upon
6538 memory contents, and values computed from them within GDB. If we
6539 find any register references or function calls, we can't use a
6540 hardware watchpoint.
6542 The idea here is that evaluating an expression generates a series
6543 of values, one holding the value of every subexpression. (The
6544 expression a*b+c has five subexpressions: a, b, a*b, c, and
6545 a*b+c.) GDB's values hold almost enough information to establish
6546 the criteria given above --- they identify memory lvalues,
6547 register lvalues, computed values, etcetera. So we can evaluate
6548 the expression, and then scan the chain of values that leaves
6549 behind to decide whether we can detect any possible change to the
6550 expression's final value using only hardware watchpoints.
6552 However, I don't think that the values returned by inferior
6553 function calls are special in any way. So this function may not
6554 notice that an expression involving an inferior function call
6555 can't be watched with hardware watchpoints. FIXME. */
6556 for (; v
; v
= value_next (v
))
6558 if (VALUE_LVAL (v
) == lval_memory
)
6561 /* A lazy memory lvalue is one that GDB never needed to fetch;
6562 we either just used its address (e.g., `a' in `a.b') or
6563 we never needed it at all (e.g., `a' in `a,b'). */
6567 /* Ahh, memory we actually used! Check if we can cover
6568 it with hardware watchpoints. */
6569 struct type
*vtype
= check_typedef (value_type (v
));
6571 /* We only watch structs and arrays if user asked for it
6572 explicitly, never if they just happen to appear in a
6573 middle of some value chain. */
6575 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6576 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6578 CORE_ADDR vaddr
= value_address (v
);
6579 int len
= TYPE_LENGTH (value_type (v
));
6581 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
6588 else if (VALUE_LVAL (v
) != not_lval
6589 && deprecated_value_modifiable (v
) == 0)
6590 return 0; /* ??? What does this represent? */
6591 else if (VALUE_LVAL (v
) == lval_register
)
6592 return 0; /* cannot watch a register with a HW watchpoint */
6595 /* The expression itself looks suitable for using a hardware
6596 watchpoint, but give the target machine a chance to reject it. */
6597 return found_memory_cnt
;
6601 watch_command_wrapper (char *arg
, int from_tty
)
6603 watch_command (arg
, from_tty
);
6607 watch_command (char *arg
, int from_tty
)
6609 watch_command_1 (arg
, hw_write
, from_tty
);
6613 rwatch_command_wrapper (char *arg
, int from_tty
)
6615 rwatch_command (arg
, from_tty
);
6619 rwatch_command (char *arg
, int from_tty
)
6621 watch_command_1 (arg
, hw_read
, from_tty
);
6625 awatch_command_wrapper (char *arg
, int from_tty
)
6627 awatch_command (arg
, from_tty
);
6631 awatch_command (char *arg
, int from_tty
)
6633 watch_command_1 (arg
, hw_access
, from_tty
);
6637 /* Helper routines for the until_command routine in infcmd.c. Here
6638 because it uses the mechanisms of breakpoints. */
6640 struct until_break_command_continuation_args
6642 struct breakpoint
*breakpoint
;
6643 struct breakpoint
*breakpoint2
;
6646 /* This function is called by fetch_inferior_event via the
6647 cmd_continuation pointer, to complete the until command. It takes
6648 care of cleaning up the temporary breakpoints set up by the until
6651 until_break_command_continuation (void *arg
)
6653 struct until_break_command_continuation_args
*a
= arg
;
6655 delete_breakpoint (a
->breakpoint
);
6657 delete_breakpoint (a
->breakpoint2
);
6661 until_break_command (char *arg
, int from_tty
, int anywhere
)
6663 struct symtabs_and_lines sals
;
6664 struct symtab_and_line sal
;
6665 struct frame_info
*frame
= get_selected_frame (NULL
);
6666 struct breakpoint
*breakpoint
;
6667 struct breakpoint
*breakpoint2
= NULL
;
6668 struct cleanup
*old_chain
;
6670 clear_proceed_status ();
6672 /* Set a breakpoint where the user wants it and at return from
6675 if (default_breakpoint_valid
)
6676 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6677 default_breakpoint_line
, (char ***) NULL
, NULL
);
6679 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6680 0, (char ***) NULL
, NULL
);
6682 if (sals
.nelts
!= 1)
6683 error (_("Couldn't get information on specified line."));
6686 xfree (sals
.sals
); /* malloc'd, so freed */
6689 error (_("Junk at end of arguments."));
6691 resolve_sal_pc (&sal
);
6694 /* If the user told us to continue until a specified location,
6695 we don't specify a frame at which we need to stop. */
6696 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
6697 null_frame_id
, bp_until
);
6699 /* Otherwise, specify the selected frame, because we want to stop only
6700 at the very same frame. */
6701 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
6702 get_stack_frame_id (frame
),
6705 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6707 /* Keep within the current frame, or in frames called by the current
6710 if (frame_id_p (frame_unwind_caller_id (frame
)))
6712 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
6713 sal
.pc
= frame_unwind_caller_pc (frame
);
6714 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
6716 frame_unwind_caller_id (frame
),
6718 make_cleanup_delete_breakpoint (breakpoint2
);
6721 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6723 /* If we are running asynchronously, and proceed call above has actually
6724 managed to start the target, arrange for breakpoints to be
6725 deleted when the target stops. Otherwise, we're already stopped and
6726 delete breakpoints via cleanup chain. */
6728 if (target_can_async_p () && is_running (inferior_ptid
))
6730 struct until_break_command_continuation_args
*args
;
6731 args
= xmalloc (sizeof (*args
));
6733 args
->breakpoint
= breakpoint
;
6734 args
->breakpoint2
= breakpoint2
;
6736 discard_cleanups (old_chain
);
6737 add_continuation (inferior_thread (),
6738 until_break_command_continuation
, args
,
6742 do_cleanups (old_chain
);
6746 ep_skip_leading_whitespace (char **s
)
6748 if ((s
== NULL
) || (*s
== NULL
))
6750 while (isspace (**s
))
6754 /* This function attempts to parse an optional "if <cond>" clause
6755 from the arg string. If one is not found, it returns NULL.
6757 Else, it returns a pointer to the condition string. (It does not
6758 attempt to evaluate the string against a particular block.) And,
6759 it updates arg to point to the first character following the parsed
6760 if clause in the arg string. */
6763 ep_parse_optional_if_clause (char **arg
)
6767 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6770 /* Skip the "if" keyword. */
6773 /* Skip any extra leading whitespace, and record the start of the
6774 condition string. */
6775 ep_skip_leading_whitespace (arg
);
6778 /* Assume that the condition occupies the remainder of the arg string. */
6779 (*arg
) += strlen (cond_string
);
6784 /* This function attempts to parse an optional filename from the arg
6785 string. If one is not found, it returns NULL.
6787 Else, it returns a pointer to the parsed filename. (This function
6788 makes no attempt to verify that a file of that name exists, or is
6789 accessible.) And, it updates arg to point to the first character
6790 following the parsed filename in the arg string.
6792 Note that clients needing to preserve the returned filename for
6793 future access should copy it to their own buffers. */
6795 ep_parse_optional_filename (char **arg
)
6797 static char filename
[1024];
6802 if ((*arg_p
== '\0') || isspace (*arg_p
))
6820 /* Commands to deal with catching events, such as signals, exceptions,
6821 process start/exit, etc. */
6825 catch_fork_temporary
, catch_vfork_temporary
,
6826 catch_fork_permanent
, catch_vfork_permanent
6831 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6833 struct gdbarch
*gdbarch
= get_current_arch ();
6834 char *cond_string
= NULL
;
6835 catch_fork_kind fork_kind
;
6838 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6839 tempflag
= (fork_kind
== catch_fork_temporary
6840 || fork_kind
== catch_vfork_temporary
);
6844 ep_skip_leading_whitespace (&arg
);
6846 /* The allowed syntax is:
6848 catch [v]fork if <cond>
6850 First, check if there's an if clause. */
6851 cond_string
= ep_parse_optional_if_clause (&arg
);
6853 if ((*arg
!= '\0') && !isspace (*arg
))
6854 error (_("Junk at end of arguments."));
6856 /* If this target supports it, create a fork or vfork catchpoint
6857 and enable reporting of such events. */
6860 case catch_fork_temporary
:
6861 case catch_fork_permanent
:
6862 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
6863 &catch_fork_breakpoint_ops
);
6865 case catch_vfork_temporary
:
6866 case catch_vfork_permanent
:
6867 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
6868 &catch_vfork_breakpoint_ops
);
6871 error (_("unsupported or unknown fork kind; cannot catch it"));
6877 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6879 struct gdbarch
*gdbarch
= get_current_arch ();
6881 char *cond_string
= NULL
;
6883 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6887 ep_skip_leading_whitespace (&arg
);
6889 /* The allowed syntax is:
6891 catch exec if <cond>
6893 First, check if there's an if clause. */
6894 cond_string
= ep_parse_optional_if_clause (&arg
);
6896 if ((*arg
!= '\0') && !isspace (*arg
))
6897 error (_("Junk at end of arguments."));
6899 /* If this target supports it, create an exec catchpoint
6900 and enable reporting of such events. */
6901 create_catchpoint (gdbarch
, tempflag
, cond_string
,
6902 &catch_exec_breakpoint_ops
);
6905 static enum print_stop_action
6906 print_exception_catchpoint (struct breakpoint
*b
)
6908 int bp_temp
, bp_throw
;
6910 annotate_catchpoint (b
->number
);
6912 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6913 if (b
->loc
->address
!= b
->loc
->requested_address
)
6914 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6917 bp_temp
= b
->disposition
== disp_del
;
6919 bp_temp
? "Temporary catchpoint "
6921 if (!ui_out_is_mi_like_p (uiout
))
6922 ui_out_field_int (uiout
, "bkptno", b
->number
);
6924 bp_throw
? " (exception thrown), "
6925 : " (exception caught), ");
6926 if (ui_out_is_mi_like_p (uiout
))
6928 ui_out_field_string (uiout
, "reason",
6929 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6930 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6931 ui_out_field_int (uiout
, "bkptno", b
->number
);
6933 return PRINT_SRC_AND_LOC
;
6937 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
6939 struct value_print_options opts
;
6940 get_user_print_options (&opts
);
6941 if (opts
.addressprint
)
6944 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6945 ui_out_field_string (uiout
, "addr", "<PENDING>");
6947 ui_out_field_core_addr (uiout
, "addr",
6948 b
->loc
->gdbarch
, b
->loc
->address
);
6953 if (strstr (b
->addr_string
, "throw") != NULL
)
6954 ui_out_field_string (uiout
, "what", "exception throw");
6956 ui_out_field_string (uiout
, "what", "exception catch");
6960 print_mention_exception_catchpoint (struct breakpoint
*b
)
6965 bp_temp
= b
->disposition
== disp_del
;
6966 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6967 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6968 : _("Catchpoint "));
6969 ui_out_field_int (uiout
, "bkptno", b
->number
);
6970 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6974 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6977 NULL
, /* breakpoint_hit */
6978 print_exception_catchpoint
,
6979 print_one_exception_catchpoint
,
6980 print_mention_exception_catchpoint
6984 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6985 enum exception_event_kind ex_event
, int from_tty
)
6987 char *trigger_func_name
;
6989 if (ex_event
== EX_EVENT_CATCH
)
6990 trigger_func_name
= "__cxa_begin_catch";
6992 trigger_func_name
= "__cxa_throw";
6994 break_command_really (get_current_arch (),
6995 trigger_func_name
, cond_string
, -1,
6996 0 /* condition and thread are valid. */,
6999 AUTO_BOOLEAN_TRUE
/* pending */,
7000 &gnu_v3_exception_catchpoint_ops
, from_tty
,
7006 /* Deal with "catch catch" and "catch throw" commands */
7009 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
7010 int tempflag
, int from_tty
)
7012 char *cond_string
= NULL
;
7013 struct symtab_and_line
*sal
= NULL
;
7017 ep_skip_leading_whitespace (&arg
);
7019 cond_string
= ep_parse_optional_if_clause (&arg
);
7021 if ((*arg
!= '\0') && !isspace (*arg
))
7022 error (_("Junk at end of arguments."));
7024 if (ex_event
!= EX_EVENT_THROW
7025 && ex_event
!= EX_EVENT_CATCH
)
7026 error (_("Unsupported or unknown exception event; cannot catch it"));
7028 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
7031 warning (_("Unsupported with this platform/compiler combination."));
7034 /* Implementation of "catch catch" command. */
7037 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7039 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7040 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
7043 /* Implementation of "catch throw" command. */
7046 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7048 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7049 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
7052 /* Create a breakpoint struct for Ada exception catchpoints. */
7055 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
7056 struct symtab_and_line sal
,
7060 struct expression
*cond
,
7061 struct breakpoint_ops
*ops
,
7065 struct breakpoint
*b
;
7069 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7071 loc_gdbarch
= gdbarch
;
7073 describe_other_breakpoints (loc_gdbarch
, sal
.pc
, sal
.section
, -1);
7074 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
7075 version for exception catchpoints, because two catchpoints
7076 used for different exception names will use the same address.
7077 In this case, a "breakpoint ... also set at..." warning is
7078 unproductive. Besides. the warning phrasing is also a bit
7079 inapropriate, we should use the word catchpoint, and tell
7080 the user what type of catchpoint it is. The above is good
7081 enough for now, though. */
7084 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
7085 set_breakpoint_count (breakpoint_count
+ 1);
7087 b
->enable_state
= bp_enabled
;
7088 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7089 b
->number
= breakpoint_count
;
7090 b
->ignore_count
= 0;
7091 b
->loc
->cond
= cond
;
7092 b
->addr_string
= addr_string
;
7093 b
->language
= language_ada
;
7094 b
->cond_string
= cond_string
;
7095 b
->exp_string
= exp_string
;
7100 update_global_location_list (1);
7103 /* Implement the "catch exception" command. */
7106 catch_ada_exception_command (char *arg
, int from_tty
,
7107 struct cmd_list_element
*command
)
7109 struct gdbarch
*gdbarch
= get_current_arch ();
7111 struct symtab_and_line sal
;
7113 char *addr_string
= NULL
;
7114 char *exp_string
= NULL
;
7115 char *cond_string
= NULL
;
7116 struct expression
*cond
= NULL
;
7117 struct breakpoint_ops
*ops
= NULL
;
7119 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7123 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
7124 &cond_string
, &cond
, &ops
);
7125 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
7126 cond_string
, cond
, ops
, tempflag
,
7130 /* Implement the "catch assert" command. */
7133 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
7135 struct gdbarch
*gdbarch
= get_current_arch ();
7137 struct symtab_and_line sal
;
7138 char *addr_string
= NULL
;
7139 struct breakpoint_ops
*ops
= NULL
;
7141 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7145 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
7146 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
7147 ops
, tempflag
, from_tty
);
7151 catch_command (char *arg
, int from_tty
)
7153 error (_("Catch requires an event name."));
7158 tcatch_command (char *arg
, int from_tty
)
7160 error (_("Catch requires an event name."));
7163 /* Delete breakpoints by address or line. */
7166 clear_command (char *arg
, int from_tty
)
7168 struct breakpoint
*b
;
7169 VEC(breakpoint_p
) *found
= 0;
7172 struct symtabs_and_lines sals
;
7173 struct symtab_and_line sal
;
7178 sals
= decode_line_spec (arg
, 1);
7183 sals
.sals
= (struct symtab_and_line
*)
7184 xmalloc (sizeof (struct symtab_and_line
));
7185 make_cleanup (xfree
, sals
.sals
);
7186 init_sal (&sal
); /* initialize to zeroes */
7187 sal
.line
= default_breakpoint_line
;
7188 sal
.symtab
= default_breakpoint_symtab
;
7189 sal
.pc
= default_breakpoint_address
;
7190 if (sal
.symtab
== 0)
7191 error (_("No source file specified."));
7199 /* We don't call resolve_sal_pc here. That's not
7200 as bad as it seems, because all existing breakpoints
7201 typically have both file/line and pc set. So, if
7202 clear is given file/line, we can match this to existing
7203 breakpoint without obtaining pc at all.
7205 We only support clearing given the address explicitly
7206 present in breakpoint table. Say, we've set breakpoint
7207 at file:line. There were several PC values for that file:line,
7208 due to optimization, all in one block.
7209 We've picked one PC value. If "clear" is issued with another
7210 PC corresponding to the same file:line, the breakpoint won't
7211 be cleared. We probably can still clear the breakpoint, but
7212 since the other PC value is never presented to user, user
7213 can only find it by guessing, and it does not seem important
7216 /* For each line spec given, delete bps which correspond
7217 to it. Do it in two passes, solely to preserve the current
7218 behavior that from_tty is forced true if we delete more than
7222 for (i
= 0; i
< sals
.nelts
; i
++)
7224 /* If exact pc given, clear bpts at that pc.
7225 If line given (pc == 0), clear all bpts on specified line.
7226 If defaulting, clear all bpts on default line
7229 defaulting sal.pc != 0 tests to do
7234 1 0 <can't happen> */
7238 /* Find all matching breakpoints and add them to
7243 /* Are we going to delete b? */
7244 if (b
->type
!= bp_none
7245 && b
->type
!= bp_watchpoint
7246 && b
->type
!= bp_hardware_watchpoint
7247 && b
->type
!= bp_read_watchpoint
7248 && b
->type
!= bp_access_watchpoint
)
7250 struct bp_location
*loc
= b
->loc
;
7251 for (; loc
; loc
= loc
->next
)
7253 int pc_match
= sal
.pc
7254 && (loc
->address
== sal
.pc
)
7255 && (!section_is_overlay (loc
->section
)
7256 || loc
->section
== sal
.section
);
7257 int line_match
= ((default_match
|| (0 == sal
.pc
))
7258 && b
->source_file
!= NULL
7259 && sal
.symtab
!= NULL
7260 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
7261 && b
->line_number
== sal
.line
);
7262 if (pc_match
|| line_match
)
7271 VEC_safe_push(breakpoint_p
, found
, b
);
7274 /* Now go thru the 'found' chain and delete them. */
7275 if (VEC_empty(breakpoint_p
, found
))
7278 error (_("No breakpoint at %s."), arg
);
7280 error (_("No breakpoint at this line."));
7283 if (VEC_length(breakpoint_p
, found
) > 1)
7284 from_tty
= 1; /* Always report if deleted more than one */
7287 if (VEC_length(breakpoint_p
, found
) == 1)
7288 printf_unfiltered (_("Deleted breakpoint "));
7290 printf_unfiltered (_("Deleted breakpoints "));
7292 breakpoints_changed ();
7294 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
7297 printf_unfiltered ("%d ", b
->number
);
7298 delete_breakpoint (b
);
7301 putchar_unfiltered ('\n');
7304 /* Delete breakpoint in BS if they are `delete' breakpoints and
7305 all breakpoints that are marked for deletion, whether hit or not.
7306 This is called after any breakpoint is hit, or after errors. */
7309 breakpoint_auto_delete (bpstat bs
)
7311 struct breakpoint
*b
, *temp
;
7313 for (; bs
; bs
= bs
->next
)
7314 if (bs
->breakpoint_at
7315 && bs
->breakpoint_at
->owner
7316 && bs
->breakpoint_at
->owner
->disposition
== disp_del
7318 delete_breakpoint (bs
->breakpoint_at
->owner
);
7320 ALL_BREAKPOINTS_SAFE (b
, temp
)
7322 if (b
->disposition
== disp_del_at_next_stop
)
7323 delete_breakpoint (b
);
7327 /* A cleanup function which destroys a vector. */
7330 do_vec_free (void *p
)
7332 VEC(bp_location_p
) **vec
= p
;
7334 VEC_free (bp_location_p
, *vec
);
7337 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
7338 into the inferior, only remove already-inserted locations that no
7339 longer should be inserted. Functions that delete a breakpoint or
7340 breakpoints should pass false, so that deleting a breakpoint
7341 doesn't have the side effect of inserting the locations of other
7342 breakpoints that are marked not-inserted, but should_be_inserted
7343 returns true on them.
7345 This behaviour is useful is situations close to tear-down -- e.g.,
7346 after an exec, while the target still has execution, but breakpoint
7347 shadows of the previous executable image should *NOT* be restored
7348 to the new image; or before detaching, where the target still has
7349 execution and wants to delete breakpoints from GDB's lists, and all
7350 breakpoints had already been removed from the inferior. */
7353 update_global_location_list (int should_insert
)
7355 struct breakpoint
*b
;
7356 struct bp_location
**next
= &bp_location_chain
;
7357 struct bp_location
*loc
;
7358 struct bp_location
*loc2
;
7359 VEC(bp_location_p
) *old_locations
= NULL
;
7362 struct cleanup
*cleanups
;
7364 cleanups
= make_cleanup (do_vec_free
, &old_locations
);
7365 /* Store old locations for future reference. */
7366 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7367 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7369 bp_location_chain
= NULL
;
7372 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7375 next
= &(loc
->global_next
);
7380 /* Identify bp_location instances that are no longer present in the new
7381 list, and therefore should be freed. Note that it's not necessary that
7382 those locations should be removed from inferior -- if there's another
7383 location at the same address (previously marked as duplicate),
7384 we don't need to remove/insert the location. */
7385 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7387 /* Tells if 'loc' is found amoung the new locations. If not, we
7389 int found_object
= 0;
7390 /* Tells if the location should remain inserted in the target. */
7391 int keep_in_target
= 0;
7393 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7400 /* If this location is no longer present, and inserted, look if there's
7401 maybe a new location at the same address. If so, mark that one
7402 inserted, and don't remove this one. This is needed so that we
7403 don't have a time window where a breakpoint at certain location is not
7408 /* If the location is inserted now, we might have to remove it. */
7410 if (found_object
&& should_be_inserted (loc
))
7412 /* The location is still present in the location list, and still
7413 should be inserted. Don't do anything. */
7418 /* The location is either no longer present, or got disabled.
7419 See if there's another location at the same address, in which
7420 case we don't need to remove this one from the target. */
7421 if (breakpoint_address_is_meaningful (loc
->owner
))
7422 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7424 /* For the sake of should_insert_location. The
7425 call to check_duplicates will fix up this later. */
7426 loc2
->duplicate
= 0;
7427 if (should_be_inserted (loc2
)
7428 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7431 loc2
->target_info
= loc
->target_info
;
7438 if (!keep_in_target
)
7440 if (remove_breakpoint (loc
, mark_uninserted
))
7442 /* This is just about all we can do. We could keep this
7443 location on the global list, and try to remove it next
7444 time, but there's no particular reason why we will
7447 Note that at this point, loc->owner is still valid,
7448 as delete_breakpoint frees the breakpoint only
7449 after calling us. */
7450 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7451 loc
->owner
->number
);
7459 if (removed
&& non_stop
)
7461 /* This location was removed from the targets. In non-stop mode,
7462 a race condition is possible where we've removed a breakpoint,
7463 but stop events for that breakpoint are already queued and will
7464 arrive later. To suppress spurious SIGTRAPs reported to user,
7465 we keep this breakpoint location for a bit, and will retire it
7466 after we see 3 * thread_count events.
7467 The theory here is that reporting of events should,
7468 "on the average", be fair, so after that many event we'll see
7469 events from all threads that have anything of interest, and no
7470 longer need to keep this breakpoint. This is just a
7471 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7472 which is usability issue, but not a correctness problem. */
7473 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7476 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
7479 free_bp_location (loc
);
7485 check_duplicates (b
);
7488 if (breakpoints_always_inserted_mode () && should_insert
7489 && (have_live_inferiors ()
7490 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
7491 insert_breakpoint_locations ();
7493 do_cleanups (cleanups
);
7497 breakpoint_retire_moribund (void)
7499 struct bp_location
*loc
;
7502 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7503 if (--(loc
->events_till_retirement
) == 0)
7505 free_bp_location (loc
);
7506 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7512 update_global_location_list_nothrow (int inserting
)
7514 struct gdb_exception e
;
7515 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7516 update_global_location_list (inserting
);
7519 /* Clear BPT from a BPS. */
7521 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7524 for (bs
= bps
; bs
; bs
= bs
->next
)
7525 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7527 bs
->breakpoint_at
= NULL
;
7529 /* bs->commands will be freed later. */
7533 /* Callback for iterate_over_threads. */
7535 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7537 struct breakpoint
*bpt
= data
;
7538 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7542 /* Delete a breakpoint and clean up all traces of it in the data
7546 delete_breakpoint (struct breakpoint
*bpt
)
7548 struct breakpoint
*b
;
7549 struct bp_location
*loc
, *next
;
7551 gdb_assert (bpt
!= NULL
);
7553 /* Has this bp already been deleted? This can happen because multiple
7554 lists can hold pointers to bp's. bpstat lists are especial culprits.
7556 One example of this happening is a watchpoint's scope bp. When the
7557 scope bp triggers, we notice that the watchpoint is out of scope, and
7558 delete it. We also delete its scope bp. But the scope bp is marked
7559 "auto-deleting", and is already on a bpstat. That bpstat is then
7560 checked for auto-deleting bp's, which are deleted.
7562 A real solution to this problem might involve reference counts in bp's,
7563 and/or giving them pointers back to their referencing bpstat's, and
7564 teaching delete_breakpoint to only free a bp's storage when no more
7565 references were extent. A cheaper bandaid was chosen. */
7566 if (bpt
->type
== bp_none
)
7569 observer_notify_breakpoint_deleted (bpt
->number
);
7571 if (breakpoint_chain
== bpt
)
7572 breakpoint_chain
= bpt
->next
;
7577 b
->next
= bpt
->next
;
7581 free_command_lines (&bpt
->commands
);
7582 if (bpt
->cond_string
!= NULL
)
7583 xfree (bpt
->cond_string
);
7584 if (bpt
->addr_string
!= NULL
)
7585 xfree (bpt
->addr_string
);
7586 if (bpt
->exp
!= NULL
)
7588 if (bpt
->exp_string
!= NULL
)
7589 xfree (bpt
->exp_string
);
7590 if (bpt
->val
!= NULL
)
7591 value_free (bpt
->val
);
7592 if (bpt
->source_file
!= NULL
)
7593 xfree (bpt
->source_file
);
7594 if (bpt
->exec_pathname
!= NULL
)
7595 xfree (bpt
->exec_pathname
);
7597 /* Be sure no bpstat's are pointing at it after it's been freed. */
7598 /* FIXME, how can we find all bpstat's?
7599 We just check stop_bpstat for now. Note that we cannot just
7600 remove bpstats pointing at bpt from the stop_bpstat list
7601 entirely, as breakpoint commands are associated with the bpstat;
7602 if we remove it here, then the later call to
7603 bpstat_do_actions (&stop_bpstat);
7604 in event-top.c won't do anything, and temporary breakpoints
7605 with commands won't work. */
7607 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7609 /* Now that breakpoint is removed from breakpoint
7610 list, update the global location list. This
7611 will remove locations that used to belong to
7612 this breakpoint. Do this before freeing
7613 the breakpoint itself, since remove_breakpoint
7614 looks at location's owner. It might be better
7615 design to have location completely self-contained,
7616 but it's not the case now. */
7617 update_global_location_list (0);
7620 /* On the chance that someone will soon try again to delete this same
7621 bp, we mark it as deleted before freeing its storage. */
7622 bpt
->type
= bp_none
;
7628 do_delete_breakpoint_cleanup (void *b
)
7630 delete_breakpoint (b
);
7634 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7636 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7640 delete_command (char *arg
, int from_tty
)
7642 struct breakpoint
*b
, *temp
;
7648 int breaks_to_delete
= 0;
7650 /* Delete all breakpoints if no argument.
7651 Do not delete internal or call-dummy breakpoints, these
7652 have to be deleted with an explicit breakpoint number argument. */
7655 if (b
->type
!= bp_call_dummy
7656 && b
->type
!= bp_shlib_event
7657 && b
->type
!= bp_thread_event
7658 && b
->type
!= bp_overlay_event
7659 && b
->type
!= bp_longjmp_master
7662 breaks_to_delete
= 1;
7667 /* Ask user only if there are some breakpoints to delete. */
7669 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7671 ALL_BREAKPOINTS_SAFE (b
, temp
)
7673 if (b
->type
!= bp_call_dummy
7674 && b
->type
!= bp_shlib_event
7675 && b
->type
!= bp_thread_event
7676 && b
->type
!= bp_overlay_event
7677 && b
->type
!= bp_longjmp_master
7679 delete_breakpoint (b
);
7684 map_breakpoint_numbers (arg
, delete_breakpoint
);
7688 all_locations_are_pending (struct bp_location
*loc
)
7690 for (; loc
; loc
= loc
->next
)
7691 if (!loc
->shlib_disabled
)
7696 /* Subroutine of update_breakpoint_locations to simplify it.
7697 Return non-zero if multiple fns in list LOC have the same name.
7698 Null names are ignored. */
7701 ambiguous_names_p (struct bp_location
*loc
)
7703 struct bp_location
*l
;
7704 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7705 (int (*) (const void *, const void *)) streq
,
7706 NULL
, xcalloc
, xfree
);
7708 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7711 const char *name
= l
->function_name
;
7713 /* Allow for some names to be NULL, ignore them. */
7717 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7719 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7734 update_breakpoint_locations (struct breakpoint
*b
,
7735 struct symtabs_and_lines sals
)
7739 struct bp_location
*existing_locations
= b
->loc
;
7741 /* If there's no new locations, and all existing locations
7742 are pending, don't do anything. This optimizes
7743 the common case where all locations are in the same
7744 shared library, that was unloaded. We'd like to
7745 retain the location, so that when the library
7746 is loaded again, we don't loose the enabled/disabled
7747 status of the individual locations. */
7748 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7753 for (i
= 0; i
< sals
.nelts
; ++i
)
7755 struct bp_location
*new_loc
=
7756 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
7758 /* Reparse conditions, they might contain references to the
7760 if (b
->cond_string
!= NULL
)
7762 struct gdb_exception e
;
7765 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7767 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7772 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7773 b
->number
, e
.message
);
7774 new_loc
->enabled
= 0;
7778 if (b
->source_file
!= NULL
)
7779 xfree (b
->source_file
);
7780 if (sals
.sals
[i
].symtab
== NULL
)
7781 b
->source_file
= NULL
;
7783 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
7785 if (b
->line_number
== 0)
7786 b
->line_number
= sals
.sals
[i
].line
;
7789 /* Update locations of permanent breakpoints. */
7790 if (b
->enable_state
== bp_permanent
)
7791 make_breakpoint_permanent (b
);
7793 /* If possible, carry over 'disable' status from existing breakpoints. */
7795 struct bp_location
*e
= existing_locations
;
7796 /* If there are multiple breakpoints with the same function name,
7797 e.g. for inline functions, comparing function names won't work.
7798 Instead compare pc addresses; this is just a heuristic as things
7799 may have moved, but in practice it gives the correct answer
7800 often enough until a better solution is found. */
7801 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7803 for (; e
; e
= e
->next
)
7805 if (!e
->enabled
&& e
->function_name
)
7807 struct bp_location
*l
= b
->loc
;
7808 if (have_ambiguous_names
)
7810 for (; l
; l
= l
->next
)
7811 if (e
->address
== l
->address
)
7819 for (; l
; l
= l
->next
)
7820 if (l
->function_name
7821 && strcmp (e
->function_name
, l
->function_name
) == 0)
7831 update_global_location_list (1);
7835 /* Reset a breakpoint given it's struct breakpoint * BINT.
7836 The value we return ends up being the return value from catch_errors.
7837 Unused in this case. */
7840 breakpoint_re_set_one (void *bint
)
7842 /* get past catch_errs */
7843 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7847 int *not_found_ptr
= ¬_found
;
7848 struct symtabs_and_lines sals
= {};
7849 struct symtabs_and_lines expanded
;
7851 enum enable_state save_enable
;
7852 struct gdb_exception e
;
7853 struct cleanup
*cleanups
;
7858 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7862 case bp_hardware_breakpoint
:
7864 /* Do not attempt to re-set breakpoints disabled during startup. */
7865 if (b
->enable_state
== bp_startup_disabled
)
7868 if (b
->addr_string
== NULL
)
7870 /* Anything without a string can't be re-set. */
7871 delete_breakpoint (b
);
7875 set_language (b
->language
);
7876 input_radix
= b
->input_radix
;
7878 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7880 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7885 int not_found_and_ok
= 0;
7886 /* For pending breakpoints, it's expected that parsing
7887 will fail until the right shared library is loaded.
7888 User has already told to create pending breakpoints and
7889 don't need extra messages. If breakpoint is in bp_shlib_disabled
7890 state, then user already saw the message about that breakpoint
7891 being disabled, and don't want to see more errors. */
7893 && (b
->condition_not_parsed
7894 || (b
->loc
&& b
->loc
->shlib_disabled
)
7895 || b
->enable_state
== bp_disabled
))
7896 not_found_and_ok
= 1;
7898 if (!not_found_and_ok
)
7900 /* We surely don't want to warn about the same breakpoint
7901 10 times. One solution, implemented here, is disable
7902 the breakpoint on error. Another solution would be to
7903 have separate 'warning emitted' flag. Since this
7904 happens only when a binary has changed, I don't know
7905 which approach is better. */
7906 b
->enable_state
= bp_disabled
;
7907 throw_exception (e
);
7914 gdb_assert (sals
.nelts
== 1);
7915 resolve_sal_pc (&sals
.sals
[0]);
7916 if (b
->condition_not_parsed
&& s
&& s
[0])
7918 char *cond_string
= 0;
7922 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7923 &cond_string
, &thread
, &task
);
7925 b
->cond_string
= cond_string
;
7928 b
->condition_not_parsed
= 0;
7930 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7931 cleanups
= make_cleanup (xfree
, sals
.sals
);
7932 update_breakpoint_locations (b
, expanded
);
7933 do_cleanups (cleanups
);
7937 case bp_hardware_watchpoint
:
7938 case bp_read_watchpoint
:
7939 case bp_access_watchpoint
:
7940 /* Watchpoint can be either on expression using entirely global variables,
7941 or it can be on local variables.
7943 Watchpoints of the first kind are never auto-deleted, and even persist
7944 across program restarts. Since they can use variables from shared
7945 libraries, we need to reparse expression as libraries are loaded
7948 Watchpoints on local variables can also change meaning as result
7949 of solib event. For example, if a watchpoint uses both a local and
7950 a global variables in expression, it's a local watchpoint, but
7951 unloading of a shared library will make the expression invalid.
7952 This is not a very common use case, but we still re-evaluate
7953 expression, to avoid surprises to the user.
7955 Note that for local watchpoints, we re-evaluate it only if
7956 watchpoints frame id is still valid. If it's not, it means
7957 the watchpoint is out of scope and will be deleted soon. In fact,
7958 I'm not sure we'll ever be called in this case.
7960 If a local watchpoint's frame id is still valid, then
7961 b->exp_valid_block is likewise valid, and we can safely use it.
7963 Don't do anything about disabled watchpoints, since they will
7964 be reevaluated again when enabled. */
7965 update_watchpoint (b
, 1 /* reparse */);
7967 /* We needn't really do anything to reset these, since the mask
7968 that requests them is unaffected by e.g., new libraries being
7974 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7976 /* Delete overlay event and longjmp master breakpoints; they will be
7977 reset later by breakpoint_re_set. */
7978 case bp_overlay_event
:
7979 case bp_longjmp_master
:
7980 delete_breakpoint (b
);
7983 /* This breakpoint is special, it's set up when the inferior
7984 starts and we really don't want to touch it. */
7985 case bp_shlib_event
:
7987 /* Like bp_shlib_event, this breakpoint type is special.
7988 Once it is set up, we do not want to touch it. */
7989 case bp_thread_event
:
7991 /* Keep temporary breakpoints, which can be encountered when we step
7992 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7993 Otherwise these should have been blown away via the cleanup chain
7994 or by breakpoint_init_inferior when we rerun the executable. */
7997 case bp_watchpoint_scope
:
7999 case bp_step_resume
:
8001 case bp_longjmp_resume
:
8008 /* Re-set all breakpoints after symbols have been re-loaded. */
8010 breakpoint_re_set (void)
8012 struct breakpoint
*b
, *temp
;
8013 enum language save_language
;
8014 int save_input_radix
;
8016 save_language
= current_language
->la_language
;
8017 save_input_radix
= input_radix
;
8018 ALL_BREAKPOINTS_SAFE (b
, temp
)
8020 /* Format possible error msg */
8021 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
8023 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
8024 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
8025 do_cleanups (cleanups
);
8027 set_language (save_language
);
8028 input_radix
= save_input_radix
;
8030 create_overlay_event_breakpoint ("_ovly_debug_event");
8031 create_longjmp_master_breakpoint ("longjmp");
8032 create_longjmp_master_breakpoint ("_longjmp");
8033 create_longjmp_master_breakpoint ("siglongjmp");
8034 create_longjmp_master_breakpoint ("_siglongjmp");
8037 /* Reset the thread number of this breakpoint:
8039 - If the breakpoint is for all threads, leave it as-is.
8040 - Else, reset it to the current thread for inferior_ptid. */
8042 breakpoint_re_set_thread (struct breakpoint
*b
)
8044 if (b
->thread
!= -1)
8046 if (in_thread_list (inferior_ptid
))
8047 b
->thread
= pid_to_thread_id (inferior_ptid
);
8051 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
8052 If from_tty is nonzero, it prints a message to that effect,
8053 which ends with a period (no newline). */
8056 set_ignore_count (int bptnum
, int count
, int from_tty
)
8058 struct breakpoint
*b
;
8064 if (b
->number
== bptnum
)
8066 b
->ignore_count
= count
;
8070 printf_filtered (_("Will stop next time breakpoint %d is reached."),
8072 else if (count
== 1)
8073 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
8076 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
8079 breakpoints_changed ();
8080 observer_notify_breakpoint_modified (b
->number
);
8084 error (_("No breakpoint number %d."), bptnum
);
8088 make_breakpoint_silent (struct breakpoint
*b
)
8090 /* Silence the breakpoint. */
8094 /* Command to set ignore-count of breakpoint N to COUNT. */
8097 ignore_command (char *args
, int from_tty
)
8103 error_no_arg (_("a breakpoint number"));
8105 num
= get_number (&p
);
8107 error (_("bad breakpoint number: '%s'"), args
);
8109 error (_("Second argument (specified ignore-count) is missing."));
8111 set_ignore_count (num
,
8112 longest_to_int (value_as_long (parse_and_eval (p
))),
8115 printf_filtered ("\n");
8118 /* Call FUNCTION on each of the breakpoints
8119 whose numbers are given in ARGS. */
8122 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
8127 struct breakpoint
*b
, *tmp
;
8131 error_no_arg (_("one or more breakpoint numbers"));
8138 num
= get_number_or_range (&p1
);
8141 warning (_("bad breakpoint number at or near '%s'"), p
);
8145 ALL_BREAKPOINTS_SAFE (b
, tmp
)
8146 if (b
->number
== num
)
8148 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
8151 if (related_breakpoint
)
8152 function (related_breakpoint
);
8156 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
8162 static struct bp_location
*
8163 find_location_by_number (char *number
)
8165 char *dot
= strchr (number
, '.');
8169 struct breakpoint
*b
;
8170 struct bp_location
*loc
;
8175 bp_num
= get_number_or_range (&p1
);
8177 error (_("Bad breakpoint number '%s'"), number
);
8180 if (b
->number
== bp_num
)
8185 if (!b
|| b
->number
!= bp_num
)
8186 error (_("Bad breakpoint number '%s'"), number
);
8189 loc_num
= get_number_or_range (&p1
);
8191 error (_("Bad breakpoint location number '%s'"), number
);
8195 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
8198 error (_("Bad breakpoint location number '%s'"), dot
+1);
8204 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
8205 If from_tty is nonzero, it prints a message to that effect,
8206 which ends with a period (no newline). */
8209 disable_breakpoint (struct breakpoint
*bpt
)
8211 /* Never disable a watchpoint scope breakpoint; we want to
8212 hit them when we leave scope so we can delete both the
8213 watchpoint and its scope breakpoint at that time. */
8214 if (bpt
->type
== bp_watchpoint_scope
)
8217 /* You can't disable permanent breakpoints. */
8218 if (bpt
->enable_state
== bp_permanent
)
8221 bpt
->enable_state
= bp_disabled
;
8223 update_global_location_list (0);
8225 observer_notify_breakpoint_modified (bpt
->number
);
8229 disable_command (char *args
, int from_tty
)
8231 struct breakpoint
*bpt
;
8233 ALL_BREAKPOINTS (bpt
)
8237 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
8243 case bp_hardware_breakpoint
:
8245 case bp_hardware_watchpoint
:
8246 case bp_read_watchpoint
:
8247 case bp_access_watchpoint
:
8248 disable_breakpoint (bpt
);
8252 else if (strchr (args
, '.'))
8254 struct bp_location
*loc
= find_location_by_number (args
);
8257 update_global_location_list (0);
8260 map_breakpoint_numbers (args
, disable_breakpoint
);
8264 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
8266 int target_resources_ok
, other_type_used
;
8269 if (bpt
->type
== bp_hardware_breakpoint
)
8272 i
= hw_breakpoint_used_count ();
8273 target_resources_ok
=
8274 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8276 if (target_resources_ok
== 0)
8277 error (_("No hardware breakpoint support in the target."));
8278 else if (target_resources_ok
< 0)
8279 error (_("Hardware breakpoints used exceeds limit."));
8282 if (bpt
->type
== bp_watchpoint
8283 || bpt
->type
== bp_hardware_watchpoint
8284 || bpt
->type
== bp_read_watchpoint
8285 || bpt
->type
== bp_access_watchpoint
)
8287 struct gdb_exception e
;
8289 TRY_CATCH (e
, RETURN_MASK_ALL
)
8291 update_watchpoint (bpt
, 1 /* reparse */);
8295 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
8301 if (bpt
->enable_state
!= bp_permanent
)
8302 bpt
->enable_state
= bp_enabled
;
8303 bpt
->disposition
= disposition
;
8304 update_global_location_list (1);
8305 breakpoints_changed ();
8307 observer_notify_breakpoint_modified (bpt
->number
);
8312 enable_breakpoint (struct breakpoint
*bpt
)
8314 do_enable_breakpoint (bpt
, bpt
->disposition
);
8317 /* The enable command enables the specified breakpoints (or all defined
8318 breakpoints) so they once again become (or continue to be) effective
8319 in stopping the inferior. */
8322 enable_command (char *args
, int from_tty
)
8324 struct breakpoint
*bpt
;
8326 ALL_BREAKPOINTS (bpt
)
8330 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8336 case bp_hardware_breakpoint
:
8338 case bp_hardware_watchpoint
:
8339 case bp_read_watchpoint
:
8340 case bp_access_watchpoint
:
8341 enable_breakpoint (bpt
);
8345 else if (strchr (args
, '.'))
8347 struct bp_location
*loc
= find_location_by_number (args
);
8350 update_global_location_list (1);
8353 map_breakpoint_numbers (args
, enable_breakpoint
);
8357 enable_once_breakpoint (struct breakpoint
*bpt
)
8359 do_enable_breakpoint (bpt
, disp_disable
);
8363 enable_once_command (char *args
, int from_tty
)
8365 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8369 enable_delete_breakpoint (struct breakpoint
*bpt
)
8371 do_enable_breakpoint (bpt
, disp_del
);
8375 enable_delete_command (char *args
, int from_tty
)
8377 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8381 set_breakpoint_cmd (char *args
, int from_tty
)
8386 show_breakpoint_cmd (char *args
, int from_tty
)
8390 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8392 struct symtabs_and_lines
8393 decode_line_spec_1 (char *string
, int funfirstline
)
8395 struct symtabs_and_lines sals
;
8397 error (_("Empty line specification."));
8398 if (default_breakpoint_valid
)
8399 sals
= decode_line_1 (&string
, funfirstline
,
8400 default_breakpoint_symtab
,
8401 default_breakpoint_line
,
8402 (char ***) NULL
, NULL
);
8404 sals
= decode_line_1 (&string
, funfirstline
,
8405 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8407 error (_("Junk at end of line specification: %s"), string
);
8411 /* Create and insert a raw software breakpoint at PC. Return an
8412 identifier, which should be used to remove the breakpoint later.
8413 In general, places which call this should be using something on the
8414 breakpoint chain instead; this function should be eliminated
8418 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
8420 struct bp_target_info
*bp_tgt
;
8422 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8423 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8425 bp_tgt
->placed_address
= pc
;
8426 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
8428 /* Could not insert the breakpoint. */
8436 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8439 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
8441 struct bp_target_info
*bp_tgt
= bp
;
8444 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
8450 /* One (or perhaps two) breakpoints used for software single stepping. */
8452 static void *single_step_breakpoints
[2];
8453 static struct gdbarch
*single_step_gdbarch
[2];
8455 /* Create and insert a breakpoint for software single step. */
8458 insert_single_step_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR next_pc
)
8462 if (single_step_breakpoints
[0] == NULL
)
8464 bpt_p
= &single_step_breakpoints
[0];
8465 single_step_gdbarch
[0] = gdbarch
;
8469 gdb_assert (single_step_breakpoints
[1] == NULL
);
8470 bpt_p
= &single_step_breakpoints
[1];
8471 single_step_gdbarch
[1] = gdbarch
;
8474 /* NOTE drow/2006-04-11: A future improvement to this function would be
8475 to only create the breakpoints once, and actually put them on the
8476 breakpoint chain. That would let us use set_raw_breakpoint. We could
8477 adjust the addresses each time they were needed. Doing this requires
8478 corresponding changes elsewhere where single step breakpoints are
8479 handled, however. So, for now, we use this. */
8481 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, next_pc
);
8483 error (_("Could not insert single-step breakpoint at %s"),
8484 paddress (gdbarch
, next_pc
));
8487 /* Remove and delete any breakpoints used for software single step. */
8490 remove_single_step_breakpoints (void)
8492 gdb_assert (single_step_breakpoints
[0] != NULL
);
8494 /* See insert_single_step_breakpoint for more about this deprecated
8496 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
8497 single_step_breakpoints
[0]);
8498 single_step_gdbarch
[0] = NULL
;
8499 single_step_breakpoints
[0] = NULL
;
8501 if (single_step_breakpoints
[1] != NULL
)
8503 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
8504 single_step_breakpoints
[1]);
8505 single_step_gdbarch
[1] = NULL
;
8506 single_step_breakpoints
[1] = NULL
;
8510 /* Check whether a software single-step breakpoint is inserted at PC. */
8513 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8517 for (i
= 0; i
< 2; i
++)
8519 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8520 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8527 /* Tracepoint-specific operations. */
8529 /* Set tracepoint count to NUM. */
8531 set_tracepoint_count (int num
)
8533 tracepoint_count
= num
;
8534 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
8538 trace_command (char *arg
, int from_tty
)
8540 break_command_really (get_current_arch (),
8542 NULL
, 0, 1 /* parse arg */,
8543 0 /* tempflag */, 0 /* hardwareflag */,
8545 0 /* Ignore count */,
8546 pending_break_support
,
8550 set_tracepoint_count (breakpoint_count
);
8553 /* Print information on tracepoint number TPNUM_EXP, or all if
8557 tracepoints_info (char *tpnum_exp
, int from_tty
)
8559 struct breakpoint
*b
;
8560 int tps_to_list
= 0;
8562 /* In the no-arguments case, say "No tracepoints" if none found. */
8575 ui_out_message (uiout
, 0, "No tracepoints.\n");
8580 /* Otherwise be the same as "info break". */
8581 breakpoints_info (tpnum_exp
, from_tty
);
8584 /* The 'enable trace' command enables tracepoints.
8585 Not supported by all targets. */
8587 enable_trace_command (char *args
, int from_tty
)
8589 enable_command (args
, from_tty
);
8592 /* The 'disable trace' command disables tracepoints.
8593 Not supported by all targets. */
8595 disable_trace_command (char *args
, int from_tty
)
8597 disable_command (args
, from_tty
);
8600 /* Remove a tracepoint (or all if no argument) */
8602 delete_trace_command (char *arg
, int from_tty
)
8604 struct breakpoint
*b
, *temp
;
8610 int breaks_to_delete
= 0;
8612 /* Delete all breakpoints if no argument.
8613 Do not delete internal or call-dummy breakpoints, these
8614 have to be deleted with an explicit breakpoint number argument. */
8619 breaks_to_delete
= 1;
8624 /* Ask user only if there are some breakpoints to delete. */
8626 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
8628 ALL_BREAKPOINTS_SAFE (b
, temp
)
8630 if (b
->type
== bp_tracepoint
8632 delete_breakpoint (b
);
8637 map_breakpoint_numbers (arg
, delete_breakpoint
);
8640 /* Set passcount for tracepoint.
8642 First command argument is passcount, second is tracepoint number.
8643 If tracepoint number omitted, apply to most recently defined.
8644 Also accepts special argument "all". */
8647 trace_pass_command (char *args
, int from_tty
)
8649 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
8653 if (args
== 0 || *args
== 0)
8654 error (_("passcount command requires an argument (count + optional TP num)"));
8656 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
8658 while (*args
&& isspace ((int) *args
))
8661 if (*args
&& strncasecmp (args
, "all", 3) == 0)
8663 args
+= 3; /* Skip special argument "all". */
8666 error (_("Junk at end of arguments."));
8669 t1
= get_tracepoint_by_number (&args
, 1, 1);
8675 ALL_TRACEPOINTS (t2
)
8676 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
8678 t2
->pass_count
= count
;
8679 observer_notify_tracepoint_modified (t2
->number
);
8681 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
8685 t1
= get_tracepoint_by_number (&args
, 1, 0);
8692 get_tracepoint (int num
)
8694 struct breakpoint
*t
;
8697 if (t
->number
== num
)
8703 /* Utility: parse a tracepoint number and look it up in the list.
8704 If MULTI_P is true, there might be a range of tracepoints in ARG.
8705 if OPTIONAL_P is true, then if the argument is missing, the most
8706 recent tracepoint (tracepoint_count) is returned. */
8708 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
8710 extern int tracepoint_count
;
8711 struct breakpoint
*t
;
8713 char *instring
= arg
== NULL
? NULL
: *arg
;
8715 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
8718 tpnum
= tracepoint_count
;
8720 error_no_arg (_("tracepoint number"));
8723 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
8727 if (instring
&& *instring
)
8728 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
8731 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
8736 if (t
->number
== tpnum
)
8741 /* FIXME: if we are in the middle of a range we don't want to give
8742 a message. The current interface to get_number_or_range doesn't
8743 allow us to discover this. */
8744 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
8748 /* save-tracepoints command */
8750 tracepoint_save_command (char *args
, int from_tty
)
8752 struct breakpoint
*tp
;
8754 struct action_line
*line
;
8756 char *i1
= " ", *i2
= " ";
8757 char *indent
, *actionline
, *pathname
;
8759 struct cleanup
*cleanup
;
8761 if (args
== 0 || *args
== 0)
8762 error (_("Argument required (file name in which to save tracepoints)"));
8764 /* See if we have anything to save. */
8765 ALL_TRACEPOINTS (tp
)
8772 warning (_("save-tracepoints: no tracepoints to save."));
8776 pathname
= tilde_expand (args
);
8777 cleanup
= make_cleanup (xfree
, pathname
);
8778 fp
= fopen (pathname
, "w");
8780 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
8781 args
, safe_strerror (errno
));
8782 make_cleanup_fclose (fp
);
8784 ALL_TRACEPOINTS (tp
)
8786 if (tp
->addr_string
)
8787 fprintf (fp
, "trace %s\n", tp
->addr_string
);
8790 sprintf_vma (tmp
, tp
->loc
->address
);
8791 fprintf (fp
, "trace *0x%s\n", tmp
);
8795 fprintf (fp
, " passcount %d\n", tp
->pass_count
);
8799 fprintf (fp
, " actions\n");
8801 for (line
= tp
->actions
; line
; line
= line
->next
)
8803 struct cmd_list_element
*cmd
;
8805 QUIT
; /* allow user to bail out with ^C */
8806 actionline
= line
->action
;
8807 while (isspace ((int) *actionline
))
8810 fprintf (fp
, "%s%s\n", indent
, actionline
);
8811 if (*actionline
!= '#') /* skip for comment lines */
8813 cmd
= lookup_cmd (&actionline
, cmdlist
, "", -1, 1);
8815 error (_("Bad action list item: %s"), actionline
);
8816 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
8818 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
8824 do_cleanups (cleanup
);
8826 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
8830 /* Create a vector of all tracepoints. */
8835 VEC(breakpoint_p
) *tp_vec
= 0;
8836 struct breakpoint
*tp
;
8838 ALL_TRACEPOINTS (tp
)
8840 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
8847 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8848 It is defined as a macro to prevent duplication.
8849 COMMAND should be a string constant containing the name of the command. */
8850 #define BREAK_ARGS_HELP(command) \
8851 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8852 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8853 If a line number is specified, break at start of code for that line.\n\
8854 If a function is specified, break at start of code for that function.\n\
8855 If an address is specified, break at that exact address.\n\
8856 With no LOCATION, uses current execution address of selected stack frame.\n\
8857 This is useful for breaking on return to a stack frame.\n\
8859 THREADNUM is the number from \"info threads\".\n\
8860 CONDITION is a boolean expression.\n\
8862 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8864 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8866 /* List of subcommands for "catch". */
8867 static struct cmd_list_element
*catch_cmdlist
;
8869 /* List of subcommands for "tcatch". */
8870 static struct cmd_list_element
*tcatch_cmdlist
;
8872 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8873 lists, and pass some additional user data to the command function. */
8875 add_catch_command (char *name
, char *docstring
,
8876 void (*sfunc
) (char *args
, int from_tty
,
8877 struct cmd_list_element
*command
),
8878 void *user_data_catch
,
8879 void *user_data_tcatch
)
8881 struct cmd_list_element
*command
;
8883 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8885 set_cmd_sfunc (command
, sfunc
);
8886 set_cmd_context (command
, user_data_catch
);
8888 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8890 set_cmd_sfunc (command
, sfunc
);
8891 set_cmd_context (command
, user_data_tcatch
);
8895 _initialize_breakpoint (void)
8897 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8898 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8899 struct cmd_list_element
*c
;
8901 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8903 breakpoint_chain
= 0;
8904 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8905 before a breakpoint is set. */
8906 breakpoint_count
= 0;
8908 tracepoint_count
= 0;
8910 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8911 Set ignore-count of breakpoint number N to COUNT.\n\
8912 Usage is `ignore N COUNT'."));
8914 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8916 add_com ("commands", class_breakpoint
, commands_command
, _("\
8917 Set commands to be executed when a breakpoint is hit.\n\
8918 Give breakpoint number as argument after \"commands\".\n\
8919 With no argument, the targeted breakpoint is the last one set.\n\
8920 The commands themselves follow starting on the next line.\n\
8921 Type a line containing \"end\" to indicate the end of them.\n\
8922 Give \"silent\" as the first line to make the breakpoint silent;\n\
8923 then no output is printed when it is hit, except what the commands print."));
8925 add_com ("condition", class_breakpoint
, condition_command
, _("\
8926 Specify breakpoint number N to break only if COND is true.\n\
8927 Usage is `condition N COND', where N is an integer and COND is an\n\
8928 expression to be evaluated whenever breakpoint N is reached."));
8930 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8931 Set a temporary breakpoint.\n\
8932 Like \"break\" except the breakpoint is only temporary,\n\
8933 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8934 by using \"enable delete\" on the breakpoint number.\n\
8936 BREAK_ARGS_HELP ("tbreak")));
8937 set_cmd_completer (c
, location_completer
);
8939 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8940 Set a hardware assisted breakpoint.\n\
8941 Like \"break\" except the breakpoint requires hardware support,\n\
8942 some target hardware may not have this support.\n\
8944 BREAK_ARGS_HELP ("hbreak")));
8945 set_cmd_completer (c
, location_completer
);
8947 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8948 Set a temporary hardware assisted breakpoint.\n\
8949 Like \"hbreak\" except the breakpoint is only temporary,\n\
8950 so it will be deleted when hit.\n\
8952 BREAK_ARGS_HELP ("thbreak")));
8953 set_cmd_completer (c
, location_completer
);
8955 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8956 Enable some breakpoints.\n\
8957 Give breakpoint numbers (separated by spaces) as arguments.\n\
8958 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8959 This is used to cancel the effect of the \"disable\" command.\n\
8960 With a subcommand you can enable temporarily."),
8961 &enablelist
, "enable ", 1, &cmdlist
);
8963 add_com ("ab", class_breakpoint
, enable_command
, _("\
8964 Enable some breakpoints.\n\
8965 Give breakpoint numbers (separated by spaces) as arguments.\n\
8966 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8967 This is used to cancel the effect of the \"disable\" command.\n\
8968 With a subcommand you can enable temporarily."));
8970 add_com_alias ("en", "enable", class_breakpoint
, 1);
8972 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8973 Enable some breakpoints.\n\
8974 Give breakpoint numbers (separated by spaces) as arguments.\n\
8975 This is used to cancel the effect of the \"disable\" command.\n\
8976 May be abbreviated to simply \"enable\".\n"),
8977 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8979 add_cmd ("once", no_class
, enable_once_command
, _("\
8980 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8981 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8984 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8985 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8986 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8989 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8990 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8991 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8994 add_cmd ("once", no_class
, enable_once_command
, _("\
8995 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8996 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8999 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
9000 Disable some breakpoints.\n\
9001 Arguments are breakpoint numbers with spaces in between.\n\
9002 To disable all breakpoints, give no argument.\n\
9003 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
9004 &disablelist
, "disable ", 1, &cmdlist
);
9005 add_com_alias ("dis", "disable", class_breakpoint
, 1);
9006 add_com_alias ("disa", "disable", class_breakpoint
, 1);
9008 add_com ("sb", class_breakpoint
, disable_command
, _("\
9009 Disable some breakpoints.\n\
9010 Arguments are breakpoint numbers with spaces in between.\n\
9011 To disable all breakpoints, give no argument.\n\
9012 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
9014 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
9015 Disable some breakpoints.\n\
9016 Arguments are breakpoint numbers with spaces in between.\n\
9017 To disable all breakpoints, give no argument.\n\
9018 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
9019 This command may be abbreviated \"disable\"."),
9022 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
9023 Delete some breakpoints or auto-display expressions.\n\
9024 Arguments are breakpoint numbers with spaces in between.\n\
9025 To delete all breakpoints, give no argument.\n\
9027 Also a prefix command for deletion of other GDB objects.\n\
9028 The \"unset\" command is also an alias for \"delete\"."),
9029 &deletelist
, "delete ", 1, &cmdlist
);
9030 add_com_alias ("d", "delete", class_breakpoint
, 1);
9031 add_com_alias ("del", "delete", class_breakpoint
, 1);
9033 add_com ("db", class_breakpoint
, delete_command
, _("\
9034 Delete some breakpoints.\n\
9035 Arguments are breakpoint numbers with spaces in between.\n\
9036 To delete all breakpoints, give no argument.\n"));
9038 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
9039 Delete some breakpoints or auto-display expressions.\n\
9040 Arguments are breakpoint numbers with spaces in between.\n\
9041 To delete all breakpoints, give no argument.\n\
9042 This command may be abbreviated \"delete\"."),
9045 add_com ("clear", class_breakpoint
, clear_command
, _("\
9046 Clear breakpoint at specified line or function.\n\
9047 Argument may be line number, function name, or \"*\" and an address.\n\
9048 If line number is specified, all breakpoints in that line are cleared.\n\
9049 If function is specified, breakpoints at beginning of function are cleared.\n\
9050 If an address is specified, breakpoints at that address are cleared.\n\
9052 With no argument, clears all breakpoints in the line that the selected frame\n\
9055 See also the \"delete\" command which clears breakpoints by number."));
9057 c
= add_com ("break", class_breakpoint
, break_command
, _("\
9058 Set breakpoint at specified line or function.\n"
9059 BREAK_ARGS_HELP ("break")));
9060 set_cmd_completer (c
, location_completer
);
9062 add_com_alias ("b", "break", class_run
, 1);
9063 add_com_alias ("br", "break", class_run
, 1);
9064 add_com_alias ("bre", "break", class_run
, 1);
9065 add_com_alias ("brea", "break", class_run
, 1);
9068 add_com_alias ("ba", "break", class_breakpoint
, 1);
9072 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
9073 Break in function/address or break at a line in the current file."),
9074 &stoplist
, "stop ", 1, &cmdlist
);
9075 add_cmd ("in", class_breakpoint
, stopin_command
,
9076 _("Break in function or address."), &stoplist
);
9077 add_cmd ("at", class_breakpoint
, stopat_command
,
9078 _("Break at a line in the current file."), &stoplist
);
9079 add_com ("status", class_info
, breakpoints_info
, _("\
9080 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9081 The \"Type\" column indicates one of:\n\
9082 \tbreakpoint - normal breakpoint\n\
9083 \twatchpoint - watchpoint\n\
9084 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9085 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9086 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9087 address and file/line number respectively.\n\
9089 Convenience variable \"$_\" and default examine address for \"x\"\n\
9090 are set to the address of the last breakpoint listed unless the command\n\
9091 is prefixed with \"server \".\n\n\
9092 Convenience variable \"$bpnum\" contains the number of the last\n\
9096 add_info ("breakpoints", breakpoints_info
, _("\
9097 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9098 The \"Type\" column indicates one of:\n\
9099 \tbreakpoint - normal breakpoint\n\
9100 \twatchpoint - watchpoint\n\
9101 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9102 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9103 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9104 address and file/line number respectively.\n\
9106 Convenience variable \"$_\" and default examine address for \"x\"\n\
9107 are set to the address of the last breakpoint listed unless the command\n\
9108 is prefixed with \"server \".\n\n\
9109 Convenience variable \"$bpnum\" contains the number of the last\n\
9113 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
9114 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
9115 The \"Type\" column indicates one of:\n\
9116 \tbreakpoint - normal breakpoint\n\
9117 \twatchpoint - watchpoint\n\
9118 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9119 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9120 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9121 address and file/line number respectively.\n\
9123 Convenience variable \"$_\" and default examine address for \"x\"\n\
9124 are set to the address of the last breakpoint listed unless the command\n\
9125 is prefixed with \"server \".\n\n\
9126 Convenience variable \"$bpnum\" contains the number of the last\n\
9129 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
9130 Status of all breakpoints, or breakpoint number NUMBER.\n\
9131 The \"Type\" column indicates one of:\n\
9132 \tbreakpoint - normal breakpoint\n\
9133 \twatchpoint - watchpoint\n\
9134 \tlongjmp - internal breakpoint used to step through longjmp()\n\
9135 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
9136 \tuntil - internal breakpoint used by the \"until\" command\n\
9137 \tfinish - internal breakpoint used by the \"finish\" command\n\
9138 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
9139 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
9140 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
9141 address and file/line number respectively.\n\
9143 Convenience variable \"$_\" and default examine address for \"x\"\n\
9144 are set to the address of the last breakpoint listed unless the command\n\
9145 is prefixed with \"server \".\n\n\
9146 Convenience variable \"$bpnum\" contains the number of the last\n\
9148 &maintenanceinfolist
);
9150 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
9151 Set catchpoints to catch events."),
9152 &catch_cmdlist
, "catch ",
9153 0/*allow-unknown*/, &cmdlist
);
9155 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
9156 Set temporary catchpoints to catch events."),
9157 &tcatch_cmdlist
, "tcatch ",
9158 0/*allow-unknown*/, &cmdlist
);
9160 /* Add catch and tcatch sub-commands. */
9161 add_catch_command ("catch", _("\
9162 Catch an exception, when caught.\n\
9163 With an argument, catch only exceptions with the given name."),
9164 catch_catch_command
,
9167 add_catch_command ("throw", _("\
9168 Catch an exception, when thrown.\n\
9169 With an argument, catch only exceptions with the given name."),
9170 catch_throw_command
,
9173 add_catch_command ("fork", _("Catch calls to fork."),
9174 catch_fork_command_1
,
9175 (void *) (uintptr_t) catch_fork_permanent
,
9176 (void *) (uintptr_t) catch_fork_temporary
);
9177 add_catch_command ("vfork", _("Catch calls to vfork."),
9178 catch_fork_command_1
,
9179 (void *) (uintptr_t) catch_vfork_permanent
,
9180 (void *) (uintptr_t) catch_vfork_temporary
);
9181 add_catch_command ("exec", _("Catch calls to exec."),
9182 catch_exec_command_1
,
9185 add_catch_command ("exception", _("\
9186 Catch Ada exceptions, when raised.\n\
9187 With an argument, catch only exceptions with the given name."),
9188 catch_ada_exception_command
,
9191 add_catch_command ("assert", _("\
9192 Catch failed Ada assertions, when raised.\n\
9193 With an argument, catch only exceptions with the given name."),
9194 catch_assert_command
,
9198 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
9199 Set a watchpoint for an expression.\n\
9200 A watchpoint stops execution of your program whenever the value of\n\
9201 an expression changes."));
9202 set_cmd_completer (c
, expression_completer
);
9204 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
9205 Set a read watchpoint for an expression.\n\
9206 A watchpoint stops execution of your program whenever the value of\n\
9207 an expression is read."));
9208 set_cmd_completer (c
, expression_completer
);
9210 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
9211 Set a watchpoint for an expression.\n\
9212 A watchpoint stops execution of your program whenever the value of\n\
9213 an expression is either read or written."));
9214 set_cmd_completer (c
, expression_completer
);
9216 add_info ("watchpoints", breakpoints_info
,
9217 _("Synonym for ``info breakpoints''."));
9220 /* XXX: cagney/2005-02-23: This should be a boolean, and should
9221 respond to changes - contrary to the description. */
9222 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
9223 &can_use_hw_watchpoints
, _("\
9224 Set debugger's willingness to use watchpoint hardware."), _("\
9225 Show debugger's willingness to use watchpoint hardware."), _("\
9226 If zero, gdb will not use hardware for new watchpoints, even if\n\
9227 such is available. (However, any hardware watchpoints that were\n\
9228 created before setting this to nonzero, will continue to use watchpoint\n\
9231 show_can_use_hw_watchpoints
,
9232 &setlist
, &showlist
);
9234 can_use_hw_watchpoints
= 1;
9236 /* Tracepoint manipulation commands. */
9238 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
9239 Set a tracepoint at specified line or function.\n\
9241 BREAK_ARGS_HELP ("trace") "\n\
9242 Do \"help tracepoints\" for info on other tracepoint commands."));
9243 set_cmd_completer (c
, location_completer
);
9245 add_com_alias ("tp", "trace", class_alias
, 0);
9246 add_com_alias ("tr", "trace", class_alias
, 1);
9247 add_com_alias ("tra", "trace", class_alias
, 1);
9248 add_com_alias ("trac", "trace", class_alias
, 1);
9250 add_info ("tracepoints", tracepoints_info
, _("\
9251 Status of tracepoints, or tracepoint number NUMBER.\n\
9252 Convenience variable \"$tpnum\" contains the number of the\n\
9253 last tracepoint set."));
9255 add_info_alias ("tp", "tracepoints", 1);
9257 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
9258 Delete specified tracepoints.\n\
9259 Arguments are tracepoint numbers, separated by spaces.\n\
9260 No argument means delete all tracepoints."),
9263 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
9264 Disable specified tracepoints.\n\
9265 Arguments are tracepoint numbers, separated by spaces.\n\
9266 No argument means disable all tracepoints."),
9268 deprecate_cmd (c
, "disable");
9270 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
9271 Enable specified tracepoints.\n\
9272 Arguments are tracepoint numbers, separated by spaces.\n\
9273 No argument means enable all tracepoints."),
9275 deprecate_cmd (c
, "enable");
9277 add_com ("passcount", class_trace
, trace_pass_command
, _("\
9278 Set the passcount for a tracepoint.\n\
9279 The trace will end when the tracepoint has been passed 'count' times.\n\
9280 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
9281 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
9283 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
9284 Save current tracepoint definitions as a script.\n\
9285 Use the 'source' command in another debug session to restore them."));
9286 set_cmd_completer (c
, filename_completer
);
9288 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
9289 Breakpoint specific settings\n\
9290 Configure various breakpoint-specific variables such as\n\
9291 pending breakpoint behavior"),
9292 &breakpoint_set_cmdlist
, "set breakpoint ",
9293 0/*allow-unknown*/, &setlist
);
9294 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
9295 Breakpoint specific settings\n\
9296 Configure various breakpoint-specific variables such as\n\
9297 pending breakpoint behavior"),
9298 &breakpoint_show_cmdlist
, "show breakpoint ",
9299 0/*allow-unknown*/, &showlist
);
9301 add_setshow_auto_boolean_cmd ("pending", no_class
,
9302 &pending_break_support
, _("\
9303 Set debugger's behavior regarding pending breakpoints."), _("\
9304 Show debugger's behavior regarding pending breakpoints."), _("\
9305 If on, an unrecognized breakpoint location will cause gdb to create a\n\
9306 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
9307 an error. If auto, an unrecognized breakpoint location results in a\n\
9308 user-query to see if a pending breakpoint should be created."),
9310 show_pending_break_support
,
9311 &breakpoint_set_cmdlist
,
9312 &breakpoint_show_cmdlist
);
9314 pending_break_support
= AUTO_BOOLEAN_AUTO
;
9316 add_setshow_boolean_cmd ("auto-hw", no_class
,
9317 &automatic_hardware_breakpoints
, _("\
9318 Set automatic usage of hardware breakpoints."), _("\
9319 Show automatic usage of hardware breakpoints."), _("\
9320 If set, the debugger will automatically use hardware breakpoints for\n\
9321 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
9322 a warning will be emitted for such breakpoints."),
9324 show_automatic_hardware_breakpoints
,
9325 &breakpoint_set_cmdlist
,
9326 &breakpoint_show_cmdlist
);
9328 add_setshow_enum_cmd ("always-inserted", class_support
,
9329 always_inserted_enums
, &always_inserted_mode
, _("\
9330 Set mode for inserting breakpoints."), _("\
9331 Show mode for inserting breakpoints."), _("\
9332 When this mode is off, breakpoints are inserted in inferior when it is\n\
9333 resumed, and removed when execution stops. When this mode is on,\n\
9334 breakpoints are inserted immediately and removed only when the user\n\
9335 deletes the breakpoint. When this mode is auto (which is the default),\n\
9336 the behaviour depends on the non-stop setting (see help set non-stop).\n\
9337 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
9338 behaves as if always-inserted mode is on; if gdb is controlling the\n\
9339 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
9341 &show_always_inserted_mode
,
9342 &breakpoint_set_cmdlist
,
9343 &breakpoint_show_cmdlist
);
9345 automatic_hardware_breakpoints
= 1;
9347 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);