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 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 2 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, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
28 #include "breakpoint.h"
30 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb_string.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
55 #include "exceptions.h"
59 #include "gdb-events.h"
60 #include "mi/mi-common.h"
62 /* Prototypes for local functions. */
64 static void until_break_command_continuation (struct continuation_arg
*arg
);
66 static void catch_command_1 (char *, int, int);
68 static void enable_delete_command (char *, int);
70 static void enable_delete_breakpoint (struct breakpoint
*);
72 static void enable_once_command (char *, int);
74 static void enable_once_breakpoint (struct breakpoint
*);
76 static void disable_command (char *, int);
78 static void enable_command (char *, int);
80 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
82 static void ignore_command (char *, int);
84 static int breakpoint_re_set_one (void *);
86 static void clear_command (char *, int);
88 static void catch_command (char *, int);
90 static void watch_command (char *, int);
92 static int can_use_hardware_watchpoint (struct value
*);
94 static int break_command_1 (char *, int, int, struct breakpoint
*);
96 static void mention (struct breakpoint
*);
98 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
100 static void check_duplicates (struct breakpoint
*);
102 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
104 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
107 static void describe_other_breakpoints (CORE_ADDR
, asection
*, int);
109 static void breakpoints_info (char *, int);
111 static void breakpoint_1 (int, int);
113 static bpstat
bpstat_alloc (struct breakpoint
*, bpstat
);
115 static int breakpoint_cond_eval (void *);
117 static void cleanup_executing_breakpoints (void *);
119 static void commands_command (char *, int);
121 static void condition_command (char *, int);
123 static int get_number_trailer (char **, int);
125 void set_breakpoint_count (int);
134 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
136 static enum print_stop_action
print_it_typical (bpstat
);
138 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
142 enum exception_event_kind kind
;
145 args_for_catchpoint_enable
;
147 static int watchpoint_check (void *);
149 static int cover_target_enable_exception_callback (void *);
151 static void maintenance_info_breakpoints (char *, int);
153 static void create_longjmp_breakpoint (char *);
155 static void create_overlay_event_breakpoint (char *);
157 static int hw_breakpoint_used_count (void);
159 static int hw_watchpoint_used_count (enum bptype
, int *);
161 static void hbreak_command (char *, int);
163 static void thbreak_command (char *, int);
165 static void watch_command_1 (char *, int, int);
167 static void rwatch_command (char *, int);
169 static void awatch_command (char *, int);
171 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
173 static void solib_load_unload_1 (char *hookname
,
176 char *cond_string
, enum bptype bp_kind
);
178 static void create_fork_vfork_event_catchpoint (int tempflag
,
180 enum bptype bp_kind
);
182 static void stop_command (char *arg
, int from_tty
);
184 static void stopin_command (char *arg
, int from_tty
);
186 static void stopat_command (char *arg
, int from_tty
);
188 static char *ep_find_event_name_end (char *arg
);
190 static char *ep_parse_optional_if_clause (char **arg
);
192 static char *ep_parse_optional_filename (char **arg
);
194 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
195 enum exception_event_kind ex_event
,
196 struct symtab_and_line
*sal
);
198 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
199 char *arg
, int tempflag
, int from_tty
);
201 static void tcatch_command (char *arg
, int from_tty
);
203 static void ep_skip_leading_whitespace (char **s
);
205 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
207 /* Prototypes for exported functions. */
209 /* If FALSE, gdb will not use hardware support for watchpoints, even
210 if such is available. */
211 static int can_use_hw_watchpoints
;
214 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
215 struct cmd_list_element
*c
,
218 fprintf_filtered (file
, _("\
219 Debugger's willingness to use watchpoint hardware is %s.\n"),
223 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
224 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
225 for unrecognized breakpoint locations.
226 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
227 static enum auto_boolean pending_break_support
;
229 show_pending_break_support (struct ui_file
*file
, int from_tty
,
230 struct cmd_list_element
*c
,
233 fprintf_filtered (file
, _("\
234 Debugger's behavior regarding pending breakpoints is %s.\n"),
238 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
239 set with "break" but falling in read-only memory.
240 If 0, gdb will warn about such breakpoints, but won't automatically
241 use hardware breakpoints. */
242 static int automatic_hardware_breakpoints
;
244 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
245 struct cmd_list_element
*c
,
248 fprintf_filtered (file
, _("\
249 Automatic usage of hardware breakpoints is %s.\n"),
254 void _initialize_breakpoint (void);
256 extern int addressprint
; /* Print machine addresses? */
258 /* Are we executing breakpoint commands? */
259 static int executing_breakpoint_commands
;
261 /* Are overlay event breakpoints enabled? */
262 static int overlay_events_enabled
;
264 /* Walk the following statement or block through all breakpoints.
265 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
268 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
270 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
271 for (B = breakpoint_chain; \
272 B ? (TMP=B->next, 1): 0; \
275 /* Similar iterators for the low-level breakpoints. */
277 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->next)
279 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
280 for (B = bp_location_chain; \
281 B ? (TMP=B->next, 1): 0; \
284 /* True if breakpoint hit counts should be displayed in breakpoint info. */
286 int show_breakpoint_hit_counts
= 1;
288 /* Chains of all breakpoints defined. */
290 struct breakpoint
*breakpoint_chain
;
292 struct bp_location
*bp_location_chain
;
294 /* Number of last breakpoint made. */
296 int breakpoint_count
;
298 /* Pointer to current exception event record */
299 static struct exception_event_record
*current_exception_event
;
301 /* This function returns a pointer to the string representation of the
302 pathname of the dynamically-linked library that has just been
305 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
306 or undefined results are guaranteed.
308 This string's contents are only valid immediately after the
309 inferior has stopped in the dynamic linker hook, and becomes
310 invalid as soon as the inferior is continued. Clients should make
311 a copy of this string if they wish to continue the inferior and
312 then access the string. */
314 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
315 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
318 /* This function returns a pointer to the string representation of the
319 pathname of the dynamically-linked library that has just been
322 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
323 TRUE, or undefined results are guaranteed.
325 This string's contents are only valid immediately after the
326 inferior has stopped in the dynamic linker hook, and becomes
327 invalid as soon as the inferior is continued. Clients should make
328 a copy of this string if they wish to continue the inferior and
329 then access the string. */
331 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
332 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
335 /* This function is called by the "catch load" command. It allows the
336 debugger to be notified by the dynamic linker when a specified
337 library file (or any library file, if filename is NULL) is loaded. */
339 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
340 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
341 error (_("catch of library loads not yet implemented on this platform"))
344 /* This function is called by the "catch unload" command. It allows
345 the debugger to be notified by the dynamic linker when a specified
346 library file (or any library file, if filename is NULL) is
349 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
350 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
351 error (_("catch of library unloads not yet implemented on this platform"))
354 /* Return whether a breakpoint is an active enabled breakpoint. */
356 breakpoint_enabled (struct breakpoint
*b
)
358 return (b
->enable_state
== bp_enabled
&& !b
->pending
);
361 /* Set breakpoint count to NUM. */
364 set_breakpoint_count (int num
)
366 breakpoint_count
= num
;
367 set_internalvar (lookup_internalvar ("bpnum"),
368 value_from_longest (builtin_type_int
, (LONGEST
) num
));
371 /* Used in run_command to zero the hit count when a new run starts. */
374 clear_breakpoint_hit_counts (void)
376 struct breakpoint
*b
;
382 /* Default address, symtab and line to put a breakpoint at
383 for "break" command with no arg.
384 if default_breakpoint_valid is zero, the other three are
385 not valid, and "break" with no arg is an error.
387 This set by print_stack_frame, which calls set_default_breakpoint. */
389 int default_breakpoint_valid
;
390 CORE_ADDR default_breakpoint_address
;
391 struct symtab
*default_breakpoint_symtab
;
392 int default_breakpoint_line
;
394 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
395 Advance *PP after the string and any trailing whitespace.
397 Currently the string can either be a number or "$" followed by the name
398 of a convenience variable. Making it an expression wouldn't work well
399 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
401 If the string is a NULL pointer, that denotes the last breakpoint.
403 TRAILER is a character which can be found after the number; most
404 commonly this is `-'. If you don't want a trailer, use \0. */
406 get_number_trailer (char **pp
, int trailer
)
408 int retval
= 0; /* default */
412 /* Empty line means refer to the last breakpoint. */
413 return breakpoint_count
;
416 /* Make a copy of the name, so we can null-terminate it
417 to pass to lookup_internalvar(). */
422 while (isalnum (*p
) || *p
== '_')
424 varname
= (char *) alloca (p
- start
+ 1);
425 strncpy (varname
, start
, p
- start
);
426 varname
[p
- start
] = '\0';
427 val
= value_of_internalvar (lookup_internalvar (varname
));
428 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
429 retval
= (int) value_as_long (val
);
432 printf_filtered (_("Convenience variable must have integer value.\n"));
440 while (*p
>= '0' && *p
<= '9')
443 /* There is no number here. (e.g. "cond a == b"). */
445 /* Skip non-numeric token */
446 while (*p
&& !isspace((int) *p
))
448 /* Return zero, which caller must interpret as error. */
454 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
456 /* Trailing junk: return 0 and let caller print error msg. */
457 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
468 /* Like get_number_trailer, but don't allow a trailer. */
470 get_number (char **pp
)
472 return get_number_trailer (pp
, '\0');
475 /* Parse a number or a range.
476 * A number will be of the form handled by get_number.
477 * A range will be of the form <number1> - <number2>, and
478 * will represent all the integers between number1 and number2,
481 * While processing a range, this fuction is called iteratively;
482 * At each call it will return the next value in the range.
484 * At the beginning of parsing a range, the char pointer PP will
485 * be advanced past <number1> and left pointing at the '-' token.
486 * Subsequent calls will not advance the pointer until the range
487 * is completed. The call that completes the range will advance
488 * pointer PP past <number2>.
492 get_number_or_range (char **pp
)
494 static int last_retval
, end_value
;
495 static char *end_ptr
;
496 static int in_range
= 0;
500 /* Default case: pp is pointing either to a solo number,
501 or to the first number of a range. */
502 last_retval
= get_number_trailer (pp
, '-');
507 /* This is the start of a range (<number1> - <number2>).
508 Skip the '-', parse and remember the second number,
509 and also remember the end of the final token. */
513 while (isspace ((int) *end_ptr
))
514 end_ptr
++; /* skip white space */
515 end_value
= get_number (temp
);
516 if (end_value
< last_retval
)
518 error (_("inverted range"));
520 else if (end_value
== last_retval
)
522 /* degenerate range (number1 == number2). Advance the
523 token pointer so that the range will be treated as a
532 error (_("negative value"));
535 /* pp points to the '-' that betokens a range. All
536 number-parsing has already been done. Return the next
537 integer value (one greater than the saved previous value).
538 Do not advance the token pointer 'pp' until the end of range
541 if (++last_retval
== end_value
)
543 /* End of range reached; advance token pointer. */
553 /* condition N EXP -- set break condition of breakpoint N to EXP. */
556 condition_command (char *arg
, int from_tty
)
558 struct breakpoint
*b
;
563 error_no_arg (_("breakpoint number"));
566 bnum
= get_number (&p
);
568 error (_("Bad breakpoint argument: '%s'"), arg
);
571 if (b
->number
== bnum
)
578 if (b
->cond_string
!= NULL
)
579 xfree (b
->cond_string
);
584 b
->cond_string
= NULL
;
586 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
591 /* I don't know if it matters whether this is the string the user
592 typed in or the decompiled expression. */
593 b
->cond_string
= savestring (arg
, strlen (arg
));
596 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->loc
->address
), 0);
598 error (_("Junk at end of expression"));
601 breakpoints_changed ();
602 breakpoint_modify_event (b
->number
);
606 error (_("No breakpoint number %d."), bnum
);
610 commands_command (char *arg
, int from_tty
)
612 struct breakpoint
*b
;
615 struct command_line
*l
;
617 /* If we allowed this, we would have problems with when to
618 free the storage, if we change the commands currently
621 if (executing_breakpoint_commands
)
622 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
625 bnum
= get_number (&p
);
628 error (_("Unexpected extra arguments following breakpoint number."));
631 if (b
->number
== bnum
)
633 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
635 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
636 l
= read_command_lines (tmpbuf
, from_tty
);
637 do_cleanups (cleanups
);
638 free_command_lines (&b
->commands
);
640 breakpoints_changed ();
641 breakpoint_modify_event (b
->number
);
644 error (_("No breakpoint number %d."), bnum
);
647 /* Like commands_command, but instead of reading the commands from
648 input stream, takes them from an already parsed command structure.
650 This is used by cli-script.c to DTRT with breakpoint commands
651 that are part of if and while bodies. */
652 enum command_control_type
653 commands_from_control_command (char *arg
, struct command_line
*cmd
)
655 struct breakpoint
*b
;
659 /* If we allowed this, we would have problems with when to
660 free the storage, if we change the commands currently
663 if (executing_breakpoint_commands
)
664 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
666 /* An empty string for the breakpoint number means the last
667 breakpoint, but get_number expects a NULL pointer. */
672 bnum
= get_number (&p
);
675 error (_("Unexpected extra arguments following breakpoint number."));
678 if (b
->number
== bnum
)
680 free_command_lines (&b
->commands
);
681 if (cmd
->body_count
!= 1)
682 error (_("Invalid \"commands\" block structure."));
683 /* We need to copy the commands because if/while will free the
684 list after it finishes execution. */
685 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
686 breakpoints_changed ();
687 breakpoint_modify_event (b
->number
);
688 return simple_control
;
690 error (_("No breakpoint number %d."), bnum
);
693 /* Like target_read_memory() but if breakpoints are inserted, return
694 the shadow contents instead of the breakpoints themselves.
696 Read "memory data" from whatever target or inferior we have.
697 Returns zero if successful, errno value if not. EIO is used
698 for address out of bounds. If breakpoints are inserted, returns
699 shadow contents, not the breakpoints themselves. From breakpoint.c. */
702 read_memory_nobpt (CORE_ADDR memaddr
, gdb_byte
*myaddr
, unsigned len
)
705 struct bp_location
*b
;
706 CORE_ADDR bp_addr
= 0;
709 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
710 /* No breakpoints on this machine. */
711 return target_read_memory (memaddr
, myaddr
, len
);
715 if (b
->owner
->type
== bp_none
)
716 warning (_("reading through apparently deleted breakpoint #%d?"),
719 if (b
->loc_type
!= bp_loc_software_breakpoint
)
723 /* Addresses and length of the part of the breakpoint that
725 bp_addr
= b
->target_info
.placed_address
;
726 bp_size
= b
->target_info
.shadow_len
;
728 /* bp isn't valid, or doesn't shadow memory. */
730 if (bp_addr
+ bp_size
<= memaddr
)
731 /* The breakpoint is entirely before the chunk of memory we
734 if (bp_addr
>= memaddr
+ len
)
735 /* The breakpoint is entirely after the chunk of memory we are
738 /* Copy the breakpoint from the shadow contents, and recurse for
739 the things before and after. */
741 /* Offset within shadow_contents. */
744 if (bp_addr
< memaddr
)
746 /* Only copy the second part of the breakpoint. */
747 bp_size
-= memaddr
- bp_addr
;
748 bptoffset
= memaddr
- bp_addr
;
752 if (bp_addr
+ bp_size
> memaddr
+ len
)
754 /* Only copy the first part of the breakpoint. */
755 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
758 memcpy (myaddr
+ bp_addr
- memaddr
,
759 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
761 if (bp_addr
> memaddr
)
763 /* Copy the section of memory before the breakpoint. */
764 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
769 if (bp_addr
+ bp_size
< memaddr
+ len
)
771 /* Copy the section of memory after the breakpoint. */
772 status
= read_memory_nobpt (bp_addr
+ bp_size
,
773 myaddr
+ bp_addr
+ bp_size
- memaddr
,
774 memaddr
+ len
- (bp_addr
+ bp_size
));
781 /* Nothing overlaps. Just call read_memory_noerr. */
782 return target_read_memory (memaddr
, myaddr
, len
);
786 /* A wrapper function for inserting catchpoints. */
788 insert_catchpoint (struct ui_out
*uo
, void *args
)
790 struct breakpoint
*b
= (struct breakpoint
*) args
;
796 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
799 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
802 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
805 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
810 /* Helper routine: free the value chain for a breakpoint (watchpoint). */
813 free_valchain (struct bp_location
*b
)
818 /* Free the saved value chain. We will construct a new one
819 the next time the watchpoint is inserted. */
820 for (v
= b
->owner
->val_chain
; v
; v
= n
)
825 b
->owner
->val_chain
= NULL
;
828 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
829 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
830 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
832 NOTE drow/2003-09-09: This routine could be broken down to an object-style
833 method for each breakpoint or catchpoint type. */
835 insert_bp_location (struct bp_location
*bpt
,
836 struct ui_file
*tmp_error_stream
,
837 int *disabled_breaks
, int *process_warning
,
838 int *hw_breakpoint_error
)
842 /* Permanent breakpoints cannot be inserted or removed. Disabled
843 breakpoints should not be inserted. */
844 if (!breakpoint_enabled (bpt
->owner
))
847 if (bpt
->inserted
|| bpt
->duplicate
)
850 /* Initialize the target-specific information. */
851 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
852 bpt
->target_info
.placed_address
= bpt
->address
;
854 if (bpt
->loc_type
== bp_loc_software_breakpoint
855 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
857 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
859 /* If the explicitly specified breakpoint type
860 is not hardware breakpoint, check the memory map to see
861 if the breakpoint address is in read only memory or not.
862 Two important cases are:
863 - location type is not hardware breakpoint, memory
864 is readonly. We change the type of the location to
866 - location type is hardware breakpoint, memory is read-write.
867 This means we've previously made the location hardware one, but
868 then the memory map changed, so we undo.
870 When breakpoints are removed, remove_breakpoints will
871 use location types we've just set here, the only possible
872 problem is that memory map has changed during running program,
873 but it's not going to work anyway with current gdb. */
874 struct mem_region
*mr
875 = lookup_mem_region (bpt
->target_info
.placed_address
);
879 if (automatic_hardware_breakpoints
)
882 enum bp_loc_type new_type
;
884 if (mr
->attrib
.mode
!= MEM_RW
)
885 new_type
= bp_loc_hardware_breakpoint
;
887 new_type
= bp_loc_software_breakpoint
;
889 if (new_type
!= bpt
->loc_type
)
892 bpt
->loc_type
= new_type
;
895 fprintf_filtered (gdb_stdout
, _("\
896 Note: automatically using hardware breakpoints for read-only addresses.\n"));
901 else if (bpt
->loc_type
== bp_loc_software_breakpoint
902 && mr
->attrib
.mode
!= MEM_RW
)
903 warning (_("cannot set software breakpoint at readonly address %s"),
904 paddr (bpt
->address
));
908 /* First check to see if we have to handle an overlay. */
909 if (overlay_debugging
== ovly_off
910 || bpt
->section
== NULL
911 || !(section_is_overlay (bpt
->section
)))
913 /* No overlay handling: just set the breakpoint. */
915 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
916 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
918 val
= target_insert_breakpoint (&bpt
->target_info
);
922 /* This breakpoint is in an overlay section.
923 Shall we set a breakpoint at the LMA? */
924 if (!overlay_events_enabled
)
926 /* Yes -- overlay event support is not active,
927 so we must try to set a breakpoint at the LMA.
928 This will not work for a hardware breakpoint. */
929 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
930 warning (_("hardware breakpoint %d not supported in overlay!"),
934 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
936 /* Set a software (trap) breakpoint at the LMA. */
937 bpt
->overlay_target_info
= bpt
->target_info
;
938 bpt
->overlay_target_info
.placed_address
= addr
;
939 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
941 fprintf_unfiltered (tmp_error_stream
,
942 "Overlay breakpoint %d failed: in ROM?",
946 /* Shall we set a breakpoint at the VMA? */
947 if (section_is_mapped (bpt
->section
))
949 /* Yes. This overlay section is mapped into memory. */
950 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
951 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
953 val
= target_insert_breakpoint (&bpt
->target_info
);
957 /* No. This breakpoint will not be inserted.
958 No error, but do not mark the bp as 'inserted'. */
965 /* Can't set the breakpoint. */
967 #if defined (DISABLE_UNSETTABLE_BREAK)
968 DISABLE_UNSETTABLE_BREAK (bpt
->address
)
970 solib_address (bpt
->address
)
974 /* See also: disable_breakpoints_in_shlibs. */
976 bpt
->owner
->enable_state
= bp_shlib_disabled
;
977 if (!*disabled_breaks
)
979 fprintf_unfiltered (tmp_error_stream
,
980 "Cannot insert breakpoint %d.\n",
982 fprintf_unfiltered (tmp_error_stream
,
983 "Temporarily disabling shared library breakpoints:\n");
985 *disabled_breaks
= 1;
986 fprintf_unfiltered (tmp_error_stream
,
987 "breakpoint #%d\n", bpt
->owner
->number
);
991 #ifdef ONE_PROCESS_WRITETEXT
992 *process_warning
= 1;
994 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
996 *hw_breakpoint_error
= 1;
997 fprintf_unfiltered (tmp_error_stream
,
998 "Cannot insert hardware breakpoint %d.\n",
1003 fprintf_unfiltered (tmp_error_stream
,
1004 "Cannot insert breakpoint %d.\n",
1005 bpt
->owner
->number
);
1006 fprintf_filtered (tmp_error_stream
,
1007 "Error accessing memory address ");
1008 deprecated_print_address_numeric (bpt
->address
, 1, tmp_error_stream
);
1009 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1010 safe_strerror (val
));
1021 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1022 /* NOTE drow/2003-09-08: This state only exists for removing
1023 watchpoints. It's not clear that it's necessary... */
1024 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1026 /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints
1027 based on the expression. Ideally this should happen at a higher level,
1028 and there should be one bp_location for each computed address we
1029 must watch. As soon as a many-to-one mapping is available I'll
1032 int within_current_scope
;
1033 struct value
*mark
= value_mark ();
1035 struct frame_id saved_frame_id
;
1037 /* Save the current frame's ID so we can restore it after
1038 evaluating the watchpoint expression on its own frame. */
1039 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1040 took a frame parameter, so that we didn't have to change the
1042 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1044 /* Determine if the watchpoint is within scope. */
1045 if (bpt
->owner
->exp_valid_block
== NULL
)
1046 within_current_scope
= 1;
1049 struct frame_info
*fi
;
1050 fi
= frame_find_by_id (bpt
->owner
->watchpoint_frame
);
1051 within_current_scope
= (fi
!= NULL
);
1052 if (within_current_scope
)
1056 if (within_current_scope
)
1058 free_valchain (bpt
);
1060 /* Evaluate the expression and cut the chain of values
1061 produced off from the value chain.
1063 Make sure the value returned isn't lazy; we use
1064 laziness to determine what memory GDB actually needed
1065 in order to compute the value of the expression. */
1066 v
= evaluate_expression (bpt
->owner
->exp
);
1068 value_release_to_mark (mark
);
1070 bpt
->owner
->val_chain
= v
;
1073 /* Look at each value on the value chain. */
1074 for (; v
; v
= value_next (v
))
1076 /* If it's a memory location, and GDB actually needed
1077 its contents to evaluate the expression, then we
1079 if (VALUE_LVAL (v
) == lval_memory
1080 && ! value_lazy (v
))
1082 struct type
*vtype
= check_typedef (value_type (v
));
1084 /* We only watch structs and arrays if user asked
1085 for it explicitly, never if they just happen to
1086 appear in the middle of some value chain. */
1087 if (v
== bpt
->owner
->val_chain
1088 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1089 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1094 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
1095 len
= TYPE_LENGTH (value_type (v
));
1097 if (bpt
->owner
->type
== bp_read_watchpoint
)
1099 else if (bpt
->owner
->type
== bp_access_watchpoint
)
1102 val
= target_insert_watchpoint (addr
, len
, type
);
1105 /* Don't exit the loop, try to insert
1106 every value on the value chain. That's
1107 because we will be removing all the
1108 watches below, and removing a
1109 watchpoint we didn't insert could have
1117 /* Failure to insert a watchpoint on any memory value in the
1118 value chain brings us here. */
1121 remove_breakpoint (bpt
, mark_uninserted
);
1122 *hw_breakpoint_error
= 1;
1123 fprintf_unfiltered (tmp_error_stream
,
1124 "Could not insert hardware watchpoint %d.\n",
1125 bpt
->owner
->number
);
1131 printf_filtered (_("\
1132 Hardware watchpoint %d deleted because the program has left the block \n\
1133 in which its expression is valid.\n"),
1134 bpt
->owner
->number
);
1135 if (bpt
->owner
->related_breakpoint
)
1136 bpt
->owner
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1137 bpt
->owner
->disposition
= disp_del_at_next_stop
;
1140 /* Restore the selected frame. */
1141 select_frame (frame_find_by_id (saved_frame_id
));
1146 else if (ep_is_exception_catchpoint (bpt
->owner
))
1148 /* FIXME drow/2003-09-09: This code sets both a catchpoint and a
1149 breakpoint. Once again, it would be better if this was represented
1150 as two bp_locations. */
1152 /* If we get here, we must have a callback mechanism for exception
1153 events -- with g++ style embedded label support, we insert
1154 ordinary breakpoints and not catchpoints. */
1155 val
= target_insert_breakpoint (&bpt
->target_info
);
1158 /* Couldn't set breakpoint for some reason */
1159 fprintf_unfiltered (tmp_error_stream
,
1160 "Cannot insert catchpoint %d; disabling it.\n",
1161 bpt
->owner
->number
);
1162 fprintf_filtered (tmp_error_stream
,
1163 "Error accessing memory address ");
1164 deprecated_print_address_numeric (bpt
->address
, 1, tmp_error_stream
);
1165 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1166 safe_strerror (val
));
1167 bpt
->owner
->enable_state
= bp_disabled
;
1171 /* Bp set, now make sure callbacks are enabled */
1172 /* Format possible error msg */
1173 char *message
= xstrprintf ("Error inserting catchpoint %d:\n",
1174 bpt
->owner
->number
);
1175 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
1177 args_for_catchpoint_enable args
;
1178 args
.kind
= bpt
->owner
->type
== bp_catch_catch
?
1179 EX_EVENT_CATCH
: EX_EVENT_THROW
;
1181 val
= catch_errors (cover_target_enable_exception_callback
,
1182 &args
, message
, RETURN_MASK_ALL
);
1183 do_cleanups (cleanups
);
1184 if (val
!= 0 && val
!= -1)
1187 /* Check if something went wrong; val == 0 can be ignored */
1190 /* something went wrong */
1191 fprintf_unfiltered (tmp_error_stream
,
1192 "Cannot insert catchpoint %d; disabling it.\n",
1193 bpt
->owner
->number
);
1194 bpt
->owner
->enable_state
= bp_disabled
;
1201 else if (bpt
->owner
->type
== bp_catch_fork
1202 || bpt
->owner
->type
== bp_catch_vfork
1203 || bpt
->owner
->type
== bp_catch_exec
)
1205 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1206 bpt
->owner
, RETURN_MASK_ERROR
);
1207 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1208 bpt
->owner
->number
);
1210 bpt
->owner
->enable_state
= bp_disabled
;
1214 /* We've already printed an error message if there was a problem
1215 inserting this catchpoint, and we've disabled the catchpoint,
1216 so just return success. */
1223 /* insert_breakpoints is used when starting or continuing the program.
1224 remove_breakpoints is used when the program stops.
1225 Both return zero if successful,
1226 or an `errno' value if could not write the inferior. */
1229 insert_breakpoints (void)
1231 struct bp_location
*b
, *temp
;
1232 int return_val
= 0; /* return success code. */
1234 int disabled_breaks
= 0;
1235 int hw_breakpoint_error
= 0;
1236 int process_warning
= 0;
1238 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1239 make_cleanup_ui_file_delete (tmp_error_stream
);
1241 /* Explicitly mark the warning -- this will only be printed if
1242 there was an error. */
1243 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1245 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1247 /* Permanent breakpoints cannot be inserted or removed. Disabled
1248 breakpoints should not be inserted. */
1249 if (!breakpoint_enabled (b
->owner
))
1252 /* There is no point inserting thread-specific breakpoints if the
1253 thread no longer exists. */
1254 if (b
->owner
->thread
!= -1
1255 && !valid_thread_id (b
->owner
->thread
))
1258 /* FIXME drow/2003-10-07: This code should be pushed elsewhere when
1259 hardware watchpoints are split into multiple loc breakpoints. */
1260 if ((b
->loc_type
== bp_loc_hardware_watchpoint
1261 || b
->owner
->type
== bp_watchpoint
) && !b
->owner
->val
)
1264 val
= evaluate_expression (b
->owner
->exp
);
1265 release_value (val
);
1266 if (value_lazy (val
))
1267 value_fetch_lazy (val
);
1268 b
->owner
->val
= val
;
1271 val
= insert_bp_location (b
, tmp_error_stream
,
1272 &disabled_breaks
, &process_warning
,
1273 &hw_breakpoint_error
);
1280 /* If a hardware breakpoint or watchpoint was inserted, add a
1281 message about possibly exhausted resources. */
1282 if (hw_breakpoint_error
)
1284 fprintf_unfiltered (tmp_error_stream
,
1285 "Could not insert hardware breakpoints:\n\
1286 You may have requested too many hardware breakpoints/watchpoints.\n");
1288 #ifdef ONE_PROCESS_WRITETEXT
1289 if (process_warning
)
1290 fprintf_unfiltered (tmp_error_stream
,
1291 "The same program may be running in another process.");
1293 target_terminal_ours_for_output ();
1294 error_stream (tmp_error_stream
);
1300 remove_breakpoints (void)
1302 struct bp_location
*b
;
1305 ALL_BP_LOCATIONS (b
)
1309 val
= remove_breakpoint (b
, mark_uninserted
);
1318 remove_hw_watchpoints (void)
1320 struct bp_location
*b
;
1323 ALL_BP_LOCATIONS (b
)
1325 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1327 val
= remove_breakpoint (b
, mark_uninserted
);
1336 reattach_breakpoints (int pid
)
1338 struct bp_location
*b
;
1340 struct cleanup
*old_chain
= save_inferior_ptid ();
1342 /* Set inferior_ptid; remove_breakpoint uses this global. */
1343 inferior_ptid
= pid_to_ptid (pid
);
1344 ALL_BP_LOCATIONS (b
)
1348 remove_breakpoint (b
, mark_inserted
);
1349 /* Note: since we insert a breakpoint right after removing,
1350 any decisions about automatically using hardware breakpoints
1351 made in insert_bp_location are preserved. */
1352 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1353 val
= target_insert_hw_breakpoint (&b
->target_info
);
1355 val
= target_insert_breakpoint (&b
->target_info
);
1356 /* FIXME drow/2003-10-07: This doesn't handle any other kinds of
1357 breakpoints. It's wrong for watchpoints, for example. */
1360 do_cleanups (old_chain
);
1365 do_cleanups (old_chain
);
1370 update_breakpoints_after_exec (void)
1372 struct breakpoint
*b
;
1373 struct breakpoint
*temp
;
1375 /* Doing this first prevents the badness of having delete_breakpoint()
1376 write a breakpoint's current "shadow contents" to lift the bp. That
1377 shadow is NOT valid after an exec()! */
1378 mark_breakpoints_out ();
1380 ALL_BREAKPOINTS_SAFE (b
, temp
)
1382 /* Solib breakpoints must be explicitly reset after an exec(). */
1383 if (b
->type
== bp_shlib_event
)
1385 delete_breakpoint (b
);
1389 /* Thread event breakpoints must be set anew after an exec(),
1390 as must overlay event breakpoints. */
1391 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1393 delete_breakpoint (b
);
1397 /* Step-resume breakpoints are meaningless after an exec(). */
1398 if (b
->type
== bp_step_resume
)
1400 delete_breakpoint (b
);
1404 /* Ditto the exception-handling catchpoints. */
1405 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1407 delete_breakpoint (b
);
1411 /* Don't delete an exec catchpoint, because else the inferior
1412 won't stop when it ought!
1414 Similarly, we probably ought to keep vfork catchpoints, 'cause
1415 on this target, we may not be able to stop when the vfork is
1416 seen, but only when the subsequent exec is seen. (And because
1417 deleting fork catchpoints here but not vfork catchpoints will
1418 seem mysterious to users, keep those too.)
1420 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1421 target address field, if any, is sufficient to have it be reset
1422 automagically. Certainly on HP-UX that's true.
1424 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1425 valid code address on some platforms (like the mn10300
1426 simulators). We shouldn't assign any special interpretation to
1427 a breakpoint with a zero address. And in fact, GDB doesn't ---
1428 I can't see what that comment above is talking about. As far
1429 as I can tell, setting the address of a
1430 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1431 is meaningless, since those are implemented with HP-UX kernel
1432 hackery, not by storing breakpoint instructions somewhere. */
1433 if ((b
->type
== bp_catch_exec
) ||
1434 (b
->type
== bp_catch_vfork
) ||
1435 (b
->type
== bp_catch_fork
))
1437 b
->loc
->address
= (CORE_ADDR
) 0;
1441 /* bp_finish is a special case. The only way we ought to be able
1442 to see one of these when an exec() has happened, is if the user
1443 caught a vfork, and then said "finish". Ordinarily a finish just
1444 carries them to the call-site of the current callee, by setting
1445 a temporary bp there and resuming. But in this case, the finish
1446 will carry them entirely through the vfork & exec.
1448 We don't want to allow a bp_finish to remain inserted now. But
1449 we can't safely delete it, 'cause finish_command has a handle to
1450 the bp on a bpstat, and will later want to delete it. There's a
1451 chance (and I've seen it happen) that if we delete the bp_finish
1452 here, that its storage will get reused by the time finish_command
1453 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1454 We really must allow finish_command to delete a bp_finish.
1456 In the absense of a general solution for the "how do we know
1457 it's safe to delete something others may have handles to?"
1458 problem, what we'll do here is just uninsert the bp_finish, and
1459 let finish_command delete it.
1461 (We know the bp_finish is "doomed" in the sense that it's
1462 momentary, and will be deleted as soon as finish_command sees
1463 the inferior stopped. So it doesn't matter that the bp's
1464 address is probably bogus in the new a.out, unlike e.g., the
1465 solib breakpoints.) */
1467 if (b
->type
== bp_finish
)
1472 /* Without a symbolic address, we have little hope of the
1473 pre-exec() address meaning the same thing in the post-exec()
1475 if (b
->addr_string
== NULL
)
1477 delete_breakpoint (b
);
1481 /* If this breakpoint has survived the above battery of checks, then
1482 it must have a symbolic address. Be sure that it gets reevaluated
1483 to a target address, rather than reusing the old evaluation.
1485 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1486 for bp_catch_exec and friends, I'm pretty sure this is entirely
1487 unnecessary. A call to breakpoint_re_set_one always recomputes
1488 the breakpoint's address from scratch, or deletes it if it can't.
1489 So I think this assignment could be deleted without effect. */
1490 b
->loc
->address
= (CORE_ADDR
) 0;
1492 /* FIXME what about longjmp breakpoints? Re-create them here? */
1493 create_overlay_event_breakpoint ("_ovly_debug_event");
1497 detach_breakpoints (int pid
)
1499 struct bp_location
*b
;
1501 struct cleanup
*old_chain
= save_inferior_ptid ();
1503 if (pid
== PIDGET (inferior_ptid
))
1504 error (_("Cannot detach breakpoints of inferior_ptid"));
1506 /* Set inferior_ptid; remove_breakpoint uses this global. */
1507 inferior_ptid
= pid_to_ptid (pid
);
1508 ALL_BP_LOCATIONS (b
)
1512 val
= remove_breakpoint (b
, mark_inserted
);
1515 do_cleanups (old_chain
);
1520 do_cleanups (old_chain
);
1525 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1529 if (b
->owner
->enable_state
== bp_permanent
)
1530 /* Permanent breakpoints cannot be inserted or removed. */
1533 if (b
->owner
->type
== bp_none
)
1534 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1537 if (b
->loc_type
== bp_loc_software_breakpoint
1538 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1540 /* "Normal" instruction breakpoint: either the standard
1541 trap-instruction bp (bp_breakpoint), or a
1542 bp_hardware_breakpoint. */
1544 /* First check to see if we have to handle an overlay. */
1545 if (overlay_debugging
== ovly_off
1546 || b
->section
== NULL
1547 || !(section_is_overlay (b
->section
)))
1549 /* No overlay handling: just remove the breakpoint. */
1551 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1552 val
= target_remove_hw_breakpoint (&b
->target_info
);
1554 val
= target_remove_breakpoint (&b
->target_info
);
1558 /* This breakpoint is in an overlay section.
1559 Did we set a breakpoint at the LMA? */
1560 if (!overlay_events_enabled
)
1562 /* Yes -- overlay event support is not active, so we
1563 should have set a breakpoint at the LMA. Remove it.
1565 /* Ignore any failures: if the LMA is in ROM, we will
1566 have already warned when we failed to insert it. */
1567 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1568 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1570 target_remove_breakpoint (&b
->overlay_target_info
);
1572 /* Did we set a breakpoint at the VMA?
1573 If so, we will have marked the breakpoint 'inserted'. */
1576 /* Yes -- remove it. Previously we did not bother to
1577 remove the breakpoint if the section had been
1578 unmapped, but let's not rely on that being safe. We
1579 don't know what the overlay manager might do. */
1580 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1581 val
= target_remove_hw_breakpoint (&b
->target_info
);
1583 /* However, we should remove *software* breakpoints only
1584 if the section is still mapped, or else we overwrite
1585 wrong code with the saved shadow contents. */
1586 else if (section_is_mapped (b
->section
))
1587 val
= target_remove_breakpoint (&b
->target_info
);
1593 /* No -- not inserted, so no need to remove. No error. */
1599 b
->inserted
= (is
== mark_inserted
);
1601 else if (b
->loc_type
== bp_loc_hardware_watchpoint
1602 && breakpoint_enabled (b
->owner
)
1608 b
->inserted
= (is
== mark_inserted
);
1609 /* Walk down the saved value chain. */
1610 for (v
= b
->owner
->val_chain
; v
; v
= value_next (v
))
1612 /* For each memory reference remove the watchpoint
1614 if (VALUE_LVAL (v
) == lval_memory
1615 && ! value_lazy (v
))
1617 struct type
*vtype
= check_typedef (value_type (v
));
1619 if (v
== b
->owner
->val_chain
1620 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1621 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1626 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
1627 len
= TYPE_LENGTH (value_type (v
));
1629 if (b
->owner
->type
== bp_read_watchpoint
)
1631 else if (b
->owner
->type
== bp_access_watchpoint
)
1634 val
= target_remove_watchpoint (addr
, len
, type
);
1641 /* Failure to remove any of the hardware watchpoints comes here. */
1642 if ((is
== mark_uninserted
) && (b
->inserted
))
1643 warning (_("Could not remove hardware watchpoint %d."),
1646 else if ((b
->owner
->type
== bp_catch_fork
||
1647 b
->owner
->type
== bp_catch_vfork
||
1648 b
->owner
->type
== bp_catch_exec
)
1649 && breakpoint_enabled (b
->owner
)
1653 switch (b
->owner
->type
)
1656 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1658 case bp_catch_vfork
:
1659 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1662 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1665 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1670 b
->inserted
= (is
== mark_inserted
);
1672 else if ((b
->owner
->type
== bp_catch_catch
||
1673 b
->owner
->type
== bp_catch_throw
)
1674 && breakpoint_enabled (b
->owner
)
1677 val
= target_remove_breakpoint (&b
->target_info
);
1680 b
->inserted
= (is
== mark_inserted
);
1686 /* Clear the "inserted" flag in all breakpoints. */
1689 mark_breakpoints_out (void)
1691 struct bp_location
*bpt
;
1693 ALL_BP_LOCATIONS (bpt
)
1697 /* Clear the "inserted" flag in all breakpoints and delete any
1698 breakpoints which should go away between runs of the program.
1700 Plus other such housekeeping that has to be done for breakpoints
1703 Note: this function gets called at the end of a run (by
1704 generic_mourn_inferior) and when a run begins (by
1705 init_wait_for_inferior). */
1710 breakpoint_init_inferior (enum inf_context context
)
1712 struct breakpoint
*b
, *temp
;
1713 struct bp_location
*bpt
;
1715 ALL_BP_LOCATIONS (bpt
)
1718 ALL_BREAKPOINTS_SAFE (b
, temp
)
1723 case bp_watchpoint_scope
:
1725 /* If the call dummy breakpoint is at the entry point it will
1726 cause problems when the inferior is rerun, so we better
1729 Also get rid of scope breakpoints. */
1730 delete_breakpoint (b
);
1734 case bp_hardware_watchpoint
:
1735 case bp_read_watchpoint
:
1736 case bp_access_watchpoint
:
1738 /* Likewise for watchpoints on local expressions. */
1739 if (b
->exp_valid_block
!= NULL
)
1740 delete_breakpoint (b
);
1741 if (context
== inf_starting
)
1743 /* Reset val field to force reread of starting value
1744 in insert_breakpoints. */
1746 value_free (b
->val
);
1756 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1757 exists at PC. It returns ordinary_breakpoint_here if it's an
1758 ordinary breakpoint, or permanent_breakpoint_here if it's a
1759 permanent breakpoint.
1760 - When continuing from a location with an ordinary breakpoint, we
1761 actually single step once before calling insert_breakpoints.
1762 - When continuing from a localion with a permanent breakpoint, we
1763 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1764 the target, to advance the PC past the breakpoint. */
1766 enum breakpoint_here
1767 breakpoint_here_p (CORE_ADDR pc
)
1769 struct bp_location
*bpt
;
1770 int any_breakpoint_here
= 0;
1772 ALL_BP_LOCATIONS (bpt
)
1774 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1775 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1778 if ((breakpoint_enabled (bpt
->owner
)
1779 || bpt
->owner
->enable_state
== bp_permanent
)
1780 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1782 if (overlay_debugging
1783 && section_is_overlay (bpt
->section
)
1784 && !section_is_mapped (bpt
->section
))
1785 continue; /* unmapped overlay -- can't be a match */
1786 else if (bpt
->owner
->enable_state
== bp_permanent
)
1787 return permanent_breakpoint_here
;
1789 any_breakpoint_here
= 1;
1793 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1797 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1798 but it only returns true if there is actually a breakpoint inserted
1802 breakpoint_inserted_here_p (CORE_ADDR pc
)
1804 struct bp_location
*bpt
;
1806 ALL_BP_LOCATIONS (bpt
)
1808 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1809 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1813 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1815 if (overlay_debugging
1816 && section_is_overlay (bpt
->section
)
1817 && !section_is_mapped (bpt
->section
))
1818 continue; /* unmapped overlay -- can't be a match */
1824 /* Also check for software single-step breakpoints. */
1825 if (single_step_breakpoint_inserted_here_p (pc
))
1831 /* This function returns non-zero iff there is a software breakpoint
1835 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1837 struct bp_location
*bpt
;
1838 int any_breakpoint_here
= 0;
1840 ALL_BP_LOCATIONS (bpt
)
1842 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1845 if ((breakpoint_enabled (bpt
->owner
)
1846 || bpt
->owner
->enable_state
== bp_permanent
)
1848 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1850 if (overlay_debugging
1851 && section_is_overlay (bpt
->section
)
1852 && !section_is_mapped (bpt
->section
))
1853 continue; /* unmapped overlay -- can't be a match */
1859 /* Also check for software single-step breakpoints. */
1860 if (single_step_breakpoint_inserted_here_p (pc
))
1866 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1867 PC is valid for process/thread PTID. */
1870 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1872 struct bp_location
*bpt
;
1875 thread
= pid_to_thread_id (ptid
);
1877 ALL_BP_LOCATIONS (bpt
)
1879 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1880 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1883 if ((breakpoint_enabled (bpt
->owner
)
1884 || bpt
->owner
->enable_state
== bp_permanent
)
1885 && bpt
->address
== pc
1886 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1888 if (overlay_debugging
1889 && section_is_overlay (bpt
->section
)
1890 && !section_is_mapped (bpt
->section
))
1891 continue; /* unmapped overlay -- can't be a match */
1901 /* bpstat stuff. External routines' interfaces are documented
1905 ep_is_catchpoint (struct breakpoint
*ep
)
1908 (ep
->type
== bp_catch_load
)
1909 || (ep
->type
== bp_catch_unload
)
1910 || (ep
->type
== bp_catch_fork
)
1911 || (ep
->type
== bp_catch_vfork
)
1912 || (ep
->type
== bp_catch_exec
)
1913 || (ep
->type
== bp_catch_catch
)
1914 || (ep
->type
== bp_catch_throw
);
1916 /* ??rehrauer: Add more kinds here, as are implemented... */
1920 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1923 (ep
->type
== bp_catch_load
)
1924 || (ep
->type
== bp_catch_unload
);
1928 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1931 (ep
->type
== bp_catch_catch
)
1932 || (ep
->type
== bp_catch_throw
);
1935 /* Clear a bpstat so that it says we are not at any breakpoint.
1936 Also free any storage that is part of a bpstat. */
1939 bpstat_clear (bpstat
*bsp
)
1950 if (p
->old_val
!= NULL
)
1951 value_free (p
->old_val
);
1952 free_command_lines (&p
->commands
);
1959 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1960 is part of the bpstat is copied as well. */
1963 bpstat_copy (bpstat bs
)
1967 bpstat retval
= NULL
;
1972 for (; bs
!= NULL
; bs
= bs
->next
)
1974 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1975 memcpy (tmp
, bs
, sizeof (*tmp
));
1976 if (bs
->commands
!= NULL
)
1977 tmp
->commands
= copy_command_lines (bs
->commands
);
1978 if (bs
->old_val
!= NULL
)
1979 tmp
->old_val
= value_copy (bs
->old_val
);
1982 /* This is the first thing in the chain. */
1992 /* Find the bpstat associated with this breakpoint */
1995 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2000 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2002 if (bsp
->breakpoint_at
== breakpoint
)
2008 /* Find a step_resume breakpoint associated with this bpstat.
2009 (If there are multiple step_resume bp's on the list, this function
2010 will arbitrarily pick one.)
2012 It is an error to use this function if BPSTAT doesn't contain a
2013 step_resume breakpoint.
2015 See wait_for_inferior's use of this function. */
2017 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2021 gdb_assert (bsp
!= NULL
);
2023 current_thread
= pid_to_thread_id (inferior_ptid
);
2025 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2027 if ((bsp
->breakpoint_at
!= NULL
) &&
2028 (bsp
->breakpoint_at
->type
== bp_step_resume
) &&
2029 (bsp
->breakpoint_at
->thread
== current_thread
||
2030 bsp
->breakpoint_at
->thread
== -1))
2031 return bsp
->breakpoint_at
;
2034 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2038 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2039 at. *BSP upon return is a bpstat which points to the remaining
2040 breakpoints stopped at (but which is not guaranteed to be good for
2041 anything but further calls to bpstat_num).
2042 Return 0 if passed a bpstat which does not indicate any breakpoints.
2043 Return -1 if stopped at a breakpoint that has been deleted since
2045 Return 1 otherwise. */
2048 bpstat_num (bpstat
*bsp
, int *num
)
2050 struct breakpoint
*b
;
2053 return 0; /* No more breakpoint values */
2055 b
= (*bsp
)->breakpoint_at
;
2056 *bsp
= (*bsp
)->next
;
2058 return -1; /* breakpoint that's been deleted since */
2060 *num
= b
->number
; /* We have its number */
2064 /* Modify BS so that the actions will not be performed. */
2067 bpstat_clear_actions (bpstat bs
)
2069 for (; bs
!= NULL
; bs
= bs
->next
)
2071 free_command_lines (&bs
->commands
);
2072 if (bs
->old_val
!= NULL
)
2074 value_free (bs
->old_val
);
2080 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2082 cleanup_executing_breakpoints (void *ignore
)
2084 executing_breakpoint_commands
= 0;
2087 /* Execute all the commands associated with all the breakpoints at this
2088 location. Any of these commands could cause the process to proceed
2089 beyond this point, etc. We look out for such changes by checking
2090 the global "breakpoint_proceeded" after each command. */
2093 bpstat_do_actions (bpstat
*bsp
)
2096 struct cleanup
*old_chain
;
2098 /* Avoid endless recursion if a `source' command is contained
2100 if (executing_breakpoint_commands
)
2103 executing_breakpoint_commands
= 1;
2104 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2107 /* Note that (as of this writing), our callers all appear to
2108 be passing us the address of global stop_bpstat. And, if
2109 our calls to execute_control_command cause the inferior to
2110 proceed, that global (and hence, *bsp) will change.
2112 We must be careful to not touch *bsp unless the inferior
2113 has not proceeded. */
2115 /* This pointer will iterate over the list of bpstat's. */
2118 breakpoint_proceeded
= 0;
2119 for (; bs
!= NULL
; bs
= bs
->next
)
2121 struct command_line
*cmd
;
2122 struct cleanup
*this_cmd_tree_chain
;
2124 /* Take ownership of the BSP's command tree, if it has one.
2126 The command tree could legitimately contain commands like
2127 'step' and 'next', which call clear_proceed_status, which
2128 frees stop_bpstat's command tree. To make sure this doesn't
2129 free the tree we're executing out from under us, we need to
2130 take ownership of the tree ourselves. Since a given bpstat's
2131 commands are only executed once, we don't need to copy it; we
2132 can clear the pointer in the bpstat, and make sure we free
2133 the tree when we're done. */
2136 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2140 execute_control_command (cmd
);
2142 if (breakpoint_proceeded
)
2148 /* We can free this command tree now. */
2149 do_cleanups (this_cmd_tree_chain
);
2151 if (breakpoint_proceeded
)
2152 /* The inferior is proceeded by the command; bomb out now.
2153 The bpstat chain has been blown away by wait_for_inferior.
2154 But since execution has stopped again, there is a new bpstat
2155 to look at, so start over. */
2158 do_cleanups (old_chain
);
2161 /* This is the normal print function for a bpstat. In the future,
2162 much of this logic could (should?) be moved to bpstat_stop_status,
2163 by having it set different print_it values.
2165 Current scheme: When we stop, bpstat_print() is called. It loops
2166 through the bpstat list of things causing this stop, calling the
2167 print_bp_stop_message function on each one. The behavior of the
2168 print_bp_stop_message function depends on the print_it field of
2169 bpstat. If such field so indicates, call this function here.
2171 Return values from this routine (ultimately used by bpstat_print()
2172 and normal_stop() to decide what to do):
2173 PRINT_NOTHING: Means we already printed all we needed to print,
2174 don't print anything else.
2175 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2176 that something to be followed by a location.
2177 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2178 that something to be followed by a location.
2179 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2182 static enum print_stop_action
2183 print_it_typical (bpstat bs
)
2185 struct cleanup
*old_chain
, *ui_out_chain
;
2186 struct ui_stream
*stb
;
2187 stb
= ui_out_stream_new (uiout
);
2188 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2189 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2190 which has since been deleted. */
2191 if (bs
->breakpoint_at
== NULL
)
2192 return PRINT_UNKNOWN
;
2194 switch (bs
->breakpoint_at
->type
)
2197 case bp_hardware_breakpoint
:
2198 if (bs
->breakpoint_at
->loc
->address
!= bs
->breakpoint_at
->loc
->requested_address
)
2199 breakpoint_adjustment_warning (bs
->breakpoint_at
->loc
->requested_address
,
2200 bs
->breakpoint_at
->loc
->address
,
2201 bs
->breakpoint_at
->number
, 1);
2202 annotate_breakpoint (bs
->breakpoint_at
->number
);
2203 ui_out_text (uiout
, "\nBreakpoint ");
2204 if (ui_out_is_mi_like_p (uiout
))
2205 ui_out_field_string (uiout
, "reason",
2206 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2207 ui_out_field_int (uiout
, "bkptno", bs
->breakpoint_at
->number
);
2208 ui_out_text (uiout
, ", ");
2209 return PRINT_SRC_AND_LOC
;
2212 case bp_shlib_event
:
2213 /* Did we stop because the user set the stop_on_solib_events
2214 variable? (If so, we report this as a generic, "Stopped due
2215 to shlib event" message.) */
2216 printf_filtered (_("Stopped due to shared library event\n"));
2217 return PRINT_NOTHING
;
2220 case bp_thread_event
:
2221 /* Not sure how we will get here.
2222 GDB should not stop for these breakpoints. */
2223 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2224 return PRINT_NOTHING
;
2227 case bp_overlay_event
:
2228 /* By analogy with the thread event, GDB should not stop for these. */
2229 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2230 return PRINT_NOTHING
;
2234 annotate_catchpoint (bs
->breakpoint_at
->number
);
2235 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2236 bs
->breakpoint_at
->number
,
2237 bs
->breakpoint_at
->triggered_dll_pathname
);
2238 return PRINT_SRC_AND_LOC
;
2241 case bp_catch_unload
:
2242 annotate_catchpoint (bs
->breakpoint_at
->number
);
2243 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2244 bs
->breakpoint_at
->number
,
2245 bs
->breakpoint_at
->triggered_dll_pathname
);
2246 return PRINT_SRC_AND_LOC
;
2250 annotate_catchpoint (bs
->breakpoint_at
->number
);
2251 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2252 bs
->breakpoint_at
->number
,
2253 bs
->breakpoint_at
->forked_inferior_pid
);
2254 return PRINT_SRC_AND_LOC
;
2257 case bp_catch_vfork
:
2258 annotate_catchpoint (bs
->breakpoint_at
->number
);
2259 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2260 bs
->breakpoint_at
->number
,
2261 bs
->breakpoint_at
->forked_inferior_pid
);
2262 return PRINT_SRC_AND_LOC
;
2266 annotate_catchpoint (bs
->breakpoint_at
->number
);
2267 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2268 bs
->breakpoint_at
->number
,
2269 bs
->breakpoint_at
->exec_pathname
);
2270 return PRINT_SRC_AND_LOC
;
2273 case bp_catch_catch
:
2274 if (current_exception_event
&&
2275 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2277 annotate_catchpoint (bs
->breakpoint_at
->number
);
2278 printf_filtered (_("\nCatchpoint %d (exception caught), "),
2279 bs
->breakpoint_at
->number
);
2280 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2281 printf_filtered (_("throw location %s:%d, "),
2282 CURRENT_EXCEPTION_THROW_FILE
,
2283 CURRENT_EXCEPTION_THROW_LINE
);
2285 printf_filtered (_("throw location unknown, "));
2287 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2288 printf_filtered (_("catch location %s:%d\n"),
2289 CURRENT_EXCEPTION_CATCH_FILE
,
2290 CURRENT_EXCEPTION_CATCH_LINE
);
2292 printf_filtered (_("catch location unknown\n"));
2294 /* don't bother to print location frame info */
2295 return PRINT_SRC_ONLY
;
2299 /* really throw, some other bpstat will handle it */
2300 return PRINT_UNKNOWN
;
2304 case bp_catch_throw
:
2305 if (current_exception_event
&&
2306 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2308 annotate_catchpoint (bs
->breakpoint_at
->number
);
2309 printf_filtered (_("\nCatchpoint %d (exception thrown), "),
2310 bs
->breakpoint_at
->number
);
2311 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2312 printf_filtered (_("throw location %s:%d, "),
2313 CURRENT_EXCEPTION_THROW_FILE
,
2314 CURRENT_EXCEPTION_THROW_LINE
);
2316 printf_filtered (_("throw location unknown, "));
2318 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2319 printf_filtered (_("catch location %s:%d\n"),
2320 CURRENT_EXCEPTION_CATCH_FILE
,
2321 CURRENT_EXCEPTION_CATCH_LINE
);
2323 printf_filtered (_("catch location unknown\n"));
2325 /* don't bother to print location frame info */
2326 return PRINT_SRC_ONLY
;
2330 /* really catch, some other bpstat will handle it */
2331 return PRINT_UNKNOWN
;
2336 case bp_hardware_watchpoint
:
2337 if (bs
->old_val
!= NULL
)
2339 annotate_watchpoint (bs
->breakpoint_at
->number
);
2340 if (ui_out_is_mi_like_p (uiout
))
2343 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2344 mention (bs
->breakpoint_at
);
2345 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2346 ui_out_text (uiout
, "\nOld value = ");
2347 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2348 ui_out_field_stream (uiout
, "old", stb
);
2349 ui_out_text (uiout
, "\nNew value = ");
2350 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2351 ui_out_field_stream (uiout
, "new", stb
);
2352 do_cleanups (ui_out_chain
);
2353 ui_out_text (uiout
, "\n");
2354 value_free (bs
->old_val
);
2357 /* More than one watchpoint may have been triggered. */
2358 return PRINT_UNKNOWN
;
2361 case bp_read_watchpoint
:
2362 if (ui_out_is_mi_like_p (uiout
))
2365 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2366 mention (bs
->breakpoint_at
);
2367 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2368 ui_out_text (uiout
, "\nValue = ");
2369 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2370 ui_out_field_stream (uiout
, "value", stb
);
2371 do_cleanups (ui_out_chain
);
2372 ui_out_text (uiout
, "\n");
2373 return PRINT_UNKNOWN
;
2376 case bp_access_watchpoint
:
2377 if (bs
->old_val
!= NULL
)
2379 annotate_watchpoint (bs
->breakpoint_at
->number
);
2380 if (ui_out_is_mi_like_p (uiout
))
2383 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2384 mention (bs
->breakpoint_at
);
2385 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2386 ui_out_text (uiout
, "\nOld value = ");
2387 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2388 ui_out_field_stream (uiout
, "old", stb
);
2389 value_free (bs
->old_val
);
2391 ui_out_text (uiout
, "\nNew value = ");
2395 mention (bs
->breakpoint_at
);
2396 if (ui_out_is_mi_like_p (uiout
))
2399 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2400 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2401 ui_out_text (uiout
, "\nValue = ");
2403 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0,Val_pretty_default
);
2404 ui_out_field_stream (uiout
, "new", stb
);
2405 do_cleanups (ui_out_chain
);
2406 ui_out_text (uiout
, "\n");
2407 return PRINT_UNKNOWN
;
2410 /* Fall through, we don't deal with these types of breakpoints
2414 if (ui_out_is_mi_like_p (uiout
))
2417 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2418 return PRINT_UNKNOWN
;
2422 if (ui_out_is_mi_like_p (uiout
))
2425 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2426 return PRINT_UNKNOWN
;
2431 case bp_longjmp_resume
:
2432 case bp_step_resume
:
2433 case bp_watchpoint_scope
:
2436 return PRINT_UNKNOWN
;
2440 /* Generic routine for printing messages indicating why we
2441 stopped. The behavior of this function depends on the value
2442 'print_it' in the bpstat structure. Under some circumstances we
2443 may decide not to print anything here and delegate the task to
2446 static enum print_stop_action
2447 print_bp_stop_message (bpstat bs
)
2449 switch (bs
->print_it
)
2452 /* Nothing should be printed for this bpstat entry. */
2453 return PRINT_UNKNOWN
;
2457 /* We still want to print the frame, but we already printed the
2458 relevant messages. */
2459 return PRINT_SRC_AND_LOC
;
2462 case print_it_normal
:
2463 /* Normal case. Call the breakpoint's print_it method, or
2464 print_it_typical. */
2465 if (bs
->breakpoint_at
!= NULL
&& bs
->breakpoint_at
->ops
!= NULL
2466 && bs
->breakpoint_at
->ops
->print_it
!= NULL
)
2467 return bs
->breakpoint_at
->ops
->print_it (bs
->breakpoint_at
);
2469 return print_it_typical (bs
);
2473 internal_error (__FILE__
, __LINE__
,
2474 _("print_bp_stop_message: unrecognized enum value"));
2479 /* Print a message indicating what happened. This is called from
2480 normal_stop(). The input to this routine is the head of the bpstat
2481 list - a list of the eventpoints that caused this stop. This
2482 routine calls the generic print routine for printing a message
2483 about reasons for stopping. This will print (for example) the
2484 "Breakpoint n," part of the output. The return value of this
2487 PRINT_UNKNOWN: Means we printed nothing
2488 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2489 code to print the location. An example is
2490 "Breakpoint 1, " which should be followed by
2492 PRINT_SRC_ONLY: Means we printed something, but there is no need
2493 to also print the location part of the message.
2494 An example is the catch/throw messages, which
2495 don't require a location appended to the end.
2496 PRINT_NOTHING: We have done some printing and we don't need any
2497 further info to be printed.*/
2499 enum print_stop_action
2500 bpstat_print (bpstat bs
)
2504 /* Maybe another breakpoint in the chain caused us to stop.
2505 (Currently all watchpoints go on the bpstat whether hit or not.
2506 That probably could (should) be changed, provided care is taken
2507 with respect to bpstat_explains_signal). */
2508 for (; bs
; bs
= bs
->next
)
2510 val
= print_bp_stop_message (bs
);
2511 if (val
== PRINT_SRC_ONLY
2512 || val
== PRINT_SRC_AND_LOC
2513 || val
== PRINT_NOTHING
)
2517 /* We reached the end of the chain, or we got a null BS to start
2518 with and nothing was printed. */
2519 return PRINT_UNKNOWN
;
2522 /* Evaluate the expression EXP and return 1 if value is zero.
2523 This is used inside a catch_errors to evaluate the breakpoint condition.
2524 The argument is a "struct expression *" that has been cast to char * to
2525 make it pass through catch_errors. */
2528 breakpoint_cond_eval (void *exp
)
2530 struct value
*mark
= value_mark ();
2531 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2532 value_free_to_mark (mark
);
2536 /* Allocate a new bpstat and chain it to the current one. */
2539 bpstat_alloc (struct breakpoint
*b
, bpstat cbs
/* Current "bs" value */ )
2543 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2545 bs
->breakpoint_at
= b
;
2546 /* If the condition is false, etc., don't do the commands. */
2547 bs
->commands
= NULL
;
2549 bs
->print_it
= print_it_normal
;
2553 /* Possible return values for watchpoint_check (this can't be an enum
2554 because of check_errors). */
2555 /* The watchpoint has been deleted. */
2556 #define WP_DELETED 1
2557 /* The value has changed. */
2558 #define WP_VALUE_CHANGED 2
2559 /* The value has not changed. */
2560 #define WP_VALUE_NOT_CHANGED 3
2562 #define BP_TEMPFLAG 1
2563 #define BP_HARDWAREFLAG 2
2565 /* Check watchpoint condition. */
2568 watchpoint_check (void *p
)
2570 bpstat bs
= (bpstat
) p
;
2571 struct breakpoint
*b
;
2572 struct frame_info
*fr
;
2573 int within_current_scope
;
2575 b
= bs
->breakpoint_at
;
2577 if (b
->exp_valid_block
== NULL
)
2578 within_current_scope
= 1;
2581 /* There is no current frame at this moment. If we're going to have
2582 any chance of handling watchpoints on local variables, we'll need
2583 the frame chain (so we can determine if we're in scope). */
2584 reinit_frame_cache ();
2585 fr
= frame_find_by_id (b
->watchpoint_frame
);
2586 within_current_scope
= (fr
!= NULL
);
2588 /* If we've gotten confused in the unwinder, we might have
2589 returned a frame that can't describe this variable. */
2590 if (within_current_scope
2591 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2592 within_current_scope
= 0;
2594 /* in_function_epilogue_p() returns a non-zero value if we're still
2595 in the function but the stack frame has already been invalidated.
2596 Since we can't rely on the values of local variables after the
2597 stack has been destroyed, we are treating the watchpoint in that
2598 state as `not changed' without further checking.
2600 vinschen/2003-09-04: The former implementation left out the case
2601 that the watchpoint frame couldn't be found by frame_find_by_id()
2602 because the current PC is currently in an epilogue. Calling
2603 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2604 if ((!within_current_scope
|| fr
== get_current_frame ())
2605 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2606 return WP_VALUE_NOT_CHANGED
;
2607 if (fr
&& within_current_scope
)
2608 /* If we end up stopping, the current frame will get selected
2609 in normal_stop. So this call to select_frame won't affect
2614 if (within_current_scope
)
2616 /* We use value_{,free_to_}mark because it could be a
2617 *long* time before we return to the command level and
2618 call free_all_values. We can't call free_all_values because
2619 we might be in the middle of evaluating a function call. */
2621 struct value
*mark
= value_mark ();
2622 struct value
*new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
2623 if (!value_equal (b
->val
, new_val
))
2625 release_value (new_val
);
2626 value_free_to_mark (mark
);
2627 bs
->old_val
= b
->val
;
2629 /* We will stop here */
2630 return WP_VALUE_CHANGED
;
2634 /* Nothing changed, don't do anything. */
2635 value_free_to_mark (mark
);
2636 /* We won't stop here */
2637 return WP_VALUE_NOT_CHANGED
;
2642 /* This seems like the only logical thing to do because
2643 if we temporarily ignored the watchpoint, then when
2644 we reenter the block in which it is valid it contains
2645 garbage (in the case of a function, it may have two
2646 garbage values, one before and one after the prologue).
2647 So we can't even detect the first assignment to it and
2648 watch after that (since the garbage may or may not equal
2649 the first value assigned). */
2650 /* We print all the stop information in print_it_typical(), but
2651 in this case, by the time we call print_it_typical() this bp
2652 will be deleted already. So we have no choice but print the
2653 information here. */
2654 if (ui_out_is_mi_like_p (uiout
))
2656 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2657 ui_out_text (uiout
, "\nWatchpoint ");
2658 ui_out_field_int (uiout
, "wpnum", bs
->breakpoint_at
->number
);
2659 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2660 which its expression is valid.\n");
2662 if (b
->related_breakpoint
)
2663 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2664 b
->disposition
= disp_del_at_next_stop
;
2670 /* Get a bpstat associated with having just stopped at address
2671 BP_ADDR in thread PTID. STOPPED_BY_WATCHPOINT is 1 if the
2672 target thinks we stopped due to a hardware watchpoint, 0 if we
2673 know we did not trigger a hardware watchpoint, and -1 if we do not know. */
2675 /* Determine whether we stopped at a breakpoint, etc, or whether we
2676 don't understand this stop. Result is a chain of bpstat's such that:
2678 if we don't understand the stop, the result is a null pointer.
2680 if we understand why we stopped, the result is not null.
2682 Each element of the chain refers to a particular breakpoint or
2683 watchpoint at which we have stopped. (We may have stopped for
2684 several reasons concurrently.)
2686 Each element of the chain has valid next, breakpoint_at,
2687 commands, FIXME??? fields. */
2690 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
, int stopped_by_watchpoint
)
2692 struct breakpoint
*b
, *temp
;
2693 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2694 int real_breakpoint
= 0;
2695 /* Root of the chain of bpstat's */
2696 struct bpstats root_bs
[1];
2697 /* Pointer to the last thing in the chain currently. */
2698 bpstat bs
= root_bs
;
2699 int thread_id
= pid_to_thread_id (ptid
);
2701 ALL_BREAKPOINTS_SAFE (b
, temp
)
2703 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2706 if (b
->type
!= bp_watchpoint
2707 && b
->type
!= bp_hardware_watchpoint
2708 && b
->type
!= bp_read_watchpoint
2709 && b
->type
!= bp_access_watchpoint
2710 && b
->type
!= bp_hardware_breakpoint
2711 && b
->type
!= bp_catch_fork
2712 && b
->type
!= bp_catch_vfork
2713 && b
->type
!= bp_catch_exec
2714 && b
->type
!= bp_catch_catch
2715 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2717 if (b
->loc
->address
!= bp_addr
) /* address doesn't match */
2719 if (overlay_debugging
/* unmapped overlay section */
2720 && section_is_overlay (b
->loc
->section
)
2721 && !section_is_mapped (b
->loc
->section
))
2725 /* Continuable hardware watchpoints are treated as non-existent if the
2726 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2727 some data address). Otherwise gdb won't stop on a break instruction
2728 in the code (not from a breakpoint) when a hardware watchpoint has
2731 if ((b
->type
== bp_hardware_watchpoint
2732 || b
->type
== bp_read_watchpoint
2733 || b
->type
== bp_access_watchpoint
)
2734 && !stopped_by_watchpoint
)
2737 if (b
->type
== bp_hardware_breakpoint
)
2739 if (b
->loc
->address
!= bp_addr
)
2741 if (overlay_debugging
/* unmapped overlay section */
2742 && section_is_overlay (b
->loc
->section
)
2743 && !section_is_mapped (b
->loc
->section
))
2747 /* Is this a catchpoint of a load or unload? If so, did we
2748 get a load or unload of the specified library? If not,
2750 if ((b
->type
== bp_catch_load
)
2751 #if defined(SOLIB_HAVE_LOAD_EVENT)
2752 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2753 || ((b
->dll_pathname
!= NULL
)
2754 && (strcmp (b
->dll_pathname
,
2755 SOLIB_LOADED_LIBRARY_PATHNAME (
2756 PIDGET (inferior_ptid
)))
2762 if ((b
->type
== bp_catch_unload
)
2763 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2764 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2765 || ((b
->dll_pathname
!= NULL
)
2766 && (strcmp (b
->dll_pathname
,
2767 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2768 PIDGET (inferior_ptid
)))
2774 if ((b
->type
== bp_catch_fork
)
2775 && !inferior_has_forked (PIDGET (inferior_ptid
),
2776 &b
->forked_inferior_pid
))
2779 if ((b
->type
== bp_catch_vfork
)
2780 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2781 &b
->forked_inferior_pid
))
2784 if ((b
->type
== bp_catch_exec
)
2785 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2788 if (ep_is_exception_catchpoint (b
) &&
2789 !(current_exception_event
= target_get_current_exception_event ()))
2792 /* Come here if it's a watchpoint, or if the break address matches */
2794 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
2796 /* Watchpoints may change this, if not found to have triggered. */
2800 if (b
->type
== bp_watchpoint
||
2801 b
->type
== bp_hardware_watchpoint
)
2803 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2805 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2806 int e
= catch_errors (watchpoint_check
, bs
, message
,
2808 do_cleanups (cleanups
);
2812 /* We've already printed what needs to be printed. */
2813 /* Actually this is superfluous, because by the time we
2814 call print_it_typical() the wp will be already deleted,
2815 and the function will return immediately. */
2816 bs
->print_it
= print_it_done
;
2819 case WP_VALUE_CHANGED
:
2823 case WP_VALUE_NOT_CHANGED
:
2825 bs
->print_it
= print_it_noop
;
2832 /* Error from catch_errors. */
2833 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2834 if (b
->related_breakpoint
)
2835 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2836 b
->disposition
= disp_del_at_next_stop
;
2837 /* We've already printed what needs to be printed. */
2838 bs
->print_it
= print_it_done
;
2844 else if (b
->type
== bp_read_watchpoint
||
2845 b
->type
== bp_access_watchpoint
)
2851 if (!target_stopped_data_address (¤t_target
, &addr
))
2853 for (v
= b
->val_chain
; v
; v
= value_next (v
))
2855 if (VALUE_LVAL (v
) == lval_memory
2856 && ! value_lazy (v
))
2858 struct type
*vtype
= check_typedef (value_type (v
));
2860 if (v
== b
->val_chain
2861 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2862 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2866 vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
2867 /* Exact match not required. Within range is
2869 if (addr
>= vaddr
&&
2870 addr
< vaddr
+ TYPE_LENGTH (value_type (v
)))
2877 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2879 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2880 int e
= catch_errors (watchpoint_check
, bs
, message
,
2882 do_cleanups (cleanups
);
2886 /* We've already printed what needs to be printed. */
2887 bs
->print_it
= print_it_done
;
2890 case WP_VALUE_CHANGED
:
2891 if (b
->type
== bp_read_watchpoint
)
2893 /* Don't stop: read watchpoints shouldn't fire if
2894 the value has changed. This is for targets
2895 which cannot set read-only watchpoints. */
2896 bs
->print_it
= print_it_noop
;
2902 case WP_VALUE_NOT_CHANGED
:
2909 /* Error from catch_errors. */
2910 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2911 if (b
->related_breakpoint
)
2912 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2913 b
->disposition
= disp_del_at_next_stop
;
2914 /* We've already printed what needs to be printed. */
2915 bs
->print_it
= print_it_done
;
2919 else /* found == 0 */
2921 /* This is a case where some watchpoint(s) triggered,
2922 but not at the address of this watchpoint (FOUND
2923 was left zero). So don't print anything for this
2925 bs
->print_it
= print_it_noop
;
2932 /* By definition, an encountered breakpoint is a triggered
2936 real_breakpoint
= 1;
2939 if (frame_id_p (b
->frame_id
)
2940 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2944 int value_is_zero
= 0;
2948 /* Need to select the frame, with all that implies
2949 so that the conditions will have the right context. */
2950 select_frame (get_current_frame ());
2952 = catch_errors (breakpoint_cond_eval
, (b
->cond
),
2953 "Error in testing breakpoint condition:\n",
2955 /* FIXME-someday, should give breakpoint # */
2958 if (b
->cond
&& value_is_zero
)
2961 /* Don't consider this a hit. */
2964 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2967 /* Don't consider this a hit. */
2970 else if (b
->ignore_count
> 0)
2973 annotate_ignore_count_change ();
2978 /* We will stop here */
2979 if (b
->disposition
== disp_disable
)
2980 b
->enable_state
= bp_disabled
;
2983 bs
->commands
= b
->commands
;
2985 (strcmp ("silent", bs
->commands
->line
) == 0
2986 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
2988 bs
->commands
= bs
->commands
->next
;
2991 bs
->commands
= copy_command_lines (bs
->commands
);
2994 /* Print nothing for this entry if we dont stop or if we dont print. */
2995 if (bs
->stop
== 0 || bs
->print
== 0)
2996 bs
->print_it
= print_it_noop
;
2999 bs
->next
= NULL
; /* Terminate the chain */
3000 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3002 /* The value of a hardware watchpoint hasn't changed, but the
3003 intermediate memory locations we are watching may have. */
3004 if (bs
&& !bs
->stop
&&
3005 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
3006 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
3007 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
3009 remove_breakpoints ();
3010 insert_breakpoints ();
3015 /* Tell what to do about this bpstat. */
3017 bpstat_what (bpstat bs
)
3019 /* Classify each bpstat as one of the following. */
3022 /* This bpstat element has no effect on the main_action. */
3025 /* There was a watchpoint, stop but don't print. */
3028 /* There was a watchpoint, stop and print. */
3031 /* There was a breakpoint but we're not stopping. */
3034 /* There was a breakpoint, stop but don't print. */
3037 /* There was a breakpoint, stop and print. */
3040 /* We hit the longjmp breakpoint. */
3043 /* We hit the longjmp_resume breakpoint. */
3046 /* We hit the step_resume breakpoint. */
3049 /* We hit the shared library event breakpoint. */
3052 /* We caught a shared library event. */
3055 /* This is just used to count how many enums there are. */
3059 /* Here is the table which drives this routine. So that we can
3060 format it pretty, we define some abbreviations for the
3061 enum bpstat_what codes. */
3062 #define kc BPSTAT_WHAT_KEEP_CHECKING
3063 #define ss BPSTAT_WHAT_STOP_SILENT
3064 #define sn BPSTAT_WHAT_STOP_NOISY
3065 #define sgl BPSTAT_WHAT_SINGLE
3066 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3067 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3068 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
3069 #define sr BPSTAT_WHAT_STEP_RESUME
3070 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3071 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3073 /* "Can't happen." Might want to print an error message.
3074 abort() is not out of the question, but chances are GDB is just
3075 a bit confused, not unusable. */
3076 #define err BPSTAT_WHAT_STOP_NOISY
3078 /* Given an old action and a class, come up with a new action. */
3079 /* One interesting property of this table is that wp_silent is the same
3080 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3081 after stopping, the check for whether to step over a breakpoint
3082 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3083 reference to how we stopped. We retain separate wp_silent and
3084 bp_silent codes in case we want to change that someday.
3086 Another possibly interesting property of this table is that
3087 there's a partial ordering, priority-like, of the actions. Once
3088 you've decided that some action is appropriate, you'll never go
3089 back and decide something of a lower priority is better. The
3092 kc < clr sgl shl shlr slr sn sr ss
3093 sgl < clrs shl shlr slr sn sr ss
3094 slr < err shl shlr sn sr ss
3095 clr < clrs err shl shlr sn sr ss
3096 clrs < err shl shlr sn sr ss
3103 What I think this means is that we don't need a damned table
3104 here. If you just put the rows and columns in the right order,
3105 it'd look awfully regular. We could simply walk the bpstat list
3106 and choose the highest priority action we find, with a little
3107 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3108 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3109 is messy anyway). */
3111 /* step_resume entries: a step resume breakpoint overrides another
3112 breakpoint of signal handling (see comment in wait_for_inferior
3113 at where we set the step_resume breakpoint). */
3115 static const enum bpstat_what_main_action
3116 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3119 /* kc ss sn sgl slr clr clrs sr shl shlr
3122 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, shl
, shlr
},
3124 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3126 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3128 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, shl
, shlr
},
3130 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3132 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3134 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, shl
, shlr
},
3136 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, shl
, shlr
},
3138 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3140 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3142 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3157 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3158 struct bpstat_what retval
;
3160 retval
.call_dummy
= 0;
3161 for (; bs
!= NULL
; bs
= bs
->next
)
3163 enum class bs_class
= no_effect
;
3164 if (bs
->breakpoint_at
== NULL
)
3165 /* I suspect this can happen if it was a momentary breakpoint
3166 which has since been deleted. */
3168 switch (bs
->breakpoint_at
->type
)
3174 case bp_hardware_breakpoint
:
3180 bs_class
= bp_noisy
;
3182 bs_class
= bp_silent
;
3185 bs_class
= bp_nostop
;
3188 case bp_hardware_watchpoint
:
3189 case bp_read_watchpoint
:
3190 case bp_access_watchpoint
:
3194 bs_class
= wp_noisy
;
3196 bs_class
= wp_silent
;
3199 /* There was a watchpoint, but we're not stopping.
3200 This requires no further action. */
3201 bs_class
= no_effect
;
3204 bs_class
= long_jump
;
3206 case bp_longjmp_resume
:
3207 bs_class
= long_resume
;
3209 case bp_step_resume
:
3212 bs_class
= step_resume
;
3215 /* It is for the wrong frame. */
3216 bs_class
= bp_nostop
;
3218 case bp_watchpoint_scope
:
3219 bs_class
= bp_nostop
;
3221 case bp_shlib_event
:
3222 bs_class
= shlib_event
;
3224 case bp_thread_event
:
3225 case bp_overlay_event
:
3226 bs_class
= bp_nostop
;
3229 case bp_catch_unload
:
3230 /* Only if this catchpoint triggered should we cause the
3231 step-out-of-dld behaviour. Otherwise, we ignore this
3234 bs_class
= catch_shlib_event
;
3236 bs_class
= no_effect
;
3239 case bp_catch_vfork
:
3244 bs_class
= bp_noisy
;
3246 bs_class
= bp_silent
;
3249 /* There was a catchpoint, but we're not stopping.
3250 This requires no further action. */
3251 bs_class
= no_effect
;
3253 case bp_catch_catch
:
3254 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
3255 bs_class
= bp_nostop
;
3257 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3259 case bp_catch_throw
:
3260 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3261 bs_class
= bp_nostop
;
3263 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3266 /* Make sure the action is stop (silent or noisy),
3267 so infrun.c pops the dummy frame. */
3268 bs_class
= bp_silent
;
3269 retval
.call_dummy
= 1;
3272 current_action
= table
[(int) bs_class
][(int) current_action
];
3274 retval
.main_action
= current_action
;
3278 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3279 without hardware support). This isn't related to a specific bpstat,
3280 just to things like whether watchpoints are set. */
3283 bpstat_should_step (void)
3285 struct breakpoint
*b
;
3287 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3292 /* Nonzero if there are enabled hardware watchpoints. */
3294 bpstat_have_active_hw_watchpoints (void)
3296 struct bp_location
*bpt
;
3297 ALL_BP_LOCATIONS (bpt
)
3298 if (breakpoint_enabled (bpt
->owner
)
3300 && bpt
->loc_type
== bp_loc_hardware_watchpoint
)
3306 /* Given a bpstat that records zero or more triggered eventpoints, this
3307 function returns another bpstat which contains only the catchpoints
3308 on that first list, if any. */
3310 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3312 struct bpstats root_bs
[1];
3313 bpstat bs
= root_bs
;
3314 struct breakpoint
*ep
;
3317 bpstat_clear (cp_list
);
3318 root_bs
->next
= NULL
;
3320 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3322 /* Is this eventpoint a catchpoint? If not, ignore it. */
3323 ep
= ep_list
->breakpoint_at
;
3326 if ((ep
->type
!= bp_catch_load
) &&
3327 (ep
->type
!= bp_catch_unload
) &&
3328 (ep
->type
!= bp_catch_catch
) &&
3329 (ep
->type
!= bp_catch_throw
))
3330 /* pai: (temp) ADD fork/vfork here!! */
3333 /* Yes; add it to the list. */
3334 bs
= bpstat_alloc (ep
, bs
);
3339 #if defined(SOLIB_ADD)
3340 /* Also, for each triggered catchpoint, tag it with the name of
3341 the library that caused this trigger. (We copy the name now,
3342 because it's only guaranteed to be available NOW, when the
3343 catchpoint triggers. Clients who may wish to know the name
3344 later must get it from the catchpoint itself.) */
3345 if (ep
->triggered_dll_pathname
!= NULL
)
3346 xfree (ep
->triggered_dll_pathname
);
3347 if (ep
->type
== bp_catch_load
)
3348 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3349 PIDGET (inferior_ptid
));
3351 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3352 PIDGET (inferior_ptid
));
3354 dll_pathname
= NULL
;
3358 ep
->triggered_dll_pathname
= (char *)
3359 xmalloc (strlen (dll_pathname
) + 1);
3360 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3363 ep
->triggered_dll_pathname
= NULL
;
3369 /* Print B to gdb_stdout. */
3371 print_one_breakpoint (struct breakpoint
*b
,
3372 CORE_ADDR
*last_addr
)
3374 struct command_line
*l
;
3376 struct ep_type_description
3381 static struct ep_type_description bptypes
[] =
3383 {bp_none
, "?deleted?"},
3384 {bp_breakpoint
, "breakpoint"},
3385 {bp_hardware_breakpoint
, "hw breakpoint"},
3386 {bp_until
, "until"},
3387 {bp_finish
, "finish"},
3388 {bp_watchpoint
, "watchpoint"},
3389 {bp_hardware_watchpoint
, "hw watchpoint"},
3390 {bp_read_watchpoint
, "read watchpoint"},
3391 {bp_access_watchpoint
, "acc watchpoint"},
3392 {bp_longjmp
, "longjmp"},
3393 {bp_longjmp_resume
, "longjmp resume"},
3394 {bp_step_resume
, "step resume"},
3395 {bp_watchpoint_scope
, "watchpoint scope"},
3396 {bp_call_dummy
, "call dummy"},
3397 {bp_shlib_event
, "shlib events"},
3398 {bp_thread_event
, "thread events"},
3399 {bp_overlay_event
, "overlay events"},
3400 {bp_catch_load
, "catch load"},
3401 {bp_catch_unload
, "catch unload"},
3402 {bp_catch_fork
, "catch fork"},
3403 {bp_catch_vfork
, "catch vfork"},
3404 {bp_catch_exec
, "catch exec"},
3405 {bp_catch_catch
, "catch catch"},
3406 {bp_catch_throw
, "catch throw"}
3409 static char *bpdisps
[] =
3410 {"del", "dstp", "dis", "keep"};
3411 static char bpenables
[] = "nynny";
3412 char wrap_indent
[80];
3413 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3414 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3415 struct cleanup
*bkpt_chain
;
3418 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3422 ui_out_field_int (uiout
, "number", b
->number
);
3426 if (((int) b
->type
> (sizeof (bptypes
) / sizeof (bptypes
[0])))
3427 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3428 internal_error (__FILE__
, __LINE__
,
3429 _("bptypes table does not describe type #%d."),
3431 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3435 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3439 ui_out_field_fmt (uiout
, "enabled", "%c", bpenables
[(int) b
->enable_state
]);
3440 ui_out_spaces (uiout
, 2);
3443 strcpy (wrap_indent
, " ");
3446 if (TARGET_ADDR_BIT
<= 32)
3447 strcat (wrap_indent
, " ");
3449 strcat (wrap_indent
, " ");
3452 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3453 b
->ops
->print_one (b
, last_addr
);
3458 internal_error (__FILE__
, __LINE__
,
3459 _("print_one_breakpoint: bp_none encountered\n"));
3463 case bp_hardware_watchpoint
:
3464 case bp_read_watchpoint
:
3465 case bp_access_watchpoint
:
3466 /* Field 4, the address, is omitted (which makes the columns
3467 not line up too nicely with the headers, but the effect
3468 is relatively readable). */
3470 ui_out_field_skip (uiout
, "addr");
3472 print_expression (b
->exp
, stb
->stream
);
3473 ui_out_field_stream (uiout
, "what", stb
);
3477 case bp_catch_unload
:
3478 /* Field 4, the address, is omitted (which makes the columns
3479 not line up too nicely with the headers, but the effect
3480 is relatively readable). */
3482 ui_out_field_skip (uiout
, "addr");
3484 if (b
->dll_pathname
== NULL
)
3486 ui_out_field_string (uiout
, "what", "<any library>");
3487 ui_out_spaces (uiout
, 1);
3491 ui_out_text (uiout
, "library \"");
3492 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3493 ui_out_text (uiout
, "\" ");
3498 case bp_catch_vfork
:
3499 /* Field 4, the address, is omitted (which makes the columns
3500 not line up too nicely with the headers, but the effect
3501 is relatively readable). */
3503 ui_out_field_skip (uiout
, "addr");
3505 if (b
->forked_inferior_pid
!= 0)
3507 ui_out_text (uiout
, "process ");
3508 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3509 ui_out_spaces (uiout
, 1);
3514 /* Field 4, the address, is omitted (which makes the columns
3515 not line up too nicely with the headers, but the effect
3516 is relatively readable). */
3518 ui_out_field_skip (uiout
, "addr");
3520 if (b
->exec_pathname
!= NULL
)
3522 ui_out_text (uiout
, "program \"");
3523 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3524 ui_out_text (uiout
, "\" ");
3528 case bp_catch_catch
:
3529 /* Field 4, the address, is omitted (which makes the columns
3530 not line up too nicely with the headers, but the effect
3531 is relatively readable). */
3533 ui_out_field_skip (uiout
, "addr");
3535 ui_out_field_string (uiout
, "what", "exception catch");
3536 ui_out_spaces (uiout
, 1);
3539 case bp_catch_throw
:
3540 /* Field 4, the address, is omitted (which makes the columns
3541 not line up too nicely with the headers, but the effect
3542 is relatively readable). */
3544 ui_out_field_skip (uiout
, "addr");
3546 ui_out_field_string (uiout
, "what", "exception throw");
3547 ui_out_spaces (uiout
, 1);
3551 case bp_hardware_breakpoint
:
3555 case bp_longjmp_resume
:
3556 case bp_step_resume
:
3557 case bp_watchpoint_scope
:
3559 case bp_shlib_event
:
3560 case bp_thread_event
:
3561 case bp_overlay_event
:
3566 ui_out_field_string (uiout
, "addr", "<PENDING>");
3568 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
3571 *last_addr
= b
->loc
->address
;
3574 sym
= find_pc_sect_function (b
->loc
->address
, b
->loc
->section
);
3577 ui_out_text (uiout
, "in ");
3578 ui_out_field_string (uiout
, "func",
3579 SYMBOL_PRINT_NAME (sym
));
3580 ui_out_wrap_hint (uiout
, wrap_indent
);
3581 ui_out_text (uiout
, " at ");
3583 ui_out_field_string (uiout
, "file", b
->source_file
);
3584 ui_out_text (uiout
, ":");
3586 if (ui_out_is_mi_like_p (uiout
))
3588 struct symtab_and_line sal
= find_pc_line (b
->loc
->address
, 0);
3589 char *fullname
= symtab_to_fullname (sal
.symtab
);
3592 ui_out_field_string (uiout
, "fullname", fullname
);
3595 ui_out_field_int (uiout
, "line", b
->line_number
);
3597 else if (b
->pending
)
3599 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3603 print_address_symbolic (b
->loc
->address
, stb
->stream
, demangle
, "");
3604 ui_out_field_stream (uiout
, "at", stb
);
3609 if (b
->thread
!= -1)
3611 /* FIXME: This seems to be redundant and lost here; see the
3612 "stop only in" line a little further down. */
3613 ui_out_text (uiout
, " thread ");
3614 ui_out_field_int (uiout
, "thread", b
->thread
);
3617 ui_out_text (uiout
, "\n");
3619 if (frame_id_p (b
->frame_id
))
3622 ui_out_text (uiout
, "\tstop only in stack frame at ");
3623 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3625 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3626 ui_out_text (uiout
, "\n");
3629 if (b
->cond
&& !ada_exception_catchpoint_p (b
))
3631 /* We do not print the condition for Ada exception catchpoints
3632 because the condition is an internal implementation detail
3633 that we do not want to expose to the user. */
3635 ui_out_text (uiout
, "\tstop only if ");
3636 print_expression (b
->cond
, stb
->stream
);
3637 ui_out_field_stream (uiout
, "cond", stb
);
3638 ui_out_text (uiout
, "\n");
3641 if (b
->pending
&& b
->cond_string
)
3644 ui_out_text (uiout
, "\tstop only if ");
3645 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3646 ui_out_text (uiout
, "\n");
3649 if (b
->thread
!= -1)
3651 /* FIXME should make an annotation for this */
3652 ui_out_text (uiout
, "\tstop only in thread ");
3653 ui_out_field_int (uiout
, "thread", b
->thread
);
3654 ui_out_text (uiout
, "\n");
3657 if (show_breakpoint_hit_counts
&& b
->hit_count
)
3659 /* FIXME should make an annotation for this */
3660 if (ep_is_catchpoint (b
))
3661 ui_out_text (uiout
, "\tcatchpoint");
3663 ui_out_text (uiout
, "\tbreakpoint");
3664 ui_out_text (uiout
, " already hit ");
3665 ui_out_field_int (uiout
, "times", b
->hit_count
);
3666 if (b
->hit_count
== 1)
3667 ui_out_text (uiout
, " time\n");
3669 ui_out_text (uiout
, " times\n");
3672 /* Output the count also if it is zero, but only if this is
3673 mi. FIXME: Should have a better test for this. */
3674 if (ui_out_is_mi_like_p (uiout
))
3675 if (show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3676 ui_out_field_int (uiout
, "times", b
->hit_count
);
3678 if (b
->ignore_count
)
3681 ui_out_text (uiout
, "\tignore next ");
3682 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3683 ui_out_text (uiout
, " hits\n");
3686 if ((l
= b
->commands
))
3688 struct cleanup
*script_chain
;
3691 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3692 print_command_lines (uiout
, l
, 4);
3693 do_cleanups (script_chain
);
3695 do_cleanups (bkpt_chain
);
3696 do_cleanups (old_chain
);
3699 struct captured_breakpoint_query_args
3705 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3707 struct captured_breakpoint_query_args
*args
= data
;
3708 struct breakpoint
*b
;
3709 CORE_ADDR dummy_addr
= 0;
3712 if (args
->bnum
== b
->number
)
3714 print_one_breakpoint (b
, &dummy_addr
);
3722 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3724 struct captured_breakpoint_query_args args
;
3726 /* For the moment we don't trust print_one_breakpoint() to not throw
3728 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3729 error_message
, RETURN_MASK_ALL
) < 0)
3735 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3736 catchpoints, et.al.). */
3739 user_settable_breakpoint (const struct breakpoint
*b
)
3741 return (b
->type
== bp_breakpoint
3742 || b
->type
== bp_catch_load
3743 || b
->type
== bp_catch_unload
3744 || b
->type
== bp_catch_fork
3745 || b
->type
== bp_catch_vfork
3746 || b
->type
== bp_catch_exec
3747 || b
->type
== bp_catch_catch
3748 || b
->type
== bp_catch_throw
3749 || b
->type
== bp_hardware_breakpoint
3750 || b
->type
== bp_watchpoint
3751 || b
->type
== bp_read_watchpoint
3752 || b
->type
== bp_access_watchpoint
3753 || b
->type
== bp_hardware_watchpoint
);
3756 /* Print information on user settable breakpoint (watchpoint, etc)
3757 number BNUM. If BNUM is -1 print all user settable breakpoints.
3758 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3761 breakpoint_1 (int bnum
, int allflag
)
3763 struct breakpoint
*b
;
3764 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3765 int nr_printable_breakpoints
;
3766 struct cleanup
*bkpttbl_chain
;
3768 /* Compute the number of rows in the table. */
3769 nr_printable_breakpoints
= 0;
3772 || bnum
== b
->number
)
3774 if (allflag
|| user_settable_breakpoint (b
))
3775 nr_printable_breakpoints
++;
3780 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3784 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3787 if (nr_printable_breakpoints
> 0)
3788 annotate_breakpoints_headers ();
3789 if (nr_printable_breakpoints
> 0)
3791 ui_out_table_header (uiout
, 3, ui_left
, "number", "Num"); /* 1 */
3792 if (nr_printable_breakpoints
> 0)
3794 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3795 if (nr_printable_breakpoints
> 0)
3797 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3798 if (nr_printable_breakpoints
> 0)
3800 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3803 if (nr_printable_breakpoints
> 0)
3805 if (TARGET_ADDR_BIT
<= 32)
3806 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3808 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3810 if (nr_printable_breakpoints
> 0)
3812 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3813 ui_out_table_body (uiout
);
3814 if (nr_printable_breakpoints
> 0)
3815 annotate_breakpoints_table ();
3819 || bnum
== b
->number
)
3821 /* We only print out user settable breakpoints unless the
3823 if (allflag
|| user_settable_breakpoint (b
))
3824 print_one_breakpoint (b
, &last_addr
);
3827 do_cleanups (bkpttbl_chain
);
3829 if (nr_printable_breakpoints
== 0)
3832 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3834 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3839 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3840 that a comparison of an unsigned with -1 is always false. */
3841 if (last_addr
!= (CORE_ADDR
) -1)
3842 set_next_address (last_addr
);
3845 /* FIXME? Should this be moved up so that it is only called when
3846 there have been breakpoints? */
3847 annotate_breakpoints_table_end ();
3851 breakpoints_info (char *bnum_exp
, int from_tty
)
3856 bnum
= parse_and_eval_long (bnum_exp
);
3858 breakpoint_1 (bnum
, 0);
3862 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3867 bnum
= parse_and_eval_long (bnum_exp
);
3869 breakpoint_1 (bnum
, 1);
3872 /* Print a message describing any breakpoints set at PC. */
3875 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
3878 struct breakpoint
*b
;
3881 if (b
->loc
->address
== pc
) /* address match / overlay match */
3882 if (!b
->pending
&& (!overlay_debugging
|| b
->loc
->section
== section
))
3887 printf_filtered (_("Note: breakpoint "));
3888 else /* if (others == ???) */
3889 printf_filtered (_("Note: breakpoints "));
3891 if (b
->loc
->address
== pc
) /* address match / overlay match */
3892 if (!b
->pending
&& (!overlay_debugging
|| b
->loc
->section
== section
))
3895 printf_filtered ("%d", b
->number
);
3896 if (b
->thread
== -1 && thread
!= -1)
3897 printf_filtered (" (all threads)");
3898 else if (b
->thread
!= -1)
3899 printf_filtered (" (thread %d)", b
->thread
);
3900 printf_filtered ("%s%s ",
3901 ((b
->enable_state
== bp_disabled
||
3902 b
->enable_state
== bp_shlib_disabled
||
3903 b
->enable_state
== bp_call_disabled
)
3905 : b
->enable_state
== bp_permanent
3909 : ((others
== 1) ? " and" : ""));
3911 printf_filtered (_("also set at pc "));
3912 deprecated_print_address_numeric (pc
, 1, gdb_stdout
);
3913 printf_filtered (".\n");
3917 /* Set the default place to put a breakpoint
3918 for the `break' command with no arguments. */
3921 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3924 default_breakpoint_valid
= valid
;
3925 default_breakpoint_address
= addr
;
3926 default_breakpoint_symtab
= symtab
;
3927 default_breakpoint_line
= line
;
3930 /* Return true iff it is meaningful to use the address member of
3931 BPT. For some breakpoint types, the address member is irrelevant
3932 and it makes no sense to attempt to compare it to other addresses
3933 (or use it for any other purpose either).
3935 More specifically, each of the following breakpoint types will always
3936 have a zero valued address and we don't want check_duplicates() to mark
3937 breakpoints of any of these types to be a duplicate of an actual
3938 breakpoint at address zero:
3941 bp_hardware_watchpoint
3943 bp_access_watchpoint
3950 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3952 enum bptype type
= bpt
->type
;
3954 return (type
!= bp_watchpoint
3955 && type
!= bp_hardware_watchpoint
3956 && type
!= bp_read_watchpoint
3957 && type
!= bp_access_watchpoint
3958 && type
!= bp_catch_exec
3959 && type
!= bp_longjmp_resume
3960 && type
!= bp_catch_fork
3961 && type
!= bp_catch_vfork
);
3964 /* Rescan breakpoints at the same address and section as BPT,
3965 marking the first one as "first" and any others as "duplicates".
3966 This is so that the bpt instruction is only inserted once.
3967 If we have a permanent breakpoint at the same place as BPT, make
3968 that one the official one, and the rest as duplicates. */
3971 check_duplicates (struct breakpoint
*bpt
)
3973 struct bp_location
*b
;
3975 struct bp_location
*perm_bp
= 0;
3976 CORE_ADDR address
= bpt
->loc
->address
;
3977 asection
*section
= bpt
->loc
->section
;
3979 if (! breakpoint_address_is_meaningful (bpt
))
3982 ALL_BP_LOCATIONS (b
)
3983 if (b
->owner
->enable_state
!= bp_disabled
3984 && b
->owner
->enable_state
!= bp_shlib_disabled
3985 && !b
->owner
->pending
3986 && b
->owner
->enable_state
!= bp_call_disabled
3987 && b
->address
== address
/* address / overlay match */
3988 && (!overlay_debugging
|| b
->section
== section
)
3989 && breakpoint_address_is_meaningful (b
->owner
))
3991 /* Have we found a permanent breakpoint? */
3992 if (b
->owner
->enable_state
== bp_permanent
)
3999 b
->duplicate
= count
> 1;
4002 /* If we found a permanent breakpoint at this address, go over the
4003 list again and declare all the other breakpoints there to be the
4007 perm_bp
->duplicate
= 0;
4009 /* Permanent breakpoint should always be inserted. */
4010 if (! perm_bp
->inserted
)
4011 internal_error (__FILE__
, __LINE__
,
4012 _("allegedly permanent breakpoint is not "
4013 "actually inserted"));
4015 ALL_BP_LOCATIONS (b
)
4018 if (b
->owner
->enable_state
!= bp_disabled
4019 && b
->owner
->enable_state
!= bp_shlib_disabled
4020 && !b
->owner
->pending
4021 && b
->owner
->enable_state
!= bp_call_disabled
4022 && b
->address
== address
/* address / overlay match */
4023 && (!overlay_debugging
|| b
->section
== section
)
4024 && breakpoint_address_is_meaningful (b
->owner
))
4027 internal_error (__FILE__
, __LINE__
,
4028 _("another breakpoint was inserted on top of "
4029 "a permanent breakpoint"));
4038 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4039 int bnum
, int have_bnum
)
4044 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4045 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4047 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4048 bnum
, astr1
, astr2
);
4050 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4053 /* Adjust a breakpoint's address to account for architectural constraints
4054 on breakpoint placement. Return the adjusted address. Note: Very
4055 few targets require this kind of adjustment. For most targets,
4056 this function is simply the identity function. */
4059 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4061 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4063 /* Very few targets need any kind of breakpoint adjustment. */
4066 else if (bptype
== bp_watchpoint
4067 || bptype
== bp_hardware_watchpoint
4068 || bptype
== bp_read_watchpoint
4069 || bptype
== bp_access_watchpoint
4070 || bptype
== bp_catch_fork
4071 || bptype
== bp_catch_vfork
4072 || bptype
== bp_catch_exec
)
4074 /* Watchpoints and the various bp_catch_* eventpoints should not
4075 have their addresses modified. */
4080 CORE_ADDR adjusted_bpaddr
;
4082 /* Some targets have architectural constraints on the placement
4083 of breakpoint instructions. Obtain the adjusted address. */
4084 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4087 /* An adjusted breakpoint address can significantly alter
4088 a user's expectations. Print a warning if an adjustment
4090 if (adjusted_bpaddr
!= bpaddr
)
4091 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4093 return adjusted_bpaddr
;
4097 /* Allocate a struct bp_location. */
4099 static struct bp_location
*
4100 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4102 struct bp_location
*loc
, *loc_p
;
4104 loc
= xmalloc (sizeof (struct bp_location
));
4105 memset (loc
, 0, sizeof (*loc
));
4115 case bp_longjmp_resume
:
4116 case bp_step_resume
:
4117 case bp_watchpoint_scope
:
4119 case bp_shlib_event
:
4120 case bp_thread_event
:
4121 case bp_overlay_event
:
4123 case bp_catch_unload
:
4124 loc
->loc_type
= bp_loc_software_breakpoint
;
4126 case bp_hardware_breakpoint
:
4127 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4129 case bp_hardware_watchpoint
:
4130 case bp_read_watchpoint
:
4131 case bp_access_watchpoint
:
4132 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4136 case bp_catch_vfork
:
4138 case bp_catch_catch
:
4139 case bp_catch_throw
:
4140 loc
->loc_type
= bp_loc_other
;
4143 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4146 /* Add this breakpoint to the end of the chain. */
4148 loc_p
= bp_location_chain
;
4150 bp_location_chain
= loc
;
4154 loc_p
= loc_p
->next
;
4161 /* set_raw_breakpoint() is a low level routine for allocating and
4162 partially initializing a breakpoint of type BPTYPE. The newly
4163 created breakpoint's address, section, source file name, and line
4164 number are provided by SAL. The newly created and partially
4165 initialized breakpoint is added to the breakpoint chain and
4166 is also returned as the value of this function.
4168 It is expected that the caller will complete the initialization of
4169 the newly created breakpoint struct as well as output any status
4170 information regarding the creation of a new breakpoint. In
4171 particular, set_raw_breakpoint() does NOT set the breakpoint
4172 number! Care should be taken to not allow an error() to occur
4173 prior to completing the initialization of the breakpoint. If this
4174 should happen, a bogus breakpoint will be left on the chain. */
4177 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4179 struct breakpoint
*b
, *b1
;
4180 CORE_ADDR adjusted_address
;
4182 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4183 memset (b
, 0, sizeof (*b
));
4185 /* Adjust the breakpoint's address prior to allocating a location.
4186 Once we call allocate_bp_location(), that mostly uninitialized
4187 location will be placed on the location chain. Adjustment of the
4188 breakpoint may cause read_memory_nobpt() to be called and we do
4189 not want its scan of the location chain to find a breakpoint and
4190 location that's only been partially initialized. */
4191 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4193 b
->loc
= allocate_bp_location (b
, bptype
);
4194 b
->loc
->requested_address
= sal
.pc
;
4195 b
->loc
->address
= adjusted_address
;
4197 if (sal
.symtab
== NULL
)
4198 b
->source_file
= NULL
;
4200 b
->source_file
= savestring (sal
.symtab
->filename
,
4201 strlen (sal
.symtab
->filename
));
4202 b
->loc
->section
= sal
.section
;
4204 b
->language
= current_language
->la_language
;
4205 b
->input_radix
= input_radix
;
4207 b
->line_number
= sal
.line
;
4208 b
->enable_state
= bp_enabled
;
4211 b
->ignore_count
= 0;
4213 b
->frame_id
= null_frame_id
;
4214 b
->dll_pathname
= NULL
;
4215 b
->triggered_dll_pathname
= NULL
;
4216 b
->forked_inferior_pid
= 0;
4217 b
->exec_pathname
= NULL
;
4221 /* Add this breakpoint to the end of the chain
4222 so that a list of breakpoints will come out in order
4223 of increasing numbers. */
4225 b1
= breakpoint_chain
;
4227 breakpoint_chain
= b
;
4235 check_duplicates (b
);
4236 breakpoints_changed ();
4242 /* Note that the breakpoint object B describes a permanent breakpoint
4243 instruction, hard-wired into the inferior's code. */
4245 make_breakpoint_permanent (struct breakpoint
*b
)
4247 b
->enable_state
= bp_permanent
;
4249 /* By definition, permanent breakpoints are already present in the code. */
4250 b
->loc
->inserted
= 1;
4253 static struct breakpoint
*
4254 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4256 static int internal_breakpoint_number
= -1;
4257 struct symtab_and_line sal
;
4258 struct breakpoint
*b
;
4260 init_sal (&sal
); /* initialize to zeroes */
4263 sal
.section
= find_pc_overlay (sal
.pc
);
4265 b
= set_raw_breakpoint (sal
, type
);
4266 b
->number
= internal_breakpoint_number
--;
4267 b
->disposition
= disp_donttouch
;
4274 create_longjmp_breakpoint (char *func_name
)
4276 struct breakpoint
*b
;
4277 struct minimal_symbol
*m
;
4279 if (func_name
== NULL
)
4280 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4283 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4286 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4289 b
->enable_state
= bp_disabled
;
4292 b
->addr_string
= xstrdup (func_name
);
4295 /* Call this routine when stepping and nexting to enable a breakpoint
4296 if we do a longjmp(). When we hit that breakpoint, call
4297 set_longjmp_resume_breakpoint() to figure out where we are going. */
4300 enable_longjmp_breakpoint (void)
4302 struct breakpoint
*b
;
4305 if (b
->type
== bp_longjmp
)
4307 b
->enable_state
= bp_enabled
;
4308 check_duplicates (b
);
4313 disable_longjmp_breakpoint (void)
4315 struct breakpoint
*b
;
4318 if (b
->type
== bp_longjmp
4319 || b
->type
== bp_longjmp_resume
)
4321 b
->enable_state
= bp_disabled
;
4322 check_duplicates (b
);
4327 create_overlay_event_breakpoint (char *func_name
)
4329 struct breakpoint
*b
;
4330 struct minimal_symbol
*m
;
4332 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4335 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4337 b
->addr_string
= xstrdup (func_name
);
4339 if (overlay_debugging
== ovly_auto
)
4341 b
->enable_state
= bp_enabled
;
4342 overlay_events_enabled
= 1;
4346 b
->enable_state
= bp_disabled
;
4347 overlay_events_enabled
= 0;
4352 enable_overlay_breakpoints (void)
4354 struct breakpoint
*b
;
4357 if (b
->type
== bp_overlay_event
)
4359 b
->enable_state
= bp_enabled
;
4360 check_duplicates (b
);
4361 overlay_events_enabled
= 1;
4366 disable_overlay_breakpoints (void)
4368 struct breakpoint
*b
;
4371 if (b
->type
== bp_overlay_event
)
4373 b
->enable_state
= bp_disabled
;
4374 check_duplicates (b
);
4375 overlay_events_enabled
= 0;
4380 create_thread_event_breakpoint (CORE_ADDR address
)
4382 struct breakpoint
*b
;
4384 b
= create_internal_breakpoint (address
, bp_thread_event
);
4386 b
->enable_state
= bp_enabled
;
4387 /* addr_string has to be used or breakpoint_re_set will delete me. */
4388 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4394 remove_thread_event_breakpoints (void)
4396 struct breakpoint
*b
, *temp
;
4398 ALL_BREAKPOINTS_SAFE (b
, temp
)
4399 if (b
->type
== bp_thread_event
)
4400 delete_breakpoint (b
);
4403 struct captured_parse_breakpoint_args
4406 struct symtabs_and_lines
*sals_p
;
4407 char ***addr_string_p
;
4411 struct lang_and_radix
4417 /* Cleanup helper routine to restore the current language and
4420 do_restore_lang_radix_cleanup (void *old
)
4422 struct lang_and_radix
*p
= old
;
4423 set_language (p
->lang
);
4424 input_radix
= p
->radix
;
4427 /* Try and resolve a pending breakpoint. */
4429 resolve_pending_breakpoint (struct breakpoint
*b
)
4431 /* Try and reparse the breakpoint in case the shared library
4433 struct symtabs_and_lines sals
;
4434 struct symtab_and_line pending_sal
;
4435 char **cond_string
= (char **) NULL
;
4436 char *copy_arg
= b
->addr_string
;
4441 struct ui_file
*old_gdb_stderr
;
4442 struct lang_and_radix old_lr
;
4443 struct cleanup
*old_chain
;
4445 /* Set language, input-radix, then reissue breakpoint command.
4446 Ensure the language and input-radix are restored afterwards. */
4447 old_lr
.lang
= current_language
->la_language
;
4448 old_lr
.radix
= input_radix
;
4449 old_chain
= make_cleanup (do_restore_lang_radix_cleanup
, &old_lr
);
4451 set_language (b
->language
);
4452 input_radix
= b
->input_radix
;
4453 rc
= break_command_1 (b
->addr_string
, b
->flag
, b
->from_tty
, b
);
4455 if (rc
== GDB_RC_OK
)
4456 /* Pending breakpoint has been resolved. */
4457 printf_filtered (_("Pending breakpoint \"%s\" resolved\n"), b
->addr_string
);
4459 do_cleanups (old_chain
);
4464 remove_solib_event_breakpoints (void)
4466 struct breakpoint
*b
, *temp
;
4468 ALL_BREAKPOINTS_SAFE (b
, temp
)
4469 if (b
->type
== bp_shlib_event
)
4470 delete_breakpoint (b
);
4474 create_solib_event_breakpoint (CORE_ADDR address
)
4476 struct breakpoint
*b
;
4478 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4482 /* Disable any breakpoints that are on code in shared libraries. Only
4483 apply to enabled breakpoints, disabled ones can just stay disabled. */
4486 disable_breakpoints_in_shlibs (int silent
)
4488 struct breakpoint
*b
;
4489 int disabled_shlib_breaks
= 0;
4491 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4494 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4495 && breakpoint_enabled (b
) && !b
->loc
->duplicate
4497 && PC_SOLIB (b
->loc
->address
)
4499 && solib_address (b
->loc
->address
)
4503 b
->enable_state
= bp_shlib_disabled
;
4506 if (!disabled_shlib_breaks
)
4508 target_terminal_ours_for_output ();
4509 warning (_("Temporarily disabling shared library breakpoints:"));
4511 disabled_shlib_breaks
= 1;
4512 warning (_("breakpoint #%d "), b
->number
);
4518 /* Disable any breakpoints that are in in an unloaded shared library. Only
4519 apply to enabled breakpoints, disabled ones can just stay disabled. */
4522 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4524 struct breakpoint
*b
;
4525 int disabled_shlib_breaks
= 0;
4527 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4530 if ((b
->loc
->loc_type
== bp_loc_hardware_breakpoint
4531 || b
->loc
->loc_type
== bp_loc_software_breakpoint
)
4532 && breakpoint_enabled (b
) && !b
->loc
->duplicate
)
4535 char *so_name
= PC_SOLIB (b
->loc
->address
);
4537 char *so_name
= solib_address (b
->loc
->address
);
4539 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4541 b
->enable_state
= bp_shlib_disabled
;
4542 /* At this point, we cannot rely on remove_breakpoint
4543 succeeding so we must mark the breakpoint as not inserted
4544 to prevent future errors occurring in remove_breakpoints. */
4545 b
->loc
->inserted
= 0;
4546 if (!disabled_shlib_breaks
)
4548 target_terminal_ours_for_output ();
4549 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4552 disabled_shlib_breaks
= 1;
4558 /* Try to reenable any breakpoints in shared libraries. */
4560 re_enable_breakpoints_in_shlibs (void)
4562 struct breakpoint
*b
, *tmp
;
4564 ALL_BREAKPOINTS_SAFE (b
, tmp
)
4566 if (b
->enable_state
== bp_shlib_disabled
)
4571 /* Do not reenable the breakpoint if the shared library is
4572 still not mapped in. */
4574 lib
= PC_SOLIB (b
->loc
->address
);
4576 lib
= solib_address (b
->loc
->address
);
4578 if (lib
!= NULL
&& target_read_memory (b
->loc
->address
, buf
, 1) == 0)
4579 b
->enable_state
= bp_enabled
;
4581 else if (b
->pending
&& (b
->enable_state
== bp_enabled
))
4583 if (resolve_pending_breakpoint (b
) == GDB_RC_OK
)
4584 delete_breakpoint (b
);
4590 solib_load_unload_1 (char *hookname
, int tempflag
, char *dll_pathname
,
4591 char *cond_string
, enum bptype bp_kind
)
4593 struct breakpoint
*b
;
4594 struct symtabs_and_lines sals
;
4595 struct cleanup
*old_chain
;
4596 struct cleanup
*canonical_strings_chain
= NULL
;
4597 char *addr_start
= hookname
;
4598 char *addr_end
= NULL
;
4599 char **canonical
= (char **) NULL
;
4600 int thread
= -1; /* All threads. */
4602 /* Set a breakpoint on the specified hook. */
4603 sals
= decode_line_1 (&hookname
, 1, (struct symtab
*) NULL
,
4604 0, &canonical
, NULL
);
4605 addr_end
= hookname
;
4607 if (sals
.nelts
== 0)
4609 warning (_("Unable to set a breakpoint on dynamic linker callback.\n"
4610 "Suggest linking with /opt/langtools/lib/end.o.\n"
4611 "GDB will be unable to track shl_load/shl_unload calls."));
4614 if (sals
.nelts
!= 1)
4616 warning (_("Unable to set unique breakpoint on dynamic linker callback.\n"
4617 "GDB will be unable to track shl_load/shl_unload calls."));
4621 /* Make sure that all storage allocated in decode_line_1 gets freed
4622 in case the following errors out. */
4623 old_chain
= make_cleanup (xfree
, sals
.sals
);
4624 if (canonical
!= (char **) NULL
)
4626 make_cleanup (xfree
, canonical
);
4627 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
4628 if (canonical
[0] != NULL
)
4629 make_cleanup (xfree
, canonical
[0]);
4632 resolve_sal_pc (&sals
.sals
[0]);
4634 /* Remove the canonical strings from the cleanup, they are needed below. */
4635 if (canonical
!= (char **) NULL
)
4636 discard_cleanups (canonical_strings_chain
);
4638 b
= set_raw_breakpoint (sals
.sals
[0], bp_kind
);
4639 set_breakpoint_count (breakpoint_count
+ 1);
4640 b
->number
= breakpoint_count
;
4642 b
->cond_string
= (cond_string
== NULL
) ?
4643 NULL
: savestring (cond_string
, strlen (cond_string
));
4646 if (canonical
!= (char **) NULL
&& canonical
[0] != NULL
)
4647 b
->addr_string
= canonical
[0];
4648 else if (addr_start
)
4649 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
4651 b
->enable_state
= bp_enabled
;
4652 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4654 if (dll_pathname
== NULL
)
4655 b
->dll_pathname
= NULL
;
4658 b
->dll_pathname
= (char *) xmalloc (strlen (dll_pathname
) + 1);
4659 strcpy (b
->dll_pathname
, dll_pathname
);
4663 do_cleanups (old_chain
);
4667 create_solib_load_event_breakpoint (char *hookname
, int tempflag
,
4668 char *dll_pathname
, char *cond_string
)
4670 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4671 cond_string
, bp_catch_load
);
4675 create_solib_unload_event_breakpoint (char *hookname
, int tempflag
,
4676 char *dll_pathname
, char *cond_string
)
4678 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4679 cond_string
, bp_catch_unload
);
4683 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4684 enum bptype bp_kind
)
4686 struct symtab_and_line sal
;
4687 struct breakpoint
*b
;
4688 int thread
= -1; /* All threads. */
4695 b
= set_raw_breakpoint (sal
, bp_kind
);
4696 set_breakpoint_count (breakpoint_count
+ 1);
4697 b
->number
= breakpoint_count
;
4699 b
->cond_string
= (cond_string
== NULL
) ?
4700 NULL
: savestring (cond_string
, strlen (cond_string
));
4702 b
->addr_string
= NULL
;
4703 b
->enable_state
= bp_enabled
;
4704 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4705 b
->forked_inferior_pid
= 0;
4711 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4713 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4717 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4719 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4723 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4725 struct symtab_and_line sal
;
4726 struct breakpoint
*b
;
4727 int thread
= -1; /* All threads. */
4734 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4735 set_breakpoint_count (breakpoint_count
+ 1);
4736 b
->number
= breakpoint_count
;
4738 b
->cond_string
= (cond_string
== NULL
) ?
4739 NULL
: savestring (cond_string
, strlen (cond_string
));
4741 b
->addr_string
= NULL
;
4742 b
->enable_state
= bp_enabled
;
4743 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4749 hw_breakpoint_used_count (void)
4751 struct breakpoint
*b
;
4756 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4764 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4766 struct breakpoint
*b
;
4769 *other_type_used
= 0;
4772 if (breakpoint_enabled (b
))
4774 if (b
->type
== type
)
4776 else if ((b
->type
== bp_hardware_watchpoint
||
4777 b
->type
== bp_read_watchpoint
||
4778 b
->type
== bp_access_watchpoint
))
4779 *other_type_used
= 1;
4785 /* Call this after hitting the longjmp() breakpoint. Use this to set
4786 a new breakpoint at the target of the jmp_buf.
4788 FIXME - This ought to be done by setting a temporary breakpoint
4789 that gets deleted automatically... */
4792 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4794 struct breakpoint
*b
;
4797 if (b
->type
== bp_longjmp_resume
)
4799 b
->loc
->requested_address
= pc
;
4800 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4802 b
->enable_state
= bp_enabled
;
4803 b
->frame_id
= frame_id
;
4804 check_duplicates (b
);
4810 disable_watchpoints_before_interactive_call_start (void)
4812 struct breakpoint
*b
;
4816 if (((b
->type
== bp_watchpoint
)
4817 || (b
->type
== bp_hardware_watchpoint
)
4818 || (b
->type
== bp_read_watchpoint
)
4819 || (b
->type
== bp_access_watchpoint
)
4820 || ep_is_exception_catchpoint (b
))
4821 && breakpoint_enabled (b
))
4823 b
->enable_state
= bp_call_disabled
;
4824 check_duplicates (b
);
4830 enable_watchpoints_after_interactive_call_stop (void)
4832 struct breakpoint
*b
;
4836 if (((b
->type
== bp_watchpoint
)
4837 || (b
->type
== bp_hardware_watchpoint
)
4838 || (b
->type
== bp_read_watchpoint
)
4839 || (b
->type
== bp_access_watchpoint
)
4840 || ep_is_exception_catchpoint (b
))
4841 && (b
->enable_state
== bp_call_disabled
))
4843 b
->enable_state
= bp_enabled
;
4844 check_duplicates (b
);
4850 /* Set a breakpoint that will evaporate an end of command
4851 at address specified by SAL.
4852 Restrict it to frame FRAME if FRAME is nonzero. */
4855 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4858 struct breakpoint
*b
;
4859 b
= set_raw_breakpoint (sal
, type
);
4860 b
->enable_state
= bp_enabled
;
4861 b
->disposition
= disp_donttouch
;
4862 b
->frame_id
= frame_id
;
4864 /* If we're debugging a multi-threaded program, then we
4865 want momentary breakpoints to be active in only a
4866 single thread of control. */
4867 if (in_thread_list (inferior_ptid
))
4868 b
->thread
= pid_to_thread_id (inferior_ptid
);
4874 /* Tell the user we have just set a breakpoint B. */
4877 mention (struct breakpoint
*b
)
4880 struct cleanup
*old_chain
, *ui_out_chain
;
4881 struct ui_stream
*stb
;
4883 stb
= ui_out_stream_new (uiout
);
4884 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4886 /* FIXME: This is misplaced; mention() is called by things (like
4887 hitting a watchpoint) other than breakpoint creation. It should
4888 be possible to clean this up and at the same time replace the
4889 random calls to breakpoint_changed with this hook, as has already
4890 been done for deprecated_delete_breakpoint_hook and so on. */
4891 if (deprecated_create_breakpoint_hook
)
4892 deprecated_create_breakpoint_hook (b
);
4893 breakpoint_create_event (b
->number
);
4895 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4896 b
->ops
->print_mention (b
);
4901 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4904 ui_out_text (uiout
, "Watchpoint ");
4905 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4906 ui_out_field_int (uiout
, "number", b
->number
);
4907 ui_out_text (uiout
, ": ");
4908 print_expression (b
->exp
, stb
->stream
);
4909 ui_out_field_stream (uiout
, "exp", stb
);
4910 do_cleanups (ui_out_chain
);
4912 case bp_hardware_watchpoint
:
4913 ui_out_text (uiout
, "Hardware watchpoint ");
4914 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4915 ui_out_field_int (uiout
, "number", b
->number
);
4916 ui_out_text (uiout
, ": ");
4917 print_expression (b
->exp
, stb
->stream
);
4918 ui_out_field_stream (uiout
, "exp", stb
);
4919 do_cleanups (ui_out_chain
);
4921 case bp_read_watchpoint
:
4922 ui_out_text (uiout
, "Hardware read watchpoint ");
4923 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4924 ui_out_field_int (uiout
, "number", b
->number
);
4925 ui_out_text (uiout
, ": ");
4926 print_expression (b
->exp
, stb
->stream
);
4927 ui_out_field_stream (uiout
, "exp", stb
);
4928 do_cleanups (ui_out_chain
);
4930 case bp_access_watchpoint
:
4931 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4932 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4933 ui_out_field_int (uiout
, "number", b
->number
);
4934 ui_out_text (uiout
, ": ");
4935 print_expression (b
->exp
, stb
->stream
);
4936 ui_out_field_stream (uiout
, "exp", stb
);
4937 do_cleanups (ui_out_chain
);
4940 if (ui_out_is_mi_like_p (uiout
))
4945 printf_filtered (_("Breakpoint %d"), b
->number
);
4948 case bp_hardware_breakpoint
:
4949 if (ui_out_is_mi_like_p (uiout
))
4954 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4958 case bp_catch_unload
:
4959 printf_filtered (_("Catchpoint %d (%s %s)"),
4961 (b
->type
== bp_catch_load
) ? "load" : "unload",
4962 (b
->dll_pathname
!= NULL
) ?
4963 b
->dll_pathname
: "<any library>");
4966 case bp_catch_vfork
:
4967 printf_filtered (_("Catchpoint %d (%s)"),
4969 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4972 printf_filtered (_("Catchpoint %d (exec)"),
4975 case bp_catch_catch
:
4976 case bp_catch_throw
:
4977 printf_filtered (_("Catchpoint %d (%s)"),
4979 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4985 case bp_longjmp_resume
:
4986 case bp_step_resume
:
4988 case bp_watchpoint_scope
:
4989 case bp_shlib_event
:
4990 case bp_thread_event
:
4991 case bp_overlay_event
:
4997 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5001 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5005 if (addressprint
|| b
->source_file
== NULL
)
5007 printf_filtered (" at ");
5008 deprecated_print_address_numeric (b
->loc
->address
, 1, gdb_stdout
);
5011 printf_filtered (": file %s, line %d.",
5012 b
->source_file
, b
->line_number
);
5015 do_cleanups (old_chain
);
5016 if (ui_out_is_mi_like_p (uiout
))
5018 printf_filtered ("\n");
5022 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5023 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
5024 COND[i] and COND_STRING[i] values.
5026 The parameter PENDING_BP points to a pending breakpoint that is
5027 the basis of the breakpoints currently being created. The pending
5028 breakpoint may contain a separate condition string or commands
5029 that were added after the initial pending breakpoint was created.
5031 NOTE: If the function succeeds, the caller is expected to cleanup
5032 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
5033 array contents). If the function fails (error() is called), the
5034 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5035 COND and SALS arrays and each of those arrays contents. */
5038 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5039 struct expression
**cond
, char **cond_string
,
5040 enum bptype type
, enum bpdisp disposition
,
5041 int thread
, int ignore_count
, int from_tty
,
5042 struct breakpoint
*pending_bp
)
5044 if (type
== bp_hardware_breakpoint
)
5046 int i
= hw_breakpoint_used_count ();
5047 int target_resources_ok
=
5048 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5050 if (target_resources_ok
== 0)
5051 error (_("No hardware breakpoint support in the target."));
5052 else if (target_resources_ok
< 0)
5053 error (_("Hardware breakpoints used exceeds limit."));
5056 /* Now set all the breakpoints. */
5059 for (i
= 0; i
< sals
.nelts
; i
++)
5061 struct breakpoint
*b
;
5062 struct symtab_and_line sal
= sals
.sals
[i
];
5065 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5067 b
= set_raw_breakpoint (sal
, type
);
5068 set_breakpoint_count (breakpoint_count
+ 1);
5069 b
->number
= breakpoint_count
;
5073 b
->addr_string
= addr_string
[i
];
5075 /* addr_string has to be used or breakpoint_re_set will delete
5077 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5078 b
->cond_string
= cond_string
[i
];
5079 b
->ignore_count
= ignore_count
;
5080 b
->enable_state
= bp_enabled
;
5081 b
->disposition
= disposition
;
5082 /* If resolving a pending breakpoint, a check must be made to see if
5083 the user has specified a new condition or commands for the
5084 breakpoint. A new condition will override any condition that was
5085 initially specified with the initial breakpoint command. */
5089 if (pending_bp
->cond_string
)
5091 arg
= pending_bp
->cond_string
;
5092 b
->cond_string
= savestring (arg
, strlen (arg
));
5093 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->loc
->address
), 0);
5095 error (_("Junk at end of pending breakpoint condition expression"));
5097 /* If there are commands associated with the breakpoint, they should
5099 if (pending_bp
->commands
)
5100 b
->commands
= copy_command_lines (pending_bp
->commands
);
5102 /* We have to copy over the ignore_count and thread as well. */
5103 b
->ignore_count
= pending_bp
->ignore_count
;
5104 b
->thread
= pending_bp
->thread
;
5111 /* Parse ARG which is assumed to be a SAL specification possibly
5112 followed by conditionals. On return, SALS contains an array of SAL
5113 addresses found. ADDR_STRING contains a vector of (canonical)
5114 address strings. ARG points to the end of the SAL. */
5117 parse_breakpoint_sals (char **address
,
5118 struct symtabs_and_lines
*sals
,
5119 char ***addr_string
,
5122 char *addr_start
= *address
;
5123 *addr_string
= NULL
;
5124 /* If no arg given, or if first arg is 'if ', use the default
5126 if ((*address
) == NULL
5127 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5129 if (default_breakpoint_valid
)
5131 struct symtab_and_line sal
;
5132 init_sal (&sal
); /* initialize to zeroes */
5133 sals
->sals
= (struct symtab_and_line
*)
5134 xmalloc (sizeof (struct symtab_and_line
));
5135 sal
.pc
= default_breakpoint_address
;
5136 sal
.line
= default_breakpoint_line
;
5137 sal
.symtab
= default_breakpoint_symtab
;
5138 sal
.section
= find_pc_overlay (sal
.pc
);
5139 sals
->sals
[0] = sal
;
5143 error (_("No default breakpoint address now."));
5147 /* Force almost all breakpoints to be in terms of the
5148 current_source_symtab (which is decode_line_1's default). This
5149 should produce the results we want almost all of the time while
5150 leaving default_breakpoint_* alone.
5151 ObjC: However, don't match an Objective-C method name which
5152 may have a '+' or '-' succeeded by a '[' */
5154 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5156 if (default_breakpoint_valid
5158 || ((strchr ("+-", (*address
)[0]) != NULL
)
5159 && ((*address
)[1] != '['))))
5160 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5161 default_breakpoint_line
, addr_string
,
5164 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5165 addr_string
, not_found_ptr
);
5167 /* For any SAL that didn't have a canonical string, fill one in. */
5168 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5169 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5170 if (addr_start
!= (*address
))
5173 for (i
= 0; i
< sals
->nelts
; i
++)
5175 /* Add the string if not present. */
5176 if ((*addr_string
)[i
] == NULL
)
5177 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5183 /* Convert each SAL into a real PC. Verify that the PC can be
5184 inserted as a breakpoint. If it can't throw an error. */
5187 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5191 for (i
= 0; i
< sals
->nelts
; i
++)
5193 resolve_sal_pc (&sals
->sals
[i
]);
5195 /* It's possible for the PC to be nonzero, but still an illegal
5196 value on some targets.
5198 For example, on HP-UX if you start gdb, and before running the
5199 inferior you try to set a breakpoint on a shared library function
5200 "foo" where the inferior doesn't call "foo" directly but does
5201 pass its address to another function call, then we do find a
5202 minimal symbol for the "foo", but it's address is invalid.
5203 (Appears to be an index into a table that the loader sets up
5204 when the inferior is run.)
5206 Give the target a chance to bless sals.sals[i].pc before we
5207 try to make a breakpoint for it. */
5208 #ifdef DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE
5209 if (DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE (sals
->sals
[i
].pc
))
5211 if (address
== NULL
)
5212 error (_("Cannot break without a running program."));
5214 error (_("Cannot break on %s without a running program."),
5222 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5224 struct captured_parse_breakpoint_args
*args
= data
;
5226 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5227 args
->not_found_ptr
);
5230 /* Set a breakpoint according to ARG (function, linenum or *address)
5231 flag: first bit : 0 non-temporary, 1 temporary.
5232 second bit : 0 normal breakpoint, 1 hardware breakpoint.
5234 PENDING_BP is non-NULL when this function is being called to resolve
5235 a pending breakpoint. */
5238 break_command_1 (char *arg
, int flag
, int from_tty
, struct breakpoint
*pending_bp
)
5240 struct gdb_exception e
;
5241 int tempflag
, hardwareflag
;
5242 struct symtabs_and_lines sals
;
5243 struct expression
**cond
= 0;
5244 struct symtab_and_line pending_sal
;
5245 char **cond_string
= (char **) NULL
;
5248 char *addr_start
= arg
;
5250 struct cleanup
*old_chain
;
5251 struct cleanup
*breakpoint_chain
= NULL
;
5252 struct captured_parse_breakpoint_args parse_args
;
5256 int ignore_count
= 0;
5259 hardwareflag
= flag
& BP_HARDWAREFLAG
;
5260 tempflag
= flag
& BP_TEMPFLAG
;
5266 parse_args
.arg_p
= &arg
;
5267 parse_args
.sals_p
= &sals
;
5268 parse_args
.addr_string_p
= &addr_string
;
5269 parse_args
.not_found_ptr
= ¬_found
;
5271 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5272 &parse_args
, RETURN_MASK_ALL
);
5274 /* If caller is interested in rc value from parse, set value. */
5278 exception_print (gdb_stderr
, e
);
5283 case NOT_FOUND_ERROR
:
5284 /* If called to resolve pending breakpoint, just return
5289 exception_print (gdb_stderr
, e
);
5291 /* If pending breakpoint support is turned off, throw
5294 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5295 deprecated_throw_reason (RETURN_ERROR
);
5297 /* If pending breakpoint support is auto query and the user
5298 selects no, then simply return the error code. */
5299 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5300 !nquery ("Make breakpoint pending on future shared library load? "))
5303 /* At this point, either the user was queried about setting
5304 a pending breakpoint and selected yes, or pending
5305 breakpoint behavior is on and thus a pending breakpoint
5306 is defaulted on behalf of the user. */
5307 copy_arg
= xstrdup (addr_start
);
5308 addr_string
= ©_arg
;
5310 sals
.sals
= &pending_sal
;
5315 exception_print (gdb_stderr
, e
);
5323 /* Create a chain of things that always need to be cleaned up. */
5324 old_chain
= make_cleanup (null_cleanup
, 0);
5328 /* Make sure that all storage allocated to SALS gets freed. */
5329 make_cleanup (xfree
, sals
.sals
);
5331 /* Cleanup the addr_string array but not its contents. */
5332 make_cleanup (xfree
, addr_string
);
5335 /* Allocate space for all the cond expressions. */
5336 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5337 make_cleanup (xfree
, cond
);
5339 /* Allocate space for all the cond strings. */
5340 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
5341 make_cleanup (xfree
, cond_string
);
5343 /* ----------------------------- SNIP -----------------------------
5344 Anything added to the cleanup chain beyond this point is assumed
5345 to be part of a breakpoint. If the breakpoint create succeeds
5346 then the memory is not reclaimed. */
5347 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5349 /* Mark the contents of the addr_string for cleanup. These go on
5350 the breakpoint_chain and only occure if the breakpoint create
5352 for (i
= 0; i
< sals
.nelts
; i
++)
5354 if (addr_string
[i
] != NULL
)
5355 make_cleanup (xfree
, addr_string
[i
]);
5358 /* Resolve all line numbers to PC's and verify that the addresses
5359 are ok for the target. */
5361 breakpoint_sals_to_pc (&sals
, addr_start
);
5363 /* Verify that condition can be parsed, before setting any
5364 breakpoints. Allocate a separate condition expression for each
5366 thread
= -1; /* No specific thread yet */
5369 for (i
= 0; i
< sals
.nelts
; i
++)
5376 char *cond_start
= NULL
;
5377 char *cond_end
= NULL
;
5378 while (*tok
== ' ' || *tok
== '\t')
5383 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5386 toklen
= end_tok
- tok
;
5388 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5390 tok
= cond_start
= end_tok
+ 1;
5391 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
),
5393 make_cleanup (xfree
, cond
[i
]);
5395 cond_string
[i
] = savestring (cond_start
,
5396 cond_end
- cond_start
);
5397 make_cleanup (xfree
, cond_string
[i
]);
5399 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5405 thread
= strtol (tok
, &tok
, 0);
5407 error (_("Junk after thread keyword."));
5408 if (!valid_thread_id (thread
))
5409 error (_("Unknown thread %d."), thread
);
5412 error (_("Junk at end of arguments."));
5415 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
5416 hardwareflag
? bp_hardware_breakpoint
5418 tempflag
? disp_del
: disp_donttouch
,
5419 thread
, ignore_count
, from_tty
,
5424 struct symtab_and_line sal
;
5425 struct breakpoint
*b
;
5430 make_cleanup (xfree
, copy_arg
);
5432 b
= set_raw_breakpoint (sal
, hardwareflag
? bp_hardware_breakpoint
5434 set_breakpoint_count (breakpoint_count
+ 1);
5435 b
->number
= breakpoint_count
;
5438 b
->addr_string
= *addr_string
;
5439 b
->cond_string
= *cond_string
;
5440 b
->ignore_count
= ignore_count
;
5442 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5443 b
->from_tty
= from_tty
;
5449 warning (_("Multiple breakpoints were set.\n"
5450 "Use the \"delete\" command to delete unwanted breakpoints."));
5451 /* That's it. Discard the cleanups for data inserted into the
5453 discard_cleanups (breakpoint_chain
);
5454 /* But cleanup everything else. */
5455 do_cleanups (old_chain
);
5460 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5461 linenum or *address) with COND and IGNORE_COUNT. */
5463 struct captured_breakpoint_args
5474 do_captured_breakpoint (struct ui_out
*uiout
, void *data
)
5476 struct captured_breakpoint_args
*args
= data
;
5477 struct symtabs_and_lines sals
;
5478 struct expression
**cond
;
5479 struct cleanup
*old_chain
;
5480 struct cleanup
*breakpoint_chain
= NULL
;
5487 /* Parse the source and lines spec. Delay check that the expression
5488 didn't contain trailing garbage until after cleanups are in
5492 address_end
= args
->address
;
5494 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
, 0);
5499 /* Create a chain of things at always need to be cleaned up. */
5500 old_chain
= make_cleanup (null_cleanup
, 0);
5502 /* Always have a addr_string array, even if it is empty. */
5503 make_cleanup (xfree
, addr_string
);
5505 /* Make sure that all storage allocated to SALS gets freed. */
5506 make_cleanup (xfree
, sals
.sals
);
5508 /* Allocate space for all the cond expressions. */
5509 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5510 make_cleanup (xfree
, cond
);
5512 /* Allocate space for all the cond strings. */
5513 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
5514 make_cleanup (xfree
, cond_string
);
5516 /* ----------------------------- SNIP -----------------------------
5517 Anything added to the cleanup chain beyond this point is assumed
5518 to be part of a breakpoint. If the breakpoint create goes
5519 through then that memory is not cleaned up. */
5520 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5522 /* Mark the contents of the addr_string for cleanup. These go on
5523 the breakpoint_chain and only occure if the breakpoint create
5525 for (i
= 0; i
< sals
.nelts
; i
++)
5527 if (addr_string
[i
] != NULL
)
5528 make_cleanup (xfree
, addr_string
[i
]);
5531 /* Wait until now before checking for garbage at the end of the
5532 address. That way cleanups can take care of freeing any
5534 if (*address_end
!= '\0')
5535 error (_("Garbage %s following breakpoint address"), address_end
);
5537 /* Resolve all line numbers to PC's. */
5538 breakpoint_sals_to_pc (&sals
, args
->address
);
5540 /* Verify that conditions can be parsed, before setting any
5542 for (i
= 0; i
< sals
.nelts
; i
++)
5544 if (args
->condition
!= NULL
)
5546 char *tok
= args
->condition
;
5547 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
5549 error (_("Garbage %s follows condition"), tok
);
5550 make_cleanup (xfree
, cond
[i
]);
5551 cond_string
[i
] = xstrdup (args
->condition
);
5555 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
5556 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
5557 args
->tempflag
? disp_del
: disp_donttouch
,
5558 args
->thread
, args
->ignore_count
, 0/*from-tty*/,
5559 NULL
/*pending_bp*/);
5561 /* That's it. Discard the cleanups for data inserted into the
5563 discard_cleanups (breakpoint_chain
);
5564 /* But cleanup everything else. */
5565 do_cleanups (old_chain
);
5570 gdb_breakpoint (char *address
, char *condition
,
5571 int hardwareflag
, int tempflag
,
5572 int thread
, int ignore_count
,
5573 char **error_message
)
5575 struct captured_breakpoint_args args
;
5576 args
.address
= address
;
5577 args
.condition
= condition
;
5578 args
.hardwareflag
= hardwareflag
;
5579 args
.tempflag
= tempflag
;
5580 args
.thread
= thread
;
5581 args
.ignore_count
= ignore_count
;
5582 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint
, &args
,
5583 error_message
, RETURN_MASK_ALL
) < 0)
5590 /* Helper function for break_command_1 and disassemble_command. */
5593 resolve_sal_pc (struct symtab_and_line
*sal
)
5597 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5599 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5600 error (_("No line %d in file \"%s\"."),
5601 sal
->line
, sal
->symtab
->filename
);
5605 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5607 struct blockvector
*bv
;
5612 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5615 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5616 sym
= block_function (b
);
5619 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5620 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5624 /* It really is worthwhile to have the section, so we'll just
5625 have to look harder. This case can be executed if we have
5626 line numbers but no functions (as can happen in assembly
5629 struct minimal_symbol
*msym
;
5631 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5633 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5640 break_command (char *arg
, int from_tty
)
5642 break_command_1 (arg
, 0, from_tty
, NULL
);
5646 tbreak_command (char *arg
, int from_tty
)
5648 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
, NULL
);
5652 hbreak_command (char *arg
, int from_tty
)
5654 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
, NULL
);
5658 thbreak_command (char *arg
, int from_tty
)
5660 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
, NULL
);
5664 stop_command (char *arg
, int from_tty
)
5666 printf_filtered (_("Specify the type of breakpoint to set.\n\
5667 Usage: stop in <function | address>\n\
5668 stop at <line>\n"));
5672 stopin_command (char *arg
, int from_tty
)
5676 if (arg
== (char *) NULL
)
5678 else if (*arg
!= '*')
5683 /* look for a ':'. If this is a line number specification, then
5684 say it is bad, otherwise, it should be an address or
5685 function/method name */
5686 while (*argptr
&& !hasColon
)
5688 hasColon
= (*argptr
== ':');
5693 badInput
= (*argptr
!= ':'); /* Not a class::method */
5695 badInput
= isdigit (*arg
); /* a simple line number */
5699 printf_filtered (_("Usage: stop in <function | address>\n"));
5701 break_command_1 (arg
, 0, from_tty
, NULL
);
5705 stopat_command (char *arg
, int from_tty
)
5709 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5716 /* look for a ':'. If there is a '::' then get out, otherwise
5717 it is probably a line number. */
5718 while (*argptr
&& !hasColon
)
5720 hasColon
= (*argptr
== ':');
5725 badInput
= (*argptr
== ':'); /* we have class::method */
5727 badInput
= !isdigit (*arg
); /* not a line number */
5731 printf_filtered (_("Usage: stop at <line>\n"));
5733 break_command_1 (arg
, 0, from_tty
, NULL
);
5736 /* accessflag: hw_write: watch write,
5737 hw_read: watch read,
5738 hw_access: watch access (read or write) */
5740 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5742 struct breakpoint
*b
;
5743 struct symtab_and_line sal
;
5744 struct expression
*exp
;
5745 struct block
*exp_valid_block
;
5746 struct value
*val
, *mark
;
5747 struct frame_info
*frame
;
5748 struct frame_info
*prev_frame
= NULL
;
5749 char *exp_start
= NULL
;
5750 char *exp_end
= NULL
;
5751 char *tok
, *end_tok
;
5753 char *cond_start
= NULL
;
5754 char *cond_end
= NULL
;
5755 struct expression
*cond
= NULL
;
5756 int i
, other_type_used
, target_resources_ok
= 0;
5757 enum bptype bp_type
;
5760 init_sal (&sal
); /* initialize to zeroes */
5762 /* Parse arguments. */
5763 innermost_block
= NULL
;
5765 exp
= parse_exp_1 (&arg
, 0, 0);
5767 exp_valid_block
= innermost_block
;
5768 mark
= value_mark ();
5769 val
= evaluate_expression (exp
);
5770 release_value (val
);
5771 if (value_lazy (val
))
5772 value_fetch_lazy (val
);
5775 while (*tok
== ' ' || *tok
== '\t')
5779 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5782 toklen
= end_tok
- tok
;
5783 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5785 tok
= cond_start
= end_tok
+ 1;
5786 cond
= parse_exp_1 (&tok
, 0, 0);
5790 error (_("Junk at end of command."));
5792 if (accessflag
== hw_read
)
5793 bp_type
= bp_read_watchpoint
;
5794 else if (accessflag
== hw_access
)
5795 bp_type
= bp_access_watchpoint
;
5797 bp_type
= bp_hardware_watchpoint
;
5799 mem_cnt
= can_use_hardware_watchpoint (val
);
5800 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5801 error (_("Expression cannot be implemented with read/access watchpoint."));
5804 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5805 target_resources_ok
=
5806 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5808 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5809 error (_("Target does not support this type of hardware watchpoint."));
5811 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5812 error (_("Target can only support one kind of HW watchpoint at a time."));
5815 #if defined(HPUXHPPA)
5816 /* On HP-UX if you set a h/w
5817 watchpoint before the "run" command, the inferior dies with a e.g.,
5818 SIGILL once you start it. I initially believed this was due to a
5819 bad interaction between page protection traps and the initial
5820 startup sequence by the dynamic linker.
5822 However, I tried avoiding that by having HP-UX's implementation of
5823 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5824 yet, which forced slow watches before a "run" or "attach", and it
5825 still fails somewhere in the startup code.
5827 Until I figure out what's happening, I'm disallowing watches altogether
5828 before the "run" or "attach" command. We'll tell the user they must
5829 set watches after getting the program started. */
5830 if (!target_has_execution
)
5832 warning (_("can't do that without a running program; try \"break main\"), \"run\" first");
5835 #endif /* HPUXHPPA */
5837 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5838 watchpoint could not be set. */
5839 if (!mem_cnt
|| target_resources_ok
<= 0)
5840 bp_type
= bp_watchpoint
;
5842 /* Now set up the breakpoint. */
5843 b
= set_raw_breakpoint (sal
, bp_type
);
5844 set_breakpoint_count (breakpoint_count
+ 1);
5845 b
->number
= breakpoint_count
;
5846 b
->disposition
= disp_donttouch
;
5848 b
->exp_valid_block
= exp_valid_block
;
5849 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5853 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5857 frame
= block_innermost_frame (exp_valid_block
);
5860 prev_frame
= get_prev_frame (frame
);
5861 b
->watchpoint_frame
= get_frame_id (frame
);
5865 memset (&b
->watchpoint_frame
, 0, sizeof (b
->watchpoint_frame
));
5868 /* If the expression is "local", then set up a "watchpoint scope"
5869 breakpoint at the point where we've left the scope of the watchpoint
5871 if (innermost_block
)
5875 struct breakpoint
*scope_breakpoint
;
5876 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5877 bp_watchpoint_scope
);
5879 scope_breakpoint
->enable_state
= bp_enabled
;
5881 /* Automatically delete the breakpoint when it hits. */
5882 scope_breakpoint
->disposition
= disp_del
;
5884 /* Only break in the proper frame (help with recursion). */
5885 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5887 /* Set the address at which we will stop. */
5888 scope_breakpoint
->loc
->requested_address
5889 = get_frame_pc (prev_frame
);
5890 scope_breakpoint
->loc
->address
5891 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5892 scope_breakpoint
->type
);
5894 /* The scope breakpoint is related to the watchpoint. We
5895 will need to act on them together. */
5896 b
->related_breakpoint
= scope_breakpoint
;
5899 value_free_to_mark (mark
);
5903 /* Return count of locations need to be watched and can be handled
5904 in hardware. If the watchpoint can not be handled
5905 in hardware return zero. */
5908 can_use_hardware_watchpoint (struct value
*v
)
5910 int found_memory_cnt
= 0;
5911 struct value
*head
= v
;
5913 /* Did the user specifically forbid us to use hardware watchpoints? */
5914 if (!can_use_hw_watchpoints
)
5917 /* Make sure that the value of the expression depends only upon
5918 memory contents, and values computed from them within GDB. If we
5919 find any register references or function calls, we can't use a
5920 hardware watchpoint.
5922 The idea here is that evaluating an expression generates a series
5923 of values, one holding the value of every subexpression. (The
5924 expression a*b+c has five subexpressions: a, b, a*b, c, and
5925 a*b+c.) GDB's values hold almost enough information to establish
5926 the criteria given above --- they identify memory lvalues,
5927 register lvalues, computed values, etcetera. So we can evaluate
5928 the expression, and then scan the chain of values that leaves
5929 behind to decide whether we can detect any possible change to the
5930 expression's final value using only hardware watchpoints.
5932 However, I don't think that the values returned by inferior
5933 function calls are special in any way. So this function may not
5934 notice that an expression involving an inferior function call
5935 can't be watched with hardware watchpoints. FIXME. */
5936 for (; v
; v
= value_next (v
))
5938 if (VALUE_LVAL (v
) == lval_memory
)
5941 /* A lazy memory lvalue is one that GDB never needed to fetch;
5942 we either just used its address (e.g., `a' in `a.b') or
5943 we never needed it at all (e.g., `a' in `a,b'). */
5947 /* Ahh, memory we actually used! Check if we can cover
5948 it with hardware watchpoints. */
5949 struct type
*vtype
= check_typedef (value_type (v
));
5951 /* We only watch structs and arrays if user asked for it
5952 explicitly, never if they just happen to appear in a
5953 middle of some value chain. */
5955 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5956 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5958 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
5959 int len
= TYPE_LENGTH (value_type (v
));
5961 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5968 else if (VALUE_LVAL (v
) != not_lval
5969 && deprecated_value_modifiable (v
) == 0)
5970 return 0; /* ??? What does this represent? */
5971 else if (VALUE_LVAL (v
) == lval_register
)
5972 return 0; /* cannot watch a register with a HW watchpoint */
5975 /* The expression itself looks suitable for using a hardware
5976 watchpoint, but give the target machine a chance to reject it. */
5977 return found_memory_cnt
;
5981 watch_command_wrapper (char *arg
, int from_tty
)
5983 watch_command (arg
, from_tty
);
5987 watch_command (char *arg
, int from_tty
)
5989 watch_command_1 (arg
, hw_write
, from_tty
);
5993 rwatch_command_wrapper (char *arg
, int from_tty
)
5995 rwatch_command (arg
, from_tty
);
5999 rwatch_command (char *arg
, int from_tty
)
6001 watch_command_1 (arg
, hw_read
, from_tty
);
6005 awatch_command_wrapper (char *arg
, int from_tty
)
6007 awatch_command (arg
, from_tty
);
6011 awatch_command (char *arg
, int from_tty
)
6013 watch_command_1 (arg
, hw_access
, from_tty
);
6017 /* Helper routines for the until_command routine in infcmd.c. Here
6018 because it uses the mechanisms of breakpoints. */
6020 /* This function is called by fetch_inferior_event via the
6021 cmd_continuation pointer, to complete the until command. It takes
6022 care of cleaning up the temporary breakpoints set up by the until
6025 until_break_command_continuation (struct continuation_arg
*arg
)
6027 struct cleanup
*cleanups
;
6029 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
6030 do_exec_cleanups (cleanups
);
6034 until_break_command (char *arg
, int from_tty
, int anywhere
)
6036 struct symtabs_and_lines sals
;
6037 struct symtab_and_line sal
;
6038 struct frame_info
*frame
= get_selected_frame (NULL
);
6039 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6040 struct breakpoint
*breakpoint
;
6041 struct cleanup
*old_chain
;
6042 struct continuation_arg
*arg1
;
6045 clear_proceed_status ();
6047 /* Set a breakpoint where the user wants it and at return from
6050 if (default_breakpoint_valid
)
6051 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6052 default_breakpoint_line
, (char ***) NULL
, NULL
);
6054 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6055 0, (char ***) NULL
, NULL
);
6057 if (sals
.nelts
!= 1)
6058 error (_("Couldn't get information on specified line."));
6061 xfree (sals
.sals
); /* malloc'd, so freed */
6064 error (_("Junk at end of arguments."));
6066 resolve_sal_pc (&sal
);
6069 /* If the user told us to continue until a specified location,
6070 we don't specify a frame at which we need to stop. */
6071 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6073 /* Otherwise, specify the current frame, because we want to stop only
6074 at the very same frame. */
6075 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6078 if (!target_can_async_p ())
6079 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6081 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
6083 /* If we are running asynchronously, and the target supports async
6084 execution, we are not waiting for the target to stop, in the call
6085 tp proceed, below. This means that we cannot delete the
6086 brekpoints until the target has actually stopped. The only place
6087 where we get a chance to do that is in fetch_inferior_event, so
6088 we must set things up for that. */
6090 if (target_can_async_p ())
6092 /* In this case the arg for the continuation is just the point
6093 in the exec_cleanups chain from where to start doing
6094 cleanups, because all the continuation does is the cleanups in
6095 the exec_cleanup_chain. */
6097 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6099 arg1
->data
.pointer
= old_chain
;
6101 add_continuation (until_break_command_continuation
, arg1
);
6104 /* Keep within the current frame, or in frames called by the current
6108 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6109 sal
.pc
= get_frame_pc (prev_frame
);
6110 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6112 if (!target_can_async_p ())
6113 make_cleanup_delete_breakpoint (breakpoint
);
6115 make_exec_cleanup_delete_breakpoint (breakpoint
);
6118 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6119 /* Do the cleanups now, anly if we are not running asynchronously,
6120 of if we are, but the target is still synchronous. */
6121 if (!target_can_async_p ())
6122 do_cleanups (old_chain
);
6126 ep_skip_leading_whitespace (char **s
)
6128 if ((s
== NULL
) || (*s
== NULL
))
6130 while (isspace (**s
))
6134 /* This function examines a string, and attempts to find a token
6135 that might be an event name in the leading characters. If a
6136 possible match is found, a pointer to the last character of
6137 the token is returned. Else, NULL is returned. */
6140 ep_find_event_name_end (char *arg
)
6143 char *event_name_end
= NULL
;
6145 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6149 /* We break out of the loop when we find a token delimiter.
6150 Basically, we're looking for alphanumerics and underscores;
6151 anything else delimites the token. */
6154 if (!isalnum (*s
) && (*s
!= '_'))
6160 return event_name_end
;
6164 /* This function attempts to parse an optional "if <cond>" clause
6165 from the arg string. If one is not found, it returns NULL.
6167 Else, it returns a pointer to the condition string. (It does not
6168 attempt to evaluate the string against a particular block.) And,
6169 it updates arg to point to the first character following the parsed
6170 if clause in the arg string. */
6173 ep_parse_optional_if_clause (char **arg
)
6177 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6180 /* Skip the "if" keyword. */
6183 /* Skip any extra leading whitespace, and record the start of the
6184 condition string. */
6185 ep_skip_leading_whitespace (arg
);
6188 /* Assume that the condition occupies the remainder of the arg string. */
6189 (*arg
) += strlen (cond_string
);
6194 /* This function attempts to parse an optional filename from the arg
6195 string. If one is not found, it returns NULL.
6197 Else, it returns a pointer to the parsed filename. (This function
6198 makes no attempt to verify that a file of that name exists, or is
6199 accessible.) And, it updates arg to point to the first character
6200 following the parsed filename in the arg string.
6202 Note that clients needing to preserve the returned filename for
6203 future access should copy it to their own buffers. */
6205 ep_parse_optional_filename (char **arg
)
6207 static char filename
[1024];
6212 if ((*arg_p
== '\0') || isspace (*arg_p
))
6230 /* Commands to deal with catching events, such as signals, exceptions,
6231 process start/exit, etc. */
6235 catch_fork
, catch_vfork
6240 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6243 char *cond_string
= NULL
;
6245 ep_skip_leading_whitespace (&arg
);
6247 /* The allowed syntax is:
6249 catch [v]fork if <cond>
6251 First, check if there's an if clause. */
6252 cond_string
= ep_parse_optional_if_clause (&arg
);
6254 if ((*arg
!= '\0') && !isspace (*arg
))
6255 error (_("Junk at end of arguments."));
6257 /* If this target supports it, create a fork or vfork catchpoint
6258 and enable reporting of such events. */
6262 create_fork_event_catchpoint (tempflag
, cond_string
);
6265 create_vfork_event_catchpoint (tempflag
, cond_string
);
6268 error (_("unsupported or unknown fork kind; cannot catch it"));
6274 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6276 char *cond_string
= NULL
;
6278 ep_skip_leading_whitespace (&arg
);
6280 /* The allowed syntax is:
6282 catch exec if <cond>
6284 First, check if there's an if clause. */
6285 cond_string
= ep_parse_optional_if_clause (&arg
);
6287 if ((*arg
!= '\0') && !isspace (*arg
))
6288 error (_("Junk at end of arguments."));
6290 /* If this target supports it, create an exec catchpoint
6291 and enable reporting of such events. */
6292 create_exec_event_catchpoint (tempflag
, cond_string
);
6296 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6298 char *dll_pathname
= NULL
;
6299 char *cond_string
= NULL
;
6301 ep_skip_leading_whitespace (&arg
);
6303 /* The allowed syntax is:
6305 catch load if <cond>
6306 catch load <filename>
6307 catch load <filename> if <cond>
6309 The user is not allowed to specify the <filename> after an
6312 We'll ignore the pathological case of a file named "if".
6314 First, check if there's an if clause. If so, then there
6315 cannot be a filename. */
6316 cond_string
= ep_parse_optional_if_clause (&arg
);
6318 /* If there was an if clause, then there cannot be a filename.
6319 Else, there might be a filename and an if clause. */
6320 if (cond_string
== NULL
)
6322 dll_pathname
= ep_parse_optional_filename (&arg
);
6323 ep_skip_leading_whitespace (&arg
);
6324 cond_string
= ep_parse_optional_if_clause (&arg
);
6327 if ((*arg
!= '\0') && !isspace (*arg
))
6328 error (_("Junk at end of arguments."));
6330 /* Create a load breakpoint that only triggers when a load of
6331 the specified dll (or any dll, if no pathname was specified)
6333 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6334 dll_pathname
, cond_string
);
6338 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6340 char *dll_pathname
= NULL
;
6341 char *cond_string
= NULL
;
6343 ep_skip_leading_whitespace (&arg
);
6345 /* The allowed syntax is:
6347 catch unload if <cond>
6348 catch unload <filename>
6349 catch unload <filename> if <cond>
6351 The user is not allowed to specify the <filename> after an
6354 We'll ignore the pathological case of a file named "if".
6356 First, check if there's an if clause. If so, then there
6357 cannot be a filename. */
6358 cond_string
= ep_parse_optional_if_clause (&arg
);
6360 /* If there was an if clause, then there cannot be a filename.
6361 Else, there might be a filename and an if clause. */
6362 if (cond_string
== NULL
)
6364 dll_pathname
= ep_parse_optional_filename (&arg
);
6365 ep_skip_leading_whitespace (&arg
);
6366 cond_string
= ep_parse_optional_if_clause (&arg
);
6369 if ((*arg
!= '\0') && !isspace (*arg
))
6370 error (_("Junk at end of arguments."));
6372 /* Create an unload breakpoint that only triggers when an unload of
6373 the specified dll (or any dll, if no pathname was specified)
6375 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6376 dll_pathname
, cond_string
);
6379 /* Commands to deal with catching exceptions. */
6381 /* Set a breakpoint at the specified callback routine for an
6382 exception event callback */
6385 create_exception_catchpoint (int tempflag
, char *cond_string
,
6386 enum exception_event_kind ex_event
,
6387 struct symtab_and_line
*sal
)
6389 struct breakpoint
*b
;
6390 int thread
= -1; /* All threads. */
6393 if (!sal
) /* no exception support? */
6398 case EX_EVENT_THROW
:
6399 bptype
= bp_catch_throw
;
6401 case EX_EVENT_CATCH
:
6402 bptype
= bp_catch_catch
;
6404 default: /* error condition */
6405 error (_("Internal error -- invalid catchpoint kind"));
6408 b
= set_raw_breakpoint (*sal
, bptype
);
6409 set_breakpoint_count (breakpoint_count
+ 1);
6410 b
->number
= breakpoint_count
;
6412 b
->cond_string
= (cond_string
== NULL
) ?
6413 NULL
: savestring (cond_string
, strlen (cond_string
));
6415 b
->addr_string
= NULL
;
6416 b
->enable_state
= bp_enabled
;
6417 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6421 static enum print_stop_action
6422 print_exception_catchpoint (struct breakpoint
*b
)
6424 annotate_catchpoint (b
->number
);
6426 if (strstr (b
->addr_string
, "throw") != NULL
)
6427 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6430 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6433 return PRINT_SRC_AND_LOC
;
6437 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6442 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6445 *last_addr
= b
->loc
->address
;
6446 if (strstr (b
->addr_string
, "throw") != NULL
)
6447 ui_out_field_string (uiout
, "what", "exception throw");
6449 ui_out_field_string (uiout
, "what", "exception catch");
6453 print_mention_exception_catchpoint (struct breakpoint
*b
)
6455 if (strstr (b
->addr_string
, "throw") != NULL
)
6456 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6458 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6461 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6462 print_exception_catchpoint
,
6463 print_one_exception_catchpoint
,
6464 print_mention_exception_catchpoint
6468 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6469 enum exception_event_kind ex_event
, int from_tty
)
6471 char *trigger_func_name
, *nameptr
;
6472 struct symtabs_and_lines sals
;
6473 struct breakpoint
*b
;
6475 if (ex_event
== EX_EVENT_CATCH
)
6476 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6478 trigger_func_name
= xstrdup ("__cxa_throw");
6480 nameptr
= trigger_func_name
;
6481 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6482 if (sals
.nelts
== 0)
6484 xfree (trigger_func_name
);
6488 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6489 set_breakpoint_count (breakpoint_count
+ 1);
6490 b
->number
= breakpoint_count
;
6492 b
->cond_string
= (cond_string
== NULL
) ?
6493 NULL
: savestring (cond_string
, strlen (cond_string
));
6495 b
->addr_string
= trigger_func_name
;
6496 b
->enable_state
= bp_enabled
;
6497 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6498 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6505 /* Deal with "catch catch" and "catch throw" commands */
6508 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6509 int tempflag
, int from_tty
)
6511 char *cond_string
= NULL
;
6512 struct symtab_and_line
*sal
= NULL
;
6514 ep_skip_leading_whitespace (&arg
);
6516 cond_string
= ep_parse_optional_if_clause (&arg
);
6518 if ((*arg
!= '\0') && !isspace (*arg
))
6519 error (_("Junk at end of arguments."));
6521 if ((ex_event
!= EX_EVENT_THROW
) &&
6522 (ex_event
!= EX_EVENT_CATCH
))
6523 error (_("Unsupported or unknown exception event; cannot catch it"));
6525 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6528 /* See if we can find a callback routine */
6529 sal
= target_enable_exception_callback (ex_event
, 1);
6533 /* We have callbacks from the runtime system for exceptions.
6534 Set a breakpoint on the sal found, if no errors */
6535 if (sal
!= (struct symtab_and_line
*) -1)
6536 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6538 return; /* something went wrong with setting up callbacks */
6541 warning (_("Unsupported with this platform/compiler combination."));
6544 /* Create a breakpoint struct for Ada exception catchpoints. */
6547 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6551 struct expression
*cond
,
6552 struct breakpoint_ops
*ops
,
6556 struct breakpoint
*b
;
6560 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6561 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6562 version for exception catchpoints, because two catchpoints
6563 used for different exception names will use the same address.
6564 In this case, a "breakpoint ... also set at..." warning is
6565 unproductive. Besides. the warning phrasing is also a bit
6566 inapropriate, we should use the word catchpoint, and tell
6567 the user what type of catchpoint it is. The above is good
6568 enough for now, though. */
6571 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6572 set_breakpoint_count (breakpoint_count
+ 1);
6574 b
->enable_state
= bp_enabled
;
6575 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6576 b
->number
= breakpoint_count
;
6577 b
->ignore_count
= 0;
6579 b
->addr_string
= addr_string
;
6580 b
->language
= language_ada
;
6581 b
->cond_string
= cond_string
;
6582 b
->exp_string
= exp_string
;
6585 b
->from_tty
= from_tty
;
6590 /* Implement the "catch exception" command. */
6593 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6595 struct symtab_and_line sal
;
6597 char *addr_string
= NULL
;
6598 char *exp_string
= NULL
;
6599 char *cond_string
= NULL
;
6600 struct expression
*cond
= NULL
;
6601 struct breakpoint_ops
*ops
= NULL
;
6603 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6604 &cond_string
, &cond
, &ops
);
6605 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6606 cond_string
, cond
, ops
, tempflag
,
6610 /* Implement the "catch assert" command. */
6613 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6615 struct symtab_and_line sal
;
6616 char *addr_string
= NULL
;
6617 struct breakpoint_ops
*ops
= NULL
;
6619 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6620 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6621 tempflag
, from_tty
);
6624 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6625 inside a catch_errors */
6628 cover_target_enable_exception_callback (void *arg
)
6630 args_for_catchpoint_enable
*args
= arg
;
6631 struct symtab_and_line
*sal
;
6632 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6635 else if (sal
== (struct symtab_and_line
*) -1)
6638 return 1; /*is valid */
6642 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6645 /* The first argument may be an event name, such as "start" or "load".
6646 If so, then handle it as such. If it doesn't match an event name,
6647 then attempt to interpret it as an exception name. (This latter is
6648 the v4.16-and-earlier GDB meaning of the "catch" command.)
6650 First, try to find the bounds of what might be an event name. */
6651 char *arg1_start
= arg
;
6655 if (arg1_start
== NULL
)
6657 /* Old behaviour was to use pre-v-4.16 syntax */
6658 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6660 /* Now, this is not allowed */
6661 error (_("Catch requires an event name."));
6664 arg1_end
= ep_find_event_name_end (arg1_start
);
6665 if (arg1_end
== NULL
)
6666 error (_("catch requires an event"));
6667 arg1_length
= arg1_end
+ 1 - arg1_start
;
6669 /* Try to match what we found against known event names. */
6670 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6672 error (_("Catch of signal not yet implemented"));
6674 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6676 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6677 tempflag
, from_tty
);
6679 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6681 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6682 tempflag
, from_tty
);
6684 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6686 error (_("Catch of thread_start not yet implemented"));
6688 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6690 error (_("Catch of thread_exit not yet implemented"));
6692 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6694 error (_("Catch of thread_join not yet implemented"));
6696 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6698 error (_("Catch of start not yet implemented"));
6700 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6702 error (_("Catch of exit not yet implemented"));
6704 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6706 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6708 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6710 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6712 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6714 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6716 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6718 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6720 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6722 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6724 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6726 error (_("Catch of stop not yet implemented"));
6728 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6730 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6733 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6735 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6738 /* This doesn't appear to be an event name */
6742 /* Pre-v.4.16 behaviour was to treat the argument
6743 as the name of an exception */
6744 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6745 /* Now this is not allowed */
6746 error (_("Unknown event kind specified for catch"));
6751 /* Used by the gui, could be made a worker for other things. */
6754 set_breakpoint_sal (struct symtab_and_line sal
)
6756 struct breakpoint
*b
;
6757 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6758 set_breakpoint_count (breakpoint_count
+ 1);
6759 b
->number
= breakpoint_count
;
6766 catch_command (char *arg
, int from_tty
)
6768 catch_command_1 (arg
, 0, from_tty
);
6773 tcatch_command (char *arg
, int from_tty
)
6775 catch_command_1 (arg
, 1, from_tty
);
6778 /* Delete breakpoints by address or line. */
6781 clear_command (char *arg
, int from_tty
)
6783 struct breakpoint
*b
, *tmp
, *prev
, *found
;
6785 struct symtabs_and_lines sals
;
6786 struct symtab_and_line sal
;
6791 sals
= decode_line_spec (arg
, 1);
6796 sals
.sals
= (struct symtab_and_line
*)
6797 xmalloc (sizeof (struct symtab_and_line
));
6798 make_cleanup (xfree
, sals
.sals
);
6799 init_sal (&sal
); /* initialize to zeroes */
6800 sal
.line
= default_breakpoint_line
;
6801 sal
.symtab
= default_breakpoint_symtab
;
6802 sal
.pc
= default_breakpoint_address
;
6803 if (sal
.symtab
== 0)
6804 error (_("No source file specified."));
6812 /* For each line spec given, delete bps which correspond
6813 to it. Do it in two passes, solely to preserve the current
6814 behavior that from_tty is forced true if we delete more than
6818 for (i
= 0; i
< sals
.nelts
; i
++)
6820 /* If exact pc given, clear bpts at that pc.
6821 If line given (pc == 0), clear all bpts on specified line.
6822 If defaulting, clear all bpts on default line
6825 defaulting sal.pc != 0 tests to do
6830 1 0 <can't happen> */
6835 /* Find all matching breakpoints, remove them from the
6836 breakpoint chain, and add them to the 'found' chain. */
6837 ALL_BREAKPOINTS_SAFE (b
, tmp
)
6839 /* Are we going to delete b? */
6840 if (b
->type
!= bp_none
6841 && b
->type
!= bp_watchpoint
6842 && b
->type
!= bp_hardware_watchpoint
6843 && b
->type
!= bp_read_watchpoint
6844 && b
->type
!= bp_access_watchpoint
6845 /* Not if b is a watchpoint of any sort... */
6846 && (((sal
.pc
&& (b
->loc
->address
== sal
.pc
))
6847 && (!section_is_overlay (b
->loc
->section
)
6848 || b
->loc
->section
== sal
.section
))
6849 /* Yes, if sal.pc matches b (modulo overlays). */
6850 || ((default_match
|| (0 == sal
.pc
))
6851 && b
->source_file
!= NULL
6852 && sal
.symtab
!= NULL
6853 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6854 && b
->line_number
== sal
.line
)))
6855 /* Yes, if sal source file and line matches b. */
6857 /* Remove it from breakpoint_chain... */
6858 if (b
== breakpoint_chain
)
6860 /* b is at the head of the list */
6861 breakpoint_chain
= b
->next
;
6865 prev
->next
= b
->next
;
6867 /* And add it to 'found' chain. */
6873 /* Keep b, and keep a pointer to it. */
6878 /* Now go thru the 'found' chain and delete them. */
6882 error (_("No breakpoint at %s."), arg
);
6884 error (_("No breakpoint at this line."));
6888 from_tty
= 1; /* Always report if deleted more than one */
6892 printf_unfiltered (_("Deleted breakpoint "));
6894 printf_unfiltered (_("Deleted breakpoints "));
6896 breakpoints_changed ();
6900 printf_unfiltered ("%d ", found
->number
);
6902 delete_breakpoint (found
);
6906 putchar_unfiltered ('\n');
6909 /* Delete breakpoint in BS if they are `delete' breakpoints and
6910 all breakpoints that are marked for deletion, whether hit or not.
6911 This is called after any breakpoint is hit, or after errors. */
6914 breakpoint_auto_delete (bpstat bs
)
6916 struct breakpoint
*b
, *temp
;
6918 for (; bs
; bs
= bs
->next
)
6919 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== disp_del
6921 delete_breakpoint (bs
->breakpoint_at
);
6923 ALL_BREAKPOINTS_SAFE (b
, temp
)
6925 if (b
->disposition
== disp_del_at_next_stop
)
6926 delete_breakpoint (b
);
6930 /* Delete a breakpoint and clean up all traces of it in the data
6934 delete_breakpoint (struct breakpoint
*bpt
)
6936 struct breakpoint
*b
;
6938 struct bp_location
*loc
;
6940 gdb_assert (bpt
!= NULL
);
6942 /* Has this bp already been deleted? This can happen because multiple
6943 lists can hold pointers to bp's. bpstat lists are especial culprits.
6945 One example of this happening is a watchpoint's scope bp. When the
6946 scope bp triggers, we notice that the watchpoint is out of scope, and
6947 delete it. We also delete its scope bp. But the scope bp is marked
6948 "auto-deleting", and is already on a bpstat. That bpstat is then
6949 checked for auto-deleting bp's, which are deleted.
6951 A real solution to this problem might involve reference counts in bp's,
6952 and/or giving them pointers back to their referencing bpstat's, and
6953 teaching delete_breakpoint to only free a bp's storage when no more
6954 references were extent. A cheaper bandaid was chosen. */
6955 if (bpt
->type
== bp_none
)
6958 if (deprecated_delete_breakpoint_hook
)
6959 deprecated_delete_breakpoint_hook (bpt
);
6960 breakpoint_delete_event (bpt
->number
);
6962 if (bpt
->loc
->inserted
)
6963 remove_breakpoint (bpt
->loc
, mark_inserted
);
6965 free_valchain (bpt
->loc
);
6967 if (breakpoint_chain
== bpt
)
6968 breakpoint_chain
= bpt
->next
;
6970 if (bp_location_chain
== bpt
->loc
)
6971 bp_location_chain
= bpt
->loc
->next
;
6973 /* If we have callback-style exception catchpoints, don't go through
6974 the adjustments to the C++ runtime library etc. if the inferior
6975 isn't actually running. target_enable_exception_callback for a
6976 null target ops vector gives an undesirable error message, so we
6977 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6978 exceptions are supported in this way, it's OK for now. FIXME */
6979 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
6981 /* Format possible error msg */
6982 char *message
= xstrprintf ("Error in deleting catchpoint %d:\n",
6984 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
6985 args_for_catchpoint_enable args
;
6986 args
.kind
= bpt
->type
== bp_catch_catch
?
6987 EX_EVENT_CATCH
: EX_EVENT_THROW
;
6989 catch_errors (cover_target_enable_exception_callback
, &args
,
6990 message
, RETURN_MASK_ALL
);
6991 do_cleanups (cleanups
);
6998 b
->next
= bpt
->next
;
7002 ALL_BP_LOCATIONS (loc
)
7003 if (loc
->next
== bpt
->loc
)
7005 loc
->next
= bpt
->loc
->next
;
7009 check_duplicates (bpt
);
7010 /* If this breakpoint was inserted, and there is another breakpoint
7011 at the same address, we need to insert the other breakpoint. */
7012 if (bpt
->loc
->inserted
7013 && bpt
->type
!= bp_hardware_watchpoint
7014 && bpt
->type
!= bp_read_watchpoint
7015 && bpt
->type
!= bp_access_watchpoint
7016 && bpt
->type
!= bp_catch_fork
7017 && bpt
->type
!= bp_catch_vfork
7018 && bpt
->type
!= bp_catch_exec
)
7021 if (b
->loc
->address
== bpt
->loc
->address
7022 && b
->loc
->section
== bpt
->loc
->section
7023 && !b
->loc
->duplicate
7024 && b
->enable_state
!= bp_disabled
7025 && b
->enable_state
!= bp_shlib_disabled
7027 && b
->enable_state
!= bp_call_disabled
)
7031 /* We should never reach this point if there is a permanent
7032 breakpoint at the same address as the one being deleted.
7033 If there is a permanent breakpoint somewhere, it should
7034 always be the only one inserted. */
7035 if (b
->enable_state
== bp_permanent
)
7036 internal_error (__FILE__
, __LINE__
,
7037 _("another breakpoint was inserted on top of "
7038 "a permanent breakpoint"));
7040 memset (&b
->loc
->target_info
, 0, sizeof (b
->loc
->target_info
));
7041 b
->loc
->target_info
.placed_address
= b
->loc
->address
;
7042 if (b
->type
== bp_hardware_breakpoint
)
7043 val
= target_insert_hw_breakpoint (&b
->loc
->target_info
);
7045 val
= target_insert_breakpoint (&b
->loc
->target_info
);
7047 /* If there was an error in the insert, print a message, then stop execution. */
7050 struct ui_file
*tmp_error_stream
= mem_fileopen ();
7051 make_cleanup_ui_file_delete (tmp_error_stream
);
7054 if (b
->type
== bp_hardware_breakpoint
)
7056 fprintf_unfiltered (tmp_error_stream
,
7057 "Cannot insert hardware breakpoint %d.\n"
7058 "You may have requested too many hardware breakpoints.\n",
7063 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
7064 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
7065 deprecated_print_address_numeric (b
->loc
->address
, 1, tmp_error_stream
);
7066 fprintf_filtered (tmp_error_stream
, ": %s.\n",
7067 safe_strerror (val
));
7070 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
7071 target_terminal_ours_for_output ();
7072 error_stream(tmp_error_stream
);
7075 b
->loc
->inserted
= 1;
7079 free_command_lines (&bpt
->commands
);
7082 if (bpt
->cond_string
!= NULL
)
7083 xfree (bpt
->cond_string
);
7084 if (bpt
->addr_string
!= NULL
)
7085 xfree (bpt
->addr_string
);
7086 if (bpt
->exp
!= NULL
)
7088 if (bpt
->exp_string
!= NULL
)
7089 xfree (bpt
->exp_string
);
7090 if (bpt
->val
!= NULL
)
7091 value_free (bpt
->val
);
7092 if (bpt
->source_file
!= NULL
)
7093 xfree (bpt
->source_file
);
7094 if (bpt
->dll_pathname
!= NULL
)
7095 xfree (bpt
->dll_pathname
);
7096 if (bpt
->triggered_dll_pathname
!= NULL
)
7097 xfree (bpt
->triggered_dll_pathname
);
7098 if (bpt
->exec_pathname
!= NULL
)
7099 xfree (bpt
->exec_pathname
);
7101 /* Be sure no bpstat's are pointing at it after it's been freed. */
7102 /* FIXME, how can we find all bpstat's?
7103 We just check stop_bpstat for now. */
7104 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
7105 if (bs
->breakpoint_at
== bpt
)
7107 bs
->breakpoint_at
= NULL
;
7109 /* bs->commands will be freed later. */
7111 /* On the chance that someone will soon try again to delete this same
7112 bp, we mark it as deleted before freeing its storage. */
7113 bpt
->type
= bp_none
;
7120 do_delete_breakpoint_cleanup (void *b
)
7122 delete_breakpoint (b
);
7126 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7128 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7132 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
7134 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
7138 delete_command (char *arg
, int from_tty
)
7140 struct breakpoint
*b
, *temp
;
7146 int breaks_to_delete
= 0;
7148 /* Delete all breakpoints if no argument.
7149 Do not delete internal or call-dummy breakpoints, these
7150 have to be deleted with an explicit breakpoint number argument. */
7153 if (b
->type
!= bp_call_dummy
&&
7154 b
->type
!= bp_shlib_event
&&
7155 b
->type
!= bp_thread_event
&&
7156 b
->type
!= bp_overlay_event
&&
7159 breaks_to_delete
= 1;
7164 /* Ask user only if there are some breakpoints to delete. */
7166 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7168 ALL_BREAKPOINTS_SAFE (b
, temp
)
7170 if (b
->type
!= bp_call_dummy
&&
7171 b
->type
!= bp_shlib_event
&&
7172 b
->type
!= bp_thread_event
&&
7173 b
->type
!= bp_overlay_event
&&
7175 delete_breakpoint (b
);
7180 map_breakpoint_numbers (arg
, delete_breakpoint
);
7183 /* Reset a breakpoint given it's struct breakpoint * BINT.
7184 The value we return ends up being the return value from catch_errors.
7185 Unused in this case. */
7188 breakpoint_re_set_one (void *bint
)
7190 /* get past catch_errs */
7191 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7195 int *not_found_ptr
= NULL
;
7196 struct symtabs_and_lines sals
;
7198 enum enable_state save_enable
;
7203 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7207 case bp_hardware_breakpoint
:
7209 case bp_catch_unload
:
7210 if (b
->addr_string
== NULL
)
7212 /* Anything without a string can't be re-set. */
7213 delete_breakpoint (b
);
7216 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
7218 ``And a hack it is, although Apple's Darwin version of GDB
7219 contains an almost identical hack to implement a "future
7220 break" command. It seems to work in many real world cases,
7221 but it is easy to come up with a test case where the patch
7222 doesn't help at all.''
7224 ``It seems that the way GDB implements breakpoints - in -
7225 shared - libraries was designed for a.out shared library
7226 systems (SunOS 4) where shared libraries were loaded at a
7227 fixed address in memory. Since ELF shared libraries can (and
7228 will) be loaded at any address in memory, things break.
7229 Fixing this is not trivial. Therefore, I'm not sure whether
7230 we should add this hack to the branch only. I cannot
7231 guarantee that things will be fixed on the trunk in the near
7234 In case we have a problem, disable this breakpoint. We'll
7235 restore its status if we succeed. Don't disable a
7236 shlib_disabled breakpoint though. There's a fair chance we
7237 can't re-set it if the shared library it's in hasn't been
7243 save_enable
= b
->enable_state
;
7244 if (b
->enable_state
!= bp_shlib_disabled
)
7245 b
->enable_state
= bp_disabled
;
7247 /* If resetting a shlib-disabled breakpoint, we don't want to
7248 see an error message if it is not found since we will expect
7249 this to occur until the shared library is finally reloaded.
7250 We accomplish this by giving decode_line_1 a pointer to use
7251 for silent notification that the symbol is not found. */
7252 not_found_ptr
= ¬_found
;
7254 set_language (b
->language
);
7255 input_radix
= b
->input_radix
;
7257 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7259 for (i
= 0; i
< sals
.nelts
; i
++)
7261 resolve_sal_pc (&sals
.sals
[i
]);
7263 /* Reparse conditions, they might contain references to the
7265 if (b
->cond_string
!= NULL
)
7271 /* Avoid re-freeing b->exp if an error during the call
7275 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
7278 /* We need to re-set the breakpoint if the address changes... */
7279 if (b
->loc
->address
!= sals
.sals
[i
].pc
7280 /* ...or new and old breakpoints both have source files, and
7281 the source file name or the line number changes... */
7282 || (b
->source_file
!= NULL
7283 && sals
.sals
[i
].symtab
!= NULL
7284 && (strcmp (b
->source_file
, sals
.sals
[i
].symtab
->filename
) != 0
7285 || b
->line_number
!= sals
.sals
[i
].line
)
7287 /* ...or we switch between having a source file and not having
7289 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
7292 if (b
->source_file
!= NULL
)
7293 xfree (b
->source_file
);
7294 if (sals
.sals
[i
].symtab
== NULL
)
7295 b
->source_file
= NULL
;
7298 savestring (sals
.sals
[i
].symtab
->filename
,
7299 strlen (sals
.sals
[i
].symtab
->filename
));
7300 b
->line_number
= sals
.sals
[i
].line
;
7301 b
->loc
->requested_address
= sals
.sals
[i
].pc
;
7303 = adjust_breakpoint_address (b
->loc
->requested_address
,
7306 /* Used to check for duplicates here, but that can
7307 cause trouble, as it doesn't check for disabled
7312 /* Might be better to do this just once per breakpoint_re_set,
7313 rather than once for every breakpoint. */
7314 breakpoints_changed ();
7316 b
->loc
->section
= sals
.sals
[i
].section
;
7317 b
->enable_state
= save_enable
; /* Restore it, this worked. */
7320 /* Now that this is re-enabled, check_duplicates
7322 check_duplicates (b
);
7329 case bp_hardware_watchpoint
:
7330 case bp_read_watchpoint
:
7331 case bp_access_watchpoint
:
7332 innermost_block
= NULL
;
7333 /* The issue arises of what context to evaluate this in. The
7334 same one as when it was set, but what does that mean when
7335 symbols have been re-read? We could save the filename and
7336 functionname, but if the context is more local than that, the
7337 best we could do would be something like how many levels deep
7338 and which index at that particular level, but that's going to
7339 be less stable than filenames or function names. */
7341 /* So for now, just use a global context. */
7345 /* Avoid re-freeing b->exp if an error during the call to
7346 parse_expression. */
7349 b
->exp
= parse_expression (b
->exp_string
);
7350 b
->exp_valid_block
= innermost_block
;
7351 mark
= value_mark ();
7354 value_free (b
->val
);
7355 /* Avoid re-freeing b->val if an error during the call to
7356 evaluate_expression. */
7359 b
->val
= evaluate_expression (b
->exp
);
7360 release_value (b
->val
);
7361 if (value_lazy (b
->val
) && breakpoint_enabled (b
))
7362 value_fetch_lazy (b
->val
);
7364 if (b
->cond_string
!= NULL
)
7370 /* Avoid re-freeing b->exp if an error during the call
7374 b
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
7376 if (breakpoint_enabled (b
))
7378 value_free_to_mark (mark
);
7380 case bp_catch_catch
:
7381 case bp_catch_throw
:
7383 /* We needn't really do anything to reset these, since the mask
7384 that requests them is unaffected by e.g., new libraries being
7387 case bp_catch_vfork
:
7392 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7394 /* Delete longjmp and overlay event breakpoints; they will be
7395 reset later by breakpoint_re_set. */
7397 case bp_longjmp_resume
:
7398 case bp_overlay_event
:
7399 delete_breakpoint (b
);
7402 /* This breakpoint is special, it's set up when the inferior
7403 starts and we really don't want to touch it. */
7404 case bp_shlib_event
:
7406 /* Like bp_shlib_event, this breakpoint type is special.
7407 Once it is set up, we do not want to touch it. */
7408 case bp_thread_event
:
7410 /* Keep temporary breakpoints, which can be encountered when we step
7411 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7412 Otherwise these should have been blown away via the cleanup chain
7413 or by breakpoint_init_inferior when we rerun the executable. */
7416 case bp_watchpoint_scope
:
7418 case bp_step_resume
:
7425 /* Re-set all breakpoints after symbols have been re-loaded. */
7427 breakpoint_re_set (void)
7429 struct breakpoint
*b
, *temp
;
7430 enum language save_language
;
7431 int save_input_radix
;
7433 save_language
= current_language
->la_language
;
7434 save_input_radix
= input_radix
;
7435 ALL_BREAKPOINTS_SAFE (b
, temp
)
7437 /* Format possible error msg */
7438 char *message
= xstrprintf ("Error in re-setting breakpoint %d:\n",
7440 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7441 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7442 do_cleanups (cleanups
);
7444 set_language (save_language
);
7445 input_radix
= save_input_radix
;
7447 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
7449 create_longjmp_breakpoint ("longjmp");
7450 create_longjmp_breakpoint ("_longjmp");
7451 create_longjmp_breakpoint ("siglongjmp");
7452 create_longjmp_breakpoint ("_siglongjmp");
7453 create_longjmp_breakpoint (NULL
);
7456 create_overlay_event_breakpoint ("_ovly_debug_event");
7459 /* Reset the thread number of this breakpoint:
7461 - If the breakpoint is for all threads, leave it as-is.
7462 - Else, reset it to the current thread for inferior_ptid. */
7464 breakpoint_re_set_thread (struct breakpoint
*b
)
7466 if (b
->thread
!= -1)
7468 if (in_thread_list (inferior_ptid
))
7469 b
->thread
= pid_to_thread_id (inferior_ptid
);
7473 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7474 If from_tty is nonzero, it prints a message to that effect,
7475 which ends with a period (no newline). */
7478 set_ignore_count (int bptnum
, int count
, int from_tty
)
7480 struct breakpoint
*b
;
7486 if (b
->number
== bptnum
)
7488 b
->ignore_count
= count
;
7492 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7494 else if (count
== 1)
7495 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7498 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7501 breakpoints_changed ();
7502 breakpoint_modify_event (b
->number
);
7506 error (_("No breakpoint number %d."), bptnum
);
7509 /* Clear the ignore counts of all breakpoints. */
7511 breakpoint_clear_ignore_counts (void)
7513 struct breakpoint
*b
;
7516 b
->ignore_count
= 0;
7519 /* Command to set ignore-count of breakpoint N to COUNT. */
7522 ignore_command (char *args
, int from_tty
)
7528 error_no_arg (_("a breakpoint number"));
7530 num
= get_number (&p
);
7532 error (_("bad breakpoint number: '%s'"), args
);
7534 error (_("Second argument (specified ignore-count) is missing."));
7536 set_ignore_count (num
,
7537 longest_to_int (value_as_long (parse_and_eval (p
))),
7540 printf_filtered ("\n");
7543 /* Call FUNCTION on each of the breakpoints
7544 whose numbers are given in ARGS. */
7547 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7552 struct breakpoint
*b
, *tmp
;
7556 error_no_arg (_("one or more breakpoint numbers"));
7563 num
= get_number_or_range (&p1
);
7566 warning (_("bad breakpoint number at or near '%s'"), p
);
7570 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7571 if (b
->number
== num
)
7573 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7576 if (related_breakpoint
)
7577 function (related_breakpoint
);
7581 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7587 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7588 If from_tty is nonzero, it prints a message to that effect,
7589 which ends with a period (no newline). */
7592 disable_breakpoint (struct breakpoint
*bpt
)
7594 /* Never disable a watchpoint scope breakpoint; we want to
7595 hit them when we leave scope so we can delete both the
7596 watchpoint and its scope breakpoint at that time. */
7597 if (bpt
->type
== bp_watchpoint_scope
)
7600 /* You can't disable permanent breakpoints. */
7601 if (bpt
->enable_state
== bp_permanent
)
7604 bpt
->enable_state
= bp_disabled
;
7606 check_duplicates (bpt
);
7608 if (deprecated_modify_breakpoint_hook
)
7609 deprecated_modify_breakpoint_hook (bpt
);
7610 breakpoint_modify_event (bpt
->number
);
7614 disable_command (char *args
, int from_tty
)
7616 struct breakpoint
*bpt
;
7618 ALL_BREAKPOINTS (bpt
)
7622 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7627 case bp_catch_unload
:
7629 case bp_catch_vfork
:
7631 case bp_catch_catch
:
7632 case bp_catch_throw
:
7633 case bp_hardware_breakpoint
:
7635 case bp_hardware_watchpoint
:
7636 case bp_read_watchpoint
:
7637 case bp_access_watchpoint
:
7638 disable_breakpoint (bpt
);
7643 map_breakpoint_numbers (args
, disable_breakpoint
);
7647 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7649 int target_resources_ok
, other_type_used
;
7652 if (bpt
->type
== bp_hardware_breakpoint
)
7655 i
= hw_breakpoint_used_count ();
7656 target_resources_ok
=
7657 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7659 if (target_resources_ok
== 0)
7660 error (_("No hardware breakpoint support in the target."));
7661 else if (target_resources_ok
< 0)
7662 error (_("Hardware breakpoints used exceeds limit."));
7667 if (bpt
->enable_state
!= bp_enabled
)
7669 /* When enabling a pending breakpoint, we need to check if the breakpoint
7670 is resolvable since shared libraries could have been loaded
7671 after the breakpoint was disabled. */
7672 breakpoints_changed ();
7673 if (resolve_pending_breakpoint (bpt
) == GDB_RC_OK
)
7675 delete_breakpoint (bpt
);
7678 bpt
->enable_state
= bp_enabled
;
7679 bpt
->disposition
= disposition
;
7682 else /* Not a pending breakpoint. */
7684 if (bpt
->enable_state
!= bp_permanent
)
7685 bpt
->enable_state
= bp_enabled
;
7686 bpt
->disposition
= disposition
;
7687 check_duplicates (bpt
);
7688 breakpoints_changed ();
7690 if (bpt
->type
== bp_watchpoint
||
7691 bpt
->type
== bp_hardware_watchpoint
||
7692 bpt
->type
== bp_read_watchpoint
||
7693 bpt
->type
== bp_access_watchpoint
)
7695 struct frame_id saved_frame_id
;
7697 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7698 if (bpt
->exp_valid_block
!= NULL
)
7700 struct frame_info
*fr
=
7701 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7704 printf_filtered (_("\
7705 Cannot enable watchpoint %d because the block in which its expression\n\
7706 is valid is not currently in scope.\n"), bpt
->number
);
7707 bpt
->enable_state
= bp_disabled
;
7713 value_free (bpt
->val
);
7714 mark
= value_mark ();
7715 bpt
->val
= evaluate_expression (bpt
->exp
);
7716 release_value (bpt
->val
);
7717 if (value_lazy (bpt
->val
))
7718 value_fetch_lazy (bpt
->val
);
7720 if (bpt
->type
== bp_hardware_watchpoint
||
7721 bpt
->type
== bp_read_watchpoint
||
7722 bpt
->type
== bp_access_watchpoint
)
7724 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7725 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7727 /* Hack around 'unused var' error for some targets here */
7728 (void) mem_cnt
, (void) i
;
7729 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7730 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7731 /* we can consider of type is bp_hardware_watchpoint, convert to
7732 bp_watchpoint in the following condition */
7733 if (target_resources_ok
< 0)
7735 printf_filtered (_("\
7736 Cannot enable watchpoint %d because target watch resources\n\
7737 have been allocated for other watchpoints.\n"), bpt
->number
);
7738 bpt
->enable_state
= bp_disabled
;
7739 value_free_to_mark (mark
);
7744 select_frame (frame_find_by_id (saved_frame_id
));
7745 value_free_to_mark (mark
);
7749 if (deprecated_modify_breakpoint_hook
)
7750 deprecated_modify_breakpoint_hook (bpt
);
7751 breakpoint_modify_event (bpt
->number
);
7755 enable_breakpoint (struct breakpoint
*bpt
)
7757 do_enable_breakpoint (bpt
, bpt
->disposition
);
7760 /* The enable command enables the specified breakpoints (or all defined
7761 breakpoints) so they once again become (or continue to be) effective
7762 in stopping the inferior. */
7765 enable_command (char *args
, int from_tty
)
7767 struct breakpoint
*bpt
;
7769 ALL_BREAKPOINTS (bpt
)
7773 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7778 case bp_catch_unload
:
7780 case bp_catch_vfork
:
7782 case bp_catch_catch
:
7783 case bp_catch_throw
:
7784 case bp_hardware_breakpoint
:
7786 case bp_hardware_watchpoint
:
7787 case bp_read_watchpoint
:
7788 case bp_access_watchpoint
:
7789 enable_breakpoint (bpt
);
7794 map_breakpoint_numbers (args
, enable_breakpoint
);
7798 enable_once_breakpoint (struct breakpoint
*bpt
)
7800 do_enable_breakpoint (bpt
, disp_disable
);
7804 enable_once_command (char *args
, int from_tty
)
7806 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7810 enable_delete_breakpoint (struct breakpoint
*bpt
)
7812 do_enable_breakpoint (bpt
, disp_del
);
7816 enable_delete_command (char *args
, int from_tty
)
7818 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7822 set_breakpoint_cmd (char *args
, int from_tty
)
7827 show_breakpoint_cmd (char *args
, int from_tty
)
7831 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7833 struct symtabs_and_lines
7834 decode_line_spec_1 (char *string
, int funfirstline
)
7836 struct symtabs_and_lines sals
;
7838 error (_("Empty line specification."));
7839 if (default_breakpoint_valid
)
7840 sals
= decode_line_1 (&string
, funfirstline
,
7841 default_breakpoint_symtab
,
7842 default_breakpoint_line
,
7843 (char ***) NULL
, NULL
);
7845 sals
= decode_line_1 (&string
, funfirstline
,
7846 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7848 error (_("Junk at end of line specification: %s"), string
);
7852 /* Create and insert a raw software breakpoint at PC. Return an
7853 identifier, which should be used to remove the breakpoint later.
7854 In general, places which call this should be using something on the
7855 breakpoint chain instead; this function should be eliminated
7859 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7861 struct bp_target_info
*bp_tgt
;
7863 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7864 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7866 bp_tgt
->placed_address
= pc
;
7867 if (target_insert_breakpoint (bp_tgt
) != 0)
7869 /* Could not insert the breakpoint. */
7877 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7880 deprecated_remove_raw_breakpoint (void *bp
)
7882 struct bp_target_info
*bp_tgt
= bp
;
7885 ret
= target_remove_breakpoint (bp_tgt
);
7891 /* One (or perhaps two) breakpoints used for software single stepping. */
7893 static void *single_step_breakpoints
[2];
7895 /* Create and insert a breakpoint for software single step. */
7898 insert_single_step_breakpoint (CORE_ADDR next_pc
)
7902 if (single_step_breakpoints
[0] == NULL
)
7903 bpt_p
= &single_step_breakpoints
[0];
7906 gdb_assert (single_step_breakpoints
[1] == NULL
);
7907 bpt_p
= &single_step_breakpoints
[1];
7910 /* NOTE drow/2006-04-11: A future improvement to this function would be
7911 to only create the breakpoints once, and actually put them on the
7912 breakpoint chain. That would let us use set_raw_breakpoint. We could
7913 adjust the addresses each time they were needed. Doing this requires
7914 corresponding changes elsewhere where single step breakpoints are
7915 handled, however. So, for now, we use this. */
7917 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
7919 error (_("Could not insert single-step breakpoint at 0x%s"),
7920 paddr_nz (next_pc
));
7923 /* Remove and delete any breakpoints used for software single step. */
7926 remove_single_step_breakpoints (void)
7928 gdb_assert (single_step_breakpoints
[0] != NULL
);
7930 /* See insert_single_step_breakpoint for more about this deprecated
7932 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
7933 single_step_breakpoints
[0] = NULL
;
7935 if (single_step_breakpoints
[1] != NULL
)
7937 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
7938 single_step_breakpoints
[1] = NULL
;
7942 /* Check whether a software single-step breakpoint is inserted at PC. */
7945 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
7949 for (i
= 0; i
< 2; i
++)
7951 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
7952 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
7960 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
7961 It is defined as a macro to prevent duplication.
7962 COMMAND should be a string constant containing the name of the command. */
7963 #define BREAK_ARGS_HELP(command) \
7964 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
7965 LOCATION may be a line number, function name, or \"*\" and an address.\n\
7966 If a line number is specified, break at start of code for that line.\n\
7967 If a function is specified, break at start of code for that function.\n\
7968 If an address is specified, break at that exact address.\n\
7969 With no LOCATION, uses current execution address of selected stack frame.\n\
7970 This is useful for breaking on return to a stack frame.\n\
7972 THREADNUM is the number from \"info threads\".\n\
7973 CONDITION is a boolean expression.\n\
7975 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7977 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
7980 _initialize_breakpoint (void)
7982 static struct cmd_list_element
*breakpoint_set_cmdlist
;
7983 static struct cmd_list_element
*breakpoint_show_cmdlist
;
7984 struct cmd_list_element
*c
;
7986 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
7988 breakpoint_chain
= 0;
7989 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7990 before a breakpoint is set. */
7991 breakpoint_count
= 0;
7993 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
7994 Set ignore-count of breakpoint number N to COUNT.\n\
7995 Usage is `ignore N COUNT'."));
7997 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7999 add_com ("commands", class_breakpoint
, commands_command
, _("\
8000 Set commands to be executed when a breakpoint is hit.\n\
8001 Give breakpoint number as argument after \"commands\".\n\
8002 With no argument, the targeted breakpoint is the last one set.\n\
8003 The commands themselves follow starting on the next line.\n\
8004 Type a line containing \"end\" to indicate the end of them.\n\
8005 Give \"silent\" as the first line to make the breakpoint silent;\n\
8006 then no output is printed when it is hit, except what the commands print."));
8008 add_com ("condition", class_breakpoint
, condition_command
, _("\
8009 Specify breakpoint number N to break only if COND is true.\n\
8010 Usage is `condition N COND', where N is an integer and COND is an\n\
8011 expression to be evaluated whenever breakpoint N is reached."));
8013 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8014 Set a temporary breakpoint.\n\
8015 Like \"break\" except the breakpoint is only temporary,\n\
8016 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8017 by using \"enable delete\" on the breakpoint number.\n\
8019 BREAK_ARGS_HELP ("tbreak")));
8020 set_cmd_completer (c
, location_completer
);
8022 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8023 Set a hardware assisted breakpoint.\n\
8024 Like \"break\" except the breakpoint requires hardware support,\n\
8025 some target hardware may not have this support.\n\
8027 BREAK_ARGS_HELP ("hbreak")));
8028 set_cmd_completer (c
, location_completer
);
8030 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8031 Set a temporary hardware assisted breakpoint.\n\
8032 Like \"hbreak\" except the breakpoint is only temporary,\n\
8033 so it will be deleted when hit.\n\
8035 BREAK_ARGS_HELP ("thbreak")));
8036 set_cmd_completer (c
, location_completer
);
8038 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8039 Enable some breakpoints.\n\
8040 Give breakpoint numbers (separated by spaces) as arguments.\n\
8041 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8042 This is used to cancel the effect of the \"disable\" command.\n\
8043 With a subcommand you can enable temporarily."),
8044 &enablelist
, "enable ", 1, &cmdlist
);
8046 add_com ("ab", class_breakpoint
, enable_command
, _("\
8047 Enable some breakpoints.\n\
8048 Give breakpoint numbers (separated by spaces) as arguments.\n\
8049 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8050 This is used to cancel the effect of the \"disable\" command.\n\
8051 With a subcommand you can enable temporarily."));
8053 add_com_alias ("en", "enable", class_breakpoint
, 1);
8055 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8056 Enable some breakpoints.\n\
8057 Give breakpoint numbers (separated by spaces) as arguments.\n\
8058 This is used to cancel the effect of the \"disable\" command.\n\
8059 May be abbreviated to simply \"enable\".\n"),
8060 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8062 add_cmd ("once", no_class
, enable_once_command
, _("\
8063 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8064 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8067 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8068 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8069 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8072 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8073 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8074 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8077 add_cmd ("once", no_class
, enable_once_command
, _("\
8078 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8079 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8082 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8083 Disable some breakpoints.\n\
8084 Arguments are breakpoint numbers with spaces in between.\n\
8085 To disable all breakpoints, give no argument.\n\
8086 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8087 &disablelist
, "disable ", 1, &cmdlist
);
8088 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8089 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8091 add_com ("sb", class_breakpoint
, disable_command
, _("\
8092 Disable some breakpoints.\n\
8093 Arguments are breakpoint numbers with spaces in between.\n\
8094 To disable all breakpoints, give no argument.\n\
8095 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8097 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8098 Disable some breakpoints.\n\
8099 Arguments are breakpoint numbers with spaces in between.\n\
8100 To disable all breakpoints, give no argument.\n\
8101 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8102 This command may be abbreviated \"disable\"."),
8105 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8106 Delete some breakpoints or auto-display expressions.\n\
8107 Arguments are breakpoint numbers with spaces in between.\n\
8108 To delete all breakpoints, give no argument.\n\
8110 Also a prefix command for deletion of other GDB objects.\n\
8111 The \"unset\" command is also an alias for \"delete\"."),
8112 &deletelist
, "delete ", 1, &cmdlist
);
8113 add_com_alias ("d", "delete", class_breakpoint
, 1);
8114 add_com_alias ("del", "delete", class_breakpoint
, 1);
8116 add_com ("db", class_breakpoint
, delete_command
, _("\
8117 Delete some breakpoints.\n\
8118 Arguments are breakpoint numbers with spaces in between.\n\
8119 To delete all breakpoints, give no argument.\n"));
8121 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8122 Delete some breakpoints or auto-display expressions.\n\
8123 Arguments are breakpoint numbers with spaces in between.\n\
8124 To delete all breakpoints, give no argument.\n\
8125 This command may be abbreviated \"delete\"."),
8128 add_com ("clear", class_breakpoint
, clear_command
, _("\
8129 Clear breakpoint at specified line or function.\n\
8130 Argument may be line number, function name, or \"*\" and an address.\n\
8131 If line number is specified, all breakpoints in that line are cleared.\n\
8132 If function is specified, breakpoints at beginning of function are cleared.\n\
8133 If an address is specified, breakpoints at that address are cleared.\n\
8135 With no argument, clears all breakpoints in the line that the selected frame\n\
8138 See also the \"delete\" command which clears breakpoints by number."));
8140 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8141 Set breakpoint at specified line or function.\n"
8142 BREAK_ARGS_HELP ("break")));
8143 set_cmd_completer (c
, location_completer
);
8145 add_com_alias ("b", "break", class_run
, 1);
8146 add_com_alias ("br", "break", class_run
, 1);
8147 add_com_alias ("bre", "break", class_run
, 1);
8148 add_com_alias ("brea", "break", class_run
, 1);
8152 add_com_alias ("ba", "break", class_breakpoint
, 1);
8153 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8158 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8159 Break in function/address or break at a line in the current file."),
8160 &stoplist
, "stop ", 1, &cmdlist
);
8161 add_cmd ("in", class_breakpoint
, stopin_command
,
8162 _("Break in function or address."), &stoplist
);
8163 add_cmd ("at", class_breakpoint
, stopat_command
,
8164 _("Break at a line in the current file."), &stoplist
);
8165 add_com ("status", class_info
, breakpoints_info
, _("\
8166 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8167 The \"Type\" column indicates one of:\n\
8168 \tbreakpoint - normal breakpoint\n\
8169 \twatchpoint - watchpoint\n\
8170 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8171 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8172 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8173 address and file/line number respectively.\n\
8175 Convenience variable \"$_\" and default examine address for \"x\"\n\
8176 are set to the address of the last breakpoint listed.\n\n\
8177 Convenience variable \"$bpnum\" contains the number of the last\n\
8181 add_info ("breakpoints", breakpoints_info
, _("\
8182 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8183 The \"Type\" column indicates one of:\n\
8184 \tbreakpoint - normal breakpoint\n\
8185 \twatchpoint - watchpoint\n\
8186 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8187 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8188 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8189 address and file/line number respectively.\n\
8191 Convenience variable \"$_\" and default examine address for \"x\"\n\
8192 are set to the address of the last breakpoint listed.\n\n\
8193 Convenience variable \"$bpnum\" contains the number of the last\n\
8197 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8198 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8199 The \"Type\" column indicates one of:\n\
8200 \tbreakpoint - normal breakpoint\n\
8201 \twatchpoint - watchpoint\n\
8202 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8203 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8204 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8205 address and file/line number respectively.\n\
8207 Convenience variable \"$_\" and default examine address for \"x\"\n\
8208 are set to the address of the last breakpoint listed.\n\n\
8209 Convenience variable \"$bpnum\" contains the number of the last\n\
8212 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8213 Status of all breakpoints, or breakpoint number NUMBER.\n\
8214 The \"Type\" column indicates one of:\n\
8215 \tbreakpoint - normal breakpoint\n\
8216 \twatchpoint - watchpoint\n\
8217 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8218 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8219 \tuntil - internal breakpoint used by the \"until\" command\n\
8220 \tfinish - internal breakpoint used by the \"finish\" command\n\
8221 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8222 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8223 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8224 address and file/line number respectively.\n\
8226 Convenience variable \"$_\" and default examine address for \"x\"\n\
8227 are set to the address of the last breakpoint listed.\n\
8229 Convenience variable \"$bpnum\" contains the number of the last\n\
8231 &maintenanceinfolist
);
8233 add_com ("catch", class_breakpoint
, catch_command
, _("\
8234 Set catchpoints to catch events.\n\
8235 Raised signals may be caught:\n\
8236 \tcatch signal - all signals\n\
8237 \tcatch signal <signame> - a particular signal\n\
8238 Raised exceptions may be caught:\n\
8239 \tcatch throw - all exceptions, when thrown\n\
8240 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8241 \tcatch catch - all exceptions, when caught\n\
8242 \tcatch catch <exceptname> - a particular exception, when caught\n\
8243 Thread or process events may be caught:\n\
8244 \tcatch thread_start - any threads, just after creation\n\
8245 \tcatch thread_exit - any threads, just before expiration\n\
8246 \tcatch thread_join - any threads, just after joins\n\
8247 Process events may be caught:\n\
8248 \tcatch start - any processes, just after creation\n\
8249 \tcatch exit - any processes, just before expiration\n\
8250 \tcatch fork - calls to fork()\n\
8251 \tcatch vfork - calls to vfork()\n\
8252 \tcatch exec - calls to exec()\n\
8253 Dynamically-linked library events may be caught:\n\
8254 \tcatch load - loads of any library\n\
8255 \tcatch load <libname> - loads of a particular library\n\
8256 \tcatch unload - unloads of any library\n\
8257 \tcatch unload <libname> - unloads of a particular library\n\
8258 The act of your program's execution stopping may also be caught:\n\
8260 C++ exceptions may be caught:\n\
8261 \tcatch throw - all exceptions, when thrown\n\
8262 \tcatch catch - all exceptions, when caught\n\
8263 Ada exceptions may be caught:\n\
8264 \tcatch exception - all exceptions, when raised\n\
8265 \tcatch exception <name> - a particular exception, when raised\n\
8266 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8267 \tcatch assert - all failed assertions, when raised\n\
8269 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8270 after a fork or vfork is caught.\n\n\
8271 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8273 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8274 Set temporary catchpoints to catch events.\n\
8275 Args like \"catch\" command.\n\
8276 Like \"catch\" except the catchpoint is only temporary,\n\
8277 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8278 by using \"enable delete\" on the catchpoint number."));
8280 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8281 Set a watchpoint for an expression.\n\
8282 A watchpoint stops execution of your program whenever the value of\n\
8283 an expression changes."));
8284 set_cmd_completer (c
, location_completer
);
8286 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8287 Set a read watchpoint for an expression.\n\
8288 A watchpoint stops execution of your program whenever the value of\n\
8289 an expression is read."));
8290 set_cmd_completer (c
, location_completer
);
8292 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8293 Set a watchpoint for an expression.\n\
8294 A watchpoint stops execution of your program whenever the value of\n\
8295 an expression is either read or written."));
8296 set_cmd_completer (c
, location_completer
);
8298 add_info ("watchpoints", breakpoints_info
,
8299 _("Synonym for ``info breakpoints''."));
8302 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8303 respond to changes - contrary to the description. */
8304 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8305 &can_use_hw_watchpoints
, _("\
8306 Set debugger's willingness to use watchpoint hardware."), _("\
8307 Show debugger's willingness to use watchpoint hardware."), _("\
8308 If zero, gdb will not use hardware for new watchpoints, even if\n\
8309 such is available. (However, any hardware watchpoints that were\n\
8310 created before setting this to nonzero, will continue to use watchpoint\n\
8313 show_can_use_hw_watchpoints
,
8314 &setlist
, &showlist
);
8316 can_use_hw_watchpoints
= 1;
8318 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8319 Breakpoint specific settings\n\
8320 Configure various breakpoint-specific variables such as\n\
8321 pending breakpoint behavior"),
8322 &breakpoint_set_cmdlist
, "set breakpoint ",
8323 0/*allow-unknown*/, &setlist
);
8324 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8325 Breakpoint specific settings\n\
8326 Configure various breakpoint-specific variables such as\n\
8327 pending breakpoint behavior"),
8328 &breakpoint_show_cmdlist
, "show breakpoint ",
8329 0/*allow-unknown*/, &showlist
);
8331 add_setshow_auto_boolean_cmd ("pending", no_class
,
8332 &pending_break_support
, _("\
8333 Set debugger's behavior regarding pending breakpoints."), _("\
8334 Show debugger's behavior regarding pending breakpoints."), _("\
8335 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8336 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8337 an error. If auto, an unrecognized breakpoint location results in a\n\
8338 user-query to see if a pending breakpoint should be created."),
8340 show_pending_break_support
,
8341 &breakpoint_set_cmdlist
,
8342 &breakpoint_show_cmdlist
);
8344 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8346 add_setshow_boolean_cmd ("auto-hw", no_class
,
8347 &automatic_hardware_breakpoints
, _("\
8348 Set automatic usage of hardware breakpoints."), _("\
8349 Show automatic usage of hardware breakpoints."), _("\
8350 If set, the debugger will automatically use hardware breakpoints for\n\
8351 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8352 a warning will be emitted for such breakpoints."),
8354 show_automatic_hardware_breakpoints
,
8355 &breakpoint_set_cmdlist
,
8356 &breakpoint_show_cmdlist
);
8358 automatic_hardware_breakpoints
= 1;