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/>. */
26 #include "breakpoint.h"
28 #include "expression.h"
34 #include "gdbthread.h"
37 #include "gdb_string.h"
44 #include "completer.h"
47 #include "cli/cli-script.h"
48 #include "gdb_assert.h"
53 #include "exceptions.h"
58 #include "gdb-events.h"
59 #include "mi/mi-common.h"
61 /* Prototypes for local functions. */
63 static void until_break_command_continuation (struct continuation_arg
*arg
);
65 static void catch_command_1 (char *, int, int);
67 static void enable_delete_command (char *, int);
69 static void enable_delete_breakpoint (struct breakpoint
*);
71 static void enable_once_command (char *, int);
73 static void enable_once_breakpoint (struct breakpoint
*);
75 static void disable_command (char *, int);
77 static void enable_command (char *, int);
79 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
81 static void ignore_command (char *, int);
83 static int breakpoint_re_set_one (void *);
85 static void clear_command (char *, int);
87 static void catch_command (char *, int);
89 static void watch_command (char *, int);
91 static int can_use_hardware_watchpoint (struct value
*);
93 static int break_command_1 (char *, int, int);
95 static void mention (struct breakpoint
*);
97 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
99 static void check_duplicates (struct breakpoint
*);
101 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
103 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
106 static void describe_other_breakpoints (CORE_ADDR
, asection
*, int);
108 static void breakpoints_info (char *, int);
110 static void breakpoint_1 (int, int);
112 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
114 static int breakpoint_cond_eval (void *);
116 static void cleanup_executing_breakpoints (void *);
118 static void commands_command (char *, int);
120 static void condition_command (char *, int);
122 static int get_number_trailer (char **, int);
124 void set_breakpoint_count (int);
133 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
135 static enum print_stop_action
print_it_typical (bpstat
);
137 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
141 enum exception_event_kind kind
;
144 args_for_catchpoint_enable
;
146 static int watchpoint_check (void *);
148 static void maintenance_info_breakpoints (char *, int);
150 static void create_longjmp_breakpoint (char *);
152 static void create_overlay_event_breakpoint (char *);
154 static int hw_breakpoint_used_count (void);
156 static int hw_watchpoint_used_count (enum bptype
, int *);
158 static void hbreak_command (char *, int);
160 static void thbreak_command (char *, int);
162 static void watch_command_1 (char *, int, int);
164 static void rwatch_command (char *, int);
166 static void awatch_command (char *, int);
168 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
170 static void create_fork_vfork_event_catchpoint (int tempflag
,
172 enum bptype bp_kind
);
174 static void stop_command (char *arg
, int from_tty
);
176 static void stopin_command (char *arg
, int from_tty
);
178 static void stopat_command (char *arg
, int from_tty
);
180 static char *ep_find_event_name_end (char *arg
);
182 static char *ep_parse_optional_if_clause (char **arg
);
184 static char *ep_parse_optional_filename (char **arg
);
186 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
187 enum exception_event_kind ex_event
,
188 struct symtab_and_line
*sal
);
190 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
191 char *arg
, int tempflag
, int from_tty
);
193 static void tcatch_command (char *arg
, int from_tty
);
195 static void ep_skip_leading_whitespace (char **s
);
197 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
199 static void free_bp_location (struct bp_location
*loc
);
201 static void mark_breakpoints_out (void);
203 /* Prototypes for exported functions. */
205 /* If FALSE, gdb will not use hardware support for watchpoints, even
206 if such is available. */
207 static int can_use_hw_watchpoints
;
210 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
211 struct cmd_list_element
*c
,
214 fprintf_filtered (file
, _("\
215 Debugger's willingness to use watchpoint hardware is %s.\n"),
219 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
220 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
221 for unrecognized breakpoint locations.
222 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
223 static enum auto_boolean pending_break_support
;
225 show_pending_break_support (struct ui_file
*file
, int from_tty
,
226 struct cmd_list_element
*c
,
229 fprintf_filtered (file
, _("\
230 Debugger's behavior regarding pending breakpoints is %s.\n"),
234 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
235 set with "break" but falling in read-only memory.
236 If 0, gdb will warn about such breakpoints, but won't automatically
237 use hardware breakpoints. */
238 static int automatic_hardware_breakpoints
;
240 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
241 struct cmd_list_element
*c
,
244 fprintf_filtered (file
, _("\
245 Automatic usage of hardware breakpoints is %s.\n"),
250 void _initialize_breakpoint (void);
252 extern int addressprint
; /* Print machine addresses? */
254 /* Are we executing breakpoint commands? */
255 static int executing_breakpoint_commands
;
257 /* Are overlay event breakpoints enabled? */
258 static int overlay_events_enabled
;
260 /* Walk the following statement or block through all breakpoints.
261 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
264 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
266 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
267 for (B = breakpoint_chain; \
268 B ? (TMP=B->next, 1): 0; \
271 /* Similar iterators for the low-level breakpoints. */
273 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
275 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
276 for (B = bp_location_chain; \
277 B ? (TMP=B->global_next, 1): 0; \
280 /* True if breakpoint hit counts should be displayed in breakpoint info. */
282 int show_breakpoint_hit_counts
= 1;
284 /* Chains of all breakpoints defined. */
286 struct breakpoint
*breakpoint_chain
;
288 struct bp_location
*bp_location_chain
;
290 /* Number of last breakpoint made. */
292 int breakpoint_count
;
294 /* Pointer to current exception event record */
295 static struct exception_event_record
*current_exception_event
;
297 /* This function returns a pointer to the string representation of the
298 pathname of the dynamically-linked library that has just been
301 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
302 or undefined results are guaranteed.
304 This string's contents are only valid immediately after the
305 inferior has stopped in the dynamic linker hook, and becomes
306 invalid as soon as the inferior is continued. Clients should make
307 a copy of this string if they wish to continue the inferior and
308 then access the string. */
310 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
311 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
314 /* This function returns a pointer to the string representation of the
315 pathname of the dynamically-linked library that has just been
318 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
319 TRUE, or undefined results are guaranteed.
321 This string's contents are only valid immediately after the
322 inferior has stopped in the dynamic linker hook, and becomes
323 invalid as soon as the inferior is continued. Clients should make
324 a copy of this string if they wish to continue the inferior and
325 then access the string. */
327 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
328 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
331 /* This function is called by the "catch load" command. It allows the
332 debugger to be notified by the dynamic linker when a specified
333 library file (or any library file, if filename is NULL) is loaded. */
335 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
336 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
337 error (_("catch of library loads not yet implemented on this platform"))
340 /* This function is called by the "catch unload" command. It allows
341 the debugger to be notified by the dynamic linker when a specified
342 library file (or any library file, if filename is NULL) is
345 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
346 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
347 error (_("catch of library unloads not yet implemented on this platform"))
350 /* Return whether a breakpoint is an active enabled breakpoint. */
352 breakpoint_enabled (struct breakpoint
*b
)
354 return (b
->enable_state
== bp_enabled
);
357 /* Set breakpoint count to NUM. */
360 set_breakpoint_count (int num
)
362 breakpoint_count
= num
;
363 set_internalvar (lookup_internalvar ("bpnum"),
364 value_from_longest (builtin_type_int
, (LONGEST
) num
));
367 /* Used in run_command to zero the hit count when a new run starts. */
370 clear_breakpoint_hit_counts (void)
372 struct breakpoint
*b
;
378 /* Default address, symtab and line to put a breakpoint at
379 for "break" command with no arg.
380 if default_breakpoint_valid is zero, the other three are
381 not valid, and "break" with no arg is an error.
383 This set by print_stack_frame, which calls set_default_breakpoint. */
385 int default_breakpoint_valid
;
386 CORE_ADDR default_breakpoint_address
;
387 struct symtab
*default_breakpoint_symtab
;
388 int default_breakpoint_line
;
390 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
391 Advance *PP after the string and any trailing whitespace.
393 Currently the string can either be a number or "$" followed by the name
394 of a convenience variable. Making it an expression wouldn't work well
395 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
397 If the string is a NULL pointer, that denotes the last breakpoint.
399 TRAILER is a character which can be found after the number; most
400 commonly this is `-'. If you don't want a trailer, use \0. */
402 get_number_trailer (char **pp
, int trailer
)
404 int retval
= 0; /* default */
408 /* Empty line means refer to the last breakpoint. */
409 return breakpoint_count
;
412 /* Make a copy of the name, so we can null-terminate it
413 to pass to lookup_internalvar(). */
418 while (isalnum (*p
) || *p
== '_')
420 varname
= (char *) alloca (p
- start
+ 1);
421 strncpy (varname
, start
, p
- start
);
422 varname
[p
- start
] = '\0';
423 val
= value_of_internalvar (lookup_internalvar (varname
));
424 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
425 retval
= (int) value_as_long (val
);
428 printf_filtered (_("Convenience variable must have integer value.\n"));
436 while (*p
>= '0' && *p
<= '9')
439 /* There is no number here. (e.g. "cond a == b"). */
441 /* Skip non-numeric token */
442 while (*p
&& !isspace((int) *p
))
444 /* Return zero, which caller must interpret as error. */
450 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
452 /* Trailing junk: return 0 and let caller print error msg. */
453 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
464 /* Like get_number_trailer, but don't allow a trailer. */
466 get_number (char **pp
)
468 return get_number_trailer (pp
, '\0');
471 /* Parse a number or a range.
472 * A number will be of the form handled by get_number.
473 * A range will be of the form <number1> - <number2>, and
474 * will represent all the integers between number1 and number2,
477 * While processing a range, this fuction is called iteratively;
478 * At each call it will return the next value in the range.
480 * At the beginning of parsing a range, the char pointer PP will
481 * be advanced past <number1> and left pointing at the '-' token.
482 * Subsequent calls will not advance the pointer until the range
483 * is completed. The call that completes the range will advance
484 * pointer PP past <number2>.
488 get_number_or_range (char **pp
)
490 static int last_retval
, end_value
;
491 static char *end_ptr
;
492 static int in_range
= 0;
496 /* Default case: pp is pointing either to a solo number,
497 or to the first number of a range. */
498 last_retval
= get_number_trailer (pp
, '-');
503 /* This is the start of a range (<number1> - <number2>).
504 Skip the '-', parse and remember the second number,
505 and also remember the end of the final token. */
509 while (isspace ((int) *end_ptr
))
510 end_ptr
++; /* skip white space */
511 end_value
= get_number (temp
);
512 if (end_value
< last_retval
)
514 error (_("inverted range"));
516 else if (end_value
== last_retval
)
518 /* degenerate range (number1 == number2). Advance the
519 token pointer so that the range will be treated as a
528 error (_("negative value"));
531 /* pp points to the '-' that betokens a range. All
532 number-parsing has already been done. Return the next
533 integer value (one greater than the saved previous value).
534 Do not advance the token pointer 'pp' until the end of range
537 if (++last_retval
== end_value
)
539 /* End of range reached; advance token pointer. */
549 /* condition N EXP -- set break condition of breakpoint N to EXP. */
552 condition_command (char *arg
, int from_tty
)
554 struct breakpoint
*b
;
559 error_no_arg (_("breakpoint number"));
562 bnum
= get_number (&p
);
564 error (_("Bad breakpoint argument: '%s'"), arg
);
567 if (b
->number
== bnum
)
569 struct bp_location
*loc
= b
->loc
;
570 for (; loc
; loc
= loc
->next
)
578 if (b
->cond_string
!= NULL
)
579 xfree (b
->cond_string
);
583 b
->cond_string
= NULL
;
585 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
590 /* I don't know if it matters whether this is the string the user
591 typed in or the decompiled expression. */
592 b
->cond_string
= savestring (arg
, strlen (arg
));
593 b
->condition_not_parsed
= 0;
594 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
597 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
599 error (_("Junk at end of expression"));
602 breakpoints_changed ();
603 breakpoint_modify_event (b
->number
);
607 error (_("No breakpoint number %d."), bnum
);
611 commands_command (char *arg
, int from_tty
)
613 struct breakpoint
*b
;
616 struct command_line
*l
;
618 /* If we allowed this, we would have problems with when to
619 free the storage, if we change the commands currently
622 if (executing_breakpoint_commands
)
623 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
626 bnum
= get_number (&p
);
629 error (_("Unexpected extra arguments following breakpoint number."));
632 if (b
->number
== bnum
)
634 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
636 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
637 l
= read_command_lines (tmpbuf
, from_tty
);
638 do_cleanups (cleanups
);
639 free_command_lines (&b
->commands
);
641 breakpoints_changed ();
642 breakpoint_modify_event (b
->number
);
645 error (_("No breakpoint number %d."), bnum
);
648 /* Like commands_command, but instead of reading the commands from
649 input stream, takes them from an already parsed command structure.
651 This is used by cli-script.c to DTRT with breakpoint commands
652 that are part of if and while bodies. */
653 enum command_control_type
654 commands_from_control_command (char *arg
, struct command_line
*cmd
)
656 struct breakpoint
*b
;
660 /* If we allowed this, we would have problems with when to
661 free the storage, if we change the commands currently
664 if (executing_breakpoint_commands
)
665 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
667 /* An empty string for the breakpoint number means the last
668 breakpoint, but get_number expects a NULL pointer. */
673 bnum
= get_number (&p
);
676 error (_("Unexpected extra arguments following breakpoint number."));
679 if (b
->number
== bnum
)
681 free_command_lines (&b
->commands
);
682 if (cmd
->body_count
!= 1)
683 error (_("Invalid \"commands\" block structure."));
684 /* We need to copy the commands because if/while will free the
685 list after it finishes execution. */
686 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
687 breakpoints_changed ();
688 breakpoint_modify_event (b
->number
);
689 return simple_control
;
691 error (_("No breakpoint number %d."), bnum
);
694 /* Like target_read_memory() but if breakpoints are inserted, return
695 the shadow contents instead of the breakpoints themselves.
697 Read "memory data" from whatever target or inferior we have.
698 Returns zero if successful, errno value if not. EIO is used
699 for address out of bounds. If breakpoints are inserted, returns
700 shadow contents, not the breakpoints themselves. From breakpoint.c. */
703 read_memory_nobpt (CORE_ADDR memaddr
, gdb_byte
*myaddr
, unsigned len
)
706 const struct bp_location
*b
;
707 CORE_ADDR bp_addr
= 0;
710 if (gdbarch_breakpoint_from_pc (current_gdbarch
, &bp_addr
, &bp_size
) == NULL
)
711 /* No breakpoints on this machine. */
712 return target_read_memory (memaddr
, myaddr
, len
);
716 if (b
->owner
->type
== bp_none
)
717 warning (_("reading through apparently deleted breakpoint #%d?"),
720 if (b
->loc_type
!= bp_loc_software_breakpoint
)
724 /* Addresses and length of the part of the breakpoint that
726 bp_addr
= b
->target_info
.placed_address
;
727 bp_size
= b
->target_info
.shadow_len
;
729 /* bp isn't valid, or doesn't shadow memory. */
731 if (bp_addr
+ bp_size
<= memaddr
)
732 /* The breakpoint is entirely before the chunk of memory we
735 if (bp_addr
>= memaddr
+ len
)
736 /* The breakpoint is entirely after the chunk of memory we are
739 /* Copy the breakpoint from the shadow contents, and recurse for
740 the things before and after. */
742 /* Offset within shadow_contents. */
745 if (bp_addr
< memaddr
)
747 /* Only copy the second part of the breakpoint. */
748 bp_size
-= memaddr
- bp_addr
;
749 bptoffset
= memaddr
- bp_addr
;
753 if (bp_addr
+ bp_size
> memaddr
+ len
)
755 /* Only copy the first part of the breakpoint. */
756 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
759 memcpy (myaddr
+ bp_addr
- memaddr
,
760 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
762 if (bp_addr
> memaddr
)
764 /* Copy the section of memory before the breakpoint. */
765 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
770 if (bp_addr
+ bp_size
< memaddr
+ len
)
772 /* Copy the section of memory after the breakpoint. */
773 status
= read_memory_nobpt (bp_addr
+ bp_size
,
774 myaddr
+ bp_addr
+ bp_size
- memaddr
,
775 memaddr
+ len
- (bp_addr
+ bp_size
));
782 /* Nothing overlaps. Just call read_memory_noerr. */
783 return target_read_memory (memaddr
, myaddr
, len
);
787 /* A wrapper function for inserting catchpoints. */
789 insert_catchpoint (struct ui_out
*uo
, void *args
)
791 struct breakpoint
*b
= (struct breakpoint
*) args
;
797 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
800 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
803 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
806 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
811 /* Helper routine: free the value chain for a breakpoint (watchpoint). */
814 free_valchain (struct bp_location
*b
)
819 /* Free the saved value chain. We will construct a new one
820 the next time the watchpoint is inserted. */
821 for (v
= b
->owner
->val_chain
; v
; v
= n
)
826 b
->owner
->val_chain
= NULL
;
829 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
830 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
831 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
833 NOTE drow/2003-09-09: This routine could be broken down to an object-style
834 method for each breakpoint or catchpoint type. */
836 insert_bp_location (struct bp_location
*bpt
,
837 struct ui_file
*tmp_error_stream
,
838 int *disabled_breaks
, int *process_warning
,
839 int *hw_breakpoint_error
)
843 if (!breakpoint_enabled (bpt
->owner
))
846 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->inserted
|| bpt
->duplicate
)
849 /* Initialize the target-specific information. */
850 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
851 bpt
->target_info
.placed_address
= bpt
->address
;
853 if (bpt
->loc_type
== bp_loc_software_breakpoint
854 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
856 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
858 /* If the explicitly specified breakpoint type
859 is not hardware breakpoint, check the memory map to see
860 if the breakpoint address is in read only memory or not.
861 Two important cases are:
862 - location type is not hardware breakpoint, memory
863 is readonly. We change the type of the location to
865 - location type is hardware breakpoint, memory is read-write.
866 This means we've previously made the location hardware one, but
867 then the memory map changed, so we undo.
869 When breakpoints are removed, remove_breakpoints will
870 use location types we've just set here, the only possible
871 problem is that memory map has changed during running program,
872 but it's not going to work anyway with current gdb. */
873 struct mem_region
*mr
874 = lookup_mem_region (bpt
->target_info
.placed_address
);
878 if (automatic_hardware_breakpoints
)
881 enum bp_loc_type new_type
;
883 if (mr
->attrib
.mode
!= MEM_RW
)
884 new_type
= bp_loc_hardware_breakpoint
;
886 new_type
= bp_loc_software_breakpoint
;
888 if (new_type
!= bpt
->loc_type
)
891 bpt
->loc_type
= new_type
;
894 fprintf_filtered (gdb_stdout
, _("\
895 Note: automatically using hardware breakpoints for read-only addresses.\n"));
900 else if (bpt
->loc_type
== bp_loc_software_breakpoint
901 && mr
->attrib
.mode
!= MEM_RW
)
902 warning (_("cannot set software breakpoint at readonly address %s"),
903 paddr (bpt
->address
));
907 /* First check to see if we have to handle an overlay. */
908 if (overlay_debugging
== ovly_off
909 || bpt
->section
== NULL
910 || !(section_is_overlay (bpt
->section
)))
912 /* No overlay handling: just set the breakpoint. */
914 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
915 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
917 val
= target_insert_breakpoint (&bpt
->target_info
);
921 /* This breakpoint is in an overlay section.
922 Shall we set a breakpoint at the LMA? */
923 if (!overlay_events_enabled
)
925 /* Yes -- overlay event support is not active,
926 so we must try to set a breakpoint at the LMA.
927 This will not work for a hardware breakpoint. */
928 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
929 warning (_("hardware breakpoint %d not supported in overlay!"),
933 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
935 /* Set a software (trap) breakpoint at the LMA. */
936 bpt
->overlay_target_info
= bpt
->target_info
;
937 bpt
->overlay_target_info
.placed_address
= addr
;
938 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
940 fprintf_unfiltered (tmp_error_stream
,
941 "Overlay breakpoint %d failed: in ROM?",
945 /* Shall we set a breakpoint at the VMA? */
946 if (section_is_mapped (bpt
->section
))
948 /* Yes. This overlay section is mapped into memory. */
949 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
950 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
952 val
= target_insert_breakpoint (&bpt
->target_info
);
956 /* No. This breakpoint will not be inserted.
957 No error, but do not mark the bp as 'inserted'. */
964 /* Can't set the breakpoint. */
965 if (solib_address (bpt
->address
))
967 /* See also: disable_breakpoints_in_shlibs. */
969 bpt
->shlib_disabled
= 1;
970 if (!*disabled_breaks
)
972 fprintf_unfiltered (tmp_error_stream
,
973 "Cannot insert breakpoint %d.\n",
975 fprintf_unfiltered (tmp_error_stream
,
976 "Temporarily disabling shared library breakpoints:\n");
978 *disabled_breaks
= 1;
979 fprintf_unfiltered (tmp_error_stream
,
980 "breakpoint #%d\n", bpt
->owner
->number
);
984 #ifdef ONE_PROCESS_WRITETEXT
985 *process_warning
= 1;
987 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
989 *hw_breakpoint_error
= 1;
990 fprintf_unfiltered (tmp_error_stream
,
991 "Cannot insert hardware breakpoint %d.\n",
996 fprintf_unfiltered (tmp_error_stream
,
997 "Cannot insert breakpoint %d.\n",
999 fprintf_filtered (tmp_error_stream
,
1000 "Error accessing memory address ");
1001 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1002 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1003 safe_strerror (val
));
1014 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1015 /* NOTE drow/2003-09-08: This state only exists for removing
1016 watchpoints. It's not clear that it's necessary... */
1017 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1019 /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints
1020 based on the expression. Ideally this should happen at a higher level,
1021 and there should be one bp_location for each computed address we
1022 must watch. As soon as a many-to-one mapping is available I'll
1025 int within_current_scope
;
1026 struct value
*mark
= value_mark ();
1028 struct frame_id saved_frame_id
;
1030 /* Save the current frame's ID so we can restore it after
1031 evaluating the watchpoint expression on its own frame. */
1032 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1033 took a frame parameter, so that we didn't have to change the
1035 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1037 /* Determine if the watchpoint is within scope. */
1038 if (bpt
->owner
->exp_valid_block
== NULL
)
1039 within_current_scope
= 1;
1042 struct frame_info
*fi
;
1043 fi
= frame_find_by_id (bpt
->owner
->watchpoint_frame
);
1044 within_current_scope
= (fi
!= NULL
);
1045 if (within_current_scope
)
1049 if (within_current_scope
)
1051 free_valchain (bpt
);
1053 /* Evaluate the expression and cut the chain of values
1054 produced off from the value chain.
1056 Make sure the value returned isn't lazy; we use
1057 laziness to determine what memory GDB actually needed
1058 in order to compute the value of the expression. */
1059 v
= evaluate_expression (bpt
->owner
->exp
);
1061 value_release_to_mark (mark
);
1063 bpt
->owner
->val_chain
= v
;
1066 /* Look at each value on the value chain. */
1067 for (; v
; v
= value_next (v
))
1069 /* If it's a memory location, and GDB actually needed
1070 its contents to evaluate the expression, then we
1072 if (VALUE_LVAL (v
) == lval_memory
1073 && ! value_lazy (v
))
1075 struct type
*vtype
= check_typedef (value_type (v
));
1077 /* We only watch structs and arrays if user asked
1078 for it explicitly, never if they just happen to
1079 appear in the middle of some value chain. */
1080 if (v
== bpt
->owner
->val_chain
1081 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1082 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1087 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
1088 len
= TYPE_LENGTH (value_type (v
));
1090 if (bpt
->owner
->type
== bp_read_watchpoint
)
1092 else if (bpt
->owner
->type
== bp_access_watchpoint
)
1095 val
= target_insert_watchpoint (addr
, len
, type
);
1098 /* Don't exit the loop, try to insert
1099 every value on the value chain. That's
1100 because we will be removing all the
1101 watches below, and removing a
1102 watchpoint we didn't insert could have
1110 /* Failure to insert a watchpoint on any memory value in the
1111 value chain brings us here. */
1114 remove_breakpoint (bpt
, mark_uninserted
);
1115 *hw_breakpoint_error
= 1;
1116 fprintf_unfiltered (tmp_error_stream
,
1117 "Could not insert hardware watchpoint %d.\n",
1118 bpt
->owner
->number
);
1124 printf_filtered (_("\
1125 Hardware watchpoint %d deleted because the program has left the block \n\
1126 in which its expression is valid.\n"),
1127 bpt
->owner
->number
);
1128 if (bpt
->owner
->related_breakpoint
)
1129 bpt
->owner
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1130 bpt
->owner
->disposition
= disp_del_at_next_stop
;
1133 /* Restore the selected frame. */
1134 select_frame (frame_find_by_id (saved_frame_id
));
1139 else if (bpt
->owner
->type
== bp_catch_fork
1140 || bpt
->owner
->type
== bp_catch_vfork
1141 || bpt
->owner
->type
== bp_catch_exec
)
1143 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1144 bpt
->owner
, RETURN_MASK_ERROR
);
1145 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1146 bpt
->owner
->number
);
1148 bpt
->owner
->enable_state
= bp_disabled
;
1152 /* We've already printed an error message if there was a problem
1153 inserting this catchpoint, and we've disabled the catchpoint,
1154 so just return success. */
1161 /* insert_breakpoints is used when starting or continuing the program.
1162 remove_breakpoints is used when the program stops.
1163 Both return zero if successful,
1164 or an `errno' value if could not write the inferior. */
1167 insert_breakpoints (void)
1169 struct bp_location
*b
, *temp
;
1172 int disabled_breaks
= 0;
1173 int hw_breakpoint_error
= 0;
1174 int process_warning
= 0;
1176 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1177 make_cleanup_ui_file_delete (tmp_error_stream
);
1179 /* Explicitly mark the warning -- this will only be printed if
1180 there was an error. */
1181 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1183 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1185 if (!breakpoint_enabled (b
->owner
))
1188 /* There is no point inserting thread-specific breakpoints if the
1189 thread no longer exists. */
1190 if (b
->owner
->thread
!= -1
1191 && !valid_thread_id (b
->owner
->thread
))
1194 /* FIXME drow/2003-10-07: This code should be pushed elsewhere when
1195 hardware watchpoints are split into multiple loc breakpoints. */
1196 if ((b
->loc_type
== bp_loc_hardware_watchpoint
1197 || b
->owner
->type
== bp_watchpoint
) && !b
->owner
->val
)
1200 val
= evaluate_expression (b
->owner
->exp
);
1201 release_value (val
);
1202 if (value_lazy (val
))
1203 value_fetch_lazy (val
);
1204 b
->owner
->val
= val
;
1207 val
= insert_bp_location (b
, tmp_error_stream
,
1208 &disabled_breaks
, &process_warning
,
1209 &hw_breakpoint_error
);
1216 /* If a hardware breakpoint or watchpoint was inserted, add a
1217 message about possibly exhausted resources. */
1218 if (hw_breakpoint_error
)
1220 fprintf_unfiltered (tmp_error_stream
,
1221 "Could not insert hardware breakpoints:\n\
1222 You may have requested too many hardware breakpoints/watchpoints.\n");
1224 #ifdef ONE_PROCESS_WRITETEXT
1225 if (process_warning
)
1226 fprintf_unfiltered (tmp_error_stream
,
1227 "The same program may be running in another process.");
1229 target_terminal_ours_for_output ();
1230 error_stream (tmp_error_stream
);
1235 remove_breakpoints (void)
1237 struct bp_location
*b
;
1240 ALL_BP_LOCATIONS (b
)
1244 val
= remove_breakpoint (b
, mark_uninserted
);
1253 remove_hw_watchpoints (void)
1255 struct bp_location
*b
;
1258 ALL_BP_LOCATIONS (b
)
1260 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1262 val
= remove_breakpoint (b
, mark_uninserted
);
1271 reattach_breakpoints (int pid
)
1273 struct bp_location
*b
;
1275 struct cleanup
*old_chain
= save_inferior_ptid ();
1276 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1277 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1279 make_cleanup_ui_file_delete (tmp_error_stream
);
1281 inferior_ptid
= pid_to_ptid (pid
);
1282 ALL_BP_LOCATIONS (b
)
1287 val
= insert_bp_location (b
, tmp_error_stream
,
1288 &dummy1
, &dummy2
, &dummy3
);
1291 do_cleanups (old_chain
);
1296 do_cleanups (old_chain
);
1301 update_breakpoints_after_exec (void)
1303 struct breakpoint
*b
;
1304 struct breakpoint
*temp
;
1306 /* Doing this first prevents the badness of having delete_breakpoint()
1307 write a breakpoint's current "shadow contents" to lift the bp. That
1308 shadow is NOT valid after an exec()! */
1309 mark_breakpoints_out ();
1311 ALL_BREAKPOINTS_SAFE (b
, temp
)
1313 /* Solib breakpoints must be explicitly reset after an exec(). */
1314 if (b
->type
== bp_shlib_event
)
1316 delete_breakpoint (b
);
1320 /* Thread event breakpoints must be set anew after an exec(),
1321 as must overlay event breakpoints. */
1322 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1324 delete_breakpoint (b
);
1328 /* Step-resume breakpoints are meaningless after an exec(). */
1329 if (b
->type
== bp_step_resume
)
1331 delete_breakpoint (b
);
1335 /* Don't delete an exec catchpoint, because else the inferior
1336 won't stop when it ought!
1338 Similarly, we probably ought to keep vfork catchpoints, 'cause
1339 on this target, we may not be able to stop when the vfork is
1340 seen, but only when the subsequent exec is seen. (And because
1341 deleting fork catchpoints here but not vfork catchpoints will
1342 seem mysterious to users, keep those too.) */
1343 if ((b
->type
== bp_catch_exec
) ||
1344 (b
->type
== bp_catch_vfork
) ||
1345 (b
->type
== bp_catch_fork
))
1350 /* bp_finish is a special case. The only way we ought to be able
1351 to see one of these when an exec() has happened, is if the user
1352 caught a vfork, and then said "finish". Ordinarily a finish just
1353 carries them to the call-site of the current callee, by setting
1354 a temporary bp there and resuming. But in this case, the finish
1355 will carry them entirely through the vfork & exec.
1357 We don't want to allow a bp_finish to remain inserted now. But
1358 we can't safely delete it, 'cause finish_command has a handle to
1359 the bp on a bpstat, and will later want to delete it. There's a
1360 chance (and I've seen it happen) that if we delete the bp_finish
1361 here, that its storage will get reused by the time finish_command
1362 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1363 We really must allow finish_command to delete a bp_finish.
1365 In the absense of a general solution for the "how do we know
1366 it's safe to delete something others may have handles to?"
1367 problem, what we'll do here is just uninsert the bp_finish, and
1368 let finish_command delete it.
1370 (We know the bp_finish is "doomed" in the sense that it's
1371 momentary, and will be deleted as soon as finish_command sees
1372 the inferior stopped. So it doesn't matter that the bp's
1373 address is probably bogus in the new a.out, unlike e.g., the
1374 solib breakpoints.) */
1376 if (b
->type
== bp_finish
)
1381 /* Without a symbolic address, we have little hope of the
1382 pre-exec() address meaning the same thing in the post-exec()
1384 if (b
->addr_string
== NULL
)
1386 delete_breakpoint (b
);
1390 /* FIXME what about longjmp breakpoints? Re-create them here? */
1391 create_overlay_event_breakpoint ("_ovly_debug_event");
1395 detach_breakpoints (int pid
)
1397 struct bp_location
*b
;
1399 struct cleanup
*old_chain
= save_inferior_ptid ();
1401 if (pid
== PIDGET (inferior_ptid
))
1402 error (_("Cannot detach breakpoints of inferior_ptid"));
1404 /* Set inferior_ptid; remove_breakpoint uses this global. */
1405 inferior_ptid
= pid_to_ptid (pid
);
1406 ALL_BP_LOCATIONS (b
)
1410 val
= remove_breakpoint (b
, mark_inserted
);
1413 do_cleanups (old_chain
);
1418 do_cleanups (old_chain
);
1423 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1427 if (b
->owner
->enable_state
== bp_permanent
)
1428 /* Permanent breakpoints cannot be inserted or removed. */
1431 if (b
->owner
->type
== bp_none
)
1432 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1435 if (b
->loc_type
== bp_loc_software_breakpoint
1436 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1438 /* "Normal" instruction breakpoint: either the standard
1439 trap-instruction bp (bp_breakpoint), or a
1440 bp_hardware_breakpoint. */
1442 /* First check to see if we have to handle an overlay. */
1443 if (overlay_debugging
== ovly_off
1444 || b
->section
== NULL
1445 || !(section_is_overlay (b
->section
)))
1447 /* No overlay handling: just remove the breakpoint. */
1449 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1450 val
= target_remove_hw_breakpoint (&b
->target_info
);
1452 val
= target_remove_breakpoint (&b
->target_info
);
1456 /* This breakpoint is in an overlay section.
1457 Did we set a breakpoint at the LMA? */
1458 if (!overlay_events_enabled
)
1460 /* Yes -- overlay event support is not active, so we
1461 should have set a breakpoint at the LMA. Remove it.
1463 /* Ignore any failures: if the LMA is in ROM, we will
1464 have already warned when we failed to insert it. */
1465 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1466 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1468 target_remove_breakpoint (&b
->overlay_target_info
);
1470 /* Did we set a breakpoint at the VMA?
1471 If so, we will have marked the breakpoint 'inserted'. */
1474 /* Yes -- remove it. Previously we did not bother to
1475 remove the breakpoint if the section had been
1476 unmapped, but let's not rely on that being safe. We
1477 don't know what the overlay manager might do. */
1478 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1479 val
= target_remove_hw_breakpoint (&b
->target_info
);
1481 /* However, we should remove *software* breakpoints only
1482 if the section is still mapped, or else we overwrite
1483 wrong code with the saved shadow contents. */
1484 else if (section_is_mapped (b
->section
))
1485 val
= target_remove_breakpoint (&b
->target_info
);
1491 /* No -- not inserted, so no need to remove. No error. */
1497 b
->inserted
= (is
== mark_inserted
);
1499 else if (b
->loc_type
== bp_loc_hardware_watchpoint
1500 && breakpoint_enabled (b
->owner
)
1506 b
->inserted
= (is
== mark_inserted
);
1507 /* Walk down the saved value chain. */
1508 for (v
= b
->owner
->val_chain
; v
; v
= value_next (v
))
1510 /* For each memory reference remove the watchpoint
1512 if (VALUE_LVAL (v
) == lval_memory
1513 && ! value_lazy (v
))
1515 struct type
*vtype
= check_typedef (value_type (v
));
1517 if (v
== b
->owner
->val_chain
1518 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1519 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1524 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
1525 len
= TYPE_LENGTH (value_type (v
));
1527 if (b
->owner
->type
== bp_read_watchpoint
)
1529 else if (b
->owner
->type
== bp_access_watchpoint
)
1532 val
= target_remove_watchpoint (addr
, len
, type
);
1539 /* Failure to remove any of the hardware watchpoints comes here. */
1540 if ((is
== mark_uninserted
) && (b
->inserted
))
1541 warning (_("Could not remove hardware watchpoint %d."),
1544 else if ((b
->owner
->type
== bp_catch_fork
||
1545 b
->owner
->type
== bp_catch_vfork
||
1546 b
->owner
->type
== bp_catch_exec
)
1547 && breakpoint_enabled (b
->owner
)
1551 switch (b
->owner
->type
)
1554 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1556 case bp_catch_vfork
:
1557 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1560 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1563 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1568 b
->inserted
= (is
== mark_inserted
);
1574 /* Clear the "inserted" flag in all breakpoints. */
1577 mark_breakpoints_out (void)
1579 struct bp_location
*bpt
;
1581 ALL_BP_LOCATIONS (bpt
)
1585 /* Clear the "inserted" flag in all breakpoints and delete any
1586 breakpoints which should go away between runs of the program.
1588 Plus other such housekeeping that has to be done for breakpoints
1591 Note: this function gets called at the end of a run (by
1592 generic_mourn_inferior) and when a run begins (by
1593 init_wait_for_inferior). */
1598 breakpoint_init_inferior (enum inf_context context
)
1600 struct breakpoint
*b
, *temp
;
1601 struct bp_location
*bpt
;
1603 ALL_BP_LOCATIONS (bpt
)
1606 ALL_BREAKPOINTS_SAFE (b
, temp
)
1611 case bp_watchpoint_scope
:
1613 /* If the call dummy breakpoint is at the entry point it will
1614 cause problems when the inferior is rerun, so we better
1617 Also get rid of scope breakpoints. */
1618 delete_breakpoint (b
);
1622 case bp_hardware_watchpoint
:
1623 case bp_read_watchpoint
:
1624 case bp_access_watchpoint
:
1626 /* Likewise for watchpoints on local expressions. */
1627 if (b
->exp_valid_block
!= NULL
)
1628 delete_breakpoint (b
);
1629 else if (context
== inf_starting
)
1631 /* Reset val field to force reread of starting value
1632 in insert_breakpoints. */
1634 value_free (b
->val
);
1644 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1645 exists at PC. It returns ordinary_breakpoint_here if it's an
1646 ordinary breakpoint, or permanent_breakpoint_here if it's a
1647 permanent breakpoint.
1648 - When continuing from a location with an ordinary breakpoint, we
1649 actually single step once before calling insert_breakpoints.
1650 - When continuing from a localion with a permanent breakpoint, we
1651 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1652 the target, to advance the PC past the breakpoint. */
1654 enum breakpoint_here
1655 breakpoint_here_p (CORE_ADDR pc
)
1657 const struct bp_location
*bpt
;
1658 int any_breakpoint_here
= 0;
1660 ALL_BP_LOCATIONS (bpt
)
1662 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1663 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1666 if ((breakpoint_enabled (bpt
->owner
)
1667 || bpt
->owner
->enable_state
== bp_permanent
)
1668 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1670 if (overlay_debugging
1671 && section_is_overlay (bpt
->section
)
1672 && !section_is_mapped (bpt
->section
))
1673 continue; /* unmapped overlay -- can't be a match */
1674 else if (bpt
->owner
->enable_state
== bp_permanent
)
1675 return permanent_breakpoint_here
;
1677 any_breakpoint_here
= 1;
1681 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1685 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1686 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1687 This does not check for single-step breakpoints, which are
1688 inserted and removed using direct target manipulation. */
1691 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1693 const struct bp_location
*bpt
;
1695 ALL_BP_LOCATIONS (bpt
)
1697 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1698 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1702 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1704 if (overlay_debugging
1705 && section_is_overlay (bpt
->section
)
1706 && !section_is_mapped (bpt
->section
))
1707 continue; /* unmapped overlay -- can't be a match */
1715 /* Returns non-zero iff there's either regular breakpoint
1716 or a single step breakpoint inserted at PC. */
1719 breakpoint_inserted_here_p (CORE_ADDR pc
)
1721 if (regular_breakpoint_inserted_here_p (pc
))
1724 if (single_step_breakpoint_inserted_here_p (pc
))
1730 /* This function returns non-zero iff there is a software breakpoint
1734 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1736 const struct bp_location
*bpt
;
1737 int any_breakpoint_here
= 0;
1739 ALL_BP_LOCATIONS (bpt
)
1741 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1745 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1747 if (overlay_debugging
1748 && section_is_overlay (bpt
->section
)
1749 && !section_is_mapped (bpt
->section
))
1750 continue; /* unmapped overlay -- can't be a match */
1756 /* Also check for software single-step breakpoints. */
1757 if (single_step_breakpoint_inserted_here_p (pc
))
1763 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1764 PC is valid for process/thread PTID. */
1767 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1769 const struct bp_location
*bpt
;
1772 thread
= pid_to_thread_id (ptid
);
1774 ALL_BP_LOCATIONS (bpt
)
1776 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1777 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1780 if ((breakpoint_enabled (bpt
->owner
)
1781 || bpt
->owner
->enable_state
== bp_permanent
)
1782 && bpt
->address
== pc
1783 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1785 if (overlay_debugging
1786 && section_is_overlay (bpt
->section
)
1787 && !section_is_mapped (bpt
->section
))
1788 continue; /* unmapped overlay -- can't be a match */
1798 /* bpstat stuff. External routines' interfaces are documented
1802 ep_is_catchpoint (struct breakpoint
*ep
)
1805 (ep
->type
== bp_catch_load
)
1806 || (ep
->type
== bp_catch_unload
)
1807 || (ep
->type
== bp_catch_fork
)
1808 || (ep
->type
== bp_catch_vfork
)
1809 || (ep
->type
== bp_catch_exec
);
1811 /* ??rehrauer: Add more kinds here, as are implemented... */
1815 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1818 (ep
->type
== bp_catch_load
)
1819 || (ep
->type
== bp_catch_unload
);
1823 bpstat_free (bpstat bs
)
1825 if (bs
->old_val
!= NULL
)
1826 value_free (bs
->old_val
);
1827 free_command_lines (&bs
->commands
);
1831 /* Clear a bpstat so that it says we are not at any breakpoint.
1832 Also free any storage that is part of a bpstat. */
1835 bpstat_clear (bpstat
*bsp
)
1852 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1853 is part of the bpstat is copied as well. */
1856 bpstat_copy (bpstat bs
)
1860 bpstat retval
= NULL
;
1865 for (; bs
!= NULL
; bs
= bs
->next
)
1867 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1868 memcpy (tmp
, bs
, sizeof (*tmp
));
1869 if (bs
->commands
!= NULL
)
1870 tmp
->commands
= copy_command_lines (bs
->commands
);
1871 if (bs
->old_val
!= NULL
)
1872 tmp
->old_val
= value_copy (bs
->old_val
);
1875 /* This is the first thing in the chain. */
1885 /* Find the bpstat associated with this breakpoint */
1888 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1893 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1895 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
1901 /* Find a step_resume breakpoint associated with this bpstat.
1902 (If there are multiple step_resume bp's on the list, this function
1903 will arbitrarily pick one.)
1905 It is an error to use this function if BPSTAT doesn't contain a
1906 step_resume breakpoint.
1908 See wait_for_inferior's use of this function. */
1910 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1914 gdb_assert (bsp
!= NULL
);
1916 current_thread
= pid_to_thread_id (inferior_ptid
);
1918 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1920 if ((bsp
->breakpoint_at
!= NULL
) &&
1921 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
1922 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
1923 bsp
->breakpoint_at
->owner
->thread
== -1))
1924 return bsp
->breakpoint_at
->owner
;
1927 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
1931 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
1932 at. *BSP upon return is a bpstat which points to the remaining
1933 breakpoints stopped at (but which is not guaranteed to be good for
1934 anything but further calls to bpstat_num).
1935 Return 0 if passed a bpstat which does not indicate any breakpoints.
1936 Return -1 if stopped at a breakpoint that has been deleted since
1938 Return 1 otherwise. */
1941 bpstat_num (bpstat
*bsp
, int *num
)
1943 struct breakpoint
*b
;
1946 return 0; /* No more breakpoint values */
1948 /* We assume we'll never have several bpstats that
1949 correspond to a single breakpoint -- otherwise,
1950 this function might return the same number more
1951 than once and this will look ugly. */
1952 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
1953 *bsp
= (*bsp
)->next
;
1955 return -1; /* breakpoint that's been deleted since */
1957 *num
= b
->number
; /* We have its number */
1961 /* Modify BS so that the actions will not be performed. */
1964 bpstat_clear_actions (bpstat bs
)
1966 for (; bs
!= NULL
; bs
= bs
->next
)
1968 free_command_lines (&bs
->commands
);
1969 if (bs
->old_val
!= NULL
)
1971 value_free (bs
->old_val
);
1977 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1979 cleanup_executing_breakpoints (void *ignore
)
1981 executing_breakpoint_commands
= 0;
1984 /* Execute all the commands associated with all the breakpoints at this
1985 location. Any of these commands could cause the process to proceed
1986 beyond this point, etc. We look out for such changes by checking
1987 the global "breakpoint_proceeded" after each command. */
1990 bpstat_do_actions (bpstat
*bsp
)
1993 struct cleanup
*old_chain
;
1995 /* Avoid endless recursion if a `source' command is contained
1997 if (executing_breakpoint_commands
)
2000 executing_breakpoint_commands
= 1;
2001 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2004 /* Note that (as of this writing), our callers all appear to
2005 be passing us the address of global stop_bpstat. And, if
2006 our calls to execute_control_command cause the inferior to
2007 proceed, that global (and hence, *bsp) will change.
2009 We must be careful to not touch *bsp unless the inferior
2010 has not proceeded. */
2012 /* This pointer will iterate over the list of bpstat's. */
2015 breakpoint_proceeded
= 0;
2016 for (; bs
!= NULL
; bs
= bs
->next
)
2018 struct command_line
*cmd
;
2019 struct cleanup
*this_cmd_tree_chain
;
2021 /* Take ownership of the BSP's command tree, if it has one.
2023 The command tree could legitimately contain commands like
2024 'step' and 'next', which call clear_proceed_status, which
2025 frees stop_bpstat's command tree. To make sure this doesn't
2026 free the tree we're executing out from under us, we need to
2027 take ownership of the tree ourselves. Since a given bpstat's
2028 commands are only executed once, we don't need to copy it; we
2029 can clear the pointer in the bpstat, and make sure we free
2030 the tree when we're done. */
2033 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2037 execute_control_command (cmd
);
2039 if (breakpoint_proceeded
)
2045 /* We can free this command tree now. */
2046 do_cleanups (this_cmd_tree_chain
);
2048 if (breakpoint_proceeded
)
2049 /* The inferior is proceeded by the command; bomb out now.
2050 The bpstat chain has been blown away by wait_for_inferior.
2051 But since execution has stopped again, there is a new bpstat
2052 to look at, so start over. */
2055 do_cleanups (old_chain
);
2058 /* This is the normal print function for a bpstat. In the future,
2059 much of this logic could (should?) be moved to bpstat_stop_status,
2060 by having it set different print_it values.
2062 Current scheme: When we stop, bpstat_print() is called. It loops
2063 through the bpstat list of things causing this stop, calling the
2064 print_bp_stop_message function on each one. The behavior of the
2065 print_bp_stop_message function depends on the print_it field of
2066 bpstat. If such field so indicates, call this function here.
2068 Return values from this routine (ultimately used by bpstat_print()
2069 and normal_stop() to decide what to do):
2070 PRINT_NOTHING: Means we already printed all we needed to print,
2071 don't print anything else.
2072 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2073 that something to be followed by a location.
2074 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2075 that something to be followed by a location.
2076 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2079 static enum print_stop_action
2080 print_it_typical (bpstat bs
)
2082 struct cleanup
*old_chain
, *ui_out_chain
;
2083 struct breakpoint
*b
;
2084 const struct bp_location
*bl
;
2085 struct ui_stream
*stb
;
2086 stb
= ui_out_stream_new (uiout
);
2087 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2088 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2089 which has since been deleted. */
2090 if (bs
->breakpoint_at
== NULL
)
2091 return PRINT_UNKNOWN
;
2092 bl
= bs
->breakpoint_at
;
2098 case bp_hardware_breakpoint
:
2099 if (bl
->address
!= bl
->requested_address
)
2100 breakpoint_adjustment_warning (bl
->requested_address
,
2103 annotate_breakpoint (b
->number
);
2104 ui_out_text (uiout
, "\nBreakpoint ");
2105 if (ui_out_is_mi_like_p (uiout
))
2106 ui_out_field_string (uiout
, "reason",
2107 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2108 ui_out_field_int (uiout
, "bkptno", b
->number
);
2109 ui_out_text (uiout
, ", ");
2110 return PRINT_SRC_AND_LOC
;
2113 case bp_shlib_event
:
2114 /* Did we stop because the user set the stop_on_solib_events
2115 variable? (If so, we report this as a generic, "Stopped due
2116 to shlib event" message.) */
2117 printf_filtered (_("Stopped due to shared library event\n"));
2118 return PRINT_NOTHING
;
2121 case bp_thread_event
:
2122 /* Not sure how we will get here.
2123 GDB should not stop for these breakpoints. */
2124 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2125 return PRINT_NOTHING
;
2128 case bp_overlay_event
:
2129 /* By analogy with the thread event, GDB should not stop for these. */
2130 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2131 return PRINT_NOTHING
;
2135 annotate_catchpoint (b
->number
);
2136 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2138 b
->triggered_dll_pathname
);
2139 return PRINT_SRC_AND_LOC
;
2142 case bp_catch_unload
:
2143 annotate_catchpoint (b
->number
);
2144 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2146 b
->triggered_dll_pathname
);
2147 return PRINT_SRC_AND_LOC
;
2151 annotate_catchpoint (b
->number
);
2152 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2154 b
->forked_inferior_pid
);
2155 return PRINT_SRC_AND_LOC
;
2158 case bp_catch_vfork
:
2159 annotate_catchpoint (b
->number
);
2160 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2162 b
->forked_inferior_pid
);
2163 return PRINT_SRC_AND_LOC
;
2167 annotate_catchpoint (b
->number
);
2168 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2171 return PRINT_SRC_AND_LOC
;
2175 case bp_hardware_watchpoint
:
2176 if (bs
->old_val
!= NULL
)
2178 annotate_watchpoint (b
->number
);
2179 if (ui_out_is_mi_like_p (uiout
))
2182 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2184 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2185 ui_out_text (uiout
, "\nOld value = ");
2186 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2187 ui_out_field_stream (uiout
, "old", stb
);
2188 ui_out_text (uiout
, "\nNew value = ");
2189 value_print (b
->val
, stb
->stream
, 0, Val_pretty_default
);
2190 ui_out_field_stream (uiout
, "new", stb
);
2191 do_cleanups (ui_out_chain
);
2192 ui_out_text (uiout
, "\n");
2193 value_free (bs
->old_val
);
2196 /* More than one watchpoint may have been triggered. */
2197 return PRINT_UNKNOWN
;
2200 case bp_read_watchpoint
:
2201 if (ui_out_is_mi_like_p (uiout
))
2204 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2206 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2207 ui_out_text (uiout
, "\nValue = ");
2208 value_print (b
->val
, stb
->stream
, 0, Val_pretty_default
);
2209 ui_out_field_stream (uiout
, "value", stb
);
2210 do_cleanups (ui_out_chain
);
2211 ui_out_text (uiout
, "\n");
2212 return PRINT_UNKNOWN
;
2215 case bp_access_watchpoint
:
2216 if (bs
->old_val
!= NULL
)
2218 annotate_watchpoint (b
->number
);
2219 if (ui_out_is_mi_like_p (uiout
))
2222 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2224 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2225 ui_out_text (uiout
, "\nOld value = ");
2226 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2227 ui_out_field_stream (uiout
, "old", stb
);
2228 value_free (bs
->old_val
);
2230 ui_out_text (uiout
, "\nNew value = ");
2235 if (ui_out_is_mi_like_p (uiout
))
2238 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2239 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2240 ui_out_text (uiout
, "\nValue = ");
2242 value_print (b
->val
, stb
->stream
, 0,Val_pretty_default
);
2243 ui_out_field_stream (uiout
, "new", stb
);
2244 do_cleanups (ui_out_chain
);
2245 ui_out_text (uiout
, "\n");
2246 return PRINT_UNKNOWN
;
2249 /* Fall through, we don't deal with these types of breakpoints
2253 if (ui_out_is_mi_like_p (uiout
))
2256 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2257 return PRINT_UNKNOWN
;
2261 if (ui_out_is_mi_like_p (uiout
))
2264 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2265 return PRINT_UNKNOWN
;
2270 case bp_longjmp_resume
:
2271 case bp_step_resume
:
2272 case bp_watchpoint_scope
:
2275 return PRINT_UNKNOWN
;
2279 /* Generic routine for printing messages indicating why we
2280 stopped. The behavior of this function depends on the value
2281 'print_it' in the bpstat structure. Under some circumstances we
2282 may decide not to print anything here and delegate the task to
2285 static enum print_stop_action
2286 print_bp_stop_message (bpstat bs
)
2288 switch (bs
->print_it
)
2291 /* Nothing should be printed for this bpstat entry. */
2292 return PRINT_UNKNOWN
;
2296 /* We still want to print the frame, but we already printed the
2297 relevant messages. */
2298 return PRINT_SRC_AND_LOC
;
2301 case print_it_normal
:
2303 const struct bp_location
*bl
= bs
->breakpoint_at
;
2304 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2306 /* Normal case. Call the breakpoint's print_it method, or
2307 print_it_typical. */
2308 /* FIXME: how breakpoint can ever be NULL here? */
2309 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2310 return b
->ops
->print_it (b
);
2312 return print_it_typical (bs
);
2317 internal_error (__FILE__
, __LINE__
,
2318 _("print_bp_stop_message: unrecognized enum value"));
2323 /* Print a message indicating what happened. This is called from
2324 normal_stop(). The input to this routine is the head of the bpstat
2325 list - a list of the eventpoints that caused this stop. This
2326 routine calls the generic print routine for printing a message
2327 about reasons for stopping. This will print (for example) the
2328 "Breakpoint n," part of the output. The return value of this
2331 PRINT_UNKNOWN: Means we printed nothing
2332 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2333 code to print the location. An example is
2334 "Breakpoint 1, " which should be followed by
2336 PRINT_SRC_ONLY: Means we printed something, but there is no need
2337 to also print the location part of the message.
2338 An example is the catch/throw messages, which
2339 don't require a location appended to the end.
2340 PRINT_NOTHING: We have done some printing and we don't need any
2341 further info to be printed.*/
2343 enum print_stop_action
2344 bpstat_print (bpstat bs
)
2348 /* Maybe another breakpoint in the chain caused us to stop.
2349 (Currently all watchpoints go on the bpstat whether hit or not.
2350 That probably could (should) be changed, provided care is taken
2351 with respect to bpstat_explains_signal). */
2352 for (; bs
; bs
= bs
->next
)
2354 val
= print_bp_stop_message (bs
);
2355 if (val
== PRINT_SRC_ONLY
2356 || val
== PRINT_SRC_AND_LOC
2357 || val
== PRINT_NOTHING
)
2361 /* We reached the end of the chain, or we got a null BS to start
2362 with and nothing was printed. */
2363 return PRINT_UNKNOWN
;
2366 /* Evaluate the expression EXP and return 1 if value is zero.
2367 This is used inside a catch_errors to evaluate the breakpoint condition.
2368 The argument is a "struct expression *" that has been cast to char * to
2369 make it pass through catch_errors. */
2372 breakpoint_cond_eval (void *exp
)
2374 struct value
*mark
= value_mark ();
2375 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2376 value_free_to_mark (mark
);
2380 /* Allocate a new bpstat and chain it to the current one. */
2383 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2387 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2389 bs
->breakpoint_at
= bl
;
2390 /* If the condition is false, etc., don't do the commands. */
2391 bs
->commands
= NULL
;
2393 bs
->print_it
= print_it_normal
;
2397 /* The target has stopped with waitstatus WS. Check if any hardware
2398 watchpoints have triggered, according to the target. */
2401 watchpoints_triggered (struct target_waitstatus
*ws
)
2403 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2405 struct breakpoint
*b
;
2407 if (!stopped_by_watchpoint
)
2409 /* We were not stopped by a watchpoint. Mark all watchpoints
2410 as not triggered. */
2412 if (b
->type
== bp_hardware_watchpoint
2413 || b
->type
== bp_read_watchpoint
2414 || b
->type
== bp_access_watchpoint
)
2415 b
->watchpoint_triggered
= watch_triggered_no
;
2420 if (!target_stopped_data_address (¤t_target
, &addr
))
2422 /* We were stopped by a watchpoint, but we don't know where.
2423 Mark all watchpoints as unknown. */
2425 if (b
->type
== bp_hardware_watchpoint
2426 || b
->type
== bp_read_watchpoint
2427 || b
->type
== bp_access_watchpoint
)
2428 b
->watchpoint_triggered
= watch_triggered_unknown
;
2430 return stopped_by_watchpoint
;
2433 /* The target could report the data address. Mark watchpoints
2434 affected by this data address as triggered, and all others as not
2438 if (b
->type
== bp_hardware_watchpoint
2439 || b
->type
== bp_read_watchpoint
2440 || b
->type
== bp_access_watchpoint
)
2444 b
->watchpoint_triggered
= watch_triggered_no
;
2445 for (v
= b
->val_chain
; v
; v
= value_next (v
))
2447 if (VALUE_LVAL (v
) == lval_memory
&& ! value_lazy (v
))
2449 struct type
*vtype
= check_typedef (value_type (v
));
2451 if (v
== b
->val_chain
2452 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2453 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2457 vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
2458 /* Exact match not required. Within range is
2461 && addr
< vaddr
+ TYPE_LENGTH (value_type (v
)))
2463 b
->watchpoint_triggered
= watch_triggered_yes
;
2474 /* Possible return values for watchpoint_check (this can't be an enum
2475 because of check_errors). */
2476 /* The watchpoint has been deleted. */
2477 #define WP_DELETED 1
2478 /* The value has changed. */
2479 #define WP_VALUE_CHANGED 2
2480 /* The value has not changed. */
2481 #define WP_VALUE_NOT_CHANGED 3
2483 #define BP_TEMPFLAG 1
2484 #define BP_HARDWAREFLAG 2
2486 /* Check watchpoint condition. */
2489 watchpoint_check (void *p
)
2491 bpstat bs
= (bpstat
) p
;
2492 struct breakpoint
*b
;
2493 struct frame_info
*fr
;
2494 int within_current_scope
;
2496 b
= bs
->breakpoint_at
->owner
;
2498 if (b
->exp_valid_block
== NULL
)
2499 within_current_scope
= 1;
2502 /* There is no current frame at this moment. If we're going to have
2503 any chance of handling watchpoints on local variables, we'll need
2504 the frame chain (so we can determine if we're in scope). */
2505 reinit_frame_cache ();
2506 fr
= frame_find_by_id (b
->watchpoint_frame
);
2507 within_current_scope
= (fr
!= NULL
);
2509 /* If we've gotten confused in the unwinder, we might have
2510 returned a frame that can't describe this variable. */
2511 if (within_current_scope
2512 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2513 within_current_scope
= 0;
2515 /* in_function_epilogue_p() returns a non-zero value if we're still
2516 in the function but the stack frame has already been invalidated.
2517 Since we can't rely on the values of local variables after the
2518 stack has been destroyed, we are treating the watchpoint in that
2519 state as `not changed' without further checking.
2521 vinschen/2003-09-04: The former implementation left out the case
2522 that the watchpoint frame couldn't be found by frame_find_by_id()
2523 because the current PC is currently in an epilogue. Calling
2524 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2525 if ((!within_current_scope
|| fr
== get_current_frame ())
2526 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2527 return WP_VALUE_NOT_CHANGED
;
2528 if (fr
&& within_current_scope
)
2529 /* If we end up stopping, the current frame will get selected
2530 in normal_stop. So this call to select_frame won't affect
2535 if (within_current_scope
)
2537 /* We use value_{,free_to_}mark because it could be a
2538 *long* time before we return to the command level and
2539 call free_all_values. We can't call free_all_values because
2540 we might be in the middle of evaluating a function call. */
2542 struct value
*mark
= value_mark ();
2543 struct value
*new_val
= evaluate_expression (b
->exp
);
2544 if (!value_equal (b
->val
, new_val
))
2546 release_value (new_val
);
2547 value_free_to_mark (mark
);
2548 bs
->old_val
= b
->val
;
2550 /* We will stop here */
2551 return WP_VALUE_CHANGED
;
2555 /* Nothing changed, don't do anything. */
2556 value_free_to_mark (mark
);
2557 /* We won't stop here */
2558 return WP_VALUE_NOT_CHANGED
;
2563 /* This seems like the only logical thing to do because
2564 if we temporarily ignored the watchpoint, then when
2565 we reenter the block in which it is valid it contains
2566 garbage (in the case of a function, it may have two
2567 garbage values, one before and one after the prologue).
2568 So we can't even detect the first assignment to it and
2569 watch after that (since the garbage may or may not equal
2570 the first value assigned). */
2571 /* We print all the stop information in print_it_typical(), but
2572 in this case, by the time we call print_it_typical() this bp
2573 will be deleted already. So we have no choice but print the
2574 information here. */
2575 if (ui_out_is_mi_like_p (uiout
))
2577 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2578 ui_out_text (uiout
, "\nWatchpoint ");
2579 ui_out_field_int (uiout
, "wpnum", b
->number
);
2580 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2581 which its expression is valid.\n");
2583 if (b
->related_breakpoint
)
2584 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2585 b
->disposition
= disp_del_at_next_stop
;
2591 /* Get a bpstat associated with having just stopped at address
2592 BP_ADDR in thread PTID.
2594 Determine whether we stopped at a breakpoint, etc, or whether we
2595 don't understand this stop. Result is a chain of bpstat's such that:
2597 if we don't understand the stop, the result is a null pointer.
2599 if we understand why we stopped, the result is not null.
2601 Each element of the chain refers to a particular breakpoint or
2602 watchpoint at which we have stopped. (We may have stopped for
2603 several reasons concurrently.)
2605 Each element of the chain has valid next, breakpoint_at,
2606 commands, FIXME??? fields. */
2609 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2611 struct breakpoint
*b
= NULL
;
2612 const struct bp_location
*bl
;
2613 /* Root of the chain of bpstat's */
2614 struct bpstats root_bs
[1];
2615 /* Pointer to the last thing in the chain currently. */
2616 bpstat bs
= root_bs
;
2617 int thread_id
= pid_to_thread_id (ptid
);
2619 ALL_BP_LOCATIONS (bl
)
2623 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2626 if (b
->type
!= bp_watchpoint
2627 && b
->type
!= bp_hardware_watchpoint
2628 && b
->type
!= bp_read_watchpoint
2629 && b
->type
!= bp_access_watchpoint
2630 && b
->type
!= bp_hardware_breakpoint
2631 && b
->type
!= bp_catch_fork
2632 && b
->type
!= bp_catch_vfork
2633 && b
->type
!= bp_catch_exec
) /* a non-watchpoint bp */
2635 if (bl
->address
!= bp_addr
) /* address doesn't match */
2637 if (overlay_debugging
/* unmapped overlay section */
2638 && section_is_overlay (bl
->section
)
2639 && !section_is_mapped (bl
->section
))
2643 /* Continuable hardware watchpoints are treated as non-existent if the
2644 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2645 some data address). Otherwise gdb won't stop on a break instruction
2646 in the code (not from a breakpoint) when a hardware watchpoint has
2647 been defined. Also skip watchpoints which we know did not trigger
2648 (did not match the data address). */
2650 if ((b
->type
== bp_hardware_watchpoint
2651 || b
->type
== bp_read_watchpoint
2652 || b
->type
== bp_access_watchpoint
)
2653 && b
->watchpoint_triggered
== watch_triggered_no
)
2656 if (b
->type
== bp_hardware_breakpoint
)
2658 if (bl
->address
!= bp_addr
)
2660 if (overlay_debugging
/* unmapped overlay section */
2661 && section_is_overlay (bl
->section
)
2662 && !section_is_mapped (bl
->section
))
2666 /* Is this a catchpoint of a load or unload? If so, did we
2667 get a load or unload of the specified library? If not,
2669 if ((b
->type
== bp_catch_load
)
2670 #if defined(SOLIB_HAVE_LOAD_EVENT)
2671 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2672 || ((b
->dll_pathname
!= NULL
)
2673 && (strcmp (b
->dll_pathname
,
2674 SOLIB_LOADED_LIBRARY_PATHNAME (
2675 PIDGET (inferior_ptid
)))
2681 if ((b
->type
== bp_catch_unload
)
2682 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2683 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2684 || ((b
->dll_pathname
!= NULL
)
2685 && (strcmp (b
->dll_pathname
,
2686 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2687 PIDGET (inferior_ptid
)))
2693 if ((b
->type
== bp_catch_fork
)
2694 && !inferior_has_forked (PIDGET (inferior_ptid
),
2695 &b
->forked_inferior_pid
))
2698 if ((b
->type
== bp_catch_vfork
)
2699 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2700 &b
->forked_inferior_pid
))
2703 if ((b
->type
== bp_catch_exec
)
2704 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2707 /* Come here if it's a watchpoint, or if the break address matches */
2709 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
2711 /* Watchpoints may change this, if not found to have triggered. */
2715 if (b
->type
== bp_watchpoint
2716 || b
->type
== bp_read_watchpoint
2717 || b
->type
== bp_access_watchpoint
2718 || b
->type
== bp_hardware_watchpoint
)
2722 int must_check_value
= 0;
2724 if (b
->type
== bp_watchpoint
)
2725 /* For a software watchpoint, we must always check the
2727 must_check_value
= 1;
2728 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2729 /* We have a hardware watchpoint (read, write, or access)
2730 and the target earlier reported an address watched by
2732 must_check_value
= 1;
2733 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2734 && b
->type
== bp_hardware_watchpoint
)
2735 /* We were stopped by a hardware watchpoint, but the target could
2736 not report the data address. We must check the watchpoint's
2737 value. Access and read watchpoints are out of luck; without
2738 a data address, we can't figure it out. */
2739 must_check_value
= 1;
2741 if (must_check_value
)
2743 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2745 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2746 int e
= catch_errors (watchpoint_check
, bs
, message
,
2748 do_cleanups (cleanups
);
2752 /* We've already printed what needs to be printed. */
2753 bs
->print_it
= print_it_done
;
2756 case WP_VALUE_CHANGED
:
2757 if (b
->type
== bp_read_watchpoint
)
2759 /* Don't stop: read watchpoints shouldn't fire if
2760 the value has changed. This is for targets
2761 which cannot set read-only watchpoints. */
2762 bs
->print_it
= print_it_noop
;
2768 case WP_VALUE_NOT_CHANGED
:
2769 if (b
->type
== bp_hardware_watchpoint
2770 || b
->type
== bp_watchpoint
)
2772 /* Don't stop: write watchpoints shouldn't fire if
2773 the value hasn't changed. */
2774 bs
->print_it
= print_it_noop
;
2784 /* Error from catch_errors. */
2785 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2786 if (b
->related_breakpoint
)
2787 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2788 b
->disposition
= disp_del_at_next_stop
;
2789 /* We've already printed what needs to be printed. */
2790 bs
->print_it
= print_it_done
;
2794 else /* must_check_value == 0 */
2796 /* This is a case where some watchpoint(s) triggered, but
2797 not at the address of this watchpoint, or else no
2798 watchpoint triggered after all. So don't print
2799 anything for this watchpoint. */
2800 bs
->print_it
= print_it_noop
;
2807 /* By definition, an encountered breakpoint is a triggered
2812 if (frame_id_p (b
->frame_id
)
2813 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2817 int value_is_zero
= 0;
2819 /* If this is a scope breakpoint, mark the associated
2820 watchpoint as triggered so that we will handle the
2821 out-of-scope event. We'll get to the watchpoint next
2823 if (b
->type
== bp_watchpoint_scope
)
2824 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2826 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2828 /* Need to select the frame, with all that implies
2829 so that the conditions will have the right context. */
2830 select_frame (get_current_frame ());
2832 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2833 "Error in testing breakpoint condition:\n",
2835 /* FIXME-someday, should give breakpoint # */
2838 if (bl
->cond
&& value_is_zero
)
2841 /* Don't consider this a hit. */
2844 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2847 /* Don't consider this a hit. */
2850 else if (b
->ignore_count
> 0)
2853 annotate_ignore_count_change ();
2856 else if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
2857 /* We do not stop for these. */
2861 /* We will stop here */
2862 if (b
->disposition
== disp_disable
)
2863 b
->enable_state
= bp_disabled
;
2866 bs
->commands
= b
->commands
;
2868 (strcmp ("silent", bs
->commands
->line
) == 0
2869 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
2871 bs
->commands
= bs
->commands
->next
;
2874 bs
->commands
= copy_command_lines (bs
->commands
);
2877 /* Print nothing for this entry if we dont stop or if we dont print. */
2878 if (bs
->stop
== 0 || bs
->print
== 0)
2879 bs
->print_it
= print_it_noop
;
2882 bs
->next
= NULL
; /* Terminate the chain */
2883 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2885 /* If we aren't stopping, the value of some hardware watchpoint may
2886 not have changed, but the intermediate memory locations we are
2887 watching may have. Don't bother if we're stopping; this will get
2889 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
2894 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
2896 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
2897 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
2898 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
2900 remove_breakpoints ();
2901 insert_breakpoints ();
2905 return root_bs
->next
;
2908 /* Tell what to do about this bpstat. */
2910 bpstat_what (bpstat bs
)
2912 /* Classify each bpstat as one of the following. */
2915 /* This bpstat element has no effect on the main_action. */
2918 /* There was a watchpoint, stop but don't print. */
2921 /* There was a watchpoint, stop and print. */
2924 /* There was a breakpoint but we're not stopping. */
2927 /* There was a breakpoint, stop but don't print. */
2930 /* There was a breakpoint, stop and print. */
2933 /* We hit the longjmp breakpoint. */
2936 /* We hit the longjmp_resume breakpoint. */
2939 /* We hit the step_resume breakpoint. */
2942 /* We hit the shared library event breakpoint. */
2945 /* We caught a shared library event. */
2948 /* This is just used to count how many enums there are. */
2952 /* Here is the table which drives this routine. So that we can
2953 format it pretty, we define some abbreviations for the
2954 enum bpstat_what codes. */
2955 #define kc BPSTAT_WHAT_KEEP_CHECKING
2956 #define ss BPSTAT_WHAT_STOP_SILENT
2957 #define sn BPSTAT_WHAT_STOP_NOISY
2958 #define sgl BPSTAT_WHAT_SINGLE
2959 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2960 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2961 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2962 #define sr BPSTAT_WHAT_STEP_RESUME
2963 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2964 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2966 /* "Can't happen." Might want to print an error message.
2967 abort() is not out of the question, but chances are GDB is just
2968 a bit confused, not unusable. */
2969 #define err BPSTAT_WHAT_STOP_NOISY
2971 /* Given an old action and a class, come up with a new action. */
2972 /* One interesting property of this table is that wp_silent is the same
2973 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2974 after stopping, the check for whether to step over a breakpoint
2975 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2976 reference to how we stopped. We retain separate wp_silent and
2977 bp_silent codes in case we want to change that someday.
2979 Another possibly interesting property of this table is that
2980 there's a partial ordering, priority-like, of the actions. Once
2981 you've decided that some action is appropriate, you'll never go
2982 back and decide something of a lower priority is better. The
2985 kc < clr sgl shl shlr slr sn sr ss
2986 sgl < clrs shl shlr slr sn sr ss
2987 slr < err shl shlr sn sr ss
2988 clr < clrs err shl shlr sn sr ss
2989 clrs < err shl shlr sn sr ss
2996 What I think this means is that we don't need a damned table
2997 here. If you just put the rows and columns in the right order,
2998 it'd look awfully regular. We could simply walk the bpstat list
2999 and choose the highest priority action we find, with a little
3000 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3001 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3002 is messy anyway). */
3004 /* step_resume entries: a step resume breakpoint overrides another
3005 breakpoint of signal handling (see comment in wait_for_inferior
3006 at where we set the step_resume breakpoint). */
3008 static const enum bpstat_what_main_action
3009 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3012 /* kc ss sn sgl slr clr clrs sr shl shlr
3015 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, shl
, shlr
},
3017 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3019 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3021 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, shl
, shlr
},
3023 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3025 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3027 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, shl
, shlr
},
3029 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, shl
, shlr
},
3031 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3033 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3035 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3050 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3051 struct bpstat_what retval
;
3053 retval
.call_dummy
= 0;
3054 for (; bs
!= NULL
; bs
= bs
->next
)
3056 enum class bs_class
= no_effect
;
3057 if (bs
->breakpoint_at
== NULL
)
3058 /* I suspect this can happen if it was a momentary breakpoint
3059 which has since been deleted. */
3061 switch (bs
->breakpoint_at
->owner
->type
)
3067 case bp_hardware_breakpoint
:
3073 bs_class
= bp_noisy
;
3075 bs_class
= bp_silent
;
3078 bs_class
= bp_nostop
;
3081 case bp_hardware_watchpoint
:
3082 case bp_read_watchpoint
:
3083 case bp_access_watchpoint
:
3087 bs_class
= wp_noisy
;
3089 bs_class
= wp_silent
;
3092 /* There was a watchpoint, but we're not stopping.
3093 This requires no further action. */
3094 bs_class
= no_effect
;
3097 bs_class
= long_jump
;
3099 case bp_longjmp_resume
:
3100 bs_class
= long_resume
;
3102 case bp_step_resume
:
3105 bs_class
= step_resume
;
3108 /* It is for the wrong frame. */
3109 bs_class
= bp_nostop
;
3111 case bp_watchpoint_scope
:
3112 bs_class
= bp_nostop
;
3114 case bp_shlib_event
:
3115 bs_class
= shlib_event
;
3117 case bp_thread_event
:
3118 case bp_overlay_event
:
3119 bs_class
= bp_nostop
;
3122 case bp_catch_unload
:
3123 /* Only if this catchpoint triggered should we cause the
3124 step-out-of-dld behaviour. Otherwise, we ignore this
3127 bs_class
= catch_shlib_event
;
3129 bs_class
= no_effect
;
3132 case bp_catch_vfork
:
3137 bs_class
= bp_noisy
;
3139 bs_class
= bp_silent
;
3142 /* There was a catchpoint, but we're not stopping.
3143 This requires no further action. */
3144 bs_class
= no_effect
;
3147 /* Make sure the action is stop (silent or noisy),
3148 so infrun.c pops the dummy frame. */
3149 bs_class
= bp_silent
;
3150 retval
.call_dummy
= 1;
3153 current_action
= table
[(int) bs_class
][(int) current_action
];
3155 retval
.main_action
= current_action
;
3159 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3160 without hardware support). This isn't related to a specific bpstat,
3161 just to things like whether watchpoints are set. */
3164 bpstat_should_step (void)
3166 struct breakpoint
*b
;
3168 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3175 /* Given a bpstat that records zero or more triggered eventpoints, this
3176 function returns another bpstat which contains only the catchpoints
3177 on that first list, if any. */
3179 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3181 struct bpstats root_bs
[1];
3182 bpstat bs
= root_bs
;
3183 struct breakpoint
*ep
;
3186 bpstat_clear (cp_list
);
3187 root_bs
->next
= NULL
;
3189 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3191 /* Is this eventpoint a catchpoint? If not, ignore it. */
3192 ep
= ep_list
->breakpoint_at
->owner
;
3195 if ((ep
->type
!= bp_catch_load
) &&
3196 (ep
->type
!= bp_catch_unload
))
3197 /* pai: (temp) ADD fork/vfork here!! */
3200 /* Yes; add it to the list. */
3201 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3206 #if defined(SOLIB_ADD)
3207 /* Also, for each triggered catchpoint, tag it with the name of
3208 the library that caused this trigger. (We copy the name now,
3209 because it's only guaranteed to be available NOW, when the
3210 catchpoint triggers. Clients who may wish to know the name
3211 later must get it from the catchpoint itself.) */
3212 if (ep
->triggered_dll_pathname
!= NULL
)
3213 xfree (ep
->triggered_dll_pathname
);
3214 if (ep
->type
== bp_catch_load
)
3215 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3216 PIDGET (inferior_ptid
));
3218 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3219 PIDGET (inferior_ptid
));
3221 dll_pathname
= NULL
;
3225 ep
->triggered_dll_pathname
= (char *)
3226 xmalloc (strlen (dll_pathname
) + 1);
3227 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3230 ep
->triggered_dll_pathname
= NULL
;
3236 static void print_breakpoint_location (struct breakpoint
*b
,
3237 struct bp_location
*loc
,
3239 struct ui_stream
*stb
)
3244 = find_pc_sect_function (loc
->address
, loc
->section
);
3247 ui_out_text (uiout
, "in ");
3248 ui_out_field_string (uiout
, "func",
3249 SYMBOL_PRINT_NAME (sym
));
3250 ui_out_wrap_hint (uiout
, wrap_indent
);
3251 ui_out_text (uiout
, " at ");
3253 ui_out_field_string (uiout
, "file", b
->source_file
);
3254 ui_out_text (uiout
, ":");
3256 if (ui_out_is_mi_like_p (uiout
))
3258 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3259 char *fullname
= symtab_to_fullname (sal
.symtab
);
3262 ui_out_field_string (uiout
, "fullname", fullname
);
3265 ui_out_field_int (uiout
, "line", b
->line_number
);
3269 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3273 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3274 ui_out_field_stream (uiout
, "at", stb
);
3278 /* Print B to gdb_stdout. */
3280 print_one_breakpoint_location (struct breakpoint
*b
,
3281 struct bp_location
*loc
,
3283 CORE_ADDR
*last_addr
)
3285 struct command_line
*l
;
3287 struct ep_type_description
3292 static struct ep_type_description bptypes
[] =
3294 {bp_none
, "?deleted?"},
3295 {bp_breakpoint
, "breakpoint"},
3296 {bp_hardware_breakpoint
, "hw breakpoint"},
3297 {bp_until
, "until"},
3298 {bp_finish
, "finish"},
3299 {bp_watchpoint
, "watchpoint"},
3300 {bp_hardware_watchpoint
, "hw watchpoint"},
3301 {bp_read_watchpoint
, "read watchpoint"},
3302 {bp_access_watchpoint
, "acc watchpoint"},
3303 {bp_longjmp
, "longjmp"},
3304 {bp_longjmp_resume
, "longjmp resume"},
3305 {bp_step_resume
, "step resume"},
3306 {bp_watchpoint_scope
, "watchpoint scope"},
3307 {bp_call_dummy
, "call dummy"},
3308 {bp_shlib_event
, "shlib events"},
3309 {bp_thread_event
, "thread events"},
3310 {bp_overlay_event
, "overlay events"},
3311 {bp_catch_load
, "catch load"},
3312 {bp_catch_unload
, "catch unload"},
3313 {bp_catch_fork
, "catch fork"},
3314 {bp_catch_vfork
, "catch vfork"},
3315 {bp_catch_exec
, "catch exec"}
3318 static char *bpdisps
[] =
3319 {"del", "dstp", "dis", "keep"};
3320 static char bpenables
[] = "nynny";
3321 char wrap_indent
[80];
3322 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3323 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3324 struct cleanup
*bkpt_chain
;
3326 int header_of_multiple
= 0;
3327 int part_of_multiple
= (loc
!= NULL
);
3329 gdb_assert (!loc
|| loc_number
!= 0);
3330 /* See comment in print_one_breakpoint concerning
3331 treatment of breakpoints with single disabled
3335 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3336 header_of_multiple
= 1;
3341 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3345 if (part_of_multiple
)
3348 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3349 ui_out_field_string (uiout
, "number", formatted
);
3354 ui_out_field_int (uiout
, "number", b
->number
);
3359 if (part_of_multiple
)
3360 ui_out_field_skip (uiout
, "type");
3363 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3364 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3365 internal_error (__FILE__
, __LINE__
,
3366 _("bptypes table does not describe type #%d."),
3368 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3373 if (part_of_multiple
)
3374 ui_out_field_skip (uiout
, "disp");
3376 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3381 if (part_of_multiple
)
3382 ui_out_field_string (uiout
, "enabled",
3384 ? (loc
->enabled
? "y(p)" : "n(p)")
3385 : (loc
->enabled
? "y" : "n"));
3388 int pending
= (b
->loc
== NULL
|| b
->loc
->shlib_disabled
);
3389 /* For header of multiple, there's no point showing pending
3390 state -- it will be apparent from the locations. */
3391 if (header_of_multiple
)
3393 ui_out_field_fmt (uiout
, "enabled", "%c%s",
3394 bpenables
[(int) b
->enable_state
],
3395 pending
? "(p)" : "");
3397 ui_out_spaces (uiout
, 3);
3402 strcpy (wrap_indent
, " ");
3405 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3406 strcat (wrap_indent
, " ");
3408 strcat (wrap_indent
, " ");
3411 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3413 /* Although the print_one can possibly print
3414 all locations, calling it here is not likely
3415 to get any nice result. So, make sure there's
3416 just one location. */
3417 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3418 b
->ops
->print_one (b
, last_addr
);
3424 internal_error (__FILE__
, __LINE__
,
3425 _("print_one_breakpoint: bp_none encountered\n"));
3429 case bp_hardware_watchpoint
:
3430 case bp_read_watchpoint
:
3431 case bp_access_watchpoint
:
3432 /* Field 4, the address, is omitted (which makes the columns
3433 not line up too nicely with the headers, but the effect
3434 is relatively readable). */
3436 ui_out_field_skip (uiout
, "addr");
3438 print_expression (b
->exp
, stb
->stream
);
3439 ui_out_field_stream (uiout
, "what", stb
);
3443 case bp_catch_unload
:
3444 /* Field 4, the address, is omitted (which makes the columns
3445 not line up too nicely with the headers, but the effect
3446 is relatively readable). */
3448 ui_out_field_skip (uiout
, "addr");
3450 if (b
->dll_pathname
== NULL
)
3452 ui_out_field_string (uiout
, "what", "<any library>");
3453 ui_out_spaces (uiout
, 1);
3457 ui_out_text (uiout
, "library \"");
3458 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3459 ui_out_text (uiout
, "\" ");
3464 case bp_catch_vfork
:
3465 /* Field 4, the address, is omitted (which makes the columns
3466 not line up too nicely with the headers, but the effect
3467 is relatively readable). */
3469 ui_out_field_skip (uiout
, "addr");
3471 if (b
->forked_inferior_pid
!= 0)
3473 ui_out_text (uiout
, "process ");
3474 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3475 ui_out_spaces (uiout
, 1);
3480 /* Field 4, the address, is omitted (which makes the columns
3481 not line up too nicely with the headers, but the effect
3482 is relatively readable). */
3484 ui_out_field_skip (uiout
, "addr");
3486 if (b
->exec_pathname
!= NULL
)
3488 ui_out_text (uiout
, "program \"");
3489 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3490 ui_out_text (uiout
, "\" ");
3495 case bp_hardware_breakpoint
:
3499 case bp_longjmp_resume
:
3500 case bp_step_resume
:
3501 case bp_watchpoint_scope
:
3503 case bp_shlib_event
:
3504 case bp_thread_event
:
3505 case bp_overlay_event
:
3510 ui_out_field_string (uiout
, "addr", "<PENDING>");
3511 else if (header_of_multiple
)
3512 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3514 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3517 if (!header_of_multiple
)
3518 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3520 *last_addr
= b
->loc
->address
;
3524 if (!part_of_multiple
&& b
->thread
!= -1)
3526 /* FIXME: This seems to be redundant and lost here; see the
3527 "stop only in" line a little further down. */
3528 ui_out_text (uiout
, " thread ");
3529 ui_out_field_int (uiout
, "thread", b
->thread
);
3532 ui_out_text (uiout
, "\n");
3534 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3537 ui_out_text (uiout
, "\tstop only in stack frame at ");
3538 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3540 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3541 ui_out_text (uiout
, "\n");
3544 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3546 /* We do not print the condition for Ada exception catchpoints
3547 because the condition is an internal implementation detail
3548 that we do not want to expose to the user. */
3550 ui_out_text (uiout
, "\tstop only if ");
3551 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3552 ui_out_text (uiout
, "\n");
3555 if (!part_of_multiple
&& b
->thread
!= -1)
3557 /* FIXME should make an annotation for this */
3558 ui_out_text (uiout
, "\tstop only in thread ");
3559 ui_out_field_int (uiout
, "thread", b
->thread
);
3560 ui_out_text (uiout
, "\n");
3563 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3565 /* FIXME should make an annotation for this */
3566 if (ep_is_catchpoint (b
))
3567 ui_out_text (uiout
, "\tcatchpoint");
3569 ui_out_text (uiout
, "\tbreakpoint");
3570 ui_out_text (uiout
, " already hit ");
3571 ui_out_field_int (uiout
, "times", b
->hit_count
);
3572 if (b
->hit_count
== 1)
3573 ui_out_text (uiout
, " time\n");
3575 ui_out_text (uiout
, " times\n");
3578 /* Output the count also if it is zero, but only if this is
3579 mi. FIXME: Should have a better test for this. */
3580 if (ui_out_is_mi_like_p (uiout
))
3581 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3582 ui_out_field_int (uiout
, "times", b
->hit_count
);
3584 if (!part_of_multiple
&& b
->ignore_count
)
3587 ui_out_text (uiout
, "\tignore next ");
3588 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3589 ui_out_text (uiout
, " hits\n");
3592 if (!part_of_multiple
&& (l
= b
->commands
))
3594 struct cleanup
*script_chain
;
3597 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3598 print_command_lines (uiout
, l
, 4);
3599 do_cleanups (script_chain
);
3601 do_cleanups (bkpt_chain
);
3602 do_cleanups (old_chain
);
3606 print_one_breakpoint (struct breakpoint
*b
,
3607 CORE_ADDR
*last_addr
)
3609 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3611 /* If this breakpoint has custom print function,
3612 it's already printed. Otherwise, print individual
3613 locations, if any. */
3614 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3616 /* If breakpoint has a single location that is
3617 disabled, we print it as if it had
3618 several locations, since otherwise it's hard to
3619 represent "breakpoint enabled, location disabled"
3622 && (b
->loc
->next
|| !b
->loc
->enabled
)
3623 && !ui_out_is_mi_like_p (uiout
))
3625 struct bp_location
*loc
;
3627 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3628 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3634 struct captured_breakpoint_query_args
3640 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3642 struct captured_breakpoint_query_args
*args
= data
;
3643 struct breakpoint
*b
;
3644 CORE_ADDR dummy_addr
= 0;
3647 if (args
->bnum
== b
->number
)
3649 print_one_breakpoint (b
, &dummy_addr
);
3657 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3659 struct captured_breakpoint_query_args args
;
3661 /* For the moment we don't trust print_one_breakpoint() to not throw
3663 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3664 error_message
, RETURN_MASK_ALL
) < 0)
3670 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3671 catchpoints, et.al.). */
3674 user_settable_breakpoint (const struct breakpoint
*b
)
3676 return (b
->type
== bp_breakpoint
3677 || b
->type
== bp_catch_load
3678 || b
->type
== bp_catch_unload
3679 || b
->type
== bp_catch_fork
3680 || b
->type
== bp_catch_vfork
3681 || b
->type
== bp_catch_exec
3682 || b
->type
== bp_hardware_breakpoint
3683 || b
->type
== bp_watchpoint
3684 || b
->type
== bp_read_watchpoint
3685 || b
->type
== bp_access_watchpoint
3686 || b
->type
== bp_hardware_watchpoint
);
3689 /* Print information on user settable breakpoint (watchpoint, etc)
3690 number BNUM. If BNUM is -1 print all user settable breakpoints.
3691 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3694 breakpoint_1 (int bnum
, int allflag
)
3696 struct breakpoint
*b
;
3697 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3698 int nr_printable_breakpoints
;
3699 struct cleanup
*bkpttbl_chain
;
3701 /* Compute the number of rows in the table. */
3702 nr_printable_breakpoints
= 0;
3705 || bnum
== b
->number
)
3707 if (allflag
|| user_settable_breakpoint (b
))
3708 nr_printable_breakpoints
++;
3713 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3717 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3720 if (nr_printable_breakpoints
> 0)
3721 annotate_breakpoints_headers ();
3722 if (nr_printable_breakpoints
> 0)
3724 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3725 if (nr_printable_breakpoints
> 0)
3727 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3728 if (nr_printable_breakpoints
> 0)
3730 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3731 if (nr_printable_breakpoints
> 0)
3733 ui_out_table_header (uiout
, 4, ui_left
, "enabled", "Enb"); /* 4 */
3736 if (nr_printable_breakpoints
> 0)
3738 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3739 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3741 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3743 if (nr_printable_breakpoints
> 0)
3745 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3746 ui_out_table_body (uiout
);
3747 if (nr_printable_breakpoints
> 0)
3748 annotate_breakpoints_table ();
3752 || bnum
== b
->number
)
3754 /* We only print out user settable breakpoints unless the
3756 if (allflag
|| user_settable_breakpoint (b
))
3757 print_one_breakpoint (b
, &last_addr
);
3760 do_cleanups (bkpttbl_chain
);
3762 if (nr_printable_breakpoints
== 0)
3765 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3767 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3772 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3773 that a comparison of an unsigned with -1 is always false. */
3774 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3775 set_next_address (last_addr
);
3778 /* FIXME? Should this be moved up so that it is only called when
3779 there have been breakpoints? */
3780 annotate_breakpoints_table_end ();
3784 breakpoints_info (char *bnum_exp
, int from_tty
)
3789 bnum
= parse_and_eval_long (bnum_exp
);
3791 breakpoint_1 (bnum
, 0);
3795 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3800 bnum
= parse_and_eval_long (bnum_exp
);
3802 breakpoint_1 (bnum
, 1);
3806 breakpoint_has_pc (struct breakpoint
*b
, CORE_ADDR pc
, asection
*section
)
3808 struct bp_location
*bl
= b
->loc
;
3809 for (; bl
; bl
= bl
->next
)
3811 if (bl
->address
== pc
3812 && (!overlay_debugging
|| bl
->section
== section
))
3818 /* Print a message describing any breakpoints set at PC. */
3821 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
3824 struct breakpoint
*b
;
3827 others
+= breakpoint_has_pc (b
, pc
, section
);
3831 printf_filtered (_("Note: breakpoint "));
3832 else /* if (others == ???) */
3833 printf_filtered (_("Note: breakpoints "));
3835 if (breakpoint_has_pc (b
, pc
, section
))
3838 printf_filtered ("%d", b
->number
);
3839 if (b
->thread
== -1 && thread
!= -1)
3840 printf_filtered (" (all threads)");
3841 else if (b
->thread
!= -1)
3842 printf_filtered (" (thread %d)", b
->thread
);
3843 printf_filtered ("%s%s ",
3844 ((b
->enable_state
== bp_disabled
||
3845 b
->enable_state
== bp_call_disabled
)
3847 : b
->enable_state
== bp_permanent
3851 : ((others
== 1) ? " and" : ""));
3853 printf_filtered (_("also set at pc "));
3854 fputs_filtered (paddress (pc
), gdb_stdout
);
3855 printf_filtered (".\n");
3859 /* Set the default place to put a breakpoint
3860 for the `break' command with no arguments. */
3863 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3866 default_breakpoint_valid
= valid
;
3867 default_breakpoint_address
= addr
;
3868 default_breakpoint_symtab
= symtab
;
3869 default_breakpoint_line
= line
;
3872 /* Return true iff it is meaningful to use the address member of
3873 BPT. For some breakpoint types, the address member is irrelevant
3874 and it makes no sense to attempt to compare it to other addresses
3875 (or use it for any other purpose either).
3877 More specifically, each of the following breakpoint types will always
3878 have a zero valued address and we don't want check_duplicates() to mark
3879 breakpoints of any of these types to be a duplicate of an actual
3880 breakpoint at address zero:
3883 bp_hardware_watchpoint
3885 bp_access_watchpoint
3892 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3894 enum bptype type
= bpt
->type
;
3896 return (type
!= bp_watchpoint
3897 && type
!= bp_hardware_watchpoint
3898 && type
!= bp_read_watchpoint
3899 && type
!= bp_access_watchpoint
3900 && type
!= bp_catch_exec
3901 && type
!= bp_longjmp_resume
3902 && type
!= bp_catch_fork
3903 && type
!= bp_catch_vfork
);
3906 /* Rescan breakpoints at the same address and section as BPT,
3907 marking the first one as "first" and any others as "duplicates".
3908 This is so that the bpt instruction is only inserted once.
3909 If we have a permanent breakpoint at the same place as BPT, make
3910 that one the official one, and the rest as duplicates. */
3913 check_duplicates_for (CORE_ADDR address
, asection
*section
)
3915 struct bp_location
*b
;
3917 struct bp_location
*perm_bp
= 0;
3919 ALL_BP_LOCATIONS (b
)
3920 if (b
->owner
->enable_state
!= bp_disabled
3921 && b
->owner
->enable_state
!= bp_call_disabled
3923 && !b
->shlib_disabled
3924 && b
->address
== address
/* address / overlay match */
3925 && (!overlay_debugging
|| b
->section
== section
)
3926 && breakpoint_address_is_meaningful (b
->owner
))
3928 /* Have we found a permanent breakpoint? */
3929 if (b
->owner
->enable_state
== bp_permanent
)
3936 b
->duplicate
= count
> 1;
3939 /* If we found a permanent breakpoint at this address, go over the
3940 list again and declare all the other breakpoints there to be the
3944 perm_bp
->duplicate
= 0;
3946 /* Permanent breakpoint should always be inserted. */
3947 if (! perm_bp
->inserted
)
3948 internal_error (__FILE__
, __LINE__
,
3949 _("allegedly permanent breakpoint is not "
3950 "actually inserted"));
3952 ALL_BP_LOCATIONS (b
)
3955 if (b
->owner
->enable_state
!= bp_disabled
3956 && b
->owner
->enable_state
!= bp_call_disabled
3957 && b
->enabled
&& !b
->shlib_disabled
3958 && b
->address
== address
/* address / overlay match */
3959 && (!overlay_debugging
|| b
->section
== section
)
3960 && breakpoint_address_is_meaningful (b
->owner
))
3963 internal_error (__FILE__
, __LINE__
,
3964 _("another breakpoint was inserted on top of "
3965 "a permanent breakpoint"));
3974 check_duplicates (struct breakpoint
*bpt
)
3976 struct bp_location
*bl
= bpt
->loc
;
3978 if (! breakpoint_address_is_meaningful (bpt
))
3981 for (; bl
; bl
= bl
->next
)
3982 check_duplicates_for (bl
->address
, bl
->section
);
3986 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
3987 int bnum
, int have_bnum
)
3992 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
3993 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
3995 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
3996 bnum
, astr1
, astr2
);
3998 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4001 /* Adjust a breakpoint's address to account for architectural constraints
4002 on breakpoint placement. Return the adjusted address. Note: Very
4003 few targets require this kind of adjustment. For most targets,
4004 this function is simply the identity function. */
4007 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4009 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4011 /* Very few targets need any kind of breakpoint adjustment. */
4014 else if (bptype
== bp_watchpoint
4015 || bptype
== bp_hardware_watchpoint
4016 || bptype
== bp_read_watchpoint
4017 || bptype
== bp_access_watchpoint
4018 || bptype
== bp_catch_fork
4019 || bptype
== bp_catch_vfork
4020 || bptype
== bp_catch_exec
)
4022 /* Watchpoints and the various bp_catch_* eventpoints should not
4023 have their addresses modified. */
4028 CORE_ADDR adjusted_bpaddr
;
4030 /* Some targets have architectural constraints on the placement
4031 of breakpoint instructions. Obtain the adjusted address. */
4032 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4035 /* An adjusted breakpoint address can significantly alter
4036 a user's expectations. Print a warning if an adjustment
4038 if (adjusted_bpaddr
!= bpaddr
)
4039 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4041 return adjusted_bpaddr
;
4045 /* Allocate a struct bp_location. */
4047 static struct bp_location
*
4048 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4050 struct bp_location
*loc
, *loc_p
;
4052 loc
= xmalloc (sizeof (struct bp_location
));
4053 memset (loc
, 0, sizeof (*loc
));
4057 loc
->shlib_disabled
= 0;
4066 case bp_longjmp_resume
:
4067 case bp_step_resume
:
4068 case bp_watchpoint_scope
:
4070 case bp_shlib_event
:
4071 case bp_thread_event
:
4072 case bp_overlay_event
:
4074 case bp_catch_unload
:
4075 loc
->loc_type
= bp_loc_software_breakpoint
;
4077 case bp_hardware_breakpoint
:
4078 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4080 case bp_hardware_watchpoint
:
4081 case bp_read_watchpoint
:
4082 case bp_access_watchpoint
:
4083 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4087 case bp_catch_vfork
:
4089 loc
->loc_type
= bp_loc_other
;
4092 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4095 /* Add this breakpoint to the end of the chain. */
4097 loc_p
= bp_location_chain
;
4099 bp_location_chain
= loc
;
4102 while (loc_p
->global_next
)
4103 loc_p
= loc_p
->global_next
;
4104 loc_p
->global_next
= loc
;
4110 static void free_bp_location (struct bp_location
*loc
)
4117 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4118 that has type BPTYPE and has no locations as yet. */
4120 static struct breakpoint
*
4121 set_raw_breakpoint_without_location (enum bptype bptype
)
4123 struct breakpoint
*b
, *b1
;
4125 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4126 memset (b
, 0, sizeof (*b
));
4129 b
->language
= current_language
->la_language
;
4130 b
->input_radix
= input_radix
;
4132 b
->enable_state
= bp_enabled
;
4135 b
->ignore_count
= 0;
4137 b
->frame_id
= null_frame_id
;
4138 b
->dll_pathname
= NULL
;
4139 b
->triggered_dll_pathname
= NULL
;
4140 b
->forked_inferior_pid
= 0;
4141 b
->exec_pathname
= NULL
;
4143 b
->condition_not_parsed
= 0;
4145 /* Add this breakpoint to the end of the chain
4146 so that a list of breakpoints will come out in order
4147 of increasing numbers. */
4149 b1
= breakpoint_chain
;
4151 breakpoint_chain
= b
;
4161 /* Initialize loc->function_name. */
4163 set_breakpoint_location_function (struct bp_location
*loc
)
4165 if (loc
->owner
->type
== bp_breakpoint
4166 || loc
->owner
->type
== bp_hardware_breakpoint
)
4168 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4170 if (loc
->function_name
)
4171 loc
->function_name
= xstrdup (loc
->function_name
);
4175 /* set_raw_breakpoint is a low level routine for allocating and
4176 partially initializing a breakpoint of type BPTYPE. The newly
4177 created breakpoint's address, section, source file name, and line
4178 number are provided by SAL. The newly created and partially
4179 initialized breakpoint is added to the breakpoint chain and
4180 is also returned as the value of this function.
4182 It is expected that the caller will complete the initialization of
4183 the newly created breakpoint struct as well as output any status
4184 information regarding the creation of a new breakpoint. In
4185 particular, set_raw_breakpoint does NOT set the breakpoint
4186 number! Care should be taken to not allow an error to occur
4187 prior to completing the initialization of the breakpoint. If this
4188 should happen, a bogus breakpoint will be left on the chain. */
4191 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4193 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4194 CORE_ADDR adjusted_address
;
4196 /* Adjust the breakpoint's address prior to allocating a location.
4197 Once we call allocate_bp_location(), that mostly uninitialized
4198 location will be placed on the location chain. Adjustment of the
4199 breakpoint may cause read_memory_nobpt() to be called and we do
4200 not want its scan of the location chain to find a breakpoint and
4201 location that's only been partially initialized. */
4202 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4204 b
->loc
= allocate_bp_location (b
, bptype
);
4205 b
->loc
->requested_address
= sal
.pc
;
4206 b
->loc
->address
= adjusted_address
;
4208 if (sal
.symtab
== NULL
)
4209 b
->source_file
= NULL
;
4211 b
->source_file
= savestring (sal
.symtab
->filename
,
4212 strlen (sal
.symtab
->filename
));
4213 b
->loc
->section
= sal
.section
;
4214 b
->line_number
= sal
.line
;
4216 set_breakpoint_location_function (b
->loc
);
4218 check_duplicates (b
);
4219 breakpoints_changed ();
4225 /* Note that the breakpoint object B describes a permanent breakpoint
4226 instruction, hard-wired into the inferior's code. */
4228 make_breakpoint_permanent (struct breakpoint
*b
)
4230 struct bp_location
*bl
;
4231 b
->enable_state
= bp_permanent
;
4233 /* By definition, permanent breakpoints are already present in the code.
4234 Mark all locations as inserted. For now, make_breakpoint_permanent
4235 is called in just one place, so it's hard to say if it's reasonable
4236 to have permanent breakpoint with multiple locations or not,
4237 but it's easy to implmement. */
4238 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4242 static struct breakpoint
*
4243 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4245 static int internal_breakpoint_number
= -1;
4246 struct symtab_and_line sal
;
4247 struct breakpoint
*b
;
4249 init_sal (&sal
); /* initialize to zeroes */
4252 sal
.section
= find_pc_overlay (sal
.pc
);
4254 b
= set_raw_breakpoint (sal
, type
);
4255 b
->number
= internal_breakpoint_number
--;
4256 b
->disposition
= disp_donttouch
;
4263 create_longjmp_breakpoint (char *func_name
)
4265 struct breakpoint
*b
;
4266 struct minimal_symbol
*m
;
4268 if (func_name
== NULL
)
4269 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4272 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4275 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4278 b
->enable_state
= bp_disabled
;
4281 b
->addr_string
= xstrdup (func_name
);
4284 /* Call this routine when stepping and nexting to enable a breakpoint
4285 if we do a longjmp(). When we hit that breakpoint, call
4286 set_longjmp_resume_breakpoint() to figure out where we are going. */
4289 enable_longjmp_breakpoint (void)
4291 struct breakpoint
*b
;
4294 if (b
->type
== bp_longjmp
)
4296 b
->enable_state
= bp_enabled
;
4297 check_duplicates (b
);
4302 disable_longjmp_breakpoint (void)
4304 struct breakpoint
*b
;
4307 if (b
->type
== bp_longjmp
4308 || b
->type
== bp_longjmp_resume
)
4310 b
->enable_state
= bp_disabled
;
4311 check_duplicates (b
);
4316 create_overlay_event_breakpoint (char *func_name
)
4318 struct breakpoint
*b
;
4319 struct minimal_symbol
*m
;
4321 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4324 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4326 b
->addr_string
= xstrdup (func_name
);
4328 if (overlay_debugging
== ovly_auto
)
4330 b
->enable_state
= bp_enabled
;
4331 overlay_events_enabled
= 1;
4335 b
->enable_state
= bp_disabled
;
4336 overlay_events_enabled
= 0;
4341 enable_overlay_breakpoints (void)
4343 struct breakpoint
*b
;
4346 if (b
->type
== bp_overlay_event
)
4348 b
->enable_state
= bp_enabled
;
4349 check_duplicates (b
);
4350 overlay_events_enabled
= 1;
4355 disable_overlay_breakpoints (void)
4357 struct breakpoint
*b
;
4360 if (b
->type
== bp_overlay_event
)
4362 b
->enable_state
= bp_disabled
;
4363 check_duplicates (b
);
4364 overlay_events_enabled
= 0;
4369 create_thread_event_breakpoint (CORE_ADDR address
)
4371 struct breakpoint
*b
;
4373 b
= create_internal_breakpoint (address
, bp_thread_event
);
4375 b
->enable_state
= bp_enabled
;
4376 /* addr_string has to be used or breakpoint_re_set will delete me. */
4377 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4383 remove_thread_event_breakpoints (void)
4385 struct breakpoint
*b
, *temp
;
4387 ALL_BREAKPOINTS_SAFE (b
, temp
)
4388 if (b
->type
== bp_thread_event
)
4389 delete_breakpoint (b
);
4392 struct captured_parse_breakpoint_args
4395 struct symtabs_and_lines
*sals_p
;
4396 char ***addr_string_p
;
4400 struct lang_and_radix
4408 remove_solib_event_breakpoints (void)
4410 struct breakpoint
*b
, *temp
;
4412 ALL_BREAKPOINTS_SAFE (b
, temp
)
4413 if (b
->type
== bp_shlib_event
)
4414 delete_breakpoint (b
);
4418 create_solib_event_breakpoint (CORE_ADDR address
)
4420 struct breakpoint
*b
;
4422 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4426 /* Disable any breakpoints that are on code in shared libraries. Only
4427 apply to enabled breakpoints, disabled ones can just stay disabled. */
4430 disable_breakpoints_in_shlibs (void)
4432 struct bp_location
*loc
;
4433 int disabled_shlib_breaks
= 0;
4435 ALL_BP_LOCATIONS (loc
)
4437 struct breakpoint
*b
= loc
->owner
;
4438 /* We apply the check to all breakpoints, including disabled
4439 for those with loc->duplicate set. This is so that when breakpoint
4440 becomes enabled, or the duplicate is removed, gdb will try to insert
4441 all breakpoints. If we don't set shlib_disabled here, we'll try
4442 to insert those breakpoints and fail. */
4443 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4444 && !loc
->shlib_disabled
4446 && PC_SOLIB (loc
->address
)
4448 && solib_address (loc
->address
)
4452 loc
->shlib_disabled
= 1;
4457 /* Disable any breakpoints that are in in an unloaded shared library. Only
4458 apply to enabled breakpoints, disabled ones can just stay disabled. */
4461 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4463 struct bp_location
*loc
;
4464 int disabled_shlib_breaks
= 0;
4466 ALL_BP_LOCATIONS (loc
)
4468 struct breakpoint
*b
= loc
->owner
;
4469 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4470 || loc
->loc_type
== bp_loc_software_breakpoint
)
4471 && !loc
->shlib_disabled
)
4474 char *so_name
= PC_SOLIB (loc
->address
);
4476 char *so_name
= solib_address (loc
->address
);
4478 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4480 loc
->shlib_disabled
= 1;
4481 /* At this point, we cannot rely on remove_breakpoint
4482 succeeding so we must mark the breakpoint as not inserted
4483 to prevent future errors occurring in remove_breakpoints. */
4485 if (!disabled_shlib_breaks
)
4487 target_terminal_ours_for_output ();
4488 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4491 disabled_shlib_breaks
= 1;
4498 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4499 enum bptype bp_kind
)
4501 struct symtab_and_line sal
;
4502 struct breakpoint
*b
;
4503 int thread
= -1; /* All threads. */
4510 b
= set_raw_breakpoint (sal
, bp_kind
);
4511 set_breakpoint_count (breakpoint_count
+ 1);
4512 b
->number
= breakpoint_count
;
4513 b
->cond_string
= (cond_string
== NULL
) ?
4514 NULL
: savestring (cond_string
, strlen (cond_string
));
4516 b
->addr_string
= NULL
;
4517 b
->enable_state
= bp_enabled
;
4518 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4519 b
->forked_inferior_pid
= 0;
4525 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4527 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4531 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4533 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4537 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4539 struct symtab_and_line sal
;
4540 struct breakpoint
*b
;
4541 int thread
= -1; /* All threads. */
4548 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4549 set_breakpoint_count (breakpoint_count
+ 1);
4550 b
->number
= breakpoint_count
;
4551 b
->cond_string
= (cond_string
== NULL
) ?
4552 NULL
: savestring (cond_string
, strlen (cond_string
));
4554 b
->addr_string
= NULL
;
4555 b
->enable_state
= bp_enabled
;
4556 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4562 hw_breakpoint_used_count (void)
4564 struct breakpoint
*b
;
4569 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4577 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4579 struct breakpoint
*b
;
4582 *other_type_used
= 0;
4585 if (breakpoint_enabled (b
))
4587 if (b
->type
== type
)
4589 else if ((b
->type
== bp_hardware_watchpoint
||
4590 b
->type
== bp_read_watchpoint
||
4591 b
->type
== bp_access_watchpoint
))
4592 *other_type_used
= 1;
4598 /* Call this after hitting the longjmp() breakpoint. Use this to set
4599 a new breakpoint at the target of the jmp_buf.
4601 FIXME - This ought to be done by setting a temporary breakpoint
4602 that gets deleted automatically... */
4605 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4607 struct breakpoint
*b
;
4610 if (b
->type
== bp_longjmp_resume
)
4612 b
->loc
->requested_address
= pc
;
4613 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4615 b
->enable_state
= bp_enabled
;
4616 b
->frame_id
= frame_id
;
4617 check_duplicates (b
);
4623 disable_watchpoints_before_interactive_call_start (void)
4625 struct breakpoint
*b
;
4629 if (((b
->type
== bp_watchpoint
)
4630 || (b
->type
== bp_hardware_watchpoint
)
4631 || (b
->type
== bp_read_watchpoint
)
4632 || (b
->type
== bp_access_watchpoint
))
4633 && breakpoint_enabled (b
))
4635 b
->enable_state
= bp_call_disabled
;
4636 check_duplicates (b
);
4642 enable_watchpoints_after_interactive_call_stop (void)
4644 struct breakpoint
*b
;
4648 if (((b
->type
== bp_watchpoint
)
4649 || (b
->type
== bp_hardware_watchpoint
)
4650 || (b
->type
== bp_read_watchpoint
)
4651 || (b
->type
== bp_access_watchpoint
))
4652 && (b
->enable_state
== bp_call_disabled
))
4654 b
->enable_state
= bp_enabled
;
4655 check_duplicates (b
);
4661 /* Set a breakpoint that will evaporate an end of command
4662 at address specified by SAL.
4663 Restrict it to frame FRAME if FRAME is nonzero. */
4666 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4669 struct breakpoint
*b
;
4670 b
= set_raw_breakpoint (sal
, type
);
4671 b
->enable_state
= bp_enabled
;
4672 b
->disposition
= disp_donttouch
;
4673 b
->frame_id
= frame_id
;
4675 /* If we're debugging a multi-threaded program, then we
4676 want momentary breakpoints to be active in only a
4677 single thread of control. */
4678 if (in_thread_list (inferior_ptid
))
4679 b
->thread
= pid_to_thread_id (inferior_ptid
);
4685 /* Tell the user we have just set a breakpoint B. */
4688 mention (struct breakpoint
*b
)
4691 struct cleanup
*old_chain
, *ui_out_chain
;
4692 struct ui_stream
*stb
;
4694 stb
= ui_out_stream_new (uiout
);
4695 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4697 /* FIXME: This is misplaced; mention() is called by things (like
4698 hitting a watchpoint) other than breakpoint creation. It should
4699 be possible to clean this up and at the same time replace the
4700 random calls to breakpoint_changed with this hook, as has already
4701 been done for deprecated_delete_breakpoint_hook and so on. */
4702 if (deprecated_create_breakpoint_hook
)
4703 deprecated_create_breakpoint_hook (b
);
4704 breakpoint_create_event (b
->number
);
4706 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4707 b
->ops
->print_mention (b
);
4712 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4715 ui_out_text (uiout
, "Watchpoint ");
4716 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4717 ui_out_field_int (uiout
, "number", b
->number
);
4718 ui_out_text (uiout
, ": ");
4719 print_expression (b
->exp
, stb
->stream
);
4720 ui_out_field_stream (uiout
, "exp", stb
);
4721 do_cleanups (ui_out_chain
);
4723 case bp_hardware_watchpoint
:
4724 ui_out_text (uiout
, "Hardware watchpoint ");
4725 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4726 ui_out_field_int (uiout
, "number", b
->number
);
4727 ui_out_text (uiout
, ": ");
4728 print_expression (b
->exp
, stb
->stream
);
4729 ui_out_field_stream (uiout
, "exp", stb
);
4730 do_cleanups (ui_out_chain
);
4732 case bp_read_watchpoint
:
4733 ui_out_text (uiout
, "Hardware read watchpoint ");
4734 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4735 ui_out_field_int (uiout
, "number", b
->number
);
4736 ui_out_text (uiout
, ": ");
4737 print_expression (b
->exp
, stb
->stream
);
4738 ui_out_field_stream (uiout
, "exp", stb
);
4739 do_cleanups (ui_out_chain
);
4741 case bp_access_watchpoint
:
4742 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4743 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4744 ui_out_field_int (uiout
, "number", b
->number
);
4745 ui_out_text (uiout
, ": ");
4746 print_expression (b
->exp
, stb
->stream
);
4747 ui_out_field_stream (uiout
, "exp", stb
);
4748 do_cleanups (ui_out_chain
);
4751 if (ui_out_is_mi_like_p (uiout
))
4756 printf_filtered (_("Breakpoint %d"), b
->number
);
4759 case bp_hardware_breakpoint
:
4760 if (ui_out_is_mi_like_p (uiout
))
4765 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4769 case bp_catch_unload
:
4770 printf_filtered (_("Catchpoint %d (%s %s)"),
4772 (b
->type
== bp_catch_load
) ? "load" : "unload",
4773 (b
->dll_pathname
!= NULL
) ?
4774 b
->dll_pathname
: "<any library>");
4777 case bp_catch_vfork
:
4778 printf_filtered (_("Catchpoint %d (%s)"),
4780 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4783 printf_filtered (_("Catchpoint %d (exec)"),
4790 case bp_longjmp_resume
:
4791 case bp_step_resume
:
4793 case bp_watchpoint_scope
:
4794 case bp_shlib_event
:
4795 case bp_thread_event
:
4796 case bp_overlay_event
:
4802 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4806 printf_filtered (_(" (%s) pending."), b
->addr_string
);
4810 if (addressprint
|| b
->source_file
== NULL
)
4812 printf_filtered (" at ");
4813 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
4816 printf_filtered (": file %s, line %d.",
4817 b
->source_file
, b
->line_number
);
4821 struct bp_location
*loc
= b
->loc
;
4823 for (; loc
; loc
= loc
->next
)
4825 printf_filtered (" (%d locations)", n
);
4830 do_cleanups (old_chain
);
4831 if (ui_out_is_mi_like_p (uiout
))
4833 printf_filtered ("\n");
4837 static struct bp_location
*
4838 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
4839 const struct symtab_and_line
*sal
)
4841 struct bp_location
*loc
, **tmp
;
4843 loc
= allocate_bp_location (b
, bptype
);
4844 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
4847 loc
->requested_address
= sal
->pc
;
4848 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
4850 loc
->section
= sal
->section
;
4852 set_breakpoint_location_function (loc
);
4856 /* Create a breakpoint with SAL as location. Use ADDR_STRING
4857 as textual description of the location, and COND_STRING
4858 as condition expression. */
4861 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
4863 enum bptype type
, enum bpdisp disposition
,
4864 int thread
, int ignore_count
, int from_tty
)
4866 struct breakpoint
*b
= NULL
;
4869 if (type
== bp_hardware_breakpoint
)
4871 int i
= hw_breakpoint_used_count ();
4872 int target_resources_ok
=
4873 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4875 if (target_resources_ok
== 0)
4876 error (_("No hardware breakpoint support in the target."));
4877 else if (target_resources_ok
< 0)
4878 error (_("Hardware breakpoints used exceeds limit."));
4881 for (i
= 0; i
< sals
.nelts
; ++i
)
4883 struct symtab_and_line sal
= sals
.sals
[i
];
4884 struct bp_location
*loc
;
4887 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
4891 b
= set_raw_breakpoint (sal
, type
);
4892 set_breakpoint_count (breakpoint_count
+ 1);
4893 b
->number
= breakpoint_count
;
4896 b
->cond_string
= cond_string
;
4897 b
->ignore_count
= ignore_count
;
4898 b
->enable_state
= bp_enabled
;
4899 b
->disposition
= disposition
;
4905 loc
= add_location_to_breakpoint (b
, type
, &sal
);
4910 char *arg
= b
->cond_string
;
4911 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
4913 error (_("Garbage %s follows condition"), arg
);
4918 b
->addr_string
= addr_string
;
4920 /* addr_string has to be used or breakpoint_re_set will delete
4922 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4927 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
4928 elements to fill the void space. */
4929 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
4931 int i
= index_to_remove
+1;
4932 int last_index
= sal
->nelts
-1;
4934 for (;i
<= last_index
; ++i
)
4935 sal
->sals
[i
-1] = sal
->sals
[i
];
4940 /* If appropriate, obtains all sals that correspond
4941 to the same file and line as SAL. This is done
4942 only if SAL does not have explicit PC and has
4943 line and file information. If we got just a single
4944 expanded sal, return the original.
4946 Otherwise, if SAL.explicit_line is not set, filter out
4947 all sals for which the name of enclosing function
4948 is different from SAL. This makes sure that if we have
4949 breakpoint originally set in template instantiation, say
4950 foo<int>(), we won't expand SAL to locations at the same
4951 line in all existing instantiations of 'foo'.
4954 struct symtabs_and_lines
4955 expand_line_sal_maybe (struct symtab_and_line sal
)
4957 struct symtabs_and_lines expanded
;
4958 CORE_ADDR original_pc
= sal
.pc
;
4959 char *original_function
= NULL
;
4963 /* If we have explicit pc, don't expand.
4964 If we have no line number, we can't expand. */
4965 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
4968 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
4969 expanded
.sals
[0] = sal
;
4974 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
4976 expanded
= expand_line_sal (sal
);
4977 if (expanded
.nelts
== 1)
4979 /* We had one sal, we got one sal. Without futher
4980 processing, just return the original sal. */
4981 xfree (expanded
.sals
);
4983 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
4984 sal
.pc
= original_pc
;
4985 expanded
.sals
[0] = sal
;
4989 if (!sal
.explicit_line
)
4991 CORE_ADDR func_addr
, func_end
;
4992 for (i
= 0; i
< expanded
.nelts
; ++i
)
4994 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
4995 char *this_function
;
4996 if (find_pc_partial_function (pc
, &this_function
,
4997 &func_addr
, &func_end
))
4999 if (this_function
&&
5000 strcmp (this_function
, original_function
) != 0)
5002 remove_sal (&expanded
, i
);
5005 else if (func_addr
== pc
)
5007 /* We're at beginning of a function, and should
5009 struct symbol
*sym
= find_pc_function (pc
);
5011 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5014 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5021 if (expanded
.nelts
<= 1)
5023 /* This is un ugly workaround. If we get zero
5024 expanded sals then something is really wrong.
5025 Fix that by returnign the original sal. */
5026 xfree (expanded
.sals
);
5028 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5029 sal
.pc
= original_pc
;
5030 expanded
.sals
[0] = sal
;
5037 for (i
= 0; i
< expanded
.nelts
; ++i
)
5038 if (expanded
.sals
[i
].pc
== original_pc
)
5049 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5050 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5051 value. COND_STRING, if not NULL, specified the condition to be
5052 used for all breakpoints. Essentially the only case where
5053 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5054 function. In that case, it's still not possible to specify
5055 separate conditions for different overloaded functions, so
5056 we take just a single condition string.
5058 NOTE: If the function succeeds, the caller is expected to cleanup
5059 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5060 array contents). If the function fails (error() is called), the
5061 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5062 COND and SALS arrays and each of those arrays contents. */
5065 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5067 enum bptype type
, enum bpdisp disposition
,
5068 int thread
, int ignore_count
, int from_tty
)
5071 for (i
= 0; i
< sals
.nelts
; ++i
)
5073 struct symtabs_and_lines expanded
=
5074 expand_line_sal_maybe (sals
.sals
[i
]);
5076 create_breakpoint (expanded
, addr_string
[i
],
5077 cond_string
, type
, disposition
,
5078 thread
, ignore_count
, from_tty
);
5082 /* Parse ARG which is assumed to be a SAL specification possibly
5083 followed by conditionals. On return, SALS contains an array of SAL
5084 addresses found. ADDR_STRING contains a vector of (canonical)
5085 address strings. ARG points to the end of the SAL. */
5088 parse_breakpoint_sals (char **address
,
5089 struct symtabs_and_lines
*sals
,
5090 char ***addr_string
,
5093 char *addr_start
= *address
;
5094 *addr_string
= NULL
;
5095 /* If no arg given, or if first arg is 'if ', use the default
5097 if ((*address
) == NULL
5098 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5100 if (default_breakpoint_valid
)
5102 struct symtab_and_line sal
;
5103 init_sal (&sal
); /* initialize to zeroes */
5104 sals
->sals
= (struct symtab_and_line
*)
5105 xmalloc (sizeof (struct symtab_and_line
));
5106 sal
.pc
= default_breakpoint_address
;
5107 sal
.line
= default_breakpoint_line
;
5108 sal
.symtab
= default_breakpoint_symtab
;
5109 sal
.section
= find_pc_overlay (sal
.pc
);
5110 sals
->sals
[0] = sal
;
5114 error (_("No default breakpoint address now."));
5118 /* Force almost all breakpoints to be in terms of the
5119 current_source_symtab (which is decode_line_1's default). This
5120 should produce the results we want almost all of the time while
5121 leaving default_breakpoint_* alone.
5122 ObjC: However, don't match an Objective-C method name which
5123 may have a '+' or '-' succeeded by a '[' */
5125 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5127 if (default_breakpoint_valid
5129 || ((strchr ("+-", (*address
)[0]) != NULL
)
5130 && ((*address
)[1] != '['))))
5131 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5132 default_breakpoint_line
, addr_string
,
5135 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5136 addr_string
, not_found_ptr
);
5138 /* For any SAL that didn't have a canonical string, fill one in. */
5139 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5140 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5141 if (addr_start
!= (*address
))
5144 for (i
= 0; i
< sals
->nelts
; i
++)
5146 /* Add the string if not present. */
5147 if ((*addr_string
)[i
] == NULL
)
5148 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5154 /* Convert each SAL into a real PC. Verify that the PC can be
5155 inserted as a breakpoint. If it can't throw an error. */
5158 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5162 for (i
= 0; i
< sals
->nelts
; i
++)
5163 resolve_sal_pc (&sals
->sals
[i
]);
5167 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5169 struct captured_parse_breakpoint_args
*args
= data
;
5171 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5172 args
->not_found_ptr
);
5175 /* Given TOK, a string specification of condition and thread, as
5176 accepted by the 'break' command, extract the condition
5177 string and thread number and set *COND_STRING and *THREAD.
5178 PC identifies the context at which the condition should be parsed.
5179 If no condition is found, *COND_STRING is set to NULL.
5180 If no thread is found, *THREAD is set to -1. */
5182 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5183 char **cond_string
, int *thread
)
5185 *cond_string
= NULL
;
5191 char *cond_start
= NULL
;
5192 char *cond_end
= NULL
;
5193 while (*tok
== ' ' || *tok
== '\t')
5198 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5201 toklen
= end_tok
- tok
;
5203 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5205 tok
= cond_start
= end_tok
+ 1;
5206 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5208 *cond_string
= savestring (cond_start
,
5209 cond_end
- cond_start
);
5211 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5217 *thread
= strtol (tok
, &tok
, 0);
5219 error (_("Junk after thread keyword."));
5220 if (!valid_thread_id (*thread
))
5221 error (_("Unknown thread %d."), *thread
);
5224 error (_("Junk at end of arguments."));
5228 /* Set a breakpoint. This function is shared between
5229 CLI and MI functions for setting a breakpoint.
5230 This function has two major modes of operations,
5231 selected by the PARSE_CONDITION_AND_THREAD parameter.
5232 If non-zero, the function will parse arg, extracting
5233 breakpoint location, address and thread. Otherwise,
5234 ARG is just the location of breakpoint, with condition
5235 and thread specified by the COND_STRING and THREAD
5239 break_command_really (char *arg
, char *cond_string
, int thread
,
5240 int parse_condition_and_thread
,
5241 int tempflag
, int hardwareflag
,
5243 enum auto_boolean pending_break_support
,
5246 struct gdb_exception e
;
5247 struct symtabs_and_lines sals
;
5248 struct symtab_and_line pending_sal
;
5251 char *addr_start
= arg
;
5253 struct cleanup
*old_chain
;
5254 struct cleanup
*breakpoint_chain
= NULL
;
5255 struct captured_parse_breakpoint_args parse_args
;
5264 parse_args
.arg_p
= &arg
;
5265 parse_args
.sals_p
= &sals
;
5266 parse_args
.addr_string_p
= &addr_string
;
5267 parse_args
.not_found_ptr
= ¬_found
;
5269 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5270 &parse_args
, RETURN_MASK_ALL
);
5272 /* If caller is interested in rc value from parse, set value. */
5276 exception_print (gdb_stderr
, e
);
5281 case NOT_FOUND_ERROR
:
5283 exception_print (gdb_stderr
, e
);
5285 /* If pending breakpoint support is turned off, throw
5288 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5289 deprecated_throw_reason (RETURN_ERROR
);
5291 /* If pending breakpoint support is auto query and the user
5292 selects no, then simply return the error code. */
5293 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5294 !nquery ("Make breakpoint pending on future shared library load? "))
5297 /* At this point, either the user was queried about setting
5298 a pending breakpoint and selected yes, or pending
5299 breakpoint behavior is on and thus a pending breakpoint
5300 is defaulted on behalf of the user. */
5301 copy_arg
= xstrdup (addr_start
);
5302 addr_string
= ©_arg
;
5304 sals
.sals
= &pending_sal
;
5309 exception_print (gdb_stderr
, e
);
5317 /* Create a chain of things that always need to be cleaned up. */
5318 old_chain
= make_cleanup (null_cleanup
, 0);
5322 /* Make sure that all storage allocated to SALS gets freed. */
5323 make_cleanup (xfree
, sals
.sals
);
5325 /* Cleanup the addr_string array but not its contents. */
5326 make_cleanup (xfree
, addr_string
);
5329 /* ----------------------------- SNIP -----------------------------
5330 Anything added to the cleanup chain beyond this point is assumed
5331 to be part of a breakpoint. If the breakpoint create succeeds
5332 then the memory is not reclaimed. */
5333 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5335 /* Mark the contents of the addr_string for cleanup. These go on
5336 the breakpoint_chain and only occure if the breakpoint create
5338 for (i
= 0; i
< sals
.nelts
; i
++)
5340 if (addr_string
[i
] != NULL
)
5341 make_cleanup (xfree
, addr_string
[i
]);
5344 /* Resolve all line numbers to PC's and verify that the addresses
5345 are ok for the target. */
5347 breakpoint_sals_to_pc (&sals
, addr_start
);
5349 /* Verify that condition can be parsed, before setting any
5350 breakpoints. Allocate a separate condition expression for each
5354 if (parse_condition_and_thread
)
5356 /* Here we only parse 'arg' to separate condition
5357 from thread number, so parsing in context of first
5358 sal is OK. When setting the breakpoint we'll
5359 re-parse it in context of each sal. */
5362 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5364 make_cleanup (xfree
, cond_string
);
5368 /* Create a private copy of condition string. */
5371 cond_string
= xstrdup (cond_string
);
5372 make_cleanup (xfree
, cond_string
);
5375 create_breakpoints (sals
, addr_string
, cond_string
,
5376 hardwareflag
? bp_hardware_breakpoint
5378 tempflag
? disp_del
: disp_donttouch
,
5379 thread
, ignore_count
, from_tty
);
5383 struct symtab_and_line sal
= {0};
5384 struct breakpoint
*b
;
5386 make_cleanup (xfree
, copy_arg
);
5388 b
= set_raw_breakpoint_without_location (hardwareflag
5389 ? bp_hardware_breakpoint
5391 set_breakpoint_count (breakpoint_count
+ 1);
5392 b
->number
= breakpoint_count
;
5394 b
->addr_string
= addr_string
[0];
5395 b
->cond_string
= NULL
;
5396 b
->ignore_count
= ignore_count
;
5397 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5398 b
->condition_not_parsed
= 1;
5403 warning (_("Multiple breakpoints were set.\n"
5404 "Use the \"delete\" command to delete unwanted breakpoints."));
5405 /* That's it. Discard the cleanups for data inserted into the
5407 discard_cleanups (breakpoint_chain
);
5408 /* But cleanup everything else. */
5409 do_cleanups (old_chain
);
5414 /* Set a breakpoint.
5415 ARG is a string describing breakpoint address,
5416 condition, and thread.
5417 FLAG specifies if a breakpoint is hardware on,
5418 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5422 break_command_1 (char *arg
, int flag
, int from_tty
)
5424 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5425 int tempflag
= flag
& BP_TEMPFLAG
;
5427 return break_command_really (arg
,
5428 NULL
, 0, 1 /* parse arg */,
5429 tempflag
, hardwareflag
,
5430 0 /* Ignore count */,
5431 pending_break_support
, from_tty
);
5436 gdb_breakpoint (char *address
, char *condition
,
5437 int hardwareflag
, int tempflag
,
5438 int thread
, int ignore_count
,
5440 char **error_message
)
5442 return break_command_really (address
, condition
, thread
,
5443 0 /* condition and thread are valid. */,
5444 tempflag
, hardwareflag
,
5447 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5452 /* Helper function for break_command_1 and disassemble_command. */
5455 resolve_sal_pc (struct symtab_and_line
*sal
)
5459 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5461 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5462 error (_("No line %d in file \"%s\"."),
5463 sal
->line
, sal
->symtab
->filename
);
5467 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5469 struct blockvector
*bv
;
5473 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5476 sym
= block_function (b
);
5479 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5480 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5484 /* It really is worthwhile to have the section, so we'll just
5485 have to look harder. This case can be executed if we have
5486 line numbers but no functions (as can happen in assembly
5489 struct minimal_symbol
*msym
;
5491 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5493 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5500 break_command (char *arg
, int from_tty
)
5502 break_command_1 (arg
, 0, from_tty
);
5506 tbreak_command (char *arg
, int from_tty
)
5508 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5512 hbreak_command (char *arg
, int from_tty
)
5514 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5518 thbreak_command (char *arg
, int from_tty
)
5520 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5524 stop_command (char *arg
, int from_tty
)
5526 printf_filtered (_("Specify the type of breakpoint to set.\n\
5527 Usage: stop in <function | address>\n\
5528 stop at <line>\n"));
5532 stopin_command (char *arg
, int from_tty
)
5536 if (arg
== (char *) NULL
)
5538 else if (*arg
!= '*')
5543 /* look for a ':'. If this is a line number specification, then
5544 say it is bad, otherwise, it should be an address or
5545 function/method name */
5546 while (*argptr
&& !hasColon
)
5548 hasColon
= (*argptr
== ':');
5553 badInput
= (*argptr
!= ':'); /* Not a class::method */
5555 badInput
= isdigit (*arg
); /* a simple line number */
5559 printf_filtered (_("Usage: stop in <function | address>\n"));
5561 break_command_1 (arg
, 0, from_tty
);
5565 stopat_command (char *arg
, int from_tty
)
5569 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5576 /* look for a ':'. If there is a '::' then get out, otherwise
5577 it is probably a line number. */
5578 while (*argptr
&& !hasColon
)
5580 hasColon
= (*argptr
== ':');
5585 badInput
= (*argptr
== ':'); /* we have class::method */
5587 badInput
= !isdigit (*arg
); /* not a line number */
5591 printf_filtered (_("Usage: stop at <line>\n"));
5593 break_command_1 (arg
, 0, from_tty
);
5596 /* accessflag: hw_write: watch write,
5597 hw_read: watch read,
5598 hw_access: watch access (read or write) */
5600 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5602 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5603 struct symtab_and_line sal
;
5604 struct expression
*exp
;
5605 struct block
*exp_valid_block
;
5606 struct value
*val
, *mark
;
5607 struct frame_info
*frame
;
5608 struct frame_info
*prev_frame
= NULL
;
5609 char *exp_start
= NULL
;
5610 char *exp_end
= NULL
;
5611 char *tok
, *id_tok_start
, *end_tok
;
5613 char *cond_start
= NULL
;
5614 char *cond_end
= NULL
;
5615 struct expression
*cond
= NULL
;
5616 int i
, other_type_used
, target_resources_ok
= 0;
5617 enum bptype bp_type
;
5621 init_sal (&sal
); /* initialize to zeroes */
5623 /* Make sure that we actually have parameters to parse. */
5624 if (arg
!= NULL
&& arg
[0] != '\0')
5626 toklen
= strlen (arg
); /* Size of argument list. */
5628 /* Points tok to the end of the argument list. */
5629 tok
= arg
+ toklen
- 1;
5631 /* Go backwards in the parameters list. Skip the last parameter.
5632 If we're expecting a 'thread <thread_num>' parameter, this should
5633 be the thread identifier. */
5634 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5636 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5639 /* Points end_tok to the beginning of the last token. */
5640 id_tok_start
= tok
+ 1;
5642 /* Go backwards in the parameters list. Skip one more parameter.
5643 If we're expecting a 'thread <thread_num>' parameter, we should
5644 reach a "thread" token. */
5645 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5650 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5653 /* Move the pointer forward to skip the whitespace and
5654 calculate the length of the token. */
5656 toklen
= end_tok
- tok
;
5658 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5660 /* At this point we've found a "thread" token, which means
5661 the user is trying to set a watchpoint that triggers
5662 only in a specific thread. */
5665 /* Extract the thread ID from the next token. */
5666 thread
= strtol (id_tok_start
, &endp
, 0);
5668 /* Check if the user provided a valid numeric value for the
5670 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5671 error (_("Invalid thread ID specification %s."), id_tok_start
);
5673 /* Check if the thread actually exists. */
5674 if (!valid_thread_id (thread
))
5675 error (_("Unknown thread %d."), thread
);
5677 /* Truncate the string and get rid of the thread <thread_num>
5678 parameter before the parameter list is parsed by the
5679 evaluate_expression() function. */
5684 /* Parse the rest of the arguments. */
5685 innermost_block
= NULL
;
5687 exp
= parse_exp_1 (&arg
, 0, 0);
5689 exp_valid_block
= innermost_block
;
5690 mark
= value_mark ();
5691 val
= evaluate_expression (exp
);
5692 release_value (val
);
5693 if (value_lazy (val
))
5694 value_fetch_lazy (val
);
5697 while (*tok
== ' ' || *tok
== '\t')
5701 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5704 toklen
= end_tok
- tok
;
5705 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5707 tok
= cond_start
= end_tok
+ 1;
5708 cond
= parse_exp_1 (&tok
, 0, 0);
5712 error (_("Junk at end of command."));
5714 if (accessflag
== hw_read
)
5715 bp_type
= bp_read_watchpoint
;
5716 else if (accessflag
== hw_access
)
5717 bp_type
= bp_access_watchpoint
;
5719 bp_type
= bp_hardware_watchpoint
;
5721 mem_cnt
= can_use_hardware_watchpoint (val
);
5722 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5723 error (_("Expression cannot be implemented with read/access watchpoint."));
5726 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5727 target_resources_ok
=
5728 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5730 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5731 error (_("Target does not support this type of hardware watchpoint."));
5733 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5734 error (_("Target can only support one kind of HW watchpoint at a time."));
5737 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5738 watchpoint could not be set. */
5739 if (!mem_cnt
|| target_resources_ok
<= 0)
5740 bp_type
= bp_watchpoint
;
5742 frame
= block_innermost_frame (exp_valid_block
);
5744 prev_frame
= get_prev_frame (frame
);
5748 /* If the expression is "local", then set up a "watchpoint scope"
5749 breakpoint at the point where we've left the scope of the watchpoint
5750 expression. Create the scope breakpoint before the watchpoint, so
5751 that we will encounter it first in bpstat_stop_status. */
5752 if (innermost_block
&& prev_frame
)
5754 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5755 bp_watchpoint_scope
);
5757 scope_breakpoint
->enable_state
= bp_enabled
;
5759 /* Automatically delete the breakpoint when it hits. */
5760 scope_breakpoint
->disposition
= disp_del
;
5762 /* Only break in the proper frame (help with recursion). */
5763 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5765 /* Set the address at which we will stop. */
5766 scope_breakpoint
->loc
->requested_address
5767 = get_frame_pc (prev_frame
);
5768 scope_breakpoint
->loc
->address
5769 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5770 scope_breakpoint
->type
);
5773 /* Now set up the breakpoint. */
5774 b
= set_raw_breakpoint (sal
, bp_type
);
5775 set_breakpoint_count (breakpoint_count
+ 1);
5776 b
->number
= breakpoint_count
;
5778 b
->disposition
= disp_donttouch
;
5780 b
->exp_valid_block
= exp_valid_block
;
5781 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5783 b
->loc
->cond
= cond
;
5785 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5790 b
->watchpoint_frame
= get_frame_id (frame
);
5792 b
->watchpoint_frame
= null_frame_id
;
5794 if (scope_breakpoint
!= NULL
)
5796 /* The scope breakpoint is related to the watchpoint. We will
5797 need to act on them together. */
5798 b
->related_breakpoint
= scope_breakpoint
;
5799 scope_breakpoint
->related_breakpoint
= b
;
5802 value_free_to_mark (mark
);
5806 /* Return count of locations need to be watched and can be handled
5807 in hardware. If the watchpoint can not be handled
5808 in hardware return zero. */
5811 can_use_hardware_watchpoint (struct value
*v
)
5813 int found_memory_cnt
= 0;
5814 struct value
*head
= v
;
5816 /* Did the user specifically forbid us to use hardware watchpoints? */
5817 if (!can_use_hw_watchpoints
)
5820 /* Make sure that the value of the expression depends only upon
5821 memory contents, and values computed from them within GDB. If we
5822 find any register references or function calls, we can't use a
5823 hardware watchpoint.
5825 The idea here is that evaluating an expression generates a series
5826 of values, one holding the value of every subexpression. (The
5827 expression a*b+c has five subexpressions: a, b, a*b, c, and
5828 a*b+c.) GDB's values hold almost enough information to establish
5829 the criteria given above --- they identify memory lvalues,
5830 register lvalues, computed values, etcetera. So we can evaluate
5831 the expression, and then scan the chain of values that leaves
5832 behind to decide whether we can detect any possible change to the
5833 expression's final value using only hardware watchpoints.
5835 However, I don't think that the values returned by inferior
5836 function calls are special in any way. So this function may not
5837 notice that an expression involving an inferior function call
5838 can't be watched with hardware watchpoints. FIXME. */
5839 for (; v
; v
= value_next (v
))
5841 if (VALUE_LVAL (v
) == lval_memory
)
5844 /* A lazy memory lvalue is one that GDB never needed to fetch;
5845 we either just used its address (e.g., `a' in `a.b') or
5846 we never needed it at all (e.g., `a' in `a,b'). */
5850 /* Ahh, memory we actually used! Check if we can cover
5851 it with hardware watchpoints. */
5852 struct type
*vtype
= check_typedef (value_type (v
));
5854 /* We only watch structs and arrays if user asked for it
5855 explicitly, never if they just happen to appear in a
5856 middle of some value chain. */
5858 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5859 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5861 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
5862 int len
= TYPE_LENGTH (value_type (v
));
5864 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5871 else if (VALUE_LVAL (v
) != not_lval
5872 && deprecated_value_modifiable (v
) == 0)
5873 return 0; /* ??? What does this represent? */
5874 else if (VALUE_LVAL (v
) == lval_register
)
5875 return 0; /* cannot watch a register with a HW watchpoint */
5878 /* The expression itself looks suitable for using a hardware
5879 watchpoint, but give the target machine a chance to reject it. */
5880 return found_memory_cnt
;
5884 watch_command_wrapper (char *arg
, int from_tty
)
5886 watch_command (arg
, from_tty
);
5890 watch_command (char *arg
, int from_tty
)
5892 watch_command_1 (arg
, hw_write
, from_tty
);
5896 rwatch_command_wrapper (char *arg
, int from_tty
)
5898 rwatch_command (arg
, from_tty
);
5902 rwatch_command (char *arg
, int from_tty
)
5904 watch_command_1 (arg
, hw_read
, from_tty
);
5908 awatch_command_wrapper (char *arg
, int from_tty
)
5910 awatch_command (arg
, from_tty
);
5914 awatch_command (char *arg
, int from_tty
)
5916 watch_command_1 (arg
, hw_access
, from_tty
);
5920 /* Helper routines for the until_command routine in infcmd.c. Here
5921 because it uses the mechanisms of breakpoints. */
5923 /* This function is called by fetch_inferior_event via the
5924 cmd_continuation pointer, to complete the until command. It takes
5925 care of cleaning up the temporary breakpoints set up by the until
5928 until_break_command_continuation (struct continuation_arg
*arg
)
5930 struct cleanup
*cleanups
;
5932 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
5933 do_exec_cleanups (cleanups
);
5937 until_break_command (char *arg
, int from_tty
, int anywhere
)
5939 struct symtabs_and_lines sals
;
5940 struct symtab_and_line sal
;
5941 struct frame_info
*frame
= get_selected_frame (NULL
);
5942 struct frame_info
*prev_frame
= get_prev_frame (frame
);
5943 struct breakpoint
*breakpoint
;
5944 struct cleanup
*old_chain
;
5945 struct continuation_arg
*arg1
;
5948 clear_proceed_status ();
5950 /* Set a breakpoint where the user wants it and at return from
5953 if (default_breakpoint_valid
)
5954 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
5955 default_breakpoint_line
, (char ***) NULL
, NULL
);
5957 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
5958 0, (char ***) NULL
, NULL
);
5960 if (sals
.nelts
!= 1)
5961 error (_("Couldn't get information on specified line."));
5964 xfree (sals
.sals
); /* malloc'd, so freed */
5967 error (_("Junk at end of arguments."));
5969 resolve_sal_pc (&sal
);
5972 /* If the user told us to continue until a specified location,
5973 we don't specify a frame at which we need to stop. */
5974 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
5976 /* Otherwise, specify the current frame, because we want to stop only
5977 at the very same frame. */
5978 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
5981 if (!target_can_async_p ())
5982 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
5984 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
5986 /* If we are running asynchronously, and the target supports async
5987 execution, we are not waiting for the target to stop, in the call
5988 tp proceed, below. This means that we cannot delete the
5989 brekpoints until the target has actually stopped. The only place
5990 where we get a chance to do that is in fetch_inferior_event, so
5991 we must set things up for that. */
5993 if (target_can_async_p ())
5995 /* In this case the arg for the continuation is just the point
5996 in the exec_cleanups chain from where to start doing
5997 cleanups, because all the continuation does is the cleanups in
5998 the exec_cleanup_chain. */
6000 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6002 arg1
->data
.pointer
= old_chain
;
6004 add_continuation (until_break_command_continuation
, arg1
);
6007 /* Keep within the current frame, or in frames called by the current
6011 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6012 sal
.pc
= get_frame_pc (prev_frame
);
6013 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6015 if (!target_can_async_p ())
6016 make_cleanup_delete_breakpoint (breakpoint
);
6018 make_exec_cleanup_delete_breakpoint (breakpoint
);
6021 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6022 /* Do the cleanups now, anly if we are not running asynchronously,
6023 of if we are, but the target is still synchronous. */
6024 if (!target_can_async_p ())
6025 do_cleanups (old_chain
);
6029 ep_skip_leading_whitespace (char **s
)
6031 if ((s
== NULL
) || (*s
== NULL
))
6033 while (isspace (**s
))
6037 /* This function examines a string, and attempts to find a token
6038 that might be an event name in the leading characters. If a
6039 possible match is found, a pointer to the last character of
6040 the token is returned. Else, NULL is returned. */
6043 ep_find_event_name_end (char *arg
)
6046 char *event_name_end
= NULL
;
6048 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6052 /* We break out of the loop when we find a token delimiter.
6053 Basically, we're looking for alphanumerics and underscores;
6054 anything else delimites the token. */
6057 if (!isalnum (*s
) && (*s
!= '_'))
6063 return event_name_end
;
6067 /* This function attempts to parse an optional "if <cond>" clause
6068 from the arg string. If one is not found, it returns NULL.
6070 Else, it returns a pointer to the condition string. (It does not
6071 attempt to evaluate the string against a particular block.) And,
6072 it updates arg to point to the first character following the parsed
6073 if clause in the arg string. */
6076 ep_parse_optional_if_clause (char **arg
)
6080 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6083 /* Skip the "if" keyword. */
6086 /* Skip any extra leading whitespace, and record the start of the
6087 condition string. */
6088 ep_skip_leading_whitespace (arg
);
6091 /* Assume that the condition occupies the remainder of the arg string. */
6092 (*arg
) += strlen (cond_string
);
6097 /* This function attempts to parse an optional filename from the arg
6098 string. If one is not found, it returns NULL.
6100 Else, it returns a pointer to the parsed filename. (This function
6101 makes no attempt to verify that a file of that name exists, or is
6102 accessible.) And, it updates arg to point to the first character
6103 following the parsed filename in the arg string.
6105 Note that clients needing to preserve the returned filename for
6106 future access should copy it to their own buffers. */
6108 ep_parse_optional_filename (char **arg
)
6110 static char filename
[1024];
6115 if ((*arg_p
== '\0') || isspace (*arg_p
))
6133 /* Commands to deal with catching events, such as signals, exceptions,
6134 process start/exit, etc. */
6138 catch_fork
, catch_vfork
6143 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6146 char *cond_string
= NULL
;
6148 ep_skip_leading_whitespace (&arg
);
6150 /* The allowed syntax is:
6152 catch [v]fork if <cond>
6154 First, check if there's an if clause. */
6155 cond_string
= ep_parse_optional_if_clause (&arg
);
6157 if ((*arg
!= '\0') && !isspace (*arg
))
6158 error (_("Junk at end of arguments."));
6160 /* If this target supports it, create a fork or vfork catchpoint
6161 and enable reporting of such events. */
6165 create_fork_event_catchpoint (tempflag
, cond_string
);
6168 create_vfork_event_catchpoint (tempflag
, cond_string
);
6171 error (_("unsupported or unknown fork kind; cannot catch it"));
6177 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6179 char *cond_string
= NULL
;
6181 ep_skip_leading_whitespace (&arg
);
6183 /* The allowed syntax is:
6185 catch exec if <cond>
6187 First, check if there's an if clause. */
6188 cond_string
= ep_parse_optional_if_clause (&arg
);
6190 if ((*arg
!= '\0') && !isspace (*arg
))
6191 error (_("Junk at end of arguments."));
6193 /* If this target supports it, create an exec catchpoint
6194 and enable reporting of such events. */
6195 create_exec_event_catchpoint (tempflag
, cond_string
);
6199 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6201 char *dll_pathname
= NULL
;
6202 char *cond_string
= NULL
;
6204 ep_skip_leading_whitespace (&arg
);
6206 /* The allowed syntax is:
6208 catch load if <cond>
6209 catch load <filename>
6210 catch load <filename> if <cond>
6212 The user is not allowed to specify the <filename> after an
6215 We'll ignore the pathological case of a file named "if".
6217 First, check if there's an if clause. If so, then there
6218 cannot be a filename. */
6219 cond_string
= ep_parse_optional_if_clause (&arg
);
6221 /* If there was an if clause, then there cannot be a filename.
6222 Else, there might be a filename and an if clause. */
6223 if (cond_string
== NULL
)
6225 dll_pathname
= ep_parse_optional_filename (&arg
);
6226 ep_skip_leading_whitespace (&arg
);
6227 cond_string
= ep_parse_optional_if_clause (&arg
);
6230 if ((*arg
!= '\0') && !isspace (*arg
))
6231 error (_("Junk at end of arguments."));
6233 /* Create a load breakpoint that only triggers when a load of
6234 the specified dll (or any dll, if no pathname was specified)
6236 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6237 dll_pathname
, cond_string
);
6241 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6243 char *dll_pathname
= NULL
;
6244 char *cond_string
= NULL
;
6246 ep_skip_leading_whitespace (&arg
);
6248 /* The allowed syntax is:
6250 catch unload if <cond>
6251 catch unload <filename>
6252 catch unload <filename> if <cond>
6254 The user is not allowed to specify the <filename> after an
6257 We'll ignore the pathological case of a file named "if".
6259 First, check if there's an if clause. If so, then there
6260 cannot be a filename. */
6261 cond_string
= ep_parse_optional_if_clause (&arg
);
6263 /* If there was an if clause, then there cannot be a filename.
6264 Else, there might be a filename and an if clause. */
6265 if (cond_string
== NULL
)
6267 dll_pathname
= ep_parse_optional_filename (&arg
);
6268 ep_skip_leading_whitespace (&arg
);
6269 cond_string
= ep_parse_optional_if_clause (&arg
);
6272 if ((*arg
!= '\0') && !isspace (*arg
))
6273 error (_("Junk at end of arguments."));
6275 /* Create an unload breakpoint that only triggers when an unload of
6276 the specified dll (or any dll, if no pathname was specified)
6278 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6279 dll_pathname
, cond_string
);
6282 static enum print_stop_action
6283 print_exception_catchpoint (struct breakpoint
*b
)
6285 annotate_catchpoint (b
->number
);
6287 if (strstr (b
->addr_string
, "throw") != NULL
)
6288 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6291 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6294 return PRINT_SRC_AND_LOC
;
6298 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6303 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6306 *last_addr
= b
->loc
->address
;
6307 if (strstr (b
->addr_string
, "throw") != NULL
)
6308 ui_out_field_string (uiout
, "what", "exception throw");
6310 ui_out_field_string (uiout
, "what", "exception catch");
6314 print_mention_exception_catchpoint (struct breakpoint
*b
)
6316 if (strstr (b
->addr_string
, "throw") != NULL
)
6317 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6319 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6322 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6323 print_exception_catchpoint
,
6324 print_one_exception_catchpoint
,
6325 print_mention_exception_catchpoint
6329 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6330 enum exception_event_kind ex_event
, int from_tty
)
6332 char *trigger_func_name
, *nameptr
;
6333 struct symtabs_and_lines sals
;
6334 struct breakpoint
*b
;
6336 if (ex_event
== EX_EVENT_CATCH
)
6337 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6339 trigger_func_name
= xstrdup ("__cxa_throw");
6341 nameptr
= trigger_func_name
;
6342 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6343 if (sals
.nelts
== 0)
6345 xfree (trigger_func_name
);
6349 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6350 set_breakpoint_count (breakpoint_count
+ 1);
6351 b
->number
= breakpoint_count
;
6352 b
->cond_string
= (cond_string
== NULL
) ?
6353 NULL
: savestring (cond_string
, strlen (cond_string
));
6355 b
->addr_string
= trigger_func_name
;
6356 b
->enable_state
= bp_enabled
;
6357 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6358 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6365 /* Deal with "catch catch" and "catch throw" commands */
6368 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6369 int tempflag
, int from_tty
)
6371 char *cond_string
= NULL
;
6372 struct symtab_and_line
*sal
= NULL
;
6374 ep_skip_leading_whitespace (&arg
);
6376 cond_string
= ep_parse_optional_if_clause (&arg
);
6378 if ((*arg
!= '\0') && !isspace (*arg
))
6379 error (_("Junk at end of arguments."));
6381 if ((ex_event
!= EX_EVENT_THROW
) &&
6382 (ex_event
!= EX_EVENT_CATCH
))
6383 error (_("Unsupported or unknown exception event; cannot catch it"));
6385 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6388 warning (_("Unsupported with this platform/compiler combination."));
6391 /* Create a breakpoint struct for Ada exception catchpoints. */
6394 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6398 struct expression
*cond
,
6399 struct breakpoint_ops
*ops
,
6403 struct breakpoint
*b
;
6407 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6408 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6409 version for exception catchpoints, because two catchpoints
6410 used for different exception names will use the same address.
6411 In this case, a "breakpoint ... also set at..." warning is
6412 unproductive. Besides. the warning phrasing is also a bit
6413 inapropriate, we should use the word catchpoint, and tell
6414 the user what type of catchpoint it is. The above is good
6415 enough for now, though. */
6418 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6419 set_breakpoint_count (breakpoint_count
+ 1);
6421 b
->enable_state
= bp_enabled
;
6422 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6423 b
->number
= breakpoint_count
;
6424 b
->ignore_count
= 0;
6425 b
->loc
->cond
= cond
;
6426 b
->addr_string
= addr_string
;
6427 b
->language
= language_ada
;
6428 b
->cond_string
= cond_string
;
6429 b
->exp_string
= exp_string
;
6436 /* Implement the "catch exception" command. */
6439 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6441 struct symtab_and_line sal
;
6443 char *addr_string
= NULL
;
6444 char *exp_string
= NULL
;
6445 char *cond_string
= NULL
;
6446 struct expression
*cond
= NULL
;
6447 struct breakpoint_ops
*ops
= NULL
;
6449 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6450 &cond_string
, &cond
, &ops
);
6451 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6452 cond_string
, cond
, ops
, tempflag
,
6456 /* Implement the "catch assert" command. */
6459 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6461 struct symtab_and_line sal
;
6462 char *addr_string
= NULL
;
6463 struct breakpoint_ops
*ops
= NULL
;
6465 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6466 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6467 tempflag
, from_tty
);
6471 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6474 /* The first argument may be an event name, such as "start" or "load".
6475 If so, then handle it as such. If it doesn't match an event name,
6476 then attempt to interpret it as an exception name. (This latter is
6477 the v4.16-and-earlier GDB meaning of the "catch" command.)
6479 First, try to find the bounds of what might be an event name. */
6480 char *arg1_start
= arg
;
6484 if (arg1_start
== NULL
)
6486 /* Old behaviour was to use pre-v-4.16 syntax */
6487 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6489 /* Now, this is not allowed */
6490 error (_("Catch requires an event name."));
6493 arg1_end
= ep_find_event_name_end (arg1_start
);
6494 if (arg1_end
== NULL
)
6495 error (_("catch requires an event"));
6496 arg1_length
= arg1_end
+ 1 - arg1_start
;
6498 /* Try to match what we found against known event names. */
6499 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6501 error (_("Catch of signal not yet implemented"));
6503 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6505 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6506 tempflag
, from_tty
);
6508 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6510 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6511 tempflag
, from_tty
);
6513 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6515 error (_("Catch of thread_start not yet implemented"));
6517 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6519 error (_("Catch of thread_exit not yet implemented"));
6521 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6523 error (_("Catch of thread_join not yet implemented"));
6525 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6527 error (_("Catch of start not yet implemented"));
6529 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6531 error (_("Catch of exit not yet implemented"));
6533 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6535 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6537 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6539 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6541 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6543 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6545 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6547 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6549 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6551 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6553 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6555 error (_("Catch of stop not yet implemented"));
6557 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6559 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6562 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6564 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6567 /* This doesn't appear to be an event name */
6571 /* Pre-v.4.16 behaviour was to treat the argument
6572 as the name of an exception */
6573 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6574 /* Now this is not allowed */
6575 error (_("Unknown event kind specified for catch"));
6581 catch_command (char *arg
, int from_tty
)
6583 catch_command_1 (arg
, 0, from_tty
);
6588 tcatch_command (char *arg
, int from_tty
)
6590 catch_command_1 (arg
, 1, from_tty
);
6593 /* Delete breakpoints by address or line. */
6596 clear_command (char *arg
, int from_tty
)
6598 struct breakpoint
*b
;
6599 VEC(breakpoint_p
) *found
= 0;
6602 struct symtabs_and_lines sals
;
6603 struct symtab_and_line sal
;
6608 sals
= decode_line_spec (arg
, 1);
6613 sals
.sals
= (struct symtab_and_line
*)
6614 xmalloc (sizeof (struct symtab_and_line
));
6615 make_cleanup (xfree
, sals
.sals
);
6616 init_sal (&sal
); /* initialize to zeroes */
6617 sal
.line
= default_breakpoint_line
;
6618 sal
.symtab
= default_breakpoint_symtab
;
6619 sal
.pc
= default_breakpoint_address
;
6620 if (sal
.symtab
== 0)
6621 error (_("No source file specified."));
6629 /* We don't call resolve_sal_pc here. That's not
6630 as bad as it seems, because all existing breakpoints
6631 typically have both file/line and pc set. So, if
6632 clear is given file/line, we can match this to existing
6633 breakpoint without obtaining pc at all.
6635 We only support clearing given the address explicitly
6636 present in breakpoint table. Say, we've set breakpoint
6637 at file:line. There were several PC values for that file:line,
6638 due to optimization, all in one block.
6639 We've picked one PC value. If "clear" is issued with another
6640 PC corresponding to the same file:line, the breakpoint won't
6641 be cleared. We probably can still clear the breakpoint, but
6642 since the other PC value is never presented to user, user
6643 can only find it by guessing, and it does not seem important
6646 /* For each line spec given, delete bps which correspond
6647 to it. Do it in two passes, solely to preserve the current
6648 behavior that from_tty is forced true if we delete more than
6652 for (i
= 0; i
< sals
.nelts
; i
++)
6654 /* If exact pc given, clear bpts at that pc.
6655 If line given (pc == 0), clear all bpts on specified line.
6656 If defaulting, clear all bpts on default line
6659 defaulting sal.pc != 0 tests to do
6664 1 0 <can't happen> */
6668 /* Find all matching breakpoints and add them to
6673 /* Are we going to delete b? */
6674 if (b
->type
!= bp_none
6675 && b
->type
!= bp_watchpoint
6676 && b
->type
!= bp_hardware_watchpoint
6677 && b
->type
!= bp_read_watchpoint
6678 && b
->type
!= bp_access_watchpoint
)
6680 struct bp_location
*loc
= b
->loc
;
6681 for (; loc
; loc
= loc
->next
)
6683 int pc_match
= sal
.pc
6684 && (loc
->address
== sal
.pc
)
6685 && (!section_is_overlay (loc
->section
)
6686 || loc
->section
== sal
.section
);
6687 int line_match
= ((default_match
|| (0 == sal
.pc
))
6688 && b
->source_file
!= NULL
6689 && sal
.symtab
!= NULL
6690 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6691 && b
->line_number
== sal
.line
);
6692 if (pc_match
|| line_match
)
6701 VEC_safe_push(breakpoint_p
, found
, b
);
6704 /* Now go thru the 'found' chain and delete them. */
6705 if (VEC_empty(breakpoint_p
, found
))
6708 error (_("No breakpoint at %s."), arg
);
6710 error (_("No breakpoint at this line."));
6713 if (VEC_length(breakpoint_p
, found
) > 1)
6714 from_tty
= 1; /* Always report if deleted more than one */
6717 if (VEC_length(breakpoint_p
, found
) == 1)
6718 printf_unfiltered (_("Deleted breakpoint "));
6720 printf_unfiltered (_("Deleted breakpoints "));
6722 breakpoints_changed ();
6724 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6727 printf_unfiltered ("%d ", b
->number
);
6728 delete_breakpoint (b
);
6731 putchar_unfiltered ('\n');
6734 /* Delete breakpoint in BS if they are `delete' breakpoints and
6735 all breakpoints that are marked for deletion, whether hit or not.
6736 This is called after any breakpoint is hit, or after errors. */
6739 breakpoint_auto_delete (bpstat bs
)
6741 struct breakpoint
*b
, *temp
;
6743 for (; bs
; bs
= bs
->next
)
6744 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
->disposition
== disp_del
6746 delete_breakpoint (bs
->breakpoint_at
->owner
);
6748 ALL_BREAKPOINTS_SAFE (b
, temp
)
6750 if (b
->disposition
== disp_del_at_next_stop
)
6751 delete_breakpoint (b
);
6755 /* Remove locations of breakpoint BPT from
6756 the global list of breakpoint locations. */
6759 unlink_locations_from_global_list (struct breakpoint
*bpt
)
6761 /* This code assumes that the locations
6762 of a breakpoint are found in the global list
6763 in the same order, but not necessary adjacent. */
6764 struct bp_location
**tmp
= &bp_location_chain
;
6765 struct bp_location
*here
= bpt
->loc
;
6770 for (; *tmp
&& here
;)
6774 *tmp
= here
->global_next
;
6779 tmp
= &((*tmp
)->global_next
);
6784 /* Delete a breakpoint and clean up all traces of it in the data
6788 delete_breakpoint (struct breakpoint
*bpt
)
6790 struct breakpoint
*b
;
6792 struct bp_location
*loc
;
6794 gdb_assert (bpt
!= NULL
);
6796 /* Has this bp already been deleted? This can happen because multiple
6797 lists can hold pointers to bp's. bpstat lists are especial culprits.
6799 One example of this happening is a watchpoint's scope bp. When the
6800 scope bp triggers, we notice that the watchpoint is out of scope, and
6801 delete it. We also delete its scope bp. But the scope bp is marked
6802 "auto-deleting", and is already on a bpstat. That bpstat is then
6803 checked for auto-deleting bp's, which are deleted.
6805 A real solution to this problem might involve reference counts in bp's,
6806 and/or giving them pointers back to their referencing bpstat's, and
6807 teaching delete_breakpoint to only free a bp's storage when no more
6808 references were extent. A cheaper bandaid was chosen. */
6809 if (bpt
->type
== bp_none
)
6812 if (deprecated_delete_breakpoint_hook
)
6813 deprecated_delete_breakpoint_hook (bpt
);
6814 breakpoint_delete_event (bpt
->number
);
6816 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
6819 remove_breakpoint (loc
, mark_inserted
);
6821 free_valchain (loc
);
6826 if (loc
->function_name
)
6827 xfree (loc
->function_name
);
6830 if (breakpoint_chain
== bpt
)
6831 breakpoint_chain
= bpt
->next
;
6836 b
->next
= bpt
->next
;
6840 unlink_locations_from_global_list (bpt
);
6842 check_duplicates (bpt
);
6844 if (bpt
->type
!= bp_hardware_watchpoint
6845 && bpt
->type
!= bp_read_watchpoint
6846 && bpt
->type
!= bp_access_watchpoint
6847 && bpt
->type
!= bp_catch_fork
6848 && bpt
->type
!= bp_catch_vfork
6849 && bpt
->type
!= bp_catch_exec
)
6850 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
6852 /* If this breakpoint location was inserted, and there is
6853 another breakpoint at the same address, we need to
6854 insert the other breakpoint. */
6857 struct bp_location
*loc2
;
6858 ALL_BP_LOCATIONS (loc2
)
6859 if (loc2
->address
== loc
->address
6860 && loc2
->section
== loc
->section
6862 && loc2
->owner
->enable_state
!= bp_disabled
6864 && !loc2
->shlib_disabled
6865 && loc2
->owner
->enable_state
!= bp_call_disabled
)
6869 /* We should never reach this point if there is a permanent
6870 breakpoint at the same address as the one being deleted.
6871 If there is a permanent breakpoint somewhere, it should
6872 always be the only one inserted. */
6873 if (loc2
->owner
->enable_state
== bp_permanent
)
6874 internal_error (__FILE__
, __LINE__
,
6875 _("another breakpoint was inserted on top of "
6876 "a permanent breakpoint"));
6878 memset (&loc2
->target_info
, 0, sizeof (loc2
->target_info
));
6879 loc2
->target_info
.placed_address
= loc2
->address
;
6880 if (b
->type
== bp_hardware_breakpoint
)
6881 val
= target_insert_hw_breakpoint (&loc2
->target_info
);
6883 val
= target_insert_breakpoint (&loc2
->target_info
);
6885 /* If there was an error in the insert, print a message, then stop execution. */
6888 struct ui_file
*tmp_error_stream
= mem_fileopen ();
6889 make_cleanup_ui_file_delete (tmp_error_stream
);
6892 if (b
->type
== bp_hardware_breakpoint
)
6894 fprintf_unfiltered (tmp_error_stream
,
6895 "Cannot insert hardware breakpoint %d.\n"
6896 "You may have requested too many hardware breakpoints.\n",
6901 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
6902 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
6903 fputs_filtered (paddress (loc2
->address
),
6905 fprintf_filtered (tmp_error_stream
, ": %s.\n",
6906 safe_strerror (val
));
6909 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
6910 target_terminal_ours_for_output ();
6911 error_stream(tmp_error_stream
);
6919 free_command_lines (&bpt
->commands
);
6920 if (bpt
->cond_string
!= NULL
)
6921 xfree (bpt
->cond_string
);
6922 if (bpt
->addr_string
!= NULL
)
6923 xfree (bpt
->addr_string
);
6924 if (bpt
->exp
!= NULL
)
6926 if (bpt
->exp_string
!= NULL
)
6927 xfree (bpt
->exp_string
);
6928 if (bpt
->val
!= NULL
)
6929 value_free (bpt
->val
);
6930 if (bpt
->source_file
!= NULL
)
6931 xfree (bpt
->source_file
);
6932 if (bpt
->dll_pathname
!= NULL
)
6933 xfree (bpt
->dll_pathname
);
6934 if (bpt
->triggered_dll_pathname
!= NULL
)
6935 xfree (bpt
->triggered_dll_pathname
);
6936 if (bpt
->exec_pathname
!= NULL
)
6937 xfree (bpt
->exec_pathname
);
6939 /* Be sure no bpstat's are pointing at it after it's been freed. */
6940 /* FIXME, how can we find all bpstat's?
6941 We just check stop_bpstat for now. Note that we cannot just
6942 remove bpstats pointing at bpt from the stop_bpstat list
6943 entirely, as breakpoint commands are associated with the bpstat;
6944 if we remove it here, then the later call to
6945 bpstat_do_actions (&stop_bpstat);
6946 in event-top.c won't do anything, and temporary breakpoints
6947 with commands won't work. */
6948 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
6949 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
6951 bs
->breakpoint_at
= NULL
;
6953 /* bs->commands will be freed later. */
6955 /* On the chance that someone will soon try again to delete this same
6956 bp, we mark it as deleted before freeing its storage. */
6957 bpt
->type
= bp_none
;
6959 for (loc
= bpt
->loc
; loc
;)
6961 struct bp_location
*loc_next
= loc
->next
;
6969 do_delete_breakpoint_cleanup (void *b
)
6971 delete_breakpoint (b
);
6975 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
6977 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
6981 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
6983 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
6987 delete_command (char *arg
, int from_tty
)
6989 struct breakpoint
*b
, *temp
;
6995 int breaks_to_delete
= 0;
6997 /* Delete all breakpoints if no argument.
6998 Do not delete internal or call-dummy breakpoints, these
6999 have to be deleted with an explicit breakpoint number argument. */
7002 if (b
->type
!= bp_call_dummy
&&
7003 b
->type
!= bp_shlib_event
&&
7004 b
->type
!= bp_thread_event
&&
7005 b
->type
!= bp_overlay_event
&&
7008 breaks_to_delete
= 1;
7013 /* Ask user only if there are some breakpoints to delete. */
7015 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7017 ALL_BREAKPOINTS_SAFE (b
, temp
)
7019 if (b
->type
!= bp_call_dummy
&&
7020 b
->type
!= bp_shlib_event
&&
7021 b
->type
!= bp_thread_event
&&
7022 b
->type
!= bp_overlay_event
&&
7024 delete_breakpoint (b
);
7029 map_breakpoint_numbers (arg
, delete_breakpoint
);
7033 all_locations_are_pending (struct bp_location
*loc
)
7035 for (; loc
; loc
= loc
->next
)
7036 if (!loc
->shlib_disabled
)
7042 update_breakpoint_locations (struct breakpoint
*b
,
7043 struct symtabs_and_lines sals
)
7047 struct bp_location
*existing_locations
= b
->loc
;
7049 /* If there's no new locations, and all existing locations
7050 are pending, don't do anything. This optimizes
7051 the common case where all locations are in the same
7052 shared library, that was unloaded. We'd like to
7053 retain the location, so that when the library
7054 is loaded again, we don't loose the enabled/disabled
7055 status of the individual locations. */
7056 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7059 unlink_locations_from_global_list (b
);
7062 for (i
= 0; i
< sals
.nelts
; ++i
)
7064 struct bp_location
*new_loc
=
7065 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7067 /* Reparse conditions, they might contain references to the
7069 if (b
->cond_string
!= NULL
)
7071 struct gdb_exception e
;
7074 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7076 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7081 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7082 b
->number
, e
.message
);
7083 new_loc
->enabled
= 0;
7087 if (b
->source_file
!= NULL
)
7088 xfree (b
->source_file
);
7089 if (sals
.sals
[i
].symtab
== NULL
)
7090 b
->source_file
= NULL
;
7093 savestring (sals
.sals
[i
].symtab
->filename
,
7094 strlen (sals
.sals
[i
].symtab
->filename
));
7096 if (b
->line_number
== 0)
7097 b
->line_number
= sals
.sals
[i
].line
;
7100 /* If possible, carry over 'disable' status from existing breakpoints. */
7102 struct bp_location
*e
= existing_locations
;
7103 for (; e
; e
= e
->next
)
7105 if (!e
->enabled
&& e
->function_name
)
7107 struct bp_location
*l
= b
->loc
;
7108 for (; l
; l
= l
->next
)
7109 if (l
->function_name
7110 && strcmp (e
->function_name
, l
->function_name
) == 0)
7119 while (existing_locations
)
7121 struct bp_location
*next
= existing_locations
->next
;
7122 free_bp_location (existing_locations
);
7123 existing_locations
= next
;
7128 /* Reset a breakpoint given it's struct breakpoint * BINT.
7129 The value we return ends up being the return value from catch_errors.
7130 Unused in this case. */
7133 breakpoint_re_set_one (void *bint
)
7135 /* get past catch_errs */
7136 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7140 int *not_found_ptr
= ¬_found
;
7141 struct symtabs_and_lines sals
= {};
7142 struct symtabs_and_lines expanded
;
7144 enum enable_state save_enable
;
7145 struct gdb_exception e
;
7151 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7155 case bp_hardware_breakpoint
:
7157 case bp_catch_unload
:
7158 if (b
->addr_string
== NULL
)
7160 /* Anything without a string can't be re-set. */
7161 delete_breakpoint (b
);
7165 set_language (b
->language
);
7166 input_radix
= b
->input_radix
;
7168 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7170 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7175 int not_found_and_ok
= 0;
7176 /* For pending breakpoints, it's expected that parsing
7177 will fail until the right shared library is loaded.
7178 User has already told to create pending breakpoints and
7179 don't need extra messages. If breakpoint is in bp_shlib_disabled
7180 state, then user already saw the message about that breakpoint
7181 being disabled, and don't want to see more errors. */
7183 && (b
->condition_not_parsed
7184 || (b
->loc
&& b
->loc
->shlib_disabled
)
7185 || b
->enable_state
== bp_disabled
))
7186 not_found_and_ok
= 1;
7188 if (!not_found_and_ok
)
7190 /* We surely don't want to warn about the same breakpoint
7191 10 times. One solution, implemented here, is disable
7192 the breakpoint on error. Another solution would be to
7193 have separate 'warning emitted' flag. Since this
7194 happens only when a binary has changed, I don't know
7195 which approach is better. */
7196 b
->enable_state
= bp_disabled
;
7197 throw_exception (e
);
7204 gdb_assert (sals
.nelts
== 1);
7205 resolve_sal_pc (&sals
.sals
[0]);
7206 if (b
->condition_not_parsed
&& s
&& s
[0])
7208 char *cond_string
= 0;
7210 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7211 &cond_string
, &thread
);
7213 b
->cond_string
= cond_string
;
7215 b
->condition_not_parsed
= 0;
7217 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7218 update_breakpoint_locations (b
, expanded
);
7220 /* Now that this is re-enabled, check_duplicates
7222 check_duplicates (b
);
7228 case bp_hardware_watchpoint
:
7229 case bp_read_watchpoint
:
7230 case bp_access_watchpoint
:
7231 innermost_block
= NULL
;
7232 /* The issue arises of what context to evaluate this in. The
7233 same one as when it was set, but what does that mean when
7234 symbols have been re-read? We could save the filename and
7235 functionname, but if the context is more local than that, the
7236 best we could do would be something like how many levels deep
7237 and which index at that particular level, but that's going to
7238 be less stable than filenames or function names. */
7240 /* So for now, just use a global context. */
7244 /* Avoid re-freeing b->exp if an error during the call to
7245 parse_expression. */
7248 b
->exp
= parse_expression (b
->exp_string
);
7249 b
->exp_valid_block
= innermost_block
;
7250 mark
= value_mark ();
7253 value_free (b
->val
);
7254 /* Avoid re-freeing b->val if an error during the call to
7255 evaluate_expression. */
7258 b
->val
= evaluate_expression (b
->exp
);
7259 release_value (b
->val
);
7260 if (value_lazy (b
->val
) && breakpoint_enabled (b
))
7261 value_fetch_lazy (b
->val
);
7263 if (b
->cond_string
!= NULL
)
7268 xfree (b
->loc
->cond
);
7269 /* Avoid re-freeing b->exp if an error during the call
7271 b
->loc
->cond
= NULL
;
7273 b
->loc
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
7275 if (breakpoint_enabled (b
))
7277 value_free_to_mark (mark
);
7279 /* We needn't really do anything to reset these, since the mask
7280 that requests them is unaffected by e.g., new libraries being
7283 case bp_catch_vfork
:
7288 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7290 /* Delete longjmp and overlay event breakpoints; they will be
7291 reset later by breakpoint_re_set. */
7293 case bp_longjmp_resume
:
7294 case bp_overlay_event
:
7295 delete_breakpoint (b
);
7298 /* This breakpoint is special, it's set up when the inferior
7299 starts and we really don't want to touch it. */
7300 case bp_shlib_event
:
7302 /* Like bp_shlib_event, this breakpoint type is special.
7303 Once it is set up, we do not want to touch it. */
7304 case bp_thread_event
:
7306 /* Keep temporary breakpoints, which can be encountered when we step
7307 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7308 Otherwise these should have been blown away via the cleanup chain
7309 or by breakpoint_init_inferior when we rerun the executable. */
7312 case bp_watchpoint_scope
:
7314 case bp_step_resume
:
7321 /* Re-set all breakpoints after symbols have been re-loaded. */
7323 breakpoint_re_set (void)
7325 struct breakpoint
*b
, *temp
;
7326 enum language save_language
;
7327 int save_input_radix
;
7329 save_language
= current_language
->la_language
;
7330 save_input_radix
= input_radix
;
7331 ALL_BREAKPOINTS_SAFE (b
, temp
)
7333 /* Format possible error msg */
7334 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7336 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7337 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7338 do_cleanups (cleanups
);
7340 set_language (save_language
);
7341 input_radix
= save_input_radix
;
7343 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
7345 create_longjmp_breakpoint ("longjmp");
7346 create_longjmp_breakpoint ("_longjmp");
7347 create_longjmp_breakpoint ("siglongjmp");
7348 create_longjmp_breakpoint ("_siglongjmp");
7349 create_longjmp_breakpoint (NULL
);
7352 create_overlay_event_breakpoint ("_ovly_debug_event");
7355 /* Reset the thread number of this breakpoint:
7357 - If the breakpoint is for all threads, leave it as-is.
7358 - Else, reset it to the current thread for inferior_ptid. */
7360 breakpoint_re_set_thread (struct breakpoint
*b
)
7362 if (b
->thread
!= -1)
7364 if (in_thread_list (inferior_ptid
))
7365 b
->thread
= pid_to_thread_id (inferior_ptid
);
7369 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7370 If from_tty is nonzero, it prints a message to that effect,
7371 which ends with a period (no newline). */
7374 set_ignore_count (int bptnum
, int count
, int from_tty
)
7376 struct breakpoint
*b
;
7382 if (b
->number
== bptnum
)
7384 b
->ignore_count
= count
;
7388 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7390 else if (count
== 1)
7391 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7394 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7397 breakpoints_changed ();
7398 breakpoint_modify_event (b
->number
);
7402 error (_("No breakpoint number %d."), bptnum
);
7405 /* Clear the ignore counts of all breakpoints. */
7407 breakpoint_clear_ignore_counts (void)
7409 struct breakpoint
*b
;
7412 b
->ignore_count
= 0;
7415 /* Command to set ignore-count of breakpoint N to COUNT. */
7418 ignore_command (char *args
, int from_tty
)
7424 error_no_arg (_("a breakpoint number"));
7426 num
= get_number (&p
);
7428 error (_("bad breakpoint number: '%s'"), args
);
7430 error (_("Second argument (specified ignore-count) is missing."));
7432 set_ignore_count (num
,
7433 longest_to_int (value_as_long (parse_and_eval (p
))),
7436 printf_filtered ("\n");
7439 /* Call FUNCTION on each of the breakpoints
7440 whose numbers are given in ARGS. */
7443 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7448 struct breakpoint
*b
, *tmp
;
7452 error_no_arg (_("one or more breakpoint numbers"));
7459 num
= get_number_or_range (&p1
);
7462 warning (_("bad breakpoint number at or near '%s'"), p
);
7466 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7467 if (b
->number
== num
)
7469 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7472 if (related_breakpoint
)
7473 function (related_breakpoint
);
7477 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7483 static struct bp_location
*
7484 find_location_by_number (char *number
)
7486 char *dot
= strchr (number
, '.');
7490 struct breakpoint
*b
;
7491 struct bp_location
*loc
;
7496 bp_num
= get_number_or_range (&p1
);
7498 error (_("Bad breakpoint number '%s'"), number
);
7501 if (b
->number
== bp_num
)
7506 if (!b
|| b
->number
!= bp_num
)
7507 error (_("Bad breakpoint number '%s'"), number
);
7510 loc_num
= get_number_or_range (&p1
);
7512 error (_("Bad breakpoint location number '%s'"), number
);
7516 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7519 error (_("Bad breakpoint location number '%s'"), dot
+1);
7525 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7526 If from_tty is nonzero, it prints a message to that effect,
7527 which ends with a period (no newline). */
7530 disable_breakpoint (struct breakpoint
*bpt
)
7532 /* Never disable a watchpoint scope breakpoint; we want to
7533 hit them when we leave scope so we can delete both the
7534 watchpoint and its scope breakpoint at that time. */
7535 if (bpt
->type
== bp_watchpoint_scope
)
7538 /* You can't disable permanent breakpoints. */
7539 if (bpt
->enable_state
== bp_permanent
)
7542 bpt
->enable_state
= bp_disabled
;
7544 check_duplicates (bpt
);
7546 if (deprecated_modify_breakpoint_hook
)
7547 deprecated_modify_breakpoint_hook (bpt
);
7548 breakpoint_modify_event (bpt
->number
);
7552 disable_command (char *args
, int from_tty
)
7554 struct breakpoint
*bpt
;
7556 ALL_BREAKPOINTS (bpt
)
7560 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7565 case bp_catch_unload
:
7567 case bp_catch_vfork
:
7569 case bp_hardware_breakpoint
:
7571 case bp_hardware_watchpoint
:
7572 case bp_read_watchpoint
:
7573 case bp_access_watchpoint
:
7574 disable_breakpoint (bpt
);
7578 else if (strchr (args
, '.'))
7580 struct bp_location
*loc
= find_location_by_number (args
);
7583 check_duplicates (loc
->owner
);
7586 map_breakpoint_numbers (args
, disable_breakpoint
);
7590 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7592 int target_resources_ok
, other_type_used
;
7595 if (bpt
->type
== bp_hardware_breakpoint
)
7598 i
= hw_breakpoint_used_count ();
7599 target_resources_ok
=
7600 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7602 if (target_resources_ok
== 0)
7603 error (_("No hardware breakpoint support in the target."));
7604 else if (target_resources_ok
< 0)
7605 error (_("Hardware breakpoints used exceeds limit."));
7608 if (bpt
->type
== bp_watchpoint
||
7609 bpt
->type
== bp_hardware_watchpoint
||
7610 bpt
->type
== bp_read_watchpoint
||
7611 bpt
->type
== bp_access_watchpoint
)
7613 struct frame_id saved_frame_id
;
7615 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7616 if (bpt
->exp_valid_block
!= NULL
)
7618 struct frame_info
*fr
=
7619 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7622 printf_filtered (_("\
7623 Cannot enable watchpoint %d because the block in which its expression\n\
7624 is valid is not currently in scope.\n"), bpt
->number
);
7631 value_free (bpt
->val
);
7632 mark
= value_mark ();
7633 bpt
->val
= evaluate_expression (bpt
->exp
);
7634 release_value (bpt
->val
);
7635 if (value_lazy (bpt
->val
))
7636 value_fetch_lazy (bpt
->val
);
7638 if (bpt
->type
== bp_hardware_watchpoint
||
7639 bpt
->type
== bp_read_watchpoint
||
7640 bpt
->type
== bp_access_watchpoint
)
7642 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7643 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7645 /* Hack around 'unused var' error for some targets here */
7646 (void) mem_cnt
, (void) i
;
7647 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7648 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7649 /* we can consider of type is bp_hardware_watchpoint, convert to
7650 bp_watchpoint in the following condition */
7651 if (target_resources_ok
< 0)
7653 printf_filtered (_("\
7654 Cannot enable watchpoint %d because target watch resources\n\
7655 have been allocated for other watchpoints.\n"), bpt
->number
);
7656 value_free_to_mark (mark
);
7661 select_frame (frame_find_by_id (saved_frame_id
));
7662 value_free_to_mark (mark
);
7665 if (bpt
->enable_state
!= bp_permanent
)
7666 bpt
->enable_state
= bp_enabled
;
7667 bpt
->disposition
= disposition
;
7668 check_duplicates (bpt
);
7669 breakpoints_changed ();
7671 if (deprecated_modify_breakpoint_hook
)
7672 deprecated_modify_breakpoint_hook (bpt
);
7673 breakpoint_modify_event (bpt
->number
);
7678 enable_breakpoint (struct breakpoint
*bpt
)
7680 do_enable_breakpoint (bpt
, bpt
->disposition
);
7683 /* The enable command enables the specified breakpoints (or all defined
7684 breakpoints) so they once again become (or continue to be) effective
7685 in stopping the inferior. */
7688 enable_command (char *args
, int from_tty
)
7690 struct breakpoint
*bpt
;
7692 ALL_BREAKPOINTS (bpt
)
7696 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7701 case bp_catch_unload
:
7703 case bp_catch_vfork
:
7705 case bp_hardware_breakpoint
:
7707 case bp_hardware_watchpoint
:
7708 case bp_read_watchpoint
:
7709 case bp_access_watchpoint
:
7710 enable_breakpoint (bpt
);
7714 else if (strchr (args
, '.'))
7716 struct bp_location
*loc
= find_location_by_number (args
);
7719 check_duplicates (loc
->owner
);
7722 map_breakpoint_numbers (args
, enable_breakpoint
);
7726 enable_once_breakpoint (struct breakpoint
*bpt
)
7728 do_enable_breakpoint (bpt
, disp_disable
);
7732 enable_once_command (char *args
, int from_tty
)
7734 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7738 enable_delete_breakpoint (struct breakpoint
*bpt
)
7740 do_enable_breakpoint (bpt
, disp_del
);
7744 enable_delete_command (char *args
, int from_tty
)
7746 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7750 set_breakpoint_cmd (char *args
, int from_tty
)
7755 show_breakpoint_cmd (char *args
, int from_tty
)
7759 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7761 struct symtabs_and_lines
7762 decode_line_spec_1 (char *string
, int funfirstline
)
7764 struct symtabs_and_lines sals
;
7766 error (_("Empty line specification."));
7767 if (default_breakpoint_valid
)
7768 sals
= decode_line_1 (&string
, funfirstline
,
7769 default_breakpoint_symtab
,
7770 default_breakpoint_line
,
7771 (char ***) NULL
, NULL
);
7773 sals
= decode_line_1 (&string
, funfirstline
,
7774 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7776 error (_("Junk at end of line specification: %s"), string
);
7780 /* Create and insert a raw software breakpoint at PC. Return an
7781 identifier, which should be used to remove the breakpoint later.
7782 In general, places which call this should be using something on the
7783 breakpoint chain instead; this function should be eliminated
7787 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7789 struct bp_target_info
*bp_tgt
;
7791 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7792 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7794 bp_tgt
->placed_address
= pc
;
7795 if (target_insert_breakpoint (bp_tgt
) != 0)
7797 /* Could not insert the breakpoint. */
7805 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7808 deprecated_remove_raw_breakpoint (void *bp
)
7810 struct bp_target_info
*bp_tgt
= bp
;
7813 ret
= target_remove_breakpoint (bp_tgt
);
7819 /* One (or perhaps two) breakpoints used for software single stepping. */
7821 static void *single_step_breakpoints
[2];
7823 /* Create and insert a breakpoint for software single step. */
7826 insert_single_step_breakpoint (CORE_ADDR next_pc
)
7830 if (single_step_breakpoints
[0] == NULL
)
7831 bpt_p
= &single_step_breakpoints
[0];
7834 gdb_assert (single_step_breakpoints
[1] == NULL
);
7835 bpt_p
= &single_step_breakpoints
[1];
7838 /* NOTE drow/2006-04-11: A future improvement to this function would be
7839 to only create the breakpoints once, and actually put them on the
7840 breakpoint chain. That would let us use set_raw_breakpoint. We could
7841 adjust the addresses each time they were needed. Doing this requires
7842 corresponding changes elsewhere where single step breakpoints are
7843 handled, however. So, for now, we use this. */
7845 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
7847 error (_("Could not insert single-step breakpoint at 0x%s"),
7848 paddr_nz (next_pc
));
7851 /* Remove and delete any breakpoints used for software single step. */
7854 remove_single_step_breakpoints (void)
7856 gdb_assert (single_step_breakpoints
[0] != NULL
);
7858 /* See insert_single_step_breakpoint for more about this deprecated
7860 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
7861 single_step_breakpoints
[0] = NULL
;
7863 if (single_step_breakpoints
[1] != NULL
)
7865 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
7866 single_step_breakpoints
[1] = NULL
;
7870 /* Check whether a software single-step breakpoint is inserted at PC. */
7873 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
7877 for (i
= 0; i
< 2; i
++)
7879 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
7880 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
7888 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
7889 It is defined as a macro to prevent duplication.
7890 COMMAND should be a string constant containing the name of the command. */
7891 #define BREAK_ARGS_HELP(command) \
7892 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
7893 LOCATION may be a line number, function name, or \"*\" and an address.\n\
7894 If a line number is specified, break at start of code for that line.\n\
7895 If a function is specified, break at start of code for that function.\n\
7896 If an address is specified, break at that exact address.\n\
7897 With no LOCATION, uses current execution address of selected stack frame.\n\
7898 This is useful for breaking on return to a stack frame.\n\
7900 THREADNUM is the number from \"info threads\".\n\
7901 CONDITION is a boolean expression.\n\
7903 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7905 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
7908 _initialize_breakpoint (void)
7910 static struct cmd_list_element
*breakpoint_set_cmdlist
;
7911 static struct cmd_list_element
*breakpoint_show_cmdlist
;
7912 struct cmd_list_element
*c
;
7914 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
7916 breakpoint_chain
= 0;
7917 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7918 before a breakpoint is set. */
7919 breakpoint_count
= 0;
7921 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
7922 Set ignore-count of breakpoint number N to COUNT.\n\
7923 Usage is `ignore N COUNT'."));
7925 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7927 add_com ("commands", class_breakpoint
, commands_command
, _("\
7928 Set commands to be executed when a breakpoint is hit.\n\
7929 Give breakpoint number as argument after \"commands\".\n\
7930 With no argument, the targeted breakpoint is the last one set.\n\
7931 The commands themselves follow starting on the next line.\n\
7932 Type a line containing \"end\" to indicate the end of them.\n\
7933 Give \"silent\" as the first line to make the breakpoint silent;\n\
7934 then no output is printed when it is hit, except what the commands print."));
7936 add_com ("condition", class_breakpoint
, condition_command
, _("\
7937 Specify breakpoint number N to break only if COND is true.\n\
7938 Usage is `condition N COND', where N is an integer and COND is an\n\
7939 expression to be evaluated whenever breakpoint N is reached."));
7941 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
7942 Set a temporary breakpoint.\n\
7943 Like \"break\" except the breakpoint is only temporary,\n\
7944 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7945 by using \"enable delete\" on the breakpoint number.\n\
7947 BREAK_ARGS_HELP ("tbreak")));
7948 set_cmd_completer (c
, location_completer
);
7950 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
7951 Set a hardware assisted breakpoint.\n\
7952 Like \"break\" except the breakpoint requires hardware support,\n\
7953 some target hardware may not have this support.\n\
7955 BREAK_ARGS_HELP ("hbreak")));
7956 set_cmd_completer (c
, location_completer
);
7958 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
7959 Set a temporary hardware assisted breakpoint.\n\
7960 Like \"hbreak\" except the breakpoint is only temporary,\n\
7961 so it will be deleted when hit.\n\
7963 BREAK_ARGS_HELP ("thbreak")));
7964 set_cmd_completer (c
, location_completer
);
7966 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
7967 Enable some breakpoints.\n\
7968 Give breakpoint numbers (separated by spaces) as arguments.\n\
7969 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7970 This is used to cancel the effect of the \"disable\" command.\n\
7971 With a subcommand you can enable temporarily."),
7972 &enablelist
, "enable ", 1, &cmdlist
);
7974 add_com ("ab", class_breakpoint
, enable_command
, _("\
7975 Enable some breakpoints.\n\
7976 Give breakpoint numbers (separated by spaces) as arguments.\n\
7977 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7978 This is used to cancel the effect of the \"disable\" command.\n\
7979 With a subcommand you can enable temporarily."));
7981 add_com_alias ("en", "enable", class_breakpoint
, 1);
7983 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
7984 Enable some breakpoints.\n\
7985 Give breakpoint numbers (separated by spaces) as arguments.\n\
7986 This is used to cancel the effect of the \"disable\" command.\n\
7987 May be abbreviated to simply \"enable\".\n"),
7988 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
7990 add_cmd ("once", no_class
, enable_once_command
, _("\
7991 Enable breakpoints for one hit. Give breakpoint numbers.\n\
7992 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
7995 add_cmd ("delete", no_class
, enable_delete_command
, _("\
7996 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7997 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8000 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8001 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8002 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8005 add_cmd ("once", no_class
, enable_once_command
, _("\
8006 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8007 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8010 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8011 Disable some breakpoints.\n\
8012 Arguments are breakpoint numbers with spaces in between.\n\
8013 To disable all breakpoints, give no argument.\n\
8014 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8015 &disablelist
, "disable ", 1, &cmdlist
);
8016 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8017 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8019 add_com ("sb", class_breakpoint
, disable_command
, _("\
8020 Disable some breakpoints.\n\
8021 Arguments are breakpoint numbers with spaces in between.\n\
8022 To disable all breakpoints, give no argument.\n\
8023 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8025 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8026 Disable some breakpoints.\n\
8027 Arguments are breakpoint numbers with spaces in between.\n\
8028 To disable all breakpoints, give no argument.\n\
8029 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8030 This command may be abbreviated \"disable\"."),
8033 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8034 Delete some breakpoints or auto-display expressions.\n\
8035 Arguments are breakpoint numbers with spaces in between.\n\
8036 To delete all breakpoints, give no argument.\n\
8038 Also a prefix command for deletion of other GDB objects.\n\
8039 The \"unset\" command is also an alias for \"delete\"."),
8040 &deletelist
, "delete ", 1, &cmdlist
);
8041 add_com_alias ("d", "delete", class_breakpoint
, 1);
8042 add_com_alias ("del", "delete", class_breakpoint
, 1);
8044 add_com ("db", class_breakpoint
, delete_command
, _("\
8045 Delete some breakpoints.\n\
8046 Arguments are breakpoint numbers with spaces in between.\n\
8047 To delete all breakpoints, give no argument.\n"));
8049 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8050 Delete some breakpoints or auto-display expressions.\n\
8051 Arguments are breakpoint numbers with spaces in between.\n\
8052 To delete all breakpoints, give no argument.\n\
8053 This command may be abbreviated \"delete\"."),
8056 add_com ("clear", class_breakpoint
, clear_command
, _("\
8057 Clear breakpoint at specified line or function.\n\
8058 Argument may be line number, function name, or \"*\" and an address.\n\
8059 If line number is specified, all breakpoints in that line are cleared.\n\
8060 If function is specified, breakpoints at beginning of function are cleared.\n\
8061 If an address is specified, breakpoints at that address are cleared.\n\
8063 With no argument, clears all breakpoints in the line that the selected frame\n\
8066 See also the \"delete\" command which clears breakpoints by number."));
8068 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8069 Set breakpoint at specified line or function.\n"
8070 BREAK_ARGS_HELP ("break")));
8071 set_cmd_completer (c
, location_completer
);
8073 add_com_alias ("b", "break", class_run
, 1);
8074 add_com_alias ("br", "break", class_run
, 1);
8075 add_com_alias ("bre", "break", class_run
, 1);
8076 add_com_alias ("brea", "break", class_run
, 1);
8080 add_com_alias ("ba", "break", class_breakpoint
, 1);
8081 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8086 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8087 Break in function/address or break at a line in the current file."),
8088 &stoplist
, "stop ", 1, &cmdlist
);
8089 add_cmd ("in", class_breakpoint
, stopin_command
,
8090 _("Break in function or address."), &stoplist
);
8091 add_cmd ("at", class_breakpoint
, stopat_command
,
8092 _("Break at a line in the current file."), &stoplist
);
8093 add_com ("status", class_info
, breakpoints_info
, _("\
8094 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8095 The \"Type\" column indicates one of:\n\
8096 \tbreakpoint - normal breakpoint\n\
8097 \twatchpoint - watchpoint\n\
8098 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8099 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8100 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8101 address and file/line number respectively.\n\
8103 Convenience variable \"$_\" and default examine address for \"x\"\n\
8104 are set to the address of the last breakpoint listed unless the command\n\
8105 is prefixed with \"server \".\n\n\
8106 Convenience variable \"$bpnum\" contains the number of the last\n\
8110 add_info ("breakpoints", breakpoints_info
, _("\
8111 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8112 The \"Type\" column indicates one of:\n\
8113 \tbreakpoint - normal breakpoint\n\
8114 \twatchpoint - watchpoint\n\
8115 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8116 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8117 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8118 address and file/line number respectively.\n\
8120 Convenience variable \"$_\" and default examine address for \"x\"\n\
8121 are set to the address of the last breakpoint listed unless the command\n\
8122 is prefixed with \"server \".\n\n\
8123 Convenience variable \"$bpnum\" contains the number of the last\n\
8127 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8128 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8129 The \"Type\" column indicates one of:\n\
8130 \tbreakpoint - normal breakpoint\n\
8131 \twatchpoint - watchpoint\n\
8132 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8133 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8134 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8135 address and file/line number respectively.\n\
8137 Convenience variable \"$_\" and default examine address for \"x\"\n\
8138 are set to the address of the last breakpoint listed unless the command\n\
8139 is prefixed with \"server \".\n\n\
8140 Convenience variable \"$bpnum\" contains the number of the last\n\
8143 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8144 Status of all breakpoints, or breakpoint number NUMBER.\n\
8145 The \"Type\" column indicates one of:\n\
8146 \tbreakpoint - normal breakpoint\n\
8147 \twatchpoint - watchpoint\n\
8148 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8149 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8150 \tuntil - internal breakpoint used by the \"until\" command\n\
8151 \tfinish - internal breakpoint used by the \"finish\" command\n\
8152 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8153 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8154 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8155 address and file/line number respectively.\n\
8157 Convenience variable \"$_\" and default examine address for \"x\"\n\
8158 are set to the address of the last breakpoint listed unless the command\n\
8159 is prefixed with \"server \".\n\n\
8160 Convenience variable \"$bpnum\" contains the number of the last\n\
8162 &maintenanceinfolist
);
8164 add_com ("catch", class_breakpoint
, catch_command
, _("\
8165 Set catchpoints to catch events.\n\
8166 Raised signals may be caught:\n\
8167 \tcatch signal - all signals\n\
8168 \tcatch signal <signame> - a particular signal\n\
8169 Raised exceptions may be caught:\n\
8170 \tcatch throw - all exceptions, when thrown\n\
8171 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8172 \tcatch catch - all exceptions, when caught\n\
8173 \tcatch catch <exceptname> - a particular exception, when caught\n\
8174 Thread or process events may be caught:\n\
8175 \tcatch thread_start - any threads, just after creation\n\
8176 \tcatch thread_exit - any threads, just before expiration\n\
8177 \tcatch thread_join - any threads, just after joins\n\
8178 Process events may be caught:\n\
8179 \tcatch start - any processes, just after creation\n\
8180 \tcatch exit - any processes, just before expiration\n\
8181 \tcatch fork - calls to fork()\n\
8182 \tcatch vfork - calls to vfork()\n\
8183 \tcatch exec - calls to exec()\n\
8184 Dynamically-linked library events may be caught:\n\
8185 \tcatch load - loads of any library\n\
8186 \tcatch load <libname> - loads of a particular library\n\
8187 \tcatch unload - unloads of any library\n\
8188 \tcatch unload <libname> - unloads of a particular library\n\
8189 The act of your program's execution stopping may also be caught:\n\
8191 C++ exceptions may be caught:\n\
8192 \tcatch throw - all exceptions, when thrown\n\
8193 \tcatch catch - all exceptions, when caught\n\
8194 Ada exceptions may be caught:\n\
8195 \tcatch exception - all exceptions, when raised\n\
8196 \tcatch exception <name> - a particular exception, when raised\n\
8197 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8198 \tcatch assert - all failed assertions, when raised\n\
8200 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8201 after a fork or vfork is caught.\n\n\
8202 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8204 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8205 Set temporary catchpoints to catch events.\n\
8206 Args like \"catch\" command.\n\
8207 Like \"catch\" except the catchpoint is only temporary,\n\
8208 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8209 by using \"enable delete\" on the catchpoint number."));
8211 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8212 Set a watchpoint for an expression.\n\
8213 A watchpoint stops execution of your program whenever the value of\n\
8214 an expression changes."));
8215 set_cmd_completer (c
, location_completer
);
8217 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8218 Set a read watchpoint for an expression.\n\
8219 A watchpoint stops execution of your program whenever the value of\n\
8220 an expression is read."));
8221 set_cmd_completer (c
, location_completer
);
8223 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8224 Set a watchpoint for an expression.\n\
8225 A watchpoint stops execution of your program whenever the value of\n\
8226 an expression is either read or written."));
8227 set_cmd_completer (c
, location_completer
);
8229 add_info ("watchpoints", breakpoints_info
,
8230 _("Synonym for ``info breakpoints''."));
8233 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8234 respond to changes - contrary to the description. */
8235 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8236 &can_use_hw_watchpoints
, _("\
8237 Set debugger's willingness to use watchpoint hardware."), _("\
8238 Show debugger's willingness to use watchpoint hardware."), _("\
8239 If zero, gdb will not use hardware for new watchpoints, even if\n\
8240 such is available. (However, any hardware watchpoints that were\n\
8241 created before setting this to nonzero, will continue to use watchpoint\n\
8244 show_can_use_hw_watchpoints
,
8245 &setlist
, &showlist
);
8247 can_use_hw_watchpoints
= 1;
8249 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8250 Breakpoint specific settings\n\
8251 Configure various breakpoint-specific variables such as\n\
8252 pending breakpoint behavior"),
8253 &breakpoint_set_cmdlist
, "set breakpoint ",
8254 0/*allow-unknown*/, &setlist
);
8255 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8256 Breakpoint specific settings\n\
8257 Configure various breakpoint-specific variables such as\n\
8258 pending breakpoint behavior"),
8259 &breakpoint_show_cmdlist
, "show breakpoint ",
8260 0/*allow-unknown*/, &showlist
);
8262 add_setshow_auto_boolean_cmd ("pending", no_class
,
8263 &pending_break_support
, _("\
8264 Set debugger's behavior regarding pending breakpoints."), _("\
8265 Show debugger's behavior regarding pending breakpoints."), _("\
8266 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8267 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8268 an error. If auto, an unrecognized breakpoint location results in a\n\
8269 user-query to see if a pending breakpoint should be created."),
8271 show_pending_break_support
,
8272 &breakpoint_set_cmdlist
,
8273 &breakpoint_show_cmdlist
);
8275 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8277 add_setshow_boolean_cmd ("auto-hw", no_class
,
8278 &automatic_hardware_breakpoints
, _("\
8279 Set automatic usage of hardware breakpoints."), _("\
8280 Show automatic usage of hardware breakpoints."), _("\
8281 If set, the debugger will automatically use hardware breakpoints for\n\
8282 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8283 a warning will be emitted for such breakpoints."),
8285 show_automatic_hardware_breakpoints
,
8286 &breakpoint_set_cmdlist
,
8287 &breakpoint_show_cmdlist
);
8289 automatic_hardware_breakpoints
= 1;