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"
59 #include "gdb-events.h"
60 #include "mi/mi-common.h"
62 /* Prototypes for local functions. */
64 static void until_break_command_continuation (struct continuation_arg
*arg
);
66 static void catch_command_1 (char *, int, int);
68 static void enable_delete_command (char *, int);
70 static void enable_delete_breakpoint (struct breakpoint
*);
72 static void enable_once_command (char *, int);
74 static void enable_once_breakpoint (struct breakpoint
*);
76 static void disable_command (char *, int);
78 static void enable_command (char *, int);
80 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
82 static void ignore_command (char *, int);
84 static int breakpoint_re_set_one (void *);
86 static void clear_command (char *, int);
88 static void catch_command (char *, int);
90 static void watch_command (char *, int);
92 static int can_use_hardware_watchpoint (struct value
*);
94 static void break_command_1 (char *, int, int);
96 static void mention (struct breakpoint
*);
98 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
100 static void check_duplicates (struct breakpoint
*);
102 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
104 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
107 static void describe_other_breakpoints (CORE_ADDR
, asection
*, int);
109 static void breakpoints_info (char *, int);
111 static void breakpoint_1 (int, int);
113 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
115 static int breakpoint_cond_eval (void *);
117 static void cleanup_executing_breakpoints (void *);
119 static void commands_command (char *, int);
121 static void condition_command (char *, int);
123 static int get_number_trailer (char **, int);
125 void set_breakpoint_count (int);
134 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
136 static enum print_stop_action
print_it_typical (bpstat
);
138 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
142 enum exception_event_kind kind
;
145 args_for_catchpoint_enable
;
147 static int watchpoint_check (void *);
149 static void maintenance_info_breakpoints (char *, int);
151 static void create_longjmp_breakpoint (char *);
153 static void create_overlay_event_breakpoint (char *);
155 static int hw_breakpoint_used_count (void);
157 static int hw_watchpoint_used_count (enum bptype
, int *);
159 static void hbreak_command (char *, int);
161 static void thbreak_command (char *, int);
163 static void watch_command_1 (char *, int, int);
165 static void rwatch_command (char *, int);
167 static void awatch_command (char *, int);
169 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
171 static void create_fork_vfork_event_catchpoint (int tempflag
,
173 enum bptype bp_kind
);
175 static void stop_command (char *arg
, int from_tty
);
177 static void stopin_command (char *arg
, int from_tty
);
179 static void stopat_command (char *arg
, int from_tty
);
181 static char *ep_find_event_name_end (char *arg
);
183 static char *ep_parse_optional_if_clause (char **arg
);
185 static char *ep_parse_optional_filename (char **arg
);
187 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
188 enum exception_event_kind ex_event
,
189 struct symtab_and_line
*sal
);
191 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
192 char *arg
, int tempflag
, int from_tty
);
194 static void tcatch_command (char *arg
, int from_tty
);
196 static void ep_skip_leading_whitespace (char **s
);
198 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
200 static void free_bp_location (struct bp_location
*loc
);
202 static void mark_breakpoints_out (void);
204 static struct bp_location
*
205 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
);
208 unlink_locations_from_global_list (struct breakpoint
*bpt
);
211 is_hardware_watchpoint (struct breakpoint
*bpt
);
213 /* Prototypes for exported functions. */
215 /* If FALSE, gdb will not use hardware support for watchpoints, even
216 if such is available. */
217 static int can_use_hw_watchpoints
;
220 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
221 struct cmd_list_element
*c
,
224 fprintf_filtered (file
, _("\
225 Debugger's willingness to use watchpoint hardware is %s.\n"),
229 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
230 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
231 for unrecognized breakpoint locations.
232 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
233 static enum auto_boolean pending_break_support
;
235 show_pending_break_support (struct ui_file
*file
, int from_tty
,
236 struct cmd_list_element
*c
,
239 fprintf_filtered (file
, _("\
240 Debugger's behavior regarding pending breakpoints is %s.\n"),
244 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
245 set with "break" but falling in read-only memory.
246 If 0, gdb will warn about such breakpoints, but won't automatically
247 use hardware breakpoints. */
248 static int automatic_hardware_breakpoints
;
250 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
251 struct cmd_list_element
*c
,
254 fprintf_filtered (file
, _("\
255 Automatic usage of hardware breakpoints is %s.\n"),
260 void _initialize_breakpoint (void);
262 extern int addressprint
; /* Print machine addresses? */
264 /* Are we executing breakpoint commands? */
265 static int executing_breakpoint_commands
;
267 /* Are overlay event breakpoints enabled? */
268 static int overlay_events_enabled
;
270 /* Walk the following statement or block through all breakpoints.
271 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
274 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
276 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
277 for (B = breakpoint_chain; \
278 B ? (TMP=B->next, 1): 0; \
281 /* Similar iterators for the low-level breakpoints. */
283 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
285 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
286 for (B = bp_location_chain; \
287 B ? (TMP=B->global_next, 1): 0; \
290 /* True if breakpoint hit counts should be displayed in breakpoint info. */
292 int show_breakpoint_hit_counts
= 1;
294 /* Chains of all breakpoints defined. */
296 struct breakpoint
*breakpoint_chain
;
298 struct bp_location
*bp_location_chain
;
300 /* Number of last breakpoint made. */
302 int breakpoint_count
;
304 /* Pointer to current exception event record */
305 static struct exception_event_record
*current_exception_event
;
307 /* This function returns a pointer to the string representation of the
308 pathname of the dynamically-linked library that has just been
311 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
312 or undefined results are guaranteed.
314 This string's contents are only valid immediately after the
315 inferior has stopped in the dynamic linker hook, and becomes
316 invalid as soon as the inferior is continued. Clients should make
317 a copy of this string if they wish to continue the inferior and
318 then access the string. */
320 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
321 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
324 /* This function returns a pointer to the string representation of the
325 pathname of the dynamically-linked library that has just been
328 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
329 TRUE, or undefined results are guaranteed.
331 This string's contents are only valid immediately after the
332 inferior has stopped in the dynamic linker hook, and becomes
333 invalid as soon as the inferior is continued. Clients should make
334 a copy of this string if they wish to continue the inferior and
335 then access the string. */
337 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
338 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
341 /* This function is called by the "catch load" command. It allows the
342 debugger to be notified by the dynamic linker when a specified
343 library file (or any library file, if filename is NULL) is loaded. */
345 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
346 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
347 error (_("catch of library loads not yet implemented on this platform"))
350 /* This function is called by the "catch unload" command. It allows
351 the debugger to be notified by the dynamic linker when a specified
352 library file (or any library file, if filename is NULL) is
355 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
356 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
357 error (_("catch of library unloads not yet implemented on this platform"))
360 /* Return whether a breakpoint is an active enabled breakpoint. */
362 breakpoint_enabled (struct breakpoint
*b
)
364 return (b
->enable_state
== bp_enabled
);
367 /* Set breakpoint count to NUM. */
370 set_breakpoint_count (int num
)
372 breakpoint_count
= num
;
373 set_internalvar (lookup_internalvar ("bpnum"),
374 value_from_longest (builtin_type_int
, (LONGEST
) num
));
377 /* Used in run_command to zero the hit count when a new run starts. */
380 clear_breakpoint_hit_counts (void)
382 struct breakpoint
*b
;
388 /* Default address, symtab and line to put a breakpoint at
389 for "break" command with no arg.
390 if default_breakpoint_valid is zero, the other three are
391 not valid, and "break" with no arg is an error.
393 This set by print_stack_frame, which calls set_default_breakpoint. */
395 int default_breakpoint_valid
;
396 CORE_ADDR default_breakpoint_address
;
397 struct symtab
*default_breakpoint_symtab
;
398 int default_breakpoint_line
;
400 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
401 Advance *PP after the string and any trailing whitespace.
403 Currently the string can either be a number or "$" followed by the name
404 of a convenience variable. Making it an expression wouldn't work well
405 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
407 If the string is a NULL pointer, that denotes the last breakpoint.
409 TRAILER is a character which can be found after the number; most
410 commonly this is `-'. If you don't want a trailer, use \0. */
412 get_number_trailer (char **pp
, int trailer
)
414 int retval
= 0; /* default */
418 /* Empty line means refer to the last breakpoint. */
419 return breakpoint_count
;
422 /* Make a copy of the name, so we can null-terminate it
423 to pass to lookup_internalvar(). */
428 while (isalnum (*p
) || *p
== '_')
430 varname
= (char *) alloca (p
- start
+ 1);
431 strncpy (varname
, start
, p
- start
);
432 varname
[p
- start
] = '\0';
433 val
= value_of_internalvar (lookup_internalvar (varname
));
434 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
435 retval
= (int) value_as_long (val
);
438 printf_filtered (_("Convenience variable must have integer value.\n"));
446 while (*p
>= '0' && *p
<= '9')
449 /* There is no number here. (e.g. "cond a == b"). */
451 /* Skip non-numeric token */
452 while (*p
&& !isspace((int) *p
))
454 /* Return zero, which caller must interpret as error. */
460 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
462 /* Trailing junk: return 0 and let caller print error msg. */
463 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
474 /* Like get_number_trailer, but don't allow a trailer. */
476 get_number (char **pp
)
478 return get_number_trailer (pp
, '\0');
481 /* Parse a number or a range.
482 * A number will be of the form handled by get_number.
483 * A range will be of the form <number1> - <number2>, and
484 * will represent all the integers between number1 and number2,
487 * While processing a range, this fuction is called iteratively;
488 * At each call it will return the next value in the range.
490 * At the beginning of parsing a range, the char pointer PP will
491 * be advanced past <number1> and left pointing at the '-' token.
492 * Subsequent calls will not advance the pointer until the range
493 * is completed. The call that completes the range will advance
494 * pointer PP past <number2>.
498 get_number_or_range (char **pp
)
500 static int last_retval
, end_value
;
501 static char *end_ptr
;
502 static int in_range
= 0;
506 /* Default case: pp is pointing either to a solo number,
507 or to the first number of a range. */
508 last_retval
= get_number_trailer (pp
, '-');
513 /* This is the start of a range (<number1> - <number2>).
514 Skip the '-', parse and remember the second number,
515 and also remember the end of the final token. */
519 while (isspace ((int) *end_ptr
))
520 end_ptr
++; /* skip white space */
521 end_value
= get_number (temp
);
522 if (end_value
< last_retval
)
524 error (_("inverted range"));
526 else if (end_value
== last_retval
)
528 /* degenerate range (number1 == number2). Advance the
529 token pointer so that the range will be treated as a
538 error (_("negative value"));
541 /* pp points to the '-' that betokens a range. All
542 number-parsing has already been done. Return the next
543 integer value (one greater than the saved previous value).
544 Do not advance the token pointer 'pp' until the end of range
547 if (++last_retval
== end_value
)
549 /* End of range reached; advance token pointer. */
559 /* condition N EXP -- set break condition of breakpoint N to EXP. */
562 condition_command (char *arg
, int from_tty
)
564 struct breakpoint
*b
;
569 error_no_arg (_("breakpoint number"));
572 bnum
= get_number (&p
);
574 error (_("Bad breakpoint argument: '%s'"), arg
);
577 if (b
->number
== bnum
)
579 struct bp_location
*loc
= b
->loc
;
580 for (; loc
; loc
= loc
->next
)
588 if (b
->cond_string
!= NULL
)
589 xfree (b
->cond_string
);
593 b
->cond_string
= NULL
;
595 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
600 /* I don't know if it matters whether this is the string the user
601 typed in or the decompiled expression. */
602 b
->cond_string
= savestring (arg
, strlen (arg
));
603 b
->condition_not_parsed
= 0;
604 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
607 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
609 error (_("Junk at end of expression"));
612 breakpoints_changed ();
613 breakpoint_modify_event (b
->number
);
617 error (_("No breakpoint number %d."), bnum
);
621 commands_command (char *arg
, int from_tty
)
623 struct breakpoint
*b
;
626 struct command_line
*l
;
628 /* If we allowed this, we would have problems with when to
629 free the storage, if we change the commands currently
632 if (executing_breakpoint_commands
)
633 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
636 bnum
= get_number (&p
);
639 error (_("Unexpected extra arguments following breakpoint number."));
642 if (b
->number
== bnum
)
644 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
646 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
647 l
= read_command_lines (tmpbuf
, from_tty
);
648 do_cleanups (cleanups
);
649 free_command_lines (&b
->commands
);
651 breakpoints_changed ();
652 breakpoint_modify_event (b
->number
);
655 error (_("No breakpoint number %d."), bnum
);
658 /* Like commands_command, but instead of reading the commands from
659 input stream, takes them from an already parsed command structure.
661 This is used by cli-script.c to DTRT with breakpoint commands
662 that are part of if and while bodies. */
663 enum command_control_type
664 commands_from_control_command (char *arg
, struct command_line
*cmd
)
666 struct breakpoint
*b
;
670 /* If we allowed this, we would have problems with when to
671 free the storage, if we change the commands currently
674 if (executing_breakpoint_commands
)
675 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
677 /* An empty string for the breakpoint number means the last
678 breakpoint, but get_number expects a NULL pointer. */
683 bnum
= get_number (&p
);
686 error (_("Unexpected extra arguments following breakpoint number."));
689 if (b
->number
== bnum
)
691 free_command_lines (&b
->commands
);
692 if (cmd
->body_count
!= 1)
693 error (_("Invalid \"commands\" block structure."));
694 /* We need to copy the commands because if/while will free the
695 list after it finishes execution. */
696 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
697 breakpoints_changed ();
698 breakpoint_modify_event (b
->number
);
699 return simple_control
;
701 error (_("No breakpoint number %d."), bnum
);
704 /* Like target_read_memory() but if breakpoints are inserted, return
705 the shadow contents instead of the breakpoints themselves.
707 Read "memory data" from whatever target or inferior we have.
708 Returns zero if successful, errno value if not. EIO is used
709 for address out of bounds. If breakpoints are inserted, returns
710 shadow contents, not the breakpoints themselves. From breakpoint.c. */
713 read_memory_nobpt (CORE_ADDR memaddr
, gdb_byte
*myaddr
, unsigned len
)
716 const struct bp_location
*b
;
717 CORE_ADDR bp_addr
= 0;
720 if (gdbarch_breakpoint_from_pc (current_gdbarch
, &bp_addr
, &bp_size
) == NULL
)
721 /* No breakpoints on this machine. */
722 return target_read_memory (memaddr
, myaddr
, len
);
726 if (b
->owner
->type
== bp_none
)
727 warning (_("reading through apparently deleted breakpoint #%d?"),
730 if (b
->loc_type
!= bp_loc_software_breakpoint
)
734 /* Addresses and length of the part of the breakpoint that
736 bp_addr
= b
->target_info
.placed_address
;
737 bp_size
= b
->target_info
.shadow_len
;
739 /* bp isn't valid, or doesn't shadow memory. */
741 if (bp_addr
+ bp_size
<= memaddr
)
742 /* The breakpoint is entirely before the chunk of memory we
745 if (bp_addr
>= memaddr
+ len
)
746 /* The breakpoint is entirely after the chunk of memory we are
749 /* Copy the breakpoint from the shadow contents, and recurse for
750 the things before and after. */
752 /* Offset within shadow_contents. */
755 if (bp_addr
< memaddr
)
757 /* Only copy the second part of the breakpoint. */
758 bp_size
-= memaddr
- bp_addr
;
759 bptoffset
= memaddr
- bp_addr
;
763 if (bp_addr
+ bp_size
> memaddr
+ len
)
765 /* Only copy the first part of the breakpoint. */
766 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
769 memcpy (myaddr
+ bp_addr
- memaddr
,
770 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
772 if (bp_addr
> memaddr
)
774 /* Copy the section of memory before the breakpoint. */
775 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
780 if (bp_addr
+ bp_size
< memaddr
+ len
)
782 /* Copy the section of memory after the breakpoint. */
783 status
= read_memory_nobpt (bp_addr
+ bp_size
,
784 myaddr
+ bp_addr
+ bp_size
- memaddr
,
785 memaddr
+ len
- (bp_addr
+ bp_size
));
792 /* Nothing overlaps. Just call read_memory_noerr. */
793 return target_read_memory (memaddr
, myaddr
, len
);
797 /* A wrapper function for inserting catchpoints. */
799 insert_catchpoint (struct ui_out
*uo
, void *args
)
801 struct breakpoint
*b
= (struct breakpoint
*) args
;
807 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
810 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
813 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
816 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
822 is_hardware_watchpoint (struct breakpoint
*bpt
)
824 return (bpt
->type
== bp_hardware_watchpoint
825 || bpt
->type
== bp_read_watchpoint
826 || bpt
->type
== bp_access_watchpoint
);
829 /* Assuming that B is a hardware breakpoint:
830 - Reparse watchpoint expression, is REPARSE is non-zero
831 - Evaluate expression and store the result in B->val
832 - Update the list of values that must be watched in B->loc.
834 If the watchpoint is disabled, do nothing. If this is
835 local watchpoint that is out of scope, delete it. */
837 update_watchpoint (struct breakpoint
*b
, int reparse
)
839 int within_current_scope
;
840 struct value
*mark
= value_mark ();
841 struct frame_id saved_frame_id
;
842 struct bp_location
*loc
;
845 unlink_locations_from_global_list (b
);
846 for (loc
= b
->loc
; loc
;)
848 struct bp_location
*loc_next
= loc
->next
;
849 remove_breakpoint (loc
, mark_uninserted
);
855 if (b
->disposition
== disp_del_at_next_stop
)
858 /* Save the current frame's ID so we can restore it after
859 evaluating the watchpoint expression on its own frame. */
860 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
861 took a frame parameter, so that we didn't have to change the
863 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
865 /* Determine if the watchpoint is within scope. */
866 if (b
->exp_valid_block
== NULL
)
867 within_current_scope
= 1;
870 struct frame_info
*fi
;
871 fi
= frame_find_by_id (b
->watchpoint_frame
);
872 within_current_scope
= (fi
!= NULL
);
873 if (within_current_scope
)
877 if (within_current_scope
&& reparse
)
886 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
887 /* If the meaning of expression itself changed, the old value is
888 no longer relevant. We don't want to report a watchpoint hit
889 to the user when the old value and the new value may actually
890 be completely different objects. */
896 /* If we failed to parse the expression, for example because
897 it refers to a global variable in a not-yet-loaded shared library,
898 don't try to insert watchpoint. We don't automatically delete
899 such watchpoint, though, since failure to parse expression
900 is different from out-of-scope watchpoint. */
901 if (within_current_scope
&& b
->exp
)
903 struct value
*v
, *next
;
905 /* Evaluate the expression and make sure it's not lazy, so that
906 after target stops again, we have a non-lazy previous value
907 to compare with. Also, making the value non-lazy will fetch
908 intermediate values as needed, which we use to decide which
911 The value returned by evaluate_expression is stored in b->val.
912 In addition, we look at all values which were created
913 during evaluation, and set watchoints at addresses as needed.
914 Those values are explicitly deleted here. */
915 v
= evaluate_expression (b
->exp
);
916 /* Avoid setting b->val if it's already set. The meaning of
917 b->val is 'the last value' user saw, and we should update
918 it only if we reported that last value to user. As it
919 happens, the code that reports it updates b->val directly. */
923 value_release_to_mark (mark
);
925 /* Look at each value on the value chain. */
928 /* If it's a memory location, and GDB actually needed
929 its contents to evaluate the expression, then we
931 if (VALUE_LVAL (v
) == lval_memory
934 struct type
*vtype
= check_typedef (value_type (v
));
936 /* We only watch structs and arrays if user asked
937 for it explicitly, never if they just happen to
938 appear in the middle of some value chain. */
940 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
941 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
945 struct bp_location
*loc
, **tmp
;
947 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
948 len
= TYPE_LENGTH (value_type (v
));
950 if (b
->type
== bp_read_watchpoint
)
952 else if (b
->type
== bp_access_watchpoint
)
955 loc
= allocate_bp_location (b
, bp_hardware_watchpoint
);
956 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
961 loc
->watchpoint_type
= type
;
965 next
= value_next (v
);
970 if (reparse
&& b
->cond_string
!= NULL
)
972 char *s
= b
->cond_string
;
975 xfree (b
->loc
->cond
);
978 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
981 else if (!within_current_scope
)
983 printf_filtered (_("\
984 Hardware watchpoint %d deleted because the program has left the block \n\
985 in which its expression is valid.\n"),
987 if (b
->related_breakpoint
)
988 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
989 b
->disposition
= disp_del_at_next_stop
;
992 /* Restore the selected frame. */
993 select_frame (frame_find_by_id (saved_frame_id
));
997 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
998 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
999 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1001 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1002 method for each breakpoint or catchpoint type. */
1004 insert_bp_location (struct bp_location
*bpt
,
1005 struct ui_file
*tmp_error_stream
,
1006 int *disabled_breaks
, int *process_warning
,
1007 int *hw_breakpoint_error
)
1011 if (!breakpoint_enabled (bpt
->owner
))
1014 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->inserted
|| bpt
->duplicate
)
1017 /* Initialize the target-specific information. */
1018 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1019 bpt
->target_info
.placed_address
= bpt
->address
;
1021 if (bpt
->loc_type
== bp_loc_software_breakpoint
1022 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1024 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1026 /* If the explicitly specified breakpoint type
1027 is not hardware breakpoint, check the memory map to see
1028 if the breakpoint address is in read only memory or not.
1029 Two important cases are:
1030 - location type is not hardware breakpoint, memory
1031 is readonly. We change the type of the location to
1032 hardware breakpoint.
1033 - location type is hardware breakpoint, memory is read-write.
1034 This means we've previously made the location hardware one, but
1035 then the memory map changed, so we undo.
1037 When breakpoints are removed, remove_breakpoints will
1038 use location types we've just set here, the only possible
1039 problem is that memory map has changed during running program,
1040 but it's not going to work anyway with current gdb. */
1041 struct mem_region
*mr
1042 = lookup_mem_region (bpt
->target_info
.placed_address
);
1046 if (automatic_hardware_breakpoints
)
1049 enum bp_loc_type new_type
;
1051 if (mr
->attrib
.mode
!= MEM_RW
)
1052 new_type
= bp_loc_hardware_breakpoint
;
1054 new_type
= bp_loc_software_breakpoint
;
1056 if (new_type
!= bpt
->loc_type
)
1058 static int said
= 0;
1059 bpt
->loc_type
= new_type
;
1062 fprintf_filtered (gdb_stdout
, _("\
1063 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1068 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1069 && mr
->attrib
.mode
!= MEM_RW
)
1070 warning (_("cannot set software breakpoint at readonly address %s"),
1071 paddr (bpt
->address
));
1075 /* First check to see if we have to handle an overlay. */
1076 if (overlay_debugging
== ovly_off
1077 || bpt
->section
== NULL
1078 || !(section_is_overlay (bpt
->section
)))
1080 /* No overlay handling: just set the breakpoint. */
1082 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1083 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1085 val
= target_insert_breakpoint (&bpt
->target_info
);
1089 /* This breakpoint is in an overlay section.
1090 Shall we set a breakpoint at the LMA? */
1091 if (!overlay_events_enabled
)
1093 /* Yes -- overlay event support is not active,
1094 so we must try to set a breakpoint at the LMA.
1095 This will not work for a hardware breakpoint. */
1096 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1097 warning (_("hardware breakpoint %d not supported in overlay!"),
1098 bpt
->owner
->number
);
1101 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1103 /* Set a software (trap) breakpoint at the LMA. */
1104 bpt
->overlay_target_info
= bpt
->target_info
;
1105 bpt
->overlay_target_info
.placed_address
= addr
;
1106 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1108 fprintf_unfiltered (tmp_error_stream
,
1109 "Overlay breakpoint %d failed: in ROM?",
1110 bpt
->owner
->number
);
1113 /* Shall we set a breakpoint at the VMA? */
1114 if (section_is_mapped (bpt
->section
))
1116 /* Yes. This overlay section is mapped into memory. */
1117 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1118 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1120 val
= target_insert_breakpoint (&bpt
->target_info
);
1124 /* No. This breakpoint will not be inserted.
1125 No error, but do not mark the bp as 'inserted'. */
1132 /* Can't set the breakpoint. */
1133 if (solib_address (bpt
->address
))
1135 /* See also: disable_breakpoints_in_shlibs. */
1137 bpt
->shlib_disabled
= 1;
1138 if (!*disabled_breaks
)
1140 fprintf_unfiltered (tmp_error_stream
,
1141 "Cannot insert breakpoint %d.\n",
1142 bpt
->owner
->number
);
1143 fprintf_unfiltered (tmp_error_stream
,
1144 "Temporarily disabling shared library breakpoints:\n");
1146 *disabled_breaks
= 1;
1147 fprintf_unfiltered (tmp_error_stream
,
1148 "breakpoint #%d\n", bpt
->owner
->number
);
1152 #ifdef ONE_PROCESS_WRITETEXT
1153 *process_warning
= 1;
1155 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1157 *hw_breakpoint_error
= 1;
1158 fprintf_unfiltered (tmp_error_stream
,
1159 "Cannot insert hardware breakpoint %d.\n",
1160 bpt
->owner
->number
);
1164 fprintf_unfiltered (tmp_error_stream
,
1165 "Cannot insert breakpoint %d.\n",
1166 bpt
->owner
->number
);
1167 fprintf_filtered (tmp_error_stream
,
1168 "Error accessing memory address ");
1169 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1170 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1171 safe_strerror (val
));
1182 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1183 /* NOTE drow/2003-09-08: This state only exists for removing
1184 watchpoints. It's not clear that it's necessary... */
1185 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1187 val
= target_insert_watchpoint (bpt
->address
,
1189 bpt
->watchpoint_type
);
1190 bpt
->inserted
= (val
!= -1);
1193 else if (bpt
->owner
->type
== bp_catch_fork
1194 || bpt
->owner
->type
== bp_catch_vfork
1195 || bpt
->owner
->type
== bp_catch_exec
)
1197 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1198 bpt
->owner
, RETURN_MASK_ERROR
);
1199 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1200 bpt
->owner
->number
);
1202 bpt
->owner
->enable_state
= bp_disabled
;
1206 /* We've already printed an error message if there was a problem
1207 inserting this catchpoint, and we've disabled the catchpoint,
1208 so just return success. */
1215 /* insert_breakpoints is used when starting or continuing the program.
1216 remove_breakpoints is used when the program stops.
1217 Both return zero if successful,
1218 or an `errno' value if could not write the inferior. */
1221 insert_breakpoints (void)
1223 struct breakpoint
*bpt
;
1224 struct bp_location
*b
, *temp
;
1227 int disabled_breaks
= 0;
1228 int hw_breakpoint_error
= 0;
1229 int process_warning
= 0;
1231 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1232 make_cleanup_ui_file_delete (tmp_error_stream
);
1234 /* Explicitly mark the warning -- this will only be printed if
1235 there was an error. */
1236 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1238 ALL_BREAKPOINTS (bpt
)
1239 if (is_hardware_watchpoint (bpt
))
1240 update_watchpoint (bpt
, 0 /* don't reparse */);
1242 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1244 if (!breakpoint_enabled (b
->owner
))
1247 /* There is no point inserting thread-specific breakpoints if the
1248 thread no longer exists. */
1249 if (b
->owner
->thread
!= -1
1250 && !valid_thread_id (b
->owner
->thread
))
1253 val
= insert_bp_location (b
, tmp_error_stream
,
1254 &disabled_breaks
, &process_warning
,
1255 &hw_breakpoint_error
);
1260 /* If we failed to insert all locations of a watchpoint,
1261 remove them, as half-inserted watchpoint is of limited use. */
1262 ALL_BREAKPOINTS (bpt
)
1264 int some_failed
= 0;
1265 struct bp_location
*loc
;
1267 if (!is_hardware_watchpoint (bpt
))
1270 if (bpt
->enable_state
!= bp_enabled
)
1273 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1281 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1283 remove_breakpoint (loc
, mark_uninserted
);
1285 hw_breakpoint_error
= 1;
1286 fprintf_unfiltered (tmp_error_stream
,
1287 "Could not insert hardware watchpoint %d.\n",
1295 /* If a hardware breakpoint or watchpoint was inserted, add a
1296 message about possibly exhausted resources. */
1297 if (hw_breakpoint_error
)
1299 fprintf_unfiltered (tmp_error_stream
,
1300 "Could not insert hardware breakpoints:\n\
1301 You may have requested too many hardware breakpoints/watchpoints.\n");
1303 #ifdef ONE_PROCESS_WRITETEXT
1304 if (process_warning
)
1305 fprintf_unfiltered (tmp_error_stream
,
1306 "The same program may be running in another process.");
1308 target_terminal_ours_for_output ();
1309 error_stream (tmp_error_stream
);
1314 remove_breakpoints (void)
1316 struct bp_location
*b
;
1319 ALL_BP_LOCATIONS (b
)
1323 val
= remove_breakpoint (b
, mark_uninserted
);
1332 remove_hw_watchpoints (void)
1334 struct bp_location
*b
;
1337 ALL_BP_LOCATIONS (b
)
1339 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1341 val
= remove_breakpoint (b
, mark_uninserted
);
1350 reattach_breakpoints (int pid
)
1352 struct bp_location
*b
;
1354 struct cleanup
*old_chain
= save_inferior_ptid ();
1355 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1356 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1358 make_cleanup_ui_file_delete (tmp_error_stream
);
1360 inferior_ptid
= pid_to_ptid (pid
);
1361 ALL_BP_LOCATIONS (b
)
1366 val
= insert_bp_location (b
, tmp_error_stream
,
1367 &dummy1
, &dummy2
, &dummy3
);
1370 do_cleanups (old_chain
);
1375 do_cleanups (old_chain
);
1380 update_breakpoints_after_exec (void)
1382 struct breakpoint
*b
;
1383 struct breakpoint
*temp
;
1385 /* Doing this first prevents the badness of having delete_breakpoint()
1386 write a breakpoint's current "shadow contents" to lift the bp. That
1387 shadow is NOT valid after an exec()! */
1388 mark_breakpoints_out ();
1390 ALL_BREAKPOINTS_SAFE (b
, temp
)
1392 /* Solib breakpoints must be explicitly reset after an exec(). */
1393 if (b
->type
== bp_shlib_event
)
1395 delete_breakpoint (b
);
1399 /* Thread event breakpoints must be set anew after an exec(),
1400 as must overlay event breakpoints. */
1401 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1403 delete_breakpoint (b
);
1407 /* Step-resume breakpoints are meaningless after an exec(). */
1408 if (b
->type
== bp_step_resume
)
1410 delete_breakpoint (b
);
1414 /* Don't delete an exec catchpoint, because else the inferior
1415 won't stop when it ought!
1417 Similarly, we probably ought to keep vfork catchpoints, 'cause
1418 on this target, we may not be able to stop when the vfork is
1419 seen, but only when the subsequent exec is seen. (And because
1420 deleting fork catchpoints here but not vfork catchpoints will
1421 seem mysterious to users, keep those too.) */
1422 if ((b
->type
== bp_catch_exec
) ||
1423 (b
->type
== bp_catch_vfork
) ||
1424 (b
->type
== bp_catch_fork
))
1429 /* bp_finish is a special case. The only way we ought to be able
1430 to see one of these when an exec() has happened, is if the user
1431 caught a vfork, and then said "finish". Ordinarily a finish just
1432 carries them to the call-site of the current callee, by setting
1433 a temporary bp there and resuming. But in this case, the finish
1434 will carry them entirely through the vfork & exec.
1436 We don't want to allow a bp_finish to remain inserted now. But
1437 we can't safely delete it, 'cause finish_command has a handle to
1438 the bp on a bpstat, and will later want to delete it. There's a
1439 chance (and I've seen it happen) that if we delete the bp_finish
1440 here, that its storage will get reused by the time finish_command
1441 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1442 We really must allow finish_command to delete a bp_finish.
1444 In the absense of a general solution for the "how do we know
1445 it's safe to delete something others may have handles to?"
1446 problem, what we'll do here is just uninsert the bp_finish, and
1447 let finish_command delete it.
1449 (We know the bp_finish is "doomed" in the sense that it's
1450 momentary, and will be deleted as soon as finish_command sees
1451 the inferior stopped. So it doesn't matter that the bp's
1452 address is probably bogus in the new a.out, unlike e.g., the
1453 solib breakpoints.) */
1455 if (b
->type
== bp_finish
)
1460 /* Without a symbolic address, we have little hope of the
1461 pre-exec() address meaning the same thing in the post-exec()
1463 if (b
->addr_string
== NULL
)
1465 delete_breakpoint (b
);
1469 /* FIXME what about longjmp breakpoints? Re-create them here? */
1470 create_overlay_event_breakpoint ("_ovly_debug_event");
1474 detach_breakpoints (int pid
)
1476 struct bp_location
*b
;
1478 struct cleanup
*old_chain
= save_inferior_ptid ();
1480 if (pid
== PIDGET (inferior_ptid
))
1481 error (_("Cannot detach breakpoints of inferior_ptid"));
1483 /* Set inferior_ptid; remove_breakpoint uses this global. */
1484 inferior_ptid
= pid_to_ptid (pid
);
1485 ALL_BP_LOCATIONS (b
)
1489 val
= remove_breakpoint (b
, mark_inserted
);
1492 do_cleanups (old_chain
);
1497 do_cleanups (old_chain
);
1502 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1506 if (b
->owner
->enable_state
== bp_permanent
)
1507 /* Permanent breakpoints cannot be inserted or removed. */
1510 if (b
->owner
->type
== bp_none
)
1511 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1514 if (b
->loc_type
== bp_loc_software_breakpoint
1515 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1517 /* "Normal" instruction breakpoint: either the standard
1518 trap-instruction bp (bp_breakpoint), or a
1519 bp_hardware_breakpoint. */
1521 /* First check to see if we have to handle an overlay. */
1522 if (overlay_debugging
== ovly_off
1523 || b
->section
== NULL
1524 || !(section_is_overlay (b
->section
)))
1526 /* No overlay handling: just remove the breakpoint. */
1528 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1529 val
= target_remove_hw_breakpoint (&b
->target_info
);
1531 val
= target_remove_breakpoint (&b
->target_info
);
1535 /* This breakpoint is in an overlay section.
1536 Did we set a breakpoint at the LMA? */
1537 if (!overlay_events_enabled
)
1539 /* Yes -- overlay event support is not active, so we
1540 should have set a breakpoint at the LMA. Remove it.
1542 /* Ignore any failures: if the LMA is in ROM, we will
1543 have already warned when we failed to insert it. */
1544 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1545 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1547 target_remove_breakpoint (&b
->overlay_target_info
);
1549 /* Did we set a breakpoint at the VMA?
1550 If so, we will have marked the breakpoint 'inserted'. */
1553 /* Yes -- remove it. Previously we did not bother to
1554 remove the breakpoint if the section had been
1555 unmapped, but let's not rely on that being safe. We
1556 don't know what the overlay manager might do. */
1557 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1558 val
= target_remove_hw_breakpoint (&b
->target_info
);
1560 /* However, we should remove *software* breakpoints only
1561 if the section is still mapped, or else we overwrite
1562 wrong code with the saved shadow contents. */
1563 else if (section_is_mapped (b
->section
))
1564 val
= target_remove_breakpoint (&b
->target_info
);
1570 /* No -- not inserted, so no need to remove. No error. */
1576 b
->inserted
= (is
== mark_inserted
);
1578 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1583 b
->inserted
= (is
== mark_inserted
);
1584 val
= target_remove_watchpoint (b
->address
, b
->length
,
1585 b
->watchpoint_type
);
1587 /* Failure to remove any of the hardware watchpoints comes here. */
1588 if ((is
== mark_uninserted
) && (b
->inserted
))
1589 warning (_("Could not remove hardware watchpoint %d."),
1592 else if ((b
->owner
->type
== bp_catch_fork
||
1593 b
->owner
->type
== bp_catch_vfork
||
1594 b
->owner
->type
== bp_catch_exec
)
1595 && breakpoint_enabled (b
->owner
)
1599 switch (b
->owner
->type
)
1602 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1604 case bp_catch_vfork
:
1605 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1608 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1611 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1616 b
->inserted
= (is
== mark_inserted
);
1622 /* Clear the "inserted" flag in all breakpoints. */
1625 mark_breakpoints_out (void)
1627 struct bp_location
*bpt
;
1629 ALL_BP_LOCATIONS (bpt
)
1633 /* Clear the "inserted" flag in all breakpoints and delete any
1634 breakpoints which should go away between runs of the program.
1636 Plus other such housekeeping that has to be done for breakpoints
1639 Note: this function gets called at the end of a run (by
1640 generic_mourn_inferior) and when a run begins (by
1641 init_wait_for_inferior). */
1646 breakpoint_init_inferior (enum inf_context context
)
1648 struct breakpoint
*b
, *temp
;
1649 struct bp_location
*bpt
;
1651 ALL_BP_LOCATIONS (bpt
)
1654 ALL_BREAKPOINTS_SAFE (b
, temp
)
1659 case bp_watchpoint_scope
:
1661 /* If the call dummy breakpoint is at the entry point it will
1662 cause problems when the inferior is rerun, so we better
1665 Also get rid of scope breakpoints. */
1666 delete_breakpoint (b
);
1670 case bp_hardware_watchpoint
:
1671 case bp_read_watchpoint
:
1672 case bp_access_watchpoint
:
1674 /* Likewise for watchpoints on local expressions. */
1675 if (b
->exp_valid_block
!= NULL
)
1676 delete_breakpoint (b
);
1677 else if (context
== inf_starting
)
1679 /* Reset val field to force reread of starting value
1680 in insert_breakpoints. */
1682 value_free (b
->val
);
1692 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1693 exists at PC. It returns ordinary_breakpoint_here if it's an
1694 ordinary breakpoint, or permanent_breakpoint_here if it's a
1695 permanent breakpoint.
1696 - When continuing from a location with an ordinary breakpoint, we
1697 actually single step once before calling insert_breakpoints.
1698 - When continuing from a localion with a permanent breakpoint, we
1699 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1700 the target, to advance the PC past the breakpoint. */
1702 enum breakpoint_here
1703 breakpoint_here_p (CORE_ADDR pc
)
1705 const struct bp_location
*bpt
;
1706 int any_breakpoint_here
= 0;
1708 ALL_BP_LOCATIONS (bpt
)
1710 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1711 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1714 if ((breakpoint_enabled (bpt
->owner
)
1715 || bpt
->owner
->enable_state
== bp_permanent
)
1716 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1718 if (overlay_debugging
1719 && section_is_overlay (bpt
->section
)
1720 && !section_is_mapped (bpt
->section
))
1721 continue; /* unmapped overlay -- can't be a match */
1722 else if (bpt
->owner
->enable_state
== bp_permanent
)
1723 return permanent_breakpoint_here
;
1725 any_breakpoint_here
= 1;
1729 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1733 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1734 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1735 This does not check for single-step breakpoints, which are
1736 inserted and removed using direct target manipulation. */
1739 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1741 const struct bp_location
*bpt
;
1743 ALL_BP_LOCATIONS (bpt
)
1745 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1746 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1750 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1752 if (overlay_debugging
1753 && section_is_overlay (bpt
->section
)
1754 && !section_is_mapped (bpt
->section
))
1755 continue; /* unmapped overlay -- can't be a match */
1763 /* Returns non-zero iff there's either regular breakpoint
1764 or a single step breakpoint inserted at PC. */
1767 breakpoint_inserted_here_p (CORE_ADDR pc
)
1769 if (regular_breakpoint_inserted_here_p (pc
))
1772 if (single_step_breakpoint_inserted_here_p (pc
))
1778 /* This function returns non-zero iff there is a software breakpoint
1782 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1784 const struct bp_location
*bpt
;
1785 int any_breakpoint_here
= 0;
1787 ALL_BP_LOCATIONS (bpt
)
1789 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1793 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1795 if (overlay_debugging
1796 && section_is_overlay (bpt
->section
)
1797 && !section_is_mapped (bpt
->section
))
1798 continue; /* unmapped overlay -- can't be a match */
1804 /* Also check for software single-step breakpoints. */
1805 if (single_step_breakpoint_inserted_here_p (pc
))
1811 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1812 PC is valid for process/thread PTID. */
1815 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1817 const struct bp_location
*bpt
;
1820 thread
= pid_to_thread_id (ptid
);
1822 ALL_BP_LOCATIONS (bpt
)
1824 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1825 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1828 if ((breakpoint_enabled (bpt
->owner
)
1829 || bpt
->owner
->enable_state
== bp_permanent
)
1830 && bpt
->address
== pc
1831 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1833 if (overlay_debugging
1834 && section_is_overlay (bpt
->section
)
1835 && !section_is_mapped (bpt
->section
))
1836 continue; /* unmapped overlay -- can't be a match */
1846 /* bpstat stuff. External routines' interfaces are documented
1850 ep_is_catchpoint (struct breakpoint
*ep
)
1853 (ep
->type
== bp_catch_load
)
1854 || (ep
->type
== bp_catch_unload
)
1855 || (ep
->type
== bp_catch_fork
)
1856 || (ep
->type
== bp_catch_vfork
)
1857 || (ep
->type
== bp_catch_exec
);
1859 /* ??rehrauer: Add more kinds here, as are implemented... */
1863 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1866 (ep
->type
== bp_catch_load
)
1867 || (ep
->type
== bp_catch_unload
);
1871 bpstat_free (bpstat bs
)
1873 if (bs
->old_val
!= NULL
)
1874 value_free (bs
->old_val
);
1875 free_command_lines (&bs
->commands
);
1879 /* Clear a bpstat so that it says we are not at any breakpoint.
1880 Also free any storage that is part of a bpstat. */
1883 bpstat_clear (bpstat
*bsp
)
1900 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1901 is part of the bpstat is copied as well. */
1904 bpstat_copy (bpstat bs
)
1908 bpstat retval
= NULL
;
1913 for (; bs
!= NULL
; bs
= bs
->next
)
1915 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1916 memcpy (tmp
, bs
, sizeof (*tmp
));
1917 if (bs
->commands
!= NULL
)
1918 tmp
->commands
= copy_command_lines (bs
->commands
);
1919 if (bs
->old_val
!= NULL
)
1920 tmp
->old_val
= value_copy (bs
->old_val
);
1923 /* This is the first thing in the chain. */
1933 /* Find the bpstat associated with this breakpoint */
1936 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1941 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1943 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
1949 /* Find a step_resume breakpoint associated with this bpstat.
1950 (If there are multiple step_resume bp's on the list, this function
1951 will arbitrarily pick one.)
1953 It is an error to use this function if BPSTAT doesn't contain a
1954 step_resume breakpoint.
1956 See wait_for_inferior's use of this function. */
1958 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1962 gdb_assert (bsp
!= NULL
);
1964 current_thread
= pid_to_thread_id (inferior_ptid
);
1966 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1968 if ((bsp
->breakpoint_at
!= NULL
) &&
1969 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
1970 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
1971 bsp
->breakpoint_at
->owner
->thread
== -1))
1972 return bsp
->breakpoint_at
->owner
;
1975 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
1979 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
1980 at. *BSP upon return is a bpstat which points to the remaining
1981 breakpoints stopped at (but which is not guaranteed to be good for
1982 anything but further calls to bpstat_num).
1983 Return 0 if passed a bpstat which does not indicate any breakpoints.
1984 Return -1 if stopped at a breakpoint that has been deleted since
1986 Return 1 otherwise. */
1989 bpstat_num (bpstat
*bsp
, int *num
)
1991 struct breakpoint
*b
;
1994 return 0; /* No more breakpoint values */
1996 /* We assume we'll never have several bpstats that
1997 correspond to a single breakpoint -- otherwise,
1998 this function might return the same number more
1999 than once and this will look ugly. */
2000 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2001 *bsp
= (*bsp
)->next
;
2003 return -1; /* breakpoint that's been deleted since */
2005 *num
= b
->number
; /* We have its number */
2009 /* Modify BS so that the actions will not be performed. */
2012 bpstat_clear_actions (bpstat bs
)
2014 for (; bs
!= NULL
; bs
= bs
->next
)
2016 free_command_lines (&bs
->commands
);
2017 if (bs
->old_val
!= NULL
)
2019 value_free (bs
->old_val
);
2025 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2027 cleanup_executing_breakpoints (void *ignore
)
2029 executing_breakpoint_commands
= 0;
2032 /* Execute all the commands associated with all the breakpoints at this
2033 location. Any of these commands could cause the process to proceed
2034 beyond this point, etc. We look out for such changes by checking
2035 the global "breakpoint_proceeded" after each command. */
2038 bpstat_do_actions (bpstat
*bsp
)
2041 struct cleanup
*old_chain
;
2043 /* Avoid endless recursion if a `source' command is contained
2045 if (executing_breakpoint_commands
)
2048 executing_breakpoint_commands
= 1;
2049 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2052 /* Note that (as of this writing), our callers all appear to
2053 be passing us the address of global stop_bpstat. And, if
2054 our calls to execute_control_command cause the inferior to
2055 proceed, that global (and hence, *bsp) will change.
2057 We must be careful to not touch *bsp unless the inferior
2058 has not proceeded. */
2060 /* This pointer will iterate over the list of bpstat's. */
2063 breakpoint_proceeded
= 0;
2064 for (; bs
!= NULL
; bs
= bs
->next
)
2066 struct command_line
*cmd
;
2067 struct cleanup
*this_cmd_tree_chain
;
2069 /* Take ownership of the BSP's command tree, if it has one.
2071 The command tree could legitimately contain commands like
2072 'step' and 'next', which call clear_proceed_status, which
2073 frees stop_bpstat's command tree. To make sure this doesn't
2074 free the tree we're executing out from under us, we need to
2075 take ownership of the tree ourselves. Since a given bpstat's
2076 commands are only executed once, we don't need to copy it; we
2077 can clear the pointer in the bpstat, and make sure we free
2078 the tree when we're done. */
2081 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2085 execute_control_command (cmd
);
2087 if (breakpoint_proceeded
)
2093 /* We can free this command tree now. */
2094 do_cleanups (this_cmd_tree_chain
);
2096 if (breakpoint_proceeded
)
2097 /* The inferior is proceeded by the command; bomb out now.
2098 The bpstat chain has been blown away by wait_for_inferior.
2099 But since execution has stopped again, there is a new bpstat
2100 to look at, so start over. */
2103 do_cleanups (old_chain
);
2106 /* This is the normal print function for a bpstat. In the future,
2107 much of this logic could (should?) be moved to bpstat_stop_status,
2108 by having it set different print_it values.
2110 Current scheme: When we stop, bpstat_print() is called. It loops
2111 through the bpstat list of things causing this stop, calling the
2112 print_bp_stop_message function on each one. The behavior of the
2113 print_bp_stop_message function depends on the print_it field of
2114 bpstat. If such field so indicates, call this function here.
2116 Return values from this routine (ultimately used by bpstat_print()
2117 and normal_stop() to decide what to do):
2118 PRINT_NOTHING: Means we already printed all we needed to print,
2119 don't print anything else.
2120 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2121 that something to be followed by a location.
2122 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2123 that something to be followed by a location.
2124 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2127 static enum print_stop_action
2128 print_it_typical (bpstat bs
)
2130 struct cleanup
*old_chain
, *ui_out_chain
;
2131 struct breakpoint
*b
;
2132 const struct bp_location
*bl
;
2133 struct ui_stream
*stb
;
2134 stb
= ui_out_stream_new (uiout
);
2135 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2136 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2137 which has since been deleted. */
2138 if (bs
->breakpoint_at
== NULL
)
2139 return PRINT_UNKNOWN
;
2140 bl
= bs
->breakpoint_at
;
2146 case bp_hardware_breakpoint
:
2147 if (bl
->address
!= bl
->requested_address
)
2148 breakpoint_adjustment_warning (bl
->requested_address
,
2151 annotate_breakpoint (b
->number
);
2152 ui_out_text (uiout
, "\nBreakpoint ");
2153 if (ui_out_is_mi_like_p (uiout
))
2154 ui_out_field_string (uiout
, "reason",
2155 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2156 ui_out_field_int (uiout
, "bkptno", b
->number
);
2157 ui_out_text (uiout
, ", ");
2158 return PRINT_SRC_AND_LOC
;
2161 case bp_shlib_event
:
2162 /* Did we stop because the user set the stop_on_solib_events
2163 variable? (If so, we report this as a generic, "Stopped due
2164 to shlib event" message.) */
2165 printf_filtered (_("Stopped due to shared library event\n"));
2166 return PRINT_NOTHING
;
2169 case bp_thread_event
:
2170 /* Not sure how we will get here.
2171 GDB should not stop for these breakpoints. */
2172 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2173 return PRINT_NOTHING
;
2176 case bp_overlay_event
:
2177 /* By analogy with the thread event, GDB should not stop for these. */
2178 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2179 return PRINT_NOTHING
;
2183 annotate_catchpoint (b
->number
);
2184 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2186 b
->triggered_dll_pathname
);
2187 return PRINT_SRC_AND_LOC
;
2190 case bp_catch_unload
:
2191 annotate_catchpoint (b
->number
);
2192 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2194 b
->triggered_dll_pathname
);
2195 return PRINT_SRC_AND_LOC
;
2199 annotate_catchpoint (b
->number
);
2200 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2202 b
->forked_inferior_pid
);
2203 return PRINT_SRC_AND_LOC
;
2206 case bp_catch_vfork
:
2207 annotate_catchpoint (b
->number
);
2208 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2210 b
->forked_inferior_pid
);
2211 return PRINT_SRC_AND_LOC
;
2215 annotate_catchpoint (b
->number
);
2216 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2219 return PRINT_SRC_AND_LOC
;
2223 case bp_hardware_watchpoint
:
2224 if (bs
->old_val
!= NULL
)
2226 annotate_watchpoint (b
->number
);
2227 if (ui_out_is_mi_like_p (uiout
))
2230 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2232 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2233 ui_out_text (uiout
, "\nOld value = ");
2234 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2235 ui_out_field_stream (uiout
, "old", stb
);
2236 ui_out_text (uiout
, "\nNew value = ");
2237 value_print (b
->val
, stb
->stream
, 0, Val_pretty_default
);
2238 ui_out_field_stream (uiout
, "new", stb
);
2239 do_cleanups (ui_out_chain
);
2240 ui_out_text (uiout
, "\n");
2241 value_free (bs
->old_val
);
2244 /* More than one watchpoint may have been triggered. */
2245 return PRINT_UNKNOWN
;
2248 case bp_read_watchpoint
:
2249 if (ui_out_is_mi_like_p (uiout
))
2252 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2254 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2255 ui_out_text (uiout
, "\nValue = ");
2256 value_print (b
->val
, stb
->stream
, 0, Val_pretty_default
);
2257 ui_out_field_stream (uiout
, "value", stb
);
2258 do_cleanups (ui_out_chain
);
2259 ui_out_text (uiout
, "\n");
2260 return PRINT_UNKNOWN
;
2263 case bp_access_watchpoint
:
2264 if (bs
->old_val
!= NULL
)
2266 annotate_watchpoint (b
->number
);
2267 if (ui_out_is_mi_like_p (uiout
))
2270 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2272 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2273 ui_out_text (uiout
, "\nOld value = ");
2274 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2275 ui_out_field_stream (uiout
, "old", stb
);
2276 value_free (bs
->old_val
);
2278 ui_out_text (uiout
, "\nNew value = ");
2283 if (ui_out_is_mi_like_p (uiout
))
2286 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2287 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2288 ui_out_text (uiout
, "\nValue = ");
2290 value_print (b
->val
, stb
->stream
, 0,Val_pretty_default
);
2291 ui_out_field_stream (uiout
, "new", stb
);
2292 do_cleanups (ui_out_chain
);
2293 ui_out_text (uiout
, "\n");
2294 return PRINT_UNKNOWN
;
2297 /* Fall through, we don't deal with these types of breakpoints
2301 if (ui_out_is_mi_like_p (uiout
))
2304 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2305 return PRINT_UNKNOWN
;
2309 if (ui_out_is_mi_like_p (uiout
))
2312 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2313 return PRINT_UNKNOWN
;
2318 case bp_longjmp_resume
:
2319 case bp_step_resume
:
2320 case bp_watchpoint_scope
:
2323 return PRINT_UNKNOWN
;
2327 /* Generic routine for printing messages indicating why we
2328 stopped. The behavior of this function depends on the value
2329 'print_it' in the bpstat structure. Under some circumstances we
2330 may decide not to print anything here and delegate the task to
2333 static enum print_stop_action
2334 print_bp_stop_message (bpstat bs
)
2336 switch (bs
->print_it
)
2339 /* Nothing should be printed for this bpstat entry. */
2340 return PRINT_UNKNOWN
;
2344 /* We still want to print the frame, but we already printed the
2345 relevant messages. */
2346 return PRINT_SRC_AND_LOC
;
2349 case print_it_normal
:
2351 const struct bp_location
*bl
= bs
->breakpoint_at
;
2352 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2354 /* Normal case. Call the breakpoint's print_it method, or
2355 print_it_typical. */
2356 /* FIXME: how breakpoint can ever be NULL here? */
2357 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2358 return b
->ops
->print_it (b
);
2360 return print_it_typical (bs
);
2365 internal_error (__FILE__
, __LINE__
,
2366 _("print_bp_stop_message: unrecognized enum value"));
2371 /* Print a message indicating what happened. This is called from
2372 normal_stop(). The input to this routine is the head of the bpstat
2373 list - a list of the eventpoints that caused this stop. This
2374 routine calls the generic print routine for printing a message
2375 about reasons for stopping. This will print (for example) the
2376 "Breakpoint n," part of the output. The return value of this
2379 PRINT_UNKNOWN: Means we printed nothing
2380 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2381 code to print the location. An example is
2382 "Breakpoint 1, " which should be followed by
2384 PRINT_SRC_ONLY: Means we printed something, but there is no need
2385 to also print the location part of the message.
2386 An example is the catch/throw messages, which
2387 don't require a location appended to the end.
2388 PRINT_NOTHING: We have done some printing and we don't need any
2389 further info to be printed.*/
2391 enum print_stop_action
2392 bpstat_print (bpstat bs
)
2396 /* Maybe another breakpoint in the chain caused us to stop.
2397 (Currently all watchpoints go on the bpstat whether hit or not.
2398 That probably could (should) be changed, provided care is taken
2399 with respect to bpstat_explains_signal). */
2400 for (; bs
; bs
= bs
->next
)
2402 val
= print_bp_stop_message (bs
);
2403 if (val
== PRINT_SRC_ONLY
2404 || val
== PRINT_SRC_AND_LOC
2405 || val
== PRINT_NOTHING
)
2409 /* We reached the end of the chain, or we got a null BS to start
2410 with and nothing was printed. */
2411 return PRINT_UNKNOWN
;
2414 /* Evaluate the expression EXP and return 1 if value is zero.
2415 This is used inside a catch_errors to evaluate the breakpoint condition.
2416 The argument is a "struct expression *" that has been cast to char * to
2417 make it pass through catch_errors. */
2420 breakpoint_cond_eval (void *exp
)
2422 struct value
*mark
= value_mark ();
2423 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2424 value_free_to_mark (mark
);
2428 /* Allocate a new bpstat and chain it to the current one. */
2431 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2435 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2437 bs
->breakpoint_at
= bl
;
2438 /* If the condition is false, etc., don't do the commands. */
2439 bs
->commands
= NULL
;
2441 bs
->print_it
= print_it_normal
;
2445 /* The target has stopped with waitstatus WS. Check if any hardware
2446 watchpoints have triggered, according to the target. */
2449 watchpoints_triggered (struct target_waitstatus
*ws
)
2451 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2453 struct breakpoint
*b
;
2455 if (!stopped_by_watchpoint
)
2457 /* We were not stopped by a watchpoint. Mark all watchpoints
2458 as not triggered. */
2460 if (b
->type
== bp_hardware_watchpoint
2461 || b
->type
== bp_read_watchpoint
2462 || b
->type
== bp_access_watchpoint
)
2463 b
->watchpoint_triggered
= watch_triggered_no
;
2468 if (!target_stopped_data_address (¤t_target
, &addr
))
2470 /* We were stopped by a watchpoint, but we don't know where.
2471 Mark all watchpoints as unknown. */
2473 if (b
->type
== bp_hardware_watchpoint
2474 || b
->type
== bp_read_watchpoint
2475 || b
->type
== bp_access_watchpoint
)
2476 b
->watchpoint_triggered
= watch_triggered_unknown
;
2478 return stopped_by_watchpoint
;
2481 /* The target could report the data address. Mark watchpoints
2482 affected by this data address as triggered, and all others as not
2486 if (b
->type
== bp_hardware_watchpoint
2487 || b
->type
== bp_read_watchpoint
2488 || b
->type
== bp_access_watchpoint
)
2490 struct bp_location
*loc
;
2493 b
->watchpoint_triggered
= watch_triggered_no
;
2494 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2495 /* Exact match not required. Within range is
2497 if (addr
>= loc
->address
2498 && addr
< loc
->address
+ loc
->length
)
2500 b
->watchpoint_triggered
= watch_triggered_yes
;
2508 /* Possible return values for watchpoint_check (this can't be an enum
2509 because of check_errors). */
2510 /* The watchpoint has been deleted. */
2511 #define WP_DELETED 1
2512 /* The value has changed. */
2513 #define WP_VALUE_CHANGED 2
2514 /* The value has not changed. */
2515 #define WP_VALUE_NOT_CHANGED 3
2517 #define BP_TEMPFLAG 1
2518 #define BP_HARDWAREFLAG 2
2520 /* Check watchpoint condition. */
2523 watchpoint_check (void *p
)
2525 bpstat bs
= (bpstat
) p
;
2526 struct breakpoint
*b
;
2527 struct frame_info
*fr
;
2528 int within_current_scope
;
2530 b
= bs
->breakpoint_at
->owner
;
2532 if (b
->exp_valid_block
== NULL
)
2533 within_current_scope
= 1;
2536 /* There is no current frame at this moment. If we're going to have
2537 any chance of handling watchpoints on local variables, we'll need
2538 the frame chain (so we can determine if we're in scope). */
2539 reinit_frame_cache ();
2540 fr
= frame_find_by_id (b
->watchpoint_frame
);
2541 within_current_scope
= (fr
!= NULL
);
2543 /* If we've gotten confused in the unwinder, we might have
2544 returned a frame that can't describe this variable. */
2545 if (within_current_scope
2546 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2547 within_current_scope
= 0;
2549 /* in_function_epilogue_p() returns a non-zero value if we're still
2550 in the function but the stack frame has already been invalidated.
2551 Since we can't rely on the values of local variables after the
2552 stack has been destroyed, we are treating the watchpoint in that
2553 state as `not changed' without further checking.
2555 vinschen/2003-09-04: The former implementation left out the case
2556 that the watchpoint frame couldn't be found by frame_find_by_id()
2557 because the current PC is currently in an epilogue. Calling
2558 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2559 if ((!within_current_scope
|| fr
== get_current_frame ())
2560 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2561 return WP_VALUE_NOT_CHANGED
;
2562 if (fr
&& within_current_scope
)
2563 /* If we end up stopping, the current frame will get selected
2564 in normal_stop. So this call to select_frame won't affect
2569 if (within_current_scope
)
2571 /* We use value_{,free_to_}mark because it could be a
2572 *long* time before we return to the command level and
2573 call free_all_values. We can't call free_all_values because
2574 we might be in the middle of evaluating a function call. */
2576 struct value
*mark
= value_mark ();
2577 struct value
*new_val
= evaluate_expression (b
->exp
);
2578 if (!value_equal (b
->val
, new_val
))
2580 release_value (new_val
);
2581 value_free_to_mark (mark
);
2582 bs
->old_val
= b
->val
;
2584 /* We will stop here */
2585 return WP_VALUE_CHANGED
;
2589 /* Nothing changed, don't do anything. */
2590 value_free_to_mark (mark
);
2591 /* We won't stop here */
2592 return WP_VALUE_NOT_CHANGED
;
2597 /* This seems like the only logical thing to do because
2598 if we temporarily ignored the watchpoint, then when
2599 we reenter the block in which it is valid it contains
2600 garbage (in the case of a function, it may have two
2601 garbage values, one before and one after the prologue).
2602 So we can't even detect the first assignment to it and
2603 watch after that (since the garbage may or may not equal
2604 the first value assigned). */
2605 /* We print all the stop information in print_it_typical(), but
2606 in this case, by the time we call print_it_typical() this bp
2607 will be deleted already. So we have no choice but print the
2608 information here. */
2609 if (ui_out_is_mi_like_p (uiout
))
2611 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2612 ui_out_text (uiout
, "\nWatchpoint ");
2613 ui_out_field_int (uiout
, "wpnum", b
->number
);
2614 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2615 which its expression is valid.\n");
2617 if (b
->related_breakpoint
)
2618 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2619 b
->disposition
= disp_del_at_next_stop
;
2625 /* Get a bpstat associated with having just stopped at address
2626 BP_ADDR in thread PTID.
2628 Determine whether we stopped at a breakpoint, etc, or whether we
2629 don't understand this stop. Result is a chain of bpstat's such that:
2631 if we don't understand the stop, the result is a null pointer.
2633 if we understand why we stopped, the result is not null.
2635 Each element of the chain refers to a particular breakpoint or
2636 watchpoint at which we have stopped. (We may have stopped for
2637 several reasons concurrently.)
2639 Each element of the chain has valid next, breakpoint_at,
2640 commands, FIXME??? fields. */
2643 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2645 struct breakpoint
*b
= NULL
;
2646 const struct bp_location
*bl
;
2647 /* Root of the chain of bpstat's */
2648 struct bpstats root_bs
[1];
2649 /* Pointer to the last thing in the chain currently. */
2650 bpstat bs
= root_bs
;
2651 int thread_id
= pid_to_thread_id (ptid
);
2653 ALL_BP_LOCATIONS (bl
)
2657 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2660 if (b
->type
!= bp_watchpoint
2661 && b
->type
!= bp_hardware_watchpoint
2662 && b
->type
!= bp_read_watchpoint
2663 && b
->type
!= bp_access_watchpoint
2664 && b
->type
!= bp_hardware_breakpoint
2665 && b
->type
!= bp_catch_fork
2666 && b
->type
!= bp_catch_vfork
2667 && b
->type
!= bp_catch_exec
) /* a non-watchpoint bp */
2669 if (bl
->address
!= bp_addr
) /* address doesn't match */
2671 if (overlay_debugging
/* unmapped overlay section */
2672 && section_is_overlay (bl
->section
)
2673 && !section_is_mapped (bl
->section
))
2677 /* Continuable hardware watchpoints are treated as non-existent if the
2678 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2679 some data address). Otherwise gdb won't stop on a break instruction
2680 in the code (not from a breakpoint) when a hardware watchpoint has
2681 been defined. Also skip watchpoints which we know did not trigger
2682 (did not match the data address). */
2684 if ((b
->type
== bp_hardware_watchpoint
2685 || b
->type
== bp_read_watchpoint
2686 || b
->type
== bp_access_watchpoint
)
2687 && b
->watchpoint_triggered
== watch_triggered_no
)
2690 if (b
->type
== bp_hardware_breakpoint
)
2692 if (bl
->address
!= bp_addr
)
2694 if (overlay_debugging
/* unmapped overlay section */
2695 && section_is_overlay (bl
->section
)
2696 && !section_is_mapped (bl
->section
))
2700 /* Is this a catchpoint of a load or unload? If so, did we
2701 get a load or unload of the specified library? If not,
2703 if ((b
->type
== bp_catch_load
)
2704 #if defined(SOLIB_HAVE_LOAD_EVENT)
2705 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2706 || ((b
->dll_pathname
!= NULL
)
2707 && (strcmp (b
->dll_pathname
,
2708 SOLIB_LOADED_LIBRARY_PATHNAME (
2709 PIDGET (inferior_ptid
)))
2715 if ((b
->type
== bp_catch_unload
)
2716 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2717 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2718 || ((b
->dll_pathname
!= NULL
)
2719 && (strcmp (b
->dll_pathname
,
2720 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2721 PIDGET (inferior_ptid
)))
2727 if ((b
->type
== bp_catch_fork
)
2728 && !inferior_has_forked (PIDGET (inferior_ptid
),
2729 &b
->forked_inferior_pid
))
2732 if ((b
->type
== bp_catch_vfork
)
2733 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2734 &b
->forked_inferior_pid
))
2737 if ((b
->type
== bp_catch_exec
)
2738 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2741 /* For hardware watchpoints, we look only at the first location.
2742 The watchpoint_check function will work on entire expression,
2743 not the individual locations. For read watchopints, the
2744 watchpoints_triggered function have checked all locations
2747 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
2750 /* Come here if it's a watchpoint, or if the break address matches */
2752 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
2754 /* Watchpoints may change this, if not found to have triggered. */
2758 if (b
->type
== bp_watchpoint
2759 || b
->type
== bp_read_watchpoint
2760 || b
->type
== bp_access_watchpoint
2761 || b
->type
== bp_hardware_watchpoint
)
2765 int must_check_value
= 0;
2767 if (b
->type
== bp_watchpoint
)
2768 /* For a software watchpoint, we must always check the
2770 must_check_value
= 1;
2771 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2772 /* We have a hardware watchpoint (read, write, or access)
2773 and the target earlier reported an address watched by
2775 must_check_value
= 1;
2776 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2777 && b
->type
== bp_hardware_watchpoint
)
2778 /* We were stopped by a hardware watchpoint, but the target could
2779 not report the data address. We must check the watchpoint's
2780 value. Access and read watchpoints are out of luck; without
2781 a data address, we can't figure it out. */
2782 must_check_value
= 1;
2784 if (must_check_value
)
2786 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2788 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2789 int e
= catch_errors (watchpoint_check
, bs
, message
,
2791 do_cleanups (cleanups
);
2795 /* We've already printed what needs to be printed. */
2796 bs
->print_it
= print_it_done
;
2799 case WP_VALUE_CHANGED
:
2800 if (b
->type
== bp_read_watchpoint
)
2802 /* Don't stop: read watchpoints shouldn't fire if
2803 the value has changed. This is for targets
2804 which cannot set read-only watchpoints. */
2805 bs
->print_it
= print_it_noop
;
2811 case WP_VALUE_NOT_CHANGED
:
2812 if (b
->type
== bp_hardware_watchpoint
2813 || b
->type
== bp_watchpoint
)
2815 /* Don't stop: write watchpoints shouldn't fire if
2816 the value hasn't changed. */
2817 bs
->print_it
= print_it_noop
;
2827 /* Error from catch_errors. */
2828 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2829 if (b
->related_breakpoint
)
2830 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2831 b
->disposition
= disp_del_at_next_stop
;
2832 /* We've already printed what needs to be printed. */
2833 bs
->print_it
= print_it_done
;
2837 else /* must_check_value == 0 */
2839 /* This is a case where some watchpoint(s) triggered, but
2840 not at the address of this watchpoint, or else no
2841 watchpoint triggered after all. So don't print
2842 anything for this watchpoint. */
2843 bs
->print_it
= print_it_noop
;
2850 /* By definition, an encountered breakpoint is a triggered
2855 if (frame_id_p (b
->frame_id
)
2856 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2860 int value_is_zero
= 0;
2862 /* If this is a scope breakpoint, mark the associated
2863 watchpoint as triggered so that we will handle the
2864 out-of-scope event. We'll get to the watchpoint next
2866 if (b
->type
== bp_watchpoint_scope
)
2867 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2869 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2871 /* Need to select the frame, with all that implies
2872 so that the conditions will have the right context. */
2873 select_frame (get_current_frame ());
2875 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2876 "Error in testing breakpoint condition:\n",
2878 /* FIXME-someday, should give breakpoint # */
2881 if (bl
->cond
&& value_is_zero
)
2884 /* Don't consider this a hit. */
2887 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2890 /* Don't consider this a hit. */
2893 else if (b
->ignore_count
> 0)
2896 annotate_ignore_count_change ();
2899 else if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
2900 /* We do not stop for these. */
2904 /* We will stop here */
2905 if (b
->disposition
== disp_disable
)
2906 b
->enable_state
= bp_disabled
;
2909 bs
->commands
= b
->commands
;
2911 (strcmp ("silent", bs
->commands
->line
) == 0
2912 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
2914 bs
->commands
= bs
->commands
->next
;
2917 bs
->commands
= copy_command_lines (bs
->commands
);
2920 /* Print nothing for this entry if we dont stop or if we dont print. */
2921 if (bs
->stop
== 0 || bs
->print
== 0)
2922 bs
->print_it
= print_it_noop
;
2925 bs
->next
= NULL
; /* Terminate the chain */
2926 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2928 /* If we aren't stopping, the value of some hardware watchpoint may
2929 not have changed, but the intermediate memory locations we are
2930 watching may have. Don't bother if we're stopping; this will get
2932 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
2937 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
2939 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
2940 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
2941 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
2943 /* remove/insert can invalidate bs->breakpoint_at, if this
2944 location is no longer used by the watchpoint. Prevent
2945 further code from trying to use it. */
2946 bs
->breakpoint_at
= NULL
;
2947 remove_breakpoints ();
2948 insert_breakpoints ();
2952 return root_bs
->next
;
2955 /* Tell what to do about this bpstat. */
2957 bpstat_what (bpstat bs
)
2959 /* Classify each bpstat as one of the following. */
2962 /* This bpstat element has no effect on the main_action. */
2965 /* There was a watchpoint, stop but don't print. */
2968 /* There was a watchpoint, stop and print. */
2971 /* There was a breakpoint but we're not stopping. */
2974 /* There was a breakpoint, stop but don't print. */
2977 /* There was a breakpoint, stop and print. */
2980 /* We hit the longjmp breakpoint. */
2983 /* We hit the longjmp_resume breakpoint. */
2986 /* We hit the step_resume breakpoint. */
2989 /* We hit the shared library event breakpoint. */
2992 /* We caught a shared library event. */
2995 /* This is just used to count how many enums there are. */
2999 /* Here is the table which drives this routine. So that we can
3000 format it pretty, we define some abbreviations for the
3001 enum bpstat_what codes. */
3002 #define kc BPSTAT_WHAT_KEEP_CHECKING
3003 #define ss BPSTAT_WHAT_STOP_SILENT
3004 #define sn BPSTAT_WHAT_STOP_NOISY
3005 #define sgl BPSTAT_WHAT_SINGLE
3006 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3007 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3008 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
3009 #define sr BPSTAT_WHAT_STEP_RESUME
3010 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3011 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3013 /* "Can't happen." Might want to print an error message.
3014 abort() is not out of the question, but chances are GDB is just
3015 a bit confused, not unusable. */
3016 #define err BPSTAT_WHAT_STOP_NOISY
3018 /* Given an old action and a class, come up with a new action. */
3019 /* One interesting property of this table is that wp_silent is the same
3020 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3021 after stopping, the check for whether to step over a breakpoint
3022 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3023 reference to how we stopped. We retain separate wp_silent and
3024 bp_silent codes in case we want to change that someday.
3026 Another possibly interesting property of this table is that
3027 there's a partial ordering, priority-like, of the actions. Once
3028 you've decided that some action is appropriate, you'll never go
3029 back and decide something of a lower priority is better. The
3032 kc < clr sgl shl shlr slr sn sr ss
3033 sgl < clrs shl shlr slr sn sr ss
3034 slr < err shl shlr sn sr ss
3035 clr < clrs err shl shlr sn sr ss
3036 clrs < err shl shlr sn sr ss
3043 What I think this means is that we don't need a damned table
3044 here. If you just put the rows and columns in the right order,
3045 it'd look awfully regular. We could simply walk the bpstat list
3046 and choose the highest priority action we find, with a little
3047 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3048 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3049 is messy anyway). */
3051 /* step_resume entries: a step resume breakpoint overrides another
3052 breakpoint of signal handling (see comment in wait_for_inferior
3053 at where we set the step_resume breakpoint). */
3055 static const enum bpstat_what_main_action
3056 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3059 /* kc ss sn sgl slr clr clrs sr shl shlr
3062 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, shl
, shlr
},
3064 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3066 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3068 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, shl
, shlr
},
3070 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3072 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3074 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, shl
, shlr
},
3076 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, shl
, shlr
},
3078 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3080 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3082 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3097 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3098 struct bpstat_what retval
;
3100 retval
.call_dummy
= 0;
3101 for (; bs
!= NULL
; bs
= bs
->next
)
3103 enum class bs_class
= no_effect
;
3104 if (bs
->breakpoint_at
== NULL
)
3105 /* I suspect this can happen if it was a momentary breakpoint
3106 which has since been deleted. */
3108 switch (bs
->breakpoint_at
->owner
->type
)
3114 case bp_hardware_breakpoint
:
3120 bs_class
= bp_noisy
;
3122 bs_class
= bp_silent
;
3125 bs_class
= bp_nostop
;
3128 case bp_hardware_watchpoint
:
3129 case bp_read_watchpoint
:
3130 case bp_access_watchpoint
:
3134 bs_class
= wp_noisy
;
3136 bs_class
= wp_silent
;
3139 /* There was a watchpoint, but we're not stopping.
3140 This requires no further action. */
3141 bs_class
= no_effect
;
3144 bs_class
= long_jump
;
3146 case bp_longjmp_resume
:
3147 bs_class
= long_resume
;
3149 case bp_step_resume
:
3152 bs_class
= step_resume
;
3155 /* It is for the wrong frame. */
3156 bs_class
= bp_nostop
;
3158 case bp_watchpoint_scope
:
3159 bs_class
= bp_nostop
;
3161 case bp_shlib_event
:
3162 bs_class
= shlib_event
;
3164 case bp_thread_event
:
3165 case bp_overlay_event
:
3166 bs_class
= bp_nostop
;
3169 case bp_catch_unload
:
3170 /* Only if this catchpoint triggered should we cause the
3171 step-out-of-dld behaviour. Otherwise, we ignore this
3174 bs_class
= catch_shlib_event
;
3176 bs_class
= no_effect
;
3179 case bp_catch_vfork
:
3184 bs_class
= bp_noisy
;
3186 bs_class
= bp_silent
;
3189 /* There was a catchpoint, but we're not stopping.
3190 This requires no further action. */
3191 bs_class
= no_effect
;
3194 /* Make sure the action is stop (silent or noisy),
3195 so infrun.c pops the dummy frame. */
3196 bs_class
= bp_silent
;
3197 retval
.call_dummy
= 1;
3200 current_action
= table
[(int) bs_class
][(int) current_action
];
3202 retval
.main_action
= current_action
;
3206 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3207 without hardware support). This isn't related to a specific bpstat,
3208 just to things like whether watchpoints are set. */
3211 bpstat_should_step (void)
3213 struct breakpoint
*b
;
3215 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3222 /* Given a bpstat that records zero or more triggered eventpoints, this
3223 function returns another bpstat which contains only the catchpoints
3224 on that first list, if any. */
3226 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3228 struct bpstats root_bs
[1];
3229 bpstat bs
= root_bs
;
3230 struct breakpoint
*ep
;
3233 bpstat_clear (cp_list
);
3234 root_bs
->next
= NULL
;
3236 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3238 /* Is this eventpoint a catchpoint? If not, ignore it. */
3239 ep
= ep_list
->breakpoint_at
->owner
;
3242 if ((ep
->type
!= bp_catch_load
) &&
3243 (ep
->type
!= bp_catch_unload
))
3244 /* pai: (temp) ADD fork/vfork here!! */
3247 /* Yes; add it to the list. */
3248 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3253 #if defined(SOLIB_ADD)
3254 /* Also, for each triggered catchpoint, tag it with the name of
3255 the library that caused this trigger. (We copy the name now,
3256 because it's only guaranteed to be available NOW, when the
3257 catchpoint triggers. Clients who may wish to know the name
3258 later must get it from the catchpoint itself.) */
3259 if (ep
->triggered_dll_pathname
!= NULL
)
3260 xfree (ep
->triggered_dll_pathname
);
3261 if (ep
->type
== bp_catch_load
)
3262 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3263 PIDGET (inferior_ptid
));
3265 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3266 PIDGET (inferior_ptid
));
3268 dll_pathname
= NULL
;
3272 ep
->triggered_dll_pathname
= (char *)
3273 xmalloc (strlen (dll_pathname
) + 1);
3274 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3277 ep
->triggered_dll_pathname
= NULL
;
3283 static void print_breakpoint_location (struct breakpoint
*b
,
3284 struct bp_location
*loc
,
3286 struct ui_stream
*stb
)
3291 = find_pc_sect_function (loc
->address
, loc
->section
);
3294 ui_out_text (uiout
, "in ");
3295 ui_out_field_string (uiout
, "func",
3296 SYMBOL_PRINT_NAME (sym
));
3297 ui_out_wrap_hint (uiout
, wrap_indent
);
3298 ui_out_text (uiout
, " at ");
3300 ui_out_field_string (uiout
, "file", b
->source_file
);
3301 ui_out_text (uiout
, ":");
3303 if (ui_out_is_mi_like_p (uiout
))
3305 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3306 char *fullname
= symtab_to_fullname (sal
.symtab
);
3309 ui_out_field_string (uiout
, "fullname", fullname
);
3312 ui_out_field_int (uiout
, "line", b
->line_number
);
3316 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3320 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3321 ui_out_field_stream (uiout
, "at", stb
);
3325 /* Print B to gdb_stdout. */
3327 print_one_breakpoint_location (struct breakpoint
*b
,
3328 struct bp_location
*loc
,
3330 CORE_ADDR
*last_addr
)
3332 struct command_line
*l
;
3334 struct ep_type_description
3339 static struct ep_type_description bptypes
[] =
3341 {bp_none
, "?deleted?"},
3342 {bp_breakpoint
, "breakpoint"},
3343 {bp_hardware_breakpoint
, "hw breakpoint"},
3344 {bp_until
, "until"},
3345 {bp_finish
, "finish"},
3346 {bp_watchpoint
, "watchpoint"},
3347 {bp_hardware_watchpoint
, "hw watchpoint"},
3348 {bp_read_watchpoint
, "read watchpoint"},
3349 {bp_access_watchpoint
, "acc watchpoint"},
3350 {bp_longjmp
, "longjmp"},
3351 {bp_longjmp_resume
, "longjmp resume"},
3352 {bp_step_resume
, "step resume"},
3353 {bp_watchpoint_scope
, "watchpoint scope"},
3354 {bp_call_dummy
, "call dummy"},
3355 {bp_shlib_event
, "shlib events"},
3356 {bp_thread_event
, "thread events"},
3357 {bp_overlay_event
, "overlay events"},
3358 {bp_catch_load
, "catch load"},
3359 {bp_catch_unload
, "catch unload"},
3360 {bp_catch_fork
, "catch fork"},
3361 {bp_catch_vfork
, "catch vfork"},
3362 {bp_catch_exec
, "catch exec"}
3365 static char *bpdisps
[] =
3366 {"del", "dstp", "dis", "keep"};
3367 static char bpenables
[] = "nynny";
3368 char wrap_indent
[80];
3369 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3370 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3371 struct cleanup
*bkpt_chain
;
3373 int header_of_multiple
= 0;
3374 int part_of_multiple
= (loc
!= NULL
);
3376 gdb_assert (!loc
|| loc_number
!= 0);
3377 /* See comment in print_one_breakpoint concerning
3378 treatment of breakpoints with single disabled
3382 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3383 header_of_multiple
= 1;
3388 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3392 if (part_of_multiple
)
3395 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3396 ui_out_field_string (uiout
, "number", formatted
);
3401 ui_out_field_int (uiout
, "number", b
->number
);
3406 if (part_of_multiple
)
3407 ui_out_field_skip (uiout
, "type");
3410 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3411 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3412 internal_error (__FILE__
, __LINE__
,
3413 _("bptypes table does not describe type #%d."),
3415 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3420 if (part_of_multiple
)
3421 ui_out_field_skip (uiout
, "disp");
3423 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3428 if (part_of_multiple
)
3429 ui_out_field_string (uiout
, "enabled",
3431 ? (loc
->enabled
? "y(p)" : "n(p)")
3432 : (loc
->enabled
? "y" : "n"));
3435 int pending
= (b
->loc
== NULL
|| b
->loc
->shlib_disabled
);
3436 /* For header of multiple, there's no point showing pending
3437 state -- it will be apparent from the locations. */
3438 if (header_of_multiple
)
3440 ui_out_field_fmt (uiout
, "enabled", "%c%s",
3441 bpenables
[(int) b
->enable_state
],
3442 pending
? "(p)" : "");
3444 ui_out_spaces (uiout
, 3);
3449 strcpy (wrap_indent
, " ");
3452 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3453 strcat (wrap_indent
, " ");
3455 strcat (wrap_indent
, " ");
3458 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3460 /* Although the print_one can possibly print
3461 all locations, calling it here is not likely
3462 to get any nice result. So, make sure there's
3463 just one location. */
3464 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3465 b
->ops
->print_one (b
, last_addr
);
3471 internal_error (__FILE__
, __LINE__
,
3472 _("print_one_breakpoint: bp_none encountered\n"));
3476 case bp_hardware_watchpoint
:
3477 case bp_read_watchpoint
:
3478 case bp_access_watchpoint
:
3479 /* Field 4, the address, is omitted (which makes the columns
3480 not line up too nicely with the headers, but the effect
3481 is relatively readable). */
3483 ui_out_field_skip (uiout
, "addr");
3485 print_expression (b
->exp
, stb
->stream
);
3486 ui_out_field_stream (uiout
, "what", stb
);
3490 case bp_catch_unload
:
3491 /* Field 4, the address, is omitted (which makes the columns
3492 not line up too nicely with the headers, but the effect
3493 is relatively readable). */
3495 ui_out_field_skip (uiout
, "addr");
3497 if (b
->dll_pathname
== NULL
)
3499 ui_out_field_string (uiout
, "what", "<any library>");
3500 ui_out_spaces (uiout
, 1);
3504 ui_out_text (uiout
, "library \"");
3505 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3506 ui_out_text (uiout
, "\" ");
3511 case bp_catch_vfork
:
3512 /* Field 4, the address, is omitted (which makes the columns
3513 not line up too nicely with the headers, but the effect
3514 is relatively readable). */
3516 ui_out_field_skip (uiout
, "addr");
3518 if (b
->forked_inferior_pid
!= 0)
3520 ui_out_text (uiout
, "process ");
3521 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3522 ui_out_spaces (uiout
, 1);
3527 /* Field 4, the address, is omitted (which makes the columns
3528 not line up too nicely with the headers, but the effect
3529 is relatively readable). */
3531 ui_out_field_skip (uiout
, "addr");
3533 if (b
->exec_pathname
!= NULL
)
3535 ui_out_text (uiout
, "program \"");
3536 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3537 ui_out_text (uiout
, "\" ");
3542 case bp_hardware_breakpoint
:
3546 case bp_longjmp_resume
:
3547 case bp_step_resume
:
3548 case bp_watchpoint_scope
:
3550 case bp_shlib_event
:
3551 case bp_thread_event
:
3552 case bp_overlay_event
:
3557 ui_out_field_string (uiout
, "addr", "<PENDING>");
3558 else if (header_of_multiple
)
3559 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3561 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3564 if (!header_of_multiple
)
3565 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3567 *last_addr
= b
->loc
->address
;
3571 if (!part_of_multiple
&& b
->thread
!= -1)
3573 /* FIXME: This seems to be redundant and lost here; see the
3574 "stop only in" line a little further down. */
3575 ui_out_text (uiout
, " thread ");
3576 ui_out_field_int (uiout
, "thread", b
->thread
);
3579 ui_out_text (uiout
, "\n");
3581 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3584 ui_out_text (uiout
, "\tstop only in stack frame at ");
3585 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3587 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3588 ui_out_text (uiout
, "\n");
3591 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3593 /* We do not print the condition for Ada exception catchpoints
3594 because the condition is an internal implementation detail
3595 that we do not want to expose to the user. */
3597 ui_out_text (uiout
, "\tstop only if ");
3598 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3599 ui_out_text (uiout
, "\n");
3602 if (!part_of_multiple
&& b
->thread
!= -1)
3604 /* FIXME should make an annotation for this */
3605 ui_out_text (uiout
, "\tstop only in thread ");
3606 ui_out_field_int (uiout
, "thread", b
->thread
);
3607 ui_out_text (uiout
, "\n");
3610 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3612 /* FIXME should make an annotation for this */
3613 if (ep_is_catchpoint (b
))
3614 ui_out_text (uiout
, "\tcatchpoint");
3616 ui_out_text (uiout
, "\tbreakpoint");
3617 ui_out_text (uiout
, " already hit ");
3618 ui_out_field_int (uiout
, "times", b
->hit_count
);
3619 if (b
->hit_count
== 1)
3620 ui_out_text (uiout
, " time\n");
3622 ui_out_text (uiout
, " times\n");
3625 /* Output the count also if it is zero, but only if this is
3626 mi. FIXME: Should have a better test for this. */
3627 if (ui_out_is_mi_like_p (uiout
))
3628 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3629 ui_out_field_int (uiout
, "times", b
->hit_count
);
3631 if (!part_of_multiple
&& b
->ignore_count
)
3634 ui_out_text (uiout
, "\tignore next ");
3635 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3636 ui_out_text (uiout
, " hits\n");
3639 if (!part_of_multiple
&& (l
= b
->commands
))
3641 struct cleanup
*script_chain
;
3644 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3645 print_command_lines (uiout
, l
, 4);
3646 do_cleanups (script_chain
);
3648 do_cleanups (bkpt_chain
);
3649 do_cleanups (old_chain
);
3653 print_one_breakpoint (struct breakpoint
*b
,
3654 CORE_ADDR
*last_addr
)
3656 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3658 /* If this breakpoint has custom print function,
3659 it's already printed. Otherwise, print individual
3660 locations, if any. */
3661 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3663 /* If breakpoint has a single location that is
3664 disabled, we print it as if it had
3665 several locations, since otherwise it's hard to
3666 represent "breakpoint enabled, location disabled"
3668 Note that while hardware watchpoints have
3669 several locations internally, that's no a property
3672 && !is_hardware_watchpoint (b
)
3673 && (b
->loc
->next
|| !b
->loc
->enabled
)
3674 && !ui_out_is_mi_like_p (uiout
))
3676 struct bp_location
*loc
;
3678 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3679 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3685 struct captured_breakpoint_query_args
3691 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3693 struct captured_breakpoint_query_args
*args
= data
;
3694 struct breakpoint
*b
;
3695 CORE_ADDR dummy_addr
= 0;
3698 if (args
->bnum
== b
->number
)
3700 print_one_breakpoint (b
, &dummy_addr
);
3708 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3710 struct captured_breakpoint_query_args args
;
3712 /* For the moment we don't trust print_one_breakpoint() to not throw
3714 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3715 error_message
, RETURN_MASK_ALL
) < 0)
3721 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3722 catchpoints, et.al.). */
3725 user_settable_breakpoint (const struct breakpoint
*b
)
3727 return (b
->type
== bp_breakpoint
3728 || b
->type
== bp_catch_load
3729 || b
->type
== bp_catch_unload
3730 || b
->type
== bp_catch_fork
3731 || b
->type
== bp_catch_vfork
3732 || b
->type
== bp_catch_exec
3733 || b
->type
== bp_hardware_breakpoint
3734 || b
->type
== bp_watchpoint
3735 || b
->type
== bp_read_watchpoint
3736 || b
->type
== bp_access_watchpoint
3737 || b
->type
== bp_hardware_watchpoint
);
3740 /* Print information on user settable breakpoint (watchpoint, etc)
3741 number BNUM. If BNUM is -1 print all user settable breakpoints.
3742 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3745 breakpoint_1 (int bnum
, int allflag
)
3747 struct breakpoint
*b
;
3748 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3749 int nr_printable_breakpoints
;
3750 struct cleanup
*bkpttbl_chain
;
3752 /* Compute the number of rows in the table. */
3753 nr_printable_breakpoints
= 0;
3756 || bnum
== b
->number
)
3758 if (allflag
|| user_settable_breakpoint (b
))
3759 nr_printable_breakpoints
++;
3764 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3768 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3771 if (nr_printable_breakpoints
> 0)
3772 annotate_breakpoints_headers ();
3773 if (nr_printable_breakpoints
> 0)
3775 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3776 if (nr_printable_breakpoints
> 0)
3778 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3779 if (nr_printable_breakpoints
> 0)
3781 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3782 if (nr_printable_breakpoints
> 0)
3784 ui_out_table_header (uiout
, 4, ui_left
, "enabled", "Enb"); /* 4 */
3787 if (nr_printable_breakpoints
> 0)
3789 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3790 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3792 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3794 if (nr_printable_breakpoints
> 0)
3796 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3797 ui_out_table_body (uiout
);
3798 if (nr_printable_breakpoints
> 0)
3799 annotate_breakpoints_table ();
3803 || bnum
== b
->number
)
3805 /* We only print out user settable breakpoints unless the
3807 if (allflag
|| user_settable_breakpoint (b
))
3808 print_one_breakpoint (b
, &last_addr
);
3811 do_cleanups (bkpttbl_chain
);
3813 if (nr_printable_breakpoints
== 0)
3816 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3818 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3823 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3824 that a comparison of an unsigned with -1 is always false. */
3825 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3826 set_next_address (last_addr
);
3829 /* FIXME? Should this be moved up so that it is only called when
3830 there have been breakpoints? */
3831 annotate_breakpoints_table_end ();
3835 breakpoints_info (char *bnum_exp
, int from_tty
)
3840 bnum
= parse_and_eval_long (bnum_exp
);
3842 breakpoint_1 (bnum
, 0);
3846 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3851 bnum
= parse_and_eval_long (bnum_exp
);
3853 breakpoint_1 (bnum
, 1);
3857 breakpoint_has_pc (struct breakpoint
*b
, CORE_ADDR pc
, asection
*section
)
3859 struct bp_location
*bl
= b
->loc
;
3860 for (; bl
; bl
= bl
->next
)
3862 if (bl
->address
== pc
3863 && (!overlay_debugging
|| bl
->section
== section
))
3869 /* Print a message describing any breakpoints set at PC. */
3872 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
3875 struct breakpoint
*b
;
3878 others
+= breakpoint_has_pc (b
, pc
, section
);
3882 printf_filtered (_("Note: breakpoint "));
3883 else /* if (others == ???) */
3884 printf_filtered (_("Note: breakpoints "));
3886 if (breakpoint_has_pc (b
, pc
, section
))
3889 printf_filtered ("%d", b
->number
);
3890 if (b
->thread
== -1 && thread
!= -1)
3891 printf_filtered (" (all threads)");
3892 else if (b
->thread
!= -1)
3893 printf_filtered (" (thread %d)", b
->thread
);
3894 printf_filtered ("%s%s ",
3895 ((b
->enable_state
== bp_disabled
||
3896 b
->enable_state
== bp_call_disabled
)
3898 : b
->enable_state
== bp_permanent
3902 : ((others
== 1) ? " and" : ""));
3904 printf_filtered (_("also set at pc "));
3905 fputs_filtered (paddress (pc
), gdb_stdout
);
3906 printf_filtered (".\n");
3910 /* Set the default place to put a breakpoint
3911 for the `break' command with no arguments. */
3914 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3917 default_breakpoint_valid
= valid
;
3918 default_breakpoint_address
= addr
;
3919 default_breakpoint_symtab
= symtab
;
3920 default_breakpoint_line
= line
;
3923 /* Return true iff it is meaningful to use the address member of
3924 BPT. For some breakpoint types, the address member is irrelevant
3925 and it makes no sense to attempt to compare it to other addresses
3926 (or use it for any other purpose either).
3928 More specifically, each of the following breakpoint types will always
3929 have a zero valued address and we don't want check_duplicates() to mark
3930 breakpoints of any of these types to be a duplicate of an actual
3931 breakpoint at address zero:
3934 bp_hardware_watchpoint
3936 bp_access_watchpoint
3943 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3945 enum bptype type
= bpt
->type
;
3947 return (type
!= bp_watchpoint
3948 && type
!= bp_hardware_watchpoint
3949 && type
!= bp_read_watchpoint
3950 && type
!= bp_access_watchpoint
3951 && type
!= bp_catch_exec
3952 && type
!= bp_longjmp_resume
3953 && type
!= bp_catch_fork
3954 && type
!= bp_catch_vfork
);
3957 /* Rescan breakpoints at the same address and section as BPT,
3958 marking the first one as "first" and any others as "duplicates".
3959 This is so that the bpt instruction is only inserted once.
3960 If we have a permanent breakpoint at the same place as BPT, make
3961 that one the official one, and the rest as duplicates. */
3964 check_duplicates_for (CORE_ADDR address
, asection
*section
)
3966 struct bp_location
*b
;
3968 struct bp_location
*perm_bp
= 0;
3970 ALL_BP_LOCATIONS (b
)
3971 if (b
->owner
->enable_state
!= bp_disabled
3972 && b
->owner
->enable_state
!= bp_call_disabled
3974 && !b
->shlib_disabled
3975 && b
->address
== address
/* address / overlay match */
3976 && (!overlay_debugging
|| b
->section
== section
)
3977 && breakpoint_address_is_meaningful (b
->owner
))
3979 /* Have we found a permanent breakpoint? */
3980 if (b
->owner
->enable_state
== bp_permanent
)
3987 b
->duplicate
= count
> 1;
3990 /* If we found a permanent breakpoint at this address, go over the
3991 list again and declare all the other breakpoints there to be the
3995 perm_bp
->duplicate
= 0;
3997 /* Permanent breakpoint should always be inserted. */
3998 if (! perm_bp
->inserted
)
3999 internal_error (__FILE__
, __LINE__
,
4000 _("allegedly permanent breakpoint is not "
4001 "actually inserted"));
4003 ALL_BP_LOCATIONS (b
)
4006 if (b
->owner
->enable_state
!= bp_disabled
4007 && b
->owner
->enable_state
!= bp_call_disabled
4008 && b
->enabled
&& !b
->shlib_disabled
4009 && b
->address
== address
/* address / overlay match */
4010 && (!overlay_debugging
|| b
->section
== section
)
4011 && breakpoint_address_is_meaningful (b
->owner
))
4014 internal_error (__FILE__
, __LINE__
,
4015 _("another breakpoint was inserted on top of "
4016 "a permanent breakpoint"));
4025 check_duplicates (struct breakpoint
*bpt
)
4027 struct bp_location
*bl
= bpt
->loc
;
4029 if (! breakpoint_address_is_meaningful (bpt
))
4032 for (; bl
; bl
= bl
->next
)
4033 check_duplicates_for (bl
->address
, bl
->section
);
4037 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4038 int bnum
, int have_bnum
)
4043 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4044 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4046 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4047 bnum
, astr1
, astr2
);
4049 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4052 /* Adjust a breakpoint's address to account for architectural constraints
4053 on breakpoint placement. Return the adjusted address. Note: Very
4054 few targets require this kind of adjustment. For most targets,
4055 this function is simply the identity function. */
4058 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4060 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4062 /* Very few targets need any kind of breakpoint adjustment. */
4065 else if (bptype
== bp_watchpoint
4066 || bptype
== bp_hardware_watchpoint
4067 || bptype
== bp_read_watchpoint
4068 || bptype
== bp_access_watchpoint
4069 || bptype
== bp_catch_fork
4070 || bptype
== bp_catch_vfork
4071 || bptype
== bp_catch_exec
)
4073 /* Watchpoints and the various bp_catch_* eventpoints should not
4074 have their addresses modified. */
4079 CORE_ADDR adjusted_bpaddr
;
4081 /* Some targets have architectural constraints on the placement
4082 of breakpoint instructions. Obtain the adjusted address. */
4083 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4086 /* An adjusted breakpoint address can significantly alter
4087 a user's expectations. Print a warning if an adjustment
4089 if (adjusted_bpaddr
!= bpaddr
)
4090 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4092 return adjusted_bpaddr
;
4096 /* Allocate a struct bp_location. */
4098 static struct bp_location
*
4099 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4101 struct bp_location
*loc
, *loc_p
;
4103 loc
= xmalloc (sizeof (struct bp_location
));
4104 memset (loc
, 0, sizeof (*loc
));
4108 loc
->shlib_disabled
= 0;
4117 case bp_longjmp_resume
:
4118 case bp_step_resume
:
4119 case bp_watchpoint_scope
:
4121 case bp_shlib_event
:
4122 case bp_thread_event
:
4123 case bp_overlay_event
:
4125 case bp_catch_unload
:
4126 loc
->loc_type
= bp_loc_software_breakpoint
;
4128 case bp_hardware_breakpoint
:
4129 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4131 case bp_hardware_watchpoint
:
4132 case bp_read_watchpoint
:
4133 case bp_access_watchpoint
:
4134 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4138 case bp_catch_vfork
:
4140 loc
->loc_type
= bp_loc_other
;
4143 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4146 /* Add this breakpoint to the end of the chain. */
4148 loc_p
= bp_location_chain
;
4150 bp_location_chain
= loc
;
4153 while (loc_p
->global_next
)
4154 loc_p
= loc_p
->global_next
;
4155 loc_p
->global_next
= loc
;
4161 static void free_bp_location (struct bp_location
*loc
)
4168 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4169 that has type BPTYPE and has no locations as yet. */
4171 static struct breakpoint
*
4172 set_raw_breakpoint_without_location (enum bptype bptype
)
4174 struct breakpoint
*b
, *b1
;
4176 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4177 memset (b
, 0, sizeof (*b
));
4180 b
->language
= current_language
->la_language
;
4181 b
->input_radix
= input_radix
;
4183 b
->enable_state
= bp_enabled
;
4186 b
->ignore_count
= 0;
4188 b
->frame_id
= null_frame_id
;
4189 b
->dll_pathname
= NULL
;
4190 b
->triggered_dll_pathname
= NULL
;
4191 b
->forked_inferior_pid
= 0;
4192 b
->exec_pathname
= NULL
;
4194 b
->condition_not_parsed
= 0;
4196 /* Add this breakpoint to the end of the chain
4197 so that a list of breakpoints will come out in order
4198 of increasing numbers. */
4200 b1
= breakpoint_chain
;
4202 breakpoint_chain
= b
;
4212 /* Initialize loc->function_name. */
4214 set_breakpoint_location_function (struct bp_location
*loc
)
4216 if (loc
->owner
->type
== bp_breakpoint
4217 || loc
->owner
->type
== bp_hardware_breakpoint
)
4219 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4221 if (loc
->function_name
)
4222 loc
->function_name
= xstrdup (loc
->function_name
);
4226 /* set_raw_breakpoint is a low level routine for allocating and
4227 partially initializing a breakpoint of type BPTYPE. The newly
4228 created breakpoint's address, section, source file name, and line
4229 number are provided by SAL. The newly created and partially
4230 initialized breakpoint is added to the breakpoint chain and
4231 is also returned as the value of this function.
4233 It is expected that the caller will complete the initialization of
4234 the newly created breakpoint struct as well as output any status
4235 information regarding the creation of a new breakpoint. In
4236 particular, set_raw_breakpoint does NOT set the breakpoint
4237 number! Care should be taken to not allow an error to occur
4238 prior to completing the initialization of the breakpoint. If this
4239 should happen, a bogus breakpoint will be left on the chain. */
4242 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4244 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4245 CORE_ADDR adjusted_address
;
4247 /* Adjust the breakpoint's address prior to allocating a location.
4248 Once we call allocate_bp_location(), that mostly uninitialized
4249 location will be placed on the location chain. Adjustment of the
4250 breakpoint may cause read_memory_nobpt() to be called and we do
4251 not want its scan of the location chain to find a breakpoint and
4252 location that's only been partially initialized. */
4253 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4255 b
->loc
= allocate_bp_location (b
, bptype
);
4256 b
->loc
->requested_address
= sal
.pc
;
4257 b
->loc
->address
= adjusted_address
;
4259 if (sal
.symtab
== NULL
)
4260 b
->source_file
= NULL
;
4262 b
->source_file
= savestring (sal
.symtab
->filename
,
4263 strlen (sal
.symtab
->filename
));
4264 b
->loc
->section
= sal
.section
;
4265 b
->line_number
= sal
.line
;
4267 set_breakpoint_location_function (b
->loc
);
4269 check_duplicates (b
);
4270 breakpoints_changed ();
4276 /* Note that the breakpoint object B describes a permanent breakpoint
4277 instruction, hard-wired into the inferior's code. */
4279 make_breakpoint_permanent (struct breakpoint
*b
)
4281 struct bp_location
*bl
;
4282 b
->enable_state
= bp_permanent
;
4284 /* By definition, permanent breakpoints are already present in the code.
4285 Mark all locations as inserted. For now, make_breakpoint_permanent
4286 is called in just one place, so it's hard to say if it's reasonable
4287 to have permanent breakpoint with multiple locations or not,
4288 but it's easy to implmement. */
4289 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4293 static struct breakpoint
*
4294 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4296 static int internal_breakpoint_number
= -1;
4297 struct symtab_and_line sal
;
4298 struct breakpoint
*b
;
4300 init_sal (&sal
); /* initialize to zeroes */
4303 sal
.section
= find_pc_overlay (sal
.pc
);
4305 b
= set_raw_breakpoint (sal
, type
);
4306 b
->number
= internal_breakpoint_number
--;
4307 b
->disposition
= disp_donttouch
;
4314 create_longjmp_breakpoint (char *func_name
)
4316 struct breakpoint
*b
;
4317 struct minimal_symbol
*m
;
4319 if (func_name
== NULL
)
4320 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4323 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4326 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4329 b
->enable_state
= bp_disabled
;
4332 b
->addr_string
= xstrdup (func_name
);
4335 /* Call this routine when stepping and nexting to enable a breakpoint
4336 if we do a longjmp(). When we hit that breakpoint, call
4337 set_longjmp_resume_breakpoint() to figure out where we are going. */
4340 enable_longjmp_breakpoint (void)
4342 struct breakpoint
*b
;
4345 if (b
->type
== bp_longjmp
)
4347 b
->enable_state
= bp_enabled
;
4348 check_duplicates (b
);
4353 disable_longjmp_breakpoint (void)
4355 struct breakpoint
*b
;
4358 if (b
->type
== bp_longjmp
4359 || b
->type
== bp_longjmp_resume
)
4361 b
->enable_state
= bp_disabled
;
4362 check_duplicates (b
);
4367 create_overlay_event_breakpoint (char *func_name
)
4369 struct breakpoint
*b
;
4370 struct minimal_symbol
*m
;
4372 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4375 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4377 b
->addr_string
= xstrdup (func_name
);
4379 if (overlay_debugging
== ovly_auto
)
4381 b
->enable_state
= bp_enabled
;
4382 overlay_events_enabled
= 1;
4386 b
->enable_state
= bp_disabled
;
4387 overlay_events_enabled
= 0;
4392 enable_overlay_breakpoints (void)
4394 struct breakpoint
*b
;
4397 if (b
->type
== bp_overlay_event
)
4399 b
->enable_state
= bp_enabled
;
4400 check_duplicates (b
);
4401 overlay_events_enabled
= 1;
4406 disable_overlay_breakpoints (void)
4408 struct breakpoint
*b
;
4411 if (b
->type
== bp_overlay_event
)
4413 b
->enable_state
= bp_disabled
;
4414 check_duplicates (b
);
4415 overlay_events_enabled
= 0;
4420 create_thread_event_breakpoint (CORE_ADDR address
)
4422 struct breakpoint
*b
;
4424 b
= create_internal_breakpoint (address
, bp_thread_event
);
4426 b
->enable_state
= bp_enabled
;
4427 /* addr_string has to be used or breakpoint_re_set will delete me. */
4428 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4434 remove_thread_event_breakpoints (void)
4436 struct breakpoint
*b
, *temp
;
4438 ALL_BREAKPOINTS_SAFE (b
, temp
)
4439 if (b
->type
== bp_thread_event
)
4440 delete_breakpoint (b
);
4443 struct captured_parse_breakpoint_args
4446 struct symtabs_and_lines
*sals_p
;
4447 char ***addr_string_p
;
4451 struct lang_and_radix
4459 remove_solib_event_breakpoints (void)
4461 struct breakpoint
*b
, *temp
;
4463 ALL_BREAKPOINTS_SAFE (b
, temp
)
4464 if (b
->type
== bp_shlib_event
)
4465 delete_breakpoint (b
);
4469 create_solib_event_breakpoint (CORE_ADDR address
)
4471 struct breakpoint
*b
;
4473 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4477 /* Disable any breakpoints that are on code in shared libraries. Only
4478 apply to enabled breakpoints, disabled ones can just stay disabled. */
4481 disable_breakpoints_in_shlibs (void)
4483 struct bp_location
*loc
;
4484 int disabled_shlib_breaks
= 0;
4486 ALL_BP_LOCATIONS (loc
)
4488 struct breakpoint
*b
= loc
->owner
;
4489 /* We apply the check to all breakpoints, including disabled
4490 for those with loc->duplicate set. This is so that when breakpoint
4491 becomes enabled, or the duplicate is removed, gdb will try to insert
4492 all breakpoints. If we don't set shlib_disabled here, we'll try
4493 to insert those breakpoints and fail. */
4494 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4495 && !loc
->shlib_disabled
4497 && PC_SOLIB (loc
->address
)
4499 && solib_address (loc
->address
)
4503 loc
->shlib_disabled
= 1;
4508 /* Disable any breakpoints that are in in an unloaded shared library. Only
4509 apply to enabled breakpoints, disabled ones can just stay disabled. */
4512 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4514 struct bp_location
*loc
;
4515 int disabled_shlib_breaks
= 0;
4517 ALL_BP_LOCATIONS (loc
)
4519 struct breakpoint
*b
= loc
->owner
;
4520 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4521 || loc
->loc_type
== bp_loc_software_breakpoint
)
4522 && !loc
->shlib_disabled
)
4525 char *so_name
= PC_SOLIB (loc
->address
);
4527 char *so_name
= solib_address (loc
->address
);
4529 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4531 loc
->shlib_disabled
= 1;
4532 /* At this point, we cannot rely on remove_breakpoint
4533 succeeding so we must mark the breakpoint as not inserted
4534 to prevent future errors occurring in remove_breakpoints. */
4536 if (!disabled_shlib_breaks
)
4538 target_terminal_ours_for_output ();
4539 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4542 disabled_shlib_breaks
= 1;
4549 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4550 enum bptype bp_kind
)
4552 struct symtab_and_line sal
;
4553 struct breakpoint
*b
;
4554 int thread
= -1; /* All threads. */
4561 b
= set_raw_breakpoint (sal
, bp_kind
);
4562 set_breakpoint_count (breakpoint_count
+ 1);
4563 b
->number
= breakpoint_count
;
4564 b
->cond_string
= (cond_string
== NULL
) ?
4565 NULL
: savestring (cond_string
, strlen (cond_string
));
4567 b
->addr_string
= NULL
;
4568 b
->enable_state
= bp_enabled
;
4569 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4570 b
->forked_inferior_pid
= 0;
4576 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4578 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4582 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4584 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4588 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4590 struct symtab_and_line sal
;
4591 struct breakpoint
*b
;
4592 int thread
= -1; /* All threads. */
4599 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4600 set_breakpoint_count (breakpoint_count
+ 1);
4601 b
->number
= breakpoint_count
;
4602 b
->cond_string
= (cond_string
== NULL
) ?
4603 NULL
: savestring (cond_string
, strlen (cond_string
));
4605 b
->addr_string
= NULL
;
4606 b
->enable_state
= bp_enabled
;
4607 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4613 hw_breakpoint_used_count (void)
4615 struct breakpoint
*b
;
4620 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4628 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4630 struct breakpoint
*b
;
4633 *other_type_used
= 0;
4636 if (breakpoint_enabled (b
))
4638 if (b
->type
== type
)
4640 else if ((b
->type
== bp_hardware_watchpoint
||
4641 b
->type
== bp_read_watchpoint
||
4642 b
->type
== bp_access_watchpoint
))
4643 *other_type_used
= 1;
4649 /* Call this after hitting the longjmp() breakpoint. Use this to set
4650 a new breakpoint at the target of the jmp_buf.
4652 FIXME - This ought to be done by setting a temporary breakpoint
4653 that gets deleted automatically... */
4656 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4658 struct breakpoint
*b
;
4661 if (b
->type
== bp_longjmp_resume
)
4663 b
->loc
->requested_address
= pc
;
4664 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4666 b
->enable_state
= bp_enabled
;
4667 b
->frame_id
= frame_id
;
4668 check_duplicates (b
);
4674 disable_watchpoints_before_interactive_call_start (void)
4676 struct breakpoint
*b
;
4680 if (((b
->type
== bp_watchpoint
)
4681 || (b
->type
== bp_hardware_watchpoint
)
4682 || (b
->type
== bp_read_watchpoint
)
4683 || (b
->type
== bp_access_watchpoint
))
4684 && breakpoint_enabled (b
))
4686 b
->enable_state
= bp_call_disabled
;
4687 check_duplicates (b
);
4693 enable_watchpoints_after_interactive_call_stop (void)
4695 struct breakpoint
*b
;
4699 if (((b
->type
== bp_watchpoint
)
4700 || (b
->type
== bp_hardware_watchpoint
)
4701 || (b
->type
== bp_read_watchpoint
)
4702 || (b
->type
== bp_access_watchpoint
))
4703 && (b
->enable_state
== bp_call_disabled
))
4705 b
->enable_state
= bp_enabled
;
4706 check_duplicates (b
);
4712 /* Set a breakpoint that will evaporate an end of command
4713 at address specified by SAL.
4714 Restrict it to frame FRAME if FRAME is nonzero. */
4717 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4720 struct breakpoint
*b
;
4721 b
= set_raw_breakpoint (sal
, type
);
4722 b
->enable_state
= bp_enabled
;
4723 b
->disposition
= disp_donttouch
;
4724 b
->frame_id
= frame_id
;
4726 /* If we're debugging a multi-threaded program, then we
4727 want momentary breakpoints to be active in only a
4728 single thread of control. */
4729 if (in_thread_list (inferior_ptid
))
4730 b
->thread
= pid_to_thread_id (inferior_ptid
);
4736 /* Tell the user we have just set a breakpoint B. */
4739 mention (struct breakpoint
*b
)
4742 struct cleanup
*old_chain
, *ui_out_chain
;
4743 struct ui_stream
*stb
;
4745 stb
= ui_out_stream_new (uiout
);
4746 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4748 /* FIXME: This is misplaced; mention() is called by things (like
4749 hitting a watchpoint) other than breakpoint creation. It should
4750 be possible to clean this up and at the same time replace the
4751 random calls to breakpoint_changed with this hook, as has already
4752 been done for deprecated_delete_breakpoint_hook and so on. */
4753 if (deprecated_create_breakpoint_hook
)
4754 deprecated_create_breakpoint_hook (b
);
4755 breakpoint_create_event (b
->number
);
4757 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4758 b
->ops
->print_mention (b
);
4763 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4766 ui_out_text (uiout
, "Watchpoint ");
4767 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4768 ui_out_field_int (uiout
, "number", b
->number
);
4769 ui_out_text (uiout
, ": ");
4770 print_expression (b
->exp
, stb
->stream
);
4771 ui_out_field_stream (uiout
, "exp", stb
);
4772 do_cleanups (ui_out_chain
);
4774 case bp_hardware_watchpoint
:
4775 ui_out_text (uiout
, "Hardware watchpoint ");
4776 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4777 ui_out_field_int (uiout
, "number", b
->number
);
4778 ui_out_text (uiout
, ": ");
4779 print_expression (b
->exp
, stb
->stream
);
4780 ui_out_field_stream (uiout
, "exp", stb
);
4781 do_cleanups (ui_out_chain
);
4783 case bp_read_watchpoint
:
4784 ui_out_text (uiout
, "Hardware read watchpoint ");
4785 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4786 ui_out_field_int (uiout
, "number", b
->number
);
4787 ui_out_text (uiout
, ": ");
4788 print_expression (b
->exp
, stb
->stream
);
4789 ui_out_field_stream (uiout
, "exp", stb
);
4790 do_cleanups (ui_out_chain
);
4792 case bp_access_watchpoint
:
4793 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4794 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4795 ui_out_field_int (uiout
, "number", b
->number
);
4796 ui_out_text (uiout
, ": ");
4797 print_expression (b
->exp
, stb
->stream
);
4798 ui_out_field_stream (uiout
, "exp", stb
);
4799 do_cleanups (ui_out_chain
);
4802 if (ui_out_is_mi_like_p (uiout
))
4807 printf_filtered (_("Breakpoint %d"), b
->number
);
4810 case bp_hardware_breakpoint
:
4811 if (ui_out_is_mi_like_p (uiout
))
4816 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4820 case bp_catch_unload
:
4821 printf_filtered (_("Catchpoint %d (%s %s)"),
4823 (b
->type
== bp_catch_load
) ? "load" : "unload",
4824 (b
->dll_pathname
!= NULL
) ?
4825 b
->dll_pathname
: "<any library>");
4828 case bp_catch_vfork
:
4829 printf_filtered (_("Catchpoint %d (%s)"),
4831 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4834 printf_filtered (_("Catchpoint %d (exec)"),
4841 case bp_longjmp_resume
:
4842 case bp_step_resume
:
4844 case bp_watchpoint_scope
:
4845 case bp_shlib_event
:
4846 case bp_thread_event
:
4847 case bp_overlay_event
:
4853 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4857 printf_filtered (_(" (%s) pending."), b
->addr_string
);
4861 if (addressprint
|| b
->source_file
== NULL
)
4863 printf_filtered (" at ");
4864 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
4867 printf_filtered (": file %s, line %d.",
4868 b
->source_file
, b
->line_number
);
4872 struct bp_location
*loc
= b
->loc
;
4874 for (; loc
; loc
= loc
->next
)
4876 printf_filtered (" (%d locations)", n
);
4881 do_cleanups (old_chain
);
4882 if (ui_out_is_mi_like_p (uiout
))
4884 printf_filtered ("\n");
4888 static struct bp_location
*
4889 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
4890 const struct symtab_and_line
*sal
)
4892 struct bp_location
*loc
, **tmp
;
4894 loc
= allocate_bp_location (b
, bptype
);
4895 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
4898 loc
->requested_address
= sal
->pc
;
4899 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
4901 loc
->section
= sal
->section
;
4903 set_breakpoint_location_function (loc
);
4907 /* Create a breakpoint with SAL as location. Use ADDR_STRING
4908 as textual description of the location, and COND_STRING
4909 as condition expression. */
4912 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
4914 enum bptype type
, enum bpdisp disposition
,
4915 int thread
, int ignore_count
, int from_tty
)
4917 struct breakpoint
*b
= NULL
;
4920 if (type
== bp_hardware_breakpoint
)
4922 int i
= hw_breakpoint_used_count ();
4923 int target_resources_ok
=
4924 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4926 if (target_resources_ok
== 0)
4927 error (_("No hardware breakpoint support in the target."));
4928 else if (target_resources_ok
< 0)
4929 error (_("Hardware breakpoints used exceeds limit."));
4932 for (i
= 0; i
< sals
.nelts
; ++i
)
4934 struct symtab_and_line sal
= sals
.sals
[i
];
4935 struct bp_location
*loc
;
4938 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
4942 b
= set_raw_breakpoint (sal
, type
);
4943 set_breakpoint_count (breakpoint_count
+ 1);
4944 b
->number
= breakpoint_count
;
4947 b
->cond_string
= cond_string
;
4948 b
->ignore_count
= ignore_count
;
4949 b
->enable_state
= bp_enabled
;
4950 b
->disposition
= disposition
;
4956 loc
= add_location_to_breakpoint (b
, type
, &sal
);
4961 char *arg
= b
->cond_string
;
4962 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
4964 error (_("Garbage %s follows condition"), arg
);
4969 b
->addr_string
= addr_string
;
4971 /* addr_string has to be used or breakpoint_re_set will delete
4973 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4978 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
4979 elements to fill the void space. */
4980 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
4982 int i
= index_to_remove
+1;
4983 int last_index
= sal
->nelts
-1;
4985 for (;i
<= last_index
; ++i
)
4986 sal
->sals
[i
-1] = sal
->sals
[i
];
4991 /* If appropriate, obtains all sals that correspond
4992 to the same file and line as SAL. This is done
4993 only if SAL does not have explicit PC and has
4994 line and file information. If we got just a single
4995 expanded sal, return the original.
4997 Otherwise, if SAL.explicit_line is not set, filter out
4998 all sals for which the name of enclosing function
4999 is different from SAL. This makes sure that if we have
5000 breakpoint originally set in template instantiation, say
5001 foo<int>(), we won't expand SAL to locations at the same
5002 line in all existing instantiations of 'foo'.
5005 struct symtabs_and_lines
5006 expand_line_sal_maybe (struct symtab_and_line sal
)
5008 struct symtabs_and_lines expanded
;
5009 CORE_ADDR original_pc
= sal
.pc
;
5010 char *original_function
= NULL
;
5014 /* If we have explicit pc, don't expand.
5015 If we have no line number, we can't expand. */
5016 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5019 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5020 expanded
.sals
[0] = sal
;
5025 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5027 expanded
= expand_line_sal (sal
);
5028 if (expanded
.nelts
== 1)
5030 /* We had one sal, we got one sal. Without futher
5031 processing, just return the original sal. */
5032 xfree (expanded
.sals
);
5034 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5035 sal
.pc
= original_pc
;
5036 expanded
.sals
[0] = sal
;
5040 if (!sal
.explicit_line
)
5042 CORE_ADDR func_addr
, func_end
;
5043 for (i
= 0; i
< expanded
.nelts
; ++i
)
5045 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5046 char *this_function
;
5047 if (find_pc_partial_function (pc
, &this_function
,
5048 &func_addr
, &func_end
))
5050 if (this_function
&&
5051 strcmp (this_function
, original_function
) != 0)
5053 remove_sal (&expanded
, i
);
5056 else if (func_addr
== pc
)
5058 /* We're at beginning of a function, and should
5060 struct symbol
*sym
= find_pc_function (pc
);
5062 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5065 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5072 if (expanded
.nelts
<= 1)
5074 /* This is un ugly workaround. If we get zero
5075 expanded sals then something is really wrong.
5076 Fix that by returnign the original sal. */
5077 xfree (expanded
.sals
);
5079 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5080 sal
.pc
= original_pc
;
5081 expanded
.sals
[0] = sal
;
5088 for (i
= 0; i
< expanded
.nelts
; ++i
)
5089 if (expanded
.sals
[i
].pc
== original_pc
)
5100 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5101 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5102 value. COND_STRING, if not NULL, specified the condition to be
5103 used for all breakpoints. Essentially the only case where
5104 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5105 function. In that case, it's still not possible to specify
5106 separate conditions for different overloaded functions, so
5107 we take just a single condition string.
5109 NOTE: If the function succeeds, the caller is expected to cleanup
5110 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5111 array contents). If the function fails (error() is called), the
5112 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5113 COND and SALS arrays and each of those arrays contents. */
5116 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5118 enum bptype type
, enum bpdisp disposition
,
5119 int thread
, int ignore_count
, int from_tty
)
5122 for (i
= 0; i
< sals
.nelts
; ++i
)
5124 struct symtabs_and_lines expanded
=
5125 expand_line_sal_maybe (sals
.sals
[i
]);
5127 create_breakpoint (expanded
, addr_string
[i
],
5128 cond_string
, type
, disposition
,
5129 thread
, ignore_count
, from_tty
);
5133 /* Parse ARG which is assumed to be a SAL specification possibly
5134 followed by conditionals. On return, SALS contains an array of SAL
5135 addresses found. ADDR_STRING contains a vector of (canonical)
5136 address strings. ARG points to the end of the SAL. */
5139 parse_breakpoint_sals (char **address
,
5140 struct symtabs_and_lines
*sals
,
5141 char ***addr_string
,
5144 char *addr_start
= *address
;
5145 *addr_string
= NULL
;
5146 /* If no arg given, or if first arg is 'if ', use the default
5148 if ((*address
) == NULL
5149 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5151 if (default_breakpoint_valid
)
5153 struct symtab_and_line sal
;
5154 init_sal (&sal
); /* initialize to zeroes */
5155 sals
->sals
= (struct symtab_and_line
*)
5156 xmalloc (sizeof (struct symtab_and_line
));
5157 sal
.pc
= default_breakpoint_address
;
5158 sal
.line
= default_breakpoint_line
;
5159 sal
.symtab
= default_breakpoint_symtab
;
5160 sal
.section
= find_pc_overlay (sal
.pc
);
5161 sals
->sals
[0] = sal
;
5165 error (_("No default breakpoint address now."));
5169 /* Force almost all breakpoints to be in terms of the
5170 current_source_symtab (which is decode_line_1's default). This
5171 should produce the results we want almost all of the time while
5172 leaving default_breakpoint_* alone.
5173 ObjC: However, don't match an Objective-C method name which
5174 may have a '+' or '-' succeeded by a '[' */
5176 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5178 if (default_breakpoint_valid
5180 || ((strchr ("+-", (*address
)[0]) != NULL
)
5181 && ((*address
)[1] != '['))))
5182 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5183 default_breakpoint_line
, addr_string
,
5186 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5187 addr_string
, not_found_ptr
);
5189 /* For any SAL that didn't have a canonical string, fill one in. */
5190 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5191 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5192 if (addr_start
!= (*address
))
5195 for (i
= 0; i
< sals
->nelts
; i
++)
5197 /* Add the string if not present. */
5198 if ((*addr_string
)[i
] == NULL
)
5199 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5205 /* Convert each SAL into a real PC. Verify that the PC can be
5206 inserted as a breakpoint. If it can't throw an error. */
5209 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5213 for (i
= 0; i
< sals
->nelts
; i
++)
5214 resolve_sal_pc (&sals
->sals
[i
]);
5218 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5220 struct captured_parse_breakpoint_args
*args
= data
;
5222 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5223 args
->not_found_ptr
);
5226 /* Given TOK, a string specification of condition and thread, as
5227 accepted by the 'break' command, extract the condition
5228 string and thread number and set *COND_STRING and *THREAD.
5229 PC identifies the context at which the condition should be parsed.
5230 If no condition is found, *COND_STRING is set to NULL.
5231 If no thread is found, *THREAD is set to -1. */
5233 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5234 char **cond_string
, int *thread
)
5236 *cond_string
= NULL
;
5242 char *cond_start
= NULL
;
5243 char *cond_end
= NULL
;
5244 while (*tok
== ' ' || *tok
== '\t')
5249 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5252 toklen
= end_tok
- tok
;
5254 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5256 tok
= cond_start
= end_tok
+ 1;
5257 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5259 *cond_string
= savestring (cond_start
,
5260 cond_end
- cond_start
);
5262 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5268 *thread
= strtol (tok
, &tok
, 0);
5270 error (_("Junk after thread keyword."));
5271 if (!valid_thread_id (*thread
))
5272 error (_("Unknown thread %d."), *thread
);
5275 error (_("Junk at end of arguments."));
5279 /* Set a breakpoint. This function is shared between
5280 CLI and MI functions for setting a breakpoint.
5281 This function has two major modes of operations,
5282 selected by the PARSE_CONDITION_AND_THREAD parameter.
5283 If non-zero, the function will parse arg, extracting
5284 breakpoint location, address and thread. Otherwise,
5285 ARG is just the location of breakpoint, with condition
5286 and thread specified by the COND_STRING and THREAD
5290 break_command_really (char *arg
, char *cond_string
, int thread
,
5291 int parse_condition_and_thread
,
5292 int tempflag
, int hardwareflag
,
5294 enum auto_boolean pending_break_support
,
5297 struct gdb_exception e
;
5298 struct symtabs_and_lines sals
;
5299 struct symtab_and_line pending_sal
;
5302 char *addr_start
= arg
;
5304 struct cleanup
*old_chain
;
5305 struct cleanup
*breakpoint_chain
= NULL
;
5306 struct captured_parse_breakpoint_args parse_args
;
5315 parse_args
.arg_p
= &arg
;
5316 parse_args
.sals_p
= &sals
;
5317 parse_args
.addr_string_p
= &addr_string
;
5318 parse_args
.not_found_ptr
= ¬_found
;
5320 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5321 &parse_args
, RETURN_MASK_ALL
);
5323 /* If caller is interested in rc value from parse, set value. */
5327 throw_exception (e
);
5331 case NOT_FOUND_ERROR
:
5333 /* If pending breakpoint support is turned off, throw
5336 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5337 throw_exception (e
);
5339 exception_print (gdb_stderr
, e
);
5341 /* If pending breakpoint support is auto query and the user
5342 selects no, then simply return the error code. */
5343 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5344 !nquery ("Make breakpoint pending on future shared library load? "))
5347 /* At this point, either the user was queried about setting
5348 a pending breakpoint and selected yes, or pending
5349 breakpoint behavior is on and thus a pending breakpoint
5350 is defaulted on behalf of the user. */
5351 copy_arg
= xstrdup (addr_start
);
5352 addr_string
= ©_arg
;
5354 sals
.sals
= &pending_sal
;
5359 throw_exception (e
);
5366 /* Create a chain of things that always need to be cleaned up. */
5367 old_chain
= make_cleanup (null_cleanup
, 0);
5371 /* Make sure that all storage allocated to SALS gets freed. */
5372 make_cleanup (xfree
, sals
.sals
);
5374 /* Cleanup the addr_string array but not its contents. */
5375 make_cleanup (xfree
, addr_string
);
5378 /* ----------------------------- SNIP -----------------------------
5379 Anything added to the cleanup chain beyond this point is assumed
5380 to be part of a breakpoint. If the breakpoint create succeeds
5381 then the memory is not reclaimed. */
5382 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5384 /* Mark the contents of the addr_string for cleanup. These go on
5385 the breakpoint_chain and only occure if the breakpoint create
5387 for (i
= 0; i
< sals
.nelts
; i
++)
5389 if (addr_string
[i
] != NULL
)
5390 make_cleanup (xfree
, addr_string
[i
]);
5393 /* Resolve all line numbers to PC's and verify that the addresses
5394 are ok for the target. */
5396 breakpoint_sals_to_pc (&sals
, addr_start
);
5398 /* Verify that condition can be parsed, before setting any
5399 breakpoints. Allocate a separate condition expression for each
5403 if (parse_condition_and_thread
)
5405 /* Here we only parse 'arg' to separate condition
5406 from thread number, so parsing in context of first
5407 sal is OK. When setting the breakpoint we'll
5408 re-parse it in context of each sal. */
5411 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5413 make_cleanup (xfree
, cond_string
);
5417 /* Create a private copy of condition string. */
5420 cond_string
= xstrdup (cond_string
);
5421 make_cleanup (xfree
, cond_string
);
5424 create_breakpoints (sals
, addr_string
, cond_string
,
5425 hardwareflag
? bp_hardware_breakpoint
5427 tempflag
? disp_del
: disp_donttouch
,
5428 thread
, ignore_count
, from_tty
);
5432 struct symtab_and_line sal
= {0};
5433 struct breakpoint
*b
;
5435 make_cleanup (xfree
, copy_arg
);
5437 b
= set_raw_breakpoint_without_location (hardwareflag
5438 ? bp_hardware_breakpoint
5440 set_breakpoint_count (breakpoint_count
+ 1);
5441 b
->number
= breakpoint_count
;
5443 b
->addr_string
= addr_string
[0];
5444 b
->cond_string
= NULL
;
5445 b
->ignore_count
= ignore_count
;
5446 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5447 b
->condition_not_parsed
= 1;
5452 warning (_("Multiple breakpoints were set.\n"
5453 "Use the \"delete\" command to delete unwanted breakpoints."));
5454 /* That's it. Discard the cleanups for data inserted into the
5456 discard_cleanups (breakpoint_chain
);
5457 /* But cleanup everything else. */
5458 do_cleanups (old_chain
);
5461 /* Set a breakpoint.
5462 ARG is a string describing breakpoint address,
5463 condition, and thread.
5464 FLAG specifies if a breakpoint is hardware on,
5465 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5469 break_command_1 (char *arg
, int flag
, int from_tty
)
5471 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5472 int tempflag
= flag
& BP_TEMPFLAG
;
5474 break_command_really (arg
,
5475 NULL
, 0, 1 /* parse arg */,
5476 tempflag
, hardwareflag
,
5477 0 /* Ignore count */,
5478 pending_break_support
, from_tty
);
5483 set_breakpoint (char *address
, char *condition
,
5484 int hardwareflag
, int tempflag
,
5485 int thread
, int ignore_count
,
5488 break_command_really (address
, condition
, thread
,
5489 0 /* condition and thread are valid. */,
5490 tempflag
, hardwareflag
,
5493 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5498 /* Helper function for break_command_1 and disassemble_command. */
5501 resolve_sal_pc (struct symtab_and_line
*sal
)
5505 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5507 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5508 error (_("No line %d in file \"%s\"."),
5509 sal
->line
, sal
->symtab
->filename
);
5513 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5515 struct blockvector
*bv
;
5519 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5522 sym
= block_function (b
);
5525 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5526 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5530 /* It really is worthwhile to have the section, so we'll just
5531 have to look harder. This case can be executed if we have
5532 line numbers but no functions (as can happen in assembly
5535 struct minimal_symbol
*msym
;
5537 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5539 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5546 break_command (char *arg
, int from_tty
)
5548 break_command_1 (arg
, 0, from_tty
);
5552 tbreak_command (char *arg
, int from_tty
)
5554 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5558 hbreak_command (char *arg
, int from_tty
)
5560 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5564 thbreak_command (char *arg
, int from_tty
)
5566 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5570 stop_command (char *arg
, int from_tty
)
5572 printf_filtered (_("Specify the type of breakpoint to set.\n\
5573 Usage: stop in <function | address>\n\
5574 stop at <line>\n"));
5578 stopin_command (char *arg
, int from_tty
)
5582 if (arg
== (char *) NULL
)
5584 else if (*arg
!= '*')
5589 /* look for a ':'. If this is a line number specification, then
5590 say it is bad, otherwise, it should be an address or
5591 function/method name */
5592 while (*argptr
&& !hasColon
)
5594 hasColon
= (*argptr
== ':');
5599 badInput
= (*argptr
!= ':'); /* Not a class::method */
5601 badInput
= isdigit (*arg
); /* a simple line number */
5605 printf_filtered (_("Usage: stop in <function | address>\n"));
5607 break_command_1 (arg
, 0, from_tty
);
5611 stopat_command (char *arg
, int from_tty
)
5615 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5622 /* look for a ':'. If there is a '::' then get out, otherwise
5623 it is probably a line number. */
5624 while (*argptr
&& !hasColon
)
5626 hasColon
= (*argptr
== ':');
5631 badInput
= (*argptr
== ':'); /* we have class::method */
5633 badInput
= !isdigit (*arg
); /* not a line number */
5637 printf_filtered (_("Usage: stop at <line>\n"));
5639 break_command_1 (arg
, 0, from_tty
);
5642 /* accessflag: hw_write: watch write,
5643 hw_read: watch read,
5644 hw_access: watch access (read or write) */
5646 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5648 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5649 struct symtab_and_line sal
;
5650 struct expression
*exp
;
5651 struct block
*exp_valid_block
;
5652 struct value
*val
, *mark
;
5653 struct frame_info
*frame
;
5654 struct frame_info
*prev_frame
= NULL
;
5655 char *exp_start
= NULL
;
5656 char *exp_end
= NULL
;
5657 char *tok
, *id_tok_start
, *end_tok
;
5659 char *cond_start
= NULL
;
5660 char *cond_end
= NULL
;
5661 struct expression
*cond
= NULL
;
5662 int i
, other_type_used
, target_resources_ok
= 0;
5663 enum bptype bp_type
;
5667 init_sal (&sal
); /* initialize to zeroes */
5669 /* Make sure that we actually have parameters to parse. */
5670 if (arg
!= NULL
&& arg
[0] != '\0')
5672 toklen
= strlen (arg
); /* Size of argument list. */
5674 /* Points tok to the end of the argument list. */
5675 tok
= arg
+ toklen
- 1;
5677 /* Go backwards in the parameters list. Skip the last parameter.
5678 If we're expecting a 'thread <thread_num>' parameter, this should
5679 be the thread identifier. */
5680 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5682 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5685 /* Points end_tok to the beginning of the last token. */
5686 id_tok_start
= tok
+ 1;
5688 /* Go backwards in the parameters list. Skip one more parameter.
5689 If we're expecting a 'thread <thread_num>' parameter, we should
5690 reach a "thread" token. */
5691 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5696 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5699 /* Move the pointer forward to skip the whitespace and
5700 calculate the length of the token. */
5702 toklen
= end_tok
- tok
;
5704 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5706 /* At this point we've found a "thread" token, which means
5707 the user is trying to set a watchpoint that triggers
5708 only in a specific thread. */
5711 /* Extract the thread ID from the next token. */
5712 thread
= strtol (id_tok_start
, &endp
, 0);
5714 /* Check if the user provided a valid numeric value for the
5716 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5717 error (_("Invalid thread ID specification %s."), id_tok_start
);
5719 /* Check if the thread actually exists. */
5720 if (!valid_thread_id (thread
))
5721 error (_("Unknown thread %d."), thread
);
5723 /* Truncate the string and get rid of the thread <thread_num>
5724 parameter before the parameter list is parsed by the
5725 evaluate_expression() function. */
5730 /* Parse the rest of the arguments. */
5731 innermost_block
= NULL
;
5733 exp
= parse_exp_1 (&arg
, 0, 0);
5735 exp_valid_block
= innermost_block
;
5736 mark
= value_mark ();
5737 val
= evaluate_expression (exp
);
5738 release_value (val
);
5739 if (value_lazy (val
))
5740 value_fetch_lazy (val
);
5743 while (*tok
== ' ' || *tok
== '\t')
5747 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5750 toklen
= end_tok
- tok
;
5751 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5753 tok
= cond_start
= end_tok
+ 1;
5754 cond
= parse_exp_1 (&tok
, 0, 0);
5758 error (_("Junk at end of command."));
5760 if (accessflag
== hw_read
)
5761 bp_type
= bp_read_watchpoint
;
5762 else if (accessflag
== hw_access
)
5763 bp_type
= bp_access_watchpoint
;
5765 bp_type
= bp_hardware_watchpoint
;
5767 mem_cnt
= can_use_hardware_watchpoint (val
);
5768 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5769 error (_("Expression cannot be implemented with read/access watchpoint."));
5772 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5773 target_resources_ok
=
5774 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5776 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5777 error (_("Target does not support this type of hardware watchpoint."));
5779 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5780 error (_("Target can only support one kind of HW watchpoint at a time."));
5783 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5784 watchpoint could not be set. */
5785 if (!mem_cnt
|| target_resources_ok
<= 0)
5786 bp_type
= bp_watchpoint
;
5788 frame
= block_innermost_frame (exp_valid_block
);
5790 prev_frame
= get_prev_frame (frame
);
5794 /* If the expression is "local", then set up a "watchpoint scope"
5795 breakpoint at the point where we've left the scope of the watchpoint
5796 expression. Create the scope breakpoint before the watchpoint, so
5797 that we will encounter it first in bpstat_stop_status. */
5798 if (innermost_block
&& prev_frame
)
5800 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5801 bp_watchpoint_scope
);
5803 scope_breakpoint
->enable_state
= bp_enabled
;
5805 /* Automatically delete the breakpoint when it hits. */
5806 scope_breakpoint
->disposition
= disp_del
;
5808 /* Only break in the proper frame (help with recursion). */
5809 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5811 /* Set the address at which we will stop. */
5812 scope_breakpoint
->loc
->requested_address
5813 = get_frame_pc (prev_frame
);
5814 scope_breakpoint
->loc
->address
5815 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5816 scope_breakpoint
->type
);
5819 /* Now set up the breakpoint. */
5820 b
= set_raw_breakpoint (sal
, bp_type
);
5821 set_breakpoint_count (breakpoint_count
+ 1);
5822 b
->number
= breakpoint_count
;
5824 b
->disposition
= disp_donttouch
;
5826 b
->exp_valid_block
= exp_valid_block
;
5827 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5829 b
->loc
->cond
= cond
;
5831 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5836 b
->watchpoint_frame
= get_frame_id (frame
);
5838 b
->watchpoint_frame
= null_frame_id
;
5840 if (scope_breakpoint
!= NULL
)
5842 /* The scope breakpoint is related to the watchpoint. We will
5843 need to act on them together. */
5844 b
->related_breakpoint
= scope_breakpoint
;
5845 scope_breakpoint
->related_breakpoint
= b
;
5848 value_free_to_mark (mark
);
5852 /* Return count of locations need to be watched and can be handled
5853 in hardware. If the watchpoint can not be handled
5854 in hardware return zero. */
5857 can_use_hardware_watchpoint (struct value
*v
)
5859 int found_memory_cnt
= 0;
5860 struct value
*head
= v
;
5862 /* Did the user specifically forbid us to use hardware watchpoints? */
5863 if (!can_use_hw_watchpoints
)
5866 /* Make sure that the value of the expression depends only upon
5867 memory contents, and values computed from them within GDB. If we
5868 find any register references or function calls, we can't use a
5869 hardware watchpoint.
5871 The idea here is that evaluating an expression generates a series
5872 of values, one holding the value of every subexpression. (The
5873 expression a*b+c has five subexpressions: a, b, a*b, c, and
5874 a*b+c.) GDB's values hold almost enough information to establish
5875 the criteria given above --- they identify memory lvalues,
5876 register lvalues, computed values, etcetera. So we can evaluate
5877 the expression, and then scan the chain of values that leaves
5878 behind to decide whether we can detect any possible change to the
5879 expression's final value using only hardware watchpoints.
5881 However, I don't think that the values returned by inferior
5882 function calls are special in any way. So this function may not
5883 notice that an expression involving an inferior function call
5884 can't be watched with hardware watchpoints. FIXME. */
5885 for (; v
; v
= value_next (v
))
5887 if (VALUE_LVAL (v
) == lval_memory
)
5890 /* A lazy memory lvalue is one that GDB never needed to fetch;
5891 we either just used its address (e.g., `a' in `a.b') or
5892 we never needed it at all (e.g., `a' in `a,b'). */
5896 /* Ahh, memory we actually used! Check if we can cover
5897 it with hardware watchpoints. */
5898 struct type
*vtype
= check_typedef (value_type (v
));
5900 /* We only watch structs and arrays if user asked for it
5901 explicitly, never if they just happen to appear in a
5902 middle of some value chain. */
5904 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5905 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5907 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
5908 int len
= TYPE_LENGTH (value_type (v
));
5910 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5917 else if (VALUE_LVAL (v
) != not_lval
5918 && deprecated_value_modifiable (v
) == 0)
5919 return 0; /* ??? What does this represent? */
5920 else if (VALUE_LVAL (v
) == lval_register
)
5921 return 0; /* cannot watch a register with a HW watchpoint */
5924 /* The expression itself looks suitable for using a hardware
5925 watchpoint, but give the target machine a chance to reject it. */
5926 return found_memory_cnt
;
5930 watch_command_wrapper (char *arg
, int from_tty
)
5932 watch_command (arg
, from_tty
);
5936 watch_command (char *arg
, int from_tty
)
5938 watch_command_1 (arg
, hw_write
, from_tty
);
5942 rwatch_command_wrapper (char *arg
, int from_tty
)
5944 rwatch_command (arg
, from_tty
);
5948 rwatch_command (char *arg
, int from_tty
)
5950 watch_command_1 (arg
, hw_read
, from_tty
);
5954 awatch_command_wrapper (char *arg
, int from_tty
)
5956 awatch_command (arg
, from_tty
);
5960 awatch_command (char *arg
, int from_tty
)
5962 watch_command_1 (arg
, hw_access
, from_tty
);
5966 /* Helper routines for the until_command routine in infcmd.c. Here
5967 because it uses the mechanisms of breakpoints. */
5969 /* This function is called by fetch_inferior_event via the
5970 cmd_continuation pointer, to complete the until command. It takes
5971 care of cleaning up the temporary breakpoints set up by the until
5974 until_break_command_continuation (struct continuation_arg
*arg
)
5976 struct cleanup
*cleanups
;
5978 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
5979 do_exec_cleanups (cleanups
);
5983 until_break_command (char *arg
, int from_tty
, int anywhere
)
5985 struct symtabs_and_lines sals
;
5986 struct symtab_and_line sal
;
5987 struct frame_info
*frame
= get_selected_frame (NULL
);
5988 struct frame_info
*prev_frame
= get_prev_frame (frame
);
5989 struct breakpoint
*breakpoint
;
5990 struct cleanup
*old_chain
;
5991 struct continuation_arg
*arg1
;
5994 clear_proceed_status ();
5996 /* Set a breakpoint where the user wants it and at return from
5999 if (default_breakpoint_valid
)
6000 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6001 default_breakpoint_line
, (char ***) NULL
, NULL
);
6003 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6004 0, (char ***) NULL
, NULL
);
6006 if (sals
.nelts
!= 1)
6007 error (_("Couldn't get information on specified line."));
6010 xfree (sals
.sals
); /* malloc'd, so freed */
6013 error (_("Junk at end of arguments."));
6015 resolve_sal_pc (&sal
);
6018 /* If the user told us to continue until a specified location,
6019 we don't specify a frame at which we need to stop. */
6020 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6022 /* Otherwise, specify the current frame, because we want to stop only
6023 at the very same frame. */
6024 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6027 if (!target_can_async_p ())
6028 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6030 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
6032 /* If we are running asynchronously, and the target supports async
6033 execution, we are not waiting for the target to stop, in the call
6034 tp proceed, below. This means that we cannot delete the
6035 brekpoints until the target has actually stopped. The only place
6036 where we get a chance to do that is in fetch_inferior_event, so
6037 we must set things up for that. */
6039 if (target_can_async_p ())
6041 /* In this case the arg for the continuation is just the point
6042 in the exec_cleanups chain from where to start doing
6043 cleanups, because all the continuation does is the cleanups in
6044 the exec_cleanup_chain. */
6046 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6048 arg1
->data
.pointer
= old_chain
;
6050 add_continuation (until_break_command_continuation
, arg1
);
6053 /* Keep within the current frame, or in frames called by the current
6057 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6058 sal
.pc
= get_frame_pc (prev_frame
);
6059 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6061 if (!target_can_async_p ())
6062 make_cleanup_delete_breakpoint (breakpoint
);
6064 make_exec_cleanup_delete_breakpoint (breakpoint
);
6067 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6068 /* Do the cleanups now, anly if we are not running asynchronously,
6069 of if we are, but the target is still synchronous. */
6070 if (!target_can_async_p ())
6071 do_cleanups (old_chain
);
6075 ep_skip_leading_whitespace (char **s
)
6077 if ((s
== NULL
) || (*s
== NULL
))
6079 while (isspace (**s
))
6083 /* This function examines a string, and attempts to find a token
6084 that might be an event name in the leading characters. If a
6085 possible match is found, a pointer to the last character of
6086 the token is returned. Else, NULL is returned. */
6089 ep_find_event_name_end (char *arg
)
6092 char *event_name_end
= NULL
;
6094 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6098 /* We break out of the loop when we find a token delimiter.
6099 Basically, we're looking for alphanumerics and underscores;
6100 anything else delimites the token. */
6103 if (!isalnum (*s
) && (*s
!= '_'))
6109 return event_name_end
;
6113 /* This function attempts to parse an optional "if <cond>" clause
6114 from the arg string. If one is not found, it returns NULL.
6116 Else, it returns a pointer to the condition string. (It does not
6117 attempt to evaluate the string against a particular block.) And,
6118 it updates arg to point to the first character following the parsed
6119 if clause in the arg string. */
6122 ep_parse_optional_if_clause (char **arg
)
6126 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6129 /* Skip the "if" keyword. */
6132 /* Skip any extra leading whitespace, and record the start of the
6133 condition string. */
6134 ep_skip_leading_whitespace (arg
);
6137 /* Assume that the condition occupies the remainder of the arg string. */
6138 (*arg
) += strlen (cond_string
);
6143 /* This function attempts to parse an optional filename from the arg
6144 string. If one is not found, it returns NULL.
6146 Else, it returns a pointer to the parsed filename. (This function
6147 makes no attempt to verify that a file of that name exists, or is
6148 accessible.) And, it updates arg to point to the first character
6149 following the parsed filename in the arg string.
6151 Note that clients needing to preserve the returned filename for
6152 future access should copy it to their own buffers. */
6154 ep_parse_optional_filename (char **arg
)
6156 static char filename
[1024];
6161 if ((*arg_p
== '\0') || isspace (*arg_p
))
6179 /* Commands to deal with catching events, such as signals, exceptions,
6180 process start/exit, etc. */
6184 catch_fork
, catch_vfork
6189 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6192 char *cond_string
= NULL
;
6194 ep_skip_leading_whitespace (&arg
);
6196 /* The allowed syntax is:
6198 catch [v]fork if <cond>
6200 First, check if there's an if clause. */
6201 cond_string
= ep_parse_optional_if_clause (&arg
);
6203 if ((*arg
!= '\0') && !isspace (*arg
))
6204 error (_("Junk at end of arguments."));
6206 /* If this target supports it, create a fork or vfork catchpoint
6207 and enable reporting of such events. */
6211 create_fork_event_catchpoint (tempflag
, cond_string
);
6214 create_vfork_event_catchpoint (tempflag
, cond_string
);
6217 error (_("unsupported or unknown fork kind; cannot catch it"));
6223 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6225 char *cond_string
= NULL
;
6227 ep_skip_leading_whitespace (&arg
);
6229 /* The allowed syntax is:
6231 catch exec if <cond>
6233 First, check if there's an if clause. */
6234 cond_string
= ep_parse_optional_if_clause (&arg
);
6236 if ((*arg
!= '\0') && !isspace (*arg
))
6237 error (_("Junk at end of arguments."));
6239 /* If this target supports it, create an exec catchpoint
6240 and enable reporting of such events. */
6241 create_exec_event_catchpoint (tempflag
, cond_string
);
6245 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6247 char *dll_pathname
= NULL
;
6248 char *cond_string
= NULL
;
6250 ep_skip_leading_whitespace (&arg
);
6252 /* The allowed syntax is:
6254 catch load if <cond>
6255 catch load <filename>
6256 catch load <filename> if <cond>
6258 The user is not allowed to specify the <filename> after an
6261 We'll ignore the pathological case of a file named "if".
6263 First, check if there's an if clause. If so, then there
6264 cannot be a filename. */
6265 cond_string
= ep_parse_optional_if_clause (&arg
);
6267 /* If there was an if clause, then there cannot be a filename.
6268 Else, there might be a filename and an if clause. */
6269 if (cond_string
== NULL
)
6271 dll_pathname
= ep_parse_optional_filename (&arg
);
6272 ep_skip_leading_whitespace (&arg
);
6273 cond_string
= ep_parse_optional_if_clause (&arg
);
6276 if ((*arg
!= '\0') && !isspace (*arg
))
6277 error (_("Junk at end of arguments."));
6279 /* Create a load breakpoint that only triggers when a load of
6280 the specified dll (or any dll, if no pathname was specified)
6282 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6283 dll_pathname
, cond_string
);
6287 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6289 char *dll_pathname
= NULL
;
6290 char *cond_string
= NULL
;
6292 ep_skip_leading_whitespace (&arg
);
6294 /* The allowed syntax is:
6296 catch unload if <cond>
6297 catch unload <filename>
6298 catch unload <filename> if <cond>
6300 The user is not allowed to specify the <filename> after an
6303 We'll ignore the pathological case of a file named "if".
6305 First, check if there's an if clause. If so, then there
6306 cannot be a filename. */
6307 cond_string
= ep_parse_optional_if_clause (&arg
);
6309 /* If there was an if clause, then there cannot be a filename.
6310 Else, there might be a filename and an if clause. */
6311 if (cond_string
== NULL
)
6313 dll_pathname
= ep_parse_optional_filename (&arg
);
6314 ep_skip_leading_whitespace (&arg
);
6315 cond_string
= ep_parse_optional_if_clause (&arg
);
6318 if ((*arg
!= '\0') && !isspace (*arg
))
6319 error (_("Junk at end of arguments."));
6321 /* Create an unload breakpoint that only triggers when an unload of
6322 the specified dll (or any dll, if no pathname was specified)
6324 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6325 dll_pathname
, cond_string
);
6328 static enum print_stop_action
6329 print_exception_catchpoint (struct breakpoint
*b
)
6331 annotate_catchpoint (b
->number
);
6333 if (strstr (b
->addr_string
, "throw") != NULL
)
6334 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6337 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6340 return PRINT_SRC_AND_LOC
;
6344 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6349 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6352 *last_addr
= b
->loc
->address
;
6353 if (strstr (b
->addr_string
, "throw") != NULL
)
6354 ui_out_field_string (uiout
, "what", "exception throw");
6356 ui_out_field_string (uiout
, "what", "exception catch");
6360 print_mention_exception_catchpoint (struct breakpoint
*b
)
6362 if (strstr (b
->addr_string
, "throw") != NULL
)
6363 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6365 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6368 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6369 print_exception_catchpoint
,
6370 print_one_exception_catchpoint
,
6371 print_mention_exception_catchpoint
6375 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6376 enum exception_event_kind ex_event
, int from_tty
)
6378 char *trigger_func_name
, *nameptr
;
6379 struct symtabs_and_lines sals
;
6380 struct breakpoint
*b
;
6382 if (ex_event
== EX_EVENT_CATCH
)
6383 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6385 trigger_func_name
= xstrdup ("__cxa_throw");
6387 nameptr
= trigger_func_name
;
6388 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6389 if (sals
.nelts
== 0)
6391 xfree (trigger_func_name
);
6395 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6396 set_breakpoint_count (breakpoint_count
+ 1);
6397 b
->number
= breakpoint_count
;
6398 b
->cond_string
= (cond_string
== NULL
) ?
6399 NULL
: savestring (cond_string
, strlen (cond_string
));
6401 b
->addr_string
= trigger_func_name
;
6402 b
->enable_state
= bp_enabled
;
6403 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6404 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6411 /* Deal with "catch catch" and "catch throw" commands */
6414 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6415 int tempflag
, int from_tty
)
6417 char *cond_string
= NULL
;
6418 struct symtab_and_line
*sal
= NULL
;
6420 ep_skip_leading_whitespace (&arg
);
6422 cond_string
= ep_parse_optional_if_clause (&arg
);
6424 if ((*arg
!= '\0') && !isspace (*arg
))
6425 error (_("Junk at end of arguments."));
6427 if ((ex_event
!= EX_EVENT_THROW
) &&
6428 (ex_event
!= EX_EVENT_CATCH
))
6429 error (_("Unsupported or unknown exception event; cannot catch it"));
6431 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6434 warning (_("Unsupported with this platform/compiler combination."));
6437 /* Create a breakpoint struct for Ada exception catchpoints. */
6440 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6444 struct expression
*cond
,
6445 struct breakpoint_ops
*ops
,
6449 struct breakpoint
*b
;
6453 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6454 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6455 version for exception catchpoints, because two catchpoints
6456 used for different exception names will use the same address.
6457 In this case, a "breakpoint ... also set at..." warning is
6458 unproductive. Besides. the warning phrasing is also a bit
6459 inapropriate, we should use the word catchpoint, and tell
6460 the user what type of catchpoint it is. The above is good
6461 enough for now, though. */
6464 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6465 set_breakpoint_count (breakpoint_count
+ 1);
6467 b
->enable_state
= bp_enabled
;
6468 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6469 b
->number
= breakpoint_count
;
6470 b
->ignore_count
= 0;
6471 b
->loc
->cond
= cond
;
6472 b
->addr_string
= addr_string
;
6473 b
->language
= language_ada
;
6474 b
->cond_string
= cond_string
;
6475 b
->exp_string
= exp_string
;
6482 /* Implement the "catch exception" command. */
6485 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6487 struct symtab_and_line sal
;
6489 char *addr_string
= NULL
;
6490 char *exp_string
= NULL
;
6491 char *cond_string
= NULL
;
6492 struct expression
*cond
= NULL
;
6493 struct breakpoint_ops
*ops
= NULL
;
6495 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6496 &cond_string
, &cond
, &ops
);
6497 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6498 cond_string
, cond
, ops
, tempflag
,
6502 /* Implement the "catch assert" command. */
6505 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6507 struct symtab_and_line sal
;
6508 char *addr_string
= NULL
;
6509 struct breakpoint_ops
*ops
= NULL
;
6511 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6512 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6513 tempflag
, from_tty
);
6517 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6520 /* The first argument may be an event name, such as "start" or "load".
6521 If so, then handle it as such. If it doesn't match an event name,
6522 then attempt to interpret it as an exception name. (This latter is
6523 the v4.16-and-earlier GDB meaning of the "catch" command.)
6525 First, try to find the bounds of what might be an event name. */
6526 char *arg1_start
= arg
;
6530 if (arg1_start
== NULL
)
6532 /* Old behaviour was to use pre-v-4.16 syntax */
6533 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6535 /* Now, this is not allowed */
6536 error (_("Catch requires an event name."));
6539 arg1_end
= ep_find_event_name_end (arg1_start
);
6540 if (arg1_end
== NULL
)
6541 error (_("catch requires an event"));
6542 arg1_length
= arg1_end
+ 1 - arg1_start
;
6544 /* Try to match what we found against known event names. */
6545 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6547 error (_("Catch of signal not yet implemented"));
6549 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6551 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6552 tempflag
, from_tty
);
6554 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6556 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6557 tempflag
, from_tty
);
6559 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6561 error (_("Catch of thread_start not yet implemented"));
6563 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6565 error (_("Catch of thread_exit not yet implemented"));
6567 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6569 error (_("Catch of thread_join not yet implemented"));
6571 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6573 error (_("Catch of start not yet implemented"));
6575 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6577 error (_("Catch of exit not yet implemented"));
6579 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6581 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6583 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6585 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6587 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6589 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6591 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6593 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6595 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6597 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6599 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6601 error (_("Catch of stop not yet implemented"));
6603 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6605 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6608 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6610 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6613 /* This doesn't appear to be an event name */
6617 /* Pre-v.4.16 behaviour was to treat the argument
6618 as the name of an exception */
6619 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6620 /* Now this is not allowed */
6621 error (_("Unknown event kind specified for catch"));
6627 catch_command (char *arg
, int from_tty
)
6629 catch_command_1 (arg
, 0, from_tty
);
6634 tcatch_command (char *arg
, int from_tty
)
6636 catch_command_1 (arg
, 1, from_tty
);
6639 /* Delete breakpoints by address or line. */
6642 clear_command (char *arg
, int from_tty
)
6644 struct breakpoint
*b
;
6645 VEC(breakpoint_p
) *found
= 0;
6648 struct symtabs_and_lines sals
;
6649 struct symtab_and_line sal
;
6654 sals
= decode_line_spec (arg
, 1);
6659 sals
.sals
= (struct symtab_and_line
*)
6660 xmalloc (sizeof (struct symtab_and_line
));
6661 make_cleanup (xfree
, sals
.sals
);
6662 init_sal (&sal
); /* initialize to zeroes */
6663 sal
.line
= default_breakpoint_line
;
6664 sal
.symtab
= default_breakpoint_symtab
;
6665 sal
.pc
= default_breakpoint_address
;
6666 if (sal
.symtab
== 0)
6667 error (_("No source file specified."));
6675 /* We don't call resolve_sal_pc here. That's not
6676 as bad as it seems, because all existing breakpoints
6677 typically have both file/line and pc set. So, if
6678 clear is given file/line, we can match this to existing
6679 breakpoint without obtaining pc at all.
6681 We only support clearing given the address explicitly
6682 present in breakpoint table. Say, we've set breakpoint
6683 at file:line. There were several PC values for that file:line,
6684 due to optimization, all in one block.
6685 We've picked one PC value. If "clear" is issued with another
6686 PC corresponding to the same file:line, the breakpoint won't
6687 be cleared. We probably can still clear the breakpoint, but
6688 since the other PC value is never presented to user, user
6689 can only find it by guessing, and it does not seem important
6692 /* For each line spec given, delete bps which correspond
6693 to it. Do it in two passes, solely to preserve the current
6694 behavior that from_tty is forced true if we delete more than
6698 for (i
= 0; i
< sals
.nelts
; i
++)
6700 /* If exact pc given, clear bpts at that pc.
6701 If line given (pc == 0), clear all bpts on specified line.
6702 If defaulting, clear all bpts on default line
6705 defaulting sal.pc != 0 tests to do
6710 1 0 <can't happen> */
6714 /* Find all matching breakpoints and add them to
6719 /* Are we going to delete b? */
6720 if (b
->type
!= bp_none
6721 && b
->type
!= bp_watchpoint
6722 && b
->type
!= bp_hardware_watchpoint
6723 && b
->type
!= bp_read_watchpoint
6724 && b
->type
!= bp_access_watchpoint
)
6726 struct bp_location
*loc
= b
->loc
;
6727 for (; loc
; loc
= loc
->next
)
6729 int pc_match
= sal
.pc
6730 && (loc
->address
== sal
.pc
)
6731 && (!section_is_overlay (loc
->section
)
6732 || loc
->section
== sal
.section
);
6733 int line_match
= ((default_match
|| (0 == sal
.pc
))
6734 && b
->source_file
!= NULL
6735 && sal
.symtab
!= NULL
6736 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6737 && b
->line_number
== sal
.line
);
6738 if (pc_match
|| line_match
)
6747 VEC_safe_push(breakpoint_p
, found
, b
);
6750 /* Now go thru the 'found' chain and delete them. */
6751 if (VEC_empty(breakpoint_p
, found
))
6754 error (_("No breakpoint at %s."), arg
);
6756 error (_("No breakpoint at this line."));
6759 if (VEC_length(breakpoint_p
, found
) > 1)
6760 from_tty
= 1; /* Always report if deleted more than one */
6763 if (VEC_length(breakpoint_p
, found
) == 1)
6764 printf_unfiltered (_("Deleted breakpoint "));
6766 printf_unfiltered (_("Deleted breakpoints "));
6768 breakpoints_changed ();
6770 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6773 printf_unfiltered ("%d ", b
->number
);
6774 delete_breakpoint (b
);
6777 putchar_unfiltered ('\n');
6780 /* Delete breakpoint in BS if they are `delete' breakpoints and
6781 all breakpoints that are marked for deletion, whether hit or not.
6782 This is called after any breakpoint is hit, or after errors. */
6785 breakpoint_auto_delete (bpstat bs
)
6787 struct breakpoint
*b
, *temp
;
6789 for (; bs
; bs
= bs
->next
)
6790 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
->disposition
== disp_del
6792 delete_breakpoint (bs
->breakpoint_at
->owner
);
6794 ALL_BREAKPOINTS_SAFE (b
, temp
)
6796 if (b
->disposition
== disp_del_at_next_stop
)
6797 delete_breakpoint (b
);
6801 /* Remove locations of breakpoint BPT from
6802 the global list of breakpoint locations. */
6805 unlink_locations_from_global_list (struct breakpoint
*bpt
)
6807 /* This code assumes that the locations
6808 of a breakpoint are found in the global list
6809 in the same order, but not necessary adjacent. */
6810 struct bp_location
**tmp
= &bp_location_chain
;
6811 struct bp_location
*here
= bpt
->loc
;
6816 for (; *tmp
&& here
;)
6820 *tmp
= here
->global_next
;
6825 tmp
= &((*tmp
)->global_next
);
6830 /* Delete a breakpoint and clean up all traces of it in the data
6834 delete_breakpoint (struct breakpoint
*bpt
)
6836 struct breakpoint
*b
;
6838 struct bp_location
*loc
;
6840 gdb_assert (bpt
!= NULL
);
6842 /* Has this bp already been deleted? This can happen because multiple
6843 lists can hold pointers to bp's. bpstat lists are especial culprits.
6845 One example of this happening is a watchpoint's scope bp. When the
6846 scope bp triggers, we notice that the watchpoint is out of scope, and
6847 delete it. We also delete its scope bp. But the scope bp is marked
6848 "auto-deleting", and is already on a bpstat. That bpstat is then
6849 checked for auto-deleting bp's, which are deleted.
6851 A real solution to this problem might involve reference counts in bp's,
6852 and/or giving them pointers back to their referencing bpstat's, and
6853 teaching delete_breakpoint to only free a bp's storage when no more
6854 references were extent. A cheaper bandaid was chosen. */
6855 if (bpt
->type
== bp_none
)
6858 if (deprecated_delete_breakpoint_hook
)
6859 deprecated_delete_breakpoint_hook (bpt
);
6860 breakpoint_delete_event (bpt
->number
);
6862 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
6865 remove_breakpoint (loc
, mark_inserted
);
6870 if (loc
->function_name
)
6871 xfree (loc
->function_name
);
6874 if (breakpoint_chain
== bpt
)
6875 breakpoint_chain
= bpt
->next
;
6880 b
->next
= bpt
->next
;
6884 unlink_locations_from_global_list (bpt
);
6886 check_duplicates (bpt
);
6888 if (bpt
->type
!= bp_hardware_watchpoint
6889 && bpt
->type
!= bp_read_watchpoint
6890 && bpt
->type
!= bp_access_watchpoint
6891 && bpt
->type
!= bp_catch_fork
6892 && bpt
->type
!= bp_catch_vfork
6893 && bpt
->type
!= bp_catch_exec
)
6894 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
6896 /* If this breakpoint location was inserted, and there is
6897 another breakpoint at the same address, we need to
6898 insert the other breakpoint. */
6901 struct bp_location
*loc2
;
6902 ALL_BP_LOCATIONS (loc2
)
6903 if (loc2
->address
== loc
->address
6904 && loc2
->section
== loc
->section
6906 && loc2
->owner
->enable_state
!= bp_disabled
6908 && !loc2
->shlib_disabled
6909 && loc2
->owner
->enable_state
!= bp_call_disabled
)
6913 /* We should never reach this point if there is a permanent
6914 breakpoint at the same address as the one being deleted.
6915 If there is a permanent breakpoint somewhere, it should
6916 always be the only one inserted. */
6917 if (loc2
->owner
->enable_state
== bp_permanent
)
6918 internal_error (__FILE__
, __LINE__
,
6919 _("another breakpoint was inserted on top of "
6920 "a permanent breakpoint"));
6922 memset (&loc2
->target_info
, 0, sizeof (loc2
->target_info
));
6923 loc2
->target_info
.placed_address
= loc2
->address
;
6924 if (b
->type
== bp_hardware_breakpoint
)
6925 val
= target_insert_hw_breakpoint (&loc2
->target_info
);
6927 val
= target_insert_breakpoint (&loc2
->target_info
);
6929 /* If there was an error in the insert, print a message, then stop execution. */
6932 struct ui_file
*tmp_error_stream
= mem_fileopen ();
6933 make_cleanup_ui_file_delete (tmp_error_stream
);
6936 if (b
->type
== bp_hardware_breakpoint
)
6938 fprintf_unfiltered (tmp_error_stream
,
6939 "Cannot insert hardware breakpoint %d.\n"
6940 "You may have requested too many hardware breakpoints.\n",
6945 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
6946 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
6947 fputs_filtered (paddress (loc2
->address
),
6949 fprintf_filtered (tmp_error_stream
, ": %s.\n",
6950 safe_strerror (val
));
6953 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
6954 target_terminal_ours_for_output ();
6955 error_stream(tmp_error_stream
);
6963 free_command_lines (&bpt
->commands
);
6964 if (bpt
->cond_string
!= NULL
)
6965 xfree (bpt
->cond_string
);
6966 if (bpt
->addr_string
!= NULL
)
6967 xfree (bpt
->addr_string
);
6968 if (bpt
->exp
!= NULL
)
6970 if (bpt
->exp_string
!= NULL
)
6971 xfree (bpt
->exp_string
);
6972 if (bpt
->val
!= NULL
)
6973 value_free (bpt
->val
);
6974 if (bpt
->source_file
!= NULL
)
6975 xfree (bpt
->source_file
);
6976 if (bpt
->dll_pathname
!= NULL
)
6977 xfree (bpt
->dll_pathname
);
6978 if (bpt
->triggered_dll_pathname
!= NULL
)
6979 xfree (bpt
->triggered_dll_pathname
);
6980 if (bpt
->exec_pathname
!= NULL
)
6981 xfree (bpt
->exec_pathname
);
6983 /* Be sure no bpstat's are pointing at it after it's been freed. */
6984 /* FIXME, how can we find all bpstat's?
6985 We just check stop_bpstat for now. Note that we cannot just
6986 remove bpstats pointing at bpt from the stop_bpstat list
6987 entirely, as breakpoint commands are associated with the bpstat;
6988 if we remove it here, then the later call to
6989 bpstat_do_actions (&stop_bpstat);
6990 in event-top.c won't do anything, and temporary breakpoints
6991 with commands won't work. */
6992 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
6993 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
6995 bs
->breakpoint_at
= NULL
;
6997 /* bs->commands will be freed later. */
6999 /* On the chance that someone will soon try again to delete this same
7000 bp, we mark it as deleted before freeing its storage. */
7001 bpt
->type
= bp_none
;
7003 for (loc
= bpt
->loc
; loc
;)
7005 struct bp_location
*loc_next
= loc
->next
;
7013 do_delete_breakpoint_cleanup (void *b
)
7015 delete_breakpoint (b
);
7019 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7021 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7025 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
7027 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
7031 delete_command (char *arg
, int from_tty
)
7033 struct breakpoint
*b
, *temp
;
7039 int breaks_to_delete
= 0;
7041 /* Delete all breakpoints if no argument.
7042 Do not delete internal or call-dummy breakpoints, these
7043 have to be deleted with an explicit breakpoint number argument. */
7046 if (b
->type
!= bp_call_dummy
&&
7047 b
->type
!= bp_shlib_event
&&
7048 b
->type
!= bp_thread_event
&&
7049 b
->type
!= bp_overlay_event
&&
7052 breaks_to_delete
= 1;
7057 /* Ask user only if there are some breakpoints to delete. */
7059 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7061 ALL_BREAKPOINTS_SAFE (b
, temp
)
7063 if (b
->type
!= bp_call_dummy
&&
7064 b
->type
!= bp_shlib_event
&&
7065 b
->type
!= bp_thread_event
&&
7066 b
->type
!= bp_overlay_event
&&
7068 delete_breakpoint (b
);
7073 map_breakpoint_numbers (arg
, delete_breakpoint
);
7077 all_locations_are_pending (struct bp_location
*loc
)
7079 for (; loc
; loc
= loc
->next
)
7080 if (!loc
->shlib_disabled
)
7085 /* Subroutine of update_breakpoint_locations to simplify it.
7086 Return non-zero if multiple fns in list LOC have the same name.
7087 Null names are ignored. */
7090 ambiguous_names_p (struct bp_location
*loc
)
7092 struct bp_location
*l
;
7093 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7094 (int (*) (const void *, const void *)) streq
,
7095 NULL
, xcalloc
, xfree
);
7097 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7100 const char *name
= l
->function_name
;
7102 /* Allow for some names to be NULL, ignore them. */
7106 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7108 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7123 update_breakpoint_locations (struct breakpoint
*b
,
7124 struct symtabs_and_lines sals
)
7128 struct bp_location
*existing_locations
= b
->loc
;
7130 /* If there's no new locations, and all existing locations
7131 are pending, don't do anything. This optimizes
7132 the common case where all locations are in the same
7133 shared library, that was unloaded. We'd like to
7134 retain the location, so that when the library
7135 is loaded again, we don't loose the enabled/disabled
7136 status of the individual locations. */
7137 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7140 unlink_locations_from_global_list (b
);
7143 for (i
= 0; i
< sals
.nelts
; ++i
)
7145 struct bp_location
*new_loc
=
7146 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7148 /* Reparse conditions, they might contain references to the
7150 if (b
->cond_string
!= NULL
)
7152 struct gdb_exception e
;
7155 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7157 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7162 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7163 b
->number
, e
.message
);
7164 new_loc
->enabled
= 0;
7168 if (b
->source_file
!= NULL
)
7169 xfree (b
->source_file
);
7170 if (sals
.sals
[i
].symtab
== NULL
)
7171 b
->source_file
= NULL
;
7174 savestring (sals
.sals
[i
].symtab
->filename
,
7175 strlen (sals
.sals
[i
].symtab
->filename
));
7177 if (b
->line_number
== 0)
7178 b
->line_number
= sals
.sals
[i
].line
;
7181 /* If possible, carry over 'disable' status from existing breakpoints. */
7183 struct bp_location
*e
= existing_locations
;
7184 /* If there are multiple breakpoints with the same function name,
7185 e.g. for inline functions, comparing function names won't work.
7186 Instead compare pc addresses; this is just a heuristic as things
7187 may have moved, but in practice it gives the correct answer
7188 often enough until a better solution is found. */
7189 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7191 for (; e
; e
= e
->next
)
7193 if (!e
->enabled
&& e
->function_name
)
7195 struct bp_location
*l
= b
->loc
;
7196 if (have_ambiguous_names
)
7198 for (; l
; l
= l
->next
)
7199 if (e
->address
== l
->address
)
7207 for (; l
; l
= l
->next
)
7208 if (l
->function_name
7209 && strcmp (e
->function_name
, l
->function_name
) == 0)
7219 while (existing_locations
)
7221 struct bp_location
*next
= existing_locations
->next
;
7222 free_bp_location (existing_locations
);
7223 existing_locations
= next
;
7228 /* Reset a breakpoint given it's struct breakpoint * BINT.
7229 The value we return ends up being the return value from catch_errors.
7230 Unused in this case. */
7233 breakpoint_re_set_one (void *bint
)
7235 /* get past catch_errs */
7236 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7240 int *not_found_ptr
= ¬_found
;
7241 struct symtabs_and_lines sals
= {};
7242 struct symtabs_and_lines expanded
;
7244 enum enable_state save_enable
;
7245 struct gdb_exception e
;
7251 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7255 case bp_hardware_breakpoint
:
7257 case bp_catch_unload
:
7258 if (b
->addr_string
== NULL
)
7260 /* Anything without a string can't be re-set. */
7261 delete_breakpoint (b
);
7265 set_language (b
->language
);
7266 input_radix
= b
->input_radix
;
7268 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7270 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7275 int not_found_and_ok
= 0;
7276 /* For pending breakpoints, it's expected that parsing
7277 will fail until the right shared library is loaded.
7278 User has already told to create pending breakpoints and
7279 don't need extra messages. If breakpoint is in bp_shlib_disabled
7280 state, then user already saw the message about that breakpoint
7281 being disabled, and don't want to see more errors. */
7283 && (b
->condition_not_parsed
7284 || (b
->loc
&& b
->loc
->shlib_disabled
)
7285 || b
->enable_state
== bp_disabled
))
7286 not_found_and_ok
= 1;
7288 if (!not_found_and_ok
)
7290 /* We surely don't want to warn about the same breakpoint
7291 10 times. One solution, implemented here, is disable
7292 the breakpoint on error. Another solution would be to
7293 have separate 'warning emitted' flag. Since this
7294 happens only when a binary has changed, I don't know
7295 which approach is better. */
7296 b
->enable_state
= bp_disabled
;
7297 throw_exception (e
);
7304 gdb_assert (sals
.nelts
== 1);
7305 resolve_sal_pc (&sals
.sals
[0]);
7306 if (b
->condition_not_parsed
&& s
&& s
[0])
7308 char *cond_string
= 0;
7310 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7311 &cond_string
, &thread
);
7313 b
->cond_string
= cond_string
;
7315 b
->condition_not_parsed
= 0;
7317 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7318 update_breakpoint_locations (b
, expanded
);
7320 /* Now that this is re-enabled, check_duplicates
7322 check_duplicates (b
);
7328 case bp_hardware_watchpoint
:
7329 case bp_read_watchpoint
:
7330 case bp_access_watchpoint
:
7331 /* Watchpoint can be either on expression using entirely global variables,
7332 or it can be on local variables.
7334 Watchpoints of the first kind are never auto-deleted, and even persist
7335 across program restarts. Since they can use variables from shared
7336 libraries, we need to reparse expression as libraries are loaded
7339 Watchpoints on local variables can also change meaning as result
7340 of solib event. For example, if a watchpoint uses both a local and
7341 a global variables in expression, it's a local watchpoint, but
7342 unloading of a shared library will make the expression invalid.
7343 This is not a very common use case, but we still re-evaluate
7344 expression, to avoid surprises to the user.
7346 Note that for local watchpoints, we re-evaluate it only if
7347 watchpoints frame id is still valid. If it's not, it means
7348 the watchpoint is out of scope and will be deleted soon. In fact,
7349 I'm not sure we'll ever be called in this case.
7351 If a local watchpoint's frame id is still valid, then
7352 b->exp_valid_block is likewise valid, and we can safely use it.
7354 Don't do anything about disabled watchpoints, since they will
7355 be reevaluated again when enabled. */
7356 update_watchpoint (b
, 1 /* reparse */);
7358 /* We needn't really do anything to reset these, since the mask
7359 that requests them is unaffected by e.g., new libraries being
7362 case bp_catch_vfork
:
7367 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7369 /* Delete longjmp and overlay event breakpoints; they will be
7370 reset later by breakpoint_re_set. */
7372 case bp_longjmp_resume
:
7373 case bp_overlay_event
:
7374 delete_breakpoint (b
);
7377 /* This breakpoint is special, it's set up when the inferior
7378 starts and we really don't want to touch it. */
7379 case bp_shlib_event
:
7381 /* Like bp_shlib_event, this breakpoint type is special.
7382 Once it is set up, we do not want to touch it. */
7383 case bp_thread_event
:
7385 /* Keep temporary breakpoints, which can be encountered when we step
7386 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7387 Otherwise these should have been blown away via the cleanup chain
7388 or by breakpoint_init_inferior when we rerun the executable. */
7391 case bp_watchpoint_scope
:
7393 case bp_step_resume
:
7400 /* Re-set all breakpoints after symbols have been re-loaded. */
7402 breakpoint_re_set (void)
7404 struct breakpoint
*b
, *temp
;
7405 enum language save_language
;
7406 int save_input_radix
;
7408 save_language
= current_language
->la_language
;
7409 save_input_radix
= input_radix
;
7410 ALL_BREAKPOINTS_SAFE (b
, temp
)
7412 /* Format possible error msg */
7413 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7415 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7416 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7417 do_cleanups (cleanups
);
7419 set_language (save_language
);
7420 input_radix
= save_input_radix
;
7422 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
7424 create_longjmp_breakpoint ("longjmp");
7425 create_longjmp_breakpoint ("_longjmp");
7426 create_longjmp_breakpoint ("siglongjmp");
7427 create_longjmp_breakpoint ("_siglongjmp");
7428 create_longjmp_breakpoint (NULL
);
7431 create_overlay_event_breakpoint ("_ovly_debug_event");
7434 /* Reset the thread number of this breakpoint:
7436 - If the breakpoint is for all threads, leave it as-is.
7437 - Else, reset it to the current thread for inferior_ptid. */
7439 breakpoint_re_set_thread (struct breakpoint
*b
)
7441 if (b
->thread
!= -1)
7443 if (in_thread_list (inferior_ptid
))
7444 b
->thread
= pid_to_thread_id (inferior_ptid
);
7448 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7449 If from_tty is nonzero, it prints a message to that effect,
7450 which ends with a period (no newline). */
7453 set_ignore_count (int bptnum
, int count
, int from_tty
)
7455 struct breakpoint
*b
;
7461 if (b
->number
== bptnum
)
7463 b
->ignore_count
= count
;
7467 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7469 else if (count
== 1)
7470 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7473 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7476 breakpoints_changed ();
7477 breakpoint_modify_event (b
->number
);
7481 error (_("No breakpoint number %d."), bptnum
);
7484 /* Clear the ignore counts of all breakpoints. */
7486 breakpoint_clear_ignore_counts (void)
7488 struct breakpoint
*b
;
7491 b
->ignore_count
= 0;
7494 /* Command to set ignore-count of breakpoint N to COUNT. */
7497 ignore_command (char *args
, int from_tty
)
7503 error_no_arg (_("a breakpoint number"));
7505 num
= get_number (&p
);
7507 error (_("bad breakpoint number: '%s'"), args
);
7509 error (_("Second argument (specified ignore-count) is missing."));
7511 set_ignore_count (num
,
7512 longest_to_int (value_as_long (parse_and_eval (p
))),
7515 printf_filtered ("\n");
7518 /* Call FUNCTION on each of the breakpoints
7519 whose numbers are given in ARGS. */
7522 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7527 struct breakpoint
*b
, *tmp
;
7531 error_no_arg (_("one or more breakpoint numbers"));
7538 num
= get_number_or_range (&p1
);
7541 warning (_("bad breakpoint number at or near '%s'"), p
);
7545 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7546 if (b
->number
== num
)
7548 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7551 if (related_breakpoint
)
7552 function (related_breakpoint
);
7556 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7562 static struct bp_location
*
7563 find_location_by_number (char *number
)
7565 char *dot
= strchr (number
, '.');
7569 struct breakpoint
*b
;
7570 struct bp_location
*loc
;
7575 bp_num
= get_number_or_range (&p1
);
7577 error (_("Bad breakpoint number '%s'"), number
);
7580 if (b
->number
== bp_num
)
7585 if (!b
|| b
->number
!= bp_num
)
7586 error (_("Bad breakpoint number '%s'"), number
);
7589 loc_num
= get_number_or_range (&p1
);
7591 error (_("Bad breakpoint location number '%s'"), number
);
7595 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7598 error (_("Bad breakpoint location number '%s'"), dot
+1);
7604 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7605 If from_tty is nonzero, it prints a message to that effect,
7606 which ends with a period (no newline). */
7609 disable_breakpoint (struct breakpoint
*bpt
)
7611 /* Never disable a watchpoint scope breakpoint; we want to
7612 hit them when we leave scope so we can delete both the
7613 watchpoint and its scope breakpoint at that time. */
7614 if (bpt
->type
== bp_watchpoint_scope
)
7617 /* You can't disable permanent breakpoints. */
7618 if (bpt
->enable_state
== bp_permanent
)
7621 bpt
->enable_state
= bp_disabled
;
7623 check_duplicates (bpt
);
7625 if (deprecated_modify_breakpoint_hook
)
7626 deprecated_modify_breakpoint_hook (bpt
);
7627 breakpoint_modify_event (bpt
->number
);
7631 disable_command (char *args
, int from_tty
)
7633 struct breakpoint
*bpt
;
7635 ALL_BREAKPOINTS (bpt
)
7639 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7644 case bp_catch_unload
:
7646 case bp_catch_vfork
:
7648 case bp_hardware_breakpoint
:
7650 case bp_hardware_watchpoint
:
7651 case bp_read_watchpoint
:
7652 case bp_access_watchpoint
:
7653 disable_breakpoint (bpt
);
7657 else if (strchr (args
, '.'))
7659 struct bp_location
*loc
= find_location_by_number (args
);
7662 check_duplicates (loc
->owner
);
7665 map_breakpoint_numbers (args
, disable_breakpoint
);
7669 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7671 int target_resources_ok
, other_type_used
;
7674 if (bpt
->type
== bp_hardware_breakpoint
)
7677 i
= hw_breakpoint_used_count ();
7678 target_resources_ok
=
7679 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7681 if (target_resources_ok
== 0)
7682 error (_("No hardware breakpoint support in the target."));
7683 else if (target_resources_ok
< 0)
7684 error (_("Hardware breakpoints used exceeds limit."));
7687 if (bpt
->type
== bp_watchpoint
||
7688 bpt
->type
== bp_hardware_watchpoint
||
7689 bpt
->type
== bp_read_watchpoint
||
7690 bpt
->type
== bp_access_watchpoint
)
7692 struct frame_id saved_frame_id
;
7694 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7695 if (bpt
->exp_valid_block
!= NULL
)
7697 struct frame_info
*fr
=
7698 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7701 printf_filtered (_("\
7702 Cannot enable watchpoint %d because the block in which its expression\n\
7703 is valid is not currently in scope.\n"), bpt
->number
);
7710 value_free (bpt
->val
);
7711 mark
= value_mark ();
7712 bpt
->val
= evaluate_expression (bpt
->exp
);
7713 release_value (bpt
->val
);
7714 if (value_lazy (bpt
->val
))
7715 value_fetch_lazy (bpt
->val
);
7717 if (bpt
->type
== bp_hardware_watchpoint
||
7718 bpt
->type
== bp_read_watchpoint
||
7719 bpt
->type
== bp_access_watchpoint
)
7721 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7722 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7724 /* Hack around 'unused var' error for some targets here */
7725 (void) mem_cnt
, (void) i
;
7726 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7727 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7728 /* we can consider of type is bp_hardware_watchpoint, convert to
7729 bp_watchpoint in the following condition */
7730 if (target_resources_ok
< 0)
7732 printf_filtered (_("\
7733 Cannot enable watchpoint %d because target watch resources\n\
7734 have been allocated for other watchpoints.\n"), bpt
->number
);
7735 value_free_to_mark (mark
);
7740 select_frame (frame_find_by_id (saved_frame_id
));
7741 value_free_to_mark (mark
);
7744 if (bpt
->enable_state
!= bp_permanent
)
7745 bpt
->enable_state
= bp_enabled
;
7746 bpt
->disposition
= disposition
;
7747 check_duplicates (bpt
);
7748 breakpoints_changed ();
7750 if (deprecated_modify_breakpoint_hook
)
7751 deprecated_modify_breakpoint_hook (bpt
);
7752 breakpoint_modify_event (bpt
->number
);
7757 enable_breakpoint (struct breakpoint
*bpt
)
7759 do_enable_breakpoint (bpt
, bpt
->disposition
);
7762 /* The enable command enables the specified breakpoints (or all defined
7763 breakpoints) so they once again become (or continue to be) effective
7764 in stopping the inferior. */
7767 enable_command (char *args
, int from_tty
)
7769 struct breakpoint
*bpt
;
7771 ALL_BREAKPOINTS (bpt
)
7775 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7780 case bp_catch_unload
:
7782 case bp_catch_vfork
:
7784 case bp_hardware_breakpoint
:
7786 case bp_hardware_watchpoint
:
7787 case bp_read_watchpoint
:
7788 case bp_access_watchpoint
:
7789 enable_breakpoint (bpt
);
7793 else if (strchr (args
, '.'))
7795 struct bp_location
*loc
= find_location_by_number (args
);
7798 check_duplicates (loc
->owner
);
7801 map_breakpoint_numbers (args
, enable_breakpoint
);
7805 enable_once_breakpoint (struct breakpoint
*bpt
)
7807 do_enable_breakpoint (bpt
, disp_disable
);
7811 enable_once_command (char *args
, int from_tty
)
7813 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7817 enable_delete_breakpoint (struct breakpoint
*bpt
)
7819 do_enable_breakpoint (bpt
, disp_del
);
7823 enable_delete_command (char *args
, int from_tty
)
7825 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7829 set_breakpoint_cmd (char *args
, int from_tty
)
7834 show_breakpoint_cmd (char *args
, int from_tty
)
7838 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7840 struct symtabs_and_lines
7841 decode_line_spec_1 (char *string
, int funfirstline
)
7843 struct symtabs_and_lines sals
;
7845 error (_("Empty line specification."));
7846 if (default_breakpoint_valid
)
7847 sals
= decode_line_1 (&string
, funfirstline
,
7848 default_breakpoint_symtab
,
7849 default_breakpoint_line
,
7850 (char ***) NULL
, NULL
);
7852 sals
= decode_line_1 (&string
, funfirstline
,
7853 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7855 error (_("Junk at end of line specification: %s"), string
);
7859 /* Create and insert a raw software breakpoint at PC. Return an
7860 identifier, which should be used to remove the breakpoint later.
7861 In general, places which call this should be using something on the
7862 breakpoint chain instead; this function should be eliminated
7866 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7868 struct bp_target_info
*bp_tgt
;
7870 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7871 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7873 bp_tgt
->placed_address
= pc
;
7874 if (target_insert_breakpoint (bp_tgt
) != 0)
7876 /* Could not insert the breakpoint. */
7884 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7887 deprecated_remove_raw_breakpoint (void *bp
)
7889 struct bp_target_info
*bp_tgt
= bp
;
7892 ret
= target_remove_breakpoint (bp_tgt
);
7898 /* One (or perhaps two) breakpoints used for software single stepping. */
7900 static void *single_step_breakpoints
[2];
7902 /* Create and insert a breakpoint for software single step. */
7905 insert_single_step_breakpoint (CORE_ADDR next_pc
)
7909 if (single_step_breakpoints
[0] == NULL
)
7910 bpt_p
= &single_step_breakpoints
[0];
7913 gdb_assert (single_step_breakpoints
[1] == NULL
);
7914 bpt_p
= &single_step_breakpoints
[1];
7917 /* NOTE drow/2006-04-11: A future improvement to this function would be
7918 to only create the breakpoints once, and actually put them on the
7919 breakpoint chain. That would let us use set_raw_breakpoint. We could
7920 adjust the addresses each time they were needed. Doing this requires
7921 corresponding changes elsewhere where single step breakpoints are
7922 handled, however. So, for now, we use this. */
7924 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
7926 error (_("Could not insert single-step breakpoint at 0x%s"),
7927 paddr_nz (next_pc
));
7930 /* Remove and delete any breakpoints used for software single step. */
7933 remove_single_step_breakpoints (void)
7935 gdb_assert (single_step_breakpoints
[0] != NULL
);
7937 /* See insert_single_step_breakpoint for more about this deprecated
7939 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
7940 single_step_breakpoints
[0] = NULL
;
7942 if (single_step_breakpoints
[1] != NULL
)
7944 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
7945 single_step_breakpoints
[1] = NULL
;
7949 /* Check whether a software single-step breakpoint is inserted at PC. */
7952 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
7956 for (i
= 0; i
< 2; i
++)
7958 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
7959 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
7967 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
7968 It is defined as a macro to prevent duplication.
7969 COMMAND should be a string constant containing the name of the command. */
7970 #define BREAK_ARGS_HELP(command) \
7971 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
7972 LOCATION may be a line number, function name, or \"*\" and an address.\n\
7973 If a line number is specified, break at start of code for that line.\n\
7974 If a function is specified, break at start of code for that function.\n\
7975 If an address is specified, break at that exact address.\n\
7976 With no LOCATION, uses current execution address of selected stack frame.\n\
7977 This is useful for breaking on return to a stack frame.\n\
7979 THREADNUM is the number from \"info threads\".\n\
7980 CONDITION is a boolean expression.\n\
7982 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7984 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
7987 _initialize_breakpoint (void)
7989 static struct cmd_list_element
*breakpoint_set_cmdlist
;
7990 static struct cmd_list_element
*breakpoint_show_cmdlist
;
7991 struct cmd_list_element
*c
;
7993 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
7995 breakpoint_chain
= 0;
7996 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7997 before a breakpoint is set. */
7998 breakpoint_count
= 0;
8000 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8001 Set ignore-count of breakpoint number N to COUNT.\n\
8002 Usage is `ignore N COUNT'."));
8004 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8006 add_com ("commands", class_breakpoint
, commands_command
, _("\
8007 Set commands to be executed when a breakpoint is hit.\n\
8008 Give breakpoint number as argument after \"commands\".\n\
8009 With no argument, the targeted breakpoint is the last one set.\n\
8010 The commands themselves follow starting on the next line.\n\
8011 Type a line containing \"end\" to indicate the end of them.\n\
8012 Give \"silent\" as the first line to make the breakpoint silent;\n\
8013 then no output is printed when it is hit, except what the commands print."));
8015 add_com ("condition", class_breakpoint
, condition_command
, _("\
8016 Specify breakpoint number N to break only if COND is true.\n\
8017 Usage is `condition N COND', where N is an integer and COND is an\n\
8018 expression to be evaluated whenever breakpoint N is reached."));
8020 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8021 Set a temporary breakpoint.\n\
8022 Like \"break\" except the breakpoint is only temporary,\n\
8023 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8024 by using \"enable delete\" on the breakpoint number.\n\
8026 BREAK_ARGS_HELP ("tbreak")));
8027 set_cmd_completer (c
, location_completer
);
8029 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8030 Set a hardware assisted breakpoint.\n\
8031 Like \"break\" except the breakpoint requires hardware support,\n\
8032 some target hardware may not have this support.\n\
8034 BREAK_ARGS_HELP ("hbreak")));
8035 set_cmd_completer (c
, location_completer
);
8037 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8038 Set a temporary hardware assisted breakpoint.\n\
8039 Like \"hbreak\" except the breakpoint is only temporary,\n\
8040 so it will be deleted when hit.\n\
8042 BREAK_ARGS_HELP ("thbreak")));
8043 set_cmd_completer (c
, location_completer
);
8045 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8046 Enable some breakpoints.\n\
8047 Give breakpoint numbers (separated by spaces) as arguments.\n\
8048 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8049 This is used to cancel the effect of the \"disable\" command.\n\
8050 With a subcommand you can enable temporarily."),
8051 &enablelist
, "enable ", 1, &cmdlist
);
8053 add_com ("ab", class_breakpoint
, enable_command
, _("\
8054 Enable some breakpoints.\n\
8055 Give breakpoint numbers (separated by spaces) as arguments.\n\
8056 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8057 This is used to cancel the effect of the \"disable\" command.\n\
8058 With a subcommand you can enable temporarily."));
8060 add_com_alias ("en", "enable", class_breakpoint
, 1);
8062 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8063 Enable some breakpoints.\n\
8064 Give breakpoint numbers (separated by spaces) as arguments.\n\
8065 This is used to cancel the effect of the \"disable\" command.\n\
8066 May be abbreviated to simply \"enable\".\n"),
8067 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8069 add_cmd ("once", no_class
, enable_once_command
, _("\
8070 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8071 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8074 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8075 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8076 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8079 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8080 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8081 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8084 add_cmd ("once", no_class
, enable_once_command
, _("\
8085 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8086 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8089 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8090 Disable some breakpoints.\n\
8091 Arguments are breakpoint numbers with spaces in between.\n\
8092 To disable all breakpoints, give no argument.\n\
8093 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8094 &disablelist
, "disable ", 1, &cmdlist
);
8095 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8096 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8098 add_com ("sb", class_breakpoint
, disable_command
, _("\
8099 Disable some breakpoints.\n\
8100 Arguments are breakpoint numbers with spaces in between.\n\
8101 To disable all breakpoints, give no argument.\n\
8102 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8104 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8105 Disable some breakpoints.\n\
8106 Arguments are breakpoint numbers with spaces in between.\n\
8107 To disable all breakpoints, give no argument.\n\
8108 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8109 This command may be abbreviated \"disable\"."),
8112 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8113 Delete some breakpoints or auto-display expressions.\n\
8114 Arguments are breakpoint numbers with spaces in between.\n\
8115 To delete all breakpoints, give no argument.\n\
8117 Also a prefix command for deletion of other GDB objects.\n\
8118 The \"unset\" command is also an alias for \"delete\"."),
8119 &deletelist
, "delete ", 1, &cmdlist
);
8120 add_com_alias ("d", "delete", class_breakpoint
, 1);
8121 add_com_alias ("del", "delete", class_breakpoint
, 1);
8123 add_com ("db", class_breakpoint
, delete_command
, _("\
8124 Delete some breakpoints.\n\
8125 Arguments are breakpoint numbers with spaces in between.\n\
8126 To delete all breakpoints, give no argument.\n"));
8128 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8129 Delete some breakpoints or auto-display expressions.\n\
8130 Arguments are breakpoint numbers with spaces in between.\n\
8131 To delete all breakpoints, give no argument.\n\
8132 This command may be abbreviated \"delete\"."),
8135 add_com ("clear", class_breakpoint
, clear_command
, _("\
8136 Clear breakpoint at specified line or function.\n\
8137 Argument may be line number, function name, or \"*\" and an address.\n\
8138 If line number is specified, all breakpoints in that line are cleared.\n\
8139 If function is specified, breakpoints at beginning of function are cleared.\n\
8140 If an address is specified, breakpoints at that address are cleared.\n\
8142 With no argument, clears all breakpoints in the line that the selected frame\n\
8145 See also the \"delete\" command which clears breakpoints by number."));
8147 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8148 Set breakpoint at specified line or function.\n"
8149 BREAK_ARGS_HELP ("break")));
8150 set_cmd_completer (c
, location_completer
);
8152 add_com_alias ("b", "break", class_run
, 1);
8153 add_com_alias ("br", "break", class_run
, 1);
8154 add_com_alias ("bre", "break", class_run
, 1);
8155 add_com_alias ("brea", "break", class_run
, 1);
8159 add_com_alias ("ba", "break", class_breakpoint
, 1);
8160 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8165 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8166 Break in function/address or break at a line in the current file."),
8167 &stoplist
, "stop ", 1, &cmdlist
);
8168 add_cmd ("in", class_breakpoint
, stopin_command
,
8169 _("Break in function or address."), &stoplist
);
8170 add_cmd ("at", class_breakpoint
, stopat_command
,
8171 _("Break at a line in the current file."), &stoplist
);
8172 add_com ("status", class_info
, breakpoints_info
, _("\
8173 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8174 The \"Type\" column indicates one of:\n\
8175 \tbreakpoint - normal breakpoint\n\
8176 \twatchpoint - watchpoint\n\
8177 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8178 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8179 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8180 address and file/line number respectively.\n\
8182 Convenience variable \"$_\" and default examine address for \"x\"\n\
8183 are set to the address of the last breakpoint listed unless the command\n\
8184 is prefixed with \"server \".\n\n\
8185 Convenience variable \"$bpnum\" contains the number of the last\n\
8189 add_info ("breakpoints", breakpoints_info
, _("\
8190 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8191 The \"Type\" column indicates one of:\n\
8192 \tbreakpoint - normal breakpoint\n\
8193 \twatchpoint - watchpoint\n\
8194 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8195 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8196 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8197 address and file/line number respectively.\n\
8199 Convenience variable \"$_\" and default examine address for \"x\"\n\
8200 are set to the address of the last breakpoint listed unless the command\n\
8201 is prefixed with \"server \".\n\n\
8202 Convenience variable \"$bpnum\" contains the number of the last\n\
8206 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8207 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8208 The \"Type\" column indicates one of:\n\
8209 \tbreakpoint - normal breakpoint\n\
8210 \twatchpoint - watchpoint\n\
8211 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8212 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8213 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8214 address and file/line number respectively.\n\
8216 Convenience variable \"$_\" and default examine address for \"x\"\n\
8217 are set to the address of the last breakpoint listed unless the command\n\
8218 is prefixed with \"server \".\n\n\
8219 Convenience variable \"$bpnum\" contains the number of the last\n\
8222 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8223 Status of all breakpoints, or breakpoint number NUMBER.\n\
8224 The \"Type\" column indicates one of:\n\
8225 \tbreakpoint - normal breakpoint\n\
8226 \twatchpoint - watchpoint\n\
8227 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8228 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8229 \tuntil - internal breakpoint used by the \"until\" command\n\
8230 \tfinish - internal breakpoint used by the \"finish\" command\n\
8231 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8232 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8233 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8234 address and file/line number respectively.\n\
8236 Convenience variable \"$_\" and default examine address for \"x\"\n\
8237 are set to the address of the last breakpoint listed unless the command\n\
8238 is prefixed with \"server \".\n\n\
8239 Convenience variable \"$bpnum\" contains the number of the last\n\
8241 &maintenanceinfolist
);
8243 add_com ("catch", class_breakpoint
, catch_command
, _("\
8244 Set catchpoints to catch events.\n\
8245 Raised signals may be caught:\n\
8246 \tcatch signal - all signals\n\
8247 \tcatch signal <signame> - a particular signal\n\
8248 Raised exceptions may be caught:\n\
8249 \tcatch throw - all exceptions, when thrown\n\
8250 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8251 \tcatch catch - all exceptions, when caught\n\
8252 \tcatch catch <exceptname> - a particular exception, when caught\n\
8253 Thread or process events may be caught:\n\
8254 \tcatch thread_start - any threads, just after creation\n\
8255 \tcatch thread_exit - any threads, just before expiration\n\
8256 \tcatch thread_join - any threads, just after joins\n\
8257 Process events may be caught:\n\
8258 \tcatch start - any processes, just after creation\n\
8259 \tcatch exit - any processes, just before expiration\n\
8260 \tcatch fork - calls to fork()\n\
8261 \tcatch vfork - calls to vfork()\n\
8262 \tcatch exec - calls to exec()\n\
8263 Dynamically-linked library events may be caught:\n\
8264 \tcatch load - loads of any library\n\
8265 \tcatch load <libname> - loads of a particular library\n\
8266 \tcatch unload - unloads of any library\n\
8267 \tcatch unload <libname> - unloads of a particular library\n\
8268 The act of your program's execution stopping may also be caught:\n\
8270 C++ exceptions may be caught:\n\
8271 \tcatch throw - all exceptions, when thrown\n\
8272 \tcatch catch - all exceptions, when caught\n\
8273 Ada exceptions may be caught:\n\
8274 \tcatch exception - all exceptions, when raised\n\
8275 \tcatch exception <name> - a particular exception, when raised\n\
8276 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8277 \tcatch assert - all failed assertions, when raised\n\
8279 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8280 after a fork or vfork is caught.\n\n\
8281 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8283 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8284 Set temporary catchpoints to catch events.\n\
8285 Args like \"catch\" command.\n\
8286 Like \"catch\" except the catchpoint is only temporary,\n\
8287 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8288 by using \"enable delete\" on the catchpoint number."));
8290 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8291 Set a watchpoint for an expression.\n\
8292 A watchpoint stops execution of your program whenever the value of\n\
8293 an expression changes."));
8294 set_cmd_completer (c
, location_completer
);
8296 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8297 Set a read watchpoint for an expression.\n\
8298 A watchpoint stops execution of your program whenever the value of\n\
8299 an expression is read."));
8300 set_cmd_completer (c
, location_completer
);
8302 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8303 Set a watchpoint for an expression.\n\
8304 A watchpoint stops execution of your program whenever the value of\n\
8305 an expression is either read or written."));
8306 set_cmd_completer (c
, location_completer
);
8308 add_info ("watchpoints", breakpoints_info
,
8309 _("Synonym for ``info breakpoints''."));
8312 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8313 respond to changes - contrary to the description. */
8314 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8315 &can_use_hw_watchpoints
, _("\
8316 Set debugger's willingness to use watchpoint hardware."), _("\
8317 Show debugger's willingness to use watchpoint hardware."), _("\
8318 If zero, gdb will not use hardware for new watchpoints, even if\n\
8319 such is available. (However, any hardware watchpoints that were\n\
8320 created before setting this to nonzero, will continue to use watchpoint\n\
8323 show_can_use_hw_watchpoints
,
8324 &setlist
, &showlist
);
8326 can_use_hw_watchpoints
= 1;
8328 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8329 Breakpoint specific settings\n\
8330 Configure various breakpoint-specific variables such as\n\
8331 pending breakpoint behavior"),
8332 &breakpoint_set_cmdlist
, "set breakpoint ",
8333 0/*allow-unknown*/, &setlist
);
8334 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8335 Breakpoint specific settings\n\
8336 Configure various breakpoint-specific variables such as\n\
8337 pending breakpoint behavior"),
8338 &breakpoint_show_cmdlist
, "show breakpoint ",
8339 0/*allow-unknown*/, &showlist
);
8341 add_setshow_auto_boolean_cmd ("pending", no_class
,
8342 &pending_break_support
, _("\
8343 Set debugger's behavior regarding pending breakpoints."), _("\
8344 Show debugger's behavior regarding pending breakpoints."), _("\
8345 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8346 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8347 an error. If auto, an unrecognized breakpoint location results in a\n\
8348 user-query to see if a pending breakpoint should be created."),
8350 show_pending_break_support
,
8351 &breakpoint_set_cmdlist
,
8352 &breakpoint_show_cmdlist
);
8354 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8356 add_setshow_boolean_cmd ("auto-hw", no_class
,
8357 &automatic_hardware_breakpoints
, _("\
8358 Set automatic usage of hardware breakpoints."), _("\
8359 Show automatic usage of hardware breakpoints."), _("\
8360 If set, the debugger will automatically use hardware breakpoints for\n\
8361 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8362 a warning will be emitted for such breakpoints."),
8364 show_automatic_hardware_breakpoints
,
8365 &breakpoint_set_cmdlist
,
8366 &breakpoint_show_cmdlist
);
8368 automatic_hardware_breakpoints
= 1;