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
)
1941 || (ep
->type
== bp_catch_load
)
1942 || (ep
->type
== bp_catch_unload
);
1944 /* ??rehrauer: Add more kinds here, as are implemented... */
1948 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1951 (ep
->type
== bp_catch_load
)
1952 || (ep
->type
== bp_catch_unload
);
1956 bpstat_free (bpstat bs
)
1958 if (bs
->old_val
!= NULL
)
1959 value_free (bs
->old_val
);
1960 free_command_lines (&bs
->commands
);
1964 /* Clear a bpstat so that it says we are not at any breakpoint.
1965 Also free any storage that is part of a bpstat. */
1968 bpstat_clear (bpstat
*bsp
)
1985 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1986 is part of the bpstat is copied as well. */
1989 bpstat_copy (bpstat bs
)
1993 bpstat retval
= NULL
;
1998 for (; bs
!= NULL
; bs
= bs
->next
)
2000 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2001 memcpy (tmp
, bs
, sizeof (*tmp
));
2002 if (bs
->commands
!= NULL
)
2003 tmp
->commands
= copy_command_lines (bs
->commands
);
2004 if (bs
->old_val
!= NULL
)
2006 tmp
->old_val
= value_copy (bs
->old_val
);
2007 release_value (tmp
->old_val
);
2011 /* This is the first thing in the chain. */
2021 /* Find the bpstat associated with this breakpoint */
2024 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2029 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2031 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2037 /* Find a step_resume breakpoint associated with this bpstat.
2038 (If there are multiple step_resume bp's on the list, this function
2039 will arbitrarily pick one.)
2041 It is an error to use this function if BPSTAT doesn't contain a
2042 step_resume breakpoint.
2044 See wait_for_inferior's use of this function. */
2046 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2050 gdb_assert (bsp
!= NULL
);
2052 current_thread
= pid_to_thread_id (inferior_ptid
);
2054 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2056 if ((bsp
->breakpoint_at
!= NULL
) &&
2057 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2058 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2059 bsp
->breakpoint_at
->owner
->thread
== -1))
2060 return bsp
->breakpoint_at
->owner
;
2063 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2067 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2068 at. *BSP upon return is a bpstat which points to the remaining
2069 breakpoints stopped at (but which is not guaranteed to be good for
2070 anything but further calls to bpstat_num).
2071 Return 0 if passed a bpstat which does not indicate any breakpoints.
2072 Return -1 if stopped at a breakpoint that has been deleted since
2074 Return 1 otherwise. */
2077 bpstat_num (bpstat
*bsp
, int *num
)
2079 struct breakpoint
*b
;
2082 return 0; /* No more breakpoint values */
2084 /* We assume we'll never have several bpstats that
2085 correspond to a single breakpoint -- otherwise,
2086 this function might return the same number more
2087 than once and this will look ugly. */
2088 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2089 *bsp
= (*bsp
)->next
;
2091 return -1; /* breakpoint that's been deleted since */
2093 *num
= b
->number
; /* We have its number */
2097 /* Modify BS so that the actions will not be performed. */
2100 bpstat_clear_actions (bpstat bs
)
2102 for (; bs
!= NULL
; bs
= bs
->next
)
2104 free_command_lines (&bs
->commands
);
2105 if (bs
->old_val
!= NULL
)
2107 value_free (bs
->old_val
);
2113 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2115 cleanup_executing_breakpoints (void *ignore
)
2117 executing_breakpoint_commands
= 0;
2120 /* Execute all the commands associated with all the breakpoints at this
2121 location. Any of these commands could cause the process to proceed
2122 beyond this point, etc. We look out for such changes by checking
2123 the global "breakpoint_proceeded" after each command.
2125 Returns true if a breakpoint command resumed the inferior. In that
2126 case, it is the caller's responsibility to recall it again with the
2127 bpstat of the current thread. */
2130 bpstat_do_actions_1 (bpstat
*bsp
)
2133 struct cleanup
*old_chain
;
2136 /* Avoid endless recursion if a `source' command is contained
2138 if (executing_breakpoint_commands
)
2141 executing_breakpoint_commands
= 1;
2142 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2144 /* This pointer will iterate over the list of bpstat's. */
2147 breakpoint_proceeded
= 0;
2148 for (; bs
!= NULL
; bs
= bs
->next
)
2150 struct command_line
*cmd
;
2151 struct cleanup
*this_cmd_tree_chain
;
2153 /* Take ownership of the BSP's command tree, if it has one.
2155 The command tree could legitimately contain commands like
2156 'step' and 'next', which call clear_proceed_status, which
2157 frees stop_bpstat's command tree. To make sure this doesn't
2158 free the tree we're executing out from under us, we need to
2159 take ownership of the tree ourselves. Since a given bpstat's
2160 commands are only executed once, we don't need to copy it; we
2161 can clear the pointer in the bpstat, and make sure we free
2162 the tree when we're done. */
2165 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2169 execute_control_command (cmd
);
2171 if (breakpoint_proceeded
)
2177 /* We can free this command tree now. */
2178 do_cleanups (this_cmd_tree_chain
);
2180 if (breakpoint_proceeded
)
2182 if (target_can_async_p ())
2183 /* If we are in async mode, then the target might be still
2184 running, not stopped at any breakpoint, so nothing for
2185 us to do here -- just return to the event loop. */
2188 /* In sync mode, when execute_control_command returns
2189 we're already standing on the next breakpoint.
2190 Breakpoint commands for that stop were not run, since
2191 execute_command does not run breakpoint commands --
2192 only command_line_handler does, but that one is not
2193 involved in execution of breakpoint commands. So, we
2194 can now execute breakpoint commands. It should be
2195 noted that making execute_command do bpstat actions is
2196 not an option -- in this case we'll have recursive
2197 invocation of bpstat for each breakpoint with a
2198 command, and can easily blow up GDB stack. Instead, we
2199 return true, which will trigger the caller to recall us
2200 with the new stop_bpstat. */
2205 do_cleanups (old_chain
);
2210 bpstat_do_actions (void)
2212 /* Do any commands attached to breakpoint we are stopped at. */
2213 while (!ptid_equal (inferior_ptid
, null_ptid
)
2214 && target_has_execution
2215 && !is_exited (inferior_ptid
)
2216 && !is_executing (inferior_ptid
))
2217 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2218 and only return when it is stopped at the next breakpoint, we
2219 keep doing breakpoint actions until it returns false to
2220 indicate the inferior was not resumed. */
2221 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2225 /* Print out the (old or new) value associated with a watchpoint. */
2228 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2231 fprintf_unfiltered (stream
, _("<unreadable>"));
2234 struct value_print_options opts
;
2235 get_user_print_options (&opts
);
2236 value_print (val
, stream
, &opts
);
2240 /* This is the normal print function for a bpstat. In the future,
2241 much of this logic could (should?) be moved to bpstat_stop_status,
2242 by having it set different print_it values.
2244 Current scheme: When we stop, bpstat_print() is called. It loops
2245 through the bpstat list of things causing this stop, calling the
2246 print_bp_stop_message function on each one. The behavior of the
2247 print_bp_stop_message function depends on the print_it field of
2248 bpstat. If such field so indicates, call this function here.
2250 Return values from this routine (ultimately used by bpstat_print()
2251 and normal_stop() to decide what to do):
2252 PRINT_NOTHING: Means we already printed all we needed to print,
2253 don't print anything else.
2254 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2255 that something to be followed by a location.
2256 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2257 that something to be followed by a location.
2258 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2261 static enum print_stop_action
2262 print_it_typical (bpstat bs
)
2264 struct cleanup
*old_chain
, *ui_out_chain
;
2265 struct breakpoint
*b
;
2266 const struct bp_location
*bl
;
2267 struct ui_stream
*stb
;
2269 stb
= ui_out_stream_new (uiout
);
2270 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2271 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2272 which has since been deleted. */
2273 if (bs
->breakpoint_at
== NULL
)
2274 return PRINT_UNKNOWN
;
2275 bl
= bs
->breakpoint_at
;
2281 case bp_hardware_breakpoint
:
2282 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2283 if (bl
->address
!= bl
->requested_address
)
2284 breakpoint_adjustment_warning (bl
->requested_address
,
2287 annotate_breakpoint (b
->number
);
2289 ui_out_text (uiout
, "\nTemporary breakpoint ");
2291 ui_out_text (uiout
, "\nBreakpoint ");
2292 if (ui_out_is_mi_like_p (uiout
))
2294 ui_out_field_string (uiout
, "reason",
2295 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2296 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2298 ui_out_field_int (uiout
, "bkptno", b
->number
);
2299 ui_out_text (uiout
, ", ");
2300 return PRINT_SRC_AND_LOC
;
2303 case bp_shlib_event
:
2304 /* Did we stop because the user set the stop_on_solib_events
2305 variable? (If so, we report this as a generic, "Stopped due
2306 to shlib event" message.) */
2307 printf_filtered (_("Stopped due to shared library event\n"));
2308 return PRINT_NOTHING
;
2311 case bp_thread_event
:
2312 /* Not sure how we will get here.
2313 GDB should not stop for these breakpoints. */
2314 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2315 return PRINT_NOTHING
;
2318 case bp_overlay_event
:
2319 /* By analogy with the thread event, GDB should not stop for these. */
2320 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2321 return PRINT_NOTHING
;
2325 annotate_catchpoint (b
->number
);
2326 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2328 b
->triggered_dll_pathname
);
2329 return PRINT_SRC_AND_LOC
;
2332 case bp_catch_unload
:
2333 annotate_catchpoint (b
->number
);
2334 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2336 b
->triggered_dll_pathname
);
2337 return PRINT_SRC_AND_LOC
;
2341 case bp_hardware_watchpoint
:
2342 annotate_watchpoint (b
->number
);
2343 if (ui_out_is_mi_like_p (uiout
))
2346 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2348 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2349 ui_out_text (uiout
, "\nOld value = ");
2350 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2351 ui_out_field_stream (uiout
, "old", stb
);
2352 ui_out_text (uiout
, "\nNew value = ");
2353 watchpoint_value_print (b
->val
, stb
->stream
);
2354 ui_out_field_stream (uiout
, "new", stb
);
2355 do_cleanups (ui_out_chain
);
2356 ui_out_text (uiout
, "\n");
2357 /* More than one watchpoint may have been triggered. */
2358 return PRINT_UNKNOWN
;
2361 case bp_read_watchpoint
:
2362 if (ui_out_is_mi_like_p (uiout
))
2365 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2367 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2368 ui_out_text (uiout
, "\nValue = ");
2369 watchpoint_value_print (b
->val
, stb
->stream
);
2370 ui_out_field_stream (uiout
, "value", stb
);
2371 do_cleanups (ui_out_chain
);
2372 ui_out_text (uiout
, "\n");
2373 return PRINT_UNKNOWN
;
2376 case bp_access_watchpoint
:
2377 if (bs
->old_val
!= NULL
)
2379 annotate_watchpoint (b
->number
);
2380 if (ui_out_is_mi_like_p (uiout
))
2383 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2385 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2386 ui_out_text (uiout
, "\nOld value = ");
2387 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2388 ui_out_field_stream (uiout
, "old", stb
);
2389 ui_out_text (uiout
, "\nNew value = ");
2394 if (ui_out_is_mi_like_p (uiout
))
2397 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2398 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2399 ui_out_text (uiout
, "\nValue = ");
2401 watchpoint_value_print (b
->val
, stb
->stream
);
2402 ui_out_field_stream (uiout
, "new", stb
);
2403 do_cleanups (ui_out_chain
);
2404 ui_out_text (uiout
, "\n");
2405 return PRINT_UNKNOWN
;
2408 /* Fall through, we don't deal with these types of breakpoints
2412 if (ui_out_is_mi_like_p (uiout
))
2415 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2416 return PRINT_UNKNOWN
;
2420 if (ui_out_is_mi_like_p (uiout
))
2423 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2424 return PRINT_UNKNOWN
;
2429 case bp_longjmp_resume
:
2430 case bp_step_resume
:
2431 case bp_watchpoint_scope
:
2434 return PRINT_UNKNOWN
;
2438 /* Generic routine for printing messages indicating why we
2439 stopped. The behavior of this function depends on the value
2440 'print_it' in the bpstat structure. Under some circumstances we
2441 may decide not to print anything here and delegate the task to
2444 static enum print_stop_action
2445 print_bp_stop_message (bpstat bs
)
2447 switch (bs
->print_it
)
2450 /* Nothing should be printed for this bpstat entry. */
2451 return PRINT_UNKNOWN
;
2455 /* We still want to print the frame, but we already printed the
2456 relevant messages. */
2457 return PRINT_SRC_AND_LOC
;
2460 case print_it_normal
:
2462 const struct bp_location
*bl
= bs
->breakpoint_at
;
2463 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2465 /* Normal case. Call the breakpoint's print_it method, or
2466 print_it_typical. */
2467 /* FIXME: how breakpoint can ever be NULL here? */
2468 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2469 return b
->ops
->print_it (b
);
2471 return print_it_typical (bs
);
2476 internal_error (__FILE__
, __LINE__
,
2477 _("print_bp_stop_message: unrecognized enum value"));
2482 /* Print a message indicating what happened. This is called from
2483 normal_stop(). The input to this routine is the head of the bpstat
2484 list - a list of the eventpoints that caused this stop. This
2485 routine calls the generic print routine for printing a message
2486 about reasons for stopping. This will print (for example) the
2487 "Breakpoint n," part of the output. The return value of this
2490 PRINT_UNKNOWN: Means we printed nothing
2491 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2492 code to print the location. An example is
2493 "Breakpoint 1, " which should be followed by
2495 PRINT_SRC_ONLY: Means we printed something, but there is no need
2496 to also print the location part of the message.
2497 An example is the catch/throw messages, which
2498 don't require a location appended to the end.
2499 PRINT_NOTHING: We have done some printing and we don't need any
2500 further info to be printed.*/
2502 enum print_stop_action
2503 bpstat_print (bpstat bs
)
2507 /* Maybe another breakpoint in the chain caused us to stop.
2508 (Currently all watchpoints go on the bpstat whether hit or not.
2509 That probably could (should) be changed, provided care is taken
2510 with respect to bpstat_explains_signal). */
2511 for (; bs
; bs
= bs
->next
)
2513 val
= print_bp_stop_message (bs
);
2514 if (val
== PRINT_SRC_ONLY
2515 || val
== PRINT_SRC_AND_LOC
2516 || val
== PRINT_NOTHING
)
2520 /* We reached the end of the chain, or we got a null BS to start
2521 with and nothing was printed. */
2522 return PRINT_UNKNOWN
;
2525 /* Evaluate the expression EXP and return 1 if value is zero.
2526 This is used inside a catch_errors to evaluate the breakpoint condition.
2527 The argument is a "struct expression *" that has been cast to char * to
2528 make it pass through catch_errors. */
2531 breakpoint_cond_eval (void *exp
)
2533 struct value
*mark
= value_mark ();
2534 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2535 value_free_to_mark (mark
);
2539 /* Allocate a new bpstat and chain it to the current one. */
2542 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2546 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2548 bs
->breakpoint_at
= bl
;
2549 /* If the condition is false, etc., don't do the commands. */
2550 bs
->commands
= NULL
;
2552 bs
->print_it
= print_it_normal
;
2556 /* The target has stopped with waitstatus WS. Check if any hardware
2557 watchpoints have triggered, according to the target. */
2560 watchpoints_triggered (struct target_waitstatus
*ws
)
2562 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2564 struct breakpoint
*b
;
2566 if (!stopped_by_watchpoint
)
2568 /* We were not stopped by a watchpoint. Mark all watchpoints
2569 as not triggered. */
2571 if (b
->type
== bp_hardware_watchpoint
2572 || b
->type
== bp_read_watchpoint
2573 || b
->type
== bp_access_watchpoint
)
2574 b
->watchpoint_triggered
= watch_triggered_no
;
2579 if (!target_stopped_data_address (¤t_target
, &addr
))
2581 /* We were stopped by a watchpoint, but we don't know where.
2582 Mark all watchpoints as unknown. */
2584 if (b
->type
== bp_hardware_watchpoint
2585 || b
->type
== bp_read_watchpoint
2586 || b
->type
== bp_access_watchpoint
)
2587 b
->watchpoint_triggered
= watch_triggered_unknown
;
2589 return stopped_by_watchpoint
;
2592 /* The target could report the data address. Mark watchpoints
2593 affected by this data address as triggered, and all others as not
2597 if (b
->type
== bp_hardware_watchpoint
2598 || b
->type
== bp_read_watchpoint
2599 || b
->type
== bp_access_watchpoint
)
2601 struct bp_location
*loc
;
2604 b
->watchpoint_triggered
= watch_triggered_no
;
2605 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2606 /* Exact match not required. Within range is
2608 if (target_watchpoint_addr_within_range (¤t_target
,
2612 b
->watchpoint_triggered
= watch_triggered_yes
;
2620 /* Possible return values for watchpoint_check (this can't be an enum
2621 because of check_errors). */
2622 /* The watchpoint has been deleted. */
2623 #define WP_DELETED 1
2624 /* The value has changed. */
2625 #define WP_VALUE_CHANGED 2
2626 /* The value has not changed. */
2627 #define WP_VALUE_NOT_CHANGED 3
2629 #define BP_TEMPFLAG 1
2630 #define BP_HARDWAREFLAG 2
2632 /* Check watchpoint condition. */
2635 watchpoint_check (void *p
)
2637 bpstat bs
= (bpstat
) p
;
2638 struct breakpoint
*b
;
2639 struct frame_info
*fr
;
2640 int within_current_scope
;
2642 b
= bs
->breakpoint_at
->owner
;
2644 if (b
->exp_valid_block
== NULL
)
2645 within_current_scope
= 1;
2648 /* There is no current frame at this moment. If we're going to have
2649 any chance of handling watchpoints on local variables, we'll need
2650 the frame chain (so we can determine if we're in scope). */
2651 reinit_frame_cache ();
2652 fr
= frame_find_by_id (b
->watchpoint_frame
);
2653 within_current_scope
= (fr
!= NULL
);
2655 /* If we've gotten confused in the unwinder, we might have
2656 returned a frame that can't describe this variable. */
2657 if (within_current_scope
2658 && (block_linkage_function (b
->exp_valid_block
)
2659 != get_frame_function (fr
)))
2660 within_current_scope
= 0;
2662 /* in_function_epilogue_p() returns a non-zero value if we're still
2663 in the function but the stack frame has already been invalidated.
2664 Since we can't rely on the values of local variables after the
2665 stack has been destroyed, we are treating the watchpoint in that
2666 state as `not changed' without further checking.
2668 vinschen/2003-09-04: The former implementation left out the case
2669 that the watchpoint frame couldn't be found by frame_find_by_id()
2670 because the current PC is currently in an epilogue. Calling
2671 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2672 if ((!within_current_scope
|| fr
== get_current_frame ())
2673 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2674 return WP_VALUE_NOT_CHANGED
;
2675 if (fr
&& within_current_scope
)
2676 /* If we end up stopping, the current frame will get selected
2677 in normal_stop. So this call to select_frame won't affect
2682 if (within_current_scope
)
2684 /* We use value_{,free_to_}mark because it could be a
2685 *long* time before we return to the command level and
2686 call free_all_values. We can't call free_all_values because
2687 we might be in the middle of evaluating a function call. */
2689 struct value
*mark
= value_mark ();
2690 struct value
*new_val
;
2692 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2693 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2694 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2696 if (new_val
!= NULL
)
2698 release_value (new_val
);
2699 value_free_to_mark (mark
);
2701 bs
->old_val
= b
->val
;
2704 /* We will stop here */
2705 return WP_VALUE_CHANGED
;
2709 /* Nothing changed, don't do anything. */
2710 value_free_to_mark (mark
);
2711 /* We won't stop here */
2712 return WP_VALUE_NOT_CHANGED
;
2717 /* This seems like the only logical thing to do because
2718 if we temporarily ignored the watchpoint, then when
2719 we reenter the block in which it is valid it contains
2720 garbage (in the case of a function, it may have two
2721 garbage values, one before and one after the prologue).
2722 So we can't even detect the first assignment to it and
2723 watch after that (since the garbage may or may not equal
2724 the first value assigned). */
2725 /* We print all the stop information in print_it_typical(), but
2726 in this case, by the time we call print_it_typical() this bp
2727 will be deleted already. So we have no choice but print the
2728 information here. */
2729 if (ui_out_is_mi_like_p (uiout
))
2731 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2732 ui_out_text (uiout
, "\nWatchpoint ");
2733 ui_out_field_int (uiout
, "wpnum", b
->number
);
2734 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2735 which its expression is valid.\n");
2737 if (b
->related_breakpoint
)
2738 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2739 b
->disposition
= disp_del_at_next_stop
;
2745 /* Return true if it looks like target has stopped due to hitting
2746 breakpoint location BL. This function does not check if we
2747 should stop, only if BL explains the stop. */
2749 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2751 struct breakpoint
*b
= bl
->owner
;
2753 if (b
->type
!= bp_watchpoint
2754 && b
->type
!= bp_hardware_watchpoint
2755 && b
->type
!= bp_read_watchpoint
2756 && b
->type
!= bp_access_watchpoint
2757 && b
->type
!= bp_hardware_breakpoint
2758 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
2760 if (bl
->address
!= bp_addr
) /* address doesn't match */
2762 if (overlay_debugging
/* unmapped overlay section */
2763 && section_is_overlay (bl
->section
)
2764 && !section_is_mapped (bl
->section
))
2768 /* Continuable hardware watchpoints are treated as non-existent if the
2769 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2770 some data address). Otherwise gdb won't stop on a break instruction
2771 in the code (not from a breakpoint) when a hardware watchpoint has
2772 been defined. Also skip watchpoints which we know did not trigger
2773 (did not match the data address). */
2775 if ((b
->type
== bp_hardware_watchpoint
2776 || b
->type
== bp_read_watchpoint
2777 || b
->type
== bp_access_watchpoint
)
2778 && b
->watchpoint_triggered
== watch_triggered_no
)
2781 if (b
->type
== bp_hardware_breakpoint
)
2783 if (bl
->address
!= bp_addr
)
2785 if (overlay_debugging
/* unmapped overlay section */
2786 && section_is_overlay (bl
->section
)
2787 && !section_is_mapped (bl
->section
))
2791 /* Is this a catchpoint of a load or unload? If so, did we
2792 get a load or unload of the specified library? If not,
2794 if ((b
->type
== bp_catch_load
)
2795 #if defined(SOLIB_HAVE_LOAD_EVENT)
2796 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2797 || ((b
->dll_pathname
!= NULL
)
2798 && (strcmp (b
->dll_pathname
,
2799 SOLIB_LOADED_LIBRARY_PATHNAME (
2800 PIDGET (inferior_ptid
)))
2806 if ((b
->type
== bp_catch_unload
)
2807 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2808 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2809 || ((b
->dll_pathname
!= NULL
)
2810 && (strcmp (b
->dll_pathname
,
2811 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2812 PIDGET (inferior_ptid
)))
2818 if (b
->type
== bp_catchpoint
)
2820 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2821 if (!b
->ops
->breakpoint_hit (b
))
2828 /* If BS refers to a watchpoint, determine if the watched values
2829 has actually changed, and we should stop. If not, set BS->stop
2832 bpstat_check_watchpoint (bpstat bs
)
2834 const struct bp_location
*bl
= bs
->breakpoint_at
;
2835 struct breakpoint
*b
= bl
->owner
;
2837 if (b
->type
== bp_watchpoint
2838 || b
->type
== bp_read_watchpoint
2839 || b
->type
== bp_access_watchpoint
2840 || b
->type
== bp_hardware_watchpoint
)
2844 int must_check_value
= 0;
2846 if (b
->type
== bp_watchpoint
)
2847 /* For a software watchpoint, we must always check the
2849 must_check_value
= 1;
2850 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2851 /* We have a hardware watchpoint (read, write, or access)
2852 and the target earlier reported an address watched by
2854 must_check_value
= 1;
2855 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2856 && b
->type
== bp_hardware_watchpoint
)
2857 /* We were stopped by a hardware watchpoint, but the target could
2858 not report the data address. We must check the watchpoint's
2859 value. Access and read watchpoints are out of luck; without
2860 a data address, we can't figure it out. */
2861 must_check_value
= 1;
2863 if (must_check_value
)
2865 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2867 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2868 int e
= catch_errors (watchpoint_check
, bs
, message
,
2870 do_cleanups (cleanups
);
2874 /* We've already printed what needs to be printed. */
2875 bs
->print_it
= print_it_done
;
2878 case WP_VALUE_CHANGED
:
2879 if (b
->type
== bp_read_watchpoint
)
2881 /* Don't stop: read watchpoints shouldn't fire if
2882 the value has changed. This is for targets
2883 which cannot set read-only watchpoints. */
2884 bs
->print_it
= print_it_noop
;
2888 case WP_VALUE_NOT_CHANGED
:
2889 if (b
->type
== bp_hardware_watchpoint
2890 || b
->type
== bp_watchpoint
)
2892 /* Don't stop: write watchpoints shouldn't fire if
2893 the value hasn't changed. */
2894 bs
->print_it
= print_it_noop
;
2902 /* Error from catch_errors. */
2903 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2904 if (b
->related_breakpoint
)
2905 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2906 b
->disposition
= disp_del_at_next_stop
;
2907 /* We've already printed what needs to be printed. */
2908 bs
->print_it
= print_it_done
;
2912 else /* must_check_value == 0 */
2914 /* This is a case where some watchpoint(s) triggered, but
2915 not at the address of this watchpoint, or else no
2916 watchpoint triggered after all. So don't print
2917 anything for this watchpoint. */
2918 bs
->print_it
= print_it_noop
;
2925 /* Check conditions (condition proper, frame, thread and ignore count)
2926 of breakpoint referred to by BS. If we should not stop for this
2927 breakpoint, set BS->stop to 0. */
2929 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2931 int thread_id
= pid_to_thread_id (ptid
);
2932 const struct bp_location
*bl
= bs
->breakpoint_at
;
2933 struct breakpoint
*b
= bl
->owner
;
2935 if (frame_id_p (b
->frame_id
)
2936 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2940 int value_is_zero
= 0;
2942 /* If this is a scope breakpoint, mark the associated
2943 watchpoint as triggered so that we will handle the
2944 out-of-scope event. We'll get to the watchpoint next
2946 if (b
->type
== bp_watchpoint_scope
)
2947 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2949 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2951 /* Need to select the frame, with all that implies
2952 so that the conditions will have the right context. */
2953 select_frame (get_current_frame ());
2955 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2956 "Error in testing breakpoint condition:\n",
2958 /* FIXME-someday, should give breakpoint # */
2961 if (bl
->cond
&& value_is_zero
)
2965 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2969 else if (b
->ignore_count
> 0)
2972 annotate_ignore_count_change ();
2974 /* Increase the hit count even though we don't
2982 /* Get a bpstat associated with having just stopped at address
2983 BP_ADDR in thread PTID.
2985 Determine whether we stopped at a breakpoint, etc, or whether we
2986 don't understand this stop. Result is a chain of bpstat's such that:
2988 if we don't understand the stop, the result is a null pointer.
2990 if we understand why we stopped, the result is not null.
2992 Each element of the chain refers to a particular breakpoint or
2993 watchpoint at which we have stopped. (We may have stopped for
2994 several reasons concurrently.)
2996 Each element of the chain has valid next, breakpoint_at,
2997 commands, FIXME??? fields. */
3000 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3002 struct breakpoint
*b
= NULL
;
3003 const struct bp_location
*bl
;
3004 struct bp_location
*loc
;
3005 /* Root of the chain of bpstat's */
3006 struct bpstats root_bs
[1];
3007 /* Pointer to the last thing in the chain currently. */
3008 bpstat bs
= root_bs
;
3010 int need_remove_insert
;
3012 ALL_BP_LOCATIONS (bl
)
3016 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3019 /* For hardware watchpoints, we look only at the first location.
3020 The watchpoint_check function will work on entire expression,
3021 not the individual locations. For read watchopints, the
3022 watchpoints_triggered function have checked all locations
3025 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3028 if (!bpstat_check_location (bl
, bp_addr
))
3031 /* Come here if it's a watchpoint, or if the break address matches */
3033 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3035 /* Assume we stop. Should we find watchpoint that is not actually
3036 triggered, or if condition of breakpoint is false, we'll reset
3041 bpstat_check_watchpoint (bs
);
3045 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3046 /* We do not stop for these. */
3049 bpstat_check_breakpoint_conditions (bs
, ptid
);
3055 /* We will stop here */
3056 if (b
->disposition
== disp_disable
)
3058 if (b
->enable_state
!= bp_permanent
)
3059 b
->enable_state
= bp_disabled
;
3060 update_global_location_list (0);
3064 bs
->commands
= b
->commands
;
3066 (strcmp ("silent", bs
->commands
->line
) == 0
3067 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3069 bs
->commands
= bs
->commands
->next
;
3072 bs
->commands
= copy_command_lines (bs
->commands
);
3075 /* Print nothing for this entry if we dont stop or if we dont print. */
3076 if (bs
->stop
== 0 || bs
->print
== 0)
3077 bs
->print_it
= print_it_noop
;
3080 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3082 if (loc
->address
== bp_addr
)
3084 bs
= bpstat_alloc (loc
, bs
);
3085 /* For hits of moribund locations, we should just proceed. */
3088 bs
->print_it
= print_it_noop
;
3092 bs
->next
= NULL
; /* Terminate the chain */
3093 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3095 /* If we aren't stopping, the value of some hardware watchpoint may
3096 not have changed, but the intermediate memory locations we are
3097 watching may have. Don't bother if we're stopping; this will get
3099 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3103 need_remove_insert
= 0;
3105 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3107 && bs
->breakpoint_at
->owner
3108 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3109 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3110 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3112 /* remove/insert can invalidate bs->breakpoint_at, if this
3113 location is no longer used by the watchpoint. Prevent
3114 further code from trying to use it. */
3115 bs
->breakpoint_at
= NULL
;
3116 need_remove_insert
= 1;
3119 if (need_remove_insert
)
3121 remove_breakpoints ();
3122 insert_breakpoints ();
3125 return root_bs
->next
;
3128 /* Tell what to do about this bpstat. */
3130 bpstat_what (bpstat bs
)
3132 /* Classify each bpstat as one of the following. */
3135 /* This bpstat element has no effect on the main_action. */
3138 /* There was a watchpoint, stop but don't print. */
3141 /* There was a watchpoint, stop and print. */
3144 /* There was a breakpoint but we're not stopping. */
3147 /* There was a breakpoint, stop but don't print. */
3150 /* There was a breakpoint, stop and print. */
3153 /* We hit the longjmp breakpoint. */
3156 /* We hit the longjmp_resume breakpoint. */
3159 /* We hit the step_resume breakpoint. */
3162 /* We hit the shared library event breakpoint. */
3165 /* We caught a shared library event. */
3168 /* This is just used to count how many enums there are. */
3172 /* Here is the table which drives this routine. So that we can
3173 format it pretty, we define some abbreviations for the
3174 enum bpstat_what codes. */
3175 #define kc BPSTAT_WHAT_KEEP_CHECKING
3176 #define ss BPSTAT_WHAT_STOP_SILENT
3177 #define sn BPSTAT_WHAT_STOP_NOISY
3178 #define sgl BPSTAT_WHAT_SINGLE
3179 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3180 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3181 #define sr BPSTAT_WHAT_STEP_RESUME
3182 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3183 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3185 /* "Can't happen." Might want to print an error message.
3186 abort() is not out of the question, but chances are GDB is just
3187 a bit confused, not unusable. */
3188 #define err BPSTAT_WHAT_STOP_NOISY
3190 /* Given an old action and a class, come up with a new action. */
3191 /* One interesting property of this table is that wp_silent is the same
3192 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3193 after stopping, the check for whether to step over a breakpoint
3194 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3195 reference to how we stopped. We retain separate wp_silent and
3196 bp_silent codes in case we want to change that someday.
3198 Another possibly interesting property of this table is that
3199 there's a partial ordering, priority-like, of the actions. Once
3200 you've decided that some action is appropriate, you'll never go
3201 back and decide something of a lower priority is better. The
3204 kc < clr sgl shl shlr slr sn sr ss
3205 sgl < shl shlr slr sn sr ss
3206 slr < err shl shlr sn sr ss
3207 clr < err shl shlr sn sr ss
3214 What I think this means is that we don't need a damned table
3215 here. If you just put the rows and columns in the right order,
3216 it'd look awfully regular. We could simply walk the bpstat list
3217 and choose the highest priority action we find, with a little
3218 logic to handle the 'err' cases. */
3220 /* step_resume entries: a step resume breakpoint overrides another
3221 breakpoint of signal handling (see comment in wait_for_inferior
3222 at where we set the step_resume breakpoint). */
3224 static const enum bpstat_what_main_action
3225 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3228 /* kc ss sn sgl slr clr sr shl shlr
3231 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, shlr
},
3233 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3235 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3237 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, shlr
},
3239 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3241 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3243 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, shlr
},
3245 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, shlr
},
3247 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3249 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3251 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3265 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3266 struct bpstat_what retval
;
3268 retval
.call_dummy
= 0;
3269 for (; bs
!= NULL
; bs
= bs
->next
)
3271 enum class bs_class
= no_effect
;
3272 if (bs
->breakpoint_at
== NULL
)
3273 /* I suspect this can happen if it was a momentary breakpoint
3274 which has since been deleted. */
3276 if (bs
->breakpoint_at
->owner
== NULL
)
3277 bs_class
= bp_nostop
;
3279 switch (bs
->breakpoint_at
->owner
->type
)
3285 case bp_hardware_breakpoint
:
3291 bs_class
= bp_noisy
;
3293 bs_class
= bp_silent
;
3296 bs_class
= bp_nostop
;
3299 case bp_hardware_watchpoint
:
3300 case bp_read_watchpoint
:
3301 case bp_access_watchpoint
:
3305 bs_class
= wp_noisy
;
3307 bs_class
= wp_silent
;
3310 /* There was a watchpoint, but we're not stopping.
3311 This requires no further action. */
3312 bs_class
= no_effect
;
3315 bs_class
= long_jump
;
3317 case bp_longjmp_resume
:
3318 bs_class
= long_resume
;
3320 case bp_step_resume
:
3323 bs_class
= step_resume
;
3326 /* It is for the wrong frame. */
3327 bs_class
= bp_nostop
;
3329 case bp_watchpoint_scope
:
3330 bs_class
= bp_nostop
;
3332 case bp_shlib_event
:
3333 bs_class
= shlib_event
;
3335 case bp_thread_event
:
3336 case bp_overlay_event
:
3337 bs_class
= bp_nostop
;
3340 case bp_catch_unload
:
3341 /* Only if this catchpoint triggered should we cause the
3342 step-out-of-dld behaviour. Otherwise, we ignore this
3345 bs_class
= catch_shlib_event
;
3347 bs_class
= no_effect
;
3353 bs_class
= bp_noisy
;
3355 bs_class
= bp_silent
;
3358 /* There was a catchpoint, but we're not stopping.
3359 This requires no further action. */
3360 bs_class
= no_effect
;
3363 /* Make sure the action is stop (silent or noisy),
3364 so infrun.c pops the dummy frame. */
3365 bs_class
= bp_silent
;
3366 retval
.call_dummy
= 1;
3369 current_action
= table
[(int) bs_class
][(int) current_action
];
3371 retval
.main_action
= current_action
;
3375 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3376 without hardware support). This isn't related to a specific bpstat,
3377 just to things like whether watchpoints are set. */
3380 bpstat_should_step (void)
3382 struct breakpoint
*b
;
3384 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3391 /* Given a bpstat that records zero or more triggered eventpoints, this
3392 function returns another bpstat which contains only the catchpoints
3393 on that first list, if any. */
3395 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3397 struct bpstats root_bs
[1];
3398 bpstat bs
= root_bs
;
3399 struct breakpoint
*ep
;
3402 bpstat_clear (cp_list
);
3403 root_bs
->next
= NULL
;
3405 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3407 /* Is this eventpoint a catchpoint? If not, ignore it. */
3408 ep
= ep_list
->breakpoint_at
->owner
;
3411 if ((ep
->type
!= bp_catch_load
) &&
3412 (ep
->type
!= bp_catch_unload
))
3413 /* pai: (temp) ADD fork/vfork here!! */
3416 /* Yes; add it to the list. */
3417 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3422 #if defined(SOLIB_ADD)
3423 /* Also, for each triggered catchpoint, tag it with the name of
3424 the library that caused this trigger. (We copy the name now,
3425 because it's only guaranteed to be available NOW, when the
3426 catchpoint triggers. Clients who may wish to know the name
3427 later must get it from the catchpoint itself.) */
3428 if (ep
->triggered_dll_pathname
!= NULL
)
3429 xfree (ep
->triggered_dll_pathname
);
3430 if (ep
->type
== bp_catch_load
)
3431 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3432 PIDGET (inferior_ptid
));
3434 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3435 PIDGET (inferior_ptid
));
3437 dll_pathname
= NULL
;
3441 ep
->triggered_dll_pathname
= (char *)
3442 xmalloc (strlen (dll_pathname
) + 1);
3443 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3446 ep
->triggered_dll_pathname
= NULL
;
3452 static void print_breakpoint_location (struct breakpoint
*b
,
3453 struct bp_location
*loc
,
3455 struct ui_stream
*stb
)
3460 = find_pc_sect_function (loc
->address
, loc
->section
);
3463 ui_out_text (uiout
, "in ");
3464 ui_out_field_string (uiout
, "func",
3465 SYMBOL_PRINT_NAME (sym
));
3466 ui_out_wrap_hint (uiout
, wrap_indent
);
3467 ui_out_text (uiout
, " at ");
3469 ui_out_field_string (uiout
, "file", b
->source_file
);
3470 ui_out_text (uiout
, ":");
3472 if (ui_out_is_mi_like_p (uiout
))
3474 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3475 char *fullname
= symtab_to_fullname (sal
.symtab
);
3478 ui_out_field_string (uiout
, "fullname", fullname
);
3481 ui_out_field_int (uiout
, "line", b
->line_number
);
3485 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3489 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3490 ui_out_field_stream (uiout
, "at", stb
);
3494 /* Print B to gdb_stdout. */
3496 print_one_breakpoint_location (struct breakpoint
*b
,
3497 struct bp_location
*loc
,
3499 CORE_ADDR
*last_addr
)
3501 struct command_line
*l
;
3503 struct ep_type_description
3508 static struct ep_type_description bptypes
[] =
3510 {bp_none
, "?deleted?"},
3511 {bp_breakpoint
, "breakpoint"},
3512 {bp_hardware_breakpoint
, "hw breakpoint"},
3513 {bp_until
, "until"},
3514 {bp_finish
, "finish"},
3515 {bp_watchpoint
, "watchpoint"},
3516 {bp_hardware_watchpoint
, "hw watchpoint"},
3517 {bp_read_watchpoint
, "read watchpoint"},
3518 {bp_access_watchpoint
, "acc watchpoint"},
3519 {bp_longjmp
, "longjmp"},
3520 {bp_longjmp_resume
, "longjmp resume"},
3521 {bp_step_resume
, "step resume"},
3522 {bp_watchpoint_scope
, "watchpoint scope"},
3523 {bp_call_dummy
, "call dummy"},
3524 {bp_shlib_event
, "shlib events"},
3525 {bp_thread_event
, "thread events"},
3526 {bp_overlay_event
, "overlay events"},
3527 {bp_catchpoint
, "catchpoint"},
3528 {bp_catch_load
, "catch load"},
3529 {bp_catch_unload
, "catch unload"}
3532 static char bpenables
[] = "nynny";
3533 char wrap_indent
[80];
3534 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3535 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3536 struct cleanup
*bkpt_chain
;
3538 int header_of_multiple
= 0;
3539 int part_of_multiple
= (loc
!= NULL
);
3540 struct value_print_options opts
;
3542 get_user_print_options (&opts
);
3544 gdb_assert (!loc
|| loc_number
!= 0);
3545 /* See comment in print_one_breakpoint concerning
3546 treatment of breakpoints with single disabled
3550 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3551 header_of_multiple
= 1;
3556 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3560 if (part_of_multiple
)
3563 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3564 ui_out_field_string (uiout
, "number", formatted
);
3569 ui_out_field_int (uiout
, "number", b
->number
);
3574 if (part_of_multiple
)
3575 ui_out_field_skip (uiout
, "type");
3578 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3579 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3580 internal_error (__FILE__
, __LINE__
,
3581 _("bptypes table does not describe type #%d."),
3583 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3588 if (part_of_multiple
)
3589 ui_out_field_skip (uiout
, "disp");
3591 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3596 if (part_of_multiple
)
3597 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3599 ui_out_field_fmt (uiout
, "enabled", "%c",
3600 bpenables
[(int) b
->enable_state
]);
3601 ui_out_spaces (uiout
, 2);
3605 strcpy (wrap_indent
, " ");
3606 if (opts
.addressprint
)
3608 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3609 strcat (wrap_indent
, " ");
3611 strcat (wrap_indent
, " ");
3614 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3616 /* Although the print_one can possibly print
3617 all locations, calling it here is not likely
3618 to get any nice result. So, make sure there's
3619 just one location. */
3620 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3621 b
->ops
->print_one (b
, last_addr
);
3627 internal_error (__FILE__
, __LINE__
,
3628 _("print_one_breakpoint: bp_none encountered\n"));
3632 case bp_hardware_watchpoint
:
3633 case bp_read_watchpoint
:
3634 case bp_access_watchpoint
:
3635 /* Field 4, the address, is omitted (which makes the columns
3636 not line up too nicely with the headers, but the effect
3637 is relatively readable). */
3638 if (opts
.addressprint
)
3639 ui_out_field_skip (uiout
, "addr");
3641 print_expression (b
->exp
, stb
->stream
);
3642 ui_out_field_stream (uiout
, "what", stb
);
3646 case bp_catch_unload
:
3647 /* Field 4, the address, is omitted (which makes the columns
3648 not line up too nicely with the headers, but the effect
3649 is relatively readable). */
3650 if (opts
.addressprint
)
3651 ui_out_field_skip (uiout
, "addr");
3653 if (b
->dll_pathname
== NULL
)
3655 ui_out_field_string (uiout
, "what", "<any library>");
3656 ui_out_spaces (uiout
, 1);
3660 ui_out_text (uiout
, "library \"");
3661 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3662 ui_out_text (uiout
, "\" ");
3667 case bp_hardware_breakpoint
:
3671 case bp_longjmp_resume
:
3672 case bp_step_resume
:
3673 case bp_watchpoint_scope
:
3675 case bp_shlib_event
:
3676 case bp_thread_event
:
3677 case bp_overlay_event
:
3678 if (opts
.addressprint
)
3681 if (header_of_multiple
)
3682 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3683 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3684 ui_out_field_string (uiout
, "addr", "<PENDING>");
3686 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3689 if (!header_of_multiple
)
3690 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3692 *last_addr
= b
->loc
->address
;
3696 if (!part_of_multiple
&& b
->thread
!= -1)
3698 /* FIXME: This seems to be redundant and lost here; see the
3699 "stop only in" line a little further down. */
3700 ui_out_text (uiout
, " thread ");
3701 ui_out_field_int (uiout
, "thread", b
->thread
);
3704 ui_out_text (uiout
, "\n");
3706 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3709 ui_out_text (uiout
, "\tstop only in stack frame at ");
3710 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3712 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3713 ui_out_text (uiout
, "\n");
3716 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3718 /* We do not print the condition for Ada exception catchpoints
3719 because the condition is an internal implementation detail
3720 that we do not want to expose to the user. */
3722 ui_out_text (uiout
, "\tstop only if ");
3723 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3724 ui_out_text (uiout
, "\n");
3727 if (!part_of_multiple
&& b
->thread
!= -1)
3729 /* FIXME should make an annotation for this */
3730 ui_out_text (uiout
, "\tstop only in thread ");
3731 ui_out_field_int (uiout
, "thread", b
->thread
);
3732 ui_out_text (uiout
, "\n");
3735 if (!part_of_multiple
&& b
->hit_count
)
3737 /* FIXME should make an annotation for this */
3738 if (ep_is_catchpoint (b
))
3739 ui_out_text (uiout
, "\tcatchpoint");
3741 ui_out_text (uiout
, "\tbreakpoint");
3742 ui_out_text (uiout
, " already hit ");
3743 ui_out_field_int (uiout
, "times", b
->hit_count
);
3744 if (b
->hit_count
== 1)
3745 ui_out_text (uiout
, " time\n");
3747 ui_out_text (uiout
, " times\n");
3750 /* Output the count also if it is zero, but only if this is
3751 mi. FIXME: Should have a better test for this. */
3752 if (ui_out_is_mi_like_p (uiout
))
3753 if (!part_of_multiple
&& b
->hit_count
== 0)
3754 ui_out_field_int (uiout
, "times", b
->hit_count
);
3756 if (!part_of_multiple
&& b
->ignore_count
)
3759 ui_out_text (uiout
, "\tignore next ");
3760 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3761 ui_out_text (uiout
, " hits\n");
3764 if (!part_of_multiple
&& (l
= b
->commands
))
3766 struct cleanup
*script_chain
;
3769 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3770 print_command_lines (uiout
, l
, 4);
3771 do_cleanups (script_chain
);
3774 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3777 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3778 else if (b
->exp_string
)
3779 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3782 do_cleanups (bkpt_chain
);
3783 do_cleanups (old_chain
);
3787 print_one_breakpoint (struct breakpoint
*b
,
3788 CORE_ADDR
*last_addr
)
3790 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3792 /* If this breakpoint has custom print function,
3793 it's already printed. Otherwise, print individual
3794 locations, if any. */
3795 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3797 /* If breakpoint has a single location that is
3798 disabled, we print it as if it had
3799 several locations, since otherwise it's hard to
3800 represent "breakpoint enabled, location disabled"
3802 Note that while hardware watchpoints have
3803 several locations internally, that's no a property
3806 && !is_hardware_watchpoint (b
)
3807 && (b
->loc
->next
|| !b
->loc
->enabled
)
3808 && !ui_out_is_mi_like_p (uiout
))
3810 struct bp_location
*loc
;
3812 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3813 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3819 struct captured_breakpoint_query_args
3825 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3827 struct captured_breakpoint_query_args
*args
= data
;
3828 struct breakpoint
*b
;
3829 CORE_ADDR dummy_addr
= 0;
3832 if (args
->bnum
== b
->number
)
3834 print_one_breakpoint (b
, &dummy_addr
);
3842 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3844 struct captured_breakpoint_query_args args
;
3846 /* For the moment we don't trust print_one_breakpoint() to not throw
3848 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3849 error_message
, RETURN_MASK_ALL
) < 0)
3855 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3856 catchpoints, et.al.). */
3859 user_settable_breakpoint (const struct breakpoint
*b
)
3861 return (b
->type
== bp_breakpoint
3862 || b
->type
== bp_catchpoint
3863 || b
->type
== bp_catch_load
3864 || b
->type
== bp_catch_unload
3865 || b
->type
== bp_hardware_breakpoint
3866 || b
->type
== bp_watchpoint
3867 || b
->type
== bp_read_watchpoint
3868 || b
->type
== bp_access_watchpoint
3869 || b
->type
== bp_hardware_watchpoint
);
3872 /* Print information on user settable breakpoint (watchpoint, etc)
3873 number BNUM. If BNUM is -1 print all user settable breakpoints.
3874 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3877 breakpoint_1 (int bnum
, int allflag
)
3879 struct breakpoint
*b
;
3880 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3881 int nr_printable_breakpoints
;
3882 struct cleanup
*bkpttbl_chain
;
3883 struct value_print_options opts
;
3885 get_user_print_options (&opts
);
3887 /* Compute the number of rows in the table. */
3888 nr_printable_breakpoints
= 0;
3891 || bnum
== b
->number
)
3893 if (allflag
|| user_settable_breakpoint (b
))
3894 nr_printable_breakpoints
++;
3897 if (opts
.addressprint
)
3899 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3903 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3906 if (nr_printable_breakpoints
> 0)
3907 annotate_breakpoints_headers ();
3908 if (nr_printable_breakpoints
> 0)
3910 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3911 if (nr_printable_breakpoints
> 0)
3913 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3914 if (nr_printable_breakpoints
> 0)
3916 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3917 if (nr_printable_breakpoints
> 0)
3919 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3920 if (opts
.addressprint
)
3922 if (nr_printable_breakpoints
> 0)
3924 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3925 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3927 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3929 if (nr_printable_breakpoints
> 0)
3931 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3932 ui_out_table_body (uiout
);
3933 if (nr_printable_breakpoints
> 0)
3934 annotate_breakpoints_table ();
3938 || bnum
== b
->number
)
3940 /* We only print out user settable breakpoints unless the
3942 if (allflag
|| user_settable_breakpoint (b
))
3943 print_one_breakpoint (b
, &last_addr
);
3946 do_cleanups (bkpttbl_chain
);
3948 if (nr_printable_breakpoints
== 0)
3951 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3953 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3958 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3959 that a comparison of an unsigned with -1 is always false. */
3960 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3961 set_next_address (current_gdbarch
, last_addr
);
3964 /* FIXME? Should this be moved up so that it is only called when
3965 there have been breakpoints? */
3966 annotate_breakpoints_table_end ();
3970 breakpoints_info (char *bnum_exp
, int from_tty
)
3975 bnum
= parse_and_eval_long (bnum_exp
);
3977 breakpoint_1 (bnum
, 0);
3981 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3986 bnum
= parse_and_eval_long (bnum_exp
);
3988 breakpoint_1 (bnum
, 1);
3992 breakpoint_has_pc (struct breakpoint
*b
,
3993 CORE_ADDR pc
, struct obj_section
*section
)
3995 struct bp_location
*bl
= b
->loc
;
3996 for (; bl
; bl
= bl
->next
)
3998 if (bl
->address
== pc
3999 && (!overlay_debugging
|| bl
->section
== section
))
4005 /* Print a message describing any breakpoints set at PC. */
4008 describe_other_breakpoints (CORE_ADDR pc
, struct obj_section
*section
,
4012 struct breakpoint
*b
;
4015 others
+= breakpoint_has_pc (b
, pc
, section
);
4019 printf_filtered (_("Note: breakpoint "));
4020 else /* if (others == ???) */
4021 printf_filtered (_("Note: breakpoints "));
4023 if (breakpoint_has_pc (b
, pc
, section
))
4026 printf_filtered ("%d", b
->number
);
4027 if (b
->thread
== -1 && thread
!= -1)
4028 printf_filtered (" (all threads)");
4029 else if (b
->thread
!= -1)
4030 printf_filtered (" (thread %d)", b
->thread
);
4031 printf_filtered ("%s%s ",
4032 ((b
->enable_state
== bp_disabled
||
4033 b
->enable_state
== bp_call_disabled
)
4035 : b
->enable_state
== bp_permanent
4039 : ((others
== 1) ? " and" : ""));
4041 printf_filtered (_("also set at pc "));
4042 fputs_filtered (paddress (pc
), gdb_stdout
);
4043 printf_filtered (".\n");
4047 /* Set the default place to put a breakpoint
4048 for the `break' command with no arguments. */
4051 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4054 default_breakpoint_valid
= valid
;
4055 default_breakpoint_address
= addr
;
4056 default_breakpoint_symtab
= symtab
;
4057 default_breakpoint_line
= line
;
4060 /* Return true iff it is meaningful to use the address member of
4061 BPT. For some breakpoint types, the address member is irrelevant
4062 and it makes no sense to attempt to compare it to other addresses
4063 (or use it for any other purpose either).
4065 More specifically, each of the following breakpoint types will always
4066 have a zero valued address and we don't want check_duplicates() to mark
4067 breakpoints of any of these types to be a duplicate of an actual
4068 breakpoint at address zero:
4071 bp_hardware_watchpoint
4073 bp_access_watchpoint
4077 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4079 enum bptype type
= bpt
->type
;
4081 return (type
!= bp_watchpoint
4082 && type
!= bp_hardware_watchpoint
4083 && type
!= bp_read_watchpoint
4084 && type
!= bp_access_watchpoint
4085 && type
!= bp_catchpoint
);
4088 /* Rescan breakpoints at the same address and section as BPT,
4089 marking the first one as "first" and any others as "duplicates".
4090 This is so that the bpt instruction is only inserted once.
4091 If we have a permanent breakpoint at the same place as BPT, make
4092 that one the official one, and the rest as duplicates. */
4095 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
4097 struct bp_location
*b
;
4099 struct bp_location
*perm_bp
= 0;
4101 ALL_BP_LOCATIONS (b
)
4102 if (b
->owner
->enable_state
!= bp_disabled
4103 && b
->owner
->enable_state
!= bp_call_disabled
4105 && !b
->shlib_disabled
4106 && b
->address
== address
/* address / overlay match */
4107 && (!overlay_debugging
|| b
->section
== section
)
4108 && breakpoint_address_is_meaningful (b
->owner
))
4110 /* Have we found a permanent breakpoint? */
4111 if (b
->owner
->enable_state
== bp_permanent
)
4118 b
->duplicate
= count
> 1;
4121 /* If we found a permanent breakpoint at this address, go over the
4122 list again and declare all the other breakpoints there to be the
4126 perm_bp
->duplicate
= 0;
4128 /* Permanent breakpoint should always be inserted. */
4129 if (! perm_bp
->inserted
)
4130 internal_error (__FILE__
, __LINE__
,
4131 _("allegedly permanent breakpoint is not "
4132 "actually inserted"));
4134 ALL_BP_LOCATIONS (b
)
4137 if (b
->owner
->enable_state
!= bp_disabled
4138 && b
->owner
->enable_state
!= bp_call_disabled
4139 && b
->enabled
&& !b
->shlib_disabled
4140 && b
->address
== address
/* address / overlay match */
4141 && (!overlay_debugging
|| b
->section
== section
)
4142 && breakpoint_address_is_meaningful (b
->owner
))
4145 internal_error (__FILE__
, __LINE__
,
4146 _("another breakpoint was inserted on top of "
4147 "a permanent breakpoint"));
4156 check_duplicates (struct breakpoint
*bpt
)
4158 struct bp_location
*bl
= bpt
->loc
;
4160 if (! breakpoint_address_is_meaningful (bpt
))
4163 for (; bl
; bl
= bl
->next
)
4164 check_duplicates_for (bl
->address
, bl
->section
);
4168 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4169 int bnum
, int have_bnum
)
4174 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4175 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4177 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4178 bnum
, astr1
, astr2
);
4180 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4183 /* Adjust a breakpoint's address to account for architectural constraints
4184 on breakpoint placement. Return the adjusted address. Note: Very
4185 few targets require this kind of adjustment. For most targets,
4186 this function is simply the identity function. */
4189 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4191 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4193 /* Very few targets need any kind of breakpoint adjustment. */
4196 else if (bptype
== bp_watchpoint
4197 || bptype
== bp_hardware_watchpoint
4198 || bptype
== bp_read_watchpoint
4199 || bptype
== bp_access_watchpoint
4200 || bptype
== bp_catchpoint
)
4202 /* Watchpoints and the various bp_catch_* eventpoints should not
4203 have their addresses modified. */
4208 CORE_ADDR adjusted_bpaddr
;
4210 /* Some targets have architectural constraints on the placement
4211 of breakpoint instructions. Obtain the adjusted address. */
4212 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4215 /* An adjusted breakpoint address can significantly alter
4216 a user's expectations. Print a warning if an adjustment
4218 if (adjusted_bpaddr
!= bpaddr
)
4219 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4221 return adjusted_bpaddr
;
4225 /* Allocate a struct bp_location. */
4227 static struct bp_location
*
4228 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4230 struct bp_location
*loc
, *loc_p
;
4232 loc
= xmalloc (sizeof (struct bp_location
));
4233 memset (loc
, 0, sizeof (*loc
));
4237 loc
->shlib_disabled
= 0;
4246 case bp_longjmp_resume
:
4247 case bp_step_resume
:
4248 case bp_watchpoint_scope
:
4250 case bp_shlib_event
:
4251 case bp_thread_event
:
4252 case bp_overlay_event
:
4254 case bp_catch_unload
:
4255 loc
->loc_type
= bp_loc_software_breakpoint
;
4257 case bp_hardware_breakpoint
:
4258 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4260 case bp_hardware_watchpoint
:
4261 case bp_read_watchpoint
:
4262 case bp_access_watchpoint
:
4263 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4267 loc
->loc_type
= bp_loc_other
;
4270 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4276 static void free_bp_location (struct bp_location
*loc
)
4281 if (loc
->function_name
)
4282 xfree (loc
->function_name
);
4287 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4288 that has type BPTYPE and has no locations as yet. */
4290 static struct breakpoint
*
4291 set_raw_breakpoint_without_location (enum bptype bptype
)
4293 struct breakpoint
*b
, *b1
;
4295 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4296 memset (b
, 0, sizeof (*b
));
4299 b
->language
= current_language
->la_language
;
4300 b
->input_radix
= input_radix
;
4302 b
->enable_state
= bp_enabled
;
4305 b
->ignore_count
= 0;
4307 b
->frame_id
= null_frame_id
;
4308 b
->dll_pathname
= NULL
;
4309 b
->triggered_dll_pathname
= NULL
;
4310 b
->forked_inferior_pid
= null_ptid
;
4311 b
->exec_pathname
= NULL
;
4313 b
->condition_not_parsed
= 0;
4315 /* Add this breakpoint to the end of the chain
4316 so that a list of breakpoints will come out in order
4317 of increasing numbers. */
4319 b1
= breakpoint_chain
;
4321 breakpoint_chain
= b
;
4331 /* Initialize loc->function_name. */
4333 set_breakpoint_location_function (struct bp_location
*loc
)
4335 if (loc
->owner
->type
== bp_breakpoint
4336 || loc
->owner
->type
== bp_hardware_breakpoint
)
4338 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4340 if (loc
->function_name
)
4341 loc
->function_name
= xstrdup (loc
->function_name
);
4345 /* set_raw_breakpoint is a low level routine for allocating and
4346 partially initializing a breakpoint of type BPTYPE. The newly
4347 created breakpoint's address, section, source file name, and line
4348 number are provided by SAL. The newly created and partially
4349 initialized breakpoint is added to the breakpoint chain and
4350 is also returned as the value of this function.
4352 It is expected that the caller will complete the initialization of
4353 the newly created breakpoint struct as well as output any status
4354 information regarding the creation of a new breakpoint. In
4355 particular, set_raw_breakpoint does NOT set the breakpoint
4356 number! Care should be taken to not allow an error to occur
4357 prior to completing the initialization of the breakpoint. If this
4358 should happen, a bogus breakpoint will be left on the chain. */
4361 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4363 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4364 CORE_ADDR adjusted_address
;
4366 /* Adjust the breakpoint's address prior to allocating a location.
4367 Once we call allocate_bp_location(), that mostly uninitialized
4368 location will be placed on the location chain. Adjustment of the
4369 breakpoint may cause target_read_memory() to be called and we do
4370 not want its scan of the location chain to find a breakpoint and
4371 location that's only been partially initialized. */
4372 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4374 b
->loc
= allocate_bp_location (b
, bptype
);
4375 b
->loc
->requested_address
= sal
.pc
;
4376 b
->loc
->address
= adjusted_address
;
4378 if (sal
.symtab
== NULL
)
4379 b
->source_file
= NULL
;
4381 b
->source_file
= savestring (sal
.symtab
->filename
,
4382 strlen (sal
.symtab
->filename
));
4383 b
->loc
->section
= sal
.section
;
4384 b
->line_number
= sal
.line
;
4386 set_breakpoint_location_function (b
->loc
);
4388 breakpoints_changed ();
4394 /* Note that the breakpoint object B describes a permanent breakpoint
4395 instruction, hard-wired into the inferior's code. */
4397 make_breakpoint_permanent (struct breakpoint
*b
)
4399 struct bp_location
*bl
;
4400 b
->enable_state
= bp_permanent
;
4402 /* By definition, permanent breakpoints are already present in the code.
4403 Mark all locations as inserted. For now, make_breakpoint_permanent
4404 is called in just one place, so it's hard to say if it's reasonable
4405 to have permanent breakpoint with multiple locations or not,
4406 but it's easy to implmement. */
4407 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4411 static struct breakpoint
*
4412 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4414 static int internal_breakpoint_number
= -1;
4415 struct symtab_and_line sal
;
4416 struct breakpoint
*b
;
4418 init_sal (&sal
); /* initialize to zeroes */
4421 sal
.section
= find_pc_overlay (sal
.pc
);
4423 b
= set_raw_breakpoint (sal
, type
);
4424 b
->number
= internal_breakpoint_number
--;
4425 b
->disposition
= disp_donttouch
;
4432 create_longjmp_breakpoint (char *func_name
)
4434 struct minimal_symbol
*m
;
4436 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4438 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4439 update_global_location_list (1);
4442 /* Call this routine when stepping and nexting to enable a breakpoint
4443 if we do a longjmp(). When we hit that breakpoint, call
4444 set_longjmp_resume_breakpoint() to figure out where we are going. */
4447 set_longjmp_breakpoint (void)
4449 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4451 create_longjmp_breakpoint ("longjmp");
4452 create_longjmp_breakpoint ("_longjmp");
4453 create_longjmp_breakpoint ("siglongjmp");
4454 create_longjmp_breakpoint ("_siglongjmp");
4458 /* Delete all longjmp breakpoints from THREAD. */
4460 delete_longjmp_breakpoint (int thread
)
4462 struct breakpoint
*b
, *temp
;
4464 ALL_BREAKPOINTS_SAFE (b
, temp
)
4465 if (b
->type
== bp_longjmp
)
4467 if (b
->thread
== thread
)
4468 delete_breakpoint (b
);
4473 create_overlay_event_breakpoint_1 (char *func_name
, struct objfile
*objfile
)
4475 struct breakpoint
*b
;
4476 struct minimal_symbol
*m
;
4478 if ((m
= lookup_minimal_symbol_text (func_name
, objfile
)) == NULL
)
4481 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4483 b
->addr_string
= xstrdup (func_name
);
4485 if (overlay_debugging
== ovly_auto
)
4487 b
->enable_state
= bp_enabled
;
4488 overlay_events_enabled
= 1;
4492 b
->enable_state
= bp_disabled
;
4493 overlay_events_enabled
= 0;
4495 update_global_location_list (1);
4499 create_overlay_event_breakpoint (char *func_name
)
4501 struct objfile
*objfile
;
4502 ALL_OBJFILES (objfile
)
4503 create_overlay_event_breakpoint_1 (func_name
, objfile
);
4507 enable_overlay_breakpoints (void)
4509 struct breakpoint
*b
;
4512 if (b
->type
== bp_overlay_event
)
4514 b
->enable_state
= bp_enabled
;
4515 update_global_location_list (1);
4516 overlay_events_enabled
= 1;
4521 disable_overlay_breakpoints (void)
4523 struct breakpoint
*b
;
4526 if (b
->type
== bp_overlay_event
)
4528 b
->enable_state
= bp_disabled
;
4529 update_global_location_list (0);
4530 overlay_events_enabled
= 0;
4535 create_thread_event_breakpoint (CORE_ADDR address
)
4537 struct breakpoint
*b
;
4539 b
= create_internal_breakpoint (address
, bp_thread_event
);
4541 b
->enable_state
= bp_enabled
;
4542 /* addr_string has to be used or breakpoint_re_set will delete me. */
4543 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4545 update_global_location_list_nothrow (1);
4551 remove_thread_event_breakpoints (void)
4553 struct breakpoint
*b
, *temp
;
4555 ALL_BREAKPOINTS_SAFE (b
, temp
)
4556 if (b
->type
== bp_thread_event
)
4557 delete_breakpoint (b
);
4560 struct captured_parse_breakpoint_args
4563 struct symtabs_and_lines
*sals_p
;
4564 char ***addr_string_p
;
4568 struct lang_and_radix
4576 remove_solib_event_breakpoints (void)
4578 struct breakpoint
*b
, *temp
;
4580 ALL_BREAKPOINTS_SAFE (b
, temp
)
4581 if (b
->type
== bp_shlib_event
)
4582 delete_breakpoint (b
);
4586 create_solib_event_breakpoint (CORE_ADDR address
)
4588 struct breakpoint
*b
;
4590 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4591 update_global_location_list_nothrow (1);
4595 /* Disable any breakpoints that are on code in shared libraries. Only
4596 apply to enabled breakpoints, disabled ones can just stay disabled. */
4599 disable_breakpoints_in_shlibs (void)
4601 struct bp_location
*loc
;
4602 int disabled_shlib_breaks
= 0;
4604 ALL_BP_LOCATIONS (loc
)
4606 struct breakpoint
*b
= loc
->owner
;
4607 /* We apply the check to all breakpoints, including disabled
4608 for those with loc->duplicate set. This is so that when breakpoint
4609 becomes enabled, or the duplicate is removed, gdb will try to insert
4610 all breakpoints. If we don't set shlib_disabled here, we'll try
4611 to insert those breakpoints and fail. */
4612 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4613 && !loc
->shlib_disabled
4615 && PC_SOLIB (loc
->address
)
4617 && solib_address (loc
->address
)
4621 loc
->shlib_disabled
= 1;
4626 /* Disable any breakpoints that are in in an unloaded shared library. Only
4627 apply to enabled breakpoints, disabled ones can just stay disabled. */
4630 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4632 struct bp_location
*loc
;
4633 int disabled_shlib_breaks
= 0;
4635 ALL_BP_LOCATIONS (loc
)
4637 struct breakpoint
*b
= loc
->owner
;
4638 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4639 || loc
->loc_type
== bp_loc_software_breakpoint
)
4640 && !loc
->shlib_disabled
)
4643 char *so_name
= PC_SOLIB (loc
->address
);
4645 char *so_name
= solib_address (loc
->address
);
4647 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4649 loc
->shlib_disabled
= 1;
4650 /* At this point, we cannot rely on remove_breakpoint
4651 succeeding so we must mark the breakpoint as not inserted
4652 to prevent future errors occurring in remove_breakpoints. */
4654 if (!disabled_shlib_breaks
)
4656 target_terminal_ours_for_output ();
4657 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4660 disabled_shlib_breaks
= 1;
4666 /* FORK & VFORK catchpoints. */
4668 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4671 insert_catch_fork (struct breakpoint
*b
)
4673 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4676 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4679 remove_catch_fork (struct breakpoint
*b
)
4681 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4684 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4688 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4690 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4693 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4695 static enum print_stop_action
4696 print_it_catch_fork (struct breakpoint
*b
)
4698 annotate_catchpoint (b
->number
);
4699 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4700 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4701 return PRINT_SRC_AND_LOC
;
4704 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4707 print_one_catch_fork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4709 struct value_print_options opts
;
4711 get_user_print_options (&opts
);
4713 /* Field 4, the address, is omitted (which makes the columns
4714 not line up too nicely with the headers, but the effect
4715 is relatively readable). */
4716 if (opts
.addressprint
)
4717 ui_out_field_skip (uiout
, "addr");
4719 ui_out_text (uiout
, "fork");
4720 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4722 ui_out_text (uiout
, ", process ");
4723 ui_out_field_int (uiout
, "what",
4724 ptid_get_pid (b
->forked_inferior_pid
));
4725 ui_out_spaces (uiout
, 1);
4729 /* Implement the "print_mention" breakpoint_ops method for fork
4733 print_mention_catch_fork (struct breakpoint
*b
)
4735 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4738 /* The breakpoint_ops structure to be used in fork catchpoints. */
4740 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4744 breakpoint_hit_catch_fork
,
4745 print_it_catch_fork
,
4746 print_one_catch_fork
,
4747 print_mention_catch_fork
4750 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4753 insert_catch_vfork (struct breakpoint
*b
)
4755 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4758 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4761 remove_catch_vfork (struct breakpoint
*b
)
4763 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4766 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4770 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4772 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4775 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4777 static enum print_stop_action
4778 print_it_catch_vfork (struct breakpoint
*b
)
4780 annotate_catchpoint (b
->number
);
4781 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4782 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4783 return PRINT_SRC_AND_LOC
;
4786 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4789 print_one_catch_vfork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4791 struct value_print_options opts
;
4793 get_user_print_options (&opts
);
4794 /* Field 4, the address, is omitted (which makes the columns
4795 not line up too nicely with the headers, but the effect
4796 is relatively readable). */
4797 if (opts
.addressprint
)
4798 ui_out_field_skip (uiout
, "addr");
4800 ui_out_text (uiout
, "vfork");
4801 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4803 ui_out_text (uiout
, ", process ");
4804 ui_out_field_int (uiout
, "what",
4805 ptid_get_pid (b
->forked_inferior_pid
));
4806 ui_out_spaces (uiout
, 1);
4810 /* Implement the "print_mention" breakpoint_ops method for vfork
4814 print_mention_catch_vfork (struct breakpoint
*b
)
4816 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4819 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4821 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4825 breakpoint_hit_catch_vfork
,
4826 print_it_catch_vfork
,
4827 print_one_catch_vfork
,
4828 print_mention_catch_vfork
4831 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4833 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4834 If COND_STRING is not NULL, then store it in the breakpoint.
4835 OPS, if not NULL, is the breakpoint_ops structure associated
4836 to the catchpoint. */
4838 static struct breakpoint
*
4839 create_catchpoint (int tempflag
, char *cond_string
,
4840 struct breakpoint_ops
*ops
)
4842 struct symtab_and_line sal
;
4843 struct breakpoint
*b
;
4850 b
= set_raw_breakpoint (sal
, bp_catchpoint
);
4851 set_breakpoint_count (breakpoint_count
+ 1);
4852 b
->number
= breakpoint_count
;
4854 b
->cond_string
= (cond_string
== NULL
) ?
4855 NULL
: savestring (cond_string
, strlen (cond_string
));
4857 b
->addr_string
= NULL
;
4858 b
->enable_state
= bp_enabled
;
4859 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4863 update_global_location_list (1);
4869 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4870 struct breakpoint_ops
*ops
)
4872 struct breakpoint
*b
= create_catchpoint (tempflag
, cond_string
, ops
);
4874 /* FIXME: We should put this information in a breakpoint private data
4876 b
->forked_inferior_pid
= null_ptid
;
4879 /* Exec catchpoints. */
4882 insert_catch_exec (struct breakpoint
*b
)
4884 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
4888 remove_catch_exec (struct breakpoint
*b
)
4890 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
4894 breakpoint_hit_catch_exec (struct breakpoint
*b
)
4896 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
4899 static enum print_stop_action
4900 print_it_catch_exec (struct breakpoint
*b
)
4902 annotate_catchpoint (b
->number
);
4903 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
4905 return PRINT_SRC_AND_LOC
;
4909 print_one_catch_exec (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4911 struct value_print_options opts
;
4913 get_user_print_options (&opts
);
4915 /* Field 4, the address, is omitted (which makes the columns
4916 not line up too nicely with the headers, but the effect
4917 is relatively readable). */
4918 if (opts
.addressprint
)
4919 ui_out_field_skip (uiout
, "addr");
4921 ui_out_text (uiout
, "exec");
4922 if (b
->exec_pathname
!= NULL
)
4924 ui_out_text (uiout
, ", program \"");
4925 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
4926 ui_out_text (uiout
, "\" ");
4931 print_mention_catch_exec (struct breakpoint
*b
)
4933 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
4936 static struct breakpoint_ops catch_exec_breakpoint_ops
=
4940 breakpoint_hit_catch_exec
,
4941 print_it_catch_exec
,
4942 print_one_catch_exec
,
4943 print_mention_catch_exec
4947 hw_breakpoint_used_count (void)
4949 struct breakpoint
*b
;
4954 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
4962 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4964 struct breakpoint
*b
;
4967 *other_type_used
= 0;
4970 if (breakpoint_enabled (b
))
4972 if (b
->type
== type
)
4974 else if ((b
->type
== bp_hardware_watchpoint
||
4975 b
->type
== bp_read_watchpoint
||
4976 b
->type
== bp_access_watchpoint
))
4977 *other_type_used
= 1;
4984 disable_watchpoints_before_interactive_call_start (void)
4986 struct breakpoint
*b
;
4990 if (((b
->type
== bp_watchpoint
)
4991 || (b
->type
== bp_hardware_watchpoint
)
4992 || (b
->type
== bp_read_watchpoint
)
4993 || (b
->type
== bp_access_watchpoint
))
4994 && breakpoint_enabled (b
))
4996 b
->enable_state
= bp_call_disabled
;
4997 update_global_location_list (0);
5003 enable_watchpoints_after_interactive_call_stop (void)
5005 struct breakpoint
*b
;
5009 if (((b
->type
== bp_watchpoint
)
5010 || (b
->type
== bp_hardware_watchpoint
)
5011 || (b
->type
== bp_read_watchpoint
)
5012 || (b
->type
== bp_access_watchpoint
))
5013 && (b
->enable_state
== bp_call_disabled
))
5015 b
->enable_state
= bp_enabled
;
5016 update_global_location_list (1);
5022 /* Set a breakpoint that will evaporate an end of command
5023 at address specified by SAL.
5024 Restrict it to frame FRAME if FRAME is nonzero. */
5027 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
5030 struct breakpoint
*b
;
5031 b
= set_raw_breakpoint (sal
, type
);
5032 b
->enable_state
= bp_enabled
;
5033 b
->disposition
= disp_donttouch
;
5034 b
->frame_id
= frame_id
;
5036 /* If we're debugging a multi-threaded program, then we
5037 want momentary breakpoints to be active in only a
5038 single thread of control. */
5039 if (in_thread_list (inferior_ptid
))
5040 b
->thread
= pid_to_thread_id (inferior_ptid
);
5042 update_global_location_list_nothrow (1);
5048 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
5050 struct symtab_and_line sal
;
5052 sal
= find_pc_line (pc
, 0);
5054 sal
.section
= find_pc_overlay (pc
);
5055 sal
.explicit_pc
= 1;
5057 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
5061 /* Tell the user we have just set a breakpoint B. */
5064 mention (struct breakpoint
*b
)
5067 struct cleanup
*old_chain
, *ui_out_chain
;
5068 struct ui_stream
*stb
;
5069 struct value_print_options opts
;
5071 get_user_print_options (&opts
);
5073 stb
= ui_out_stream_new (uiout
);
5074 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
5076 /* FIXME: This is misplaced; mention() is called by things (like
5077 hitting a watchpoint) other than breakpoint creation. It should
5078 be possible to clean this up and at the same time replace the
5079 random calls to breakpoint_changed with this hook. */
5080 observer_notify_breakpoint_created (b
->number
);
5082 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
5083 b
->ops
->print_mention (b
);
5088 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
5091 ui_out_text (uiout
, "Watchpoint ");
5092 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5093 ui_out_field_int (uiout
, "number", b
->number
);
5094 ui_out_text (uiout
, ": ");
5095 print_expression (b
->exp
, stb
->stream
);
5096 ui_out_field_stream (uiout
, "exp", stb
);
5097 do_cleanups (ui_out_chain
);
5099 case bp_hardware_watchpoint
:
5100 ui_out_text (uiout
, "Hardware watchpoint ");
5101 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5102 ui_out_field_int (uiout
, "number", b
->number
);
5103 ui_out_text (uiout
, ": ");
5104 print_expression (b
->exp
, stb
->stream
);
5105 ui_out_field_stream (uiout
, "exp", stb
);
5106 do_cleanups (ui_out_chain
);
5108 case bp_read_watchpoint
:
5109 ui_out_text (uiout
, "Hardware read watchpoint ");
5110 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
5111 ui_out_field_int (uiout
, "number", b
->number
);
5112 ui_out_text (uiout
, ": ");
5113 print_expression (b
->exp
, stb
->stream
);
5114 ui_out_field_stream (uiout
, "exp", stb
);
5115 do_cleanups (ui_out_chain
);
5117 case bp_access_watchpoint
:
5118 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
5119 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
5120 ui_out_field_int (uiout
, "number", b
->number
);
5121 ui_out_text (uiout
, ": ");
5122 print_expression (b
->exp
, stb
->stream
);
5123 ui_out_field_stream (uiout
, "exp", stb
);
5124 do_cleanups (ui_out_chain
);
5127 if (ui_out_is_mi_like_p (uiout
))
5132 if (b
->disposition
== disp_del
)
5133 printf_filtered (_("Temporary breakpoint"));
5135 printf_filtered (_("Breakpoint"));
5136 printf_filtered (_(" %d"), b
->number
);
5139 case bp_hardware_breakpoint
:
5140 if (ui_out_is_mi_like_p (uiout
))
5145 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
5149 case bp_catch_unload
:
5150 printf_filtered (_("Catchpoint %d (%s %s)"),
5152 (b
->type
== bp_catch_load
) ? "load" : "unload",
5153 (b
->dll_pathname
!= NULL
) ?
5154 b
->dll_pathname
: "<any library>");
5160 case bp_longjmp_resume
:
5161 case bp_step_resume
:
5163 case bp_watchpoint_scope
:
5164 case bp_shlib_event
:
5165 case bp_thread_event
:
5166 case bp_overlay_event
:
5172 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5176 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5180 if (opts
.addressprint
|| b
->source_file
== NULL
)
5182 printf_filtered (" at ");
5183 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5186 printf_filtered (": file %s, line %d.",
5187 b
->source_file
, b
->line_number
);
5191 struct bp_location
*loc
= b
->loc
;
5193 for (; loc
; loc
= loc
->next
)
5195 printf_filtered (" (%d locations)", n
);
5200 do_cleanups (old_chain
);
5201 if (ui_out_is_mi_like_p (uiout
))
5203 printf_filtered ("\n");
5207 static struct bp_location
*
5208 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5209 const struct symtab_and_line
*sal
)
5211 struct bp_location
*loc
, **tmp
;
5213 loc
= allocate_bp_location (b
, bptype
);
5214 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5217 loc
->requested_address
= sal
->pc
;
5218 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5220 loc
->section
= sal
->section
;
5222 set_breakpoint_location_function (loc
);
5227 /* Return 1 if LOC is pointing to a permanent breakpoint,
5228 return 0 otherwise. */
5231 bp_loc_is_permanent (struct bp_location
*loc
)
5235 const gdb_byte
*brk
;
5236 gdb_byte
*target_mem
;
5238 gdb_assert (loc
!= NULL
);
5240 addr
= loc
->address
;
5241 brk
= gdbarch_breakpoint_from_pc (current_gdbarch
, &addr
, &len
);
5243 target_mem
= alloca (len
);
5245 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5246 && memcmp (target_mem
, brk
, len
) == 0)
5254 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5255 as textual description of the location, and COND_STRING
5256 as condition expression. */
5259 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5261 enum bptype type
, enum bpdisp disposition
,
5262 int thread
, int ignore_count
,
5263 struct breakpoint_ops
*ops
, int from_tty
)
5265 struct breakpoint
*b
= NULL
;
5268 if (type
== bp_hardware_breakpoint
)
5270 int i
= hw_breakpoint_used_count ();
5271 int target_resources_ok
=
5272 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5274 if (target_resources_ok
== 0)
5275 error (_("No hardware breakpoint support in the target."));
5276 else if (target_resources_ok
< 0)
5277 error (_("Hardware breakpoints used exceeds limit."));
5280 for (i
= 0; i
< sals
.nelts
; ++i
)
5282 struct symtab_and_line sal
= sals
.sals
[i
];
5283 struct bp_location
*loc
;
5286 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5290 b
= set_raw_breakpoint (sal
, type
);
5291 set_breakpoint_count (breakpoint_count
+ 1);
5292 b
->number
= breakpoint_count
;
5295 b
->cond_string
= cond_string
;
5296 b
->ignore_count
= ignore_count
;
5297 b
->enable_state
= bp_enabled
;
5298 b
->disposition
= disposition
;
5304 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5307 if (bp_loc_is_permanent (loc
))
5308 make_breakpoint_permanent (b
);
5312 char *arg
= b
->cond_string
;
5313 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5315 error (_("Garbage %s follows condition"), arg
);
5320 b
->addr_string
= addr_string
;
5322 /* addr_string has to be used or breakpoint_re_set will delete
5324 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5330 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5331 elements to fill the void space. */
5332 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5334 int i
= index_to_remove
+1;
5335 int last_index
= sal
->nelts
-1;
5337 for (;i
<= last_index
; ++i
)
5338 sal
->sals
[i
-1] = sal
->sals
[i
];
5343 /* If appropriate, obtains all sals that correspond
5344 to the same file and line as SAL. This is done
5345 only if SAL does not have explicit PC and has
5346 line and file information. If we got just a single
5347 expanded sal, return the original.
5349 Otherwise, if SAL.explicit_line is not set, filter out
5350 all sals for which the name of enclosing function
5351 is different from SAL. This makes sure that if we have
5352 breakpoint originally set in template instantiation, say
5353 foo<int>(), we won't expand SAL to locations at the same
5354 line in all existing instantiations of 'foo'.
5357 struct symtabs_and_lines
5358 expand_line_sal_maybe (struct symtab_and_line sal
)
5360 struct symtabs_and_lines expanded
;
5361 CORE_ADDR original_pc
= sal
.pc
;
5362 char *original_function
= NULL
;
5366 /* If we have explicit pc, don't expand.
5367 If we have no line number, we can't expand. */
5368 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5371 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5372 expanded
.sals
[0] = sal
;
5377 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5379 expanded
= expand_line_sal (sal
);
5380 if (expanded
.nelts
== 1)
5382 /* We had one sal, we got one sal. Without futher
5383 processing, just return the original sal. */
5384 xfree (expanded
.sals
);
5386 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5387 sal
.pc
= original_pc
;
5388 expanded
.sals
[0] = sal
;
5392 if (!sal
.explicit_line
)
5394 CORE_ADDR func_addr
, func_end
;
5395 for (i
= 0; i
< expanded
.nelts
; ++i
)
5397 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5398 char *this_function
;
5399 if (find_pc_partial_function (pc
, &this_function
,
5400 &func_addr
, &func_end
))
5402 if (this_function
&&
5403 strcmp (this_function
, original_function
) != 0)
5405 remove_sal (&expanded
, i
);
5408 else if (func_addr
== pc
)
5410 /* We're at beginning of a function, and should
5412 struct symbol
*sym
= find_pc_function (pc
);
5414 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5417 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5424 if (expanded
.nelts
<= 1)
5426 /* This is un ugly workaround. If we get zero
5427 expanded sals then something is really wrong.
5428 Fix that by returnign the original sal. */
5429 xfree (expanded
.sals
);
5431 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5432 sal
.pc
= original_pc
;
5433 expanded
.sals
[0] = sal
;
5440 for (i
= 0; i
< expanded
.nelts
; ++i
)
5441 if (expanded
.sals
[i
].pc
== original_pc
)
5452 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5453 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5454 value. COND_STRING, if not NULL, specified the condition to be
5455 used for all breakpoints. Essentially the only case where
5456 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5457 function. In that case, it's still not possible to specify
5458 separate conditions for different overloaded functions, so
5459 we take just a single condition string.
5461 NOTE: If the function succeeds, the caller is expected to cleanup
5462 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5463 array contents). If the function fails (error() is called), the
5464 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5465 COND and SALS arrays and each of those arrays contents. */
5468 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5470 enum bptype type
, enum bpdisp disposition
,
5471 int thread
, int ignore_count
,
5472 struct breakpoint_ops
*ops
, int from_tty
)
5475 for (i
= 0; i
< sals
.nelts
; ++i
)
5477 struct symtabs_and_lines expanded
=
5478 expand_line_sal_maybe (sals
.sals
[i
]);
5480 create_breakpoint (expanded
, addr_string
[i
],
5481 cond_string
, type
, disposition
,
5482 thread
, ignore_count
, ops
, from_tty
);
5485 update_global_location_list (1);
5488 /* Parse ARG which is assumed to be a SAL specification possibly
5489 followed by conditionals. On return, SALS contains an array of SAL
5490 addresses found. ADDR_STRING contains a vector of (canonical)
5491 address strings. ARG points to the end of the SAL. */
5494 parse_breakpoint_sals (char **address
,
5495 struct symtabs_and_lines
*sals
,
5496 char ***addr_string
,
5499 char *addr_start
= *address
;
5500 *addr_string
= NULL
;
5501 /* If no arg given, or if first arg is 'if ', use the default
5503 if ((*address
) == NULL
5504 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5506 if (default_breakpoint_valid
)
5508 struct symtab_and_line sal
;
5509 init_sal (&sal
); /* initialize to zeroes */
5510 sals
->sals
= (struct symtab_and_line
*)
5511 xmalloc (sizeof (struct symtab_and_line
));
5512 sal
.pc
= default_breakpoint_address
;
5513 sal
.line
= default_breakpoint_line
;
5514 sal
.symtab
= default_breakpoint_symtab
;
5515 sal
.section
= find_pc_overlay (sal
.pc
);
5516 sals
->sals
[0] = sal
;
5520 error (_("No default breakpoint address now."));
5524 /* Force almost all breakpoints to be in terms of the
5525 current_source_symtab (which is decode_line_1's default). This
5526 should produce the results we want almost all of the time while
5527 leaving default_breakpoint_* alone.
5528 ObjC: However, don't match an Objective-C method name which
5529 may have a '+' or '-' succeeded by a '[' */
5531 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5533 if (default_breakpoint_valid
5535 || ((strchr ("+-", (*address
)[0]) != NULL
)
5536 && ((*address
)[1] != '['))))
5537 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5538 default_breakpoint_line
, addr_string
,
5541 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5542 addr_string
, not_found_ptr
);
5544 /* For any SAL that didn't have a canonical string, fill one in. */
5545 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5546 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5547 if (addr_start
!= (*address
))
5550 for (i
= 0; i
< sals
->nelts
; i
++)
5552 /* Add the string if not present. */
5553 if ((*addr_string
)[i
] == NULL
)
5554 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5560 /* Convert each SAL into a real PC. Verify that the PC can be
5561 inserted as a breakpoint. If it can't throw an error. */
5564 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5568 for (i
= 0; i
< sals
->nelts
; i
++)
5569 resolve_sal_pc (&sals
->sals
[i
]);
5573 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5575 struct captured_parse_breakpoint_args
*args
= data
;
5577 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5578 args
->not_found_ptr
);
5581 /* Given TOK, a string specification of condition and thread, as
5582 accepted by the 'break' command, extract the condition
5583 string and thread number and set *COND_STRING and *THREAD.
5584 PC identifies the context at which the condition should be parsed.
5585 If no condition is found, *COND_STRING is set to NULL.
5586 If no thread is found, *THREAD is set to -1. */
5588 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5589 char **cond_string
, int *thread
)
5591 *cond_string
= NULL
;
5597 char *cond_start
= NULL
;
5598 char *cond_end
= NULL
;
5599 while (*tok
== ' ' || *tok
== '\t')
5604 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5607 toklen
= end_tok
- tok
;
5609 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5611 tok
= cond_start
= end_tok
+ 1;
5612 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5614 *cond_string
= savestring (cond_start
,
5615 cond_end
- cond_start
);
5617 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5623 *thread
= strtol (tok
, &tok
, 0);
5625 error (_("Junk after thread keyword."));
5626 if (!valid_thread_id (*thread
))
5627 error (_("Unknown thread %d."), *thread
);
5630 error (_("Junk at end of arguments."));
5634 /* Set a breakpoint. This function is shared between
5635 CLI and MI functions for setting a breakpoint.
5636 This function has two major modes of operations,
5637 selected by the PARSE_CONDITION_AND_THREAD parameter.
5638 If non-zero, the function will parse arg, extracting
5639 breakpoint location, address and thread. Otherwise,
5640 ARG is just the location of breakpoint, with condition
5641 and thread specified by the COND_STRING and THREAD
5645 break_command_really (char *arg
, char *cond_string
, int thread
,
5646 int parse_condition_and_thread
,
5647 int tempflag
, int hardwareflag
,
5649 enum auto_boolean pending_break_support
,
5650 struct breakpoint_ops
*ops
,
5653 struct gdb_exception e
;
5654 struct symtabs_and_lines sals
;
5655 struct symtab_and_line pending_sal
;
5658 char *addr_start
= arg
;
5660 struct cleanup
*old_chain
;
5661 struct cleanup
*breakpoint_chain
= NULL
;
5662 struct captured_parse_breakpoint_args parse_args
;
5671 parse_args
.arg_p
= &arg
;
5672 parse_args
.sals_p
= &sals
;
5673 parse_args
.addr_string_p
= &addr_string
;
5674 parse_args
.not_found_ptr
= ¬_found
;
5676 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5677 &parse_args
, RETURN_MASK_ALL
);
5679 /* If caller is interested in rc value from parse, set value. */
5683 throw_exception (e
);
5687 case NOT_FOUND_ERROR
:
5689 /* If pending breakpoint support is turned off, throw
5692 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5693 throw_exception (e
);
5695 exception_print (gdb_stderr
, e
);
5697 /* If pending breakpoint support is auto query and the user
5698 selects no, then simply return the error code. */
5699 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5700 !nquery ("Make breakpoint pending on future shared library load? "))
5703 /* At this point, either the user was queried about setting
5704 a pending breakpoint and selected yes, or pending
5705 breakpoint behavior is on and thus a pending breakpoint
5706 is defaulted on behalf of the user. */
5707 copy_arg
= xstrdup (addr_start
);
5708 addr_string
= ©_arg
;
5710 sals
.sals
= &pending_sal
;
5715 throw_exception (e
);
5722 /* Create a chain of things that always need to be cleaned up. */
5723 old_chain
= make_cleanup (null_cleanup
, 0);
5727 /* Make sure that all storage allocated to SALS gets freed. */
5728 make_cleanup (xfree
, sals
.sals
);
5730 /* Cleanup the addr_string array but not its contents. */
5731 make_cleanup (xfree
, addr_string
);
5734 /* ----------------------------- SNIP -----------------------------
5735 Anything added to the cleanup chain beyond this point is assumed
5736 to be part of a breakpoint. If the breakpoint create succeeds
5737 then the memory is not reclaimed. */
5738 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5740 /* Mark the contents of the addr_string for cleanup. These go on
5741 the breakpoint_chain and only occure if the breakpoint create
5743 for (i
= 0; i
< sals
.nelts
; i
++)
5745 if (addr_string
[i
] != NULL
)
5746 make_cleanup (xfree
, addr_string
[i
]);
5749 /* Resolve all line numbers to PC's and verify that the addresses
5750 are ok for the target. */
5752 breakpoint_sals_to_pc (&sals
, addr_start
);
5754 /* Verify that condition can be parsed, before setting any
5755 breakpoints. Allocate a separate condition expression for each
5759 if (parse_condition_and_thread
)
5761 /* Here we only parse 'arg' to separate condition
5762 from thread number, so parsing in context of first
5763 sal is OK. When setting the breakpoint we'll
5764 re-parse it in context of each sal. */
5767 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5769 make_cleanup (xfree
, cond_string
);
5773 /* Create a private copy of condition string. */
5776 cond_string
= xstrdup (cond_string
);
5777 make_cleanup (xfree
, cond_string
);
5780 create_breakpoints (sals
, addr_string
, cond_string
,
5781 hardwareflag
? bp_hardware_breakpoint
5783 tempflag
? disp_del
: disp_donttouch
,
5784 thread
, ignore_count
, ops
, from_tty
);
5788 struct symtab_and_line sal
= {0};
5789 struct breakpoint
*b
;
5791 make_cleanup (xfree
, copy_arg
);
5793 b
= set_raw_breakpoint_without_location (hardwareflag
5794 ? bp_hardware_breakpoint
5796 set_breakpoint_count (breakpoint_count
+ 1);
5797 b
->number
= breakpoint_count
;
5799 b
->addr_string
= addr_string
[0];
5800 b
->cond_string
= NULL
;
5801 b
->ignore_count
= ignore_count
;
5802 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5803 b
->condition_not_parsed
= 1;
5806 update_global_location_list (1);
5811 warning (_("Multiple breakpoints were set.\n"
5812 "Use the \"delete\" command to delete unwanted breakpoints."));
5813 /* That's it. Discard the cleanups for data inserted into the
5815 discard_cleanups (breakpoint_chain
);
5816 /* But cleanup everything else. */
5817 do_cleanups (old_chain
);
5820 /* Set a breakpoint.
5821 ARG is a string describing breakpoint address,
5822 condition, and thread.
5823 FLAG specifies if a breakpoint is hardware on,
5824 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5828 break_command_1 (char *arg
, int flag
, int from_tty
)
5830 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5831 int tempflag
= flag
& BP_TEMPFLAG
;
5833 break_command_really (arg
,
5834 NULL
, 0, 1 /* parse arg */,
5835 tempflag
, hardwareflag
,
5836 0 /* Ignore count */,
5837 pending_break_support
,
5838 NULL
/* breakpoint_ops */,
5844 set_breakpoint (char *address
, char *condition
,
5845 int hardwareflag
, int tempflag
,
5846 int thread
, int ignore_count
,
5849 break_command_really (address
, condition
, thread
,
5850 0 /* condition and thread are valid. */,
5851 tempflag
, hardwareflag
,
5854 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5858 /* Adjust SAL to the first instruction past the function prologue.
5859 The end of the prologue is determined using the line table from
5860 the debugging information.
5862 If SAL is already past the prologue, then do nothing. */
5865 skip_prologue_sal (struct symtab_and_line
*sal
)
5867 struct symbol
*sym
= find_pc_function (sal
->pc
);
5868 struct symtab_and_line start_sal
;
5873 start_sal
= find_function_start_sal (sym
, 1);
5874 if (sal
->pc
< start_sal
.pc
)
5878 /* Helper function for break_command_1 and disassemble_command. */
5881 resolve_sal_pc (struct symtab_and_line
*sal
)
5885 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5887 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5888 error (_("No line %d in file \"%s\"."),
5889 sal
->line
, sal
->symtab
->filename
);
5892 /* If this SAL corresponds to a breakpoint inserted using
5893 a line number, then skip the function prologue if necessary. */
5894 if (sal
->explicit_line
)
5895 skip_prologue_sal (sal
);
5898 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5900 struct blockvector
*bv
;
5904 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5907 sym
= block_linkage_function (b
);
5910 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5911 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
5915 /* It really is worthwhile to have the section, so we'll just
5916 have to look harder. This case can be executed if we have
5917 line numbers but no functions (as can happen in assembly
5920 struct minimal_symbol
*msym
;
5922 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5924 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
5931 break_command (char *arg
, int from_tty
)
5933 break_command_1 (arg
, 0, from_tty
);
5937 tbreak_command (char *arg
, int from_tty
)
5939 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5943 hbreak_command (char *arg
, int from_tty
)
5945 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5949 thbreak_command (char *arg
, int from_tty
)
5951 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5955 stop_command (char *arg
, int from_tty
)
5957 printf_filtered (_("Specify the type of breakpoint to set.\n\
5958 Usage: stop in <function | address>\n\
5959 stop at <line>\n"));
5963 stopin_command (char *arg
, int from_tty
)
5967 if (arg
== (char *) NULL
)
5969 else if (*arg
!= '*')
5974 /* look for a ':'. If this is a line number specification, then
5975 say it is bad, otherwise, it should be an address or
5976 function/method name */
5977 while (*argptr
&& !hasColon
)
5979 hasColon
= (*argptr
== ':');
5984 badInput
= (*argptr
!= ':'); /* Not a class::method */
5986 badInput
= isdigit (*arg
); /* a simple line number */
5990 printf_filtered (_("Usage: stop in <function | address>\n"));
5992 break_command_1 (arg
, 0, from_tty
);
5996 stopat_command (char *arg
, int from_tty
)
6000 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
6007 /* look for a ':'. If there is a '::' then get out, otherwise
6008 it is probably a line number. */
6009 while (*argptr
&& !hasColon
)
6011 hasColon
= (*argptr
== ':');
6016 badInput
= (*argptr
== ':'); /* we have class::method */
6018 badInput
= !isdigit (*arg
); /* not a line number */
6022 printf_filtered (_("Usage: stop at <line>\n"));
6024 break_command_1 (arg
, 0, from_tty
);
6027 /* accessflag: hw_write: watch write,
6028 hw_read: watch read,
6029 hw_access: watch access (read or write) */
6031 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
6033 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
6034 struct symtab_and_line sal
;
6035 struct expression
*exp
;
6036 struct block
*exp_valid_block
;
6037 struct value
*val
, *mark
;
6038 struct frame_info
*frame
;
6039 struct frame_info
*prev_frame
= NULL
;
6040 char *exp_start
= NULL
;
6041 char *exp_end
= NULL
;
6042 char *tok
, *id_tok_start
, *end_tok
;
6044 char *cond_start
= NULL
;
6045 char *cond_end
= NULL
;
6046 struct expression
*cond
= NULL
;
6047 int i
, other_type_used
, target_resources_ok
= 0;
6048 enum bptype bp_type
;
6052 init_sal (&sal
); /* initialize to zeroes */
6054 /* Make sure that we actually have parameters to parse. */
6055 if (arg
!= NULL
&& arg
[0] != '\0')
6057 toklen
= strlen (arg
); /* Size of argument list. */
6059 /* Points tok to the end of the argument list. */
6060 tok
= arg
+ toklen
- 1;
6062 /* Go backwards in the parameters list. Skip the last parameter.
6063 If we're expecting a 'thread <thread_num>' parameter, this should
6064 be the thread identifier. */
6065 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6067 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6070 /* Points end_tok to the beginning of the last token. */
6071 id_tok_start
= tok
+ 1;
6073 /* Go backwards in the parameters list. Skip one more parameter.
6074 If we're expecting a 'thread <thread_num>' parameter, we should
6075 reach a "thread" token. */
6076 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6081 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6084 /* Move the pointer forward to skip the whitespace and
6085 calculate the length of the token. */
6087 toklen
= end_tok
- tok
;
6089 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
6091 /* At this point we've found a "thread" token, which means
6092 the user is trying to set a watchpoint that triggers
6093 only in a specific thread. */
6096 /* Extract the thread ID from the next token. */
6097 thread
= strtol (id_tok_start
, &endp
, 0);
6099 /* Check if the user provided a valid numeric value for the
6101 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
6102 error (_("Invalid thread ID specification %s."), id_tok_start
);
6104 /* Check if the thread actually exists. */
6105 if (!valid_thread_id (thread
))
6106 error (_("Unknown thread %d."), thread
);
6108 /* Truncate the string and get rid of the thread <thread_num>
6109 parameter before the parameter list is parsed by the
6110 evaluate_expression() function. */
6115 /* Parse the rest of the arguments. */
6116 innermost_block
= NULL
;
6118 exp
= parse_exp_1 (&arg
, 0, 0);
6120 exp_valid_block
= innermost_block
;
6121 mark
= value_mark ();
6122 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
6124 release_value (val
);
6127 while (*tok
== ' ' || *tok
== '\t')
6131 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6134 toklen
= end_tok
- tok
;
6135 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6137 tok
= cond_start
= end_tok
+ 1;
6138 cond
= parse_exp_1 (&tok
, 0, 0);
6142 error (_("Junk at end of command."));
6144 if (accessflag
== hw_read
)
6145 bp_type
= bp_read_watchpoint
;
6146 else if (accessflag
== hw_access
)
6147 bp_type
= bp_access_watchpoint
;
6149 bp_type
= bp_hardware_watchpoint
;
6151 mem_cnt
= can_use_hardware_watchpoint (val
);
6152 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
6153 error (_("Expression cannot be implemented with read/access watchpoint."));
6156 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
6157 target_resources_ok
=
6158 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
6160 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
6161 error (_("Target does not support this type of hardware watchpoint."));
6163 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
6164 error (_("Target can only support one kind of HW watchpoint at a time."));
6167 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6168 watchpoint could not be set. */
6169 if (!mem_cnt
|| target_resources_ok
<= 0)
6170 bp_type
= bp_watchpoint
;
6172 frame
= block_innermost_frame (exp_valid_block
);
6174 prev_frame
= get_prev_frame (frame
);
6178 /* If the expression is "local", then set up a "watchpoint scope"
6179 breakpoint at the point where we've left the scope of the watchpoint
6180 expression. Create the scope breakpoint before the watchpoint, so
6181 that we will encounter it first in bpstat_stop_status. */
6182 if (innermost_block
&& prev_frame
)
6184 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
6185 bp_watchpoint_scope
);
6187 scope_breakpoint
->enable_state
= bp_enabled
;
6189 /* Automatically delete the breakpoint when it hits. */
6190 scope_breakpoint
->disposition
= disp_del
;
6192 /* Only break in the proper frame (help with recursion). */
6193 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6195 /* Set the address at which we will stop. */
6196 scope_breakpoint
->loc
->requested_address
6197 = get_frame_pc (prev_frame
);
6198 scope_breakpoint
->loc
->address
6199 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6200 scope_breakpoint
->type
);
6203 /* Now set up the breakpoint. */
6204 b
= set_raw_breakpoint (sal
, bp_type
);
6205 set_breakpoint_count (breakpoint_count
+ 1);
6206 b
->number
= breakpoint_count
;
6208 b
->disposition
= disp_donttouch
;
6210 b
->exp_valid_block
= exp_valid_block
;
6211 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6214 b
->loc
->cond
= cond
;
6216 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6221 b
->watchpoint_frame
= get_frame_id (frame
);
6223 b
->watchpoint_frame
= null_frame_id
;
6225 if (scope_breakpoint
!= NULL
)
6227 /* The scope breakpoint is related to the watchpoint. We will
6228 need to act on them together. */
6229 b
->related_breakpoint
= scope_breakpoint
;
6230 scope_breakpoint
->related_breakpoint
= b
;
6233 value_free_to_mark (mark
);
6235 update_global_location_list (1);
6238 /* Return count of locations need to be watched and can be handled
6239 in hardware. If the watchpoint can not be handled
6240 in hardware return zero. */
6243 can_use_hardware_watchpoint (struct value
*v
)
6245 int found_memory_cnt
= 0;
6246 struct value
*head
= v
;
6248 /* Did the user specifically forbid us to use hardware watchpoints? */
6249 if (!can_use_hw_watchpoints
)
6252 /* Make sure that the value of the expression depends only upon
6253 memory contents, and values computed from them within GDB. If we
6254 find any register references or function calls, we can't use a
6255 hardware watchpoint.
6257 The idea here is that evaluating an expression generates a series
6258 of values, one holding the value of every subexpression. (The
6259 expression a*b+c has five subexpressions: a, b, a*b, c, and
6260 a*b+c.) GDB's values hold almost enough information to establish
6261 the criteria given above --- they identify memory lvalues,
6262 register lvalues, computed values, etcetera. So we can evaluate
6263 the expression, and then scan the chain of values that leaves
6264 behind to decide whether we can detect any possible change to the
6265 expression's final value using only hardware watchpoints.
6267 However, I don't think that the values returned by inferior
6268 function calls are special in any way. So this function may not
6269 notice that an expression involving an inferior function call
6270 can't be watched with hardware watchpoints. FIXME. */
6271 for (; v
; v
= value_next (v
))
6273 if (VALUE_LVAL (v
) == lval_memory
)
6276 /* A lazy memory lvalue is one that GDB never needed to fetch;
6277 we either just used its address (e.g., `a' in `a.b') or
6278 we never needed it at all (e.g., `a' in `a,b'). */
6282 /* Ahh, memory we actually used! Check if we can cover
6283 it with hardware watchpoints. */
6284 struct type
*vtype
= check_typedef (value_type (v
));
6286 /* We only watch structs and arrays if user asked for it
6287 explicitly, never if they just happen to appear in a
6288 middle of some value chain. */
6290 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6291 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6293 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6294 int len
= TYPE_LENGTH (value_type (v
));
6296 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6303 else if (VALUE_LVAL (v
) != not_lval
6304 && deprecated_value_modifiable (v
) == 0)
6305 return 0; /* ??? What does this represent? */
6306 else if (VALUE_LVAL (v
) == lval_register
)
6307 return 0; /* cannot watch a register with a HW watchpoint */
6310 /* The expression itself looks suitable for using a hardware
6311 watchpoint, but give the target machine a chance to reject it. */
6312 return found_memory_cnt
;
6316 watch_command_wrapper (char *arg
, int from_tty
)
6318 watch_command (arg
, from_tty
);
6322 watch_command (char *arg
, int from_tty
)
6324 watch_command_1 (arg
, hw_write
, from_tty
);
6328 rwatch_command_wrapper (char *arg
, int from_tty
)
6330 rwatch_command (arg
, from_tty
);
6334 rwatch_command (char *arg
, int from_tty
)
6336 watch_command_1 (arg
, hw_read
, from_tty
);
6340 awatch_command_wrapper (char *arg
, int from_tty
)
6342 awatch_command (arg
, from_tty
);
6346 awatch_command (char *arg
, int from_tty
)
6348 watch_command_1 (arg
, hw_access
, from_tty
);
6352 /* Helper routines for the until_command routine in infcmd.c. Here
6353 because it uses the mechanisms of breakpoints. */
6355 struct until_break_command_continuation_args
6357 struct breakpoint
*breakpoint
;
6358 struct breakpoint
*breakpoint2
;
6361 /* This function is called by fetch_inferior_event via the
6362 cmd_continuation pointer, to complete the until command. It takes
6363 care of cleaning up the temporary breakpoints set up by the until
6366 until_break_command_continuation (void *arg
)
6368 struct until_break_command_continuation_args
*a
= arg
;
6370 delete_breakpoint (a
->breakpoint
);
6372 delete_breakpoint (a
->breakpoint2
);
6376 until_break_command (char *arg
, int from_tty
, int anywhere
)
6378 struct symtabs_and_lines sals
;
6379 struct symtab_and_line sal
;
6380 struct frame_info
*frame
= get_selected_frame (NULL
);
6381 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6382 struct breakpoint
*breakpoint
;
6383 struct breakpoint
*breakpoint2
= NULL
;
6384 struct cleanup
*old_chain
;
6386 clear_proceed_status ();
6388 /* Set a breakpoint where the user wants it and at return from
6391 if (default_breakpoint_valid
)
6392 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6393 default_breakpoint_line
, (char ***) NULL
, NULL
);
6395 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6396 0, (char ***) NULL
, NULL
);
6398 if (sals
.nelts
!= 1)
6399 error (_("Couldn't get information on specified line."));
6402 xfree (sals
.sals
); /* malloc'd, so freed */
6405 error (_("Junk at end of arguments."));
6407 resolve_sal_pc (&sal
);
6410 /* If the user told us to continue until a specified location,
6411 we don't specify a frame at which we need to stop. */
6412 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6414 /* Otherwise, specify the current frame, because we want to stop only
6415 at the very same frame. */
6416 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6419 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6421 /* Keep within the current frame, or in frames called by the current
6425 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6426 sal
.pc
= get_frame_pc (prev_frame
);
6427 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6429 make_cleanup_delete_breakpoint (breakpoint2
);
6432 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6434 /* If we are running asynchronously, and proceed call above has actually
6435 managed to start the target, arrange for breakpoints to be
6436 deleted when the target stops. Otherwise, we're already stopped and
6437 delete breakpoints via cleanup chain. */
6439 if (target_can_async_p () && is_running (inferior_ptid
))
6441 struct until_break_command_continuation_args
*args
;
6442 args
= xmalloc (sizeof (*args
));
6444 args
->breakpoint
= breakpoint
;
6445 args
->breakpoint2
= breakpoint2
;
6447 discard_cleanups (old_chain
);
6448 add_continuation (inferior_thread (),
6449 until_break_command_continuation
, args
,
6453 do_cleanups (old_chain
);
6457 ep_skip_leading_whitespace (char **s
)
6459 if ((s
== NULL
) || (*s
== NULL
))
6461 while (isspace (**s
))
6465 /* This function attempts to parse an optional "if <cond>" clause
6466 from the arg string. If one is not found, it returns NULL.
6468 Else, it returns a pointer to the condition string. (It does not
6469 attempt to evaluate the string against a particular block.) And,
6470 it updates arg to point to the first character following the parsed
6471 if clause in the arg string. */
6474 ep_parse_optional_if_clause (char **arg
)
6478 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6481 /* Skip the "if" keyword. */
6484 /* Skip any extra leading whitespace, and record the start of the
6485 condition string. */
6486 ep_skip_leading_whitespace (arg
);
6489 /* Assume that the condition occupies the remainder of the arg string. */
6490 (*arg
) += strlen (cond_string
);
6495 /* This function attempts to parse an optional filename from the arg
6496 string. If one is not found, it returns NULL.
6498 Else, it returns a pointer to the parsed filename. (This function
6499 makes no attempt to verify that a file of that name exists, or is
6500 accessible.) And, it updates arg to point to the first character
6501 following the parsed filename in the arg string.
6503 Note that clients needing to preserve the returned filename for
6504 future access should copy it to their own buffers. */
6506 ep_parse_optional_filename (char **arg
)
6508 static char filename
[1024];
6513 if ((*arg_p
== '\0') || isspace (*arg_p
))
6531 /* Commands to deal with catching events, such as signals, exceptions,
6532 process start/exit, etc. */
6536 catch_fork_temporary
, catch_vfork_temporary
,
6537 catch_fork_permanent
, catch_vfork_permanent
6542 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6544 char *cond_string
= NULL
;
6545 catch_fork_kind fork_kind
;
6548 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6549 tempflag
= (fork_kind
== catch_fork_temporary
6550 || fork_kind
== catch_vfork_temporary
);
6554 ep_skip_leading_whitespace (&arg
);
6556 /* The allowed syntax is:
6558 catch [v]fork if <cond>
6560 First, check if there's an if clause. */
6561 cond_string
= ep_parse_optional_if_clause (&arg
);
6563 if ((*arg
!= '\0') && !isspace (*arg
))
6564 error (_("Junk at end of arguments."));
6566 /* If this target supports it, create a fork or vfork catchpoint
6567 and enable reporting of such events. */
6570 case catch_fork_temporary
:
6571 case catch_fork_permanent
:
6572 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6573 &catch_fork_breakpoint_ops
);
6575 case catch_vfork_temporary
:
6576 case catch_vfork_permanent
:
6577 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6578 &catch_vfork_breakpoint_ops
);
6581 error (_("unsupported or unknown fork kind; cannot catch it"));
6587 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6590 char *cond_string
= NULL
;
6592 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6596 ep_skip_leading_whitespace (&arg
);
6598 /* The allowed syntax is:
6600 catch exec if <cond>
6602 First, check if there's an if clause. */
6603 cond_string
= ep_parse_optional_if_clause (&arg
);
6605 if ((*arg
!= '\0') && !isspace (*arg
))
6606 error (_("Junk at end of arguments."));
6608 /* If this target supports it, create an exec catchpoint
6609 and enable reporting of such events. */
6610 create_catchpoint (tempflag
, cond_string
, &catch_exec_breakpoint_ops
);
6614 catch_load_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6617 char *dll_pathname
= NULL
;
6618 char *cond_string
= NULL
;
6620 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6624 ep_skip_leading_whitespace (&arg
);
6626 /* The allowed syntax is:
6628 catch load if <cond>
6629 catch load <filename>
6630 catch load <filename> if <cond>
6632 The user is not allowed to specify the <filename> after an
6635 We'll ignore the pathological case of a file named "if".
6637 First, check if there's an if clause. If so, then there
6638 cannot be a filename. */
6639 cond_string
= ep_parse_optional_if_clause (&arg
);
6641 /* If there was an if clause, then there cannot be a filename.
6642 Else, there might be a filename and an if clause. */
6643 if (cond_string
== NULL
)
6645 dll_pathname
= ep_parse_optional_filename (&arg
);
6646 ep_skip_leading_whitespace (&arg
);
6647 cond_string
= ep_parse_optional_if_clause (&arg
);
6650 if ((*arg
!= '\0') && !isspace (*arg
))
6651 error (_("Junk at end of arguments."));
6653 /* Create a load breakpoint that only triggers when a load of
6654 the specified dll (or any dll, if no pathname was specified)
6656 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6657 dll_pathname
, cond_string
);
6661 catch_unload_command_1 (char *arg
, int from_tty
,
6662 struct cmd_list_element
*command
)
6665 char *dll_pathname
= NULL
;
6666 char *cond_string
= NULL
;
6668 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6672 ep_skip_leading_whitespace (&arg
);
6674 /* The allowed syntax is:
6676 catch unload if <cond>
6677 catch unload <filename>
6678 catch unload <filename> if <cond>
6680 The user is not allowed to specify the <filename> after an
6683 We'll ignore the pathological case of a file named "if".
6685 First, check if there's an if clause. If so, then there
6686 cannot be a filename. */
6687 cond_string
= ep_parse_optional_if_clause (&arg
);
6689 /* If there was an if clause, then there cannot be a filename.
6690 Else, there might be a filename and an if clause. */
6691 if (cond_string
== NULL
)
6693 dll_pathname
= ep_parse_optional_filename (&arg
);
6694 ep_skip_leading_whitespace (&arg
);
6695 cond_string
= ep_parse_optional_if_clause (&arg
);
6698 if ((*arg
!= '\0') && !isspace (*arg
))
6699 error (_("Junk at end of arguments."));
6701 /* Create an unload breakpoint that only triggers when an unload of
6702 the specified dll (or any dll, if no pathname was specified)
6704 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6705 dll_pathname
, cond_string
);
6708 static enum print_stop_action
6709 print_exception_catchpoint (struct breakpoint
*b
)
6711 int bp_temp
, bp_throw
;
6713 annotate_catchpoint (b
->number
);
6715 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6716 if (b
->loc
->address
!= b
->loc
->requested_address
)
6717 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6720 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6722 bp_temp
? "Temporary catchpoint "
6724 if (!ui_out_is_mi_like_p (uiout
))
6725 ui_out_field_int (uiout
, "bkptno", b
->number
);
6727 bp_throw
? " (exception thrown), "
6728 : " (exception caught), ");
6729 if (ui_out_is_mi_like_p (uiout
))
6731 ui_out_field_string (uiout
, "reason",
6732 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6733 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6734 ui_out_field_int (uiout
, "bkptno", b
->number
);
6736 return PRINT_SRC_AND_LOC
;
6740 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6742 struct value_print_options opts
;
6743 get_user_print_options (&opts
);
6744 if (opts
.addressprint
)
6747 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6748 ui_out_field_string (uiout
, "addr", "<PENDING>");
6750 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6754 *last_addr
= b
->loc
->address
;
6755 if (strstr (b
->addr_string
, "throw") != NULL
)
6756 ui_out_field_string (uiout
, "what", "exception throw");
6758 ui_out_field_string (uiout
, "what", "exception catch");
6762 print_mention_exception_catchpoint (struct breakpoint
*b
)
6767 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6768 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6769 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6770 : _("Catchpoint "));
6771 ui_out_field_int (uiout
, "bkptno", b
->number
);
6772 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6776 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6779 NULL
, /* breakpoint_hit */
6780 print_exception_catchpoint
,
6781 print_one_exception_catchpoint
,
6782 print_mention_exception_catchpoint
6786 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6787 enum exception_event_kind ex_event
, int from_tty
)
6789 char *trigger_func_name
;
6791 if (ex_event
== EX_EVENT_CATCH
)
6792 trigger_func_name
= "__cxa_begin_catch";
6794 trigger_func_name
= "__cxa_throw";
6796 break_command_really (trigger_func_name
, cond_string
, -1,
6797 0 /* condition and thread are valid. */,
6800 AUTO_BOOLEAN_TRUE
/* pending */,
6801 &gnu_v3_exception_catchpoint_ops
, from_tty
);
6806 /* Deal with "catch catch" and "catch throw" commands */
6809 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6810 int tempflag
, int from_tty
)
6812 char *cond_string
= NULL
;
6813 struct symtab_and_line
*sal
= NULL
;
6817 ep_skip_leading_whitespace (&arg
);
6819 cond_string
= ep_parse_optional_if_clause (&arg
);
6821 if ((*arg
!= '\0') && !isspace (*arg
))
6822 error (_("Junk at end of arguments."));
6824 if ((ex_event
!= EX_EVENT_THROW
) &&
6825 (ex_event
!= EX_EVENT_CATCH
))
6826 error (_("Unsupported or unknown exception event; cannot catch it"));
6828 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6831 warning (_("Unsupported with this platform/compiler combination."));
6834 /* Implementation of "catch catch" command. */
6837 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6839 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6840 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6843 /* Implementation of "catch throw" command. */
6846 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6848 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6849 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6852 /* Create a breakpoint struct for Ada exception catchpoints. */
6855 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6859 struct expression
*cond
,
6860 struct breakpoint_ops
*ops
,
6864 struct breakpoint
*b
;
6868 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6869 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6870 version for exception catchpoints, because two catchpoints
6871 used for different exception names will use the same address.
6872 In this case, a "breakpoint ... also set at..." warning is
6873 unproductive. Besides. the warning phrasing is also a bit
6874 inapropriate, we should use the word catchpoint, and tell
6875 the user what type of catchpoint it is. The above is good
6876 enough for now, though. */
6879 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6880 set_breakpoint_count (breakpoint_count
+ 1);
6882 b
->enable_state
= bp_enabled
;
6883 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6884 b
->number
= breakpoint_count
;
6885 b
->ignore_count
= 0;
6886 b
->loc
->cond
= cond
;
6887 b
->addr_string
= addr_string
;
6888 b
->language
= language_ada
;
6889 b
->cond_string
= cond_string
;
6890 b
->exp_string
= exp_string
;
6895 update_global_location_list (1);
6898 /* Implement the "catch exception" command. */
6901 catch_ada_exception_command (char *arg
, int from_tty
,
6902 struct cmd_list_element
*command
)
6905 struct symtab_and_line sal
;
6907 char *addr_string
= NULL
;
6908 char *exp_string
= NULL
;
6909 char *cond_string
= NULL
;
6910 struct expression
*cond
= NULL
;
6911 struct breakpoint_ops
*ops
= NULL
;
6913 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6917 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6918 &cond_string
, &cond
, &ops
);
6919 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6920 cond_string
, cond
, ops
, tempflag
,
6924 /* Implement the "catch assert" command. */
6927 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6930 struct symtab_and_line sal
;
6931 char *addr_string
= NULL
;
6932 struct breakpoint_ops
*ops
= NULL
;
6934 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6938 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6939 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6940 tempflag
, from_tty
);
6944 catch_command (char *arg
, int from_tty
)
6946 error (_("Catch requires an event name."));
6951 tcatch_command (char *arg
, int from_tty
)
6953 error (_("Catch requires an event name."));
6956 /* Delete breakpoints by address or line. */
6959 clear_command (char *arg
, int from_tty
)
6961 struct breakpoint
*b
;
6962 VEC(breakpoint_p
) *found
= 0;
6965 struct symtabs_and_lines sals
;
6966 struct symtab_and_line sal
;
6971 sals
= decode_line_spec (arg
, 1);
6976 sals
.sals
= (struct symtab_and_line
*)
6977 xmalloc (sizeof (struct symtab_and_line
));
6978 make_cleanup (xfree
, sals
.sals
);
6979 init_sal (&sal
); /* initialize to zeroes */
6980 sal
.line
= default_breakpoint_line
;
6981 sal
.symtab
= default_breakpoint_symtab
;
6982 sal
.pc
= default_breakpoint_address
;
6983 if (sal
.symtab
== 0)
6984 error (_("No source file specified."));
6992 /* We don't call resolve_sal_pc here. That's not
6993 as bad as it seems, because all existing breakpoints
6994 typically have both file/line and pc set. So, if
6995 clear is given file/line, we can match this to existing
6996 breakpoint without obtaining pc at all.
6998 We only support clearing given the address explicitly
6999 present in breakpoint table. Say, we've set breakpoint
7000 at file:line. There were several PC values for that file:line,
7001 due to optimization, all in one block.
7002 We've picked one PC value. If "clear" is issued with another
7003 PC corresponding to the same file:line, the breakpoint won't
7004 be cleared. We probably can still clear the breakpoint, but
7005 since the other PC value is never presented to user, user
7006 can only find it by guessing, and it does not seem important
7009 /* For each line spec given, delete bps which correspond
7010 to it. Do it in two passes, solely to preserve the current
7011 behavior that from_tty is forced true if we delete more than
7015 for (i
= 0; i
< sals
.nelts
; i
++)
7017 /* If exact pc given, clear bpts at that pc.
7018 If line given (pc == 0), clear all bpts on specified line.
7019 If defaulting, clear all bpts on default line
7022 defaulting sal.pc != 0 tests to do
7027 1 0 <can't happen> */
7031 /* Find all matching breakpoints and add them to
7036 /* Are we going to delete b? */
7037 if (b
->type
!= bp_none
7038 && b
->type
!= bp_watchpoint
7039 && b
->type
!= bp_hardware_watchpoint
7040 && b
->type
!= bp_read_watchpoint
7041 && b
->type
!= bp_access_watchpoint
)
7043 struct bp_location
*loc
= b
->loc
;
7044 for (; loc
; loc
= loc
->next
)
7046 int pc_match
= sal
.pc
7047 && (loc
->address
== sal
.pc
)
7048 && (!section_is_overlay (loc
->section
)
7049 || loc
->section
== sal
.section
);
7050 int line_match
= ((default_match
|| (0 == sal
.pc
))
7051 && b
->source_file
!= NULL
7052 && sal
.symtab
!= NULL
7053 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
7054 && b
->line_number
== sal
.line
);
7055 if (pc_match
|| line_match
)
7064 VEC_safe_push(breakpoint_p
, found
, b
);
7067 /* Now go thru the 'found' chain and delete them. */
7068 if (VEC_empty(breakpoint_p
, found
))
7071 error (_("No breakpoint at %s."), arg
);
7073 error (_("No breakpoint at this line."));
7076 if (VEC_length(breakpoint_p
, found
) > 1)
7077 from_tty
= 1; /* Always report if deleted more than one */
7080 if (VEC_length(breakpoint_p
, found
) == 1)
7081 printf_unfiltered (_("Deleted breakpoint "));
7083 printf_unfiltered (_("Deleted breakpoints "));
7085 breakpoints_changed ();
7087 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
7090 printf_unfiltered ("%d ", b
->number
);
7091 delete_breakpoint (b
);
7094 putchar_unfiltered ('\n');
7097 /* Delete breakpoint in BS if they are `delete' breakpoints and
7098 all breakpoints that are marked for deletion, whether hit or not.
7099 This is called after any breakpoint is hit, or after errors. */
7102 breakpoint_auto_delete (bpstat bs
)
7104 struct breakpoint
*b
, *temp
;
7106 for (; bs
; bs
= bs
->next
)
7107 if (bs
->breakpoint_at
7108 && bs
->breakpoint_at
->owner
7109 && bs
->breakpoint_at
->owner
->disposition
== disp_del
7111 delete_breakpoint (bs
->breakpoint_at
->owner
);
7113 ALL_BREAKPOINTS_SAFE (b
, temp
)
7115 if (b
->disposition
== disp_del_at_next_stop
)
7116 delete_breakpoint (b
);
7120 /* If SHOULD_INSERT is true, do not insert any breakpoint locations
7121 into the inferior, only remove already-inserted locations that no
7122 longer should be inserted. Functions that delete a breakpoint or
7123 breakpoints should pass false, so that deleting a breakpoint
7124 doesn't have the side effect of inserting the locations of other
7125 breakpoints that are marked not-inserted, but should_be_inserted
7126 returns true on them.
7128 This behaviour is useful is situations close to tear-down -- e.g.,
7129 after an exec, while the target still has execution, but breakpoint
7130 shadows of the previous executable image should *NOT* be restored
7131 to the new image; or before detaching, where the target still has
7132 execution and wants to delete breakpoints from GDB's lists, and all
7133 breakpoints had already been removed from the inferior. */
7136 update_global_location_list (int should_insert
)
7138 struct breakpoint
*b
;
7139 struct bp_location
**next
= &bp_location_chain
;
7140 struct bp_location
*loc
;
7141 struct bp_location
*loc2
;
7142 struct gdb_exception e
;
7143 VEC(bp_location_p
) *old_locations
= NULL
;
7147 /* Store old locations for future reference. */
7148 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7149 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7151 bp_location_chain
= NULL
;
7154 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7157 next
= &(loc
->global_next
);
7162 /* Identify bp_location instances that are no longer present in the new
7163 list, and therefore should be freed. Note that it's not necessary that
7164 those locations should be removed from inferior -- if there's another
7165 location at the same address (previously marked as duplicate),
7166 we don't need to remove/insert the location. */
7167 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7169 /* Tells if 'loc' is found amoung the new locations. If not, we
7171 int found_object
= 0;
7172 /* Tells if the location should remain inserted in the target. */
7173 int keep_in_target
= 0;
7175 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7182 /* If this location is no longer present, and inserted, look if there's
7183 maybe a new location at the same address. If so, mark that one
7184 inserted, and don't remove this one. This is needed so that we
7185 don't have a time window where a breakpoint at certain location is not
7190 /* If the location is inserted now, we might have to remove it. */
7192 if (found_object
&& should_be_inserted (loc
))
7194 /* The location is still present in the location list, and still
7195 should be inserted. Don't do anything. */
7200 /* The location is either no longer present, or got disabled.
7201 See if there's another location at the same address, in which
7202 case we don't need to remove this one from the target. */
7203 if (breakpoint_address_is_meaningful (loc
->owner
))
7204 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7206 /* For the sake of should_insert_location. The
7207 call to check_duplicates will fix up this later. */
7208 loc2
->duplicate
= 0;
7209 if (should_be_inserted (loc2
)
7210 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7213 loc2
->target_info
= loc
->target_info
;
7220 if (!keep_in_target
)
7222 if (remove_breakpoint (loc
, mark_uninserted
))
7224 /* This is just about all we can do. We could keep this
7225 location on the global list, and try to remove it next
7226 time, but there's no particular reason why we will
7229 Note that at this point, loc->owner is still valid,
7230 as delete_breakpoint frees the breakpoint only
7231 after calling us. */
7232 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7233 loc
->owner
->number
);
7241 if (removed
&& non_stop
)
7243 /* This location was removed from the targets. In non-stop mode,
7244 a race condition is possible where we've removed a breakpoint,
7245 but stop events for that breakpoint are already queued and will
7246 arrive later. To suppress spurious SIGTRAPs reported to user,
7247 we keep this breakpoint location for a bit, and will retire it
7248 after we see 3 * thread_count events.
7249 The theory here is that reporting of events should,
7250 "on the average", be fair, so after that many event we'll see
7251 events from all threads that have anything of interest, and no
7252 longer need to keep this breakpoint. This is just a
7253 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7254 which is usability issue, but not a correctness problem. */
7255 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7258 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
7261 free_bp_location (loc
);
7267 check_duplicates (b
);
7270 if (breakpoints_always_inserted_mode () && should_insert
7271 && (target_has_execution
7272 || (gdbarch_has_global_solist (target_gdbarch
)
7273 && target_supports_multi_process ())))
7274 insert_breakpoint_locations ();
7278 breakpoint_retire_moribund (void)
7280 struct bp_location
*loc
;
7283 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7284 if (--(loc
->events_till_retirement
) == 0)
7286 free_bp_location (loc
);
7287 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7293 update_global_location_list_nothrow (int inserting
)
7295 struct gdb_exception e
;
7296 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7297 update_global_location_list (inserting
);
7300 /* Clear BPT from a BPS. */
7302 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7305 for (bs
= bps
; bs
; bs
= bs
->next
)
7306 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7308 bs
->breakpoint_at
= NULL
;
7310 /* bs->commands will be freed later. */
7314 /* Callback for iterate_over_threads. */
7316 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7318 struct breakpoint
*bpt
= data
;
7319 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7323 /* Delete a breakpoint and clean up all traces of it in the data
7327 delete_breakpoint (struct breakpoint
*bpt
)
7329 struct breakpoint
*b
;
7330 struct bp_location
*loc
, *next
;
7332 gdb_assert (bpt
!= NULL
);
7334 /* Has this bp already been deleted? This can happen because multiple
7335 lists can hold pointers to bp's. bpstat lists are especial culprits.
7337 One example of this happening is a watchpoint's scope bp. When the
7338 scope bp triggers, we notice that the watchpoint is out of scope, and
7339 delete it. We also delete its scope bp. But the scope bp is marked
7340 "auto-deleting", and is already on a bpstat. That bpstat is then
7341 checked for auto-deleting bp's, which are deleted.
7343 A real solution to this problem might involve reference counts in bp's,
7344 and/or giving them pointers back to their referencing bpstat's, and
7345 teaching delete_breakpoint to only free a bp's storage when no more
7346 references were extent. A cheaper bandaid was chosen. */
7347 if (bpt
->type
== bp_none
)
7350 observer_notify_breakpoint_deleted (bpt
->number
);
7352 if (breakpoint_chain
== bpt
)
7353 breakpoint_chain
= bpt
->next
;
7358 b
->next
= bpt
->next
;
7362 free_command_lines (&bpt
->commands
);
7363 if (bpt
->cond_string
!= NULL
)
7364 xfree (bpt
->cond_string
);
7365 if (bpt
->addr_string
!= NULL
)
7366 xfree (bpt
->addr_string
);
7367 if (bpt
->exp
!= NULL
)
7369 if (bpt
->exp_string
!= NULL
)
7370 xfree (bpt
->exp_string
);
7371 if (bpt
->val
!= NULL
)
7372 value_free (bpt
->val
);
7373 if (bpt
->source_file
!= NULL
)
7374 xfree (bpt
->source_file
);
7375 if (bpt
->dll_pathname
!= NULL
)
7376 xfree (bpt
->dll_pathname
);
7377 if (bpt
->triggered_dll_pathname
!= NULL
)
7378 xfree (bpt
->triggered_dll_pathname
);
7379 if (bpt
->exec_pathname
!= NULL
)
7380 xfree (bpt
->exec_pathname
);
7382 /* Be sure no bpstat's are pointing at it after it's been freed. */
7383 /* FIXME, how can we find all bpstat's?
7384 We just check stop_bpstat for now. Note that we cannot just
7385 remove bpstats pointing at bpt from the stop_bpstat list
7386 entirely, as breakpoint commands are associated with the bpstat;
7387 if we remove it here, then the later call to
7388 bpstat_do_actions (&stop_bpstat);
7389 in event-top.c won't do anything, and temporary breakpoints
7390 with commands won't work. */
7392 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7394 /* Now that breakpoint is removed from breakpoint
7395 list, update the global location list. This
7396 will remove locations that used to belong to
7397 this breakpoint. Do this before freeing
7398 the breakpoint itself, since remove_breakpoint
7399 looks at location's owner. It might be better
7400 design to have location completely self-contained,
7401 but it's not the case now. */
7402 update_global_location_list (0);
7405 /* On the chance that someone will soon try again to delete this same
7406 bp, we mark it as deleted before freeing its storage. */
7407 bpt
->type
= bp_none
;
7413 do_delete_breakpoint_cleanup (void *b
)
7415 delete_breakpoint (b
);
7419 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7421 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7425 delete_command (char *arg
, int from_tty
)
7427 struct breakpoint
*b
, *temp
;
7433 int breaks_to_delete
= 0;
7435 /* Delete all breakpoints if no argument.
7436 Do not delete internal or call-dummy breakpoints, these
7437 have to be deleted with an explicit breakpoint number argument. */
7440 if (b
->type
!= bp_call_dummy
&&
7441 b
->type
!= bp_shlib_event
&&
7442 b
->type
!= bp_thread_event
&&
7443 b
->type
!= bp_overlay_event
&&
7446 breaks_to_delete
= 1;
7451 /* Ask user only if there are some breakpoints to delete. */
7453 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7455 ALL_BREAKPOINTS_SAFE (b
, temp
)
7457 if (b
->type
!= bp_call_dummy
&&
7458 b
->type
!= bp_shlib_event
&&
7459 b
->type
!= bp_thread_event
&&
7460 b
->type
!= bp_overlay_event
&&
7462 delete_breakpoint (b
);
7467 map_breakpoint_numbers (arg
, delete_breakpoint
);
7471 all_locations_are_pending (struct bp_location
*loc
)
7473 for (; loc
; loc
= loc
->next
)
7474 if (!loc
->shlib_disabled
)
7479 /* Subroutine of update_breakpoint_locations to simplify it.
7480 Return non-zero if multiple fns in list LOC have the same name.
7481 Null names are ignored. */
7484 ambiguous_names_p (struct bp_location
*loc
)
7486 struct bp_location
*l
;
7487 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7488 (int (*) (const void *, const void *)) streq
,
7489 NULL
, xcalloc
, xfree
);
7491 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7494 const char *name
= l
->function_name
;
7496 /* Allow for some names to be NULL, ignore them. */
7500 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7502 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7517 update_breakpoint_locations (struct breakpoint
*b
,
7518 struct symtabs_and_lines sals
)
7522 struct bp_location
*existing_locations
= b
->loc
;
7524 /* If there's no new locations, and all existing locations
7525 are pending, don't do anything. This optimizes
7526 the common case where all locations are in the same
7527 shared library, that was unloaded. We'd like to
7528 retain the location, so that when the library
7529 is loaded again, we don't loose the enabled/disabled
7530 status of the individual locations. */
7531 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7536 for (i
= 0; i
< sals
.nelts
; ++i
)
7538 struct bp_location
*new_loc
=
7539 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7541 /* Reparse conditions, they might contain references to the
7543 if (b
->cond_string
!= NULL
)
7545 struct gdb_exception e
;
7548 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7550 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7555 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7556 b
->number
, e
.message
);
7557 new_loc
->enabled
= 0;
7561 if (b
->source_file
!= NULL
)
7562 xfree (b
->source_file
);
7563 if (sals
.sals
[i
].symtab
== NULL
)
7564 b
->source_file
= NULL
;
7567 savestring (sals
.sals
[i
].symtab
->filename
,
7568 strlen (sals
.sals
[i
].symtab
->filename
));
7570 if (b
->line_number
== 0)
7571 b
->line_number
= sals
.sals
[i
].line
;
7574 /* Update locations of permanent breakpoints. */
7575 if (b
->enable_state
== bp_permanent
)
7576 make_breakpoint_permanent (b
);
7578 /* If possible, carry over 'disable' status from existing breakpoints. */
7580 struct bp_location
*e
= existing_locations
;
7581 /* If there are multiple breakpoints with the same function name,
7582 e.g. for inline functions, comparing function names won't work.
7583 Instead compare pc addresses; this is just a heuristic as things
7584 may have moved, but in practice it gives the correct answer
7585 often enough until a better solution is found. */
7586 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7588 for (; e
; e
= e
->next
)
7590 if (!e
->enabled
&& e
->function_name
)
7592 struct bp_location
*l
= b
->loc
;
7593 if (have_ambiguous_names
)
7595 for (; l
; l
= l
->next
)
7596 if (e
->address
== l
->address
)
7604 for (; l
; l
= l
->next
)
7605 if (l
->function_name
7606 && strcmp (e
->function_name
, l
->function_name
) == 0)
7616 update_global_location_list (1);
7620 /* Reset a breakpoint given it's struct breakpoint * BINT.
7621 The value we return ends up being the return value from catch_errors.
7622 Unused in this case. */
7625 breakpoint_re_set_one (void *bint
)
7627 /* get past catch_errs */
7628 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7632 int *not_found_ptr
= ¬_found
;
7633 struct symtabs_and_lines sals
= {};
7634 struct symtabs_and_lines expanded
;
7636 enum enable_state save_enable
;
7637 struct gdb_exception e
;
7643 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7647 case bp_hardware_breakpoint
:
7649 case bp_catch_unload
:
7650 if (b
->addr_string
== NULL
)
7652 /* Anything without a string can't be re-set. */
7653 delete_breakpoint (b
);
7657 set_language (b
->language
);
7658 input_radix
= b
->input_radix
;
7660 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7662 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7667 int not_found_and_ok
= 0;
7668 /* For pending breakpoints, it's expected that parsing
7669 will fail until the right shared library is loaded.
7670 User has already told to create pending breakpoints and
7671 don't need extra messages. If breakpoint is in bp_shlib_disabled
7672 state, then user already saw the message about that breakpoint
7673 being disabled, and don't want to see more errors. */
7675 && (b
->condition_not_parsed
7676 || (b
->loc
&& b
->loc
->shlib_disabled
)
7677 || b
->enable_state
== bp_disabled
))
7678 not_found_and_ok
= 1;
7680 if (!not_found_and_ok
)
7682 /* We surely don't want to warn about the same breakpoint
7683 10 times. One solution, implemented here, is disable
7684 the breakpoint on error. Another solution would be to
7685 have separate 'warning emitted' flag. Since this
7686 happens only when a binary has changed, I don't know
7687 which approach is better. */
7688 b
->enable_state
= bp_disabled
;
7689 throw_exception (e
);
7696 gdb_assert (sals
.nelts
== 1);
7697 resolve_sal_pc (&sals
.sals
[0]);
7698 if (b
->condition_not_parsed
&& s
&& s
[0])
7700 char *cond_string
= 0;
7702 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7703 &cond_string
, &thread
);
7705 b
->cond_string
= cond_string
;
7707 b
->condition_not_parsed
= 0;
7709 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7710 update_breakpoint_locations (b
, expanded
);
7716 case bp_hardware_watchpoint
:
7717 case bp_read_watchpoint
:
7718 case bp_access_watchpoint
:
7719 /* Watchpoint can be either on expression using entirely global variables,
7720 or it can be on local variables.
7722 Watchpoints of the first kind are never auto-deleted, and even persist
7723 across program restarts. Since they can use variables from shared
7724 libraries, we need to reparse expression as libraries are loaded
7727 Watchpoints on local variables can also change meaning as result
7728 of solib event. For example, if a watchpoint uses both a local and
7729 a global variables in expression, it's a local watchpoint, but
7730 unloading of a shared library will make the expression invalid.
7731 This is not a very common use case, but we still re-evaluate
7732 expression, to avoid surprises to the user.
7734 Note that for local watchpoints, we re-evaluate it only if
7735 watchpoints frame id is still valid. If it's not, it means
7736 the watchpoint is out of scope and will be deleted soon. In fact,
7737 I'm not sure we'll ever be called in this case.
7739 If a local watchpoint's frame id is still valid, then
7740 b->exp_valid_block is likewise valid, and we can safely use it.
7742 Don't do anything about disabled watchpoints, since they will
7743 be reevaluated again when enabled. */
7744 update_watchpoint (b
, 1 /* reparse */);
7746 /* We needn't really do anything to reset these, since the mask
7747 that requests them is unaffected by e.g., new libraries being
7753 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7755 /* Delete overlay event breakpoints; they will be reset later by
7756 breakpoint_re_set. */
7757 case bp_overlay_event
:
7758 delete_breakpoint (b
);
7761 /* This breakpoint is special, it's set up when the inferior
7762 starts and we really don't want to touch it. */
7763 case bp_shlib_event
:
7765 /* Like bp_shlib_event, this breakpoint type is special.
7766 Once it is set up, we do not want to touch it. */
7767 case bp_thread_event
:
7769 /* Keep temporary breakpoints, which can be encountered when we step
7770 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7771 Otherwise these should have been blown away via the cleanup chain
7772 or by breakpoint_init_inferior when we rerun the executable. */
7775 case bp_watchpoint_scope
:
7777 case bp_step_resume
:
7779 case bp_longjmp_resume
:
7786 /* Re-set all breakpoints after symbols have been re-loaded. */
7788 breakpoint_re_set (void)
7790 struct breakpoint
*b
, *temp
;
7791 enum language save_language
;
7792 int save_input_radix
;
7794 save_language
= current_language
->la_language
;
7795 save_input_radix
= input_radix
;
7796 ALL_BREAKPOINTS_SAFE (b
, temp
)
7798 /* Format possible error msg */
7799 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7801 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7802 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7803 do_cleanups (cleanups
);
7805 set_language (save_language
);
7806 input_radix
= save_input_radix
;
7808 create_overlay_event_breakpoint ("_ovly_debug_event");
7811 /* Reset the thread number of this breakpoint:
7813 - If the breakpoint is for all threads, leave it as-is.
7814 - Else, reset it to the current thread for inferior_ptid. */
7816 breakpoint_re_set_thread (struct breakpoint
*b
)
7818 if (b
->thread
!= -1)
7820 if (in_thread_list (inferior_ptid
))
7821 b
->thread
= pid_to_thread_id (inferior_ptid
);
7825 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7826 If from_tty is nonzero, it prints a message to that effect,
7827 which ends with a period (no newline). */
7830 set_ignore_count (int bptnum
, int count
, int from_tty
)
7832 struct breakpoint
*b
;
7838 if (b
->number
== bptnum
)
7840 b
->ignore_count
= count
;
7844 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7846 else if (count
== 1)
7847 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7850 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7853 breakpoints_changed ();
7854 observer_notify_breakpoint_modified (b
->number
);
7858 error (_("No breakpoint number %d."), bptnum
);
7862 make_breakpoint_silent (struct breakpoint
*b
)
7864 /* Silence the breakpoint. */
7868 /* Command to set ignore-count of breakpoint N to COUNT. */
7871 ignore_command (char *args
, int from_tty
)
7877 error_no_arg (_("a breakpoint number"));
7879 num
= get_number (&p
);
7881 error (_("bad breakpoint number: '%s'"), args
);
7883 error (_("Second argument (specified ignore-count) is missing."));
7885 set_ignore_count (num
,
7886 longest_to_int (value_as_long (parse_and_eval (p
))),
7889 printf_filtered ("\n");
7892 /* Call FUNCTION on each of the breakpoints
7893 whose numbers are given in ARGS. */
7896 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7901 struct breakpoint
*b
, *tmp
;
7905 error_no_arg (_("one or more breakpoint numbers"));
7912 num
= get_number_or_range (&p1
);
7915 warning (_("bad breakpoint number at or near '%s'"), p
);
7919 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7920 if (b
->number
== num
)
7922 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7925 if (related_breakpoint
)
7926 function (related_breakpoint
);
7930 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7936 static struct bp_location
*
7937 find_location_by_number (char *number
)
7939 char *dot
= strchr (number
, '.');
7943 struct breakpoint
*b
;
7944 struct bp_location
*loc
;
7949 bp_num
= get_number_or_range (&p1
);
7951 error (_("Bad breakpoint number '%s'"), number
);
7954 if (b
->number
== bp_num
)
7959 if (!b
|| b
->number
!= bp_num
)
7960 error (_("Bad breakpoint number '%s'"), number
);
7963 loc_num
= get_number_or_range (&p1
);
7965 error (_("Bad breakpoint location number '%s'"), number
);
7969 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7972 error (_("Bad breakpoint location number '%s'"), dot
+1);
7978 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7979 If from_tty is nonzero, it prints a message to that effect,
7980 which ends with a period (no newline). */
7983 disable_breakpoint (struct breakpoint
*bpt
)
7985 /* Never disable a watchpoint scope breakpoint; we want to
7986 hit them when we leave scope so we can delete both the
7987 watchpoint and its scope breakpoint at that time. */
7988 if (bpt
->type
== bp_watchpoint_scope
)
7991 /* You can't disable permanent breakpoints. */
7992 if (bpt
->enable_state
== bp_permanent
)
7995 bpt
->enable_state
= bp_disabled
;
7997 update_global_location_list (0);
7999 observer_notify_breakpoint_modified (bpt
->number
);
8003 disable_command (char *args
, int from_tty
)
8005 struct breakpoint
*bpt
;
8007 ALL_BREAKPOINTS (bpt
)
8011 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
8017 case bp_catch_unload
:
8018 case bp_hardware_breakpoint
:
8020 case bp_hardware_watchpoint
:
8021 case bp_read_watchpoint
:
8022 case bp_access_watchpoint
:
8023 disable_breakpoint (bpt
);
8027 else if (strchr (args
, '.'))
8029 struct bp_location
*loc
= find_location_by_number (args
);
8032 update_global_location_list (0);
8035 map_breakpoint_numbers (args
, disable_breakpoint
);
8039 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
8041 int target_resources_ok
, other_type_used
;
8044 if (bpt
->type
== bp_hardware_breakpoint
)
8047 i
= hw_breakpoint_used_count ();
8048 target_resources_ok
=
8049 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
8051 if (target_resources_ok
== 0)
8052 error (_("No hardware breakpoint support in the target."));
8053 else if (target_resources_ok
< 0)
8054 error (_("Hardware breakpoints used exceeds limit."));
8057 if (bpt
->type
== bp_watchpoint
||
8058 bpt
->type
== bp_hardware_watchpoint
||
8059 bpt
->type
== bp_read_watchpoint
||
8060 bpt
->type
== bp_access_watchpoint
)
8062 struct frame_id saved_frame_id
;
8064 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
8065 if (bpt
->exp_valid_block
!= NULL
)
8067 struct frame_info
*fr
=
8068 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
8071 printf_filtered (_("\
8072 Cannot enable watchpoint %d because the block in which its expression\n\
8073 is valid is not currently in scope.\n"), bpt
->number
);
8080 value_free (bpt
->val
);
8081 mark
= value_mark ();
8082 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
8084 release_value (bpt
->val
);
8087 if (bpt
->type
== bp_hardware_watchpoint
||
8088 bpt
->type
== bp_read_watchpoint
||
8089 bpt
->type
== bp_access_watchpoint
)
8091 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
8092 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
8094 /* Hack around 'unused var' error for some targets here */
8095 (void) mem_cnt
, (void) i
;
8096 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
8097 bpt
->type
, i
+ mem_cnt
, other_type_used
);
8098 /* we can consider of type is bp_hardware_watchpoint, convert to
8099 bp_watchpoint in the following condition */
8100 if (target_resources_ok
< 0)
8102 printf_filtered (_("\
8103 Cannot enable watchpoint %d because target watch resources\n\
8104 have been allocated for other watchpoints.\n"), bpt
->number
);
8105 value_free_to_mark (mark
);
8110 select_frame (frame_find_by_id (saved_frame_id
));
8111 value_free_to_mark (mark
);
8114 if (bpt
->enable_state
!= bp_permanent
)
8115 bpt
->enable_state
= bp_enabled
;
8116 bpt
->disposition
= disposition
;
8117 update_global_location_list (1);
8118 breakpoints_changed ();
8120 observer_notify_breakpoint_modified (bpt
->number
);
8125 enable_breakpoint (struct breakpoint
*bpt
)
8127 do_enable_breakpoint (bpt
, bpt
->disposition
);
8130 /* The enable command enables the specified breakpoints (or all defined
8131 breakpoints) so they once again become (or continue to be) effective
8132 in stopping the inferior. */
8135 enable_command (char *args
, int from_tty
)
8137 struct breakpoint
*bpt
;
8139 ALL_BREAKPOINTS (bpt
)
8143 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8149 case bp_catch_unload
:
8150 case bp_hardware_breakpoint
:
8152 case bp_hardware_watchpoint
:
8153 case bp_read_watchpoint
:
8154 case bp_access_watchpoint
:
8155 enable_breakpoint (bpt
);
8159 else if (strchr (args
, '.'))
8161 struct bp_location
*loc
= find_location_by_number (args
);
8164 update_global_location_list (1);
8167 map_breakpoint_numbers (args
, enable_breakpoint
);
8171 enable_once_breakpoint (struct breakpoint
*bpt
)
8173 do_enable_breakpoint (bpt
, disp_disable
);
8177 enable_once_command (char *args
, int from_tty
)
8179 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8183 enable_delete_breakpoint (struct breakpoint
*bpt
)
8185 do_enable_breakpoint (bpt
, disp_del
);
8189 enable_delete_command (char *args
, int from_tty
)
8191 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8195 set_breakpoint_cmd (char *args
, int from_tty
)
8200 show_breakpoint_cmd (char *args
, int from_tty
)
8204 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8206 struct symtabs_and_lines
8207 decode_line_spec_1 (char *string
, int funfirstline
)
8209 struct symtabs_and_lines sals
;
8211 error (_("Empty line specification."));
8212 if (default_breakpoint_valid
)
8213 sals
= decode_line_1 (&string
, funfirstline
,
8214 default_breakpoint_symtab
,
8215 default_breakpoint_line
,
8216 (char ***) NULL
, NULL
);
8218 sals
= decode_line_1 (&string
, funfirstline
,
8219 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8221 error (_("Junk at end of line specification: %s"), string
);
8225 /* Create and insert a raw software breakpoint at PC. Return an
8226 identifier, which should be used to remove the breakpoint later.
8227 In general, places which call this should be using something on the
8228 breakpoint chain instead; this function should be eliminated
8232 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8234 struct bp_target_info
*bp_tgt
;
8236 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8237 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8239 bp_tgt
->placed_address
= pc
;
8240 if (target_insert_breakpoint (bp_tgt
) != 0)
8242 /* Could not insert the breakpoint. */
8250 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8253 deprecated_remove_raw_breakpoint (void *bp
)
8255 struct bp_target_info
*bp_tgt
= bp
;
8258 ret
= target_remove_breakpoint (bp_tgt
);
8264 /* One (or perhaps two) breakpoints used for software single stepping. */
8266 static void *single_step_breakpoints
[2];
8268 /* Create and insert a breakpoint for software single step. */
8271 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8275 if (single_step_breakpoints
[0] == NULL
)
8276 bpt_p
= &single_step_breakpoints
[0];
8279 gdb_assert (single_step_breakpoints
[1] == NULL
);
8280 bpt_p
= &single_step_breakpoints
[1];
8283 /* NOTE drow/2006-04-11: A future improvement to this function would be
8284 to only create the breakpoints once, and actually put them on the
8285 breakpoint chain. That would let us use set_raw_breakpoint. We could
8286 adjust the addresses each time they were needed. Doing this requires
8287 corresponding changes elsewhere where single step breakpoints are
8288 handled, however. So, for now, we use this. */
8290 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8292 error (_("Could not insert single-step breakpoint at 0x%s"),
8293 paddr_nz (next_pc
));
8296 /* Remove and delete any breakpoints used for software single step. */
8299 remove_single_step_breakpoints (void)
8301 gdb_assert (single_step_breakpoints
[0] != NULL
);
8303 /* See insert_single_step_breakpoint for more about this deprecated
8305 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8306 single_step_breakpoints
[0] = NULL
;
8308 if (single_step_breakpoints
[1] != NULL
)
8310 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8311 single_step_breakpoints
[1] = NULL
;
8315 /* Check whether a software single-step breakpoint is inserted at PC. */
8318 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8322 for (i
= 0; i
< 2; i
++)
8324 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8325 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8333 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8334 It is defined as a macro to prevent duplication.
8335 COMMAND should be a string constant containing the name of the command. */
8336 #define BREAK_ARGS_HELP(command) \
8337 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8338 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8339 If a line number is specified, break at start of code for that line.\n\
8340 If a function is specified, break at start of code for that function.\n\
8341 If an address is specified, break at that exact address.\n\
8342 With no LOCATION, uses current execution address of selected stack frame.\n\
8343 This is useful for breaking on return to a stack frame.\n\
8345 THREADNUM is the number from \"info threads\".\n\
8346 CONDITION is a boolean expression.\n\
8348 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8350 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8352 /* List of subcommands for "catch". */
8353 static struct cmd_list_element
*catch_cmdlist
;
8355 /* List of subcommands for "tcatch". */
8356 static struct cmd_list_element
*tcatch_cmdlist
;
8358 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8359 lists, and pass some additional user data to the command function. */
8361 add_catch_command (char *name
, char *docstring
,
8362 void (*sfunc
) (char *args
, int from_tty
,
8363 struct cmd_list_element
*command
),
8364 void *user_data_catch
,
8365 void *user_data_tcatch
)
8367 struct cmd_list_element
*command
;
8369 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8371 set_cmd_sfunc (command
, sfunc
);
8372 set_cmd_context (command
, user_data_catch
);
8374 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8376 set_cmd_sfunc (command
, sfunc
);
8377 set_cmd_context (command
, user_data_tcatch
);
8381 _initialize_breakpoint (void)
8383 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8384 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8385 struct cmd_list_element
*c
;
8387 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8389 breakpoint_chain
= 0;
8390 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8391 before a breakpoint is set. */
8392 breakpoint_count
= 0;
8394 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8395 Set ignore-count of breakpoint number N to COUNT.\n\
8396 Usage is `ignore N COUNT'."));
8398 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8400 add_com ("commands", class_breakpoint
, commands_command
, _("\
8401 Set commands to be executed when a breakpoint is hit.\n\
8402 Give breakpoint number as argument after \"commands\".\n\
8403 With no argument, the targeted breakpoint is the last one set.\n\
8404 The commands themselves follow starting on the next line.\n\
8405 Type a line containing \"end\" to indicate the end of them.\n\
8406 Give \"silent\" as the first line to make the breakpoint silent;\n\
8407 then no output is printed when it is hit, except what the commands print."));
8409 add_com ("condition", class_breakpoint
, condition_command
, _("\
8410 Specify breakpoint number N to break only if COND is true.\n\
8411 Usage is `condition N COND', where N is an integer and COND is an\n\
8412 expression to be evaluated whenever breakpoint N is reached."));
8414 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8415 Set a temporary breakpoint.\n\
8416 Like \"break\" except the breakpoint is only temporary,\n\
8417 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8418 by using \"enable delete\" on the breakpoint number.\n\
8420 BREAK_ARGS_HELP ("tbreak")));
8421 set_cmd_completer (c
, location_completer
);
8423 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8424 Set a hardware assisted breakpoint.\n\
8425 Like \"break\" except the breakpoint requires hardware support,\n\
8426 some target hardware may not have this support.\n\
8428 BREAK_ARGS_HELP ("hbreak")));
8429 set_cmd_completer (c
, location_completer
);
8431 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8432 Set a temporary hardware assisted breakpoint.\n\
8433 Like \"hbreak\" except the breakpoint is only temporary,\n\
8434 so it will be deleted when hit.\n\
8436 BREAK_ARGS_HELP ("thbreak")));
8437 set_cmd_completer (c
, location_completer
);
8439 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8440 Enable some breakpoints.\n\
8441 Give breakpoint numbers (separated by spaces) as arguments.\n\
8442 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8443 This is used to cancel the effect of the \"disable\" command.\n\
8444 With a subcommand you can enable temporarily."),
8445 &enablelist
, "enable ", 1, &cmdlist
);
8447 add_com ("ab", class_breakpoint
, enable_command
, _("\
8448 Enable some breakpoints.\n\
8449 Give breakpoint numbers (separated by spaces) as arguments.\n\
8450 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8451 This is used to cancel the effect of the \"disable\" command.\n\
8452 With a subcommand you can enable temporarily."));
8454 add_com_alias ("en", "enable", class_breakpoint
, 1);
8456 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8457 Enable some breakpoints.\n\
8458 Give breakpoint numbers (separated by spaces) as arguments.\n\
8459 This is used to cancel the effect of the \"disable\" command.\n\
8460 May be abbreviated to simply \"enable\".\n"),
8461 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8463 add_cmd ("once", no_class
, enable_once_command
, _("\
8464 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8465 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8468 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8469 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8470 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8473 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8474 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8475 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8478 add_cmd ("once", no_class
, enable_once_command
, _("\
8479 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8480 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8483 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8484 Disable some breakpoints.\n\
8485 Arguments are breakpoint numbers with spaces in between.\n\
8486 To disable all breakpoints, give no argument.\n\
8487 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8488 &disablelist
, "disable ", 1, &cmdlist
);
8489 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8490 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8492 add_com ("sb", class_breakpoint
, disable_command
, _("\
8493 Disable some breakpoints.\n\
8494 Arguments are breakpoint numbers with spaces in between.\n\
8495 To disable all breakpoints, give no argument.\n\
8496 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8498 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8499 Disable some breakpoints.\n\
8500 Arguments are breakpoint numbers with spaces in between.\n\
8501 To disable all breakpoints, give no argument.\n\
8502 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8503 This command may be abbreviated \"disable\"."),
8506 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8507 Delete some breakpoints or auto-display expressions.\n\
8508 Arguments are breakpoint numbers with spaces in between.\n\
8509 To delete all breakpoints, give no argument.\n\
8511 Also a prefix command for deletion of other GDB objects.\n\
8512 The \"unset\" command is also an alias for \"delete\"."),
8513 &deletelist
, "delete ", 1, &cmdlist
);
8514 add_com_alias ("d", "delete", class_breakpoint
, 1);
8515 add_com_alias ("del", "delete", class_breakpoint
, 1);
8517 add_com ("db", class_breakpoint
, delete_command
, _("\
8518 Delete some breakpoints.\n\
8519 Arguments are breakpoint numbers with spaces in between.\n\
8520 To delete all breakpoints, give no argument.\n"));
8522 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8523 Delete some breakpoints or auto-display expressions.\n\
8524 Arguments are breakpoint numbers with spaces in between.\n\
8525 To delete all breakpoints, give no argument.\n\
8526 This command may be abbreviated \"delete\"."),
8529 add_com ("clear", class_breakpoint
, clear_command
, _("\
8530 Clear breakpoint at specified line or function.\n\
8531 Argument may be line number, function name, or \"*\" and an address.\n\
8532 If line number is specified, all breakpoints in that line are cleared.\n\
8533 If function is specified, breakpoints at beginning of function are cleared.\n\
8534 If an address is specified, breakpoints at that address are cleared.\n\
8536 With no argument, clears all breakpoints in the line that the selected frame\n\
8539 See also the \"delete\" command which clears breakpoints by number."));
8541 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8542 Set breakpoint at specified line or function.\n"
8543 BREAK_ARGS_HELP ("break")));
8544 set_cmd_completer (c
, location_completer
);
8546 add_com_alias ("b", "break", class_run
, 1);
8547 add_com_alias ("br", "break", class_run
, 1);
8548 add_com_alias ("bre", "break", class_run
, 1);
8549 add_com_alias ("brea", "break", class_run
, 1);
8553 add_com_alias ("ba", "break", class_breakpoint
, 1);
8554 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8559 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8560 Break in function/address or break at a line in the current file."),
8561 &stoplist
, "stop ", 1, &cmdlist
);
8562 add_cmd ("in", class_breakpoint
, stopin_command
,
8563 _("Break in function or address."), &stoplist
);
8564 add_cmd ("at", class_breakpoint
, stopat_command
,
8565 _("Break at a line in the current file."), &stoplist
);
8566 add_com ("status", class_info
, breakpoints_info
, _("\
8567 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8568 The \"Type\" column indicates one of:\n\
8569 \tbreakpoint - normal breakpoint\n\
8570 \twatchpoint - watchpoint\n\
8571 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8572 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8573 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8574 address and file/line number respectively.\n\
8576 Convenience variable \"$_\" and default examine address for \"x\"\n\
8577 are set to the address of the last breakpoint listed unless the command\n\
8578 is prefixed with \"server \".\n\n\
8579 Convenience variable \"$bpnum\" contains the number of the last\n\
8583 add_info ("breakpoints", breakpoints_info
, _("\
8584 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8585 The \"Type\" column indicates one of:\n\
8586 \tbreakpoint - normal breakpoint\n\
8587 \twatchpoint - watchpoint\n\
8588 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8589 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8590 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8591 address and file/line number respectively.\n\
8593 Convenience variable \"$_\" and default examine address for \"x\"\n\
8594 are set to the address of the last breakpoint listed unless the command\n\
8595 is prefixed with \"server \".\n\n\
8596 Convenience variable \"$bpnum\" contains the number of the last\n\
8600 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8601 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8602 The \"Type\" column indicates one of:\n\
8603 \tbreakpoint - normal breakpoint\n\
8604 \twatchpoint - watchpoint\n\
8605 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8606 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8607 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8608 address and file/line number respectively.\n\
8610 Convenience variable \"$_\" and default examine address for \"x\"\n\
8611 are set to the address of the last breakpoint listed unless the command\n\
8612 is prefixed with \"server \".\n\n\
8613 Convenience variable \"$bpnum\" contains the number of the last\n\
8616 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8617 Status of all breakpoints, or breakpoint number NUMBER.\n\
8618 The \"Type\" column indicates one of:\n\
8619 \tbreakpoint - normal breakpoint\n\
8620 \twatchpoint - watchpoint\n\
8621 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8622 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8623 \tuntil - internal breakpoint used by the \"until\" command\n\
8624 \tfinish - internal breakpoint used by the \"finish\" command\n\
8625 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8626 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8627 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8628 address and file/line number respectively.\n\
8630 Convenience variable \"$_\" and default examine address for \"x\"\n\
8631 are set to the address of the last breakpoint listed unless the command\n\
8632 is prefixed with \"server \".\n\n\
8633 Convenience variable \"$bpnum\" contains the number of the last\n\
8635 &maintenanceinfolist
);
8637 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
8638 Set catchpoints to catch events."),
8639 &catch_cmdlist
, "catch ",
8640 0/*allow-unknown*/, &cmdlist
);
8642 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
8643 Set temporary catchpoints to catch events."),
8644 &tcatch_cmdlist
, "tcatch ",
8645 0/*allow-unknown*/, &cmdlist
);
8647 /* Add catch and tcatch sub-commands. */
8648 add_catch_command ("catch", _("\
8649 Catch an exception, when caught.\n\
8650 With an argument, catch only exceptions with the given name."),
8651 catch_catch_command
,
8654 add_catch_command ("throw", _("\
8655 Catch an exception, when thrown.\n\
8656 With an argument, catch only exceptions with the given name."),
8657 catch_throw_command
,
8660 add_catch_command ("fork", _("Catch calls to fork."),
8661 catch_fork_command_1
,
8662 (void *) (uintptr_t) catch_fork_permanent
,
8663 (void *) (uintptr_t) catch_fork_temporary
);
8664 add_catch_command ("vfork", _("Catch calls to vfork."),
8665 catch_fork_command_1
,
8666 (void *) (uintptr_t) catch_vfork_permanent
,
8667 (void *) (uintptr_t) catch_vfork_temporary
);
8668 add_catch_command ("exec", _("Catch calls to exec."),
8669 catch_exec_command_1
,
8672 add_catch_command ("load", _("\
8673 Catch library loads.\n\
8674 With an argument, catch only loads of that library."),
8675 catch_load_command_1
,
8678 add_catch_command ("unload", _("\
8679 Catch library unloads.\n\
8680 With an argument, catch only unloads of that library."),
8681 catch_unload_command_1
,
8684 add_catch_command ("exception", _("\
8685 Catch Ada exceptions, when raised.\n\
8686 With an argument, catch only exceptions with the given name."),
8687 catch_ada_exception_command
,
8690 add_catch_command ("assert", _("\
8691 Catch failed Ada assertions, when raised.\n\
8692 With an argument, catch only exceptions with the given name."),
8693 catch_assert_command
,
8697 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8698 Set a watchpoint for an expression.\n\
8699 A watchpoint stops execution of your program whenever the value of\n\
8700 an expression changes."));
8701 set_cmd_completer (c
, expression_completer
);
8703 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8704 Set a read watchpoint for an expression.\n\
8705 A watchpoint stops execution of your program whenever the value of\n\
8706 an expression is read."));
8707 set_cmd_completer (c
, expression_completer
);
8709 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8710 Set a watchpoint for an expression.\n\
8711 A watchpoint stops execution of your program whenever the value of\n\
8712 an expression is either read or written."));
8713 set_cmd_completer (c
, expression_completer
);
8715 add_info ("watchpoints", breakpoints_info
,
8716 _("Synonym for ``info breakpoints''."));
8719 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8720 respond to changes - contrary to the description. */
8721 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8722 &can_use_hw_watchpoints
, _("\
8723 Set debugger's willingness to use watchpoint hardware."), _("\
8724 Show debugger's willingness to use watchpoint hardware."), _("\
8725 If zero, gdb will not use hardware for new watchpoints, even if\n\
8726 such is available. (However, any hardware watchpoints that were\n\
8727 created before setting this to nonzero, will continue to use watchpoint\n\
8730 show_can_use_hw_watchpoints
,
8731 &setlist
, &showlist
);
8733 can_use_hw_watchpoints
= 1;
8735 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8736 Breakpoint specific settings\n\
8737 Configure various breakpoint-specific variables such as\n\
8738 pending breakpoint behavior"),
8739 &breakpoint_set_cmdlist
, "set breakpoint ",
8740 0/*allow-unknown*/, &setlist
);
8741 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8742 Breakpoint specific settings\n\
8743 Configure various breakpoint-specific variables such as\n\
8744 pending breakpoint behavior"),
8745 &breakpoint_show_cmdlist
, "show breakpoint ",
8746 0/*allow-unknown*/, &showlist
);
8748 add_setshow_auto_boolean_cmd ("pending", no_class
,
8749 &pending_break_support
, _("\
8750 Set debugger's behavior regarding pending breakpoints."), _("\
8751 Show debugger's behavior regarding pending breakpoints."), _("\
8752 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8753 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8754 an error. If auto, an unrecognized breakpoint location results in a\n\
8755 user-query to see if a pending breakpoint should be created."),
8757 show_pending_break_support
,
8758 &breakpoint_set_cmdlist
,
8759 &breakpoint_show_cmdlist
);
8761 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8763 add_setshow_boolean_cmd ("auto-hw", no_class
,
8764 &automatic_hardware_breakpoints
, _("\
8765 Set automatic usage of hardware breakpoints."), _("\
8766 Show automatic usage of hardware breakpoints."), _("\
8767 If set, the debugger will automatically use hardware breakpoints for\n\
8768 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8769 a warning will be emitted for such breakpoints."),
8771 show_automatic_hardware_breakpoints
,
8772 &breakpoint_set_cmdlist
,
8773 &breakpoint_show_cmdlist
);
8775 add_setshow_enum_cmd ("always-inserted", class_support
,
8776 always_inserted_enums
, &always_inserted_mode
, _("\
8777 Set mode for inserting breakpoints."), _("\
8778 Show mode for inserting breakpoints."), _("\
8779 When this mode is off, breakpoints are inserted in inferior when it is\n\
8780 resumed, and removed when execution stops. When this mode is on,\n\
8781 breakpoints are inserted immediately and removed only when the user\n\
8782 deletes the breakpoint. When this mode is auto (which is the default),\n\
8783 the behaviour depends on the non-stop setting (see help set non-stop).\n\
8784 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
8785 behaves as if always-inserted mode is on; if gdb is controlling the\n\
8786 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
8788 &show_always_inserted_mode
,
8789 &breakpoint_set_cmdlist
,
8790 &breakpoint_show_cmdlist
);
8792 automatic_hardware_breakpoints
= 1;