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 stop_command (char *arg
, int from_tty
);
164 static void stopin_command (char *arg
, int from_tty
);
166 static void stopat_command (char *arg
, int from_tty
);
168 static char *ep_parse_optional_if_clause (char **arg
);
170 static char *ep_parse_optional_filename (char **arg
);
172 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
173 char *arg
, int tempflag
, int from_tty
);
175 static void tcatch_command (char *arg
, int from_tty
);
177 static void ep_skip_leading_whitespace (char **s
);
179 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
181 static void free_bp_location (struct bp_location
*loc
);
183 static struct bp_location
*
184 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
);
186 static void update_global_location_list (int);
188 static void update_global_location_list_nothrow (int);
190 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
192 static void insert_breakpoint_locations (void);
195 bpdisp_text (enum bpdisp disp
)
197 /* NOTE: the following values are a part of MI protocol and represent
198 values of 'disp' field returned when inferior stops at a breakpoint. */
199 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
200 return bpdisps
[(int) disp
];
203 /* Prototypes for exported functions. */
204 /* If FALSE, gdb will not use hardware support for watchpoints, even
205 if such is available. */
206 static int can_use_hw_watchpoints
;
209 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
210 struct cmd_list_element
*c
,
213 fprintf_filtered (file
, _("\
214 Debugger's willingness to use watchpoint hardware is %s.\n"),
218 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
219 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
220 for unrecognized breakpoint locations.
221 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
222 static enum auto_boolean pending_break_support
;
224 show_pending_break_support (struct ui_file
*file
, int from_tty
,
225 struct cmd_list_element
*c
,
228 fprintf_filtered (file
, _("\
229 Debugger's behavior regarding pending breakpoints is %s.\n"),
233 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
234 set with "break" but falling in read-only memory.
235 If 0, gdb will warn about such breakpoints, but won't automatically
236 use hardware breakpoints. */
237 static int automatic_hardware_breakpoints
;
239 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
240 struct cmd_list_element
*c
,
243 fprintf_filtered (file
, _("\
244 Automatic usage of hardware breakpoints is %s.\n"),
248 /* If on, gdb will keep breakpoints inserted even as inferior is
249 stopped, and immediately insert any new breakpoints. If off, gdb
250 will insert breakpoints into inferior only when resuming it, and
251 will remove breakpoints upon stop. If auto, GDB will behave as ON
252 if in non-stop mode, and as OFF if all-stop mode.*/
254 static const char always_inserted_auto
[] = "auto";
255 static const char always_inserted_on
[] = "on";
256 static const char always_inserted_off
[] = "off";
257 static const char *always_inserted_enums
[] = {
258 always_inserted_auto
,
263 static const char *always_inserted_mode
= always_inserted_auto
;
265 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
266 struct cmd_list_element
*c
, const char *value
)
268 if (always_inserted_mode
== always_inserted_auto
)
269 fprintf_filtered (file
, _("\
270 Always inserted breakpoint mode is %s (currently %s).\n"),
272 breakpoints_always_inserted_mode () ? "on" : "off");
274 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
278 breakpoints_always_inserted_mode (void)
280 return (always_inserted_mode
== always_inserted_on
281 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
284 void _initialize_breakpoint (void);
286 extern int addressprint
; /* Print machine addresses? */
288 /* Are we executing breakpoint commands? */
289 static int executing_breakpoint_commands
;
291 /* Are overlay event breakpoints enabled? */
292 static int overlay_events_enabled
;
294 /* Walk the following statement or block through all breakpoints.
295 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
298 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
300 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
301 for (B = breakpoint_chain; \
302 B ? (TMP=B->next, 1): 0; \
305 /* Similar iterators for the low-level breakpoints. */
307 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
309 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
310 for (B = bp_location_chain; \
311 B ? (TMP=B->global_next, 1): 0; \
314 /* Chains of all breakpoints defined. */
316 struct breakpoint
*breakpoint_chain
;
318 struct bp_location
*bp_location_chain
;
320 /* The locations that no longer correspond to any breakpoint,
321 unlinked from bp_location_chain, but for which a hit
322 may still be reported by a target. */
323 VEC(bp_location_p
) *moribund_locations
= NULL
;
325 /* Number of last breakpoint made. */
327 int breakpoint_count
;
329 /* This function returns a pointer to the string representation of the
330 pathname of the dynamically-linked library that has just been
333 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
334 or undefined results are guaranteed.
336 This string's contents are only valid immediately after the
337 inferior has stopped in the dynamic linker hook, and becomes
338 invalid as soon as the inferior is continued. Clients should make
339 a copy of this string if they wish to continue the inferior and
340 then access the string. */
342 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
343 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
346 /* This function returns a pointer to the string representation of the
347 pathname of the dynamically-linked library that has just been
350 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
351 TRUE, or undefined results are guaranteed.
353 This string's contents are only valid immediately after the
354 inferior has stopped in the dynamic linker hook, and becomes
355 invalid as soon as the inferior is continued. Clients should make
356 a copy of this string if they wish to continue the inferior and
357 then access the string. */
359 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
360 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
363 /* This function is called by the "catch load" command. It allows the
364 debugger to be notified by the dynamic linker when a specified
365 library file (or any library file, if filename is NULL) is loaded. */
367 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
368 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
369 error (_("catch of library loads not yet implemented on this platform"))
372 /* This function is called by the "catch unload" command. It allows
373 the debugger to be notified by the dynamic linker when a specified
374 library file (or any library file, if filename is NULL) is
377 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
378 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
379 error (_("catch of library unloads not yet implemented on this platform"))
382 /* Return whether a breakpoint is an active enabled breakpoint. */
384 breakpoint_enabled (struct breakpoint
*b
)
386 return (b
->enable_state
== bp_enabled
);
389 /* Set breakpoint count to NUM. */
392 set_breakpoint_count (int num
)
394 breakpoint_count
= num
;
395 set_internalvar (lookup_internalvar ("bpnum"),
396 value_from_longest (builtin_type_int32
, (LONGEST
) num
));
399 /* Used in run_command to zero the hit count when a new run starts. */
402 clear_breakpoint_hit_counts (void)
404 struct breakpoint
*b
;
410 /* Default address, symtab and line to put a breakpoint at
411 for "break" command with no arg.
412 if default_breakpoint_valid is zero, the other three are
413 not valid, and "break" with no arg is an error.
415 This set by print_stack_frame, which calls set_default_breakpoint. */
417 int default_breakpoint_valid
;
418 CORE_ADDR default_breakpoint_address
;
419 struct symtab
*default_breakpoint_symtab
;
420 int default_breakpoint_line
;
422 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
423 Advance *PP after the string and any trailing whitespace.
425 Currently the string can either be a number or "$" followed by the name
426 of a convenience variable. Making it an expression wouldn't work well
427 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
429 If the string is a NULL pointer, that denotes the last breakpoint.
431 TRAILER is a character which can be found after the number; most
432 commonly this is `-'. If you don't want a trailer, use \0. */
434 get_number_trailer (char **pp
, int trailer
)
436 int retval
= 0; /* default */
440 /* Empty line means refer to the last breakpoint. */
441 return breakpoint_count
;
444 /* Make a copy of the name, so we can null-terminate it
445 to pass to lookup_internalvar(). */
450 while (isalnum (*p
) || *p
== '_')
452 varname
= (char *) alloca (p
- start
+ 1);
453 strncpy (varname
, start
, p
- start
);
454 varname
[p
- start
] = '\0';
455 val
= value_of_internalvar (lookup_internalvar (varname
));
456 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
457 retval
= (int) value_as_long (val
);
460 printf_filtered (_("Convenience variable must have integer value.\n"));
468 while (*p
>= '0' && *p
<= '9')
471 /* There is no number here. (e.g. "cond a == b"). */
473 /* Skip non-numeric token */
474 while (*p
&& !isspace((int) *p
))
476 /* Return zero, which caller must interpret as error. */
482 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
484 /* Trailing junk: return 0 and let caller print error msg. */
485 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
496 /* Like get_number_trailer, but don't allow a trailer. */
498 get_number (char **pp
)
500 return get_number_trailer (pp
, '\0');
503 /* Parse a number or a range.
504 * A number will be of the form handled by get_number.
505 * A range will be of the form <number1> - <number2>, and
506 * will represent all the integers between number1 and number2,
509 * While processing a range, this fuction is called iteratively;
510 * At each call it will return the next value in the range.
512 * At the beginning of parsing a range, the char pointer PP will
513 * be advanced past <number1> and left pointing at the '-' token.
514 * Subsequent calls will not advance the pointer until the range
515 * is completed. The call that completes the range will advance
516 * pointer PP past <number2>.
520 get_number_or_range (char **pp
)
522 static int last_retval
, end_value
;
523 static char *end_ptr
;
524 static int in_range
= 0;
528 /* Default case: pp is pointing either to a solo number,
529 or to the first number of a range. */
530 last_retval
= get_number_trailer (pp
, '-');
535 /* This is the start of a range (<number1> - <number2>).
536 Skip the '-', parse and remember the second number,
537 and also remember the end of the final token. */
541 while (isspace ((int) *end_ptr
))
542 end_ptr
++; /* skip white space */
543 end_value
= get_number (temp
);
544 if (end_value
< last_retval
)
546 error (_("inverted range"));
548 else if (end_value
== last_retval
)
550 /* degenerate range (number1 == number2). Advance the
551 token pointer so that the range will be treated as a
560 error (_("negative value"));
563 /* pp points to the '-' that betokens a range. All
564 number-parsing has already been done. Return the next
565 integer value (one greater than the saved previous value).
566 Do not advance the token pointer 'pp' until the end of range
569 if (++last_retval
== end_value
)
571 /* End of range reached; advance token pointer. */
581 /* condition N EXP -- set break condition of breakpoint N to EXP. */
584 condition_command (char *arg
, int from_tty
)
586 struct breakpoint
*b
;
591 error_no_arg (_("breakpoint number"));
594 bnum
= get_number (&p
);
596 error (_("Bad breakpoint argument: '%s'"), arg
);
599 if (b
->number
== bnum
)
601 struct bp_location
*loc
= b
->loc
;
602 for (; loc
; loc
= loc
->next
)
610 if (b
->cond_string
!= NULL
)
611 xfree (b
->cond_string
);
615 b
->cond_string
= NULL
;
617 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
622 /* I don't know if it matters whether this is the string the user
623 typed in or the decompiled expression. */
624 b
->cond_string
= savestring (arg
, strlen (arg
));
625 b
->condition_not_parsed
= 0;
626 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
630 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
632 error (_("Junk at end of expression"));
635 breakpoints_changed ();
636 observer_notify_breakpoint_modified (b
->number
);
640 error (_("No breakpoint number %d."), bnum
);
644 commands_command (char *arg
, int from_tty
)
646 struct breakpoint
*b
;
649 struct command_line
*l
;
651 /* If we allowed this, we would have problems with when to
652 free the storage, if we change the commands currently
655 if (executing_breakpoint_commands
)
656 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
659 bnum
= get_number (&p
);
662 error (_("Unexpected extra arguments following breakpoint number."));
665 if (b
->number
== bnum
)
667 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
669 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
670 l
= read_command_lines (tmpbuf
, from_tty
, 1);
671 do_cleanups (cleanups
);
672 free_command_lines (&b
->commands
);
674 breakpoints_changed ();
675 observer_notify_breakpoint_modified (b
->number
);
678 error (_("No breakpoint number %d."), bnum
);
681 /* Like commands_command, but instead of reading the commands from
682 input stream, takes them from an already parsed command structure.
684 This is used by cli-script.c to DTRT with breakpoint commands
685 that are part of if and while bodies. */
686 enum command_control_type
687 commands_from_control_command (char *arg
, struct command_line
*cmd
)
689 struct breakpoint
*b
;
693 /* If we allowed this, we would have problems with when to
694 free the storage, if we change the commands currently
697 if (executing_breakpoint_commands
)
698 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
700 /* An empty string for the breakpoint number means the last
701 breakpoint, but get_number expects a NULL pointer. */
706 bnum
= get_number (&p
);
709 error (_("Unexpected extra arguments following breakpoint number."));
712 if (b
->number
== bnum
)
714 free_command_lines (&b
->commands
);
715 if (cmd
->body_count
!= 1)
716 error (_("Invalid \"commands\" block structure."));
717 /* We need to copy the commands because if/while will free the
718 list after it finishes execution. */
719 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
720 breakpoints_changed ();
721 observer_notify_breakpoint_modified (b
->number
);
722 return simple_control
;
724 error (_("No breakpoint number %d."), bnum
);
727 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
728 by replacing any memory breakpoints with their shadowed contents. */
731 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
733 struct bp_location
*b
;
734 CORE_ADDR bp_addr
= 0;
740 if (b
->owner
->type
== bp_none
)
741 warning (_("reading through apparently deleted breakpoint #%d?"),
744 if (b
->loc_type
!= bp_loc_software_breakpoint
)
748 /* Addresses and length of the part of the breakpoint that
750 bp_addr
= b
->target_info
.placed_address
;
751 bp_size
= b
->target_info
.shadow_len
;
753 /* bp isn't valid, or doesn't shadow memory. */
756 if (bp_addr
+ bp_size
<= memaddr
)
757 /* The breakpoint is entirely before the chunk of memory we
761 if (bp_addr
>= memaddr
+ len
)
762 /* The breakpoint is entirely after the chunk of memory we are
766 /* Offset within shadow_contents. */
767 if (bp_addr
< memaddr
)
769 /* Only copy the second part of the breakpoint. */
770 bp_size
-= memaddr
- bp_addr
;
771 bptoffset
= memaddr
- bp_addr
;
775 if (bp_addr
+ bp_size
> memaddr
+ len
)
777 /* Only copy the first part of the breakpoint. */
778 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
781 memcpy (buf
+ bp_addr
- memaddr
,
782 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
787 /* A wrapper function for inserting catchpoints. */
789 insert_catchpoint (struct ui_out
*uo
, void *args
)
791 struct breakpoint
*b
= (struct breakpoint
*) args
;
797 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
801 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
804 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
810 is_hardware_watchpoint (struct breakpoint
*bpt
)
812 return (bpt
->type
== bp_hardware_watchpoint
813 || bpt
->type
== bp_read_watchpoint
814 || bpt
->type
== bp_access_watchpoint
);
817 /* Find the current value of a watchpoint on EXP. Return the value in
818 *VALP and *RESULTP and the chain of intermediate and final values
819 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
822 If an error occurs while evaluating the expression, *RESULTP will
823 be set to NULL. *RESULTP may be a lazy value, if the result could
824 not be read from memory. It is used to determine whether a value
825 is user-specified (we should watch the whole value) or intermediate
826 (we should watch only the bit used to locate the final value).
828 If the final value, or any intermediate value, could not be read
829 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
830 set to any referenced values. *VALP will never be a lazy value.
831 This is the value which we store in struct breakpoint.
833 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
834 value chain. The caller must free the values individually. If
835 VAL_CHAIN is NULL, all generated values will be left on the value
839 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
840 struct value
**resultp
, struct value
**val_chain
)
842 struct value
*mark
, *new_mark
, *result
;
850 /* Evaluate the expression. */
851 mark
= value_mark ();
853 gdb_evaluate_expression (exp
, &result
);
854 new_mark
= value_mark ();
855 if (mark
== new_mark
)
860 /* Make sure it's not lazy, so that after the target stops again we
861 have a non-lazy previous value to compare with. */
863 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
868 /* Return the chain of intermediate values. We use this to
869 decide which addresses to watch. */
870 *val_chain
= new_mark
;
871 value_release_to_mark (mark
);
875 /* Assuming that B is a hardware watchpoint:
876 - Reparse watchpoint expression, is REPARSE is non-zero
877 - Evaluate expression and store the result in B->val
878 - Update the list of values that must be watched in B->loc.
880 If the watchpoint is disabled, do nothing. If this is
881 local watchpoint that is out of scope, delete it. */
883 update_watchpoint (struct breakpoint
*b
, int reparse
)
885 int within_current_scope
;
886 struct frame_id saved_frame_id
;
887 struct bp_location
*loc
;
890 /* We don't free locations. They are stored in
891 bp_location_chain and update_global_locations will
892 eventually delete them and remove breakpoints if
896 if (b
->disposition
== disp_del_at_next_stop
)
899 /* Save the current frame's ID so we can restore it after
900 evaluating the watchpoint expression on its own frame. */
901 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
902 took a frame parameter, so that we didn't have to change the
904 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
906 /* Determine if the watchpoint is within scope. */
907 if (b
->exp_valid_block
== NULL
)
908 within_current_scope
= 1;
911 struct frame_info
*fi
;
912 fi
= frame_find_by_id (b
->watchpoint_frame
);
913 within_current_scope
= (fi
!= NULL
);
914 if (within_current_scope
)
918 if (within_current_scope
&& reparse
)
927 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
928 /* If the meaning of expression itself changed, the old value is
929 no longer relevant. We don't want to report a watchpoint hit
930 to the user when the old value and the new value may actually
931 be completely different objects. */
937 /* If we failed to parse the expression, for example because
938 it refers to a global variable in a not-yet-loaded shared library,
939 don't try to insert watchpoint. We don't automatically delete
940 such watchpoint, though, since failure to parse expression
941 is different from out-of-scope watchpoint. */
942 if (within_current_scope
&& b
->exp
)
944 struct value
*val_chain
, *v
, *result
, *next
;
946 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
948 /* Avoid setting b->val if it's already set. The meaning of
949 b->val is 'the last value' user saw, and we should update
950 it only if we reported that last value to user. As it
951 happens, the code that reports it updates b->val directly. */
958 /* Look at each value on the value chain. */
959 for (v
= val_chain
; v
; v
= next
)
961 /* If it's a memory location, and GDB actually needed
962 its contents to evaluate the expression, then we
963 must watch it. If the first value returned is
964 still lazy, that means an error occurred reading it;
965 watch it anyway in case it becomes readable. */
966 if (VALUE_LVAL (v
) == lval_memory
967 && (v
== val_chain
|| ! value_lazy (v
)))
969 struct type
*vtype
= check_typedef (value_type (v
));
971 /* We only watch structs and arrays if user asked
972 for it explicitly, never if they just happen to
973 appear in the middle of some value chain. */
975 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
976 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
980 struct bp_location
*loc
, **tmp
;
982 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
983 len
= TYPE_LENGTH (value_type (v
));
985 if (b
->type
== bp_read_watchpoint
)
987 else if (b
->type
== bp_access_watchpoint
)
990 loc
= allocate_bp_location (b
, bp_hardware_watchpoint
);
991 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
996 loc
->watchpoint_type
= type
;
1000 next
= value_next (v
);
1005 /* We just regenerated the list of breakpoint locations.
1006 The new location does not have its condition field set to anything
1007 and therefore, we must always reparse the cond_string, independently
1008 of the value of the reparse flag. */
1009 if (b
->cond_string
!= NULL
)
1011 char *s
= b
->cond_string
;
1012 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1015 else if (!within_current_scope
)
1017 printf_filtered (_("\
1018 Hardware watchpoint %d deleted because the program has left the block \n\
1019 in which its expression is valid.\n"),
1021 if (b
->related_breakpoint
)
1022 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1023 b
->disposition
= disp_del_at_next_stop
;
1026 /* Restore the selected frame. */
1027 select_frame (frame_find_by_id (saved_frame_id
));
1031 /* Returns 1 iff breakpoint location should be
1032 inserted in the inferior. */
1034 should_be_inserted (struct bp_location
*bpt
)
1036 if (!breakpoint_enabled (bpt
->owner
))
1039 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1042 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1048 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1049 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1050 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1052 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1053 method for each breakpoint or catchpoint type. */
1055 insert_bp_location (struct bp_location
*bpt
,
1056 struct ui_file
*tmp_error_stream
,
1057 int *disabled_breaks
, int *process_warning
,
1058 int *hw_breakpoint_error
)
1062 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1065 /* Initialize the target-specific information. */
1066 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1067 bpt
->target_info
.placed_address
= bpt
->address
;
1069 if (bpt
->loc_type
== bp_loc_software_breakpoint
1070 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1072 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1074 /* If the explicitly specified breakpoint type
1075 is not hardware breakpoint, check the memory map to see
1076 if the breakpoint address is in read only memory or not.
1077 Two important cases are:
1078 - location type is not hardware breakpoint, memory
1079 is readonly. We change the type of the location to
1080 hardware breakpoint.
1081 - location type is hardware breakpoint, memory is read-write.
1082 This means we've previously made the location hardware one, but
1083 then the memory map changed, so we undo.
1085 When breakpoints are removed, remove_breakpoints will
1086 use location types we've just set here, the only possible
1087 problem is that memory map has changed during running program,
1088 but it's not going to work anyway with current gdb. */
1089 struct mem_region
*mr
1090 = lookup_mem_region (bpt
->target_info
.placed_address
);
1094 if (automatic_hardware_breakpoints
)
1097 enum bp_loc_type new_type
;
1099 if (mr
->attrib
.mode
!= MEM_RW
)
1100 new_type
= bp_loc_hardware_breakpoint
;
1102 new_type
= bp_loc_software_breakpoint
;
1104 if (new_type
!= bpt
->loc_type
)
1106 static int said
= 0;
1107 bpt
->loc_type
= new_type
;
1110 fprintf_filtered (gdb_stdout
, _("\
1111 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1116 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1117 && mr
->attrib
.mode
!= MEM_RW
)
1118 warning (_("cannot set software breakpoint at readonly address %s"),
1119 paddr (bpt
->address
));
1123 /* First check to see if we have to handle an overlay. */
1124 if (overlay_debugging
== ovly_off
1125 || bpt
->section
== NULL
1126 || !(section_is_overlay (bpt
->section
)))
1128 /* No overlay handling: just set the breakpoint. */
1130 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1131 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1133 val
= target_insert_breakpoint (&bpt
->target_info
);
1137 /* This breakpoint is in an overlay section.
1138 Shall we set a breakpoint at the LMA? */
1139 if (!overlay_events_enabled
)
1141 /* Yes -- overlay event support is not active,
1142 so we must try to set a breakpoint at the LMA.
1143 This will not work for a hardware breakpoint. */
1144 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1145 warning (_("hardware breakpoint %d not supported in overlay!"),
1146 bpt
->owner
->number
);
1149 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1151 /* Set a software (trap) breakpoint at the LMA. */
1152 bpt
->overlay_target_info
= bpt
->target_info
;
1153 bpt
->overlay_target_info
.placed_address
= addr
;
1154 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1156 fprintf_unfiltered (tmp_error_stream
,
1157 "Overlay breakpoint %d failed: in ROM?",
1158 bpt
->owner
->number
);
1161 /* Shall we set a breakpoint at the VMA? */
1162 if (section_is_mapped (bpt
->section
))
1164 /* Yes. This overlay section is mapped into memory. */
1165 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1166 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1168 val
= target_insert_breakpoint (&bpt
->target_info
);
1172 /* No. This breakpoint will not be inserted.
1173 No error, but do not mark the bp as 'inserted'. */
1180 /* Can't set the breakpoint. */
1181 if (solib_address (bpt
->address
))
1183 /* See also: disable_breakpoints_in_shlibs. */
1185 bpt
->shlib_disabled
= 1;
1186 if (!*disabled_breaks
)
1188 fprintf_unfiltered (tmp_error_stream
,
1189 "Cannot insert breakpoint %d.\n",
1190 bpt
->owner
->number
);
1191 fprintf_unfiltered (tmp_error_stream
,
1192 "Temporarily disabling shared library breakpoints:\n");
1194 *disabled_breaks
= 1;
1195 fprintf_unfiltered (tmp_error_stream
,
1196 "breakpoint #%d\n", bpt
->owner
->number
);
1200 #ifdef ONE_PROCESS_WRITETEXT
1201 *process_warning
= 1;
1203 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1205 *hw_breakpoint_error
= 1;
1206 fprintf_unfiltered (tmp_error_stream
,
1207 "Cannot insert hardware breakpoint %d.\n",
1208 bpt
->owner
->number
);
1212 fprintf_unfiltered (tmp_error_stream
,
1213 "Cannot insert breakpoint %d.\n",
1214 bpt
->owner
->number
);
1215 fprintf_filtered (tmp_error_stream
,
1216 "Error accessing memory address ");
1217 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1218 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1219 safe_strerror (val
));
1230 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1231 /* NOTE drow/2003-09-08: This state only exists for removing
1232 watchpoints. It's not clear that it's necessary... */
1233 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1235 val
= target_insert_watchpoint (bpt
->address
,
1237 bpt
->watchpoint_type
);
1238 bpt
->inserted
= (val
!= -1);
1241 else if (bpt
->owner
->type
== bp_catchpoint
1242 || bpt
->owner
->type
== bp_catch_exec
)
1244 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1245 bpt
->owner
, RETURN_MASK_ERROR
);
1246 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1247 bpt
->owner
->number
);
1249 bpt
->owner
->enable_state
= bp_disabled
;
1253 /* We've already printed an error message if there was a problem
1254 inserting this catchpoint, and we've disabled the catchpoint,
1255 so just return success. */
1262 /* Make sure all breakpoints are inserted in inferior.
1263 Throws exception on any error.
1264 A breakpoint that is already inserted won't be inserted
1265 again, so calling this function twice is safe. */
1267 insert_breakpoints (void)
1269 struct breakpoint
*bpt
;
1271 ALL_BREAKPOINTS (bpt
)
1272 if (is_hardware_watchpoint (bpt
))
1273 update_watchpoint (bpt
, 0 /* don't reparse. */);
1275 update_global_location_list (1);
1277 if (!breakpoints_always_inserted_mode () && target_has_execution
)
1278 /* update_global_location_list does not insert breakpoints
1279 when always_inserted_mode is not enabled. Explicitly
1281 insert_breakpoint_locations ();
1284 /* insert_breakpoints is used when starting or continuing the program.
1285 remove_breakpoints is used when the program stops.
1286 Both return zero if successful,
1287 or an `errno' value if could not write the inferior. */
1290 insert_breakpoint_locations (void)
1292 struct breakpoint
*bpt
;
1293 struct bp_location
*b
, *temp
;
1296 int disabled_breaks
= 0;
1297 int hw_breakpoint_error
= 0;
1298 int process_warning
= 0;
1300 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1301 make_cleanup_ui_file_delete (tmp_error_stream
);
1303 /* Explicitly mark the warning -- this will only be printed if
1304 there was an error. */
1305 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1307 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1309 if (!should_be_inserted (b
) || b
->inserted
)
1312 /* There is no point inserting thread-specific breakpoints if the
1313 thread no longer exists. */
1314 if (b
->owner
->thread
!= -1
1315 && !valid_thread_id (b
->owner
->thread
))
1318 val
= insert_bp_location (b
, tmp_error_stream
,
1319 &disabled_breaks
, &process_warning
,
1320 &hw_breakpoint_error
);
1325 /* If we failed to insert all locations of a watchpoint,
1326 remove them, as half-inserted watchpoint is of limited use. */
1327 ALL_BREAKPOINTS (bpt
)
1329 int some_failed
= 0;
1330 struct bp_location
*loc
;
1332 if (!is_hardware_watchpoint (bpt
))
1335 if (!breakpoint_enabled (bpt
))
1338 if (bpt
->disposition
== disp_del_at_next_stop
)
1341 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1349 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1351 remove_breakpoint (loc
, mark_uninserted
);
1353 hw_breakpoint_error
= 1;
1354 fprintf_unfiltered (tmp_error_stream
,
1355 "Could not insert hardware watchpoint %d.\n",
1363 /* If a hardware breakpoint or watchpoint was inserted, add a
1364 message about possibly exhausted resources. */
1365 if (hw_breakpoint_error
)
1367 fprintf_unfiltered (tmp_error_stream
,
1368 "Could not insert hardware breakpoints:\n\
1369 You may have requested too many hardware breakpoints/watchpoints.\n");
1371 #ifdef ONE_PROCESS_WRITETEXT
1372 if (process_warning
)
1373 fprintf_unfiltered (tmp_error_stream
,
1374 "The same program may be running in another process.");
1376 target_terminal_ours_for_output ();
1377 error_stream (tmp_error_stream
);
1382 remove_breakpoints (void)
1384 struct bp_location
*b
;
1387 ALL_BP_LOCATIONS (b
)
1391 val
= remove_breakpoint (b
, mark_uninserted
);
1400 remove_hw_watchpoints (void)
1402 struct bp_location
*b
;
1405 ALL_BP_LOCATIONS (b
)
1407 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1409 val
= remove_breakpoint (b
, mark_uninserted
);
1418 reattach_breakpoints (int pid
)
1420 struct bp_location
*b
;
1422 struct cleanup
*old_chain
= save_inferior_ptid ();
1423 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1424 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1426 make_cleanup_ui_file_delete (tmp_error_stream
);
1428 inferior_ptid
= pid_to_ptid (pid
);
1429 ALL_BP_LOCATIONS (b
)
1434 val
= insert_bp_location (b
, tmp_error_stream
,
1435 &dummy1
, &dummy2
, &dummy3
);
1438 do_cleanups (old_chain
);
1443 do_cleanups (old_chain
);
1448 update_breakpoints_after_exec (void)
1450 struct breakpoint
*b
;
1451 struct breakpoint
*temp
;
1452 struct bp_location
*bploc
;
1454 /* We're about to delete breakpoints from GDB's lists. If the
1455 INSERTED flag is true, GDB will try to lift the breakpoints by
1456 writing the breakpoints' "shadow contents" back into memory. The
1457 "shadow contents" are NOT valid after an exec, so GDB should not
1458 do that. Instead, the target is responsible from marking
1459 breakpoints out as soon as it detects an exec. We don't do that
1460 here instead, because there may be other attempts to delete
1461 breakpoints after detecting an exec and before reaching here. */
1462 ALL_BP_LOCATIONS (bploc
)
1463 gdb_assert (!bploc
->inserted
);
1465 ALL_BREAKPOINTS_SAFE (b
, temp
)
1467 /* Solib breakpoints must be explicitly reset after an exec(). */
1468 if (b
->type
== bp_shlib_event
)
1470 delete_breakpoint (b
);
1474 /* Thread event breakpoints must be set anew after an exec(),
1475 as must overlay event breakpoints. */
1476 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1478 delete_breakpoint (b
);
1482 /* Step-resume breakpoints are meaningless after an exec(). */
1483 if (b
->type
== bp_step_resume
)
1485 delete_breakpoint (b
);
1489 /* Longjmp and longjmp-resume breakpoints are also meaningless
1491 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1493 delete_breakpoint (b
);
1497 if (b
->type
== bp_catchpoint
)
1499 /* For now, none of the bp_catchpoint breakpoints need to
1500 do anything at this point. In the future, if some of
1501 the catchpoints need to something, we will need to add
1502 a new method, and call this method from here. */
1506 /* Don't delete an exec catchpoint, because else the inferior
1507 won't stop when it ought! */
1508 if (b
->type
== bp_catch_exec
)
1513 /* bp_finish is a special case. The only way we ought to be able
1514 to see one of these when an exec() has happened, is if the user
1515 caught a vfork, and then said "finish". Ordinarily a finish just
1516 carries them to the call-site of the current callee, by setting
1517 a temporary bp there and resuming. But in this case, the finish
1518 will carry them entirely through the vfork & exec.
1520 We don't want to allow a bp_finish to remain inserted now. But
1521 we can't safely delete it, 'cause finish_command has a handle to
1522 the bp on a bpstat, and will later want to delete it. There's a
1523 chance (and I've seen it happen) that if we delete the bp_finish
1524 here, that its storage will get reused by the time finish_command
1525 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1526 We really must allow finish_command to delete a bp_finish.
1528 In the absense of a general solution for the "how do we know
1529 it's safe to delete something others may have handles to?"
1530 problem, what we'll do here is just uninsert the bp_finish, and
1531 let finish_command delete it.
1533 (We know the bp_finish is "doomed" in the sense that it's
1534 momentary, and will be deleted as soon as finish_command sees
1535 the inferior stopped. So it doesn't matter that the bp's
1536 address is probably bogus in the new a.out, unlike e.g., the
1537 solib breakpoints.) */
1539 if (b
->type
== bp_finish
)
1544 /* Without a symbolic address, we have little hope of the
1545 pre-exec() address meaning the same thing in the post-exec()
1547 if (b
->addr_string
== NULL
)
1549 delete_breakpoint (b
);
1553 /* FIXME what about longjmp breakpoints? Re-create them here? */
1554 create_overlay_event_breakpoint ("_ovly_debug_event");
1558 detach_breakpoints (int pid
)
1560 struct bp_location
*b
;
1562 struct cleanup
*old_chain
= save_inferior_ptid ();
1564 if (pid
== PIDGET (inferior_ptid
))
1565 error (_("Cannot detach breakpoints of inferior_ptid"));
1567 /* Set inferior_ptid; remove_breakpoint uses this global. */
1568 inferior_ptid
= pid_to_ptid (pid
);
1569 ALL_BP_LOCATIONS (b
)
1573 val
= remove_breakpoint (b
, mark_inserted
);
1576 do_cleanups (old_chain
);
1581 do_cleanups (old_chain
);
1586 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1590 if (b
->owner
->enable_state
== bp_permanent
)
1591 /* Permanent breakpoints cannot be inserted or removed. */
1594 /* The type of none suggests that owner is actually deleted.
1595 This should not ever happen. */
1596 gdb_assert (b
->owner
->type
!= bp_none
);
1598 if (b
->loc_type
== bp_loc_software_breakpoint
1599 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1601 /* "Normal" instruction breakpoint: either the standard
1602 trap-instruction bp (bp_breakpoint), or a
1603 bp_hardware_breakpoint. */
1605 /* First check to see if we have to handle an overlay. */
1606 if (overlay_debugging
== ovly_off
1607 || b
->section
== NULL
1608 || !(section_is_overlay (b
->section
)))
1610 /* No overlay handling: just remove the breakpoint. */
1612 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1613 val
= target_remove_hw_breakpoint (&b
->target_info
);
1615 val
= target_remove_breakpoint (&b
->target_info
);
1619 /* This breakpoint is in an overlay section.
1620 Did we set a breakpoint at the LMA? */
1621 if (!overlay_events_enabled
)
1623 /* Yes -- overlay event support is not active, so we
1624 should have set a breakpoint at the LMA. Remove it.
1626 /* Ignore any failures: if the LMA is in ROM, we will
1627 have already warned when we failed to insert it. */
1628 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1629 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1631 target_remove_breakpoint (&b
->overlay_target_info
);
1633 /* Did we set a breakpoint at the VMA?
1634 If so, we will have marked the breakpoint 'inserted'. */
1637 /* Yes -- remove it. Previously we did not bother to
1638 remove the breakpoint if the section had been
1639 unmapped, but let's not rely on that being safe. We
1640 don't know what the overlay manager might do. */
1641 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1642 val
= target_remove_hw_breakpoint (&b
->target_info
);
1644 /* However, we should remove *software* breakpoints only
1645 if the section is still mapped, or else we overwrite
1646 wrong code with the saved shadow contents. */
1647 else if (section_is_mapped (b
->section
))
1648 val
= target_remove_breakpoint (&b
->target_info
);
1654 /* No -- not inserted, so no need to remove. No error. */
1659 /* In some cases, we might not be able to remove a breakpoint
1660 in a shared library that has already been removed, but we
1661 have not yet processed the shlib unload event. */
1662 if (val
&& solib_address (b
->address
))
1667 b
->inserted
= (is
== mark_inserted
);
1669 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1674 b
->inserted
= (is
== mark_inserted
);
1675 val
= target_remove_watchpoint (b
->address
, b
->length
,
1676 b
->watchpoint_type
);
1678 /* Failure to remove any of the hardware watchpoints comes here. */
1679 if ((is
== mark_uninserted
) && (b
->inserted
))
1680 warning (_("Could not remove hardware watchpoint %d."),
1683 else if (b
->owner
->type
== bp_catchpoint
1684 && breakpoint_enabled (b
->owner
)
1687 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
1689 val
= b
->owner
->ops
->remove (b
->owner
);
1692 b
->inserted
= (is
== mark_inserted
);
1694 else if (b
->owner
->type
== bp_catch_exec
1695 && breakpoint_enabled (b
->owner
)
1699 switch (b
->owner
->type
)
1702 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1705 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1710 b
->inserted
= (is
== mark_inserted
);
1716 /* Clear the "inserted" flag in all breakpoints. */
1719 mark_breakpoints_out (void)
1721 struct bp_location
*bpt
;
1723 ALL_BP_LOCATIONS (bpt
)
1727 /* Clear the "inserted" flag in all breakpoints and delete any
1728 breakpoints which should go away between runs of the program.
1730 Plus other such housekeeping that has to be done for breakpoints
1733 Note: this function gets called at the end of a run (by
1734 generic_mourn_inferior) and when a run begins (by
1735 init_wait_for_inferior). */
1740 breakpoint_init_inferior (enum inf_context context
)
1742 struct breakpoint
*b
, *temp
;
1743 struct bp_location
*bpt
;
1746 ALL_BP_LOCATIONS (bpt
)
1747 if (bpt
->owner
->enable_state
!= bp_permanent
)
1750 ALL_BREAKPOINTS_SAFE (b
, temp
)
1755 case bp_watchpoint_scope
:
1757 /* If the call dummy breakpoint is at the entry point it will
1758 cause problems when the inferior is rerun, so we better
1761 Also get rid of scope breakpoints. */
1762 delete_breakpoint (b
);
1766 case bp_hardware_watchpoint
:
1767 case bp_read_watchpoint
:
1768 case bp_access_watchpoint
:
1770 /* Likewise for watchpoints on local expressions. */
1771 if (b
->exp_valid_block
!= NULL
)
1772 delete_breakpoint (b
);
1773 else if (context
== inf_starting
)
1775 /* Reset val field to force reread of starting value
1776 in insert_breakpoints. */
1778 value_free (b
->val
);
1788 /* Get rid of the moribund locations. */
1789 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
1790 free_bp_location (bpt
);
1791 VEC_free (bp_location_p
, moribund_locations
);
1794 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1795 exists at PC. It returns ordinary_breakpoint_here if it's an
1796 ordinary breakpoint, or permanent_breakpoint_here if it's a
1797 permanent breakpoint.
1798 - When continuing from a location with an ordinary breakpoint, we
1799 actually single step once before calling insert_breakpoints.
1800 - When continuing from a localion with a permanent breakpoint, we
1801 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1802 the target, to advance the PC past the breakpoint. */
1804 enum breakpoint_here
1805 breakpoint_here_p (CORE_ADDR pc
)
1807 const struct bp_location
*bpt
;
1808 int any_breakpoint_here
= 0;
1810 ALL_BP_LOCATIONS (bpt
)
1812 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1813 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1816 if ((breakpoint_enabled (bpt
->owner
)
1817 || bpt
->owner
->enable_state
== bp_permanent
)
1818 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1820 if (overlay_debugging
1821 && section_is_overlay (bpt
->section
)
1822 && !section_is_mapped (bpt
->section
))
1823 continue; /* unmapped overlay -- can't be a match */
1824 else if (bpt
->owner
->enable_state
== bp_permanent
)
1825 return permanent_breakpoint_here
;
1827 any_breakpoint_here
= 1;
1831 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1834 /* Return true if there's a moribund breakpoint at PC. */
1837 moribund_breakpoint_here_p (CORE_ADDR pc
)
1839 struct bp_location
*loc
;
1842 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
1843 if (loc
->address
== pc
)
1849 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1850 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1851 This does not check for single-step breakpoints, which are
1852 inserted and removed using direct target manipulation. */
1855 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1857 const struct bp_location
*bpt
;
1859 ALL_BP_LOCATIONS (bpt
)
1861 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1862 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1866 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1868 if (overlay_debugging
1869 && section_is_overlay (bpt
->section
)
1870 && !section_is_mapped (bpt
->section
))
1871 continue; /* unmapped overlay -- can't be a match */
1879 /* Returns non-zero iff there's either regular breakpoint
1880 or a single step breakpoint inserted at PC. */
1883 breakpoint_inserted_here_p (CORE_ADDR pc
)
1885 if (regular_breakpoint_inserted_here_p (pc
))
1888 if (single_step_breakpoint_inserted_here_p (pc
))
1894 /* This function returns non-zero iff there is a software breakpoint
1898 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1900 const struct bp_location
*bpt
;
1901 int any_breakpoint_here
= 0;
1903 ALL_BP_LOCATIONS (bpt
)
1905 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1909 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1911 if (overlay_debugging
1912 && section_is_overlay (bpt
->section
)
1913 && !section_is_mapped (bpt
->section
))
1914 continue; /* unmapped overlay -- can't be a match */
1920 /* Also check for software single-step breakpoints. */
1921 if (single_step_breakpoint_inserted_here_p (pc
))
1927 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1928 PC is valid for process/thread PTID. */
1931 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1933 const struct bp_location
*bpt
;
1936 thread
= pid_to_thread_id (ptid
);
1938 ALL_BP_LOCATIONS (bpt
)
1940 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1941 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1944 if ((breakpoint_enabled (bpt
->owner
)
1945 || bpt
->owner
->enable_state
== bp_permanent
)
1946 && bpt
->address
== pc
1947 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1949 if (overlay_debugging
1950 && section_is_overlay (bpt
->section
)
1951 && !section_is_mapped (bpt
->section
))
1952 continue; /* unmapped overlay -- can't be a match */
1962 /* bpstat stuff. External routines' interfaces are documented
1966 ep_is_catchpoint (struct breakpoint
*ep
)
1968 return (ep
->type
== bp_catchpoint
)
1969 || (ep
->type
== bp_catch_load
)
1970 || (ep
->type
== bp_catch_unload
)
1971 || (ep
->type
== bp_catch_exec
);
1973 /* ??rehrauer: Add more kinds here, as are implemented... */
1977 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1980 (ep
->type
== bp_catch_load
)
1981 || (ep
->type
== bp_catch_unload
);
1985 bpstat_free (bpstat bs
)
1987 if (bs
->old_val
!= NULL
)
1988 value_free (bs
->old_val
);
1989 free_command_lines (&bs
->commands
);
1993 /* Clear a bpstat so that it says we are not at any breakpoint.
1994 Also free any storage that is part of a bpstat. */
1997 bpstat_clear (bpstat
*bsp
)
2014 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2015 is part of the bpstat is copied as well. */
2018 bpstat_copy (bpstat bs
)
2022 bpstat retval
= NULL
;
2027 for (; bs
!= NULL
; bs
= bs
->next
)
2029 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2030 memcpy (tmp
, bs
, sizeof (*tmp
));
2031 if (bs
->commands
!= NULL
)
2032 tmp
->commands
= copy_command_lines (bs
->commands
);
2033 if (bs
->old_val
!= NULL
)
2035 tmp
->old_val
= value_copy (bs
->old_val
);
2036 release_value (tmp
->old_val
);
2040 /* This is the first thing in the chain. */
2050 /* Find the bpstat associated with this breakpoint */
2053 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2058 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2060 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2066 /* Find a step_resume breakpoint associated with this bpstat.
2067 (If there are multiple step_resume bp's on the list, this function
2068 will arbitrarily pick one.)
2070 It is an error to use this function if BPSTAT doesn't contain a
2071 step_resume breakpoint.
2073 See wait_for_inferior's use of this function. */
2075 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2079 gdb_assert (bsp
!= NULL
);
2081 current_thread
= pid_to_thread_id (inferior_ptid
);
2083 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2085 if ((bsp
->breakpoint_at
!= NULL
) &&
2086 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2087 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2088 bsp
->breakpoint_at
->owner
->thread
== -1))
2089 return bsp
->breakpoint_at
->owner
;
2092 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2096 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2097 at. *BSP upon return is a bpstat which points to the remaining
2098 breakpoints stopped at (but which is not guaranteed to be good for
2099 anything but further calls to bpstat_num).
2100 Return 0 if passed a bpstat which does not indicate any breakpoints.
2101 Return -1 if stopped at a breakpoint that has been deleted since
2103 Return 1 otherwise. */
2106 bpstat_num (bpstat
*bsp
, int *num
)
2108 struct breakpoint
*b
;
2111 return 0; /* No more breakpoint values */
2113 /* We assume we'll never have several bpstats that
2114 correspond to a single breakpoint -- otherwise,
2115 this function might return the same number more
2116 than once and this will look ugly. */
2117 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2118 *bsp
= (*bsp
)->next
;
2120 return -1; /* breakpoint that's been deleted since */
2122 *num
= b
->number
; /* We have its number */
2126 /* Modify BS so that the actions will not be performed. */
2129 bpstat_clear_actions (bpstat bs
)
2131 for (; bs
!= NULL
; bs
= bs
->next
)
2133 free_command_lines (&bs
->commands
);
2134 if (bs
->old_val
!= NULL
)
2136 value_free (bs
->old_val
);
2142 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2144 cleanup_executing_breakpoints (void *ignore
)
2146 executing_breakpoint_commands
= 0;
2149 /* Execute all the commands associated with all the breakpoints at this
2150 location. Any of these commands could cause the process to proceed
2151 beyond this point, etc. We look out for such changes by checking
2152 the global "breakpoint_proceeded" after each command.
2154 Returns true if a breakpoint command resumed the inferior. In that
2155 case, it is the caller's responsibility to recall it again with the
2156 bpstat of the current thread. */
2159 bpstat_do_actions_1 (bpstat
*bsp
)
2162 struct cleanup
*old_chain
;
2165 /* Avoid endless recursion if a `source' command is contained
2167 if (executing_breakpoint_commands
)
2170 executing_breakpoint_commands
= 1;
2171 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2173 /* This pointer will iterate over the list of bpstat's. */
2176 breakpoint_proceeded
= 0;
2177 for (; bs
!= NULL
; bs
= bs
->next
)
2179 struct command_line
*cmd
;
2180 struct cleanup
*this_cmd_tree_chain
;
2182 /* Take ownership of the BSP's command tree, if it has one.
2184 The command tree could legitimately contain commands like
2185 'step' and 'next', which call clear_proceed_status, which
2186 frees stop_bpstat's command tree. To make sure this doesn't
2187 free the tree we're executing out from under us, we need to
2188 take ownership of the tree ourselves. Since a given bpstat's
2189 commands are only executed once, we don't need to copy it; we
2190 can clear the pointer in the bpstat, and make sure we free
2191 the tree when we're done. */
2194 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2198 execute_control_command (cmd
);
2200 if (breakpoint_proceeded
)
2206 /* We can free this command tree now. */
2207 do_cleanups (this_cmd_tree_chain
);
2209 if (breakpoint_proceeded
)
2211 if (target_can_async_p ())
2212 /* If we are in async mode, then the target might be still
2213 running, not stopped at any breakpoint, so nothing for
2214 us to do here -- just return to the event loop. */
2217 /* In sync mode, when execute_control_command returns
2218 we're already standing on the next breakpoint.
2219 Breakpoint commands for that stop were not run, since
2220 execute_command does not run breakpoint commands --
2221 only command_line_handler does, but that one is not
2222 involved in execution of breakpoint commands. So, we
2223 can now execute breakpoint commands. It should be
2224 noted that making execute_command do bpstat actions is
2225 not an option -- in this case we'll have recursive
2226 invocation of bpstat for each breakpoint with a
2227 command, and can easily blow up GDB stack. Instead, we
2228 return true, which will trigger the caller to recall us
2229 with the new stop_bpstat. */
2234 do_cleanups (old_chain
);
2239 bpstat_do_actions (void)
2241 /* Do any commands attached to breakpoint we are stopped at. */
2242 while (!ptid_equal (inferior_ptid
, null_ptid
)
2243 && target_has_execution
2244 && !is_exited (inferior_ptid
)
2245 && !is_executing (inferior_ptid
))
2246 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2247 and only return when it is stopped at the next breakpoint, we
2248 keep doing breakpoint actions until it returns false to
2249 indicate the inferior was not resumed. */
2250 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
2254 /* Print out the (old or new) value associated with a watchpoint. */
2257 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2260 fprintf_unfiltered (stream
, _("<unreadable>"));
2262 value_print (val
, stream
, 0, Val_pretty_default
);
2265 /* This is the normal print function for a bpstat. In the future,
2266 much of this logic could (should?) be moved to bpstat_stop_status,
2267 by having it set different print_it values.
2269 Current scheme: When we stop, bpstat_print() is called. It loops
2270 through the bpstat list of things causing this stop, calling the
2271 print_bp_stop_message function on each one. The behavior of the
2272 print_bp_stop_message function depends on the print_it field of
2273 bpstat. If such field so indicates, call this function here.
2275 Return values from this routine (ultimately used by bpstat_print()
2276 and normal_stop() to decide what to do):
2277 PRINT_NOTHING: Means we already printed all we needed to print,
2278 don't print anything else.
2279 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2280 that something to be followed by a location.
2281 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2282 that something to be followed by a location.
2283 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2286 static enum print_stop_action
2287 print_it_typical (bpstat bs
)
2289 struct cleanup
*old_chain
, *ui_out_chain
;
2290 struct breakpoint
*b
;
2291 const struct bp_location
*bl
;
2292 struct ui_stream
*stb
;
2294 stb
= ui_out_stream_new (uiout
);
2295 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2296 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2297 which has since been deleted. */
2298 if (bs
->breakpoint_at
== NULL
)
2299 return PRINT_UNKNOWN
;
2300 bl
= bs
->breakpoint_at
;
2306 case bp_hardware_breakpoint
:
2307 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2308 if (bl
->address
!= bl
->requested_address
)
2309 breakpoint_adjustment_warning (bl
->requested_address
,
2312 annotate_breakpoint (b
->number
);
2314 ui_out_text (uiout
, "\nTemporary breakpoint ");
2316 ui_out_text (uiout
, "\nBreakpoint ");
2317 if (ui_out_is_mi_like_p (uiout
))
2319 ui_out_field_string (uiout
, "reason",
2320 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2321 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2323 ui_out_field_int (uiout
, "bkptno", b
->number
);
2324 ui_out_text (uiout
, ", ");
2325 return PRINT_SRC_AND_LOC
;
2328 case bp_shlib_event
:
2329 /* Did we stop because the user set the stop_on_solib_events
2330 variable? (If so, we report this as a generic, "Stopped due
2331 to shlib event" message.) */
2332 printf_filtered (_("Stopped due to shared library event\n"));
2333 return PRINT_NOTHING
;
2336 case bp_thread_event
:
2337 /* Not sure how we will get here.
2338 GDB should not stop for these breakpoints. */
2339 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2340 return PRINT_NOTHING
;
2343 case bp_overlay_event
:
2344 /* By analogy with the thread event, GDB should not stop for these. */
2345 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2346 return PRINT_NOTHING
;
2350 annotate_catchpoint (b
->number
);
2351 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2353 b
->triggered_dll_pathname
);
2354 return PRINT_SRC_AND_LOC
;
2357 case bp_catch_unload
:
2358 annotate_catchpoint (b
->number
);
2359 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2361 b
->triggered_dll_pathname
);
2362 return PRINT_SRC_AND_LOC
;
2366 annotate_catchpoint (b
->number
);
2367 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2370 return PRINT_SRC_AND_LOC
;
2374 case bp_hardware_watchpoint
:
2375 annotate_watchpoint (b
->number
);
2376 if (ui_out_is_mi_like_p (uiout
))
2379 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2381 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2382 ui_out_text (uiout
, "\nOld value = ");
2383 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2384 ui_out_field_stream (uiout
, "old", stb
);
2385 ui_out_text (uiout
, "\nNew value = ");
2386 watchpoint_value_print (b
->val
, stb
->stream
);
2387 ui_out_field_stream (uiout
, "new", stb
);
2388 do_cleanups (ui_out_chain
);
2389 ui_out_text (uiout
, "\n");
2390 /* More than one watchpoint may have been triggered. */
2391 return PRINT_UNKNOWN
;
2394 case bp_read_watchpoint
:
2395 if (ui_out_is_mi_like_p (uiout
))
2398 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2400 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2401 ui_out_text (uiout
, "\nValue = ");
2402 watchpoint_value_print (b
->val
, stb
->stream
);
2403 ui_out_field_stream (uiout
, "value", stb
);
2404 do_cleanups (ui_out_chain
);
2405 ui_out_text (uiout
, "\n");
2406 return PRINT_UNKNOWN
;
2409 case bp_access_watchpoint
:
2410 if (bs
->old_val
!= NULL
)
2412 annotate_watchpoint (b
->number
);
2413 if (ui_out_is_mi_like_p (uiout
))
2416 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2418 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2419 ui_out_text (uiout
, "\nOld value = ");
2420 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2421 ui_out_field_stream (uiout
, "old", stb
);
2422 ui_out_text (uiout
, "\nNew value = ");
2427 if (ui_out_is_mi_like_p (uiout
))
2430 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2431 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2432 ui_out_text (uiout
, "\nValue = ");
2434 watchpoint_value_print (b
->val
, stb
->stream
);
2435 ui_out_field_stream (uiout
, "new", stb
);
2436 do_cleanups (ui_out_chain
);
2437 ui_out_text (uiout
, "\n");
2438 return PRINT_UNKNOWN
;
2441 /* Fall through, we don't deal with these types of breakpoints
2445 if (ui_out_is_mi_like_p (uiout
))
2448 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2449 return PRINT_UNKNOWN
;
2453 if (ui_out_is_mi_like_p (uiout
))
2456 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2457 return PRINT_UNKNOWN
;
2462 case bp_longjmp_resume
:
2463 case bp_step_resume
:
2464 case bp_watchpoint_scope
:
2467 return PRINT_UNKNOWN
;
2471 /* Generic routine for printing messages indicating why we
2472 stopped. The behavior of this function depends on the value
2473 'print_it' in the bpstat structure. Under some circumstances we
2474 may decide not to print anything here and delegate the task to
2477 static enum print_stop_action
2478 print_bp_stop_message (bpstat bs
)
2480 switch (bs
->print_it
)
2483 /* Nothing should be printed for this bpstat entry. */
2484 return PRINT_UNKNOWN
;
2488 /* We still want to print the frame, but we already printed the
2489 relevant messages. */
2490 return PRINT_SRC_AND_LOC
;
2493 case print_it_normal
:
2495 const struct bp_location
*bl
= bs
->breakpoint_at
;
2496 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2498 /* Normal case. Call the breakpoint's print_it method, or
2499 print_it_typical. */
2500 /* FIXME: how breakpoint can ever be NULL here? */
2501 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2502 return b
->ops
->print_it (b
);
2504 return print_it_typical (bs
);
2509 internal_error (__FILE__
, __LINE__
,
2510 _("print_bp_stop_message: unrecognized enum value"));
2515 /* Print a message indicating what happened. This is called from
2516 normal_stop(). The input to this routine is the head of the bpstat
2517 list - a list of the eventpoints that caused this stop. This
2518 routine calls the generic print routine for printing a message
2519 about reasons for stopping. This will print (for example) the
2520 "Breakpoint n," part of the output. The return value of this
2523 PRINT_UNKNOWN: Means we printed nothing
2524 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2525 code to print the location. An example is
2526 "Breakpoint 1, " which should be followed by
2528 PRINT_SRC_ONLY: Means we printed something, but there is no need
2529 to also print the location part of the message.
2530 An example is the catch/throw messages, which
2531 don't require a location appended to the end.
2532 PRINT_NOTHING: We have done some printing and we don't need any
2533 further info to be printed.*/
2535 enum print_stop_action
2536 bpstat_print (bpstat bs
)
2540 /* Maybe another breakpoint in the chain caused us to stop.
2541 (Currently all watchpoints go on the bpstat whether hit or not.
2542 That probably could (should) be changed, provided care is taken
2543 with respect to bpstat_explains_signal). */
2544 for (; bs
; bs
= bs
->next
)
2546 val
= print_bp_stop_message (bs
);
2547 if (val
== PRINT_SRC_ONLY
2548 || val
== PRINT_SRC_AND_LOC
2549 || val
== PRINT_NOTHING
)
2553 /* We reached the end of the chain, or we got a null BS to start
2554 with and nothing was printed. */
2555 return PRINT_UNKNOWN
;
2558 /* Evaluate the expression EXP and return 1 if value is zero.
2559 This is used inside a catch_errors to evaluate the breakpoint condition.
2560 The argument is a "struct expression *" that has been cast to char * to
2561 make it pass through catch_errors. */
2564 breakpoint_cond_eval (void *exp
)
2566 struct value
*mark
= value_mark ();
2567 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2568 value_free_to_mark (mark
);
2572 /* Allocate a new bpstat and chain it to the current one. */
2575 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2579 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2581 bs
->breakpoint_at
= bl
;
2582 /* If the condition is false, etc., don't do the commands. */
2583 bs
->commands
= NULL
;
2585 bs
->print_it
= print_it_normal
;
2589 /* The target has stopped with waitstatus WS. Check if any hardware
2590 watchpoints have triggered, according to the target. */
2593 watchpoints_triggered (struct target_waitstatus
*ws
)
2595 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2597 struct breakpoint
*b
;
2599 if (!stopped_by_watchpoint
)
2601 /* We were not stopped by a watchpoint. Mark all watchpoints
2602 as not triggered. */
2604 if (b
->type
== bp_hardware_watchpoint
2605 || b
->type
== bp_read_watchpoint
2606 || b
->type
== bp_access_watchpoint
)
2607 b
->watchpoint_triggered
= watch_triggered_no
;
2612 if (!target_stopped_data_address (¤t_target
, &addr
))
2614 /* We were stopped by a watchpoint, but we don't know where.
2615 Mark all watchpoints as unknown. */
2617 if (b
->type
== bp_hardware_watchpoint
2618 || b
->type
== bp_read_watchpoint
2619 || b
->type
== bp_access_watchpoint
)
2620 b
->watchpoint_triggered
= watch_triggered_unknown
;
2622 return stopped_by_watchpoint
;
2625 /* The target could report the data address. Mark watchpoints
2626 affected by this data address as triggered, and all others as not
2630 if (b
->type
== bp_hardware_watchpoint
2631 || b
->type
== bp_read_watchpoint
2632 || b
->type
== bp_access_watchpoint
)
2634 struct bp_location
*loc
;
2637 b
->watchpoint_triggered
= watch_triggered_no
;
2638 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2639 /* Exact match not required. Within range is
2641 if (target_watchpoint_addr_within_range (¤t_target
,
2645 b
->watchpoint_triggered
= watch_triggered_yes
;
2653 /* Possible return values for watchpoint_check (this can't be an enum
2654 because of check_errors). */
2655 /* The watchpoint has been deleted. */
2656 #define WP_DELETED 1
2657 /* The value has changed. */
2658 #define WP_VALUE_CHANGED 2
2659 /* The value has not changed. */
2660 #define WP_VALUE_NOT_CHANGED 3
2662 #define BP_TEMPFLAG 1
2663 #define BP_HARDWAREFLAG 2
2665 /* Check watchpoint condition. */
2668 watchpoint_check (void *p
)
2670 bpstat bs
= (bpstat
) p
;
2671 struct breakpoint
*b
;
2672 struct frame_info
*fr
;
2673 int within_current_scope
;
2675 b
= bs
->breakpoint_at
->owner
;
2677 if (b
->exp_valid_block
== NULL
)
2678 within_current_scope
= 1;
2681 /* There is no current frame at this moment. If we're going to have
2682 any chance of handling watchpoints on local variables, we'll need
2683 the frame chain (so we can determine if we're in scope). */
2684 reinit_frame_cache ();
2685 fr
= frame_find_by_id (b
->watchpoint_frame
);
2686 within_current_scope
= (fr
!= NULL
);
2688 /* If we've gotten confused in the unwinder, we might have
2689 returned a frame that can't describe this variable. */
2690 if (within_current_scope
2691 && (block_linkage_function (b
->exp_valid_block
)
2692 != get_frame_function (fr
)))
2693 within_current_scope
= 0;
2695 /* in_function_epilogue_p() returns a non-zero value if we're still
2696 in the function but the stack frame has already been invalidated.
2697 Since we can't rely on the values of local variables after the
2698 stack has been destroyed, we are treating the watchpoint in that
2699 state as `not changed' without further checking.
2701 vinschen/2003-09-04: The former implementation left out the case
2702 that the watchpoint frame couldn't be found by frame_find_by_id()
2703 because the current PC is currently in an epilogue. Calling
2704 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2705 if ((!within_current_scope
|| fr
== get_current_frame ())
2706 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2707 return WP_VALUE_NOT_CHANGED
;
2708 if (fr
&& within_current_scope
)
2709 /* If we end up stopping, the current frame will get selected
2710 in normal_stop. So this call to select_frame won't affect
2715 if (within_current_scope
)
2717 /* We use value_{,free_to_}mark because it could be a
2718 *long* time before we return to the command level and
2719 call free_all_values. We can't call free_all_values because
2720 we might be in the middle of evaluating a function call. */
2722 struct value
*mark
= value_mark ();
2723 struct value
*new_val
;
2725 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2726 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2727 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2729 if (new_val
!= NULL
)
2731 release_value (new_val
);
2732 value_free_to_mark (mark
);
2734 bs
->old_val
= b
->val
;
2737 /* We will stop here */
2738 return WP_VALUE_CHANGED
;
2742 /* Nothing changed, don't do anything. */
2743 value_free_to_mark (mark
);
2744 /* We won't stop here */
2745 return WP_VALUE_NOT_CHANGED
;
2750 /* This seems like the only logical thing to do because
2751 if we temporarily ignored the watchpoint, then when
2752 we reenter the block in which it is valid it contains
2753 garbage (in the case of a function, it may have two
2754 garbage values, one before and one after the prologue).
2755 So we can't even detect the first assignment to it and
2756 watch after that (since the garbage may or may not equal
2757 the first value assigned). */
2758 /* We print all the stop information in print_it_typical(), but
2759 in this case, by the time we call print_it_typical() this bp
2760 will be deleted already. So we have no choice but print the
2761 information here. */
2762 if (ui_out_is_mi_like_p (uiout
))
2764 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2765 ui_out_text (uiout
, "\nWatchpoint ");
2766 ui_out_field_int (uiout
, "wpnum", b
->number
);
2767 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2768 which its expression is valid.\n");
2770 if (b
->related_breakpoint
)
2771 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2772 b
->disposition
= disp_del_at_next_stop
;
2778 /* Return true if it looks like target has stopped due to hitting
2779 breakpoint location BL. This function does not check if we
2780 should stop, only if BL explains the stop. */
2782 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2784 struct breakpoint
*b
= bl
->owner
;
2786 if (b
->type
!= bp_watchpoint
2787 && b
->type
!= bp_hardware_watchpoint
2788 && b
->type
!= bp_read_watchpoint
2789 && b
->type
!= bp_access_watchpoint
2790 && b
->type
!= bp_hardware_breakpoint
2791 && b
->type
!= bp_catchpoint
2792 && b
->type
!= bp_catch_exec
) /* a non-watchpoint bp */
2794 if (bl
->address
!= bp_addr
) /* address doesn't match */
2796 if (overlay_debugging
/* unmapped overlay section */
2797 && section_is_overlay (bl
->section
)
2798 && !section_is_mapped (bl
->section
))
2802 /* Continuable hardware watchpoints are treated as non-existent if the
2803 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2804 some data address). Otherwise gdb won't stop on a break instruction
2805 in the code (not from a breakpoint) when a hardware watchpoint has
2806 been defined. Also skip watchpoints which we know did not trigger
2807 (did not match the data address). */
2809 if ((b
->type
== bp_hardware_watchpoint
2810 || b
->type
== bp_read_watchpoint
2811 || b
->type
== bp_access_watchpoint
)
2812 && b
->watchpoint_triggered
== watch_triggered_no
)
2815 if (b
->type
== bp_hardware_breakpoint
)
2817 if (bl
->address
!= bp_addr
)
2819 if (overlay_debugging
/* unmapped overlay section */
2820 && section_is_overlay (bl
->section
)
2821 && !section_is_mapped (bl
->section
))
2825 /* Is this a catchpoint of a load or unload? If so, did we
2826 get a load or unload of the specified library? If not,
2828 if ((b
->type
== bp_catch_load
)
2829 #if defined(SOLIB_HAVE_LOAD_EVENT)
2830 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2831 || ((b
->dll_pathname
!= NULL
)
2832 && (strcmp (b
->dll_pathname
,
2833 SOLIB_LOADED_LIBRARY_PATHNAME (
2834 PIDGET (inferior_ptid
)))
2840 if ((b
->type
== bp_catch_unload
)
2841 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2842 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2843 || ((b
->dll_pathname
!= NULL
)
2844 && (strcmp (b
->dll_pathname
,
2845 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2846 PIDGET (inferior_ptid
)))
2852 if (b
->type
== bp_catchpoint
)
2854 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
2855 if (!b
->ops
->breakpoint_hit (b
))
2859 if ((b
->type
== bp_catch_exec
)
2860 && !inferior_has_execd (inferior_ptid
, &b
->exec_pathname
))
2866 /* If BS refers to a watchpoint, determine if the watched values
2867 has actually changed, and we should stop. If not, set BS->stop
2870 bpstat_check_watchpoint (bpstat bs
)
2872 const struct bp_location
*bl
= bs
->breakpoint_at
;
2873 struct breakpoint
*b
= bl
->owner
;
2875 if (b
->type
== bp_watchpoint
2876 || b
->type
== bp_read_watchpoint
2877 || b
->type
== bp_access_watchpoint
2878 || b
->type
== bp_hardware_watchpoint
)
2882 int must_check_value
= 0;
2884 if (b
->type
== bp_watchpoint
)
2885 /* For a software watchpoint, we must always check the
2887 must_check_value
= 1;
2888 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2889 /* We have a hardware watchpoint (read, write, or access)
2890 and the target earlier reported an address watched by
2892 must_check_value
= 1;
2893 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2894 && b
->type
== bp_hardware_watchpoint
)
2895 /* We were stopped by a hardware watchpoint, but the target could
2896 not report the data address. We must check the watchpoint's
2897 value. Access and read watchpoints are out of luck; without
2898 a data address, we can't figure it out. */
2899 must_check_value
= 1;
2901 if (must_check_value
)
2903 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2905 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2906 int e
= catch_errors (watchpoint_check
, bs
, message
,
2908 do_cleanups (cleanups
);
2912 /* We've already printed what needs to be printed. */
2913 bs
->print_it
= print_it_done
;
2916 case WP_VALUE_CHANGED
:
2917 if (b
->type
== bp_read_watchpoint
)
2919 /* Don't stop: read watchpoints shouldn't fire if
2920 the value has changed. This is for targets
2921 which cannot set read-only watchpoints. */
2922 bs
->print_it
= print_it_noop
;
2926 case WP_VALUE_NOT_CHANGED
:
2927 if (b
->type
== bp_hardware_watchpoint
2928 || b
->type
== bp_watchpoint
)
2930 /* Don't stop: write watchpoints shouldn't fire if
2931 the value hasn't changed. */
2932 bs
->print_it
= print_it_noop
;
2940 /* Error from catch_errors. */
2941 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2942 if (b
->related_breakpoint
)
2943 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2944 b
->disposition
= disp_del_at_next_stop
;
2945 /* We've already printed what needs to be printed. */
2946 bs
->print_it
= print_it_done
;
2950 else /* must_check_value == 0 */
2952 /* This is a case where some watchpoint(s) triggered, but
2953 not at the address of this watchpoint, or else no
2954 watchpoint triggered after all. So don't print
2955 anything for this watchpoint. */
2956 bs
->print_it
= print_it_noop
;
2963 /* Check conditions (condition proper, frame, thread and ignore count)
2964 of breakpoint referred to by BS. If we should not stop for this
2965 breakpoint, set BS->stop to 0. */
2967 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2969 int thread_id
= pid_to_thread_id (ptid
);
2970 const struct bp_location
*bl
= bs
->breakpoint_at
;
2971 struct breakpoint
*b
= bl
->owner
;
2973 if (frame_id_p (b
->frame_id
)
2974 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2978 int value_is_zero
= 0;
2980 /* If this is a scope breakpoint, mark the associated
2981 watchpoint as triggered so that we will handle the
2982 out-of-scope event. We'll get to the watchpoint next
2984 if (b
->type
== bp_watchpoint_scope
)
2985 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2987 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2989 /* Need to select the frame, with all that implies
2990 so that the conditions will have the right context. */
2991 select_frame (get_current_frame ());
2993 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2994 "Error in testing breakpoint condition:\n",
2996 /* FIXME-someday, should give breakpoint # */
2999 if (bl
->cond
&& value_is_zero
)
3003 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3007 else if (b
->ignore_count
> 0)
3010 annotate_ignore_count_change ();
3012 /* Increase the hit count even though we don't
3020 /* Get a bpstat associated with having just stopped at address
3021 BP_ADDR in thread PTID.
3023 Determine whether we stopped at a breakpoint, etc, or whether we
3024 don't understand this stop. Result is a chain of bpstat's such that:
3026 if we don't understand the stop, the result is a null pointer.
3028 if we understand why we stopped, the result is not null.
3030 Each element of the chain refers to a particular breakpoint or
3031 watchpoint at which we have stopped. (We may have stopped for
3032 several reasons concurrently.)
3034 Each element of the chain has valid next, breakpoint_at,
3035 commands, FIXME??? fields. */
3038 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3040 struct breakpoint
*b
= NULL
;
3041 const struct bp_location
*bl
;
3042 struct bp_location
*loc
;
3043 /* Root of the chain of bpstat's */
3044 struct bpstats root_bs
[1];
3045 /* Pointer to the last thing in the chain currently. */
3046 bpstat bs
= root_bs
;
3048 int need_remove_insert
;
3050 ALL_BP_LOCATIONS (bl
)
3054 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3057 /* For hardware watchpoints, we look only at the first location.
3058 The watchpoint_check function will work on entire expression,
3059 not the individual locations. For read watchopints, the
3060 watchpoints_triggered function have checked all locations
3063 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3066 if (!bpstat_check_location (bl
, bp_addr
))
3069 /* Come here if it's a watchpoint, or if the break address matches */
3071 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3073 /* Assume we stop. Should we find watchpoint that is not actually
3074 triggered, or if condition of breakpoint is false, we'll reset
3079 bpstat_check_watchpoint (bs
);
3083 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3084 /* We do not stop for these. */
3087 bpstat_check_breakpoint_conditions (bs
, ptid
);
3093 /* We will stop here */
3094 if (b
->disposition
== disp_disable
)
3096 if (b
->enable_state
!= bp_permanent
)
3097 b
->enable_state
= bp_disabled
;
3098 update_global_location_list (0);
3102 bs
->commands
= b
->commands
;
3104 (strcmp ("silent", bs
->commands
->line
) == 0
3105 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3107 bs
->commands
= bs
->commands
->next
;
3110 bs
->commands
= copy_command_lines (bs
->commands
);
3113 /* Print nothing for this entry if we dont stop or if we dont print. */
3114 if (bs
->stop
== 0 || bs
->print
== 0)
3115 bs
->print_it
= print_it_noop
;
3118 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3120 if (loc
->address
== bp_addr
)
3122 bs
= bpstat_alloc (loc
, bs
);
3123 /* For hits of moribund locations, we should just proceed. */
3126 bs
->print_it
= print_it_noop
;
3130 bs
->next
= NULL
; /* Terminate the chain */
3131 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3133 /* If we aren't stopping, the value of some hardware watchpoint may
3134 not have changed, but the intermediate memory locations we are
3135 watching may have. Don't bother if we're stopping; this will get
3137 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3141 need_remove_insert
= 0;
3143 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3145 && bs
->breakpoint_at
->owner
3146 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3147 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3148 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3150 /* remove/insert can invalidate bs->breakpoint_at, if this
3151 location is no longer used by the watchpoint. Prevent
3152 further code from trying to use it. */
3153 bs
->breakpoint_at
= NULL
;
3154 need_remove_insert
= 1;
3157 if (need_remove_insert
)
3159 remove_breakpoints ();
3160 insert_breakpoints ();
3163 return root_bs
->next
;
3166 /* Tell what to do about this bpstat. */
3168 bpstat_what (bpstat bs
)
3170 /* Classify each bpstat as one of the following. */
3173 /* This bpstat element has no effect on the main_action. */
3176 /* There was a watchpoint, stop but don't print. */
3179 /* There was a watchpoint, stop and print. */
3182 /* There was a breakpoint but we're not stopping. */
3185 /* There was a breakpoint, stop but don't print. */
3188 /* There was a breakpoint, stop and print. */
3191 /* We hit the longjmp breakpoint. */
3194 /* We hit the longjmp_resume breakpoint. */
3197 /* We hit the step_resume breakpoint. */
3200 /* We hit the shared library event breakpoint. */
3203 /* We caught a shared library event. */
3206 /* This is just used to count how many enums there are. */
3210 /* Here is the table which drives this routine. So that we can
3211 format it pretty, we define some abbreviations for the
3212 enum bpstat_what codes. */
3213 #define kc BPSTAT_WHAT_KEEP_CHECKING
3214 #define ss BPSTAT_WHAT_STOP_SILENT
3215 #define sn BPSTAT_WHAT_STOP_NOISY
3216 #define sgl BPSTAT_WHAT_SINGLE
3217 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3218 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3219 #define sr BPSTAT_WHAT_STEP_RESUME
3220 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3221 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3223 /* "Can't happen." Might want to print an error message.
3224 abort() is not out of the question, but chances are GDB is just
3225 a bit confused, not unusable. */
3226 #define err BPSTAT_WHAT_STOP_NOISY
3228 /* Given an old action and a class, come up with a new action. */
3229 /* One interesting property of this table is that wp_silent is the same
3230 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3231 after stopping, the check for whether to step over a breakpoint
3232 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3233 reference to how we stopped. We retain separate wp_silent and
3234 bp_silent codes in case we want to change that someday.
3236 Another possibly interesting property of this table is that
3237 there's a partial ordering, priority-like, of the actions. Once
3238 you've decided that some action is appropriate, you'll never go
3239 back and decide something of a lower priority is better. The
3242 kc < clr sgl shl shlr slr sn sr ss
3243 sgl < shl shlr slr sn sr ss
3244 slr < err shl shlr sn sr ss
3245 clr < err shl shlr sn sr ss
3252 What I think this means is that we don't need a damned table
3253 here. If you just put the rows and columns in the right order,
3254 it'd look awfully regular. We could simply walk the bpstat list
3255 and choose the highest priority action we find, with a little
3256 logic to handle the 'err' cases. */
3258 /* step_resume entries: a step resume breakpoint overrides another
3259 breakpoint of signal handling (see comment in wait_for_inferior
3260 at where we set the step_resume breakpoint). */
3262 static const enum bpstat_what_main_action
3263 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3266 /* kc ss sn sgl slr clr sr shl shlr
3269 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, shlr
},
3271 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3273 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3275 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, shlr
},
3277 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3279 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3281 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, shlr
},
3283 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, shlr
},
3285 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3287 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3289 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3303 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3304 struct bpstat_what retval
;
3306 retval
.call_dummy
= 0;
3307 for (; bs
!= NULL
; bs
= bs
->next
)
3309 enum class bs_class
= no_effect
;
3310 if (bs
->breakpoint_at
== NULL
)
3311 /* I suspect this can happen if it was a momentary breakpoint
3312 which has since been deleted. */
3314 if (bs
->breakpoint_at
->owner
== NULL
)
3315 bs_class
= bp_nostop
;
3317 switch (bs
->breakpoint_at
->owner
->type
)
3323 case bp_hardware_breakpoint
:
3329 bs_class
= bp_noisy
;
3331 bs_class
= bp_silent
;
3334 bs_class
= bp_nostop
;
3337 case bp_hardware_watchpoint
:
3338 case bp_read_watchpoint
:
3339 case bp_access_watchpoint
:
3343 bs_class
= wp_noisy
;
3345 bs_class
= wp_silent
;
3348 /* There was a watchpoint, but we're not stopping.
3349 This requires no further action. */
3350 bs_class
= no_effect
;
3353 bs_class
= long_jump
;
3355 case bp_longjmp_resume
:
3356 bs_class
= long_resume
;
3358 case bp_step_resume
:
3361 bs_class
= step_resume
;
3364 /* It is for the wrong frame. */
3365 bs_class
= bp_nostop
;
3367 case bp_watchpoint_scope
:
3368 bs_class
= bp_nostop
;
3370 case bp_shlib_event
:
3371 bs_class
= shlib_event
;
3373 case bp_thread_event
:
3374 case bp_overlay_event
:
3375 bs_class
= bp_nostop
;
3378 case bp_catch_unload
:
3379 /* Only if this catchpoint triggered should we cause the
3380 step-out-of-dld behaviour. Otherwise, we ignore this
3383 bs_class
= catch_shlib_event
;
3385 bs_class
= no_effect
;
3392 bs_class
= bp_noisy
;
3394 bs_class
= bp_silent
;
3397 /* There was a catchpoint, but we're not stopping.
3398 This requires no further action. */
3399 bs_class
= no_effect
;
3402 /* Make sure the action is stop (silent or noisy),
3403 so infrun.c pops the dummy frame. */
3404 bs_class
= bp_silent
;
3405 retval
.call_dummy
= 1;
3408 current_action
= table
[(int) bs_class
][(int) current_action
];
3410 retval
.main_action
= current_action
;
3414 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3415 without hardware support). This isn't related to a specific bpstat,
3416 just to things like whether watchpoints are set. */
3419 bpstat_should_step (void)
3421 struct breakpoint
*b
;
3423 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3430 /* Given a bpstat that records zero or more triggered eventpoints, this
3431 function returns another bpstat which contains only the catchpoints
3432 on that first list, if any. */
3434 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3436 struct bpstats root_bs
[1];
3437 bpstat bs
= root_bs
;
3438 struct breakpoint
*ep
;
3441 bpstat_clear (cp_list
);
3442 root_bs
->next
= NULL
;
3444 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3446 /* Is this eventpoint a catchpoint? If not, ignore it. */
3447 ep
= ep_list
->breakpoint_at
->owner
;
3450 if ((ep
->type
!= bp_catch_load
) &&
3451 (ep
->type
!= bp_catch_unload
))
3452 /* pai: (temp) ADD fork/vfork here!! */
3455 /* Yes; add it to the list. */
3456 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3461 #if defined(SOLIB_ADD)
3462 /* Also, for each triggered catchpoint, tag it with the name of
3463 the library that caused this trigger. (We copy the name now,
3464 because it's only guaranteed to be available NOW, when the
3465 catchpoint triggers. Clients who may wish to know the name
3466 later must get it from the catchpoint itself.) */
3467 if (ep
->triggered_dll_pathname
!= NULL
)
3468 xfree (ep
->triggered_dll_pathname
);
3469 if (ep
->type
== bp_catch_load
)
3470 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3471 PIDGET (inferior_ptid
));
3473 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3474 PIDGET (inferior_ptid
));
3476 dll_pathname
= NULL
;
3480 ep
->triggered_dll_pathname
= (char *)
3481 xmalloc (strlen (dll_pathname
) + 1);
3482 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3485 ep
->triggered_dll_pathname
= NULL
;
3491 static void print_breakpoint_location (struct breakpoint
*b
,
3492 struct bp_location
*loc
,
3494 struct ui_stream
*stb
)
3499 = find_pc_sect_function (loc
->address
, loc
->section
);
3502 ui_out_text (uiout
, "in ");
3503 ui_out_field_string (uiout
, "func",
3504 SYMBOL_PRINT_NAME (sym
));
3505 ui_out_wrap_hint (uiout
, wrap_indent
);
3506 ui_out_text (uiout
, " at ");
3508 ui_out_field_string (uiout
, "file", b
->source_file
);
3509 ui_out_text (uiout
, ":");
3511 if (ui_out_is_mi_like_p (uiout
))
3513 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3514 char *fullname
= symtab_to_fullname (sal
.symtab
);
3517 ui_out_field_string (uiout
, "fullname", fullname
);
3520 ui_out_field_int (uiout
, "line", b
->line_number
);
3524 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3528 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3529 ui_out_field_stream (uiout
, "at", stb
);
3533 /* Print B to gdb_stdout. */
3535 print_one_breakpoint_location (struct breakpoint
*b
,
3536 struct bp_location
*loc
,
3538 CORE_ADDR
*last_addr
)
3540 struct command_line
*l
;
3542 struct ep_type_description
3547 static struct ep_type_description bptypes
[] =
3549 {bp_none
, "?deleted?"},
3550 {bp_breakpoint
, "breakpoint"},
3551 {bp_hardware_breakpoint
, "hw breakpoint"},
3552 {bp_until
, "until"},
3553 {bp_finish
, "finish"},
3554 {bp_watchpoint
, "watchpoint"},
3555 {bp_hardware_watchpoint
, "hw watchpoint"},
3556 {bp_read_watchpoint
, "read watchpoint"},
3557 {bp_access_watchpoint
, "acc watchpoint"},
3558 {bp_longjmp
, "longjmp"},
3559 {bp_longjmp_resume
, "longjmp resume"},
3560 {bp_step_resume
, "step resume"},
3561 {bp_watchpoint_scope
, "watchpoint scope"},
3562 {bp_call_dummy
, "call dummy"},
3563 {bp_shlib_event
, "shlib events"},
3564 {bp_thread_event
, "thread events"},
3565 {bp_overlay_event
, "overlay events"},
3566 {bp_catchpoint
, "catchpoint"},
3567 {bp_catch_load
, "catch load"},
3568 {bp_catch_unload
, "catch unload"},
3569 {bp_catch_exec
, "catch exec"}
3572 static char bpenables
[] = "nynny";
3573 char wrap_indent
[80];
3574 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3575 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3576 struct cleanup
*bkpt_chain
;
3578 int header_of_multiple
= 0;
3579 int part_of_multiple
= (loc
!= NULL
);
3581 gdb_assert (!loc
|| loc_number
!= 0);
3582 /* See comment in print_one_breakpoint concerning
3583 treatment of breakpoints with single disabled
3587 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3588 header_of_multiple
= 1;
3593 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3597 if (part_of_multiple
)
3600 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3601 ui_out_field_string (uiout
, "number", formatted
);
3606 ui_out_field_int (uiout
, "number", b
->number
);
3611 if (part_of_multiple
)
3612 ui_out_field_skip (uiout
, "type");
3615 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3616 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3617 internal_error (__FILE__
, __LINE__
,
3618 _("bptypes table does not describe type #%d."),
3620 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3625 if (part_of_multiple
)
3626 ui_out_field_skip (uiout
, "disp");
3628 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3633 if (part_of_multiple
)
3634 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3636 ui_out_field_fmt (uiout
, "enabled", "%c",
3637 bpenables
[(int) b
->enable_state
]);
3638 ui_out_spaces (uiout
, 2);
3642 strcpy (wrap_indent
, " ");
3645 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3646 strcat (wrap_indent
, " ");
3648 strcat (wrap_indent
, " ");
3651 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3653 /* Although the print_one can possibly print
3654 all locations, calling it here is not likely
3655 to get any nice result. So, make sure there's
3656 just one location. */
3657 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3658 b
->ops
->print_one (b
, last_addr
);
3664 internal_error (__FILE__
, __LINE__
,
3665 _("print_one_breakpoint: bp_none encountered\n"));
3669 case bp_hardware_watchpoint
:
3670 case bp_read_watchpoint
:
3671 case bp_access_watchpoint
:
3672 /* Field 4, the address, is omitted (which makes the columns
3673 not line up too nicely with the headers, but the effect
3674 is relatively readable). */
3676 ui_out_field_skip (uiout
, "addr");
3678 print_expression (b
->exp
, stb
->stream
);
3679 ui_out_field_stream (uiout
, "what", stb
);
3683 case bp_catch_unload
:
3684 /* Field 4, the address, is omitted (which makes the columns
3685 not line up too nicely with the headers, but the effect
3686 is relatively readable). */
3688 ui_out_field_skip (uiout
, "addr");
3690 if (b
->dll_pathname
== NULL
)
3692 ui_out_field_string (uiout
, "what", "<any library>");
3693 ui_out_spaces (uiout
, 1);
3697 ui_out_text (uiout
, "library \"");
3698 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3699 ui_out_text (uiout
, "\" ");
3704 /* Field 4, the address, is omitted (which makes the columns
3705 not line up too nicely with the headers, but the effect
3706 is relatively readable). */
3708 ui_out_field_skip (uiout
, "addr");
3710 if (b
->exec_pathname
!= NULL
)
3712 ui_out_text (uiout
, "program \"");
3713 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3714 ui_out_text (uiout
, "\" ");
3719 case bp_hardware_breakpoint
:
3723 case bp_longjmp_resume
:
3724 case bp_step_resume
:
3725 case bp_watchpoint_scope
:
3727 case bp_shlib_event
:
3728 case bp_thread_event
:
3729 case bp_overlay_event
:
3733 if (header_of_multiple
)
3734 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3735 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3736 ui_out_field_string (uiout
, "addr", "<PENDING>");
3738 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3741 if (!header_of_multiple
)
3742 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3744 *last_addr
= b
->loc
->address
;
3748 if (!part_of_multiple
&& b
->thread
!= -1)
3750 /* FIXME: This seems to be redundant and lost here; see the
3751 "stop only in" line a little further down. */
3752 ui_out_text (uiout
, " thread ");
3753 ui_out_field_int (uiout
, "thread", b
->thread
);
3756 ui_out_text (uiout
, "\n");
3758 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3761 ui_out_text (uiout
, "\tstop only in stack frame at ");
3762 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3764 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3765 ui_out_text (uiout
, "\n");
3768 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3770 /* We do not print the condition for Ada exception catchpoints
3771 because the condition is an internal implementation detail
3772 that we do not want to expose to the user. */
3774 ui_out_text (uiout
, "\tstop only if ");
3775 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3776 ui_out_text (uiout
, "\n");
3779 if (!part_of_multiple
&& b
->thread
!= -1)
3781 /* FIXME should make an annotation for this */
3782 ui_out_text (uiout
, "\tstop only in thread ");
3783 ui_out_field_int (uiout
, "thread", b
->thread
);
3784 ui_out_text (uiout
, "\n");
3787 if (!part_of_multiple
&& b
->hit_count
)
3789 /* FIXME should make an annotation for this */
3790 if (ep_is_catchpoint (b
))
3791 ui_out_text (uiout
, "\tcatchpoint");
3793 ui_out_text (uiout
, "\tbreakpoint");
3794 ui_out_text (uiout
, " already hit ");
3795 ui_out_field_int (uiout
, "times", b
->hit_count
);
3796 if (b
->hit_count
== 1)
3797 ui_out_text (uiout
, " time\n");
3799 ui_out_text (uiout
, " times\n");
3802 /* Output the count also if it is zero, but only if this is
3803 mi. FIXME: Should have a better test for this. */
3804 if (ui_out_is_mi_like_p (uiout
))
3805 if (!part_of_multiple
&& b
->hit_count
== 0)
3806 ui_out_field_int (uiout
, "times", b
->hit_count
);
3808 if (!part_of_multiple
&& b
->ignore_count
)
3811 ui_out_text (uiout
, "\tignore next ");
3812 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3813 ui_out_text (uiout
, " hits\n");
3816 if (!part_of_multiple
&& (l
= b
->commands
))
3818 struct cleanup
*script_chain
;
3821 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3822 print_command_lines (uiout
, l
, 4);
3823 do_cleanups (script_chain
);
3826 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3829 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3830 else if (b
->exp_string
)
3831 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3834 do_cleanups (bkpt_chain
);
3835 do_cleanups (old_chain
);
3839 print_one_breakpoint (struct breakpoint
*b
,
3840 CORE_ADDR
*last_addr
)
3842 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3844 /* If this breakpoint has custom print function,
3845 it's already printed. Otherwise, print individual
3846 locations, if any. */
3847 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3849 /* If breakpoint has a single location that is
3850 disabled, we print it as if it had
3851 several locations, since otherwise it's hard to
3852 represent "breakpoint enabled, location disabled"
3854 Note that while hardware watchpoints have
3855 several locations internally, that's no a property
3858 && !is_hardware_watchpoint (b
)
3859 && (b
->loc
->next
|| !b
->loc
->enabled
)
3860 && !ui_out_is_mi_like_p (uiout
))
3862 struct bp_location
*loc
;
3864 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3865 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3871 struct captured_breakpoint_query_args
3877 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3879 struct captured_breakpoint_query_args
*args
= data
;
3880 struct breakpoint
*b
;
3881 CORE_ADDR dummy_addr
= 0;
3884 if (args
->bnum
== b
->number
)
3886 print_one_breakpoint (b
, &dummy_addr
);
3894 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3896 struct captured_breakpoint_query_args args
;
3898 /* For the moment we don't trust print_one_breakpoint() to not throw
3900 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3901 error_message
, RETURN_MASK_ALL
) < 0)
3907 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3908 catchpoints, et.al.). */
3911 user_settable_breakpoint (const struct breakpoint
*b
)
3913 return (b
->type
== bp_breakpoint
3914 || b
->type
== bp_catchpoint
3915 || b
->type
== bp_catch_load
3916 || b
->type
== bp_catch_unload
3917 || b
->type
== bp_catch_exec
3918 || b
->type
== bp_hardware_breakpoint
3919 || b
->type
== bp_watchpoint
3920 || b
->type
== bp_read_watchpoint
3921 || b
->type
== bp_access_watchpoint
3922 || b
->type
== bp_hardware_watchpoint
);
3925 /* Print information on user settable breakpoint (watchpoint, etc)
3926 number BNUM. If BNUM is -1 print all user settable breakpoints.
3927 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3930 breakpoint_1 (int bnum
, int allflag
)
3932 struct breakpoint
*b
;
3933 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3934 int nr_printable_breakpoints
;
3935 struct cleanup
*bkpttbl_chain
;
3937 /* Compute the number of rows in the table. */
3938 nr_printable_breakpoints
= 0;
3941 || bnum
== b
->number
)
3943 if (allflag
|| user_settable_breakpoint (b
))
3944 nr_printable_breakpoints
++;
3949 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3953 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3956 if (nr_printable_breakpoints
> 0)
3957 annotate_breakpoints_headers ();
3958 if (nr_printable_breakpoints
> 0)
3960 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3961 if (nr_printable_breakpoints
> 0)
3963 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3964 if (nr_printable_breakpoints
> 0)
3966 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3967 if (nr_printable_breakpoints
> 0)
3969 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3972 if (nr_printable_breakpoints
> 0)
3974 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3975 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3977 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3979 if (nr_printable_breakpoints
> 0)
3981 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3982 ui_out_table_body (uiout
);
3983 if (nr_printable_breakpoints
> 0)
3984 annotate_breakpoints_table ();
3988 || bnum
== b
->number
)
3990 /* We only print out user settable breakpoints unless the
3992 if (allflag
|| user_settable_breakpoint (b
))
3993 print_one_breakpoint (b
, &last_addr
);
3996 do_cleanups (bkpttbl_chain
);
3998 if (nr_printable_breakpoints
== 0)
4001 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
4003 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
4008 /* Compare against (CORE_ADDR)-1 in case some compiler decides
4009 that a comparison of an unsigned with -1 is always false. */
4010 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
4011 set_next_address (current_gdbarch
, last_addr
);
4014 /* FIXME? Should this be moved up so that it is only called when
4015 there have been breakpoints? */
4016 annotate_breakpoints_table_end ();
4020 breakpoints_info (char *bnum_exp
, int from_tty
)
4025 bnum
= parse_and_eval_long (bnum_exp
);
4027 breakpoint_1 (bnum
, 0);
4031 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4036 bnum
= parse_and_eval_long (bnum_exp
);
4038 breakpoint_1 (bnum
, 1);
4042 breakpoint_has_pc (struct breakpoint
*b
,
4043 CORE_ADDR pc
, struct obj_section
*section
)
4045 struct bp_location
*bl
= b
->loc
;
4046 for (; bl
; bl
= bl
->next
)
4048 if (bl
->address
== pc
4049 && (!overlay_debugging
|| bl
->section
== section
))
4055 /* Print a message describing any breakpoints set at PC. */
4058 describe_other_breakpoints (CORE_ADDR pc
, struct obj_section
*section
,
4062 struct breakpoint
*b
;
4065 others
+= breakpoint_has_pc (b
, pc
, section
);
4069 printf_filtered (_("Note: breakpoint "));
4070 else /* if (others == ???) */
4071 printf_filtered (_("Note: breakpoints "));
4073 if (breakpoint_has_pc (b
, pc
, section
))
4076 printf_filtered ("%d", b
->number
);
4077 if (b
->thread
== -1 && thread
!= -1)
4078 printf_filtered (" (all threads)");
4079 else if (b
->thread
!= -1)
4080 printf_filtered (" (thread %d)", b
->thread
);
4081 printf_filtered ("%s%s ",
4082 ((b
->enable_state
== bp_disabled
||
4083 b
->enable_state
== bp_call_disabled
)
4085 : b
->enable_state
== bp_permanent
4089 : ((others
== 1) ? " and" : ""));
4091 printf_filtered (_("also set at pc "));
4092 fputs_filtered (paddress (pc
), gdb_stdout
);
4093 printf_filtered (".\n");
4097 /* Set the default place to put a breakpoint
4098 for the `break' command with no arguments. */
4101 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4104 default_breakpoint_valid
= valid
;
4105 default_breakpoint_address
= addr
;
4106 default_breakpoint_symtab
= symtab
;
4107 default_breakpoint_line
= line
;
4110 /* Return true iff it is meaningful to use the address member of
4111 BPT. For some breakpoint types, the address member is irrelevant
4112 and it makes no sense to attempt to compare it to other addresses
4113 (or use it for any other purpose either).
4115 More specifically, each of the following breakpoint types will always
4116 have a zero valued address and we don't want check_duplicates() to mark
4117 breakpoints of any of these types to be a duplicate of an actual
4118 breakpoint at address zero:
4121 bp_hardware_watchpoint
4123 bp_access_watchpoint
4128 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4130 enum bptype type
= bpt
->type
;
4132 return (type
!= bp_watchpoint
4133 && type
!= bp_hardware_watchpoint
4134 && type
!= bp_read_watchpoint
4135 && type
!= bp_access_watchpoint
4136 && type
!= bp_catchpoint
4137 && type
!= bp_catch_exec
);
4140 /* Rescan breakpoints at the same address and section as BPT,
4141 marking the first one as "first" and any others as "duplicates".
4142 This is so that the bpt instruction is only inserted once.
4143 If we have a permanent breakpoint at the same place as BPT, make
4144 that one the official one, and the rest as duplicates. */
4147 check_duplicates_for (CORE_ADDR address
, struct obj_section
*section
)
4149 struct bp_location
*b
;
4151 struct bp_location
*perm_bp
= 0;
4153 ALL_BP_LOCATIONS (b
)
4154 if (b
->owner
->enable_state
!= bp_disabled
4155 && b
->owner
->enable_state
!= bp_call_disabled
4157 && !b
->shlib_disabled
4158 && b
->address
== address
/* address / overlay match */
4159 && (!overlay_debugging
|| b
->section
== section
)
4160 && breakpoint_address_is_meaningful (b
->owner
))
4162 /* Have we found a permanent breakpoint? */
4163 if (b
->owner
->enable_state
== bp_permanent
)
4170 b
->duplicate
= count
> 1;
4173 /* If we found a permanent breakpoint at this address, go over the
4174 list again and declare all the other breakpoints there to be the
4178 perm_bp
->duplicate
= 0;
4180 /* Permanent breakpoint should always be inserted. */
4181 if (! perm_bp
->inserted
)
4182 internal_error (__FILE__
, __LINE__
,
4183 _("allegedly permanent breakpoint is not "
4184 "actually inserted"));
4186 ALL_BP_LOCATIONS (b
)
4189 if (b
->owner
->enable_state
!= bp_disabled
4190 && b
->owner
->enable_state
!= bp_call_disabled
4191 && b
->enabled
&& !b
->shlib_disabled
4192 && b
->address
== address
/* address / overlay match */
4193 && (!overlay_debugging
|| b
->section
== section
)
4194 && breakpoint_address_is_meaningful (b
->owner
))
4197 internal_error (__FILE__
, __LINE__
,
4198 _("another breakpoint was inserted on top of "
4199 "a permanent breakpoint"));
4208 check_duplicates (struct breakpoint
*bpt
)
4210 struct bp_location
*bl
= bpt
->loc
;
4212 if (! breakpoint_address_is_meaningful (bpt
))
4215 for (; bl
; bl
= bl
->next
)
4216 check_duplicates_for (bl
->address
, bl
->section
);
4220 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4221 int bnum
, int have_bnum
)
4226 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4227 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4229 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4230 bnum
, astr1
, astr2
);
4232 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4235 /* Adjust a breakpoint's address to account for architectural constraints
4236 on breakpoint placement. Return the adjusted address. Note: Very
4237 few targets require this kind of adjustment. For most targets,
4238 this function is simply the identity function. */
4241 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4243 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4245 /* Very few targets need any kind of breakpoint adjustment. */
4248 else if (bptype
== bp_watchpoint
4249 || bptype
== bp_hardware_watchpoint
4250 || bptype
== bp_read_watchpoint
4251 || bptype
== bp_access_watchpoint
4252 || bptype
== bp_catchpoint
4253 || bptype
== bp_catch_exec
)
4255 /* Watchpoints and the various bp_catch_* eventpoints should not
4256 have their addresses modified. */
4261 CORE_ADDR adjusted_bpaddr
;
4263 /* Some targets have architectural constraints on the placement
4264 of breakpoint instructions. Obtain the adjusted address. */
4265 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4268 /* An adjusted breakpoint address can significantly alter
4269 a user's expectations. Print a warning if an adjustment
4271 if (adjusted_bpaddr
!= bpaddr
)
4272 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4274 return adjusted_bpaddr
;
4278 /* Allocate a struct bp_location. */
4280 static struct bp_location
*
4281 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4283 struct bp_location
*loc
, *loc_p
;
4285 loc
= xmalloc (sizeof (struct bp_location
));
4286 memset (loc
, 0, sizeof (*loc
));
4290 loc
->shlib_disabled
= 0;
4299 case bp_longjmp_resume
:
4300 case bp_step_resume
:
4301 case bp_watchpoint_scope
:
4303 case bp_shlib_event
:
4304 case bp_thread_event
:
4305 case bp_overlay_event
:
4307 case bp_catch_unload
:
4308 loc
->loc_type
= bp_loc_software_breakpoint
;
4310 case bp_hardware_breakpoint
:
4311 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4313 case bp_hardware_watchpoint
:
4314 case bp_read_watchpoint
:
4315 case bp_access_watchpoint
:
4316 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4321 loc
->loc_type
= bp_loc_other
;
4324 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4330 static void free_bp_location (struct bp_location
*loc
)
4335 if (loc
->function_name
)
4336 xfree (loc
->function_name
);
4341 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4342 that has type BPTYPE and has no locations as yet. */
4344 static struct breakpoint
*
4345 set_raw_breakpoint_without_location (enum bptype bptype
)
4347 struct breakpoint
*b
, *b1
;
4349 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4350 memset (b
, 0, sizeof (*b
));
4353 b
->language
= current_language
->la_language
;
4354 b
->input_radix
= input_radix
;
4356 b
->enable_state
= bp_enabled
;
4359 b
->ignore_count
= 0;
4361 b
->frame_id
= null_frame_id
;
4362 b
->dll_pathname
= NULL
;
4363 b
->triggered_dll_pathname
= NULL
;
4364 b
->forked_inferior_pid
= null_ptid
;
4365 b
->exec_pathname
= NULL
;
4367 b
->condition_not_parsed
= 0;
4369 /* Add this breakpoint to the end of the chain
4370 so that a list of breakpoints will come out in order
4371 of increasing numbers. */
4373 b1
= breakpoint_chain
;
4375 breakpoint_chain
= b
;
4385 /* Initialize loc->function_name. */
4387 set_breakpoint_location_function (struct bp_location
*loc
)
4389 if (loc
->owner
->type
== bp_breakpoint
4390 || loc
->owner
->type
== bp_hardware_breakpoint
)
4392 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4394 if (loc
->function_name
)
4395 loc
->function_name
= xstrdup (loc
->function_name
);
4399 /* set_raw_breakpoint is a low level routine for allocating and
4400 partially initializing a breakpoint of type BPTYPE. The newly
4401 created breakpoint's address, section, source file name, and line
4402 number are provided by SAL. The newly created and partially
4403 initialized breakpoint is added to the breakpoint chain and
4404 is also returned as the value of this function.
4406 It is expected that the caller will complete the initialization of
4407 the newly created breakpoint struct as well as output any status
4408 information regarding the creation of a new breakpoint. In
4409 particular, set_raw_breakpoint does NOT set the breakpoint
4410 number! Care should be taken to not allow an error to occur
4411 prior to completing the initialization of the breakpoint. If this
4412 should happen, a bogus breakpoint will be left on the chain. */
4415 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4417 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4418 CORE_ADDR adjusted_address
;
4420 /* Adjust the breakpoint's address prior to allocating a location.
4421 Once we call allocate_bp_location(), that mostly uninitialized
4422 location will be placed on the location chain. Adjustment of the
4423 breakpoint may cause target_read_memory() to be called and we do
4424 not want its scan of the location chain to find a breakpoint and
4425 location that's only been partially initialized. */
4426 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4428 b
->loc
= allocate_bp_location (b
, bptype
);
4429 b
->loc
->requested_address
= sal
.pc
;
4430 b
->loc
->address
= adjusted_address
;
4432 if (sal
.symtab
== NULL
)
4433 b
->source_file
= NULL
;
4435 b
->source_file
= savestring (sal
.symtab
->filename
,
4436 strlen (sal
.symtab
->filename
));
4437 b
->loc
->section
= sal
.section
;
4438 b
->line_number
= sal
.line
;
4440 set_breakpoint_location_function (b
->loc
);
4442 breakpoints_changed ();
4448 /* Note that the breakpoint object B describes a permanent breakpoint
4449 instruction, hard-wired into the inferior's code. */
4451 make_breakpoint_permanent (struct breakpoint
*b
)
4453 struct bp_location
*bl
;
4454 b
->enable_state
= bp_permanent
;
4456 /* By definition, permanent breakpoints are already present in the code.
4457 Mark all locations as inserted. For now, make_breakpoint_permanent
4458 is called in just one place, so it's hard to say if it's reasonable
4459 to have permanent breakpoint with multiple locations or not,
4460 but it's easy to implmement. */
4461 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4465 static struct breakpoint
*
4466 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4468 static int internal_breakpoint_number
= -1;
4469 struct symtab_and_line sal
;
4470 struct breakpoint
*b
;
4472 init_sal (&sal
); /* initialize to zeroes */
4475 sal
.section
= find_pc_overlay (sal
.pc
);
4477 b
= set_raw_breakpoint (sal
, type
);
4478 b
->number
= internal_breakpoint_number
--;
4479 b
->disposition
= disp_donttouch
;
4486 create_longjmp_breakpoint (char *func_name
)
4488 struct minimal_symbol
*m
;
4490 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4492 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4493 update_global_location_list (1);
4496 /* Call this routine when stepping and nexting to enable a breakpoint
4497 if we do a longjmp(). When we hit that breakpoint, call
4498 set_longjmp_resume_breakpoint() to figure out where we are going. */
4501 set_longjmp_breakpoint (void)
4503 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4505 create_longjmp_breakpoint ("longjmp");
4506 create_longjmp_breakpoint ("_longjmp");
4507 create_longjmp_breakpoint ("siglongjmp");
4508 create_longjmp_breakpoint ("_siglongjmp");
4512 /* Delete all longjmp breakpoints from THREAD. */
4514 delete_longjmp_breakpoint (int thread
)
4516 struct breakpoint
*b
, *temp
;
4518 ALL_BREAKPOINTS_SAFE (b
, temp
)
4519 if (b
->type
== bp_longjmp
)
4521 if (b
->thread
== thread
)
4522 delete_breakpoint (b
);
4527 create_overlay_event_breakpoint_1 (char *func_name
, struct objfile
*objfile
)
4529 struct breakpoint
*b
;
4530 struct minimal_symbol
*m
;
4532 if ((m
= lookup_minimal_symbol_text (func_name
, objfile
)) == NULL
)
4535 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4537 b
->addr_string
= xstrdup (func_name
);
4539 if (overlay_debugging
== ovly_auto
)
4541 b
->enable_state
= bp_enabled
;
4542 overlay_events_enabled
= 1;
4546 b
->enable_state
= bp_disabled
;
4547 overlay_events_enabled
= 0;
4549 update_global_location_list (1);
4553 create_overlay_event_breakpoint (char *func_name
)
4555 struct objfile
*objfile
;
4556 ALL_OBJFILES (objfile
)
4557 create_overlay_event_breakpoint_1 (func_name
, objfile
);
4561 enable_overlay_breakpoints (void)
4563 struct breakpoint
*b
;
4566 if (b
->type
== bp_overlay_event
)
4568 b
->enable_state
= bp_enabled
;
4569 update_global_location_list (1);
4570 overlay_events_enabled
= 1;
4575 disable_overlay_breakpoints (void)
4577 struct breakpoint
*b
;
4580 if (b
->type
== bp_overlay_event
)
4582 b
->enable_state
= bp_disabled
;
4583 update_global_location_list (0);
4584 overlay_events_enabled
= 0;
4589 create_thread_event_breakpoint (CORE_ADDR address
)
4591 struct breakpoint
*b
;
4593 b
= create_internal_breakpoint (address
, bp_thread_event
);
4595 b
->enable_state
= bp_enabled
;
4596 /* addr_string has to be used or breakpoint_re_set will delete me. */
4597 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4599 update_global_location_list_nothrow (1);
4605 remove_thread_event_breakpoints (void)
4607 struct breakpoint
*b
, *temp
;
4609 ALL_BREAKPOINTS_SAFE (b
, temp
)
4610 if (b
->type
== bp_thread_event
)
4611 delete_breakpoint (b
);
4614 struct captured_parse_breakpoint_args
4617 struct symtabs_and_lines
*sals_p
;
4618 char ***addr_string_p
;
4622 struct lang_and_radix
4630 remove_solib_event_breakpoints (void)
4632 struct breakpoint
*b
, *temp
;
4634 ALL_BREAKPOINTS_SAFE (b
, temp
)
4635 if (b
->type
== bp_shlib_event
)
4636 delete_breakpoint (b
);
4640 create_solib_event_breakpoint (CORE_ADDR address
)
4642 struct breakpoint
*b
;
4644 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4645 update_global_location_list_nothrow (1);
4649 /* Disable any breakpoints that are on code in shared libraries. Only
4650 apply to enabled breakpoints, disabled ones can just stay disabled. */
4653 disable_breakpoints_in_shlibs (void)
4655 struct bp_location
*loc
;
4656 int disabled_shlib_breaks
= 0;
4658 ALL_BP_LOCATIONS (loc
)
4660 struct breakpoint
*b
= loc
->owner
;
4661 /* We apply the check to all breakpoints, including disabled
4662 for those with loc->duplicate set. This is so that when breakpoint
4663 becomes enabled, or the duplicate is removed, gdb will try to insert
4664 all breakpoints. If we don't set shlib_disabled here, we'll try
4665 to insert those breakpoints and fail. */
4666 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4667 && !loc
->shlib_disabled
4669 && PC_SOLIB (loc
->address
)
4671 && solib_address (loc
->address
)
4675 loc
->shlib_disabled
= 1;
4680 /* Disable any breakpoints that are in in an unloaded shared library. Only
4681 apply to enabled breakpoints, disabled ones can just stay disabled. */
4684 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4686 struct bp_location
*loc
;
4687 int disabled_shlib_breaks
= 0;
4689 ALL_BP_LOCATIONS (loc
)
4691 struct breakpoint
*b
= loc
->owner
;
4692 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4693 || loc
->loc_type
== bp_loc_software_breakpoint
)
4694 && !loc
->shlib_disabled
)
4697 char *so_name
= PC_SOLIB (loc
->address
);
4699 char *so_name
= solib_address (loc
->address
);
4701 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4703 loc
->shlib_disabled
= 1;
4704 /* At this point, we cannot rely on remove_breakpoint
4705 succeeding so we must mark the breakpoint as not inserted
4706 to prevent future errors occurring in remove_breakpoints. */
4708 if (!disabled_shlib_breaks
)
4710 target_terminal_ours_for_output ();
4711 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4714 disabled_shlib_breaks
= 1;
4720 /* FORK & VFORK catchpoints. */
4722 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4725 insert_catch_fork (struct breakpoint
*b
)
4727 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
4730 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4733 remove_catch_fork (struct breakpoint
*b
)
4735 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
4738 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
4742 breakpoint_hit_catch_fork (struct breakpoint
*b
)
4744 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
4747 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4749 static enum print_stop_action
4750 print_it_catch_fork (struct breakpoint
*b
)
4752 annotate_catchpoint (b
->number
);
4753 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4754 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4755 return PRINT_SRC_AND_LOC
;
4758 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4761 print_one_catch_fork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4763 /* Field 4, the address, is omitted (which makes the columns
4764 not line up too nicely with the headers, but the effect
4765 is relatively readable). */
4767 ui_out_field_skip (uiout
, "addr");
4769 ui_out_text (uiout
, "fork");
4770 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4772 ui_out_text (uiout
, ", process ");
4773 ui_out_field_int (uiout
, "what",
4774 ptid_get_pid (b
->forked_inferior_pid
));
4775 ui_out_spaces (uiout
, 1);
4779 /* Implement the "print_mention" breakpoint_ops method for fork
4783 print_mention_catch_fork (struct breakpoint
*b
)
4785 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
4788 /* The breakpoint_ops structure to be used in fork catchpoints. */
4790 static struct breakpoint_ops catch_fork_breakpoint_ops
=
4794 breakpoint_hit_catch_fork
,
4795 print_it_catch_fork
,
4796 print_one_catch_fork
,
4797 print_mention_catch_fork
4800 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4803 insert_catch_vfork (struct breakpoint
*b
)
4805 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
4808 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4811 remove_catch_vfork (struct breakpoint
*b
)
4813 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
4816 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4820 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
4822 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
4825 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4827 static enum print_stop_action
4828 print_it_catch_vfork (struct breakpoint
*b
)
4830 annotate_catchpoint (b
->number
);
4831 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4832 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
4833 return PRINT_SRC_AND_LOC
;
4836 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4839 print_one_catch_vfork (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
4841 /* Field 4, the address, is omitted (which makes the columns
4842 not line up too nicely with the headers, but the effect
4843 is relatively readable). */
4845 ui_out_field_skip (uiout
, "addr");
4847 ui_out_text (uiout
, "vfork");
4848 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
4850 ui_out_text (uiout
, ", process ");
4851 ui_out_field_int (uiout
, "what",
4852 ptid_get_pid (b
->forked_inferior_pid
));
4853 ui_out_spaces (uiout
, 1);
4857 /* Implement the "print_mention" breakpoint_ops method for vfork
4861 print_mention_catch_vfork (struct breakpoint
*b
)
4863 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
4866 /* The breakpoint_ops structure to be used in vfork catchpoints. */
4868 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
4872 breakpoint_hit_catch_vfork
,
4873 print_it_catch_vfork
,
4874 print_one_catch_vfork
,
4875 print_mention_catch_vfork
4878 /* Create a new breakpoint of the bp_catchpoint kind and return it.
4880 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4881 If COND_STRING is not NULL, then store it in the breakpoint.
4882 OPS, if not NULL, is the breakpoint_ops structure associated
4883 to the catchpoint. */
4885 static struct breakpoint
*
4886 create_catchpoint (int tempflag
, char *cond_string
,
4887 struct breakpoint_ops
*ops
)
4889 struct symtab_and_line sal
;
4890 struct breakpoint
*b
;
4897 b
= set_raw_breakpoint (sal
, bp_catchpoint
);
4898 set_breakpoint_count (breakpoint_count
+ 1);
4899 b
->number
= breakpoint_count
;
4901 b
->cond_string
= (cond_string
== NULL
) ?
4902 NULL
: savestring (cond_string
, strlen (cond_string
));
4904 b
->addr_string
= NULL
;
4905 b
->enable_state
= bp_enabled
;
4906 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4910 update_global_location_list (1);
4916 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4917 struct breakpoint_ops
*ops
)
4919 struct breakpoint
*b
= create_catchpoint (tempflag
, cond_string
, ops
);
4921 /* FIXME: We should put this information in a breakpoint private data
4923 b
->forked_inferior_pid
= null_ptid
;
4927 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4929 struct symtab_and_line sal
;
4930 struct breakpoint
*b
;
4931 int thread
= -1; /* All threads. */
4938 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4939 set_breakpoint_count (breakpoint_count
+ 1);
4940 b
->number
= breakpoint_count
;
4941 b
->cond_string
= (cond_string
== NULL
) ?
4942 NULL
: savestring (cond_string
, strlen (cond_string
));
4944 b
->addr_string
= NULL
;
4945 b
->enable_state
= bp_enabled
;
4946 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4947 update_global_location_list (1);
4953 hw_breakpoint_used_count (void)
4955 struct breakpoint
*b
;
4960 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
4968 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4970 struct breakpoint
*b
;
4973 *other_type_used
= 0;
4976 if (breakpoint_enabled (b
))
4978 if (b
->type
== type
)
4980 else if ((b
->type
== bp_hardware_watchpoint
||
4981 b
->type
== bp_read_watchpoint
||
4982 b
->type
== bp_access_watchpoint
))
4983 *other_type_used
= 1;
4990 disable_watchpoints_before_interactive_call_start (void)
4992 struct breakpoint
*b
;
4996 if (((b
->type
== bp_watchpoint
)
4997 || (b
->type
== bp_hardware_watchpoint
)
4998 || (b
->type
== bp_read_watchpoint
)
4999 || (b
->type
== bp_access_watchpoint
))
5000 && breakpoint_enabled (b
))
5002 b
->enable_state
= bp_call_disabled
;
5003 update_global_location_list (0);
5009 enable_watchpoints_after_interactive_call_stop (void)
5011 struct breakpoint
*b
;
5015 if (((b
->type
== bp_watchpoint
)
5016 || (b
->type
== bp_hardware_watchpoint
)
5017 || (b
->type
== bp_read_watchpoint
)
5018 || (b
->type
== bp_access_watchpoint
))
5019 && (b
->enable_state
== bp_call_disabled
))
5021 b
->enable_state
= bp_enabled
;
5022 update_global_location_list (1);
5028 /* Set a breakpoint that will evaporate an end of command
5029 at address specified by SAL.
5030 Restrict it to frame FRAME if FRAME is nonzero. */
5033 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
5036 struct breakpoint
*b
;
5037 b
= set_raw_breakpoint (sal
, type
);
5038 b
->enable_state
= bp_enabled
;
5039 b
->disposition
= disp_donttouch
;
5040 b
->frame_id
= frame_id
;
5042 /* If we're debugging a multi-threaded program, then we
5043 want momentary breakpoints to be active in only a
5044 single thread of control. */
5045 if (in_thread_list (inferior_ptid
))
5046 b
->thread
= pid_to_thread_id (inferior_ptid
);
5048 update_global_location_list_nothrow (1);
5054 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
5056 struct symtab_and_line sal
;
5058 sal
= find_pc_line (pc
, 0);
5060 sal
.section
= find_pc_overlay (pc
);
5061 sal
.explicit_pc
= 1;
5063 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
5067 /* Tell the user we have just set a breakpoint B. */
5070 mention (struct breakpoint
*b
)
5073 struct cleanup
*old_chain
, *ui_out_chain
;
5074 struct ui_stream
*stb
;
5076 stb
= ui_out_stream_new (uiout
);
5077 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
5079 /* FIXME: This is misplaced; mention() is called by things (like
5080 hitting a watchpoint) other than breakpoint creation. It should
5081 be possible to clean this up and at the same time replace the
5082 random calls to breakpoint_changed with this hook. */
5083 observer_notify_breakpoint_created (b
->number
);
5085 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
5086 b
->ops
->print_mention (b
);
5091 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
5094 ui_out_text (uiout
, "Watchpoint ");
5095 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5096 ui_out_field_int (uiout
, "number", b
->number
);
5097 ui_out_text (uiout
, ": ");
5098 print_expression (b
->exp
, stb
->stream
);
5099 ui_out_field_stream (uiout
, "exp", stb
);
5100 do_cleanups (ui_out_chain
);
5102 case bp_hardware_watchpoint
:
5103 ui_out_text (uiout
, "Hardware watchpoint ");
5104 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
5105 ui_out_field_int (uiout
, "number", b
->number
);
5106 ui_out_text (uiout
, ": ");
5107 print_expression (b
->exp
, stb
->stream
);
5108 ui_out_field_stream (uiout
, "exp", stb
);
5109 do_cleanups (ui_out_chain
);
5111 case bp_read_watchpoint
:
5112 ui_out_text (uiout
, "Hardware read watchpoint ");
5113 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
5114 ui_out_field_int (uiout
, "number", b
->number
);
5115 ui_out_text (uiout
, ": ");
5116 print_expression (b
->exp
, stb
->stream
);
5117 ui_out_field_stream (uiout
, "exp", stb
);
5118 do_cleanups (ui_out_chain
);
5120 case bp_access_watchpoint
:
5121 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
5122 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
5123 ui_out_field_int (uiout
, "number", b
->number
);
5124 ui_out_text (uiout
, ": ");
5125 print_expression (b
->exp
, stb
->stream
);
5126 ui_out_field_stream (uiout
, "exp", stb
);
5127 do_cleanups (ui_out_chain
);
5130 if (ui_out_is_mi_like_p (uiout
))
5135 if (b
->disposition
== disp_del
)
5136 printf_filtered (_("Temporary breakpoint"));
5138 printf_filtered (_("Breakpoint"));
5139 printf_filtered (_(" %d"), b
->number
);
5142 case bp_hardware_breakpoint
:
5143 if (ui_out_is_mi_like_p (uiout
))
5148 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
5152 case bp_catch_unload
:
5153 printf_filtered (_("Catchpoint %d (%s %s)"),
5155 (b
->type
== bp_catch_load
) ? "load" : "unload",
5156 (b
->dll_pathname
!= NULL
) ?
5157 b
->dll_pathname
: "<any library>");
5160 printf_filtered (_("Catchpoint %d (exec)"),
5167 case bp_longjmp_resume
:
5168 case bp_step_resume
:
5170 case bp_watchpoint_scope
:
5171 case bp_shlib_event
:
5172 case bp_thread_event
:
5173 case bp_overlay_event
:
5179 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5183 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5187 if (addressprint
|| b
->source_file
== NULL
)
5189 printf_filtered (" at ");
5190 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5193 printf_filtered (": file %s, line %d.",
5194 b
->source_file
, b
->line_number
);
5198 struct bp_location
*loc
= b
->loc
;
5200 for (; loc
; loc
= loc
->next
)
5202 printf_filtered (" (%d locations)", n
);
5207 do_cleanups (old_chain
);
5208 if (ui_out_is_mi_like_p (uiout
))
5210 printf_filtered ("\n");
5214 static struct bp_location
*
5215 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5216 const struct symtab_and_line
*sal
)
5218 struct bp_location
*loc
, **tmp
;
5220 loc
= allocate_bp_location (b
, bptype
);
5221 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5224 loc
->requested_address
= sal
->pc
;
5225 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5227 loc
->section
= sal
->section
;
5229 set_breakpoint_location_function (loc
);
5234 /* Return 1 if LOC is pointing to a permanent breakpoint,
5235 return 0 otherwise. */
5238 bp_loc_is_permanent (struct bp_location
*loc
)
5242 const gdb_byte
*brk
;
5243 gdb_byte
*target_mem
;
5245 gdb_assert (loc
!= NULL
);
5247 addr
= loc
->address
;
5248 brk
= gdbarch_breakpoint_from_pc (current_gdbarch
, &addr
, &len
);
5250 target_mem
= alloca (len
);
5252 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
5253 && memcmp (target_mem
, brk
, len
) == 0)
5261 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5262 as textual description of the location, and COND_STRING
5263 as condition expression. */
5266 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5268 enum bptype type
, enum bpdisp disposition
,
5269 int thread
, int ignore_count
,
5270 struct breakpoint_ops
*ops
, int from_tty
)
5272 struct breakpoint
*b
= NULL
;
5275 if (type
== bp_hardware_breakpoint
)
5277 int i
= hw_breakpoint_used_count ();
5278 int target_resources_ok
=
5279 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5281 if (target_resources_ok
== 0)
5282 error (_("No hardware breakpoint support in the target."));
5283 else if (target_resources_ok
< 0)
5284 error (_("Hardware breakpoints used exceeds limit."));
5287 for (i
= 0; i
< sals
.nelts
; ++i
)
5289 struct symtab_and_line sal
= sals
.sals
[i
];
5290 struct bp_location
*loc
;
5293 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5297 b
= set_raw_breakpoint (sal
, type
);
5298 set_breakpoint_count (breakpoint_count
+ 1);
5299 b
->number
= breakpoint_count
;
5302 b
->cond_string
= cond_string
;
5303 b
->ignore_count
= ignore_count
;
5304 b
->enable_state
= bp_enabled
;
5305 b
->disposition
= disposition
;
5311 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5314 if (bp_loc_is_permanent (loc
))
5315 make_breakpoint_permanent (b
);
5319 char *arg
= b
->cond_string
;
5320 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5322 error (_("Garbage %s follows condition"), arg
);
5327 b
->addr_string
= addr_string
;
5329 /* addr_string has to be used or breakpoint_re_set will delete
5331 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5337 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5338 elements to fill the void space. */
5339 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5341 int i
= index_to_remove
+1;
5342 int last_index
= sal
->nelts
-1;
5344 for (;i
<= last_index
; ++i
)
5345 sal
->sals
[i
-1] = sal
->sals
[i
];
5350 /* If appropriate, obtains all sals that correspond
5351 to the same file and line as SAL. This is done
5352 only if SAL does not have explicit PC and has
5353 line and file information. If we got just a single
5354 expanded sal, return the original.
5356 Otherwise, if SAL.explicit_line is not set, filter out
5357 all sals for which the name of enclosing function
5358 is different from SAL. This makes sure that if we have
5359 breakpoint originally set in template instantiation, say
5360 foo<int>(), we won't expand SAL to locations at the same
5361 line in all existing instantiations of 'foo'.
5364 struct symtabs_and_lines
5365 expand_line_sal_maybe (struct symtab_and_line sal
)
5367 struct symtabs_and_lines expanded
;
5368 CORE_ADDR original_pc
= sal
.pc
;
5369 char *original_function
= NULL
;
5373 /* If we have explicit pc, don't expand.
5374 If we have no line number, we can't expand. */
5375 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5378 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5379 expanded
.sals
[0] = sal
;
5384 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5386 expanded
= expand_line_sal (sal
);
5387 if (expanded
.nelts
== 1)
5389 /* We had one sal, we got one sal. Without futher
5390 processing, just return the original sal. */
5391 xfree (expanded
.sals
);
5393 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5394 sal
.pc
= original_pc
;
5395 expanded
.sals
[0] = sal
;
5399 if (!sal
.explicit_line
)
5401 CORE_ADDR func_addr
, func_end
;
5402 for (i
= 0; i
< expanded
.nelts
; ++i
)
5404 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5405 char *this_function
;
5406 if (find_pc_partial_function (pc
, &this_function
,
5407 &func_addr
, &func_end
))
5409 if (this_function
&&
5410 strcmp (this_function
, original_function
) != 0)
5412 remove_sal (&expanded
, i
);
5415 else if (func_addr
== pc
)
5417 /* We're at beginning of a function, and should
5419 struct symbol
*sym
= find_pc_function (pc
);
5421 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5424 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5431 if (expanded
.nelts
<= 1)
5433 /* This is un ugly workaround. If we get zero
5434 expanded sals then something is really wrong.
5435 Fix that by returnign the original sal. */
5436 xfree (expanded
.sals
);
5438 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5439 sal
.pc
= original_pc
;
5440 expanded
.sals
[0] = sal
;
5447 for (i
= 0; i
< expanded
.nelts
; ++i
)
5448 if (expanded
.sals
[i
].pc
== original_pc
)
5459 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5460 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5461 value. COND_STRING, if not NULL, specified the condition to be
5462 used for all breakpoints. Essentially the only case where
5463 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5464 function. In that case, it's still not possible to specify
5465 separate conditions for different overloaded functions, so
5466 we take just a single condition string.
5468 NOTE: If the function succeeds, the caller is expected to cleanup
5469 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5470 array contents). If the function fails (error() is called), the
5471 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5472 COND and SALS arrays and each of those arrays contents. */
5475 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5477 enum bptype type
, enum bpdisp disposition
,
5478 int thread
, int ignore_count
,
5479 struct breakpoint_ops
*ops
, int from_tty
)
5482 for (i
= 0; i
< sals
.nelts
; ++i
)
5484 struct symtabs_and_lines expanded
=
5485 expand_line_sal_maybe (sals
.sals
[i
]);
5487 create_breakpoint (expanded
, addr_string
[i
],
5488 cond_string
, type
, disposition
,
5489 thread
, ignore_count
, ops
, from_tty
);
5492 update_global_location_list (1);
5495 /* Parse ARG which is assumed to be a SAL specification possibly
5496 followed by conditionals. On return, SALS contains an array of SAL
5497 addresses found. ADDR_STRING contains a vector of (canonical)
5498 address strings. ARG points to the end of the SAL. */
5501 parse_breakpoint_sals (char **address
,
5502 struct symtabs_and_lines
*sals
,
5503 char ***addr_string
,
5506 char *addr_start
= *address
;
5507 *addr_string
= NULL
;
5508 /* If no arg given, or if first arg is 'if ', use the default
5510 if ((*address
) == NULL
5511 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5513 if (default_breakpoint_valid
)
5515 struct symtab_and_line sal
;
5516 init_sal (&sal
); /* initialize to zeroes */
5517 sals
->sals
= (struct symtab_and_line
*)
5518 xmalloc (sizeof (struct symtab_and_line
));
5519 sal
.pc
= default_breakpoint_address
;
5520 sal
.line
= default_breakpoint_line
;
5521 sal
.symtab
= default_breakpoint_symtab
;
5522 sal
.section
= find_pc_overlay (sal
.pc
);
5523 sals
->sals
[0] = sal
;
5527 error (_("No default breakpoint address now."));
5531 /* Force almost all breakpoints to be in terms of the
5532 current_source_symtab (which is decode_line_1's default). This
5533 should produce the results we want almost all of the time while
5534 leaving default_breakpoint_* alone.
5535 ObjC: However, don't match an Objective-C method name which
5536 may have a '+' or '-' succeeded by a '[' */
5538 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5540 if (default_breakpoint_valid
5542 || ((strchr ("+-", (*address
)[0]) != NULL
)
5543 && ((*address
)[1] != '['))))
5544 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5545 default_breakpoint_line
, addr_string
,
5548 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5549 addr_string
, not_found_ptr
);
5551 /* For any SAL that didn't have a canonical string, fill one in. */
5552 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5553 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5554 if (addr_start
!= (*address
))
5557 for (i
= 0; i
< sals
->nelts
; i
++)
5559 /* Add the string if not present. */
5560 if ((*addr_string
)[i
] == NULL
)
5561 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5567 /* Convert each SAL into a real PC. Verify that the PC can be
5568 inserted as a breakpoint. If it can't throw an error. */
5571 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5575 for (i
= 0; i
< sals
->nelts
; i
++)
5576 resolve_sal_pc (&sals
->sals
[i
]);
5580 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5582 struct captured_parse_breakpoint_args
*args
= data
;
5584 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5585 args
->not_found_ptr
);
5588 /* Given TOK, a string specification of condition and thread, as
5589 accepted by the 'break' command, extract the condition
5590 string and thread number and set *COND_STRING and *THREAD.
5591 PC identifies the context at which the condition should be parsed.
5592 If no condition is found, *COND_STRING is set to NULL.
5593 If no thread is found, *THREAD is set to -1. */
5595 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5596 char **cond_string
, int *thread
)
5598 *cond_string
= NULL
;
5604 char *cond_start
= NULL
;
5605 char *cond_end
= NULL
;
5606 while (*tok
== ' ' || *tok
== '\t')
5611 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5614 toklen
= end_tok
- tok
;
5616 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5618 tok
= cond_start
= end_tok
+ 1;
5619 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5621 *cond_string
= savestring (cond_start
,
5622 cond_end
- cond_start
);
5624 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5630 *thread
= strtol (tok
, &tok
, 0);
5632 error (_("Junk after thread keyword."));
5633 if (!valid_thread_id (*thread
))
5634 error (_("Unknown thread %d."), *thread
);
5637 error (_("Junk at end of arguments."));
5641 /* Set a breakpoint. This function is shared between
5642 CLI and MI functions for setting a breakpoint.
5643 This function has two major modes of operations,
5644 selected by the PARSE_CONDITION_AND_THREAD parameter.
5645 If non-zero, the function will parse arg, extracting
5646 breakpoint location, address and thread. Otherwise,
5647 ARG is just the location of breakpoint, with condition
5648 and thread specified by the COND_STRING and THREAD
5652 break_command_really (char *arg
, char *cond_string
, int thread
,
5653 int parse_condition_and_thread
,
5654 int tempflag
, int hardwareflag
,
5656 enum auto_boolean pending_break_support
,
5657 struct breakpoint_ops
*ops
,
5660 struct gdb_exception e
;
5661 struct symtabs_and_lines sals
;
5662 struct symtab_and_line pending_sal
;
5665 char *addr_start
= arg
;
5667 struct cleanup
*old_chain
;
5668 struct cleanup
*breakpoint_chain
= NULL
;
5669 struct captured_parse_breakpoint_args parse_args
;
5678 parse_args
.arg_p
= &arg
;
5679 parse_args
.sals_p
= &sals
;
5680 parse_args
.addr_string_p
= &addr_string
;
5681 parse_args
.not_found_ptr
= ¬_found
;
5683 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5684 &parse_args
, RETURN_MASK_ALL
);
5686 /* If caller is interested in rc value from parse, set value. */
5690 throw_exception (e
);
5694 case NOT_FOUND_ERROR
:
5696 /* If pending breakpoint support is turned off, throw
5699 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5700 throw_exception (e
);
5702 exception_print (gdb_stderr
, e
);
5704 /* If pending breakpoint support is auto query and the user
5705 selects no, then simply return the error code. */
5706 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5707 !nquery ("Make breakpoint pending on future shared library load? "))
5710 /* At this point, either the user was queried about setting
5711 a pending breakpoint and selected yes, or pending
5712 breakpoint behavior is on and thus a pending breakpoint
5713 is defaulted on behalf of the user. */
5714 copy_arg
= xstrdup (addr_start
);
5715 addr_string
= ©_arg
;
5717 sals
.sals
= &pending_sal
;
5722 throw_exception (e
);
5729 /* Create a chain of things that always need to be cleaned up. */
5730 old_chain
= make_cleanup (null_cleanup
, 0);
5734 /* Make sure that all storage allocated to SALS gets freed. */
5735 make_cleanup (xfree
, sals
.sals
);
5737 /* Cleanup the addr_string array but not its contents. */
5738 make_cleanup (xfree
, addr_string
);
5741 /* ----------------------------- SNIP -----------------------------
5742 Anything added to the cleanup chain beyond this point is assumed
5743 to be part of a breakpoint. If the breakpoint create succeeds
5744 then the memory is not reclaimed. */
5745 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5747 /* Mark the contents of the addr_string for cleanup. These go on
5748 the breakpoint_chain and only occure if the breakpoint create
5750 for (i
= 0; i
< sals
.nelts
; i
++)
5752 if (addr_string
[i
] != NULL
)
5753 make_cleanup (xfree
, addr_string
[i
]);
5756 /* Resolve all line numbers to PC's and verify that the addresses
5757 are ok for the target. */
5759 breakpoint_sals_to_pc (&sals
, addr_start
);
5761 /* Verify that condition can be parsed, before setting any
5762 breakpoints. Allocate a separate condition expression for each
5766 if (parse_condition_and_thread
)
5768 /* Here we only parse 'arg' to separate condition
5769 from thread number, so parsing in context of first
5770 sal is OK. When setting the breakpoint we'll
5771 re-parse it in context of each sal. */
5774 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5776 make_cleanup (xfree
, cond_string
);
5780 /* Create a private copy of condition string. */
5783 cond_string
= xstrdup (cond_string
);
5784 make_cleanup (xfree
, cond_string
);
5787 create_breakpoints (sals
, addr_string
, cond_string
,
5788 hardwareflag
? bp_hardware_breakpoint
5790 tempflag
? disp_del
: disp_donttouch
,
5791 thread
, ignore_count
, ops
, from_tty
);
5795 struct symtab_and_line sal
= {0};
5796 struct breakpoint
*b
;
5798 make_cleanup (xfree
, copy_arg
);
5800 b
= set_raw_breakpoint_without_location (hardwareflag
5801 ? bp_hardware_breakpoint
5803 set_breakpoint_count (breakpoint_count
+ 1);
5804 b
->number
= breakpoint_count
;
5806 b
->addr_string
= addr_string
[0];
5807 b
->cond_string
= NULL
;
5808 b
->ignore_count
= ignore_count
;
5809 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5810 b
->condition_not_parsed
= 1;
5813 update_global_location_list (1);
5818 warning (_("Multiple breakpoints were set.\n"
5819 "Use the \"delete\" command to delete unwanted breakpoints."));
5820 /* That's it. Discard the cleanups for data inserted into the
5822 discard_cleanups (breakpoint_chain
);
5823 /* But cleanup everything else. */
5824 do_cleanups (old_chain
);
5827 /* Set a breakpoint.
5828 ARG is a string describing breakpoint address,
5829 condition, and thread.
5830 FLAG specifies if a breakpoint is hardware on,
5831 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5835 break_command_1 (char *arg
, int flag
, int from_tty
)
5837 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5838 int tempflag
= flag
& BP_TEMPFLAG
;
5840 break_command_really (arg
,
5841 NULL
, 0, 1 /* parse arg */,
5842 tempflag
, hardwareflag
,
5843 0 /* Ignore count */,
5844 pending_break_support
,
5845 NULL
/* breakpoint_ops */,
5851 set_breakpoint (char *address
, char *condition
,
5852 int hardwareflag
, int tempflag
,
5853 int thread
, int ignore_count
,
5856 break_command_really (address
, condition
, thread
,
5857 0 /* condition and thread are valid. */,
5858 tempflag
, hardwareflag
,
5861 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5865 /* Adjust SAL to the first instruction past the function prologue.
5866 The end of the prologue is determined using the line table from
5867 the debugging information.
5869 If SAL is already past the prologue, then do nothing. */
5872 skip_prologue_sal (struct symtab_and_line
*sal
)
5874 struct symbol
*sym
= find_pc_function (sal
->pc
);
5875 struct symtab_and_line start_sal
;
5880 start_sal
= find_function_start_sal (sym
, 1);
5881 if (sal
->pc
< start_sal
.pc
)
5885 /* Helper function for break_command_1 and disassemble_command. */
5888 resolve_sal_pc (struct symtab_and_line
*sal
)
5892 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5894 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5895 error (_("No line %d in file \"%s\"."),
5896 sal
->line
, sal
->symtab
->filename
);
5899 /* If this SAL corresponds to a breakpoint inserted using
5900 a line number, then skip the function prologue if necessary. */
5901 if (sal
->explicit_line
)
5902 skip_prologue_sal (sal
);
5905 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5907 struct blockvector
*bv
;
5911 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5914 sym
= block_linkage_function (b
);
5917 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5918 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
5922 /* It really is worthwhile to have the section, so we'll just
5923 have to look harder. This case can be executed if we have
5924 line numbers but no functions (as can happen in assembly
5927 struct minimal_symbol
*msym
;
5929 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5931 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
5938 break_command (char *arg
, int from_tty
)
5940 break_command_1 (arg
, 0, from_tty
);
5944 tbreak_command (char *arg
, int from_tty
)
5946 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5950 hbreak_command (char *arg
, int from_tty
)
5952 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5956 thbreak_command (char *arg
, int from_tty
)
5958 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5962 stop_command (char *arg
, int from_tty
)
5964 printf_filtered (_("Specify the type of breakpoint to set.\n\
5965 Usage: stop in <function | address>\n\
5966 stop at <line>\n"));
5970 stopin_command (char *arg
, int from_tty
)
5974 if (arg
== (char *) NULL
)
5976 else if (*arg
!= '*')
5981 /* look for a ':'. If this is a line number specification, then
5982 say it is bad, otherwise, it should be an address or
5983 function/method name */
5984 while (*argptr
&& !hasColon
)
5986 hasColon
= (*argptr
== ':');
5991 badInput
= (*argptr
!= ':'); /* Not a class::method */
5993 badInput
= isdigit (*arg
); /* a simple line number */
5997 printf_filtered (_("Usage: stop in <function | address>\n"));
5999 break_command_1 (arg
, 0, from_tty
);
6003 stopat_command (char *arg
, int from_tty
)
6007 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
6014 /* look for a ':'. If there is a '::' then get out, otherwise
6015 it is probably a line number. */
6016 while (*argptr
&& !hasColon
)
6018 hasColon
= (*argptr
== ':');
6023 badInput
= (*argptr
== ':'); /* we have class::method */
6025 badInput
= !isdigit (*arg
); /* not a line number */
6029 printf_filtered (_("Usage: stop at <line>\n"));
6031 break_command_1 (arg
, 0, from_tty
);
6034 /* accessflag: hw_write: watch write,
6035 hw_read: watch read,
6036 hw_access: watch access (read or write) */
6038 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
6040 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
6041 struct symtab_and_line sal
;
6042 struct expression
*exp
;
6043 struct block
*exp_valid_block
;
6044 struct value
*val
, *mark
;
6045 struct frame_info
*frame
;
6046 struct frame_info
*prev_frame
= NULL
;
6047 char *exp_start
= NULL
;
6048 char *exp_end
= NULL
;
6049 char *tok
, *id_tok_start
, *end_tok
;
6051 char *cond_start
= NULL
;
6052 char *cond_end
= NULL
;
6053 struct expression
*cond
= NULL
;
6054 int i
, other_type_used
, target_resources_ok
= 0;
6055 enum bptype bp_type
;
6059 init_sal (&sal
); /* initialize to zeroes */
6061 /* Make sure that we actually have parameters to parse. */
6062 if (arg
!= NULL
&& arg
[0] != '\0')
6064 toklen
= strlen (arg
); /* Size of argument list. */
6066 /* Points tok to the end of the argument list. */
6067 tok
= arg
+ toklen
- 1;
6069 /* Go backwards in the parameters list. Skip the last parameter.
6070 If we're expecting a 'thread <thread_num>' parameter, this should
6071 be the thread identifier. */
6072 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6074 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6077 /* Points end_tok to the beginning of the last token. */
6078 id_tok_start
= tok
+ 1;
6080 /* Go backwards in the parameters list. Skip one more parameter.
6081 If we're expecting a 'thread <thread_num>' parameter, we should
6082 reach a "thread" token. */
6083 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
6088 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
6091 /* Move the pointer forward to skip the whitespace and
6092 calculate the length of the token. */
6094 toklen
= end_tok
- tok
;
6096 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
6098 /* At this point we've found a "thread" token, which means
6099 the user is trying to set a watchpoint that triggers
6100 only in a specific thread. */
6103 /* Extract the thread ID from the next token. */
6104 thread
= strtol (id_tok_start
, &endp
, 0);
6106 /* Check if the user provided a valid numeric value for the
6108 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
6109 error (_("Invalid thread ID specification %s."), id_tok_start
);
6111 /* Check if the thread actually exists. */
6112 if (!valid_thread_id (thread
))
6113 error (_("Unknown thread %d."), thread
);
6115 /* Truncate the string and get rid of the thread <thread_num>
6116 parameter before the parameter list is parsed by the
6117 evaluate_expression() function. */
6122 /* Parse the rest of the arguments. */
6123 innermost_block
= NULL
;
6125 exp
= parse_exp_1 (&arg
, 0, 0);
6127 exp_valid_block
= innermost_block
;
6128 mark
= value_mark ();
6129 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
6131 release_value (val
);
6134 while (*tok
== ' ' || *tok
== '\t')
6138 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6141 toklen
= end_tok
- tok
;
6142 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
6144 tok
= cond_start
= end_tok
+ 1;
6145 cond
= parse_exp_1 (&tok
, 0, 0);
6149 error (_("Junk at end of command."));
6151 if (accessflag
== hw_read
)
6152 bp_type
= bp_read_watchpoint
;
6153 else if (accessflag
== hw_access
)
6154 bp_type
= bp_access_watchpoint
;
6156 bp_type
= bp_hardware_watchpoint
;
6158 mem_cnt
= can_use_hardware_watchpoint (val
);
6159 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
6160 error (_("Expression cannot be implemented with read/access watchpoint."));
6163 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
6164 target_resources_ok
=
6165 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
6167 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
6168 error (_("Target does not support this type of hardware watchpoint."));
6170 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
6171 error (_("Target can only support one kind of HW watchpoint at a time."));
6174 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6175 watchpoint could not be set. */
6176 if (!mem_cnt
|| target_resources_ok
<= 0)
6177 bp_type
= bp_watchpoint
;
6179 frame
= block_innermost_frame (exp_valid_block
);
6181 prev_frame
= get_prev_frame (frame
);
6185 /* If the expression is "local", then set up a "watchpoint scope"
6186 breakpoint at the point where we've left the scope of the watchpoint
6187 expression. Create the scope breakpoint before the watchpoint, so
6188 that we will encounter it first in bpstat_stop_status. */
6189 if (innermost_block
&& prev_frame
)
6191 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
6192 bp_watchpoint_scope
);
6194 scope_breakpoint
->enable_state
= bp_enabled
;
6196 /* Automatically delete the breakpoint when it hits. */
6197 scope_breakpoint
->disposition
= disp_del
;
6199 /* Only break in the proper frame (help with recursion). */
6200 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6202 /* Set the address at which we will stop. */
6203 scope_breakpoint
->loc
->requested_address
6204 = get_frame_pc (prev_frame
);
6205 scope_breakpoint
->loc
->address
6206 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6207 scope_breakpoint
->type
);
6210 /* Now set up the breakpoint. */
6211 b
= set_raw_breakpoint (sal
, bp_type
);
6212 set_breakpoint_count (breakpoint_count
+ 1);
6213 b
->number
= breakpoint_count
;
6215 b
->disposition
= disp_donttouch
;
6217 b
->exp_valid_block
= exp_valid_block
;
6218 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6221 b
->loc
->cond
= cond
;
6223 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6228 b
->watchpoint_frame
= get_frame_id (frame
);
6230 b
->watchpoint_frame
= null_frame_id
;
6232 if (scope_breakpoint
!= NULL
)
6234 /* The scope breakpoint is related to the watchpoint. We will
6235 need to act on them together. */
6236 b
->related_breakpoint
= scope_breakpoint
;
6237 scope_breakpoint
->related_breakpoint
= b
;
6240 value_free_to_mark (mark
);
6242 update_global_location_list (1);
6245 /* Return count of locations need to be watched and can be handled
6246 in hardware. If the watchpoint can not be handled
6247 in hardware return zero. */
6250 can_use_hardware_watchpoint (struct value
*v
)
6252 int found_memory_cnt
= 0;
6253 struct value
*head
= v
;
6255 /* Did the user specifically forbid us to use hardware watchpoints? */
6256 if (!can_use_hw_watchpoints
)
6259 /* Make sure that the value of the expression depends only upon
6260 memory contents, and values computed from them within GDB. If we
6261 find any register references or function calls, we can't use a
6262 hardware watchpoint.
6264 The idea here is that evaluating an expression generates a series
6265 of values, one holding the value of every subexpression. (The
6266 expression a*b+c has five subexpressions: a, b, a*b, c, and
6267 a*b+c.) GDB's values hold almost enough information to establish
6268 the criteria given above --- they identify memory lvalues,
6269 register lvalues, computed values, etcetera. So we can evaluate
6270 the expression, and then scan the chain of values that leaves
6271 behind to decide whether we can detect any possible change to the
6272 expression's final value using only hardware watchpoints.
6274 However, I don't think that the values returned by inferior
6275 function calls are special in any way. So this function may not
6276 notice that an expression involving an inferior function call
6277 can't be watched with hardware watchpoints. FIXME. */
6278 for (; v
; v
= value_next (v
))
6280 if (VALUE_LVAL (v
) == lval_memory
)
6283 /* A lazy memory lvalue is one that GDB never needed to fetch;
6284 we either just used its address (e.g., `a' in `a.b') or
6285 we never needed it at all (e.g., `a' in `a,b'). */
6289 /* Ahh, memory we actually used! Check if we can cover
6290 it with hardware watchpoints. */
6291 struct type
*vtype
= check_typedef (value_type (v
));
6293 /* We only watch structs and arrays if user asked for it
6294 explicitly, never if they just happen to appear in a
6295 middle of some value chain. */
6297 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6298 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6300 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6301 int len
= TYPE_LENGTH (value_type (v
));
6303 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6310 else if (VALUE_LVAL (v
) != not_lval
6311 && deprecated_value_modifiable (v
) == 0)
6312 return 0; /* ??? What does this represent? */
6313 else if (VALUE_LVAL (v
) == lval_register
)
6314 return 0; /* cannot watch a register with a HW watchpoint */
6317 /* The expression itself looks suitable for using a hardware
6318 watchpoint, but give the target machine a chance to reject it. */
6319 return found_memory_cnt
;
6323 watch_command_wrapper (char *arg
, int from_tty
)
6325 watch_command (arg
, from_tty
);
6329 watch_command (char *arg
, int from_tty
)
6331 watch_command_1 (arg
, hw_write
, from_tty
);
6335 rwatch_command_wrapper (char *arg
, int from_tty
)
6337 rwatch_command (arg
, from_tty
);
6341 rwatch_command (char *arg
, int from_tty
)
6343 watch_command_1 (arg
, hw_read
, from_tty
);
6347 awatch_command_wrapper (char *arg
, int from_tty
)
6349 awatch_command (arg
, from_tty
);
6353 awatch_command (char *arg
, int from_tty
)
6355 watch_command_1 (arg
, hw_access
, from_tty
);
6359 /* Helper routines for the until_command routine in infcmd.c. Here
6360 because it uses the mechanisms of breakpoints. */
6362 struct until_break_command_continuation_args
6364 struct breakpoint
*breakpoint
;
6365 struct breakpoint
*breakpoint2
;
6368 /* This function is called by fetch_inferior_event via the
6369 cmd_continuation pointer, to complete the until command. It takes
6370 care of cleaning up the temporary breakpoints set up by the until
6373 until_break_command_continuation (void *arg
)
6375 struct until_break_command_continuation_args
*a
= arg
;
6377 delete_breakpoint (a
->breakpoint
);
6379 delete_breakpoint (a
->breakpoint2
);
6383 until_break_command (char *arg
, int from_tty
, int anywhere
)
6385 struct symtabs_and_lines sals
;
6386 struct symtab_and_line sal
;
6387 struct frame_info
*frame
= get_selected_frame (NULL
);
6388 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6389 struct breakpoint
*breakpoint
;
6390 struct breakpoint
*breakpoint2
= NULL
;
6391 struct cleanup
*old_chain
;
6393 clear_proceed_status ();
6395 /* Set a breakpoint where the user wants it and at return from
6398 if (default_breakpoint_valid
)
6399 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6400 default_breakpoint_line
, (char ***) NULL
, NULL
);
6402 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6403 0, (char ***) NULL
, NULL
);
6405 if (sals
.nelts
!= 1)
6406 error (_("Couldn't get information on specified line."));
6409 xfree (sals
.sals
); /* malloc'd, so freed */
6412 error (_("Junk at end of arguments."));
6414 resolve_sal_pc (&sal
);
6417 /* If the user told us to continue until a specified location,
6418 we don't specify a frame at which we need to stop. */
6419 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6421 /* Otherwise, specify the current frame, because we want to stop only
6422 at the very same frame. */
6423 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6426 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6428 /* Keep within the current frame, or in frames called by the current
6432 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6433 sal
.pc
= get_frame_pc (prev_frame
);
6434 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6436 make_cleanup_delete_breakpoint (breakpoint2
);
6439 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6441 /* If we are running asynchronously, and proceed call above has actually
6442 managed to start the target, arrange for breakpoints to be
6443 deleted when the target stops. Otherwise, we're already stopped and
6444 delete breakpoints via cleanup chain. */
6446 if (target_can_async_p () && is_running (inferior_ptid
))
6448 struct until_break_command_continuation_args
*args
;
6449 args
= xmalloc (sizeof (*args
));
6451 args
->breakpoint
= breakpoint
;
6452 args
->breakpoint2
= breakpoint2
;
6454 discard_cleanups (old_chain
);
6455 add_continuation (inferior_thread (),
6456 until_break_command_continuation
, args
,
6460 do_cleanups (old_chain
);
6464 ep_skip_leading_whitespace (char **s
)
6466 if ((s
== NULL
) || (*s
== NULL
))
6468 while (isspace (**s
))
6472 /* This function attempts to parse an optional "if <cond>" clause
6473 from the arg string. If one is not found, it returns NULL.
6475 Else, it returns a pointer to the condition string. (It does not
6476 attempt to evaluate the string against a particular block.) And,
6477 it updates arg to point to the first character following the parsed
6478 if clause in the arg string. */
6481 ep_parse_optional_if_clause (char **arg
)
6485 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6488 /* Skip the "if" keyword. */
6491 /* Skip any extra leading whitespace, and record the start of the
6492 condition string. */
6493 ep_skip_leading_whitespace (arg
);
6496 /* Assume that the condition occupies the remainder of the arg string. */
6497 (*arg
) += strlen (cond_string
);
6502 /* This function attempts to parse an optional filename from the arg
6503 string. If one is not found, it returns NULL.
6505 Else, it returns a pointer to the parsed filename. (This function
6506 makes no attempt to verify that a file of that name exists, or is
6507 accessible.) And, it updates arg to point to the first character
6508 following the parsed filename in the arg string.
6510 Note that clients needing to preserve the returned filename for
6511 future access should copy it to their own buffers. */
6513 ep_parse_optional_filename (char **arg
)
6515 static char filename
[1024];
6520 if ((*arg_p
== '\0') || isspace (*arg_p
))
6538 /* Commands to deal with catching events, such as signals, exceptions,
6539 process start/exit, etc. */
6543 catch_fork_temporary
, catch_vfork_temporary
,
6544 catch_fork_permanent
, catch_vfork_permanent
6549 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6551 char *cond_string
= NULL
;
6552 catch_fork_kind fork_kind
;
6555 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6556 tempflag
= (fork_kind
== catch_fork_temporary
6557 || fork_kind
== catch_vfork_temporary
);
6561 ep_skip_leading_whitespace (&arg
);
6563 /* The allowed syntax is:
6565 catch [v]fork if <cond>
6567 First, check if there's an if clause. */
6568 cond_string
= ep_parse_optional_if_clause (&arg
);
6570 if ((*arg
!= '\0') && !isspace (*arg
))
6571 error (_("Junk at end of arguments."));
6573 /* If this target supports it, create a fork or vfork catchpoint
6574 and enable reporting of such events. */
6577 case catch_fork_temporary
:
6578 case catch_fork_permanent
:
6579 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6580 &catch_fork_breakpoint_ops
);
6582 case catch_vfork_temporary
:
6583 case catch_vfork_permanent
:
6584 create_fork_vfork_event_catchpoint (tempflag
, cond_string
,
6585 &catch_vfork_breakpoint_ops
);
6588 error (_("unsupported or unknown fork kind; cannot catch it"));
6594 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6597 char *cond_string
= NULL
;
6599 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6603 ep_skip_leading_whitespace (&arg
);
6605 /* The allowed syntax is:
6607 catch exec if <cond>
6609 First, check if there's an if clause. */
6610 cond_string
= ep_parse_optional_if_clause (&arg
);
6612 if ((*arg
!= '\0') && !isspace (*arg
))
6613 error (_("Junk at end of arguments."));
6615 /* If this target supports it, create an exec catchpoint
6616 and enable reporting of such events. */
6617 create_exec_event_catchpoint (tempflag
, cond_string
);
6621 catch_load_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6624 char *dll_pathname
= NULL
;
6625 char *cond_string
= NULL
;
6627 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6631 ep_skip_leading_whitespace (&arg
);
6633 /* The allowed syntax is:
6635 catch load if <cond>
6636 catch load <filename>
6637 catch load <filename> if <cond>
6639 The user is not allowed to specify the <filename> after an
6642 We'll ignore the pathological case of a file named "if".
6644 First, check if there's an if clause. If so, then there
6645 cannot be a filename. */
6646 cond_string
= ep_parse_optional_if_clause (&arg
);
6648 /* If there was an if clause, then there cannot be a filename.
6649 Else, there might be a filename and an if clause. */
6650 if (cond_string
== NULL
)
6652 dll_pathname
= ep_parse_optional_filename (&arg
);
6653 ep_skip_leading_whitespace (&arg
);
6654 cond_string
= ep_parse_optional_if_clause (&arg
);
6657 if ((*arg
!= '\0') && !isspace (*arg
))
6658 error (_("Junk at end of arguments."));
6660 /* Create a load breakpoint that only triggers when a load of
6661 the specified dll (or any dll, if no pathname was specified)
6663 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6664 dll_pathname
, cond_string
);
6668 catch_unload_command_1 (char *arg
, int from_tty
,
6669 struct cmd_list_element
*command
)
6672 char *dll_pathname
= NULL
;
6673 char *cond_string
= NULL
;
6675 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6679 ep_skip_leading_whitespace (&arg
);
6681 /* The allowed syntax is:
6683 catch unload if <cond>
6684 catch unload <filename>
6685 catch unload <filename> if <cond>
6687 The user is not allowed to specify the <filename> after an
6690 We'll ignore the pathological case of a file named "if".
6692 First, check if there's an if clause. If so, then there
6693 cannot be a filename. */
6694 cond_string
= ep_parse_optional_if_clause (&arg
);
6696 /* If there was an if clause, then there cannot be a filename.
6697 Else, there might be a filename and an if clause. */
6698 if (cond_string
== NULL
)
6700 dll_pathname
= ep_parse_optional_filename (&arg
);
6701 ep_skip_leading_whitespace (&arg
);
6702 cond_string
= ep_parse_optional_if_clause (&arg
);
6705 if ((*arg
!= '\0') && !isspace (*arg
))
6706 error (_("Junk at end of arguments."));
6708 /* Create an unload breakpoint that only triggers when an unload of
6709 the specified dll (or any dll, if no pathname was specified)
6711 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6712 dll_pathname
, cond_string
);
6715 static enum print_stop_action
6716 print_exception_catchpoint (struct breakpoint
*b
)
6718 int bp_temp
, bp_throw
;
6720 annotate_catchpoint (b
->number
);
6722 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6723 if (b
->loc
->address
!= b
->loc
->requested_address
)
6724 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6727 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6729 bp_temp
? "Temporary catchpoint "
6731 if (!ui_out_is_mi_like_p (uiout
))
6732 ui_out_field_int (uiout
, "bkptno", b
->number
);
6734 bp_throw
? " (exception thrown), "
6735 : " (exception caught), ");
6736 if (ui_out_is_mi_like_p (uiout
))
6738 ui_out_field_string (uiout
, "reason",
6739 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6740 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6741 ui_out_field_int (uiout
, "bkptno", b
->number
);
6743 return PRINT_SRC_AND_LOC
;
6747 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6752 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6753 ui_out_field_string (uiout
, "addr", "<PENDING>");
6755 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6759 *last_addr
= b
->loc
->address
;
6760 if (strstr (b
->addr_string
, "throw") != NULL
)
6761 ui_out_field_string (uiout
, "what", "exception throw");
6763 ui_out_field_string (uiout
, "what", "exception catch");
6767 print_mention_exception_catchpoint (struct breakpoint
*b
)
6772 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6773 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6774 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6775 : _("Catchpoint "));
6776 ui_out_field_int (uiout
, "bkptno", b
->number
);
6777 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6781 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6784 NULL
, /* breakpoint_hit */
6785 print_exception_catchpoint
,
6786 print_one_exception_catchpoint
,
6787 print_mention_exception_catchpoint
6791 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6792 enum exception_event_kind ex_event
, int from_tty
)
6794 char *trigger_func_name
;
6796 if (ex_event
== EX_EVENT_CATCH
)
6797 trigger_func_name
= "__cxa_begin_catch";
6799 trigger_func_name
= "__cxa_throw";
6801 break_command_really (trigger_func_name
, cond_string
, -1,
6802 0 /* condition and thread are valid. */,
6805 AUTO_BOOLEAN_TRUE
/* pending */,
6806 &gnu_v3_exception_catchpoint_ops
, from_tty
);
6811 /* Deal with "catch catch" and "catch throw" commands */
6814 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6815 int tempflag
, int from_tty
)
6817 char *cond_string
= NULL
;
6818 struct symtab_and_line
*sal
= NULL
;
6822 ep_skip_leading_whitespace (&arg
);
6824 cond_string
= ep_parse_optional_if_clause (&arg
);
6826 if ((*arg
!= '\0') && !isspace (*arg
))
6827 error (_("Junk at end of arguments."));
6829 if ((ex_event
!= EX_EVENT_THROW
) &&
6830 (ex_event
!= EX_EVENT_CATCH
))
6831 error (_("Unsupported or unknown exception event; cannot catch it"));
6833 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6836 warning (_("Unsupported with this platform/compiler combination."));
6839 /* Implementation of "catch catch" command. */
6842 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6844 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6845 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6848 /* Implementation of "catch throw" command. */
6851 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6853 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6854 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6857 /* Create a breakpoint struct for Ada exception catchpoints. */
6860 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6864 struct expression
*cond
,
6865 struct breakpoint_ops
*ops
,
6869 struct breakpoint
*b
;
6873 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6874 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6875 version for exception catchpoints, because two catchpoints
6876 used for different exception names will use the same address.
6877 In this case, a "breakpoint ... also set at..." warning is
6878 unproductive. Besides. the warning phrasing is also a bit
6879 inapropriate, we should use the word catchpoint, and tell
6880 the user what type of catchpoint it is. The above is good
6881 enough for now, though. */
6884 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6885 set_breakpoint_count (breakpoint_count
+ 1);
6887 b
->enable_state
= bp_enabled
;
6888 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6889 b
->number
= breakpoint_count
;
6890 b
->ignore_count
= 0;
6891 b
->loc
->cond
= cond
;
6892 b
->addr_string
= addr_string
;
6893 b
->language
= language_ada
;
6894 b
->cond_string
= cond_string
;
6895 b
->exp_string
= exp_string
;
6900 update_global_location_list (1);
6903 /* Implement the "catch exception" command. */
6906 catch_ada_exception_command (char *arg
, int from_tty
,
6907 struct cmd_list_element
*command
)
6910 struct symtab_and_line sal
;
6912 char *addr_string
= NULL
;
6913 char *exp_string
= NULL
;
6914 char *cond_string
= NULL
;
6915 struct expression
*cond
= NULL
;
6916 struct breakpoint_ops
*ops
= NULL
;
6918 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6922 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6923 &cond_string
, &cond
, &ops
);
6924 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6925 cond_string
, cond
, ops
, tempflag
,
6929 /* Implement the "catch assert" command. */
6932 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6935 struct symtab_and_line sal
;
6936 char *addr_string
= NULL
;
6937 struct breakpoint_ops
*ops
= NULL
;
6939 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6943 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6944 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6945 tempflag
, from_tty
);
6949 catch_command (char *arg
, int from_tty
)
6951 error (_("Catch requires an event name."));
6956 tcatch_command (char *arg
, int from_tty
)
6958 error (_("Catch requires an event name."));
6961 /* Delete breakpoints by address or line. */
6964 clear_command (char *arg
, int from_tty
)
6966 struct breakpoint
*b
;
6967 VEC(breakpoint_p
) *found
= 0;
6970 struct symtabs_and_lines sals
;
6971 struct symtab_and_line sal
;
6976 sals
= decode_line_spec (arg
, 1);
6981 sals
.sals
= (struct symtab_and_line
*)
6982 xmalloc (sizeof (struct symtab_and_line
));
6983 make_cleanup (xfree
, sals
.sals
);
6984 init_sal (&sal
); /* initialize to zeroes */
6985 sal
.line
= default_breakpoint_line
;
6986 sal
.symtab
= default_breakpoint_symtab
;
6987 sal
.pc
= default_breakpoint_address
;
6988 if (sal
.symtab
== 0)
6989 error (_("No source file specified."));
6997 /* We don't call resolve_sal_pc here. That's not
6998 as bad as it seems, because all existing breakpoints
6999 typically have both file/line and pc set. So, if
7000 clear is given file/line, we can match this to existing
7001 breakpoint without obtaining pc at all.
7003 We only support clearing given the address explicitly
7004 present in breakpoint table. Say, we've set breakpoint
7005 at file:line. There were several PC values for that file:line,
7006 due to optimization, all in one block.
7007 We've picked one PC value. If "clear" is issued with another
7008 PC corresponding to the same file:line, the breakpoint won't
7009 be cleared. We probably can still clear the breakpoint, but
7010 since the other PC value is never presented to user, user
7011 can only find it by guessing, and it does not seem important
7014 /* For each line spec given, delete bps which correspond
7015 to it. Do it in two passes, solely to preserve the current
7016 behavior that from_tty is forced true if we delete more than
7020 for (i
= 0; i
< sals
.nelts
; i
++)
7022 /* If exact pc given, clear bpts at that pc.
7023 If line given (pc == 0), clear all bpts on specified line.
7024 If defaulting, clear all bpts on default line
7027 defaulting sal.pc != 0 tests to do
7032 1 0 <can't happen> */
7036 /* Find all matching breakpoints and add them to
7041 /* Are we going to delete b? */
7042 if (b
->type
!= bp_none
7043 && b
->type
!= bp_watchpoint
7044 && b
->type
!= bp_hardware_watchpoint
7045 && b
->type
!= bp_read_watchpoint
7046 && b
->type
!= bp_access_watchpoint
)
7048 struct bp_location
*loc
= b
->loc
;
7049 for (; loc
; loc
= loc
->next
)
7051 int pc_match
= sal
.pc
7052 && (loc
->address
== sal
.pc
)
7053 && (!section_is_overlay (loc
->section
)
7054 || loc
->section
== sal
.section
);
7055 int line_match
= ((default_match
|| (0 == sal
.pc
))
7056 && b
->source_file
!= NULL
7057 && sal
.symtab
!= NULL
7058 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
7059 && b
->line_number
== sal
.line
);
7060 if (pc_match
|| line_match
)
7069 VEC_safe_push(breakpoint_p
, found
, b
);
7072 /* Now go thru the 'found' chain and delete them. */
7073 if (VEC_empty(breakpoint_p
, found
))
7076 error (_("No breakpoint at %s."), arg
);
7078 error (_("No breakpoint at this line."));
7081 if (VEC_length(breakpoint_p
, found
) > 1)
7082 from_tty
= 1; /* Always report if deleted more than one */
7085 if (VEC_length(breakpoint_p
, found
) == 1)
7086 printf_unfiltered (_("Deleted breakpoint "));
7088 printf_unfiltered (_("Deleted breakpoints "));
7090 breakpoints_changed ();
7092 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
7095 printf_unfiltered ("%d ", b
->number
);
7096 delete_breakpoint (b
);
7099 putchar_unfiltered ('\n');
7102 /* Delete breakpoint in BS if they are `delete' breakpoints and
7103 all breakpoints that are marked for deletion, whether hit or not.
7104 This is called after any breakpoint is hit, or after errors. */
7107 breakpoint_auto_delete (bpstat bs
)
7109 struct breakpoint
*b
, *temp
;
7111 for (; bs
; bs
= bs
->next
)
7112 if (bs
->breakpoint_at
7113 && bs
->breakpoint_at
->owner
7114 && bs
->breakpoint_at
->owner
->disposition
== disp_del
7116 delete_breakpoint (bs
->breakpoint_at
->owner
);
7118 ALL_BREAKPOINTS_SAFE (b
, temp
)
7120 if (b
->disposition
== disp_del_at_next_stop
)
7121 delete_breakpoint (b
);
7125 /* If SHOULD_INSERT is true, do not insert any breakpoint locations
7126 into the inferior, only remove already-inserted locations that no
7127 longer should be inserted. Functions that delete a breakpoint or
7128 breakpoints should pass false, so that deleting a breakpoint
7129 doesn't have the side effect of inserting the locations of other
7130 breakpoints that are marked not-inserted, but should_be_inserted
7131 returns true on them.
7133 This behaviour is useful is situations close to tear-down -- e.g.,
7134 after an exec, while the target still has execution, but breakpoint
7135 shadows of the previous executable image should *NOT* be restored
7136 to the new image; or before detaching, where the target still has
7137 execution and wants to delete breakpoints from GDB's lists, and all
7138 breakpoints had already been removed from the inferior. */
7141 update_global_location_list (int should_insert
)
7143 struct breakpoint
*b
;
7144 struct bp_location
**next
= &bp_location_chain
;
7145 struct bp_location
*loc
;
7146 struct bp_location
*loc2
;
7147 struct gdb_exception e
;
7148 VEC(bp_location_p
) *old_locations
= NULL
;
7152 /* Store old locations for future reference. */
7153 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
7154 VEC_safe_push (bp_location_p
, old_locations
, loc
);
7156 bp_location_chain
= NULL
;
7159 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
7162 next
= &(loc
->global_next
);
7167 /* Identify bp_location instances that are no longer present in the new
7168 list, and therefore should be freed. Note that it's not necessary that
7169 those locations should be removed from inferior -- if there's another
7170 location at the same address (previously marked as duplicate),
7171 we don't need to remove/insert the location. */
7172 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
7174 /* Tells if 'loc' is found amoung the new locations. If not, we
7176 int found_object
= 0;
7177 /* Tells if the location should remain inserted in the target. */
7178 int keep_in_target
= 0;
7180 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7187 /* If this location is no longer present, and inserted, look if there's
7188 maybe a new location at the same address. If so, mark that one
7189 inserted, and don't remove this one. This is needed so that we
7190 don't have a time window where a breakpoint at certain location is not
7195 /* If the location is inserted now, we might have to remove it. */
7197 if (found_object
&& should_be_inserted (loc
))
7199 /* The location is still present in the location list, and still
7200 should be inserted. Don't do anything. */
7205 /* The location is either no longer present, or got disabled.
7206 See if there's another location at the same address, in which
7207 case we don't need to remove this one from the target. */
7208 if (breakpoint_address_is_meaningful (loc
->owner
))
7209 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7211 /* For the sake of should_insert_location. The
7212 call to check_duplicates will fix up this later. */
7213 loc2
->duplicate
= 0;
7214 if (should_be_inserted (loc2
)
7215 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7218 loc2
->target_info
= loc
->target_info
;
7225 if (!keep_in_target
)
7227 if (remove_breakpoint (loc
, mark_uninserted
))
7229 /* This is just about all we can do. We could keep this
7230 location on the global list, and try to remove it next
7231 time, but there's no particular reason why we will
7234 Note that at this point, loc->owner is still valid,
7235 as delete_breakpoint frees the breakpoint only
7236 after calling us. */
7237 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7238 loc
->owner
->number
);
7246 if (removed
&& non_stop
)
7248 /* This location was removed from the targets. In non-stop mode,
7249 a race condition is possible where we've removed a breakpoint,
7250 but stop events for that breakpoint are already queued and will
7251 arrive later. To suppress spurious SIGTRAPs reported to user,
7252 we keep this breakpoint location for a bit, and will retire it
7253 after we see 3 * thread_count events.
7254 The theory here is that reporting of events should,
7255 "on the average", be fair, so after that many event we'll see
7256 events from all threads that have anything of interest, and no
7257 longer need to keep this breakpoint. This is just a
7258 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7259 which is usability issue, but not a correctness problem. */
7260 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7263 VEC_safe_push (bp_location_p
, moribund_locations
, loc
);
7266 free_bp_location (loc
);
7272 check_duplicates (b
);
7275 if (breakpoints_always_inserted_mode ()
7277 && target_has_execution
)
7278 insert_breakpoint_locations ();
7282 breakpoint_retire_moribund (void)
7284 struct bp_location
*loc
;
7287 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7288 if (--(loc
->events_till_retirement
) == 0)
7290 free_bp_location (loc
);
7291 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7297 update_global_location_list_nothrow (int inserting
)
7299 struct gdb_exception e
;
7300 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7301 update_global_location_list (inserting
);
7304 /* Clear BPT from a BPS. */
7306 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7309 for (bs
= bps
; bs
; bs
= bs
->next
)
7310 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7312 bs
->breakpoint_at
= NULL
;
7314 /* bs->commands will be freed later. */
7318 /* Callback for iterate_over_threads. */
7320 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7322 struct breakpoint
*bpt
= data
;
7323 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7327 /* Delete a breakpoint and clean up all traces of it in the data
7331 delete_breakpoint (struct breakpoint
*bpt
)
7333 struct breakpoint
*b
;
7334 struct bp_location
*loc
, *next
;
7336 gdb_assert (bpt
!= NULL
);
7338 /* Has this bp already been deleted? This can happen because multiple
7339 lists can hold pointers to bp's. bpstat lists are especial culprits.
7341 One example of this happening is a watchpoint's scope bp. When the
7342 scope bp triggers, we notice that the watchpoint is out of scope, and
7343 delete it. We also delete its scope bp. But the scope bp is marked
7344 "auto-deleting", and is already on a bpstat. That bpstat is then
7345 checked for auto-deleting bp's, which are deleted.
7347 A real solution to this problem might involve reference counts in bp's,
7348 and/or giving them pointers back to their referencing bpstat's, and
7349 teaching delete_breakpoint to only free a bp's storage when no more
7350 references were extent. A cheaper bandaid was chosen. */
7351 if (bpt
->type
== bp_none
)
7354 observer_notify_breakpoint_deleted (bpt
->number
);
7356 if (breakpoint_chain
== bpt
)
7357 breakpoint_chain
= bpt
->next
;
7362 b
->next
= bpt
->next
;
7366 free_command_lines (&bpt
->commands
);
7367 if (bpt
->cond_string
!= NULL
)
7368 xfree (bpt
->cond_string
);
7369 if (bpt
->addr_string
!= NULL
)
7370 xfree (bpt
->addr_string
);
7371 if (bpt
->exp
!= NULL
)
7373 if (bpt
->exp_string
!= NULL
)
7374 xfree (bpt
->exp_string
);
7375 if (bpt
->val
!= NULL
)
7376 value_free (bpt
->val
);
7377 if (bpt
->source_file
!= NULL
)
7378 xfree (bpt
->source_file
);
7379 if (bpt
->dll_pathname
!= NULL
)
7380 xfree (bpt
->dll_pathname
);
7381 if (bpt
->triggered_dll_pathname
!= NULL
)
7382 xfree (bpt
->triggered_dll_pathname
);
7383 if (bpt
->exec_pathname
!= NULL
)
7384 xfree (bpt
->exec_pathname
);
7386 /* Be sure no bpstat's are pointing at it after it's been freed. */
7387 /* FIXME, how can we find all bpstat's?
7388 We just check stop_bpstat for now. Note that we cannot just
7389 remove bpstats pointing at bpt from the stop_bpstat list
7390 entirely, as breakpoint commands are associated with the bpstat;
7391 if we remove it here, then the later call to
7392 bpstat_do_actions (&stop_bpstat);
7393 in event-top.c won't do anything, and temporary breakpoints
7394 with commands won't work. */
7396 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7398 /* Now that breakpoint is removed from breakpoint
7399 list, update the global location list. This
7400 will remove locations that used to belong to
7401 this breakpoint. Do this before freeing
7402 the breakpoint itself, since remove_breakpoint
7403 looks at location's owner. It might be better
7404 design to have location completely self-contained,
7405 but it's not the case now. */
7406 update_global_location_list (0);
7409 /* On the chance that someone will soon try again to delete this same
7410 bp, we mark it as deleted before freeing its storage. */
7411 bpt
->type
= bp_none
;
7417 do_delete_breakpoint_cleanup (void *b
)
7419 delete_breakpoint (b
);
7423 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7425 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7429 delete_command (char *arg
, int from_tty
)
7431 struct breakpoint
*b
, *temp
;
7437 int breaks_to_delete
= 0;
7439 /* Delete all breakpoints if no argument.
7440 Do not delete internal or call-dummy breakpoints, these
7441 have to be deleted with an explicit breakpoint number argument. */
7444 if (b
->type
!= bp_call_dummy
&&
7445 b
->type
!= bp_shlib_event
&&
7446 b
->type
!= bp_thread_event
&&
7447 b
->type
!= bp_overlay_event
&&
7450 breaks_to_delete
= 1;
7455 /* Ask user only if there are some breakpoints to delete. */
7457 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7459 ALL_BREAKPOINTS_SAFE (b
, temp
)
7461 if (b
->type
!= bp_call_dummy
&&
7462 b
->type
!= bp_shlib_event
&&
7463 b
->type
!= bp_thread_event
&&
7464 b
->type
!= bp_overlay_event
&&
7466 delete_breakpoint (b
);
7471 map_breakpoint_numbers (arg
, delete_breakpoint
);
7475 all_locations_are_pending (struct bp_location
*loc
)
7477 for (; loc
; loc
= loc
->next
)
7478 if (!loc
->shlib_disabled
)
7483 /* Subroutine of update_breakpoint_locations to simplify it.
7484 Return non-zero if multiple fns in list LOC have the same name.
7485 Null names are ignored. */
7488 ambiguous_names_p (struct bp_location
*loc
)
7490 struct bp_location
*l
;
7491 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7492 (int (*) (const void *, const void *)) streq
,
7493 NULL
, xcalloc
, xfree
);
7495 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7498 const char *name
= l
->function_name
;
7500 /* Allow for some names to be NULL, ignore them. */
7504 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7506 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7521 update_breakpoint_locations (struct breakpoint
*b
,
7522 struct symtabs_and_lines sals
)
7526 struct bp_location
*existing_locations
= b
->loc
;
7528 /* If there's no new locations, and all existing locations
7529 are pending, don't do anything. This optimizes
7530 the common case where all locations are in the same
7531 shared library, that was unloaded. We'd like to
7532 retain the location, so that when the library
7533 is loaded again, we don't loose the enabled/disabled
7534 status of the individual locations. */
7535 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7540 for (i
= 0; i
< sals
.nelts
; ++i
)
7542 struct bp_location
*new_loc
=
7543 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7545 /* Reparse conditions, they might contain references to the
7547 if (b
->cond_string
!= NULL
)
7549 struct gdb_exception e
;
7552 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7554 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7559 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7560 b
->number
, e
.message
);
7561 new_loc
->enabled
= 0;
7565 if (b
->source_file
!= NULL
)
7566 xfree (b
->source_file
);
7567 if (sals
.sals
[i
].symtab
== NULL
)
7568 b
->source_file
= NULL
;
7571 savestring (sals
.sals
[i
].symtab
->filename
,
7572 strlen (sals
.sals
[i
].symtab
->filename
));
7574 if (b
->line_number
== 0)
7575 b
->line_number
= sals
.sals
[i
].line
;
7578 /* Update locations of permanent breakpoints. */
7579 if (b
->enable_state
== bp_permanent
)
7580 make_breakpoint_permanent (b
);
7582 /* If possible, carry over 'disable' status from existing breakpoints. */
7584 struct bp_location
*e
= existing_locations
;
7585 /* If there are multiple breakpoints with the same function name,
7586 e.g. for inline functions, comparing function names won't work.
7587 Instead compare pc addresses; this is just a heuristic as things
7588 may have moved, but in practice it gives the correct answer
7589 often enough until a better solution is found. */
7590 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7592 for (; e
; e
= e
->next
)
7594 if (!e
->enabled
&& e
->function_name
)
7596 struct bp_location
*l
= b
->loc
;
7597 if (have_ambiguous_names
)
7599 for (; l
; l
= l
->next
)
7600 if (e
->address
== l
->address
)
7608 for (; l
; l
= l
->next
)
7609 if (l
->function_name
7610 && strcmp (e
->function_name
, l
->function_name
) == 0)
7620 update_global_location_list (1);
7624 /* Reset a breakpoint given it's struct breakpoint * BINT.
7625 The value we return ends up being the return value from catch_errors.
7626 Unused in this case. */
7629 breakpoint_re_set_one (void *bint
)
7631 /* get past catch_errs */
7632 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7636 int *not_found_ptr
= ¬_found
;
7637 struct symtabs_and_lines sals
= {};
7638 struct symtabs_and_lines expanded
;
7640 enum enable_state save_enable
;
7641 struct gdb_exception e
;
7647 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7651 case bp_hardware_breakpoint
:
7653 case bp_catch_unload
:
7654 if (b
->addr_string
== NULL
)
7656 /* Anything without a string can't be re-set. */
7657 delete_breakpoint (b
);
7661 set_language (b
->language
);
7662 input_radix
= b
->input_radix
;
7664 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7666 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7671 int not_found_and_ok
= 0;
7672 /* For pending breakpoints, it's expected that parsing
7673 will fail until the right shared library is loaded.
7674 User has already told to create pending breakpoints and
7675 don't need extra messages. If breakpoint is in bp_shlib_disabled
7676 state, then user already saw the message about that breakpoint
7677 being disabled, and don't want to see more errors. */
7679 && (b
->condition_not_parsed
7680 || (b
->loc
&& b
->loc
->shlib_disabled
)
7681 || b
->enable_state
== bp_disabled
))
7682 not_found_and_ok
= 1;
7684 if (!not_found_and_ok
)
7686 /* We surely don't want to warn about the same breakpoint
7687 10 times. One solution, implemented here, is disable
7688 the breakpoint on error. Another solution would be to
7689 have separate 'warning emitted' flag. Since this
7690 happens only when a binary has changed, I don't know
7691 which approach is better. */
7692 b
->enable_state
= bp_disabled
;
7693 throw_exception (e
);
7700 gdb_assert (sals
.nelts
== 1);
7701 resolve_sal_pc (&sals
.sals
[0]);
7702 if (b
->condition_not_parsed
&& s
&& s
[0])
7704 char *cond_string
= 0;
7706 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7707 &cond_string
, &thread
);
7709 b
->cond_string
= cond_string
;
7711 b
->condition_not_parsed
= 0;
7713 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7714 update_breakpoint_locations (b
, expanded
);
7720 case bp_hardware_watchpoint
:
7721 case bp_read_watchpoint
:
7722 case bp_access_watchpoint
:
7723 /* Watchpoint can be either on expression using entirely global variables,
7724 or it can be on local variables.
7726 Watchpoints of the first kind are never auto-deleted, and even persist
7727 across program restarts. Since they can use variables from shared
7728 libraries, we need to reparse expression as libraries are loaded
7731 Watchpoints on local variables can also change meaning as result
7732 of solib event. For example, if a watchpoint uses both a local and
7733 a global variables in expression, it's a local watchpoint, but
7734 unloading of a shared library will make the expression invalid.
7735 This is not a very common use case, but we still re-evaluate
7736 expression, to avoid surprises to the user.
7738 Note that for local watchpoints, we re-evaluate it only if
7739 watchpoints frame id is still valid. If it's not, it means
7740 the watchpoint is out of scope and will be deleted soon. In fact,
7741 I'm not sure we'll ever be called in this case.
7743 If a local watchpoint's frame id is still valid, then
7744 b->exp_valid_block is likewise valid, and we can safely use it.
7746 Don't do anything about disabled watchpoints, since they will
7747 be reevaluated again when enabled. */
7748 update_watchpoint (b
, 1 /* reparse */);
7750 /* We needn't really do anything to reset these, since the mask
7751 that requests them is unaffected by e.g., new libraries being
7758 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7760 /* Delete overlay event breakpoints; they will be reset later by
7761 breakpoint_re_set. */
7762 case bp_overlay_event
:
7763 delete_breakpoint (b
);
7766 /* This breakpoint is special, it's set up when the inferior
7767 starts and we really don't want to touch it. */
7768 case bp_shlib_event
:
7770 /* Like bp_shlib_event, this breakpoint type is special.
7771 Once it is set up, we do not want to touch it. */
7772 case bp_thread_event
:
7774 /* Keep temporary breakpoints, which can be encountered when we step
7775 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7776 Otherwise these should have been blown away via the cleanup chain
7777 or by breakpoint_init_inferior when we rerun the executable. */
7780 case bp_watchpoint_scope
:
7782 case bp_step_resume
:
7784 case bp_longjmp_resume
:
7791 /* Re-set all breakpoints after symbols have been re-loaded. */
7793 breakpoint_re_set (void)
7795 struct breakpoint
*b
, *temp
;
7796 enum language save_language
;
7797 int save_input_radix
;
7799 save_language
= current_language
->la_language
;
7800 save_input_radix
= input_radix
;
7801 ALL_BREAKPOINTS_SAFE (b
, temp
)
7803 /* Format possible error msg */
7804 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7806 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7807 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7808 do_cleanups (cleanups
);
7810 set_language (save_language
);
7811 input_radix
= save_input_radix
;
7813 create_overlay_event_breakpoint ("_ovly_debug_event");
7816 /* Reset the thread number of this breakpoint:
7818 - If the breakpoint is for all threads, leave it as-is.
7819 - Else, reset it to the current thread for inferior_ptid. */
7821 breakpoint_re_set_thread (struct breakpoint
*b
)
7823 if (b
->thread
!= -1)
7825 if (in_thread_list (inferior_ptid
))
7826 b
->thread
= pid_to_thread_id (inferior_ptid
);
7830 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7831 If from_tty is nonzero, it prints a message to that effect,
7832 which ends with a period (no newline). */
7835 set_ignore_count (int bptnum
, int count
, int from_tty
)
7837 struct breakpoint
*b
;
7843 if (b
->number
== bptnum
)
7845 b
->ignore_count
= count
;
7849 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7851 else if (count
== 1)
7852 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7855 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7858 breakpoints_changed ();
7859 observer_notify_breakpoint_modified (b
->number
);
7863 error (_("No breakpoint number %d."), bptnum
);
7867 make_breakpoint_silent (struct breakpoint
*b
)
7869 /* Silence the breakpoint. */
7873 /* Command to set ignore-count of breakpoint N to COUNT. */
7876 ignore_command (char *args
, int from_tty
)
7882 error_no_arg (_("a breakpoint number"));
7884 num
= get_number (&p
);
7886 error (_("bad breakpoint number: '%s'"), args
);
7888 error (_("Second argument (specified ignore-count) is missing."));
7890 set_ignore_count (num
,
7891 longest_to_int (value_as_long (parse_and_eval (p
))),
7894 printf_filtered ("\n");
7897 /* Call FUNCTION on each of the breakpoints
7898 whose numbers are given in ARGS. */
7901 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7906 struct breakpoint
*b
, *tmp
;
7910 error_no_arg (_("one or more breakpoint numbers"));
7917 num
= get_number_or_range (&p1
);
7920 warning (_("bad breakpoint number at or near '%s'"), p
);
7924 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7925 if (b
->number
== num
)
7927 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7930 if (related_breakpoint
)
7931 function (related_breakpoint
);
7935 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7941 static struct bp_location
*
7942 find_location_by_number (char *number
)
7944 char *dot
= strchr (number
, '.');
7948 struct breakpoint
*b
;
7949 struct bp_location
*loc
;
7954 bp_num
= get_number_or_range (&p1
);
7956 error (_("Bad breakpoint number '%s'"), number
);
7959 if (b
->number
== bp_num
)
7964 if (!b
|| b
->number
!= bp_num
)
7965 error (_("Bad breakpoint number '%s'"), number
);
7968 loc_num
= get_number_or_range (&p1
);
7970 error (_("Bad breakpoint location number '%s'"), number
);
7974 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7977 error (_("Bad breakpoint location number '%s'"), dot
+1);
7983 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7984 If from_tty is nonzero, it prints a message to that effect,
7985 which ends with a period (no newline). */
7988 disable_breakpoint (struct breakpoint
*bpt
)
7990 /* Never disable a watchpoint scope breakpoint; we want to
7991 hit them when we leave scope so we can delete both the
7992 watchpoint and its scope breakpoint at that time. */
7993 if (bpt
->type
== bp_watchpoint_scope
)
7996 /* You can't disable permanent breakpoints. */
7997 if (bpt
->enable_state
== bp_permanent
)
8000 bpt
->enable_state
= bp_disabled
;
8002 update_global_location_list (0);
8004 observer_notify_breakpoint_modified (bpt
->number
);
8008 disable_command (char *args
, int from_tty
)
8010 struct breakpoint
*bpt
;
8012 ALL_BREAKPOINTS (bpt
)
8016 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
8022 case bp_catch_unload
:
8024 case bp_hardware_breakpoint
:
8026 case bp_hardware_watchpoint
:
8027 case bp_read_watchpoint
:
8028 case bp_access_watchpoint
:
8029 disable_breakpoint (bpt
);
8033 else if (strchr (args
, '.'))
8035 struct bp_location
*loc
= find_location_by_number (args
);
8038 update_global_location_list (0);
8041 map_breakpoint_numbers (args
, disable_breakpoint
);
8045 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
8047 int target_resources_ok
, other_type_used
;
8050 if (bpt
->type
== bp_hardware_breakpoint
)
8053 i
= hw_breakpoint_used_count ();
8054 target_resources_ok
=
8055 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
8057 if (target_resources_ok
== 0)
8058 error (_("No hardware breakpoint support in the target."));
8059 else if (target_resources_ok
< 0)
8060 error (_("Hardware breakpoints used exceeds limit."));
8063 if (bpt
->type
== bp_watchpoint
||
8064 bpt
->type
== bp_hardware_watchpoint
||
8065 bpt
->type
== bp_read_watchpoint
||
8066 bpt
->type
== bp_access_watchpoint
)
8068 struct frame_id saved_frame_id
;
8070 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
8071 if (bpt
->exp_valid_block
!= NULL
)
8073 struct frame_info
*fr
=
8074 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
8077 printf_filtered (_("\
8078 Cannot enable watchpoint %d because the block in which its expression\n\
8079 is valid is not currently in scope.\n"), bpt
->number
);
8086 value_free (bpt
->val
);
8087 mark
= value_mark ();
8088 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
8090 release_value (bpt
->val
);
8093 if (bpt
->type
== bp_hardware_watchpoint
||
8094 bpt
->type
== bp_read_watchpoint
||
8095 bpt
->type
== bp_access_watchpoint
)
8097 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
8098 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
8100 /* Hack around 'unused var' error for some targets here */
8101 (void) mem_cnt
, (void) i
;
8102 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
8103 bpt
->type
, i
+ mem_cnt
, other_type_used
);
8104 /* we can consider of type is bp_hardware_watchpoint, convert to
8105 bp_watchpoint in the following condition */
8106 if (target_resources_ok
< 0)
8108 printf_filtered (_("\
8109 Cannot enable watchpoint %d because target watch resources\n\
8110 have been allocated for other watchpoints.\n"), bpt
->number
);
8111 value_free_to_mark (mark
);
8116 select_frame (frame_find_by_id (saved_frame_id
));
8117 value_free_to_mark (mark
);
8120 if (bpt
->enable_state
!= bp_permanent
)
8121 bpt
->enable_state
= bp_enabled
;
8122 bpt
->disposition
= disposition
;
8123 update_global_location_list (1);
8124 breakpoints_changed ();
8126 observer_notify_breakpoint_modified (bpt
->number
);
8131 enable_breakpoint (struct breakpoint
*bpt
)
8133 do_enable_breakpoint (bpt
, bpt
->disposition
);
8136 /* The enable command enables the specified breakpoints (or all defined
8137 breakpoints) so they once again become (or continue to be) effective
8138 in stopping the inferior. */
8141 enable_command (char *args
, int from_tty
)
8143 struct breakpoint
*bpt
;
8145 ALL_BREAKPOINTS (bpt
)
8149 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8155 case bp_catch_unload
:
8157 case bp_hardware_breakpoint
:
8159 case bp_hardware_watchpoint
:
8160 case bp_read_watchpoint
:
8161 case bp_access_watchpoint
:
8162 enable_breakpoint (bpt
);
8166 else if (strchr (args
, '.'))
8168 struct bp_location
*loc
= find_location_by_number (args
);
8171 update_global_location_list (1);
8174 map_breakpoint_numbers (args
, enable_breakpoint
);
8178 enable_once_breakpoint (struct breakpoint
*bpt
)
8180 do_enable_breakpoint (bpt
, disp_disable
);
8184 enable_once_command (char *args
, int from_tty
)
8186 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8190 enable_delete_breakpoint (struct breakpoint
*bpt
)
8192 do_enable_breakpoint (bpt
, disp_del
);
8196 enable_delete_command (char *args
, int from_tty
)
8198 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8202 set_breakpoint_cmd (char *args
, int from_tty
)
8207 show_breakpoint_cmd (char *args
, int from_tty
)
8211 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8213 struct symtabs_and_lines
8214 decode_line_spec_1 (char *string
, int funfirstline
)
8216 struct symtabs_and_lines sals
;
8218 error (_("Empty line specification."));
8219 if (default_breakpoint_valid
)
8220 sals
= decode_line_1 (&string
, funfirstline
,
8221 default_breakpoint_symtab
,
8222 default_breakpoint_line
,
8223 (char ***) NULL
, NULL
);
8225 sals
= decode_line_1 (&string
, funfirstline
,
8226 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8228 error (_("Junk at end of line specification: %s"), string
);
8232 /* Create and insert a raw software breakpoint at PC. Return an
8233 identifier, which should be used to remove the breakpoint later.
8234 In general, places which call this should be using something on the
8235 breakpoint chain instead; this function should be eliminated
8239 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8241 struct bp_target_info
*bp_tgt
;
8243 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8244 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8246 bp_tgt
->placed_address
= pc
;
8247 if (target_insert_breakpoint (bp_tgt
) != 0)
8249 /* Could not insert the breakpoint. */
8257 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8260 deprecated_remove_raw_breakpoint (void *bp
)
8262 struct bp_target_info
*bp_tgt
= bp
;
8265 ret
= target_remove_breakpoint (bp_tgt
);
8271 /* One (or perhaps two) breakpoints used for software single stepping. */
8273 static void *single_step_breakpoints
[2];
8275 /* Create and insert a breakpoint for software single step. */
8278 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8282 if (single_step_breakpoints
[0] == NULL
)
8283 bpt_p
= &single_step_breakpoints
[0];
8286 gdb_assert (single_step_breakpoints
[1] == NULL
);
8287 bpt_p
= &single_step_breakpoints
[1];
8290 /* NOTE drow/2006-04-11: A future improvement to this function would be
8291 to only create the breakpoints once, and actually put them on the
8292 breakpoint chain. That would let us use set_raw_breakpoint. We could
8293 adjust the addresses each time they were needed. Doing this requires
8294 corresponding changes elsewhere where single step breakpoints are
8295 handled, however. So, for now, we use this. */
8297 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8299 error (_("Could not insert single-step breakpoint at 0x%s"),
8300 paddr_nz (next_pc
));
8303 /* Remove and delete any breakpoints used for software single step. */
8306 remove_single_step_breakpoints (void)
8308 gdb_assert (single_step_breakpoints
[0] != NULL
);
8310 /* See insert_single_step_breakpoint for more about this deprecated
8312 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8313 single_step_breakpoints
[0] = NULL
;
8315 if (single_step_breakpoints
[1] != NULL
)
8317 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8318 single_step_breakpoints
[1] = NULL
;
8322 /* Check whether a software single-step breakpoint is inserted at PC. */
8325 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8329 for (i
= 0; i
< 2; i
++)
8331 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8332 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8340 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8341 It is defined as a macro to prevent duplication.
8342 COMMAND should be a string constant containing the name of the command. */
8343 #define BREAK_ARGS_HELP(command) \
8344 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8345 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8346 If a line number is specified, break at start of code for that line.\n\
8347 If a function is specified, break at start of code for that function.\n\
8348 If an address is specified, break at that exact address.\n\
8349 With no LOCATION, uses current execution address of selected stack frame.\n\
8350 This is useful for breaking on return to a stack frame.\n\
8352 THREADNUM is the number from \"info threads\".\n\
8353 CONDITION is a boolean expression.\n\
8355 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8357 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8359 /* List of subcommands for "catch". */
8360 static struct cmd_list_element
*catch_cmdlist
;
8362 /* List of subcommands for "tcatch". */
8363 static struct cmd_list_element
*tcatch_cmdlist
;
8365 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8366 lists, and pass some additional user data to the command function. */
8368 add_catch_command (char *name
, char *docstring
,
8369 void (*sfunc
) (char *args
, int from_tty
,
8370 struct cmd_list_element
*command
),
8371 void *user_data_catch
,
8372 void *user_data_tcatch
)
8374 struct cmd_list_element
*command
;
8376 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8378 set_cmd_sfunc (command
, sfunc
);
8379 set_cmd_context (command
, user_data_catch
);
8381 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8383 set_cmd_sfunc (command
, sfunc
);
8384 set_cmd_context (command
, user_data_tcatch
);
8388 _initialize_breakpoint (void)
8390 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8391 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8392 struct cmd_list_element
*c
;
8394 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8396 breakpoint_chain
= 0;
8397 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8398 before a breakpoint is set. */
8399 breakpoint_count
= 0;
8401 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8402 Set ignore-count of breakpoint number N to COUNT.\n\
8403 Usage is `ignore N COUNT'."));
8405 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8407 add_com ("commands", class_breakpoint
, commands_command
, _("\
8408 Set commands to be executed when a breakpoint is hit.\n\
8409 Give breakpoint number as argument after \"commands\".\n\
8410 With no argument, the targeted breakpoint is the last one set.\n\
8411 The commands themselves follow starting on the next line.\n\
8412 Type a line containing \"end\" to indicate the end of them.\n\
8413 Give \"silent\" as the first line to make the breakpoint silent;\n\
8414 then no output is printed when it is hit, except what the commands print."));
8416 add_com ("condition", class_breakpoint
, condition_command
, _("\
8417 Specify breakpoint number N to break only if COND is true.\n\
8418 Usage is `condition N COND', where N is an integer and COND is an\n\
8419 expression to be evaluated whenever breakpoint N is reached."));
8421 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8422 Set a temporary breakpoint.\n\
8423 Like \"break\" except the breakpoint is only temporary,\n\
8424 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8425 by using \"enable delete\" on the breakpoint number.\n\
8427 BREAK_ARGS_HELP ("tbreak")));
8428 set_cmd_completer (c
, location_completer
);
8430 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8431 Set a hardware assisted breakpoint.\n\
8432 Like \"break\" except the breakpoint requires hardware support,\n\
8433 some target hardware may not have this support.\n\
8435 BREAK_ARGS_HELP ("hbreak")));
8436 set_cmd_completer (c
, location_completer
);
8438 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8439 Set a temporary hardware assisted breakpoint.\n\
8440 Like \"hbreak\" except the breakpoint is only temporary,\n\
8441 so it will be deleted when hit.\n\
8443 BREAK_ARGS_HELP ("thbreak")));
8444 set_cmd_completer (c
, location_completer
);
8446 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8447 Enable some breakpoints.\n\
8448 Give breakpoint numbers (separated by spaces) as arguments.\n\
8449 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8450 This is used to cancel the effect of the \"disable\" command.\n\
8451 With a subcommand you can enable temporarily."),
8452 &enablelist
, "enable ", 1, &cmdlist
);
8454 add_com ("ab", class_breakpoint
, enable_command
, _("\
8455 Enable some breakpoints.\n\
8456 Give breakpoint numbers (separated by spaces) as arguments.\n\
8457 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8458 This is used to cancel the effect of the \"disable\" command.\n\
8459 With a subcommand you can enable temporarily."));
8461 add_com_alias ("en", "enable", class_breakpoint
, 1);
8463 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8464 Enable some breakpoints.\n\
8465 Give breakpoint numbers (separated by spaces) as arguments.\n\
8466 This is used to cancel the effect of the \"disable\" command.\n\
8467 May be abbreviated to simply \"enable\".\n"),
8468 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8470 add_cmd ("once", no_class
, enable_once_command
, _("\
8471 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8472 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8475 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8476 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8477 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8480 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8481 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8482 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8485 add_cmd ("once", no_class
, enable_once_command
, _("\
8486 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8487 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8490 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8491 Disable some breakpoints.\n\
8492 Arguments are breakpoint numbers with spaces in between.\n\
8493 To disable all breakpoints, give no argument.\n\
8494 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8495 &disablelist
, "disable ", 1, &cmdlist
);
8496 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8497 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8499 add_com ("sb", class_breakpoint
, disable_command
, _("\
8500 Disable some breakpoints.\n\
8501 Arguments are breakpoint numbers with spaces in between.\n\
8502 To disable all breakpoints, give no argument.\n\
8503 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8505 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8506 Disable some breakpoints.\n\
8507 Arguments are breakpoint numbers with spaces in between.\n\
8508 To disable all breakpoints, give no argument.\n\
8509 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8510 This command may be abbreviated \"disable\"."),
8513 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8514 Delete some breakpoints or auto-display expressions.\n\
8515 Arguments are breakpoint numbers with spaces in between.\n\
8516 To delete all breakpoints, give no argument.\n\
8518 Also a prefix command for deletion of other GDB objects.\n\
8519 The \"unset\" command is also an alias for \"delete\"."),
8520 &deletelist
, "delete ", 1, &cmdlist
);
8521 add_com_alias ("d", "delete", class_breakpoint
, 1);
8522 add_com_alias ("del", "delete", class_breakpoint
, 1);
8524 add_com ("db", class_breakpoint
, delete_command
, _("\
8525 Delete some breakpoints.\n\
8526 Arguments are breakpoint numbers with spaces in between.\n\
8527 To delete all breakpoints, give no argument.\n"));
8529 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8530 Delete some breakpoints or auto-display expressions.\n\
8531 Arguments are breakpoint numbers with spaces in between.\n\
8532 To delete all breakpoints, give no argument.\n\
8533 This command may be abbreviated \"delete\"."),
8536 add_com ("clear", class_breakpoint
, clear_command
, _("\
8537 Clear breakpoint at specified line or function.\n\
8538 Argument may be line number, function name, or \"*\" and an address.\n\
8539 If line number is specified, all breakpoints in that line are cleared.\n\
8540 If function is specified, breakpoints at beginning of function are cleared.\n\
8541 If an address is specified, breakpoints at that address are cleared.\n\
8543 With no argument, clears all breakpoints in the line that the selected frame\n\
8546 See also the \"delete\" command which clears breakpoints by number."));
8548 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8549 Set breakpoint at specified line or function.\n"
8550 BREAK_ARGS_HELP ("break")));
8551 set_cmd_completer (c
, location_completer
);
8553 add_com_alias ("b", "break", class_run
, 1);
8554 add_com_alias ("br", "break", class_run
, 1);
8555 add_com_alias ("bre", "break", class_run
, 1);
8556 add_com_alias ("brea", "break", class_run
, 1);
8560 add_com_alias ("ba", "break", class_breakpoint
, 1);
8561 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8566 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8567 Break in function/address or break at a line in the current file."),
8568 &stoplist
, "stop ", 1, &cmdlist
);
8569 add_cmd ("in", class_breakpoint
, stopin_command
,
8570 _("Break in function or address."), &stoplist
);
8571 add_cmd ("at", class_breakpoint
, stopat_command
,
8572 _("Break at a line in the current file."), &stoplist
);
8573 add_com ("status", class_info
, breakpoints_info
, _("\
8574 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8575 The \"Type\" column indicates one of:\n\
8576 \tbreakpoint - normal breakpoint\n\
8577 \twatchpoint - watchpoint\n\
8578 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8579 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8580 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8581 address and file/line number respectively.\n\
8583 Convenience variable \"$_\" and default examine address for \"x\"\n\
8584 are set to the address of the last breakpoint listed unless the command\n\
8585 is prefixed with \"server \".\n\n\
8586 Convenience variable \"$bpnum\" contains the number of the last\n\
8590 add_info ("breakpoints", breakpoints_info
, _("\
8591 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8592 The \"Type\" column indicates one of:\n\
8593 \tbreakpoint - normal breakpoint\n\
8594 \twatchpoint - watchpoint\n\
8595 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8596 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8597 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8598 address and file/line number respectively.\n\
8600 Convenience variable \"$_\" and default examine address for \"x\"\n\
8601 are set to the address of the last breakpoint listed unless the command\n\
8602 is prefixed with \"server \".\n\n\
8603 Convenience variable \"$bpnum\" contains the number of the last\n\
8607 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8608 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8609 The \"Type\" column indicates one of:\n\
8610 \tbreakpoint - normal breakpoint\n\
8611 \twatchpoint - watchpoint\n\
8612 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8613 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8614 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8615 address and file/line number respectively.\n\
8617 Convenience variable \"$_\" and default examine address for \"x\"\n\
8618 are set to the address of the last breakpoint listed unless the command\n\
8619 is prefixed with \"server \".\n\n\
8620 Convenience variable \"$bpnum\" contains the number of the last\n\
8623 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8624 Status of all breakpoints, or breakpoint number NUMBER.\n\
8625 The \"Type\" column indicates one of:\n\
8626 \tbreakpoint - normal breakpoint\n\
8627 \twatchpoint - watchpoint\n\
8628 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8629 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8630 \tuntil - internal breakpoint used by the \"until\" command\n\
8631 \tfinish - internal breakpoint used by the \"finish\" command\n\
8632 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8633 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8634 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8635 address and file/line number respectively.\n\
8637 Convenience variable \"$_\" and default examine address for \"x\"\n\
8638 are set to the address of the last breakpoint listed unless the command\n\
8639 is prefixed with \"server \".\n\n\
8640 Convenience variable \"$bpnum\" contains the number of the last\n\
8642 &maintenanceinfolist
);
8644 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
8645 Set catchpoints to catch events."),
8646 &catch_cmdlist
, "catch ",
8647 0/*allow-unknown*/, &cmdlist
);
8649 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
8650 Set temporary catchpoints to catch events."),
8651 &tcatch_cmdlist
, "tcatch ",
8652 0/*allow-unknown*/, &cmdlist
);
8654 /* Add catch and tcatch sub-commands. */
8655 add_catch_command ("catch", _("\
8656 Catch an exception, when caught.\n\
8657 With an argument, catch only exceptions with the given name."),
8658 catch_catch_command
,
8661 add_catch_command ("throw", _("\
8662 Catch an exception, when thrown.\n\
8663 With an argument, catch only exceptions with the given name."),
8664 catch_throw_command
,
8667 add_catch_command ("fork", _("Catch calls to fork."),
8668 catch_fork_command_1
,
8669 (void *) (uintptr_t) catch_fork_permanent
,
8670 (void *) (uintptr_t) catch_fork_temporary
);
8671 add_catch_command ("vfork", _("Catch calls to vfork."),
8672 catch_fork_command_1
,
8673 (void *) (uintptr_t) catch_vfork_permanent
,
8674 (void *) (uintptr_t) catch_vfork_temporary
);
8675 add_catch_command ("exec", _("Catch calls to exec."),
8676 catch_exec_command_1
,
8679 add_catch_command ("load", _("\
8680 Catch library loads.\n\
8681 With an argument, catch only loads of that library."),
8682 catch_load_command_1
,
8685 add_catch_command ("unload", _("\
8686 Catch library unloads.\n\
8687 With an argument, catch only unloads of that library."),
8688 catch_unload_command_1
,
8691 add_catch_command ("exception", _("\
8692 Catch Ada exceptions, when raised.\n\
8693 With an argument, catch only exceptions with the given name."),
8694 catch_ada_exception_command
,
8697 add_catch_command ("assert", _("\
8698 Catch failed Ada assertions, when raised.\n\
8699 With an argument, catch only exceptions with the given name."),
8700 catch_assert_command
,
8704 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8705 Set a watchpoint for an expression.\n\
8706 A watchpoint stops execution of your program whenever the value of\n\
8707 an expression changes."));
8708 set_cmd_completer (c
, expression_completer
);
8710 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8711 Set a read watchpoint for an expression.\n\
8712 A watchpoint stops execution of your program whenever the value of\n\
8713 an expression is read."));
8714 set_cmd_completer (c
, expression_completer
);
8716 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8717 Set a watchpoint for an expression.\n\
8718 A watchpoint stops execution of your program whenever the value of\n\
8719 an expression is either read or written."));
8720 set_cmd_completer (c
, expression_completer
);
8722 add_info ("watchpoints", breakpoints_info
,
8723 _("Synonym for ``info breakpoints''."));
8726 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8727 respond to changes - contrary to the description. */
8728 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8729 &can_use_hw_watchpoints
, _("\
8730 Set debugger's willingness to use watchpoint hardware."), _("\
8731 Show debugger's willingness to use watchpoint hardware."), _("\
8732 If zero, gdb will not use hardware for new watchpoints, even if\n\
8733 such is available. (However, any hardware watchpoints that were\n\
8734 created before setting this to nonzero, will continue to use watchpoint\n\
8737 show_can_use_hw_watchpoints
,
8738 &setlist
, &showlist
);
8740 can_use_hw_watchpoints
= 1;
8742 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8743 Breakpoint specific settings\n\
8744 Configure various breakpoint-specific variables such as\n\
8745 pending breakpoint behavior"),
8746 &breakpoint_set_cmdlist
, "set breakpoint ",
8747 0/*allow-unknown*/, &setlist
);
8748 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8749 Breakpoint specific settings\n\
8750 Configure various breakpoint-specific variables such as\n\
8751 pending breakpoint behavior"),
8752 &breakpoint_show_cmdlist
, "show breakpoint ",
8753 0/*allow-unknown*/, &showlist
);
8755 add_setshow_auto_boolean_cmd ("pending", no_class
,
8756 &pending_break_support
, _("\
8757 Set debugger's behavior regarding pending breakpoints."), _("\
8758 Show debugger's behavior regarding pending breakpoints."), _("\
8759 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8760 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8761 an error. If auto, an unrecognized breakpoint location results in a\n\
8762 user-query to see if a pending breakpoint should be created."),
8764 show_pending_break_support
,
8765 &breakpoint_set_cmdlist
,
8766 &breakpoint_show_cmdlist
);
8768 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8770 add_setshow_boolean_cmd ("auto-hw", no_class
,
8771 &automatic_hardware_breakpoints
, _("\
8772 Set automatic usage of hardware breakpoints."), _("\
8773 Show automatic usage of hardware breakpoints."), _("\
8774 If set, the debugger will automatically use hardware breakpoints for\n\
8775 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8776 a warning will be emitted for such breakpoints."),
8778 show_automatic_hardware_breakpoints
,
8779 &breakpoint_set_cmdlist
,
8780 &breakpoint_show_cmdlist
);
8782 add_setshow_enum_cmd ("always-inserted", class_support
,
8783 always_inserted_enums
, &always_inserted_mode
, _("\
8784 Set mode for inserting breakpoints."), _("\
8785 Show mode for inserting breakpoints."), _("\
8786 When this mode is off, breakpoints are inserted in inferior when it is\n\
8787 resumed, and removed when execution stops. When this mode is on,\n\
8788 breakpoints are inserted immediately and removed only when the user\n\
8789 deletes the breakpoint. When this mode is auto (which is the default),\n\
8790 the behaviour depends on the non-stop setting (see help set non-stop).\n\
8791 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
8792 behaves as if always-inserted mode is on; if gdb is controlling the\n\
8793 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
8795 &show_always_inserted_mode
,
8796 &breakpoint_set_cmdlist
,
8797 &breakpoint_show_cmdlist
);
8799 automatic_hardware_breakpoints
= 1;