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 () && target_has_execution
)
1267 /* update_global_location_list does not insert breakpoints
1268 when always_inserted_mode is not enabled. Explicitly
1270 insert_breakpoint_locations ();
1273 /* insert_breakpoints is used when starting or continuing the program.
1274 remove_breakpoints is used when the program stops.
1275 Both return zero if successful,
1276 or an `errno' value if could not write the inferior. */
1279 insert_breakpoint_locations (void)
1281 struct breakpoint
*bpt
;
1282 struct bp_location
*b
, *temp
;
1285 int disabled_breaks
= 0;
1286 int hw_breakpoint_error
= 0;
1287 int process_warning
= 0;
1289 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1290 make_cleanup_ui_file_delete (tmp_error_stream
);
1292 /* Explicitly mark the warning -- this will only be printed if
1293 there was an error. */
1294 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1296 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1298 if (!should_be_inserted (b
) || b
->inserted
)
1301 /* There is no point inserting thread-specific breakpoints if the
1302 thread no longer exists. */
1303 if (b
->owner
->thread
!= -1
1304 && !valid_thread_id (b
->owner
->thread
))
1307 val
= insert_bp_location (b
, tmp_error_stream
,
1308 &disabled_breaks
, &process_warning
,
1309 &hw_breakpoint_error
);
1314 /* If we failed to insert all locations of a watchpoint,
1315 remove them, as half-inserted watchpoint is of limited use. */
1316 ALL_BREAKPOINTS (bpt
)
1318 int some_failed
= 0;
1319 struct bp_location
*loc
;
1321 if (!is_hardware_watchpoint (bpt
))
1324 if (!breakpoint_enabled (bpt
))
1327 if (bpt
->disposition
== disp_del_at_next_stop
)
1330 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1338 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1340 remove_breakpoint (loc
, mark_uninserted
);
1342 hw_breakpoint_error
= 1;
1343 fprintf_unfiltered (tmp_error_stream
,
1344 "Could not insert hardware watchpoint %d.\n",
1352 /* If a hardware breakpoint or watchpoint was inserted, add a
1353 message about possibly exhausted resources. */
1354 if (hw_breakpoint_error
)
1356 fprintf_unfiltered (tmp_error_stream
,
1357 "Could not insert hardware breakpoints:\n\
1358 You may have requested too many hardware breakpoints/watchpoints.\n");
1360 #ifdef ONE_PROCESS_WRITETEXT
1361 if (process_warning
)
1362 fprintf_unfiltered (tmp_error_stream
,
1363 "The same program may be running in another process.");
1365 target_terminal_ours_for_output ();
1366 error_stream (tmp_error_stream
);
1371 remove_breakpoints (void)
1373 struct bp_location
*b
;
1376 ALL_BP_LOCATIONS (b
)
1380 val
= remove_breakpoint (b
, mark_uninserted
);
1389 remove_hw_watchpoints (void)
1391 struct bp_location
*b
;
1394 ALL_BP_LOCATIONS (b
)
1396 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1398 val
= remove_breakpoint (b
, mark_uninserted
);
1407 reattach_breakpoints (int pid
)
1409 struct bp_location
*b
;
1411 struct cleanup
*old_chain
= save_inferior_ptid ();
1412 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1413 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1415 make_cleanup_ui_file_delete (tmp_error_stream
);
1417 inferior_ptid
= pid_to_ptid (pid
);
1418 ALL_BP_LOCATIONS (b
)
1423 val
= insert_bp_location (b
, tmp_error_stream
,
1424 &dummy1
, &dummy2
, &dummy3
);
1427 do_cleanups (old_chain
);
1432 do_cleanups (old_chain
);
1437 update_breakpoints_after_exec (void)
1439 struct breakpoint
*b
;
1440 struct breakpoint
*temp
;
1441 struct bp_location
*bploc
;
1443 /* We're about to delete breakpoints from GDB's lists. If the
1444 INSERTED flag is true, GDB will try to lift the breakpoints by
1445 writing the breakpoints' "shadow contents" back into memory. The
1446 "shadow contents" are NOT valid after an exec, so GDB should not
1447 do that. Instead, the target is responsible from marking
1448 breakpoints out as soon as it detects an exec. We don't do that
1449 here instead, because there may be other attempts to delete
1450 breakpoints after detecting an exec and before reaching here. */
1451 ALL_BP_LOCATIONS (bploc
)
1452 gdb_assert (!bploc
->inserted
);
1454 ALL_BREAKPOINTS_SAFE (b
, temp
)
1456 /* Solib breakpoints must be explicitly reset after an exec(). */
1457 if (b
->type
== bp_shlib_event
)
1459 delete_breakpoint (b
);
1463 /* Thread event breakpoints must be set anew after an exec(),
1464 as must overlay event breakpoints. */
1465 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1467 delete_breakpoint (b
);
1471 /* Step-resume breakpoints are meaningless after an exec(). */
1472 if (b
->type
== bp_step_resume
)
1474 delete_breakpoint (b
);
1478 /* Longjmp and longjmp-resume breakpoints are also meaningless
1480 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1482 delete_breakpoint (b
);
1486 if (b
->type
== bp_catchpoint
)
1488 /* For now, none of the bp_catchpoint breakpoints need to
1489 do anything at this point. In the future, if some of
1490 the catchpoints need to something, we will need to add
1491 a new method, and call this method from here. */
1495 /* bp_finish is a special case. The only way we ought to be able
1496 to see one of these when an exec() has happened, is if the user
1497 caught a vfork, and then said "finish". Ordinarily a finish just
1498 carries them to the call-site of the current callee, by setting
1499 a temporary bp there and resuming. But in this case, the finish
1500 will carry them entirely through the vfork & exec.
1502 We don't want to allow a bp_finish to remain inserted now. But
1503 we can't safely delete it, 'cause finish_command has a handle to
1504 the bp on a bpstat, and will later want to delete it. There's a
1505 chance (and I've seen it happen) that if we delete the bp_finish
1506 here, that its storage will get reused by the time finish_command
1507 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1508 We really must allow finish_command to delete a bp_finish.
1510 In the absense of a general solution for the "how do we know
1511 it's safe to delete something others may have handles to?"
1512 problem, what we'll do here is just uninsert the bp_finish, and
1513 let finish_command delete it.
1515 (We know the bp_finish is "doomed" in the sense that it's
1516 momentary, and will be deleted as soon as finish_command sees
1517 the inferior stopped. So it doesn't matter that the bp's
1518 address is probably bogus in the new a.out, unlike e.g., the
1519 solib breakpoints.) */
1521 if (b
->type
== bp_finish
)
1526 /* Without a symbolic address, we have little hope of the
1527 pre-exec() address meaning the same thing in the post-exec()
1529 if (b
->addr_string
== NULL
)
1531 delete_breakpoint (b
);
1535 /* FIXME what about longjmp breakpoints? Re-create them here? */
1536 create_overlay_event_breakpoint ("_ovly_debug_event");
1540 detach_breakpoints (int pid
)
1542 struct bp_location
*b
;
1544 struct cleanup
*old_chain
= save_inferior_ptid ();
1546 if (pid
== PIDGET (inferior_ptid
))
1547 error (_("Cannot detach breakpoints of inferior_ptid"));
1549 /* Set inferior_ptid; remove_breakpoint uses this global. */
1550 inferior_ptid
= pid_to_ptid (pid
);
1551 ALL_BP_LOCATIONS (b
)
1555 val
= remove_breakpoint (b
, mark_inserted
);
1558 do_cleanups (old_chain
);
1563 do_cleanups (old_chain
);
1568 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1572 if (b
->owner
->enable_state
== bp_permanent
)
1573 /* Permanent breakpoints cannot be inserted or removed. */
1576 /* The type of none suggests that owner is actually deleted.
1577 This should not ever happen. */
1578 gdb_assert (b
->owner
->type
!= bp_none
);
1580 if (b
->loc_type
== bp_loc_software_breakpoint
1581 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1583 /* "Normal" instruction breakpoint: either the standard
1584 trap-instruction bp (bp_breakpoint), or a
1585 bp_hardware_breakpoint. */
1587 /* First check to see if we have to handle an overlay. */
1588 if (overlay_debugging
== ovly_off
1589 || b
->section
== NULL
1590 || !(section_is_overlay (b
->section
)))
1592 /* No overlay handling: just remove the breakpoint. */
1594 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1595 val
= target_remove_hw_breakpoint (&b
->target_info
);
1597 val
= target_remove_breakpoint (&b
->target_info
);
1601 /* This breakpoint is in an overlay section.
1602 Did we set a breakpoint at the LMA? */
1603 if (!overlay_events_enabled
)
1605 /* Yes -- overlay event support is not active, so we
1606 should have set a breakpoint at the LMA. Remove it.
1608 /* Ignore any failures: if the LMA is in ROM, we will
1609 have already warned when we failed to insert it. */
1610 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1611 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1613 target_remove_breakpoint (&b
->overlay_target_info
);
1615 /* Did we set a breakpoint at the VMA?
1616 If so, we will have marked the breakpoint 'inserted'. */
1619 /* Yes -- remove it. Previously we did not bother to
1620 remove the breakpoint if the section had been
1621 unmapped, but let's not rely on that being safe. We
1622 don't know what the overlay manager might do. */
1623 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1624 val
= target_remove_hw_breakpoint (&b
->target_info
);
1626 /* However, we should remove *software* breakpoints only
1627 if the section is still mapped, or else we overwrite
1628 wrong code with the saved shadow contents. */
1629 else if (section_is_mapped (b
->section
))
1630 val
= target_remove_breakpoint (&b
->target_info
);
1636 /* No -- not inserted, so no need to remove. No error. */
1641 /* In some cases, we might not be able to remove a breakpoint
1642 in a shared library that has already been removed, but we
1643 have not yet processed the shlib unload event. */
1644 if (val
&& solib_address (b
->address
))
1649 b
->inserted
= (is
== mark_inserted
);
1651 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1656 b
->inserted
= (is
== mark_inserted
);
1657 val
= target_remove_watchpoint (b
->address
, b
->length
,
1658 b
->watchpoint_type
);
1660 /* Failure to remove any of the hardware watchpoints comes here. */
1661 if ((is
== mark_uninserted
) && (b
->inserted
))
1662 warning (_("Could not remove hardware watchpoint %d."),
1665 else if (b
->owner
->type
== bp_catchpoint
1666 && breakpoint_enabled (b
->owner
)
1669 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
1671 val
= b
->owner
->ops
->remove (b
->owner
);
1674 b
->inserted
= (is
== mark_inserted
);
1680 /* Clear the "inserted" flag in all breakpoints. */
1683 mark_breakpoints_out (void)
1685 struct bp_location
*bpt
;
1687 ALL_BP_LOCATIONS (bpt
)
1691 /* Clear the "inserted" flag in all breakpoints and delete any
1692 breakpoints which should go away between runs of the program.
1694 Plus other such housekeeping that has to be done for breakpoints
1697 Note: this function gets called at the end of a run (by
1698 generic_mourn_inferior) and when a run begins (by
1699 init_wait_for_inferior). */
1704 breakpoint_init_inferior (enum inf_context context
)
1706 struct breakpoint
*b
, *temp
;
1707 struct bp_location
*bpt
;
1710 ALL_BP_LOCATIONS (bpt
)
1711 if (bpt
->owner
->enable_state
!= bp_permanent
)
1714 ALL_BREAKPOINTS_SAFE (b
, temp
)
1719 case bp_watchpoint_scope
:
1721 /* If the call dummy breakpoint is at the entry point it will
1722 cause problems when the inferior is rerun, so we better
1725 Also get rid of scope breakpoints. */
1726 delete_breakpoint (b
);
1730 case bp_hardware_watchpoint
:
1731 case bp_read_watchpoint
:
1732 case bp_access_watchpoint
:
1734 /* Likewise for watchpoints on local expressions. */
1735 if (b
->exp_valid_block
!= NULL
)
1736 delete_breakpoint (b
);
1737 else if (context
== inf_starting
)
1739 /* Reset val field to force reread of starting value
1740 in insert_breakpoints. */
1742 value_free (b
->val
);
1752 /* Get rid of the moribund locations. */
1753 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
1754 free_bp_location (bpt
);
1755 VEC_free (bp_location_p
, moribund_locations
);
1758 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1759 exists at PC. It returns ordinary_breakpoint_here if it's an
1760 ordinary breakpoint, or permanent_breakpoint_here if it's a
1761 permanent breakpoint.
1762 - When continuing from a location with an ordinary breakpoint, we
1763 actually single step once before calling insert_breakpoints.
1764 - When continuing from a localion with a permanent breakpoint, we
1765 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1766 the target, to advance the PC past the breakpoint. */
1768 enum breakpoint_here
1769 breakpoint_here_p (CORE_ADDR pc
)
1771 const struct bp_location
*bpt
;
1772 int any_breakpoint_here
= 0;
1774 ALL_BP_LOCATIONS (bpt
)
1776 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1777 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1780 if ((breakpoint_enabled (bpt
->owner
)
1781 || bpt
->owner
->enable_state
== bp_permanent
)
1782 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1784 if (overlay_debugging
1785 && section_is_overlay (bpt
->section
)
1786 && !section_is_mapped (bpt
->section
))
1787 continue; /* unmapped overlay -- can't be a match */
1788 else if (bpt
->owner
->enable_state
== bp_permanent
)
1789 return permanent_breakpoint_here
;
1791 any_breakpoint_here
= 1;
1795 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1798 /* Return true if there's a moribund breakpoint at PC. */
1801 moribund_breakpoint_here_p (CORE_ADDR pc
)
1803 struct bp_location
*loc
;
1806 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
1807 if (loc
->address
== pc
)
1813 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1814 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1815 This does not check for single-step breakpoints, which are
1816 inserted and removed using direct target manipulation. */
1819 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1821 const struct bp_location
*bpt
;
1823 ALL_BP_LOCATIONS (bpt
)
1825 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1826 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1830 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1832 if (overlay_debugging
1833 && section_is_overlay (bpt
->section
)
1834 && !section_is_mapped (bpt
->section
))
1835 continue; /* unmapped overlay -- can't be a match */
1843 /* Returns non-zero iff there's either regular breakpoint
1844 or a single step breakpoint inserted at PC. */
1847 breakpoint_inserted_here_p (CORE_ADDR pc
)
1849 if (regular_breakpoint_inserted_here_p (pc
))
1852 if (single_step_breakpoint_inserted_here_p (pc
))
1858 /* This function returns non-zero iff there is a software breakpoint
1862 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1864 const struct bp_location
*bpt
;
1865 int any_breakpoint_here
= 0;
1867 ALL_BP_LOCATIONS (bpt
)
1869 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1873 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1875 if (overlay_debugging
1876 && section_is_overlay (bpt
->section
)
1877 && !section_is_mapped (bpt
->section
))
1878 continue; /* unmapped overlay -- can't be a match */
1884 /* Also check for software single-step breakpoints. */
1885 if (single_step_breakpoint_inserted_here_p (pc
))
1891 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1892 PC is valid for process/thread PTID. */
1895 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1897 const struct bp_location
*bpt
;
1900 thread
= pid_to_thread_id (ptid
);
1902 ALL_BP_LOCATIONS (bpt
)
1904 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1905 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1908 if ((breakpoint_enabled (bpt
->owner
)
1909 || bpt
->owner
->enable_state
== bp_permanent
)
1910 && bpt
->address
== pc
1911 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1913 if (overlay_debugging
1914 && section_is_overlay (bpt
->section
)
1915 && !section_is_mapped (bpt
->section
))
1916 continue; /* unmapped overlay -- can't be a match */
1926 /* bpstat stuff. External routines' interfaces are documented
1930 ep_is_catchpoint (struct breakpoint
*ep
)
1932 return (ep
->type
== bp_catchpoint
)
1933 || (ep
->type
== bp_catch_load
)
1934 || (ep
->type
== bp_catch_unload
);
1936 /* ??rehrauer: Add more kinds here, as are implemented... */
1940 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1943 (ep
->type
== bp_catch_load
)
1944 || (ep
->type
== bp_catch_unload
);
1948 bpstat_free (bpstat bs
)
1950 if (bs
->old_val
!= NULL
)
1951 value_free (bs
->old_val
);
1952 free_command_lines (&bs
->commands
);
1956 /* Clear a bpstat so that it says we are not at any breakpoint.
1957 Also free any storage that is part of a bpstat. */
1960 bpstat_clear (bpstat
*bsp
)
1977 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1978 is part of the bpstat is copied as well. */
1981 bpstat_copy (bpstat bs
)
1985 bpstat retval
= NULL
;
1990 for (; bs
!= NULL
; bs
= bs
->next
)
1992 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1993 memcpy (tmp
, bs
, sizeof (*tmp
));
1994 if (bs
->commands
!= NULL
)
1995 tmp
->commands
= copy_command_lines (bs
->commands
);
1996 if (bs
->old_val
!= NULL
)
1998 tmp
->old_val
= value_copy (bs
->old_val
);
1999 release_value (tmp
->old_val
);
2003 /* This is the first thing in the chain. */
2013 /* Find the bpstat associated with this breakpoint */
2016 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2021 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2023 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2029 /* Find a step_resume breakpoint associated with this bpstat.
2030 (If there are multiple step_resume bp's on the list, this function
2031 will arbitrarily pick one.)
2033 It is an error to use this function if BPSTAT doesn't contain a
2034 step_resume breakpoint.
2036 See wait_for_inferior's use of this function. */
2038 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2042 gdb_assert (bsp
!= NULL
);
2044 current_thread
= pid_to_thread_id (inferior_ptid
);
2046 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2048 if ((bsp
->breakpoint_at
!= NULL
) &&
2049 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2050 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2051 bsp
->breakpoint_at
->owner
->thread
== -1))
2052 return bsp
->breakpoint_at
->owner
;
2055 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2059 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2060 at. *BSP upon return is a bpstat which points to the remaining
2061 breakpoints stopped at (but which is not guaranteed to be good for
2062 anything but further calls to bpstat_num).
2063 Return 0 if passed a bpstat which does not indicate any breakpoints.
2064 Return -1 if stopped at a breakpoint that has been deleted since
2066 Return 1 otherwise. */
2069 bpstat_num (bpstat
*bsp
, int *num
)
2071 struct breakpoint
*b
;
2074 return 0; /* No more breakpoint values */
2076 /* We assume we'll never have several bpstats that
2077 correspond to a single breakpoint -- otherwise,
2078 this function might return the same number more
2079 than once and this will look ugly. */
2080 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2081 *bsp
= (*bsp
)->next
;
2083 return -1; /* breakpoint that's been deleted since */
2085 *num
= b
->number
; /* We have its number */
2089 /* Modify BS so that the actions will not be performed. */
2092 bpstat_clear_actions (bpstat bs
)
2094 for (; bs
!= NULL
; bs
= bs
->next
)
2096 free_command_lines (&bs
->commands
);
2097 if (bs
->old_val
!= NULL
)
2099 value_free (bs
->old_val
);
2105 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2107 cleanup_executing_breakpoints (void *ignore
)
2109 executing_breakpoint_commands
= 0;
2112 /* Execute all the commands associated with all the breakpoints at this
2113 location. Any of these commands could cause the process to proceed
2114 beyond this point, etc. We look out for such changes by checking
2115 the global "breakpoint_proceeded" after each command.
2117 Returns true if a breakpoint command resumed the inferior. In that
2118 case, it is the caller's responsibility to recall it again with the
2119 bpstat of the current thread. */
2122 bpstat_do_actions_1 (bpstat
*bsp
)
2125 struct cleanup
*old_chain
;
2128 /* Avoid endless recursion if a `source' command is contained
2130 if (executing_breakpoint_commands
)
2133 executing_breakpoint_commands
= 1;
2134 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2136 /* This pointer will iterate over the list of bpstat's. */
2139 breakpoint_proceeded
= 0;
2140 for (; bs
!= NULL
; bs
= bs
->next
)
2142 struct command_line
*cmd
;
2143 struct cleanup
*this_cmd_tree_chain
;
2145 /* Take ownership of the BSP's command tree, if it has one.
2147 The command tree could legitimately contain commands like
2148 'step' and 'next', which call clear_proceed_status, which
2149 frees stop_bpstat's command tree. To make sure this doesn't
2150 free the tree we're executing out from under us, we need to
2151 take ownership of the tree ourselves. Since a given bpstat's
2152 commands are only executed once, we don't need to copy it; we
2153 can clear the pointer in the bpstat, and make sure we free
2154 the tree when we're done. */
2157 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2161 execute_control_command (cmd
);
2163 if (breakpoint_proceeded
)
2169 /* We can free this command tree now. */
2170 do_cleanups (this_cmd_tree_chain
);
2172 if (breakpoint_proceeded
)
2174 if (target_can_async_p ())
2175 /* If we are in async mode, then the target might be still
2176 running, not stopped at any breakpoint, so nothing for
2177 us to do here -- just return to the event loop. */
2180 /* In sync mode, when execute_control_command returns
2181 we're already standing on the next breakpoint.
2182 Breakpoint commands for that stop were not run, since
2183 execute_command does not run breakpoint commands --
2184 only command_line_handler does, but that one is not
2185 involved in execution of breakpoint commands. So, we
2186 can now execute breakpoint commands. It should be
2187 noted that making execute_command do bpstat actions is
2188 not an option -- in this case we'll have recursive
2189 invocation of bpstat for each breakpoint with a
2190 command, and can easily blow up GDB stack. Instead, we
2191 return true, which will trigger the caller to recall us
2192 with the new stop_bpstat. */
2197 do_cleanups (old_chain
);
2202 bpstat_do_actions (void)
2204 /* Do any commands attached to breakpoint we are stopped at. */
2205 while (!ptid_equal (inferior_ptid
, null_ptid
)
2206 && target_has_execution
2207 && !is_exited (inferior_ptid
)
2208 && !is_executing (inferior_ptid
))
2209 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2210 and only return when it is stopped at the next breakpoint, we
2211 keep doing breakpoint actions until it returns false to
2212 indicate the inferior was not resumed. */
2213 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2217 /* Print out the (old or new) value associated with a watchpoint. */
2220 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2223 fprintf_unfiltered (stream
, _("<unreadable>"));
2226 struct value_print_options opts
;
2227 get_user_print_options (&opts
);
2228 value_print (val
, stream
, &opts
);
2232 /* This is the normal print function for a bpstat. In the future,
2233 much of this logic could (should?) be moved to bpstat_stop_status,
2234 by having it set different print_it values.
2236 Current scheme: When we stop, bpstat_print() is called. It loops
2237 through the bpstat list of things causing this stop, calling the
2238 print_bp_stop_message function on each one. The behavior of the
2239 print_bp_stop_message function depends on the print_it field of
2240 bpstat. If such field so indicates, call this function here.
2242 Return values from this routine (ultimately used by bpstat_print()
2243 and normal_stop() to decide what to do):
2244 PRINT_NOTHING: Means we already printed all we needed to print,
2245 don't print anything else.
2246 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2247 that something to be followed by a location.
2248 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2249 that something to be followed by a location.
2250 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2253 static enum print_stop_action
2254 print_it_typical (bpstat bs
)
2256 struct cleanup
*old_chain
, *ui_out_chain
;
2257 struct breakpoint
*b
;
2258 const struct bp_location
*bl
;
2259 struct ui_stream
*stb
;
2261 stb
= ui_out_stream_new (uiout
);
2262 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2263 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2264 which has since been deleted. */
2265 if (bs
->breakpoint_at
== NULL
)
2266 return PRINT_UNKNOWN
;
2267 bl
= bs
->breakpoint_at
;
2273 case bp_hardware_breakpoint
:
2274 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2275 if (bl
->address
!= bl
->requested_address
)
2276 breakpoint_adjustment_warning (bl
->requested_address
,
2279 annotate_breakpoint (b
->number
);
2281 ui_out_text (uiout
, "\nTemporary breakpoint ");
2283 ui_out_text (uiout
, "\nBreakpoint ");
2284 if (ui_out_is_mi_like_p (uiout
))
2286 ui_out_field_string (uiout
, "reason",
2287 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2288 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2290 ui_out_field_int (uiout
, "bkptno", b
->number
);
2291 ui_out_text (uiout
, ", ");
2292 return PRINT_SRC_AND_LOC
;
2295 case bp_shlib_event
:
2296 /* Did we stop because the user set the stop_on_solib_events
2297 variable? (If so, we report this as a generic, "Stopped due
2298 to shlib event" message.) */
2299 printf_filtered (_("Stopped due to shared library event\n"));
2300 return PRINT_NOTHING
;
2303 case bp_thread_event
:
2304 /* Not sure how we will get here.
2305 GDB should not stop for these breakpoints. */
2306 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2307 return PRINT_NOTHING
;
2310 case bp_overlay_event
:
2311 /* By analogy with the thread event, GDB should not stop for these. */
2312 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2313 return PRINT_NOTHING
;
2317 annotate_catchpoint (b
->number
);
2318 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2320 b
->triggered_dll_pathname
);
2321 return PRINT_SRC_AND_LOC
;
2324 case bp_catch_unload
:
2325 annotate_catchpoint (b
->number
);
2326 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2328 b
->triggered_dll_pathname
);
2329 return PRINT_SRC_AND_LOC
;
2333 case bp_hardware_watchpoint
:
2334 annotate_watchpoint (b
->number
);
2335 if (ui_out_is_mi_like_p (uiout
))
2338 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2340 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2341 ui_out_text (uiout
, "\nOld value = ");
2342 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2343 ui_out_field_stream (uiout
, "old", stb
);
2344 ui_out_text (uiout
, "\nNew value = ");
2345 watchpoint_value_print (b
->val
, stb
->stream
);
2346 ui_out_field_stream (uiout
, "new", stb
);
2347 do_cleanups (ui_out_chain
);
2348 ui_out_text (uiout
, "\n");
2349 /* More than one watchpoint may have been triggered. */
2350 return PRINT_UNKNOWN
;
2353 case bp_read_watchpoint
:
2354 if (ui_out_is_mi_like_p (uiout
))
2357 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2359 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2360 ui_out_text (uiout
, "\nValue = ");
2361 watchpoint_value_print (b
->val
, stb
->stream
);
2362 ui_out_field_stream (uiout
, "value", stb
);
2363 do_cleanups (ui_out_chain
);
2364 ui_out_text (uiout
, "\n");
2365 return PRINT_UNKNOWN
;
2368 case bp_access_watchpoint
:
2369 if (bs
->old_val
!= NULL
)
2371 annotate_watchpoint (b
->number
);
2372 if (ui_out_is_mi_like_p (uiout
))
2375 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2377 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2378 ui_out_text (uiout
, "\nOld value = ");
2379 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2380 ui_out_field_stream (uiout
, "old", stb
);
2381 ui_out_text (uiout
, "\nNew value = ");
2386 if (ui_out_is_mi_like_p (uiout
))
2389 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2390 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2391 ui_out_text (uiout
, "\nValue = ");
2393 watchpoint_value_print (b
->val
, stb
->stream
);
2394 ui_out_field_stream (uiout
, "new", stb
);
2395 do_cleanups (ui_out_chain
);
2396 ui_out_text (uiout
, "\n");
2397 return PRINT_UNKNOWN
;
2400 /* Fall through, we don't deal with these types of breakpoints
2404 if (ui_out_is_mi_like_p (uiout
))
2407 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2408 return PRINT_UNKNOWN
;
2412 if (ui_out_is_mi_like_p (uiout
))
2415 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2416 return PRINT_UNKNOWN
;
2421 case bp_longjmp_resume
:
2422 case bp_step_resume
:
2423 case bp_watchpoint_scope
:
2426 return PRINT_UNKNOWN
;
2430 /* Generic routine for printing messages indicating why we
2431 stopped. The behavior of this function depends on the value
2432 'print_it' in the bpstat structure. Under some circumstances we
2433 may decide not to print anything here and delegate the task to
2436 static enum print_stop_action
2437 print_bp_stop_message (bpstat bs
)
2439 switch (bs
->print_it
)
2442 /* Nothing should be printed for this bpstat entry. */
2443 return PRINT_UNKNOWN
;
2447 /* We still want to print the frame, but we already printed the
2448 relevant messages. */
2449 return PRINT_SRC_AND_LOC
;
2452 case print_it_normal
:
2454 const struct bp_location
*bl
= bs
->breakpoint_at
;
2455 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2457 /* Normal case. Call the breakpoint's print_it method, or
2458 print_it_typical. */
2459 /* FIXME: how breakpoint can ever be NULL here? */
2460 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2461 return b
->ops
->print_it (b
);
2463 return print_it_typical (bs
);
2468 internal_error (__FILE__
, __LINE__
,
2469 _("print_bp_stop_message: unrecognized enum value"));
2474 /* Print a message indicating what happened. This is called from
2475 normal_stop(). The input to this routine is the head of the bpstat
2476 list - a list of the eventpoints that caused this stop. This
2477 routine calls the generic print routine for printing a message
2478 about reasons for stopping. This will print (for example) the
2479 "Breakpoint n," part of the output. The return value of this
2482 PRINT_UNKNOWN: Means we printed nothing
2483 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2484 code to print the location. An example is
2485 "Breakpoint 1, " which should be followed by
2487 PRINT_SRC_ONLY: Means we printed something, but there is no need
2488 to also print the location part of the message.
2489 An example is the catch/throw messages, which
2490 don't require a location appended to the end.
2491 PRINT_NOTHING: We have done some printing and we don't need any
2492 further info to be printed.*/
2494 enum print_stop_action
2495 bpstat_print (bpstat bs
)
2499 /* Maybe another breakpoint in the chain caused us to stop.
2500 (Currently all watchpoints go on the bpstat whether hit or not.
2501 That probably could (should) be changed, provided care is taken
2502 with respect to bpstat_explains_signal). */
2503 for (; bs
; bs
= bs
->next
)
2505 val
= print_bp_stop_message (bs
);
2506 if (val
== PRINT_SRC_ONLY
2507 || val
== PRINT_SRC_AND_LOC
2508 || val
== PRINT_NOTHING
)
2512 /* We reached the end of the chain, or we got a null BS to start
2513 with and nothing was printed. */
2514 return PRINT_UNKNOWN
;
2517 /* Evaluate the expression EXP and return 1 if value is zero.
2518 This is used inside a catch_errors to evaluate the breakpoint condition.
2519 The argument is a "struct expression *" that has been cast to char * to
2520 make it pass through catch_errors. */
2523 breakpoint_cond_eval (void *exp
)
2525 struct value
*mark
= value_mark ();
2526 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2527 value_free_to_mark (mark
);
2531 /* Allocate a new bpstat and chain it to the current one. */
2534 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2538 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2540 bs
->breakpoint_at
= bl
;
2541 /* If the condition is false, etc., don't do the commands. */
2542 bs
->commands
= NULL
;
2544 bs
->print_it
= print_it_normal
;
2548 /* The target has stopped with waitstatus WS. Check if any hardware
2549 watchpoints have triggered, according to the target. */
2552 watchpoints_triggered (struct target_waitstatus
*ws
)
2554 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2556 struct breakpoint
*b
;
2558 if (!stopped_by_watchpoint
)
2560 /* We were not stopped by a watchpoint. Mark all watchpoints
2561 as not triggered. */
2563 if (b
->type
== bp_hardware_watchpoint
2564 || b
->type
== bp_read_watchpoint
2565 || b
->type
== bp_access_watchpoint
)
2566 b
->watchpoint_triggered
= watch_triggered_no
;
2571 if (!target_stopped_data_address (¤t_target
, &addr
))
2573 /* We were stopped by a watchpoint, but we don't know where.
2574 Mark all watchpoints as unknown. */
2576 if (b
->type
== bp_hardware_watchpoint
2577 || b
->type
== bp_read_watchpoint
2578 || b
->type
== bp_access_watchpoint
)
2579 b
->watchpoint_triggered
= watch_triggered_unknown
;
2581 return stopped_by_watchpoint
;
2584 /* The target could report the data address. Mark watchpoints
2585 affected by this data address as triggered, and all others as not
2589 if (b
->type
== bp_hardware_watchpoint
2590 || b
->type
== bp_read_watchpoint
2591 || b
->type
== bp_access_watchpoint
)
2593 struct bp_location
*loc
;
2596 b
->watchpoint_triggered
= watch_triggered_no
;
2597 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2598 /* Exact match not required. Within range is
2600 if (target_watchpoint_addr_within_range (¤t_target
,
2604 b
->watchpoint_triggered
= watch_triggered_yes
;
2612 /* Possible return values for watchpoint_check (this can't be an enum
2613 because of check_errors). */
2614 /* The watchpoint has been deleted. */
2615 #define WP_DELETED 1
2616 /* The value has changed. */
2617 #define WP_VALUE_CHANGED 2
2618 /* The value has not changed. */
2619 #define WP_VALUE_NOT_CHANGED 3
2621 #define BP_TEMPFLAG 1
2622 #define BP_HARDWAREFLAG 2
2624 /* Check watchpoint condition. */
2627 watchpoint_check (void *p
)
2629 bpstat bs
= (bpstat
) p
;
2630 struct breakpoint
*b
;
2631 struct frame_info
*fr
;
2632 int within_current_scope
;
2634 b
= bs
->breakpoint_at
->owner
;
2636 if (b
->exp_valid_block
== NULL
)
2637 within_current_scope
= 1;
2640 /* There is no current frame at this moment. If we're going to have
2641 any chance of handling watchpoints on local variables, we'll need
2642 the frame chain (so we can determine if we're in scope). */
2643 reinit_frame_cache ();
2644 fr
= frame_find_by_id (b
->watchpoint_frame
);
2645 within_current_scope
= (fr
!= NULL
);
2647 /* If we've gotten confused in the unwinder, we might have
2648 returned a frame that can't describe this variable. */
2649 if (within_current_scope
2650 && (block_linkage_function (b
->exp_valid_block
)
2651 != get_frame_function (fr
)))
2652 within_current_scope
= 0;
2654 /* in_function_epilogue_p() returns a non-zero value if we're still
2655 in the function but the stack frame has already been invalidated.
2656 Since we can't rely on the values of local variables after the
2657 stack has been destroyed, we are treating the watchpoint in that
2658 state as `not changed' without further checking.
2660 vinschen/2003-09-04: The former implementation left out the case
2661 that the watchpoint frame couldn't be found by frame_find_by_id()
2662 because the current PC is currently in an epilogue. Calling
2663 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2664 if ((!within_current_scope
|| fr
== get_current_frame ())
2665 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2666 return WP_VALUE_NOT_CHANGED
;
2667 if (fr
&& within_current_scope
)
2668 /* If we end up stopping, the current frame will get selected
2669 in normal_stop. So this call to select_frame won't affect
2674 if (within_current_scope
)
2676 /* We use value_{,free_to_}mark because it could be a
2677 *long* time before we return to the command level and
2678 call free_all_values. We can't call free_all_values because
2679 we might be in the middle of evaluating a function call. */
2681 struct value
*mark
= value_mark ();
2682 struct value
*new_val
;
2684 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2685 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2686 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2688 if (new_val
!= NULL
)
2690 release_value (new_val
);
2691 value_free_to_mark (mark
);
2693 bs
->old_val
= b
->val
;
2696 /* We will stop here */
2697 return WP_VALUE_CHANGED
;
2701 /* Nothing changed, don't do anything. */
2702 value_free_to_mark (mark
);
2703 /* We won't stop here */
2704 return WP_VALUE_NOT_CHANGED
;
2709 /* This seems like the only logical thing to do because
2710 if we temporarily ignored the watchpoint, then when
2711 we reenter the block in which it is valid it contains
2712 garbage (in the case of a function, it may have two
2713 garbage values, one before and one after the prologue).
2714 So we can't even detect the first assignment to it and
2715 watch after that (since the garbage may or may not equal
2716 the first value assigned). */
2717 /* We print all the stop information in print_it_typical(), but
2718 in this case, by the time we call print_it_typical() this bp
2719 will be deleted already. So we have no choice but print the
2720 information here. */
2721 if (ui_out_is_mi_like_p (uiout
))
2723 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2724 ui_out_text (uiout
, "\nWatchpoint ");
2725 ui_out_field_int (uiout
, "wpnum", b
->number
);
2726 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2727 which its expression is valid.\n");
2729 if (b
->related_breakpoint
)
2730 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2731 b
->disposition
= disp_del_at_next_stop
;
2737 /* Return true if it looks like target has stopped due to hitting
2738 breakpoint location BL. This function does not check if we
2739 should stop, only if BL explains the stop. */
2741 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2743 struct breakpoint
*b
= bl
->owner
;
2745 if (b
->type
!= bp_watchpoint
2746 && b
->type
!= bp_hardware_watchpoint
2747 && b
->type
!= bp_read_watchpoint
2748 && b
->type
!= bp_access_watchpoint
2749 && b
->type
!= bp_hardware_breakpoint
2750 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
2752 if (bl
->address
!= bp_addr
) /* address doesn't match */
2754 if (overlay_debugging
/* unmapped overlay section */
2755 && section_is_overlay (bl
->section
)
2756 && !section_is_mapped (bl
->section
))
2760 /* Continuable hardware watchpoints are treated as non-existent if the
2761 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2762 some data address). Otherwise gdb won't stop on a break instruction
2763 in the code (not from a breakpoint) when a hardware watchpoint has
2764 been defined. Also skip watchpoints which we know did not trigger
2765 (did not match the data address). */
2767 if ((b
->type
== bp_hardware_watchpoint
2768 || b
->type
== bp_read_watchpoint
2769 || b
->type
== bp_access_watchpoint
)
2770 && b
->watchpoint_triggered
== watch_triggered_no
)
2773 if (b
->type
== bp_hardware_breakpoint
)
2775 if (bl
->address
!= bp_addr
)
2777 if (overlay_debugging
/* unmapped overlay section */
2778 && section_is_overlay (bl
->section
)
2779 && !section_is_mapped (bl
->section
))
2783 /* Is this a catchpoint of a load or unload? If so, did we
2784 get a load or unload of the specified library? If not,
2786 if ((b
->type
== bp_catch_load
)
2787 #if defined(SOLIB_HAVE_LOAD_EVENT)
2788 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2789 || ((b
->dll_pathname
!= NULL
)
2790 && (strcmp (b
->dll_pathname
,
2791 SOLIB_LOADED_LIBRARY_PATHNAME (
2792 PIDGET (inferior_ptid
)))
2798 if ((b
->type
== bp_catch_unload
)
2799 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2800 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2801 || ((b
->dll_pathname
!= NULL
)
2802 && (strcmp (b
->dll_pathname
,
2803 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2804 PIDGET (inferior_ptid
)))
2810 if (b
->type
== bp_catchpoint
)
2812 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2813 if (!b
->ops
->breakpoint_hit (b
))
2820 /* If BS refers to a watchpoint, determine if the watched values
2821 has actually changed, and we should stop. If not, set BS->stop
2824 bpstat_check_watchpoint (bpstat bs
)
2826 const struct bp_location
*bl
= bs
->breakpoint_at
;
2827 struct breakpoint
*b
= bl
->owner
;
2829 if (b
->type
== bp_watchpoint
2830 || b
->type
== bp_read_watchpoint
2831 || b
->type
== bp_access_watchpoint
2832 || b
->type
== bp_hardware_watchpoint
)
2836 int must_check_value
= 0;
2838 if (b
->type
== bp_watchpoint
)
2839 /* For a software watchpoint, we must always check the
2841 must_check_value
= 1;
2842 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2843 /* We have a hardware watchpoint (read, write, or access)
2844 and the target earlier reported an address watched by
2846 must_check_value
= 1;
2847 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2848 && b
->type
== bp_hardware_watchpoint
)
2849 /* We were stopped by a hardware watchpoint, but the target could
2850 not report the data address. We must check the watchpoint's
2851 value. Access and read watchpoints are out of luck; without
2852 a data address, we can't figure it out. */
2853 must_check_value
= 1;
2855 if (must_check_value
)
2857 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2859 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2860 int e
= catch_errors (watchpoint_check
, bs
, message
,
2862 do_cleanups (cleanups
);
2866 /* We've already printed what needs to be printed. */
2867 bs
->print_it
= print_it_done
;
2870 case WP_VALUE_CHANGED
:
2871 if (b
->type
== bp_read_watchpoint
)
2873 /* Don't stop: read watchpoints shouldn't fire if
2874 the value has changed. This is for targets
2875 which cannot set read-only watchpoints. */
2876 bs
->print_it
= print_it_noop
;
2880 case WP_VALUE_NOT_CHANGED
:
2881 if (b
->type
== bp_hardware_watchpoint
2882 || b
->type
== bp_watchpoint
)
2884 /* Don't stop: write watchpoints shouldn't fire if
2885 the value hasn't changed. */
2886 bs
->print_it
= print_it_noop
;
2894 /* Error from catch_errors. */
2895 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2896 if (b
->related_breakpoint
)
2897 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2898 b
->disposition
= disp_del_at_next_stop
;
2899 /* We've already printed what needs to be printed. */
2900 bs
->print_it
= print_it_done
;
2904 else /* must_check_value == 0 */
2906 /* This is a case where some watchpoint(s) triggered, but
2907 not at the address of this watchpoint, or else no
2908 watchpoint triggered after all. So don't print
2909 anything for this watchpoint. */
2910 bs
->print_it
= print_it_noop
;
2917 /* Check conditions (condition proper, frame, thread and ignore count)
2918 of breakpoint referred to by BS. If we should not stop for this
2919 breakpoint, set BS->stop to 0. */
2921 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2923 int thread_id
= pid_to_thread_id (ptid
);
2924 const struct bp_location
*bl
= bs
->breakpoint_at
;
2925 struct breakpoint
*b
= bl
->owner
;
2927 if (frame_id_p (b
->frame_id
)
2928 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2932 int value_is_zero
= 0;
2934 /* If this is a scope breakpoint, mark the associated
2935 watchpoint as triggered so that we will handle the
2936 out-of-scope event. We'll get to the watchpoint next
2938 if (b
->type
== bp_watchpoint_scope
)
2939 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2941 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2943 /* Need to select the frame, with all that implies
2944 so that the conditions will have the right context. */
2945 select_frame (get_current_frame ());
2947 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2948 "Error in testing breakpoint condition:\n",
2950 /* FIXME-someday, should give breakpoint # */
2953 if (bl
->cond
&& value_is_zero
)
2957 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2961 else if (b
->ignore_count
> 0)
2964 annotate_ignore_count_change ();
2966 /* Increase the hit count even though we don't
2974 /* Get a bpstat associated with having just stopped at address
2975 BP_ADDR in thread PTID.
2977 Determine whether we stopped at a breakpoint, etc, or whether we
2978 don't understand this stop. Result is a chain of bpstat's such that:
2980 if we don't understand the stop, the result is a null pointer.
2982 if we understand why we stopped, the result is not null.
2984 Each element of the chain refers to a particular breakpoint or
2985 watchpoint at which we have stopped. (We may have stopped for
2986 several reasons concurrently.)
2988 Each element of the chain has valid next, breakpoint_at,
2989 commands, FIXME??? fields. */
2992 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2994 struct breakpoint
*b
= NULL
;
2995 const struct bp_location
*bl
;
2996 struct bp_location
*loc
;
2997 /* Root of the chain of bpstat's */
2998 struct bpstats root_bs
[1];
2999 /* Pointer to the last thing in the chain currently. */
3000 bpstat bs
= root_bs
;
3002 int need_remove_insert
;
3004 ALL_BP_LOCATIONS (bl
)
3008 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3011 /* For hardware watchpoints, we look only at the first location.
3012 The watchpoint_check function will work on entire expression,
3013 not the individual locations. For read watchopints, the
3014 watchpoints_triggered function have checked all locations
3017 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3020 if (!bpstat_check_location (bl
, bp_addr
))
3023 /* Come here if it's a watchpoint, or if the break address matches */
3025 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3027 /* Assume we stop. Should we find watchpoint that is not actually
3028 triggered, or if condition of breakpoint is false, we'll reset
3033 bpstat_check_watchpoint (bs
);
3037 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3038 /* We do not stop for these. */
3041 bpstat_check_breakpoint_conditions (bs
, ptid
);
3047 /* We will stop here */
3048 if (b
->disposition
== disp_disable
)
3050 if (b
->enable_state
!= bp_permanent
)
3051 b
->enable_state
= bp_disabled
;
3052 update_global_location_list (0);
3056 bs
->commands
= b
->commands
;
3058 (strcmp ("silent", bs
->commands
->line
) == 0
3059 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3061 bs
->commands
= bs
->commands
->next
;
3064 bs
->commands
= copy_command_lines (bs
->commands
);
3067 /* Print nothing for this entry if we dont stop or if we dont print. */
3068 if (bs
->stop
== 0 || bs
->print
== 0)
3069 bs
->print_it
= print_it_noop
;
3072 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3074 if (loc
->address
== bp_addr
)
3076 bs
= bpstat_alloc (loc
, bs
);
3077 /* For hits of moribund locations, we should just proceed. */
3080 bs
->print_it
= print_it_noop
;
3084 bs
->next
= NULL
; /* Terminate the chain */
3085 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3087 /* If we aren't stopping, the value of some hardware watchpoint may
3088 not have changed, but the intermediate memory locations we are
3089 watching may have. Don't bother if we're stopping; this will get
3091 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3095 need_remove_insert
= 0;
3097 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3099 && bs
->breakpoint_at
->owner
3100 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3101 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3102 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3104 /* remove/insert can invalidate bs->breakpoint_at, if this
3105 location is no longer used by the watchpoint. Prevent
3106 further code from trying to use it. */
3107 bs
->breakpoint_at
= NULL
;
3108 need_remove_insert
= 1;
3111 if (need_remove_insert
)
3113 remove_breakpoints ();
3114 insert_breakpoints ();
3117 return root_bs
->next
;
3120 /* Tell what to do about this bpstat. */
3122 bpstat_what (bpstat bs
)
3124 /* Classify each bpstat as one of the following. */
3127 /* This bpstat element has no effect on the main_action. */
3130 /* There was a watchpoint, stop but don't print. */
3133 /* There was a watchpoint, stop and print. */
3136 /* There was a breakpoint but we're not stopping. */
3139 /* There was a breakpoint, stop but don't print. */
3142 /* There was a breakpoint, stop and print. */
3145 /* We hit the longjmp breakpoint. */
3148 /* We hit the longjmp_resume breakpoint. */
3151 /* We hit the step_resume breakpoint. */
3154 /* We hit the shared library event breakpoint. */
3157 /* We caught a shared library event. */
3160 /* This is just used to count how many enums there are. */
3164 /* Here is the table which drives this routine. So that we can
3165 format it pretty, we define some abbreviations for the
3166 enum bpstat_what codes. */
3167 #define kc BPSTAT_WHAT_KEEP_CHECKING
3168 #define ss BPSTAT_WHAT_STOP_SILENT
3169 #define sn BPSTAT_WHAT_STOP_NOISY
3170 #define sgl BPSTAT_WHAT_SINGLE
3171 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3172 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3173 #define sr BPSTAT_WHAT_STEP_RESUME
3174 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3175 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3177 /* "Can't happen." Might want to print an error message.
3178 abort() is not out of the question, but chances are GDB is just
3179 a bit confused, not unusable. */
3180 #define err BPSTAT_WHAT_STOP_NOISY
3182 /* Given an old action and a class, come up with a new action. */
3183 /* One interesting property of this table is that wp_silent is the same
3184 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3185 after stopping, the check for whether to step over a breakpoint
3186 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3187 reference to how we stopped. We retain separate wp_silent and
3188 bp_silent codes in case we want to change that someday.
3190 Another possibly interesting property of this table is that
3191 there's a partial ordering, priority-like, of the actions. Once
3192 you've decided that some action is appropriate, you'll never go
3193 back and decide something of a lower priority is better. The
3196 kc < clr sgl shl shlr slr sn sr ss
3197 sgl < shl shlr slr sn sr ss
3198 slr < err shl shlr sn sr ss
3199 clr < err shl shlr sn sr ss
3206 What I think this means is that we don't need a damned table
3207 here. If you just put the rows and columns in the right order,
3208 it'd look awfully regular. We could simply walk the bpstat list
3209 and choose the highest priority action we find, with a little
3210 logic to handle the 'err' cases. */
3212 /* step_resume entries: a step resume breakpoint overrides another
3213 breakpoint of signal handling (see comment in wait_for_inferior
3214 at where we set the step_resume breakpoint). */
3216 static const enum bpstat_what_main_action
3217 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3220 /* kc ss sn sgl slr clr sr shl shlr
3223 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, shlr
},
3225 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3227 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3229 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, shlr
},
3231 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3233 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3235 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, shlr
},
3237 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, shlr
},
3239 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3241 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3243 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3257 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3258 struct bpstat_what retval
;
3260 retval
.call_dummy
= 0;
3261 for (; bs
!= NULL
; bs
= bs
->next
)
3263 enum class bs_class
= no_effect
;
3264 if (bs
->breakpoint_at
== NULL
)
3265 /* I suspect this can happen if it was a momentary breakpoint
3266 which has since been deleted. */
3268 if (bs
->breakpoint_at
->owner
== NULL
)
3269 bs_class
= bp_nostop
;
3271 switch (bs
->breakpoint_at
->owner
->type
)
3277 case bp_hardware_breakpoint
:
3283 bs_class
= bp_noisy
;
3285 bs_class
= bp_silent
;
3288 bs_class
= bp_nostop
;
3291 case bp_hardware_watchpoint
:
3292 case bp_read_watchpoint
:
3293 case bp_access_watchpoint
:
3297 bs_class
= wp_noisy
;
3299 bs_class
= wp_silent
;
3302 /* There was a watchpoint, but we're not stopping.
3303 This requires no further action. */
3304 bs_class
= no_effect
;
3307 bs_class
= long_jump
;
3309 case bp_longjmp_resume
:
3310 bs_class
= long_resume
;
3312 case bp_step_resume
:
3315 bs_class
= step_resume
;
3318 /* It is for the wrong frame. */
3319 bs_class
= bp_nostop
;
3321 case bp_watchpoint_scope
:
3322 bs_class
= bp_nostop
;
3324 case bp_shlib_event
:
3325 bs_class
= shlib_event
;
3327 case bp_thread_event
:
3328 case bp_overlay_event
:
3329 bs_class
= bp_nostop
;
3332 case bp_catch_unload
:
3333 /* Only if this catchpoint triggered should we cause the
3334 step-out-of-dld behaviour. Otherwise, we ignore this
3337 bs_class
= catch_shlib_event
;
3339 bs_class
= no_effect
;
3345 bs_class
= bp_noisy
;
3347 bs_class
= bp_silent
;
3350 /* There was a catchpoint, but we're not stopping.
3351 This requires no further action. */
3352 bs_class
= no_effect
;
3355 /* Make sure the action is stop (silent or noisy),
3356 so infrun.c pops the dummy frame. */
3357 bs_class
= bp_silent
;
3358 retval
.call_dummy
= 1;
3361 current_action
= table
[(int) bs_class
][(int) current_action
];
3363 retval
.main_action
= current_action
;
3367 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3368 without hardware support). This isn't related to a specific bpstat,
3369 just to things like whether watchpoints are set. */
3372 bpstat_should_step (void)
3374 struct breakpoint
*b
;
3376 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3383 /* Given a bpstat that records zero or more triggered eventpoints, this
3384 function returns another bpstat which contains only the catchpoints
3385 on that first list, if any. */
3387 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3389 struct bpstats root_bs
[1];
3390 bpstat bs
= root_bs
;
3391 struct breakpoint
*ep
;
3394 bpstat_clear (cp_list
);
3395 root_bs
->next
= NULL
;
3397 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3399 /* Is this eventpoint a catchpoint? If not, ignore it. */
3400 ep
= ep_list
->breakpoint_at
->owner
;
3403 if ((ep
->type
!= bp_catch_load
) &&
3404 (ep
->type
!= bp_catch_unload
))
3405 /* pai: (temp) ADD fork/vfork here!! */
3408 /* Yes; add it to the list. */
3409 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3414 #if defined(SOLIB_ADD)
3415 /* Also, for each triggered catchpoint, tag it with the name of
3416 the library that caused this trigger. (We copy the name now,
3417 because it's only guaranteed to be available NOW, when the
3418 catchpoint triggers. Clients who may wish to know the name
3419 later must get it from the catchpoint itself.) */
3420 if (ep
->triggered_dll_pathname
!= NULL
)
3421 xfree (ep
->triggered_dll_pathname
);
3422 if (ep
->type
== bp_catch_load
)
3423 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3424 PIDGET (inferior_ptid
));
3426 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3427 PIDGET (inferior_ptid
));
3429 dll_pathname
= NULL
;
3433 ep
->triggered_dll_pathname
= (char *)
3434 xmalloc (strlen (dll_pathname
) + 1);
3435 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3438 ep
->triggered_dll_pathname
= NULL
;
3444 static void print_breakpoint_location (struct breakpoint
*b
,
3445 struct bp_location
*loc
,
3447 struct ui_stream
*stb
)
3452 = find_pc_sect_function (loc
->address
, loc
->section
);
3455 ui_out_text (uiout
, "in ");
3456 ui_out_field_string (uiout
, "func",
3457 SYMBOL_PRINT_NAME (sym
));
3458 ui_out_wrap_hint (uiout
, wrap_indent
);
3459 ui_out_text (uiout
, " at ");
3461 ui_out_field_string (uiout
, "file", b
->source_file
);
3462 ui_out_text (uiout
, ":");
3464 if (ui_out_is_mi_like_p (uiout
))
3466 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3467 char *fullname
= symtab_to_fullname (sal
.symtab
);
3470 ui_out_field_string (uiout
, "fullname", fullname
);
3473 ui_out_field_int (uiout
, "line", b
->line_number
);
3477 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3481 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3482 ui_out_field_stream (uiout
, "at", stb
);
3486 /* Print B to gdb_stdout. */
3488 print_one_breakpoint_location (struct breakpoint
*b
,
3489 struct bp_location
*loc
,
3491 CORE_ADDR
*last_addr
)
3493 struct command_line
*l
;
3495 struct ep_type_description
3500 static struct ep_type_description bptypes
[] =
3502 {bp_none
, "?deleted?"},
3503 {bp_breakpoint
, "breakpoint"},
3504 {bp_hardware_breakpoint
, "hw breakpoint"},
3505 {bp_until
, "until"},
3506 {bp_finish
, "finish"},
3507 {bp_watchpoint
, "watchpoint"},
3508 {bp_hardware_watchpoint
, "hw watchpoint"},
3509 {bp_read_watchpoint
, "read watchpoint"},
3510 {bp_access_watchpoint
, "acc watchpoint"},
3511 {bp_longjmp
, "longjmp"},
3512 {bp_longjmp_resume
, "longjmp resume"},
3513 {bp_step_resume
, "step resume"},
3514 {bp_watchpoint_scope
, "watchpoint scope"},
3515 {bp_call_dummy
, "call dummy"},
3516 {bp_shlib_event
, "shlib events"},
3517 {bp_thread_event
, "thread events"},
3518 {bp_overlay_event
, "overlay events"},
3519 {bp_catchpoint
, "catchpoint"},
3520 {bp_catch_load
, "catch load"},
3521 {bp_catch_unload
, "catch unload"}
3524 static char bpenables
[] = "nynny";
3525 char wrap_indent
[80];
3526 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3527 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3528 struct cleanup
*bkpt_chain
;
3530 int header_of_multiple
= 0;
3531 int part_of_multiple
= (loc
!= NULL
);
3532 struct value_print_options opts
;
3534 get_user_print_options (&opts
);
3536 gdb_assert (!loc
|| loc_number
!= 0);
3537 /* See comment in print_one_breakpoint concerning
3538 treatment of breakpoints with single disabled
3542 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3543 header_of_multiple
= 1;
3548 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3552 if (part_of_multiple
)
3555 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3556 ui_out_field_string (uiout
, "number", formatted
);
3561 ui_out_field_int (uiout
, "number", b
->number
);
3566 if (part_of_multiple
)
3567 ui_out_field_skip (uiout
, "type");
3570 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3571 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3572 internal_error (__FILE__
, __LINE__
,
3573 _("bptypes table does not describe type #%d."),
3575 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3580 if (part_of_multiple
)
3581 ui_out_field_skip (uiout
, "disp");
3583 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3588 if (part_of_multiple
)
3589 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3591 ui_out_field_fmt (uiout
, "enabled", "%c",
3592 bpenables
[(int) b
->enable_state
]);
3593 ui_out_spaces (uiout
, 2);
3597 strcpy (wrap_indent
, " ");
3598 if (opts
.addressprint
)
3600 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3601 strcat (wrap_indent
, " ");
3603 strcat (wrap_indent
, " ");
3606 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3608 /* Although the print_one can possibly print
3609 all locations, calling it here is not likely
3610 to get any nice result. So, make sure there's
3611 just one location. */
3612 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3613 b
->ops
->print_one (b
, last_addr
);
3619 internal_error (__FILE__
, __LINE__
,
3620 _("print_one_breakpoint: bp_none encountered\n"));
3624 case bp_hardware_watchpoint
:
3625 case bp_read_watchpoint
:
3626 case bp_access_watchpoint
:
3627 /* Field 4, the address, is omitted (which makes the columns
3628 not line up too nicely with the headers, but the effect
3629 is relatively readable). */
3630 if (opts
.addressprint
)
3631 ui_out_field_skip (uiout
, "addr");
3633 print_expression (b
->exp
, stb
->stream
);
3634 ui_out_field_stream (uiout
, "what", stb
);
3638 case bp_catch_unload
:
3639 /* Field 4, the address, is omitted (which makes the columns
3640 not line up too nicely with the headers, but the effect
3641 is relatively readable). */
3642 if (opts
.addressprint
)
3643 ui_out_field_skip (uiout
, "addr");
3645 if (b
->dll_pathname
== NULL
)
3647 ui_out_field_string (uiout
, "what", "<any library>");
3648 ui_out_spaces (uiout
, 1);
3652 ui_out_text (uiout
, "library \"");
3653 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3654 ui_out_text (uiout
, "\" ");
3659 case bp_hardware_breakpoint
:
3663 case bp_longjmp_resume
:
3664 case bp_step_resume
:
3665 case bp_watchpoint_scope
:
3667 case bp_shlib_event
:
3668 case bp_thread_event
:
3669 case bp_overlay_event
:
3670 if (opts
.addressprint
)
3673 if (header_of_multiple
)
3674 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3675 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3676 ui_out_field_string (uiout
, "addr", "<PENDING>");
3678 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3681 if (!header_of_multiple
)
3682 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3684 *last_addr
= b
->loc
->address
;
3688 if (!part_of_multiple
&& b
->thread
!= -1)
3690 /* FIXME: This seems to be redundant and lost here; see the
3691 "stop only in" line a little further down. */
3692 ui_out_text (uiout
, " thread ");
3693 ui_out_field_int (uiout
, "thread", b
->thread
);
3696 ui_out_text (uiout
, "\n");
3698 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3701 ui_out_text (uiout
, "\tstop only in stack frame at ");
3702 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3704 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3705 ui_out_text (uiout
, "\n");
3708 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3710 /* We do not print the condition for Ada exception catchpoints
3711 because the condition is an internal implementation detail
3712 that we do not want to expose to the user. */
3714 ui_out_text (uiout
, "\tstop only if ");
3715 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3716 ui_out_text (uiout
, "\n");
3719 if (!part_of_multiple
&& b
->thread
!= -1)
3721 /* FIXME should make an annotation for this */
3722 ui_out_text (uiout
, "\tstop only in thread ");
3723 ui_out_field_int (uiout
, "thread", b
->thread
);
3724 ui_out_text (uiout
, "\n");
3727 if (!part_of_multiple
&& b
->hit_count
)
3729 /* FIXME should make an annotation for this */
3730 if (ep_is_catchpoint (b
))
3731 ui_out_text (uiout
, "\tcatchpoint");
3733 ui_out_text (uiout
, "\tbreakpoint");
3734 ui_out_text (uiout
, " already hit ");
3735 ui_out_field_int (uiout
, "times", b
->hit_count
);
3736 if (b
->hit_count
== 1)
3737 ui_out_text (uiout
, " time\n");
3739 ui_out_text (uiout
, " times\n");
3742 /* Output the count also if it is zero, but only if this is
3743 mi. FIXME: Should have a better test for this. */
3744 if (ui_out_is_mi_like_p (uiout
))
3745 if (!part_of_multiple
&& b
->hit_count
== 0)
3746 ui_out_field_int (uiout
, "times", b
->hit_count
);
3748 if (!part_of_multiple
&& b
->ignore_count
)
3751 ui_out_text (uiout
, "\tignore next ");
3752 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3753 ui_out_text (uiout
, " hits\n");
3756 if (!part_of_multiple
&& (l
= b
->commands
))
3758 struct cleanup
*script_chain
;
3761 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3762 print_command_lines (uiout
, l
, 4);
3763 do_cleanups (script_chain
);
3766 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3769 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3770 else if (b
->exp_string
)
3771 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3774 do_cleanups (bkpt_chain
);
3775 do_cleanups (old_chain
);
3779 print_one_breakpoint (struct breakpoint
*b
,
3780 CORE_ADDR
*last_addr
)
3782 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3784 /* If this breakpoint has custom print function,
3785 it's already printed. Otherwise, print individual
3786 locations, if any. */
3787 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3789 /* If breakpoint has a single location that is
3790 disabled, we print it as if it had
3791 several locations, since otherwise it's hard to
3792 represent "breakpoint enabled, location disabled"
3794 Note that while hardware watchpoints have
3795 several locations internally, that's no a property
3798 && !is_hardware_watchpoint (b
)
3799 && (b
->loc
->next
|| !b
->loc
->enabled
)
3800 && !ui_out_is_mi_like_p (uiout
))
3802 struct bp_location
*loc
;
3804 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3805 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3811 struct captured_breakpoint_query_args
3817 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3819 struct captured_breakpoint_query_args
*args
= data
;
3820 struct breakpoint
*b
;
3821 CORE_ADDR dummy_addr
= 0;
3824 if (args
->bnum
== b
->number
)
3826 print_one_breakpoint (b
, &dummy_addr
);
3834 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3836 struct captured_breakpoint_query_args args
;
3838 /* For the moment we don't trust print_one_breakpoint() to not throw
3840 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3841 error_message
, RETURN_MASK_ALL
) < 0)
3847 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3848 catchpoints, et.al.). */
3851 user_settable_breakpoint (const struct breakpoint
*b
)
3853 return (b
->type
== bp_breakpoint
3854 || b
->type
== bp_catchpoint
3855 || b
->type
== bp_catch_load
3856 || b
->type
== bp_catch_unload
3857 || b
->type
== bp_hardware_breakpoint
3858 || b
->type
== bp_watchpoint
3859 || b
->type
== bp_read_watchpoint
3860 || b
->type
== bp_access_watchpoint
3861 || b
->type
== bp_hardware_watchpoint
);
3864 /* Print information on user settable breakpoint (watchpoint, etc)
3865 number BNUM. If BNUM is -1 print all user settable breakpoints.
3866 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3869 breakpoint_1 (int bnum
, int allflag
)
3871 struct breakpoint
*b
;
3872 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3873 int nr_printable_breakpoints
;
3874 struct cleanup
*bkpttbl_chain
;
3875 struct value_print_options opts
;
3877 get_user_print_options (&opts
);
3879 /* Compute the number of rows in the table. */
3880 nr_printable_breakpoints
= 0;
3883 || bnum
== b
->number
)
3885 if (allflag
|| user_settable_breakpoint (b
))
3886 nr_printable_breakpoints
++;
3889 if (opts
.addressprint
)
3891 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3895 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3898 if (nr_printable_breakpoints
> 0)
3899 annotate_breakpoints_headers ();
3900 if (nr_printable_breakpoints
> 0)
3902 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3903 if (nr_printable_breakpoints
> 0)
3905 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3906 if (nr_printable_breakpoints
> 0)
3908 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3909 if (nr_printable_breakpoints
> 0)
3911 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3912 if (opts
.addressprint
)
3914 if (nr_printable_breakpoints
> 0)
3916 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3917 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3919 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3921 if (nr_printable_breakpoints
> 0)
3923 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3924 ui_out_table_body (uiout
);
3925 if (nr_printable_breakpoints
> 0)
3926 annotate_breakpoints_table ();
3930 || bnum
== b
->number
)
3932 /* We only print out user settable breakpoints unless the
3934 if (allflag
|| user_settable_breakpoint (b
))
3935 print_one_breakpoint (b
, &last_addr
);
3938 do_cleanups (bkpttbl_chain
);
3940 if (nr_printable_breakpoints
== 0)
3943 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3945 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3950 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3951 that a comparison of an unsigned with -1 is always false. */
3952 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3953 set_next_address (current_gdbarch
, last_addr
);
3956 /* FIXME? Should this be moved up so that it is only called when
3957 there have been breakpoints? */
3958 annotate_breakpoints_table_end ();
3962 breakpoints_info (char *bnum_exp
, int from_tty
)
3967 bnum
= parse_and_eval_long (bnum_exp
);
3969 breakpoint_1 (bnum
, 0);
3973 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3978 bnum
= parse_and_eval_long (bnum_exp
);
3980 breakpoint_1 (bnum
, 1);
3984 breakpoint_has_pc (struct breakpoint
*b
,
3985 CORE_ADDR pc
, struct obj_section
*section
)
3987 struct bp_location
*bl
= b
->loc
;
3988 for (; bl
; bl
= bl
->next
)
3990 if (bl
->address
== pc
3991 && (!overlay_debugging
|| bl
->section
== section
))
3997 /* Print a message describing any breakpoints set at PC. */
4000 describe_other_breakpoints (CORE_ADDR pc
, struct obj_section
*section
,
4004 struct breakpoint
*b
;
4007 others
+= breakpoint_has_pc (b
, pc
, section
);
4011 printf_filtered (_("Note: breakpoint "));
4012 else /* if (others == ???) */
4013 printf_filtered (_("Note: breakpoints "));
4015 if (breakpoint_has_pc (b
, pc
, section
))
4018 printf_filtered ("%d", b
->number
);
4019 if (b
->thread
== -1 && thread
!= -1)
4020 printf_filtered (" (all threads)");
4021 else if (b
->thread
!= -1)
4022 printf_filtered (" (thread %d)", b
->thread
);
4023 printf_filtered ("%s%s ",
4024 ((b
->enable_state
== bp_disabled
||
4025 b
->enable_state
== bp_call_disabled
)
4027 : b
->enable_state
== bp_permanent
4031 : ((others
== 1) ? " and" : ""));
4033 printf_filtered (_("also set at pc "));
4034 fputs_filtered (paddress (pc
), gdb_stdout
);
4035 printf_filtered (".\n");
4039 /* Set the default place to put a breakpoint
4040 for the `break' command with no arguments. */
4043 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4046 default_breakpoint_valid
= valid
;
4047 default_breakpoint_address
= addr
;
4048 default_breakpoint_symtab
= symtab
;
4049 default_breakpoint_line
= line
;
4052 /* Return true iff it is meaningful to use the address member of
4053 BPT. For some breakpoint types, the address member is irrelevant
4054 and it makes no sense to attempt to compare it to other addresses
4055 (or use it for any other purpose either).
4057 More specifically, each of the following breakpoint types will always
4058 have a zero valued address and we don't want check_duplicates() to mark
4059 breakpoints of any of these types to be a duplicate of an actual
4060 breakpoint at address zero:
4063 bp_hardware_watchpoint
4065 bp_access_watchpoint
4069 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4071 enum bptype type
= bpt
->type
;
4073 return (type
!= bp_watchpoint
4074 && type
!= bp_hardware_watchpoint
4075 && type
!= bp_read_watchpoint
4076 && type
!= bp_access_watchpoint
4077 && type
!= bp_catchpoint
);
4080 /* Rescan breakpoints at the same address and section as BPT,
4081 marking the first one as "first" and any others as "duplicates".
4082 This is so that the bpt instruction is only inserted once.
4083 If we have a permanent breakpoint at the same place as BPT, make
4084 that one the official one, and the rest as duplicates. */
4087 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
4089 struct bp_location
*b
;
4091 struct bp_location
*perm_bp
= 0;
4093 ALL_BP_LOCATIONS (b
)
4094 if (b
->owner
->enable_state
!= bp_disabled
4095 && b
->owner
->enable_state
!= bp_call_disabled
4097 && !b
->shlib_disabled
4098 && b
->address
== address
/* address / overlay match */
4099 && (!overlay_debugging
|| b
->section
== section
)
4100 && breakpoint_address_is_meaningful (b
->owner
))
4102 /* Have we found a permanent breakpoint? */
4103 if (b
->owner
->enable_state
== bp_permanent
)
4110 b
->duplicate
= count
> 1;
4113 /* If we found a permanent breakpoint at this address, go over the
4114 list again and declare all the other breakpoints there to be the
4118 perm_bp
->duplicate
= 0;
4120 /* Permanent breakpoint should always be inserted. */
4121 if (! perm_bp
->inserted
)
4122 internal_error (__FILE__
, __LINE__
,
4123 _("allegedly permanent breakpoint is not "
4124 "actually inserted"));
4126 ALL_BP_LOCATIONS (b
)
4129 if (b
->owner
->enable_state
!= bp_disabled
4130 && b
->owner
->enable_state
!= bp_call_disabled
4131 && b
->enabled
&& !b
->shlib_disabled
4132 && b
->address
== address
/* address / overlay match */
4133 && (!overlay_debugging
|| b
->section
== section
)
4134 && breakpoint_address_is_meaningful (b
->owner
))
4137 internal_error (__FILE__
, __LINE__
,
4138 _("another breakpoint was inserted on top of "
4139 "a permanent breakpoint"));
4148 check_duplicates (struct breakpoint
*bpt
)
4150 struct bp_location
*bl
= bpt
->loc
;
4152 if (! breakpoint_address_is_meaningful (bpt
))
4155 for (; bl
; bl
= bl
->next
)
4156 check_duplicates_for (bl
->address
, bl
->section
);
4160 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4161 int bnum
, int have_bnum
)
4166 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4167 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4169 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4170 bnum
, astr1
, astr2
);
4172 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4175 /* Adjust a breakpoint's address to account for architectural constraints
4176 on breakpoint placement. Return the adjusted address. Note: Very
4177 few targets require this kind of adjustment. For most targets,
4178 this function is simply the identity function. */
4181 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4183 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4185 /* Very few targets need any kind of breakpoint adjustment. */
4188 else if (bptype
== bp_watchpoint
4189 || bptype
== bp_hardware_watchpoint
4190 || bptype
== bp_read_watchpoint
4191 || bptype
== bp_access_watchpoint
4192 || bptype
== bp_catchpoint
)
4194 /* Watchpoints and the various bp_catch_* eventpoints should not
4195 have their addresses modified. */
4200 CORE_ADDR adjusted_bpaddr
;
4202 /* Some targets have architectural constraints on the placement
4203 of breakpoint instructions. Obtain the adjusted address. */
4204 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4207 /* An adjusted breakpoint address can significantly alter
4208 a user's expectations. Print a warning if an adjustment
4210 if (adjusted_bpaddr
!= bpaddr
)
4211 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4213 return adjusted_bpaddr
;
4217 /* Allocate a struct bp_location. */
4219 static struct bp_location
*
4220 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4222 struct bp_location
*loc
, *loc_p
;
4224 loc
= xmalloc (sizeof (struct bp_location
));
4225 memset (loc
, 0, sizeof (*loc
));
4229 loc
->shlib_disabled
= 0;
4238 case bp_longjmp_resume
:
4239 case bp_step_resume
:
4240 case bp_watchpoint_scope
:
4242 case bp_shlib_event
:
4243 case bp_thread_event
:
4244 case bp_overlay_event
:
4246 case bp_catch_unload
:
4247 loc
->loc_type
= bp_loc_software_breakpoint
;
4249 case bp_hardware_breakpoint
:
4250 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4252 case bp_hardware_watchpoint
:
4253 case bp_read_watchpoint
:
4254 case bp_access_watchpoint
:
4255 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4259 loc
->loc_type
= bp_loc_other
;
4262 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4268 static void free_bp_location (struct bp_location
*loc
)
4273 if (loc
->function_name
)
4274 xfree (loc
->function_name
);
4279 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4280 that has type BPTYPE and has no locations as yet. */
4282 static struct breakpoint
*
4283 set_raw_breakpoint_without_location (enum bptype bptype
)
4285 struct breakpoint
*b
, *b1
;
4287 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4288 memset (b
, 0, sizeof (*b
));
4291 b
->language
= current_language
->la_language
;
4292 b
->input_radix
= input_radix
;
4294 b
->enable_state
= bp_enabled
;
4297 b
->ignore_count
= 0;
4299 b
->frame_id
= null_frame_id
;
4300 b
->dll_pathname
= NULL
;
4301 b
->triggered_dll_pathname
= NULL
;
4302 b
->forked_inferior_pid
= null_ptid
;
4303 b
->exec_pathname
= NULL
;
4305 b
->condition_not_parsed
= 0;
4307 /* Add this breakpoint to the end of the chain
4308 so that a list of breakpoints will come out in order
4309 of increasing numbers. */
4311 b1
= breakpoint_chain
;
4313 breakpoint_chain
= b
;
4323 /* Initialize loc->function_name. */
4325 set_breakpoint_location_function (struct bp_location
*loc
)
4327 if (loc
->owner
->type
== bp_breakpoint
4328 || loc
->owner
->type
== bp_hardware_breakpoint
)
4330 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4332 if (loc
->function_name
)
4333 loc
->function_name
= xstrdup (loc
->function_name
);
4337 /* set_raw_breakpoint is a low level routine for allocating and
4338 partially initializing a breakpoint of type BPTYPE. The newly
4339 created breakpoint's address, section, source file name, and line
4340 number are provided by SAL. The newly created and partially
4341 initialized breakpoint is added to the breakpoint chain and
4342 is also returned as the value of this function.
4344 It is expected that the caller will complete the initialization of
4345 the newly created breakpoint struct as well as output any status
4346 information regarding the creation of a new breakpoint. In
4347 particular, set_raw_breakpoint does NOT set the breakpoint
4348 number! Care should be taken to not allow an error to occur
4349 prior to completing the initialization of the breakpoint. If this
4350 should happen, a bogus breakpoint will be left on the chain. */
4353 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4355 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4356 CORE_ADDR adjusted_address
;
4358 /* Adjust the breakpoint's address prior to allocating a location.
4359 Once we call allocate_bp_location(), that mostly uninitialized
4360 location will be placed on the location chain. Adjustment of the
4361 breakpoint may cause target_read_memory() to be called and we do
4362 not want its scan of the location chain to find a breakpoint and
4363 location that's only been partially initialized. */
4364 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4366 b
->loc
= allocate_bp_location (b
, bptype
);
4367 b
->loc
->requested_address
= sal
.pc
;
4368 b
->loc
->address
= adjusted_address
;
4370 if (sal
.symtab
== NULL
)
4371 b
->source_file
= NULL
;
4373 b
->source_file
= savestring (sal
.symtab
->filename
,
4374 strlen (sal
.symtab
->filename
));
4375 b
->loc
->section
= sal
.section
;
4376 b
->line_number
= sal
.line
;
4378 set_breakpoint_location_function (b
->loc
);
4380 breakpoints_changed ();
4386 /* Note that the breakpoint object B describes a permanent breakpoint
4387 instruction, hard-wired into the inferior's code. */
4389 make_breakpoint_permanent (struct breakpoint
*b
)
4391 struct bp_location
*bl
;
4392 b
->enable_state
= bp_permanent
;
4394 /* By definition, permanent breakpoints are already present in the code.
4395 Mark all locations as inserted. For now, make_breakpoint_permanent
4396 is called in just one place, so it's hard to say if it's reasonable
4397 to have permanent breakpoint with multiple locations or not,
4398 but it's easy to implmement. */
4399 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4403 static struct breakpoint
*
4404 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4406 static int internal_breakpoint_number
= -1;
4407 struct symtab_and_line sal
;
4408 struct breakpoint
*b
;
4410 init_sal (&sal
); /* initialize to zeroes */
4413 sal
.section
= find_pc_overlay (sal
.pc
);
4415 b
= set_raw_breakpoint (sal
, type
);
4416 b
->number
= internal_breakpoint_number
--;
4417 b
->disposition
= disp_donttouch
;
4424 create_longjmp_breakpoint (char *func_name
)
4426 struct minimal_symbol
*m
;
4428 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4430 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4431 update_global_location_list (1);
4434 /* Call this routine when stepping and nexting to enable a breakpoint
4435 if we do a longjmp(). When we hit that breakpoint, call
4436 set_longjmp_resume_breakpoint() to figure out where we are going. */
4439 set_longjmp_breakpoint (void)
4441 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4443 create_longjmp_breakpoint ("longjmp");
4444 create_longjmp_breakpoint ("_longjmp");
4445 create_longjmp_breakpoint ("siglongjmp");
4446 create_longjmp_breakpoint ("_siglongjmp");
4450 /* Delete all longjmp breakpoints from THREAD. */
4452 delete_longjmp_breakpoint (int thread
)
4454 struct breakpoint
*b
, *temp
;
4456 ALL_BREAKPOINTS_SAFE (b
, temp
)
4457 if (b
->type
== bp_longjmp
)
4459 if (b
->thread
== thread
)
4460 delete_breakpoint (b
);
4465 create_overlay_event_breakpoint_1 (char *func_name
, struct objfile
*objfile
)
4467 struct breakpoint
*b
;
4468 struct minimal_symbol
*m
;
4470 if ((m
= lookup_minimal_symbol_text (func_name
, objfile
)) == NULL
)
4473 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4475 b
->addr_string
= xstrdup (func_name
);
4477 if (overlay_debugging
== ovly_auto
)
4479 b
->enable_state
= bp_enabled
;
4480 overlay_events_enabled
= 1;
4484 b
->enable_state
= bp_disabled
;
4485 overlay_events_enabled
= 0;
4487 update_global_location_list (1);
4491 create_overlay_event_breakpoint (char *func_name
)
4493 struct objfile
*objfile
;
4494 ALL_OBJFILES (objfile
)
4495 create_overlay_event_breakpoint_1 (func_name
, objfile
);
4499 enable_overlay_breakpoints (void)
4501 struct breakpoint
*b
;
4504 if (b
->type
== bp_overlay_event
)
4506 b
->enable_state
= bp_enabled
;
4507 update_global_location_list (1);
4508 overlay_events_enabled
= 1;
4513 disable_overlay_breakpoints (void)
4515 struct breakpoint
*b
;
4518 if (b
->type
== bp_overlay_event
)
4520 b
->enable_state
= bp_disabled
;
4521 update_global_location_list (0);
4522 overlay_events_enabled
= 0;
4527 create_thread_event_breakpoint (CORE_ADDR address
)
4529 struct breakpoint
*b
;
4531 b
= create_internal_breakpoint (address
, bp_thread_event
);
4533 b
->enable_state
= bp_enabled
;
4534 /* addr_string has to be used or breakpoint_re_set will delete me. */
4535 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4537 update_global_location_list_nothrow (1);
4543 remove_thread_event_breakpoints (void)
4545 struct breakpoint
*b
, *temp
;
4547 ALL_BREAKPOINTS_SAFE (b
, temp
)
4548 if (b
->type
== bp_thread_event
)
4549 delete_breakpoint (b
);
4552 struct captured_parse_breakpoint_args
4555 struct symtabs_and_lines
*sals_p
;
4556 char ***addr_string_p
;
4560 struct lang_and_radix
4568 remove_solib_event_breakpoints (void)
4570 struct breakpoint
*b
, *temp
;
4572 ALL_BREAKPOINTS_SAFE (b
, temp
)
4573 if (b
->type
== bp_shlib_event
)
4574 delete_breakpoint (b
);
4578 create_solib_event_breakpoint (CORE_ADDR address
)
4580 struct breakpoint
*b
;
4582 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4583 update_global_location_list_nothrow (1);
4587 /* Disable any breakpoints that are on code in shared libraries. Only
4588 apply to enabled breakpoints, disabled ones can just stay disabled. */
4591 disable_breakpoints_in_shlibs (void)
4593 struct bp_location
*loc
;
4594 int disabled_shlib_breaks
= 0;
4596 ALL_BP_LOCATIONS (loc
)
4598 struct breakpoint
*b
= loc
->owner
;
4599 /* We apply the check to all breakpoints, including disabled
4600 for those with loc->duplicate set. This is so that when breakpoint
4601 becomes enabled, or the duplicate is removed, gdb will try to insert
4602 all breakpoints. If we don't set shlib_disabled here, we'll try
4603 to insert those breakpoints and fail. */
4604 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4605 && !loc
->shlib_disabled
4607 && PC_SOLIB (loc
->address
)
4609 && solib_address (loc
->address
)
4613 loc
->shlib_disabled
= 1;
4618 /* Disable any breakpoints that are in in an unloaded shared library. Only
4619 apply to enabled breakpoints, disabled ones can just stay disabled. */
4622 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4624 struct bp_location
*loc
;
4625 int disabled_shlib_breaks
= 0;
4627 ALL_BP_LOCATIONS (loc
)
4629 struct breakpoint
*b
= loc
->owner
;
4630 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4631 || loc
->loc_type
== bp_loc_software_breakpoint
)
4632 && !loc
->shlib_disabled
)
4635 char *so_name
= PC_SOLIB (loc
->address
);
4637 char *so_name
= solib_address (loc
->address
);
4639 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4641 loc
->shlib_disabled
= 1;
4642 /* At this point, we cannot rely on remove_breakpoint
4643 succeeding so we must mark the breakpoint as not inserted
4644 to prevent future errors occurring in remove_breakpoints. */
4646 if (!disabled_shlib_breaks
)
4648 target_terminal_ours_for_output ();
4649 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4652 disabled_shlib_breaks
= 1;
4658 /* FORK & VFORK catchpoints. */
4660 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4663 insert_catch_fork (struct breakpoint
*b
)
4665 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4668 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4671 remove_catch_fork (struct breakpoint
*b
)
4673 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4676 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4680 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4682 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4685 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4687 static enum print_stop_action
4688 print_it_catch_fork (struct breakpoint
*b
)
4690 annotate_catchpoint (b
->number
);
4691 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4692 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4693 return PRINT_SRC_AND_LOC
;
4696 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4699 print_one_catch_fork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4701 struct value_print_options opts
;
4703 get_user_print_options (&opts
);
4705 /* Field 4, the address, is omitted (which makes the columns
4706 not line up too nicely with the headers, but the effect
4707 is relatively readable). */
4708 if (opts
.addressprint
)
4709 ui_out_field_skip (uiout
, "addr");
4711 ui_out_text (uiout
, "fork");
4712 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4714 ui_out_text (uiout
, ", process ");
4715 ui_out_field_int (uiout
, "what",
4716 ptid_get_pid (b
->forked_inferior_pid
));
4717 ui_out_spaces (uiout
, 1);
4721 /* Implement the "print_mention" breakpoint_ops method for fork
4725 print_mention_catch_fork (struct breakpoint
*b
)
4727 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4730 /* The breakpoint_ops structure to be used in fork catchpoints. */
4732 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4736 breakpoint_hit_catch_fork
,
4737 print_it_catch_fork
,
4738 print_one_catch_fork
,
4739 print_mention_catch_fork
4742 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4745 insert_catch_vfork (struct breakpoint
*b
)
4747 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4750 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4753 remove_catch_vfork (struct breakpoint
*b
)
4755 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4758 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4762 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4764 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4767 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4769 static enum print_stop_action
4770 print_it_catch_vfork (struct breakpoint
*b
)
4772 annotate_catchpoint (b
->number
);
4773 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4774 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4775 return PRINT_SRC_AND_LOC
;
4778 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4781 print_one_catch_vfork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4783 struct value_print_options opts
;
4785 get_user_print_options (&opts
);
4786 /* Field 4, the address, is omitted (which makes the columns
4787 not line up too nicely with the headers, but the effect
4788 is relatively readable). */
4789 if (opts
.addressprint
)
4790 ui_out_field_skip (uiout
, "addr");
4792 ui_out_text (uiout
, "vfork");
4793 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4795 ui_out_text (uiout
, ", process ");
4796 ui_out_field_int (uiout
, "what",
4797 ptid_get_pid (b
->forked_inferior_pid
));
4798 ui_out_spaces (uiout
, 1);
4802 /* Implement the "print_mention" breakpoint_ops method for vfork
4806 print_mention_catch_vfork (struct breakpoint
*b
)
4808 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4811 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4813 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4817 breakpoint_hit_catch_vfork
,
4818 print_it_catch_vfork
,
4819 print_one_catch_vfork
,
4820 print_mention_catch_vfork
4823 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4825 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4826 If COND_STRING is not NULL, then store it in the breakpoint.
4827 OPS, if not NULL, is the breakpoint_ops structure associated
4828 to the catchpoint. */
4830 static struct breakpoint
*
4831 create_catchpoint (int tempflag
, char *cond_string
,
4832 struct breakpoint_ops
*ops
)
4834 struct symtab_and_line sal
;
4835 struct breakpoint
*b
;
4842 b
= set_raw_breakpoint (sal
, bp_catchpoint
);
4843 set_breakpoint_count (breakpoint_count
+ 1);
4844 b
->number
= breakpoint_count
;
4846 b
->cond_string
= (cond_string
== NULL
) ?
4847 NULL
: savestring (cond_string
, strlen (cond_string
));
4849 b
->addr_string
= NULL
;
4850 b
->enable_state
= bp_enabled
;
4851 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4855 update_global_location_list (1);
4861 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4862 struct breakpoint_ops
*ops
)
4864 struct breakpoint
*b
= create_catchpoint (tempflag
, cond_string
, ops
);
4866 /* FIXME: We should put this information in a breakpoint private data
4868 b
->forked_inferior_pid
= null_ptid
;
4871 /* Exec catchpoints. */
4874 insert_catch_exec (struct breakpoint
*b
)
4876 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
4880 remove_catch_exec (struct breakpoint
*b
)
4882 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
4886 breakpoint_hit_catch_exec (struct breakpoint
*b
)
4888 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
4891 static enum print_stop_action
4892 print_it_catch_exec (struct breakpoint
*b
)
4894 annotate_catchpoint (b
->number
);
4895 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
4897 return PRINT_SRC_AND_LOC
;
4901 print_one_catch_exec (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4903 struct value_print_options opts
;
4905 get_user_print_options (&opts
);
4907 /* Field 4, the address, is omitted (which makes the columns
4908 not line up too nicely with the headers, but the effect
4909 is relatively readable). */
4910 if (opts
.addressprint
)
4911 ui_out_field_skip (uiout
, "addr");
4913 ui_out_text (uiout
, "exec");
4914 if (b
->exec_pathname
!= NULL
)
4916 ui_out_text (uiout
, ", program \"");
4917 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
4918 ui_out_text (uiout
, "\" ");
4923 print_mention_catch_exec (struct breakpoint
*b
)
4925 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
4928 static struct breakpoint_ops catch_exec_breakpoint_ops
=
4932 breakpoint_hit_catch_exec
,
4933 print_it_catch_exec
,
4934 print_one_catch_exec
,
4935 print_mention_catch_exec
4939 hw_breakpoint_used_count (void)
4941 struct breakpoint
*b
;
4946 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
4954 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4956 struct breakpoint
*b
;
4959 *other_type_used
= 0;
4962 if (breakpoint_enabled (b
))
4964 if (b
->type
== type
)
4966 else if ((b
->type
== bp_hardware_watchpoint
||
4967 b
->type
== bp_read_watchpoint
||
4968 b
->type
== bp_access_watchpoint
))
4969 *other_type_used
= 1;
4976 disable_watchpoints_before_interactive_call_start (void)
4978 struct breakpoint
*b
;
4982 if (((b
->type
== bp_watchpoint
)
4983 || (b
->type
== bp_hardware_watchpoint
)
4984 || (b
->type
== bp_read_watchpoint
)
4985 || (b
->type
== bp_access_watchpoint
))
4986 && breakpoint_enabled (b
))
4988 b
->enable_state
= bp_call_disabled
;
4989 update_global_location_list (0);
4995 enable_watchpoints_after_interactive_call_stop (void)
4997 struct breakpoint
*b
;
5001 if (((b
->type
== bp_watchpoint
)
5002 || (b
->type
== bp_hardware_watchpoint
)
5003 || (b
->type
== bp_read_watchpoint
)
5004 || (b
->type
== bp_access_watchpoint
))
5005 && (b
->enable_state
== bp_call_disabled
))
5007 b
->enable_state
= bp_enabled
;
5008 update_global_location_list (1);
5014 /* Set a breakpoint that will evaporate an end of command
5015 at address specified by SAL.
5016 Restrict it to frame FRAME if FRAME is nonzero. */
5019 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
5022 struct breakpoint
*b
;
5023 b
= set_raw_breakpoint (sal
, type
);
5024 b
->enable_state
= bp_enabled
;
5025 b
->disposition
= disp_donttouch
;
5026 b
->frame_id
= frame_id
;
5028 /* If we're debugging a multi-threaded program, then we
5029 want momentary breakpoints to be active in only a
5030 single thread of control. */
5031 if (in_thread_list (inferior_ptid
))
5032 b
->thread
= pid_to_thread_id (inferior_ptid
);
5034 update_global_location_list_nothrow (1);
5040 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
5042 struct symtab_and_line sal
;
5044 sal
= find_pc_line (pc
, 0);
5046 sal
.section
= find_pc_overlay (pc
);
5047 sal
.explicit_pc
= 1;
5049 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
5053 /* Tell the user we have just set a breakpoint B. */
5056 mention (struct breakpoint
*b
)
5059 struct cleanup
*old_chain
, *ui_out_chain
;
5060 struct ui_stream
*stb
;
5061 struct value_print_options opts
;
5063 get_user_print_options (&opts
);
5065 stb
= ui_out_stream_new (uiout
);
5066 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
5068 /* FIXME: This is misplaced; mention() is called by things (like
5069 hitting a watchpoint) other than breakpoint creation. It should
5070 be possible to clean this up and at the same time replace the
5071 random calls to breakpoint_changed with this hook. */
5072 observer_notify_breakpoint_created (b
->number
);
5074 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
5075 b
->ops
->print_mention (b
);
5080 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
5083 ui_out_text (uiout
, "Watchpoint ");
5084 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5085 ui_out_field_int (uiout
, "number", b
->number
);
5086 ui_out_text (uiout
, ": ");
5087 print_expression (b
->exp
, stb
->stream
);
5088 ui_out_field_stream (uiout
, "exp", stb
);
5089 do_cleanups (ui_out_chain
);
5091 case bp_hardware_watchpoint
:
5092 ui_out_text (uiout
, "Hardware watchpoint ");
5093 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5094 ui_out_field_int (uiout
, "number", b
->number
);
5095 ui_out_text (uiout
, ": ");
5096 print_expression (b
->exp
, stb
->stream
);
5097 ui_out_field_stream (uiout
, "exp", stb
);
5098 do_cleanups (ui_out_chain
);
5100 case bp_read_watchpoint
:
5101 ui_out_text (uiout
, "Hardware read watchpoint ");
5102 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
5103 ui_out_field_int (uiout
, "number", b
->number
);
5104 ui_out_text (uiout
, ": ");
5105 print_expression (b
->exp
, stb
->stream
);
5106 ui_out_field_stream (uiout
, "exp", stb
);
5107 do_cleanups (ui_out_chain
);
5109 case bp_access_watchpoint
:
5110 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
5111 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
5112 ui_out_field_int (uiout
, "number", b
->number
);
5113 ui_out_text (uiout
, ": ");
5114 print_expression (b
->exp
, stb
->stream
);
5115 ui_out_field_stream (uiout
, "exp", stb
);
5116 do_cleanups (ui_out_chain
);
5119 if (ui_out_is_mi_like_p (uiout
))
5124 if (b
->disposition
== disp_del
)
5125 printf_filtered (_("Temporary breakpoint"));
5127 printf_filtered (_("Breakpoint"));
5128 printf_filtered (_(" %d"), b
->number
);
5131 case bp_hardware_breakpoint
:
5132 if (ui_out_is_mi_like_p (uiout
))
5137 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
5141 case bp_catch_unload
:
5142 printf_filtered (_("Catchpoint %d (%s %s)"),
5144 (b
->type
== bp_catch_load
) ? "load" : "unload",
5145 (b
->dll_pathname
!= NULL
) ?
5146 b
->dll_pathname
: "<any library>");
5152 case bp_longjmp_resume
:
5153 case bp_step_resume
:
5155 case bp_watchpoint_scope
:
5156 case bp_shlib_event
:
5157 case bp_thread_event
:
5158 case bp_overlay_event
:
5164 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5168 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5172 if (opts
.addressprint
|| b
->source_file
== NULL
)
5174 printf_filtered (" at ");
5175 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5178 printf_filtered (": file %s, line %d.",
5179 b
->source_file
, b
->line_number
);
5183 struct bp_location
*loc
= b
->loc
;
5185 for (; loc
; loc
= loc
->next
)
5187 printf_filtered (" (%d locations)", n
);
5192 do_cleanups (old_chain
);
5193 if (ui_out_is_mi_like_p (uiout
))
5195 printf_filtered ("\n");
5199 static struct bp_location
*
5200 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5201 const struct symtab_and_line
*sal
)
5203 struct bp_location
*loc
, **tmp
;
5205 loc
= allocate_bp_location (b
, bptype
);
5206 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5209 loc
->requested_address
= sal
->pc
;
5210 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5212 loc
->section
= sal
->section
;
5214 set_breakpoint_location_function (loc
);
5219 /* Return 1 if LOC is pointing to a permanent breakpoint,
5220 return 0 otherwise. */
5223 bp_loc_is_permanent (struct bp_location
*loc
)
5227 const gdb_byte
*brk
;
5228 gdb_byte
*target_mem
;
5230 gdb_assert (loc
!= NULL
);
5232 addr
= loc
->address
;
5233 brk
= gdbarch_breakpoint_from_pc (current_gdbarch
, &addr
, &len
);
5235 target_mem
= alloca (len
);
5237 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5238 && memcmp (target_mem
, brk
, len
) == 0)
5246 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5247 as textual description of the location, and COND_STRING
5248 as condition expression. */
5251 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5253 enum bptype type
, enum bpdisp disposition
,
5254 int thread
, int ignore_count
,
5255 struct breakpoint_ops
*ops
, int from_tty
)
5257 struct breakpoint
*b
= NULL
;
5260 if (type
== bp_hardware_breakpoint
)
5262 int i
= hw_breakpoint_used_count ();
5263 int target_resources_ok
=
5264 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5266 if (target_resources_ok
== 0)
5267 error (_("No hardware breakpoint support in the target."));
5268 else if (target_resources_ok
< 0)
5269 error (_("Hardware breakpoints used exceeds limit."));
5272 for (i
= 0; i
< sals
.nelts
; ++i
)
5274 struct symtab_and_line sal
= sals
.sals
[i
];
5275 struct bp_location
*loc
;
5278 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5282 b
= set_raw_breakpoint (sal
, type
);
5283 set_breakpoint_count (breakpoint_count
+ 1);
5284 b
->number
= breakpoint_count
;
5287 b
->cond_string
= cond_string
;
5288 b
->ignore_count
= ignore_count
;
5289 b
->enable_state
= bp_enabled
;
5290 b
->disposition
= disposition
;
5296 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5299 if (bp_loc_is_permanent (loc
))
5300 make_breakpoint_permanent (b
);
5304 char *arg
= b
->cond_string
;
5305 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5307 error (_("Garbage %s follows condition"), arg
);
5312 b
->addr_string
= addr_string
;
5314 /* addr_string has to be used or breakpoint_re_set will delete
5316 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5322 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5323 elements to fill the void space. */
5324 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5326 int i
= index_to_remove
+1;
5327 int last_index
= sal
->nelts
-1;
5329 for (;i
<= last_index
; ++i
)
5330 sal
->sals
[i
-1] = sal
->sals
[i
];
5335 /* If appropriate, obtains all sals that correspond
5336 to the same file and line as SAL. This is done
5337 only if SAL does not have explicit PC and has
5338 line and file information. If we got just a single
5339 expanded sal, return the original.
5341 Otherwise, if SAL.explicit_line is not set, filter out
5342 all sals for which the name of enclosing function
5343 is different from SAL. This makes sure that if we have
5344 breakpoint originally set in template instantiation, say
5345 foo<int>(), we won't expand SAL to locations at the same
5346 line in all existing instantiations of 'foo'.
5349 struct symtabs_and_lines
5350 expand_line_sal_maybe (struct symtab_and_line sal
)
5352 struct symtabs_and_lines expanded
;
5353 CORE_ADDR original_pc
= sal
.pc
;
5354 char *original_function
= NULL
;
5358 /* If we have explicit pc, don't expand.
5359 If we have no line number, we can't expand. */
5360 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5363 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5364 expanded
.sals
[0] = sal
;
5369 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5371 expanded
= expand_line_sal (sal
);
5372 if (expanded
.nelts
== 1)
5374 /* We had one sal, we got one sal. Without futher
5375 processing, just return the original sal. */
5376 xfree (expanded
.sals
);
5378 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5379 sal
.pc
= original_pc
;
5380 expanded
.sals
[0] = sal
;
5384 if (!sal
.explicit_line
)
5386 CORE_ADDR func_addr
, func_end
;
5387 for (i
= 0; i
< expanded
.nelts
; ++i
)
5389 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5390 char *this_function
;
5391 if (find_pc_partial_function (pc
, &this_function
,
5392 &func_addr
, &func_end
))
5394 if (this_function
&&
5395 strcmp (this_function
, original_function
) != 0)
5397 remove_sal (&expanded
, i
);
5400 else if (func_addr
== pc
)
5402 /* We're at beginning of a function, and should
5404 struct symbol
*sym
= find_pc_function (pc
);
5406 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5409 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5416 if (expanded
.nelts
<= 1)
5418 /* This is un ugly workaround. If we get zero
5419 expanded sals then something is really wrong.
5420 Fix that by returnign the original sal. */
5421 xfree (expanded
.sals
);
5423 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5424 sal
.pc
= original_pc
;
5425 expanded
.sals
[0] = sal
;
5432 for (i
= 0; i
< expanded
.nelts
; ++i
)
5433 if (expanded
.sals
[i
].pc
== original_pc
)
5444 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5445 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5446 value. COND_STRING, if not NULL, specified the condition to be
5447 used for all breakpoints. Essentially the only case where
5448 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5449 function. In that case, it's still not possible to specify
5450 separate conditions for different overloaded functions, so
5451 we take just a single condition string.
5453 NOTE: If the function succeeds, the caller is expected to cleanup
5454 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5455 array contents). If the function fails (error() is called), the
5456 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5457 COND and SALS arrays and each of those arrays contents. */
5460 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5462 enum bptype type
, enum bpdisp disposition
,
5463 int thread
, int ignore_count
,
5464 struct breakpoint_ops
*ops
, int from_tty
)
5467 for (i
= 0; i
< sals
.nelts
; ++i
)
5469 struct symtabs_and_lines expanded
=
5470 expand_line_sal_maybe (sals
.sals
[i
]);
5472 create_breakpoint (expanded
, addr_string
[i
],
5473 cond_string
, type
, disposition
,
5474 thread
, ignore_count
, ops
, from_tty
);
5477 update_global_location_list (1);
5480 /* Parse ARG which is assumed to be a SAL specification possibly
5481 followed by conditionals. On return, SALS contains an array of SAL
5482 addresses found. ADDR_STRING contains a vector of (canonical)
5483 address strings. ARG points to the end of the SAL. */
5486 parse_breakpoint_sals (char **address
,
5487 struct symtabs_and_lines
*sals
,
5488 char ***addr_string
,
5491 char *addr_start
= *address
;
5492 *addr_string
= NULL
;
5493 /* If no arg given, or if first arg is 'if ', use the default
5495 if ((*address
) == NULL
5496 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5498 if (default_breakpoint_valid
)
5500 struct symtab_and_line sal
;
5501 init_sal (&sal
); /* initialize to zeroes */
5502 sals
->sals
= (struct symtab_and_line
*)
5503 xmalloc (sizeof (struct symtab_and_line
));
5504 sal
.pc
= default_breakpoint_address
;
5505 sal
.line
= default_breakpoint_line
;
5506 sal
.symtab
= default_breakpoint_symtab
;
5507 sal
.section
= find_pc_overlay (sal
.pc
);
5508 sals
->sals
[0] = sal
;
5512 error (_("No default breakpoint address now."));
5516 /* Force almost all breakpoints to be in terms of the
5517 current_source_symtab (which is decode_line_1's default). This
5518 should produce the results we want almost all of the time while
5519 leaving default_breakpoint_* alone.
5520 ObjC: However, don't match an Objective-C method name which
5521 may have a '+' or '-' succeeded by a '[' */
5523 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5525 if (default_breakpoint_valid
5527 || ((strchr ("+-", (*address
)[0]) != NULL
)
5528 && ((*address
)[1] != '['))))
5529 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5530 default_breakpoint_line
, addr_string
,
5533 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5534 addr_string
, not_found_ptr
);
5536 /* For any SAL that didn't have a canonical string, fill one in. */
5537 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5538 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5539 if (addr_start
!= (*address
))
5542 for (i
= 0; i
< sals
->nelts
; i
++)
5544 /* Add the string if not present. */
5545 if ((*addr_string
)[i
] == NULL
)
5546 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5552 /* Convert each SAL into a real PC. Verify that the PC can be
5553 inserted as a breakpoint. If it can't throw an error. */
5556 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5560 for (i
= 0; i
< sals
->nelts
; i
++)
5561 resolve_sal_pc (&sals
->sals
[i
]);
5565 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5567 struct captured_parse_breakpoint_args
*args
= data
;
5569 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5570 args
->not_found_ptr
);
5573 /* Given TOK, a string specification of condition and thread, as
5574 accepted by the 'break' command, extract the condition
5575 string and thread number and set *COND_STRING and *THREAD.
5576 PC identifies the context at which the condition should be parsed.
5577 If no condition is found, *COND_STRING is set to NULL.
5578 If no thread is found, *THREAD is set to -1. */
5580 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5581 char **cond_string
, int *thread
)
5583 *cond_string
= NULL
;
5589 char *cond_start
= NULL
;
5590 char *cond_end
= NULL
;
5591 while (*tok
== ' ' || *tok
== '\t')
5596 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5599 toklen
= end_tok
- tok
;
5601 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5603 tok
= cond_start
= end_tok
+ 1;
5604 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5606 *cond_string
= savestring (cond_start
,
5607 cond_end
- cond_start
);
5609 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5615 *thread
= strtol (tok
, &tok
, 0);
5617 error (_("Junk after thread keyword."));
5618 if (!valid_thread_id (*thread
))
5619 error (_("Unknown thread %d."), *thread
);
5622 error (_("Junk at end of arguments."));
5626 /* Set a breakpoint. This function is shared between
5627 CLI and MI functions for setting a breakpoint.
5628 This function has two major modes of operations,
5629 selected by the PARSE_CONDITION_AND_THREAD parameter.
5630 If non-zero, the function will parse arg, extracting
5631 breakpoint location, address and thread. Otherwise,
5632 ARG is just the location of breakpoint, with condition
5633 and thread specified by the COND_STRING and THREAD
5637 break_command_really (char *arg
, char *cond_string
, int thread
,
5638 int parse_condition_and_thread
,
5639 int tempflag
, int hardwareflag
,
5641 enum auto_boolean pending_break_support
,
5642 struct breakpoint_ops
*ops
,
5645 struct gdb_exception e
;
5646 struct symtabs_and_lines sals
;
5647 struct symtab_and_line pending_sal
;
5650 char *addr_start
= arg
;
5652 struct cleanup
*old_chain
;
5653 struct cleanup
*breakpoint_chain
= NULL
;
5654 struct captured_parse_breakpoint_args parse_args
;
5663 parse_args
.arg_p
= &arg
;
5664 parse_args
.sals_p
= &sals
;
5665 parse_args
.addr_string_p
= &addr_string
;
5666 parse_args
.not_found_ptr
= ¬_found
;
5668 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5669 &parse_args
, RETURN_MASK_ALL
);
5671 /* If caller is interested in rc value from parse, set value. */
5675 throw_exception (e
);
5679 case NOT_FOUND_ERROR
:
5681 /* If pending breakpoint support is turned off, throw
5684 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5685 throw_exception (e
);
5687 exception_print (gdb_stderr
, e
);
5689 /* If pending breakpoint support is auto query and the user
5690 selects no, then simply return the error code. */
5691 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5692 !nquery ("Make breakpoint pending on future shared library load? "))
5695 /* At this point, either the user was queried about setting
5696 a pending breakpoint and selected yes, or pending
5697 breakpoint behavior is on and thus a pending breakpoint
5698 is defaulted on behalf of the user. */
5699 copy_arg
= xstrdup (addr_start
);
5700 addr_string
= ©_arg
;
5702 sals
.sals
= &pending_sal
;
5707 throw_exception (e
);
5714 /* Create a chain of things that always need to be cleaned up. */
5715 old_chain
= make_cleanup (null_cleanup
, 0);
5719 /* Make sure that all storage allocated to SALS gets freed. */
5720 make_cleanup (xfree
, sals
.sals
);
5722 /* Cleanup the addr_string array but not its contents. */
5723 make_cleanup (xfree
, addr_string
);
5726 /* ----------------------------- SNIP -----------------------------
5727 Anything added to the cleanup chain beyond this point is assumed
5728 to be part of a breakpoint. If the breakpoint create succeeds
5729 then the memory is not reclaimed. */
5730 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5732 /* Mark the contents of the addr_string for cleanup. These go on
5733 the breakpoint_chain and only occure if the breakpoint create
5735 for (i
= 0; i
< sals
.nelts
; i
++)
5737 if (addr_string
[i
] != NULL
)
5738 make_cleanup (xfree
, addr_string
[i
]);
5741 /* Resolve all line numbers to PC's and verify that the addresses
5742 are ok for the target. */
5744 breakpoint_sals_to_pc (&sals
, addr_start
);
5746 /* Verify that condition can be parsed, before setting any
5747 breakpoints. Allocate a separate condition expression for each
5751 if (parse_condition_and_thread
)
5753 /* Here we only parse 'arg' to separate condition
5754 from thread number, so parsing in context of first
5755 sal is OK. When setting the breakpoint we'll
5756 re-parse it in context of each sal. */
5759 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5761 make_cleanup (xfree
, cond_string
);
5765 /* Create a private copy of condition string. */
5768 cond_string
= xstrdup (cond_string
);
5769 make_cleanup (xfree
, cond_string
);
5772 create_breakpoints (sals
, addr_string
, cond_string
,
5773 hardwareflag
? bp_hardware_breakpoint
5775 tempflag
? disp_del
: disp_donttouch
,
5776 thread
, ignore_count
, ops
, from_tty
);
5780 struct symtab_and_line sal
= {0};
5781 struct breakpoint
*b
;
5783 make_cleanup (xfree
, copy_arg
);
5785 b
= set_raw_breakpoint_without_location (hardwareflag
5786 ? bp_hardware_breakpoint
5788 set_breakpoint_count (breakpoint_count
+ 1);
5789 b
->number
= breakpoint_count
;
5791 b
->addr_string
= addr_string
[0];
5792 b
->cond_string
= NULL
;
5793 b
->ignore_count
= ignore_count
;
5794 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5795 b
->condition_not_parsed
= 1;
5798 update_global_location_list (1);
5803 warning (_("Multiple breakpoints were set.\n"
5804 "Use the \"delete\" command to delete unwanted breakpoints."));
5805 /* That's it. Discard the cleanups for data inserted into the
5807 discard_cleanups (breakpoint_chain
);
5808 /* But cleanup everything else. */
5809 do_cleanups (old_chain
);
5812 /* Set a breakpoint.
5813 ARG is a string describing breakpoint address,
5814 condition, and thread.
5815 FLAG specifies if a breakpoint is hardware on,
5816 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5820 break_command_1 (char *arg
, int flag
, int from_tty
)
5822 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5823 int tempflag
= flag
& BP_TEMPFLAG
;
5825 break_command_really (arg
,
5826 NULL
, 0, 1 /* parse arg */,
5827 tempflag
, hardwareflag
,
5828 0 /* Ignore count */,
5829 pending_break_support
,
5830 NULL
/* breakpoint_ops */,
5836 set_breakpoint (char *address
, char *condition
,
5837 int hardwareflag
, int tempflag
,
5838 int thread
, int ignore_count
,
5841 break_command_really (address
, condition
, thread
,
5842 0 /* condition and thread are valid. */,
5843 tempflag
, hardwareflag
,
5846 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5850 /* Adjust SAL to the first instruction past the function prologue.
5851 The end of the prologue is determined using the line table from
5852 the debugging information.
5854 If SAL is already past the prologue, then do nothing. */
5857 skip_prologue_sal (struct symtab_and_line
*sal
)
5859 struct symbol
*sym
= find_pc_function (sal
->pc
);
5860 struct symtab_and_line start_sal
;
5865 start_sal
= find_function_start_sal (sym
, 1);
5866 if (sal
->pc
< start_sal
.pc
)
5870 /* Helper function for break_command_1 and disassemble_command. */
5873 resolve_sal_pc (struct symtab_and_line
*sal
)
5877 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5879 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5880 error (_("No line %d in file \"%s\"."),
5881 sal
->line
, sal
->symtab
->filename
);
5884 /* If this SAL corresponds to a breakpoint inserted using
5885 a line number, then skip the function prologue if necessary. */
5886 if (sal
->explicit_line
)
5887 skip_prologue_sal (sal
);
5890 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5892 struct blockvector
*bv
;
5896 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5899 sym
= block_linkage_function (b
);
5902 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5903 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
5907 /* It really is worthwhile to have the section, so we'll just
5908 have to look harder. This case can be executed if we have
5909 line numbers but no functions (as can happen in assembly
5912 struct minimal_symbol
*msym
;
5914 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5916 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
5923 break_command (char *arg
, int from_tty
)
5925 break_command_1 (arg
, 0, from_tty
);
5929 tbreak_command (char *arg
, int from_tty
)
5931 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5935 hbreak_command (char *arg
, int from_tty
)
5937 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5941 thbreak_command (char *arg
, int from_tty
)
5943 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5947 stop_command (char *arg
, int from_tty
)
5949 printf_filtered (_("Specify the type of breakpoint to set.\n\
5950 Usage: stop in <function | address>\n\
5951 stop at <line>\n"));
5955 stopin_command (char *arg
, int from_tty
)
5959 if (arg
== (char *) NULL
)
5961 else if (*arg
!= '*')
5966 /* look for a ':'. If this is a line number specification, then
5967 say it is bad, otherwise, it should be an address or
5968 function/method name */
5969 while (*argptr
&& !hasColon
)
5971 hasColon
= (*argptr
== ':');
5976 badInput
= (*argptr
!= ':'); /* Not a class::method */
5978 badInput
= isdigit (*arg
); /* a simple line number */
5982 printf_filtered (_("Usage: stop in <function | address>\n"));
5984 break_command_1 (arg
, 0, from_tty
);
5988 stopat_command (char *arg
, int from_tty
)
5992 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5999 /* look for a ':'. If there is a '::' then get out, otherwise
6000 it is probably a line number. */
6001 while (*argptr
&& !hasColon
)
6003 hasColon
= (*argptr
== ':');
6008 badInput
= (*argptr
== ':'); /* we have class::method */
6010 badInput
= !isdigit (*arg
); /* not a line number */
6014 printf_filtered (_("Usage: stop at <line>\n"));
6016 break_command_1 (arg
, 0, from_tty
);
6019 /* accessflag: hw_write: watch write,
6020 hw_read: watch read,
6021 hw_access: watch access (read or write) */
6023 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
6025 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
6026 struct symtab_and_line sal
;
6027 struct expression
*exp
;
6028 struct block
*exp_valid_block
;
6029 struct value
*val
, *mark
;
6030 struct frame_info
*frame
;
6031 struct frame_info
*prev_frame
= NULL
;
6032 char *exp_start
= NULL
;
6033 char *exp_end
= NULL
;
6034 char *tok
, *id_tok_start
, *end_tok
;
6036 char *cond_start
= NULL
;
6037 char *cond_end
= NULL
;
6038 struct expression
*cond
= NULL
;
6039 int i
, other_type_used
, target_resources_ok
= 0;
6040 enum bptype bp_type
;
6044 init_sal (&sal
); /* initialize to zeroes */
6046 /* Make sure that we actually have parameters to parse. */
6047 if (arg
!= NULL
&& arg
[0] != '\0')
6049 toklen
= strlen (arg
); /* Size of argument list. */
6051 /* Points tok to the end of the argument list. */
6052 tok
= arg
+ toklen
- 1;
6054 /* Go backwards in the parameters list. Skip the last parameter.
6055 If we're expecting a 'thread <thread_num>' parameter, this should
6056 be the thread identifier. */
6057 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6059 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6062 /* Points end_tok to the beginning of the last token. */
6063 id_tok_start
= tok
+ 1;
6065 /* Go backwards in the parameters list. Skip one more parameter.
6066 If we're expecting a 'thread <thread_num>' parameter, we should
6067 reach a "thread" token. */
6068 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6073 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6076 /* Move the pointer forward to skip the whitespace and
6077 calculate the length of the token. */
6079 toklen
= end_tok
- tok
;
6081 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
6083 /* At this point we've found a "thread" token, which means
6084 the user is trying to set a watchpoint that triggers
6085 only in a specific thread. */
6088 /* Extract the thread ID from the next token. */
6089 thread
= strtol (id_tok_start
, &endp
, 0);
6091 /* Check if the user provided a valid numeric value for the
6093 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
6094 error (_("Invalid thread ID specification %s."), id_tok_start
);
6096 /* Check if the thread actually exists. */
6097 if (!valid_thread_id (thread
))
6098 error (_("Unknown thread %d."), thread
);
6100 /* Truncate the string and get rid of the thread <thread_num>
6101 parameter before the parameter list is parsed by the
6102 evaluate_expression() function. */
6107 /* Parse the rest of the arguments. */
6108 innermost_block
= NULL
;
6110 exp
= parse_exp_1 (&arg
, 0, 0);
6112 exp_valid_block
= innermost_block
;
6113 mark
= value_mark ();
6114 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
6116 release_value (val
);
6119 while (*tok
== ' ' || *tok
== '\t')
6123 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6126 toklen
= end_tok
- tok
;
6127 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6129 tok
= cond_start
= end_tok
+ 1;
6130 cond
= parse_exp_1 (&tok
, 0, 0);
6134 error (_("Junk at end of command."));
6136 if (accessflag
== hw_read
)
6137 bp_type
= bp_read_watchpoint
;
6138 else if (accessflag
== hw_access
)
6139 bp_type
= bp_access_watchpoint
;
6141 bp_type
= bp_hardware_watchpoint
;
6143 mem_cnt
= can_use_hardware_watchpoint (val
);
6144 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
6145 error (_("Expression cannot be implemented with read/access watchpoint."));
6148 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
6149 target_resources_ok
=
6150 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
6152 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
6153 error (_("Target does not support this type of hardware watchpoint."));
6155 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
6156 error (_("Target can only support one kind of HW watchpoint at a time."));
6159 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6160 watchpoint could not be set. */
6161 if (!mem_cnt
|| target_resources_ok
<= 0)
6162 bp_type
= bp_watchpoint
;
6164 frame
= block_innermost_frame (exp_valid_block
);
6166 prev_frame
= get_prev_frame (frame
);
6170 /* If the expression is "local", then set up a "watchpoint scope"
6171 breakpoint at the point where we've left the scope of the watchpoint
6172 expression. Create the scope breakpoint before the watchpoint, so
6173 that we will encounter it first in bpstat_stop_status. */
6174 if (innermost_block
&& prev_frame
)
6176 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
6177 bp_watchpoint_scope
);
6179 scope_breakpoint
->enable_state
= bp_enabled
;
6181 /* Automatically delete the breakpoint when it hits. */
6182 scope_breakpoint
->disposition
= disp_del
;
6184 /* Only break in the proper frame (help with recursion). */
6185 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6187 /* Set the address at which we will stop. */
6188 scope_breakpoint
->loc
->requested_address
6189 = get_frame_pc (prev_frame
);
6190 scope_breakpoint
->loc
->address
6191 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6192 scope_breakpoint
->type
);
6195 /* Now set up the breakpoint. */
6196 b
= set_raw_breakpoint (sal
, bp_type
);
6197 set_breakpoint_count (breakpoint_count
+ 1);
6198 b
->number
= breakpoint_count
;
6200 b
->disposition
= disp_donttouch
;
6202 b
->exp_valid_block
= exp_valid_block
;
6203 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6206 b
->loc
->cond
= cond
;
6208 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6213 b
->watchpoint_frame
= get_frame_id (frame
);
6215 b
->watchpoint_frame
= null_frame_id
;
6217 if (scope_breakpoint
!= NULL
)
6219 /* The scope breakpoint is related to the watchpoint. We will
6220 need to act on them together. */
6221 b
->related_breakpoint
= scope_breakpoint
;
6222 scope_breakpoint
->related_breakpoint
= b
;
6225 value_free_to_mark (mark
);
6227 update_global_location_list (1);
6230 /* Return count of locations need to be watched and can be handled
6231 in hardware. If the watchpoint can not be handled
6232 in hardware return zero. */
6235 can_use_hardware_watchpoint (struct value
*v
)
6237 int found_memory_cnt
= 0;
6238 struct value
*head
= v
;
6240 /* Did the user specifically forbid us to use hardware watchpoints? */
6241 if (!can_use_hw_watchpoints
)
6244 /* Make sure that the value of the expression depends only upon
6245 memory contents, and values computed from them within GDB. If we
6246 find any register references or function calls, we can't use a
6247 hardware watchpoint.
6249 The idea here is that evaluating an expression generates a series
6250 of values, one holding the value of every subexpression. (The
6251 expression a*b+c has five subexpressions: a, b, a*b, c, and
6252 a*b+c.) GDB's values hold almost enough information to establish
6253 the criteria given above --- they identify memory lvalues,
6254 register lvalues, computed values, etcetera. So we can evaluate
6255 the expression, and then scan the chain of values that leaves
6256 behind to decide whether we can detect any possible change to the
6257 expression's final value using only hardware watchpoints.
6259 However, I don't think that the values returned by inferior
6260 function calls are special in any way. So this function may not
6261 notice that an expression involving an inferior function call
6262 can't be watched with hardware watchpoints. FIXME. */
6263 for (; v
; v
= value_next (v
))
6265 if (VALUE_LVAL (v
) == lval_memory
)
6268 /* A lazy memory lvalue is one that GDB never needed to fetch;
6269 we either just used its address (e.g., `a' in `a.b') or
6270 we never needed it at all (e.g., `a' in `a,b'). */
6274 /* Ahh, memory we actually used! Check if we can cover
6275 it with hardware watchpoints. */
6276 struct type
*vtype
= check_typedef (value_type (v
));
6278 /* We only watch structs and arrays if user asked for it
6279 explicitly, never if they just happen to appear in a
6280 middle of some value chain. */
6282 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6283 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6285 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6286 int len
= TYPE_LENGTH (value_type (v
));
6288 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6295 else if (VALUE_LVAL (v
) != not_lval
6296 && deprecated_value_modifiable (v
) == 0)
6297 return 0; /* ??? What does this represent? */
6298 else if (VALUE_LVAL (v
) == lval_register
)
6299 return 0; /* cannot watch a register with a HW watchpoint */
6302 /* The expression itself looks suitable for using a hardware
6303 watchpoint, but give the target machine a chance to reject it. */
6304 return found_memory_cnt
;
6308 watch_command_wrapper (char *arg
, int from_tty
)
6310 watch_command (arg
, from_tty
);
6314 watch_command (char *arg
, int from_tty
)
6316 watch_command_1 (arg
, hw_write
, from_tty
);
6320 rwatch_command_wrapper (char *arg
, int from_tty
)
6322 rwatch_command (arg
, from_tty
);
6326 rwatch_command (char *arg
, int from_tty
)
6328 watch_command_1 (arg
, hw_read
, from_tty
);
6332 awatch_command_wrapper (char *arg
, int from_tty
)
6334 awatch_command (arg
, from_tty
);
6338 awatch_command (char *arg
, int from_tty
)
6340 watch_command_1 (arg
, hw_access
, from_tty
);
6344 /* Helper routines for the until_command routine in infcmd.c. Here
6345 because it uses the mechanisms of breakpoints. */
6347 struct until_break_command_continuation_args
6349 struct breakpoint
*breakpoint
;
6350 struct breakpoint
*breakpoint2
;
6353 /* This function is called by fetch_inferior_event via the
6354 cmd_continuation pointer, to complete the until command. It takes
6355 care of cleaning up the temporary breakpoints set up by the until
6358 until_break_command_continuation (void *arg
)
6360 struct until_break_command_continuation_args
*a
= arg
;
6362 delete_breakpoint (a
->breakpoint
);
6364 delete_breakpoint (a
->breakpoint2
);
6368 until_break_command (char *arg
, int from_tty
, int anywhere
)
6370 struct symtabs_and_lines sals
;
6371 struct symtab_and_line sal
;
6372 struct frame_info
*frame
= get_selected_frame (NULL
);
6373 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6374 struct breakpoint
*breakpoint
;
6375 struct breakpoint
*breakpoint2
= NULL
;
6376 struct cleanup
*old_chain
;
6378 clear_proceed_status ();
6380 /* Set a breakpoint where the user wants it and at return from
6383 if (default_breakpoint_valid
)
6384 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6385 default_breakpoint_line
, (char ***) NULL
, NULL
);
6387 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6388 0, (char ***) NULL
, NULL
);
6390 if (sals
.nelts
!= 1)
6391 error (_("Couldn't get information on specified line."));
6394 xfree (sals
.sals
); /* malloc'd, so freed */
6397 error (_("Junk at end of arguments."));
6399 resolve_sal_pc (&sal
);
6402 /* If the user told us to continue until a specified location,
6403 we don't specify a frame at which we need to stop. */
6404 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6406 /* Otherwise, specify the current frame, because we want to stop only
6407 at the very same frame. */
6408 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6411 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6413 /* Keep within the current frame, or in frames called by the current
6417 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6418 sal
.pc
= get_frame_pc (prev_frame
);
6419 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6421 make_cleanup_delete_breakpoint (breakpoint2
);
6424 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6426 /* If we are running asynchronously, and proceed call above has actually
6427 managed to start the target, arrange for breakpoints to be
6428 deleted when the target stops. Otherwise, we're already stopped and
6429 delete breakpoints via cleanup chain. */
6431 if (target_can_async_p () && is_running (inferior_ptid
))
6433 struct until_break_command_continuation_args
*args
;
6434 args
= xmalloc (sizeof (*args
));
6436 args
->breakpoint
= breakpoint
;
6437 args
->breakpoint2
= breakpoint2
;
6439 discard_cleanups (old_chain
);
6440 add_continuation (inferior_thread (),
6441 until_break_command_continuation
, args
,
6445 do_cleanups (old_chain
);
6449 ep_skip_leading_whitespace (char **s
)
6451 if ((s
== NULL
) || (*s
== NULL
))
6453 while (isspace (**s
))
6457 /* This function attempts to parse an optional "if <cond>" clause
6458 from the arg string. If one is not found, it returns NULL.
6460 Else, it returns a pointer to the condition string. (It does not
6461 attempt to evaluate the string against a particular block.) And,
6462 it updates arg to point to the first character following the parsed
6463 if clause in the arg string. */
6466 ep_parse_optional_if_clause (char **arg
)
6470 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6473 /* Skip the "if" keyword. */
6476 /* Skip any extra leading whitespace, and record the start of the
6477 condition string. */
6478 ep_skip_leading_whitespace (arg
);
6481 /* Assume that the condition occupies the remainder of the arg string. */
6482 (*arg
) += strlen (cond_string
);
6487 /* This function attempts to parse an optional filename from the arg
6488 string. If one is not found, it returns NULL.
6490 Else, it returns a pointer to the parsed filename. (This function
6491 makes no attempt to verify that a file of that name exists, or is
6492 accessible.) And, it updates arg to point to the first character
6493 following the parsed filename in the arg string.
6495 Note that clients needing to preserve the returned filename for
6496 future access should copy it to their own buffers. */
6498 ep_parse_optional_filename (char **arg
)
6500 static char filename
[1024];
6505 if ((*arg_p
== '\0') || isspace (*arg_p
))
6523 /* Commands to deal with catching events, such as signals, exceptions,
6524 process start/exit, etc. */
6528 catch_fork_temporary
, catch_vfork_temporary
,
6529 catch_fork_permanent
, catch_vfork_permanent
6534 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6536 char *cond_string
= NULL
;
6537 catch_fork_kind fork_kind
;
6540 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6541 tempflag
= (fork_kind
== catch_fork_temporary
6542 || fork_kind
== catch_vfork_temporary
);
6546 ep_skip_leading_whitespace (&arg
);
6548 /* The allowed syntax is:
6550 catch [v]fork if <cond>
6552 First, check if there's an if clause. */
6553 cond_string
= ep_parse_optional_if_clause (&arg
);
6555 if ((*arg
!= '\0') && !isspace (*arg
))
6556 error (_("Junk at end of arguments."));
6558 /* If this target supports it, create a fork or vfork catchpoint
6559 and enable reporting of such events. */
6562 case catch_fork_temporary
:
6563 case catch_fork_permanent
:
6564 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6565 &catch_fork_breakpoint_ops
);
6567 case catch_vfork_temporary
:
6568 case catch_vfork_permanent
:
6569 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6570 &catch_vfork_breakpoint_ops
);
6573 error (_("unsupported or unknown fork kind; cannot catch it"));
6579 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6582 char *cond_string
= NULL
;
6584 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6588 ep_skip_leading_whitespace (&arg
);
6590 /* The allowed syntax is:
6592 catch exec if <cond>
6594 First, check if there's an if clause. */
6595 cond_string
= ep_parse_optional_if_clause (&arg
);
6597 if ((*arg
!= '\0') && !isspace (*arg
))
6598 error (_("Junk at end of arguments."));
6600 /* If this target supports it, create an exec catchpoint
6601 and enable reporting of such events. */
6602 create_catchpoint (tempflag
, cond_string
, &catch_exec_breakpoint_ops
);
6606 catch_load_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6609 char *dll_pathname
= NULL
;
6610 char *cond_string
= NULL
;
6612 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6616 ep_skip_leading_whitespace (&arg
);
6618 /* The allowed syntax is:
6620 catch load if <cond>
6621 catch load <filename>
6622 catch load <filename> if <cond>
6624 The user is not allowed to specify the <filename> after an
6627 We'll ignore the pathological case of a file named "if".
6629 First, check if there's an if clause. If so, then there
6630 cannot be a filename. */
6631 cond_string
= ep_parse_optional_if_clause (&arg
);
6633 /* If there was an if clause, then there cannot be a filename.
6634 Else, there might be a filename and an if clause. */
6635 if (cond_string
== NULL
)
6637 dll_pathname
= ep_parse_optional_filename (&arg
);
6638 ep_skip_leading_whitespace (&arg
);
6639 cond_string
= ep_parse_optional_if_clause (&arg
);
6642 if ((*arg
!= '\0') && !isspace (*arg
))
6643 error (_("Junk at end of arguments."));
6645 /* Create a load breakpoint that only triggers when a load of
6646 the specified dll (or any dll, if no pathname was specified)
6648 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6649 dll_pathname
, cond_string
);
6653 catch_unload_command_1 (char *arg
, int from_tty
,
6654 struct cmd_list_element
*command
)
6657 char *dll_pathname
= NULL
;
6658 char *cond_string
= NULL
;
6660 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6664 ep_skip_leading_whitespace (&arg
);
6666 /* The allowed syntax is:
6668 catch unload if <cond>
6669 catch unload <filename>
6670 catch unload <filename> if <cond>
6672 The user is not allowed to specify the <filename> after an
6675 We'll ignore the pathological case of a file named "if".
6677 First, check if there's an if clause. If so, then there
6678 cannot be a filename. */
6679 cond_string
= ep_parse_optional_if_clause (&arg
);
6681 /* If there was an if clause, then there cannot be a filename.
6682 Else, there might be a filename and an if clause. */
6683 if (cond_string
== NULL
)
6685 dll_pathname
= ep_parse_optional_filename (&arg
);
6686 ep_skip_leading_whitespace (&arg
);
6687 cond_string
= ep_parse_optional_if_clause (&arg
);
6690 if ((*arg
!= '\0') && !isspace (*arg
))
6691 error (_("Junk at end of arguments."));
6693 /* Create an unload breakpoint that only triggers when an unload of
6694 the specified dll (or any dll, if no pathname was specified)
6696 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6697 dll_pathname
, cond_string
);
6700 static enum print_stop_action
6701 print_exception_catchpoint (struct breakpoint
*b
)
6703 int bp_temp
, bp_throw
;
6705 annotate_catchpoint (b
->number
);
6707 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6708 if (b
->loc
->address
!= b
->loc
->requested_address
)
6709 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6712 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6714 bp_temp
? "Temporary catchpoint "
6716 if (!ui_out_is_mi_like_p (uiout
))
6717 ui_out_field_int (uiout
, "bkptno", b
->number
);
6719 bp_throw
? " (exception thrown), "
6720 : " (exception caught), ");
6721 if (ui_out_is_mi_like_p (uiout
))
6723 ui_out_field_string (uiout
, "reason",
6724 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6725 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6726 ui_out_field_int (uiout
, "bkptno", b
->number
);
6728 return PRINT_SRC_AND_LOC
;
6732 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6734 struct value_print_options opts
;
6735 get_user_print_options (&opts
);
6736 if (opts
.addressprint
)
6739 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6740 ui_out_field_string (uiout
, "addr", "<PENDING>");
6742 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6746 *last_addr
= b
->loc
->address
;
6747 if (strstr (b
->addr_string
, "throw") != NULL
)
6748 ui_out_field_string (uiout
, "what", "exception throw");
6750 ui_out_field_string (uiout
, "what", "exception catch");
6754 print_mention_exception_catchpoint (struct breakpoint
*b
)
6759 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6760 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6761 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6762 : _("Catchpoint "));
6763 ui_out_field_int (uiout
, "bkptno", b
->number
);
6764 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6768 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6771 NULL
, /* breakpoint_hit */
6772 print_exception_catchpoint
,
6773 print_one_exception_catchpoint
,
6774 print_mention_exception_catchpoint
6778 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6779 enum exception_event_kind ex_event
, int from_tty
)
6781 char *trigger_func_name
;
6783 if (ex_event
== EX_EVENT_CATCH
)
6784 trigger_func_name
= "__cxa_begin_catch";
6786 trigger_func_name
= "__cxa_throw";
6788 break_command_really (trigger_func_name
, cond_string
, -1,
6789 0 /* condition and thread are valid. */,
6792 AUTO_BOOLEAN_TRUE
/* pending */,
6793 &gnu_v3_exception_catchpoint_ops
, from_tty
);
6798 /* Deal with "catch catch" and "catch throw" commands */
6801 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6802 int tempflag
, int from_tty
)
6804 char *cond_string
= NULL
;
6805 struct symtab_and_line
*sal
= NULL
;
6809 ep_skip_leading_whitespace (&arg
);
6811 cond_string
= ep_parse_optional_if_clause (&arg
);
6813 if ((*arg
!= '\0') && !isspace (*arg
))
6814 error (_("Junk at end of arguments."));
6816 if ((ex_event
!= EX_EVENT_THROW
) &&
6817 (ex_event
!= EX_EVENT_CATCH
))
6818 error (_("Unsupported or unknown exception event; cannot catch it"));
6820 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6823 warning (_("Unsupported with this platform/compiler combination."));
6826 /* Implementation of "catch catch" command. */
6829 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6831 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6832 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6835 /* Implementation of "catch throw" command. */
6838 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6840 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6841 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6844 /* Create a breakpoint struct for Ada exception catchpoints. */
6847 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6851 struct expression
*cond
,
6852 struct breakpoint_ops
*ops
,
6856 struct breakpoint
*b
;
6860 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6861 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6862 version for exception catchpoints, because two catchpoints
6863 used for different exception names will use the same address.
6864 In this case, a "breakpoint ... also set at..." warning is
6865 unproductive. Besides. the warning phrasing is also a bit
6866 inapropriate, we should use the word catchpoint, and tell
6867 the user what type of catchpoint it is. The above is good
6868 enough for now, though. */
6871 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6872 set_breakpoint_count (breakpoint_count
+ 1);
6874 b
->enable_state
= bp_enabled
;
6875 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6876 b
->number
= breakpoint_count
;
6877 b
->ignore_count
= 0;
6878 b
->loc
->cond
= cond
;
6879 b
->addr_string
= addr_string
;
6880 b
->language
= language_ada
;
6881 b
->cond_string
= cond_string
;
6882 b
->exp_string
= exp_string
;
6887 update_global_location_list (1);
6890 /* Implement the "catch exception" command. */
6893 catch_ada_exception_command (char *arg
, int from_tty
,
6894 struct cmd_list_element
*command
)
6897 struct symtab_and_line sal
;
6899 char *addr_string
= NULL
;
6900 char *exp_string
= NULL
;
6901 char *cond_string
= NULL
;
6902 struct expression
*cond
= NULL
;
6903 struct breakpoint_ops
*ops
= NULL
;
6905 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6909 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6910 &cond_string
, &cond
, &ops
);
6911 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6912 cond_string
, cond
, ops
, tempflag
,
6916 /* Implement the "catch assert" command. */
6919 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6922 struct symtab_and_line sal
;
6923 char *addr_string
= NULL
;
6924 struct breakpoint_ops
*ops
= NULL
;
6926 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6930 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6931 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6932 tempflag
, from_tty
);
6936 catch_command (char *arg
, int from_tty
)
6938 error (_("Catch requires an event name."));
6943 tcatch_command (char *arg
, int from_tty
)
6945 error (_("Catch requires an event name."));
6948 /* Delete breakpoints by address or line. */
6951 clear_command (char *arg
, int from_tty
)
6953 struct breakpoint
*b
;
6954 VEC(breakpoint_p
) *found
= 0;
6957 struct symtabs_and_lines sals
;
6958 struct symtab_and_line sal
;
6963 sals
= decode_line_spec (arg
, 1);
6968 sals
.sals
= (struct symtab_and_line
*)
6969 xmalloc (sizeof (struct symtab_and_line
));
6970 make_cleanup (xfree
, sals
.sals
);
6971 init_sal (&sal
); /* initialize to zeroes */
6972 sal
.line
= default_breakpoint_line
;
6973 sal
.symtab
= default_breakpoint_symtab
;
6974 sal
.pc
= default_breakpoint_address
;
6975 if (sal
.symtab
== 0)
6976 error (_("No source file specified."));
6984 /* We don't call resolve_sal_pc here. That's not
6985 as bad as it seems, because all existing breakpoints
6986 typically have both file/line and pc set. So, if
6987 clear is given file/line, we can match this to existing
6988 breakpoint without obtaining pc at all.
6990 We only support clearing given the address explicitly
6991 present in breakpoint table. Say, we've set breakpoint
6992 at file:line. There were several PC values for that file:line,
6993 due to optimization, all in one block.
6994 We've picked one PC value. If "clear" is issued with another
6995 PC corresponding to the same file:line, the breakpoint won't
6996 be cleared. We probably can still clear the breakpoint, but
6997 since the other PC value is never presented to user, user
6998 can only find it by guessing, and it does not seem important
7001 /* For each line spec given, delete bps which correspond
7002 to it. Do it in two passes, solely to preserve the current
7003 behavior that from_tty is forced true if we delete more than
7007 for (i
= 0; i
< sals
.nelts
; i
++)
7009 /* If exact pc given, clear bpts at that pc.
7010 If line given (pc == 0), clear all bpts on specified line.
7011 If defaulting, clear all bpts on default line
7014 defaulting sal.pc != 0 tests to do
7019 1 0 <can't happen> */
7023 /* Find all matching breakpoints and add them to
7028 /* Are we going to delete b? */
7029 if (b
->type
!= bp_none
7030 && b
->type
!= bp_watchpoint
7031 && b
->type
!= bp_hardware_watchpoint
7032 && b
->type
!= bp_read_watchpoint
7033 && b
->type
!= bp_access_watchpoint
)
7035 struct bp_location
*loc
= b
->loc
;
7036 for (; loc
; loc
= loc
->next
)
7038 int pc_match
= sal
.pc
7039 && (loc
->address
== sal
.pc
)
7040 && (!section_is_overlay (loc
->section
)
7041 || loc
->section
== sal
.section
);
7042 int line_match
= ((default_match
|| (0 == sal
.pc
))
7043 && b
->source_file
!= NULL
7044 && sal
.symtab
!= NULL
7045 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
7046 && b
->line_number
== sal
.line
);
7047 if (pc_match
|| line_match
)
7056 VEC_safe_push(breakpoint_p
, found
, b
);
7059 /* Now go thru the 'found' chain and delete them. */
7060 if (VEC_empty(breakpoint_p
, found
))
7063 error (_("No breakpoint at %s."), arg
);
7065 error (_("No breakpoint at this line."));
7068 if (VEC_length(breakpoint_p
, found
) > 1)
7069 from_tty
= 1; /* Always report if deleted more than one */
7072 if (VEC_length(breakpoint_p
, found
) == 1)
7073 printf_unfiltered (_("Deleted breakpoint "));
7075 printf_unfiltered (_("Deleted breakpoints "));
7077 breakpoints_changed ();
7079 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
7082 printf_unfiltered ("%d ", b
->number
);
7083 delete_breakpoint (b
);
7086 putchar_unfiltered ('\n');
7089 /* Delete breakpoint in BS if they are `delete' breakpoints and
7090 all breakpoints that are marked for deletion, whether hit or not.
7091 This is called after any breakpoint is hit, or after errors. */
7094 breakpoint_auto_delete (bpstat bs
)
7096 struct breakpoint
*b
, *temp
;
7098 for (; bs
; bs
= bs
->next
)
7099 if (bs
->breakpoint_at
7100 && bs
->breakpoint_at
->owner
7101 && bs
->breakpoint_at
->owner
->disposition
== disp_del
7103 delete_breakpoint (bs
->breakpoint_at
->owner
);
7105 ALL_BREAKPOINTS_SAFE (b
, temp
)
7107 if (b
->disposition
== disp_del_at_next_stop
)
7108 delete_breakpoint (b
);
7112 /* If SHOULD_INSERT is true, do not insert any breakpoint locations
7113 into the inferior, only remove already-inserted locations that no
7114 longer should be inserted. Functions that delete a breakpoint or
7115 breakpoints should pass false, so that deleting a breakpoint
7116 doesn't have the side effect of inserting the locations of other
7117 breakpoints that are marked not-inserted, but should_be_inserted
7118 returns true on them.
7120 This behaviour is useful is situations close to tear-down -- e.g.,
7121 after an exec, while the target still has execution, but breakpoint
7122 shadows of the previous executable image should *NOT* be restored
7123 to the new image; or before detaching, where the target still has
7124 execution and wants to delete breakpoints from GDB's lists, and all
7125 breakpoints had already been removed from the inferior. */
7128 update_global_location_list (int should_insert
)
7130 struct breakpoint
*b
;
7131 struct bp_location
**next
= &bp_location_chain
;
7132 struct bp_location
*loc
;
7133 struct bp_location
*loc2
;
7134 struct gdb_exception e
;
7135 VEC(bp_location_p
) *old_locations
= NULL
;
7139 /* Store old locations for future reference. */
7140 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7141 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7143 bp_location_chain
= NULL
;
7146 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7149 next
= &(loc
->global_next
);
7154 /* Identify bp_location instances that are no longer present in the new
7155 list, and therefore should be freed. Note that it's not necessary that
7156 those locations should be removed from inferior -- if there's another
7157 location at the same address (previously marked as duplicate),
7158 we don't need to remove/insert the location. */
7159 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7161 /* Tells if 'loc' is found amoung the new locations. If not, we
7163 int found_object
= 0;
7164 /* Tells if the location should remain inserted in the target. */
7165 int keep_in_target
= 0;
7167 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7174 /* If this location is no longer present, and inserted, look if there's
7175 maybe a new location at the same address. If so, mark that one
7176 inserted, and don't remove this one. This is needed so that we
7177 don't have a time window where a breakpoint at certain location is not
7182 /* If the location is inserted now, we might have to remove it. */
7184 if (found_object
&& should_be_inserted (loc
))
7186 /* The location is still present in the location list, and still
7187 should be inserted. Don't do anything. */
7192 /* The location is either no longer present, or got disabled.
7193 See if there's another location at the same address, in which
7194 case we don't need to remove this one from the target. */
7195 if (breakpoint_address_is_meaningful (loc
->owner
))
7196 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7198 /* For the sake of should_insert_location. The
7199 call to check_duplicates will fix up this later. */
7200 loc2
->duplicate
= 0;
7201 if (should_be_inserted (loc2
)
7202 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7205 loc2
->target_info
= loc
->target_info
;
7212 if (!keep_in_target
)
7214 if (remove_breakpoint (loc
, mark_uninserted
))
7216 /* This is just about all we can do. We could keep this
7217 location on the global list, and try to remove it next
7218 time, but there's no particular reason why we will
7221 Note that at this point, loc->owner is still valid,
7222 as delete_breakpoint frees the breakpoint only
7223 after calling us. */
7224 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7225 loc
->owner
->number
);
7233 if (removed
&& non_stop
)
7235 /* This location was removed from the targets. In non-stop mode,
7236 a race condition is possible where we've removed a breakpoint,
7237 but stop events for that breakpoint are already queued and will
7238 arrive later. To suppress spurious SIGTRAPs reported to user,
7239 we keep this breakpoint location for a bit, and will retire it
7240 after we see 3 * thread_count events.
7241 The theory here is that reporting of events should,
7242 "on the average", be fair, so after that many event we'll see
7243 events from all threads that have anything of interest, and no
7244 longer need to keep this breakpoint. This is just a
7245 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7246 which is usability issue, but not a correctness problem. */
7247 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7250 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
7253 free_bp_location (loc
);
7259 check_duplicates (b
);
7262 if (breakpoints_always_inserted_mode ()
7264 && target_has_execution
)
7265 insert_breakpoint_locations ();
7269 breakpoint_retire_moribund (void)
7271 struct bp_location
*loc
;
7274 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7275 if (--(loc
->events_till_retirement
) == 0)
7277 free_bp_location (loc
);
7278 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7284 update_global_location_list_nothrow (int inserting
)
7286 struct gdb_exception e
;
7287 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7288 update_global_location_list (inserting
);
7291 /* Clear BPT from a BPS. */
7293 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7296 for (bs
= bps
; bs
; bs
= bs
->next
)
7297 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7299 bs
->breakpoint_at
= NULL
;
7301 /* bs->commands will be freed later. */
7305 /* Callback for iterate_over_threads. */
7307 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7309 struct breakpoint
*bpt
= data
;
7310 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7314 /* Delete a breakpoint and clean up all traces of it in the data
7318 delete_breakpoint (struct breakpoint
*bpt
)
7320 struct breakpoint
*b
;
7321 struct bp_location
*loc
, *next
;
7323 gdb_assert (bpt
!= NULL
);
7325 /* Has this bp already been deleted? This can happen because multiple
7326 lists can hold pointers to bp's. bpstat lists are especial culprits.
7328 One example of this happening is a watchpoint's scope bp. When the
7329 scope bp triggers, we notice that the watchpoint is out of scope, and
7330 delete it. We also delete its scope bp. But the scope bp is marked
7331 "auto-deleting", and is already on a bpstat. That bpstat is then
7332 checked for auto-deleting bp's, which are deleted.
7334 A real solution to this problem might involve reference counts in bp's,
7335 and/or giving them pointers back to their referencing bpstat's, and
7336 teaching delete_breakpoint to only free a bp's storage when no more
7337 references were extent. A cheaper bandaid was chosen. */
7338 if (bpt
->type
== bp_none
)
7341 observer_notify_breakpoint_deleted (bpt
->number
);
7343 if (breakpoint_chain
== bpt
)
7344 breakpoint_chain
= bpt
->next
;
7349 b
->next
= bpt
->next
;
7353 free_command_lines (&bpt
->commands
);
7354 if (bpt
->cond_string
!= NULL
)
7355 xfree (bpt
->cond_string
);
7356 if (bpt
->addr_string
!= NULL
)
7357 xfree (bpt
->addr_string
);
7358 if (bpt
->exp
!= NULL
)
7360 if (bpt
->exp_string
!= NULL
)
7361 xfree (bpt
->exp_string
);
7362 if (bpt
->val
!= NULL
)
7363 value_free (bpt
->val
);
7364 if (bpt
->source_file
!= NULL
)
7365 xfree (bpt
->source_file
);
7366 if (bpt
->dll_pathname
!= NULL
)
7367 xfree (bpt
->dll_pathname
);
7368 if (bpt
->triggered_dll_pathname
!= NULL
)
7369 xfree (bpt
->triggered_dll_pathname
);
7370 if (bpt
->exec_pathname
!= NULL
)
7371 xfree (bpt
->exec_pathname
);
7373 /* Be sure no bpstat's are pointing at it after it's been freed. */
7374 /* FIXME, how can we find all bpstat's?
7375 We just check stop_bpstat for now. Note that we cannot just
7376 remove bpstats pointing at bpt from the stop_bpstat list
7377 entirely, as breakpoint commands are associated with the bpstat;
7378 if we remove it here, then the later call to
7379 bpstat_do_actions (&stop_bpstat);
7380 in event-top.c won't do anything, and temporary breakpoints
7381 with commands won't work. */
7383 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7385 /* Now that breakpoint is removed from breakpoint
7386 list, update the global location list. This
7387 will remove locations that used to belong to
7388 this breakpoint. Do this before freeing
7389 the breakpoint itself, since remove_breakpoint
7390 looks at location's owner. It might be better
7391 design to have location completely self-contained,
7392 but it's not the case now. */
7393 update_global_location_list (0);
7396 /* On the chance that someone will soon try again to delete this same
7397 bp, we mark it as deleted before freeing its storage. */
7398 bpt
->type
= bp_none
;
7404 do_delete_breakpoint_cleanup (void *b
)
7406 delete_breakpoint (b
);
7410 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7412 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7416 delete_command (char *arg
, int from_tty
)
7418 struct breakpoint
*b
, *temp
;
7424 int breaks_to_delete
= 0;
7426 /* Delete all breakpoints if no argument.
7427 Do not delete internal or call-dummy breakpoints, these
7428 have to be deleted with an explicit breakpoint number argument. */
7431 if (b
->type
!= bp_call_dummy
&&
7432 b
->type
!= bp_shlib_event
&&
7433 b
->type
!= bp_thread_event
&&
7434 b
->type
!= bp_overlay_event
&&
7437 breaks_to_delete
= 1;
7442 /* Ask user only if there are some breakpoints to delete. */
7444 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7446 ALL_BREAKPOINTS_SAFE (b
, temp
)
7448 if (b
->type
!= bp_call_dummy
&&
7449 b
->type
!= bp_shlib_event
&&
7450 b
->type
!= bp_thread_event
&&
7451 b
->type
!= bp_overlay_event
&&
7453 delete_breakpoint (b
);
7458 map_breakpoint_numbers (arg
, delete_breakpoint
);
7462 all_locations_are_pending (struct bp_location
*loc
)
7464 for (; loc
; loc
= loc
->next
)
7465 if (!loc
->shlib_disabled
)
7470 /* Subroutine of update_breakpoint_locations to simplify it.
7471 Return non-zero if multiple fns in list LOC have the same name.
7472 Null names are ignored. */
7475 ambiguous_names_p (struct bp_location
*loc
)
7477 struct bp_location
*l
;
7478 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7479 (int (*) (const void *, const void *)) streq
,
7480 NULL
, xcalloc
, xfree
);
7482 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7485 const char *name
= l
->function_name
;
7487 /* Allow for some names to be NULL, ignore them. */
7491 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7493 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7508 update_breakpoint_locations (struct breakpoint
*b
,
7509 struct symtabs_and_lines sals
)
7513 struct bp_location
*existing_locations
= b
->loc
;
7515 /* If there's no new locations, and all existing locations
7516 are pending, don't do anything. This optimizes
7517 the common case where all locations are in the same
7518 shared library, that was unloaded. We'd like to
7519 retain the location, so that when the library
7520 is loaded again, we don't loose the enabled/disabled
7521 status of the individual locations. */
7522 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7527 for (i
= 0; i
< sals
.nelts
; ++i
)
7529 struct bp_location
*new_loc
=
7530 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7532 /* Reparse conditions, they might contain references to the
7534 if (b
->cond_string
!= NULL
)
7536 struct gdb_exception e
;
7539 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7541 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7546 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7547 b
->number
, e
.message
);
7548 new_loc
->enabled
= 0;
7552 if (b
->source_file
!= NULL
)
7553 xfree (b
->source_file
);
7554 if (sals
.sals
[i
].symtab
== NULL
)
7555 b
->source_file
= NULL
;
7558 savestring (sals
.sals
[i
].symtab
->filename
,
7559 strlen (sals
.sals
[i
].symtab
->filename
));
7561 if (b
->line_number
== 0)
7562 b
->line_number
= sals
.sals
[i
].line
;
7565 /* Update locations of permanent breakpoints. */
7566 if (b
->enable_state
== bp_permanent
)
7567 make_breakpoint_permanent (b
);
7569 /* If possible, carry over 'disable' status from existing breakpoints. */
7571 struct bp_location
*e
= existing_locations
;
7572 /* If there are multiple breakpoints with the same function name,
7573 e.g. for inline functions, comparing function names won't work.
7574 Instead compare pc addresses; this is just a heuristic as things
7575 may have moved, but in practice it gives the correct answer
7576 often enough until a better solution is found. */
7577 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7579 for (; e
; e
= e
->next
)
7581 if (!e
->enabled
&& e
->function_name
)
7583 struct bp_location
*l
= b
->loc
;
7584 if (have_ambiguous_names
)
7586 for (; l
; l
= l
->next
)
7587 if (e
->address
== l
->address
)
7595 for (; l
; l
= l
->next
)
7596 if (l
->function_name
7597 && strcmp (e
->function_name
, l
->function_name
) == 0)
7607 update_global_location_list (1);
7611 /* Reset a breakpoint given it's struct breakpoint * BINT.
7612 The value we return ends up being the return value from catch_errors.
7613 Unused in this case. */
7616 breakpoint_re_set_one (void *bint
)
7618 /* get past catch_errs */
7619 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7623 int *not_found_ptr
= ¬_found
;
7624 struct symtabs_and_lines sals
= {};
7625 struct symtabs_and_lines expanded
;
7627 enum enable_state save_enable
;
7628 struct gdb_exception e
;
7634 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7638 case bp_hardware_breakpoint
:
7640 case bp_catch_unload
:
7641 if (b
->addr_string
== NULL
)
7643 /* Anything without a string can't be re-set. */
7644 delete_breakpoint (b
);
7648 set_language (b
->language
);
7649 input_radix
= b
->input_radix
;
7651 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7653 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7658 int not_found_and_ok
= 0;
7659 /* For pending breakpoints, it's expected that parsing
7660 will fail until the right shared library is loaded.
7661 User has already told to create pending breakpoints and
7662 don't need extra messages. If breakpoint is in bp_shlib_disabled
7663 state, then user already saw the message about that breakpoint
7664 being disabled, and don't want to see more errors. */
7666 && (b
->condition_not_parsed
7667 || (b
->loc
&& b
->loc
->shlib_disabled
)
7668 || b
->enable_state
== bp_disabled
))
7669 not_found_and_ok
= 1;
7671 if (!not_found_and_ok
)
7673 /* We surely don't want to warn about the same breakpoint
7674 10 times. One solution, implemented here, is disable
7675 the breakpoint on error. Another solution would be to
7676 have separate 'warning emitted' flag. Since this
7677 happens only when a binary has changed, I don't know
7678 which approach is better. */
7679 b
->enable_state
= bp_disabled
;
7680 throw_exception (e
);
7687 gdb_assert (sals
.nelts
== 1);
7688 resolve_sal_pc (&sals
.sals
[0]);
7689 if (b
->condition_not_parsed
&& s
&& s
[0])
7691 char *cond_string
= 0;
7693 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7694 &cond_string
, &thread
);
7696 b
->cond_string
= cond_string
;
7698 b
->condition_not_parsed
= 0;
7700 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7701 update_breakpoint_locations (b
, expanded
);
7707 case bp_hardware_watchpoint
:
7708 case bp_read_watchpoint
:
7709 case bp_access_watchpoint
:
7710 /* Watchpoint can be either on expression using entirely global variables,
7711 or it can be on local variables.
7713 Watchpoints of the first kind are never auto-deleted, and even persist
7714 across program restarts. Since they can use variables from shared
7715 libraries, we need to reparse expression as libraries are loaded
7718 Watchpoints on local variables can also change meaning as result
7719 of solib event. For example, if a watchpoint uses both a local and
7720 a global variables in expression, it's a local watchpoint, but
7721 unloading of a shared library will make the expression invalid.
7722 This is not a very common use case, but we still re-evaluate
7723 expression, to avoid surprises to the user.
7725 Note that for local watchpoints, we re-evaluate it only if
7726 watchpoints frame id is still valid. If it's not, it means
7727 the watchpoint is out of scope and will be deleted soon. In fact,
7728 I'm not sure we'll ever be called in this case.
7730 If a local watchpoint's frame id is still valid, then
7731 b->exp_valid_block is likewise valid, and we can safely use it.
7733 Don't do anything about disabled watchpoints, since they will
7734 be reevaluated again when enabled. */
7735 update_watchpoint (b
, 1 /* reparse */);
7737 /* We needn't really do anything to reset these, since the mask
7738 that requests them is unaffected by e.g., new libraries being
7744 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7746 /* Delete overlay event breakpoints; they will be reset later by
7747 breakpoint_re_set. */
7748 case bp_overlay_event
:
7749 delete_breakpoint (b
);
7752 /* This breakpoint is special, it's set up when the inferior
7753 starts and we really don't want to touch it. */
7754 case bp_shlib_event
:
7756 /* Like bp_shlib_event, this breakpoint type is special.
7757 Once it is set up, we do not want to touch it. */
7758 case bp_thread_event
:
7760 /* Keep temporary breakpoints, which can be encountered when we step
7761 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7762 Otherwise these should have been blown away via the cleanup chain
7763 or by breakpoint_init_inferior when we rerun the executable. */
7766 case bp_watchpoint_scope
:
7768 case bp_step_resume
:
7770 case bp_longjmp_resume
:
7777 /* Re-set all breakpoints after symbols have been re-loaded. */
7779 breakpoint_re_set (void)
7781 struct breakpoint
*b
, *temp
;
7782 enum language save_language
;
7783 int save_input_radix
;
7785 save_language
= current_language
->la_language
;
7786 save_input_radix
= input_radix
;
7787 ALL_BREAKPOINTS_SAFE (b
, temp
)
7789 /* Format possible error msg */
7790 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7792 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7793 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7794 do_cleanups (cleanups
);
7796 set_language (save_language
);
7797 input_radix
= save_input_radix
;
7799 create_overlay_event_breakpoint ("_ovly_debug_event");
7802 /* Reset the thread number of this breakpoint:
7804 - If the breakpoint is for all threads, leave it as-is.
7805 - Else, reset it to the current thread for inferior_ptid. */
7807 breakpoint_re_set_thread (struct breakpoint
*b
)
7809 if (b
->thread
!= -1)
7811 if (in_thread_list (inferior_ptid
))
7812 b
->thread
= pid_to_thread_id (inferior_ptid
);
7816 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7817 If from_tty is nonzero, it prints a message to that effect,
7818 which ends with a period (no newline). */
7821 set_ignore_count (int bptnum
, int count
, int from_tty
)
7823 struct breakpoint
*b
;
7829 if (b
->number
== bptnum
)
7831 b
->ignore_count
= count
;
7835 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7837 else if (count
== 1)
7838 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7841 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7844 breakpoints_changed ();
7845 observer_notify_breakpoint_modified (b
->number
);
7849 error (_("No breakpoint number %d."), bptnum
);
7853 make_breakpoint_silent (struct breakpoint
*b
)
7855 /* Silence the breakpoint. */
7859 /* Command to set ignore-count of breakpoint N to COUNT. */
7862 ignore_command (char *args
, int from_tty
)
7868 error_no_arg (_("a breakpoint number"));
7870 num
= get_number (&p
);
7872 error (_("bad breakpoint number: '%s'"), args
);
7874 error (_("Second argument (specified ignore-count) is missing."));
7876 set_ignore_count (num
,
7877 longest_to_int (value_as_long (parse_and_eval (p
))),
7880 printf_filtered ("\n");
7883 /* Call FUNCTION on each of the breakpoints
7884 whose numbers are given in ARGS. */
7887 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7892 struct breakpoint
*b
, *tmp
;
7896 error_no_arg (_("one or more breakpoint numbers"));
7903 num
= get_number_or_range (&p1
);
7906 warning (_("bad breakpoint number at or near '%s'"), p
);
7910 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7911 if (b
->number
== num
)
7913 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7916 if (related_breakpoint
)
7917 function (related_breakpoint
);
7921 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7927 static struct bp_location
*
7928 find_location_by_number (char *number
)
7930 char *dot
= strchr (number
, '.');
7934 struct breakpoint
*b
;
7935 struct bp_location
*loc
;
7940 bp_num
= get_number_or_range (&p1
);
7942 error (_("Bad breakpoint number '%s'"), number
);
7945 if (b
->number
== bp_num
)
7950 if (!b
|| b
->number
!= bp_num
)
7951 error (_("Bad breakpoint number '%s'"), number
);
7954 loc_num
= get_number_or_range (&p1
);
7956 error (_("Bad breakpoint location number '%s'"), number
);
7960 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7963 error (_("Bad breakpoint location number '%s'"), dot
+1);
7969 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7970 If from_tty is nonzero, it prints a message to that effect,
7971 which ends with a period (no newline). */
7974 disable_breakpoint (struct breakpoint
*bpt
)
7976 /* Never disable a watchpoint scope breakpoint; we want to
7977 hit them when we leave scope so we can delete both the
7978 watchpoint and its scope breakpoint at that time. */
7979 if (bpt
->type
== bp_watchpoint_scope
)
7982 /* You can't disable permanent breakpoints. */
7983 if (bpt
->enable_state
== bp_permanent
)
7986 bpt
->enable_state
= bp_disabled
;
7988 update_global_location_list (0);
7990 observer_notify_breakpoint_modified (bpt
->number
);
7994 disable_command (char *args
, int from_tty
)
7996 struct breakpoint
*bpt
;
7998 ALL_BREAKPOINTS (bpt
)
8002 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
8008 case bp_catch_unload
:
8009 case bp_hardware_breakpoint
:
8011 case bp_hardware_watchpoint
:
8012 case bp_read_watchpoint
:
8013 case bp_access_watchpoint
:
8014 disable_breakpoint (bpt
);
8018 else if (strchr (args
, '.'))
8020 struct bp_location
*loc
= find_location_by_number (args
);
8023 update_global_location_list (0);
8026 map_breakpoint_numbers (args
, disable_breakpoint
);
8030 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
8032 int target_resources_ok
, other_type_used
;
8035 if (bpt
->type
== bp_hardware_breakpoint
)
8038 i
= hw_breakpoint_used_count ();
8039 target_resources_ok
=
8040 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
8042 if (target_resources_ok
== 0)
8043 error (_("No hardware breakpoint support in the target."));
8044 else if (target_resources_ok
< 0)
8045 error (_("Hardware breakpoints used exceeds limit."));
8048 if (bpt
->type
== bp_watchpoint
||
8049 bpt
->type
== bp_hardware_watchpoint
||
8050 bpt
->type
== bp_read_watchpoint
||
8051 bpt
->type
== bp_access_watchpoint
)
8053 struct frame_id saved_frame_id
;
8055 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
8056 if (bpt
->exp_valid_block
!= NULL
)
8058 struct frame_info
*fr
=
8059 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
8062 printf_filtered (_("\
8063 Cannot enable watchpoint %d because the block in which its expression\n\
8064 is valid is not currently in scope.\n"), bpt
->number
);
8071 value_free (bpt
->val
);
8072 mark
= value_mark ();
8073 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
8075 release_value (bpt
->val
);
8078 if (bpt
->type
== bp_hardware_watchpoint
||
8079 bpt
->type
== bp_read_watchpoint
||
8080 bpt
->type
== bp_access_watchpoint
)
8082 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
8083 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
8085 /* Hack around 'unused var' error for some targets here */
8086 (void) mem_cnt
, (void) i
;
8087 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
8088 bpt
->type
, i
+ mem_cnt
, other_type_used
);
8089 /* we can consider of type is bp_hardware_watchpoint, convert to
8090 bp_watchpoint in the following condition */
8091 if (target_resources_ok
< 0)
8093 printf_filtered (_("\
8094 Cannot enable watchpoint %d because target watch resources\n\
8095 have been allocated for other watchpoints.\n"), bpt
->number
);
8096 value_free_to_mark (mark
);
8101 select_frame (frame_find_by_id (saved_frame_id
));
8102 value_free_to_mark (mark
);
8105 if (bpt
->enable_state
!= bp_permanent
)
8106 bpt
->enable_state
= bp_enabled
;
8107 bpt
->disposition
= disposition
;
8108 update_global_location_list (1);
8109 breakpoints_changed ();
8111 observer_notify_breakpoint_modified (bpt
->number
);
8116 enable_breakpoint (struct breakpoint
*bpt
)
8118 do_enable_breakpoint (bpt
, bpt
->disposition
);
8121 /* The enable command enables the specified breakpoints (or all defined
8122 breakpoints) so they once again become (or continue to be) effective
8123 in stopping the inferior. */
8126 enable_command (char *args
, int from_tty
)
8128 struct breakpoint
*bpt
;
8130 ALL_BREAKPOINTS (bpt
)
8134 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8140 case bp_catch_unload
:
8141 case bp_hardware_breakpoint
:
8143 case bp_hardware_watchpoint
:
8144 case bp_read_watchpoint
:
8145 case bp_access_watchpoint
:
8146 enable_breakpoint (bpt
);
8150 else if (strchr (args
, '.'))
8152 struct bp_location
*loc
= find_location_by_number (args
);
8155 update_global_location_list (1);
8158 map_breakpoint_numbers (args
, enable_breakpoint
);
8162 enable_once_breakpoint (struct breakpoint
*bpt
)
8164 do_enable_breakpoint (bpt
, disp_disable
);
8168 enable_once_command (char *args
, int from_tty
)
8170 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8174 enable_delete_breakpoint (struct breakpoint
*bpt
)
8176 do_enable_breakpoint (bpt
, disp_del
);
8180 enable_delete_command (char *args
, int from_tty
)
8182 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8186 set_breakpoint_cmd (char *args
, int from_tty
)
8191 show_breakpoint_cmd (char *args
, int from_tty
)
8195 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8197 struct symtabs_and_lines
8198 decode_line_spec_1 (char *string
, int funfirstline
)
8200 struct symtabs_and_lines sals
;
8202 error (_("Empty line specification."));
8203 if (default_breakpoint_valid
)
8204 sals
= decode_line_1 (&string
, funfirstline
,
8205 default_breakpoint_symtab
,
8206 default_breakpoint_line
,
8207 (char ***) NULL
, NULL
);
8209 sals
= decode_line_1 (&string
, funfirstline
,
8210 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8212 error (_("Junk at end of line specification: %s"), string
);
8216 /* Create and insert a raw software breakpoint at PC. Return an
8217 identifier, which should be used to remove the breakpoint later.
8218 In general, places which call this should be using something on the
8219 breakpoint chain instead; this function should be eliminated
8223 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8225 struct bp_target_info
*bp_tgt
;
8227 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8228 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8230 bp_tgt
->placed_address
= pc
;
8231 if (target_insert_breakpoint (bp_tgt
) != 0)
8233 /* Could not insert the breakpoint. */
8241 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8244 deprecated_remove_raw_breakpoint (void *bp
)
8246 struct bp_target_info
*bp_tgt
= bp
;
8249 ret
= target_remove_breakpoint (bp_tgt
);
8255 /* One (or perhaps two) breakpoints used for software single stepping. */
8257 static void *single_step_breakpoints
[2];
8259 /* Create and insert a breakpoint for software single step. */
8262 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8266 if (single_step_breakpoints
[0] == NULL
)
8267 bpt_p
= &single_step_breakpoints
[0];
8270 gdb_assert (single_step_breakpoints
[1] == NULL
);
8271 bpt_p
= &single_step_breakpoints
[1];
8274 /* NOTE drow/2006-04-11: A future improvement to this function would be
8275 to only create the breakpoints once, and actually put them on the
8276 breakpoint chain. That would let us use set_raw_breakpoint. We could
8277 adjust the addresses each time they were needed. Doing this requires
8278 corresponding changes elsewhere where single step breakpoints are
8279 handled, however. So, for now, we use this. */
8281 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8283 error (_("Could not insert single-step breakpoint at 0x%s"),
8284 paddr_nz (next_pc
));
8287 /* Remove and delete any breakpoints used for software single step. */
8290 remove_single_step_breakpoints (void)
8292 gdb_assert (single_step_breakpoints
[0] != NULL
);
8294 /* See insert_single_step_breakpoint for more about this deprecated
8296 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8297 single_step_breakpoints
[0] = NULL
;
8299 if (single_step_breakpoints
[1] != NULL
)
8301 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8302 single_step_breakpoints
[1] = NULL
;
8306 /* Check whether a software single-step breakpoint is inserted at PC. */
8309 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8313 for (i
= 0; i
< 2; i
++)
8315 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8316 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8324 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8325 It is defined as a macro to prevent duplication.
8326 COMMAND should be a string constant containing the name of the command. */
8327 #define BREAK_ARGS_HELP(command) \
8328 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8329 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8330 If a line number is specified, break at start of code for that line.\n\
8331 If a function is specified, break at start of code for that function.\n\
8332 If an address is specified, break at that exact address.\n\
8333 With no LOCATION, uses current execution address of selected stack frame.\n\
8334 This is useful for breaking on return to a stack frame.\n\
8336 THREADNUM is the number from \"info threads\".\n\
8337 CONDITION is a boolean expression.\n\
8339 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8341 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8343 /* List of subcommands for "catch". */
8344 static struct cmd_list_element
*catch_cmdlist
;
8346 /* List of subcommands for "tcatch". */
8347 static struct cmd_list_element
*tcatch_cmdlist
;
8349 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8350 lists, and pass some additional user data to the command function. */
8352 add_catch_command (char *name
, char *docstring
,
8353 void (*sfunc
) (char *args
, int from_tty
,
8354 struct cmd_list_element
*command
),
8355 void *user_data_catch
,
8356 void *user_data_tcatch
)
8358 struct cmd_list_element
*command
;
8360 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8362 set_cmd_sfunc (command
, sfunc
);
8363 set_cmd_context (command
, user_data_catch
);
8365 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8367 set_cmd_sfunc (command
, sfunc
);
8368 set_cmd_context (command
, user_data_tcatch
);
8372 _initialize_breakpoint (void)
8374 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8375 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8376 struct cmd_list_element
*c
;
8378 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8380 breakpoint_chain
= 0;
8381 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8382 before a breakpoint is set. */
8383 breakpoint_count
= 0;
8385 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8386 Set ignore-count of breakpoint number N to COUNT.\n\
8387 Usage is `ignore N COUNT'."));
8389 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8391 add_com ("commands", class_breakpoint
, commands_command
, _("\
8392 Set commands to be executed when a breakpoint is hit.\n\
8393 Give breakpoint number as argument after \"commands\".\n\
8394 With no argument, the targeted breakpoint is the last one set.\n\
8395 The commands themselves follow starting on the next line.\n\
8396 Type a line containing \"end\" to indicate the end of them.\n\
8397 Give \"silent\" as the first line to make the breakpoint silent;\n\
8398 then no output is printed when it is hit, except what the commands print."));
8400 add_com ("condition", class_breakpoint
, condition_command
, _("\
8401 Specify breakpoint number N to break only if COND is true.\n\
8402 Usage is `condition N COND', where N is an integer and COND is an\n\
8403 expression to be evaluated whenever breakpoint N is reached."));
8405 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8406 Set a temporary breakpoint.\n\
8407 Like \"break\" except the breakpoint is only temporary,\n\
8408 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8409 by using \"enable delete\" on the breakpoint number.\n\
8411 BREAK_ARGS_HELP ("tbreak")));
8412 set_cmd_completer (c
, location_completer
);
8414 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8415 Set a hardware assisted breakpoint.\n\
8416 Like \"break\" except the breakpoint requires hardware support,\n\
8417 some target hardware may not have this support.\n\
8419 BREAK_ARGS_HELP ("hbreak")));
8420 set_cmd_completer (c
, location_completer
);
8422 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8423 Set a temporary hardware assisted breakpoint.\n\
8424 Like \"hbreak\" except the breakpoint is only temporary,\n\
8425 so it will be deleted when hit.\n\
8427 BREAK_ARGS_HELP ("thbreak")));
8428 set_cmd_completer (c
, location_completer
);
8430 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8431 Enable some breakpoints.\n\
8432 Give breakpoint numbers (separated by spaces) as arguments.\n\
8433 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8434 This is used to cancel the effect of the \"disable\" command.\n\
8435 With a subcommand you can enable temporarily."),
8436 &enablelist
, "enable ", 1, &cmdlist
);
8438 add_com ("ab", class_breakpoint
, enable_command
, _("\
8439 Enable some breakpoints.\n\
8440 Give breakpoint numbers (separated by spaces) as arguments.\n\
8441 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8442 This is used to cancel the effect of the \"disable\" command.\n\
8443 With a subcommand you can enable temporarily."));
8445 add_com_alias ("en", "enable", class_breakpoint
, 1);
8447 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8448 Enable some breakpoints.\n\
8449 Give breakpoint numbers (separated by spaces) as arguments.\n\
8450 This is used to cancel the effect of the \"disable\" command.\n\
8451 May be abbreviated to simply \"enable\".\n"),
8452 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8454 add_cmd ("once", no_class
, enable_once_command
, _("\
8455 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8456 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8459 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8460 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8461 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8464 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8465 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8466 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8469 add_cmd ("once", no_class
, enable_once_command
, _("\
8470 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8471 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8474 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8475 Disable some breakpoints.\n\
8476 Arguments are breakpoint numbers with spaces in between.\n\
8477 To disable all breakpoints, give no argument.\n\
8478 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8479 &disablelist
, "disable ", 1, &cmdlist
);
8480 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8481 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8483 add_com ("sb", 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."));
8489 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8490 Disable some breakpoints.\n\
8491 Arguments are breakpoint numbers with spaces in between.\n\
8492 To disable all breakpoints, give no argument.\n\
8493 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8494 This command may be abbreviated \"disable\"."),
8497 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8498 Delete some breakpoints or auto-display expressions.\n\
8499 Arguments are breakpoint numbers with spaces in between.\n\
8500 To delete all breakpoints, give no argument.\n\
8502 Also a prefix command for deletion of other GDB objects.\n\
8503 The \"unset\" command is also an alias for \"delete\"."),
8504 &deletelist
, "delete ", 1, &cmdlist
);
8505 add_com_alias ("d", "delete", class_breakpoint
, 1);
8506 add_com_alias ("del", "delete", class_breakpoint
, 1);
8508 add_com ("db", class_breakpoint
, delete_command
, _("\
8509 Delete some breakpoints.\n\
8510 Arguments are breakpoint numbers with spaces in between.\n\
8511 To delete all breakpoints, give no argument.\n"));
8513 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8514 Delete some breakpoints or auto-display expressions.\n\
8515 Arguments are breakpoint numbers with spaces in between.\n\
8516 To delete all breakpoints, give no argument.\n\
8517 This command may be abbreviated \"delete\"."),
8520 add_com ("clear", class_breakpoint
, clear_command
, _("\
8521 Clear breakpoint at specified line or function.\n\
8522 Argument may be line number, function name, or \"*\" and an address.\n\
8523 If line number is specified, all breakpoints in that line are cleared.\n\
8524 If function is specified, breakpoints at beginning of function are cleared.\n\
8525 If an address is specified, breakpoints at that address are cleared.\n\
8527 With no argument, clears all breakpoints in the line that the selected frame\n\
8530 See also the \"delete\" command which clears breakpoints by number."));
8532 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8533 Set breakpoint at specified line or function.\n"
8534 BREAK_ARGS_HELP ("break")));
8535 set_cmd_completer (c
, location_completer
);
8537 add_com_alias ("b", "break", class_run
, 1);
8538 add_com_alias ("br", "break", class_run
, 1);
8539 add_com_alias ("bre", "break", class_run
, 1);
8540 add_com_alias ("brea", "break", class_run
, 1);
8544 add_com_alias ("ba", "break", class_breakpoint
, 1);
8545 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8550 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8551 Break in function/address or break at a line in the current file."),
8552 &stoplist
, "stop ", 1, &cmdlist
);
8553 add_cmd ("in", class_breakpoint
, stopin_command
,
8554 _("Break in function or address."), &stoplist
);
8555 add_cmd ("at", class_breakpoint
, stopat_command
,
8556 _("Break at a line in the current file."), &stoplist
);
8557 add_com ("status", class_info
, breakpoints_info
, _("\
8558 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8559 The \"Type\" column indicates one of:\n\
8560 \tbreakpoint - normal breakpoint\n\
8561 \twatchpoint - watchpoint\n\
8562 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8563 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8564 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8565 address and file/line number respectively.\n\
8567 Convenience variable \"$_\" and default examine address for \"x\"\n\
8568 are set to the address of the last breakpoint listed unless the command\n\
8569 is prefixed with \"server \".\n\n\
8570 Convenience variable \"$bpnum\" contains the number of the last\n\
8574 add_info ("breakpoints", breakpoints_info
, _("\
8575 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8576 The \"Type\" column indicates one of:\n\
8577 \tbreakpoint - normal breakpoint\n\
8578 \twatchpoint - watchpoint\n\
8579 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8580 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8581 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8582 address and file/line number respectively.\n\
8584 Convenience variable \"$_\" and default examine address for \"x\"\n\
8585 are set to the address of the last breakpoint listed unless the command\n\
8586 is prefixed with \"server \".\n\n\
8587 Convenience variable \"$bpnum\" contains the number of the last\n\
8591 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8592 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8593 The \"Type\" column indicates one of:\n\
8594 \tbreakpoint - normal breakpoint\n\
8595 \twatchpoint - watchpoint\n\
8596 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8597 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8598 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8599 address and file/line number respectively.\n\
8601 Convenience variable \"$_\" and default examine address for \"x\"\n\
8602 are set to the address of the last breakpoint listed unless the command\n\
8603 is prefixed with \"server \".\n\n\
8604 Convenience variable \"$bpnum\" contains the number of the last\n\
8607 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8608 Status of all breakpoints, or breakpoint number NUMBER.\n\
8609 The \"Type\" column indicates one of:\n\
8610 \tbreakpoint - normal breakpoint\n\
8611 \twatchpoint - watchpoint\n\
8612 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8613 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8614 \tuntil - internal breakpoint used by the \"until\" command\n\
8615 \tfinish - internal breakpoint used by the \"finish\" command\n\
8616 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8617 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8618 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8619 address and file/line number respectively.\n\
8621 Convenience variable \"$_\" and default examine address for \"x\"\n\
8622 are set to the address of the last breakpoint listed unless the command\n\
8623 is prefixed with \"server \".\n\n\
8624 Convenience variable \"$bpnum\" contains the number of the last\n\
8626 &maintenanceinfolist
);
8628 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
8629 Set catchpoints to catch events."),
8630 &catch_cmdlist
, "catch ",
8631 0/*allow-unknown*/, &cmdlist
);
8633 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
8634 Set temporary catchpoints to catch events."),
8635 &tcatch_cmdlist
, "tcatch ",
8636 0/*allow-unknown*/, &cmdlist
);
8638 /* Add catch and tcatch sub-commands. */
8639 add_catch_command ("catch", _("\
8640 Catch an exception, when caught.\n\
8641 With an argument, catch only exceptions with the given name."),
8642 catch_catch_command
,
8645 add_catch_command ("throw", _("\
8646 Catch an exception, when thrown.\n\
8647 With an argument, catch only exceptions with the given name."),
8648 catch_throw_command
,
8651 add_catch_command ("fork", _("Catch calls to fork."),
8652 catch_fork_command_1
,
8653 (void *) (uintptr_t) catch_fork_permanent
,
8654 (void *) (uintptr_t) catch_fork_temporary
);
8655 add_catch_command ("vfork", _("Catch calls to vfork."),
8656 catch_fork_command_1
,
8657 (void *) (uintptr_t) catch_vfork_permanent
,
8658 (void *) (uintptr_t) catch_vfork_temporary
);
8659 add_catch_command ("exec", _("Catch calls to exec."),
8660 catch_exec_command_1
,
8663 add_catch_command ("load", _("\
8664 Catch library loads.\n\
8665 With an argument, catch only loads of that library."),
8666 catch_load_command_1
,
8669 add_catch_command ("unload", _("\
8670 Catch library unloads.\n\
8671 With an argument, catch only unloads of that library."),
8672 catch_unload_command_1
,
8675 add_catch_command ("exception", _("\
8676 Catch Ada exceptions, when raised.\n\
8677 With an argument, catch only exceptions with the given name."),
8678 catch_ada_exception_command
,
8681 add_catch_command ("assert", _("\
8682 Catch failed Ada assertions, when raised.\n\
8683 With an argument, catch only exceptions with the given name."),
8684 catch_assert_command
,
8688 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8689 Set a watchpoint for an expression.\n\
8690 A watchpoint stops execution of your program whenever the value of\n\
8691 an expression changes."));
8692 set_cmd_completer (c
, expression_completer
);
8694 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8695 Set a read watchpoint for an expression.\n\
8696 A watchpoint stops execution of your program whenever the value of\n\
8697 an expression is read."));
8698 set_cmd_completer (c
, expression_completer
);
8700 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8701 Set a watchpoint for an expression.\n\
8702 A watchpoint stops execution of your program whenever the value of\n\
8703 an expression is either read or written."));
8704 set_cmd_completer (c
, expression_completer
);
8706 add_info ("watchpoints", breakpoints_info
,
8707 _("Synonym for ``info breakpoints''."));
8710 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8711 respond to changes - contrary to the description. */
8712 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8713 &can_use_hw_watchpoints
, _("\
8714 Set debugger's willingness to use watchpoint hardware."), _("\
8715 Show debugger's willingness to use watchpoint hardware."), _("\
8716 If zero, gdb will not use hardware for new watchpoints, even if\n\
8717 such is available. (However, any hardware watchpoints that were\n\
8718 created before setting this to nonzero, will continue to use watchpoint\n\
8721 show_can_use_hw_watchpoints
,
8722 &setlist
, &showlist
);
8724 can_use_hw_watchpoints
= 1;
8726 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8727 Breakpoint specific settings\n\
8728 Configure various breakpoint-specific variables such as\n\
8729 pending breakpoint behavior"),
8730 &breakpoint_set_cmdlist
, "set breakpoint ",
8731 0/*allow-unknown*/, &setlist
);
8732 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8733 Breakpoint specific settings\n\
8734 Configure various breakpoint-specific variables such as\n\
8735 pending breakpoint behavior"),
8736 &breakpoint_show_cmdlist
, "show breakpoint ",
8737 0/*allow-unknown*/, &showlist
);
8739 add_setshow_auto_boolean_cmd ("pending", no_class
,
8740 &pending_break_support
, _("\
8741 Set debugger's behavior regarding pending breakpoints."), _("\
8742 Show debugger's behavior regarding pending breakpoints."), _("\
8743 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8744 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8745 an error. If auto, an unrecognized breakpoint location results in a\n\
8746 user-query to see if a pending breakpoint should be created."),
8748 show_pending_break_support
,
8749 &breakpoint_set_cmdlist
,
8750 &breakpoint_show_cmdlist
);
8752 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8754 add_setshow_boolean_cmd ("auto-hw", no_class
,
8755 &automatic_hardware_breakpoints
, _("\
8756 Set automatic usage of hardware breakpoints."), _("\
8757 Show automatic usage of hardware breakpoints."), _("\
8758 If set, the debugger will automatically use hardware breakpoints for\n\
8759 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8760 a warning will be emitted for such breakpoints."),
8762 show_automatic_hardware_breakpoints
,
8763 &breakpoint_set_cmdlist
,
8764 &breakpoint_show_cmdlist
);
8766 add_setshow_enum_cmd ("always-inserted", class_support
,
8767 always_inserted_enums
, &always_inserted_mode
, _("\
8768 Set mode for inserting breakpoints."), _("\
8769 Show mode for inserting breakpoints."), _("\
8770 When this mode is off, breakpoints are inserted in inferior when it is\n\
8771 resumed, and removed when execution stops. When this mode is on,\n\
8772 breakpoints are inserted immediately and removed only when the user\n\
8773 deletes the breakpoint. When this mode is auto (which is the default),\n\
8774 the behaviour depends on the non-stop setting (see help set non-stop).\n\
8775 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
8776 behaves as if always-inserted mode is on; if gdb is controlling the\n\
8777 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
8779 &show_always_inserted_mode
,
8780 &breakpoint_set_cmdlist
,
8781 &breakpoint_show_cmdlist
);
8783 automatic_hardware_breakpoints
= 1;