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 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/>. */
27 #include "breakpoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
45 #include "completer.h"
48 #include "cli/cli-script.h"
49 #include "gdb_assert.h"
54 #include "exceptions.h"
61 #include "mi/mi-common.h"
63 /* Arguments to pass as context to some catch command handlers. */
64 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
65 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
67 /* Prototypes for local functions. */
69 static void enable_delete_command (char *, int);
71 static void enable_delete_breakpoint (struct breakpoint
*);
73 static void enable_once_command (char *, int);
75 static void enable_once_breakpoint (struct breakpoint
*);
77 static void disable_command (char *, int);
79 static void enable_command (char *, int);
81 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
83 static void ignore_command (char *, int);
85 static int breakpoint_re_set_one (void *);
87 static void clear_command (char *, int);
89 static void catch_command (char *, int);
91 static void watch_command (char *, int);
93 static int can_use_hardware_watchpoint (struct value
*);
95 static void break_command_1 (char *, int, int);
97 static void mention (struct breakpoint
*);
99 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
101 static void check_duplicates (struct breakpoint
*);
103 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
105 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
108 static void describe_other_breakpoints (CORE_ADDR
, struct obj_section
*, int);
110 static void breakpoints_info (char *, int);
112 static void breakpoint_1 (int, int);
114 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
116 static int breakpoint_cond_eval (void *);
118 static void cleanup_executing_breakpoints (void *);
120 static void commands_command (char *, int);
122 static void condition_command (char *, int);
124 static int get_number_trailer (char **, int);
126 void set_breakpoint_count (int);
135 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
137 static enum print_stop_action
print_it_typical (bpstat
);
139 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
141 static int watchpoint_check (void *);
143 static void maintenance_info_breakpoints (char *, int);
145 static void create_overlay_event_breakpoint (char *);
147 static int hw_breakpoint_used_count (void);
149 static int hw_watchpoint_used_count (enum bptype
, int *);
151 static void hbreak_command (char *, int);
153 static void thbreak_command (char *, int);
155 static void watch_command_1 (char *, int, int);
157 static void rwatch_command (char *, int);
159 static void awatch_command (char *, int);
161 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
163 static void stop_command (char *arg
, int from_tty
);
165 static void stopin_command (char *arg
, int from_tty
);
167 static void stopat_command (char *arg
, int from_tty
);
169 static char *ep_parse_optional_if_clause (char **arg
);
171 static char *ep_parse_optional_filename (char **arg
);
173 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
174 char *arg
, int tempflag
, int from_tty
);
176 static void tcatch_command (char *arg
, int from_tty
);
178 static void ep_skip_leading_whitespace (char **s
);
180 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
182 static void free_bp_location (struct bp_location
*loc
);
184 static struct bp_location
*
185 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
);
187 static void update_global_location_list (int);
189 static void update_global_location_list_nothrow (int);
191 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
193 static void insert_breakpoint_locations (void);
196 bpdisp_text (enum bpdisp disp
)
198 /* NOTE: the following values are a part of MI protocol and represent
199 values of 'disp' field returned when inferior stops at a breakpoint. */
200 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
201 return bpdisps
[(int) disp
];
204 /* Prototypes for exported functions. */
205 /* If FALSE, gdb will not use hardware support for watchpoints, even
206 if such is available. */
207 static int can_use_hw_watchpoints
;
210 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
211 struct cmd_list_element
*c
,
214 fprintf_filtered (file
, _("\
215 Debugger's willingness to use watchpoint hardware is %s.\n"),
219 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
220 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
221 for unrecognized breakpoint locations.
222 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
223 static enum auto_boolean pending_break_support
;
225 show_pending_break_support (struct ui_file
*file
, int from_tty
,
226 struct cmd_list_element
*c
,
229 fprintf_filtered (file
, _("\
230 Debugger's behavior regarding pending breakpoints is %s.\n"),
234 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
235 set with "break" but falling in read-only memory.
236 If 0, gdb will warn about such breakpoints, but won't automatically
237 use hardware breakpoints. */
238 static int automatic_hardware_breakpoints
;
240 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
241 struct cmd_list_element
*c
,
244 fprintf_filtered (file
, _("\
245 Automatic usage of hardware breakpoints is %s.\n"),
249 /* If on, gdb will keep breakpoints inserted even as inferior is
250 stopped, and immediately insert any new breakpoints. If off, gdb
251 will insert breakpoints into inferior only when resuming it, and
252 will remove breakpoints upon stop. If auto, GDB will behave as ON
253 if in non-stop mode, and as OFF if all-stop mode.*/
255 static const char always_inserted_auto
[] = "auto";
256 static const char always_inserted_on
[] = "on";
257 static const char always_inserted_off
[] = "off";
258 static const char *always_inserted_enums
[] = {
259 always_inserted_auto
,
264 static const char *always_inserted_mode
= always_inserted_auto
;
266 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
267 struct cmd_list_element
*c
, const char *value
)
269 if (always_inserted_mode
== always_inserted_auto
)
270 fprintf_filtered (file
, _("\
271 Always inserted breakpoint mode is %s (currently %s).\n"),
273 breakpoints_always_inserted_mode () ? "on" : "off");
275 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
279 breakpoints_always_inserted_mode (void)
281 return (always_inserted_mode
== always_inserted_on
282 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
285 void _initialize_breakpoint (void);
287 /* Are we executing breakpoint commands? */
288 static int executing_breakpoint_commands
;
290 /* Are overlay event breakpoints enabled? */
291 static int overlay_events_enabled
;
293 /* Walk the following statement or block through all breakpoints.
294 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
297 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
299 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
300 for (B = breakpoint_chain; \
301 B ? (TMP=B->next, 1): 0; \
304 /* Similar iterators for the low-level breakpoints. */
306 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
308 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
309 for (B = bp_location_chain; \
310 B ? (TMP=B->global_next, 1): 0; \
313 /* Chains of all breakpoints defined. */
315 struct breakpoint
*breakpoint_chain
;
317 struct bp_location
*bp_location_chain
;
319 /* The locations that no longer correspond to any breakpoint,
320 unlinked from bp_location_chain, but for which a hit
321 may still be reported by a target. */
322 VEC(bp_location_p
) *moribund_locations
= NULL
;
324 /* Number of last breakpoint made. */
326 int breakpoint_count
;
328 /* This function returns a pointer to the string representation of the
329 pathname of the dynamically-linked library that has just been
332 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
333 or undefined results are guaranteed.
335 This string's contents are only valid immediately after the
336 inferior has stopped in the dynamic linker hook, and becomes
337 invalid as soon as the inferior is continued. Clients should make
338 a copy of this string if they wish to continue the inferior and
339 then access the string. */
341 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
342 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
345 /* This function returns a pointer to the string representation of the
346 pathname of the dynamically-linked library that has just been
349 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
350 TRUE, or undefined results are guaranteed.
352 This string's contents are only valid immediately after the
353 inferior has stopped in the dynamic linker hook, and becomes
354 invalid as soon as the inferior is continued. Clients should make
355 a copy of this string if they wish to continue the inferior and
356 then access the string. */
358 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
359 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
362 /* This function is called by the "catch load" command. It allows the
363 debugger to be notified by the dynamic linker when a specified
364 library file (or any library file, if filename is NULL) is loaded. */
366 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
367 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
368 error (_("catch of library loads not yet implemented on this platform"))
371 /* This function is called by the "catch unload" command. It allows
372 the debugger to be notified by the dynamic linker when a specified
373 library file (or any library file, if filename is NULL) is
376 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
377 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
378 error (_("catch of library unloads not yet implemented on this platform"))
381 /* Return whether a breakpoint is an active enabled breakpoint. */
383 breakpoint_enabled (struct breakpoint
*b
)
385 return (b
->enable_state
== bp_enabled
);
388 /* Set breakpoint count to NUM. */
391 set_breakpoint_count (int num
)
393 breakpoint_count
= num
;
394 set_internalvar (lookup_internalvar ("bpnum"),
395 value_from_longest (builtin_type_int32
, (LONGEST
) num
));
398 /* Used in run_command to zero the hit count when a new run starts. */
401 clear_breakpoint_hit_counts (void)
403 struct breakpoint
*b
;
409 /* Default address, symtab and line to put a breakpoint at
410 for "break" command with no arg.
411 if default_breakpoint_valid is zero, the other three are
412 not valid, and "break" with no arg is an error.
414 This set by print_stack_frame, which calls set_default_breakpoint. */
416 int default_breakpoint_valid
;
417 CORE_ADDR default_breakpoint_address
;
418 struct symtab
*default_breakpoint_symtab
;
419 int default_breakpoint_line
;
421 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
422 Advance *PP after the string and any trailing whitespace.
424 Currently the string can either be a number or "$" followed by the name
425 of a convenience variable. Making it an expression wouldn't work well
426 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
428 If the string is a NULL pointer, that denotes the last breakpoint.
430 TRAILER is a character which can be found after the number; most
431 commonly this is `-'. If you don't want a trailer, use \0. */
433 get_number_trailer (char **pp
, int trailer
)
435 int retval
= 0; /* default */
439 /* Empty line means refer to the last breakpoint. */
440 return breakpoint_count
;
443 /* Make a copy of the name, so we can null-terminate it
444 to pass to lookup_internalvar(). */
449 while (isalnum (*p
) || *p
== '_')
451 varname
= (char *) alloca (p
- start
+ 1);
452 strncpy (varname
, start
, p
- start
);
453 varname
[p
- start
] = '\0';
454 val
= value_of_internalvar (lookup_internalvar (varname
));
455 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
456 retval
= (int) value_as_long (val
);
459 printf_filtered (_("Convenience variable must have integer value.\n"));
467 while (*p
>= '0' && *p
<= '9')
470 /* There is no number here. (e.g. "cond a == b"). */
472 /* Skip non-numeric token */
473 while (*p
&& !isspace((int) *p
))
475 /* Return zero, which caller must interpret as error. */
481 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
483 /* Trailing junk: return 0 and let caller print error msg. */
484 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
495 /* Like get_number_trailer, but don't allow a trailer. */
497 get_number (char **pp
)
499 return get_number_trailer (pp
, '\0');
502 /* Parse a number or a range.
503 * A number will be of the form handled by get_number.
504 * A range will be of the form <number1> - <number2>, and
505 * will represent all the integers between number1 and number2,
508 * While processing a range, this fuction is called iteratively;
509 * At each call it will return the next value in the range.
511 * At the beginning of parsing a range, the char pointer PP will
512 * be advanced past <number1> and left pointing at the '-' token.
513 * Subsequent calls will not advance the pointer until the range
514 * is completed. The call that completes the range will advance
515 * pointer PP past <number2>.
519 get_number_or_range (char **pp
)
521 static int last_retval
, end_value
;
522 static char *end_ptr
;
523 static int in_range
= 0;
527 /* Default case: pp is pointing either to a solo number,
528 or to the first number of a range. */
529 last_retval
= get_number_trailer (pp
, '-');
534 /* This is the start of a range (<number1> - <number2>).
535 Skip the '-', parse and remember the second number,
536 and also remember the end of the final token. */
540 while (isspace ((int) *end_ptr
))
541 end_ptr
++; /* skip white space */
542 end_value
= get_number (temp
);
543 if (end_value
< last_retval
)
545 error (_("inverted range"));
547 else if (end_value
== last_retval
)
549 /* degenerate range (number1 == number2). Advance the
550 token pointer so that the range will be treated as a
559 error (_("negative value"));
562 /* pp points to the '-' that betokens a range. All
563 number-parsing has already been done. Return the next
564 integer value (one greater than the saved previous value).
565 Do not advance the token pointer 'pp' until the end of range
568 if (++last_retval
== end_value
)
570 /* End of range reached; advance token pointer. */
580 /* condition N EXP -- set break condition of breakpoint N to EXP. */
583 condition_command (char *arg
, int from_tty
)
585 struct breakpoint
*b
;
590 error_no_arg (_("breakpoint number"));
593 bnum
= get_number (&p
);
595 error (_("Bad breakpoint argument: '%s'"), arg
);
598 if (b
->number
== bnum
)
600 struct bp_location
*loc
= b
->loc
;
601 for (; loc
; loc
= loc
->next
)
609 if (b
->cond_string
!= NULL
)
610 xfree (b
->cond_string
);
614 b
->cond_string
= NULL
;
616 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
621 /* I don't know if it matters whether this is the string the user
622 typed in or the decompiled expression. */
623 b
->cond_string
= savestring (arg
, strlen (arg
));
624 b
->condition_not_parsed
= 0;
625 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
629 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
631 error (_("Junk at end of expression"));
634 breakpoints_changed ();
635 observer_notify_breakpoint_modified (b
->number
);
639 error (_("No breakpoint number %d."), bnum
);
643 commands_command (char *arg
, int from_tty
)
645 struct breakpoint
*b
;
648 struct command_line
*l
;
650 /* If we allowed this, we would have problems with when to
651 free the storage, if we change the commands currently
654 if (executing_breakpoint_commands
)
655 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
658 bnum
= get_number (&p
);
661 error (_("Unexpected extra arguments following breakpoint number."));
664 if (b
->number
== bnum
)
666 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
668 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
669 l
= read_command_lines (tmpbuf
, from_tty
, 1);
670 do_cleanups (cleanups
);
671 free_command_lines (&b
->commands
);
673 breakpoints_changed ();
674 observer_notify_breakpoint_modified (b
->number
);
677 error (_("No breakpoint number %d."), bnum
);
680 /* Like commands_command, but instead of reading the commands from
681 input stream, takes them from an already parsed command structure.
683 This is used by cli-script.c to DTRT with breakpoint commands
684 that are part of if and while bodies. */
685 enum command_control_type
686 commands_from_control_command (char *arg
, struct command_line
*cmd
)
688 struct breakpoint
*b
;
692 /* If we allowed this, we would have problems with when to
693 free the storage, if we change the commands currently
696 if (executing_breakpoint_commands
)
697 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
699 /* An empty string for the breakpoint number means the last
700 breakpoint, but get_number expects a NULL pointer. */
705 bnum
= get_number (&p
);
708 error (_("Unexpected extra arguments following breakpoint number."));
711 if (b
->number
== bnum
)
713 free_command_lines (&b
->commands
);
714 if (cmd
->body_count
!= 1)
715 error (_("Invalid \"commands\" block structure."));
716 /* We need to copy the commands because if/while will free the
717 list after it finishes execution. */
718 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
719 breakpoints_changed ();
720 observer_notify_breakpoint_modified (b
->number
);
721 return simple_control
;
723 error (_("No breakpoint number %d."), bnum
);
726 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
727 by replacing any memory breakpoints with their shadowed contents. */
730 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
732 struct bp_location
*b
;
733 CORE_ADDR bp_addr
= 0;
739 if (b
->owner
->type
== bp_none
)
740 warning (_("reading through apparently deleted breakpoint #%d?"),
743 if (b
->loc_type
!= bp_loc_software_breakpoint
)
747 /* Addresses and length of the part of the breakpoint that
749 bp_addr
= b
->target_info
.placed_address
;
750 bp_size
= b
->target_info
.shadow_len
;
752 /* bp isn't valid, or doesn't shadow memory. */
755 if (bp_addr
+ bp_size
<= memaddr
)
756 /* The breakpoint is entirely before the chunk of memory we
760 if (bp_addr
>= memaddr
+ len
)
761 /* The breakpoint is entirely after the chunk of memory we are
765 /* Offset within shadow_contents. */
766 if (bp_addr
< memaddr
)
768 /* Only copy the second part of the breakpoint. */
769 bp_size
-= memaddr
- bp_addr
;
770 bptoffset
= memaddr
- bp_addr
;
774 if (bp_addr
+ bp_size
> memaddr
+ len
)
776 /* Only copy the first part of the breakpoint. */
777 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
780 memcpy (buf
+ bp_addr
- memaddr
,
781 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
786 /* A wrapper function for inserting catchpoints. */
788 insert_catchpoint (struct ui_out
*uo
, void *args
)
790 struct breakpoint
*b
= (struct breakpoint
*) args
;
793 gdb_assert (b
->type
== bp_catchpoint
);
794 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
800 is_hardware_watchpoint (struct breakpoint
*bpt
)
802 return (bpt
->type
== bp_hardware_watchpoint
803 || bpt
->type
== bp_read_watchpoint
804 || bpt
->type
== bp_access_watchpoint
);
807 /* Find the current value of a watchpoint on EXP. Return the value in
808 *VALP and *RESULTP and the chain of intermediate and final values
809 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
812 If an error occurs while evaluating the expression, *RESULTP will
813 be set to NULL. *RESULTP may be a lazy value, if the result could
814 not be read from memory. It is used to determine whether a value
815 is user-specified (we should watch the whole value) or intermediate
816 (we should watch only the bit used to locate the final value).
818 If the final value, or any intermediate value, could not be read
819 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
820 set to any referenced values. *VALP will never be a lazy value.
821 This is the value which we store in struct breakpoint.
823 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
824 value chain. The caller must free the values individually. If
825 VAL_CHAIN is NULL, all generated values will be left on the value
829 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
830 struct value
**resultp
, struct value
**val_chain
)
832 struct value
*mark
, *new_mark
, *result
;
840 /* Evaluate the expression. */
841 mark
= value_mark ();
843 gdb_evaluate_expression (exp
, &result
);
844 new_mark
= value_mark ();
845 if (mark
== new_mark
)
850 /* Make sure it's not lazy, so that after the target stops again we
851 have a non-lazy previous value to compare with. */
853 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
858 /* Return the chain of intermediate values. We use this to
859 decide which addresses to watch. */
860 *val_chain
= new_mark
;
861 value_release_to_mark (mark
);
865 /* Assuming that B is a hardware watchpoint:
866 - Reparse watchpoint expression, is REPARSE is non-zero
867 - Evaluate expression and store the result in B->val
868 - Update the list of values that must be watched in B->loc.
870 If the watchpoint is disabled, do nothing. If this is
871 local watchpoint that is out of scope, delete it. */
873 update_watchpoint (struct breakpoint
*b
, int reparse
)
875 int within_current_scope
;
876 struct frame_id saved_frame_id
;
877 struct bp_location
*loc
;
880 /* We don't free locations. They are stored in
881 bp_location_chain and update_global_locations will
882 eventually delete them and remove breakpoints if
886 if (b
->disposition
== disp_del_at_next_stop
)
889 /* Save the current frame's ID so we can restore it after
890 evaluating the watchpoint expression on its own frame. */
891 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
892 took a frame parameter, so that we didn't have to change the
894 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
896 /* Determine if the watchpoint is within scope. */
897 if (b
->exp_valid_block
== NULL
)
898 within_current_scope
= 1;
901 struct frame_info
*fi
;
902 fi
= frame_find_by_id (b
->watchpoint_frame
);
903 within_current_scope
= (fi
!= NULL
);
904 if (within_current_scope
)
908 if (within_current_scope
&& reparse
)
917 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
918 /* If the meaning of expression itself changed, the old value is
919 no longer relevant. We don't want to report a watchpoint hit
920 to the user when the old value and the new value may actually
921 be completely different objects. */
927 /* If we failed to parse the expression, for example because
928 it refers to a global variable in a not-yet-loaded shared library,
929 don't try to insert watchpoint. We don't automatically delete
930 such watchpoint, though, since failure to parse expression
931 is different from out-of-scope watchpoint. */
932 if (within_current_scope
&& b
->exp
)
934 struct value
*val_chain
, *v
, *result
, *next
;
936 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
938 /* Avoid setting b->val if it's already set. The meaning of
939 b->val is 'the last value' user saw, and we should update
940 it only if we reported that last value to user. As it
941 happens, the code that reports it updates b->val directly. */
948 /* Look at each value on the value chain. */
949 for (v
= val_chain
; v
; v
= next
)
951 /* If it's a memory location, and GDB actually needed
952 its contents to evaluate the expression, then we
953 must watch it. If the first value returned is
954 still lazy, that means an error occurred reading it;
955 watch it anyway in case it becomes readable. */
956 if (VALUE_LVAL (v
) == lval_memory
957 && (v
== val_chain
|| ! value_lazy (v
)))
959 struct type
*vtype
= check_typedef (value_type (v
));
961 /* We only watch structs and arrays if user asked
962 for it explicitly, never if they just happen to
963 appear in the middle of some value chain. */
965 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
966 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
970 struct bp_location
*loc
, **tmp
;
972 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
973 len
= TYPE_LENGTH (value_type (v
));
975 if (b
->type
== bp_read_watchpoint
)
977 else if (b
->type
== bp_access_watchpoint
)
980 loc
= allocate_bp_location (b
, bp_hardware_watchpoint
);
981 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
986 loc
->watchpoint_type
= type
;
990 next
= value_next (v
);
995 /* We just regenerated the list of breakpoint locations.
996 The new location does not have its condition field set to anything
997 and therefore, we must always reparse the cond_string, independently
998 of the value of the reparse flag. */
999 if (b
->cond_string
!= NULL
)
1001 char *s
= b
->cond_string
;
1002 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1005 else if (!within_current_scope
)
1007 printf_filtered (_("\
1008 Hardware watchpoint %d deleted because the program has left the block \n\
1009 in which its expression is valid.\n"),
1011 if (b
->related_breakpoint
)
1012 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1013 b
->disposition
= disp_del_at_next_stop
;
1016 /* Restore the selected frame. */
1017 select_frame (frame_find_by_id (saved_frame_id
));
1021 /* Returns 1 iff breakpoint location should be
1022 inserted in the inferior. */
1024 should_be_inserted (struct bp_location
*bpt
)
1026 if (!breakpoint_enabled (bpt
->owner
))
1029 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1032 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1038 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1039 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1040 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1042 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1043 method for each breakpoint or catchpoint type. */
1045 insert_bp_location (struct bp_location
*bpt
,
1046 struct ui_file
*tmp_error_stream
,
1047 int *disabled_breaks
, int *process_warning
,
1048 int *hw_breakpoint_error
)
1052 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1055 /* Initialize the target-specific information. */
1056 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1057 bpt
->target_info
.placed_address
= bpt
->address
;
1059 if (bpt
->loc_type
== bp_loc_software_breakpoint
1060 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1062 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1064 /* If the explicitly specified breakpoint type
1065 is not hardware breakpoint, check the memory map to see
1066 if the breakpoint address is in read only memory or not.
1067 Two important cases are:
1068 - location type is not hardware breakpoint, memory
1069 is readonly. We change the type of the location to
1070 hardware breakpoint.
1071 - location type is hardware breakpoint, memory is read-write.
1072 This means we've previously made the location hardware one, but
1073 then the memory map changed, so we undo.
1075 When breakpoints are removed, remove_breakpoints will
1076 use location types we've just set here, the only possible
1077 problem is that memory map has changed during running program,
1078 but it's not going to work anyway with current gdb. */
1079 struct mem_region
*mr
1080 = lookup_mem_region (bpt
->target_info
.placed_address
);
1084 if (automatic_hardware_breakpoints
)
1087 enum bp_loc_type new_type
;
1089 if (mr
->attrib
.mode
!= MEM_RW
)
1090 new_type
= bp_loc_hardware_breakpoint
;
1092 new_type
= bp_loc_software_breakpoint
;
1094 if (new_type
!= bpt
->loc_type
)
1096 static int said
= 0;
1097 bpt
->loc_type
= new_type
;
1100 fprintf_filtered (gdb_stdout
, _("\
1101 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1106 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1107 && mr
->attrib
.mode
!= MEM_RW
)
1108 warning (_("cannot set software breakpoint at readonly address %s"),
1109 paddr (bpt
->address
));
1113 /* First check to see if we have to handle an overlay. */
1114 if (overlay_debugging
== ovly_off
1115 || bpt
->section
== NULL
1116 || !(section_is_overlay (bpt
->section
)))
1118 /* No overlay handling: just set the breakpoint. */
1120 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1121 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1123 val
= target_insert_breakpoint (&bpt
->target_info
);
1127 /* This breakpoint is in an overlay section.
1128 Shall we set a breakpoint at the LMA? */
1129 if (!overlay_events_enabled
)
1131 /* Yes -- overlay event support is not active,
1132 so we must try to set a breakpoint at the LMA.
1133 This will not work for a hardware breakpoint. */
1134 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1135 warning (_("hardware breakpoint %d not supported in overlay!"),
1136 bpt
->owner
->number
);
1139 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1141 /* Set a software (trap) breakpoint at the LMA. */
1142 bpt
->overlay_target_info
= bpt
->target_info
;
1143 bpt
->overlay_target_info
.placed_address
= addr
;
1144 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1146 fprintf_unfiltered (tmp_error_stream
,
1147 "Overlay breakpoint %d failed: in ROM?",
1148 bpt
->owner
->number
);
1151 /* Shall we set a breakpoint at the VMA? */
1152 if (section_is_mapped (bpt
->section
))
1154 /* Yes. This overlay section is mapped into memory. */
1155 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1156 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1158 val
= target_insert_breakpoint (&bpt
->target_info
);
1162 /* No. This breakpoint will not be inserted.
1163 No error, but do not mark the bp as 'inserted'. */
1170 /* Can't set the breakpoint. */
1171 if (solib_address (bpt
->address
))
1173 /* See also: disable_breakpoints_in_shlibs. */
1175 bpt
->shlib_disabled
= 1;
1176 if (!*disabled_breaks
)
1178 fprintf_unfiltered (tmp_error_stream
,
1179 "Cannot insert breakpoint %d.\n",
1180 bpt
->owner
->number
);
1181 fprintf_unfiltered (tmp_error_stream
,
1182 "Temporarily disabling shared library breakpoints:\n");
1184 *disabled_breaks
= 1;
1185 fprintf_unfiltered (tmp_error_stream
,
1186 "breakpoint #%d\n", bpt
->owner
->number
);
1190 #ifdef ONE_PROCESS_WRITETEXT
1191 *process_warning
= 1;
1193 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1195 *hw_breakpoint_error
= 1;
1196 fprintf_unfiltered (tmp_error_stream
,
1197 "Cannot insert hardware breakpoint %d.\n",
1198 bpt
->owner
->number
);
1202 fprintf_unfiltered (tmp_error_stream
,
1203 "Cannot insert breakpoint %d.\n",
1204 bpt
->owner
->number
);
1205 fprintf_filtered (tmp_error_stream
,
1206 "Error accessing memory address ");
1207 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1208 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1209 safe_strerror (val
));
1220 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1221 /* NOTE drow/2003-09-08: This state only exists for removing
1222 watchpoints. It's not clear that it's necessary... */
1223 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1225 val
= target_insert_watchpoint (bpt
->address
,
1227 bpt
->watchpoint_type
);
1228 bpt
->inserted
= (val
!= -1);
1231 else if (bpt
->owner
->type
== bp_catchpoint
)
1233 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1234 bpt
->owner
, RETURN_MASK_ERROR
);
1235 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1236 bpt
->owner
->number
);
1238 bpt
->owner
->enable_state
= bp_disabled
;
1242 /* We've already printed an error message if there was a problem
1243 inserting this catchpoint, and we've disabled the catchpoint,
1244 so just return success. */
1251 /* Make sure all breakpoints are inserted in inferior.
1252 Throws exception on any error.
1253 A breakpoint that is already inserted won't be inserted
1254 again, so calling this function twice is safe. */
1256 insert_breakpoints (void)
1258 struct breakpoint
*bpt
;
1260 ALL_BREAKPOINTS (bpt
)
1261 if (is_hardware_watchpoint (bpt
))
1262 update_watchpoint (bpt
, 0 /* don't reparse. */);
1264 update_global_location_list (1);
1266 if (!breakpoints_always_inserted_mode ()
1267 && (target_has_execution
1268 || (gdbarch_has_global_solist (target_gdbarch
)
1269 && target_supports_multi_process ())))
1270 /* update_global_location_list does not insert breakpoints
1271 when always_inserted_mode is not enabled. Explicitly
1273 insert_breakpoint_locations ();
1276 /* insert_breakpoints is used when starting or continuing the program.
1277 remove_breakpoints is used when the program stops.
1278 Both return zero if successful,
1279 or an `errno' value if could not write the inferior. */
1282 insert_breakpoint_locations (void)
1284 struct breakpoint
*bpt
;
1285 struct bp_location
*b
, *temp
;
1288 int disabled_breaks
= 0;
1289 int hw_breakpoint_error
= 0;
1290 int process_warning
= 0;
1292 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1293 make_cleanup_ui_file_delete (tmp_error_stream
);
1295 /* Explicitly mark the warning -- this will only be printed if
1296 there was an error. */
1297 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1299 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1301 if (!should_be_inserted (b
) || b
->inserted
)
1304 /* There is no point inserting thread-specific breakpoints if the
1305 thread no longer exists. */
1306 if (b
->owner
->thread
!= -1
1307 && !valid_thread_id (b
->owner
->thread
))
1310 val
= insert_bp_location (b
, tmp_error_stream
,
1311 &disabled_breaks
, &process_warning
,
1312 &hw_breakpoint_error
);
1317 /* If we failed to insert all locations of a watchpoint,
1318 remove them, as half-inserted watchpoint is of limited use. */
1319 ALL_BREAKPOINTS (bpt
)
1321 int some_failed
= 0;
1322 struct bp_location
*loc
;
1324 if (!is_hardware_watchpoint (bpt
))
1327 if (!breakpoint_enabled (bpt
))
1330 if (bpt
->disposition
== disp_del_at_next_stop
)
1333 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1341 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1343 remove_breakpoint (loc
, mark_uninserted
);
1345 hw_breakpoint_error
= 1;
1346 fprintf_unfiltered (tmp_error_stream
,
1347 "Could not insert hardware watchpoint %d.\n",
1355 /* If a hardware breakpoint or watchpoint was inserted, add a
1356 message about possibly exhausted resources. */
1357 if (hw_breakpoint_error
)
1359 fprintf_unfiltered (tmp_error_stream
,
1360 "Could not insert hardware breakpoints:\n\
1361 You may have requested too many hardware breakpoints/watchpoints.\n");
1363 #ifdef ONE_PROCESS_WRITETEXT
1364 if (process_warning
)
1365 fprintf_unfiltered (tmp_error_stream
,
1366 "The same program may be running in another process.");
1368 target_terminal_ours_for_output ();
1369 error_stream (tmp_error_stream
);
1374 remove_breakpoints (void)
1376 struct bp_location
*b
;
1379 ALL_BP_LOCATIONS (b
)
1383 val
= remove_breakpoint (b
, mark_uninserted
);
1392 remove_hw_watchpoints (void)
1394 struct bp_location
*b
;
1397 ALL_BP_LOCATIONS (b
)
1399 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1401 val
= remove_breakpoint (b
, mark_uninserted
);
1410 reattach_breakpoints (int pid
)
1412 struct bp_location
*b
;
1414 struct cleanup
*old_chain
= save_inferior_ptid ();
1415 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1416 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1418 make_cleanup_ui_file_delete (tmp_error_stream
);
1420 inferior_ptid
= pid_to_ptid (pid
);
1421 ALL_BP_LOCATIONS (b
)
1426 val
= insert_bp_location (b
, tmp_error_stream
,
1427 &dummy1
, &dummy2
, &dummy3
);
1430 do_cleanups (old_chain
);
1435 do_cleanups (old_chain
);
1440 update_breakpoints_after_exec (void)
1442 struct breakpoint
*b
;
1443 struct breakpoint
*temp
;
1444 struct bp_location
*bploc
;
1446 /* We're about to delete breakpoints from GDB's lists. If the
1447 INSERTED flag is true, GDB will try to lift the breakpoints by
1448 writing the breakpoints' "shadow contents" back into memory. The
1449 "shadow contents" are NOT valid after an exec, so GDB should not
1450 do that. Instead, the target is responsible from marking
1451 breakpoints out as soon as it detects an exec. We don't do that
1452 here instead, because there may be other attempts to delete
1453 breakpoints after detecting an exec and before reaching here. */
1454 ALL_BP_LOCATIONS (bploc
)
1455 gdb_assert (!bploc
->inserted
);
1457 ALL_BREAKPOINTS_SAFE (b
, temp
)
1459 /* Solib breakpoints must be explicitly reset after an exec(). */
1460 if (b
->type
== bp_shlib_event
)
1462 delete_breakpoint (b
);
1466 /* Thread event breakpoints must be set anew after an exec(),
1467 as must overlay event breakpoints. */
1468 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1470 delete_breakpoint (b
);
1474 /* Step-resume breakpoints are meaningless after an exec(). */
1475 if (b
->type
== bp_step_resume
)
1477 delete_breakpoint (b
);
1481 /* Longjmp and longjmp-resume breakpoints are also meaningless
1483 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1485 delete_breakpoint (b
);
1489 if (b
->type
== bp_catchpoint
)
1491 /* For now, none of the bp_catchpoint breakpoints need to
1492 do anything at this point. In the future, if some of
1493 the catchpoints need to something, we will need to add
1494 a new method, and call this method from here. */
1498 /* bp_finish is a special case. The only way we ought to be able
1499 to see one of these when an exec() has happened, is if the user
1500 caught a vfork, and then said "finish". Ordinarily a finish just
1501 carries them to the call-site of the current callee, by setting
1502 a temporary bp there and resuming. But in this case, the finish
1503 will carry them entirely through the vfork & exec.
1505 We don't want to allow a bp_finish to remain inserted now. But
1506 we can't safely delete it, 'cause finish_command has a handle to
1507 the bp on a bpstat, and will later want to delete it. There's a
1508 chance (and I've seen it happen) that if we delete the bp_finish
1509 here, that its storage will get reused by the time finish_command
1510 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1511 We really must allow finish_command to delete a bp_finish.
1513 In the absense of a general solution for the "how do we know
1514 it's safe to delete something others may have handles to?"
1515 problem, what we'll do here is just uninsert the bp_finish, and
1516 let finish_command delete it.
1518 (We know the bp_finish is "doomed" in the sense that it's
1519 momentary, and will be deleted as soon as finish_command sees
1520 the inferior stopped. So it doesn't matter that the bp's
1521 address is probably bogus in the new a.out, unlike e.g., the
1522 solib breakpoints.) */
1524 if (b
->type
== bp_finish
)
1529 /* Without a symbolic address, we have little hope of the
1530 pre-exec() address meaning the same thing in the post-exec()
1532 if (b
->addr_string
== NULL
)
1534 delete_breakpoint (b
);
1538 /* FIXME what about longjmp breakpoints? Re-create them here? */
1539 create_overlay_event_breakpoint ("_ovly_debug_event");
1543 detach_breakpoints (int pid
)
1545 struct bp_location
*b
;
1547 struct cleanup
*old_chain
= save_inferior_ptid ();
1549 if (pid
== PIDGET (inferior_ptid
))
1550 error (_("Cannot detach breakpoints of inferior_ptid"));
1552 /* Set inferior_ptid; remove_breakpoint uses this global. */
1553 inferior_ptid
= pid_to_ptid (pid
);
1554 ALL_BP_LOCATIONS (b
)
1558 val
= remove_breakpoint (b
, mark_inserted
);
1561 do_cleanups (old_chain
);
1566 do_cleanups (old_chain
);
1571 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1575 if (b
->owner
->enable_state
== bp_permanent
)
1576 /* Permanent breakpoints cannot be inserted or removed. */
1579 /* The type of none suggests that owner is actually deleted.
1580 This should not ever happen. */
1581 gdb_assert (b
->owner
->type
!= bp_none
);
1583 if (b
->loc_type
== bp_loc_software_breakpoint
1584 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1586 /* "Normal" instruction breakpoint: either the standard
1587 trap-instruction bp (bp_breakpoint), or a
1588 bp_hardware_breakpoint. */
1590 /* First check to see if we have to handle an overlay. */
1591 if (overlay_debugging
== ovly_off
1592 || b
->section
== NULL
1593 || !(section_is_overlay (b
->section
)))
1595 /* No overlay handling: just remove the breakpoint. */
1597 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1598 val
= target_remove_hw_breakpoint (&b
->target_info
);
1600 val
= target_remove_breakpoint (&b
->target_info
);
1604 /* This breakpoint is in an overlay section.
1605 Did we set a breakpoint at the LMA? */
1606 if (!overlay_events_enabled
)
1608 /* Yes -- overlay event support is not active, so we
1609 should have set a breakpoint at the LMA. Remove it.
1611 /* Ignore any failures: if the LMA is in ROM, we will
1612 have already warned when we failed to insert it. */
1613 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1614 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1616 target_remove_breakpoint (&b
->overlay_target_info
);
1618 /* Did we set a breakpoint at the VMA?
1619 If so, we will have marked the breakpoint 'inserted'. */
1622 /* Yes -- remove it. Previously we did not bother to
1623 remove the breakpoint if the section had been
1624 unmapped, but let's not rely on that being safe. We
1625 don't know what the overlay manager might do. */
1626 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1627 val
= target_remove_hw_breakpoint (&b
->target_info
);
1629 /* However, we should remove *software* breakpoints only
1630 if the section is still mapped, or else we overwrite
1631 wrong code with the saved shadow contents. */
1632 else if (section_is_mapped (b
->section
))
1633 val
= target_remove_breakpoint (&b
->target_info
);
1639 /* No -- not inserted, so no need to remove. No error. */
1644 /* In some cases, we might not be able to remove a breakpoint
1645 in a shared library that has already been removed, but we
1646 have not yet processed the shlib unload event. */
1647 if (val
&& solib_address (b
->address
))
1652 b
->inserted
= (is
== mark_inserted
);
1654 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1659 b
->inserted
= (is
== mark_inserted
);
1660 val
= target_remove_watchpoint (b
->address
, b
->length
,
1661 b
->watchpoint_type
);
1663 /* Failure to remove any of the hardware watchpoints comes here. */
1664 if ((is
== mark_uninserted
) && (b
->inserted
))
1665 warning (_("Could not remove hardware watchpoint %d."),
1668 else if (b
->owner
->type
== bp_catchpoint
1669 && breakpoint_enabled (b
->owner
)
1672 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
1674 val
= b
->owner
->ops
->remove (b
->owner
);
1677 b
->inserted
= (is
== mark_inserted
);
1683 /* Clear the "inserted" flag in all breakpoints. */
1686 mark_breakpoints_out (void)
1688 struct bp_location
*bpt
;
1690 ALL_BP_LOCATIONS (bpt
)
1694 /* Clear the "inserted" flag in all breakpoints and delete any
1695 breakpoints which should go away between runs of the program.
1697 Plus other such housekeeping that has to be done for breakpoints
1700 Note: this function gets called at the end of a run (by
1701 generic_mourn_inferior) and when a run begins (by
1702 init_wait_for_inferior). */
1707 breakpoint_init_inferior (enum inf_context context
)
1709 struct breakpoint
*b
, *temp
;
1710 struct bp_location
*bpt
;
1713 /* If breakpoint locations are shared across processes, then there's
1715 if (gdbarch_has_global_solist (target_gdbarch
))
1718 ALL_BP_LOCATIONS (bpt
)
1719 if (bpt
->owner
->enable_state
!= bp_permanent
)
1722 ALL_BREAKPOINTS_SAFE (b
, temp
)
1727 case bp_watchpoint_scope
:
1729 /* If the call dummy breakpoint is at the entry point it will
1730 cause problems when the inferior is rerun, so we better
1733 Also get rid of scope breakpoints. */
1734 delete_breakpoint (b
);
1738 case bp_hardware_watchpoint
:
1739 case bp_read_watchpoint
:
1740 case bp_access_watchpoint
:
1742 /* Likewise for watchpoints on local expressions. */
1743 if (b
->exp_valid_block
!= NULL
)
1744 delete_breakpoint (b
);
1745 else if (context
== inf_starting
)
1747 /* Reset val field to force reread of starting value
1748 in insert_breakpoints. */
1750 value_free (b
->val
);
1760 /* Get rid of the moribund locations. */
1761 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
1762 free_bp_location (bpt
);
1763 VEC_free (bp_location_p
, moribund_locations
);
1766 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1767 exists at PC. It returns ordinary_breakpoint_here if it's an
1768 ordinary breakpoint, or permanent_breakpoint_here if it's a
1769 permanent breakpoint.
1770 - When continuing from a location with an ordinary breakpoint, we
1771 actually single step once before calling insert_breakpoints.
1772 - When continuing from a localion with a permanent breakpoint, we
1773 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1774 the target, to advance the PC past the breakpoint. */
1776 enum breakpoint_here
1777 breakpoint_here_p (CORE_ADDR pc
)
1779 const struct bp_location
*bpt
;
1780 int any_breakpoint_here
= 0;
1782 ALL_BP_LOCATIONS (bpt
)
1784 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1785 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1788 if ((breakpoint_enabled (bpt
->owner
)
1789 || bpt
->owner
->enable_state
== bp_permanent
)
1790 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1792 if (overlay_debugging
1793 && section_is_overlay (bpt
->section
)
1794 && !section_is_mapped (bpt
->section
))
1795 continue; /* unmapped overlay -- can't be a match */
1796 else if (bpt
->owner
->enable_state
== bp_permanent
)
1797 return permanent_breakpoint_here
;
1799 any_breakpoint_here
= 1;
1803 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1806 /* Return true if there's a moribund breakpoint at PC. */
1809 moribund_breakpoint_here_p (CORE_ADDR pc
)
1811 struct bp_location
*loc
;
1814 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
1815 if (loc
->address
== pc
)
1821 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1822 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1823 This does not check for single-step breakpoints, which are
1824 inserted and removed using direct target manipulation. */
1827 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1829 const struct bp_location
*bpt
;
1831 ALL_BP_LOCATIONS (bpt
)
1833 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1834 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1838 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1840 if (overlay_debugging
1841 && section_is_overlay (bpt
->section
)
1842 && !section_is_mapped (bpt
->section
))
1843 continue; /* unmapped overlay -- can't be a match */
1851 /* Returns non-zero iff there's either regular breakpoint
1852 or a single step breakpoint inserted at PC. */
1855 breakpoint_inserted_here_p (CORE_ADDR pc
)
1857 if (regular_breakpoint_inserted_here_p (pc
))
1860 if (single_step_breakpoint_inserted_here_p (pc
))
1866 /* This function returns non-zero iff there is a software breakpoint
1870 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1872 const struct bp_location
*bpt
;
1873 int any_breakpoint_here
= 0;
1875 ALL_BP_LOCATIONS (bpt
)
1877 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1881 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1883 if (overlay_debugging
1884 && section_is_overlay (bpt
->section
)
1885 && !section_is_mapped (bpt
->section
))
1886 continue; /* unmapped overlay -- can't be a match */
1892 /* Also check for software single-step breakpoints. */
1893 if (single_step_breakpoint_inserted_here_p (pc
))
1899 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1900 PC is valid for process/thread PTID. */
1903 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1905 const struct bp_location
*bpt
;
1908 thread
= pid_to_thread_id (ptid
);
1910 ALL_BP_LOCATIONS (bpt
)
1912 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1913 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1916 if ((breakpoint_enabled (bpt
->owner
)
1917 || bpt
->owner
->enable_state
== bp_permanent
)
1918 && bpt
->address
== pc
1919 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1921 if (overlay_debugging
1922 && section_is_overlay (bpt
->section
)
1923 && !section_is_mapped (bpt
->section
))
1924 continue; /* unmapped overlay -- can't be a match */
1934 /* bpstat stuff. External routines' interfaces are documented
1938 ep_is_catchpoint (struct breakpoint
*ep
)
1940 return (ep
->type
== bp_catchpoint
);
1944 bpstat_free (bpstat bs
)
1946 if (bs
->old_val
!= NULL
)
1947 value_free (bs
->old_val
);
1948 free_command_lines (&bs
->commands
);
1952 /* Clear a bpstat so that it says we are not at any breakpoint.
1953 Also free any storage that is part of a bpstat. */
1956 bpstat_clear (bpstat
*bsp
)
1973 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1974 is part of the bpstat is copied as well. */
1977 bpstat_copy (bpstat bs
)
1981 bpstat retval
= NULL
;
1986 for (; bs
!= NULL
; bs
= bs
->next
)
1988 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1989 memcpy (tmp
, bs
, sizeof (*tmp
));
1990 if (bs
->commands
!= NULL
)
1991 tmp
->commands
= copy_command_lines (bs
->commands
);
1992 if (bs
->old_val
!= NULL
)
1994 tmp
->old_val
= value_copy (bs
->old_val
);
1995 release_value (tmp
->old_val
);
1999 /* This is the first thing in the chain. */
2009 /* Find the bpstat associated with this breakpoint */
2012 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2017 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2019 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2025 /* Find a step_resume breakpoint associated with this bpstat.
2026 (If there are multiple step_resume bp's on the list, this function
2027 will arbitrarily pick one.)
2029 It is an error to use this function if BPSTAT doesn't contain a
2030 step_resume breakpoint.
2032 See wait_for_inferior's use of this function. */
2034 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2038 gdb_assert (bsp
!= NULL
);
2040 current_thread
= pid_to_thread_id (inferior_ptid
);
2042 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2044 if ((bsp
->breakpoint_at
!= NULL
) &&
2045 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2046 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2047 bsp
->breakpoint_at
->owner
->thread
== -1))
2048 return bsp
->breakpoint_at
->owner
;
2051 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2055 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2056 at. *BSP upon return is a bpstat which points to the remaining
2057 breakpoints stopped at (but which is not guaranteed to be good for
2058 anything but further calls to bpstat_num).
2059 Return 0 if passed a bpstat which does not indicate any breakpoints.
2060 Return -1 if stopped at a breakpoint that has been deleted since
2062 Return 1 otherwise. */
2065 bpstat_num (bpstat
*bsp
, int *num
)
2067 struct breakpoint
*b
;
2070 return 0; /* No more breakpoint values */
2072 /* We assume we'll never have several bpstats that
2073 correspond to a single breakpoint -- otherwise,
2074 this function might return the same number more
2075 than once and this will look ugly. */
2076 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2077 *bsp
= (*bsp
)->next
;
2079 return -1; /* breakpoint that's been deleted since */
2081 *num
= b
->number
; /* We have its number */
2085 /* Modify BS so that the actions will not be performed. */
2088 bpstat_clear_actions (bpstat bs
)
2090 for (; bs
!= NULL
; bs
= bs
->next
)
2092 free_command_lines (&bs
->commands
);
2093 if (bs
->old_val
!= NULL
)
2095 value_free (bs
->old_val
);
2101 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2103 cleanup_executing_breakpoints (void *ignore
)
2105 executing_breakpoint_commands
= 0;
2108 /* Execute all the commands associated with all the breakpoints at this
2109 location. Any of these commands could cause the process to proceed
2110 beyond this point, etc. We look out for such changes by checking
2111 the global "breakpoint_proceeded" after each command.
2113 Returns true if a breakpoint command resumed the inferior. In that
2114 case, it is the caller's responsibility to recall it again with the
2115 bpstat of the current thread. */
2118 bpstat_do_actions_1 (bpstat
*bsp
)
2121 struct cleanup
*old_chain
;
2124 /* Avoid endless recursion if a `source' command is contained
2126 if (executing_breakpoint_commands
)
2129 executing_breakpoint_commands
= 1;
2130 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2132 /* This pointer will iterate over the list of bpstat's. */
2135 breakpoint_proceeded
= 0;
2136 for (; bs
!= NULL
; bs
= bs
->next
)
2138 struct command_line
*cmd
;
2139 struct cleanup
*this_cmd_tree_chain
;
2141 /* Take ownership of the BSP's command tree, if it has one.
2143 The command tree could legitimately contain commands like
2144 'step' and 'next', which call clear_proceed_status, which
2145 frees stop_bpstat's command tree. To make sure this doesn't
2146 free the tree we're executing out from under us, we need to
2147 take ownership of the tree ourselves. Since a given bpstat's
2148 commands are only executed once, we don't need to copy it; we
2149 can clear the pointer in the bpstat, and make sure we free
2150 the tree when we're done. */
2153 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2157 execute_control_command (cmd
);
2159 if (breakpoint_proceeded
)
2165 /* We can free this command tree now. */
2166 do_cleanups (this_cmd_tree_chain
);
2168 if (breakpoint_proceeded
)
2170 if (target_can_async_p ())
2171 /* If we are in async mode, then the target might be still
2172 running, not stopped at any breakpoint, so nothing for
2173 us to do here -- just return to the event loop. */
2176 /* In sync mode, when execute_control_command returns
2177 we're already standing on the next breakpoint.
2178 Breakpoint commands for that stop were not run, since
2179 execute_command does not run breakpoint commands --
2180 only command_line_handler does, but that one is not
2181 involved in execution of breakpoint commands. So, we
2182 can now execute breakpoint commands. It should be
2183 noted that making execute_command do bpstat actions is
2184 not an option -- in this case we'll have recursive
2185 invocation of bpstat for each breakpoint with a
2186 command, and can easily blow up GDB stack. Instead, we
2187 return true, which will trigger the caller to recall us
2188 with the new stop_bpstat. */
2193 do_cleanups (old_chain
);
2198 bpstat_do_actions (void)
2200 /* Do any commands attached to breakpoint we are stopped at. */
2201 while (!ptid_equal (inferior_ptid
, null_ptid
)
2202 && target_has_execution
2203 && !is_exited (inferior_ptid
)
2204 && !is_executing (inferior_ptid
))
2205 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2206 and only return when it is stopped at the next breakpoint, we
2207 keep doing breakpoint actions until it returns false to
2208 indicate the inferior was not resumed. */
2209 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2213 /* Print out the (old or new) value associated with a watchpoint. */
2216 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2219 fprintf_unfiltered (stream
, _("<unreadable>"));
2222 struct value_print_options opts
;
2223 get_user_print_options (&opts
);
2224 value_print (val
, stream
, &opts
);
2228 /* This is the normal print function for a bpstat. In the future,
2229 much of this logic could (should?) be moved to bpstat_stop_status,
2230 by having it set different print_it values.
2232 Current scheme: When we stop, bpstat_print() is called. It loops
2233 through the bpstat list of things causing this stop, calling the
2234 print_bp_stop_message function on each one. The behavior of the
2235 print_bp_stop_message function depends on the print_it field of
2236 bpstat. If such field so indicates, call this function here.
2238 Return values from this routine (ultimately used by bpstat_print()
2239 and normal_stop() to decide what to do):
2240 PRINT_NOTHING: Means we already printed all we needed to print,
2241 don't print anything else.
2242 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2243 that something to be followed by a location.
2244 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2245 that something to be followed by a location.
2246 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2249 static enum print_stop_action
2250 print_it_typical (bpstat bs
)
2252 struct cleanup
*old_chain
, *ui_out_chain
;
2253 struct breakpoint
*b
;
2254 const struct bp_location
*bl
;
2255 struct ui_stream
*stb
;
2257 stb
= ui_out_stream_new (uiout
);
2258 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2259 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2260 which has since been deleted. */
2261 if (bs
->breakpoint_at
== NULL
)
2262 return PRINT_UNKNOWN
;
2263 bl
= bs
->breakpoint_at
;
2269 case bp_hardware_breakpoint
:
2270 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2271 if (bl
->address
!= bl
->requested_address
)
2272 breakpoint_adjustment_warning (bl
->requested_address
,
2275 annotate_breakpoint (b
->number
);
2277 ui_out_text (uiout
, "\nTemporary breakpoint ");
2279 ui_out_text (uiout
, "\nBreakpoint ");
2280 if (ui_out_is_mi_like_p (uiout
))
2282 ui_out_field_string (uiout
, "reason",
2283 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2284 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2286 ui_out_field_int (uiout
, "bkptno", b
->number
);
2287 ui_out_text (uiout
, ", ");
2288 return PRINT_SRC_AND_LOC
;
2291 case bp_shlib_event
:
2292 /* Did we stop because the user set the stop_on_solib_events
2293 variable? (If so, we report this as a generic, "Stopped due
2294 to shlib event" message.) */
2295 printf_filtered (_("Stopped due to shared library event\n"));
2296 return PRINT_NOTHING
;
2299 case bp_thread_event
:
2300 /* Not sure how we will get here.
2301 GDB should not stop for these breakpoints. */
2302 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2303 return PRINT_NOTHING
;
2306 case bp_overlay_event
:
2307 /* By analogy with the thread event, GDB should not stop for these. */
2308 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2309 return PRINT_NOTHING
;
2313 case bp_hardware_watchpoint
:
2314 annotate_watchpoint (b
->number
);
2315 if (ui_out_is_mi_like_p (uiout
))
2318 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2320 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2321 ui_out_text (uiout
, "\nOld value = ");
2322 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2323 ui_out_field_stream (uiout
, "old", stb
);
2324 ui_out_text (uiout
, "\nNew value = ");
2325 watchpoint_value_print (b
->val
, stb
->stream
);
2326 ui_out_field_stream (uiout
, "new", stb
);
2327 do_cleanups (ui_out_chain
);
2328 ui_out_text (uiout
, "\n");
2329 /* More than one watchpoint may have been triggered. */
2330 return PRINT_UNKNOWN
;
2333 case bp_read_watchpoint
:
2334 if (ui_out_is_mi_like_p (uiout
))
2337 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2339 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2340 ui_out_text (uiout
, "\nValue = ");
2341 watchpoint_value_print (b
->val
, stb
->stream
);
2342 ui_out_field_stream (uiout
, "value", stb
);
2343 do_cleanups (ui_out_chain
);
2344 ui_out_text (uiout
, "\n");
2345 return PRINT_UNKNOWN
;
2348 case bp_access_watchpoint
:
2349 if (bs
->old_val
!= NULL
)
2351 annotate_watchpoint (b
->number
);
2352 if (ui_out_is_mi_like_p (uiout
))
2355 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2357 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2358 ui_out_text (uiout
, "\nOld value = ");
2359 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2360 ui_out_field_stream (uiout
, "old", stb
);
2361 ui_out_text (uiout
, "\nNew value = ");
2366 if (ui_out_is_mi_like_p (uiout
))
2369 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2370 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2371 ui_out_text (uiout
, "\nValue = ");
2373 watchpoint_value_print (b
->val
, stb
->stream
);
2374 ui_out_field_stream (uiout
, "new", stb
);
2375 do_cleanups (ui_out_chain
);
2376 ui_out_text (uiout
, "\n");
2377 return PRINT_UNKNOWN
;
2380 /* Fall through, we don't deal with these types of breakpoints
2384 if (ui_out_is_mi_like_p (uiout
))
2387 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2388 return PRINT_UNKNOWN
;
2392 if (ui_out_is_mi_like_p (uiout
))
2395 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2396 return PRINT_UNKNOWN
;
2401 case bp_longjmp_resume
:
2402 case bp_step_resume
:
2403 case bp_watchpoint_scope
:
2406 return PRINT_UNKNOWN
;
2410 /* Generic routine for printing messages indicating why we
2411 stopped. The behavior of this function depends on the value
2412 'print_it' in the bpstat structure. Under some circumstances we
2413 may decide not to print anything here and delegate the task to
2416 static enum print_stop_action
2417 print_bp_stop_message (bpstat bs
)
2419 switch (bs
->print_it
)
2422 /* Nothing should be printed for this bpstat entry. */
2423 return PRINT_UNKNOWN
;
2427 /* We still want to print the frame, but we already printed the
2428 relevant messages. */
2429 return PRINT_SRC_AND_LOC
;
2432 case print_it_normal
:
2434 const struct bp_location
*bl
= bs
->breakpoint_at
;
2435 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2437 /* Normal case. Call the breakpoint's print_it method, or
2438 print_it_typical. */
2439 /* FIXME: how breakpoint can ever be NULL here? */
2440 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2441 return b
->ops
->print_it (b
);
2443 return print_it_typical (bs
);
2448 internal_error (__FILE__
, __LINE__
,
2449 _("print_bp_stop_message: unrecognized enum value"));
2454 /* Print a message indicating what happened. This is called from
2455 normal_stop(). The input to this routine is the head of the bpstat
2456 list - a list of the eventpoints that caused this stop. This
2457 routine calls the generic print routine for printing a message
2458 about reasons for stopping. This will print (for example) the
2459 "Breakpoint n," part of the output. The return value of this
2462 PRINT_UNKNOWN: Means we printed nothing
2463 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2464 code to print the location. An example is
2465 "Breakpoint 1, " which should be followed by
2467 PRINT_SRC_ONLY: Means we printed something, but there is no need
2468 to also print the location part of the message.
2469 An example is the catch/throw messages, which
2470 don't require a location appended to the end.
2471 PRINT_NOTHING: We have done some printing and we don't need any
2472 further info to be printed.*/
2474 enum print_stop_action
2475 bpstat_print (bpstat bs
)
2479 /* Maybe another breakpoint in the chain caused us to stop.
2480 (Currently all watchpoints go on the bpstat whether hit or not.
2481 That probably could (should) be changed, provided care is taken
2482 with respect to bpstat_explains_signal). */
2483 for (; bs
; bs
= bs
->next
)
2485 val
= print_bp_stop_message (bs
);
2486 if (val
== PRINT_SRC_ONLY
2487 || val
== PRINT_SRC_AND_LOC
2488 || val
== PRINT_NOTHING
)
2492 /* We reached the end of the chain, or we got a null BS to start
2493 with and nothing was printed. */
2494 return PRINT_UNKNOWN
;
2497 /* Evaluate the expression EXP and return 1 if value is zero.
2498 This is used inside a catch_errors to evaluate the breakpoint condition.
2499 The argument is a "struct expression *" that has been cast to char * to
2500 make it pass through catch_errors. */
2503 breakpoint_cond_eval (void *exp
)
2505 struct value
*mark
= value_mark ();
2506 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2507 value_free_to_mark (mark
);
2511 /* Allocate a new bpstat and chain it to the current one. */
2514 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2518 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2520 bs
->breakpoint_at
= bl
;
2521 /* If the condition is false, etc., don't do the commands. */
2522 bs
->commands
= NULL
;
2524 bs
->print_it
= print_it_normal
;
2528 /* The target has stopped with waitstatus WS. Check if any hardware
2529 watchpoints have triggered, according to the target. */
2532 watchpoints_triggered (struct target_waitstatus
*ws
)
2534 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2536 struct breakpoint
*b
;
2538 if (!stopped_by_watchpoint
)
2540 /* We were not stopped by a watchpoint. Mark all watchpoints
2541 as not triggered. */
2543 if (b
->type
== bp_hardware_watchpoint
2544 || b
->type
== bp_read_watchpoint
2545 || b
->type
== bp_access_watchpoint
)
2546 b
->watchpoint_triggered
= watch_triggered_no
;
2551 if (!target_stopped_data_address (¤t_target
, &addr
))
2553 /* We were stopped by a watchpoint, but we don't know where.
2554 Mark all watchpoints as unknown. */
2556 if (b
->type
== bp_hardware_watchpoint
2557 || b
->type
== bp_read_watchpoint
2558 || b
->type
== bp_access_watchpoint
)
2559 b
->watchpoint_triggered
= watch_triggered_unknown
;
2561 return stopped_by_watchpoint
;
2564 /* The target could report the data address. Mark watchpoints
2565 affected by this data address as triggered, and all others as not
2569 if (b
->type
== bp_hardware_watchpoint
2570 || b
->type
== bp_read_watchpoint
2571 || b
->type
== bp_access_watchpoint
)
2573 struct bp_location
*loc
;
2576 b
->watchpoint_triggered
= watch_triggered_no
;
2577 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2578 /* Exact match not required. Within range is
2580 if (target_watchpoint_addr_within_range (¤t_target
,
2584 b
->watchpoint_triggered
= watch_triggered_yes
;
2592 /* Possible return values for watchpoint_check (this can't be an enum
2593 because of check_errors). */
2594 /* The watchpoint has been deleted. */
2595 #define WP_DELETED 1
2596 /* The value has changed. */
2597 #define WP_VALUE_CHANGED 2
2598 /* The value has not changed. */
2599 #define WP_VALUE_NOT_CHANGED 3
2601 #define BP_TEMPFLAG 1
2602 #define BP_HARDWAREFLAG 2
2604 /* Check watchpoint condition. */
2607 watchpoint_check (void *p
)
2609 bpstat bs
= (bpstat
) p
;
2610 struct breakpoint
*b
;
2611 struct frame_info
*fr
;
2612 int within_current_scope
;
2614 b
= bs
->breakpoint_at
->owner
;
2616 if (b
->exp_valid_block
== NULL
)
2617 within_current_scope
= 1;
2620 /* There is no current frame at this moment. If we're going to have
2621 any chance of handling watchpoints on local variables, we'll need
2622 the frame chain (so we can determine if we're in scope). */
2623 reinit_frame_cache ();
2624 fr
= frame_find_by_id (b
->watchpoint_frame
);
2625 within_current_scope
= (fr
!= NULL
);
2627 /* If we've gotten confused in the unwinder, we might have
2628 returned a frame that can't describe this variable. */
2629 if (within_current_scope
2630 && (block_linkage_function (b
->exp_valid_block
)
2631 != get_frame_function (fr
)))
2632 within_current_scope
= 0;
2634 /* in_function_epilogue_p() returns a non-zero value if we're still
2635 in the function but the stack frame has already been invalidated.
2636 Since we can't rely on the values of local variables after the
2637 stack has been destroyed, we are treating the watchpoint in that
2638 state as `not changed' without further checking.
2640 vinschen/2003-09-04: The former implementation left out the case
2641 that the watchpoint frame couldn't be found by frame_find_by_id()
2642 because the current PC is currently in an epilogue. Calling
2643 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2644 if ((!within_current_scope
|| fr
== get_current_frame ())
2645 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2646 return WP_VALUE_NOT_CHANGED
;
2647 if (fr
&& within_current_scope
)
2648 /* If we end up stopping, the current frame will get selected
2649 in normal_stop. So this call to select_frame won't affect
2654 if (within_current_scope
)
2656 /* We use value_{,free_to_}mark because it could be a
2657 *long* time before we return to the command level and
2658 call free_all_values. We can't call free_all_values because
2659 we might be in the middle of evaluating a function call. */
2661 struct value
*mark
= value_mark ();
2662 struct value
*new_val
;
2664 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2665 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2666 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2668 if (new_val
!= NULL
)
2670 release_value (new_val
);
2671 value_free_to_mark (mark
);
2673 bs
->old_val
= b
->val
;
2676 /* We will stop here */
2677 return WP_VALUE_CHANGED
;
2681 /* Nothing changed, don't do anything. */
2682 value_free_to_mark (mark
);
2683 /* We won't stop here */
2684 return WP_VALUE_NOT_CHANGED
;
2689 /* This seems like the only logical thing to do because
2690 if we temporarily ignored the watchpoint, then when
2691 we reenter the block in which it is valid it contains
2692 garbage (in the case of a function, it may have two
2693 garbage values, one before and one after the prologue).
2694 So we can't even detect the first assignment to it and
2695 watch after that (since the garbage may or may not equal
2696 the first value assigned). */
2697 /* We print all the stop information in print_it_typical(), but
2698 in this case, by the time we call print_it_typical() this bp
2699 will be deleted already. So we have no choice but print the
2700 information here. */
2701 if (ui_out_is_mi_like_p (uiout
))
2703 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2704 ui_out_text (uiout
, "\nWatchpoint ");
2705 ui_out_field_int (uiout
, "wpnum", b
->number
);
2706 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2707 which its expression is valid.\n");
2709 if (b
->related_breakpoint
)
2710 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2711 b
->disposition
= disp_del_at_next_stop
;
2717 /* Return true if it looks like target has stopped due to hitting
2718 breakpoint location BL. This function does not check if we
2719 should stop, only if BL explains the stop. */
2721 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2723 struct breakpoint
*b
= bl
->owner
;
2725 if (b
->type
!= bp_watchpoint
2726 && b
->type
!= bp_hardware_watchpoint
2727 && b
->type
!= bp_read_watchpoint
2728 && b
->type
!= bp_access_watchpoint
2729 && b
->type
!= bp_hardware_breakpoint
2730 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
2732 if (bl
->address
!= bp_addr
) /* address doesn't match */
2734 if (overlay_debugging
/* unmapped overlay section */
2735 && section_is_overlay (bl
->section
)
2736 && !section_is_mapped (bl
->section
))
2740 /* Continuable hardware watchpoints are treated as non-existent if the
2741 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2742 some data address). Otherwise gdb won't stop on a break instruction
2743 in the code (not from a breakpoint) when a hardware watchpoint has
2744 been defined. Also skip watchpoints which we know did not trigger
2745 (did not match the data address). */
2747 if ((b
->type
== bp_hardware_watchpoint
2748 || b
->type
== bp_read_watchpoint
2749 || b
->type
== bp_access_watchpoint
)
2750 && b
->watchpoint_triggered
== watch_triggered_no
)
2753 if (b
->type
== bp_hardware_breakpoint
)
2755 if (bl
->address
!= bp_addr
)
2757 if (overlay_debugging
/* unmapped overlay section */
2758 && section_is_overlay (bl
->section
)
2759 && !section_is_mapped (bl
->section
))
2763 if (b
->type
== bp_catchpoint
)
2765 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2766 if (!b
->ops
->breakpoint_hit (b
))
2773 /* If BS refers to a watchpoint, determine if the watched values
2774 has actually changed, and we should stop. If not, set BS->stop
2777 bpstat_check_watchpoint (bpstat bs
)
2779 const struct bp_location
*bl
= bs
->breakpoint_at
;
2780 struct breakpoint
*b
= bl
->owner
;
2782 if (b
->type
== bp_watchpoint
2783 || b
->type
== bp_read_watchpoint
2784 || b
->type
== bp_access_watchpoint
2785 || b
->type
== bp_hardware_watchpoint
)
2789 int must_check_value
= 0;
2791 if (b
->type
== bp_watchpoint
)
2792 /* For a software watchpoint, we must always check the
2794 must_check_value
= 1;
2795 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2796 /* We have a hardware watchpoint (read, write, or access)
2797 and the target earlier reported an address watched by
2799 must_check_value
= 1;
2800 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2801 && b
->type
== bp_hardware_watchpoint
)
2802 /* We were stopped by a hardware watchpoint, but the target could
2803 not report the data address. We must check the watchpoint's
2804 value. Access and read watchpoints are out of luck; without
2805 a data address, we can't figure it out. */
2806 must_check_value
= 1;
2808 if (must_check_value
)
2810 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2812 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2813 int e
= catch_errors (watchpoint_check
, bs
, message
,
2815 do_cleanups (cleanups
);
2819 /* We've already printed what needs to be printed. */
2820 bs
->print_it
= print_it_done
;
2823 case WP_VALUE_CHANGED
:
2824 if (b
->type
== bp_read_watchpoint
)
2826 /* Don't stop: read watchpoints shouldn't fire if
2827 the value has changed. This is for targets
2828 which cannot set read-only watchpoints. */
2829 bs
->print_it
= print_it_noop
;
2833 case WP_VALUE_NOT_CHANGED
:
2834 if (b
->type
== bp_hardware_watchpoint
2835 || b
->type
== bp_watchpoint
)
2837 /* Don't stop: write watchpoints shouldn't fire if
2838 the value hasn't changed. */
2839 bs
->print_it
= print_it_noop
;
2847 /* Error from catch_errors. */
2848 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2849 if (b
->related_breakpoint
)
2850 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2851 b
->disposition
= disp_del_at_next_stop
;
2852 /* We've already printed what needs to be printed. */
2853 bs
->print_it
= print_it_done
;
2857 else /* must_check_value == 0 */
2859 /* This is a case where some watchpoint(s) triggered, but
2860 not at the address of this watchpoint, or else no
2861 watchpoint triggered after all. So don't print
2862 anything for this watchpoint. */
2863 bs
->print_it
= print_it_noop
;
2870 /* Check conditions (condition proper, frame, thread and ignore count)
2871 of breakpoint referred to by BS. If we should not stop for this
2872 breakpoint, set BS->stop to 0. */
2874 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2876 int thread_id
= pid_to_thread_id (ptid
);
2877 const struct bp_location
*bl
= bs
->breakpoint_at
;
2878 struct breakpoint
*b
= bl
->owner
;
2880 if (frame_id_p (b
->frame_id
)
2881 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2885 int value_is_zero
= 0;
2887 /* If this is a scope breakpoint, mark the associated
2888 watchpoint as triggered so that we will handle the
2889 out-of-scope event. We'll get to the watchpoint next
2891 if (b
->type
== bp_watchpoint_scope
)
2892 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2894 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2896 /* Need to select the frame, with all that implies
2897 so that the conditions will have the right context. */
2898 select_frame (get_current_frame ());
2900 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2901 "Error in testing breakpoint condition:\n",
2903 /* FIXME-someday, should give breakpoint # */
2906 if (bl
->cond
&& value_is_zero
)
2910 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2914 else if (b
->ignore_count
> 0)
2917 annotate_ignore_count_change ();
2919 /* Increase the hit count even though we don't
2927 /* Get a bpstat associated with having just stopped at address
2928 BP_ADDR in thread PTID.
2930 Determine whether we stopped at a breakpoint, etc, or whether we
2931 don't understand this stop. Result is a chain of bpstat's such that:
2933 if we don't understand the stop, the result is a null pointer.
2935 if we understand why we stopped, the result is not null.
2937 Each element of the chain refers to a particular breakpoint or
2938 watchpoint at which we have stopped. (We may have stopped for
2939 several reasons concurrently.)
2941 Each element of the chain has valid next, breakpoint_at,
2942 commands, FIXME??? fields. */
2945 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2947 struct breakpoint
*b
= NULL
;
2948 const struct bp_location
*bl
;
2949 struct bp_location
*loc
;
2950 /* Root of the chain of bpstat's */
2951 struct bpstats root_bs
[1];
2952 /* Pointer to the last thing in the chain currently. */
2953 bpstat bs
= root_bs
;
2955 int need_remove_insert
;
2957 ALL_BP_LOCATIONS (bl
)
2961 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2964 /* For hardware watchpoints, we look only at the first location.
2965 The watchpoint_check function will work on entire expression,
2966 not the individual locations. For read watchopints, the
2967 watchpoints_triggered function have checked all locations
2970 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
2973 if (!bpstat_check_location (bl
, bp_addr
))
2976 /* Come here if it's a watchpoint, or if the break address matches */
2978 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
2980 /* Assume we stop. Should we find watchpoint that is not actually
2981 triggered, or if condition of breakpoint is false, we'll reset
2986 bpstat_check_watchpoint (bs
);
2990 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
2991 /* We do not stop for these. */
2994 bpstat_check_breakpoint_conditions (bs
, ptid
);
3000 /* We will stop here */
3001 if (b
->disposition
== disp_disable
)
3003 if (b
->enable_state
!= bp_permanent
)
3004 b
->enable_state
= bp_disabled
;
3005 update_global_location_list (0);
3009 bs
->commands
= b
->commands
;
3011 (strcmp ("silent", bs
->commands
->line
) == 0
3012 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3014 bs
->commands
= bs
->commands
->next
;
3017 bs
->commands
= copy_command_lines (bs
->commands
);
3020 /* Print nothing for this entry if we dont stop or if we dont print. */
3021 if (bs
->stop
== 0 || bs
->print
== 0)
3022 bs
->print_it
= print_it_noop
;
3025 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3027 if (loc
->address
== bp_addr
)
3029 bs
= bpstat_alloc (loc
, bs
);
3030 /* For hits of moribund locations, we should just proceed. */
3033 bs
->print_it
= print_it_noop
;
3037 bs
->next
= NULL
; /* Terminate the chain */
3038 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3040 /* If we aren't stopping, the value of some hardware watchpoint may
3041 not have changed, but the intermediate memory locations we are
3042 watching may have. Don't bother if we're stopping; this will get
3044 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3048 need_remove_insert
= 0;
3050 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3052 && bs
->breakpoint_at
->owner
3053 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3054 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3055 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3057 /* remove/insert can invalidate bs->breakpoint_at, if this
3058 location is no longer used by the watchpoint. Prevent
3059 further code from trying to use it. */
3060 bs
->breakpoint_at
= NULL
;
3061 need_remove_insert
= 1;
3064 if (need_remove_insert
)
3066 remove_breakpoints ();
3067 insert_breakpoints ();
3070 return root_bs
->next
;
3073 /* Tell what to do about this bpstat. */
3075 bpstat_what (bpstat bs
)
3077 /* Classify each bpstat as one of the following. */
3080 /* This bpstat element has no effect on the main_action. */
3083 /* There was a watchpoint, stop but don't print. */
3086 /* There was a watchpoint, stop and print. */
3089 /* There was a breakpoint but we're not stopping. */
3092 /* There was a breakpoint, stop but don't print. */
3095 /* There was a breakpoint, stop and print. */
3098 /* We hit the longjmp breakpoint. */
3101 /* We hit the longjmp_resume breakpoint. */
3104 /* We hit the step_resume breakpoint. */
3107 /* We hit the shared library event breakpoint. */
3110 /* We caught a shared library event. */
3113 /* This is just used to count how many enums there are. */
3117 /* Here is the table which drives this routine. So that we can
3118 format it pretty, we define some abbreviations for the
3119 enum bpstat_what codes. */
3120 #define kc BPSTAT_WHAT_KEEP_CHECKING
3121 #define ss BPSTAT_WHAT_STOP_SILENT
3122 #define sn BPSTAT_WHAT_STOP_NOISY
3123 #define sgl BPSTAT_WHAT_SINGLE
3124 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3125 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3126 #define sr BPSTAT_WHAT_STEP_RESUME
3127 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3128 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3130 /* "Can't happen." Might want to print an error message.
3131 abort() is not out of the question, but chances are GDB is just
3132 a bit confused, not unusable. */
3133 #define err BPSTAT_WHAT_STOP_NOISY
3135 /* Given an old action and a class, come up with a new action. */
3136 /* One interesting property of this table is that wp_silent is the same
3137 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3138 after stopping, the check for whether to step over a breakpoint
3139 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3140 reference to how we stopped. We retain separate wp_silent and
3141 bp_silent codes in case we want to change that someday.
3143 Another possibly interesting property of this table is that
3144 there's a partial ordering, priority-like, of the actions. Once
3145 you've decided that some action is appropriate, you'll never go
3146 back and decide something of a lower priority is better. The
3149 kc < clr sgl shl shlr slr sn sr ss
3150 sgl < shl shlr slr sn sr ss
3151 slr < err shl shlr sn sr ss
3152 clr < err shl shlr sn sr ss
3159 What I think this means is that we don't need a damned table
3160 here. If you just put the rows and columns in the right order,
3161 it'd look awfully regular. We could simply walk the bpstat list
3162 and choose the highest priority action we find, with a little
3163 logic to handle the 'err' cases. */
3165 /* step_resume entries: a step resume breakpoint overrides another
3166 breakpoint of signal handling (see comment in wait_for_inferior
3167 at where we set the step_resume breakpoint). */
3169 static const enum bpstat_what_main_action
3170 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3173 /* kc ss sn sgl slr clr sr shl shlr
3176 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, shlr
},
3178 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3180 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3182 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, shlr
},
3184 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3186 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3188 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, shlr
},
3190 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, shlr
},
3192 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3194 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3196 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3210 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3211 struct bpstat_what retval
;
3213 retval
.call_dummy
= 0;
3214 for (; bs
!= NULL
; bs
= bs
->next
)
3216 enum class bs_class
= no_effect
;
3217 if (bs
->breakpoint_at
== NULL
)
3218 /* I suspect this can happen if it was a momentary breakpoint
3219 which has since been deleted. */
3221 if (bs
->breakpoint_at
->owner
== NULL
)
3222 bs_class
= bp_nostop
;
3224 switch (bs
->breakpoint_at
->owner
->type
)
3230 case bp_hardware_breakpoint
:
3236 bs_class
= bp_noisy
;
3238 bs_class
= bp_silent
;
3241 bs_class
= bp_nostop
;
3244 case bp_hardware_watchpoint
:
3245 case bp_read_watchpoint
:
3246 case bp_access_watchpoint
:
3250 bs_class
= wp_noisy
;
3252 bs_class
= wp_silent
;
3255 /* There was a watchpoint, but we're not stopping.
3256 This requires no further action. */
3257 bs_class
= no_effect
;
3260 bs_class
= long_jump
;
3262 case bp_longjmp_resume
:
3263 bs_class
= long_resume
;
3265 case bp_step_resume
:
3268 bs_class
= step_resume
;
3271 /* It is for the wrong frame. */
3272 bs_class
= bp_nostop
;
3274 case bp_watchpoint_scope
:
3275 bs_class
= bp_nostop
;
3277 case bp_shlib_event
:
3278 bs_class
= shlib_event
;
3280 case bp_thread_event
:
3281 case bp_overlay_event
:
3282 bs_class
= bp_nostop
;
3288 bs_class
= bp_noisy
;
3290 bs_class
= bp_silent
;
3293 /* There was a catchpoint, but we're not stopping.
3294 This requires no further action. */
3295 bs_class
= no_effect
;
3298 /* Make sure the action is stop (silent or noisy),
3299 so infrun.c pops the dummy frame. */
3300 bs_class
= bp_silent
;
3301 retval
.call_dummy
= 1;
3304 current_action
= table
[(int) bs_class
][(int) current_action
];
3306 retval
.main_action
= current_action
;
3310 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3311 without hardware support). This isn't related to a specific bpstat,
3312 just to things like whether watchpoints are set. */
3315 bpstat_should_step (void)
3317 struct breakpoint
*b
;
3319 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3326 static void print_breakpoint_location (struct breakpoint
*b
,
3327 struct bp_location
*loc
,
3329 struct ui_stream
*stb
)
3334 = find_pc_sect_function (loc
->address
, loc
->section
);
3337 ui_out_text (uiout
, "in ");
3338 ui_out_field_string (uiout
, "func",
3339 SYMBOL_PRINT_NAME (sym
));
3340 ui_out_wrap_hint (uiout
, wrap_indent
);
3341 ui_out_text (uiout
, " at ");
3343 ui_out_field_string (uiout
, "file", b
->source_file
);
3344 ui_out_text (uiout
, ":");
3346 if (ui_out_is_mi_like_p (uiout
))
3348 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3349 char *fullname
= symtab_to_fullname (sal
.symtab
);
3352 ui_out_field_string (uiout
, "fullname", fullname
);
3355 ui_out_field_int (uiout
, "line", b
->line_number
);
3359 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3363 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3364 ui_out_field_stream (uiout
, "at", stb
);
3368 /* Print B to gdb_stdout. */
3370 print_one_breakpoint_location (struct breakpoint
*b
,
3371 struct bp_location
*loc
,
3373 CORE_ADDR
*last_addr
)
3375 struct command_line
*l
;
3377 struct ep_type_description
3382 static struct ep_type_description bptypes
[] =
3384 {bp_none
, "?deleted?"},
3385 {bp_breakpoint
, "breakpoint"},
3386 {bp_hardware_breakpoint
, "hw breakpoint"},
3387 {bp_until
, "until"},
3388 {bp_finish
, "finish"},
3389 {bp_watchpoint
, "watchpoint"},
3390 {bp_hardware_watchpoint
, "hw watchpoint"},
3391 {bp_read_watchpoint
, "read watchpoint"},
3392 {bp_access_watchpoint
, "acc watchpoint"},
3393 {bp_longjmp
, "longjmp"},
3394 {bp_longjmp_resume
, "longjmp resume"},
3395 {bp_step_resume
, "step resume"},
3396 {bp_watchpoint_scope
, "watchpoint scope"},
3397 {bp_call_dummy
, "call dummy"},
3398 {bp_shlib_event
, "shlib events"},
3399 {bp_thread_event
, "thread events"},
3400 {bp_overlay_event
, "overlay events"},
3401 {bp_catchpoint
, "catchpoint"},
3404 static char bpenables
[] = "nynny";
3405 char wrap_indent
[80];
3406 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3407 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3408 struct cleanup
*bkpt_chain
;
3410 int header_of_multiple
= 0;
3411 int part_of_multiple
= (loc
!= NULL
);
3412 struct value_print_options opts
;
3414 get_user_print_options (&opts
);
3416 gdb_assert (!loc
|| loc_number
!= 0);
3417 /* See comment in print_one_breakpoint concerning
3418 treatment of breakpoints with single disabled
3422 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3423 header_of_multiple
= 1;
3428 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3432 if (part_of_multiple
)
3435 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3436 ui_out_field_string (uiout
, "number", formatted
);
3441 ui_out_field_int (uiout
, "number", b
->number
);
3446 if (part_of_multiple
)
3447 ui_out_field_skip (uiout
, "type");
3450 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3451 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3452 internal_error (__FILE__
, __LINE__
,
3453 _("bptypes table does not describe type #%d."),
3455 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3460 if (part_of_multiple
)
3461 ui_out_field_skip (uiout
, "disp");
3463 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3468 if (part_of_multiple
)
3469 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3471 ui_out_field_fmt (uiout
, "enabled", "%c",
3472 bpenables
[(int) b
->enable_state
]);
3473 ui_out_spaces (uiout
, 2);
3477 strcpy (wrap_indent
, " ");
3478 if (opts
.addressprint
)
3480 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3481 strcat (wrap_indent
, " ");
3483 strcat (wrap_indent
, " ");
3486 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3488 /* Although the print_one can possibly print
3489 all locations, calling it here is not likely
3490 to get any nice result. So, make sure there's
3491 just one location. */
3492 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3493 b
->ops
->print_one (b
, last_addr
);
3499 internal_error (__FILE__
, __LINE__
,
3500 _("print_one_breakpoint: bp_none encountered\n"));
3504 case bp_hardware_watchpoint
:
3505 case bp_read_watchpoint
:
3506 case bp_access_watchpoint
:
3507 /* Field 4, the address, is omitted (which makes the columns
3508 not line up too nicely with the headers, but the effect
3509 is relatively readable). */
3510 if (opts
.addressprint
)
3511 ui_out_field_skip (uiout
, "addr");
3513 print_expression (b
->exp
, stb
->stream
);
3514 ui_out_field_stream (uiout
, "what", stb
);
3518 case bp_hardware_breakpoint
:
3522 case bp_longjmp_resume
:
3523 case bp_step_resume
:
3524 case bp_watchpoint_scope
:
3526 case bp_shlib_event
:
3527 case bp_thread_event
:
3528 case bp_overlay_event
:
3529 if (opts
.addressprint
)
3532 if (header_of_multiple
)
3533 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3534 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3535 ui_out_field_string (uiout
, "addr", "<PENDING>");
3537 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3540 if (!header_of_multiple
)
3541 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3543 *last_addr
= b
->loc
->address
;
3547 if (!part_of_multiple
&& b
->thread
!= -1)
3549 /* FIXME: This seems to be redundant and lost here; see the
3550 "stop only in" line a little further down. */
3551 ui_out_text (uiout
, " thread ");
3552 ui_out_field_int (uiout
, "thread", b
->thread
);
3555 ui_out_text (uiout
, "\n");
3557 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3560 ui_out_text (uiout
, "\tstop only in stack frame at ");
3561 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3563 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3564 ui_out_text (uiout
, "\n");
3567 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3569 /* We do not print the condition for Ada exception catchpoints
3570 because the condition is an internal implementation detail
3571 that we do not want to expose to the user. */
3573 ui_out_text (uiout
, "\tstop only if ");
3574 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3575 ui_out_text (uiout
, "\n");
3578 if (!part_of_multiple
&& b
->thread
!= -1)
3580 /* FIXME should make an annotation for this */
3581 ui_out_text (uiout
, "\tstop only in thread ");
3582 ui_out_field_int (uiout
, "thread", b
->thread
);
3583 ui_out_text (uiout
, "\n");
3586 if (!part_of_multiple
&& b
->hit_count
)
3588 /* FIXME should make an annotation for this */
3589 if (ep_is_catchpoint (b
))
3590 ui_out_text (uiout
, "\tcatchpoint");
3592 ui_out_text (uiout
, "\tbreakpoint");
3593 ui_out_text (uiout
, " already hit ");
3594 ui_out_field_int (uiout
, "times", b
->hit_count
);
3595 if (b
->hit_count
== 1)
3596 ui_out_text (uiout
, " time\n");
3598 ui_out_text (uiout
, " times\n");
3601 /* Output the count also if it is zero, but only if this is
3602 mi. FIXME: Should have a better test for this. */
3603 if (ui_out_is_mi_like_p (uiout
))
3604 if (!part_of_multiple
&& b
->hit_count
== 0)
3605 ui_out_field_int (uiout
, "times", b
->hit_count
);
3607 if (!part_of_multiple
&& b
->ignore_count
)
3610 ui_out_text (uiout
, "\tignore next ");
3611 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3612 ui_out_text (uiout
, " hits\n");
3615 if (!part_of_multiple
&& (l
= b
->commands
))
3617 struct cleanup
*script_chain
;
3620 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3621 print_command_lines (uiout
, l
, 4);
3622 do_cleanups (script_chain
);
3625 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3628 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3629 else if (b
->exp_string
)
3630 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3633 do_cleanups (bkpt_chain
);
3634 do_cleanups (old_chain
);
3638 print_one_breakpoint (struct breakpoint
*b
,
3639 CORE_ADDR
*last_addr
)
3641 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3643 /* If this breakpoint has custom print function,
3644 it's already printed. Otherwise, print individual
3645 locations, if any. */
3646 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3648 /* If breakpoint has a single location that is
3649 disabled, we print it as if it had
3650 several locations, since otherwise it's hard to
3651 represent "breakpoint enabled, location disabled"
3653 Note that while hardware watchpoints have
3654 several locations internally, that's no a property
3657 && !is_hardware_watchpoint (b
)
3658 && (b
->loc
->next
|| !b
->loc
->enabled
)
3659 && !ui_out_is_mi_like_p (uiout
))
3661 struct bp_location
*loc
;
3663 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3664 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3670 struct captured_breakpoint_query_args
3676 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3678 struct captured_breakpoint_query_args
*args
= data
;
3679 struct breakpoint
*b
;
3680 CORE_ADDR dummy_addr
= 0;
3683 if (args
->bnum
== b
->number
)
3685 print_one_breakpoint (b
, &dummy_addr
);
3693 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3695 struct captured_breakpoint_query_args args
;
3697 /* For the moment we don't trust print_one_breakpoint() to not throw
3699 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3700 error_message
, RETURN_MASK_ALL
) < 0)
3706 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3707 catchpoints, et.al.). */
3710 user_settable_breakpoint (const struct breakpoint
*b
)
3712 return (b
->type
== bp_breakpoint
3713 || b
->type
== bp_catchpoint
3714 || b
->type
== bp_hardware_breakpoint
3715 || b
->type
== bp_watchpoint
3716 || b
->type
== bp_read_watchpoint
3717 || b
->type
== bp_access_watchpoint
3718 || b
->type
== bp_hardware_watchpoint
);
3721 /* Print information on user settable breakpoint (watchpoint, etc)
3722 number BNUM. If BNUM is -1 print all user settable breakpoints.
3723 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3726 breakpoint_1 (int bnum
, int allflag
)
3728 struct breakpoint
*b
;
3729 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3730 int nr_printable_breakpoints
;
3731 struct cleanup
*bkpttbl_chain
;
3732 struct value_print_options opts
;
3734 get_user_print_options (&opts
);
3736 /* Compute the number of rows in the table. */
3737 nr_printable_breakpoints
= 0;
3740 || bnum
== b
->number
)
3742 if (allflag
|| user_settable_breakpoint (b
))
3743 nr_printable_breakpoints
++;
3746 if (opts
.addressprint
)
3748 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3752 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3755 if (nr_printable_breakpoints
> 0)
3756 annotate_breakpoints_headers ();
3757 if (nr_printable_breakpoints
> 0)
3759 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3760 if (nr_printable_breakpoints
> 0)
3762 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3763 if (nr_printable_breakpoints
> 0)
3765 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3766 if (nr_printable_breakpoints
> 0)
3768 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3769 if (opts
.addressprint
)
3771 if (nr_printable_breakpoints
> 0)
3773 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3774 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3776 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3778 if (nr_printable_breakpoints
> 0)
3780 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3781 ui_out_table_body (uiout
);
3782 if (nr_printable_breakpoints
> 0)
3783 annotate_breakpoints_table ();
3787 || bnum
== b
->number
)
3789 /* We only print out user settable breakpoints unless the
3791 if (allflag
|| user_settable_breakpoint (b
))
3792 print_one_breakpoint (b
, &last_addr
);
3795 do_cleanups (bkpttbl_chain
);
3797 if (nr_printable_breakpoints
== 0)
3800 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3802 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3807 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3808 that a comparison of an unsigned with -1 is always false. */
3809 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3810 set_next_address (current_gdbarch
, last_addr
);
3813 /* FIXME? Should this be moved up so that it is only called when
3814 there have been breakpoints? */
3815 annotate_breakpoints_table_end ();
3819 breakpoints_info (char *bnum_exp
, int from_tty
)
3824 bnum
= parse_and_eval_long (bnum_exp
);
3826 breakpoint_1 (bnum
, 0);
3830 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3835 bnum
= parse_and_eval_long (bnum_exp
);
3837 breakpoint_1 (bnum
, 1);
3841 breakpoint_has_pc (struct breakpoint
*b
,
3842 CORE_ADDR pc
, struct obj_section
*section
)
3844 struct bp_location
*bl
= b
->loc
;
3845 for (; bl
; bl
= bl
->next
)
3847 if (bl
->address
== pc
3848 && (!overlay_debugging
|| bl
->section
== section
))
3854 /* Print a message describing any breakpoints set at PC. */
3857 describe_other_breakpoints (CORE_ADDR pc
, struct obj_section
*section
,
3861 struct breakpoint
*b
;
3864 others
+= breakpoint_has_pc (b
, pc
, section
);
3868 printf_filtered (_("Note: breakpoint "));
3869 else /* if (others == ???) */
3870 printf_filtered (_("Note: breakpoints "));
3872 if (breakpoint_has_pc (b
, pc
, section
))
3875 printf_filtered ("%d", b
->number
);
3876 if (b
->thread
== -1 && thread
!= -1)
3877 printf_filtered (" (all threads)");
3878 else if (b
->thread
!= -1)
3879 printf_filtered (" (thread %d)", b
->thread
);
3880 printf_filtered ("%s%s ",
3881 ((b
->enable_state
== bp_disabled
||
3882 b
->enable_state
== bp_call_disabled
)
3884 : b
->enable_state
== bp_permanent
3888 : ((others
== 1) ? " and" : ""));
3890 printf_filtered (_("also set at pc "));
3891 fputs_filtered (paddress (pc
), gdb_stdout
);
3892 printf_filtered (".\n");
3896 /* Set the default place to put a breakpoint
3897 for the `break' command with no arguments. */
3900 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3903 default_breakpoint_valid
= valid
;
3904 default_breakpoint_address
= addr
;
3905 default_breakpoint_symtab
= symtab
;
3906 default_breakpoint_line
= line
;
3909 /* Return true iff it is meaningful to use the address member of
3910 BPT. For some breakpoint types, the address member is irrelevant
3911 and it makes no sense to attempt to compare it to other addresses
3912 (or use it for any other purpose either).
3914 More specifically, each of the following breakpoint types will always
3915 have a zero valued address and we don't want check_duplicates() to mark
3916 breakpoints of any of these types to be a duplicate of an actual
3917 breakpoint at address zero:
3920 bp_hardware_watchpoint
3922 bp_access_watchpoint
3926 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3928 enum bptype type
= bpt
->type
;
3930 return (type
!= bp_watchpoint
3931 && type
!= bp_hardware_watchpoint
3932 && type
!= bp_read_watchpoint
3933 && type
!= bp_access_watchpoint
3934 && type
!= bp_catchpoint
);
3937 /* Rescan breakpoints at the same address and section as BPT,
3938 marking the first one as "first" and any others as "duplicates".
3939 This is so that the bpt instruction is only inserted once.
3940 If we have a permanent breakpoint at the same place as BPT, make
3941 that one the official one, and the rest as duplicates. */
3944 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
3946 struct bp_location
*b
;
3948 struct bp_location
*perm_bp
= 0;
3950 ALL_BP_LOCATIONS (b
)
3951 if (b
->owner
->enable_state
!= bp_disabled
3952 && b
->owner
->enable_state
!= bp_call_disabled
3954 && !b
->shlib_disabled
3955 && b
->address
== address
/* address / overlay match */
3956 && (!overlay_debugging
|| b
->section
== section
)
3957 && breakpoint_address_is_meaningful (b
->owner
))
3959 /* Have we found a permanent breakpoint? */
3960 if (b
->owner
->enable_state
== bp_permanent
)
3967 b
->duplicate
= count
> 1;
3970 /* If we found a permanent breakpoint at this address, go over the
3971 list again and declare all the other breakpoints there to be the
3975 perm_bp
->duplicate
= 0;
3977 /* Permanent breakpoint should always be inserted. */
3978 if (! perm_bp
->inserted
)
3979 internal_error (__FILE__
, __LINE__
,
3980 _("allegedly permanent breakpoint is not "
3981 "actually inserted"));
3983 ALL_BP_LOCATIONS (b
)
3986 if (b
->owner
->enable_state
!= bp_disabled
3987 && b
->owner
->enable_state
!= bp_call_disabled
3988 && b
->enabled
&& !b
->shlib_disabled
3989 && b
->address
== address
/* address / overlay match */
3990 && (!overlay_debugging
|| b
->section
== section
)
3991 && breakpoint_address_is_meaningful (b
->owner
))
3994 internal_error (__FILE__
, __LINE__
,
3995 _("another breakpoint was inserted on top of "
3996 "a permanent breakpoint"));
4005 check_duplicates (struct breakpoint
*bpt
)
4007 struct bp_location
*bl
= bpt
->loc
;
4009 if (! breakpoint_address_is_meaningful (bpt
))
4012 for (; bl
; bl
= bl
->next
)
4013 check_duplicates_for (bl
->address
, bl
->section
);
4017 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4018 int bnum
, int have_bnum
)
4023 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4024 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4026 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4027 bnum
, astr1
, astr2
);
4029 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4032 /* Adjust a breakpoint's address to account for architectural constraints
4033 on breakpoint placement. Return the adjusted address. Note: Very
4034 few targets require this kind of adjustment. For most targets,
4035 this function is simply the identity function. */
4038 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4040 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4042 /* Very few targets need any kind of breakpoint adjustment. */
4045 else if (bptype
== bp_watchpoint
4046 || bptype
== bp_hardware_watchpoint
4047 || bptype
== bp_read_watchpoint
4048 || bptype
== bp_access_watchpoint
4049 || bptype
== bp_catchpoint
)
4051 /* Watchpoints and the various bp_catch_* eventpoints should not
4052 have their addresses modified. */
4057 CORE_ADDR adjusted_bpaddr
;
4059 /* Some targets have architectural constraints on the placement
4060 of breakpoint instructions. Obtain the adjusted address. */
4061 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4064 /* An adjusted breakpoint address can significantly alter
4065 a user's expectations. Print a warning if an adjustment
4067 if (adjusted_bpaddr
!= bpaddr
)
4068 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4070 return adjusted_bpaddr
;
4074 /* Allocate a struct bp_location. */
4076 static struct bp_location
*
4077 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4079 struct bp_location
*loc
, *loc_p
;
4081 loc
= xmalloc (sizeof (struct bp_location
));
4082 memset (loc
, 0, sizeof (*loc
));
4086 loc
->shlib_disabled
= 0;
4095 case bp_longjmp_resume
:
4096 case bp_step_resume
:
4097 case bp_watchpoint_scope
:
4099 case bp_shlib_event
:
4100 case bp_thread_event
:
4101 case bp_overlay_event
:
4102 loc
->loc_type
= bp_loc_software_breakpoint
;
4104 case bp_hardware_breakpoint
:
4105 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4107 case bp_hardware_watchpoint
:
4108 case bp_read_watchpoint
:
4109 case bp_access_watchpoint
:
4110 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4114 loc
->loc_type
= bp_loc_other
;
4117 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4123 static void free_bp_location (struct bp_location
*loc
)
4128 if (loc
->function_name
)
4129 xfree (loc
->function_name
);
4134 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4135 that has type BPTYPE and has no locations as yet. */
4137 static struct breakpoint
*
4138 set_raw_breakpoint_without_location (enum bptype bptype
)
4140 struct breakpoint
*b
, *b1
;
4142 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4143 memset (b
, 0, sizeof (*b
));
4146 b
->language
= current_language
->la_language
;
4147 b
->input_radix
= input_radix
;
4149 b
->enable_state
= bp_enabled
;
4152 b
->ignore_count
= 0;
4154 b
->frame_id
= null_frame_id
;
4155 b
->forked_inferior_pid
= null_ptid
;
4156 b
->exec_pathname
= NULL
;
4158 b
->condition_not_parsed
= 0;
4160 /* Add this breakpoint to the end of the chain
4161 so that a list of breakpoints will come out in order
4162 of increasing numbers. */
4164 b1
= breakpoint_chain
;
4166 breakpoint_chain
= b
;
4176 /* Initialize loc->function_name. */
4178 set_breakpoint_location_function (struct bp_location
*loc
)
4180 if (loc
->owner
->type
== bp_breakpoint
4181 || loc
->owner
->type
== bp_hardware_breakpoint
)
4183 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4185 if (loc
->function_name
)
4186 loc
->function_name
= xstrdup (loc
->function_name
);
4190 /* set_raw_breakpoint is a low level routine for allocating and
4191 partially initializing a breakpoint of type BPTYPE. The newly
4192 created breakpoint's address, section, source file name, and line
4193 number are provided by SAL. The newly created and partially
4194 initialized breakpoint is added to the breakpoint chain and
4195 is also returned as the value of this function.
4197 It is expected that the caller will complete the initialization of
4198 the newly created breakpoint struct as well as output any status
4199 information regarding the creation of a new breakpoint. In
4200 particular, set_raw_breakpoint does NOT set the breakpoint
4201 number! Care should be taken to not allow an error to occur
4202 prior to completing the initialization of the breakpoint. If this
4203 should happen, a bogus breakpoint will be left on the chain. */
4206 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4208 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4209 CORE_ADDR adjusted_address
;
4211 /* Adjust the breakpoint's address prior to allocating a location.
4212 Once we call allocate_bp_location(), that mostly uninitialized
4213 location will be placed on the location chain. Adjustment of the
4214 breakpoint may cause target_read_memory() to be called and we do
4215 not want its scan of the location chain to find a breakpoint and
4216 location that's only been partially initialized. */
4217 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4219 b
->loc
= allocate_bp_location (b
, bptype
);
4220 b
->loc
->requested_address
= sal
.pc
;
4221 b
->loc
->address
= adjusted_address
;
4223 if (sal
.symtab
== NULL
)
4224 b
->source_file
= NULL
;
4226 b
->source_file
= savestring (sal
.symtab
->filename
,
4227 strlen (sal
.symtab
->filename
));
4228 b
->loc
->section
= sal
.section
;
4229 b
->line_number
= sal
.line
;
4231 set_breakpoint_location_function (b
->loc
);
4233 breakpoints_changed ();
4239 /* Note that the breakpoint object B describes a permanent breakpoint
4240 instruction, hard-wired into the inferior's code. */
4242 make_breakpoint_permanent (struct breakpoint
*b
)
4244 struct bp_location
*bl
;
4245 b
->enable_state
= bp_permanent
;
4247 /* By definition, permanent breakpoints are already present in the code.
4248 Mark all locations as inserted. For now, make_breakpoint_permanent
4249 is called in just one place, so it's hard to say if it's reasonable
4250 to have permanent breakpoint with multiple locations or not,
4251 but it's easy to implmement. */
4252 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4256 static struct breakpoint
*
4257 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4259 static int internal_breakpoint_number
= -1;
4260 struct symtab_and_line sal
;
4261 struct breakpoint
*b
;
4263 init_sal (&sal
); /* initialize to zeroes */
4266 sal
.section
= find_pc_overlay (sal
.pc
);
4268 b
= set_raw_breakpoint (sal
, type
);
4269 b
->number
= internal_breakpoint_number
--;
4270 b
->disposition
= disp_donttouch
;
4277 create_longjmp_breakpoint (char *func_name
)
4279 struct minimal_symbol
*m
;
4281 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4283 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4284 update_global_location_list (1);
4287 /* Call this routine when stepping and nexting to enable a breakpoint
4288 if we do a longjmp(). When we hit that breakpoint, call
4289 set_longjmp_resume_breakpoint() to figure out where we are going. */
4292 set_longjmp_breakpoint (void)
4294 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4296 create_longjmp_breakpoint ("longjmp");
4297 create_longjmp_breakpoint ("_longjmp");
4298 create_longjmp_breakpoint ("siglongjmp");
4299 create_longjmp_breakpoint ("_siglongjmp");
4303 /* Delete all longjmp breakpoints from THREAD. */
4305 delete_longjmp_breakpoint (int thread
)
4307 struct breakpoint
*b
, *temp
;
4309 ALL_BREAKPOINTS_SAFE (b
, temp
)
4310 if (b
->type
== bp_longjmp
)
4312 if (b
->thread
== thread
)
4313 delete_breakpoint (b
);
4318 create_overlay_event_breakpoint_1 (char *func_name
, struct objfile
*objfile
)
4320 struct breakpoint
*b
;
4321 struct minimal_symbol
*m
;
4323 if ((m
= lookup_minimal_symbol_text (func_name
, objfile
)) == NULL
)
4326 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4328 b
->addr_string
= xstrdup (func_name
);
4330 if (overlay_debugging
== ovly_auto
)
4332 b
->enable_state
= bp_enabled
;
4333 overlay_events_enabled
= 1;
4337 b
->enable_state
= bp_disabled
;
4338 overlay_events_enabled
= 0;
4340 update_global_location_list (1);
4344 create_overlay_event_breakpoint (char *func_name
)
4346 struct objfile
*objfile
;
4347 ALL_OBJFILES (objfile
)
4348 create_overlay_event_breakpoint_1 (func_name
, objfile
);
4352 enable_overlay_breakpoints (void)
4354 struct breakpoint
*b
;
4357 if (b
->type
== bp_overlay_event
)
4359 b
->enable_state
= bp_enabled
;
4360 update_global_location_list (1);
4361 overlay_events_enabled
= 1;
4366 disable_overlay_breakpoints (void)
4368 struct breakpoint
*b
;
4371 if (b
->type
== bp_overlay_event
)
4373 b
->enable_state
= bp_disabled
;
4374 update_global_location_list (0);
4375 overlay_events_enabled
= 0;
4380 create_thread_event_breakpoint (CORE_ADDR address
)
4382 struct breakpoint
*b
;
4384 b
= create_internal_breakpoint (address
, bp_thread_event
);
4386 b
->enable_state
= bp_enabled
;
4387 /* addr_string has to be used or breakpoint_re_set will delete me. */
4388 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4390 update_global_location_list_nothrow (1);
4396 remove_thread_event_breakpoints (void)
4398 struct breakpoint
*b
, *temp
;
4400 ALL_BREAKPOINTS_SAFE (b
, temp
)
4401 if (b
->type
== bp_thread_event
)
4402 delete_breakpoint (b
);
4405 struct captured_parse_breakpoint_args
4408 struct symtabs_and_lines
*sals_p
;
4409 char ***addr_string_p
;
4413 struct lang_and_radix
4421 remove_solib_event_breakpoints (void)
4423 struct breakpoint
*b
, *temp
;
4425 ALL_BREAKPOINTS_SAFE (b
, temp
)
4426 if (b
->type
== bp_shlib_event
)
4427 delete_breakpoint (b
);
4431 create_solib_event_breakpoint (CORE_ADDR address
)
4433 struct breakpoint
*b
;
4435 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4436 update_global_location_list_nothrow (1);
4440 /* Disable any breakpoints that are on code in shared libraries. Only
4441 apply to enabled breakpoints, disabled ones can just stay disabled. */
4444 disable_breakpoints_in_shlibs (void)
4446 struct bp_location
*loc
;
4447 int disabled_shlib_breaks
= 0;
4449 ALL_BP_LOCATIONS (loc
)
4451 struct breakpoint
*b
= loc
->owner
;
4452 /* We apply the check to all breakpoints, including disabled
4453 for those with loc->duplicate set. This is so that when breakpoint
4454 becomes enabled, or the duplicate is removed, gdb will try to insert
4455 all breakpoints. If we don't set shlib_disabled here, we'll try
4456 to insert those breakpoints and fail. */
4457 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4458 && !loc
->shlib_disabled
4460 && PC_SOLIB (loc
->address
)
4462 && solib_address (loc
->address
)
4466 loc
->shlib_disabled
= 1;
4471 /* Disable any breakpoints that are in in an unloaded shared library. Only
4472 apply to enabled breakpoints, disabled ones can just stay disabled. */
4475 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4477 struct bp_location
*loc
;
4478 int disabled_shlib_breaks
= 0;
4480 ALL_BP_LOCATIONS (loc
)
4482 struct breakpoint
*b
= loc
->owner
;
4483 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4484 || loc
->loc_type
== bp_loc_software_breakpoint
)
4485 && !loc
->shlib_disabled
)
4488 char *so_name
= PC_SOLIB (loc
->address
);
4490 char *so_name
= solib_address (loc
->address
);
4492 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4494 loc
->shlib_disabled
= 1;
4495 /* At this point, we cannot rely on remove_breakpoint
4496 succeeding so we must mark the breakpoint as not inserted
4497 to prevent future errors occurring in remove_breakpoints. */
4499 if (!disabled_shlib_breaks
)
4501 target_terminal_ours_for_output ();
4502 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4505 disabled_shlib_breaks
= 1;
4511 /* FORK & VFORK catchpoints. */
4513 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4516 insert_catch_fork (struct breakpoint
*b
)
4518 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4521 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4524 remove_catch_fork (struct breakpoint
*b
)
4526 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4529 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4533 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4535 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4538 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4540 static enum print_stop_action
4541 print_it_catch_fork (struct breakpoint
*b
)
4543 annotate_catchpoint (b
->number
);
4544 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4545 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4546 return PRINT_SRC_AND_LOC
;
4549 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4552 print_one_catch_fork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4554 struct value_print_options opts
;
4556 get_user_print_options (&opts
);
4558 /* Field 4, the address, is omitted (which makes the columns
4559 not line up too nicely with the headers, but the effect
4560 is relatively readable). */
4561 if (opts
.addressprint
)
4562 ui_out_field_skip (uiout
, "addr");
4564 ui_out_text (uiout
, "fork");
4565 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4567 ui_out_text (uiout
, ", process ");
4568 ui_out_field_int (uiout
, "what",
4569 ptid_get_pid (b
->forked_inferior_pid
));
4570 ui_out_spaces (uiout
, 1);
4574 /* Implement the "print_mention" breakpoint_ops method for fork
4578 print_mention_catch_fork (struct breakpoint
*b
)
4580 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4583 /* The breakpoint_ops structure to be used in fork catchpoints. */
4585 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4589 breakpoint_hit_catch_fork
,
4590 print_it_catch_fork
,
4591 print_one_catch_fork
,
4592 print_mention_catch_fork
4595 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4598 insert_catch_vfork (struct breakpoint
*b
)
4600 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4603 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4606 remove_catch_vfork (struct breakpoint
*b
)
4608 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4611 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4615 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4617 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4620 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4622 static enum print_stop_action
4623 print_it_catch_vfork (struct breakpoint
*b
)
4625 annotate_catchpoint (b
->number
);
4626 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4627 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4628 return PRINT_SRC_AND_LOC
;
4631 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4634 print_one_catch_vfork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4636 struct value_print_options opts
;
4638 get_user_print_options (&opts
);
4639 /* Field 4, the address, is omitted (which makes the columns
4640 not line up too nicely with the headers, but the effect
4641 is relatively readable). */
4642 if (opts
.addressprint
)
4643 ui_out_field_skip (uiout
, "addr");
4645 ui_out_text (uiout
, "vfork");
4646 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4648 ui_out_text (uiout
, ", process ");
4649 ui_out_field_int (uiout
, "what",
4650 ptid_get_pid (b
->forked_inferior_pid
));
4651 ui_out_spaces (uiout
, 1);
4655 /* Implement the "print_mention" breakpoint_ops method for vfork
4659 print_mention_catch_vfork (struct breakpoint
*b
)
4661 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4664 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4666 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4670 breakpoint_hit_catch_vfork
,
4671 print_it_catch_vfork
,
4672 print_one_catch_vfork
,
4673 print_mention_catch_vfork
4676 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4678 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4679 If COND_STRING is not NULL, then store it in the breakpoint.
4680 OPS, if not NULL, is the breakpoint_ops structure associated
4681 to the catchpoint. */
4683 static struct breakpoint
*
4684 create_catchpoint (int tempflag
, char *cond_string
,
4685 struct breakpoint_ops
*ops
)
4687 struct symtab_and_line sal
;
4688 struct breakpoint
*b
;
4695 b
= set_raw_breakpoint (sal
, bp_catchpoint
);
4696 set_breakpoint_count (breakpoint_count
+ 1);
4697 b
->number
= breakpoint_count
;
4699 b
->cond_string
= (cond_string
== NULL
) ?
4700 NULL
: savestring (cond_string
, strlen (cond_string
));
4702 b
->addr_string
= NULL
;
4703 b
->enable_state
= bp_enabled
;
4704 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4708 update_global_location_list (1);
4714 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4715 struct breakpoint_ops
*ops
)
4717 struct breakpoint
*b
= create_catchpoint (tempflag
, cond_string
, ops
);
4719 /* FIXME: We should put this information in a breakpoint private data
4721 b
->forked_inferior_pid
= null_ptid
;
4724 /* Exec catchpoints. */
4727 insert_catch_exec (struct breakpoint
*b
)
4729 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
4733 remove_catch_exec (struct breakpoint
*b
)
4735 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
4739 breakpoint_hit_catch_exec (struct breakpoint
*b
)
4741 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
4744 static enum print_stop_action
4745 print_it_catch_exec (struct breakpoint
*b
)
4747 annotate_catchpoint (b
->number
);
4748 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
4750 return PRINT_SRC_AND_LOC
;
4754 print_one_catch_exec (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4756 struct value_print_options opts
;
4758 get_user_print_options (&opts
);
4760 /* Field 4, the address, is omitted (which makes the columns
4761 not line up too nicely with the headers, but the effect
4762 is relatively readable). */
4763 if (opts
.addressprint
)
4764 ui_out_field_skip (uiout
, "addr");
4766 ui_out_text (uiout
, "exec");
4767 if (b
->exec_pathname
!= NULL
)
4769 ui_out_text (uiout
, ", program \"");
4770 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
4771 ui_out_text (uiout
, "\" ");
4776 print_mention_catch_exec (struct breakpoint
*b
)
4778 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
4781 static struct breakpoint_ops catch_exec_breakpoint_ops
=
4785 breakpoint_hit_catch_exec
,
4786 print_it_catch_exec
,
4787 print_one_catch_exec
,
4788 print_mention_catch_exec
4792 hw_breakpoint_used_count (void)
4794 struct breakpoint
*b
;
4799 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
4807 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4809 struct breakpoint
*b
;
4812 *other_type_used
= 0;
4815 if (breakpoint_enabled (b
))
4817 if (b
->type
== type
)
4819 else if ((b
->type
== bp_hardware_watchpoint
||
4820 b
->type
== bp_read_watchpoint
||
4821 b
->type
== bp_access_watchpoint
))
4822 *other_type_used
= 1;
4829 disable_watchpoints_before_interactive_call_start (void)
4831 struct breakpoint
*b
;
4835 if (((b
->type
== bp_watchpoint
)
4836 || (b
->type
== bp_hardware_watchpoint
)
4837 || (b
->type
== bp_read_watchpoint
)
4838 || (b
->type
== bp_access_watchpoint
))
4839 && breakpoint_enabled (b
))
4841 b
->enable_state
= bp_call_disabled
;
4842 update_global_location_list (0);
4848 enable_watchpoints_after_interactive_call_stop (void)
4850 struct breakpoint
*b
;
4854 if (((b
->type
== bp_watchpoint
)
4855 || (b
->type
== bp_hardware_watchpoint
)
4856 || (b
->type
== bp_read_watchpoint
)
4857 || (b
->type
== bp_access_watchpoint
))
4858 && (b
->enable_state
== bp_call_disabled
))
4860 b
->enable_state
= bp_enabled
;
4861 update_global_location_list (1);
4867 /* Set a breakpoint that will evaporate an end of command
4868 at address specified by SAL.
4869 Restrict it to frame FRAME if FRAME is nonzero. */
4872 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4875 struct breakpoint
*b
;
4876 b
= set_raw_breakpoint (sal
, type
);
4877 b
->enable_state
= bp_enabled
;
4878 b
->disposition
= disp_donttouch
;
4879 b
->frame_id
= frame_id
;
4881 /* If we're debugging a multi-threaded program, then we
4882 want momentary breakpoints to be active in only a
4883 single thread of control. */
4884 if (in_thread_list (inferior_ptid
))
4885 b
->thread
= pid_to_thread_id (inferior_ptid
);
4887 update_global_location_list_nothrow (1);
4893 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
4895 struct symtab_and_line sal
;
4897 sal
= find_pc_line (pc
, 0);
4899 sal
.section
= find_pc_overlay (pc
);
4900 sal
.explicit_pc
= 1;
4902 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
4906 /* Tell the user we have just set a breakpoint B. */
4909 mention (struct breakpoint
*b
)
4912 struct cleanup
*old_chain
, *ui_out_chain
;
4913 struct ui_stream
*stb
;
4914 struct value_print_options opts
;
4916 get_user_print_options (&opts
);
4918 stb
= ui_out_stream_new (uiout
);
4919 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4921 /* FIXME: This is misplaced; mention() is called by things (like
4922 hitting a watchpoint) other than breakpoint creation. It should
4923 be possible to clean this up and at the same time replace the
4924 random calls to breakpoint_changed with this hook. */
4925 observer_notify_breakpoint_created (b
->number
);
4927 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4928 b
->ops
->print_mention (b
);
4933 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4936 ui_out_text (uiout
, "Watchpoint ");
4937 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4938 ui_out_field_int (uiout
, "number", b
->number
);
4939 ui_out_text (uiout
, ": ");
4940 print_expression (b
->exp
, stb
->stream
);
4941 ui_out_field_stream (uiout
, "exp", stb
);
4942 do_cleanups (ui_out_chain
);
4944 case bp_hardware_watchpoint
:
4945 ui_out_text (uiout
, "Hardware watchpoint ");
4946 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4947 ui_out_field_int (uiout
, "number", b
->number
);
4948 ui_out_text (uiout
, ": ");
4949 print_expression (b
->exp
, stb
->stream
);
4950 ui_out_field_stream (uiout
, "exp", stb
);
4951 do_cleanups (ui_out_chain
);
4953 case bp_read_watchpoint
:
4954 ui_out_text (uiout
, "Hardware read watchpoint ");
4955 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4956 ui_out_field_int (uiout
, "number", b
->number
);
4957 ui_out_text (uiout
, ": ");
4958 print_expression (b
->exp
, stb
->stream
);
4959 ui_out_field_stream (uiout
, "exp", stb
);
4960 do_cleanups (ui_out_chain
);
4962 case bp_access_watchpoint
:
4963 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4964 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4965 ui_out_field_int (uiout
, "number", b
->number
);
4966 ui_out_text (uiout
, ": ");
4967 print_expression (b
->exp
, stb
->stream
);
4968 ui_out_field_stream (uiout
, "exp", stb
);
4969 do_cleanups (ui_out_chain
);
4972 if (ui_out_is_mi_like_p (uiout
))
4977 if (b
->disposition
== disp_del
)
4978 printf_filtered (_("Temporary breakpoint"));
4980 printf_filtered (_("Breakpoint"));
4981 printf_filtered (_(" %d"), b
->number
);
4984 case bp_hardware_breakpoint
:
4985 if (ui_out_is_mi_like_p (uiout
))
4990 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4997 case bp_longjmp_resume
:
4998 case bp_step_resume
:
5000 case bp_watchpoint_scope
:
5001 case bp_shlib_event
:
5002 case bp_thread_event
:
5003 case bp_overlay_event
:
5009 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5013 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5017 if (opts
.addressprint
|| b
->source_file
== NULL
)
5019 printf_filtered (" at ");
5020 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5023 printf_filtered (": file %s, line %d.",
5024 b
->source_file
, b
->line_number
);
5028 struct bp_location
*loc
= b
->loc
;
5030 for (; loc
; loc
= loc
->next
)
5032 printf_filtered (" (%d locations)", n
);
5037 do_cleanups (old_chain
);
5038 if (ui_out_is_mi_like_p (uiout
))
5040 printf_filtered ("\n");
5044 static struct bp_location
*
5045 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5046 const struct symtab_and_line
*sal
)
5048 struct bp_location
*loc
, **tmp
;
5050 loc
= allocate_bp_location (b
, bptype
);
5051 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5054 loc
->requested_address
= sal
->pc
;
5055 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5057 loc
->section
= sal
->section
;
5059 set_breakpoint_location_function (loc
);
5064 /* Return 1 if LOC is pointing to a permanent breakpoint,
5065 return 0 otherwise. */
5068 bp_loc_is_permanent (struct bp_location
*loc
)
5072 const gdb_byte
*brk
;
5073 gdb_byte
*target_mem
;
5075 gdb_assert (loc
!= NULL
);
5077 addr
= loc
->address
;
5078 brk
= gdbarch_breakpoint_from_pc (current_gdbarch
, &addr
, &len
);
5080 target_mem
= alloca (len
);
5082 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5083 && memcmp (target_mem
, brk
, len
) == 0)
5091 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5092 as textual description of the location, and COND_STRING
5093 as condition expression. */
5096 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5098 enum bptype type
, enum bpdisp disposition
,
5099 int thread
, int ignore_count
,
5100 struct breakpoint_ops
*ops
, int from_tty
)
5102 struct breakpoint
*b
= NULL
;
5105 if (type
== bp_hardware_breakpoint
)
5107 int i
= hw_breakpoint_used_count ();
5108 int target_resources_ok
=
5109 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5111 if (target_resources_ok
== 0)
5112 error (_("No hardware breakpoint support in the target."));
5113 else if (target_resources_ok
< 0)
5114 error (_("Hardware breakpoints used exceeds limit."));
5117 for (i
= 0; i
< sals
.nelts
; ++i
)
5119 struct symtab_and_line sal
= sals
.sals
[i
];
5120 struct bp_location
*loc
;
5123 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5127 b
= set_raw_breakpoint (sal
, type
);
5128 set_breakpoint_count (breakpoint_count
+ 1);
5129 b
->number
= breakpoint_count
;
5132 b
->cond_string
= cond_string
;
5133 b
->ignore_count
= ignore_count
;
5134 b
->enable_state
= bp_enabled
;
5135 b
->disposition
= disposition
;
5141 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5144 if (bp_loc_is_permanent (loc
))
5145 make_breakpoint_permanent (b
);
5149 char *arg
= b
->cond_string
;
5150 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5152 error (_("Garbage %s follows condition"), arg
);
5157 b
->addr_string
= addr_string
;
5159 /* addr_string has to be used or breakpoint_re_set will delete
5161 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5167 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5168 elements to fill the void space. */
5169 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5171 int i
= index_to_remove
+1;
5172 int last_index
= sal
->nelts
-1;
5174 for (;i
<= last_index
; ++i
)
5175 sal
->sals
[i
-1] = sal
->sals
[i
];
5180 /* If appropriate, obtains all sals that correspond
5181 to the same file and line as SAL. This is done
5182 only if SAL does not have explicit PC and has
5183 line and file information. If we got just a single
5184 expanded sal, return the original.
5186 Otherwise, if SAL.explicit_line is not set, filter out
5187 all sals for which the name of enclosing function
5188 is different from SAL. This makes sure that if we have
5189 breakpoint originally set in template instantiation, say
5190 foo<int>(), we won't expand SAL to locations at the same
5191 line in all existing instantiations of 'foo'.
5194 struct symtabs_and_lines
5195 expand_line_sal_maybe (struct symtab_and_line sal
)
5197 struct symtabs_and_lines expanded
;
5198 CORE_ADDR original_pc
= sal
.pc
;
5199 char *original_function
= NULL
;
5203 /* If we have explicit pc, don't expand.
5204 If we have no line number, we can't expand. */
5205 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5208 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5209 expanded
.sals
[0] = sal
;
5214 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5216 expanded
= expand_line_sal (sal
);
5217 if (expanded
.nelts
== 1)
5219 /* We had one sal, we got one sal. Without futher
5220 processing, just return the original sal. */
5221 xfree (expanded
.sals
);
5223 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5224 sal
.pc
= original_pc
;
5225 expanded
.sals
[0] = sal
;
5229 if (!sal
.explicit_line
)
5231 CORE_ADDR func_addr
, func_end
;
5232 for (i
= 0; i
< expanded
.nelts
; ++i
)
5234 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5235 char *this_function
;
5236 if (find_pc_partial_function (pc
, &this_function
,
5237 &func_addr
, &func_end
))
5239 if (this_function
&&
5240 strcmp (this_function
, original_function
) != 0)
5242 remove_sal (&expanded
, i
);
5245 else if (func_addr
== pc
)
5247 /* We're at beginning of a function, and should
5249 struct symbol
*sym
= find_pc_function (pc
);
5251 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5254 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5261 if (expanded
.nelts
<= 1)
5263 /* This is un ugly workaround. If we get zero
5264 expanded sals then something is really wrong.
5265 Fix that by returnign the original sal. */
5266 xfree (expanded
.sals
);
5268 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5269 sal
.pc
= original_pc
;
5270 expanded
.sals
[0] = sal
;
5277 for (i
= 0; i
< expanded
.nelts
; ++i
)
5278 if (expanded
.sals
[i
].pc
== original_pc
)
5289 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5290 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5291 value. COND_STRING, if not NULL, specified the condition to be
5292 used for all breakpoints. Essentially the only case where
5293 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5294 function. In that case, it's still not possible to specify
5295 separate conditions for different overloaded functions, so
5296 we take just a single condition string.
5298 NOTE: If the function succeeds, the caller is expected to cleanup
5299 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5300 array contents). If the function fails (error() is called), the
5301 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5302 COND and SALS arrays and each of those arrays contents. */
5305 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5307 enum bptype type
, enum bpdisp disposition
,
5308 int thread
, int ignore_count
,
5309 struct breakpoint_ops
*ops
, int from_tty
)
5312 for (i
= 0; i
< sals
.nelts
; ++i
)
5314 struct symtabs_and_lines expanded
=
5315 expand_line_sal_maybe (sals
.sals
[i
]);
5317 create_breakpoint (expanded
, addr_string
[i
],
5318 cond_string
, type
, disposition
,
5319 thread
, ignore_count
, ops
, from_tty
);
5322 update_global_location_list (1);
5325 /* Parse ARG which is assumed to be a SAL specification possibly
5326 followed by conditionals. On return, SALS contains an array of SAL
5327 addresses found. ADDR_STRING contains a vector of (canonical)
5328 address strings. ARG points to the end of the SAL. */
5331 parse_breakpoint_sals (char **address
,
5332 struct symtabs_and_lines
*sals
,
5333 char ***addr_string
,
5336 char *addr_start
= *address
;
5337 *addr_string
= NULL
;
5338 /* If no arg given, or if first arg is 'if ', use the default
5340 if ((*address
) == NULL
5341 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5343 if (default_breakpoint_valid
)
5345 struct symtab_and_line sal
;
5346 init_sal (&sal
); /* initialize to zeroes */
5347 sals
->sals
= (struct symtab_and_line
*)
5348 xmalloc (sizeof (struct symtab_and_line
));
5349 sal
.pc
= default_breakpoint_address
;
5350 sal
.line
= default_breakpoint_line
;
5351 sal
.symtab
= default_breakpoint_symtab
;
5352 sal
.section
= find_pc_overlay (sal
.pc
);
5353 sals
->sals
[0] = sal
;
5357 error (_("No default breakpoint address now."));
5361 /* Force almost all breakpoints to be in terms of the
5362 current_source_symtab (which is decode_line_1's default). This
5363 should produce the results we want almost all of the time while
5364 leaving default_breakpoint_* alone.
5365 ObjC: However, don't match an Objective-C method name which
5366 may have a '+' or '-' succeeded by a '[' */
5368 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5370 if (default_breakpoint_valid
5372 || ((strchr ("+-", (*address
)[0]) != NULL
)
5373 && ((*address
)[1] != '['))))
5374 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5375 default_breakpoint_line
, addr_string
,
5378 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5379 addr_string
, not_found_ptr
);
5381 /* For any SAL that didn't have a canonical string, fill one in. */
5382 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5383 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5384 if (addr_start
!= (*address
))
5387 for (i
= 0; i
< sals
->nelts
; i
++)
5389 /* Add the string if not present. */
5390 if ((*addr_string
)[i
] == NULL
)
5391 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5397 /* Convert each SAL into a real PC. Verify that the PC can be
5398 inserted as a breakpoint. If it can't throw an error. */
5401 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5405 for (i
= 0; i
< sals
->nelts
; i
++)
5406 resolve_sal_pc (&sals
->sals
[i
]);
5410 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5412 struct captured_parse_breakpoint_args
*args
= data
;
5414 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5415 args
->not_found_ptr
);
5418 /* Given TOK, a string specification of condition and thread, as
5419 accepted by the 'break' command, extract the condition
5420 string and thread number and set *COND_STRING and *THREAD.
5421 PC identifies the context at which the condition should be parsed.
5422 If no condition is found, *COND_STRING is set to NULL.
5423 If no thread is found, *THREAD is set to -1. */
5425 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5426 char **cond_string
, int *thread
)
5428 *cond_string
= NULL
;
5434 char *cond_start
= NULL
;
5435 char *cond_end
= NULL
;
5436 while (*tok
== ' ' || *tok
== '\t')
5441 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5444 toklen
= end_tok
- tok
;
5446 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5448 tok
= cond_start
= end_tok
+ 1;
5449 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5451 *cond_string
= savestring (cond_start
,
5452 cond_end
- cond_start
);
5454 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5460 *thread
= strtol (tok
, &tok
, 0);
5462 error (_("Junk after thread keyword."));
5463 if (!valid_thread_id (*thread
))
5464 error (_("Unknown thread %d."), *thread
);
5467 error (_("Junk at end of arguments."));
5471 /* Set a breakpoint. This function is shared between
5472 CLI and MI functions for setting a breakpoint.
5473 This function has two major modes of operations,
5474 selected by the PARSE_CONDITION_AND_THREAD parameter.
5475 If non-zero, the function will parse arg, extracting
5476 breakpoint location, address and thread. Otherwise,
5477 ARG is just the location of breakpoint, with condition
5478 and thread specified by the COND_STRING and THREAD
5482 break_command_really (char *arg
, char *cond_string
, int thread
,
5483 int parse_condition_and_thread
,
5484 int tempflag
, int hardwareflag
,
5486 enum auto_boolean pending_break_support
,
5487 struct breakpoint_ops
*ops
,
5490 struct gdb_exception e
;
5491 struct symtabs_and_lines sals
;
5492 struct symtab_and_line pending_sal
;
5495 char *addr_start
= arg
;
5497 struct cleanup
*old_chain
;
5498 struct cleanup
*breakpoint_chain
= NULL
;
5499 struct captured_parse_breakpoint_args parse_args
;
5508 parse_args
.arg_p
= &arg
;
5509 parse_args
.sals_p
= &sals
;
5510 parse_args
.addr_string_p
= &addr_string
;
5511 parse_args
.not_found_ptr
= ¬_found
;
5513 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5514 &parse_args
, RETURN_MASK_ALL
);
5516 /* If caller is interested in rc value from parse, set value. */
5520 throw_exception (e
);
5524 case NOT_FOUND_ERROR
:
5526 /* If pending breakpoint support is turned off, throw
5529 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5530 throw_exception (e
);
5532 exception_print (gdb_stderr
, e
);
5534 /* If pending breakpoint support is auto query and the user
5535 selects no, then simply return the error code. */
5536 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5537 !nquery ("Make breakpoint pending on future shared library load? "))
5540 /* At this point, either the user was queried about setting
5541 a pending breakpoint and selected yes, or pending
5542 breakpoint behavior is on and thus a pending breakpoint
5543 is defaulted on behalf of the user. */
5544 copy_arg
= xstrdup (addr_start
);
5545 addr_string
= ©_arg
;
5547 sals
.sals
= &pending_sal
;
5552 throw_exception (e
);
5559 /* Create a chain of things that always need to be cleaned up. */
5560 old_chain
= make_cleanup (null_cleanup
, 0);
5564 /* Make sure that all storage allocated to SALS gets freed. */
5565 make_cleanup (xfree
, sals
.sals
);
5567 /* Cleanup the addr_string array but not its contents. */
5568 make_cleanup (xfree
, addr_string
);
5571 /* ----------------------------- SNIP -----------------------------
5572 Anything added to the cleanup chain beyond this point is assumed
5573 to be part of a breakpoint. If the breakpoint create succeeds
5574 then the memory is not reclaimed. */
5575 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5577 /* Mark the contents of the addr_string for cleanup. These go on
5578 the breakpoint_chain and only occure if the breakpoint create
5580 for (i
= 0; i
< sals
.nelts
; i
++)
5582 if (addr_string
[i
] != NULL
)
5583 make_cleanup (xfree
, addr_string
[i
]);
5586 /* Resolve all line numbers to PC's and verify that the addresses
5587 are ok for the target. */
5589 breakpoint_sals_to_pc (&sals
, addr_start
);
5591 /* Verify that condition can be parsed, before setting any
5592 breakpoints. Allocate a separate condition expression for each
5596 if (parse_condition_and_thread
)
5598 /* Here we only parse 'arg' to separate condition
5599 from thread number, so parsing in context of first
5600 sal is OK. When setting the breakpoint we'll
5601 re-parse it in context of each sal. */
5604 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5606 make_cleanup (xfree
, cond_string
);
5610 /* Create a private copy of condition string. */
5613 cond_string
= xstrdup (cond_string
);
5614 make_cleanup (xfree
, cond_string
);
5617 create_breakpoints (sals
, addr_string
, cond_string
,
5618 hardwareflag
? bp_hardware_breakpoint
5620 tempflag
? disp_del
: disp_donttouch
,
5621 thread
, ignore_count
, ops
, from_tty
);
5625 struct symtab_and_line sal
= {0};
5626 struct breakpoint
*b
;
5628 make_cleanup (xfree
, copy_arg
);
5630 b
= set_raw_breakpoint_without_location (hardwareflag
5631 ? bp_hardware_breakpoint
5633 set_breakpoint_count (breakpoint_count
+ 1);
5634 b
->number
= breakpoint_count
;
5636 b
->addr_string
= addr_string
[0];
5637 b
->cond_string
= NULL
;
5638 b
->ignore_count
= ignore_count
;
5639 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5640 b
->condition_not_parsed
= 1;
5643 update_global_location_list (1);
5648 warning (_("Multiple breakpoints were set.\n"
5649 "Use the \"delete\" command to delete unwanted breakpoints."));
5650 /* That's it. Discard the cleanups for data inserted into the
5652 discard_cleanups (breakpoint_chain
);
5653 /* But cleanup everything else. */
5654 do_cleanups (old_chain
);
5657 /* Set a breakpoint.
5658 ARG is a string describing breakpoint address,
5659 condition, and thread.
5660 FLAG specifies if a breakpoint is hardware on,
5661 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5665 break_command_1 (char *arg
, int flag
, int from_tty
)
5667 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5668 int tempflag
= flag
& BP_TEMPFLAG
;
5670 break_command_really (arg
,
5671 NULL
, 0, 1 /* parse arg */,
5672 tempflag
, hardwareflag
,
5673 0 /* Ignore count */,
5674 pending_break_support
,
5675 NULL
/* breakpoint_ops */,
5681 set_breakpoint (char *address
, char *condition
,
5682 int hardwareflag
, int tempflag
,
5683 int thread
, int ignore_count
,
5686 break_command_really (address
, condition
, thread
,
5687 0 /* condition and thread are valid. */,
5688 tempflag
, hardwareflag
,
5691 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5695 /* Adjust SAL to the first instruction past the function prologue.
5696 The end of the prologue is determined using the line table from
5697 the debugging information.
5699 If SAL is already past the prologue, then do nothing. */
5702 skip_prologue_sal (struct symtab_and_line
*sal
)
5704 struct symbol
*sym
= find_pc_function (sal
->pc
);
5705 struct symtab_and_line start_sal
;
5710 start_sal
= find_function_start_sal (sym
, 1);
5711 if (sal
->pc
< start_sal
.pc
)
5715 /* Helper function for break_command_1 and disassemble_command. */
5718 resolve_sal_pc (struct symtab_and_line
*sal
)
5722 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5724 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5725 error (_("No line %d in file \"%s\"."),
5726 sal
->line
, sal
->symtab
->filename
);
5729 /* If this SAL corresponds to a breakpoint inserted using
5730 a line number, then skip the function prologue if necessary. */
5731 if (sal
->explicit_line
)
5732 skip_prologue_sal (sal
);
5735 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5737 struct blockvector
*bv
;
5741 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5744 sym
= block_linkage_function (b
);
5747 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5748 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
5752 /* It really is worthwhile to have the section, so we'll just
5753 have to look harder. This case can be executed if we have
5754 line numbers but no functions (as can happen in assembly
5757 struct minimal_symbol
*msym
;
5759 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5761 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
5768 break_command (char *arg
, int from_tty
)
5770 break_command_1 (arg
, 0, from_tty
);
5774 tbreak_command (char *arg
, int from_tty
)
5776 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5780 hbreak_command (char *arg
, int from_tty
)
5782 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5786 thbreak_command (char *arg
, int from_tty
)
5788 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5792 stop_command (char *arg
, int from_tty
)
5794 printf_filtered (_("Specify the type of breakpoint to set.\n\
5795 Usage: stop in <function | address>\n\
5796 stop at <line>\n"));
5800 stopin_command (char *arg
, int from_tty
)
5804 if (arg
== (char *) NULL
)
5806 else if (*arg
!= '*')
5811 /* look for a ':'. If this is a line number specification, then
5812 say it is bad, otherwise, it should be an address or
5813 function/method name */
5814 while (*argptr
&& !hasColon
)
5816 hasColon
= (*argptr
== ':');
5821 badInput
= (*argptr
!= ':'); /* Not a class::method */
5823 badInput
= isdigit (*arg
); /* a simple line number */
5827 printf_filtered (_("Usage: stop in <function | address>\n"));
5829 break_command_1 (arg
, 0, from_tty
);
5833 stopat_command (char *arg
, int from_tty
)
5837 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5844 /* look for a ':'. If there is a '::' then get out, otherwise
5845 it is probably a line number. */
5846 while (*argptr
&& !hasColon
)
5848 hasColon
= (*argptr
== ':');
5853 badInput
= (*argptr
== ':'); /* we have class::method */
5855 badInput
= !isdigit (*arg
); /* not a line number */
5859 printf_filtered (_("Usage: stop at <line>\n"));
5861 break_command_1 (arg
, 0, from_tty
);
5864 /* accessflag: hw_write: watch write,
5865 hw_read: watch read,
5866 hw_access: watch access (read or write) */
5868 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5870 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5871 struct symtab_and_line sal
;
5872 struct expression
*exp
;
5873 struct block
*exp_valid_block
;
5874 struct value
*val
, *mark
;
5875 struct frame_info
*frame
;
5876 struct frame_info
*prev_frame
= NULL
;
5877 char *exp_start
= NULL
;
5878 char *exp_end
= NULL
;
5879 char *tok
, *id_tok_start
, *end_tok
;
5881 char *cond_start
= NULL
;
5882 char *cond_end
= NULL
;
5883 struct expression
*cond
= NULL
;
5884 int i
, other_type_used
, target_resources_ok
= 0;
5885 enum bptype bp_type
;
5889 init_sal (&sal
); /* initialize to zeroes */
5891 /* Make sure that we actually have parameters to parse. */
5892 if (arg
!= NULL
&& arg
[0] != '\0')
5894 toklen
= strlen (arg
); /* Size of argument list. */
5896 /* Points tok to the end of the argument list. */
5897 tok
= arg
+ toklen
- 1;
5899 /* Go backwards in the parameters list. Skip the last parameter.
5900 If we're expecting a 'thread <thread_num>' parameter, this should
5901 be the thread identifier. */
5902 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5904 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5907 /* Points end_tok to the beginning of the last token. */
5908 id_tok_start
= tok
+ 1;
5910 /* Go backwards in the parameters list. Skip one more parameter.
5911 If we're expecting a 'thread <thread_num>' parameter, we should
5912 reach a "thread" token. */
5913 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5918 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5921 /* Move the pointer forward to skip the whitespace and
5922 calculate the length of the token. */
5924 toklen
= end_tok
- tok
;
5926 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5928 /* At this point we've found a "thread" token, which means
5929 the user is trying to set a watchpoint that triggers
5930 only in a specific thread. */
5933 /* Extract the thread ID from the next token. */
5934 thread
= strtol (id_tok_start
, &endp
, 0);
5936 /* Check if the user provided a valid numeric value for the
5938 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5939 error (_("Invalid thread ID specification %s."), id_tok_start
);
5941 /* Check if the thread actually exists. */
5942 if (!valid_thread_id (thread
))
5943 error (_("Unknown thread %d."), thread
);
5945 /* Truncate the string and get rid of the thread <thread_num>
5946 parameter before the parameter list is parsed by the
5947 evaluate_expression() function. */
5952 /* Parse the rest of the arguments. */
5953 innermost_block
= NULL
;
5955 exp
= parse_exp_1 (&arg
, 0, 0);
5957 exp_valid_block
= innermost_block
;
5958 mark
= value_mark ();
5959 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5961 release_value (val
);
5964 while (*tok
== ' ' || *tok
== '\t')
5968 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5971 toklen
= end_tok
- tok
;
5972 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5974 tok
= cond_start
= end_tok
+ 1;
5975 cond
= parse_exp_1 (&tok
, 0, 0);
5979 error (_("Junk at end of command."));
5981 if (accessflag
== hw_read
)
5982 bp_type
= bp_read_watchpoint
;
5983 else if (accessflag
== hw_access
)
5984 bp_type
= bp_access_watchpoint
;
5986 bp_type
= bp_hardware_watchpoint
;
5988 mem_cnt
= can_use_hardware_watchpoint (val
);
5989 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5990 error (_("Expression cannot be implemented with read/access watchpoint."));
5993 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5994 target_resources_ok
=
5995 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5997 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5998 error (_("Target does not support this type of hardware watchpoint."));
6000 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
6001 error (_("Target can only support one kind of HW watchpoint at a time."));
6004 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6005 watchpoint could not be set. */
6006 if (!mem_cnt
|| target_resources_ok
<= 0)
6007 bp_type
= bp_watchpoint
;
6009 frame
= block_innermost_frame (exp_valid_block
);
6011 prev_frame
= get_prev_frame (frame
);
6015 /* If the expression is "local", then set up a "watchpoint scope"
6016 breakpoint at the point where we've left the scope of the watchpoint
6017 expression. Create the scope breakpoint before the watchpoint, so
6018 that we will encounter it first in bpstat_stop_status. */
6019 if (innermost_block
&& prev_frame
)
6021 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
6022 bp_watchpoint_scope
);
6024 scope_breakpoint
->enable_state
= bp_enabled
;
6026 /* Automatically delete the breakpoint when it hits. */
6027 scope_breakpoint
->disposition
= disp_del
;
6029 /* Only break in the proper frame (help with recursion). */
6030 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6032 /* Set the address at which we will stop. */
6033 scope_breakpoint
->loc
->requested_address
6034 = get_frame_pc (prev_frame
);
6035 scope_breakpoint
->loc
->address
6036 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6037 scope_breakpoint
->type
);
6040 /* Now set up the breakpoint. */
6041 b
= set_raw_breakpoint (sal
, bp_type
);
6042 set_breakpoint_count (breakpoint_count
+ 1);
6043 b
->number
= breakpoint_count
;
6045 b
->disposition
= disp_donttouch
;
6047 b
->exp_valid_block
= exp_valid_block
;
6048 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6051 b
->loc
->cond
= cond
;
6053 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6058 b
->watchpoint_frame
= get_frame_id (frame
);
6060 b
->watchpoint_frame
= null_frame_id
;
6062 if (scope_breakpoint
!= NULL
)
6064 /* The scope breakpoint is related to the watchpoint. We will
6065 need to act on them together. */
6066 b
->related_breakpoint
= scope_breakpoint
;
6067 scope_breakpoint
->related_breakpoint
= b
;
6070 value_free_to_mark (mark
);
6072 update_global_location_list (1);
6075 /* Return count of locations need to be watched and can be handled
6076 in hardware. If the watchpoint can not be handled
6077 in hardware return zero. */
6080 can_use_hardware_watchpoint (struct value
*v
)
6082 int found_memory_cnt
= 0;
6083 struct value
*head
= v
;
6085 /* Did the user specifically forbid us to use hardware watchpoints? */
6086 if (!can_use_hw_watchpoints
)
6089 /* Make sure that the value of the expression depends only upon
6090 memory contents, and values computed from them within GDB. If we
6091 find any register references or function calls, we can't use a
6092 hardware watchpoint.
6094 The idea here is that evaluating an expression generates a series
6095 of values, one holding the value of every subexpression. (The
6096 expression a*b+c has five subexpressions: a, b, a*b, c, and
6097 a*b+c.) GDB's values hold almost enough information to establish
6098 the criteria given above --- they identify memory lvalues,
6099 register lvalues, computed values, etcetera. So we can evaluate
6100 the expression, and then scan the chain of values that leaves
6101 behind to decide whether we can detect any possible change to the
6102 expression's final value using only hardware watchpoints.
6104 However, I don't think that the values returned by inferior
6105 function calls are special in any way. So this function may not
6106 notice that an expression involving an inferior function call
6107 can't be watched with hardware watchpoints. FIXME. */
6108 for (; v
; v
= value_next (v
))
6110 if (VALUE_LVAL (v
) == lval_memory
)
6113 /* A lazy memory lvalue is one that GDB never needed to fetch;
6114 we either just used its address (e.g., `a' in `a.b') or
6115 we never needed it at all (e.g., `a' in `a,b'). */
6119 /* Ahh, memory we actually used! Check if we can cover
6120 it with hardware watchpoints. */
6121 struct type
*vtype
= check_typedef (value_type (v
));
6123 /* We only watch structs and arrays if user asked for it
6124 explicitly, never if they just happen to appear in a
6125 middle of some value chain. */
6127 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6128 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6130 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6131 int len
= TYPE_LENGTH (value_type (v
));
6133 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6140 else if (VALUE_LVAL (v
) != not_lval
6141 && deprecated_value_modifiable (v
) == 0)
6142 return 0; /* ??? What does this represent? */
6143 else if (VALUE_LVAL (v
) == lval_register
)
6144 return 0; /* cannot watch a register with a HW watchpoint */
6147 /* The expression itself looks suitable for using a hardware
6148 watchpoint, but give the target machine a chance to reject it. */
6149 return found_memory_cnt
;
6153 watch_command_wrapper (char *arg
, int from_tty
)
6155 watch_command (arg
, from_tty
);
6159 watch_command (char *arg
, int from_tty
)
6161 watch_command_1 (arg
, hw_write
, from_tty
);
6165 rwatch_command_wrapper (char *arg
, int from_tty
)
6167 rwatch_command (arg
, from_tty
);
6171 rwatch_command (char *arg
, int from_tty
)
6173 watch_command_1 (arg
, hw_read
, from_tty
);
6177 awatch_command_wrapper (char *arg
, int from_tty
)
6179 awatch_command (arg
, from_tty
);
6183 awatch_command (char *arg
, int from_tty
)
6185 watch_command_1 (arg
, hw_access
, from_tty
);
6189 /* Helper routines for the until_command routine in infcmd.c. Here
6190 because it uses the mechanisms of breakpoints. */
6192 struct until_break_command_continuation_args
6194 struct breakpoint
*breakpoint
;
6195 struct breakpoint
*breakpoint2
;
6198 /* This function is called by fetch_inferior_event via the
6199 cmd_continuation pointer, to complete the until command. It takes
6200 care of cleaning up the temporary breakpoints set up by the until
6203 until_break_command_continuation (void *arg
)
6205 struct until_break_command_continuation_args
*a
= arg
;
6207 delete_breakpoint (a
->breakpoint
);
6209 delete_breakpoint (a
->breakpoint2
);
6213 until_break_command (char *arg
, int from_tty
, int anywhere
)
6215 struct symtabs_and_lines sals
;
6216 struct symtab_and_line sal
;
6217 struct frame_info
*frame
= get_selected_frame (NULL
);
6218 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6219 struct breakpoint
*breakpoint
;
6220 struct breakpoint
*breakpoint2
= NULL
;
6221 struct cleanup
*old_chain
;
6223 clear_proceed_status ();
6225 /* Set a breakpoint where the user wants it and at return from
6228 if (default_breakpoint_valid
)
6229 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6230 default_breakpoint_line
, (char ***) NULL
, NULL
);
6232 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6233 0, (char ***) NULL
, NULL
);
6235 if (sals
.nelts
!= 1)
6236 error (_("Couldn't get information on specified line."));
6239 xfree (sals
.sals
); /* malloc'd, so freed */
6242 error (_("Junk at end of arguments."));
6244 resolve_sal_pc (&sal
);
6247 /* If the user told us to continue until a specified location,
6248 we don't specify a frame at which we need to stop. */
6249 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6251 /* Otherwise, specify the current frame, because we want to stop only
6252 at the very same frame. */
6253 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6256 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6258 /* Keep within the current frame, or in frames called by the current
6262 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6263 sal
.pc
= get_frame_pc (prev_frame
);
6264 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6266 make_cleanup_delete_breakpoint (breakpoint2
);
6269 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6271 /* If we are running asynchronously, and proceed call above has actually
6272 managed to start the target, arrange for breakpoints to be
6273 deleted when the target stops. Otherwise, we're already stopped and
6274 delete breakpoints via cleanup chain. */
6276 if (target_can_async_p () && is_running (inferior_ptid
))
6278 struct until_break_command_continuation_args
*args
;
6279 args
= xmalloc (sizeof (*args
));
6281 args
->breakpoint
= breakpoint
;
6282 args
->breakpoint2
= breakpoint2
;
6284 discard_cleanups (old_chain
);
6285 add_continuation (inferior_thread (),
6286 until_break_command_continuation
, args
,
6290 do_cleanups (old_chain
);
6294 ep_skip_leading_whitespace (char **s
)
6296 if ((s
== NULL
) || (*s
== NULL
))
6298 while (isspace (**s
))
6302 /* This function attempts to parse an optional "if <cond>" clause
6303 from the arg string. If one is not found, it returns NULL.
6305 Else, it returns a pointer to the condition string. (It does not
6306 attempt to evaluate the string against a particular block.) And,
6307 it updates arg to point to the first character following the parsed
6308 if clause in the arg string. */
6311 ep_parse_optional_if_clause (char **arg
)
6315 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6318 /* Skip the "if" keyword. */
6321 /* Skip any extra leading whitespace, and record the start of the
6322 condition string. */
6323 ep_skip_leading_whitespace (arg
);
6326 /* Assume that the condition occupies the remainder of the arg string. */
6327 (*arg
) += strlen (cond_string
);
6332 /* This function attempts to parse an optional filename from the arg
6333 string. If one is not found, it returns NULL.
6335 Else, it returns a pointer to the parsed filename. (This function
6336 makes no attempt to verify that a file of that name exists, or is
6337 accessible.) And, it updates arg to point to the first character
6338 following the parsed filename in the arg string.
6340 Note that clients needing to preserve the returned filename for
6341 future access should copy it to their own buffers. */
6343 ep_parse_optional_filename (char **arg
)
6345 static char filename
[1024];
6350 if ((*arg_p
== '\0') || isspace (*arg_p
))
6368 /* Commands to deal with catching events, such as signals, exceptions,
6369 process start/exit, etc. */
6373 catch_fork_temporary
, catch_vfork_temporary
,
6374 catch_fork_permanent
, catch_vfork_permanent
6379 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6381 char *cond_string
= NULL
;
6382 catch_fork_kind fork_kind
;
6385 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6386 tempflag
= (fork_kind
== catch_fork_temporary
6387 || fork_kind
== catch_vfork_temporary
);
6391 ep_skip_leading_whitespace (&arg
);
6393 /* The allowed syntax is:
6395 catch [v]fork if <cond>
6397 First, check if there's an if clause. */
6398 cond_string
= ep_parse_optional_if_clause (&arg
);
6400 if ((*arg
!= '\0') && !isspace (*arg
))
6401 error (_("Junk at end of arguments."));
6403 /* If this target supports it, create a fork or vfork catchpoint
6404 and enable reporting of such events. */
6407 case catch_fork_temporary
:
6408 case catch_fork_permanent
:
6409 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6410 &catch_fork_breakpoint_ops
);
6412 case catch_vfork_temporary
:
6413 case catch_vfork_permanent
:
6414 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6415 &catch_vfork_breakpoint_ops
);
6418 error (_("unsupported or unknown fork kind; cannot catch it"));
6424 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6427 char *cond_string
= NULL
;
6429 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6433 ep_skip_leading_whitespace (&arg
);
6435 /* The allowed syntax is:
6437 catch exec if <cond>
6439 First, check if there's an if clause. */
6440 cond_string
= ep_parse_optional_if_clause (&arg
);
6442 if ((*arg
!= '\0') && !isspace (*arg
))
6443 error (_("Junk at end of arguments."));
6445 /* If this target supports it, create an exec catchpoint
6446 and enable reporting of such events. */
6447 create_catchpoint (tempflag
, cond_string
, &catch_exec_breakpoint_ops
);
6450 static enum print_stop_action
6451 print_exception_catchpoint (struct breakpoint
*b
)
6453 int bp_temp
, bp_throw
;
6455 annotate_catchpoint (b
->number
);
6457 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6458 if (b
->loc
->address
!= b
->loc
->requested_address
)
6459 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6462 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6464 bp_temp
? "Temporary catchpoint "
6466 if (!ui_out_is_mi_like_p (uiout
))
6467 ui_out_field_int (uiout
, "bkptno", b
->number
);
6469 bp_throw
? " (exception thrown), "
6470 : " (exception caught), ");
6471 if (ui_out_is_mi_like_p (uiout
))
6473 ui_out_field_string (uiout
, "reason",
6474 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6475 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6476 ui_out_field_int (uiout
, "bkptno", b
->number
);
6478 return PRINT_SRC_AND_LOC
;
6482 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6484 struct value_print_options opts
;
6485 get_user_print_options (&opts
);
6486 if (opts
.addressprint
)
6489 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6490 ui_out_field_string (uiout
, "addr", "<PENDING>");
6492 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6496 *last_addr
= b
->loc
->address
;
6497 if (strstr (b
->addr_string
, "throw") != NULL
)
6498 ui_out_field_string (uiout
, "what", "exception throw");
6500 ui_out_field_string (uiout
, "what", "exception catch");
6504 print_mention_exception_catchpoint (struct breakpoint
*b
)
6509 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6510 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6511 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6512 : _("Catchpoint "));
6513 ui_out_field_int (uiout
, "bkptno", b
->number
);
6514 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6518 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6521 NULL
, /* breakpoint_hit */
6522 print_exception_catchpoint
,
6523 print_one_exception_catchpoint
,
6524 print_mention_exception_catchpoint
6528 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6529 enum exception_event_kind ex_event
, int from_tty
)
6531 char *trigger_func_name
;
6533 if (ex_event
== EX_EVENT_CATCH
)
6534 trigger_func_name
= "__cxa_begin_catch";
6536 trigger_func_name
= "__cxa_throw";
6538 break_command_really (trigger_func_name
, cond_string
, -1,
6539 0 /* condition and thread are valid. */,
6542 AUTO_BOOLEAN_TRUE
/* pending */,
6543 &gnu_v3_exception_catchpoint_ops
, from_tty
);
6548 /* Deal with "catch catch" and "catch throw" commands */
6551 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6552 int tempflag
, int from_tty
)
6554 char *cond_string
= NULL
;
6555 struct symtab_and_line
*sal
= NULL
;
6559 ep_skip_leading_whitespace (&arg
);
6561 cond_string
= ep_parse_optional_if_clause (&arg
);
6563 if ((*arg
!= '\0') && !isspace (*arg
))
6564 error (_("Junk at end of arguments."));
6566 if ((ex_event
!= EX_EVENT_THROW
) &&
6567 (ex_event
!= EX_EVENT_CATCH
))
6568 error (_("Unsupported or unknown exception event; cannot catch it"));
6570 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6573 warning (_("Unsupported with this platform/compiler combination."));
6576 /* Implementation of "catch catch" command. */
6579 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6581 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6582 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6585 /* Implementation of "catch throw" command. */
6588 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6590 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6591 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6594 /* Create a breakpoint struct for Ada exception catchpoints. */
6597 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6601 struct expression
*cond
,
6602 struct breakpoint_ops
*ops
,
6606 struct breakpoint
*b
;
6610 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6611 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6612 version for exception catchpoints, because two catchpoints
6613 used for different exception names will use the same address.
6614 In this case, a "breakpoint ... also set at..." warning is
6615 unproductive. Besides. the warning phrasing is also a bit
6616 inapropriate, we should use the word catchpoint, and tell
6617 the user what type of catchpoint it is. The above is good
6618 enough for now, though. */
6621 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6622 set_breakpoint_count (breakpoint_count
+ 1);
6624 b
->enable_state
= bp_enabled
;
6625 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6626 b
->number
= breakpoint_count
;
6627 b
->ignore_count
= 0;
6628 b
->loc
->cond
= cond
;
6629 b
->addr_string
= addr_string
;
6630 b
->language
= language_ada
;
6631 b
->cond_string
= cond_string
;
6632 b
->exp_string
= exp_string
;
6637 update_global_location_list (1);
6640 /* Implement the "catch exception" command. */
6643 catch_ada_exception_command (char *arg
, int from_tty
,
6644 struct cmd_list_element
*command
)
6647 struct symtab_and_line sal
;
6649 char *addr_string
= NULL
;
6650 char *exp_string
= NULL
;
6651 char *cond_string
= NULL
;
6652 struct expression
*cond
= NULL
;
6653 struct breakpoint_ops
*ops
= NULL
;
6655 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6659 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6660 &cond_string
, &cond
, &ops
);
6661 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6662 cond_string
, cond
, ops
, tempflag
,
6666 /* Implement the "catch assert" command. */
6669 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6672 struct symtab_and_line sal
;
6673 char *addr_string
= NULL
;
6674 struct breakpoint_ops
*ops
= NULL
;
6676 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6680 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6681 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6682 tempflag
, from_tty
);
6686 catch_command (char *arg
, int from_tty
)
6688 error (_("Catch requires an event name."));
6693 tcatch_command (char *arg
, int from_tty
)
6695 error (_("Catch requires an event name."));
6698 /* Delete breakpoints by address or line. */
6701 clear_command (char *arg
, int from_tty
)
6703 struct breakpoint
*b
;
6704 VEC(breakpoint_p
) *found
= 0;
6707 struct symtabs_and_lines sals
;
6708 struct symtab_and_line sal
;
6713 sals
= decode_line_spec (arg
, 1);
6718 sals
.sals
= (struct symtab_and_line
*)
6719 xmalloc (sizeof (struct symtab_and_line
));
6720 make_cleanup (xfree
, sals
.sals
);
6721 init_sal (&sal
); /* initialize to zeroes */
6722 sal
.line
= default_breakpoint_line
;
6723 sal
.symtab
= default_breakpoint_symtab
;
6724 sal
.pc
= default_breakpoint_address
;
6725 if (sal
.symtab
== 0)
6726 error (_("No source file specified."));
6734 /* We don't call resolve_sal_pc here. That's not
6735 as bad as it seems, because all existing breakpoints
6736 typically have both file/line and pc set. So, if
6737 clear is given file/line, we can match this to existing
6738 breakpoint without obtaining pc at all.
6740 We only support clearing given the address explicitly
6741 present in breakpoint table. Say, we've set breakpoint
6742 at file:line. There were several PC values for that file:line,
6743 due to optimization, all in one block.
6744 We've picked one PC value. If "clear" is issued with another
6745 PC corresponding to the same file:line, the breakpoint won't
6746 be cleared. We probably can still clear the breakpoint, but
6747 since the other PC value is never presented to user, user
6748 can only find it by guessing, and it does not seem important
6751 /* For each line spec given, delete bps which correspond
6752 to it. Do it in two passes, solely to preserve the current
6753 behavior that from_tty is forced true if we delete more than
6757 for (i
= 0; i
< sals
.nelts
; i
++)
6759 /* If exact pc given, clear bpts at that pc.
6760 If line given (pc == 0), clear all bpts on specified line.
6761 If defaulting, clear all bpts on default line
6764 defaulting sal.pc != 0 tests to do
6769 1 0 <can't happen> */
6773 /* Find all matching breakpoints and add them to
6778 /* Are we going to delete b? */
6779 if (b
->type
!= bp_none
6780 && b
->type
!= bp_watchpoint
6781 && b
->type
!= bp_hardware_watchpoint
6782 && b
->type
!= bp_read_watchpoint
6783 && b
->type
!= bp_access_watchpoint
)
6785 struct bp_location
*loc
= b
->loc
;
6786 for (; loc
; loc
= loc
->next
)
6788 int pc_match
= sal
.pc
6789 && (loc
->address
== sal
.pc
)
6790 && (!section_is_overlay (loc
->section
)
6791 || loc
->section
== sal
.section
);
6792 int line_match
= ((default_match
|| (0 == sal
.pc
))
6793 && b
->source_file
!= NULL
6794 && sal
.symtab
!= NULL
6795 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6796 && b
->line_number
== sal
.line
);
6797 if (pc_match
|| line_match
)
6806 VEC_safe_push(breakpoint_p
, found
, b
);
6809 /* Now go thru the 'found' chain and delete them. */
6810 if (VEC_empty(breakpoint_p
, found
))
6813 error (_("No breakpoint at %s."), arg
);
6815 error (_("No breakpoint at this line."));
6818 if (VEC_length(breakpoint_p
, found
) > 1)
6819 from_tty
= 1; /* Always report if deleted more than one */
6822 if (VEC_length(breakpoint_p
, found
) == 1)
6823 printf_unfiltered (_("Deleted breakpoint "));
6825 printf_unfiltered (_("Deleted breakpoints "));
6827 breakpoints_changed ();
6829 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6832 printf_unfiltered ("%d ", b
->number
);
6833 delete_breakpoint (b
);
6836 putchar_unfiltered ('\n');
6839 /* Delete breakpoint in BS if they are `delete' breakpoints and
6840 all breakpoints that are marked for deletion, whether hit or not.
6841 This is called after any breakpoint is hit, or after errors. */
6844 breakpoint_auto_delete (bpstat bs
)
6846 struct breakpoint
*b
, *temp
;
6848 for (; bs
; bs
= bs
->next
)
6849 if (bs
->breakpoint_at
6850 && bs
->breakpoint_at
->owner
6851 && bs
->breakpoint_at
->owner
->disposition
== disp_del
6853 delete_breakpoint (bs
->breakpoint_at
->owner
);
6855 ALL_BREAKPOINTS_SAFE (b
, temp
)
6857 if (b
->disposition
== disp_del_at_next_stop
)
6858 delete_breakpoint (b
);
6862 /* If SHOULD_INSERT is true, do not insert any breakpoint locations
6863 into the inferior, only remove already-inserted locations that no
6864 longer should be inserted. Functions that delete a breakpoint or
6865 breakpoints should pass false, so that deleting a breakpoint
6866 doesn't have the side effect of inserting the locations of other
6867 breakpoints that are marked not-inserted, but should_be_inserted
6868 returns true on them.
6870 This behaviour is useful is situations close to tear-down -- e.g.,
6871 after an exec, while the target still has execution, but breakpoint
6872 shadows of the previous executable image should *NOT* be restored
6873 to the new image; or before detaching, where the target still has
6874 execution and wants to delete breakpoints from GDB's lists, and all
6875 breakpoints had already been removed from the inferior. */
6878 update_global_location_list (int should_insert
)
6880 struct breakpoint
*b
;
6881 struct bp_location
**next
= &bp_location_chain
;
6882 struct bp_location
*loc
;
6883 struct bp_location
*loc2
;
6884 struct gdb_exception e
;
6885 VEC(bp_location_p
) *old_locations
= NULL
;
6889 /* Store old locations for future reference. */
6890 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
6891 VEC_safe_push (bp_location_p
, old_locations
, loc
);
6893 bp_location_chain
= NULL
;
6896 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6899 next
= &(loc
->global_next
);
6904 /* Identify bp_location instances that are no longer present in the new
6905 list, and therefore should be freed. Note that it's not necessary that
6906 those locations should be removed from inferior -- if there's another
6907 location at the same address (previously marked as duplicate),
6908 we don't need to remove/insert the location. */
6909 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
6911 /* Tells if 'loc' is found amoung the new locations. If not, we
6913 int found_object
= 0;
6914 /* Tells if the location should remain inserted in the target. */
6915 int keep_in_target
= 0;
6917 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
6924 /* If this location is no longer present, and inserted, look if there's
6925 maybe a new location at the same address. If so, mark that one
6926 inserted, and don't remove this one. This is needed so that we
6927 don't have a time window where a breakpoint at certain location is not
6932 /* If the location is inserted now, we might have to remove it. */
6934 if (found_object
&& should_be_inserted (loc
))
6936 /* The location is still present in the location list, and still
6937 should be inserted. Don't do anything. */
6942 /* The location is either no longer present, or got disabled.
6943 See if there's another location at the same address, in which
6944 case we don't need to remove this one from the target. */
6945 if (breakpoint_address_is_meaningful (loc
->owner
))
6946 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
6948 /* For the sake of should_insert_location. The
6949 call to check_duplicates will fix up this later. */
6950 loc2
->duplicate
= 0;
6951 if (should_be_inserted (loc2
)
6952 && loc2
!= loc
&& loc2
->address
== loc
->address
)
6955 loc2
->target_info
= loc
->target_info
;
6962 if (!keep_in_target
)
6964 if (remove_breakpoint (loc
, mark_uninserted
))
6966 /* This is just about all we can do. We could keep this
6967 location on the global list, and try to remove it next
6968 time, but there's no particular reason why we will
6971 Note that at this point, loc->owner is still valid,
6972 as delete_breakpoint frees the breakpoint only
6973 after calling us. */
6974 printf_filtered (_("warning: Error removing breakpoint %d\n"),
6975 loc
->owner
->number
);
6983 if (removed
&& non_stop
)
6985 /* This location was removed from the targets. In non-stop mode,
6986 a race condition is possible where we've removed a breakpoint,
6987 but stop events for that breakpoint are already queued and will
6988 arrive later. To suppress spurious SIGTRAPs reported to user,
6989 we keep this breakpoint location for a bit, and will retire it
6990 after we see 3 * thread_count events.
6991 The theory here is that reporting of events should,
6992 "on the average", be fair, so after that many event we'll see
6993 events from all threads that have anything of interest, and no
6994 longer need to keep this breakpoint. This is just a
6995 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
6996 which is usability issue, but not a correctness problem. */
6997 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7000 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
7003 free_bp_location (loc
);
7009 check_duplicates (b
);
7012 if (breakpoints_always_inserted_mode () && should_insert
7013 && (target_has_execution
7014 || (gdbarch_has_global_solist (target_gdbarch
)
7015 && target_supports_multi_process ())))
7016 insert_breakpoint_locations ();
7020 breakpoint_retire_moribund (void)
7022 struct bp_location
*loc
;
7025 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7026 if (--(loc
->events_till_retirement
) == 0)
7028 free_bp_location (loc
);
7029 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7035 update_global_location_list_nothrow (int inserting
)
7037 struct gdb_exception e
;
7038 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7039 update_global_location_list (inserting
);
7042 /* Clear BPT from a BPS. */
7044 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7047 for (bs
= bps
; bs
; bs
= bs
->next
)
7048 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7050 bs
->breakpoint_at
= NULL
;
7052 /* bs->commands will be freed later. */
7056 /* Callback for iterate_over_threads. */
7058 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7060 struct breakpoint
*bpt
= data
;
7061 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7065 /* Delete a breakpoint and clean up all traces of it in the data
7069 delete_breakpoint (struct breakpoint
*bpt
)
7071 struct breakpoint
*b
;
7072 struct bp_location
*loc
, *next
;
7074 gdb_assert (bpt
!= NULL
);
7076 /* Has this bp already been deleted? This can happen because multiple
7077 lists can hold pointers to bp's. bpstat lists are especial culprits.
7079 One example of this happening is a watchpoint's scope bp. When the
7080 scope bp triggers, we notice that the watchpoint is out of scope, and
7081 delete it. We also delete its scope bp. But the scope bp is marked
7082 "auto-deleting", and is already on a bpstat. That bpstat is then
7083 checked for auto-deleting bp's, which are deleted.
7085 A real solution to this problem might involve reference counts in bp's,
7086 and/or giving them pointers back to their referencing bpstat's, and
7087 teaching delete_breakpoint to only free a bp's storage when no more
7088 references were extent. A cheaper bandaid was chosen. */
7089 if (bpt
->type
== bp_none
)
7092 observer_notify_breakpoint_deleted (bpt
->number
);
7094 if (breakpoint_chain
== bpt
)
7095 breakpoint_chain
= bpt
->next
;
7100 b
->next
= bpt
->next
;
7104 free_command_lines (&bpt
->commands
);
7105 if (bpt
->cond_string
!= NULL
)
7106 xfree (bpt
->cond_string
);
7107 if (bpt
->addr_string
!= NULL
)
7108 xfree (bpt
->addr_string
);
7109 if (bpt
->exp
!= NULL
)
7111 if (bpt
->exp_string
!= NULL
)
7112 xfree (bpt
->exp_string
);
7113 if (bpt
->val
!= NULL
)
7114 value_free (bpt
->val
);
7115 if (bpt
->source_file
!= NULL
)
7116 xfree (bpt
->source_file
);
7117 if (bpt
->exec_pathname
!= NULL
)
7118 xfree (bpt
->exec_pathname
);
7120 /* Be sure no bpstat's are pointing at it after it's been freed. */
7121 /* FIXME, how can we find all bpstat's?
7122 We just check stop_bpstat for now. Note that we cannot just
7123 remove bpstats pointing at bpt from the stop_bpstat list
7124 entirely, as breakpoint commands are associated with the bpstat;
7125 if we remove it here, then the later call to
7126 bpstat_do_actions (&stop_bpstat);
7127 in event-top.c won't do anything, and temporary breakpoints
7128 with commands won't work. */
7130 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7132 /* Now that breakpoint is removed from breakpoint
7133 list, update the global location list. This
7134 will remove locations that used to belong to
7135 this breakpoint. Do this before freeing
7136 the breakpoint itself, since remove_breakpoint
7137 looks at location's owner. It might be better
7138 design to have location completely self-contained,
7139 but it's not the case now. */
7140 update_global_location_list (0);
7143 /* On the chance that someone will soon try again to delete this same
7144 bp, we mark it as deleted before freeing its storage. */
7145 bpt
->type
= bp_none
;
7151 do_delete_breakpoint_cleanup (void *b
)
7153 delete_breakpoint (b
);
7157 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7159 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7163 delete_command (char *arg
, int from_tty
)
7165 struct breakpoint
*b
, *temp
;
7171 int breaks_to_delete
= 0;
7173 /* Delete all breakpoints if no argument.
7174 Do not delete internal or call-dummy breakpoints, these
7175 have to be deleted with an explicit breakpoint number argument. */
7178 if (b
->type
!= bp_call_dummy
&&
7179 b
->type
!= bp_shlib_event
&&
7180 b
->type
!= bp_thread_event
&&
7181 b
->type
!= bp_overlay_event
&&
7184 breaks_to_delete
= 1;
7189 /* Ask user only if there are some breakpoints to delete. */
7191 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7193 ALL_BREAKPOINTS_SAFE (b
, temp
)
7195 if (b
->type
!= bp_call_dummy
&&
7196 b
->type
!= bp_shlib_event
&&
7197 b
->type
!= bp_thread_event
&&
7198 b
->type
!= bp_overlay_event
&&
7200 delete_breakpoint (b
);
7205 map_breakpoint_numbers (arg
, delete_breakpoint
);
7209 all_locations_are_pending (struct bp_location
*loc
)
7211 for (; loc
; loc
= loc
->next
)
7212 if (!loc
->shlib_disabled
)
7217 /* Subroutine of update_breakpoint_locations to simplify it.
7218 Return non-zero if multiple fns in list LOC have the same name.
7219 Null names are ignored. */
7222 ambiguous_names_p (struct bp_location
*loc
)
7224 struct bp_location
*l
;
7225 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7226 (int (*) (const void *, const void *)) streq
,
7227 NULL
, xcalloc
, xfree
);
7229 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7232 const char *name
= l
->function_name
;
7234 /* Allow for some names to be NULL, ignore them. */
7238 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7240 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7255 update_breakpoint_locations (struct breakpoint
*b
,
7256 struct symtabs_and_lines sals
)
7260 struct bp_location
*existing_locations
= b
->loc
;
7262 /* If there's no new locations, and all existing locations
7263 are pending, don't do anything. This optimizes
7264 the common case where all locations are in the same
7265 shared library, that was unloaded. We'd like to
7266 retain the location, so that when the library
7267 is loaded again, we don't loose the enabled/disabled
7268 status of the individual locations. */
7269 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7274 for (i
= 0; i
< sals
.nelts
; ++i
)
7276 struct bp_location
*new_loc
=
7277 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7279 /* Reparse conditions, they might contain references to the
7281 if (b
->cond_string
!= NULL
)
7283 struct gdb_exception e
;
7286 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7288 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7293 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7294 b
->number
, e
.message
);
7295 new_loc
->enabled
= 0;
7299 if (b
->source_file
!= NULL
)
7300 xfree (b
->source_file
);
7301 if (sals
.sals
[i
].symtab
== NULL
)
7302 b
->source_file
= NULL
;
7305 savestring (sals
.sals
[i
].symtab
->filename
,
7306 strlen (sals
.sals
[i
].symtab
->filename
));
7308 if (b
->line_number
== 0)
7309 b
->line_number
= sals
.sals
[i
].line
;
7312 /* Update locations of permanent breakpoints. */
7313 if (b
->enable_state
== bp_permanent
)
7314 make_breakpoint_permanent (b
);
7316 /* If possible, carry over 'disable' status from existing breakpoints. */
7318 struct bp_location
*e
= existing_locations
;
7319 /* If there are multiple breakpoints with the same function name,
7320 e.g. for inline functions, comparing function names won't work.
7321 Instead compare pc addresses; this is just a heuristic as things
7322 may have moved, but in practice it gives the correct answer
7323 often enough until a better solution is found. */
7324 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7326 for (; e
; e
= e
->next
)
7328 if (!e
->enabled
&& e
->function_name
)
7330 struct bp_location
*l
= b
->loc
;
7331 if (have_ambiguous_names
)
7333 for (; l
; l
= l
->next
)
7334 if (e
->address
== l
->address
)
7342 for (; l
; l
= l
->next
)
7343 if (l
->function_name
7344 && strcmp (e
->function_name
, l
->function_name
) == 0)
7354 update_global_location_list (1);
7358 /* Reset a breakpoint given it's struct breakpoint * BINT.
7359 The value we return ends up being the return value from catch_errors.
7360 Unused in this case. */
7363 breakpoint_re_set_one (void *bint
)
7365 /* get past catch_errs */
7366 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7370 int *not_found_ptr
= ¬_found
;
7371 struct symtabs_and_lines sals
= {};
7372 struct symtabs_and_lines expanded
;
7374 enum enable_state save_enable
;
7375 struct gdb_exception e
;
7381 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7385 case bp_hardware_breakpoint
:
7386 if (b
->addr_string
== NULL
)
7388 /* Anything without a string can't be re-set. */
7389 delete_breakpoint (b
);
7393 set_language (b
->language
);
7394 input_radix
= b
->input_radix
;
7396 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7398 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7403 int not_found_and_ok
= 0;
7404 /* For pending breakpoints, it's expected that parsing
7405 will fail until the right shared library is loaded.
7406 User has already told to create pending breakpoints and
7407 don't need extra messages. If breakpoint is in bp_shlib_disabled
7408 state, then user already saw the message about that breakpoint
7409 being disabled, and don't want to see more errors. */
7411 && (b
->condition_not_parsed
7412 || (b
->loc
&& b
->loc
->shlib_disabled
)
7413 || b
->enable_state
== bp_disabled
))
7414 not_found_and_ok
= 1;
7416 if (!not_found_and_ok
)
7418 /* We surely don't want to warn about the same breakpoint
7419 10 times. One solution, implemented here, is disable
7420 the breakpoint on error. Another solution would be to
7421 have separate 'warning emitted' flag. Since this
7422 happens only when a binary has changed, I don't know
7423 which approach is better. */
7424 b
->enable_state
= bp_disabled
;
7425 throw_exception (e
);
7432 gdb_assert (sals
.nelts
== 1);
7433 resolve_sal_pc (&sals
.sals
[0]);
7434 if (b
->condition_not_parsed
&& s
&& s
[0])
7436 char *cond_string
= 0;
7438 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7439 &cond_string
, &thread
);
7441 b
->cond_string
= cond_string
;
7443 b
->condition_not_parsed
= 0;
7445 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7446 update_breakpoint_locations (b
, expanded
);
7452 case bp_hardware_watchpoint
:
7453 case bp_read_watchpoint
:
7454 case bp_access_watchpoint
:
7455 /* Watchpoint can be either on expression using entirely global variables,
7456 or it can be on local variables.
7458 Watchpoints of the first kind are never auto-deleted, and even persist
7459 across program restarts. Since they can use variables from shared
7460 libraries, we need to reparse expression as libraries are loaded
7463 Watchpoints on local variables can also change meaning as result
7464 of solib event. For example, if a watchpoint uses both a local and
7465 a global variables in expression, it's a local watchpoint, but
7466 unloading of a shared library will make the expression invalid.
7467 This is not a very common use case, but we still re-evaluate
7468 expression, to avoid surprises to the user.
7470 Note that for local watchpoints, we re-evaluate it only if
7471 watchpoints frame id is still valid. If it's not, it means
7472 the watchpoint is out of scope and will be deleted soon. In fact,
7473 I'm not sure we'll ever be called in this case.
7475 If a local watchpoint's frame id is still valid, then
7476 b->exp_valid_block is likewise valid, and we can safely use it.
7478 Don't do anything about disabled watchpoints, since they will
7479 be reevaluated again when enabled. */
7480 update_watchpoint (b
, 1 /* reparse */);
7482 /* We needn't really do anything to reset these, since the mask
7483 that requests them is unaffected by e.g., new libraries being
7489 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7491 /* Delete overlay event breakpoints; they will be reset later by
7492 breakpoint_re_set. */
7493 case bp_overlay_event
:
7494 delete_breakpoint (b
);
7497 /* This breakpoint is special, it's set up when the inferior
7498 starts and we really don't want to touch it. */
7499 case bp_shlib_event
:
7501 /* Like bp_shlib_event, this breakpoint type is special.
7502 Once it is set up, we do not want to touch it. */
7503 case bp_thread_event
:
7505 /* Keep temporary breakpoints, which can be encountered when we step
7506 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7507 Otherwise these should have been blown away via the cleanup chain
7508 or by breakpoint_init_inferior when we rerun the executable. */
7511 case bp_watchpoint_scope
:
7513 case bp_step_resume
:
7515 case bp_longjmp_resume
:
7522 /* Re-set all breakpoints after symbols have been re-loaded. */
7524 breakpoint_re_set (void)
7526 struct breakpoint
*b
, *temp
;
7527 enum language save_language
;
7528 int save_input_radix
;
7530 save_language
= current_language
->la_language
;
7531 save_input_radix
= input_radix
;
7532 ALL_BREAKPOINTS_SAFE (b
, temp
)
7534 /* Format possible error msg */
7535 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7537 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7538 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7539 do_cleanups (cleanups
);
7541 set_language (save_language
);
7542 input_radix
= save_input_radix
;
7544 create_overlay_event_breakpoint ("_ovly_debug_event");
7547 /* Reset the thread number of this breakpoint:
7549 - If the breakpoint is for all threads, leave it as-is.
7550 - Else, reset it to the current thread for inferior_ptid. */
7552 breakpoint_re_set_thread (struct breakpoint
*b
)
7554 if (b
->thread
!= -1)
7556 if (in_thread_list (inferior_ptid
))
7557 b
->thread
= pid_to_thread_id (inferior_ptid
);
7561 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7562 If from_tty is nonzero, it prints a message to that effect,
7563 which ends with a period (no newline). */
7566 set_ignore_count (int bptnum
, int count
, int from_tty
)
7568 struct breakpoint
*b
;
7574 if (b
->number
== bptnum
)
7576 b
->ignore_count
= count
;
7580 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7582 else if (count
== 1)
7583 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7586 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7589 breakpoints_changed ();
7590 observer_notify_breakpoint_modified (b
->number
);
7594 error (_("No breakpoint number %d."), bptnum
);
7598 make_breakpoint_silent (struct breakpoint
*b
)
7600 /* Silence the breakpoint. */
7604 /* Command to set ignore-count of breakpoint N to COUNT. */
7607 ignore_command (char *args
, int from_tty
)
7613 error_no_arg (_("a breakpoint number"));
7615 num
= get_number (&p
);
7617 error (_("bad breakpoint number: '%s'"), args
);
7619 error (_("Second argument (specified ignore-count) is missing."));
7621 set_ignore_count (num
,
7622 longest_to_int (value_as_long (parse_and_eval (p
))),
7625 printf_filtered ("\n");
7628 /* Call FUNCTION on each of the breakpoints
7629 whose numbers are given in ARGS. */
7632 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7637 struct breakpoint
*b
, *tmp
;
7641 error_no_arg (_("one or more breakpoint numbers"));
7648 num
= get_number_or_range (&p1
);
7651 warning (_("bad breakpoint number at or near '%s'"), p
);
7655 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7656 if (b
->number
== num
)
7658 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7661 if (related_breakpoint
)
7662 function (related_breakpoint
);
7666 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7672 static struct bp_location
*
7673 find_location_by_number (char *number
)
7675 char *dot
= strchr (number
, '.');
7679 struct breakpoint
*b
;
7680 struct bp_location
*loc
;
7685 bp_num
= get_number_or_range (&p1
);
7687 error (_("Bad breakpoint number '%s'"), number
);
7690 if (b
->number
== bp_num
)
7695 if (!b
|| b
->number
!= bp_num
)
7696 error (_("Bad breakpoint number '%s'"), number
);
7699 loc_num
= get_number_or_range (&p1
);
7701 error (_("Bad breakpoint location number '%s'"), number
);
7705 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7708 error (_("Bad breakpoint location number '%s'"), dot
+1);
7714 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7715 If from_tty is nonzero, it prints a message to that effect,
7716 which ends with a period (no newline). */
7719 disable_breakpoint (struct breakpoint
*bpt
)
7721 /* Never disable a watchpoint scope breakpoint; we want to
7722 hit them when we leave scope so we can delete both the
7723 watchpoint and its scope breakpoint at that time. */
7724 if (bpt
->type
== bp_watchpoint_scope
)
7727 /* You can't disable permanent breakpoints. */
7728 if (bpt
->enable_state
== bp_permanent
)
7731 bpt
->enable_state
= bp_disabled
;
7733 update_global_location_list (0);
7735 observer_notify_breakpoint_modified (bpt
->number
);
7739 disable_command (char *args
, int from_tty
)
7741 struct breakpoint
*bpt
;
7743 ALL_BREAKPOINTS (bpt
)
7747 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7752 case bp_hardware_breakpoint
:
7754 case bp_hardware_watchpoint
:
7755 case bp_read_watchpoint
:
7756 case bp_access_watchpoint
:
7757 disable_breakpoint (bpt
);
7761 else if (strchr (args
, '.'))
7763 struct bp_location
*loc
= find_location_by_number (args
);
7766 update_global_location_list (0);
7769 map_breakpoint_numbers (args
, disable_breakpoint
);
7773 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7775 int target_resources_ok
, other_type_used
;
7778 if (bpt
->type
== bp_hardware_breakpoint
)
7781 i
= hw_breakpoint_used_count ();
7782 target_resources_ok
=
7783 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7785 if (target_resources_ok
== 0)
7786 error (_("No hardware breakpoint support in the target."));
7787 else if (target_resources_ok
< 0)
7788 error (_("Hardware breakpoints used exceeds limit."));
7791 if (bpt
->type
== bp_watchpoint
||
7792 bpt
->type
== bp_hardware_watchpoint
||
7793 bpt
->type
== bp_read_watchpoint
||
7794 bpt
->type
== bp_access_watchpoint
)
7796 struct frame_id saved_frame_id
;
7798 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7799 if (bpt
->exp_valid_block
!= NULL
)
7801 struct frame_info
*fr
=
7802 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7805 printf_filtered (_("\
7806 Cannot enable watchpoint %d because the block in which its expression\n\
7807 is valid is not currently in scope.\n"), bpt
->number
);
7814 value_free (bpt
->val
);
7815 mark
= value_mark ();
7816 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7818 release_value (bpt
->val
);
7821 if (bpt
->type
== bp_hardware_watchpoint
||
7822 bpt
->type
== bp_read_watchpoint
||
7823 bpt
->type
== bp_access_watchpoint
)
7825 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7826 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7828 /* Hack around 'unused var' error for some targets here */
7829 (void) mem_cnt
, (void) i
;
7830 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7831 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7832 /* we can consider of type is bp_hardware_watchpoint, convert to
7833 bp_watchpoint in the following condition */
7834 if (target_resources_ok
< 0)
7836 printf_filtered (_("\
7837 Cannot enable watchpoint %d because target watch resources\n\
7838 have been allocated for other watchpoints.\n"), bpt
->number
);
7839 value_free_to_mark (mark
);
7844 select_frame (frame_find_by_id (saved_frame_id
));
7845 value_free_to_mark (mark
);
7848 if (bpt
->enable_state
!= bp_permanent
)
7849 bpt
->enable_state
= bp_enabled
;
7850 bpt
->disposition
= disposition
;
7851 update_global_location_list (1);
7852 breakpoints_changed ();
7854 observer_notify_breakpoint_modified (bpt
->number
);
7859 enable_breakpoint (struct breakpoint
*bpt
)
7861 do_enable_breakpoint (bpt
, bpt
->disposition
);
7864 /* The enable command enables the specified breakpoints (or all defined
7865 breakpoints) so they once again become (or continue to be) effective
7866 in stopping the inferior. */
7869 enable_command (char *args
, int from_tty
)
7871 struct breakpoint
*bpt
;
7873 ALL_BREAKPOINTS (bpt
)
7877 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7882 case bp_hardware_breakpoint
:
7884 case bp_hardware_watchpoint
:
7885 case bp_read_watchpoint
:
7886 case bp_access_watchpoint
:
7887 enable_breakpoint (bpt
);
7891 else if (strchr (args
, '.'))
7893 struct bp_location
*loc
= find_location_by_number (args
);
7896 update_global_location_list (1);
7899 map_breakpoint_numbers (args
, enable_breakpoint
);
7903 enable_once_breakpoint (struct breakpoint
*bpt
)
7905 do_enable_breakpoint (bpt
, disp_disable
);
7909 enable_once_command (char *args
, int from_tty
)
7911 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7915 enable_delete_breakpoint (struct breakpoint
*bpt
)
7917 do_enable_breakpoint (bpt
, disp_del
);
7921 enable_delete_command (char *args
, int from_tty
)
7923 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7927 set_breakpoint_cmd (char *args
, int from_tty
)
7932 show_breakpoint_cmd (char *args
, int from_tty
)
7936 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7938 struct symtabs_and_lines
7939 decode_line_spec_1 (char *string
, int funfirstline
)
7941 struct symtabs_and_lines sals
;
7943 error (_("Empty line specification."));
7944 if (default_breakpoint_valid
)
7945 sals
= decode_line_1 (&string
, funfirstline
,
7946 default_breakpoint_symtab
,
7947 default_breakpoint_line
,
7948 (char ***) NULL
, NULL
);
7950 sals
= decode_line_1 (&string
, funfirstline
,
7951 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7953 error (_("Junk at end of line specification: %s"), string
);
7957 /* Create and insert a raw software breakpoint at PC. Return an
7958 identifier, which should be used to remove the breakpoint later.
7959 In general, places which call this should be using something on the
7960 breakpoint chain instead; this function should be eliminated
7964 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7966 struct bp_target_info
*bp_tgt
;
7968 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7969 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7971 bp_tgt
->placed_address
= pc
;
7972 if (target_insert_breakpoint (bp_tgt
) != 0)
7974 /* Could not insert the breakpoint. */
7982 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7985 deprecated_remove_raw_breakpoint (void *bp
)
7987 struct bp_target_info
*bp_tgt
= bp
;
7990 ret
= target_remove_breakpoint (bp_tgt
);
7996 /* One (or perhaps two) breakpoints used for software single stepping. */
7998 static void *single_step_breakpoints
[2];
8000 /* Create and insert a breakpoint for software single step. */
8003 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8007 if (single_step_breakpoints
[0] == NULL
)
8008 bpt_p
= &single_step_breakpoints
[0];
8011 gdb_assert (single_step_breakpoints
[1] == NULL
);
8012 bpt_p
= &single_step_breakpoints
[1];
8015 /* NOTE drow/2006-04-11: A future improvement to this function would be
8016 to only create the breakpoints once, and actually put them on the
8017 breakpoint chain. That would let us use set_raw_breakpoint. We could
8018 adjust the addresses each time they were needed. Doing this requires
8019 corresponding changes elsewhere where single step breakpoints are
8020 handled, however. So, for now, we use this. */
8022 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8024 error (_("Could not insert single-step breakpoint at 0x%s"),
8025 paddr_nz (next_pc
));
8028 /* Remove and delete any breakpoints used for software single step. */
8031 remove_single_step_breakpoints (void)
8033 gdb_assert (single_step_breakpoints
[0] != NULL
);
8035 /* See insert_single_step_breakpoint for more about this deprecated
8037 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8038 single_step_breakpoints
[0] = NULL
;
8040 if (single_step_breakpoints
[1] != NULL
)
8042 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8043 single_step_breakpoints
[1] = NULL
;
8047 /* Check whether a software single-step breakpoint is inserted at PC. */
8050 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8054 for (i
= 0; i
< 2; i
++)
8056 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8057 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8065 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8066 It is defined as a macro to prevent duplication.
8067 COMMAND should be a string constant containing the name of the command. */
8068 #define BREAK_ARGS_HELP(command) \
8069 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8070 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8071 If a line number is specified, break at start of code for that line.\n\
8072 If a function is specified, break at start of code for that function.\n\
8073 If an address is specified, break at that exact address.\n\
8074 With no LOCATION, uses current execution address of selected stack frame.\n\
8075 This is useful for breaking on return to a stack frame.\n\
8077 THREADNUM is the number from \"info threads\".\n\
8078 CONDITION is a boolean expression.\n\
8080 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8082 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8084 /* List of subcommands for "catch". */
8085 static struct cmd_list_element
*catch_cmdlist
;
8087 /* List of subcommands for "tcatch". */
8088 static struct cmd_list_element
*tcatch_cmdlist
;
8090 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8091 lists, and pass some additional user data to the command function. */
8093 add_catch_command (char *name
, char *docstring
,
8094 void (*sfunc
) (char *args
, int from_tty
,
8095 struct cmd_list_element
*command
),
8096 void *user_data_catch
,
8097 void *user_data_tcatch
)
8099 struct cmd_list_element
*command
;
8101 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8103 set_cmd_sfunc (command
, sfunc
);
8104 set_cmd_context (command
, user_data_catch
);
8106 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8108 set_cmd_sfunc (command
, sfunc
);
8109 set_cmd_context (command
, user_data_tcatch
);
8113 _initialize_breakpoint (void)
8115 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8116 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8117 struct cmd_list_element
*c
;
8119 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8121 breakpoint_chain
= 0;
8122 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8123 before a breakpoint is set. */
8124 breakpoint_count
= 0;
8126 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8127 Set ignore-count of breakpoint number N to COUNT.\n\
8128 Usage is `ignore N COUNT'."));
8130 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8132 add_com ("commands", class_breakpoint
, commands_command
, _("\
8133 Set commands to be executed when a breakpoint is hit.\n\
8134 Give breakpoint number as argument after \"commands\".\n\
8135 With no argument, the targeted breakpoint is the last one set.\n\
8136 The commands themselves follow starting on the next line.\n\
8137 Type a line containing \"end\" to indicate the end of them.\n\
8138 Give \"silent\" as the first line to make the breakpoint silent;\n\
8139 then no output is printed when it is hit, except what the commands print."));
8141 add_com ("condition", class_breakpoint
, condition_command
, _("\
8142 Specify breakpoint number N to break only if COND is true.\n\
8143 Usage is `condition N COND', where N is an integer and COND is an\n\
8144 expression to be evaluated whenever breakpoint N is reached."));
8146 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8147 Set a temporary breakpoint.\n\
8148 Like \"break\" except the breakpoint is only temporary,\n\
8149 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8150 by using \"enable delete\" on the breakpoint number.\n\
8152 BREAK_ARGS_HELP ("tbreak")));
8153 set_cmd_completer (c
, location_completer
);
8155 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8156 Set a hardware assisted breakpoint.\n\
8157 Like \"break\" except the breakpoint requires hardware support,\n\
8158 some target hardware may not have this support.\n\
8160 BREAK_ARGS_HELP ("hbreak")));
8161 set_cmd_completer (c
, location_completer
);
8163 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8164 Set a temporary hardware assisted breakpoint.\n\
8165 Like \"hbreak\" except the breakpoint is only temporary,\n\
8166 so it will be deleted when hit.\n\
8168 BREAK_ARGS_HELP ("thbreak")));
8169 set_cmd_completer (c
, location_completer
);
8171 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8172 Enable some breakpoints.\n\
8173 Give breakpoint numbers (separated by spaces) as arguments.\n\
8174 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8175 This is used to cancel the effect of the \"disable\" command.\n\
8176 With a subcommand you can enable temporarily."),
8177 &enablelist
, "enable ", 1, &cmdlist
);
8179 add_com ("ab", class_breakpoint
, enable_command
, _("\
8180 Enable some breakpoints.\n\
8181 Give breakpoint numbers (separated by spaces) as arguments.\n\
8182 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8183 This is used to cancel the effect of the \"disable\" command.\n\
8184 With a subcommand you can enable temporarily."));
8186 add_com_alias ("en", "enable", class_breakpoint
, 1);
8188 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8189 Enable some breakpoints.\n\
8190 Give breakpoint numbers (separated by spaces) as arguments.\n\
8191 This is used to cancel the effect of the \"disable\" command.\n\
8192 May be abbreviated to simply \"enable\".\n"),
8193 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8195 add_cmd ("once", no_class
, enable_once_command
, _("\
8196 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8197 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8200 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8201 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8202 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8205 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8206 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8207 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8210 add_cmd ("once", no_class
, enable_once_command
, _("\
8211 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8212 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8215 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8216 Disable some breakpoints.\n\
8217 Arguments are breakpoint numbers with spaces in between.\n\
8218 To disable all breakpoints, give no argument.\n\
8219 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8220 &disablelist
, "disable ", 1, &cmdlist
);
8221 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8222 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8224 add_com ("sb", class_breakpoint
, disable_command
, _("\
8225 Disable some breakpoints.\n\
8226 Arguments are breakpoint numbers with spaces in between.\n\
8227 To disable all breakpoints, give no argument.\n\
8228 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8230 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8231 Disable some breakpoints.\n\
8232 Arguments are breakpoint numbers with spaces in between.\n\
8233 To disable all breakpoints, give no argument.\n\
8234 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8235 This command may be abbreviated \"disable\"."),
8238 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8239 Delete some breakpoints or auto-display expressions.\n\
8240 Arguments are breakpoint numbers with spaces in between.\n\
8241 To delete all breakpoints, give no argument.\n\
8243 Also a prefix command for deletion of other GDB objects.\n\
8244 The \"unset\" command is also an alias for \"delete\"."),
8245 &deletelist
, "delete ", 1, &cmdlist
);
8246 add_com_alias ("d", "delete", class_breakpoint
, 1);
8247 add_com_alias ("del", "delete", class_breakpoint
, 1);
8249 add_com ("db", class_breakpoint
, delete_command
, _("\
8250 Delete some breakpoints.\n\
8251 Arguments are breakpoint numbers with spaces in between.\n\
8252 To delete all breakpoints, give no argument.\n"));
8254 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8255 Delete some breakpoints or auto-display expressions.\n\
8256 Arguments are breakpoint numbers with spaces in between.\n\
8257 To delete all breakpoints, give no argument.\n\
8258 This command may be abbreviated \"delete\"."),
8261 add_com ("clear", class_breakpoint
, clear_command
, _("\
8262 Clear breakpoint at specified line or function.\n\
8263 Argument may be line number, function name, or \"*\" and an address.\n\
8264 If line number is specified, all breakpoints in that line are cleared.\n\
8265 If function is specified, breakpoints at beginning of function are cleared.\n\
8266 If an address is specified, breakpoints at that address are cleared.\n\
8268 With no argument, clears all breakpoints in the line that the selected frame\n\
8271 See also the \"delete\" command which clears breakpoints by number."));
8273 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8274 Set breakpoint at specified line or function.\n"
8275 BREAK_ARGS_HELP ("break")));
8276 set_cmd_completer (c
, location_completer
);
8278 add_com_alias ("b", "break", class_run
, 1);
8279 add_com_alias ("br", "break", class_run
, 1);
8280 add_com_alias ("bre", "break", class_run
, 1);
8281 add_com_alias ("brea", "break", class_run
, 1);
8285 add_com_alias ("ba", "break", class_breakpoint
, 1);
8286 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8291 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8292 Break in function/address or break at a line in the current file."),
8293 &stoplist
, "stop ", 1, &cmdlist
);
8294 add_cmd ("in", class_breakpoint
, stopin_command
,
8295 _("Break in function or address."), &stoplist
);
8296 add_cmd ("at", class_breakpoint
, stopat_command
,
8297 _("Break at a line in the current file."), &stoplist
);
8298 add_com ("status", class_info
, breakpoints_info
, _("\
8299 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8300 The \"Type\" column indicates one of:\n\
8301 \tbreakpoint - normal breakpoint\n\
8302 \twatchpoint - watchpoint\n\
8303 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8304 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8305 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8306 address and file/line number respectively.\n\
8308 Convenience variable \"$_\" and default examine address for \"x\"\n\
8309 are set to the address of the last breakpoint listed unless the command\n\
8310 is prefixed with \"server \".\n\n\
8311 Convenience variable \"$bpnum\" contains the number of the last\n\
8315 add_info ("breakpoints", breakpoints_info
, _("\
8316 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8317 The \"Type\" column indicates one of:\n\
8318 \tbreakpoint - normal breakpoint\n\
8319 \twatchpoint - watchpoint\n\
8320 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8321 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8322 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8323 address and file/line number respectively.\n\
8325 Convenience variable \"$_\" and default examine address for \"x\"\n\
8326 are set to the address of the last breakpoint listed unless the command\n\
8327 is prefixed with \"server \".\n\n\
8328 Convenience variable \"$bpnum\" contains the number of the last\n\
8332 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8333 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8334 The \"Type\" column indicates one of:\n\
8335 \tbreakpoint - normal breakpoint\n\
8336 \twatchpoint - watchpoint\n\
8337 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8338 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8339 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8340 address and file/line number respectively.\n\
8342 Convenience variable \"$_\" and default examine address for \"x\"\n\
8343 are set to the address of the last breakpoint listed unless the command\n\
8344 is prefixed with \"server \".\n\n\
8345 Convenience variable \"$bpnum\" contains the number of the last\n\
8348 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8349 Status of all breakpoints, or breakpoint number NUMBER.\n\
8350 The \"Type\" column indicates one of:\n\
8351 \tbreakpoint - normal breakpoint\n\
8352 \twatchpoint - watchpoint\n\
8353 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8354 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8355 \tuntil - internal breakpoint used by the \"until\" command\n\
8356 \tfinish - internal breakpoint used by the \"finish\" command\n\
8357 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8358 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8359 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8360 address and file/line number respectively.\n\
8362 Convenience variable \"$_\" and default examine address for \"x\"\n\
8363 are set to the address of the last breakpoint listed unless the command\n\
8364 is prefixed with \"server \".\n\n\
8365 Convenience variable \"$bpnum\" contains the number of the last\n\
8367 &maintenanceinfolist
);
8369 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
8370 Set catchpoints to catch events."),
8371 &catch_cmdlist
, "catch ",
8372 0/*allow-unknown*/, &cmdlist
);
8374 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
8375 Set temporary catchpoints to catch events."),
8376 &tcatch_cmdlist
, "tcatch ",
8377 0/*allow-unknown*/, &cmdlist
);
8379 /* Add catch and tcatch sub-commands. */
8380 add_catch_command ("catch", _("\
8381 Catch an exception, when caught.\n\
8382 With an argument, catch only exceptions with the given name."),
8383 catch_catch_command
,
8386 add_catch_command ("throw", _("\
8387 Catch an exception, when thrown.\n\
8388 With an argument, catch only exceptions with the given name."),
8389 catch_throw_command
,
8392 add_catch_command ("fork", _("Catch calls to fork."),
8393 catch_fork_command_1
,
8394 (void *) (uintptr_t) catch_fork_permanent
,
8395 (void *) (uintptr_t) catch_fork_temporary
);
8396 add_catch_command ("vfork", _("Catch calls to vfork."),
8397 catch_fork_command_1
,
8398 (void *) (uintptr_t) catch_vfork_permanent
,
8399 (void *) (uintptr_t) catch_vfork_temporary
);
8400 add_catch_command ("exec", _("Catch calls to exec."),
8401 catch_exec_command_1
,
8404 add_catch_command ("exception", _("\
8405 Catch Ada exceptions, when raised.\n\
8406 With an argument, catch only exceptions with the given name."),
8407 catch_ada_exception_command
,
8410 add_catch_command ("assert", _("\
8411 Catch failed Ada assertions, when raised.\n\
8412 With an argument, catch only exceptions with the given name."),
8413 catch_assert_command
,
8417 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8418 Set a watchpoint for an expression.\n\
8419 A watchpoint stops execution of your program whenever the value of\n\
8420 an expression changes."));
8421 set_cmd_completer (c
, expression_completer
);
8423 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8424 Set a read watchpoint for an expression.\n\
8425 A watchpoint stops execution of your program whenever the value of\n\
8426 an expression is read."));
8427 set_cmd_completer (c
, expression_completer
);
8429 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8430 Set a watchpoint for an expression.\n\
8431 A watchpoint stops execution of your program whenever the value of\n\
8432 an expression is either read or written."));
8433 set_cmd_completer (c
, expression_completer
);
8435 add_info ("watchpoints", breakpoints_info
,
8436 _("Synonym for ``info breakpoints''."));
8439 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8440 respond to changes - contrary to the description. */
8441 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8442 &can_use_hw_watchpoints
, _("\
8443 Set debugger's willingness to use watchpoint hardware."), _("\
8444 Show debugger's willingness to use watchpoint hardware."), _("\
8445 If zero, gdb will not use hardware for new watchpoints, even if\n\
8446 such is available. (However, any hardware watchpoints that were\n\
8447 created before setting this to nonzero, will continue to use watchpoint\n\
8450 show_can_use_hw_watchpoints
,
8451 &setlist
, &showlist
);
8453 can_use_hw_watchpoints
= 1;
8455 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8456 Breakpoint specific settings\n\
8457 Configure various breakpoint-specific variables such as\n\
8458 pending breakpoint behavior"),
8459 &breakpoint_set_cmdlist
, "set breakpoint ",
8460 0/*allow-unknown*/, &setlist
);
8461 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8462 Breakpoint specific settings\n\
8463 Configure various breakpoint-specific variables such as\n\
8464 pending breakpoint behavior"),
8465 &breakpoint_show_cmdlist
, "show breakpoint ",
8466 0/*allow-unknown*/, &showlist
);
8468 add_setshow_auto_boolean_cmd ("pending", no_class
,
8469 &pending_break_support
, _("\
8470 Set debugger's behavior regarding pending breakpoints."), _("\
8471 Show debugger's behavior regarding pending breakpoints."), _("\
8472 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8473 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8474 an error. If auto, an unrecognized breakpoint location results in a\n\
8475 user-query to see if a pending breakpoint should be created."),
8477 show_pending_break_support
,
8478 &breakpoint_set_cmdlist
,
8479 &breakpoint_show_cmdlist
);
8481 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8483 add_setshow_boolean_cmd ("auto-hw", no_class
,
8484 &automatic_hardware_breakpoints
, _("\
8485 Set automatic usage of hardware breakpoints."), _("\
8486 Show automatic usage of hardware breakpoints."), _("\
8487 If set, the debugger will automatically use hardware breakpoints for\n\
8488 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8489 a warning will be emitted for such breakpoints."),
8491 show_automatic_hardware_breakpoints
,
8492 &breakpoint_set_cmdlist
,
8493 &breakpoint_show_cmdlist
);
8495 add_setshow_enum_cmd ("always-inserted", class_support
,
8496 always_inserted_enums
, &always_inserted_mode
, _("\
8497 Set mode for inserting breakpoints."), _("\
8498 Show mode for inserting breakpoints."), _("\
8499 When this mode is off, breakpoints are inserted in inferior when it is\n\
8500 resumed, and removed when execution stops. When this mode is on,\n\
8501 breakpoints are inserted immediately and removed only when the user\n\
8502 deletes the breakpoint. When this mode is auto (which is the default),\n\
8503 the behaviour depends on the non-stop setting (see help set non-stop).\n\
8504 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
8505 behaves as if always-inserted mode is on; if gdb is controlling the\n\
8506 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
8508 &show_always_inserted_mode
,
8509 &breakpoint_set_cmdlist
,
8510 &breakpoint_show_cmdlist
);
8512 automatic_hardware_breakpoints
= 1;