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"
60 #include "gdb-events.h"
61 #include "mi/mi-common.h"
63 /* Prototypes for local functions. */
65 static void until_break_command_continuation (struct continuation_arg
*arg
);
67 static void catch_command_1 (char *, int, int);
69 static void enable_delete_command (char *, int);
71 static void enable_delete_breakpoint (struct breakpoint
*);
73 static void enable_once_command (char *, int);
75 static void enable_once_breakpoint (struct breakpoint
*);
77 static void disable_command (char *, int);
79 static void enable_command (char *, int);
81 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
83 static void ignore_command (char *, int);
85 static int breakpoint_re_set_one (void *);
87 static void clear_command (char *, int);
89 static void catch_command (char *, int);
91 static void watch_command (char *, int);
93 static int can_use_hardware_watchpoint (struct value
*);
95 static void break_command_1 (char *, int, int);
97 static void mention (struct breakpoint
*);
99 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
101 static void check_duplicates (struct breakpoint
*);
103 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
105 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
108 static void describe_other_breakpoints (CORE_ADDR
, asection
*, int);
110 static void breakpoints_info (char *, int);
112 static void breakpoint_1 (int, int);
114 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
116 static int breakpoint_cond_eval (void *);
118 static void cleanup_executing_breakpoints (void *);
120 static void commands_command (char *, int);
122 static void condition_command (char *, int);
124 static int get_number_trailer (char **, int);
126 void set_breakpoint_count (int);
135 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
137 static enum print_stop_action
print_it_typical (bpstat
);
139 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
143 enum exception_event_kind kind
;
146 args_for_catchpoint_enable
;
148 static int watchpoint_check (void *);
150 static void maintenance_info_breakpoints (char *, int);
152 static void create_longjmp_breakpoint (char *);
154 static void create_overlay_event_breakpoint (char *);
156 static int hw_breakpoint_used_count (void);
158 static int hw_watchpoint_used_count (enum bptype
, int *);
160 static void hbreak_command (char *, int);
162 static void thbreak_command (char *, int);
164 static void watch_command_1 (char *, int, int);
166 static void rwatch_command (char *, int);
168 static void awatch_command (char *, int);
170 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
172 static void create_fork_vfork_event_catchpoint (int tempflag
,
174 enum bptype bp_kind
);
176 static void stop_command (char *arg
, int from_tty
);
178 static void stopin_command (char *arg
, int from_tty
);
180 static void stopat_command (char *arg
, int from_tty
);
182 static char *ep_find_event_name_end (char *arg
);
184 static char *ep_parse_optional_if_clause (char **arg
);
186 static char *ep_parse_optional_filename (char **arg
);
188 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
189 enum exception_event_kind ex_event
,
190 struct symtab_and_line
*sal
);
192 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
193 char *arg
, int tempflag
, int from_tty
);
195 static void tcatch_command (char *arg
, int from_tty
);
197 static void ep_skip_leading_whitespace (char **s
);
199 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
201 static void free_bp_location (struct bp_location
*loc
);
203 static void mark_breakpoints_out (void);
205 static struct bp_location
*
206 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
);
209 unlink_locations_from_global_list (struct breakpoint
*bpt
);
212 is_hardware_watchpoint (struct breakpoint
*bpt
);
214 /* Prototypes for exported functions. */
216 /* If FALSE, gdb will not use hardware support for watchpoints, even
217 if such is available. */
218 static int can_use_hw_watchpoints
;
221 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
222 struct cmd_list_element
*c
,
225 fprintf_filtered (file
, _("\
226 Debugger's willingness to use watchpoint hardware is %s.\n"),
230 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
231 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
232 for unrecognized breakpoint locations.
233 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
234 static enum auto_boolean pending_break_support
;
236 show_pending_break_support (struct ui_file
*file
, int from_tty
,
237 struct cmd_list_element
*c
,
240 fprintf_filtered (file
, _("\
241 Debugger's behavior regarding pending breakpoints is %s.\n"),
245 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
246 set with "break" but falling in read-only memory.
247 If 0, gdb will warn about such breakpoints, but won't automatically
248 use hardware breakpoints. */
249 static int automatic_hardware_breakpoints
;
251 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
252 struct cmd_list_element
*c
,
255 fprintf_filtered (file
, _("\
256 Automatic usage of hardware breakpoints is %s.\n"),
261 void _initialize_breakpoint (void);
263 extern int addressprint
; /* Print machine addresses? */
265 /* Are we executing breakpoint commands? */
266 static int executing_breakpoint_commands
;
268 /* Are overlay event breakpoints enabled? */
269 static int overlay_events_enabled
;
271 /* Walk the following statement or block through all breakpoints.
272 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
275 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
277 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
278 for (B = breakpoint_chain; \
279 B ? (TMP=B->next, 1): 0; \
282 /* Similar iterators for the low-level breakpoints. */
284 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
286 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
287 for (B = bp_location_chain; \
288 B ? (TMP=B->global_next, 1): 0; \
291 /* True if breakpoint hit counts should be displayed in breakpoint info. */
293 int show_breakpoint_hit_counts
= 1;
295 /* Chains of all breakpoints defined. */
297 struct breakpoint
*breakpoint_chain
;
299 struct bp_location
*bp_location_chain
;
301 /* Number of last breakpoint made. */
303 int breakpoint_count
;
305 /* Pointer to current exception event record */
306 static struct exception_event_record
*current_exception_event
;
308 /* This function returns a pointer to the string representation of the
309 pathname of the dynamically-linked library that has just been
312 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
313 or undefined results are guaranteed.
315 This string's contents are only valid immediately after the
316 inferior has stopped in the dynamic linker hook, and becomes
317 invalid as soon as the inferior is continued. Clients should make
318 a copy of this string if they wish to continue the inferior and
319 then access the string. */
321 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
322 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
325 /* This function returns a pointer to the string representation of the
326 pathname of the dynamically-linked library that has just been
329 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
330 TRUE, or undefined results are guaranteed.
332 This string's contents are only valid immediately after the
333 inferior has stopped in the dynamic linker hook, and becomes
334 invalid as soon as the inferior is continued. Clients should make
335 a copy of this string if they wish to continue the inferior and
336 then access the string. */
338 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
339 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
342 /* This function is called by the "catch load" command. It allows the
343 debugger to be notified by the dynamic linker when a specified
344 library file (or any library file, if filename is NULL) is loaded. */
346 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
347 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
348 error (_("catch of library loads not yet implemented on this platform"))
351 /* This function is called by the "catch unload" command. It allows
352 the debugger to be notified by the dynamic linker when a specified
353 library file (or any library file, if filename is NULL) is
356 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
357 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
358 error (_("catch of library unloads not yet implemented on this platform"))
361 /* Return whether a breakpoint is an active enabled breakpoint. */
363 breakpoint_enabled (struct breakpoint
*b
)
365 return (b
->enable_state
== bp_enabled
);
368 /* Set breakpoint count to NUM. */
371 set_breakpoint_count (int num
)
373 breakpoint_count
= num
;
374 set_internalvar (lookup_internalvar ("bpnum"),
375 value_from_longest (builtin_type_int
, (LONGEST
) num
));
378 /* Used in run_command to zero the hit count when a new run starts. */
381 clear_breakpoint_hit_counts (void)
383 struct breakpoint
*b
;
389 /* Default address, symtab and line to put a breakpoint at
390 for "break" command with no arg.
391 if default_breakpoint_valid is zero, the other three are
392 not valid, and "break" with no arg is an error.
394 This set by print_stack_frame, which calls set_default_breakpoint. */
396 int default_breakpoint_valid
;
397 CORE_ADDR default_breakpoint_address
;
398 struct symtab
*default_breakpoint_symtab
;
399 int default_breakpoint_line
;
401 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
402 Advance *PP after the string and any trailing whitespace.
404 Currently the string can either be a number or "$" followed by the name
405 of a convenience variable. Making it an expression wouldn't work well
406 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
408 If the string is a NULL pointer, that denotes the last breakpoint.
410 TRAILER is a character which can be found after the number; most
411 commonly this is `-'. If you don't want a trailer, use \0. */
413 get_number_trailer (char **pp
, int trailer
)
415 int retval
= 0; /* default */
419 /* Empty line means refer to the last breakpoint. */
420 return breakpoint_count
;
423 /* Make a copy of the name, so we can null-terminate it
424 to pass to lookup_internalvar(). */
429 while (isalnum (*p
) || *p
== '_')
431 varname
= (char *) alloca (p
- start
+ 1);
432 strncpy (varname
, start
, p
- start
);
433 varname
[p
- start
] = '\0';
434 val
= value_of_internalvar (lookup_internalvar (varname
));
435 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
436 retval
= (int) value_as_long (val
);
439 printf_filtered (_("Convenience variable must have integer value.\n"));
447 while (*p
>= '0' && *p
<= '9')
450 /* There is no number here. (e.g. "cond a == b"). */
452 /* Skip non-numeric token */
453 while (*p
&& !isspace((int) *p
))
455 /* Return zero, which caller must interpret as error. */
461 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
463 /* Trailing junk: return 0 and let caller print error msg. */
464 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
475 /* Like get_number_trailer, but don't allow a trailer. */
477 get_number (char **pp
)
479 return get_number_trailer (pp
, '\0');
482 /* Parse a number or a range.
483 * A number will be of the form handled by get_number.
484 * A range will be of the form <number1> - <number2>, and
485 * will represent all the integers between number1 and number2,
488 * While processing a range, this fuction is called iteratively;
489 * At each call it will return the next value in the range.
491 * At the beginning of parsing a range, the char pointer PP will
492 * be advanced past <number1> and left pointing at the '-' token.
493 * Subsequent calls will not advance the pointer until the range
494 * is completed. The call that completes the range will advance
495 * pointer PP past <number2>.
499 get_number_or_range (char **pp
)
501 static int last_retval
, end_value
;
502 static char *end_ptr
;
503 static int in_range
= 0;
507 /* Default case: pp is pointing either to a solo number,
508 or to the first number of a range. */
509 last_retval
= get_number_trailer (pp
, '-');
514 /* This is the start of a range (<number1> - <number2>).
515 Skip the '-', parse and remember the second number,
516 and also remember the end of the final token. */
520 while (isspace ((int) *end_ptr
))
521 end_ptr
++; /* skip white space */
522 end_value
= get_number (temp
);
523 if (end_value
< last_retval
)
525 error (_("inverted range"));
527 else if (end_value
== last_retval
)
529 /* degenerate range (number1 == number2). Advance the
530 token pointer so that the range will be treated as a
539 error (_("negative value"));
542 /* pp points to the '-' that betokens a range. All
543 number-parsing has already been done. Return the next
544 integer value (one greater than the saved previous value).
545 Do not advance the token pointer 'pp' until the end of range
548 if (++last_retval
== end_value
)
550 /* End of range reached; advance token pointer. */
560 /* condition N EXP -- set break condition of breakpoint N to EXP. */
563 condition_command (char *arg
, int from_tty
)
565 struct breakpoint
*b
;
570 error_no_arg (_("breakpoint number"));
573 bnum
= get_number (&p
);
575 error (_("Bad breakpoint argument: '%s'"), arg
);
578 if (b
->number
== bnum
)
580 struct bp_location
*loc
= b
->loc
;
581 for (; loc
; loc
= loc
->next
)
589 if (b
->cond_string
!= NULL
)
590 xfree (b
->cond_string
);
594 b
->cond_string
= NULL
;
596 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
601 /* I don't know if it matters whether this is the string the user
602 typed in or the decompiled expression. */
603 b
->cond_string
= savestring (arg
, strlen (arg
));
604 b
->condition_not_parsed
= 0;
605 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
608 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
610 error (_("Junk at end of expression"));
613 breakpoints_changed ();
614 breakpoint_modify_event (b
->number
);
618 error (_("No breakpoint number %d."), bnum
);
622 commands_command (char *arg
, int from_tty
)
624 struct breakpoint
*b
;
627 struct command_line
*l
;
629 /* If we allowed this, we would have problems with when to
630 free the storage, if we change the commands currently
633 if (executing_breakpoint_commands
)
634 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
637 bnum
= get_number (&p
);
640 error (_("Unexpected extra arguments following breakpoint number."));
643 if (b
->number
== bnum
)
645 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
647 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
648 l
= read_command_lines (tmpbuf
, from_tty
);
649 do_cleanups (cleanups
);
650 free_command_lines (&b
->commands
);
652 breakpoints_changed ();
653 breakpoint_modify_event (b
->number
);
656 error (_("No breakpoint number %d."), bnum
);
659 /* Like commands_command, but instead of reading the commands from
660 input stream, takes them from an already parsed command structure.
662 This is used by cli-script.c to DTRT with breakpoint commands
663 that are part of if and while bodies. */
664 enum command_control_type
665 commands_from_control_command (char *arg
, struct command_line
*cmd
)
667 struct breakpoint
*b
;
671 /* If we allowed this, we would have problems with when to
672 free the storage, if we change the commands currently
675 if (executing_breakpoint_commands
)
676 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
678 /* An empty string for the breakpoint number means the last
679 breakpoint, but get_number expects a NULL pointer. */
684 bnum
= get_number (&p
);
687 error (_("Unexpected extra arguments following breakpoint number."));
690 if (b
->number
== bnum
)
692 free_command_lines (&b
->commands
);
693 if (cmd
->body_count
!= 1)
694 error (_("Invalid \"commands\" block structure."));
695 /* We need to copy the commands because if/while will free the
696 list after it finishes execution. */
697 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
698 breakpoints_changed ();
699 breakpoint_modify_event (b
->number
);
700 return simple_control
;
702 error (_("No breakpoint number %d."), bnum
);
705 /* Like target_read_memory() but if breakpoints are inserted, return
706 the shadow contents instead of the breakpoints themselves.
708 Read "memory data" from whatever target or inferior we have.
709 Returns zero if successful, errno value if not. EIO is used
710 for address out of bounds. If breakpoints are inserted, returns
711 shadow contents, not the breakpoints themselves. From breakpoint.c. */
714 read_memory_nobpt (CORE_ADDR memaddr
, gdb_byte
*myaddr
, unsigned len
)
717 const struct bp_location
*b
;
718 CORE_ADDR bp_addr
= 0;
721 if (gdbarch_breakpoint_from_pc (current_gdbarch
, &bp_addr
, &bp_size
) == NULL
)
722 /* No breakpoints on this machine. */
723 return target_read_memory (memaddr
, myaddr
, len
);
727 if (b
->owner
->type
== bp_none
)
728 warning (_("reading through apparently deleted breakpoint #%d?"),
731 if (b
->loc_type
!= bp_loc_software_breakpoint
)
735 /* Addresses and length of the part of the breakpoint that
737 bp_addr
= b
->target_info
.placed_address
;
738 bp_size
= b
->target_info
.shadow_len
;
740 /* bp isn't valid, or doesn't shadow memory. */
742 if (bp_addr
+ bp_size
<= memaddr
)
743 /* The breakpoint is entirely before the chunk of memory we
746 if (bp_addr
>= memaddr
+ len
)
747 /* The breakpoint is entirely after the chunk of memory we are
750 /* Copy the breakpoint from the shadow contents, and recurse for
751 the things before and after. */
753 /* Offset within shadow_contents. */
756 if (bp_addr
< memaddr
)
758 /* Only copy the second part of the breakpoint. */
759 bp_size
-= memaddr
- bp_addr
;
760 bptoffset
= memaddr
- bp_addr
;
764 if (bp_addr
+ bp_size
> memaddr
+ len
)
766 /* Only copy the first part of the breakpoint. */
767 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
770 memcpy (myaddr
+ bp_addr
- memaddr
,
771 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
773 if (bp_addr
> memaddr
)
775 /* Copy the section of memory before the breakpoint. */
776 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
781 if (bp_addr
+ bp_size
< memaddr
+ len
)
783 /* Copy the section of memory after the breakpoint. */
784 status
= read_memory_nobpt (bp_addr
+ bp_size
,
785 myaddr
+ bp_addr
+ bp_size
- memaddr
,
786 memaddr
+ len
- (bp_addr
+ bp_size
));
793 /* Nothing overlaps. Just call read_memory_noerr. */
794 return target_read_memory (memaddr
, myaddr
, len
);
798 /* A wrapper function for inserting catchpoints. */
800 insert_catchpoint (struct ui_out
*uo
, void *args
)
802 struct breakpoint
*b
= (struct breakpoint
*) args
;
808 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
811 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
814 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
817 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
823 is_hardware_watchpoint (struct breakpoint
*bpt
)
825 return (bpt
->type
== bp_hardware_watchpoint
826 || bpt
->type
== bp_read_watchpoint
827 || bpt
->type
== bp_access_watchpoint
);
830 /* Find the current value of a watchpoint on EXP. Return the value in
831 *VALP and *RESULTP and the chain of intermediate and final values
832 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
835 If an error occurs while evaluating the expression, *RESULTP will
836 be set to NULL. *RESULTP may be a lazy value, if the result could
837 not be read from memory. It is used to determine whether a value
838 is user-specified (we should watch the whole value) or intermediate
839 (we should watch only the bit used to locate the final value).
841 If the final value, or any intermediate value, could not be read
842 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
843 set to any referenced values. *VALP will never be a lazy value.
844 This is the value which we store in struct breakpoint.
846 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
847 value chain. The caller must free the values individually. If
848 VAL_CHAIN is NULL, all generated values will be left on the value
852 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
853 struct value
**resultp
, struct value
**val_chain
)
855 struct value
*mark
, *new_mark
, *result
;
863 /* Evaluate the expression. */
864 mark
= value_mark ();
866 gdb_evaluate_expression (exp
, &result
);
867 new_mark
= value_mark ();
868 if (mark
== new_mark
)
873 /* Make sure it's not lazy, so that after the target stops again we
874 have a non-lazy previous value to compare with. */
876 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
881 /* Return the chain of intermediate values. We use this to
882 decide which addresses to watch. */
883 *val_chain
= new_mark
;
884 value_release_to_mark (mark
);
888 /* Assuming that B is a hardware watchpoint:
889 - Reparse watchpoint expression, is REPARSE is non-zero
890 - Evaluate expression and store the result in B->val
891 - Update the list of values that must be watched in B->loc.
893 If the watchpoint is disabled, do nothing. If this is
894 local watchpoint that is out of scope, delete it. */
896 update_watchpoint (struct breakpoint
*b
, int reparse
)
898 int within_current_scope
;
899 struct frame_id saved_frame_id
;
900 struct bp_location
*loc
;
903 unlink_locations_from_global_list (b
);
904 for (loc
= b
->loc
; loc
;)
906 struct bp_location
*loc_next
= loc
->next
;
907 remove_breakpoint (loc
, mark_uninserted
);
913 if (b
->disposition
== disp_del_at_next_stop
)
916 /* Save the current frame's ID so we can restore it after
917 evaluating the watchpoint expression on its own frame. */
918 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
919 took a frame parameter, so that we didn't have to change the
921 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
923 /* Determine if the watchpoint is within scope. */
924 if (b
->exp_valid_block
== NULL
)
925 within_current_scope
= 1;
928 struct frame_info
*fi
;
929 fi
= frame_find_by_id (b
->watchpoint_frame
);
930 within_current_scope
= (fi
!= NULL
);
931 if (within_current_scope
)
935 if (within_current_scope
&& reparse
)
944 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
945 /* If the meaning of expression itself changed, the old value is
946 no longer relevant. We don't want to report a watchpoint hit
947 to the user when the old value and the new value may actually
948 be completely different objects. */
954 /* If we failed to parse the expression, for example because
955 it refers to a global variable in a not-yet-loaded shared library,
956 don't try to insert watchpoint. We don't automatically delete
957 such watchpoint, though, since failure to parse expression
958 is different from out-of-scope watchpoint. */
959 if (within_current_scope
&& b
->exp
)
961 struct value
*val_chain
, *v
, *result
, *next
;
963 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
965 /* Avoid setting b->val if it's already set. The meaning of
966 b->val is 'the last value' user saw, and we should update
967 it only if we reported that last value to user. As it
968 happens, the code that reports it updates b->val directly. */
975 /* Look at each value on the value chain. */
976 for (v
= val_chain
; v
; v
= next
)
978 /* If it's a memory location, and GDB actually needed
979 its contents to evaluate the expression, then we
980 must watch it. If the first value returned is
981 still lazy, that means an error occurred reading it;
982 watch it anyway in case it becomes readable. */
983 if (VALUE_LVAL (v
) == lval_memory
984 && (v
== val_chain
|| ! value_lazy (v
)))
986 struct type
*vtype
= check_typedef (value_type (v
));
988 /* We only watch structs and arrays if user asked
989 for it explicitly, never if they just happen to
990 appear in the middle of some value chain. */
992 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
993 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
997 struct bp_location
*loc
, **tmp
;
999 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
1000 len
= TYPE_LENGTH (value_type (v
));
1002 if (b
->type
== bp_read_watchpoint
)
1004 else if (b
->type
== bp_access_watchpoint
)
1007 loc
= allocate_bp_location (b
, bp_hardware_watchpoint
);
1008 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1011 loc
->address
= addr
;
1013 loc
->watchpoint_type
= type
;
1017 next
= value_next (v
);
1022 if (reparse
&& b
->cond_string
!= NULL
)
1024 char *s
= b
->cond_string
;
1027 xfree (b
->loc
->cond
);
1028 b
->loc
->cond
= NULL
;
1030 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1033 else if (!within_current_scope
)
1035 printf_filtered (_("\
1036 Hardware watchpoint %d deleted because the program has left the block \n\
1037 in which its expression is valid.\n"),
1039 if (b
->related_breakpoint
)
1040 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1041 b
->disposition
= disp_del_at_next_stop
;
1044 /* Restore the selected frame. */
1045 select_frame (frame_find_by_id (saved_frame_id
));
1049 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1050 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1051 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1053 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1054 method for each breakpoint or catchpoint type. */
1056 insert_bp_location (struct bp_location
*bpt
,
1057 struct ui_file
*tmp_error_stream
,
1058 int *disabled_breaks
, int *process_warning
,
1059 int *hw_breakpoint_error
)
1063 if (!breakpoint_enabled (bpt
->owner
))
1066 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->inserted
|| bpt
->duplicate
)
1069 /* Initialize the target-specific information. */
1070 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1071 bpt
->target_info
.placed_address
= bpt
->address
;
1073 if (bpt
->loc_type
== bp_loc_software_breakpoint
1074 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1076 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1078 /* If the explicitly specified breakpoint type
1079 is not hardware breakpoint, check the memory map to see
1080 if the breakpoint address is in read only memory or not.
1081 Two important cases are:
1082 - location type is not hardware breakpoint, memory
1083 is readonly. We change the type of the location to
1084 hardware breakpoint.
1085 - location type is hardware breakpoint, memory is read-write.
1086 This means we've previously made the location hardware one, but
1087 then the memory map changed, so we undo.
1089 When breakpoints are removed, remove_breakpoints will
1090 use location types we've just set here, the only possible
1091 problem is that memory map has changed during running program,
1092 but it's not going to work anyway with current gdb. */
1093 struct mem_region
*mr
1094 = lookup_mem_region (bpt
->target_info
.placed_address
);
1098 if (automatic_hardware_breakpoints
)
1101 enum bp_loc_type new_type
;
1103 if (mr
->attrib
.mode
!= MEM_RW
)
1104 new_type
= bp_loc_hardware_breakpoint
;
1106 new_type
= bp_loc_software_breakpoint
;
1108 if (new_type
!= bpt
->loc_type
)
1110 static int said
= 0;
1111 bpt
->loc_type
= new_type
;
1114 fprintf_filtered (gdb_stdout
, _("\
1115 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1120 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1121 && mr
->attrib
.mode
!= MEM_RW
)
1122 warning (_("cannot set software breakpoint at readonly address %s"),
1123 paddr (bpt
->address
));
1127 /* First check to see if we have to handle an overlay. */
1128 if (overlay_debugging
== ovly_off
1129 || bpt
->section
== NULL
1130 || !(section_is_overlay (bpt
->section
)))
1132 /* No overlay handling: just set the breakpoint. */
1134 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1135 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1137 val
= target_insert_breakpoint (&bpt
->target_info
);
1141 /* This breakpoint is in an overlay section.
1142 Shall we set a breakpoint at the LMA? */
1143 if (!overlay_events_enabled
)
1145 /* Yes -- overlay event support is not active,
1146 so we must try to set a breakpoint at the LMA.
1147 This will not work for a hardware breakpoint. */
1148 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1149 warning (_("hardware breakpoint %d not supported in overlay!"),
1150 bpt
->owner
->number
);
1153 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1155 /* Set a software (trap) breakpoint at the LMA. */
1156 bpt
->overlay_target_info
= bpt
->target_info
;
1157 bpt
->overlay_target_info
.placed_address
= addr
;
1158 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1160 fprintf_unfiltered (tmp_error_stream
,
1161 "Overlay breakpoint %d failed: in ROM?",
1162 bpt
->owner
->number
);
1165 /* Shall we set a breakpoint at the VMA? */
1166 if (section_is_mapped (bpt
->section
))
1168 /* Yes. This overlay section is mapped into memory. */
1169 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1170 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1172 val
= target_insert_breakpoint (&bpt
->target_info
);
1176 /* No. This breakpoint will not be inserted.
1177 No error, but do not mark the bp as 'inserted'. */
1184 /* Can't set the breakpoint. */
1185 if (solib_address (bpt
->address
))
1187 /* See also: disable_breakpoints_in_shlibs. */
1189 bpt
->shlib_disabled
= 1;
1190 if (!*disabled_breaks
)
1192 fprintf_unfiltered (tmp_error_stream
,
1193 "Cannot insert breakpoint %d.\n",
1194 bpt
->owner
->number
);
1195 fprintf_unfiltered (tmp_error_stream
,
1196 "Temporarily disabling shared library breakpoints:\n");
1198 *disabled_breaks
= 1;
1199 fprintf_unfiltered (tmp_error_stream
,
1200 "breakpoint #%d\n", bpt
->owner
->number
);
1204 #ifdef ONE_PROCESS_WRITETEXT
1205 *process_warning
= 1;
1207 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1209 *hw_breakpoint_error
= 1;
1210 fprintf_unfiltered (tmp_error_stream
,
1211 "Cannot insert hardware breakpoint %d.\n",
1212 bpt
->owner
->number
);
1216 fprintf_unfiltered (tmp_error_stream
,
1217 "Cannot insert breakpoint %d.\n",
1218 bpt
->owner
->number
);
1219 fprintf_filtered (tmp_error_stream
,
1220 "Error accessing memory address ");
1221 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1222 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1223 safe_strerror (val
));
1234 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1235 /* NOTE drow/2003-09-08: This state only exists for removing
1236 watchpoints. It's not clear that it's necessary... */
1237 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1239 val
= target_insert_watchpoint (bpt
->address
,
1241 bpt
->watchpoint_type
);
1242 bpt
->inserted
= (val
!= -1);
1245 else if (bpt
->owner
->type
== bp_catch_fork
1246 || bpt
->owner
->type
== bp_catch_vfork
1247 || bpt
->owner
->type
== bp_catch_exec
)
1249 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1250 bpt
->owner
, RETURN_MASK_ERROR
);
1251 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1252 bpt
->owner
->number
);
1254 bpt
->owner
->enable_state
= bp_disabled
;
1258 /* We've already printed an error message if there was a problem
1259 inserting this catchpoint, and we've disabled the catchpoint,
1260 so just return success. */
1267 /* insert_breakpoints is used when starting or continuing the program.
1268 remove_breakpoints is used when the program stops.
1269 Both return zero if successful,
1270 or an `errno' value if could not write the inferior. */
1273 insert_breakpoints (void)
1275 struct breakpoint
*bpt
;
1276 struct bp_location
*b
, *temp
;
1279 int disabled_breaks
= 0;
1280 int hw_breakpoint_error
= 0;
1281 int process_warning
= 0;
1283 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1284 make_cleanup_ui_file_delete (tmp_error_stream
);
1286 /* Explicitly mark the warning -- this will only be printed if
1287 there was an error. */
1288 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1290 ALL_BREAKPOINTS (bpt
)
1291 if (is_hardware_watchpoint (bpt
))
1292 update_watchpoint (bpt
, 0 /* don't reparse */);
1294 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1296 if (!breakpoint_enabled (b
->owner
))
1299 /* There is no point inserting thread-specific breakpoints if the
1300 thread no longer exists. */
1301 if (b
->owner
->thread
!= -1
1302 && !valid_thread_id (b
->owner
->thread
))
1305 val
= insert_bp_location (b
, tmp_error_stream
,
1306 &disabled_breaks
, &process_warning
,
1307 &hw_breakpoint_error
);
1312 /* If we failed to insert all locations of a watchpoint,
1313 remove them, as half-inserted watchpoint is of limited use. */
1314 ALL_BREAKPOINTS (bpt
)
1316 int some_failed
= 0;
1317 struct bp_location
*loc
;
1319 if (!is_hardware_watchpoint (bpt
))
1322 if (bpt
->enable_state
!= bp_enabled
)
1325 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1333 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1335 remove_breakpoint (loc
, mark_uninserted
);
1337 hw_breakpoint_error
= 1;
1338 fprintf_unfiltered (tmp_error_stream
,
1339 "Could not insert hardware watchpoint %d.\n",
1347 /* If a hardware breakpoint or watchpoint was inserted, add a
1348 message about possibly exhausted resources. */
1349 if (hw_breakpoint_error
)
1351 fprintf_unfiltered (tmp_error_stream
,
1352 "Could not insert hardware breakpoints:\n\
1353 You may have requested too many hardware breakpoints/watchpoints.\n");
1355 #ifdef ONE_PROCESS_WRITETEXT
1356 if (process_warning
)
1357 fprintf_unfiltered (tmp_error_stream
,
1358 "The same program may be running in another process.");
1360 target_terminal_ours_for_output ();
1361 error_stream (tmp_error_stream
);
1366 remove_breakpoints (void)
1368 struct bp_location
*b
;
1371 ALL_BP_LOCATIONS (b
)
1375 val
= remove_breakpoint (b
, mark_uninserted
);
1384 remove_hw_watchpoints (void)
1386 struct bp_location
*b
;
1389 ALL_BP_LOCATIONS (b
)
1391 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1393 val
= remove_breakpoint (b
, mark_uninserted
);
1402 reattach_breakpoints (int pid
)
1404 struct bp_location
*b
;
1406 struct cleanup
*old_chain
= save_inferior_ptid ();
1407 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1408 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1410 make_cleanup_ui_file_delete (tmp_error_stream
);
1412 inferior_ptid
= pid_to_ptid (pid
);
1413 ALL_BP_LOCATIONS (b
)
1418 val
= insert_bp_location (b
, tmp_error_stream
,
1419 &dummy1
, &dummy2
, &dummy3
);
1422 do_cleanups (old_chain
);
1427 do_cleanups (old_chain
);
1432 update_breakpoints_after_exec (void)
1434 struct breakpoint
*b
;
1435 struct breakpoint
*temp
;
1437 /* Doing this first prevents the badness of having delete_breakpoint()
1438 write a breakpoint's current "shadow contents" to lift the bp. That
1439 shadow is NOT valid after an exec()! */
1440 mark_breakpoints_out ();
1442 ALL_BREAKPOINTS_SAFE (b
, temp
)
1444 /* Solib breakpoints must be explicitly reset after an exec(). */
1445 if (b
->type
== bp_shlib_event
)
1447 delete_breakpoint (b
);
1451 /* Thread event breakpoints must be set anew after an exec(),
1452 as must overlay event breakpoints. */
1453 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1455 delete_breakpoint (b
);
1459 /* Step-resume breakpoints are meaningless after an exec(). */
1460 if (b
->type
== bp_step_resume
)
1462 delete_breakpoint (b
);
1466 /* Don't delete an exec catchpoint, because else the inferior
1467 won't stop when it ought!
1469 Similarly, we probably ought to keep vfork catchpoints, 'cause
1470 on this target, we may not be able to stop when the vfork is
1471 seen, but only when the subsequent exec is seen. (And because
1472 deleting fork catchpoints here but not vfork catchpoints will
1473 seem mysterious to users, keep those too.) */
1474 if ((b
->type
== bp_catch_exec
) ||
1475 (b
->type
== bp_catch_vfork
) ||
1476 (b
->type
== bp_catch_fork
))
1481 /* bp_finish is a special case. The only way we ought to be able
1482 to see one of these when an exec() has happened, is if the user
1483 caught a vfork, and then said "finish". Ordinarily a finish just
1484 carries them to the call-site of the current callee, by setting
1485 a temporary bp there and resuming. But in this case, the finish
1486 will carry them entirely through the vfork & exec.
1488 We don't want to allow a bp_finish to remain inserted now. But
1489 we can't safely delete it, 'cause finish_command has a handle to
1490 the bp on a bpstat, and will later want to delete it. There's a
1491 chance (and I've seen it happen) that if we delete the bp_finish
1492 here, that its storage will get reused by the time finish_command
1493 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1494 We really must allow finish_command to delete a bp_finish.
1496 In the absense of a general solution for the "how do we know
1497 it's safe to delete something others may have handles to?"
1498 problem, what we'll do here is just uninsert the bp_finish, and
1499 let finish_command delete it.
1501 (We know the bp_finish is "doomed" in the sense that it's
1502 momentary, and will be deleted as soon as finish_command sees
1503 the inferior stopped. So it doesn't matter that the bp's
1504 address is probably bogus in the new a.out, unlike e.g., the
1505 solib breakpoints.) */
1507 if (b
->type
== bp_finish
)
1512 /* Without a symbolic address, we have little hope of the
1513 pre-exec() address meaning the same thing in the post-exec()
1515 if (b
->addr_string
== NULL
)
1517 delete_breakpoint (b
);
1521 /* FIXME what about longjmp breakpoints? Re-create them here? */
1522 create_overlay_event_breakpoint ("_ovly_debug_event");
1526 detach_breakpoints (int pid
)
1528 struct bp_location
*b
;
1530 struct cleanup
*old_chain
= save_inferior_ptid ();
1532 if (pid
== PIDGET (inferior_ptid
))
1533 error (_("Cannot detach breakpoints of inferior_ptid"));
1535 /* Set inferior_ptid; remove_breakpoint uses this global. */
1536 inferior_ptid
= pid_to_ptid (pid
);
1537 ALL_BP_LOCATIONS (b
)
1541 val
= remove_breakpoint (b
, mark_inserted
);
1544 do_cleanups (old_chain
);
1549 do_cleanups (old_chain
);
1554 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1558 if (b
->owner
->enable_state
== bp_permanent
)
1559 /* Permanent breakpoints cannot be inserted or removed. */
1562 if (b
->owner
->type
== bp_none
)
1563 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1566 if (b
->loc_type
== bp_loc_software_breakpoint
1567 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1569 /* "Normal" instruction breakpoint: either the standard
1570 trap-instruction bp (bp_breakpoint), or a
1571 bp_hardware_breakpoint. */
1573 /* First check to see if we have to handle an overlay. */
1574 if (overlay_debugging
== ovly_off
1575 || b
->section
== NULL
1576 || !(section_is_overlay (b
->section
)))
1578 /* No overlay handling: just remove the breakpoint. */
1580 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1581 val
= target_remove_hw_breakpoint (&b
->target_info
);
1583 val
= target_remove_breakpoint (&b
->target_info
);
1587 /* This breakpoint is in an overlay section.
1588 Did we set a breakpoint at the LMA? */
1589 if (!overlay_events_enabled
)
1591 /* Yes -- overlay event support is not active, so we
1592 should have set a breakpoint at the LMA. Remove it.
1594 /* Ignore any failures: if the LMA is in ROM, we will
1595 have already warned when we failed to insert it. */
1596 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1597 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1599 target_remove_breakpoint (&b
->overlay_target_info
);
1601 /* Did we set a breakpoint at the VMA?
1602 If so, we will have marked the breakpoint 'inserted'. */
1605 /* Yes -- remove it. Previously we did not bother to
1606 remove the breakpoint if the section had been
1607 unmapped, but let's not rely on that being safe. We
1608 don't know what the overlay manager might do. */
1609 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1610 val
= target_remove_hw_breakpoint (&b
->target_info
);
1612 /* However, we should remove *software* breakpoints only
1613 if the section is still mapped, or else we overwrite
1614 wrong code with the saved shadow contents. */
1615 else if (section_is_mapped (b
->section
))
1616 val
= target_remove_breakpoint (&b
->target_info
);
1622 /* No -- not inserted, so no need to remove. No error. */
1628 b
->inserted
= (is
== mark_inserted
);
1630 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1635 b
->inserted
= (is
== mark_inserted
);
1636 val
= target_remove_watchpoint (b
->address
, b
->length
,
1637 b
->watchpoint_type
);
1639 /* Failure to remove any of the hardware watchpoints comes here. */
1640 if ((is
== mark_uninserted
) && (b
->inserted
))
1641 warning (_("Could not remove hardware watchpoint %d."),
1644 else if ((b
->owner
->type
== bp_catch_fork
||
1645 b
->owner
->type
== bp_catch_vfork
||
1646 b
->owner
->type
== bp_catch_exec
)
1647 && breakpoint_enabled (b
->owner
)
1651 switch (b
->owner
->type
)
1654 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1656 case bp_catch_vfork
:
1657 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1660 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1663 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1668 b
->inserted
= (is
== mark_inserted
);
1674 /* Clear the "inserted" flag in all breakpoints. */
1677 mark_breakpoints_out (void)
1679 struct bp_location
*bpt
;
1681 ALL_BP_LOCATIONS (bpt
)
1685 /* Clear the "inserted" flag in all breakpoints and delete any
1686 breakpoints which should go away between runs of the program.
1688 Plus other such housekeeping that has to be done for breakpoints
1691 Note: this function gets called at the end of a run (by
1692 generic_mourn_inferior) and when a run begins (by
1693 init_wait_for_inferior). */
1698 breakpoint_init_inferior (enum inf_context context
)
1700 struct breakpoint
*b
, *temp
;
1701 struct bp_location
*bpt
;
1703 ALL_BP_LOCATIONS (bpt
)
1706 ALL_BREAKPOINTS_SAFE (b
, temp
)
1711 case bp_watchpoint_scope
:
1713 /* If the call dummy breakpoint is at the entry point it will
1714 cause problems when the inferior is rerun, so we better
1717 Also get rid of scope breakpoints. */
1718 delete_breakpoint (b
);
1722 case bp_hardware_watchpoint
:
1723 case bp_read_watchpoint
:
1724 case bp_access_watchpoint
:
1726 /* Likewise for watchpoints on local expressions. */
1727 if (b
->exp_valid_block
!= NULL
)
1728 delete_breakpoint (b
);
1729 else if (context
== inf_starting
)
1731 /* Reset val field to force reread of starting value
1732 in insert_breakpoints. */
1734 value_free (b
->val
);
1745 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1746 exists at PC. It returns ordinary_breakpoint_here if it's an
1747 ordinary breakpoint, or permanent_breakpoint_here if it's a
1748 permanent breakpoint.
1749 - When continuing from a location with an ordinary breakpoint, we
1750 actually single step once before calling insert_breakpoints.
1751 - When continuing from a localion with a permanent breakpoint, we
1752 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1753 the target, to advance the PC past the breakpoint. */
1755 enum breakpoint_here
1756 breakpoint_here_p (CORE_ADDR pc
)
1758 const struct bp_location
*bpt
;
1759 int any_breakpoint_here
= 0;
1761 ALL_BP_LOCATIONS (bpt
)
1763 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1764 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1767 if ((breakpoint_enabled (bpt
->owner
)
1768 || bpt
->owner
->enable_state
== bp_permanent
)
1769 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1771 if (overlay_debugging
1772 && section_is_overlay (bpt
->section
)
1773 && !section_is_mapped (bpt
->section
))
1774 continue; /* unmapped overlay -- can't be a match */
1775 else if (bpt
->owner
->enable_state
== bp_permanent
)
1776 return permanent_breakpoint_here
;
1778 any_breakpoint_here
= 1;
1782 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1786 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1787 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1788 This does not check for single-step breakpoints, which are
1789 inserted and removed using direct target manipulation. */
1792 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1794 const struct bp_location
*bpt
;
1796 ALL_BP_LOCATIONS (bpt
)
1798 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1799 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1803 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1805 if (overlay_debugging
1806 && section_is_overlay (bpt
->section
)
1807 && !section_is_mapped (bpt
->section
))
1808 continue; /* unmapped overlay -- can't be a match */
1816 /* Returns non-zero iff there's either regular breakpoint
1817 or a single step breakpoint inserted at PC. */
1820 breakpoint_inserted_here_p (CORE_ADDR pc
)
1822 if (regular_breakpoint_inserted_here_p (pc
))
1825 if (single_step_breakpoint_inserted_here_p (pc
))
1831 /* This function returns non-zero iff there is a software breakpoint
1835 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1837 const struct bp_location
*bpt
;
1838 int any_breakpoint_here
= 0;
1840 ALL_BP_LOCATIONS (bpt
)
1842 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1846 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1848 if (overlay_debugging
1849 && section_is_overlay (bpt
->section
)
1850 && !section_is_mapped (bpt
->section
))
1851 continue; /* unmapped overlay -- can't be a match */
1857 /* Also check for software single-step breakpoints. */
1858 if (single_step_breakpoint_inserted_here_p (pc
))
1864 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1865 PC is valid for process/thread PTID. */
1868 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1870 const struct bp_location
*bpt
;
1873 thread
= pid_to_thread_id (ptid
);
1875 ALL_BP_LOCATIONS (bpt
)
1877 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1878 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1881 if ((breakpoint_enabled (bpt
->owner
)
1882 || bpt
->owner
->enable_state
== bp_permanent
)
1883 && bpt
->address
== pc
1884 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1886 if (overlay_debugging
1887 && section_is_overlay (bpt
->section
)
1888 && !section_is_mapped (bpt
->section
))
1889 continue; /* unmapped overlay -- can't be a match */
1899 /* bpstat stuff. External routines' interfaces are documented
1903 ep_is_catchpoint (struct breakpoint
*ep
)
1906 (ep
->type
== bp_catch_load
)
1907 || (ep
->type
== bp_catch_unload
)
1908 || (ep
->type
== bp_catch_fork
)
1909 || (ep
->type
== bp_catch_vfork
)
1910 || (ep
->type
== bp_catch_exec
);
1912 /* ??rehrauer: Add more kinds here, as are implemented... */
1916 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1919 (ep
->type
== bp_catch_load
)
1920 || (ep
->type
== bp_catch_unload
);
1924 bpstat_free (bpstat bs
)
1926 if (bs
->old_val
!= NULL
)
1927 value_free (bs
->old_val
);
1928 free_command_lines (&bs
->commands
);
1932 /* Clear a bpstat so that it says we are not at any breakpoint.
1933 Also free any storage that is part of a bpstat. */
1936 bpstat_clear (bpstat
*bsp
)
1953 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1954 is part of the bpstat is copied as well. */
1957 bpstat_copy (bpstat bs
)
1961 bpstat retval
= NULL
;
1966 for (; bs
!= NULL
; bs
= bs
->next
)
1968 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1969 memcpy (tmp
, bs
, sizeof (*tmp
));
1970 if (bs
->commands
!= NULL
)
1971 tmp
->commands
= copy_command_lines (bs
->commands
);
1972 if (bs
->old_val
!= NULL
)
1973 tmp
->old_val
= value_copy (bs
->old_val
);
1976 /* This is the first thing in the chain. */
1986 /* Find the bpstat associated with this breakpoint */
1989 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1994 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1996 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2002 /* Find a step_resume breakpoint associated with this bpstat.
2003 (If there are multiple step_resume bp's on the list, this function
2004 will arbitrarily pick one.)
2006 It is an error to use this function if BPSTAT doesn't contain a
2007 step_resume breakpoint.
2009 See wait_for_inferior's use of this function. */
2011 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2015 gdb_assert (bsp
!= NULL
);
2017 current_thread
= pid_to_thread_id (inferior_ptid
);
2019 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2021 if ((bsp
->breakpoint_at
!= NULL
) &&
2022 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2023 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2024 bsp
->breakpoint_at
->owner
->thread
== -1))
2025 return bsp
->breakpoint_at
->owner
;
2028 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2032 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2033 at. *BSP upon return is a bpstat which points to the remaining
2034 breakpoints stopped at (but which is not guaranteed to be good for
2035 anything but further calls to bpstat_num).
2036 Return 0 if passed a bpstat which does not indicate any breakpoints.
2037 Return -1 if stopped at a breakpoint that has been deleted since
2039 Return 1 otherwise. */
2042 bpstat_num (bpstat
*bsp
, int *num
)
2044 struct breakpoint
*b
;
2047 return 0; /* No more breakpoint values */
2049 /* We assume we'll never have several bpstats that
2050 correspond to a single breakpoint -- otherwise,
2051 this function might return the same number more
2052 than once and this will look ugly. */
2053 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2054 *bsp
= (*bsp
)->next
;
2056 return -1; /* breakpoint that's been deleted since */
2058 *num
= b
->number
; /* We have its number */
2062 /* Modify BS so that the actions will not be performed. */
2065 bpstat_clear_actions (bpstat bs
)
2067 for (; bs
!= NULL
; bs
= bs
->next
)
2069 free_command_lines (&bs
->commands
);
2070 if (bs
->old_val
!= NULL
)
2072 value_free (bs
->old_val
);
2078 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2080 cleanup_executing_breakpoints (void *ignore
)
2082 executing_breakpoint_commands
= 0;
2085 /* Execute all the commands associated with all the breakpoints at this
2086 location. Any of these commands could cause the process to proceed
2087 beyond this point, etc. We look out for such changes by checking
2088 the global "breakpoint_proceeded" after each command. */
2091 bpstat_do_actions (bpstat
*bsp
)
2094 struct cleanup
*old_chain
;
2096 /* Avoid endless recursion if a `source' command is contained
2098 if (executing_breakpoint_commands
)
2101 executing_breakpoint_commands
= 1;
2102 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2105 /* Note that (as of this writing), our callers all appear to
2106 be passing us the address of global stop_bpstat. And, if
2107 our calls to execute_control_command cause the inferior to
2108 proceed, that global (and hence, *bsp) will change.
2110 We must be careful to not touch *bsp unless the inferior
2111 has not proceeded. */
2113 /* This pointer will iterate over the list of bpstat's. */
2116 breakpoint_proceeded
= 0;
2117 for (; bs
!= NULL
; bs
= bs
->next
)
2119 struct command_line
*cmd
;
2120 struct cleanup
*this_cmd_tree_chain
;
2122 /* Take ownership of the BSP's command tree, if it has one.
2124 The command tree could legitimately contain commands like
2125 'step' and 'next', which call clear_proceed_status, which
2126 frees stop_bpstat's command tree. To make sure this doesn't
2127 free the tree we're executing out from under us, we need to
2128 take ownership of the tree ourselves. Since a given bpstat's
2129 commands are only executed once, we don't need to copy it; we
2130 can clear the pointer in the bpstat, and make sure we free
2131 the tree when we're done. */
2134 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2138 execute_control_command (cmd
);
2140 if (breakpoint_proceeded
)
2146 /* We can free this command tree now. */
2147 do_cleanups (this_cmd_tree_chain
);
2149 if (breakpoint_proceeded
)
2150 /* The inferior is proceeded by the command; bomb out now.
2151 The bpstat chain has been blown away by wait_for_inferior.
2152 But since execution has stopped again, there is a new bpstat
2153 to look at, so start over. */
2156 do_cleanups (old_chain
);
2159 /* Print out the (old or new) value associated with a watchpoint. */
2162 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2165 fprintf_unfiltered (stream
, _("<unreadable>"));
2167 value_print (val
, stream
, 0, Val_pretty_default
);
2170 /* This is the normal print function for a bpstat. In the future,
2171 much of this logic could (should?) be moved to bpstat_stop_status,
2172 by having it set different print_it values.
2174 Current scheme: When we stop, bpstat_print() is called. It loops
2175 through the bpstat list of things causing this stop, calling the
2176 print_bp_stop_message function on each one. The behavior of the
2177 print_bp_stop_message function depends on the print_it field of
2178 bpstat. If such field so indicates, call this function here.
2180 Return values from this routine (ultimately used by bpstat_print()
2181 and normal_stop() to decide what to do):
2182 PRINT_NOTHING: Means we already printed all we needed to print,
2183 don't print anything else.
2184 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2185 that something to be followed by a location.
2186 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2187 that something to be followed by a location.
2188 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2191 static enum print_stop_action
2192 print_it_typical (bpstat bs
)
2194 struct cleanup
*old_chain
, *ui_out_chain
;
2195 struct breakpoint
*b
;
2196 const struct bp_location
*bl
;
2197 struct ui_stream
*stb
;
2198 stb
= ui_out_stream_new (uiout
);
2199 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2200 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2201 which has since been deleted. */
2202 if (bs
->breakpoint_at
== NULL
)
2203 return PRINT_UNKNOWN
;
2204 bl
= bs
->breakpoint_at
;
2210 case bp_hardware_breakpoint
:
2211 if (bl
->address
!= bl
->requested_address
)
2212 breakpoint_adjustment_warning (bl
->requested_address
,
2215 annotate_breakpoint (b
->number
);
2216 ui_out_text (uiout
, "\nBreakpoint ");
2217 if (ui_out_is_mi_like_p (uiout
))
2218 ui_out_field_string (uiout
, "reason",
2219 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2220 ui_out_field_int (uiout
, "bkptno", b
->number
);
2221 ui_out_text (uiout
, ", ");
2222 return PRINT_SRC_AND_LOC
;
2225 case bp_shlib_event
:
2226 /* Did we stop because the user set the stop_on_solib_events
2227 variable? (If so, we report this as a generic, "Stopped due
2228 to shlib event" message.) */
2229 printf_filtered (_("Stopped due to shared library event\n"));
2230 return PRINT_NOTHING
;
2233 case bp_thread_event
:
2234 /* Not sure how we will get here.
2235 GDB should not stop for these breakpoints. */
2236 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2237 return PRINT_NOTHING
;
2240 case bp_overlay_event
:
2241 /* By analogy with the thread event, GDB should not stop for these. */
2242 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2243 return PRINT_NOTHING
;
2247 annotate_catchpoint (b
->number
);
2248 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2250 b
->triggered_dll_pathname
);
2251 return PRINT_SRC_AND_LOC
;
2254 case bp_catch_unload
:
2255 annotate_catchpoint (b
->number
);
2256 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2258 b
->triggered_dll_pathname
);
2259 return PRINT_SRC_AND_LOC
;
2263 annotate_catchpoint (b
->number
);
2264 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2266 b
->forked_inferior_pid
);
2267 return PRINT_SRC_AND_LOC
;
2270 case bp_catch_vfork
:
2271 annotate_catchpoint (b
->number
);
2272 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2274 b
->forked_inferior_pid
);
2275 return PRINT_SRC_AND_LOC
;
2279 annotate_catchpoint (b
->number
);
2280 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2283 return PRINT_SRC_AND_LOC
;
2287 case bp_hardware_watchpoint
:
2288 annotate_watchpoint (b
->number
);
2289 if (ui_out_is_mi_like_p (uiout
))
2292 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2294 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2295 ui_out_text (uiout
, "\nOld value = ");
2296 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2297 ui_out_field_stream (uiout
, "old", stb
);
2298 ui_out_text (uiout
, "\nNew value = ");
2299 watchpoint_value_print (b
->val
, stb
->stream
);
2300 ui_out_field_stream (uiout
, "new", stb
);
2301 do_cleanups (ui_out_chain
);
2302 ui_out_text (uiout
, "\n");
2303 /* More than one watchpoint may have been triggered. */
2304 return PRINT_UNKNOWN
;
2307 case bp_read_watchpoint
:
2308 if (ui_out_is_mi_like_p (uiout
))
2311 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2313 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2314 ui_out_text (uiout
, "\nValue = ");
2315 watchpoint_value_print (b
->val
, stb
->stream
);
2316 ui_out_field_stream (uiout
, "value", stb
);
2317 do_cleanups (ui_out_chain
);
2318 ui_out_text (uiout
, "\n");
2319 return PRINT_UNKNOWN
;
2322 case bp_access_watchpoint
:
2323 if (bs
->old_val
!= NULL
)
2325 annotate_watchpoint (b
->number
);
2326 if (ui_out_is_mi_like_p (uiout
))
2329 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2331 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2332 ui_out_text (uiout
, "\nOld value = ");
2333 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2334 ui_out_field_stream (uiout
, "old", stb
);
2335 ui_out_text (uiout
, "\nNew value = ");
2340 if (ui_out_is_mi_like_p (uiout
))
2343 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2344 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2345 ui_out_text (uiout
, "\nValue = ");
2347 watchpoint_value_print (b
->val
, stb
->stream
);
2348 ui_out_field_stream (uiout
, "new", stb
);
2349 do_cleanups (ui_out_chain
);
2350 ui_out_text (uiout
, "\n");
2351 return PRINT_UNKNOWN
;
2354 /* Fall through, we don't deal with these types of breakpoints
2358 if (ui_out_is_mi_like_p (uiout
))
2361 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2362 return PRINT_UNKNOWN
;
2366 if (ui_out_is_mi_like_p (uiout
))
2369 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2370 return PRINT_UNKNOWN
;
2375 case bp_longjmp_resume
:
2376 case bp_step_resume
:
2377 case bp_watchpoint_scope
:
2380 return PRINT_UNKNOWN
;
2384 /* Generic routine for printing messages indicating why we
2385 stopped. The behavior of this function depends on the value
2386 'print_it' in the bpstat structure. Under some circumstances we
2387 may decide not to print anything here and delegate the task to
2390 static enum print_stop_action
2391 print_bp_stop_message (bpstat bs
)
2393 switch (bs
->print_it
)
2396 /* Nothing should be printed for this bpstat entry. */
2397 return PRINT_UNKNOWN
;
2401 /* We still want to print the frame, but we already printed the
2402 relevant messages. */
2403 return PRINT_SRC_AND_LOC
;
2406 case print_it_normal
:
2408 const struct bp_location
*bl
= bs
->breakpoint_at
;
2409 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2411 /* Normal case. Call the breakpoint's print_it method, or
2412 print_it_typical. */
2413 /* FIXME: how breakpoint can ever be NULL here? */
2414 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2415 return b
->ops
->print_it (b
);
2417 return print_it_typical (bs
);
2422 internal_error (__FILE__
, __LINE__
,
2423 _("print_bp_stop_message: unrecognized enum value"));
2428 /* Print a message indicating what happened. This is called from
2429 normal_stop(). The input to this routine is the head of the bpstat
2430 list - a list of the eventpoints that caused this stop. This
2431 routine calls the generic print routine for printing a message
2432 about reasons for stopping. This will print (for example) the
2433 "Breakpoint n," part of the output. The return value of this
2436 PRINT_UNKNOWN: Means we printed nothing
2437 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2438 code to print the location. An example is
2439 "Breakpoint 1, " which should be followed by
2441 PRINT_SRC_ONLY: Means we printed something, but there is no need
2442 to also print the location part of the message.
2443 An example is the catch/throw messages, which
2444 don't require a location appended to the end.
2445 PRINT_NOTHING: We have done some printing and we don't need any
2446 further info to be printed.*/
2448 enum print_stop_action
2449 bpstat_print (bpstat bs
)
2453 /* Maybe another breakpoint in the chain caused us to stop.
2454 (Currently all watchpoints go on the bpstat whether hit or not.
2455 That probably could (should) be changed, provided care is taken
2456 with respect to bpstat_explains_signal). */
2457 for (; bs
; bs
= bs
->next
)
2459 val
= print_bp_stop_message (bs
);
2460 if (val
== PRINT_SRC_ONLY
2461 || val
== PRINT_SRC_AND_LOC
2462 || val
== PRINT_NOTHING
)
2466 /* We reached the end of the chain, or we got a null BS to start
2467 with and nothing was printed. */
2468 return PRINT_UNKNOWN
;
2471 /* Evaluate the expression EXP and return 1 if value is zero.
2472 This is used inside a catch_errors to evaluate the breakpoint condition.
2473 The argument is a "struct expression *" that has been cast to char * to
2474 make it pass through catch_errors. */
2477 breakpoint_cond_eval (void *exp
)
2479 struct value
*mark
= value_mark ();
2480 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2481 value_free_to_mark (mark
);
2485 /* Allocate a new bpstat and chain it to the current one. */
2488 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2492 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2494 bs
->breakpoint_at
= bl
;
2495 /* If the condition is false, etc., don't do the commands. */
2496 bs
->commands
= NULL
;
2498 bs
->print_it
= print_it_normal
;
2502 /* The target has stopped with waitstatus WS. Check if any hardware
2503 watchpoints have triggered, according to the target. */
2506 watchpoints_triggered (struct target_waitstatus
*ws
)
2508 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2510 struct breakpoint
*b
;
2512 if (!stopped_by_watchpoint
)
2514 /* We were not stopped by a watchpoint. Mark all watchpoints
2515 as not triggered. */
2517 if (b
->type
== bp_hardware_watchpoint
2518 || b
->type
== bp_read_watchpoint
2519 || b
->type
== bp_access_watchpoint
)
2520 b
->watchpoint_triggered
= watch_triggered_no
;
2525 if (!target_stopped_data_address (¤t_target
, &addr
))
2527 /* We were stopped by a watchpoint, but we don't know where.
2528 Mark all watchpoints as unknown. */
2530 if (b
->type
== bp_hardware_watchpoint
2531 || b
->type
== bp_read_watchpoint
2532 || b
->type
== bp_access_watchpoint
)
2533 b
->watchpoint_triggered
= watch_triggered_unknown
;
2535 return stopped_by_watchpoint
;
2538 /* The target could report the data address. Mark watchpoints
2539 affected by this data address as triggered, and all others as not
2543 if (b
->type
== bp_hardware_watchpoint
2544 || b
->type
== bp_read_watchpoint
2545 || b
->type
== bp_access_watchpoint
)
2547 struct bp_location
*loc
;
2550 b
->watchpoint_triggered
= watch_triggered_no
;
2551 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2552 /* Exact match not required. Within range is
2554 if (addr
>= loc
->address
2555 && addr
< loc
->address
+ loc
->length
)
2557 b
->watchpoint_triggered
= watch_triggered_yes
;
2565 /* Possible return values for watchpoint_check (this can't be an enum
2566 because of check_errors). */
2567 /* The watchpoint has been deleted. */
2568 #define WP_DELETED 1
2569 /* The value has changed. */
2570 #define WP_VALUE_CHANGED 2
2571 /* The value has not changed. */
2572 #define WP_VALUE_NOT_CHANGED 3
2574 #define BP_TEMPFLAG 1
2575 #define BP_HARDWAREFLAG 2
2577 /* Check watchpoint condition. */
2580 watchpoint_check (void *p
)
2582 bpstat bs
= (bpstat
) p
;
2583 struct breakpoint
*b
;
2584 struct frame_info
*fr
;
2585 int within_current_scope
;
2587 b
= bs
->breakpoint_at
->owner
;
2589 if (b
->exp_valid_block
== NULL
)
2590 within_current_scope
= 1;
2593 /* There is no current frame at this moment. If we're going to have
2594 any chance of handling watchpoints on local variables, we'll need
2595 the frame chain (so we can determine if we're in scope). */
2596 reinit_frame_cache ();
2597 fr
= frame_find_by_id (b
->watchpoint_frame
);
2598 within_current_scope
= (fr
!= NULL
);
2600 /* If we've gotten confused in the unwinder, we might have
2601 returned a frame that can't describe this variable. */
2602 if (within_current_scope
2603 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2604 within_current_scope
= 0;
2606 /* in_function_epilogue_p() returns a non-zero value if we're still
2607 in the function but the stack frame has already been invalidated.
2608 Since we can't rely on the values of local variables after the
2609 stack has been destroyed, we are treating the watchpoint in that
2610 state as `not changed' without further checking.
2612 vinschen/2003-09-04: The former implementation left out the case
2613 that the watchpoint frame couldn't be found by frame_find_by_id()
2614 because the current PC is currently in an epilogue. Calling
2615 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2616 if ((!within_current_scope
|| fr
== get_current_frame ())
2617 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2618 return WP_VALUE_NOT_CHANGED
;
2619 if (fr
&& within_current_scope
)
2620 /* If we end up stopping, the current frame will get selected
2621 in normal_stop. So this call to select_frame won't affect
2626 if (within_current_scope
)
2628 /* We use value_{,free_to_}mark because it could be a
2629 *long* time before we return to the command level and
2630 call free_all_values. We can't call free_all_values because
2631 we might be in the middle of evaluating a function call. */
2633 struct value
*mark
= value_mark ();
2634 struct value
*new_val
;
2636 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2637 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2638 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2640 if (new_val
!= NULL
)
2642 release_value (new_val
);
2643 value_free_to_mark (mark
);
2645 bs
->old_val
= b
->val
;
2648 /* We will stop here */
2649 return WP_VALUE_CHANGED
;
2653 /* Nothing changed, don't do anything. */
2654 value_free_to_mark (mark
);
2655 /* We won't stop here */
2656 return WP_VALUE_NOT_CHANGED
;
2661 /* This seems like the only logical thing to do because
2662 if we temporarily ignored the watchpoint, then when
2663 we reenter the block in which it is valid it contains
2664 garbage (in the case of a function, it may have two
2665 garbage values, one before and one after the prologue).
2666 So we can't even detect the first assignment to it and
2667 watch after that (since the garbage may or may not equal
2668 the first value assigned). */
2669 /* We print all the stop information in print_it_typical(), but
2670 in this case, by the time we call print_it_typical() this bp
2671 will be deleted already. So we have no choice but print the
2672 information here. */
2673 if (ui_out_is_mi_like_p (uiout
))
2675 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2676 ui_out_text (uiout
, "\nWatchpoint ");
2677 ui_out_field_int (uiout
, "wpnum", b
->number
);
2678 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2679 which its expression is valid.\n");
2681 if (b
->related_breakpoint
)
2682 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2683 b
->disposition
= disp_del_at_next_stop
;
2689 /* Get a bpstat associated with having just stopped at address
2690 BP_ADDR in thread PTID.
2692 Determine whether we stopped at a breakpoint, etc, or whether we
2693 don't understand this stop. Result is a chain of bpstat's such that:
2695 if we don't understand the stop, the result is a null pointer.
2697 if we understand why we stopped, the result is not null.
2699 Each element of the chain refers to a particular breakpoint or
2700 watchpoint at which we have stopped. (We may have stopped for
2701 several reasons concurrently.)
2703 Each element of the chain has valid next, breakpoint_at,
2704 commands, FIXME??? fields. */
2707 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2709 struct breakpoint
*b
= NULL
;
2710 const struct bp_location
*bl
;
2711 /* Root of the chain of bpstat's */
2712 struct bpstats root_bs
[1];
2713 /* Pointer to the last thing in the chain currently. */
2714 bpstat bs
= root_bs
;
2715 int thread_id
= pid_to_thread_id (ptid
);
2717 ALL_BP_LOCATIONS (bl
)
2721 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2724 if (b
->type
!= bp_watchpoint
2725 && b
->type
!= bp_hardware_watchpoint
2726 && b
->type
!= bp_read_watchpoint
2727 && b
->type
!= bp_access_watchpoint
2728 && b
->type
!= bp_hardware_breakpoint
2729 && b
->type
!= bp_catch_fork
2730 && b
->type
!= bp_catch_vfork
2731 && b
->type
!= bp_catch_exec
) /* a non-watchpoint bp */
2733 if (bl
->address
!= bp_addr
) /* address doesn't match */
2735 if (overlay_debugging
/* unmapped overlay section */
2736 && section_is_overlay (bl
->section
)
2737 && !section_is_mapped (bl
->section
))
2741 /* Continuable hardware watchpoints are treated as non-existent if the
2742 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2743 some data address). Otherwise gdb won't stop on a break instruction
2744 in the code (not from a breakpoint) when a hardware watchpoint has
2745 been defined. Also skip watchpoints which we know did not trigger
2746 (did not match the data address). */
2748 if ((b
->type
== bp_hardware_watchpoint
2749 || b
->type
== bp_read_watchpoint
2750 || b
->type
== bp_access_watchpoint
)
2751 && b
->watchpoint_triggered
== watch_triggered_no
)
2754 if (b
->type
== bp_hardware_breakpoint
)
2756 if (bl
->address
!= bp_addr
)
2758 if (overlay_debugging
/* unmapped overlay section */
2759 && section_is_overlay (bl
->section
)
2760 && !section_is_mapped (bl
->section
))
2764 /* Is this a catchpoint of a load or unload? If so, did we
2765 get a load or unload of the specified library? If not,
2767 if ((b
->type
== bp_catch_load
)
2768 #if defined(SOLIB_HAVE_LOAD_EVENT)
2769 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2770 || ((b
->dll_pathname
!= NULL
)
2771 && (strcmp (b
->dll_pathname
,
2772 SOLIB_LOADED_LIBRARY_PATHNAME (
2773 PIDGET (inferior_ptid
)))
2779 if ((b
->type
== bp_catch_unload
)
2780 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2781 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2782 || ((b
->dll_pathname
!= NULL
)
2783 && (strcmp (b
->dll_pathname
,
2784 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2785 PIDGET (inferior_ptid
)))
2791 if ((b
->type
== bp_catch_fork
)
2792 && !inferior_has_forked (PIDGET (inferior_ptid
),
2793 &b
->forked_inferior_pid
))
2796 if ((b
->type
== bp_catch_vfork
)
2797 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2798 &b
->forked_inferior_pid
))
2801 if ((b
->type
== bp_catch_exec
)
2802 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2805 /* For hardware watchpoints, we look only at the first location.
2806 The watchpoint_check function will work on entire expression,
2807 not the individual locations. For read watchopints, the
2808 watchpoints_triggered function have checked all locations
2811 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
2814 /* Come here if it's a watchpoint, or if the break address matches */
2816 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
2818 /* Watchpoints may change this, if not found to have triggered. */
2822 if (b
->type
== bp_watchpoint
2823 || b
->type
== bp_read_watchpoint
2824 || b
->type
== bp_access_watchpoint
2825 || b
->type
== bp_hardware_watchpoint
)
2829 int must_check_value
= 0;
2831 if (b
->type
== bp_watchpoint
)
2832 /* For a software watchpoint, we must always check the
2834 must_check_value
= 1;
2835 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2836 /* We have a hardware watchpoint (read, write, or access)
2837 and the target earlier reported an address watched by
2839 must_check_value
= 1;
2840 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2841 && b
->type
== bp_hardware_watchpoint
)
2842 /* We were stopped by a hardware watchpoint, but the target could
2843 not report the data address. We must check the watchpoint's
2844 value. Access and read watchpoints are out of luck; without
2845 a data address, we can't figure it out. */
2846 must_check_value
= 1;
2848 if (must_check_value
)
2850 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2852 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2853 int e
= catch_errors (watchpoint_check
, bs
, message
,
2855 do_cleanups (cleanups
);
2859 /* We've already printed what needs to be printed. */
2860 bs
->print_it
= print_it_done
;
2863 case WP_VALUE_CHANGED
:
2864 if (b
->type
== bp_read_watchpoint
)
2866 /* Don't stop: read watchpoints shouldn't fire if
2867 the value has changed. This is for targets
2868 which cannot set read-only watchpoints. */
2869 bs
->print_it
= print_it_noop
;
2875 case WP_VALUE_NOT_CHANGED
:
2876 if (b
->type
== bp_hardware_watchpoint
2877 || b
->type
== bp_watchpoint
)
2879 /* Don't stop: write watchpoints shouldn't fire if
2880 the value hasn't changed. */
2881 bs
->print_it
= print_it_noop
;
2891 /* Error from catch_errors. */
2892 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2893 if (b
->related_breakpoint
)
2894 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2895 b
->disposition
= disp_del_at_next_stop
;
2896 /* We've already printed what needs to be printed. */
2897 bs
->print_it
= print_it_done
;
2901 else /* must_check_value == 0 */
2903 /* This is a case where some watchpoint(s) triggered, but
2904 not at the address of this watchpoint, or else no
2905 watchpoint triggered after all. So don't print
2906 anything for this watchpoint. */
2907 bs
->print_it
= print_it_noop
;
2914 /* By definition, an encountered breakpoint is a triggered
2919 if (frame_id_p (b
->frame_id
)
2920 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2924 int value_is_zero
= 0;
2926 /* If this is a scope breakpoint, mark the associated
2927 watchpoint as triggered so that we will handle the
2928 out-of-scope event. We'll get to the watchpoint next
2930 if (b
->type
== bp_watchpoint_scope
)
2931 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2933 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2935 /* Need to select the frame, with all that implies
2936 so that the conditions will have the right context. */
2937 select_frame (get_current_frame ());
2939 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2940 "Error in testing breakpoint condition:\n",
2942 /* FIXME-someday, should give breakpoint # */
2945 if (bl
->cond
&& value_is_zero
)
2948 /* Don't consider this a hit. */
2951 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2954 /* Don't consider this a hit. */
2957 else if (b
->ignore_count
> 0)
2960 annotate_ignore_count_change ();
2963 else if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
2964 /* We do not stop for these. */
2968 /* We will stop here */
2969 if (b
->disposition
== disp_disable
)
2970 b
->enable_state
= bp_disabled
;
2973 bs
->commands
= b
->commands
;
2975 (strcmp ("silent", bs
->commands
->line
) == 0
2976 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
2978 bs
->commands
= bs
->commands
->next
;
2981 bs
->commands
= copy_command_lines (bs
->commands
);
2984 /* Print nothing for this entry if we dont stop or if we dont print. */
2985 if (bs
->stop
== 0 || bs
->print
== 0)
2986 bs
->print_it
= print_it_noop
;
2989 bs
->next
= NULL
; /* Terminate the chain */
2990 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2992 /* If we aren't stopping, the value of some hardware watchpoint may
2993 not have changed, but the intermediate memory locations we are
2994 watching may have. Don't bother if we're stopping; this will get
2996 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3001 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3003 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3004 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3005 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3007 /* remove/insert can invalidate bs->breakpoint_at, if this
3008 location is no longer used by the watchpoint. Prevent
3009 further code from trying to use it. */
3010 bs
->breakpoint_at
= NULL
;
3011 remove_breakpoints ();
3012 insert_breakpoints ();
3016 return root_bs
->next
;
3019 /* Tell what to do about this bpstat. */
3021 bpstat_what (bpstat bs
)
3023 /* Classify each bpstat as one of the following. */
3026 /* This bpstat element has no effect on the main_action. */
3029 /* There was a watchpoint, stop but don't print. */
3032 /* There was a watchpoint, stop and print. */
3035 /* There was a breakpoint but we're not stopping. */
3038 /* There was a breakpoint, stop but don't print. */
3041 /* There was a breakpoint, stop and print. */
3044 /* We hit the longjmp breakpoint. */
3047 /* We hit the longjmp_resume breakpoint. */
3050 /* We hit the step_resume breakpoint. */
3053 /* We hit the shared library event breakpoint. */
3056 /* We caught a shared library event. */
3059 /* This is just used to count how many enums there are. */
3063 /* Here is the table which drives this routine. So that we can
3064 format it pretty, we define some abbreviations for the
3065 enum bpstat_what codes. */
3066 #define kc BPSTAT_WHAT_KEEP_CHECKING
3067 #define ss BPSTAT_WHAT_STOP_SILENT
3068 #define sn BPSTAT_WHAT_STOP_NOISY
3069 #define sgl BPSTAT_WHAT_SINGLE
3070 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3071 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3072 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
3073 #define sr BPSTAT_WHAT_STEP_RESUME
3074 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3075 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3077 /* "Can't happen." Might want to print an error message.
3078 abort() is not out of the question, but chances are GDB is just
3079 a bit confused, not unusable. */
3080 #define err BPSTAT_WHAT_STOP_NOISY
3082 /* Given an old action and a class, come up with a new action. */
3083 /* One interesting property of this table is that wp_silent is the same
3084 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3085 after stopping, the check for whether to step over a breakpoint
3086 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3087 reference to how we stopped. We retain separate wp_silent and
3088 bp_silent codes in case we want to change that someday.
3090 Another possibly interesting property of this table is that
3091 there's a partial ordering, priority-like, of the actions. Once
3092 you've decided that some action is appropriate, you'll never go
3093 back and decide something of a lower priority is better. The
3096 kc < clr sgl shl shlr slr sn sr ss
3097 sgl < clrs shl shlr slr sn sr ss
3098 slr < err shl shlr sn sr ss
3099 clr < clrs err shl shlr sn sr ss
3100 clrs < err shl shlr sn sr ss
3107 What I think this means is that we don't need a damned table
3108 here. If you just put the rows and columns in the right order,
3109 it'd look awfully regular. We could simply walk the bpstat list
3110 and choose the highest priority action we find, with a little
3111 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3112 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3113 is messy anyway). */
3115 /* step_resume entries: a step resume breakpoint overrides another
3116 breakpoint of signal handling (see comment in wait_for_inferior
3117 at where we set the step_resume breakpoint). */
3119 static const enum bpstat_what_main_action
3120 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3123 /* kc ss sn sgl slr clr clrs sr shl shlr
3126 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, shl
, shlr
},
3128 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3130 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3132 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, shl
, shlr
},
3134 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3136 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3138 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, shl
, shlr
},
3140 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, shl
, shlr
},
3142 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3144 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3146 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3161 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3162 struct bpstat_what retval
;
3164 retval
.call_dummy
= 0;
3165 for (; bs
!= NULL
; bs
= bs
->next
)
3167 enum class bs_class
= no_effect
;
3168 if (bs
->breakpoint_at
== NULL
)
3169 /* I suspect this can happen if it was a momentary breakpoint
3170 which has since been deleted. */
3172 switch (bs
->breakpoint_at
->owner
->type
)
3178 case bp_hardware_breakpoint
:
3184 bs_class
= bp_noisy
;
3186 bs_class
= bp_silent
;
3189 bs_class
= bp_nostop
;
3192 case bp_hardware_watchpoint
:
3193 case bp_read_watchpoint
:
3194 case bp_access_watchpoint
:
3198 bs_class
= wp_noisy
;
3200 bs_class
= wp_silent
;
3203 /* There was a watchpoint, but we're not stopping.
3204 This requires no further action. */
3205 bs_class
= no_effect
;
3208 bs_class
= long_jump
;
3210 case bp_longjmp_resume
:
3211 bs_class
= long_resume
;
3213 case bp_step_resume
:
3216 bs_class
= step_resume
;
3219 /* It is for the wrong frame. */
3220 bs_class
= bp_nostop
;
3222 case bp_watchpoint_scope
:
3223 bs_class
= bp_nostop
;
3225 case bp_shlib_event
:
3226 bs_class
= shlib_event
;
3228 case bp_thread_event
:
3229 case bp_overlay_event
:
3230 bs_class
= bp_nostop
;
3233 case bp_catch_unload
:
3234 /* Only if this catchpoint triggered should we cause the
3235 step-out-of-dld behaviour. Otherwise, we ignore this
3238 bs_class
= catch_shlib_event
;
3240 bs_class
= no_effect
;
3243 case bp_catch_vfork
:
3248 bs_class
= bp_noisy
;
3250 bs_class
= bp_silent
;
3253 /* There was a catchpoint, but we're not stopping.
3254 This requires no further action. */
3255 bs_class
= no_effect
;
3258 /* Make sure the action is stop (silent or noisy),
3259 so infrun.c pops the dummy frame. */
3260 bs_class
= bp_silent
;
3261 retval
.call_dummy
= 1;
3264 current_action
= table
[(int) bs_class
][(int) current_action
];
3266 retval
.main_action
= current_action
;
3270 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3271 without hardware support). This isn't related to a specific bpstat,
3272 just to things like whether watchpoints are set. */
3275 bpstat_should_step (void)
3277 struct breakpoint
*b
;
3279 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3286 /* Given a bpstat that records zero or more triggered eventpoints, this
3287 function returns another bpstat which contains only the catchpoints
3288 on that first list, if any. */
3290 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3292 struct bpstats root_bs
[1];
3293 bpstat bs
= root_bs
;
3294 struct breakpoint
*ep
;
3297 bpstat_clear (cp_list
);
3298 root_bs
->next
= NULL
;
3300 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3302 /* Is this eventpoint a catchpoint? If not, ignore it. */
3303 ep
= ep_list
->breakpoint_at
->owner
;
3306 if ((ep
->type
!= bp_catch_load
) &&
3307 (ep
->type
!= bp_catch_unload
))
3308 /* pai: (temp) ADD fork/vfork here!! */
3311 /* Yes; add it to the list. */
3312 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3317 #if defined(SOLIB_ADD)
3318 /* Also, for each triggered catchpoint, tag it with the name of
3319 the library that caused this trigger. (We copy the name now,
3320 because it's only guaranteed to be available NOW, when the
3321 catchpoint triggers. Clients who may wish to know the name
3322 later must get it from the catchpoint itself.) */
3323 if (ep
->triggered_dll_pathname
!= NULL
)
3324 xfree (ep
->triggered_dll_pathname
);
3325 if (ep
->type
== bp_catch_load
)
3326 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3327 PIDGET (inferior_ptid
));
3329 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3330 PIDGET (inferior_ptid
));
3332 dll_pathname
= NULL
;
3336 ep
->triggered_dll_pathname
= (char *)
3337 xmalloc (strlen (dll_pathname
) + 1);
3338 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3341 ep
->triggered_dll_pathname
= NULL
;
3347 static void print_breakpoint_location (struct breakpoint
*b
,
3348 struct bp_location
*loc
,
3350 struct ui_stream
*stb
)
3355 = find_pc_sect_function (loc
->address
, loc
->section
);
3358 ui_out_text (uiout
, "in ");
3359 ui_out_field_string (uiout
, "func",
3360 SYMBOL_PRINT_NAME (sym
));
3361 ui_out_wrap_hint (uiout
, wrap_indent
);
3362 ui_out_text (uiout
, " at ");
3364 ui_out_field_string (uiout
, "file", b
->source_file
);
3365 ui_out_text (uiout
, ":");
3367 if (ui_out_is_mi_like_p (uiout
))
3369 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3370 char *fullname
= symtab_to_fullname (sal
.symtab
);
3373 ui_out_field_string (uiout
, "fullname", fullname
);
3376 ui_out_field_int (uiout
, "line", b
->line_number
);
3380 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3384 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3385 ui_out_field_stream (uiout
, "at", stb
);
3389 /* Print B to gdb_stdout. */
3391 print_one_breakpoint_location (struct breakpoint
*b
,
3392 struct bp_location
*loc
,
3394 CORE_ADDR
*last_addr
)
3396 struct command_line
*l
;
3398 struct ep_type_description
3403 static struct ep_type_description bptypes
[] =
3405 {bp_none
, "?deleted?"},
3406 {bp_breakpoint
, "breakpoint"},
3407 {bp_hardware_breakpoint
, "hw breakpoint"},
3408 {bp_until
, "until"},
3409 {bp_finish
, "finish"},
3410 {bp_watchpoint
, "watchpoint"},
3411 {bp_hardware_watchpoint
, "hw watchpoint"},
3412 {bp_read_watchpoint
, "read watchpoint"},
3413 {bp_access_watchpoint
, "acc watchpoint"},
3414 {bp_longjmp
, "longjmp"},
3415 {bp_longjmp_resume
, "longjmp resume"},
3416 {bp_step_resume
, "step resume"},
3417 {bp_watchpoint_scope
, "watchpoint scope"},
3418 {bp_call_dummy
, "call dummy"},
3419 {bp_shlib_event
, "shlib events"},
3420 {bp_thread_event
, "thread events"},
3421 {bp_overlay_event
, "overlay events"},
3422 {bp_catch_load
, "catch load"},
3423 {bp_catch_unload
, "catch unload"},
3424 {bp_catch_fork
, "catch fork"},
3425 {bp_catch_vfork
, "catch vfork"},
3426 {bp_catch_exec
, "catch exec"}
3429 static char *bpdisps
[] =
3430 {"del", "dstp", "dis", "keep"};
3431 static char bpenables
[] = "nynny";
3432 char wrap_indent
[80];
3433 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3434 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3435 struct cleanup
*bkpt_chain
;
3437 int header_of_multiple
= 0;
3438 int part_of_multiple
= (loc
!= NULL
);
3440 gdb_assert (!loc
|| loc_number
!= 0);
3441 /* See comment in print_one_breakpoint concerning
3442 treatment of breakpoints with single disabled
3446 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3447 header_of_multiple
= 1;
3452 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3456 if (part_of_multiple
)
3459 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3460 ui_out_field_string (uiout
, "number", formatted
);
3465 ui_out_field_int (uiout
, "number", b
->number
);
3470 if (part_of_multiple
)
3471 ui_out_field_skip (uiout
, "type");
3474 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3475 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3476 internal_error (__FILE__
, __LINE__
,
3477 _("bptypes table does not describe type #%d."),
3479 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3484 if (part_of_multiple
)
3485 ui_out_field_skip (uiout
, "disp");
3487 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3492 if (part_of_multiple
)
3493 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3495 ui_out_field_fmt (uiout
, "enabled", "%c",
3496 bpenables
[(int) b
->enable_state
]);
3497 ui_out_spaces (uiout
, 2);
3501 strcpy (wrap_indent
, " ");
3504 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3505 strcat (wrap_indent
, " ");
3507 strcat (wrap_indent
, " ");
3510 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3512 /* Although the print_one can possibly print
3513 all locations, calling it here is not likely
3514 to get any nice result. So, make sure there's
3515 just one location. */
3516 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3517 b
->ops
->print_one (b
, last_addr
);
3523 internal_error (__FILE__
, __LINE__
,
3524 _("print_one_breakpoint: bp_none encountered\n"));
3528 case bp_hardware_watchpoint
:
3529 case bp_read_watchpoint
:
3530 case bp_access_watchpoint
:
3531 /* Field 4, the address, is omitted (which makes the columns
3532 not line up too nicely with the headers, but the effect
3533 is relatively readable). */
3535 ui_out_field_skip (uiout
, "addr");
3537 print_expression (b
->exp
, stb
->stream
);
3538 ui_out_field_stream (uiout
, "what", stb
);
3542 case bp_catch_unload
:
3543 /* Field 4, the address, is omitted (which makes the columns
3544 not line up too nicely with the headers, but the effect
3545 is relatively readable). */
3547 ui_out_field_skip (uiout
, "addr");
3549 if (b
->dll_pathname
== NULL
)
3551 ui_out_field_string (uiout
, "what", "<any library>");
3552 ui_out_spaces (uiout
, 1);
3556 ui_out_text (uiout
, "library \"");
3557 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3558 ui_out_text (uiout
, "\" ");
3563 case bp_catch_vfork
:
3564 /* Field 4, the address, is omitted (which makes the columns
3565 not line up too nicely with the headers, but the effect
3566 is relatively readable). */
3568 ui_out_field_skip (uiout
, "addr");
3570 if (b
->forked_inferior_pid
!= 0)
3572 ui_out_text (uiout
, "process ");
3573 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3574 ui_out_spaces (uiout
, 1);
3579 /* Field 4, the address, is omitted (which makes the columns
3580 not line up too nicely with the headers, but the effect
3581 is relatively readable). */
3583 ui_out_field_skip (uiout
, "addr");
3585 if (b
->exec_pathname
!= NULL
)
3587 ui_out_text (uiout
, "program \"");
3588 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3589 ui_out_text (uiout
, "\" ");
3594 case bp_hardware_breakpoint
:
3598 case bp_longjmp_resume
:
3599 case bp_step_resume
:
3600 case bp_watchpoint_scope
:
3602 case bp_shlib_event
:
3603 case bp_thread_event
:
3604 case bp_overlay_event
:
3608 if (header_of_multiple
)
3609 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3610 if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3611 ui_out_field_string (uiout
, "addr", "<PENDING>");
3613 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3616 if (!header_of_multiple
)
3617 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3619 *last_addr
= b
->loc
->address
;
3623 if (!part_of_multiple
&& b
->thread
!= -1)
3625 /* FIXME: This seems to be redundant and lost here; see the
3626 "stop only in" line a little further down. */
3627 ui_out_text (uiout
, " thread ");
3628 ui_out_field_int (uiout
, "thread", b
->thread
);
3631 ui_out_text (uiout
, "\n");
3633 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3636 ui_out_text (uiout
, "\tstop only in stack frame at ");
3637 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3639 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3640 ui_out_text (uiout
, "\n");
3643 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3645 /* We do not print the condition for Ada exception catchpoints
3646 because the condition is an internal implementation detail
3647 that we do not want to expose to the user. */
3649 ui_out_text (uiout
, "\tstop only if ");
3650 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3651 ui_out_text (uiout
, "\n");
3654 if (!part_of_multiple
&& b
->thread
!= -1)
3656 /* FIXME should make an annotation for this */
3657 ui_out_text (uiout
, "\tstop only in thread ");
3658 ui_out_field_int (uiout
, "thread", b
->thread
);
3659 ui_out_text (uiout
, "\n");
3662 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3664 /* FIXME should make an annotation for this */
3665 if (ep_is_catchpoint (b
))
3666 ui_out_text (uiout
, "\tcatchpoint");
3668 ui_out_text (uiout
, "\tbreakpoint");
3669 ui_out_text (uiout
, " already hit ");
3670 ui_out_field_int (uiout
, "times", b
->hit_count
);
3671 if (b
->hit_count
== 1)
3672 ui_out_text (uiout
, " time\n");
3674 ui_out_text (uiout
, " times\n");
3677 /* Output the count also if it is zero, but only if this is
3678 mi. FIXME: Should have a better test for this. */
3679 if (ui_out_is_mi_like_p (uiout
))
3680 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3681 ui_out_field_int (uiout
, "times", b
->hit_count
);
3683 if (!part_of_multiple
&& b
->ignore_count
)
3686 ui_out_text (uiout
, "\tignore next ");
3687 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3688 ui_out_text (uiout
, " hits\n");
3691 if (!part_of_multiple
&& (l
= b
->commands
))
3693 struct cleanup
*script_chain
;
3696 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3697 print_command_lines (uiout
, l
, 4);
3698 do_cleanups (script_chain
);
3700 do_cleanups (bkpt_chain
);
3701 do_cleanups (old_chain
);
3705 print_one_breakpoint (struct breakpoint
*b
,
3706 CORE_ADDR
*last_addr
)
3708 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3710 /* If this breakpoint has custom print function,
3711 it's already printed. Otherwise, print individual
3712 locations, if any. */
3713 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3715 /* If breakpoint has a single location that is
3716 disabled, we print it as if it had
3717 several locations, since otherwise it's hard to
3718 represent "breakpoint enabled, location disabled"
3720 Note that while hardware watchpoints have
3721 several locations internally, that's no a property
3724 && !is_hardware_watchpoint (b
)
3725 && (b
->loc
->next
|| !b
->loc
->enabled
)
3726 && !ui_out_is_mi_like_p (uiout
))
3728 struct bp_location
*loc
;
3730 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3731 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3737 struct captured_breakpoint_query_args
3743 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3745 struct captured_breakpoint_query_args
*args
= data
;
3746 struct breakpoint
*b
;
3747 CORE_ADDR dummy_addr
= 0;
3750 if (args
->bnum
== b
->number
)
3752 print_one_breakpoint (b
, &dummy_addr
);
3760 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3762 struct captured_breakpoint_query_args args
;
3764 /* For the moment we don't trust print_one_breakpoint() to not throw
3766 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3767 error_message
, RETURN_MASK_ALL
) < 0)
3773 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3774 catchpoints, et.al.). */
3777 user_settable_breakpoint (const struct breakpoint
*b
)
3779 return (b
->type
== bp_breakpoint
3780 || b
->type
== bp_catch_load
3781 || b
->type
== bp_catch_unload
3782 || b
->type
== bp_catch_fork
3783 || b
->type
== bp_catch_vfork
3784 || b
->type
== bp_catch_exec
3785 || b
->type
== bp_hardware_breakpoint
3786 || b
->type
== bp_watchpoint
3787 || b
->type
== bp_read_watchpoint
3788 || b
->type
== bp_access_watchpoint
3789 || b
->type
== bp_hardware_watchpoint
);
3792 /* Print information on user settable breakpoint (watchpoint, etc)
3793 number BNUM. If BNUM is -1 print all user settable breakpoints.
3794 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3797 breakpoint_1 (int bnum
, int allflag
)
3799 struct breakpoint
*b
;
3800 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3801 int nr_printable_breakpoints
;
3802 struct cleanup
*bkpttbl_chain
;
3804 /* Compute the number of rows in the table. */
3805 nr_printable_breakpoints
= 0;
3808 || bnum
== b
->number
)
3810 if (allflag
|| user_settable_breakpoint (b
))
3811 nr_printable_breakpoints
++;
3816 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3820 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3823 if (nr_printable_breakpoints
> 0)
3824 annotate_breakpoints_headers ();
3825 if (nr_printable_breakpoints
> 0)
3827 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3828 if (nr_printable_breakpoints
> 0)
3830 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3831 if (nr_printable_breakpoints
> 0)
3833 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3834 if (nr_printable_breakpoints
> 0)
3836 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3839 if (nr_printable_breakpoints
> 0)
3841 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3842 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3844 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3846 if (nr_printable_breakpoints
> 0)
3848 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3849 ui_out_table_body (uiout
);
3850 if (nr_printable_breakpoints
> 0)
3851 annotate_breakpoints_table ();
3855 || bnum
== b
->number
)
3857 /* We only print out user settable breakpoints unless the
3859 if (allflag
|| user_settable_breakpoint (b
))
3860 print_one_breakpoint (b
, &last_addr
);
3863 do_cleanups (bkpttbl_chain
);
3865 if (nr_printable_breakpoints
== 0)
3868 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3870 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3875 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3876 that a comparison of an unsigned with -1 is always false. */
3877 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3878 set_next_address (last_addr
);
3881 /* FIXME? Should this be moved up so that it is only called when
3882 there have been breakpoints? */
3883 annotate_breakpoints_table_end ();
3887 breakpoints_info (char *bnum_exp
, int from_tty
)
3892 bnum
= parse_and_eval_long (bnum_exp
);
3894 breakpoint_1 (bnum
, 0);
3898 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3903 bnum
= parse_and_eval_long (bnum_exp
);
3905 breakpoint_1 (bnum
, 1);
3909 breakpoint_has_pc (struct breakpoint
*b
, CORE_ADDR pc
, asection
*section
)
3911 struct bp_location
*bl
= b
->loc
;
3912 for (; bl
; bl
= bl
->next
)
3914 if (bl
->address
== pc
3915 && (!overlay_debugging
|| bl
->section
== section
))
3921 /* Print a message describing any breakpoints set at PC. */
3924 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
3927 struct breakpoint
*b
;
3930 others
+= breakpoint_has_pc (b
, pc
, section
);
3934 printf_filtered (_("Note: breakpoint "));
3935 else /* if (others == ???) */
3936 printf_filtered (_("Note: breakpoints "));
3938 if (breakpoint_has_pc (b
, pc
, section
))
3941 printf_filtered ("%d", b
->number
);
3942 if (b
->thread
== -1 && thread
!= -1)
3943 printf_filtered (" (all threads)");
3944 else if (b
->thread
!= -1)
3945 printf_filtered (" (thread %d)", b
->thread
);
3946 printf_filtered ("%s%s ",
3947 ((b
->enable_state
== bp_disabled
||
3948 b
->enable_state
== bp_call_disabled
)
3950 : b
->enable_state
== bp_permanent
3954 : ((others
== 1) ? " and" : ""));
3956 printf_filtered (_("also set at pc "));
3957 fputs_filtered (paddress (pc
), gdb_stdout
);
3958 printf_filtered (".\n");
3962 /* Set the default place to put a breakpoint
3963 for the `break' command with no arguments. */
3966 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3969 default_breakpoint_valid
= valid
;
3970 default_breakpoint_address
= addr
;
3971 default_breakpoint_symtab
= symtab
;
3972 default_breakpoint_line
= line
;
3975 /* Return true iff it is meaningful to use the address member of
3976 BPT. For some breakpoint types, the address member is irrelevant
3977 and it makes no sense to attempt to compare it to other addresses
3978 (or use it for any other purpose either).
3980 More specifically, each of the following breakpoint types will always
3981 have a zero valued address and we don't want check_duplicates() to mark
3982 breakpoints of any of these types to be a duplicate of an actual
3983 breakpoint at address zero:
3986 bp_hardware_watchpoint
3988 bp_access_watchpoint
3995 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3997 enum bptype type
= bpt
->type
;
3999 return (type
!= bp_watchpoint
4000 && type
!= bp_hardware_watchpoint
4001 && type
!= bp_read_watchpoint
4002 && type
!= bp_access_watchpoint
4003 && type
!= bp_catch_exec
4004 && type
!= bp_longjmp_resume
4005 && type
!= bp_catch_fork
4006 && type
!= bp_catch_vfork
);
4009 /* Rescan breakpoints at the same address and section as BPT,
4010 marking the first one as "first" and any others as "duplicates".
4011 This is so that the bpt instruction is only inserted once.
4012 If we have a permanent breakpoint at the same place as BPT, make
4013 that one the official one, and the rest as duplicates. */
4016 check_duplicates_for (CORE_ADDR address
, asection
*section
)
4018 struct bp_location
*b
;
4020 struct bp_location
*perm_bp
= 0;
4022 ALL_BP_LOCATIONS (b
)
4023 if (b
->owner
->enable_state
!= bp_disabled
4024 && b
->owner
->enable_state
!= bp_call_disabled
4026 && !b
->shlib_disabled
4027 && b
->address
== address
/* address / overlay match */
4028 && (!overlay_debugging
|| b
->section
== section
)
4029 && breakpoint_address_is_meaningful (b
->owner
))
4031 /* Have we found a permanent breakpoint? */
4032 if (b
->owner
->enable_state
== bp_permanent
)
4039 b
->duplicate
= count
> 1;
4042 /* If we found a permanent breakpoint at this address, go over the
4043 list again and declare all the other breakpoints there to be the
4047 perm_bp
->duplicate
= 0;
4049 /* Permanent breakpoint should always be inserted. */
4050 if (! perm_bp
->inserted
)
4051 internal_error (__FILE__
, __LINE__
,
4052 _("allegedly permanent breakpoint is not "
4053 "actually inserted"));
4055 ALL_BP_LOCATIONS (b
)
4058 if (b
->owner
->enable_state
!= bp_disabled
4059 && b
->owner
->enable_state
!= bp_call_disabled
4060 && b
->enabled
&& !b
->shlib_disabled
4061 && b
->address
== address
/* address / overlay match */
4062 && (!overlay_debugging
|| b
->section
== section
)
4063 && breakpoint_address_is_meaningful (b
->owner
))
4066 internal_error (__FILE__
, __LINE__
,
4067 _("another breakpoint was inserted on top of "
4068 "a permanent breakpoint"));
4077 check_duplicates (struct breakpoint
*bpt
)
4079 struct bp_location
*bl
= bpt
->loc
;
4081 if (! breakpoint_address_is_meaningful (bpt
))
4084 for (; bl
; bl
= bl
->next
)
4085 check_duplicates_for (bl
->address
, bl
->section
);
4089 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4090 int bnum
, int have_bnum
)
4095 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4096 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4098 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4099 bnum
, astr1
, astr2
);
4101 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4104 /* Adjust a breakpoint's address to account for architectural constraints
4105 on breakpoint placement. Return the adjusted address. Note: Very
4106 few targets require this kind of adjustment. For most targets,
4107 this function is simply the identity function. */
4110 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4112 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4114 /* Very few targets need any kind of breakpoint adjustment. */
4117 else if (bptype
== bp_watchpoint
4118 || bptype
== bp_hardware_watchpoint
4119 || bptype
== bp_read_watchpoint
4120 || bptype
== bp_access_watchpoint
4121 || bptype
== bp_catch_fork
4122 || bptype
== bp_catch_vfork
4123 || bptype
== bp_catch_exec
)
4125 /* Watchpoints and the various bp_catch_* eventpoints should not
4126 have their addresses modified. */
4131 CORE_ADDR adjusted_bpaddr
;
4133 /* Some targets have architectural constraints on the placement
4134 of breakpoint instructions. Obtain the adjusted address. */
4135 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4138 /* An adjusted breakpoint address can significantly alter
4139 a user's expectations. Print a warning if an adjustment
4141 if (adjusted_bpaddr
!= bpaddr
)
4142 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4144 return adjusted_bpaddr
;
4148 /* Allocate a struct bp_location. */
4150 static struct bp_location
*
4151 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4153 struct bp_location
*loc
, *loc_p
;
4155 loc
= xmalloc (sizeof (struct bp_location
));
4156 memset (loc
, 0, sizeof (*loc
));
4160 loc
->shlib_disabled
= 0;
4169 case bp_longjmp_resume
:
4170 case bp_step_resume
:
4171 case bp_watchpoint_scope
:
4173 case bp_shlib_event
:
4174 case bp_thread_event
:
4175 case bp_overlay_event
:
4177 case bp_catch_unload
:
4178 loc
->loc_type
= bp_loc_software_breakpoint
;
4180 case bp_hardware_breakpoint
:
4181 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4183 case bp_hardware_watchpoint
:
4184 case bp_read_watchpoint
:
4185 case bp_access_watchpoint
:
4186 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4190 case bp_catch_vfork
:
4192 loc
->loc_type
= bp_loc_other
;
4195 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4198 /* Add this breakpoint to the end of the chain. */
4200 loc_p
= bp_location_chain
;
4202 bp_location_chain
= loc
;
4205 while (loc_p
->global_next
)
4206 loc_p
= loc_p
->global_next
;
4207 loc_p
->global_next
= loc
;
4213 static void free_bp_location (struct bp_location
*loc
)
4220 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4221 that has type BPTYPE and has no locations as yet. */
4223 static struct breakpoint
*
4224 set_raw_breakpoint_without_location (enum bptype bptype
)
4226 struct breakpoint
*b
, *b1
;
4228 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4229 memset (b
, 0, sizeof (*b
));
4232 b
->language
= current_language
->la_language
;
4233 b
->input_radix
= input_radix
;
4235 b
->enable_state
= bp_enabled
;
4238 b
->ignore_count
= 0;
4240 b
->frame_id
= null_frame_id
;
4241 b
->dll_pathname
= NULL
;
4242 b
->triggered_dll_pathname
= NULL
;
4243 b
->forked_inferior_pid
= 0;
4244 b
->exec_pathname
= NULL
;
4246 b
->condition_not_parsed
= 0;
4248 /* Add this breakpoint to the end of the chain
4249 so that a list of breakpoints will come out in order
4250 of increasing numbers. */
4252 b1
= breakpoint_chain
;
4254 breakpoint_chain
= b
;
4264 /* Initialize loc->function_name. */
4266 set_breakpoint_location_function (struct bp_location
*loc
)
4268 if (loc
->owner
->type
== bp_breakpoint
4269 || loc
->owner
->type
== bp_hardware_breakpoint
)
4271 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4273 if (loc
->function_name
)
4274 loc
->function_name
= xstrdup (loc
->function_name
);
4278 /* set_raw_breakpoint is a low level routine for allocating and
4279 partially initializing a breakpoint of type BPTYPE. The newly
4280 created breakpoint's address, section, source file name, and line
4281 number are provided by SAL. The newly created and partially
4282 initialized breakpoint is added to the breakpoint chain and
4283 is also returned as the value of this function.
4285 It is expected that the caller will complete the initialization of
4286 the newly created breakpoint struct as well as output any status
4287 information regarding the creation of a new breakpoint. In
4288 particular, set_raw_breakpoint does NOT set the breakpoint
4289 number! Care should be taken to not allow an error to occur
4290 prior to completing the initialization of the breakpoint. If this
4291 should happen, a bogus breakpoint will be left on the chain. */
4294 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4296 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4297 CORE_ADDR adjusted_address
;
4299 /* Adjust the breakpoint's address prior to allocating a location.
4300 Once we call allocate_bp_location(), that mostly uninitialized
4301 location will be placed on the location chain. Adjustment of the
4302 breakpoint may cause read_memory_nobpt() to be called and we do
4303 not want its scan of the location chain to find a breakpoint and
4304 location that's only been partially initialized. */
4305 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4307 b
->loc
= allocate_bp_location (b
, bptype
);
4308 b
->loc
->requested_address
= sal
.pc
;
4309 b
->loc
->address
= adjusted_address
;
4311 if (sal
.symtab
== NULL
)
4312 b
->source_file
= NULL
;
4314 b
->source_file
= savestring (sal
.symtab
->filename
,
4315 strlen (sal
.symtab
->filename
));
4316 b
->loc
->section
= sal
.section
;
4317 b
->line_number
= sal
.line
;
4319 set_breakpoint_location_function (b
->loc
);
4321 check_duplicates (b
);
4322 breakpoints_changed ();
4328 /* Note that the breakpoint object B describes a permanent breakpoint
4329 instruction, hard-wired into the inferior's code. */
4331 make_breakpoint_permanent (struct breakpoint
*b
)
4333 struct bp_location
*bl
;
4334 b
->enable_state
= bp_permanent
;
4336 /* By definition, permanent breakpoints are already present in the code.
4337 Mark all locations as inserted. For now, make_breakpoint_permanent
4338 is called in just one place, so it's hard to say if it's reasonable
4339 to have permanent breakpoint with multiple locations or not,
4340 but it's easy to implmement. */
4341 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4345 static struct breakpoint
*
4346 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4348 static int internal_breakpoint_number
= -1;
4349 struct symtab_and_line sal
;
4350 struct breakpoint
*b
;
4352 init_sal (&sal
); /* initialize to zeroes */
4355 sal
.section
= find_pc_overlay (sal
.pc
);
4357 b
= set_raw_breakpoint (sal
, type
);
4358 b
->number
= internal_breakpoint_number
--;
4359 b
->disposition
= disp_donttouch
;
4366 create_longjmp_breakpoint (char *func_name
)
4368 struct breakpoint
*b
;
4369 struct minimal_symbol
*m
;
4371 if (func_name
== NULL
)
4372 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4375 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4378 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4381 b
->enable_state
= bp_disabled
;
4384 b
->addr_string
= xstrdup (func_name
);
4387 /* Call this routine when stepping and nexting to enable a breakpoint
4388 if we do a longjmp(). When we hit that breakpoint, call
4389 set_longjmp_resume_breakpoint() to figure out where we are going. */
4392 enable_longjmp_breakpoint (void)
4394 struct breakpoint
*b
;
4397 if (b
->type
== bp_longjmp
)
4399 b
->enable_state
= bp_enabled
;
4400 check_duplicates (b
);
4405 disable_longjmp_breakpoint (void)
4407 struct breakpoint
*b
;
4410 if (b
->type
== bp_longjmp
4411 || b
->type
== bp_longjmp_resume
)
4413 b
->enable_state
= bp_disabled
;
4414 check_duplicates (b
);
4419 create_overlay_event_breakpoint (char *func_name
)
4421 struct breakpoint
*b
;
4422 struct minimal_symbol
*m
;
4424 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4427 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4429 b
->addr_string
= xstrdup (func_name
);
4431 if (overlay_debugging
== ovly_auto
)
4433 b
->enable_state
= bp_enabled
;
4434 overlay_events_enabled
= 1;
4438 b
->enable_state
= bp_disabled
;
4439 overlay_events_enabled
= 0;
4444 enable_overlay_breakpoints (void)
4446 struct breakpoint
*b
;
4449 if (b
->type
== bp_overlay_event
)
4451 b
->enable_state
= bp_enabled
;
4452 check_duplicates (b
);
4453 overlay_events_enabled
= 1;
4458 disable_overlay_breakpoints (void)
4460 struct breakpoint
*b
;
4463 if (b
->type
== bp_overlay_event
)
4465 b
->enable_state
= bp_disabled
;
4466 check_duplicates (b
);
4467 overlay_events_enabled
= 0;
4472 create_thread_event_breakpoint (CORE_ADDR address
)
4474 struct breakpoint
*b
;
4476 b
= create_internal_breakpoint (address
, bp_thread_event
);
4478 b
->enable_state
= bp_enabled
;
4479 /* addr_string has to be used or breakpoint_re_set will delete me. */
4480 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4486 remove_thread_event_breakpoints (void)
4488 struct breakpoint
*b
, *temp
;
4490 ALL_BREAKPOINTS_SAFE (b
, temp
)
4491 if (b
->type
== bp_thread_event
)
4492 delete_breakpoint (b
);
4495 struct captured_parse_breakpoint_args
4498 struct symtabs_and_lines
*sals_p
;
4499 char ***addr_string_p
;
4503 struct lang_and_radix
4511 remove_solib_event_breakpoints (void)
4513 struct breakpoint
*b
, *temp
;
4515 ALL_BREAKPOINTS_SAFE (b
, temp
)
4516 if (b
->type
== bp_shlib_event
)
4517 delete_breakpoint (b
);
4521 create_solib_event_breakpoint (CORE_ADDR address
)
4523 struct breakpoint
*b
;
4525 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4529 /* Disable any breakpoints that are on code in shared libraries. Only
4530 apply to enabled breakpoints, disabled ones can just stay disabled. */
4533 disable_breakpoints_in_shlibs (void)
4535 struct bp_location
*loc
;
4536 int disabled_shlib_breaks
= 0;
4538 ALL_BP_LOCATIONS (loc
)
4540 struct breakpoint
*b
= loc
->owner
;
4541 /* We apply the check to all breakpoints, including disabled
4542 for those with loc->duplicate set. This is so that when breakpoint
4543 becomes enabled, or the duplicate is removed, gdb will try to insert
4544 all breakpoints. If we don't set shlib_disabled here, we'll try
4545 to insert those breakpoints and fail. */
4546 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4547 && !loc
->shlib_disabled
4549 && PC_SOLIB (loc
->address
)
4551 && solib_address (loc
->address
)
4555 loc
->shlib_disabled
= 1;
4560 /* Disable any breakpoints that are in in an unloaded shared library. Only
4561 apply to enabled breakpoints, disabled ones can just stay disabled. */
4564 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4566 struct bp_location
*loc
;
4567 int disabled_shlib_breaks
= 0;
4569 ALL_BP_LOCATIONS (loc
)
4571 struct breakpoint
*b
= loc
->owner
;
4572 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4573 || loc
->loc_type
== bp_loc_software_breakpoint
)
4574 && !loc
->shlib_disabled
)
4577 char *so_name
= PC_SOLIB (loc
->address
);
4579 char *so_name
= solib_address (loc
->address
);
4581 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4583 loc
->shlib_disabled
= 1;
4584 /* At this point, we cannot rely on remove_breakpoint
4585 succeeding so we must mark the breakpoint as not inserted
4586 to prevent future errors occurring in remove_breakpoints. */
4588 if (!disabled_shlib_breaks
)
4590 target_terminal_ours_for_output ();
4591 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4594 disabled_shlib_breaks
= 1;
4601 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4602 enum bptype bp_kind
)
4604 struct symtab_and_line sal
;
4605 struct breakpoint
*b
;
4606 int thread
= -1; /* All threads. */
4613 b
= set_raw_breakpoint (sal
, bp_kind
);
4614 set_breakpoint_count (breakpoint_count
+ 1);
4615 b
->number
= breakpoint_count
;
4616 b
->cond_string
= (cond_string
== NULL
) ?
4617 NULL
: savestring (cond_string
, strlen (cond_string
));
4619 b
->addr_string
= NULL
;
4620 b
->enable_state
= bp_enabled
;
4621 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4622 b
->forked_inferior_pid
= 0;
4628 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4630 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4634 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4636 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4640 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4642 struct symtab_and_line sal
;
4643 struct breakpoint
*b
;
4644 int thread
= -1; /* All threads. */
4651 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4652 set_breakpoint_count (breakpoint_count
+ 1);
4653 b
->number
= breakpoint_count
;
4654 b
->cond_string
= (cond_string
== NULL
) ?
4655 NULL
: savestring (cond_string
, strlen (cond_string
));
4657 b
->addr_string
= NULL
;
4658 b
->enable_state
= bp_enabled
;
4659 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4665 hw_breakpoint_used_count (void)
4667 struct breakpoint
*b
;
4672 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4680 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4682 struct breakpoint
*b
;
4685 *other_type_used
= 0;
4688 if (breakpoint_enabled (b
))
4690 if (b
->type
== type
)
4692 else if ((b
->type
== bp_hardware_watchpoint
||
4693 b
->type
== bp_read_watchpoint
||
4694 b
->type
== bp_access_watchpoint
))
4695 *other_type_used
= 1;
4701 /* Call this after hitting the longjmp() breakpoint. Use this to set
4702 a new breakpoint at the target of the jmp_buf.
4704 FIXME - This ought to be done by setting a temporary breakpoint
4705 that gets deleted automatically... */
4708 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4710 struct breakpoint
*b
;
4713 if (b
->type
== bp_longjmp_resume
)
4715 b
->loc
->requested_address
= pc
;
4716 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4718 b
->enable_state
= bp_enabled
;
4719 b
->frame_id
= frame_id
;
4720 check_duplicates (b
);
4726 disable_watchpoints_before_interactive_call_start (void)
4728 struct breakpoint
*b
;
4732 if (((b
->type
== bp_watchpoint
)
4733 || (b
->type
== bp_hardware_watchpoint
)
4734 || (b
->type
== bp_read_watchpoint
)
4735 || (b
->type
== bp_access_watchpoint
))
4736 && breakpoint_enabled (b
))
4738 b
->enable_state
= bp_call_disabled
;
4739 check_duplicates (b
);
4745 enable_watchpoints_after_interactive_call_stop (void)
4747 struct breakpoint
*b
;
4751 if (((b
->type
== bp_watchpoint
)
4752 || (b
->type
== bp_hardware_watchpoint
)
4753 || (b
->type
== bp_read_watchpoint
)
4754 || (b
->type
== bp_access_watchpoint
))
4755 && (b
->enable_state
== bp_call_disabled
))
4757 b
->enable_state
= bp_enabled
;
4758 check_duplicates (b
);
4764 /* Set a breakpoint that will evaporate an end of command
4765 at address specified by SAL.
4766 Restrict it to frame FRAME if FRAME is nonzero. */
4769 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4772 struct breakpoint
*b
;
4773 b
= set_raw_breakpoint (sal
, type
);
4774 b
->enable_state
= bp_enabled
;
4775 b
->disposition
= disp_donttouch
;
4776 b
->frame_id
= frame_id
;
4778 /* If we're debugging a multi-threaded program, then we
4779 want momentary breakpoints to be active in only a
4780 single thread of control. */
4781 if (in_thread_list (inferior_ptid
))
4782 b
->thread
= pid_to_thread_id (inferior_ptid
);
4788 /* Tell the user we have just set a breakpoint B. */
4791 mention (struct breakpoint
*b
)
4794 struct cleanup
*old_chain
, *ui_out_chain
;
4795 struct ui_stream
*stb
;
4797 stb
= ui_out_stream_new (uiout
);
4798 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4800 /* FIXME: This is misplaced; mention() is called by things (like
4801 hitting a watchpoint) other than breakpoint creation. It should
4802 be possible to clean this up and at the same time replace the
4803 random calls to breakpoint_changed with this hook, as has already
4804 been done for deprecated_delete_breakpoint_hook and so on. */
4805 if (deprecated_create_breakpoint_hook
)
4806 deprecated_create_breakpoint_hook (b
);
4807 breakpoint_create_event (b
->number
);
4809 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4810 b
->ops
->print_mention (b
);
4815 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4818 ui_out_text (uiout
, "Watchpoint ");
4819 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4820 ui_out_field_int (uiout
, "number", b
->number
);
4821 ui_out_text (uiout
, ": ");
4822 print_expression (b
->exp
, stb
->stream
);
4823 ui_out_field_stream (uiout
, "exp", stb
);
4824 do_cleanups (ui_out_chain
);
4826 case bp_hardware_watchpoint
:
4827 ui_out_text (uiout
, "Hardware watchpoint ");
4828 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4829 ui_out_field_int (uiout
, "number", b
->number
);
4830 ui_out_text (uiout
, ": ");
4831 print_expression (b
->exp
, stb
->stream
);
4832 ui_out_field_stream (uiout
, "exp", stb
);
4833 do_cleanups (ui_out_chain
);
4835 case bp_read_watchpoint
:
4836 ui_out_text (uiout
, "Hardware read watchpoint ");
4837 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4838 ui_out_field_int (uiout
, "number", b
->number
);
4839 ui_out_text (uiout
, ": ");
4840 print_expression (b
->exp
, stb
->stream
);
4841 ui_out_field_stream (uiout
, "exp", stb
);
4842 do_cleanups (ui_out_chain
);
4844 case bp_access_watchpoint
:
4845 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4846 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4847 ui_out_field_int (uiout
, "number", b
->number
);
4848 ui_out_text (uiout
, ": ");
4849 print_expression (b
->exp
, stb
->stream
);
4850 ui_out_field_stream (uiout
, "exp", stb
);
4851 do_cleanups (ui_out_chain
);
4854 if (ui_out_is_mi_like_p (uiout
))
4859 printf_filtered (_("Breakpoint %d"), b
->number
);
4862 case bp_hardware_breakpoint
:
4863 if (ui_out_is_mi_like_p (uiout
))
4868 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4872 case bp_catch_unload
:
4873 printf_filtered (_("Catchpoint %d (%s %s)"),
4875 (b
->type
== bp_catch_load
) ? "load" : "unload",
4876 (b
->dll_pathname
!= NULL
) ?
4877 b
->dll_pathname
: "<any library>");
4880 case bp_catch_vfork
:
4881 printf_filtered (_("Catchpoint %d (%s)"),
4883 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4886 printf_filtered (_("Catchpoint %d (exec)"),
4893 case bp_longjmp_resume
:
4894 case bp_step_resume
:
4896 case bp_watchpoint_scope
:
4897 case bp_shlib_event
:
4898 case bp_thread_event
:
4899 case bp_overlay_event
:
4905 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4909 printf_filtered (_(" (%s) pending."), b
->addr_string
);
4913 if (addressprint
|| b
->source_file
== NULL
)
4915 printf_filtered (" at ");
4916 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
4919 printf_filtered (": file %s, line %d.",
4920 b
->source_file
, b
->line_number
);
4924 struct bp_location
*loc
= b
->loc
;
4926 for (; loc
; loc
= loc
->next
)
4928 printf_filtered (" (%d locations)", n
);
4933 do_cleanups (old_chain
);
4934 if (ui_out_is_mi_like_p (uiout
))
4936 printf_filtered ("\n");
4940 static struct bp_location
*
4941 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
4942 const struct symtab_and_line
*sal
)
4944 struct bp_location
*loc
, **tmp
;
4946 loc
= allocate_bp_location (b
, bptype
);
4947 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
4950 loc
->requested_address
= sal
->pc
;
4951 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
4953 loc
->section
= sal
->section
;
4955 set_breakpoint_location_function (loc
);
4959 /* Create a breakpoint with SAL as location. Use ADDR_STRING
4960 as textual description of the location, and COND_STRING
4961 as condition expression. */
4964 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
4966 enum bptype type
, enum bpdisp disposition
,
4967 int thread
, int ignore_count
, int from_tty
)
4969 struct breakpoint
*b
= NULL
;
4972 if (type
== bp_hardware_breakpoint
)
4974 int i
= hw_breakpoint_used_count ();
4975 int target_resources_ok
=
4976 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4978 if (target_resources_ok
== 0)
4979 error (_("No hardware breakpoint support in the target."));
4980 else if (target_resources_ok
< 0)
4981 error (_("Hardware breakpoints used exceeds limit."));
4984 for (i
= 0; i
< sals
.nelts
; ++i
)
4986 struct symtab_and_line sal
= sals
.sals
[i
];
4987 struct bp_location
*loc
;
4990 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
4994 b
= set_raw_breakpoint (sal
, type
);
4995 set_breakpoint_count (breakpoint_count
+ 1);
4996 b
->number
= breakpoint_count
;
4999 b
->cond_string
= cond_string
;
5000 b
->ignore_count
= ignore_count
;
5001 b
->enable_state
= bp_enabled
;
5002 b
->disposition
= disposition
;
5008 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5013 char *arg
= b
->cond_string
;
5014 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5016 error (_("Garbage %s follows condition"), arg
);
5021 b
->addr_string
= addr_string
;
5023 /* addr_string has to be used or breakpoint_re_set will delete
5025 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5030 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5031 elements to fill the void space. */
5032 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5034 int i
= index_to_remove
+1;
5035 int last_index
= sal
->nelts
-1;
5037 for (;i
<= last_index
; ++i
)
5038 sal
->sals
[i
-1] = sal
->sals
[i
];
5043 /* If appropriate, obtains all sals that correspond
5044 to the same file and line as SAL. This is done
5045 only if SAL does not have explicit PC and has
5046 line and file information. If we got just a single
5047 expanded sal, return the original.
5049 Otherwise, if SAL.explicit_line is not set, filter out
5050 all sals for which the name of enclosing function
5051 is different from SAL. This makes sure that if we have
5052 breakpoint originally set in template instantiation, say
5053 foo<int>(), we won't expand SAL to locations at the same
5054 line in all existing instantiations of 'foo'.
5057 struct symtabs_and_lines
5058 expand_line_sal_maybe (struct symtab_and_line sal
)
5060 struct symtabs_and_lines expanded
;
5061 CORE_ADDR original_pc
= sal
.pc
;
5062 char *original_function
= NULL
;
5066 /* If we have explicit pc, don't expand.
5067 If we have no line number, we can't expand. */
5068 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5071 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5072 expanded
.sals
[0] = sal
;
5077 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5079 expanded
= expand_line_sal (sal
);
5080 if (expanded
.nelts
== 1)
5082 /* We had one sal, we got one sal. Without futher
5083 processing, just return the original sal. */
5084 xfree (expanded
.sals
);
5086 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5087 sal
.pc
= original_pc
;
5088 expanded
.sals
[0] = sal
;
5092 if (!sal
.explicit_line
)
5094 CORE_ADDR func_addr
, func_end
;
5095 for (i
= 0; i
< expanded
.nelts
; ++i
)
5097 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5098 char *this_function
;
5099 if (find_pc_partial_function (pc
, &this_function
,
5100 &func_addr
, &func_end
))
5102 if (this_function
&&
5103 strcmp (this_function
, original_function
) != 0)
5105 remove_sal (&expanded
, i
);
5108 else if (func_addr
== pc
)
5110 /* We're at beginning of a function, and should
5112 struct symbol
*sym
= find_pc_function (pc
);
5114 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5117 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5124 if (expanded
.nelts
<= 1)
5126 /* This is un ugly workaround. If we get zero
5127 expanded sals then something is really wrong.
5128 Fix that by returnign the original sal. */
5129 xfree (expanded
.sals
);
5131 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5132 sal
.pc
= original_pc
;
5133 expanded
.sals
[0] = sal
;
5140 for (i
= 0; i
< expanded
.nelts
; ++i
)
5141 if (expanded
.sals
[i
].pc
== original_pc
)
5152 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5153 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5154 value. COND_STRING, if not NULL, specified the condition to be
5155 used for all breakpoints. Essentially the only case where
5156 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5157 function. In that case, it's still not possible to specify
5158 separate conditions for different overloaded functions, so
5159 we take just a single condition string.
5161 NOTE: If the function succeeds, the caller is expected to cleanup
5162 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5163 array contents). If the function fails (error() is called), the
5164 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5165 COND and SALS arrays and each of those arrays contents. */
5168 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5170 enum bptype type
, enum bpdisp disposition
,
5171 int thread
, int ignore_count
, int from_tty
)
5174 for (i
= 0; i
< sals
.nelts
; ++i
)
5176 struct symtabs_and_lines expanded
=
5177 expand_line_sal_maybe (sals
.sals
[i
]);
5179 create_breakpoint (expanded
, addr_string
[i
],
5180 cond_string
, type
, disposition
,
5181 thread
, ignore_count
, from_tty
);
5185 /* Parse ARG which is assumed to be a SAL specification possibly
5186 followed by conditionals. On return, SALS contains an array of SAL
5187 addresses found. ADDR_STRING contains a vector of (canonical)
5188 address strings. ARG points to the end of the SAL. */
5191 parse_breakpoint_sals (char **address
,
5192 struct symtabs_and_lines
*sals
,
5193 char ***addr_string
,
5196 char *addr_start
= *address
;
5197 *addr_string
= NULL
;
5198 /* If no arg given, or if first arg is 'if ', use the default
5200 if ((*address
) == NULL
5201 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5203 if (default_breakpoint_valid
)
5205 struct symtab_and_line sal
;
5206 init_sal (&sal
); /* initialize to zeroes */
5207 sals
->sals
= (struct symtab_and_line
*)
5208 xmalloc (sizeof (struct symtab_and_line
));
5209 sal
.pc
= default_breakpoint_address
;
5210 sal
.line
= default_breakpoint_line
;
5211 sal
.symtab
= default_breakpoint_symtab
;
5212 sal
.section
= find_pc_overlay (sal
.pc
);
5213 sals
->sals
[0] = sal
;
5217 error (_("No default breakpoint address now."));
5221 /* Force almost all breakpoints to be in terms of the
5222 current_source_symtab (which is decode_line_1's default). This
5223 should produce the results we want almost all of the time while
5224 leaving default_breakpoint_* alone.
5225 ObjC: However, don't match an Objective-C method name which
5226 may have a '+' or '-' succeeded by a '[' */
5228 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5230 if (default_breakpoint_valid
5232 || ((strchr ("+-", (*address
)[0]) != NULL
)
5233 && ((*address
)[1] != '['))))
5234 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5235 default_breakpoint_line
, addr_string
,
5238 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5239 addr_string
, not_found_ptr
);
5241 /* For any SAL that didn't have a canonical string, fill one in. */
5242 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5243 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5244 if (addr_start
!= (*address
))
5247 for (i
= 0; i
< sals
->nelts
; i
++)
5249 /* Add the string if not present. */
5250 if ((*addr_string
)[i
] == NULL
)
5251 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5257 /* Convert each SAL into a real PC. Verify that the PC can be
5258 inserted as a breakpoint. If it can't throw an error. */
5261 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5265 for (i
= 0; i
< sals
->nelts
; i
++)
5266 resolve_sal_pc (&sals
->sals
[i
]);
5270 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5272 struct captured_parse_breakpoint_args
*args
= data
;
5274 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5275 args
->not_found_ptr
);
5278 /* Given TOK, a string specification of condition and thread, as
5279 accepted by the 'break' command, extract the condition
5280 string and thread number and set *COND_STRING and *THREAD.
5281 PC identifies the context at which the condition should be parsed.
5282 If no condition is found, *COND_STRING is set to NULL.
5283 If no thread is found, *THREAD is set to -1. */
5285 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5286 char **cond_string
, int *thread
)
5288 *cond_string
= NULL
;
5294 char *cond_start
= NULL
;
5295 char *cond_end
= NULL
;
5296 while (*tok
== ' ' || *tok
== '\t')
5301 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5304 toklen
= end_tok
- tok
;
5306 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5308 tok
= cond_start
= end_tok
+ 1;
5309 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5311 *cond_string
= savestring (cond_start
,
5312 cond_end
- cond_start
);
5314 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5320 *thread
= strtol (tok
, &tok
, 0);
5322 error (_("Junk after thread keyword."));
5323 if (!valid_thread_id (*thread
))
5324 error (_("Unknown thread %d."), *thread
);
5327 error (_("Junk at end of arguments."));
5331 /* Set a breakpoint. This function is shared between
5332 CLI and MI functions for setting a breakpoint.
5333 This function has two major modes of operations,
5334 selected by the PARSE_CONDITION_AND_THREAD parameter.
5335 If non-zero, the function will parse arg, extracting
5336 breakpoint location, address and thread. Otherwise,
5337 ARG is just the location of breakpoint, with condition
5338 and thread specified by the COND_STRING and THREAD
5342 break_command_really (char *arg
, char *cond_string
, int thread
,
5343 int parse_condition_and_thread
,
5344 int tempflag
, int hardwareflag
,
5346 enum auto_boolean pending_break_support
,
5349 struct gdb_exception e
;
5350 struct symtabs_and_lines sals
;
5351 struct symtab_and_line pending_sal
;
5354 char *addr_start
= arg
;
5356 struct cleanup
*old_chain
;
5357 struct cleanup
*breakpoint_chain
= NULL
;
5358 struct captured_parse_breakpoint_args parse_args
;
5367 parse_args
.arg_p
= &arg
;
5368 parse_args
.sals_p
= &sals
;
5369 parse_args
.addr_string_p
= &addr_string
;
5370 parse_args
.not_found_ptr
= ¬_found
;
5372 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5373 &parse_args
, RETURN_MASK_ALL
);
5375 /* If caller is interested in rc value from parse, set value. */
5379 throw_exception (e
);
5383 case NOT_FOUND_ERROR
:
5385 /* If pending breakpoint support is turned off, throw
5388 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5389 throw_exception (e
);
5391 exception_print (gdb_stderr
, e
);
5393 /* If pending breakpoint support is auto query and the user
5394 selects no, then simply return the error code. */
5395 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5396 !nquery ("Make breakpoint pending on future shared library load? "))
5399 /* At this point, either the user was queried about setting
5400 a pending breakpoint and selected yes, or pending
5401 breakpoint behavior is on and thus a pending breakpoint
5402 is defaulted on behalf of the user. */
5403 copy_arg
= xstrdup (addr_start
);
5404 addr_string
= ©_arg
;
5406 sals
.sals
= &pending_sal
;
5411 throw_exception (e
);
5418 /* Create a chain of things that always need to be cleaned up. */
5419 old_chain
= make_cleanup (null_cleanup
, 0);
5423 /* Make sure that all storage allocated to SALS gets freed. */
5424 make_cleanup (xfree
, sals
.sals
);
5426 /* Cleanup the addr_string array but not its contents. */
5427 make_cleanup (xfree
, addr_string
);
5430 /* ----------------------------- SNIP -----------------------------
5431 Anything added to the cleanup chain beyond this point is assumed
5432 to be part of a breakpoint. If the breakpoint create succeeds
5433 then the memory is not reclaimed. */
5434 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5436 /* Mark the contents of the addr_string for cleanup. These go on
5437 the breakpoint_chain and only occure if the breakpoint create
5439 for (i
= 0; i
< sals
.nelts
; i
++)
5441 if (addr_string
[i
] != NULL
)
5442 make_cleanup (xfree
, addr_string
[i
]);
5445 /* Resolve all line numbers to PC's and verify that the addresses
5446 are ok for the target. */
5448 breakpoint_sals_to_pc (&sals
, addr_start
);
5450 /* Verify that condition can be parsed, before setting any
5451 breakpoints. Allocate a separate condition expression for each
5455 if (parse_condition_and_thread
)
5457 /* Here we only parse 'arg' to separate condition
5458 from thread number, so parsing in context of first
5459 sal is OK. When setting the breakpoint we'll
5460 re-parse it in context of each sal. */
5463 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5465 make_cleanup (xfree
, cond_string
);
5469 /* Create a private copy of condition string. */
5472 cond_string
= xstrdup (cond_string
);
5473 make_cleanup (xfree
, cond_string
);
5476 create_breakpoints (sals
, addr_string
, cond_string
,
5477 hardwareflag
? bp_hardware_breakpoint
5479 tempflag
? disp_del
: disp_donttouch
,
5480 thread
, ignore_count
, from_tty
);
5484 struct symtab_and_line sal
= {0};
5485 struct breakpoint
*b
;
5487 make_cleanup (xfree
, copy_arg
);
5489 b
= set_raw_breakpoint_without_location (hardwareflag
5490 ? bp_hardware_breakpoint
5492 set_breakpoint_count (breakpoint_count
+ 1);
5493 b
->number
= breakpoint_count
;
5495 b
->addr_string
= addr_string
[0];
5496 b
->cond_string
= NULL
;
5497 b
->ignore_count
= ignore_count
;
5498 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5499 b
->condition_not_parsed
= 1;
5504 warning (_("Multiple breakpoints were set.\n"
5505 "Use the \"delete\" command to delete unwanted breakpoints."));
5506 /* That's it. Discard the cleanups for data inserted into the
5508 discard_cleanups (breakpoint_chain
);
5509 /* But cleanup everything else. */
5510 do_cleanups (old_chain
);
5513 /* Set a breakpoint.
5514 ARG is a string describing breakpoint address,
5515 condition, and thread.
5516 FLAG specifies if a breakpoint is hardware on,
5517 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5521 break_command_1 (char *arg
, int flag
, int from_tty
)
5523 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5524 int tempflag
= flag
& BP_TEMPFLAG
;
5526 break_command_really (arg
,
5527 NULL
, 0, 1 /* parse arg */,
5528 tempflag
, hardwareflag
,
5529 0 /* Ignore count */,
5530 pending_break_support
, from_tty
);
5535 set_breakpoint (char *address
, char *condition
,
5536 int hardwareflag
, int tempflag
,
5537 int thread
, int ignore_count
,
5540 break_command_really (address
, condition
, thread
,
5541 0 /* condition and thread are valid. */,
5542 tempflag
, hardwareflag
,
5545 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5549 /* Adjust SAL to the first instruction past the function prologue.
5550 The end of the prologue is determined using the line table from
5551 the debugging information.
5553 If SAL is already past the prologue, then do nothing. */
5556 skip_prologue_sal (struct symtab_and_line
*sal
)
5558 struct symbol
*sym
= find_pc_function (sal
->pc
);
5559 struct symtab_and_line start_sal
;
5564 start_sal
= find_function_start_sal (sym
, 1);
5565 if (sal
->pc
< start_sal
.pc
)
5569 /* Helper function for break_command_1 and disassemble_command. */
5572 resolve_sal_pc (struct symtab_and_line
*sal
)
5576 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5578 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5579 error (_("No line %d in file \"%s\"."),
5580 sal
->line
, sal
->symtab
->filename
);
5583 /* If this SAL corresponds to a breakpoint inserted using
5584 a line number, then skip the function prologue if necessary. */
5585 if (sal
->explicit_line
)
5586 skip_prologue_sal (sal
);
5589 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5591 struct blockvector
*bv
;
5595 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5598 sym
= block_function (b
);
5601 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5602 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5606 /* It really is worthwhile to have the section, so we'll just
5607 have to look harder. This case can be executed if we have
5608 line numbers but no functions (as can happen in assembly
5611 struct minimal_symbol
*msym
;
5613 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5615 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5622 break_command (char *arg
, int from_tty
)
5624 break_command_1 (arg
, 0, from_tty
);
5628 tbreak_command (char *arg
, int from_tty
)
5630 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5634 hbreak_command (char *arg
, int from_tty
)
5636 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5640 thbreak_command (char *arg
, int from_tty
)
5642 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5646 stop_command (char *arg
, int from_tty
)
5648 printf_filtered (_("Specify the type of breakpoint to set.\n\
5649 Usage: stop in <function | address>\n\
5650 stop at <line>\n"));
5654 stopin_command (char *arg
, int from_tty
)
5658 if (arg
== (char *) NULL
)
5660 else if (*arg
!= '*')
5665 /* look for a ':'. If this is a line number specification, then
5666 say it is bad, otherwise, it should be an address or
5667 function/method name */
5668 while (*argptr
&& !hasColon
)
5670 hasColon
= (*argptr
== ':');
5675 badInput
= (*argptr
!= ':'); /* Not a class::method */
5677 badInput
= isdigit (*arg
); /* a simple line number */
5681 printf_filtered (_("Usage: stop in <function | address>\n"));
5683 break_command_1 (arg
, 0, from_tty
);
5687 stopat_command (char *arg
, int from_tty
)
5691 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5698 /* look for a ':'. If there is a '::' then get out, otherwise
5699 it is probably a line number. */
5700 while (*argptr
&& !hasColon
)
5702 hasColon
= (*argptr
== ':');
5707 badInput
= (*argptr
== ':'); /* we have class::method */
5709 badInput
= !isdigit (*arg
); /* not a line number */
5713 printf_filtered (_("Usage: stop at <line>\n"));
5715 break_command_1 (arg
, 0, from_tty
);
5718 /* accessflag: hw_write: watch write,
5719 hw_read: watch read,
5720 hw_access: watch access (read or write) */
5722 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5724 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5725 struct symtab_and_line sal
;
5726 struct expression
*exp
;
5727 struct block
*exp_valid_block
;
5728 struct value
*val
, *mark
;
5729 struct frame_info
*frame
;
5730 struct frame_info
*prev_frame
= NULL
;
5731 char *exp_start
= NULL
;
5732 char *exp_end
= NULL
;
5733 char *tok
, *id_tok_start
, *end_tok
;
5735 char *cond_start
= NULL
;
5736 char *cond_end
= NULL
;
5737 struct expression
*cond
= NULL
;
5738 int i
, other_type_used
, target_resources_ok
= 0;
5739 enum bptype bp_type
;
5743 init_sal (&sal
); /* initialize to zeroes */
5745 /* Make sure that we actually have parameters to parse. */
5746 if (arg
!= NULL
&& arg
[0] != '\0')
5748 toklen
= strlen (arg
); /* Size of argument list. */
5750 /* Points tok to the end of the argument list. */
5751 tok
= arg
+ toklen
- 1;
5753 /* Go backwards in the parameters list. Skip the last parameter.
5754 If we're expecting a 'thread <thread_num>' parameter, this should
5755 be the thread identifier. */
5756 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5758 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5761 /* Points end_tok to the beginning of the last token. */
5762 id_tok_start
= tok
+ 1;
5764 /* Go backwards in the parameters list. Skip one more parameter.
5765 If we're expecting a 'thread <thread_num>' parameter, we should
5766 reach a "thread" token. */
5767 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5772 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5775 /* Move the pointer forward to skip the whitespace and
5776 calculate the length of the token. */
5778 toklen
= end_tok
- tok
;
5780 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5782 /* At this point we've found a "thread" token, which means
5783 the user is trying to set a watchpoint that triggers
5784 only in a specific thread. */
5787 /* Extract the thread ID from the next token. */
5788 thread
= strtol (id_tok_start
, &endp
, 0);
5790 /* Check if the user provided a valid numeric value for the
5792 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5793 error (_("Invalid thread ID specification %s."), id_tok_start
);
5795 /* Check if the thread actually exists. */
5796 if (!valid_thread_id (thread
))
5797 error (_("Unknown thread %d."), thread
);
5799 /* Truncate the string and get rid of the thread <thread_num>
5800 parameter before the parameter list is parsed by the
5801 evaluate_expression() function. */
5806 /* Parse the rest of the arguments. */
5807 innermost_block
= NULL
;
5809 exp
= parse_exp_1 (&arg
, 0, 0);
5811 exp_valid_block
= innermost_block
;
5812 mark
= value_mark ();
5813 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5815 release_value (val
);
5818 while (*tok
== ' ' || *tok
== '\t')
5822 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5825 toklen
= end_tok
- tok
;
5826 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5828 tok
= cond_start
= end_tok
+ 1;
5829 cond
= parse_exp_1 (&tok
, 0, 0);
5833 error (_("Junk at end of command."));
5835 if (accessflag
== hw_read
)
5836 bp_type
= bp_read_watchpoint
;
5837 else if (accessflag
== hw_access
)
5838 bp_type
= bp_access_watchpoint
;
5840 bp_type
= bp_hardware_watchpoint
;
5842 mem_cnt
= can_use_hardware_watchpoint (val
);
5843 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5844 error (_("Expression cannot be implemented with read/access watchpoint."));
5847 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5848 target_resources_ok
=
5849 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5851 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5852 error (_("Target does not support this type of hardware watchpoint."));
5854 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5855 error (_("Target can only support one kind of HW watchpoint at a time."));
5858 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5859 watchpoint could not be set. */
5860 if (!mem_cnt
|| target_resources_ok
<= 0)
5861 bp_type
= bp_watchpoint
;
5863 frame
= block_innermost_frame (exp_valid_block
);
5865 prev_frame
= get_prev_frame (frame
);
5869 /* If the expression is "local", then set up a "watchpoint scope"
5870 breakpoint at the point where we've left the scope of the watchpoint
5871 expression. Create the scope breakpoint before the watchpoint, so
5872 that we will encounter it first in bpstat_stop_status. */
5873 if (innermost_block
&& prev_frame
)
5875 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5876 bp_watchpoint_scope
);
5878 scope_breakpoint
->enable_state
= bp_enabled
;
5880 /* Automatically delete the breakpoint when it hits. */
5881 scope_breakpoint
->disposition
= disp_del
;
5883 /* Only break in the proper frame (help with recursion). */
5884 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5886 /* Set the address at which we will stop. */
5887 scope_breakpoint
->loc
->requested_address
5888 = get_frame_pc (prev_frame
);
5889 scope_breakpoint
->loc
->address
5890 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5891 scope_breakpoint
->type
);
5894 /* Now set up the breakpoint. */
5895 b
= set_raw_breakpoint (sal
, bp_type
);
5896 set_breakpoint_count (breakpoint_count
+ 1);
5897 b
->number
= breakpoint_count
;
5899 b
->disposition
= disp_donttouch
;
5901 b
->exp_valid_block
= exp_valid_block
;
5902 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5905 b
->loc
->cond
= cond
;
5907 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5912 b
->watchpoint_frame
= get_frame_id (frame
);
5914 b
->watchpoint_frame
= null_frame_id
;
5916 if (scope_breakpoint
!= NULL
)
5918 /* The scope breakpoint is related to the watchpoint. We will
5919 need to act on them together. */
5920 b
->related_breakpoint
= scope_breakpoint
;
5921 scope_breakpoint
->related_breakpoint
= b
;
5924 value_free_to_mark (mark
);
5928 /* Return count of locations need to be watched and can be handled
5929 in hardware. If the watchpoint can not be handled
5930 in hardware return zero. */
5933 can_use_hardware_watchpoint (struct value
*v
)
5935 int found_memory_cnt
= 0;
5936 struct value
*head
= v
;
5938 /* Did the user specifically forbid us to use hardware watchpoints? */
5939 if (!can_use_hw_watchpoints
)
5942 /* Make sure that the value of the expression depends only upon
5943 memory contents, and values computed from them within GDB. If we
5944 find any register references or function calls, we can't use a
5945 hardware watchpoint.
5947 The idea here is that evaluating an expression generates a series
5948 of values, one holding the value of every subexpression. (The
5949 expression a*b+c has five subexpressions: a, b, a*b, c, and
5950 a*b+c.) GDB's values hold almost enough information to establish
5951 the criteria given above --- they identify memory lvalues,
5952 register lvalues, computed values, etcetera. So we can evaluate
5953 the expression, and then scan the chain of values that leaves
5954 behind to decide whether we can detect any possible change to the
5955 expression's final value using only hardware watchpoints.
5957 However, I don't think that the values returned by inferior
5958 function calls are special in any way. So this function may not
5959 notice that an expression involving an inferior function call
5960 can't be watched with hardware watchpoints. FIXME. */
5961 for (; v
; v
= value_next (v
))
5963 if (VALUE_LVAL (v
) == lval_memory
)
5966 /* A lazy memory lvalue is one that GDB never needed to fetch;
5967 we either just used its address (e.g., `a' in `a.b') or
5968 we never needed it at all (e.g., `a' in `a,b'). */
5972 /* Ahh, memory we actually used! Check if we can cover
5973 it with hardware watchpoints. */
5974 struct type
*vtype
= check_typedef (value_type (v
));
5976 /* We only watch structs and arrays if user asked for it
5977 explicitly, never if they just happen to appear in a
5978 middle of some value chain. */
5980 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5981 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5983 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
5984 int len
= TYPE_LENGTH (value_type (v
));
5986 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5993 else if (VALUE_LVAL (v
) != not_lval
5994 && deprecated_value_modifiable (v
) == 0)
5995 return 0; /* ??? What does this represent? */
5996 else if (VALUE_LVAL (v
) == lval_register
)
5997 return 0; /* cannot watch a register with a HW watchpoint */
6000 /* The expression itself looks suitable for using a hardware
6001 watchpoint, but give the target machine a chance to reject it. */
6002 return found_memory_cnt
;
6006 watch_command_wrapper (char *arg
, int from_tty
)
6008 watch_command (arg
, from_tty
);
6012 watch_command (char *arg
, int from_tty
)
6014 watch_command_1 (arg
, hw_write
, from_tty
);
6018 rwatch_command_wrapper (char *arg
, int from_tty
)
6020 rwatch_command (arg
, from_tty
);
6024 rwatch_command (char *arg
, int from_tty
)
6026 watch_command_1 (arg
, hw_read
, from_tty
);
6030 awatch_command_wrapper (char *arg
, int from_tty
)
6032 awatch_command (arg
, from_tty
);
6036 awatch_command (char *arg
, int from_tty
)
6038 watch_command_1 (arg
, hw_access
, from_tty
);
6042 /* Helper routines for the until_command routine in infcmd.c. Here
6043 because it uses the mechanisms of breakpoints. */
6045 /* This function is called by fetch_inferior_event via the
6046 cmd_continuation pointer, to complete the until command. It takes
6047 care of cleaning up the temporary breakpoints set up by the until
6050 until_break_command_continuation (struct continuation_arg
*arg
)
6052 struct cleanup
*cleanups
;
6054 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
6055 do_exec_cleanups (cleanups
);
6059 until_break_command (char *arg
, int from_tty
, int anywhere
)
6061 struct symtabs_and_lines sals
;
6062 struct symtab_and_line sal
;
6063 struct frame_info
*frame
= get_selected_frame (NULL
);
6064 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6065 struct breakpoint
*breakpoint
;
6066 struct cleanup
*old_chain
;
6067 struct continuation_arg
*arg1
;
6070 clear_proceed_status ();
6072 /* Set a breakpoint where the user wants it and at return from
6075 if (default_breakpoint_valid
)
6076 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6077 default_breakpoint_line
, (char ***) NULL
, NULL
);
6079 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6080 0, (char ***) NULL
, NULL
);
6082 if (sals
.nelts
!= 1)
6083 error (_("Couldn't get information on specified line."));
6086 xfree (sals
.sals
); /* malloc'd, so freed */
6089 error (_("Junk at end of arguments."));
6091 resolve_sal_pc (&sal
);
6094 /* If the user told us to continue until a specified location,
6095 we don't specify a frame at which we need to stop. */
6096 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6098 /* Otherwise, specify the current frame, because we want to stop only
6099 at the very same frame. */
6100 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6103 if (!target_can_async_p ())
6104 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6106 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
6108 /* If we are running asynchronously, and the target supports async
6109 execution, we are not waiting for the target to stop, in the call
6110 tp proceed, below. This means that we cannot delete the
6111 brekpoints until the target has actually stopped. The only place
6112 where we get a chance to do that is in fetch_inferior_event, so
6113 we must set things up for that. */
6115 if (target_can_async_p ())
6117 /* In this case the arg for the continuation is just the point
6118 in the exec_cleanups chain from where to start doing
6119 cleanups, because all the continuation does is the cleanups in
6120 the exec_cleanup_chain. */
6122 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6124 arg1
->data
.pointer
= old_chain
;
6126 add_continuation (until_break_command_continuation
, arg1
);
6129 /* Keep within the current frame, or in frames called by the current
6133 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6134 sal
.pc
= get_frame_pc (prev_frame
);
6135 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6137 if (!target_can_async_p ())
6138 make_cleanup_delete_breakpoint (breakpoint
);
6140 make_exec_cleanup_delete_breakpoint (breakpoint
);
6143 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6144 /* Do the cleanups now, anly if we are not running asynchronously,
6145 of if we are, but the target is still synchronous. */
6146 if (!target_can_async_p ())
6147 do_cleanups (old_chain
);
6151 ep_skip_leading_whitespace (char **s
)
6153 if ((s
== NULL
) || (*s
== NULL
))
6155 while (isspace (**s
))
6159 /* This function examines a string, and attempts to find a token
6160 that might be an event name in the leading characters. If a
6161 possible match is found, a pointer to the last character of
6162 the token is returned. Else, NULL is returned. */
6165 ep_find_event_name_end (char *arg
)
6168 char *event_name_end
= NULL
;
6170 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6174 /* We break out of the loop when we find a token delimiter.
6175 Basically, we're looking for alphanumerics and underscores;
6176 anything else delimites the token. */
6179 if (!isalnum (*s
) && (*s
!= '_'))
6185 return event_name_end
;
6189 /* This function attempts to parse an optional "if <cond>" clause
6190 from the arg string. If one is not found, it returns NULL.
6192 Else, it returns a pointer to the condition string. (It does not
6193 attempt to evaluate the string against a particular block.) And,
6194 it updates arg to point to the first character following the parsed
6195 if clause in the arg string. */
6198 ep_parse_optional_if_clause (char **arg
)
6202 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6205 /* Skip the "if" keyword. */
6208 /* Skip any extra leading whitespace, and record the start of the
6209 condition string. */
6210 ep_skip_leading_whitespace (arg
);
6213 /* Assume that the condition occupies the remainder of the arg string. */
6214 (*arg
) += strlen (cond_string
);
6219 /* This function attempts to parse an optional filename from the arg
6220 string. If one is not found, it returns NULL.
6222 Else, it returns a pointer to the parsed filename. (This function
6223 makes no attempt to verify that a file of that name exists, or is
6224 accessible.) And, it updates arg to point to the first character
6225 following the parsed filename in the arg string.
6227 Note that clients needing to preserve the returned filename for
6228 future access should copy it to their own buffers. */
6230 ep_parse_optional_filename (char **arg
)
6232 static char filename
[1024];
6237 if ((*arg_p
== '\0') || isspace (*arg_p
))
6255 /* Commands to deal with catching events, such as signals, exceptions,
6256 process start/exit, etc. */
6260 catch_fork
, catch_vfork
6265 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6268 char *cond_string
= NULL
;
6270 ep_skip_leading_whitespace (&arg
);
6272 /* The allowed syntax is:
6274 catch [v]fork if <cond>
6276 First, check if there's an if clause. */
6277 cond_string
= ep_parse_optional_if_clause (&arg
);
6279 if ((*arg
!= '\0') && !isspace (*arg
))
6280 error (_("Junk at end of arguments."));
6282 /* If this target supports it, create a fork or vfork catchpoint
6283 and enable reporting of such events. */
6287 create_fork_event_catchpoint (tempflag
, cond_string
);
6290 create_vfork_event_catchpoint (tempflag
, cond_string
);
6293 error (_("unsupported or unknown fork kind; cannot catch it"));
6299 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6301 char *cond_string
= NULL
;
6303 ep_skip_leading_whitespace (&arg
);
6305 /* The allowed syntax is:
6307 catch exec if <cond>
6309 First, check if there's an if clause. */
6310 cond_string
= ep_parse_optional_if_clause (&arg
);
6312 if ((*arg
!= '\0') && !isspace (*arg
))
6313 error (_("Junk at end of arguments."));
6315 /* If this target supports it, create an exec catchpoint
6316 and enable reporting of such events. */
6317 create_exec_event_catchpoint (tempflag
, cond_string
);
6321 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6323 char *dll_pathname
= NULL
;
6324 char *cond_string
= NULL
;
6326 ep_skip_leading_whitespace (&arg
);
6328 /* The allowed syntax is:
6330 catch load if <cond>
6331 catch load <filename>
6332 catch load <filename> if <cond>
6334 The user is not allowed to specify the <filename> after an
6337 We'll ignore the pathological case of a file named "if".
6339 First, check if there's an if clause. If so, then there
6340 cannot be a filename. */
6341 cond_string
= ep_parse_optional_if_clause (&arg
);
6343 /* If there was an if clause, then there cannot be a filename.
6344 Else, there might be a filename and an if clause. */
6345 if (cond_string
== NULL
)
6347 dll_pathname
= ep_parse_optional_filename (&arg
);
6348 ep_skip_leading_whitespace (&arg
);
6349 cond_string
= ep_parse_optional_if_clause (&arg
);
6352 if ((*arg
!= '\0') && !isspace (*arg
))
6353 error (_("Junk at end of arguments."));
6355 /* Create a load breakpoint that only triggers when a load of
6356 the specified dll (or any dll, if no pathname was specified)
6358 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6359 dll_pathname
, cond_string
);
6363 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6365 char *dll_pathname
= NULL
;
6366 char *cond_string
= NULL
;
6368 ep_skip_leading_whitespace (&arg
);
6370 /* The allowed syntax is:
6372 catch unload if <cond>
6373 catch unload <filename>
6374 catch unload <filename> if <cond>
6376 The user is not allowed to specify the <filename> after an
6379 We'll ignore the pathological case of a file named "if".
6381 First, check if there's an if clause. If so, then there
6382 cannot be a filename. */
6383 cond_string
= ep_parse_optional_if_clause (&arg
);
6385 /* If there was an if clause, then there cannot be a filename.
6386 Else, there might be a filename and an if clause. */
6387 if (cond_string
== NULL
)
6389 dll_pathname
= ep_parse_optional_filename (&arg
);
6390 ep_skip_leading_whitespace (&arg
);
6391 cond_string
= ep_parse_optional_if_clause (&arg
);
6394 if ((*arg
!= '\0') && !isspace (*arg
))
6395 error (_("Junk at end of arguments."));
6397 /* Create an unload breakpoint that only triggers when an unload of
6398 the specified dll (or any dll, if no pathname was specified)
6400 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6401 dll_pathname
, cond_string
);
6404 static enum print_stop_action
6405 print_exception_catchpoint (struct breakpoint
*b
)
6407 annotate_catchpoint (b
->number
);
6409 if (strstr (b
->addr_string
, "throw") != NULL
)
6410 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6413 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6416 return PRINT_SRC_AND_LOC
;
6420 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6425 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6428 *last_addr
= b
->loc
->address
;
6429 if (strstr (b
->addr_string
, "throw") != NULL
)
6430 ui_out_field_string (uiout
, "what", "exception throw");
6432 ui_out_field_string (uiout
, "what", "exception catch");
6436 print_mention_exception_catchpoint (struct breakpoint
*b
)
6438 if (strstr (b
->addr_string
, "throw") != NULL
)
6439 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6441 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6444 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6445 print_exception_catchpoint
,
6446 print_one_exception_catchpoint
,
6447 print_mention_exception_catchpoint
6451 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6452 enum exception_event_kind ex_event
, int from_tty
)
6454 char *trigger_func_name
, *nameptr
;
6455 struct symtabs_and_lines sals
;
6456 struct breakpoint
*b
;
6458 if (ex_event
== EX_EVENT_CATCH
)
6459 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6461 trigger_func_name
= xstrdup ("__cxa_throw");
6463 nameptr
= trigger_func_name
;
6464 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6465 if (sals
.nelts
== 0)
6467 xfree (trigger_func_name
);
6471 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6472 set_breakpoint_count (breakpoint_count
+ 1);
6473 b
->number
= breakpoint_count
;
6474 b
->cond_string
= (cond_string
== NULL
) ?
6475 NULL
: savestring (cond_string
, strlen (cond_string
));
6477 b
->addr_string
= trigger_func_name
;
6478 b
->enable_state
= bp_enabled
;
6479 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6480 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6487 /* Deal with "catch catch" and "catch throw" commands */
6490 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6491 int tempflag
, int from_tty
)
6493 char *cond_string
= NULL
;
6494 struct symtab_and_line
*sal
= NULL
;
6496 ep_skip_leading_whitespace (&arg
);
6498 cond_string
= ep_parse_optional_if_clause (&arg
);
6500 if ((*arg
!= '\0') && !isspace (*arg
))
6501 error (_("Junk at end of arguments."));
6503 if ((ex_event
!= EX_EVENT_THROW
) &&
6504 (ex_event
!= EX_EVENT_CATCH
))
6505 error (_("Unsupported or unknown exception event; cannot catch it"));
6507 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6510 warning (_("Unsupported with this platform/compiler combination."));
6513 /* Create a breakpoint struct for Ada exception catchpoints. */
6516 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6520 struct expression
*cond
,
6521 struct breakpoint_ops
*ops
,
6525 struct breakpoint
*b
;
6529 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6530 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6531 version for exception catchpoints, because two catchpoints
6532 used for different exception names will use the same address.
6533 In this case, a "breakpoint ... also set at..." warning is
6534 unproductive. Besides. the warning phrasing is also a bit
6535 inapropriate, we should use the word catchpoint, and tell
6536 the user what type of catchpoint it is. The above is good
6537 enough for now, though. */
6540 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6541 set_breakpoint_count (breakpoint_count
+ 1);
6543 b
->enable_state
= bp_enabled
;
6544 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6545 b
->number
= breakpoint_count
;
6546 b
->ignore_count
= 0;
6547 b
->loc
->cond
= cond
;
6548 b
->addr_string
= addr_string
;
6549 b
->language
= language_ada
;
6550 b
->cond_string
= cond_string
;
6551 b
->exp_string
= exp_string
;
6558 /* Implement the "catch exception" command. */
6561 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6563 struct symtab_and_line sal
;
6565 char *addr_string
= NULL
;
6566 char *exp_string
= NULL
;
6567 char *cond_string
= NULL
;
6568 struct expression
*cond
= NULL
;
6569 struct breakpoint_ops
*ops
= NULL
;
6571 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6572 &cond_string
, &cond
, &ops
);
6573 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6574 cond_string
, cond
, ops
, tempflag
,
6578 /* Implement the "catch assert" command. */
6581 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6583 struct symtab_and_line sal
;
6584 char *addr_string
= NULL
;
6585 struct breakpoint_ops
*ops
= NULL
;
6587 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6588 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6589 tempflag
, from_tty
);
6593 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6596 /* The first argument may be an event name, such as "start" or "load".
6597 If so, then handle it as such. If it doesn't match an event name,
6598 then attempt to interpret it as an exception name. (This latter is
6599 the v4.16-and-earlier GDB meaning of the "catch" command.)
6601 First, try to find the bounds of what might be an event name. */
6602 char *arg1_start
= arg
;
6606 if (arg1_start
== NULL
)
6608 /* Old behaviour was to use pre-v-4.16 syntax */
6609 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6611 /* Now, this is not allowed */
6612 error (_("Catch requires an event name."));
6615 arg1_end
= ep_find_event_name_end (arg1_start
);
6616 if (arg1_end
== NULL
)
6617 error (_("catch requires an event"));
6618 arg1_length
= arg1_end
+ 1 - arg1_start
;
6620 /* Try to match what we found against known event names. */
6621 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6623 error (_("Catch of signal not yet implemented"));
6625 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6627 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6628 tempflag
, from_tty
);
6630 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6632 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6633 tempflag
, from_tty
);
6635 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6637 error (_("Catch of thread_start not yet implemented"));
6639 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6641 error (_("Catch of thread_exit not yet implemented"));
6643 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6645 error (_("Catch of thread_join not yet implemented"));
6647 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6649 error (_("Catch of start not yet implemented"));
6651 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6653 error (_("Catch of exit not yet implemented"));
6655 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6657 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6659 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6661 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6663 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6665 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6667 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6669 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6671 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6673 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6675 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6677 error (_("Catch of stop not yet implemented"));
6679 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6681 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6684 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6686 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6689 /* This doesn't appear to be an event name */
6693 /* Pre-v.4.16 behaviour was to treat the argument
6694 as the name of an exception */
6695 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6696 /* Now this is not allowed */
6697 error (_("Unknown event kind specified for catch"));
6703 catch_command (char *arg
, int from_tty
)
6705 catch_command_1 (arg
, 0, from_tty
);
6710 tcatch_command (char *arg
, int from_tty
)
6712 catch_command_1 (arg
, 1, from_tty
);
6715 /* Delete breakpoints by address or line. */
6718 clear_command (char *arg
, int from_tty
)
6720 struct breakpoint
*b
;
6721 VEC(breakpoint_p
) *found
= 0;
6724 struct symtabs_and_lines sals
;
6725 struct symtab_and_line sal
;
6730 sals
= decode_line_spec (arg
, 1);
6735 sals
.sals
= (struct symtab_and_line
*)
6736 xmalloc (sizeof (struct symtab_and_line
));
6737 make_cleanup (xfree
, sals
.sals
);
6738 init_sal (&sal
); /* initialize to zeroes */
6739 sal
.line
= default_breakpoint_line
;
6740 sal
.symtab
= default_breakpoint_symtab
;
6741 sal
.pc
= default_breakpoint_address
;
6742 if (sal
.symtab
== 0)
6743 error (_("No source file specified."));
6751 /* We don't call resolve_sal_pc here. That's not
6752 as bad as it seems, because all existing breakpoints
6753 typically have both file/line and pc set. So, if
6754 clear is given file/line, we can match this to existing
6755 breakpoint without obtaining pc at all.
6757 We only support clearing given the address explicitly
6758 present in breakpoint table. Say, we've set breakpoint
6759 at file:line. There were several PC values for that file:line,
6760 due to optimization, all in one block.
6761 We've picked one PC value. If "clear" is issued with another
6762 PC corresponding to the same file:line, the breakpoint won't
6763 be cleared. We probably can still clear the breakpoint, but
6764 since the other PC value is never presented to user, user
6765 can only find it by guessing, and it does not seem important
6768 /* For each line spec given, delete bps which correspond
6769 to it. Do it in two passes, solely to preserve the current
6770 behavior that from_tty is forced true if we delete more than
6774 for (i
= 0; i
< sals
.nelts
; i
++)
6776 /* If exact pc given, clear bpts at that pc.
6777 If line given (pc == 0), clear all bpts on specified line.
6778 If defaulting, clear all bpts on default line
6781 defaulting sal.pc != 0 tests to do
6786 1 0 <can't happen> */
6790 /* Find all matching breakpoints and add them to
6795 /* Are we going to delete b? */
6796 if (b
->type
!= bp_none
6797 && b
->type
!= bp_watchpoint
6798 && b
->type
!= bp_hardware_watchpoint
6799 && b
->type
!= bp_read_watchpoint
6800 && b
->type
!= bp_access_watchpoint
)
6802 struct bp_location
*loc
= b
->loc
;
6803 for (; loc
; loc
= loc
->next
)
6805 int pc_match
= sal
.pc
6806 && (loc
->address
== sal
.pc
)
6807 && (!section_is_overlay (loc
->section
)
6808 || loc
->section
== sal
.section
);
6809 int line_match
= ((default_match
|| (0 == sal
.pc
))
6810 && b
->source_file
!= NULL
6811 && sal
.symtab
!= NULL
6812 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6813 && b
->line_number
== sal
.line
);
6814 if (pc_match
|| line_match
)
6823 VEC_safe_push(breakpoint_p
, found
, b
);
6826 /* Now go thru the 'found' chain and delete them. */
6827 if (VEC_empty(breakpoint_p
, found
))
6830 error (_("No breakpoint at %s."), arg
);
6832 error (_("No breakpoint at this line."));
6835 if (VEC_length(breakpoint_p
, found
) > 1)
6836 from_tty
= 1; /* Always report if deleted more than one */
6839 if (VEC_length(breakpoint_p
, found
) == 1)
6840 printf_unfiltered (_("Deleted breakpoint "));
6842 printf_unfiltered (_("Deleted breakpoints "));
6844 breakpoints_changed ();
6846 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6849 printf_unfiltered ("%d ", b
->number
);
6850 delete_breakpoint (b
);
6853 putchar_unfiltered ('\n');
6856 /* Delete breakpoint in BS if they are `delete' breakpoints and
6857 all breakpoints that are marked for deletion, whether hit or not.
6858 This is called after any breakpoint is hit, or after errors. */
6861 breakpoint_auto_delete (bpstat bs
)
6863 struct breakpoint
*b
, *temp
;
6865 for (; bs
; bs
= bs
->next
)
6866 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
->disposition
== disp_del
6868 delete_breakpoint (bs
->breakpoint_at
->owner
);
6870 ALL_BREAKPOINTS_SAFE (b
, temp
)
6872 if (b
->disposition
== disp_del_at_next_stop
)
6873 delete_breakpoint (b
);
6877 /* Remove locations of breakpoint BPT from
6878 the global list of breakpoint locations. */
6881 unlink_locations_from_global_list (struct breakpoint
*bpt
)
6883 /* This code assumes that the locations
6884 of a breakpoint are found in the global list
6885 in the same order, but not necessary adjacent. */
6886 struct bp_location
**tmp
= &bp_location_chain
;
6887 struct bp_location
*here
= bpt
->loc
;
6892 for (; *tmp
&& here
;)
6896 *tmp
= here
->global_next
;
6901 tmp
= &((*tmp
)->global_next
);
6906 /* Delete a breakpoint and clean up all traces of it in the data
6910 delete_breakpoint (struct breakpoint
*bpt
)
6912 struct breakpoint
*b
;
6914 struct bp_location
*loc
;
6916 gdb_assert (bpt
!= NULL
);
6918 /* Has this bp already been deleted? This can happen because multiple
6919 lists can hold pointers to bp's. bpstat lists are especial culprits.
6921 One example of this happening is a watchpoint's scope bp. When the
6922 scope bp triggers, we notice that the watchpoint is out of scope, and
6923 delete it. We also delete its scope bp. But the scope bp is marked
6924 "auto-deleting", and is already on a bpstat. That bpstat is then
6925 checked for auto-deleting bp's, which are deleted.
6927 A real solution to this problem might involve reference counts in bp's,
6928 and/or giving them pointers back to their referencing bpstat's, and
6929 teaching delete_breakpoint to only free a bp's storage when no more
6930 references were extent. A cheaper bandaid was chosen. */
6931 if (bpt
->type
== bp_none
)
6934 if (deprecated_delete_breakpoint_hook
)
6935 deprecated_delete_breakpoint_hook (bpt
);
6936 breakpoint_delete_event (bpt
->number
);
6938 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
6941 remove_breakpoint (loc
, mark_inserted
);
6946 if (loc
->function_name
)
6947 xfree (loc
->function_name
);
6950 if (breakpoint_chain
== bpt
)
6951 breakpoint_chain
= bpt
->next
;
6956 b
->next
= bpt
->next
;
6960 unlink_locations_from_global_list (bpt
);
6962 check_duplicates (bpt
);
6964 if (bpt
->type
!= bp_hardware_watchpoint
6965 && bpt
->type
!= bp_read_watchpoint
6966 && bpt
->type
!= bp_access_watchpoint
6967 && bpt
->type
!= bp_catch_fork
6968 && bpt
->type
!= bp_catch_vfork
6969 && bpt
->type
!= bp_catch_exec
)
6970 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
6972 /* If this breakpoint location was inserted, and there is
6973 another breakpoint at the same address, we need to
6974 insert the other breakpoint. */
6977 struct bp_location
*loc2
;
6978 ALL_BP_LOCATIONS (loc2
)
6979 if (loc2
->address
== loc
->address
6980 && loc2
->section
== loc
->section
6982 && loc2
->owner
->enable_state
!= bp_disabled
6984 && !loc2
->shlib_disabled
6985 && loc2
->owner
->enable_state
!= bp_call_disabled
)
6989 /* We should never reach this point if there is a permanent
6990 breakpoint at the same address as the one being deleted.
6991 If there is a permanent breakpoint somewhere, it should
6992 always be the only one inserted. */
6993 if (loc2
->owner
->enable_state
== bp_permanent
)
6994 internal_error (__FILE__
, __LINE__
,
6995 _("another breakpoint was inserted on top of "
6996 "a permanent breakpoint"));
6998 memset (&loc2
->target_info
, 0, sizeof (loc2
->target_info
));
6999 loc2
->target_info
.placed_address
= loc2
->address
;
7000 if (b
->type
== bp_hardware_breakpoint
)
7001 val
= target_insert_hw_breakpoint (&loc2
->target_info
);
7003 val
= target_insert_breakpoint (&loc2
->target_info
);
7005 /* If there was an error in the insert, print a message, then stop execution. */
7008 struct ui_file
*tmp_error_stream
= mem_fileopen ();
7009 make_cleanup_ui_file_delete (tmp_error_stream
);
7012 if (b
->type
== bp_hardware_breakpoint
)
7014 fprintf_unfiltered (tmp_error_stream
,
7015 "Cannot insert hardware breakpoint %d.\n"
7016 "You may have requested too many hardware breakpoints.\n",
7021 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
7022 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
7023 fputs_filtered (paddress (loc2
->address
),
7025 fprintf_filtered (tmp_error_stream
, ": %s.\n",
7026 safe_strerror (val
));
7029 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
7030 target_terminal_ours_for_output ();
7031 error_stream(tmp_error_stream
);
7039 free_command_lines (&bpt
->commands
);
7040 if (bpt
->cond_string
!= NULL
)
7041 xfree (bpt
->cond_string
);
7042 if (bpt
->addr_string
!= NULL
)
7043 xfree (bpt
->addr_string
);
7044 if (bpt
->exp
!= NULL
)
7046 if (bpt
->exp_string
!= NULL
)
7047 xfree (bpt
->exp_string
);
7048 if (bpt
->val
!= NULL
)
7049 value_free (bpt
->val
);
7050 if (bpt
->source_file
!= NULL
)
7051 xfree (bpt
->source_file
);
7052 if (bpt
->dll_pathname
!= NULL
)
7053 xfree (bpt
->dll_pathname
);
7054 if (bpt
->triggered_dll_pathname
!= NULL
)
7055 xfree (bpt
->triggered_dll_pathname
);
7056 if (bpt
->exec_pathname
!= NULL
)
7057 xfree (bpt
->exec_pathname
);
7059 /* Be sure no bpstat's are pointing at it after it's been freed. */
7060 /* FIXME, how can we find all bpstat's?
7061 We just check stop_bpstat for now. Note that we cannot just
7062 remove bpstats pointing at bpt from the stop_bpstat list
7063 entirely, as breakpoint commands are associated with the bpstat;
7064 if we remove it here, then the later call to
7065 bpstat_do_actions (&stop_bpstat);
7066 in event-top.c won't do anything, and temporary breakpoints
7067 with commands won't work. */
7068 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
7069 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7071 bs
->breakpoint_at
= NULL
;
7073 /* bs->commands will be freed later. */
7075 /* On the chance that someone will soon try again to delete this same
7076 bp, we mark it as deleted before freeing its storage. */
7077 bpt
->type
= bp_none
;
7079 for (loc
= bpt
->loc
; loc
;)
7081 struct bp_location
*loc_next
= loc
->next
;
7089 do_delete_breakpoint_cleanup (void *b
)
7091 delete_breakpoint (b
);
7095 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7097 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7101 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
7103 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
7107 delete_command (char *arg
, int from_tty
)
7109 struct breakpoint
*b
, *temp
;
7115 int breaks_to_delete
= 0;
7117 /* Delete all breakpoints if no argument.
7118 Do not delete internal or call-dummy breakpoints, these
7119 have to be deleted with an explicit breakpoint number argument. */
7122 if (b
->type
!= bp_call_dummy
&&
7123 b
->type
!= bp_shlib_event
&&
7124 b
->type
!= bp_thread_event
&&
7125 b
->type
!= bp_overlay_event
&&
7128 breaks_to_delete
= 1;
7133 /* Ask user only if there are some breakpoints to delete. */
7135 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7137 ALL_BREAKPOINTS_SAFE (b
, temp
)
7139 if (b
->type
!= bp_call_dummy
&&
7140 b
->type
!= bp_shlib_event
&&
7141 b
->type
!= bp_thread_event
&&
7142 b
->type
!= bp_overlay_event
&&
7144 delete_breakpoint (b
);
7149 map_breakpoint_numbers (arg
, delete_breakpoint
);
7153 all_locations_are_pending (struct bp_location
*loc
)
7155 for (; loc
; loc
= loc
->next
)
7156 if (!loc
->shlib_disabled
)
7161 /* Subroutine of update_breakpoint_locations to simplify it.
7162 Return non-zero if multiple fns in list LOC have the same name.
7163 Null names are ignored. */
7166 ambiguous_names_p (struct bp_location
*loc
)
7168 struct bp_location
*l
;
7169 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7170 (int (*) (const void *, const void *)) streq
,
7171 NULL
, xcalloc
, xfree
);
7173 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7176 const char *name
= l
->function_name
;
7178 /* Allow for some names to be NULL, ignore them. */
7182 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7184 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7199 update_breakpoint_locations (struct breakpoint
*b
,
7200 struct symtabs_and_lines sals
)
7204 struct bp_location
*existing_locations
= b
->loc
;
7206 /* If there's no new locations, and all existing locations
7207 are pending, don't do anything. This optimizes
7208 the common case where all locations are in the same
7209 shared library, that was unloaded. We'd like to
7210 retain the location, so that when the library
7211 is loaded again, we don't loose the enabled/disabled
7212 status of the individual locations. */
7213 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7216 unlink_locations_from_global_list (b
);
7219 for (i
= 0; i
< sals
.nelts
; ++i
)
7221 struct bp_location
*new_loc
=
7222 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7224 /* Reparse conditions, they might contain references to the
7226 if (b
->cond_string
!= NULL
)
7228 struct gdb_exception e
;
7231 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7233 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7238 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7239 b
->number
, e
.message
);
7240 new_loc
->enabled
= 0;
7244 if (b
->source_file
!= NULL
)
7245 xfree (b
->source_file
);
7246 if (sals
.sals
[i
].symtab
== NULL
)
7247 b
->source_file
= NULL
;
7250 savestring (sals
.sals
[i
].symtab
->filename
,
7251 strlen (sals
.sals
[i
].symtab
->filename
));
7253 if (b
->line_number
== 0)
7254 b
->line_number
= sals
.sals
[i
].line
;
7257 /* If possible, carry over 'disable' status from existing breakpoints. */
7259 struct bp_location
*e
= existing_locations
;
7260 /* If there are multiple breakpoints with the same function name,
7261 e.g. for inline functions, comparing function names won't work.
7262 Instead compare pc addresses; this is just a heuristic as things
7263 may have moved, but in practice it gives the correct answer
7264 often enough until a better solution is found. */
7265 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7267 for (; e
; e
= e
->next
)
7269 if (!e
->enabled
&& e
->function_name
)
7271 struct bp_location
*l
= b
->loc
;
7272 if (have_ambiguous_names
)
7274 for (; l
; l
= l
->next
)
7275 if (e
->address
== l
->address
)
7283 for (; l
; l
= l
->next
)
7284 if (l
->function_name
7285 && strcmp (e
->function_name
, l
->function_name
) == 0)
7295 while (existing_locations
)
7297 struct bp_location
*next
= existing_locations
->next
;
7298 free_bp_location (existing_locations
);
7299 existing_locations
= next
;
7304 /* Reset a breakpoint given it's struct breakpoint * BINT.
7305 The value we return ends up being the return value from catch_errors.
7306 Unused in this case. */
7309 breakpoint_re_set_one (void *bint
)
7311 /* get past catch_errs */
7312 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7316 int *not_found_ptr
= ¬_found
;
7317 struct symtabs_and_lines sals
= {};
7318 struct symtabs_and_lines expanded
;
7320 enum enable_state save_enable
;
7321 struct gdb_exception e
;
7327 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7331 case bp_hardware_breakpoint
:
7333 case bp_catch_unload
:
7334 if (b
->addr_string
== NULL
)
7336 /* Anything without a string can't be re-set. */
7337 delete_breakpoint (b
);
7341 set_language (b
->language
);
7342 input_radix
= b
->input_radix
;
7344 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7346 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7351 int not_found_and_ok
= 0;
7352 /* For pending breakpoints, it's expected that parsing
7353 will fail until the right shared library is loaded.
7354 User has already told to create pending breakpoints and
7355 don't need extra messages. If breakpoint is in bp_shlib_disabled
7356 state, then user already saw the message about that breakpoint
7357 being disabled, and don't want to see more errors. */
7359 && (b
->condition_not_parsed
7360 || (b
->loc
&& b
->loc
->shlib_disabled
)
7361 || b
->enable_state
== bp_disabled
))
7362 not_found_and_ok
= 1;
7364 if (!not_found_and_ok
)
7366 /* We surely don't want to warn about the same breakpoint
7367 10 times. One solution, implemented here, is disable
7368 the breakpoint on error. Another solution would be to
7369 have separate 'warning emitted' flag. Since this
7370 happens only when a binary has changed, I don't know
7371 which approach is better. */
7372 b
->enable_state
= bp_disabled
;
7373 throw_exception (e
);
7380 gdb_assert (sals
.nelts
== 1);
7381 resolve_sal_pc (&sals
.sals
[0]);
7382 if (b
->condition_not_parsed
&& s
&& s
[0])
7384 char *cond_string
= 0;
7386 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7387 &cond_string
, &thread
);
7389 b
->cond_string
= cond_string
;
7391 b
->condition_not_parsed
= 0;
7393 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7394 update_breakpoint_locations (b
, expanded
);
7396 /* Now that this is re-enabled, check_duplicates
7398 check_duplicates (b
);
7404 case bp_hardware_watchpoint
:
7405 case bp_read_watchpoint
:
7406 case bp_access_watchpoint
:
7407 /* Watchpoint can be either on expression using entirely global variables,
7408 or it can be on local variables.
7410 Watchpoints of the first kind are never auto-deleted, and even persist
7411 across program restarts. Since they can use variables from shared
7412 libraries, we need to reparse expression as libraries are loaded
7415 Watchpoints on local variables can also change meaning as result
7416 of solib event. For example, if a watchpoint uses both a local and
7417 a global variables in expression, it's a local watchpoint, but
7418 unloading of a shared library will make the expression invalid.
7419 This is not a very common use case, but we still re-evaluate
7420 expression, to avoid surprises to the user.
7422 Note that for local watchpoints, we re-evaluate it only if
7423 watchpoints frame id is still valid. If it's not, it means
7424 the watchpoint is out of scope and will be deleted soon. In fact,
7425 I'm not sure we'll ever be called in this case.
7427 If a local watchpoint's frame id is still valid, then
7428 b->exp_valid_block is likewise valid, and we can safely use it.
7430 Don't do anything about disabled watchpoints, since they will
7431 be reevaluated again when enabled. */
7432 update_watchpoint (b
, 1 /* reparse */);
7434 /* We needn't really do anything to reset these, since the mask
7435 that requests them is unaffected by e.g., new libraries being
7438 case bp_catch_vfork
:
7443 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7445 /* Delete longjmp and overlay event breakpoints; they will be
7446 reset later by breakpoint_re_set. */
7448 case bp_longjmp_resume
:
7449 case bp_overlay_event
:
7450 delete_breakpoint (b
);
7453 /* This breakpoint is special, it's set up when the inferior
7454 starts and we really don't want to touch it. */
7455 case bp_shlib_event
:
7457 /* Like bp_shlib_event, this breakpoint type is special.
7458 Once it is set up, we do not want to touch it. */
7459 case bp_thread_event
:
7461 /* Keep temporary breakpoints, which can be encountered when we step
7462 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7463 Otherwise these should have been blown away via the cleanup chain
7464 or by breakpoint_init_inferior when we rerun the executable. */
7467 case bp_watchpoint_scope
:
7469 case bp_step_resume
:
7476 /* Re-set all breakpoints after symbols have been re-loaded. */
7478 breakpoint_re_set (void)
7480 struct breakpoint
*b
, *temp
;
7481 enum language save_language
;
7482 int save_input_radix
;
7484 save_language
= current_language
->la_language
;
7485 save_input_radix
= input_radix
;
7486 ALL_BREAKPOINTS_SAFE (b
, temp
)
7488 /* Format possible error msg */
7489 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7491 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7492 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7493 do_cleanups (cleanups
);
7495 set_language (save_language
);
7496 input_radix
= save_input_radix
;
7498 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
7500 create_longjmp_breakpoint ("longjmp");
7501 create_longjmp_breakpoint ("_longjmp");
7502 create_longjmp_breakpoint ("siglongjmp");
7503 create_longjmp_breakpoint ("_siglongjmp");
7504 create_longjmp_breakpoint (NULL
);
7507 create_overlay_event_breakpoint ("_ovly_debug_event");
7510 /* Reset the thread number of this breakpoint:
7512 - If the breakpoint is for all threads, leave it as-is.
7513 - Else, reset it to the current thread for inferior_ptid. */
7515 breakpoint_re_set_thread (struct breakpoint
*b
)
7517 if (b
->thread
!= -1)
7519 if (in_thread_list (inferior_ptid
))
7520 b
->thread
= pid_to_thread_id (inferior_ptid
);
7524 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7525 If from_tty is nonzero, it prints a message to that effect,
7526 which ends with a period (no newline). */
7529 set_ignore_count (int bptnum
, int count
, int from_tty
)
7531 struct breakpoint
*b
;
7537 if (b
->number
== bptnum
)
7539 b
->ignore_count
= count
;
7543 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7545 else if (count
== 1)
7546 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7549 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7552 breakpoints_changed ();
7553 breakpoint_modify_event (b
->number
);
7557 error (_("No breakpoint number %d."), bptnum
);
7560 /* Clear the ignore counts of all breakpoints. */
7562 breakpoint_clear_ignore_counts (void)
7564 struct breakpoint
*b
;
7567 b
->ignore_count
= 0;
7570 /* Command to set ignore-count of breakpoint N to COUNT. */
7573 ignore_command (char *args
, int from_tty
)
7579 error_no_arg (_("a breakpoint number"));
7581 num
= get_number (&p
);
7583 error (_("bad breakpoint number: '%s'"), args
);
7585 error (_("Second argument (specified ignore-count) is missing."));
7587 set_ignore_count (num
,
7588 longest_to_int (value_as_long (parse_and_eval (p
))),
7591 printf_filtered ("\n");
7594 /* Call FUNCTION on each of the breakpoints
7595 whose numbers are given in ARGS. */
7598 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7603 struct breakpoint
*b
, *tmp
;
7607 error_no_arg (_("one or more breakpoint numbers"));
7614 num
= get_number_or_range (&p1
);
7617 warning (_("bad breakpoint number at or near '%s'"), p
);
7621 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7622 if (b
->number
== num
)
7624 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7627 if (related_breakpoint
)
7628 function (related_breakpoint
);
7632 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7638 static struct bp_location
*
7639 find_location_by_number (char *number
)
7641 char *dot
= strchr (number
, '.');
7645 struct breakpoint
*b
;
7646 struct bp_location
*loc
;
7651 bp_num
= get_number_or_range (&p1
);
7653 error (_("Bad breakpoint number '%s'"), number
);
7656 if (b
->number
== bp_num
)
7661 if (!b
|| b
->number
!= bp_num
)
7662 error (_("Bad breakpoint number '%s'"), number
);
7665 loc_num
= get_number_or_range (&p1
);
7667 error (_("Bad breakpoint location number '%s'"), number
);
7671 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7674 error (_("Bad breakpoint location number '%s'"), dot
+1);
7680 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7681 If from_tty is nonzero, it prints a message to that effect,
7682 which ends with a period (no newline). */
7685 disable_breakpoint (struct breakpoint
*bpt
)
7687 /* Never disable a watchpoint scope breakpoint; we want to
7688 hit them when we leave scope so we can delete both the
7689 watchpoint and its scope breakpoint at that time. */
7690 if (bpt
->type
== bp_watchpoint_scope
)
7693 /* You can't disable permanent breakpoints. */
7694 if (bpt
->enable_state
== bp_permanent
)
7697 bpt
->enable_state
= bp_disabled
;
7699 check_duplicates (bpt
);
7701 if (deprecated_modify_breakpoint_hook
)
7702 deprecated_modify_breakpoint_hook (bpt
);
7703 breakpoint_modify_event (bpt
->number
);
7707 disable_command (char *args
, int from_tty
)
7709 struct breakpoint
*bpt
;
7711 ALL_BREAKPOINTS (bpt
)
7715 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7720 case bp_catch_unload
:
7722 case bp_catch_vfork
:
7724 case bp_hardware_breakpoint
:
7726 case bp_hardware_watchpoint
:
7727 case bp_read_watchpoint
:
7728 case bp_access_watchpoint
:
7729 disable_breakpoint (bpt
);
7733 else if (strchr (args
, '.'))
7735 struct bp_location
*loc
= find_location_by_number (args
);
7738 check_duplicates (loc
->owner
);
7741 map_breakpoint_numbers (args
, disable_breakpoint
);
7745 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7747 int target_resources_ok
, other_type_used
;
7750 if (bpt
->type
== bp_hardware_breakpoint
)
7753 i
= hw_breakpoint_used_count ();
7754 target_resources_ok
=
7755 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7757 if (target_resources_ok
== 0)
7758 error (_("No hardware breakpoint support in the target."));
7759 else if (target_resources_ok
< 0)
7760 error (_("Hardware breakpoints used exceeds limit."));
7763 if (bpt
->type
== bp_watchpoint
||
7764 bpt
->type
== bp_hardware_watchpoint
||
7765 bpt
->type
== bp_read_watchpoint
||
7766 bpt
->type
== bp_access_watchpoint
)
7768 struct frame_id saved_frame_id
;
7770 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7771 if (bpt
->exp_valid_block
!= NULL
)
7773 struct frame_info
*fr
=
7774 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7777 printf_filtered (_("\
7778 Cannot enable watchpoint %d because the block in which its expression\n\
7779 is valid is not currently in scope.\n"), bpt
->number
);
7786 value_free (bpt
->val
);
7787 mark
= value_mark ();
7788 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7790 release_value (bpt
->val
);
7793 if (bpt
->type
== bp_hardware_watchpoint
||
7794 bpt
->type
== bp_read_watchpoint
||
7795 bpt
->type
== bp_access_watchpoint
)
7797 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7798 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7800 /* Hack around 'unused var' error for some targets here */
7801 (void) mem_cnt
, (void) i
;
7802 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7803 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7804 /* we can consider of type is bp_hardware_watchpoint, convert to
7805 bp_watchpoint in the following condition */
7806 if (target_resources_ok
< 0)
7808 printf_filtered (_("\
7809 Cannot enable watchpoint %d because target watch resources\n\
7810 have been allocated for other watchpoints.\n"), bpt
->number
);
7811 value_free_to_mark (mark
);
7816 select_frame (frame_find_by_id (saved_frame_id
));
7817 value_free_to_mark (mark
);
7820 if (bpt
->enable_state
!= bp_permanent
)
7821 bpt
->enable_state
= bp_enabled
;
7822 bpt
->disposition
= disposition
;
7823 check_duplicates (bpt
);
7824 breakpoints_changed ();
7826 if (deprecated_modify_breakpoint_hook
)
7827 deprecated_modify_breakpoint_hook (bpt
);
7828 breakpoint_modify_event (bpt
->number
);
7833 enable_breakpoint (struct breakpoint
*bpt
)
7835 do_enable_breakpoint (bpt
, bpt
->disposition
);
7838 /* The enable command enables the specified breakpoints (or all defined
7839 breakpoints) so they once again become (or continue to be) effective
7840 in stopping the inferior. */
7843 enable_command (char *args
, int from_tty
)
7845 struct breakpoint
*bpt
;
7847 ALL_BREAKPOINTS (bpt
)
7851 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7856 case bp_catch_unload
:
7858 case bp_catch_vfork
:
7860 case bp_hardware_breakpoint
:
7862 case bp_hardware_watchpoint
:
7863 case bp_read_watchpoint
:
7864 case bp_access_watchpoint
:
7865 enable_breakpoint (bpt
);
7869 else if (strchr (args
, '.'))
7871 struct bp_location
*loc
= find_location_by_number (args
);
7874 check_duplicates (loc
->owner
);
7877 map_breakpoint_numbers (args
, enable_breakpoint
);
7881 enable_once_breakpoint (struct breakpoint
*bpt
)
7883 do_enable_breakpoint (bpt
, disp_disable
);
7887 enable_once_command (char *args
, int from_tty
)
7889 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7893 enable_delete_breakpoint (struct breakpoint
*bpt
)
7895 do_enable_breakpoint (bpt
, disp_del
);
7899 enable_delete_command (char *args
, int from_tty
)
7901 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7905 set_breakpoint_cmd (char *args
, int from_tty
)
7910 show_breakpoint_cmd (char *args
, int from_tty
)
7914 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7916 struct symtabs_and_lines
7917 decode_line_spec_1 (char *string
, int funfirstline
)
7919 struct symtabs_and_lines sals
;
7921 error (_("Empty line specification."));
7922 if (default_breakpoint_valid
)
7923 sals
= decode_line_1 (&string
, funfirstline
,
7924 default_breakpoint_symtab
,
7925 default_breakpoint_line
,
7926 (char ***) NULL
, NULL
);
7928 sals
= decode_line_1 (&string
, funfirstline
,
7929 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7931 error (_("Junk at end of line specification: %s"), string
);
7935 /* Create and insert a raw software breakpoint at PC. Return an
7936 identifier, which should be used to remove the breakpoint later.
7937 In general, places which call this should be using something on the
7938 breakpoint chain instead; this function should be eliminated
7942 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7944 struct bp_target_info
*bp_tgt
;
7946 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7947 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7949 bp_tgt
->placed_address
= pc
;
7950 if (target_insert_breakpoint (bp_tgt
) != 0)
7952 /* Could not insert the breakpoint. */
7960 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7963 deprecated_remove_raw_breakpoint (void *bp
)
7965 struct bp_target_info
*bp_tgt
= bp
;
7968 ret
= target_remove_breakpoint (bp_tgt
);
7974 /* One (or perhaps two) breakpoints used for software single stepping. */
7976 static void *single_step_breakpoints
[2];
7978 /* Create and insert a breakpoint for software single step. */
7981 insert_single_step_breakpoint (CORE_ADDR next_pc
)
7985 if (single_step_breakpoints
[0] == NULL
)
7986 bpt_p
= &single_step_breakpoints
[0];
7989 gdb_assert (single_step_breakpoints
[1] == NULL
);
7990 bpt_p
= &single_step_breakpoints
[1];
7993 /* NOTE drow/2006-04-11: A future improvement to this function would be
7994 to only create the breakpoints once, and actually put them on the
7995 breakpoint chain. That would let us use set_raw_breakpoint. We could
7996 adjust the addresses each time they were needed. Doing this requires
7997 corresponding changes elsewhere where single step breakpoints are
7998 handled, however. So, for now, we use this. */
8000 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8002 error (_("Could not insert single-step breakpoint at 0x%s"),
8003 paddr_nz (next_pc
));
8006 /* Remove and delete any breakpoints used for software single step. */
8009 remove_single_step_breakpoints (void)
8011 gdb_assert (single_step_breakpoints
[0] != NULL
);
8013 /* See insert_single_step_breakpoint for more about this deprecated
8015 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8016 single_step_breakpoints
[0] = NULL
;
8018 if (single_step_breakpoints
[1] != NULL
)
8020 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8021 single_step_breakpoints
[1] = NULL
;
8025 /* Check whether a software single-step breakpoint is inserted at PC. */
8028 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8032 for (i
= 0; i
< 2; i
++)
8034 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8035 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8043 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8044 It is defined as a macro to prevent duplication.
8045 COMMAND should be a string constant containing the name of the command. */
8046 #define BREAK_ARGS_HELP(command) \
8047 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8048 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8049 If a line number is specified, break at start of code for that line.\n\
8050 If a function is specified, break at start of code for that function.\n\
8051 If an address is specified, break at that exact address.\n\
8052 With no LOCATION, uses current execution address of selected stack frame.\n\
8053 This is useful for breaking on return to a stack frame.\n\
8055 THREADNUM is the number from \"info threads\".\n\
8056 CONDITION is a boolean expression.\n\
8058 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8060 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8063 _initialize_breakpoint (void)
8065 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8066 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8067 struct cmd_list_element
*c
;
8069 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8071 breakpoint_chain
= 0;
8072 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8073 before a breakpoint is set. */
8074 breakpoint_count
= 0;
8076 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8077 Set ignore-count of breakpoint number N to COUNT.\n\
8078 Usage is `ignore N COUNT'."));
8080 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8082 add_com ("commands", class_breakpoint
, commands_command
, _("\
8083 Set commands to be executed when a breakpoint is hit.\n\
8084 Give breakpoint number as argument after \"commands\".\n\
8085 With no argument, the targeted breakpoint is the last one set.\n\
8086 The commands themselves follow starting on the next line.\n\
8087 Type a line containing \"end\" to indicate the end of them.\n\
8088 Give \"silent\" as the first line to make the breakpoint silent;\n\
8089 then no output is printed when it is hit, except what the commands print."));
8091 add_com ("condition", class_breakpoint
, condition_command
, _("\
8092 Specify breakpoint number N to break only if COND is true.\n\
8093 Usage is `condition N COND', where N is an integer and COND is an\n\
8094 expression to be evaluated whenever breakpoint N is reached."));
8096 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8097 Set a temporary breakpoint.\n\
8098 Like \"break\" except the breakpoint is only temporary,\n\
8099 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8100 by using \"enable delete\" on the breakpoint number.\n\
8102 BREAK_ARGS_HELP ("tbreak")));
8103 set_cmd_completer (c
, location_completer
);
8105 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8106 Set a hardware assisted breakpoint.\n\
8107 Like \"break\" except the breakpoint requires hardware support,\n\
8108 some target hardware may not have this support.\n\
8110 BREAK_ARGS_HELP ("hbreak")));
8111 set_cmd_completer (c
, location_completer
);
8113 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8114 Set a temporary hardware assisted breakpoint.\n\
8115 Like \"hbreak\" except the breakpoint is only temporary,\n\
8116 so it will be deleted when hit.\n\
8118 BREAK_ARGS_HELP ("thbreak")));
8119 set_cmd_completer (c
, location_completer
);
8121 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8122 Enable some breakpoints.\n\
8123 Give breakpoint numbers (separated by spaces) as arguments.\n\
8124 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8125 This is used to cancel the effect of the \"disable\" command.\n\
8126 With a subcommand you can enable temporarily."),
8127 &enablelist
, "enable ", 1, &cmdlist
);
8129 add_com ("ab", class_breakpoint
, enable_command
, _("\
8130 Enable some breakpoints.\n\
8131 Give breakpoint numbers (separated by spaces) as arguments.\n\
8132 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8133 This is used to cancel the effect of the \"disable\" command.\n\
8134 With a subcommand you can enable temporarily."));
8136 add_com_alias ("en", "enable", class_breakpoint
, 1);
8138 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8139 Enable some breakpoints.\n\
8140 Give breakpoint numbers (separated by spaces) as arguments.\n\
8141 This is used to cancel the effect of the \"disable\" command.\n\
8142 May be abbreviated to simply \"enable\".\n"),
8143 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8145 add_cmd ("once", no_class
, enable_once_command
, _("\
8146 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8147 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8150 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8151 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8152 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8155 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8156 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8157 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8160 add_cmd ("once", no_class
, enable_once_command
, _("\
8161 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8162 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8165 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8166 Disable some breakpoints.\n\
8167 Arguments are breakpoint numbers with spaces in between.\n\
8168 To disable all breakpoints, give no argument.\n\
8169 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8170 &disablelist
, "disable ", 1, &cmdlist
);
8171 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8172 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8174 add_com ("sb", class_breakpoint
, disable_command
, _("\
8175 Disable some breakpoints.\n\
8176 Arguments are breakpoint numbers with spaces in between.\n\
8177 To disable all breakpoints, give no argument.\n\
8178 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8180 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8181 Disable some breakpoints.\n\
8182 Arguments are breakpoint numbers with spaces in between.\n\
8183 To disable all breakpoints, give no argument.\n\
8184 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8185 This command may be abbreviated \"disable\"."),
8188 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8189 Delete some breakpoints or auto-display expressions.\n\
8190 Arguments are breakpoint numbers with spaces in between.\n\
8191 To delete all breakpoints, give no argument.\n\
8193 Also a prefix command for deletion of other GDB objects.\n\
8194 The \"unset\" command is also an alias for \"delete\"."),
8195 &deletelist
, "delete ", 1, &cmdlist
);
8196 add_com_alias ("d", "delete", class_breakpoint
, 1);
8197 add_com_alias ("del", "delete", class_breakpoint
, 1);
8199 add_com ("db", class_breakpoint
, delete_command
, _("\
8200 Delete some breakpoints.\n\
8201 Arguments are breakpoint numbers with spaces in between.\n\
8202 To delete all breakpoints, give no argument.\n"));
8204 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8205 Delete some breakpoints or auto-display expressions.\n\
8206 Arguments are breakpoint numbers with spaces in between.\n\
8207 To delete all breakpoints, give no argument.\n\
8208 This command may be abbreviated \"delete\"."),
8211 add_com ("clear", class_breakpoint
, clear_command
, _("\
8212 Clear breakpoint at specified line or function.\n\
8213 Argument may be line number, function name, or \"*\" and an address.\n\
8214 If line number is specified, all breakpoints in that line are cleared.\n\
8215 If function is specified, breakpoints at beginning of function are cleared.\n\
8216 If an address is specified, breakpoints at that address are cleared.\n\
8218 With no argument, clears all breakpoints in the line that the selected frame\n\
8221 See also the \"delete\" command which clears breakpoints by number."));
8223 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8224 Set breakpoint at specified line or function.\n"
8225 BREAK_ARGS_HELP ("break")));
8226 set_cmd_completer (c
, location_completer
);
8228 add_com_alias ("b", "break", class_run
, 1);
8229 add_com_alias ("br", "break", class_run
, 1);
8230 add_com_alias ("bre", "break", class_run
, 1);
8231 add_com_alias ("brea", "break", class_run
, 1);
8235 add_com_alias ("ba", "break", class_breakpoint
, 1);
8236 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8241 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8242 Break in function/address or break at a line in the current file."),
8243 &stoplist
, "stop ", 1, &cmdlist
);
8244 add_cmd ("in", class_breakpoint
, stopin_command
,
8245 _("Break in function or address."), &stoplist
);
8246 add_cmd ("at", class_breakpoint
, stopat_command
,
8247 _("Break at a line in the current file."), &stoplist
);
8248 add_com ("status", class_info
, breakpoints_info
, _("\
8249 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8250 The \"Type\" column indicates one of:\n\
8251 \tbreakpoint - normal breakpoint\n\
8252 \twatchpoint - watchpoint\n\
8253 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8254 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8255 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8256 address and file/line number respectively.\n\
8258 Convenience variable \"$_\" and default examine address for \"x\"\n\
8259 are set to the address of the last breakpoint listed unless the command\n\
8260 is prefixed with \"server \".\n\n\
8261 Convenience variable \"$bpnum\" contains the number of the last\n\
8265 add_info ("breakpoints", breakpoints_info
, _("\
8266 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8267 The \"Type\" column indicates one of:\n\
8268 \tbreakpoint - normal breakpoint\n\
8269 \twatchpoint - watchpoint\n\
8270 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8271 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8272 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8273 address and file/line number respectively.\n\
8275 Convenience variable \"$_\" and default examine address for \"x\"\n\
8276 are set to the address of the last breakpoint listed unless the command\n\
8277 is prefixed with \"server \".\n\n\
8278 Convenience variable \"$bpnum\" contains the number of the last\n\
8282 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8283 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8284 The \"Type\" column indicates one of:\n\
8285 \tbreakpoint - normal breakpoint\n\
8286 \twatchpoint - watchpoint\n\
8287 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8288 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8289 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8290 address and file/line number respectively.\n\
8292 Convenience variable \"$_\" and default examine address for \"x\"\n\
8293 are set to the address of the last breakpoint listed unless the command\n\
8294 is prefixed with \"server \".\n\n\
8295 Convenience variable \"$bpnum\" contains the number of the last\n\
8298 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8299 Status of all breakpoints, or breakpoint number NUMBER.\n\
8300 The \"Type\" column indicates one of:\n\
8301 \tbreakpoint - normal breakpoint\n\
8302 \twatchpoint - watchpoint\n\
8303 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8304 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8305 \tuntil - internal breakpoint used by the \"until\" command\n\
8306 \tfinish - internal breakpoint used by the \"finish\" command\n\
8307 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8308 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8309 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8310 address and file/line number respectively.\n\
8312 Convenience variable \"$_\" and default examine address for \"x\"\n\
8313 are set to the address of the last breakpoint listed unless the command\n\
8314 is prefixed with \"server \".\n\n\
8315 Convenience variable \"$bpnum\" contains the number of the last\n\
8317 &maintenanceinfolist
);
8319 add_com ("catch", class_breakpoint
, catch_command
, _("\
8320 Set catchpoints to catch events.\n\
8321 Raised signals may be caught:\n\
8322 \tcatch signal - all signals\n\
8323 \tcatch signal <signame> - a particular signal\n\
8324 Raised exceptions may be caught:\n\
8325 \tcatch throw - all exceptions, when thrown\n\
8326 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8327 \tcatch catch - all exceptions, when caught\n\
8328 \tcatch catch <exceptname> - a particular exception, when caught\n\
8329 Thread or process events may be caught:\n\
8330 \tcatch thread_start - any threads, just after creation\n\
8331 \tcatch thread_exit - any threads, just before expiration\n\
8332 \tcatch thread_join - any threads, just after joins\n\
8333 Process events may be caught:\n\
8334 \tcatch start - any processes, just after creation\n\
8335 \tcatch exit - any processes, just before expiration\n\
8336 \tcatch fork - calls to fork()\n\
8337 \tcatch vfork - calls to vfork()\n\
8338 \tcatch exec - calls to exec()\n\
8339 Dynamically-linked library events may be caught:\n\
8340 \tcatch load - loads of any library\n\
8341 \tcatch load <libname> - loads of a particular library\n\
8342 \tcatch unload - unloads of any library\n\
8343 \tcatch unload <libname> - unloads of a particular library\n\
8344 The act of your program's execution stopping may also be caught:\n\
8346 C++ exceptions may be caught:\n\
8347 \tcatch throw - all exceptions, when thrown\n\
8348 \tcatch catch - all exceptions, when caught\n\
8349 Ada exceptions may be caught:\n\
8350 \tcatch exception - all exceptions, when raised\n\
8351 \tcatch exception <name> - a particular exception, when raised\n\
8352 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8353 \tcatch assert - all failed assertions, when raised\n\
8355 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8356 after a fork or vfork is caught.\n\n\
8357 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8359 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8360 Set temporary catchpoints to catch events.\n\
8361 Args like \"catch\" command.\n\
8362 Like \"catch\" except the catchpoint is only temporary,\n\
8363 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8364 by using \"enable delete\" on the catchpoint number."));
8366 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8367 Set a watchpoint for an expression.\n\
8368 A watchpoint stops execution of your program whenever the value of\n\
8369 an expression changes."));
8370 set_cmd_completer (c
, location_completer
);
8372 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8373 Set a read watchpoint for an expression.\n\
8374 A watchpoint stops execution of your program whenever the value of\n\
8375 an expression is read."));
8376 set_cmd_completer (c
, location_completer
);
8378 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8379 Set a watchpoint for an expression.\n\
8380 A watchpoint stops execution of your program whenever the value of\n\
8381 an expression is either read or written."));
8382 set_cmd_completer (c
, location_completer
);
8384 add_info ("watchpoints", breakpoints_info
,
8385 _("Synonym for ``info breakpoints''."));
8388 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8389 respond to changes - contrary to the description. */
8390 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8391 &can_use_hw_watchpoints
, _("\
8392 Set debugger's willingness to use watchpoint hardware."), _("\
8393 Show debugger's willingness to use watchpoint hardware."), _("\
8394 If zero, gdb will not use hardware for new watchpoints, even if\n\
8395 such is available. (However, any hardware watchpoints that were\n\
8396 created before setting this to nonzero, will continue to use watchpoint\n\
8399 show_can_use_hw_watchpoints
,
8400 &setlist
, &showlist
);
8402 can_use_hw_watchpoints
= 1;
8404 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8405 Breakpoint specific settings\n\
8406 Configure various breakpoint-specific variables such as\n\
8407 pending breakpoint behavior"),
8408 &breakpoint_set_cmdlist
, "set breakpoint ",
8409 0/*allow-unknown*/, &setlist
);
8410 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8411 Breakpoint specific settings\n\
8412 Configure various breakpoint-specific variables such as\n\
8413 pending breakpoint behavior"),
8414 &breakpoint_show_cmdlist
, "show breakpoint ",
8415 0/*allow-unknown*/, &showlist
);
8417 add_setshow_auto_boolean_cmd ("pending", no_class
,
8418 &pending_break_support
, _("\
8419 Set debugger's behavior regarding pending breakpoints."), _("\
8420 Show debugger's behavior regarding pending breakpoints."), _("\
8421 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8422 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8423 an error. If auto, an unrecognized breakpoint location results in a\n\
8424 user-query to see if a pending breakpoint should be created."),
8426 show_pending_break_support
,
8427 &breakpoint_set_cmdlist
,
8428 &breakpoint_show_cmdlist
);
8430 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8432 add_setshow_boolean_cmd ("auto-hw", no_class
,
8433 &automatic_hardware_breakpoints
, _("\
8434 Set automatic usage of hardware breakpoints."), _("\
8435 Show automatic usage of hardware breakpoints."), _("\
8436 If set, the debugger will automatically use hardware breakpoints for\n\
8437 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8438 a warning will be emitted for such breakpoints."),
8440 show_automatic_hardware_breakpoints
,
8441 &breakpoint_set_cmdlist
,
8442 &breakpoint_show_cmdlist
);
8444 automatic_hardware_breakpoints
= 1;