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);
95 static void mention (struct breakpoint
*);
97 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
99 static void check_duplicates (struct breakpoint
*);
101 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
103 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
106 static void describe_other_breakpoints (CORE_ADDR
, asection
*, int);
108 static void breakpoints_info (char *, int);
110 static void breakpoint_1 (int, int);
112 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
114 static int breakpoint_cond_eval (void *);
116 static void cleanup_executing_breakpoints (void *);
118 static void commands_command (char *, int);
120 static void condition_command (char *, int);
122 static int get_number_trailer (char **, int);
124 void set_breakpoint_count (int);
133 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
135 static enum print_stop_action
print_it_typical (bpstat
);
137 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
141 enum exception_event_kind kind
;
144 args_for_catchpoint_enable
;
146 static int watchpoint_check (void *);
148 static 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 create_fork_vfork_event_catchpoint (int tempflag
,
174 enum bptype bp_kind
);
176 static void stop_command (char *arg
, int from_tty
);
178 static void stopin_command (char *arg
, int from_tty
);
180 static void stopat_command (char *arg
, int from_tty
);
182 static char *ep_find_event_name_end (char *arg
);
184 static char *ep_parse_optional_if_clause (char **arg
);
186 static char *ep_parse_optional_filename (char **arg
);
188 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
189 enum exception_event_kind ex_event
,
190 struct symtab_and_line
*sal
);
192 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
193 char *arg
, int tempflag
, int from_tty
);
195 static void tcatch_command (char *arg
, int from_tty
);
197 static void ep_skip_leading_whitespace (char **s
);
199 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
201 static void free_bp_location (struct bp_location
*loc
);
203 static void mark_breakpoints_out (void);
205 /* Prototypes for exported functions. */
207 /* If FALSE, gdb will not use hardware support for watchpoints, even
208 if such is available. */
209 static int can_use_hw_watchpoints
;
212 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
213 struct cmd_list_element
*c
,
216 fprintf_filtered (file
, _("\
217 Debugger's willingness to use watchpoint hardware is %s.\n"),
221 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
222 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
223 for unrecognized breakpoint locations.
224 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
225 static enum auto_boolean pending_break_support
;
227 show_pending_break_support (struct ui_file
*file
, int from_tty
,
228 struct cmd_list_element
*c
,
231 fprintf_filtered (file
, _("\
232 Debugger's behavior regarding pending breakpoints is %s.\n"),
236 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
237 set with "break" but falling in read-only memory.
238 If 0, gdb will warn about such breakpoints, but won't automatically
239 use hardware breakpoints. */
240 static int automatic_hardware_breakpoints
;
242 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
243 struct cmd_list_element
*c
,
246 fprintf_filtered (file
, _("\
247 Automatic usage of hardware breakpoints is %s.\n"),
252 void _initialize_breakpoint (void);
254 extern int addressprint
; /* Print machine addresses? */
256 /* Are we executing breakpoint commands? */
257 static int executing_breakpoint_commands
;
259 /* Are overlay event breakpoints enabled? */
260 static int overlay_events_enabled
;
262 /* Walk the following statement or block through all breakpoints.
263 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
266 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
268 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
269 for (B = breakpoint_chain; \
270 B ? (TMP=B->next, 1): 0; \
273 /* Similar iterators for the low-level breakpoints. */
275 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
277 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
278 for (B = bp_location_chain; \
279 B ? (TMP=B->global_next, 1): 0; \
282 /* True if breakpoint hit counts should be displayed in breakpoint info. */
284 int show_breakpoint_hit_counts
= 1;
286 /* Chains of all breakpoints defined. */
288 struct breakpoint
*breakpoint_chain
;
290 struct bp_location
*bp_location_chain
;
292 /* Number of last breakpoint made. */
294 int breakpoint_count
;
296 /* Pointer to current exception event record */
297 static struct exception_event_record
*current_exception_event
;
299 /* This function returns a pointer to the string representation of the
300 pathname of the dynamically-linked library that has just been
303 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
304 or undefined results are guaranteed.
306 This string's contents are only valid immediately after the
307 inferior has stopped in the dynamic linker hook, and becomes
308 invalid as soon as the inferior is continued. Clients should make
309 a copy of this string if they wish to continue the inferior and
310 then access the string. */
312 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
313 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
316 /* This function returns a pointer to the string representation of the
317 pathname of the dynamically-linked library that has just been
320 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
321 TRUE, or undefined results are guaranteed.
323 This string's contents are only valid immediately after the
324 inferior has stopped in the dynamic linker hook, and becomes
325 invalid as soon as the inferior is continued. Clients should make
326 a copy of this string if they wish to continue the inferior and
327 then access the string. */
329 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
330 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
333 /* This function is called by the "catch load" command. It allows the
334 debugger to be notified by the dynamic linker when a specified
335 library file (or any library file, if filename is NULL) is loaded. */
337 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
338 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
339 error (_("catch of library loads not yet implemented on this platform"))
342 /* This function is called by the "catch unload" command. It allows
343 the debugger to be notified by the dynamic linker when a specified
344 library file (or any library file, if filename is NULL) is
347 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
348 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
349 error (_("catch of library unloads not yet implemented on this platform"))
352 /* Return whether a breakpoint is an active enabled breakpoint. */
354 breakpoint_enabled (struct breakpoint
*b
)
356 return (b
->enable_state
== bp_enabled
);
359 /* Set breakpoint count to NUM. */
362 set_breakpoint_count (int num
)
364 breakpoint_count
= num
;
365 set_internalvar (lookup_internalvar ("bpnum"),
366 value_from_longest (builtin_type_int
, (LONGEST
) num
));
369 /* Used in run_command to zero the hit count when a new run starts. */
372 clear_breakpoint_hit_counts (void)
374 struct breakpoint
*b
;
380 /* Default address, symtab and line to put a breakpoint at
381 for "break" command with no arg.
382 if default_breakpoint_valid is zero, the other three are
383 not valid, and "break" with no arg is an error.
385 This set by print_stack_frame, which calls set_default_breakpoint. */
387 int default_breakpoint_valid
;
388 CORE_ADDR default_breakpoint_address
;
389 struct symtab
*default_breakpoint_symtab
;
390 int default_breakpoint_line
;
392 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
393 Advance *PP after the string and any trailing whitespace.
395 Currently the string can either be a number or "$" followed by the name
396 of a convenience variable. Making it an expression wouldn't work well
397 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
399 If the string is a NULL pointer, that denotes the last breakpoint.
401 TRAILER is a character which can be found after the number; most
402 commonly this is `-'. If you don't want a trailer, use \0. */
404 get_number_trailer (char **pp
, int trailer
)
406 int retval
= 0; /* default */
410 /* Empty line means refer to the last breakpoint. */
411 return breakpoint_count
;
414 /* Make a copy of the name, so we can null-terminate it
415 to pass to lookup_internalvar(). */
420 while (isalnum (*p
) || *p
== '_')
422 varname
= (char *) alloca (p
- start
+ 1);
423 strncpy (varname
, start
, p
- start
);
424 varname
[p
- start
] = '\0';
425 val
= value_of_internalvar (lookup_internalvar (varname
));
426 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
427 retval
= (int) value_as_long (val
);
430 printf_filtered (_("Convenience variable must have integer value.\n"));
438 while (*p
>= '0' && *p
<= '9')
441 /* There is no number here. (e.g. "cond a == b"). */
443 /* Skip non-numeric token */
444 while (*p
&& !isspace((int) *p
))
446 /* Return zero, which caller must interpret as error. */
452 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
454 /* Trailing junk: return 0 and let caller print error msg. */
455 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
466 /* Like get_number_trailer, but don't allow a trailer. */
468 get_number (char **pp
)
470 return get_number_trailer (pp
, '\0');
473 /* Parse a number or a range.
474 * A number will be of the form handled by get_number.
475 * A range will be of the form <number1> - <number2>, and
476 * will represent all the integers between number1 and number2,
479 * While processing a range, this fuction is called iteratively;
480 * At each call it will return the next value in the range.
482 * At the beginning of parsing a range, the char pointer PP will
483 * be advanced past <number1> and left pointing at the '-' token.
484 * Subsequent calls will not advance the pointer until the range
485 * is completed. The call that completes the range will advance
486 * pointer PP past <number2>.
490 get_number_or_range (char **pp
)
492 static int last_retval
, end_value
;
493 static char *end_ptr
;
494 static int in_range
= 0;
498 /* Default case: pp is pointing either to a solo number,
499 or to the first number of a range. */
500 last_retval
= get_number_trailer (pp
, '-');
505 /* This is the start of a range (<number1> - <number2>).
506 Skip the '-', parse and remember the second number,
507 and also remember the end of the final token. */
511 while (isspace ((int) *end_ptr
))
512 end_ptr
++; /* skip white space */
513 end_value
= get_number (temp
);
514 if (end_value
< last_retval
)
516 error (_("inverted range"));
518 else if (end_value
== last_retval
)
520 /* degenerate range (number1 == number2). Advance the
521 token pointer so that the range will be treated as a
530 error (_("negative value"));
533 /* pp points to the '-' that betokens a range. All
534 number-parsing has already been done. Return the next
535 integer value (one greater than the saved previous value).
536 Do not advance the token pointer 'pp' until the end of range
539 if (++last_retval
== end_value
)
541 /* End of range reached; advance token pointer. */
551 /* condition N EXP -- set break condition of breakpoint N to EXP. */
554 condition_command (char *arg
, int from_tty
)
556 struct breakpoint
*b
;
561 error_no_arg (_("breakpoint number"));
564 bnum
= get_number (&p
);
566 error (_("Bad breakpoint argument: '%s'"), arg
);
569 if (b
->number
== bnum
)
571 struct bp_location
*loc
= b
->loc
;
572 for (; loc
; loc
= loc
->next
)
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
));
595 b
->condition_not_parsed
= 0;
596 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
599 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
601 error (_("Junk at end of expression"));
604 breakpoints_changed ();
605 breakpoint_modify_event (b
->number
);
609 error (_("No breakpoint number %d."), bnum
);
613 commands_command (char *arg
, int from_tty
)
615 struct breakpoint
*b
;
618 struct command_line
*l
;
620 /* If we allowed this, we would have problems with when to
621 free the storage, if we change the commands currently
624 if (executing_breakpoint_commands
)
625 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
628 bnum
= get_number (&p
);
631 error (_("Unexpected extra arguments following breakpoint number."));
634 if (b
->number
== bnum
)
636 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
638 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
639 l
= read_command_lines (tmpbuf
, from_tty
);
640 do_cleanups (cleanups
);
641 free_command_lines (&b
->commands
);
643 breakpoints_changed ();
644 breakpoint_modify_event (b
->number
);
647 error (_("No breakpoint number %d."), bnum
);
650 /* Like commands_command, but instead of reading the commands from
651 input stream, takes them from an already parsed command structure.
653 This is used by cli-script.c to DTRT with breakpoint commands
654 that are part of if and while bodies. */
655 enum command_control_type
656 commands_from_control_command (char *arg
, struct command_line
*cmd
)
658 struct breakpoint
*b
;
662 /* If we allowed this, we would have problems with when to
663 free the storage, if we change the commands currently
666 if (executing_breakpoint_commands
)
667 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
669 /* An empty string for the breakpoint number means the last
670 breakpoint, but get_number expects a NULL pointer. */
675 bnum
= get_number (&p
);
678 error (_("Unexpected extra arguments following breakpoint number."));
681 if (b
->number
== bnum
)
683 free_command_lines (&b
->commands
);
684 if (cmd
->body_count
!= 1)
685 error (_("Invalid \"commands\" block structure."));
686 /* We need to copy the commands because if/while will free the
687 list after it finishes execution. */
688 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
689 breakpoints_changed ();
690 breakpoint_modify_event (b
->number
);
691 return simple_control
;
693 error (_("No breakpoint number %d."), bnum
);
696 /* Like target_read_memory() but if breakpoints are inserted, return
697 the shadow contents instead of the breakpoints themselves.
699 Read "memory data" from whatever target or inferior we have.
700 Returns zero if successful, errno value if not. EIO is used
701 for address out of bounds. If breakpoints are inserted, returns
702 shadow contents, not the breakpoints themselves. From breakpoint.c. */
705 read_memory_nobpt (CORE_ADDR memaddr
, gdb_byte
*myaddr
, unsigned len
)
708 const struct bp_location
*b
;
709 CORE_ADDR bp_addr
= 0;
712 if (gdbarch_breakpoint_from_pc (current_gdbarch
, &bp_addr
, &bp_size
) == NULL
)
713 /* No breakpoints on this machine. */
714 return target_read_memory (memaddr
, myaddr
, len
);
718 if (b
->owner
->type
== bp_none
)
719 warning (_("reading through apparently deleted breakpoint #%d?"),
722 if (b
->loc_type
!= bp_loc_software_breakpoint
)
726 /* Addresses and length of the part of the breakpoint that
728 bp_addr
= b
->target_info
.placed_address
;
729 bp_size
= b
->target_info
.shadow_len
;
731 /* bp isn't valid, or doesn't shadow memory. */
733 if (bp_addr
+ bp_size
<= memaddr
)
734 /* The breakpoint is entirely before the chunk of memory we
737 if (bp_addr
>= memaddr
+ len
)
738 /* The breakpoint is entirely after the chunk of memory we are
741 /* Copy the breakpoint from the shadow contents, and recurse for
742 the things before and after. */
744 /* Offset within shadow_contents. */
747 if (bp_addr
< memaddr
)
749 /* Only copy the second part of the breakpoint. */
750 bp_size
-= memaddr
- bp_addr
;
751 bptoffset
= memaddr
- bp_addr
;
755 if (bp_addr
+ bp_size
> memaddr
+ len
)
757 /* Only copy the first part of the breakpoint. */
758 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
761 memcpy (myaddr
+ bp_addr
- memaddr
,
762 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
764 if (bp_addr
> memaddr
)
766 /* Copy the section of memory before the breakpoint. */
767 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
772 if (bp_addr
+ bp_size
< memaddr
+ len
)
774 /* Copy the section of memory after the breakpoint. */
775 status
= read_memory_nobpt (bp_addr
+ bp_size
,
776 myaddr
+ bp_addr
+ bp_size
- memaddr
,
777 memaddr
+ len
- (bp_addr
+ bp_size
));
784 /* Nothing overlaps. Just call read_memory_noerr. */
785 return target_read_memory (memaddr
, myaddr
, len
);
789 /* A wrapper function for inserting catchpoints. */
791 insert_catchpoint (struct ui_out
*uo
, void *args
)
793 struct breakpoint
*b
= (struct breakpoint
*) args
;
799 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
802 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
805 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
808 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
813 /* Helper routine: free the value chain for a breakpoint (watchpoint). */
816 free_valchain (struct bp_location
*b
)
821 /* Free the saved value chain. We will construct a new one
822 the next time the watchpoint is inserted. */
823 for (v
= b
->owner
->val_chain
; v
; v
= n
)
828 b
->owner
->val_chain
= NULL
;
831 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
832 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
833 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
835 NOTE drow/2003-09-09: This routine could be broken down to an object-style
836 method for each breakpoint or catchpoint type. */
838 insert_bp_location (struct bp_location
*bpt
,
839 struct ui_file
*tmp_error_stream
,
840 int *disabled_breaks
, int *process_warning
,
841 int *hw_breakpoint_error
)
845 if (!breakpoint_enabled (bpt
->owner
))
848 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->inserted
|| bpt
->duplicate
)
851 /* Initialize the target-specific information. */
852 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
853 bpt
->target_info
.placed_address
= bpt
->address
;
855 if (bpt
->loc_type
== bp_loc_software_breakpoint
856 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
858 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
860 /* If the explicitly specified breakpoint type
861 is not hardware breakpoint, check the memory map to see
862 if the breakpoint address is in read only memory or not.
863 Two important cases are:
864 - location type is not hardware breakpoint, memory
865 is readonly. We change the type of the location to
867 - location type is hardware breakpoint, memory is read-write.
868 This means we've previously made the location hardware one, but
869 then the memory map changed, so we undo.
871 When breakpoints are removed, remove_breakpoints will
872 use location types we've just set here, the only possible
873 problem is that memory map has changed during running program,
874 but it's not going to work anyway with current gdb. */
875 struct mem_region
*mr
876 = lookup_mem_region (bpt
->target_info
.placed_address
);
880 if (automatic_hardware_breakpoints
)
883 enum bp_loc_type new_type
;
885 if (mr
->attrib
.mode
!= MEM_RW
)
886 new_type
= bp_loc_hardware_breakpoint
;
888 new_type
= bp_loc_software_breakpoint
;
890 if (new_type
!= bpt
->loc_type
)
893 bpt
->loc_type
= new_type
;
896 fprintf_filtered (gdb_stdout
, _("\
897 Note: automatically using hardware breakpoints for read-only addresses.\n"));
902 else if (bpt
->loc_type
== bp_loc_software_breakpoint
903 && mr
->attrib
.mode
!= MEM_RW
)
904 warning (_("cannot set software breakpoint at readonly address %s"),
905 paddr (bpt
->address
));
909 /* First check to see if we have to handle an overlay. */
910 if (overlay_debugging
== ovly_off
911 || bpt
->section
== NULL
912 || !(section_is_overlay (bpt
->section
)))
914 /* No overlay handling: just set the breakpoint. */
916 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
917 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
919 val
= target_insert_breakpoint (&bpt
->target_info
);
923 /* This breakpoint is in an overlay section.
924 Shall we set a breakpoint at the LMA? */
925 if (!overlay_events_enabled
)
927 /* Yes -- overlay event support is not active,
928 so we must try to set a breakpoint at the LMA.
929 This will not work for a hardware breakpoint. */
930 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
931 warning (_("hardware breakpoint %d not supported in overlay!"),
935 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
937 /* Set a software (trap) breakpoint at the LMA. */
938 bpt
->overlay_target_info
= bpt
->target_info
;
939 bpt
->overlay_target_info
.placed_address
= addr
;
940 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
942 fprintf_unfiltered (tmp_error_stream
,
943 "Overlay breakpoint %d failed: in ROM?",
947 /* Shall we set a breakpoint at the VMA? */
948 if (section_is_mapped (bpt
->section
))
950 /* Yes. This overlay section is mapped into memory. */
951 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
952 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
954 val
= target_insert_breakpoint (&bpt
->target_info
);
958 /* No. This breakpoint will not be inserted.
959 No error, but do not mark the bp as 'inserted'. */
966 /* Can't set the breakpoint. */
967 if (solib_address (bpt
->address
))
969 /* See also: disable_breakpoints_in_shlibs. */
971 bpt
->shlib_disabled
= 1;
972 if (!*disabled_breaks
)
974 fprintf_unfiltered (tmp_error_stream
,
975 "Cannot insert breakpoint %d.\n",
977 fprintf_unfiltered (tmp_error_stream
,
978 "Temporarily disabling shared library breakpoints:\n");
980 *disabled_breaks
= 1;
981 fprintf_unfiltered (tmp_error_stream
,
982 "breakpoint #%d\n", bpt
->owner
->number
);
986 #ifdef ONE_PROCESS_WRITETEXT
987 *process_warning
= 1;
989 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
991 *hw_breakpoint_error
= 1;
992 fprintf_unfiltered (tmp_error_stream
,
993 "Cannot insert hardware breakpoint %d.\n",
998 fprintf_unfiltered (tmp_error_stream
,
999 "Cannot insert breakpoint %d.\n",
1000 bpt
->owner
->number
);
1001 fprintf_filtered (tmp_error_stream
,
1002 "Error accessing memory address ");
1003 deprecated_print_address_numeric (bpt
->address
, 1, tmp_error_stream
);
1004 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1005 safe_strerror (val
));
1016 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1017 /* NOTE drow/2003-09-08: This state only exists for removing
1018 watchpoints. It's not clear that it's necessary... */
1019 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1021 /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints
1022 based on the expression. Ideally this should happen at a higher level,
1023 and there should be one bp_location for each computed address we
1024 must watch. As soon as a many-to-one mapping is available I'll
1027 int within_current_scope
;
1028 struct value
*mark
= value_mark ();
1030 struct frame_id saved_frame_id
;
1032 /* Save the current frame's ID so we can restore it after
1033 evaluating the watchpoint expression on its own frame. */
1034 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1035 took a frame parameter, so that we didn't have to change the
1037 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1039 /* Determine if the watchpoint is within scope. */
1040 if (bpt
->owner
->exp_valid_block
== NULL
)
1041 within_current_scope
= 1;
1044 struct frame_info
*fi
;
1045 fi
= frame_find_by_id (bpt
->owner
->watchpoint_frame
);
1046 within_current_scope
= (fi
!= NULL
);
1047 if (within_current_scope
)
1051 if (within_current_scope
)
1053 free_valchain (bpt
);
1055 /* Evaluate the expression and cut the chain of values
1056 produced off from the value chain.
1058 Make sure the value returned isn't lazy; we use
1059 laziness to determine what memory GDB actually needed
1060 in order to compute the value of the expression. */
1061 v
= evaluate_expression (bpt
->owner
->exp
);
1063 value_release_to_mark (mark
);
1065 bpt
->owner
->val_chain
= v
;
1068 /* Look at each value on the value chain. */
1069 for (; v
; v
= value_next (v
))
1071 /* If it's a memory location, and GDB actually needed
1072 its contents to evaluate the expression, then we
1074 if (VALUE_LVAL (v
) == lval_memory
1075 && ! value_lazy (v
))
1077 struct type
*vtype
= check_typedef (value_type (v
));
1079 /* We only watch structs and arrays if user asked
1080 for it explicitly, never if they just happen to
1081 appear in the middle of some value chain. */
1082 if (v
== bpt
->owner
->val_chain
1083 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1084 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1089 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
1090 len
= TYPE_LENGTH (value_type (v
));
1092 if (bpt
->owner
->type
== bp_read_watchpoint
)
1094 else if (bpt
->owner
->type
== bp_access_watchpoint
)
1097 val
= target_insert_watchpoint (addr
, len
, type
);
1100 /* Don't exit the loop, try to insert
1101 every value on the value chain. That's
1102 because we will be removing all the
1103 watches below, and removing a
1104 watchpoint we didn't insert could have
1112 /* Failure to insert a watchpoint on any memory value in the
1113 value chain brings us here. */
1116 remove_breakpoint (bpt
, mark_uninserted
);
1117 *hw_breakpoint_error
= 1;
1118 fprintf_unfiltered (tmp_error_stream
,
1119 "Could not insert hardware watchpoint %d.\n",
1120 bpt
->owner
->number
);
1126 printf_filtered (_("\
1127 Hardware watchpoint %d deleted because the program has left the block \n\
1128 in which its expression is valid.\n"),
1129 bpt
->owner
->number
);
1130 if (bpt
->owner
->related_breakpoint
)
1131 bpt
->owner
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1132 bpt
->owner
->disposition
= disp_del_at_next_stop
;
1135 /* Restore the selected frame. */
1136 select_frame (frame_find_by_id (saved_frame_id
));
1141 else if (ep_is_exception_catchpoint (bpt
->owner
))
1143 /* FIXME drow/2003-09-09: This code sets both a catchpoint and a
1144 breakpoint. Once again, it would be better if this was represented
1145 as two bp_locations. */
1147 /* If we get here, we must have a callback mechanism for exception
1148 events -- with g++ style embedded label support, we insert
1149 ordinary breakpoints and not catchpoints. */
1150 val
= target_insert_breakpoint (&bpt
->target_info
);
1153 /* Couldn't set breakpoint for some reason */
1154 fprintf_unfiltered (tmp_error_stream
,
1155 "Cannot insert catchpoint %d; disabling it.\n",
1156 bpt
->owner
->number
);
1157 fprintf_filtered (tmp_error_stream
,
1158 "Error accessing memory address ");
1159 deprecated_print_address_numeric (bpt
->address
, 1, tmp_error_stream
);
1160 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1161 safe_strerror (val
));
1162 bpt
->owner
->enable_state
= bp_disabled
;
1166 /* Bp set, now make sure callbacks are enabled */
1167 /* Format possible error msg */
1168 char *message
= xstrprintf ("Error inserting catchpoint %d:\n",
1169 bpt
->owner
->number
);
1170 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
1172 args_for_catchpoint_enable args
;
1173 args
.kind
= bpt
->owner
->type
== bp_catch_catch
?
1174 EX_EVENT_CATCH
: EX_EVENT_THROW
;
1176 val
= catch_errors (cover_target_enable_exception_callback
,
1177 &args
, message
, RETURN_MASK_ALL
);
1178 do_cleanups (cleanups
);
1179 if (val
!= 0 && val
!= -1)
1182 /* Check if something went wrong; val == 0 can be ignored */
1185 /* something went wrong */
1186 fprintf_unfiltered (tmp_error_stream
,
1187 "Cannot insert catchpoint %d; disabling it.\n",
1188 bpt
->owner
->number
);
1189 bpt
->owner
->enable_state
= bp_disabled
;
1196 else if (bpt
->owner
->type
== bp_catch_fork
1197 || bpt
->owner
->type
== bp_catch_vfork
1198 || bpt
->owner
->type
== bp_catch_exec
)
1200 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1201 bpt
->owner
, RETURN_MASK_ERROR
);
1202 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1203 bpt
->owner
->number
);
1205 bpt
->owner
->enable_state
= bp_disabled
;
1209 /* We've already printed an error message if there was a problem
1210 inserting this catchpoint, and we've disabled the catchpoint,
1211 so just return success. */
1218 /* insert_breakpoints is used when starting or continuing the program.
1219 remove_breakpoints is used when the program stops.
1220 Both return zero if successful,
1221 or an `errno' value if could not write the inferior. */
1224 insert_breakpoints (void)
1226 struct bp_location
*b
, *temp
;
1229 int disabled_breaks
= 0;
1230 int hw_breakpoint_error
= 0;
1231 int process_warning
= 0;
1233 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1234 make_cleanup_ui_file_delete (tmp_error_stream
);
1236 /* Explicitly mark the warning -- this will only be printed if
1237 there was an error. */
1238 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1240 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1242 if (!breakpoint_enabled (b
->owner
))
1245 /* There is no point inserting thread-specific breakpoints if the
1246 thread no longer exists. */
1247 if (b
->owner
->thread
!= -1
1248 && !valid_thread_id (b
->owner
->thread
))
1251 /* FIXME drow/2003-10-07: This code should be pushed elsewhere when
1252 hardware watchpoints are split into multiple loc breakpoints. */
1253 if ((b
->loc_type
== bp_loc_hardware_watchpoint
1254 || b
->owner
->type
== bp_watchpoint
) && !b
->owner
->val
)
1257 val
= evaluate_expression (b
->owner
->exp
);
1258 release_value (val
);
1259 if (value_lazy (val
))
1260 value_fetch_lazy (val
);
1261 b
->owner
->val
= val
;
1264 val
= insert_bp_location (b
, tmp_error_stream
,
1265 &disabled_breaks
, &process_warning
,
1266 &hw_breakpoint_error
);
1273 /* If a hardware breakpoint or watchpoint was inserted, add a
1274 message about possibly exhausted resources. */
1275 if (hw_breakpoint_error
)
1277 fprintf_unfiltered (tmp_error_stream
,
1278 "Could not insert hardware breakpoints:\n\
1279 You may have requested too many hardware breakpoints/watchpoints.\n");
1281 #ifdef ONE_PROCESS_WRITETEXT
1282 if (process_warning
)
1283 fprintf_unfiltered (tmp_error_stream
,
1284 "The same program may be running in another process.");
1286 target_terminal_ours_for_output ();
1287 error_stream (tmp_error_stream
);
1292 remove_breakpoints (void)
1294 struct bp_location
*b
;
1297 ALL_BP_LOCATIONS (b
)
1301 val
= remove_breakpoint (b
, mark_uninserted
);
1310 remove_hw_watchpoints (void)
1312 struct bp_location
*b
;
1315 ALL_BP_LOCATIONS (b
)
1317 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1319 val
= remove_breakpoint (b
, mark_uninserted
);
1328 reattach_breakpoints (int pid
)
1330 struct bp_location
*b
;
1332 struct cleanup
*old_chain
= save_inferior_ptid ();
1333 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1334 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1336 make_cleanup_ui_file_delete (tmp_error_stream
);
1338 inferior_ptid
= pid_to_ptid (pid
);
1339 ALL_BP_LOCATIONS (b
)
1344 val
= insert_bp_location (b
, tmp_error_stream
,
1345 &dummy1
, &dummy2
, &dummy3
);
1348 do_cleanups (old_chain
);
1353 do_cleanups (old_chain
);
1358 update_breakpoints_after_exec (void)
1360 struct breakpoint
*b
;
1361 struct breakpoint
*temp
;
1363 /* Doing this first prevents the badness of having delete_breakpoint()
1364 write a breakpoint's current "shadow contents" to lift the bp. That
1365 shadow is NOT valid after an exec()! */
1366 mark_breakpoints_out ();
1368 ALL_BREAKPOINTS_SAFE (b
, temp
)
1370 /* Solib breakpoints must be explicitly reset after an exec(). */
1371 if (b
->type
== bp_shlib_event
)
1373 delete_breakpoint (b
);
1377 /* Thread event breakpoints must be set anew after an exec(),
1378 as must overlay event breakpoints. */
1379 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1381 delete_breakpoint (b
);
1385 /* Step-resume breakpoints are meaningless after an exec(). */
1386 if (b
->type
== bp_step_resume
)
1388 delete_breakpoint (b
);
1392 /* Ditto the exception-handling catchpoints. */
1393 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1395 delete_breakpoint (b
);
1399 /* Don't delete an exec catchpoint, because else the inferior
1400 won't stop when it ought!
1402 Similarly, we probably ought to keep vfork catchpoints, 'cause
1403 on this target, we may not be able to stop when the vfork is
1404 seen, but only when the subsequent exec is seen. (And because
1405 deleting fork catchpoints here but not vfork catchpoints will
1406 seem mysterious to users, keep those too.) */
1407 if ((b
->type
== bp_catch_exec
) ||
1408 (b
->type
== bp_catch_vfork
) ||
1409 (b
->type
== bp_catch_fork
))
1414 /* bp_finish is a special case. The only way we ought to be able
1415 to see one of these when an exec() has happened, is if the user
1416 caught a vfork, and then said "finish". Ordinarily a finish just
1417 carries them to the call-site of the current callee, by setting
1418 a temporary bp there and resuming. But in this case, the finish
1419 will carry them entirely through the vfork & exec.
1421 We don't want to allow a bp_finish to remain inserted now. But
1422 we can't safely delete it, 'cause finish_command has a handle to
1423 the bp on a bpstat, and will later want to delete it. There's a
1424 chance (and I've seen it happen) that if we delete the bp_finish
1425 here, that its storage will get reused by the time finish_command
1426 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1427 We really must allow finish_command to delete a bp_finish.
1429 In the absense of a general solution for the "how do we know
1430 it's safe to delete something others may have handles to?"
1431 problem, what we'll do here is just uninsert the bp_finish, and
1432 let finish_command delete it.
1434 (We know the bp_finish is "doomed" in the sense that it's
1435 momentary, and will be deleted as soon as finish_command sees
1436 the inferior stopped. So it doesn't matter that the bp's
1437 address is probably bogus in the new a.out, unlike e.g., the
1438 solib breakpoints.) */
1440 if (b
->type
== bp_finish
)
1445 /* Without a symbolic address, we have little hope of the
1446 pre-exec() address meaning the same thing in the post-exec()
1448 if (b
->addr_string
== NULL
)
1450 delete_breakpoint (b
);
1454 /* FIXME what about longjmp breakpoints? Re-create them here? */
1455 create_overlay_event_breakpoint ("_ovly_debug_event");
1459 detach_breakpoints (int pid
)
1461 struct bp_location
*b
;
1463 struct cleanup
*old_chain
= save_inferior_ptid ();
1465 if (pid
== PIDGET (inferior_ptid
))
1466 error (_("Cannot detach breakpoints of inferior_ptid"));
1468 /* Set inferior_ptid; remove_breakpoint uses this global. */
1469 inferior_ptid
= pid_to_ptid (pid
);
1470 ALL_BP_LOCATIONS (b
)
1474 val
= remove_breakpoint (b
, mark_inserted
);
1477 do_cleanups (old_chain
);
1482 do_cleanups (old_chain
);
1487 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1491 if (b
->owner
->enable_state
== bp_permanent
)
1492 /* Permanent breakpoints cannot be inserted or removed. */
1495 if (b
->owner
->type
== bp_none
)
1496 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1499 if (b
->loc_type
== bp_loc_software_breakpoint
1500 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1502 /* "Normal" instruction breakpoint: either the standard
1503 trap-instruction bp (bp_breakpoint), or a
1504 bp_hardware_breakpoint. */
1506 /* First check to see if we have to handle an overlay. */
1507 if (overlay_debugging
== ovly_off
1508 || b
->section
== NULL
1509 || !(section_is_overlay (b
->section
)))
1511 /* No overlay handling: just remove the breakpoint. */
1513 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1514 val
= target_remove_hw_breakpoint (&b
->target_info
);
1516 val
= target_remove_breakpoint (&b
->target_info
);
1520 /* This breakpoint is in an overlay section.
1521 Did we set a breakpoint at the LMA? */
1522 if (!overlay_events_enabled
)
1524 /* Yes -- overlay event support is not active, so we
1525 should have set a breakpoint at the LMA. Remove it.
1527 /* Ignore any failures: if the LMA is in ROM, we will
1528 have already warned when we failed to insert it. */
1529 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1530 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1532 target_remove_breakpoint (&b
->overlay_target_info
);
1534 /* Did we set a breakpoint at the VMA?
1535 If so, we will have marked the breakpoint 'inserted'. */
1538 /* Yes -- remove it. Previously we did not bother to
1539 remove the breakpoint if the section had been
1540 unmapped, but let's not rely on that being safe. We
1541 don't know what the overlay manager might do. */
1542 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1543 val
= target_remove_hw_breakpoint (&b
->target_info
);
1545 /* However, we should remove *software* breakpoints only
1546 if the section is still mapped, or else we overwrite
1547 wrong code with the saved shadow contents. */
1548 else if (section_is_mapped (b
->section
))
1549 val
= target_remove_breakpoint (&b
->target_info
);
1555 /* No -- not inserted, so no need to remove. No error. */
1561 b
->inserted
= (is
== mark_inserted
);
1563 else if (b
->loc_type
== bp_loc_hardware_watchpoint
1564 && breakpoint_enabled (b
->owner
)
1570 b
->inserted
= (is
== mark_inserted
);
1571 /* Walk down the saved value chain. */
1572 for (v
= b
->owner
->val_chain
; v
; v
= value_next (v
))
1574 /* For each memory reference remove the watchpoint
1576 if (VALUE_LVAL (v
) == lval_memory
1577 && ! value_lazy (v
))
1579 struct type
*vtype
= check_typedef (value_type (v
));
1581 if (v
== b
->owner
->val_chain
1582 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1583 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1588 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
1589 len
= TYPE_LENGTH (value_type (v
));
1591 if (b
->owner
->type
== bp_read_watchpoint
)
1593 else if (b
->owner
->type
== bp_access_watchpoint
)
1596 val
= target_remove_watchpoint (addr
, len
, type
);
1603 /* Failure to remove any of the hardware watchpoints comes here. */
1604 if ((is
== mark_uninserted
) && (b
->inserted
))
1605 warning (_("Could not remove hardware watchpoint %d."),
1608 else if ((b
->owner
->type
== bp_catch_fork
||
1609 b
->owner
->type
== bp_catch_vfork
||
1610 b
->owner
->type
== bp_catch_exec
)
1611 && breakpoint_enabled (b
->owner
)
1615 switch (b
->owner
->type
)
1618 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1620 case bp_catch_vfork
:
1621 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1624 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1627 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1632 b
->inserted
= (is
== mark_inserted
);
1634 else if ((b
->owner
->type
== bp_catch_catch
||
1635 b
->owner
->type
== bp_catch_throw
)
1636 && breakpoint_enabled (b
->owner
)
1639 val
= target_remove_breakpoint (&b
->target_info
);
1642 b
->inserted
= (is
== mark_inserted
);
1648 /* Clear the "inserted" flag in all breakpoints. */
1651 mark_breakpoints_out (void)
1653 struct bp_location
*bpt
;
1655 ALL_BP_LOCATIONS (bpt
)
1659 /* Clear the "inserted" flag in all breakpoints and delete any
1660 breakpoints which should go away between runs of the program.
1662 Plus other such housekeeping that has to be done for breakpoints
1665 Note: this function gets called at the end of a run (by
1666 generic_mourn_inferior) and when a run begins (by
1667 init_wait_for_inferior). */
1672 breakpoint_init_inferior (enum inf_context context
)
1674 struct breakpoint
*b
, *temp
;
1675 struct bp_location
*bpt
;
1677 ALL_BP_LOCATIONS (bpt
)
1680 ALL_BREAKPOINTS_SAFE (b
, temp
)
1685 case bp_watchpoint_scope
:
1687 /* If the call dummy breakpoint is at the entry point it will
1688 cause problems when the inferior is rerun, so we better
1691 Also get rid of scope breakpoints. */
1692 delete_breakpoint (b
);
1696 case bp_hardware_watchpoint
:
1697 case bp_read_watchpoint
:
1698 case bp_access_watchpoint
:
1700 /* Likewise for watchpoints on local expressions. */
1701 if (b
->exp_valid_block
!= NULL
)
1702 delete_breakpoint (b
);
1703 else if (context
== inf_starting
)
1705 /* Reset val field to force reread of starting value
1706 in insert_breakpoints. */
1708 value_free (b
->val
);
1718 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1719 exists at PC. It returns ordinary_breakpoint_here if it's an
1720 ordinary breakpoint, or permanent_breakpoint_here if it's a
1721 permanent breakpoint.
1722 - When continuing from a location with an ordinary breakpoint, we
1723 actually single step once before calling insert_breakpoints.
1724 - When continuing from a localion with a permanent breakpoint, we
1725 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1726 the target, to advance the PC past the breakpoint. */
1728 enum breakpoint_here
1729 breakpoint_here_p (CORE_ADDR pc
)
1731 const struct bp_location
*bpt
;
1732 int any_breakpoint_here
= 0;
1734 ALL_BP_LOCATIONS (bpt
)
1736 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1737 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1740 if ((breakpoint_enabled (bpt
->owner
)
1741 || bpt
->owner
->enable_state
== bp_permanent
)
1742 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1744 if (overlay_debugging
1745 && section_is_overlay (bpt
->section
)
1746 && !section_is_mapped (bpt
->section
))
1747 continue; /* unmapped overlay -- can't be a match */
1748 else if (bpt
->owner
->enable_state
== bp_permanent
)
1749 return permanent_breakpoint_here
;
1751 any_breakpoint_here
= 1;
1755 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1759 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1760 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1761 This does not check for single-step breakpoints, which are
1762 inserted and removed using direct target manipulation. */
1765 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1767 const struct bp_location
*bpt
;
1769 ALL_BP_LOCATIONS (bpt
)
1771 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1772 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1776 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1778 if (overlay_debugging
1779 && section_is_overlay (bpt
->section
)
1780 && !section_is_mapped (bpt
->section
))
1781 continue; /* unmapped overlay -- can't be a match */
1789 /* Returns non-zero iff there's either regular breakpoint
1790 or a single step breakpoint inserted at PC. */
1793 breakpoint_inserted_here_p (CORE_ADDR pc
)
1795 if (regular_breakpoint_inserted_here_p (pc
))
1798 if (single_step_breakpoint_inserted_here_p (pc
))
1804 /* This function returns non-zero iff there is a software breakpoint
1808 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1810 const struct bp_location
*bpt
;
1811 int any_breakpoint_here
= 0;
1813 ALL_BP_LOCATIONS (bpt
)
1815 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1819 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1821 if (overlay_debugging
1822 && section_is_overlay (bpt
->section
)
1823 && !section_is_mapped (bpt
->section
))
1824 continue; /* unmapped overlay -- can't be a match */
1830 /* Also check for software single-step breakpoints. */
1831 if (single_step_breakpoint_inserted_here_p (pc
))
1837 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1838 PC is valid for process/thread PTID. */
1841 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1843 const struct bp_location
*bpt
;
1846 thread
= pid_to_thread_id (ptid
);
1848 ALL_BP_LOCATIONS (bpt
)
1850 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1851 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1854 if ((breakpoint_enabled (bpt
->owner
)
1855 || bpt
->owner
->enable_state
== bp_permanent
)
1856 && bpt
->address
== pc
1857 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1859 if (overlay_debugging
1860 && section_is_overlay (bpt
->section
)
1861 && !section_is_mapped (bpt
->section
))
1862 continue; /* unmapped overlay -- can't be a match */
1872 /* bpstat stuff. External routines' interfaces are documented
1876 ep_is_catchpoint (struct breakpoint
*ep
)
1879 (ep
->type
== bp_catch_load
)
1880 || (ep
->type
== bp_catch_unload
)
1881 || (ep
->type
== bp_catch_fork
)
1882 || (ep
->type
== bp_catch_vfork
)
1883 || (ep
->type
== bp_catch_exec
)
1884 || (ep
->type
== bp_catch_catch
)
1885 || (ep
->type
== bp_catch_throw
);
1887 /* ??rehrauer: Add more kinds here, as are implemented... */
1891 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1894 (ep
->type
== bp_catch_load
)
1895 || (ep
->type
== bp_catch_unload
);
1899 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1902 (ep
->type
== bp_catch_catch
)
1903 || (ep
->type
== bp_catch_throw
);
1907 bpstat_free (bpstat bs
)
1909 if (bs
->old_val
!= NULL
)
1910 value_free (bs
->old_val
);
1911 free_command_lines (&bs
->commands
);
1915 /* Clear a bpstat so that it says we are not at any breakpoint.
1916 Also free any storage that is part of a bpstat. */
1919 bpstat_clear (bpstat
*bsp
)
1936 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1937 is part of the bpstat is copied as well. */
1940 bpstat_copy (bpstat bs
)
1944 bpstat retval
= NULL
;
1949 for (; bs
!= NULL
; bs
= bs
->next
)
1951 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1952 memcpy (tmp
, bs
, sizeof (*tmp
));
1953 if (bs
->commands
!= NULL
)
1954 tmp
->commands
= copy_command_lines (bs
->commands
);
1955 if (bs
->old_val
!= NULL
)
1956 tmp
->old_val
= value_copy (bs
->old_val
);
1959 /* This is the first thing in the chain. */
1969 /* Find the bpstat associated with this breakpoint */
1972 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1977 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1979 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
1985 /* Find a step_resume breakpoint associated with this bpstat.
1986 (If there are multiple step_resume bp's on the list, this function
1987 will arbitrarily pick one.)
1989 It is an error to use this function if BPSTAT doesn't contain a
1990 step_resume breakpoint.
1992 See wait_for_inferior's use of this function. */
1994 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1998 gdb_assert (bsp
!= NULL
);
2000 current_thread
= pid_to_thread_id (inferior_ptid
);
2002 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2004 if ((bsp
->breakpoint_at
!= NULL
) &&
2005 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2006 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2007 bsp
->breakpoint_at
->owner
->thread
== -1))
2008 return bsp
->breakpoint_at
->owner
;
2011 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2015 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2016 at. *BSP upon return is a bpstat which points to the remaining
2017 breakpoints stopped at (but which is not guaranteed to be good for
2018 anything but further calls to bpstat_num).
2019 Return 0 if passed a bpstat which does not indicate any breakpoints.
2020 Return -1 if stopped at a breakpoint that has been deleted since
2022 Return 1 otherwise. */
2025 bpstat_num (bpstat
*bsp
, int *num
)
2027 struct breakpoint
*b
;
2030 return 0; /* No more breakpoint values */
2032 /* We assume we'll never have several bpstats that
2033 correspond to a single breakpoint -- otherwise,
2034 this function might return the same number more
2035 than once and this will look ugly. */
2036 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2037 *bsp
= (*bsp
)->next
;
2039 return -1; /* breakpoint that's been deleted since */
2041 *num
= b
->number
; /* We have its number */
2045 /* Modify BS so that the actions will not be performed. */
2048 bpstat_clear_actions (bpstat bs
)
2050 for (; bs
!= NULL
; bs
= bs
->next
)
2052 free_command_lines (&bs
->commands
);
2053 if (bs
->old_val
!= NULL
)
2055 value_free (bs
->old_val
);
2061 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2063 cleanup_executing_breakpoints (void *ignore
)
2065 executing_breakpoint_commands
= 0;
2068 /* Execute all the commands associated with all the breakpoints at this
2069 location. Any of these commands could cause the process to proceed
2070 beyond this point, etc. We look out for such changes by checking
2071 the global "breakpoint_proceeded" after each command. */
2074 bpstat_do_actions (bpstat
*bsp
)
2077 struct cleanup
*old_chain
;
2079 /* Avoid endless recursion if a `source' command is contained
2081 if (executing_breakpoint_commands
)
2084 executing_breakpoint_commands
= 1;
2085 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2088 /* Note that (as of this writing), our callers all appear to
2089 be passing us the address of global stop_bpstat. And, if
2090 our calls to execute_control_command cause the inferior to
2091 proceed, that global (and hence, *bsp) will change.
2093 We must be careful to not touch *bsp unless the inferior
2094 has not proceeded. */
2096 /* This pointer will iterate over the list of bpstat's. */
2099 breakpoint_proceeded
= 0;
2100 for (; bs
!= NULL
; bs
= bs
->next
)
2102 struct command_line
*cmd
;
2103 struct cleanup
*this_cmd_tree_chain
;
2105 /* Take ownership of the BSP's command tree, if it has one.
2107 The command tree could legitimately contain commands like
2108 'step' and 'next', which call clear_proceed_status, which
2109 frees stop_bpstat's command tree. To make sure this doesn't
2110 free the tree we're executing out from under us, we need to
2111 take ownership of the tree ourselves. Since a given bpstat's
2112 commands are only executed once, we don't need to copy it; we
2113 can clear the pointer in the bpstat, and make sure we free
2114 the tree when we're done. */
2117 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2121 execute_control_command (cmd
);
2123 if (breakpoint_proceeded
)
2129 /* We can free this command tree now. */
2130 do_cleanups (this_cmd_tree_chain
);
2132 if (breakpoint_proceeded
)
2133 /* The inferior is proceeded by the command; bomb out now.
2134 The bpstat chain has been blown away by wait_for_inferior.
2135 But since execution has stopped again, there is a new bpstat
2136 to look at, so start over. */
2139 do_cleanups (old_chain
);
2142 /* This is the normal print function for a bpstat. In the future,
2143 much of this logic could (should?) be moved to bpstat_stop_status,
2144 by having it set different print_it values.
2146 Current scheme: When we stop, bpstat_print() is called. It loops
2147 through the bpstat list of things causing this stop, calling the
2148 print_bp_stop_message function on each one. The behavior of the
2149 print_bp_stop_message function depends on the print_it field of
2150 bpstat. If such field so indicates, call this function here.
2152 Return values from this routine (ultimately used by bpstat_print()
2153 and normal_stop() to decide what to do):
2154 PRINT_NOTHING: Means we already printed all we needed to print,
2155 don't print anything else.
2156 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2157 that something to be followed by a location.
2158 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2159 that something to be followed by a location.
2160 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2163 static enum print_stop_action
2164 print_it_typical (bpstat bs
)
2166 struct cleanup
*old_chain
, *ui_out_chain
;
2167 struct breakpoint
*b
;
2168 const struct bp_location
*bl
;
2169 struct ui_stream
*stb
;
2170 stb
= ui_out_stream_new (uiout
);
2171 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2172 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2173 which has since been deleted. */
2174 if (bs
->breakpoint_at
== NULL
)
2175 return PRINT_UNKNOWN
;
2176 bl
= bs
->breakpoint_at
;
2182 case bp_hardware_breakpoint
:
2183 if (bl
->address
!= bl
->requested_address
)
2184 breakpoint_adjustment_warning (bl
->requested_address
,
2187 annotate_breakpoint (b
->number
);
2188 ui_out_text (uiout
, "\nBreakpoint ");
2189 if (ui_out_is_mi_like_p (uiout
))
2190 ui_out_field_string (uiout
, "reason",
2191 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2192 ui_out_field_int (uiout
, "bkptno", b
->number
);
2193 ui_out_text (uiout
, ", ");
2194 return PRINT_SRC_AND_LOC
;
2197 case bp_shlib_event
:
2198 /* Did we stop because the user set the stop_on_solib_events
2199 variable? (If so, we report this as a generic, "Stopped due
2200 to shlib event" message.) */
2201 printf_filtered (_("Stopped due to shared library event\n"));
2202 return PRINT_NOTHING
;
2205 case bp_thread_event
:
2206 /* Not sure how we will get here.
2207 GDB should not stop for these breakpoints. */
2208 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2209 return PRINT_NOTHING
;
2212 case bp_overlay_event
:
2213 /* By analogy with the thread event, GDB should not stop for these. */
2214 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2215 return PRINT_NOTHING
;
2219 annotate_catchpoint (b
->number
);
2220 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2222 b
->triggered_dll_pathname
);
2223 return PRINT_SRC_AND_LOC
;
2226 case bp_catch_unload
:
2227 annotate_catchpoint (b
->number
);
2228 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2230 b
->triggered_dll_pathname
);
2231 return PRINT_SRC_AND_LOC
;
2235 annotate_catchpoint (b
->number
);
2236 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2238 b
->forked_inferior_pid
);
2239 return PRINT_SRC_AND_LOC
;
2242 case bp_catch_vfork
:
2243 annotate_catchpoint (b
->number
);
2244 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2246 b
->forked_inferior_pid
);
2247 return PRINT_SRC_AND_LOC
;
2251 annotate_catchpoint (b
->number
);
2252 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2255 return PRINT_SRC_AND_LOC
;
2258 case bp_catch_catch
:
2259 if (current_exception_event
&&
2260 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2262 annotate_catchpoint (b
->number
);
2263 printf_filtered (_("\nCatchpoint %d (exception caught), "),
2265 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2266 printf_filtered (_("throw location %s:%d, "),
2267 CURRENT_EXCEPTION_THROW_FILE
,
2268 CURRENT_EXCEPTION_THROW_LINE
);
2270 printf_filtered (_("throw location unknown, "));
2272 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2273 printf_filtered (_("catch location %s:%d\n"),
2274 CURRENT_EXCEPTION_CATCH_FILE
,
2275 CURRENT_EXCEPTION_CATCH_LINE
);
2277 printf_filtered (_("catch location unknown\n"));
2279 /* don't bother to print location frame info */
2280 return PRINT_SRC_ONLY
;
2284 /* really throw, some other bpstat will handle it */
2285 return PRINT_UNKNOWN
;
2289 case bp_catch_throw
:
2290 if (current_exception_event
&&
2291 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2293 annotate_catchpoint (b
->number
);
2294 printf_filtered (_("\nCatchpoint %d (exception thrown), "),
2296 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2297 printf_filtered (_("throw location %s:%d, "),
2298 CURRENT_EXCEPTION_THROW_FILE
,
2299 CURRENT_EXCEPTION_THROW_LINE
);
2301 printf_filtered (_("throw location unknown, "));
2303 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2304 printf_filtered (_("catch location %s:%d\n"),
2305 CURRENT_EXCEPTION_CATCH_FILE
,
2306 CURRENT_EXCEPTION_CATCH_LINE
);
2308 printf_filtered (_("catch location unknown\n"));
2310 /* don't bother to print location frame info */
2311 return PRINT_SRC_ONLY
;
2315 /* really catch, some other bpstat will handle it */
2316 return PRINT_UNKNOWN
;
2321 case bp_hardware_watchpoint
:
2322 if (bs
->old_val
!= NULL
)
2324 annotate_watchpoint (b
->number
);
2325 if (ui_out_is_mi_like_p (uiout
))
2328 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2330 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2331 ui_out_text (uiout
, "\nOld value = ");
2332 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2333 ui_out_field_stream (uiout
, "old", stb
);
2334 ui_out_text (uiout
, "\nNew value = ");
2335 value_print (b
->val
, stb
->stream
, 0, Val_pretty_default
);
2336 ui_out_field_stream (uiout
, "new", stb
);
2337 do_cleanups (ui_out_chain
);
2338 ui_out_text (uiout
, "\n");
2339 value_free (bs
->old_val
);
2342 /* More than one watchpoint may have been triggered. */
2343 return PRINT_UNKNOWN
;
2346 case bp_read_watchpoint
:
2347 if (ui_out_is_mi_like_p (uiout
))
2350 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2352 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2353 ui_out_text (uiout
, "\nValue = ");
2354 value_print (b
->val
, stb
->stream
, 0, Val_pretty_default
);
2355 ui_out_field_stream (uiout
, "value", stb
);
2356 do_cleanups (ui_out_chain
);
2357 ui_out_text (uiout
, "\n");
2358 return PRINT_UNKNOWN
;
2361 case bp_access_watchpoint
:
2362 if (bs
->old_val
!= NULL
)
2364 annotate_watchpoint (b
->number
);
2365 if (ui_out_is_mi_like_p (uiout
))
2368 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2370 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2371 ui_out_text (uiout
, "\nOld value = ");
2372 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2373 ui_out_field_stream (uiout
, "old", stb
);
2374 value_free (bs
->old_val
);
2376 ui_out_text (uiout
, "\nNew value = ");
2381 if (ui_out_is_mi_like_p (uiout
))
2384 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2385 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2386 ui_out_text (uiout
, "\nValue = ");
2388 value_print (b
->val
, stb
->stream
, 0,Val_pretty_default
);
2389 ui_out_field_stream (uiout
, "new", stb
);
2390 do_cleanups (ui_out_chain
);
2391 ui_out_text (uiout
, "\n");
2392 return PRINT_UNKNOWN
;
2395 /* Fall through, we don't deal with these types of breakpoints
2399 if (ui_out_is_mi_like_p (uiout
))
2402 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2403 return PRINT_UNKNOWN
;
2407 if (ui_out_is_mi_like_p (uiout
))
2410 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2411 return PRINT_UNKNOWN
;
2416 case bp_longjmp_resume
:
2417 case bp_step_resume
:
2418 case bp_watchpoint_scope
:
2421 return PRINT_UNKNOWN
;
2425 /* Generic routine for printing messages indicating why we
2426 stopped. The behavior of this function depends on the value
2427 'print_it' in the bpstat structure. Under some circumstances we
2428 may decide not to print anything here and delegate the task to
2431 static enum print_stop_action
2432 print_bp_stop_message (bpstat bs
)
2434 switch (bs
->print_it
)
2437 /* Nothing should be printed for this bpstat entry. */
2438 return PRINT_UNKNOWN
;
2442 /* We still want to print the frame, but we already printed the
2443 relevant messages. */
2444 return PRINT_SRC_AND_LOC
;
2447 case print_it_normal
:
2449 const struct bp_location
*bl
= bs
->breakpoint_at
;
2450 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2452 /* Normal case. Call the breakpoint's print_it method, or
2453 print_it_typical. */
2454 /* FIXME: how breakpoint can ever be NULL here? */
2455 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2456 return b
->ops
->print_it (b
);
2458 return print_it_typical (bs
);
2463 internal_error (__FILE__
, __LINE__
,
2464 _("print_bp_stop_message: unrecognized enum value"));
2469 /* Print a message indicating what happened. This is called from
2470 normal_stop(). The input to this routine is the head of the bpstat
2471 list - a list of the eventpoints that caused this stop. This
2472 routine calls the generic print routine for printing a message
2473 about reasons for stopping. This will print (for example) the
2474 "Breakpoint n," part of the output. The return value of this
2477 PRINT_UNKNOWN: Means we printed nothing
2478 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2479 code to print the location. An example is
2480 "Breakpoint 1, " which should be followed by
2482 PRINT_SRC_ONLY: Means we printed something, but there is no need
2483 to also print the location part of the message.
2484 An example is the catch/throw messages, which
2485 don't require a location appended to the end.
2486 PRINT_NOTHING: We have done some printing and we don't need any
2487 further info to be printed.*/
2489 enum print_stop_action
2490 bpstat_print (bpstat bs
)
2494 /* Maybe another breakpoint in the chain caused us to stop.
2495 (Currently all watchpoints go on the bpstat whether hit or not.
2496 That probably could (should) be changed, provided care is taken
2497 with respect to bpstat_explains_signal). */
2498 for (; bs
; bs
= bs
->next
)
2500 val
= print_bp_stop_message (bs
);
2501 if (val
== PRINT_SRC_ONLY
2502 || val
== PRINT_SRC_AND_LOC
2503 || val
== PRINT_NOTHING
)
2507 /* We reached the end of the chain, or we got a null BS to start
2508 with and nothing was printed. */
2509 return PRINT_UNKNOWN
;
2512 /* Evaluate the expression EXP and return 1 if value is zero.
2513 This is used inside a catch_errors to evaluate the breakpoint condition.
2514 The argument is a "struct expression *" that has been cast to char * to
2515 make it pass through catch_errors. */
2518 breakpoint_cond_eval (void *exp
)
2520 struct value
*mark
= value_mark ();
2521 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2522 value_free_to_mark (mark
);
2526 /* Allocate a new bpstat and chain it to the current one. */
2529 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2533 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2535 bs
->breakpoint_at
= bl
;
2536 /* If the condition is false, etc., don't do the commands. */
2537 bs
->commands
= NULL
;
2539 bs
->print_it
= print_it_normal
;
2543 /* The target has stopped with waitstatus WS. Check if any hardware
2544 watchpoints have triggered, according to the target. */
2547 watchpoints_triggered (struct target_waitstatus
*ws
)
2549 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2551 struct breakpoint
*b
;
2553 if (!stopped_by_watchpoint
)
2555 /* We were not stopped by a watchpoint. Mark all watchpoints
2556 as not triggered. */
2558 if (b
->type
== bp_hardware_watchpoint
2559 || b
->type
== bp_read_watchpoint
2560 || b
->type
== bp_access_watchpoint
)
2561 b
->watchpoint_triggered
= watch_triggered_no
;
2566 if (!target_stopped_data_address (¤t_target
, &addr
))
2568 /* We were stopped by a watchpoint, but we don't know where.
2569 Mark all watchpoints as unknown. */
2571 if (b
->type
== bp_hardware_watchpoint
2572 || b
->type
== bp_read_watchpoint
2573 || b
->type
== bp_access_watchpoint
)
2574 b
->watchpoint_triggered
= watch_triggered_unknown
;
2576 return stopped_by_watchpoint
;
2579 /* The target could report the data address. Mark watchpoints
2580 affected by this data address as triggered, and all others as not
2584 if (b
->type
== bp_hardware_watchpoint
2585 || b
->type
== bp_read_watchpoint
2586 || b
->type
== bp_access_watchpoint
)
2590 b
->watchpoint_triggered
= watch_triggered_no
;
2591 for (v
= b
->val_chain
; v
; v
= value_next (v
))
2593 if (VALUE_LVAL (v
) == lval_memory
&& ! value_lazy (v
))
2595 struct type
*vtype
= check_typedef (value_type (v
));
2597 if (v
== b
->val_chain
2598 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2599 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2603 vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
2604 /* Exact match not required. Within range is
2607 && addr
< vaddr
+ TYPE_LENGTH (value_type (v
)))
2609 b
->watchpoint_triggered
= watch_triggered_yes
;
2620 /* Possible return values for watchpoint_check (this can't be an enum
2621 because of check_errors). */
2622 /* The watchpoint has been deleted. */
2623 #define WP_DELETED 1
2624 /* The value has changed. */
2625 #define WP_VALUE_CHANGED 2
2626 /* The value has not changed. */
2627 #define WP_VALUE_NOT_CHANGED 3
2629 #define BP_TEMPFLAG 1
2630 #define BP_HARDWAREFLAG 2
2632 /* Check watchpoint condition. */
2635 watchpoint_check (void *p
)
2637 bpstat bs
= (bpstat
) p
;
2638 struct breakpoint
*b
;
2639 struct frame_info
*fr
;
2640 int within_current_scope
;
2642 b
= bs
->breakpoint_at
->owner
;
2644 if (b
->exp_valid_block
== NULL
)
2645 within_current_scope
= 1;
2648 /* There is no current frame at this moment. If we're going to have
2649 any chance of handling watchpoints on local variables, we'll need
2650 the frame chain (so we can determine if we're in scope). */
2651 reinit_frame_cache ();
2652 fr
= frame_find_by_id (b
->watchpoint_frame
);
2653 within_current_scope
= (fr
!= NULL
);
2655 /* If we've gotten confused in the unwinder, we might have
2656 returned a frame that can't describe this variable. */
2657 if (within_current_scope
2658 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2659 within_current_scope
= 0;
2661 /* in_function_epilogue_p() returns a non-zero value if we're still
2662 in the function but the stack frame has already been invalidated.
2663 Since we can't rely on the values of local variables after the
2664 stack has been destroyed, we are treating the watchpoint in that
2665 state as `not changed' without further checking.
2667 vinschen/2003-09-04: The former implementation left out the case
2668 that the watchpoint frame couldn't be found by frame_find_by_id()
2669 because the current PC is currently in an epilogue. Calling
2670 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2671 if ((!within_current_scope
|| fr
== get_current_frame ())
2672 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2673 return WP_VALUE_NOT_CHANGED
;
2674 if (fr
&& within_current_scope
)
2675 /* If we end up stopping, the current frame will get selected
2676 in normal_stop. So this call to select_frame won't affect
2681 if (within_current_scope
)
2683 /* We use value_{,free_to_}mark because it could be a
2684 *long* time before we return to the command level and
2685 call free_all_values. We can't call free_all_values because
2686 we might be in the middle of evaluating a function call. */
2688 struct value
*mark
= value_mark ();
2689 struct value
*new_val
= evaluate_expression (b
->exp
);
2690 if (!value_equal (b
->val
, new_val
))
2692 release_value (new_val
);
2693 value_free_to_mark (mark
);
2694 bs
->old_val
= b
->val
;
2696 /* We will stop here */
2697 return WP_VALUE_CHANGED
;
2701 /* Nothing changed, don't do anything. */
2702 value_free_to_mark (mark
);
2703 /* We won't stop here */
2704 return WP_VALUE_NOT_CHANGED
;
2709 /* This seems like the only logical thing to do because
2710 if we temporarily ignored the watchpoint, then when
2711 we reenter the block in which it is valid it contains
2712 garbage (in the case of a function, it may have two
2713 garbage values, one before and one after the prologue).
2714 So we can't even detect the first assignment to it and
2715 watch after that (since the garbage may or may not equal
2716 the first value assigned). */
2717 /* We print all the stop information in print_it_typical(), but
2718 in this case, by the time we call print_it_typical() this bp
2719 will be deleted already. So we have no choice but print the
2720 information here. */
2721 if (ui_out_is_mi_like_p (uiout
))
2723 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2724 ui_out_text (uiout
, "\nWatchpoint ");
2725 ui_out_field_int (uiout
, "wpnum", b
->number
);
2726 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2727 which its expression is valid.\n");
2729 if (b
->related_breakpoint
)
2730 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2731 b
->disposition
= disp_del_at_next_stop
;
2737 /* Get a bpstat associated with having just stopped at address
2738 BP_ADDR in thread PTID.
2740 Determine whether we stopped at a breakpoint, etc, or whether we
2741 don't understand this stop. Result is a chain of bpstat's such that:
2743 if we don't understand the stop, the result is a null pointer.
2745 if we understand why we stopped, the result is not null.
2747 Each element of the chain refers to a particular breakpoint or
2748 watchpoint at which we have stopped. (We may have stopped for
2749 several reasons concurrently.)
2751 Each element of the chain has valid next, breakpoint_at,
2752 commands, FIXME??? fields. */
2755 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2757 struct breakpoint
*b
= NULL
;
2758 const struct bp_location
*bl
;
2759 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2760 int real_breakpoint
= 0;
2761 /* Root of the chain of bpstat's */
2762 struct bpstats root_bs
[1];
2763 /* Pointer to the last thing in the chain currently. */
2764 bpstat bs
= root_bs
;
2765 int thread_id
= pid_to_thread_id (ptid
);
2767 ALL_BP_LOCATIONS (bl
)
2771 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2774 if (b
->type
!= bp_watchpoint
2775 && b
->type
!= bp_hardware_watchpoint
2776 && b
->type
!= bp_read_watchpoint
2777 && b
->type
!= bp_access_watchpoint
2778 && b
->type
!= bp_hardware_breakpoint
2779 && b
->type
!= bp_catch_fork
2780 && b
->type
!= bp_catch_vfork
2781 && b
->type
!= bp_catch_exec
2782 && b
->type
!= bp_catch_catch
2783 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2785 if (bl
->address
!= bp_addr
) /* address doesn't match */
2787 if (overlay_debugging
/* unmapped overlay section */
2788 && section_is_overlay (bl
->section
)
2789 && !section_is_mapped (bl
->section
))
2793 /* Continuable hardware watchpoints are treated as non-existent if the
2794 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2795 some data address). Otherwise gdb won't stop on a break instruction
2796 in the code (not from a breakpoint) when a hardware watchpoint has
2797 been defined. Also skip watchpoints which we know did not trigger
2798 (did not match the data address). */
2800 if ((b
->type
== bp_hardware_watchpoint
2801 || b
->type
== bp_read_watchpoint
2802 || b
->type
== bp_access_watchpoint
)
2803 && b
->watchpoint_triggered
== watch_triggered_no
)
2806 if (b
->type
== bp_hardware_breakpoint
)
2808 if (bl
->address
!= bp_addr
)
2810 if (overlay_debugging
/* unmapped overlay section */
2811 && section_is_overlay (bl
->section
)
2812 && !section_is_mapped (bl
->section
))
2816 /* Is this a catchpoint of a load or unload? If so, did we
2817 get a load or unload of the specified library? If not,
2819 if ((b
->type
== bp_catch_load
)
2820 #if defined(SOLIB_HAVE_LOAD_EVENT)
2821 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2822 || ((b
->dll_pathname
!= NULL
)
2823 && (strcmp (b
->dll_pathname
,
2824 SOLIB_LOADED_LIBRARY_PATHNAME (
2825 PIDGET (inferior_ptid
)))
2831 if ((b
->type
== bp_catch_unload
)
2832 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2833 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2834 || ((b
->dll_pathname
!= NULL
)
2835 && (strcmp (b
->dll_pathname
,
2836 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2837 PIDGET (inferior_ptid
)))
2843 if ((b
->type
== bp_catch_fork
)
2844 && !inferior_has_forked (PIDGET (inferior_ptid
),
2845 &b
->forked_inferior_pid
))
2848 if ((b
->type
== bp_catch_vfork
)
2849 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2850 &b
->forked_inferior_pid
))
2853 if ((b
->type
== bp_catch_exec
)
2854 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2857 if (ep_is_exception_catchpoint (b
) &&
2858 !(current_exception_event
= target_get_current_exception_event ()))
2861 /* Come here if it's a watchpoint, or if the break address matches */
2863 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
2865 /* Watchpoints may change this, if not found to have triggered. */
2869 if (b
->type
== bp_watchpoint
2870 || b
->type
== bp_read_watchpoint
2871 || b
->type
== bp_access_watchpoint
2872 || b
->type
== bp_hardware_watchpoint
)
2876 int must_check_value
= 0;
2878 if (b
->type
== bp_watchpoint
)
2879 /* For a software watchpoint, we must always check the
2881 must_check_value
= 1;
2882 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2883 /* We have a hardware watchpoint (read, write, or access)
2884 and the target earlier reported an address watched by
2886 must_check_value
= 1;
2887 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2888 && b
->type
== bp_hardware_watchpoint
)
2889 /* We were stopped by a hardware watchpoint, but the target could
2890 not report the data address. We must check the watchpoint's
2891 value. Access and read watchpoints are out of luck; without
2892 a data address, we can't figure it out. */
2893 must_check_value
= 1;
2895 if (must_check_value
)
2897 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2899 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2900 int e
= catch_errors (watchpoint_check
, bs
, message
,
2902 do_cleanups (cleanups
);
2906 /* We've already printed what needs to be printed. */
2907 bs
->print_it
= print_it_done
;
2910 case WP_VALUE_CHANGED
:
2911 if (b
->type
== bp_read_watchpoint
)
2913 /* Don't stop: read watchpoints shouldn't fire if
2914 the value has changed. This is for targets
2915 which cannot set read-only watchpoints. */
2916 bs
->print_it
= print_it_noop
;
2922 case WP_VALUE_NOT_CHANGED
:
2923 if (b
->type
== bp_hardware_watchpoint
2924 || b
->type
== bp_watchpoint
)
2926 /* Don't stop: write watchpoints shouldn't fire if
2927 the value hasn't changed. */
2928 bs
->print_it
= print_it_noop
;
2938 /* Error from catch_errors. */
2939 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2940 if (b
->related_breakpoint
)
2941 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2942 b
->disposition
= disp_del_at_next_stop
;
2943 /* We've already printed what needs to be printed. */
2944 bs
->print_it
= print_it_done
;
2948 else /* must_check_value == 0 */
2950 /* This is a case where some watchpoint(s) triggered, but
2951 not at the address of this watchpoint, or else no
2952 watchpoint triggered after all. So don't print
2953 anything for this watchpoint. */
2954 bs
->print_it
= print_it_noop
;
2961 /* By definition, an encountered breakpoint is a triggered
2965 real_breakpoint
= 1;
2968 if (frame_id_p (b
->frame_id
)
2969 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2973 int value_is_zero
= 0;
2975 /* If this is a scope breakpoint, mark the associated
2976 watchpoint as triggered so that we will handle the
2977 out-of-scope event. We'll get to the watchpoint next
2979 if (b
->type
== bp_watchpoint_scope
)
2980 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2984 /* Need to select the frame, with all that implies
2985 so that the conditions will have the right context. */
2986 select_frame (get_current_frame ());
2988 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2989 "Error in testing breakpoint condition:\n",
2991 /* FIXME-someday, should give breakpoint # */
2994 if (bl
->cond
&& value_is_zero
)
2997 /* Don't consider this a hit. */
3000 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3003 /* Don't consider this a hit. */
3006 else if (b
->ignore_count
> 0)
3009 annotate_ignore_count_change ();
3012 else if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3013 /* We do not stop for these. */
3017 /* We will stop here */
3018 if (b
->disposition
== disp_disable
)
3019 b
->enable_state
= bp_disabled
;
3022 bs
->commands
= b
->commands
;
3024 (strcmp ("silent", bs
->commands
->line
) == 0
3025 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3027 bs
->commands
= bs
->commands
->next
;
3030 bs
->commands
= copy_command_lines (bs
->commands
);
3033 /* Print nothing for this entry if we dont stop or if we dont print. */
3034 if (bs
->stop
== 0 || bs
->print
== 0)
3035 bs
->print_it
= print_it_noop
;
3038 bs
->next
= NULL
; /* Terminate the chain */
3039 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3041 /* If we aren't stopping, the value of some hardware watchpoint may
3042 not have changed, but the intermediate memory locations we are
3043 watching may have. Don't bother if we're stopping; this will get
3045 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3050 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3052 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3053 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3054 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3056 remove_breakpoints ();
3057 insert_breakpoints ();
3061 return root_bs
->next
;
3064 /* Tell what to do about this bpstat. */
3066 bpstat_what (bpstat bs
)
3068 /* Classify each bpstat as one of the following. */
3071 /* This bpstat element has no effect on the main_action. */
3074 /* There was a watchpoint, stop but don't print. */
3077 /* There was a watchpoint, stop and print. */
3080 /* There was a breakpoint but we're not stopping. */
3083 /* There was a breakpoint, stop but don't print. */
3086 /* There was a breakpoint, stop and print. */
3089 /* We hit the longjmp breakpoint. */
3092 /* We hit the longjmp_resume breakpoint. */
3095 /* We hit the step_resume breakpoint. */
3098 /* We hit the shared library event breakpoint. */
3101 /* We caught a shared library event. */
3104 /* This is just used to count how many enums there are. */
3108 /* Here is the table which drives this routine. So that we can
3109 format it pretty, we define some abbreviations for the
3110 enum bpstat_what codes. */
3111 #define kc BPSTAT_WHAT_KEEP_CHECKING
3112 #define ss BPSTAT_WHAT_STOP_SILENT
3113 #define sn BPSTAT_WHAT_STOP_NOISY
3114 #define sgl BPSTAT_WHAT_SINGLE
3115 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3116 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3117 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
3118 #define sr BPSTAT_WHAT_STEP_RESUME
3119 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3120 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3122 /* "Can't happen." Might want to print an error message.
3123 abort() is not out of the question, but chances are GDB is just
3124 a bit confused, not unusable. */
3125 #define err BPSTAT_WHAT_STOP_NOISY
3127 /* Given an old action and a class, come up with a new action. */
3128 /* One interesting property of this table is that wp_silent is the same
3129 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3130 after stopping, the check for whether to step over a breakpoint
3131 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3132 reference to how we stopped. We retain separate wp_silent and
3133 bp_silent codes in case we want to change that someday.
3135 Another possibly interesting property of this table is that
3136 there's a partial ordering, priority-like, of the actions. Once
3137 you've decided that some action is appropriate, you'll never go
3138 back and decide something of a lower priority is better. The
3141 kc < clr sgl shl shlr slr sn sr ss
3142 sgl < clrs shl shlr slr sn sr ss
3143 slr < err shl shlr sn sr ss
3144 clr < clrs err shl shlr sn sr ss
3145 clrs < err shl shlr sn sr ss
3152 What I think this means is that we don't need a damned table
3153 here. If you just put the rows and columns in the right order,
3154 it'd look awfully regular. We could simply walk the bpstat list
3155 and choose the highest priority action we find, with a little
3156 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3157 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3158 is messy anyway). */
3160 /* step_resume entries: a step resume breakpoint overrides another
3161 breakpoint of signal handling (see comment in wait_for_inferior
3162 at where we set the step_resume breakpoint). */
3164 static const enum bpstat_what_main_action
3165 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3168 /* kc ss sn sgl slr clr clrs sr shl shlr
3171 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, shl
, shlr
},
3173 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3175 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3177 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, shl
, shlr
},
3179 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3181 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3183 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, shl
, shlr
},
3185 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, shl
, shlr
},
3187 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3189 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3191 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3206 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3207 struct bpstat_what retval
;
3209 retval
.call_dummy
= 0;
3210 for (; bs
!= NULL
; bs
= bs
->next
)
3212 enum class bs_class
= no_effect
;
3213 if (bs
->breakpoint_at
== NULL
)
3214 /* I suspect this can happen if it was a momentary breakpoint
3215 which has since been deleted. */
3217 switch (bs
->breakpoint_at
->owner
->type
)
3223 case bp_hardware_breakpoint
:
3229 bs_class
= bp_noisy
;
3231 bs_class
= bp_silent
;
3234 bs_class
= bp_nostop
;
3237 case bp_hardware_watchpoint
:
3238 case bp_read_watchpoint
:
3239 case bp_access_watchpoint
:
3243 bs_class
= wp_noisy
;
3245 bs_class
= wp_silent
;
3248 /* There was a watchpoint, but we're not stopping.
3249 This requires no further action. */
3250 bs_class
= no_effect
;
3253 bs_class
= long_jump
;
3255 case bp_longjmp_resume
:
3256 bs_class
= long_resume
;
3258 case bp_step_resume
:
3261 bs_class
= step_resume
;
3264 /* It is for the wrong frame. */
3265 bs_class
= bp_nostop
;
3267 case bp_watchpoint_scope
:
3268 bs_class
= bp_nostop
;
3270 case bp_shlib_event
:
3271 bs_class
= shlib_event
;
3273 case bp_thread_event
:
3274 case bp_overlay_event
:
3275 bs_class
= bp_nostop
;
3278 case bp_catch_unload
:
3279 /* Only if this catchpoint triggered should we cause the
3280 step-out-of-dld behaviour. Otherwise, we ignore this
3283 bs_class
= catch_shlib_event
;
3285 bs_class
= no_effect
;
3288 case bp_catch_vfork
:
3293 bs_class
= bp_noisy
;
3295 bs_class
= bp_silent
;
3298 /* There was a catchpoint, but we're not stopping.
3299 This requires no further action. */
3300 bs_class
= no_effect
;
3302 case bp_catch_catch
:
3303 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
3304 bs_class
= bp_nostop
;
3306 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3308 case bp_catch_throw
:
3309 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3310 bs_class
= bp_nostop
;
3312 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3315 /* Make sure the action is stop (silent or noisy),
3316 so infrun.c pops the dummy frame. */
3317 bs_class
= bp_silent
;
3318 retval
.call_dummy
= 1;
3321 current_action
= table
[(int) bs_class
][(int) current_action
];
3323 retval
.main_action
= current_action
;
3327 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3328 without hardware support). This isn't related to a specific bpstat,
3329 just to things like whether watchpoints are set. */
3332 bpstat_should_step (void)
3334 struct breakpoint
*b
;
3336 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3341 /* Nonzero if there are enabled hardware watchpoints. */
3343 bpstat_have_active_hw_watchpoints (void)
3345 const struct bp_location
*bpt
;
3346 ALL_BP_LOCATIONS (bpt
)
3347 if (breakpoint_enabled (bpt
->owner
)
3349 && bpt
->loc_type
== bp_loc_hardware_watchpoint
)
3355 /* Given a bpstat that records zero or more triggered eventpoints, this
3356 function returns another bpstat which contains only the catchpoints
3357 on that first list, if any. */
3359 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3361 struct bpstats root_bs
[1];
3362 bpstat bs
= root_bs
;
3363 struct breakpoint
*ep
;
3366 bpstat_clear (cp_list
);
3367 root_bs
->next
= NULL
;
3369 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3371 /* Is this eventpoint a catchpoint? If not, ignore it. */
3372 ep
= ep_list
->breakpoint_at
->owner
;
3375 if ((ep
->type
!= bp_catch_load
) &&
3376 (ep
->type
!= bp_catch_unload
) &&
3377 (ep
->type
!= bp_catch_catch
) &&
3378 (ep
->type
!= bp_catch_throw
))
3379 /* pai: (temp) ADD fork/vfork here!! */
3382 /* Yes; add it to the list. */
3383 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3388 #if defined(SOLIB_ADD)
3389 /* Also, for each triggered catchpoint, tag it with the name of
3390 the library that caused this trigger. (We copy the name now,
3391 because it's only guaranteed to be available NOW, when the
3392 catchpoint triggers. Clients who may wish to know the name
3393 later must get it from the catchpoint itself.) */
3394 if (ep
->triggered_dll_pathname
!= NULL
)
3395 xfree (ep
->triggered_dll_pathname
);
3396 if (ep
->type
== bp_catch_load
)
3397 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3398 PIDGET (inferior_ptid
));
3400 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3401 PIDGET (inferior_ptid
));
3403 dll_pathname
= NULL
;
3407 ep
->triggered_dll_pathname
= (char *)
3408 xmalloc (strlen (dll_pathname
) + 1);
3409 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3412 ep
->triggered_dll_pathname
= NULL
;
3418 static void print_breakpoint_location (struct breakpoint
*b
,
3419 struct bp_location
*loc
,
3421 struct ui_stream
*stb
)
3426 = find_pc_sect_function (loc
->address
, loc
->section
);
3429 ui_out_text (uiout
, "in ");
3430 ui_out_field_string (uiout
, "func",
3431 SYMBOL_PRINT_NAME (sym
));
3432 ui_out_wrap_hint (uiout
, wrap_indent
);
3433 ui_out_text (uiout
, " at ");
3435 ui_out_field_string (uiout
, "file", b
->source_file
);
3436 ui_out_text (uiout
, ":");
3438 if (ui_out_is_mi_like_p (uiout
))
3440 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3441 char *fullname
= symtab_to_fullname (sal
.symtab
);
3444 ui_out_field_string (uiout
, "fullname", fullname
);
3447 ui_out_field_int (uiout
, "line", b
->line_number
);
3451 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3455 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3456 ui_out_field_stream (uiout
, "at", stb
);
3460 /* Print B to gdb_stdout. */
3462 print_one_breakpoint_location (struct breakpoint
*b
,
3463 struct bp_location
*loc
,
3465 CORE_ADDR
*last_addr
)
3467 struct command_line
*l
;
3469 struct ep_type_description
3474 static struct ep_type_description bptypes
[] =
3476 {bp_none
, "?deleted?"},
3477 {bp_breakpoint
, "breakpoint"},
3478 {bp_hardware_breakpoint
, "hw breakpoint"},
3479 {bp_until
, "until"},
3480 {bp_finish
, "finish"},
3481 {bp_watchpoint
, "watchpoint"},
3482 {bp_hardware_watchpoint
, "hw watchpoint"},
3483 {bp_read_watchpoint
, "read watchpoint"},
3484 {bp_access_watchpoint
, "acc watchpoint"},
3485 {bp_longjmp
, "longjmp"},
3486 {bp_longjmp_resume
, "longjmp resume"},
3487 {bp_step_resume
, "step resume"},
3488 {bp_watchpoint_scope
, "watchpoint scope"},
3489 {bp_call_dummy
, "call dummy"},
3490 {bp_shlib_event
, "shlib events"},
3491 {bp_thread_event
, "thread events"},
3492 {bp_overlay_event
, "overlay events"},
3493 {bp_catch_load
, "catch load"},
3494 {bp_catch_unload
, "catch unload"},
3495 {bp_catch_fork
, "catch fork"},
3496 {bp_catch_vfork
, "catch vfork"},
3497 {bp_catch_exec
, "catch exec"},
3498 {bp_catch_catch
, "catch catch"},
3499 {bp_catch_throw
, "catch throw"}
3502 static char *bpdisps
[] =
3503 {"del", "dstp", "dis", "keep"};
3504 static char bpenables
[] = "nynny";
3505 char wrap_indent
[80];
3506 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3507 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3508 struct cleanup
*bkpt_chain
;
3510 int header_of_multiple
= 0;
3511 int part_of_multiple
= (loc
!= NULL
);
3513 gdb_assert (!loc
|| loc_number
!= 0);
3514 /* See comment in print_one_breakpoint concerning
3515 treatment of breakpoints with single disabled
3519 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3520 header_of_multiple
= 1;
3525 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3529 if (part_of_multiple
)
3532 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3533 ui_out_field_string (uiout
, "number", formatted
);
3538 ui_out_field_int (uiout
, "number", b
->number
);
3543 if (part_of_multiple
)
3544 ui_out_field_skip (uiout
, "type");
3547 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3548 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3549 internal_error (__FILE__
, __LINE__
,
3550 _("bptypes table does not describe type #%d."),
3552 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3557 if (part_of_multiple
)
3558 ui_out_field_skip (uiout
, "disp");
3560 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3565 if (part_of_multiple
)
3566 ui_out_field_string (uiout
, "enabled",
3568 ? (loc
->enabled
? "y(p)" : "n(p)")
3569 : (loc
->enabled
? "y" : "n"));
3572 int pending
= (b
->loc
== NULL
|| b
->loc
->shlib_disabled
);
3573 /* For header of multiple, there's no point showing pending
3574 state -- it will be apparent from the locations. */
3575 if (header_of_multiple
)
3577 ui_out_field_fmt (uiout
, "enabled", "%c%s",
3578 bpenables
[(int) b
->enable_state
],
3579 pending
? "(p)" : "");
3581 ui_out_spaces (uiout
, 3);
3586 strcpy (wrap_indent
, " ");
3589 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3590 strcat (wrap_indent
, " ");
3592 strcat (wrap_indent
, " ");
3595 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3597 /* Although the print_one can possibly print
3598 all locations, calling it here is not likely
3599 to get any nice result. So, make sure there's
3600 just one location. */
3601 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3602 b
->ops
->print_one (b
, last_addr
);
3608 internal_error (__FILE__
, __LINE__
,
3609 _("print_one_breakpoint: bp_none encountered\n"));
3613 case bp_hardware_watchpoint
:
3614 case bp_read_watchpoint
:
3615 case bp_access_watchpoint
:
3616 /* Field 4, the address, is omitted (which makes the columns
3617 not line up too nicely with the headers, but the effect
3618 is relatively readable). */
3620 ui_out_field_skip (uiout
, "addr");
3622 print_expression (b
->exp
, stb
->stream
);
3623 ui_out_field_stream (uiout
, "what", stb
);
3627 case bp_catch_unload
:
3628 /* Field 4, the address, is omitted (which makes the columns
3629 not line up too nicely with the headers, but the effect
3630 is relatively readable). */
3632 ui_out_field_skip (uiout
, "addr");
3634 if (b
->dll_pathname
== NULL
)
3636 ui_out_field_string (uiout
, "what", "<any library>");
3637 ui_out_spaces (uiout
, 1);
3641 ui_out_text (uiout
, "library \"");
3642 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3643 ui_out_text (uiout
, "\" ");
3648 case bp_catch_vfork
:
3649 /* Field 4, the address, is omitted (which makes the columns
3650 not line up too nicely with the headers, but the effect
3651 is relatively readable). */
3653 ui_out_field_skip (uiout
, "addr");
3655 if (b
->forked_inferior_pid
!= 0)
3657 ui_out_text (uiout
, "process ");
3658 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3659 ui_out_spaces (uiout
, 1);
3664 /* Field 4, the address, is omitted (which makes the columns
3665 not line up too nicely with the headers, but the effect
3666 is relatively readable). */
3668 ui_out_field_skip (uiout
, "addr");
3670 if (b
->exec_pathname
!= NULL
)
3672 ui_out_text (uiout
, "program \"");
3673 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3674 ui_out_text (uiout
, "\" ");
3678 case bp_catch_catch
:
3679 /* Field 4, the address, is omitted (which makes the columns
3680 not line up too nicely with the headers, but the effect
3681 is relatively readable). */
3683 ui_out_field_skip (uiout
, "addr");
3685 ui_out_field_string (uiout
, "what", "exception catch");
3686 ui_out_spaces (uiout
, 1);
3689 case bp_catch_throw
:
3690 /* Field 4, the address, is omitted (which makes the columns
3691 not line up too nicely with the headers, but the effect
3692 is relatively readable). */
3694 ui_out_field_skip (uiout
, "addr");
3696 ui_out_field_string (uiout
, "what", "exception throw");
3697 ui_out_spaces (uiout
, 1);
3701 case bp_hardware_breakpoint
:
3705 case bp_longjmp_resume
:
3706 case bp_step_resume
:
3707 case bp_watchpoint_scope
:
3709 case bp_shlib_event
:
3710 case bp_thread_event
:
3711 case bp_overlay_event
:
3716 ui_out_field_string (uiout
, "addr", "<PENDING>");
3717 else if (header_of_multiple
)
3718 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3720 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3723 if (!header_of_multiple
)
3724 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3726 *last_addr
= b
->loc
->address
;
3730 if (!part_of_multiple
&& b
->thread
!= -1)
3732 /* FIXME: This seems to be redundant and lost here; see the
3733 "stop only in" line a little further down. */
3734 ui_out_text (uiout
, " thread ");
3735 ui_out_field_int (uiout
, "thread", b
->thread
);
3738 ui_out_text (uiout
, "\n");
3740 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3743 ui_out_text (uiout
, "\tstop only in stack frame at ");
3744 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3746 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3747 ui_out_text (uiout
, "\n");
3750 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3752 /* We do not print the condition for Ada exception catchpoints
3753 because the condition is an internal implementation detail
3754 that we do not want to expose to the user. */
3756 ui_out_text (uiout
, "\tstop only if ");
3757 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3758 ui_out_text (uiout
, "\n");
3761 if (!part_of_multiple
&& b
->thread
!= -1)
3763 /* FIXME should make an annotation for this */
3764 ui_out_text (uiout
, "\tstop only in thread ");
3765 ui_out_field_int (uiout
, "thread", b
->thread
);
3766 ui_out_text (uiout
, "\n");
3769 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3771 /* FIXME should make an annotation for this */
3772 if (ep_is_catchpoint (b
))
3773 ui_out_text (uiout
, "\tcatchpoint");
3775 ui_out_text (uiout
, "\tbreakpoint");
3776 ui_out_text (uiout
, " already hit ");
3777 ui_out_field_int (uiout
, "times", b
->hit_count
);
3778 if (b
->hit_count
== 1)
3779 ui_out_text (uiout
, " time\n");
3781 ui_out_text (uiout
, " times\n");
3784 /* Output the count also if it is zero, but only if this is
3785 mi. FIXME: Should have a better test for this. */
3786 if (ui_out_is_mi_like_p (uiout
))
3787 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3788 ui_out_field_int (uiout
, "times", b
->hit_count
);
3790 if (!part_of_multiple
&& b
->ignore_count
)
3793 ui_out_text (uiout
, "\tignore next ");
3794 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3795 ui_out_text (uiout
, " hits\n");
3798 if (!part_of_multiple
&& (l
= b
->commands
))
3800 struct cleanup
*script_chain
;
3803 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3804 print_command_lines (uiout
, l
, 4);
3805 do_cleanups (script_chain
);
3807 do_cleanups (bkpt_chain
);
3808 do_cleanups (old_chain
);
3812 print_one_breakpoint (struct breakpoint
*b
,
3813 CORE_ADDR
*last_addr
)
3815 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3817 /* If this breakpoint has custom print function,
3818 it's already printed. Otherwise, print individual
3819 locations, if any. */
3820 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3822 /* If breakpoint has a single location that is
3823 disabled, we print it as if it had
3824 several locations, since otherwise it's hard to
3825 represent "breakpoint enabled, location disabled"
3828 && (b
->loc
->next
|| !b
->loc
->enabled
)
3829 && !ui_out_is_mi_like_p (uiout
))
3831 struct bp_location
*loc
;
3833 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3834 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3840 struct captured_breakpoint_query_args
3846 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3848 struct captured_breakpoint_query_args
*args
= data
;
3849 struct breakpoint
*b
;
3850 CORE_ADDR dummy_addr
= 0;
3853 if (args
->bnum
== b
->number
)
3855 print_one_breakpoint (b
, &dummy_addr
);
3863 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3865 struct captured_breakpoint_query_args args
;
3867 /* For the moment we don't trust print_one_breakpoint() to not throw
3869 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3870 error_message
, RETURN_MASK_ALL
) < 0)
3876 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3877 catchpoints, et.al.). */
3880 user_settable_breakpoint (const struct breakpoint
*b
)
3882 return (b
->type
== bp_breakpoint
3883 || b
->type
== bp_catch_load
3884 || b
->type
== bp_catch_unload
3885 || b
->type
== bp_catch_fork
3886 || b
->type
== bp_catch_vfork
3887 || b
->type
== bp_catch_exec
3888 || b
->type
== bp_catch_catch
3889 || b
->type
== bp_catch_throw
3890 || b
->type
== bp_hardware_breakpoint
3891 || b
->type
== bp_watchpoint
3892 || b
->type
== bp_read_watchpoint
3893 || b
->type
== bp_access_watchpoint
3894 || b
->type
== bp_hardware_watchpoint
);
3897 /* Print information on user settable breakpoint (watchpoint, etc)
3898 number BNUM. If BNUM is -1 print all user settable breakpoints.
3899 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3902 breakpoint_1 (int bnum
, int allflag
)
3904 struct breakpoint
*b
;
3905 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3906 int nr_printable_breakpoints
;
3907 struct cleanup
*bkpttbl_chain
;
3909 /* Compute the number of rows in the table. */
3910 nr_printable_breakpoints
= 0;
3913 || bnum
== b
->number
)
3915 if (allflag
|| user_settable_breakpoint (b
))
3916 nr_printable_breakpoints
++;
3921 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3925 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3928 if (nr_printable_breakpoints
> 0)
3929 annotate_breakpoints_headers ();
3930 if (nr_printable_breakpoints
> 0)
3932 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3933 if (nr_printable_breakpoints
> 0)
3935 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3936 if (nr_printable_breakpoints
> 0)
3938 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3939 if (nr_printable_breakpoints
> 0)
3941 ui_out_table_header (uiout
, 4, ui_left
, "enabled", "Enb"); /* 4 */
3944 if (nr_printable_breakpoints
> 0)
3946 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3947 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3949 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3951 if (nr_printable_breakpoints
> 0)
3953 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3954 ui_out_table_body (uiout
);
3955 if (nr_printable_breakpoints
> 0)
3956 annotate_breakpoints_table ();
3960 || bnum
== b
->number
)
3962 /* We only print out user settable breakpoints unless the
3964 if (allflag
|| user_settable_breakpoint (b
))
3965 print_one_breakpoint (b
, &last_addr
);
3968 do_cleanups (bkpttbl_chain
);
3970 if (nr_printable_breakpoints
== 0)
3973 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3975 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3980 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3981 that a comparison of an unsigned with -1 is always false. */
3982 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3983 set_next_address (last_addr
);
3986 /* FIXME? Should this be moved up so that it is only called when
3987 there have been breakpoints? */
3988 annotate_breakpoints_table_end ();
3992 breakpoints_info (char *bnum_exp
, int from_tty
)
3997 bnum
= parse_and_eval_long (bnum_exp
);
3999 breakpoint_1 (bnum
, 0);
4003 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4008 bnum
= parse_and_eval_long (bnum_exp
);
4010 breakpoint_1 (bnum
, 1);
4014 breakpoint_has_pc (struct breakpoint
*b
, CORE_ADDR pc
, asection
*section
)
4016 struct bp_location
*bl
= b
->loc
;
4017 for (; bl
; bl
= bl
->next
)
4019 if (bl
->address
== pc
4020 && (!overlay_debugging
|| bl
->section
== section
))
4026 /* Print a message describing any breakpoints set at PC. */
4029 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
4032 struct breakpoint
*b
;
4035 others
+= breakpoint_has_pc (b
, pc
, section
);
4039 printf_filtered (_("Note: breakpoint "));
4040 else /* if (others == ???) */
4041 printf_filtered (_("Note: breakpoints "));
4043 if (breakpoint_has_pc (b
, pc
, section
))
4046 printf_filtered ("%d", b
->number
);
4047 if (b
->thread
== -1 && thread
!= -1)
4048 printf_filtered (" (all threads)");
4049 else if (b
->thread
!= -1)
4050 printf_filtered (" (thread %d)", b
->thread
);
4051 printf_filtered ("%s%s ",
4052 ((b
->enable_state
== bp_disabled
||
4053 b
->enable_state
== bp_call_disabled
)
4055 : b
->enable_state
== bp_permanent
4059 : ((others
== 1) ? " and" : ""));
4061 printf_filtered (_("also set at pc "));
4062 deprecated_print_address_numeric (pc
, 1, gdb_stdout
);
4063 printf_filtered (".\n");
4067 /* Set the default place to put a breakpoint
4068 for the `break' command with no arguments. */
4071 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4074 default_breakpoint_valid
= valid
;
4075 default_breakpoint_address
= addr
;
4076 default_breakpoint_symtab
= symtab
;
4077 default_breakpoint_line
= line
;
4080 /* Return true iff it is meaningful to use the address member of
4081 BPT. For some breakpoint types, the address member is irrelevant
4082 and it makes no sense to attempt to compare it to other addresses
4083 (or use it for any other purpose either).
4085 More specifically, each of the following breakpoint types will always
4086 have a zero valued address and we don't want check_duplicates() to mark
4087 breakpoints of any of these types to be a duplicate of an actual
4088 breakpoint at address zero:
4091 bp_hardware_watchpoint
4093 bp_access_watchpoint
4100 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4102 enum bptype type
= bpt
->type
;
4104 return (type
!= bp_watchpoint
4105 && type
!= bp_hardware_watchpoint
4106 && type
!= bp_read_watchpoint
4107 && type
!= bp_access_watchpoint
4108 && type
!= bp_catch_exec
4109 && type
!= bp_longjmp_resume
4110 && type
!= bp_catch_fork
4111 && type
!= bp_catch_vfork
);
4114 /* Rescan breakpoints at the same address and section as BPT,
4115 marking the first one as "first" and any others as "duplicates".
4116 This is so that the bpt instruction is only inserted once.
4117 If we have a permanent breakpoint at the same place as BPT, make
4118 that one the official one, and the rest as duplicates. */
4121 check_duplicates_for (CORE_ADDR address
, asection
*section
)
4123 struct bp_location
*b
;
4125 struct bp_location
*perm_bp
= 0;
4127 ALL_BP_LOCATIONS (b
)
4128 if (b
->owner
->enable_state
!= bp_disabled
4129 && b
->owner
->enable_state
!= bp_call_disabled
4131 && !b
->shlib_disabled
4132 && b
->address
== address
/* address / overlay match */
4133 && (!overlay_debugging
|| b
->section
== section
)
4134 && breakpoint_address_is_meaningful (b
->owner
))
4136 /* Have we found a permanent breakpoint? */
4137 if (b
->owner
->enable_state
== bp_permanent
)
4144 b
->duplicate
= count
> 1;
4147 /* If we found a permanent breakpoint at this address, go over the
4148 list again and declare all the other breakpoints there to be the
4152 perm_bp
->duplicate
= 0;
4154 /* Permanent breakpoint should always be inserted. */
4155 if (! perm_bp
->inserted
)
4156 internal_error (__FILE__
, __LINE__
,
4157 _("allegedly permanent breakpoint is not "
4158 "actually inserted"));
4160 ALL_BP_LOCATIONS (b
)
4163 if (b
->owner
->enable_state
!= bp_disabled
4164 && b
->owner
->enable_state
!= bp_call_disabled
4165 && b
->enabled
&& !b
->shlib_disabled
4166 && b
->address
== address
/* address / overlay match */
4167 && (!overlay_debugging
|| b
->section
== section
)
4168 && breakpoint_address_is_meaningful (b
->owner
))
4171 internal_error (__FILE__
, __LINE__
,
4172 _("another breakpoint was inserted on top of "
4173 "a permanent breakpoint"));
4182 check_duplicates (struct breakpoint
*bpt
)
4184 struct bp_location
*bl
= bpt
->loc
;
4186 if (! breakpoint_address_is_meaningful (bpt
))
4189 for (; bl
; bl
= bl
->next
)
4190 check_duplicates_for (bl
->address
, bl
->section
);
4194 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4195 int bnum
, int have_bnum
)
4200 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4201 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4203 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4204 bnum
, astr1
, astr2
);
4206 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4209 /* Adjust a breakpoint's address to account for architectural constraints
4210 on breakpoint placement. Return the adjusted address. Note: Very
4211 few targets require this kind of adjustment. For most targets,
4212 this function is simply the identity function. */
4215 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4217 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4219 /* Very few targets need any kind of breakpoint adjustment. */
4222 else if (bptype
== bp_watchpoint
4223 || bptype
== bp_hardware_watchpoint
4224 || bptype
== bp_read_watchpoint
4225 || bptype
== bp_access_watchpoint
4226 || bptype
== bp_catch_fork
4227 || bptype
== bp_catch_vfork
4228 || bptype
== bp_catch_exec
)
4230 /* Watchpoints and the various bp_catch_* eventpoints should not
4231 have their addresses modified. */
4236 CORE_ADDR adjusted_bpaddr
;
4238 /* Some targets have architectural constraints on the placement
4239 of breakpoint instructions. Obtain the adjusted address. */
4240 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4243 /* An adjusted breakpoint address can significantly alter
4244 a user's expectations. Print a warning if an adjustment
4246 if (adjusted_bpaddr
!= bpaddr
)
4247 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4249 return adjusted_bpaddr
;
4253 /* Allocate a struct bp_location. */
4255 static struct bp_location
*
4256 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4258 struct bp_location
*loc
, *loc_p
;
4260 loc
= xmalloc (sizeof (struct bp_location
));
4261 memset (loc
, 0, sizeof (*loc
));
4265 loc
->shlib_disabled
= 0;
4274 case bp_longjmp_resume
:
4275 case bp_step_resume
:
4276 case bp_watchpoint_scope
:
4278 case bp_shlib_event
:
4279 case bp_thread_event
:
4280 case bp_overlay_event
:
4282 case bp_catch_unload
:
4283 loc
->loc_type
= bp_loc_software_breakpoint
;
4285 case bp_hardware_breakpoint
:
4286 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4288 case bp_hardware_watchpoint
:
4289 case bp_read_watchpoint
:
4290 case bp_access_watchpoint
:
4291 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4295 case bp_catch_vfork
:
4297 case bp_catch_catch
:
4298 case bp_catch_throw
:
4299 loc
->loc_type
= bp_loc_other
;
4302 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4305 /* Add this breakpoint to the end of the chain. */
4307 loc_p
= bp_location_chain
;
4309 bp_location_chain
= loc
;
4312 while (loc_p
->global_next
)
4313 loc_p
= loc_p
->global_next
;
4314 loc_p
->global_next
= loc
;
4320 static void free_bp_location (struct bp_location
*loc
)
4327 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4328 that has type BPTYPE and has no locations as yet. */
4330 static struct breakpoint
*
4331 set_raw_breakpoint_without_location (enum bptype bptype
)
4333 struct breakpoint
*b
, *b1
;
4335 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4336 memset (b
, 0, sizeof (*b
));
4339 b
->language
= current_language
->la_language
;
4340 b
->input_radix
= input_radix
;
4342 b
->enable_state
= bp_enabled
;
4345 b
->ignore_count
= 0;
4347 b
->frame_id
= null_frame_id
;
4348 b
->dll_pathname
= NULL
;
4349 b
->triggered_dll_pathname
= NULL
;
4350 b
->forked_inferior_pid
= 0;
4351 b
->exec_pathname
= NULL
;
4353 b
->condition_not_parsed
= 0;
4355 /* Add this breakpoint to the end of the chain
4356 so that a list of breakpoints will come out in order
4357 of increasing numbers. */
4359 b1
= breakpoint_chain
;
4361 breakpoint_chain
= b
;
4371 /* Initialize loc->function_name. */
4373 set_breakpoint_location_function (struct bp_location
*loc
)
4375 if (loc
->owner
->type
== bp_breakpoint
4376 || loc
->owner
->type
== bp_hardware_breakpoint
)
4378 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4380 if (loc
->function_name
)
4381 loc
->function_name
= xstrdup (loc
->function_name
);
4385 /* set_raw_breakpoint is a low level routine for allocating and
4386 partially initializing a breakpoint of type BPTYPE. The newly
4387 created breakpoint's address, section, source file name, and line
4388 number are provided by SAL. The newly created and partially
4389 initialized breakpoint is added to the breakpoint chain and
4390 is also returned as the value of this function.
4392 It is expected that the caller will complete the initialization of
4393 the newly created breakpoint struct as well as output any status
4394 information regarding the creation of a new breakpoint. In
4395 particular, set_raw_breakpoint does NOT set the breakpoint
4396 number! Care should be taken to not allow an error to occur
4397 prior to completing the initialization of the breakpoint. If this
4398 should happen, a bogus breakpoint will be left on the chain. */
4401 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4403 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4404 CORE_ADDR adjusted_address
;
4406 /* Adjust the breakpoint's address prior to allocating a location.
4407 Once we call allocate_bp_location(), that mostly uninitialized
4408 location will be placed on the location chain. Adjustment of the
4409 breakpoint may cause read_memory_nobpt() to be called and we do
4410 not want its scan of the location chain to find a breakpoint and
4411 location that's only been partially initialized. */
4412 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4414 b
->loc
= allocate_bp_location (b
, bptype
);
4415 b
->loc
->requested_address
= sal
.pc
;
4416 b
->loc
->address
= adjusted_address
;
4418 if (sal
.symtab
== NULL
)
4419 b
->source_file
= NULL
;
4421 b
->source_file
= savestring (sal
.symtab
->filename
,
4422 strlen (sal
.symtab
->filename
));
4423 b
->loc
->section
= sal
.section
;
4424 b
->line_number
= sal
.line
;
4426 set_breakpoint_location_function (b
->loc
);
4428 check_duplicates (b
);
4429 breakpoints_changed ();
4435 /* Note that the breakpoint object B describes a permanent breakpoint
4436 instruction, hard-wired into the inferior's code. */
4438 make_breakpoint_permanent (struct breakpoint
*b
)
4440 struct bp_location
*bl
;
4441 b
->enable_state
= bp_permanent
;
4443 /* By definition, permanent breakpoints are already present in the code.
4444 Mark all locations as inserted. For now, make_breakpoint_permanent
4445 is called in just one place, so it's hard to say if it's reasonable
4446 to have permanent breakpoint with multiple locations or not,
4447 but it's easy to implmement. */
4448 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4452 static struct breakpoint
*
4453 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4455 static int internal_breakpoint_number
= -1;
4456 struct symtab_and_line sal
;
4457 struct breakpoint
*b
;
4459 init_sal (&sal
); /* initialize to zeroes */
4462 sal
.section
= find_pc_overlay (sal
.pc
);
4464 b
= set_raw_breakpoint (sal
, type
);
4465 b
->number
= internal_breakpoint_number
--;
4466 b
->disposition
= disp_donttouch
;
4473 create_longjmp_breakpoint (char *func_name
)
4475 struct breakpoint
*b
;
4476 struct minimal_symbol
*m
;
4478 if (func_name
== NULL
)
4479 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4482 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4485 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4488 b
->enable_state
= bp_disabled
;
4491 b
->addr_string
= xstrdup (func_name
);
4494 /* Call this routine when stepping and nexting to enable a breakpoint
4495 if we do a longjmp(). When we hit that breakpoint, call
4496 set_longjmp_resume_breakpoint() to figure out where we are going. */
4499 enable_longjmp_breakpoint (void)
4501 struct breakpoint
*b
;
4504 if (b
->type
== bp_longjmp
)
4506 b
->enable_state
= bp_enabled
;
4507 check_duplicates (b
);
4512 disable_longjmp_breakpoint (void)
4514 struct breakpoint
*b
;
4517 if (b
->type
== bp_longjmp
4518 || b
->type
== bp_longjmp_resume
)
4520 b
->enable_state
= bp_disabled
;
4521 check_duplicates (b
);
4526 create_overlay_event_breakpoint (char *func_name
)
4528 struct breakpoint
*b
;
4529 struct minimal_symbol
*m
;
4531 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4534 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4536 b
->addr_string
= xstrdup (func_name
);
4538 if (overlay_debugging
== ovly_auto
)
4540 b
->enable_state
= bp_enabled
;
4541 overlay_events_enabled
= 1;
4545 b
->enable_state
= bp_disabled
;
4546 overlay_events_enabled
= 0;
4551 enable_overlay_breakpoints (void)
4553 struct breakpoint
*b
;
4556 if (b
->type
== bp_overlay_event
)
4558 b
->enable_state
= bp_enabled
;
4559 check_duplicates (b
);
4560 overlay_events_enabled
= 1;
4565 disable_overlay_breakpoints (void)
4567 struct breakpoint
*b
;
4570 if (b
->type
== bp_overlay_event
)
4572 b
->enable_state
= bp_disabled
;
4573 check_duplicates (b
);
4574 overlay_events_enabled
= 0;
4579 create_thread_event_breakpoint (CORE_ADDR address
)
4581 struct breakpoint
*b
;
4583 b
= create_internal_breakpoint (address
, bp_thread_event
);
4585 b
->enable_state
= bp_enabled
;
4586 /* addr_string has to be used or breakpoint_re_set will delete me. */
4587 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4593 remove_thread_event_breakpoints (void)
4595 struct breakpoint
*b
, *temp
;
4597 ALL_BREAKPOINTS_SAFE (b
, temp
)
4598 if (b
->type
== bp_thread_event
)
4599 delete_breakpoint (b
);
4602 struct captured_parse_breakpoint_args
4605 struct symtabs_and_lines
*sals_p
;
4606 char ***addr_string_p
;
4610 struct lang_and_radix
4618 remove_solib_event_breakpoints (void)
4620 struct breakpoint
*b
, *temp
;
4622 ALL_BREAKPOINTS_SAFE (b
, temp
)
4623 if (b
->type
== bp_shlib_event
)
4624 delete_breakpoint (b
);
4628 create_solib_event_breakpoint (CORE_ADDR address
)
4630 struct breakpoint
*b
;
4632 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4636 /* Disable any breakpoints that are on code in shared libraries. Only
4637 apply to enabled breakpoints, disabled ones can just stay disabled. */
4640 disable_breakpoints_in_shlibs (void)
4642 struct bp_location
*loc
;
4643 int disabled_shlib_breaks
= 0;
4645 ALL_BP_LOCATIONS (loc
)
4647 struct breakpoint
*b
= loc
->owner
;
4648 /* We apply the check to all breakpoints, including disabled
4649 for those with loc->duplicate set. This is so that when breakpoint
4650 becomes enabled, or the duplicate is removed, gdb will try to insert
4651 all breakpoints. If we don't set shlib_disabled here, we'll try
4652 to insert those breakpoints and fail. */
4653 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4654 && !loc
->shlib_disabled
4656 && PC_SOLIB (loc
->address
)
4658 && solib_address (loc
->address
)
4662 loc
->shlib_disabled
= 1;
4667 /* Disable any breakpoints that are in in an unloaded shared library. Only
4668 apply to enabled breakpoints, disabled ones can just stay disabled. */
4671 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4673 struct bp_location
*loc
;
4674 int disabled_shlib_breaks
= 0;
4676 ALL_BP_LOCATIONS (loc
)
4678 struct breakpoint
*b
= loc
->owner
;
4679 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4680 || loc
->loc_type
== bp_loc_software_breakpoint
)
4681 && !loc
->shlib_disabled
)
4684 char *so_name
= PC_SOLIB (loc
->address
);
4686 char *so_name
= solib_address (loc
->address
);
4688 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4690 loc
->shlib_disabled
= 1;
4691 /* At this point, we cannot rely on remove_breakpoint
4692 succeeding so we must mark the breakpoint as not inserted
4693 to prevent future errors occurring in remove_breakpoints. */
4695 if (!disabled_shlib_breaks
)
4697 target_terminal_ours_for_output ();
4698 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4701 disabled_shlib_breaks
= 1;
4708 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4709 enum bptype bp_kind
)
4711 struct symtab_and_line sal
;
4712 struct breakpoint
*b
;
4713 int thread
= -1; /* All threads. */
4720 b
= set_raw_breakpoint (sal
, bp_kind
);
4721 set_breakpoint_count (breakpoint_count
+ 1);
4722 b
->number
= breakpoint_count
;
4723 b
->cond_string
= (cond_string
== NULL
) ?
4724 NULL
: savestring (cond_string
, strlen (cond_string
));
4726 b
->addr_string
= NULL
;
4727 b
->enable_state
= bp_enabled
;
4728 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4729 b
->forked_inferior_pid
= 0;
4735 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4737 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4741 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4743 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4747 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4749 struct symtab_and_line sal
;
4750 struct breakpoint
*b
;
4751 int thread
= -1; /* All threads. */
4758 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4759 set_breakpoint_count (breakpoint_count
+ 1);
4760 b
->number
= breakpoint_count
;
4761 b
->cond_string
= (cond_string
== NULL
) ?
4762 NULL
: savestring (cond_string
, strlen (cond_string
));
4764 b
->addr_string
= NULL
;
4765 b
->enable_state
= bp_enabled
;
4766 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4772 hw_breakpoint_used_count (void)
4774 struct breakpoint
*b
;
4779 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4787 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4789 struct breakpoint
*b
;
4792 *other_type_used
= 0;
4795 if (breakpoint_enabled (b
))
4797 if (b
->type
== type
)
4799 else if ((b
->type
== bp_hardware_watchpoint
||
4800 b
->type
== bp_read_watchpoint
||
4801 b
->type
== bp_access_watchpoint
))
4802 *other_type_used
= 1;
4808 /* Call this after hitting the longjmp() breakpoint. Use this to set
4809 a new breakpoint at the target of the jmp_buf.
4811 FIXME - This ought to be done by setting a temporary breakpoint
4812 that gets deleted automatically... */
4815 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4817 struct breakpoint
*b
;
4820 if (b
->type
== bp_longjmp_resume
)
4822 b
->loc
->requested_address
= pc
;
4823 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4825 b
->enable_state
= bp_enabled
;
4826 b
->frame_id
= frame_id
;
4827 check_duplicates (b
);
4833 disable_watchpoints_before_interactive_call_start (void)
4835 struct breakpoint
*b
;
4839 if (((b
->type
== bp_watchpoint
)
4840 || (b
->type
== bp_hardware_watchpoint
)
4841 || (b
->type
== bp_read_watchpoint
)
4842 || (b
->type
== bp_access_watchpoint
)
4843 || ep_is_exception_catchpoint (b
))
4844 && breakpoint_enabled (b
))
4846 b
->enable_state
= bp_call_disabled
;
4847 check_duplicates (b
);
4853 enable_watchpoints_after_interactive_call_stop (void)
4855 struct breakpoint
*b
;
4859 if (((b
->type
== bp_watchpoint
)
4860 || (b
->type
== bp_hardware_watchpoint
)
4861 || (b
->type
== bp_read_watchpoint
)
4862 || (b
->type
== bp_access_watchpoint
)
4863 || ep_is_exception_catchpoint (b
))
4864 && (b
->enable_state
== bp_call_disabled
))
4866 b
->enable_state
= bp_enabled
;
4867 check_duplicates (b
);
4873 /* Set a breakpoint that will evaporate an end of command
4874 at address specified by SAL.
4875 Restrict it to frame FRAME if FRAME is nonzero. */
4878 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4881 struct breakpoint
*b
;
4882 b
= set_raw_breakpoint (sal
, type
);
4883 b
->enable_state
= bp_enabled
;
4884 b
->disposition
= disp_donttouch
;
4885 b
->frame_id
= frame_id
;
4887 /* If we're debugging a multi-threaded program, then we
4888 want momentary breakpoints to be active in only a
4889 single thread of control. */
4890 if (in_thread_list (inferior_ptid
))
4891 b
->thread
= pid_to_thread_id (inferior_ptid
);
4897 /* Tell the user we have just set a breakpoint B. */
4900 mention (struct breakpoint
*b
)
4903 struct cleanup
*old_chain
, *ui_out_chain
;
4904 struct ui_stream
*stb
;
4906 stb
= ui_out_stream_new (uiout
);
4907 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4909 /* FIXME: This is misplaced; mention() is called by things (like
4910 hitting a watchpoint) other than breakpoint creation. It should
4911 be possible to clean this up and at the same time replace the
4912 random calls to breakpoint_changed with this hook, as has already
4913 been done for deprecated_delete_breakpoint_hook and so on. */
4914 if (deprecated_create_breakpoint_hook
)
4915 deprecated_create_breakpoint_hook (b
);
4916 breakpoint_create_event (b
->number
);
4918 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4919 b
->ops
->print_mention (b
);
4924 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4927 ui_out_text (uiout
, "Watchpoint ");
4928 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4929 ui_out_field_int (uiout
, "number", b
->number
);
4930 ui_out_text (uiout
, ": ");
4931 print_expression (b
->exp
, stb
->stream
);
4932 ui_out_field_stream (uiout
, "exp", stb
);
4933 do_cleanups (ui_out_chain
);
4935 case bp_hardware_watchpoint
:
4936 ui_out_text (uiout
, "Hardware watchpoint ");
4937 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4938 ui_out_field_int (uiout
, "number", b
->number
);
4939 ui_out_text (uiout
, ": ");
4940 print_expression (b
->exp
, stb
->stream
);
4941 ui_out_field_stream (uiout
, "exp", stb
);
4942 do_cleanups (ui_out_chain
);
4944 case bp_read_watchpoint
:
4945 ui_out_text (uiout
, "Hardware read watchpoint ");
4946 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4947 ui_out_field_int (uiout
, "number", b
->number
);
4948 ui_out_text (uiout
, ": ");
4949 print_expression (b
->exp
, stb
->stream
);
4950 ui_out_field_stream (uiout
, "exp", stb
);
4951 do_cleanups (ui_out_chain
);
4953 case bp_access_watchpoint
:
4954 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4955 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4956 ui_out_field_int (uiout
, "number", b
->number
);
4957 ui_out_text (uiout
, ": ");
4958 print_expression (b
->exp
, stb
->stream
);
4959 ui_out_field_stream (uiout
, "exp", stb
);
4960 do_cleanups (ui_out_chain
);
4963 if (ui_out_is_mi_like_p (uiout
))
4968 printf_filtered (_("Breakpoint %d"), b
->number
);
4971 case bp_hardware_breakpoint
:
4972 if (ui_out_is_mi_like_p (uiout
))
4977 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4981 case bp_catch_unload
:
4982 printf_filtered (_("Catchpoint %d (%s %s)"),
4984 (b
->type
== bp_catch_load
) ? "load" : "unload",
4985 (b
->dll_pathname
!= NULL
) ?
4986 b
->dll_pathname
: "<any library>");
4989 case bp_catch_vfork
:
4990 printf_filtered (_("Catchpoint %d (%s)"),
4992 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4995 printf_filtered (_("Catchpoint %d (exec)"),
4998 case bp_catch_catch
:
4999 case bp_catch_throw
:
5000 printf_filtered (_("Catchpoint %d (%s)"),
5002 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
5008 case bp_longjmp_resume
:
5009 case bp_step_resume
:
5011 case bp_watchpoint_scope
:
5012 case bp_shlib_event
:
5013 case bp_thread_event
:
5014 case bp_overlay_event
:
5020 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5024 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5028 if (addressprint
|| b
->source_file
== NULL
)
5030 printf_filtered (" at ");
5031 deprecated_print_address_numeric (b
->loc
->address
, 1, gdb_stdout
);
5034 printf_filtered (": file %s, line %d.",
5035 b
->source_file
, b
->line_number
);
5039 struct bp_location
*loc
= b
->loc
;
5041 for (; loc
; loc
= loc
->next
)
5043 printf_filtered (" (%d locations)", n
);
5048 do_cleanups (old_chain
);
5049 if (ui_out_is_mi_like_p (uiout
))
5051 printf_filtered ("\n");
5055 static struct bp_location
*
5056 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5057 const struct symtab_and_line
*sal
)
5059 struct bp_location
*loc
, **tmp
;
5061 loc
= allocate_bp_location (b
, bptype
);
5062 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5065 loc
->requested_address
= sal
->pc
;
5066 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5068 loc
->section
= sal
->section
;
5070 set_breakpoint_location_function (loc
);
5074 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5075 as textual description of the location, and COND_STRING
5076 as condition expression. */
5079 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5081 enum bptype type
, enum bpdisp disposition
,
5082 int thread
, int ignore_count
, int from_tty
)
5084 struct breakpoint
*b
= NULL
;
5087 if (type
== bp_hardware_breakpoint
)
5089 int i
= hw_breakpoint_used_count ();
5090 int target_resources_ok
=
5091 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5093 if (target_resources_ok
== 0)
5094 error (_("No hardware breakpoint support in the target."));
5095 else if (target_resources_ok
< 0)
5096 error (_("Hardware breakpoints used exceeds limit."));
5099 for (i
= 0; i
< sals
.nelts
; ++i
)
5101 struct symtab_and_line sal
= sals
.sals
[i
];
5102 struct bp_location
*loc
;
5105 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5109 b
= set_raw_breakpoint (sal
, type
);
5110 set_breakpoint_count (breakpoint_count
+ 1);
5111 b
->number
= breakpoint_count
;
5114 b
->cond_string
= cond_string
;
5115 b
->ignore_count
= ignore_count
;
5116 b
->enable_state
= bp_enabled
;
5117 b
->disposition
= disposition
;
5123 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5128 char *arg
= b
->cond_string
;
5129 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5131 error (_("Garbage %s follows condition"), arg
);
5136 b
->addr_string
= addr_string
;
5138 /* addr_string has to be used or breakpoint_re_set will delete
5140 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5145 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5146 elements to fill the void space. */
5147 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5149 int i
= index_to_remove
+1;
5150 int last_index
= sal
->nelts
-1;
5152 for (;i
<= last_index
; ++i
)
5153 sal
->sals
[i
-1] = sal
->sals
[i
];
5158 /* If appropriate, obtains all sals that correspond
5159 to the same file and line as SAL. This is done
5160 only if SAL does not have explicit PC and has
5161 line and file information. If we got just a single
5162 expanded sal, return the original.
5164 Otherwise, if SAL.explicit_line is not set, filter out
5165 all sals for which the name of enclosing function
5166 is different from SAL. This makes sure that if we have
5167 breakpoint originally set in template instantiation, say
5168 foo<int>(), we won't expand SAL to locations at the same
5169 line in all existing instantiations of 'foo'.
5172 struct symtabs_and_lines
5173 expand_line_sal_maybe (struct symtab_and_line sal
)
5175 struct symtabs_and_lines expanded
;
5176 CORE_ADDR original_pc
= sal
.pc
;
5177 char *original_function
= NULL
;
5181 /* If we have explicit pc, don't expand.
5182 If we have no line number, we can't expand. */
5183 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5186 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5187 expanded
.sals
[0] = sal
;
5192 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5194 expanded
= expand_line_sal (sal
);
5195 if (expanded
.nelts
== 1)
5197 /* We had one sal, we got one sal. Without futher
5198 processing, just return the original sal. */
5199 xfree (expanded
.sals
);
5201 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5202 sal
.pc
= original_pc
;
5203 expanded
.sals
[0] = sal
;
5207 if (!sal
.explicit_line
)
5209 CORE_ADDR func_addr
, func_end
;
5210 for (i
= 0; i
< expanded
.nelts
; ++i
)
5212 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5213 char *this_function
;
5214 if (find_pc_partial_function (pc
, &this_function
,
5215 &func_addr
, &func_end
))
5217 if (this_function
&&
5218 strcmp (this_function
, original_function
) != 0)
5220 remove_sal (&expanded
, i
);
5223 else if (func_addr
== pc
)
5225 /* We're at beginning of a function, and should
5227 struct symbol
*sym
= find_pc_function (pc
);
5229 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5232 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5239 if (expanded
.nelts
<= 1)
5241 /* This is un ugly workaround. If we get zero
5242 expanded sals then something is really wrong.
5243 Fix that by returnign the original sal. */
5244 xfree (expanded
.sals
);
5246 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5247 sal
.pc
= original_pc
;
5248 expanded
.sals
[0] = sal
;
5255 for (i
= 0; i
< expanded
.nelts
; ++i
)
5256 if (expanded
.sals
[i
].pc
== original_pc
)
5267 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5268 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5269 value. COND_STRING, if not NULL, specified the condition to be
5270 used for all breakpoints. Essentially the only case where
5271 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5272 function. In that case, it's still not possible to specify
5273 separate conditions for different overloaded functions, so
5274 we take just a single condition string.
5276 NOTE: If the function succeeds, the caller is expected to cleanup
5277 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5278 array contents). If the function fails (error() is called), the
5279 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5280 COND and SALS arrays and each of those arrays contents. */
5283 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5285 enum bptype type
, enum bpdisp disposition
,
5286 int thread
, int ignore_count
, int from_tty
)
5289 for (i
= 0; i
< sals
.nelts
; ++i
)
5291 struct symtabs_and_lines expanded
=
5292 expand_line_sal_maybe (sals
.sals
[i
]);
5294 create_breakpoint (expanded
, addr_string
[i
],
5295 cond_string
, type
, disposition
,
5296 thread
, ignore_count
, from_tty
);
5300 /* Parse ARG which is assumed to be a SAL specification possibly
5301 followed by conditionals. On return, SALS contains an array of SAL
5302 addresses found. ADDR_STRING contains a vector of (canonical)
5303 address strings. ARG points to the end of the SAL. */
5306 parse_breakpoint_sals (char **address
,
5307 struct symtabs_and_lines
*sals
,
5308 char ***addr_string
,
5311 char *addr_start
= *address
;
5312 *addr_string
= NULL
;
5313 /* If no arg given, or if first arg is 'if ', use the default
5315 if ((*address
) == NULL
5316 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5318 if (default_breakpoint_valid
)
5320 struct symtab_and_line sal
;
5321 init_sal (&sal
); /* initialize to zeroes */
5322 sals
->sals
= (struct symtab_and_line
*)
5323 xmalloc (sizeof (struct symtab_and_line
));
5324 sal
.pc
= default_breakpoint_address
;
5325 sal
.line
= default_breakpoint_line
;
5326 sal
.symtab
= default_breakpoint_symtab
;
5327 sal
.section
= find_pc_overlay (sal
.pc
);
5328 sals
->sals
[0] = sal
;
5332 error (_("No default breakpoint address now."));
5336 /* Force almost all breakpoints to be in terms of the
5337 current_source_symtab (which is decode_line_1's default). This
5338 should produce the results we want almost all of the time while
5339 leaving default_breakpoint_* alone.
5340 ObjC: However, don't match an Objective-C method name which
5341 may have a '+' or '-' succeeded by a '[' */
5343 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5345 if (default_breakpoint_valid
5347 || ((strchr ("+-", (*address
)[0]) != NULL
)
5348 && ((*address
)[1] != '['))))
5349 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5350 default_breakpoint_line
, addr_string
,
5353 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5354 addr_string
, not_found_ptr
);
5356 /* For any SAL that didn't have a canonical string, fill one in. */
5357 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5358 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5359 if (addr_start
!= (*address
))
5362 for (i
= 0; i
< sals
->nelts
; i
++)
5364 /* Add the string if not present. */
5365 if ((*addr_string
)[i
] == NULL
)
5366 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5372 /* Convert each SAL into a real PC. Verify that the PC can be
5373 inserted as a breakpoint. If it can't throw an error. */
5376 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5380 for (i
= 0; i
< sals
->nelts
; i
++)
5381 resolve_sal_pc (&sals
->sals
[i
]);
5385 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5387 struct captured_parse_breakpoint_args
*args
= data
;
5389 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5390 args
->not_found_ptr
);
5393 /* Given TOK, a string specification of condition and thread, as
5394 accepted by the 'break' command, extract the condition
5395 string and thread number and set *COND_STRING and *THREAD.
5396 PC identifies the context at which the condition should be parsed.
5397 If no condition is found, *COND_STRING is set to NULL.
5398 If no thread is found, *THREAD is set to -1. */
5400 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5401 char **cond_string
, int *thread
)
5403 *cond_string
= NULL
;
5409 char *cond_start
= NULL
;
5410 char *cond_end
= NULL
;
5411 while (*tok
== ' ' || *tok
== '\t')
5416 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5419 toklen
= end_tok
- tok
;
5421 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5423 tok
= cond_start
= end_tok
+ 1;
5424 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5426 *cond_string
= savestring (cond_start
,
5427 cond_end
- cond_start
);
5429 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5435 *thread
= strtol (tok
, &tok
, 0);
5437 error (_("Junk after thread keyword."));
5438 if (!valid_thread_id (*thread
))
5439 error (_("Unknown thread %d."), *thread
);
5442 error (_("Junk at end of arguments."));
5446 /* Set a breakpoint according to ARG (function, linenum or *address)
5447 flag: first bit : 0 non-temporary, 1 temporary.
5448 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
5451 break_command_1 (char *arg
, int flag
, int from_tty
)
5453 struct gdb_exception e
;
5454 int tempflag
, hardwareflag
;
5455 struct symtabs_and_lines sals
;
5456 struct symtab_and_line pending_sal
;
5457 char *cond_string
= NULL
;
5460 char *addr_start
= arg
;
5462 struct cleanup
*old_chain
;
5463 struct cleanup
*breakpoint_chain
= NULL
;
5464 struct captured_parse_breakpoint_args parse_args
;
5468 int ignore_count
= 0;
5471 hardwareflag
= flag
& BP_HARDWAREFLAG
;
5472 tempflag
= flag
& BP_TEMPFLAG
;
5478 parse_args
.arg_p
= &arg
;
5479 parse_args
.sals_p
= &sals
;
5480 parse_args
.addr_string_p
= &addr_string
;
5481 parse_args
.not_found_ptr
= ¬_found
;
5483 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5484 &parse_args
, RETURN_MASK_ALL
);
5486 /* If caller is interested in rc value from parse, set value. */
5490 exception_print (gdb_stderr
, e
);
5495 case NOT_FOUND_ERROR
:
5497 exception_print (gdb_stderr
, e
);
5499 /* If pending breakpoint support is turned off, throw
5502 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5503 deprecated_throw_reason (RETURN_ERROR
);
5505 /* If pending breakpoint support is auto query and the user
5506 selects no, then simply return the error code. */
5507 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5508 !nquery ("Make breakpoint pending on future shared library load? "))
5511 /* At this point, either the user was queried about setting
5512 a pending breakpoint and selected yes, or pending
5513 breakpoint behavior is on and thus a pending breakpoint
5514 is defaulted on behalf of the user. */
5515 copy_arg
= xstrdup (addr_start
);
5516 addr_string
= ©_arg
;
5518 sals
.sals
= &pending_sal
;
5523 exception_print (gdb_stderr
, e
);
5531 /* Create a chain of things that always need to be cleaned up. */
5532 old_chain
= make_cleanup (null_cleanup
, 0);
5536 /* Make sure that all storage allocated to SALS gets freed. */
5537 make_cleanup (xfree
, sals
.sals
);
5539 /* Cleanup the addr_string array but not its contents. */
5540 make_cleanup (xfree
, addr_string
);
5543 /* ----------------------------- SNIP -----------------------------
5544 Anything added to the cleanup chain beyond this point is assumed
5545 to be part of a breakpoint. If the breakpoint create succeeds
5546 then the memory is not reclaimed. */
5547 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5549 /* Mark the contents of the addr_string for cleanup. These go on
5550 the breakpoint_chain and only occure if the breakpoint create
5552 for (i
= 0; i
< sals
.nelts
; i
++)
5554 if (addr_string
[i
] != NULL
)
5555 make_cleanup (xfree
, addr_string
[i
]);
5558 /* Resolve all line numbers to PC's and verify that the addresses
5559 are ok for the target. */
5561 breakpoint_sals_to_pc (&sals
, addr_start
);
5563 /* Verify that condition can be parsed, before setting any
5564 breakpoints. Allocate a separate condition expression for each
5568 /* Here we only parse 'arg' to separate condition
5569 from thread number, so parsing in context of first
5570 sal is OK. When setting the breakpoint we'll
5571 re-parse it in context of each sal. */
5572 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5574 make_cleanup (xfree
, cond_string
);
5575 create_breakpoints (sals
, addr_string
, cond_string
,
5576 hardwareflag
? bp_hardware_breakpoint
5578 tempflag
? disp_del
: disp_donttouch
,
5579 thread
, ignore_count
, from_tty
);
5583 struct symtab_and_line sal
= {0};
5584 struct breakpoint
*b
;
5586 make_cleanup (xfree
, copy_arg
);
5588 b
= set_raw_breakpoint_without_location (hardwareflag
5589 ? bp_hardware_breakpoint
5591 set_breakpoint_count (breakpoint_count
+ 1);
5592 b
->number
= breakpoint_count
;
5594 b
->addr_string
= addr_string
[0];
5595 b
->cond_string
= cond_string
;
5596 b
->ignore_count
= ignore_count
;
5597 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5598 b
->condition_not_parsed
= 1;
5603 warning (_("Multiple breakpoints were set.\n"
5604 "Use the \"delete\" command to delete unwanted breakpoints."));
5605 /* That's it. Discard the cleanups for data inserted into the
5607 discard_cleanups (breakpoint_chain
);
5608 /* But cleanup everything else. */
5609 do_cleanups (old_chain
);
5614 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5615 linenum or *address) with COND and IGNORE_COUNT. */
5617 struct captured_breakpoint_args
5628 do_captured_breakpoint (struct ui_out
*uiout
, void *data
)
5630 struct captured_breakpoint_args
*args
= data
;
5631 struct symtabs_and_lines sals
;
5632 struct expression
**cond
;
5633 struct cleanup
*old_chain
;
5634 struct cleanup
*breakpoint_chain
= NULL
;
5637 char *cond_string
= 0;
5641 /* Parse the source and lines spec. Delay check that the expression
5642 didn't contain trailing garbage until after cleanups are in
5646 address_end
= args
->address
;
5648 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
, 0);
5653 /* Create a chain of things at always need to be cleaned up. */
5654 old_chain
= make_cleanup (null_cleanup
, 0);
5656 /* Always have a addr_string array, even if it is empty. */
5657 make_cleanup (xfree
, addr_string
);
5659 /* Make sure that all storage allocated to SALS gets freed. */
5660 make_cleanup (xfree
, sals
.sals
);
5662 /* Allocate space for all the cond expressions. */
5663 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5664 make_cleanup (xfree
, cond
);
5666 /* ----------------------------- SNIP -----------------------------
5667 Anything added to the cleanup chain beyond this point is assumed
5668 to be part of a breakpoint. If the breakpoint create goes
5669 through then that memory is not cleaned up. */
5670 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5672 /* Mark the contents of the addr_string for cleanup. These go on
5673 the breakpoint_chain and only occure if the breakpoint create
5675 for (i
= 0; i
< sals
.nelts
; i
++)
5677 if (addr_string
[i
] != NULL
)
5678 make_cleanup (xfree
, addr_string
[i
]);
5681 /* Wait until now before checking for garbage at the end of the
5682 address. That way cleanups can take care of freeing any
5684 if (*address_end
!= '\0')
5685 error (_("Garbage %s following breakpoint address"), address_end
);
5687 /* Resolve all line numbers to PC's. */
5688 breakpoint_sals_to_pc (&sals
, args
->address
);
5690 if (args
->condition
!= NULL
)
5692 cond_string
= xstrdup (args
->condition
);
5693 make_cleanup (xfree
, cond_string
);
5696 create_breakpoints (sals
, addr_string
, args
->condition
,
5697 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
5698 args
->tempflag
? disp_del
: disp_donttouch
,
5699 args
->thread
, args
->ignore_count
, 0/*from-tty*/);
5701 /* That's it. Discard the cleanups for data inserted into the
5703 discard_cleanups (breakpoint_chain
);
5704 /* But cleanup everything else. */
5705 do_cleanups (old_chain
);
5710 gdb_breakpoint (char *address
, char *condition
,
5711 int hardwareflag
, int tempflag
,
5712 int thread
, int ignore_count
,
5713 char **error_message
)
5715 struct captured_breakpoint_args args
;
5716 args
.address
= address
;
5717 args
.condition
= condition
;
5718 args
.hardwareflag
= hardwareflag
;
5719 args
.tempflag
= tempflag
;
5720 args
.thread
= thread
;
5721 args
.ignore_count
= ignore_count
;
5722 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint
, &args
,
5723 error_message
, RETURN_MASK_ALL
) < 0)
5730 /* Helper function for break_command_1 and disassemble_command. */
5733 resolve_sal_pc (struct symtab_and_line
*sal
)
5737 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5739 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5740 error (_("No line %d in file \"%s\"."),
5741 sal
->line
, sal
->symtab
->filename
);
5745 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5747 struct blockvector
*bv
;
5752 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5755 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5756 sym
= block_function (b
);
5759 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5760 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5764 /* It really is worthwhile to have the section, so we'll just
5765 have to look harder. This case can be executed if we have
5766 line numbers but no functions (as can happen in assembly
5769 struct minimal_symbol
*msym
;
5771 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5773 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5780 break_command (char *arg
, int from_tty
)
5782 break_command_1 (arg
, 0, from_tty
);
5786 tbreak_command (char *arg
, int from_tty
)
5788 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5792 hbreak_command (char *arg
, int from_tty
)
5794 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5798 thbreak_command (char *arg
, int from_tty
)
5800 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5804 stop_command (char *arg
, int from_tty
)
5806 printf_filtered (_("Specify the type of breakpoint to set.\n\
5807 Usage: stop in <function | address>\n\
5808 stop at <line>\n"));
5812 stopin_command (char *arg
, int from_tty
)
5816 if (arg
== (char *) NULL
)
5818 else if (*arg
!= '*')
5823 /* look for a ':'. If this is a line number specification, then
5824 say it is bad, otherwise, it should be an address or
5825 function/method name */
5826 while (*argptr
&& !hasColon
)
5828 hasColon
= (*argptr
== ':');
5833 badInput
= (*argptr
!= ':'); /* Not a class::method */
5835 badInput
= isdigit (*arg
); /* a simple line number */
5839 printf_filtered (_("Usage: stop in <function | address>\n"));
5841 break_command_1 (arg
, 0, from_tty
);
5845 stopat_command (char *arg
, int from_tty
)
5849 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5856 /* look for a ':'. If there is a '::' then get out, otherwise
5857 it is probably a line number. */
5858 while (*argptr
&& !hasColon
)
5860 hasColon
= (*argptr
== ':');
5865 badInput
= (*argptr
== ':'); /* we have class::method */
5867 badInput
= !isdigit (*arg
); /* not a line number */
5871 printf_filtered (_("Usage: stop at <line>\n"));
5873 break_command_1 (arg
, 0, from_tty
);
5876 /* accessflag: hw_write: watch write,
5877 hw_read: watch read,
5878 hw_access: watch access (read or write) */
5880 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5882 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5883 struct symtab_and_line sal
;
5884 struct expression
*exp
;
5885 struct block
*exp_valid_block
;
5886 struct value
*val
, *mark
;
5887 struct frame_info
*frame
;
5888 struct frame_info
*prev_frame
= NULL
;
5889 char *exp_start
= NULL
;
5890 char *exp_end
= NULL
;
5891 char *tok
, *end_tok
;
5893 char *cond_start
= NULL
;
5894 char *cond_end
= NULL
;
5895 struct expression
*cond
= NULL
;
5896 int i
, other_type_used
, target_resources_ok
= 0;
5897 enum bptype bp_type
;
5900 init_sal (&sal
); /* initialize to zeroes */
5902 /* Parse arguments. */
5903 innermost_block
= NULL
;
5905 exp
= parse_exp_1 (&arg
, 0, 0);
5907 exp_valid_block
= innermost_block
;
5908 mark
= value_mark ();
5909 val
= evaluate_expression (exp
);
5910 release_value (val
);
5911 if (value_lazy (val
))
5912 value_fetch_lazy (val
);
5915 while (*tok
== ' ' || *tok
== '\t')
5919 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5922 toklen
= end_tok
- tok
;
5923 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5925 tok
= cond_start
= end_tok
+ 1;
5926 cond
= parse_exp_1 (&tok
, 0, 0);
5930 error (_("Junk at end of command."));
5932 if (accessflag
== hw_read
)
5933 bp_type
= bp_read_watchpoint
;
5934 else if (accessflag
== hw_access
)
5935 bp_type
= bp_access_watchpoint
;
5937 bp_type
= bp_hardware_watchpoint
;
5939 mem_cnt
= can_use_hardware_watchpoint (val
);
5940 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5941 error (_("Expression cannot be implemented with read/access watchpoint."));
5944 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5945 target_resources_ok
=
5946 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5948 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5949 error (_("Target does not support this type of hardware watchpoint."));
5951 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5952 error (_("Target can only support one kind of HW watchpoint at a time."));
5955 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5956 watchpoint could not be set. */
5957 if (!mem_cnt
|| target_resources_ok
<= 0)
5958 bp_type
= bp_watchpoint
;
5960 frame
= block_innermost_frame (exp_valid_block
);
5962 prev_frame
= get_prev_frame (frame
);
5966 /* If the expression is "local", then set up a "watchpoint scope"
5967 breakpoint at the point where we've left the scope of the watchpoint
5968 expression. Create the scope breakpoint before the watchpoint, so
5969 that we will encounter it first in bpstat_stop_status. */
5970 if (innermost_block
&& prev_frame
)
5972 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5973 bp_watchpoint_scope
);
5975 scope_breakpoint
->enable_state
= bp_enabled
;
5977 /* Automatically delete the breakpoint when it hits. */
5978 scope_breakpoint
->disposition
= disp_del
;
5980 /* Only break in the proper frame (help with recursion). */
5981 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5983 /* Set the address at which we will stop. */
5984 scope_breakpoint
->loc
->requested_address
5985 = get_frame_pc (prev_frame
);
5986 scope_breakpoint
->loc
->address
5987 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5988 scope_breakpoint
->type
);
5991 /* Now set up the breakpoint. */
5992 b
= set_raw_breakpoint (sal
, bp_type
);
5993 set_breakpoint_count (breakpoint_count
+ 1);
5994 b
->number
= breakpoint_count
;
5995 b
->disposition
= disp_donttouch
;
5997 b
->exp_valid_block
= exp_valid_block
;
5998 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6000 b
->loc
->cond
= cond
;
6002 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6007 b
->watchpoint_frame
= get_frame_id (frame
);
6009 b
->watchpoint_frame
= null_frame_id
;
6011 if (scope_breakpoint
!= NULL
)
6013 /* The scope breakpoint is related to the watchpoint. We will
6014 need to act on them together. */
6015 b
->related_breakpoint
= scope_breakpoint
;
6016 scope_breakpoint
->related_breakpoint
= b
;
6019 value_free_to_mark (mark
);
6023 /* Return count of locations need to be watched and can be handled
6024 in hardware. If the watchpoint can not be handled
6025 in hardware return zero. */
6028 can_use_hardware_watchpoint (struct value
*v
)
6030 int found_memory_cnt
= 0;
6031 struct value
*head
= v
;
6033 /* Did the user specifically forbid us to use hardware watchpoints? */
6034 if (!can_use_hw_watchpoints
)
6037 /* Make sure that the value of the expression depends only upon
6038 memory contents, and values computed from them within GDB. If we
6039 find any register references or function calls, we can't use a
6040 hardware watchpoint.
6042 The idea here is that evaluating an expression generates a series
6043 of values, one holding the value of every subexpression. (The
6044 expression a*b+c has five subexpressions: a, b, a*b, c, and
6045 a*b+c.) GDB's values hold almost enough information to establish
6046 the criteria given above --- they identify memory lvalues,
6047 register lvalues, computed values, etcetera. So we can evaluate
6048 the expression, and then scan the chain of values that leaves
6049 behind to decide whether we can detect any possible change to the
6050 expression's final value using only hardware watchpoints.
6052 However, I don't think that the values returned by inferior
6053 function calls are special in any way. So this function may not
6054 notice that an expression involving an inferior function call
6055 can't be watched with hardware watchpoints. FIXME. */
6056 for (; v
; v
= value_next (v
))
6058 if (VALUE_LVAL (v
) == lval_memory
)
6061 /* A lazy memory lvalue is one that GDB never needed to fetch;
6062 we either just used its address (e.g., `a' in `a.b') or
6063 we never needed it at all (e.g., `a' in `a,b'). */
6067 /* Ahh, memory we actually used! Check if we can cover
6068 it with hardware watchpoints. */
6069 struct type
*vtype
= check_typedef (value_type (v
));
6071 /* We only watch structs and arrays if user asked for it
6072 explicitly, never if they just happen to appear in a
6073 middle of some value chain. */
6075 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6076 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6078 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6079 int len
= TYPE_LENGTH (value_type (v
));
6081 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6088 else if (VALUE_LVAL (v
) != not_lval
6089 && deprecated_value_modifiable (v
) == 0)
6090 return 0; /* ??? What does this represent? */
6091 else if (VALUE_LVAL (v
) == lval_register
)
6092 return 0; /* cannot watch a register with a HW watchpoint */
6095 /* The expression itself looks suitable for using a hardware
6096 watchpoint, but give the target machine a chance to reject it. */
6097 return found_memory_cnt
;
6101 watch_command_wrapper (char *arg
, int from_tty
)
6103 watch_command (arg
, from_tty
);
6107 watch_command (char *arg
, int from_tty
)
6109 watch_command_1 (arg
, hw_write
, from_tty
);
6113 rwatch_command_wrapper (char *arg
, int from_tty
)
6115 rwatch_command (arg
, from_tty
);
6119 rwatch_command (char *arg
, int from_tty
)
6121 watch_command_1 (arg
, hw_read
, from_tty
);
6125 awatch_command_wrapper (char *arg
, int from_tty
)
6127 awatch_command (arg
, from_tty
);
6131 awatch_command (char *arg
, int from_tty
)
6133 watch_command_1 (arg
, hw_access
, from_tty
);
6137 /* Helper routines for the until_command routine in infcmd.c. Here
6138 because it uses the mechanisms of breakpoints. */
6140 /* This function is called by fetch_inferior_event via the
6141 cmd_continuation pointer, to complete the until command. It takes
6142 care of cleaning up the temporary breakpoints set up by the until
6145 until_break_command_continuation (struct continuation_arg
*arg
)
6147 struct cleanup
*cleanups
;
6149 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
6150 do_exec_cleanups (cleanups
);
6154 until_break_command (char *arg
, int from_tty
, int anywhere
)
6156 struct symtabs_and_lines sals
;
6157 struct symtab_and_line sal
;
6158 struct frame_info
*frame
= get_selected_frame (NULL
);
6159 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6160 struct breakpoint
*breakpoint
;
6161 struct cleanup
*old_chain
;
6162 struct continuation_arg
*arg1
;
6165 clear_proceed_status ();
6167 /* Set a breakpoint where the user wants it and at return from
6170 if (default_breakpoint_valid
)
6171 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6172 default_breakpoint_line
, (char ***) NULL
, NULL
);
6174 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6175 0, (char ***) NULL
, NULL
);
6177 if (sals
.nelts
!= 1)
6178 error (_("Couldn't get information on specified line."));
6181 xfree (sals
.sals
); /* malloc'd, so freed */
6184 error (_("Junk at end of arguments."));
6186 resolve_sal_pc (&sal
);
6189 /* If the user told us to continue until a specified location,
6190 we don't specify a frame at which we need to stop. */
6191 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6193 /* Otherwise, specify the current frame, because we want to stop only
6194 at the very same frame. */
6195 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6198 if (!target_can_async_p ())
6199 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6201 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
6203 /* If we are running asynchronously, and the target supports async
6204 execution, we are not waiting for the target to stop, in the call
6205 tp proceed, below. This means that we cannot delete the
6206 brekpoints until the target has actually stopped. The only place
6207 where we get a chance to do that is in fetch_inferior_event, so
6208 we must set things up for that. */
6210 if (target_can_async_p ())
6212 /* In this case the arg for the continuation is just the point
6213 in the exec_cleanups chain from where to start doing
6214 cleanups, because all the continuation does is the cleanups in
6215 the exec_cleanup_chain. */
6217 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6219 arg1
->data
.pointer
= old_chain
;
6221 add_continuation (until_break_command_continuation
, arg1
);
6224 /* Keep within the current frame, or in frames called by the current
6228 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6229 sal
.pc
= get_frame_pc (prev_frame
);
6230 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6232 if (!target_can_async_p ())
6233 make_cleanup_delete_breakpoint (breakpoint
);
6235 make_exec_cleanup_delete_breakpoint (breakpoint
);
6238 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6239 /* Do the cleanups now, anly if we are not running asynchronously,
6240 of if we are, but the target is still synchronous. */
6241 if (!target_can_async_p ())
6242 do_cleanups (old_chain
);
6246 ep_skip_leading_whitespace (char **s
)
6248 if ((s
== NULL
) || (*s
== NULL
))
6250 while (isspace (**s
))
6254 /* This function examines a string, and attempts to find a token
6255 that might be an event name in the leading characters. If a
6256 possible match is found, a pointer to the last character of
6257 the token is returned. Else, NULL is returned. */
6260 ep_find_event_name_end (char *arg
)
6263 char *event_name_end
= NULL
;
6265 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6269 /* We break out of the loop when we find a token delimiter.
6270 Basically, we're looking for alphanumerics and underscores;
6271 anything else delimites the token. */
6274 if (!isalnum (*s
) && (*s
!= '_'))
6280 return event_name_end
;
6284 /* This function attempts to parse an optional "if <cond>" clause
6285 from the arg string. If one is not found, it returns NULL.
6287 Else, it returns a pointer to the condition string. (It does not
6288 attempt to evaluate the string against a particular block.) And,
6289 it updates arg to point to the first character following the parsed
6290 if clause in the arg string. */
6293 ep_parse_optional_if_clause (char **arg
)
6297 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6300 /* Skip the "if" keyword. */
6303 /* Skip any extra leading whitespace, and record the start of the
6304 condition string. */
6305 ep_skip_leading_whitespace (arg
);
6308 /* Assume that the condition occupies the remainder of the arg string. */
6309 (*arg
) += strlen (cond_string
);
6314 /* This function attempts to parse an optional filename from the arg
6315 string. If one is not found, it returns NULL.
6317 Else, it returns a pointer to the parsed filename. (This function
6318 makes no attempt to verify that a file of that name exists, or is
6319 accessible.) And, it updates arg to point to the first character
6320 following the parsed filename in the arg string.
6322 Note that clients needing to preserve the returned filename for
6323 future access should copy it to their own buffers. */
6325 ep_parse_optional_filename (char **arg
)
6327 static char filename
[1024];
6332 if ((*arg_p
== '\0') || isspace (*arg_p
))
6350 /* Commands to deal with catching events, such as signals, exceptions,
6351 process start/exit, etc. */
6355 catch_fork
, catch_vfork
6360 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6363 char *cond_string
= NULL
;
6365 ep_skip_leading_whitespace (&arg
);
6367 /* The allowed syntax is:
6369 catch [v]fork if <cond>
6371 First, check if there's an if clause. */
6372 cond_string
= ep_parse_optional_if_clause (&arg
);
6374 if ((*arg
!= '\0') && !isspace (*arg
))
6375 error (_("Junk at end of arguments."));
6377 /* If this target supports it, create a fork or vfork catchpoint
6378 and enable reporting of such events. */
6382 create_fork_event_catchpoint (tempflag
, cond_string
);
6385 create_vfork_event_catchpoint (tempflag
, cond_string
);
6388 error (_("unsupported or unknown fork kind; cannot catch it"));
6394 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6396 char *cond_string
= NULL
;
6398 ep_skip_leading_whitespace (&arg
);
6400 /* The allowed syntax is:
6402 catch exec if <cond>
6404 First, check if there's an if clause. */
6405 cond_string
= ep_parse_optional_if_clause (&arg
);
6407 if ((*arg
!= '\0') && !isspace (*arg
))
6408 error (_("Junk at end of arguments."));
6410 /* If this target supports it, create an exec catchpoint
6411 and enable reporting of such events. */
6412 create_exec_event_catchpoint (tempflag
, cond_string
);
6416 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6418 char *dll_pathname
= NULL
;
6419 char *cond_string
= NULL
;
6421 ep_skip_leading_whitespace (&arg
);
6423 /* The allowed syntax is:
6425 catch load if <cond>
6426 catch load <filename>
6427 catch load <filename> if <cond>
6429 The user is not allowed to specify the <filename> after an
6432 We'll ignore the pathological case of a file named "if".
6434 First, check if there's an if clause. If so, then there
6435 cannot be a filename. */
6436 cond_string
= ep_parse_optional_if_clause (&arg
);
6438 /* If there was an if clause, then there cannot be a filename.
6439 Else, there might be a filename and an if clause. */
6440 if (cond_string
== NULL
)
6442 dll_pathname
= ep_parse_optional_filename (&arg
);
6443 ep_skip_leading_whitespace (&arg
);
6444 cond_string
= ep_parse_optional_if_clause (&arg
);
6447 if ((*arg
!= '\0') && !isspace (*arg
))
6448 error (_("Junk at end of arguments."));
6450 /* Create a load breakpoint that only triggers when a load of
6451 the specified dll (or any dll, if no pathname was specified)
6453 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6454 dll_pathname
, cond_string
);
6458 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6460 char *dll_pathname
= NULL
;
6461 char *cond_string
= NULL
;
6463 ep_skip_leading_whitespace (&arg
);
6465 /* The allowed syntax is:
6467 catch unload if <cond>
6468 catch unload <filename>
6469 catch unload <filename> if <cond>
6471 The user is not allowed to specify the <filename> after an
6474 We'll ignore the pathological case of a file named "if".
6476 First, check if there's an if clause. If so, then there
6477 cannot be a filename. */
6478 cond_string
= ep_parse_optional_if_clause (&arg
);
6480 /* If there was an if clause, then there cannot be a filename.
6481 Else, there might be a filename and an if clause. */
6482 if (cond_string
== NULL
)
6484 dll_pathname
= ep_parse_optional_filename (&arg
);
6485 ep_skip_leading_whitespace (&arg
);
6486 cond_string
= ep_parse_optional_if_clause (&arg
);
6489 if ((*arg
!= '\0') && !isspace (*arg
))
6490 error (_("Junk at end of arguments."));
6492 /* Create an unload breakpoint that only triggers when an unload of
6493 the specified dll (or any dll, if no pathname was specified)
6495 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6496 dll_pathname
, cond_string
);
6499 /* Commands to deal with catching exceptions. */
6501 /* Set a breakpoint at the specified callback routine for an
6502 exception event callback */
6505 create_exception_catchpoint (int tempflag
, char *cond_string
,
6506 enum exception_event_kind ex_event
,
6507 struct symtab_and_line
*sal
)
6509 struct breakpoint
*b
;
6510 int thread
= -1; /* All threads. */
6513 if (!sal
) /* no exception support? */
6518 case EX_EVENT_THROW
:
6519 bptype
= bp_catch_throw
;
6521 case EX_EVENT_CATCH
:
6522 bptype
= bp_catch_catch
;
6524 default: /* error condition */
6525 error (_("Internal error -- invalid catchpoint kind"));
6528 b
= set_raw_breakpoint (*sal
, bptype
);
6529 set_breakpoint_count (breakpoint_count
+ 1);
6530 b
->number
= breakpoint_count
;
6531 b
->cond_string
= (cond_string
== NULL
) ?
6532 NULL
: savestring (cond_string
, strlen (cond_string
));
6534 b
->addr_string
= NULL
;
6535 b
->enable_state
= bp_enabled
;
6536 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6540 static enum print_stop_action
6541 print_exception_catchpoint (struct breakpoint
*b
)
6543 annotate_catchpoint (b
->number
);
6545 if (strstr (b
->addr_string
, "throw") != NULL
)
6546 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6549 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6552 return PRINT_SRC_AND_LOC
;
6556 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6561 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6564 *last_addr
= b
->loc
->address
;
6565 if (strstr (b
->addr_string
, "throw") != NULL
)
6566 ui_out_field_string (uiout
, "what", "exception throw");
6568 ui_out_field_string (uiout
, "what", "exception catch");
6572 print_mention_exception_catchpoint (struct breakpoint
*b
)
6574 if (strstr (b
->addr_string
, "throw") != NULL
)
6575 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6577 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6580 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6581 print_exception_catchpoint
,
6582 print_one_exception_catchpoint
,
6583 print_mention_exception_catchpoint
6587 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6588 enum exception_event_kind ex_event
, int from_tty
)
6590 char *trigger_func_name
, *nameptr
;
6591 struct symtabs_and_lines sals
;
6592 struct breakpoint
*b
;
6594 if (ex_event
== EX_EVENT_CATCH
)
6595 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6597 trigger_func_name
= xstrdup ("__cxa_throw");
6599 nameptr
= trigger_func_name
;
6600 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6601 if (sals
.nelts
== 0)
6603 xfree (trigger_func_name
);
6607 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6608 set_breakpoint_count (breakpoint_count
+ 1);
6609 b
->number
= breakpoint_count
;
6610 b
->cond_string
= (cond_string
== NULL
) ?
6611 NULL
: savestring (cond_string
, strlen (cond_string
));
6613 b
->addr_string
= trigger_func_name
;
6614 b
->enable_state
= bp_enabled
;
6615 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6616 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6623 /* Deal with "catch catch" and "catch throw" commands */
6626 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6627 int tempflag
, int from_tty
)
6629 char *cond_string
= NULL
;
6630 struct symtab_and_line
*sal
= NULL
;
6632 ep_skip_leading_whitespace (&arg
);
6634 cond_string
= ep_parse_optional_if_clause (&arg
);
6636 if ((*arg
!= '\0') && !isspace (*arg
))
6637 error (_("Junk at end of arguments."));
6639 if ((ex_event
!= EX_EVENT_THROW
) &&
6640 (ex_event
!= EX_EVENT_CATCH
))
6641 error (_("Unsupported or unknown exception event; cannot catch it"));
6643 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6646 /* See if we can find a callback routine */
6647 sal
= target_enable_exception_callback (ex_event
, 1);
6651 /* We have callbacks from the runtime system for exceptions.
6652 Set a breakpoint on the sal found, if no errors */
6653 if (sal
!= (struct symtab_and_line
*) -1)
6654 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6656 return; /* something went wrong with setting up callbacks */
6659 warning (_("Unsupported with this platform/compiler combination."));
6662 /* Create a breakpoint struct for Ada exception catchpoints. */
6665 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6669 struct expression
*cond
,
6670 struct breakpoint_ops
*ops
,
6674 struct breakpoint
*b
;
6678 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6679 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6680 version for exception catchpoints, because two catchpoints
6681 used for different exception names will use the same address.
6682 In this case, a "breakpoint ... also set at..." warning is
6683 unproductive. Besides. the warning phrasing is also a bit
6684 inapropriate, we should use the word catchpoint, and tell
6685 the user what type of catchpoint it is. The above is good
6686 enough for now, though. */
6689 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6690 set_breakpoint_count (breakpoint_count
+ 1);
6692 b
->enable_state
= bp_enabled
;
6693 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6694 b
->number
= breakpoint_count
;
6695 b
->ignore_count
= 0;
6696 b
->loc
->cond
= cond
;
6697 b
->addr_string
= addr_string
;
6698 b
->language
= language_ada
;
6699 b
->cond_string
= cond_string
;
6700 b
->exp_string
= exp_string
;
6707 /* Implement the "catch exception" command. */
6710 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6712 struct symtab_and_line sal
;
6714 char *addr_string
= NULL
;
6715 char *exp_string
= NULL
;
6716 char *cond_string
= NULL
;
6717 struct expression
*cond
= NULL
;
6718 struct breakpoint_ops
*ops
= NULL
;
6720 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6721 &cond_string
, &cond
, &ops
);
6722 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6723 cond_string
, cond
, ops
, tempflag
,
6727 /* Implement the "catch assert" command. */
6730 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6732 struct symtab_and_line sal
;
6733 char *addr_string
= NULL
;
6734 struct breakpoint_ops
*ops
= NULL
;
6736 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6737 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6738 tempflag
, from_tty
);
6741 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6742 inside a catch_errors */
6745 cover_target_enable_exception_callback (void *arg
)
6747 args_for_catchpoint_enable
*args
= arg
;
6748 struct symtab_and_line
*sal
;
6749 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6752 else if (sal
== (struct symtab_and_line
*) -1)
6755 return 1; /*is valid */
6759 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6762 /* The first argument may be an event name, such as "start" or "load".
6763 If so, then handle it as such. If it doesn't match an event name,
6764 then attempt to interpret it as an exception name. (This latter is
6765 the v4.16-and-earlier GDB meaning of the "catch" command.)
6767 First, try to find the bounds of what might be an event name. */
6768 char *arg1_start
= arg
;
6772 if (arg1_start
== NULL
)
6774 /* Old behaviour was to use pre-v-4.16 syntax */
6775 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6777 /* Now, this is not allowed */
6778 error (_("Catch requires an event name."));
6781 arg1_end
= ep_find_event_name_end (arg1_start
);
6782 if (arg1_end
== NULL
)
6783 error (_("catch requires an event"));
6784 arg1_length
= arg1_end
+ 1 - arg1_start
;
6786 /* Try to match what we found against known event names. */
6787 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6789 error (_("Catch of signal not yet implemented"));
6791 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6793 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6794 tempflag
, from_tty
);
6796 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6798 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6799 tempflag
, from_tty
);
6801 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6803 error (_("Catch of thread_start not yet implemented"));
6805 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6807 error (_("Catch of thread_exit not yet implemented"));
6809 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6811 error (_("Catch of thread_join not yet implemented"));
6813 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6815 error (_("Catch of start not yet implemented"));
6817 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6819 error (_("Catch of exit not yet implemented"));
6821 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6823 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6825 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6827 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6829 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6831 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6833 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6835 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6837 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6839 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6841 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6843 error (_("Catch of stop not yet implemented"));
6845 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6847 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6850 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6852 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6855 /* This doesn't appear to be an event name */
6859 /* Pre-v.4.16 behaviour was to treat the argument
6860 as the name of an exception */
6861 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6862 /* Now this is not allowed */
6863 error (_("Unknown event kind specified for catch"));
6869 catch_command (char *arg
, int from_tty
)
6871 catch_command_1 (arg
, 0, from_tty
);
6876 tcatch_command (char *arg
, int from_tty
)
6878 catch_command_1 (arg
, 1, from_tty
);
6881 /* Delete breakpoints by address or line. */
6884 clear_command (char *arg
, int from_tty
)
6886 struct breakpoint
*b
;
6887 VEC(breakpoint_p
) *found
= 0;
6890 struct symtabs_and_lines sals
;
6891 struct symtab_and_line sal
;
6896 sals
= decode_line_spec (arg
, 1);
6901 sals
.sals
= (struct symtab_and_line
*)
6902 xmalloc (sizeof (struct symtab_and_line
));
6903 make_cleanup (xfree
, sals
.sals
);
6904 init_sal (&sal
); /* initialize to zeroes */
6905 sal
.line
= default_breakpoint_line
;
6906 sal
.symtab
= default_breakpoint_symtab
;
6907 sal
.pc
= default_breakpoint_address
;
6908 if (sal
.symtab
== 0)
6909 error (_("No source file specified."));
6917 /* We don't call resolve_sal_pc here. That's not
6918 as bad as it seems, because all existing breakpoints
6919 typically have both file/line and pc set. So, if
6920 clear is given file/line, we can match this to existing
6921 breakpoint without obtaining pc at all.
6923 We only support clearing given the address explicitly
6924 present in breakpoint table. Say, we've set breakpoint
6925 at file:line. There were several PC values for that file:line,
6926 due to optimization, all in one block.
6927 We've picked one PC value. If "clear" is issued with another
6928 PC corresponding to the same file:line, the breakpoint won't
6929 be cleared. We probably can still clear the breakpoint, but
6930 since the other PC value is never presented to user, user
6931 can only find it by guessing, and it does not seem important
6934 /* For each line spec given, delete bps which correspond
6935 to it. Do it in two passes, solely to preserve the current
6936 behavior that from_tty is forced true if we delete more than
6940 for (i
= 0; i
< sals
.nelts
; i
++)
6942 /* If exact pc given, clear bpts at that pc.
6943 If line given (pc == 0), clear all bpts on specified line.
6944 If defaulting, clear all bpts on default line
6947 defaulting sal.pc != 0 tests to do
6952 1 0 <can't happen> */
6956 /* Find all matching breakpoints and add them to
6961 /* Are we going to delete b? */
6962 if (b
->type
!= bp_none
6963 && b
->type
!= bp_watchpoint
6964 && b
->type
!= bp_hardware_watchpoint
6965 && b
->type
!= bp_read_watchpoint
6966 && b
->type
!= bp_access_watchpoint
)
6968 struct bp_location
*loc
= b
->loc
;
6969 for (; loc
; loc
= loc
->next
)
6971 int pc_match
= sal
.pc
6972 && (loc
->address
== sal
.pc
)
6973 && (!section_is_overlay (loc
->section
)
6974 || loc
->section
== sal
.section
);
6975 int line_match
= ((default_match
|| (0 == sal
.pc
))
6976 && b
->source_file
!= NULL
6977 && sal
.symtab
!= NULL
6978 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6979 && b
->line_number
== sal
.line
);
6980 if (pc_match
|| line_match
)
6989 VEC_safe_push(breakpoint_p
, found
, b
);
6992 /* Now go thru the 'found' chain and delete them. */
6993 if (VEC_empty(breakpoint_p
, found
))
6996 error (_("No breakpoint at %s."), arg
);
6998 error (_("No breakpoint at this line."));
7001 if (VEC_length(breakpoint_p
, found
) > 1)
7002 from_tty
= 1; /* Always report if deleted more than one */
7005 if (VEC_length(breakpoint_p
, found
) == 1)
7006 printf_unfiltered (_("Deleted breakpoint "));
7008 printf_unfiltered (_("Deleted breakpoints "));
7010 breakpoints_changed ();
7012 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
7015 printf_unfiltered ("%d ", b
->number
);
7016 delete_breakpoint (b
);
7019 putchar_unfiltered ('\n');
7022 /* Delete breakpoint in BS if they are `delete' breakpoints and
7023 all breakpoints that are marked for deletion, whether hit or not.
7024 This is called after any breakpoint is hit, or after errors. */
7027 breakpoint_auto_delete (bpstat bs
)
7029 struct breakpoint
*b
, *temp
;
7031 for (; bs
; bs
= bs
->next
)
7032 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
->disposition
== disp_del
7034 delete_breakpoint (bs
->breakpoint_at
->owner
);
7036 ALL_BREAKPOINTS_SAFE (b
, temp
)
7038 if (b
->disposition
== disp_del_at_next_stop
)
7039 delete_breakpoint (b
);
7043 /* Remove locations of breakpoint BPT from
7044 the global list of breakpoint locations. */
7047 unlink_locations_from_global_list (struct breakpoint
*bpt
)
7049 /* This code assumes that the locations
7050 of a breakpoint are found in the global list
7051 in the same order, but not necessary adjacent. */
7052 struct bp_location
**tmp
= &bp_location_chain
;
7053 struct bp_location
*here
= bpt
->loc
;
7058 for (; *tmp
&& here
;)
7062 *tmp
= here
->global_next
;
7067 tmp
= &((*tmp
)->global_next
);
7072 /* Delete a breakpoint and clean up all traces of it in the data
7076 delete_breakpoint (struct breakpoint
*bpt
)
7078 struct breakpoint
*b
;
7080 struct bp_location
*loc
;
7082 gdb_assert (bpt
!= NULL
);
7084 /* Has this bp already been deleted? This can happen because multiple
7085 lists can hold pointers to bp's. bpstat lists are especial culprits.
7087 One example of this happening is a watchpoint's scope bp. When the
7088 scope bp triggers, we notice that the watchpoint is out of scope, and
7089 delete it. We also delete its scope bp. But the scope bp is marked
7090 "auto-deleting", and is already on a bpstat. That bpstat is then
7091 checked for auto-deleting bp's, which are deleted.
7093 A real solution to this problem might involve reference counts in bp's,
7094 and/or giving them pointers back to their referencing bpstat's, and
7095 teaching delete_breakpoint to only free a bp's storage when no more
7096 references were extent. A cheaper bandaid was chosen. */
7097 if (bpt
->type
== bp_none
)
7100 if (deprecated_delete_breakpoint_hook
)
7101 deprecated_delete_breakpoint_hook (bpt
);
7102 breakpoint_delete_event (bpt
->number
);
7104 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
7107 remove_breakpoint (loc
, mark_inserted
);
7109 free_valchain (loc
);
7114 if (loc
->function_name
)
7115 xfree (loc
->function_name
);
7118 if (breakpoint_chain
== bpt
)
7119 breakpoint_chain
= bpt
->next
;
7121 /* If we have callback-style exception catchpoints, don't go through
7122 the adjustments to the C++ runtime library etc. if the inferior
7123 isn't actually running. target_enable_exception_callback for a
7124 null target ops vector gives an undesirable error message, so we
7125 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
7126 exceptions are supported in this way, it's OK for now. FIXME */
7127 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
7129 /* Format possible error msg */
7130 char *message
= xstrprintf ("Error in deleting catchpoint %d:\n",
7132 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7133 args_for_catchpoint_enable args
;
7134 args
.kind
= bpt
->type
== bp_catch_catch
?
7135 EX_EVENT_CATCH
: EX_EVENT_THROW
;
7137 catch_errors (cover_target_enable_exception_callback
, &args
,
7138 message
, RETURN_MASK_ALL
);
7139 do_cleanups (cleanups
);
7146 b
->next
= bpt
->next
;
7150 unlink_locations_from_global_list (bpt
);
7152 check_duplicates (bpt
);
7154 if (bpt
->type
!= bp_hardware_watchpoint
7155 && bpt
->type
!= bp_read_watchpoint
7156 && bpt
->type
!= bp_access_watchpoint
7157 && bpt
->type
!= bp_catch_fork
7158 && bpt
->type
!= bp_catch_vfork
7159 && bpt
->type
!= bp_catch_exec
)
7160 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
7162 /* If this breakpoint location was inserted, and there is
7163 another breakpoint at the same address, we need to
7164 insert the other breakpoint. */
7167 struct bp_location
*loc2
;
7168 ALL_BP_LOCATIONS (loc2
)
7169 if (loc2
->address
== loc
->address
7170 && loc2
->section
== loc
->section
7172 && loc2
->owner
->enable_state
!= bp_disabled
7174 && !loc2
->shlib_disabled
7175 && loc2
->owner
->enable_state
!= bp_call_disabled
)
7179 /* We should never reach this point if there is a permanent
7180 breakpoint at the same address as the one being deleted.
7181 If there is a permanent breakpoint somewhere, it should
7182 always be the only one inserted. */
7183 if (loc2
->owner
->enable_state
== bp_permanent
)
7184 internal_error (__FILE__
, __LINE__
,
7185 _("another breakpoint was inserted on top of "
7186 "a permanent breakpoint"));
7188 memset (&loc2
->target_info
, 0, sizeof (loc2
->target_info
));
7189 loc2
->target_info
.placed_address
= loc2
->address
;
7190 if (b
->type
== bp_hardware_breakpoint
)
7191 val
= target_insert_hw_breakpoint (&loc2
->target_info
);
7193 val
= target_insert_breakpoint (&loc2
->target_info
);
7195 /* If there was an error in the insert, print a message, then stop execution. */
7198 struct ui_file
*tmp_error_stream
= mem_fileopen ();
7199 make_cleanup_ui_file_delete (tmp_error_stream
);
7202 if (b
->type
== bp_hardware_breakpoint
)
7204 fprintf_unfiltered (tmp_error_stream
,
7205 "Cannot insert hardware breakpoint %d.\n"
7206 "You may have requested too many hardware breakpoints.\n",
7211 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
7212 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
7213 deprecated_print_address_numeric (loc2
->address
, 1, tmp_error_stream
);
7214 fprintf_filtered (tmp_error_stream
, ": %s.\n",
7215 safe_strerror (val
));
7218 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
7219 target_terminal_ours_for_output ();
7220 error_stream(tmp_error_stream
);
7228 free_command_lines (&bpt
->commands
);
7229 if (bpt
->cond_string
!= NULL
)
7230 xfree (bpt
->cond_string
);
7231 if (bpt
->addr_string
!= NULL
)
7232 xfree (bpt
->addr_string
);
7233 if (bpt
->exp
!= NULL
)
7235 if (bpt
->exp_string
!= NULL
)
7236 xfree (bpt
->exp_string
);
7237 if (bpt
->val
!= NULL
)
7238 value_free (bpt
->val
);
7239 if (bpt
->source_file
!= NULL
)
7240 xfree (bpt
->source_file
);
7241 if (bpt
->dll_pathname
!= NULL
)
7242 xfree (bpt
->dll_pathname
);
7243 if (bpt
->triggered_dll_pathname
!= NULL
)
7244 xfree (bpt
->triggered_dll_pathname
);
7245 if (bpt
->exec_pathname
!= NULL
)
7246 xfree (bpt
->exec_pathname
);
7248 /* Be sure no bpstat's are pointing at it after it's been freed. */
7249 /* FIXME, how can we find all bpstat's?
7250 We just check stop_bpstat for now. Note that we cannot just
7251 remove bpstats pointing at bpt from the stop_bpstat list
7252 entirely, as breakpoint commands are associated with the bpstat;
7253 if we remove it here, then the later call to
7254 bpstat_do_actions (&stop_bpstat);
7255 in event-top.c won't do anything, and temporary breakpoints
7256 with commands won't work. */
7257 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
7258 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7260 bs
->breakpoint_at
= NULL
;
7262 /* bs->commands will be freed later. */
7264 /* On the chance that someone will soon try again to delete this same
7265 bp, we mark it as deleted before freeing its storage. */
7266 bpt
->type
= bp_none
;
7268 for (loc
= bpt
->loc
; loc
;)
7270 struct bp_location
*loc_next
= loc
->next
;
7278 do_delete_breakpoint_cleanup (void *b
)
7280 delete_breakpoint (b
);
7284 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7286 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7290 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
7292 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
7296 delete_command (char *arg
, int from_tty
)
7298 struct breakpoint
*b
, *temp
;
7304 int breaks_to_delete
= 0;
7306 /* Delete all breakpoints if no argument.
7307 Do not delete internal or call-dummy breakpoints, these
7308 have to be deleted with an explicit breakpoint number argument. */
7311 if (b
->type
!= bp_call_dummy
&&
7312 b
->type
!= bp_shlib_event
&&
7313 b
->type
!= bp_thread_event
&&
7314 b
->type
!= bp_overlay_event
&&
7317 breaks_to_delete
= 1;
7322 /* Ask user only if there are some breakpoints to delete. */
7324 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7326 ALL_BREAKPOINTS_SAFE (b
, temp
)
7328 if (b
->type
!= bp_call_dummy
&&
7329 b
->type
!= bp_shlib_event
&&
7330 b
->type
!= bp_thread_event
&&
7331 b
->type
!= bp_overlay_event
&&
7333 delete_breakpoint (b
);
7338 map_breakpoint_numbers (arg
, delete_breakpoint
);
7342 all_locations_are_pending (struct bp_location
*loc
)
7344 for (; loc
; loc
= loc
->next
)
7345 if (!loc
->shlib_disabled
)
7351 update_breakpoint_locations (struct breakpoint
*b
,
7352 struct symtabs_and_lines sals
)
7356 struct bp_location
*existing_locations
= b
->loc
;
7358 /* If there's no new locations, and all existing locations
7359 are pending, don't do anything. This optimizes
7360 the common case where all locations are in the same
7361 shared library, that was unloaded. We'd like to
7362 retain the location, so that when the library
7363 is loaded again, we don't loose the enabled/disabled
7364 status of the individual locations. */
7365 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7368 unlink_locations_from_global_list (b
);
7371 for (i
= 0; i
< sals
.nelts
; ++i
)
7373 struct bp_location
*new_loc
=
7374 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7376 /* Reparse conditions, they might contain references to the
7378 if (b
->cond_string
!= NULL
)
7380 struct gdb_exception e
;
7383 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7385 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7390 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7391 b
->number
, e
.message
);
7392 new_loc
->enabled
= 0;
7396 if (b
->source_file
!= NULL
)
7397 xfree (b
->source_file
);
7398 if (sals
.sals
[i
].symtab
== NULL
)
7399 b
->source_file
= NULL
;
7402 savestring (sals
.sals
[i
].symtab
->filename
,
7403 strlen (sals
.sals
[i
].symtab
->filename
));
7405 if (b
->line_number
== 0)
7406 b
->line_number
= sals
.sals
[i
].line
;
7409 /* If possible, carry over 'disable' status from existing breakpoints. */
7411 struct bp_location
*e
= existing_locations
;
7412 for (; e
; e
= e
->next
)
7414 if (!e
->enabled
&& e
->function_name
)
7416 struct bp_location
*l
= b
->loc
;
7417 for (; l
; l
= l
->next
)
7418 if (l
->function_name
7419 && strcmp (e
->function_name
, l
->function_name
) == 0)
7428 while (existing_locations
)
7430 struct bp_location
*next
= existing_locations
->next
;
7431 free_bp_location (existing_locations
);
7432 existing_locations
= next
;
7437 /* Reset a breakpoint given it's struct breakpoint * BINT.
7438 The value we return ends up being the return value from catch_errors.
7439 Unused in this case. */
7442 breakpoint_re_set_one (void *bint
)
7444 /* get past catch_errs */
7445 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7449 int *not_found_ptr
= ¬_found
;
7450 struct symtabs_and_lines sals
= {};
7451 struct symtabs_and_lines expanded
;
7453 enum enable_state save_enable
;
7454 struct gdb_exception e
;
7460 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7464 case bp_hardware_breakpoint
:
7466 case bp_catch_unload
:
7467 if (b
->addr_string
== NULL
)
7469 /* Anything without a string can't be re-set. */
7470 delete_breakpoint (b
);
7474 set_language (b
->language
);
7475 input_radix
= b
->input_radix
;
7477 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7479 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7484 int not_found_and_ok
= 0;
7485 /* For pending breakpoints, it's expected that parsing
7486 will fail until the right shared library is loaded.
7487 User has already told to create pending breakpoints and
7488 don't need extra messages. If breakpoint is in bp_shlib_disabled
7489 state, then user already saw the message about that breakpoint
7490 being disabled, and don't want to see more errors. */
7492 && (b
->condition_not_parsed
7493 || (b
->loc
&& b
->loc
->shlib_disabled
)
7494 || b
->enable_state
== bp_disabled
))
7495 not_found_and_ok
= 1;
7497 if (!not_found_and_ok
)
7499 /* We surely don't want to warn about the same breakpoint
7500 10 times. One solution, implemented here, is disable
7501 the breakpoint on error. Another solution would be to
7502 have separate 'warning emitted' flag. Since this
7503 happens only when a binary has changed, I don't know
7504 which approach is better. */
7505 b
->enable_state
= bp_disabled
;
7506 throw_exception (e
);
7513 gdb_assert (sals
.nelts
== 1);
7514 resolve_sal_pc (&sals
.sals
[0]);
7515 if (b
->condition_not_parsed
&& s
&& s
[0])
7517 char *cond_string
= 0;
7519 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7520 &cond_string
, &thread
);
7522 b
->cond_string
= cond_string
;
7524 b
->condition_not_parsed
= 0;
7526 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7527 update_breakpoint_locations (b
, expanded
);
7529 /* Now that this is re-enabled, check_duplicates
7531 check_duplicates (b
);
7537 case bp_hardware_watchpoint
:
7538 case bp_read_watchpoint
:
7539 case bp_access_watchpoint
:
7540 innermost_block
= NULL
;
7541 /* The issue arises of what context to evaluate this in. The
7542 same one as when it was set, but what does that mean when
7543 symbols have been re-read? We could save the filename and
7544 functionname, but if the context is more local than that, the
7545 best we could do would be something like how many levels deep
7546 and which index at that particular level, but that's going to
7547 be less stable than filenames or function names. */
7549 /* So for now, just use a global context. */
7553 /* Avoid re-freeing b->exp if an error during the call to
7554 parse_expression. */
7557 b
->exp
= parse_expression (b
->exp_string
);
7558 b
->exp_valid_block
= innermost_block
;
7559 mark
= value_mark ();
7562 value_free (b
->val
);
7563 /* Avoid re-freeing b->val if an error during the call to
7564 evaluate_expression. */
7567 b
->val
= evaluate_expression (b
->exp
);
7568 release_value (b
->val
);
7569 if (value_lazy (b
->val
) && breakpoint_enabled (b
))
7570 value_fetch_lazy (b
->val
);
7572 if (b
->cond_string
!= NULL
)
7577 xfree (b
->loc
->cond
);
7578 /* Avoid re-freeing b->exp if an error during the call
7580 b
->loc
->cond
= NULL
;
7582 b
->loc
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
7584 if (breakpoint_enabled (b
))
7586 value_free_to_mark (mark
);
7588 case bp_catch_catch
:
7589 case bp_catch_throw
:
7591 /* We needn't really do anything to reset these, since the mask
7592 that requests them is unaffected by e.g., new libraries being
7595 case bp_catch_vfork
:
7600 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7602 /* Delete longjmp and overlay event breakpoints; they will be
7603 reset later by breakpoint_re_set. */
7605 case bp_longjmp_resume
:
7606 case bp_overlay_event
:
7607 delete_breakpoint (b
);
7610 /* This breakpoint is special, it's set up when the inferior
7611 starts and we really don't want to touch it. */
7612 case bp_shlib_event
:
7614 /* Like bp_shlib_event, this breakpoint type is special.
7615 Once it is set up, we do not want to touch it. */
7616 case bp_thread_event
:
7618 /* Keep temporary breakpoints, which can be encountered when we step
7619 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7620 Otherwise these should have been blown away via the cleanup chain
7621 or by breakpoint_init_inferior when we rerun the executable. */
7624 case bp_watchpoint_scope
:
7626 case bp_step_resume
:
7633 /* Re-set all breakpoints after symbols have been re-loaded. */
7635 breakpoint_re_set (void)
7637 struct breakpoint
*b
, *temp
;
7638 enum language save_language
;
7639 int save_input_radix
;
7641 save_language
= current_language
->la_language
;
7642 save_input_radix
= input_radix
;
7643 ALL_BREAKPOINTS_SAFE (b
, temp
)
7645 /* Format possible error msg */
7646 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7648 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7649 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7650 do_cleanups (cleanups
);
7652 set_language (save_language
);
7653 input_radix
= save_input_radix
;
7655 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
7657 create_longjmp_breakpoint ("longjmp");
7658 create_longjmp_breakpoint ("_longjmp");
7659 create_longjmp_breakpoint ("siglongjmp");
7660 create_longjmp_breakpoint ("_siglongjmp");
7661 create_longjmp_breakpoint (NULL
);
7664 create_overlay_event_breakpoint ("_ovly_debug_event");
7667 /* Reset the thread number of this breakpoint:
7669 - If the breakpoint is for all threads, leave it as-is.
7670 - Else, reset it to the current thread for inferior_ptid. */
7672 breakpoint_re_set_thread (struct breakpoint
*b
)
7674 if (b
->thread
!= -1)
7676 if (in_thread_list (inferior_ptid
))
7677 b
->thread
= pid_to_thread_id (inferior_ptid
);
7681 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7682 If from_tty is nonzero, it prints a message to that effect,
7683 which ends with a period (no newline). */
7686 set_ignore_count (int bptnum
, int count
, int from_tty
)
7688 struct breakpoint
*b
;
7694 if (b
->number
== bptnum
)
7696 b
->ignore_count
= count
;
7700 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7702 else if (count
== 1)
7703 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7706 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7709 breakpoints_changed ();
7710 breakpoint_modify_event (b
->number
);
7714 error (_("No breakpoint number %d."), bptnum
);
7717 /* Clear the ignore counts of all breakpoints. */
7719 breakpoint_clear_ignore_counts (void)
7721 struct breakpoint
*b
;
7724 b
->ignore_count
= 0;
7727 /* Command to set ignore-count of breakpoint N to COUNT. */
7730 ignore_command (char *args
, int from_tty
)
7736 error_no_arg (_("a breakpoint number"));
7738 num
= get_number (&p
);
7740 error (_("bad breakpoint number: '%s'"), args
);
7742 error (_("Second argument (specified ignore-count) is missing."));
7744 set_ignore_count (num
,
7745 longest_to_int (value_as_long (parse_and_eval (p
))),
7748 printf_filtered ("\n");
7751 /* Call FUNCTION on each of the breakpoints
7752 whose numbers are given in ARGS. */
7755 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7760 struct breakpoint
*b
, *tmp
;
7764 error_no_arg (_("one or more breakpoint numbers"));
7771 num
= get_number_or_range (&p1
);
7774 warning (_("bad breakpoint number at or near '%s'"), p
);
7778 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7779 if (b
->number
== num
)
7781 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7784 if (related_breakpoint
)
7785 function (related_breakpoint
);
7789 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7795 static struct bp_location
*
7796 find_location_by_number (char *number
)
7798 char *dot
= strchr (number
, '.');
7802 struct breakpoint
*b
;
7803 struct bp_location
*loc
;
7808 bp_num
= get_number_or_range (&p1
);
7810 error (_("Bad breakpoint number '%s'"), number
);
7813 if (b
->number
== bp_num
)
7818 if (!b
|| b
->number
!= bp_num
)
7819 error (_("Bad breakpoint number '%s'"), number
);
7822 loc_num
= get_number_or_range (&p1
);
7824 error (_("Bad breakpoint location number '%s'"), number
);
7828 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7831 error (_("Bad breakpoint location number '%s'"), dot
+1);
7837 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7838 If from_tty is nonzero, it prints a message to that effect,
7839 which ends with a period (no newline). */
7842 disable_breakpoint (struct breakpoint
*bpt
)
7844 /* Never disable a watchpoint scope breakpoint; we want to
7845 hit them when we leave scope so we can delete both the
7846 watchpoint and its scope breakpoint at that time. */
7847 if (bpt
->type
== bp_watchpoint_scope
)
7850 /* You can't disable permanent breakpoints. */
7851 if (bpt
->enable_state
== bp_permanent
)
7854 bpt
->enable_state
= bp_disabled
;
7856 check_duplicates (bpt
);
7858 if (deprecated_modify_breakpoint_hook
)
7859 deprecated_modify_breakpoint_hook (bpt
);
7860 breakpoint_modify_event (bpt
->number
);
7864 disable_command (char *args
, int from_tty
)
7866 struct breakpoint
*bpt
;
7868 ALL_BREAKPOINTS (bpt
)
7872 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7877 case bp_catch_unload
:
7879 case bp_catch_vfork
:
7881 case bp_catch_catch
:
7882 case bp_catch_throw
:
7883 case bp_hardware_breakpoint
:
7885 case bp_hardware_watchpoint
:
7886 case bp_read_watchpoint
:
7887 case bp_access_watchpoint
:
7888 disable_breakpoint (bpt
);
7892 else if (strchr (args
, '.'))
7894 struct bp_location
*loc
= find_location_by_number (args
);
7897 check_duplicates (loc
->owner
);
7900 map_breakpoint_numbers (args
, disable_breakpoint
);
7904 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7906 int target_resources_ok
, other_type_used
;
7909 if (bpt
->type
== bp_hardware_breakpoint
)
7912 i
= hw_breakpoint_used_count ();
7913 target_resources_ok
=
7914 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7916 if (target_resources_ok
== 0)
7917 error (_("No hardware breakpoint support in the target."));
7918 else if (target_resources_ok
< 0)
7919 error (_("Hardware breakpoints used exceeds limit."));
7922 if (bpt
->type
== bp_watchpoint
||
7923 bpt
->type
== bp_hardware_watchpoint
||
7924 bpt
->type
== bp_read_watchpoint
||
7925 bpt
->type
== bp_access_watchpoint
)
7927 struct frame_id saved_frame_id
;
7929 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7930 if (bpt
->exp_valid_block
!= NULL
)
7932 struct frame_info
*fr
=
7933 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7936 printf_filtered (_("\
7937 Cannot enable watchpoint %d because the block in which its expression\n\
7938 is valid is not currently in scope.\n"), bpt
->number
);
7945 value_free (bpt
->val
);
7946 mark
= value_mark ();
7947 bpt
->val
= evaluate_expression (bpt
->exp
);
7948 release_value (bpt
->val
);
7949 if (value_lazy (bpt
->val
))
7950 value_fetch_lazy (bpt
->val
);
7952 if (bpt
->type
== bp_hardware_watchpoint
||
7953 bpt
->type
== bp_read_watchpoint
||
7954 bpt
->type
== bp_access_watchpoint
)
7956 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7957 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7959 /* Hack around 'unused var' error for some targets here */
7960 (void) mem_cnt
, (void) i
;
7961 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7962 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7963 /* we can consider of type is bp_hardware_watchpoint, convert to
7964 bp_watchpoint in the following condition */
7965 if (target_resources_ok
< 0)
7967 printf_filtered (_("\
7968 Cannot enable watchpoint %d because target watch resources\n\
7969 have been allocated for other watchpoints.\n"), bpt
->number
);
7970 value_free_to_mark (mark
);
7975 select_frame (frame_find_by_id (saved_frame_id
));
7976 value_free_to_mark (mark
);
7979 if (bpt
->enable_state
!= bp_permanent
)
7980 bpt
->enable_state
= bp_enabled
;
7981 bpt
->disposition
= disposition
;
7982 check_duplicates (bpt
);
7983 breakpoints_changed ();
7985 if (deprecated_modify_breakpoint_hook
)
7986 deprecated_modify_breakpoint_hook (bpt
);
7987 breakpoint_modify_event (bpt
->number
);
7992 enable_breakpoint (struct breakpoint
*bpt
)
7994 do_enable_breakpoint (bpt
, bpt
->disposition
);
7997 /* The enable command enables the specified breakpoints (or all defined
7998 breakpoints) so they once again become (or continue to be) effective
7999 in stopping the inferior. */
8002 enable_command (char *args
, int from_tty
)
8004 struct breakpoint
*bpt
;
8006 ALL_BREAKPOINTS (bpt
)
8010 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8015 case bp_catch_unload
:
8017 case bp_catch_vfork
:
8019 case bp_catch_catch
:
8020 case bp_catch_throw
:
8021 case bp_hardware_breakpoint
:
8023 case bp_hardware_watchpoint
:
8024 case bp_read_watchpoint
:
8025 case bp_access_watchpoint
:
8026 enable_breakpoint (bpt
);
8030 else if (strchr (args
, '.'))
8032 struct bp_location
*loc
= find_location_by_number (args
);
8035 check_duplicates (loc
->owner
);
8038 map_breakpoint_numbers (args
, enable_breakpoint
);
8042 enable_once_breakpoint (struct breakpoint
*bpt
)
8044 do_enable_breakpoint (bpt
, disp_disable
);
8048 enable_once_command (char *args
, int from_tty
)
8050 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8054 enable_delete_breakpoint (struct breakpoint
*bpt
)
8056 do_enable_breakpoint (bpt
, disp_del
);
8060 enable_delete_command (char *args
, int from_tty
)
8062 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8066 set_breakpoint_cmd (char *args
, int from_tty
)
8071 show_breakpoint_cmd (char *args
, int from_tty
)
8075 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8077 struct symtabs_and_lines
8078 decode_line_spec_1 (char *string
, int funfirstline
)
8080 struct symtabs_and_lines sals
;
8082 error (_("Empty line specification."));
8083 if (default_breakpoint_valid
)
8084 sals
= decode_line_1 (&string
, funfirstline
,
8085 default_breakpoint_symtab
,
8086 default_breakpoint_line
,
8087 (char ***) NULL
, NULL
);
8089 sals
= decode_line_1 (&string
, funfirstline
,
8090 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8092 error (_("Junk at end of line specification: %s"), string
);
8096 /* Create and insert a raw software breakpoint at PC. Return an
8097 identifier, which should be used to remove the breakpoint later.
8098 In general, places which call this should be using something on the
8099 breakpoint chain instead; this function should be eliminated
8103 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8105 struct bp_target_info
*bp_tgt
;
8107 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8108 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8110 bp_tgt
->placed_address
= pc
;
8111 if (target_insert_breakpoint (bp_tgt
) != 0)
8113 /* Could not insert the breakpoint. */
8121 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8124 deprecated_remove_raw_breakpoint (void *bp
)
8126 struct bp_target_info
*bp_tgt
= bp
;
8129 ret
= target_remove_breakpoint (bp_tgt
);
8135 /* One (or perhaps two) breakpoints used for software single stepping. */
8137 static void *single_step_breakpoints
[2];
8139 /* Create and insert a breakpoint for software single step. */
8142 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8146 if (single_step_breakpoints
[0] == NULL
)
8147 bpt_p
= &single_step_breakpoints
[0];
8150 gdb_assert (single_step_breakpoints
[1] == NULL
);
8151 bpt_p
= &single_step_breakpoints
[1];
8154 /* NOTE drow/2006-04-11: A future improvement to this function would be
8155 to only create the breakpoints once, and actually put them on the
8156 breakpoint chain. That would let us use set_raw_breakpoint. We could
8157 adjust the addresses each time they were needed. Doing this requires
8158 corresponding changes elsewhere where single step breakpoints are
8159 handled, however. So, for now, we use this. */
8161 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8163 error (_("Could not insert single-step breakpoint at 0x%s"),
8164 paddr_nz (next_pc
));
8167 /* Remove and delete any breakpoints used for software single step. */
8170 remove_single_step_breakpoints (void)
8172 gdb_assert (single_step_breakpoints
[0] != NULL
);
8174 /* See insert_single_step_breakpoint for more about this deprecated
8176 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8177 single_step_breakpoints
[0] = NULL
;
8179 if (single_step_breakpoints
[1] != NULL
)
8181 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8182 single_step_breakpoints
[1] = NULL
;
8186 /* Check whether a software single-step breakpoint is inserted at PC. */
8189 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8193 for (i
= 0; i
< 2; i
++)
8195 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8196 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8204 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8205 It is defined as a macro to prevent duplication.
8206 COMMAND should be a string constant containing the name of the command. */
8207 #define BREAK_ARGS_HELP(command) \
8208 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8209 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8210 If a line number is specified, break at start of code for that line.\n\
8211 If a function is specified, break at start of code for that function.\n\
8212 If an address is specified, break at that exact address.\n\
8213 With no LOCATION, uses current execution address of selected stack frame.\n\
8214 This is useful for breaking on return to a stack frame.\n\
8216 THREADNUM is the number from \"info threads\".\n\
8217 CONDITION is a boolean expression.\n\
8219 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8221 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8224 _initialize_breakpoint (void)
8226 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8227 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8228 struct cmd_list_element
*c
;
8230 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8232 breakpoint_chain
= 0;
8233 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8234 before a breakpoint is set. */
8235 breakpoint_count
= 0;
8237 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8238 Set ignore-count of breakpoint number N to COUNT.\n\
8239 Usage is `ignore N COUNT'."));
8241 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8243 add_com ("commands", class_breakpoint
, commands_command
, _("\
8244 Set commands to be executed when a breakpoint is hit.\n\
8245 Give breakpoint number as argument after \"commands\".\n\
8246 With no argument, the targeted breakpoint is the last one set.\n\
8247 The commands themselves follow starting on the next line.\n\
8248 Type a line containing \"end\" to indicate the end of them.\n\
8249 Give \"silent\" as the first line to make the breakpoint silent;\n\
8250 then no output is printed when it is hit, except what the commands print."));
8252 add_com ("condition", class_breakpoint
, condition_command
, _("\
8253 Specify breakpoint number N to break only if COND is true.\n\
8254 Usage is `condition N COND', where N is an integer and COND is an\n\
8255 expression to be evaluated whenever breakpoint N is reached."));
8257 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8258 Set a temporary breakpoint.\n\
8259 Like \"break\" except the breakpoint is only temporary,\n\
8260 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8261 by using \"enable delete\" on the breakpoint number.\n\
8263 BREAK_ARGS_HELP ("tbreak")));
8264 set_cmd_completer (c
, location_completer
);
8266 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8267 Set a hardware assisted breakpoint.\n\
8268 Like \"break\" except the breakpoint requires hardware support,\n\
8269 some target hardware may not have this support.\n\
8271 BREAK_ARGS_HELP ("hbreak")));
8272 set_cmd_completer (c
, location_completer
);
8274 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8275 Set a temporary hardware assisted breakpoint.\n\
8276 Like \"hbreak\" except the breakpoint is only temporary,\n\
8277 so it will be deleted when hit.\n\
8279 BREAK_ARGS_HELP ("thbreak")));
8280 set_cmd_completer (c
, location_completer
);
8282 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8283 Enable some breakpoints.\n\
8284 Give breakpoint numbers (separated by spaces) as arguments.\n\
8285 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8286 This is used to cancel the effect of the \"disable\" command.\n\
8287 With a subcommand you can enable temporarily."),
8288 &enablelist
, "enable ", 1, &cmdlist
);
8290 add_com ("ab", class_breakpoint
, enable_command
, _("\
8291 Enable some breakpoints.\n\
8292 Give breakpoint numbers (separated by spaces) as arguments.\n\
8293 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8294 This is used to cancel the effect of the \"disable\" command.\n\
8295 With a subcommand you can enable temporarily."));
8297 add_com_alias ("en", "enable", class_breakpoint
, 1);
8299 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8300 Enable some breakpoints.\n\
8301 Give breakpoint numbers (separated by spaces) as arguments.\n\
8302 This is used to cancel the effect of the \"disable\" command.\n\
8303 May be abbreviated to simply \"enable\".\n"),
8304 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8306 add_cmd ("once", no_class
, enable_once_command
, _("\
8307 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8308 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8311 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8312 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8313 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8316 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8317 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8318 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8321 add_cmd ("once", no_class
, enable_once_command
, _("\
8322 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8323 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8326 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8327 Disable some breakpoints.\n\
8328 Arguments are breakpoint numbers with spaces in between.\n\
8329 To disable all breakpoints, give no argument.\n\
8330 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8331 &disablelist
, "disable ", 1, &cmdlist
);
8332 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8333 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8335 add_com ("sb", class_breakpoint
, disable_command
, _("\
8336 Disable some breakpoints.\n\
8337 Arguments are breakpoint numbers with spaces in between.\n\
8338 To disable all breakpoints, give no argument.\n\
8339 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8341 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8342 Disable some breakpoints.\n\
8343 Arguments are breakpoint numbers with spaces in between.\n\
8344 To disable all breakpoints, give no argument.\n\
8345 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8346 This command may be abbreviated \"disable\"."),
8349 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8350 Delete some breakpoints or auto-display expressions.\n\
8351 Arguments are breakpoint numbers with spaces in between.\n\
8352 To delete all breakpoints, give no argument.\n\
8354 Also a prefix command for deletion of other GDB objects.\n\
8355 The \"unset\" command is also an alias for \"delete\"."),
8356 &deletelist
, "delete ", 1, &cmdlist
);
8357 add_com_alias ("d", "delete", class_breakpoint
, 1);
8358 add_com_alias ("del", "delete", class_breakpoint
, 1);
8360 add_com ("db", class_breakpoint
, delete_command
, _("\
8361 Delete some breakpoints.\n\
8362 Arguments are breakpoint numbers with spaces in between.\n\
8363 To delete all breakpoints, give no argument.\n"));
8365 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8366 Delete some breakpoints or auto-display expressions.\n\
8367 Arguments are breakpoint numbers with spaces in between.\n\
8368 To delete all breakpoints, give no argument.\n\
8369 This command may be abbreviated \"delete\"."),
8372 add_com ("clear", class_breakpoint
, clear_command
, _("\
8373 Clear breakpoint at specified line or function.\n\
8374 Argument may be line number, function name, or \"*\" and an address.\n\
8375 If line number is specified, all breakpoints in that line are cleared.\n\
8376 If function is specified, breakpoints at beginning of function are cleared.\n\
8377 If an address is specified, breakpoints at that address are cleared.\n\
8379 With no argument, clears all breakpoints in the line that the selected frame\n\
8382 See also the \"delete\" command which clears breakpoints by number."));
8384 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8385 Set breakpoint at specified line or function.\n"
8386 BREAK_ARGS_HELP ("break")));
8387 set_cmd_completer (c
, location_completer
);
8389 add_com_alias ("b", "break", class_run
, 1);
8390 add_com_alias ("br", "break", class_run
, 1);
8391 add_com_alias ("bre", "break", class_run
, 1);
8392 add_com_alias ("brea", "break", class_run
, 1);
8396 add_com_alias ("ba", "break", class_breakpoint
, 1);
8397 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8402 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8403 Break in function/address or break at a line in the current file."),
8404 &stoplist
, "stop ", 1, &cmdlist
);
8405 add_cmd ("in", class_breakpoint
, stopin_command
,
8406 _("Break in function or address."), &stoplist
);
8407 add_cmd ("at", class_breakpoint
, stopat_command
,
8408 _("Break at a line in the current file."), &stoplist
);
8409 add_com ("status", class_info
, breakpoints_info
, _("\
8410 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8411 The \"Type\" column indicates one of:\n\
8412 \tbreakpoint - normal breakpoint\n\
8413 \twatchpoint - watchpoint\n\
8414 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8415 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8416 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8417 address and file/line number respectively.\n\
8419 Convenience variable \"$_\" and default examine address for \"x\"\n\
8420 are set to the address of the last breakpoint listed unless the command\n\
8421 is prefixed with \"server \".\n\n\
8422 Convenience variable \"$bpnum\" contains the number of the last\n\
8426 add_info ("breakpoints", breakpoints_info
, _("\
8427 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8428 The \"Type\" column indicates one of:\n\
8429 \tbreakpoint - normal breakpoint\n\
8430 \twatchpoint - watchpoint\n\
8431 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8432 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8433 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8434 address and file/line number respectively.\n\
8436 Convenience variable \"$_\" and default examine address for \"x\"\n\
8437 are set to the address of the last breakpoint listed unless the command\n\
8438 is prefixed with \"server \".\n\n\
8439 Convenience variable \"$bpnum\" contains the number of the last\n\
8443 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8444 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8445 The \"Type\" column indicates one of:\n\
8446 \tbreakpoint - normal breakpoint\n\
8447 \twatchpoint - watchpoint\n\
8448 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8449 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8450 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8451 address and file/line number respectively.\n\
8453 Convenience variable \"$_\" and default examine address for \"x\"\n\
8454 are set to the address of the last breakpoint listed unless the command\n\
8455 is prefixed with \"server \".\n\n\
8456 Convenience variable \"$bpnum\" contains the number of the last\n\
8459 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8460 Status of all breakpoints, or breakpoint number NUMBER.\n\
8461 The \"Type\" column indicates one of:\n\
8462 \tbreakpoint - normal breakpoint\n\
8463 \twatchpoint - watchpoint\n\
8464 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8465 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8466 \tuntil - internal breakpoint used by the \"until\" command\n\
8467 \tfinish - internal breakpoint used by the \"finish\" command\n\
8468 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8469 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8470 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8471 address and file/line number respectively.\n\
8473 Convenience variable \"$_\" and default examine address for \"x\"\n\
8474 are set to the address of the last breakpoint listed unless the command\n\
8475 is prefixed with \"server \".\n\n\
8476 Convenience variable \"$bpnum\" contains the number of the last\n\
8478 &maintenanceinfolist
);
8480 add_com ("catch", class_breakpoint
, catch_command
, _("\
8481 Set catchpoints to catch events.\n\
8482 Raised signals may be caught:\n\
8483 \tcatch signal - all signals\n\
8484 \tcatch signal <signame> - a particular signal\n\
8485 Raised exceptions may be caught:\n\
8486 \tcatch throw - all exceptions, when thrown\n\
8487 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8488 \tcatch catch - all exceptions, when caught\n\
8489 \tcatch catch <exceptname> - a particular exception, when caught\n\
8490 Thread or process events may be caught:\n\
8491 \tcatch thread_start - any threads, just after creation\n\
8492 \tcatch thread_exit - any threads, just before expiration\n\
8493 \tcatch thread_join - any threads, just after joins\n\
8494 Process events may be caught:\n\
8495 \tcatch start - any processes, just after creation\n\
8496 \tcatch exit - any processes, just before expiration\n\
8497 \tcatch fork - calls to fork()\n\
8498 \tcatch vfork - calls to vfork()\n\
8499 \tcatch exec - calls to exec()\n\
8500 Dynamically-linked library events may be caught:\n\
8501 \tcatch load - loads of any library\n\
8502 \tcatch load <libname> - loads of a particular library\n\
8503 \tcatch unload - unloads of any library\n\
8504 \tcatch unload <libname> - unloads of a particular library\n\
8505 The act of your program's execution stopping may also be caught:\n\
8507 C++ exceptions may be caught:\n\
8508 \tcatch throw - all exceptions, when thrown\n\
8509 \tcatch catch - all exceptions, when caught\n\
8510 Ada exceptions may be caught:\n\
8511 \tcatch exception - all exceptions, when raised\n\
8512 \tcatch exception <name> - a particular exception, when raised\n\
8513 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8514 \tcatch assert - all failed assertions, when raised\n\
8516 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8517 after a fork or vfork is caught.\n\n\
8518 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8520 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8521 Set temporary catchpoints to catch events.\n\
8522 Args like \"catch\" command.\n\
8523 Like \"catch\" except the catchpoint is only temporary,\n\
8524 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8525 by using \"enable delete\" on the catchpoint number."));
8527 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8528 Set a watchpoint for an expression.\n\
8529 A watchpoint stops execution of your program whenever the value of\n\
8530 an expression changes."));
8531 set_cmd_completer (c
, location_completer
);
8533 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8534 Set a read watchpoint for an expression.\n\
8535 A watchpoint stops execution of your program whenever the value of\n\
8536 an expression is read."));
8537 set_cmd_completer (c
, location_completer
);
8539 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8540 Set a watchpoint for an expression.\n\
8541 A watchpoint stops execution of your program whenever the value of\n\
8542 an expression is either read or written."));
8543 set_cmd_completer (c
, location_completer
);
8545 add_info ("watchpoints", breakpoints_info
,
8546 _("Synonym for ``info breakpoints''."));
8549 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8550 respond to changes - contrary to the description. */
8551 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8552 &can_use_hw_watchpoints
, _("\
8553 Set debugger's willingness to use watchpoint hardware."), _("\
8554 Show debugger's willingness to use watchpoint hardware."), _("\
8555 If zero, gdb will not use hardware for new watchpoints, even if\n\
8556 such is available. (However, any hardware watchpoints that were\n\
8557 created before setting this to nonzero, will continue to use watchpoint\n\
8560 show_can_use_hw_watchpoints
,
8561 &setlist
, &showlist
);
8563 can_use_hw_watchpoints
= 1;
8565 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8566 Breakpoint specific settings\n\
8567 Configure various breakpoint-specific variables such as\n\
8568 pending breakpoint behavior"),
8569 &breakpoint_set_cmdlist
, "set breakpoint ",
8570 0/*allow-unknown*/, &setlist
);
8571 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8572 Breakpoint specific settings\n\
8573 Configure various breakpoint-specific variables such as\n\
8574 pending breakpoint behavior"),
8575 &breakpoint_show_cmdlist
, "show breakpoint ",
8576 0/*allow-unknown*/, &showlist
);
8578 add_setshow_auto_boolean_cmd ("pending", no_class
,
8579 &pending_break_support
, _("\
8580 Set debugger's behavior regarding pending breakpoints."), _("\
8581 Show debugger's behavior regarding pending breakpoints."), _("\
8582 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8583 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8584 an error. If auto, an unrecognized breakpoint location results in a\n\
8585 user-query to see if a pending breakpoint should be created."),
8587 show_pending_break_support
,
8588 &breakpoint_set_cmdlist
,
8589 &breakpoint_show_cmdlist
);
8591 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8593 add_setshow_boolean_cmd ("auto-hw", no_class
,
8594 &automatic_hardware_breakpoints
, _("\
8595 Set automatic usage of hardware breakpoints."), _("\
8596 Show automatic usage of hardware breakpoints."), _("\
8597 If set, the debugger will automatically use hardware breakpoints for\n\
8598 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8599 a warning will be emitted for such breakpoints."),
8601 show_automatic_hardware_breakpoints
,
8602 &breakpoint_set_cmdlist
,
8603 &breakpoint_show_cmdlist
);
8605 automatic_hardware_breakpoints
= 1;