1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "breakpoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
45 #include "completer.h"
48 #include "cli/cli-script.h"
49 #include "gdb_assert.h"
54 #include "exceptions.h"
60 #include "gdb-events.h"
61 #include "mi/mi-common.h"
63 #include "gdb_stdint.h"
65 /* Prototypes for local functions. */
67 static void until_break_command_continuation (struct continuation_arg
*arg
);
69 static void catch_command_1 (char *, int, int);
71 static void enable_delete_command (char *, int);
73 static void enable_delete_breakpoint (struct breakpoint
*);
75 static void enable_once_command (char *, int);
77 static void enable_once_breakpoint (struct breakpoint
*);
79 static void disable_command (char *, int);
81 static void enable_command (char *, int);
83 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
85 static void ignore_command (char *, int);
87 static int breakpoint_re_set_one (void *);
89 static void clear_command (char *, int);
91 static void catch_command (char *, int);
93 static void watch_command (char *, int);
95 static int can_use_hardware_watchpoint (struct value
*);
97 static void break_command_1 (char *, int, int);
99 static void mention (struct breakpoint
*);
101 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
103 static void check_duplicates (struct breakpoint
*);
105 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
107 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
110 static void describe_other_breakpoints (CORE_ADDR
, asection
*, int);
112 static void breakpoints_info (char *, int);
114 static void breakpoint_1 (int, int);
116 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
118 static int breakpoint_cond_eval (void *);
120 static void cleanup_executing_breakpoints (void *);
122 static void commands_command (char *, int);
124 static void condition_command (char *, int);
126 static int get_number_trailer (char **, int);
128 void set_breakpoint_count (int);
137 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
139 static enum print_stop_action
print_it_typical (bpstat
);
141 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
145 enum exception_event_kind kind
;
148 args_for_catchpoint_enable
;
150 static int watchpoint_check (void *);
152 static void maintenance_info_breakpoints (char *, int);
154 static void create_longjmp_breakpoint (char *);
156 static void create_overlay_event_breakpoint (char *);
158 static int hw_breakpoint_used_count (void);
160 static int hw_watchpoint_used_count (enum bptype
, int *);
162 static void hbreak_command (char *, int);
164 static void thbreak_command (char *, int);
166 static void watch_command_1 (char *, int, int);
168 static void rwatch_command (char *, int);
170 static void awatch_command (char *, int);
172 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
174 static void create_fork_vfork_event_catchpoint (int tempflag
,
176 enum bptype bp_kind
);
178 static void stop_command (char *arg
, int from_tty
);
180 static void stopin_command (char *arg
, int from_tty
);
182 static void stopat_command (char *arg
, int from_tty
);
184 static char *ep_find_event_name_end (char *arg
);
186 static char *ep_parse_optional_if_clause (char **arg
);
188 static char *ep_parse_optional_filename (char **arg
);
190 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
191 enum exception_event_kind ex_event
,
192 struct symtab_and_line
*sal
);
194 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
195 char *arg
, int tempflag
, int from_tty
);
197 static void tcatch_command (char *arg
, int from_tty
);
199 static void ep_skip_leading_whitespace (char **s
);
201 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
203 static void free_bp_location (struct bp_location
*loc
);
205 static void mark_breakpoints_out (void);
207 static struct bp_location
*
208 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
);
210 static void update_global_location_list (void);
212 static void update_global_location_list_nothrow (void);
214 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
216 static void insert_breakpoint_locations (void);
219 bpdisp_text (enum bpdisp disp
)
221 /* NOTE: the following values are a part of MI protocol and represent
222 values of 'disp' field returned when inferior stops at a breakpoint. */
223 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
224 return bpdisps
[(int) disp
];
227 /* Prototypes for exported functions. */
228 /* If FALSE, gdb will not use hardware support for watchpoints, even
229 if such is available. */
230 static int can_use_hw_watchpoints
;
233 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
234 struct cmd_list_element
*c
,
237 fprintf_filtered (file
, _("\
238 Debugger's willingness to use watchpoint hardware is %s.\n"),
242 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
243 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
244 for unrecognized breakpoint locations.
245 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
246 static enum auto_boolean pending_break_support
;
248 show_pending_break_support (struct ui_file
*file
, int from_tty
,
249 struct cmd_list_element
*c
,
252 fprintf_filtered (file
, _("\
253 Debugger's behavior regarding pending breakpoints is %s.\n"),
257 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
258 set with "break" but falling in read-only memory.
259 If 0, gdb will warn about such breakpoints, but won't automatically
260 use hardware breakpoints. */
261 static int automatic_hardware_breakpoints
;
263 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
264 struct cmd_list_element
*c
,
267 fprintf_filtered (file
, _("\
268 Automatic usage of hardware breakpoints is %s.\n"),
272 /* If 1, gdb will keep breakpoints inserted even as inferior is stopped,
273 and immediately insert any new breakpoints. If 0, gdb will insert
274 breakpoints into inferior only when resuming it, and will remove
275 breakpoints upon stop. */
276 static int always_inserted_mode
= 0;
278 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
279 struct cmd_list_element
*c
, const char *value
)
281 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
285 void _initialize_breakpoint (void);
287 extern int addressprint
; /* Print machine addresses? */
289 /* Are we executing breakpoint commands? */
290 static int executing_breakpoint_commands
;
292 /* Are overlay event breakpoints enabled? */
293 static int overlay_events_enabled
;
295 /* Walk the following statement or block through all breakpoints.
296 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
299 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
301 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
302 for (B = breakpoint_chain; \
303 B ? (TMP=B->next, 1): 0; \
306 /* Similar iterators for the low-level breakpoints. */
308 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
310 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
311 for (B = bp_location_chain; \
312 B ? (TMP=B->global_next, 1): 0; \
315 /* True if breakpoint hit counts should be displayed in breakpoint info. */
317 int show_breakpoint_hit_counts
= 1;
319 /* Chains of all breakpoints defined. */
321 struct breakpoint
*breakpoint_chain
;
323 struct bp_location
*bp_location_chain
;
325 /* Number of last breakpoint made. */
327 int breakpoint_count
;
329 /* Pointer to current exception event record */
330 static struct exception_event_record
*current_exception_event
;
332 /* This function returns a pointer to the string representation of the
333 pathname of the dynamically-linked library that has just been
336 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
337 or undefined results are guaranteed.
339 This string's contents are only valid immediately after the
340 inferior has stopped in the dynamic linker hook, and becomes
341 invalid as soon as the inferior is continued. Clients should make
342 a copy of this string if they wish to continue the inferior and
343 then access the string. */
345 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
346 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
349 /* This function returns a pointer to the string representation of the
350 pathname of the dynamically-linked library that has just been
353 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
354 TRUE, or undefined results are guaranteed.
356 This string's contents are only valid immediately after the
357 inferior has stopped in the dynamic linker hook, and becomes
358 invalid as soon as the inferior is continued. Clients should make
359 a copy of this string if they wish to continue the inferior and
360 then access the string. */
362 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
363 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
366 /* This function is called by the "catch load" command. It allows the
367 debugger to be notified by the dynamic linker when a specified
368 library file (or any library file, if filename is NULL) is loaded. */
370 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
371 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
372 error (_("catch of library loads not yet implemented on this platform"))
375 /* This function is called by the "catch unload" command. It allows
376 the debugger to be notified by the dynamic linker when a specified
377 library file (or any library file, if filename is NULL) is
380 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
381 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
382 error (_("catch of library unloads not yet implemented on this platform"))
385 /* Return whether a breakpoint is an active enabled breakpoint. */
387 breakpoint_enabled (struct breakpoint
*b
)
389 return (b
->enable_state
== bp_enabled
);
392 /* Set breakpoint count to NUM. */
395 set_breakpoint_count (int num
)
397 breakpoint_count
= num
;
398 set_internalvar (lookup_internalvar ("bpnum"),
399 value_from_longest (builtin_type_int
, (LONGEST
) num
));
402 /* Used in run_command to zero the hit count when a new run starts. */
405 clear_breakpoint_hit_counts (void)
407 struct breakpoint
*b
;
413 /* Default address, symtab and line to put a breakpoint at
414 for "break" command with no arg.
415 if default_breakpoint_valid is zero, the other three are
416 not valid, and "break" with no arg is an error.
418 This set by print_stack_frame, which calls set_default_breakpoint. */
420 int default_breakpoint_valid
;
421 CORE_ADDR default_breakpoint_address
;
422 struct symtab
*default_breakpoint_symtab
;
423 int default_breakpoint_line
;
425 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
426 Advance *PP after the string and any trailing whitespace.
428 Currently the string can either be a number or "$" followed by the name
429 of a convenience variable. Making it an expression wouldn't work well
430 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
432 If the string is a NULL pointer, that denotes the last breakpoint.
434 TRAILER is a character which can be found after the number; most
435 commonly this is `-'. If you don't want a trailer, use \0. */
437 get_number_trailer (char **pp
, int trailer
)
439 int retval
= 0; /* default */
443 /* Empty line means refer to the last breakpoint. */
444 return breakpoint_count
;
447 /* Make a copy of the name, so we can null-terminate it
448 to pass to lookup_internalvar(). */
453 while (isalnum (*p
) || *p
== '_')
455 varname
= (char *) alloca (p
- start
+ 1);
456 strncpy (varname
, start
, p
- start
);
457 varname
[p
- start
] = '\0';
458 val
= value_of_internalvar (lookup_internalvar (varname
));
459 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
460 retval
= (int) value_as_long (val
);
463 printf_filtered (_("Convenience variable must have integer value.\n"));
471 while (*p
>= '0' && *p
<= '9')
474 /* There is no number here. (e.g. "cond a == b"). */
476 /* Skip non-numeric token */
477 while (*p
&& !isspace((int) *p
))
479 /* Return zero, which caller must interpret as error. */
485 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
487 /* Trailing junk: return 0 and let caller print error msg. */
488 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
499 /* Like get_number_trailer, but don't allow a trailer. */
501 get_number (char **pp
)
503 return get_number_trailer (pp
, '\0');
506 /* Parse a number or a range.
507 * A number will be of the form handled by get_number.
508 * A range will be of the form <number1> - <number2>, and
509 * will represent all the integers between number1 and number2,
512 * While processing a range, this fuction is called iteratively;
513 * At each call it will return the next value in the range.
515 * At the beginning of parsing a range, the char pointer PP will
516 * be advanced past <number1> and left pointing at the '-' token.
517 * Subsequent calls will not advance the pointer until the range
518 * is completed. The call that completes the range will advance
519 * pointer PP past <number2>.
523 get_number_or_range (char **pp
)
525 static int last_retval
, end_value
;
526 static char *end_ptr
;
527 static int in_range
= 0;
531 /* Default case: pp is pointing either to a solo number,
532 or to the first number of a range. */
533 last_retval
= get_number_trailer (pp
, '-');
538 /* This is the start of a range (<number1> - <number2>).
539 Skip the '-', parse and remember the second number,
540 and also remember the end of the final token. */
544 while (isspace ((int) *end_ptr
))
545 end_ptr
++; /* skip white space */
546 end_value
= get_number (temp
);
547 if (end_value
< last_retval
)
549 error (_("inverted range"));
551 else if (end_value
== last_retval
)
553 /* degenerate range (number1 == number2). Advance the
554 token pointer so that the range will be treated as a
563 error (_("negative value"));
566 /* pp points to the '-' that betokens a range. All
567 number-parsing has already been done. Return the next
568 integer value (one greater than the saved previous value).
569 Do not advance the token pointer 'pp' until the end of range
572 if (++last_retval
== end_value
)
574 /* End of range reached; advance token pointer. */
584 /* condition N EXP -- set break condition of breakpoint N to EXP. */
587 condition_command (char *arg
, int from_tty
)
589 struct breakpoint
*b
;
594 error_no_arg (_("breakpoint number"));
597 bnum
= get_number (&p
);
599 error (_("Bad breakpoint argument: '%s'"), arg
);
602 if (b
->number
== bnum
)
604 struct bp_location
*loc
= b
->loc
;
605 for (; loc
; loc
= loc
->next
)
613 if (b
->cond_string
!= NULL
)
614 xfree (b
->cond_string
);
618 b
->cond_string
= NULL
;
620 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
625 /* I don't know if it matters whether this is the string the user
626 typed in or the decompiled expression. */
627 b
->cond_string
= savestring (arg
, strlen (arg
));
628 b
->condition_not_parsed
= 0;
629 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
632 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
634 error (_("Junk at end of expression"));
637 breakpoints_changed ();
638 breakpoint_modify_event (b
->number
);
642 error (_("No breakpoint number %d."), bnum
);
646 commands_command (char *arg
, int from_tty
)
648 struct breakpoint
*b
;
651 struct command_line
*l
;
653 /* If we allowed this, we would have problems with when to
654 free the storage, if we change the commands currently
657 if (executing_breakpoint_commands
)
658 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
661 bnum
= get_number (&p
);
664 error (_("Unexpected extra arguments following breakpoint number."));
667 if (b
->number
== bnum
)
669 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
671 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
672 l
= read_command_lines (tmpbuf
, from_tty
);
673 do_cleanups (cleanups
);
674 free_command_lines (&b
->commands
);
676 breakpoints_changed ();
677 breakpoint_modify_event (b
->number
);
680 error (_("No breakpoint number %d."), bnum
);
683 /* Like commands_command, but instead of reading the commands from
684 input stream, takes them from an already parsed command structure.
686 This is used by cli-script.c to DTRT with breakpoint commands
687 that are part of if and while bodies. */
688 enum command_control_type
689 commands_from_control_command (char *arg
, struct command_line
*cmd
)
691 struct breakpoint
*b
;
695 /* If we allowed this, we would have problems with when to
696 free the storage, if we change the commands currently
699 if (executing_breakpoint_commands
)
700 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
702 /* An empty string for the breakpoint number means the last
703 breakpoint, but get_number expects a NULL pointer. */
708 bnum
= get_number (&p
);
711 error (_("Unexpected extra arguments following breakpoint number."));
714 if (b
->number
== bnum
)
716 free_command_lines (&b
->commands
);
717 if (cmd
->body_count
!= 1)
718 error (_("Invalid \"commands\" block structure."));
719 /* We need to copy the commands because if/while will free the
720 list after it finishes execution. */
721 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
722 breakpoints_changed ();
723 breakpoint_modify_event (b
->number
);
724 return simple_control
;
726 error (_("No breakpoint number %d."), bnum
);
729 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
730 by replacing any memory breakpoints with their shadowed contents. */
733 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
735 struct bp_location
*b
;
736 CORE_ADDR bp_addr
= 0;
742 if (b
->owner
->type
== bp_none
)
743 warning (_("reading through apparently deleted breakpoint #%d?"),
746 if (b
->loc_type
!= bp_loc_software_breakpoint
)
750 /* Addresses and length of the part of the breakpoint that
752 bp_addr
= b
->target_info
.placed_address
;
753 bp_size
= b
->target_info
.shadow_len
;
755 /* bp isn't valid, or doesn't shadow memory. */
758 if (bp_addr
+ bp_size
<= memaddr
)
759 /* The breakpoint is entirely before the chunk of memory we
763 if (bp_addr
>= memaddr
+ len
)
764 /* The breakpoint is entirely after the chunk of memory we are
768 /* Offset within shadow_contents. */
769 if (bp_addr
< memaddr
)
771 /* Only copy the second part of the breakpoint. */
772 bp_size
-= memaddr
- bp_addr
;
773 bptoffset
= memaddr
- bp_addr
;
777 if (bp_addr
+ bp_size
> memaddr
+ len
)
779 /* Only copy the first part of the breakpoint. */
780 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
783 memcpy (buf
+ bp_addr
- memaddr
,
784 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
789 /* A wrapper function for inserting catchpoints. */
791 insert_catchpoint (struct ui_out
*uo
, void *args
)
793 struct breakpoint
*b
= (struct breakpoint
*) args
;
799 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
802 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
805 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
808 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
814 is_hardware_watchpoint (struct breakpoint
*bpt
)
816 return (bpt
->type
== bp_hardware_watchpoint
817 || bpt
->type
== bp_read_watchpoint
818 || bpt
->type
== bp_access_watchpoint
);
821 /* Find the current value of a watchpoint on EXP. Return the value in
822 *VALP and *RESULTP and the chain of intermediate and final values
823 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
826 If an error occurs while evaluating the expression, *RESULTP will
827 be set to NULL. *RESULTP may be a lazy value, if the result could
828 not be read from memory. It is used to determine whether a value
829 is user-specified (we should watch the whole value) or intermediate
830 (we should watch only the bit used to locate the final value).
832 If the final value, or any intermediate value, could not be read
833 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
834 set to any referenced values. *VALP will never be a lazy value.
835 This is the value which we store in struct breakpoint.
837 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
838 value chain. The caller must free the values individually. If
839 VAL_CHAIN is NULL, all generated values will be left on the value
843 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
844 struct value
**resultp
, struct value
**val_chain
)
846 struct value
*mark
, *new_mark
, *result
;
854 /* Evaluate the expression. */
855 mark
= value_mark ();
857 gdb_evaluate_expression (exp
, &result
);
858 new_mark
= value_mark ();
859 if (mark
== new_mark
)
864 /* Make sure it's not lazy, so that after the target stops again we
865 have a non-lazy previous value to compare with. */
867 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
872 /* Return the chain of intermediate values. We use this to
873 decide which addresses to watch. */
874 *val_chain
= new_mark
;
875 value_release_to_mark (mark
);
879 /* Assuming that B is a hardware watchpoint:
880 - Reparse watchpoint expression, is REPARSE is non-zero
881 - Evaluate expression and store the result in B->val
882 - Update the list of values that must be watched in B->loc.
884 If the watchpoint is disabled, do nothing. If this is
885 local watchpoint that is out of scope, delete it. */
887 update_watchpoint (struct breakpoint
*b
, int reparse
)
889 int within_current_scope
;
890 struct frame_id saved_frame_id
;
891 struct bp_location
*loc
;
894 /* We don't free locations. They are stored in
895 bp_location_chain and update_global_locations will
896 eventually delete them and remove breakpoints if
900 if (b
->disposition
== disp_del_at_next_stop
)
903 /* Save the current frame's ID so we can restore it after
904 evaluating the watchpoint expression on its own frame. */
905 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
906 took a frame parameter, so that we didn't have to change the
908 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
910 /* Determine if the watchpoint is within scope. */
911 if (b
->exp_valid_block
== NULL
)
912 within_current_scope
= 1;
915 struct frame_info
*fi
;
916 fi
= frame_find_by_id (b
->watchpoint_frame
);
917 within_current_scope
= (fi
!= NULL
);
918 if (within_current_scope
)
922 if (within_current_scope
&& reparse
)
931 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
932 /* If the meaning of expression itself changed, the old value is
933 no longer relevant. We don't want to report a watchpoint hit
934 to the user when the old value and the new value may actually
935 be completely different objects. */
941 /* If we failed to parse the expression, for example because
942 it refers to a global variable in a not-yet-loaded shared library,
943 don't try to insert watchpoint. We don't automatically delete
944 such watchpoint, though, since failure to parse expression
945 is different from out-of-scope watchpoint. */
946 if (within_current_scope
&& b
->exp
)
948 struct value
*val_chain
, *v
, *result
, *next
;
950 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
952 /* Avoid setting b->val if it's already set. The meaning of
953 b->val is 'the last value' user saw, and we should update
954 it only if we reported that last value to user. As it
955 happens, the code that reports it updates b->val directly. */
962 /* Look at each value on the value chain. */
963 for (v
= val_chain
; v
; v
= next
)
965 /* If it's a memory location, and GDB actually needed
966 its contents to evaluate the expression, then we
967 must watch it. If the first value returned is
968 still lazy, that means an error occurred reading it;
969 watch it anyway in case it becomes readable. */
970 if (VALUE_LVAL (v
) == lval_memory
971 && (v
== val_chain
|| ! value_lazy (v
)))
973 struct type
*vtype
= check_typedef (value_type (v
));
975 /* We only watch structs and arrays if user asked
976 for it explicitly, never if they just happen to
977 appear in the middle of some value chain. */
979 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
980 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
984 struct bp_location
*loc
, **tmp
;
986 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
987 len
= TYPE_LENGTH (value_type (v
));
989 if (b
->type
== bp_read_watchpoint
)
991 else if (b
->type
== bp_access_watchpoint
)
994 loc
= allocate_bp_location (b
, bp_hardware_watchpoint
);
995 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1000 loc
->watchpoint_type
= type
;
1004 next
= value_next (v
);
1009 /* We just regenerated the list of breakpoint locations.
1010 The new location does not have its condition field set to anything
1011 and therefore, we must always reparse the cond_string, independently
1012 of the value of the reparse flag. */
1013 if (b
->cond_string
!= NULL
)
1015 char *s
= b
->cond_string
;
1016 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1019 else if (!within_current_scope
)
1021 printf_filtered (_("\
1022 Hardware watchpoint %d deleted because the program has left the block \n\
1023 in which its expression is valid.\n"),
1025 if (b
->related_breakpoint
)
1026 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1027 b
->disposition
= disp_del_at_next_stop
;
1030 /* Restore the selected frame. */
1031 select_frame (frame_find_by_id (saved_frame_id
));
1035 /* Returns 1 iff breakpoint location should be
1036 inserted in the inferior. */
1038 should_be_inserted (struct bp_location
*bpt
)
1040 if (!breakpoint_enabled (bpt
->owner
))
1043 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1046 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1052 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1053 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1054 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1056 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1057 method for each breakpoint or catchpoint type. */
1059 insert_bp_location (struct bp_location
*bpt
,
1060 struct ui_file
*tmp_error_stream
,
1061 int *disabled_breaks
, int *process_warning
,
1062 int *hw_breakpoint_error
)
1066 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1069 /* Initialize the target-specific information. */
1070 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1071 bpt
->target_info
.placed_address
= bpt
->address
;
1073 if (bpt
->loc_type
== bp_loc_software_breakpoint
1074 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1076 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1078 /* If the explicitly specified breakpoint type
1079 is not hardware breakpoint, check the memory map to see
1080 if the breakpoint address is in read only memory or not.
1081 Two important cases are:
1082 - location type is not hardware breakpoint, memory
1083 is readonly. We change the type of the location to
1084 hardware breakpoint.
1085 - location type is hardware breakpoint, memory is read-write.
1086 This means we've previously made the location hardware one, but
1087 then the memory map changed, so we undo.
1089 When breakpoints are removed, remove_breakpoints will
1090 use location types we've just set here, the only possible
1091 problem is that memory map has changed during running program,
1092 but it's not going to work anyway with current gdb. */
1093 struct mem_region
*mr
1094 = lookup_mem_region (bpt
->target_info
.placed_address
);
1098 if (automatic_hardware_breakpoints
)
1101 enum bp_loc_type new_type
;
1103 if (mr
->attrib
.mode
!= MEM_RW
)
1104 new_type
= bp_loc_hardware_breakpoint
;
1106 new_type
= bp_loc_software_breakpoint
;
1108 if (new_type
!= bpt
->loc_type
)
1110 static int said
= 0;
1111 bpt
->loc_type
= new_type
;
1114 fprintf_filtered (gdb_stdout
, _("\
1115 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1120 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1121 && mr
->attrib
.mode
!= MEM_RW
)
1122 warning (_("cannot set software breakpoint at readonly address %s"),
1123 paddr (bpt
->address
));
1127 /* First check to see if we have to handle an overlay. */
1128 if (overlay_debugging
== ovly_off
1129 || bpt
->section
== NULL
1130 || !(section_is_overlay (bpt
->section
)))
1132 /* No overlay handling: just set the breakpoint. */
1134 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1135 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1137 val
= target_insert_breakpoint (&bpt
->target_info
);
1141 /* This breakpoint is in an overlay section.
1142 Shall we set a breakpoint at the LMA? */
1143 if (!overlay_events_enabled
)
1145 /* Yes -- overlay event support is not active,
1146 so we must try to set a breakpoint at the LMA.
1147 This will not work for a hardware breakpoint. */
1148 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1149 warning (_("hardware breakpoint %d not supported in overlay!"),
1150 bpt
->owner
->number
);
1153 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1155 /* Set a software (trap) breakpoint at the LMA. */
1156 bpt
->overlay_target_info
= bpt
->target_info
;
1157 bpt
->overlay_target_info
.placed_address
= addr
;
1158 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1160 fprintf_unfiltered (tmp_error_stream
,
1161 "Overlay breakpoint %d failed: in ROM?",
1162 bpt
->owner
->number
);
1165 /* Shall we set a breakpoint at the VMA? */
1166 if (section_is_mapped (bpt
->section
))
1168 /* Yes. This overlay section is mapped into memory. */
1169 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1170 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1172 val
= target_insert_breakpoint (&bpt
->target_info
);
1176 /* No. This breakpoint will not be inserted.
1177 No error, but do not mark the bp as 'inserted'. */
1184 /* Can't set the breakpoint. */
1185 if (solib_address (bpt
->address
))
1187 /* See also: disable_breakpoints_in_shlibs. */
1189 bpt
->shlib_disabled
= 1;
1190 if (!*disabled_breaks
)
1192 fprintf_unfiltered (tmp_error_stream
,
1193 "Cannot insert breakpoint %d.\n",
1194 bpt
->owner
->number
);
1195 fprintf_unfiltered (tmp_error_stream
,
1196 "Temporarily disabling shared library breakpoints:\n");
1198 *disabled_breaks
= 1;
1199 fprintf_unfiltered (tmp_error_stream
,
1200 "breakpoint #%d\n", bpt
->owner
->number
);
1204 #ifdef ONE_PROCESS_WRITETEXT
1205 *process_warning
= 1;
1207 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1209 *hw_breakpoint_error
= 1;
1210 fprintf_unfiltered (tmp_error_stream
,
1211 "Cannot insert hardware breakpoint %d.\n",
1212 bpt
->owner
->number
);
1216 fprintf_unfiltered (tmp_error_stream
,
1217 "Cannot insert breakpoint %d.\n",
1218 bpt
->owner
->number
);
1219 fprintf_filtered (tmp_error_stream
,
1220 "Error accessing memory address ");
1221 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1222 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1223 safe_strerror (val
));
1234 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1235 /* NOTE drow/2003-09-08: This state only exists for removing
1236 watchpoints. It's not clear that it's necessary... */
1237 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1239 val
= target_insert_watchpoint (bpt
->address
,
1241 bpt
->watchpoint_type
);
1242 bpt
->inserted
= (val
!= -1);
1245 else if (bpt
->owner
->type
== bp_catch_fork
1246 || bpt
->owner
->type
== bp_catch_vfork
1247 || bpt
->owner
->type
== bp_catch_exec
)
1249 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1250 bpt
->owner
, RETURN_MASK_ERROR
);
1251 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1252 bpt
->owner
->number
);
1254 bpt
->owner
->enable_state
= bp_disabled
;
1258 /* We've already printed an error message if there was a problem
1259 inserting this catchpoint, and we've disabled the catchpoint,
1260 so just return success. */
1267 /* Make sure all breakpoints are inserted in inferior.
1268 Throws exception on any error.
1269 A breakpoint that is already inserted won't be inserted
1270 again, so calling this function twice is safe. */
1272 insert_breakpoints (void)
1274 struct breakpoint
*bpt
;
1276 ALL_BREAKPOINTS (bpt
)
1277 if (is_hardware_watchpoint (bpt
))
1278 update_watchpoint (bpt
, 0 /* don't reparse. */);
1280 update_global_location_list ();
1282 if (!always_inserted_mode
&& target_has_execution
)
1283 /* update_global_location_list does not insert breakpoints
1284 when always_inserted_mode is not enabled. Explicitly
1286 insert_breakpoint_locations ();
1289 /* insert_breakpoints is used when starting or continuing the program.
1290 remove_breakpoints is used when the program stops.
1291 Both return zero if successful,
1292 or an `errno' value if could not write the inferior. */
1295 insert_breakpoint_locations (void)
1297 struct breakpoint
*bpt
;
1298 struct bp_location
*b
, *temp
;
1301 int disabled_breaks
= 0;
1302 int hw_breakpoint_error
= 0;
1303 int process_warning
= 0;
1305 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1306 make_cleanup_ui_file_delete (tmp_error_stream
);
1308 /* Explicitly mark the warning -- this will only be printed if
1309 there was an error. */
1310 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1312 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1314 if (!should_be_inserted (b
) || b
->inserted
)
1317 /* There is no point inserting thread-specific breakpoints if the
1318 thread no longer exists. */
1319 if (b
->owner
->thread
!= -1
1320 && !valid_thread_id (b
->owner
->thread
))
1323 val
= insert_bp_location (b
, tmp_error_stream
,
1324 &disabled_breaks
, &process_warning
,
1325 &hw_breakpoint_error
);
1330 /* If we failed to insert all locations of a watchpoint,
1331 remove them, as half-inserted watchpoint is of limited use. */
1332 ALL_BREAKPOINTS (bpt
)
1334 int some_failed
= 0;
1335 struct bp_location
*loc
;
1337 if (!is_hardware_watchpoint (bpt
))
1340 if (bpt
->enable_state
!= bp_enabled
)
1343 if (bpt
->disposition
== disp_del_at_next_stop
)
1346 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1354 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1356 remove_breakpoint (loc
, mark_uninserted
);
1358 hw_breakpoint_error
= 1;
1359 fprintf_unfiltered (tmp_error_stream
,
1360 "Could not insert hardware watchpoint %d.\n",
1368 /* If a hardware breakpoint or watchpoint was inserted, add a
1369 message about possibly exhausted resources. */
1370 if (hw_breakpoint_error
)
1372 fprintf_unfiltered (tmp_error_stream
,
1373 "Could not insert hardware breakpoints:\n\
1374 You may have requested too many hardware breakpoints/watchpoints.\n");
1376 #ifdef ONE_PROCESS_WRITETEXT
1377 if (process_warning
)
1378 fprintf_unfiltered (tmp_error_stream
,
1379 "The same program may be running in another process.");
1381 target_terminal_ours_for_output ();
1382 error_stream (tmp_error_stream
);
1387 remove_breakpoints (void)
1389 struct bp_location
*b
;
1392 ALL_BP_LOCATIONS (b
)
1396 val
= remove_breakpoint (b
, mark_uninserted
);
1405 remove_hw_watchpoints (void)
1407 struct bp_location
*b
;
1410 ALL_BP_LOCATIONS (b
)
1412 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1414 val
= remove_breakpoint (b
, mark_uninserted
);
1423 reattach_breakpoints (int pid
)
1425 struct bp_location
*b
;
1427 struct cleanup
*old_chain
= save_inferior_ptid ();
1428 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1429 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1431 make_cleanup_ui_file_delete (tmp_error_stream
);
1433 inferior_ptid
= pid_to_ptid (pid
);
1434 ALL_BP_LOCATIONS (b
)
1439 val
= insert_bp_location (b
, tmp_error_stream
,
1440 &dummy1
, &dummy2
, &dummy3
);
1443 do_cleanups (old_chain
);
1448 do_cleanups (old_chain
);
1453 restore_always_inserted_mode (void *p
)
1455 always_inserted_mode
= (uintptr_t) p
;
1459 update_breakpoints_after_exec (void)
1461 struct breakpoint
*b
;
1462 struct breakpoint
*temp
;
1463 struct cleanup
*cleanup
;
1465 /* Doing this first prevents the badness of having delete_breakpoint()
1466 write a breakpoint's current "shadow contents" to lift the bp. That
1467 shadow is NOT valid after an exec()! */
1468 mark_breakpoints_out ();
1470 /* The binary we used to debug is now gone, and we're updating
1471 breakpoints for the new binary. Until we're done, we should not
1472 try to insert breakpoints. */
1473 cleanup
= make_cleanup (restore_always_inserted_mode
,
1474 (void *) (uintptr_t) always_inserted_mode
);
1475 always_inserted_mode
= 0;
1477 ALL_BREAKPOINTS_SAFE (b
, temp
)
1479 /* Solib breakpoints must be explicitly reset after an exec(). */
1480 if (b
->type
== bp_shlib_event
)
1482 delete_breakpoint (b
);
1486 /* Thread event breakpoints must be set anew after an exec(),
1487 as must overlay event breakpoints. */
1488 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1490 delete_breakpoint (b
);
1494 /* Step-resume breakpoints are meaningless after an exec(). */
1495 if (b
->type
== bp_step_resume
)
1497 delete_breakpoint (b
);
1501 /* Don't delete an exec catchpoint, because else the inferior
1502 won't stop when it ought!
1504 Similarly, we probably ought to keep vfork catchpoints, 'cause
1505 on this target, we may not be able to stop when the vfork is
1506 seen, but only when the subsequent exec is seen. (And because
1507 deleting fork catchpoints here but not vfork catchpoints will
1508 seem mysterious to users, keep those too.) */
1509 if ((b
->type
== bp_catch_exec
) ||
1510 (b
->type
== bp_catch_vfork
) ||
1511 (b
->type
== bp_catch_fork
))
1516 /* bp_finish is a special case. The only way we ought to be able
1517 to see one of these when an exec() has happened, is if the user
1518 caught a vfork, and then said "finish". Ordinarily a finish just
1519 carries them to the call-site of the current callee, by setting
1520 a temporary bp there and resuming. But in this case, the finish
1521 will carry them entirely through the vfork & exec.
1523 We don't want to allow a bp_finish to remain inserted now. But
1524 we can't safely delete it, 'cause finish_command has a handle to
1525 the bp on a bpstat, and will later want to delete it. There's a
1526 chance (and I've seen it happen) that if we delete the bp_finish
1527 here, that its storage will get reused by the time finish_command
1528 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1529 We really must allow finish_command to delete a bp_finish.
1531 In the absense of a general solution for the "how do we know
1532 it's safe to delete something others may have handles to?"
1533 problem, what we'll do here is just uninsert the bp_finish, and
1534 let finish_command delete it.
1536 (We know the bp_finish is "doomed" in the sense that it's
1537 momentary, and will be deleted as soon as finish_command sees
1538 the inferior stopped. So it doesn't matter that the bp's
1539 address is probably bogus in the new a.out, unlike e.g., the
1540 solib breakpoints.) */
1542 if (b
->type
== bp_finish
)
1547 /* Without a symbolic address, we have little hope of the
1548 pre-exec() address meaning the same thing in the post-exec()
1550 if (b
->addr_string
== NULL
)
1552 delete_breakpoint (b
);
1556 /* FIXME what about longjmp breakpoints? Re-create them here? */
1557 create_overlay_event_breakpoint ("_ovly_debug_event");
1558 do_cleanups (cleanup
);
1562 detach_breakpoints (int pid
)
1564 struct bp_location
*b
;
1566 struct cleanup
*old_chain
= save_inferior_ptid ();
1568 if (pid
== PIDGET (inferior_ptid
))
1569 error (_("Cannot detach breakpoints of inferior_ptid"));
1571 /* Set inferior_ptid; remove_breakpoint uses this global. */
1572 inferior_ptid
= pid_to_ptid (pid
);
1573 ALL_BP_LOCATIONS (b
)
1577 val
= remove_breakpoint (b
, mark_inserted
);
1580 do_cleanups (old_chain
);
1585 do_cleanups (old_chain
);
1590 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1594 if (b
->owner
->enable_state
== bp_permanent
)
1595 /* Permanent breakpoints cannot be inserted or removed. */
1598 /* The type of none suggests that owner is actually deleted.
1599 This should not ever happen. */
1600 gdb_assert (b
->owner
->type
!= bp_none
);
1602 if (b
->loc_type
== bp_loc_software_breakpoint
1603 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1605 /* "Normal" instruction breakpoint: either the standard
1606 trap-instruction bp (bp_breakpoint), or a
1607 bp_hardware_breakpoint. */
1609 /* First check to see if we have to handle an overlay. */
1610 if (overlay_debugging
== ovly_off
1611 || b
->section
== NULL
1612 || !(section_is_overlay (b
->section
)))
1614 /* No overlay handling: just remove the breakpoint. */
1616 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1617 val
= target_remove_hw_breakpoint (&b
->target_info
);
1619 val
= target_remove_breakpoint (&b
->target_info
);
1623 /* This breakpoint is in an overlay section.
1624 Did we set a breakpoint at the LMA? */
1625 if (!overlay_events_enabled
)
1627 /* Yes -- overlay event support is not active, so we
1628 should have set a breakpoint at the LMA. Remove it.
1630 /* Ignore any failures: if the LMA is in ROM, we will
1631 have already warned when we failed to insert it. */
1632 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1633 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1635 target_remove_breakpoint (&b
->overlay_target_info
);
1637 /* Did we set a breakpoint at the VMA?
1638 If so, we will have marked the breakpoint 'inserted'. */
1641 /* Yes -- remove it. Previously we did not bother to
1642 remove the breakpoint if the section had been
1643 unmapped, but let's not rely on that being safe. We
1644 don't know what the overlay manager might do. */
1645 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1646 val
= target_remove_hw_breakpoint (&b
->target_info
);
1648 /* However, we should remove *software* breakpoints only
1649 if the section is still mapped, or else we overwrite
1650 wrong code with the saved shadow contents. */
1651 else if (section_is_mapped (b
->section
))
1652 val
= target_remove_breakpoint (&b
->target_info
);
1658 /* No -- not inserted, so no need to remove. No error. */
1664 b
->inserted
= (is
== mark_inserted
);
1666 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1671 b
->inserted
= (is
== mark_inserted
);
1672 val
= target_remove_watchpoint (b
->address
, b
->length
,
1673 b
->watchpoint_type
);
1675 /* Failure to remove any of the hardware watchpoints comes here. */
1676 if ((is
== mark_uninserted
) && (b
->inserted
))
1677 warning (_("Could not remove hardware watchpoint %d."),
1680 else if ((b
->owner
->type
== bp_catch_fork
||
1681 b
->owner
->type
== bp_catch_vfork
||
1682 b
->owner
->type
== bp_catch_exec
)
1683 && breakpoint_enabled (b
->owner
)
1687 switch (b
->owner
->type
)
1690 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1692 case bp_catch_vfork
:
1693 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1696 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1699 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1704 b
->inserted
= (is
== mark_inserted
);
1710 /* Clear the "inserted" flag in all breakpoints. */
1713 mark_breakpoints_out (void)
1715 struct bp_location
*bpt
;
1717 ALL_BP_LOCATIONS (bpt
)
1721 /* Clear the "inserted" flag in all breakpoints and delete any
1722 breakpoints which should go away between runs of the program.
1724 Plus other such housekeeping that has to be done for breakpoints
1727 Note: this function gets called at the end of a run (by
1728 generic_mourn_inferior) and when a run begins (by
1729 init_wait_for_inferior). */
1734 breakpoint_init_inferior (enum inf_context context
)
1736 struct breakpoint
*b
, *temp
;
1737 struct bp_location
*bpt
;
1739 ALL_BP_LOCATIONS (bpt
)
1742 ALL_BREAKPOINTS_SAFE (b
, temp
)
1747 case bp_watchpoint_scope
:
1749 /* If the call dummy breakpoint is at the entry point it will
1750 cause problems when the inferior is rerun, so we better
1753 Also get rid of scope breakpoints. */
1754 delete_breakpoint (b
);
1758 case bp_hardware_watchpoint
:
1759 case bp_read_watchpoint
:
1760 case bp_access_watchpoint
:
1762 /* Likewise for watchpoints on local expressions. */
1763 if (b
->exp_valid_block
!= NULL
)
1764 delete_breakpoint (b
);
1765 else if (context
== inf_starting
)
1767 /* Reset val field to force reread of starting value
1768 in insert_breakpoints. */
1770 value_free (b
->val
);
1781 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1782 exists at PC. It returns ordinary_breakpoint_here if it's an
1783 ordinary breakpoint, or permanent_breakpoint_here if it's a
1784 permanent breakpoint.
1785 - When continuing from a location with an ordinary breakpoint, we
1786 actually single step once before calling insert_breakpoints.
1787 - When continuing from a localion with a permanent breakpoint, we
1788 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1789 the target, to advance the PC past the breakpoint. */
1791 enum breakpoint_here
1792 breakpoint_here_p (CORE_ADDR pc
)
1794 const struct bp_location
*bpt
;
1795 int any_breakpoint_here
= 0;
1797 ALL_BP_LOCATIONS (bpt
)
1799 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1800 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1803 if ((breakpoint_enabled (bpt
->owner
)
1804 || bpt
->owner
->enable_state
== bp_permanent
)
1805 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1807 if (overlay_debugging
1808 && section_is_overlay (bpt
->section
)
1809 && !section_is_mapped (bpt
->section
))
1810 continue; /* unmapped overlay -- can't be a match */
1811 else if (bpt
->owner
->enable_state
== bp_permanent
)
1812 return permanent_breakpoint_here
;
1814 any_breakpoint_here
= 1;
1818 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1822 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1823 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1824 This does not check for single-step breakpoints, which are
1825 inserted and removed using direct target manipulation. */
1828 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1830 const struct bp_location
*bpt
;
1832 ALL_BP_LOCATIONS (bpt
)
1834 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1835 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1839 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1841 if (overlay_debugging
1842 && section_is_overlay (bpt
->section
)
1843 && !section_is_mapped (bpt
->section
))
1844 continue; /* unmapped overlay -- can't be a match */
1852 /* Returns non-zero iff there's either regular breakpoint
1853 or a single step breakpoint inserted at PC. */
1856 breakpoint_inserted_here_p (CORE_ADDR pc
)
1858 if (regular_breakpoint_inserted_here_p (pc
))
1861 if (single_step_breakpoint_inserted_here_p (pc
))
1867 /* This function returns non-zero iff there is a software breakpoint
1871 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1873 const struct bp_location
*bpt
;
1874 int any_breakpoint_here
= 0;
1876 ALL_BP_LOCATIONS (bpt
)
1878 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1882 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1884 if (overlay_debugging
1885 && section_is_overlay (bpt
->section
)
1886 && !section_is_mapped (bpt
->section
))
1887 continue; /* unmapped overlay -- can't be a match */
1893 /* Also check for software single-step breakpoints. */
1894 if (single_step_breakpoint_inserted_here_p (pc
))
1900 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1901 PC is valid for process/thread PTID. */
1904 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1906 const struct bp_location
*bpt
;
1909 thread
= pid_to_thread_id (ptid
);
1911 ALL_BP_LOCATIONS (bpt
)
1913 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1914 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1917 if ((breakpoint_enabled (bpt
->owner
)
1918 || bpt
->owner
->enable_state
== bp_permanent
)
1919 && bpt
->address
== pc
1920 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1922 if (overlay_debugging
1923 && section_is_overlay (bpt
->section
)
1924 && !section_is_mapped (bpt
->section
))
1925 continue; /* unmapped overlay -- can't be a match */
1935 /* bpstat stuff. External routines' interfaces are documented
1939 ep_is_catchpoint (struct breakpoint
*ep
)
1942 (ep
->type
== bp_catch_load
)
1943 || (ep
->type
== bp_catch_unload
)
1944 || (ep
->type
== bp_catch_fork
)
1945 || (ep
->type
== bp_catch_vfork
)
1946 || (ep
->type
== bp_catch_exec
);
1948 /* ??rehrauer: Add more kinds here, as are implemented... */
1952 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1955 (ep
->type
== bp_catch_load
)
1956 || (ep
->type
== bp_catch_unload
);
1960 bpstat_free (bpstat bs
)
1962 if (bs
->old_val
!= NULL
)
1963 value_free (bs
->old_val
);
1964 free_command_lines (&bs
->commands
);
1968 /* Clear a bpstat so that it says we are not at any breakpoint.
1969 Also free any storage that is part of a bpstat. */
1972 bpstat_clear (bpstat
*bsp
)
1989 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1990 is part of the bpstat is copied as well. */
1993 bpstat_copy (bpstat bs
)
1997 bpstat retval
= NULL
;
2002 for (; bs
!= NULL
; bs
= bs
->next
)
2004 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2005 memcpy (tmp
, bs
, sizeof (*tmp
));
2006 if (bs
->commands
!= NULL
)
2007 tmp
->commands
= copy_command_lines (bs
->commands
);
2008 if (bs
->old_val
!= NULL
)
2009 tmp
->old_val
= value_copy (bs
->old_val
);
2012 /* This is the first thing in the chain. */
2022 /* Find the bpstat associated with this breakpoint */
2025 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2030 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2032 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2038 /* Find a step_resume breakpoint associated with this bpstat.
2039 (If there are multiple step_resume bp's on the list, this function
2040 will arbitrarily pick one.)
2042 It is an error to use this function if BPSTAT doesn't contain a
2043 step_resume breakpoint.
2045 See wait_for_inferior's use of this function. */
2047 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2051 gdb_assert (bsp
!= NULL
);
2053 current_thread
= pid_to_thread_id (inferior_ptid
);
2055 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2057 if ((bsp
->breakpoint_at
!= NULL
) &&
2058 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2059 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2060 bsp
->breakpoint_at
->owner
->thread
== -1))
2061 return bsp
->breakpoint_at
->owner
;
2064 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2068 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2069 at. *BSP upon return is a bpstat which points to the remaining
2070 breakpoints stopped at (but which is not guaranteed to be good for
2071 anything but further calls to bpstat_num).
2072 Return 0 if passed a bpstat which does not indicate any breakpoints.
2073 Return -1 if stopped at a breakpoint that has been deleted since
2075 Return 1 otherwise. */
2078 bpstat_num (bpstat
*bsp
, int *num
)
2080 struct breakpoint
*b
;
2083 return 0; /* No more breakpoint values */
2085 /* We assume we'll never have several bpstats that
2086 correspond to a single breakpoint -- otherwise,
2087 this function might return the same number more
2088 than once and this will look ugly. */
2089 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2090 *bsp
= (*bsp
)->next
;
2092 return -1; /* breakpoint that's been deleted since */
2094 *num
= b
->number
; /* We have its number */
2098 /* Modify BS so that the actions will not be performed. */
2101 bpstat_clear_actions (bpstat bs
)
2103 for (; bs
!= NULL
; bs
= bs
->next
)
2105 free_command_lines (&bs
->commands
);
2106 if (bs
->old_val
!= NULL
)
2108 value_free (bs
->old_val
);
2114 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2116 cleanup_executing_breakpoints (void *ignore
)
2118 executing_breakpoint_commands
= 0;
2121 /* Execute all the commands associated with all the breakpoints at this
2122 location. Any of these commands could cause the process to proceed
2123 beyond this point, etc. We look out for such changes by checking
2124 the global "breakpoint_proceeded" after each command. */
2127 bpstat_do_actions (bpstat
*bsp
)
2130 struct cleanup
*old_chain
;
2132 /* Avoid endless recursion if a `source' command is contained
2134 if (executing_breakpoint_commands
)
2137 executing_breakpoint_commands
= 1;
2138 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2141 /* Note that (as of this writing), our callers all appear to
2142 be passing us the address of global stop_bpstat. And, if
2143 our calls to execute_control_command cause the inferior to
2144 proceed, that global (and hence, *bsp) will change.
2146 We must be careful to not touch *bsp unless the inferior
2147 has not proceeded. */
2149 /* This pointer will iterate over the list of bpstat's. */
2152 breakpoint_proceeded
= 0;
2153 for (; bs
!= NULL
; bs
= bs
->next
)
2155 struct command_line
*cmd
;
2156 struct cleanup
*this_cmd_tree_chain
;
2158 /* Take ownership of the BSP's command tree, if it has one.
2160 The command tree could legitimately contain commands like
2161 'step' and 'next', which call clear_proceed_status, which
2162 frees stop_bpstat's command tree. To make sure this doesn't
2163 free the tree we're executing out from under us, we need to
2164 take ownership of the tree ourselves. Since a given bpstat's
2165 commands are only executed once, we don't need to copy it; we
2166 can clear the pointer in the bpstat, and make sure we free
2167 the tree when we're done. */
2170 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2174 execute_control_command (cmd
);
2176 if (breakpoint_proceeded
)
2182 /* We can free this command tree now. */
2183 do_cleanups (this_cmd_tree_chain
);
2185 if (breakpoint_proceeded
)
2187 if (target_can_async_p ())
2188 /* If we are in async mode, then the target might
2189 be still running, not stopped at any breakpoint,
2190 so nothing for us to do here -- just return to
2194 /* In sync mode, when execute_control_command returns
2195 we're already standing on the next breakpoint.
2196 Breakpoint commands for that stop were not run,
2197 since execute_command does not run breakpoint
2198 commands -- only command_line_handler does, but
2199 that one is not involved in execution of breakpoint
2200 commands. So, we can now execute breakpoint commands.
2201 There's an implicit assumption that we're called with
2202 stop_bpstat, so our parameter is the new bpstat to
2204 It should be noted that making execute_command do
2205 bpstat actions is not an option -- in this case we'll
2206 have recursive invocation of bpstat for each breakpoint
2207 with a command, and can easily blow up GDB stack. */
2211 do_cleanups (old_chain
);
2214 /* Print out the (old or new) value associated with a watchpoint. */
2217 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2220 fprintf_unfiltered (stream
, _("<unreadable>"));
2222 value_print (val
, stream
, 0, Val_pretty_default
);
2225 /* This is the normal print function for a bpstat. In the future,
2226 much of this logic could (should?) be moved to bpstat_stop_status,
2227 by having it set different print_it values.
2229 Current scheme: When we stop, bpstat_print() is called. It loops
2230 through the bpstat list of things causing this stop, calling the
2231 print_bp_stop_message function on each one. The behavior of the
2232 print_bp_stop_message function depends on the print_it field of
2233 bpstat. If such field so indicates, call this function here.
2235 Return values from this routine (ultimately used by bpstat_print()
2236 and normal_stop() to decide what to do):
2237 PRINT_NOTHING: Means we already printed all we needed to print,
2238 don't print anything else.
2239 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2240 that something to be followed by a location.
2241 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2242 that something to be followed by a location.
2243 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2246 static enum print_stop_action
2247 print_it_typical (bpstat bs
)
2249 struct cleanup
*old_chain
, *ui_out_chain
;
2250 struct breakpoint
*b
;
2251 const struct bp_location
*bl
;
2252 struct ui_stream
*stb
;
2254 stb
= ui_out_stream_new (uiout
);
2255 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2256 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2257 which has since been deleted. */
2258 if (bs
->breakpoint_at
== NULL
)
2259 return PRINT_UNKNOWN
;
2260 bl
= bs
->breakpoint_at
;
2266 case bp_hardware_breakpoint
:
2267 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2268 if (bl
->address
!= bl
->requested_address
)
2269 breakpoint_adjustment_warning (bl
->requested_address
,
2272 annotate_breakpoint (b
->number
);
2274 ui_out_text (uiout
, "\nTemporary breakpoint ");
2276 ui_out_text (uiout
, "\nBreakpoint ");
2277 if (ui_out_is_mi_like_p (uiout
))
2279 ui_out_field_string (uiout
, "reason",
2280 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2281 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2283 ui_out_field_int (uiout
, "bkptno", b
->number
);
2284 ui_out_text (uiout
, ", ");
2285 return PRINT_SRC_AND_LOC
;
2288 case bp_shlib_event
:
2289 /* Did we stop because the user set the stop_on_solib_events
2290 variable? (If so, we report this as a generic, "Stopped due
2291 to shlib event" message.) */
2292 printf_filtered (_("Stopped due to shared library event\n"));
2293 return PRINT_NOTHING
;
2296 case bp_thread_event
:
2297 /* Not sure how we will get here.
2298 GDB should not stop for these breakpoints. */
2299 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2300 return PRINT_NOTHING
;
2303 case bp_overlay_event
:
2304 /* By analogy with the thread event, GDB should not stop for these. */
2305 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2306 return PRINT_NOTHING
;
2310 annotate_catchpoint (b
->number
);
2311 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2313 b
->triggered_dll_pathname
);
2314 return PRINT_SRC_AND_LOC
;
2317 case bp_catch_unload
:
2318 annotate_catchpoint (b
->number
);
2319 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2321 b
->triggered_dll_pathname
);
2322 return PRINT_SRC_AND_LOC
;
2326 annotate_catchpoint (b
->number
);
2327 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2329 b
->forked_inferior_pid
);
2330 return PRINT_SRC_AND_LOC
;
2333 case bp_catch_vfork
:
2334 annotate_catchpoint (b
->number
);
2335 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2337 b
->forked_inferior_pid
);
2338 return PRINT_SRC_AND_LOC
;
2342 annotate_catchpoint (b
->number
);
2343 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2346 return PRINT_SRC_AND_LOC
;
2350 case bp_hardware_watchpoint
:
2351 annotate_watchpoint (b
->number
);
2352 if (ui_out_is_mi_like_p (uiout
))
2355 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2357 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2358 ui_out_text (uiout
, "\nOld value = ");
2359 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2360 ui_out_field_stream (uiout
, "old", stb
);
2361 ui_out_text (uiout
, "\nNew value = ");
2362 watchpoint_value_print (b
->val
, stb
->stream
);
2363 ui_out_field_stream (uiout
, "new", stb
);
2364 do_cleanups (ui_out_chain
);
2365 ui_out_text (uiout
, "\n");
2366 /* More than one watchpoint may have been triggered. */
2367 return PRINT_UNKNOWN
;
2370 case bp_read_watchpoint
:
2371 if (ui_out_is_mi_like_p (uiout
))
2374 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2376 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2377 ui_out_text (uiout
, "\nValue = ");
2378 watchpoint_value_print (b
->val
, stb
->stream
);
2379 ui_out_field_stream (uiout
, "value", stb
);
2380 do_cleanups (ui_out_chain
);
2381 ui_out_text (uiout
, "\n");
2382 return PRINT_UNKNOWN
;
2385 case bp_access_watchpoint
:
2386 if (bs
->old_val
!= NULL
)
2388 annotate_watchpoint (b
->number
);
2389 if (ui_out_is_mi_like_p (uiout
))
2392 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2394 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2395 ui_out_text (uiout
, "\nOld value = ");
2396 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2397 ui_out_field_stream (uiout
, "old", stb
);
2398 ui_out_text (uiout
, "\nNew value = ");
2403 if (ui_out_is_mi_like_p (uiout
))
2406 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2407 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2408 ui_out_text (uiout
, "\nValue = ");
2410 watchpoint_value_print (b
->val
, stb
->stream
);
2411 ui_out_field_stream (uiout
, "new", stb
);
2412 do_cleanups (ui_out_chain
);
2413 ui_out_text (uiout
, "\n");
2414 return PRINT_UNKNOWN
;
2417 /* Fall through, we don't deal with these types of breakpoints
2421 if (ui_out_is_mi_like_p (uiout
))
2424 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2425 return PRINT_UNKNOWN
;
2429 if (ui_out_is_mi_like_p (uiout
))
2432 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2433 return PRINT_UNKNOWN
;
2438 case bp_longjmp_resume
:
2439 case bp_step_resume
:
2440 case bp_watchpoint_scope
:
2443 return PRINT_UNKNOWN
;
2447 /* Generic routine for printing messages indicating why we
2448 stopped. The behavior of this function depends on the value
2449 'print_it' in the bpstat structure. Under some circumstances we
2450 may decide not to print anything here and delegate the task to
2453 static enum print_stop_action
2454 print_bp_stop_message (bpstat bs
)
2456 switch (bs
->print_it
)
2459 /* Nothing should be printed for this bpstat entry. */
2460 return PRINT_UNKNOWN
;
2464 /* We still want to print the frame, but we already printed the
2465 relevant messages. */
2466 return PRINT_SRC_AND_LOC
;
2469 case print_it_normal
:
2471 const struct bp_location
*bl
= bs
->breakpoint_at
;
2472 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2474 /* Normal case. Call the breakpoint's print_it method, or
2475 print_it_typical. */
2476 /* FIXME: how breakpoint can ever be NULL here? */
2477 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2478 return b
->ops
->print_it (b
);
2480 return print_it_typical (bs
);
2485 internal_error (__FILE__
, __LINE__
,
2486 _("print_bp_stop_message: unrecognized enum value"));
2491 /* Print a message indicating what happened. This is called from
2492 normal_stop(). The input to this routine is the head of the bpstat
2493 list - a list of the eventpoints that caused this stop. This
2494 routine calls the generic print routine for printing a message
2495 about reasons for stopping. This will print (for example) the
2496 "Breakpoint n," part of the output. The return value of this
2499 PRINT_UNKNOWN: Means we printed nothing
2500 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2501 code to print the location. An example is
2502 "Breakpoint 1, " which should be followed by
2504 PRINT_SRC_ONLY: Means we printed something, but there is no need
2505 to also print the location part of the message.
2506 An example is the catch/throw messages, which
2507 don't require a location appended to the end.
2508 PRINT_NOTHING: We have done some printing and we don't need any
2509 further info to be printed.*/
2511 enum print_stop_action
2512 bpstat_print (bpstat bs
)
2516 /* Maybe another breakpoint in the chain caused us to stop.
2517 (Currently all watchpoints go on the bpstat whether hit or not.
2518 That probably could (should) be changed, provided care is taken
2519 with respect to bpstat_explains_signal). */
2520 for (; bs
; bs
= bs
->next
)
2522 val
= print_bp_stop_message (bs
);
2523 if (val
== PRINT_SRC_ONLY
2524 || val
== PRINT_SRC_AND_LOC
2525 || val
== PRINT_NOTHING
)
2529 /* We reached the end of the chain, or we got a null BS to start
2530 with and nothing was printed. */
2531 return PRINT_UNKNOWN
;
2534 /* Evaluate the expression EXP and return 1 if value is zero.
2535 This is used inside a catch_errors to evaluate the breakpoint condition.
2536 The argument is a "struct expression *" that has been cast to char * to
2537 make it pass through catch_errors. */
2540 breakpoint_cond_eval (void *exp
)
2542 struct value
*mark
= value_mark ();
2543 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2544 value_free_to_mark (mark
);
2548 /* Allocate a new bpstat and chain it to the current one. */
2551 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2555 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2557 bs
->breakpoint_at
= bl
;
2558 /* If the condition is false, etc., don't do the commands. */
2559 bs
->commands
= NULL
;
2561 bs
->print_it
= print_it_normal
;
2565 /* The target has stopped with waitstatus WS. Check if any hardware
2566 watchpoints have triggered, according to the target. */
2569 watchpoints_triggered (struct target_waitstatus
*ws
)
2571 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2573 struct breakpoint
*b
;
2575 if (!stopped_by_watchpoint
)
2577 /* We were not stopped by a watchpoint. Mark all watchpoints
2578 as not triggered. */
2580 if (b
->type
== bp_hardware_watchpoint
2581 || b
->type
== bp_read_watchpoint
2582 || b
->type
== bp_access_watchpoint
)
2583 b
->watchpoint_triggered
= watch_triggered_no
;
2588 if (!target_stopped_data_address (¤t_target
, &addr
))
2590 /* We were stopped by a watchpoint, but we don't know where.
2591 Mark all watchpoints as unknown. */
2593 if (b
->type
== bp_hardware_watchpoint
2594 || b
->type
== bp_read_watchpoint
2595 || b
->type
== bp_access_watchpoint
)
2596 b
->watchpoint_triggered
= watch_triggered_unknown
;
2598 return stopped_by_watchpoint
;
2601 /* The target could report the data address. Mark watchpoints
2602 affected by this data address as triggered, and all others as not
2606 if (b
->type
== bp_hardware_watchpoint
2607 || b
->type
== bp_read_watchpoint
2608 || b
->type
== bp_access_watchpoint
)
2610 struct bp_location
*loc
;
2613 b
->watchpoint_triggered
= watch_triggered_no
;
2614 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2615 /* Exact match not required. Within range is
2617 if (addr
>= loc
->address
2618 && addr
< loc
->address
+ loc
->length
)
2620 b
->watchpoint_triggered
= watch_triggered_yes
;
2628 /* Possible return values for watchpoint_check (this can't be an enum
2629 because of check_errors). */
2630 /* The watchpoint has been deleted. */
2631 #define WP_DELETED 1
2632 /* The value has changed. */
2633 #define WP_VALUE_CHANGED 2
2634 /* The value has not changed. */
2635 #define WP_VALUE_NOT_CHANGED 3
2637 #define BP_TEMPFLAG 1
2638 #define BP_HARDWAREFLAG 2
2640 /* Check watchpoint condition. */
2643 watchpoint_check (void *p
)
2645 bpstat bs
= (bpstat
) p
;
2646 struct breakpoint
*b
;
2647 struct frame_info
*fr
;
2648 int within_current_scope
;
2650 b
= bs
->breakpoint_at
->owner
;
2652 if (b
->exp_valid_block
== NULL
)
2653 within_current_scope
= 1;
2656 /* There is no current frame at this moment. If we're going to have
2657 any chance of handling watchpoints on local variables, we'll need
2658 the frame chain (so we can determine if we're in scope). */
2659 reinit_frame_cache ();
2660 fr
= frame_find_by_id (b
->watchpoint_frame
);
2661 within_current_scope
= (fr
!= NULL
);
2663 /* If we've gotten confused in the unwinder, we might have
2664 returned a frame that can't describe this variable. */
2665 if (within_current_scope
2666 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2667 within_current_scope
= 0;
2669 /* in_function_epilogue_p() returns a non-zero value if we're still
2670 in the function but the stack frame has already been invalidated.
2671 Since we can't rely on the values of local variables after the
2672 stack has been destroyed, we are treating the watchpoint in that
2673 state as `not changed' without further checking.
2675 vinschen/2003-09-04: The former implementation left out the case
2676 that the watchpoint frame couldn't be found by frame_find_by_id()
2677 because the current PC is currently in an epilogue. Calling
2678 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2679 if ((!within_current_scope
|| fr
== get_current_frame ())
2680 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2681 return WP_VALUE_NOT_CHANGED
;
2682 if (fr
&& within_current_scope
)
2683 /* If we end up stopping, the current frame will get selected
2684 in normal_stop. So this call to select_frame won't affect
2689 if (within_current_scope
)
2691 /* We use value_{,free_to_}mark because it could be a
2692 *long* time before we return to the command level and
2693 call free_all_values. We can't call free_all_values because
2694 we might be in the middle of evaluating a function call. */
2696 struct value
*mark
= value_mark ();
2697 struct value
*new_val
;
2699 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2700 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2701 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2703 if (new_val
!= NULL
)
2705 release_value (new_val
);
2706 value_free_to_mark (mark
);
2708 bs
->old_val
= b
->val
;
2711 /* We will stop here */
2712 return WP_VALUE_CHANGED
;
2716 /* Nothing changed, don't do anything. */
2717 value_free_to_mark (mark
);
2718 /* We won't stop here */
2719 return WP_VALUE_NOT_CHANGED
;
2724 /* This seems like the only logical thing to do because
2725 if we temporarily ignored the watchpoint, then when
2726 we reenter the block in which it is valid it contains
2727 garbage (in the case of a function, it may have two
2728 garbage values, one before and one after the prologue).
2729 So we can't even detect the first assignment to it and
2730 watch after that (since the garbage may or may not equal
2731 the first value assigned). */
2732 /* We print all the stop information in print_it_typical(), but
2733 in this case, by the time we call print_it_typical() this bp
2734 will be deleted already. So we have no choice but print the
2735 information here. */
2736 if (ui_out_is_mi_like_p (uiout
))
2738 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2739 ui_out_text (uiout
, "\nWatchpoint ");
2740 ui_out_field_int (uiout
, "wpnum", b
->number
);
2741 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2742 which its expression is valid.\n");
2744 if (b
->related_breakpoint
)
2745 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2746 b
->disposition
= disp_del_at_next_stop
;
2752 /* Get a bpstat associated with having just stopped at address
2753 BP_ADDR in thread PTID.
2755 Determine whether we stopped at a breakpoint, etc, or whether we
2756 don't understand this stop. Result is a chain of bpstat's such that:
2758 if we don't understand the stop, the result is a null pointer.
2760 if we understand why we stopped, the result is not null.
2762 Each element of the chain refers to a particular breakpoint or
2763 watchpoint at which we have stopped. (We may have stopped for
2764 several reasons concurrently.)
2766 Each element of the chain has valid next, breakpoint_at,
2767 commands, FIXME??? fields. */
2770 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2772 struct breakpoint
*b
= NULL
;
2773 const struct bp_location
*bl
;
2774 /* Root of the chain of bpstat's */
2775 struct bpstats root_bs
[1];
2776 /* Pointer to the last thing in the chain currently. */
2777 bpstat bs
= root_bs
;
2778 int thread_id
= pid_to_thread_id (ptid
);
2780 ALL_BP_LOCATIONS (bl
)
2784 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2787 if (b
->type
!= bp_watchpoint
2788 && b
->type
!= bp_hardware_watchpoint
2789 && b
->type
!= bp_read_watchpoint
2790 && b
->type
!= bp_access_watchpoint
2791 && b
->type
!= bp_hardware_breakpoint
2792 && b
->type
!= bp_catch_fork
2793 && b
->type
!= bp_catch_vfork
2794 && b
->type
!= bp_catch_exec
) /* a non-watchpoint bp */
2796 if (bl
->address
!= bp_addr
) /* address doesn't match */
2798 if (overlay_debugging
/* unmapped overlay section */
2799 && section_is_overlay (bl
->section
)
2800 && !section_is_mapped (bl
->section
))
2804 /* Continuable hardware watchpoints are treated as non-existent if the
2805 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2806 some data address). Otherwise gdb won't stop on a break instruction
2807 in the code (not from a breakpoint) when a hardware watchpoint has
2808 been defined. Also skip watchpoints which we know did not trigger
2809 (did not match the data address). */
2811 if ((b
->type
== bp_hardware_watchpoint
2812 || b
->type
== bp_read_watchpoint
2813 || b
->type
== bp_access_watchpoint
)
2814 && b
->watchpoint_triggered
== watch_triggered_no
)
2817 if (b
->type
== bp_hardware_breakpoint
)
2819 if (bl
->address
!= bp_addr
)
2821 if (overlay_debugging
/* unmapped overlay section */
2822 && section_is_overlay (bl
->section
)
2823 && !section_is_mapped (bl
->section
))
2827 /* Is this a catchpoint of a load or unload? If so, did we
2828 get a load or unload of the specified library? If not,
2830 if ((b
->type
== bp_catch_load
)
2831 #if defined(SOLIB_HAVE_LOAD_EVENT)
2832 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2833 || ((b
->dll_pathname
!= NULL
)
2834 && (strcmp (b
->dll_pathname
,
2835 SOLIB_LOADED_LIBRARY_PATHNAME (
2836 PIDGET (inferior_ptid
)))
2842 if ((b
->type
== bp_catch_unload
)
2843 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2844 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2845 || ((b
->dll_pathname
!= NULL
)
2846 && (strcmp (b
->dll_pathname
,
2847 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2848 PIDGET (inferior_ptid
)))
2854 if ((b
->type
== bp_catch_fork
)
2855 && !inferior_has_forked (PIDGET (inferior_ptid
),
2856 &b
->forked_inferior_pid
))
2859 if ((b
->type
== bp_catch_vfork
)
2860 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2861 &b
->forked_inferior_pid
))
2864 if ((b
->type
== bp_catch_exec
)
2865 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2868 /* For hardware watchpoints, we look only at the first location.
2869 The watchpoint_check function will work on entire expression,
2870 not the individual locations. For read watchopints, the
2871 watchpoints_triggered function have checked all locations
2874 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
2877 /* Come here if it's a watchpoint, or if the break address matches */
2879 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
2881 /* Watchpoints may change this, if not found to have triggered. */
2885 if (b
->type
== bp_watchpoint
2886 || b
->type
== bp_read_watchpoint
2887 || b
->type
== bp_access_watchpoint
2888 || b
->type
== bp_hardware_watchpoint
)
2892 int must_check_value
= 0;
2894 if (b
->type
== bp_watchpoint
)
2895 /* For a software watchpoint, we must always check the
2897 must_check_value
= 1;
2898 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2899 /* We have a hardware watchpoint (read, write, or access)
2900 and the target earlier reported an address watched by
2902 must_check_value
= 1;
2903 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2904 && b
->type
== bp_hardware_watchpoint
)
2905 /* We were stopped by a hardware watchpoint, but the target could
2906 not report the data address. We must check the watchpoint's
2907 value. Access and read watchpoints are out of luck; without
2908 a data address, we can't figure it out. */
2909 must_check_value
= 1;
2911 if (must_check_value
)
2913 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2915 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2916 int e
= catch_errors (watchpoint_check
, bs
, message
,
2918 do_cleanups (cleanups
);
2922 /* We've already printed what needs to be printed. */
2923 bs
->print_it
= print_it_done
;
2926 case WP_VALUE_CHANGED
:
2927 if (b
->type
== bp_read_watchpoint
)
2929 /* Don't stop: read watchpoints shouldn't fire if
2930 the value has changed. This is for targets
2931 which cannot set read-only watchpoints. */
2932 bs
->print_it
= print_it_noop
;
2938 case WP_VALUE_NOT_CHANGED
:
2939 if (b
->type
== bp_hardware_watchpoint
2940 || b
->type
== bp_watchpoint
)
2942 /* Don't stop: write watchpoints shouldn't fire if
2943 the value hasn't changed. */
2944 bs
->print_it
= print_it_noop
;
2954 /* Error from catch_errors. */
2955 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2956 if (b
->related_breakpoint
)
2957 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2958 b
->disposition
= disp_del_at_next_stop
;
2959 /* We've already printed what needs to be printed. */
2960 bs
->print_it
= print_it_done
;
2964 else /* must_check_value == 0 */
2966 /* This is a case where some watchpoint(s) triggered, but
2967 not at the address of this watchpoint, or else no
2968 watchpoint triggered after all. So don't print
2969 anything for this watchpoint. */
2970 bs
->print_it
= print_it_noop
;
2977 /* By definition, an encountered breakpoint is a triggered
2982 if (frame_id_p (b
->frame_id
)
2983 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2987 int value_is_zero
= 0;
2989 /* If this is a scope breakpoint, mark the associated
2990 watchpoint as triggered so that we will handle the
2991 out-of-scope event. We'll get to the watchpoint next
2993 if (b
->type
== bp_watchpoint_scope
)
2994 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2996 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2998 /* Need to select the frame, with all that implies
2999 so that the conditions will have the right context. */
3000 select_frame (get_current_frame ());
3002 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
3003 "Error in testing breakpoint condition:\n",
3005 /* FIXME-someday, should give breakpoint # */
3008 if (bl
->cond
&& value_is_zero
)
3011 /* Don't consider this a hit. */
3014 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3017 /* Don't consider this a hit. */
3020 else if (b
->ignore_count
> 0)
3023 annotate_ignore_count_change ();
3026 else if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3027 /* We do not stop for these. */
3031 /* We will stop here */
3032 if (b
->disposition
== disp_disable
)
3034 b
->enable_state
= bp_disabled
;
3035 update_global_location_list ();
3039 bs
->commands
= b
->commands
;
3041 (strcmp ("silent", bs
->commands
->line
) == 0
3042 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3044 bs
->commands
= bs
->commands
->next
;
3047 bs
->commands
= copy_command_lines (bs
->commands
);
3050 /* Print nothing for this entry if we dont stop or if we dont print. */
3051 if (bs
->stop
== 0 || bs
->print
== 0)
3052 bs
->print_it
= print_it_noop
;
3055 bs
->next
= NULL
; /* Terminate the chain */
3056 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3058 /* If we aren't stopping, the value of some hardware watchpoint may
3059 not have changed, but the intermediate memory locations we are
3060 watching may have. Don't bother if we're stopping; this will get
3062 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3067 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3069 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3070 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3071 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3073 /* remove/insert can invalidate bs->breakpoint_at, if this
3074 location is no longer used by the watchpoint. Prevent
3075 further code from trying to use it. */
3076 bs
->breakpoint_at
= NULL
;
3077 remove_breakpoints ();
3078 insert_breakpoints ();
3082 return root_bs
->next
;
3085 /* Tell what to do about this bpstat. */
3087 bpstat_what (bpstat bs
)
3089 /* Classify each bpstat as one of the following. */
3092 /* This bpstat element has no effect on the main_action. */
3095 /* There was a watchpoint, stop but don't print. */
3098 /* There was a watchpoint, stop and print. */
3101 /* There was a breakpoint but we're not stopping. */
3104 /* There was a breakpoint, stop but don't print. */
3107 /* There was a breakpoint, stop and print. */
3110 /* We hit the longjmp breakpoint. */
3113 /* We hit the longjmp_resume breakpoint. */
3116 /* We hit the step_resume breakpoint. */
3119 /* We hit the shared library event breakpoint. */
3122 /* We caught a shared library event. */
3125 /* This is just used to count how many enums there are. */
3129 /* Here is the table which drives this routine. So that we can
3130 format it pretty, we define some abbreviations for the
3131 enum bpstat_what codes. */
3132 #define kc BPSTAT_WHAT_KEEP_CHECKING
3133 #define ss BPSTAT_WHAT_STOP_SILENT
3134 #define sn BPSTAT_WHAT_STOP_NOISY
3135 #define sgl BPSTAT_WHAT_SINGLE
3136 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3137 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3138 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
3139 #define sr BPSTAT_WHAT_STEP_RESUME
3140 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3141 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3143 /* "Can't happen." Might want to print an error message.
3144 abort() is not out of the question, but chances are GDB is just
3145 a bit confused, not unusable. */
3146 #define err BPSTAT_WHAT_STOP_NOISY
3148 /* Given an old action and a class, come up with a new action. */
3149 /* One interesting property of this table is that wp_silent is the same
3150 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3151 after stopping, the check for whether to step over a breakpoint
3152 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3153 reference to how we stopped. We retain separate wp_silent and
3154 bp_silent codes in case we want to change that someday.
3156 Another possibly interesting property of this table is that
3157 there's a partial ordering, priority-like, of the actions. Once
3158 you've decided that some action is appropriate, you'll never go
3159 back and decide something of a lower priority is better. The
3162 kc < clr sgl shl shlr slr sn sr ss
3163 sgl < clrs shl shlr slr sn sr ss
3164 slr < err shl shlr sn sr ss
3165 clr < clrs err shl shlr sn sr ss
3166 clrs < err shl shlr sn sr ss
3173 What I think this means is that we don't need a damned table
3174 here. If you just put the rows and columns in the right order,
3175 it'd look awfully regular. We could simply walk the bpstat list
3176 and choose the highest priority action we find, with a little
3177 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3178 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3179 is messy anyway). */
3181 /* step_resume entries: a step resume breakpoint overrides another
3182 breakpoint of signal handling (see comment in wait_for_inferior
3183 at where we set the step_resume breakpoint). */
3185 static const enum bpstat_what_main_action
3186 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3189 /* kc ss sn sgl slr clr clrs sr shl shlr
3192 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, shl
, shlr
},
3194 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3196 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3198 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, shl
, shlr
},
3200 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3202 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3204 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, shl
, shlr
},
3206 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, shl
, shlr
},
3208 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3210 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3212 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3227 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3228 struct bpstat_what retval
;
3230 retval
.call_dummy
= 0;
3231 for (; bs
!= NULL
; bs
= bs
->next
)
3233 enum class bs_class
= no_effect
;
3234 if (bs
->breakpoint_at
== NULL
)
3235 /* I suspect this can happen if it was a momentary breakpoint
3236 which has since been deleted. */
3238 switch (bs
->breakpoint_at
->owner
->type
)
3244 case bp_hardware_breakpoint
:
3250 bs_class
= bp_noisy
;
3252 bs_class
= bp_silent
;
3255 bs_class
= bp_nostop
;
3258 case bp_hardware_watchpoint
:
3259 case bp_read_watchpoint
:
3260 case bp_access_watchpoint
:
3264 bs_class
= wp_noisy
;
3266 bs_class
= wp_silent
;
3269 /* There was a watchpoint, but we're not stopping.
3270 This requires no further action. */
3271 bs_class
= no_effect
;
3274 bs_class
= long_jump
;
3276 case bp_longjmp_resume
:
3277 bs_class
= long_resume
;
3279 case bp_step_resume
:
3282 bs_class
= step_resume
;
3285 /* It is for the wrong frame. */
3286 bs_class
= bp_nostop
;
3288 case bp_watchpoint_scope
:
3289 bs_class
= bp_nostop
;
3291 case bp_shlib_event
:
3292 bs_class
= shlib_event
;
3294 case bp_thread_event
:
3295 case bp_overlay_event
:
3296 bs_class
= bp_nostop
;
3299 case bp_catch_unload
:
3300 /* Only if this catchpoint triggered should we cause the
3301 step-out-of-dld behaviour. Otherwise, we ignore this
3304 bs_class
= catch_shlib_event
;
3306 bs_class
= no_effect
;
3309 case bp_catch_vfork
:
3314 bs_class
= bp_noisy
;
3316 bs_class
= bp_silent
;
3319 /* There was a catchpoint, but we're not stopping.
3320 This requires no further action. */
3321 bs_class
= no_effect
;
3324 /* Make sure the action is stop (silent or noisy),
3325 so infrun.c pops the dummy frame. */
3326 bs_class
= bp_silent
;
3327 retval
.call_dummy
= 1;
3330 current_action
= table
[(int) bs_class
][(int) current_action
];
3332 retval
.main_action
= current_action
;
3336 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3337 without hardware support). This isn't related to a specific bpstat,
3338 just to things like whether watchpoints are set. */
3341 bpstat_should_step (void)
3343 struct breakpoint
*b
;
3345 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3352 /* Given a bpstat that records zero or more triggered eventpoints, this
3353 function returns another bpstat which contains only the catchpoints
3354 on that first list, if any. */
3356 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3358 struct bpstats root_bs
[1];
3359 bpstat bs
= root_bs
;
3360 struct breakpoint
*ep
;
3363 bpstat_clear (cp_list
);
3364 root_bs
->next
= NULL
;
3366 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3368 /* Is this eventpoint a catchpoint? If not, ignore it. */
3369 ep
= ep_list
->breakpoint_at
->owner
;
3372 if ((ep
->type
!= bp_catch_load
) &&
3373 (ep
->type
!= bp_catch_unload
))
3374 /* pai: (temp) ADD fork/vfork here!! */
3377 /* Yes; add it to the list. */
3378 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3383 #if defined(SOLIB_ADD)
3384 /* Also, for each triggered catchpoint, tag it with the name of
3385 the library that caused this trigger. (We copy the name now,
3386 because it's only guaranteed to be available NOW, when the
3387 catchpoint triggers. Clients who may wish to know the name
3388 later must get it from the catchpoint itself.) */
3389 if (ep
->triggered_dll_pathname
!= NULL
)
3390 xfree (ep
->triggered_dll_pathname
);
3391 if (ep
->type
== bp_catch_load
)
3392 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3393 PIDGET (inferior_ptid
));
3395 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3396 PIDGET (inferior_ptid
));
3398 dll_pathname
= NULL
;
3402 ep
->triggered_dll_pathname
= (char *)
3403 xmalloc (strlen (dll_pathname
) + 1);
3404 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3407 ep
->triggered_dll_pathname
= NULL
;
3413 static void print_breakpoint_location (struct breakpoint
*b
,
3414 struct bp_location
*loc
,
3416 struct ui_stream
*stb
)
3421 = find_pc_sect_function (loc
->address
, loc
->section
);
3424 ui_out_text (uiout
, "in ");
3425 ui_out_field_string (uiout
, "func",
3426 SYMBOL_PRINT_NAME (sym
));
3427 ui_out_wrap_hint (uiout
, wrap_indent
);
3428 ui_out_text (uiout
, " at ");
3430 ui_out_field_string (uiout
, "file", b
->source_file
);
3431 ui_out_text (uiout
, ":");
3433 if (ui_out_is_mi_like_p (uiout
))
3435 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3436 char *fullname
= symtab_to_fullname (sal
.symtab
);
3439 ui_out_field_string (uiout
, "fullname", fullname
);
3442 ui_out_field_int (uiout
, "line", b
->line_number
);
3446 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3450 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3451 ui_out_field_stream (uiout
, "at", stb
);
3455 /* Print B to gdb_stdout. */
3457 print_one_breakpoint_location (struct breakpoint
*b
,
3458 struct bp_location
*loc
,
3460 CORE_ADDR
*last_addr
)
3462 struct command_line
*l
;
3464 struct ep_type_description
3469 static struct ep_type_description bptypes
[] =
3471 {bp_none
, "?deleted?"},
3472 {bp_breakpoint
, "breakpoint"},
3473 {bp_hardware_breakpoint
, "hw breakpoint"},
3474 {bp_until
, "until"},
3475 {bp_finish
, "finish"},
3476 {bp_watchpoint
, "watchpoint"},
3477 {bp_hardware_watchpoint
, "hw watchpoint"},
3478 {bp_read_watchpoint
, "read watchpoint"},
3479 {bp_access_watchpoint
, "acc watchpoint"},
3480 {bp_longjmp
, "longjmp"},
3481 {bp_longjmp_resume
, "longjmp resume"},
3482 {bp_step_resume
, "step resume"},
3483 {bp_watchpoint_scope
, "watchpoint scope"},
3484 {bp_call_dummy
, "call dummy"},
3485 {bp_shlib_event
, "shlib events"},
3486 {bp_thread_event
, "thread events"},
3487 {bp_overlay_event
, "overlay events"},
3488 {bp_catch_load
, "catch load"},
3489 {bp_catch_unload
, "catch unload"},
3490 {bp_catch_fork
, "catch fork"},
3491 {bp_catch_vfork
, "catch vfork"},
3492 {bp_catch_exec
, "catch exec"}
3495 static char bpenables
[] = "nynny";
3496 char wrap_indent
[80];
3497 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3498 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3499 struct cleanup
*bkpt_chain
;
3501 int header_of_multiple
= 0;
3502 int part_of_multiple
= (loc
!= NULL
);
3504 gdb_assert (!loc
|| loc_number
!= 0);
3505 /* See comment in print_one_breakpoint concerning
3506 treatment of breakpoints with single disabled
3510 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3511 header_of_multiple
= 1;
3516 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3520 if (part_of_multiple
)
3523 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3524 ui_out_field_string (uiout
, "number", formatted
);
3529 ui_out_field_int (uiout
, "number", b
->number
);
3534 if (part_of_multiple
)
3535 ui_out_field_skip (uiout
, "type");
3538 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3539 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3540 internal_error (__FILE__
, __LINE__
,
3541 _("bptypes table does not describe type #%d."),
3543 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3548 if (part_of_multiple
)
3549 ui_out_field_skip (uiout
, "disp");
3551 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3556 if (part_of_multiple
)
3557 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3559 ui_out_field_fmt (uiout
, "enabled", "%c",
3560 bpenables
[(int) b
->enable_state
]);
3561 ui_out_spaces (uiout
, 2);
3565 strcpy (wrap_indent
, " ");
3568 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3569 strcat (wrap_indent
, " ");
3571 strcat (wrap_indent
, " ");
3574 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3576 /* Although the print_one can possibly print
3577 all locations, calling it here is not likely
3578 to get any nice result. So, make sure there's
3579 just one location. */
3580 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3581 b
->ops
->print_one (b
, last_addr
);
3587 internal_error (__FILE__
, __LINE__
,
3588 _("print_one_breakpoint: bp_none encountered\n"));
3592 case bp_hardware_watchpoint
:
3593 case bp_read_watchpoint
:
3594 case bp_access_watchpoint
:
3595 /* Field 4, the address, is omitted (which makes the columns
3596 not line up too nicely with the headers, but the effect
3597 is relatively readable). */
3599 ui_out_field_skip (uiout
, "addr");
3601 print_expression (b
->exp
, stb
->stream
);
3602 ui_out_field_stream (uiout
, "what", stb
);
3606 case bp_catch_unload
:
3607 /* Field 4, the address, is omitted (which makes the columns
3608 not line up too nicely with the headers, but the effect
3609 is relatively readable). */
3611 ui_out_field_skip (uiout
, "addr");
3613 if (b
->dll_pathname
== NULL
)
3615 ui_out_field_string (uiout
, "what", "<any library>");
3616 ui_out_spaces (uiout
, 1);
3620 ui_out_text (uiout
, "library \"");
3621 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3622 ui_out_text (uiout
, "\" ");
3627 case bp_catch_vfork
:
3628 /* Field 4, the address, is omitted (which makes the columns
3629 not line up too nicely with the headers, but the effect
3630 is relatively readable). */
3632 ui_out_field_skip (uiout
, "addr");
3634 if (b
->forked_inferior_pid
!= 0)
3636 ui_out_text (uiout
, "process ");
3637 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3638 ui_out_spaces (uiout
, 1);
3643 /* Field 4, the address, is omitted (which makes the columns
3644 not line up too nicely with the headers, but the effect
3645 is relatively readable). */
3647 ui_out_field_skip (uiout
, "addr");
3649 if (b
->exec_pathname
!= NULL
)
3651 ui_out_text (uiout
, "program \"");
3652 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3653 ui_out_text (uiout
, "\" ");
3658 case bp_hardware_breakpoint
:
3662 case bp_longjmp_resume
:
3663 case bp_step_resume
:
3664 case bp_watchpoint_scope
:
3666 case bp_shlib_event
:
3667 case bp_thread_event
:
3668 case bp_overlay_event
:
3672 if (header_of_multiple
)
3673 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3674 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3675 ui_out_field_string (uiout
, "addr", "<PENDING>");
3677 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3680 if (!header_of_multiple
)
3681 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3683 *last_addr
= b
->loc
->address
;
3687 if (!part_of_multiple
&& b
->thread
!= -1)
3689 /* FIXME: This seems to be redundant and lost here; see the
3690 "stop only in" line a little further down. */
3691 ui_out_text (uiout
, " thread ");
3692 ui_out_field_int (uiout
, "thread", b
->thread
);
3695 ui_out_text (uiout
, "\n");
3697 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3700 ui_out_text (uiout
, "\tstop only in stack frame at ");
3701 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3703 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3704 ui_out_text (uiout
, "\n");
3707 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3709 /* We do not print the condition for Ada exception catchpoints
3710 because the condition is an internal implementation detail
3711 that we do not want to expose to the user. */
3713 ui_out_text (uiout
, "\tstop only if ");
3714 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3715 ui_out_text (uiout
, "\n");
3718 if (!part_of_multiple
&& b
->thread
!= -1)
3720 /* FIXME should make an annotation for this */
3721 ui_out_text (uiout
, "\tstop only in thread ");
3722 ui_out_field_int (uiout
, "thread", b
->thread
);
3723 ui_out_text (uiout
, "\n");
3726 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3728 /* FIXME should make an annotation for this */
3729 if (ep_is_catchpoint (b
))
3730 ui_out_text (uiout
, "\tcatchpoint");
3732 ui_out_text (uiout
, "\tbreakpoint");
3733 ui_out_text (uiout
, " already hit ");
3734 ui_out_field_int (uiout
, "times", b
->hit_count
);
3735 if (b
->hit_count
== 1)
3736 ui_out_text (uiout
, " time\n");
3738 ui_out_text (uiout
, " times\n");
3741 /* Output the count also if it is zero, but only if this is
3742 mi. FIXME: Should have a better test for this. */
3743 if (ui_out_is_mi_like_p (uiout
))
3744 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3745 ui_out_field_int (uiout
, "times", b
->hit_count
);
3747 if (!part_of_multiple
&& b
->ignore_count
)
3750 ui_out_text (uiout
, "\tignore next ");
3751 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3752 ui_out_text (uiout
, " hits\n");
3755 if (!part_of_multiple
&& (l
= b
->commands
))
3757 struct cleanup
*script_chain
;
3760 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3761 print_command_lines (uiout
, l
, 4);
3762 do_cleanups (script_chain
);
3765 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3768 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3769 else if (b
->exp_string
)
3770 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3773 do_cleanups (bkpt_chain
);
3774 do_cleanups (old_chain
);
3778 print_one_breakpoint (struct breakpoint
*b
,
3779 CORE_ADDR
*last_addr
)
3781 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3783 /* If this breakpoint has custom print function,
3784 it's already printed. Otherwise, print individual
3785 locations, if any. */
3786 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3788 /* If breakpoint has a single location that is
3789 disabled, we print it as if it had
3790 several locations, since otherwise it's hard to
3791 represent "breakpoint enabled, location disabled"
3793 Note that while hardware watchpoints have
3794 several locations internally, that's no a property
3797 && !is_hardware_watchpoint (b
)
3798 && (b
->loc
->next
|| !b
->loc
->enabled
)
3799 && !ui_out_is_mi_like_p (uiout
))
3801 struct bp_location
*loc
;
3803 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3804 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3810 struct captured_breakpoint_query_args
3816 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3818 struct captured_breakpoint_query_args
*args
= data
;
3819 struct breakpoint
*b
;
3820 CORE_ADDR dummy_addr
= 0;
3823 if (args
->bnum
== b
->number
)
3825 print_one_breakpoint (b
, &dummy_addr
);
3833 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3835 struct captured_breakpoint_query_args args
;
3837 /* For the moment we don't trust print_one_breakpoint() to not throw
3839 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3840 error_message
, RETURN_MASK_ALL
) < 0)
3846 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3847 catchpoints, et.al.). */
3850 user_settable_breakpoint (const struct breakpoint
*b
)
3852 return (b
->type
== bp_breakpoint
3853 || b
->type
== bp_catch_load
3854 || b
->type
== bp_catch_unload
3855 || b
->type
== bp_catch_fork
3856 || b
->type
== bp_catch_vfork
3857 || b
->type
== bp_catch_exec
3858 || b
->type
== bp_hardware_breakpoint
3859 || b
->type
== bp_watchpoint
3860 || b
->type
== bp_read_watchpoint
3861 || b
->type
== bp_access_watchpoint
3862 || b
->type
== bp_hardware_watchpoint
);
3865 /* Print information on user settable breakpoint (watchpoint, etc)
3866 number BNUM. If BNUM is -1 print all user settable breakpoints.
3867 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3870 breakpoint_1 (int bnum
, int allflag
)
3872 struct breakpoint
*b
;
3873 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3874 int nr_printable_breakpoints
;
3875 struct cleanup
*bkpttbl_chain
;
3877 /* Compute the number of rows in the table. */
3878 nr_printable_breakpoints
= 0;
3881 || bnum
== b
->number
)
3883 if (allflag
|| user_settable_breakpoint (b
))
3884 nr_printable_breakpoints
++;
3889 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3893 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3896 if (nr_printable_breakpoints
> 0)
3897 annotate_breakpoints_headers ();
3898 if (nr_printable_breakpoints
> 0)
3900 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3901 if (nr_printable_breakpoints
> 0)
3903 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3904 if (nr_printable_breakpoints
> 0)
3906 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3907 if (nr_printable_breakpoints
> 0)
3909 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3912 if (nr_printable_breakpoints
> 0)
3914 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3915 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3917 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3919 if (nr_printable_breakpoints
> 0)
3921 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3922 ui_out_table_body (uiout
);
3923 if (nr_printable_breakpoints
> 0)
3924 annotate_breakpoints_table ();
3928 || bnum
== b
->number
)
3930 /* We only print out user settable breakpoints unless the
3932 if (allflag
|| user_settable_breakpoint (b
))
3933 print_one_breakpoint (b
, &last_addr
);
3936 do_cleanups (bkpttbl_chain
);
3938 if (nr_printable_breakpoints
== 0)
3941 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3943 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3948 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3949 that a comparison of an unsigned with -1 is always false. */
3950 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3951 set_next_address (last_addr
);
3954 /* FIXME? Should this be moved up so that it is only called when
3955 there have been breakpoints? */
3956 annotate_breakpoints_table_end ();
3960 breakpoints_info (char *bnum_exp
, int from_tty
)
3965 bnum
= parse_and_eval_long (bnum_exp
);
3967 breakpoint_1 (bnum
, 0);
3971 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3976 bnum
= parse_and_eval_long (bnum_exp
);
3978 breakpoint_1 (bnum
, 1);
3982 breakpoint_has_pc (struct breakpoint
*b
, CORE_ADDR pc
, asection
*section
)
3984 struct bp_location
*bl
= b
->loc
;
3985 for (; bl
; bl
= bl
->next
)
3987 if (bl
->address
== pc
3988 && (!overlay_debugging
|| bl
->section
== section
))
3994 /* Print a message describing any breakpoints set at PC. */
3997 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
4000 struct breakpoint
*b
;
4003 others
+= breakpoint_has_pc (b
, pc
, section
);
4007 printf_filtered (_("Note: breakpoint "));
4008 else /* if (others == ???) */
4009 printf_filtered (_("Note: breakpoints "));
4011 if (breakpoint_has_pc (b
, pc
, section
))
4014 printf_filtered ("%d", b
->number
);
4015 if (b
->thread
== -1 && thread
!= -1)
4016 printf_filtered (" (all threads)");
4017 else if (b
->thread
!= -1)
4018 printf_filtered (" (thread %d)", b
->thread
);
4019 printf_filtered ("%s%s ",
4020 ((b
->enable_state
== bp_disabled
||
4021 b
->enable_state
== bp_call_disabled
)
4023 : b
->enable_state
== bp_permanent
4027 : ((others
== 1) ? " and" : ""));
4029 printf_filtered (_("also set at pc "));
4030 fputs_filtered (paddress (pc
), gdb_stdout
);
4031 printf_filtered (".\n");
4035 /* Set the default place to put a breakpoint
4036 for the `break' command with no arguments. */
4039 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4042 default_breakpoint_valid
= valid
;
4043 default_breakpoint_address
= addr
;
4044 default_breakpoint_symtab
= symtab
;
4045 default_breakpoint_line
= line
;
4048 /* Return true iff it is meaningful to use the address member of
4049 BPT. For some breakpoint types, the address member is irrelevant
4050 and it makes no sense to attempt to compare it to other addresses
4051 (or use it for any other purpose either).
4053 More specifically, each of the following breakpoint types will always
4054 have a zero valued address and we don't want check_duplicates() to mark
4055 breakpoints of any of these types to be a duplicate of an actual
4056 breakpoint at address zero:
4059 bp_hardware_watchpoint
4061 bp_access_watchpoint
4068 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4070 enum bptype type
= bpt
->type
;
4072 return (type
!= bp_watchpoint
4073 && type
!= bp_hardware_watchpoint
4074 && type
!= bp_read_watchpoint
4075 && type
!= bp_access_watchpoint
4076 && type
!= bp_catch_exec
4077 && type
!= bp_longjmp_resume
4078 && type
!= bp_catch_fork
4079 && type
!= bp_catch_vfork
);
4082 /* Rescan breakpoints at the same address and section as BPT,
4083 marking the first one as "first" and any others as "duplicates".
4084 This is so that the bpt instruction is only inserted once.
4085 If we have a permanent breakpoint at the same place as BPT, make
4086 that one the official one, and the rest as duplicates. */
4089 check_duplicates_for (CORE_ADDR address
, asection
*section
)
4091 struct bp_location
*b
;
4093 struct bp_location
*perm_bp
= 0;
4095 ALL_BP_LOCATIONS (b
)
4096 if (b
->owner
->enable_state
!= bp_disabled
4097 && b
->owner
->enable_state
!= bp_call_disabled
4099 && !b
->shlib_disabled
4100 && b
->address
== address
/* address / overlay match */
4101 && (!overlay_debugging
|| b
->section
== section
)
4102 && breakpoint_address_is_meaningful (b
->owner
))
4104 /* Have we found a permanent breakpoint? */
4105 if (b
->owner
->enable_state
== bp_permanent
)
4112 b
->duplicate
= count
> 1;
4115 /* If we found a permanent breakpoint at this address, go over the
4116 list again and declare all the other breakpoints there to be the
4120 perm_bp
->duplicate
= 0;
4122 /* Permanent breakpoint should always be inserted. */
4123 if (! perm_bp
->inserted
)
4124 internal_error (__FILE__
, __LINE__
,
4125 _("allegedly permanent breakpoint is not "
4126 "actually inserted"));
4128 ALL_BP_LOCATIONS (b
)
4131 if (b
->owner
->enable_state
!= bp_disabled
4132 && b
->owner
->enable_state
!= bp_call_disabled
4133 && b
->enabled
&& !b
->shlib_disabled
4134 && b
->address
== address
/* address / overlay match */
4135 && (!overlay_debugging
|| b
->section
== section
)
4136 && breakpoint_address_is_meaningful (b
->owner
))
4139 internal_error (__FILE__
, __LINE__
,
4140 _("another breakpoint was inserted on top of "
4141 "a permanent breakpoint"));
4150 check_duplicates (struct breakpoint
*bpt
)
4152 struct bp_location
*bl
= bpt
->loc
;
4154 if (! breakpoint_address_is_meaningful (bpt
))
4157 for (; bl
; bl
= bl
->next
)
4158 check_duplicates_for (bl
->address
, bl
->section
);
4162 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4163 int bnum
, int have_bnum
)
4168 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4169 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4171 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4172 bnum
, astr1
, astr2
);
4174 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4177 /* Adjust a breakpoint's address to account for architectural constraints
4178 on breakpoint placement. Return the adjusted address. Note: Very
4179 few targets require this kind of adjustment. For most targets,
4180 this function is simply the identity function. */
4183 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4185 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4187 /* Very few targets need any kind of breakpoint adjustment. */
4190 else if (bptype
== bp_watchpoint
4191 || bptype
== bp_hardware_watchpoint
4192 || bptype
== bp_read_watchpoint
4193 || bptype
== bp_access_watchpoint
4194 || bptype
== bp_catch_fork
4195 || bptype
== bp_catch_vfork
4196 || bptype
== bp_catch_exec
)
4198 /* Watchpoints and the various bp_catch_* eventpoints should not
4199 have their addresses modified. */
4204 CORE_ADDR adjusted_bpaddr
;
4206 /* Some targets have architectural constraints on the placement
4207 of breakpoint instructions. Obtain the adjusted address. */
4208 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4211 /* An adjusted breakpoint address can significantly alter
4212 a user's expectations. Print a warning if an adjustment
4214 if (adjusted_bpaddr
!= bpaddr
)
4215 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4217 return adjusted_bpaddr
;
4221 /* Allocate a struct bp_location. */
4223 static struct bp_location
*
4224 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4226 struct bp_location
*loc
, *loc_p
;
4228 loc
= xmalloc (sizeof (struct bp_location
));
4229 memset (loc
, 0, sizeof (*loc
));
4233 loc
->shlib_disabled
= 0;
4242 case bp_longjmp_resume
:
4243 case bp_step_resume
:
4244 case bp_watchpoint_scope
:
4246 case bp_shlib_event
:
4247 case bp_thread_event
:
4248 case bp_overlay_event
:
4250 case bp_catch_unload
:
4251 loc
->loc_type
= bp_loc_software_breakpoint
;
4253 case bp_hardware_breakpoint
:
4254 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4256 case bp_hardware_watchpoint
:
4257 case bp_read_watchpoint
:
4258 case bp_access_watchpoint
:
4259 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4263 case bp_catch_vfork
:
4265 loc
->loc_type
= bp_loc_other
;
4268 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4274 static void free_bp_location (struct bp_location
*loc
)
4279 if (loc
->function_name
)
4280 xfree (loc
->function_name
);
4285 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4286 that has type BPTYPE and has no locations as yet. */
4288 static struct breakpoint
*
4289 set_raw_breakpoint_without_location (enum bptype bptype
)
4291 struct breakpoint
*b
, *b1
;
4293 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4294 memset (b
, 0, sizeof (*b
));
4297 b
->language
= current_language
->la_language
;
4298 b
->input_radix
= input_radix
;
4300 b
->enable_state
= bp_enabled
;
4303 b
->ignore_count
= 0;
4305 b
->frame_id
= null_frame_id
;
4306 b
->dll_pathname
= NULL
;
4307 b
->triggered_dll_pathname
= NULL
;
4308 b
->forked_inferior_pid
= 0;
4309 b
->exec_pathname
= NULL
;
4311 b
->condition_not_parsed
= 0;
4313 /* Add this breakpoint to the end of the chain
4314 so that a list of breakpoints will come out in order
4315 of increasing numbers. */
4317 b1
= breakpoint_chain
;
4319 breakpoint_chain
= b
;
4329 /* Initialize loc->function_name. */
4331 set_breakpoint_location_function (struct bp_location
*loc
)
4333 if (loc
->owner
->type
== bp_breakpoint
4334 || loc
->owner
->type
== bp_hardware_breakpoint
)
4336 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4338 if (loc
->function_name
)
4339 loc
->function_name
= xstrdup (loc
->function_name
);
4343 /* set_raw_breakpoint is a low level routine for allocating and
4344 partially initializing a breakpoint of type BPTYPE. The newly
4345 created breakpoint's address, section, source file name, and line
4346 number are provided by SAL. The newly created and partially
4347 initialized breakpoint is added to the breakpoint chain and
4348 is also returned as the value of this function.
4350 It is expected that the caller will complete the initialization of
4351 the newly created breakpoint struct as well as output any status
4352 information regarding the creation of a new breakpoint. In
4353 particular, set_raw_breakpoint does NOT set the breakpoint
4354 number! Care should be taken to not allow an error to occur
4355 prior to completing the initialization of the breakpoint. If this
4356 should happen, a bogus breakpoint will be left on the chain. */
4359 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4361 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4362 CORE_ADDR adjusted_address
;
4364 /* Adjust the breakpoint's address prior to allocating a location.
4365 Once we call allocate_bp_location(), that mostly uninitialized
4366 location will be placed on the location chain. Adjustment of the
4367 breakpoint may cause target_read_memory() to be called and we do
4368 not want its scan of the location chain to find a breakpoint and
4369 location that's only been partially initialized. */
4370 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4372 b
->loc
= allocate_bp_location (b
, bptype
);
4373 b
->loc
->requested_address
= sal
.pc
;
4374 b
->loc
->address
= adjusted_address
;
4376 if (sal
.symtab
== NULL
)
4377 b
->source_file
= NULL
;
4379 b
->source_file
= savestring (sal
.symtab
->filename
,
4380 strlen (sal
.symtab
->filename
));
4381 b
->loc
->section
= sal
.section
;
4382 b
->line_number
= sal
.line
;
4384 set_breakpoint_location_function (b
->loc
);
4386 breakpoints_changed ();
4392 /* Note that the breakpoint object B describes a permanent breakpoint
4393 instruction, hard-wired into the inferior's code. */
4395 make_breakpoint_permanent (struct breakpoint
*b
)
4397 struct bp_location
*bl
;
4398 b
->enable_state
= bp_permanent
;
4400 /* By definition, permanent breakpoints are already present in the code.
4401 Mark all locations as inserted. For now, make_breakpoint_permanent
4402 is called in just one place, so it's hard to say if it's reasonable
4403 to have permanent breakpoint with multiple locations or not,
4404 but it's easy to implmement. */
4405 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4409 static struct breakpoint
*
4410 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4412 static int internal_breakpoint_number
= -1;
4413 struct symtab_and_line sal
;
4414 struct breakpoint
*b
;
4416 init_sal (&sal
); /* initialize to zeroes */
4419 sal
.section
= find_pc_overlay (sal
.pc
);
4421 b
= set_raw_breakpoint (sal
, type
);
4422 b
->number
= internal_breakpoint_number
--;
4423 b
->disposition
= disp_donttouch
;
4430 create_longjmp_breakpoint (char *func_name
)
4432 struct breakpoint
*b
;
4433 struct minimal_symbol
*m
;
4435 if (func_name
== NULL
)
4436 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4439 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4442 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4445 b
->enable_state
= bp_disabled
;
4448 b
->addr_string
= xstrdup (func_name
);
4449 update_global_location_list ();
4452 /* Call this routine when stepping and nexting to enable a breakpoint
4453 if we do a longjmp(). When we hit that breakpoint, call
4454 set_longjmp_resume_breakpoint() to figure out where we are going. */
4457 enable_longjmp_breakpoint (void)
4459 struct breakpoint
*b
;
4462 if (b
->type
== bp_longjmp
)
4464 b
->enable_state
= bp_enabled
;
4465 update_global_location_list ();
4470 disable_longjmp_breakpoint (void)
4472 struct breakpoint
*b
;
4475 if (b
->type
== bp_longjmp
4476 || b
->type
== bp_longjmp_resume
)
4478 b
->enable_state
= bp_disabled
;
4479 update_global_location_list ();
4484 create_overlay_event_breakpoint (char *func_name
)
4486 struct breakpoint
*b
;
4487 struct minimal_symbol
*m
;
4489 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4492 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4494 b
->addr_string
= xstrdup (func_name
);
4496 if (overlay_debugging
== ovly_auto
)
4498 b
->enable_state
= bp_enabled
;
4499 overlay_events_enabled
= 1;
4503 b
->enable_state
= bp_disabled
;
4504 overlay_events_enabled
= 0;
4506 update_global_location_list ();
4510 enable_overlay_breakpoints (void)
4512 struct breakpoint
*b
;
4515 if (b
->type
== bp_overlay_event
)
4517 b
->enable_state
= bp_enabled
;
4518 update_global_location_list ();
4519 overlay_events_enabled
= 1;
4524 disable_overlay_breakpoints (void)
4526 struct breakpoint
*b
;
4529 if (b
->type
== bp_overlay_event
)
4531 b
->enable_state
= bp_disabled
;
4532 update_global_location_list ();
4533 overlay_events_enabled
= 0;
4538 create_thread_event_breakpoint (CORE_ADDR address
)
4540 struct breakpoint
*b
;
4542 b
= create_internal_breakpoint (address
, bp_thread_event
);
4544 b
->enable_state
= bp_enabled
;
4545 /* addr_string has to be used or breakpoint_re_set will delete me. */
4546 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4548 update_global_location_list_nothrow ();
4554 remove_thread_event_breakpoints (void)
4556 struct breakpoint
*b
, *temp
;
4558 ALL_BREAKPOINTS_SAFE (b
, temp
)
4559 if (b
->type
== bp_thread_event
)
4560 delete_breakpoint (b
);
4563 struct captured_parse_breakpoint_args
4566 struct symtabs_and_lines
*sals_p
;
4567 char ***addr_string_p
;
4571 struct lang_and_radix
4579 remove_solib_event_breakpoints (void)
4581 struct breakpoint
*b
, *temp
;
4583 ALL_BREAKPOINTS_SAFE (b
, temp
)
4584 if (b
->type
== bp_shlib_event
)
4585 delete_breakpoint (b
);
4589 create_solib_event_breakpoint (CORE_ADDR address
)
4591 struct breakpoint
*b
;
4593 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4594 update_global_location_list_nothrow ();
4598 /* Disable any breakpoints that are on code in shared libraries. Only
4599 apply to enabled breakpoints, disabled ones can just stay disabled. */
4602 disable_breakpoints_in_shlibs (void)
4604 struct bp_location
*loc
;
4605 int disabled_shlib_breaks
= 0;
4607 ALL_BP_LOCATIONS (loc
)
4609 struct breakpoint
*b
= loc
->owner
;
4610 /* We apply the check to all breakpoints, including disabled
4611 for those with loc->duplicate set. This is so that when breakpoint
4612 becomes enabled, or the duplicate is removed, gdb will try to insert
4613 all breakpoints. If we don't set shlib_disabled here, we'll try
4614 to insert those breakpoints and fail. */
4615 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4616 && !loc
->shlib_disabled
4618 && PC_SOLIB (loc
->address
)
4620 && solib_address (loc
->address
)
4624 loc
->shlib_disabled
= 1;
4629 /* Disable any breakpoints that are in in an unloaded shared library. Only
4630 apply to enabled breakpoints, disabled ones can just stay disabled. */
4633 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4635 struct bp_location
*loc
;
4636 int disabled_shlib_breaks
= 0;
4638 ALL_BP_LOCATIONS (loc
)
4640 struct breakpoint
*b
= loc
->owner
;
4641 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4642 || loc
->loc_type
== bp_loc_software_breakpoint
)
4643 && !loc
->shlib_disabled
)
4646 char *so_name
= PC_SOLIB (loc
->address
);
4648 char *so_name
= solib_address (loc
->address
);
4650 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4652 loc
->shlib_disabled
= 1;
4653 /* At this point, we cannot rely on remove_breakpoint
4654 succeeding so we must mark the breakpoint as not inserted
4655 to prevent future errors occurring in remove_breakpoints. */
4657 if (!disabled_shlib_breaks
)
4659 target_terminal_ours_for_output ();
4660 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4663 disabled_shlib_breaks
= 1;
4670 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4671 enum bptype bp_kind
)
4673 struct symtab_and_line sal
;
4674 struct breakpoint
*b
;
4675 int thread
= -1; /* All threads. */
4682 b
= set_raw_breakpoint (sal
, bp_kind
);
4683 set_breakpoint_count (breakpoint_count
+ 1);
4684 b
->number
= breakpoint_count
;
4685 b
->cond_string
= (cond_string
== NULL
) ?
4686 NULL
: savestring (cond_string
, strlen (cond_string
));
4688 b
->addr_string
= NULL
;
4689 b
->enable_state
= bp_enabled
;
4690 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4691 b
->forked_inferior_pid
= 0;
4692 update_global_location_list ();
4699 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4701 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4705 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4707 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4711 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4713 struct symtab_and_line sal
;
4714 struct breakpoint
*b
;
4715 int thread
= -1; /* All threads. */
4722 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4723 set_breakpoint_count (breakpoint_count
+ 1);
4724 b
->number
= breakpoint_count
;
4725 b
->cond_string
= (cond_string
== NULL
) ?
4726 NULL
: savestring (cond_string
, strlen (cond_string
));
4728 b
->addr_string
= NULL
;
4729 b
->enable_state
= bp_enabled
;
4730 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4731 update_global_location_list ();
4737 hw_breakpoint_used_count (void)
4739 struct breakpoint
*b
;
4744 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4752 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4754 struct breakpoint
*b
;
4757 *other_type_used
= 0;
4760 if (breakpoint_enabled (b
))
4762 if (b
->type
== type
)
4764 else if ((b
->type
== bp_hardware_watchpoint
||
4765 b
->type
== bp_read_watchpoint
||
4766 b
->type
== bp_access_watchpoint
))
4767 *other_type_used
= 1;
4773 /* Call this after hitting the longjmp() breakpoint. Use this to set
4774 a new breakpoint at the target of the jmp_buf.
4776 FIXME - This ought to be done by setting a temporary breakpoint
4777 that gets deleted automatically... */
4780 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4782 struct breakpoint
*b
;
4785 if (b
->type
== bp_longjmp_resume
)
4787 b
->loc
->requested_address
= pc
;
4788 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4790 b
->enable_state
= bp_enabled
;
4791 b
->frame_id
= frame_id
;
4792 update_global_location_list ();
4798 disable_watchpoints_before_interactive_call_start (void)
4800 struct breakpoint
*b
;
4804 if (((b
->type
== bp_watchpoint
)
4805 || (b
->type
== bp_hardware_watchpoint
)
4806 || (b
->type
== bp_read_watchpoint
)
4807 || (b
->type
== bp_access_watchpoint
))
4808 && breakpoint_enabled (b
))
4810 b
->enable_state
= bp_call_disabled
;
4811 update_global_location_list ();
4817 enable_watchpoints_after_interactive_call_stop (void)
4819 struct breakpoint
*b
;
4823 if (((b
->type
== bp_watchpoint
)
4824 || (b
->type
== bp_hardware_watchpoint
)
4825 || (b
->type
== bp_read_watchpoint
)
4826 || (b
->type
== bp_access_watchpoint
))
4827 && (b
->enable_state
== bp_call_disabled
))
4829 b
->enable_state
= bp_enabled
;
4830 update_global_location_list ();
4836 /* Set a breakpoint that will evaporate an end of command
4837 at address specified by SAL.
4838 Restrict it to frame FRAME if FRAME is nonzero. */
4841 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4844 struct breakpoint
*b
;
4845 b
= set_raw_breakpoint (sal
, type
);
4846 b
->enable_state
= bp_enabled
;
4847 b
->disposition
= disp_donttouch
;
4848 b
->frame_id
= frame_id
;
4850 /* If we're debugging a multi-threaded program, then we
4851 want momentary breakpoints to be active in only a
4852 single thread of control. */
4853 if (in_thread_list (inferior_ptid
))
4854 b
->thread
= pid_to_thread_id (inferior_ptid
);
4856 update_global_location_list_nothrow ();
4862 /* Tell the user we have just set a breakpoint B. */
4865 mention (struct breakpoint
*b
)
4868 struct cleanup
*old_chain
, *ui_out_chain
;
4869 struct ui_stream
*stb
;
4871 stb
= ui_out_stream_new (uiout
);
4872 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4874 /* FIXME: This is misplaced; mention() is called by things (like
4875 hitting a watchpoint) other than breakpoint creation. It should
4876 be possible to clean this up and at the same time replace the
4877 random calls to breakpoint_changed with this hook, as has already
4878 been done for deprecated_delete_breakpoint_hook and so on. */
4879 if (deprecated_create_breakpoint_hook
)
4880 deprecated_create_breakpoint_hook (b
);
4881 breakpoint_create_event (b
->number
);
4883 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4884 b
->ops
->print_mention (b
);
4889 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4892 ui_out_text (uiout
, "Watchpoint ");
4893 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4894 ui_out_field_int (uiout
, "number", b
->number
);
4895 ui_out_text (uiout
, ": ");
4896 print_expression (b
->exp
, stb
->stream
);
4897 ui_out_field_stream (uiout
, "exp", stb
);
4898 do_cleanups (ui_out_chain
);
4900 case bp_hardware_watchpoint
:
4901 ui_out_text (uiout
, "Hardware watchpoint ");
4902 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4903 ui_out_field_int (uiout
, "number", b
->number
);
4904 ui_out_text (uiout
, ": ");
4905 print_expression (b
->exp
, stb
->stream
);
4906 ui_out_field_stream (uiout
, "exp", stb
);
4907 do_cleanups (ui_out_chain
);
4909 case bp_read_watchpoint
:
4910 ui_out_text (uiout
, "Hardware read watchpoint ");
4911 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4912 ui_out_field_int (uiout
, "number", b
->number
);
4913 ui_out_text (uiout
, ": ");
4914 print_expression (b
->exp
, stb
->stream
);
4915 ui_out_field_stream (uiout
, "exp", stb
);
4916 do_cleanups (ui_out_chain
);
4918 case bp_access_watchpoint
:
4919 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4920 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4921 ui_out_field_int (uiout
, "number", b
->number
);
4922 ui_out_text (uiout
, ": ");
4923 print_expression (b
->exp
, stb
->stream
);
4924 ui_out_field_stream (uiout
, "exp", stb
);
4925 do_cleanups (ui_out_chain
);
4928 if (ui_out_is_mi_like_p (uiout
))
4933 if (b
->disposition
== disp_del
)
4934 printf_filtered (_("Temporary breakpoint"));
4936 printf_filtered (_("Breakpoint"));
4937 printf_filtered (_(" %d"), b
->number
);
4940 case bp_hardware_breakpoint
:
4941 if (ui_out_is_mi_like_p (uiout
))
4946 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4950 case bp_catch_unload
:
4951 printf_filtered (_("Catchpoint %d (%s %s)"),
4953 (b
->type
== bp_catch_load
) ? "load" : "unload",
4954 (b
->dll_pathname
!= NULL
) ?
4955 b
->dll_pathname
: "<any library>");
4958 case bp_catch_vfork
:
4959 printf_filtered (_("Catchpoint %d (%s)"),
4961 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4964 printf_filtered (_("Catchpoint %d (exec)"),
4971 case bp_longjmp_resume
:
4972 case bp_step_resume
:
4974 case bp_watchpoint_scope
:
4975 case bp_shlib_event
:
4976 case bp_thread_event
:
4977 case bp_overlay_event
:
4983 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4987 printf_filtered (_(" (%s) pending."), b
->addr_string
);
4991 if (addressprint
|| b
->source_file
== NULL
)
4993 printf_filtered (" at ");
4994 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
4997 printf_filtered (": file %s, line %d.",
4998 b
->source_file
, b
->line_number
);
5002 struct bp_location
*loc
= b
->loc
;
5004 for (; loc
; loc
= loc
->next
)
5006 printf_filtered (" (%d locations)", n
);
5011 do_cleanups (old_chain
);
5012 if (ui_out_is_mi_like_p (uiout
))
5014 printf_filtered ("\n");
5018 static struct bp_location
*
5019 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5020 const struct symtab_and_line
*sal
)
5022 struct bp_location
*loc
, **tmp
;
5024 loc
= allocate_bp_location (b
, bptype
);
5025 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5028 loc
->requested_address
= sal
->pc
;
5029 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5031 loc
->section
= sal
->section
;
5033 set_breakpoint_location_function (loc
);
5037 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5038 as textual description of the location, and COND_STRING
5039 as condition expression. */
5042 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5044 enum bptype type
, enum bpdisp disposition
,
5045 int thread
, int ignore_count
, int from_tty
)
5047 struct breakpoint
*b
= NULL
;
5050 if (type
== bp_hardware_breakpoint
)
5052 int i
= hw_breakpoint_used_count ();
5053 int target_resources_ok
=
5054 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5056 if (target_resources_ok
== 0)
5057 error (_("No hardware breakpoint support in the target."));
5058 else if (target_resources_ok
< 0)
5059 error (_("Hardware breakpoints used exceeds limit."));
5062 for (i
= 0; i
< sals
.nelts
; ++i
)
5064 struct symtab_and_line sal
= sals
.sals
[i
];
5065 struct bp_location
*loc
;
5068 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5072 b
= set_raw_breakpoint (sal
, type
);
5073 set_breakpoint_count (breakpoint_count
+ 1);
5074 b
->number
= breakpoint_count
;
5077 b
->cond_string
= cond_string
;
5078 b
->ignore_count
= ignore_count
;
5079 b
->enable_state
= bp_enabled
;
5080 b
->disposition
= disposition
;
5086 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5091 char *arg
= b
->cond_string
;
5092 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5094 error (_("Garbage %s follows condition"), arg
);
5099 b
->addr_string
= addr_string
;
5101 /* addr_string has to be used or breakpoint_re_set will delete
5103 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5108 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5109 elements to fill the void space. */
5110 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5112 int i
= index_to_remove
+1;
5113 int last_index
= sal
->nelts
-1;
5115 for (;i
<= last_index
; ++i
)
5116 sal
->sals
[i
-1] = sal
->sals
[i
];
5121 /* If appropriate, obtains all sals that correspond
5122 to the same file and line as SAL. This is done
5123 only if SAL does not have explicit PC and has
5124 line and file information. If we got just a single
5125 expanded sal, return the original.
5127 Otherwise, if SAL.explicit_line is not set, filter out
5128 all sals for which the name of enclosing function
5129 is different from SAL. This makes sure that if we have
5130 breakpoint originally set in template instantiation, say
5131 foo<int>(), we won't expand SAL to locations at the same
5132 line in all existing instantiations of 'foo'.
5135 struct symtabs_and_lines
5136 expand_line_sal_maybe (struct symtab_and_line sal
)
5138 struct symtabs_and_lines expanded
;
5139 CORE_ADDR original_pc
= sal
.pc
;
5140 char *original_function
= NULL
;
5144 /* If we have explicit pc, don't expand.
5145 If we have no line number, we can't expand. */
5146 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5149 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5150 expanded
.sals
[0] = sal
;
5155 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5157 expanded
= expand_line_sal (sal
);
5158 if (expanded
.nelts
== 1)
5160 /* We had one sal, we got one sal. Without futher
5161 processing, just return the original sal. */
5162 xfree (expanded
.sals
);
5164 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5165 sal
.pc
= original_pc
;
5166 expanded
.sals
[0] = sal
;
5170 if (!sal
.explicit_line
)
5172 CORE_ADDR func_addr
, func_end
;
5173 for (i
= 0; i
< expanded
.nelts
; ++i
)
5175 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5176 char *this_function
;
5177 if (find_pc_partial_function (pc
, &this_function
,
5178 &func_addr
, &func_end
))
5180 if (this_function
&&
5181 strcmp (this_function
, original_function
) != 0)
5183 remove_sal (&expanded
, i
);
5186 else if (func_addr
== pc
)
5188 /* We're at beginning of a function, and should
5190 struct symbol
*sym
= find_pc_function (pc
);
5192 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5195 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5202 if (expanded
.nelts
<= 1)
5204 /* This is un ugly workaround. If we get zero
5205 expanded sals then something is really wrong.
5206 Fix that by returnign the original sal. */
5207 xfree (expanded
.sals
);
5209 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5210 sal
.pc
= original_pc
;
5211 expanded
.sals
[0] = sal
;
5218 for (i
= 0; i
< expanded
.nelts
; ++i
)
5219 if (expanded
.sals
[i
].pc
== original_pc
)
5230 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5231 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5232 value. COND_STRING, if not NULL, specified the condition to be
5233 used for all breakpoints. Essentially the only case where
5234 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5235 function. In that case, it's still not possible to specify
5236 separate conditions for different overloaded functions, so
5237 we take just a single condition string.
5239 NOTE: If the function succeeds, the caller is expected to cleanup
5240 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5241 array contents). If the function fails (error() is called), the
5242 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5243 COND and SALS arrays and each of those arrays contents. */
5246 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5248 enum bptype type
, enum bpdisp disposition
,
5249 int thread
, int ignore_count
, int from_tty
)
5252 for (i
= 0; i
< sals
.nelts
; ++i
)
5254 struct symtabs_and_lines expanded
=
5255 expand_line_sal_maybe (sals
.sals
[i
]);
5257 create_breakpoint (expanded
, addr_string
[i
],
5258 cond_string
, type
, disposition
,
5259 thread
, ignore_count
, from_tty
);
5262 update_global_location_list ();
5265 /* Parse ARG which is assumed to be a SAL specification possibly
5266 followed by conditionals. On return, SALS contains an array of SAL
5267 addresses found. ADDR_STRING contains a vector of (canonical)
5268 address strings. ARG points to the end of the SAL. */
5271 parse_breakpoint_sals (char **address
,
5272 struct symtabs_and_lines
*sals
,
5273 char ***addr_string
,
5276 char *addr_start
= *address
;
5277 *addr_string
= NULL
;
5278 /* If no arg given, or if first arg is 'if ', use the default
5280 if ((*address
) == NULL
5281 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5283 if (default_breakpoint_valid
)
5285 struct symtab_and_line sal
;
5286 init_sal (&sal
); /* initialize to zeroes */
5287 sals
->sals
= (struct symtab_and_line
*)
5288 xmalloc (sizeof (struct symtab_and_line
));
5289 sal
.pc
= default_breakpoint_address
;
5290 sal
.line
= default_breakpoint_line
;
5291 sal
.symtab
= default_breakpoint_symtab
;
5292 sal
.section
= find_pc_overlay (sal
.pc
);
5293 sals
->sals
[0] = sal
;
5297 error (_("No default breakpoint address now."));
5301 /* Force almost all breakpoints to be in terms of the
5302 current_source_symtab (which is decode_line_1's default). This
5303 should produce the results we want almost all of the time while
5304 leaving default_breakpoint_* alone.
5305 ObjC: However, don't match an Objective-C method name which
5306 may have a '+' or '-' succeeded by a '[' */
5308 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5310 if (default_breakpoint_valid
5312 || ((strchr ("+-", (*address
)[0]) != NULL
)
5313 && ((*address
)[1] != '['))))
5314 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5315 default_breakpoint_line
, addr_string
,
5318 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5319 addr_string
, not_found_ptr
);
5321 /* For any SAL that didn't have a canonical string, fill one in. */
5322 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5323 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5324 if (addr_start
!= (*address
))
5327 for (i
= 0; i
< sals
->nelts
; i
++)
5329 /* Add the string if not present. */
5330 if ((*addr_string
)[i
] == NULL
)
5331 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5337 /* Convert each SAL into a real PC. Verify that the PC can be
5338 inserted as a breakpoint. If it can't throw an error. */
5341 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5345 for (i
= 0; i
< sals
->nelts
; i
++)
5346 resolve_sal_pc (&sals
->sals
[i
]);
5350 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5352 struct captured_parse_breakpoint_args
*args
= data
;
5354 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5355 args
->not_found_ptr
);
5358 /* Given TOK, a string specification of condition and thread, as
5359 accepted by the 'break' command, extract the condition
5360 string and thread number and set *COND_STRING and *THREAD.
5361 PC identifies the context at which the condition should be parsed.
5362 If no condition is found, *COND_STRING is set to NULL.
5363 If no thread is found, *THREAD is set to -1. */
5365 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5366 char **cond_string
, int *thread
)
5368 *cond_string
= NULL
;
5374 char *cond_start
= NULL
;
5375 char *cond_end
= NULL
;
5376 while (*tok
== ' ' || *tok
== '\t')
5381 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5384 toklen
= end_tok
- tok
;
5386 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5388 tok
= cond_start
= end_tok
+ 1;
5389 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5391 *cond_string
= savestring (cond_start
,
5392 cond_end
- cond_start
);
5394 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5400 *thread
= strtol (tok
, &tok
, 0);
5402 error (_("Junk after thread keyword."));
5403 if (!valid_thread_id (*thread
))
5404 error (_("Unknown thread %d."), *thread
);
5407 error (_("Junk at end of arguments."));
5411 /* Set a breakpoint. This function is shared between
5412 CLI and MI functions for setting a breakpoint.
5413 This function has two major modes of operations,
5414 selected by the PARSE_CONDITION_AND_THREAD parameter.
5415 If non-zero, the function will parse arg, extracting
5416 breakpoint location, address and thread. Otherwise,
5417 ARG is just the location of breakpoint, with condition
5418 and thread specified by the COND_STRING and THREAD
5422 break_command_really (char *arg
, char *cond_string
, int thread
,
5423 int parse_condition_and_thread
,
5424 int tempflag
, int hardwareflag
,
5426 enum auto_boolean pending_break_support
,
5429 struct gdb_exception e
;
5430 struct symtabs_and_lines sals
;
5431 struct symtab_and_line pending_sal
;
5434 char *addr_start
= arg
;
5436 struct cleanup
*old_chain
;
5437 struct cleanup
*breakpoint_chain
= NULL
;
5438 struct captured_parse_breakpoint_args parse_args
;
5447 parse_args
.arg_p
= &arg
;
5448 parse_args
.sals_p
= &sals
;
5449 parse_args
.addr_string_p
= &addr_string
;
5450 parse_args
.not_found_ptr
= ¬_found
;
5452 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5453 &parse_args
, RETURN_MASK_ALL
);
5455 /* If caller is interested in rc value from parse, set value. */
5459 throw_exception (e
);
5463 case NOT_FOUND_ERROR
:
5465 /* If pending breakpoint support is turned off, throw
5468 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5469 throw_exception (e
);
5471 exception_print (gdb_stderr
, e
);
5473 /* If pending breakpoint support is auto query and the user
5474 selects no, then simply return the error code. */
5475 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5476 !nquery ("Make breakpoint pending on future shared library load? "))
5479 /* At this point, either the user was queried about setting
5480 a pending breakpoint and selected yes, or pending
5481 breakpoint behavior is on and thus a pending breakpoint
5482 is defaulted on behalf of the user. */
5483 copy_arg
= xstrdup (addr_start
);
5484 addr_string
= ©_arg
;
5486 sals
.sals
= &pending_sal
;
5491 throw_exception (e
);
5498 /* Create a chain of things that always need to be cleaned up. */
5499 old_chain
= make_cleanup (null_cleanup
, 0);
5503 /* Make sure that all storage allocated to SALS gets freed. */
5504 make_cleanup (xfree
, sals
.sals
);
5506 /* Cleanup the addr_string array but not its contents. */
5507 make_cleanup (xfree
, addr_string
);
5510 /* ----------------------------- SNIP -----------------------------
5511 Anything added to the cleanup chain beyond this point is assumed
5512 to be part of a breakpoint. If the breakpoint create succeeds
5513 then the memory is not reclaimed. */
5514 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5516 /* Mark the contents of the addr_string for cleanup. These go on
5517 the breakpoint_chain and only occure if the breakpoint create
5519 for (i
= 0; i
< sals
.nelts
; i
++)
5521 if (addr_string
[i
] != NULL
)
5522 make_cleanup (xfree
, addr_string
[i
]);
5525 /* Resolve all line numbers to PC's and verify that the addresses
5526 are ok for the target. */
5528 breakpoint_sals_to_pc (&sals
, addr_start
);
5530 /* Verify that condition can be parsed, before setting any
5531 breakpoints. Allocate a separate condition expression for each
5535 if (parse_condition_and_thread
)
5537 /* Here we only parse 'arg' to separate condition
5538 from thread number, so parsing in context of first
5539 sal is OK. When setting the breakpoint we'll
5540 re-parse it in context of each sal. */
5543 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5545 make_cleanup (xfree
, cond_string
);
5549 /* Create a private copy of condition string. */
5552 cond_string
= xstrdup (cond_string
);
5553 make_cleanup (xfree
, cond_string
);
5556 create_breakpoints (sals
, addr_string
, cond_string
,
5557 hardwareflag
? bp_hardware_breakpoint
5559 tempflag
? disp_del
: disp_donttouch
,
5560 thread
, ignore_count
, from_tty
);
5564 struct symtab_and_line sal
= {0};
5565 struct breakpoint
*b
;
5567 make_cleanup (xfree
, copy_arg
);
5569 b
= set_raw_breakpoint_without_location (hardwareflag
5570 ? bp_hardware_breakpoint
5572 set_breakpoint_count (breakpoint_count
+ 1);
5573 b
->number
= breakpoint_count
;
5575 b
->addr_string
= addr_string
[0];
5576 b
->cond_string
= NULL
;
5577 b
->ignore_count
= ignore_count
;
5578 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5579 b
->condition_not_parsed
= 1;
5581 update_global_location_list ();
5586 warning (_("Multiple breakpoints were set.\n"
5587 "Use the \"delete\" command to delete unwanted breakpoints."));
5588 /* That's it. Discard the cleanups for data inserted into the
5590 discard_cleanups (breakpoint_chain
);
5591 /* But cleanup everything else. */
5592 do_cleanups (old_chain
);
5595 /* Set a breakpoint.
5596 ARG is a string describing breakpoint address,
5597 condition, and thread.
5598 FLAG specifies if a breakpoint is hardware on,
5599 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5603 break_command_1 (char *arg
, int flag
, int from_tty
)
5605 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5606 int tempflag
= flag
& BP_TEMPFLAG
;
5608 break_command_really (arg
,
5609 NULL
, 0, 1 /* parse arg */,
5610 tempflag
, hardwareflag
,
5611 0 /* Ignore count */,
5612 pending_break_support
, from_tty
);
5617 set_breakpoint (char *address
, char *condition
,
5618 int hardwareflag
, int tempflag
,
5619 int thread
, int ignore_count
,
5622 break_command_really (address
, condition
, thread
,
5623 0 /* condition and thread are valid. */,
5624 tempflag
, hardwareflag
,
5627 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5631 /* Adjust SAL to the first instruction past the function prologue.
5632 The end of the prologue is determined using the line table from
5633 the debugging information.
5635 If SAL is already past the prologue, then do nothing. */
5638 skip_prologue_sal (struct symtab_and_line
*sal
)
5640 struct symbol
*sym
= find_pc_function (sal
->pc
);
5641 struct symtab_and_line start_sal
;
5646 start_sal
= find_function_start_sal (sym
, 1);
5647 if (sal
->pc
< start_sal
.pc
)
5651 /* Helper function for break_command_1 and disassemble_command. */
5654 resolve_sal_pc (struct symtab_and_line
*sal
)
5658 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5660 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5661 error (_("No line %d in file \"%s\"."),
5662 sal
->line
, sal
->symtab
->filename
);
5665 /* If this SAL corresponds to a breakpoint inserted using
5666 a line number, then skip the function prologue if necessary. */
5667 if (sal
->explicit_line
)
5668 skip_prologue_sal (sal
);
5671 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5673 struct blockvector
*bv
;
5677 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5680 sym
= block_function (b
);
5683 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5684 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5688 /* It really is worthwhile to have the section, so we'll just
5689 have to look harder. This case can be executed if we have
5690 line numbers but no functions (as can happen in assembly
5693 struct minimal_symbol
*msym
;
5695 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5697 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5704 break_command (char *arg
, int from_tty
)
5706 break_command_1 (arg
, 0, from_tty
);
5710 tbreak_command (char *arg
, int from_tty
)
5712 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5716 hbreak_command (char *arg
, int from_tty
)
5718 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5722 thbreak_command (char *arg
, int from_tty
)
5724 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5728 stop_command (char *arg
, int from_tty
)
5730 printf_filtered (_("Specify the type of breakpoint to set.\n\
5731 Usage: stop in <function | address>\n\
5732 stop at <line>\n"));
5736 stopin_command (char *arg
, int from_tty
)
5740 if (arg
== (char *) NULL
)
5742 else if (*arg
!= '*')
5747 /* look for a ':'. If this is a line number specification, then
5748 say it is bad, otherwise, it should be an address or
5749 function/method name */
5750 while (*argptr
&& !hasColon
)
5752 hasColon
= (*argptr
== ':');
5757 badInput
= (*argptr
!= ':'); /* Not a class::method */
5759 badInput
= isdigit (*arg
); /* a simple line number */
5763 printf_filtered (_("Usage: stop in <function | address>\n"));
5765 break_command_1 (arg
, 0, from_tty
);
5769 stopat_command (char *arg
, int from_tty
)
5773 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5780 /* look for a ':'. If there is a '::' then get out, otherwise
5781 it is probably a line number. */
5782 while (*argptr
&& !hasColon
)
5784 hasColon
= (*argptr
== ':');
5789 badInput
= (*argptr
== ':'); /* we have class::method */
5791 badInput
= !isdigit (*arg
); /* not a line number */
5795 printf_filtered (_("Usage: stop at <line>\n"));
5797 break_command_1 (arg
, 0, from_tty
);
5800 /* accessflag: hw_write: watch write,
5801 hw_read: watch read,
5802 hw_access: watch access (read or write) */
5804 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5806 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5807 struct symtab_and_line sal
;
5808 struct expression
*exp
;
5809 struct block
*exp_valid_block
;
5810 struct value
*val
, *mark
;
5811 struct frame_info
*frame
;
5812 struct frame_info
*prev_frame
= NULL
;
5813 char *exp_start
= NULL
;
5814 char *exp_end
= NULL
;
5815 char *tok
, *id_tok_start
, *end_tok
;
5817 char *cond_start
= NULL
;
5818 char *cond_end
= NULL
;
5819 struct expression
*cond
= NULL
;
5820 int i
, other_type_used
, target_resources_ok
= 0;
5821 enum bptype bp_type
;
5825 init_sal (&sal
); /* initialize to zeroes */
5827 /* Make sure that we actually have parameters to parse. */
5828 if (arg
!= NULL
&& arg
[0] != '\0')
5830 toklen
= strlen (arg
); /* Size of argument list. */
5832 /* Points tok to the end of the argument list. */
5833 tok
= arg
+ toklen
- 1;
5835 /* Go backwards in the parameters list. Skip the last parameter.
5836 If we're expecting a 'thread <thread_num>' parameter, this should
5837 be the thread identifier. */
5838 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5840 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5843 /* Points end_tok to the beginning of the last token. */
5844 id_tok_start
= tok
+ 1;
5846 /* Go backwards in the parameters list. Skip one more parameter.
5847 If we're expecting a 'thread <thread_num>' parameter, we should
5848 reach a "thread" token. */
5849 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5854 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5857 /* Move the pointer forward to skip the whitespace and
5858 calculate the length of the token. */
5860 toklen
= end_tok
- tok
;
5862 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5864 /* At this point we've found a "thread" token, which means
5865 the user is trying to set a watchpoint that triggers
5866 only in a specific thread. */
5869 /* Extract the thread ID from the next token. */
5870 thread
= strtol (id_tok_start
, &endp
, 0);
5872 /* Check if the user provided a valid numeric value for the
5874 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5875 error (_("Invalid thread ID specification %s."), id_tok_start
);
5877 /* Check if the thread actually exists. */
5878 if (!valid_thread_id (thread
))
5879 error (_("Unknown thread %d."), thread
);
5881 /* Truncate the string and get rid of the thread <thread_num>
5882 parameter before the parameter list is parsed by the
5883 evaluate_expression() function. */
5888 /* Parse the rest of the arguments. */
5889 innermost_block
= NULL
;
5891 exp
= parse_exp_1 (&arg
, 0, 0);
5893 exp_valid_block
= innermost_block
;
5894 mark
= value_mark ();
5895 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5897 release_value (val
);
5900 while (*tok
== ' ' || *tok
== '\t')
5904 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5907 toklen
= end_tok
- tok
;
5908 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5910 tok
= cond_start
= end_tok
+ 1;
5911 cond
= parse_exp_1 (&tok
, 0, 0);
5915 error (_("Junk at end of command."));
5917 if (accessflag
== hw_read
)
5918 bp_type
= bp_read_watchpoint
;
5919 else if (accessflag
== hw_access
)
5920 bp_type
= bp_access_watchpoint
;
5922 bp_type
= bp_hardware_watchpoint
;
5924 mem_cnt
= can_use_hardware_watchpoint (val
);
5925 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5926 error (_("Expression cannot be implemented with read/access watchpoint."));
5929 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5930 target_resources_ok
=
5931 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5933 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5934 error (_("Target does not support this type of hardware watchpoint."));
5936 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5937 error (_("Target can only support one kind of HW watchpoint at a time."));
5940 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5941 watchpoint could not be set. */
5942 if (!mem_cnt
|| target_resources_ok
<= 0)
5943 bp_type
= bp_watchpoint
;
5945 frame
= block_innermost_frame (exp_valid_block
);
5947 prev_frame
= get_prev_frame (frame
);
5951 /* If the expression is "local", then set up a "watchpoint scope"
5952 breakpoint at the point where we've left the scope of the watchpoint
5953 expression. Create the scope breakpoint before the watchpoint, so
5954 that we will encounter it first in bpstat_stop_status. */
5955 if (innermost_block
&& prev_frame
)
5957 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5958 bp_watchpoint_scope
);
5960 scope_breakpoint
->enable_state
= bp_enabled
;
5962 /* Automatically delete the breakpoint when it hits. */
5963 scope_breakpoint
->disposition
= disp_del
;
5965 /* Only break in the proper frame (help with recursion). */
5966 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5968 /* Set the address at which we will stop. */
5969 scope_breakpoint
->loc
->requested_address
5970 = get_frame_pc (prev_frame
);
5971 scope_breakpoint
->loc
->address
5972 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5973 scope_breakpoint
->type
);
5976 /* Now set up the breakpoint. */
5977 b
= set_raw_breakpoint (sal
, bp_type
);
5978 set_breakpoint_count (breakpoint_count
+ 1);
5979 b
->number
= breakpoint_count
;
5981 b
->disposition
= disp_donttouch
;
5983 b
->exp_valid_block
= exp_valid_block
;
5984 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5987 b
->loc
->cond
= cond
;
5989 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5994 b
->watchpoint_frame
= get_frame_id (frame
);
5996 b
->watchpoint_frame
= null_frame_id
;
5998 if (scope_breakpoint
!= NULL
)
6000 /* The scope breakpoint is related to the watchpoint. We will
6001 need to act on them together. */
6002 b
->related_breakpoint
= scope_breakpoint
;
6003 scope_breakpoint
->related_breakpoint
= b
;
6006 value_free_to_mark (mark
);
6008 update_global_location_list ();
6011 /* Return count of locations need to be watched and can be handled
6012 in hardware. If the watchpoint can not be handled
6013 in hardware return zero. */
6016 can_use_hardware_watchpoint (struct value
*v
)
6018 int found_memory_cnt
= 0;
6019 struct value
*head
= v
;
6021 /* Did the user specifically forbid us to use hardware watchpoints? */
6022 if (!can_use_hw_watchpoints
)
6025 /* Make sure that the value of the expression depends only upon
6026 memory contents, and values computed from them within GDB. If we
6027 find any register references or function calls, we can't use a
6028 hardware watchpoint.
6030 The idea here is that evaluating an expression generates a series
6031 of values, one holding the value of every subexpression. (The
6032 expression a*b+c has five subexpressions: a, b, a*b, c, and
6033 a*b+c.) GDB's values hold almost enough information to establish
6034 the criteria given above --- they identify memory lvalues,
6035 register lvalues, computed values, etcetera. So we can evaluate
6036 the expression, and then scan the chain of values that leaves
6037 behind to decide whether we can detect any possible change to the
6038 expression's final value using only hardware watchpoints.
6040 However, I don't think that the values returned by inferior
6041 function calls are special in any way. So this function may not
6042 notice that an expression involving an inferior function call
6043 can't be watched with hardware watchpoints. FIXME. */
6044 for (; v
; v
= value_next (v
))
6046 if (VALUE_LVAL (v
) == lval_memory
)
6049 /* A lazy memory lvalue is one that GDB never needed to fetch;
6050 we either just used its address (e.g., `a' in `a.b') or
6051 we never needed it at all (e.g., `a' in `a,b'). */
6055 /* Ahh, memory we actually used! Check if we can cover
6056 it with hardware watchpoints. */
6057 struct type
*vtype
= check_typedef (value_type (v
));
6059 /* We only watch structs and arrays if user asked for it
6060 explicitly, never if they just happen to appear in a
6061 middle of some value chain. */
6063 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6064 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6066 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6067 int len
= TYPE_LENGTH (value_type (v
));
6069 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6076 else if (VALUE_LVAL (v
) != not_lval
6077 && deprecated_value_modifiable (v
) == 0)
6078 return 0; /* ??? What does this represent? */
6079 else if (VALUE_LVAL (v
) == lval_register
)
6080 return 0; /* cannot watch a register with a HW watchpoint */
6083 /* The expression itself looks suitable for using a hardware
6084 watchpoint, but give the target machine a chance to reject it. */
6085 return found_memory_cnt
;
6089 watch_command_wrapper (char *arg
, int from_tty
)
6091 watch_command (arg
, from_tty
);
6095 watch_command (char *arg
, int from_tty
)
6097 watch_command_1 (arg
, hw_write
, from_tty
);
6101 rwatch_command_wrapper (char *arg
, int from_tty
)
6103 rwatch_command (arg
, from_tty
);
6107 rwatch_command (char *arg
, int from_tty
)
6109 watch_command_1 (arg
, hw_read
, from_tty
);
6113 awatch_command_wrapper (char *arg
, int from_tty
)
6115 awatch_command (arg
, from_tty
);
6119 awatch_command (char *arg
, int from_tty
)
6121 watch_command_1 (arg
, hw_access
, from_tty
);
6125 /* Helper routines for the until_command routine in infcmd.c. Here
6126 because it uses the mechanisms of breakpoints. */
6128 /* This function is called by fetch_inferior_event via the
6129 cmd_continuation pointer, to complete the until command. It takes
6130 care of cleaning up the temporary breakpoints set up by the until
6133 until_break_command_continuation (struct continuation_arg
*arg
)
6135 struct cleanup
*cleanups
;
6137 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
6138 do_exec_cleanups (cleanups
);
6142 until_break_command (char *arg
, int from_tty
, int anywhere
)
6144 struct symtabs_and_lines sals
;
6145 struct symtab_and_line sal
;
6146 struct frame_info
*frame
= get_selected_frame (NULL
);
6147 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6148 struct breakpoint
*breakpoint
;
6149 struct cleanup
*old_chain
;
6150 struct continuation_arg
*arg1
;
6153 clear_proceed_status ();
6155 /* Set a breakpoint where the user wants it and at return from
6158 if (default_breakpoint_valid
)
6159 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6160 default_breakpoint_line
, (char ***) NULL
, NULL
);
6162 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6163 0, (char ***) NULL
, NULL
);
6165 if (sals
.nelts
!= 1)
6166 error (_("Couldn't get information on specified line."));
6169 xfree (sals
.sals
); /* malloc'd, so freed */
6172 error (_("Junk at end of arguments."));
6174 resolve_sal_pc (&sal
);
6177 /* If the user told us to continue until a specified location,
6178 we don't specify a frame at which we need to stop. */
6179 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6181 /* Otherwise, specify the current frame, because we want to stop only
6182 at the very same frame. */
6183 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6186 if (!target_can_async_p ())
6187 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6189 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
6191 /* If we are running asynchronously, and the target supports async
6192 execution, we are not waiting for the target to stop, in the call
6193 tp proceed, below. This means that we cannot delete the
6194 brekpoints until the target has actually stopped. The only place
6195 where we get a chance to do that is in fetch_inferior_event, so
6196 we must set things up for that. */
6198 if (target_can_async_p ())
6200 /* In this case the arg for the continuation is just the point
6201 in the exec_cleanups chain from where to start doing
6202 cleanups, because all the continuation does is the cleanups in
6203 the exec_cleanup_chain. */
6205 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6207 arg1
->data
.pointer
= old_chain
;
6209 add_continuation (until_break_command_continuation
, arg1
);
6212 /* Keep within the current frame, or in frames called by the current
6216 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6217 sal
.pc
= get_frame_pc (prev_frame
);
6218 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6220 if (!target_can_async_p ())
6221 make_cleanup_delete_breakpoint (breakpoint
);
6223 make_exec_cleanup_delete_breakpoint (breakpoint
);
6226 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6227 /* Do the cleanups now, anly if we are not running asynchronously,
6228 of if we are, but the target is still synchronous. */
6229 if (!target_can_async_p ())
6230 do_cleanups (old_chain
);
6234 ep_skip_leading_whitespace (char **s
)
6236 if ((s
== NULL
) || (*s
== NULL
))
6238 while (isspace (**s
))
6242 /* This function examines a string, and attempts to find a token
6243 that might be an event name in the leading characters. If a
6244 possible match is found, a pointer to the last character of
6245 the token is returned. Else, NULL is returned. */
6248 ep_find_event_name_end (char *arg
)
6251 char *event_name_end
= NULL
;
6253 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6257 /* We break out of the loop when we find a token delimiter.
6258 Basically, we're looking for alphanumerics and underscores;
6259 anything else delimites the token. */
6262 if (!isalnum (*s
) && (*s
!= '_'))
6268 return event_name_end
;
6272 /* This function attempts to parse an optional "if <cond>" clause
6273 from the arg string. If one is not found, it returns NULL.
6275 Else, it returns a pointer to the condition string. (It does not
6276 attempt to evaluate the string against a particular block.) And,
6277 it updates arg to point to the first character following the parsed
6278 if clause in the arg string. */
6281 ep_parse_optional_if_clause (char **arg
)
6285 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6288 /* Skip the "if" keyword. */
6291 /* Skip any extra leading whitespace, and record the start of the
6292 condition string. */
6293 ep_skip_leading_whitespace (arg
);
6296 /* Assume that the condition occupies the remainder of the arg string. */
6297 (*arg
) += strlen (cond_string
);
6302 /* This function attempts to parse an optional filename from the arg
6303 string. If one is not found, it returns NULL.
6305 Else, it returns a pointer to the parsed filename. (This function
6306 makes no attempt to verify that a file of that name exists, or is
6307 accessible.) And, it updates arg to point to the first character
6308 following the parsed filename in the arg string.
6310 Note that clients needing to preserve the returned filename for
6311 future access should copy it to their own buffers. */
6313 ep_parse_optional_filename (char **arg
)
6315 static char filename
[1024];
6320 if ((*arg_p
== '\0') || isspace (*arg_p
))
6338 /* Commands to deal with catching events, such as signals, exceptions,
6339 process start/exit, etc. */
6343 catch_fork
, catch_vfork
6348 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6351 char *cond_string
= NULL
;
6353 ep_skip_leading_whitespace (&arg
);
6355 /* The allowed syntax is:
6357 catch [v]fork if <cond>
6359 First, check if there's an if clause. */
6360 cond_string
= ep_parse_optional_if_clause (&arg
);
6362 if ((*arg
!= '\0') && !isspace (*arg
))
6363 error (_("Junk at end of arguments."));
6365 /* If this target supports it, create a fork or vfork catchpoint
6366 and enable reporting of such events. */
6370 create_fork_event_catchpoint (tempflag
, cond_string
);
6373 create_vfork_event_catchpoint (tempflag
, cond_string
);
6376 error (_("unsupported or unknown fork kind; cannot catch it"));
6382 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6384 char *cond_string
= NULL
;
6386 ep_skip_leading_whitespace (&arg
);
6388 /* The allowed syntax is:
6390 catch exec if <cond>
6392 First, check if there's an if clause. */
6393 cond_string
= ep_parse_optional_if_clause (&arg
);
6395 if ((*arg
!= '\0') && !isspace (*arg
))
6396 error (_("Junk at end of arguments."));
6398 /* If this target supports it, create an exec catchpoint
6399 and enable reporting of such events. */
6400 create_exec_event_catchpoint (tempflag
, cond_string
);
6404 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6406 char *dll_pathname
= NULL
;
6407 char *cond_string
= NULL
;
6409 ep_skip_leading_whitespace (&arg
);
6411 /* The allowed syntax is:
6413 catch load if <cond>
6414 catch load <filename>
6415 catch load <filename> if <cond>
6417 The user is not allowed to specify the <filename> after an
6420 We'll ignore the pathological case of a file named "if".
6422 First, check if there's an if clause. If so, then there
6423 cannot be a filename. */
6424 cond_string
= ep_parse_optional_if_clause (&arg
);
6426 /* If there was an if clause, then there cannot be a filename.
6427 Else, there might be a filename and an if clause. */
6428 if (cond_string
== NULL
)
6430 dll_pathname
= ep_parse_optional_filename (&arg
);
6431 ep_skip_leading_whitespace (&arg
);
6432 cond_string
= ep_parse_optional_if_clause (&arg
);
6435 if ((*arg
!= '\0') && !isspace (*arg
))
6436 error (_("Junk at end of arguments."));
6438 /* Create a load breakpoint that only triggers when a load of
6439 the specified dll (or any dll, if no pathname was specified)
6441 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6442 dll_pathname
, cond_string
);
6446 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6448 char *dll_pathname
= NULL
;
6449 char *cond_string
= NULL
;
6451 ep_skip_leading_whitespace (&arg
);
6453 /* The allowed syntax is:
6455 catch unload if <cond>
6456 catch unload <filename>
6457 catch unload <filename> if <cond>
6459 The user is not allowed to specify the <filename> after an
6462 We'll ignore the pathological case of a file named "if".
6464 First, check if there's an if clause. If so, then there
6465 cannot be a filename. */
6466 cond_string
= ep_parse_optional_if_clause (&arg
);
6468 /* If there was an if clause, then there cannot be a filename.
6469 Else, there might be a filename and an if clause. */
6470 if (cond_string
== NULL
)
6472 dll_pathname
= ep_parse_optional_filename (&arg
);
6473 ep_skip_leading_whitespace (&arg
);
6474 cond_string
= ep_parse_optional_if_clause (&arg
);
6477 if ((*arg
!= '\0') && !isspace (*arg
))
6478 error (_("Junk at end of arguments."));
6480 /* Create an unload breakpoint that only triggers when an unload of
6481 the specified dll (or any dll, if no pathname was specified)
6483 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6484 dll_pathname
, cond_string
);
6487 static enum print_stop_action
6488 print_exception_catchpoint (struct breakpoint
*b
)
6490 annotate_catchpoint (b
->number
);
6492 if (strstr (b
->addr_string
, "throw") != NULL
)
6493 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6496 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6499 return PRINT_SRC_AND_LOC
;
6503 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6508 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6511 *last_addr
= b
->loc
->address
;
6512 if (strstr (b
->addr_string
, "throw") != NULL
)
6513 ui_out_field_string (uiout
, "what", "exception throw");
6515 ui_out_field_string (uiout
, "what", "exception catch");
6519 print_mention_exception_catchpoint (struct breakpoint
*b
)
6521 if (strstr (b
->addr_string
, "throw") != NULL
)
6522 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6524 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6527 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6528 print_exception_catchpoint
,
6529 print_one_exception_catchpoint
,
6530 print_mention_exception_catchpoint
6534 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6535 enum exception_event_kind ex_event
, int from_tty
)
6537 char *trigger_func_name
, *nameptr
;
6538 struct symtabs_and_lines sals
;
6539 struct breakpoint
*b
;
6541 if (ex_event
== EX_EVENT_CATCH
)
6542 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6544 trigger_func_name
= xstrdup ("__cxa_throw");
6546 nameptr
= trigger_func_name
;
6547 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6548 if (sals
.nelts
== 0)
6550 xfree (trigger_func_name
);
6554 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6555 set_breakpoint_count (breakpoint_count
+ 1);
6556 b
->number
= breakpoint_count
;
6557 b
->cond_string
= (cond_string
== NULL
) ?
6558 NULL
: savestring (cond_string
, strlen (cond_string
));
6560 b
->addr_string
= trigger_func_name
;
6561 b
->enable_state
= bp_enabled
;
6562 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6563 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6567 update_global_location_list ();
6571 /* Deal with "catch catch" and "catch throw" commands */
6574 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6575 int tempflag
, int from_tty
)
6577 char *cond_string
= NULL
;
6578 struct symtab_and_line
*sal
= NULL
;
6580 ep_skip_leading_whitespace (&arg
);
6582 cond_string
= ep_parse_optional_if_clause (&arg
);
6584 if ((*arg
!= '\0') && !isspace (*arg
))
6585 error (_("Junk at end of arguments."));
6587 if ((ex_event
!= EX_EVENT_THROW
) &&
6588 (ex_event
!= EX_EVENT_CATCH
))
6589 error (_("Unsupported or unknown exception event; cannot catch it"));
6591 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6594 warning (_("Unsupported with this platform/compiler combination."));
6597 /* Create a breakpoint struct for Ada exception catchpoints. */
6600 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6604 struct expression
*cond
,
6605 struct breakpoint_ops
*ops
,
6609 struct breakpoint
*b
;
6613 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6614 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6615 version for exception catchpoints, because two catchpoints
6616 used for different exception names will use the same address.
6617 In this case, a "breakpoint ... also set at..." warning is
6618 unproductive. Besides. the warning phrasing is also a bit
6619 inapropriate, we should use the word catchpoint, and tell
6620 the user what type of catchpoint it is. The above is good
6621 enough for now, though. */
6624 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6625 set_breakpoint_count (breakpoint_count
+ 1);
6627 b
->enable_state
= bp_enabled
;
6628 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6629 b
->number
= breakpoint_count
;
6630 b
->ignore_count
= 0;
6631 b
->loc
->cond
= cond
;
6632 b
->addr_string
= addr_string
;
6633 b
->language
= language_ada
;
6634 b
->cond_string
= cond_string
;
6635 b
->exp_string
= exp_string
;
6640 update_global_location_list ();
6643 /* Implement the "catch exception" command. */
6646 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6648 struct symtab_and_line sal
;
6650 char *addr_string
= NULL
;
6651 char *exp_string
= NULL
;
6652 char *cond_string
= NULL
;
6653 struct expression
*cond
= NULL
;
6654 struct breakpoint_ops
*ops
= NULL
;
6656 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6657 &cond_string
, &cond
, &ops
);
6658 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6659 cond_string
, cond
, ops
, tempflag
,
6663 /* Implement the "catch assert" command. */
6666 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6668 struct symtab_and_line sal
;
6669 char *addr_string
= NULL
;
6670 struct breakpoint_ops
*ops
= NULL
;
6672 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6673 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6674 tempflag
, from_tty
);
6678 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6681 /* The first argument may be an event name, such as "start" or "load".
6682 If so, then handle it as such. If it doesn't match an event name,
6683 then attempt to interpret it as an exception name. (This latter is
6684 the v4.16-and-earlier GDB meaning of the "catch" command.)
6686 First, try to find the bounds of what might be an event name. */
6687 char *arg1_start
= arg
;
6691 if (arg1_start
== NULL
)
6693 /* Old behaviour was to use pre-v-4.16 syntax */
6694 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6696 /* Now, this is not allowed */
6697 error (_("Catch requires an event name."));
6700 arg1_end
= ep_find_event_name_end (arg1_start
);
6701 if (arg1_end
== NULL
)
6702 error (_("catch requires an event"));
6703 arg1_length
= arg1_end
+ 1 - arg1_start
;
6705 /* Try to match what we found against known event names. */
6706 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6708 error (_("Catch of signal not yet implemented"));
6710 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6712 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6713 tempflag
, from_tty
);
6715 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6717 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6718 tempflag
, from_tty
);
6720 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6722 error (_("Catch of thread_start not yet implemented"));
6724 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6726 error (_("Catch of thread_exit not yet implemented"));
6728 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6730 error (_("Catch of thread_join not yet implemented"));
6732 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6734 error (_("Catch of start not yet implemented"));
6736 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6738 error (_("Catch of exit not yet implemented"));
6740 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6742 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6744 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6746 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6748 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6750 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6752 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6754 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6756 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6758 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6760 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6762 error (_("Catch of stop not yet implemented"));
6764 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6766 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6769 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6771 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6774 /* This doesn't appear to be an event name */
6778 /* Pre-v.4.16 behaviour was to treat the argument
6779 as the name of an exception */
6780 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6781 /* Now this is not allowed */
6782 error (_("Unknown event kind specified for catch"));
6788 catch_command (char *arg
, int from_tty
)
6790 catch_command_1 (arg
, 0, from_tty
);
6795 tcatch_command (char *arg
, int from_tty
)
6797 catch_command_1 (arg
, 1, from_tty
);
6800 /* Delete breakpoints by address or line. */
6803 clear_command (char *arg
, int from_tty
)
6805 struct breakpoint
*b
;
6806 VEC(breakpoint_p
) *found
= 0;
6809 struct symtabs_and_lines sals
;
6810 struct symtab_and_line sal
;
6815 sals
= decode_line_spec (arg
, 1);
6820 sals
.sals
= (struct symtab_and_line
*)
6821 xmalloc (sizeof (struct symtab_and_line
));
6822 make_cleanup (xfree
, sals
.sals
);
6823 init_sal (&sal
); /* initialize to zeroes */
6824 sal
.line
= default_breakpoint_line
;
6825 sal
.symtab
= default_breakpoint_symtab
;
6826 sal
.pc
= default_breakpoint_address
;
6827 if (sal
.symtab
== 0)
6828 error (_("No source file specified."));
6836 /* We don't call resolve_sal_pc here. That's not
6837 as bad as it seems, because all existing breakpoints
6838 typically have both file/line and pc set. So, if
6839 clear is given file/line, we can match this to existing
6840 breakpoint without obtaining pc at all.
6842 We only support clearing given the address explicitly
6843 present in breakpoint table. Say, we've set breakpoint
6844 at file:line. There were several PC values for that file:line,
6845 due to optimization, all in one block.
6846 We've picked one PC value. If "clear" is issued with another
6847 PC corresponding to the same file:line, the breakpoint won't
6848 be cleared. We probably can still clear the breakpoint, but
6849 since the other PC value is never presented to user, user
6850 can only find it by guessing, and it does not seem important
6853 /* For each line spec given, delete bps which correspond
6854 to it. Do it in two passes, solely to preserve the current
6855 behavior that from_tty is forced true if we delete more than
6859 for (i
= 0; i
< sals
.nelts
; i
++)
6861 /* If exact pc given, clear bpts at that pc.
6862 If line given (pc == 0), clear all bpts on specified line.
6863 If defaulting, clear all bpts on default line
6866 defaulting sal.pc != 0 tests to do
6871 1 0 <can't happen> */
6875 /* Find all matching breakpoints and add them to
6880 /* Are we going to delete b? */
6881 if (b
->type
!= bp_none
6882 && b
->type
!= bp_watchpoint
6883 && b
->type
!= bp_hardware_watchpoint
6884 && b
->type
!= bp_read_watchpoint
6885 && b
->type
!= bp_access_watchpoint
)
6887 struct bp_location
*loc
= b
->loc
;
6888 for (; loc
; loc
= loc
->next
)
6890 int pc_match
= sal
.pc
6891 && (loc
->address
== sal
.pc
)
6892 && (!section_is_overlay (loc
->section
)
6893 || loc
->section
== sal
.section
);
6894 int line_match
= ((default_match
|| (0 == sal
.pc
))
6895 && b
->source_file
!= NULL
6896 && sal
.symtab
!= NULL
6897 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6898 && b
->line_number
== sal
.line
);
6899 if (pc_match
|| line_match
)
6908 VEC_safe_push(breakpoint_p
, found
, b
);
6911 /* Now go thru the 'found' chain and delete them. */
6912 if (VEC_empty(breakpoint_p
, found
))
6915 error (_("No breakpoint at %s."), arg
);
6917 error (_("No breakpoint at this line."));
6920 if (VEC_length(breakpoint_p
, found
) > 1)
6921 from_tty
= 1; /* Always report if deleted more than one */
6924 if (VEC_length(breakpoint_p
, found
) == 1)
6925 printf_unfiltered (_("Deleted breakpoint "));
6927 printf_unfiltered (_("Deleted breakpoints "));
6929 breakpoints_changed ();
6931 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6934 printf_unfiltered ("%d ", b
->number
);
6935 delete_breakpoint (b
);
6938 putchar_unfiltered ('\n');
6941 /* Delete breakpoint in BS if they are `delete' breakpoints and
6942 all breakpoints that are marked for deletion, whether hit or not.
6943 This is called after any breakpoint is hit, or after errors. */
6946 breakpoint_auto_delete (bpstat bs
)
6948 struct breakpoint
*b
, *temp
;
6950 for (; bs
; bs
= bs
->next
)
6951 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
->disposition
== disp_del
6953 delete_breakpoint (bs
->breakpoint_at
->owner
);
6955 ALL_BREAKPOINTS_SAFE (b
, temp
)
6957 if (b
->disposition
== disp_del_at_next_stop
)
6958 delete_breakpoint (b
);
6963 update_global_location_list (void)
6965 struct breakpoint
*b
;
6966 struct bp_location
**next
= &bp_location_chain
;
6967 struct bp_location
*loc
;
6968 struct bp_location
*loc2
;
6969 struct gdb_exception e
;
6970 VEC(bp_location_p
) *old_locations
= NULL
;
6974 /* Store old locations for future reference. */
6975 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
6976 VEC_safe_push (bp_location_p
, old_locations
, loc
);
6978 bp_location_chain
= NULL
;
6981 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6984 next
= &(loc
->global_next
);
6989 /* Identify bp_location instances that are no longer present in the new
6990 list, and therefore should be freed. Note that it's not necessary that
6991 those locations should be removed from inferior -- if there's another
6992 location at the same address (previously marked as duplicate),
6993 we don't need to remove/insert the location. */
6994 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
6996 /* Tells if 'loc' is found amoung the new locations. If not, we
6998 int found_object
= 0;
6999 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7006 /* If this location is no longer present, and inserted, look if there's
7007 maybe a new location at the same address. If so, mark that one
7008 inserted, and don't remove this one. This is needed so that we
7009 don't have a time window where a breakpoint at certain location is not
7014 /* If the location is inserted now, we might have to remove it. */
7017 if (found_object
&& should_be_inserted (loc
))
7019 /* The location is still present in the location list, and still
7020 should be inserted. Don't do anything. */
7025 /* The location is either no longer present, or got disabled.
7026 See if there's another location at the same address, in which
7027 case we don't need to remove this one from the target. */
7028 if (breakpoint_address_is_meaningful (loc
->owner
))
7029 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7031 /* For the sake of should_insert_location. The
7032 call to check_duplicates will fix up this later. */
7033 loc2
->duplicate
= 0;
7034 if (should_be_inserted (loc2
)
7035 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7038 loc2
->target_info
= loc
->target_info
;
7046 if (remove_breakpoint (loc
, mark_uninserted
))
7048 /* This is just about all we can do. We could keep this
7049 location on the global list, and try to remove it next
7050 time, but there's no particular reason why we will
7053 Note that at this point, loc->owner is still valid,
7054 as delete_breakpoint frees the breakpoint only
7055 after calling us. */
7056 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7057 loc
->owner
->number
);
7062 free_bp_location (loc
);
7067 check_duplicates (b
);
7070 if (always_inserted_mode
&& target_has_execution
)
7071 insert_breakpoint_locations ();
7075 update_global_location_list_nothrow (void)
7077 struct gdb_exception e
;
7078 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7079 update_global_location_list ();
7082 /* Delete a breakpoint and clean up all traces of it in the data
7086 delete_breakpoint (struct breakpoint
*bpt
)
7088 struct breakpoint
*b
;
7090 struct bp_location
*loc
, *next
;
7092 gdb_assert (bpt
!= NULL
);
7094 /* Has this bp already been deleted? This can happen because multiple
7095 lists can hold pointers to bp's. bpstat lists are especial culprits.
7097 One example of this happening is a watchpoint's scope bp. When the
7098 scope bp triggers, we notice that the watchpoint is out of scope, and
7099 delete it. We also delete its scope bp. But the scope bp is marked
7100 "auto-deleting", and is already on a bpstat. That bpstat is then
7101 checked for auto-deleting bp's, which are deleted.
7103 A real solution to this problem might involve reference counts in bp's,
7104 and/or giving them pointers back to their referencing bpstat's, and
7105 teaching delete_breakpoint to only free a bp's storage when no more
7106 references were extent. A cheaper bandaid was chosen. */
7107 if (bpt
->type
== bp_none
)
7110 if (deprecated_delete_breakpoint_hook
)
7111 deprecated_delete_breakpoint_hook (bpt
);
7112 breakpoint_delete_event (bpt
->number
);
7114 if (breakpoint_chain
== bpt
)
7115 breakpoint_chain
= bpt
->next
;
7120 b
->next
= bpt
->next
;
7124 free_command_lines (&bpt
->commands
);
7125 if (bpt
->cond_string
!= NULL
)
7126 xfree (bpt
->cond_string
);
7127 if (bpt
->addr_string
!= NULL
)
7128 xfree (bpt
->addr_string
);
7129 if (bpt
->exp
!= NULL
)
7131 if (bpt
->exp_string
!= NULL
)
7132 xfree (bpt
->exp_string
);
7133 if (bpt
->val
!= NULL
)
7134 value_free (bpt
->val
);
7135 if (bpt
->source_file
!= NULL
)
7136 xfree (bpt
->source_file
);
7137 if (bpt
->dll_pathname
!= NULL
)
7138 xfree (bpt
->dll_pathname
);
7139 if (bpt
->triggered_dll_pathname
!= NULL
)
7140 xfree (bpt
->triggered_dll_pathname
);
7141 if (bpt
->exec_pathname
!= NULL
)
7142 xfree (bpt
->exec_pathname
);
7144 /* Be sure no bpstat's are pointing at it after it's been freed. */
7145 /* FIXME, how can we find all bpstat's?
7146 We just check stop_bpstat for now. Note that we cannot just
7147 remove bpstats pointing at bpt from the stop_bpstat list
7148 entirely, as breakpoint commands are associated with the bpstat;
7149 if we remove it here, then the later call to
7150 bpstat_do_actions (&stop_bpstat);
7151 in event-top.c won't do anything, and temporary breakpoints
7152 with commands won't work. */
7153 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
7154 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7156 bs
->breakpoint_at
= NULL
;
7158 /* bs->commands will be freed later. */
7161 /* Now that breakpoint is removed from breakpoint
7162 list, update the global location list. This
7163 will remove locations that used to belong to
7164 this breakpoint. Do this before freeing
7165 the breakpoint itself, since remove_breakpoint
7166 looks at location's owner. It might be better
7167 design to have location completely self-contained,
7168 but it's not the case now. */
7169 update_global_location_list ();
7172 /* On the chance that someone will soon try again to delete this same
7173 bp, we mark it as deleted before freeing its storage. */
7174 bpt
->type
= bp_none
;
7180 do_delete_breakpoint_cleanup (void *b
)
7182 delete_breakpoint (b
);
7186 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7188 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7192 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
7194 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
7198 delete_command (char *arg
, int from_tty
)
7200 struct breakpoint
*b
, *temp
;
7206 int breaks_to_delete
= 0;
7208 /* Delete all breakpoints if no argument.
7209 Do not delete internal or call-dummy breakpoints, these
7210 have to be deleted with an explicit breakpoint number argument. */
7213 if (b
->type
!= bp_call_dummy
&&
7214 b
->type
!= bp_shlib_event
&&
7215 b
->type
!= bp_thread_event
&&
7216 b
->type
!= bp_overlay_event
&&
7219 breaks_to_delete
= 1;
7224 /* Ask user only if there are some breakpoints to delete. */
7226 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7228 ALL_BREAKPOINTS_SAFE (b
, temp
)
7230 if (b
->type
!= bp_call_dummy
&&
7231 b
->type
!= bp_shlib_event
&&
7232 b
->type
!= bp_thread_event
&&
7233 b
->type
!= bp_overlay_event
&&
7235 delete_breakpoint (b
);
7240 map_breakpoint_numbers (arg
, delete_breakpoint
);
7244 all_locations_are_pending (struct bp_location
*loc
)
7246 for (; loc
; loc
= loc
->next
)
7247 if (!loc
->shlib_disabled
)
7252 /* Subroutine of update_breakpoint_locations to simplify it.
7253 Return non-zero if multiple fns in list LOC have the same name.
7254 Null names are ignored. */
7257 ambiguous_names_p (struct bp_location
*loc
)
7259 struct bp_location
*l
;
7260 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7261 (int (*) (const void *, const void *)) streq
,
7262 NULL
, xcalloc
, xfree
);
7264 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7267 const char *name
= l
->function_name
;
7269 /* Allow for some names to be NULL, ignore them. */
7273 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7275 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7290 update_breakpoint_locations (struct breakpoint
*b
,
7291 struct symtabs_and_lines sals
)
7295 struct bp_location
*existing_locations
= b
->loc
;
7297 /* If there's no new locations, and all existing locations
7298 are pending, don't do anything. This optimizes
7299 the common case where all locations are in the same
7300 shared library, that was unloaded. We'd like to
7301 retain the location, so that when the library
7302 is loaded again, we don't loose the enabled/disabled
7303 status of the individual locations. */
7304 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7309 for (i
= 0; i
< sals
.nelts
; ++i
)
7311 struct bp_location
*new_loc
=
7312 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7314 /* Reparse conditions, they might contain references to the
7316 if (b
->cond_string
!= NULL
)
7318 struct gdb_exception e
;
7321 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7323 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7328 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7329 b
->number
, e
.message
);
7330 new_loc
->enabled
= 0;
7334 if (b
->source_file
!= NULL
)
7335 xfree (b
->source_file
);
7336 if (sals
.sals
[i
].symtab
== NULL
)
7337 b
->source_file
= NULL
;
7340 savestring (sals
.sals
[i
].symtab
->filename
,
7341 strlen (sals
.sals
[i
].symtab
->filename
));
7343 if (b
->line_number
== 0)
7344 b
->line_number
= sals
.sals
[i
].line
;
7347 /* If possible, carry over 'disable' status from existing breakpoints. */
7349 struct bp_location
*e
= existing_locations
;
7350 /* If there are multiple breakpoints with the same function name,
7351 e.g. for inline functions, comparing function names won't work.
7352 Instead compare pc addresses; this is just a heuristic as things
7353 may have moved, but in practice it gives the correct answer
7354 often enough until a better solution is found. */
7355 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7357 for (; e
; e
= e
->next
)
7359 if (!e
->enabled
&& e
->function_name
)
7361 struct bp_location
*l
= b
->loc
;
7362 if (have_ambiguous_names
)
7364 for (; l
; l
= l
->next
)
7365 if (e
->address
== l
->address
)
7373 for (; l
; l
= l
->next
)
7374 if (l
->function_name
7375 && strcmp (e
->function_name
, l
->function_name
) == 0)
7385 update_global_location_list ();
7389 /* Reset a breakpoint given it's struct breakpoint * BINT.
7390 The value we return ends up being the return value from catch_errors.
7391 Unused in this case. */
7394 breakpoint_re_set_one (void *bint
)
7396 /* get past catch_errs */
7397 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7401 int *not_found_ptr
= ¬_found
;
7402 struct symtabs_and_lines sals
= {};
7403 struct symtabs_and_lines expanded
;
7405 enum enable_state save_enable
;
7406 struct gdb_exception e
;
7412 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7416 case bp_hardware_breakpoint
:
7418 case bp_catch_unload
:
7419 if (b
->addr_string
== NULL
)
7421 /* Anything without a string can't be re-set. */
7422 delete_breakpoint (b
);
7426 set_language (b
->language
);
7427 input_radix
= b
->input_radix
;
7429 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7431 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7436 int not_found_and_ok
= 0;
7437 /* For pending breakpoints, it's expected that parsing
7438 will fail until the right shared library is loaded.
7439 User has already told to create pending breakpoints and
7440 don't need extra messages. If breakpoint is in bp_shlib_disabled
7441 state, then user already saw the message about that breakpoint
7442 being disabled, and don't want to see more errors. */
7444 && (b
->condition_not_parsed
7445 || (b
->loc
&& b
->loc
->shlib_disabled
)
7446 || b
->enable_state
== bp_disabled
))
7447 not_found_and_ok
= 1;
7449 if (!not_found_and_ok
)
7451 /* We surely don't want to warn about the same breakpoint
7452 10 times. One solution, implemented here, is disable
7453 the breakpoint on error. Another solution would be to
7454 have separate 'warning emitted' flag. Since this
7455 happens only when a binary has changed, I don't know
7456 which approach is better. */
7457 b
->enable_state
= bp_disabled
;
7458 throw_exception (e
);
7465 gdb_assert (sals
.nelts
== 1);
7466 resolve_sal_pc (&sals
.sals
[0]);
7467 if (b
->condition_not_parsed
&& s
&& s
[0])
7469 char *cond_string
= 0;
7471 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7472 &cond_string
, &thread
);
7474 b
->cond_string
= cond_string
;
7476 b
->condition_not_parsed
= 0;
7478 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7479 update_breakpoint_locations (b
, expanded
);
7485 case bp_hardware_watchpoint
:
7486 case bp_read_watchpoint
:
7487 case bp_access_watchpoint
:
7488 /* Watchpoint can be either on expression using entirely global variables,
7489 or it can be on local variables.
7491 Watchpoints of the first kind are never auto-deleted, and even persist
7492 across program restarts. Since they can use variables from shared
7493 libraries, we need to reparse expression as libraries are loaded
7496 Watchpoints on local variables can also change meaning as result
7497 of solib event. For example, if a watchpoint uses both a local and
7498 a global variables in expression, it's a local watchpoint, but
7499 unloading of a shared library will make the expression invalid.
7500 This is not a very common use case, but we still re-evaluate
7501 expression, to avoid surprises to the user.
7503 Note that for local watchpoints, we re-evaluate it only if
7504 watchpoints frame id is still valid. If it's not, it means
7505 the watchpoint is out of scope and will be deleted soon. In fact,
7506 I'm not sure we'll ever be called in this case.
7508 If a local watchpoint's frame id is still valid, then
7509 b->exp_valid_block is likewise valid, and we can safely use it.
7511 Don't do anything about disabled watchpoints, since they will
7512 be reevaluated again when enabled. */
7513 update_watchpoint (b
, 1 /* reparse */);
7515 /* We needn't really do anything to reset these, since the mask
7516 that requests them is unaffected by e.g., new libraries being
7519 case bp_catch_vfork
:
7524 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7526 /* Delete longjmp and overlay event breakpoints; they will be
7527 reset later by breakpoint_re_set. */
7529 case bp_longjmp_resume
:
7530 case bp_overlay_event
:
7531 delete_breakpoint (b
);
7534 /* This breakpoint is special, it's set up when the inferior
7535 starts and we really don't want to touch it. */
7536 case bp_shlib_event
:
7538 /* Like bp_shlib_event, this breakpoint type is special.
7539 Once it is set up, we do not want to touch it. */
7540 case bp_thread_event
:
7542 /* Keep temporary breakpoints, which can be encountered when we step
7543 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7544 Otherwise these should have been blown away via the cleanup chain
7545 or by breakpoint_init_inferior when we rerun the executable. */
7548 case bp_watchpoint_scope
:
7550 case bp_step_resume
:
7557 /* Re-set all breakpoints after symbols have been re-loaded. */
7559 breakpoint_re_set (void)
7561 struct breakpoint
*b
, *temp
;
7562 enum language save_language
;
7563 int save_input_radix
;
7565 save_language
= current_language
->la_language
;
7566 save_input_radix
= input_radix
;
7567 ALL_BREAKPOINTS_SAFE (b
, temp
)
7569 /* Format possible error msg */
7570 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7572 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7573 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7574 do_cleanups (cleanups
);
7576 set_language (save_language
);
7577 input_radix
= save_input_radix
;
7579 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
7581 create_longjmp_breakpoint ("longjmp");
7582 create_longjmp_breakpoint ("_longjmp");
7583 create_longjmp_breakpoint ("siglongjmp");
7584 create_longjmp_breakpoint ("_siglongjmp");
7585 create_longjmp_breakpoint (NULL
);
7588 create_overlay_event_breakpoint ("_ovly_debug_event");
7591 /* Reset the thread number of this breakpoint:
7593 - If the breakpoint is for all threads, leave it as-is.
7594 - Else, reset it to the current thread for inferior_ptid. */
7596 breakpoint_re_set_thread (struct breakpoint
*b
)
7598 if (b
->thread
!= -1)
7600 if (in_thread_list (inferior_ptid
))
7601 b
->thread
= pid_to_thread_id (inferior_ptid
);
7605 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7606 If from_tty is nonzero, it prints a message to that effect,
7607 which ends with a period (no newline). */
7610 set_ignore_count (int bptnum
, int count
, int from_tty
)
7612 struct breakpoint
*b
;
7618 if (b
->number
== bptnum
)
7620 b
->ignore_count
= count
;
7624 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7626 else if (count
== 1)
7627 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7630 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7633 breakpoints_changed ();
7634 breakpoint_modify_event (b
->number
);
7638 error (_("No breakpoint number %d."), bptnum
);
7641 /* Clear the ignore counts of all breakpoints. */
7643 breakpoint_clear_ignore_counts (void)
7645 struct breakpoint
*b
;
7648 b
->ignore_count
= 0;
7651 /* Command to set ignore-count of breakpoint N to COUNT. */
7654 ignore_command (char *args
, int from_tty
)
7660 error_no_arg (_("a breakpoint number"));
7662 num
= get_number (&p
);
7664 error (_("bad breakpoint number: '%s'"), args
);
7666 error (_("Second argument (specified ignore-count) is missing."));
7668 set_ignore_count (num
,
7669 longest_to_int (value_as_long (parse_and_eval (p
))),
7672 printf_filtered ("\n");
7675 /* Call FUNCTION on each of the breakpoints
7676 whose numbers are given in ARGS. */
7679 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7684 struct breakpoint
*b
, *tmp
;
7688 error_no_arg (_("one or more breakpoint numbers"));
7695 num
= get_number_or_range (&p1
);
7698 warning (_("bad breakpoint number at or near '%s'"), p
);
7702 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7703 if (b
->number
== num
)
7705 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7708 if (related_breakpoint
)
7709 function (related_breakpoint
);
7713 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7719 static struct bp_location
*
7720 find_location_by_number (char *number
)
7722 char *dot
= strchr (number
, '.');
7726 struct breakpoint
*b
;
7727 struct bp_location
*loc
;
7732 bp_num
= get_number_or_range (&p1
);
7734 error (_("Bad breakpoint number '%s'"), number
);
7737 if (b
->number
== bp_num
)
7742 if (!b
|| b
->number
!= bp_num
)
7743 error (_("Bad breakpoint number '%s'"), number
);
7746 loc_num
= get_number_or_range (&p1
);
7748 error (_("Bad breakpoint location number '%s'"), number
);
7752 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7755 error (_("Bad breakpoint location number '%s'"), dot
+1);
7761 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7762 If from_tty is nonzero, it prints a message to that effect,
7763 which ends with a period (no newline). */
7766 disable_breakpoint (struct breakpoint
*bpt
)
7768 /* Never disable a watchpoint scope breakpoint; we want to
7769 hit them when we leave scope so we can delete both the
7770 watchpoint and its scope breakpoint at that time. */
7771 if (bpt
->type
== bp_watchpoint_scope
)
7774 /* You can't disable permanent breakpoints. */
7775 if (bpt
->enable_state
== bp_permanent
)
7778 bpt
->enable_state
= bp_disabled
;
7780 update_global_location_list ();
7782 if (deprecated_modify_breakpoint_hook
)
7783 deprecated_modify_breakpoint_hook (bpt
);
7784 breakpoint_modify_event (bpt
->number
);
7788 disable_command (char *args
, int from_tty
)
7790 struct breakpoint
*bpt
;
7792 ALL_BREAKPOINTS (bpt
)
7796 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7801 case bp_catch_unload
:
7803 case bp_catch_vfork
:
7805 case bp_hardware_breakpoint
:
7807 case bp_hardware_watchpoint
:
7808 case bp_read_watchpoint
:
7809 case bp_access_watchpoint
:
7810 disable_breakpoint (bpt
);
7814 else if (strchr (args
, '.'))
7816 struct bp_location
*loc
= find_location_by_number (args
);
7819 update_global_location_list ();
7822 map_breakpoint_numbers (args
, disable_breakpoint
);
7826 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7828 int target_resources_ok
, other_type_used
;
7831 if (bpt
->type
== bp_hardware_breakpoint
)
7834 i
= hw_breakpoint_used_count ();
7835 target_resources_ok
=
7836 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7838 if (target_resources_ok
== 0)
7839 error (_("No hardware breakpoint support in the target."));
7840 else if (target_resources_ok
< 0)
7841 error (_("Hardware breakpoints used exceeds limit."));
7844 if (bpt
->type
== bp_watchpoint
||
7845 bpt
->type
== bp_hardware_watchpoint
||
7846 bpt
->type
== bp_read_watchpoint
||
7847 bpt
->type
== bp_access_watchpoint
)
7849 struct frame_id saved_frame_id
;
7851 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7852 if (bpt
->exp_valid_block
!= NULL
)
7854 struct frame_info
*fr
=
7855 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7858 printf_filtered (_("\
7859 Cannot enable watchpoint %d because the block in which its expression\n\
7860 is valid is not currently in scope.\n"), bpt
->number
);
7867 value_free (bpt
->val
);
7868 mark
= value_mark ();
7869 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7871 release_value (bpt
->val
);
7874 if (bpt
->type
== bp_hardware_watchpoint
||
7875 bpt
->type
== bp_read_watchpoint
||
7876 bpt
->type
== bp_access_watchpoint
)
7878 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7879 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7881 /* Hack around 'unused var' error for some targets here */
7882 (void) mem_cnt
, (void) i
;
7883 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7884 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7885 /* we can consider of type is bp_hardware_watchpoint, convert to
7886 bp_watchpoint in the following condition */
7887 if (target_resources_ok
< 0)
7889 printf_filtered (_("\
7890 Cannot enable watchpoint %d because target watch resources\n\
7891 have been allocated for other watchpoints.\n"), bpt
->number
);
7892 value_free_to_mark (mark
);
7897 select_frame (frame_find_by_id (saved_frame_id
));
7898 value_free_to_mark (mark
);
7901 if (bpt
->enable_state
!= bp_permanent
)
7902 bpt
->enable_state
= bp_enabled
;
7903 bpt
->disposition
= disposition
;
7904 update_global_location_list ();
7905 breakpoints_changed ();
7907 if (deprecated_modify_breakpoint_hook
)
7908 deprecated_modify_breakpoint_hook (bpt
);
7909 breakpoint_modify_event (bpt
->number
);
7914 enable_breakpoint (struct breakpoint
*bpt
)
7916 do_enable_breakpoint (bpt
, bpt
->disposition
);
7919 /* The enable command enables the specified breakpoints (or all defined
7920 breakpoints) so they once again become (or continue to be) effective
7921 in stopping the inferior. */
7924 enable_command (char *args
, int from_tty
)
7926 struct breakpoint
*bpt
;
7928 ALL_BREAKPOINTS (bpt
)
7932 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7937 case bp_catch_unload
:
7939 case bp_catch_vfork
:
7941 case bp_hardware_breakpoint
:
7943 case bp_hardware_watchpoint
:
7944 case bp_read_watchpoint
:
7945 case bp_access_watchpoint
:
7946 enable_breakpoint (bpt
);
7950 else if (strchr (args
, '.'))
7952 struct bp_location
*loc
= find_location_by_number (args
);
7955 update_global_location_list ();
7958 map_breakpoint_numbers (args
, enable_breakpoint
);
7962 enable_once_breakpoint (struct breakpoint
*bpt
)
7964 do_enable_breakpoint (bpt
, disp_disable
);
7968 enable_once_command (char *args
, int from_tty
)
7970 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7974 enable_delete_breakpoint (struct breakpoint
*bpt
)
7976 do_enable_breakpoint (bpt
, disp_del
);
7980 enable_delete_command (char *args
, int from_tty
)
7982 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7986 set_breakpoint_cmd (char *args
, int from_tty
)
7991 show_breakpoint_cmd (char *args
, int from_tty
)
7995 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7997 struct symtabs_and_lines
7998 decode_line_spec_1 (char *string
, int funfirstline
)
8000 struct symtabs_and_lines sals
;
8002 error (_("Empty line specification."));
8003 if (default_breakpoint_valid
)
8004 sals
= decode_line_1 (&string
, funfirstline
,
8005 default_breakpoint_symtab
,
8006 default_breakpoint_line
,
8007 (char ***) NULL
, NULL
);
8009 sals
= decode_line_1 (&string
, funfirstline
,
8010 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8012 error (_("Junk at end of line specification: %s"), string
);
8016 /* Create and insert a raw software breakpoint at PC. Return an
8017 identifier, which should be used to remove the breakpoint later.
8018 In general, places which call this should be using something on the
8019 breakpoint chain instead; this function should be eliminated
8023 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8025 struct bp_target_info
*bp_tgt
;
8027 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8028 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8030 bp_tgt
->placed_address
= pc
;
8031 if (target_insert_breakpoint (bp_tgt
) != 0)
8033 /* Could not insert the breakpoint. */
8041 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8044 deprecated_remove_raw_breakpoint (void *bp
)
8046 struct bp_target_info
*bp_tgt
= bp
;
8049 ret
= target_remove_breakpoint (bp_tgt
);
8055 /* One (or perhaps two) breakpoints used for software single stepping. */
8057 static void *single_step_breakpoints
[2];
8059 /* Create and insert a breakpoint for software single step. */
8062 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8066 if (single_step_breakpoints
[0] == NULL
)
8067 bpt_p
= &single_step_breakpoints
[0];
8070 gdb_assert (single_step_breakpoints
[1] == NULL
);
8071 bpt_p
= &single_step_breakpoints
[1];
8074 /* NOTE drow/2006-04-11: A future improvement to this function would be
8075 to only create the breakpoints once, and actually put them on the
8076 breakpoint chain. That would let us use set_raw_breakpoint. We could
8077 adjust the addresses each time they were needed. Doing this requires
8078 corresponding changes elsewhere where single step breakpoints are
8079 handled, however. So, for now, we use this. */
8081 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8083 error (_("Could not insert single-step breakpoint at 0x%s"),
8084 paddr_nz (next_pc
));
8087 /* Remove and delete any breakpoints used for software single step. */
8090 remove_single_step_breakpoints (void)
8092 gdb_assert (single_step_breakpoints
[0] != NULL
);
8094 /* See insert_single_step_breakpoint for more about this deprecated
8096 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8097 single_step_breakpoints
[0] = NULL
;
8099 if (single_step_breakpoints
[1] != NULL
)
8101 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8102 single_step_breakpoints
[1] = NULL
;
8106 /* Check whether a software single-step breakpoint is inserted at PC. */
8109 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8113 for (i
= 0; i
< 2; i
++)
8115 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8116 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8123 int breakpoints_always_inserted_mode (void)
8125 return always_inserted_mode
;
8129 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8130 It is defined as a macro to prevent duplication.
8131 COMMAND should be a string constant containing the name of the command. */
8132 #define BREAK_ARGS_HELP(command) \
8133 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8134 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8135 If a line number is specified, break at start of code for that line.\n\
8136 If a function is specified, break at start of code for that function.\n\
8137 If an address is specified, break at that exact address.\n\
8138 With no LOCATION, uses current execution address of selected stack frame.\n\
8139 This is useful for breaking on return to a stack frame.\n\
8141 THREADNUM is the number from \"info threads\".\n\
8142 CONDITION is a boolean expression.\n\
8144 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8146 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8149 _initialize_breakpoint (void)
8151 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8152 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8153 struct cmd_list_element
*c
;
8155 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8157 breakpoint_chain
= 0;
8158 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8159 before a breakpoint is set. */
8160 breakpoint_count
= 0;
8162 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8163 Set ignore-count of breakpoint number N to COUNT.\n\
8164 Usage is `ignore N COUNT'."));
8166 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8168 add_com ("commands", class_breakpoint
, commands_command
, _("\
8169 Set commands to be executed when a breakpoint is hit.\n\
8170 Give breakpoint number as argument after \"commands\".\n\
8171 With no argument, the targeted breakpoint is the last one set.\n\
8172 The commands themselves follow starting on the next line.\n\
8173 Type a line containing \"end\" to indicate the end of them.\n\
8174 Give \"silent\" as the first line to make the breakpoint silent;\n\
8175 then no output is printed when it is hit, except what the commands print."));
8177 add_com ("condition", class_breakpoint
, condition_command
, _("\
8178 Specify breakpoint number N to break only if COND is true.\n\
8179 Usage is `condition N COND', where N is an integer and COND is an\n\
8180 expression to be evaluated whenever breakpoint N is reached."));
8182 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8183 Set a temporary breakpoint.\n\
8184 Like \"break\" except the breakpoint is only temporary,\n\
8185 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8186 by using \"enable delete\" on the breakpoint number.\n\
8188 BREAK_ARGS_HELP ("tbreak")));
8189 set_cmd_completer (c
, location_completer
);
8191 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8192 Set a hardware assisted breakpoint.\n\
8193 Like \"break\" except the breakpoint requires hardware support,\n\
8194 some target hardware may not have this support.\n\
8196 BREAK_ARGS_HELP ("hbreak")));
8197 set_cmd_completer (c
, location_completer
);
8199 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8200 Set a temporary hardware assisted breakpoint.\n\
8201 Like \"hbreak\" except the breakpoint is only temporary,\n\
8202 so it will be deleted when hit.\n\
8204 BREAK_ARGS_HELP ("thbreak")));
8205 set_cmd_completer (c
, location_completer
);
8207 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8208 Enable some breakpoints.\n\
8209 Give breakpoint numbers (separated by spaces) as arguments.\n\
8210 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8211 This is used to cancel the effect of the \"disable\" command.\n\
8212 With a subcommand you can enable temporarily."),
8213 &enablelist
, "enable ", 1, &cmdlist
);
8215 add_com ("ab", class_breakpoint
, enable_command
, _("\
8216 Enable some breakpoints.\n\
8217 Give breakpoint numbers (separated by spaces) as arguments.\n\
8218 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8219 This is used to cancel the effect of the \"disable\" command.\n\
8220 With a subcommand you can enable temporarily."));
8222 add_com_alias ("en", "enable", class_breakpoint
, 1);
8224 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8225 Enable some breakpoints.\n\
8226 Give breakpoint numbers (separated by spaces) as arguments.\n\
8227 This is used to cancel the effect of the \"disable\" command.\n\
8228 May be abbreviated to simply \"enable\".\n"),
8229 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8231 add_cmd ("once", no_class
, enable_once_command
, _("\
8232 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8233 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8236 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8237 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8238 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8241 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8242 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8243 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8246 add_cmd ("once", no_class
, enable_once_command
, _("\
8247 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8248 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8251 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8252 Disable some breakpoints.\n\
8253 Arguments are breakpoint numbers with spaces in between.\n\
8254 To disable all breakpoints, give no argument.\n\
8255 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8256 &disablelist
, "disable ", 1, &cmdlist
);
8257 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8258 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8260 add_com ("sb", class_breakpoint
, disable_command
, _("\
8261 Disable some breakpoints.\n\
8262 Arguments are breakpoint numbers with spaces in between.\n\
8263 To disable all breakpoints, give no argument.\n\
8264 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8266 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8267 Disable some breakpoints.\n\
8268 Arguments are breakpoint numbers with spaces in between.\n\
8269 To disable all breakpoints, give no argument.\n\
8270 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8271 This command may be abbreviated \"disable\"."),
8274 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8275 Delete some breakpoints or auto-display expressions.\n\
8276 Arguments are breakpoint numbers with spaces in between.\n\
8277 To delete all breakpoints, give no argument.\n\
8279 Also a prefix command for deletion of other GDB objects.\n\
8280 The \"unset\" command is also an alias for \"delete\"."),
8281 &deletelist
, "delete ", 1, &cmdlist
);
8282 add_com_alias ("d", "delete", class_breakpoint
, 1);
8283 add_com_alias ("del", "delete", class_breakpoint
, 1);
8285 add_com ("db", class_breakpoint
, delete_command
, _("\
8286 Delete some breakpoints.\n\
8287 Arguments are breakpoint numbers with spaces in between.\n\
8288 To delete all breakpoints, give no argument.\n"));
8290 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8291 Delete some breakpoints or auto-display expressions.\n\
8292 Arguments are breakpoint numbers with spaces in between.\n\
8293 To delete all breakpoints, give no argument.\n\
8294 This command may be abbreviated \"delete\"."),
8297 add_com ("clear", class_breakpoint
, clear_command
, _("\
8298 Clear breakpoint at specified line or function.\n\
8299 Argument may be line number, function name, or \"*\" and an address.\n\
8300 If line number is specified, all breakpoints in that line are cleared.\n\
8301 If function is specified, breakpoints at beginning of function are cleared.\n\
8302 If an address is specified, breakpoints at that address are cleared.\n\
8304 With no argument, clears all breakpoints in the line that the selected frame\n\
8307 See also the \"delete\" command which clears breakpoints by number."));
8309 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8310 Set breakpoint at specified line or function.\n"
8311 BREAK_ARGS_HELP ("break")));
8312 set_cmd_completer (c
, location_completer
);
8314 add_com_alias ("b", "break", class_run
, 1);
8315 add_com_alias ("br", "break", class_run
, 1);
8316 add_com_alias ("bre", "break", class_run
, 1);
8317 add_com_alias ("brea", "break", class_run
, 1);
8321 add_com_alias ("ba", "break", class_breakpoint
, 1);
8322 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8327 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8328 Break in function/address or break at a line in the current file."),
8329 &stoplist
, "stop ", 1, &cmdlist
);
8330 add_cmd ("in", class_breakpoint
, stopin_command
,
8331 _("Break in function or address."), &stoplist
);
8332 add_cmd ("at", class_breakpoint
, stopat_command
,
8333 _("Break at a line in the current file."), &stoplist
);
8334 add_com ("status", class_info
, breakpoints_info
, _("\
8335 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8336 The \"Type\" column indicates one of:\n\
8337 \tbreakpoint - normal breakpoint\n\
8338 \twatchpoint - watchpoint\n\
8339 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8340 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8341 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8342 address and file/line number respectively.\n\
8344 Convenience variable \"$_\" and default examine address for \"x\"\n\
8345 are set to the address of the last breakpoint listed unless the command\n\
8346 is prefixed with \"server \".\n\n\
8347 Convenience variable \"$bpnum\" contains the number of the last\n\
8351 add_info ("breakpoints", breakpoints_info
, _("\
8352 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8353 The \"Type\" column indicates one of:\n\
8354 \tbreakpoint - normal breakpoint\n\
8355 \twatchpoint - watchpoint\n\
8356 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8357 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8358 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8359 address and file/line number respectively.\n\
8361 Convenience variable \"$_\" and default examine address for \"x\"\n\
8362 are set to the address of the last breakpoint listed unless the command\n\
8363 is prefixed with \"server \".\n\n\
8364 Convenience variable \"$bpnum\" contains the number of the last\n\
8368 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8369 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8370 The \"Type\" column indicates one of:\n\
8371 \tbreakpoint - normal breakpoint\n\
8372 \twatchpoint - watchpoint\n\
8373 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8374 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8375 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8376 address and file/line number respectively.\n\
8378 Convenience variable \"$_\" and default examine address for \"x\"\n\
8379 are set to the address of the last breakpoint listed unless the command\n\
8380 is prefixed with \"server \".\n\n\
8381 Convenience variable \"$bpnum\" contains the number of the last\n\
8384 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8385 Status of all breakpoints, or breakpoint number NUMBER.\n\
8386 The \"Type\" column indicates one of:\n\
8387 \tbreakpoint - normal breakpoint\n\
8388 \twatchpoint - watchpoint\n\
8389 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8390 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8391 \tuntil - internal breakpoint used by the \"until\" command\n\
8392 \tfinish - internal breakpoint used by the \"finish\" command\n\
8393 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8394 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8395 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8396 address and file/line number respectively.\n\
8398 Convenience variable \"$_\" and default examine address for \"x\"\n\
8399 are set to the address of the last breakpoint listed unless the command\n\
8400 is prefixed with \"server \".\n\n\
8401 Convenience variable \"$bpnum\" contains the number of the last\n\
8403 &maintenanceinfolist
);
8405 add_com ("catch", class_breakpoint
, catch_command
, _("\
8406 Set catchpoints to catch events.\n\
8407 Raised signals may be caught:\n\
8408 \tcatch signal - all signals\n\
8409 \tcatch signal <signame> - a particular signal\n\
8410 Raised exceptions may be caught:\n\
8411 \tcatch throw - all exceptions, when thrown\n\
8412 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8413 \tcatch catch - all exceptions, when caught\n\
8414 \tcatch catch <exceptname> - a particular exception, when caught\n\
8415 Thread or process events may be caught:\n\
8416 \tcatch thread_start - any threads, just after creation\n\
8417 \tcatch thread_exit - any threads, just before expiration\n\
8418 \tcatch thread_join - any threads, just after joins\n\
8419 Process events may be caught:\n\
8420 \tcatch start - any processes, just after creation\n\
8421 \tcatch exit - any processes, just before expiration\n\
8422 \tcatch fork - calls to fork()\n\
8423 \tcatch vfork - calls to vfork()\n\
8424 \tcatch exec - calls to exec()\n\
8425 Dynamically-linked library events may be caught:\n\
8426 \tcatch load - loads of any library\n\
8427 \tcatch load <libname> - loads of a particular library\n\
8428 \tcatch unload - unloads of any library\n\
8429 \tcatch unload <libname> - unloads of a particular library\n\
8430 The act of your program's execution stopping may also be caught:\n\
8432 C++ exceptions may be caught:\n\
8433 \tcatch throw - all exceptions, when thrown\n\
8434 \tcatch catch - all exceptions, when caught\n\
8435 Ada exceptions may be caught:\n\
8436 \tcatch exception - all exceptions, when raised\n\
8437 \tcatch exception <name> - a particular exception, when raised\n\
8438 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8439 \tcatch assert - all failed assertions, when raised\n\
8441 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8442 after a fork or vfork is caught.\n\n\
8443 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8445 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8446 Set temporary catchpoints to catch events.\n\
8447 Args like \"catch\" command.\n\
8448 Like \"catch\" except the catchpoint is only temporary,\n\
8449 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8450 by using \"enable delete\" on the catchpoint number."));
8452 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8453 Set a watchpoint for an expression.\n\
8454 A watchpoint stops execution of your program whenever the value of\n\
8455 an expression changes."));
8456 set_cmd_completer (c
, location_completer
);
8458 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8459 Set a read watchpoint for an expression.\n\
8460 A watchpoint stops execution of your program whenever the value of\n\
8461 an expression is read."));
8462 set_cmd_completer (c
, location_completer
);
8464 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8465 Set a watchpoint for an expression.\n\
8466 A watchpoint stops execution of your program whenever the value of\n\
8467 an expression is either read or written."));
8468 set_cmd_completer (c
, location_completer
);
8470 add_info ("watchpoints", breakpoints_info
,
8471 _("Synonym for ``info breakpoints''."));
8474 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8475 respond to changes - contrary to the description. */
8476 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8477 &can_use_hw_watchpoints
, _("\
8478 Set debugger's willingness to use watchpoint hardware."), _("\
8479 Show debugger's willingness to use watchpoint hardware."), _("\
8480 If zero, gdb will not use hardware for new watchpoints, even if\n\
8481 such is available. (However, any hardware watchpoints that were\n\
8482 created before setting this to nonzero, will continue to use watchpoint\n\
8485 show_can_use_hw_watchpoints
,
8486 &setlist
, &showlist
);
8488 can_use_hw_watchpoints
= 1;
8490 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8491 Breakpoint specific settings\n\
8492 Configure various breakpoint-specific variables such as\n\
8493 pending breakpoint behavior"),
8494 &breakpoint_set_cmdlist
, "set breakpoint ",
8495 0/*allow-unknown*/, &setlist
);
8496 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8497 Breakpoint specific settings\n\
8498 Configure various breakpoint-specific variables such as\n\
8499 pending breakpoint behavior"),
8500 &breakpoint_show_cmdlist
, "show breakpoint ",
8501 0/*allow-unknown*/, &showlist
);
8503 add_setshow_auto_boolean_cmd ("pending", no_class
,
8504 &pending_break_support
, _("\
8505 Set debugger's behavior regarding pending breakpoints."), _("\
8506 Show debugger's behavior regarding pending breakpoints."), _("\
8507 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8508 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8509 an error. If auto, an unrecognized breakpoint location results in a\n\
8510 user-query to see if a pending breakpoint should be created."),
8512 show_pending_break_support
,
8513 &breakpoint_set_cmdlist
,
8514 &breakpoint_show_cmdlist
);
8516 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8518 add_setshow_boolean_cmd ("auto-hw", no_class
,
8519 &automatic_hardware_breakpoints
, _("\
8520 Set automatic usage of hardware breakpoints."), _("\
8521 Show automatic usage of hardware breakpoints."), _("\
8522 If set, the debugger will automatically use hardware breakpoints for\n\
8523 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8524 a warning will be emitted for such breakpoints."),
8526 show_automatic_hardware_breakpoints
,
8527 &breakpoint_set_cmdlist
,
8528 &breakpoint_show_cmdlist
);
8530 add_setshow_boolean_cmd ("always-inserted", class_support
,
8531 &always_inserted_mode
, _("\
8532 Set mode for inserting breakpoints."), _("\
8533 Show mode for inserting breakpoints."), _("\
8534 When this mode is off (which is the default), breakpoints are inserted in\n\
8535 inferior when it is resumed, and removed when execution stops. When this\n\
8536 mode is on, breakpoints are inserted immediately and removed only when\n\
8537 the user deletes the breakpoint."),
8539 &show_always_inserted_mode
,
8540 &breakpoint_set_cmdlist
,
8541 &breakpoint_show_cmdlist
);
8543 automatic_hardware_breakpoints
= 1;