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
, struct obj_section
*, 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
)
1753 if (bpt
->owner
->enable_state
!= bp_permanent
)
1756 ALL_BREAKPOINTS_SAFE (b
, temp
)
1761 case bp_watchpoint_scope
:
1763 /* If the call dummy breakpoint is at the entry point it will
1764 cause problems when the inferior is rerun, so we better
1767 Also get rid of scope breakpoints. */
1768 delete_breakpoint (b
);
1772 case bp_hardware_watchpoint
:
1773 case bp_read_watchpoint
:
1774 case bp_access_watchpoint
:
1776 /* Likewise for watchpoints on local expressions. */
1777 if (b
->exp_valid_block
!= NULL
)
1778 delete_breakpoint (b
);
1779 else if (context
== inf_starting
)
1781 /* Reset val field to force reread of starting value
1782 in insert_breakpoints. */
1784 value_free (b
->val
);
1795 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1796 exists at PC. It returns ordinary_breakpoint_here if it's an
1797 ordinary breakpoint, or permanent_breakpoint_here if it's a
1798 permanent breakpoint.
1799 - When continuing from a location with an ordinary breakpoint, we
1800 actually single step once before calling insert_breakpoints.
1801 - When continuing from a localion with a permanent breakpoint, we
1802 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1803 the target, to advance the PC past the breakpoint. */
1805 enum breakpoint_here
1806 breakpoint_here_p (CORE_ADDR pc
)
1808 const struct bp_location
*bpt
;
1809 int any_breakpoint_here
= 0;
1811 ALL_BP_LOCATIONS (bpt
)
1813 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1814 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1817 if ((breakpoint_enabled (bpt
->owner
)
1818 || bpt
->owner
->enable_state
== bp_permanent
)
1819 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1821 if (overlay_debugging
1822 && section_is_overlay (bpt
->section
)
1823 && !section_is_mapped (bpt
->section
))
1824 continue; /* unmapped overlay -- can't be a match */
1825 else if (bpt
->owner
->enable_state
== bp_permanent
)
1826 return permanent_breakpoint_here
;
1828 any_breakpoint_here
= 1;
1832 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1836 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1837 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1838 This does not check for single-step breakpoints, which are
1839 inserted and removed using direct target manipulation. */
1842 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1844 const struct bp_location
*bpt
;
1846 ALL_BP_LOCATIONS (bpt
)
1848 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1849 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1853 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1855 if (overlay_debugging
1856 && section_is_overlay (bpt
->section
)
1857 && !section_is_mapped (bpt
->section
))
1858 continue; /* unmapped overlay -- can't be a match */
1866 /* Returns non-zero iff there's either regular breakpoint
1867 or a single step breakpoint inserted at PC. */
1870 breakpoint_inserted_here_p (CORE_ADDR pc
)
1872 if (regular_breakpoint_inserted_here_p (pc
))
1875 if (single_step_breakpoint_inserted_here_p (pc
))
1881 /* This function returns non-zero iff there is a software breakpoint
1885 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1887 const struct bp_location
*bpt
;
1888 int any_breakpoint_here
= 0;
1890 ALL_BP_LOCATIONS (bpt
)
1892 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1896 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1898 if (overlay_debugging
1899 && section_is_overlay (bpt
->section
)
1900 && !section_is_mapped (bpt
->section
))
1901 continue; /* unmapped overlay -- can't be a match */
1907 /* Also check for software single-step breakpoints. */
1908 if (single_step_breakpoint_inserted_here_p (pc
))
1914 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1915 PC is valid for process/thread PTID. */
1918 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1920 const struct bp_location
*bpt
;
1923 thread
= pid_to_thread_id (ptid
);
1925 ALL_BP_LOCATIONS (bpt
)
1927 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1928 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1931 if ((breakpoint_enabled (bpt
->owner
)
1932 || bpt
->owner
->enable_state
== bp_permanent
)
1933 && bpt
->address
== pc
1934 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1936 if (overlay_debugging
1937 && section_is_overlay (bpt
->section
)
1938 && !section_is_mapped (bpt
->section
))
1939 continue; /* unmapped overlay -- can't be a match */
1949 /* bpstat stuff. External routines' interfaces are documented
1953 ep_is_catchpoint (struct breakpoint
*ep
)
1956 (ep
->type
== bp_catch_load
)
1957 || (ep
->type
== bp_catch_unload
)
1958 || (ep
->type
== bp_catch_fork
)
1959 || (ep
->type
== bp_catch_vfork
)
1960 || (ep
->type
== bp_catch_exec
);
1962 /* ??rehrauer: Add more kinds here, as are implemented... */
1966 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1969 (ep
->type
== bp_catch_load
)
1970 || (ep
->type
== bp_catch_unload
);
1974 bpstat_free (bpstat bs
)
1976 if (bs
->old_val
!= NULL
)
1977 value_free (bs
->old_val
);
1978 free_command_lines (&bs
->commands
);
1982 /* Clear a bpstat so that it says we are not at any breakpoint.
1983 Also free any storage that is part of a bpstat. */
1986 bpstat_clear (bpstat
*bsp
)
2003 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2004 is part of the bpstat is copied as well. */
2007 bpstat_copy (bpstat bs
)
2011 bpstat retval
= NULL
;
2016 for (; bs
!= NULL
; bs
= bs
->next
)
2018 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2019 memcpy (tmp
, bs
, sizeof (*tmp
));
2020 if (bs
->commands
!= NULL
)
2021 tmp
->commands
= copy_command_lines (bs
->commands
);
2022 if (bs
->old_val
!= NULL
)
2024 tmp
->old_val
= value_copy (bs
->old_val
);
2025 release_value (tmp
->old_val
);
2029 /* This is the first thing in the chain. */
2039 /* Find the bpstat associated with this breakpoint */
2042 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2047 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2049 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2055 /* Find a step_resume breakpoint associated with this bpstat.
2056 (If there are multiple step_resume bp's on the list, this function
2057 will arbitrarily pick one.)
2059 It is an error to use this function if BPSTAT doesn't contain a
2060 step_resume breakpoint.
2062 See wait_for_inferior's use of this function. */
2064 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2068 gdb_assert (bsp
!= NULL
);
2070 current_thread
= pid_to_thread_id (inferior_ptid
);
2072 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2074 if ((bsp
->breakpoint_at
!= NULL
) &&
2075 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2076 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2077 bsp
->breakpoint_at
->owner
->thread
== -1))
2078 return bsp
->breakpoint_at
->owner
;
2081 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2085 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2086 at. *BSP upon return is a bpstat which points to the remaining
2087 breakpoints stopped at (but which is not guaranteed to be good for
2088 anything but further calls to bpstat_num).
2089 Return 0 if passed a bpstat which does not indicate any breakpoints.
2090 Return -1 if stopped at a breakpoint that has been deleted since
2092 Return 1 otherwise. */
2095 bpstat_num (bpstat
*bsp
, int *num
)
2097 struct breakpoint
*b
;
2100 return 0; /* No more breakpoint values */
2102 /* We assume we'll never have several bpstats that
2103 correspond to a single breakpoint -- otherwise,
2104 this function might return the same number more
2105 than once and this will look ugly. */
2106 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2107 *bsp
= (*bsp
)->next
;
2109 return -1; /* breakpoint that's been deleted since */
2111 *num
= b
->number
; /* We have its number */
2115 /* Modify BS so that the actions will not be performed. */
2118 bpstat_clear_actions (bpstat bs
)
2120 for (; bs
!= NULL
; bs
= bs
->next
)
2122 free_command_lines (&bs
->commands
);
2123 if (bs
->old_val
!= NULL
)
2125 value_free (bs
->old_val
);
2131 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2133 cleanup_executing_breakpoints (void *ignore
)
2135 executing_breakpoint_commands
= 0;
2138 /* Execute all the commands associated with all the breakpoints at this
2139 location. Any of these commands could cause the process to proceed
2140 beyond this point, etc. We look out for such changes by checking
2141 the global "breakpoint_proceeded" after each command.
2143 Returns true if a breakpoint command resumed the inferior. In that
2144 case, it is the caller's responsibility to recall it again with the
2145 bpstat of the current thread. */
2148 bpstat_do_actions_1 (bpstat
*bsp
)
2151 struct cleanup
*old_chain
;
2154 /* Avoid endless recursion if a `source' command is contained
2156 if (executing_breakpoint_commands
)
2159 executing_breakpoint_commands
= 1;
2160 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2162 /* This pointer will iterate over the list of bpstat's. */
2165 breakpoint_proceeded
= 0;
2166 for (; bs
!= NULL
; bs
= bs
->next
)
2168 struct command_line
*cmd
;
2169 struct cleanup
*this_cmd_tree_chain
;
2171 /* Take ownership of the BSP's command tree, if it has one.
2173 The command tree could legitimately contain commands like
2174 'step' and 'next', which call clear_proceed_status, which
2175 frees stop_bpstat's command tree. To make sure this doesn't
2176 free the tree we're executing out from under us, we need to
2177 take ownership of the tree ourselves. Since a given bpstat's
2178 commands are only executed once, we don't need to copy it; we
2179 can clear the pointer in the bpstat, and make sure we free
2180 the tree when we're done. */
2183 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2187 execute_control_command (cmd
);
2189 if (breakpoint_proceeded
)
2195 /* We can free this command tree now. */
2196 do_cleanups (this_cmd_tree_chain
);
2198 if (breakpoint_proceeded
)
2200 if (target_can_async_p ())
2201 /* If we are in async mode, then the target might be still
2202 running, not stopped at any breakpoint, so nothing for
2203 us to do here -- just return to the event loop. */
2206 /* In sync mode, when execute_control_command returns
2207 we're already standing on the next breakpoint.
2208 Breakpoint commands for that stop were not run, since
2209 execute_command does not run breakpoint commands --
2210 only command_line_handler does, but that one is not
2211 involved in execution of breakpoint commands. So, we
2212 can now execute breakpoint commands. It should be
2213 noted that making execute_command do bpstat actions is
2214 not an option -- in this case we'll have recursive
2215 invocation of bpstat for each breakpoint with a
2216 command, and can easily blow up GDB stack. Instead, we
2217 return true, which will trigger the caller to recall us
2218 with the new stop_bpstat. */
2223 do_cleanups (old_chain
);
2228 bpstat_do_actions (void)
2230 /* Do any commands attached to breakpoint we are stopped at. */
2231 while (!ptid_equal (inferior_ptid
, null_ptid
)
2232 && target_has_execution
2233 && !is_exited (inferior_ptid
)
2234 && !is_executing (inferior_ptid
))
2235 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2236 and only return when it is stopped at the next breakpoint, we
2237 keep doing breakpoint actions until it returns false to
2238 indicate the inferior was not resumed. */
2239 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2243 /* Print out the (old or new) value associated with a watchpoint. */
2246 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2249 fprintf_unfiltered (stream
, _("<unreadable>"));
2251 value_print (val
, stream
, 0, Val_pretty_default
);
2254 /* This is the normal print function for a bpstat. In the future,
2255 much of this logic could (should?) be moved to bpstat_stop_status,
2256 by having it set different print_it values.
2258 Current scheme: When we stop, bpstat_print() is called. It loops
2259 through the bpstat list of things causing this stop, calling the
2260 print_bp_stop_message function on each one. The behavior of the
2261 print_bp_stop_message function depends on the print_it field of
2262 bpstat. If such field so indicates, call this function here.
2264 Return values from this routine (ultimately used by bpstat_print()
2265 and normal_stop() to decide what to do):
2266 PRINT_NOTHING: Means we already printed all we needed to print,
2267 don't print anything else.
2268 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2269 that something to be followed by a location.
2270 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2271 that something to be followed by a location.
2272 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2275 static enum print_stop_action
2276 print_it_typical (bpstat bs
)
2278 struct cleanup
*old_chain
, *ui_out_chain
;
2279 struct breakpoint
*b
;
2280 const struct bp_location
*bl
;
2281 struct ui_stream
*stb
;
2283 stb
= ui_out_stream_new (uiout
);
2284 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2285 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2286 which has since been deleted. */
2287 if (bs
->breakpoint_at
== NULL
)
2288 return PRINT_UNKNOWN
;
2289 bl
= bs
->breakpoint_at
;
2295 case bp_hardware_breakpoint
:
2296 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2297 if (bl
->address
!= bl
->requested_address
)
2298 breakpoint_adjustment_warning (bl
->requested_address
,
2301 annotate_breakpoint (b
->number
);
2303 ui_out_text (uiout
, "\nTemporary breakpoint ");
2305 ui_out_text (uiout
, "\nBreakpoint ");
2306 if (ui_out_is_mi_like_p (uiout
))
2308 ui_out_field_string (uiout
, "reason",
2309 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2310 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2312 ui_out_field_int (uiout
, "bkptno", b
->number
);
2313 ui_out_text (uiout
, ", ");
2314 return PRINT_SRC_AND_LOC
;
2317 case bp_shlib_event
:
2318 /* Did we stop because the user set the stop_on_solib_events
2319 variable? (If so, we report this as a generic, "Stopped due
2320 to shlib event" message.) */
2321 printf_filtered (_("Stopped due to shared library event\n"));
2322 return PRINT_NOTHING
;
2325 case bp_thread_event
:
2326 /* Not sure how we will get here.
2327 GDB should not stop for these breakpoints. */
2328 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2329 return PRINT_NOTHING
;
2332 case bp_overlay_event
:
2333 /* By analogy with the thread event, GDB should not stop for these. */
2334 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2335 return PRINT_NOTHING
;
2339 annotate_catchpoint (b
->number
);
2340 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2342 b
->triggered_dll_pathname
);
2343 return PRINT_SRC_AND_LOC
;
2346 case bp_catch_unload
:
2347 annotate_catchpoint (b
->number
);
2348 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2350 b
->triggered_dll_pathname
);
2351 return PRINT_SRC_AND_LOC
;
2355 annotate_catchpoint (b
->number
);
2356 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2358 ptid_get_pid (b
->forked_inferior_pid
));
2359 return PRINT_SRC_AND_LOC
;
2362 case bp_catch_vfork
:
2363 annotate_catchpoint (b
->number
);
2364 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2366 ptid_get_pid (b
->forked_inferior_pid
));
2367 return PRINT_SRC_AND_LOC
;
2371 annotate_catchpoint (b
->number
);
2372 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2375 return PRINT_SRC_AND_LOC
;
2379 case bp_hardware_watchpoint
:
2380 annotate_watchpoint (b
->number
);
2381 if (ui_out_is_mi_like_p (uiout
))
2384 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2386 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2387 ui_out_text (uiout
, "\nOld value = ");
2388 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2389 ui_out_field_stream (uiout
, "old", stb
);
2390 ui_out_text (uiout
, "\nNew value = ");
2391 watchpoint_value_print (b
->val
, stb
->stream
);
2392 ui_out_field_stream (uiout
, "new", stb
);
2393 do_cleanups (ui_out_chain
);
2394 ui_out_text (uiout
, "\n");
2395 /* More than one watchpoint may have been triggered. */
2396 return PRINT_UNKNOWN
;
2399 case bp_read_watchpoint
:
2400 if (ui_out_is_mi_like_p (uiout
))
2403 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2405 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2406 ui_out_text (uiout
, "\nValue = ");
2407 watchpoint_value_print (b
->val
, stb
->stream
);
2408 ui_out_field_stream (uiout
, "value", stb
);
2409 do_cleanups (ui_out_chain
);
2410 ui_out_text (uiout
, "\n");
2411 return PRINT_UNKNOWN
;
2414 case bp_access_watchpoint
:
2415 if (bs
->old_val
!= NULL
)
2417 annotate_watchpoint (b
->number
);
2418 if (ui_out_is_mi_like_p (uiout
))
2421 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
, "\nOld value = ");
2425 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2426 ui_out_field_stream (uiout
, "old", stb
);
2427 ui_out_text (uiout
, "\nNew value = ");
2432 if (ui_out_is_mi_like_p (uiout
))
2435 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2436 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2437 ui_out_text (uiout
, "\nValue = ");
2439 watchpoint_value_print (b
->val
, stb
->stream
);
2440 ui_out_field_stream (uiout
, "new", stb
);
2441 do_cleanups (ui_out_chain
);
2442 ui_out_text (uiout
, "\n");
2443 return PRINT_UNKNOWN
;
2446 /* Fall through, we don't deal with these types of breakpoints
2450 if (ui_out_is_mi_like_p (uiout
))
2453 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2454 return PRINT_UNKNOWN
;
2458 if (ui_out_is_mi_like_p (uiout
))
2461 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2462 return PRINT_UNKNOWN
;
2467 case bp_longjmp_resume
:
2468 case bp_step_resume
:
2469 case bp_watchpoint_scope
:
2472 return PRINT_UNKNOWN
;
2476 /* Generic routine for printing messages indicating why we
2477 stopped. The behavior of this function depends on the value
2478 'print_it' in the bpstat structure. Under some circumstances we
2479 may decide not to print anything here and delegate the task to
2482 static enum print_stop_action
2483 print_bp_stop_message (bpstat bs
)
2485 switch (bs
->print_it
)
2488 /* Nothing should be printed for this bpstat entry. */
2489 return PRINT_UNKNOWN
;
2493 /* We still want to print the frame, but we already printed the
2494 relevant messages. */
2495 return PRINT_SRC_AND_LOC
;
2498 case print_it_normal
:
2500 const struct bp_location
*bl
= bs
->breakpoint_at
;
2501 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2503 /* Normal case. Call the breakpoint's print_it method, or
2504 print_it_typical. */
2505 /* FIXME: how breakpoint can ever be NULL here? */
2506 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2507 return b
->ops
->print_it (b
);
2509 return print_it_typical (bs
);
2514 internal_error (__FILE__
, __LINE__
,
2515 _("print_bp_stop_message: unrecognized enum value"));
2520 /* Print a message indicating what happened. This is called from
2521 normal_stop(). The input to this routine is the head of the bpstat
2522 list - a list of the eventpoints that caused this stop. This
2523 routine calls the generic print routine for printing a message
2524 about reasons for stopping. This will print (for example) the
2525 "Breakpoint n," part of the output. The return value of this
2528 PRINT_UNKNOWN: Means we printed nothing
2529 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2530 code to print the location. An example is
2531 "Breakpoint 1, " which should be followed by
2533 PRINT_SRC_ONLY: Means we printed something, but there is no need
2534 to also print the location part of the message.
2535 An example is the catch/throw messages, which
2536 don't require a location appended to the end.
2537 PRINT_NOTHING: We have done some printing and we don't need any
2538 further info to be printed.*/
2540 enum print_stop_action
2541 bpstat_print (bpstat bs
)
2545 /* Maybe another breakpoint in the chain caused us to stop.
2546 (Currently all watchpoints go on the bpstat whether hit or not.
2547 That probably could (should) be changed, provided care is taken
2548 with respect to bpstat_explains_signal). */
2549 for (; bs
; bs
= bs
->next
)
2551 val
= print_bp_stop_message (bs
);
2552 if (val
== PRINT_SRC_ONLY
2553 || val
== PRINT_SRC_AND_LOC
2554 || val
== PRINT_NOTHING
)
2558 /* We reached the end of the chain, or we got a null BS to start
2559 with and nothing was printed. */
2560 return PRINT_UNKNOWN
;
2563 /* Evaluate the expression EXP and return 1 if value is zero.
2564 This is used inside a catch_errors to evaluate the breakpoint condition.
2565 The argument is a "struct expression *" that has been cast to char * to
2566 make it pass through catch_errors. */
2569 breakpoint_cond_eval (void *exp
)
2571 struct value
*mark
= value_mark ();
2572 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2573 value_free_to_mark (mark
);
2577 /* Allocate a new bpstat and chain it to the current one. */
2580 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2584 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2586 bs
->breakpoint_at
= bl
;
2587 /* If the condition is false, etc., don't do the commands. */
2588 bs
->commands
= NULL
;
2590 bs
->print_it
= print_it_normal
;
2594 /* The target has stopped with waitstatus WS. Check if any hardware
2595 watchpoints have triggered, according to the target. */
2598 watchpoints_triggered (struct target_waitstatus
*ws
)
2600 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2602 struct breakpoint
*b
;
2604 if (!stopped_by_watchpoint
)
2606 /* We were not stopped by a watchpoint. Mark all watchpoints
2607 as not triggered. */
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_no
;
2617 if (!target_stopped_data_address (¤t_target
, &addr
))
2619 /* We were stopped by a watchpoint, but we don't know where.
2620 Mark all watchpoints as unknown. */
2622 if (b
->type
== bp_hardware_watchpoint
2623 || b
->type
== bp_read_watchpoint
2624 || b
->type
== bp_access_watchpoint
)
2625 b
->watchpoint_triggered
= watch_triggered_unknown
;
2627 return stopped_by_watchpoint
;
2630 /* The target could report the data address. Mark watchpoints
2631 affected by this data address as triggered, and all others as not
2635 if (b
->type
== bp_hardware_watchpoint
2636 || b
->type
== bp_read_watchpoint
2637 || b
->type
== bp_access_watchpoint
)
2639 struct bp_location
*loc
;
2642 b
->watchpoint_triggered
= watch_triggered_no
;
2643 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2644 /* Exact match not required. Within range is
2646 if (target_watchpoint_addr_within_range (¤t_target
,
2650 b
->watchpoint_triggered
= watch_triggered_yes
;
2658 /* Possible return values for watchpoint_check (this can't be an enum
2659 because of check_errors). */
2660 /* The watchpoint has been deleted. */
2661 #define WP_DELETED 1
2662 /* The value has changed. */
2663 #define WP_VALUE_CHANGED 2
2664 /* The value has not changed. */
2665 #define WP_VALUE_NOT_CHANGED 3
2667 #define BP_TEMPFLAG 1
2668 #define BP_HARDWAREFLAG 2
2670 /* Check watchpoint condition. */
2673 watchpoint_check (void *p
)
2675 bpstat bs
= (bpstat
) p
;
2676 struct breakpoint
*b
;
2677 struct frame_info
*fr
;
2678 int within_current_scope
;
2680 b
= bs
->breakpoint_at
->owner
;
2682 if (b
->exp_valid_block
== NULL
)
2683 within_current_scope
= 1;
2686 /* There is no current frame at this moment. If we're going to have
2687 any chance of handling watchpoints on local variables, we'll need
2688 the frame chain (so we can determine if we're in scope). */
2689 reinit_frame_cache ();
2690 fr
= frame_find_by_id (b
->watchpoint_frame
);
2691 within_current_scope
= (fr
!= NULL
);
2693 /* If we've gotten confused in the unwinder, we might have
2694 returned a frame that can't describe this variable. */
2695 if (within_current_scope
2696 && (block_linkage_function (b
->exp_valid_block
)
2697 != get_frame_function (fr
)))
2698 within_current_scope
= 0;
2700 /* in_function_epilogue_p() returns a non-zero value if we're still
2701 in the function but the stack frame has already been invalidated.
2702 Since we can't rely on the values of local variables after the
2703 stack has been destroyed, we are treating the watchpoint in that
2704 state as `not changed' without further checking.
2706 vinschen/2003-09-04: The former implementation left out the case
2707 that the watchpoint frame couldn't be found by frame_find_by_id()
2708 because the current PC is currently in an epilogue. Calling
2709 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2710 if ((!within_current_scope
|| fr
== get_current_frame ())
2711 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2712 return WP_VALUE_NOT_CHANGED
;
2713 if (fr
&& within_current_scope
)
2714 /* If we end up stopping, the current frame will get selected
2715 in normal_stop. So this call to select_frame won't affect
2720 if (within_current_scope
)
2722 /* We use value_{,free_to_}mark because it could be a
2723 *long* time before we return to the command level and
2724 call free_all_values. We can't call free_all_values because
2725 we might be in the middle of evaluating a function call. */
2727 struct value
*mark
= value_mark ();
2728 struct value
*new_val
;
2730 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2731 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2732 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2734 if (new_val
!= NULL
)
2736 release_value (new_val
);
2737 value_free_to_mark (mark
);
2739 bs
->old_val
= b
->val
;
2742 /* We will stop here */
2743 return WP_VALUE_CHANGED
;
2747 /* Nothing changed, don't do anything. */
2748 value_free_to_mark (mark
);
2749 /* We won't stop here */
2750 return WP_VALUE_NOT_CHANGED
;
2755 /* This seems like the only logical thing to do because
2756 if we temporarily ignored the watchpoint, then when
2757 we reenter the block in which it is valid it contains
2758 garbage (in the case of a function, it may have two
2759 garbage values, one before and one after the prologue).
2760 So we can't even detect the first assignment to it and
2761 watch after that (since the garbage may or may not equal
2762 the first value assigned). */
2763 /* We print all the stop information in print_it_typical(), but
2764 in this case, by the time we call print_it_typical() this bp
2765 will be deleted already. So we have no choice but print the
2766 information here. */
2767 if (ui_out_is_mi_like_p (uiout
))
2769 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2770 ui_out_text (uiout
, "\nWatchpoint ");
2771 ui_out_field_int (uiout
, "wpnum", b
->number
);
2772 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2773 which its expression is valid.\n");
2775 if (b
->related_breakpoint
)
2776 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2777 b
->disposition
= disp_del_at_next_stop
;
2783 /* Return true if it looks like target has stopped due to hitting
2784 breakpoint location BL. This function does not check if we
2785 should stop, only if BL explains the stop. */
2787 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2789 struct breakpoint
*b
= bl
->owner
;
2791 if (b
->type
!= bp_watchpoint
2792 && b
->type
!= bp_hardware_watchpoint
2793 && b
->type
!= bp_read_watchpoint
2794 && b
->type
!= bp_access_watchpoint
2795 && b
->type
!= bp_hardware_breakpoint
2796 && b
->type
!= bp_catch_fork
2797 && b
->type
!= bp_catch_vfork
2798 && b
->type
!= bp_catch_exec
) /* a non-watchpoint bp */
2800 if (bl
->address
!= bp_addr
) /* address doesn't match */
2802 if (overlay_debugging
/* unmapped overlay section */
2803 && section_is_overlay (bl
->section
)
2804 && !section_is_mapped (bl
->section
))
2808 /* Continuable hardware watchpoints are treated as non-existent if the
2809 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2810 some data address). Otherwise gdb won't stop on a break instruction
2811 in the code (not from a breakpoint) when a hardware watchpoint has
2812 been defined. Also skip watchpoints which we know did not trigger
2813 (did not match the data address). */
2815 if ((b
->type
== bp_hardware_watchpoint
2816 || b
->type
== bp_read_watchpoint
2817 || b
->type
== bp_access_watchpoint
)
2818 && b
->watchpoint_triggered
== watch_triggered_no
)
2821 if (b
->type
== bp_hardware_breakpoint
)
2823 if (bl
->address
!= bp_addr
)
2825 if (overlay_debugging
/* unmapped overlay section */
2826 && section_is_overlay (bl
->section
)
2827 && !section_is_mapped (bl
->section
))
2831 /* Is this a catchpoint of a load or unload? If so, did we
2832 get a load or unload of the specified library? If not,
2834 if ((b
->type
== bp_catch_load
)
2835 #if defined(SOLIB_HAVE_LOAD_EVENT)
2836 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2837 || ((b
->dll_pathname
!= NULL
)
2838 && (strcmp (b
->dll_pathname
,
2839 SOLIB_LOADED_LIBRARY_PATHNAME (
2840 PIDGET (inferior_ptid
)))
2846 if ((b
->type
== bp_catch_unload
)
2847 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2848 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2849 || ((b
->dll_pathname
!= NULL
)
2850 && (strcmp (b
->dll_pathname
,
2851 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2852 PIDGET (inferior_ptid
)))
2858 if ((b
->type
== bp_catch_fork
)
2859 && !inferior_has_forked (inferior_ptid
,
2860 &b
->forked_inferior_pid
))
2863 if ((b
->type
== bp_catch_vfork
)
2864 && !inferior_has_vforked (inferior_ptid
,
2865 &b
->forked_inferior_pid
))
2868 if ((b
->type
== bp_catch_exec
)
2869 && !inferior_has_execd (inferior_ptid
, &b
->exec_pathname
))
2875 /* If BS refers to a watchpoint, determine if the watched values
2876 has actually changed, and we should stop. If not, set BS->stop
2879 bpstat_check_watchpoint (bpstat bs
)
2881 const struct bp_location
*bl
= bs
->breakpoint_at
;
2882 struct breakpoint
*b
= bl
->owner
;
2884 if (b
->type
== bp_watchpoint
2885 || b
->type
== bp_read_watchpoint
2886 || b
->type
== bp_access_watchpoint
2887 || b
->type
== bp_hardware_watchpoint
)
2891 int must_check_value
= 0;
2893 if (b
->type
== bp_watchpoint
)
2894 /* For a software watchpoint, we must always check the
2896 must_check_value
= 1;
2897 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2898 /* We have a hardware watchpoint (read, write, or access)
2899 and the target earlier reported an address watched by
2901 must_check_value
= 1;
2902 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2903 && b
->type
== bp_hardware_watchpoint
)
2904 /* We were stopped by a hardware watchpoint, but the target could
2905 not report the data address. We must check the watchpoint's
2906 value. Access and read watchpoints are out of luck; without
2907 a data address, we can't figure it out. */
2908 must_check_value
= 1;
2910 if (must_check_value
)
2912 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2914 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2915 int e
= catch_errors (watchpoint_check
, bs
, message
,
2917 do_cleanups (cleanups
);
2921 /* We've already printed what needs to be printed. */
2922 bs
->print_it
= print_it_done
;
2925 case WP_VALUE_CHANGED
:
2926 if (b
->type
== bp_read_watchpoint
)
2928 /* Don't stop: read watchpoints shouldn't fire if
2929 the value has changed. This is for targets
2930 which cannot set read-only watchpoints. */
2931 bs
->print_it
= print_it_noop
;
2935 case WP_VALUE_NOT_CHANGED
:
2936 if (b
->type
== bp_hardware_watchpoint
2937 || b
->type
== bp_watchpoint
)
2939 /* Don't stop: write watchpoints shouldn't fire if
2940 the value hasn't changed. */
2941 bs
->print_it
= print_it_noop
;
2949 /* Error from catch_errors. */
2950 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2951 if (b
->related_breakpoint
)
2952 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2953 b
->disposition
= disp_del_at_next_stop
;
2954 /* We've already printed what needs to be printed. */
2955 bs
->print_it
= print_it_done
;
2959 else /* must_check_value == 0 */
2961 /* This is a case where some watchpoint(s) triggered, but
2962 not at the address of this watchpoint, or else no
2963 watchpoint triggered after all. So don't print
2964 anything for this watchpoint. */
2965 bs
->print_it
= print_it_noop
;
2972 /* Check conditions (condition proper, frame, thread and ignore count)
2973 of breakpoint referred to by BS. If we should not stop for this
2974 breakpoint, set BS->stop to 0. */
2976 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2978 int thread_id
= pid_to_thread_id (ptid
);
2979 const struct bp_location
*bl
= bs
->breakpoint_at
;
2980 struct breakpoint
*b
= bl
->owner
;
2982 if (frame_id_p (b
->frame_id
)
2983 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2987 int value_is_zero
= 0;
2989 /* If this is a scope breakpoint, mark the associated
2990 watchpoint as triggered so that we will handle the
2991 out-of-scope event. We'll get to the watchpoint next
2993 if (b
->type
== bp_watchpoint_scope
)
2994 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2996 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2998 /* Need to select the frame, with all that implies
2999 so that the conditions will have the right context. */
3000 select_frame (get_current_frame ());
3002 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
3003 "Error in testing breakpoint condition:\n",
3005 /* FIXME-someday, should give breakpoint # */
3008 if (bl
->cond
&& value_is_zero
)
3012 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3016 else if (b
->ignore_count
> 0)
3019 annotate_ignore_count_change ();
3021 /* Increase the hit count even though we don't
3029 /* Get a bpstat associated with having just stopped at address
3030 BP_ADDR in thread PTID.
3032 Determine whether we stopped at a breakpoint, etc, or whether we
3033 don't understand this stop. Result is a chain of bpstat's such that:
3035 if we don't understand the stop, the result is a null pointer.
3037 if we understand why we stopped, the result is not null.
3039 Each element of the chain refers to a particular breakpoint or
3040 watchpoint at which we have stopped. (We may have stopped for
3041 several reasons concurrently.)
3043 Each element of the chain has valid next, breakpoint_at,
3044 commands, FIXME??? fields. */
3047 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3049 struct breakpoint
*b
= NULL
;
3050 const struct bp_location
*bl
;
3051 struct bp_location
*loc
;
3052 /* Root of the chain of bpstat's */
3053 struct bpstats root_bs
[1];
3054 /* Pointer to the last thing in the chain currently. */
3055 bpstat bs
= root_bs
;
3058 ALL_BP_LOCATIONS (bl
)
3062 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3065 /* For hardware watchpoints, we look only at the first location.
3066 The watchpoint_check function will work on entire expression,
3067 not the individual locations. For read watchopints, the
3068 watchpoints_triggered function have checked all locations
3071 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3074 if (!bpstat_check_location (bl
, bp_addr
))
3077 /* Come here if it's a watchpoint, or if the break address matches */
3079 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3081 /* Assume we stop. Should we find watchpoint that is not actually
3082 triggered, or if condition of breakpoint is false, we'll reset
3087 bpstat_check_watchpoint (bs
);
3091 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3092 /* We do not stop for these. */
3095 bpstat_check_breakpoint_conditions (bs
, ptid
);
3101 /* We will stop here */
3102 if (b
->disposition
== disp_disable
)
3104 if (b
->enable_state
!= bp_permanent
)
3105 b
->enable_state
= bp_disabled
;
3106 update_global_location_list (0);
3110 bs
->commands
= b
->commands
;
3112 (strcmp ("silent", bs
->commands
->line
) == 0
3113 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3115 bs
->commands
= bs
->commands
->next
;
3118 bs
->commands
= copy_command_lines (bs
->commands
);
3121 /* Print nothing for this entry if we dont stop or if we dont print. */
3122 if (bs
->stop
== 0 || bs
->print
== 0)
3123 bs
->print_it
= print_it_noop
;
3126 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3128 if (loc
->address
== bp_addr
)
3130 bs
= bpstat_alloc (loc
, bs
);
3131 /* For hits of moribund locations, we should just proceed. */
3134 bs
->print_it
= print_it_noop
;
3138 bs
->next
= NULL
; /* Terminate the chain */
3139 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3141 /* If we aren't stopping, the value of some hardware watchpoint may
3142 not have changed, but the intermediate memory locations we are
3143 watching may have. Don't bother if we're stopping; this will get
3145 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3150 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3152 && bs
->breakpoint_at
->owner
3153 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3154 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3155 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3157 /* remove/insert can invalidate bs->breakpoint_at, if this
3158 location is no longer used by the watchpoint. Prevent
3159 further code from trying to use it. */
3160 bs
->breakpoint_at
= NULL
;
3161 remove_breakpoints ();
3162 insert_breakpoints ();
3166 return root_bs
->next
;
3169 /* Tell what to do about this bpstat. */
3171 bpstat_what (bpstat bs
)
3173 /* Classify each bpstat as one of the following. */
3176 /* This bpstat element has no effect on the main_action. */
3179 /* There was a watchpoint, stop but don't print. */
3182 /* There was a watchpoint, stop and print. */
3185 /* There was a breakpoint but we're not stopping. */
3188 /* There was a breakpoint, stop but don't print. */
3191 /* There was a breakpoint, stop and print. */
3194 /* We hit the longjmp breakpoint. */
3197 /* We hit the longjmp_resume breakpoint. */
3200 /* We hit the step_resume breakpoint. */
3203 /* We hit the shared library event breakpoint. */
3206 /* We caught a shared library event. */
3209 /* This is just used to count how many enums there are. */
3213 /* Here is the table which drives this routine. So that we can
3214 format it pretty, we define some abbreviations for the
3215 enum bpstat_what codes. */
3216 #define kc BPSTAT_WHAT_KEEP_CHECKING
3217 #define ss BPSTAT_WHAT_STOP_SILENT
3218 #define sn BPSTAT_WHAT_STOP_NOISY
3219 #define sgl BPSTAT_WHAT_SINGLE
3220 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3221 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3222 #define sr BPSTAT_WHAT_STEP_RESUME
3223 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3224 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3226 /* "Can't happen." Might want to print an error message.
3227 abort() is not out of the question, but chances are GDB is just
3228 a bit confused, not unusable. */
3229 #define err BPSTAT_WHAT_STOP_NOISY
3231 /* Given an old action and a class, come up with a new action. */
3232 /* One interesting property of this table is that wp_silent is the same
3233 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3234 after stopping, the check for whether to step over a breakpoint
3235 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3236 reference to how we stopped. We retain separate wp_silent and
3237 bp_silent codes in case we want to change that someday.
3239 Another possibly interesting property of this table is that
3240 there's a partial ordering, priority-like, of the actions. Once
3241 you've decided that some action is appropriate, you'll never go
3242 back and decide something of a lower priority is better. The
3245 kc < clr sgl shl shlr slr sn sr ss
3246 sgl < shl shlr slr sn sr ss
3247 slr < err shl shlr sn sr ss
3248 clr < err shl shlr sn sr ss
3255 What I think this means is that we don't need a damned table
3256 here. If you just put the rows and columns in the right order,
3257 it'd look awfully regular. We could simply walk the bpstat list
3258 and choose the highest priority action we find, with a little
3259 logic to handle the 'err' cases. */
3261 /* step_resume entries: a step resume breakpoint overrides another
3262 breakpoint of signal handling (see comment in wait_for_inferior
3263 at where we set the step_resume breakpoint). */
3265 static const enum bpstat_what_main_action
3266 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3269 /* kc ss sn sgl slr clr sr shl shlr
3272 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, shlr
},
3274 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3276 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3278 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, shlr
},
3280 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3282 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3284 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, shlr
},
3286 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, shlr
},
3288 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3290 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3292 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3306 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3307 struct bpstat_what retval
;
3309 retval
.call_dummy
= 0;
3310 for (; bs
!= NULL
; bs
= bs
->next
)
3312 enum class bs_class
= no_effect
;
3313 if (bs
->breakpoint_at
== NULL
)
3314 /* I suspect this can happen if it was a momentary breakpoint
3315 which has since been deleted. */
3317 if (bs
->breakpoint_at
->owner
== NULL
)
3318 bs_class
= bp_nostop
;
3320 switch (bs
->breakpoint_at
->owner
->type
)
3326 case bp_hardware_breakpoint
:
3332 bs_class
= bp_noisy
;
3334 bs_class
= bp_silent
;
3337 bs_class
= bp_nostop
;
3340 case bp_hardware_watchpoint
:
3341 case bp_read_watchpoint
:
3342 case bp_access_watchpoint
:
3346 bs_class
= wp_noisy
;
3348 bs_class
= wp_silent
;
3351 /* There was a watchpoint, but we're not stopping.
3352 This requires no further action. */
3353 bs_class
= no_effect
;
3356 bs_class
= long_jump
;
3358 case bp_longjmp_resume
:
3359 bs_class
= long_resume
;
3361 case bp_step_resume
:
3364 bs_class
= step_resume
;
3367 /* It is for the wrong frame. */
3368 bs_class
= bp_nostop
;
3370 case bp_watchpoint_scope
:
3371 bs_class
= bp_nostop
;
3373 case bp_shlib_event
:
3374 bs_class
= shlib_event
;
3376 case bp_thread_event
:
3377 case bp_overlay_event
:
3378 bs_class
= bp_nostop
;
3381 case bp_catch_unload
:
3382 /* Only if this catchpoint triggered should we cause the
3383 step-out-of-dld behaviour. Otherwise, we ignore this
3386 bs_class
= catch_shlib_event
;
3388 bs_class
= no_effect
;
3391 case bp_catch_vfork
:
3396 bs_class
= bp_noisy
;
3398 bs_class
= bp_silent
;
3401 /* There was a catchpoint, but we're not stopping.
3402 This requires no further action. */
3403 bs_class
= no_effect
;
3406 /* Make sure the action is stop (silent or noisy),
3407 so infrun.c pops the dummy frame. */
3408 bs_class
= bp_silent
;
3409 retval
.call_dummy
= 1;
3412 current_action
= table
[(int) bs_class
][(int) current_action
];
3414 retval
.main_action
= current_action
;
3418 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3419 without hardware support). This isn't related to a specific bpstat,
3420 just to things like whether watchpoints are set. */
3423 bpstat_should_step (void)
3425 struct breakpoint
*b
;
3427 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3434 /* Given a bpstat that records zero or more triggered eventpoints, this
3435 function returns another bpstat which contains only the catchpoints
3436 on that first list, if any. */
3438 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3440 struct bpstats root_bs
[1];
3441 bpstat bs
= root_bs
;
3442 struct breakpoint
*ep
;
3445 bpstat_clear (cp_list
);
3446 root_bs
->next
= NULL
;
3448 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3450 /* Is this eventpoint a catchpoint? If not, ignore it. */
3451 ep
= ep_list
->breakpoint_at
->owner
;
3454 if ((ep
->type
!= bp_catch_load
) &&
3455 (ep
->type
!= bp_catch_unload
))
3456 /* pai: (temp) ADD fork/vfork here!! */
3459 /* Yes; add it to the list. */
3460 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3465 #if defined(SOLIB_ADD)
3466 /* Also, for each triggered catchpoint, tag it with the name of
3467 the library that caused this trigger. (We copy the name now,
3468 because it's only guaranteed to be available NOW, when the
3469 catchpoint triggers. Clients who may wish to know the name
3470 later must get it from the catchpoint itself.) */
3471 if (ep
->triggered_dll_pathname
!= NULL
)
3472 xfree (ep
->triggered_dll_pathname
);
3473 if (ep
->type
== bp_catch_load
)
3474 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3475 PIDGET (inferior_ptid
));
3477 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3478 PIDGET (inferior_ptid
));
3480 dll_pathname
= NULL
;
3484 ep
->triggered_dll_pathname
= (char *)
3485 xmalloc (strlen (dll_pathname
) + 1);
3486 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3489 ep
->triggered_dll_pathname
= NULL
;
3495 static void print_breakpoint_location (struct breakpoint
*b
,
3496 struct bp_location
*loc
,
3498 struct ui_stream
*stb
)
3503 = find_pc_sect_function (loc
->address
, loc
->section
);
3506 ui_out_text (uiout
, "in ");
3507 ui_out_field_string (uiout
, "func",
3508 SYMBOL_PRINT_NAME (sym
));
3509 ui_out_wrap_hint (uiout
, wrap_indent
);
3510 ui_out_text (uiout
, " at ");
3512 ui_out_field_string (uiout
, "file", b
->source_file
);
3513 ui_out_text (uiout
, ":");
3515 if (ui_out_is_mi_like_p (uiout
))
3517 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3518 char *fullname
= symtab_to_fullname (sal
.symtab
);
3521 ui_out_field_string (uiout
, "fullname", fullname
);
3524 ui_out_field_int (uiout
, "line", b
->line_number
);
3528 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3532 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3533 ui_out_field_stream (uiout
, "at", stb
);
3537 /* Print B to gdb_stdout. */
3539 print_one_breakpoint_location (struct breakpoint
*b
,
3540 struct bp_location
*loc
,
3542 CORE_ADDR
*last_addr
)
3544 struct command_line
*l
;
3546 struct ep_type_description
3551 static struct ep_type_description bptypes
[] =
3553 {bp_none
, "?deleted?"},
3554 {bp_breakpoint
, "breakpoint"},
3555 {bp_hardware_breakpoint
, "hw breakpoint"},
3556 {bp_until
, "until"},
3557 {bp_finish
, "finish"},
3558 {bp_watchpoint
, "watchpoint"},
3559 {bp_hardware_watchpoint
, "hw watchpoint"},
3560 {bp_read_watchpoint
, "read watchpoint"},
3561 {bp_access_watchpoint
, "acc watchpoint"},
3562 {bp_longjmp
, "longjmp"},
3563 {bp_longjmp_resume
, "longjmp resume"},
3564 {bp_step_resume
, "step resume"},
3565 {bp_watchpoint_scope
, "watchpoint scope"},
3566 {bp_call_dummy
, "call dummy"},
3567 {bp_shlib_event
, "shlib events"},
3568 {bp_thread_event
, "thread events"},
3569 {bp_overlay_event
, "overlay events"},
3570 {bp_catch_load
, "catch load"},
3571 {bp_catch_unload
, "catch unload"},
3572 {bp_catch_fork
, "catch fork"},
3573 {bp_catch_vfork
, "catch vfork"},
3574 {bp_catch_exec
, "catch exec"}
3577 static char bpenables
[] = "nynny";
3578 char wrap_indent
[80];
3579 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3580 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3581 struct cleanup
*bkpt_chain
;
3583 int header_of_multiple
= 0;
3584 int part_of_multiple
= (loc
!= NULL
);
3586 gdb_assert (!loc
|| loc_number
!= 0);
3587 /* See comment in print_one_breakpoint concerning
3588 treatment of breakpoints with single disabled
3592 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3593 header_of_multiple
= 1;
3598 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3602 if (part_of_multiple
)
3605 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3606 ui_out_field_string (uiout
, "number", formatted
);
3611 ui_out_field_int (uiout
, "number", b
->number
);
3616 if (part_of_multiple
)
3617 ui_out_field_skip (uiout
, "type");
3620 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3621 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3622 internal_error (__FILE__
, __LINE__
,
3623 _("bptypes table does not describe type #%d."),
3625 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3630 if (part_of_multiple
)
3631 ui_out_field_skip (uiout
, "disp");
3633 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3638 if (part_of_multiple
)
3639 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3641 ui_out_field_fmt (uiout
, "enabled", "%c",
3642 bpenables
[(int) b
->enable_state
]);
3643 ui_out_spaces (uiout
, 2);
3647 strcpy (wrap_indent
, " ");
3650 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3651 strcat (wrap_indent
, " ");
3653 strcat (wrap_indent
, " ");
3656 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3658 /* Although the print_one can possibly print
3659 all locations, calling it here is not likely
3660 to get any nice result. So, make sure there's
3661 just one location. */
3662 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3663 b
->ops
->print_one (b
, last_addr
);
3669 internal_error (__FILE__
, __LINE__
,
3670 _("print_one_breakpoint: bp_none encountered\n"));
3674 case bp_hardware_watchpoint
:
3675 case bp_read_watchpoint
:
3676 case bp_access_watchpoint
:
3677 /* Field 4, the address, is omitted (which makes the columns
3678 not line up too nicely with the headers, but the effect
3679 is relatively readable). */
3681 ui_out_field_skip (uiout
, "addr");
3683 print_expression (b
->exp
, stb
->stream
);
3684 ui_out_field_stream (uiout
, "what", stb
);
3688 case bp_catch_unload
:
3689 /* Field 4, the address, is omitted (which makes the columns
3690 not line up too nicely with the headers, but the effect
3691 is relatively readable). */
3693 ui_out_field_skip (uiout
, "addr");
3695 if (b
->dll_pathname
== NULL
)
3697 ui_out_field_string (uiout
, "what", "<any library>");
3698 ui_out_spaces (uiout
, 1);
3702 ui_out_text (uiout
, "library \"");
3703 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3704 ui_out_text (uiout
, "\" ");
3709 case bp_catch_vfork
:
3710 /* Field 4, the address, is omitted (which makes the columns
3711 not line up too nicely with the headers, but the effect
3712 is relatively readable). */
3714 ui_out_field_skip (uiout
, "addr");
3716 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
3718 ui_out_text (uiout
, "process ");
3719 ui_out_field_int (uiout
, "what",
3720 ptid_get_pid (b
->forked_inferior_pid
));
3721 ui_out_spaces (uiout
, 1);
3726 /* Field 4, the address, is omitted (which makes the columns
3727 not line up too nicely with the headers, but the effect
3728 is relatively readable). */
3730 ui_out_field_skip (uiout
, "addr");
3732 if (b
->exec_pathname
!= NULL
)
3734 ui_out_text (uiout
, "program \"");
3735 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3736 ui_out_text (uiout
, "\" ");
3741 case bp_hardware_breakpoint
:
3745 case bp_longjmp_resume
:
3746 case bp_step_resume
:
3747 case bp_watchpoint_scope
:
3749 case bp_shlib_event
:
3750 case bp_thread_event
:
3751 case bp_overlay_event
:
3755 if (header_of_multiple
)
3756 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3757 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3758 ui_out_field_string (uiout
, "addr", "<PENDING>");
3760 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3763 if (!header_of_multiple
)
3764 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3766 *last_addr
= b
->loc
->address
;
3770 if (!part_of_multiple
&& b
->thread
!= -1)
3772 /* FIXME: This seems to be redundant and lost here; see the
3773 "stop only in" line a little further down. */
3774 ui_out_text (uiout
, " thread ");
3775 ui_out_field_int (uiout
, "thread", b
->thread
);
3778 ui_out_text (uiout
, "\n");
3780 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3783 ui_out_text (uiout
, "\tstop only in stack frame at ");
3784 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3786 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3787 ui_out_text (uiout
, "\n");
3790 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3792 /* We do not print the condition for Ada exception catchpoints
3793 because the condition is an internal implementation detail
3794 that we do not want to expose to the user. */
3796 ui_out_text (uiout
, "\tstop only if ");
3797 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3798 ui_out_text (uiout
, "\n");
3801 if (!part_of_multiple
&& b
->thread
!= -1)
3803 /* FIXME should make an annotation for this */
3804 ui_out_text (uiout
, "\tstop only in thread ");
3805 ui_out_field_int (uiout
, "thread", b
->thread
);
3806 ui_out_text (uiout
, "\n");
3809 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3811 /* FIXME should make an annotation for this */
3812 if (ep_is_catchpoint (b
))
3813 ui_out_text (uiout
, "\tcatchpoint");
3815 ui_out_text (uiout
, "\tbreakpoint");
3816 ui_out_text (uiout
, " already hit ");
3817 ui_out_field_int (uiout
, "times", b
->hit_count
);
3818 if (b
->hit_count
== 1)
3819 ui_out_text (uiout
, " time\n");
3821 ui_out_text (uiout
, " times\n");
3824 /* Output the count also if it is zero, but only if this is
3825 mi. FIXME: Should have a better test for this. */
3826 if (ui_out_is_mi_like_p (uiout
))
3827 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3828 ui_out_field_int (uiout
, "times", b
->hit_count
);
3830 if (!part_of_multiple
&& b
->ignore_count
)
3833 ui_out_text (uiout
, "\tignore next ");
3834 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3835 ui_out_text (uiout
, " hits\n");
3838 if (!part_of_multiple
&& (l
= b
->commands
))
3840 struct cleanup
*script_chain
;
3843 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3844 print_command_lines (uiout
, l
, 4);
3845 do_cleanups (script_chain
);
3848 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3851 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3852 else if (b
->exp_string
)
3853 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3856 do_cleanups (bkpt_chain
);
3857 do_cleanups (old_chain
);
3861 print_one_breakpoint (struct breakpoint
*b
,
3862 CORE_ADDR
*last_addr
)
3864 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3866 /* If this breakpoint has custom print function,
3867 it's already printed. Otherwise, print individual
3868 locations, if any. */
3869 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3871 /* If breakpoint has a single location that is
3872 disabled, we print it as if it had
3873 several locations, since otherwise it's hard to
3874 represent "breakpoint enabled, location disabled"
3876 Note that while hardware watchpoints have
3877 several locations internally, that's no a property
3880 && !is_hardware_watchpoint (b
)
3881 && (b
->loc
->next
|| !b
->loc
->enabled
)
3882 && !ui_out_is_mi_like_p (uiout
))
3884 struct bp_location
*loc
;
3886 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3887 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3893 struct captured_breakpoint_query_args
3899 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3901 struct captured_breakpoint_query_args
*args
= data
;
3902 struct breakpoint
*b
;
3903 CORE_ADDR dummy_addr
= 0;
3906 if (args
->bnum
== b
->number
)
3908 print_one_breakpoint (b
, &dummy_addr
);
3916 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3918 struct captured_breakpoint_query_args args
;
3920 /* For the moment we don't trust print_one_breakpoint() to not throw
3922 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3923 error_message
, RETURN_MASK_ALL
) < 0)
3929 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3930 catchpoints, et.al.). */
3933 user_settable_breakpoint (const struct breakpoint
*b
)
3935 return (b
->type
== bp_breakpoint
3936 || b
->type
== bp_catch_load
3937 || b
->type
== bp_catch_unload
3938 || b
->type
== bp_catch_fork
3939 || b
->type
== bp_catch_vfork
3940 || b
->type
== bp_catch_exec
3941 || b
->type
== bp_hardware_breakpoint
3942 || b
->type
== bp_watchpoint
3943 || b
->type
== bp_read_watchpoint
3944 || b
->type
== bp_access_watchpoint
3945 || b
->type
== bp_hardware_watchpoint
);
3948 /* Print information on user settable breakpoint (watchpoint, etc)
3949 number BNUM. If BNUM is -1 print all user settable breakpoints.
3950 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3953 breakpoint_1 (int bnum
, int allflag
)
3955 struct breakpoint
*b
;
3956 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3957 int nr_printable_breakpoints
;
3958 struct cleanup
*bkpttbl_chain
;
3960 /* Compute the number of rows in the table. */
3961 nr_printable_breakpoints
= 0;
3964 || bnum
== b
->number
)
3966 if (allflag
|| user_settable_breakpoint (b
))
3967 nr_printable_breakpoints
++;
3972 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3976 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3979 if (nr_printable_breakpoints
> 0)
3980 annotate_breakpoints_headers ();
3981 if (nr_printable_breakpoints
> 0)
3983 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3984 if (nr_printable_breakpoints
> 0)
3986 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3987 if (nr_printable_breakpoints
> 0)
3989 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3990 if (nr_printable_breakpoints
> 0)
3992 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3995 if (nr_printable_breakpoints
> 0)
3997 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3998 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4000 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4002 if (nr_printable_breakpoints
> 0)
4004 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4005 ui_out_table_body (uiout
);
4006 if (nr_printable_breakpoints
> 0)
4007 annotate_breakpoints_table ();
4011 || bnum
== b
->number
)
4013 /* We only print out user settable breakpoints unless the
4015 if (allflag
|| user_settable_breakpoint (b
))
4016 print_one_breakpoint (b
, &last_addr
);
4019 do_cleanups (bkpttbl_chain
);
4021 if (nr_printable_breakpoints
== 0)
4024 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
4026 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
4031 /* Compare against (CORE_ADDR)-1 in case some compiler decides
4032 that a comparison of an unsigned with -1 is always false. */
4033 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
4034 set_next_address (last_addr
);
4037 /* FIXME? Should this be moved up so that it is only called when
4038 there have been breakpoints? */
4039 annotate_breakpoints_table_end ();
4043 breakpoints_info (char *bnum_exp
, int from_tty
)
4048 bnum
= parse_and_eval_long (bnum_exp
);
4050 breakpoint_1 (bnum
, 0);
4054 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4059 bnum
= parse_and_eval_long (bnum_exp
);
4061 breakpoint_1 (bnum
, 1);
4065 breakpoint_has_pc (struct breakpoint
*b
,
4066 CORE_ADDR pc
, struct obj_section
*section
)
4068 struct bp_location
*bl
= b
->loc
;
4069 for (; bl
; bl
= bl
->next
)
4071 if (bl
->address
== pc
4072 && (!overlay_debugging
|| bl
->section
== section
))
4078 /* Print a message describing any breakpoints set at PC. */
4081 describe_other_breakpoints (CORE_ADDR pc
, struct obj_section
*section
,
4085 struct breakpoint
*b
;
4088 others
+= breakpoint_has_pc (b
, pc
, section
);
4092 printf_filtered (_("Note: breakpoint "));
4093 else /* if (others == ???) */
4094 printf_filtered (_("Note: breakpoints "));
4096 if (breakpoint_has_pc (b
, pc
, section
))
4099 printf_filtered ("%d", b
->number
);
4100 if (b
->thread
== -1 && thread
!= -1)
4101 printf_filtered (" (all threads)");
4102 else if (b
->thread
!= -1)
4103 printf_filtered (" (thread %d)", b
->thread
);
4104 printf_filtered ("%s%s ",
4105 ((b
->enable_state
== bp_disabled
||
4106 b
->enable_state
== bp_call_disabled
)
4108 : b
->enable_state
== bp_permanent
4112 : ((others
== 1) ? " and" : ""));
4114 printf_filtered (_("also set at pc "));
4115 fputs_filtered (paddress (pc
), gdb_stdout
);
4116 printf_filtered (".\n");
4120 /* Set the default place to put a breakpoint
4121 for the `break' command with no arguments. */
4124 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4127 default_breakpoint_valid
= valid
;
4128 default_breakpoint_address
= addr
;
4129 default_breakpoint_symtab
= symtab
;
4130 default_breakpoint_line
= line
;
4133 /* Return true iff it is meaningful to use the address member of
4134 BPT. For some breakpoint types, the address member is irrelevant
4135 and it makes no sense to attempt to compare it to other addresses
4136 (or use it for any other purpose either).
4138 More specifically, each of the following breakpoint types will always
4139 have a zero valued address and we don't want check_duplicates() to mark
4140 breakpoints of any of these types to be a duplicate of an actual
4141 breakpoint at address zero:
4144 bp_hardware_watchpoint
4146 bp_access_watchpoint
4152 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4154 enum bptype type
= bpt
->type
;
4156 return (type
!= bp_watchpoint
4157 && type
!= bp_hardware_watchpoint
4158 && type
!= bp_read_watchpoint
4159 && type
!= bp_access_watchpoint
4160 && type
!= bp_catch_exec
4161 && type
!= bp_catch_fork
4162 && type
!= bp_catch_vfork
);
4165 /* Rescan breakpoints at the same address and section as BPT,
4166 marking the first one as "first" and any others as "duplicates".
4167 This is so that the bpt instruction is only inserted once.
4168 If we have a permanent breakpoint at the same place as BPT, make
4169 that one the official one, and the rest as duplicates. */
4172 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
4174 struct bp_location
*b
;
4176 struct bp_location
*perm_bp
= 0;
4178 ALL_BP_LOCATIONS (b
)
4179 if (b
->owner
->enable_state
!= bp_disabled
4180 && b
->owner
->enable_state
!= bp_call_disabled
4182 && !b
->shlib_disabled
4183 && b
->address
== address
/* address / overlay match */
4184 && (!overlay_debugging
|| b
->section
== section
)
4185 && breakpoint_address_is_meaningful (b
->owner
))
4187 /* Have we found a permanent breakpoint? */
4188 if (b
->owner
->enable_state
== bp_permanent
)
4195 b
->duplicate
= count
> 1;
4198 /* If we found a permanent breakpoint at this address, go over the
4199 list again and declare all the other breakpoints there to be the
4203 perm_bp
->duplicate
= 0;
4205 /* Permanent breakpoint should always be inserted. */
4206 if (! perm_bp
->inserted
)
4207 internal_error (__FILE__
, __LINE__
,
4208 _("allegedly permanent breakpoint is not "
4209 "actually inserted"));
4211 ALL_BP_LOCATIONS (b
)
4214 if (b
->owner
->enable_state
!= bp_disabled
4215 && b
->owner
->enable_state
!= bp_call_disabled
4216 && b
->enabled
&& !b
->shlib_disabled
4217 && b
->address
== address
/* address / overlay match */
4218 && (!overlay_debugging
|| b
->section
== section
)
4219 && breakpoint_address_is_meaningful (b
->owner
))
4222 internal_error (__FILE__
, __LINE__
,
4223 _("another breakpoint was inserted on top of "
4224 "a permanent breakpoint"));
4233 check_duplicates (struct breakpoint
*bpt
)
4235 struct bp_location
*bl
= bpt
->loc
;
4237 if (! breakpoint_address_is_meaningful (bpt
))
4240 for (; bl
; bl
= bl
->next
)
4241 check_duplicates_for (bl
->address
, bl
->section
);
4245 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4246 int bnum
, int have_bnum
)
4251 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4252 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4254 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4255 bnum
, astr1
, astr2
);
4257 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4260 /* Adjust a breakpoint's address to account for architectural constraints
4261 on breakpoint placement. Return the adjusted address. Note: Very
4262 few targets require this kind of adjustment. For most targets,
4263 this function is simply the identity function. */
4266 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4268 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4270 /* Very few targets need any kind of breakpoint adjustment. */
4273 else if (bptype
== bp_watchpoint
4274 || bptype
== bp_hardware_watchpoint
4275 || bptype
== bp_read_watchpoint
4276 || bptype
== bp_access_watchpoint
4277 || bptype
== bp_catch_fork
4278 || bptype
== bp_catch_vfork
4279 || bptype
== bp_catch_exec
)
4281 /* Watchpoints and the various bp_catch_* eventpoints should not
4282 have their addresses modified. */
4287 CORE_ADDR adjusted_bpaddr
;
4289 /* Some targets have architectural constraints on the placement
4290 of breakpoint instructions. Obtain the adjusted address. */
4291 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4294 /* An adjusted breakpoint address can significantly alter
4295 a user's expectations. Print a warning if an adjustment
4297 if (adjusted_bpaddr
!= bpaddr
)
4298 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4300 return adjusted_bpaddr
;
4304 /* Allocate a struct bp_location. */
4306 static struct bp_location
*
4307 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4309 struct bp_location
*loc
, *loc_p
;
4311 loc
= xmalloc (sizeof (struct bp_location
));
4312 memset (loc
, 0, sizeof (*loc
));
4316 loc
->shlib_disabled
= 0;
4325 case bp_longjmp_resume
:
4326 case bp_step_resume
:
4327 case bp_watchpoint_scope
:
4329 case bp_shlib_event
:
4330 case bp_thread_event
:
4331 case bp_overlay_event
:
4333 case bp_catch_unload
:
4334 loc
->loc_type
= bp_loc_software_breakpoint
;
4336 case bp_hardware_breakpoint
:
4337 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4339 case bp_hardware_watchpoint
:
4340 case bp_read_watchpoint
:
4341 case bp_access_watchpoint
:
4342 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4346 case bp_catch_vfork
:
4348 loc
->loc_type
= bp_loc_other
;
4351 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4357 static void free_bp_location (struct bp_location
*loc
)
4362 if (loc
->function_name
)
4363 xfree (loc
->function_name
);
4368 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4369 that has type BPTYPE and has no locations as yet. */
4371 static struct breakpoint
*
4372 set_raw_breakpoint_without_location (enum bptype bptype
)
4374 struct breakpoint
*b
, *b1
;
4376 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4377 memset (b
, 0, sizeof (*b
));
4380 b
->language
= current_language
->la_language
;
4381 b
->input_radix
= input_radix
;
4383 b
->enable_state
= bp_enabled
;
4386 b
->ignore_count
= 0;
4388 b
->frame_id
= null_frame_id
;
4389 b
->dll_pathname
= NULL
;
4390 b
->triggered_dll_pathname
= NULL
;
4391 b
->forked_inferior_pid
= null_ptid
;
4392 b
->exec_pathname
= NULL
;
4394 b
->condition_not_parsed
= 0;
4396 /* Add this breakpoint to the end of the chain
4397 so that a list of breakpoints will come out in order
4398 of increasing numbers. */
4400 b1
= breakpoint_chain
;
4402 breakpoint_chain
= b
;
4412 /* Initialize loc->function_name. */
4414 set_breakpoint_location_function (struct bp_location
*loc
)
4416 if (loc
->owner
->type
== bp_breakpoint
4417 || loc
->owner
->type
== bp_hardware_breakpoint
)
4419 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4421 if (loc
->function_name
)
4422 loc
->function_name
= xstrdup (loc
->function_name
);
4426 /* set_raw_breakpoint is a low level routine for allocating and
4427 partially initializing a breakpoint of type BPTYPE. The newly
4428 created breakpoint's address, section, source file name, and line
4429 number are provided by SAL. The newly created and partially
4430 initialized breakpoint is added to the breakpoint chain and
4431 is also returned as the value of this function.
4433 It is expected that the caller will complete the initialization of
4434 the newly created breakpoint struct as well as output any status
4435 information regarding the creation of a new breakpoint. In
4436 particular, set_raw_breakpoint does NOT set the breakpoint
4437 number! Care should be taken to not allow an error to occur
4438 prior to completing the initialization of the breakpoint. If this
4439 should happen, a bogus breakpoint will be left on the chain. */
4442 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4444 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4445 CORE_ADDR adjusted_address
;
4447 /* Adjust the breakpoint's address prior to allocating a location.
4448 Once we call allocate_bp_location(), that mostly uninitialized
4449 location will be placed on the location chain. Adjustment of the
4450 breakpoint may cause target_read_memory() to be called and we do
4451 not want its scan of the location chain to find a breakpoint and
4452 location that's only been partially initialized. */
4453 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4455 b
->loc
= allocate_bp_location (b
, bptype
);
4456 b
->loc
->requested_address
= sal
.pc
;
4457 b
->loc
->address
= adjusted_address
;
4459 if (sal
.symtab
== NULL
)
4460 b
->source_file
= NULL
;
4462 b
->source_file
= savestring (sal
.symtab
->filename
,
4463 strlen (sal
.symtab
->filename
));
4464 b
->loc
->section
= sal
.section
;
4465 b
->line_number
= sal
.line
;
4467 set_breakpoint_location_function (b
->loc
);
4469 breakpoints_changed ();
4475 /* Note that the breakpoint object B describes a permanent breakpoint
4476 instruction, hard-wired into the inferior's code. */
4478 make_breakpoint_permanent (struct breakpoint
*b
)
4480 struct bp_location
*bl
;
4481 b
->enable_state
= bp_permanent
;
4483 /* By definition, permanent breakpoints are already present in the code.
4484 Mark all locations as inserted. For now, make_breakpoint_permanent
4485 is called in just one place, so it's hard to say if it's reasonable
4486 to have permanent breakpoint with multiple locations or not,
4487 but it's easy to implmement. */
4488 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4492 static struct breakpoint
*
4493 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4495 static int internal_breakpoint_number
= -1;
4496 struct symtab_and_line sal
;
4497 struct breakpoint
*b
;
4499 init_sal (&sal
); /* initialize to zeroes */
4502 sal
.section
= find_pc_overlay (sal
.pc
);
4504 b
= set_raw_breakpoint (sal
, type
);
4505 b
->number
= internal_breakpoint_number
--;
4506 b
->disposition
= disp_donttouch
;
4513 create_longjmp_breakpoint (char *func_name
)
4515 struct minimal_symbol
*m
;
4517 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4519 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4520 update_global_location_list (1);
4523 /* Call this routine when stepping and nexting to enable a breakpoint
4524 if we do a longjmp(). When we hit that breakpoint, call
4525 set_longjmp_resume_breakpoint() to figure out where we are going. */
4528 set_longjmp_breakpoint (void)
4530 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4532 create_longjmp_breakpoint ("longjmp");
4533 create_longjmp_breakpoint ("_longjmp");
4534 create_longjmp_breakpoint ("siglongjmp");
4535 create_longjmp_breakpoint ("_siglongjmp");
4539 /* Delete all longjmp breakpoints from THREAD. */
4541 delete_longjmp_breakpoint (int thread
)
4543 struct breakpoint
*b
, *temp
;
4545 ALL_BREAKPOINTS_SAFE (b
, temp
)
4546 if (b
->type
== bp_longjmp
)
4548 if (b
->thread
== thread
)
4549 delete_breakpoint (b
);
4554 create_overlay_event_breakpoint_1 (char *func_name
, struct objfile
*objfile
)
4556 struct breakpoint
*b
;
4557 struct minimal_symbol
*m
;
4559 if ((m
= lookup_minimal_symbol_text (func_name
, objfile
)) == NULL
)
4562 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4564 b
->addr_string
= xstrdup (func_name
);
4566 if (overlay_debugging
== ovly_auto
)
4568 b
->enable_state
= bp_enabled
;
4569 overlay_events_enabled
= 1;
4573 b
->enable_state
= bp_disabled
;
4574 overlay_events_enabled
= 0;
4576 update_global_location_list (1);
4580 create_overlay_event_breakpoint (char *func_name
)
4582 struct objfile
*objfile
;
4583 ALL_OBJFILES (objfile
)
4584 create_overlay_event_breakpoint_1 (func_name
, objfile
);
4588 enable_overlay_breakpoints (void)
4590 struct breakpoint
*b
;
4593 if (b
->type
== bp_overlay_event
)
4595 b
->enable_state
= bp_enabled
;
4596 update_global_location_list (1);
4597 overlay_events_enabled
= 1;
4602 disable_overlay_breakpoints (void)
4604 struct breakpoint
*b
;
4607 if (b
->type
== bp_overlay_event
)
4609 b
->enable_state
= bp_disabled
;
4610 update_global_location_list (0);
4611 overlay_events_enabled
= 0;
4616 create_thread_event_breakpoint (CORE_ADDR address
)
4618 struct breakpoint
*b
;
4620 b
= create_internal_breakpoint (address
, bp_thread_event
);
4622 b
->enable_state
= bp_enabled
;
4623 /* addr_string has to be used or breakpoint_re_set will delete me. */
4624 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4626 update_global_location_list_nothrow (1);
4632 remove_thread_event_breakpoints (void)
4634 struct breakpoint
*b
, *temp
;
4636 ALL_BREAKPOINTS_SAFE (b
, temp
)
4637 if (b
->type
== bp_thread_event
)
4638 delete_breakpoint (b
);
4641 struct captured_parse_breakpoint_args
4644 struct symtabs_and_lines
*sals_p
;
4645 char ***addr_string_p
;
4649 struct lang_and_radix
4657 remove_solib_event_breakpoints (void)
4659 struct breakpoint
*b
, *temp
;
4661 ALL_BREAKPOINTS_SAFE (b
, temp
)
4662 if (b
->type
== bp_shlib_event
)
4663 delete_breakpoint (b
);
4667 create_solib_event_breakpoint (CORE_ADDR address
)
4669 struct breakpoint
*b
;
4671 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4672 update_global_location_list_nothrow (1);
4676 /* Disable any breakpoints that are on code in shared libraries. Only
4677 apply to enabled breakpoints, disabled ones can just stay disabled. */
4680 disable_breakpoints_in_shlibs (void)
4682 struct bp_location
*loc
;
4683 int disabled_shlib_breaks
= 0;
4685 ALL_BP_LOCATIONS (loc
)
4687 struct breakpoint
*b
= loc
->owner
;
4688 /* We apply the check to all breakpoints, including disabled
4689 for those with loc->duplicate set. This is so that when breakpoint
4690 becomes enabled, or the duplicate is removed, gdb will try to insert
4691 all breakpoints. If we don't set shlib_disabled here, we'll try
4692 to insert those breakpoints and fail. */
4693 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4694 && !loc
->shlib_disabled
4696 && PC_SOLIB (loc
->address
)
4698 && solib_address (loc
->address
)
4702 loc
->shlib_disabled
= 1;
4707 /* Disable any breakpoints that are in in an unloaded shared library. Only
4708 apply to enabled breakpoints, disabled ones can just stay disabled. */
4711 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4713 struct bp_location
*loc
;
4714 int disabled_shlib_breaks
= 0;
4716 ALL_BP_LOCATIONS (loc
)
4718 struct breakpoint
*b
= loc
->owner
;
4719 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4720 || loc
->loc_type
== bp_loc_software_breakpoint
)
4721 && !loc
->shlib_disabled
)
4724 char *so_name
= PC_SOLIB (loc
->address
);
4726 char *so_name
= solib_address (loc
->address
);
4728 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4730 loc
->shlib_disabled
= 1;
4731 /* At this point, we cannot rely on remove_breakpoint
4732 succeeding so we must mark the breakpoint as not inserted
4733 to prevent future errors occurring in remove_breakpoints. */
4735 if (!disabled_shlib_breaks
)
4737 target_terminal_ours_for_output ();
4738 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4741 disabled_shlib_breaks
= 1;
4748 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4749 enum bptype bp_kind
)
4751 struct symtab_and_line sal
;
4752 struct breakpoint
*b
;
4753 int thread
= -1; /* All threads. */
4760 b
= set_raw_breakpoint (sal
, bp_kind
);
4761 set_breakpoint_count (breakpoint_count
+ 1);
4762 b
->number
= breakpoint_count
;
4763 b
->cond_string
= (cond_string
== NULL
) ?
4764 NULL
: savestring (cond_string
, strlen (cond_string
));
4766 b
->addr_string
= NULL
;
4767 b
->enable_state
= bp_enabled
;
4768 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4769 b
->forked_inferior_pid
= null_ptid
;
4770 update_global_location_list (1);
4777 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4779 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4783 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4785 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4789 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4791 struct symtab_and_line sal
;
4792 struct breakpoint
*b
;
4793 int thread
= -1; /* All threads. */
4800 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4801 set_breakpoint_count (breakpoint_count
+ 1);
4802 b
->number
= breakpoint_count
;
4803 b
->cond_string
= (cond_string
== NULL
) ?
4804 NULL
: savestring (cond_string
, strlen (cond_string
));
4806 b
->addr_string
= NULL
;
4807 b
->enable_state
= bp_enabled
;
4808 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4809 update_global_location_list (1);
4815 hw_breakpoint_used_count (void)
4817 struct breakpoint
*b
;
4822 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
4830 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4832 struct breakpoint
*b
;
4835 *other_type_used
= 0;
4838 if (breakpoint_enabled (b
))
4840 if (b
->type
== type
)
4842 else if ((b
->type
== bp_hardware_watchpoint
||
4843 b
->type
== bp_read_watchpoint
||
4844 b
->type
== bp_access_watchpoint
))
4845 *other_type_used
= 1;
4852 disable_watchpoints_before_interactive_call_start (void)
4854 struct breakpoint
*b
;
4858 if (((b
->type
== bp_watchpoint
)
4859 || (b
->type
== bp_hardware_watchpoint
)
4860 || (b
->type
== bp_read_watchpoint
)
4861 || (b
->type
== bp_access_watchpoint
))
4862 && breakpoint_enabled (b
))
4864 b
->enable_state
= bp_call_disabled
;
4865 update_global_location_list (0);
4871 enable_watchpoints_after_interactive_call_stop (void)
4873 struct breakpoint
*b
;
4877 if (((b
->type
== bp_watchpoint
)
4878 || (b
->type
== bp_hardware_watchpoint
)
4879 || (b
->type
== bp_read_watchpoint
)
4880 || (b
->type
== bp_access_watchpoint
))
4881 && (b
->enable_state
== bp_call_disabled
))
4883 b
->enable_state
= bp_enabled
;
4884 update_global_location_list (1);
4890 /* Set a breakpoint that will evaporate an end of command
4891 at address specified by SAL.
4892 Restrict it to frame FRAME if FRAME is nonzero. */
4895 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4898 struct breakpoint
*b
;
4899 b
= set_raw_breakpoint (sal
, type
);
4900 b
->enable_state
= bp_enabled
;
4901 b
->disposition
= disp_donttouch
;
4902 b
->frame_id
= frame_id
;
4904 /* If we're debugging a multi-threaded program, then we
4905 want momentary breakpoints to be active in only a
4906 single thread of control. */
4907 if (in_thread_list (inferior_ptid
))
4908 b
->thread
= pid_to_thread_id (inferior_ptid
);
4910 update_global_location_list_nothrow (1);
4916 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
4918 struct symtab_and_line sal
;
4920 sal
= find_pc_line (pc
, 0);
4922 sal
.section
= find_pc_overlay (pc
);
4923 sal
.explicit_pc
= 1;
4925 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
4929 /* Tell the user we have just set a breakpoint B. */
4932 mention (struct breakpoint
*b
)
4935 struct cleanup
*old_chain
, *ui_out_chain
;
4936 struct ui_stream
*stb
;
4938 stb
= ui_out_stream_new (uiout
);
4939 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4941 /* FIXME: This is misplaced; mention() is called by things (like
4942 hitting a watchpoint) other than breakpoint creation. It should
4943 be possible to clean this up and at the same time replace the
4944 random calls to breakpoint_changed with this hook. */
4945 observer_notify_breakpoint_created (b
->number
);
4947 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4948 b
->ops
->print_mention (b
);
4953 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4956 ui_out_text (uiout
, "Watchpoint ");
4957 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4958 ui_out_field_int (uiout
, "number", b
->number
);
4959 ui_out_text (uiout
, ": ");
4960 print_expression (b
->exp
, stb
->stream
);
4961 ui_out_field_stream (uiout
, "exp", stb
);
4962 do_cleanups (ui_out_chain
);
4964 case bp_hardware_watchpoint
:
4965 ui_out_text (uiout
, "Hardware watchpoint ");
4966 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4967 ui_out_field_int (uiout
, "number", b
->number
);
4968 ui_out_text (uiout
, ": ");
4969 print_expression (b
->exp
, stb
->stream
);
4970 ui_out_field_stream (uiout
, "exp", stb
);
4971 do_cleanups (ui_out_chain
);
4973 case bp_read_watchpoint
:
4974 ui_out_text (uiout
, "Hardware read watchpoint ");
4975 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4976 ui_out_field_int (uiout
, "number", b
->number
);
4977 ui_out_text (uiout
, ": ");
4978 print_expression (b
->exp
, stb
->stream
);
4979 ui_out_field_stream (uiout
, "exp", stb
);
4980 do_cleanups (ui_out_chain
);
4982 case bp_access_watchpoint
:
4983 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4984 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4985 ui_out_field_int (uiout
, "number", b
->number
);
4986 ui_out_text (uiout
, ": ");
4987 print_expression (b
->exp
, stb
->stream
);
4988 ui_out_field_stream (uiout
, "exp", stb
);
4989 do_cleanups (ui_out_chain
);
4992 if (ui_out_is_mi_like_p (uiout
))
4997 if (b
->disposition
== disp_del
)
4998 printf_filtered (_("Temporary breakpoint"));
5000 printf_filtered (_("Breakpoint"));
5001 printf_filtered (_(" %d"), b
->number
);
5004 case bp_hardware_breakpoint
:
5005 if (ui_out_is_mi_like_p (uiout
))
5010 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
5014 case bp_catch_unload
:
5015 printf_filtered (_("Catchpoint %d (%s %s)"),
5017 (b
->type
== bp_catch_load
) ? "load" : "unload",
5018 (b
->dll_pathname
!= NULL
) ?
5019 b
->dll_pathname
: "<any library>");
5022 case bp_catch_vfork
:
5023 printf_filtered (_("Catchpoint %d (%s)"),
5025 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
5028 printf_filtered (_("Catchpoint %d (exec)"),
5035 case bp_longjmp_resume
:
5036 case bp_step_resume
:
5038 case bp_watchpoint_scope
:
5039 case bp_shlib_event
:
5040 case bp_thread_event
:
5041 case bp_overlay_event
:
5047 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5051 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5055 if (addressprint
|| b
->source_file
== NULL
)
5057 printf_filtered (" at ");
5058 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5061 printf_filtered (": file %s, line %d.",
5062 b
->source_file
, b
->line_number
);
5066 struct bp_location
*loc
= b
->loc
;
5068 for (; loc
; loc
= loc
->next
)
5070 printf_filtered (" (%d locations)", n
);
5075 do_cleanups (old_chain
);
5076 if (ui_out_is_mi_like_p (uiout
))
5078 printf_filtered ("\n");
5082 static struct bp_location
*
5083 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5084 const struct symtab_and_line
*sal
)
5086 struct bp_location
*loc
, **tmp
;
5088 loc
= allocate_bp_location (b
, bptype
);
5089 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5092 loc
->requested_address
= sal
->pc
;
5093 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5095 loc
->section
= sal
->section
;
5097 set_breakpoint_location_function (loc
);
5102 /* Return 1 if LOC is pointing to a permanent breakpoint,
5103 return 0 otherwise. */
5106 bp_loc_is_permanent (struct bp_location
*loc
)
5110 const gdb_byte
*brk
;
5111 gdb_byte
*target_mem
;
5113 gdb_assert (loc
!= NULL
);
5115 addr
= loc
->address
;
5116 brk
= gdbarch_breakpoint_from_pc (current_gdbarch
, &addr
, &len
);
5118 target_mem
= alloca (len
);
5120 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5121 && memcmp (target_mem
, brk
, len
) == 0)
5129 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5130 as textual description of the location, and COND_STRING
5131 as condition expression. */
5134 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5136 enum bptype type
, enum bpdisp disposition
,
5137 int thread
, int ignore_count
,
5138 struct breakpoint_ops
*ops
, int from_tty
)
5140 struct breakpoint
*b
= NULL
;
5143 if (type
== bp_hardware_breakpoint
)
5145 int i
= hw_breakpoint_used_count ();
5146 int target_resources_ok
=
5147 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5149 if (target_resources_ok
== 0)
5150 error (_("No hardware breakpoint support in the target."));
5151 else if (target_resources_ok
< 0)
5152 error (_("Hardware breakpoints used exceeds limit."));
5155 for (i
= 0; i
< sals
.nelts
; ++i
)
5157 struct symtab_and_line sal
= sals
.sals
[i
];
5158 struct bp_location
*loc
;
5161 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5165 b
= set_raw_breakpoint (sal
, type
);
5166 set_breakpoint_count (breakpoint_count
+ 1);
5167 b
->number
= breakpoint_count
;
5170 b
->cond_string
= cond_string
;
5171 b
->ignore_count
= ignore_count
;
5172 b
->enable_state
= bp_enabled
;
5173 b
->disposition
= disposition
;
5179 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5182 if (bp_loc_is_permanent (loc
))
5183 make_breakpoint_permanent (b
);
5187 char *arg
= b
->cond_string
;
5188 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5190 error (_("Garbage %s follows condition"), arg
);
5195 b
->addr_string
= addr_string
;
5197 /* addr_string has to be used or breakpoint_re_set will delete
5199 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5205 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5206 elements to fill the void space. */
5207 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5209 int i
= index_to_remove
+1;
5210 int last_index
= sal
->nelts
-1;
5212 for (;i
<= last_index
; ++i
)
5213 sal
->sals
[i
-1] = sal
->sals
[i
];
5218 /* If appropriate, obtains all sals that correspond
5219 to the same file and line as SAL. This is done
5220 only if SAL does not have explicit PC and has
5221 line and file information. If we got just a single
5222 expanded sal, return the original.
5224 Otherwise, if SAL.explicit_line is not set, filter out
5225 all sals for which the name of enclosing function
5226 is different from SAL. This makes sure that if we have
5227 breakpoint originally set in template instantiation, say
5228 foo<int>(), we won't expand SAL to locations at the same
5229 line in all existing instantiations of 'foo'.
5232 struct symtabs_and_lines
5233 expand_line_sal_maybe (struct symtab_and_line sal
)
5235 struct symtabs_and_lines expanded
;
5236 CORE_ADDR original_pc
= sal
.pc
;
5237 char *original_function
= NULL
;
5241 /* If we have explicit pc, don't expand.
5242 If we have no line number, we can't expand. */
5243 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5246 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5247 expanded
.sals
[0] = sal
;
5252 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5254 expanded
= expand_line_sal (sal
);
5255 if (expanded
.nelts
== 1)
5257 /* We had one sal, we got one sal. Without futher
5258 processing, just return the original sal. */
5259 xfree (expanded
.sals
);
5261 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5262 sal
.pc
= original_pc
;
5263 expanded
.sals
[0] = sal
;
5267 if (!sal
.explicit_line
)
5269 CORE_ADDR func_addr
, func_end
;
5270 for (i
= 0; i
< expanded
.nelts
; ++i
)
5272 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5273 char *this_function
;
5274 if (find_pc_partial_function (pc
, &this_function
,
5275 &func_addr
, &func_end
))
5277 if (this_function
&&
5278 strcmp (this_function
, original_function
) != 0)
5280 remove_sal (&expanded
, i
);
5283 else if (func_addr
== pc
)
5285 /* We're at beginning of a function, and should
5287 struct symbol
*sym
= find_pc_function (pc
);
5289 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5292 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5299 if (expanded
.nelts
<= 1)
5301 /* This is un ugly workaround. If we get zero
5302 expanded sals then something is really wrong.
5303 Fix that by returnign the original sal. */
5304 xfree (expanded
.sals
);
5306 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5307 sal
.pc
= original_pc
;
5308 expanded
.sals
[0] = sal
;
5315 for (i
= 0; i
< expanded
.nelts
; ++i
)
5316 if (expanded
.sals
[i
].pc
== original_pc
)
5327 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5328 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5329 value. COND_STRING, if not NULL, specified the condition to be
5330 used for all breakpoints. Essentially the only case where
5331 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5332 function. In that case, it's still not possible to specify
5333 separate conditions for different overloaded functions, so
5334 we take just a single condition string.
5336 NOTE: If the function succeeds, the caller is expected to cleanup
5337 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5338 array contents). If the function fails (error() is called), the
5339 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5340 COND and SALS arrays and each of those arrays contents. */
5343 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5345 enum bptype type
, enum bpdisp disposition
,
5346 int thread
, int ignore_count
,
5347 struct breakpoint_ops
*ops
, int from_tty
)
5350 for (i
= 0; i
< sals
.nelts
; ++i
)
5352 struct symtabs_and_lines expanded
=
5353 expand_line_sal_maybe (sals
.sals
[i
]);
5355 create_breakpoint (expanded
, addr_string
[i
],
5356 cond_string
, type
, disposition
,
5357 thread
, ignore_count
, ops
, from_tty
);
5360 update_global_location_list (1);
5363 /* Parse ARG which is assumed to be a SAL specification possibly
5364 followed by conditionals. On return, SALS contains an array of SAL
5365 addresses found. ADDR_STRING contains a vector of (canonical)
5366 address strings. ARG points to the end of the SAL. */
5369 parse_breakpoint_sals (char **address
,
5370 struct symtabs_and_lines
*sals
,
5371 char ***addr_string
,
5374 char *addr_start
= *address
;
5375 *addr_string
= NULL
;
5376 /* If no arg given, or if first arg is 'if ', use the default
5378 if ((*address
) == NULL
5379 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5381 if (default_breakpoint_valid
)
5383 struct symtab_and_line sal
;
5384 init_sal (&sal
); /* initialize to zeroes */
5385 sals
->sals
= (struct symtab_and_line
*)
5386 xmalloc (sizeof (struct symtab_and_line
));
5387 sal
.pc
= default_breakpoint_address
;
5388 sal
.line
= default_breakpoint_line
;
5389 sal
.symtab
= default_breakpoint_symtab
;
5390 sal
.section
= find_pc_overlay (sal
.pc
);
5391 sals
->sals
[0] = sal
;
5395 error (_("No default breakpoint address now."));
5399 /* Force almost all breakpoints to be in terms of the
5400 current_source_symtab (which is decode_line_1's default). This
5401 should produce the results we want almost all of the time while
5402 leaving default_breakpoint_* alone.
5403 ObjC: However, don't match an Objective-C method name which
5404 may have a '+' or '-' succeeded by a '[' */
5406 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5408 if (default_breakpoint_valid
5410 || ((strchr ("+-", (*address
)[0]) != NULL
)
5411 && ((*address
)[1] != '['))))
5412 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5413 default_breakpoint_line
, addr_string
,
5416 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5417 addr_string
, not_found_ptr
);
5419 /* For any SAL that didn't have a canonical string, fill one in. */
5420 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5421 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5422 if (addr_start
!= (*address
))
5425 for (i
= 0; i
< sals
->nelts
; i
++)
5427 /* Add the string if not present. */
5428 if ((*addr_string
)[i
] == NULL
)
5429 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5435 /* Convert each SAL into a real PC. Verify that the PC can be
5436 inserted as a breakpoint. If it can't throw an error. */
5439 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5443 for (i
= 0; i
< sals
->nelts
; i
++)
5444 resolve_sal_pc (&sals
->sals
[i
]);
5448 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5450 struct captured_parse_breakpoint_args
*args
= data
;
5452 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5453 args
->not_found_ptr
);
5456 /* Given TOK, a string specification of condition and thread, as
5457 accepted by the 'break' command, extract the condition
5458 string and thread number and set *COND_STRING and *THREAD.
5459 PC identifies the context at which the condition should be parsed.
5460 If no condition is found, *COND_STRING is set to NULL.
5461 If no thread is found, *THREAD is set to -1. */
5463 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5464 char **cond_string
, int *thread
)
5466 *cond_string
= NULL
;
5472 char *cond_start
= NULL
;
5473 char *cond_end
= NULL
;
5474 while (*tok
== ' ' || *tok
== '\t')
5479 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5482 toklen
= end_tok
- tok
;
5484 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5486 tok
= cond_start
= end_tok
+ 1;
5487 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5489 *cond_string
= savestring (cond_start
,
5490 cond_end
- cond_start
);
5492 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5498 *thread
= strtol (tok
, &tok
, 0);
5500 error (_("Junk after thread keyword."));
5501 if (!valid_thread_id (*thread
))
5502 error (_("Unknown thread %d."), *thread
);
5505 error (_("Junk at end of arguments."));
5509 /* Set a breakpoint. This function is shared between
5510 CLI and MI functions for setting a breakpoint.
5511 This function has two major modes of operations,
5512 selected by the PARSE_CONDITION_AND_THREAD parameter.
5513 If non-zero, the function will parse arg, extracting
5514 breakpoint location, address and thread. Otherwise,
5515 ARG is just the location of breakpoint, with condition
5516 and thread specified by the COND_STRING and THREAD
5520 break_command_really (char *arg
, char *cond_string
, int thread
,
5521 int parse_condition_and_thread
,
5522 int tempflag
, int hardwareflag
,
5524 enum auto_boolean pending_break_support
,
5525 struct breakpoint_ops
*ops
,
5528 struct gdb_exception e
;
5529 struct symtabs_and_lines sals
;
5530 struct symtab_and_line pending_sal
;
5533 char *addr_start
= arg
;
5535 struct cleanup
*old_chain
;
5536 struct cleanup
*breakpoint_chain
= NULL
;
5537 struct captured_parse_breakpoint_args parse_args
;
5546 parse_args
.arg_p
= &arg
;
5547 parse_args
.sals_p
= &sals
;
5548 parse_args
.addr_string_p
= &addr_string
;
5549 parse_args
.not_found_ptr
= ¬_found
;
5551 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5552 &parse_args
, RETURN_MASK_ALL
);
5554 /* If caller is interested in rc value from parse, set value. */
5558 throw_exception (e
);
5562 case NOT_FOUND_ERROR
:
5564 /* If pending breakpoint support is turned off, throw
5567 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5568 throw_exception (e
);
5570 exception_print (gdb_stderr
, e
);
5572 /* If pending breakpoint support is auto query and the user
5573 selects no, then simply return the error code. */
5574 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5575 !nquery ("Make breakpoint pending on future shared library load? "))
5578 /* At this point, either the user was queried about setting
5579 a pending breakpoint and selected yes, or pending
5580 breakpoint behavior is on and thus a pending breakpoint
5581 is defaulted on behalf of the user. */
5582 copy_arg
= xstrdup (addr_start
);
5583 addr_string
= ©_arg
;
5585 sals
.sals
= &pending_sal
;
5590 throw_exception (e
);
5597 /* Create a chain of things that always need to be cleaned up. */
5598 old_chain
= make_cleanup (null_cleanup
, 0);
5602 /* Make sure that all storage allocated to SALS gets freed. */
5603 make_cleanup (xfree
, sals
.sals
);
5605 /* Cleanup the addr_string array but not its contents. */
5606 make_cleanup (xfree
, addr_string
);
5609 /* ----------------------------- SNIP -----------------------------
5610 Anything added to the cleanup chain beyond this point is assumed
5611 to be part of a breakpoint. If the breakpoint create succeeds
5612 then the memory is not reclaimed. */
5613 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5615 /* Mark the contents of the addr_string for cleanup. These go on
5616 the breakpoint_chain and only occure if the breakpoint create
5618 for (i
= 0; i
< sals
.nelts
; i
++)
5620 if (addr_string
[i
] != NULL
)
5621 make_cleanup (xfree
, addr_string
[i
]);
5624 /* Resolve all line numbers to PC's and verify that the addresses
5625 are ok for the target. */
5627 breakpoint_sals_to_pc (&sals
, addr_start
);
5629 /* Verify that condition can be parsed, before setting any
5630 breakpoints. Allocate a separate condition expression for each
5634 if (parse_condition_and_thread
)
5636 /* Here we only parse 'arg' to separate condition
5637 from thread number, so parsing in context of first
5638 sal is OK. When setting the breakpoint we'll
5639 re-parse it in context of each sal. */
5642 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5644 make_cleanup (xfree
, cond_string
);
5648 /* Create a private copy of condition string. */
5651 cond_string
= xstrdup (cond_string
);
5652 make_cleanup (xfree
, cond_string
);
5655 create_breakpoints (sals
, addr_string
, cond_string
,
5656 hardwareflag
? bp_hardware_breakpoint
5658 tempflag
? disp_del
: disp_donttouch
,
5659 thread
, ignore_count
, ops
, from_tty
);
5663 struct symtab_and_line sal
= {0};
5664 struct breakpoint
*b
;
5666 make_cleanup (xfree
, copy_arg
);
5668 b
= set_raw_breakpoint_without_location (hardwareflag
5669 ? bp_hardware_breakpoint
5671 set_breakpoint_count (breakpoint_count
+ 1);
5672 b
->number
= breakpoint_count
;
5674 b
->addr_string
= addr_string
[0];
5675 b
->cond_string
= NULL
;
5676 b
->ignore_count
= ignore_count
;
5677 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5678 b
->condition_not_parsed
= 1;
5681 update_global_location_list (1);
5686 warning (_("Multiple breakpoints were set.\n"
5687 "Use the \"delete\" command to delete unwanted breakpoints."));
5688 /* That's it. Discard the cleanups for data inserted into the
5690 discard_cleanups (breakpoint_chain
);
5691 /* But cleanup everything else. */
5692 do_cleanups (old_chain
);
5695 /* Set a breakpoint.
5696 ARG is a string describing breakpoint address,
5697 condition, and thread.
5698 FLAG specifies if a breakpoint is hardware on,
5699 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5703 break_command_1 (char *arg
, int flag
, int from_tty
)
5705 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5706 int tempflag
= flag
& BP_TEMPFLAG
;
5708 break_command_really (arg
,
5709 NULL
, 0, 1 /* parse arg */,
5710 tempflag
, hardwareflag
,
5711 0 /* Ignore count */,
5712 pending_break_support
,
5713 NULL
/* breakpoint_ops */,
5719 set_breakpoint (char *address
, char *condition
,
5720 int hardwareflag
, int tempflag
,
5721 int thread
, int ignore_count
,
5724 break_command_really (address
, condition
, thread
,
5725 0 /* condition and thread are valid. */,
5726 tempflag
, hardwareflag
,
5729 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5733 /* Adjust SAL to the first instruction past the function prologue.
5734 The end of the prologue is determined using the line table from
5735 the debugging information.
5737 If SAL is already past the prologue, then do nothing. */
5740 skip_prologue_sal (struct symtab_and_line
*sal
)
5742 struct symbol
*sym
= find_pc_function (sal
->pc
);
5743 struct symtab_and_line start_sal
;
5748 start_sal
= find_function_start_sal (sym
, 1);
5749 if (sal
->pc
< start_sal
.pc
)
5753 /* Helper function for break_command_1 and disassemble_command. */
5756 resolve_sal_pc (struct symtab_and_line
*sal
)
5760 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5762 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5763 error (_("No line %d in file \"%s\"."),
5764 sal
->line
, sal
->symtab
->filename
);
5767 /* If this SAL corresponds to a breakpoint inserted using
5768 a line number, then skip the function prologue if necessary. */
5769 if (sal
->explicit_line
)
5770 skip_prologue_sal (sal
);
5773 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5775 struct blockvector
*bv
;
5779 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5782 sym
= block_linkage_function (b
);
5785 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5786 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
5790 /* It really is worthwhile to have the section, so we'll just
5791 have to look harder. This case can be executed if we have
5792 line numbers but no functions (as can happen in assembly
5795 struct minimal_symbol
*msym
;
5797 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5799 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
5806 break_command (char *arg
, int from_tty
)
5808 break_command_1 (arg
, 0, from_tty
);
5812 tbreak_command (char *arg
, int from_tty
)
5814 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5818 hbreak_command (char *arg
, int from_tty
)
5820 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5824 thbreak_command (char *arg
, int from_tty
)
5826 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5830 stop_command (char *arg
, int from_tty
)
5832 printf_filtered (_("Specify the type of breakpoint to set.\n\
5833 Usage: stop in <function | address>\n\
5834 stop at <line>\n"));
5838 stopin_command (char *arg
, int from_tty
)
5842 if (arg
== (char *) NULL
)
5844 else if (*arg
!= '*')
5849 /* look for a ':'. If this is a line number specification, then
5850 say it is bad, otherwise, it should be an address or
5851 function/method name */
5852 while (*argptr
&& !hasColon
)
5854 hasColon
= (*argptr
== ':');
5859 badInput
= (*argptr
!= ':'); /* Not a class::method */
5861 badInput
= isdigit (*arg
); /* a simple line number */
5865 printf_filtered (_("Usage: stop in <function | address>\n"));
5867 break_command_1 (arg
, 0, from_tty
);
5871 stopat_command (char *arg
, int from_tty
)
5875 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5882 /* look for a ':'. If there is a '::' then get out, otherwise
5883 it is probably a line number. */
5884 while (*argptr
&& !hasColon
)
5886 hasColon
= (*argptr
== ':');
5891 badInput
= (*argptr
== ':'); /* we have class::method */
5893 badInput
= !isdigit (*arg
); /* not a line number */
5897 printf_filtered (_("Usage: stop at <line>\n"));
5899 break_command_1 (arg
, 0, from_tty
);
5902 /* accessflag: hw_write: watch write,
5903 hw_read: watch read,
5904 hw_access: watch access (read or write) */
5906 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5908 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5909 struct symtab_and_line sal
;
5910 struct expression
*exp
;
5911 struct block
*exp_valid_block
;
5912 struct value
*val
, *mark
;
5913 struct frame_info
*frame
;
5914 struct frame_info
*prev_frame
= NULL
;
5915 char *exp_start
= NULL
;
5916 char *exp_end
= NULL
;
5917 char *tok
, *id_tok_start
, *end_tok
;
5919 char *cond_start
= NULL
;
5920 char *cond_end
= NULL
;
5921 struct expression
*cond
= NULL
;
5922 int i
, other_type_used
, target_resources_ok
= 0;
5923 enum bptype bp_type
;
5927 init_sal (&sal
); /* initialize to zeroes */
5929 /* Make sure that we actually have parameters to parse. */
5930 if (arg
!= NULL
&& arg
[0] != '\0')
5932 toklen
= strlen (arg
); /* Size of argument list. */
5934 /* Points tok to the end of the argument list. */
5935 tok
= arg
+ toklen
- 1;
5937 /* Go backwards in the parameters list. Skip the last parameter.
5938 If we're expecting a 'thread <thread_num>' parameter, this should
5939 be the thread identifier. */
5940 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5942 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5945 /* Points end_tok to the beginning of the last token. */
5946 id_tok_start
= tok
+ 1;
5948 /* Go backwards in the parameters list. Skip one more parameter.
5949 If we're expecting a 'thread <thread_num>' parameter, we should
5950 reach a "thread" token. */
5951 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5956 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5959 /* Move the pointer forward to skip the whitespace and
5960 calculate the length of the token. */
5962 toklen
= end_tok
- tok
;
5964 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5966 /* At this point we've found a "thread" token, which means
5967 the user is trying to set a watchpoint that triggers
5968 only in a specific thread. */
5971 /* Extract the thread ID from the next token. */
5972 thread
= strtol (id_tok_start
, &endp
, 0);
5974 /* Check if the user provided a valid numeric value for the
5976 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5977 error (_("Invalid thread ID specification %s."), id_tok_start
);
5979 /* Check if the thread actually exists. */
5980 if (!valid_thread_id (thread
))
5981 error (_("Unknown thread %d."), thread
);
5983 /* Truncate the string and get rid of the thread <thread_num>
5984 parameter before the parameter list is parsed by the
5985 evaluate_expression() function. */
5990 /* Parse the rest of the arguments. */
5991 innermost_block
= NULL
;
5993 exp
= parse_exp_1 (&arg
, 0, 0);
5995 exp_valid_block
= innermost_block
;
5996 mark
= value_mark ();
5997 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5999 release_value (val
);
6002 while (*tok
== ' ' || *tok
== '\t')
6006 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6009 toklen
= end_tok
- tok
;
6010 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6012 tok
= cond_start
= end_tok
+ 1;
6013 cond
= parse_exp_1 (&tok
, 0, 0);
6017 error (_("Junk at end of command."));
6019 if (accessflag
== hw_read
)
6020 bp_type
= bp_read_watchpoint
;
6021 else if (accessflag
== hw_access
)
6022 bp_type
= bp_access_watchpoint
;
6024 bp_type
= bp_hardware_watchpoint
;
6026 mem_cnt
= can_use_hardware_watchpoint (val
);
6027 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
6028 error (_("Expression cannot be implemented with read/access watchpoint."));
6031 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
6032 target_resources_ok
=
6033 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
6035 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
6036 error (_("Target does not support this type of hardware watchpoint."));
6038 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
6039 error (_("Target can only support one kind of HW watchpoint at a time."));
6042 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6043 watchpoint could not be set. */
6044 if (!mem_cnt
|| target_resources_ok
<= 0)
6045 bp_type
= bp_watchpoint
;
6047 frame
= block_innermost_frame (exp_valid_block
);
6049 prev_frame
= get_prev_frame (frame
);
6053 /* If the expression is "local", then set up a "watchpoint scope"
6054 breakpoint at the point where we've left the scope of the watchpoint
6055 expression. Create the scope breakpoint before the watchpoint, so
6056 that we will encounter it first in bpstat_stop_status. */
6057 if (innermost_block
&& prev_frame
)
6059 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
6060 bp_watchpoint_scope
);
6062 scope_breakpoint
->enable_state
= bp_enabled
;
6064 /* Automatically delete the breakpoint when it hits. */
6065 scope_breakpoint
->disposition
= disp_del
;
6067 /* Only break in the proper frame (help with recursion). */
6068 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6070 /* Set the address at which we will stop. */
6071 scope_breakpoint
->loc
->requested_address
6072 = get_frame_pc (prev_frame
);
6073 scope_breakpoint
->loc
->address
6074 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6075 scope_breakpoint
->type
);
6078 /* Now set up the breakpoint. */
6079 b
= set_raw_breakpoint (sal
, bp_type
);
6080 set_breakpoint_count (breakpoint_count
+ 1);
6081 b
->number
= breakpoint_count
;
6083 b
->disposition
= disp_donttouch
;
6085 b
->exp_valid_block
= exp_valid_block
;
6086 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6089 b
->loc
->cond
= cond
;
6091 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6096 b
->watchpoint_frame
= get_frame_id (frame
);
6098 b
->watchpoint_frame
= null_frame_id
;
6100 if (scope_breakpoint
!= NULL
)
6102 /* The scope breakpoint is related to the watchpoint. We will
6103 need to act on them together. */
6104 b
->related_breakpoint
= scope_breakpoint
;
6105 scope_breakpoint
->related_breakpoint
= b
;
6108 value_free_to_mark (mark
);
6110 update_global_location_list (1);
6113 /* Return count of locations need to be watched and can be handled
6114 in hardware. If the watchpoint can not be handled
6115 in hardware return zero. */
6118 can_use_hardware_watchpoint (struct value
*v
)
6120 int found_memory_cnt
= 0;
6121 struct value
*head
= v
;
6123 /* Did the user specifically forbid us to use hardware watchpoints? */
6124 if (!can_use_hw_watchpoints
)
6127 /* Make sure that the value of the expression depends only upon
6128 memory contents, and values computed from them within GDB. If we
6129 find any register references or function calls, we can't use a
6130 hardware watchpoint.
6132 The idea here is that evaluating an expression generates a series
6133 of values, one holding the value of every subexpression. (The
6134 expression a*b+c has five subexpressions: a, b, a*b, c, and
6135 a*b+c.) GDB's values hold almost enough information to establish
6136 the criteria given above --- they identify memory lvalues,
6137 register lvalues, computed values, etcetera. So we can evaluate
6138 the expression, and then scan the chain of values that leaves
6139 behind to decide whether we can detect any possible change to the
6140 expression's final value using only hardware watchpoints.
6142 However, I don't think that the values returned by inferior
6143 function calls are special in any way. So this function may not
6144 notice that an expression involving an inferior function call
6145 can't be watched with hardware watchpoints. FIXME. */
6146 for (; v
; v
= value_next (v
))
6148 if (VALUE_LVAL (v
) == lval_memory
)
6151 /* A lazy memory lvalue is one that GDB never needed to fetch;
6152 we either just used its address (e.g., `a' in `a.b') or
6153 we never needed it at all (e.g., `a' in `a,b'). */
6157 /* Ahh, memory we actually used! Check if we can cover
6158 it with hardware watchpoints. */
6159 struct type
*vtype
= check_typedef (value_type (v
));
6161 /* We only watch structs and arrays if user asked for it
6162 explicitly, never if they just happen to appear in a
6163 middle of some value chain. */
6165 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6166 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6168 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6169 int len
= TYPE_LENGTH (value_type (v
));
6171 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6178 else if (VALUE_LVAL (v
) != not_lval
6179 && deprecated_value_modifiable (v
) == 0)
6180 return 0; /* ??? What does this represent? */
6181 else if (VALUE_LVAL (v
) == lval_register
)
6182 return 0; /* cannot watch a register with a HW watchpoint */
6185 /* The expression itself looks suitable for using a hardware
6186 watchpoint, but give the target machine a chance to reject it. */
6187 return found_memory_cnt
;
6191 watch_command_wrapper (char *arg
, int from_tty
)
6193 watch_command (arg
, from_tty
);
6197 watch_command (char *arg
, int from_tty
)
6199 watch_command_1 (arg
, hw_write
, from_tty
);
6203 rwatch_command_wrapper (char *arg
, int from_tty
)
6205 rwatch_command (arg
, from_tty
);
6209 rwatch_command (char *arg
, int from_tty
)
6211 watch_command_1 (arg
, hw_read
, from_tty
);
6215 awatch_command_wrapper (char *arg
, int from_tty
)
6217 awatch_command (arg
, from_tty
);
6221 awatch_command (char *arg
, int from_tty
)
6223 watch_command_1 (arg
, hw_access
, from_tty
);
6227 /* Helper routines for the until_command routine in infcmd.c. Here
6228 because it uses the mechanisms of breakpoints. */
6230 struct until_break_command_continuation_args
6232 struct breakpoint
*breakpoint
;
6233 struct breakpoint
*breakpoint2
;
6236 /* This function is called by fetch_inferior_event via the
6237 cmd_continuation pointer, to complete the until command. It takes
6238 care of cleaning up the temporary breakpoints set up by the until
6241 until_break_command_continuation (void *arg
)
6243 struct until_break_command_continuation_args
*a
= arg
;
6245 delete_breakpoint (a
->breakpoint
);
6247 delete_breakpoint (a
->breakpoint2
);
6251 until_break_command (char *arg
, int from_tty
, int anywhere
)
6253 struct symtabs_and_lines sals
;
6254 struct symtab_and_line sal
;
6255 struct frame_info
*frame
= get_selected_frame (NULL
);
6256 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6257 struct breakpoint
*breakpoint
;
6258 struct breakpoint
*breakpoint2
= NULL
;
6259 struct cleanup
*old_chain
;
6261 clear_proceed_status ();
6263 /* Set a breakpoint where the user wants it and at return from
6266 if (default_breakpoint_valid
)
6267 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6268 default_breakpoint_line
, (char ***) NULL
, NULL
);
6270 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6271 0, (char ***) NULL
, NULL
);
6273 if (sals
.nelts
!= 1)
6274 error (_("Couldn't get information on specified line."));
6277 xfree (sals
.sals
); /* malloc'd, so freed */
6280 error (_("Junk at end of arguments."));
6282 resolve_sal_pc (&sal
);
6285 /* If the user told us to continue until a specified location,
6286 we don't specify a frame at which we need to stop. */
6287 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6289 /* Otherwise, specify the current frame, because we want to stop only
6290 at the very same frame. */
6291 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6294 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6296 /* Keep within the current frame, or in frames called by the current
6300 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6301 sal
.pc
= get_frame_pc (prev_frame
);
6302 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6304 make_cleanup_delete_breakpoint (breakpoint2
);
6307 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6309 /* If we are running asynchronously, and proceed call above has actually
6310 managed to start the target, arrange for breakpoints to be
6311 deleted when the target stops. Otherwise, we're already stopped and
6312 delete breakpoints via cleanup chain. */
6314 if (target_can_async_p () && is_running (inferior_ptid
))
6316 struct until_break_command_continuation_args
*args
;
6317 args
= xmalloc (sizeof (*args
));
6319 args
->breakpoint
= breakpoint
;
6320 args
->breakpoint2
= breakpoint2
;
6322 discard_cleanups (old_chain
);
6323 add_continuation (until_break_command_continuation
, args
,
6327 do_cleanups (old_chain
);
6331 ep_skip_leading_whitespace (char **s
)
6333 if ((s
== NULL
) || (*s
== NULL
))
6335 while (isspace (**s
))
6339 /* This function attempts to parse an optional "if <cond>" clause
6340 from the arg string. If one is not found, it returns NULL.
6342 Else, it returns a pointer to the condition string. (It does not
6343 attempt to evaluate the string against a particular block.) And,
6344 it updates arg to point to the first character following the parsed
6345 if clause in the arg string. */
6348 ep_parse_optional_if_clause (char **arg
)
6352 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6355 /* Skip the "if" keyword. */
6358 /* Skip any extra leading whitespace, and record the start of the
6359 condition string. */
6360 ep_skip_leading_whitespace (arg
);
6363 /* Assume that the condition occupies the remainder of the arg string. */
6364 (*arg
) += strlen (cond_string
);
6369 /* This function attempts to parse an optional filename from the arg
6370 string. If one is not found, it returns NULL.
6372 Else, it returns a pointer to the parsed filename. (This function
6373 makes no attempt to verify that a file of that name exists, or is
6374 accessible.) And, it updates arg to point to the first character
6375 following the parsed filename in the arg string.
6377 Note that clients needing to preserve the returned filename for
6378 future access should copy it to their own buffers. */
6380 ep_parse_optional_filename (char **arg
)
6382 static char filename
[1024];
6387 if ((*arg_p
== '\0') || isspace (*arg_p
))
6405 /* Commands to deal with catching events, such as signals, exceptions,
6406 process start/exit, etc. */
6410 catch_fork_temporary
, catch_vfork_temporary
,
6411 catch_fork_permanent
, catch_vfork_permanent
6416 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6418 char *cond_string
= NULL
;
6419 catch_fork_kind fork_kind
;
6422 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6423 tempflag
= (fork_kind
== catch_fork_temporary
6424 || fork_kind
== catch_vfork_temporary
);
6428 ep_skip_leading_whitespace (&arg
);
6430 /* The allowed syntax is:
6432 catch [v]fork if <cond>
6434 First, check if there's an if clause. */
6435 cond_string
= ep_parse_optional_if_clause (&arg
);
6437 if ((*arg
!= '\0') && !isspace (*arg
))
6438 error (_("Junk at end of arguments."));
6440 /* If this target supports it, create a fork or vfork catchpoint
6441 and enable reporting of such events. */
6444 case catch_fork_temporary
:
6445 case catch_fork_permanent
:
6446 create_fork_event_catchpoint (tempflag
, cond_string
);
6448 case catch_vfork_temporary
:
6449 case catch_vfork_permanent
:
6450 create_vfork_event_catchpoint (tempflag
, cond_string
);
6453 error (_("unsupported or unknown fork kind; cannot catch it"));
6459 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6462 char *cond_string
= NULL
;
6464 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6468 ep_skip_leading_whitespace (&arg
);
6470 /* The allowed syntax is:
6472 catch exec if <cond>
6474 First, check if there's an if clause. */
6475 cond_string
= ep_parse_optional_if_clause (&arg
);
6477 if ((*arg
!= '\0') && !isspace (*arg
))
6478 error (_("Junk at end of arguments."));
6480 /* If this target supports it, create an exec catchpoint
6481 and enable reporting of such events. */
6482 create_exec_event_catchpoint (tempflag
, cond_string
);
6486 catch_load_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6489 char *dll_pathname
= NULL
;
6490 char *cond_string
= NULL
;
6492 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6496 ep_skip_leading_whitespace (&arg
);
6498 /* The allowed syntax is:
6500 catch load if <cond>
6501 catch load <filename>
6502 catch load <filename> if <cond>
6504 The user is not allowed to specify the <filename> after an
6507 We'll ignore the pathological case of a file named "if".
6509 First, check if there's an if clause. If so, then there
6510 cannot be a filename. */
6511 cond_string
= ep_parse_optional_if_clause (&arg
);
6513 /* If there was an if clause, then there cannot be a filename.
6514 Else, there might be a filename and an if clause. */
6515 if (cond_string
== NULL
)
6517 dll_pathname
= ep_parse_optional_filename (&arg
);
6518 ep_skip_leading_whitespace (&arg
);
6519 cond_string
= ep_parse_optional_if_clause (&arg
);
6522 if ((*arg
!= '\0') && !isspace (*arg
))
6523 error (_("Junk at end of arguments."));
6525 /* Create a load breakpoint that only triggers when a load of
6526 the specified dll (or any dll, if no pathname was specified)
6528 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6529 dll_pathname
, cond_string
);
6533 catch_unload_command_1 (char *arg
, int from_tty
,
6534 struct cmd_list_element
*command
)
6537 char *dll_pathname
= NULL
;
6538 char *cond_string
= NULL
;
6540 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6544 ep_skip_leading_whitespace (&arg
);
6546 /* The allowed syntax is:
6548 catch unload if <cond>
6549 catch unload <filename>
6550 catch unload <filename> if <cond>
6552 The user is not allowed to specify the <filename> after an
6555 We'll ignore the pathological case of a file named "if".
6557 First, check if there's an if clause. If so, then there
6558 cannot be a filename. */
6559 cond_string
= ep_parse_optional_if_clause (&arg
);
6561 /* If there was an if clause, then there cannot be a filename.
6562 Else, there might be a filename and an if clause. */
6563 if (cond_string
== NULL
)
6565 dll_pathname
= ep_parse_optional_filename (&arg
);
6566 ep_skip_leading_whitespace (&arg
);
6567 cond_string
= ep_parse_optional_if_clause (&arg
);
6570 if ((*arg
!= '\0') && !isspace (*arg
))
6571 error (_("Junk at end of arguments."));
6573 /* Create an unload breakpoint that only triggers when an unload of
6574 the specified dll (or any dll, if no pathname was specified)
6576 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6577 dll_pathname
, cond_string
);
6580 static enum print_stop_action
6581 print_exception_catchpoint (struct breakpoint
*b
)
6583 int bp_temp
, bp_throw
;
6585 annotate_catchpoint (b
->number
);
6587 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6588 if (b
->loc
->address
!= b
->loc
->requested_address
)
6589 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6592 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6594 bp_temp
? "Temporary catchpoint "
6596 if (!ui_out_is_mi_like_p (uiout
))
6597 ui_out_field_int (uiout
, "bkptno", b
->number
);
6599 bp_throw
? " (exception thrown), "
6600 : " (exception caught), ");
6601 if (ui_out_is_mi_like_p (uiout
))
6603 ui_out_field_string (uiout
, "reason",
6604 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6605 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6606 ui_out_field_int (uiout
, "bkptno", b
->number
);
6608 return PRINT_SRC_AND_LOC
;
6612 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6617 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6618 ui_out_field_string (uiout
, "addr", "<PENDING>");
6620 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6624 *last_addr
= b
->loc
->address
;
6625 if (strstr (b
->addr_string
, "throw") != NULL
)
6626 ui_out_field_string (uiout
, "what", "exception throw");
6628 ui_out_field_string (uiout
, "what", "exception catch");
6632 print_mention_exception_catchpoint (struct breakpoint
*b
)
6637 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6638 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6639 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6640 : _("Catchpoint "));
6641 ui_out_field_int (uiout
, "bkptno", b
->number
);
6642 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6646 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6647 print_exception_catchpoint
,
6648 print_one_exception_catchpoint
,
6649 print_mention_exception_catchpoint
6653 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6654 enum exception_event_kind ex_event
, int from_tty
)
6656 char *trigger_func_name
;
6658 if (ex_event
== EX_EVENT_CATCH
)
6659 trigger_func_name
= "__cxa_begin_catch";
6661 trigger_func_name
= "__cxa_throw";
6663 break_command_really (trigger_func_name
, cond_string
, -1,
6664 0 /* condition and thread are valid. */,
6667 AUTO_BOOLEAN_TRUE
/* pending */,
6668 &gnu_v3_exception_catchpoint_ops
, from_tty
);
6673 /* Deal with "catch catch" and "catch throw" commands */
6676 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6677 int tempflag
, int from_tty
)
6679 char *cond_string
= NULL
;
6680 struct symtab_and_line
*sal
= NULL
;
6684 ep_skip_leading_whitespace (&arg
);
6686 cond_string
= ep_parse_optional_if_clause (&arg
);
6688 if ((*arg
!= '\0') && !isspace (*arg
))
6689 error (_("Junk at end of arguments."));
6691 if ((ex_event
!= EX_EVENT_THROW
) &&
6692 (ex_event
!= EX_EVENT_CATCH
))
6693 error (_("Unsupported or unknown exception event; cannot catch it"));
6695 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6698 warning (_("Unsupported with this platform/compiler combination."));
6701 /* Implementation of "catch catch" command. */
6704 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6706 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6707 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6710 /* Implementation of "catch throw" command. */
6713 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6715 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6716 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6719 /* Create a breakpoint struct for Ada exception catchpoints. */
6722 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6726 struct expression
*cond
,
6727 struct breakpoint_ops
*ops
,
6731 struct breakpoint
*b
;
6735 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6736 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6737 version for exception catchpoints, because two catchpoints
6738 used for different exception names will use the same address.
6739 In this case, a "breakpoint ... also set at..." warning is
6740 unproductive. Besides. the warning phrasing is also a bit
6741 inapropriate, we should use the word catchpoint, and tell
6742 the user what type of catchpoint it is. The above is good
6743 enough for now, though. */
6746 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6747 set_breakpoint_count (breakpoint_count
+ 1);
6749 b
->enable_state
= bp_enabled
;
6750 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6751 b
->number
= breakpoint_count
;
6752 b
->ignore_count
= 0;
6753 b
->loc
->cond
= cond
;
6754 b
->addr_string
= addr_string
;
6755 b
->language
= language_ada
;
6756 b
->cond_string
= cond_string
;
6757 b
->exp_string
= exp_string
;
6762 update_global_location_list (1);
6765 /* Implement the "catch exception" command. */
6768 catch_ada_exception_command (char *arg
, int from_tty
,
6769 struct cmd_list_element
*command
)
6772 struct symtab_and_line sal
;
6774 char *addr_string
= NULL
;
6775 char *exp_string
= NULL
;
6776 char *cond_string
= NULL
;
6777 struct expression
*cond
= NULL
;
6778 struct breakpoint_ops
*ops
= NULL
;
6780 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6784 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6785 &cond_string
, &cond
, &ops
);
6786 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6787 cond_string
, cond
, ops
, tempflag
,
6791 /* Implement the "catch assert" command. */
6794 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6797 struct symtab_and_line sal
;
6798 char *addr_string
= NULL
;
6799 struct breakpoint_ops
*ops
= NULL
;
6801 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6805 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6806 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6807 tempflag
, from_tty
);
6811 catch_command (char *arg
, int from_tty
)
6813 error (_("Catch requires an event name."));
6818 tcatch_command (char *arg
, int from_tty
)
6820 error (_("Catch requires an event name."));
6823 /* Delete breakpoints by address or line. */
6826 clear_command (char *arg
, int from_tty
)
6828 struct breakpoint
*b
;
6829 VEC(breakpoint_p
) *found
= 0;
6832 struct symtabs_and_lines sals
;
6833 struct symtab_and_line sal
;
6838 sals
= decode_line_spec (arg
, 1);
6843 sals
.sals
= (struct symtab_and_line
*)
6844 xmalloc (sizeof (struct symtab_and_line
));
6845 make_cleanup (xfree
, sals
.sals
);
6846 init_sal (&sal
); /* initialize to zeroes */
6847 sal
.line
= default_breakpoint_line
;
6848 sal
.symtab
= default_breakpoint_symtab
;
6849 sal
.pc
= default_breakpoint_address
;
6850 if (sal
.symtab
== 0)
6851 error (_("No source file specified."));
6859 /* We don't call resolve_sal_pc here. That's not
6860 as bad as it seems, because all existing breakpoints
6861 typically have both file/line and pc set. So, if
6862 clear is given file/line, we can match this to existing
6863 breakpoint without obtaining pc at all.
6865 We only support clearing given the address explicitly
6866 present in breakpoint table. Say, we've set breakpoint
6867 at file:line. There were several PC values for that file:line,
6868 due to optimization, all in one block.
6869 We've picked one PC value. If "clear" is issued with another
6870 PC corresponding to the same file:line, the breakpoint won't
6871 be cleared. We probably can still clear the breakpoint, but
6872 since the other PC value is never presented to user, user
6873 can only find it by guessing, and it does not seem important
6876 /* For each line spec given, delete bps which correspond
6877 to it. Do it in two passes, solely to preserve the current
6878 behavior that from_tty is forced true if we delete more than
6882 for (i
= 0; i
< sals
.nelts
; i
++)
6884 /* If exact pc given, clear bpts at that pc.
6885 If line given (pc == 0), clear all bpts on specified line.
6886 If defaulting, clear all bpts on default line
6889 defaulting sal.pc != 0 tests to do
6894 1 0 <can't happen> */
6898 /* Find all matching breakpoints and add them to
6903 /* Are we going to delete b? */
6904 if (b
->type
!= bp_none
6905 && b
->type
!= bp_watchpoint
6906 && b
->type
!= bp_hardware_watchpoint
6907 && b
->type
!= bp_read_watchpoint
6908 && b
->type
!= bp_access_watchpoint
)
6910 struct bp_location
*loc
= b
->loc
;
6911 for (; loc
; loc
= loc
->next
)
6913 int pc_match
= sal
.pc
6914 && (loc
->address
== sal
.pc
)
6915 && (!section_is_overlay (loc
->section
)
6916 || loc
->section
== sal
.section
);
6917 int line_match
= ((default_match
|| (0 == sal
.pc
))
6918 && b
->source_file
!= NULL
6919 && sal
.symtab
!= NULL
6920 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6921 && b
->line_number
== sal
.line
);
6922 if (pc_match
|| line_match
)
6931 VEC_safe_push(breakpoint_p
, found
, b
);
6934 /* Now go thru the 'found' chain and delete them. */
6935 if (VEC_empty(breakpoint_p
, found
))
6938 error (_("No breakpoint at %s."), arg
);
6940 error (_("No breakpoint at this line."));
6943 if (VEC_length(breakpoint_p
, found
) > 1)
6944 from_tty
= 1; /* Always report if deleted more than one */
6947 if (VEC_length(breakpoint_p
, found
) == 1)
6948 printf_unfiltered (_("Deleted breakpoint "));
6950 printf_unfiltered (_("Deleted breakpoints "));
6952 breakpoints_changed ();
6954 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6957 printf_unfiltered ("%d ", b
->number
);
6958 delete_breakpoint (b
);
6961 putchar_unfiltered ('\n');
6964 /* Delete breakpoint in BS if they are `delete' breakpoints and
6965 all breakpoints that are marked for deletion, whether hit or not.
6966 This is called after any breakpoint is hit, or after errors. */
6969 breakpoint_auto_delete (bpstat bs
)
6971 struct breakpoint
*b
, *temp
;
6973 for (; bs
; bs
= bs
->next
)
6974 if (bs
->breakpoint_at
6975 && bs
->breakpoint_at
->owner
6976 && bs
->breakpoint_at
->owner
->disposition
== disp_del
6978 delete_breakpoint (bs
->breakpoint_at
->owner
);
6980 ALL_BREAKPOINTS_SAFE (b
, temp
)
6982 if (b
->disposition
== disp_del_at_next_stop
)
6983 delete_breakpoint (b
);
6987 /* If SHOULD_INSERT is true, do not insert any breakpoint locations
6988 into the inferior, only remove already-inserted locations that no
6989 longer should be inserted. Functions that delete a breakpoint or
6990 breakpoints should pass false, so that deleting a breakpoint
6991 doesn't have the side effect of inserting the locations of other
6992 breakpoints that are marked not-inserted, but should_be_inserted
6993 returns true on them.
6995 This behaviour is useful is situations close to tear-down -- e.g.,
6996 after an exec, while the target still has execution, but breakpoint
6997 shadows of the previous executable image should *NOT* be restored
6998 to the new image; or before detaching, where the target still has
6999 execution and wants to delete breakpoints from GDB's lists, and all
7000 breakpoints had already been removed from the inferior. */
7003 update_global_location_list (int should_insert
)
7005 struct breakpoint
*b
;
7006 struct bp_location
**next
= &bp_location_chain
;
7007 struct bp_location
*loc
;
7008 struct bp_location
*loc2
;
7009 struct gdb_exception e
;
7010 VEC(bp_location_p
) *old_locations
= NULL
;
7014 /* Store old locations for future reference. */
7015 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7016 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7018 bp_location_chain
= NULL
;
7021 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7024 next
= &(loc
->global_next
);
7029 /* Identify bp_location instances that are no longer present in the new
7030 list, and therefore should be freed. Note that it's not necessary that
7031 those locations should be removed from inferior -- if there's another
7032 location at the same address (previously marked as duplicate),
7033 we don't need to remove/insert the location. */
7034 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7036 /* Tells if 'loc' is found amoung the new locations. If not, we
7038 int found_object
= 0;
7039 /* Tells if the location should remain inserted in the target. */
7040 int keep_in_target
= 0;
7042 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7049 /* If this location is no longer present, and inserted, look if there's
7050 maybe a new location at the same address. If so, mark that one
7051 inserted, and don't remove this one. This is needed so that we
7052 don't have a time window where a breakpoint at certain location is not
7057 /* If the location is inserted now, we might have to remove it. */
7059 if (found_object
&& should_be_inserted (loc
))
7061 /* The location is still present in the location list, and still
7062 should be inserted. Don't do anything. */
7067 /* The location is either no longer present, or got disabled.
7068 See if there's another location at the same address, in which
7069 case we don't need to remove this one from the target. */
7070 if (breakpoint_address_is_meaningful (loc
->owner
))
7071 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7073 /* For the sake of should_insert_location. The
7074 call to check_duplicates will fix up this later. */
7075 loc2
->duplicate
= 0;
7076 if (should_be_inserted (loc2
)
7077 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7080 loc2
->target_info
= loc
->target_info
;
7087 if (!keep_in_target
)
7089 if (remove_breakpoint (loc
, mark_uninserted
))
7091 /* This is just about all we can do. We could keep this
7092 location on the global list, and try to remove it next
7093 time, but there's no particular reason why we will
7096 Note that at this point, loc->owner is still valid,
7097 as delete_breakpoint frees the breakpoint only
7098 after calling us. */
7099 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7100 loc
->owner
->number
);
7110 /* This location was removed from the targets. In non-stop mode,
7111 a race condition is possible where we've removed a breakpoint,
7112 but stop events for that breakpoint are already queued and will
7113 arrive later. To suppress spurious SIGTRAPs reported to user,
7114 we keep this breakpoint location for a bit, and will retire it
7115 after we see 3 * thread_count events.
7116 The theory here is that reporting of events should,
7117 "on the average", be fair, so after that many event we'll see
7118 events from all threads that have anything of interest, and no
7119 longer need to keep this breakpoint. This is just a
7120 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7121 which is usability issue, but not a correctness problem. */
7122 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7126 free_bp_location (loc
);
7132 check_duplicates (b
);
7135 if (breakpoints_always_inserted_mode ()
7137 && target_has_execution
)
7138 insert_breakpoint_locations ();
7142 breakpoint_retire_moribund (void)
7144 struct bp_location
*loc
;
7147 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7148 if (--(loc
->events_till_retirement
) == 0)
7150 free_bp_location (loc
);
7151 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7157 update_global_location_list_nothrow (int inserting
)
7159 struct gdb_exception e
;
7160 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7161 update_global_location_list (inserting
);
7164 /* Clear BPT from a BPS. */
7166 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7169 for (bs
= bps
; bs
; bs
= bs
->next
)
7170 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7172 bs
->breakpoint_at
= NULL
;
7174 /* bs->commands will be freed later. */
7178 /* Callback for iterate_over_threads. */
7180 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7182 struct breakpoint
*bpt
= data
;
7183 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7187 /* Delete a breakpoint and clean up all traces of it in the data
7191 delete_breakpoint (struct breakpoint
*bpt
)
7193 struct breakpoint
*b
;
7194 struct bp_location
*loc
, *next
;
7196 gdb_assert (bpt
!= NULL
);
7198 /* Has this bp already been deleted? This can happen because multiple
7199 lists can hold pointers to bp's. bpstat lists are especial culprits.
7201 One example of this happening is a watchpoint's scope bp. When the
7202 scope bp triggers, we notice that the watchpoint is out of scope, and
7203 delete it. We also delete its scope bp. But the scope bp is marked
7204 "auto-deleting", and is already on a bpstat. That bpstat is then
7205 checked for auto-deleting bp's, which are deleted.
7207 A real solution to this problem might involve reference counts in bp's,
7208 and/or giving them pointers back to their referencing bpstat's, and
7209 teaching delete_breakpoint to only free a bp's storage when no more
7210 references were extent. A cheaper bandaid was chosen. */
7211 if (bpt
->type
== bp_none
)
7214 observer_notify_breakpoint_deleted (bpt
->number
);
7216 if (breakpoint_chain
== bpt
)
7217 breakpoint_chain
= bpt
->next
;
7222 b
->next
= bpt
->next
;
7226 free_command_lines (&bpt
->commands
);
7227 if (bpt
->cond_string
!= NULL
)
7228 xfree (bpt
->cond_string
);
7229 if (bpt
->addr_string
!= NULL
)
7230 xfree (bpt
->addr_string
);
7231 if (bpt
->exp
!= NULL
)
7233 if (bpt
->exp_string
!= NULL
)
7234 xfree (bpt
->exp_string
);
7235 if (bpt
->val
!= NULL
)
7236 value_free (bpt
->val
);
7237 if (bpt
->source_file
!= NULL
)
7238 xfree (bpt
->source_file
);
7239 if (bpt
->dll_pathname
!= NULL
)
7240 xfree (bpt
->dll_pathname
);
7241 if (bpt
->triggered_dll_pathname
!= NULL
)
7242 xfree (bpt
->triggered_dll_pathname
);
7243 if (bpt
->exec_pathname
!= NULL
)
7244 xfree (bpt
->exec_pathname
);
7246 /* Be sure no bpstat's are pointing at it after it's been freed. */
7247 /* FIXME, how can we find all bpstat's?
7248 We just check stop_bpstat for now. Note that we cannot just
7249 remove bpstats pointing at bpt from the stop_bpstat list
7250 entirely, as breakpoint commands are associated with the bpstat;
7251 if we remove it here, then the later call to
7252 bpstat_do_actions (&stop_bpstat);
7253 in event-top.c won't do anything, and temporary breakpoints
7254 with commands won't work. */
7256 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7258 /* Now that breakpoint is removed from breakpoint
7259 list, update the global location list. This
7260 will remove locations that used to belong to
7261 this breakpoint. Do this before freeing
7262 the breakpoint itself, since remove_breakpoint
7263 looks at location's owner. It might be better
7264 design to have location completely self-contained,
7265 but it's not the case now. */
7266 update_global_location_list (0);
7269 /* On the chance that someone will soon try again to delete this same
7270 bp, we mark it as deleted before freeing its storage. */
7271 bpt
->type
= bp_none
;
7277 do_delete_breakpoint_cleanup (void *b
)
7279 delete_breakpoint (b
);
7283 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7285 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7289 delete_command (char *arg
, int from_tty
)
7291 struct breakpoint
*b
, *temp
;
7297 int breaks_to_delete
= 0;
7299 /* Delete all breakpoints if no argument.
7300 Do not delete internal or call-dummy breakpoints, these
7301 have to be deleted with an explicit breakpoint number argument. */
7304 if (b
->type
!= bp_call_dummy
&&
7305 b
->type
!= bp_shlib_event
&&
7306 b
->type
!= bp_thread_event
&&
7307 b
->type
!= bp_overlay_event
&&
7310 breaks_to_delete
= 1;
7315 /* Ask user only if there are some breakpoints to delete. */
7317 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7319 ALL_BREAKPOINTS_SAFE (b
, temp
)
7321 if (b
->type
!= bp_call_dummy
&&
7322 b
->type
!= bp_shlib_event
&&
7323 b
->type
!= bp_thread_event
&&
7324 b
->type
!= bp_overlay_event
&&
7326 delete_breakpoint (b
);
7331 map_breakpoint_numbers (arg
, delete_breakpoint
);
7335 all_locations_are_pending (struct bp_location
*loc
)
7337 for (; loc
; loc
= loc
->next
)
7338 if (!loc
->shlib_disabled
)
7343 /* Subroutine of update_breakpoint_locations to simplify it.
7344 Return non-zero if multiple fns in list LOC have the same name.
7345 Null names are ignored. */
7348 ambiguous_names_p (struct bp_location
*loc
)
7350 struct bp_location
*l
;
7351 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7352 (int (*) (const void *, const void *)) streq
,
7353 NULL
, xcalloc
, xfree
);
7355 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7358 const char *name
= l
->function_name
;
7360 /* Allow for some names to be NULL, ignore them. */
7364 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7366 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7381 update_breakpoint_locations (struct breakpoint
*b
,
7382 struct symtabs_and_lines sals
)
7386 struct bp_location
*existing_locations
= b
->loc
;
7388 /* If there's no new locations, and all existing locations
7389 are pending, don't do anything. This optimizes
7390 the common case where all locations are in the same
7391 shared library, that was unloaded. We'd like to
7392 retain the location, so that when the library
7393 is loaded again, we don't loose the enabled/disabled
7394 status of the individual locations. */
7395 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7400 for (i
= 0; i
< sals
.nelts
; ++i
)
7402 struct bp_location
*new_loc
=
7403 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7405 /* Reparse conditions, they might contain references to the
7407 if (b
->cond_string
!= NULL
)
7409 struct gdb_exception e
;
7412 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7414 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7419 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7420 b
->number
, e
.message
);
7421 new_loc
->enabled
= 0;
7425 if (b
->source_file
!= NULL
)
7426 xfree (b
->source_file
);
7427 if (sals
.sals
[i
].symtab
== NULL
)
7428 b
->source_file
= NULL
;
7431 savestring (sals
.sals
[i
].symtab
->filename
,
7432 strlen (sals
.sals
[i
].symtab
->filename
));
7434 if (b
->line_number
== 0)
7435 b
->line_number
= sals
.sals
[i
].line
;
7438 /* Update locations of permanent breakpoints. */
7439 if (b
->enable_state
== bp_permanent
)
7440 make_breakpoint_permanent (b
);
7442 /* If possible, carry over 'disable' status from existing breakpoints. */
7444 struct bp_location
*e
= existing_locations
;
7445 /* If there are multiple breakpoints with the same function name,
7446 e.g. for inline functions, comparing function names won't work.
7447 Instead compare pc addresses; this is just a heuristic as things
7448 may have moved, but in practice it gives the correct answer
7449 often enough until a better solution is found. */
7450 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7452 for (; e
; e
= e
->next
)
7454 if (!e
->enabled
&& e
->function_name
)
7456 struct bp_location
*l
= b
->loc
;
7457 if (have_ambiguous_names
)
7459 for (; l
; l
= l
->next
)
7460 if (e
->address
== l
->address
)
7468 for (; l
; l
= l
->next
)
7469 if (l
->function_name
7470 && strcmp (e
->function_name
, l
->function_name
) == 0)
7480 update_global_location_list (1);
7484 /* Reset a breakpoint given it's struct breakpoint * BINT.
7485 The value we return ends up being the return value from catch_errors.
7486 Unused in this case. */
7489 breakpoint_re_set_one (void *bint
)
7491 /* get past catch_errs */
7492 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7496 int *not_found_ptr
= ¬_found
;
7497 struct symtabs_and_lines sals
= {};
7498 struct symtabs_and_lines expanded
;
7500 enum enable_state save_enable
;
7501 struct gdb_exception e
;
7507 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7511 case bp_hardware_breakpoint
:
7513 case bp_catch_unload
:
7514 if (b
->addr_string
== NULL
)
7516 /* Anything without a string can't be re-set. */
7517 delete_breakpoint (b
);
7521 set_language (b
->language
);
7522 input_radix
= b
->input_radix
;
7524 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7526 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7531 int not_found_and_ok
= 0;
7532 /* For pending breakpoints, it's expected that parsing
7533 will fail until the right shared library is loaded.
7534 User has already told to create pending breakpoints and
7535 don't need extra messages. If breakpoint is in bp_shlib_disabled
7536 state, then user already saw the message about that breakpoint
7537 being disabled, and don't want to see more errors. */
7539 && (b
->condition_not_parsed
7540 || (b
->loc
&& b
->loc
->shlib_disabled
)
7541 || b
->enable_state
== bp_disabled
))
7542 not_found_and_ok
= 1;
7544 if (!not_found_and_ok
)
7546 /* We surely don't want to warn about the same breakpoint
7547 10 times. One solution, implemented here, is disable
7548 the breakpoint on error. Another solution would be to
7549 have separate 'warning emitted' flag. Since this
7550 happens only when a binary has changed, I don't know
7551 which approach is better. */
7552 b
->enable_state
= bp_disabled
;
7553 throw_exception (e
);
7560 gdb_assert (sals
.nelts
== 1);
7561 resolve_sal_pc (&sals
.sals
[0]);
7562 if (b
->condition_not_parsed
&& s
&& s
[0])
7564 char *cond_string
= 0;
7566 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7567 &cond_string
, &thread
);
7569 b
->cond_string
= cond_string
;
7571 b
->condition_not_parsed
= 0;
7573 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7574 update_breakpoint_locations (b
, expanded
);
7580 case bp_hardware_watchpoint
:
7581 case bp_read_watchpoint
:
7582 case bp_access_watchpoint
:
7583 /* Watchpoint can be either on expression using entirely global variables,
7584 or it can be on local variables.
7586 Watchpoints of the first kind are never auto-deleted, and even persist
7587 across program restarts. Since they can use variables from shared
7588 libraries, we need to reparse expression as libraries are loaded
7591 Watchpoints on local variables can also change meaning as result
7592 of solib event. For example, if a watchpoint uses both a local and
7593 a global variables in expression, it's a local watchpoint, but
7594 unloading of a shared library will make the expression invalid.
7595 This is not a very common use case, but we still re-evaluate
7596 expression, to avoid surprises to the user.
7598 Note that for local watchpoints, we re-evaluate it only if
7599 watchpoints frame id is still valid. If it's not, it means
7600 the watchpoint is out of scope and will be deleted soon. In fact,
7601 I'm not sure we'll ever be called in this case.
7603 If a local watchpoint's frame id is still valid, then
7604 b->exp_valid_block is likewise valid, and we can safely use it.
7606 Don't do anything about disabled watchpoints, since they will
7607 be reevaluated again when enabled. */
7608 update_watchpoint (b
, 1 /* reparse */);
7610 /* We needn't really do anything to reset these, since the mask
7611 that requests them is unaffected by e.g., new libraries being
7614 case bp_catch_vfork
:
7619 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7621 /* Delete overlay event breakpoints; they will be reset later by
7622 breakpoint_re_set. */
7623 case bp_overlay_event
:
7624 delete_breakpoint (b
);
7627 /* This breakpoint is special, it's set up when the inferior
7628 starts and we really don't want to touch it. */
7629 case bp_shlib_event
:
7631 /* Like bp_shlib_event, this breakpoint type is special.
7632 Once it is set up, we do not want to touch it. */
7633 case bp_thread_event
:
7635 /* Keep temporary breakpoints, which can be encountered when we step
7636 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7637 Otherwise these should have been blown away via the cleanup chain
7638 or by breakpoint_init_inferior when we rerun the executable. */
7641 case bp_watchpoint_scope
:
7643 case bp_step_resume
:
7645 case bp_longjmp_resume
:
7652 /* Re-set all breakpoints after symbols have been re-loaded. */
7654 breakpoint_re_set (void)
7656 struct breakpoint
*b
, *temp
;
7657 enum language save_language
;
7658 int save_input_radix
;
7660 save_language
= current_language
->la_language
;
7661 save_input_radix
= input_radix
;
7662 ALL_BREAKPOINTS_SAFE (b
, temp
)
7664 /* Format possible error msg */
7665 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7667 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7668 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7669 do_cleanups (cleanups
);
7671 set_language (save_language
);
7672 input_radix
= save_input_radix
;
7674 create_overlay_event_breakpoint ("_ovly_debug_event");
7677 /* Reset the thread number of this breakpoint:
7679 - If the breakpoint is for all threads, leave it as-is.
7680 - Else, reset it to the current thread for inferior_ptid. */
7682 breakpoint_re_set_thread (struct breakpoint
*b
)
7684 if (b
->thread
!= -1)
7686 if (in_thread_list (inferior_ptid
))
7687 b
->thread
= pid_to_thread_id (inferior_ptid
);
7691 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7692 If from_tty is nonzero, it prints a message to that effect,
7693 which ends with a period (no newline). */
7696 set_ignore_count (int bptnum
, int count
, int from_tty
)
7698 struct breakpoint
*b
;
7704 if (b
->number
== bptnum
)
7706 b
->ignore_count
= count
;
7710 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7712 else if (count
== 1)
7713 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7716 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7719 breakpoints_changed ();
7720 observer_notify_breakpoint_modified (b
->number
);
7724 error (_("No breakpoint number %d."), bptnum
);
7727 /* Clear the ignore counts of all breakpoints. */
7729 breakpoint_clear_ignore_counts (void)
7731 struct breakpoint
*b
;
7734 b
->ignore_count
= 0;
7737 /* Command to set ignore-count of breakpoint N to COUNT. */
7740 ignore_command (char *args
, int from_tty
)
7746 error_no_arg (_("a breakpoint number"));
7748 num
= get_number (&p
);
7750 error (_("bad breakpoint number: '%s'"), args
);
7752 error (_("Second argument (specified ignore-count) is missing."));
7754 set_ignore_count (num
,
7755 longest_to_int (value_as_long (parse_and_eval (p
))),
7758 printf_filtered ("\n");
7761 /* Call FUNCTION on each of the breakpoints
7762 whose numbers are given in ARGS. */
7765 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7770 struct breakpoint
*b
, *tmp
;
7774 error_no_arg (_("one or more breakpoint numbers"));
7781 num
= get_number_or_range (&p1
);
7784 warning (_("bad breakpoint number at or near '%s'"), p
);
7788 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7789 if (b
->number
== num
)
7791 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7794 if (related_breakpoint
)
7795 function (related_breakpoint
);
7799 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7805 static struct bp_location
*
7806 find_location_by_number (char *number
)
7808 char *dot
= strchr (number
, '.');
7812 struct breakpoint
*b
;
7813 struct bp_location
*loc
;
7818 bp_num
= get_number_or_range (&p1
);
7820 error (_("Bad breakpoint number '%s'"), number
);
7823 if (b
->number
== bp_num
)
7828 if (!b
|| b
->number
!= bp_num
)
7829 error (_("Bad breakpoint number '%s'"), number
);
7832 loc_num
= get_number_or_range (&p1
);
7834 error (_("Bad breakpoint location number '%s'"), number
);
7838 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7841 error (_("Bad breakpoint location number '%s'"), dot
+1);
7847 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7848 If from_tty is nonzero, it prints a message to that effect,
7849 which ends with a period (no newline). */
7852 disable_breakpoint (struct breakpoint
*bpt
)
7854 /* Never disable a watchpoint scope breakpoint; we want to
7855 hit them when we leave scope so we can delete both the
7856 watchpoint and its scope breakpoint at that time. */
7857 if (bpt
->type
== bp_watchpoint_scope
)
7860 /* You can't disable permanent breakpoints. */
7861 if (bpt
->enable_state
== bp_permanent
)
7864 bpt
->enable_state
= bp_disabled
;
7866 update_global_location_list (0);
7868 observer_notify_breakpoint_modified (bpt
->number
);
7872 disable_command (char *args
, int from_tty
)
7874 struct breakpoint
*bpt
;
7876 ALL_BREAKPOINTS (bpt
)
7880 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7885 case bp_catch_unload
:
7887 case bp_catch_vfork
:
7889 case bp_hardware_breakpoint
:
7891 case bp_hardware_watchpoint
:
7892 case bp_read_watchpoint
:
7893 case bp_access_watchpoint
:
7894 disable_breakpoint (bpt
);
7898 else if (strchr (args
, '.'))
7900 struct bp_location
*loc
= find_location_by_number (args
);
7903 update_global_location_list (0);
7906 map_breakpoint_numbers (args
, disable_breakpoint
);
7910 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7912 int target_resources_ok
, other_type_used
;
7915 if (bpt
->type
== bp_hardware_breakpoint
)
7918 i
= hw_breakpoint_used_count ();
7919 target_resources_ok
=
7920 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7922 if (target_resources_ok
== 0)
7923 error (_("No hardware breakpoint support in the target."));
7924 else if (target_resources_ok
< 0)
7925 error (_("Hardware breakpoints used exceeds limit."));
7928 if (bpt
->type
== bp_watchpoint
||
7929 bpt
->type
== bp_hardware_watchpoint
||
7930 bpt
->type
== bp_read_watchpoint
||
7931 bpt
->type
== bp_access_watchpoint
)
7933 struct frame_id saved_frame_id
;
7935 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7936 if (bpt
->exp_valid_block
!= NULL
)
7938 struct frame_info
*fr
=
7939 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7942 printf_filtered (_("\
7943 Cannot enable watchpoint %d because the block in which its expression\n\
7944 is valid is not currently in scope.\n"), bpt
->number
);
7951 value_free (bpt
->val
);
7952 mark
= value_mark ();
7953 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7955 release_value (bpt
->val
);
7958 if (bpt
->type
== bp_hardware_watchpoint
||
7959 bpt
->type
== bp_read_watchpoint
||
7960 bpt
->type
== bp_access_watchpoint
)
7962 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7963 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7965 /* Hack around 'unused var' error for some targets here */
7966 (void) mem_cnt
, (void) i
;
7967 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7968 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7969 /* we can consider of type is bp_hardware_watchpoint, convert to
7970 bp_watchpoint in the following condition */
7971 if (target_resources_ok
< 0)
7973 printf_filtered (_("\
7974 Cannot enable watchpoint %d because target watch resources\n\
7975 have been allocated for other watchpoints.\n"), bpt
->number
);
7976 value_free_to_mark (mark
);
7981 select_frame (frame_find_by_id (saved_frame_id
));
7982 value_free_to_mark (mark
);
7985 if (bpt
->enable_state
!= bp_permanent
)
7986 bpt
->enable_state
= bp_enabled
;
7987 bpt
->disposition
= disposition
;
7988 update_global_location_list (1);
7989 breakpoints_changed ();
7991 observer_notify_breakpoint_modified (bpt
->number
);
7996 enable_breakpoint (struct breakpoint
*bpt
)
7998 do_enable_breakpoint (bpt
, bpt
->disposition
);
8001 /* The enable command enables the specified breakpoints (or all defined
8002 breakpoints) so they once again become (or continue to be) effective
8003 in stopping the inferior. */
8006 enable_command (char *args
, int from_tty
)
8008 struct breakpoint
*bpt
;
8010 ALL_BREAKPOINTS (bpt
)
8014 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8019 case bp_catch_unload
:
8021 case bp_catch_vfork
:
8023 case bp_hardware_breakpoint
:
8025 case bp_hardware_watchpoint
:
8026 case bp_read_watchpoint
:
8027 case bp_access_watchpoint
:
8028 enable_breakpoint (bpt
);
8032 else if (strchr (args
, '.'))
8034 struct bp_location
*loc
= find_location_by_number (args
);
8037 update_global_location_list (1);
8040 map_breakpoint_numbers (args
, enable_breakpoint
);
8044 enable_once_breakpoint (struct breakpoint
*bpt
)
8046 do_enable_breakpoint (bpt
, disp_disable
);
8050 enable_once_command (char *args
, int from_tty
)
8052 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8056 enable_delete_breakpoint (struct breakpoint
*bpt
)
8058 do_enable_breakpoint (bpt
, disp_del
);
8062 enable_delete_command (char *args
, int from_tty
)
8064 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8068 set_breakpoint_cmd (char *args
, int from_tty
)
8073 show_breakpoint_cmd (char *args
, int from_tty
)
8077 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8079 struct symtabs_and_lines
8080 decode_line_spec_1 (char *string
, int funfirstline
)
8082 struct symtabs_and_lines sals
;
8084 error (_("Empty line specification."));
8085 if (default_breakpoint_valid
)
8086 sals
= decode_line_1 (&string
, funfirstline
,
8087 default_breakpoint_symtab
,
8088 default_breakpoint_line
,
8089 (char ***) NULL
, NULL
);
8091 sals
= decode_line_1 (&string
, funfirstline
,
8092 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8094 error (_("Junk at end of line specification: %s"), string
);
8098 /* Create and insert a raw software breakpoint at PC. Return an
8099 identifier, which should be used to remove the breakpoint later.
8100 In general, places which call this should be using something on the
8101 breakpoint chain instead; this function should be eliminated
8105 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8107 struct bp_target_info
*bp_tgt
;
8109 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8110 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8112 bp_tgt
->placed_address
= pc
;
8113 if (target_insert_breakpoint (bp_tgt
) != 0)
8115 /* Could not insert the breakpoint. */
8123 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8126 deprecated_remove_raw_breakpoint (void *bp
)
8128 struct bp_target_info
*bp_tgt
= bp
;
8131 ret
= target_remove_breakpoint (bp_tgt
);
8137 /* One (or perhaps two) breakpoints used for software single stepping. */
8139 static void *single_step_breakpoints
[2];
8141 /* Create and insert a breakpoint for software single step. */
8144 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8148 if (single_step_breakpoints
[0] == NULL
)
8149 bpt_p
= &single_step_breakpoints
[0];
8152 gdb_assert (single_step_breakpoints
[1] == NULL
);
8153 bpt_p
= &single_step_breakpoints
[1];
8156 /* NOTE drow/2006-04-11: A future improvement to this function would be
8157 to only create the breakpoints once, and actually put them on the
8158 breakpoint chain. That would let us use set_raw_breakpoint. We could
8159 adjust the addresses each time they were needed. Doing this requires
8160 corresponding changes elsewhere where single step breakpoints are
8161 handled, however. So, for now, we use this. */
8163 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8165 error (_("Could not insert single-step breakpoint at 0x%s"),
8166 paddr_nz (next_pc
));
8169 /* Remove and delete any breakpoints used for software single step. */
8172 remove_single_step_breakpoints (void)
8174 gdb_assert (single_step_breakpoints
[0] != NULL
);
8176 /* See insert_single_step_breakpoint for more about this deprecated
8178 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8179 single_step_breakpoints
[0] = NULL
;
8181 if (single_step_breakpoints
[1] != NULL
)
8183 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8184 single_step_breakpoints
[1] = NULL
;
8188 /* Check whether a software single-step breakpoint is inserted at PC. */
8191 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8195 for (i
= 0; i
< 2; i
++)
8197 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8198 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8206 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8207 It is defined as a macro to prevent duplication.
8208 COMMAND should be a string constant containing the name of the command. */
8209 #define BREAK_ARGS_HELP(command) \
8210 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8211 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8212 If a line number is specified, break at start of code for that line.\n\
8213 If a function is specified, break at start of code for that function.\n\
8214 If an address is specified, break at that exact address.\n\
8215 With no LOCATION, uses current execution address of selected stack frame.\n\
8216 This is useful for breaking on return to a stack frame.\n\
8218 THREADNUM is the number from \"info threads\".\n\
8219 CONDITION is a boolean expression.\n\
8221 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8223 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8225 /* List of subcommands for "catch". */
8226 static struct cmd_list_element
*catch_cmdlist
;
8228 /* List of subcommands for "tcatch". */
8229 static struct cmd_list_element
*tcatch_cmdlist
;
8231 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8232 lists, and pass some additional user data to the command function. */
8234 add_catch_command (char *name
, char *docstring
,
8235 void (*sfunc
) (char *args
, int from_tty
,
8236 struct cmd_list_element
*command
),
8237 void *user_data_catch
,
8238 void *user_data_tcatch
)
8240 struct cmd_list_element
*command
;
8242 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8244 set_cmd_sfunc (command
, sfunc
);
8245 set_cmd_context (command
, user_data_catch
);
8247 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8249 set_cmd_sfunc (command
, sfunc
);
8250 set_cmd_context (command
, user_data_tcatch
);
8254 _initialize_breakpoint (void)
8256 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8257 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8258 struct cmd_list_element
*c
;
8260 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8262 breakpoint_chain
= 0;
8263 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8264 before a breakpoint is set. */
8265 breakpoint_count
= 0;
8267 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8268 Set ignore-count of breakpoint number N to COUNT.\n\
8269 Usage is `ignore N COUNT'."));
8271 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8273 add_com ("commands", class_breakpoint
, commands_command
, _("\
8274 Set commands to be executed when a breakpoint is hit.\n\
8275 Give breakpoint number as argument after \"commands\".\n\
8276 With no argument, the targeted breakpoint is the last one set.\n\
8277 The commands themselves follow starting on the next line.\n\
8278 Type a line containing \"end\" to indicate the end of them.\n\
8279 Give \"silent\" as the first line to make the breakpoint silent;\n\
8280 then no output is printed when it is hit, except what the commands print."));
8282 add_com ("condition", class_breakpoint
, condition_command
, _("\
8283 Specify breakpoint number N to break only if COND is true.\n\
8284 Usage is `condition N COND', where N is an integer and COND is an\n\
8285 expression to be evaluated whenever breakpoint N is reached."));
8287 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8288 Set a temporary breakpoint.\n\
8289 Like \"break\" except the breakpoint is only temporary,\n\
8290 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8291 by using \"enable delete\" on the breakpoint number.\n\
8293 BREAK_ARGS_HELP ("tbreak")));
8294 set_cmd_completer (c
, location_completer
);
8296 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8297 Set a hardware assisted breakpoint.\n\
8298 Like \"break\" except the breakpoint requires hardware support,\n\
8299 some target hardware may not have this support.\n\
8301 BREAK_ARGS_HELP ("hbreak")));
8302 set_cmd_completer (c
, location_completer
);
8304 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8305 Set a temporary hardware assisted breakpoint.\n\
8306 Like \"hbreak\" except the breakpoint is only temporary,\n\
8307 so it will be deleted when hit.\n\
8309 BREAK_ARGS_HELP ("thbreak")));
8310 set_cmd_completer (c
, location_completer
);
8312 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8313 Enable some breakpoints.\n\
8314 Give breakpoint numbers (separated by spaces) as arguments.\n\
8315 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8316 This is used to cancel the effect of the \"disable\" command.\n\
8317 With a subcommand you can enable temporarily."),
8318 &enablelist
, "enable ", 1, &cmdlist
);
8320 add_com ("ab", class_breakpoint
, enable_command
, _("\
8321 Enable some breakpoints.\n\
8322 Give breakpoint numbers (separated by spaces) as arguments.\n\
8323 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8324 This is used to cancel the effect of the \"disable\" command.\n\
8325 With a subcommand you can enable temporarily."));
8327 add_com_alias ("en", "enable", class_breakpoint
, 1);
8329 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8330 Enable some breakpoints.\n\
8331 Give breakpoint numbers (separated by spaces) as arguments.\n\
8332 This is used to cancel the effect of the \"disable\" command.\n\
8333 May be abbreviated to simply \"enable\".\n"),
8334 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8336 add_cmd ("once", no_class
, enable_once_command
, _("\
8337 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8338 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8341 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8342 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8343 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8346 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8347 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8348 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8351 add_cmd ("once", no_class
, enable_once_command
, _("\
8352 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8353 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8356 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8357 Disable some breakpoints.\n\
8358 Arguments are breakpoint numbers with spaces in between.\n\
8359 To disable all breakpoints, give no argument.\n\
8360 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8361 &disablelist
, "disable ", 1, &cmdlist
);
8362 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8363 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8365 add_com ("sb", class_breakpoint
, disable_command
, _("\
8366 Disable some breakpoints.\n\
8367 Arguments are breakpoint numbers with spaces in between.\n\
8368 To disable all breakpoints, give no argument.\n\
8369 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8371 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8372 Disable some breakpoints.\n\
8373 Arguments are breakpoint numbers with spaces in between.\n\
8374 To disable all breakpoints, give no argument.\n\
8375 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8376 This command may be abbreviated \"disable\"."),
8379 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8380 Delete some breakpoints or auto-display expressions.\n\
8381 Arguments are breakpoint numbers with spaces in between.\n\
8382 To delete all breakpoints, give no argument.\n\
8384 Also a prefix command for deletion of other GDB objects.\n\
8385 The \"unset\" command is also an alias for \"delete\"."),
8386 &deletelist
, "delete ", 1, &cmdlist
);
8387 add_com_alias ("d", "delete", class_breakpoint
, 1);
8388 add_com_alias ("del", "delete", class_breakpoint
, 1);
8390 add_com ("db", class_breakpoint
, delete_command
, _("\
8391 Delete some breakpoints.\n\
8392 Arguments are breakpoint numbers with spaces in between.\n\
8393 To delete all breakpoints, give no argument.\n"));
8395 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8396 Delete some breakpoints or auto-display expressions.\n\
8397 Arguments are breakpoint numbers with spaces in between.\n\
8398 To delete all breakpoints, give no argument.\n\
8399 This command may be abbreviated \"delete\"."),
8402 add_com ("clear", class_breakpoint
, clear_command
, _("\
8403 Clear breakpoint at specified line or function.\n\
8404 Argument may be line number, function name, or \"*\" and an address.\n\
8405 If line number is specified, all breakpoints in that line are cleared.\n\
8406 If function is specified, breakpoints at beginning of function are cleared.\n\
8407 If an address is specified, breakpoints at that address are cleared.\n\
8409 With no argument, clears all breakpoints in the line that the selected frame\n\
8412 See also the \"delete\" command which clears breakpoints by number."));
8414 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8415 Set breakpoint at specified line or function.\n"
8416 BREAK_ARGS_HELP ("break")));
8417 set_cmd_completer (c
, location_completer
);
8419 add_com_alias ("b", "break", class_run
, 1);
8420 add_com_alias ("br", "break", class_run
, 1);
8421 add_com_alias ("bre", "break", class_run
, 1);
8422 add_com_alias ("brea", "break", class_run
, 1);
8426 add_com_alias ("ba", "break", class_breakpoint
, 1);
8427 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8432 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8433 Break in function/address or break at a line in the current file."),
8434 &stoplist
, "stop ", 1, &cmdlist
);
8435 add_cmd ("in", class_breakpoint
, stopin_command
,
8436 _("Break in function or address."), &stoplist
);
8437 add_cmd ("at", class_breakpoint
, stopat_command
,
8438 _("Break at a line in the current file."), &stoplist
);
8439 add_com ("status", class_info
, breakpoints_info
, _("\
8440 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8441 The \"Type\" column indicates one of:\n\
8442 \tbreakpoint - normal breakpoint\n\
8443 \twatchpoint - watchpoint\n\
8444 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8445 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8446 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8447 address and file/line number respectively.\n\
8449 Convenience variable \"$_\" and default examine address for \"x\"\n\
8450 are set to the address of the last breakpoint listed unless the command\n\
8451 is prefixed with \"server \".\n\n\
8452 Convenience variable \"$bpnum\" contains the number of the last\n\
8456 add_info ("breakpoints", breakpoints_info
, _("\
8457 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8458 The \"Type\" column indicates one of:\n\
8459 \tbreakpoint - normal breakpoint\n\
8460 \twatchpoint - watchpoint\n\
8461 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8462 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8463 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8464 address and file/line number respectively.\n\
8466 Convenience variable \"$_\" and default examine address for \"x\"\n\
8467 are set to the address of the last breakpoint listed unless the command\n\
8468 is prefixed with \"server \".\n\n\
8469 Convenience variable \"$bpnum\" contains the number of the last\n\
8473 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8474 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8475 The \"Type\" column indicates one of:\n\
8476 \tbreakpoint - normal breakpoint\n\
8477 \twatchpoint - watchpoint\n\
8478 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8479 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8480 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8481 address and file/line number respectively.\n\
8483 Convenience variable \"$_\" and default examine address for \"x\"\n\
8484 are set to the address of the last breakpoint listed unless the command\n\
8485 is prefixed with \"server \".\n\n\
8486 Convenience variable \"$bpnum\" contains the number of the last\n\
8489 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8490 Status of all breakpoints, or breakpoint number NUMBER.\n\
8491 The \"Type\" column indicates one of:\n\
8492 \tbreakpoint - normal breakpoint\n\
8493 \twatchpoint - watchpoint\n\
8494 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8495 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8496 \tuntil - internal breakpoint used by the \"until\" command\n\
8497 \tfinish - internal breakpoint used by the \"finish\" command\n\
8498 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8499 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8500 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8501 address and file/line number respectively.\n\
8503 Convenience variable \"$_\" and default examine address for \"x\"\n\
8504 are set to the address of the last breakpoint listed unless the command\n\
8505 is prefixed with \"server \".\n\n\
8506 Convenience variable \"$bpnum\" contains the number of the last\n\
8508 &maintenanceinfolist
);
8510 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
8511 Set catchpoints to catch events."),
8512 &catch_cmdlist
, "catch ",
8513 0/*allow-unknown*/, &cmdlist
);
8515 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
8516 Set temporary catchpoints to catch events."),
8517 &tcatch_cmdlist
, "tcatch ",
8518 0/*allow-unknown*/, &cmdlist
);
8520 /* Add catch and tcatch sub-commands. */
8521 add_catch_command ("catch", _("\
8522 Catch an exception, when caught.\n\
8523 With an argument, catch only exceptions with the given name."),
8524 catch_catch_command
,
8527 add_catch_command ("throw", _("\
8528 Catch an exception, when thrown.\n\
8529 With an argument, catch only exceptions with the given name."),
8530 catch_throw_command
,
8533 add_catch_command ("fork", _("Catch calls to fork."),
8534 catch_fork_command_1
,
8535 (void *) (uintptr_t) catch_fork_permanent
,
8536 (void *) (uintptr_t) catch_fork_temporary
);
8537 add_catch_command ("vfork", _("Catch calls to vfork."),
8538 catch_fork_command_1
,
8539 (void *) (uintptr_t) catch_vfork_permanent
,
8540 (void *) (uintptr_t) catch_vfork_temporary
);
8541 add_catch_command ("exec", _("Catch calls to exec."),
8542 catch_exec_command_1
,
8545 add_catch_command ("load", _("\
8546 Catch library loads.\n\
8547 With an argument, catch only loads of that library."),
8548 catch_load_command_1
,
8551 add_catch_command ("unload", _("\
8552 Catch library unloads.\n\
8553 With an argument, catch only unloads of that library."),
8554 catch_unload_command_1
,
8557 add_catch_command ("exception", _("\
8558 Catch Ada exceptions, when raised.\n\
8559 With an argument, catch only exceptions with the given name."),
8560 catch_ada_exception_command
,
8563 add_catch_command ("assert", _("\
8564 Catch failed Ada assertions, when raised.\n\
8565 With an argument, catch only exceptions with the given name."),
8566 catch_assert_command
,
8570 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8571 Set a watchpoint for an expression.\n\
8572 A watchpoint stops execution of your program whenever the value of\n\
8573 an expression changes."));
8574 set_cmd_completer (c
, expression_completer
);
8576 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8577 Set a read watchpoint for an expression.\n\
8578 A watchpoint stops execution of your program whenever the value of\n\
8579 an expression is read."));
8580 set_cmd_completer (c
, expression_completer
);
8582 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8583 Set a watchpoint for an expression.\n\
8584 A watchpoint stops execution of your program whenever the value of\n\
8585 an expression is either read or written."));
8586 set_cmd_completer (c
, expression_completer
);
8588 add_info ("watchpoints", breakpoints_info
,
8589 _("Synonym for ``info breakpoints''."));
8592 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8593 respond to changes - contrary to the description. */
8594 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8595 &can_use_hw_watchpoints
, _("\
8596 Set debugger's willingness to use watchpoint hardware."), _("\
8597 Show debugger's willingness to use watchpoint hardware."), _("\
8598 If zero, gdb will not use hardware for new watchpoints, even if\n\
8599 such is available. (However, any hardware watchpoints that were\n\
8600 created before setting this to nonzero, will continue to use watchpoint\n\
8603 show_can_use_hw_watchpoints
,
8604 &setlist
, &showlist
);
8606 can_use_hw_watchpoints
= 1;
8608 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8609 Breakpoint specific settings\n\
8610 Configure various breakpoint-specific variables such as\n\
8611 pending breakpoint behavior"),
8612 &breakpoint_set_cmdlist
, "set breakpoint ",
8613 0/*allow-unknown*/, &setlist
);
8614 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8615 Breakpoint specific settings\n\
8616 Configure various breakpoint-specific variables such as\n\
8617 pending breakpoint behavior"),
8618 &breakpoint_show_cmdlist
, "show breakpoint ",
8619 0/*allow-unknown*/, &showlist
);
8621 add_setshow_auto_boolean_cmd ("pending", no_class
,
8622 &pending_break_support
, _("\
8623 Set debugger's behavior regarding pending breakpoints."), _("\
8624 Show debugger's behavior regarding pending breakpoints."), _("\
8625 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8626 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8627 an error. If auto, an unrecognized breakpoint location results in a\n\
8628 user-query to see if a pending breakpoint should be created."),
8630 show_pending_break_support
,
8631 &breakpoint_set_cmdlist
,
8632 &breakpoint_show_cmdlist
);
8634 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8636 add_setshow_boolean_cmd ("auto-hw", no_class
,
8637 &automatic_hardware_breakpoints
, _("\
8638 Set automatic usage of hardware breakpoints."), _("\
8639 Show automatic usage of hardware breakpoints."), _("\
8640 If set, the debugger will automatically use hardware breakpoints for\n\
8641 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8642 a warning will be emitted for such breakpoints."),
8644 show_automatic_hardware_breakpoints
,
8645 &breakpoint_set_cmdlist
,
8646 &breakpoint_show_cmdlist
);
8648 add_setshow_enum_cmd ("always-inserted", class_support
,
8649 always_inserted_enums
, &always_inserted_mode
, _("\
8650 Set mode for inserting breakpoints."), _("\
8651 Show mode for inserting breakpoints."), _("\
8652 When this mode is off, breakpoints are inserted in inferior when it is\n\
8653 resumed, and removed when execution stops. When this mode is on,\n\
8654 breakpoints are inserted immediately and removed only when the user\n\
8655 deletes the breakpoint. When this mode is auto (which is the default),\n\
8656 the behaviour depends on the non-stop setting (see help set non-stop).\n\
8657 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
8658 behaves as if always-inserted mode is on; if gdb is controlling the\n\
8659 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
8661 &show_always_inserted_mode
,
8662 &breakpoint_set_cmdlist
,
8663 &breakpoint_show_cmdlist
);
8665 automatic_hardware_breakpoints
= 1;