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 "mi/mi-common.h"
62 /* Arguments to pass as context to some catch command handlers. */
63 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
64 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
66 /* Prototypes for local functions. */
68 static void enable_delete_command (char *, int);
70 static void enable_delete_breakpoint (struct breakpoint
*);
72 static void enable_once_command (char *, int);
74 static void enable_once_breakpoint (struct breakpoint
*);
76 static void disable_command (char *, int);
78 static void enable_command (char *, int);
80 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
82 static void ignore_command (char *, int);
84 static int breakpoint_re_set_one (void *);
86 static void clear_command (char *, int);
88 static void catch_command (char *, int);
90 static void watch_command (char *, int);
92 static int can_use_hardware_watchpoint (struct value
*);
94 static void break_command_1 (char *, int, int);
96 static void mention (struct breakpoint
*);
98 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
100 static void check_duplicates (struct breakpoint
*);
102 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
104 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
107 static void describe_other_breakpoints (CORE_ADDR
, asection
*, int);
109 static void breakpoints_info (char *, int);
111 static void breakpoint_1 (int, int);
113 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
115 static int breakpoint_cond_eval (void *);
117 static void cleanup_executing_breakpoints (void *);
119 static void commands_command (char *, int);
121 static void condition_command (char *, int);
123 static int get_number_trailer (char **, int);
125 void set_breakpoint_count (int);
134 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
136 static enum print_stop_action
print_it_typical (bpstat
);
138 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
140 static int watchpoint_check (void *);
142 static void maintenance_info_breakpoints (char *, int);
144 static void create_overlay_event_breakpoint (char *);
146 static int hw_breakpoint_used_count (void);
148 static int hw_watchpoint_used_count (enum bptype
, int *);
150 static void hbreak_command (char *, int);
152 static void thbreak_command (char *, int);
154 static void watch_command_1 (char *, int, int);
156 static void rwatch_command (char *, int);
158 static void awatch_command (char *, int);
160 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
162 static void create_fork_vfork_event_catchpoint (int tempflag
,
164 enum bptype bp_kind
);
166 static void stop_command (char *arg
, int from_tty
);
168 static void stopin_command (char *arg
, int from_tty
);
170 static void stopat_command (char *arg
, int from_tty
);
172 static char *ep_parse_optional_if_clause (char **arg
);
174 static char *ep_parse_optional_filename (char **arg
);
176 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
177 char *arg
, int tempflag
, int from_tty
);
179 static void tcatch_command (char *arg
, int from_tty
);
181 static void ep_skip_leading_whitespace (char **s
);
183 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
185 static void free_bp_location (struct bp_location
*loc
);
187 static struct bp_location
*
188 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
);
190 static void update_global_location_list (int);
192 static void update_global_location_list_nothrow (int);
194 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
196 static void insert_breakpoint_locations (void);
199 bpdisp_text (enum bpdisp disp
)
201 /* NOTE: the following values are a part of MI protocol and represent
202 values of 'disp' field returned when inferior stops at a breakpoint. */
203 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
204 return bpdisps
[(int) disp
];
207 /* Prototypes for exported functions. */
208 /* If FALSE, gdb will not use hardware support for watchpoints, even
209 if such is available. */
210 static int can_use_hw_watchpoints
;
213 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
214 struct cmd_list_element
*c
,
217 fprintf_filtered (file
, _("\
218 Debugger's willingness to use watchpoint hardware is %s.\n"),
222 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
223 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
224 for unrecognized breakpoint locations.
225 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
226 static enum auto_boolean pending_break_support
;
228 show_pending_break_support (struct ui_file
*file
, int from_tty
,
229 struct cmd_list_element
*c
,
232 fprintf_filtered (file
, _("\
233 Debugger's behavior regarding pending breakpoints is %s.\n"),
237 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
238 set with "break" but falling in read-only memory.
239 If 0, gdb will warn about such breakpoints, but won't automatically
240 use hardware breakpoints. */
241 static int automatic_hardware_breakpoints
;
243 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
244 struct cmd_list_element
*c
,
247 fprintf_filtered (file
, _("\
248 Automatic usage of hardware breakpoints is %s.\n"),
252 /* If on, gdb will keep breakpoints inserted even as inferior is
253 stopped, and immediately insert any new breakpoints. If off, gdb
254 will insert breakpoints into inferior only when resuming it, and
255 will remove breakpoints upon stop. If auto, GDB will behave as ON
256 if in non-stop mode, and as OFF if all-stop mode.*/
258 static const char always_inserted_auto
[] = "auto";
259 static const char always_inserted_on
[] = "on";
260 static const char always_inserted_off
[] = "off";
261 static const char *always_inserted_enums
[] = {
262 always_inserted_auto
,
267 static const char *always_inserted_mode
= always_inserted_auto
;
269 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
270 struct cmd_list_element
*c
, const char *value
)
272 if (always_inserted_mode
== always_inserted_auto
)
273 fprintf_filtered (file
, _("\
274 Always inserted breakpoint mode is %s (currently %s).\n"),
276 breakpoints_always_inserted_mode () ? "on" : "off");
278 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
282 breakpoints_always_inserted_mode (void)
284 return (always_inserted_mode
== always_inserted_on
285 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
288 void _initialize_breakpoint (void);
290 extern int addressprint
; /* Print machine addresses? */
292 /* Are we executing breakpoint commands? */
293 static int executing_breakpoint_commands
;
295 /* Are overlay event breakpoints enabled? */
296 static int overlay_events_enabled
;
298 /* Walk the following statement or block through all breakpoints.
299 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
302 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
304 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
305 for (B = breakpoint_chain; \
306 B ? (TMP=B->next, 1): 0; \
309 /* Similar iterators for the low-level breakpoints. */
311 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
313 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
314 for (B = bp_location_chain; \
315 B ? (TMP=B->global_next, 1): 0; \
318 /* True if breakpoint hit counts should be displayed in breakpoint info. */
320 int show_breakpoint_hit_counts
= 1;
322 /* Chains of all breakpoints defined. */
324 struct breakpoint
*breakpoint_chain
;
326 struct bp_location
*bp_location_chain
;
328 /* The locations that no longer correspond to any breakpoint,
329 unlinked from bp_location_chain, but for which a hit
330 may still be reported by a target. */
331 VEC(bp_location_p
) *moribund_locations
= NULL
;
333 /* Number of last breakpoint made. */
335 int breakpoint_count
;
337 /* This function returns a pointer to the string representation of the
338 pathname of the dynamically-linked library that has just been
341 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
342 or undefined results are guaranteed.
344 This string's contents are only valid immediately after the
345 inferior has stopped in the dynamic linker hook, and becomes
346 invalid as soon as the inferior is continued. Clients should make
347 a copy of this string if they wish to continue the inferior and
348 then access the string. */
350 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
351 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
354 /* This function returns a pointer to the string representation of the
355 pathname of the dynamically-linked library that has just been
358 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
359 TRUE, or undefined results are guaranteed.
361 This string's contents are only valid immediately after the
362 inferior has stopped in the dynamic linker hook, and becomes
363 invalid as soon as the inferior is continued. Clients should make
364 a copy of this string if they wish to continue the inferior and
365 then access the string. */
367 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
368 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
371 /* This function is called by the "catch load" command. It allows the
372 debugger to be notified by the dynamic linker when a specified
373 library file (or any library file, if filename is NULL) is loaded. */
375 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
376 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
377 error (_("catch of library loads not yet implemented on this platform"))
380 /* This function is called by the "catch unload" command. It allows
381 the debugger to be notified by the dynamic linker when a specified
382 library file (or any library file, if filename is NULL) is
385 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
386 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
387 error (_("catch of library unloads not yet implemented on this platform"))
390 /* Return whether a breakpoint is an active enabled breakpoint. */
392 breakpoint_enabled (struct breakpoint
*b
)
394 return (b
->enable_state
== bp_enabled
);
397 /* Set breakpoint count to NUM. */
400 set_breakpoint_count (int num
)
402 breakpoint_count
= num
;
403 set_internalvar (lookup_internalvar ("bpnum"),
404 value_from_longest (builtin_type_int
, (LONGEST
) num
));
407 /* Used in run_command to zero the hit count when a new run starts. */
410 clear_breakpoint_hit_counts (void)
412 struct breakpoint
*b
;
418 /* Default address, symtab and line to put a breakpoint at
419 for "break" command with no arg.
420 if default_breakpoint_valid is zero, the other three are
421 not valid, and "break" with no arg is an error.
423 This set by print_stack_frame, which calls set_default_breakpoint. */
425 int default_breakpoint_valid
;
426 CORE_ADDR default_breakpoint_address
;
427 struct symtab
*default_breakpoint_symtab
;
428 int default_breakpoint_line
;
430 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
431 Advance *PP after the string and any trailing whitespace.
433 Currently the string can either be a number or "$" followed by the name
434 of a convenience variable. Making it an expression wouldn't work well
435 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
437 If the string is a NULL pointer, that denotes the last breakpoint.
439 TRAILER is a character which can be found after the number; most
440 commonly this is `-'. If you don't want a trailer, use \0. */
442 get_number_trailer (char **pp
, int trailer
)
444 int retval
= 0; /* default */
448 /* Empty line means refer to the last breakpoint. */
449 return breakpoint_count
;
452 /* Make a copy of the name, so we can null-terminate it
453 to pass to lookup_internalvar(). */
458 while (isalnum (*p
) || *p
== '_')
460 varname
= (char *) alloca (p
- start
+ 1);
461 strncpy (varname
, start
, p
- start
);
462 varname
[p
- start
] = '\0';
463 val
= value_of_internalvar (lookup_internalvar (varname
));
464 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
465 retval
= (int) value_as_long (val
);
468 printf_filtered (_("Convenience variable must have integer value.\n"));
476 while (*p
>= '0' && *p
<= '9')
479 /* There is no number here. (e.g. "cond a == b"). */
481 /* Skip non-numeric token */
482 while (*p
&& !isspace((int) *p
))
484 /* Return zero, which caller must interpret as error. */
490 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
492 /* Trailing junk: return 0 and let caller print error msg. */
493 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
504 /* Like get_number_trailer, but don't allow a trailer. */
506 get_number (char **pp
)
508 return get_number_trailer (pp
, '\0');
511 /* Parse a number or a range.
512 * A number will be of the form handled by get_number.
513 * A range will be of the form <number1> - <number2>, and
514 * will represent all the integers between number1 and number2,
517 * While processing a range, this fuction is called iteratively;
518 * At each call it will return the next value in the range.
520 * At the beginning of parsing a range, the char pointer PP will
521 * be advanced past <number1> and left pointing at the '-' token.
522 * Subsequent calls will not advance the pointer until the range
523 * is completed. The call that completes the range will advance
524 * pointer PP past <number2>.
528 get_number_or_range (char **pp
)
530 static int last_retval
, end_value
;
531 static char *end_ptr
;
532 static int in_range
= 0;
536 /* Default case: pp is pointing either to a solo number,
537 or to the first number of a range. */
538 last_retval
= get_number_trailer (pp
, '-');
543 /* This is the start of a range (<number1> - <number2>).
544 Skip the '-', parse and remember the second number,
545 and also remember the end of the final token. */
549 while (isspace ((int) *end_ptr
))
550 end_ptr
++; /* skip white space */
551 end_value
= get_number (temp
);
552 if (end_value
< last_retval
)
554 error (_("inverted range"));
556 else if (end_value
== last_retval
)
558 /* degenerate range (number1 == number2). Advance the
559 token pointer so that the range will be treated as a
568 error (_("negative value"));
571 /* pp points to the '-' that betokens a range. All
572 number-parsing has already been done. Return the next
573 integer value (one greater than the saved previous value).
574 Do not advance the token pointer 'pp' until the end of range
577 if (++last_retval
== end_value
)
579 /* End of range reached; advance token pointer. */
589 /* condition N EXP -- set break condition of breakpoint N to EXP. */
592 condition_command (char *arg
, int from_tty
)
594 struct breakpoint
*b
;
599 error_no_arg (_("breakpoint number"));
602 bnum
= get_number (&p
);
604 error (_("Bad breakpoint argument: '%s'"), arg
);
607 if (b
->number
== bnum
)
609 struct bp_location
*loc
= b
->loc
;
610 for (; loc
; loc
= loc
->next
)
618 if (b
->cond_string
!= NULL
)
619 xfree (b
->cond_string
);
623 b
->cond_string
= NULL
;
625 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
630 /* I don't know if it matters whether this is the string the user
631 typed in or the decompiled expression. */
632 b
->cond_string
= savestring (arg
, strlen (arg
));
633 b
->condition_not_parsed
= 0;
634 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
638 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
640 error (_("Junk at end of expression"));
643 breakpoints_changed ();
644 observer_notify_breakpoint_modified (b
->number
);
648 error (_("No breakpoint number %d."), bnum
);
652 commands_command (char *arg
, int from_tty
)
654 struct breakpoint
*b
;
657 struct command_line
*l
;
659 /* If we allowed this, we would have problems with when to
660 free the storage, if we change the commands currently
663 if (executing_breakpoint_commands
)
664 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
667 bnum
= get_number (&p
);
670 error (_("Unexpected extra arguments following breakpoint number."));
673 if (b
->number
== bnum
)
675 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
677 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
678 l
= read_command_lines (tmpbuf
, from_tty
, 1);
679 do_cleanups (cleanups
);
680 free_command_lines (&b
->commands
);
682 breakpoints_changed ();
683 observer_notify_breakpoint_modified (b
->number
);
686 error (_("No breakpoint number %d."), bnum
);
689 /* Like commands_command, but instead of reading the commands from
690 input stream, takes them from an already parsed command structure.
692 This is used by cli-script.c to DTRT with breakpoint commands
693 that are part of if and while bodies. */
694 enum command_control_type
695 commands_from_control_command (char *arg
, struct command_line
*cmd
)
697 struct breakpoint
*b
;
701 /* If we allowed this, we would have problems with when to
702 free the storage, if we change the commands currently
705 if (executing_breakpoint_commands
)
706 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
708 /* An empty string for the breakpoint number means the last
709 breakpoint, but get_number expects a NULL pointer. */
714 bnum
= get_number (&p
);
717 error (_("Unexpected extra arguments following breakpoint number."));
720 if (b
->number
== bnum
)
722 free_command_lines (&b
->commands
);
723 if (cmd
->body_count
!= 1)
724 error (_("Invalid \"commands\" block structure."));
725 /* We need to copy the commands because if/while will free the
726 list after it finishes execution. */
727 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
728 breakpoints_changed ();
729 observer_notify_breakpoint_modified (b
->number
);
730 return simple_control
;
732 error (_("No breakpoint number %d."), bnum
);
735 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
736 by replacing any memory breakpoints with their shadowed contents. */
739 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
741 struct bp_location
*b
;
742 CORE_ADDR bp_addr
= 0;
748 if (b
->owner
->type
== bp_none
)
749 warning (_("reading through apparently deleted breakpoint #%d?"),
752 if (b
->loc_type
!= bp_loc_software_breakpoint
)
756 /* Addresses and length of the part of the breakpoint that
758 bp_addr
= b
->target_info
.placed_address
;
759 bp_size
= b
->target_info
.shadow_len
;
761 /* bp isn't valid, or doesn't shadow memory. */
764 if (bp_addr
+ bp_size
<= memaddr
)
765 /* The breakpoint is entirely before the chunk of memory we
769 if (bp_addr
>= memaddr
+ len
)
770 /* The breakpoint is entirely after the chunk of memory we are
774 /* Offset within shadow_contents. */
775 if (bp_addr
< memaddr
)
777 /* Only copy the second part of the breakpoint. */
778 bp_size
-= memaddr
- bp_addr
;
779 bptoffset
= memaddr
- bp_addr
;
783 if (bp_addr
+ bp_size
> memaddr
+ len
)
785 /* Only copy the first part of the breakpoint. */
786 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
789 memcpy (buf
+ bp_addr
- memaddr
,
790 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
795 /* A wrapper function for inserting catchpoints. */
797 insert_catchpoint (struct ui_out
*uo
, void *args
)
799 struct breakpoint
*b
= (struct breakpoint
*) args
;
805 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
808 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
811 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
814 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
820 is_hardware_watchpoint (struct breakpoint
*bpt
)
822 return (bpt
->type
== bp_hardware_watchpoint
823 || bpt
->type
== bp_read_watchpoint
824 || bpt
->type
== bp_access_watchpoint
);
827 /* Find the current value of a watchpoint on EXP. Return the value in
828 *VALP and *RESULTP and the chain of intermediate and final values
829 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
832 If an error occurs while evaluating the expression, *RESULTP will
833 be set to NULL. *RESULTP may be a lazy value, if the result could
834 not be read from memory. It is used to determine whether a value
835 is user-specified (we should watch the whole value) or intermediate
836 (we should watch only the bit used to locate the final value).
838 If the final value, or any intermediate value, could not be read
839 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
840 set to any referenced values. *VALP will never be a lazy value.
841 This is the value which we store in struct breakpoint.
843 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
844 value chain. The caller must free the values individually. If
845 VAL_CHAIN is NULL, all generated values will be left on the value
849 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
850 struct value
**resultp
, struct value
**val_chain
)
852 struct value
*mark
, *new_mark
, *result
;
860 /* Evaluate the expression. */
861 mark
= value_mark ();
863 gdb_evaluate_expression (exp
, &result
);
864 new_mark
= value_mark ();
865 if (mark
== new_mark
)
870 /* Make sure it's not lazy, so that after the target stops again we
871 have a non-lazy previous value to compare with. */
873 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
878 /* Return the chain of intermediate values. We use this to
879 decide which addresses to watch. */
880 *val_chain
= new_mark
;
881 value_release_to_mark (mark
);
885 /* Assuming that B is a hardware watchpoint:
886 - Reparse watchpoint expression, is REPARSE is non-zero
887 - Evaluate expression and store the result in B->val
888 - Update the list of values that must be watched in B->loc.
890 If the watchpoint is disabled, do nothing. If this is
891 local watchpoint that is out of scope, delete it. */
893 update_watchpoint (struct breakpoint
*b
, int reparse
)
895 int within_current_scope
;
896 struct frame_id saved_frame_id
;
897 struct bp_location
*loc
;
900 /* We don't free locations. They are stored in
901 bp_location_chain and update_global_locations will
902 eventually delete them and remove breakpoints if
906 if (b
->disposition
== disp_del_at_next_stop
)
909 /* Save the current frame's ID so we can restore it after
910 evaluating the watchpoint expression on its own frame. */
911 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
912 took a frame parameter, so that we didn't have to change the
914 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
916 /* Determine if the watchpoint is within scope. */
917 if (b
->exp_valid_block
== NULL
)
918 within_current_scope
= 1;
921 struct frame_info
*fi
;
922 fi
= frame_find_by_id (b
->watchpoint_frame
);
923 within_current_scope
= (fi
!= NULL
);
924 if (within_current_scope
)
928 if (within_current_scope
&& reparse
)
937 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
938 /* If the meaning of expression itself changed, the old value is
939 no longer relevant. We don't want to report a watchpoint hit
940 to the user when the old value and the new value may actually
941 be completely different objects. */
947 /* If we failed to parse the expression, for example because
948 it refers to a global variable in a not-yet-loaded shared library,
949 don't try to insert watchpoint. We don't automatically delete
950 such watchpoint, though, since failure to parse expression
951 is different from out-of-scope watchpoint. */
952 if (within_current_scope
&& b
->exp
)
954 struct value
*val_chain
, *v
, *result
, *next
;
956 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
958 /* Avoid setting b->val if it's already set. The meaning of
959 b->val is 'the last value' user saw, and we should update
960 it only if we reported that last value to user. As it
961 happens, the code that reports it updates b->val directly. */
968 /* Look at each value on the value chain. */
969 for (v
= val_chain
; v
; v
= next
)
971 /* If it's a memory location, and GDB actually needed
972 its contents to evaluate the expression, then we
973 must watch it. If the first value returned is
974 still lazy, that means an error occurred reading it;
975 watch it anyway in case it becomes readable. */
976 if (VALUE_LVAL (v
) == lval_memory
977 && (v
== val_chain
|| ! value_lazy (v
)))
979 struct type
*vtype
= check_typedef (value_type (v
));
981 /* We only watch structs and arrays if user asked
982 for it explicitly, never if they just happen to
983 appear in the middle of some value chain. */
985 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
986 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
990 struct bp_location
*loc
, **tmp
;
992 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
993 len
= TYPE_LENGTH (value_type (v
));
995 if (b
->type
== bp_read_watchpoint
)
997 else if (b
->type
== bp_access_watchpoint
)
1000 loc
= allocate_bp_location (b
, bp_hardware_watchpoint
);
1001 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1004 loc
->address
= addr
;
1006 loc
->watchpoint_type
= type
;
1010 next
= value_next (v
);
1015 /* We just regenerated the list of breakpoint locations.
1016 The new location does not have its condition field set to anything
1017 and therefore, we must always reparse the cond_string, independently
1018 of the value of the reparse flag. */
1019 if (b
->cond_string
!= NULL
)
1021 char *s
= b
->cond_string
;
1022 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1025 else if (!within_current_scope
)
1027 printf_filtered (_("\
1028 Hardware watchpoint %d deleted because the program has left the block \n\
1029 in which its expression is valid.\n"),
1031 if (b
->related_breakpoint
)
1032 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1033 b
->disposition
= disp_del_at_next_stop
;
1036 /* Restore the selected frame. */
1037 select_frame (frame_find_by_id (saved_frame_id
));
1041 /* Returns 1 iff breakpoint location should be
1042 inserted in the inferior. */
1044 should_be_inserted (struct bp_location
*bpt
)
1046 if (!breakpoint_enabled (bpt
->owner
))
1049 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1052 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1058 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1059 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1060 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1062 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1063 method for each breakpoint or catchpoint type. */
1065 insert_bp_location (struct bp_location
*bpt
,
1066 struct ui_file
*tmp_error_stream
,
1067 int *disabled_breaks
, int *process_warning
,
1068 int *hw_breakpoint_error
)
1072 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1075 /* Initialize the target-specific information. */
1076 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1077 bpt
->target_info
.placed_address
= bpt
->address
;
1079 if (bpt
->loc_type
== bp_loc_software_breakpoint
1080 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1082 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1084 /* If the explicitly specified breakpoint type
1085 is not hardware breakpoint, check the memory map to see
1086 if the breakpoint address is in read only memory or not.
1087 Two important cases are:
1088 - location type is not hardware breakpoint, memory
1089 is readonly. We change the type of the location to
1090 hardware breakpoint.
1091 - location type is hardware breakpoint, memory is read-write.
1092 This means we've previously made the location hardware one, but
1093 then the memory map changed, so we undo.
1095 When breakpoints are removed, remove_breakpoints will
1096 use location types we've just set here, the only possible
1097 problem is that memory map has changed during running program,
1098 but it's not going to work anyway with current gdb. */
1099 struct mem_region
*mr
1100 = lookup_mem_region (bpt
->target_info
.placed_address
);
1104 if (automatic_hardware_breakpoints
)
1107 enum bp_loc_type new_type
;
1109 if (mr
->attrib
.mode
!= MEM_RW
)
1110 new_type
= bp_loc_hardware_breakpoint
;
1112 new_type
= bp_loc_software_breakpoint
;
1114 if (new_type
!= bpt
->loc_type
)
1116 static int said
= 0;
1117 bpt
->loc_type
= new_type
;
1120 fprintf_filtered (gdb_stdout
, _("\
1121 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1126 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1127 && mr
->attrib
.mode
!= MEM_RW
)
1128 warning (_("cannot set software breakpoint at readonly address %s"),
1129 paddr (bpt
->address
));
1133 /* First check to see if we have to handle an overlay. */
1134 if (overlay_debugging
== ovly_off
1135 || bpt
->section
== NULL
1136 || !(section_is_overlay (bpt
->section
)))
1138 /* No overlay handling: just set the breakpoint. */
1140 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1141 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1143 val
= target_insert_breakpoint (&bpt
->target_info
);
1147 /* This breakpoint is in an overlay section.
1148 Shall we set a breakpoint at the LMA? */
1149 if (!overlay_events_enabled
)
1151 /* Yes -- overlay event support is not active,
1152 so we must try to set a breakpoint at the LMA.
1153 This will not work for a hardware breakpoint. */
1154 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1155 warning (_("hardware breakpoint %d not supported in overlay!"),
1156 bpt
->owner
->number
);
1159 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1161 /* Set a software (trap) breakpoint at the LMA. */
1162 bpt
->overlay_target_info
= bpt
->target_info
;
1163 bpt
->overlay_target_info
.placed_address
= addr
;
1164 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1166 fprintf_unfiltered (tmp_error_stream
,
1167 "Overlay breakpoint %d failed: in ROM?",
1168 bpt
->owner
->number
);
1171 /* Shall we set a breakpoint at the VMA? */
1172 if (section_is_mapped (bpt
->section
))
1174 /* Yes. This overlay section is mapped into memory. */
1175 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1176 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1178 val
= target_insert_breakpoint (&bpt
->target_info
);
1182 /* No. This breakpoint will not be inserted.
1183 No error, but do not mark the bp as 'inserted'. */
1190 /* Can't set the breakpoint. */
1191 if (solib_address (bpt
->address
))
1193 /* See also: disable_breakpoints_in_shlibs. */
1195 bpt
->shlib_disabled
= 1;
1196 if (!*disabled_breaks
)
1198 fprintf_unfiltered (tmp_error_stream
,
1199 "Cannot insert breakpoint %d.\n",
1200 bpt
->owner
->number
);
1201 fprintf_unfiltered (tmp_error_stream
,
1202 "Temporarily disabling shared library breakpoints:\n");
1204 *disabled_breaks
= 1;
1205 fprintf_unfiltered (tmp_error_stream
,
1206 "breakpoint #%d\n", bpt
->owner
->number
);
1210 #ifdef ONE_PROCESS_WRITETEXT
1211 *process_warning
= 1;
1213 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1215 *hw_breakpoint_error
= 1;
1216 fprintf_unfiltered (tmp_error_stream
,
1217 "Cannot insert hardware breakpoint %d.\n",
1218 bpt
->owner
->number
);
1222 fprintf_unfiltered (tmp_error_stream
,
1223 "Cannot insert breakpoint %d.\n",
1224 bpt
->owner
->number
);
1225 fprintf_filtered (tmp_error_stream
,
1226 "Error accessing memory address ");
1227 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1228 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1229 safe_strerror (val
));
1240 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1241 /* NOTE drow/2003-09-08: This state only exists for removing
1242 watchpoints. It's not clear that it's necessary... */
1243 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1245 val
= target_insert_watchpoint (bpt
->address
,
1247 bpt
->watchpoint_type
);
1248 bpt
->inserted
= (val
!= -1);
1251 else if (bpt
->owner
->type
== bp_catch_fork
1252 || bpt
->owner
->type
== bp_catch_vfork
1253 || bpt
->owner
->type
== bp_catch_exec
)
1255 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1256 bpt
->owner
, RETURN_MASK_ERROR
);
1257 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1258 bpt
->owner
->number
);
1260 bpt
->owner
->enable_state
= bp_disabled
;
1264 /* We've already printed an error message if there was a problem
1265 inserting this catchpoint, and we've disabled the catchpoint,
1266 so just return success. */
1273 /* Make sure all breakpoints are inserted in inferior.
1274 Throws exception on any error.
1275 A breakpoint that is already inserted won't be inserted
1276 again, so calling this function twice is safe. */
1278 insert_breakpoints (void)
1280 struct breakpoint
*bpt
;
1282 ALL_BREAKPOINTS (bpt
)
1283 if (is_hardware_watchpoint (bpt
))
1284 update_watchpoint (bpt
, 0 /* don't reparse. */);
1286 update_global_location_list (1);
1288 if (!breakpoints_always_inserted_mode () && target_has_execution
)
1289 /* update_global_location_list does not insert breakpoints
1290 when always_inserted_mode is not enabled. Explicitly
1292 insert_breakpoint_locations ();
1295 /* insert_breakpoints is used when starting or continuing the program.
1296 remove_breakpoints is used when the program stops.
1297 Both return zero if successful,
1298 or an `errno' value if could not write the inferior. */
1301 insert_breakpoint_locations (void)
1303 struct breakpoint
*bpt
;
1304 struct bp_location
*b
, *temp
;
1307 int disabled_breaks
= 0;
1308 int hw_breakpoint_error
= 0;
1309 int process_warning
= 0;
1311 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1312 make_cleanup_ui_file_delete (tmp_error_stream
);
1314 /* Explicitly mark the warning -- this will only be printed if
1315 there was an error. */
1316 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1318 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1320 if (!should_be_inserted (b
) || b
->inserted
)
1323 /* There is no point inserting thread-specific breakpoints if the
1324 thread no longer exists. */
1325 if (b
->owner
->thread
!= -1
1326 && !valid_thread_id (b
->owner
->thread
))
1329 val
= insert_bp_location (b
, tmp_error_stream
,
1330 &disabled_breaks
, &process_warning
,
1331 &hw_breakpoint_error
);
1336 /* If we failed to insert all locations of a watchpoint,
1337 remove them, as half-inserted watchpoint is of limited use. */
1338 ALL_BREAKPOINTS (bpt
)
1340 int some_failed
= 0;
1341 struct bp_location
*loc
;
1343 if (!is_hardware_watchpoint (bpt
))
1346 if (!breakpoint_enabled (bpt
))
1349 if (bpt
->disposition
== disp_del_at_next_stop
)
1352 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1360 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1362 remove_breakpoint (loc
, mark_uninserted
);
1364 hw_breakpoint_error
= 1;
1365 fprintf_unfiltered (tmp_error_stream
,
1366 "Could not insert hardware watchpoint %d.\n",
1374 /* If a hardware breakpoint or watchpoint was inserted, add a
1375 message about possibly exhausted resources. */
1376 if (hw_breakpoint_error
)
1378 fprintf_unfiltered (tmp_error_stream
,
1379 "Could not insert hardware breakpoints:\n\
1380 You may have requested too many hardware breakpoints/watchpoints.\n");
1382 #ifdef ONE_PROCESS_WRITETEXT
1383 if (process_warning
)
1384 fprintf_unfiltered (tmp_error_stream
,
1385 "The same program may be running in another process.");
1387 target_terminal_ours_for_output ();
1388 error_stream (tmp_error_stream
);
1393 remove_breakpoints (void)
1395 struct bp_location
*b
;
1398 ALL_BP_LOCATIONS (b
)
1402 val
= remove_breakpoint (b
, mark_uninserted
);
1411 remove_hw_watchpoints (void)
1413 struct bp_location
*b
;
1416 ALL_BP_LOCATIONS (b
)
1418 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1420 val
= remove_breakpoint (b
, mark_uninserted
);
1429 reattach_breakpoints (int pid
)
1431 struct bp_location
*b
;
1433 struct cleanup
*old_chain
= save_inferior_ptid ();
1434 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1435 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1437 make_cleanup_ui_file_delete (tmp_error_stream
);
1439 inferior_ptid
= pid_to_ptid (pid
);
1440 ALL_BP_LOCATIONS (b
)
1445 val
= insert_bp_location (b
, tmp_error_stream
,
1446 &dummy1
, &dummy2
, &dummy3
);
1449 do_cleanups (old_chain
);
1454 do_cleanups (old_chain
);
1459 update_breakpoints_after_exec (void)
1461 struct breakpoint
*b
;
1462 struct breakpoint
*temp
;
1463 struct bp_location
*bploc
;
1465 /* We're about to delete breakpoints from GDB's lists. If the
1466 INSERTED flag is true, GDB will try to lift the breakpoints by
1467 writing the breakpoints' "shadow contents" back into memory. The
1468 "shadow contents" are NOT valid after an exec, so GDB should not
1469 do that. Instead, the target is responsible from marking
1470 breakpoints out as soon as it detects an exec. We don't do that
1471 here instead, because there may be other attempts to delete
1472 breakpoints after detecting an exec and before reaching here. */
1473 ALL_BP_LOCATIONS (bploc
)
1474 gdb_assert (!bploc
->inserted
);
1476 ALL_BREAKPOINTS_SAFE (b
, temp
)
1478 /* Solib breakpoints must be explicitly reset after an exec(). */
1479 if (b
->type
== bp_shlib_event
)
1481 delete_breakpoint (b
);
1485 /* Thread event breakpoints must be set anew after an exec(),
1486 as must overlay event breakpoints. */
1487 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1489 delete_breakpoint (b
);
1493 /* Step-resume breakpoints are meaningless after an exec(). */
1494 if (b
->type
== bp_step_resume
)
1496 delete_breakpoint (b
);
1500 /* Longjmp and longjmp-resume breakpoints are also meaningless
1502 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1504 delete_breakpoint (b
);
1508 /* Don't delete an exec catchpoint, because else the inferior
1509 won't stop when it ought!
1511 Similarly, we probably ought to keep vfork catchpoints, 'cause
1512 on this target, we may not be able to stop when the vfork is
1513 seen, but only when the subsequent exec is seen. (And because
1514 deleting fork catchpoints here but not vfork catchpoints will
1515 seem mysterious to users, keep those too.) */
1516 if ((b
->type
== bp_catch_exec
) ||
1517 (b
->type
== bp_catch_vfork
) ||
1518 (b
->type
== bp_catch_fork
))
1523 /* bp_finish is a special case. The only way we ought to be able
1524 to see one of these when an exec() has happened, is if the user
1525 caught a vfork, and then said "finish". Ordinarily a finish just
1526 carries them to the call-site of the current callee, by setting
1527 a temporary bp there and resuming. But in this case, the finish
1528 will carry them entirely through the vfork & exec.
1530 We don't want to allow a bp_finish to remain inserted now. But
1531 we can't safely delete it, 'cause finish_command has a handle to
1532 the bp on a bpstat, and will later want to delete it. There's a
1533 chance (and I've seen it happen) that if we delete the bp_finish
1534 here, that its storage will get reused by the time finish_command
1535 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1536 We really must allow finish_command to delete a bp_finish.
1538 In the absense of a general solution for the "how do we know
1539 it's safe to delete something others may have handles to?"
1540 problem, what we'll do here is just uninsert the bp_finish, and
1541 let finish_command delete it.
1543 (We know the bp_finish is "doomed" in the sense that it's
1544 momentary, and will be deleted as soon as finish_command sees
1545 the inferior stopped. So it doesn't matter that the bp's
1546 address is probably bogus in the new a.out, unlike e.g., the
1547 solib breakpoints.) */
1549 if (b
->type
== bp_finish
)
1554 /* Without a symbolic address, we have little hope of the
1555 pre-exec() address meaning the same thing in the post-exec()
1557 if (b
->addr_string
== NULL
)
1559 delete_breakpoint (b
);
1563 /* FIXME what about longjmp breakpoints? Re-create them here? */
1564 create_overlay_event_breakpoint ("_ovly_debug_event");
1568 detach_breakpoints (int pid
)
1570 struct bp_location
*b
;
1572 struct cleanup
*old_chain
= save_inferior_ptid ();
1574 if (pid
== PIDGET (inferior_ptid
))
1575 error (_("Cannot detach breakpoints of inferior_ptid"));
1577 /* Set inferior_ptid; remove_breakpoint uses this global. */
1578 inferior_ptid
= pid_to_ptid (pid
);
1579 ALL_BP_LOCATIONS (b
)
1583 val
= remove_breakpoint (b
, mark_inserted
);
1586 do_cleanups (old_chain
);
1591 do_cleanups (old_chain
);
1596 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1600 if (b
->owner
->enable_state
== bp_permanent
)
1601 /* Permanent breakpoints cannot be inserted or removed. */
1604 /* The type of none suggests that owner is actually deleted.
1605 This should not ever happen. */
1606 gdb_assert (b
->owner
->type
!= bp_none
);
1608 if (b
->loc_type
== bp_loc_software_breakpoint
1609 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1611 /* "Normal" instruction breakpoint: either the standard
1612 trap-instruction bp (bp_breakpoint), or a
1613 bp_hardware_breakpoint. */
1615 /* First check to see if we have to handle an overlay. */
1616 if (overlay_debugging
== ovly_off
1617 || b
->section
== NULL
1618 || !(section_is_overlay (b
->section
)))
1620 /* No overlay handling: just remove the breakpoint. */
1622 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1623 val
= target_remove_hw_breakpoint (&b
->target_info
);
1625 val
= target_remove_breakpoint (&b
->target_info
);
1629 /* This breakpoint is in an overlay section.
1630 Did we set a breakpoint at the LMA? */
1631 if (!overlay_events_enabled
)
1633 /* Yes -- overlay event support is not active, so we
1634 should have set a breakpoint at the LMA. Remove it.
1636 /* Ignore any failures: if the LMA is in ROM, we will
1637 have already warned when we failed to insert it. */
1638 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1639 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1641 target_remove_breakpoint (&b
->overlay_target_info
);
1643 /* Did we set a breakpoint at the VMA?
1644 If so, we will have marked the breakpoint 'inserted'. */
1647 /* Yes -- remove it. Previously we did not bother to
1648 remove the breakpoint if the section had been
1649 unmapped, but let's not rely on that being safe. We
1650 don't know what the overlay manager might do. */
1651 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1652 val
= target_remove_hw_breakpoint (&b
->target_info
);
1654 /* However, we should remove *software* breakpoints only
1655 if the section is still mapped, or else we overwrite
1656 wrong code with the saved shadow contents. */
1657 else if (section_is_mapped (b
->section
))
1658 val
= target_remove_breakpoint (&b
->target_info
);
1664 /* No -- not inserted, so no need to remove. No error. */
1669 /* In some cases, we might not be able to remove a breakpoint
1670 in a shared library that has already been removed, but we
1671 have not yet processed the shlib unload event. */
1672 if (val
&& solib_address (b
->address
))
1677 b
->inserted
= (is
== mark_inserted
);
1679 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1684 b
->inserted
= (is
== mark_inserted
);
1685 val
= target_remove_watchpoint (b
->address
, b
->length
,
1686 b
->watchpoint_type
);
1688 /* Failure to remove any of the hardware watchpoints comes here. */
1689 if ((is
== mark_uninserted
) && (b
->inserted
))
1690 warning (_("Could not remove hardware watchpoint %d."),
1693 else if ((b
->owner
->type
== bp_catch_fork
||
1694 b
->owner
->type
== bp_catch_vfork
||
1695 b
->owner
->type
== bp_catch_exec
)
1696 && breakpoint_enabled (b
->owner
)
1700 switch (b
->owner
->type
)
1703 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1705 case bp_catch_vfork
:
1706 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1709 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1712 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1717 b
->inserted
= (is
== mark_inserted
);
1723 /* Clear the "inserted" flag in all breakpoints. */
1726 mark_breakpoints_out (void)
1728 struct bp_location
*bpt
;
1730 ALL_BP_LOCATIONS (bpt
)
1734 /* Clear the "inserted" flag in all breakpoints and delete any
1735 breakpoints which should go away between runs of the program.
1737 Plus other such housekeeping that has to be done for breakpoints
1740 Note: this function gets called at the end of a run (by
1741 generic_mourn_inferior) and when a run begins (by
1742 init_wait_for_inferior). */
1747 breakpoint_init_inferior (enum inf_context context
)
1749 struct breakpoint
*b
, *temp
;
1750 struct bp_location
*bpt
;
1752 ALL_BP_LOCATIONS (bpt
)
1755 ALL_BREAKPOINTS_SAFE (b
, temp
)
1760 case bp_watchpoint_scope
:
1762 /* If the call dummy breakpoint is at the entry point it will
1763 cause problems when the inferior is rerun, so we better
1766 Also get rid of scope breakpoints. */
1767 delete_breakpoint (b
);
1771 case bp_hardware_watchpoint
:
1772 case bp_read_watchpoint
:
1773 case bp_access_watchpoint
:
1775 /* Likewise for watchpoints on local expressions. */
1776 if (b
->exp_valid_block
!= NULL
)
1777 delete_breakpoint (b
);
1778 else if (context
== inf_starting
)
1780 /* Reset val field to force reread of starting value
1781 in insert_breakpoints. */
1783 value_free (b
->val
);
1794 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1795 exists at PC. It returns ordinary_breakpoint_here if it's an
1796 ordinary breakpoint, or permanent_breakpoint_here if it's a
1797 permanent breakpoint.
1798 - When continuing from a location with an ordinary breakpoint, we
1799 actually single step once before calling insert_breakpoints.
1800 - When continuing from a localion with a permanent breakpoint, we
1801 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1802 the target, to advance the PC past the breakpoint. */
1804 enum breakpoint_here
1805 breakpoint_here_p (CORE_ADDR pc
)
1807 const struct bp_location
*bpt
;
1808 int any_breakpoint_here
= 0;
1810 ALL_BP_LOCATIONS (bpt
)
1812 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1813 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1816 if ((breakpoint_enabled (bpt
->owner
)
1817 || bpt
->owner
->enable_state
== bp_permanent
)
1818 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1820 if (overlay_debugging
1821 && section_is_overlay (bpt
->section
)
1822 && !section_is_mapped (bpt
->section
))
1823 continue; /* unmapped overlay -- can't be a match */
1824 else if (bpt
->owner
->enable_state
== bp_permanent
)
1825 return permanent_breakpoint_here
;
1827 any_breakpoint_here
= 1;
1831 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1835 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1836 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1837 This does not check for single-step breakpoints, which are
1838 inserted and removed using direct target manipulation. */
1841 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1843 const struct bp_location
*bpt
;
1845 ALL_BP_LOCATIONS (bpt
)
1847 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1848 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1852 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1854 if (overlay_debugging
1855 && section_is_overlay (bpt
->section
)
1856 && !section_is_mapped (bpt
->section
))
1857 continue; /* unmapped overlay -- can't be a match */
1865 /* Returns non-zero iff there's either regular breakpoint
1866 or a single step breakpoint inserted at PC. */
1869 breakpoint_inserted_here_p (CORE_ADDR pc
)
1871 if (regular_breakpoint_inserted_here_p (pc
))
1874 if (single_step_breakpoint_inserted_here_p (pc
))
1880 /* This function returns non-zero iff there is a software breakpoint
1884 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1886 const struct bp_location
*bpt
;
1887 int any_breakpoint_here
= 0;
1889 ALL_BP_LOCATIONS (bpt
)
1891 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1895 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1897 if (overlay_debugging
1898 && section_is_overlay (bpt
->section
)
1899 && !section_is_mapped (bpt
->section
))
1900 continue; /* unmapped overlay -- can't be a match */
1906 /* Also check for software single-step breakpoints. */
1907 if (single_step_breakpoint_inserted_here_p (pc
))
1913 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1914 PC is valid for process/thread PTID. */
1917 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1919 const struct bp_location
*bpt
;
1922 thread
= pid_to_thread_id (ptid
);
1924 ALL_BP_LOCATIONS (bpt
)
1926 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1927 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1930 if ((breakpoint_enabled (bpt
->owner
)
1931 || bpt
->owner
->enable_state
== bp_permanent
)
1932 && bpt
->address
== pc
1933 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1935 if (overlay_debugging
1936 && section_is_overlay (bpt
->section
)
1937 && !section_is_mapped (bpt
->section
))
1938 continue; /* unmapped overlay -- can't be a match */
1948 /* bpstat stuff. External routines' interfaces are documented
1952 ep_is_catchpoint (struct breakpoint
*ep
)
1955 (ep
->type
== bp_catch_load
)
1956 || (ep
->type
== bp_catch_unload
)
1957 || (ep
->type
== bp_catch_fork
)
1958 || (ep
->type
== bp_catch_vfork
)
1959 || (ep
->type
== bp_catch_exec
);
1961 /* ??rehrauer: Add more kinds here, as are implemented... */
1965 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1968 (ep
->type
== bp_catch_load
)
1969 || (ep
->type
== bp_catch_unload
);
1973 bpstat_free (bpstat bs
)
1975 if (bs
->old_val
!= NULL
)
1976 value_free (bs
->old_val
);
1977 free_command_lines (&bs
->commands
);
1981 /* Clear a bpstat so that it says we are not at any breakpoint.
1982 Also free any storage that is part of a bpstat. */
1985 bpstat_clear (bpstat
*bsp
)
2002 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2003 is part of the bpstat is copied as well. */
2006 bpstat_copy (bpstat bs
)
2010 bpstat retval
= NULL
;
2015 for (; bs
!= NULL
; bs
= bs
->next
)
2017 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2018 memcpy (tmp
, bs
, sizeof (*tmp
));
2019 if (bs
->commands
!= NULL
)
2020 tmp
->commands
= copy_command_lines (bs
->commands
);
2021 if (bs
->old_val
!= NULL
)
2023 tmp
->old_val
= value_copy (bs
->old_val
);
2024 release_value (tmp
->old_val
);
2028 /* This is the first thing in the chain. */
2038 /* Find the bpstat associated with this breakpoint */
2041 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2046 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2048 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2054 /* Find a step_resume breakpoint associated with this bpstat.
2055 (If there are multiple step_resume bp's on the list, this function
2056 will arbitrarily pick one.)
2058 It is an error to use this function if BPSTAT doesn't contain a
2059 step_resume breakpoint.
2061 See wait_for_inferior's use of this function. */
2063 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2067 gdb_assert (bsp
!= NULL
);
2069 current_thread
= pid_to_thread_id (inferior_ptid
);
2071 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2073 if ((bsp
->breakpoint_at
!= NULL
) &&
2074 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2075 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2076 bsp
->breakpoint_at
->owner
->thread
== -1))
2077 return bsp
->breakpoint_at
->owner
;
2080 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2084 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2085 at. *BSP upon return is a bpstat which points to the remaining
2086 breakpoints stopped at (but which is not guaranteed to be good for
2087 anything but further calls to bpstat_num).
2088 Return 0 if passed a bpstat which does not indicate any breakpoints.
2089 Return -1 if stopped at a breakpoint that has been deleted since
2091 Return 1 otherwise. */
2094 bpstat_num (bpstat
*bsp
, int *num
)
2096 struct breakpoint
*b
;
2099 return 0; /* No more breakpoint values */
2101 /* We assume we'll never have several bpstats that
2102 correspond to a single breakpoint -- otherwise,
2103 this function might return the same number more
2104 than once and this will look ugly. */
2105 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2106 *bsp
= (*bsp
)->next
;
2108 return -1; /* breakpoint that's been deleted since */
2110 *num
= b
->number
; /* We have its number */
2114 /* Modify BS so that the actions will not be performed. */
2117 bpstat_clear_actions (bpstat bs
)
2119 for (; bs
!= NULL
; bs
= bs
->next
)
2121 free_command_lines (&bs
->commands
);
2122 if (bs
->old_val
!= NULL
)
2124 value_free (bs
->old_val
);
2130 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2132 cleanup_executing_breakpoints (void *ignore
)
2134 executing_breakpoint_commands
= 0;
2137 /* Execute all the commands associated with all the breakpoints at this
2138 location. Any of these commands could cause the process to proceed
2139 beyond this point, etc. We look out for such changes by checking
2140 the global "breakpoint_proceeded" after each command. */
2143 bpstat_do_actions (bpstat
*bsp
)
2146 struct cleanup
*old_chain
;
2148 /* Avoid endless recursion if a `source' command is contained
2150 if (executing_breakpoint_commands
)
2153 executing_breakpoint_commands
= 1;
2154 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2157 /* Note that (as of this writing), our callers all appear to
2158 be passing us the address of global stop_bpstat. And, if
2159 our calls to execute_control_command cause the inferior to
2160 proceed, that global (and hence, *bsp) will change.
2162 We must be careful to not touch *bsp unless the inferior
2163 has not proceeded. */
2165 /* This pointer will iterate over the list of bpstat's. */
2168 breakpoint_proceeded
= 0;
2169 for (; bs
!= NULL
; bs
= bs
->next
)
2171 struct command_line
*cmd
;
2172 struct cleanup
*this_cmd_tree_chain
;
2174 /* Take ownership of the BSP's command tree, if it has one.
2176 The command tree could legitimately contain commands like
2177 'step' and 'next', which call clear_proceed_status, which
2178 frees stop_bpstat's command tree. To make sure this doesn't
2179 free the tree we're executing out from under us, we need to
2180 take ownership of the tree ourselves. Since a given bpstat's
2181 commands are only executed once, we don't need to copy it; we
2182 can clear the pointer in the bpstat, and make sure we free
2183 the tree when we're done. */
2186 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2190 execute_control_command (cmd
);
2192 if (breakpoint_proceeded
)
2198 /* We can free this command tree now. */
2199 do_cleanups (this_cmd_tree_chain
);
2201 if (breakpoint_proceeded
)
2203 if (target_can_async_p ())
2204 /* If we are in async mode, then the target might
2205 be still running, not stopped at any breakpoint,
2206 so nothing for us to do here -- just return to
2210 /* In sync mode, when execute_control_command returns
2211 we're already standing on the next breakpoint.
2212 Breakpoint commands for that stop were not run,
2213 since execute_command does not run breakpoint
2214 commands -- only command_line_handler does, but
2215 that one is not involved in execution of breakpoint
2216 commands. So, we can now execute breakpoint commands.
2217 There's an implicit assumption that we're called with
2218 stop_bpstat, so our parameter is the new bpstat to
2220 It should be noted that making execute_command do
2221 bpstat actions is not an option -- in this case we'll
2222 have recursive invocation of bpstat for each breakpoint
2223 with a command, and can easily blow up GDB stack. */
2227 do_cleanups (old_chain
);
2230 /* Print out the (old or new) value associated with a watchpoint. */
2233 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2236 fprintf_unfiltered (stream
, _("<unreadable>"));
2238 value_print (val
, stream
, 0, Val_pretty_default
);
2241 /* This is the normal print function for a bpstat. In the future,
2242 much of this logic could (should?) be moved to bpstat_stop_status,
2243 by having it set different print_it values.
2245 Current scheme: When we stop, bpstat_print() is called. It loops
2246 through the bpstat list of things causing this stop, calling the
2247 print_bp_stop_message function on each one. The behavior of the
2248 print_bp_stop_message function depends on the print_it field of
2249 bpstat. If such field so indicates, call this function here.
2251 Return values from this routine (ultimately used by bpstat_print()
2252 and normal_stop() to decide what to do):
2253 PRINT_NOTHING: Means we already printed all we needed to print,
2254 don't print anything else.
2255 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2256 that something to be followed by a location.
2257 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2258 that something to be followed by a location.
2259 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2262 static enum print_stop_action
2263 print_it_typical (bpstat bs
)
2265 struct cleanup
*old_chain
, *ui_out_chain
;
2266 struct breakpoint
*b
;
2267 const struct bp_location
*bl
;
2268 struct ui_stream
*stb
;
2270 stb
= ui_out_stream_new (uiout
);
2271 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2272 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2273 which has since been deleted. */
2274 if (bs
->breakpoint_at
== NULL
)
2275 return PRINT_UNKNOWN
;
2276 bl
= bs
->breakpoint_at
;
2282 case bp_hardware_breakpoint
:
2283 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2284 if (bl
->address
!= bl
->requested_address
)
2285 breakpoint_adjustment_warning (bl
->requested_address
,
2288 annotate_breakpoint (b
->number
);
2290 ui_out_text (uiout
, "\nTemporary breakpoint ");
2292 ui_out_text (uiout
, "\nBreakpoint ");
2293 if (ui_out_is_mi_like_p (uiout
))
2295 ui_out_field_string (uiout
, "reason",
2296 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2297 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2299 ui_out_field_int (uiout
, "bkptno", b
->number
);
2300 ui_out_text (uiout
, ", ");
2301 return PRINT_SRC_AND_LOC
;
2304 case bp_shlib_event
:
2305 /* Did we stop because the user set the stop_on_solib_events
2306 variable? (If so, we report this as a generic, "Stopped due
2307 to shlib event" message.) */
2308 printf_filtered (_("Stopped due to shared library event\n"));
2309 return PRINT_NOTHING
;
2312 case bp_thread_event
:
2313 /* Not sure how we will get here.
2314 GDB should not stop for these breakpoints. */
2315 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2316 return PRINT_NOTHING
;
2319 case bp_overlay_event
:
2320 /* By analogy with the thread event, GDB should not stop for these. */
2321 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2322 return PRINT_NOTHING
;
2326 annotate_catchpoint (b
->number
);
2327 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2329 b
->triggered_dll_pathname
);
2330 return PRINT_SRC_AND_LOC
;
2333 case bp_catch_unload
:
2334 annotate_catchpoint (b
->number
);
2335 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2337 b
->triggered_dll_pathname
);
2338 return PRINT_SRC_AND_LOC
;
2342 annotate_catchpoint (b
->number
);
2343 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2345 ptid_get_pid (b
->forked_inferior_pid
));
2346 return PRINT_SRC_AND_LOC
;
2349 case bp_catch_vfork
:
2350 annotate_catchpoint (b
->number
);
2351 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2353 ptid_get_pid (b
->forked_inferior_pid
));
2354 return PRINT_SRC_AND_LOC
;
2358 annotate_catchpoint (b
->number
);
2359 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2362 return PRINT_SRC_AND_LOC
;
2366 case bp_hardware_watchpoint
:
2367 annotate_watchpoint (b
->number
);
2368 if (ui_out_is_mi_like_p (uiout
))
2371 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2373 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2374 ui_out_text (uiout
, "\nOld value = ");
2375 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2376 ui_out_field_stream (uiout
, "old", stb
);
2377 ui_out_text (uiout
, "\nNew value = ");
2378 watchpoint_value_print (b
->val
, stb
->stream
);
2379 ui_out_field_stream (uiout
, "new", stb
);
2380 do_cleanups (ui_out_chain
);
2381 ui_out_text (uiout
, "\n");
2382 /* More than one watchpoint may have been triggered. */
2383 return PRINT_UNKNOWN
;
2386 case bp_read_watchpoint
:
2387 if (ui_out_is_mi_like_p (uiout
))
2390 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2392 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2393 ui_out_text (uiout
, "\nValue = ");
2394 watchpoint_value_print (b
->val
, stb
->stream
);
2395 ui_out_field_stream (uiout
, "value", stb
);
2396 do_cleanups (ui_out_chain
);
2397 ui_out_text (uiout
, "\n");
2398 return PRINT_UNKNOWN
;
2401 case bp_access_watchpoint
:
2402 if (bs
->old_val
!= NULL
)
2404 annotate_watchpoint (b
->number
);
2405 if (ui_out_is_mi_like_p (uiout
))
2408 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2410 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2411 ui_out_text (uiout
, "\nOld value = ");
2412 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2413 ui_out_field_stream (uiout
, "old", stb
);
2414 ui_out_text (uiout
, "\nNew value = ");
2419 if (ui_out_is_mi_like_p (uiout
))
2422 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2423 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2424 ui_out_text (uiout
, "\nValue = ");
2426 watchpoint_value_print (b
->val
, stb
->stream
);
2427 ui_out_field_stream (uiout
, "new", stb
);
2428 do_cleanups (ui_out_chain
);
2429 ui_out_text (uiout
, "\n");
2430 return PRINT_UNKNOWN
;
2433 /* Fall through, we don't deal with these types of breakpoints
2437 if (ui_out_is_mi_like_p (uiout
))
2440 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2441 return PRINT_UNKNOWN
;
2445 if (ui_out_is_mi_like_p (uiout
))
2448 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2449 return PRINT_UNKNOWN
;
2454 case bp_longjmp_resume
:
2455 case bp_step_resume
:
2456 case bp_watchpoint_scope
:
2459 return PRINT_UNKNOWN
;
2463 /* Generic routine for printing messages indicating why we
2464 stopped. The behavior of this function depends on the value
2465 'print_it' in the bpstat structure. Under some circumstances we
2466 may decide not to print anything here and delegate the task to
2469 static enum print_stop_action
2470 print_bp_stop_message (bpstat bs
)
2472 switch (bs
->print_it
)
2475 /* Nothing should be printed for this bpstat entry. */
2476 return PRINT_UNKNOWN
;
2480 /* We still want to print the frame, but we already printed the
2481 relevant messages. */
2482 return PRINT_SRC_AND_LOC
;
2485 case print_it_normal
:
2487 const struct bp_location
*bl
= bs
->breakpoint_at
;
2488 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2490 /* Normal case. Call the breakpoint's print_it method, or
2491 print_it_typical. */
2492 /* FIXME: how breakpoint can ever be NULL here? */
2493 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2494 return b
->ops
->print_it (b
);
2496 return print_it_typical (bs
);
2501 internal_error (__FILE__
, __LINE__
,
2502 _("print_bp_stop_message: unrecognized enum value"));
2507 /* Print a message indicating what happened. This is called from
2508 normal_stop(). The input to this routine is the head of the bpstat
2509 list - a list of the eventpoints that caused this stop. This
2510 routine calls the generic print routine for printing a message
2511 about reasons for stopping. This will print (for example) the
2512 "Breakpoint n," part of the output. The return value of this
2515 PRINT_UNKNOWN: Means we printed nothing
2516 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2517 code to print the location. An example is
2518 "Breakpoint 1, " which should be followed by
2520 PRINT_SRC_ONLY: Means we printed something, but there is no need
2521 to also print the location part of the message.
2522 An example is the catch/throw messages, which
2523 don't require a location appended to the end.
2524 PRINT_NOTHING: We have done some printing and we don't need any
2525 further info to be printed.*/
2527 enum print_stop_action
2528 bpstat_print (bpstat bs
)
2532 /* Maybe another breakpoint in the chain caused us to stop.
2533 (Currently all watchpoints go on the bpstat whether hit or not.
2534 That probably could (should) be changed, provided care is taken
2535 with respect to bpstat_explains_signal). */
2536 for (; bs
; bs
= bs
->next
)
2538 val
= print_bp_stop_message (bs
);
2539 if (val
== PRINT_SRC_ONLY
2540 || val
== PRINT_SRC_AND_LOC
2541 || val
== PRINT_NOTHING
)
2545 /* We reached the end of the chain, or we got a null BS to start
2546 with and nothing was printed. */
2547 return PRINT_UNKNOWN
;
2550 /* Evaluate the expression EXP and return 1 if value is zero.
2551 This is used inside a catch_errors to evaluate the breakpoint condition.
2552 The argument is a "struct expression *" that has been cast to char * to
2553 make it pass through catch_errors. */
2556 breakpoint_cond_eval (void *exp
)
2558 struct value
*mark
= value_mark ();
2559 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2560 value_free_to_mark (mark
);
2564 /* Allocate a new bpstat and chain it to the current one. */
2567 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2571 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2573 bs
->breakpoint_at
= bl
;
2574 /* If the condition is false, etc., don't do the commands. */
2575 bs
->commands
= NULL
;
2577 bs
->print_it
= print_it_normal
;
2581 /* The target has stopped with waitstatus WS. Check if any hardware
2582 watchpoints have triggered, according to the target. */
2585 watchpoints_triggered (struct target_waitstatus
*ws
)
2587 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2589 struct breakpoint
*b
;
2591 if (!stopped_by_watchpoint
)
2593 /* We were not stopped by a watchpoint. Mark all watchpoints
2594 as not triggered. */
2596 if (b
->type
== bp_hardware_watchpoint
2597 || b
->type
== bp_read_watchpoint
2598 || b
->type
== bp_access_watchpoint
)
2599 b
->watchpoint_triggered
= watch_triggered_no
;
2604 if (!target_stopped_data_address (¤t_target
, &addr
))
2606 /* We were stopped by a watchpoint, but we don't know where.
2607 Mark all watchpoints as unknown. */
2609 if (b
->type
== bp_hardware_watchpoint
2610 || b
->type
== bp_read_watchpoint
2611 || b
->type
== bp_access_watchpoint
)
2612 b
->watchpoint_triggered
= watch_triggered_unknown
;
2614 return stopped_by_watchpoint
;
2617 /* The target could report the data address. Mark watchpoints
2618 affected by this data address as triggered, and all others as not
2622 if (b
->type
== bp_hardware_watchpoint
2623 || b
->type
== bp_read_watchpoint
2624 || b
->type
== bp_access_watchpoint
)
2626 struct bp_location
*loc
;
2629 b
->watchpoint_triggered
= watch_triggered_no
;
2630 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2631 /* Exact match not required. Within range is
2633 if (target_watchpoint_addr_within_range (¤t_target
,
2637 b
->watchpoint_triggered
= watch_triggered_yes
;
2645 /* Possible return values for watchpoint_check (this can't be an enum
2646 because of check_errors). */
2647 /* The watchpoint has been deleted. */
2648 #define WP_DELETED 1
2649 /* The value has changed. */
2650 #define WP_VALUE_CHANGED 2
2651 /* The value has not changed. */
2652 #define WP_VALUE_NOT_CHANGED 3
2654 #define BP_TEMPFLAG 1
2655 #define BP_HARDWAREFLAG 2
2657 /* Check watchpoint condition. */
2660 watchpoint_check (void *p
)
2662 bpstat bs
= (bpstat
) p
;
2663 struct breakpoint
*b
;
2664 struct frame_info
*fr
;
2665 int within_current_scope
;
2667 b
= bs
->breakpoint_at
->owner
;
2669 if (b
->exp_valid_block
== NULL
)
2670 within_current_scope
= 1;
2673 /* There is no current frame at this moment. If we're going to have
2674 any chance of handling watchpoints on local variables, we'll need
2675 the frame chain (so we can determine if we're in scope). */
2676 reinit_frame_cache ();
2677 fr
= frame_find_by_id (b
->watchpoint_frame
);
2678 within_current_scope
= (fr
!= NULL
);
2680 /* If we've gotten confused in the unwinder, we might have
2681 returned a frame that can't describe this variable. */
2682 if (within_current_scope
2683 && (block_linkage_function (b
->exp_valid_block
)
2684 != get_frame_function (fr
)))
2685 within_current_scope
= 0;
2687 /* in_function_epilogue_p() returns a non-zero value if we're still
2688 in the function but the stack frame has already been invalidated.
2689 Since we can't rely on the values of local variables after the
2690 stack has been destroyed, we are treating the watchpoint in that
2691 state as `not changed' without further checking.
2693 vinschen/2003-09-04: The former implementation left out the case
2694 that the watchpoint frame couldn't be found by frame_find_by_id()
2695 because the current PC is currently in an epilogue. Calling
2696 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2697 if ((!within_current_scope
|| fr
== get_current_frame ())
2698 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2699 return WP_VALUE_NOT_CHANGED
;
2700 if (fr
&& within_current_scope
)
2701 /* If we end up stopping, the current frame will get selected
2702 in normal_stop. So this call to select_frame won't affect
2707 if (within_current_scope
)
2709 /* We use value_{,free_to_}mark because it could be a
2710 *long* time before we return to the command level and
2711 call free_all_values. We can't call free_all_values because
2712 we might be in the middle of evaluating a function call. */
2714 struct value
*mark
= value_mark ();
2715 struct value
*new_val
;
2717 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2718 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2719 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2721 if (new_val
!= NULL
)
2723 release_value (new_val
);
2724 value_free_to_mark (mark
);
2726 bs
->old_val
= b
->val
;
2729 /* We will stop here */
2730 return WP_VALUE_CHANGED
;
2734 /* Nothing changed, don't do anything. */
2735 value_free_to_mark (mark
);
2736 /* We won't stop here */
2737 return WP_VALUE_NOT_CHANGED
;
2742 /* This seems like the only logical thing to do because
2743 if we temporarily ignored the watchpoint, then when
2744 we reenter the block in which it is valid it contains
2745 garbage (in the case of a function, it may have two
2746 garbage values, one before and one after the prologue).
2747 So we can't even detect the first assignment to it and
2748 watch after that (since the garbage may or may not equal
2749 the first value assigned). */
2750 /* We print all the stop information in print_it_typical(), but
2751 in this case, by the time we call print_it_typical() this bp
2752 will be deleted already. So we have no choice but print the
2753 information here. */
2754 if (ui_out_is_mi_like_p (uiout
))
2756 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2757 ui_out_text (uiout
, "\nWatchpoint ");
2758 ui_out_field_int (uiout
, "wpnum", b
->number
);
2759 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2760 which its expression is valid.\n");
2762 if (b
->related_breakpoint
)
2763 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2764 b
->disposition
= disp_del_at_next_stop
;
2770 /* Return true if it looks like target has stopped due to hitting
2771 breakpoint location BL. This function does not check if we
2772 should stop, only if BL explains the stop. */
2774 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2776 struct breakpoint
*b
= bl
->owner
;
2778 if (b
->type
!= bp_watchpoint
2779 && b
->type
!= bp_hardware_watchpoint
2780 && b
->type
!= bp_read_watchpoint
2781 && b
->type
!= bp_access_watchpoint
2782 && b
->type
!= bp_hardware_breakpoint
2783 && b
->type
!= bp_catch_fork
2784 && b
->type
!= bp_catch_vfork
2785 && b
->type
!= bp_catch_exec
) /* a non-watchpoint bp */
2787 if (bl
->address
!= bp_addr
) /* address doesn't match */
2789 if (overlay_debugging
/* unmapped overlay section */
2790 && section_is_overlay (bl
->section
)
2791 && !section_is_mapped (bl
->section
))
2795 /* Continuable hardware watchpoints are treated as non-existent if the
2796 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2797 some data address). Otherwise gdb won't stop on a break instruction
2798 in the code (not from a breakpoint) when a hardware watchpoint has
2799 been defined. Also skip watchpoints which we know did not trigger
2800 (did not match the data address). */
2802 if ((b
->type
== bp_hardware_watchpoint
2803 || b
->type
== bp_read_watchpoint
2804 || b
->type
== bp_access_watchpoint
)
2805 && b
->watchpoint_triggered
== watch_triggered_no
)
2808 if (b
->type
== bp_hardware_breakpoint
)
2810 if (bl
->address
!= bp_addr
)
2812 if (overlay_debugging
/* unmapped overlay section */
2813 && section_is_overlay (bl
->section
)
2814 && !section_is_mapped (bl
->section
))
2818 /* Is this a catchpoint of a load or unload? If so, did we
2819 get a load or unload of the specified library? If not,
2821 if ((b
->type
== bp_catch_load
)
2822 #if defined(SOLIB_HAVE_LOAD_EVENT)
2823 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2824 || ((b
->dll_pathname
!= NULL
)
2825 && (strcmp (b
->dll_pathname
,
2826 SOLIB_LOADED_LIBRARY_PATHNAME (
2827 PIDGET (inferior_ptid
)))
2833 if ((b
->type
== bp_catch_unload
)
2834 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2835 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2836 || ((b
->dll_pathname
!= NULL
)
2837 && (strcmp (b
->dll_pathname
,
2838 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2839 PIDGET (inferior_ptid
)))
2845 if ((b
->type
== bp_catch_fork
)
2846 && !inferior_has_forked (inferior_ptid
,
2847 &b
->forked_inferior_pid
))
2850 if ((b
->type
== bp_catch_vfork
)
2851 && !inferior_has_vforked (inferior_ptid
,
2852 &b
->forked_inferior_pid
))
2855 if ((b
->type
== bp_catch_exec
)
2856 && !inferior_has_execd (inferior_ptid
, &b
->exec_pathname
))
2862 /* If BS refers to a watchpoint, determine if the watched values
2863 has actually changed, and we should stop. If not, set BS->stop
2866 bpstat_check_watchpoint (bpstat bs
)
2868 const struct bp_location
*bl
= bs
->breakpoint_at
;
2869 struct breakpoint
*b
= bl
->owner
;
2871 if (b
->type
== bp_watchpoint
2872 || b
->type
== bp_read_watchpoint
2873 || b
->type
== bp_access_watchpoint
2874 || b
->type
== bp_hardware_watchpoint
)
2878 int must_check_value
= 0;
2880 if (b
->type
== bp_watchpoint
)
2881 /* For a software watchpoint, we must always check the
2883 must_check_value
= 1;
2884 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2885 /* We have a hardware watchpoint (read, write, or access)
2886 and the target earlier reported an address watched by
2888 must_check_value
= 1;
2889 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2890 && b
->type
== bp_hardware_watchpoint
)
2891 /* We were stopped by a hardware watchpoint, but the target could
2892 not report the data address. We must check the watchpoint's
2893 value. Access and read watchpoints are out of luck; without
2894 a data address, we can't figure it out. */
2895 must_check_value
= 1;
2897 if (must_check_value
)
2899 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2901 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2902 int e
= catch_errors (watchpoint_check
, bs
, message
,
2904 do_cleanups (cleanups
);
2908 /* We've already printed what needs to be printed. */
2909 bs
->print_it
= print_it_done
;
2912 case WP_VALUE_CHANGED
:
2913 if (b
->type
== bp_read_watchpoint
)
2915 /* Don't stop: read watchpoints shouldn't fire if
2916 the value has changed. This is for targets
2917 which cannot set read-only watchpoints. */
2918 bs
->print_it
= print_it_noop
;
2922 case WP_VALUE_NOT_CHANGED
:
2923 if (b
->type
== bp_hardware_watchpoint
2924 || b
->type
== bp_watchpoint
)
2926 /* Don't stop: write watchpoints shouldn't fire if
2927 the value hasn't changed. */
2928 bs
->print_it
= print_it_noop
;
2936 /* Error from catch_errors. */
2937 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2938 if (b
->related_breakpoint
)
2939 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2940 b
->disposition
= disp_del_at_next_stop
;
2941 /* We've already printed what needs to be printed. */
2942 bs
->print_it
= print_it_done
;
2946 else /* must_check_value == 0 */
2948 /* This is a case where some watchpoint(s) triggered, but
2949 not at the address of this watchpoint, or else no
2950 watchpoint triggered after all. So don't print
2951 anything for this watchpoint. */
2952 bs
->print_it
= print_it_noop
;
2959 /* Check conditions (condition proper, frame, thread and ignore count)
2960 of breakpoint referred to by BS. If we should not stop for this
2961 breakpoint, set BS->stop to 0. */
2963 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2965 int thread_id
= pid_to_thread_id (ptid
);
2966 const struct bp_location
*bl
= bs
->breakpoint_at
;
2967 struct breakpoint
*b
= bl
->owner
;
2969 if (frame_id_p (b
->frame_id
)
2970 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2974 int value_is_zero
= 0;
2976 /* If this is a scope breakpoint, mark the associated
2977 watchpoint as triggered so that we will handle the
2978 out-of-scope event. We'll get to the watchpoint next
2980 if (b
->type
== bp_watchpoint_scope
)
2981 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2983 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2985 /* Need to select the frame, with all that implies
2986 so that the conditions will have the right context. */
2987 select_frame (get_current_frame ());
2989 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2990 "Error in testing breakpoint condition:\n",
2992 /* FIXME-someday, should give breakpoint # */
2995 if (bl
->cond
&& value_is_zero
)
2999 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3003 else if (b
->ignore_count
> 0)
3006 annotate_ignore_count_change ();
3008 /* Increase the hit count even though we don't
3016 /* Get a bpstat associated with having just stopped at address
3017 BP_ADDR in thread PTID.
3019 Determine whether we stopped at a breakpoint, etc, or whether we
3020 don't understand this stop. Result is a chain of bpstat's such that:
3022 if we don't understand the stop, the result is a null pointer.
3024 if we understand why we stopped, the result is not null.
3026 Each element of the chain refers to a particular breakpoint or
3027 watchpoint at which we have stopped. (We may have stopped for
3028 several reasons concurrently.)
3030 Each element of the chain has valid next, breakpoint_at,
3031 commands, FIXME??? fields. */
3034 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3036 struct breakpoint
*b
= NULL
;
3037 const struct bp_location
*bl
;
3038 struct bp_location
*loc
;
3039 /* Root of the chain of bpstat's */
3040 struct bpstats root_bs
[1];
3041 /* Pointer to the last thing in the chain currently. */
3042 bpstat bs
= root_bs
;
3045 ALL_BP_LOCATIONS (bl
)
3049 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3052 /* For hardware watchpoints, we look only at the first location.
3053 The watchpoint_check function will work on entire expression,
3054 not the individual locations. For read watchopints, the
3055 watchpoints_triggered function have checked all locations
3058 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3061 if (!bpstat_check_location (bl
, bp_addr
))
3064 /* Come here if it's a watchpoint, or if the break address matches */
3066 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3068 /* Assume we stop. Should we find watchpoint that is not actually
3069 triggered, or if condition of breakpoint is false, we'll reset
3074 bpstat_check_watchpoint (bs
);
3078 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3079 /* We do not stop for these. */
3082 bpstat_check_breakpoint_conditions (bs
, ptid
);
3088 /* We will stop here */
3089 if (b
->disposition
== disp_disable
)
3091 b
->enable_state
= bp_disabled
;
3092 update_global_location_list (0);
3096 bs
->commands
= b
->commands
;
3098 (strcmp ("silent", bs
->commands
->line
) == 0
3099 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3101 bs
->commands
= bs
->commands
->next
;
3104 bs
->commands
= copy_command_lines (bs
->commands
);
3107 /* Print nothing for this entry if we dont stop or if we dont print. */
3108 if (bs
->stop
== 0 || bs
->print
== 0)
3109 bs
->print_it
= print_it_noop
;
3112 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3114 if (loc
->address
== bp_addr
)
3116 bs
= bpstat_alloc (loc
, bs
);
3117 /* For hits of moribund locations, we should just proceed. */
3120 bs
->print_it
= print_it_noop
;
3124 bs
->next
= NULL
; /* Terminate the chain */
3125 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3127 /* If we aren't stopping, the value of some hardware watchpoint may
3128 not have changed, but the intermediate memory locations we are
3129 watching may have. Don't bother if we're stopping; this will get
3131 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3136 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3138 && bs
->breakpoint_at
->owner
3139 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3140 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3141 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3143 /* remove/insert can invalidate bs->breakpoint_at, if this
3144 location is no longer used by the watchpoint. Prevent
3145 further code from trying to use it. */
3146 bs
->breakpoint_at
= NULL
;
3147 remove_breakpoints ();
3148 insert_breakpoints ();
3152 return root_bs
->next
;
3155 /* Tell what to do about this bpstat. */
3157 bpstat_what (bpstat bs
)
3159 /* Classify each bpstat as one of the following. */
3162 /* This bpstat element has no effect on the main_action. */
3165 /* There was a watchpoint, stop but don't print. */
3168 /* There was a watchpoint, stop and print. */
3171 /* There was a breakpoint but we're not stopping. */
3174 /* There was a breakpoint, stop but don't print. */
3177 /* There was a breakpoint, stop and print. */
3180 /* We hit the longjmp breakpoint. */
3183 /* We hit the longjmp_resume breakpoint. */
3186 /* We hit the step_resume breakpoint. */
3189 /* We hit the shared library event breakpoint. */
3192 /* We caught a shared library event. */
3195 /* This is just used to count how many enums there are. */
3199 /* Here is the table which drives this routine. So that we can
3200 format it pretty, we define some abbreviations for the
3201 enum bpstat_what codes. */
3202 #define kc BPSTAT_WHAT_KEEP_CHECKING
3203 #define ss BPSTAT_WHAT_STOP_SILENT
3204 #define sn BPSTAT_WHAT_STOP_NOISY
3205 #define sgl BPSTAT_WHAT_SINGLE
3206 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3207 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3208 #define sr BPSTAT_WHAT_STEP_RESUME
3209 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3210 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3212 /* "Can't happen." Might want to print an error message.
3213 abort() is not out of the question, but chances are GDB is just
3214 a bit confused, not unusable. */
3215 #define err BPSTAT_WHAT_STOP_NOISY
3217 /* Given an old action and a class, come up with a new action. */
3218 /* One interesting property of this table is that wp_silent is the same
3219 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3220 after stopping, the check for whether to step over a breakpoint
3221 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3222 reference to how we stopped. We retain separate wp_silent and
3223 bp_silent codes in case we want to change that someday.
3225 Another possibly interesting property of this table is that
3226 there's a partial ordering, priority-like, of the actions. Once
3227 you've decided that some action is appropriate, you'll never go
3228 back and decide something of a lower priority is better. The
3231 kc < clr sgl shl shlr slr sn sr ss
3232 sgl < shl shlr slr sn sr ss
3233 slr < err shl shlr sn sr ss
3234 clr < err shl shlr sn sr ss
3241 What I think this means is that we don't need a damned table
3242 here. If you just put the rows and columns in the right order,
3243 it'd look awfully regular. We could simply walk the bpstat list
3244 and choose the highest priority action we find, with a little
3245 logic to handle the 'err' cases. */
3247 /* step_resume entries: a step resume breakpoint overrides another
3248 breakpoint of signal handling (see comment in wait_for_inferior
3249 at where we set the step_resume breakpoint). */
3251 static const enum bpstat_what_main_action
3252 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3255 /* kc ss sn sgl slr clr sr shl shlr
3258 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, shlr
},
3260 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3262 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3264 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, shlr
},
3266 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3268 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3270 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, shlr
},
3272 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, shlr
},
3274 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3276 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3278 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3292 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3293 struct bpstat_what retval
;
3295 retval
.call_dummy
= 0;
3296 for (; bs
!= NULL
; bs
= bs
->next
)
3298 enum class bs_class
= no_effect
;
3299 if (bs
->breakpoint_at
== NULL
)
3300 /* I suspect this can happen if it was a momentary breakpoint
3301 which has since been deleted. */
3303 if (bs
->breakpoint_at
->owner
== NULL
)
3304 bs_class
= bp_nostop
;
3306 switch (bs
->breakpoint_at
->owner
->type
)
3312 case bp_hardware_breakpoint
:
3318 bs_class
= bp_noisy
;
3320 bs_class
= bp_silent
;
3323 bs_class
= bp_nostop
;
3326 case bp_hardware_watchpoint
:
3327 case bp_read_watchpoint
:
3328 case bp_access_watchpoint
:
3332 bs_class
= wp_noisy
;
3334 bs_class
= wp_silent
;
3337 /* There was a watchpoint, but we're not stopping.
3338 This requires no further action. */
3339 bs_class
= no_effect
;
3342 bs_class
= long_jump
;
3344 case bp_longjmp_resume
:
3345 bs_class
= long_resume
;
3347 case bp_step_resume
:
3350 bs_class
= step_resume
;
3353 /* It is for the wrong frame. */
3354 bs_class
= bp_nostop
;
3356 case bp_watchpoint_scope
:
3357 bs_class
= bp_nostop
;
3359 case bp_shlib_event
:
3360 bs_class
= shlib_event
;
3362 case bp_thread_event
:
3363 case bp_overlay_event
:
3364 bs_class
= bp_nostop
;
3367 case bp_catch_unload
:
3368 /* Only if this catchpoint triggered should we cause the
3369 step-out-of-dld behaviour. Otherwise, we ignore this
3372 bs_class
= catch_shlib_event
;
3374 bs_class
= no_effect
;
3377 case bp_catch_vfork
:
3382 bs_class
= bp_noisy
;
3384 bs_class
= bp_silent
;
3387 /* There was a catchpoint, but we're not stopping.
3388 This requires no further action. */
3389 bs_class
= no_effect
;
3392 /* Make sure the action is stop (silent or noisy),
3393 so infrun.c pops the dummy frame. */
3394 bs_class
= bp_silent
;
3395 retval
.call_dummy
= 1;
3398 current_action
= table
[(int) bs_class
][(int) current_action
];
3400 retval
.main_action
= current_action
;
3404 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3405 without hardware support). This isn't related to a specific bpstat,
3406 just to things like whether watchpoints are set. */
3409 bpstat_should_step (void)
3411 struct breakpoint
*b
;
3413 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3420 /* Given a bpstat that records zero or more triggered eventpoints, this
3421 function returns another bpstat which contains only the catchpoints
3422 on that first list, if any. */
3424 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3426 struct bpstats root_bs
[1];
3427 bpstat bs
= root_bs
;
3428 struct breakpoint
*ep
;
3431 bpstat_clear (cp_list
);
3432 root_bs
->next
= NULL
;
3434 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3436 /* Is this eventpoint a catchpoint? If not, ignore it. */
3437 ep
= ep_list
->breakpoint_at
->owner
;
3440 if ((ep
->type
!= bp_catch_load
) &&
3441 (ep
->type
!= bp_catch_unload
))
3442 /* pai: (temp) ADD fork/vfork here!! */
3445 /* Yes; add it to the list. */
3446 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3451 #if defined(SOLIB_ADD)
3452 /* Also, for each triggered catchpoint, tag it with the name of
3453 the library that caused this trigger. (We copy the name now,
3454 because it's only guaranteed to be available NOW, when the
3455 catchpoint triggers. Clients who may wish to know the name
3456 later must get it from the catchpoint itself.) */
3457 if (ep
->triggered_dll_pathname
!= NULL
)
3458 xfree (ep
->triggered_dll_pathname
);
3459 if (ep
->type
== bp_catch_load
)
3460 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3461 PIDGET (inferior_ptid
));
3463 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3464 PIDGET (inferior_ptid
));
3466 dll_pathname
= NULL
;
3470 ep
->triggered_dll_pathname
= (char *)
3471 xmalloc (strlen (dll_pathname
) + 1);
3472 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3475 ep
->triggered_dll_pathname
= NULL
;
3481 static void print_breakpoint_location (struct breakpoint
*b
,
3482 struct bp_location
*loc
,
3484 struct ui_stream
*stb
)
3489 = find_pc_sect_function (loc
->address
, loc
->section
);
3492 ui_out_text (uiout
, "in ");
3493 ui_out_field_string (uiout
, "func",
3494 SYMBOL_PRINT_NAME (sym
));
3495 ui_out_wrap_hint (uiout
, wrap_indent
);
3496 ui_out_text (uiout
, " at ");
3498 ui_out_field_string (uiout
, "file", b
->source_file
);
3499 ui_out_text (uiout
, ":");
3501 if (ui_out_is_mi_like_p (uiout
))
3503 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3504 char *fullname
= symtab_to_fullname (sal
.symtab
);
3507 ui_out_field_string (uiout
, "fullname", fullname
);
3510 ui_out_field_int (uiout
, "line", b
->line_number
);
3514 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3518 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3519 ui_out_field_stream (uiout
, "at", stb
);
3523 /* Print B to gdb_stdout. */
3525 print_one_breakpoint_location (struct breakpoint
*b
,
3526 struct bp_location
*loc
,
3528 CORE_ADDR
*last_addr
)
3530 struct command_line
*l
;
3532 struct ep_type_description
3537 static struct ep_type_description bptypes
[] =
3539 {bp_none
, "?deleted?"},
3540 {bp_breakpoint
, "breakpoint"},
3541 {bp_hardware_breakpoint
, "hw breakpoint"},
3542 {bp_until
, "until"},
3543 {bp_finish
, "finish"},
3544 {bp_watchpoint
, "watchpoint"},
3545 {bp_hardware_watchpoint
, "hw watchpoint"},
3546 {bp_read_watchpoint
, "read watchpoint"},
3547 {bp_access_watchpoint
, "acc watchpoint"},
3548 {bp_longjmp
, "longjmp"},
3549 {bp_longjmp_resume
, "longjmp resume"},
3550 {bp_step_resume
, "step resume"},
3551 {bp_watchpoint_scope
, "watchpoint scope"},
3552 {bp_call_dummy
, "call dummy"},
3553 {bp_shlib_event
, "shlib events"},
3554 {bp_thread_event
, "thread events"},
3555 {bp_overlay_event
, "overlay events"},
3556 {bp_catch_load
, "catch load"},
3557 {bp_catch_unload
, "catch unload"},
3558 {bp_catch_fork
, "catch fork"},
3559 {bp_catch_vfork
, "catch vfork"},
3560 {bp_catch_exec
, "catch exec"}
3563 static char bpenables
[] = "nynny";
3564 char wrap_indent
[80];
3565 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3566 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3567 struct cleanup
*bkpt_chain
;
3569 int header_of_multiple
= 0;
3570 int part_of_multiple
= (loc
!= NULL
);
3572 gdb_assert (!loc
|| loc_number
!= 0);
3573 /* See comment in print_one_breakpoint concerning
3574 treatment of breakpoints with single disabled
3578 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3579 header_of_multiple
= 1;
3584 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3588 if (part_of_multiple
)
3591 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3592 ui_out_field_string (uiout
, "number", formatted
);
3597 ui_out_field_int (uiout
, "number", b
->number
);
3602 if (part_of_multiple
)
3603 ui_out_field_skip (uiout
, "type");
3606 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3607 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3608 internal_error (__FILE__
, __LINE__
,
3609 _("bptypes table does not describe type #%d."),
3611 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3616 if (part_of_multiple
)
3617 ui_out_field_skip (uiout
, "disp");
3619 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3624 if (part_of_multiple
)
3625 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3627 ui_out_field_fmt (uiout
, "enabled", "%c",
3628 bpenables
[(int) b
->enable_state
]);
3629 ui_out_spaces (uiout
, 2);
3633 strcpy (wrap_indent
, " ");
3636 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3637 strcat (wrap_indent
, " ");
3639 strcat (wrap_indent
, " ");
3642 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3644 /* Although the print_one can possibly print
3645 all locations, calling it here is not likely
3646 to get any nice result. So, make sure there's
3647 just one location. */
3648 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3649 b
->ops
->print_one (b
, last_addr
);
3655 internal_error (__FILE__
, __LINE__
,
3656 _("print_one_breakpoint: bp_none encountered\n"));
3660 case bp_hardware_watchpoint
:
3661 case bp_read_watchpoint
:
3662 case bp_access_watchpoint
:
3663 /* Field 4, the address, is omitted (which makes the columns
3664 not line up too nicely with the headers, but the effect
3665 is relatively readable). */
3667 ui_out_field_skip (uiout
, "addr");
3669 print_expression (b
->exp
, stb
->stream
);
3670 ui_out_field_stream (uiout
, "what", stb
);
3674 case bp_catch_unload
:
3675 /* Field 4, the address, is omitted (which makes the columns
3676 not line up too nicely with the headers, but the effect
3677 is relatively readable). */
3679 ui_out_field_skip (uiout
, "addr");
3681 if (b
->dll_pathname
== NULL
)
3683 ui_out_field_string (uiout
, "what", "<any library>");
3684 ui_out_spaces (uiout
, 1);
3688 ui_out_text (uiout
, "library \"");
3689 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3690 ui_out_text (uiout
, "\" ");
3695 case bp_catch_vfork
:
3696 /* Field 4, the address, is omitted (which makes the columns
3697 not line up too nicely with the headers, but the effect
3698 is relatively readable). */
3700 ui_out_field_skip (uiout
, "addr");
3702 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
3704 ui_out_text (uiout
, "process ");
3705 ui_out_field_int (uiout
, "what",
3706 ptid_get_pid (b
->forked_inferior_pid
));
3707 ui_out_spaces (uiout
, 1);
3712 /* Field 4, the address, is omitted (which makes the columns
3713 not line up too nicely with the headers, but the effect
3714 is relatively readable). */
3716 ui_out_field_skip (uiout
, "addr");
3718 if (b
->exec_pathname
!= NULL
)
3720 ui_out_text (uiout
, "program \"");
3721 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3722 ui_out_text (uiout
, "\" ");
3727 case bp_hardware_breakpoint
:
3731 case bp_longjmp_resume
:
3732 case bp_step_resume
:
3733 case bp_watchpoint_scope
:
3735 case bp_shlib_event
:
3736 case bp_thread_event
:
3737 case bp_overlay_event
:
3741 if (header_of_multiple
)
3742 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3743 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3744 ui_out_field_string (uiout
, "addr", "<PENDING>");
3746 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3749 if (!header_of_multiple
)
3750 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3752 *last_addr
= b
->loc
->address
;
3756 if (!part_of_multiple
&& b
->thread
!= -1)
3758 /* FIXME: This seems to be redundant and lost here; see the
3759 "stop only in" line a little further down. */
3760 ui_out_text (uiout
, " thread ");
3761 ui_out_field_int (uiout
, "thread", b
->thread
);
3764 ui_out_text (uiout
, "\n");
3766 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3769 ui_out_text (uiout
, "\tstop only in stack frame at ");
3770 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3772 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3773 ui_out_text (uiout
, "\n");
3776 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3778 /* We do not print the condition for Ada exception catchpoints
3779 because the condition is an internal implementation detail
3780 that we do not want to expose to the user. */
3782 ui_out_text (uiout
, "\tstop only if ");
3783 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3784 ui_out_text (uiout
, "\n");
3787 if (!part_of_multiple
&& b
->thread
!= -1)
3789 /* FIXME should make an annotation for this */
3790 ui_out_text (uiout
, "\tstop only in thread ");
3791 ui_out_field_int (uiout
, "thread", b
->thread
);
3792 ui_out_text (uiout
, "\n");
3795 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3797 /* FIXME should make an annotation for this */
3798 if (ep_is_catchpoint (b
))
3799 ui_out_text (uiout
, "\tcatchpoint");
3801 ui_out_text (uiout
, "\tbreakpoint");
3802 ui_out_text (uiout
, " already hit ");
3803 ui_out_field_int (uiout
, "times", b
->hit_count
);
3804 if (b
->hit_count
== 1)
3805 ui_out_text (uiout
, " time\n");
3807 ui_out_text (uiout
, " times\n");
3810 /* Output the count also if it is zero, but only if this is
3811 mi. FIXME: Should have a better test for this. */
3812 if (ui_out_is_mi_like_p (uiout
))
3813 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3814 ui_out_field_int (uiout
, "times", b
->hit_count
);
3816 if (!part_of_multiple
&& b
->ignore_count
)
3819 ui_out_text (uiout
, "\tignore next ");
3820 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3821 ui_out_text (uiout
, " hits\n");
3824 if (!part_of_multiple
&& (l
= b
->commands
))
3826 struct cleanup
*script_chain
;
3829 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3830 print_command_lines (uiout
, l
, 4);
3831 do_cleanups (script_chain
);
3834 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3837 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3838 else if (b
->exp_string
)
3839 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3842 do_cleanups (bkpt_chain
);
3843 do_cleanups (old_chain
);
3847 print_one_breakpoint (struct breakpoint
*b
,
3848 CORE_ADDR
*last_addr
)
3850 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3852 /* If this breakpoint has custom print function,
3853 it's already printed. Otherwise, print individual
3854 locations, if any. */
3855 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3857 /* If breakpoint has a single location that is
3858 disabled, we print it as if it had
3859 several locations, since otherwise it's hard to
3860 represent "breakpoint enabled, location disabled"
3862 Note that while hardware watchpoints have
3863 several locations internally, that's no a property
3866 && !is_hardware_watchpoint (b
)
3867 && (b
->loc
->next
|| !b
->loc
->enabled
)
3868 && !ui_out_is_mi_like_p (uiout
))
3870 struct bp_location
*loc
;
3872 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3873 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3879 struct captured_breakpoint_query_args
3885 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3887 struct captured_breakpoint_query_args
*args
= data
;
3888 struct breakpoint
*b
;
3889 CORE_ADDR dummy_addr
= 0;
3892 if (args
->bnum
== b
->number
)
3894 print_one_breakpoint (b
, &dummy_addr
);
3902 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3904 struct captured_breakpoint_query_args args
;
3906 /* For the moment we don't trust print_one_breakpoint() to not throw
3908 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3909 error_message
, RETURN_MASK_ALL
) < 0)
3915 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3916 catchpoints, et.al.). */
3919 user_settable_breakpoint (const struct breakpoint
*b
)
3921 return (b
->type
== bp_breakpoint
3922 || b
->type
== bp_catch_load
3923 || b
->type
== bp_catch_unload
3924 || b
->type
== bp_catch_fork
3925 || b
->type
== bp_catch_vfork
3926 || b
->type
== bp_catch_exec
3927 || b
->type
== bp_hardware_breakpoint
3928 || b
->type
== bp_watchpoint
3929 || b
->type
== bp_read_watchpoint
3930 || b
->type
== bp_access_watchpoint
3931 || b
->type
== bp_hardware_watchpoint
);
3934 /* Print information on user settable breakpoint (watchpoint, etc)
3935 number BNUM. If BNUM is -1 print all user settable breakpoints.
3936 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3939 breakpoint_1 (int bnum
, int allflag
)
3941 struct breakpoint
*b
;
3942 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3943 int nr_printable_breakpoints
;
3944 struct cleanup
*bkpttbl_chain
;
3946 /* Compute the number of rows in the table. */
3947 nr_printable_breakpoints
= 0;
3950 || bnum
== b
->number
)
3952 if (allflag
|| user_settable_breakpoint (b
))
3953 nr_printable_breakpoints
++;
3958 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3962 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3965 if (nr_printable_breakpoints
> 0)
3966 annotate_breakpoints_headers ();
3967 if (nr_printable_breakpoints
> 0)
3969 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3970 if (nr_printable_breakpoints
> 0)
3972 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3973 if (nr_printable_breakpoints
> 0)
3975 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3976 if (nr_printable_breakpoints
> 0)
3978 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3981 if (nr_printable_breakpoints
> 0)
3983 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3984 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3986 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3988 if (nr_printable_breakpoints
> 0)
3990 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3991 ui_out_table_body (uiout
);
3992 if (nr_printable_breakpoints
> 0)
3993 annotate_breakpoints_table ();
3997 || bnum
== b
->number
)
3999 /* We only print out user settable breakpoints unless the
4001 if (allflag
|| user_settable_breakpoint (b
))
4002 print_one_breakpoint (b
, &last_addr
);
4005 do_cleanups (bkpttbl_chain
);
4007 if (nr_printable_breakpoints
== 0)
4010 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
4012 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
4017 /* Compare against (CORE_ADDR)-1 in case some compiler decides
4018 that a comparison of an unsigned with -1 is always false. */
4019 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
4020 set_next_address (last_addr
);
4023 /* FIXME? Should this be moved up so that it is only called when
4024 there have been breakpoints? */
4025 annotate_breakpoints_table_end ();
4029 breakpoints_info (char *bnum_exp
, int from_tty
)
4034 bnum
= parse_and_eval_long (bnum_exp
);
4036 breakpoint_1 (bnum
, 0);
4040 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4045 bnum
= parse_and_eval_long (bnum_exp
);
4047 breakpoint_1 (bnum
, 1);
4051 breakpoint_has_pc (struct breakpoint
*b
, CORE_ADDR pc
, asection
*section
)
4053 struct bp_location
*bl
= b
->loc
;
4054 for (; bl
; bl
= bl
->next
)
4056 if (bl
->address
== pc
4057 && (!overlay_debugging
|| bl
->section
== section
))
4063 /* Print a message describing any breakpoints set at PC. */
4066 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
4069 struct breakpoint
*b
;
4072 others
+= breakpoint_has_pc (b
, pc
, section
);
4076 printf_filtered (_("Note: breakpoint "));
4077 else /* if (others == ???) */
4078 printf_filtered (_("Note: breakpoints "));
4080 if (breakpoint_has_pc (b
, pc
, section
))
4083 printf_filtered ("%d", b
->number
);
4084 if (b
->thread
== -1 && thread
!= -1)
4085 printf_filtered (" (all threads)");
4086 else if (b
->thread
!= -1)
4087 printf_filtered (" (thread %d)", b
->thread
);
4088 printf_filtered ("%s%s ",
4089 ((b
->enable_state
== bp_disabled
||
4090 b
->enable_state
== bp_call_disabled
)
4092 : b
->enable_state
== bp_permanent
4096 : ((others
== 1) ? " and" : ""));
4098 printf_filtered (_("also set at pc "));
4099 fputs_filtered (paddress (pc
), gdb_stdout
);
4100 printf_filtered (".\n");
4104 /* Set the default place to put a breakpoint
4105 for the `break' command with no arguments. */
4108 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4111 default_breakpoint_valid
= valid
;
4112 default_breakpoint_address
= addr
;
4113 default_breakpoint_symtab
= symtab
;
4114 default_breakpoint_line
= line
;
4117 /* Return true iff it is meaningful to use the address member of
4118 BPT. For some breakpoint types, the address member is irrelevant
4119 and it makes no sense to attempt to compare it to other addresses
4120 (or use it for any other purpose either).
4122 More specifically, each of the following breakpoint types will always
4123 have a zero valued address and we don't want check_duplicates() to mark
4124 breakpoints of any of these types to be a duplicate of an actual
4125 breakpoint at address zero:
4128 bp_hardware_watchpoint
4130 bp_access_watchpoint
4136 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4138 enum bptype type
= bpt
->type
;
4140 return (type
!= bp_watchpoint
4141 && type
!= bp_hardware_watchpoint
4142 && type
!= bp_read_watchpoint
4143 && type
!= bp_access_watchpoint
4144 && type
!= bp_catch_exec
4145 && type
!= bp_catch_fork
4146 && type
!= bp_catch_vfork
);
4149 /* Rescan breakpoints at the same address and section as BPT,
4150 marking the first one as "first" and any others as "duplicates".
4151 This is so that the bpt instruction is only inserted once.
4152 If we have a permanent breakpoint at the same place as BPT, make
4153 that one the official one, and the rest as duplicates. */
4156 check_duplicates_for (CORE_ADDR address
, asection
*section
)
4158 struct bp_location
*b
;
4160 struct bp_location
*perm_bp
= 0;
4162 ALL_BP_LOCATIONS (b
)
4163 if (b
->owner
->enable_state
!= bp_disabled
4164 && b
->owner
->enable_state
!= bp_call_disabled
4166 && !b
->shlib_disabled
4167 && b
->address
== address
/* address / overlay match */
4168 && (!overlay_debugging
|| b
->section
== section
)
4169 && breakpoint_address_is_meaningful (b
->owner
))
4171 /* Have we found a permanent breakpoint? */
4172 if (b
->owner
->enable_state
== bp_permanent
)
4179 b
->duplicate
= count
> 1;
4182 /* If we found a permanent breakpoint at this address, go over the
4183 list again and declare all the other breakpoints there to be the
4187 perm_bp
->duplicate
= 0;
4189 /* Permanent breakpoint should always be inserted. */
4190 if (! perm_bp
->inserted
)
4191 internal_error (__FILE__
, __LINE__
,
4192 _("allegedly permanent breakpoint is not "
4193 "actually inserted"));
4195 ALL_BP_LOCATIONS (b
)
4198 if (b
->owner
->enable_state
!= bp_disabled
4199 && b
->owner
->enable_state
!= bp_call_disabled
4200 && b
->enabled
&& !b
->shlib_disabled
4201 && b
->address
== address
/* address / overlay match */
4202 && (!overlay_debugging
|| b
->section
== section
)
4203 && breakpoint_address_is_meaningful (b
->owner
))
4206 internal_error (__FILE__
, __LINE__
,
4207 _("another breakpoint was inserted on top of "
4208 "a permanent breakpoint"));
4217 check_duplicates (struct breakpoint
*bpt
)
4219 struct bp_location
*bl
= bpt
->loc
;
4221 if (! breakpoint_address_is_meaningful (bpt
))
4224 for (; bl
; bl
= bl
->next
)
4225 check_duplicates_for (bl
->address
, bl
->section
);
4229 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4230 int bnum
, int have_bnum
)
4235 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4236 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4238 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4239 bnum
, astr1
, astr2
);
4241 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4244 /* Adjust a breakpoint's address to account for architectural constraints
4245 on breakpoint placement. Return the adjusted address. Note: Very
4246 few targets require this kind of adjustment. For most targets,
4247 this function is simply the identity function. */
4250 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4252 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4254 /* Very few targets need any kind of breakpoint adjustment. */
4257 else if (bptype
== bp_watchpoint
4258 || bptype
== bp_hardware_watchpoint
4259 || bptype
== bp_read_watchpoint
4260 || bptype
== bp_access_watchpoint
4261 || bptype
== bp_catch_fork
4262 || bptype
== bp_catch_vfork
4263 || bptype
== bp_catch_exec
)
4265 /* Watchpoints and the various bp_catch_* eventpoints should not
4266 have their addresses modified. */
4271 CORE_ADDR adjusted_bpaddr
;
4273 /* Some targets have architectural constraints on the placement
4274 of breakpoint instructions. Obtain the adjusted address. */
4275 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4278 /* An adjusted breakpoint address can significantly alter
4279 a user's expectations. Print a warning if an adjustment
4281 if (adjusted_bpaddr
!= bpaddr
)
4282 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4284 return adjusted_bpaddr
;
4288 /* Allocate a struct bp_location. */
4290 static struct bp_location
*
4291 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4293 struct bp_location
*loc
, *loc_p
;
4295 loc
= xmalloc (sizeof (struct bp_location
));
4296 memset (loc
, 0, sizeof (*loc
));
4300 loc
->shlib_disabled
= 0;
4309 case bp_longjmp_resume
:
4310 case bp_step_resume
:
4311 case bp_watchpoint_scope
:
4313 case bp_shlib_event
:
4314 case bp_thread_event
:
4315 case bp_overlay_event
:
4317 case bp_catch_unload
:
4318 loc
->loc_type
= bp_loc_software_breakpoint
;
4320 case bp_hardware_breakpoint
:
4321 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4323 case bp_hardware_watchpoint
:
4324 case bp_read_watchpoint
:
4325 case bp_access_watchpoint
:
4326 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4330 case bp_catch_vfork
:
4332 loc
->loc_type
= bp_loc_other
;
4335 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4341 static void free_bp_location (struct bp_location
*loc
)
4346 if (loc
->function_name
)
4347 xfree (loc
->function_name
);
4352 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4353 that has type BPTYPE and has no locations as yet. */
4355 static struct breakpoint
*
4356 set_raw_breakpoint_without_location (enum bptype bptype
)
4358 struct breakpoint
*b
, *b1
;
4360 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4361 memset (b
, 0, sizeof (*b
));
4364 b
->language
= current_language
->la_language
;
4365 b
->input_radix
= input_radix
;
4367 b
->enable_state
= bp_enabled
;
4370 b
->ignore_count
= 0;
4372 b
->frame_id
= null_frame_id
;
4373 b
->dll_pathname
= NULL
;
4374 b
->triggered_dll_pathname
= NULL
;
4375 b
->forked_inferior_pid
= null_ptid
;
4376 b
->exec_pathname
= NULL
;
4378 b
->condition_not_parsed
= 0;
4380 /* Add this breakpoint to the end of the chain
4381 so that a list of breakpoints will come out in order
4382 of increasing numbers. */
4384 b1
= breakpoint_chain
;
4386 breakpoint_chain
= b
;
4396 /* Initialize loc->function_name. */
4398 set_breakpoint_location_function (struct bp_location
*loc
)
4400 if (loc
->owner
->type
== bp_breakpoint
4401 || loc
->owner
->type
== bp_hardware_breakpoint
)
4403 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4405 if (loc
->function_name
)
4406 loc
->function_name
= xstrdup (loc
->function_name
);
4410 /* set_raw_breakpoint is a low level routine for allocating and
4411 partially initializing a breakpoint of type BPTYPE. The newly
4412 created breakpoint's address, section, source file name, and line
4413 number are provided by SAL. The newly created and partially
4414 initialized breakpoint is added to the breakpoint chain and
4415 is also returned as the value of this function.
4417 It is expected that the caller will complete the initialization of
4418 the newly created breakpoint struct as well as output any status
4419 information regarding the creation of a new breakpoint. In
4420 particular, set_raw_breakpoint does NOT set the breakpoint
4421 number! Care should be taken to not allow an error to occur
4422 prior to completing the initialization of the breakpoint. If this
4423 should happen, a bogus breakpoint will be left on the chain. */
4426 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4428 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4429 CORE_ADDR adjusted_address
;
4431 /* Adjust the breakpoint's address prior to allocating a location.
4432 Once we call allocate_bp_location(), that mostly uninitialized
4433 location will be placed on the location chain. Adjustment of the
4434 breakpoint may cause target_read_memory() to be called and we do
4435 not want its scan of the location chain to find a breakpoint and
4436 location that's only been partially initialized. */
4437 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4439 b
->loc
= allocate_bp_location (b
, bptype
);
4440 b
->loc
->requested_address
= sal
.pc
;
4441 b
->loc
->address
= adjusted_address
;
4443 if (sal
.symtab
== NULL
)
4444 b
->source_file
= NULL
;
4446 b
->source_file
= savestring (sal
.symtab
->filename
,
4447 strlen (sal
.symtab
->filename
));
4448 b
->loc
->section
= sal
.section
;
4449 b
->line_number
= sal
.line
;
4451 set_breakpoint_location_function (b
->loc
);
4453 breakpoints_changed ();
4459 /* Note that the breakpoint object B describes a permanent breakpoint
4460 instruction, hard-wired into the inferior's code. */
4462 make_breakpoint_permanent (struct breakpoint
*b
)
4464 struct bp_location
*bl
;
4465 b
->enable_state
= bp_permanent
;
4467 /* By definition, permanent breakpoints are already present in the code.
4468 Mark all locations as inserted. For now, make_breakpoint_permanent
4469 is called in just one place, so it's hard to say if it's reasonable
4470 to have permanent breakpoint with multiple locations or not,
4471 but it's easy to implmement. */
4472 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4476 static struct breakpoint
*
4477 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4479 static int internal_breakpoint_number
= -1;
4480 struct symtab_and_line sal
;
4481 struct breakpoint
*b
;
4483 init_sal (&sal
); /* initialize to zeroes */
4486 sal
.section
= find_pc_overlay (sal
.pc
);
4488 b
= set_raw_breakpoint (sal
, type
);
4489 b
->number
= internal_breakpoint_number
--;
4490 b
->disposition
= disp_donttouch
;
4497 create_longjmp_breakpoint (char *func_name
)
4499 struct minimal_symbol
*m
;
4501 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4503 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4504 update_global_location_list (1);
4507 /* Call this routine when stepping and nexting to enable a breakpoint
4508 if we do a longjmp(). When we hit that breakpoint, call
4509 set_longjmp_resume_breakpoint() to figure out where we are going. */
4512 set_longjmp_breakpoint (void)
4514 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4516 create_longjmp_breakpoint ("longjmp");
4517 create_longjmp_breakpoint ("_longjmp");
4518 create_longjmp_breakpoint ("siglongjmp");
4519 create_longjmp_breakpoint ("_siglongjmp");
4523 /* Delete all longjmp breakpoints from THREAD. */
4525 delete_longjmp_breakpoint (int thread
)
4527 struct breakpoint
*b
, *temp
;
4529 ALL_BREAKPOINTS_SAFE (b
, temp
)
4530 if (b
->type
== bp_longjmp
)
4532 if (b
->thread
== thread
)
4533 delete_breakpoint (b
);
4538 create_overlay_event_breakpoint_1 (char *func_name
, struct objfile
*objfile
)
4540 struct breakpoint
*b
;
4541 struct minimal_symbol
*m
;
4543 if ((m
= lookup_minimal_symbol_text (func_name
, objfile
)) == NULL
)
4546 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4548 b
->addr_string
= xstrdup (func_name
);
4550 if (overlay_debugging
== ovly_auto
)
4552 b
->enable_state
= bp_enabled
;
4553 overlay_events_enabled
= 1;
4557 b
->enable_state
= bp_disabled
;
4558 overlay_events_enabled
= 0;
4560 update_global_location_list (1);
4564 create_overlay_event_breakpoint (char *func_name
)
4566 struct objfile
*objfile
;
4567 ALL_OBJFILES (objfile
)
4568 create_overlay_event_breakpoint_1 (func_name
, objfile
);
4572 enable_overlay_breakpoints (void)
4574 struct breakpoint
*b
;
4577 if (b
->type
== bp_overlay_event
)
4579 b
->enable_state
= bp_enabled
;
4580 update_global_location_list (1);
4581 overlay_events_enabled
= 1;
4586 disable_overlay_breakpoints (void)
4588 struct breakpoint
*b
;
4591 if (b
->type
== bp_overlay_event
)
4593 b
->enable_state
= bp_disabled
;
4594 update_global_location_list (0);
4595 overlay_events_enabled
= 0;
4600 create_thread_event_breakpoint (CORE_ADDR address
)
4602 struct breakpoint
*b
;
4604 b
= create_internal_breakpoint (address
, bp_thread_event
);
4606 b
->enable_state
= bp_enabled
;
4607 /* addr_string has to be used or breakpoint_re_set will delete me. */
4608 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4610 update_global_location_list_nothrow (1);
4616 remove_thread_event_breakpoints (void)
4618 struct breakpoint
*b
, *temp
;
4620 ALL_BREAKPOINTS_SAFE (b
, temp
)
4621 if (b
->type
== bp_thread_event
)
4622 delete_breakpoint (b
);
4625 struct captured_parse_breakpoint_args
4628 struct symtabs_and_lines
*sals_p
;
4629 char ***addr_string_p
;
4633 struct lang_and_radix
4641 remove_solib_event_breakpoints (void)
4643 struct breakpoint
*b
, *temp
;
4645 ALL_BREAKPOINTS_SAFE (b
, temp
)
4646 if (b
->type
== bp_shlib_event
)
4647 delete_breakpoint (b
);
4651 create_solib_event_breakpoint (CORE_ADDR address
)
4653 struct breakpoint
*b
;
4655 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4656 update_global_location_list_nothrow (1);
4660 /* Disable any breakpoints that are on code in shared libraries. Only
4661 apply to enabled breakpoints, disabled ones can just stay disabled. */
4664 disable_breakpoints_in_shlibs (void)
4666 struct bp_location
*loc
;
4667 int disabled_shlib_breaks
= 0;
4669 ALL_BP_LOCATIONS (loc
)
4671 struct breakpoint
*b
= loc
->owner
;
4672 /* We apply the check to all breakpoints, including disabled
4673 for those with loc->duplicate set. This is so that when breakpoint
4674 becomes enabled, or the duplicate is removed, gdb will try to insert
4675 all breakpoints. If we don't set shlib_disabled here, we'll try
4676 to insert those breakpoints and fail. */
4677 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4678 && !loc
->shlib_disabled
4680 && PC_SOLIB (loc
->address
)
4682 && solib_address (loc
->address
)
4686 loc
->shlib_disabled
= 1;
4691 /* Disable any breakpoints that are in in an unloaded shared library. Only
4692 apply to enabled breakpoints, disabled ones can just stay disabled. */
4695 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4697 struct bp_location
*loc
;
4698 int disabled_shlib_breaks
= 0;
4700 ALL_BP_LOCATIONS (loc
)
4702 struct breakpoint
*b
= loc
->owner
;
4703 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4704 || loc
->loc_type
== bp_loc_software_breakpoint
)
4705 && !loc
->shlib_disabled
)
4708 char *so_name
= PC_SOLIB (loc
->address
);
4710 char *so_name
= solib_address (loc
->address
);
4712 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4714 loc
->shlib_disabled
= 1;
4715 /* At this point, we cannot rely on remove_breakpoint
4716 succeeding so we must mark the breakpoint as not inserted
4717 to prevent future errors occurring in remove_breakpoints. */
4719 if (!disabled_shlib_breaks
)
4721 target_terminal_ours_for_output ();
4722 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4725 disabled_shlib_breaks
= 1;
4732 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4733 enum bptype bp_kind
)
4735 struct symtab_and_line sal
;
4736 struct breakpoint
*b
;
4737 int thread
= -1; /* All threads. */
4744 b
= set_raw_breakpoint (sal
, bp_kind
);
4745 set_breakpoint_count (breakpoint_count
+ 1);
4746 b
->number
= breakpoint_count
;
4747 b
->cond_string
= (cond_string
== NULL
) ?
4748 NULL
: savestring (cond_string
, strlen (cond_string
));
4750 b
->addr_string
= NULL
;
4751 b
->enable_state
= bp_enabled
;
4752 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4753 b
->forked_inferior_pid
= null_ptid
;
4754 update_global_location_list (1);
4761 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4763 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4767 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4769 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4773 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4775 struct symtab_and_line sal
;
4776 struct breakpoint
*b
;
4777 int thread
= -1; /* All threads. */
4784 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4785 set_breakpoint_count (breakpoint_count
+ 1);
4786 b
->number
= breakpoint_count
;
4787 b
->cond_string
= (cond_string
== NULL
) ?
4788 NULL
: savestring (cond_string
, strlen (cond_string
));
4790 b
->addr_string
= NULL
;
4791 b
->enable_state
= bp_enabled
;
4792 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4793 update_global_location_list (1);
4799 hw_breakpoint_used_count (void)
4801 struct breakpoint
*b
;
4806 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
4814 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4816 struct breakpoint
*b
;
4819 *other_type_used
= 0;
4822 if (breakpoint_enabled (b
))
4824 if (b
->type
== type
)
4826 else if ((b
->type
== bp_hardware_watchpoint
||
4827 b
->type
== bp_read_watchpoint
||
4828 b
->type
== bp_access_watchpoint
))
4829 *other_type_used
= 1;
4836 disable_watchpoints_before_interactive_call_start (void)
4838 struct breakpoint
*b
;
4842 if (((b
->type
== bp_watchpoint
)
4843 || (b
->type
== bp_hardware_watchpoint
)
4844 || (b
->type
== bp_read_watchpoint
)
4845 || (b
->type
== bp_access_watchpoint
))
4846 && breakpoint_enabled (b
))
4848 b
->enable_state
= bp_call_disabled
;
4849 update_global_location_list (0);
4855 enable_watchpoints_after_interactive_call_stop (void)
4857 struct breakpoint
*b
;
4861 if (((b
->type
== bp_watchpoint
)
4862 || (b
->type
== bp_hardware_watchpoint
)
4863 || (b
->type
== bp_read_watchpoint
)
4864 || (b
->type
== bp_access_watchpoint
))
4865 && (b
->enable_state
== bp_call_disabled
))
4867 b
->enable_state
= bp_enabled
;
4868 update_global_location_list (1);
4874 /* Set a breakpoint that will evaporate an end of command
4875 at address specified by SAL.
4876 Restrict it to frame FRAME if FRAME is nonzero. */
4879 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4882 struct breakpoint
*b
;
4883 b
= set_raw_breakpoint (sal
, type
);
4884 b
->enable_state
= bp_enabled
;
4885 b
->disposition
= disp_donttouch
;
4886 b
->frame_id
= frame_id
;
4888 /* If we're debugging a multi-threaded program, then we
4889 want momentary breakpoints to be active in only a
4890 single thread of control. */
4891 if (in_thread_list (inferior_ptid
))
4892 b
->thread
= pid_to_thread_id (inferior_ptid
);
4894 update_global_location_list_nothrow (1);
4900 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
4902 struct symtab_and_line sal
;
4904 sal
= find_pc_line (pc
, 0);
4906 sal
.section
= find_pc_overlay (pc
);
4907 sal
.explicit_pc
= 1;
4909 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
4913 /* Tell the user we have just set a breakpoint B. */
4916 mention (struct breakpoint
*b
)
4919 struct cleanup
*old_chain
, *ui_out_chain
;
4920 struct ui_stream
*stb
;
4922 stb
= ui_out_stream_new (uiout
);
4923 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4925 /* FIXME: This is misplaced; mention() is called by things (like
4926 hitting a watchpoint) other than breakpoint creation. It should
4927 be possible to clean this up and at the same time replace the
4928 random calls to breakpoint_changed with this hook. */
4929 observer_notify_breakpoint_created (b
->number
);
4931 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4932 b
->ops
->print_mention (b
);
4937 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4940 ui_out_text (uiout
, "Watchpoint ");
4941 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4942 ui_out_field_int (uiout
, "number", b
->number
);
4943 ui_out_text (uiout
, ": ");
4944 print_expression (b
->exp
, stb
->stream
);
4945 ui_out_field_stream (uiout
, "exp", stb
);
4946 do_cleanups (ui_out_chain
);
4948 case bp_hardware_watchpoint
:
4949 ui_out_text (uiout
, "Hardware watchpoint ");
4950 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4951 ui_out_field_int (uiout
, "number", b
->number
);
4952 ui_out_text (uiout
, ": ");
4953 print_expression (b
->exp
, stb
->stream
);
4954 ui_out_field_stream (uiout
, "exp", stb
);
4955 do_cleanups (ui_out_chain
);
4957 case bp_read_watchpoint
:
4958 ui_out_text (uiout
, "Hardware read watchpoint ");
4959 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4960 ui_out_field_int (uiout
, "number", b
->number
);
4961 ui_out_text (uiout
, ": ");
4962 print_expression (b
->exp
, stb
->stream
);
4963 ui_out_field_stream (uiout
, "exp", stb
);
4964 do_cleanups (ui_out_chain
);
4966 case bp_access_watchpoint
:
4967 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4968 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4969 ui_out_field_int (uiout
, "number", b
->number
);
4970 ui_out_text (uiout
, ": ");
4971 print_expression (b
->exp
, stb
->stream
);
4972 ui_out_field_stream (uiout
, "exp", stb
);
4973 do_cleanups (ui_out_chain
);
4976 if (ui_out_is_mi_like_p (uiout
))
4981 if (b
->disposition
== disp_del
)
4982 printf_filtered (_("Temporary breakpoint"));
4984 printf_filtered (_("Breakpoint"));
4985 printf_filtered (_(" %d"), b
->number
);
4988 case bp_hardware_breakpoint
:
4989 if (ui_out_is_mi_like_p (uiout
))
4994 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4998 case bp_catch_unload
:
4999 printf_filtered (_("Catchpoint %d (%s %s)"),
5001 (b
->type
== bp_catch_load
) ? "load" : "unload",
5002 (b
->dll_pathname
!= NULL
) ?
5003 b
->dll_pathname
: "<any library>");
5006 case bp_catch_vfork
:
5007 printf_filtered (_("Catchpoint %d (%s)"),
5009 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
5012 printf_filtered (_("Catchpoint %d (exec)"),
5019 case bp_longjmp_resume
:
5020 case bp_step_resume
:
5022 case bp_watchpoint_scope
:
5023 case bp_shlib_event
:
5024 case bp_thread_event
:
5025 case bp_overlay_event
:
5031 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5035 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5039 if (addressprint
|| b
->source_file
== NULL
)
5041 printf_filtered (" at ");
5042 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5045 printf_filtered (": file %s, line %d.",
5046 b
->source_file
, b
->line_number
);
5050 struct bp_location
*loc
= b
->loc
;
5052 for (; loc
; loc
= loc
->next
)
5054 printf_filtered (" (%d locations)", n
);
5059 do_cleanups (old_chain
);
5060 if (ui_out_is_mi_like_p (uiout
))
5062 printf_filtered ("\n");
5066 static struct bp_location
*
5067 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5068 const struct symtab_and_line
*sal
)
5070 struct bp_location
*loc
, **tmp
;
5072 loc
= allocate_bp_location (b
, bptype
);
5073 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5076 loc
->requested_address
= sal
->pc
;
5077 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5079 loc
->section
= sal
->section
;
5081 set_breakpoint_location_function (loc
);
5085 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5086 as textual description of the location, and COND_STRING
5087 as condition expression. */
5090 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5092 enum bptype type
, enum bpdisp disposition
,
5093 int thread
, int ignore_count
,
5094 struct breakpoint_ops
*ops
, int from_tty
)
5096 struct breakpoint
*b
= NULL
;
5099 if (type
== bp_hardware_breakpoint
)
5101 int i
= hw_breakpoint_used_count ();
5102 int target_resources_ok
=
5103 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5105 if (target_resources_ok
== 0)
5106 error (_("No hardware breakpoint support in the target."));
5107 else if (target_resources_ok
< 0)
5108 error (_("Hardware breakpoints used exceeds limit."));
5111 for (i
= 0; i
< sals
.nelts
; ++i
)
5113 struct symtab_and_line sal
= sals
.sals
[i
];
5114 struct bp_location
*loc
;
5117 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5121 b
= set_raw_breakpoint (sal
, type
);
5122 set_breakpoint_count (breakpoint_count
+ 1);
5123 b
->number
= breakpoint_count
;
5126 b
->cond_string
= cond_string
;
5127 b
->ignore_count
= ignore_count
;
5128 b
->enable_state
= bp_enabled
;
5129 b
->disposition
= disposition
;
5135 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5140 char *arg
= b
->cond_string
;
5141 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5143 error (_("Garbage %s follows condition"), arg
);
5148 b
->addr_string
= addr_string
;
5150 /* addr_string has to be used or breakpoint_re_set will delete
5152 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5158 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5159 elements to fill the void space. */
5160 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5162 int i
= index_to_remove
+1;
5163 int last_index
= sal
->nelts
-1;
5165 for (;i
<= last_index
; ++i
)
5166 sal
->sals
[i
-1] = sal
->sals
[i
];
5171 /* If appropriate, obtains all sals that correspond
5172 to the same file and line as SAL. This is done
5173 only if SAL does not have explicit PC and has
5174 line and file information. If we got just a single
5175 expanded sal, return the original.
5177 Otherwise, if SAL.explicit_line is not set, filter out
5178 all sals for which the name of enclosing function
5179 is different from SAL. This makes sure that if we have
5180 breakpoint originally set in template instantiation, say
5181 foo<int>(), we won't expand SAL to locations at the same
5182 line in all existing instantiations of 'foo'.
5185 struct symtabs_and_lines
5186 expand_line_sal_maybe (struct symtab_and_line sal
)
5188 struct symtabs_and_lines expanded
;
5189 CORE_ADDR original_pc
= sal
.pc
;
5190 char *original_function
= NULL
;
5194 /* If we have explicit pc, don't expand.
5195 If we have no line number, we can't expand. */
5196 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5199 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5200 expanded
.sals
[0] = sal
;
5205 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5207 expanded
= expand_line_sal (sal
);
5208 if (expanded
.nelts
== 1)
5210 /* We had one sal, we got one sal. Without futher
5211 processing, just return the original sal. */
5212 xfree (expanded
.sals
);
5214 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5215 sal
.pc
= original_pc
;
5216 expanded
.sals
[0] = sal
;
5220 if (!sal
.explicit_line
)
5222 CORE_ADDR func_addr
, func_end
;
5223 for (i
= 0; i
< expanded
.nelts
; ++i
)
5225 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5226 char *this_function
;
5227 if (find_pc_partial_function (pc
, &this_function
,
5228 &func_addr
, &func_end
))
5230 if (this_function
&&
5231 strcmp (this_function
, original_function
) != 0)
5233 remove_sal (&expanded
, i
);
5236 else if (func_addr
== pc
)
5238 /* We're at beginning of a function, and should
5240 struct symbol
*sym
= find_pc_function (pc
);
5242 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5245 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5252 if (expanded
.nelts
<= 1)
5254 /* This is un ugly workaround. If we get zero
5255 expanded sals then something is really wrong.
5256 Fix that by returnign the original sal. */
5257 xfree (expanded
.sals
);
5259 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5260 sal
.pc
= original_pc
;
5261 expanded
.sals
[0] = sal
;
5268 for (i
= 0; i
< expanded
.nelts
; ++i
)
5269 if (expanded
.sals
[i
].pc
== original_pc
)
5280 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5281 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5282 value. COND_STRING, if not NULL, specified the condition to be
5283 used for all breakpoints. Essentially the only case where
5284 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5285 function. In that case, it's still not possible to specify
5286 separate conditions for different overloaded functions, so
5287 we take just a single condition string.
5289 NOTE: If the function succeeds, the caller is expected to cleanup
5290 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5291 array contents). If the function fails (error() is called), the
5292 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5293 COND and SALS arrays and each of those arrays contents. */
5296 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5298 enum bptype type
, enum bpdisp disposition
,
5299 int thread
, int ignore_count
,
5300 struct breakpoint_ops
*ops
, int from_tty
)
5303 for (i
= 0; i
< sals
.nelts
; ++i
)
5305 struct symtabs_and_lines expanded
=
5306 expand_line_sal_maybe (sals
.sals
[i
]);
5308 create_breakpoint (expanded
, addr_string
[i
],
5309 cond_string
, type
, disposition
,
5310 thread
, ignore_count
, ops
, from_tty
);
5313 update_global_location_list (1);
5316 /* Parse ARG which is assumed to be a SAL specification possibly
5317 followed by conditionals. On return, SALS contains an array of SAL
5318 addresses found. ADDR_STRING contains a vector of (canonical)
5319 address strings. ARG points to the end of the SAL. */
5322 parse_breakpoint_sals (char **address
,
5323 struct symtabs_and_lines
*sals
,
5324 char ***addr_string
,
5327 char *addr_start
= *address
;
5328 *addr_string
= NULL
;
5329 /* If no arg given, or if first arg is 'if ', use the default
5331 if ((*address
) == NULL
5332 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5334 if (default_breakpoint_valid
)
5336 struct symtab_and_line sal
;
5337 init_sal (&sal
); /* initialize to zeroes */
5338 sals
->sals
= (struct symtab_and_line
*)
5339 xmalloc (sizeof (struct symtab_and_line
));
5340 sal
.pc
= default_breakpoint_address
;
5341 sal
.line
= default_breakpoint_line
;
5342 sal
.symtab
= default_breakpoint_symtab
;
5343 sal
.section
= find_pc_overlay (sal
.pc
);
5344 sals
->sals
[0] = sal
;
5348 error (_("No default breakpoint address now."));
5352 /* Force almost all breakpoints to be in terms of the
5353 current_source_symtab (which is decode_line_1's default). This
5354 should produce the results we want almost all of the time while
5355 leaving default_breakpoint_* alone.
5356 ObjC: However, don't match an Objective-C method name which
5357 may have a '+' or '-' succeeded by a '[' */
5359 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5361 if (default_breakpoint_valid
5363 || ((strchr ("+-", (*address
)[0]) != NULL
)
5364 && ((*address
)[1] != '['))))
5365 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5366 default_breakpoint_line
, addr_string
,
5369 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5370 addr_string
, not_found_ptr
);
5372 /* For any SAL that didn't have a canonical string, fill one in. */
5373 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5374 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5375 if (addr_start
!= (*address
))
5378 for (i
= 0; i
< sals
->nelts
; i
++)
5380 /* Add the string if not present. */
5381 if ((*addr_string
)[i
] == NULL
)
5382 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5388 /* Convert each SAL into a real PC. Verify that the PC can be
5389 inserted as a breakpoint. If it can't throw an error. */
5392 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5396 for (i
= 0; i
< sals
->nelts
; i
++)
5397 resolve_sal_pc (&sals
->sals
[i
]);
5401 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5403 struct captured_parse_breakpoint_args
*args
= data
;
5405 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5406 args
->not_found_ptr
);
5409 /* Given TOK, a string specification of condition and thread, as
5410 accepted by the 'break' command, extract the condition
5411 string and thread number and set *COND_STRING and *THREAD.
5412 PC identifies the context at which the condition should be parsed.
5413 If no condition is found, *COND_STRING is set to NULL.
5414 If no thread is found, *THREAD is set to -1. */
5416 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5417 char **cond_string
, int *thread
)
5419 *cond_string
= NULL
;
5425 char *cond_start
= NULL
;
5426 char *cond_end
= NULL
;
5427 while (*tok
== ' ' || *tok
== '\t')
5432 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5435 toklen
= end_tok
- tok
;
5437 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5439 tok
= cond_start
= end_tok
+ 1;
5440 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5442 *cond_string
= savestring (cond_start
,
5443 cond_end
- cond_start
);
5445 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5451 *thread
= strtol (tok
, &tok
, 0);
5453 error (_("Junk after thread keyword."));
5454 if (!valid_thread_id (*thread
))
5455 error (_("Unknown thread %d."), *thread
);
5458 error (_("Junk at end of arguments."));
5462 /* Set a breakpoint. This function is shared between
5463 CLI and MI functions for setting a breakpoint.
5464 This function has two major modes of operations,
5465 selected by the PARSE_CONDITION_AND_THREAD parameter.
5466 If non-zero, the function will parse arg, extracting
5467 breakpoint location, address and thread. Otherwise,
5468 ARG is just the location of breakpoint, with condition
5469 and thread specified by the COND_STRING and THREAD
5473 break_command_really (char *arg
, char *cond_string
, int thread
,
5474 int parse_condition_and_thread
,
5475 int tempflag
, int hardwareflag
,
5477 enum auto_boolean pending_break_support
,
5478 struct breakpoint_ops
*ops
,
5481 struct gdb_exception e
;
5482 struct symtabs_and_lines sals
;
5483 struct symtab_and_line pending_sal
;
5486 char *addr_start
= arg
;
5488 struct cleanup
*old_chain
;
5489 struct cleanup
*breakpoint_chain
= NULL
;
5490 struct captured_parse_breakpoint_args parse_args
;
5499 parse_args
.arg_p
= &arg
;
5500 parse_args
.sals_p
= &sals
;
5501 parse_args
.addr_string_p
= &addr_string
;
5502 parse_args
.not_found_ptr
= ¬_found
;
5504 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5505 &parse_args
, RETURN_MASK_ALL
);
5507 /* If caller is interested in rc value from parse, set value. */
5511 throw_exception (e
);
5515 case NOT_FOUND_ERROR
:
5517 /* If pending breakpoint support is turned off, throw
5520 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5521 throw_exception (e
);
5523 exception_print (gdb_stderr
, e
);
5525 /* If pending breakpoint support is auto query and the user
5526 selects no, then simply return the error code. */
5527 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5528 !nquery ("Make breakpoint pending on future shared library load? "))
5531 /* At this point, either the user was queried about setting
5532 a pending breakpoint and selected yes, or pending
5533 breakpoint behavior is on and thus a pending breakpoint
5534 is defaulted on behalf of the user. */
5535 copy_arg
= xstrdup (addr_start
);
5536 addr_string
= ©_arg
;
5538 sals
.sals
= &pending_sal
;
5543 throw_exception (e
);
5550 /* Create a chain of things that always need to be cleaned up. */
5551 old_chain
= make_cleanup (null_cleanup
, 0);
5555 /* Make sure that all storage allocated to SALS gets freed. */
5556 make_cleanup (xfree
, sals
.sals
);
5558 /* Cleanup the addr_string array but not its contents. */
5559 make_cleanup (xfree
, addr_string
);
5562 /* ----------------------------- SNIP -----------------------------
5563 Anything added to the cleanup chain beyond this point is assumed
5564 to be part of a breakpoint. If the breakpoint create succeeds
5565 then the memory is not reclaimed. */
5566 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5568 /* Mark the contents of the addr_string for cleanup. These go on
5569 the breakpoint_chain and only occure if the breakpoint create
5571 for (i
= 0; i
< sals
.nelts
; i
++)
5573 if (addr_string
[i
] != NULL
)
5574 make_cleanup (xfree
, addr_string
[i
]);
5577 /* Resolve all line numbers to PC's and verify that the addresses
5578 are ok for the target. */
5580 breakpoint_sals_to_pc (&sals
, addr_start
);
5582 /* Verify that condition can be parsed, before setting any
5583 breakpoints. Allocate a separate condition expression for each
5587 if (parse_condition_and_thread
)
5589 /* Here we only parse 'arg' to separate condition
5590 from thread number, so parsing in context of first
5591 sal is OK. When setting the breakpoint we'll
5592 re-parse it in context of each sal. */
5595 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5597 make_cleanup (xfree
, cond_string
);
5601 /* Create a private copy of condition string. */
5604 cond_string
= xstrdup (cond_string
);
5605 make_cleanup (xfree
, cond_string
);
5608 create_breakpoints (sals
, addr_string
, cond_string
,
5609 hardwareflag
? bp_hardware_breakpoint
5611 tempflag
? disp_del
: disp_donttouch
,
5612 thread
, ignore_count
, ops
, from_tty
);
5616 struct symtab_and_line sal
= {0};
5617 struct breakpoint
*b
;
5619 make_cleanup (xfree
, copy_arg
);
5621 b
= set_raw_breakpoint_without_location (hardwareflag
5622 ? bp_hardware_breakpoint
5624 set_breakpoint_count (breakpoint_count
+ 1);
5625 b
->number
= breakpoint_count
;
5627 b
->addr_string
= addr_string
[0];
5628 b
->cond_string
= NULL
;
5629 b
->ignore_count
= ignore_count
;
5630 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5631 b
->condition_not_parsed
= 1;
5634 update_global_location_list (1);
5639 warning (_("Multiple breakpoints were set.\n"
5640 "Use the \"delete\" command to delete unwanted breakpoints."));
5641 /* That's it. Discard the cleanups for data inserted into the
5643 discard_cleanups (breakpoint_chain
);
5644 /* But cleanup everything else. */
5645 do_cleanups (old_chain
);
5648 /* Set a breakpoint.
5649 ARG is a string describing breakpoint address,
5650 condition, and thread.
5651 FLAG specifies if a breakpoint is hardware on,
5652 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5656 break_command_1 (char *arg
, int flag
, int from_tty
)
5658 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5659 int tempflag
= flag
& BP_TEMPFLAG
;
5661 break_command_really (arg
,
5662 NULL
, 0, 1 /* parse arg */,
5663 tempflag
, hardwareflag
,
5664 0 /* Ignore count */,
5665 pending_break_support
,
5666 NULL
/* breakpoint_ops */,
5672 set_breakpoint (char *address
, char *condition
,
5673 int hardwareflag
, int tempflag
,
5674 int thread
, int ignore_count
,
5677 break_command_really (address
, condition
, thread
,
5678 0 /* condition and thread are valid. */,
5679 tempflag
, hardwareflag
,
5682 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5686 /* Adjust SAL to the first instruction past the function prologue.
5687 The end of the prologue is determined using the line table from
5688 the debugging information.
5690 If SAL is already past the prologue, then do nothing. */
5693 skip_prologue_sal (struct symtab_and_line
*sal
)
5695 struct symbol
*sym
= find_pc_function (sal
->pc
);
5696 struct symtab_and_line start_sal
;
5701 start_sal
= find_function_start_sal (sym
, 1);
5702 if (sal
->pc
< start_sal
.pc
)
5706 /* Helper function for break_command_1 and disassemble_command. */
5709 resolve_sal_pc (struct symtab_and_line
*sal
)
5713 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5715 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5716 error (_("No line %d in file \"%s\"."),
5717 sal
->line
, sal
->symtab
->filename
);
5720 /* If this SAL corresponds to a breakpoint inserted using
5721 a line number, then skip the function prologue if necessary. */
5722 if (sal
->explicit_line
)
5723 skip_prologue_sal (sal
);
5726 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5728 struct blockvector
*bv
;
5732 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5735 sym
= block_linkage_function (b
);
5738 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5739 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5743 /* It really is worthwhile to have the section, so we'll just
5744 have to look harder. This case can be executed if we have
5745 line numbers but no functions (as can happen in assembly
5748 struct minimal_symbol
*msym
;
5750 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5752 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5759 break_command (char *arg
, int from_tty
)
5761 break_command_1 (arg
, 0, from_tty
);
5765 tbreak_command (char *arg
, int from_tty
)
5767 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5771 hbreak_command (char *arg
, int from_tty
)
5773 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5777 thbreak_command (char *arg
, int from_tty
)
5779 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5783 stop_command (char *arg
, int from_tty
)
5785 printf_filtered (_("Specify the type of breakpoint to set.\n\
5786 Usage: stop in <function | address>\n\
5787 stop at <line>\n"));
5791 stopin_command (char *arg
, int from_tty
)
5795 if (arg
== (char *) NULL
)
5797 else if (*arg
!= '*')
5802 /* look for a ':'. If this is a line number specification, then
5803 say it is bad, otherwise, it should be an address or
5804 function/method name */
5805 while (*argptr
&& !hasColon
)
5807 hasColon
= (*argptr
== ':');
5812 badInput
= (*argptr
!= ':'); /* Not a class::method */
5814 badInput
= isdigit (*arg
); /* a simple line number */
5818 printf_filtered (_("Usage: stop in <function | address>\n"));
5820 break_command_1 (arg
, 0, from_tty
);
5824 stopat_command (char *arg
, int from_tty
)
5828 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5835 /* look for a ':'. If there is a '::' then get out, otherwise
5836 it is probably a line number. */
5837 while (*argptr
&& !hasColon
)
5839 hasColon
= (*argptr
== ':');
5844 badInput
= (*argptr
== ':'); /* we have class::method */
5846 badInput
= !isdigit (*arg
); /* not a line number */
5850 printf_filtered (_("Usage: stop at <line>\n"));
5852 break_command_1 (arg
, 0, from_tty
);
5855 /* accessflag: hw_write: watch write,
5856 hw_read: watch read,
5857 hw_access: watch access (read or write) */
5859 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5861 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5862 struct symtab_and_line sal
;
5863 struct expression
*exp
;
5864 struct block
*exp_valid_block
;
5865 struct value
*val
, *mark
;
5866 struct frame_info
*frame
;
5867 struct frame_info
*prev_frame
= NULL
;
5868 char *exp_start
= NULL
;
5869 char *exp_end
= NULL
;
5870 char *tok
, *id_tok_start
, *end_tok
;
5872 char *cond_start
= NULL
;
5873 char *cond_end
= NULL
;
5874 struct expression
*cond
= NULL
;
5875 int i
, other_type_used
, target_resources_ok
= 0;
5876 enum bptype bp_type
;
5880 init_sal (&sal
); /* initialize to zeroes */
5882 /* Make sure that we actually have parameters to parse. */
5883 if (arg
!= NULL
&& arg
[0] != '\0')
5885 toklen
= strlen (arg
); /* Size of argument list. */
5887 /* Points tok to the end of the argument list. */
5888 tok
= arg
+ toklen
- 1;
5890 /* Go backwards in the parameters list. Skip the last parameter.
5891 If we're expecting a 'thread <thread_num>' parameter, this should
5892 be the thread identifier. */
5893 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5895 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5898 /* Points end_tok to the beginning of the last token. */
5899 id_tok_start
= tok
+ 1;
5901 /* Go backwards in the parameters list. Skip one more parameter.
5902 If we're expecting a 'thread <thread_num>' parameter, we should
5903 reach a "thread" token. */
5904 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5909 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5912 /* Move the pointer forward to skip the whitespace and
5913 calculate the length of the token. */
5915 toklen
= end_tok
- tok
;
5917 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5919 /* At this point we've found a "thread" token, which means
5920 the user is trying to set a watchpoint that triggers
5921 only in a specific thread. */
5924 /* Extract the thread ID from the next token. */
5925 thread
= strtol (id_tok_start
, &endp
, 0);
5927 /* Check if the user provided a valid numeric value for the
5929 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5930 error (_("Invalid thread ID specification %s."), id_tok_start
);
5932 /* Check if the thread actually exists. */
5933 if (!valid_thread_id (thread
))
5934 error (_("Unknown thread %d."), thread
);
5936 /* Truncate the string and get rid of the thread <thread_num>
5937 parameter before the parameter list is parsed by the
5938 evaluate_expression() function. */
5943 /* Parse the rest of the arguments. */
5944 innermost_block
= NULL
;
5946 exp
= parse_exp_1 (&arg
, 0, 0);
5948 exp_valid_block
= innermost_block
;
5949 mark
= value_mark ();
5950 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5952 release_value (val
);
5955 while (*tok
== ' ' || *tok
== '\t')
5959 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5962 toklen
= end_tok
- tok
;
5963 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5965 tok
= cond_start
= end_tok
+ 1;
5966 cond
= parse_exp_1 (&tok
, 0, 0);
5970 error (_("Junk at end of command."));
5972 if (accessflag
== hw_read
)
5973 bp_type
= bp_read_watchpoint
;
5974 else if (accessflag
== hw_access
)
5975 bp_type
= bp_access_watchpoint
;
5977 bp_type
= bp_hardware_watchpoint
;
5979 mem_cnt
= can_use_hardware_watchpoint (val
);
5980 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5981 error (_("Expression cannot be implemented with read/access watchpoint."));
5984 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5985 target_resources_ok
=
5986 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5988 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5989 error (_("Target does not support this type of hardware watchpoint."));
5991 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5992 error (_("Target can only support one kind of HW watchpoint at a time."));
5995 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5996 watchpoint could not be set. */
5997 if (!mem_cnt
|| target_resources_ok
<= 0)
5998 bp_type
= bp_watchpoint
;
6000 frame
= block_innermost_frame (exp_valid_block
);
6002 prev_frame
= get_prev_frame (frame
);
6006 /* If the expression is "local", then set up a "watchpoint scope"
6007 breakpoint at the point where we've left the scope of the watchpoint
6008 expression. Create the scope breakpoint before the watchpoint, so
6009 that we will encounter it first in bpstat_stop_status. */
6010 if (innermost_block
&& prev_frame
)
6012 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
6013 bp_watchpoint_scope
);
6015 scope_breakpoint
->enable_state
= bp_enabled
;
6017 /* Automatically delete the breakpoint when it hits. */
6018 scope_breakpoint
->disposition
= disp_del
;
6020 /* Only break in the proper frame (help with recursion). */
6021 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6023 /* Set the address at which we will stop. */
6024 scope_breakpoint
->loc
->requested_address
6025 = get_frame_pc (prev_frame
);
6026 scope_breakpoint
->loc
->address
6027 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6028 scope_breakpoint
->type
);
6031 /* Now set up the breakpoint. */
6032 b
= set_raw_breakpoint (sal
, bp_type
);
6033 set_breakpoint_count (breakpoint_count
+ 1);
6034 b
->number
= breakpoint_count
;
6036 b
->disposition
= disp_donttouch
;
6038 b
->exp_valid_block
= exp_valid_block
;
6039 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6042 b
->loc
->cond
= cond
;
6044 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6049 b
->watchpoint_frame
= get_frame_id (frame
);
6051 b
->watchpoint_frame
= null_frame_id
;
6053 if (scope_breakpoint
!= NULL
)
6055 /* The scope breakpoint is related to the watchpoint. We will
6056 need to act on them together. */
6057 b
->related_breakpoint
= scope_breakpoint
;
6058 scope_breakpoint
->related_breakpoint
= b
;
6061 value_free_to_mark (mark
);
6063 update_global_location_list (1);
6066 /* Return count of locations need to be watched and can be handled
6067 in hardware. If the watchpoint can not be handled
6068 in hardware return zero. */
6071 can_use_hardware_watchpoint (struct value
*v
)
6073 int found_memory_cnt
= 0;
6074 struct value
*head
= v
;
6076 /* Did the user specifically forbid us to use hardware watchpoints? */
6077 if (!can_use_hw_watchpoints
)
6080 /* Make sure that the value of the expression depends only upon
6081 memory contents, and values computed from them within GDB. If we
6082 find any register references or function calls, we can't use a
6083 hardware watchpoint.
6085 The idea here is that evaluating an expression generates a series
6086 of values, one holding the value of every subexpression. (The
6087 expression a*b+c has five subexpressions: a, b, a*b, c, and
6088 a*b+c.) GDB's values hold almost enough information to establish
6089 the criteria given above --- they identify memory lvalues,
6090 register lvalues, computed values, etcetera. So we can evaluate
6091 the expression, and then scan the chain of values that leaves
6092 behind to decide whether we can detect any possible change to the
6093 expression's final value using only hardware watchpoints.
6095 However, I don't think that the values returned by inferior
6096 function calls are special in any way. So this function may not
6097 notice that an expression involving an inferior function call
6098 can't be watched with hardware watchpoints. FIXME. */
6099 for (; v
; v
= value_next (v
))
6101 if (VALUE_LVAL (v
) == lval_memory
)
6104 /* A lazy memory lvalue is one that GDB never needed to fetch;
6105 we either just used its address (e.g., `a' in `a.b') or
6106 we never needed it at all (e.g., `a' in `a,b'). */
6110 /* Ahh, memory we actually used! Check if we can cover
6111 it with hardware watchpoints. */
6112 struct type
*vtype
= check_typedef (value_type (v
));
6114 /* We only watch structs and arrays if user asked for it
6115 explicitly, never if they just happen to appear in a
6116 middle of some value chain. */
6118 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6119 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6121 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6122 int len
= TYPE_LENGTH (value_type (v
));
6124 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6131 else if (VALUE_LVAL (v
) != not_lval
6132 && deprecated_value_modifiable (v
) == 0)
6133 return 0; /* ??? What does this represent? */
6134 else if (VALUE_LVAL (v
) == lval_register
)
6135 return 0; /* cannot watch a register with a HW watchpoint */
6138 /* The expression itself looks suitable for using a hardware
6139 watchpoint, but give the target machine a chance to reject it. */
6140 return found_memory_cnt
;
6144 watch_command_wrapper (char *arg
, int from_tty
)
6146 watch_command (arg
, from_tty
);
6150 watch_command (char *arg
, int from_tty
)
6152 watch_command_1 (arg
, hw_write
, from_tty
);
6156 rwatch_command_wrapper (char *arg
, int from_tty
)
6158 rwatch_command (arg
, from_tty
);
6162 rwatch_command (char *arg
, int from_tty
)
6164 watch_command_1 (arg
, hw_read
, from_tty
);
6168 awatch_command_wrapper (char *arg
, int from_tty
)
6170 awatch_command (arg
, from_tty
);
6174 awatch_command (char *arg
, int from_tty
)
6176 watch_command_1 (arg
, hw_access
, from_tty
);
6180 /* Helper routines for the until_command routine in infcmd.c. Here
6181 because it uses the mechanisms of breakpoints. */
6183 struct until_break_command_continuation_args
6185 struct breakpoint
*breakpoint
;
6186 struct breakpoint
*breakpoint2
;
6189 /* This function is called by fetch_inferior_event via the
6190 cmd_continuation pointer, to complete the until command. It takes
6191 care of cleaning up the temporary breakpoints set up by the until
6194 until_break_command_continuation (void *arg
)
6196 struct until_break_command_continuation_args
*a
= arg
;
6198 delete_breakpoint (a
->breakpoint
);
6200 delete_breakpoint (a
->breakpoint2
);
6204 until_break_command (char *arg
, int from_tty
, int anywhere
)
6206 struct symtabs_and_lines sals
;
6207 struct symtab_and_line sal
;
6208 struct frame_info
*frame
= get_selected_frame (NULL
);
6209 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6210 struct breakpoint
*breakpoint
;
6211 struct breakpoint
*breakpoint2
= NULL
;
6212 struct cleanup
*old_chain
;
6214 clear_proceed_status ();
6216 /* Set a breakpoint where the user wants it and at return from
6219 if (default_breakpoint_valid
)
6220 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6221 default_breakpoint_line
, (char ***) NULL
, NULL
);
6223 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6224 0, (char ***) NULL
, NULL
);
6226 if (sals
.nelts
!= 1)
6227 error (_("Couldn't get information on specified line."));
6230 xfree (sals
.sals
); /* malloc'd, so freed */
6233 error (_("Junk at end of arguments."));
6235 resolve_sal_pc (&sal
);
6238 /* If the user told us to continue until a specified location,
6239 we don't specify a frame at which we need to stop. */
6240 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6242 /* Otherwise, specify the current frame, because we want to stop only
6243 at the very same frame. */
6244 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6247 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6249 /* Keep within the current frame, or in frames called by the current
6253 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6254 sal
.pc
= get_frame_pc (prev_frame
);
6255 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6257 make_cleanup_delete_breakpoint (breakpoint2
);
6260 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6262 /* If we are running asynchronously, and proceed call above has actually
6263 managed to start the target, arrange for breakpoints to be
6264 deleted when the target stops. Otherwise, we're already stopped and
6265 delete breakpoints via cleanup chain. */
6267 if (target_can_async_p () && is_running (inferior_ptid
))
6269 struct until_break_command_continuation_args
*args
;
6270 args
= xmalloc (sizeof (*args
));
6272 args
->breakpoint
= breakpoint
;
6273 args
->breakpoint2
= breakpoint2
;
6275 discard_cleanups (old_chain
);
6276 add_continuation (until_break_command_continuation
, args
,
6280 do_cleanups (old_chain
);
6284 ep_skip_leading_whitespace (char **s
)
6286 if ((s
== NULL
) || (*s
== NULL
))
6288 while (isspace (**s
))
6292 /* This function attempts to parse an optional "if <cond>" clause
6293 from the arg string. If one is not found, it returns NULL.
6295 Else, it returns a pointer to the condition string. (It does not
6296 attempt to evaluate the string against a particular block.) And,
6297 it updates arg to point to the first character following the parsed
6298 if clause in the arg string. */
6301 ep_parse_optional_if_clause (char **arg
)
6305 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6308 /* Skip the "if" keyword. */
6311 /* Skip any extra leading whitespace, and record the start of the
6312 condition string. */
6313 ep_skip_leading_whitespace (arg
);
6316 /* Assume that the condition occupies the remainder of the arg string. */
6317 (*arg
) += strlen (cond_string
);
6322 /* This function attempts to parse an optional filename from the arg
6323 string. If one is not found, it returns NULL.
6325 Else, it returns a pointer to the parsed filename. (This function
6326 makes no attempt to verify that a file of that name exists, or is
6327 accessible.) And, it updates arg to point to the first character
6328 following the parsed filename in the arg string.
6330 Note that clients needing to preserve the returned filename for
6331 future access should copy it to their own buffers. */
6333 ep_parse_optional_filename (char **arg
)
6335 static char filename
[1024];
6340 if ((*arg_p
== '\0') || isspace (*arg_p
))
6358 /* Commands to deal with catching events, such as signals, exceptions,
6359 process start/exit, etc. */
6363 catch_fork_temporary
, catch_vfork_temporary
,
6364 catch_fork_permanent
, catch_vfork_permanent
6369 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6371 char *cond_string
= NULL
;
6372 catch_fork_kind fork_kind
;
6375 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6376 tempflag
= (fork_kind
== catch_fork_temporary
6377 || fork_kind
== catch_vfork_temporary
);
6381 ep_skip_leading_whitespace (&arg
);
6383 /* The allowed syntax is:
6385 catch [v]fork if <cond>
6387 First, check if there's an if clause. */
6388 cond_string
= ep_parse_optional_if_clause (&arg
);
6390 if ((*arg
!= '\0') && !isspace (*arg
))
6391 error (_("Junk at end of arguments."));
6393 /* If this target supports it, create a fork or vfork catchpoint
6394 and enable reporting of such events. */
6397 case catch_fork_temporary
:
6398 case catch_fork_permanent
:
6399 create_fork_event_catchpoint (tempflag
, cond_string
);
6401 case catch_vfork_temporary
:
6402 case catch_vfork_permanent
:
6403 create_vfork_event_catchpoint (tempflag
, cond_string
);
6406 error (_("unsupported or unknown fork kind; cannot catch it"));
6412 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6415 char *cond_string
= NULL
;
6417 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6421 ep_skip_leading_whitespace (&arg
);
6423 /* The allowed syntax is:
6425 catch exec if <cond>
6427 First, check if there's an if clause. */
6428 cond_string
= ep_parse_optional_if_clause (&arg
);
6430 if ((*arg
!= '\0') && !isspace (*arg
))
6431 error (_("Junk at end of arguments."));
6433 /* If this target supports it, create an exec catchpoint
6434 and enable reporting of such events. */
6435 create_exec_event_catchpoint (tempflag
, cond_string
);
6439 catch_load_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6442 char *dll_pathname
= NULL
;
6443 char *cond_string
= NULL
;
6445 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6449 ep_skip_leading_whitespace (&arg
);
6451 /* The allowed syntax is:
6453 catch load if <cond>
6454 catch load <filename>
6455 catch load <filename> if <cond>
6457 The user is not allowed to specify the <filename> after an
6460 We'll ignore the pathological case of a file named "if".
6462 First, check if there's an if clause. If so, then there
6463 cannot be a filename. */
6464 cond_string
= ep_parse_optional_if_clause (&arg
);
6466 /* If there was an if clause, then there cannot be a filename.
6467 Else, there might be a filename and an if clause. */
6468 if (cond_string
== NULL
)
6470 dll_pathname
= ep_parse_optional_filename (&arg
);
6471 ep_skip_leading_whitespace (&arg
);
6472 cond_string
= ep_parse_optional_if_clause (&arg
);
6475 if ((*arg
!= '\0') && !isspace (*arg
))
6476 error (_("Junk at end of arguments."));
6478 /* Create a load breakpoint that only triggers when a load of
6479 the specified dll (or any dll, if no pathname was specified)
6481 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6482 dll_pathname
, cond_string
);
6486 catch_unload_command_1 (char *arg
, int from_tty
,
6487 struct cmd_list_element
*command
)
6490 char *dll_pathname
= NULL
;
6491 char *cond_string
= NULL
;
6493 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6497 ep_skip_leading_whitespace (&arg
);
6499 /* The allowed syntax is:
6501 catch unload if <cond>
6502 catch unload <filename>
6503 catch unload <filename> if <cond>
6505 The user is not allowed to specify the <filename> after an
6508 We'll ignore the pathological case of a file named "if".
6510 First, check if there's an if clause. If so, then there
6511 cannot be a filename. */
6512 cond_string
= ep_parse_optional_if_clause (&arg
);
6514 /* If there was an if clause, then there cannot be a filename.
6515 Else, there might be a filename and an if clause. */
6516 if (cond_string
== NULL
)
6518 dll_pathname
= ep_parse_optional_filename (&arg
);
6519 ep_skip_leading_whitespace (&arg
);
6520 cond_string
= ep_parse_optional_if_clause (&arg
);
6523 if ((*arg
!= '\0') && !isspace (*arg
))
6524 error (_("Junk at end of arguments."));
6526 /* Create an unload breakpoint that only triggers when an unload of
6527 the specified dll (or any dll, if no pathname was specified)
6529 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6530 dll_pathname
, cond_string
);
6533 static enum print_stop_action
6534 print_exception_catchpoint (struct breakpoint
*b
)
6536 int bp_temp
, bp_throw
;
6538 annotate_catchpoint (b
->number
);
6540 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6541 if (b
->loc
->address
!= b
->loc
->requested_address
)
6542 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6545 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6547 bp_temp
? "Temporary catchpoint "
6549 if (!ui_out_is_mi_like_p (uiout
))
6550 ui_out_field_int (uiout
, "bkptno", b
->number
);
6552 bp_throw
? " (exception thrown), "
6553 : " (exception caught), ");
6554 if (ui_out_is_mi_like_p (uiout
))
6556 ui_out_field_string (uiout
, "reason",
6557 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6558 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6559 ui_out_field_int (uiout
, "bkptno", b
->number
);
6561 return PRINT_SRC_AND_LOC
;
6565 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6570 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6571 ui_out_field_string (uiout
, "addr", "<PENDING>");
6573 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6577 *last_addr
= b
->loc
->address
;
6578 if (strstr (b
->addr_string
, "throw") != NULL
)
6579 ui_out_field_string (uiout
, "what", "exception throw");
6581 ui_out_field_string (uiout
, "what", "exception catch");
6585 print_mention_exception_catchpoint (struct breakpoint
*b
)
6590 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6591 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6592 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6593 : _("Catchpoint "));
6594 ui_out_field_int (uiout
, "bkptno", b
->number
);
6595 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6599 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6600 print_exception_catchpoint
,
6601 print_one_exception_catchpoint
,
6602 print_mention_exception_catchpoint
6606 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6607 enum exception_event_kind ex_event
, int from_tty
)
6609 char *trigger_func_name
;
6611 if (ex_event
== EX_EVENT_CATCH
)
6612 trigger_func_name
= "__cxa_begin_catch";
6614 trigger_func_name
= "__cxa_throw";
6616 break_command_really (trigger_func_name
, cond_string
, -1,
6617 0 /* condition and thread are valid. */,
6620 AUTO_BOOLEAN_TRUE
/* pending */,
6621 &gnu_v3_exception_catchpoint_ops
, from_tty
);
6626 /* Deal with "catch catch" and "catch throw" commands */
6629 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6630 int tempflag
, int from_tty
)
6632 char *cond_string
= NULL
;
6633 struct symtab_and_line
*sal
= NULL
;
6637 ep_skip_leading_whitespace (&arg
);
6639 cond_string
= ep_parse_optional_if_clause (&arg
);
6641 if ((*arg
!= '\0') && !isspace (*arg
))
6642 error (_("Junk at end of arguments."));
6644 if ((ex_event
!= EX_EVENT_THROW
) &&
6645 (ex_event
!= EX_EVENT_CATCH
))
6646 error (_("Unsupported or unknown exception event; cannot catch it"));
6648 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6651 warning (_("Unsupported with this platform/compiler combination."));
6654 /* Implementation of "catch catch" command. */
6657 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6659 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6660 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6663 /* Implementation of "catch throw" command. */
6666 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6668 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6669 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6672 /* Create a breakpoint struct for Ada exception catchpoints. */
6675 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6679 struct expression
*cond
,
6680 struct breakpoint_ops
*ops
,
6684 struct breakpoint
*b
;
6688 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6689 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6690 version for exception catchpoints, because two catchpoints
6691 used for different exception names will use the same address.
6692 In this case, a "breakpoint ... also set at..." warning is
6693 unproductive. Besides. the warning phrasing is also a bit
6694 inapropriate, we should use the word catchpoint, and tell
6695 the user what type of catchpoint it is. The above is good
6696 enough for now, though. */
6699 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6700 set_breakpoint_count (breakpoint_count
+ 1);
6702 b
->enable_state
= bp_enabled
;
6703 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6704 b
->number
= breakpoint_count
;
6705 b
->ignore_count
= 0;
6706 b
->loc
->cond
= cond
;
6707 b
->addr_string
= addr_string
;
6708 b
->language
= language_ada
;
6709 b
->cond_string
= cond_string
;
6710 b
->exp_string
= exp_string
;
6715 update_global_location_list (1);
6718 /* Implement the "catch exception" command. */
6721 catch_ada_exception_command (char *arg
, int from_tty
,
6722 struct cmd_list_element
*command
)
6725 struct symtab_and_line sal
;
6727 char *addr_string
= NULL
;
6728 char *exp_string
= NULL
;
6729 char *cond_string
= NULL
;
6730 struct expression
*cond
= NULL
;
6731 struct breakpoint_ops
*ops
= NULL
;
6733 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6737 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6738 &cond_string
, &cond
, &ops
);
6739 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6740 cond_string
, cond
, ops
, tempflag
,
6744 /* Implement the "catch assert" command. */
6747 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6750 struct symtab_and_line sal
;
6751 char *addr_string
= NULL
;
6752 struct breakpoint_ops
*ops
= NULL
;
6754 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6758 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6759 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6760 tempflag
, from_tty
);
6764 catch_command (char *arg
, int from_tty
)
6766 error (_("Catch requires an event name."));
6771 tcatch_command (char *arg
, int from_tty
)
6773 error (_("Catch requires an event name."));
6776 /* Delete breakpoints by address or line. */
6779 clear_command (char *arg
, int from_tty
)
6781 struct breakpoint
*b
;
6782 VEC(breakpoint_p
) *found
= 0;
6785 struct symtabs_and_lines sals
;
6786 struct symtab_and_line sal
;
6791 sals
= decode_line_spec (arg
, 1);
6796 sals
.sals
= (struct symtab_and_line
*)
6797 xmalloc (sizeof (struct symtab_and_line
));
6798 make_cleanup (xfree
, sals
.sals
);
6799 init_sal (&sal
); /* initialize to zeroes */
6800 sal
.line
= default_breakpoint_line
;
6801 sal
.symtab
= default_breakpoint_symtab
;
6802 sal
.pc
= default_breakpoint_address
;
6803 if (sal
.symtab
== 0)
6804 error (_("No source file specified."));
6812 /* We don't call resolve_sal_pc here. That's not
6813 as bad as it seems, because all existing breakpoints
6814 typically have both file/line and pc set. So, if
6815 clear is given file/line, we can match this to existing
6816 breakpoint without obtaining pc at all.
6818 We only support clearing given the address explicitly
6819 present in breakpoint table. Say, we've set breakpoint
6820 at file:line. There were several PC values for that file:line,
6821 due to optimization, all in one block.
6822 We've picked one PC value. If "clear" is issued with another
6823 PC corresponding to the same file:line, the breakpoint won't
6824 be cleared. We probably can still clear the breakpoint, but
6825 since the other PC value is never presented to user, user
6826 can only find it by guessing, and it does not seem important
6829 /* For each line spec given, delete bps which correspond
6830 to it. Do it in two passes, solely to preserve the current
6831 behavior that from_tty is forced true if we delete more than
6835 for (i
= 0; i
< sals
.nelts
; i
++)
6837 /* If exact pc given, clear bpts at that pc.
6838 If line given (pc == 0), clear all bpts on specified line.
6839 If defaulting, clear all bpts on default line
6842 defaulting sal.pc != 0 tests to do
6847 1 0 <can't happen> */
6851 /* Find all matching breakpoints and add them to
6856 /* Are we going to delete b? */
6857 if (b
->type
!= bp_none
6858 && b
->type
!= bp_watchpoint
6859 && b
->type
!= bp_hardware_watchpoint
6860 && b
->type
!= bp_read_watchpoint
6861 && b
->type
!= bp_access_watchpoint
)
6863 struct bp_location
*loc
= b
->loc
;
6864 for (; loc
; loc
= loc
->next
)
6866 int pc_match
= sal
.pc
6867 && (loc
->address
== sal
.pc
)
6868 && (!section_is_overlay (loc
->section
)
6869 || loc
->section
== sal
.section
);
6870 int line_match
= ((default_match
|| (0 == sal
.pc
))
6871 && b
->source_file
!= NULL
6872 && sal
.symtab
!= NULL
6873 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6874 && b
->line_number
== sal
.line
);
6875 if (pc_match
|| line_match
)
6884 VEC_safe_push(breakpoint_p
, found
, b
);
6887 /* Now go thru the 'found' chain and delete them. */
6888 if (VEC_empty(breakpoint_p
, found
))
6891 error (_("No breakpoint at %s."), arg
);
6893 error (_("No breakpoint at this line."));
6896 if (VEC_length(breakpoint_p
, found
) > 1)
6897 from_tty
= 1; /* Always report if deleted more than one */
6900 if (VEC_length(breakpoint_p
, found
) == 1)
6901 printf_unfiltered (_("Deleted breakpoint "));
6903 printf_unfiltered (_("Deleted breakpoints "));
6905 breakpoints_changed ();
6907 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6910 printf_unfiltered ("%d ", b
->number
);
6911 delete_breakpoint (b
);
6914 putchar_unfiltered ('\n');
6917 /* Delete breakpoint in BS if they are `delete' breakpoints and
6918 all breakpoints that are marked for deletion, whether hit or not.
6919 This is called after any breakpoint is hit, or after errors. */
6922 breakpoint_auto_delete (bpstat bs
)
6924 struct breakpoint
*b
, *temp
;
6926 for (; bs
; bs
= bs
->next
)
6927 if (bs
->breakpoint_at
6928 && bs
->breakpoint_at
->owner
6929 && bs
->breakpoint_at
->owner
->disposition
== disp_del
6931 delete_breakpoint (bs
->breakpoint_at
->owner
);
6933 ALL_BREAKPOINTS_SAFE (b
, temp
)
6935 if (b
->disposition
== disp_del_at_next_stop
)
6936 delete_breakpoint (b
);
6940 /* If SHOULD_INSERT is true, do not insert any breakpoint locations
6941 into the inferior, only remove already-inserted locations that no
6942 longer should be inserted. Functions that delete a breakpoint or
6943 breakpoints should pass false, so that deleting a breakpoint
6944 doesn't have the side effect of inserting the locations of other
6945 breakpoints that are marked not-inserted, but should_be_inserted
6946 returns true on them.
6948 This behaviour is useful is situations close to tear-down -- e.g.,
6949 after an exec, while the target still has execution, but breakpoint
6950 shadows of the previous executable image should *NOT* be restored
6951 to the new image; or before detaching, where the target still has
6952 execution and wants to delete breakpoints from GDB's lists, and all
6953 breakpoints had already been removed from the inferior. */
6956 update_global_location_list (int should_insert
)
6958 struct breakpoint
*b
;
6959 struct bp_location
**next
= &bp_location_chain
;
6960 struct bp_location
*loc
;
6961 struct bp_location
*loc2
;
6962 struct gdb_exception e
;
6963 VEC(bp_location_p
) *old_locations
= NULL
;
6967 /* Store old locations for future reference. */
6968 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
6969 VEC_safe_push (bp_location_p
, old_locations
, loc
);
6971 bp_location_chain
= NULL
;
6974 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6977 next
= &(loc
->global_next
);
6982 /* Identify bp_location instances that are no longer present in the new
6983 list, and therefore should be freed. Note that it's not necessary that
6984 those locations should be removed from inferior -- if there's another
6985 location at the same address (previously marked as duplicate),
6986 we don't need to remove/insert the location. */
6987 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
6989 /* Tells if 'loc' is found amoung the new locations. If not, we
6991 int found_object
= 0;
6992 /* Tells if the location should remain inserted in the target. */
6993 int keep_in_target
= 0;
6995 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7002 /* If this location is no longer present, and inserted, look if there's
7003 maybe a new location at the same address. If so, mark that one
7004 inserted, and don't remove this one. This is needed so that we
7005 don't have a time window where a breakpoint at certain location is not
7010 /* If the location is inserted now, we might have to remove it. */
7012 if (found_object
&& should_be_inserted (loc
))
7014 /* The location is still present in the location list, and still
7015 should be inserted. Don't do anything. */
7020 /* The location is either no longer present, or got disabled.
7021 See if there's another location at the same address, in which
7022 case we don't need to remove this one from the target. */
7023 if (breakpoint_address_is_meaningful (loc
->owner
))
7024 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7026 /* For the sake of should_insert_location. The
7027 call to check_duplicates will fix up this later. */
7028 loc2
->duplicate
= 0;
7029 if (should_be_inserted (loc2
)
7030 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7033 loc2
->target_info
= loc
->target_info
;
7040 if (!keep_in_target
)
7042 if (remove_breakpoint (loc
, mark_uninserted
))
7044 /* This is just about all we can do. We could keep this
7045 location on the global list, and try to remove it next
7046 time, but there's no particular reason why we will
7049 Note that at this point, loc->owner is still valid,
7050 as delete_breakpoint frees the breakpoint only
7051 after calling us. */
7052 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7053 loc
->owner
->number
);
7063 /* This location was removed from the targets. In non-stop mode,
7064 a race condition is possible where we've removed a breakpoint,
7065 but stop events for that breakpoint are already queued and will
7066 arrive later. To suppress spurious SIGTRAPs reported to user,
7067 we keep this breakpoint location for a bit, and will retire it
7068 after we see 3 * thread_count events.
7069 The theory here is that reporting of events should,
7070 "on the average", be fair, so after that many event we'll see
7071 events from all threads that have anything of interest, and no
7072 longer need to keep this breakpoint. This is just a
7073 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7074 which is usability issue, but not a correctness problem. */
7075 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7079 free_bp_location (loc
);
7085 check_duplicates (b
);
7088 if (breakpoints_always_inserted_mode ()
7090 && target_has_execution
)
7091 insert_breakpoint_locations ();
7095 breakpoint_retire_moribund (void)
7097 struct bp_location
*loc
;
7100 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7101 if (--(loc
->events_till_retirement
) == 0)
7103 free_bp_location (loc
);
7104 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7110 update_global_location_list_nothrow (int inserting
)
7112 struct gdb_exception e
;
7113 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7114 update_global_location_list (inserting
);
7117 /* Clear BPT from a BPS. */
7119 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7122 for (bs
= bps
; bs
; bs
= bs
->next
)
7123 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7125 bs
->breakpoint_at
= NULL
;
7127 /* bs->commands will be freed later. */
7131 /* Callback for iterate_over_threads. */
7133 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7135 struct breakpoint
*bpt
= data
;
7136 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7140 /* Delete a breakpoint and clean up all traces of it in the data
7144 delete_breakpoint (struct breakpoint
*bpt
)
7146 struct breakpoint
*b
;
7147 struct bp_location
*loc
, *next
;
7149 gdb_assert (bpt
!= NULL
);
7151 /* Has this bp already been deleted? This can happen because multiple
7152 lists can hold pointers to bp's. bpstat lists are especial culprits.
7154 One example of this happening is a watchpoint's scope bp. When the
7155 scope bp triggers, we notice that the watchpoint is out of scope, and
7156 delete it. We also delete its scope bp. But the scope bp is marked
7157 "auto-deleting", and is already on a bpstat. That bpstat is then
7158 checked for auto-deleting bp's, which are deleted.
7160 A real solution to this problem might involve reference counts in bp's,
7161 and/or giving them pointers back to their referencing bpstat's, and
7162 teaching delete_breakpoint to only free a bp's storage when no more
7163 references were extent. A cheaper bandaid was chosen. */
7164 if (bpt
->type
== bp_none
)
7167 observer_notify_breakpoint_deleted (bpt
->number
);
7169 if (breakpoint_chain
== bpt
)
7170 breakpoint_chain
= bpt
->next
;
7175 b
->next
= bpt
->next
;
7179 free_command_lines (&bpt
->commands
);
7180 if (bpt
->cond_string
!= NULL
)
7181 xfree (bpt
->cond_string
);
7182 if (bpt
->addr_string
!= NULL
)
7183 xfree (bpt
->addr_string
);
7184 if (bpt
->exp
!= NULL
)
7186 if (bpt
->exp_string
!= NULL
)
7187 xfree (bpt
->exp_string
);
7188 if (bpt
->val
!= NULL
)
7189 value_free (bpt
->val
);
7190 if (bpt
->source_file
!= NULL
)
7191 xfree (bpt
->source_file
);
7192 if (bpt
->dll_pathname
!= NULL
)
7193 xfree (bpt
->dll_pathname
);
7194 if (bpt
->triggered_dll_pathname
!= NULL
)
7195 xfree (bpt
->triggered_dll_pathname
);
7196 if (bpt
->exec_pathname
!= NULL
)
7197 xfree (bpt
->exec_pathname
);
7199 /* Be sure no bpstat's are pointing at it after it's been freed. */
7200 /* FIXME, how can we find all bpstat's?
7201 We just check stop_bpstat for now. Note that we cannot just
7202 remove bpstats pointing at bpt from the stop_bpstat list
7203 entirely, as breakpoint commands are associated with the bpstat;
7204 if we remove it here, then the later call to
7205 bpstat_do_actions (&stop_bpstat);
7206 in event-top.c won't do anything, and temporary breakpoints
7207 with commands won't work. */
7209 /* Clear the current context. */
7210 bpstat_remove_breakpoint (stop_bpstat
, bpt
);
7211 /* And from all threads. */
7212 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7214 /* Now that breakpoint is removed from breakpoint
7215 list, update the global location list. This
7216 will remove locations that used to belong to
7217 this breakpoint. Do this before freeing
7218 the breakpoint itself, since remove_breakpoint
7219 looks at location's owner. It might be better
7220 design to have location completely self-contained,
7221 but it's not the case now. */
7222 update_global_location_list (0);
7225 /* On the chance that someone will soon try again to delete this same
7226 bp, we mark it as deleted before freeing its storage. */
7227 bpt
->type
= bp_none
;
7233 do_delete_breakpoint_cleanup (void *b
)
7235 delete_breakpoint (b
);
7239 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7241 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7245 delete_command (char *arg
, int from_tty
)
7247 struct breakpoint
*b
, *temp
;
7253 int breaks_to_delete
= 0;
7255 /* Delete all breakpoints if no argument.
7256 Do not delete internal or call-dummy breakpoints, these
7257 have to be deleted with an explicit breakpoint number argument. */
7260 if (b
->type
!= bp_call_dummy
&&
7261 b
->type
!= bp_shlib_event
&&
7262 b
->type
!= bp_thread_event
&&
7263 b
->type
!= bp_overlay_event
&&
7266 breaks_to_delete
= 1;
7271 /* Ask user only if there are some breakpoints to delete. */
7273 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7275 ALL_BREAKPOINTS_SAFE (b
, temp
)
7277 if (b
->type
!= bp_call_dummy
&&
7278 b
->type
!= bp_shlib_event
&&
7279 b
->type
!= bp_thread_event
&&
7280 b
->type
!= bp_overlay_event
&&
7282 delete_breakpoint (b
);
7287 map_breakpoint_numbers (arg
, delete_breakpoint
);
7291 all_locations_are_pending (struct bp_location
*loc
)
7293 for (; loc
; loc
= loc
->next
)
7294 if (!loc
->shlib_disabled
)
7299 /* Subroutine of update_breakpoint_locations to simplify it.
7300 Return non-zero if multiple fns in list LOC have the same name.
7301 Null names are ignored. */
7304 ambiguous_names_p (struct bp_location
*loc
)
7306 struct bp_location
*l
;
7307 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7308 (int (*) (const void *, const void *)) streq
,
7309 NULL
, xcalloc
, xfree
);
7311 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7314 const char *name
= l
->function_name
;
7316 /* Allow for some names to be NULL, ignore them. */
7320 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7322 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7337 update_breakpoint_locations (struct breakpoint
*b
,
7338 struct symtabs_and_lines sals
)
7342 struct bp_location
*existing_locations
= b
->loc
;
7344 /* If there's no new locations, and all existing locations
7345 are pending, don't do anything. This optimizes
7346 the common case where all locations are in the same
7347 shared library, that was unloaded. We'd like to
7348 retain the location, so that when the library
7349 is loaded again, we don't loose the enabled/disabled
7350 status of the individual locations. */
7351 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7356 for (i
= 0; i
< sals
.nelts
; ++i
)
7358 struct bp_location
*new_loc
=
7359 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7361 /* Reparse conditions, they might contain references to the
7363 if (b
->cond_string
!= NULL
)
7365 struct gdb_exception e
;
7368 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7370 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7375 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7376 b
->number
, e
.message
);
7377 new_loc
->enabled
= 0;
7381 if (b
->source_file
!= NULL
)
7382 xfree (b
->source_file
);
7383 if (sals
.sals
[i
].symtab
== NULL
)
7384 b
->source_file
= NULL
;
7387 savestring (sals
.sals
[i
].symtab
->filename
,
7388 strlen (sals
.sals
[i
].symtab
->filename
));
7390 if (b
->line_number
== 0)
7391 b
->line_number
= sals
.sals
[i
].line
;
7394 /* If possible, carry over 'disable' status from existing breakpoints. */
7396 struct bp_location
*e
= existing_locations
;
7397 /* If there are multiple breakpoints with the same function name,
7398 e.g. for inline functions, comparing function names won't work.
7399 Instead compare pc addresses; this is just a heuristic as things
7400 may have moved, but in practice it gives the correct answer
7401 often enough until a better solution is found. */
7402 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7404 for (; e
; e
= e
->next
)
7406 if (!e
->enabled
&& e
->function_name
)
7408 struct bp_location
*l
= b
->loc
;
7409 if (have_ambiguous_names
)
7411 for (; l
; l
= l
->next
)
7412 if (e
->address
== l
->address
)
7420 for (; l
; l
= l
->next
)
7421 if (l
->function_name
7422 && strcmp (e
->function_name
, l
->function_name
) == 0)
7432 update_global_location_list (1);
7436 /* Reset a breakpoint given it's struct breakpoint * BINT.
7437 The value we return ends up being the return value from catch_errors.
7438 Unused in this case. */
7441 breakpoint_re_set_one (void *bint
)
7443 /* get past catch_errs */
7444 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7448 int *not_found_ptr
= ¬_found
;
7449 struct symtabs_and_lines sals
= {};
7450 struct symtabs_and_lines expanded
;
7452 enum enable_state save_enable
;
7453 struct gdb_exception e
;
7459 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7463 case bp_hardware_breakpoint
:
7465 case bp_catch_unload
:
7466 if (b
->addr_string
== NULL
)
7468 /* Anything without a string can't be re-set. */
7469 delete_breakpoint (b
);
7473 set_language (b
->language
);
7474 input_radix
= b
->input_radix
;
7476 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7478 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7483 int not_found_and_ok
= 0;
7484 /* For pending breakpoints, it's expected that parsing
7485 will fail until the right shared library is loaded.
7486 User has already told to create pending breakpoints and
7487 don't need extra messages. If breakpoint is in bp_shlib_disabled
7488 state, then user already saw the message about that breakpoint
7489 being disabled, and don't want to see more errors. */
7491 && (b
->condition_not_parsed
7492 || (b
->loc
&& b
->loc
->shlib_disabled
)
7493 || b
->enable_state
== bp_disabled
))
7494 not_found_and_ok
= 1;
7496 if (!not_found_and_ok
)
7498 /* We surely don't want to warn about the same breakpoint
7499 10 times. One solution, implemented here, is disable
7500 the breakpoint on error. Another solution would be to
7501 have separate 'warning emitted' flag. Since this
7502 happens only when a binary has changed, I don't know
7503 which approach is better. */
7504 b
->enable_state
= bp_disabled
;
7505 throw_exception (e
);
7512 gdb_assert (sals
.nelts
== 1);
7513 resolve_sal_pc (&sals
.sals
[0]);
7514 if (b
->condition_not_parsed
&& s
&& s
[0])
7516 char *cond_string
= 0;
7518 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7519 &cond_string
, &thread
);
7521 b
->cond_string
= cond_string
;
7523 b
->condition_not_parsed
= 0;
7525 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7526 update_breakpoint_locations (b
, expanded
);
7532 case bp_hardware_watchpoint
:
7533 case bp_read_watchpoint
:
7534 case bp_access_watchpoint
:
7535 /* Watchpoint can be either on expression using entirely global variables,
7536 or it can be on local variables.
7538 Watchpoints of the first kind are never auto-deleted, and even persist
7539 across program restarts. Since they can use variables from shared
7540 libraries, we need to reparse expression as libraries are loaded
7543 Watchpoints on local variables can also change meaning as result
7544 of solib event. For example, if a watchpoint uses both a local and
7545 a global variables in expression, it's a local watchpoint, but
7546 unloading of a shared library will make the expression invalid.
7547 This is not a very common use case, but we still re-evaluate
7548 expression, to avoid surprises to the user.
7550 Note that for local watchpoints, we re-evaluate it only if
7551 watchpoints frame id is still valid. If it's not, it means
7552 the watchpoint is out of scope and will be deleted soon. In fact,
7553 I'm not sure we'll ever be called in this case.
7555 If a local watchpoint's frame id is still valid, then
7556 b->exp_valid_block is likewise valid, and we can safely use it.
7558 Don't do anything about disabled watchpoints, since they will
7559 be reevaluated again when enabled. */
7560 update_watchpoint (b
, 1 /* reparse */);
7562 /* We needn't really do anything to reset these, since the mask
7563 that requests them is unaffected by e.g., new libraries being
7566 case bp_catch_vfork
:
7571 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7573 /* Delete overlay event breakpoints; they will be reset later by
7574 breakpoint_re_set. */
7575 case bp_overlay_event
:
7576 delete_breakpoint (b
);
7579 /* This breakpoint is special, it's set up when the inferior
7580 starts and we really don't want to touch it. */
7581 case bp_shlib_event
:
7583 /* Like bp_shlib_event, this breakpoint type is special.
7584 Once it is set up, we do not want to touch it. */
7585 case bp_thread_event
:
7587 /* Keep temporary breakpoints, which can be encountered when we step
7588 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7589 Otherwise these should have been blown away via the cleanup chain
7590 or by breakpoint_init_inferior when we rerun the executable. */
7593 case bp_watchpoint_scope
:
7595 case bp_step_resume
:
7597 case bp_longjmp_resume
:
7604 /* Re-set all breakpoints after symbols have been re-loaded. */
7606 breakpoint_re_set (void)
7608 struct breakpoint
*b
, *temp
;
7609 enum language save_language
;
7610 int save_input_radix
;
7612 save_language
= current_language
->la_language
;
7613 save_input_radix
= input_radix
;
7614 ALL_BREAKPOINTS_SAFE (b
, temp
)
7616 /* Format possible error msg */
7617 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7619 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7620 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7621 do_cleanups (cleanups
);
7623 set_language (save_language
);
7624 input_radix
= save_input_radix
;
7626 create_overlay_event_breakpoint ("_ovly_debug_event");
7629 /* Reset the thread number of this breakpoint:
7631 - If the breakpoint is for all threads, leave it as-is.
7632 - Else, reset it to the current thread for inferior_ptid. */
7634 breakpoint_re_set_thread (struct breakpoint
*b
)
7636 if (b
->thread
!= -1)
7638 if (in_thread_list (inferior_ptid
))
7639 b
->thread
= pid_to_thread_id (inferior_ptid
);
7643 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7644 If from_tty is nonzero, it prints a message to that effect,
7645 which ends with a period (no newline). */
7648 set_ignore_count (int bptnum
, int count
, int from_tty
)
7650 struct breakpoint
*b
;
7656 if (b
->number
== bptnum
)
7658 b
->ignore_count
= count
;
7662 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7664 else if (count
== 1)
7665 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7668 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7671 breakpoints_changed ();
7672 observer_notify_breakpoint_modified (b
->number
);
7676 error (_("No breakpoint number %d."), bptnum
);
7679 /* Clear the ignore counts of all breakpoints. */
7681 breakpoint_clear_ignore_counts (void)
7683 struct breakpoint
*b
;
7686 b
->ignore_count
= 0;
7689 /* Command to set ignore-count of breakpoint N to COUNT. */
7692 ignore_command (char *args
, int from_tty
)
7698 error_no_arg (_("a breakpoint number"));
7700 num
= get_number (&p
);
7702 error (_("bad breakpoint number: '%s'"), args
);
7704 error (_("Second argument (specified ignore-count) is missing."));
7706 set_ignore_count (num
,
7707 longest_to_int (value_as_long (parse_and_eval (p
))),
7710 printf_filtered ("\n");
7713 /* Call FUNCTION on each of the breakpoints
7714 whose numbers are given in ARGS. */
7717 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7722 struct breakpoint
*b
, *tmp
;
7726 error_no_arg (_("one or more breakpoint numbers"));
7733 num
= get_number_or_range (&p1
);
7736 warning (_("bad breakpoint number at or near '%s'"), p
);
7740 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7741 if (b
->number
== num
)
7743 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7746 if (related_breakpoint
)
7747 function (related_breakpoint
);
7751 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7757 static struct bp_location
*
7758 find_location_by_number (char *number
)
7760 char *dot
= strchr (number
, '.');
7764 struct breakpoint
*b
;
7765 struct bp_location
*loc
;
7770 bp_num
= get_number_or_range (&p1
);
7772 error (_("Bad breakpoint number '%s'"), number
);
7775 if (b
->number
== bp_num
)
7780 if (!b
|| b
->number
!= bp_num
)
7781 error (_("Bad breakpoint number '%s'"), number
);
7784 loc_num
= get_number_or_range (&p1
);
7786 error (_("Bad breakpoint location number '%s'"), number
);
7790 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7793 error (_("Bad breakpoint location number '%s'"), dot
+1);
7799 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7800 If from_tty is nonzero, it prints a message to that effect,
7801 which ends with a period (no newline). */
7804 disable_breakpoint (struct breakpoint
*bpt
)
7806 /* Never disable a watchpoint scope breakpoint; we want to
7807 hit them when we leave scope so we can delete both the
7808 watchpoint and its scope breakpoint at that time. */
7809 if (bpt
->type
== bp_watchpoint_scope
)
7812 /* You can't disable permanent breakpoints. */
7813 if (bpt
->enable_state
== bp_permanent
)
7816 bpt
->enable_state
= bp_disabled
;
7818 update_global_location_list (0);
7820 observer_notify_breakpoint_modified (bpt
->number
);
7824 disable_command (char *args
, int from_tty
)
7826 struct breakpoint
*bpt
;
7828 ALL_BREAKPOINTS (bpt
)
7832 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7837 case bp_catch_unload
:
7839 case bp_catch_vfork
:
7841 case bp_hardware_breakpoint
:
7843 case bp_hardware_watchpoint
:
7844 case bp_read_watchpoint
:
7845 case bp_access_watchpoint
:
7846 disable_breakpoint (bpt
);
7850 else if (strchr (args
, '.'))
7852 struct bp_location
*loc
= find_location_by_number (args
);
7855 update_global_location_list (0);
7858 map_breakpoint_numbers (args
, disable_breakpoint
);
7862 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7864 int target_resources_ok
, other_type_used
;
7867 if (bpt
->type
== bp_hardware_breakpoint
)
7870 i
= hw_breakpoint_used_count ();
7871 target_resources_ok
=
7872 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7874 if (target_resources_ok
== 0)
7875 error (_("No hardware breakpoint support in the target."));
7876 else if (target_resources_ok
< 0)
7877 error (_("Hardware breakpoints used exceeds limit."));
7880 if (bpt
->type
== bp_watchpoint
||
7881 bpt
->type
== bp_hardware_watchpoint
||
7882 bpt
->type
== bp_read_watchpoint
||
7883 bpt
->type
== bp_access_watchpoint
)
7885 struct frame_id saved_frame_id
;
7887 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7888 if (bpt
->exp_valid_block
!= NULL
)
7890 struct frame_info
*fr
=
7891 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7894 printf_filtered (_("\
7895 Cannot enable watchpoint %d because the block in which its expression\n\
7896 is valid is not currently in scope.\n"), bpt
->number
);
7903 value_free (bpt
->val
);
7904 mark
= value_mark ();
7905 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7907 release_value (bpt
->val
);
7910 if (bpt
->type
== bp_hardware_watchpoint
||
7911 bpt
->type
== bp_read_watchpoint
||
7912 bpt
->type
== bp_access_watchpoint
)
7914 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7915 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7917 /* Hack around 'unused var' error for some targets here */
7918 (void) mem_cnt
, (void) i
;
7919 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7920 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7921 /* we can consider of type is bp_hardware_watchpoint, convert to
7922 bp_watchpoint in the following condition */
7923 if (target_resources_ok
< 0)
7925 printf_filtered (_("\
7926 Cannot enable watchpoint %d because target watch resources\n\
7927 have been allocated for other watchpoints.\n"), bpt
->number
);
7928 value_free_to_mark (mark
);
7933 select_frame (frame_find_by_id (saved_frame_id
));
7934 value_free_to_mark (mark
);
7937 if (bpt
->enable_state
!= bp_permanent
)
7938 bpt
->enable_state
= bp_enabled
;
7939 bpt
->disposition
= disposition
;
7940 update_global_location_list (1);
7941 breakpoints_changed ();
7943 observer_notify_breakpoint_modified (bpt
->number
);
7948 enable_breakpoint (struct breakpoint
*bpt
)
7950 do_enable_breakpoint (bpt
, bpt
->disposition
);
7953 /* The enable command enables the specified breakpoints (or all defined
7954 breakpoints) so they once again become (or continue to be) effective
7955 in stopping the inferior. */
7958 enable_command (char *args
, int from_tty
)
7960 struct breakpoint
*bpt
;
7962 ALL_BREAKPOINTS (bpt
)
7966 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7971 case bp_catch_unload
:
7973 case bp_catch_vfork
:
7975 case bp_hardware_breakpoint
:
7977 case bp_hardware_watchpoint
:
7978 case bp_read_watchpoint
:
7979 case bp_access_watchpoint
:
7980 enable_breakpoint (bpt
);
7984 else if (strchr (args
, '.'))
7986 struct bp_location
*loc
= find_location_by_number (args
);
7989 update_global_location_list (1);
7992 map_breakpoint_numbers (args
, enable_breakpoint
);
7996 enable_once_breakpoint (struct breakpoint
*bpt
)
7998 do_enable_breakpoint (bpt
, disp_disable
);
8002 enable_once_command (char *args
, int from_tty
)
8004 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8008 enable_delete_breakpoint (struct breakpoint
*bpt
)
8010 do_enable_breakpoint (bpt
, disp_del
);
8014 enable_delete_command (char *args
, int from_tty
)
8016 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8020 set_breakpoint_cmd (char *args
, int from_tty
)
8025 show_breakpoint_cmd (char *args
, int from_tty
)
8029 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8031 struct symtabs_and_lines
8032 decode_line_spec_1 (char *string
, int funfirstline
)
8034 struct symtabs_and_lines sals
;
8036 error (_("Empty line specification."));
8037 if (default_breakpoint_valid
)
8038 sals
= decode_line_1 (&string
, funfirstline
,
8039 default_breakpoint_symtab
,
8040 default_breakpoint_line
,
8041 (char ***) NULL
, NULL
);
8043 sals
= decode_line_1 (&string
, funfirstline
,
8044 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8046 error (_("Junk at end of line specification: %s"), string
);
8050 /* Create and insert a raw software breakpoint at PC. Return an
8051 identifier, which should be used to remove the breakpoint later.
8052 In general, places which call this should be using something on the
8053 breakpoint chain instead; this function should be eliminated
8057 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8059 struct bp_target_info
*bp_tgt
;
8061 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8062 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8064 bp_tgt
->placed_address
= pc
;
8065 if (target_insert_breakpoint (bp_tgt
) != 0)
8067 /* Could not insert the breakpoint. */
8075 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8078 deprecated_remove_raw_breakpoint (void *bp
)
8080 struct bp_target_info
*bp_tgt
= bp
;
8083 ret
= target_remove_breakpoint (bp_tgt
);
8089 /* One (or perhaps two) breakpoints used for software single stepping. */
8091 static void *single_step_breakpoints
[2];
8093 /* Create and insert a breakpoint for software single step. */
8096 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8100 if (single_step_breakpoints
[0] == NULL
)
8101 bpt_p
= &single_step_breakpoints
[0];
8104 gdb_assert (single_step_breakpoints
[1] == NULL
);
8105 bpt_p
= &single_step_breakpoints
[1];
8108 /* NOTE drow/2006-04-11: A future improvement to this function would be
8109 to only create the breakpoints once, and actually put them on the
8110 breakpoint chain. That would let us use set_raw_breakpoint. We could
8111 adjust the addresses each time they were needed. Doing this requires
8112 corresponding changes elsewhere where single step breakpoints are
8113 handled, however. So, for now, we use this. */
8115 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8117 error (_("Could not insert single-step breakpoint at 0x%s"),
8118 paddr_nz (next_pc
));
8121 /* Remove and delete any breakpoints used for software single step. */
8124 remove_single_step_breakpoints (void)
8126 gdb_assert (single_step_breakpoints
[0] != NULL
);
8128 /* See insert_single_step_breakpoint for more about this deprecated
8130 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8131 single_step_breakpoints
[0] = NULL
;
8133 if (single_step_breakpoints
[1] != NULL
)
8135 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8136 single_step_breakpoints
[1] = NULL
;
8140 /* Check whether a software single-step breakpoint is inserted at PC. */
8143 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8147 for (i
= 0; i
< 2; i
++)
8149 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8150 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8158 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8159 It is defined as a macro to prevent duplication.
8160 COMMAND should be a string constant containing the name of the command. */
8161 #define BREAK_ARGS_HELP(command) \
8162 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8163 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8164 If a line number is specified, break at start of code for that line.\n\
8165 If a function is specified, break at start of code for that function.\n\
8166 If an address is specified, break at that exact address.\n\
8167 With no LOCATION, uses current execution address of selected stack frame.\n\
8168 This is useful for breaking on return to a stack frame.\n\
8170 THREADNUM is the number from \"info threads\".\n\
8171 CONDITION is a boolean expression.\n\
8173 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8175 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8177 /* List of subcommands for "catch". */
8178 static struct cmd_list_element
*catch_cmdlist
;
8180 /* List of subcommands for "tcatch". */
8181 static struct cmd_list_element
*tcatch_cmdlist
;
8183 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8184 lists, and pass some additional user data to the command function. */
8186 add_catch_command (char *name
, char *docstring
,
8187 void (*sfunc
) (char *args
, int from_tty
,
8188 struct cmd_list_element
*command
),
8189 void *user_data_catch
,
8190 void *user_data_tcatch
)
8192 struct cmd_list_element
*command
;
8194 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8196 set_cmd_sfunc (command
, sfunc
);
8197 set_cmd_context (command
, user_data_catch
);
8199 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8201 set_cmd_sfunc (command
, sfunc
);
8202 set_cmd_context (command
, user_data_tcatch
);
8206 _initialize_breakpoint (void)
8208 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8209 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8210 struct cmd_list_element
*c
;
8212 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8214 breakpoint_chain
= 0;
8215 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8216 before a breakpoint is set. */
8217 breakpoint_count
= 0;
8219 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8220 Set ignore-count of breakpoint number N to COUNT.\n\
8221 Usage is `ignore N COUNT'."));
8223 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8225 add_com ("commands", class_breakpoint
, commands_command
, _("\
8226 Set commands to be executed when a breakpoint is hit.\n\
8227 Give breakpoint number as argument after \"commands\".\n\
8228 With no argument, the targeted breakpoint is the last one set.\n\
8229 The commands themselves follow starting on the next line.\n\
8230 Type a line containing \"end\" to indicate the end of them.\n\
8231 Give \"silent\" as the first line to make the breakpoint silent;\n\
8232 then no output is printed when it is hit, except what the commands print."));
8234 add_com ("condition", class_breakpoint
, condition_command
, _("\
8235 Specify breakpoint number N to break only if COND is true.\n\
8236 Usage is `condition N COND', where N is an integer and COND is an\n\
8237 expression to be evaluated whenever breakpoint N is reached."));
8239 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8240 Set a temporary breakpoint.\n\
8241 Like \"break\" except the breakpoint is only temporary,\n\
8242 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8243 by using \"enable delete\" on the breakpoint number.\n\
8245 BREAK_ARGS_HELP ("tbreak")));
8246 set_cmd_completer (c
, location_completer
);
8248 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8249 Set a hardware assisted breakpoint.\n\
8250 Like \"break\" except the breakpoint requires hardware support,\n\
8251 some target hardware may not have this support.\n\
8253 BREAK_ARGS_HELP ("hbreak")));
8254 set_cmd_completer (c
, location_completer
);
8256 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8257 Set a temporary hardware assisted breakpoint.\n\
8258 Like \"hbreak\" except the breakpoint is only temporary,\n\
8259 so it will be deleted when hit.\n\
8261 BREAK_ARGS_HELP ("thbreak")));
8262 set_cmd_completer (c
, location_completer
);
8264 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8265 Enable some breakpoints.\n\
8266 Give breakpoint numbers (separated by spaces) as arguments.\n\
8267 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8268 This is used to cancel the effect of the \"disable\" command.\n\
8269 With a subcommand you can enable temporarily."),
8270 &enablelist
, "enable ", 1, &cmdlist
);
8272 add_com ("ab", class_breakpoint
, enable_command
, _("\
8273 Enable some breakpoints.\n\
8274 Give breakpoint numbers (separated by spaces) as arguments.\n\
8275 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8276 This is used to cancel the effect of the \"disable\" command.\n\
8277 With a subcommand you can enable temporarily."));
8279 add_com_alias ("en", "enable", class_breakpoint
, 1);
8281 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8282 Enable some breakpoints.\n\
8283 Give breakpoint numbers (separated by spaces) as arguments.\n\
8284 This is used to cancel the effect of the \"disable\" command.\n\
8285 May be abbreviated to simply \"enable\".\n"),
8286 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8288 add_cmd ("once", no_class
, enable_once_command
, _("\
8289 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8290 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8293 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8294 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8295 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8298 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8299 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8300 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8303 add_cmd ("once", no_class
, enable_once_command
, _("\
8304 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8305 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8308 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8309 Disable some breakpoints.\n\
8310 Arguments are breakpoint numbers with spaces in between.\n\
8311 To disable all breakpoints, give no argument.\n\
8312 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8313 &disablelist
, "disable ", 1, &cmdlist
);
8314 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8315 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8317 add_com ("sb", class_breakpoint
, disable_command
, _("\
8318 Disable some breakpoints.\n\
8319 Arguments are breakpoint numbers with spaces in between.\n\
8320 To disable all breakpoints, give no argument.\n\
8321 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8323 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8324 Disable some breakpoints.\n\
8325 Arguments are breakpoint numbers with spaces in between.\n\
8326 To disable all breakpoints, give no argument.\n\
8327 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8328 This command may be abbreviated \"disable\"."),
8331 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8332 Delete some breakpoints or auto-display expressions.\n\
8333 Arguments are breakpoint numbers with spaces in between.\n\
8334 To delete all breakpoints, give no argument.\n\
8336 Also a prefix command for deletion of other GDB objects.\n\
8337 The \"unset\" command is also an alias for \"delete\"."),
8338 &deletelist
, "delete ", 1, &cmdlist
);
8339 add_com_alias ("d", "delete", class_breakpoint
, 1);
8340 add_com_alias ("del", "delete", class_breakpoint
, 1);
8342 add_com ("db", class_breakpoint
, delete_command
, _("\
8343 Delete some breakpoints.\n\
8344 Arguments are breakpoint numbers with spaces in between.\n\
8345 To delete all breakpoints, give no argument.\n"));
8347 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8348 Delete some breakpoints or auto-display expressions.\n\
8349 Arguments are breakpoint numbers with spaces in between.\n\
8350 To delete all breakpoints, give no argument.\n\
8351 This command may be abbreviated \"delete\"."),
8354 add_com ("clear", class_breakpoint
, clear_command
, _("\
8355 Clear breakpoint at specified line or function.\n\
8356 Argument may be line number, function name, or \"*\" and an address.\n\
8357 If line number is specified, all breakpoints in that line are cleared.\n\
8358 If function is specified, breakpoints at beginning of function are cleared.\n\
8359 If an address is specified, breakpoints at that address are cleared.\n\
8361 With no argument, clears all breakpoints in the line that the selected frame\n\
8364 See also the \"delete\" command which clears breakpoints by number."));
8366 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8367 Set breakpoint at specified line or function.\n"
8368 BREAK_ARGS_HELP ("break")));
8369 set_cmd_completer (c
, location_completer
);
8371 add_com_alias ("b", "break", class_run
, 1);
8372 add_com_alias ("br", "break", class_run
, 1);
8373 add_com_alias ("bre", "break", class_run
, 1);
8374 add_com_alias ("brea", "break", class_run
, 1);
8378 add_com_alias ("ba", "break", class_breakpoint
, 1);
8379 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8384 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8385 Break in function/address or break at a line in the current file."),
8386 &stoplist
, "stop ", 1, &cmdlist
);
8387 add_cmd ("in", class_breakpoint
, stopin_command
,
8388 _("Break in function or address."), &stoplist
);
8389 add_cmd ("at", class_breakpoint
, stopat_command
,
8390 _("Break at a line in the current file."), &stoplist
);
8391 add_com ("status", class_info
, breakpoints_info
, _("\
8392 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8393 The \"Type\" column indicates one of:\n\
8394 \tbreakpoint - normal breakpoint\n\
8395 \twatchpoint - watchpoint\n\
8396 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8397 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8398 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8399 address and file/line number respectively.\n\
8401 Convenience variable \"$_\" and default examine address for \"x\"\n\
8402 are set to the address of the last breakpoint listed unless the command\n\
8403 is prefixed with \"server \".\n\n\
8404 Convenience variable \"$bpnum\" contains the number of the last\n\
8408 add_info ("breakpoints", breakpoints_info
, _("\
8409 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8410 The \"Type\" column indicates one of:\n\
8411 \tbreakpoint - normal breakpoint\n\
8412 \twatchpoint - watchpoint\n\
8413 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8414 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8415 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8416 address and file/line number respectively.\n\
8418 Convenience variable \"$_\" and default examine address for \"x\"\n\
8419 are set to the address of the last breakpoint listed unless the command\n\
8420 is prefixed with \"server \".\n\n\
8421 Convenience variable \"$bpnum\" contains the number of the last\n\
8425 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8426 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8427 The \"Type\" column indicates one of:\n\
8428 \tbreakpoint - normal breakpoint\n\
8429 \twatchpoint - watchpoint\n\
8430 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8431 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8432 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8433 address and file/line number respectively.\n\
8435 Convenience variable \"$_\" and default examine address for \"x\"\n\
8436 are set to the address of the last breakpoint listed unless the command\n\
8437 is prefixed with \"server \".\n\n\
8438 Convenience variable \"$bpnum\" contains the number of the last\n\
8441 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8442 Status of all breakpoints, or breakpoint number NUMBER.\n\
8443 The \"Type\" column indicates one of:\n\
8444 \tbreakpoint - normal breakpoint\n\
8445 \twatchpoint - watchpoint\n\
8446 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8447 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8448 \tuntil - internal breakpoint used by the \"until\" command\n\
8449 \tfinish - internal breakpoint used by the \"finish\" command\n\
8450 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8451 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8452 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8453 address and file/line number respectively.\n\
8455 Convenience variable \"$_\" and default examine address for \"x\"\n\
8456 are set to the address of the last breakpoint listed unless the command\n\
8457 is prefixed with \"server \".\n\n\
8458 Convenience variable \"$bpnum\" contains the number of the last\n\
8460 &maintenanceinfolist
);
8462 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
8463 Set catchpoints to catch events."),
8464 &catch_cmdlist
, "catch ",
8465 0/*allow-unknown*/, &cmdlist
);
8467 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
8468 Set temporary catchpoints to catch events."),
8469 &tcatch_cmdlist
, "tcatch ",
8470 0/*allow-unknown*/, &cmdlist
);
8472 /* Add catch and tcatch sub-commands. */
8473 add_catch_command ("catch", _("\
8474 Catch an exception, when caught.\n\
8475 With an argument, catch only exceptions with the given name."),
8476 catch_catch_command
,
8479 add_catch_command ("throw", _("\
8480 Catch an exception, when thrown.\n\
8481 With an argument, catch only exceptions with the given name."),
8482 catch_throw_command
,
8485 add_catch_command ("fork", _("Catch calls to fork."),
8486 catch_fork_command_1
,
8487 (void *) (uintptr_t) catch_fork_permanent
,
8488 (void *) (uintptr_t) catch_fork_temporary
);
8489 add_catch_command ("vfork", _("Catch calls to vfork."),
8490 catch_fork_command_1
,
8491 (void *) (uintptr_t) catch_vfork_permanent
,
8492 (void *) (uintptr_t) catch_vfork_temporary
);
8493 add_catch_command ("exec", _("Catch calls to exec."),
8494 catch_exec_command_1
,
8497 add_catch_command ("load", _("\
8498 Catch library loads.\n\
8499 With an argument, catch only loads of that library."),
8500 catch_load_command_1
,
8503 add_catch_command ("unload", _("\
8504 Catch library unloads.\n\
8505 With an argument, catch only unloads of that library."),
8506 catch_unload_command_1
,
8509 add_catch_command ("exception", _("\
8510 Catch Ada exceptions, when raised.\n\
8511 With an argument, catch only exceptions with the given name."),
8512 catch_ada_exception_command
,
8515 add_catch_command ("assert", _("\
8516 Catch failed Ada assertions, when raised.\n\
8517 With an argument, catch only exceptions with the given name."),
8518 catch_assert_command
,
8522 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8523 Set a watchpoint for an expression.\n\
8524 A watchpoint stops execution of your program whenever the value of\n\
8525 an expression changes."));
8526 set_cmd_completer (c
, expression_completer
);
8528 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8529 Set a read watchpoint for an expression.\n\
8530 A watchpoint stops execution of your program whenever the value of\n\
8531 an expression is read."));
8532 set_cmd_completer (c
, expression_completer
);
8534 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8535 Set a watchpoint for an expression.\n\
8536 A watchpoint stops execution of your program whenever the value of\n\
8537 an expression is either read or written."));
8538 set_cmd_completer (c
, expression_completer
);
8540 add_info ("watchpoints", breakpoints_info
,
8541 _("Synonym for ``info breakpoints''."));
8544 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8545 respond to changes - contrary to the description. */
8546 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8547 &can_use_hw_watchpoints
, _("\
8548 Set debugger's willingness to use watchpoint hardware."), _("\
8549 Show debugger's willingness to use watchpoint hardware."), _("\
8550 If zero, gdb will not use hardware for new watchpoints, even if\n\
8551 such is available. (However, any hardware watchpoints that were\n\
8552 created before setting this to nonzero, will continue to use watchpoint\n\
8555 show_can_use_hw_watchpoints
,
8556 &setlist
, &showlist
);
8558 can_use_hw_watchpoints
= 1;
8560 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8561 Breakpoint specific settings\n\
8562 Configure various breakpoint-specific variables such as\n\
8563 pending breakpoint behavior"),
8564 &breakpoint_set_cmdlist
, "set breakpoint ",
8565 0/*allow-unknown*/, &setlist
);
8566 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8567 Breakpoint specific settings\n\
8568 Configure various breakpoint-specific variables such as\n\
8569 pending breakpoint behavior"),
8570 &breakpoint_show_cmdlist
, "show breakpoint ",
8571 0/*allow-unknown*/, &showlist
);
8573 add_setshow_auto_boolean_cmd ("pending", no_class
,
8574 &pending_break_support
, _("\
8575 Set debugger's behavior regarding pending breakpoints."), _("\
8576 Show debugger's behavior regarding pending breakpoints."), _("\
8577 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8578 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8579 an error. If auto, an unrecognized breakpoint location results in a\n\
8580 user-query to see if a pending breakpoint should be created."),
8582 show_pending_break_support
,
8583 &breakpoint_set_cmdlist
,
8584 &breakpoint_show_cmdlist
);
8586 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8588 add_setshow_boolean_cmd ("auto-hw", no_class
,
8589 &automatic_hardware_breakpoints
, _("\
8590 Set automatic usage of hardware breakpoints."), _("\
8591 Show automatic usage of hardware breakpoints."), _("\
8592 If set, the debugger will automatically use hardware breakpoints for\n\
8593 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8594 a warning will be emitted for such breakpoints."),
8596 show_automatic_hardware_breakpoints
,
8597 &breakpoint_set_cmdlist
,
8598 &breakpoint_show_cmdlist
);
8600 add_setshow_enum_cmd ("always-inserted", class_support
,
8601 always_inserted_enums
, &always_inserted_mode
, _("\
8602 Set mode for inserting breakpoints."), _("\
8603 Show mode for inserting breakpoints."), _("\
8604 When this mode is off, breakpoints are inserted in inferior when it is\n\
8605 resumed, and removed when execution stops. When this mode is on,\n\
8606 breakpoints are inserted immediately and removed only when the user\n\
8607 deletes the breakpoint. When this mode is auto (which is the default),\n\
8608 the behaviour depends on the non-stop setting (see help set non-stop).\n\
8609 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
8610 behaves as if always-inserted mode is on; if gdb is controlling the\n\
8611 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
8613 &show_always_inserted_mode
,
8614 &breakpoint_set_cmdlist
,
8615 &breakpoint_show_cmdlist
);
8617 automatic_hardware_breakpoints
= 1;