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
;
1227 int return_val
= 0; /* return success code. */
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
);
1293 remove_breakpoints (void)
1295 struct bp_location
*b
;
1298 ALL_BP_LOCATIONS (b
)
1302 val
= remove_breakpoint (b
, mark_uninserted
);
1311 remove_hw_watchpoints (void)
1313 struct bp_location
*b
;
1316 ALL_BP_LOCATIONS (b
)
1318 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1320 val
= remove_breakpoint (b
, mark_uninserted
);
1329 reattach_breakpoints (int pid
)
1331 struct bp_location
*b
;
1333 struct cleanup
*old_chain
= save_inferior_ptid ();
1334 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1335 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1337 make_cleanup_ui_file_delete (tmp_error_stream
);
1339 inferior_ptid
= pid_to_ptid (pid
);
1340 ALL_BP_LOCATIONS (b
)
1345 val
= insert_bp_location (b
, tmp_error_stream
,
1346 &dummy1
, &dummy2
, &dummy3
);
1349 do_cleanups (old_chain
);
1354 do_cleanups (old_chain
);
1359 update_breakpoints_after_exec (void)
1361 struct breakpoint
*b
;
1362 struct breakpoint
*temp
;
1364 /* Doing this first prevents the badness of having delete_breakpoint()
1365 write a breakpoint's current "shadow contents" to lift the bp. That
1366 shadow is NOT valid after an exec()! */
1367 mark_breakpoints_out ();
1369 ALL_BREAKPOINTS_SAFE (b
, temp
)
1371 /* Solib breakpoints must be explicitly reset after an exec(). */
1372 if (b
->type
== bp_shlib_event
)
1374 delete_breakpoint (b
);
1378 /* Thread event breakpoints must be set anew after an exec(),
1379 as must overlay event breakpoints. */
1380 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1382 delete_breakpoint (b
);
1386 /* Step-resume breakpoints are meaningless after an exec(). */
1387 if (b
->type
== bp_step_resume
)
1389 delete_breakpoint (b
);
1393 /* Ditto the exception-handling catchpoints. */
1394 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1396 delete_breakpoint (b
);
1400 /* Don't delete an exec catchpoint, because else the inferior
1401 won't stop when it ought!
1403 Similarly, we probably ought to keep vfork catchpoints, 'cause
1404 on this target, we may not be able to stop when the vfork is
1405 seen, but only when the subsequent exec is seen. (And because
1406 deleting fork catchpoints here but not vfork catchpoints will
1407 seem mysterious to users, keep those too.) */
1408 if ((b
->type
== bp_catch_exec
) ||
1409 (b
->type
== bp_catch_vfork
) ||
1410 (b
->type
== bp_catch_fork
))
1415 /* bp_finish is a special case. The only way we ought to be able
1416 to see one of these when an exec() has happened, is if the user
1417 caught a vfork, and then said "finish". Ordinarily a finish just
1418 carries them to the call-site of the current callee, by setting
1419 a temporary bp there and resuming. But in this case, the finish
1420 will carry them entirely through the vfork & exec.
1422 We don't want to allow a bp_finish to remain inserted now. But
1423 we can't safely delete it, 'cause finish_command has a handle to
1424 the bp on a bpstat, and will later want to delete it. There's a
1425 chance (and I've seen it happen) that if we delete the bp_finish
1426 here, that its storage will get reused by the time finish_command
1427 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1428 We really must allow finish_command to delete a bp_finish.
1430 In the absense of a general solution for the "how do we know
1431 it's safe to delete something others may have handles to?"
1432 problem, what we'll do here is just uninsert the bp_finish, and
1433 let finish_command delete it.
1435 (We know the bp_finish is "doomed" in the sense that it's
1436 momentary, and will be deleted as soon as finish_command sees
1437 the inferior stopped. So it doesn't matter that the bp's
1438 address is probably bogus in the new a.out, unlike e.g., the
1439 solib breakpoints.) */
1441 if (b
->type
== bp_finish
)
1446 /* Without a symbolic address, we have little hope of the
1447 pre-exec() address meaning the same thing in the post-exec()
1449 if (b
->addr_string
== NULL
)
1451 delete_breakpoint (b
);
1455 /* FIXME what about longjmp breakpoints? Re-create them here? */
1456 create_overlay_event_breakpoint ("_ovly_debug_event");
1460 detach_breakpoints (int pid
)
1462 struct bp_location
*b
;
1464 struct cleanup
*old_chain
= save_inferior_ptid ();
1466 if (pid
== PIDGET (inferior_ptid
))
1467 error (_("Cannot detach breakpoints of inferior_ptid"));
1469 /* Set inferior_ptid; remove_breakpoint uses this global. */
1470 inferior_ptid
= pid_to_ptid (pid
);
1471 ALL_BP_LOCATIONS (b
)
1475 val
= remove_breakpoint (b
, mark_inserted
);
1478 do_cleanups (old_chain
);
1483 do_cleanups (old_chain
);
1488 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1492 if (b
->owner
->enable_state
== bp_permanent
)
1493 /* Permanent breakpoints cannot be inserted or removed. */
1496 if (b
->owner
->type
== bp_none
)
1497 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1500 if (b
->loc_type
== bp_loc_software_breakpoint
1501 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1503 /* "Normal" instruction breakpoint: either the standard
1504 trap-instruction bp (bp_breakpoint), or a
1505 bp_hardware_breakpoint. */
1507 /* First check to see if we have to handle an overlay. */
1508 if (overlay_debugging
== ovly_off
1509 || b
->section
== NULL
1510 || !(section_is_overlay (b
->section
)))
1512 /* No overlay handling: just remove the breakpoint. */
1514 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1515 val
= target_remove_hw_breakpoint (&b
->target_info
);
1517 val
= target_remove_breakpoint (&b
->target_info
);
1521 /* This breakpoint is in an overlay section.
1522 Did we set a breakpoint at the LMA? */
1523 if (!overlay_events_enabled
)
1525 /* Yes -- overlay event support is not active, so we
1526 should have set a breakpoint at the LMA. Remove it.
1528 /* Ignore any failures: if the LMA is in ROM, we will
1529 have already warned when we failed to insert it. */
1530 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1531 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1533 target_remove_breakpoint (&b
->overlay_target_info
);
1535 /* Did we set a breakpoint at the VMA?
1536 If so, we will have marked the breakpoint 'inserted'. */
1539 /* Yes -- remove it. Previously we did not bother to
1540 remove the breakpoint if the section had been
1541 unmapped, but let's not rely on that being safe. We
1542 don't know what the overlay manager might do. */
1543 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1544 val
= target_remove_hw_breakpoint (&b
->target_info
);
1546 /* However, we should remove *software* breakpoints only
1547 if the section is still mapped, or else we overwrite
1548 wrong code with the saved shadow contents. */
1549 else if (section_is_mapped (b
->section
))
1550 val
= target_remove_breakpoint (&b
->target_info
);
1556 /* No -- not inserted, so no need to remove. No error. */
1562 b
->inserted
= (is
== mark_inserted
);
1564 else if (b
->loc_type
== bp_loc_hardware_watchpoint
1565 && breakpoint_enabled (b
->owner
)
1571 b
->inserted
= (is
== mark_inserted
);
1572 /* Walk down the saved value chain. */
1573 for (v
= b
->owner
->val_chain
; v
; v
= value_next (v
))
1575 /* For each memory reference remove the watchpoint
1577 if (VALUE_LVAL (v
) == lval_memory
1578 && ! value_lazy (v
))
1580 struct type
*vtype
= check_typedef (value_type (v
));
1582 if (v
== b
->owner
->val_chain
1583 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1584 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1589 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
1590 len
= TYPE_LENGTH (value_type (v
));
1592 if (b
->owner
->type
== bp_read_watchpoint
)
1594 else if (b
->owner
->type
== bp_access_watchpoint
)
1597 val
= target_remove_watchpoint (addr
, len
, type
);
1604 /* Failure to remove any of the hardware watchpoints comes here. */
1605 if ((is
== mark_uninserted
) && (b
->inserted
))
1606 warning (_("Could not remove hardware watchpoint %d."),
1609 else if ((b
->owner
->type
== bp_catch_fork
||
1610 b
->owner
->type
== bp_catch_vfork
||
1611 b
->owner
->type
== bp_catch_exec
)
1612 && breakpoint_enabled (b
->owner
)
1616 switch (b
->owner
->type
)
1619 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1621 case bp_catch_vfork
:
1622 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1625 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1628 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1633 b
->inserted
= (is
== mark_inserted
);
1635 else if ((b
->owner
->type
== bp_catch_catch
||
1636 b
->owner
->type
== bp_catch_throw
)
1637 && breakpoint_enabled (b
->owner
)
1640 val
= target_remove_breakpoint (&b
->target_info
);
1643 b
->inserted
= (is
== mark_inserted
);
1649 /* Clear the "inserted" flag in all breakpoints. */
1652 mark_breakpoints_out (void)
1654 struct bp_location
*bpt
;
1656 ALL_BP_LOCATIONS (bpt
)
1660 /* Clear the "inserted" flag in all breakpoints and delete any
1661 breakpoints which should go away between runs of the program.
1663 Plus other such housekeeping that has to be done for breakpoints
1666 Note: this function gets called at the end of a run (by
1667 generic_mourn_inferior) and when a run begins (by
1668 init_wait_for_inferior). */
1673 breakpoint_init_inferior (enum inf_context context
)
1675 struct breakpoint
*b
, *temp
;
1676 struct bp_location
*bpt
;
1678 ALL_BP_LOCATIONS (bpt
)
1681 ALL_BREAKPOINTS_SAFE (b
, temp
)
1686 case bp_watchpoint_scope
:
1688 /* If the call dummy breakpoint is at the entry point it will
1689 cause problems when the inferior is rerun, so we better
1692 Also get rid of scope breakpoints. */
1693 delete_breakpoint (b
);
1697 case bp_hardware_watchpoint
:
1698 case bp_read_watchpoint
:
1699 case bp_access_watchpoint
:
1701 /* Likewise for watchpoints on local expressions. */
1702 if (b
->exp_valid_block
!= NULL
)
1703 delete_breakpoint (b
);
1704 else if (context
== inf_starting
)
1706 /* Reset val field to force reread of starting value
1707 in insert_breakpoints. */
1709 value_free (b
->val
);
1719 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1720 exists at PC. It returns ordinary_breakpoint_here if it's an
1721 ordinary breakpoint, or permanent_breakpoint_here if it's a
1722 permanent breakpoint.
1723 - When continuing from a location with an ordinary breakpoint, we
1724 actually single step once before calling insert_breakpoints.
1725 - When continuing from a localion with a permanent breakpoint, we
1726 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1727 the target, to advance the PC past the breakpoint. */
1729 enum breakpoint_here
1730 breakpoint_here_p (CORE_ADDR pc
)
1732 const struct bp_location
*bpt
;
1733 int any_breakpoint_here
= 0;
1735 ALL_BP_LOCATIONS (bpt
)
1737 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1738 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1741 if ((breakpoint_enabled (bpt
->owner
)
1742 || bpt
->owner
->enable_state
== bp_permanent
)
1743 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1745 if (overlay_debugging
1746 && section_is_overlay (bpt
->section
)
1747 && !section_is_mapped (bpt
->section
))
1748 continue; /* unmapped overlay -- can't be a match */
1749 else if (bpt
->owner
->enable_state
== bp_permanent
)
1750 return permanent_breakpoint_here
;
1752 any_breakpoint_here
= 1;
1756 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1760 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1761 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1762 This does not check for single-step breakpoints, which are
1763 inserted and removed using direct target manipulation. */
1766 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1768 const struct bp_location
*bpt
;
1770 ALL_BP_LOCATIONS (bpt
)
1772 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1773 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1777 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1779 if (overlay_debugging
1780 && section_is_overlay (bpt
->section
)
1781 && !section_is_mapped (bpt
->section
))
1782 continue; /* unmapped overlay -- can't be a match */
1790 /* Returns non-zero iff there's either regular breakpoint
1791 or a single step breakpoint inserted at PC. */
1794 breakpoint_inserted_here_p (CORE_ADDR pc
)
1796 if (regular_breakpoint_inserted_here_p (pc
))
1799 if (single_step_breakpoint_inserted_here_p (pc
))
1805 /* This function returns non-zero iff there is a software breakpoint
1809 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1811 const struct bp_location
*bpt
;
1812 int any_breakpoint_here
= 0;
1814 ALL_BP_LOCATIONS (bpt
)
1816 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1820 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1822 if (overlay_debugging
1823 && section_is_overlay (bpt
->section
)
1824 && !section_is_mapped (bpt
->section
))
1825 continue; /* unmapped overlay -- can't be a match */
1831 /* Also check for software single-step breakpoints. */
1832 if (single_step_breakpoint_inserted_here_p (pc
))
1838 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1839 PC is valid for process/thread PTID. */
1842 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1844 const struct bp_location
*bpt
;
1847 thread
= pid_to_thread_id (ptid
);
1849 ALL_BP_LOCATIONS (bpt
)
1851 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1852 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1855 if ((breakpoint_enabled (bpt
->owner
)
1856 || bpt
->owner
->enable_state
== bp_permanent
)
1857 && bpt
->address
== pc
1858 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1860 if (overlay_debugging
1861 && section_is_overlay (bpt
->section
)
1862 && !section_is_mapped (bpt
->section
))
1863 continue; /* unmapped overlay -- can't be a match */
1873 /* bpstat stuff. External routines' interfaces are documented
1877 ep_is_catchpoint (struct breakpoint
*ep
)
1880 (ep
->type
== bp_catch_load
)
1881 || (ep
->type
== bp_catch_unload
)
1882 || (ep
->type
== bp_catch_fork
)
1883 || (ep
->type
== bp_catch_vfork
)
1884 || (ep
->type
== bp_catch_exec
)
1885 || (ep
->type
== bp_catch_catch
)
1886 || (ep
->type
== bp_catch_throw
);
1888 /* ??rehrauer: Add more kinds here, as are implemented... */
1892 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1895 (ep
->type
== bp_catch_load
)
1896 || (ep
->type
== bp_catch_unload
);
1900 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1903 (ep
->type
== bp_catch_catch
)
1904 || (ep
->type
== bp_catch_throw
);
1908 bpstat_free (bpstat bs
)
1910 if (bs
->old_val
!= NULL
)
1911 value_free (bs
->old_val
);
1912 free_command_lines (&bs
->commands
);
1916 /* Clear a bpstat so that it says we are not at any breakpoint.
1917 Also free any storage that is part of a bpstat. */
1920 bpstat_clear (bpstat
*bsp
)
1937 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1938 is part of the bpstat is copied as well. */
1941 bpstat_copy (bpstat bs
)
1945 bpstat retval
= NULL
;
1950 for (; bs
!= NULL
; bs
= bs
->next
)
1952 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1953 memcpy (tmp
, bs
, sizeof (*tmp
));
1954 if (bs
->commands
!= NULL
)
1955 tmp
->commands
= copy_command_lines (bs
->commands
);
1956 if (bs
->old_val
!= NULL
)
1957 tmp
->old_val
= value_copy (bs
->old_val
);
1960 /* This is the first thing in the chain. */
1970 /* Find the bpstat associated with this breakpoint */
1973 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1978 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1980 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
1986 /* Find a step_resume breakpoint associated with this bpstat.
1987 (If there are multiple step_resume bp's on the list, this function
1988 will arbitrarily pick one.)
1990 It is an error to use this function if BPSTAT doesn't contain a
1991 step_resume breakpoint.
1993 See wait_for_inferior's use of this function. */
1995 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1999 gdb_assert (bsp
!= NULL
);
2001 current_thread
= pid_to_thread_id (inferior_ptid
);
2003 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2005 if ((bsp
->breakpoint_at
!= NULL
) &&
2006 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2007 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2008 bsp
->breakpoint_at
->owner
->thread
== -1))
2009 return bsp
->breakpoint_at
->owner
;
2012 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2016 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2017 at. *BSP upon return is a bpstat which points to the remaining
2018 breakpoints stopped at (but which is not guaranteed to be good for
2019 anything but further calls to bpstat_num).
2020 Return 0 if passed a bpstat which does not indicate any breakpoints.
2021 Return -1 if stopped at a breakpoint that has been deleted since
2023 Return 1 otherwise. */
2026 bpstat_num (bpstat
*bsp
, int *num
)
2028 struct breakpoint
*b
;
2031 return 0; /* No more breakpoint values */
2033 /* We assume we'll never have several bpstats that
2034 correspond to a single breakpoint -- otherwise,
2035 this function might return the same number more
2036 than once and this will look ugly. */
2037 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2038 *bsp
= (*bsp
)->next
;
2040 return -1; /* breakpoint that's been deleted since */
2042 *num
= b
->number
; /* We have its number */
2046 /* Modify BS so that the actions will not be performed. */
2049 bpstat_clear_actions (bpstat bs
)
2051 for (; bs
!= NULL
; bs
= bs
->next
)
2053 free_command_lines (&bs
->commands
);
2054 if (bs
->old_val
!= NULL
)
2056 value_free (bs
->old_val
);
2062 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2064 cleanup_executing_breakpoints (void *ignore
)
2066 executing_breakpoint_commands
= 0;
2069 /* Execute all the commands associated with all the breakpoints at this
2070 location. Any of these commands could cause the process to proceed
2071 beyond this point, etc. We look out for such changes by checking
2072 the global "breakpoint_proceeded" after each command. */
2075 bpstat_do_actions (bpstat
*bsp
)
2078 struct cleanup
*old_chain
;
2080 /* Avoid endless recursion if a `source' command is contained
2082 if (executing_breakpoint_commands
)
2085 executing_breakpoint_commands
= 1;
2086 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2089 /* Note that (as of this writing), our callers all appear to
2090 be passing us the address of global stop_bpstat. And, if
2091 our calls to execute_control_command cause the inferior to
2092 proceed, that global (and hence, *bsp) will change.
2094 We must be careful to not touch *bsp unless the inferior
2095 has not proceeded. */
2097 /* This pointer will iterate over the list of bpstat's. */
2100 breakpoint_proceeded
= 0;
2101 for (; bs
!= NULL
; bs
= bs
->next
)
2103 struct command_line
*cmd
;
2104 struct cleanup
*this_cmd_tree_chain
;
2106 /* Take ownership of the BSP's command tree, if it has one.
2108 The command tree could legitimately contain commands like
2109 'step' and 'next', which call clear_proceed_status, which
2110 frees stop_bpstat's command tree. To make sure this doesn't
2111 free the tree we're executing out from under us, we need to
2112 take ownership of the tree ourselves. Since a given bpstat's
2113 commands are only executed once, we don't need to copy it; we
2114 can clear the pointer in the bpstat, and make sure we free
2115 the tree when we're done. */
2118 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2122 execute_control_command (cmd
);
2124 if (breakpoint_proceeded
)
2130 /* We can free this command tree now. */
2131 do_cleanups (this_cmd_tree_chain
);
2133 if (breakpoint_proceeded
)
2134 /* The inferior is proceeded by the command; bomb out now.
2135 The bpstat chain has been blown away by wait_for_inferior.
2136 But since execution has stopped again, there is a new bpstat
2137 to look at, so start over. */
2140 do_cleanups (old_chain
);
2143 /* This is the normal print function for a bpstat. In the future,
2144 much of this logic could (should?) be moved to bpstat_stop_status,
2145 by having it set different print_it values.
2147 Current scheme: When we stop, bpstat_print() is called. It loops
2148 through the bpstat list of things causing this stop, calling the
2149 print_bp_stop_message function on each one. The behavior of the
2150 print_bp_stop_message function depends on the print_it field of
2151 bpstat. If such field so indicates, call this function here.
2153 Return values from this routine (ultimately used by bpstat_print()
2154 and normal_stop() to decide what to do):
2155 PRINT_NOTHING: Means we already printed all we needed to print,
2156 don't print anything else.
2157 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2158 that something to be followed by a location.
2159 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2160 that something to be followed by a location.
2161 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2164 static enum print_stop_action
2165 print_it_typical (bpstat bs
)
2167 struct cleanup
*old_chain
, *ui_out_chain
;
2168 struct breakpoint
*b
;
2169 const struct bp_location
*bl
;
2170 struct ui_stream
*stb
;
2171 stb
= ui_out_stream_new (uiout
);
2172 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2173 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2174 which has since been deleted. */
2175 if (bs
->breakpoint_at
== NULL
)
2176 return PRINT_UNKNOWN
;
2177 bl
= bs
->breakpoint_at
;
2183 case bp_hardware_breakpoint
:
2184 if (bl
->address
!= bl
->requested_address
)
2185 breakpoint_adjustment_warning (bl
->requested_address
,
2188 annotate_breakpoint (b
->number
);
2189 ui_out_text (uiout
, "\nBreakpoint ");
2190 if (ui_out_is_mi_like_p (uiout
))
2191 ui_out_field_string (uiout
, "reason",
2192 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2193 ui_out_field_int (uiout
, "bkptno", b
->number
);
2194 ui_out_text (uiout
, ", ");
2195 return PRINT_SRC_AND_LOC
;
2198 case bp_shlib_event
:
2199 /* Did we stop because the user set the stop_on_solib_events
2200 variable? (If so, we report this as a generic, "Stopped due
2201 to shlib event" message.) */
2202 printf_filtered (_("Stopped due to shared library event\n"));
2203 return PRINT_NOTHING
;
2206 case bp_thread_event
:
2207 /* Not sure how we will get here.
2208 GDB should not stop for these breakpoints. */
2209 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2210 return PRINT_NOTHING
;
2213 case bp_overlay_event
:
2214 /* By analogy with the thread event, GDB should not stop for these. */
2215 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2216 return PRINT_NOTHING
;
2220 annotate_catchpoint (b
->number
);
2221 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2223 b
->triggered_dll_pathname
);
2224 return PRINT_SRC_AND_LOC
;
2227 case bp_catch_unload
:
2228 annotate_catchpoint (b
->number
);
2229 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2231 b
->triggered_dll_pathname
);
2232 return PRINT_SRC_AND_LOC
;
2236 annotate_catchpoint (b
->number
);
2237 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2239 b
->forked_inferior_pid
);
2240 return PRINT_SRC_AND_LOC
;
2243 case bp_catch_vfork
:
2244 annotate_catchpoint (b
->number
);
2245 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2247 b
->forked_inferior_pid
);
2248 return PRINT_SRC_AND_LOC
;
2252 annotate_catchpoint (b
->number
);
2253 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2256 return PRINT_SRC_AND_LOC
;
2259 case bp_catch_catch
:
2260 if (current_exception_event
&&
2261 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2263 annotate_catchpoint (b
->number
);
2264 printf_filtered (_("\nCatchpoint %d (exception caught), "),
2266 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2267 printf_filtered (_("throw location %s:%d, "),
2268 CURRENT_EXCEPTION_THROW_FILE
,
2269 CURRENT_EXCEPTION_THROW_LINE
);
2271 printf_filtered (_("throw location unknown, "));
2273 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2274 printf_filtered (_("catch location %s:%d\n"),
2275 CURRENT_EXCEPTION_CATCH_FILE
,
2276 CURRENT_EXCEPTION_CATCH_LINE
);
2278 printf_filtered (_("catch location unknown\n"));
2280 /* don't bother to print location frame info */
2281 return PRINT_SRC_ONLY
;
2285 /* really throw, some other bpstat will handle it */
2286 return PRINT_UNKNOWN
;
2290 case bp_catch_throw
:
2291 if (current_exception_event
&&
2292 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2294 annotate_catchpoint (b
->number
);
2295 printf_filtered (_("\nCatchpoint %d (exception thrown), "),
2297 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2298 printf_filtered (_("throw location %s:%d, "),
2299 CURRENT_EXCEPTION_THROW_FILE
,
2300 CURRENT_EXCEPTION_THROW_LINE
);
2302 printf_filtered (_("throw location unknown, "));
2304 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2305 printf_filtered (_("catch location %s:%d\n"),
2306 CURRENT_EXCEPTION_CATCH_FILE
,
2307 CURRENT_EXCEPTION_CATCH_LINE
);
2309 printf_filtered (_("catch location unknown\n"));
2311 /* don't bother to print location frame info */
2312 return PRINT_SRC_ONLY
;
2316 /* really catch, some other bpstat will handle it */
2317 return PRINT_UNKNOWN
;
2322 case bp_hardware_watchpoint
:
2323 if (bs
->old_val
!= NULL
)
2325 annotate_watchpoint (b
->number
);
2326 if (ui_out_is_mi_like_p (uiout
))
2329 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2331 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2332 ui_out_text (uiout
, "\nOld value = ");
2333 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2334 ui_out_field_stream (uiout
, "old", stb
);
2335 ui_out_text (uiout
, "\nNew value = ");
2336 value_print (b
->val
, stb
->stream
, 0, Val_pretty_default
);
2337 ui_out_field_stream (uiout
, "new", stb
);
2338 do_cleanups (ui_out_chain
);
2339 ui_out_text (uiout
, "\n");
2340 value_free (bs
->old_val
);
2343 /* More than one watchpoint may have been triggered. */
2344 return PRINT_UNKNOWN
;
2347 case bp_read_watchpoint
:
2348 if (ui_out_is_mi_like_p (uiout
))
2351 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2353 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2354 ui_out_text (uiout
, "\nValue = ");
2355 value_print (b
->val
, stb
->stream
, 0, Val_pretty_default
);
2356 ui_out_field_stream (uiout
, "value", stb
);
2357 do_cleanups (ui_out_chain
);
2358 ui_out_text (uiout
, "\n");
2359 return PRINT_UNKNOWN
;
2362 case bp_access_watchpoint
:
2363 if (bs
->old_val
!= NULL
)
2365 annotate_watchpoint (b
->number
);
2366 if (ui_out_is_mi_like_p (uiout
))
2369 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2371 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2372 ui_out_text (uiout
, "\nOld value = ");
2373 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2374 ui_out_field_stream (uiout
, "old", stb
);
2375 value_free (bs
->old_val
);
2377 ui_out_text (uiout
, "\nNew value = ");
2382 if (ui_out_is_mi_like_p (uiout
))
2385 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2386 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2387 ui_out_text (uiout
, "\nValue = ");
2389 value_print (b
->val
, stb
->stream
, 0,Val_pretty_default
);
2390 ui_out_field_stream (uiout
, "new", stb
);
2391 do_cleanups (ui_out_chain
);
2392 ui_out_text (uiout
, "\n");
2393 return PRINT_UNKNOWN
;
2396 /* Fall through, we don't deal with these types of breakpoints
2400 if (ui_out_is_mi_like_p (uiout
))
2403 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2404 return PRINT_UNKNOWN
;
2408 if (ui_out_is_mi_like_p (uiout
))
2411 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2412 return PRINT_UNKNOWN
;
2417 case bp_longjmp_resume
:
2418 case bp_step_resume
:
2419 case bp_watchpoint_scope
:
2422 return PRINT_UNKNOWN
;
2426 /* Generic routine for printing messages indicating why we
2427 stopped. The behavior of this function depends on the value
2428 'print_it' in the bpstat structure. Under some circumstances we
2429 may decide not to print anything here and delegate the task to
2432 static enum print_stop_action
2433 print_bp_stop_message (bpstat bs
)
2435 switch (bs
->print_it
)
2438 /* Nothing should be printed for this bpstat entry. */
2439 return PRINT_UNKNOWN
;
2443 /* We still want to print the frame, but we already printed the
2444 relevant messages. */
2445 return PRINT_SRC_AND_LOC
;
2448 case print_it_normal
:
2450 const struct bp_location
*bl
= bs
->breakpoint_at
;
2451 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2453 /* Normal case. Call the breakpoint's print_it method, or
2454 print_it_typical. */
2455 /* FIXME: how breakpoint can ever be NULL here? */
2456 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2457 return b
->ops
->print_it (b
);
2459 return print_it_typical (bs
);
2464 internal_error (__FILE__
, __LINE__
,
2465 _("print_bp_stop_message: unrecognized enum value"));
2470 /* Print a message indicating what happened. This is called from
2471 normal_stop(). The input to this routine is the head of the bpstat
2472 list - a list of the eventpoints that caused this stop. This
2473 routine calls the generic print routine for printing a message
2474 about reasons for stopping. This will print (for example) the
2475 "Breakpoint n," part of the output. The return value of this
2478 PRINT_UNKNOWN: Means we printed nothing
2479 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2480 code to print the location. An example is
2481 "Breakpoint 1, " which should be followed by
2483 PRINT_SRC_ONLY: Means we printed something, but there is no need
2484 to also print the location part of the message.
2485 An example is the catch/throw messages, which
2486 don't require a location appended to the end.
2487 PRINT_NOTHING: We have done some printing and we don't need any
2488 further info to be printed.*/
2490 enum print_stop_action
2491 bpstat_print (bpstat bs
)
2495 /* Maybe another breakpoint in the chain caused us to stop.
2496 (Currently all watchpoints go on the bpstat whether hit or not.
2497 That probably could (should) be changed, provided care is taken
2498 with respect to bpstat_explains_signal). */
2499 for (; bs
; bs
= bs
->next
)
2501 val
= print_bp_stop_message (bs
);
2502 if (val
== PRINT_SRC_ONLY
2503 || val
== PRINT_SRC_AND_LOC
2504 || val
== PRINT_NOTHING
)
2508 /* We reached the end of the chain, or we got a null BS to start
2509 with and nothing was printed. */
2510 return PRINT_UNKNOWN
;
2513 /* Evaluate the expression EXP and return 1 if value is zero.
2514 This is used inside a catch_errors to evaluate the breakpoint condition.
2515 The argument is a "struct expression *" that has been cast to char * to
2516 make it pass through catch_errors. */
2519 breakpoint_cond_eval (void *exp
)
2521 struct value
*mark
= value_mark ();
2522 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2523 value_free_to_mark (mark
);
2527 /* Allocate a new bpstat and chain it to the current one. */
2530 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2534 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2536 bs
->breakpoint_at
= bl
;
2537 /* If the condition is false, etc., don't do the commands. */
2538 bs
->commands
= NULL
;
2540 bs
->print_it
= print_it_normal
;
2544 /* The target has stopped with waitstatus WS. Check if any hardware
2545 watchpoints have triggered, according to the target. */
2548 watchpoints_triggered (struct target_waitstatus
*ws
)
2550 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2552 struct breakpoint
*b
;
2554 if (!stopped_by_watchpoint
)
2556 /* We were not stopped by a watchpoint. Mark all watchpoints
2557 as not triggered. */
2559 if (b
->type
== bp_hardware_watchpoint
2560 || b
->type
== bp_read_watchpoint
2561 || b
->type
== bp_access_watchpoint
)
2562 b
->watchpoint_triggered
= watch_triggered_no
;
2567 if (!target_stopped_data_address (¤t_target
, &addr
))
2569 /* We were stopped by a watchpoint, but we don't know where.
2570 Mark all watchpoints as unknown. */
2572 if (b
->type
== bp_hardware_watchpoint
2573 || b
->type
== bp_read_watchpoint
2574 || b
->type
== bp_access_watchpoint
)
2575 b
->watchpoint_triggered
= watch_triggered_unknown
;
2577 return stopped_by_watchpoint
;
2580 /* The target could report the data address. Mark watchpoints
2581 affected by this data address as triggered, and all others as not
2585 if (b
->type
== bp_hardware_watchpoint
2586 || b
->type
== bp_read_watchpoint
2587 || b
->type
== bp_access_watchpoint
)
2591 b
->watchpoint_triggered
= watch_triggered_no
;
2592 for (v
= b
->val_chain
; v
; v
= value_next (v
))
2594 if (VALUE_LVAL (v
) == lval_memory
&& ! value_lazy (v
))
2596 struct type
*vtype
= check_typedef (value_type (v
));
2598 if (v
== b
->val_chain
2599 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2600 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2604 vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
2605 /* Exact match not required. Within range is
2608 && addr
< vaddr
+ TYPE_LENGTH (value_type (v
)))
2610 b
->watchpoint_triggered
= watch_triggered_yes
;
2621 /* Possible return values for watchpoint_check (this can't be an enum
2622 because of check_errors). */
2623 /* The watchpoint has been deleted. */
2624 #define WP_DELETED 1
2625 /* The value has changed. */
2626 #define WP_VALUE_CHANGED 2
2627 /* The value has not changed. */
2628 #define WP_VALUE_NOT_CHANGED 3
2630 #define BP_TEMPFLAG 1
2631 #define BP_HARDWAREFLAG 2
2633 /* Check watchpoint condition. */
2636 watchpoint_check (void *p
)
2638 bpstat bs
= (bpstat
) p
;
2639 struct breakpoint
*b
;
2640 struct frame_info
*fr
;
2641 int within_current_scope
;
2643 b
= bs
->breakpoint_at
->owner
;
2645 if (b
->exp_valid_block
== NULL
)
2646 within_current_scope
= 1;
2649 /* There is no current frame at this moment. If we're going to have
2650 any chance of handling watchpoints on local variables, we'll need
2651 the frame chain (so we can determine if we're in scope). */
2652 reinit_frame_cache ();
2653 fr
= frame_find_by_id (b
->watchpoint_frame
);
2654 within_current_scope
= (fr
!= NULL
);
2656 /* If we've gotten confused in the unwinder, we might have
2657 returned a frame that can't describe this variable. */
2658 if (within_current_scope
2659 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2660 within_current_scope
= 0;
2662 /* in_function_epilogue_p() returns a non-zero value if we're still
2663 in the function but the stack frame has already been invalidated.
2664 Since we can't rely on the values of local variables after the
2665 stack has been destroyed, we are treating the watchpoint in that
2666 state as `not changed' without further checking.
2668 vinschen/2003-09-04: The former implementation left out the case
2669 that the watchpoint frame couldn't be found by frame_find_by_id()
2670 because the current PC is currently in an epilogue. Calling
2671 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2672 if ((!within_current_scope
|| fr
== get_current_frame ())
2673 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2674 return WP_VALUE_NOT_CHANGED
;
2675 if (fr
&& within_current_scope
)
2676 /* If we end up stopping, the current frame will get selected
2677 in normal_stop. So this call to select_frame won't affect
2682 if (within_current_scope
)
2684 /* We use value_{,free_to_}mark because it could be a
2685 *long* time before we return to the command level and
2686 call free_all_values. We can't call free_all_values because
2687 we might be in the middle of evaluating a function call. */
2689 struct value
*mark
= value_mark ();
2690 struct value
*new_val
= evaluate_expression (b
->exp
);
2691 if (!value_equal (b
->val
, new_val
))
2693 release_value (new_val
);
2694 value_free_to_mark (mark
);
2695 bs
->old_val
= b
->val
;
2697 /* We will stop here */
2698 return WP_VALUE_CHANGED
;
2702 /* Nothing changed, don't do anything. */
2703 value_free_to_mark (mark
);
2704 /* We won't stop here */
2705 return WP_VALUE_NOT_CHANGED
;
2710 /* This seems like the only logical thing to do because
2711 if we temporarily ignored the watchpoint, then when
2712 we reenter the block in which it is valid it contains
2713 garbage (in the case of a function, it may have two
2714 garbage values, one before and one after the prologue).
2715 So we can't even detect the first assignment to it and
2716 watch after that (since the garbage may or may not equal
2717 the first value assigned). */
2718 /* We print all the stop information in print_it_typical(), but
2719 in this case, by the time we call print_it_typical() this bp
2720 will be deleted already. So we have no choice but print the
2721 information here. */
2722 if (ui_out_is_mi_like_p (uiout
))
2724 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2725 ui_out_text (uiout
, "\nWatchpoint ");
2726 ui_out_field_int (uiout
, "wpnum", b
->number
);
2727 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2728 which its expression is valid.\n");
2730 if (b
->related_breakpoint
)
2731 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2732 b
->disposition
= disp_del_at_next_stop
;
2738 /* Get a bpstat associated with having just stopped at address
2739 BP_ADDR in thread PTID.
2741 Determine whether we stopped at a breakpoint, etc, or whether we
2742 don't understand this stop. Result is a chain of bpstat's such that:
2744 if we don't understand the stop, the result is a null pointer.
2746 if we understand why we stopped, the result is not null.
2748 Each element of the chain refers to a particular breakpoint or
2749 watchpoint at which we have stopped. (We may have stopped for
2750 several reasons concurrently.)
2752 Each element of the chain has valid next, breakpoint_at,
2753 commands, FIXME??? fields. */
2756 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2758 struct breakpoint
*b
= NULL
;
2759 const struct bp_location
*bl
;
2760 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2761 int real_breakpoint
= 0;
2762 /* Root of the chain of bpstat's */
2763 struct bpstats root_bs
[1];
2764 /* Pointer to the last thing in the chain currently. */
2765 bpstat bs
= root_bs
;
2766 int thread_id
= pid_to_thread_id (ptid
);
2768 ALL_BP_LOCATIONS (bl
)
2772 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2775 if (b
->type
!= bp_watchpoint
2776 && b
->type
!= bp_hardware_watchpoint
2777 && b
->type
!= bp_read_watchpoint
2778 && b
->type
!= bp_access_watchpoint
2779 && b
->type
!= bp_hardware_breakpoint
2780 && b
->type
!= bp_catch_fork
2781 && b
->type
!= bp_catch_vfork
2782 && b
->type
!= bp_catch_exec
2783 && b
->type
!= bp_catch_catch
2784 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2786 if (bl
->address
!= bp_addr
) /* address doesn't match */
2788 if (overlay_debugging
/* unmapped overlay section */
2789 && section_is_overlay (bl
->section
)
2790 && !section_is_mapped (bl
->section
))
2794 /* Continuable hardware watchpoints are treated as non-existent if the
2795 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2796 some data address). Otherwise gdb won't stop on a break instruction
2797 in the code (not from a breakpoint) when a hardware watchpoint has
2798 been defined. Also skip watchpoints which we know did not trigger
2799 (did not match the data address). */
2801 if ((b
->type
== bp_hardware_watchpoint
2802 || b
->type
== bp_read_watchpoint
2803 || b
->type
== bp_access_watchpoint
)
2804 && b
->watchpoint_triggered
== watch_triggered_no
)
2807 if (b
->type
== bp_hardware_breakpoint
)
2809 if (bl
->address
!= bp_addr
)
2811 if (overlay_debugging
/* unmapped overlay section */
2812 && section_is_overlay (bl
->section
)
2813 && !section_is_mapped (bl
->section
))
2817 /* Is this a catchpoint of a load or unload? If so, did we
2818 get a load or unload of the specified library? If not,
2820 if ((b
->type
== bp_catch_load
)
2821 #if defined(SOLIB_HAVE_LOAD_EVENT)
2822 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2823 || ((b
->dll_pathname
!= NULL
)
2824 && (strcmp (b
->dll_pathname
,
2825 SOLIB_LOADED_LIBRARY_PATHNAME (
2826 PIDGET (inferior_ptid
)))
2832 if ((b
->type
== bp_catch_unload
)
2833 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2834 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2835 || ((b
->dll_pathname
!= NULL
)
2836 && (strcmp (b
->dll_pathname
,
2837 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2838 PIDGET (inferior_ptid
)))
2844 if ((b
->type
== bp_catch_fork
)
2845 && !inferior_has_forked (PIDGET (inferior_ptid
),
2846 &b
->forked_inferior_pid
))
2849 if ((b
->type
== bp_catch_vfork
)
2850 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2851 &b
->forked_inferior_pid
))
2854 if ((b
->type
== bp_catch_exec
)
2855 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2858 if (ep_is_exception_catchpoint (b
) &&
2859 !(current_exception_event
= target_get_current_exception_event ()))
2862 /* Come here if it's a watchpoint, or if the break address matches */
2864 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
2866 /* Watchpoints may change this, if not found to have triggered. */
2870 if (b
->type
== bp_watchpoint
2871 || b
->type
== bp_read_watchpoint
2872 || b
->type
== bp_access_watchpoint
2873 || b
->type
== bp_hardware_watchpoint
)
2877 int must_check_value
= 0;
2879 if (b
->type
== bp_watchpoint
)
2880 /* For a software watchpoint, we must always check the
2882 must_check_value
= 1;
2883 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2884 /* We have a hardware watchpoint (read, write, or access)
2885 and the target earlier reported an address watched by
2887 must_check_value
= 1;
2888 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2889 && b
->type
== bp_hardware_watchpoint
)
2890 /* We were stopped by a hardware watchpoint, but the target could
2891 not report the data address. We must check the watchpoint's
2892 value. Access and read watchpoints are out of luck; without
2893 a data address, we can't figure it out. */
2894 must_check_value
= 1;
2896 if (must_check_value
)
2898 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2900 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2901 int e
= catch_errors (watchpoint_check
, bs
, message
,
2903 do_cleanups (cleanups
);
2907 /* We've already printed what needs to be printed. */
2908 bs
->print_it
= print_it_done
;
2911 case WP_VALUE_CHANGED
:
2912 if (b
->type
== bp_read_watchpoint
)
2914 /* Don't stop: read watchpoints shouldn't fire if
2915 the value has changed. This is for targets
2916 which cannot set read-only watchpoints. */
2917 bs
->print_it
= print_it_noop
;
2923 case WP_VALUE_NOT_CHANGED
:
2924 if (b
->type
== bp_hardware_watchpoint
2925 || b
->type
== bp_watchpoint
)
2927 /* Don't stop: write watchpoints shouldn't fire if
2928 the value hasn't changed. */
2929 bs
->print_it
= print_it_noop
;
2939 /* Error from catch_errors. */
2940 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2941 if (b
->related_breakpoint
)
2942 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2943 b
->disposition
= disp_del_at_next_stop
;
2944 /* We've already printed what needs to be printed. */
2945 bs
->print_it
= print_it_done
;
2949 else /* must_check_value == 0 */
2951 /* This is a case where some watchpoint(s) triggered, but
2952 not at the address of this watchpoint, or else no
2953 watchpoint triggered after all. So don't print
2954 anything for this watchpoint. */
2955 bs
->print_it
= print_it_noop
;
2962 /* By definition, an encountered breakpoint is a triggered
2966 real_breakpoint
= 1;
2969 if (frame_id_p (b
->frame_id
)
2970 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2974 int value_is_zero
= 0;
2976 /* If this is a scope breakpoint, mark the associated
2977 watchpoint as triggered so that we will handle the
2978 out-of-scope event. We'll get to the watchpoint next
2980 if (b
->type
== bp_watchpoint_scope
)
2981 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2985 /* Need to select the frame, with all that implies
2986 so that the conditions will have the right context. */
2987 select_frame (get_current_frame ());
2989 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2990 "Error in testing breakpoint condition:\n",
2992 /* FIXME-someday, should give breakpoint # */
2995 if (bl
->cond
&& value_is_zero
)
2998 /* Don't consider this a hit. */
3001 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3004 /* Don't consider this a hit. */
3007 else if (b
->ignore_count
> 0)
3010 annotate_ignore_count_change ();
3013 else if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3014 /* We do not stop for these. */
3018 /* We will stop here */
3019 if (b
->disposition
== disp_disable
)
3020 b
->enable_state
= bp_disabled
;
3023 bs
->commands
= b
->commands
;
3025 (strcmp ("silent", bs
->commands
->line
) == 0
3026 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3028 bs
->commands
= bs
->commands
->next
;
3031 bs
->commands
= copy_command_lines (bs
->commands
);
3034 /* Print nothing for this entry if we dont stop or if we dont print. */
3035 if (bs
->stop
== 0 || bs
->print
== 0)
3036 bs
->print_it
= print_it_noop
;
3039 bs
->next
= NULL
; /* Terminate the chain */
3040 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3042 /* If we aren't stopping, the value of some hardware watchpoint may
3043 not have changed, but the intermediate memory locations we are
3044 watching may have. Don't bother if we're stopping; this will get
3046 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3051 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3053 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3054 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3055 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3057 remove_breakpoints ();
3058 insert_breakpoints ();
3062 return root_bs
->next
;
3065 /* Tell what to do about this bpstat. */
3067 bpstat_what (bpstat bs
)
3069 /* Classify each bpstat as one of the following. */
3072 /* This bpstat element has no effect on the main_action. */
3075 /* There was a watchpoint, stop but don't print. */
3078 /* There was a watchpoint, stop and print. */
3081 /* There was a breakpoint but we're not stopping. */
3084 /* There was a breakpoint, stop but don't print. */
3087 /* There was a breakpoint, stop and print. */
3090 /* We hit the longjmp breakpoint. */
3093 /* We hit the longjmp_resume breakpoint. */
3096 /* We hit the step_resume breakpoint. */
3099 /* We hit the shared library event breakpoint. */
3102 /* We caught a shared library event. */
3105 /* This is just used to count how many enums there are. */
3109 /* Here is the table which drives this routine. So that we can
3110 format it pretty, we define some abbreviations for the
3111 enum bpstat_what codes. */
3112 #define kc BPSTAT_WHAT_KEEP_CHECKING
3113 #define ss BPSTAT_WHAT_STOP_SILENT
3114 #define sn BPSTAT_WHAT_STOP_NOISY
3115 #define sgl BPSTAT_WHAT_SINGLE
3116 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3117 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3118 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
3119 #define sr BPSTAT_WHAT_STEP_RESUME
3120 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3121 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3123 /* "Can't happen." Might want to print an error message.
3124 abort() is not out of the question, but chances are GDB is just
3125 a bit confused, not unusable. */
3126 #define err BPSTAT_WHAT_STOP_NOISY
3128 /* Given an old action and a class, come up with a new action. */
3129 /* One interesting property of this table is that wp_silent is the same
3130 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3131 after stopping, the check for whether to step over a breakpoint
3132 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3133 reference to how we stopped. We retain separate wp_silent and
3134 bp_silent codes in case we want to change that someday.
3136 Another possibly interesting property of this table is that
3137 there's a partial ordering, priority-like, of the actions. Once
3138 you've decided that some action is appropriate, you'll never go
3139 back and decide something of a lower priority is better. The
3142 kc < clr sgl shl shlr slr sn sr ss
3143 sgl < clrs shl shlr slr sn sr ss
3144 slr < err shl shlr sn sr ss
3145 clr < clrs err shl shlr sn sr ss
3146 clrs < err shl shlr sn sr ss
3153 What I think this means is that we don't need a damned table
3154 here. If you just put the rows and columns in the right order,
3155 it'd look awfully regular. We could simply walk the bpstat list
3156 and choose the highest priority action we find, with a little
3157 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3158 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3159 is messy anyway). */
3161 /* step_resume entries: a step resume breakpoint overrides another
3162 breakpoint of signal handling (see comment in wait_for_inferior
3163 at where we set the step_resume breakpoint). */
3165 static const enum bpstat_what_main_action
3166 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3169 /* kc ss sn sgl slr clr clrs sr shl shlr
3172 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, shl
, shlr
},
3174 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3176 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3178 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, shl
, shlr
},
3180 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3182 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3184 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, shl
, shlr
},
3186 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, shl
, shlr
},
3188 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3190 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3192 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3207 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3208 struct bpstat_what retval
;
3210 retval
.call_dummy
= 0;
3211 for (; bs
!= NULL
; bs
= bs
->next
)
3213 enum class bs_class
= no_effect
;
3214 if (bs
->breakpoint_at
== NULL
)
3215 /* I suspect this can happen if it was a momentary breakpoint
3216 which has since been deleted. */
3218 switch (bs
->breakpoint_at
->owner
->type
)
3224 case bp_hardware_breakpoint
:
3230 bs_class
= bp_noisy
;
3232 bs_class
= bp_silent
;
3235 bs_class
= bp_nostop
;
3238 case bp_hardware_watchpoint
:
3239 case bp_read_watchpoint
:
3240 case bp_access_watchpoint
:
3244 bs_class
= wp_noisy
;
3246 bs_class
= wp_silent
;
3249 /* There was a watchpoint, but we're not stopping.
3250 This requires no further action. */
3251 bs_class
= no_effect
;
3254 bs_class
= long_jump
;
3256 case bp_longjmp_resume
:
3257 bs_class
= long_resume
;
3259 case bp_step_resume
:
3262 bs_class
= step_resume
;
3265 /* It is for the wrong frame. */
3266 bs_class
= bp_nostop
;
3268 case bp_watchpoint_scope
:
3269 bs_class
= bp_nostop
;
3271 case bp_shlib_event
:
3272 bs_class
= shlib_event
;
3274 case bp_thread_event
:
3275 case bp_overlay_event
:
3276 bs_class
= bp_nostop
;
3279 case bp_catch_unload
:
3280 /* Only if this catchpoint triggered should we cause the
3281 step-out-of-dld behaviour. Otherwise, we ignore this
3284 bs_class
= catch_shlib_event
;
3286 bs_class
= no_effect
;
3289 case bp_catch_vfork
:
3294 bs_class
= bp_noisy
;
3296 bs_class
= bp_silent
;
3299 /* There was a catchpoint, but we're not stopping.
3300 This requires no further action. */
3301 bs_class
= no_effect
;
3303 case bp_catch_catch
:
3304 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
3305 bs_class
= bp_nostop
;
3307 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3309 case bp_catch_throw
:
3310 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3311 bs_class
= bp_nostop
;
3313 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3316 /* Make sure the action is stop (silent or noisy),
3317 so infrun.c pops the dummy frame. */
3318 bs_class
= bp_silent
;
3319 retval
.call_dummy
= 1;
3322 current_action
= table
[(int) bs_class
][(int) current_action
];
3324 retval
.main_action
= current_action
;
3328 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3329 without hardware support). This isn't related to a specific bpstat,
3330 just to things like whether watchpoints are set. */
3333 bpstat_should_step (void)
3335 struct breakpoint
*b
;
3337 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3342 /* Nonzero if there are enabled hardware watchpoints. */
3344 bpstat_have_active_hw_watchpoints (void)
3346 const struct bp_location
*bpt
;
3347 ALL_BP_LOCATIONS (bpt
)
3348 if (breakpoint_enabled (bpt
->owner
)
3350 && bpt
->loc_type
== bp_loc_hardware_watchpoint
)
3356 /* Given a bpstat that records zero or more triggered eventpoints, this
3357 function returns another bpstat which contains only the catchpoints
3358 on that first list, if any. */
3360 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3362 struct bpstats root_bs
[1];
3363 bpstat bs
= root_bs
;
3364 struct breakpoint
*ep
;
3367 bpstat_clear (cp_list
);
3368 root_bs
->next
= NULL
;
3370 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3372 /* Is this eventpoint a catchpoint? If not, ignore it. */
3373 ep
= ep_list
->breakpoint_at
->owner
;
3376 if ((ep
->type
!= bp_catch_load
) &&
3377 (ep
->type
!= bp_catch_unload
) &&
3378 (ep
->type
!= bp_catch_catch
) &&
3379 (ep
->type
!= bp_catch_throw
))
3380 /* pai: (temp) ADD fork/vfork here!! */
3383 /* Yes; add it to the list. */
3384 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3389 #if defined(SOLIB_ADD)
3390 /* Also, for each triggered catchpoint, tag it with the name of
3391 the library that caused this trigger. (We copy the name now,
3392 because it's only guaranteed to be available NOW, when the
3393 catchpoint triggers. Clients who may wish to know the name
3394 later must get it from the catchpoint itself.) */
3395 if (ep
->triggered_dll_pathname
!= NULL
)
3396 xfree (ep
->triggered_dll_pathname
);
3397 if (ep
->type
== bp_catch_load
)
3398 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3399 PIDGET (inferior_ptid
));
3401 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3402 PIDGET (inferior_ptid
));
3404 dll_pathname
= NULL
;
3408 ep
->triggered_dll_pathname
= (char *)
3409 xmalloc (strlen (dll_pathname
) + 1);
3410 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3413 ep
->triggered_dll_pathname
= NULL
;
3419 static void print_breakpoint_location (struct breakpoint
*b
,
3420 struct bp_location
*loc
,
3422 struct ui_stream
*stb
)
3427 = find_pc_sect_function (loc
->address
, loc
->section
);
3430 ui_out_text (uiout
, "in ");
3431 ui_out_field_string (uiout
, "func",
3432 SYMBOL_PRINT_NAME (sym
));
3433 ui_out_wrap_hint (uiout
, wrap_indent
);
3434 ui_out_text (uiout
, " at ");
3436 ui_out_field_string (uiout
, "file", b
->source_file
);
3437 ui_out_text (uiout
, ":");
3439 if (ui_out_is_mi_like_p (uiout
))
3441 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3442 char *fullname
= symtab_to_fullname (sal
.symtab
);
3445 ui_out_field_string (uiout
, "fullname", fullname
);
3448 ui_out_field_int (uiout
, "line", b
->line_number
);
3452 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3456 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3457 ui_out_field_stream (uiout
, "at", stb
);
3461 /* Print B to gdb_stdout. */
3463 print_one_breakpoint_location (struct breakpoint
*b
,
3464 struct bp_location
*loc
,
3466 CORE_ADDR
*last_addr
)
3468 struct command_line
*l
;
3470 struct ep_type_description
3475 static struct ep_type_description bptypes
[] =
3477 {bp_none
, "?deleted?"},
3478 {bp_breakpoint
, "breakpoint"},
3479 {bp_hardware_breakpoint
, "hw breakpoint"},
3480 {bp_until
, "until"},
3481 {bp_finish
, "finish"},
3482 {bp_watchpoint
, "watchpoint"},
3483 {bp_hardware_watchpoint
, "hw watchpoint"},
3484 {bp_read_watchpoint
, "read watchpoint"},
3485 {bp_access_watchpoint
, "acc watchpoint"},
3486 {bp_longjmp
, "longjmp"},
3487 {bp_longjmp_resume
, "longjmp resume"},
3488 {bp_step_resume
, "step resume"},
3489 {bp_watchpoint_scope
, "watchpoint scope"},
3490 {bp_call_dummy
, "call dummy"},
3491 {bp_shlib_event
, "shlib events"},
3492 {bp_thread_event
, "thread events"},
3493 {bp_overlay_event
, "overlay events"},
3494 {bp_catch_load
, "catch load"},
3495 {bp_catch_unload
, "catch unload"},
3496 {bp_catch_fork
, "catch fork"},
3497 {bp_catch_vfork
, "catch vfork"},
3498 {bp_catch_exec
, "catch exec"},
3499 {bp_catch_catch
, "catch catch"},
3500 {bp_catch_throw
, "catch throw"}
3503 static char *bpdisps
[] =
3504 {"del", "dstp", "dis", "keep"};
3505 static char bpenables
[] = "nynny";
3506 char wrap_indent
[80];
3507 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3508 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3509 struct cleanup
*bkpt_chain
;
3511 int header_of_multiple
= 0;
3512 int part_of_multiple
= (loc
!= NULL
);
3514 gdb_assert (!loc
|| loc_number
!= 0);
3515 /* See comment in print_one_breakpoint concerning
3516 treatment of breakpoints with single disabled
3520 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3521 header_of_multiple
= 1;
3526 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3530 if (part_of_multiple
)
3533 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3534 ui_out_field_string (uiout
, "number", formatted
);
3539 ui_out_field_int (uiout
, "number", b
->number
);
3544 if (part_of_multiple
)
3545 ui_out_field_skip (uiout
, "type");
3548 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3549 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3550 internal_error (__FILE__
, __LINE__
,
3551 _("bptypes table does not describe type #%d."),
3553 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3558 if (part_of_multiple
)
3559 ui_out_field_skip (uiout
, "disp");
3561 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3566 if (part_of_multiple
)
3567 ui_out_field_string (uiout
, "enabled",
3569 ? (loc
->enabled
? "y(p)" : "n(p)")
3570 : (loc
->enabled
? "y" : "n"));
3573 int pending
= (b
->loc
== NULL
|| b
->loc
->shlib_disabled
);
3574 /* For header of multiple, there's no point showing pending
3575 state -- it will be apparent from the locations. */
3576 if (header_of_multiple
)
3578 ui_out_field_fmt (uiout
, "enabled", "%c%s",
3579 bpenables
[(int) b
->enable_state
],
3580 pending
? "(p)" : "");
3582 ui_out_spaces (uiout
, 3);
3587 strcpy (wrap_indent
, " ");
3590 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3591 strcat (wrap_indent
, " ");
3593 strcat (wrap_indent
, " ");
3596 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3598 /* Although the print_one can possibly print
3599 all locations, calling it here is not likely
3600 to get any nice result. So, make sure there's
3601 just one location. */
3602 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3603 b
->ops
->print_one (b
, last_addr
);
3609 internal_error (__FILE__
, __LINE__
,
3610 _("print_one_breakpoint: bp_none encountered\n"));
3614 case bp_hardware_watchpoint
:
3615 case bp_read_watchpoint
:
3616 case bp_access_watchpoint
:
3617 /* Field 4, the address, is omitted (which makes the columns
3618 not line up too nicely with the headers, but the effect
3619 is relatively readable). */
3621 ui_out_field_skip (uiout
, "addr");
3623 print_expression (b
->exp
, stb
->stream
);
3624 ui_out_field_stream (uiout
, "what", stb
);
3628 case bp_catch_unload
:
3629 /* Field 4, the address, is omitted (which makes the columns
3630 not line up too nicely with the headers, but the effect
3631 is relatively readable). */
3633 ui_out_field_skip (uiout
, "addr");
3635 if (b
->dll_pathname
== NULL
)
3637 ui_out_field_string (uiout
, "what", "<any library>");
3638 ui_out_spaces (uiout
, 1);
3642 ui_out_text (uiout
, "library \"");
3643 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3644 ui_out_text (uiout
, "\" ");
3649 case bp_catch_vfork
:
3650 /* Field 4, the address, is omitted (which makes the columns
3651 not line up too nicely with the headers, but the effect
3652 is relatively readable). */
3654 ui_out_field_skip (uiout
, "addr");
3656 if (b
->forked_inferior_pid
!= 0)
3658 ui_out_text (uiout
, "process ");
3659 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3660 ui_out_spaces (uiout
, 1);
3665 /* Field 4, the address, is omitted (which makes the columns
3666 not line up too nicely with the headers, but the effect
3667 is relatively readable). */
3669 ui_out_field_skip (uiout
, "addr");
3671 if (b
->exec_pathname
!= NULL
)
3673 ui_out_text (uiout
, "program \"");
3674 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3675 ui_out_text (uiout
, "\" ");
3679 case bp_catch_catch
:
3680 /* Field 4, the address, is omitted (which makes the columns
3681 not line up too nicely with the headers, but the effect
3682 is relatively readable). */
3684 ui_out_field_skip (uiout
, "addr");
3686 ui_out_field_string (uiout
, "what", "exception catch");
3687 ui_out_spaces (uiout
, 1);
3690 case bp_catch_throw
:
3691 /* Field 4, the address, is omitted (which makes the columns
3692 not line up too nicely with the headers, but the effect
3693 is relatively readable). */
3695 ui_out_field_skip (uiout
, "addr");
3697 ui_out_field_string (uiout
, "what", "exception throw");
3698 ui_out_spaces (uiout
, 1);
3702 case bp_hardware_breakpoint
:
3706 case bp_longjmp_resume
:
3707 case bp_step_resume
:
3708 case bp_watchpoint_scope
:
3710 case bp_shlib_event
:
3711 case bp_thread_event
:
3712 case bp_overlay_event
:
3717 ui_out_field_string (uiout
, "addr", "<PENDING>");
3718 else if (header_of_multiple
)
3719 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3721 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3724 if (!header_of_multiple
)
3725 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3727 *last_addr
= b
->loc
->address
;
3731 if (!part_of_multiple
&& b
->thread
!= -1)
3733 /* FIXME: This seems to be redundant and lost here; see the
3734 "stop only in" line a little further down. */
3735 ui_out_text (uiout
, " thread ");
3736 ui_out_field_int (uiout
, "thread", b
->thread
);
3739 ui_out_text (uiout
, "\n");
3741 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3744 ui_out_text (uiout
, "\tstop only in stack frame at ");
3745 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3747 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3748 ui_out_text (uiout
, "\n");
3751 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3753 /* We do not print the condition for Ada exception catchpoints
3754 because the condition is an internal implementation detail
3755 that we do not want to expose to the user. */
3757 ui_out_text (uiout
, "\tstop only if ");
3758 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3759 ui_out_text (uiout
, "\n");
3762 if (!part_of_multiple
&& b
->thread
!= -1)
3764 /* FIXME should make an annotation for this */
3765 ui_out_text (uiout
, "\tstop only in thread ");
3766 ui_out_field_int (uiout
, "thread", b
->thread
);
3767 ui_out_text (uiout
, "\n");
3770 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3772 /* FIXME should make an annotation for this */
3773 if (ep_is_catchpoint (b
))
3774 ui_out_text (uiout
, "\tcatchpoint");
3776 ui_out_text (uiout
, "\tbreakpoint");
3777 ui_out_text (uiout
, " already hit ");
3778 ui_out_field_int (uiout
, "times", b
->hit_count
);
3779 if (b
->hit_count
== 1)
3780 ui_out_text (uiout
, " time\n");
3782 ui_out_text (uiout
, " times\n");
3785 /* Output the count also if it is zero, but only if this is
3786 mi. FIXME: Should have a better test for this. */
3787 if (ui_out_is_mi_like_p (uiout
))
3788 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3789 ui_out_field_int (uiout
, "times", b
->hit_count
);
3791 if (!part_of_multiple
&& b
->ignore_count
)
3794 ui_out_text (uiout
, "\tignore next ");
3795 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3796 ui_out_text (uiout
, " hits\n");
3799 if (!part_of_multiple
&& (l
= b
->commands
))
3801 struct cleanup
*script_chain
;
3804 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3805 print_command_lines (uiout
, l
, 4);
3806 do_cleanups (script_chain
);
3808 do_cleanups (bkpt_chain
);
3809 do_cleanups (old_chain
);
3813 print_one_breakpoint (struct breakpoint
*b
,
3814 CORE_ADDR
*last_addr
)
3816 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3818 /* If this breakpoint has custom print function,
3819 it's already printed. Otherwise, print individual
3820 locations, if any. */
3821 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3823 /* If breakpoint has a single location that is
3824 disabled, we print it as if it had
3825 several locations, since otherwise it's hard to
3826 represent "breakpoint enabled, location disabled"
3829 && (b
->loc
->next
|| !b
->loc
->enabled
)
3830 && !ui_out_is_mi_like_p (uiout
))
3832 struct bp_location
*loc
;
3834 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3835 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3841 struct captured_breakpoint_query_args
3847 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3849 struct captured_breakpoint_query_args
*args
= data
;
3850 struct breakpoint
*b
;
3851 CORE_ADDR dummy_addr
= 0;
3854 if (args
->bnum
== b
->number
)
3856 print_one_breakpoint (b
, &dummy_addr
);
3864 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3866 struct captured_breakpoint_query_args args
;
3868 /* For the moment we don't trust print_one_breakpoint() to not throw
3870 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3871 error_message
, RETURN_MASK_ALL
) < 0)
3877 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3878 catchpoints, et.al.). */
3881 user_settable_breakpoint (const struct breakpoint
*b
)
3883 return (b
->type
== bp_breakpoint
3884 || b
->type
== bp_catch_load
3885 || b
->type
== bp_catch_unload
3886 || b
->type
== bp_catch_fork
3887 || b
->type
== bp_catch_vfork
3888 || b
->type
== bp_catch_exec
3889 || b
->type
== bp_catch_catch
3890 || b
->type
== bp_catch_throw
3891 || b
->type
== bp_hardware_breakpoint
3892 || b
->type
== bp_watchpoint
3893 || b
->type
== bp_read_watchpoint
3894 || b
->type
== bp_access_watchpoint
3895 || b
->type
== bp_hardware_watchpoint
);
3898 /* Print information on user settable breakpoint (watchpoint, etc)
3899 number BNUM. If BNUM is -1 print all user settable breakpoints.
3900 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3903 breakpoint_1 (int bnum
, int allflag
)
3905 struct breakpoint
*b
;
3906 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3907 int nr_printable_breakpoints
;
3908 struct cleanup
*bkpttbl_chain
;
3910 /* Compute the number of rows in the table. */
3911 nr_printable_breakpoints
= 0;
3914 || bnum
== b
->number
)
3916 if (allflag
|| user_settable_breakpoint (b
))
3917 nr_printable_breakpoints
++;
3922 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3926 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3929 if (nr_printable_breakpoints
> 0)
3930 annotate_breakpoints_headers ();
3931 if (nr_printable_breakpoints
> 0)
3933 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3934 if (nr_printable_breakpoints
> 0)
3936 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3937 if (nr_printable_breakpoints
> 0)
3939 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3940 if (nr_printable_breakpoints
> 0)
3942 ui_out_table_header (uiout
, 4, ui_left
, "enabled", "Enb"); /* 4 */
3945 if (nr_printable_breakpoints
> 0)
3947 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3948 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3950 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3952 if (nr_printable_breakpoints
> 0)
3954 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3955 ui_out_table_body (uiout
);
3956 if (nr_printable_breakpoints
> 0)
3957 annotate_breakpoints_table ();
3961 || bnum
== b
->number
)
3963 /* We only print out user settable breakpoints unless the
3965 if (allflag
|| user_settable_breakpoint (b
))
3966 print_one_breakpoint (b
, &last_addr
);
3969 do_cleanups (bkpttbl_chain
);
3971 if (nr_printable_breakpoints
== 0)
3974 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3976 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3981 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3982 that a comparison of an unsigned with -1 is always false. */
3983 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3984 set_next_address (last_addr
);
3987 /* FIXME? Should this be moved up so that it is only called when
3988 there have been breakpoints? */
3989 annotate_breakpoints_table_end ();
3993 breakpoints_info (char *bnum_exp
, int from_tty
)
3998 bnum
= parse_and_eval_long (bnum_exp
);
4000 breakpoint_1 (bnum
, 0);
4004 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4009 bnum
= parse_and_eval_long (bnum_exp
);
4011 breakpoint_1 (bnum
, 1);
4015 breakpoint_has_pc (struct breakpoint
*b
, CORE_ADDR pc
, asection
*section
)
4017 struct bp_location
*bl
= b
->loc
;
4018 for (; bl
; bl
= bl
->next
)
4020 if (bl
->address
== pc
4021 && (!overlay_debugging
|| bl
->section
== section
))
4027 /* Print a message describing any breakpoints set at PC. */
4030 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
4033 struct breakpoint
*b
;
4036 others
+= breakpoint_has_pc (b
, pc
, section
);
4040 printf_filtered (_("Note: breakpoint "));
4041 else /* if (others == ???) */
4042 printf_filtered (_("Note: breakpoints "));
4044 if (breakpoint_has_pc (b
, pc
, section
))
4047 printf_filtered ("%d", b
->number
);
4048 if (b
->thread
== -1 && thread
!= -1)
4049 printf_filtered (" (all threads)");
4050 else if (b
->thread
!= -1)
4051 printf_filtered (" (thread %d)", b
->thread
);
4052 printf_filtered ("%s%s ",
4053 ((b
->enable_state
== bp_disabled
||
4054 b
->enable_state
== bp_call_disabled
)
4056 : b
->enable_state
== bp_permanent
4060 : ((others
== 1) ? " and" : ""));
4062 printf_filtered (_("also set at pc "));
4063 deprecated_print_address_numeric (pc
, 1, gdb_stdout
);
4064 printf_filtered (".\n");
4068 /* Set the default place to put a breakpoint
4069 for the `break' command with no arguments. */
4072 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4075 default_breakpoint_valid
= valid
;
4076 default_breakpoint_address
= addr
;
4077 default_breakpoint_symtab
= symtab
;
4078 default_breakpoint_line
= line
;
4081 /* Return true iff it is meaningful to use the address member of
4082 BPT. For some breakpoint types, the address member is irrelevant
4083 and it makes no sense to attempt to compare it to other addresses
4084 (or use it for any other purpose either).
4086 More specifically, each of the following breakpoint types will always
4087 have a zero valued address and we don't want check_duplicates() to mark
4088 breakpoints of any of these types to be a duplicate of an actual
4089 breakpoint at address zero:
4092 bp_hardware_watchpoint
4094 bp_access_watchpoint
4101 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4103 enum bptype type
= bpt
->type
;
4105 return (type
!= bp_watchpoint
4106 && type
!= bp_hardware_watchpoint
4107 && type
!= bp_read_watchpoint
4108 && type
!= bp_access_watchpoint
4109 && type
!= bp_catch_exec
4110 && type
!= bp_longjmp_resume
4111 && type
!= bp_catch_fork
4112 && type
!= bp_catch_vfork
);
4115 /* Rescan breakpoints at the same address and section as BPT,
4116 marking the first one as "first" and any others as "duplicates".
4117 This is so that the bpt instruction is only inserted once.
4118 If we have a permanent breakpoint at the same place as BPT, make
4119 that one the official one, and the rest as duplicates. */
4122 check_duplicates_for (CORE_ADDR address
, asection
*section
)
4124 struct bp_location
*b
;
4126 struct bp_location
*perm_bp
= 0;
4128 ALL_BP_LOCATIONS (b
)
4129 if (b
->owner
->enable_state
!= bp_disabled
4130 && b
->owner
->enable_state
!= bp_call_disabled
4132 && !b
->shlib_disabled
4133 && b
->address
== address
/* address / overlay match */
4134 && (!overlay_debugging
|| b
->section
== section
)
4135 && breakpoint_address_is_meaningful (b
->owner
))
4137 /* Have we found a permanent breakpoint? */
4138 if (b
->owner
->enable_state
== bp_permanent
)
4145 b
->duplicate
= count
> 1;
4148 /* If we found a permanent breakpoint at this address, go over the
4149 list again and declare all the other breakpoints there to be the
4153 perm_bp
->duplicate
= 0;
4155 /* Permanent breakpoint should always be inserted. */
4156 if (! perm_bp
->inserted
)
4157 internal_error (__FILE__
, __LINE__
,
4158 _("allegedly permanent breakpoint is not "
4159 "actually inserted"));
4161 ALL_BP_LOCATIONS (b
)
4164 if (b
->owner
->enable_state
!= bp_disabled
4165 && b
->owner
->enable_state
!= bp_call_disabled
4166 && b
->enabled
&& !b
->shlib_disabled
4167 && b
->address
== address
/* address / overlay match */
4168 && (!overlay_debugging
|| b
->section
== section
)
4169 && breakpoint_address_is_meaningful (b
->owner
))
4172 internal_error (__FILE__
, __LINE__
,
4173 _("another breakpoint was inserted on top of "
4174 "a permanent breakpoint"));
4183 check_duplicates (struct breakpoint
*bpt
)
4185 struct bp_location
*bl
= bpt
->loc
;
4187 if (! breakpoint_address_is_meaningful (bpt
))
4190 for (; bl
; bl
= bl
->next
)
4191 check_duplicates_for (bl
->address
, bl
->section
);
4195 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4196 int bnum
, int have_bnum
)
4201 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4202 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4204 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4205 bnum
, astr1
, astr2
);
4207 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4210 /* Adjust a breakpoint's address to account for architectural constraints
4211 on breakpoint placement. Return the adjusted address. Note: Very
4212 few targets require this kind of adjustment. For most targets,
4213 this function is simply the identity function. */
4216 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4218 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4220 /* Very few targets need any kind of breakpoint adjustment. */
4223 else if (bptype
== bp_watchpoint
4224 || bptype
== bp_hardware_watchpoint
4225 || bptype
== bp_read_watchpoint
4226 || bptype
== bp_access_watchpoint
4227 || bptype
== bp_catch_fork
4228 || bptype
== bp_catch_vfork
4229 || bptype
== bp_catch_exec
)
4231 /* Watchpoints and the various bp_catch_* eventpoints should not
4232 have their addresses modified. */
4237 CORE_ADDR adjusted_bpaddr
;
4239 /* Some targets have architectural constraints on the placement
4240 of breakpoint instructions. Obtain the adjusted address. */
4241 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4244 /* An adjusted breakpoint address can significantly alter
4245 a user's expectations. Print a warning if an adjustment
4247 if (adjusted_bpaddr
!= bpaddr
)
4248 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4250 return adjusted_bpaddr
;
4254 /* Allocate a struct bp_location. */
4256 static struct bp_location
*
4257 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4259 struct bp_location
*loc
, *loc_p
;
4261 loc
= xmalloc (sizeof (struct bp_location
));
4262 memset (loc
, 0, sizeof (*loc
));
4266 loc
->shlib_disabled
= 0;
4275 case bp_longjmp_resume
:
4276 case bp_step_resume
:
4277 case bp_watchpoint_scope
:
4279 case bp_shlib_event
:
4280 case bp_thread_event
:
4281 case bp_overlay_event
:
4283 case bp_catch_unload
:
4284 loc
->loc_type
= bp_loc_software_breakpoint
;
4286 case bp_hardware_breakpoint
:
4287 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4289 case bp_hardware_watchpoint
:
4290 case bp_read_watchpoint
:
4291 case bp_access_watchpoint
:
4292 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4296 case bp_catch_vfork
:
4298 case bp_catch_catch
:
4299 case bp_catch_throw
:
4300 loc
->loc_type
= bp_loc_other
;
4303 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4306 /* Add this breakpoint to the end of the chain. */
4308 loc_p
= bp_location_chain
;
4310 bp_location_chain
= loc
;
4313 while (loc_p
->global_next
)
4314 loc_p
= loc_p
->global_next
;
4315 loc_p
->global_next
= loc
;
4321 static void free_bp_location (struct bp_location
*loc
)
4328 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4329 that has type BPTYPE and has no locations as yet. */
4331 static struct breakpoint
*
4332 set_raw_breakpoint_without_location (enum bptype bptype
)
4334 struct breakpoint
*b
, *b1
;
4336 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4337 memset (b
, 0, sizeof (*b
));
4340 b
->language
= current_language
->la_language
;
4341 b
->input_radix
= input_radix
;
4343 b
->enable_state
= bp_enabled
;
4346 b
->ignore_count
= 0;
4348 b
->frame_id
= null_frame_id
;
4349 b
->dll_pathname
= NULL
;
4350 b
->triggered_dll_pathname
= NULL
;
4351 b
->forked_inferior_pid
= 0;
4352 b
->exec_pathname
= NULL
;
4354 b
->condition_not_parsed
= 0;
4356 /* Add this breakpoint to the end of the chain
4357 so that a list of breakpoints will come out in order
4358 of increasing numbers. */
4360 b1
= breakpoint_chain
;
4362 breakpoint_chain
= b
;
4372 /* Initialize loc->function_name. */
4374 set_breakpoint_location_function (struct bp_location
*loc
)
4376 if (loc
->owner
->type
== bp_breakpoint
4377 || loc
->owner
->type
== bp_hardware_breakpoint
)
4379 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4381 if (loc
->function_name
)
4382 loc
->function_name
= xstrdup (loc
->function_name
);
4386 /* set_raw_breakpoint is a low level routine for allocating and
4387 partially initializing a breakpoint of type BPTYPE. The newly
4388 created breakpoint's address, section, source file name, and line
4389 number are provided by SAL. The newly created and partially
4390 initialized breakpoint is added to the breakpoint chain and
4391 is also returned as the value of this function.
4393 It is expected that the caller will complete the initialization of
4394 the newly created breakpoint struct as well as output any status
4395 information regarding the creation of a new breakpoint. In
4396 particular, set_raw_breakpoint does NOT set the breakpoint
4397 number! Care should be taken to not allow an error to occur
4398 prior to completing the initialization of the breakpoint. If this
4399 should happen, a bogus breakpoint will be left on the chain. */
4402 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4404 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4405 CORE_ADDR adjusted_address
;
4407 /* Adjust the breakpoint's address prior to allocating a location.
4408 Once we call allocate_bp_location(), that mostly uninitialized
4409 location will be placed on the location chain. Adjustment of the
4410 breakpoint may cause read_memory_nobpt() to be called and we do
4411 not want its scan of the location chain to find a breakpoint and
4412 location that's only been partially initialized. */
4413 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4415 b
->loc
= allocate_bp_location (b
, bptype
);
4416 b
->loc
->requested_address
= sal
.pc
;
4417 b
->loc
->address
= adjusted_address
;
4419 if (sal
.symtab
== NULL
)
4420 b
->source_file
= NULL
;
4422 b
->source_file
= savestring (sal
.symtab
->filename
,
4423 strlen (sal
.symtab
->filename
));
4424 b
->loc
->section
= sal
.section
;
4425 b
->line_number
= sal
.line
;
4427 set_breakpoint_location_function (b
->loc
);
4429 check_duplicates (b
);
4430 breakpoints_changed ();
4436 /* Note that the breakpoint object B describes a permanent breakpoint
4437 instruction, hard-wired into the inferior's code. */
4439 make_breakpoint_permanent (struct breakpoint
*b
)
4441 struct bp_location
*bl
;
4442 b
->enable_state
= bp_permanent
;
4444 /* By definition, permanent breakpoints are already present in the code.
4445 Mark all locations as inserted. For now, make_breakpoint_permanent
4446 is called in just one place, so it's hard to say if it's reasonable
4447 to have permanent breakpoint with multiple locations or not,
4448 but it's easy to implmement. */
4449 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4453 static struct breakpoint
*
4454 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4456 static int internal_breakpoint_number
= -1;
4457 struct symtab_and_line sal
;
4458 struct breakpoint
*b
;
4460 init_sal (&sal
); /* initialize to zeroes */
4463 sal
.section
= find_pc_overlay (sal
.pc
);
4465 b
= set_raw_breakpoint (sal
, type
);
4466 b
->number
= internal_breakpoint_number
--;
4467 b
->disposition
= disp_donttouch
;
4474 create_longjmp_breakpoint (char *func_name
)
4476 struct breakpoint
*b
;
4477 struct minimal_symbol
*m
;
4479 if (func_name
== NULL
)
4480 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4483 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4486 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4489 b
->enable_state
= bp_disabled
;
4492 b
->addr_string
= xstrdup (func_name
);
4495 /* Call this routine when stepping and nexting to enable a breakpoint
4496 if we do a longjmp(). When we hit that breakpoint, call
4497 set_longjmp_resume_breakpoint() to figure out where we are going. */
4500 enable_longjmp_breakpoint (void)
4502 struct breakpoint
*b
;
4505 if (b
->type
== bp_longjmp
)
4507 b
->enable_state
= bp_enabled
;
4508 check_duplicates (b
);
4513 disable_longjmp_breakpoint (void)
4515 struct breakpoint
*b
;
4518 if (b
->type
== bp_longjmp
4519 || b
->type
== bp_longjmp_resume
)
4521 b
->enable_state
= bp_disabled
;
4522 check_duplicates (b
);
4527 create_overlay_event_breakpoint (char *func_name
)
4529 struct breakpoint
*b
;
4530 struct minimal_symbol
*m
;
4532 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4535 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4537 b
->addr_string
= xstrdup (func_name
);
4539 if (overlay_debugging
== ovly_auto
)
4541 b
->enable_state
= bp_enabled
;
4542 overlay_events_enabled
= 1;
4546 b
->enable_state
= bp_disabled
;
4547 overlay_events_enabled
= 0;
4552 enable_overlay_breakpoints (void)
4554 struct breakpoint
*b
;
4557 if (b
->type
== bp_overlay_event
)
4559 b
->enable_state
= bp_enabled
;
4560 check_duplicates (b
);
4561 overlay_events_enabled
= 1;
4566 disable_overlay_breakpoints (void)
4568 struct breakpoint
*b
;
4571 if (b
->type
== bp_overlay_event
)
4573 b
->enable_state
= bp_disabled
;
4574 check_duplicates (b
);
4575 overlay_events_enabled
= 0;
4580 create_thread_event_breakpoint (CORE_ADDR address
)
4582 struct breakpoint
*b
;
4584 b
= create_internal_breakpoint (address
, bp_thread_event
);
4586 b
->enable_state
= bp_enabled
;
4587 /* addr_string has to be used or breakpoint_re_set will delete me. */
4588 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4594 remove_thread_event_breakpoints (void)
4596 struct breakpoint
*b
, *temp
;
4598 ALL_BREAKPOINTS_SAFE (b
, temp
)
4599 if (b
->type
== bp_thread_event
)
4600 delete_breakpoint (b
);
4603 struct captured_parse_breakpoint_args
4606 struct symtabs_and_lines
*sals_p
;
4607 char ***addr_string_p
;
4611 struct lang_and_radix
4619 remove_solib_event_breakpoints (void)
4621 struct breakpoint
*b
, *temp
;
4623 ALL_BREAKPOINTS_SAFE (b
, temp
)
4624 if (b
->type
== bp_shlib_event
)
4625 delete_breakpoint (b
);
4629 create_solib_event_breakpoint (CORE_ADDR address
)
4631 struct breakpoint
*b
;
4633 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4637 /* Disable any breakpoints that are on code in shared libraries. Only
4638 apply to enabled breakpoints, disabled ones can just stay disabled. */
4641 disable_breakpoints_in_shlibs (void)
4643 struct bp_location
*loc
;
4644 int disabled_shlib_breaks
= 0;
4646 ALL_BP_LOCATIONS (loc
)
4648 struct breakpoint
*b
= loc
->owner
;
4649 /* We apply the check to all breakpoints, including disabled
4650 for those with loc->duplicate set. This is so that when breakpoint
4651 becomes enabled, or the duplicate is removed, gdb will try to insert
4652 all breakpoints. If we don't set shlib_disabled here, we'll try
4653 to insert those breakpoints and fail. */
4654 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4655 && !loc
->shlib_disabled
4657 && PC_SOLIB (loc
->address
)
4659 && solib_address (loc
->address
)
4663 loc
->shlib_disabled
= 1;
4668 /* Disable any breakpoints that are in in an unloaded shared library. Only
4669 apply to enabled breakpoints, disabled ones can just stay disabled. */
4672 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4674 struct bp_location
*loc
;
4675 int disabled_shlib_breaks
= 0;
4677 ALL_BP_LOCATIONS (loc
)
4679 struct breakpoint
*b
= loc
->owner
;
4680 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4681 || loc
->loc_type
== bp_loc_software_breakpoint
)
4682 && !loc
->shlib_disabled
)
4685 char *so_name
= PC_SOLIB (loc
->address
);
4687 char *so_name
= solib_address (loc
->address
);
4689 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4691 loc
->shlib_disabled
= 1;
4692 /* At this point, we cannot rely on remove_breakpoint
4693 succeeding so we must mark the breakpoint as not inserted
4694 to prevent future errors occurring in remove_breakpoints. */
4696 if (!disabled_shlib_breaks
)
4698 target_terminal_ours_for_output ();
4699 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4702 disabled_shlib_breaks
= 1;
4709 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4710 enum bptype bp_kind
)
4712 struct symtab_and_line sal
;
4713 struct breakpoint
*b
;
4714 int thread
= -1; /* All threads. */
4721 b
= set_raw_breakpoint (sal
, bp_kind
);
4722 set_breakpoint_count (breakpoint_count
+ 1);
4723 b
->number
= breakpoint_count
;
4724 b
->cond_string
= (cond_string
== NULL
) ?
4725 NULL
: savestring (cond_string
, strlen (cond_string
));
4727 b
->addr_string
= NULL
;
4728 b
->enable_state
= bp_enabled
;
4729 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4730 b
->forked_inferior_pid
= 0;
4736 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4738 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4742 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4744 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4748 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4750 struct symtab_and_line sal
;
4751 struct breakpoint
*b
;
4752 int thread
= -1; /* All threads. */
4759 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4760 set_breakpoint_count (breakpoint_count
+ 1);
4761 b
->number
= breakpoint_count
;
4762 b
->cond_string
= (cond_string
== NULL
) ?
4763 NULL
: savestring (cond_string
, strlen (cond_string
));
4765 b
->addr_string
= NULL
;
4766 b
->enable_state
= bp_enabled
;
4767 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4773 hw_breakpoint_used_count (void)
4775 struct breakpoint
*b
;
4780 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4788 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4790 struct breakpoint
*b
;
4793 *other_type_used
= 0;
4796 if (breakpoint_enabled (b
))
4798 if (b
->type
== type
)
4800 else if ((b
->type
== bp_hardware_watchpoint
||
4801 b
->type
== bp_read_watchpoint
||
4802 b
->type
== bp_access_watchpoint
))
4803 *other_type_used
= 1;
4809 /* Call this after hitting the longjmp() breakpoint. Use this to set
4810 a new breakpoint at the target of the jmp_buf.
4812 FIXME - This ought to be done by setting a temporary breakpoint
4813 that gets deleted automatically... */
4816 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4818 struct breakpoint
*b
;
4821 if (b
->type
== bp_longjmp_resume
)
4823 b
->loc
->requested_address
= pc
;
4824 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4826 b
->enable_state
= bp_enabled
;
4827 b
->frame_id
= frame_id
;
4828 check_duplicates (b
);
4834 disable_watchpoints_before_interactive_call_start (void)
4836 struct breakpoint
*b
;
4840 if (((b
->type
== bp_watchpoint
)
4841 || (b
->type
== bp_hardware_watchpoint
)
4842 || (b
->type
== bp_read_watchpoint
)
4843 || (b
->type
== bp_access_watchpoint
)
4844 || ep_is_exception_catchpoint (b
))
4845 && breakpoint_enabled (b
))
4847 b
->enable_state
= bp_call_disabled
;
4848 check_duplicates (b
);
4854 enable_watchpoints_after_interactive_call_stop (void)
4856 struct breakpoint
*b
;
4860 if (((b
->type
== bp_watchpoint
)
4861 || (b
->type
== bp_hardware_watchpoint
)
4862 || (b
->type
== bp_read_watchpoint
)
4863 || (b
->type
== bp_access_watchpoint
)
4864 || ep_is_exception_catchpoint (b
))
4865 && (b
->enable_state
== bp_call_disabled
))
4867 b
->enable_state
= bp_enabled
;
4868 check_duplicates (b
);
4874 /* Set a breakpoint that will evaporate an end of command
4875 at address specified by SAL.
4876 Restrict it to frame FRAME if FRAME is nonzero. */
4879 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4882 struct breakpoint
*b
;
4883 b
= set_raw_breakpoint (sal
, type
);
4884 b
->enable_state
= bp_enabled
;
4885 b
->disposition
= disp_donttouch
;
4886 b
->frame_id
= frame_id
;
4888 /* If we're debugging a multi-threaded program, then we
4889 want momentary breakpoints to be active in only a
4890 single thread of control. */
4891 if (in_thread_list (inferior_ptid
))
4892 b
->thread
= pid_to_thread_id (inferior_ptid
);
4898 /* Tell the user we have just set a breakpoint B. */
4901 mention (struct breakpoint
*b
)
4904 struct cleanup
*old_chain
, *ui_out_chain
;
4905 struct ui_stream
*stb
;
4907 stb
= ui_out_stream_new (uiout
);
4908 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4910 /* FIXME: This is misplaced; mention() is called by things (like
4911 hitting a watchpoint) other than breakpoint creation. It should
4912 be possible to clean this up and at the same time replace the
4913 random calls to breakpoint_changed with this hook, as has already
4914 been done for deprecated_delete_breakpoint_hook and so on. */
4915 if (deprecated_create_breakpoint_hook
)
4916 deprecated_create_breakpoint_hook (b
);
4917 breakpoint_create_event (b
->number
);
4919 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4920 b
->ops
->print_mention (b
);
4925 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4928 ui_out_text (uiout
, "Watchpoint ");
4929 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4930 ui_out_field_int (uiout
, "number", b
->number
);
4931 ui_out_text (uiout
, ": ");
4932 print_expression (b
->exp
, stb
->stream
);
4933 ui_out_field_stream (uiout
, "exp", stb
);
4934 do_cleanups (ui_out_chain
);
4936 case bp_hardware_watchpoint
:
4937 ui_out_text (uiout
, "Hardware watchpoint ");
4938 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4939 ui_out_field_int (uiout
, "number", b
->number
);
4940 ui_out_text (uiout
, ": ");
4941 print_expression (b
->exp
, stb
->stream
);
4942 ui_out_field_stream (uiout
, "exp", stb
);
4943 do_cleanups (ui_out_chain
);
4945 case bp_read_watchpoint
:
4946 ui_out_text (uiout
, "Hardware read watchpoint ");
4947 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4948 ui_out_field_int (uiout
, "number", b
->number
);
4949 ui_out_text (uiout
, ": ");
4950 print_expression (b
->exp
, stb
->stream
);
4951 ui_out_field_stream (uiout
, "exp", stb
);
4952 do_cleanups (ui_out_chain
);
4954 case bp_access_watchpoint
:
4955 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4956 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4957 ui_out_field_int (uiout
, "number", b
->number
);
4958 ui_out_text (uiout
, ": ");
4959 print_expression (b
->exp
, stb
->stream
);
4960 ui_out_field_stream (uiout
, "exp", stb
);
4961 do_cleanups (ui_out_chain
);
4964 if (ui_out_is_mi_like_p (uiout
))
4969 printf_filtered (_("Breakpoint %d"), b
->number
);
4972 case bp_hardware_breakpoint
:
4973 if (ui_out_is_mi_like_p (uiout
))
4978 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4982 case bp_catch_unload
:
4983 printf_filtered (_("Catchpoint %d (%s %s)"),
4985 (b
->type
== bp_catch_load
) ? "load" : "unload",
4986 (b
->dll_pathname
!= NULL
) ?
4987 b
->dll_pathname
: "<any library>");
4990 case bp_catch_vfork
:
4991 printf_filtered (_("Catchpoint %d (%s)"),
4993 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4996 printf_filtered (_("Catchpoint %d (exec)"),
4999 case bp_catch_catch
:
5000 case bp_catch_throw
:
5001 printf_filtered (_("Catchpoint %d (%s)"),
5003 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
5009 case bp_longjmp_resume
:
5010 case bp_step_resume
:
5012 case bp_watchpoint_scope
:
5013 case bp_shlib_event
:
5014 case bp_thread_event
:
5015 case bp_overlay_event
:
5021 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5025 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5029 if (addressprint
|| b
->source_file
== NULL
)
5031 printf_filtered (" at ");
5032 deprecated_print_address_numeric (b
->loc
->address
, 1, gdb_stdout
);
5035 printf_filtered (": file %s, line %d.",
5036 b
->source_file
, b
->line_number
);
5040 struct bp_location
*loc
= b
->loc
;
5042 for (; loc
; loc
= loc
->next
)
5044 printf_filtered (" (%d locations)", n
);
5049 do_cleanups (old_chain
);
5050 if (ui_out_is_mi_like_p (uiout
))
5052 printf_filtered ("\n");
5056 static struct bp_location
*
5057 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5058 const struct symtab_and_line
*sal
)
5060 struct bp_location
*loc
, **tmp
;
5062 loc
= allocate_bp_location (b
, bptype
);
5063 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5066 loc
->requested_address
= sal
->pc
;
5067 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5069 loc
->section
= sal
->section
;
5071 set_breakpoint_location_function (loc
);
5075 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5076 as textual description of the location, and COND_STRING
5077 as condition expression. */
5080 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5082 enum bptype type
, enum bpdisp disposition
,
5083 int thread
, int ignore_count
, int from_tty
)
5085 struct breakpoint
*b
= NULL
;
5088 if (type
== bp_hardware_breakpoint
)
5090 int i
= hw_breakpoint_used_count ();
5091 int target_resources_ok
=
5092 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5094 if (target_resources_ok
== 0)
5095 error (_("No hardware breakpoint support in the target."));
5096 else if (target_resources_ok
< 0)
5097 error (_("Hardware breakpoints used exceeds limit."));
5100 for (i
= 0; i
< sals
.nelts
; ++i
)
5102 struct symtab_and_line sal
= sals
.sals
[i
];
5103 struct bp_location
*loc
;
5106 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5110 b
= set_raw_breakpoint (sal
, type
);
5111 set_breakpoint_count (breakpoint_count
+ 1);
5112 b
->number
= breakpoint_count
;
5115 b
->cond_string
= cond_string
;
5116 b
->ignore_count
= ignore_count
;
5117 b
->enable_state
= bp_enabled
;
5118 b
->disposition
= disposition
;
5124 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5129 char *arg
= b
->cond_string
;
5130 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5132 error (_("Garbage %s follows condition"), arg
);
5137 b
->addr_string
= addr_string
;
5139 /* addr_string has to be used or breakpoint_re_set will delete
5141 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5146 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5147 elements to fill the void space. */
5148 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5150 int i
= index_to_remove
+1;
5151 int last_index
= sal
->nelts
-1;
5153 for (;i
<= last_index
; ++i
)
5154 sal
->sals
[i
-1] = sal
->sals
[i
];
5159 /* If appropriate, obtains all sals that correspond
5160 to the same file and line as SAL. This is done
5161 only if SAL does not have explicit PC and has
5162 line and file information. If we got just a single
5163 expanded sal, return the original.
5165 Otherwise, if SAL.explicit_line is not set, filter out
5166 all sals for which the name of enclosing function
5167 is different from SAL. This makes sure that if we have
5168 breakpoint originally set in template instantiation, say
5169 foo<int>(), we won't expand SAL to locations at the same
5170 line in all existing instantiations of 'foo'.
5173 struct symtabs_and_lines
5174 expand_line_sal_maybe (struct symtab_and_line sal
)
5176 struct symtabs_and_lines expanded
;
5177 CORE_ADDR original_pc
= sal
.pc
;
5178 char *original_function
= NULL
;
5182 /* If we have explicit pc, don't expand.
5183 If we have no line number, we can't expand. */
5184 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5187 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5188 expanded
.sals
[0] = sal
;
5193 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5195 expanded
= expand_line_sal (sal
);
5196 if (expanded
.nelts
== 1)
5198 /* We had one sal, we got one sal. Without futher
5199 processing, just return the original sal. */
5200 xfree (expanded
.sals
);
5202 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5203 sal
.pc
= original_pc
;
5204 expanded
.sals
[0] = sal
;
5208 if (!sal
.explicit_line
)
5210 CORE_ADDR func_addr
, func_end
;
5211 for (i
= 0; i
< expanded
.nelts
; ++i
)
5213 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5214 char *this_function
;
5215 if (find_pc_partial_function (pc
, &this_function
,
5216 &func_addr
, &func_end
))
5218 if (this_function
&&
5219 strcmp (this_function
, original_function
) != 0)
5221 remove_sal (&expanded
, i
);
5224 else if (func_addr
== pc
)
5226 /* We're at beginning of a function, and should
5228 struct symbol
*sym
= find_pc_function (pc
);
5230 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5233 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5240 if (expanded
.nelts
<= 1)
5242 /* This is un ugly workaround. If we get zero
5243 expanded sals then something is really wrong.
5244 Fix that by returnign the original sal. */
5245 xfree (expanded
.sals
);
5247 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5248 sal
.pc
= original_pc
;
5249 expanded
.sals
[0] = sal
;
5256 for (i
= 0; i
< expanded
.nelts
; ++i
)
5257 if (expanded
.sals
[i
].pc
== original_pc
)
5268 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5269 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5270 value. COND_STRING, if not NULL, specified the condition to be
5271 used for all breakpoints. Essentially the only case where
5272 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5273 function. In that case, it's still not possible to specify
5274 separate conditions for different overloaded functions, so
5275 we take just a single condition string.
5277 NOTE: If the function succeeds, the caller is expected to cleanup
5278 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5279 array contents). If the function fails (error() is called), the
5280 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5281 COND and SALS arrays and each of those arrays contents. */
5284 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5286 enum bptype type
, enum bpdisp disposition
,
5287 int thread
, int ignore_count
, int from_tty
)
5290 for (i
= 0; i
< sals
.nelts
; ++i
)
5292 struct symtabs_and_lines expanded
=
5293 expand_line_sal_maybe (sals
.sals
[i
]);
5295 create_breakpoint (expanded
, addr_string
[i
],
5296 cond_string
, type
, disposition
,
5297 thread
, ignore_count
, from_tty
);
5301 /* Parse ARG which is assumed to be a SAL specification possibly
5302 followed by conditionals. On return, SALS contains an array of SAL
5303 addresses found. ADDR_STRING contains a vector of (canonical)
5304 address strings. ARG points to the end of the SAL. */
5307 parse_breakpoint_sals (char **address
,
5308 struct symtabs_and_lines
*sals
,
5309 char ***addr_string
,
5312 char *addr_start
= *address
;
5313 *addr_string
= NULL
;
5314 /* If no arg given, or if first arg is 'if ', use the default
5316 if ((*address
) == NULL
5317 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5319 if (default_breakpoint_valid
)
5321 struct symtab_and_line sal
;
5322 init_sal (&sal
); /* initialize to zeroes */
5323 sals
->sals
= (struct symtab_and_line
*)
5324 xmalloc (sizeof (struct symtab_and_line
));
5325 sal
.pc
= default_breakpoint_address
;
5326 sal
.line
= default_breakpoint_line
;
5327 sal
.symtab
= default_breakpoint_symtab
;
5328 sal
.section
= find_pc_overlay (sal
.pc
);
5329 sals
->sals
[0] = sal
;
5333 error (_("No default breakpoint address now."));
5337 /* Force almost all breakpoints to be in terms of the
5338 current_source_symtab (which is decode_line_1's default). This
5339 should produce the results we want almost all of the time while
5340 leaving default_breakpoint_* alone.
5341 ObjC: However, don't match an Objective-C method name which
5342 may have a '+' or '-' succeeded by a '[' */
5344 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5346 if (default_breakpoint_valid
5348 || ((strchr ("+-", (*address
)[0]) != NULL
)
5349 && ((*address
)[1] != '['))))
5350 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5351 default_breakpoint_line
, addr_string
,
5354 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5355 addr_string
, not_found_ptr
);
5357 /* For any SAL that didn't have a canonical string, fill one in. */
5358 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5359 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5360 if (addr_start
!= (*address
))
5363 for (i
= 0; i
< sals
->nelts
; i
++)
5365 /* Add the string if not present. */
5366 if ((*addr_string
)[i
] == NULL
)
5367 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5373 /* Convert each SAL into a real PC. Verify that the PC can be
5374 inserted as a breakpoint. If it can't throw an error. */
5377 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5381 for (i
= 0; i
< sals
->nelts
; i
++)
5382 resolve_sal_pc (&sals
->sals
[i
]);
5386 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5388 struct captured_parse_breakpoint_args
*args
= data
;
5390 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5391 args
->not_found_ptr
);
5394 /* Given TOK, a string specification of condition and thread, as
5395 accepted by the 'break' command, extract the condition
5396 string and thread number and set *COND_STRING and *THREAD.
5397 PC identifies the context at which the condition should be parsed.
5398 If no condition is found, *COND_STRING is set to NULL.
5399 If no thread is found, *THREAD is set to -1. */
5401 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5402 char **cond_string
, int *thread
)
5404 *cond_string
= NULL
;
5410 char *cond_start
= NULL
;
5411 char *cond_end
= NULL
;
5412 while (*tok
== ' ' || *tok
== '\t')
5417 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5420 toklen
= end_tok
- tok
;
5422 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5424 tok
= cond_start
= end_tok
+ 1;
5425 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5427 *cond_string
= savestring (cond_start
,
5428 cond_end
- cond_start
);
5430 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5436 *thread
= strtol (tok
, &tok
, 0);
5438 error (_("Junk after thread keyword."));
5439 if (!valid_thread_id (*thread
))
5440 error (_("Unknown thread %d."), *thread
);
5443 error (_("Junk at end of arguments."));
5447 /* Set a breakpoint according to ARG (function, linenum or *address)
5448 flag: first bit : 0 non-temporary, 1 temporary.
5449 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
5452 break_command_1 (char *arg
, int flag
, int from_tty
)
5454 struct gdb_exception e
;
5455 int tempflag
, hardwareflag
;
5456 struct symtabs_and_lines sals
;
5457 struct symtab_and_line pending_sal
;
5458 char *cond_string
= NULL
;
5461 char *addr_start
= arg
;
5463 struct cleanup
*old_chain
;
5464 struct cleanup
*breakpoint_chain
= NULL
;
5465 struct captured_parse_breakpoint_args parse_args
;
5469 int ignore_count
= 0;
5472 hardwareflag
= flag
& BP_HARDWAREFLAG
;
5473 tempflag
= flag
& BP_TEMPFLAG
;
5479 parse_args
.arg_p
= &arg
;
5480 parse_args
.sals_p
= &sals
;
5481 parse_args
.addr_string_p
= &addr_string
;
5482 parse_args
.not_found_ptr
= ¬_found
;
5484 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5485 &parse_args
, RETURN_MASK_ALL
);
5487 /* If caller is interested in rc value from parse, set value. */
5491 exception_print (gdb_stderr
, e
);
5496 case NOT_FOUND_ERROR
:
5498 exception_print (gdb_stderr
, e
);
5500 /* If pending breakpoint support is turned off, throw
5503 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5504 deprecated_throw_reason (RETURN_ERROR
);
5506 /* If pending breakpoint support is auto query and the user
5507 selects no, then simply return the error code. */
5508 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5509 !nquery ("Make breakpoint pending on future shared library load? "))
5512 /* At this point, either the user was queried about setting
5513 a pending breakpoint and selected yes, or pending
5514 breakpoint behavior is on and thus a pending breakpoint
5515 is defaulted on behalf of the user. */
5516 copy_arg
= xstrdup (addr_start
);
5517 addr_string
= ©_arg
;
5519 sals
.sals
= &pending_sal
;
5524 exception_print (gdb_stderr
, e
);
5532 /* Create a chain of things that always need to be cleaned up. */
5533 old_chain
= make_cleanup (null_cleanup
, 0);
5537 /* Make sure that all storage allocated to SALS gets freed. */
5538 make_cleanup (xfree
, sals
.sals
);
5540 /* Cleanup the addr_string array but not its contents. */
5541 make_cleanup (xfree
, addr_string
);
5544 /* ----------------------------- SNIP -----------------------------
5545 Anything added to the cleanup chain beyond this point is assumed
5546 to be part of a breakpoint. If the breakpoint create succeeds
5547 then the memory is not reclaimed. */
5548 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5550 /* Mark the contents of the addr_string for cleanup. These go on
5551 the breakpoint_chain and only occure if the breakpoint create
5553 for (i
= 0; i
< sals
.nelts
; i
++)
5555 if (addr_string
[i
] != NULL
)
5556 make_cleanup (xfree
, addr_string
[i
]);
5559 /* Resolve all line numbers to PC's and verify that the addresses
5560 are ok for the target. */
5562 breakpoint_sals_to_pc (&sals
, addr_start
);
5564 /* Verify that condition can be parsed, before setting any
5565 breakpoints. Allocate a separate condition expression for each
5569 /* Here we only parse 'arg' to separate condition
5570 from thread number, so parsing in context of first
5571 sal is OK. When setting the breakpoint we'll
5572 re-parse it in context of each sal. */
5573 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5575 make_cleanup (xfree
, cond_string
);
5576 create_breakpoints (sals
, addr_string
, cond_string
,
5577 hardwareflag
? bp_hardware_breakpoint
5579 tempflag
? disp_del
: disp_donttouch
,
5580 thread
, ignore_count
, from_tty
);
5584 struct symtab_and_line sal
= {0};
5585 struct breakpoint
*b
;
5587 make_cleanup (xfree
, copy_arg
);
5589 b
= set_raw_breakpoint_without_location (hardwareflag
5590 ? bp_hardware_breakpoint
5592 set_breakpoint_count (breakpoint_count
+ 1);
5593 b
->number
= breakpoint_count
;
5595 b
->addr_string
= addr_string
[0];
5596 b
->cond_string
= cond_string
;
5597 b
->ignore_count
= ignore_count
;
5598 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5599 b
->condition_not_parsed
= 1;
5604 warning (_("Multiple breakpoints were set.\n"
5605 "Use the \"delete\" command to delete unwanted breakpoints."));
5606 /* That's it. Discard the cleanups for data inserted into the
5608 discard_cleanups (breakpoint_chain
);
5609 /* But cleanup everything else. */
5610 do_cleanups (old_chain
);
5615 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5616 linenum or *address) with COND and IGNORE_COUNT. */
5618 struct captured_breakpoint_args
5629 do_captured_breakpoint (struct ui_out
*uiout
, void *data
)
5631 struct captured_breakpoint_args
*args
= data
;
5632 struct symtabs_and_lines sals
;
5633 struct expression
**cond
;
5634 struct cleanup
*old_chain
;
5635 struct cleanup
*breakpoint_chain
= NULL
;
5638 char *cond_string
= 0;
5642 /* Parse the source and lines spec. Delay check that the expression
5643 didn't contain trailing garbage until after cleanups are in
5647 address_end
= args
->address
;
5649 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
, 0);
5654 /* Create a chain of things at always need to be cleaned up. */
5655 old_chain
= make_cleanup (null_cleanup
, 0);
5657 /* Always have a addr_string array, even if it is empty. */
5658 make_cleanup (xfree
, addr_string
);
5660 /* Make sure that all storage allocated to SALS gets freed. */
5661 make_cleanup (xfree
, sals
.sals
);
5663 /* Allocate space for all the cond expressions. */
5664 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5665 make_cleanup (xfree
, cond
);
5667 /* ----------------------------- SNIP -----------------------------
5668 Anything added to the cleanup chain beyond this point is assumed
5669 to be part of a breakpoint. If the breakpoint create goes
5670 through then that memory is not cleaned up. */
5671 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5673 /* Mark the contents of the addr_string for cleanup. These go on
5674 the breakpoint_chain and only occure if the breakpoint create
5676 for (i
= 0; i
< sals
.nelts
; i
++)
5678 if (addr_string
[i
] != NULL
)
5679 make_cleanup (xfree
, addr_string
[i
]);
5682 /* Wait until now before checking for garbage at the end of the
5683 address. That way cleanups can take care of freeing any
5685 if (*address_end
!= '\0')
5686 error (_("Garbage %s following breakpoint address"), address_end
);
5688 /* Resolve all line numbers to PC's. */
5689 breakpoint_sals_to_pc (&sals
, args
->address
);
5691 if (args
->condition
!= NULL
)
5693 cond_string
= xstrdup (args
->condition
);
5694 make_cleanup (xfree
, cond_string
);
5697 create_breakpoints (sals
, addr_string
, args
->condition
,
5698 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
5699 args
->tempflag
? disp_del
: disp_donttouch
,
5700 args
->thread
, args
->ignore_count
, 0/*from-tty*/);
5702 /* That's it. Discard the cleanups for data inserted into the
5704 discard_cleanups (breakpoint_chain
);
5705 /* But cleanup everything else. */
5706 do_cleanups (old_chain
);
5711 gdb_breakpoint (char *address
, char *condition
,
5712 int hardwareflag
, int tempflag
,
5713 int thread
, int ignore_count
,
5714 char **error_message
)
5716 struct captured_breakpoint_args args
;
5717 args
.address
= address
;
5718 args
.condition
= condition
;
5719 args
.hardwareflag
= hardwareflag
;
5720 args
.tempflag
= tempflag
;
5721 args
.thread
= thread
;
5722 args
.ignore_count
= ignore_count
;
5723 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint
, &args
,
5724 error_message
, RETURN_MASK_ALL
) < 0)
5731 /* Helper function for break_command_1 and disassemble_command. */
5734 resolve_sal_pc (struct symtab_and_line
*sal
)
5738 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5740 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5741 error (_("No line %d in file \"%s\"."),
5742 sal
->line
, sal
->symtab
->filename
);
5746 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5748 struct blockvector
*bv
;
5753 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5756 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5757 sym
= block_function (b
);
5760 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5761 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5765 /* It really is worthwhile to have the section, so we'll just
5766 have to look harder. This case can be executed if we have
5767 line numbers but no functions (as can happen in assembly
5770 struct minimal_symbol
*msym
;
5772 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5774 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5781 break_command (char *arg
, int from_tty
)
5783 break_command_1 (arg
, 0, from_tty
);
5787 tbreak_command (char *arg
, int from_tty
)
5789 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5793 hbreak_command (char *arg
, int from_tty
)
5795 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5799 thbreak_command (char *arg
, int from_tty
)
5801 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5805 stop_command (char *arg
, int from_tty
)
5807 printf_filtered (_("Specify the type of breakpoint to set.\n\
5808 Usage: stop in <function | address>\n\
5809 stop at <line>\n"));
5813 stopin_command (char *arg
, int from_tty
)
5817 if (arg
== (char *) NULL
)
5819 else if (*arg
!= '*')
5824 /* look for a ':'. If this is a line number specification, then
5825 say it is bad, otherwise, it should be an address or
5826 function/method name */
5827 while (*argptr
&& !hasColon
)
5829 hasColon
= (*argptr
== ':');
5834 badInput
= (*argptr
!= ':'); /* Not a class::method */
5836 badInput
= isdigit (*arg
); /* a simple line number */
5840 printf_filtered (_("Usage: stop in <function | address>\n"));
5842 break_command_1 (arg
, 0, from_tty
);
5846 stopat_command (char *arg
, int from_tty
)
5850 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5857 /* look for a ':'. If there is a '::' then get out, otherwise
5858 it is probably a line number. */
5859 while (*argptr
&& !hasColon
)
5861 hasColon
= (*argptr
== ':');
5866 badInput
= (*argptr
== ':'); /* we have class::method */
5868 badInput
= !isdigit (*arg
); /* not a line number */
5872 printf_filtered (_("Usage: stop at <line>\n"));
5874 break_command_1 (arg
, 0, from_tty
);
5877 /* accessflag: hw_write: watch write,
5878 hw_read: watch read,
5879 hw_access: watch access (read or write) */
5881 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5883 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5884 struct symtab_and_line sal
;
5885 struct expression
*exp
;
5886 struct block
*exp_valid_block
;
5887 struct value
*val
, *mark
;
5888 struct frame_info
*frame
;
5889 struct frame_info
*prev_frame
= NULL
;
5890 char *exp_start
= NULL
;
5891 char *exp_end
= NULL
;
5892 char *tok
, *end_tok
;
5894 char *cond_start
= NULL
;
5895 char *cond_end
= NULL
;
5896 struct expression
*cond
= NULL
;
5897 int i
, other_type_used
, target_resources_ok
= 0;
5898 enum bptype bp_type
;
5901 init_sal (&sal
); /* initialize to zeroes */
5903 /* Parse arguments. */
5904 innermost_block
= NULL
;
5906 exp
= parse_exp_1 (&arg
, 0, 0);
5908 exp_valid_block
= innermost_block
;
5909 mark
= value_mark ();
5910 val
= evaluate_expression (exp
);
5911 release_value (val
);
5912 if (value_lazy (val
))
5913 value_fetch_lazy (val
);
5916 while (*tok
== ' ' || *tok
== '\t')
5920 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5923 toklen
= end_tok
- tok
;
5924 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5926 tok
= cond_start
= end_tok
+ 1;
5927 cond
= parse_exp_1 (&tok
, 0, 0);
5931 error (_("Junk at end of command."));
5933 if (accessflag
== hw_read
)
5934 bp_type
= bp_read_watchpoint
;
5935 else if (accessflag
== hw_access
)
5936 bp_type
= bp_access_watchpoint
;
5938 bp_type
= bp_hardware_watchpoint
;
5940 mem_cnt
= can_use_hardware_watchpoint (val
);
5941 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5942 error (_("Expression cannot be implemented with read/access watchpoint."));
5945 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5946 target_resources_ok
=
5947 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5949 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5950 error (_("Target does not support this type of hardware watchpoint."));
5952 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5953 error (_("Target can only support one kind of HW watchpoint at a time."));
5956 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5957 watchpoint could not be set. */
5958 if (!mem_cnt
|| target_resources_ok
<= 0)
5959 bp_type
= bp_watchpoint
;
5961 frame
= block_innermost_frame (exp_valid_block
);
5963 prev_frame
= get_prev_frame (frame
);
5967 /* If the expression is "local", then set up a "watchpoint scope"
5968 breakpoint at the point where we've left the scope of the watchpoint
5969 expression. Create the scope breakpoint before the watchpoint, so
5970 that we will encounter it first in bpstat_stop_status. */
5971 if (innermost_block
&& prev_frame
)
5973 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5974 bp_watchpoint_scope
);
5976 scope_breakpoint
->enable_state
= bp_enabled
;
5978 /* Automatically delete the breakpoint when it hits. */
5979 scope_breakpoint
->disposition
= disp_del
;
5981 /* Only break in the proper frame (help with recursion). */
5982 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5984 /* Set the address at which we will stop. */
5985 scope_breakpoint
->loc
->requested_address
5986 = get_frame_pc (prev_frame
);
5987 scope_breakpoint
->loc
->address
5988 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5989 scope_breakpoint
->type
);
5992 /* Now set up the breakpoint. */
5993 b
= set_raw_breakpoint (sal
, bp_type
);
5994 set_breakpoint_count (breakpoint_count
+ 1);
5995 b
->number
= breakpoint_count
;
5996 b
->disposition
= disp_donttouch
;
5998 b
->exp_valid_block
= exp_valid_block
;
5999 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6001 b
->loc
->cond
= cond
;
6003 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6008 b
->watchpoint_frame
= get_frame_id (frame
);
6010 b
->watchpoint_frame
= null_frame_id
;
6012 if (scope_breakpoint
!= NULL
)
6014 /* The scope breakpoint is related to the watchpoint. We will
6015 need to act on them together. */
6016 b
->related_breakpoint
= scope_breakpoint
;
6017 scope_breakpoint
->related_breakpoint
= b
;
6020 value_free_to_mark (mark
);
6024 /* Return count of locations need to be watched and can be handled
6025 in hardware. If the watchpoint can not be handled
6026 in hardware return zero. */
6029 can_use_hardware_watchpoint (struct value
*v
)
6031 int found_memory_cnt
= 0;
6032 struct value
*head
= v
;
6034 /* Did the user specifically forbid us to use hardware watchpoints? */
6035 if (!can_use_hw_watchpoints
)
6038 /* Make sure that the value of the expression depends only upon
6039 memory contents, and values computed from them within GDB. If we
6040 find any register references or function calls, we can't use a
6041 hardware watchpoint.
6043 The idea here is that evaluating an expression generates a series
6044 of values, one holding the value of every subexpression. (The
6045 expression a*b+c has five subexpressions: a, b, a*b, c, and
6046 a*b+c.) GDB's values hold almost enough information to establish
6047 the criteria given above --- they identify memory lvalues,
6048 register lvalues, computed values, etcetera. So we can evaluate
6049 the expression, and then scan the chain of values that leaves
6050 behind to decide whether we can detect any possible change to the
6051 expression's final value using only hardware watchpoints.
6053 However, I don't think that the values returned by inferior
6054 function calls are special in any way. So this function may not
6055 notice that an expression involving an inferior function call
6056 can't be watched with hardware watchpoints. FIXME. */
6057 for (; v
; v
= value_next (v
))
6059 if (VALUE_LVAL (v
) == lval_memory
)
6062 /* A lazy memory lvalue is one that GDB never needed to fetch;
6063 we either just used its address (e.g., `a' in `a.b') or
6064 we never needed it at all (e.g., `a' in `a,b'). */
6068 /* Ahh, memory we actually used! Check if we can cover
6069 it with hardware watchpoints. */
6070 struct type
*vtype
= check_typedef (value_type (v
));
6072 /* We only watch structs and arrays if user asked for it
6073 explicitly, never if they just happen to appear in a
6074 middle of some value chain. */
6076 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6077 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6079 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6080 int len
= TYPE_LENGTH (value_type (v
));
6082 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6089 else if (VALUE_LVAL (v
) != not_lval
6090 && deprecated_value_modifiable (v
) == 0)
6091 return 0; /* ??? What does this represent? */
6092 else if (VALUE_LVAL (v
) == lval_register
)
6093 return 0; /* cannot watch a register with a HW watchpoint */
6096 /* The expression itself looks suitable for using a hardware
6097 watchpoint, but give the target machine a chance to reject it. */
6098 return found_memory_cnt
;
6102 watch_command_wrapper (char *arg
, int from_tty
)
6104 watch_command (arg
, from_tty
);
6108 watch_command (char *arg
, int from_tty
)
6110 watch_command_1 (arg
, hw_write
, from_tty
);
6114 rwatch_command_wrapper (char *arg
, int from_tty
)
6116 rwatch_command (arg
, from_tty
);
6120 rwatch_command (char *arg
, int from_tty
)
6122 watch_command_1 (arg
, hw_read
, from_tty
);
6126 awatch_command_wrapper (char *arg
, int from_tty
)
6128 awatch_command (arg
, from_tty
);
6132 awatch_command (char *arg
, int from_tty
)
6134 watch_command_1 (arg
, hw_access
, from_tty
);
6138 /* Helper routines for the until_command routine in infcmd.c. Here
6139 because it uses the mechanisms of breakpoints. */
6141 /* This function is called by fetch_inferior_event via the
6142 cmd_continuation pointer, to complete the until command. It takes
6143 care of cleaning up the temporary breakpoints set up by the until
6146 until_break_command_continuation (struct continuation_arg
*arg
)
6148 struct cleanup
*cleanups
;
6150 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
6151 do_exec_cleanups (cleanups
);
6155 until_break_command (char *arg
, int from_tty
, int anywhere
)
6157 struct symtabs_and_lines sals
;
6158 struct symtab_and_line sal
;
6159 struct frame_info
*frame
= get_selected_frame (NULL
);
6160 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6161 struct breakpoint
*breakpoint
;
6162 struct cleanup
*old_chain
;
6163 struct continuation_arg
*arg1
;
6166 clear_proceed_status ();
6168 /* Set a breakpoint where the user wants it and at return from
6171 if (default_breakpoint_valid
)
6172 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6173 default_breakpoint_line
, (char ***) NULL
, NULL
);
6175 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6176 0, (char ***) NULL
, NULL
);
6178 if (sals
.nelts
!= 1)
6179 error (_("Couldn't get information on specified line."));
6182 xfree (sals
.sals
); /* malloc'd, so freed */
6185 error (_("Junk at end of arguments."));
6187 resolve_sal_pc (&sal
);
6190 /* If the user told us to continue until a specified location,
6191 we don't specify a frame at which we need to stop. */
6192 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6194 /* Otherwise, specify the current frame, because we want to stop only
6195 at the very same frame. */
6196 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6199 if (!target_can_async_p ())
6200 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6202 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
6204 /* If we are running asynchronously, and the target supports async
6205 execution, we are not waiting for the target to stop, in the call
6206 tp proceed, below. This means that we cannot delete the
6207 brekpoints until the target has actually stopped. The only place
6208 where we get a chance to do that is in fetch_inferior_event, so
6209 we must set things up for that. */
6211 if (target_can_async_p ())
6213 /* In this case the arg for the continuation is just the point
6214 in the exec_cleanups chain from where to start doing
6215 cleanups, because all the continuation does is the cleanups in
6216 the exec_cleanup_chain. */
6218 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6220 arg1
->data
.pointer
= old_chain
;
6222 add_continuation (until_break_command_continuation
, arg1
);
6225 /* Keep within the current frame, or in frames called by the current
6229 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6230 sal
.pc
= get_frame_pc (prev_frame
);
6231 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6233 if (!target_can_async_p ())
6234 make_cleanup_delete_breakpoint (breakpoint
);
6236 make_exec_cleanup_delete_breakpoint (breakpoint
);
6239 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6240 /* Do the cleanups now, anly if we are not running asynchronously,
6241 of if we are, but the target is still synchronous. */
6242 if (!target_can_async_p ())
6243 do_cleanups (old_chain
);
6247 ep_skip_leading_whitespace (char **s
)
6249 if ((s
== NULL
) || (*s
== NULL
))
6251 while (isspace (**s
))
6255 /* This function examines a string, and attempts to find a token
6256 that might be an event name in the leading characters. If a
6257 possible match is found, a pointer to the last character of
6258 the token is returned. Else, NULL is returned. */
6261 ep_find_event_name_end (char *arg
)
6264 char *event_name_end
= NULL
;
6266 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6270 /* We break out of the loop when we find a token delimiter.
6271 Basically, we're looking for alphanumerics and underscores;
6272 anything else delimites the token. */
6275 if (!isalnum (*s
) && (*s
!= '_'))
6281 return event_name_end
;
6285 /* This function attempts to parse an optional "if <cond>" clause
6286 from the arg string. If one is not found, it returns NULL.
6288 Else, it returns a pointer to the condition string. (It does not
6289 attempt to evaluate the string against a particular block.) And,
6290 it updates arg to point to the first character following the parsed
6291 if clause in the arg string. */
6294 ep_parse_optional_if_clause (char **arg
)
6298 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6301 /* Skip the "if" keyword. */
6304 /* Skip any extra leading whitespace, and record the start of the
6305 condition string. */
6306 ep_skip_leading_whitespace (arg
);
6309 /* Assume that the condition occupies the remainder of the arg string. */
6310 (*arg
) += strlen (cond_string
);
6315 /* This function attempts to parse an optional filename from the arg
6316 string. If one is not found, it returns NULL.
6318 Else, it returns a pointer to the parsed filename. (This function
6319 makes no attempt to verify that a file of that name exists, or is
6320 accessible.) And, it updates arg to point to the first character
6321 following the parsed filename in the arg string.
6323 Note that clients needing to preserve the returned filename for
6324 future access should copy it to their own buffers. */
6326 ep_parse_optional_filename (char **arg
)
6328 static char filename
[1024];
6333 if ((*arg_p
== '\0') || isspace (*arg_p
))
6351 /* Commands to deal with catching events, such as signals, exceptions,
6352 process start/exit, etc. */
6356 catch_fork
, catch_vfork
6361 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6364 char *cond_string
= NULL
;
6366 ep_skip_leading_whitespace (&arg
);
6368 /* The allowed syntax is:
6370 catch [v]fork if <cond>
6372 First, check if there's an if clause. */
6373 cond_string
= ep_parse_optional_if_clause (&arg
);
6375 if ((*arg
!= '\0') && !isspace (*arg
))
6376 error (_("Junk at end of arguments."));
6378 /* If this target supports it, create a fork or vfork catchpoint
6379 and enable reporting of such events. */
6383 create_fork_event_catchpoint (tempflag
, cond_string
);
6386 create_vfork_event_catchpoint (tempflag
, cond_string
);
6389 error (_("unsupported or unknown fork kind; cannot catch it"));
6395 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6397 char *cond_string
= NULL
;
6399 ep_skip_leading_whitespace (&arg
);
6401 /* The allowed syntax is:
6403 catch exec if <cond>
6405 First, check if there's an if clause. */
6406 cond_string
= ep_parse_optional_if_clause (&arg
);
6408 if ((*arg
!= '\0') && !isspace (*arg
))
6409 error (_("Junk at end of arguments."));
6411 /* If this target supports it, create an exec catchpoint
6412 and enable reporting of such events. */
6413 create_exec_event_catchpoint (tempflag
, cond_string
);
6417 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6419 char *dll_pathname
= NULL
;
6420 char *cond_string
= NULL
;
6422 ep_skip_leading_whitespace (&arg
);
6424 /* The allowed syntax is:
6426 catch load if <cond>
6427 catch load <filename>
6428 catch load <filename> if <cond>
6430 The user is not allowed to specify the <filename> after an
6433 We'll ignore the pathological case of a file named "if".
6435 First, check if there's an if clause. If so, then there
6436 cannot be a filename. */
6437 cond_string
= ep_parse_optional_if_clause (&arg
);
6439 /* If there was an if clause, then there cannot be a filename.
6440 Else, there might be a filename and an if clause. */
6441 if (cond_string
== NULL
)
6443 dll_pathname
= ep_parse_optional_filename (&arg
);
6444 ep_skip_leading_whitespace (&arg
);
6445 cond_string
= ep_parse_optional_if_clause (&arg
);
6448 if ((*arg
!= '\0') && !isspace (*arg
))
6449 error (_("Junk at end of arguments."));
6451 /* Create a load breakpoint that only triggers when a load of
6452 the specified dll (or any dll, if no pathname was specified)
6454 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6455 dll_pathname
, cond_string
);
6459 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6461 char *dll_pathname
= NULL
;
6462 char *cond_string
= NULL
;
6464 ep_skip_leading_whitespace (&arg
);
6466 /* The allowed syntax is:
6468 catch unload if <cond>
6469 catch unload <filename>
6470 catch unload <filename> if <cond>
6472 The user is not allowed to specify the <filename> after an
6475 We'll ignore the pathological case of a file named "if".
6477 First, check if there's an if clause. If so, then there
6478 cannot be a filename. */
6479 cond_string
= ep_parse_optional_if_clause (&arg
);
6481 /* If there was an if clause, then there cannot be a filename.
6482 Else, there might be a filename and an if clause. */
6483 if (cond_string
== NULL
)
6485 dll_pathname
= ep_parse_optional_filename (&arg
);
6486 ep_skip_leading_whitespace (&arg
);
6487 cond_string
= ep_parse_optional_if_clause (&arg
);
6490 if ((*arg
!= '\0') && !isspace (*arg
))
6491 error (_("Junk at end of arguments."));
6493 /* Create an unload breakpoint that only triggers when an unload of
6494 the specified dll (or any dll, if no pathname was specified)
6496 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6497 dll_pathname
, cond_string
);
6500 /* Commands to deal with catching exceptions. */
6502 /* Set a breakpoint at the specified callback routine for an
6503 exception event callback */
6506 create_exception_catchpoint (int tempflag
, char *cond_string
,
6507 enum exception_event_kind ex_event
,
6508 struct symtab_and_line
*sal
)
6510 struct breakpoint
*b
;
6511 int thread
= -1; /* All threads. */
6514 if (!sal
) /* no exception support? */
6519 case EX_EVENT_THROW
:
6520 bptype
= bp_catch_throw
;
6522 case EX_EVENT_CATCH
:
6523 bptype
= bp_catch_catch
;
6525 default: /* error condition */
6526 error (_("Internal error -- invalid catchpoint kind"));
6529 b
= set_raw_breakpoint (*sal
, bptype
);
6530 set_breakpoint_count (breakpoint_count
+ 1);
6531 b
->number
= breakpoint_count
;
6532 b
->cond_string
= (cond_string
== NULL
) ?
6533 NULL
: savestring (cond_string
, strlen (cond_string
));
6535 b
->addr_string
= NULL
;
6536 b
->enable_state
= bp_enabled
;
6537 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6541 static enum print_stop_action
6542 print_exception_catchpoint (struct breakpoint
*b
)
6544 annotate_catchpoint (b
->number
);
6546 if (strstr (b
->addr_string
, "throw") != NULL
)
6547 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6550 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6553 return PRINT_SRC_AND_LOC
;
6557 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6562 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6565 *last_addr
= b
->loc
->address
;
6566 if (strstr (b
->addr_string
, "throw") != NULL
)
6567 ui_out_field_string (uiout
, "what", "exception throw");
6569 ui_out_field_string (uiout
, "what", "exception catch");
6573 print_mention_exception_catchpoint (struct breakpoint
*b
)
6575 if (strstr (b
->addr_string
, "throw") != NULL
)
6576 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6578 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6581 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6582 print_exception_catchpoint
,
6583 print_one_exception_catchpoint
,
6584 print_mention_exception_catchpoint
6588 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6589 enum exception_event_kind ex_event
, int from_tty
)
6591 char *trigger_func_name
, *nameptr
;
6592 struct symtabs_and_lines sals
;
6593 struct breakpoint
*b
;
6595 if (ex_event
== EX_EVENT_CATCH
)
6596 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6598 trigger_func_name
= xstrdup ("__cxa_throw");
6600 nameptr
= trigger_func_name
;
6601 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6602 if (sals
.nelts
== 0)
6604 xfree (trigger_func_name
);
6608 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6609 set_breakpoint_count (breakpoint_count
+ 1);
6610 b
->number
= breakpoint_count
;
6611 b
->cond_string
= (cond_string
== NULL
) ?
6612 NULL
: savestring (cond_string
, strlen (cond_string
));
6614 b
->addr_string
= trigger_func_name
;
6615 b
->enable_state
= bp_enabled
;
6616 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6617 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6624 /* Deal with "catch catch" and "catch throw" commands */
6627 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6628 int tempflag
, int from_tty
)
6630 char *cond_string
= NULL
;
6631 struct symtab_and_line
*sal
= NULL
;
6633 ep_skip_leading_whitespace (&arg
);
6635 cond_string
= ep_parse_optional_if_clause (&arg
);
6637 if ((*arg
!= '\0') && !isspace (*arg
))
6638 error (_("Junk at end of arguments."));
6640 if ((ex_event
!= EX_EVENT_THROW
) &&
6641 (ex_event
!= EX_EVENT_CATCH
))
6642 error (_("Unsupported or unknown exception event; cannot catch it"));
6644 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6647 /* See if we can find a callback routine */
6648 sal
= target_enable_exception_callback (ex_event
, 1);
6652 /* We have callbacks from the runtime system for exceptions.
6653 Set a breakpoint on the sal found, if no errors */
6654 if (sal
!= (struct symtab_and_line
*) -1)
6655 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6657 return; /* something went wrong with setting up callbacks */
6660 warning (_("Unsupported with this platform/compiler combination."));
6663 /* Create a breakpoint struct for Ada exception catchpoints. */
6666 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6670 struct expression
*cond
,
6671 struct breakpoint_ops
*ops
,
6675 struct breakpoint
*b
;
6679 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6680 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6681 version for exception catchpoints, because two catchpoints
6682 used for different exception names will use the same address.
6683 In this case, a "breakpoint ... also set at..." warning is
6684 unproductive. Besides. the warning phrasing is also a bit
6685 inapropriate, we should use the word catchpoint, and tell
6686 the user what type of catchpoint it is. The above is good
6687 enough for now, though. */
6690 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6691 set_breakpoint_count (breakpoint_count
+ 1);
6693 b
->enable_state
= bp_enabled
;
6694 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6695 b
->number
= breakpoint_count
;
6696 b
->ignore_count
= 0;
6697 b
->loc
->cond
= cond
;
6698 b
->addr_string
= addr_string
;
6699 b
->language
= language_ada
;
6700 b
->cond_string
= cond_string
;
6701 b
->exp_string
= exp_string
;
6708 /* Implement the "catch exception" command. */
6711 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6713 struct symtab_and_line sal
;
6715 char *addr_string
= NULL
;
6716 char *exp_string
= NULL
;
6717 char *cond_string
= NULL
;
6718 struct expression
*cond
= NULL
;
6719 struct breakpoint_ops
*ops
= NULL
;
6721 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6722 &cond_string
, &cond
, &ops
);
6723 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6724 cond_string
, cond
, ops
, tempflag
,
6728 /* Implement the "catch assert" command. */
6731 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6733 struct symtab_and_line sal
;
6734 char *addr_string
= NULL
;
6735 struct breakpoint_ops
*ops
= NULL
;
6737 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6738 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6739 tempflag
, from_tty
);
6742 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6743 inside a catch_errors */
6746 cover_target_enable_exception_callback (void *arg
)
6748 args_for_catchpoint_enable
*args
= arg
;
6749 struct symtab_and_line
*sal
;
6750 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6753 else if (sal
== (struct symtab_and_line
*) -1)
6756 return 1; /*is valid */
6760 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6763 /* The first argument may be an event name, such as "start" or "load".
6764 If so, then handle it as such. If it doesn't match an event name,
6765 then attempt to interpret it as an exception name. (This latter is
6766 the v4.16-and-earlier GDB meaning of the "catch" command.)
6768 First, try to find the bounds of what might be an event name. */
6769 char *arg1_start
= arg
;
6773 if (arg1_start
== NULL
)
6775 /* Old behaviour was to use pre-v-4.16 syntax */
6776 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6778 /* Now, this is not allowed */
6779 error (_("Catch requires an event name."));
6782 arg1_end
= ep_find_event_name_end (arg1_start
);
6783 if (arg1_end
== NULL
)
6784 error (_("catch requires an event"));
6785 arg1_length
= arg1_end
+ 1 - arg1_start
;
6787 /* Try to match what we found against known event names. */
6788 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6790 error (_("Catch of signal not yet implemented"));
6792 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6794 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6795 tempflag
, from_tty
);
6797 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6799 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6800 tempflag
, from_tty
);
6802 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6804 error (_("Catch of thread_start not yet implemented"));
6806 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6808 error (_("Catch of thread_exit not yet implemented"));
6810 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6812 error (_("Catch of thread_join not yet implemented"));
6814 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6816 error (_("Catch of start not yet implemented"));
6818 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6820 error (_("Catch of exit not yet implemented"));
6822 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6824 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6826 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6828 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6830 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6832 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6834 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6836 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6838 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6840 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6842 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6844 error (_("Catch of stop not yet implemented"));
6846 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6848 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6851 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6853 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6856 /* This doesn't appear to be an event name */
6860 /* Pre-v.4.16 behaviour was to treat the argument
6861 as the name of an exception */
6862 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6863 /* Now this is not allowed */
6864 error (_("Unknown event kind specified for catch"));
6870 catch_command (char *arg
, int from_tty
)
6872 catch_command_1 (arg
, 0, from_tty
);
6877 tcatch_command (char *arg
, int from_tty
)
6879 catch_command_1 (arg
, 1, from_tty
);
6882 /* Delete breakpoints by address or line. */
6885 clear_command (char *arg
, int from_tty
)
6887 struct breakpoint
*b
;
6888 VEC(breakpoint_p
) *found
= 0;
6891 struct symtabs_and_lines sals
;
6892 struct symtab_and_line sal
;
6897 sals
= decode_line_spec (arg
, 1);
6902 sals
.sals
= (struct symtab_and_line
*)
6903 xmalloc (sizeof (struct symtab_and_line
));
6904 make_cleanup (xfree
, sals
.sals
);
6905 init_sal (&sal
); /* initialize to zeroes */
6906 sal
.line
= default_breakpoint_line
;
6907 sal
.symtab
= default_breakpoint_symtab
;
6908 sal
.pc
= default_breakpoint_address
;
6909 if (sal
.symtab
== 0)
6910 error (_("No source file specified."));
6918 /* We don't call resolve_sal_pc here. That's not
6919 as bad as it seems, because all existing breakpoints
6920 typically have both file/line and pc set. So, if
6921 clear is given file/line, we can match this to existing
6922 breakpoint without obtaining pc at all.
6924 We only support clearing given the address explicitly
6925 present in breakpoint table. Say, we've set breakpoint
6926 at file:line. There were several PC values for that file:line,
6927 due to optimization, all in one block.
6928 We've picked one PC value. If "clear" is issued with another
6929 PC corresponding to the same file:line, the breakpoint won't
6930 be cleared. We probably can still clear the breakpoint, but
6931 since the other PC value is never presented to user, user
6932 can only find it by guessing, and it does not seem important
6935 /* For each line spec given, delete bps which correspond
6936 to it. Do it in two passes, solely to preserve the current
6937 behavior that from_tty is forced true if we delete more than
6941 for (i
= 0; i
< sals
.nelts
; i
++)
6943 /* If exact pc given, clear bpts at that pc.
6944 If line given (pc == 0), clear all bpts on specified line.
6945 If defaulting, clear all bpts on default line
6948 defaulting sal.pc != 0 tests to do
6953 1 0 <can't happen> */
6957 /* Find all matching breakpoints and add them to
6962 /* Are we going to delete b? */
6963 if (b
->type
!= bp_none
6964 && b
->type
!= bp_watchpoint
6965 && b
->type
!= bp_hardware_watchpoint
6966 && b
->type
!= bp_read_watchpoint
6967 && b
->type
!= bp_access_watchpoint
)
6969 struct bp_location
*loc
= b
->loc
;
6970 for (; loc
; loc
= loc
->next
)
6972 int pc_match
= sal
.pc
6973 && (loc
->address
== sal
.pc
)
6974 && (!section_is_overlay (loc
->section
)
6975 || loc
->section
== sal
.section
);
6976 int line_match
= ((default_match
|| (0 == sal
.pc
))
6977 && b
->source_file
!= NULL
6978 && sal
.symtab
!= NULL
6979 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6980 && b
->line_number
== sal
.line
);
6981 if (pc_match
|| line_match
)
6990 VEC_safe_push(breakpoint_p
, found
, b
);
6993 /* Now go thru the 'found' chain and delete them. */
6994 if (VEC_empty(breakpoint_p
, found
))
6997 error (_("No breakpoint at %s."), arg
);
6999 error (_("No breakpoint at this line."));
7002 if (VEC_length(breakpoint_p
, found
) > 1)
7003 from_tty
= 1; /* Always report if deleted more than one */
7006 if (VEC_length(breakpoint_p
, found
) == 1)
7007 printf_unfiltered (_("Deleted breakpoint "));
7009 printf_unfiltered (_("Deleted breakpoints "));
7011 breakpoints_changed ();
7013 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
7016 printf_unfiltered ("%d ", b
->number
);
7017 delete_breakpoint (b
);
7020 putchar_unfiltered ('\n');
7023 /* Delete breakpoint in BS if they are `delete' breakpoints and
7024 all breakpoints that are marked for deletion, whether hit or not.
7025 This is called after any breakpoint is hit, or after errors. */
7028 breakpoint_auto_delete (bpstat bs
)
7030 struct breakpoint
*b
, *temp
;
7032 for (; bs
; bs
= bs
->next
)
7033 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
->disposition
== disp_del
7035 delete_breakpoint (bs
->breakpoint_at
->owner
);
7037 ALL_BREAKPOINTS_SAFE (b
, temp
)
7039 if (b
->disposition
== disp_del_at_next_stop
)
7040 delete_breakpoint (b
);
7044 /* Remove locations of breakpoint BPT from
7045 the global list of breakpoint locations. */
7048 unlink_locations_from_global_list (struct breakpoint
*bpt
)
7050 /* This code assumes that the locations
7051 of a breakpoint are found in the global list
7052 in the same order, but not necessary adjacent. */
7053 struct bp_location
**tmp
= &bp_location_chain
;
7054 struct bp_location
*here
= bpt
->loc
;
7059 for (; *tmp
&& here
;)
7063 *tmp
= here
->global_next
;
7068 tmp
= &((*tmp
)->global_next
);
7073 /* Delete a breakpoint and clean up all traces of it in the data
7077 delete_breakpoint (struct breakpoint
*bpt
)
7079 struct breakpoint
*b
;
7081 struct bp_location
*loc
;
7083 gdb_assert (bpt
!= NULL
);
7085 /* Has this bp already been deleted? This can happen because multiple
7086 lists can hold pointers to bp's. bpstat lists are especial culprits.
7088 One example of this happening is a watchpoint's scope bp. When the
7089 scope bp triggers, we notice that the watchpoint is out of scope, and
7090 delete it. We also delete its scope bp. But the scope bp is marked
7091 "auto-deleting", and is already on a bpstat. That bpstat is then
7092 checked for auto-deleting bp's, which are deleted.
7094 A real solution to this problem might involve reference counts in bp's,
7095 and/or giving them pointers back to their referencing bpstat's, and
7096 teaching delete_breakpoint to only free a bp's storage when no more
7097 references were extent. A cheaper bandaid was chosen. */
7098 if (bpt
->type
== bp_none
)
7101 if (deprecated_delete_breakpoint_hook
)
7102 deprecated_delete_breakpoint_hook (bpt
);
7103 breakpoint_delete_event (bpt
->number
);
7105 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
7108 remove_breakpoint (loc
, mark_inserted
);
7110 free_valchain (loc
);
7115 if (loc
->function_name
)
7116 xfree (loc
->function_name
);
7119 if (breakpoint_chain
== bpt
)
7120 breakpoint_chain
= bpt
->next
;
7122 /* If we have callback-style exception catchpoints, don't go through
7123 the adjustments to the C++ runtime library etc. if the inferior
7124 isn't actually running. target_enable_exception_callback for a
7125 null target ops vector gives an undesirable error message, so we
7126 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
7127 exceptions are supported in this way, it's OK for now. FIXME */
7128 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
7130 /* Format possible error msg */
7131 char *message
= xstrprintf ("Error in deleting catchpoint %d:\n",
7133 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7134 args_for_catchpoint_enable args
;
7135 args
.kind
= bpt
->type
== bp_catch_catch
?
7136 EX_EVENT_CATCH
: EX_EVENT_THROW
;
7138 catch_errors (cover_target_enable_exception_callback
, &args
,
7139 message
, RETURN_MASK_ALL
);
7140 do_cleanups (cleanups
);
7147 b
->next
= bpt
->next
;
7151 unlink_locations_from_global_list (bpt
);
7153 check_duplicates (bpt
);
7155 if (bpt
->type
!= bp_hardware_watchpoint
7156 && bpt
->type
!= bp_read_watchpoint
7157 && bpt
->type
!= bp_access_watchpoint
7158 && bpt
->type
!= bp_catch_fork
7159 && bpt
->type
!= bp_catch_vfork
7160 && bpt
->type
!= bp_catch_exec
)
7161 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
7163 /* If this breakpoint location was inserted, and there is
7164 another breakpoint at the same address, we need to
7165 insert the other breakpoint. */
7168 struct bp_location
*loc2
;
7169 ALL_BP_LOCATIONS (loc2
)
7170 if (loc2
->address
== loc
->address
7171 && loc2
->section
== loc
->section
7173 && loc2
->owner
->enable_state
!= bp_disabled
7175 && !loc2
->shlib_disabled
7176 && loc2
->owner
->enable_state
!= bp_call_disabled
)
7180 /* We should never reach this point if there is a permanent
7181 breakpoint at the same address as the one being deleted.
7182 If there is a permanent breakpoint somewhere, it should
7183 always be the only one inserted. */
7184 if (loc2
->owner
->enable_state
== bp_permanent
)
7185 internal_error (__FILE__
, __LINE__
,
7186 _("another breakpoint was inserted on top of "
7187 "a permanent breakpoint"));
7189 memset (&loc2
->target_info
, 0, sizeof (loc2
->target_info
));
7190 loc2
->target_info
.placed_address
= loc2
->address
;
7191 if (b
->type
== bp_hardware_breakpoint
)
7192 val
= target_insert_hw_breakpoint (&loc2
->target_info
);
7194 val
= target_insert_breakpoint (&loc2
->target_info
);
7196 /* If there was an error in the insert, print a message, then stop execution. */
7199 struct ui_file
*tmp_error_stream
= mem_fileopen ();
7200 make_cleanup_ui_file_delete (tmp_error_stream
);
7203 if (b
->type
== bp_hardware_breakpoint
)
7205 fprintf_unfiltered (tmp_error_stream
,
7206 "Cannot insert hardware breakpoint %d.\n"
7207 "You may have requested too many hardware breakpoints.\n",
7212 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
7213 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
7214 deprecated_print_address_numeric (loc2
->address
, 1, tmp_error_stream
);
7215 fprintf_filtered (tmp_error_stream
, ": %s.\n",
7216 safe_strerror (val
));
7219 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
7220 target_terminal_ours_for_output ();
7221 error_stream(tmp_error_stream
);
7229 free_command_lines (&bpt
->commands
);
7230 if (bpt
->cond_string
!= NULL
)
7231 xfree (bpt
->cond_string
);
7232 if (bpt
->addr_string
!= NULL
)
7233 xfree (bpt
->addr_string
);
7234 if (bpt
->exp
!= NULL
)
7236 if (bpt
->exp_string
!= NULL
)
7237 xfree (bpt
->exp_string
);
7238 if (bpt
->val
!= NULL
)
7239 value_free (bpt
->val
);
7240 if (bpt
->source_file
!= NULL
)
7241 xfree (bpt
->source_file
);
7242 if (bpt
->dll_pathname
!= NULL
)
7243 xfree (bpt
->dll_pathname
);
7244 if (bpt
->triggered_dll_pathname
!= NULL
)
7245 xfree (bpt
->triggered_dll_pathname
);
7246 if (bpt
->exec_pathname
!= NULL
)
7247 xfree (bpt
->exec_pathname
);
7249 /* Be sure no bpstat's are pointing at it after it's been freed. */
7250 /* FIXME, how can we find all bpstat's?
7251 We just check stop_bpstat for now. Note that we cannot just
7252 remove bpstats pointing at bpt from the stop_bpstat list
7253 entirely, as breakpoint commands are associated with the bpstat;
7254 if we remove it here, then the later call to
7255 bpstat_do_actions (&stop_bpstat);
7256 in event-top.c won't do anything, and temporary breakpoints
7257 with commands won't work. */
7258 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
7259 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7261 bs
->breakpoint_at
= NULL
;
7263 /* bs->commands will be freed later. */
7265 /* On the chance that someone will soon try again to delete this same
7266 bp, we mark it as deleted before freeing its storage. */
7267 bpt
->type
= bp_none
;
7269 for (loc
= bpt
->loc
; loc
;)
7271 struct bp_location
*loc_next
= loc
->next
;
7279 do_delete_breakpoint_cleanup (void *b
)
7281 delete_breakpoint (b
);
7285 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7287 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7291 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
7293 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
7297 delete_command (char *arg
, int from_tty
)
7299 struct breakpoint
*b
, *temp
;
7305 int breaks_to_delete
= 0;
7307 /* Delete all breakpoints if no argument.
7308 Do not delete internal or call-dummy breakpoints, these
7309 have to be deleted with an explicit breakpoint number argument. */
7312 if (b
->type
!= bp_call_dummy
&&
7313 b
->type
!= bp_shlib_event
&&
7314 b
->type
!= bp_thread_event
&&
7315 b
->type
!= bp_overlay_event
&&
7318 breaks_to_delete
= 1;
7323 /* Ask user only if there are some breakpoints to delete. */
7325 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7327 ALL_BREAKPOINTS_SAFE (b
, temp
)
7329 if (b
->type
!= bp_call_dummy
&&
7330 b
->type
!= bp_shlib_event
&&
7331 b
->type
!= bp_thread_event
&&
7332 b
->type
!= bp_overlay_event
&&
7334 delete_breakpoint (b
);
7339 map_breakpoint_numbers (arg
, delete_breakpoint
);
7343 all_locations_are_pending (struct bp_location
*loc
)
7345 for (; loc
; loc
= loc
->next
)
7346 if (!loc
->shlib_disabled
)
7352 update_breakpoint_locations (struct breakpoint
*b
,
7353 struct symtabs_and_lines sals
)
7357 struct bp_location
*existing_locations
= b
->loc
;
7359 /* If there's no new locations, and all existing locations
7360 are pending, don't do anything. This optimizes
7361 the common case where all locations are in the same
7362 shared library, that was unloaded. We'd like to
7363 retain the location, so that when the library
7364 is loaded again, we don't loose the enabled/disabled
7365 status of the individual locations. */
7366 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7369 unlink_locations_from_global_list (b
);
7372 for (i
= 0; i
< sals
.nelts
; ++i
)
7374 struct bp_location
*new_loc
=
7375 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7377 /* Reparse conditions, they might contain references to the
7379 if (b
->cond_string
!= NULL
)
7381 struct gdb_exception e
;
7384 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7386 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7391 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7392 b
->number
, e
.message
);
7393 new_loc
->enabled
= 0;
7397 if (b
->source_file
!= NULL
)
7398 xfree (b
->source_file
);
7399 if (sals
.sals
[i
].symtab
== NULL
)
7400 b
->source_file
= NULL
;
7403 savestring (sals
.sals
[i
].symtab
->filename
,
7404 strlen (sals
.sals
[i
].symtab
->filename
));
7406 if (b
->line_number
== 0)
7407 b
->line_number
= sals
.sals
[i
].line
;
7410 /* If possible, carry over 'disable' status from existing breakpoints. */
7412 struct bp_location
*e
= existing_locations
;
7413 for (; e
; e
= e
->next
)
7415 if (!e
->enabled
&& e
->function_name
)
7417 struct bp_location
*l
= b
->loc
;
7418 for (; l
; l
= l
->next
)
7419 if (l
->function_name
7420 && strcmp (e
->function_name
, l
->function_name
) == 0)
7429 while (existing_locations
)
7431 struct bp_location
*next
= existing_locations
->next
;
7432 free_bp_location (existing_locations
);
7433 existing_locations
= next
;
7438 /* Reset a breakpoint given it's struct breakpoint * BINT.
7439 The value we return ends up being the return value from catch_errors.
7440 Unused in this case. */
7443 breakpoint_re_set_one (void *bint
)
7445 /* get past catch_errs */
7446 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7450 int *not_found_ptr
= ¬_found
;
7451 struct symtabs_and_lines sals
= {};
7452 struct symtabs_and_lines expanded
;
7454 enum enable_state save_enable
;
7455 struct gdb_exception e
;
7461 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7465 case bp_hardware_breakpoint
:
7467 case bp_catch_unload
:
7468 if (b
->addr_string
== NULL
)
7470 /* Anything without a string can't be re-set. */
7471 delete_breakpoint (b
);
7475 set_language (b
->language
);
7476 input_radix
= b
->input_radix
;
7478 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7480 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7485 int not_found_and_ok
= 0;
7486 /* For pending breakpoints, it's expected that parsing
7487 will fail until the right shared library is loaded.
7488 User has already told to create pending breakpoints and
7489 don't need extra messages. If breakpoint is in bp_shlib_disabled
7490 state, then user already saw the message about that breakpoint
7491 being disabled, and don't want to see more errors. */
7493 && (b
->condition_not_parsed
7494 || (b
->loc
&& b
->loc
->shlib_disabled
)
7495 || b
->enable_state
== bp_disabled
))
7496 not_found_and_ok
= 1;
7498 if (!not_found_and_ok
)
7500 /* We surely don't want to warn about the same breakpoint
7501 10 times. One solution, implemented here, is disable
7502 the breakpoint on error. Another solution would be to
7503 have separate 'warning emitted' flag. Since this
7504 happens only when a binary has changed, I don't know
7505 which approach is better. */
7506 b
->enable_state
= bp_disabled
;
7507 throw_exception (e
);
7514 gdb_assert (sals
.nelts
== 1);
7515 resolve_sal_pc (&sals
.sals
[0]);
7516 if (b
->condition_not_parsed
&& s
&& s
[0])
7518 char *cond_string
= 0;
7520 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7521 &cond_string
, &thread
);
7523 b
->cond_string
= cond_string
;
7525 b
->condition_not_parsed
= 0;
7527 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7528 update_breakpoint_locations (b
, expanded
);
7530 /* Now that this is re-enabled, check_duplicates
7532 check_duplicates (b
);
7538 case bp_hardware_watchpoint
:
7539 case bp_read_watchpoint
:
7540 case bp_access_watchpoint
:
7541 innermost_block
= NULL
;
7542 /* The issue arises of what context to evaluate this in. The
7543 same one as when it was set, but what does that mean when
7544 symbols have been re-read? We could save the filename and
7545 functionname, but if the context is more local than that, the
7546 best we could do would be something like how many levels deep
7547 and which index at that particular level, but that's going to
7548 be less stable than filenames or function names. */
7550 /* So for now, just use a global context. */
7554 /* Avoid re-freeing b->exp if an error during the call to
7555 parse_expression. */
7558 b
->exp
= parse_expression (b
->exp_string
);
7559 b
->exp_valid_block
= innermost_block
;
7560 mark
= value_mark ();
7563 value_free (b
->val
);
7564 /* Avoid re-freeing b->val if an error during the call to
7565 evaluate_expression. */
7568 b
->val
= evaluate_expression (b
->exp
);
7569 release_value (b
->val
);
7570 if (value_lazy (b
->val
) && breakpoint_enabled (b
))
7571 value_fetch_lazy (b
->val
);
7573 if (b
->cond_string
!= NULL
)
7578 xfree (b
->loc
->cond
);
7579 /* Avoid re-freeing b->exp if an error during the call
7581 b
->loc
->cond
= NULL
;
7583 b
->loc
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
7585 if (breakpoint_enabled (b
))
7587 value_free_to_mark (mark
);
7589 case bp_catch_catch
:
7590 case bp_catch_throw
:
7592 /* We needn't really do anything to reset these, since the mask
7593 that requests them is unaffected by e.g., new libraries being
7596 case bp_catch_vfork
:
7601 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7603 /* Delete longjmp and overlay event breakpoints; they will be
7604 reset later by breakpoint_re_set. */
7606 case bp_longjmp_resume
:
7607 case bp_overlay_event
:
7608 delete_breakpoint (b
);
7611 /* This breakpoint is special, it's set up when the inferior
7612 starts and we really don't want to touch it. */
7613 case bp_shlib_event
:
7615 /* Like bp_shlib_event, this breakpoint type is special.
7616 Once it is set up, we do not want to touch it. */
7617 case bp_thread_event
:
7619 /* Keep temporary breakpoints, which can be encountered when we step
7620 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7621 Otherwise these should have been blown away via the cleanup chain
7622 or by breakpoint_init_inferior when we rerun the executable. */
7625 case bp_watchpoint_scope
:
7627 case bp_step_resume
:
7634 /* Re-set all breakpoints after symbols have been re-loaded. */
7636 breakpoint_re_set (void)
7638 struct breakpoint
*b
, *temp
;
7639 enum language save_language
;
7640 int save_input_radix
;
7642 save_language
= current_language
->la_language
;
7643 save_input_radix
= input_radix
;
7644 ALL_BREAKPOINTS_SAFE (b
, temp
)
7646 /* Format possible error msg */
7647 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7649 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7650 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7651 do_cleanups (cleanups
);
7653 set_language (save_language
);
7654 input_radix
= save_input_radix
;
7656 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
7658 create_longjmp_breakpoint ("longjmp");
7659 create_longjmp_breakpoint ("_longjmp");
7660 create_longjmp_breakpoint ("siglongjmp");
7661 create_longjmp_breakpoint ("_siglongjmp");
7662 create_longjmp_breakpoint (NULL
);
7665 create_overlay_event_breakpoint ("_ovly_debug_event");
7668 /* Reset the thread number of this breakpoint:
7670 - If the breakpoint is for all threads, leave it as-is.
7671 - Else, reset it to the current thread for inferior_ptid. */
7673 breakpoint_re_set_thread (struct breakpoint
*b
)
7675 if (b
->thread
!= -1)
7677 if (in_thread_list (inferior_ptid
))
7678 b
->thread
= pid_to_thread_id (inferior_ptid
);
7682 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7683 If from_tty is nonzero, it prints a message to that effect,
7684 which ends with a period (no newline). */
7687 set_ignore_count (int bptnum
, int count
, int from_tty
)
7689 struct breakpoint
*b
;
7695 if (b
->number
== bptnum
)
7697 b
->ignore_count
= count
;
7701 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7703 else if (count
== 1)
7704 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7707 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7710 breakpoints_changed ();
7711 breakpoint_modify_event (b
->number
);
7715 error (_("No breakpoint number %d."), bptnum
);
7718 /* Clear the ignore counts of all breakpoints. */
7720 breakpoint_clear_ignore_counts (void)
7722 struct breakpoint
*b
;
7725 b
->ignore_count
= 0;
7728 /* Command to set ignore-count of breakpoint N to COUNT. */
7731 ignore_command (char *args
, int from_tty
)
7737 error_no_arg (_("a breakpoint number"));
7739 num
= get_number (&p
);
7741 error (_("bad breakpoint number: '%s'"), args
);
7743 error (_("Second argument (specified ignore-count) is missing."));
7745 set_ignore_count (num
,
7746 longest_to_int (value_as_long (parse_and_eval (p
))),
7749 printf_filtered ("\n");
7752 /* Call FUNCTION on each of the breakpoints
7753 whose numbers are given in ARGS. */
7756 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7761 struct breakpoint
*b
, *tmp
;
7765 error_no_arg (_("one or more breakpoint numbers"));
7772 num
= get_number_or_range (&p1
);
7775 warning (_("bad breakpoint number at or near '%s'"), p
);
7779 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7780 if (b
->number
== num
)
7782 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7785 if (related_breakpoint
)
7786 function (related_breakpoint
);
7790 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7796 static struct bp_location
*
7797 find_location_by_number (char *number
)
7799 char *dot
= strchr (number
, '.');
7803 struct breakpoint
*b
;
7804 struct bp_location
*loc
;
7809 bp_num
= get_number_or_range (&p1
);
7811 error (_("Bad breakpoint number '%s'"), number
);
7814 if (b
->number
== bp_num
)
7819 if (!b
|| b
->number
!= bp_num
)
7820 error (_("Bad breakpoint number '%s'"), number
);
7823 loc_num
= get_number_or_range (&p1
);
7825 error (_("Bad breakpoint location number '%s'"), number
);
7829 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7832 error (_("Bad breakpoint location number '%s'"), dot
+1);
7838 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7839 If from_tty is nonzero, it prints a message to that effect,
7840 which ends with a period (no newline). */
7843 disable_breakpoint (struct breakpoint
*bpt
)
7845 /* Never disable a watchpoint scope breakpoint; we want to
7846 hit them when we leave scope so we can delete both the
7847 watchpoint and its scope breakpoint at that time. */
7848 if (bpt
->type
== bp_watchpoint_scope
)
7851 /* You can't disable permanent breakpoints. */
7852 if (bpt
->enable_state
== bp_permanent
)
7855 bpt
->enable_state
= bp_disabled
;
7857 check_duplicates (bpt
);
7859 if (deprecated_modify_breakpoint_hook
)
7860 deprecated_modify_breakpoint_hook (bpt
);
7861 breakpoint_modify_event (bpt
->number
);
7865 disable_command (char *args
, int from_tty
)
7867 struct breakpoint
*bpt
;
7869 ALL_BREAKPOINTS (bpt
)
7873 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7878 case bp_catch_unload
:
7880 case bp_catch_vfork
:
7882 case bp_catch_catch
:
7883 case bp_catch_throw
:
7884 case bp_hardware_breakpoint
:
7886 case bp_hardware_watchpoint
:
7887 case bp_read_watchpoint
:
7888 case bp_access_watchpoint
:
7889 disable_breakpoint (bpt
);
7893 else if (strchr (args
, '.'))
7895 struct bp_location
*loc
= find_location_by_number (args
);
7898 check_duplicates (loc
->owner
);
7901 map_breakpoint_numbers (args
, disable_breakpoint
);
7905 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7907 int target_resources_ok
, other_type_used
;
7910 if (bpt
->type
== bp_hardware_breakpoint
)
7913 i
= hw_breakpoint_used_count ();
7914 target_resources_ok
=
7915 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7917 if (target_resources_ok
== 0)
7918 error (_("No hardware breakpoint support in the target."));
7919 else if (target_resources_ok
< 0)
7920 error (_("Hardware breakpoints used exceeds limit."));
7923 if (bpt
->type
== bp_watchpoint
||
7924 bpt
->type
== bp_hardware_watchpoint
||
7925 bpt
->type
== bp_read_watchpoint
||
7926 bpt
->type
== bp_access_watchpoint
)
7928 struct frame_id saved_frame_id
;
7930 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7931 if (bpt
->exp_valid_block
!= NULL
)
7933 struct frame_info
*fr
=
7934 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7937 printf_filtered (_("\
7938 Cannot enable watchpoint %d because the block in which its expression\n\
7939 is valid is not currently in scope.\n"), bpt
->number
);
7946 value_free (bpt
->val
);
7947 mark
= value_mark ();
7948 bpt
->val
= evaluate_expression (bpt
->exp
);
7949 release_value (bpt
->val
);
7950 if (value_lazy (bpt
->val
))
7951 value_fetch_lazy (bpt
->val
);
7953 if (bpt
->type
== bp_hardware_watchpoint
||
7954 bpt
->type
== bp_read_watchpoint
||
7955 bpt
->type
== bp_access_watchpoint
)
7957 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7958 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7960 /* Hack around 'unused var' error for some targets here */
7961 (void) mem_cnt
, (void) i
;
7962 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7963 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7964 /* we can consider of type is bp_hardware_watchpoint, convert to
7965 bp_watchpoint in the following condition */
7966 if (target_resources_ok
< 0)
7968 printf_filtered (_("\
7969 Cannot enable watchpoint %d because target watch resources\n\
7970 have been allocated for other watchpoints.\n"), bpt
->number
);
7971 value_free_to_mark (mark
);
7976 select_frame (frame_find_by_id (saved_frame_id
));
7977 value_free_to_mark (mark
);
7980 if (bpt
->enable_state
!= bp_permanent
)
7981 bpt
->enable_state
= bp_enabled
;
7982 bpt
->disposition
= disposition
;
7983 check_duplicates (bpt
);
7984 breakpoints_changed ();
7986 if (deprecated_modify_breakpoint_hook
)
7987 deprecated_modify_breakpoint_hook (bpt
);
7988 breakpoint_modify_event (bpt
->number
);
7993 enable_breakpoint (struct breakpoint
*bpt
)
7995 do_enable_breakpoint (bpt
, bpt
->disposition
);
7998 /* The enable command enables the specified breakpoints (or all defined
7999 breakpoints) so they once again become (or continue to be) effective
8000 in stopping the inferior. */
8003 enable_command (char *args
, int from_tty
)
8005 struct breakpoint
*bpt
;
8007 ALL_BREAKPOINTS (bpt
)
8011 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8016 case bp_catch_unload
:
8018 case bp_catch_vfork
:
8020 case bp_catch_catch
:
8021 case bp_catch_throw
:
8022 case bp_hardware_breakpoint
:
8024 case bp_hardware_watchpoint
:
8025 case bp_read_watchpoint
:
8026 case bp_access_watchpoint
:
8027 enable_breakpoint (bpt
);
8031 else if (strchr (args
, '.'))
8033 struct bp_location
*loc
= find_location_by_number (args
);
8036 check_duplicates (loc
->owner
);
8039 map_breakpoint_numbers (args
, enable_breakpoint
);
8043 enable_once_breakpoint (struct breakpoint
*bpt
)
8045 do_enable_breakpoint (bpt
, disp_disable
);
8049 enable_once_command (char *args
, int from_tty
)
8051 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8055 enable_delete_breakpoint (struct breakpoint
*bpt
)
8057 do_enable_breakpoint (bpt
, disp_del
);
8061 enable_delete_command (char *args
, int from_tty
)
8063 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8067 set_breakpoint_cmd (char *args
, int from_tty
)
8072 show_breakpoint_cmd (char *args
, int from_tty
)
8076 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8078 struct symtabs_and_lines
8079 decode_line_spec_1 (char *string
, int funfirstline
)
8081 struct symtabs_and_lines sals
;
8083 error (_("Empty line specification."));
8084 if (default_breakpoint_valid
)
8085 sals
= decode_line_1 (&string
, funfirstline
,
8086 default_breakpoint_symtab
,
8087 default_breakpoint_line
,
8088 (char ***) NULL
, NULL
);
8090 sals
= decode_line_1 (&string
, funfirstline
,
8091 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8093 error (_("Junk at end of line specification: %s"), string
);
8097 /* Create and insert a raw software breakpoint at PC. Return an
8098 identifier, which should be used to remove the breakpoint later.
8099 In general, places which call this should be using something on the
8100 breakpoint chain instead; this function should be eliminated
8104 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8106 struct bp_target_info
*bp_tgt
;
8108 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8109 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8111 bp_tgt
->placed_address
= pc
;
8112 if (target_insert_breakpoint (bp_tgt
) != 0)
8114 /* Could not insert the breakpoint. */
8122 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8125 deprecated_remove_raw_breakpoint (void *bp
)
8127 struct bp_target_info
*bp_tgt
= bp
;
8130 ret
= target_remove_breakpoint (bp_tgt
);
8136 /* One (or perhaps two) breakpoints used for software single stepping. */
8138 static void *single_step_breakpoints
[2];
8140 /* Create and insert a breakpoint for software single step. */
8143 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8147 if (single_step_breakpoints
[0] == NULL
)
8148 bpt_p
= &single_step_breakpoints
[0];
8151 gdb_assert (single_step_breakpoints
[1] == NULL
);
8152 bpt_p
= &single_step_breakpoints
[1];
8155 /* NOTE drow/2006-04-11: A future improvement to this function would be
8156 to only create the breakpoints once, and actually put them on the
8157 breakpoint chain. That would let us use set_raw_breakpoint. We could
8158 adjust the addresses each time they were needed. Doing this requires
8159 corresponding changes elsewhere where single step breakpoints are
8160 handled, however. So, for now, we use this. */
8162 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8164 error (_("Could not insert single-step breakpoint at 0x%s"),
8165 paddr_nz (next_pc
));
8168 /* Remove and delete any breakpoints used for software single step. */
8171 remove_single_step_breakpoints (void)
8173 gdb_assert (single_step_breakpoints
[0] != NULL
);
8175 /* See insert_single_step_breakpoint for more about this deprecated
8177 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8178 single_step_breakpoints
[0] = NULL
;
8180 if (single_step_breakpoints
[1] != NULL
)
8182 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8183 single_step_breakpoints
[1] = NULL
;
8187 /* Check whether a software single-step breakpoint is inserted at PC. */
8190 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8194 for (i
= 0; i
< 2; i
++)
8196 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8197 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8205 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8206 It is defined as a macro to prevent duplication.
8207 COMMAND should be a string constant containing the name of the command. */
8208 #define BREAK_ARGS_HELP(command) \
8209 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8210 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8211 If a line number is specified, break at start of code for that line.\n\
8212 If a function is specified, break at start of code for that function.\n\
8213 If an address is specified, break at that exact address.\n\
8214 With no LOCATION, uses current execution address of selected stack frame.\n\
8215 This is useful for breaking on return to a stack frame.\n\
8217 THREADNUM is the number from \"info threads\".\n\
8218 CONDITION is a boolean expression.\n\
8220 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8222 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8225 _initialize_breakpoint (void)
8227 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8228 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8229 struct cmd_list_element
*c
;
8231 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8233 breakpoint_chain
= 0;
8234 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8235 before a breakpoint is set. */
8236 breakpoint_count
= 0;
8238 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8239 Set ignore-count of breakpoint number N to COUNT.\n\
8240 Usage is `ignore N COUNT'."));
8242 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8244 add_com ("commands", class_breakpoint
, commands_command
, _("\
8245 Set commands to be executed when a breakpoint is hit.\n\
8246 Give breakpoint number as argument after \"commands\".\n\
8247 With no argument, the targeted breakpoint is the last one set.\n\
8248 The commands themselves follow starting on the next line.\n\
8249 Type a line containing \"end\" to indicate the end of them.\n\
8250 Give \"silent\" as the first line to make the breakpoint silent;\n\
8251 then no output is printed when it is hit, except what the commands print."));
8253 add_com ("condition", class_breakpoint
, condition_command
, _("\
8254 Specify breakpoint number N to break only if COND is true.\n\
8255 Usage is `condition N COND', where N is an integer and COND is an\n\
8256 expression to be evaluated whenever breakpoint N is reached."));
8258 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8259 Set a temporary breakpoint.\n\
8260 Like \"break\" except the breakpoint is only temporary,\n\
8261 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8262 by using \"enable delete\" on the breakpoint number.\n\
8264 BREAK_ARGS_HELP ("tbreak")));
8265 set_cmd_completer (c
, location_completer
);
8267 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8268 Set a hardware assisted breakpoint.\n\
8269 Like \"break\" except the breakpoint requires hardware support,\n\
8270 some target hardware may not have this support.\n\
8272 BREAK_ARGS_HELP ("hbreak")));
8273 set_cmd_completer (c
, location_completer
);
8275 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8276 Set a temporary hardware assisted breakpoint.\n\
8277 Like \"hbreak\" except the breakpoint is only temporary,\n\
8278 so it will be deleted when hit.\n\
8280 BREAK_ARGS_HELP ("thbreak")));
8281 set_cmd_completer (c
, location_completer
);
8283 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8284 Enable some breakpoints.\n\
8285 Give breakpoint numbers (separated by spaces) as arguments.\n\
8286 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8287 This is used to cancel the effect of the \"disable\" command.\n\
8288 With a subcommand you can enable temporarily."),
8289 &enablelist
, "enable ", 1, &cmdlist
);
8291 add_com ("ab", class_breakpoint
, enable_command
, _("\
8292 Enable some breakpoints.\n\
8293 Give breakpoint numbers (separated by spaces) as arguments.\n\
8294 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8295 This is used to cancel the effect of the \"disable\" command.\n\
8296 With a subcommand you can enable temporarily."));
8298 add_com_alias ("en", "enable", class_breakpoint
, 1);
8300 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8301 Enable some breakpoints.\n\
8302 Give breakpoint numbers (separated by spaces) as arguments.\n\
8303 This is used to cancel the effect of the \"disable\" command.\n\
8304 May be abbreviated to simply \"enable\".\n"),
8305 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8307 add_cmd ("once", no_class
, enable_once_command
, _("\
8308 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8309 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8312 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8313 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8314 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8317 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8318 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8319 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8322 add_cmd ("once", no_class
, enable_once_command
, _("\
8323 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8324 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8327 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8328 Disable some breakpoints.\n\
8329 Arguments are breakpoint numbers with spaces in between.\n\
8330 To disable all breakpoints, give no argument.\n\
8331 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8332 &disablelist
, "disable ", 1, &cmdlist
);
8333 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8334 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8336 add_com ("sb", class_breakpoint
, disable_command
, _("\
8337 Disable some breakpoints.\n\
8338 Arguments are breakpoint numbers with spaces in between.\n\
8339 To disable all breakpoints, give no argument.\n\
8340 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8342 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8343 Disable some breakpoints.\n\
8344 Arguments are breakpoint numbers with spaces in between.\n\
8345 To disable all breakpoints, give no argument.\n\
8346 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8347 This command may be abbreviated \"disable\"."),
8350 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8351 Delete some breakpoints or auto-display expressions.\n\
8352 Arguments are breakpoint numbers with spaces in between.\n\
8353 To delete all breakpoints, give no argument.\n\
8355 Also a prefix command for deletion of other GDB objects.\n\
8356 The \"unset\" command is also an alias for \"delete\"."),
8357 &deletelist
, "delete ", 1, &cmdlist
);
8358 add_com_alias ("d", "delete", class_breakpoint
, 1);
8359 add_com_alias ("del", "delete", class_breakpoint
, 1);
8361 add_com ("db", class_breakpoint
, delete_command
, _("\
8362 Delete some breakpoints.\n\
8363 Arguments are breakpoint numbers with spaces in between.\n\
8364 To delete all breakpoints, give no argument.\n"));
8366 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8367 Delete some breakpoints or auto-display expressions.\n\
8368 Arguments are breakpoint numbers with spaces in between.\n\
8369 To delete all breakpoints, give no argument.\n\
8370 This command may be abbreviated \"delete\"."),
8373 add_com ("clear", class_breakpoint
, clear_command
, _("\
8374 Clear breakpoint at specified line or function.\n\
8375 Argument may be line number, function name, or \"*\" and an address.\n\
8376 If line number is specified, all breakpoints in that line are cleared.\n\
8377 If function is specified, breakpoints at beginning of function are cleared.\n\
8378 If an address is specified, breakpoints at that address are cleared.\n\
8380 With no argument, clears all breakpoints in the line that the selected frame\n\
8383 See also the \"delete\" command which clears breakpoints by number."));
8385 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8386 Set breakpoint at specified line or function.\n"
8387 BREAK_ARGS_HELP ("break")));
8388 set_cmd_completer (c
, location_completer
);
8390 add_com_alias ("b", "break", class_run
, 1);
8391 add_com_alias ("br", "break", class_run
, 1);
8392 add_com_alias ("bre", "break", class_run
, 1);
8393 add_com_alias ("brea", "break", class_run
, 1);
8397 add_com_alias ("ba", "break", class_breakpoint
, 1);
8398 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8403 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8404 Break in function/address or break at a line in the current file."),
8405 &stoplist
, "stop ", 1, &cmdlist
);
8406 add_cmd ("in", class_breakpoint
, stopin_command
,
8407 _("Break in function or address."), &stoplist
);
8408 add_cmd ("at", class_breakpoint
, stopat_command
,
8409 _("Break at a line in the current file."), &stoplist
);
8410 add_com ("status", class_info
, breakpoints_info
, _("\
8411 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8412 The \"Type\" column indicates one of:\n\
8413 \tbreakpoint - normal breakpoint\n\
8414 \twatchpoint - watchpoint\n\
8415 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8416 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8417 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8418 address and file/line number respectively.\n\
8420 Convenience variable \"$_\" and default examine address for \"x\"\n\
8421 are set to the address of the last breakpoint listed unless the command\n\
8422 is prefixed with \"server \".\n\n\
8423 Convenience variable \"$bpnum\" contains the number of the last\n\
8427 add_info ("breakpoints", breakpoints_info
, _("\
8428 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8429 The \"Type\" column indicates one of:\n\
8430 \tbreakpoint - normal breakpoint\n\
8431 \twatchpoint - watchpoint\n\
8432 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8433 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8434 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8435 address and file/line number respectively.\n\
8437 Convenience variable \"$_\" and default examine address for \"x\"\n\
8438 are set to the address of the last breakpoint listed unless the command\n\
8439 is prefixed with \"server \".\n\n\
8440 Convenience variable \"$bpnum\" contains the number of the last\n\
8444 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8445 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8446 The \"Type\" column indicates one of:\n\
8447 \tbreakpoint - normal breakpoint\n\
8448 \twatchpoint - watchpoint\n\
8449 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8450 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8451 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8452 address and file/line number respectively.\n\
8454 Convenience variable \"$_\" and default examine address for \"x\"\n\
8455 are set to the address of the last breakpoint listed unless the command\n\
8456 is prefixed with \"server \".\n\n\
8457 Convenience variable \"$bpnum\" contains the number of the last\n\
8460 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8461 Status of all breakpoints, or breakpoint number NUMBER.\n\
8462 The \"Type\" column indicates one of:\n\
8463 \tbreakpoint - normal breakpoint\n\
8464 \twatchpoint - watchpoint\n\
8465 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8466 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8467 \tuntil - internal breakpoint used by the \"until\" command\n\
8468 \tfinish - internal breakpoint used by the \"finish\" command\n\
8469 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8470 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8471 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8472 address and file/line number respectively.\n\
8474 Convenience variable \"$_\" and default examine address for \"x\"\n\
8475 are set to the address of the last breakpoint listed unless the command\n\
8476 is prefixed with \"server \".\n\n\
8477 Convenience variable \"$bpnum\" contains the number of the last\n\
8479 &maintenanceinfolist
);
8481 add_com ("catch", class_breakpoint
, catch_command
, _("\
8482 Set catchpoints to catch events.\n\
8483 Raised signals may be caught:\n\
8484 \tcatch signal - all signals\n\
8485 \tcatch signal <signame> - a particular signal\n\
8486 Raised exceptions may be caught:\n\
8487 \tcatch throw - all exceptions, when thrown\n\
8488 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8489 \tcatch catch - all exceptions, when caught\n\
8490 \tcatch catch <exceptname> - a particular exception, when caught\n\
8491 Thread or process events may be caught:\n\
8492 \tcatch thread_start - any threads, just after creation\n\
8493 \tcatch thread_exit - any threads, just before expiration\n\
8494 \tcatch thread_join - any threads, just after joins\n\
8495 Process events may be caught:\n\
8496 \tcatch start - any processes, just after creation\n\
8497 \tcatch exit - any processes, just before expiration\n\
8498 \tcatch fork - calls to fork()\n\
8499 \tcatch vfork - calls to vfork()\n\
8500 \tcatch exec - calls to exec()\n\
8501 Dynamically-linked library events may be caught:\n\
8502 \tcatch load - loads of any library\n\
8503 \tcatch load <libname> - loads of a particular library\n\
8504 \tcatch unload - unloads of any library\n\
8505 \tcatch unload <libname> - unloads of a particular library\n\
8506 The act of your program's execution stopping may also be caught:\n\
8508 C++ exceptions may be caught:\n\
8509 \tcatch throw - all exceptions, when thrown\n\
8510 \tcatch catch - all exceptions, when caught\n\
8511 Ada exceptions may be caught:\n\
8512 \tcatch exception - all exceptions, when raised\n\
8513 \tcatch exception <name> - a particular exception, when raised\n\
8514 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8515 \tcatch assert - all failed assertions, when raised\n\
8517 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8518 after a fork or vfork is caught.\n\n\
8519 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8521 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8522 Set temporary catchpoints to catch events.\n\
8523 Args like \"catch\" command.\n\
8524 Like \"catch\" except the catchpoint is only temporary,\n\
8525 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8526 by using \"enable delete\" on the catchpoint number."));
8528 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8529 Set a watchpoint for an expression.\n\
8530 A watchpoint stops execution of your program whenever the value of\n\
8531 an expression changes."));
8532 set_cmd_completer (c
, location_completer
);
8534 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8535 Set a read watchpoint for an expression.\n\
8536 A watchpoint stops execution of your program whenever the value of\n\
8537 an expression is read."));
8538 set_cmd_completer (c
, location_completer
);
8540 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8541 Set a watchpoint for an expression.\n\
8542 A watchpoint stops execution of your program whenever the value of\n\
8543 an expression is either read or written."));
8544 set_cmd_completer (c
, location_completer
);
8546 add_info ("watchpoints", breakpoints_info
,
8547 _("Synonym for ``info breakpoints''."));
8550 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8551 respond to changes - contrary to the description. */
8552 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8553 &can_use_hw_watchpoints
, _("\
8554 Set debugger's willingness to use watchpoint hardware."), _("\
8555 Show debugger's willingness to use watchpoint hardware."), _("\
8556 If zero, gdb will not use hardware for new watchpoints, even if\n\
8557 such is available. (However, any hardware watchpoints that were\n\
8558 created before setting this to nonzero, will continue to use watchpoint\n\
8561 show_can_use_hw_watchpoints
,
8562 &setlist
, &showlist
);
8564 can_use_hw_watchpoints
= 1;
8566 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8567 Breakpoint specific settings\n\
8568 Configure various breakpoint-specific variables such as\n\
8569 pending breakpoint behavior"),
8570 &breakpoint_set_cmdlist
, "set breakpoint ",
8571 0/*allow-unknown*/, &setlist
);
8572 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8573 Breakpoint specific settings\n\
8574 Configure various breakpoint-specific variables such as\n\
8575 pending breakpoint behavior"),
8576 &breakpoint_show_cmdlist
, "show breakpoint ",
8577 0/*allow-unknown*/, &showlist
);
8579 add_setshow_auto_boolean_cmd ("pending", no_class
,
8580 &pending_break_support
, _("\
8581 Set debugger's behavior regarding pending breakpoints."), _("\
8582 Show debugger's behavior regarding pending breakpoints."), _("\
8583 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8584 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8585 an error. If auto, an unrecognized breakpoint location results in a\n\
8586 user-query to see if a pending breakpoint should be created."),
8588 show_pending_break_support
,
8589 &breakpoint_set_cmdlist
,
8590 &breakpoint_show_cmdlist
);
8592 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8594 add_setshow_boolean_cmd ("auto-hw", no_class
,
8595 &automatic_hardware_breakpoints
, _("\
8596 Set automatic usage of hardware breakpoints."), _("\
8597 Show automatic usage of hardware breakpoints."), _("\
8598 If set, the debugger will automatically use hardware breakpoints for\n\
8599 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8600 a warning will be emitted for such breakpoints."),
8602 show_automatic_hardware_breakpoints
,
8603 &breakpoint_set_cmdlist
,
8604 &breakpoint_show_cmdlist
);
8606 automatic_hardware_breakpoints
= 1;