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 (gdbarch_breakpoint_from_pc (current_gdbarch
, &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 ();
1341 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1342 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1344 make_cleanup_ui_file_delete (tmp_error_stream
);
1346 inferior_ptid
= pid_to_ptid (pid
);
1347 ALL_BP_LOCATIONS (b
)
1352 val
= insert_bp_location (b
, tmp_error_stream
,
1353 &dummy1
, &dummy2
, &dummy3
);
1356 do_cleanups (old_chain
);
1361 do_cleanups (old_chain
);
1366 update_breakpoints_after_exec (void)
1368 struct breakpoint
*b
;
1369 struct breakpoint
*temp
;
1371 /* Doing this first prevents the badness of having delete_breakpoint()
1372 write a breakpoint's current "shadow contents" to lift the bp. That
1373 shadow is NOT valid after an exec()! */
1374 mark_breakpoints_out ();
1376 ALL_BREAKPOINTS_SAFE (b
, temp
)
1378 /* Solib breakpoints must be explicitly reset after an exec(). */
1379 if (b
->type
== bp_shlib_event
)
1381 delete_breakpoint (b
);
1385 /* Thread event breakpoints must be set anew after an exec(),
1386 as must overlay event breakpoints. */
1387 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1389 delete_breakpoint (b
);
1393 /* Step-resume breakpoints are meaningless after an exec(). */
1394 if (b
->type
== bp_step_resume
)
1396 delete_breakpoint (b
);
1400 /* Ditto the exception-handling catchpoints. */
1401 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1403 delete_breakpoint (b
);
1407 /* Don't delete an exec catchpoint, because else the inferior
1408 won't stop when it ought!
1410 Similarly, we probably ought to keep vfork catchpoints, 'cause
1411 on this target, we may not be able to stop when the vfork is
1412 seen, but only when the subsequent exec is seen. (And because
1413 deleting fork catchpoints here but not vfork catchpoints will
1414 seem mysterious to users, keep those too.)
1416 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1417 target address field, if any, is sufficient to have it be reset
1418 automagically. Certainly on HP-UX that's true.
1420 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1421 valid code address on some platforms (like the mn10300
1422 simulators). We shouldn't assign any special interpretation to
1423 a breakpoint with a zero address. And in fact, GDB doesn't ---
1424 I can't see what that comment above is talking about. As far
1425 as I can tell, setting the address of a
1426 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1427 is meaningless, since those are implemented with HP-UX kernel
1428 hackery, not by storing breakpoint instructions somewhere. */
1429 if ((b
->type
== bp_catch_exec
) ||
1430 (b
->type
== bp_catch_vfork
) ||
1431 (b
->type
== bp_catch_fork
))
1433 b
->loc
->address
= (CORE_ADDR
) 0;
1437 /* bp_finish is a special case. The only way we ought to be able
1438 to see one of these when an exec() has happened, is if the user
1439 caught a vfork, and then said "finish". Ordinarily a finish just
1440 carries them to the call-site of the current callee, by setting
1441 a temporary bp there and resuming. But in this case, the finish
1442 will carry them entirely through the vfork & exec.
1444 We don't want to allow a bp_finish to remain inserted now. But
1445 we can't safely delete it, 'cause finish_command has a handle to
1446 the bp on a bpstat, and will later want to delete it. There's a
1447 chance (and I've seen it happen) that if we delete the bp_finish
1448 here, that its storage will get reused by the time finish_command
1449 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1450 We really must allow finish_command to delete a bp_finish.
1452 In the absense of a general solution for the "how do we know
1453 it's safe to delete something others may have handles to?"
1454 problem, what we'll do here is just uninsert the bp_finish, and
1455 let finish_command delete it.
1457 (We know the bp_finish is "doomed" in the sense that it's
1458 momentary, and will be deleted as soon as finish_command sees
1459 the inferior stopped. So it doesn't matter that the bp's
1460 address is probably bogus in the new a.out, unlike e.g., the
1461 solib breakpoints.) */
1463 if (b
->type
== bp_finish
)
1468 /* Without a symbolic address, we have little hope of the
1469 pre-exec() address meaning the same thing in the post-exec()
1471 if (b
->addr_string
== NULL
)
1473 delete_breakpoint (b
);
1477 /* If this breakpoint has survived the above battery of checks, then
1478 it must have a symbolic address. Be sure that it gets reevaluated
1479 to a target address, rather than reusing the old evaluation.
1481 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1482 for bp_catch_exec and friends, I'm pretty sure this is entirely
1483 unnecessary. A call to breakpoint_re_set_one always recomputes
1484 the breakpoint's address from scratch, or deletes it if it can't.
1485 So I think this assignment could be deleted without effect. */
1486 b
->loc
->address
= (CORE_ADDR
) 0;
1488 /* FIXME what about longjmp breakpoints? Re-create them here? */
1489 create_overlay_event_breakpoint ("_ovly_debug_event");
1493 detach_breakpoints (int pid
)
1495 struct bp_location
*b
;
1497 struct cleanup
*old_chain
= save_inferior_ptid ();
1499 if (pid
== PIDGET (inferior_ptid
))
1500 error (_("Cannot detach breakpoints of inferior_ptid"));
1502 /* Set inferior_ptid; remove_breakpoint uses this global. */
1503 inferior_ptid
= pid_to_ptid (pid
);
1504 ALL_BP_LOCATIONS (b
)
1508 val
= remove_breakpoint (b
, mark_inserted
);
1511 do_cleanups (old_chain
);
1516 do_cleanups (old_chain
);
1521 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1525 if (b
->owner
->enable_state
== bp_permanent
)
1526 /* Permanent breakpoints cannot be inserted or removed. */
1529 if (b
->owner
->type
== bp_none
)
1530 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1533 if (b
->loc_type
== bp_loc_software_breakpoint
1534 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1536 /* "Normal" instruction breakpoint: either the standard
1537 trap-instruction bp (bp_breakpoint), or a
1538 bp_hardware_breakpoint. */
1540 /* First check to see if we have to handle an overlay. */
1541 if (overlay_debugging
== ovly_off
1542 || b
->section
== NULL
1543 || !(section_is_overlay (b
->section
)))
1545 /* No overlay handling: just remove the breakpoint. */
1547 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1548 val
= target_remove_hw_breakpoint (&b
->target_info
);
1550 val
= target_remove_breakpoint (&b
->target_info
);
1554 /* This breakpoint is in an overlay section.
1555 Did we set a breakpoint at the LMA? */
1556 if (!overlay_events_enabled
)
1558 /* Yes -- overlay event support is not active, so we
1559 should have set a breakpoint at the LMA. Remove it.
1561 /* Ignore any failures: if the LMA is in ROM, we will
1562 have already warned when we failed to insert it. */
1563 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1564 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1566 target_remove_breakpoint (&b
->overlay_target_info
);
1568 /* Did we set a breakpoint at the VMA?
1569 If so, we will have marked the breakpoint 'inserted'. */
1572 /* Yes -- remove it. Previously we did not bother to
1573 remove the breakpoint if the section had been
1574 unmapped, but let's not rely on that being safe. We
1575 don't know what the overlay manager might do. */
1576 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1577 val
= target_remove_hw_breakpoint (&b
->target_info
);
1579 /* However, we should remove *software* breakpoints only
1580 if the section is still mapped, or else we overwrite
1581 wrong code with the saved shadow contents. */
1582 else if (section_is_mapped (b
->section
))
1583 val
= target_remove_breakpoint (&b
->target_info
);
1589 /* No -- not inserted, so no need to remove. No error. */
1595 b
->inserted
= (is
== mark_inserted
);
1597 else if (b
->loc_type
== bp_loc_hardware_watchpoint
1598 && breakpoint_enabled (b
->owner
)
1604 b
->inserted
= (is
== mark_inserted
);
1605 /* Walk down the saved value chain. */
1606 for (v
= b
->owner
->val_chain
; v
; v
= value_next (v
))
1608 /* For each memory reference remove the watchpoint
1610 if (VALUE_LVAL (v
) == lval_memory
1611 && ! value_lazy (v
))
1613 struct type
*vtype
= check_typedef (value_type (v
));
1615 if (v
== b
->owner
->val_chain
1616 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1617 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1622 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
1623 len
= TYPE_LENGTH (value_type (v
));
1625 if (b
->owner
->type
== bp_read_watchpoint
)
1627 else if (b
->owner
->type
== bp_access_watchpoint
)
1630 val
= target_remove_watchpoint (addr
, len
, type
);
1637 /* Failure to remove any of the hardware watchpoints comes here. */
1638 if ((is
== mark_uninserted
) && (b
->inserted
))
1639 warning (_("Could not remove hardware watchpoint %d."),
1642 else if ((b
->owner
->type
== bp_catch_fork
||
1643 b
->owner
->type
== bp_catch_vfork
||
1644 b
->owner
->type
== bp_catch_exec
)
1645 && breakpoint_enabled (b
->owner
)
1649 switch (b
->owner
->type
)
1652 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1654 case bp_catch_vfork
:
1655 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1658 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1661 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1666 b
->inserted
= (is
== mark_inserted
);
1668 else if ((b
->owner
->type
== bp_catch_catch
||
1669 b
->owner
->type
== bp_catch_throw
)
1670 && breakpoint_enabled (b
->owner
)
1673 val
= target_remove_breakpoint (&b
->target_info
);
1676 b
->inserted
= (is
== mark_inserted
);
1682 /* Clear the "inserted" flag in all breakpoints. */
1685 mark_breakpoints_out (void)
1687 struct bp_location
*bpt
;
1689 ALL_BP_LOCATIONS (bpt
)
1693 /* Clear the "inserted" flag in all breakpoints and delete any
1694 breakpoints which should go away between runs of the program.
1696 Plus other such housekeeping that has to be done for breakpoints
1699 Note: this function gets called at the end of a run (by
1700 generic_mourn_inferior) and when a run begins (by
1701 init_wait_for_inferior). */
1706 breakpoint_init_inferior (enum inf_context context
)
1708 struct breakpoint
*b
, *temp
;
1709 struct bp_location
*bpt
;
1711 ALL_BP_LOCATIONS (bpt
)
1714 ALL_BREAKPOINTS_SAFE (b
, temp
)
1719 case bp_watchpoint_scope
:
1721 /* If the call dummy breakpoint is at the entry point it will
1722 cause problems when the inferior is rerun, so we better
1725 Also get rid of scope breakpoints. */
1726 delete_breakpoint (b
);
1730 case bp_hardware_watchpoint
:
1731 case bp_read_watchpoint
:
1732 case bp_access_watchpoint
:
1734 /* Likewise for watchpoints on local expressions. */
1735 if (b
->exp_valid_block
!= NULL
)
1736 delete_breakpoint (b
);
1737 if (context
== inf_starting
)
1739 /* Reset val field to force reread of starting value
1740 in insert_breakpoints. */
1742 value_free (b
->val
);
1752 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1753 exists at PC. It returns ordinary_breakpoint_here if it's an
1754 ordinary breakpoint, or permanent_breakpoint_here if it's a
1755 permanent breakpoint.
1756 - When continuing from a location with an ordinary breakpoint, we
1757 actually single step once before calling insert_breakpoints.
1758 - When continuing from a localion with a permanent breakpoint, we
1759 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1760 the target, to advance the PC past the breakpoint. */
1762 enum breakpoint_here
1763 breakpoint_here_p (CORE_ADDR pc
)
1765 struct bp_location
*bpt
;
1766 int any_breakpoint_here
= 0;
1768 ALL_BP_LOCATIONS (bpt
)
1770 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1771 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1774 if ((breakpoint_enabled (bpt
->owner
)
1775 || bpt
->owner
->enable_state
== bp_permanent
)
1776 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1778 if (overlay_debugging
1779 && section_is_overlay (bpt
->section
)
1780 && !section_is_mapped (bpt
->section
))
1781 continue; /* unmapped overlay -- can't be a match */
1782 else if (bpt
->owner
->enable_state
== bp_permanent
)
1783 return permanent_breakpoint_here
;
1785 any_breakpoint_here
= 1;
1789 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1793 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1794 but it only returns true if there is actually a breakpoint inserted
1798 breakpoint_inserted_here_p (CORE_ADDR pc
)
1800 struct bp_location
*bpt
;
1802 ALL_BP_LOCATIONS (bpt
)
1804 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1805 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1809 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1811 if (overlay_debugging
1812 && section_is_overlay (bpt
->section
)
1813 && !section_is_mapped (bpt
->section
))
1814 continue; /* unmapped overlay -- can't be a match */
1820 /* Also check for software single-step breakpoints. */
1821 if (single_step_breakpoint_inserted_here_p (pc
))
1827 /* This function returns non-zero iff there is a software breakpoint
1831 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1833 struct bp_location
*bpt
;
1834 int any_breakpoint_here
= 0;
1836 ALL_BP_LOCATIONS (bpt
)
1838 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1841 if ((breakpoint_enabled (bpt
->owner
)
1842 || bpt
->owner
->enable_state
== bp_permanent
)
1844 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1846 if (overlay_debugging
1847 && section_is_overlay (bpt
->section
)
1848 && !section_is_mapped (bpt
->section
))
1849 continue; /* unmapped overlay -- can't be a match */
1855 /* Also check for software single-step breakpoints. */
1856 if (single_step_breakpoint_inserted_here_p (pc
))
1862 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1863 PC is valid for process/thread PTID. */
1866 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1868 struct bp_location
*bpt
;
1871 thread
= pid_to_thread_id (ptid
);
1873 ALL_BP_LOCATIONS (bpt
)
1875 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1876 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1879 if ((breakpoint_enabled (bpt
->owner
)
1880 || bpt
->owner
->enable_state
== bp_permanent
)
1881 && bpt
->address
== pc
1882 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1884 if (overlay_debugging
1885 && section_is_overlay (bpt
->section
)
1886 && !section_is_mapped (bpt
->section
))
1887 continue; /* unmapped overlay -- can't be a match */
1897 /* bpstat stuff. External routines' interfaces are documented
1901 ep_is_catchpoint (struct breakpoint
*ep
)
1904 (ep
->type
== bp_catch_load
)
1905 || (ep
->type
== bp_catch_unload
)
1906 || (ep
->type
== bp_catch_fork
)
1907 || (ep
->type
== bp_catch_vfork
)
1908 || (ep
->type
== bp_catch_exec
)
1909 || (ep
->type
== bp_catch_catch
)
1910 || (ep
->type
== bp_catch_throw
);
1912 /* ??rehrauer: Add more kinds here, as are implemented... */
1916 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1919 (ep
->type
== bp_catch_load
)
1920 || (ep
->type
== bp_catch_unload
);
1924 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1927 (ep
->type
== bp_catch_catch
)
1928 || (ep
->type
== bp_catch_throw
);
1931 /* Clear a bpstat so that it says we are not at any breakpoint.
1932 Also free any storage that is part of a bpstat. */
1935 bpstat_clear (bpstat
*bsp
)
1946 if (p
->old_val
!= NULL
)
1947 value_free (p
->old_val
);
1948 free_command_lines (&p
->commands
);
1955 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1956 is part of the bpstat is copied as well. */
1959 bpstat_copy (bpstat bs
)
1963 bpstat retval
= NULL
;
1968 for (; bs
!= NULL
; bs
= bs
->next
)
1970 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1971 memcpy (tmp
, bs
, sizeof (*tmp
));
1972 if (bs
->commands
!= NULL
)
1973 tmp
->commands
= copy_command_lines (bs
->commands
);
1974 if (bs
->old_val
!= NULL
)
1975 tmp
->old_val
= value_copy (bs
->old_val
);
1978 /* This is the first thing in the chain. */
1988 /* Find the bpstat associated with this breakpoint */
1991 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1996 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1998 if (bsp
->breakpoint_at
== breakpoint
)
2004 /* Find a step_resume breakpoint associated with this bpstat.
2005 (If there are multiple step_resume bp's on the list, this function
2006 will arbitrarily pick one.)
2008 It is an error to use this function if BPSTAT doesn't contain a
2009 step_resume breakpoint.
2011 See wait_for_inferior's use of this function. */
2013 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2017 gdb_assert (bsp
!= NULL
);
2019 current_thread
= pid_to_thread_id (inferior_ptid
);
2021 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2023 if ((bsp
->breakpoint_at
!= NULL
) &&
2024 (bsp
->breakpoint_at
->type
== bp_step_resume
) &&
2025 (bsp
->breakpoint_at
->thread
== current_thread
||
2026 bsp
->breakpoint_at
->thread
== -1))
2027 return bsp
->breakpoint_at
;
2030 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2034 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2035 at. *BSP upon return is a bpstat which points to the remaining
2036 breakpoints stopped at (but which is not guaranteed to be good for
2037 anything but further calls to bpstat_num).
2038 Return 0 if passed a bpstat which does not indicate any breakpoints.
2039 Return -1 if stopped at a breakpoint that has been deleted since
2041 Return 1 otherwise. */
2044 bpstat_num (bpstat
*bsp
, int *num
)
2046 struct breakpoint
*b
;
2049 return 0; /* No more breakpoint values */
2051 b
= (*bsp
)->breakpoint_at
;
2052 *bsp
= (*bsp
)->next
;
2054 return -1; /* breakpoint that's been deleted since */
2056 *num
= b
->number
; /* We have its number */
2060 /* Modify BS so that the actions will not be performed. */
2063 bpstat_clear_actions (bpstat bs
)
2065 for (; bs
!= NULL
; bs
= bs
->next
)
2067 free_command_lines (&bs
->commands
);
2068 if (bs
->old_val
!= NULL
)
2070 value_free (bs
->old_val
);
2076 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2078 cleanup_executing_breakpoints (void *ignore
)
2080 executing_breakpoint_commands
= 0;
2083 /* Execute all the commands associated with all the breakpoints at this
2084 location. Any of these commands could cause the process to proceed
2085 beyond this point, etc. We look out for such changes by checking
2086 the global "breakpoint_proceeded" after each command. */
2089 bpstat_do_actions (bpstat
*bsp
)
2092 struct cleanup
*old_chain
;
2094 /* Avoid endless recursion if a `source' command is contained
2096 if (executing_breakpoint_commands
)
2099 executing_breakpoint_commands
= 1;
2100 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2103 /* Note that (as of this writing), our callers all appear to
2104 be passing us the address of global stop_bpstat. And, if
2105 our calls to execute_control_command cause the inferior to
2106 proceed, that global (and hence, *bsp) will change.
2108 We must be careful to not touch *bsp unless the inferior
2109 has not proceeded. */
2111 /* This pointer will iterate over the list of bpstat's. */
2114 breakpoint_proceeded
= 0;
2115 for (; bs
!= NULL
; bs
= bs
->next
)
2117 struct command_line
*cmd
;
2118 struct cleanup
*this_cmd_tree_chain
;
2120 /* Take ownership of the BSP's command tree, if it has one.
2122 The command tree could legitimately contain commands like
2123 'step' and 'next', which call clear_proceed_status, which
2124 frees stop_bpstat's command tree. To make sure this doesn't
2125 free the tree we're executing out from under us, we need to
2126 take ownership of the tree ourselves. Since a given bpstat's
2127 commands are only executed once, we don't need to copy it; we
2128 can clear the pointer in the bpstat, and make sure we free
2129 the tree when we're done. */
2132 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2136 execute_control_command (cmd
);
2138 if (breakpoint_proceeded
)
2144 /* We can free this command tree now. */
2145 do_cleanups (this_cmd_tree_chain
);
2147 if (breakpoint_proceeded
)
2148 /* The inferior is proceeded by the command; bomb out now.
2149 The bpstat chain has been blown away by wait_for_inferior.
2150 But since execution has stopped again, there is a new bpstat
2151 to look at, so start over. */
2154 do_cleanups (old_chain
);
2157 /* This is the normal print function for a bpstat. In the future,
2158 much of this logic could (should?) be moved to bpstat_stop_status,
2159 by having it set different print_it values.
2161 Current scheme: When we stop, bpstat_print() is called. It loops
2162 through the bpstat list of things causing this stop, calling the
2163 print_bp_stop_message function on each one. The behavior of the
2164 print_bp_stop_message function depends on the print_it field of
2165 bpstat. If such field so indicates, call this function here.
2167 Return values from this routine (ultimately used by bpstat_print()
2168 and normal_stop() to decide what to do):
2169 PRINT_NOTHING: Means we already printed all we needed to print,
2170 don't print anything else.
2171 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2172 that something to be followed by a location.
2173 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2174 that something to be followed by a location.
2175 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2178 static enum print_stop_action
2179 print_it_typical (bpstat bs
)
2181 struct cleanup
*old_chain
, *ui_out_chain
;
2182 struct ui_stream
*stb
;
2183 stb
= ui_out_stream_new (uiout
);
2184 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2185 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2186 which has since been deleted. */
2187 if (bs
->breakpoint_at
== NULL
)
2188 return PRINT_UNKNOWN
;
2190 switch (bs
->breakpoint_at
->type
)
2193 case bp_hardware_breakpoint
:
2194 if (bs
->breakpoint_at
->loc
->address
!= bs
->breakpoint_at
->loc
->requested_address
)
2195 breakpoint_adjustment_warning (bs
->breakpoint_at
->loc
->requested_address
,
2196 bs
->breakpoint_at
->loc
->address
,
2197 bs
->breakpoint_at
->number
, 1);
2198 annotate_breakpoint (bs
->breakpoint_at
->number
);
2199 ui_out_text (uiout
, "\nBreakpoint ");
2200 if (ui_out_is_mi_like_p (uiout
))
2201 ui_out_field_string (uiout
, "reason",
2202 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2203 ui_out_field_int (uiout
, "bkptno", bs
->breakpoint_at
->number
);
2204 ui_out_text (uiout
, ", ");
2205 return PRINT_SRC_AND_LOC
;
2208 case bp_shlib_event
:
2209 /* Did we stop because the user set the stop_on_solib_events
2210 variable? (If so, we report this as a generic, "Stopped due
2211 to shlib event" message.) */
2212 printf_filtered (_("Stopped due to shared library event\n"));
2213 return PRINT_NOTHING
;
2216 case bp_thread_event
:
2217 /* Not sure how we will get here.
2218 GDB should not stop for these breakpoints. */
2219 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2220 return PRINT_NOTHING
;
2223 case bp_overlay_event
:
2224 /* By analogy with the thread event, GDB should not stop for these. */
2225 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2226 return PRINT_NOTHING
;
2230 annotate_catchpoint (bs
->breakpoint_at
->number
);
2231 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2232 bs
->breakpoint_at
->number
,
2233 bs
->breakpoint_at
->triggered_dll_pathname
);
2234 return PRINT_SRC_AND_LOC
;
2237 case bp_catch_unload
:
2238 annotate_catchpoint (bs
->breakpoint_at
->number
);
2239 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2240 bs
->breakpoint_at
->number
,
2241 bs
->breakpoint_at
->triggered_dll_pathname
);
2242 return PRINT_SRC_AND_LOC
;
2246 annotate_catchpoint (bs
->breakpoint_at
->number
);
2247 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2248 bs
->breakpoint_at
->number
,
2249 bs
->breakpoint_at
->forked_inferior_pid
);
2250 return PRINT_SRC_AND_LOC
;
2253 case bp_catch_vfork
:
2254 annotate_catchpoint (bs
->breakpoint_at
->number
);
2255 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2256 bs
->breakpoint_at
->number
,
2257 bs
->breakpoint_at
->forked_inferior_pid
);
2258 return PRINT_SRC_AND_LOC
;
2262 annotate_catchpoint (bs
->breakpoint_at
->number
);
2263 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2264 bs
->breakpoint_at
->number
,
2265 bs
->breakpoint_at
->exec_pathname
);
2266 return PRINT_SRC_AND_LOC
;
2269 case bp_catch_catch
:
2270 if (current_exception_event
&&
2271 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2273 annotate_catchpoint (bs
->breakpoint_at
->number
);
2274 printf_filtered (_("\nCatchpoint %d (exception caught), "),
2275 bs
->breakpoint_at
->number
);
2276 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2277 printf_filtered (_("throw location %s:%d, "),
2278 CURRENT_EXCEPTION_THROW_FILE
,
2279 CURRENT_EXCEPTION_THROW_LINE
);
2281 printf_filtered (_("throw location unknown, "));
2283 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2284 printf_filtered (_("catch location %s:%d\n"),
2285 CURRENT_EXCEPTION_CATCH_FILE
,
2286 CURRENT_EXCEPTION_CATCH_LINE
);
2288 printf_filtered (_("catch location unknown\n"));
2290 /* don't bother to print location frame info */
2291 return PRINT_SRC_ONLY
;
2295 /* really throw, some other bpstat will handle it */
2296 return PRINT_UNKNOWN
;
2300 case bp_catch_throw
:
2301 if (current_exception_event
&&
2302 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2304 annotate_catchpoint (bs
->breakpoint_at
->number
);
2305 printf_filtered (_("\nCatchpoint %d (exception thrown), "),
2306 bs
->breakpoint_at
->number
);
2307 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2308 printf_filtered (_("throw location %s:%d, "),
2309 CURRENT_EXCEPTION_THROW_FILE
,
2310 CURRENT_EXCEPTION_THROW_LINE
);
2312 printf_filtered (_("throw location unknown, "));
2314 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2315 printf_filtered (_("catch location %s:%d\n"),
2316 CURRENT_EXCEPTION_CATCH_FILE
,
2317 CURRENT_EXCEPTION_CATCH_LINE
);
2319 printf_filtered (_("catch location unknown\n"));
2321 /* don't bother to print location frame info */
2322 return PRINT_SRC_ONLY
;
2326 /* really catch, some other bpstat will handle it */
2327 return PRINT_UNKNOWN
;
2332 case bp_hardware_watchpoint
:
2333 if (bs
->old_val
!= NULL
)
2335 annotate_watchpoint (bs
->breakpoint_at
->number
);
2336 if (ui_out_is_mi_like_p (uiout
))
2339 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2340 mention (bs
->breakpoint_at
);
2341 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2342 ui_out_text (uiout
, "\nOld value = ");
2343 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2344 ui_out_field_stream (uiout
, "old", stb
);
2345 ui_out_text (uiout
, "\nNew value = ");
2346 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2347 ui_out_field_stream (uiout
, "new", stb
);
2348 do_cleanups (ui_out_chain
);
2349 ui_out_text (uiout
, "\n");
2350 value_free (bs
->old_val
);
2353 /* More than one watchpoint may have been triggered. */
2354 return PRINT_UNKNOWN
;
2357 case bp_read_watchpoint
:
2358 if (ui_out_is_mi_like_p (uiout
))
2361 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2362 mention (bs
->breakpoint_at
);
2363 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2364 ui_out_text (uiout
, "\nValue = ");
2365 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2366 ui_out_field_stream (uiout
, "value", stb
);
2367 do_cleanups (ui_out_chain
);
2368 ui_out_text (uiout
, "\n");
2369 return PRINT_UNKNOWN
;
2372 case bp_access_watchpoint
:
2373 if (bs
->old_val
!= NULL
)
2375 annotate_watchpoint (bs
->breakpoint_at
->number
);
2376 if (ui_out_is_mi_like_p (uiout
))
2379 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2380 mention (bs
->breakpoint_at
);
2381 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2382 ui_out_text (uiout
, "\nOld value = ");
2383 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2384 ui_out_field_stream (uiout
, "old", stb
);
2385 value_free (bs
->old_val
);
2387 ui_out_text (uiout
, "\nNew value = ");
2391 mention (bs
->breakpoint_at
);
2392 if (ui_out_is_mi_like_p (uiout
))
2395 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2396 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2397 ui_out_text (uiout
, "\nValue = ");
2399 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0,Val_pretty_default
);
2400 ui_out_field_stream (uiout
, "new", stb
);
2401 do_cleanups (ui_out_chain
);
2402 ui_out_text (uiout
, "\n");
2403 return PRINT_UNKNOWN
;
2406 /* Fall through, we don't deal with these types of breakpoints
2410 if (ui_out_is_mi_like_p (uiout
))
2413 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2414 return PRINT_UNKNOWN
;
2418 if (ui_out_is_mi_like_p (uiout
))
2421 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2422 return PRINT_UNKNOWN
;
2427 case bp_longjmp_resume
:
2428 case bp_step_resume
:
2429 case bp_watchpoint_scope
:
2432 return PRINT_UNKNOWN
;
2436 /* Generic routine for printing messages indicating why we
2437 stopped. The behavior of this function depends on the value
2438 'print_it' in the bpstat structure. Under some circumstances we
2439 may decide not to print anything here and delegate the task to
2442 static enum print_stop_action
2443 print_bp_stop_message (bpstat bs
)
2445 switch (bs
->print_it
)
2448 /* Nothing should be printed for this bpstat entry. */
2449 return PRINT_UNKNOWN
;
2453 /* We still want to print the frame, but we already printed the
2454 relevant messages. */
2455 return PRINT_SRC_AND_LOC
;
2458 case print_it_normal
:
2459 /* Normal case. Call the breakpoint's print_it method, or
2460 print_it_typical. */
2461 if (bs
->breakpoint_at
!= NULL
&& bs
->breakpoint_at
->ops
!= NULL
2462 && bs
->breakpoint_at
->ops
->print_it
!= NULL
)
2463 return bs
->breakpoint_at
->ops
->print_it (bs
->breakpoint_at
);
2465 return print_it_typical (bs
);
2469 internal_error (__FILE__
, __LINE__
,
2470 _("print_bp_stop_message: unrecognized enum value"));
2475 /* Print a message indicating what happened. This is called from
2476 normal_stop(). The input to this routine is the head of the bpstat
2477 list - a list of the eventpoints that caused this stop. This
2478 routine calls the generic print routine for printing a message
2479 about reasons for stopping. This will print (for example) the
2480 "Breakpoint n," part of the output. The return value of this
2483 PRINT_UNKNOWN: Means we printed nothing
2484 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2485 code to print the location. An example is
2486 "Breakpoint 1, " which should be followed by
2488 PRINT_SRC_ONLY: Means we printed something, but there is no need
2489 to also print the location part of the message.
2490 An example is the catch/throw messages, which
2491 don't require a location appended to the end.
2492 PRINT_NOTHING: We have done some printing and we don't need any
2493 further info to be printed.*/
2495 enum print_stop_action
2496 bpstat_print (bpstat bs
)
2500 /* Maybe another breakpoint in the chain caused us to stop.
2501 (Currently all watchpoints go on the bpstat whether hit or not.
2502 That probably could (should) be changed, provided care is taken
2503 with respect to bpstat_explains_signal). */
2504 for (; bs
; bs
= bs
->next
)
2506 val
= print_bp_stop_message (bs
);
2507 if (val
== PRINT_SRC_ONLY
2508 || val
== PRINT_SRC_AND_LOC
2509 || val
== PRINT_NOTHING
)
2513 /* We reached the end of the chain, or we got a null BS to start
2514 with and nothing was printed. */
2515 return PRINT_UNKNOWN
;
2518 /* Evaluate the expression EXP and return 1 if value is zero.
2519 This is used inside a catch_errors to evaluate the breakpoint condition.
2520 The argument is a "struct expression *" that has been cast to char * to
2521 make it pass through catch_errors. */
2524 breakpoint_cond_eval (void *exp
)
2526 struct value
*mark
= value_mark ();
2527 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2528 value_free_to_mark (mark
);
2532 /* Allocate a new bpstat and chain it to the current one. */
2535 bpstat_alloc (struct breakpoint
*b
, bpstat cbs
/* Current "bs" value */ )
2539 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2541 bs
->breakpoint_at
= b
;
2542 /* If the condition is false, etc., don't do the commands. */
2543 bs
->commands
= NULL
;
2545 bs
->print_it
= print_it_normal
;
2549 /* Possible return values for watchpoint_check (this can't be an enum
2550 because of check_errors). */
2551 /* The watchpoint has been deleted. */
2552 #define WP_DELETED 1
2553 /* The value has changed. */
2554 #define WP_VALUE_CHANGED 2
2555 /* The value has not changed. */
2556 #define WP_VALUE_NOT_CHANGED 3
2558 #define BP_TEMPFLAG 1
2559 #define BP_HARDWAREFLAG 2
2561 /* Check watchpoint condition. */
2564 watchpoint_check (void *p
)
2566 bpstat bs
= (bpstat
) p
;
2567 struct breakpoint
*b
;
2568 struct frame_info
*fr
;
2569 int within_current_scope
;
2571 b
= bs
->breakpoint_at
;
2573 if (b
->exp_valid_block
== NULL
)
2574 within_current_scope
= 1;
2577 /* There is no current frame at this moment. If we're going to have
2578 any chance of handling watchpoints on local variables, we'll need
2579 the frame chain (so we can determine if we're in scope). */
2580 reinit_frame_cache ();
2581 fr
= frame_find_by_id (b
->watchpoint_frame
);
2582 within_current_scope
= (fr
!= NULL
);
2584 /* If we've gotten confused in the unwinder, we might have
2585 returned a frame that can't describe this variable. */
2586 if (within_current_scope
2587 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2588 within_current_scope
= 0;
2590 /* in_function_epilogue_p() returns a non-zero value if we're still
2591 in the function but the stack frame has already been invalidated.
2592 Since we can't rely on the values of local variables after the
2593 stack has been destroyed, we are treating the watchpoint in that
2594 state as `not changed' without further checking.
2596 vinschen/2003-09-04: The former implementation left out the case
2597 that the watchpoint frame couldn't be found by frame_find_by_id()
2598 because the current PC is currently in an epilogue. Calling
2599 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2600 if ((!within_current_scope
|| fr
== get_current_frame ())
2601 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2602 return WP_VALUE_NOT_CHANGED
;
2603 if (fr
&& within_current_scope
)
2604 /* If we end up stopping, the current frame will get selected
2605 in normal_stop. So this call to select_frame won't affect
2610 if (within_current_scope
)
2612 /* We use value_{,free_to_}mark because it could be a
2613 *long* time before we return to the command level and
2614 call free_all_values. We can't call free_all_values because
2615 we might be in the middle of evaluating a function call. */
2617 struct value
*mark
= value_mark ();
2618 struct value
*new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
2619 if (!value_equal (b
->val
, new_val
))
2621 release_value (new_val
);
2622 value_free_to_mark (mark
);
2623 bs
->old_val
= b
->val
;
2625 /* We will stop here */
2626 return WP_VALUE_CHANGED
;
2630 /* Nothing changed, don't do anything. */
2631 value_free_to_mark (mark
);
2632 /* We won't stop here */
2633 return WP_VALUE_NOT_CHANGED
;
2638 /* This seems like the only logical thing to do because
2639 if we temporarily ignored the watchpoint, then when
2640 we reenter the block in which it is valid it contains
2641 garbage (in the case of a function, it may have two
2642 garbage values, one before and one after the prologue).
2643 So we can't even detect the first assignment to it and
2644 watch after that (since the garbage may or may not equal
2645 the first value assigned). */
2646 /* We print all the stop information in print_it_typical(), but
2647 in this case, by the time we call print_it_typical() this bp
2648 will be deleted already. So we have no choice but print the
2649 information here. */
2650 if (ui_out_is_mi_like_p (uiout
))
2652 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2653 ui_out_text (uiout
, "\nWatchpoint ");
2654 ui_out_field_int (uiout
, "wpnum", bs
->breakpoint_at
->number
);
2655 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2656 which its expression is valid.\n");
2658 if (b
->related_breakpoint
)
2659 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2660 b
->disposition
= disp_del_at_next_stop
;
2666 /* Get a bpstat associated with having just stopped at address
2667 BP_ADDR in thread PTID. STOPPED_BY_WATCHPOINT is 1 if the
2668 target thinks we stopped due to a hardware watchpoint, 0 if we
2669 know we did not trigger a hardware watchpoint, and -1 if we do not know. */
2671 /* Determine whether we stopped at a breakpoint, etc, or whether we
2672 don't understand this stop. Result is a chain of bpstat's such that:
2674 if we don't understand the stop, the result is a null pointer.
2676 if we understand why we stopped, the result is not null.
2678 Each element of the chain refers to a particular breakpoint or
2679 watchpoint at which we have stopped. (We may have stopped for
2680 several reasons concurrently.)
2682 Each element of the chain has valid next, breakpoint_at,
2683 commands, FIXME??? fields. */
2686 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
, int stopped_by_watchpoint
)
2688 struct breakpoint
*b
, *temp
;
2689 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2690 int real_breakpoint
= 0;
2691 /* Root of the chain of bpstat's */
2692 struct bpstats root_bs
[1];
2693 /* Pointer to the last thing in the chain currently. */
2694 bpstat bs
= root_bs
;
2695 int thread_id
= pid_to_thread_id (ptid
);
2697 ALL_BREAKPOINTS_SAFE (b
, temp
)
2699 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2702 if (b
->type
!= bp_watchpoint
2703 && b
->type
!= bp_hardware_watchpoint
2704 && b
->type
!= bp_read_watchpoint
2705 && b
->type
!= bp_access_watchpoint
2706 && b
->type
!= bp_hardware_breakpoint
2707 && b
->type
!= bp_catch_fork
2708 && b
->type
!= bp_catch_vfork
2709 && b
->type
!= bp_catch_exec
2710 && b
->type
!= bp_catch_catch
2711 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2713 if (b
->loc
->address
!= bp_addr
) /* address doesn't match */
2715 if (overlay_debugging
/* unmapped overlay section */
2716 && section_is_overlay (b
->loc
->section
)
2717 && !section_is_mapped (b
->loc
->section
))
2721 /* Continuable hardware watchpoints are treated as non-existent if the
2722 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2723 some data address). Otherwise gdb won't stop on a break instruction
2724 in the code (not from a breakpoint) when a hardware watchpoint has
2727 if ((b
->type
== bp_hardware_watchpoint
2728 || b
->type
== bp_read_watchpoint
2729 || b
->type
== bp_access_watchpoint
)
2730 && !stopped_by_watchpoint
)
2733 if (b
->type
== bp_hardware_breakpoint
)
2735 if (b
->loc
->address
!= bp_addr
)
2737 if (overlay_debugging
/* unmapped overlay section */
2738 && section_is_overlay (b
->loc
->section
)
2739 && !section_is_mapped (b
->loc
->section
))
2743 /* Is this a catchpoint of a load or unload? If so, did we
2744 get a load or unload of the specified library? If not,
2746 if ((b
->type
== bp_catch_load
)
2747 #if defined(SOLIB_HAVE_LOAD_EVENT)
2748 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2749 || ((b
->dll_pathname
!= NULL
)
2750 && (strcmp (b
->dll_pathname
,
2751 SOLIB_LOADED_LIBRARY_PATHNAME (
2752 PIDGET (inferior_ptid
)))
2758 if ((b
->type
== bp_catch_unload
)
2759 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2760 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2761 || ((b
->dll_pathname
!= NULL
)
2762 && (strcmp (b
->dll_pathname
,
2763 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2764 PIDGET (inferior_ptid
)))
2770 if ((b
->type
== bp_catch_fork
)
2771 && !inferior_has_forked (PIDGET (inferior_ptid
),
2772 &b
->forked_inferior_pid
))
2775 if ((b
->type
== bp_catch_vfork
)
2776 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2777 &b
->forked_inferior_pid
))
2780 if ((b
->type
== bp_catch_exec
)
2781 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2784 if (ep_is_exception_catchpoint (b
) &&
2785 !(current_exception_event
= target_get_current_exception_event ()))
2788 /* Come here if it's a watchpoint, or if the break address matches */
2790 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
2792 /* Watchpoints may change this, if not found to have triggered. */
2796 if (b
->type
== bp_watchpoint
||
2797 b
->type
== bp_hardware_watchpoint
)
2799 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2801 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2802 int e
= catch_errors (watchpoint_check
, bs
, message
,
2804 do_cleanups (cleanups
);
2808 /* We've already printed what needs to be printed. */
2809 /* Actually this is superfluous, because by the time we
2810 call print_it_typical() the wp will be already deleted,
2811 and the function will return immediately. */
2812 bs
->print_it
= print_it_done
;
2815 case WP_VALUE_CHANGED
:
2819 case WP_VALUE_NOT_CHANGED
:
2821 bs
->print_it
= print_it_noop
;
2828 /* Error from catch_errors. */
2829 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2830 if (b
->related_breakpoint
)
2831 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2832 b
->disposition
= disp_del_at_next_stop
;
2833 /* We've already printed what needs to be printed. */
2834 bs
->print_it
= print_it_done
;
2840 else if (b
->type
== bp_read_watchpoint
||
2841 b
->type
== bp_access_watchpoint
)
2847 if (!target_stopped_data_address (¤t_target
, &addr
))
2849 for (v
= b
->val_chain
; v
; v
= value_next (v
))
2851 if (VALUE_LVAL (v
) == lval_memory
2852 && ! value_lazy (v
))
2854 struct type
*vtype
= check_typedef (value_type (v
));
2856 if (v
== b
->val_chain
2857 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2858 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2862 vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
2863 /* Exact match not required. Within range is
2865 if (addr
>= vaddr
&&
2866 addr
< vaddr
+ TYPE_LENGTH (value_type (v
)))
2873 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2875 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2876 int e
= catch_errors (watchpoint_check
, bs
, message
,
2878 do_cleanups (cleanups
);
2882 /* We've already printed what needs to be printed. */
2883 bs
->print_it
= print_it_done
;
2886 case WP_VALUE_CHANGED
:
2887 if (b
->type
== bp_read_watchpoint
)
2889 /* Don't stop: read watchpoints shouldn't fire if
2890 the value has changed. This is for targets
2891 which cannot set read-only watchpoints. */
2892 bs
->print_it
= print_it_noop
;
2898 case WP_VALUE_NOT_CHANGED
:
2905 /* Error from catch_errors. */
2906 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2907 if (b
->related_breakpoint
)
2908 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2909 b
->disposition
= disp_del_at_next_stop
;
2910 /* We've already printed what needs to be printed. */
2911 bs
->print_it
= print_it_done
;
2915 else /* found == 0 */
2917 /* This is a case where some watchpoint(s) triggered,
2918 but not at the address of this watchpoint (FOUND
2919 was left zero). So don't print anything for this
2921 bs
->print_it
= print_it_noop
;
2928 /* By definition, an encountered breakpoint is a triggered
2932 real_breakpoint
= 1;
2935 if (frame_id_p (b
->frame_id
)
2936 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2940 int value_is_zero
= 0;
2944 /* Need to select the frame, with all that implies
2945 so that the conditions will have the right context. */
2946 select_frame (get_current_frame ());
2948 = catch_errors (breakpoint_cond_eval
, (b
->cond
),
2949 "Error in testing breakpoint condition:\n",
2951 /* FIXME-someday, should give breakpoint # */
2954 if (b
->cond
&& value_is_zero
)
2957 /* Don't consider this a hit. */
2960 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2963 /* Don't consider this a hit. */
2966 else if (b
->ignore_count
> 0)
2969 annotate_ignore_count_change ();
2974 /* We will stop here */
2975 if (b
->disposition
== disp_disable
)
2976 b
->enable_state
= bp_disabled
;
2979 bs
->commands
= b
->commands
;
2981 (strcmp ("silent", bs
->commands
->line
) == 0
2982 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
2984 bs
->commands
= bs
->commands
->next
;
2987 bs
->commands
= copy_command_lines (bs
->commands
);
2990 /* Print nothing for this entry if we dont stop or if we dont print. */
2991 if (bs
->stop
== 0 || bs
->print
== 0)
2992 bs
->print_it
= print_it_noop
;
2995 bs
->next
= NULL
; /* Terminate the chain */
2996 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2998 /* The value of a hardware watchpoint hasn't changed, but the
2999 intermediate memory locations we are watching may have. */
3000 if (bs
&& !bs
->stop
&&
3001 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
3002 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
3003 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
3005 remove_breakpoints ();
3006 insert_breakpoints ();
3011 /* Tell what to do about this bpstat. */
3013 bpstat_what (bpstat bs
)
3015 /* Classify each bpstat as one of the following. */
3018 /* This bpstat element has no effect on the main_action. */
3021 /* There was a watchpoint, stop but don't print. */
3024 /* There was a watchpoint, stop and print. */
3027 /* There was a breakpoint but we're not stopping. */
3030 /* There was a breakpoint, stop but don't print. */
3033 /* There was a breakpoint, stop and print. */
3036 /* We hit the longjmp breakpoint. */
3039 /* We hit the longjmp_resume breakpoint. */
3042 /* We hit the step_resume breakpoint. */
3045 /* We hit the shared library event breakpoint. */
3048 /* We caught a shared library event. */
3051 /* This is just used to count how many enums there are. */
3055 /* Here is the table which drives this routine. So that we can
3056 format it pretty, we define some abbreviations for the
3057 enum bpstat_what codes. */
3058 #define kc BPSTAT_WHAT_KEEP_CHECKING
3059 #define ss BPSTAT_WHAT_STOP_SILENT
3060 #define sn BPSTAT_WHAT_STOP_NOISY
3061 #define sgl BPSTAT_WHAT_SINGLE
3062 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3063 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3064 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
3065 #define sr BPSTAT_WHAT_STEP_RESUME
3066 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3067 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3069 /* "Can't happen." Might want to print an error message.
3070 abort() is not out of the question, but chances are GDB is just
3071 a bit confused, not unusable. */
3072 #define err BPSTAT_WHAT_STOP_NOISY
3074 /* Given an old action and a class, come up with a new action. */
3075 /* One interesting property of this table is that wp_silent is the same
3076 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3077 after stopping, the check for whether to step over a breakpoint
3078 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3079 reference to how we stopped. We retain separate wp_silent and
3080 bp_silent codes in case we want to change that someday.
3082 Another possibly interesting property of this table is that
3083 there's a partial ordering, priority-like, of the actions. Once
3084 you've decided that some action is appropriate, you'll never go
3085 back and decide something of a lower priority is better. The
3088 kc < clr sgl shl shlr slr sn sr ss
3089 sgl < clrs shl shlr slr sn sr ss
3090 slr < err shl shlr sn sr ss
3091 clr < clrs err shl shlr sn sr ss
3092 clrs < err shl shlr sn sr ss
3099 What I think this means is that we don't need a damned table
3100 here. If you just put the rows and columns in the right order,
3101 it'd look awfully regular. We could simply walk the bpstat list
3102 and choose the highest priority action we find, with a little
3103 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3104 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3105 is messy anyway). */
3107 /* step_resume entries: a step resume breakpoint overrides another
3108 breakpoint of signal handling (see comment in wait_for_inferior
3109 at where we set the step_resume breakpoint). */
3111 static const enum bpstat_what_main_action
3112 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3115 /* kc ss sn sgl slr clr clrs sr shl shlr
3118 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, shl
, shlr
},
3120 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3122 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3124 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, shl
, shlr
},
3126 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3128 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3130 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, shl
, shlr
},
3132 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, shl
, shlr
},
3134 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3136 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3138 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3153 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3154 struct bpstat_what retval
;
3156 retval
.call_dummy
= 0;
3157 for (; bs
!= NULL
; bs
= bs
->next
)
3159 enum class bs_class
= no_effect
;
3160 if (bs
->breakpoint_at
== NULL
)
3161 /* I suspect this can happen if it was a momentary breakpoint
3162 which has since been deleted. */
3164 switch (bs
->breakpoint_at
->type
)
3170 case bp_hardware_breakpoint
:
3176 bs_class
= bp_noisy
;
3178 bs_class
= bp_silent
;
3181 bs_class
= bp_nostop
;
3184 case bp_hardware_watchpoint
:
3185 case bp_read_watchpoint
:
3186 case bp_access_watchpoint
:
3190 bs_class
= wp_noisy
;
3192 bs_class
= wp_silent
;
3195 /* There was a watchpoint, but we're not stopping.
3196 This requires no further action. */
3197 bs_class
= no_effect
;
3200 bs_class
= long_jump
;
3202 case bp_longjmp_resume
:
3203 bs_class
= long_resume
;
3205 case bp_step_resume
:
3208 bs_class
= step_resume
;
3211 /* It is for the wrong frame. */
3212 bs_class
= bp_nostop
;
3214 case bp_watchpoint_scope
:
3215 bs_class
= bp_nostop
;
3217 case bp_shlib_event
:
3218 bs_class
= shlib_event
;
3220 case bp_thread_event
:
3221 case bp_overlay_event
:
3222 bs_class
= bp_nostop
;
3225 case bp_catch_unload
:
3226 /* Only if this catchpoint triggered should we cause the
3227 step-out-of-dld behaviour. Otherwise, we ignore this
3230 bs_class
= catch_shlib_event
;
3232 bs_class
= no_effect
;
3235 case bp_catch_vfork
:
3240 bs_class
= bp_noisy
;
3242 bs_class
= bp_silent
;
3245 /* There was a catchpoint, but we're not stopping.
3246 This requires no further action. */
3247 bs_class
= no_effect
;
3249 case bp_catch_catch
:
3250 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
3251 bs_class
= bp_nostop
;
3253 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3255 case bp_catch_throw
:
3256 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3257 bs_class
= bp_nostop
;
3259 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3262 /* Make sure the action is stop (silent or noisy),
3263 so infrun.c pops the dummy frame. */
3264 bs_class
= bp_silent
;
3265 retval
.call_dummy
= 1;
3268 current_action
= table
[(int) bs_class
][(int) current_action
];
3270 retval
.main_action
= current_action
;
3274 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3275 without hardware support). This isn't related to a specific bpstat,
3276 just to things like whether watchpoints are set. */
3279 bpstat_should_step (void)
3281 struct breakpoint
*b
;
3283 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3288 /* Nonzero if there are enabled hardware watchpoints. */
3290 bpstat_have_active_hw_watchpoints (void)
3292 struct bp_location
*bpt
;
3293 ALL_BP_LOCATIONS (bpt
)
3294 if (breakpoint_enabled (bpt
->owner
)
3296 && bpt
->loc_type
== bp_loc_hardware_watchpoint
)
3302 /* Given a bpstat that records zero or more triggered eventpoints, this
3303 function returns another bpstat which contains only the catchpoints
3304 on that first list, if any. */
3306 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3308 struct bpstats root_bs
[1];
3309 bpstat bs
= root_bs
;
3310 struct breakpoint
*ep
;
3313 bpstat_clear (cp_list
);
3314 root_bs
->next
= NULL
;
3316 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3318 /* Is this eventpoint a catchpoint? If not, ignore it. */
3319 ep
= ep_list
->breakpoint_at
;
3322 if ((ep
->type
!= bp_catch_load
) &&
3323 (ep
->type
!= bp_catch_unload
) &&
3324 (ep
->type
!= bp_catch_catch
) &&
3325 (ep
->type
!= bp_catch_throw
))
3326 /* pai: (temp) ADD fork/vfork here!! */
3329 /* Yes; add it to the list. */
3330 bs
= bpstat_alloc (ep
, bs
);
3335 #if defined(SOLIB_ADD)
3336 /* Also, for each triggered catchpoint, tag it with the name of
3337 the library that caused this trigger. (We copy the name now,
3338 because it's only guaranteed to be available NOW, when the
3339 catchpoint triggers. Clients who may wish to know the name
3340 later must get it from the catchpoint itself.) */
3341 if (ep
->triggered_dll_pathname
!= NULL
)
3342 xfree (ep
->triggered_dll_pathname
);
3343 if (ep
->type
== bp_catch_load
)
3344 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3345 PIDGET (inferior_ptid
));
3347 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3348 PIDGET (inferior_ptid
));
3350 dll_pathname
= NULL
;
3354 ep
->triggered_dll_pathname
= (char *)
3355 xmalloc (strlen (dll_pathname
) + 1);
3356 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3359 ep
->triggered_dll_pathname
= NULL
;
3365 /* Print B to gdb_stdout. */
3367 print_one_breakpoint (struct breakpoint
*b
,
3368 CORE_ADDR
*last_addr
)
3370 struct command_line
*l
;
3372 struct ep_type_description
3377 static struct ep_type_description bptypes
[] =
3379 {bp_none
, "?deleted?"},
3380 {bp_breakpoint
, "breakpoint"},
3381 {bp_hardware_breakpoint
, "hw breakpoint"},
3382 {bp_until
, "until"},
3383 {bp_finish
, "finish"},
3384 {bp_watchpoint
, "watchpoint"},
3385 {bp_hardware_watchpoint
, "hw watchpoint"},
3386 {bp_read_watchpoint
, "read watchpoint"},
3387 {bp_access_watchpoint
, "acc watchpoint"},
3388 {bp_longjmp
, "longjmp"},
3389 {bp_longjmp_resume
, "longjmp resume"},
3390 {bp_step_resume
, "step resume"},
3391 {bp_watchpoint_scope
, "watchpoint scope"},
3392 {bp_call_dummy
, "call dummy"},
3393 {bp_shlib_event
, "shlib events"},
3394 {bp_thread_event
, "thread events"},
3395 {bp_overlay_event
, "overlay events"},
3396 {bp_catch_load
, "catch load"},
3397 {bp_catch_unload
, "catch unload"},
3398 {bp_catch_fork
, "catch fork"},
3399 {bp_catch_vfork
, "catch vfork"},
3400 {bp_catch_exec
, "catch exec"},
3401 {bp_catch_catch
, "catch catch"},
3402 {bp_catch_throw
, "catch throw"}
3405 static char *bpdisps
[] =
3406 {"del", "dstp", "dis", "keep"};
3407 static char bpenables
[] = "nynny";
3408 char wrap_indent
[80];
3409 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3410 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3411 struct cleanup
*bkpt_chain
;
3414 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3418 ui_out_field_int (uiout
, "number", b
->number
);
3422 if (((int) b
->type
> (sizeof (bptypes
) / sizeof (bptypes
[0])))
3423 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3424 internal_error (__FILE__
, __LINE__
,
3425 _("bptypes table does not describe type #%d."),
3427 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3431 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3435 ui_out_field_fmt (uiout
, "enabled", "%c", bpenables
[(int) b
->enable_state
]);
3436 ui_out_spaces (uiout
, 2);
3439 strcpy (wrap_indent
, " ");
3442 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3443 strcat (wrap_indent
, " ");
3445 strcat (wrap_indent
, " ");
3448 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3449 b
->ops
->print_one (b
, last_addr
);
3454 internal_error (__FILE__
, __LINE__
,
3455 _("print_one_breakpoint: bp_none encountered\n"));
3459 case bp_hardware_watchpoint
:
3460 case bp_read_watchpoint
:
3461 case bp_access_watchpoint
:
3462 /* Field 4, the address, is omitted (which makes the columns
3463 not line up too nicely with the headers, but the effect
3464 is relatively readable). */
3466 ui_out_field_skip (uiout
, "addr");
3468 print_expression (b
->exp
, stb
->stream
);
3469 ui_out_field_stream (uiout
, "what", stb
);
3473 case bp_catch_unload
:
3474 /* Field 4, the address, is omitted (which makes the columns
3475 not line up too nicely with the headers, but the effect
3476 is relatively readable). */
3478 ui_out_field_skip (uiout
, "addr");
3480 if (b
->dll_pathname
== NULL
)
3482 ui_out_field_string (uiout
, "what", "<any library>");
3483 ui_out_spaces (uiout
, 1);
3487 ui_out_text (uiout
, "library \"");
3488 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3489 ui_out_text (uiout
, "\" ");
3494 case bp_catch_vfork
:
3495 /* Field 4, the address, is omitted (which makes the columns
3496 not line up too nicely with the headers, but the effect
3497 is relatively readable). */
3499 ui_out_field_skip (uiout
, "addr");
3501 if (b
->forked_inferior_pid
!= 0)
3503 ui_out_text (uiout
, "process ");
3504 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3505 ui_out_spaces (uiout
, 1);
3510 /* Field 4, the address, is omitted (which makes the columns
3511 not line up too nicely with the headers, but the effect
3512 is relatively readable). */
3514 ui_out_field_skip (uiout
, "addr");
3516 if (b
->exec_pathname
!= NULL
)
3518 ui_out_text (uiout
, "program \"");
3519 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3520 ui_out_text (uiout
, "\" ");
3524 case bp_catch_catch
:
3525 /* Field 4, the address, is omitted (which makes the columns
3526 not line up too nicely with the headers, but the effect
3527 is relatively readable). */
3529 ui_out_field_skip (uiout
, "addr");
3531 ui_out_field_string (uiout
, "what", "exception catch");
3532 ui_out_spaces (uiout
, 1);
3535 case bp_catch_throw
:
3536 /* Field 4, the address, is omitted (which makes the columns
3537 not line up too nicely with the headers, but the effect
3538 is relatively readable). */
3540 ui_out_field_skip (uiout
, "addr");
3542 ui_out_field_string (uiout
, "what", "exception throw");
3543 ui_out_spaces (uiout
, 1);
3547 case bp_hardware_breakpoint
:
3551 case bp_longjmp_resume
:
3552 case bp_step_resume
:
3553 case bp_watchpoint_scope
:
3555 case bp_shlib_event
:
3556 case bp_thread_event
:
3557 case bp_overlay_event
:
3562 ui_out_field_string (uiout
, "addr", "<PENDING>");
3564 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
3567 *last_addr
= b
->loc
->address
;
3570 sym
= find_pc_sect_function (b
->loc
->address
, b
->loc
->section
);
3573 ui_out_text (uiout
, "in ");
3574 ui_out_field_string (uiout
, "func",
3575 SYMBOL_PRINT_NAME (sym
));
3576 ui_out_wrap_hint (uiout
, wrap_indent
);
3577 ui_out_text (uiout
, " at ");
3579 ui_out_field_string (uiout
, "file", b
->source_file
);
3580 ui_out_text (uiout
, ":");
3582 if (ui_out_is_mi_like_p (uiout
))
3584 struct symtab_and_line sal
= find_pc_line (b
->loc
->address
, 0);
3585 char *fullname
= symtab_to_fullname (sal
.symtab
);
3588 ui_out_field_string (uiout
, "fullname", fullname
);
3591 ui_out_field_int (uiout
, "line", b
->line_number
);
3593 else if (b
->pending
)
3595 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3599 print_address_symbolic (b
->loc
->address
, stb
->stream
, demangle
, "");
3600 ui_out_field_stream (uiout
, "at", stb
);
3605 if (b
->thread
!= -1)
3607 /* FIXME: This seems to be redundant and lost here; see the
3608 "stop only in" line a little further down. */
3609 ui_out_text (uiout
, " thread ");
3610 ui_out_field_int (uiout
, "thread", b
->thread
);
3613 ui_out_text (uiout
, "\n");
3615 if (frame_id_p (b
->frame_id
))
3618 ui_out_text (uiout
, "\tstop only in stack frame at ");
3619 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3621 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3622 ui_out_text (uiout
, "\n");
3625 if (b
->cond
&& !ada_exception_catchpoint_p (b
))
3627 /* We do not print the condition for Ada exception catchpoints
3628 because the condition is an internal implementation detail
3629 that we do not want to expose to the user. */
3631 ui_out_text (uiout
, "\tstop only if ");
3632 print_expression (b
->cond
, stb
->stream
);
3633 ui_out_field_stream (uiout
, "cond", stb
);
3634 ui_out_text (uiout
, "\n");
3637 if (b
->pending
&& b
->cond_string
)
3640 ui_out_text (uiout
, "\tstop only if ");
3641 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3642 ui_out_text (uiout
, "\n");
3645 if (b
->thread
!= -1)
3647 /* FIXME should make an annotation for this */
3648 ui_out_text (uiout
, "\tstop only in thread ");
3649 ui_out_field_int (uiout
, "thread", b
->thread
);
3650 ui_out_text (uiout
, "\n");
3653 if (show_breakpoint_hit_counts
&& b
->hit_count
)
3655 /* FIXME should make an annotation for this */
3656 if (ep_is_catchpoint (b
))
3657 ui_out_text (uiout
, "\tcatchpoint");
3659 ui_out_text (uiout
, "\tbreakpoint");
3660 ui_out_text (uiout
, " already hit ");
3661 ui_out_field_int (uiout
, "times", b
->hit_count
);
3662 if (b
->hit_count
== 1)
3663 ui_out_text (uiout
, " time\n");
3665 ui_out_text (uiout
, " times\n");
3668 /* Output the count also if it is zero, but only if this is
3669 mi. FIXME: Should have a better test for this. */
3670 if (ui_out_is_mi_like_p (uiout
))
3671 if (show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3672 ui_out_field_int (uiout
, "times", b
->hit_count
);
3674 if (b
->ignore_count
)
3677 ui_out_text (uiout
, "\tignore next ");
3678 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3679 ui_out_text (uiout
, " hits\n");
3682 if ((l
= b
->commands
))
3684 struct cleanup
*script_chain
;
3687 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3688 print_command_lines (uiout
, l
, 4);
3689 do_cleanups (script_chain
);
3691 do_cleanups (bkpt_chain
);
3692 do_cleanups (old_chain
);
3695 struct captured_breakpoint_query_args
3701 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3703 struct captured_breakpoint_query_args
*args
= data
;
3704 struct breakpoint
*b
;
3705 CORE_ADDR dummy_addr
= 0;
3708 if (args
->bnum
== b
->number
)
3710 print_one_breakpoint (b
, &dummy_addr
);
3718 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3720 struct captured_breakpoint_query_args args
;
3722 /* For the moment we don't trust print_one_breakpoint() to not throw
3724 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3725 error_message
, RETURN_MASK_ALL
) < 0)
3731 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3732 catchpoints, et.al.). */
3735 user_settable_breakpoint (const struct breakpoint
*b
)
3737 return (b
->type
== bp_breakpoint
3738 || b
->type
== bp_catch_load
3739 || b
->type
== bp_catch_unload
3740 || b
->type
== bp_catch_fork
3741 || b
->type
== bp_catch_vfork
3742 || b
->type
== bp_catch_exec
3743 || b
->type
== bp_catch_catch
3744 || b
->type
== bp_catch_throw
3745 || b
->type
== bp_hardware_breakpoint
3746 || b
->type
== bp_watchpoint
3747 || b
->type
== bp_read_watchpoint
3748 || b
->type
== bp_access_watchpoint
3749 || b
->type
== bp_hardware_watchpoint
);
3752 /* Print information on user settable breakpoint (watchpoint, etc)
3753 number BNUM. If BNUM is -1 print all user settable breakpoints.
3754 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3757 breakpoint_1 (int bnum
, int allflag
)
3759 struct breakpoint
*b
;
3760 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3761 int nr_printable_breakpoints
;
3762 struct cleanup
*bkpttbl_chain
;
3764 /* Compute the number of rows in the table. */
3765 nr_printable_breakpoints
= 0;
3768 || bnum
== b
->number
)
3770 if (allflag
|| user_settable_breakpoint (b
))
3771 nr_printable_breakpoints
++;
3776 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3780 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3783 if (nr_printable_breakpoints
> 0)
3784 annotate_breakpoints_headers ();
3785 if (nr_printable_breakpoints
> 0)
3787 ui_out_table_header (uiout
, 3, ui_left
, "number", "Num"); /* 1 */
3788 if (nr_printable_breakpoints
> 0)
3790 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3791 if (nr_printable_breakpoints
> 0)
3793 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3794 if (nr_printable_breakpoints
> 0)
3796 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3799 if (nr_printable_breakpoints
> 0)
3801 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3802 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3804 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3806 if (nr_printable_breakpoints
> 0)
3808 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3809 ui_out_table_body (uiout
);
3810 if (nr_printable_breakpoints
> 0)
3811 annotate_breakpoints_table ();
3815 || bnum
== b
->number
)
3817 /* We only print out user settable breakpoints unless the
3819 if (allflag
|| user_settable_breakpoint (b
))
3820 print_one_breakpoint (b
, &last_addr
);
3823 do_cleanups (bkpttbl_chain
);
3825 if (nr_printable_breakpoints
== 0)
3828 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3830 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3835 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3836 that a comparison of an unsigned with -1 is always false. */
3837 if (last_addr
!= (CORE_ADDR
) -1)
3838 set_next_address (last_addr
);
3841 /* FIXME? Should this be moved up so that it is only called when
3842 there have been breakpoints? */
3843 annotate_breakpoints_table_end ();
3847 breakpoints_info (char *bnum_exp
, int from_tty
)
3852 bnum
= parse_and_eval_long (bnum_exp
);
3854 breakpoint_1 (bnum
, 0);
3858 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3863 bnum
= parse_and_eval_long (bnum_exp
);
3865 breakpoint_1 (bnum
, 1);
3868 /* Print a message describing any breakpoints set at PC. */
3871 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
3874 struct breakpoint
*b
;
3877 if (b
->loc
->address
== pc
) /* address match / overlay match */
3878 if (!b
->pending
&& (!overlay_debugging
|| b
->loc
->section
== section
))
3883 printf_filtered (_("Note: breakpoint "));
3884 else /* if (others == ???) */
3885 printf_filtered (_("Note: breakpoints "));
3887 if (b
->loc
->address
== pc
) /* address match / overlay match */
3888 if (!b
->pending
&& (!overlay_debugging
|| b
->loc
->section
== section
))
3891 printf_filtered ("%d", b
->number
);
3892 if (b
->thread
== -1 && thread
!= -1)
3893 printf_filtered (" (all threads)");
3894 else if (b
->thread
!= -1)
3895 printf_filtered (" (thread %d)", b
->thread
);
3896 printf_filtered ("%s%s ",
3897 ((b
->enable_state
== bp_disabled
||
3898 b
->enable_state
== bp_shlib_disabled
||
3899 b
->enable_state
== bp_call_disabled
)
3901 : b
->enable_state
== bp_permanent
3905 : ((others
== 1) ? " and" : ""));
3907 printf_filtered (_("also set at pc "));
3908 deprecated_print_address_numeric (pc
, 1, gdb_stdout
);
3909 printf_filtered (".\n");
3913 /* Set the default place to put a breakpoint
3914 for the `break' command with no arguments. */
3917 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3920 default_breakpoint_valid
= valid
;
3921 default_breakpoint_address
= addr
;
3922 default_breakpoint_symtab
= symtab
;
3923 default_breakpoint_line
= line
;
3926 /* Return true iff it is meaningful to use the address member of
3927 BPT. For some breakpoint types, the address member is irrelevant
3928 and it makes no sense to attempt to compare it to other addresses
3929 (or use it for any other purpose either).
3931 More specifically, each of the following breakpoint types will always
3932 have a zero valued address and we don't want check_duplicates() to mark
3933 breakpoints of any of these types to be a duplicate of an actual
3934 breakpoint at address zero:
3937 bp_hardware_watchpoint
3939 bp_access_watchpoint
3946 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3948 enum bptype type
= bpt
->type
;
3950 return (type
!= bp_watchpoint
3951 && type
!= bp_hardware_watchpoint
3952 && type
!= bp_read_watchpoint
3953 && type
!= bp_access_watchpoint
3954 && type
!= bp_catch_exec
3955 && type
!= bp_longjmp_resume
3956 && type
!= bp_catch_fork
3957 && type
!= bp_catch_vfork
);
3960 /* Rescan breakpoints at the same address and section as BPT,
3961 marking the first one as "first" and any others as "duplicates".
3962 This is so that the bpt instruction is only inserted once.
3963 If we have a permanent breakpoint at the same place as BPT, make
3964 that one the official one, and the rest as duplicates. */
3967 check_duplicates (struct breakpoint
*bpt
)
3969 struct bp_location
*b
;
3971 struct bp_location
*perm_bp
= 0;
3972 CORE_ADDR address
= bpt
->loc
->address
;
3973 asection
*section
= bpt
->loc
->section
;
3975 if (! breakpoint_address_is_meaningful (bpt
))
3978 ALL_BP_LOCATIONS (b
)
3979 if (b
->owner
->enable_state
!= bp_disabled
3980 && b
->owner
->enable_state
!= bp_shlib_disabled
3981 && !b
->owner
->pending
3982 && b
->owner
->enable_state
!= bp_call_disabled
3983 && b
->address
== address
/* address / overlay match */
3984 && (!overlay_debugging
|| b
->section
== section
)
3985 && breakpoint_address_is_meaningful (b
->owner
))
3987 /* Have we found a permanent breakpoint? */
3988 if (b
->owner
->enable_state
== bp_permanent
)
3995 b
->duplicate
= count
> 1;
3998 /* If we found a permanent breakpoint at this address, go over the
3999 list again and declare all the other breakpoints there to be the
4003 perm_bp
->duplicate
= 0;
4005 /* Permanent breakpoint should always be inserted. */
4006 if (! perm_bp
->inserted
)
4007 internal_error (__FILE__
, __LINE__
,
4008 _("allegedly permanent breakpoint is not "
4009 "actually inserted"));
4011 ALL_BP_LOCATIONS (b
)
4014 if (b
->owner
->enable_state
!= bp_disabled
4015 && b
->owner
->enable_state
!= bp_shlib_disabled
4016 && !b
->owner
->pending
4017 && b
->owner
->enable_state
!= bp_call_disabled
4018 && b
->address
== address
/* address / overlay match */
4019 && (!overlay_debugging
|| b
->section
== section
)
4020 && breakpoint_address_is_meaningful (b
->owner
))
4023 internal_error (__FILE__
, __LINE__
,
4024 _("another breakpoint was inserted on top of "
4025 "a permanent breakpoint"));
4034 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4035 int bnum
, int have_bnum
)
4040 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4041 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4043 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4044 bnum
, astr1
, astr2
);
4046 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4049 /* Adjust a breakpoint's address to account for architectural constraints
4050 on breakpoint placement. Return the adjusted address. Note: Very
4051 few targets require this kind of adjustment. For most targets,
4052 this function is simply the identity function. */
4055 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4057 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4059 /* Very few targets need any kind of breakpoint adjustment. */
4062 else if (bptype
== bp_watchpoint
4063 || bptype
== bp_hardware_watchpoint
4064 || bptype
== bp_read_watchpoint
4065 || bptype
== bp_access_watchpoint
4066 || bptype
== bp_catch_fork
4067 || bptype
== bp_catch_vfork
4068 || bptype
== bp_catch_exec
)
4070 /* Watchpoints and the various bp_catch_* eventpoints should not
4071 have their addresses modified. */
4076 CORE_ADDR adjusted_bpaddr
;
4078 /* Some targets have architectural constraints on the placement
4079 of breakpoint instructions. Obtain the adjusted address. */
4080 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4083 /* An adjusted breakpoint address can significantly alter
4084 a user's expectations. Print a warning if an adjustment
4086 if (adjusted_bpaddr
!= bpaddr
)
4087 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4089 return adjusted_bpaddr
;
4093 /* Allocate a struct bp_location. */
4095 static struct bp_location
*
4096 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4098 struct bp_location
*loc
, *loc_p
;
4100 loc
= xmalloc (sizeof (struct bp_location
));
4101 memset (loc
, 0, sizeof (*loc
));
4111 case bp_longjmp_resume
:
4112 case bp_step_resume
:
4113 case bp_watchpoint_scope
:
4115 case bp_shlib_event
:
4116 case bp_thread_event
:
4117 case bp_overlay_event
:
4119 case bp_catch_unload
:
4120 loc
->loc_type
= bp_loc_software_breakpoint
;
4122 case bp_hardware_breakpoint
:
4123 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4125 case bp_hardware_watchpoint
:
4126 case bp_read_watchpoint
:
4127 case bp_access_watchpoint
:
4128 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4132 case bp_catch_vfork
:
4134 case bp_catch_catch
:
4135 case bp_catch_throw
:
4136 loc
->loc_type
= bp_loc_other
;
4139 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4142 /* Add this breakpoint to the end of the chain. */
4144 loc_p
= bp_location_chain
;
4146 bp_location_chain
= loc
;
4150 loc_p
= loc_p
->next
;
4157 /* set_raw_breakpoint() is a low level routine for allocating and
4158 partially initializing a breakpoint of type BPTYPE. The newly
4159 created breakpoint's address, section, source file name, and line
4160 number are provided by SAL. The newly created and partially
4161 initialized breakpoint is added to the breakpoint chain and
4162 is also returned as the value of this function.
4164 It is expected that the caller will complete the initialization of
4165 the newly created breakpoint struct as well as output any status
4166 information regarding the creation of a new breakpoint. In
4167 particular, set_raw_breakpoint() does NOT set the breakpoint
4168 number! Care should be taken to not allow an error() to occur
4169 prior to completing the initialization of the breakpoint. If this
4170 should happen, a bogus breakpoint will be left on the chain. */
4173 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4175 struct breakpoint
*b
, *b1
;
4176 CORE_ADDR adjusted_address
;
4178 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4179 memset (b
, 0, sizeof (*b
));
4181 /* Adjust the breakpoint's address prior to allocating a location.
4182 Once we call allocate_bp_location(), that mostly uninitialized
4183 location will be placed on the location chain. Adjustment of the
4184 breakpoint may cause read_memory_nobpt() to be called and we do
4185 not want its scan of the location chain to find a breakpoint and
4186 location that's only been partially initialized. */
4187 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4189 b
->loc
= allocate_bp_location (b
, bptype
);
4190 b
->loc
->requested_address
= sal
.pc
;
4191 b
->loc
->address
= adjusted_address
;
4193 if (sal
.symtab
== NULL
)
4194 b
->source_file
= NULL
;
4196 b
->source_file
= savestring (sal
.symtab
->filename
,
4197 strlen (sal
.symtab
->filename
));
4198 b
->loc
->section
= sal
.section
;
4200 b
->language
= current_language
->la_language
;
4201 b
->input_radix
= input_radix
;
4203 b
->line_number
= sal
.line
;
4204 b
->enable_state
= bp_enabled
;
4207 b
->ignore_count
= 0;
4209 b
->frame_id
= null_frame_id
;
4210 b
->dll_pathname
= NULL
;
4211 b
->triggered_dll_pathname
= NULL
;
4212 b
->forked_inferior_pid
= 0;
4213 b
->exec_pathname
= NULL
;
4217 /* Add this breakpoint to the end of the chain
4218 so that a list of breakpoints will come out in order
4219 of increasing numbers. */
4221 b1
= breakpoint_chain
;
4223 breakpoint_chain
= b
;
4231 check_duplicates (b
);
4232 breakpoints_changed ();
4238 /* Note that the breakpoint object B describes a permanent breakpoint
4239 instruction, hard-wired into the inferior's code. */
4241 make_breakpoint_permanent (struct breakpoint
*b
)
4243 b
->enable_state
= bp_permanent
;
4245 /* By definition, permanent breakpoints are already present in the code. */
4246 b
->loc
->inserted
= 1;
4249 static struct breakpoint
*
4250 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4252 static int internal_breakpoint_number
= -1;
4253 struct symtab_and_line sal
;
4254 struct breakpoint
*b
;
4256 init_sal (&sal
); /* initialize to zeroes */
4259 sal
.section
= find_pc_overlay (sal
.pc
);
4261 b
= set_raw_breakpoint (sal
, type
);
4262 b
->number
= internal_breakpoint_number
--;
4263 b
->disposition
= disp_donttouch
;
4270 create_longjmp_breakpoint (char *func_name
)
4272 struct breakpoint
*b
;
4273 struct minimal_symbol
*m
;
4275 if (func_name
== NULL
)
4276 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4279 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4282 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4285 b
->enable_state
= bp_disabled
;
4288 b
->addr_string
= xstrdup (func_name
);
4291 /* Call this routine when stepping and nexting to enable a breakpoint
4292 if we do a longjmp(). When we hit that breakpoint, call
4293 set_longjmp_resume_breakpoint() to figure out where we are going. */
4296 enable_longjmp_breakpoint (void)
4298 struct breakpoint
*b
;
4301 if (b
->type
== bp_longjmp
)
4303 b
->enable_state
= bp_enabled
;
4304 check_duplicates (b
);
4309 disable_longjmp_breakpoint (void)
4311 struct breakpoint
*b
;
4314 if (b
->type
== bp_longjmp
4315 || b
->type
== bp_longjmp_resume
)
4317 b
->enable_state
= bp_disabled
;
4318 check_duplicates (b
);
4323 create_overlay_event_breakpoint (char *func_name
)
4325 struct breakpoint
*b
;
4326 struct minimal_symbol
*m
;
4328 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4331 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4333 b
->addr_string
= xstrdup (func_name
);
4335 if (overlay_debugging
== ovly_auto
)
4337 b
->enable_state
= bp_enabled
;
4338 overlay_events_enabled
= 1;
4342 b
->enable_state
= bp_disabled
;
4343 overlay_events_enabled
= 0;
4348 enable_overlay_breakpoints (void)
4350 struct breakpoint
*b
;
4353 if (b
->type
== bp_overlay_event
)
4355 b
->enable_state
= bp_enabled
;
4356 check_duplicates (b
);
4357 overlay_events_enabled
= 1;
4362 disable_overlay_breakpoints (void)
4364 struct breakpoint
*b
;
4367 if (b
->type
== bp_overlay_event
)
4369 b
->enable_state
= bp_disabled
;
4370 check_duplicates (b
);
4371 overlay_events_enabled
= 0;
4376 create_thread_event_breakpoint (CORE_ADDR address
)
4378 struct breakpoint
*b
;
4380 b
= create_internal_breakpoint (address
, bp_thread_event
);
4382 b
->enable_state
= bp_enabled
;
4383 /* addr_string has to be used or breakpoint_re_set will delete me. */
4384 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4390 remove_thread_event_breakpoints (void)
4392 struct breakpoint
*b
, *temp
;
4394 ALL_BREAKPOINTS_SAFE (b
, temp
)
4395 if (b
->type
== bp_thread_event
)
4396 delete_breakpoint (b
);
4399 struct captured_parse_breakpoint_args
4402 struct symtabs_and_lines
*sals_p
;
4403 char ***addr_string_p
;
4407 struct lang_and_radix
4413 /* Cleanup helper routine to restore the current language and
4416 do_restore_lang_radix_cleanup (void *old
)
4418 struct lang_and_radix
*p
= old
;
4419 set_language (p
->lang
);
4420 input_radix
= p
->radix
;
4423 /* Try and resolve a pending breakpoint. */
4425 resolve_pending_breakpoint (struct breakpoint
*b
)
4427 /* Try and reparse the breakpoint in case the shared library
4429 struct symtabs_and_lines sals
;
4430 struct symtab_and_line pending_sal
;
4431 char **cond_string
= (char **) NULL
;
4432 char *copy_arg
= b
->addr_string
;
4437 struct ui_file
*old_gdb_stderr
;
4438 struct lang_and_radix old_lr
;
4439 struct cleanup
*old_chain
;
4441 /* Set language, input-radix, then reissue breakpoint command.
4442 Ensure the language and input-radix are restored afterwards. */
4443 old_lr
.lang
= current_language
->la_language
;
4444 old_lr
.radix
= input_radix
;
4445 old_chain
= make_cleanup (do_restore_lang_radix_cleanup
, &old_lr
);
4447 set_language (b
->language
);
4448 input_radix
= b
->input_radix
;
4449 rc
= break_command_1 (b
->addr_string
, b
->flag
, b
->from_tty
, b
);
4451 if (rc
== GDB_RC_OK
)
4452 /* Pending breakpoint has been resolved. */
4453 printf_filtered (_("Pending breakpoint \"%s\" resolved\n"), b
->addr_string
);
4455 do_cleanups (old_chain
);
4460 remove_solib_event_breakpoints (void)
4462 struct breakpoint
*b
, *temp
;
4464 ALL_BREAKPOINTS_SAFE (b
, temp
)
4465 if (b
->type
== bp_shlib_event
)
4466 delete_breakpoint (b
);
4470 create_solib_event_breakpoint (CORE_ADDR address
)
4472 struct breakpoint
*b
;
4474 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4478 /* Disable any breakpoints that are on code in shared libraries. Only
4479 apply to enabled breakpoints, disabled ones can just stay disabled. */
4482 disable_breakpoints_in_shlibs (int silent
)
4484 struct breakpoint
*b
;
4485 int disabled_shlib_breaks
= 0;
4487 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4490 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4491 && breakpoint_enabled (b
) && !b
->loc
->duplicate
4493 && PC_SOLIB (b
->loc
->address
)
4495 && solib_address (b
->loc
->address
)
4499 b
->enable_state
= bp_shlib_disabled
;
4502 if (!disabled_shlib_breaks
)
4504 target_terminal_ours_for_output ();
4505 warning (_("Temporarily disabling shared library breakpoints:"));
4507 disabled_shlib_breaks
= 1;
4508 warning (_("breakpoint #%d "), b
->number
);
4514 /* Disable any breakpoints that are in in an unloaded shared library. Only
4515 apply to enabled breakpoints, disabled ones can just stay disabled. */
4518 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4520 struct breakpoint
*b
;
4521 int disabled_shlib_breaks
= 0;
4523 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4526 if ((b
->loc
->loc_type
== bp_loc_hardware_breakpoint
4527 || b
->loc
->loc_type
== bp_loc_software_breakpoint
)
4528 && breakpoint_enabled (b
) && !b
->loc
->duplicate
)
4531 char *so_name
= PC_SOLIB (b
->loc
->address
);
4533 char *so_name
= solib_address (b
->loc
->address
);
4535 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4537 b
->enable_state
= bp_shlib_disabled
;
4538 /* At this point, we cannot rely on remove_breakpoint
4539 succeeding so we must mark the breakpoint as not inserted
4540 to prevent future errors occurring in remove_breakpoints. */
4541 b
->loc
->inserted
= 0;
4542 if (!disabled_shlib_breaks
)
4544 target_terminal_ours_for_output ();
4545 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4548 disabled_shlib_breaks
= 1;
4554 /* Try to reenable any breakpoints in shared libraries. */
4556 re_enable_breakpoints_in_shlibs (void)
4558 struct breakpoint
*b
, *tmp
;
4560 ALL_BREAKPOINTS_SAFE (b
, tmp
)
4562 if (b
->enable_state
== bp_shlib_disabled
)
4567 /* Do not reenable the breakpoint if the shared library is
4568 still not mapped in. */
4570 lib
= PC_SOLIB (b
->loc
->address
);
4572 lib
= solib_address (b
->loc
->address
);
4574 if (lib
!= NULL
&& target_read_memory (b
->loc
->address
, buf
, 1) == 0)
4575 b
->enable_state
= bp_enabled
;
4577 else if (b
->pending
&& (b
->enable_state
== bp_enabled
))
4579 if (resolve_pending_breakpoint (b
) == GDB_RC_OK
)
4580 delete_breakpoint (b
);
4586 solib_load_unload_1 (char *hookname
, int tempflag
, char *dll_pathname
,
4587 char *cond_string
, enum bptype bp_kind
)
4589 struct breakpoint
*b
;
4590 struct symtabs_and_lines sals
;
4591 struct cleanup
*old_chain
;
4592 struct cleanup
*canonical_strings_chain
= NULL
;
4593 char *addr_start
= hookname
;
4594 char *addr_end
= NULL
;
4595 char **canonical
= (char **) NULL
;
4596 int thread
= -1; /* All threads. */
4598 /* Set a breakpoint on the specified hook. */
4599 sals
= decode_line_1 (&hookname
, 1, (struct symtab
*) NULL
,
4600 0, &canonical
, NULL
);
4601 addr_end
= hookname
;
4603 if (sals
.nelts
== 0)
4605 warning (_("Unable to set a breakpoint on dynamic linker callback.\n"
4606 "Suggest linking with /opt/langtools/lib/end.o.\n"
4607 "GDB will be unable to track shl_load/shl_unload calls."));
4610 if (sals
.nelts
!= 1)
4612 warning (_("Unable to set unique breakpoint on dynamic linker callback.\n"
4613 "GDB will be unable to track shl_load/shl_unload calls."));
4617 /* Make sure that all storage allocated in decode_line_1 gets freed
4618 in case the following errors out. */
4619 old_chain
= make_cleanup (xfree
, sals
.sals
);
4620 if (canonical
!= (char **) NULL
)
4622 make_cleanup (xfree
, canonical
);
4623 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
4624 if (canonical
[0] != NULL
)
4625 make_cleanup (xfree
, canonical
[0]);
4628 resolve_sal_pc (&sals
.sals
[0]);
4630 /* Remove the canonical strings from the cleanup, they are needed below. */
4631 if (canonical
!= (char **) NULL
)
4632 discard_cleanups (canonical_strings_chain
);
4634 b
= set_raw_breakpoint (sals
.sals
[0], bp_kind
);
4635 set_breakpoint_count (breakpoint_count
+ 1);
4636 b
->number
= breakpoint_count
;
4638 b
->cond_string
= (cond_string
== NULL
) ?
4639 NULL
: savestring (cond_string
, strlen (cond_string
));
4642 if (canonical
!= (char **) NULL
&& canonical
[0] != NULL
)
4643 b
->addr_string
= canonical
[0];
4644 else if (addr_start
)
4645 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
4647 b
->enable_state
= bp_enabled
;
4648 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4650 if (dll_pathname
== NULL
)
4651 b
->dll_pathname
= NULL
;
4654 b
->dll_pathname
= (char *) xmalloc (strlen (dll_pathname
) + 1);
4655 strcpy (b
->dll_pathname
, dll_pathname
);
4659 do_cleanups (old_chain
);
4663 create_solib_load_event_breakpoint (char *hookname
, int tempflag
,
4664 char *dll_pathname
, char *cond_string
)
4666 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4667 cond_string
, bp_catch_load
);
4671 create_solib_unload_event_breakpoint (char *hookname
, int tempflag
,
4672 char *dll_pathname
, char *cond_string
)
4674 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4675 cond_string
, bp_catch_unload
);
4679 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4680 enum bptype bp_kind
)
4682 struct symtab_and_line sal
;
4683 struct breakpoint
*b
;
4684 int thread
= -1; /* All threads. */
4691 b
= set_raw_breakpoint (sal
, bp_kind
);
4692 set_breakpoint_count (breakpoint_count
+ 1);
4693 b
->number
= breakpoint_count
;
4695 b
->cond_string
= (cond_string
== NULL
) ?
4696 NULL
: savestring (cond_string
, strlen (cond_string
));
4698 b
->addr_string
= NULL
;
4699 b
->enable_state
= bp_enabled
;
4700 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4701 b
->forked_inferior_pid
= 0;
4707 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4709 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4713 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4715 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4719 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4721 struct symtab_and_line sal
;
4722 struct breakpoint
*b
;
4723 int thread
= -1; /* All threads. */
4730 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4731 set_breakpoint_count (breakpoint_count
+ 1);
4732 b
->number
= breakpoint_count
;
4734 b
->cond_string
= (cond_string
== NULL
) ?
4735 NULL
: savestring (cond_string
, strlen (cond_string
));
4737 b
->addr_string
= NULL
;
4738 b
->enable_state
= bp_enabled
;
4739 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4745 hw_breakpoint_used_count (void)
4747 struct breakpoint
*b
;
4752 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4760 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4762 struct breakpoint
*b
;
4765 *other_type_used
= 0;
4768 if (breakpoint_enabled (b
))
4770 if (b
->type
== type
)
4772 else if ((b
->type
== bp_hardware_watchpoint
||
4773 b
->type
== bp_read_watchpoint
||
4774 b
->type
== bp_access_watchpoint
))
4775 *other_type_used
= 1;
4781 /* Call this after hitting the longjmp() breakpoint. Use this to set
4782 a new breakpoint at the target of the jmp_buf.
4784 FIXME - This ought to be done by setting a temporary breakpoint
4785 that gets deleted automatically... */
4788 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4790 struct breakpoint
*b
;
4793 if (b
->type
== bp_longjmp_resume
)
4795 b
->loc
->requested_address
= pc
;
4796 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4798 b
->enable_state
= bp_enabled
;
4799 b
->frame_id
= frame_id
;
4800 check_duplicates (b
);
4806 disable_watchpoints_before_interactive_call_start (void)
4808 struct breakpoint
*b
;
4812 if (((b
->type
== bp_watchpoint
)
4813 || (b
->type
== bp_hardware_watchpoint
)
4814 || (b
->type
== bp_read_watchpoint
)
4815 || (b
->type
== bp_access_watchpoint
)
4816 || ep_is_exception_catchpoint (b
))
4817 && breakpoint_enabled (b
))
4819 b
->enable_state
= bp_call_disabled
;
4820 check_duplicates (b
);
4826 enable_watchpoints_after_interactive_call_stop (void)
4828 struct breakpoint
*b
;
4832 if (((b
->type
== bp_watchpoint
)
4833 || (b
->type
== bp_hardware_watchpoint
)
4834 || (b
->type
== bp_read_watchpoint
)
4835 || (b
->type
== bp_access_watchpoint
)
4836 || ep_is_exception_catchpoint (b
))
4837 && (b
->enable_state
== bp_call_disabled
))
4839 b
->enable_state
= bp_enabled
;
4840 check_duplicates (b
);
4846 /* Set a breakpoint that will evaporate an end of command
4847 at address specified by SAL.
4848 Restrict it to frame FRAME if FRAME is nonzero. */
4851 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4854 struct breakpoint
*b
;
4855 b
= set_raw_breakpoint (sal
, type
);
4856 b
->enable_state
= bp_enabled
;
4857 b
->disposition
= disp_donttouch
;
4858 b
->frame_id
= frame_id
;
4860 /* If we're debugging a multi-threaded program, then we
4861 want momentary breakpoints to be active in only a
4862 single thread of control. */
4863 if (in_thread_list (inferior_ptid
))
4864 b
->thread
= pid_to_thread_id (inferior_ptid
);
4870 /* Tell the user we have just set a breakpoint B. */
4873 mention (struct breakpoint
*b
)
4876 struct cleanup
*old_chain
, *ui_out_chain
;
4877 struct ui_stream
*stb
;
4879 stb
= ui_out_stream_new (uiout
);
4880 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4882 /* FIXME: This is misplaced; mention() is called by things (like
4883 hitting a watchpoint) other than breakpoint creation. It should
4884 be possible to clean this up and at the same time replace the
4885 random calls to breakpoint_changed with this hook, as has already
4886 been done for deprecated_delete_breakpoint_hook and so on. */
4887 if (deprecated_create_breakpoint_hook
)
4888 deprecated_create_breakpoint_hook (b
);
4889 breakpoint_create_event (b
->number
);
4891 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4892 b
->ops
->print_mention (b
);
4897 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4900 ui_out_text (uiout
, "Watchpoint ");
4901 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4902 ui_out_field_int (uiout
, "number", b
->number
);
4903 ui_out_text (uiout
, ": ");
4904 print_expression (b
->exp
, stb
->stream
);
4905 ui_out_field_stream (uiout
, "exp", stb
);
4906 do_cleanups (ui_out_chain
);
4908 case bp_hardware_watchpoint
:
4909 ui_out_text (uiout
, "Hardware watchpoint ");
4910 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4911 ui_out_field_int (uiout
, "number", b
->number
);
4912 ui_out_text (uiout
, ": ");
4913 print_expression (b
->exp
, stb
->stream
);
4914 ui_out_field_stream (uiout
, "exp", stb
);
4915 do_cleanups (ui_out_chain
);
4917 case bp_read_watchpoint
:
4918 ui_out_text (uiout
, "Hardware read watchpoint ");
4919 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4920 ui_out_field_int (uiout
, "number", b
->number
);
4921 ui_out_text (uiout
, ": ");
4922 print_expression (b
->exp
, stb
->stream
);
4923 ui_out_field_stream (uiout
, "exp", stb
);
4924 do_cleanups (ui_out_chain
);
4926 case bp_access_watchpoint
:
4927 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4928 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4929 ui_out_field_int (uiout
, "number", b
->number
);
4930 ui_out_text (uiout
, ": ");
4931 print_expression (b
->exp
, stb
->stream
);
4932 ui_out_field_stream (uiout
, "exp", stb
);
4933 do_cleanups (ui_out_chain
);
4936 if (ui_out_is_mi_like_p (uiout
))
4941 printf_filtered (_("Breakpoint %d"), b
->number
);
4944 case bp_hardware_breakpoint
:
4945 if (ui_out_is_mi_like_p (uiout
))
4950 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4954 case bp_catch_unload
:
4955 printf_filtered (_("Catchpoint %d (%s %s)"),
4957 (b
->type
== bp_catch_load
) ? "load" : "unload",
4958 (b
->dll_pathname
!= NULL
) ?
4959 b
->dll_pathname
: "<any library>");
4962 case bp_catch_vfork
:
4963 printf_filtered (_("Catchpoint %d (%s)"),
4965 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4968 printf_filtered (_("Catchpoint %d (exec)"),
4971 case bp_catch_catch
:
4972 case bp_catch_throw
:
4973 printf_filtered (_("Catchpoint %d (%s)"),
4975 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4981 case bp_longjmp_resume
:
4982 case bp_step_resume
:
4984 case bp_watchpoint_scope
:
4985 case bp_shlib_event
:
4986 case bp_thread_event
:
4987 case bp_overlay_event
:
4993 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4997 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5001 if (addressprint
|| b
->source_file
== NULL
)
5003 printf_filtered (" at ");
5004 deprecated_print_address_numeric (b
->loc
->address
, 1, gdb_stdout
);
5007 printf_filtered (": file %s, line %d.",
5008 b
->source_file
, b
->line_number
);
5011 do_cleanups (old_chain
);
5012 if (ui_out_is_mi_like_p (uiout
))
5014 printf_filtered ("\n");
5018 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5019 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
5020 COND[i] and COND_STRING[i] values.
5022 The parameter PENDING_BP points to a pending breakpoint that is
5023 the basis of the breakpoints currently being created. The pending
5024 breakpoint may contain a separate condition string or commands
5025 that were added after the initial pending breakpoint was created.
5027 NOTE: If the function succeeds, the caller is expected to cleanup
5028 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
5029 array contents). If the function fails (error() is called), the
5030 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5031 COND and SALS arrays and each of those arrays contents. */
5034 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5035 struct expression
**cond
, char **cond_string
,
5036 enum bptype type
, enum bpdisp disposition
,
5037 int thread
, int ignore_count
, int from_tty
,
5038 struct breakpoint
*pending_bp
)
5040 if (type
== bp_hardware_breakpoint
)
5042 int i
= hw_breakpoint_used_count ();
5043 int target_resources_ok
=
5044 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5046 if (target_resources_ok
== 0)
5047 error (_("No hardware breakpoint support in the target."));
5048 else if (target_resources_ok
< 0)
5049 error (_("Hardware breakpoints used exceeds limit."));
5052 /* Now set all the breakpoints. */
5055 for (i
= 0; i
< sals
.nelts
; i
++)
5057 struct breakpoint
*b
;
5058 struct symtab_and_line sal
= sals
.sals
[i
];
5061 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5063 b
= set_raw_breakpoint (sal
, type
);
5064 set_breakpoint_count (breakpoint_count
+ 1);
5065 b
->number
= breakpoint_count
;
5069 b
->addr_string
= addr_string
[i
];
5071 /* addr_string has to be used or breakpoint_re_set will delete
5073 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5074 b
->cond_string
= cond_string
[i
];
5075 b
->ignore_count
= ignore_count
;
5076 b
->enable_state
= bp_enabled
;
5077 b
->disposition
= disposition
;
5078 /* If resolving a pending breakpoint, a check must be made to see if
5079 the user has specified a new condition or commands for the
5080 breakpoint. A new condition will override any condition that was
5081 initially specified with the initial breakpoint command. */
5085 if (pending_bp
->cond_string
)
5087 arg
= pending_bp
->cond_string
;
5088 b
->cond_string
= savestring (arg
, strlen (arg
));
5089 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->loc
->address
), 0);
5091 error (_("Junk at end of pending breakpoint condition expression"));
5093 /* If there are commands associated with the breakpoint, they should
5095 if (pending_bp
->commands
)
5096 b
->commands
= copy_command_lines (pending_bp
->commands
);
5098 /* We have to copy over the ignore_count and thread as well. */
5099 b
->ignore_count
= pending_bp
->ignore_count
;
5100 b
->thread
= pending_bp
->thread
;
5107 /* Parse ARG which is assumed to be a SAL specification possibly
5108 followed by conditionals. On return, SALS contains an array of SAL
5109 addresses found. ADDR_STRING contains a vector of (canonical)
5110 address strings. ARG points to the end of the SAL. */
5113 parse_breakpoint_sals (char **address
,
5114 struct symtabs_and_lines
*sals
,
5115 char ***addr_string
,
5118 char *addr_start
= *address
;
5119 *addr_string
= NULL
;
5120 /* If no arg given, or if first arg is 'if ', use the default
5122 if ((*address
) == NULL
5123 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5125 if (default_breakpoint_valid
)
5127 struct symtab_and_line sal
;
5128 init_sal (&sal
); /* initialize to zeroes */
5129 sals
->sals
= (struct symtab_and_line
*)
5130 xmalloc (sizeof (struct symtab_and_line
));
5131 sal
.pc
= default_breakpoint_address
;
5132 sal
.line
= default_breakpoint_line
;
5133 sal
.symtab
= default_breakpoint_symtab
;
5134 sal
.section
= find_pc_overlay (sal
.pc
);
5135 sals
->sals
[0] = sal
;
5139 error (_("No default breakpoint address now."));
5143 /* Force almost all breakpoints to be in terms of the
5144 current_source_symtab (which is decode_line_1's default). This
5145 should produce the results we want almost all of the time while
5146 leaving default_breakpoint_* alone.
5147 ObjC: However, don't match an Objective-C method name which
5148 may have a '+' or '-' succeeded by a '[' */
5150 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5152 if (default_breakpoint_valid
5154 || ((strchr ("+-", (*address
)[0]) != NULL
)
5155 && ((*address
)[1] != '['))))
5156 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5157 default_breakpoint_line
, addr_string
,
5160 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5161 addr_string
, not_found_ptr
);
5163 /* For any SAL that didn't have a canonical string, fill one in. */
5164 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5165 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5166 if (addr_start
!= (*address
))
5169 for (i
= 0; i
< sals
->nelts
; i
++)
5171 /* Add the string if not present. */
5172 if ((*addr_string
)[i
] == NULL
)
5173 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5179 /* Convert each SAL into a real PC. Verify that the PC can be
5180 inserted as a breakpoint. If it can't throw an error. */
5183 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5187 for (i
= 0; i
< sals
->nelts
; i
++)
5189 resolve_sal_pc (&sals
->sals
[i
]);
5191 /* It's possible for the PC to be nonzero, but still an illegal
5192 value on some targets.
5194 For example, on HP-UX if you start gdb, and before running the
5195 inferior you try to set a breakpoint on a shared library function
5196 "foo" where the inferior doesn't call "foo" directly but does
5197 pass its address to another function call, then we do find a
5198 minimal symbol for the "foo", but it's address is invalid.
5199 (Appears to be an index into a table that the loader sets up
5200 when the inferior is run.)
5202 Give the target a chance to bless sals.sals[i].pc before we
5203 try to make a breakpoint for it. */
5204 #ifdef DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE
5205 if (DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE (sals
->sals
[i
].pc
))
5207 if (address
== NULL
)
5208 error (_("Cannot break without a running program."));
5210 error (_("Cannot break on %s without a running program."),
5218 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5220 struct captured_parse_breakpoint_args
*args
= data
;
5222 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5223 args
->not_found_ptr
);
5226 /* Set a breakpoint according to ARG (function, linenum or *address)
5227 flag: first bit : 0 non-temporary, 1 temporary.
5228 second bit : 0 normal breakpoint, 1 hardware breakpoint.
5230 PENDING_BP is non-NULL when this function is being called to resolve
5231 a pending breakpoint. */
5234 break_command_1 (char *arg
, int flag
, int from_tty
, struct breakpoint
*pending_bp
)
5236 struct gdb_exception e
;
5237 int tempflag
, hardwareflag
;
5238 struct symtabs_and_lines sals
;
5239 struct expression
**cond
= 0;
5240 struct symtab_and_line pending_sal
;
5241 char **cond_string
= (char **) NULL
;
5244 char *addr_start
= arg
;
5246 struct cleanup
*old_chain
;
5247 struct cleanup
*breakpoint_chain
= NULL
;
5248 struct captured_parse_breakpoint_args parse_args
;
5252 int ignore_count
= 0;
5255 hardwareflag
= flag
& BP_HARDWAREFLAG
;
5256 tempflag
= flag
& BP_TEMPFLAG
;
5262 parse_args
.arg_p
= &arg
;
5263 parse_args
.sals_p
= &sals
;
5264 parse_args
.addr_string_p
= &addr_string
;
5265 parse_args
.not_found_ptr
= ¬_found
;
5267 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5268 &parse_args
, RETURN_MASK_ALL
);
5270 /* If caller is interested in rc value from parse, set value. */
5274 exception_print (gdb_stderr
, e
);
5279 case NOT_FOUND_ERROR
:
5280 /* If called to resolve pending breakpoint, just return
5285 exception_print (gdb_stderr
, e
);
5287 /* If pending breakpoint support is turned off, throw
5290 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5291 deprecated_throw_reason (RETURN_ERROR
);
5293 /* If pending breakpoint support is auto query and the user
5294 selects no, then simply return the error code. */
5295 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5296 !nquery ("Make breakpoint pending on future shared library load? "))
5299 /* At this point, either the user was queried about setting
5300 a pending breakpoint and selected yes, or pending
5301 breakpoint behavior is on and thus a pending breakpoint
5302 is defaulted on behalf of the user. */
5303 copy_arg
= xstrdup (addr_start
);
5304 addr_string
= ©_arg
;
5306 sals
.sals
= &pending_sal
;
5311 exception_print (gdb_stderr
, e
);
5319 /* Create a chain of things that always need to be cleaned up. */
5320 old_chain
= make_cleanup (null_cleanup
, 0);
5324 /* Make sure that all storage allocated to SALS gets freed. */
5325 make_cleanup (xfree
, sals
.sals
);
5327 /* Cleanup the addr_string array but not its contents. */
5328 make_cleanup (xfree
, addr_string
);
5331 /* Allocate space for all the cond expressions. */
5332 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5333 make_cleanup (xfree
, cond
);
5335 /* Allocate space for all the cond strings. */
5336 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
5337 make_cleanup (xfree
, cond_string
);
5339 /* ----------------------------- SNIP -----------------------------
5340 Anything added to the cleanup chain beyond this point is assumed
5341 to be part of a breakpoint. If the breakpoint create succeeds
5342 then the memory is not reclaimed. */
5343 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5345 /* Mark the contents of the addr_string for cleanup. These go on
5346 the breakpoint_chain and only occure if the breakpoint create
5348 for (i
= 0; i
< sals
.nelts
; i
++)
5350 if (addr_string
[i
] != NULL
)
5351 make_cleanup (xfree
, addr_string
[i
]);
5354 /* Resolve all line numbers to PC's and verify that the addresses
5355 are ok for the target. */
5357 breakpoint_sals_to_pc (&sals
, addr_start
);
5359 /* Verify that condition can be parsed, before setting any
5360 breakpoints. Allocate a separate condition expression for each
5362 thread
= -1; /* No specific thread yet */
5365 for (i
= 0; i
< sals
.nelts
; i
++)
5372 char *cond_start
= NULL
;
5373 char *cond_end
= NULL
;
5374 while (*tok
== ' ' || *tok
== '\t')
5379 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5382 toklen
= end_tok
- tok
;
5384 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5386 tok
= cond_start
= end_tok
+ 1;
5387 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
),
5389 make_cleanup (xfree
, cond
[i
]);
5391 cond_string
[i
] = savestring (cond_start
,
5392 cond_end
- cond_start
);
5393 make_cleanup (xfree
, cond_string
[i
]);
5395 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5401 thread
= strtol (tok
, &tok
, 0);
5403 error (_("Junk after thread keyword."));
5404 if (!valid_thread_id (thread
))
5405 error (_("Unknown thread %d."), thread
);
5408 error (_("Junk at end of arguments."));
5411 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
5412 hardwareflag
? bp_hardware_breakpoint
5414 tempflag
? disp_del
: disp_donttouch
,
5415 thread
, ignore_count
, from_tty
,
5420 struct symtab_and_line sal
;
5421 struct breakpoint
*b
;
5426 make_cleanup (xfree
, copy_arg
);
5428 b
= set_raw_breakpoint (sal
, hardwareflag
? bp_hardware_breakpoint
5430 set_breakpoint_count (breakpoint_count
+ 1);
5431 b
->number
= breakpoint_count
;
5434 b
->addr_string
= *addr_string
;
5435 b
->cond_string
= *cond_string
;
5436 b
->ignore_count
= ignore_count
;
5438 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5439 b
->from_tty
= from_tty
;
5445 warning (_("Multiple breakpoints were set.\n"
5446 "Use the \"delete\" command to delete unwanted breakpoints."));
5447 /* That's it. Discard the cleanups for data inserted into the
5449 discard_cleanups (breakpoint_chain
);
5450 /* But cleanup everything else. */
5451 do_cleanups (old_chain
);
5456 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5457 linenum or *address) with COND and IGNORE_COUNT. */
5459 struct captured_breakpoint_args
5470 do_captured_breakpoint (struct ui_out
*uiout
, void *data
)
5472 struct captured_breakpoint_args
*args
= data
;
5473 struct symtabs_and_lines sals
;
5474 struct expression
**cond
;
5475 struct cleanup
*old_chain
;
5476 struct cleanup
*breakpoint_chain
= NULL
;
5483 /* Parse the source and lines spec. Delay check that the expression
5484 didn't contain trailing garbage until after cleanups are in
5488 address_end
= args
->address
;
5490 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
, 0);
5495 /* Create a chain of things at always need to be cleaned up. */
5496 old_chain
= make_cleanup (null_cleanup
, 0);
5498 /* Always have a addr_string array, even if it is empty. */
5499 make_cleanup (xfree
, addr_string
);
5501 /* Make sure that all storage allocated to SALS gets freed. */
5502 make_cleanup (xfree
, sals
.sals
);
5504 /* Allocate space for all the cond expressions. */
5505 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5506 make_cleanup (xfree
, cond
);
5508 /* Allocate space for all the cond strings. */
5509 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
5510 make_cleanup (xfree
, cond_string
);
5512 /* ----------------------------- SNIP -----------------------------
5513 Anything added to the cleanup chain beyond this point is assumed
5514 to be part of a breakpoint. If the breakpoint create goes
5515 through then that memory is not cleaned up. */
5516 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5518 /* Mark the contents of the addr_string for cleanup. These go on
5519 the breakpoint_chain and only occure if the breakpoint create
5521 for (i
= 0; i
< sals
.nelts
; i
++)
5523 if (addr_string
[i
] != NULL
)
5524 make_cleanup (xfree
, addr_string
[i
]);
5527 /* Wait until now before checking for garbage at the end of the
5528 address. That way cleanups can take care of freeing any
5530 if (*address_end
!= '\0')
5531 error (_("Garbage %s following breakpoint address"), address_end
);
5533 /* Resolve all line numbers to PC's. */
5534 breakpoint_sals_to_pc (&sals
, args
->address
);
5536 /* Verify that conditions can be parsed, before setting any
5538 for (i
= 0; i
< sals
.nelts
; i
++)
5540 if (args
->condition
!= NULL
)
5542 char *tok
= args
->condition
;
5543 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
5545 error (_("Garbage %s follows condition"), tok
);
5546 make_cleanup (xfree
, cond
[i
]);
5547 cond_string
[i
] = xstrdup (args
->condition
);
5551 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
5552 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
5553 args
->tempflag
? disp_del
: disp_donttouch
,
5554 args
->thread
, args
->ignore_count
, 0/*from-tty*/,
5555 NULL
/*pending_bp*/);
5557 /* That's it. Discard the cleanups for data inserted into the
5559 discard_cleanups (breakpoint_chain
);
5560 /* But cleanup everything else. */
5561 do_cleanups (old_chain
);
5566 gdb_breakpoint (char *address
, char *condition
,
5567 int hardwareflag
, int tempflag
,
5568 int thread
, int ignore_count
,
5569 char **error_message
)
5571 struct captured_breakpoint_args args
;
5572 args
.address
= address
;
5573 args
.condition
= condition
;
5574 args
.hardwareflag
= hardwareflag
;
5575 args
.tempflag
= tempflag
;
5576 args
.thread
= thread
;
5577 args
.ignore_count
= ignore_count
;
5578 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint
, &args
,
5579 error_message
, RETURN_MASK_ALL
) < 0)
5586 /* Helper function for break_command_1 and disassemble_command. */
5589 resolve_sal_pc (struct symtab_and_line
*sal
)
5593 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5595 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5596 error (_("No line %d in file \"%s\"."),
5597 sal
->line
, sal
->symtab
->filename
);
5601 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5603 struct blockvector
*bv
;
5608 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5611 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5612 sym
= block_function (b
);
5615 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5616 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5620 /* It really is worthwhile to have the section, so we'll just
5621 have to look harder. This case can be executed if we have
5622 line numbers but no functions (as can happen in assembly
5625 struct minimal_symbol
*msym
;
5627 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5629 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5636 break_command (char *arg
, int from_tty
)
5638 break_command_1 (arg
, 0, from_tty
, NULL
);
5642 tbreak_command (char *arg
, int from_tty
)
5644 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
, NULL
);
5648 hbreak_command (char *arg
, int from_tty
)
5650 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
, NULL
);
5654 thbreak_command (char *arg
, int from_tty
)
5656 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
, NULL
);
5660 stop_command (char *arg
, int from_tty
)
5662 printf_filtered (_("Specify the type of breakpoint to set.\n\
5663 Usage: stop in <function | address>\n\
5664 stop at <line>\n"));
5668 stopin_command (char *arg
, int from_tty
)
5672 if (arg
== (char *) NULL
)
5674 else if (*arg
!= '*')
5679 /* look for a ':'. If this is a line number specification, then
5680 say it is bad, otherwise, it should be an address or
5681 function/method name */
5682 while (*argptr
&& !hasColon
)
5684 hasColon
= (*argptr
== ':');
5689 badInput
= (*argptr
!= ':'); /* Not a class::method */
5691 badInput
= isdigit (*arg
); /* a simple line number */
5695 printf_filtered (_("Usage: stop in <function | address>\n"));
5697 break_command_1 (arg
, 0, from_tty
, NULL
);
5701 stopat_command (char *arg
, int from_tty
)
5705 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5712 /* look for a ':'. If there is a '::' then get out, otherwise
5713 it is probably a line number. */
5714 while (*argptr
&& !hasColon
)
5716 hasColon
= (*argptr
== ':');
5721 badInput
= (*argptr
== ':'); /* we have class::method */
5723 badInput
= !isdigit (*arg
); /* not a line number */
5727 printf_filtered (_("Usage: stop at <line>\n"));
5729 break_command_1 (arg
, 0, from_tty
, NULL
);
5732 /* accessflag: hw_write: watch write,
5733 hw_read: watch read,
5734 hw_access: watch access (read or write) */
5736 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5738 struct breakpoint
*b
;
5739 struct symtab_and_line sal
;
5740 struct expression
*exp
;
5741 struct block
*exp_valid_block
;
5742 struct value
*val
, *mark
;
5743 struct frame_info
*frame
;
5744 struct frame_info
*prev_frame
= NULL
;
5745 char *exp_start
= NULL
;
5746 char *exp_end
= NULL
;
5747 char *tok
, *end_tok
;
5749 char *cond_start
= NULL
;
5750 char *cond_end
= NULL
;
5751 struct expression
*cond
= NULL
;
5752 int i
, other_type_used
, target_resources_ok
= 0;
5753 enum bptype bp_type
;
5756 init_sal (&sal
); /* initialize to zeroes */
5758 /* Parse arguments. */
5759 innermost_block
= NULL
;
5761 exp
= parse_exp_1 (&arg
, 0, 0);
5763 exp_valid_block
= innermost_block
;
5764 mark
= value_mark ();
5765 val
= evaluate_expression (exp
);
5766 release_value (val
);
5767 if (value_lazy (val
))
5768 value_fetch_lazy (val
);
5771 while (*tok
== ' ' || *tok
== '\t')
5775 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5778 toklen
= end_tok
- tok
;
5779 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5781 tok
= cond_start
= end_tok
+ 1;
5782 cond
= parse_exp_1 (&tok
, 0, 0);
5786 error (_("Junk at end of command."));
5788 if (accessflag
== hw_read
)
5789 bp_type
= bp_read_watchpoint
;
5790 else if (accessflag
== hw_access
)
5791 bp_type
= bp_access_watchpoint
;
5793 bp_type
= bp_hardware_watchpoint
;
5795 mem_cnt
= can_use_hardware_watchpoint (val
);
5796 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5797 error (_("Expression cannot be implemented with read/access watchpoint."));
5800 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5801 target_resources_ok
=
5802 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5804 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5805 error (_("Target does not support this type of hardware watchpoint."));
5807 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5808 error (_("Target can only support one kind of HW watchpoint at a time."));
5811 #if defined(HPUXHPPA)
5812 /* On HP-UX if you set a h/w
5813 watchpoint before the "run" command, the inferior dies with a e.g.,
5814 SIGILL once you start it. I initially believed this was due to a
5815 bad interaction between page protection traps and the initial
5816 startup sequence by the dynamic linker.
5818 However, I tried avoiding that by having HP-UX's implementation of
5819 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5820 yet, which forced slow watches before a "run" or "attach", and it
5821 still fails somewhere in the startup code.
5823 Until I figure out what's happening, I'm disallowing watches altogether
5824 before the "run" or "attach" command. We'll tell the user they must
5825 set watches after getting the program started. */
5826 if (!target_has_execution
)
5828 warning (_("can't do that without a running program; try \"break main\"), \"run\" first");
5831 #endif /* HPUXHPPA */
5833 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5834 watchpoint could not be set. */
5835 if (!mem_cnt
|| target_resources_ok
<= 0)
5836 bp_type
= bp_watchpoint
;
5838 /* Now set up the breakpoint. */
5839 b
= set_raw_breakpoint (sal
, bp_type
);
5840 set_breakpoint_count (breakpoint_count
+ 1);
5841 b
->number
= breakpoint_count
;
5842 b
->disposition
= disp_donttouch
;
5844 b
->exp_valid_block
= exp_valid_block
;
5845 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5849 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5853 frame
= block_innermost_frame (exp_valid_block
);
5856 prev_frame
= get_prev_frame (frame
);
5857 b
->watchpoint_frame
= get_frame_id (frame
);
5861 memset (&b
->watchpoint_frame
, 0, sizeof (b
->watchpoint_frame
));
5864 /* If the expression is "local", then set up a "watchpoint scope"
5865 breakpoint at the point where we've left the scope of the watchpoint
5867 if (innermost_block
)
5871 struct breakpoint
*scope_breakpoint
;
5872 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5873 bp_watchpoint_scope
);
5875 scope_breakpoint
->enable_state
= bp_enabled
;
5877 /* Automatically delete the breakpoint when it hits. */
5878 scope_breakpoint
->disposition
= disp_del
;
5880 /* Only break in the proper frame (help with recursion). */
5881 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5883 /* Set the address at which we will stop. */
5884 scope_breakpoint
->loc
->requested_address
5885 = get_frame_pc (prev_frame
);
5886 scope_breakpoint
->loc
->address
5887 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5888 scope_breakpoint
->type
);
5890 /* The scope breakpoint is related to the watchpoint. We
5891 will need to act on them together. */
5892 b
->related_breakpoint
= scope_breakpoint
;
5895 value_free_to_mark (mark
);
5899 /* Return count of locations need to be watched and can be handled
5900 in hardware. If the watchpoint can not be handled
5901 in hardware return zero. */
5904 can_use_hardware_watchpoint (struct value
*v
)
5906 int found_memory_cnt
= 0;
5907 struct value
*head
= v
;
5909 /* Did the user specifically forbid us to use hardware watchpoints? */
5910 if (!can_use_hw_watchpoints
)
5913 /* Make sure that the value of the expression depends only upon
5914 memory contents, and values computed from them within GDB. If we
5915 find any register references or function calls, we can't use a
5916 hardware watchpoint.
5918 The idea here is that evaluating an expression generates a series
5919 of values, one holding the value of every subexpression. (The
5920 expression a*b+c has five subexpressions: a, b, a*b, c, and
5921 a*b+c.) GDB's values hold almost enough information to establish
5922 the criteria given above --- they identify memory lvalues,
5923 register lvalues, computed values, etcetera. So we can evaluate
5924 the expression, and then scan the chain of values that leaves
5925 behind to decide whether we can detect any possible change to the
5926 expression's final value using only hardware watchpoints.
5928 However, I don't think that the values returned by inferior
5929 function calls are special in any way. So this function may not
5930 notice that an expression involving an inferior function call
5931 can't be watched with hardware watchpoints. FIXME. */
5932 for (; v
; v
= value_next (v
))
5934 if (VALUE_LVAL (v
) == lval_memory
)
5937 /* A lazy memory lvalue is one that GDB never needed to fetch;
5938 we either just used its address (e.g., `a' in `a.b') or
5939 we never needed it at all (e.g., `a' in `a,b'). */
5943 /* Ahh, memory we actually used! Check if we can cover
5944 it with hardware watchpoints. */
5945 struct type
*vtype
= check_typedef (value_type (v
));
5947 /* We only watch structs and arrays if user asked for it
5948 explicitly, never if they just happen to appear in a
5949 middle of some value chain. */
5951 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5952 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5954 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
5955 int len
= TYPE_LENGTH (value_type (v
));
5957 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5964 else if (VALUE_LVAL (v
) != not_lval
5965 && deprecated_value_modifiable (v
) == 0)
5966 return 0; /* ??? What does this represent? */
5967 else if (VALUE_LVAL (v
) == lval_register
)
5968 return 0; /* cannot watch a register with a HW watchpoint */
5971 /* The expression itself looks suitable for using a hardware
5972 watchpoint, but give the target machine a chance to reject it. */
5973 return found_memory_cnt
;
5977 watch_command_wrapper (char *arg
, int from_tty
)
5979 watch_command (arg
, from_tty
);
5983 watch_command (char *arg
, int from_tty
)
5985 watch_command_1 (arg
, hw_write
, from_tty
);
5989 rwatch_command_wrapper (char *arg
, int from_tty
)
5991 rwatch_command (arg
, from_tty
);
5995 rwatch_command (char *arg
, int from_tty
)
5997 watch_command_1 (arg
, hw_read
, from_tty
);
6001 awatch_command_wrapper (char *arg
, int from_tty
)
6003 awatch_command (arg
, from_tty
);
6007 awatch_command (char *arg
, int from_tty
)
6009 watch_command_1 (arg
, hw_access
, from_tty
);
6013 /* Helper routines for the until_command routine in infcmd.c. Here
6014 because it uses the mechanisms of breakpoints. */
6016 /* This function is called by fetch_inferior_event via the
6017 cmd_continuation pointer, to complete the until command. It takes
6018 care of cleaning up the temporary breakpoints set up by the until
6021 until_break_command_continuation (struct continuation_arg
*arg
)
6023 struct cleanup
*cleanups
;
6025 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
6026 do_exec_cleanups (cleanups
);
6030 until_break_command (char *arg
, int from_tty
, int anywhere
)
6032 struct symtabs_and_lines sals
;
6033 struct symtab_and_line sal
;
6034 struct frame_info
*frame
= get_selected_frame (NULL
);
6035 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6036 struct breakpoint
*breakpoint
;
6037 struct cleanup
*old_chain
;
6038 struct continuation_arg
*arg1
;
6041 clear_proceed_status ();
6043 /* Set a breakpoint where the user wants it and at return from
6046 if (default_breakpoint_valid
)
6047 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6048 default_breakpoint_line
, (char ***) NULL
, NULL
);
6050 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6051 0, (char ***) NULL
, NULL
);
6053 if (sals
.nelts
!= 1)
6054 error (_("Couldn't get information on specified line."));
6057 xfree (sals
.sals
); /* malloc'd, so freed */
6060 error (_("Junk at end of arguments."));
6062 resolve_sal_pc (&sal
);
6065 /* If the user told us to continue until a specified location,
6066 we don't specify a frame at which we need to stop. */
6067 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6069 /* Otherwise, specify the current frame, because we want to stop only
6070 at the very same frame. */
6071 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6074 if (!target_can_async_p ())
6075 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6077 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
6079 /* If we are running asynchronously, and the target supports async
6080 execution, we are not waiting for the target to stop, in the call
6081 tp proceed, below. This means that we cannot delete the
6082 brekpoints until the target has actually stopped. The only place
6083 where we get a chance to do that is in fetch_inferior_event, so
6084 we must set things up for that. */
6086 if (target_can_async_p ())
6088 /* In this case the arg for the continuation is just the point
6089 in the exec_cleanups chain from where to start doing
6090 cleanups, because all the continuation does is the cleanups in
6091 the exec_cleanup_chain. */
6093 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6095 arg1
->data
.pointer
= old_chain
;
6097 add_continuation (until_break_command_continuation
, arg1
);
6100 /* Keep within the current frame, or in frames called by the current
6104 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6105 sal
.pc
= get_frame_pc (prev_frame
);
6106 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6108 if (!target_can_async_p ())
6109 make_cleanup_delete_breakpoint (breakpoint
);
6111 make_exec_cleanup_delete_breakpoint (breakpoint
);
6114 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6115 /* Do the cleanups now, anly if we are not running asynchronously,
6116 of if we are, but the target is still synchronous. */
6117 if (!target_can_async_p ())
6118 do_cleanups (old_chain
);
6122 ep_skip_leading_whitespace (char **s
)
6124 if ((s
== NULL
) || (*s
== NULL
))
6126 while (isspace (**s
))
6130 /* This function examines a string, and attempts to find a token
6131 that might be an event name in the leading characters. If a
6132 possible match is found, a pointer to the last character of
6133 the token is returned. Else, NULL is returned. */
6136 ep_find_event_name_end (char *arg
)
6139 char *event_name_end
= NULL
;
6141 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6145 /* We break out of the loop when we find a token delimiter.
6146 Basically, we're looking for alphanumerics and underscores;
6147 anything else delimites the token. */
6150 if (!isalnum (*s
) && (*s
!= '_'))
6156 return event_name_end
;
6160 /* This function attempts to parse an optional "if <cond>" clause
6161 from the arg string. If one is not found, it returns NULL.
6163 Else, it returns a pointer to the condition string. (It does not
6164 attempt to evaluate the string against a particular block.) And,
6165 it updates arg to point to the first character following the parsed
6166 if clause in the arg string. */
6169 ep_parse_optional_if_clause (char **arg
)
6173 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6176 /* Skip the "if" keyword. */
6179 /* Skip any extra leading whitespace, and record the start of the
6180 condition string. */
6181 ep_skip_leading_whitespace (arg
);
6184 /* Assume that the condition occupies the remainder of the arg string. */
6185 (*arg
) += strlen (cond_string
);
6190 /* This function attempts to parse an optional filename from the arg
6191 string. If one is not found, it returns NULL.
6193 Else, it returns a pointer to the parsed filename. (This function
6194 makes no attempt to verify that a file of that name exists, or is
6195 accessible.) And, it updates arg to point to the first character
6196 following the parsed filename in the arg string.
6198 Note that clients needing to preserve the returned filename for
6199 future access should copy it to their own buffers. */
6201 ep_parse_optional_filename (char **arg
)
6203 static char filename
[1024];
6208 if ((*arg_p
== '\0') || isspace (*arg_p
))
6226 /* Commands to deal with catching events, such as signals, exceptions,
6227 process start/exit, etc. */
6231 catch_fork
, catch_vfork
6236 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6239 char *cond_string
= NULL
;
6241 ep_skip_leading_whitespace (&arg
);
6243 /* The allowed syntax is:
6245 catch [v]fork if <cond>
6247 First, check if there's an if clause. */
6248 cond_string
= ep_parse_optional_if_clause (&arg
);
6250 if ((*arg
!= '\0') && !isspace (*arg
))
6251 error (_("Junk at end of arguments."));
6253 /* If this target supports it, create a fork or vfork catchpoint
6254 and enable reporting of such events. */
6258 create_fork_event_catchpoint (tempflag
, cond_string
);
6261 create_vfork_event_catchpoint (tempflag
, cond_string
);
6264 error (_("unsupported or unknown fork kind; cannot catch it"));
6270 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6272 char *cond_string
= NULL
;
6274 ep_skip_leading_whitespace (&arg
);
6276 /* The allowed syntax is:
6278 catch exec if <cond>
6280 First, check if there's an if clause. */
6281 cond_string
= ep_parse_optional_if_clause (&arg
);
6283 if ((*arg
!= '\0') && !isspace (*arg
))
6284 error (_("Junk at end of arguments."));
6286 /* If this target supports it, create an exec catchpoint
6287 and enable reporting of such events. */
6288 create_exec_event_catchpoint (tempflag
, cond_string
);
6292 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6294 char *dll_pathname
= NULL
;
6295 char *cond_string
= NULL
;
6297 ep_skip_leading_whitespace (&arg
);
6299 /* The allowed syntax is:
6301 catch load if <cond>
6302 catch load <filename>
6303 catch load <filename> if <cond>
6305 The user is not allowed to specify the <filename> after an
6308 We'll ignore the pathological case of a file named "if".
6310 First, check if there's an if clause. If so, then there
6311 cannot be a filename. */
6312 cond_string
= ep_parse_optional_if_clause (&arg
);
6314 /* If there was an if clause, then there cannot be a filename.
6315 Else, there might be a filename and an if clause. */
6316 if (cond_string
== NULL
)
6318 dll_pathname
= ep_parse_optional_filename (&arg
);
6319 ep_skip_leading_whitespace (&arg
);
6320 cond_string
= ep_parse_optional_if_clause (&arg
);
6323 if ((*arg
!= '\0') && !isspace (*arg
))
6324 error (_("Junk at end of arguments."));
6326 /* Create a load breakpoint that only triggers when a load of
6327 the specified dll (or any dll, if no pathname was specified)
6329 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6330 dll_pathname
, cond_string
);
6334 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6336 char *dll_pathname
= NULL
;
6337 char *cond_string
= NULL
;
6339 ep_skip_leading_whitespace (&arg
);
6341 /* The allowed syntax is:
6343 catch unload if <cond>
6344 catch unload <filename>
6345 catch unload <filename> if <cond>
6347 The user is not allowed to specify the <filename> after an
6350 We'll ignore the pathological case of a file named "if".
6352 First, check if there's an if clause. If so, then there
6353 cannot be a filename. */
6354 cond_string
= ep_parse_optional_if_clause (&arg
);
6356 /* If there was an if clause, then there cannot be a filename.
6357 Else, there might be a filename and an if clause. */
6358 if (cond_string
== NULL
)
6360 dll_pathname
= ep_parse_optional_filename (&arg
);
6361 ep_skip_leading_whitespace (&arg
);
6362 cond_string
= ep_parse_optional_if_clause (&arg
);
6365 if ((*arg
!= '\0') && !isspace (*arg
))
6366 error (_("Junk at end of arguments."));
6368 /* Create an unload breakpoint that only triggers when an unload of
6369 the specified dll (or any dll, if no pathname was specified)
6371 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6372 dll_pathname
, cond_string
);
6375 /* Commands to deal with catching exceptions. */
6377 /* Set a breakpoint at the specified callback routine for an
6378 exception event callback */
6381 create_exception_catchpoint (int tempflag
, char *cond_string
,
6382 enum exception_event_kind ex_event
,
6383 struct symtab_and_line
*sal
)
6385 struct breakpoint
*b
;
6386 int thread
= -1; /* All threads. */
6389 if (!sal
) /* no exception support? */
6394 case EX_EVENT_THROW
:
6395 bptype
= bp_catch_throw
;
6397 case EX_EVENT_CATCH
:
6398 bptype
= bp_catch_catch
;
6400 default: /* error condition */
6401 error (_("Internal error -- invalid catchpoint kind"));
6404 b
= set_raw_breakpoint (*sal
, bptype
);
6405 set_breakpoint_count (breakpoint_count
+ 1);
6406 b
->number
= breakpoint_count
;
6408 b
->cond_string
= (cond_string
== NULL
) ?
6409 NULL
: savestring (cond_string
, strlen (cond_string
));
6411 b
->addr_string
= NULL
;
6412 b
->enable_state
= bp_enabled
;
6413 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6417 static enum print_stop_action
6418 print_exception_catchpoint (struct breakpoint
*b
)
6420 annotate_catchpoint (b
->number
);
6422 if (strstr (b
->addr_string
, "throw") != NULL
)
6423 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6426 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6429 return PRINT_SRC_AND_LOC
;
6433 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6438 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6441 *last_addr
= b
->loc
->address
;
6442 if (strstr (b
->addr_string
, "throw") != NULL
)
6443 ui_out_field_string (uiout
, "what", "exception throw");
6445 ui_out_field_string (uiout
, "what", "exception catch");
6449 print_mention_exception_catchpoint (struct breakpoint
*b
)
6451 if (strstr (b
->addr_string
, "throw") != NULL
)
6452 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6454 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6457 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6458 print_exception_catchpoint
,
6459 print_one_exception_catchpoint
,
6460 print_mention_exception_catchpoint
6464 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6465 enum exception_event_kind ex_event
, int from_tty
)
6467 char *trigger_func_name
, *nameptr
;
6468 struct symtabs_and_lines sals
;
6469 struct breakpoint
*b
;
6471 if (ex_event
== EX_EVENT_CATCH
)
6472 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6474 trigger_func_name
= xstrdup ("__cxa_throw");
6476 nameptr
= trigger_func_name
;
6477 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6478 if (sals
.nelts
== 0)
6480 xfree (trigger_func_name
);
6484 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6485 set_breakpoint_count (breakpoint_count
+ 1);
6486 b
->number
= breakpoint_count
;
6488 b
->cond_string
= (cond_string
== NULL
) ?
6489 NULL
: savestring (cond_string
, strlen (cond_string
));
6491 b
->addr_string
= trigger_func_name
;
6492 b
->enable_state
= bp_enabled
;
6493 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6494 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6501 /* Deal with "catch catch" and "catch throw" commands */
6504 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6505 int tempflag
, int from_tty
)
6507 char *cond_string
= NULL
;
6508 struct symtab_and_line
*sal
= NULL
;
6510 ep_skip_leading_whitespace (&arg
);
6512 cond_string
= ep_parse_optional_if_clause (&arg
);
6514 if ((*arg
!= '\0') && !isspace (*arg
))
6515 error (_("Junk at end of arguments."));
6517 if ((ex_event
!= EX_EVENT_THROW
) &&
6518 (ex_event
!= EX_EVENT_CATCH
))
6519 error (_("Unsupported or unknown exception event; cannot catch it"));
6521 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6524 /* See if we can find a callback routine */
6525 sal
= target_enable_exception_callback (ex_event
, 1);
6529 /* We have callbacks from the runtime system for exceptions.
6530 Set a breakpoint on the sal found, if no errors */
6531 if (sal
!= (struct symtab_and_line
*) -1)
6532 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6534 return; /* something went wrong with setting up callbacks */
6537 warning (_("Unsupported with this platform/compiler combination."));
6540 /* Create a breakpoint struct for Ada exception catchpoints. */
6543 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6547 struct expression
*cond
,
6548 struct breakpoint_ops
*ops
,
6552 struct breakpoint
*b
;
6556 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6557 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6558 version for exception catchpoints, because two catchpoints
6559 used for different exception names will use the same address.
6560 In this case, a "breakpoint ... also set at..." warning is
6561 unproductive. Besides. the warning phrasing is also a bit
6562 inapropriate, we should use the word catchpoint, and tell
6563 the user what type of catchpoint it is. The above is good
6564 enough for now, though. */
6567 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6568 set_breakpoint_count (breakpoint_count
+ 1);
6570 b
->enable_state
= bp_enabled
;
6571 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6572 b
->number
= breakpoint_count
;
6573 b
->ignore_count
= 0;
6575 b
->addr_string
= addr_string
;
6576 b
->language
= language_ada
;
6577 b
->cond_string
= cond_string
;
6578 b
->exp_string
= exp_string
;
6581 b
->from_tty
= from_tty
;
6586 /* Implement the "catch exception" command. */
6589 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6591 struct symtab_and_line sal
;
6593 char *addr_string
= NULL
;
6594 char *exp_string
= NULL
;
6595 char *cond_string
= NULL
;
6596 struct expression
*cond
= NULL
;
6597 struct breakpoint_ops
*ops
= NULL
;
6599 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6600 &cond_string
, &cond
, &ops
);
6601 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6602 cond_string
, cond
, ops
, tempflag
,
6606 /* Implement the "catch assert" command. */
6609 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6611 struct symtab_and_line sal
;
6612 char *addr_string
= NULL
;
6613 struct breakpoint_ops
*ops
= NULL
;
6615 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6616 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6617 tempflag
, from_tty
);
6620 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6621 inside a catch_errors */
6624 cover_target_enable_exception_callback (void *arg
)
6626 args_for_catchpoint_enable
*args
= arg
;
6627 struct symtab_and_line
*sal
;
6628 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6631 else if (sal
== (struct symtab_and_line
*) -1)
6634 return 1; /*is valid */
6638 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6641 /* The first argument may be an event name, such as "start" or "load".
6642 If so, then handle it as such. If it doesn't match an event name,
6643 then attempt to interpret it as an exception name. (This latter is
6644 the v4.16-and-earlier GDB meaning of the "catch" command.)
6646 First, try to find the bounds of what might be an event name. */
6647 char *arg1_start
= arg
;
6651 if (arg1_start
== NULL
)
6653 /* Old behaviour was to use pre-v-4.16 syntax */
6654 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6656 /* Now, this is not allowed */
6657 error (_("Catch requires an event name."));
6660 arg1_end
= ep_find_event_name_end (arg1_start
);
6661 if (arg1_end
== NULL
)
6662 error (_("catch requires an event"));
6663 arg1_length
= arg1_end
+ 1 - arg1_start
;
6665 /* Try to match what we found against known event names. */
6666 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6668 error (_("Catch of signal not yet implemented"));
6670 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6672 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6673 tempflag
, from_tty
);
6675 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6677 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6678 tempflag
, from_tty
);
6680 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6682 error (_("Catch of thread_start not yet implemented"));
6684 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6686 error (_("Catch of thread_exit not yet implemented"));
6688 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6690 error (_("Catch of thread_join not yet implemented"));
6692 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6694 error (_("Catch of start not yet implemented"));
6696 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6698 error (_("Catch of exit not yet implemented"));
6700 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6702 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6704 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6706 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6708 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6710 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6712 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6714 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6716 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6718 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6720 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6722 error (_("Catch of stop not yet implemented"));
6724 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6726 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6729 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6731 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6734 /* This doesn't appear to be an event name */
6738 /* Pre-v.4.16 behaviour was to treat the argument
6739 as the name of an exception */
6740 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6741 /* Now this is not allowed */
6742 error (_("Unknown event kind specified for catch"));
6747 /* Used by the gui, could be made a worker for other things. */
6750 set_breakpoint_sal (struct symtab_and_line sal
)
6752 struct breakpoint
*b
;
6753 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6754 set_breakpoint_count (breakpoint_count
+ 1);
6755 b
->number
= breakpoint_count
;
6762 catch_command (char *arg
, int from_tty
)
6764 catch_command_1 (arg
, 0, from_tty
);
6769 tcatch_command (char *arg
, int from_tty
)
6771 catch_command_1 (arg
, 1, from_tty
);
6774 /* Delete breakpoints by address or line. */
6777 clear_command (char *arg
, int from_tty
)
6779 struct breakpoint
*b
, *tmp
, *prev
, *found
;
6781 struct symtabs_and_lines sals
;
6782 struct symtab_and_line sal
;
6787 sals
= decode_line_spec (arg
, 1);
6792 sals
.sals
= (struct symtab_and_line
*)
6793 xmalloc (sizeof (struct symtab_and_line
));
6794 make_cleanup (xfree
, sals
.sals
);
6795 init_sal (&sal
); /* initialize to zeroes */
6796 sal
.line
= default_breakpoint_line
;
6797 sal
.symtab
= default_breakpoint_symtab
;
6798 sal
.pc
= default_breakpoint_address
;
6799 if (sal
.symtab
== 0)
6800 error (_("No source file specified."));
6808 /* For each line spec given, delete bps which correspond
6809 to it. Do it in two passes, solely to preserve the current
6810 behavior that from_tty is forced true if we delete more than
6814 for (i
= 0; i
< sals
.nelts
; i
++)
6816 /* If exact pc given, clear bpts at that pc.
6817 If line given (pc == 0), clear all bpts on specified line.
6818 If defaulting, clear all bpts on default line
6821 defaulting sal.pc != 0 tests to do
6826 1 0 <can't happen> */
6831 /* Find all matching breakpoints, remove them from the
6832 breakpoint chain, and add them to the 'found' chain. */
6833 ALL_BREAKPOINTS_SAFE (b
, tmp
)
6835 /* Are we going to delete b? */
6836 if (b
->type
!= bp_none
6837 && b
->type
!= bp_watchpoint
6838 && b
->type
!= bp_hardware_watchpoint
6839 && b
->type
!= bp_read_watchpoint
6840 && b
->type
!= bp_access_watchpoint
6841 /* Not if b is a watchpoint of any sort... */
6842 && (((sal
.pc
&& (b
->loc
->address
== sal
.pc
))
6843 && (!section_is_overlay (b
->loc
->section
)
6844 || b
->loc
->section
== sal
.section
))
6845 /* Yes, if sal.pc matches b (modulo overlays). */
6846 || ((default_match
|| (0 == sal
.pc
))
6847 && b
->source_file
!= NULL
6848 && sal
.symtab
!= NULL
6849 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6850 && b
->line_number
== sal
.line
)))
6851 /* Yes, if sal source file and line matches b. */
6853 /* Remove it from breakpoint_chain... */
6854 if (b
== breakpoint_chain
)
6856 /* b is at the head of the list */
6857 breakpoint_chain
= b
->next
;
6861 prev
->next
= b
->next
;
6863 /* And add it to 'found' chain. */
6869 /* Keep b, and keep a pointer to it. */
6874 /* Now go thru the 'found' chain and delete them. */
6878 error (_("No breakpoint at %s."), arg
);
6880 error (_("No breakpoint at this line."));
6884 from_tty
= 1; /* Always report if deleted more than one */
6888 printf_unfiltered (_("Deleted breakpoint "));
6890 printf_unfiltered (_("Deleted breakpoints "));
6892 breakpoints_changed ();
6896 printf_unfiltered ("%d ", found
->number
);
6898 delete_breakpoint (found
);
6902 putchar_unfiltered ('\n');
6905 /* Delete breakpoint in BS if they are `delete' breakpoints and
6906 all breakpoints that are marked for deletion, whether hit or not.
6907 This is called after any breakpoint is hit, or after errors. */
6910 breakpoint_auto_delete (bpstat bs
)
6912 struct breakpoint
*b
, *temp
;
6914 for (; bs
; bs
= bs
->next
)
6915 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== disp_del
6917 delete_breakpoint (bs
->breakpoint_at
);
6919 ALL_BREAKPOINTS_SAFE (b
, temp
)
6921 if (b
->disposition
== disp_del_at_next_stop
)
6922 delete_breakpoint (b
);
6926 /* Delete a breakpoint and clean up all traces of it in the data
6930 delete_breakpoint (struct breakpoint
*bpt
)
6932 struct breakpoint
*b
;
6934 struct bp_location
*loc
;
6936 gdb_assert (bpt
!= NULL
);
6938 /* Has this bp already been deleted? This can happen because multiple
6939 lists can hold pointers to bp's. bpstat lists are especial culprits.
6941 One example of this happening is a watchpoint's scope bp. When the
6942 scope bp triggers, we notice that the watchpoint is out of scope, and
6943 delete it. We also delete its scope bp. But the scope bp is marked
6944 "auto-deleting", and is already on a bpstat. That bpstat is then
6945 checked for auto-deleting bp's, which are deleted.
6947 A real solution to this problem might involve reference counts in bp's,
6948 and/or giving them pointers back to their referencing bpstat's, and
6949 teaching delete_breakpoint to only free a bp's storage when no more
6950 references were extent. A cheaper bandaid was chosen. */
6951 if (bpt
->type
== bp_none
)
6954 if (deprecated_delete_breakpoint_hook
)
6955 deprecated_delete_breakpoint_hook (bpt
);
6956 breakpoint_delete_event (bpt
->number
);
6958 if (bpt
->loc
->inserted
)
6959 remove_breakpoint (bpt
->loc
, mark_inserted
);
6961 free_valchain (bpt
->loc
);
6963 if (breakpoint_chain
== bpt
)
6964 breakpoint_chain
= bpt
->next
;
6966 if (bp_location_chain
== bpt
->loc
)
6967 bp_location_chain
= bpt
->loc
->next
;
6969 /* If we have callback-style exception catchpoints, don't go through
6970 the adjustments to the C++ runtime library etc. if the inferior
6971 isn't actually running. target_enable_exception_callback for a
6972 null target ops vector gives an undesirable error message, so we
6973 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6974 exceptions are supported in this way, it's OK for now. FIXME */
6975 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
6977 /* Format possible error msg */
6978 char *message
= xstrprintf ("Error in deleting catchpoint %d:\n",
6980 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
6981 args_for_catchpoint_enable args
;
6982 args
.kind
= bpt
->type
== bp_catch_catch
?
6983 EX_EVENT_CATCH
: EX_EVENT_THROW
;
6985 catch_errors (cover_target_enable_exception_callback
, &args
,
6986 message
, RETURN_MASK_ALL
);
6987 do_cleanups (cleanups
);
6994 b
->next
= bpt
->next
;
6998 ALL_BP_LOCATIONS (loc
)
6999 if (loc
->next
== bpt
->loc
)
7001 loc
->next
= bpt
->loc
->next
;
7005 check_duplicates (bpt
);
7006 /* If this breakpoint was inserted, and there is another breakpoint
7007 at the same address, we need to insert the other breakpoint. */
7008 if (bpt
->loc
->inserted
7009 && bpt
->type
!= bp_hardware_watchpoint
7010 && bpt
->type
!= bp_read_watchpoint
7011 && bpt
->type
!= bp_access_watchpoint
7012 && bpt
->type
!= bp_catch_fork
7013 && bpt
->type
!= bp_catch_vfork
7014 && bpt
->type
!= bp_catch_exec
)
7017 if (b
->loc
->address
== bpt
->loc
->address
7018 && b
->loc
->section
== bpt
->loc
->section
7019 && !b
->loc
->duplicate
7020 && b
->enable_state
!= bp_disabled
7021 && b
->enable_state
!= bp_shlib_disabled
7023 && b
->enable_state
!= bp_call_disabled
)
7027 /* We should never reach this point if there is a permanent
7028 breakpoint at the same address as the one being deleted.
7029 If there is a permanent breakpoint somewhere, it should
7030 always be the only one inserted. */
7031 if (b
->enable_state
== bp_permanent
)
7032 internal_error (__FILE__
, __LINE__
,
7033 _("another breakpoint was inserted on top of "
7034 "a permanent breakpoint"));
7036 memset (&b
->loc
->target_info
, 0, sizeof (b
->loc
->target_info
));
7037 b
->loc
->target_info
.placed_address
= b
->loc
->address
;
7038 if (b
->type
== bp_hardware_breakpoint
)
7039 val
= target_insert_hw_breakpoint (&b
->loc
->target_info
);
7041 val
= target_insert_breakpoint (&b
->loc
->target_info
);
7043 /* If there was an error in the insert, print a message, then stop execution. */
7046 struct ui_file
*tmp_error_stream
= mem_fileopen ();
7047 make_cleanup_ui_file_delete (tmp_error_stream
);
7050 if (b
->type
== bp_hardware_breakpoint
)
7052 fprintf_unfiltered (tmp_error_stream
,
7053 "Cannot insert hardware breakpoint %d.\n"
7054 "You may have requested too many hardware breakpoints.\n",
7059 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
7060 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
7061 deprecated_print_address_numeric (b
->loc
->address
, 1, tmp_error_stream
);
7062 fprintf_filtered (tmp_error_stream
, ": %s.\n",
7063 safe_strerror (val
));
7066 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
7067 target_terminal_ours_for_output ();
7068 error_stream(tmp_error_stream
);
7071 b
->loc
->inserted
= 1;
7075 free_command_lines (&bpt
->commands
);
7078 if (bpt
->cond_string
!= NULL
)
7079 xfree (bpt
->cond_string
);
7080 if (bpt
->addr_string
!= NULL
)
7081 xfree (bpt
->addr_string
);
7082 if (bpt
->exp
!= NULL
)
7084 if (bpt
->exp_string
!= NULL
)
7085 xfree (bpt
->exp_string
);
7086 if (bpt
->val
!= NULL
)
7087 value_free (bpt
->val
);
7088 if (bpt
->source_file
!= NULL
)
7089 xfree (bpt
->source_file
);
7090 if (bpt
->dll_pathname
!= NULL
)
7091 xfree (bpt
->dll_pathname
);
7092 if (bpt
->triggered_dll_pathname
!= NULL
)
7093 xfree (bpt
->triggered_dll_pathname
);
7094 if (bpt
->exec_pathname
!= NULL
)
7095 xfree (bpt
->exec_pathname
);
7097 /* Be sure no bpstat's are pointing at it after it's been freed. */
7098 /* FIXME, how can we find all bpstat's?
7099 We just check stop_bpstat for now. */
7100 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
7101 if (bs
->breakpoint_at
== bpt
)
7103 bs
->breakpoint_at
= NULL
;
7105 /* bs->commands will be freed later. */
7107 /* On the chance that someone will soon try again to delete this same
7108 bp, we mark it as deleted before freeing its storage. */
7109 bpt
->type
= bp_none
;
7116 do_delete_breakpoint_cleanup (void *b
)
7118 delete_breakpoint (b
);
7122 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7124 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7128 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
7130 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
7134 delete_command (char *arg
, int from_tty
)
7136 struct breakpoint
*b
, *temp
;
7142 int breaks_to_delete
= 0;
7144 /* Delete all breakpoints if no argument.
7145 Do not delete internal or call-dummy breakpoints, these
7146 have to be deleted with an explicit breakpoint number argument. */
7149 if (b
->type
!= bp_call_dummy
&&
7150 b
->type
!= bp_shlib_event
&&
7151 b
->type
!= bp_thread_event
&&
7152 b
->type
!= bp_overlay_event
&&
7155 breaks_to_delete
= 1;
7160 /* Ask user only if there are some breakpoints to delete. */
7162 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7164 ALL_BREAKPOINTS_SAFE (b
, temp
)
7166 if (b
->type
!= bp_call_dummy
&&
7167 b
->type
!= bp_shlib_event
&&
7168 b
->type
!= bp_thread_event
&&
7169 b
->type
!= bp_overlay_event
&&
7171 delete_breakpoint (b
);
7176 map_breakpoint_numbers (arg
, delete_breakpoint
);
7179 /* Reset a breakpoint given it's struct breakpoint * BINT.
7180 The value we return ends up being the return value from catch_errors.
7181 Unused in this case. */
7184 breakpoint_re_set_one (void *bint
)
7186 /* get past catch_errs */
7187 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7191 int *not_found_ptr
= NULL
;
7192 struct symtabs_and_lines sals
;
7194 enum enable_state save_enable
;
7199 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7203 case bp_hardware_breakpoint
:
7205 case bp_catch_unload
:
7206 if (b
->addr_string
== NULL
)
7208 /* Anything without a string can't be re-set. */
7209 delete_breakpoint (b
);
7212 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
7214 ``And a hack it is, although Apple's Darwin version of GDB
7215 contains an almost identical hack to implement a "future
7216 break" command. It seems to work in many real world cases,
7217 but it is easy to come up with a test case where the patch
7218 doesn't help at all.''
7220 ``It seems that the way GDB implements breakpoints - in -
7221 shared - libraries was designed for a.out shared library
7222 systems (SunOS 4) where shared libraries were loaded at a
7223 fixed address in memory. Since ELF shared libraries can (and
7224 will) be loaded at any address in memory, things break.
7225 Fixing this is not trivial. Therefore, I'm not sure whether
7226 we should add this hack to the branch only. I cannot
7227 guarantee that things will be fixed on the trunk in the near
7230 In case we have a problem, disable this breakpoint. We'll
7231 restore its status if we succeed. Don't disable a
7232 shlib_disabled breakpoint though. There's a fair chance we
7233 can't re-set it if the shared library it's in hasn't been
7239 save_enable
= b
->enable_state
;
7240 if (b
->enable_state
!= bp_shlib_disabled
)
7241 b
->enable_state
= bp_disabled
;
7243 /* If resetting a shlib-disabled breakpoint, we don't want to
7244 see an error message if it is not found since we will expect
7245 this to occur until the shared library is finally reloaded.
7246 We accomplish this by giving decode_line_1 a pointer to use
7247 for silent notification that the symbol is not found. */
7248 not_found_ptr
= ¬_found
;
7250 set_language (b
->language
);
7251 input_radix
= b
->input_radix
;
7253 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7255 for (i
= 0; i
< sals
.nelts
; i
++)
7257 resolve_sal_pc (&sals
.sals
[i
]);
7259 /* Reparse conditions, they might contain references to the
7261 if (b
->cond_string
!= NULL
)
7267 /* Avoid re-freeing b->exp if an error during the call
7271 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
7274 /* We need to re-set the breakpoint if the address changes... */
7275 if (b
->loc
->address
!= sals
.sals
[i
].pc
7276 /* ...or new and old breakpoints both have source files, and
7277 the source file name or the line number changes... */
7278 || (b
->source_file
!= NULL
7279 && sals
.sals
[i
].symtab
!= NULL
7280 && (strcmp (b
->source_file
, sals
.sals
[i
].symtab
->filename
) != 0
7281 || b
->line_number
!= sals
.sals
[i
].line
)
7283 /* ...or we switch between having a source file and not having
7285 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
7288 if (b
->source_file
!= NULL
)
7289 xfree (b
->source_file
);
7290 if (sals
.sals
[i
].symtab
== NULL
)
7291 b
->source_file
= NULL
;
7294 savestring (sals
.sals
[i
].symtab
->filename
,
7295 strlen (sals
.sals
[i
].symtab
->filename
));
7296 b
->line_number
= sals
.sals
[i
].line
;
7297 b
->loc
->requested_address
= sals
.sals
[i
].pc
;
7299 = adjust_breakpoint_address (b
->loc
->requested_address
,
7302 /* Used to check for duplicates here, but that can
7303 cause trouble, as it doesn't check for disabled
7308 /* Might be better to do this just once per breakpoint_re_set,
7309 rather than once for every breakpoint. */
7310 breakpoints_changed ();
7312 b
->loc
->section
= sals
.sals
[i
].section
;
7313 b
->enable_state
= save_enable
; /* Restore it, this worked. */
7316 /* Now that this is re-enabled, check_duplicates
7318 check_duplicates (b
);
7325 case bp_hardware_watchpoint
:
7326 case bp_read_watchpoint
:
7327 case bp_access_watchpoint
:
7328 innermost_block
= NULL
;
7329 /* The issue arises of what context to evaluate this in. The
7330 same one as when it was set, but what does that mean when
7331 symbols have been re-read? We could save the filename and
7332 functionname, but if the context is more local than that, the
7333 best we could do would be something like how many levels deep
7334 and which index at that particular level, but that's going to
7335 be less stable than filenames or function names. */
7337 /* So for now, just use a global context. */
7341 /* Avoid re-freeing b->exp if an error during the call to
7342 parse_expression. */
7345 b
->exp
= parse_expression (b
->exp_string
);
7346 b
->exp_valid_block
= innermost_block
;
7347 mark
= value_mark ();
7350 value_free (b
->val
);
7351 /* Avoid re-freeing b->val if an error during the call to
7352 evaluate_expression. */
7355 b
->val
= evaluate_expression (b
->exp
);
7356 release_value (b
->val
);
7357 if (value_lazy (b
->val
) && breakpoint_enabled (b
))
7358 value_fetch_lazy (b
->val
);
7360 if (b
->cond_string
!= NULL
)
7366 /* Avoid re-freeing b->exp if an error during the call
7370 b
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
7372 if (breakpoint_enabled (b
))
7374 value_free_to_mark (mark
);
7376 case bp_catch_catch
:
7377 case bp_catch_throw
:
7379 /* We needn't really do anything to reset these, since the mask
7380 that requests them is unaffected by e.g., new libraries being
7383 case bp_catch_vfork
:
7388 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7390 /* Delete longjmp and overlay event breakpoints; they will be
7391 reset later by breakpoint_re_set. */
7393 case bp_longjmp_resume
:
7394 case bp_overlay_event
:
7395 delete_breakpoint (b
);
7398 /* This breakpoint is special, it's set up when the inferior
7399 starts and we really don't want to touch it. */
7400 case bp_shlib_event
:
7402 /* Like bp_shlib_event, this breakpoint type is special.
7403 Once it is set up, we do not want to touch it. */
7404 case bp_thread_event
:
7406 /* Keep temporary breakpoints, which can be encountered when we step
7407 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7408 Otherwise these should have been blown away via the cleanup chain
7409 or by breakpoint_init_inferior when we rerun the executable. */
7412 case bp_watchpoint_scope
:
7414 case bp_step_resume
:
7421 /* Re-set all breakpoints after symbols have been re-loaded. */
7423 breakpoint_re_set (void)
7425 struct breakpoint
*b
, *temp
;
7426 enum language save_language
;
7427 int save_input_radix
;
7429 save_language
= current_language
->la_language
;
7430 save_input_radix
= input_radix
;
7431 ALL_BREAKPOINTS_SAFE (b
, temp
)
7433 /* Format possible error msg */
7434 char *message
= xstrprintf ("Error in re-setting breakpoint %d:\n",
7436 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7437 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7438 do_cleanups (cleanups
);
7440 set_language (save_language
);
7441 input_radix
= save_input_radix
;
7443 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
7445 create_longjmp_breakpoint ("longjmp");
7446 create_longjmp_breakpoint ("_longjmp");
7447 create_longjmp_breakpoint ("siglongjmp");
7448 create_longjmp_breakpoint ("_siglongjmp");
7449 create_longjmp_breakpoint (NULL
);
7452 create_overlay_event_breakpoint ("_ovly_debug_event");
7455 /* Reset the thread number of this breakpoint:
7457 - If the breakpoint is for all threads, leave it as-is.
7458 - Else, reset it to the current thread for inferior_ptid. */
7460 breakpoint_re_set_thread (struct breakpoint
*b
)
7462 if (b
->thread
!= -1)
7464 if (in_thread_list (inferior_ptid
))
7465 b
->thread
= pid_to_thread_id (inferior_ptid
);
7469 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7470 If from_tty is nonzero, it prints a message to that effect,
7471 which ends with a period (no newline). */
7474 set_ignore_count (int bptnum
, int count
, int from_tty
)
7476 struct breakpoint
*b
;
7482 if (b
->number
== bptnum
)
7484 b
->ignore_count
= count
;
7488 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7490 else if (count
== 1)
7491 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7494 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7497 breakpoints_changed ();
7498 breakpoint_modify_event (b
->number
);
7502 error (_("No breakpoint number %d."), bptnum
);
7505 /* Clear the ignore counts of all breakpoints. */
7507 breakpoint_clear_ignore_counts (void)
7509 struct breakpoint
*b
;
7512 b
->ignore_count
= 0;
7515 /* Command to set ignore-count of breakpoint N to COUNT. */
7518 ignore_command (char *args
, int from_tty
)
7524 error_no_arg (_("a breakpoint number"));
7526 num
= get_number (&p
);
7528 error (_("bad breakpoint number: '%s'"), args
);
7530 error (_("Second argument (specified ignore-count) is missing."));
7532 set_ignore_count (num
,
7533 longest_to_int (value_as_long (parse_and_eval (p
))),
7536 printf_filtered ("\n");
7539 /* Call FUNCTION on each of the breakpoints
7540 whose numbers are given in ARGS. */
7543 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7548 struct breakpoint
*b
, *tmp
;
7552 error_no_arg (_("one or more breakpoint numbers"));
7559 num
= get_number_or_range (&p1
);
7562 warning (_("bad breakpoint number at or near '%s'"), p
);
7566 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7567 if (b
->number
== num
)
7569 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7572 if (related_breakpoint
)
7573 function (related_breakpoint
);
7577 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7583 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7584 If from_tty is nonzero, it prints a message to that effect,
7585 which ends with a period (no newline). */
7588 disable_breakpoint (struct breakpoint
*bpt
)
7590 /* Never disable a watchpoint scope breakpoint; we want to
7591 hit them when we leave scope so we can delete both the
7592 watchpoint and its scope breakpoint at that time. */
7593 if (bpt
->type
== bp_watchpoint_scope
)
7596 /* You can't disable permanent breakpoints. */
7597 if (bpt
->enable_state
== bp_permanent
)
7600 bpt
->enable_state
= bp_disabled
;
7602 check_duplicates (bpt
);
7604 if (deprecated_modify_breakpoint_hook
)
7605 deprecated_modify_breakpoint_hook (bpt
);
7606 breakpoint_modify_event (bpt
->number
);
7610 disable_command (char *args
, int from_tty
)
7612 struct breakpoint
*bpt
;
7614 ALL_BREAKPOINTS (bpt
)
7618 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7623 case bp_catch_unload
:
7625 case bp_catch_vfork
:
7627 case bp_catch_catch
:
7628 case bp_catch_throw
:
7629 case bp_hardware_breakpoint
:
7631 case bp_hardware_watchpoint
:
7632 case bp_read_watchpoint
:
7633 case bp_access_watchpoint
:
7634 disable_breakpoint (bpt
);
7639 map_breakpoint_numbers (args
, disable_breakpoint
);
7643 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7645 int target_resources_ok
, other_type_used
;
7648 if (bpt
->type
== bp_hardware_breakpoint
)
7651 i
= hw_breakpoint_used_count ();
7652 target_resources_ok
=
7653 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7655 if (target_resources_ok
== 0)
7656 error (_("No hardware breakpoint support in the target."));
7657 else if (target_resources_ok
< 0)
7658 error (_("Hardware breakpoints used exceeds limit."));
7663 if (bpt
->enable_state
!= bp_enabled
)
7665 /* When enabling a pending breakpoint, we need to check if the breakpoint
7666 is resolvable since shared libraries could have been loaded
7667 after the breakpoint was disabled. */
7668 breakpoints_changed ();
7669 if (resolve_pending_breakpoint (bpt
) == GDB_RC_OK
)
7671 delete_breakpoint (bpt
);
7674 bpt
->enable_state
= bp_enabled
;
7675 bpt
->disposition
= disposition
;
7678 else /* Not a pending breakpoint. */
7680 if (bpt
->enable_state
!= bp_permanent
)
7681 bpt
->enable_state
= bp_enabled
;
7682 bpt
->disposition
= disposition
;
7683 check_duplicates (bpt
);
7684 breakpoints_changed ();
7686 if (bpt
->type
== bp_watchpoint
||
7687 bpt
->type
== bp_hardware_watchpoint
||
7688 bpt
->type
== bp_read_watchpoint
||
7689 bpt
->type
== bp_access_watchpoint
)
7691 struct frame_id saved_frame_id
;
7693 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7694 if (bpt
->exp_valid_block
!= NULL
)
7696 struct frame_info
*fr
=
7697 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7700 printf_filtered (_("\
7701 Cannot enable watchpoint %d because the block in which its expression\n\
7702 is valid is not currently in scope.\n"), bpt
->number
);
7703 bpt
->enable_state
= bp_disabled
;
7709 value_free (bpt
->val
);
7710 mark
= value_mark ();
7711 bpt
->val
= evaluate_expression (bpt
->exp
);
7712 release_value (bpt
->val
);
7713 if (value_lazy (bpt
->val
))
7714 value_fetch_lazy (bpt
->val
);
7716 if (bpt
->type
== bp_hardware_watchpoint
||
7717 bpt
->type
== bp_read_watchpoint
||
7718 bpt
->type
== bp_access_watchpoint
)
7720 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7721 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7723 /* Hack around 'unused var' error for some targets here */
7724 (void) mem_cnt
, (void) i
;
7725 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7726 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7727 /* we can consider of type is bp_hardware_watchpoint, convert to
7728 bp_watchpoint in the following condition */
7729 if (target_resources_ok
< 0)
7731 printf_filtered (_("\
7732 Cannot enable watchpoint %d because target watch resources\n\
7733 have been allocated for other watchpoints.\n"), bpt
->number
);
7734 bpt
->enable_state
= bp_disabled
;
7735 value_free_to_mark (mark
);
7740 select_frame (frame_find_by_id (saved_frame_id
));
7741 value_free_to_mark (mark
);
7745 if (deprecated_modify_breakpoint_hook
)
7746 deprecated_modify_breakpoint_hook (bpt
);
7747 breakpoint_modify_event (bpt
->number
);
7751 enable_breakpoint (struct breakpoint
*bpt
)
7753 do_enable_breakpoint (bpt
, bpt
->disposition
);
7756 /* The enable command enables the specified breakpoints (or all defined
7757 breakpoints) so they once again become (or continue to be) effective
7758 in stopping the inferior. */
7761 enable_command (char *args
, int from_tty
)
7763 struct breakpoint
*bpt
;
7765 ALL_BREAKPOINTS (bpt
)
7769 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7774 case bp_catch_unload
:
7776 case bp_catch_vfork
:
7778 case bp_catch_catch
:
7779 case bp_catch_throw
:
7780 case bp_hardware_breakpoint
:
7782 case bp_hardware_watchpoint
:
7783 case bp_read_watchpoint
:
7784 case bp_access_watchpoint
:
7785 enable_breakpoint (bpt
);
7790 map_breakpoint_numbers (args
, enable_breakpoint
);
7794 enable_once_breakpoint (struct breakpoint
*bpt
)
7796 do_enable_breakpoint (bpt
, disp_disable
);
7800 enable_once_command (char *args
, int from_tty
)
7802 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7806 enable_delete_breakpoint (struct breakpoint
*bpt
)
7808 do_enable_breakpoint (bpt
, disp_del
);
7812 enable_delete_command (char *args
, int from_tty
)
7814 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7818 set_breakpoint_cmd (char *args
, int from_tty
)
7823 show_breakpoint_cmd (char *args
, int from_tty
)
7827 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7829 struct symtabs_and_lines
7830 decode_line_spec_1 (char *string
, int funfirstline
)
7832 struct symtabs_and_lines sals
;
7834 error (_("Empty line specification."));
7835 if (default_breakpoint_valid
)
7836 sals
= decode_line_1 (&string
, funfirstline
,
7837 default_breakpoint_symtab
,
7838 default_breakpoint_line
,
7839 (char ***) NULL
, NULL
);
7841 sals
= decode_line_1 (&string
, funfirstline
,
7842 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7844 error (_("Junk at end of line specification: %s"), string
);
7848 /* Create and insert a raw software breakpoint at PC. Return an
7849 identifier, which should be used to remove the breakpoint later.
7850 In general, places which call this should be using something on the
7851 breakpoint chain instead; this function should be eliminated
7855 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7857 struct bp_target_info
*bp_tgt
;
7859 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7860 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7862 bp_tgt
->placed_address
= pc
;
7863 if (target_insert_breakpoint (bp_tgt
) != 0)
7865 /* Could not insert the breakpoint. */
7873 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7876 deprecated_remove_raw_breakpoint (void *bp
)
7878 struct bp_target_info
*bp_tgt
= bp
;
7881 ret
= target_remove_breakpoint (bp_tgt
);
7887 /* One (or perhaps two) breakpoints used for software single stepping. */
7889 static void *single_step_breakpoints
[2];
7891 /* Create and insert a breakpoint for software single step. */
7894 insert_single_step_breakpoint (CORE_ADDR next_pc
)
7898 if (single_step_breakpoints
[0] == NULL
)
7899 bpt_p
= &single_step_breakpoints
[0];
7902 gdb_assert (single_step_breakpoints
[1] == NULL
);
7903 bpt_p
= &single_step_breakpoints
[1];
7906 /* NOTE drow/2006-04-11: A future improvement to this function would be
7907 to only create the breakpoints once, and actually put them on the
7908 breakpoint chain. That would let us use set_raw_breakpoint. We could
7909 adjust the addresses each time they were needed. Doing this requires
7910 corresponding changes elsewhere where single step breakpoints are
7911 handled, however. So, for now, we use this. */
7913 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
7915 error (_("Could not insert single-step breakpoint at 0x%s"),
7916 paddr_nz (next_pc
));
7919 /* Remove and delete any breakpoints used for software single step. */
7922 remove_single_step_breakpoints (void)
7924 gdb_assert (single_step_breakpoints
[0] != NULL
);
7926 /* See insert_single_step_breakpoint for more about this deprecated
7928 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
7929 single_step_breakpoints
[0] = NULL
;
7931 if (single_step_breakpoints
[1] != NULL
)
7933 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
7934 single_step_breakpoints
[1] = NULL
;
7938 /* Check whether a software single-step breakpoint is inserted at PC. */
7941 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
7945 for (i
= 0; i
< 2; i
++)
7947 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
7948 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
7956 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
7957 It is defined as a macro to prevent duplication.
7958 COMMAND should be a string constant containing the name of the command. */
7959 #define BREAK_ARGS_HELP(command) \
7960 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
7961 LOCATION may be a line number, function name, or \"*\" and an address.\n\
7962 If a line number is specified, break at start of code for that line.\n\
7963 If a function is specified, break at start of code for that function.\n\
7964 If an address is specified, break at that exact address.\n\
7965 With no LOCATION, uses current execution address of selected stack frame.\n\
7966 This is useful for breaking on return to a stack frame.\n\
7968 THREADNUM is the number from \"info threads\".\n\
7969 CONDITION is a boolean expression.\n\
7971 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7973 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
7976 _initialize_breakpoint (void)
7978 static struct cmd_list_element
*breakpoint_set_cmdlist
;
7979 static struct cmd_list_element
*breakpoint_show_cmdlist
;
7980 struct cmd_list_element
*c
;
7982 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
7984 breakpoint_chain
= 0;
7985 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7986 before a breakpoint is set. */
7987 breakpoint_count
= 0;
7989 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
7990 Set ignore-count of breakpoint number N to COUNT.\n\
7991 Usage is `ignore N COUNT'."));
7993 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7995 add_com ("commands", class_breakpoint
, commands_command
, _("\
7996 Set commands to be executed when a breakpoint is hit.\n\
7997 Give breakpoint number as argument after \"commands\".\n\
7998 With no argument, the targeted breakpoint is the last one set.\n\
7999 The commands themselves follow starting on the next line.\n\
8000 Type a line containing \"end\" to indicate the end of them.\n\
8001 Give \"silent\" as the first line to make the breakpoint silent;\n\
8002 then no output is printed when it is hit, except what the commands print."));
8004 add_com ("condition", class_breakpoint
, condition_command
, _("\
8005 Specify breakpoint number N to break only if COND is true.\n\
8006 Usage is `condition N COND', where N is an integer and COND is an\n\
8007 expression to be evaluated whenever breakpoint N is reached."));
8009 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8010 Set a temporary breakpoint.\n\
8011 Like \"break\" except the breakpoint is only temporary,\n\
8012 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8013 by using \"enable delete\" on the breakpoint number.\n\
8015 BREAK_ARGS_HELP ("tbreak")));
8016 set_cmd_completer (c
, location_completer
);
8018 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8019 Set a hardware assisted breakpoint.\n\
8020 Like \"break\" except the breakpoint requires hardware support,\n\
8021 some target hardware may not have this support.\n\
8023 BREAK_ARGS_HELP ("hbreak")));
8024 set_cmd_completer (c
, location_completer
);
8026 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8027 Set a temporary hardware assisted breakpoint.\n\
8028 Like \"hbreak\" except the breakpoint is only temporary,\n\
8029 so it will be deleted when hit.\n\
8031 BREAK_ARGS_HELP ("thbreak")));
8032 set_cmd_completer (c
, location_completer
);
8034 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8035 Enable some breakpoints.\n\
8036 Give breakpoint numbers (separated by spaces) as arguments.\n\
8037 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8038 This is used to cancel the effect of the \"disable\" command.\n\
8039 With a subcommand you can enable temporarily."),
8040 &enablelist
, "enable ", 1, &cmdlist
);
8042 add_com ("ab", class_breakpoint
, enable_command
, _("\
8043 Enable some breakpoints.\n\
8044 Give breakpoint numbers (separated by spaces) as arguments.\n\
8045 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8046 This is used to cancel the effect of the \"disable\" command.\n\
8047 With a subcommand you can enable temporarily."));
8049 add_com_alias ("en", "enable", class_breakpoint
, 1);
8051 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8052 Enable some breakpoints.\n\
8053 Give breakpoint numbers (separated by spaces) as arguments.\n\
8054 This is used to cancel the effect of the \"disable\" command.\n\
8055 May be abbreviated to simply \"enable\".\n"),
8056 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8058 add_cmd ("once", no_class
, enable_once_command
, _("\
8059 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8060 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8063 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8064 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8065 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8068 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8069 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8070 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8073 add_cmd ("once", no_class
, enable_once_command
, _("\
8074 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8075 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8078 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8079 Disable some breakpoints.\n\
8080 Arguments are breakpoint numbers with spaces in between.\n\
8081 To disable all breakpoints, give no argument.\n\
8082 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8083 &disablelist
, "disable ", 1, &cmdlist
);
8084 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8085 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8087 add_com ("sb", class_breakpoint
, disable_command
, _("\
8088 Disable some breakpoints.\n\
8089 Arguments are breakpoint numbers with spaces in between.\n\
8090 To disable all breakpoints, give no argument.\n\
8091 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8093 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8094 Disable some breakpoints.\n\
8095 Arguments are breakpoint numbers with spaces in between.\n\
8096 To disable all breakpoints, give no argument.\n\
8097 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8098 This command may be abbreviated \"disable\"."),
8101 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8102 Delete some breakpoints or auto-display expressions.\n\
8103 Arguments are breakpoint numbers with spaces in between.\n\
8104 To delete all breakpoints, give no argument.\n\
8106 Also a prefix command for deletion of other GDB objects.\n\
8107 The \"unset\" command is also an alias for \"delete\"."),
8108 &deletelist
, "delete ", 1, &cmdlist
);
8109 add_com_alias ("d", "delete", class_breakpoint
, 1);
8110 add_com_alias ("del", "delete", class_breakpoint
, 1);
8112 add_com ("db", class_breakpoint
, delete_command
, _("\
8113 Delete some breakpoints.\n\
8114 Arguments are breakpoint numbers with spaces in between.\n\
8115 To delete all breakpoints, give no argument.\n"));
8117 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8118 Delete some breakpoints or auto-display expressions.\n\
8119 Arguments are breakpoint numbers with spaces in between.\n\
8120 To delete all breakpoints, give no argument.\n\
8121 This command may be abbreviated \"delete\"."),
8124 add_com ("clear", class_breakpoint
, clear_command
, _("\
8125 Clear breakpoint at specified line or function.\n\
8126 Argument may be line number, function name, or \"*\" and an address.\n\
8127 If line number is specified, all breakpoints in that line are cleared.\n\
8128 If function is specified, breakpoints at beginning of function are cleared.\n\
8129 If an address is specified, breakpoints at that address are cleared.\n\
8131 With no argument, clears all breakpoints in the line that the selected frame\n\
8134 See also the \"delete\" command which clears breakpoints by number."));
8136 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8137 Set breakpoint at specified line or function.\n"
8138 BREAK_ARGS_HELP ("break")));
8139 set_cmd_completer (c
, location_completer
);
8141 add_com_alias ("b", "break", class_run
, 1);
8142 add_com_alias ("br", "break", class_run
, 1);
8143 add_com_alias ("bre", "break", class_run
, 1);
8144 add_com_alias ("brea", "break", class_run
, 1);
8148 add_com_alias ("ba", "break", class_breakpoint
, 1);
8149 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8154 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8155 Break in function/address or break at a line in the current file."),
8156 &stoplist
, "stop ", 1, &cmdlist
);
8157 add_cmd ("in", class_breakpoint
, stopin_command
,
8158 _("Break in function or address."), &stoplist
);
8159 add_cmd ("at", class_breakpoint
, stopat_command
,
8160 _("Break at a line in the current file."), &stoplist
);
8161 add_com ("status", class_info
, breakpoints_info
, _("\
8162 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8163 The \"Type\" column indicates one of:\n\
8164 \tbreakpoint - normal breakpoint\n\
8165 \twatchpoint - watchpoint\n\
8166 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8167 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8168 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8169 address and file/line number respectively.\n\
8171 Convenience variable \"$_\" and default examine address for \"x\"\n\
8172 are set to the address of the last breakpoint listed.\n\n\
8173 Convenience variable \"$bpnum\" contains the number of the last\n\
8177 add_info ("breakpoints", breakpoints_info
, _("\
8178 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8179 The \"Type\" column indicates one of:\n\
8180 \tbreakpoint - normal breakpoint\n\
8181 \twatchpoint - watchpoint\n\
8182 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8183 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8184 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8185 address and file/line number respectively.\n\
8187 Convenience variable \"$_\" and default examine address for \"x\"\n\
8188 are set to the address of the last breakpoint listed.\n\n\
8189 Convenience variable \"$bpnum\" contains the number of the last\n\
8193 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8194 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8195 The \"Type\" column indicates one of:\n\
8196 \tbreakpoint - normal breakpoint\n\
8197 \twatchpoint - watchpoint\n\
8198 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8199 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8200 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8201 address and file/line number respectively.\n\
8203 Convenience variable \"$_\" and default examine address for \"x\"\n\
8204 are set to the address of the last breakpoint listed.\n\n\
8205 Convenience variable \"$bpnum\" contains the number of the last\n\
8208 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8209 Status of all breakpoints, or breakpoint number NUMBER.\n\
8210 The \"Type\" column indicates one of:\n\
8211 \tbreakpoint - normal breakpoint\n\
8212 \twatchpoint - watchpoint\n\
8213 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8214 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8215 \tuntil - internal breakpoint used by the \"until\" command\n\
8216 \tfinish - internal breakpoint used by the \"finish\" command\n\
8217 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8218 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8219 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8220 address and file/line number respectively.\n\
8222 Convenience variable \"$_\" and default examine address for \"x\"\n\
8223 are set to the address of the last breakpoint listed.\n\
8225 Convenience variable \"$bpnum\" contains the number of the last\n\
8227 &maintenanceinfolist
);
8229 add_com ("catch", class_breakpoint
, catch_command
, _("\
8230 Set catchpoints to catch events.\n\
8231 Raised signals may be caught:\n\
8232 \tcatch signal - all signals\n\
8233 \tcatch signal <signame> - a particular signal\n\
8234 Raised exceptions may be caught:\n\
8235 \tcatch throw - all exceptions, when thrown\n\
8236 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8237 \tcatch catch - all exceptions, when caught\n\
8238 \tcatch catch <exceptname> - a particular exception, when caught\n\
8239 Thread or process events may be caught:\n\
8240 \tcatch thread_start - any threads, just after creation\n\
8241 \tcatch thread_exit - any threads, just before expiration\n\
8242 \tcatch thread_join - any threads, just after joins\n\
8243 Process events may be caught:\n\
8244 \tcatch start - any processes, just after creation\n\
8245 \tcatch exit - any processes, just before expiration\n\
8246 \tcatch fork - calls to fork()\n\
8247 \tcatch vfork - calls to vfork()\n\
8248 \tcatch exec - calls to exec()\n\
8249 Dynamically-linked library events may be caught:\n\
8250 \tcatch load - loads of any library\n\
8251 \tcatch load <libname> - loads of a particular library\n\
8252 \tcatch unload - unloads of any library\n\
8253 \tcatch unload <libname> - unloads of a particular library\n\
8254 The act of your program's execution stopping may also be caught:\n\
8256 C++ exceptions may be caught:\n\
8257 \tcatch throw - all exceptions, when thrown\n\
8258 \tcatch catch - all exceptions, when caught\n\
8259 Ada exceptions may be caught:\n\
8260 \tcatch exception - all exceptions, when raised\n\
8261 \tcatch exception <name> - a particular exception, when raised\n\
8262 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8263 \tcatch assert - all failed assertions, when raised\n\
8265 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8266 after a fork or vfork is caught.\n\n\
8267 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8269 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8270 Set temporary catchpoints to catch events.\n\
8271 Args like \"catch\" command.\n\
8272 Like \"catch\" except the catchpoint is only temporary,\n\
8273 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8274 by using \"enable delete\" on the catchpoint number."));
8276 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8277 Set a watchpoint for an expression.\n\
8278 A watchpoint stops execution of your program whenever the value of\n\
8279 an expression changes."));
8280 set_cmd_completer (c
, location_completer
);
8282 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8283 Set a read watchpoint for an expression.\n\
8284 A watchpoint stops execution of your program whenever the value of\n\
8285 an expression is read."));
8286 set_cmd_completer (c
, location_completer
);
8288 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8289 Set a watchpoint for an expression.\n\
8290 A watchpoint stops execution of your program whenever the value of\n\
8291 an expression is either read or written."));
8292 set_cmd_completer (c
, location_completer
);
8294 add_info ("watchpoints", breakpoints_info
,
8295 _("Synonym for ``info breakpoints''."));
8298 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8299 respond to changes - contrary to the description. */
8300 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8301 &can_use_hw_watchpoints
, _("\
8302 Set debugger's willingness to use watchpoint hardware."), _("\
8303 Show debugger's willingness to use watchpoint hardware."), _("\
8304 If zero, gdb will not use hardware for new watchpoints, even if\n\
8305 such is available. (However, any hardware watchpoints that were\n\
8306 created before setting this to nonzero, will continue to use watchpoint\n\
8309 show_can_use_hw_watchpoints
,
8310 &setlist
, &showlist
);
8312 can_use_hw_watchpoints
= 1;
8314 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8315 Breakpoint specific settings\n\
8316 Configure various breakpoint-specific variables such as\n\
8317 pending breakpoint behavior"),
8318 &breakpoint_set_cmdlist
, "set breakpoint ",
8319 0/*allow-unknown*/, &setlist
);
8320 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8321 Breakpoint specific settings\n\
8322 Configure various breakpoint-specific variables such as\n\
8323 pending breakpoint behavior"),
8324 &breakpoint_show_cmdlist
, "show breakpoint ",
8325 0/*allow-unknown*/, &showlist
);
8327 add_setshow_auto_boolean_cmd ("pending", no_class
,
8328 &pending_break_support
, _("\
8329 Set debugger's behavior regarding pending breakpoints."), _("\
8330 Show debugger's behavior regarding pending breakpoints."), _("\
8331 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8332 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8333 an error. If auto, an unrecognized breakpoint location results in a\n\
8334 user-query to see if a pending breakpoint should be created."),
8336 show_pending_break_support
,
8337 &breakpoint_set_cmdlist
,
8338 &breakpoint_show_cmdlist
);
8340 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8342 add_setshow_boolean_cmd ("auto-hw", no_class
,
8343 &automatic_hardware_breakpoints
, _("\
8344 Set automatic usage of hardware breakpoints."), _("\
8345 Show automatic usage of hardware breakpoints."), _("\
8346 If set, the debugger will automatically use hardware breakpoints for\n\
8347 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8348 a warning will be emitted for such breakpoints."),
8350 show_automatic_hardware_breakpoints
,
8351 &breakpoint_set_cmdlist
,
8352 &breakpoint_show_cmdlist
);
8354 automatic_hardware_breakpoints
= 1;