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 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "breakpoint.h"
28 #include "expression.h"
34 #include "gdbthread.h"
37 #include "gdb_string.h"
44 #include "completer.h"
47 #include "cli/cli-script.h"
48 #include "gdb_assert.h"
53 #include "exceptions.h"
58 #include "gdb-events.h"
59 #include "mi/mi-common.h"
61 /* Prototypes for local functions. */
63 static void until_break_command_continuation (struct continuation_arg
*arg
);
65 static void catch_command_1 (char *, int, int);
67 static void enable_delete_command (char *, int);
69 static void enable_delete_breakpoint (struct breakpoint
*);
71 static void enable_once_command (char *, int);
73 static void enable_once_breakpoint (struct breakpoint
*);
75 static void disable_command (char *, int);
77 static void enable_command (char *, int);
79 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
81 static void ignore_command (char *, int);
83 static int breakpoint_re_set_one (void *);
85 static void clear_command (char *, int);
87 static void catch_command (char *, int);
89 static void watch_command (char *, int);
91 static int can_use_hardware_watchpoint (struct value
*);
93 static int break_command_1 (char *, int, int, struct breakpoint
*);
95 static void mention (struct breakpoint
*);
97 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
99 static void check_duplicates (struct breakpoint
*);
101 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
103 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
106 static void describe_other_breakpoints (CORE_ADDR
, asection
*, int);
108 static void breakpoints_info (char *, int);
110 static void breakpoint_1 (int, int);
112 static bpstat
bpstat_alloc (struct bp_location
*, bpstat
);
114 static int breakpoint_cond_eval (void *);
116 static void cleanup_executing_breakpoints (void *);
118 static void commands_command (char *, int);
120 static void condition_command (char *, int);
122 static int get_number_trailer (char **, int);
124 void set_breakpoint_count (int);
133 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
135 static enum print_stop_action
print_it_typical (bpstat
);
137 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
141 enum exception_event_kind kind
;
144 args_for_catchpoint_enable
;
146 static int watchpoint_check (void *);
148 static int cover_target_enable_exception_callback (void *);
150 static void maintenance_info_breakpoints (char *, int);
152 static void create_longjmp_breakpoint (char *);
154 static void create_overlay_event_breakpoint (char *);
156 static int hw_breakpoint_used_count (void);
158 static int hw_watchpoint_used_count (enum bptype
, int *);
160 static void hbreak_command (char *, int);
162 static void thbreak_command (char *, int);
164 static void watch_command_1 (char *, int, int);
166 static void rwatch_command (char *, int);
168 static void awatch_command (char *, int);
170 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
172 static void solib_load_unload_1 (char *hookname
,
175 char *cond_string
, enum bptype bp_kind
);
177 static void create_fork_vfork_event_catchpoint (int tempflag
,
179 enum bptype bp_kind
);
181 static void stop_command (char *arg
, int from_tty
);
183 static void stopin_command (char *arg
, int from_tty
);
185 static void stopat_command (char *arg
, int from_tty
);
187 static char *ep_find_event_name_end (char *arg
);
189 static char *ep_parse_optional_if_clause (char **arg
);
191 static char *ep_parse_optional_filename (char **arg
);
193 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
194 enum exception_event_kind ex_event
,
195 struct symtab_and_line
*sal
);
197 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
198 char *arg
, int tempflag
, int from_tty
);
200 static void tcatch_command (char *arg
, int from_tty
);
202 static void ep_skip_leading_whitespace (char **s
);
204 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
206 static void free_bp_location (struct bp_location
*loc
);
208 /* Prototypes for exported functions. */
210 /* If FALSE, gdb will not use hardware support for watchpoints, even
211 if such is available. */
212 static int can_use_hw_watchpoints
;
215 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
216 struct cmd_list_element
*c
,
219 fprintf_filtered (file
, _("\
220 Debugger's willingness to use watchpoint hardware is %s.\n"),
224 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
225 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
226 for unrecognized breakpoint locations.
227 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
228 static enum auto_boolean pending_break_support
;
230 show_pending_break_support (struct ui_file
*file
, int from_tty
,
231 struct cmd_list_element
*c
,
234 fprintf_filtered (file
, _("\
235 Debugger's behavior regarding pending breakpoints is %s.\n"),
239 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
240 set with "break" but falling in read-only memory.
241 If 0, gdb will warn about such breakpoints, but won't automatically
242 use hardware breakpoints. */
243 static int automatic_hardware_breakpoints
;
245 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
246 struct cmd_list_element
*c
,
249 fprintf_filtered (file
, _("\
250 Automatic usage of hardware breakpoints is %s.\n"),
255 void _initialize_breakpoint (void);
257 extern int addressprint
; /* Print machine addresses? */
259 /* Are we executing breakpoint commands? */
260 static int executing_breakpoint_commands
;
262 /* Are overlay event breakpoints enabled? */
263 static int overlay_events_enabled
;
265 /* Walk the following statement or block through all breakpoints.
266 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
269 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
271 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
272 for (B = breakpoint_chain; \
273 B ? (TMP=B->next, 1): 0; \
276 /* Similar iterators for the low-level breakpoints. */
278 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->next)
280 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
281 for (B = bp_location_chain; \
282 B ? (TMP=B->next, 1): 0; \
285 /* True if breakpoint hit counts should be displayed in breakpoint info. */
287 int show_breakpoint_hit_counts
= 1;
289 /* Chains of all breakpoints defined. */
291 struct breakpoint
*breakpoint_chain
;
293 struct bp_location
*bp_location_chain
;
295 /* Number of last breakpoint made. */
297 int breakpoint_count
;
299 /* Pointer to current exception event record */
300 static struct exception_event_record
*current_exception_event
;
302 /* This function returns a pointer to the string representation of the
303 pathname of the dynamically-linked library that has just been
306 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
307 or undefined results are guaranteed.
309 This string's contents are only valid immediately after the
310 inferior has stopped in the dynamic linker hook, and becomes
311 invalid as soon as the inferior is continued. Clients should make
312 a copy of this string if they wish to continue the inferior and
313 then access the string. */
315 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
316 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
319 /* This function returns a pointer to the string representation of the
320 pathname of the dynamically-linked library that has just been
323 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
324 TRUE, or undefined results are guaranteed.
326 This string's contents are only valid immediately after the
327 inferior has stopped in the dynamic linker hook, and becomes
328 invalid as soon as the inferior is continued. Clients should make
329 a copy of this string if they wish to continue the inferior and
330 then access the string. */
332 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
333 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
336 /* This function is called by the "catch load" command. It allows the
337 debugger to be notified by the dynamic linker when a specified
338 library file (or any library file, if filename is NULL) is loaded. */
340 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
341 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
342 error (_("catch of library loads not yet implemented on this platform"))
345 /* This function is called by the "catch unload" command. It allows
346 the debugger to be notified by the dynamic linker when a specified
347 library file (or any library file, if filename is NULL) is
350 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
351 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
352 error (_("catch of library unloads not yet implemented on this platform"))
355 /* Return whether a breakpoint is an active enabled breakpoint. */
357 breakpoint_enabled (struct breakpoint
*b
)
359 return (b
->enable_state
== bp_enabled
&& !b
->pending
);
362 /* Set breakpoint count to NUM. */
365 set_breakpoint_count (int num
)
367 breakpoint_count
= num
;
368 set_internalvar (lookup_internalvar ("bpnum"),
369 value_from_longest (builtin_type_int
, (LONGEST
) num
));
372 /* Used in run_command to zero the hit count when a new run starts. */
375 clear_breakpoint_hit_counts (void)
377 struct breakpoint
*b
;
383 /* Default address, symtab and line to put a breakpoint at
384 for "break" command with no arg.
385 if default_breakpoint_valid is zero, the other three are
386 not valid, and "break" with no arg is an error.
388 This set by print_stack_frame, which calls set_default_breakpoint. */
390 int default_breakpoint_valid
;
391 CORE_ADDR default_breakpoint_address
;
392 struct symtab
*default_breakpoint_symtab
;
393 int default_breakpoint_line
;
395 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
396 Advance *PP after the string and any trailing whitespace.
398 Currently the string can either be a number or "$" followed by the name
399 of a convenience variable. Making it an expression wouldn't work well
400 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
402 If the string is a NULL pointer, that denotes the last breakpoint.
404 TRAILER is a character which can be found after the number; most
405 commonly this is `-'. If you don't want a trailer, use \0. */
407 get_number_trailer (char **pp
, int trailer
)
409 int retval
= 0; /* default */
413 /* Empty line means refer to the last breakpoint. */
414 return breakpoint_count
;
417 /* Make a copy of the name, so we can null-terminate it
418 to pass to lookup_internalvar(). */
423 while (isalnum (*p
) || *p
== '_')
425 varname
= (char *) alloca (p
- start
+ 1);
426 strncpy (varname
, start
, p
- start
);
427 varname
[p
- start
] = '\0';
428 val
= value_of_internalvar (lookup_internalvar (varname
));
429 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
430 retval
= (int) value_as_long (val
);
433 printf_filtered (_("Convenience variable must have integer value.\n"));
441 while (*p
>= '0' && *p
<= '9')
444 /* There is no number here. (e.g. "cond a == b"). */
446 /* Skip non-numeric token */
447 while (*p
&& !isspace((int) *p
))
449 /* Return zero, which caller must interpret as error. */
455 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
457 /* Trailing junk: return 0 and let caller print error msg. */
458 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
469 /* Like get_number_trailer, but don't allow a trailer. */
471 get_number (char **pp
)
473 return get_number_trailer (pp
, '\0');
476 /* Parse a number or a range.
477 * A number will be of the form handled by get_number.
478 * A range will be of the form <number1> - <number2>, and
479 * will represent all the integers between number1 and number2,
482 * While processing a range, this fuction is called iteratively;
483 * At each call it will return the next value in the range.
485 * At the beginning of parsing a range, the char pointer PP will
486 * be advanced past <number1> and left pointing at the '-' token.
487 * Subsequent calls will not advance the pointer until the range
488 * is completed. The call that completes the range will advance
489 * pointer PP past <number2>.
493 get_number_or_range (char **pp
)
495 static int last_retval
, end_value
;
496 static char *end_ptr
;
497 static int in_range
= 0;
501 /* Default case: pp is pointing either to a solo number,
502 or to the first number of a range. */
503 last_retval
= get_number_trailer (pp
, '-');
508 /* This is the start of a range (<number1> - <number2>).
509 Skip the '-', parse and remember the second number,
510 and also remember the end of the final token. */
514 while (isspace ((int) *end_ptr
))
515 end_ptr
++; /* skip white space */
516 end_value
= get_number (temp
);
517 if (end_value
< last_retval
)
519 error (_("inverted range"));
521 else if (end_value
== last_retval
)
523 /* degenerate range (number1 == number2). Advance the
524 token pointer so that the range will be treated as a
533 error (_("negative value"));
536 /* pp points to the '-' that betokens a range. All
537 number-parsing has already been done. Return the next
538 integer value (one greater than the saved previous value).
539 Do not advance the token pointer 'pp' until the end of range
542 if (++last_retval
== end_value
)
544 /* End of range reached; advance token pointer. */
554 /* condition N EXP -- set break condition of breakpoint N to EXP. */
557 condition_command (char *arg
, int from_tty
)
559 struct breakpoint
*b
;
564 error_no_arg (_("breakpoint number"));
567 bnum
= get_number (&p
);
569 error (_("Bad breakpoint argument: '%s'"), arg
);
572 if (b
->number
== bnum
)
574 struct bp_location
*loc
= b
->loc
;
580 if (b
->cond_string
!= NULL
)
581 xfree (b
->cond_string
);
585 b
->cond_string
= NULL
;
587 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
592 /* I don't know if it matters whether this is the string the user
593 typed in or the decompiled expression. */
594 b
->cond_string
= savestring (arg
, strlen (arg
));
597 b
->loc
->cond
= parse_exp_1 (&arg
,
598 block_for_pc (b
->loc
->address
), 0);
600 error (_("Junk at end of expression"));
603 breakpoints_changed ();
604 breakpoint_modify_event (b
->number
);
608 error (_("No breakpoint number %d."), bnum
);
612 commands_command (char *arg
, int from_tty
)
614 struct breakpoint
*b
;
617 struct command_line
*l
;
619 /* If we allowed this, we would have problems with when to
620 free the storage, if we change the commands currently
623 if (executing_breakpoint_commands
)
624 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
627 bnum
= get_number (&p
);
630 error (_("Unexpected extra arguments following breakpoint number."));
633 if (b
->number
== bnum
)
635 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
637 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
638 l
= read_command_lines (tmpbuf
, from_tty
);
639 do_cleanups (cleanups
);
640 free_command_lines (&b
->commands
);
642 breakpoints_changed ();
643 breakpoint_modify_event (b
->number
);
646 error (_("No breakpoint number %d."), bnum
);
649 /* Like commands_command, but instead of reading the commands from
650 input stream, takes them from an already parsed command structure.
652 This is used by cli-script.c to DTRT with breakpoint commands
653 that are part of if and while bodies. */
654 enum command_control_type
655 commands_from_control_command (char *arg
, struct command_line
*cmd
)
657 struct breakpoint
*b
;
661 /* If we allowed this, we would have problems with when to
662 free the storage, if we change the commands currently
665 if (executing_breakpoint_commands
)
666 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
668 /* An empty string for the breakpoint number means the last
669 breakpoint, but get_number expects a NULL pointer. */
674 bnum
= get_number (&p
);
677 error (_("Unexpected extra arguments following breakpoint number."));
680 if (b
->number
== bnum
)
682 free_command_lines (&b
->commands
);
683 if (cmd
->body_count
!= 1)
684 error (_("Invalid \"commands\" block structure."));
685 /* We need to copy the commands because if/while will free the
686 list after it finishes execution. */
687 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
688 breakpoints_changed ();
689 breakpoint_modify_event (b
->number
);
690 return simple_control
;
692 error (_("No breakpoint number %d."), bnum
);
695 /* Like target_read_memory() but if breakpoints are inserted, return
696 the shadow contents instead of the breakpoints themselves.
698 Read "memory data" from whatever target or inferior we have.
699 Returns zero if successful, errno value if not. EIO is used
700 for address out of bounds. If breakpoints are inserted, returns
701 shadow contents, not the breakpoints themselves. From breakpoint.c. */
704 read_memory_nobpt (CORE_ADDR memaddr
, gdb_byte
*myaddr
, unsigned len
)
707 struct bp_location
*b
;
708 CORE_ADDR bp_addr
= 0;
711 if (gdbarch_breakpoint_from_pc (current_gdbarch
, &bp_addr
, &bp_size
) == NULL
)
712 /* No breakpoints on this machine. */
713 return target_read_memory (memaddr
, myaddr
, len
);
717 if (b
->owner
->type
== bp_none
)
718 warning (_("reading through apparently deleted breakpoint #%d?"),
721 if (b
->loc_type
!= bp_loc_software_breakpoint
)
725 /* Addresses and length of the part of the breakpoint that
727 bp_addr
= b
->target_info
.placed_address
;
728 bp_size
= b
->target_info
.shadow_len
;
730 /* bp isn't valid, or doesn't shadow memory. */
732 if (bp_addr
+ bp_size
<= memaddr
)
733 /* The breakpoint is entirely before the chunk of memory we
736 if (bp_addr
>= memaddr
+ len
)
737 /* The breakpoint is entirely after the chunk of memory we are
740 /* Copy the breakpoint from the shadow contents, and recurse for
741 the things before and after. */
743 /* Offset within shadow_contents. */
746 if (bp_addr
< memaddr
)
748 /* Only copy the second part of the breakpoint. */
749 bp_size
-= memaddr
- bp_addr
;
750 bptoffset
= memaddr
- bp_addr
;
754 if (bp_addr
+ bp_size
> memaddr
+ len
)
756 /* Only copy the first part of the breakpoint. */
757 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
760 memcpy (myaddr
+ bp_addr
- memaddr
,
761 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
763 if (bp_addr
> memaddr
)
765 /* Copy the section of memory before the breakpoint. */
766 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
771 if (bp_addr
+ bp_size
< memaddr
+ len
)
773 /* Copy the section of memory after the breakpoint. */
774 status
= read_memory_nobpt (bp_addr
+ bp_size
,
775 myaddr
+ bp_addr
+ bp_size
- memaddr
,
776 memaddr
+ len
- (bp_addr
+ bp_size
));
783 /* Nothing overlaps. Just call read_memory_noerr. */
784 return target_read_memory (memaddr
, myaddr
, len
);
788 /* A wrapper function for inserting catchpoints. */
790 insert_catchpoint (struct ui_out
*uo
, void *args
)
792 struct breakpoint
*b
= (struct breakpoint
*) args
;
798 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
801 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
804 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
807 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
812 /* Helper routine: free the value chain for a breakpoint (watchpoint). */
815 free_valchain (struct bp_location
*b
)
820 /* Free the saved value chain. We will construct a new one
821 the next time the watchpoint is inserted. */
822 for (v
= b
->owner
->val_chain
; v
; v
= n
)
827 b
->owner
->val_chain
= NULL
;
830 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
831 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
832 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
834 NOTE drow/2003-09-09: This routine could be broken down to an object-style
835 method for each breakpoint or catchpoint type. */
837 insert_bp_location (struct bp_location
*bpt
,
838 struct ui_file
*tmp_error_stream
,
839 int *disabled_breaks
, int *process_warning
,
840 int *hw_breakpoint_error
)
844 /* Permanent breakpoints cannot be inserted or removed. Disabled
845 breakpoints should not be inserted. */
846 if (!breakpoint_enabled (bpt
->owner
))
849 if (bpt
->inserted
|| bpt
->duplicate
)
852 /* Initialize the target-specific information. */
853 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
854 bpt
->target_info
.placed_address
= bpt
->address
;
856 if (bpt
->loc_type
== bp_loc_software_breakpoint
857 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
859 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
861 /* If the explicitly specified breakpoint type
862 is not hardware breakpoint, check the memory map to see
863 if the breakpoint address is in read only memory or not.
864 Two important cases are:
865 - location type is not hardware breakpoint, memory
866 is readonly. We change the type of the location to
868 - location type is hardware breakpoint, memory is read-write.
869 This means we've previously made the location hardware one, but
870 then the memory map changed, so we undo.
872 When breakpoints are removed, remove_breakpoints will
873 use location types we've just set here, the only possible
874 problem is that memory map has changed during running program,
875 but it's not going to work anyway with current gdb. */
876 struct mem_region
*mr
877 = lookup_mem_region (bpt
->target_info
.placed_address
);
881 if (automatic_hardware_breakpoints
)
884 enum bp_loc_type new_type
;
886 if (mr
->attrib
.mode
!= MEM_RW
)
887 new_type
= bp_loc_hardware_breakpoint
;
889 new_type
= bp_loc_software_breakpoint
;
891 if (new_type
!= bpt
->loc_type
)
894 bpt
->loc_type
= new_type
;
897 fprintf_filtered (gdb_stdout
, _("\
898 Note: automatically using hardware breakpoints for read-only addresses.\n"));
903 else if (bpt
->loc_type
== bp_loc_software_breakpoint
904 && mr
->attrib
.mode
!= MEM_RW
)
905 warning (_("cannot set software breakpoint at readonly address %s"),
906 paddr (bpt
->address
));
910 /* First check to see if we have to handle an overlay. */
911 if (overlay_debugging
== ovly_off
912 || bpt
->section
== NULL
913 || !(section_is_overlay (bpt
->section
)))
915 /* No overlay handling: just set the breakpoint. */
917 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
918 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
920 val
= target_insert_breakpoint (&bpt
->target_info
);
924 /* This breakpoint is in an overlay section.
925 Shall we set a breakpoint at the LMA? */
926 if (!overlay_events_enabled
)
928 /* Yes -- overlay event support is not active,
929 so we must try to set a breakpoint at the LMA.
930 This will not work for a hardware breakpoint. */
931 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
932 warning (_("hardware breakpoint %d not supported in overlay!"),
936 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
938 /* Set a software (trap) breakpoint at the LMA. */
939 bpt
->overlay_target_info
= bpt
->target_info
;
940 bpt
->overlay_target_info
.placed_address
= addr
;
941 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
943 fprintf_unfiltered (tmp_error_stream
,
944 "Overlay breakpoint %d failed: in ROM?",
948 /* Shall we set a breakpoint at the VMA? */
949 if (section_is_mapped (bpt
->section
))
951 /* Yes. This overlay section is mapped into memory. */
952 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
953 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
955 val
= target_insert_breakpoint (&bpt
->target_info
);
959 /* No. This breakpoint will not be inserted.
960 No error, but do not mark the bp as 'inserted'. */
967 /* Can't set the breakpoint. */
968 if (solib_address (bpt
->address
))
970 /* See also: disable_breakpoints_in_shlibs. */
972 bpt
->owner
->enable_state
= bp_shlib_disabled
;
973 if (!*disabled_breaks
)
975 fprintf_unfiltered (tmp_error_stream
,
976 "Cannot insert breakpoint %d.\n",
978 fprintf_unfiltered (tmp_error_stream
,
979 "Temporarily disabling shared library breakpoints:\n");
981 *disabled_breaks
= 1;
982 fprintf_unfiltered (tmp_error_stream
,
983 "breakpoint #%d\n", bpt
->owner
->number
);
987 #ifdef ONE_PROCESS_WRITETEXT
988 *process_warning
= 1;
990 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
992 *hw_breakpoint_error
= 1;
993 fprintf_unfiltered (tmp_error_stream
,
994 "Cannot insert hardware breakpoint %d.\n",
999 fprintf_unfiltered (tmp_error_stream
,
1000 "Cannot insert breakpoint %d.\n",
1001 bpt
->owner
->number
);
1002 fprintf_filtered (tmp_error_stream
,
1003 "Error accessing memory address ");
1004 deprecated_print_address_numeric (bpt
->address
, 1, tmp_error_stream
);
1005 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1006 safe_strerror (val
));
1017 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1018 /* NOTE drow/2003-09-08: This state only exists for removing
1019 watchpoints. It's not clear that it's necessary... */
1020 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1022 /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints
1023 based on the expression. Ideally this should happen at a higher level,
1024 and there should be one bp_location for each computed address we
1025 must watch. As soon as a many-to-one mapping is available I'll
1028 int within_current_scope
;
1029 struct value
*mark
= value_mark ();
1031 struct frame_id saved_frame_id
;
1033 /* Save the current frame's ID so we can restore it after
1034 evaluating the watchpoint expression on its own frame. */
1035 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1036 took a frame parameter, so that we didn't have to change the
1038 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1040 /* Determine if the watchpoint is within scope. */
1041 if (bpt
->owner
->exp_valid_block
== NULL
)
1042 within_current_scope
= 1;
1045 struct frame_info
*fi
;
1046 fi
= frame_find_by_id (bpt
->owner
->watchpoint_frame
);
1047 within_current_scope
= (fi
!= NULL
);
1048 if (within_current_scope
)
1052 if (within_current_scope
)
1054 free_valchain (bpt
);
1056 /* Evaluate the expression and cut the chain of values
1057 produced off from the value chain.
1059 Make sure the value returned isn't lazy; we use
1060 laziness to determine what memory GDB actually needed
1061 in order to compute the value of the expression. */
1062 v
= evaluate_expression (bpt
->owner
->exp
);
1064 value_release_to_mark (mark
);
1066 bpt
->owner
->val_chain
= v
;
1069 /* Look at each value on the value chain. */
1070 for (; v
; v
= value_next (v
))
1072 /* If it's a memory location, and GDB actually needed
1073 its contents to evaluate the expression, then we
1075 if (VALUE_LVAL (v
) == lval_memory
1076 && ! value_lazy (v
))
1078 struct type
*vtype
= check_typedef (value_type (v
));
1080 /* We only watch structs and arrays if user asked
1081 for it explicitly, never if they just happen to
1082 appear in the middle of some value chain. */
1083 if (v
== bpt
->owner
->val_chain
1084 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1085 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1090 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
1091 len
= TYPE_LENGTH (value_type (v
));
1093 if (bpt
->owner
->type
== bp_read_watchpoint
)
1095 else if (bpt
->owner
->type
== bp_access_watchpoint
)
1098 val
= target_insert_watchpoint (addr
, len
, type
);
1101 /* Don't exit the loop, try to insert
1102 every value on the value chain. That's
1103 because we will be removing all the
1104 watches below, and removing a
1105 watchpoint we didn't insert could have
1113 /* Failure to insert a watchpoint on any memory value in the
1114 value chain brings us here. */
1117 remove_breakpoint (bpt
, mark_uninserted
);
1118 *hw_breakpoint_error
= 1;
1119 fprintf_unfiltered (tmp_error_stream
,
1120 "Could not insert hardware watchpoint %d.\n",
1121 bpt
->owner
->number
);
1127 printf_filtered (_("\
1128 Hardware watchpoint %d deleted because the program has left the block \n\
1129 in which its expression is valid.\n"),
1130 bpt
->owner
->number
);
1131 if (bpt
->owner
->related_breakpoint
)
1132 bpt
->owner
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1133 bpt
->owner
->disposition
= disp_del_at_next_stop
;
1136 /* Restore the selected frame. */
1137 select_frame (frame_find_by_id (saved_frame_id
));
1142 else if (ep_is_exception_catchpoint (bpt
->owner
))
1144 /* FIXME drow/2003-09-09: This code sets both a catchpoint and a
1145 breakpoint. Once again, it would be better if this was represented
1146 as two bp_locations. */
1148 /* If we get here, we must have a callback mechanism for exception
1149 events -- with g++ style embedded label support, we insert
1150 ordinary breakpoints and not catchpoints. */
1151 val
= target_insert_breakpoint (&bpt
->target_info
);
1154 /* Couldn't set breakpoint for some reason */
1155 fprintf_unfiltered (tmp_error_stream
,
1156 "Cannot insert catchpoint %d; disabling it.\n",
1157 bpt
->owner
->number
);
1158 fprintf_filtered (tmp_error_stream
,
1159 "Error accessing memory address ");
1160 deprecated_print_address_numeric (bpt
->address
, 1, tmp_error_stream
);
1161 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1162 safe_strerror (val
));
1163 bpt
->owner
->enable_state
= bp_disabled
;
1167 /* Bp set, now make sure callbacks are enabled */
1168 /* Format possible error msg */
1169 char *message
= xstrprintf ("Error inserting catchpoint %d:\n",
1170 bpt
->owner
->number
);
1171 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
1173 args_for_catchpoint_enable args
;
1174 args
.kind
= bpt
->owner
->type
== bp_catch_catch
?
1175 EX_EVENT_CATCH
: EX_EVENT_THROW
;
1177 val
= catch_errors (cover_target_enable_exception_callback
,
1178 &args
, message
, RETURN_MASK_ALL
);
1179 do_cleanups (cleanups
);
1180 if (val
!= 0 && val
!= -1)
1183 /* Check if something went wrong; val == 0 can be ignored */
1186 /* something went wrong */
1187 fprintf_unfiltered (tmp_error_stream
,
1188 "Cannot insert catchpoint %d; disabling it.\n",
1189 bpt
->owner
->number
);
1190 bpt
->owner
->enable_state
= bp_disabled
;
1197 else if (bpt
->owner
->type
== bp_catch_fork
1198 || bpt
->owner
->type
== bp_catch_vfork
1199 || bpt
->owner
->type
== bp_catch_exec
)
1201 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1202 bpt
->owner
, RETURN_MASK_ERROR
);
1203 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1204 bpt
->owner
->number
);
1206 bpt
->owner
->enable_state
= bp_disabled
;
1210 /* We've already printed an error message if there was a problem
1211 inserting this catchpoint, and we've disabled the catchpoint,
1212 so just return success. */
1219 /* insert_breakpoints is used when starting or continuing the program.
1220 remove_breakpoints is used when the program stops.
1221 Both return zero if successful,
1222 or an `errno' value if could not write the inferior. */
1225 insert_breakpoints (void)
1227 struct bp_location
*b
, *temp
;
1228 int return_val
= 0; /* return success code. */
1230 int disabled_breaks
= 0;
1231 int hw_breakpoint_error
= 0;
1232 int process_warning
= 0;
1234 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1235 make_cleanup_ui_file_delete (tmp_error_stream
);
1237 /* Explicitly mark the warning -- this will only be printed if
1238 there was an error. */
1239 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1241 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1243 /* Permanent breakpoints cannot be inserted or removed. Disabled
1244 breakpoints should not be inserted. */
1245 if (!breakpoint_enabled (b
->owner
))
1248 /* There is no point inserting thread-specific breakpoints if the
1249 thread no longer exists. */
1250 if (b
->owner
->thread
!= -1
1251 && !valid_thread_id (b
->owner
->thread
))
1254 /* FIXME drow/2003-10-07: This code should be pushed elsewhere when
1255 hardware watchpoints are split into multiple loc breakpoints. */
1256 if ((b
->loc_type
== bp_loc_hardware_watchpoint
1257 || b
->owner
->type
== bp_watchpoint
) && !b
->owner
->val
)
1260 val
= evaluate_expression (b
->owner
->exp
);
1261 release_value (val
);
1262 if (value_lazy (val
))
1263 value_fetch_lazy (val
);
1264 b
->owner
->val
= val
;
1267 val
= insert_bp_location (b
, tmp_error_stream
,
1268 &disabled_breaks
, &process_warning
,
1269 &hw_breakpoint_error
);
1276 /* If a hardware breakpoint or watchpoint was inserted, add a
1277 message about possibly exhausted resources. */
1278 if (hw_breakpoint_error
)
1280 fprintf_unfiltered (tmp_error_stream
,
1281 "Could not insert hardware breakpoints:\n\
1282 You may have requested too many hardware breakpoints/watchpoints.\n");
1284 #ifdef ONE_PROCESS_WRITETEXT
1285 if (process_warning
)
1286 fprintf_unfiltered (tmp_error_stream
,
1287 "The same program may be running in another process.");
1289 target_terminal_ours_for_output ();
1290 error_stream (tmp_error_stream
);
1296 remove_breakpoints (void)
1298 struct bp_location
*b
;
1301 ALL_BP_LOCATIONS (b
)
1305 val
= remove_breakpoint (b
, mark_uninserted
);
1314 remove_hw_watchpoints (void)
1316 struct bp_location
*b
;
1319 ALL_BP_LOCATIONS (b
)
1321 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1323 val
= remove_breakpoint (b
, mark_uninserted
);
1332 reattach_breakpoints (int pid
)
1334 struct bp_location
*b
;
1336 struct cleanup
*old_chain
= save_inferior_ptid ();
1337 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1338 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1340 make_cleanup_ui_file_delete (tmp_error_stream
);
1342 inferior_ptid
= pid_to_ptid (pid
);
1343 ALL_BP_LOCATIONS (b
)
1348 val
= insert_bp_location (b
, tmp_error_stream
,
1349 &dummy1
, &dummy2
, &dummy3
);
1352 do_cleanups (old_chain
);
1357 do_cleanups (old_chain
);
1362 update_breakpoints_after_exec (void)
1364 struct breakpoint
*b
;
1365 struct breakpoint
*temp
;
1367 /* Doing this first prevents the badness of having delete_breakpoint()
1368 write a breakpoint's current "shadow contents" to lift the bp. That
1369 shadow is NOT valid after an exec()! */
1370 mark_breakpoints_out ();
1372 ALL_BREAKPOINTS_SAFE (b
, temp
)
1374 /* Solib breakpoints must be explicitly reset after an exec(). */
1375 if (b
->type
== bp_shlib_event
)
1377 delete_breakpoint (b
);
1381 /* Thread event breakpoints must be set anew after an exec(),
1382 as must overlay event breakpoints. */
1383 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1385 delete_breakpoint (b
);
1389 /* Step-resume breakpoints are meaningless after an exec(). */
1390 if (b
->type
== bp_step_resume
)
1392 delete_breakpoint (b
);
1396 /* Ditto the exception-handling catchpoints. */
1397 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1399 delete_breakpoint (b
);
1403 /* Don't delete an exec catchpoint, because else the inferior
1404 won't stop when it ought!
1406 Similarly, we probably ought to keep vfork catchpoints, 'cause
1407 on this target, we may not be able to stop when the vfork is
1408 seen, but only when the subsequent exec is seen. (And because
1409 deleting fork catchpoints here but not vfork catchpoints will
1410 seem mysterious to users, keep those too.) */
1411 if ((b
->type
== bp_catch_exec
) ||
1412 (b
->type
== bp_catch_vfork
) ||
1413 (b
->type
== bp_catch_fork
))
1418 /* bp_finish is a special case. The only way we ought to be able
1419 to see one of these when an exec() has happened, is if the user
1420 caught a vfork, and then said "finish". Ordinarily a finish just
1421 carries them to the call-site of the current callee, by setting
1422 a temporary bp there and resuming. But in this case, the finish
1423 will carry them entirely through the vfork & exec.
1425 We don't want to allow a bp_finish to remain inserted now. But
1426 we can't safely delete it, 'cause finish_command has a handle to
1427 the bp on a bpstat, and will later want to delete it. There's a
1428 chance (and I've seen it happen) that if we delete the bp_finish
1429 here, that its storage will get reused by the time finish_command
1430 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1431 We really must allow finish_command to delete a bp_finish.
1433 In the absense of a general solution for the "how do we know
1434 it's safe to delete something others may have handles to?"
1435 problem, what we'll do here is just uninsert the bp_finish, and
1436 let finish_command delete it.
1438 (We know the bp_finish is "doomed" in the sense that it's
1439 momentary, and will be deleted as soon as finish_command sees
1440 the inferior stopped. So it doesn't matter that the bp's
1441 address is probably bogus in the new a.out, unlike e.g., the
1442 solib breakpoints.) */
1444 if (b
->type
== bp_finish
)
1449 /* Without a symbolic address, we have little hope of the
1450 pre-exec() address meaning the same thing in the post-exec()
1452 if (b
->addr_string
== NULL
)
1454 delete_breakpoint (b
);
1458 /* FIXME what about longjmp breakpoints? Re-create them here? */
1459 create_overlay_event_breakpoint ("_ovly_debug_event");
1463 detach_breakpoints (int pid
)
1465 struct bp_location
*b
;
1467 struct cleanup
*old_chain
= save_inferior_ptid ();
1469 if (pid
== PIDGET (inferior_ptid
))
1470 error (_("Cannot detach breakpoints of inferior_ptid"));
1472 /* Set inferior_ptid; remove_breakpoint uses this global. */
1473 inferior_ptid
= pid_to_ptid (pid
);
1474 ALL_BP_LOCATIONS (b
)
1478 val
= remove_breakpoint (b
, mark_inserted
);
1481 do_cleanups (old_chain
);
1486 do_cleanups (old_chain
);
1491 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1495 if (b
->owner
->enable_state
== bp_permanent
)
1496 /* Permanent breakpoints cannot be inserted or removed. */
1499 if (b
->owner
->type
== bp_none
)
1500 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1503 if (b
->loc_type
== bp_loc_software_breakpoint
1504 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1506 /* "Normal" instruction breakpoint: either the standard
1507 trap-instruction bp (bp_breakpoint), or a
1508 bp_hardware_breakpoint. */
1510 /* First check to see if we have to handle an overlay. */
1511 if (overlay_debugging
== ovly_off
1512 || b
->section
== NULL
1513 || !(section_is_overlay (b
->section
)))
1515 /* No overlay handling: just remove the breakpoint. */
1517 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1518 val
= target_remove_hw_breakpoint (&b
->target_info
);
1520 val
= target_remove_breakpoint (&b
->target_info
);
1524 /* This breakpoint is in an overlay section.
1525 Did we set a breakpoint at the LMA? */
1526 if (!overlay_events_enabled
)
1528 /* Yes -- overlay event support is not active, so we
1529 should have set a breakpoint at the LMA. Remove it.
1531 /* Ignore any failures: if the LMA is in ROM, we will
1532 have already warned when we failed to insert it. */
1533 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1534 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1536 target_remove_breakpoint (&b
->overlay_target_info
);
1538 /* Did we set a breakpoint at the VMA?
1539 If so, we will have marked the breakpoint 'inserted'. */
1542 /* Yes -- remove it. Previously we did not bother to
1543 remove the breakpoint if the section had been
1544 unmapped, but let's not rely on that being safe. We
1545 don't know what the overlay manager might do. */
1546 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1547 val
= target_remove_hw_breakpoint (&b
->target_info
);
1549 /* However, we should remove *software* breakpoints only
1550 if the section is still mapped, or else we overwrite
1551 wrong code with the saved shadow contents. */
1552 else if (section_is_mapped (b
->section
))
1553 val
= target_remove_breakpoint (&b
->target_info
);
1559 /* No -- not inserted, so no need to remove. No error. */
1565 b
->inserted
= (is
== mark_inserted
);
1567 else if (b
->loc_type
== bp_loc_hardware_watchpoint
1568 && breakpoint_enabled (b
->owner
)
1574 b
->inserted
= (is
== mark_inserted
);
1575 /* Walk down the saved value chain. */
1576 for (v
= b
->owner
->val_chain
; v
; v
= value_next (v
))
1578 /* For each memory reference remove the watchpoint
1580 if (VALUE_LVAL (v
) == lval_memory
1581 && ! value_lazy (v
))
1583 struct type
*vtype
= check_typedef (value_type (v
));
1585 if (v
== b
->owner
->val_chain
1586 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1587 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1592 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
1593 len
= TYPE_LENGTH (value_type (v
));
1595 if (b
->owner
->type
== bp_read_watchpoint
)
1597 else if (b
->owner
->type
== bp_access_watchpoint
)
1600 val
= target_remove_watchpoint (addr
, len
, type
);
1607 /* Failure to remove any of the hardware watchpoints comes here. */
1608 if ((is
== mark_uninserted
) && (b
->inserted
))
1609 warning (_("Could not remove hardware watchpoint %d."),
1612 else if ((b
->owner
->type
== bp_catch_fork
||
1613 b
->owner
->type
== bp_catch_vfork
||
1614 b
->owner
->type
== bp_catch_exec
)
1615 && breakpoint_enabled (b
->owner
)
1619 switch (b
->owner
->type
)
1622 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1624 case bp_catch_vfork
:
1625 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1628 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1631 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1636 b
->inserted
= (is
== mark_inserted
);
1638 else if ((b
->owner
->type
== bp_catch_catch
||
1639 b
->owner
->type
== bp_catch_throw
)
1640 && breakpoint_enabled (b
->owner
)
1643 val
= target_remove_breakpoint (&b
->target_info
);
1646 b
->inserted
= (is
== mark_inserted
);
1652 /* Clear the "inserted" flag in all breakpoints. */
1655 mark_breakpoints_out (void)
1657 struct bp_location
*bpt
;
1659 ALL_BP_LOCATIONS (bpt
)
1663 /* Clear the "inserted" flag in all breakpoints and delete any
1664 breakpoints which should go away between runs of the program.
1666 Plus other such housekeeping that has to be done for breakpoints
1669 Note: this function gets called at the end of a run (by
1670 generic_mourn_inferior) and when a run begins (by
1671 init_wait_for_inferior). */
1676 breakpoint_init_inferior (enum inf_context context
)
1678 struct breakpoint
*b
, *temp
;
1679 struct bp_location
*bpt
;
1681 ALL_BP_LOCATIONS (bpt
)
1684 ALL_BREAKPOINTS_SAFE (b
, temp
)
1689 case bp_watchpoint_scope
:
1691 /* If the call dummy breakpoint is at the entry point it will
1692 cause problems when the inferior is rerun, so we better
1695 Also get rid of scope breakpoints. */
1696 delete_breakpoint (b
);
1700 case bp_hardware_watchpoint
:
1701 case bp_read_watchpoint
:
1702 case bp_access_watchpoint
:
1704 /* Likewise for watchpoints on local expressions. */
1705 if (b
->exp_valid_block
!= NULL
)
1706 delete_breakpoint (b
);
1707 else if (context
== inf_starting
)
1709 /* Reset val field to force reread of starting value
1710 in insert_breakpoints. */
1712 value_free (b
->val
);
1722 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1723 exists at PC. It returns ordinary_breakpoint_here if it's an
1724 ordinary breakpoint, or permanent_breakpoint_here if it's a
1725 permanent breakpoint.
1726 - When continuing from a location with an ordinary breakpoint, we
1727 actually single step once before calling insert_breakpoints.
1728 - When continuing from a localion with a permanent breakpoint, we
1729 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1730 the target, to advance the PC past the breakpoint. */
1732 enum breakpoint_here
1733 breakpoint_here_p (CORE_ADDR pc
)
1735 struct bp_location
*bpt
;
1736 int any_breakpoint_here
= 0;
1738 ALL_BP_LOCATIONS (bpt
)
1740 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1741 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1744 if ((breakpoint_enabled (bpt
->owner
)
1745 || bpt
->owner
->enable_state
== bp_permanent
)
1746 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1748 if (overlay_debugging
1749 && section_is_overlay (bpt
->section
)
1750 && !section_is_mapped (bpt
->section
))
1751 continue; /* unmapped overlay -- can't be a match */
1752 else if (bpt
->owner
->enable_state
== bp_permanent
)
1753 return permanent_breakpoint_here
;
1755 any_breakpoint_here
= 1;
1759 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1763 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1764 but it only returns true if there is actually a breakpoint inserted
1768 breakpoint_inserted_here_p (CORE_ADDR pc
)
1770 struct bp_location
*bpt
;
1772 ALL_BP_LOCATIONS (bpt
)
1774 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1775 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1779 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1781 if (overlay_debugging
1782 && section_is_overlay (bpt
->section
)
1783 && !section_is_mapped (bpt
->section
))
1784 continue; /* unmapped overlay -- can't be a match */
1790 /* Also check for software single-step breakpoints. */
1791 if (single_step_breakpoint_inserted_here_p (pc
))
1797 /* This function returns non-zero iff there is a software breakpoint
1801 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1803 struct bp_location
*bpt
;
1804 int any_breakpoint_here
= 0;
1806 ALL_BP_LOCATIONS (bpt
)
1808 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1811 if ((breakpoint_enabled (bpt
->owner
)
1812 || bpt
->owner
->enable_state
== bp_permanent
)
1814 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1816 if (overlay_debugging
1817 && section_is_overlay (bpt
->section
)
1818 && !section_is_mapped (bpt
->section
))
1819 continue; /* unmapped overlay -- can't be a match */
1825 /* Also check for software single-step breakpoints. */
1826 if (single_step_breakpoint_inserted_here_p (pc
))
1832 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1833 PC is valid for process/thread PTID. */
1836 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1838 struct bp_location
*bpt
;
1841 thread
= pid_to_thread_id (ptid
);
1843 ALL_BP_LOCATIONS (bpt
)
1845 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1846 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1849 if ((breakpoint_enabled (bpt
->owner
)
1850 || bpt
->owner
->enable_state
== bp_permanent
)
1851 && bpt
->address
== pc
1852 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1854 if (overlay_debugging
1855 && section_is_overlay (bpt
->section
)
1856 && !section_is_mapped (bpt
->section
))
1857 continue; /* unmapped overlay -- can't be a match */
1867 /* bpstat stuff. External routines' interfaces are documented
1871 ep_is_catchpoint (struct breakpoint
*ep
)
1874 (ep
->type
== bp_catch_load
)
1875 || (ep
->type
== bp_catch_unload
)
1876 || (ep
->type
== bp_catch_fork
)
1877 || (ep
->type
== bp_catch_vfork
)
1878 || (ep
->type
== bp_catch_exec
)
1879 || (ep
->type
== bp_catch_catch
)
1880 || (ep
->type
== bp_catch_throw
);
1882 /* ??rehrauer: Add more kinds here, as are implemented... */
1886 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1889 (ep
->type
== bp_catch_load
)
1890 || (ep
->type
== bp_catch_unload
);
1894 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1897 (ep
->type
== bp_catch_catch
)
1898 || (ep
->type
== bp_catch_throw
);
1902 bpstat_free (bpstat bs
)
1904 if (bs
->old_val
!= NULL
)
1905 value_free (bs
->old_val
);
1906 free_command_lines (&bs
->commands
);
1910 /* Clear a bpstat so that it says we are not at any breakpoint.
1911 Also free any storage that is part of a bpstat. */
1914 bpstat_clear (bpstat
*bsp
)
1931 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1932 is part of the bpstat is copied as well. */
1935 bpstat_copy (bpstat bs
)
1939 bpstat retval
= NULL
;
1944 for (; bs
!= NULL
; bs
= bs
->next
)
1946 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1947 memcpy (tmp
, bs
, sizeof (*tmp
));
1948 if (bs
->commands
!= NULL
)
1949 tmp
->commands
= copy_command_lines (bs
->commands
);
1950 if (bs
->old_val
!= NULL
)
1951 tmp
->old_val
= value_copy (bs
->old_val
);
1954 /* This is the first thing in the chain. */
1964 /* Find the bpstat associated with this breakpoint */
1967 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1972 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1974 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
1980 /* Find a step_resume breakpoint associated with this bpstat.
1981 (If there are multiple step_resume bp's on the list, this function
1982 will arbitrarily pick one.)
1984 It is an error to use this function if BPSTAT doesn't contain a
1985 step_resume breakpoint.
1987 See wait_for_inferior's use of this function. */
1989 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1993 gdb_assert (bsp
!= NULL
);
1995 current_thread
= pid_to_thread_id (inferior_ptid
);
1997 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1999 if ((bsp
->breakpoint_at
!= NULL
) &&
2000 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2001 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2002 bsp
->breakpoint_at
->owner
->thread
== -1))
2003 return bsp
->breakpoint_at
->owner
;
2006 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2010 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2011 at. *BSP upon return is a bpstat which points to the remaining
2012 breakpoints stopped at (but which is not guaranteed to be good for
2013 anything but further calls to bpstat_num).
2014 Return 0 if passed a bpstat which does not indicate any breakpoints.
2015 Return -1 if stopped at a breakpoint that has been deleted since
2017 Return 1 otherwise. */
2020 bpstat_num (bpstat
*bsp
, int *num
)
2022 struct breakpoint
*b
;
2025 return 0; /* No more breakpoint values */
2027 /* We assume we'll never have several bpstats that
2028 correspond to a single breakpoint -- otherwise,
2029 this function might return the same number more
2030 than once and this will look ugly. */
2031 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2032 *bsp
= (*bsp
)->next
;
2034 return -1; /* breakpoint that's been deleted since */
2036 *num
= b
->number
; /* We have its number */
2040 /* Modify BS so that the actions will not be performed. */
2043 bpstat_clear_actions (bpstat bs
)
2045 for (; bs
!= NULL
; bs
= bs
->next
)
2047 free_command_lines (&bs
->commands
);
2048 if (bs
->old_val
!= NULL
)
2050 value_free (bs
->old_val
);
2056 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2058 cleanup_executing_breakpoints (void *ignore
)
2060 executing_breakpoint_commands
= 0;
2063 /* Execute all the commands associated with all the breakpoints at this
2064 location. Any of these commands could cause the process to proceed
2065 beyond this point, etc. We look out for such changes by checking
2066 the global "breakpoint_proceeded" after each command. */
2069 bpstat_do_actions (bpstat
*bsp
)
2072 struct cleanup
*old_chain
;
2074 /* Avoid endless recursion if a `source' command is contained
2076 if (executing_breakpoint_commands
)
2079 executing_breakpoint_commands
= 1;
2080 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2083 /* Note that (as of this writing), our callers all appear to
2084 be passing us the address of global stop_bpstat. And, if
2085 our calls to execute_control_command cause the inferior to
2086 proceed, that global (and hence, *bsp) will change.
2088 We must be careful to not touch *bsp unless the inferior
2089 has not proceeded. */
2091 /* This pointer will iterate over the list of bpstat's. */
2094 breakpoint_proceeded
= 0;
2095 for (; bs
!= NULL
; bs
= bs
->next
)
2097 struct command_line
*cmd
;
2098 struct cleanup
*this_cmd_tree_chain
;
2100 /* Take ownership of the BSP's command tree, if it has one.
2102 The command tree could legitimately contain commands like
2103 'step' and 'next', which call clear_proceed_status, which
2104 frees stop_bpstat's command tree. To make sure this doesn't
2105 free the tree we're executing out from under us, we need to
2106 take ownership of the tree ourselves. Since a given bpstat's
2107 commands are only executed once, we don't need to copy it; we
2108 can clear the pointer in the bpstat, and make sure we free
2109 the tree when we're done. */
2112 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2116 execute_control_command (cmd
);
2118 if (breakpoint_proceeded
)
2124 /* We can free this command tree now. */
2125 do_cleanups (this_cmd_tree_chain
);
2127 if (breakpoint_proceeded
)
2128 /* The inferior is proceeded by the command; bomb out now.
2129 The bpstat chain has been blown away by wait_for_inferior.
2130 But since execution has stopped again, there is a new bpstat
2131 to look at, so start over. */
2134 do_cleanups (old_chain
);
2137 /* This is the normal print function for a bpstat. In the future,
2138 much of this logic could (should?) be moved to bpstat_stop_status,
2139 by having it set different print_it values.
2141 Current scheme: When we stop, bpstat_print() is called. It loops
2142 through the bpstat list of things causing this stop, calling the
2143 print_bp_stop_message function on each one. The behavior of the
2144 print_bp_stop_message function depends on the print_it field of
2145 bpstat. If such field so indicates, call this function here.
2147 Return values from this routine (ultimately used by bpstat_print()
2148 and normal_stop() to decide what to do):
2149 PRINT_NOTHING: Means we already printed all we needed to print,
2150 don't print anything else.
2151 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2152 that something to be followed by a location.
2153 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2154 that something to be followed by a location.
2155 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2158 static enum print_stop_action
2159 print_it_typical (bpstat bs
)
2161 struct cleanup
*old_chain
, *ui_out_chain
;
2162 struct breakpoint
*b
;
2163 struct ui_stream
*stb
;
2164 stb
= ui_out_stream_new (uiout
);
2165 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2166 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2167 which has since been deleted. */
2168 if (bs
->breakpoint_at
== NULL
)
2169 return PRINT_UNKNOWN
;
2170 b
= bs
->breakpoint_at
->owner
;
2175 case bp_hardware_breakpoint
:
2176 if (b
->loc
->address
!= b
->loc
->requested_address
)
2177 breakpoint_adjustment_warning (b
->loc
->requested_address
,
2180 annotate_breakpoint (b
->number
);
2181 ui_out_text (uiout
, "\nBreakpoint ");
2182 if (ui_out_is_mi_like_p (uiout
))
2183 ui_out_field_string (uiout
, "reason",
2184 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2185 ui_out_field_int (uiout
, "bkptno", b
->number
);
2186 ui_out_text (uiout
, ", ");
2187 return PRINT_SRC_AND_LOC
;
2190 case bp_shlib_event
:
2191 /* Did we stop because the user set the stop_on_solib_events
2192 variable? (If so, we report this as a generic, "Stopped due
2193 to shlib event" message.) */
2194 printf_filtered (_("Stopped due to shared library event\n"));
2195 return PRINT_NOTHING
;
2198 case bp_thread_event
:
2199 /* Not sure how we will get here.
2200 GDB should not stop for these breakpoints. */
2201 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2202 return PRINT_NOTHING
;
2205 case bp_overlay_event
:
2206 /* By analogy with the thread event, GDB should not stop for these. */
2207 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2208 return PRINT_NOTHING
;
2212 annotate_catchpoint (b
->number
);
2213 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2215 b
->triggered_dll_pathname
);
2216 return PRINT_SRC_AND_LOC
;
2219 case bp_catch_unload
:
2220 annotate_catchpoint (b
->number
);
2221 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2223 b
->triggered_dll_pathname
);
2224 return PRINT_SRC_AND_LOC
;
2228 annotate_catchpoint (b
->number
);
2229 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2231 b
->forked_inferior_pid
);
2232 return PRINT_SRC_AND_LOC
;
2235 case bp_catch_vfork
:
2236 annotate_catchpoint (b
->number
);
2237 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2239 b
->forked_inferior_pid
);
2240 return PRINT_SRC_AND_LOC
;
2244 annotate_catchpoint (b
->number
);
2245 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2248 return PRINT_SRC_AND_LOC
;
2251 case bp_catch_catch
:
2252 if (current_exception_event
&&
2253 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2255 annotate_catchpoint (b
->number
);
2256 printf_filtered (_("\nCatchpoint %d (exception caught), "),
2258 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2259 printf_filtered (_("throw location %s:%d, "),
2260 CURRENT_EXCEPTION_THROW_FILE
,
2261 CURRENT_EXCEPTION_THROW_LINE
);
2263 printf_filtered (_("throw location unknown, "));
2265 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2266 printf_filtered (_("catch location %s:%d\n"),
2267 CURRENT_EXCEPTION_CATCH_FILE
,
2268 CURRENT_EXCEPTION_CATCH_LINE
);
2270 printf_filtered (_("catch location unknown\n"));
2272 /* don't bother to print location frame info */
2273 return PRINT_SRC_ONLY
;
2277 /* really throw, some other bpstat will handle it */
2278 return PRINT_UNKNOWN
;
2282 case bp_catch_throw
:
2283 if (current_exception_event
&&
2284 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2286 annotate_catchpoint (b
->number
);
2287 printf_filtered (_("\nCatchpoint %d (exception thrown), "),
2289 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2290 printf_filtered (_("throw location %s:%d, "),
2291 CURRENT_EXCEPTION_THROW_FILE
,
2292 CURRENT_EXCEPTION_THROW_LINE
);
2294 printf_filtered (_("throw location unknown, "));
2296 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2297 printf_filtered (_("catch location %s:%d\n"),
2298 CURRENT_EXCEPTION_CATCH_FILE
,
2299 CURRENT_EXCEPTION_CATCH_LINE
);
2301 printf_filtered (_("catch location unknown\n"));
2303 /* don't bother to print location frame info */
2304 return PRINT_SRC_ONLY
;
2308 /* really catch, some other bpstat will handle it */
2309 return PRINT_UNKNOWN
;
2314 case bp_hardware_watchpoint
:
2315 if (bs
->old_val
!= NULL
)
2317 annotate_watchpoint (b
->number
);
2318 if (ui_out_is_mi_like_p (uiout
))
2321 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2323 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2324 ui_out_text (uiout
, "\nOld value = ");
2325 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2326 ui_out_field_stream (uiout
, "old", stb
);
2327 ui_out_text (uiout
, "\nNew value = ");
2328 value_print (b
->val
, stb
->stream
, 0, Val_pretty_default
);
2329 ui_out_field_stream (uiout
, "new", stb
);
2330 do_cleanups (ui_out_chain
);
2331 ui_out_text (uiout
, "\n");
2332 value_free (bs
->old_val
);
2335 /* More than one watchpoint may have been triggered. */
2336 return PRINT_UNKNOWN
;
2339 case bp_read_watchpoint
:
2340 if (ui_out_is_mi_like_p (uiout
))
2343 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2345 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2346 ui_out_text (uiout
, "\nValue = ");
2347 value_print (b
->val
, stb
->stream
, 0, Val_pretty_default
);
2348 ui_out_field_stream (uiout
, "value", stb
);
2349 do_cleanups (ui_out_chain
);
2350 ui_out_text (uiout
, "\n");
2351 return PRINT_UNKNOWN
;
2354 case bp_access_watchpoint
:
2355 if (bs
->old_val
!= NULL
)
2357 annotate_watchpoint (b
->number
);
2358 if (ui_out_is_mi_like_p (uiout
))
2361 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2363 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2364 ui_out_text (uiout
, "\nOld value = ");
2365 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2366 ui_out_field_stream (uiout
, "old", stb
);
2367 value_free (bs
->old_val
);
2369 ui_out_text (uiout
, "\nNew value = ");
2374 if (ui_out_is_mi_like_p (uiout
))
2377 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2378 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2379 ui_out_text (uiout
, "\nValue = ");
2381 value_print (b
->val
, stb
->stream
, 0,Val_pretty_default
);
2382 ui_out_field_stream (uiout
, "new", stb
);
2383 do_cleanups (ui_out_chain
);
2384 ui_out_text (uiout
, "\n");
2385 return PRINT_UNKNOWN
;
2388 /* Fall through, we don't deal with these types of breakpoints
2392 if (ui_out_is_mi_like_p (uiout
))
2395 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2396 return PRINT_UNKNOWN
;
2400 if (ui_out_is_mi_like_p (uiout
))
2403 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2404 return PRINT_UNKNOWN
;
2409 case bp_longjmp_resume
:
2410 case bp_step_resume
:
2411 case bp_watchpoint_scope
:
2414 return PRINT_UNKNOWN
;
2418 /* Generic routine for printing messages indicating why we
2419 stopped. The behavior of this function depends on the value
2420 'print_it' in the bpstat structure. Under some circumstances we
2421 may decide not to print anything here and delegate the task to
2424 static enum print_stop_action
2425 print_bp_stop_message (bpstat bs
)
2427 switch (bs
->print_it
)
2430 /* Nothing should be printed for this bpstat entry. */
2431 return PRINT_UNKNOWN
;
2435 /* We still want to print the frame, but we already printed the
2436 relevant messages. */
2437 return PRINT_SRC_AND_LOC
;
2440 case print_it_normal
:
2442 struct bp_location
*bl
= bs
->breakpoint_at
;
2443 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2445 /* Normal case. Call the breakpoint's print_it method, or
2446 print_it_typical. */
2447 /* FIXME: how breakpoint can ever be NULL here? */
2448 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2449 return b
->ops
->print_it (b
);
2451 return print_it_typical (bs
);
2456 internal_error (__FILE__
, __LINE__
,
2457 _("print_bp_stop_message: unrecognized enum value"));
2462 /* Print a message indicating what happened. This is called from
2463 normal_stop(). The input to this routine is the head of the bpstat
2464 list - a list of the eventpoints that caused this stop. This
2465 routine calls the generic print routine for printing a message
2466 about reasons for stopping. This will print (for example) the
2467 "Breakpoint n," part of the output. The return value of this
2470 PRINT_UNKNOWN: Means we printed nothing
2471 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2472 code to print the location. An example is
2473 "Breakpoint 1, " which should be followed by
2475 PRINT_SRC_ONLY: Means we printed something, but there is no need
2476 to also print the location part of the message.
2477 An example is the catch/throw messages, which
2478 don't require a location appended to the end.
2479 PRINT_NOTHING: We have done some printing and we don't need any
2480 further info to be printed.*/
2482 enum print_stop_action
2483 bpstat_print (bpstat bs
)
2487 /* Maybe another breakpoint in the chain caused us to stop.
2488 (Currently all watchpoints go on the bpstat whether hit or not.
2489 That probably could (should) be changed, provided care is taken
2490 with respect to bpstat_explains_signal). */
2491 for (; bs
; bs
= bs
->next
)
2493 val
= print_bp_stop_message (bs
);
2494 if (val
== PRINT_SRC_ONLY
2495 || val
== PRINT_SRC_AND_LOC
2496 || val
== PRINT_NOTHING
)
2500 /* We reached the end of the chain, or we got a null BS to start
2501 with and nothing was printed. */
2502 return PRINT_UNKNOWN
;
2505 /* Evaluate the expression EXP and return 1 if value is zero.
2506 This is used inside a catch_errors to evaluate the breakpoint condition.
2507 The argument is a "struct expression *" that has been cast to char * to
2508 make it pass through catch_errors. */
2511 breakpoint_cond_eval (void *exp
)
2513 struct value
*mark
= value_mark ();
2514 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2515 value_free_to_mark (mark
);
2519 /* Allocate a new bpstat and chain it to the current one. */
2522 bpstat_alloc (struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2526 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2528 bs
->breakpoint_at
= bl
;
2529 /* If the condition is false, etc., don't do the commands. */
2530 bs
->commands
= NULL
;
2532 bs
->print_it
= print_it_normal
;
2536 /* Possible return values for watchpoint_check (this can't be an enum
2537 because of check_errors). */
2538 /* The watchpoint has been deleted. */
2539 #define WP_DELETED 1
2540 /* The value has changed. */
2541 #define WP_VALUE_CHANGED 2
2542 /* The value has not changed. */
2543 #define WP_VALUE_NOT_CHANGED 3
2545 #define BP_TEMPFLAG 1
2546 #define BP_HARDWAREFLAG 2
2548 /* Check watchpoint condition. */
2551 watchpoint_check (void *p
)
2553 bpstat bs
= (bpstat
) p
;
2554 struct breakpoint
*b
;
2555 struct frame_info
*fr
;
2556 int within_current_scope
;
2558 b
= bs
->breakpoint_at
->owner
;
2560 if (b
->exp_valid_block
== NULL
)
2561 within_current_scope
= 1;
2564 /* There is no current frame at this moment. If we're going to have
2565 any chance of handling watchpoints on local variables, we'll need
2566 the frame chain (so we can determine if we're in scope). */
2567 reinit_frame_cache ();
2568 fr
= frame_find_by_id (b
->watchpoint_frame
);
2569 within_current_scope
= (fr
!= NULL
);
2571 /* If we've gotten confused in the unwinder, we might have
2572 returned a frame that can't describe this variable. */
2573 if (within_current_scope
2574 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2575 within_current_scope
= 0;
2577 /* in_function_epilogue_p() returns a non-zero value if we're still
2578 in the function but the stack frame has already been invalidated.
2579 Since we can't rely on the values of local variables after the
2580 stack has been destroyed, we are treating the watchpoint in that
2581 state as `not changed' without further checking.
2583 vinschen/2003-09-04: The former implementation left out the case
2584 that the watchpoint frame couldn't be found by frame_find_by_id()
2585 because the current PC is currently in an epilogue. Calling
2586 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2587 if ((!within_current_scope
|| fr
== get_current_frame ())
2588 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2589 return WP_VALUE_NOT_CHANGED
;
2590 if (fr
&& within_current_scope
)
2591 /* If we end up stopping, the current frame will get selected
2592 in normal_stop. So this call to select_frame won't affect
2597 if (within_current_scope
)
2599 /* We use value_{,free_to_}mark because it could be a
2600 *long* time before we return to the command level and
2601 call free_all_values. We can't call free_all_values because
2602 we might be in the middle of evaluating a function call. */
2604 struct value
*mark
= value_mark ();
2605 struct value
*new_val
= evaluate_expression (b
->exp
);
2606 if (!value_equal (b
->val
, new_val
))
2608 release_value (new_val
);
2609 value_free_to_mark (mark
);
2610 bs
->old_val
= b
->val
;
2612 /* We will stop here */
2613 return WP_VALUE_CHANGED
;
2617 /* Nothing changed, don't do anything. */
2618 value_free_to_mark (mark
);
2619 /* We won't stop here */
2620 return WP_VALUE_NOT_CHANGED
;
2625 /* This seems like the only logical thing to do because
2626 if we temporarily ignored the watchpoint, then when
2627 we reenter the block in which it is valid it contains
2628 garbage (in the case of a function, it may have two
2629 garbage values, one before and one after the prologue).
2630 So we can't even detect the first assignment to it and
2631 watch after that (since the garbage may or may not equal
2632 the first value assigned). */
2633 /* We print all the stop information in print_it_typical(), but
2634 in this case, by the time we call print_it_typical() this bp
2635 will be deleted already. So we have no choice but print the
2636 information here. */
2637 if (ui_out_is_mi_like_p (uiout
))
2639 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2640 ui_out_text (uiout
, "\nWatchpoint ");
2641 ui_out_field_int (uiout
, "wpnum", b
->number
);
2642 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2643 which its expression is valid.\n");
2645 if (b
->related_breakpoint
)
2646 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2647 b
->disposition
= disp_del_at_next_stop
;
2653 /* Get a bpstat associated with having just stopped at address
2654 BP_ADDR in thread PTID. STOPPED_BY_WATCHPOINT is 1 if the
2655 target thinks we stopped due to a hardware watchpoint, 0 if we
2656 know we did not trigger a hardware watchpoint, and -1 if we do not know. */
2658 /* Determine whether we stopped at a breakpoint, etc, or whether we
2659 don't understand this stop. Result is a chain of bpstat's such that:
2661 if we don't understand the stop, the result is a null pointer.
2663 if we understand why we stopped, the result is not null.
2665 Each element of the chain refers to a particular breakpoint or
2666 watchpoint at which we have stopped. (We may have stopped for
2667 several reasons concurrently.)
2669 Each element of the chain has valid next, breakpoint_at,
2670 commands, FIXME??? fields. */
2673 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
, int stopped_by_watchpoint
)
2675 struct breakpoint
*b
, *temp
;
2676 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2677 int real_breakpoint
= 0;
2678 /* Root of the chain of bpstat's */
2679 struct bpstats root_bs
[1];
2680 /* Pointer to the last thing in the chain currently. */
2681 bpstat bs
= root_bs
;
2682 int thread_id
= pid_to_thread_id (ptid
);
2684 ALL_BREAKPOINTS_SAFE (b
, temp
)
2686 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2689 if (b
->type
!= bp_watchpoint
2690 && b
->type
!= bp_hardware_watchpoint
2691 && b
->type
!= bp_read_watchpoint
2692 && b
->type
!= bp_access_watchpoint
2693 && b
->type
!= bp_hardware_breakpoint
2694 && b
->type
!= bp_catch_fork
2695 && b
->type
!= bp_catch_vfork
2696 && b
->type
!= bp_catch_exec
2697 && b
->type
!= bp_catch_catch
2698 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2700 if (b
->loc
->address
!= bp_addr
) /* address doesn't match */
2702 if (overlay_debugging
/* unmapped overlay section */
2703 && section_is_overlay (b
->loc
->section
)
2704 && !section_is_mapped (b
->loc
->section
))
2708 /* Continuable hardware watchpoints are treated as non-existent if the
2709 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2710 some data address). Otherwise gdb won't stop on a break instruction
2711 in the code (not from a breakpoint) when a hardware watchpoint has
2714 if ((b
->type
== bp_hardware_watchpoint
2715 || b
->type
== bp_read_watchpoint
2716 || b
->type
== bp_access_watchpoint
)
2717 && !stopped_by_watchpoint
)
2720 if (b
->type
== bp_hardware_breakpoint
)
2722 if (b
->loc
->address
!= bp_addr
)
2724 if (overlay_debugging
/* unmapped overlay section */
2725 && section_is_overlay (b
->loc
->section
)
2726 && !section_is_mapped (b
->loc
->section
))
2730 /* Is this a catchpoint of a load or unload? If so, did we
2731 get a load or unload of the specified library? If not,
2733 if ((b
->type
== bp_catch_load
)
2734 #if defined(SOLIB_HAVE_LOAD_EVENT)
2735 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2736 || ((b
->dll_pathname
!= NULL
)
2737 && (strcmp (b
->dll_pathname
,
2738 SOLIB_LOADED_LIBRARY_PATHNAME (
2739 PIDGET (inferior_ptid
)))
2745 if ((b
->type
== bp_catch_unload
)
2746 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2747 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2748 || ((b
->dll_pathname
!= NULL
)
2749 && (strcmp (b
->dll_pathname
,
2750 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2751 PIDGET (inferior_ptid
)))
2757 if ((b
->type
== bp_catch_fork
)
2758 && !inferior_has_forked (PIDGET (inferior_ptid
),
2759 &b
->forked_inferior_pid
))
2762 if ((b
->type
== bp_catch_vfork
)
2763 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2764 &b
->forked_inferior_pid
))
2767 if ((b
->type
== bp_catch_exec
)
2768 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2771 if (ep_is_exception_catchpoint (b
) &&
2772 !(current_exception_event
= target_get_current_exception_event ()))
2775 /* Come here if it's a watchpoint, or if the break address matches */
2777 bs
= bpstat_alloc (b
->loc
, bs
); /* Alloc a bpstat to explain stop */
2779 /* Watchpoints may change this, if not found to have triggered. */
2783 if (b
->type
== bp_watchpoint
||
2784 b
->type
== bp_hardware_watchpoint
)
2786 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2788 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2789 int e
= catch_errors (watchpoint_check
, bs
, message
,
2791 do_cleanups (cleanups
);
2795 /* We've already printed what needs to be printed. */
2796 /* Actually this is superfluous, because by the time we
2797 call print_it_typical() the wp will be already deleted,
2798 and the function will return immediately. */
2799 bs
->print_it
= print_it_done
;
2802 case WP_VALUE_CHANGED
:
2806 case WP_VALUE_NOT_CHANGED
:
2808 bs
->print_it
= print_it_noop
;
2815 /* Error from catch_errors. */
2816 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2817 if (b
->related_breakpoint
)
2818 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2819 b
->disposition
= disp_del_at_next_stop
;
2820 /* We've already printed what needs to be printed. */
2821 bs
->print_it
= print_it_done
;
2827 else if (b
->type
== bp_read_watchpoint
||
2828 b
->type
== bp_access_watchpoint
)
2834 if (!target_stopped_data_address (¤t_target
, &addr
))
2836 for (v
= b
->val_chain
; v
; v
= value_next (v
))
2838 if (VALUE_LVAL (v
) == lval_memory
2839 && ! value_lazy (v
))
2841 struct type
*vtype
= check_typedef (value_type (v
));
2843 if (v
== b
->val_chain
2844 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2845 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2849 vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
2850 /* Exact match not required. Within range is
2852 if (addr
>= vaddr
&&
2853 addr
< vaddr
+ TYPE_LENGTH (value_type (v
)))
2860 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2862 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2863 int e
= catch_errors (watchpoint_check
, bs
, message
,
2865 do_cleanups (cleanups
);
2869 /* We've already printed what needs to be printed. */
2870 bs
->print_it
= print_it_done
;
2873 case WP_VALUE_CHANGED
:
2874 if (b
->type
== bp_read_watchpoint
)
2876 /* Don't stop: read watchpoints shouldn't fire if
2877 the value has changed. This is for targets
2878 which cannot set read-only watchpoints. */
2879 bs
->print_it
= print_it_noop
;
2885 case WP_VALUE_NOT_CHANGED
:
2892 /* Error from catch_errors. */
2893 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2894 if (b
->related_breakpoint
)
2895 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2896 b
->disposition
= disp_del_at_next_stop
;
2897 /* We've already printed what needs to be printed. */
2898 bs
->print_it
= print_it_done
;
2902 else /* found == 0 */
2904 /* This is a case where some watchpoint(s) triggered,
2905 but not at the address of this watchpoint (FOUND
2906 was left zero). So don't print anything for this
2908 bs
->print_it
= print_it_noop
;
2915 /* By definition, an encountered breakpoint is a triggered
2919 real_breakpoint
= 1;
2922 if (frame_id_p (b
->frame_id
)
2923 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2927 int value_is_zero
= 0;
2931 /* Need to select the frame, with all that implies
2932 so that the conditions will have the right context. */
2933 select_frame (get_current_frame ());
2935 = catch_errors (breakpoint_cond_eval
, (b
->loc
->cond
),
2936 "Error in testing breakpoint condition:\n",
2938 /* FIXME-someday, should give breakpoint # */
2941 if (b
->loc
->cond
&& value_is_zero
)
2944 /* Don't consider this a hit. */
2947 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2950 /* Don't consider this a hit. */
2953 else if (b
->ignore_count
> 0)
2956 annotate_ignore_count_change ();
2961 /* We will stop here */
2962 if (b
->disposition
== disp_disable
)
2963 b
->enable_state
= bp_disabled
;
2966 bs
->commands
= b
->commands
;
2968 (strcmp ("silent", bs
->commands
->line
) == 0
2969 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
2971 bs
->commands
= bs
->commands
->next
;
2974 bs
->commands
= copy_command_lines (bs
->commands
);
2977 /* Print nothing for this entry if we dont stop or if we dont print. */
2978 if (bs
->stop
== 0 || bs
->print
== 0)
2979 bs
->print_it
= print_it_noop
;
2982 bs
->next
= NULL
; /* Terminate the chain */
2983 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2985 /* The value of a hardware watchpoint hasn't changed, but the
2986 intermediate memory locations we are watching may have. */
2987 if (bs
&& !bs
->stop
&&
2988 (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
||
2989 bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
||
2990 bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
2992 remove_breakpoints ();
2993 insert_breakpoints ();
2998 /* Tell what to do about this bpstat. */
3000 bpstat_what (bpstat bs
)
3002 /* Classify each bpstat as one of the following. */
3005 /* This bpstat element has no effect on the main_action. */
3008 /* There was a watchpoint, stop but don't print. */
3011 /* There was a watchpoint, stop and print. */
3014 /* There was a breakpoint but we're not stopping. */
3017 /* There was a breakpoint, stop but don't print. */
3020 /* There was a breakpoint, stop and print. */
3023 /* We hit the longjmp breakpoint. */
3026 /* We hit the longjmp_resume breakpoint. */
3029 /* We hit the step_resume breakpoint. */
3032 /* We hit the shared library event breakpoint. */
3035 /* We caught a shared library event. */
3038 /* This is just used to count how many enums there are. */
3042 /* Here is the table which drives this routine. So that we can
3043 format it pretty, we define some abbreviations for the
3044 enum bpstat_what codes. */
3045 #define kc BPSTAT_WHAT_KEEP_CHECKING
3046 #define ss BPSTAT_WHAT_STOP_SILENT
3047 #define sn BPSTAT_WHAT_STOP_NOISY
3048 #define sgl BPSTAT_WHAT_SINGLE
3049 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3050 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3051 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
3052 #define sr BPSTAT_WHAT_STEP_RESUME
3053 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3054 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3056 /* "Can't happen." Might want to print an error message.
3057 abort() is not out of the question, but chances are GDB is just
3058 a bit confused, not unusable. */
3059 #define err BPSTAT_WHAT_STOP_NOISY
3061 /* Given an old action and a class, come up with a new action. */
3062 /* One interesting property of this table is that wp_silent is the same
3063 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3064 after stopping, the check for whether to step over a breakpoint
3065 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3066 reference to how we stopped. We retain separate wp_silent and
3067 bp_silent codes in case we want to change that someday.
3069 Another possibly interesting property of this table is that
3070 there's a partial ordering, priority-like, of the actions. Once
3071 you've decided that some action is appropriate, you'll never go
3072 back and decide something of a lower priority is better. The
3075 kc < clr sgl shl shlr slr sn sr ss
3076 sgl < clrs shl shlr slr sn sr ss
3077 slr < err shl shlr sn sr ss
3078 clr < clrs err shl shlr sn sr ss
3079 clrs < err shl shlr sn sr ss
3086 What I think this means is that we don't need a damned table
3087 here. If you just put the rows and columns in the right order,
3088 it'd look awfully regular. We could simply walk the bpstat list
3089 and choose the highest priority action we find, with a little
3090 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3091 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3092 is messy anyway). */
3094 /* step_resume entries: a step resume breakpoint overrides another
3095 breakpoint of signal handling (see comment in wait_for_inferior
3096 at where we set the step_resume breakpoint). */
3098 static const enum bpstat_what_main_action
3099 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3102 /* kc ss sn sgl slr clr clrs sr shl shlr
3105 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, shl
, shlr
},
3107 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3109 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3111 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, shl
, shlr
},
3113 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3115 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3117 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, shl
, shlr
},
3119 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, shl
, shlr
},
3121 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3123 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3125 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3140 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3141 struct bpstat_what retval
;
3143 retval
.call_dummy
= 0;
3144 for (; bs
!= NULL
; bs
= bs
->next
)
3146 enum class bs_class
= no_effect
;
3147 if (bs
->breakpoint_at
== NULL
)
3148 /* I suspect this can happen if it was a momentary breakpoint
3149 which has since been deleted. */
3151 switch (bs
->breakpoint_at
->owner
->type
)
3157 case bp_hardware_breakpoint
:
3163 bs_class
= bp_noisy
;
3165 bs_class
= bp_silent
;
3168 bs_class
= bp_nostop
;
3171 case bp_hardware_watchpoint
:
3172 case bp_read_watchpoint
:
3173 case bp_access_watchpoint
:
3177 bs_class
= wp_noisy
;
3179 bs_class
= wp_silent
;
3182 /* There was a watchpoint, but we're not stopping.
3183 This requires no further action. */
3184 bs_class
= no_effect
;
3187 bs_class
= long_jump
;
3189 case bp_longjmp_resume
:
3190 bs_class
= long_resume
;
3192 case bp_step_resume
:
3195 bs_class
= step_resume
;
3198 /* It is for the wrong frame. */
3199 bs_class
= bp_nostop
;
3201 case bp_watchpoint_scope
:
3202 bs_class
= bp_nostop
;
3204 case bp_shlib_event
:
3205 bs_class
= shlib_event
;
3207 case bp_thread_event
:
3208 case bp_overlay_event
:
3209 bs_class
= bp_nostop
;
3212 case bp_catch_unload
:
3213 /* Only if this catchpoint triggered should we cause the
3214 step-out-of-dld behaviour. Otherwise, we ignore this
3217 bs_class
= catch_shlib_event
;
3219 bs_class
= no_effect
;
3222 case bp_catch_vfork
:
3227 bs_class
= bp_noisy
;
3229 bs_class
= bp_silent
;
3232 /* There was a catchpoint, but we're not stopping.
3233 This requires no further action. */
3234 bs_class
= no_effect
;
3236 case bp_catch_catch
:
3237 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
3238 bs_class
= bp_nostop
;
3240 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3242 case bp_catch_throw
:
3243 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3244 bs_class
= bp_nostop
;
3246 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3249 /* Make sure the action is stop (silent or noisy),
3250 so infrun.c pops the dummy frame. */
3251 bs_class
= bp_silent
;
3252 retval
.call_dummy
= 1;
3255 current_action
= table
[(int) bs_class
][(int) current_action
];
3257 retval
.main_action
= current_action
;
3261 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3262 without hardware support). This isn't related to a specific bpstat,
3263 just to things like whether watchpoints are set. */
3266 bpstat_should_step (void)
3268 struct breakpoint
*b
;
3270 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3275 /* Nonzero if there are enabled hardware watchpoints. */
3277 bpstat_have_active_hw_watchpoints (void)
3279 struct bp_location
*bpt
;
3280 ALL_BP_LOCATIONS (bpt
)
3281 if (breakpoint_enabled (bpt
->owner
)
3283 && bpt
->loc_type
== bp_loc_hardware_watchpoint
)
3289 /* Given a bpstat that records zero or more triggered eventpoints, this
3290 function returns another bpstat which contains only the catchpoints
3291 on that first list, if any. */
3293 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3295 struct bpstats root_bs
[1];
3296 bpstat bs
= root_bs
;
3297 struct breakpoint
*ep
;
3300 bpstat_clear (cp_list
);
3301 root_bs
->next
= NULL
;
3303 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3305 /* Is this eventpoint a catchpoint? If not, ignore it. */
3306 ep
= ep_list
->breakpoint_at
->owner
;
3309 if ((ep
->type
!= bp_catch_load
) &&
3310 (ep
->type
!= bp_catch_unload
) &&
3311 (ep
->type
!= bp_catch_catch
) &&
3312 (ep
->type
!= bp_catch_throw
))
3313 /* pai: (temp) ADD fork/vfork here!! */
3316 /* Yes; add it to the list. */
3317 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3322 #if defined(SOLIB_ADD)
3323 /* Also, for each triggered catchpoint, tag it with the name of
3324 the library that caused this trigger. (We copy the name now,
3325 because it's only guaranteed to be available NOW, when the
3326 catchpoint triggers. Clients who may wish to know the name
3327 later must get it from the catchpoint itself.) */
3328 if (ep
->triggered_dll_pathname
!= NULL
)
3329 xfree (ep
->triggered_dll_pathname
);
3330 if (ep
->type
== bp_catch_load
)
3331 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3332 PIDGET (inferior_ptid
));
3334 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3335 PIDGET (inferior_ptid
));
3337 dll_pathname
= NULL
;
3341 ep
->triggered_dll_pathname
= (char *)
3342 xmalloc (strlen (dll_pathname
) + 1);
3343 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3346 ep
->triggered_dll_pathname
= NULL
;
3352 /* Print B to gdb_stdout. */
3354 print_one_breakpoint (struct breakpoint
*b
,
3355 CORE_ADDR
*last_addr
)
3357 struct command_line
*l
;
3359 struct ep_type_description
3364 static struct ep_type_description bptypes
[] =
3366 {bp_none
, "?deleted?"},
3367 {bp_breakpoint
, "breakpoint"},
3368 {bp_hardware_breakpoint
, "hw breakpoint"},
3369 {bp_until
, "until"},
3370 {bp_finish
, "finish"},
3371 {bp_watchpoint
, "watchpoint"},
3372 {bp_hardware_watchpoint
, "hw watchpoint"},
3373 {bp_read_watchpoint
, "read watchpoint"},
3374 {bp_access_watchpoint
, "acc watchpoint"},
3375 {bp_longjmp
, "longjmp"},
3376 {bp_longjmp_resume
, "longjmp resume"},
3377 {bp_step_resume
, "step resume"},
3378 {bp_watchpoint_scope
, "watchpoint scope"},
3379 {bp_call_dummy
, "call dummy"},
3380 {bp_shlib_event
, "shlib events"},
3381 {bp_thread_event
, "thread events"},
3382 {bp_overlay_event
, "overlay events"},
3383 {bp_catch_load
, "catch load"},
3384 {bp_catch_unload
, "catch unload"},
3385 {bp_catch_fork
, "catch fork"},
3386 {bp_catch_vfork
, "catch vfork"},
3387 {bp_catch_exec
, "catch exec"},
3388 {bp_catch_catch
, "catch catch"},
3389 {bp_catch_throw
, "catch throw"}
3392 static char *bpdisps
[] =
3393 {"del", "dstp", "dis", "keep"};
3394 static char bpenables
[] = "nynny";
3395 char wrap_indent
[80];
3396 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3397 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3398 struct cleanup
*bkpt_chain
;
3401 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3405 ui_out_field_int (uiout
, "number", b
->number
);
3409 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3410 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3411 internal_error (__FILE__
, __LINE__
,
3412 _("bptypes table does not describe type #%d."),
3414 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3418 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3422 ui_out_field_fmt (uiout
, "enabled", "%c", bpenables
[(int) b
->enable_state
]);
3423 ui_out_spaces (uiout
, 2);
3426 strcpy (wrap_indent
, " ");
3429 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3430 strcat (wrap_indent
, " ");
3432 strcat (wrap_indent
, " ");
3435 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3436 b
->ops
->print_one (b
, last_addr
);
3441 internal_error (__FILE__
, __LINE__
,
3442 _("print_one_breakpoint: bp_none encountered\n"));
3446 case bp_hardware_watchpoint
:
3447 case bp_read_watchpoint
:
3448 case bp_access_watchpoint
:
3449 /* Field 4, the address, is omitted (which makes the columns
3450 not line up too nicely with the headers, but the effect
3451 is relatively readable). */
3453 ui_out_field_skip (uiout
, "addr");
3455 print_expression (b
->exp
, stb
->stream
);
3456 ui_out_field_stream (uiout
, "what", stb
);
3460 case bp_catch_unload
:
3461 /* Field 4, the address, is omitted (which makes the columns
3462 not line up too nicely with the headers, but the effect
3463 is relatively readable). */
3465 ui_out_field_skip (uiout
, "addr");
3467 if (b
->dll_pathname
== NULL
)
3469 ui_out_field_string (uiout
, "what", "<any library>");
3470 ui_out_spaces (uiout
, 1);
3474 ui_out_text (uiout
, "library \"");
3475 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3476 ui_out_text (uiout
, "\" ");
3481 case bp_catch_vfork
:
3482 /* Field 4, the address, is omitted (which makes the columns
3483 not line up too nicely with the headers, but the effect
3484 is relatively readable). */
3486 ui_out_field_skip (uiout
, "addr");
3488 if (b
->forked_inferior_pid
!= 0)
3490 ui_out_text (uiout
, "process ");
3491 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3492 ui_out_spaces (uiout
, 1);
3497 /* Field 4, the address, is omitted (which makes the columns
3498 not line up too nicely with the headers, but the effect
3499 is relatively readable). */
3501 ui_out_field_skip (uiout
, "addr");
3503 if (b
->exec_pathname
!= NULL
)
3505 ui_out_text (uiout
, "program \"");
3506 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3507 ui_out_text (uiout
, "\" ");
3511 case bp_catch_catch
:
3512 /* Field 4, the address, is omitted (which makes the columns
3513 not line up too nicely with the headers, but the effect
3514 is relatively readable). */
3516 ui_out_field_skip (uiout
, "addr");
3518 ui_out_field_string (uiout
, "what", "exception catch");
3519 ui_out_spaces (uiout
, 1);
3522 case bp_catch_throw
:
3523 /* Field 4, the address, is omitted (which makes the columns
3524 not line up too nicely with the headers, but the effect
3525 is relatively readable). */
3527 ui_out_field_skip (uiout
, "addr");
3529 ui_out_field_string (uiout
, "what", "exception throw");
3530 ui_out_spaces (uiout
, 1);
3534 case bp_hardware_breakpoint
:
3538 case bp_longjmp_resume
:
3539 case bp_step_resume
:
3540 case bp_watchpoint_scope
:
3542 case bp_shlib_event
:
3543 case bp_thread_event
:
3544 case bp_overlay_event
:
3549 ui_out_field_string (uiout
, "addr", "<PENDING>");
3551 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
3554 *last_addr
= b
->loc
->address
;
3557 sym
= find_pc_sect_function (b
->loc
->address
, b
->loc
->section
);
3560 ui_out_text (uiout
, "in ");
3561 ui_out_field_string (uiout
, "func",
3562 SYMBOL_PRINT_NAME (sym
));
3563 ui_out_wrap_hint (uiout
, wrap_indent
);
3564 ui_out_text (uiout
, " at ");
3566 ui_out_field_string (uiout
, "file", b
->source_file
);
3567 ui_out_text (uiout
, ":");
3569 if (ui_out_is_mi_like_p (uiout
))
3571 struct symtab_and_line sal
= find_pc_line (b
->loc
->address
, 0);
3572 char *fullname
= symtab_to_fullname (sal
.symtab
);
3575 ui_out_field_string (uiout
, "fullname", fullname
);
3578 ui_out_field_int (uiout
, "line", b
->line_number
);
3580 else if (b
->pending
)
3582 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3586 print_address_symbolic (b
->loc
->address
, stb
->stream
, demangle
, "");
3587 ui_out_field_stream (uiout
, "at", stb
);
3592 if (b
->thread
!= -1)
3594 /* FIXME: This seems to be redundant and lost here; see the
3595 "stop only in" line a little further down. */
3596 ui_out_text (uiout
, " thread ");
3597 ui_out_field_int (uiout
, "thread", b
->thread
);
3600 ui_out_text (uiout
, "\n");
3602 if (frame_id_p (b
->frame_id
))
3605 ui_out_text (uiout
, "\tstop only in stack frame at ");
3606 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3608 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3609 ui_out_text (uiout
, "\n");
3612 if (b
->loc
->cond
&& !ada_exception_catchpoint_p (b
))
3614 /* We do not print the condition for Ada exception catchpoints
3615 because the condition is an internal implementation detail
3616 that we do not want to expose to the user. */
3618 ui_out_text (uiout
, "\tstop only if ");
3619 print_expression (b
->loc
->cond
, stb
->stream
);
3620 ui_out_field_stream (uiout
, "cond", stb
);
3621 ui_out_text (uiout
, "\n");
3624 if (b
->pending
&& b
->cond_string
)
3627 ui_out_text (uiout
, "\tstop only if ");
3628 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3629 ui_out_text (uiout
, "\n");
3632 if (b
->thread
!= -1)
3634 /* FIXME should make an annotation for this */
3635 ui_out_text (uiout
, "\tstop only in thread ");
3636 ui_out_field_int (uiout
, "thread", b
->thread
);
3637 ui_out_text (uiout
, "\n");
3640 if (show_breakpoint_hit_counts
&& b
->hit_count
)
3642 /* FIXME should make an annotation for this */
3643 if (ep_is_catchpoint (b
))
3644 ui_out_text (uiout
, "\tcatchpoint");
3646 ui_out_text (uiout
, "\tbreakpoint");
3647 ui_out_text (uiout
, " already hit ");
3648 ui_out_field_int (uiout
, "times", b
->hit_count
);
3649 if (b
->hit_count
== 1)
3650 ui_out_text (uiout
, " time\n");
3652 ui_out_text (uiout
, " times\n");
3655 /* Output the count also if it is zero, but only if this is
3656 mi. FIXME: Should have a better test for this. */
3657 if (ui_out_is_mi_like_p (uiout
))
3658 if (show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3659 ui_out_field_int (uiout
, "times", b
->hit_count
);
3661 if (b
->ignore_count
)
3664 ui_out_text (uiout
, "\tignore next ");
3665 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3666 ui_out_text (uiout
, " hits\n");
3669 if ((l
= b
->commands
))
3671 struct cleanup
*script_chain
;
3674 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3675 print_command_lines (uiout
, l
, 4);
3676 do_cleanups (script_chain
);
3678 do_cleanups (bkpt_chain
);
3679 do_cleanups (old_chain
);
3682 struct captured_breakpoint_query_args
3688 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3690 struct captured_breakpoint_query_args
*args
= data
;
3691 struct breakpoint
*b
;
3692 CORE_ADDR dummy_addr
= 0;
3695 if (args
->bnum
== b
->number
)
3697 print_one_breakpoint (b
, &dummy_addr
);
3705 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3707 struct captured_breakpoint_query_args args
;
3709 /* For the moment we don't trust print_one_breakpoint() to not throw
3711 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3712 error_message
, RETURN_MASK_ALL
) < 0)
3718 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3719 catchpoints, et.al.). */
3722 user_settable_breakpoint (const struct breakpoint
*b
)
3724 return (b
->type
== bp_breakpoint
3725 || b
->type
== bp_catch_load
3726 || b
->type
== bp_catch_unload
3727 || b
->type
== bp_catch_fork
3728 || b
->type
== bp_catch_vfork
3729 || b
->type
== bp_catch_exec
3730 || b
->type
== bp_catch_catch
3731 || b
->type
== bp_catch_throw
3732 || b
->type
== bp_hardware_breakpoint
3733 || b
->type
== bp_watchpoint
3734 || b
->type
== bp_read_watchpoint
3735 || b
->type
== bp_access_watchpoint
3736 || b
->type
== bp_hardware_watchpoint
);
3739 /* Print information on user settable breakpoint (watchpoint, etc)
3740 number BNUM. If BNUM is -1 print all user settable breakpoints.
3741 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3744 breakpoint_1 (int bnum
, int allflag
)
3746 struct breakpoint
*b
;
3747 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3748 int nr_printable_breakpoints
;
3749 struct cleanup
*bkpttbl_chain
;
3751 /* Compute the number of rows in the table. */
3752 nr_printable_breakpoints
= 0;
3755 || bnum
== b
->number
)
3757 if (allflag
|| user_settable_breakpoint (b
))
3758 nr_printable_breakpoints
++;
3763 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3767 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3770 if (nr_printable_breakpoints
> 0)
3771 annotate_breakpoints_headers ();
3772 if (nr_printable_breakpoints
> 0)
3774 ui_out_table_header (uiout
, 3, ui_left
, "number", "Num"); /* 1 */
3775 if (nr_printable_breakpoints
> 0)
3777 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3778 if (nr_printable_breakpoints
> 0)
3780 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3781 if (nr_printable_breakpoints
> 0)
3783 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3786 if (nr_printable_breakpoints
> 0)
3788 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3789 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3791 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3793 if (nr_printable_breakpoints
> 0)
3795 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3796 ui_out_table_body (uiout
);
3797 if (nr_printable_breakpoints
> 0)
3798 annotate_breakpoints_table ();
3802 || bnum
== b
->number
)
3804 /* We only print out user settable breakpoints unless the
3806 if (allflag
|| user_settable_breakpoint (b
))
3807 print_one_breakpoint (b
, &last_addr
);
3810 do_cleanups (bkpttbl_chain
);
3812 if (nr_printable_breakpoints
== 0)
3815 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3817 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3822 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3823 that a comparison of an unsigned with -1 is always false. */
3824 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3825 set_next_address (last_addr
);
3828 /* FIXME? Should this be moved up so that it is only called when
3829 there have been breakpoints? */
3830 annotate_breakpoints_table_end ();
3834 breakpoints_info (char *bnum_exp
, int from_tty
)
3839 bnum
= parse_and_eval_long (bnum_exp
);
3841 breakpoint_1 (bnum
, 0);
3845 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3850 bnum
= parse_and_eval_long (bnum_exp
);
3852 breakpoint_1 (bnum
, 1);
3855 /* Print a message describing any breakpoints set at PC. */
3858 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
3861 struct breakpoint
*b
;
3864 if (b
->loc
->address
== pc
) /* address match / overlay match */
3865 if (!b
->pending
&& (!overlay_debugging
|| b
->loc
->section
== section
))
3870 printf_filtered (_("Note: breakpoint "));
3871 else /* if (others == ???) */
3872 printf_filtered (_("Note: breakpoints "));
3874 if (b
->loc
->address
== pc
) /* address match / overlay match */
3875 if (!b
->pending
&& (!overlay_debugging
|| b
->loc
->section
== section
))
3878 printf_filtered ("%d", b
->number
);
3879 if (b
->thread
== -1 && thread
!= -1)
3880 printf_filtered (" (all threads)");
3881 else if (b
->thread
!= -1)
3882 printf_filtered (" (thread %d)", b
->thread
);
3883 printf_filtered ("%s%s ",
3884 ((b
->enable_state
== bp_disabled
||
3885 b
->enable_state
== bp_shlib_disabled
||
3886 b
->enable_state
== bp_call_disabled
)
3888 : b
->enable_state
== bp_permanent
3892 : ((others
== 1) ? " and" : ""));
3894 printf_filtered (_("also set at pc "));
3895 deprecated_print_address_numeric (pc
, 1, gdb_stdout
);
3896 printf_filtered (".\n");
3900 /* Set the default place to put a breakpoint
3901 for the `break' command with no arguments. */
3904 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3907 default_breakpoint_valid
= valid
;
3908 default_breakpoint_address
= addr
;
3909 default_breakpoint_symtab
= symtab
;
3910 default_breakpoint_line
= line
;
3913 /* Return true iff it is meaningful to use the address member of
3914 BPT. For some breakpoint types, the address member is irrelevant
3915 and it makes no sense to attempt to compare it to other addresses
3916 (or use it for any other purpose either).
3918 More specifically, each of the following breakpoint types will always
3919 have a zero valued address and we don't want check_duplicates() to mark
3920 breakpoints of any of these types to be a duplicate of an actual
3921 breakpoint at address zero:
3924 bp_hardware_watchpoint
3926 bp_access_watchpoint
3933 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3935 enum bptype type
= bpt
->type
;
3937 return (type
!= bp_watchpoint
3938 && type
!= bp_hardware_watchpoint
3939 && type
!= bp_read_watchpoint
3940 && type
!= bp_access_watchpoint
3941 && type
!= bp_catch_exec
3942 && type
!= bp_longjmp_resume
3943 && type
!= bp_catch_fork
3944 && type
!= bp_catch_vfork
);
3947 /* Rescan breakpoints at the same address and section as BPT,
3948 marking the first one as "first" and any others as "duplicates".
3949 This is so that the bpt instruction is only inserted once.
3950 If we have a permanent breakpoint at the same place as BPT, make
3951 that one the official one, and the rest as duplicates. */
3954 check_duplicates (struct breakpoint
*bpt
)
3956 struct bp_location
*b
;
3958 struct bp_location
*perm_bp
= 0;
3959 CORE_ADDR address
= bpt
->loc
->address
;
3960 asection
*section
= bpt
->loc
->section
;
3962 if (! breakpoint_address_is_meaningful (bpt
))
3965 ALL_BP_LOCATIONS (b
)
3966 if (b
->owner
->enable_state
!= bp_disabled
3967 && b
->owner
->enable_state
!= bp_shlib_disabled
3968 && !b
->owner
->pending
3969 && b
->owner
->enable_state
!= bp_call_disabled
3970 && b
->address
== address
/* address / overlay match */
3971 && (!overlay_debugging
|| b
->section
== section
)
3972 && breakpoint_address_is_meaningful (b
->owner
))
3974 /* Have we found a permanent breakpoint? */
3975 if (b
->owner
->enable_state
== bp_permanent
)
3982 b
->duplicate
= count
> 1;
3985 /* If we found a permanent breakpoint at this address, go over the
3986 list again and declare all the other breakpoints there to be the
3990 perm_bp
->duplicate
= 0;
3992 /* Permanent breakpoint should always be inserted. */
3993 if (! perm_bp
->inserted
)
3994 internal_error (__FILE__
, __LINE__
,
3995 _("allegedly permanent breakpoint is not "
3996 "actually inserted"));
3998 ALL_BP_LOCATIONS (b
)
4001 if (b
->owner
->enable_state
!= bp_disabled
4002 && b
->owner
->enable_state
!= bp_shlib_disabled
4003 && !b
->owner
->pending
4004 && b
->owner
->enable_state
!= bp_call_disabled
4005 && b
->address
== address
/* address / overlay match */
4006 && (!overlay_debugging
|| b
->section
== section
)
4007 && breakpoint_address_is_meaningful (b
->owner
))
4010 internal_error (__FILE__
, __LINE__
,
4011 _("another breakpoint was inserted on top of "
4012 "a permanent breakpoint"));
4021 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4022 int bnum
, int have_bnum
)
4027 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4028 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4030 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4031 bnum
, astr1
, astr2
);
4033 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4036 /* Adjust a breakpoint's address to account for architectural constraints
4037 on breakpoint placement. Return the adjusted address. Note: Very
4038 few targets require this kind of adjustment. For most targets,
4039 this function is simply the identity function. */
4042 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4044 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4046 /* Very few targets need any kind of breakpoint adjustment. */
4049 else if (bptype
== bp_watchpoint
4050 || bptype
== bp_hardware_watchpoint
4051 || bptype
== bp_read_watchpoint
4052 || bptype
== bp_access_watchpoint
4053 || bptype
== bp_catch_fork
4054 || bptype
== bp_catch_vfork
4055 || bptype
== bp_catch_exec
)
4057 /* Watchpoints and the various bp_catch_* eventpoints should not
4058 have their addresses modified. */
4063 CORE_ADDR adjusted_bpaddr
;
4065 /* Some targets have architectural constraints on the placement
4066 of breakpoint instructions. Obtain the adjusted address. */
4067 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4070 /* An adjusted breakpoint address can significantly alter
4071 a user's expectations. Print a warning if an adjustment
4073 if (adjusted_bpaddr
!= bpaddr
)
4074 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4076 return adjusted_bpaddr
;
4080 /* Allocate a struct bp_location. */
4082 static struct bp_location
*
4083 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4085 struct bp_location
*loc
, *loc_p
;
4087 loc
= xmalloc (sizeof (struct bp_location
));
4088 memset (loc
, 0, sizeof (*loc
));
4099 case bp_longjmp_resume
:
4100 case bp_step_resume
:
4101 case bp_watchpoint_scope
:
4103 case bp_shlib_event
:
4104 case bp_thread_event
:
4105 case bp_overlay_event
:
4107 case bp_catch_unload
:
4108 loc
->loc_type
= bp_loc_software_breakpoint
;
4110 case bp_hardware_breakpoint
:
4111 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4113 case bp_hardware_watchpoint
:
4114 case bp_read_watchpoint
:
4115 case bp_access_watchpoint
:
4116 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4120 case bp_catch_vfork
:
4122 case bp_catch_catch
:
4123 case bp_catch_throw
:
4124 loc
->loc_type
= bp_loc_other
;
4127 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4130 /* Add this breakpoint to the end of the chain. */
4132 loc_p
= bp_location_chain
;
4134 bp_location_chain
= loc
;
4138 loc_p
= loc_p
->next
;
4145 static void free_bp_location (struct bp_location
*loc
)
4152 /* set_raw_breakpoint() is a low level routine for allocating and
4153 partially initializing a breakpoint of type BPTYPE. The newly
4154 created breakpoint's address, section, source file name, and line
4155 number are provided by SAL. The newly created and partially
4156 initialized breakpoint is added to the breakpoint chain and
4157 is also returned as the value of this function.
4159 It is expected that the caller will complete the initialization of
4160 the newly created breakpoint struct as well as output any status
4161 information regarding the creation of a new breakpoint. In
4162 particular, set_raw_breakpoint() does NOT set the breakpoint
4163 number! Care should be taken to not allow an error() to occur
4164 prior to completing the initialization of the breakpoint. If this
4165 should happen, a bogus breakpoint will be left on the chain. */
4168 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4170 struct breakpoint
*b
, *b1
;
4171 CORE_ADDR adjusted_address
;
4173 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4174 memset (b
, 0, sizeof (*b
));
4176 /* Adjust the breakpoint's address prior to allocating a location.
4177 Once we call allocate_bp_location(), that mostly uninitialized
4178 location will be placed on the location chain. Adjustment of the
4179 breakpoint may cause read_memory_nobpt() to be called and we do
4180 not want its scan of the location chain to find a breakpoint and
4181 location that's only been partially initialized. */
4182 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4184 b
->loc
= allocate_bp_location (b
, bptype
);
4185 b
->loc
->requested_address
= sal
.pc
;
4186 b
->loc
->address
= adjusted_address
;
4188 if (sal
.symtab
== NULL
)
4189 b
->source_file
= NULL
;
4191 b
->source_file
= savestring (sal
.symtab
->filename
,
4192 strlen (sal
.symtab
->filename
));
4193 b
->loc
->section
= sal
.section
;
4195 b
->language
= current_language
->la_language
;
4196 b
->input_radix
= input_radix
;
4198 b
->line_number
= sal
.line
;
4199 b
->enable_state
= bp_enabled
;
4202 b
->ignore_count
= 0;
4204 b
->frame_id
= null_frame_id
;
4205 b
->dll_pathname
= NULL
;
4206 b
->triggered_dll_pathname
= NULL
;
4207 b
->forked_inferior_pid
= 0;
4208 b
->exec_pathname
= NULL
;
4212 /* Add this breakpoint to the end of the chain
4213 so that a list of breakpoints will come out in order
4214 of increasing numbers. */
4216 b1
= breakpoint_chain
;
4218 breakpoint_chain
= b
;
4226 check_duplicates (b
);
4227 breakpoints_changed ();
4233 /* Note that the breakpoint object B describes a permanent breakpoint
4234 instruction, hard-wired into the inferior's code. */
4236 make_breakpoint_permanent (struct breakpoint
*b
)
4238 b
->enable_state
= bp_permanent
;
4240 /* By definition, permanent breakpoints are already present in the code. */
4241 b
->loc
->inserted
= 1;
4244 static struct breakpoint
*
4245 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4247 static int internal_breakpoint_number
= -1;
4248 struct symtab_and_line sal
;
4249 struct breakpoint
*b
;
4251 init_sal (&sal
); /* initialize to zeroes */
4254 sal
.section
= find_pc_overlay (sal
.pc
);
4256 b
= set_raw_breakpoint (sal
, type
);
4257 b
->number
= internal_breakpoint_number
--;
4258 b
->disposition
= disp_donttouch
;
4265 create_longjmp_breakpoint (char *func_name
)
4267 struct breakpoint
*b
;
4268 struct minimal_symbol
*m
;
4270 if (func_name
== NULL
)
4271 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4274 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4277 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4280 b
->enable_state
= bp_disabled
;
4283 b
->addr_string
= xstrdup (func_name
);
4286 /* Call this routine when stepping and nexting to enable a breakpoint
4287 if we do a longjmp(). When we hit that breakpoint, call
4288 set_longjmp_resume_breakpoint() to figure out where we are going. */
4291 enable_longjmp_breakpoint (void)
4293 struct breakpoint
*b
;
4296 if (b
->type
== bp_longjmp
)
4298 b
->enable_state
= bp_enabled
;
4299 check_duplicates (b
);
4304 disable_longjmp_breakpoint (void)
4306 struct breakpoint
*b
;
4309 if (b
->type
== bp_longjmp
4310 || b
->type
== bp_longjmp_resume
)
4312 b
->enable_state
= bp_disabled
;
4313 check_duplicates (b
);
4318 create_overlay_event_breakpoint (char *func_name
)
4320 struct breakpoint
*b
;
4321 struct minimal_symbol
*m
;
4323 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4326 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4328 b
->addr_string
= xstrdup (func_name
);
4330 if (overlay_debugging
== ovly_auto
)
4332 b
->enable_state
= bp_enabled
;
4333 overlay_events_enabled
= 1;
4337 b
->enable_state
= bp_disabled
;
4338 overlay_events_enabled
= 0;
4343 enable_overlay_breakpoints (void)
4345 struct breakpoint
*b
;
4348 if (b
->type
== bp_overlay_event
)
4350 b
->enable_state
= bp_enabled
;
4351 check_duplicates (b
);
4352 overlay_events_enabled
= 1;
4357 disable_overlay_breakpoints (void)
4359 struct breakpoint
*b
;
4362 if (b
->type
== bp_overlay_event
)
4364 b
->enable_state
= bp_disabled
;
4365 check_duplicates (b
);
4366 overlay_events_enabled
= 0;
4371 create_thread_event_breakpoint (CORE_ADDR address
)
4373 struct breakpoint
*b
;
4375 b
= create_internal_breakpoint (address
, bp_thread_event
);
4377 b
->enable_state
= bp_enabled
;
4378 /* addr_string has to be used or breakpoint_re_set will delete me. */
4379 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4385 remove_thread_event_breakpoints (void)
4387 struct breakpoint
*b
, *temp
;
4389 ALL_BREAKPOINTS_SAFE (b
, temp
)
4390 if (b
->type
== bp_thread_event
)
4391 delete_breakpoint (b
);
4394 struct captured_parse_breakpoint_args
4397 struct symtabs_and_lines
*sals_p
;
4398 char ***addr_string_p
;
4402 struct lang_and_radix
4410 remove_solib_event_breakpoints (void)
4412 struct breakpoint
*b
, *temp
;
4414 ALL_BREAKPOINTS_SAFE (b
, temp
)
4415 if (b
->type
== bp_shlib_event
)
4416 delete_breakpoint (b
);
4420 create_solib_event_breakpoint (CORE_ADDR address
)
4422 struct breakpoint
*b
;
4424 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4428 /* Disable any breakpoints that are on code in shared libraries. Only
4429 apply to enabled breakpoints, disabled ones can just stay disabled. */
4432 disable_breakpoints_in_shlibs (void)
4434 struct breakpoint
*b
;
4435 int disabled_shlib_breaks
= 0;
4439 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4440 && breakpoint_enabled (b
) && !b
->loc
->duplicate
4442 && PC_SOLIB (b
->loc
->address
)
4444 && solib_address (b
->loc
->address
)
4447 b
->enable_state
= bp_shlib_disabled
;
4451 /* Disable any breakpoints that are in in an unloaded shared library. Only
4452 apply to enabled breakpoints, disabled ones can just stay disabled. */
4455 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4457 struct breakpoint
*b
;
4458 int disabled_shlib_breaks
= 0;
4462 if ((b
->loc
->loc_type
== bp_loc_hardware_breakpoint
4463 || b
->loc
->loc_type
== bp_loc_software_breakpoint
)
4464 && breakpoint_enabled (b
) && !b
->loc
->duplicate
)
4467 char *so_name
= PC_SOLIB (b
->loc
->address
);
4469 char *so_name
= solib_address (b
->loc
->address
);
4471 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4473 b
->enable_state
= bp_shlib_disabled
;
4474 /* At this point, we cannot rely on remove_breakpoint
4475 succeeding so we must mark the breakpoint as not inserted
4476 to prevent future errors occurring in remove_breakpoints. */
4477 b
->loc
->inserted
= 0;
4478 if (!disabled_shlib_breaks
)
4480 target_terminal_ours_for_output ();
4481 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4484 disabled_shlib_breaks
= 1;
4491 solib_load_unload_1 (char *hookname
, int tempflag
, char *dll_pathname
,
4492 char *cond_string
, enum bptype bp_kind
)
4494 struct breakpoint
*b
;
4495 struct symtabs_and_lines sals
;
4496 struct cleanup
*old_chain
;
4497 struct cleanup
*canonical_strings_chain
= NULL
;
4498 char *addr_start
= hookname
;
4499 char *addr_end
= NULL
;
4500 char **canonical
= (char **) NULL
;
4501 int thread
= -1; /* All threads. */
4503 /* Set a breakpoint on the specified hook. */
4504 sals
= decode_line_1 (&hookname
, 1, (struct symtab
*) NULL
,
4505 0, &canonical
, NULL
);
4506 addr_end
= hookname
;
4508 if (sals
.nelts
== 0)
4510 warning (_("Unable to set a breakpoint on dynamic linker callback.\n"
4511 "Suggest linking with /opt/langtools/lib/end.o.\n"
4512 "GDB will be unable to track shl_load/shl_unload calls."));
4515 if (sals
.nelts
!= 1)
4517 warning (_("Unable to set unique breakpoint on dynamic linker callback.\n"
4518 "GDB will be unable to track shl_load/shl_unload calls."));
4522 /* Make sure that all storage allocated in decode_line_1 gets freed
4523 in case the following errors out. */
4524 old_chain
= make_cleanup (xfree
, sals
.sals
);
4525 if (canonical
!= (char **) NULL
)
4527 make_cleanup (xfree
, canonical
);
4528 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
4529 if (canonical
[0] != NULL
)
4530 make_cleanup (xfree
, canonical
[0]);
4533 resolve_sal_pc (&sals
.sals
[0]);
4535 /* Remove the canonical strings from the cleanup, they are needed below. */
4536 if (canonical
!= (char **) NULL
)
4537 discard_cleanups (canonical_strings_chain
);
4539 b
= set_raw_breakpoint (sals
.sals
[0], bp_kind
);
4540 set_breakpoint_count (breakpoint_count
+ 1);
4541 b
->number
= breakpoint_count
;
4542 b
->cond_string
= (cond_string
== NULL
) ?
4543 NULL
: savestring (cond_string
, strlen (cond_string
));
4546 if (canonical
!= (char **) NULL
&& canonical
[0] != NULL
)
4547 b
->addr_string
= canonical
[0];
4548 else if (addr_start
)
4549 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
4551 b
->enable_state
= bp_enabled
;
4552 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4554 if (dll_pathname
== NULL
)
4555 b
->dll_pathname
= NULL
;
4558 b
->dll_pathname
= (char *) xmalloc (strlen (dll_pathname
) + 1);
4559 strcpy (b
->dll_pathname
, dll_pathname
);
4563 do_cleanups (old_chain
);
4567 create_solib_load_event_breakpoint (char *hookname
, int tempflag
,
4568 char *dll_pathname
, char *cond_string
)
4570 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4571 cond_string
, bp_catch_load
);
4575 create_solib_unload_event_breakpoint (char *hookname
, int tempflag
,
4576 char *dll_pathname
, char *cond_string
)
4578 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4579 cond_string
, bp_catch_unload
);
4583 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4584 enum bptype bp_kind
)
4586 struct symtab_and_line sal
;
4587 struct breakpoint
*b
;
4588 int thread
= -1; /* All threads. */
4595 b
= set_raw_breakpoint (sal
, bp_kind
);
4596 set_breakpoint_count (breakpoint_count
+ 1);
4597 b
->number
= breakpoint_count
;
4598 b
->cond_string
= (cond_string
== NULL
) ?
4599 NULL
: savestring (cond_string
, strlen (cond_string
));
4601 b
->addr_string
= NULL
;
4602 b
->enable_state
= bp_enabled
;
4603 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4604 b
->forked_inferior_pid
= 0;
4610 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4612 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4616 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4618 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4622 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4624 struct symtab_and_line sal
;
4625 struct breakpoint
*b
;
4626 int thread
= -1; /* All threads. */
4633 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4634 set_breakpoint_count (breakpoint_count
+ 1);
4635 b
->number
= breakpoint_count
;
4636 b
->cond_string
= (cond_string
== NULL
) ?
4637 NULL
: savestring (cond_string
, strlen (cond_string
));
4639 b
->addr_string
= NULL
;
4640 b
->enable_state
= bp_enabled
;
4641 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4647 hw_breakpoint_used_count (void)
4649 struct breakpoint
*b
;
4654 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4662 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4664 struct breakpoint
*b
;
4667 *other_type_used
= 0;
4670 if (breakpoint_enabled (b
))
4672 if (b
->type
== type
)
4674 else if ((b
->type
== bp_hardware_watchpoint
||
4675 b
->type
== bp_read_watchpoint
||
4676 b
->type
== bp_access_watchpoint
))
4677 *other_type_used
= 1;
4683 /* Call this after hitting the longjmp() breakpoint. Use this to set
4684 a new breakpoint at the target of the jmp_buf.
4686 FIXME - This ought to be done by setting a temporary breakpoint
4687 that gets deleted automatically... */
4690 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4692 struct breakpoint
*b
;
4695 if (b
->type
== bp_longjmp_resume
)
4697 b
->loc
->requested_address
= pc
;
4698 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4700 b
->enable_state
= bp_enabled
;
4701 b
->frame_id
= frame_id
;
4702 check_duplicates (b
);
4708 disable_watchpoints_before_interactive_call_start (void)
4710 struct breakpoint
*b
;
4714 if (((b
->type
== bp_watchpoint
)
4715 || (b
->type
== bp_hardware_watchpoint
)
4716 || (b
->type
== bp_read_watchpoint
)
4717 || (b
->type
== bp_access_watchpoint
)
4718 || ep_is_exception_catchpoint (b
))
4719 && breakpoint_enabled (b
))
4721 b
->enable_state
= bp_call_disabled
;
4722 check_duplicates (b
);
4728 enable_watchpoints_after_interactive_call_stop (void)
4730 struct breakpoint
*b
;
4734 if (((b
->type
== bp_watchpoint
)
4735 || (b
->type
== bp_hardware_watchpoint
)
4736 || (b
->type
== bp_read_watchpoint
)
4737 || (b
->type
== bp_access_watchpoint
)
4738 || ep_is_exception_catchpoint (b
))
4739 && (b
->enable_state
== bp_call_disabled
))
4741 b
->enable_state
= bp_enabled
;
4742 check_duplicates (b
);
4748 /* Set a breakpoint that will evaporate an end of command
4749 at address specified by SAL.
4750 Restrict it to frame FRAME if FRAME is nonzero. */
4753 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4756 struct breakpoint
*b
;
4757 b
= set_raw_breakpoint (sal
, type
);
4758 b
->enable_state
= bp_enabled
;
4759 b
->disposition
= disp_donttouch
;
4760 b
->frame_id
= frame_id
;
4762 /* If we're debugging a multi-threaded program, then we
4763 want momentary breakpoints to be active in only a
4764 single thread of control. */
4765 if (in_thread_list (inferior_ptid
))
4766 b
->thread
= pid_to_thread_id (inferior_ptid
);
4772 /* Tell the user we have just set a breakpoint B. */
4775 mention (struct breakpoint
*b
)
4778 struct cleanup
*old_chain
, *ui_out_chain
;
4779 struct ui_stream
*stb
;
4781 stb
= ui_out_stream_new (uiout
);
4782 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4784 /* FIXME: This is misplaced; mention() is called by things (like
4785 hitting a watchpoint) other than breakpoint creation. It should
4786 be possible to clean this up and at the same time replace the
4787 random calls to breakpoint_changed with this hook, as has already
4788 been done for deprecated_delete_breakpoint_hook and so on. */
4789 if (deprecated_create_breakpoint_hook
)
4790 deprecated_create_breakpoint_hook (b
);
4791 breakpoint_create_event (b
->number
);
4793 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4794 b
->ops
->print_mention (b
);
4799 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4802 ui_out_text (uiout
, "Watchpoint ");
4803 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4804 ui_out_field_int (uiout
, "number", b
->number
);
4805 ui_out_text (uiout
, ": ");
4806 print_expression (b
->exp
, stb
->stream
);
4807 ui_out_field_stream (uiout
, "exp", stb
);
4808 do_cleanups (ui_out_chain
);
4810 case bp_hardware_watchpoint
:
4811 ui_out_text (uiout
, "Hardware watchpoint ");
4812 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4813 ui_out_field_int (uiout
, "number", b
->number
);
4814 ui_out_text (uiout
, ": ");
4815 print_expression (b
->exp
, stb
->stream
);
4816 ui_out_field_stream (uiout
, "exp", stb
);
4817 do_cleanups (ui_out_chain
);
4819 case bp_read_watchpoint
:
4820 ui_out_text (uiout
, "Hardware read watchpoint ");
4821 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4822 ui_out_field_int (uiout
, "number", b
->number
);
4823 ui_out_text (uiout
, ": ");
4824 print_expression (b
->exp
, stb
->stream
);
4825 ui_out_field_stream (uiout
, "exp", stb
);
4826 do_cleanups (ui_out_chain
);
4828 case bp_access_watchpoint
:
4829 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4830 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4831 ui_out_field_int (uiout
, "number", b
->number
);
4832 ui_out_text (uiout
, ": ");
4833 print_expression (b
->exp
, stb
->stream
);
4834 ui_out_field_stream (uiout
, "exp", stb
);
4835 do_cleanups (ui_out_chain
);
4838 if (ui_out_is_mi_like_p (uiout
))
4843 printf_filtered (_("Breakpoint %d"), b
->number
);
4846 case bp_hardware_breakpoint
:
4847 if (ui_out_is_mi_like_p (uiout
))
4852 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4856 case bp_catch_unload
:
4857 printf_filtered (_("Catchpoint %d (%s %s)"),
4859 (b
->type
== bp_catch_load
) ? "load" : "unload",
4860 (b
->dll_pathname
!= NULL
) ?
4861 b
->dll_pathname
: "<any library>");
4864 case bp_catch_vfork
:
4865 printf_filtered (_("Catchpoint %d (%s)"),
4867 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4870 printf_filtered (_("Catchpoint %d (exec)"),
4873 case bp_catch_catch
:
4874 case bp_catch_throw
:
4875 printf_filtered (_("Catchpoint %d (%s)"),
4877 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4883 case bp_longjmp_resume
:
4884 case bp_step_resume
:
4886 case bp_watchpoint_scope
:
4887 case bp_shlib_event
:
4888 case bp_thread_event
:
4889 case bp_overlay_event
:
4895 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4899 printf_filtered (_(" (%s) pending."), b
->addr_string
);
4903 if (addressprint
|| b
->source_file
== NULL
)
4905 printf_filtered (" at ");
4906 deprecated_print_address_numeric (b
->loc
->address
, 1, gdb_stdout
);
4909 printf_filtered (": file %s, line %d.",
4910 b
->source_file
, b
->line_number
);
4913 do_cleanups (old_chain
);
4914 if (ui_out_is_mi_like_p (uiout
))
4916 printf_filtered ("\n");
4921 /* Create a breakpoint with SAL as location. Use ADDR_STRING
4922 as textual description of the location, and COND_STRING
4923 as condition expression.
4925 The paramter PENDING_BP is same as for the
4926 create_breakpoints function. */
4929 create_breakpoint (struct symtab_and_line sal
, char *addr_string
,
4931 enum bptype type
, enum bpdisp disposition
,
4932 int thread
, int ignore_count
, int from_tty
,
4933 struct breakpoint
*pending_bp
)
4935 struct breakpoint
*b
;
4937 if (type
== bp_hardware_breakpoint
)
4939 int i
= hw_breakpoint_used_count ();
4940 int target_resources_ok
=
4941 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4943 if (target_resources_ok
== 0)
4944 error (_("No hardware breakpoint support in the target."));
4945 else if (target_resources_ok
< 0)
4946 error (_("Hardware breakpoints used exceeds limit."));
4950 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
4952 b
= set_raw_breakpoint (sal
, type
);
4953 set_breakpoint_count (breakpoint_count
+ 1);
4954 b
->number
= breakpoint_count
;
4957 b
->cond_string
= cond_string
;
4958 b
->ignore_count
= ignore_count
;
4959 b
->enable_state
= bp_enabled
;
4960 b
->disposition
= disposition
;
4961 /* If resolving a pending breakpoint, a check must be made to see if
4962 the user has specified a new condition or commands for the
4963 breakpoint. A new condition will override any condition that was
4964 initially specified with the initial breakpoint command. */
4967 if (pending_bp
->cond_string
)
4968 b
->cond_string
= savestring (pending_bp
->cond_string
,
4969 strlen (pending_bp
->cond_string
));
4971 /* If there are commands associated with the breakpoint, they should
4973 if (pending_bp
->commands
)
4974 b
->commands
= copy_command_lines (pending_bp
->commands
);
4976 /* We have to copy over the ignore_count and thread as well. */
4977 b
->ignore_count
= pending_bp
->ignore_count
;
4978 b
->thread
= pending_bp
->thread
;
4983 char *arg
= b
->cond_string
;
4984 b
->loc
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->loc
->address
), 0);
4988 error (_("Junk at end of pending breakpoint condition expression"));
4990 error (_("Garbage %s follows condition"), arg
);
4995 b
->addr_string
= addr_string
;
4997 /* addr_string has to be used or breakpoint_re_set will delete
4999 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5004 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5005 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5006 value. COND_STRING, if not NULL, specified the condition to be
5007 used for all breakpoints. Essentially the only case where
5008 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5009 function. In that case, it's still not possible to specify
5010 separate conditions for different overloaded functions, so
5011 we take just a single condition string.
5013 The parameter PENDING_BP points to a pending breakpoint that is
5014 the basis of the breakpoints currently being created. The pending
5015 breakpoint may contain a separate condition string or commands
5016 that were added after the initial pending breakpoint was created.
5018 NOTE: If the function succeeds, the caller is expected to cleanup
5019 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5020 array contents). If the function fails (error() is called), the
5021 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5022 COND and SALS arrays and each of those arrays contents. */
5025 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5027 enum bptype type
, enum bpdisp disposition
,
5028 int thread
, int ignore_count
, int from_tty
,
5029 struct breakpoint
*pending_bp
)
5032 for (i
= 0; i
< sals
.nelts
; ++i
)
5034 create_breakpoint (sals
.sals
[i
], addr_string
[i
],
5035 cond_string
, type
, disposition
,
5036 thread
, ignore_count
, from_tty
,
5041 /* Parse ARG which is assumed to be a SAL specification possibly
5042 followed by conditionals. On return, SALS contains an array of SAL
5043 addresses found. ADDR_STRING contains a vector of (canonical)
5044 address strings. ARG points to the end of the SAL. */
5047 parse_breakpoint_sals (char **address
,
5048 struct symtabs_and_lines
*sals
,
5049 char ***addr_string
,
5052 char *addr_start
= *address
;
5053 *addr_string
= NULL
;
5054 /* If no arg given, or if first arg is 'if ', use the default
5056 if ((*address
) == NULL
5057 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5059 if (default_breakpoint_valid
)
5061 struct symtab_and_line sal
;
5062 init_sal (&sal
); /* initialize to zeroes */
5063 sals
->sals
= (struct symtab_and_line
*)
5064 xmalloc (sizeof (struct symtab_and_line
));
5065 sal
.pc
= default_breakpoint_address
;
5066 sal
.line
= default_breakpoint_line
;
5067 sal
.symtab
= default_breakpoint_symtab
;
5068 sal
.section
= find_pc_overlay (sal
.pc
);
5069 sals
->sals
[0] = sal
;
5073 error (_("No default breakpoint address now."));
5077 /* Force almost all breakpoints to be in terms of the
5078 current_source_symtab (which is decode_line_1's default). This
5079 should produce the results we want almost all of the time while
5080 leaving default_breakpoint_* alone.
5081 ObjC: However, don't match an Objective-C method name which
5082 may have a '+' or '-' succeeded by a '[' */
5084 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5086 if (default_breakpoint_valid
5088 || ((strchr ("+-", (*address
)[0]) != NULL
)
5089 && ((*address
)[1] != '['))))
5090 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5091 default_breakpoint_line
, addr_string
,
5094 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5095 addr_string
, not_found_ptr
);
5097 /* For any SAL that didn't have a canonical string, fill one in. */
5098 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5099 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5100 if (addr_start
!= (*address
))
5103 for (i
= 0; i
< sals
->nelts
; i
++)
5105 /* Add the string if not present. */
5106 if ((*addr_string
)[i
] == NULL
)
5107 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5113 /* Convert each SAL into a real PC. Verify that the PC can be
5114 inserted as a breakpoint. If it can't throw an error. */
5117 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5121 for (i
= 0; i
< sals
->nelts
; i
++)
5123 resolve_sal_pc (&sals
->sals
[i
]);
5125 /* It's possible for the PC to be nonzero, but still an illegal
5126 value on some targets.
5128 For example, on HP-UX if you start gdb, and before running the
5129 inferior you try to set a breakpoint on a shared library function
5130 "foo" where the inferior doesn't call "foo" directly but does
5131 pass its address to another function call, then we do find a
5132 minimal symbol for the "foo", but it's address is invalid.
5133 (Appears to be an index into a table that the loader sets up
5134 when the inferior is run.)
5136 Give the target a chance to bless sals.sals[i].pc before we
5137 try to make a breakpoint for it. */
5138 #ifdef DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE
5139 if (DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE (sals
->sals
[i
].pc
))
5141 if (address
== NULL
)
5142 error (_("Cannot break without a running program."));
5144 error (_("Cannot break on %s without a running program."),
5152 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5154 struct captured_parse_breakpoint_args
*args
= data
;
5156 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5157 args
->not_found_ptr
);
5160 /* Given TOK, a string specification of condition and thread, as
5161 accepted by the 'break' command, extract the condition
5162 string and thread number and set *COND_STRING and *THREAD.
5163 PC identifies the context at which the condition should be parsed.
5164 If no condition is found, *COND_STRING is set to NULL.
5165 If no thread is found, *THREAD is set to -1. */
5167 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5168 char **cond_string
, int *thread
)
5170 *cond_string
= NULL
;
5176 char *cond_start
= NULL
;
5177 char *cond_end
= NULL
;
5178 while (*tok
== ' ' || *tok
== '\t')
5183 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5186 toklen
= end_tok
- tok
;
5188 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5190 tok
= cond_start
= end_tok
+ 1;
5191 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5193 *cond_string
= savestring (cond_start
,
5194 cond_end
- cond_start
);
5196 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5202 *thread
= strtol (tok
, &tok
, 0);
5204 error (_("Junk after thread keyword."));
5205 if (!valid_thread_id (*thread
))
5206 error (_("Unknown thread %d."), *thread
);
5209 error (_("Junk at end of arguments."));
5213 /* Set a breakpoint according to ARG (function, linenum or *address)
5214 flag: first bit : 0 non-temporary, 1 temporary.
5215 second bit : 0 normal breakpoint, 1 hardware breakpoint.
5217 PENDING_BP is non-NULL when this function is being called to resolve
5218 a pending breakpoint. */
5221 break_command_1 (char *arg
, int flag
, int from_tty
, struct breakpoint
*pending_bp
)
5223 struct gdb_exception e
;
5224 int tempflag
, hardwareflag
;
5225 struct symtabs_and_lines sals
;
5226 struct symtab_and_line pending_sal
;
5227 char *cond_string
= NULL
;
5230 char *addr_start
= arg
;
5232 struct cleanup
*old_chain
;
5233 struct cleanup
*breakpoint_chain
= NULL
;
5234 struct captured_parse_breakpoint_args parse_args
;
5238 int ignore_count
= 0;
5241 hardwareflag
= flag
& BP_HARDWAREFLAG
;
5242 tempflag
= flag
& BP_TEMPFLAG
;
5248 parse_args
.arg_p
= &arg
;
5249 parse_args
.sals_p
= &sals
;
5250 parse_args
.addr_string_p
= &addr_string
;
5251 parse_args
.not_found_ptr
= ¬_found
;
5253 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5254 &parse_args
, RETURN_MASK_ALL
);
5256 /* If caller is interested in rc value from parse, set value. */
5260 exception_print (gdb_stderr
, e
);
5265 case NOT_FOUND_ERROR
:
5266 /* If called to resolve pending breakpoint, just return
5271 exception_print (gdb_stderr
, e
);
5273 /* If pending breakpoint support is turned off, throw
5276 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5277 deprecated_throw_reason (RETURN_ERROR
);
5279 /* If pending breakpoint support is auto query and the user
5280 selects no, then simply return the error code. */
5281 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5282 !nquery ("Make breakpoint pending on future shared library load? "))
5285 /* At this point, either the user was queried about setting
5286 a pending breakpoint and selected yes, or pending
5287 breakpoint behavior is on and thus a pending breakpoint
5288 is defaulted on behalf of the user. */
5289 copy_arg
= xstrdup (addr_start
);
5290 addr_string
= ©_arg
;
5292 sals
.sals
= &pending_sal
;
5297 exception_print (gdb_stderr
, e
);
5305 /* Create a chain of things that always need to be cleaned up. */
5306 old_chain
= make_cleanup (null_cleanup
, 0);
5310 /* Make sure that all storage allocated to SALS gets freed. */
5311 make_cleanup (xfree
, sals
.sals
);
5313 /* Cleanup the addr_string array but not its contents. */
5314 make_cleanup (xfree
, addr_string
);
5317 /* ----------------------------- SNIP -----------------------------
5318 Anything added to the cleanup chain beyond this point is assumed
5319 to be part of a breakpoint. If the breakpoint create succeeds
5320 then the memory is not reclaimed. */
5321 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5323 /* Mark the contents of the addr_string for cleanup. These go on
5324 the breakpoint_chain and only occure if the breakpoint create
5326 for (i
= 0; i
< sals
.nelts
; i
++)
5328 if (addr_string
[i
] != NULL
)
5329 make_cleanup (xfree
, addr_string
[i
]);
5332 /* Resolve all line numbers to PC's and verify that the addresses
5333 are ok for the target. */
5335 breakpoint_sals_to_pc (&sals
, addr_start
);
5337 /* Verify that condition can be parsed, before setting any
5338 breakpoints. Allocate a separate condition expression for each
5342 /* Here we only parse 'arg' to separate condition
5343 from thread number, so parsing in context of first
5344 sal is OK. When setting the breakpoint we'll
5345 re-parse it in context of each sal. */
5346 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5348 make_cleanup (xfree
, cond_string
);
5349 create_breakpoints (sals
, addr_string
, cond_string
,
5350 hardwareflag
? bp_hardware_breakpoint
5352 tempflag
? disp_del
: disp_donttouch
,
5353 thread
, ignore_count
, from_tty
,
5358 struct symtab_and_line sal
= {0};
5359 struct breakpoint
*b
;
5361 make_cleanup (xfree
, copy_arg
);
5363 b
= set_raw_breakpoint (sal
, hardwareflag
? bp_hardware_breakpoint
5365 set_breakpoint_count (breakpoint_count
+ 1);
5366 b
->number
= breakpoint_count
;
5367 b
->loc
->cond
= NULL
;
5369 b
->addr_string
= addr_string
[0];
5370 b
->cond_string
= cond_string
;
5371 b
->ignore_count
= ignore_count
;
5373 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5374 b
->from_tty
= from_tty
;
5380 warning (_("Multiple breakpoints were set.\n"
5381 "Use the \"delete\" command to delete unwanted breakpoints."));
5382 /* That's it. Discard the cleanups for data inserted into the
5384 discard_cleanups (breakpoint_chain
);
5385 /* But cleanup everything else. */
5386 do_cleanups (old_chain
);
5391 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5392 linenum or *address) with COND and IGNORE_COUNT. */
5394 struct captured_breakpoint_args
5405 do_captured_breakpoint (struct ui_out
*uiout
, void *data
)
5407 struct captured_breakpoint_args
*args
= data
;
5408 struct symtabs_and_lines sals
;
5409 struct expression
**cond
;
5410 struct cleanup
*old_chain
;
5411 struct cleanup
*breakpoint_chain
= NULL
;
5418 /* Parse the source and lines spec. Delay check that the expression
5419 didn't contain trailing garbage until after cleanups are in
5423 address_end
= args
->address
;
5425 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
, 0);
5430 /* Create a chain of things at always need to be cleaned up. */
5431 old_chain
= make_cleanup (null_cleanup
, 0);
5433 /* Always have a addr_string array, even if it is empty. */
5434 make_cleanup (xfree
, addr_string
);
5436 /* Make sure that all storage allocated to SALS gets freed. */
5437 make_cleanup (xfree
, sals
.sals
);
5439 /* Allocate space for all the cond expressions. */
5440 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5441 make_cleanup (xfree
, cond
);
5443 /* Allocate space for all the cond strings. */
5444 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
5445 make_cleanup (xfree
, cond_string
);
5447 /* ----------------------------- SNIP -----------------------------
5448 Anything added to the cleanup chain beyond this point is assumed
5449 to be part of a breakpoint. If the breakpoint create goes
5450 through then that memory is not cleaned up. */
5451 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5453 /* Mark the contents of the addr_string for cleanup. These go on
5454 the breakpoint_chain and only occure if the breakpoint create
5456 for (i
= 0; i
< sals
.nelts
; i
++)
5458 if (addr_string
[i
] != NULL
)
5459 make_cleanup (xfree
, addr_string
[i
]);
5462 /* Wait until now before checking for garbage at the end of the
5463 address. That way cleanups can take care of freeing any
5465 if (*address_end
!= '\0')
5466 error (_("Garbage %s following breakpoint address"), address_end
);
5468 /* Resolve all line numbers to PC's. */
5469 breakpoint_sals_to_pc (&sals
, args
->address
);
5471 if (args
->condition
!= NULL
)
5473 cond_string
= xstrdup (args
->condition
);
5474 make_cleanup (xfree
, cond_string
);
5477 create_breakpoints (sals
, addr_string
, args
->condition
,
5478 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
5479 args
->tempflag
? disp_del
: disp_donttouch
,
5480 args
->thread
, args
->ignore_count
, 0/*from-tty*/,
5481 NULL
/*pending_bp*/);
5483 /* That's it. Discard the cleanups for data inserted into the
5485 discard_cleanups (breakpoint_chain
);
5486 /* But cleanup everything else. */
5487 do_cleanups (old_chain
);
5492 gdb_breakpoint (char *address
, char *condition
,
5493 int hardwareflag
, int tempflag
,
5494 int thread
, int ignore_count
,
5495 char **error_message
)
5497 struct captured_breakpoint_args args
;
5498 args
.address
= address
;
5499 args
.condition
= condition
;
5500 args
.hardwareflag
= hardwareflag
;
5501 args
.tempflag
= tempflag
;
5502 args
.thread
= thread
;
5503 args
.ignore_count
= ignore_count
;
5504 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint
, &args
,
5505 error_message
, RETURN_MASK_ALL
) < 0)
5512 /* Helper function for break_command_1 and disassemble_command. */
5515 resolve_sal_pc (struct symtab_and_line
*sal
)
5519 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5521 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5522 error (_("No line %d in file \"%s\"."),
5523 sal
->line
, sal
->symtab
->filename
);
5527 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5529 struct blockvector
*bv
;
5534 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5537 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5538 sym
= block_function (b
);
5541 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5542 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5546 /* It really is worthwhile to have the section, so we'll just
5547 have to look harder. This case can be executed if we have
5548 line numbers but no functions (as can happen in assembly
5551 struct minimal_symbol
*msym
;
5553 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5555 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5562 break_command (char *arg
, int from_tty
)
5564 break_command_1 (arg
, 0, from_tty
, NULL
);
5568 tbreak_command (char *arg
, int from_tty
)
5570 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
, NULL
);
5574 hbreak_command (char *arg
, int from_tty
)
5576 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
, NULL
);
5580 thbreak_command (char *arg
, int from_tty
)
5582 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
, NULL
);
5586 stop_command (char *arg
, int from_tty
)
5588 printf_filtered (_("Specify the type of breakpoint to set.\n\
5589 Usage: stop in <function | address>\n\
5590 stop at <line>\n"));
5594 stopin_command (char *arg
, int from_tty
)
5598 if (arg
== (char *) NULL
)
5600 else if (*arg
!= '*')
5605 /* look for a ':'. If this is a line number specification, then
5606 say it is bad, otherwise, it should be an address or
5607 function/method name */
5608 while (*argptr
&& !hasColon
)
5610 hasColon
= (*argptr
== ':');
5615 badInput
= (*argptr
!= ':'); /* Not a class::method */
5617 badInput
= isdigit (*arg
); /* a simple line number */
5621 printf_filtered (_("Usage: stop in <function | address>\n"));
5623 break_command_1 (arg
, 0, from_tty
, NULL
);
5627 stopat_command (char *arg
, int from_tty
)
5631 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5638 /* look for a ':'. If there is a '::' then get out, otherwise
5639 it is probably a line number. */
5640 while (*argptr
&& !hasColon
)
5642 hasColon
= (*argptr
== ':');
5647 badInput
= (*argptr
== ':'); /* we have class::method */
5649 badInput
= !isdigit (*arg
); /* not a line number */
5653 printf_filtered (_("Usage: stop at <line>\n"));
5655 break_command_1 (arg
, 0, from_tty
, NULL
);
5658 /* accessflag: hw_write: watch write,
5659 hw_read: watch read,
5660 hw_access: watch access (read or write) */
5662 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5664 struct breakpoint
*b
;
5665 struct symtab_and_line sal
;
5666 struct expression
*exp
;
5667 struct block
*exp_valid_block
;
5668 struct value
*val
, *mark
;
5669 struct frame_info
*frame
;
5670 struct frame_info
*prev_frame
= NULL
;
5671 char *exp_start
= NULL
;
5672 char *exp_end
= NULL
;
5673 char *tok
, *end_tok
;
5675 char *cond_start
= NULL
;
5676 char *cond_end
= NULL
;
5677 struct expression
*cond
= NULL
;
5678 int i
, other_type_used
, target_resources_ok
= 0;
5679 enum bptype bp_type
;
5682 init_sal (&sal
); /* initialize to zeroes */
5684 /* Parse arguments. */
5685 innermost_block
= NULL
;
5687 exp
= parse_exp_1 (&arg
, 0, 0);
5689 exp_valid_block
= innermost_block
;
5690 mark
= value_mark ();
5691 val
= evaluate_expression (exp
);
5692 release_value (val
);
5693 if (value_lazy (val
))
5694 value_fetch_lazy (val
);
5697 while (*tok
== ' ' || *tok
== '\t')
5701 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5704 toklen
= end_tok
- tok
;
5705 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5707 tok
= cond_start
= end_tok
+ 1;
5708 cond
= parse_exp_1 (&tok
, 0, 0);
5712 error (_("Junk at end of command."));
5714 if (accessflag
== hw_read
)
5715 bp_type
= bp_read_watchpoint
;
5716 else if (accessflag
== hw_access
)
5717 bp_type
= bp_access_watchpoint
;
5719 bp_type
= bp_hardware_watchpoint
;
5721 mem_cnt
= can_use_hardware_watchpoint (val
);
5722 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5723 error (_("Expression cannot be implemented with read/access watchpoint."));
5726 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5727 target_resources_ok
=
5728 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5730 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5731 error (_("Target does not support this type of hardware watchpoint."));
5733 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5734 error (_("Target can only support one kind of HW watchpoint at a time."));
5737 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5738 watchpoint could not be set. */
5739 if (!mem_cnt
|| target_resources_ok
<= 0)
5740 bp_type
= bp_watchpoint
;
5742 /* Now set up the breakpoint. */
5743 b
= set_raw_breakpoint (sal
, bp_type
);
5744 set_breakpoint_count (breakpoint_count
+ 1);
5745 b
->number
= breakpoint_count
;
5746 b
->disposition
= disp_donttouch
;
5748 b
->exp_valid_block
= exp_valid_block
;
5749 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5751 b
->loc
->cond
= cond
;
5753 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5757 frame
= block_innermost_frame (exp_valid_block
);
5760 prev_frame
= get_prev_frame (frame
);
5761 b
->watchpoint_frame
= get_frame_id (frame
);
5765 memset (&b
->watchpoint_frame
, 0, sizeof (b
->watchpoint_frame
));
5768 /* If the expression is "local", then set up a "watchpoint scope"
5769 breakpoint at the point where we've left the scope of the watchpoint
5771 if (innermost_block
)
5775 struct breakpoint
*scope_breakpoint
;
5776 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5777 bp_watchpoint_scope
);
5779 scope_breakpoint
->enable_state
= bp_enabled
;
5781 /* Automatically delete the breakpoint when it hits. */
5782 scope_breakpoint
->disposition
= disp_del
;
5784 /* Only break in the proper frame (help with recursion). */
5785 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5787 /* Set the address at which we will stop. */
5788 scope_breakpoint
->loc
->requested_address
5789 = get_frame_pc (prev_frame
);
5790 scope_breakpoint
->loc
->address
5791 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5792 scope_breakpoint
->type
);
5794 /* The scope breakpoint is related to the watchpoint. We
5795 will need to act on them together. */
5796 b
->related_breakpoint
= scope_breakpoint
;
5799 value_free_to_mark (mark
);
5803 /* Return count of locations need to be watched and can be handled
5804 in hardware. If the watchpoint can not be handled
5805 in hardware return zero. */
5808 can_use_hardware_watchpoint (struct value
*v
)
5810 int found_memory_cnt
= 0;
5811 struct value
*head
= v
;
5813 /* Did the user specifically forbid us to use hardware watchpoints? */
5814 if (!can_use_hw_watchpoints
)
5817 /* Make sure that the value of the expression depends only upon
5818 memory contents, and values computed from them within GDB. If we
5819 find any register references or function calls, we can't use a
5820 hardware watchpoint.
5822 The idea here is that evaluating an expression generates a series
5823 of values, one holding the value of every subexpression. (The
5824 expression a*b+c has five subexpressions: a, b, a*b, c, and
5825 a*b+c.) GDB's values hold almost enough information to establish
5826 the criteria given above --- they identify memory lvalues,
5827 register lvalues, computed values, etcetera. So we can evaluate
5828 the expression, and then scan the chain of values that leaves
5829 behind to decide whether we can detect any possible change to the
5830 expression's final value using only hardware watchpoints.
5832 However, I don't think that the values returned by inferior
5833 function calls are special in any way. So this function may not
5834 notice that an expression involving an inferior function call
5835 can't be watched with hardware watchpoints. FIXME. */
5836 for (; v
; v
= value_next (v
))
5838 if (VALUE_LVAL (v
) == lval_memory
)
5841 /* A lazy memory lvalue is one that GDB never needed to fetch;
5842 we either just used its address (e.g., `a' in `a.b') or
5843 we never needed it at all (e.g., `a' in `a,b'). */
5847 /* Ahh, memory we actually used! Check if we can cover
5848 it with hardware watchpoints. */
5849 struct type
*vtype
= check_typedef (value_type (v
));
5851 /* We only watch structs and arrays if user asked for it
5852 explicitly, never if they just happen to appear in a
5853 middle of some value chain. */
5855 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5856 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5858 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
5859 int len
= TYPE_LENGTH (value_type (v
));
5861 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5868 else if (VALUE_LVAL (v
) != not_lval
5869 && deprecated_value_modifiable (v
) == 0)
5870 return 0; /* ??? What does this represent? */
5871 else if (VALUE_LVAL (v
) == lval_register
)
5872 return 0; /* cannot watch a register with a HW watchpoint */
5875 /* The expression itself looks suitable for using a hardware
5876 watchpoint, but give the target machine a chance to reject it. */
5877 return found_memory_cnt
;
5881 watch_command_wrapper (char *arg
, int from_tty
)
5883 watch_command (arg
, from_tty
);
5887 watch_command (char *arg
, int from_tty
)
5889 watch_command_1 (arg
, hw_write
, from_tty
);
5893 rwatch_command_wrapper (char *arg
, int from_tty
)
5895 rwatch_command (arg
, from_tty
);
5899 rwatch_command (char *arg
, int from_tty
)
5901 watch_command_1 (arg
, hw_read
, from_tty
);
5905 awatch_command_wrapper (char *arg
, int from_tty
)
5907 awatch_command (arg
, from_tty
);
5911 awatch_command (char *arg
, int from_tty
)
5913 watch_command_1 (arg
, hw_access
, from_tty
);
5917 /* Helper routines for the until_command routine in infcmd.c. Here
5918 because it uses the mechanisms of breakpoints. */
5920 /* This function is called by fetch_inferior_event via the
5921 cmd_continuation pointer, to complete the until command. It takes
5922 care of cleaning up the temporary breakpoints set up by the until
5925 until_break_command_continuation (struct continuation_arg
*arg
)
5927 struct cleanup
*cleanups
;
5929 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
5930 do_exec_cleanups (cleanups
);
5934 until_break_command (char *arg
, int from_tty
, int anywhere
)
5936 struct symtabs_and_lines sals
;
5937 struct symtab_and_line sal
;
5938 struct frame_info
*frame
= get_selected_frame (NULL
);
5939 struct frame_info
*prev_frame
= get_prev_frame (frame
);
5940 struct breakpoint
*breakpoint
;
5941 struct cleanup
*old_chain
;
5942 struct continuation_arg
*arg1
;
5945 clear_proceed_status ();
5947 /* Set a breakpoint where the user wants it and at return from
5950 if (default_breakpoint_valid
)
5951 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
5952 default_breakpoint_line
, (char ***) NULL
, NULL
);
5954 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
5955 0, (char ***) NULL
, NULL
);
5957 if (sals
.nelts
!= 1)
5958 error (_("Couldn't get information on specified line."));
5961 xfree (sals
.sals
); /* malloc'd, so freed */
5964 error (_("Junk at end of arguments."));
5966 resolve_sal_pc (&sal
);
5969 /* If the user told us to continue until a specified location,
5970 we don't specify a frame at which we need to stop. */
5971 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
5973 /* Otherwise, specify the current frame, because we want to stop only
5974 at the very same frame. */
5975 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
5978 if (!target_can_async_p ())
5979 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
5981 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
5983 /* If we are running asynchronously, and the target supports async
5984 execution, we are not waiting for the target to stop, in the call
5985 tp proceed, below. This means that we cannot delete the
5986 brekpoints until the target has actually stopped. The only place
5987 where we get a chance to do that is in fetch_inferior_event, so
5988 we must set things up for that. */
5990 if (target_can_async_p ())
5992 /* In this case the arg for the continuation is just the point
5993 in the exec_cleanups chain from where to start doing
5994 cleanups, because all the continuation does is the cleanups in
5995 the exec_cleanup_chain. */
5997 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
5999 arg1
->data
.pointer
= old_chain
;
6001 add_continuation (until_break_command_continuation
, arg1
);
6004 /* Keep within the current frame, or in frames called by the current
6008 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6009 sal
.pc
= get_frame_pc (prev_frame
);
6010 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6012 if (!target_can_async_p ())
6013 make_cleanup_delete_breakpoint (breakpoint
);
6015 make_exec_cleanup_delete_breakpoint (breakpoint
);
6018 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6019 /* Do the cleanups now, anly if we are not running asynchronously,
6020 of if we are, but the target is still synchronous. */
6021 if (!target_can_async_p ())
6022 do_cleanups (old_chain
);
6026 ep_skip_leading_whitespace (char **s
)
6028 if ((s
== NULL
) || (*s
== NULL
))
6030 while (isspace (**s
))
6034 /* This function examines a string, and attempts to find a token
6035 that might be an event name in the leading characters. If a
6036 possible match is found, a pointer to the last character of
6037 the token is returned. Else, NULL is returned. */
6040 ep_find_event_name_end (char *arg
)
6043 char *event_name_end
= NULL
;
6045 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6049 /* We break out of the loop when we find a token delimiter.
6050 Basically, we're looking for alphanumerics and underscores;
6051 anything else delimites the token. */
6054 if (!isalnum (*s
) && (*s
!= '_'))
6060 return event_name_end
;
6064 /* This function attempts to parse an optional "if <cond>" clause
6065 from the arg string. If one is not found, it returns NULL.
6067 Else, it returns a pointer to the condition string. (It does not
6068 attempt to evaluate the string against a particular block.) And,
6069 it updates arg to point to the first character following the parsed
6070 if clause in the arg string. */
6073 ep_parse_optional_if_clause (char **arg
)
6077 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6080 /* Skip the "if" keyword. */
6083 /* Skip any extra leading whitespace, and record the start of the
6084 condition string. */
6085 ep_skip_leading_whitespace (arg
);
6088 /* Assume that the condition occupies the remainder of the arg string. */
6089 (*arg
) += strlen (cond_string
);
6094 /* This function attempts to parse an optional filename from the arg
6095 string. If one is not found, it returns NULL.
6097 Else, it returns a pointer to the parsed filename. (This function
6098 makes no attempt to verify that a file of that name exists, or is
6099 accessible.) And, it updates arg to point to the first character
6100 following the parsed filename in the arg string.
6102 Note that clients needing to preserve the returned filename for
6103 future access should copy it to their own buffers. */
6105 ep_parse_optional_filename (char **arg
)
6107 static char filename
[1024];
6112 if ((*arg_p
== '\0') || isspace (*arg_p
))
6130 /* Commands to deal with catching events, such as signals, exceptions,
6131 process start/exit, etc. */
6135 catch_fork
, catch_vfork
6140 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6143 char *cond_string
= NULL
;
6145 ep_skip_leading_whitespace (&arg
);
6147 /* The allowed syntax is:
6149 catch [v]fork if <cond>
6151 First, check if there's an if clause. */
6152 cond_string
= ep_parse_optional_if_clause (&arg
);
6154 if ((*arg
!= '\0') && !isspace (*arg
))
6155 error (_("Junk at end of arguments."));
6157 /* If this target supports it, create a fork or vfork catchpoint
6158 and enable reporting of such events. */
6162 create_fork_event_catchpoint (tempflag
, cond_string
);
6165 create_vfork_event_catchpoint (tempflag
, cond_string
);
6168 error (_("unsupported or unknown fork kind; cannot catch it"));
6174 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6176 char *cond_string
= NULL
;
6178 ep_skip_leading_whitespace (&arg
);
6180 /* The allowed syntax is:
6182 catch exec if <cond>
6184 First, check if there's an if clause. */
6185 cond_string
= ep_parse_optional_if_clause (&arg
);
6187 if ((*arg
!= '\0') && !isspace (*arg
))
6188 error (_("Junk at end of arguments."));
6190 /* If this target supports it, create an exec catchpoint
6191 and enable reporting of such events. */
6192 create_exec_event_catchpoint (tempflag
, cond_string
);
6196 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6198 char *dll_pathname
= NULL
;
6199 char *cond_string
= NULL
;
6201 ep_skip_leading_whitespace (&arg
);
6203 /* The allowed syntax is:
6205 catch load if <cond>
6206 catch load <filename>
6207 catch load <filename> if <cond>
6209 The user is not allowed to specify the <filename> after an
6212 We'll ignore the pathological case of a file named "if".
6214 First, check if there's an if clause. If so, then there
6215 cannot be a filename. */
6216 cond_string
= ep_parse_optional_if_clause (&arg
);
6218 /* If there was an if clause, then there cannot be a filename.
6219 Else, there might be a filename and an if clause. */
6220 if (cond_string
== NULL
)
6222 dll_pathname
= ep_parse_optional_filename (&arg
);
6223 ep_skip_leading_whitespace (&arg
);
6224 cond_string
= ep_parse_optional_if_clause (&arg
);
6227 if ((*arg
!= '\0') && !isspace (*arg
))
6228 error (_("Junk at end of arguments."));
6230 /* Create a load breakpoint that only triggers when a load of
6231 the specified dll (or any dll, if no pathname was specified)
6233 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6234 dll_pathname
, cond_string
);
6238 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6240 char *dll_pathname
= NULL
;
6241 char *cond_string
= NULL
;
6243 ep_skip_leading_whitespace (&arg
);
6245 /* The allowed syntax is:
6247 catch unload if <cond>
6248 catch unload <filename>
6249 catch unload <filename> if <cond>
6251 The user is not allowed to specify the <filename> after an
6254 We'll ignore the pathological case of a file named "if".
6256 First, check if there's an if clause. If so, then there
6257 cannot be a filename. */
6258 cond_string
= ep_parse_optional_if_clause (&arg
);
6260 /* If there was an if clause, then there cannot be a filename.
6261 Else, there might be a filename and an if clause. */
6262 if (cond_string
== NULL
)
6264 dll_pathname
= ep_parse_optional_filename (&arg
);
6265 ep_skip_leading_whitespace (&arg
);
6266 cond_string
= ep_parse_optional_if_clause (&arg
);
6269 if ((*arg
!= '\0') && !isspace (*arg
))
6270 error (_("Junk at end of arguments."));
6272 /* Create an unload breakpoint that only triggers when an unload of
6273 the specified dll (or any dll, if no pathname was specified)
6275 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6276 dll_pathname
, cond_string
);
6279 /* Commands to deal with catching exceptions. */
6281 /* Set a breakpoint at the specified callback routine for an
6282 exception event callback */
6285 create_exception_catchpoint (int tempflag
, char *cond_string
,
6286 enum exception_event_kind ex_event
,
6287 struct symtab_and_line
*sal
)
6289 struct breakpoint
*b
;
6290 int thread
= -1; /* All threads. */
6293 if (!sal
) /* no exception support? */
6298 case EX_EVENT_THROW
:
6299 bptype
= bp_catch_throw
;
6301 case EX_EVENT_CATCH
:
6302 bptype
= bp_catch_catch
;
6304 default: /* error condition */
6305 error (_("Internal error -- invalid catchpoint kind"));
6308 b
= set_raw_breakpoint (*sal
, bptype
);
6309 set_breakpoint_count (breakpoint_count
+ 1);
6310 b
->number
= breakpoint_count
;
6311 b
->cond_string
= (cond_string
== NULL
) ?
6312 NULL
: savestring (cond_string
, strlen (cond_string
));
6314 b
->addr_string
= NULL
;
6315 b
->enable_state
= bp_enabled
;
6316 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6320 static enum print_stop_action
6321 print_exception_catchpoint (struct breakpoint
*b
)
6323 annotate_catchpoint (b
->number
);
6325 if (strstr (b
->addr_string
, "throw") != NULL
)
6326 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6329 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6332 return PRINT_SRC_AND_LOC
;
6336 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6341 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6344 *last_addr
= b
->loc
->address
;
6345 if (strstr (b
->addr_string
, "throw") != NULL
)
6346 ui_out_field_string (uiout
, "what", "exception throw");
6348 ui_out_field_string (uiout
, "what", "exception catch");
6352 print_mention_exception_catchpoint (struct breakpoint
*b
)
6354 if (strstr (b
->addr_string
, "throw") != NULL
)
6355 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6357 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6360 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6361 print_exception_catchpoint
,
6362 print_one_exception_catchpoint
,
6363 print_mention_exception_catchpoint
6367 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6368 enum exception_event_kind ex_event
, int from_tty
)
6370 char *trigger_func_name
, *nameptr
;
6371 struct symtabs_and_lines sals
;
6372 struct breakpoint
*b
;
6374 if (ex_event
== EX_EVENT_CATCH
)
6375 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6377 trigger_func_name
= xstrdup ("__cxa_throw");
6379 nameptr
= trigger_func_name
;
6380 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6381 if (sals
.nelts
== 0)
6383 xfree (trigger_func_name
);
6387 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6388 set_breakpoint_count (breakpoint_count
+ 1);
6389 b
->number
= breakpoint_count
;
6390 b
->cond_string
= (cond_string
== NULL
) ?
6391 NULL
: savestring (cond_string
, strlen (cond_string
));
6393 b
->addr_string
= trigger_func_name
;
6394 b
->enable_state
= bp_enabled
;
6395 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6396 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6403 /* Deal with "catch catch" and "catch throw" commands */
6406 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6407 int tempflag
, int from_tty
)
6409 char *cond_string
= NULL
;
6410 struct symtab_and_line
*sal
= NULL
;
6412 ep_skip_leading_whitespace (&arg
);
6414 cond_string
= ep_parse_optional_if_clause (&arg
);
6416 if ((*arg
!= '\0') && !isspace (*arg
))
6417 error (_("Junk at end of arguments."));
6419 if ((ex_event
!= EX_EVENT_THROW
) &&
6420 (ex_event
!= EX_EVENT_CATCH
))
6421 error (_("Unsupported or unknown exception event; cannot catch it"));
6423 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6426 /* See if we can find a callback routine */
6427 sal
= target_enable_exception_callback (ex_event
, 1);
6431 /* We have callbacks from the runtime system for exceptions.
6432 Set a breakpoint on the sal found, if no errors */
6433 if (sal
!= (struct symtab_and_line
*) -1)
6434 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6436 return; /* something went wrong with setting up callbacks */
6439 warning (_("Unsupported with this platform/compiler combination."));
6442 /* Create a breakpoint struct for Ada exception catchpoints. */
6445 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6449 struct expression
*cond
,
6450 struct breakpoint_ops
*ops
,
6454 struct breakpoint
*b
;
6458 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6459 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6460 version for exception catchpoints, because two catchpoints
6461 used for different exception names will use the same address.
6462 In this case, a "breakpoint ... also set at..." warning is
6463 unproductive. Besides. the warning phrasing is also a bit
6464 inapropriate, we should use the word catchpoint, and tell
6465 the user what type of catchpoint it is. The above is good
6466 enough for now, though. */
6469 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6470 set_breakpoint_count (breakpoint_count
+ 1);
6472 b
->enable_state
= bp_enabled
;
6473 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6474 b
->number
= breakpoint_count
;
6475 b
->ignore_count
= 0;
6476 b
->loc
->cond
= cond
;
6477 b
->addr_string
= addr_string
;
6478 b
->language
= language_ada
;
6479 b
->cond_string
= cond_string
;
6480 b
->exp_string
= exp_string
;
6483 b
->from_tty
= from_tty
;
6488 /* Implement the "catch exception" command. */
6491 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6493 struct symtab_and_line sal
;
6495 char *addr_string
= NULL
;
6496 char *exp_string
= NULL
;
6497 char *cond_string
= NULL
;
6498 struct expression
*cond
= NULL
;
6499 struct breakpoint_ops
*ops
= NULL
;
6501 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6502 &cond_string
, &cond
, &ops
);
6503 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6504 cond_string
, cond
, ops
, tempflag
,
6508 /* Implement the "catch assert" command. */
6511 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6513 struct symtab_and_line sal
;
6514 char *addr_string
= NULL
;
6515 struct breakpoint_ops
*ops
= NULL
;
6517 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6518 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6519 tempflag
, from_tty
);
6522 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6523 inside a catch_errors */
6526 cover_target_enable_exception_callback (void *arg
)
6528 args_for_catchpoint_enable
*args
= arg
;
6529 struct symtab_and_line
*sal
;
6530 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6533 else if (sal
== (struct symtab_and_line
*) -1)
6536 return 1; /*is valid */
6540 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6543 /* The first argument may be an event name, such as "start" or "load".
6544 If so, then handle it as such. If it doesn't match an event name,
6545 then attempt to interpret it as an exception name. (This latter is
6546 the v4.16-and-earlier GDB meaning of the "catch" command.)
6548 First, try to find the bounds of what might be an event name. */
6549 char *arg1_start
= arg
;
6553 if (arg1_start
== NULL
)
6555 /* Old behaviour was to use pre-v-4.16 syntax */
6556 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6558 /* Now, this is not allowed */
6559 error (_("Catch requires an event name."));
6562 arg1_end
= ep_find_event_name_end (arg1_start
);
6563 if (arg1_end
== NULL
)
6564 error (_("catch requires an event"));
6565 arg1_length
= arg1_end
+ 1 - arg1_start
;
6567 /* Try to match what we found against known event names. */
6568 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6570 error (_("Catch of signal not yet implemented"));
6572 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6574 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6575 tempflag
, from_tty
);
6577 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6579 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6580 tempflag
, from_tty
);
6582 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6584 error (_("Catch of thread_start not yet implemented"));
6586 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6588 error (_("Catch of thread_exit not yet implemented"));
6590 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6592 error (_("Catch of thread_join not yet implemented"));
6594 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6596 error (_("Catch of start not yet implemented"));
6598 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6600 error (_("Catch of exit not yet implemented"));
6602 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6604 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6606 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6608 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6610 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6612 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6614 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6616 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6618 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6620 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6622 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6624 error (_("Catch of stop not yet implemented"));
6626 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6628 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6631 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6633 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6636 /* This doesn't appear to be an event name */
6640 /* Pre-v.4.16 behaviour was to treat the argument
6641 as the name of an exception */
6642 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6643 /* Now this is not allowed */
6644 error (_("Unknown event kind specified for catch"));
6649 /* Used by the gui, could be made a worker for other things. */
6652 set_breakpoint_sal (struct symtab_and_line sal
)
6654 struct breakpoint
*b
;
6655 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6656 set_breakpoint_count (breakpoint_count
+ 1);
6657 b
->number
= breakpoint_count
;
6663 catch_command (char *arg
, int from_tty
)
6665 catch_command_1 (arg
, 0, from_tty
);
6670 tcatch_command (char *arg
, int from_tty
)
6672 catch_command_1 (arg
, 1, from_tty
);
6675 /* Delete breakpoints by address or line. */
6678 clear_command (char *arg
, int from_tty
)
6680 struct breakpoint
*b
, *tmp
, *prev
, *found
;
6682 struct symtabs_and_lines sals
;
6683 struct symtab_and_line sal
;
6688 sals
= decode_line_spec (arg
, 1);
6693 sals
.sals
= (struct symtab_and_line
*)
6694 xmalloc (sizeof (struct symtab_and_line
));
6695 make_cleanup (xfree
, sals
.sals
);
6696 init_sal (&sal
); /* initialize to zeroes */
6697 sal
.line
= default_breakpoint_line
;
6698 sal
.symtab
= default_breakpoint_symtab
;
6699 sal
.pc
= default_breakpoint_address
;
6700 if (sal
.symtab
== 0)
6701 error (_("No source file specified."));
6709 /* For each line spec given, delete bps which correspond
6710 to it. Do it in two passes, solely to preserve the current
6711 behavior that from_tty is forced true if we delete more than
6715 for (i
= 0; i
< sals
.nelts
; i
++)
6717 /* If exact pc given, clear bpts at that pc.
6718 If line given (pc == 0), clear all bpts on specified line.
6719 If defaulting, clear all bpts on default line
6722 defaulting sal.pc != 0 tests to do
6727 1 0 <can't happen> */
6732 /* Find all matching breakpoints, remove them from the
6733 breakpoint chain, and add them to the 'found' chain. */
6734 ALL_BREAKPOINTS_SAFE (b
, tmp
)
6736 /* Are we going to delete b? */
6737 if (b
->type
!= bp_none
6738 && b
->type
!= bp_watchpoint
6739 && b
->type
!= bp_hardware_watchpoint
6740 && b
->type
!= bp_read_watchpoint
6741 && b
->type
!= bp_access_watchpoint
6742 /* Not if b is a watchpoint of any sort... */
6743 && (((sal
.pc
&& (b
->loc
->address
== sal
.pc
))
6744 && (!section_is_overlay (b
->loc
->section
)
6745 || b
->loc
->section
== sal
.section
))
6746 /* Yes, if sal.pc matches b (modulo overlays). */
6747 || ((default_match
|| (0 == sal
.pc
))
6748 && b
->source_file
!= NULL
6749 && sal
.symtab
!= NULL
6750 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6751 && b
->line_number
== sal
.line
)))
6752 /* Yes, if sal source file and line matches b. */
6754 /* Remove it from breakpoint_chain... */
6755 if (b
== breakpoint_chain
)
6757 /* b is at the head of the list */
6758 breakpoint_chain
= b
->next
;
6762 prev
->next
= b
->next
;
6764 /* And add it to 'found' chain. */
6770 /* Keep b, and keep a pointer to it. */
6775 /* Now go thru the 'found' chain and delete them. */
6779 error (_("No breakpoint at %s."), arg
);
6781 error (_("No breakpoint at this line."));
6785 from_tty
= 1; /* Always report if deleted more than one */
6789 printf_unfiltered (_("Deleted breakpoint "));
6791 printf_unfiltered (_("Deleted breakpoints "));
6793 breakpoints_changed ();
6797 printf_unfiltered ("%d ", found
->number
);
6799 delete_breakpoint (found
);
6803 putchar_unfiltered ('\n');
6806 /* Delete breakpoint in BS if they are `delete' breakpoints and
6807 all breakpoints that are marked for deletion, whether hit or not.
6808 This is called after any breakpoint is hit, or after errors. */
6811 breakpoint_auto_delete (bpstat bs
)
6813 struct breakpoint
*b
, *temp
;
6815 for (; bs
; bs
= bs
->next
)
6816 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
->disposition
== disp_del
6818 delete_breakpoint (bs
->breakpoint_at
->owner
);
6820 ALL_BREAKPOINTS_SAFE (b
, temp
)
6822 if (b
->disposition
== disp_del_at_next_stop
)
6823 delete_breakpoint (b
);
6827 /* Delete a breakpoint and clean up all traces of it in the data
6831 delete_breakpoint (struct breakpoint
*bpt
)
6833 struct breakpoint
*b
;
6835 struct bp_location
*loc
;
6837 gdb_assert (bpt
!= NULL
);
6839 /* Has this bp already been deleted? This can happen because multiple
6840 lists can hold pointers to bp's. bpstat lists are especial culprits.
6842 One example of this happening is a watchpoint's scope bp. When the
6843 scope bp triggers, we notice that the watchpoint is out of scope, and
6844 delete it. We also delete its scope bp. But the scope bp is marked
6845 "auto-deleting", and is already on a bpstat. That bpstat is then
6846 checked for auto-deleting bp's, which are deleted.
6848 A real solution to this problem might involve reference counts in bp's,
6849 and/or giving them pointers back to their referencing bpstat's, and
6850 teaching delete_breakpoint to only free a bp's storage when no more
6851 references were extent. A cheaper bandaid was chosen. */
6852 if (bpt
->type
== bp_none
)
6855 if (deprecated_delete_breakpoint_hook
)
6856 deprecated_delete_breakpoint_hook (bpt
);
6857 breakpoint_delete_event (bpt
->number
);
6859 if (bpt
->loc
->inserted
)
6860 remove_breakpoint (bpt
->loc
, mark_inserted
);
6862 free_valchain (bpt
->loc
);
6864 if (breakpoint_chain
== bpt
)
6865 breakpoint_chain
= bpt
->next
;
6867 if (bp_location_chain
== bpt
->loc
)
6868 bp_location_chain
= bpt
->loc
->next
;
6870 /* If we have callback-style exception catchpoints, don't go through
6871 the adjustments to the C++ runtime library etc. if the inferior
6872 isn't actually running. target_enable_exception_callback for a
6873 null target ops vector gives an undesirable error message, so we
6874 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6875 exceptions are supported in this way, it's OK for now. FIXME */
6876 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
6878 /* Format possible error msg */
6879 char *message
= xstrprintf ("Error in deleting catchpoint %d:\n",
6881 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
6882 args_for_catchpoint_enable args
;
6883 args
.kind
= bpt
->type
== bp_catch_catch
?
6884 EX_EVENT_CATCH
: EX_EVENT_THROW
;
6886 catch_errors (cover_target_enable_exception_callback
, &args
,
6887 message
, RETURN_MASK_ALL
);
6888 do_cleanups (cleanups
);
6895 b
->next
= bpt
->next
;
6899 ALL_BP_LOCATIONS (loc
)
6900 if (loc
->next
== bpt
->loc
)
6902 loc
->next
= bpt
->loc
->next
;
6906 check_duplicates (bpt
);
6907 /* If this breakpoint was inserted, and there is another breakpoint
6908 at the same address, we need to insert the other breakpoint. */
6909 if (bpt
->loc
->inserted
6910 && bpt
->type
!= bp_hardware_watchpoint
6911 && bpt
->type
!= bp_read_watchpoint
6912 && bpt
->type
!= bp_access_watchpoint
6913 && bpt
->type
!= bp_catch_fork
6914 && bpt
->type
!= bp_catch_vfork
6915 && bpt
->type
!= bp_catch_exec
)
6918 if (b
->loc
->address
== bpt
->loc
->address
6919 && b
->loc
->section
== bpt
->loc
->section
6920 && !b
->loc
->duplicate
6921 && b
->enable_state
!= bp_disabled
6922 && b
->enable_state
!= bp_shlib_disabled
6924 && b
->enable_state
!= bp_call_disabled
)
6928 /* We should never reach this point if there is a permanent
6929 breakpoint at the same address as the one being deleted.
6930 If there is a permanent breakpoint somewhere, it should
6931 always be the only one inserted. */
6932 if (b
->enable_state
== bp_permanent
)
6933 internal_error (__FILE__
, __LINE__
,
6934 _("another breakpoint was inserted on top of "
6935 "a permanent breakpoint"));
6937 memset (&b
->loc
->target_info
, 0, sizeof (b
->loc
->target_info
));
6938 b
->loc
->target_info
.placed_address
= b
->loc
->address
;
6939 if (b
->type
== bp_hardware_breakpoint
)
6940 val
= target_insert_hw_breakpoint (&b
->loc
->target_info
);
6942 val
= target_insert_breakpoint (&b
->loc
->target_info
);
6944 /* If there was an error in the insert, print a message, then stop execution. */
6947 struct ui_file
*tmp_error_stream
= mem_fileopen ();
6948 make_cleanup_ui_file_delete (tmp_error_stream
);
6951 if (b
->type
== bp_hardware_breakpoint
)
6953 fprintf_unfiltered (tmp_error_stream
,
6954 "Cannot insert hardware breakpoint %d.\n"
6955 "You may have requested too many hardware breakpoints.\n",
6960 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
6961 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
6962 deprecated_print_address_numeric (b
->loc
->address
, 1, tmp_error_stream
);
6963 fprintf_filtered (tmp_error_stream
, ": %s.\n",
6964 safe_strerror (val
));
6967 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
6968 target_terminal_ours_for_output ();
6969 error_stream(tmp_error_stream
);
6972 b
->loc
->inserted
= 1;
6976 free_command_lines (&bpt
->commands
);
6977 if (bpt
->cond_string
!= NULL
)
6978 xfree (bpt
->cond_string
);
6979 if (bpt
->addr_string
!= NULL
)
6980 xfree (bpt
->addr_string
);
6981 if (bpt
->exp
!= NULL
)
6983 if (bpt
->exp_string
!= NULL
)
6984 xfree (bpt
->exp_string
);
6985 if (bpt
->val
!= NULL
)
6986 value_free (bpt
->val
);
6987 if (bpt
->source_file
!= NULL
)
6988 xfree (bpt
->source_file
);
6989 if (bpt
->dll_pathname
!= NULL
)
6990 xfree (bpt
->dll_pathname
);
6991 if (bpt
->triggered_dll_pathname
!= NULL
)
6992 xfree (bpt
->triggered_dll_pathname
);
6993 if (bpt
->exec_pathname
!= NULL
)
6994 xfree (bpt
->exec_pathname
);
6996 /* Be sure no bpstat's are pointing at it after it's been freed. */
6997 /* FIXME, how can we find all bpstat's?
6998 We just check stop_bpstat for now. Note that we cannot just
6999 remove bpstats pointing at bpt from the stop_bpstat list
7000 entirely, as breakpoint commands are associated with the bpstat;
7001 if we remove it here, then the later call to
7002 bpstat_do_actions (&stop_bpstat);
7003 in event-top.c won't do anything, and temporary breakpoints
7004 with commands won't work. */
7005 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
7006 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7008 bs
->breakpoint_at
= NULL
;
7010 /* bs->commands will be freed later. */
7012 /* On the chance that someone will soon try again to delete this same
7013 bp, we mark it as deleted before freeing its storage. */
7014 bpt
->type
= bp_none
;
7017 xfree (bpt
->loc
->cond
);
7023 do_delete_breakpoint_cleanup (void *b
)
7025 delete_breakpoint (b
);
7029 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7031 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7035 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
7037 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
7041 delete_command (char *arg
, int from_tty
)
7043 struct breakpoint
*b
, *temp
;
7049 int breaks_to_delete
= 0;
7051 /* Delete all breakpoints if no argument.
7052 Do not delete internal or call-dummy breakpoints, these
7053 have to be deleted with an explicit breakpoint number argument. */
7056 if (b
->type
!= bp_call_dummy
&&
7057 b
->type
!= bp_shlib_event
&&
7058 b
->type
!= bp_thread_event
&&
7059 b
->type
!= bp_overlay_event
&&
7062 breaks_to_delete
= 1;
7067 /* Ask user only if there are some breakpoints to delete. */
7069 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7071 ALL_BREAKPOINTS_SAFE (b
, temp
)
7073 if (b
->type
!= bp_call_dummy
&&
7074 b
->type
!= bp_shlib_event
&&
7075 b
->type
!= bp_thread_event
&&
7076 b
->type
!= bp_overlay_event
&&
7078 delete_breakpoint (b
);
7083 map_breakpoint_numbers (arg
, delete_breakpoint
);
7087 unlink_locations_from_global_list (struct breakpoint
*bpt
)
7088 /* Remove locations of this breakpoint from the list of
7089 all breakpoint locations. */
7091 struct bp_location
**tmp
= &bp_location_chain
;
7092 struct bp_location
*here
= bpt
->loc
;
7097 for (; *tmp
&& *tmp
!= here
; tmp
= &((*tmp
)->next
));
7105 update_breakpoint_location (struct breakpoint
*b
,
7106 struct symtabs_and_lines sals
)
7110 /* FIXME: memleak. */
7111 struct bp_location
*existing
= b
->loc
;
7112 struct bp_location
*loc
;
7113 struct symtab_and_line sal
;
7115 if (b
->enable_state
== bp_shlib_disabled
&& sals
.nelts
== 0)
7118 unlink_locations_from_global_list (b
);
7121 gdb_assert (sals
.nelts
== 0 || sals
.nelts
== 1);
7122 if (sals
.nelts
== 0)
7126 loc
= allocate_bp_location (b
, b
->type
);
7127 loc
->requested_address
= sal
.pc
;
7128 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
7130 loc
->section
= sal
.section
;
7133 /* Reparse conditions, they might contain references to the
7135 if (b
->cond_string
!= NULL
)
7137 struct gdb_exception e
;
7140 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7142 loc
->cond
= parse_exp_1 (&s
, block_for_pc (sal
.pc
),
7147 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7148 b
->number
, e
.message
);
7149 b
->enable_state
= bp_disabled
;
7153 if (b
->source_file
!= NULL
)
7154 xfree (b
->source_file
);
7155 if (sal
.symtab
== NULL
)
7156 b
->source_file
= NULL
;
7159 savestring (sal
.symtab
->filename
,
7160 strlen (sal
.symtab
->filename
));
7162 if (b
->line_number
== 0)
7163 b
->line_number
= sal
.line
;
7165 if (b
->enable_state
== bp_shlib_disabled
)
7166 b
->enable_state
= bp_enabled
;
7170 check_duplicates (b
);
7173 free_bp_location (existing
);
7177 /* Reset a breakpoint given it's struct breakpoint * BINT.
7178 The value we return ends up being the return value from catch_errors.
7179 Unused in this case. */
7182 breakpoint_re_set_one (void *bint
)
7184 /* get past catch_errs */
7185 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7189 int *not_found_ptr
= ¬_found
;
7190 struct symtabs_and_lines sals
= {};
7192 enum enable_state save_enable
;
7193 struct gdb_exception e
;
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
);
7213 set_language (b
->language
);
7214 input_radix
= b
->input_radix
;
7216 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7218 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7223 int not_found_and_ok
= 0;
7224 /* For pending breakpoints, it's expected that parsing
7225 will fail until the right shared library is loaded.
7226 User has already told to create pending breakpoints and
7227 don't need extra messages. If breakpoint is in bp_shlib_disabled
7228 state, then user already saw the message about that breakpoint
7229 being disabled, and don't want to see more errors. */
7230 if (not_found
&& (b
->pending
|| b
->enable_state
== bp_shlib_disabled
7231 || b
->enable_state
== bp_disabled
))
7232 not_found_and_ok
= 1;
7234 if (!not_found_and_ok
)
7236 /* We surely don't want to warn about the same breakpoint
7237 10 times. One solution, implemented here, is disable
7238 the breakpoint on error. Another solution would be to
7239 have separate 'warning emitted' flag. Since this
7240 happens only when a binary has changed, I don't know
7241 which approach is better. */
7242 b
->enable_state
= bp_disabled
;
7243 throw_exception (e
);
7250 gdb_assert (sals
.nelts
== 1);
7251 resolve_sal_pc (&sals
.sals
[0]);
7252 if (b
->pending
&& s
&& s
[0])
7254 char *cond_string
= 0;
7256 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7257 &cond_string
, &thread
);
7259 b
->cond_string
= cond_string
;
7263 update_breakpoint_location (b
, sals
);
7269 case bp_hardware_watchpoint
:
7270 case bp_read_watchpoint
:
7271 case bp_access_watchpoint
:
7272 innermost_block
= NULL
;
7273 /* The issue arises of what context to evaluate this in. The
7274 same one as when it was set, but what does that mean when
7275 symbols have been re-read? We could save the filename and
7276 functionname, but if the context is more local than that, the
7277 best we could do would be something like how many levels deep
7278 and which index at that particular level, but that's going to
7279 be less stable than filenames or function names. */
7281 /* So for now, just use a global context. */
7285 /* Avoid re-freeing b->exp if an error during the call to
7286 parse_expression. */
7289 b
->exp
= parse_expression (b
->exp_string
);
7290 b
->exp_valid_block
= innermost_block
;
7291 mark
= value_mark ();
7294 value_free (b
->val
);
7295 /* Avoid re-freeing b->val if an error during the call to
7296 evaluate_expression. */
7299 b
->val
= evaluate_expression (b
->exp
);
7300 release_value (b
->val
);
7301 if (value_lazy (b
->val
) && breakpoint_enabled (b
))
7302 value_fetch_lazy (b
->val
);
7304 if (b
->cond_string
!= NULL
)
7309 xfree (b
->loc
->cond
);
7310 /* Avoid re-freeing b->exp if an error during the call
7312 b
->loc
->cond
= NULL
;
7314 b
->loc
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
7316 if (breakpoint_enabled (b
))
7318 value_free_to_mark (mark
);
7320 case bp_catch_catch
:
7321 case bp_catch_throw
:
7323 /* We needn't really do anything to reset these, since the mask
7324 that requests them is unaffected by e.g., new libraries being
7327 case bp_catch_vfork
:
7332 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7334 /* Delete longjmp and overlay event breakpoints; they will be
7335 reset later by breakpoint_re_set. */
7337 case bp_longjmp_resume
:
7338 case bp_overlay_event
:
7339 delete_breakpoint (b
);
7342 /* This breakpoint is special, it's set up when the inferior
7343 starts and we really don't want to touch it. */
7344 case bp_shlib_event
:
7346 /* Like bp_shlib_event, this breakpoint type is special.
7347 Once it is set up, we do not want to touch it. */
7348 case bp_thread_event
:
7350 /* Keep temporary breakpoints, which can be encountered when we step
7351 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7352 Otherwise these should have been blown away via the cleanup chain
7353 or by breakpoint_init_inferior when we rerun the executable. */
7356 case bp_watchpoint_scope
:
7358 case bp_step_resume
:
7365 /* Re-set all breakpoints after symbols have been re-loaded. */
7367 breakpoint_re_set (void)
7369 struct breakpoint
*b
, *temp
;
7370 enum language save_language
;
7371 int save_input_radix
;
7373 save_language
= current_language
->la_language
;
7374 save_input_radix
= input_radix
;
7375 ALL_BREAKPOINTS_SAFE (b
, temp
)
7377 /* Format possible error msg */
7378 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7380 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7381 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7382 do_cleanups (cleanups
);
7384 set_language (save_language
);
7385 input_radix
= save_input_radix
;
7387 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
7389 create_longjmp_breakpoint ("longjmp");
7390 create_longjmp_breakpoint ("_longjmp");
7391 create_longjmp_breakpoint ("siglongjmp");
7392 create_longjmp_breakpoint ("_siglongjmp");
7393 create_longjmp_breakpoint (NULL
);
7396 create_overlay_event_breakpoint ("_ovly_debug_event");
7399 /* Reset the thread number of this breakpoint:
7401 - If the breakpoint is for all threads, leave it as-is.
7402 - Else, reset it to the current thread for inferior_ptid. */
7404 breakpoint_re_set_thread (struct breakpoint
*b
)
7406 if (b
->thread
!= -1)
7408 if (in_thread_list (inferior_ptid
))
7409 b
->thread
= pid_to_thread_id (inferior_ptid
);
7413 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7414 If from_tty is nonzero, it prints a message to that effect,
7415 which ends with a period (no newline). */
7418 set_ignore_count (int bptnum
, int count
, int from_tty
)
7420 struct breakpoint
*b
;
7426 if (b
->number
== bptnum
)
7428 b
->ignore_count
= count
;
7432 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7434 else if (count
== 1)
7435 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7438 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7441 breakpoints_changed ();
7442 breakpoint_modify_event (b
->number
);
7446 error (_("No breakpoint number %d."), bptnum
);
7449 /* Clear the ignore counts of all breakpoints. */
7451 breakpoint_clear_ignore_counts (void)
7453 struct breakpoint
*b
;
7456 b
->ignore_count
= 0;
7459 /* Command to set ignore-count of breakpoint N to COUNT. */
7462 ignore_command (char *args
, int from_tty
)
7468 error_no_arg (_("a breakpoint number"));
7470 num
= get_number (&p
);
7472 error (_("bad breakpoint number: '%s'"), args
);
7474 error (_("Second argument (specified ignore-count) is missing."));
7476 set_ignore_count (num
,
7477 longest_to_int (value_as_long (parse_and_eval (p
))),
7480 printf_filtered ("\n");
7483 /* Call FUNCTION on each of the breakpoints
7484 whose numbers are given in ARGS. */
7487 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7492 struct breakpoint
*b
, *tmp
;
7496 error_no_arg (_("one or more breakpoint numbers"));
7503 num
= get_number_or_range (&p1
);
7506 warning (_("bad breakpoint number at or near '%s'"), p
);
7510 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7511 if (b
->number
== num
)
7513 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7516 if (related_breakpoint
)
7517 function (related_breakpoint
);
7521 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7527 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7528 If from_tty is nonzero, it prints a message to that effect,
7529 which ends with a period (no newline). */
7532 disable_breakpoint (struct breakpoint
*bpt
)
7534 /* Never disable a watchpoint scope breakpoint; we want to
7535 hit them when we leave scope so we can delete both the
7536 watchpoint and its scope breakpoint at that time. */
7537 if (bpt
->type
== bp_watchpoint_scope
)
7540 /* You can't disable permanent breakpoints. */
7541 if (bpt
->enable_state
== bp_permanent
)
7544 bpt
->enable_state
= bp_disabled
;
7546 check_duplicates (bpt
);
7548 if (deprecated_modify_breakpoint_hook
)
7549 deprecated_modify_breakpoint_hook (bpt
);
7550 breakpoint_modify_event (bpt
->number
);
7554 disable_command (char *args
, int from_tty
)
7556 struct breakpoint
*bpt
;
7558 ALL_BREAKPOINTS (bpt
)
7562 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7567 case bp_catch_unload
:
7569 case bp_catch_vfork
:
7571 case bp_catch_catch
:
7572 case bp_catch_throw
:
7573 case bp_hardware_breakpoint
:
7575 case bp_hardware_watchpoint
:
7576 case bp_read_watchpoint
:
7577 case bp_access_watchpoint
:
7578 disable_breakpoint (bpt
);
7583 map_breakpoint_numbers (args
, disable_breakpoint
);
7587 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7589 int target_resources_ok
, other_type_used
;
7592 if (bpt
->type
== bp_hardware_breakpoint
)
7595 i
= hw_breakpoint_used_count ();
7596 target_resources_ok
=
7597 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7599 if (target_resources_ok
== 0)
7600 error (_("No hardware breakpoint support in the target."));
7601 else if (target_resources_ok
< 0)
7602 error (_("Hardware breakpoints used exceeds limit."));
7605 if (bpt
->enable_state
!= bp_permanent
)
7606 bpt
->enable_state
= bp_enabled
;
7607 bpt
->disposition
= disposition
;
7608 check_duplicates (bpt
);
7609 breakpoints_changed ();
7611 if (bpt
->type
== bp_watchpoint
||
7612 bpt
->type
== bp_hardware_watchpoint
||
7613 bpt
->type
== bp_read_watchpoint
||
7614 bpt
->type
== bp_access_watchpoint
)
7616 struct frame_id saved_frame_id
;
7618 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7619 if (bpt
->exp_valid_block
!= NULL
)
7621 struct frame_info
*fr
=
7622 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7625 printf_filtered (_("\
7626 Cannot enable watchpoint %d because the block in which its expression\n\
7627 is valid is not currently in scope.\n"), bpt
->number
);
7628 bpt
->enable_state
= bp_disabled
;
7634 value_free (bpt
->val
);
7635 mark
= value_mark ();
7636 bpt
->val
= evaluate_expression (bpt
->exp
);
7637 release_value (bpt
->val
);
7638 if (value_lazy (bpt
->val
))
7639 value_fetch_lazy (bpt
->val
);
7641 if (bpt
->type
== bp_hardware_watchpoint
||
7642 bpt
->type
== bp_read_watchpoint
||
7643 bpt
->type
== bp_access_watchpoint
)
7645 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7646 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7648 /* Hack around 'unused var' error for some targets here */
7649 (void) mem_cnt
, (void) i
;
7650 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7651 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7652 /* we can consider of type is bp_hardware_watchpoint, convert to
7653 bp_watchpoint in the following condition */
7654 if (target_resources_ok
< 0)
7656 printf_filtered (_("\
7657 Cannot enable watchpoint %d because target watch resources\n\
7658 have been allocated for other watchpoints.\n"), bpt
->number
);
7659 bpt
->enable_state
= bp_disabled
;
7660 value_free_to_mark (mark
);
7665 select_frame (frame_find_by_id (saved_frame_id
));
7666 value_free_to_mark (mark
);
7669 if (deprecated_modify_breakpoint_hook
)
7670 deprecated_modify_breakpoint_hook (bpt
);
7671 breakpoint_modify_event (bpt
->number
);
7676 enable_breakpoint (struct breakpoint
*bpt
)
7678 do_enable_breakpoint (bpt
, bpt
->disposition
);
7681 /* The enable command enables the specified breakpoints (or all defined
7682 breakpoints) so they once again become (or continue to be) effective
7683 in stopping the inferior. */
7686 enable_command (char *args
, int from_tty
)
7688 struct breakpoint
*bpt
;
7690 ALL_BREAKPOINTS (bpt
)
7694 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7699 case bp_catch_unload
:
7701 case bp_catch_vfork
:
7703 case bp_catch_catch
:
7704 case bp_catch_throw
:
7705 case bp_hardware_breakpoint
:
7707 case bp_hardware_watchpoint
:
7708 case bp_read_watchpoint
:
7709 case bp_access_watchpoint
:
7710 enable_breakpoint (bpt
);
7715 map_breakpoint_numbers (args
, enable_breakpoint
);
7719 enable_once_breakpoint (struct breakpoint
*bpt
)
7721 do_enable_breakpoint (bpt
, disp_disable
);
7725 enable_once_command (char *args
, int from_tty
)
7727 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7731 enable_delete_breakpoint (struct breakpoint
*bpt
)
7733 do_enable_breakpoint (bpt
, disp_del
);
7737 enable_delete_command (char *args
, int from_tty
)
7739 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7743 set_breakpoint_cmd (char *args
, int from_tty
)
7748 show_breakpoint_cmd (char *args
, int from_tty
)
7752 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7754 struct symtabs_and_lines
7755 decode_line_spec_1 (char *string
, int funfirstline
)
7757 struct symtabs_and_lines sals
;
7759 error (_("Empty line specification."));
7760 if (default_breakpoint_valid
)
7761 sals
= decode_line_1 (&string
, funfirstline
,
7762 default_breakpoint_symtab
,
7763 default_breakpoint_line
,
7764 (char ***) NULL
, NULL
);
7766 sals
= decode_line_1 (&string
, funfirstline
,
7767 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7769 error (_("Junk at end of line specification: %s"), string
);
7773 /* Create and insert a raw software breakpoint at PC. Return an
7774 identifier, which should be used to remove the breakpoint later.
7775 In general, places which call this should be using something on the
7776 breakpoint chain instead; this function should be eliminated
7780 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7782 struct bp_target_info
*bp_tgt
;
7784 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7785 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7787 bp_tgt
->placed_address
= pc
;
7788 if (target_insert_breakpoint (bp_tgt
) != 0)
7790 /* Could not insert the breakpoint. */
7798 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7801 deprecated_remove_raw_breakpoint (void *bp
)
7803 struct bp_target_info
*bp_tgt
= bp
;
7806 ret
= target_remove_breakpoint (bp_tgt
);
7812 /* One (or perhaps two) breakpoints used for software single stepping. */
7814 static void *single_step_breakpoints
[2];
7816 /* Create and insert a breakpoint for software single step. */
7819 insert_single_step_breakpoint (CORE_ADDR next_pc
)
7823 if (single_step_breakpoints
[0] == NULL
)
7824 bpt_p
= &single_step_breakpoints
[0];
7827 gdb_assert (single_step_breakpoints
[1] == NULL
);
7828 bpt_p
= &single_step_breakpoints
[1];
7831 /* NOTE drow/2006-04-11: A future improvement to this function would be
7832 to only create the breakpoints once, and actually put them on the
7833 breakpoint chain. That would let us use set_raw_breakpoint. We could
7834 adjust the addresses each time they were needed. Doing this requires
7835 corresponding changes elsewhere where single step breakpoints are
7836 handled, however. So, for now, we use this. */
7838 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
7840 error (_("Could not insert single-step breakpoint at 0x%s"),
7841 paddr_nz (next_pc
));
7844 /* Remove and delete any breakpoints used for software single step. */
7847 remove_single_step_breakpoints (void)
7849 gdb_assert (single_step_breakpoints
[0] != NULL
);
7851 /* See insert_single_step_breakpoint for more about this deprecated
7853 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
7854 single_step_breakpoints
[0] = NULL
;
7856 if (single_step_breakpoints
[1] != NULL
)
7858 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
7859 single_step_breakpoints
[1] = NULL
;
7863 /* Check whether a software single-step breakpoint is inserted at PC. */
7866 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
7870 for (i
= 0; i
< 2; i
++)
7872 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
7873 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
7881 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
7882 It is defined as a macro to prevent duplication.
7883 COMMAND should be a string constant containing the name of the command. */
7884 #define BREAK_ARGS_HELP(command) \
7885 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
7886 LOCATION may be a line number, function name, or \"*\" and an address.\n\
7887 If a line number is specified, break at start of code for that line.\n\
7888 If a function is specified, break at start of code for that function.\n\
7889 If an address is specified, break at that exact address.\n\
7890 With no LOCATION, uses current execution address of selected stack frame.\n\
7891 This is useful for breaking on return to a stack frame.\n\
7893 THREADNUM is the number from \"info threads\".\n\
7894 CONDITION is a boolean expression.\n\
7896 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7898 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
7901 _initialize_breakpoint (void)
7903 static struct cmd_list_element
*breakpoint_set_cmdlist
;
7904 static struct cmd_list_element
*breakpoint_show_cmdlist
;
7905 struct cmd_list_element
*c
;
7907 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
7909 breakpoint_chain
= 0;
7910 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7911 before a breakpoint is set. */
7912 breakpoint_count
= 0;
7914 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
7915 Set ignore-count of breakpoint number N to COUNT.\n\
7916 Usage is `ignore N COUNT'."));
7918 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7920 add_com ("commands", class_breakpoint
, commands_command
, _("\
7921 Set commands to be executed when a breakpoint is hit.\n\
7922 Give breakpoint number as argument after \"commands\".\n\
7923 With no argument, the targeted breakpoint is the last one set.\n\
7924 The commands themselves follow starting on the next line.\n\
7925 Type a line containing \"end\" to indicate the end of them.\n\
7926 Give \"silent\" as the first line to make the breakpoint silent;\n\
7927 then no output is printed when it is hit, except what the commands print."));
7929 add_com ("condition", class_breakpoint
, condition_command
, _("\
7930 Specify breakpoint number N to break only if COND is true.\n\
7931 Usage is `condition N COND', where N is an integer and COND is an\n\
7932 expression to be evaluated whenever breakpoint N is reached."));
7934 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
7935 Set a temporary breakpoint.\n\
7936 Like \"break\" except the breakpoint is only temporary,\n\
7937 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7938 by using \"enable delete\" on the breakpoint number.\n\
7940 BREAK_ARGS_HELP ("tbreak")));
7941 set_cmd_completer (c
, location_completer
);
7943 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
7944 Set a hardware assisted breakpoint.\n\
7945 Like \"break\" except the breakpoint requires hardware support,\n\
7946 some target hardware may not have this support.\n\
7948 BREAK_ARGS_HELP ("hbreak")));
7949 set_cmd_completer (c
, location_completer
);
7951 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
7952 Set a temporary hardware assisted breakpoint.\n\
7953 Like \"hbreak\" except the breakpoint is only temporary,\n\
7954 so it will be deleted when hit.\n\
7956 BREAK_ARGS_HELP ("thbreak")));
7957 set_cmd_completer (c
, location_completer
);
7959 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
7960 Enable some breakpoints.\n\
7961 Give breakpoint numbers (separated by spaces) as arguments.\n\
7962 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7963 This is used to cancel the effect of the \"disable\" command.\n\
7964 With a subcommand you can enable temporarily."),
7965 &enablelist
, "enable ", 1, &cmdlist
);
7967 add_com ("ab", class_breakpoint
, enable_command
, _("\
7968 Enable some breakpoints.\n\
7969 Give breakpoint numbers (separated by spaces) as arguments.\n\
7970 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7971 This is used to cancel the effect of the \"disable\" command.\n\
7972 With a subcommand you can enable temporarily."));
7974 add_com_alias ("en", "enable", class_breakpoint
, 1);
7976 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
7977 Enable some breakpoints.\n\
7978 Give breakpoint numbers (separated by spaces) as arguments.\n\
7979 This is used to cancel the effect of the \"disable\" command.\n\
7980 May be abbreviated to simply \"enable\".\n"),
7981 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
7983 add_cmd ("once", no_class
, enable_once_command
, _("\
7984 Enable breakpoints for one hit. Give breakpoint numbers.\n\
7985 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
7988 add_cmd ("delete", no_class
, enable_delete_command
, _("\
7989 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7990 If a breakpoint is hit while enabled in this fashion, it is deleted."),
7993 add_cmd ("delete", no_class
, enable_delete_command
, _("\
7994 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7995 If a breakpoint is hit while enabled in this fashion, it is deleted."),
7998 add_cmd ("once", no_class
, enable_once_command
, _("\
7999 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8000 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8003 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8004 Disable some breakpoints.\n\
8005 Arguments are breakpoint numbers with spaces in between.\n\
8006 To disable all breakpoints, give no argument.\n\
8007 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8008 &disablelist
, "disable ", 1, &cmdlist
);
8009 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8010 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8012 add_com ("sb", class_breakpoint
, disable_command
, _("\
8013 Disable some breakpoints.\n\
8014 Arguments are breakpoint numbers with spaces in between.\n\
8015 To disable all breakpoints, give no argument.\n\
8016 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8018 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8019 Disable some breakpoints.\n\
8020 Arguments are breakpoint numbers with spaces in between.\n\
8021 To disable all breakpoints, give no argument.\n\
8022 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8023 This command may be abbreviated \"disable\"."),
8026 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8027 Delete some breakpoints or auto-display expressions.\n\
8028 Arguments are breakpoint numbers with spaces in between.\n\
8029 To delete all breakpoints, give no argument.\n\
8031 Also a prefix command for deletion of other GDB objects.\n\
8032 The \"unset\" command is also an alias for \"delete\"."),
8033 &deletelist
, "delete ", 1, &cmdlist
);
8034 add_com_alias ("d", "delete", class_breakpoint
, 1);
8035 add_com_alias ("del", "delete", class_breakpoint
, 1);
8037 add_com ("db", class_breakpoint
, delete_command
, _("\
8038 Delete some breakpoints.\n\
8039 Arguments are breakpoint numbers with spaces in between.\n\
8040 To delete all breakpoints, give no argument.\n"));
8042 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8043 Delete some breakpoints or auto-display expressions.\n\
8044 Arguments are breakpoint numbers with spaces in between.\n\
8045 To delete all breakpoints, give no argument.\n\
8046 This command may be abbreviated \"delete\"."),
8049 add_com ("clear", class_breakpoint
, clear_command
, _("\
8050 Clear breakpoint at specified line or function.\n\
8051 Argument may be line number, function name, or \"*\" and an address.\n\
8052 If line number is specified, all breakpoints in that line are cleared.\n\
8053 If function is specified, breakpoints at beginning of function are cleared.\n\
8054 If an address is specified, breakpoints at that address are cleared.\n\
8056 With no argument, clears all breakpoints in the line that the selected frame\n\
8059 See also the \"delete\" command which clears breakpoints by number."));
8061 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8062 Set breakpoint at specified line or function.\n"
8063 BREAK_ARGS_HELP ("break")));
8064 set_cmd_completer (c
, location_completer
);
8066 add_com_alias ("b", "break", class_run
, 1);
8067 add_com_alias ("br", "break", class_run
, 1);
8068 add_com_alias ("bre", "break", class_run
, 1);
8069 add_com_alias ("brea", "break", class_run
, 1);
8073 add_com_alias ("ba", "break", class_breakpoint
, 1);
8074 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8079 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8080 Break in function/address or break at a line in the current file."),
8081 &stoplist
, "stop ", 1, &cmdlist
);
8082 add_cmd ("in", class_breakpoint
, stopin_command
,
8083 _("Break in function or address."), &stoplist
);
8084 add_cmd ("at", class_breakpoint
, stopat_command
,
8085 _("Break at a line in the current file."), &stoplist
);
8086 add_com ("status", class_info
, breakpoints_info
, _("\
8087 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8088 The \"Type\" column indicates one of:\n\
8089 \tbreakpoint - normal breakpoint\n\
8090 \twatchpoint - watchpoint\n\
8091 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8092 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8093 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8094 address and file/line number respectively.\n\
8096 Convenience variable \"$_\" and default examine address for \"x\"\n\
8097 are set to the address of the last breakpoint listed unless the command\n\
8098 is prefixed with \"server \".\n\n\
8099 Convenience variable \"$bpnum\" contains the number of the last\n\
8103 add_info ("breakpoints", breakpoints_info
, _("\
8104 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8105 The \"Type\" column indicates one of:\n\
8106 \tbreakpoint - normal breakpoint\n\
8107 \twatchpoint - watchpoint\n\
8108 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8109 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8110 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8111 address and file/line number respectively.\n\
8113 Convenience variable \"$_\" and default examine address for \"x\"\n\
8114 are set to the address of the last breakpoint listed unless the command\n\
8115 is prefixed with \"server \".\n\n\
8116 Convenience variable \"$bpnum\" contains the number of the last\n\
8120 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8121 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8122 The \"Type\" column indicates one of:\n\
8123 \tbreakpoint - normal breakpoint\n\
8124 \twatchpoint - watchpoint\n\
8125 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8126 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8127 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8128 address and file/line number respectively.\n\
8130 Convenience variable \"$_\" and default examine address for \"x\"\n\
8131 are set to the address of the last breakpoint listed unless the command\n\
8132 is prefixed with \"server \".\n\n\
8133 Convenience variable \"$bpnum\" contains the number of the last\n\
8136 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8137 Status of all breakpoints, or breakpoint number NUMBER.\n\
8138 The \"Type\" column indicates one of:\n\
8139 \tbreakpoint - normal breakpoint\n\
8140 \twatchpoint - watchpoint\n\
8141 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8142 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8143 \tuntil - internal breakpoint used by the \"until\" command\n\
8144 \tfinish - internal breakpoint used by the \"finish\" command\n\
8145 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8146 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8147 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8148 address and file/line number respectively.\n\
8150 Convenience variable \"$_\" and default examine address for \"x\"\n\
8151 are set to the address of the last breakpoint listed unless the command\n\
8152 is prefixed with \"server \".\n\n\
8153 Convenience variable \"$bpnum\" contains the number of the last\n\
8155 &maintenanceinfolist
);
8157 add_com ("catch", class_breakpoint
, catch_command
, _("\
8158 Set catchpoints to catch events.\n\
8159 Raised signals may be caught:\n\
8160 \tcatch signal - all signals\n\
8161 \tcatch signal <signame> - a particular signal\n\
8162 Raised exceptions may be caught:\n\
8163 \tcatch throw - all exceptions, when thrown\n\
8164 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8165 \tcatch catch - all exceptions, when caught\n\
8166 \tcatch catch <exceptname> - a particular exception, when caught\n\
8167 Thread or process events may be caught:\n\
8168 \tcatch thread_start - any threads, just after creation\n\
8169 \tcatch thread_exit - any threads, just before expiration\n\
8170 \tcatch thread_join - any threads, just after joins\n\
8171 Process events may be caught:\n\
8172 \tcatch start - any processes, just after creation\n\
8173 \tcatch exit - any processes, just before expiration\n\
8174 \tcatch fork - calls to fork()\n\
8175 \tcatch vfork - calls to vfork()\n\
8176 \tcatch exec - calls to exec()\n\
8177 Dynamically-linked library events may be caught:\n\
8178 \tcatch load - loads of any library\n\
8179 \tcatch load <libname> - loads of a particular library\n\
8180 \tcatch unload - unloads of any library\n\
8181 \tcatch unload <libname> - unloads of a particular library\n\
8182 The act of your program's execution stopping may also be caught:\n\
8184 C++ exceptions may be caught:\n\
8185 \tcatch throw - all exceptions, when thrown\n\
8186 \tcatch catch - all exceptions, when caught\n\
8187 Ada exceptions may be caught:\n\
8188 \tcatch exception - all exceptions, when raised\n\
8189 \tcatch exception <name> - a particular exception, when raised\n\
8190 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8191 \tcatch assert - all failed assertions, when raised\n\
8193 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8194 after a fork or vfork is caught.\n\n\
8195 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8197 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8198 Set temporary catchpoints to catch events.\n\
8199 Args like \"catch\" command.\n\
8200 Like \"catch\" except the catchpoint is only temporary,\n\
8201 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8202 by using \"enable delete\" on the catchpoint number."));
8204 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8205 Set a watchpoint for an expression.\n\
8206 A watchpoint stops execution of your program whenever the value of\n\
8207 an expression changes."));
8208 set_cmd_completer (c
, location_completer
);
8210 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8211 Set a read watchpoint for an expression.\n\
8212 A watchpoint stops execution of your program whenever the value of\n\
8213 an expression is read."));
8214 set_cmd_completer (c
, location_completer
);
8216 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8217 Set a watchpoint for an expression.\n\
8218 A watchpoint stops execution of your program whenever the value of\n\
8219 an expression is either read or written."));
8220 set_cmd_completer (c
, location_completer
);
8222 add_info ("watchpoints", breakpoints_info
,
8223 _("Synonym for ``info breakpoints''."));
8226 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8227 respond to changes - contrary to the description. */
8228 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8229 &can_use_hw_watchpoints
, _("\
8230 Set debugger's willingness to use watchpoint hardware."), _("\
8231 Show debugger's willingness to use watchpoint hardware."), _("\
8232 If zero, gdb will not use hardware for new watchpoints, even if\n\
8233 such is available. (However, any hardware watchpoints that were\n\
8234 created before setting this to nonzero, will continue to use watchpoint\n\
8237 show_can_use_hw_watchpoints
,
8238 &setlist
, &showlist
);
8240 can_use_hw_watchpoints
= 1;
8242 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8243 Breakpoint specific settings\n\
8244 Configure various breakpoint-specific variables such as\n\
8245 pending breakpoint behavior"),
8246 &breakpoint_set_cmdlist
, "set breakpoint ",
8247 0/*allow-unknown*/, &setlist
);
8248 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8249 Breakpoint specific settings\n\
8250 Configure various breakpoint-specific variables such as\n\
8251 pending breakpoint behavior"),
8252 &breakpoint_show_cmdlist
, "show breakpoint ",
8253 0/*allow-unknown*/, &showlist
);
8255 add_setshow_auto_boolean_cmd ("pending", no_class
,
8256 &pending_break_support
, _("\
8257 Set debugger's behavior regarding pending breakpoints."), _("\
8258 Show debugger's behavior regarding pending breakpoints."), _("\
8259 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8260 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8261 an error. If auto, an unrecognized breakpoint location results in a\n\
8262 user-query to see if a pending breakpoint should be created."),
8264 show_pending_break_support
,
8265 &breakpoint_set_cmdlist
,
8266 &breakpoint_show_cmdlist
);
8268 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8270 add_setshow_boolean_cmd ("auto-hw", no_class
,
8271 &automatic_hardware_breakpoints
, _("\
8272 Set automatic usage of hardware breakpoints."), _("\
8273 Show automatic usage of hardware breakpoints."), _("\
8274 If set, the debugger will automatically use hardware breakpoints for\n\
8275 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8276 a warning will be emitted for such breakpoints."),
8278 show_automatic_hardware_breakpoints
,
8279 &breakpoint_set_cmdlist
,
8280 &breakpoint_show_cmdlist
);
8282 automatic_hardware_breakpoints
= 1;