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 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1761 but it only returns true if there is actually a breakpoint inserted
1765 breakpoint_inserted_here_p (CORE_ADDR pc
)
1767 const struct bp_location
*bpt
;
1769 ALL_BP_LOCATIONS (bpt
)
1771 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1772 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1776 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1778 if (overlay_debugging
1779 && section_is_overlay (bpt
->section
)
1780 && !section_is_mapped (bpt
->section
))
1781 continue; /* unmapped overlay -- can't be a match */
1787 /* Also check for software single-step breakpoints. */
1788 if (single_step_breakpoint_inserted_here_p (pc
))
1794 /* This function returns non-zero iff there is a software breakpoint
1798 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1800 const struct bp_location
*bpt
;
1801 int any_breakpoint_here
= 0;
1803 ALL_BP_LOCATIONS (bpt
)
1805 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1809 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1811 if (overlay_debugging
1812 && section_is_overlay (bpt
->section
)
1813 && !section_is_mapped (bpt
->section
))
1814 continue; /* unmapped overlay -- can't be a match */
1820 /* Also check for software single-step breakpoints. */
1821 if (single_step_breakpoint_inserted_here_p (pc
))
1827 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1828 PC is valid for process/thread PTID. */
1831 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1833 const struct bp_location
*bpt
;
1836 thread
= pid_to_thread_id (ptid
);
1838 ALL_BP_LOCATIONS (bpt
)
1840 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1841 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1844 if ((breakpoint_enabled (bpt
->owner
)
1845 || bpt
->owner
->enable_state
== bp_permanent
)
1846 && bpt
->address
== pc
1847 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1849 if (overlay_debugging
1850 && section_is_overlay (bpt
->section
)
1851 && !section_is_mapped (bpt
->section
))
1852 continue; /* unmapped overlay -- can't be a match */
1862 /* bpstat stuff. External routines' interfaces are documented
1866 ep_is_catchpoint (struct breakpoint
*ep
)
1869 (ep
->type
== bp_catch_load
)
1870 || (ep
->type
== bp_catch_unload
)
1871 || (ep
->type
== bp_catch_fork
)
1872 || (ep
->type
== bp_catch_vfork
)
1873 || (ep
->type
== bp_catch_exec
)
1874 || (ep
->type
== bp_catch_catch
)
1875 || (ep
->type
== bp_catch_throw
);
1877 /* ??rehrauer: Add more kinds here, as are implemented... */
1881 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1884 (ep
->type
== bp_catch_load
)
1885 || (ep
->type
== bp_catch_unload
);
1889 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1892 (ep
->type
== bp_catch_catch
)
1893 || (ep
->type
== bp_catch_throw
);
1897 bpstat_free (bpstat bs
)
1899 if (bs
->old_val
!= NULL
)
1900 value_free (bs
->old_val
);
1901 free_command_lines (&bs
->commands
);
1905 /* Clear a bpstat so that it says we are not at any breakpoint.
1906 Also free any storage that is part of a bpstat. */
1909 bpstat_clear (bpstat
*bsp
)
1926 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1927 is part of the bpstat is copied as well. */
1930 bpstat_copy (bpstat bs
)
1934 bpstat retval
= NULL
;
1939 for (; bs
!= NULL
; bs
= bs
->next
)
1941 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1942 memcpy (tmp
, bs
, sizeof (*tmp
));
1943 if (bs
->commands
!= NULL
)
1944 tmp
->commands
= copy_command_lines (bs
->commands
);
1945 if (bs
->old_val
!= NULL
)
1946 tmp
->old_val
= value_copy (bs
->old_val
);
1949 /* This is the first thing in the chain. */
1959 /* Find the bpstat associated with this breakpoint */
1962 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1967 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1969 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
1975 /* Find a step_resume breakpoint associated with this bpstat.
1976 (If there are multiple step_resume bp's on the list, this function
1977 will arbitrarily pick one.)
1979 It is an error to use this function if BPSTAT doesn't contain a
1980 step_resume breakpoint.
1982 See wait_for_inferior's use of this function. */
1984 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1988 gdb_assert (bsp
!= NULL
);
1990 current_thread
= pid_to_thread_id (inferior_ptid
);
1992 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1994 if ((bsp
->breakpoint_at
!= NULL
) &&
1995 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
1996 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
1997 bsp
->breakpoint_at
->owner
->thread
== -1))
1998 return bsp
->breakpoint_at
->owner
;
2001 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2005 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2006 at. *BSP upon return is a bpstat which points to the remaining
2007 breakpoints stopped at (but which is not guaranteed to be good for
2008 anything but further calls to bpstat_num).
2009 Return 0 if passed a bpstat which does not indicate any breakpoints.
2010 Return -1 if stopped at a breakpoint that has been deleted since
2012 Return 1 otherwise. */
2015 bpstat_num (bpstat
*bsp
, int *num
)
2017 struct breakpoint
*b
;
2020 return 0; /* No more breakpoint values */
2022 /* We assume we'll never have several bpstats that
2023 correspond to a single breakpoint -- otherwise,
2024 this function might return the same number more
2025 than once and this will look ugly. */
2026 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2027 *bsp
= (*bsp
)->next
;
2029 return -1; /* breakpoint that's been deleted since */
2031 *num
= b
->number
; /* We have its number */
2035 /* Modify BS so that the actions will not be performed. */
2038 bpstat_clear_actions (bpstat bs
)
2040 for (; bs
!= NULL
; bs
= bs
->next
)
2042 free_command_lines (&bs
->commands
);
2043 if (bs
->old_val
!= NULL
)
2045 value_free (bs
->old_val
);
2051 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2053 cleanup_executing_breakpoints (void *ignore
)
2055 executing_breakpoint_commands
= 0;
2058 /* Execute all the commands associated with all the breakpoints at this
2059 location. Any of these commands could cause the process to proceed
2060 beyond this point, etc. We look out for such changes by checking
2061 the global "breakpoint_proceeded" after each command. */
2064 bpstat_do_actions (bpstat
*bsp
)
2067 struct cleanup
*old_chain
;
2069 /* Avoid endless recursion if a `source' command is contained
2071 if (executing_breakpoint_commands
)
2074 executing_breakpoint_commands
= 1;
2075 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2078 /* Note that (as of this writing), our callers all appear to
2079 be passing us the address of global stop_bpstat. And, if
2080 our calls to execute_control_command cause the inferior to
2081 proceed, that global (and hence, *bsp) will change.
2083 We must be careful to not touch *bsp unless the inferior
2084 has not proceeded. */
2086 /* This pointer will iterate over the list of bpstat's. */
2089 breakpoint_proceeded
= 0;
2090 for (; bs
!= NULL
; bs
= bs
->next
)
2092 struct command_line
*cmd
;
2093 struct cleanup
*this_cmd_tree_chain
;
2095 /* Take ownership of the BSP's command tree, if it has one.
2097 The command tree could legitimately contain commands like
2098 'step' and 'next', which call clear_proceed_status, which
2099 frees stop_bpstat's command tree. To make sure this doesn't
2100 free the tree we're executing out from under us, we need to
2101 take ownership of the tree ourselves. Since a given bpstat's
2102 commands are only executed once, we don't need to copy it; we
2103 can clear the pointer in the bpstat, and make sure we free
2104 the tree when we're done. */
2107 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2111 execute_control_command (cmd
);
2113 if (breakpoint_proceeded
)
2119 /* We can free this command tree now. */
2120 do_cleanups (this_cmd_tree_chain
);
2122 if (breakpoint_proceeded
)
2123 /* The inferior is proceeded by the command; bomb out now.
2124 The bpstat chain has been blown away by wait_for_inferior.
2125 But since execution has stopped again, there is a new bpstat
2126 to look at, so start over. */
2129 do_cleanups (old_chain
);
2132 /* This is the normal print function for a bpstat. In the future,
2133 much of this logic could (should?) be moved to bpstat_stop_status,
2134 by having it set different print_it values.
2136 Current scheme: When we stop, bpstat_print() is called. It loops
2137 through the bpstat list of things causing this stop, calling the
2138 print_bp_stop_message function on each one. The behavior of the
2139 print_bp_stop_message function depends on the print_it field of
2140 bpstat. If such field so indicates, call this function here.
2142 Return values from this routine (ultimately used by bpstat_print()
2143 and normal_stop() to decide what to do):
2144 PRINT_NOTHING: Means we already printed all we needed to print,
2145 don't print anything else.
2146 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2147 that something to be followed by a location.
2148 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2149 that something to be followed by a location.
2150 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2153 static enum print_stop_action
2154 print_it_typical (bpstat bs
)
2156 struct cleanup
*old_chain
, *ui_out_chain
;
2157 struct breakpoint
*b
;
2158 const struct bp_location
*bl
;
2159 struct ui_stream
*stb
;
2160 stb
= ui_out_stream_new (uiout
);
2161 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2162 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2163 which has since been deleted. */
2164 if (bs
->breakpoint_at
== NULL
)
2165 return PRINT_UNKNOWN
;
2166 bl
= bs
->breakpoint_at
;
2172 case bp_hardware_breakpoint
:
2173 if (bl
->address
!= bl
->requested_address
)
2174 breakpoint_adjustment_warning (bl
->requested_address
,
2177 annotate_breakpoint (b
->number
);
2178 ui_out_text (uiout
, "\nBreakpoint ");
2179 if (ui_out_is_mi_like_p (uiout
))
2180 ui_out_field_string (uiout
, "reason",
2181 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2182 ui_out_field_int (uiout
, "bkptno", b
->number
);
2183 ui_out_text (uiout
, ", ");
2184 return PRINT_SRC_AND_LOC
;
2187 case bp_shlib_event
:
2188 /* Did we stop because the user set the stop_on_solib_events
2189 variable? (If so, we report this as a generic, "Stopped due
2190 to shlib event" message.) */
2191 printf_filtered (_("Stopped due to shared library event\n"));
2192 return PRINT_NOTHING
;
2195 case bp_thread_event
:
2196 /* Not sure how we will get here.
2197 GDB should not stop for these breakpoints. */
2198 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2199 return PRINT_NOTHING
;
2202 case bp_overlay_event
:
2203 /* By analogy with the thread event, GDB should not stop for these. */
2204 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2205 return PRINT_NOTHING
;
2209 annotate_catchpoint (b
->number
);
2210 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2212 b
->triggered_dll_pathname
);
2213 return PRINT_SRC_AND_LOC
;
2216 case bp_catch_unload
:
2217 annotate_catchpoint (b
->number
);
2218 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2220 b
->triggered_dll_pathname
);
2221 return PRINT_SRC_AND_LOC
;
2225 annotate_catchpoint (b
->number
);
2226 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2228 b
->forked_inferior_pid
);
2229 return PRINT_SRC_AND_LOC
;
2232 case bp_catch_vfork
:
2233 annotate_catchpoint (b
->number
);
2234 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2236 b
->forked_inferior_pid
);
2237 return PRINT_SRC_AND_LOC
;
2241 annotate_catchpoint (b
->number
);
2242 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2245 return PRINT_SRC_AND_LOC
;
2248 case bp_catch_catch
:
2249 if (current_exception_event
&&
2250 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2252 annotate_catchpoint (b
->number
);
2253 printf_filtered (_("\nCatchpoint %d (exception caught), "),
2255 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2256 printf_filtered (_("throw location %s:%d, "),
2257 CURRENT_EXCEPTION_THROW_FILE
,
2258 CURRENT_EXCEPTION_THROW_LINE
);
2260 printf_filtered (_("throw location unknown, "));
2262 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2263 printf_filtered (_("catch location %s:%d\n"),
2264 CURRENT_EXCEPTION_CATCH_FILE
,
2265 CURRENT_EXCEPTION_CATCH_LINE
);
2267 printf_filtered (_("catch location unknown\n"));
2269 /* don't bother to print location frame info */
2270 return PRINT_SRC_ONLY
;
2274 /* really throw, some other bpstat will handle it */
2275 return PRINT_UNKNOWN
;
2279 case bp_catch_throw
:
2280 if (current_exception_event
&&
2281 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2283 annotate_catchpoint (b
->number
);
2284 printf_filtered (_("\nCatchpoint %d (exception thrown), "),
2286 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2287 printf_filtered (_("throw location %s:%d, "),
2288 CURRENT_EXCEPTION_THROW_FILE
,
2289 CURRENT_EXCEPTION_THROW_LINE
);
2291 printf_filtered (_("throw location unknown, "));
2293 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2294 printf_filtered (_("catch location %s:%d\n"),
2295 CURRENT_EXCEPTION_CATCH_FILE
,
2296 CURRENT_EXCEPTION_CATCH_LINE
);
2298 printf_filtered (_("catch location unknown\n"));
2300 /* don't bother to print location frame info */
2301 return PRINT_SRC_ONLY
;
2305 /* really catch, some other bpstat will handle it */
2306 return PRINT_UNKNOWN
;
2311 case bp_hardware_watchpoint
:
2312 if (bs
->old_val
!= NULL
)
2314 annotate_watchpoint (b
->number
);
2315 if (ui_out_is_mi_like_p (uiout
))
2318 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2320 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2321 ui_out_text (uiout
, "\nOld value = ");
2322 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2323 ui_out_field_stream (uiout
, "old", stb
);
2324 ui_out_text (uiout
, "\nNew value = ");
2325 value_print (b
->val
, stb
->stream
, 0, Val_pretty_default
);
2326 ui_out_field_stream (uiout
, "new", stb
);
2327 do_cleanups (ui_out_chain
);
2328 ui_out_text (uiout
, "\n");
2329 value_free (bs
->old_val
);
2332 /* More than one watchpoint may have been triggered. */
2333 return PRINT_UNKNOWN
;
2336 case bp_read_watchpoint
:
2337 if (ui_out_is_mi_like_p (uiout
))
2340 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2342 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2343 ui_out_text (uiout
, "\nValue = ");
2344 value_print (b
->val
, stb
->stream
, 0, Val_pretty_default
);
2345 ui_out_field_stream (uiout
, "value", stb
);
2346 do_cleanups (ui_out_chain
);
2347 ui_out_text (uiout
, "\n");
2348 return PRINT_UNKNOWN
;
2351 case bp_access_watchpoint
:
2352 if (bs
->old_val
!= NULL
)
2354 annotate_watchpoint (b
->number
);
2355 if (ui_out_is_mi_like_p (uiout
))
2358 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2360 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2361 ui_out_text (uiout
, "\nOld value = ");
2362 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2363 ui_out_field_stream (uiout
, "old", stb
);
2364 value_free (bs
->old_val
);
2366 ui_out_text (uiout
, "\nNew value = ");
2371 if (ui_out_is_mi_like_p (uiout
))
2374 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2375 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2376 ui_out_text (uiout
, "\nValue = ");
2378 value_print (b
->val
, stb
->stream
, 0,Val_pretty_default
);
2379 ui_out_field_stream (uiout
, "new", stb
);
2380 do_cleanups (ui_out_chain
);
2381 ui_out_text (uiout
, "\n");
2382 return PRINT_UNKNOWN
;
2385 /* Fall through, we don't deal with these types of breakpoints
2389 if (ui_out_is_mi_like_p (uiout
))
2392 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2393 return PRINT_UNKNOWN
;
2397 if (ui_out_is_mi_like_p (uiout
))
2400 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2401 return PRINT_UNKNOWN
;
2406 case bp_longjmp_resume
:
2407 case bp_step_resume
:
2408 case bp_watchpoint_scope
:
2411 return PRINT_UNKNOWN
;
2415 /* Generic routine for printing messages indicating why we
2416 stopped. The behavior of this function depends on the value
2417 'print_it' in the bpstat structure. Under some circumstances we
2418 may decide not to print anything here and delegate the task to
2421 static enum print_stop_action
2422 print_bp_stop_message (bpstat bs
)
2424 switch (bs
->print_it
)
2427 /* Nothing should be printed for this bpstat entry. */
2428 return PRINT_UNKNOWN
;
2432 /* We still want to print the frame, but we already printed the
2433 relevant messages. */
2434 return PRINT_SRC_AND_LOC
;
2437 case print_it_normal
:
2439 const struct bp_location
*bl
= bs
->breakpoint_at
;
2440 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2442 /* Normal case. Call the breakpoint's print_it method, or
2443 print_it_typical. */
2444 /* FIXME: how breakpoint can ever be NULL here? */
2445 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2446 return b
->ops
->print_it (b
);
2448 return print_it_typical (bs
);
2453 internal_error (__FILE__
, __LINE__
,
2454 _("print_bp_stop_message: unrecognized enum value"));
2459 /* Print a message indicating what happened. This is called from
2460 normal_stop(). The input to this routine is the head of the bpstat
2461 list - a list of the eventpoints that caused this stop. This
2462 routine calls the generic print routine for printing a message
2463 about reasons for stopping. This will print (for example) the
2464 "Breakpoint n," part of the output. The return value of this
2467 PRINT_UNKNOWN: Means we printed nothing
2468 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2469 code to print the location. An example is
2470 "Breakpoint 1, " which should be followed by
2472 PRINT_SRC_ONLY: Means we printed something, but there is no need
2473 to also print the location part of the message.
2474 An example is the catch/throw messages, which
2475 don't require a location appended to the end.
2476 PRINT_NOTHING: We have done some printing and we don't need any
2477 further info to be printed.*/
2479 enum print_stop_action
2480 bpstat_print (bpstat bs
)
2484 /* Maybe another breakpoint in the chain caused us to stop.
2485 (Currently all watchpoints go on the bpstat whether hit or not.
2486 That probably could (should) be changed, provided care is taken
2487 with respect to bpstat_explains_signal). */
2488 for (; bs
; bs
= bs
->next
)
2490 val
= print_bp_stop_message (bs
);
2491 if (val
== PRINT_SRC_ONLY
2492 || val
== PRINT_SRC_AND_LOC
2493 || val
== PRINT_NOTHING
)
2497 /* We reached the end of the chain, or we got a null BS to start
2498 with and nothing was printed. */
2499 return PRINT_UNKNOWN
;
2502 /* Evaluate the expression EXP and return 1 if value is zero.
2503 This is used inside a catch_errors to evaluate the breakpoint condition.
2504 The argument is a "struct expression *" that has been cast to char * to
2505 make it pass through catch_errors. */
2508 breakpoint_cond_eval (void *exp
)
2510 struct value
*mark
= value_mark ();
2511 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2512 value_free_to_mark (mark
);
2516 /* Allocate a new bpstat and chain it to the current one. */
2519 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2523 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2525 bs
->breakpoint_at
= bl
;
2526 /* If the condition is false, etc., don't do the commands. */
2527 bs
->commands
= NULL
;
2529 bs
->print_it
= print_it_normal
;
2533 /* The target has stopped with waitstatus WS. Check if any hardware
2534 watchpoints have triggered, according to the target. */
2537 watchpoints_triggered (struct target_waitstatus
*ws
)
2539 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2541 struct breakpoint
*b
;
2543 if (!stopped_by_watchpoint
)
2545 /* We were not stopped by a watchpoint. Mark all watchpoints
2546 as not triggered. */
2548 if (b
->type
== bp_hardware_watchpoint
2549 || b
->type
== bp_read_watchpoint
2550 || b
->type
== bp_access_watchpoint
)
2551 b
->watchpoint_triggered
= watch_triggered_no
;
2556 if (!target_stopped_data_address (¤t_target
, &addr
))
2558 /* We were stopped by a watchpoint, but we don't know where.
2559 Mark all watchpoints as unknown. */
2561 if (b
->type
== bp_hardware_watchpoint
2562 || b
->type
== bp_read_watchpoint
2563 || b
->type
== bp_access_watchpoint
)
2564 b
->watchpoint_triggered
= watch_triggered_unknown
;
2566 return stopped_by_watchpoint
;
2569 /* The target could report the data address. Mark watchpoints
2570 affected by this data address as triggered, and all others as not
2574 if (b
->type
== bp_hardware_watchpoint
2575 || b
->type
== bp_read_watchpoint
2576 || b
->type
== bp_access_watchpoint
)
2580 b
->watchpoint_triggered
= watch_triggered_no
;
2581 for (v
= b
->val_chain
; v
; v
= value_next (v
))
2583 if (VALUE_LVAL (v
) == lval_memory
&& ! value_lazy (v
))
2585 struct type
*vtype
= check_typedef (value_type (v
));
2587 if (v
== b
->val_chain
2588 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2589 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2593 vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
2594 /* Exact match not required. Within range is
2597 && addr
< vaddr
+ TYPE_LENGTH (value_type (v
)))
2599 b
->watchpoint_triggered
= watch_triggered_yes
;
2610 /* Possible return values for watchpoint_check (this can't be an enum
2611 because of check_errors). */
2612 /* The watchpoint has been deleted. */
2613 #define WP_DELETED 1
2614 /* The value has changed. */
2615 #define WP_VALUE_CHANGED 2
2616 /* The value has not changed. */
2617 #define WP_VALUE_NOT_CHANGED 3
2619 #define BP_TEMPFLAG 1
2620 #define BP_HARDWAREFLAG 2
2622 /* Check watchpoint condition. */
2625 watchpoint_check (void *p
)
2627 bpstat bs
= (bpstat
) p
;
2628 struct breakpoint
*b
;
2629 struct frame_info
*fr
;
2630 int within_current_scope
;
2632 b
= bs
->breakpoint_at
->owner
;
2634 if (b
->exp_valid_block
== NULL
)
2635 within_current_scope
= 1;
2638 /* There is no current frame at this moment. If we're going to have
2639 any chance of handling watchpoints on local variables, we'll need
2640 the frame chain (so we can determine if we're in scope). */
2641 reinit_frame_cache ();
2642 fr
= frame_find_by_id (b
->watchpoint_frame
);
2643 within_current_scope
= (fr
!= NULL
);
2645 /* If we've gotten confused in the unwinder, we might have
2646 returned a frame that can't describe this variable. */
2647 if (within_current_scope
2648 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2649 within_current_scope
= 0;
2651 /* in_function_epilogue_p() returns a non-zero value if we're still
2652 in the function but the stack frame has already been invalidated.
2653 Since we can't rely on the values of local variables after the
2654 stack has been destroyed, we are treating the watchpoint in that
2655 state as `not changed' without further checking.
2657 vinschen/2003-09-04: The former implementation left out the case
2658 that the watchpoint frame couldn't be found by frame_find_by_id()
2659 because the current PC is currently in an epilogue. Calling
2660 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2661 if ((!within_current_scope
|| fr
== get_current_frame ())
2662 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2663 return WP_VALUE_NOT_CHANGED
;
2664 if (fr
&& within_current_scope
)
2665 /* If we end up stopping, the current frame will get selected
2666 in normal_stop. So this call to select_frame won't affect
2671 if (within_current_scope
)
2673 /* We use value_{,free_to_}mark because it could be a
2674 *long* time before we return to the command level and
2675 call free_all_values. We can't call free_all_values because
2676 we might be in the middle of evaluating a function call. */
2678 struct value
*mark
= value_mark ();
2679 struct value
*new_val
= evaluate_expression (b
->exp
);
2680 if (!value_equal (b
->val
, new_val
))
2682 release_value (new_val
);
2683 value_free_to_mark (mark
);
2684 bs
->old_val
= b
->val
;
2686 /* We will stop here */
2687 return WP_VALUE_CHANGED
;
2691 /* Nothing changed, don't do anything. */
2692 value_free_to_mark (mark
);
2693 /* We won't stop here */
2694 return WP_VALUE_NOT_CHANGED
;
2699 /* This seems like the only logical thing to do because
2700 if we temporarily ignored the watchpoint, then when
2701 we reenter the block in which it is valid it contains
2702 garbage (in the case of a function, it may have two
2703 garbage values, one before and one after the prologue).
2704 So we can't even detect the first assignment to it and
2705 watch after that (since the garbage may or may not equal
2706 the first value assigned). */
2707 /* We print all the stop information in print_it_typical(), but
2708 in this case, by the time we call print_it_typical() this bp
2709 will be deleted already. So we have no choice but print the
2710 information here. */
2711 if (ui_out_is_mi_like_p (uiout
))
2713 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2714 ui_out_text (uiout
, "\nWatchpoint ");
2715 ui_out_field_int (uiout
, "wpnum", b
->number
);
2716 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2717 which its expression is valid.\n");
2719 if (b
->related_breakpoint
)
2720 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2721 b
->disposition
= disp_del_at_next_stop
;
2727 /* Get a bpstat associated with having just stopped at address
2728 BP_ADDR in thread PTID.
2730 Determine whether we stopped at a breakpoint, etc, or whether we
2731 don't understand this stop. Result is a chain of bpstat's such that:
2733 if we don't understand the stop, the result is a null pointer.
2735 if we understand why we stopped, the result is not null.
2737 Each element of the chain refers to a particular breakpoint or
2738 watchpoint at which we have stopped. (We may have stopped for
2739 several reasons concurrently.)
2741 Each element of the chain has valid next, breakpoint_at,
2742 commands, FIXME??? fields. */
2745 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2747 struct breakpoint
*b
= NULL
;
2748 const struct bp_location
*bl
;
2749 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2750 int real_breakpoint
= 0;
2751 /* Root of the chain of bpstat's */
2752 struct bpstats root_bs
[1];
2753 /* Pointer to the last thing in the chain currently. */
2754 bpstat bs
= root_bs
;
2755 int thread_id
= pid_to_thread_id (ptid
);
2757 ALL_BP_LOCATIONS (bl
)
2761 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2764 if (b
->type
!= bp_watchpoint
2765 && b
->type
!= bp_hardware_watchpoint
2766 && b
->type
!= bp_read_watchpoint
2767 && b
->type
!= bp_access_watchpoint
2768 && b
->type
!= bp_hardware_breakpoint
2769 && b
->type
!= bp_catch_fork
2770 && b
->type
!= bp_catch_vfork
2771 && b
->type
!= bp_catch_exec
2772 && b
->type
!= bp_catch_catch
2773 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2775 if (bl
->address
!= bp_addr
) /* address doesn't match */
2777 if (overlay_debugging
/* unmapped overlay section */
2778 && section_is_overlay (bl
->section
)
2779 && !section_is_mapped (bl
->section
))
2783 /* Continuable hardware watchpoints are treated as non-existent if the
2784 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2785 some data address). Otherwise gdb won't stop on a break instruction
2786 in the code (not from a breakpoint) when a hardware watchpoint has
2787 been defined. Also skip watchpoints which we know did not trigger
2788 (did not match the data address). */
2790 if ((b
->type
== bp_hardware_watchpoint
2791 || b
->type
== bp_read_watchpoint
2792 || b
->type
== bp_access_watchpoint
)
2793 && b
->watchpoint_triggered
== watch_triggered_no
)
2796 if (b
->type
== bp_hardware_breakpoint
)
2798 if (bl
->address
!= bp_addr
)
2800 if (overlay_debugging
/* unmapped overlay section */
2801 && section_is_overlay (bl
->section
)
2802 && !section_is_mapped (bl
->section
))
2806 /* Is this a catchpoint of a load or unload? If so, did we
2807 get a load or unload of the specified library? If not,
2809 if ((b
->type
== bp_catch_load
)
2810 #if defined(SOLIB_HAVE_LOAD_EVENT)
2811 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2812 || ((b
->dll_pathname
!= NULL
)
2813 && (strcmp (b
->dll_pathname
,
2814 SOLIB_LOADED_LIBRARY_PATHNAME (
2815 PIDGET (inferior_ptid
)))
2821 if ((b
->type
== bp_catch_unload
)
2822 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2823 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2824 || ((b
->dll_pathname
!= NULL
)
2825 && (strcmp (b
->dll_pathname
,
2826 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2827 PIDGET (inferior_ptid
)))
2833 if ((b
->type
== bp_catch_fork
)
2834 && !inferior_has_forked (PIDGET (inferior_ptid
),
2835 &b
->forked_inferior_pid
))
2838 if ((b
->type
== bp_catch_vfork
)
2839 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2840 &b
->forked_inferior_pid
))
2843 if ((b
->type
== bp_catch_exec
)
2844 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2847 if (ep_is_exception_catchpoint (b
) &&
2848 !(current_exception_event
= target_get_current_exception_event ()))
2851 /* Come here if it's a watchpoint, or if the break address matches */
2853 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
2855 /* Watchpoints may change this, if not found to have triggered. */
2859 if (b
->type
== bp_watchpoint
2860 || b
->type
== bp_read_watchpoint
2861 || b
->type
== bp_access_watchpoint
2862 || b
->type
== bp_hardware_watchpoint
)
2866 int must_check_value
= 0;
2868 if (b
->type
== bp_watchpoint
)
2869 /* For a software watchpoint, we must always check the
2871 must_check_value
= 1;
2872 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2873 /* We have a hardware watchpoint (read, write, or access)
2874 and the target earlier reported an address watched by
2876 must_check_value
= 1;
2877 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2878 && b
->type
== bp_hardware_watchpoint
)
2879 /* We were stopped by a hardware watchpoint, but the target could
2880 not report the data address. We must check the watchpoint's
2881 value. Access and read watchpoints are out of luck; without
2882 a data address, we can't figure it out. */
2883 must_check_value
= 1;
2885 if (must_check_value
)
2887 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2889 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2890 int e
= catch_errors (watchpoint_check
, bs
, message
,
2892 do_cleanups (cleanups
);
2896 /* We've already printed what needs to be printed. */
2897 bs
->print_it
= print_it_done
;
2900 case WP_VALUE_CHANGED
:
2901 if (b
->type
== bp_read_watchpoint
)
2903 /* Don't stop: read watchpoints shouldn't fire if
2904 the value has changed. This is for targets
2905 which cannot set read-only watchpoints. */
2906 bs
->print_it
= print_it_noop
;
2912 case WP_VALUE_NOT_CHANGED
:
2913 if (b
->type
== bp_hardware_watchpoint
2914 || b
->type
== bp_watchpoint
)
2916 /* Don't stop: write watchpoints shouldn't fire if
2917 the value hasn't changed. */
2918 bs
->print_it
= print_it_noop
;
2928 /* Error from catch_errors. */
2929 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2930 if (b
->related_breakpoint
)
2931 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2932 b
->disposition
= disp_del_at_next_stop
;
2933 /* We've already printed what needs to be printed. */
2934 bs
->print_it
= print_it_done
;
2938 else /* must_check_value == 0 */
2940 /* This is a case where some watchpoint(s) triggered, but
2941 not at the address of this watchpoint, or else no
2942 watchpoint triggered after all. So don't print
2943 anything for this watchpoint. */
2944 bs
->print_it
= print_it_noop
;
2951 /* By definition, an encountered breakpoint is a triggered
2955 real_breakpoint
= 1;
2958 if (frame_id_p (b
->frame_id
)
2959 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2963 int value_is_zero
= 0;
2965 /* If this is a scope breakpoint, mark the associated
2966 watchpoint as triggered so that we will handle the
2967 out-of-scope event. We'll get to the watchpoint next
2969 if (b
->type
== bp_watchpoint_scope
)
2970 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2974 /* Need to select the frame, with all that implies
2975 so that the conditions will have the right context. */
2976 select_frame (get_current_frame ());
2978 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2979 "Error in testing breakpoint condition:\n",
2981 /* FIXME-someday, should give breakpoint # */
2984 if (bl
->cond
&& value_is_zero
)
2987 /* Don't consider this a hit. */
2990 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2993 /* Don't consider this a hit. */
2996 else if (b
->ignore_count
> 0)
2999 annotate_ignore_count_change ();
3002 else if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3003 /* We do not stop for these. */
3007 /* We will stop here */
3008 if (b
->disposition
== disp_disable
)
3009 b
->enable_state
= bp_disabled
;
3012 bs
->commands
= b
->commands
;
3014 (strcmp ("silent", bs
->commands
->line
) == 0
3015 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3017 bs
->commands
= bs
->commands
->next
;
3020 bs
->commands
= copy_command_lines (bs
->commands
);
3023 /* Print nothing for this entry if we dont stop or if we dont print. */
3024 if (bs
->stop
== 0 || bs
->print
== 0)
3025 bs
->print_it
= print_it_noop
;
3028 bs
->next
= NULL
; /* Terminate the chain */
3029 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3031 /* If we aren't stopping, the value of some hardware watchpoint may
3032 not have changed, but the intermediate memory locations we are
3033 watching may have. Don't bother if we're stopping; this will get
3035 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3040 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3042 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3043 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3044 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3046 remove_breakpoints ();
3047 insert_breakpoints ();
3051 return root_bs
->next
;
3054 /* Tell what to do about this bpstat. */
3056 bpstat_what (bpstat bs
)
3058 /* Classify each bpstat as one of the following. */
3061 /* This bpstat element has no effect on the main_action. */
3064 /* There was a watchpoint, stop but don't print. */
3067 /* There was a watchpoint, stop and print. */
3070 /* There was a breakpoint but we're not stopping. */
3073 /* There was a breakpoint, stop but don't print. */
3076 /* There was a breakpoint, stop and print. */
3079 /* We hit the longjmp breakpoint. */
3082 /* We hit the longjmp_resume breakpoint. */
3085 /* We hit the step_resume breakpoint. */
3088 /* We hit the shared library event breakpoint. */
3091 /* We caught a shared library event. */
3094 /* This is just used to count how many enums there are. */
3098 /* Here is the table which drives this routine. So that we can
3099 format it pretty, we define some abbreviations for the
3100 enum bpstat_what codes. */
3101 #define kc BPSTAT_WHAT_KEEP_CHECKING
3102 #define ss BPSTAT_WHAT_STOP_SILENT
3103 #define sn BPSTAT_WHAT_STOP_NOISY
3104 #define sgl BPSTAT_WHAT_SINGLE
3105 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3106 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3107 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
3108 #define sr BPSTAT_WHAT_STEP_RESUME
3109 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3110 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3112 /* "Can't happen." Might want to print an error message.
3113 abort() is not out of the question, but chances are GDB is just
3114 a bit confused, not unusable. */
3115 #define err BPSTAT_WHAT_STOP_NOISY
3117 /* Given an old action and a class, come up with a new action. */
3118 /* One interesting property of this table is that wp_silent is the same
3119 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3120 after stopping, the check for whether to step over a breakpoint
3121 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3122 reference to how we stopped. We retain separate wp_silent and
3123 bp_silent codes in case we want to change that someday.
3125 Another possibly interesting property of this table is that
3126 there's a partial ordering, priority-like, of the actions. Once
3127 you've decided that some action is appropriate, you'll never go
3128 back and decide something of a lower priority is better. The
3131 kc < clr sgl shl shlr slr sn sr ss
3132 sgl < clrs shl shlr slr sn sr ss
3133 slr < err shl shlr sn sr ss
3134 clr < clrs err shl shlr sn sr ss
3135 clrs < err shl shlr sn sr ss
3142 What I think this means is that we don't need a damned table
3143 here. If you just put the rows and columns in the right order,
3144 it'd look awfully regular. We could simply walk the bpstat list
3145 and choose the highest priority action we find, with a little
3146 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3147 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3148 is messy anyway). */
3150 /* step_resume entries: a step resume breakpoint overrides another
3151 breakpoint of signal handling (see comment in wait_for_inferior
3152 at where we set the step_resume breakpoint). */
3154 static const enum bpstat_what_main_action
3155 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3158 /* kc ss sn sgl slr clr clrs sr shl shlr
3161 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, shl
, shlr
},
3163 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3165 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3167 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, shl
, shlr
},
3169 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3171 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3173 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, shl
, shlr
},
3175 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, shl
, shlr
},
3177 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3179 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3181 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3196 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3197 struct bpstat_what retval
;
3199 retval
.call_dummy
= 0;
3200 for (; bs
!= NULL
; bs
= bs
->next
)
3202 enum class bs_class
= no_effect
;
3203 if (bs
->breakpoint_at
== NULL
)
3204 /* I suspect this can happen if it was a momentary breakpoint
3205 which has since been deleted. */
3207 switch (bs
->breakpoint_at
->owner
->type
)
3213 case bp_hardware_breakpoint
:
3219 bs_class
= bp_noisy
;
3221 bs_class
= bp_silent
;
3224 bs_class
= bp_nostop
;
3227 case bp_hardware_watchpoint
:
3228 case bp_read_watchpoint
:
3229 case bp_access_watchpoint
:
3233 bs_class
= wp_noisy
;
3235 bs_class
= wp_silent
;
3238 /* There was a watchpoint, but we're not stopping.
3239 This requires no further action. */
3240 bs_class
= no_effect
;
3243 bs_class
= long_jump
;
3245 case bp_longjmp_resume
:
3246 bs_class
= long_resume
;
3248 case bp_step_resume
:
3251 bs_class
= step_resume
;
3254 /* It is for the wrong frame. */
3255 bs_class
= bp_nostop
;
3257 case bp_watchpoint_scope
:
3258 bs_class
= bp_nostop
;
3260 case bp_shlib_event
:
3261 bs_class
= shlib_event
;
3263 case bp_thread_event
:
3264 case bp_overlay_event
:
3265 bs_class
= bp_nostop
;
3268 case bp_catch_unload
:
3269 /* Only if this catchpoint triggered should we cause the
3270 step-out-of-dld behaviour. Otherwise, we ignore this
3273 bs_class
= catch_shlib_event
;
3275 bs_class
= no_effect
;
3278 case bp_catch_vfork
:
3283 bs_class
= bp_noisy
;
3285 bs_class
= bp_silent
;
3288 /* There was a catchpoint, but we're not stopping.
3289 This requires no further action. */
3290 bs_class
= no_effect
;
3292 case bp_catch_catch
:
3293 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
3294 bs_class
= bp_nostop
;
3296 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3298 case bp_catch_throw
:
3299 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3300 bs_class
= bp_nostop
;
3302 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3305 /* Make sure the action is stop (silent or noisy),
3306 so infrun.c pops the dummy frame. */
3307 bs_class
= bp_silent
;
3308 retval
.call_dummy
= 1;
3311 current_action
= table
[(int) bs_class
][(int) current_action
];
3313 retval
.main_action
= current_action
;
3317 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3318 without hardware support). This isn't related to a specific bpstat,
3319 just to things like whether watchpoints are set. */
3322 bpstat_should_step (void)
3324 struct breakpoint
*b
;
3326 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3331 /* Nonzero if there are enabled hardware watchpoints. */
3333 bpstat_have_active_hw_watchpoints (void)
3335 const struct bp_location
*bpt
;
3336 ALL_BP_LOCATIONS (bpt
)
3337 if (breakpoint_enabled (bpt
->owner
)
3339 && bpt
->loc_type
== bp_loc_hardware_watchpoint
)
3345 /* Given a bpstat that records zero or more triggered eventpoints, this
3346 function returns another bpstat which contains only the catchpoints
3347 on that first list, if any. */
3349 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3351 struct bpstats root_bs
[1];
3352 bpstat bs
= root_bs
;
3353 struct breakpoint
*ep
;
3356 bpstat_clear (cp_list
);
3357 root_bs
->next
= NULL
;
3359 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3361 /* Is this eventpoint a catchpoint? If not, ignore it. */
3362 ep
= ep_list
->breakpoint_at
->owner
;
3365 if ((ep
->type
!= bp_catch_load
) &&
3366 (ep
->type
!= bp_catch_unload
) &&
3367 (ep
->type
!= bp_catch_catch
) &&
3368 (ep
->type
!= bp_catch_throw
))
3369 /* pai: (temp) ADD fork/vfork here!! */
3372 /* Yes; add it to the list. */
3373 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3378 #if defined(SOLIB_ADD)
3379 /* Also, for each triggered catchpoint, tag it with the name of
3380 the library that caused this trigger. (We copy the name now,
3381 because it's only guaranteed to be available NOW, when the
3382 catchpoint triggers. Clients who may wish to know the name
3383 later must get it from the catchpoint itself.) */
3384 if (ep
->triggered_dll_pathname
!= NULL
)
3385 xfree (ep
->triggered_dll_pathname
);
3386 if (ep
->type
== bp_catch_load
)
3387 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3388 PIDGET (inferior_ptid
));
3390 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3391 PIDGET (inferior_ptid
));
3393 dll_pathname
= NULL
;
3397 ep
->triggered_dll_pathname
= (char *)
3398 xmalloc (strlen (dll_pathname
) + 1);
3399 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3402 ep
->triggered_dll_pathname
= NULL
;
3408 static void print_breakpoint_location (struct breakpoint
*b
,
3409 struct bp_location
*loc
,
3411 struct ui_stream
*stb
)
3416 = find_pc_sect_function (loc
->address
, loc
->section
);
3419 ui_out_text (uiout
, "in ");
3420 ui_out_field_string (uiout
, "func",
3421 SYMBOL_PRINT_NAME (sym
));
3422 ui_out_wrap_hint (uiout
, wrap_indent
);
3423 ui_out_text (uiout
, " at ");
3425 ui_out_field_string (uiout
, "file", b
->source_file
);
3426 ui_out_text (uiout
, ":");
3428 if (ui_out_is_mi_like_p (uiout
))
3430 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3431 char *fullname
= symtab_to_fullname (sal
.symtab
);
3434 ui_out_field_string (uiout
, "fullname", fullname
);
3437 ui_out_field_int (uiout
, "line", b
->line_number
);
3441 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3445 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3446 ui_out_field_stream (uiout
, "at", stb
);
3450 /* Print B to gdb_stdout. */
3452 print_one_breakpoint_location (struct breakpoint
*b
,
3453 struct bp_location
*loc
,
3455 CORE_ADDR
*last_addr
)
3457 struct command_line
*l
;
3459 struct ep_type_description
3464 static struct ep_type_description bptypes
[] =
3466 {bp_none
, "?deleted?"},
3467 {bp_breakpoint
, "breakpoint"},
3468 {bp_hardware_breakpoint
, "hw breakpoint"},
3469 {bp_until
, "until"},
3470 {bp_finish
, "finish"},
3471 {bp_watchpoint
, "watchpoint"},
3472 {bp_hardware_watchpoint
, "hw watchpoint"},
3473 {bp_read_watchpoint
, "read watchpoint"},
3474 {bp_access_watchpoint
, "acc watchpoint"},
3475 {bp_longjmp
, "longjmp"},
3476 {bp_longjmp_resume
, "longjmp resume"},
3477 {bp_step_resume
, "step resume"},
3478 {bp_watchpoint_scope
, "watchpoint scope"},
3479 {bp_call_dummy
, "call dummy"},
3480 {bp_shlib_event
, "shlib events"},
3481 {bp_thread_event
, "thread events"},
3482 {bp_overlay_event
, "overlay events"},
3483 {bp_catch_load
, "catch load"},
3484 {bp_catch_unload
, "catch unload"},
3485 {bp_catch_fork
, "catch fork"},
3486 {bp_catch_vfork
, "catch vfork"},
3487 {bp_catch_exec
, "catch exec"},
3488 {bp_catch_catch
, "catch catch"},
3489 {bp_catch_throw
, "catch throw"}
3492 static char *bpdisps
[] =
3493 {"del", "dstp", "dis", "keep"};
3494 static char bpenables
[] = "nynny";
3495 char wrap_indent
[80];
3496 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3497 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3498 struct cleanup
*bkpt_chain
;
3500 int header_of_multiple
= 0;
3501 int part_of_multiple
= (loc
!= NULL
);
3503 gdb_assert (!loc
|| loc_number
!= 0);
3504 /* See comment in print_one_breakpoint concerning
3505 treatment of breakpoints with single disabled
3509 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3510 header_of_multiple
= 1;
3515 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3519 if (part_of_multiple
)
3522 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3523 ui_out_field_string (uiout
, "number", formatted
);
3528 ui_out_field_int (uiout
, "number", b
->number
);
3533 if (part_of_multiple
)
3534 ui_out_field_skip (uiout
, "type");
3537 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3538 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3539 internal_error (__FILE__
, __LINE__
,
3540 _("bptypes table does not describe type #%d."),
3542 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3547 if (part_of_multiple
)
3548 ui_out_field_skip (uiout
, "disp");
3550 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3555 if (part_of_multiple
)
3556 ui_out_field_string (uiout
, "enabled",
3558 ? (loc
->enabled
? "y(p)" : "n(p)")
3559 : (loc
->enabled
? "y" : "n"));
3562 int pending
= (b
->loc
== NULL
|| b
->loc
->shlib_disabled
);
3563 /* For header of multiple, there's no point showing pending
3564 state -- it will be apparent from the locations. */
3565 if (header_of_multiple
)
3567 ui_out_field_fmt (uiout
, "enabled", "%c%s",
3568 bpenables
[(int) b
->enable_state
],
3569 pending
? "(p)" : "");
3571 ui_out_spaces (uiout
, 3);
3576 strcpy (wrap_indent
, " ");
3579 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3580 strcat (wrap_indent
, " ");
3582 strcat (wrap_indent
, " ");
3585 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3587 /* Although the print_one can possibly print
3588 all locations, calling it here is not likely
3589 to get any nice result. So, make sure there's
3590 just one location. */
3591 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3592 b
->ops
->print_one (b
, last_addr
);
3598 internal_error (__FILE__
, __LINE__
,
3599 _("print_one_breakpoint: bp_none encountered\n"));
3603 case bp_hardware_watchpoint
:
3604 case bp_read_watchpoint
:
3605 case bp_access_watchpoint
:
3606 /* Field 4, the address, is omitted (which makes the columns
3607 not line up too nicely with the headers, but the effect
3608 is relatively readable). */
3610 ui_out_field_skip (uiout
, "addr");
3612 print_expression (b
->exp
, stb
->stream
);
3613 ui_out_field_stream (uiout
, "what", stb
);
3617 case bp_catch_unload
:
3618 /* Field 4, the address, is omitted (which makes the columns
3619 not line up too nicely with the headers, but the effect
3620 is relatively readable). */
3622 ui_out_field_skip (uiout
, "addr");
3624 if (b
->dll_pathname
== NULL
)
3626 ui_out_field_string (uiout
, "what", "<any library>");
3627 ui_out_spaces (uiout
, 1);
3631 ui_out_text (uiout
, "library \"");
3632 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3633 ui_out_text (uiout
, "\" ");
3638 case bp_catch_vfork
:
3639 /* Field 4, the address, is omitted (which makes the columns
3640 not line up too nicely with the headers, but the effect
3641 is relatively readable). */
3643 ui_out_field_skip (uiout
, "addr");
3645 if (b
->forked_inferior_pid
!= 0)
3647 ui_out_text (uiout
, "process ");
3648 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3649 ui_out_spaces (uiout
, 1);
3654 /* Field 4, the address, is omitted (which makes the columns
3655 not line up too nicely with the headers, but the effect
3656 is relatively readable). */
3658 ui_out_field_skip (uiout
, "addr");
3660 if (b
->exec_pathname
!= NULL
)
3662 ui_out_text (uiout
, "program \"");
3663 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3664 ui_out_text (uiout
, "\" ");
3668 case bp_catch_catch
:
3669 /* Field 4, the address, is omitted (which makes the columns
3670 not line up too nicely with the headers, but the effect
3671 is relatively readable). */
3673 ui_out_field_skip (uiout
, "addr");
3675 ui_out_field_string (uiout
, "what", "exception catch");
3676 ui_out_spaces (uiout
, 1);
3679 case bp_catch_throw
:
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 throw");
3687 ui_out_spaces (uiout
, 1);
3691 case bp_hardware_breakpoint
:
3695 case bp_longjmp_resume
:
3696 case bp_step_resume
:
3697 case bp_watchpoint_scope
:
3699 case bp_shlib_event
:
3700 case bp_thread_event
:
3701 case bp_overlay_event
:
3706 ui_out_field_string (uiout
, "addr", "<PENDING>");
3707 else if (header_of_multiple
)
3708 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3710 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3713 if (!header_of_multiple
)
3714 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3716 *last_addr
= b
->loc
->address
;
3720 if (!part_of_multiple
&& b
->thread
!= -1)
3722 /* FIXME: This seems to be redundant and lost here; see the
3723 "stop only in" line a little further down. */
3724 ui_out_text (uiout
, " thread ");
3725 ui_out_field_int (uiout
, "thread", b
->thread
);
3728 ui_out_text (uiout
, "\n");
3730 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3733 ui_out_text (uiout
, "\tstop only in stack frame at ");
3734 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3736 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3737 ui_out_text (uiout
, "\n");
3740 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3742 /* We do not print the condition for Ada exception catchpoints
3743 because the condition is an internal implementation detail
3744 that we do not want to expose to the user. */
3746 ui_out_text (uiout
, "\tstop only if ");
3747 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3748 ui_out_text (uiout
, "\n");
3751 if (!part_of_multiple
&& b
->thread
!= -1)
3753 /* FIXME should make an annotation for this */
3754 ui_out_text (uiout
, "\tstop only in thread ");
3755 ui_out_field_int (uiout
, "thread", b
->thread
);
3756 ui_out_text (uiout
, "\n");
3759 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3761 /* FIXME should make an annotation for this */
3762 if (ep_is_catchpoint (b
))
3763 ui_out_text (uiout
, "\tcatchpoint");
3765 ui_out_text (uiout
, "\tbreakpoint");
3766 ui_out_text (uiout
, " already hit ");
3767 ui_out_field_int (uiout
, "times", b
->hit_count
);
3768 if (b
->hit_count
== 1)
3769 ui_out_text (uiout
, " time\n");
3771 ui_out_text (uiout
, " times\n");
3774 /* Output the count also if it is zero, but only if this is
3775 mi. FIXME: Should have a better test for this. */
3776 if (ui_out_is_mi_like_p (uiout
))
3777 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3778 ui_out_field_int (uiout
, "times", b
->hit_count
);
3780 if (!part_of_multiple
&& b
->ignore_count
)
3783 ui_out_text (uiout
, "\tignore next ");
3784 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3785 ui_out_text (uiout
, " hits\n");
3788 if (!part_of_multiple
&& (l
= b
->commands
))
3790 struct cleanup
*script_chain
;
3793 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3794 print_command_lines (uiout
, l
, 4);
3795 do_cleanups (script_chain
);
3797 do_cleanups (bkpt_chain
);
3798 do_cleanups (old_chain
);
3802 print_one_breakpoint (struct breakpoint
*b
,
3803 CORE_ADDR
*last_addr
)
3805 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3807 /* If this breakpoint has custom print function,
3808 it's already printed. Otherwise, print individual
3809 locations, if any. */
3810 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3812 /* If breakpoint has a single location that is
3813 disabled, we print it as if it had
3814 several locations, since otherwise it's hard to
3815 represent "breakpoint enabled, location disabled"
3818 && (b
->loc
->next
|| !b
->loc
->enabled
)
3819 && !ui_out_is_mi_like_p (uiout
))
3821 struct bp_location
*loc
;
3823 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3824 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3830 struct captured_breakpoint_query_args
3836 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3838 struct captured_breakpoint_query_args
*args
= data
;
3839 struct breakpoint
*b
;
3840 CORE_ADDR dummy_addr
= 0;
3843 if (args
->bnum
== b
->number
)
3845 print_one_breakpoint (b
, &dummy_addr
);
3853 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3855 struct captured_breakpoint_query_args args
;
3857 /* For the moment we don't trust print_one_breakpoint() to not throw
3859 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3860 error_message
, RETURN_MASK_ALL
) < 0)
3866 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3867 catchpoints, et.al.). */
3870 user_settable_breakpoint (const struct breakpoint
*b
)
3872 return (b
->type
== bp_breakpoint
3873 || b
->type
== bp_catch_load
3874 || b
->type
== bp_catch_unload
3875 || b
->type
== bp_catch_fork
3876 || b
->type
== bp_catch_vfork
3877 || b
->type
== bp_catch_exec
3878 || b
->type
== bp_catch_catch
3879 || b
->type
== bp_catch_throw
3880 || b
->type
== bp_hardware_breakpoint
3881 || b
->type
== bp_watchpoint
3882 || b
->type
== bp_read_watchpoint
3883 || b
->type
== bp_access_watchpoint
3884 || b
->type
== bp_hardware_watchpoint
);
3887 /* Print information on user settable breakpoint (watchpoint, etc)
3888 number BNUM. If BNUM is -1 print all user settable breakpoints.
3889 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3892 breakpoint_1 (int bnum
, int allflag
)
3894 struct breakpoint
*b
;
3895 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3896 int nr_printable_breakpoints
;
3897 struct cleanup
*bkpttbl_chain
;
3899 /* Compute the number of rows in the table. */
3900 nr_printable_breakpoints
= 0;
3903 || bnum
== b
->number
)
3905 if (allflag
|| user_settable_breakpoint (b
))
3906 nr_printable_breakpoints
++;
3911 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3915 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3918 if (nr_printable_breakpoints
> 0)
3919 annotate_breakpoints_headers ();
3920 if (nr_printable_breakpoints
> 0)
3922 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3923 if (nr_printable_breakpoints
> 0)
3925 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3926 if (nr_printable_breakpoints
> 0)
3928 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3929 if (nr_printable_breakpoints
> 0)
3931 ui_out_table_header (uiout
, 4, ui_left
, "enabled", "Enb"); /* 4 */
3934 if (nr_printable_breakpoints
> 0)
3936 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3937 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3939 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3941 if (nr_printable_breakpoints
> 0)
3943 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3944 ui_out_table_body (uiout
);
3945 if (nr_printable_breakpoints
> 0)
3946 annotate_breakpoints_table ();
3950 || bnum
== b
->number
)
3952 /* We only print out user settable breakpoints unless the
3954 if (allflag
|| user_settable_breakpoint (b
))
3955 print_one_breakpoint (b
, &last_addr
);
3958 do_cleanups (bkpttbl_chain
);
3960 if (nr_printable_breakpoints
== 0)
3963 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3965 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3970 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3971 that a comparison of an unsigned with -1 is always false. */
3972 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3973 set_next_address (last_addr
);
3976 /* FIXME? Should this be moved up so that it is only called when
3977 there have been breakpoints? */
3978 annotate_breakpoints_table_end ();
3982 breakpoints_info (char *bnum_exp
, int from_tty
)
3987 bnum
= parse_and_eval_long (bnum_exp
);
3989 breakpoint_1 (bnum
, 0);
3993 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3998 bnum
= parse_and_eval_long (bnum_exp
);
4000 breakpoint_1 (bnum
, 1);
4004 breakpoint_has_pc (struct breakpoint
*b
, CORE_ADDR pc
, asection
*section
)
4006 struct bp_location
*bl
= b
->loc
;
4007 for (; bl
; bl
= bl
->next
)
4009 if (bl
->address
== pc
4010 && (!overlay_debugging
|| bl
->section
== section
))
4016 /* Print a message describing any breakpoints set at PC. */
4019 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
4022 struct breakpoint
*b
;
4025 others
+= breakpoint_has_pc (b
, pc
, section
);
4029 printf_filtered (_("Note: breakpoint "));
4030 else /* if (others == ???) */
4031 printf_filtered (_("Note: breakpoints "));
4033 if (breakpoint_has_pc (b
, pc
, section
))
4036 printf_filtered ("%d", b
->number
);
4037 if (b
->thread
== -1 && thread
!= -1)
4038 printf_filtered (" (all threads)");
4039 else if (b
->thread
!= -1)
4040 printf_filtered (" (thread %d)", b
->thread
);
4041 printf_filtered ("%s%s ",
4042 ((b
->enable_state
== bp_disabled
||
4043 b
->enable_state
== bp_call_disabled
)
4045 : b
->enable_state
== bp_permanent
4049 : ((others
== 1) ? " and" : ""));
4051 printf_filtered (_("also set at pc "));
4052 deprecated_print_address_numeric (pc
, 1, gdb_stdout
);
4053 printf_filtered (".\n");
4057 /* Set the default place to put a breakpoint
4058 for the `break' command with no arguments. */
4061 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4064 default_breakpoint_valid
= valid
;
4065 default_breakpoint_address
= addr
;
4066 default_breakpoint_symtab
= symtab
;
4067 default_breakpoint_line
= line
;
4070 /* Return true iff it is meaningful to use the address member of
4071 BPT. For some breakpoint types, the address member is irrelevant
4072 and it makes no sense to attempt to compare it to other addresses
4073 (or use it for any other purpose either).
4075 More specifically, each of the following breakpoint types will always
4076 have a zero valued address and we don't want check_duplicates() to mark
4077 breakpoints of any of these types to be a duplicate of an actual
4078 breakpoint at address zero:
4081 bp_hardware_watchpoint
4083 bp_access_watchpoint
4090 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4092 enum bptype type
= bpt
->type
;
4094 return (type
!= bp_watchpoint
4095 && type
!= bp_hardware_watchpoint
4096 && type
!= bp_read_watchpoint
4097 && type
!= bp_access_watchpoint
4098 && type
!= bp_catch_exec
4099 && type
!= bp_longjmp_resume
4100 && type
!= bp_catch_fork
4101 && type
!= bp_catch_vfork
);
4104 /* Rescan breakpoints at the same address and section as BPT,
4105 marking the first one as "first" and any others as "duplicates".
4106 This is so that the bpt instruction is only inserted once.
4107 If we have a permanent breakpoint at the same place as BPT, make
4108 that one the official one, and the rest as duplicates. */
4111 check_duplicates_for (CORE_ADDR address
, asection
*section
)
4113 struct bp_location
*b
;
4115 struct bp_location
*perm_bp
= 0;
4117 ALL_BP_LOCATIONS (b
)
4118 if (b
->owner
->enable_state
!= bp_disabled
4119 && b
->owner
->enable_state
!= bp_call_disabled
4121 && !b
->shlib_disabled
4122 && b
->address
== address
/* address / overlay match */
4123 && (!overlay_debugging
|| b
->section
== section
)
4124 && breakpoint_address_is_meaningful (b
->owner
))
4126 /* Have we found a permanent breakpoint? */
4127 if (b
->owner
->enable_state
== bp_permanent
)
4134 b
->duplicate
= count
> 1;
4137 /* If we found a permanent breakpoint at this address, go over the
4138 list again and declare all the other breakpoints there to be the
4142 perm_bp
->duplicate
= 0;
4144 /* Permanent breakpoint should always be inserted. */
4145 if (! perm_bp
->inserted
)
4146 internal_error (__FILE__
, __LINE__
,
4147 _("allegedly permanent breakpoint is not "
4148 "actually inserted"));
4150 ALL_BP_LOCATIONS (b
)
4153 if (b
->owner
->enable_state
!= bp_disabled
4154 && b
->owner
->enable_state
!= bp_call_disabled
4155 && b
->enabled
&& !b
->shlib_disabled
4156 && b
->address
== address
/* address / overlay match */
4157 && (!overlay_debugging
|| b
->section
== section
)
4158 && breakpoint_address_is_meaningful (b
->owner
))
4161 internal_error (__FILE__
, __LINE__
,
4162 _("another breakpoint was inserted on top of "
4163 "a permanent breakpoint"));
4172 check_duplicates (struct breakpoint
*bpt
)
4174 struct bp_location
*bl
= bpt
->loc
;
4176 if (! breakpoint_address_is_meaningful (bpt
))
4179 for (; bl
; bl
= bl
->next
)
4180 check_duplicates_for (bl
->address
, bl
->section
);
4184 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4185 int bnum
, int have_bnum
)
4190 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4191 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4193 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4194 bnum
, astr1
, astr2
);
4196 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4199 /* Adjust a breakpoint's address to account for architectural constraints
4200 on breakpoint placement. Return the adjusted address. Note: Very
4201 few targets require this kind of adjustment. For most targets,
4202 this function is simply the identity function. */
4205 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4207 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4209 /* Very few targets need any kind of breakpoint adjustment. */
4212 else if (bptype
== bp_watchpoint
4213 || bptype
== bp_hardware_watchpoint
4214 || bptype
== bp_read_watchpoint
4215 || bptype
== bp_access_watchpoint
4216 || bptype
== bp_catch_fork
4217 || bptype
== bp_catch_vfork
4218 || bptype
== bp_catch_exec
)
4220 /* Watchpoints and the various bp_catch_* eventpoints should not
4221 have their addresses modified. */
4226 CORE_ADDR adjusted_bpaddr
;
4228 /* Some targets have architectural constraints on the placement
4229 of breakpoint instructions. Obtain the adjusted address. */
4230 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4233 /* An adjusted breakpoint address can significantly alter
4234 a user's expectations. Print a warning if an adjustment
4236 if (adjusted_bpaddr
!= bpaddr
)
4237 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4239 return adjusted_bpaddr
;
4243 /* Allocate a struct bp_location. */
4245 static struct bp_location
*
4246 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4248 struct bp_location
*loc
, *loc_p
;
4250 loc
= xmalloc (sizeof (struct bp_location
));
4251 memset (loc
, 0, sizeof (*loc
));
4255 loc
->shlib_disabled
= 0;
4264 case bp_longjmp_resume
:
4265 case bp_step_resume
:
4266 case bp_watchpoint_scope
:
4268 case bp_shlib_event
:
4269 case bp_thread_event
:
4270 case bp_overlay_event
:
4272 case bp_catch_unload
:
4273 loc
->loc_type
= bp_loc_software_breakpoint
;
4275 case bp_hardware_breakpoint
:
4276 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4278 case bp_hardware_watchpoint
:
4279 case bp_read_watchpoint
:
4280 case bp_access_watchpoint
:
4281 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4285 case bp_catch_vfork
:
4287 case bp_catch_catch
:
4288 case bp_catch_throw
:
4289 loc
->loc_type
= bp_loc_other
;
4292 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4295 /* Add this breakpoint to the end of the chain. */
4297 loc_p
= bp_location_chain
;
4299 bp_location_chain
= loc
;
4302 while (loc_p
->global_next
)
4303 loc_p
= loc_p
->global_next
;
4304 loc_p
->global_next
= loc
;
4310 static void free_bp_location (struct bp_location
*loc
)
4317 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4318 that has type BPTYPE and has no locations as yet. */
4320 static struct breakpoint
*
4321 set_raw_breakpoint_without_location (enum bptype bptype
)
4323 struct breakpoint
*b
, *b1
;
4325 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4326 memset (b
, 0, sizeof (*b
));
4329 b
->language
= current_language
->la_language
;
4330 b
->input_radix
= input_radix
;
4332 b
->enable_state
= bp_enabled
;
4335 b
->ignore_count
= 0;
4337 b
->frame_id
= null_frame_id
;
4338 b
->dll_pathname
= NULL
;
4339 b
->triggered_dll_pathname
= NULL
;
4340 b
->forked_inferior_pid
= 0;
4341 b
->exec_pathname
= NULL
;
4343 b
->condition_not_parsed
= 0;
4345 /* Add this breakpoint to the end of the chain
4346 so that a list of breakpoints will come out in order
4347 of increasing numbers. */
4349 b1
= breakpoint_chain
;
4351 breakpoint_chain
= b
;
4361 /* Initialize loc->function_name. */
4363 set_breakpoint_location_function (struct bp_location
*loc
)
4365 if (loc
->owner
->type
== bp_breakpoint
4366 || loc
->owner
->type
== bp_hardware_breakpoint
)
4368 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4370 if (loc
->function_name
)
4371 loc
->function_name
= xstrdup (loc
->function_name
);
4375 /* set_raw_breakpoint is a low level routine for allocating and
4376 partially initializing a breakpoint of type BPTYPE. The newly
4377 created breakpoint's address, section, source file name, and line
4378 number are provided by SAL. The newly created and partially
4379 initialized breakpoint is added to the breakpoint chain and
4380 is also returned as the value of this function.
4382 It is expected that the caller will complete the initialization of
4383 the newly created breakpoint struct as well as output any status
4384 information regarding the creation of a new breakpoint. In
4385 particular, set_raw_breakpoint does NOT set the breakpoint
4386 number! Care should be taken to not allow an error to occur
4387 prior to completing the initialization of the breakpoint. If this
4388 should happen, a bogus breakpoint will be left on the chain. */
4391 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4393 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4394 CORE_ADDR adjusted_address
;
4396 /* Adjust the breakpoint's address prior to allocating a location.
4397 Once we call allocate_bp_location(), that mostly uninitialized
4398 location will be placed on the location chain. Adjustment of the
4399 breakpoint may cause read_memory_nobpt() to be called and we do
4400 not want its scan of the location chain to find a breakpoint and
4401 location that's only been partially initialized. */
4402 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4404 b
->loc
= allocate_bp_location (b
, bptype
);
4405 b
->loc
->requested_address
= sal
.pc
;
4406 b
->loc
->address
= adjusted_address
;
4408 if (sal
.symtab
== NULL
)
4409 b
->source_file
= NULL
;
4411 b
->source_file
= savestring (sal
.symtab
->filename
,
4412 strlen (sal
.symtab
->filename
));
4413 b
->loc
->section
= sal
.section
;
4414 b
->line_number
= sal
.line
;
4416 set_breakpoint_location_function (b
->loc
);
4418 check_duplicates (b
);
4419 breakpoints_changed ();
4425 /* Note that the breakpoint object B describes a permanent breakpoint
4426 instruction, hard-wired into the inferior's code. */
4428 make_breakpoint_permanent (struct breakpoint
*b
)
4430 struct bp_location
*bl
;
4431 b
->enable_state
= bp_permanent
;
4433 /* By definition, permanent breakpoints are already present in the code.
4434 Mark all locations as inserted. For now, make_breakpoint_permanent
4435 is called in just one place, so it's hard to say if it's reasonable
4436 to have permanent breakpoint with multiple locations or not,
4437 but it's easy to implmement. */
4438 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4442 static struct breakpoint
*
4443 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4445 static int internal_breakpoint_number
= -1;
4446 struct symtab_and_line sal
;
4447 struct breakpoint
*b
;
4449 init_sal (&sal
); /* initialize to zeroes */
4452 sal
.section
= find_pc_overlay (sal
.pc
);
4454 b
= set_raw_breakpoint (sal
, type
);
4455 b
->number
= internal_breakpoint_number
--;
4456 b
->disposition
= disp_donttouch
;
4463 create_longjmp_breakpoint (char *func_name
)
4465 struct breakpoint
*b
;
4466 struct minimal_symbol
*m
;
4468 if (func_name
== NULL
)
4469 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4472 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4475 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4478 b
->enable_state
= bp_disabled
;
4481 b
->addr_string
= xstrdup (func_name
);
4484 /* Call this routine when stepping and nexting to enable a breakpoint
4485 if we do a longjmp(). When we hit that breakpoint, call
4486 set_longjmp_resume_breakpoint() to figure out where we are going. */
4489 enable_longjmp_breakpoint (void)
4491 struct breakpoint
*b
;
4494 if (b
->type
== bp_longjmp
)
4496 b
->enable_state
= bp_enabled
;
4497 check_duplicates (b
);
4502 disable_longjmp_breakpoint (void)
4504 struct breakpoint
*b
;
4507 if (b
->type
== bp_longjmp
4508 || b
->type
== bp_longjmp_resume
)
4510 b
->enable_state
= bp_disabled
;
4511 check_duplicates (b
);
4516 create_overlay_event_breakpoint (char *func_name
)
4518 struct breakpoint
*b
;
4519 struct minimal_symbol
*m
;
4521 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4524 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4526 b
->addr_string
= xstrdup (func_name
);
4528 if (overlay_debugging
== ovly_auto
)
4530 b
->enable_state
= bp_enabled
;
4531 overlay_events_enabled
= 1;
4535 b
->enable_state
= bp_disabled
;
4536 overlay_events_enabled
= 0;
4541 enable_overlay_breakpoints (void)
4543 struct breakpoint
*b
;
4546 if (b
->type
== bp_overlay_event
)
4548 b
->enable_state
= bp_enabled
;
4549 check_duplicates (b
);
4550 overlay_events_enabled
= 1;
4555 disable_overlay_breakpoints (void)
4557 struct breakpoint
*b
;
4560 if (b
->type
== bp_overlay_event
)
4562 b
->enable_state
= bp_disabled
;
4563 check_duplicates (b
);
4564 overlay_events_enabled
= 0;
4569 create_thread_event_breakpoint (CORE_ADDR address
)
4571 struct breakpoint
*b
;
4573 b
= create_internal_breakpoint (address
, bp_thread_event
);
4575 b
->enable_state
= bp_enabled
;
4576 /* addr_string has to be used or breakpoint_re_set will delete me. */
4577 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4583 remove_thread_event_breakpoints (void)
4585 struct breakpoint
*b
, *temp
;
4587 ALL_BREAKPOINTS_SAFE (b
, temp
)
4588 if (b
->type
== bp_thread_event
)
4589 delete_breakpoint (b
);
4592 struct captured_parse_breakpoint_args
4595 struct symtabs_and_lines
*sals_p
;
4596 char ***addr_string_p
;
4600 struct lang_and_radix
4608 remove_solib_event_breakpoints (void)
4610 struct breakpoint
*b
, *temp
;
4612 ALL_BREAKPOINTS_SAFE (b
, temp
)
4613 if (b
->type
== bp_shlib_event
)
4614 delete_breakpoint (b
);
4618 create_solib_event_breakpoint (CORE_ADDR address
)
4620 struct breakpoint
*b
;
4622 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4626 /* Disable any breakpoints that are on code in shared libraries. Only
4627 apply to enabled breakpoints, disabled ones can just stay disabled. */
4630 disable_breakpoints_in_shlibs (void)
4632 struct bp_location
*loc
;
4633 int disabled_shlib_breaks
= 0;
4635 ALL_BP_LOCATIONS (loc
)
4637 struct breakpoint
*b
= loc
->owner
;
4638 /* We apply the check to all breakpoints, including disabled
4639 for those with loc->duplicate set. This is so that when breakpoint
4640 becomes enabled, or the duplicate is removed, gdb will try to insert
4641 all breakpoints. If we don't set shlib_disabled here, we'll try
4642 to insert those breakpoints and fail. */
4643 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4644 && !loc
->shlib_disabled
4646 && PC_SOLIB (loc
->address
)
4648 && solib_address (loc
->address
)
4652 loc
->shlib_disabled
= 1;
4657 /* Disable any breakpoints that are in in an unloaded shared library. Only
4658 apply to enabled breakpoints, disabled ones can just stay disabled. */
4661 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4663 struct bp_location
*loc
;
4664 int disabled_shlib_breaks
= 0;
4666 ALL_BP_LOCATIONS (loc
)
4668 struct breakpoint
*b
= loc
->owner
;
4669 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4670 || loc
->loc_type
== bp_loc_software_breakpoint
)
4671 && !loc
->shlib_disabled
)
4674 char *so_name
= PC_SOLIB (loc
->address
);
4676 char *so_name
= solib_address (loc
->address
);
4678 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4680 loc
->shlib_disabled
= 1;
4681 /* At this point, we cannot rely on remove_breakpoint
4682 succeeding so we must mark the breakpoint as not inserted
4683 to prevent future errors occurring in remove_breakpoints. */
4685 if (!disabled_shlib_breaks
)
4687 target_terminal_ours_for_output ();
4688 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4691 disabled_shlib_breaks
= 1;
4698 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4699 enum bptype bp_kind
)
4701 struct symtab_and_line sal
;
4702 struct breakpoint
*b
;
4703 int thread
= -1; /* All threads. */
4710 b
= set_raw_breakpoint (sal
, bp_kind
);
4711 set_breakpoint_count (breakpoint_count
+ 1);
4712 b
->number
= breakpoint_count
;
4713 b
->cond_string
= (cond_string
== NULL
) ?
4714 NULL
: savestring (cond_string
, strlen (cond_string
));
4716 b
->addr_string
= NULL
;
4717 b
->enable_state
= bp_enabled
;
4718 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4719 b
->forked_inferior_pid
= 0;
4725 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4727 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4731 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4733 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4737 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4739 struct symtab_and_line sal
;
4740 struct breakpoint
*b
;
4741 int thread
= -1; /* All threads. */
4748 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4749 set_breakpoint_count (breakpoint_count
+ 1);
4750 b
->number
= breakpoint_count
;
4751 b
->cond_string
= (cond_string
== NULL
) ?
4752 NULL
: savestring (cond_string
, strlen (cond_string
));
4754 b
->addr_string
= NULL
;
4755 b
->enable_state
= bp_enabled
;
4756 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4762 hw_breakpoint_used_count (void)
4764 struct breakpoint
*b
;
4769 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4777 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4779 struct breakpoint
*b
;
4782 *other_type_used
= 0;
4785 if (breakpoint_enabled (b
))
4787 if (b
->type
== type
)
4789 else if ((b
->type
== bp_hardware_watchpoint
||
4790 b
->type
== bp_read_watchpoint
||
4791 b
->type
== bp_access_watchpoint
))
4792 *other_type_used
= 1;
4798 /* Call this after hitting the longjmp() breakpoint. Use this to set
4799 a new breakpoint at the target of the jmp_buf.
4801 FIXME - This ought to be done by setting a temporary breakpoint
4802 that gets deleted automatically... */
4805 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4807 struct breakpoint
*b
;
4810 if (b
->type
== bp_longjmp_resume
)
4812 b
->loc
->requested_address
= pc
;
4813 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4815 b
->enable_state
= bp_enabled
;
4816 b
->frame_id
= frame_id
;
4817 check_duplicates (b
);
4823 disable_watchpoints_before_interactive_call_start (void)
4825 struct breakpoint
*b
;
4829 if (((b
->type
== bp_watchpoint
)
4830 || (b
->type
== bp_hardware_watchpoint
)
4831 || (b
->type
== bp_read_watchpoint
)
4832 || (b
->type
== bp_access_watchpoint
)
4833 || ep_is_exception_catchpoint (b
))
4834 && breakpoint_enabled (b
))
4836 b
->enable_state
= bp_call_disabled
;
4837 check_duplicates (b
);
4843 enable_watchpoints_after_interactive_call_stop (void)
4845 struct breakpoint
*b
;
4849 if (((b
->type
== bp_watchpoint
)
4850 || (b
->type
== bp_hardware_watchpoint
)
4851 || (b
->type
== bp_read_watchpoint
)
4852 || (b
->type
== bp_access_watchpoint
)
4853 || ep_is_exception_catchpoint (b
))
4854 && (b
->enable_state
== bp_call_disabled
))
4856 b
->enable_state
= bp_enabled
;
4857 check_duplicates (b
);
4863 /* Set a breakpoint that will evaporate an end of command
4864 at address specified by SAL.
4865 Restrict it to frame FRAME if FRAME is nonzero. */
4868 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4871 struct breakpoint
*b
;
4872 b
= set_raw_breakpoint (sal
, type
);
4873 b
->enable_state
= bp_enabled
;
4874 b
->disposition
= disp_donttouch
;
4875 b
->frame_id
= frame_id
;
4877 /* If we're debugging a multi-threaded program, then we
4878 want momentary breakpoints to be active in only a
4879 single thread of control. */
4880 if (in_thread_list (inferior_ptid
))
4881 b
->thread
= pid_to_thread_id (inferior_ptid
);
4887 /* Tell the user we have just set a breakpoint B. */
4890 mention (struct breakpoint
*b
)
4893 struct cleanup
*old_chain
, *ui_out_chain
;
4894 struct ui_stream
*stb
;
4896 stb
= ui_out_stream_new (uiout
);
4897 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4899 /* FIXME: This is misplaced; mention() is called by things (like
4900 hitting a watchpoint) other than breakpoint creation. It should
4901 be possible to clean this up and at the same time replace the
4902 random calls to breakpoint_changed with this hook, as has already
4903 been done for deprecated_delete_breakpoint_hook and so on. */
4904 if (deprecated_create_breakpoint_hook
)
4905 deprecated_create_breakpoint_hook (b
);
4906 breakpoint_create_event (b
->number
);
4908 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4909 b
->ops
->print_mention (b
);
4914 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4917 ui_out_text (uiout
, "Watchpoint ");
4918 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4919 ui_out_field_int (uiout
, "number", b
->number
);
4920 ui_out_text (uiout
, ": ");
4921 print_expression (b
->exp
, stb
->stream
);
4922 ui_out_field_stream (uiout
, "exp", stb
);
4923 do_cleanups (ui_out_chain
);
4925 case bp_hardware_watchpoint
:
4926 ui_out_text (uiout
, "Hardware watchpoint ");
4927 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4928 ui_out_field_int (uiout
, "number", b
->number
);
4929 ui_out_text (uiout
, ": ");
4930 print_expression (b
->exp
, stb
->stream
);
4931 ui_out_field_stream (uiout
, "exp", stb
);
4932 do_cleanups (ui_out_chain
);
4934 case bp_read_watchpoint
:
4935 ui_out_text (uiout
, "Hardware read watchpoint ");
4936 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4937 ui_out_field_int (uiout
, "number", b
->number
);
4938 ui_out_text (uiout
, ": ");
4939 print_expression (b
->exp
, stb
->stream
);
4940 ui_out_field_stream (uiout
, "exp", stb
);
4941 do_cleanups (ui_out_chain
);
4943 case bp_access_watchpoint
:
4944 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4945 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4946 ui_out_field_int (uiout
, "number", b
->number
);
4947 ui_out_text (uiout
, ": ");
4948 print_expression (b
->exp
, stb
->stream
);
4949 ui_out_field_stream (uiout
, "exp", stb
);
4950 do_cleanups (ui_out_chain
);
4953 if (ui_out_is_mi_like_p (uiout
))
4958 printf_filtered (_("Breakpoint %d"), b
->number
);
4961 case bp_hardware_breakpoint
:
4962 if (ui_out_is_mi_like_p (uiout
))
4967 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4971 case bp_catch_unload
:
4972 printf_filtered (_("Catchpoint %d (%s %s)"),
4974 (b
->type
== bp_catch_load
) ? "load" : "unload",
4975 (b
->dll_pathname
!= NULL
) ?
4976 b
->dll_pathname
: "<any library>");
4979 case bp_catch_vfork
:
4980 printf_filtered (_("Catchpoint %d (%s)"),
4982 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4985 printf_filtered (_("Catchpoint %d (exec)"),
4988 case bp_catch_catch
:
4989 case bp_catch_throw
:
4990 printf_filtered (_("Catchpoint %d (%s)"),
4992 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4998 case bp_longjmp_resume
:
4999 case bp_step_resume
:
5001 case bp_watchpoint_scope
:
5002 case bp_shlib_event
:
5003 case bp_thread_event
:
5004 case bp_overlay_event
:
5010 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5014 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5018 if (addressprint
|| b
->source_file
== NULL
)
5020 printf_filtered (" at ");
5021 deprecated_print_address_numeric (b
->loc
->address
, 1, gdb_stdout
);
5024 printf_filtered (": file %s, line %d.",
5025 b
->source_file
, b
->line_number
);
5029 struct bp_location
*loc
= b
->loc
;
5031 for (; loc
; loc
= loc
->next
)
5033 printf_filtered (" (%d locations)", n
);
5038 do_cleanups (old_chain
);
5039 if (ui_out_is_mi_like_p (uiout
))
5041 printf_filtered ("\n");
5045 static struct bp_location
*
5046 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5047 const struct symtab_and_line
*sal
)
5049 struct bp_location
*loc
, **tmp
;
5051 loc
= allocate_bp_location (b
, bptype
);
5052 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5055 loc
->requested_address
= sal
->pc
;
5056 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5058 loc
->section
= sal
->section
;
5060 set_breakpoint_location_function (loc
);
5064 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5065 as textual description of the location, and COND_STRING
5066 as condition expression. */
5069 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5071 enum bptype type
, enum bpdisp disposition
,
5072 int thread
, int ignore_count
, int from_tty
)
5074 struct breakpoint
*b
= NULL
;
5077 if (type
== bp_hardware_breakpoint
)
5079 int i
= hw_breakpoint_used_count ();
5080 int target_resources_ok
=
5081 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5083 if (target_resources_ok
== 0)
5084 error (_("No hardware breakpoint support in the target."));
5085 else if (target_resources_ok
< 0)
5086 error (_("Hardware breakpoints used exceeds limit."));
5089 for (i
= 0; i
< sals
.nelts
; ++i
)
5091 struct symtab_and_line sal
= sals
.sals
[i
];
5092 struct bp_location
*loc
;
5095 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5099 b
= set_raw_breakpoint (sal
, type
);
5100 set_breakpoint_count (breakpoint_count
+ 1);
5101 b
->number
= breakpoint_count
;
5104 b
->cond_string
= cond_string
;
5105 b
->ignore_count
= ignore_count
;
5106 b
->enable_state
= bp_enabled
;
5107 b
->disposition
= disposition
;
5113 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5118 char *arg
= b
->cond_string
;
5119 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5121 error (_("Garbage %s follows condition"), arg
);
5126 b
->addr_string
= addr_string
;
5128 /* addr_string has to be used or breakpoint_re_set will delete
5130 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5135 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5136 elements to fill the void space. */
5137 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5139 int i
= index_to_remove
+1;
5140 int last_index
= sal
->nelts
-1;
5142 for (;i
<= last_index
; ++i
)
5143 sal
->sals
[i
-1] = sal
->sals
[i
];
5148 /* If appropriate, obtains all sals that correspond
5149 to the same file and line as SAL. This is done
5150 only if SAL does not have explicit PC and has
5151 line and file information. If we got just a single
5152 expanded sal, return the original.
5154 Otherwise, if SAL.explicit_line is not set, filter out
5155 all sals for which the name of enclosing function
5156 is different from SAL. This makes sure that if we have
5157 breakpoint originally set in template instantiation, say
5158 foo<int>(), we won't expand SAL to locations at the same
5159 line in all existing instantiations of 'foo'.
5162 struct symtabs_and_lines
5163 expand_line_sal_maybe (struct symtab_and_line sal
)
5165 struct symtabs_and_lines expanded
;
5166 CORE_ADDR original_pc
= sal
.pc
;
5167 char *original_function
= NULL
;
5171 /* If we have explicit pc, don't expand.
5172 If we have no line number, we can't expand. */
5173 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5176 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5177 expanded
.sals
[0] = sal
;
5182 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5184 expanded
= expand_line_sal (sal
);
5185 if (expanded
.nelts
== 1)
5187 /* We had one sal, we got one sal. Without futher
5188 processing, just return the original sal. */
5189 xfree (expanded
.sals
);
5191 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5192 sal
.pc
= original_pc
;
5193 expanded
.sals
[0] = sal
;
5197 if (!sal
.explicit_line
)
5199 CORE_ADDR func_addr
, func_end
;
5200 for (i
= 0; i
< expanded
.nelts
; ++i
)
5202 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5203 char *this_function
;
5204 if (find_pc_partial_function (pc
, &this_function
,
5205 &func_addr
, &func_end
))
5207 if (this_function
&&
5208 strcmp (this_function
, original_function
) != 0)
5210 remove_sal (&expanded
, i
);
5213 else if (func_addr
== pc
)
5215 /* We're at beginning of a function, and should
5217 struct symbol
*sym
= find_pc_function (pc
);
5219 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5222 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5229 if (expanded
.nelts
<= 1)
5231 /* This is un ugly workaround. If we get zero
5232 expanded sals then something is really wrong.
5233 Fix that by returnign the original sal. */
5234 xfree (expanded
.sals
);
5236 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5237 sal
.pc
= original_pc
;
5238 expanded
.sals
[0] = sal
;
5245 for (i
= 0; i
< expanded
.nelts
; ++i
)
5246 if (expanded
.sals
[i
].pc
== original_pc
)
5257 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5258 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5259 value. COND_STRING, if not NULL, specified the condition to be
5260 used for all breakpoints. Essentially the only case where
5261 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5262 function. In that case, it's still not possible to specify
5263 separate conditions for different overloaded functions, so
5264 we take just a single condition string.
5266 NOTE: If the function succeeds, the caller is expected to cleanup
5267 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5268 array contents). If the function fails (error() is called), the
5269 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5270 COND and SALS arrays and each of those arrays contents. */
5273 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5275 enum bptype type
, enum bpdisp disposition
,
5276 int thread
, int ignore_count
, int from_tty
)
5279 for (i
= 0; i
< sals
.nelts
; ++i
)
5281 struct symtabs_and_lines expanded
=
5282 expand_line_sal_maybe (sals
.sals
[i
]);
5284 create_breakpoint (expanded
, addr_string
[i
],
5285 cond_string
, type
, disposition
,
5286 thread
, ignore_count
, from_tty
);
5290 /* Parse ARG which is assumed to be a SAL specification possibly
5291 followed by conditionals. On return, SALS contains an array of SAL
5292 addresses found. ADDR_STRING contains a vector of (canonical)
5293 address strings. ARG points to the end of the SAL. */
5296 parse_breakpoint_sals (char **address
,
5297 struct symtabs_and_lines
*sals
,
5298 char ***addr_string
,
5301 char *addr_start
= *address
;
5302 *addr_string
= NULL
;
5303 /* If no arg given, or if first arg is 'if ', use the default
5305 if ((*address
) == NULL
5306 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5308 if (default_breakpoint_valid
)
5310 struct symtab_and_line sal
;
5311 init_sal (&sal
); /* initialize to zeroes */
5312 sals
->sals
= (struct symtab_and_line
*)
5313 xmalloc (sizeof (struct symtab_and_line
));
5314 sal
.pc
= default_breakpoint_address
;
5315 sal
.line
= default_breakpoint_line
;
5316 sal
.symtab
= default_breakpoint_symtab
;
5317 sal
.section
= find_pc_overlay (sal
.pc
);
5318 sals
->sals
[0] = sal
;
5322 error (_("No default breakpoint address now."));
5326 /* Force almost all breakpoints to be in terms of the
5327 current_source_symtab (which is decode_line_1's default). This
5328 should produce the results we want almost all of the time while
5329 leaving default_breakpoint_* alone.
5330 ObjC: However, don't match an Objective-C method name which
5331 may have a '+' or '-' succeeded by a '[' */
5333 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5335 if (default_breakpoint_valid
5337 || ((strchr ("+-", (*address
)[0]) != NULL
)
5338 && ((*address
)[1] != '['))))
5339 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5340 default_breakpoint_line
, addr_string
,
5343 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5344 addr_string
, not_found_ptr
);
5346 /* For any SAL that didn't have a canonical string, fill one in. */
5347 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5348 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5349 if (addr_start
!= (*address
))
5352 for (i
= 0; i
< sals
->nelts
; i
++)
5354 /* Add the string if not present. */
5355 if ((*addr_string
)[i
] == NULL
)
5356 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5362 /* Convert each SAL into a real PC. Verify that the PC can be
5363 inserted as a breakpoint. If it can't throw an error. */
5366 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5370 for (i
= 0; i
< sals
->nelts
; i
++)
5371 resolve_sal_pc (&sals
->sals
[i
]);
5375 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5377 struct captured_parse_breakpoint_args
*args
= data
;
5379 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5380 args
->not_found_ptr
);
5383 /* Given TOK, a string specification of condition and thread, as
5384 accepted by the 'break' command, extract the condition
5385 string and thread number and set *COND_STRING and *THREAD.
5386 PC identifies the context at which the condition should be parsed.
5387 If no condition is found, *COND_STRING is set to NULL.
5388 If no thread is found, *THREAD is set to -1. */
5390 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5391 char **cond_string
, int *thread
)
5393 *cond_string
= NULL
;
5399 char *cond_start
= NULL
;
5400 char *cond_end
= NULL
;
5401 while (*tok
== ' ' || *tok
== '\t')
5406 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5409 toklen
= end_tok
- tok
;
5411 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5413 tok
= cond_start
= end_tok
+ 1;
5414 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5416 *cond_string
= savestring (cond_start
,
5417 cond_end
- cond_start
);
5419 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5425 *thread
= strtol (tok
, &tok
, 0);
5427 error (_("Junk after thread keyword."));
5428 if (!valid_thread_id (*thread
))
5429 error (_("Unknown thread %d."), *thread
);
5432 error (_("Junk at end of arguments."));
5436 /* Set a breakpoint according to ARG (function, linenum or *address)
5437 flag: first bit : 0 non-temporary, 1 temporary.
5438 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
5441 break_command_1 (char *arg
, int flag
, int from_tty
)
5443 struct gdb_exception e
;
5444 int tempflag
, hardwareflag
;
5445 struct symtabs_and_lines sals
;
5446 struct symtab_and_line pending_sal
;
5447 char *cond_string
= NULL
;
5450 char *addr_start
= arg
;
5452 struct cleanup
*old_chain
;
5453 struct cleanup
*breakpoint_chain
= NULL
;
5454 struct captured_parse_breakpoint_args parse_args
;
5458 int ignore_count
= 0;
5461 hardwareflag
= flag
& BP_HARDWAREFLAG
;
5462 tempflag
= flag
& BP_TEMPFLAG
;
5468 parse_args
.arg_p
= &arg
;
5469 parse_args
.sals_p
= &sals
;
5470 parse_args
.addr_string_p
= &addr_string
;
5471 parse_args
.not_found_ptr
= ¬_found
;
5473 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5474 &parse_args
, RETURN_MASK_ALL
);
5476 /* If caller is interested in rc value from parse, set value. */
5480 exception_print (gdb_stderr
, e
);
5485 case NOT_FOUND_ERROR
:
5487 exception_print (gdb_stderr
, e
);
5489 /* If pending breakpoint support is turned off, throw
5492 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5493 deprecated_throw_reason (RETURN_ERROR
);
5495 /* If pending breakpoint support is auto query and the user
5496 selects no, then simply return the error code. */
5497 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5498 !nquery ("Make breakpoint pending on future shared library load? "))
5501 /* At this point, either the user was queried about setting
5502 a pending breakpoint and selected yes, or pending
5503 breakpoint behavior is on and thus a pending breakpoint
5504 is defaulted on behalf of the user. */
5505 copy_arg
= xstrdup (addr_start
);
5506 addr_string
= ©_arg
;
5508 sals
.sals
= &pending_sal
;
5513 exception_print (gdb_stderr
, e
);
5521 /* Create a chain of things that always need to be cleaned up. */
5522 old_chain
= make_cleanup (null_cleanup
, 0);
5526 /* Make sure that all storage allocated to SALS gets freed. */
5527 make_cleanup (xfree
, sals
.sals
);
5529 /* Cleanup the addr_string array but not its contents. */
5530 make_cleanup (xfree
, addr_string
);
5533 /* ----------------------------- SNIP -----------------------------
5534 Anything added to the cleanup chain beyond this point is assumed
5535 to be part of a breakpoint. If the breakpoint create succeeds
5536 then the memory is not reclaimed. */
5537 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5539 /* Mark the contents of the addr_string for cleanup. These go on
5540 the breakpoint_chain and only occure if the breakpoint create
5542 for (i
= 0; i
< sals
.nelts
; i
++)
5544 if (addr_string
[i
] != NULL
)
5545 make_cleanup (xfree
, addr_string
[i
]);
5548 /* Resolve all line numbers to PC's and verify that the addresses
5549 are ok for the target. */
5551 breakpoint_sals_to_pc (&sals
, addr_start
);
5553 /* Verify that condition can be parsed, before setting any
5554 breakpoints. Allocate a separate condition expression for each
5558 /* Here we only parse 'arg' to separate condition
5559 from thread number, so parsing in context of first
5560 sal is OK. When setting the breakpoint we'll
5561 re-parse it in context of each sal. */
5562 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5564 make_cleanup (xfree
, cond_string
);
5565 create_breakpoints (sals
, addr_string
, cond_string
,
5566 hardwareflag
? bp_hardware_breakpoint
5568 tempflag
? disp_del
: disp_donttouch
,
5569 thread
, ignore_count
, from_tty
);
5573 struct symtab_and_line sal
= {0};
5574 struct breakpoint
*b
;
5576 make_cleanup (xfree
, copy_arg
);
5578 b
= set_raw_breakpoint_without_location (hardwareflag
5579 ? bp_hardware_breakpoint
5581 set_breakpoint_count (breakpoint_count
+ 1);
5582 b
->number
= breakpoint_count
;
5584 b
->addr_string
= addr_string
[0];
5585 b
->cond_string
= cond_string
;
5586 b
->ignore_count
= ignore_count
;
5587 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5588 b
->condition_not_parsed
= 1;
5593 warning (_("Multiple breakpoints were set.\n"
5594 "Use the \"delete\" command to delete unwanted breakpoints."));
5595 /* That's it. Discard the cleanups for data inserted into the
5597 discard_cleanups (breakpoint_chain
);
5598 /* But cleanup everything else. */
5599 do_cleanups (old_chain
);
5604 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5605 linenum or *address) with COND and IGNORE_COUNT. */
5607 struct captured_breakpoint_args
5618 do_captured_breakpoint (struct ui_out
*uiout
, void *data
)
5620 struct captured_breakpoint_args
*args
= data
;
5621 struct symtabs_and_lines sals
;
5622 struct expression
**cond
;
5623 struct cleanup
*old_chain
;
5624 struct cleanup
*breakpoint_chain
= NULL
;
5627 char *cond_string
= 0;
5631 /* Parse the source and lines spec. Delay check that the expression
5632 didn't contain trailing garbage until after cleanups are in
5636 address_end
= args
->address
;
5638 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
, 0);
5643 /* Create a chain of things at always need to be cleaned up. */
5644 old_chain
= make_cleanup (null_cleanup
, 0);
5646 /* Always have a addr_string array, even if it is empty. */
5647 make_cleanup (xfree
, addr_string
);
5649 /* Make sure that all storage allocated to SALS gets freed. */
5650 make_cleanup (xfree
, sals
.sals
);
5652 /* Allocate space for all the cond expressions. */
5653 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5654 make_cleanup (xfree
, cond
);
5656 /* ----------------------------- SNIP -----------------------------
5657 Anything added to the cleanup chain beyond this point is assumed
5658 to be part of a breakpoint. If the breakpoint create goes
5659 through then that memory is not cleaned up. */
5660 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5662 /* Mark the contents of the addr_string for cleanup. These go on
5663 the breakpoint_chain and only occure if the breakpoint create
5665 for (i
= 0; i
< sals
.nelts
; i
++)
5667 if (addr_string
[i
] != NULL
)
5668 make_cleanup (xfree
, addr_string
[i
]);
5671 /* Wait until now before checking for garbage at the end of the
5672 address. That way cleanups can take care of freeing any
5674 if (*address_end
!= '\0')
5675 error (_("Garbage %s following breakpoint address"), address_end
);
5677 /* Resolve all line numbers to PC's. */
5678 breakpoint_sals_to_pc (&sals
, args
->address
);
5680 if (args
->condition
!= NULL
)
5682 cond_string
= xstrdup (args
->condition
);
5683 make_cleanup (xfree
, cond_string
);
5686 create_breakpoints (sals
, addr_string
, args
->condition
,
5687 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
5688 args
->tempflag
? disp_del
: disp_donttouch
,
5689 args
->thread
, args
->ignore_count
, 0/*from-tty*/);
5691 /* That's it. Discard the cleanups for data inserted into the
5693 discard_cleanups (breakpoint_chain
);
5694 /* But cleanup everything else. */
5695 do_cleanups (old_chain
);
5700 gdb_breakpoint (char *address
, char *condition
,
5701 int hardwareflag
, int tempflag
,
5702 int thread
, int ignore_count
,
5703 char **error_message
)
5705 struct captured_breakpoint_args args
;
5706 args
.address
= address
;
5707 args
.condition
= condition
;
5708 args
.hardwareflag
= hardwareflag
;
5709 args
.tempflag
= tempflag
;
5710 args
.thread
= thread
;
5711 args
.ignore_count
= ignore_count
;
5712 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint
, &args
,
5713 error_message
, RETURN_MASK_ALL
) < 0)
5720 /* Helper function for break_command_1 and disassemble_command. */
5723 resolve_sal_pc (struct symtab_and_line
*sal
)
5727 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5729 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5730 error (_("No line %d in file \"%s\"."),
5731 sal
->line
, sal
->symtab
->filename
);
5735 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5737 struct blockvector
*bv
;
5742 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5745 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5746 sym
= block_function (b
);
5749 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5750 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5754 /* It really is worthwhile to have the section, so we'll just
5755 have to look harder. This case can be executed if we have
5756 line numbers but no functions (as can happen in assembly
5759 struct minimal_symbol
*msym
;
5761 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5763 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5770 break_command (char *arg
, int from_tty
)
5772 break_command_1 (arg
, 0, from_tty
);
5776 tbreak_command (char *arg
, int from_tty
)
5778 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5782 hbreak_command (char *arg
, int from_tty
)
5784 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5788 thbreak_command (char *arg
, int from_tty
)
5790 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5794 stop_command (char *arg
, int from_tty
)
5796 printf_filtered (_("Specify the type of breakpoint to set.\n\
5797 Usage: stop in <function | address>\n\
5798 stop at <line>\n"));
5802 stopin_command (char *arg
, int from_tty
)
5806 if (arg
== (char *) NULL
)
5808 else if (*arg
!= '*')
5813 /* look for a ':'. If this is a line number specification, then
5814 say it is bad, otherwise, it should be an address or
5815 function/method name */
5816 while (*argptr
&& !hasColon
)
5818 hasColon
= (*argptr
== ':');
5823 badInput
= (*argptr
!= ':'); /* Not a class::method */
5825 badInput
= isdigit (*arg
); /* a simple line number */
5829 printf_filtered (_("Usage: stop in <function | address>\n"));
5831 break_command_1 (arg
, 0, from_tty
);
5835 stopat_command (char *arg
, int from_tty
)
5839 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5846 /* look for a ':'. If there is a '::' then get out, otherwise
5847 it is probably a line number. */
5848 while (*argptr
&& !hasColon
)
5850 hasColon
= (*argptr
== ':');
5855 badInput
= (*argptr
== ':'); /* we have class::method */
5857 badInput
= !isdigit (*arg
); /* not a line number */
5861 printf_filtered (_("Usage: stop at <line>\n"));
5863 break_command_1 (arg
, 0, from_tty
);
5866 /* accessflag: hw_write: watch write,
5867 hw_read: watch read,
5868 hw_access: watch access (read or write) */
5870 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5872 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5873 struct symtab_and_line sal
;
5874 struct expression
*exp
;
5875 struct block
*exp_valid_block
;
5876 struct value
*val
, *mark
;
5877 struct frame_info
*frame
;
5878 struct frame_info
*prev_frame
= NULL
;
5879 char *exp_start
= NULL
;
5880 char *exp_end
= NULL
;
5881 char *tok
, *end_tok
;
5883 char *cond_start
= NULL
;
5884 char *cond_end
= NULL
;
5885 struct expression
*cond
= NULL
;
5886 int i
, other_type_used
, target_resources_ok
= 0;
5887 enum bptype bp_type
;
5890 init_sal (&sal
); /* initialize to zeroes */
5892 /* Parse arguments. */
5893 innermost_block
= NULL
;
5895 exp
= parse_exp_1 (&arg
, 0, 0);
5897 exp_valid_block
= innermost_block
;
5898 mark
= value_mark ();
5899 val
= evaluate_expression (exp
);
5900 release_value (val
);
5901 if (value_lazy (val
))
5902 value_fetch_lazy (val
);
5905 while (*tok
== ' ' || *tok
== '\t')
5909 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5912 toklen
= end_tok
- tok
;
5913 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5915 tok
= cond_start
= end_tok
+ 1;
5916 cond
= parse_exp_1 (&tok
, 0, 0);
5920 error (_("Junk at end of command."));
5922 if (accessflag
== hw_read
)
5923 bp_type
= bp_read_watchpoint
;
5924 else if (accessflag
== hw_access
)
5925 bp_type
= bp_access_watchpoint
;
5927 bp_type
= bp_hardware_watchpoint
;
5929 mem_cnt
= can_use_hardware_watchpoint (val
);
5930 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5931 error (_("Expression cannot be implemented with read/access watchpoint."));
5934 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5935 target_resources_ok
=
5936 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5938 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5939 error (_("Target does not support this type of hardware watchpoint."));
5941 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5942 error (_("Target can only support one kind of HW watchpoint at a time."));
5945 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5946 watchpoint could not be set. */
5947 if (!mem_cnt
|| target_resources_ok
<= 0)
5948 bp_type
= bp_watchpoint
;
5950 frame
= block_innermost_frame (exp_valid_block
);
5952 prev_frame
= get_prev_frame (frame
);
5956 /* If the expression is "local", then set up a "watchpoint scope"
5957 breakpoint at the point where we've left the scope of the watchpoint
5958 expression. Create the scope breakpoint before the watchpoint, so
5959 that we will encounter it first in bpstat_stop_status. */
5960 if (innermost_block
&& prev_frame
)
5962 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5963 bp_watchpoint_scope
);
5965 scope_breakpoint
->enable_state
= bp_enabled
;
5967 /* Automatically delete the breakpoint when it hits. */
5968 scope_breakpoint
->disposition
= disp_del
;
5970 /* Only break in the proper frame (help with recursion). */
5971 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5973 /* Set the address at which we will stop. */
5974 scope_breakpoint
->loc
->requested_address
5975 = get_frame_pc (prev_frame
);
5976 scope_breakpoint
->loc
->address
5977 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5978 scope_breakpoint
->type
);
5981 /* Now set up the breakpoint. */
5982 b
= set_raw_breakpoint (sal
, bp_type
);
5983 set_breakpoint_count (breakpoint_count
+ 1);
5984 b
->number
= breakpoint_count
;
5985 b
->disposition
= disp_donttouch
;
5987 b
->exp_valid_block
= exp_valid_block
;
5988 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5990 b
->loc
->cond
= cond
;
5992 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5997 b
->watchpoint_frame
= get_frame_id (frame
);
5999 b
->watchpoint_frame
= null_frame_id
;
6001 if (scope_breakpoint
!= NULL
)
6003 /* The scope breakpoint is related to the watchpoint. We will
6004 need to act on them together. */
6005 b
->related_breakpoint
= scope_breakpoint
;
6006 scope_breakpoint
->related_breakpoint
= b
;
6009 value_free_to_mark (mark
);
6013 /* Return count of locations need to be watched and can be handled
6014 in hardware. If the watchpoint can not be handled
6015 in hardware return zero. */
6018 can_use_hardware_watchpoint (struct value
*v
)
6020 int found_memory_cnt
= 0;
6021 struct value
*head
= v
;
6023 /* Did the user specifically forbid us to use hardware watchpoints? */
6024 if (!can_use_hw_watchpoints
)
6027 /* Make sure that the value of the expression depends only upon
6028 memory contents, and values computed from them within GDB. If we
6029 find any register references or function calls, we can't use a
6030 hardware watchpoint.
6032 The idea here is that evaluating an expression generates a series
6033 of values, one holding the value of every subexpression. (The
6034 expression a*b+c has five subexpressions: a, b, a*b, c, and
6035 a*b+c.) GDB's values hold almost enough information to establish
6036 the criteria given above --- they identify memory lvalues,
6037 register lvalues, computed values, etcetera. So we can evaluate
6038 the expression, and then scan the chain of values that leaves
6039 behind to decide whether we can detect any possible change to the
6040 expression's final value using only hardware watchpoints.
6042 However, I don't think that the values returned by inferior
6043 function calls are special in any way. So this function may not
6044 notice that an expression involving an inferior function call
6045 can't be watched with hardware watchpoints. FIXME. */
6046 for (; v
; v
= value_next (v
))
6048 if (VALUE_LVAL (v
) == lval_memory
)
6051 /* A lazy memory lvalue is one that GDB never needed to fetch;
6052 we either just used its address (e.g., `a' in `a.b') or
6053 we never needed it at all (e.g., `a' in `a,b'). */
6057 /* Ahh, memory we actually used! Check if we can cover
6058 it with hardware watchpoints. */
6059 struct type
*vtype
= check_typedef (value_type (v
));
6061 /* We only watch structs and arrays if user asked for it
6062 explicitly, never if they just happen to appear in a
6063 middle of some value chain. */
6065 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6066 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6068 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6069 int len
= TYPE_LENGTH (value_type (v
));
6071 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6078 else if (VALUE_LVAL (v
) != not_lval
6079 && deprecated_value_modifiable (v
) == 0)
6080 return 0; /* ??? What does this represent? */
6081 else if (VALUE_LVAL (v
) == lval_register
)
6082 return 0; /* cannot watch a register with a HW watchpoint */
6085 /* The expression itself looks suitable for using a hardware
6086 watchpoint, but give the target machine a chance to reject it. */
6087 return found_memory_cnt
;
6091 watch_command_wrapper (char *arg
, int from_tty
)
6093 watch_command (arg
, from_tty
);
6097 watch_command (char *arg
, int from_tty
)
6099 watch_command_1 (arg
, hw_write
, from_tty
);
6103 rwatch_command_wrapper (char *arg
, int from_tty
)
6105 rwatch_command (arg
, from_tty
);
6109 rwatch_command (char *arg
, int from_tty
)
6111 watch_command_1 (arg
, hw_read
, from_tty
);
6115 awatch_command_wrapper (char *arg
, int from_tty
)
6117 awatch_command (arg
, from_tty
);
6121 awatch_command (char *arg
, int from_tty
)
6123 watch_command_1 (arg
, hw_access
, from_tty
);
6127 /* Helper routines for the until_command routine in infcmd.c. Here
6128 because it uses the mechanisms of breakpoints. */
6130 /* This function is called by fetch_inferior_event via the
6131 cmd_continuation pointer, to complete the until command. It takes
6132 care of cleaning up the temporary breakpoints set up by the until
6135 until_break_command_continuation (struct continuation_arg
*arg
)
6137 struct cleanup
*cleanups
;
6139 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
6140 do_exec_cleanups (cleanups
);
6144 until_break_command (char *arg
, int from_tty
, int anywhere
)
6146 struct symtabs_and_lines sals
;
6147 struct symtab_and_line sal
;
6148 struct frame_info
*frame
= get_selected_frame (NULL
);
6149 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6150 struct breakpoint
*breakpoint
;
6151 struct cleanup
*old_chain
;
6152 struct continuation_arg
*arg1
;
6155 clear_proceed_status ();
6157 /* Set a breakpoint where the user wants it and at return from
6160 if (default_breakpoint_valid
)
6161 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6162 default_breakpoint_line
, (char ***) NULL
, NULL
);
6164 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6165 0, (char ***) NULL
, NULL
);
6167 if (sals
.nelts
!= 1)
6168 error (_("Couldn't get information on specified line."));
6171 xfree (sals
.sals
); /* malloc'd, so freed */
6174 error (_("Junk at end of arguments."));
6176 resolve_sal_pc (&sal
);
6179 /* If the user told us to continue until a specified location,
6180 we don't specify a frame at which we need to stop. */
6181 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6183 /* Otherwise, specify the current frame, because we want to stop only
6184 at the very same frame. */
6185 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6188 if (!target_can_async_p ())
6189 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6191 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
6193 /* If we are running asynchronously, and the target supports async
6194 execution, we are not waiting for the target to stop, in the call
6195 tp proceed, below. This means that we cannot delete the
6196 brekpoints until the target has actually stopped. The only place
6197 where we get a chance to do that is in fetch_inferior_event, so
6198 we must set things up for that. */
6200 if (target_can_async_p ())
6202 /* In this case the arg for the continuation is just the point
6203 in the exec_cleanups chain from where to start doing
6204 cleanups, because all the continuation does is the cleanups in
6205 the exec_cleanup_chain. */
6207 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6209 arg1
->data
.pointer
= old_chain
;
6211 add_continuation (until_break_command_continuation
, arg1
);
6214 /* Keep within the current frame, or in frames called by the current
6218 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6219 sal
.pc
= get_frame_pc (prev_frame
);
6220 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6222 if (!target_can_async_p ())
6223 make_cleanup_delete_breakpoint (breakpoint
);
6225 make_exec_cleanup_delete_breakpoint (breakpoint
);
6228 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6229 /* Do the cleanups now, anly if we are not running asynchronously,
6230 of if we are, but the target is still synchronous. */
6231 if (!target_can_async_p ())
6232 do_cleanups (old_chain
);
6236 ep_skip_leading_whitespace (char **s
)
6238 if ((s
== NULL
) || (*s
== NULL
))
6240 while (isspace (**s
))
6244 /* This function examines a string, and attempts to find a token
6245 that might be an event name in the leading characters. If a
6246 possible match is found, a pointer to the last character of
6247 the token is returned. Else, NULL is returned. */
6250 ep_find_event_name_end (char *arg
)
6253 char *event_name_end
= NULL
;
6255 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6259 /* We break out of the loop when we find a token delimiter.
6260 Basically, we're looking for alphanumerics and underscores;
6261 anything else delimites the token. */
6264 if (!isalnum (*s
) && (*s
!= '_'))
6270 return event_name_end
;
6274 /* This function attempts to parse an optional "if <cond>" clause
6275 from the arg string. If one is not found, it returns NULL.
6277 Else, it returns a pointer to the condition string. (It does not
6278 attempt to evaluate the string against a particular block.) And,
6279 it updates arg to point to the first character following the parsed
6280 if clause in the arg string. */
6283 ep_parse_optional_if_clause (char **arg
)
6287 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6290 /* Skip the "if" keyword. */
6293 /* Skip any extra leading whitespace, and record the start of the
6294 condition string. */
6295 ep_skip_leading_whitespace (arg
);
6298 /* Assume that the condition occupies the remainder of the arg string. */
6299 (*arg
) += strlen (cond_string
);
6304 /* This function attempts to parse an optional filename from the arg
6305 string. If one is not found, it returns NULL.
6307 Else, it returns a pointer to the parsed filename. (This function
6308 makes no attempt to verify that a file of that name exists, or is
6309 accessible.) And, it updates arg to point to the first character
6310 following the parsed filename in the arg string.
6312 Note that clients needing to preserve the returned filename for
6313 future access should copy it to their own buffers. */
6315 ep_parse_optional_filename (char **arg
)
6317 static char filename
[1024];
6322 if ((*arg_p
== '\0') || isspace (*arg_p
))
6340 /* Commands to deal with catching events, such as signals, exceptions,
6341 process start/exit, etc. */
6345 catch_fork
, catch_vfork
6350 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6353 char *cond_string
= NULL
;
6355 ep_skip_leading_whitespace (&arg
);
6357 /* The allowed syntax is:
6359 catch [v]fork if <cond>
6361 First, check if there's an if clause. */
6362 cond_string
= ep_parse_optional_if_clause (&arg
);
6364 if ((*arg
!= '\0') && !isspace (*arg
))
6365 error (_("Junk at end of arguments."));
6367 /* If this target supports it, create a fork or vfork catchpoint
6368 and enable reporting of such events. */
6372 create_fork_event_catchpoint (tempflag
, cond_string
);
6375 create_vfork_event_catchpoint (tempflag
, cond_string
);
6378 error (_("unsupported or unknown fork kind; cannot catch it"));
6384 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6386 char *cond_string
= NULL
;
6388 ep_skip_leading_whitespace (&arg
);
6390 /* The allowed syntax is:
6392 catch exec if <cond>
6394 First, check if there's an if clause. */
6395 cond_string
= ep_parse_optional_if_clause (&arg
);
6397 if ((*arg
!= '\0') && !isspace (*arg
))
6398 error (_("Junk at end of arguments."));
6400 /* If this target supports it, create an exec catchpoint
6401 and enable reporting of such events. */
6402 create_exec_event_catchpoint (tempflag
, cond_string
);
6406 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6408 char *dll_pathname
= NULL
;
6409 char *cond_string
= NULL
;
6411 ep_skip_leading_whitespace (&arg
);
6413 /* The allowed syntax is:
6415 catch load if <cond>
6416 catch load <filename>
6417 catch load <filename> if <cond>
6419 The user is not allowed to specify the <filename> after an
6422 We'll ignore the pathological case of a file named "if".
6424 First, check if there's an if clause. If so, then there
6425 cannot be a filename. */
6426 cond_string
= ep_parse_optional_if_clause (&arg
);
6428 /* If there was an if clause, then there cannot be a filename.
6429 Else, there might be a filename and an if clause. */
6430 if (cond_string
== NULL
)
6432 dll_pathname
= ep_parse_optional_filename (&arg
);
6433 ep_skip_leading_whitespace (&arg
);
6434 cond_string
= ep_parse_optional_if_clause (&arg
);
6437 if ((*arg
!= '\0') && !isspace (*arg
))
6438 error (_("Junk at end of arguments."));
6440 /* Create a load breakpoint that only triggers when a load of
6441 the specified dll (or any dll, if no pathname was specified)
6443 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6444 dll_pathname
, cond_string
);
6448 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6450 char *dll_pathname
= NULL
;
6451 char *cond_string
= NULL
;
6453 ep_skip_leading_whitespace (&arg
);
6455 /* The allowed syntax is:
6457 catch unload if <cond>
6458 catch unload <filename>
6459 catch unload <filename> if <cond>
6461 The user is not allowed to specify the <filename> after an
6464 We'll ignore the pathological case of a file named "if".
6466 First, check if there's an if clause. If so, then there
6467 cannot be a filename. */
6468 cond_string
= ep_parse_optional_if_clause (&arg
);
6470 /* If there was an if clause, then there cannot be a filename.
6471 Else, there might be a filename and an if clause. */
6472 if (cond_string
== NULL
)
6474 dll_pathname
= ep_parse_optional_filename (&arg
);
6475 ep_skip_leading_whitespace (&arg
);
6476 cond_string
= ep_parse_optional_if_clause (&arg
);
6479 if ((*arg
!= '\0') && !isspace (*arg
))
6480 error (_("Junk at end of arguments."));
6482 /* Create an unload breakpoint that only triggers when an unload of
6483 the specified dll (or any dll, if no pathname was specified)
6485 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6486 dll_pathname
, cond_string
);
6489 /* Commands to deal with catching exceptions. */
6491 /* Set a breakpoint at the specified callback routine for an
6492 exception event callback */
6495 create_exception_catchpoint (int tempflag
, char *cond_string
,
6496 enum exception_event_kind ex_event
,
6497 struct symtab_and_line
*sal
)
6499 struct breakpoint
*b
;
6500 int thread
= -1; /* All threads. */
6503 if (!sal
) /* no exception support? */
6508 case EX_EVENT_THROW
:
6509 bptype
= bp_catch_throw
;
6511 case EX_EVENT_CATCH
:
6512 bptype
= bp_catch_catch
;
6514 default: /* error condition */
6515 error (_("Internal error -- invalid catchpoint kind"));
6518 b
= set_raw_breakpoint (*sal
, bptype
);
6519 set_breakpoint_count (breakpoint_count
+ 1);
6520 b
->number
= breakpoint_count
;
6521 b
->cond_string
= (cond_string
== NULL
) ?
6522 NULL
: savestring (cond_string
, strlen (cond_string
));
6524 b
->addr_string
= NULL
;
6525 b
->enable_state
= bp_enabled
;
6526 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6530 static enum print_stop_action
6531 print_exception_catchpoint (struct breakpoint
*b
)
6533 annotate_catchpoint (b
->number
);
6535 if (strstr (b
->addr_string
, "throw") != NULL
)
6536 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6539 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6542 return PRINT_SRC_AND_LOC
;
6546 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6551 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6554 *last_addr
= b
->loc
->address
;
6555 if (strstr (b
->addr_string
, "throw") != NULL
)
6556 ui_out_field_string (uiout
, "what", "exception throw");
6558 ui_out_field_string (uiout
, "what", "exception catch");
6562 print_mention_exception_catchpoint (struct breakpoint
*b
)
6564 if (strstr (b
->addr_string
, "throw") != NULL
)
6565 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6567 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6570 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6571 print_exception_catchpoint
,
6572 print_one_exception_catchpoint
,
6573 print_mention_exception_catchpoint
6577 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6578 enum exception_event_kind ex_event
, int from_tty
)
6580 char *trigger_func_name
, *nameptr
;
6581 struct symtabs_and_lines sals
;
6582 struct breakpoint
*b
;
6584 if (ex_event
== EX_EVENT_CATCH
)
6585 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6587 trigger_func_name
= xstrdup ("__cxa_throw");
6589 nameptr
= trigger_func_name
;
6590 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6591 if (sals
.nelts
== 0)
6593 xfree (trigger_func_name
);
6597 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6598 set_breakpoint_count (breakpoint_count
+ 1);
6599 b
->number
= breakpoint_count
;
6600 b
->cond_string
= (cond_string
== NULL
) ?
6601 NULL
: savestring (cond_string
, strlen (cond_string
));
6603 b
->addr_string
= trigger_func_name
;
6604 b
->enable_state
= bp_enabled
;
6605 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6606 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6613 /* Deal with "catch catch" and "catch throw" commands */
6616 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6617 int tempflag
, int from_tty
)
6619 char *cond_string
= NULL
;
6620 struct symtab_and_line
*sal
= NULL
;
6622 ep_skip_leading_whitespace (&arg
);
6624 cond_string
= ep_parse_optional_if_clause (&arg
);
6626 if ((*arg
!= '\0') && !isspace (*arg
))
6627 error (_("Junk at end of arguments."));
6629 if ((ex_event
!= EX_EVENT_THROW
) &&
6630 (ex_event
!= EX_EVENT_CATCH
))
6631 error (_("Unsupported or unknown exception event; cannot catch it"));
6633 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6636 /* See if we can find a callback routine */
6637 sal
= target_enable_exception_callback (ex_event
, 1);
6641 /* We have callbacks from the runtime system for exceptions.
6642 Set a breakpoint on the sal found, if no errors */
6643 if (sal
!= (struct symtab_and_line
*) -1)
6644 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6646 return; /* something went wrong with setting up callbacks */
6649 warning (_("Unsupported with this platform/compiler combination."));
6652 /* Create a breakpoint struct for Ada exception catchpoints. */
6655 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6659 struct expression
*cond
,
6660 struct breakpoint_ops
*ops
,
6664 struct breakpoint
*b
;
6668 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6669 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6670 version for exception catchpoints, because two catchpoints
6671 used for different exception names will use the same address.
6672 In this case, a "breakpoint ... also set at..." warning is
6673 unproductive. Besides. the warning phrasing is also a bit
6674 inapropriate, we should use the word catchpoint, and tell
6675 the user what type of catchpoint it is. The above is good
6676 enough for now, though. */
6679 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6680 set_breakpoint_count (breakpoint_count
+ 1);
6682 b
->enable_state
= bp_enabled
;
6683 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6684 b
->number
= breakpoint_count
;
6685 b
->ignore_count
= 0;
6686 b
->loc
->cond
= cond
;
6687 b
->addr_string
= addr_string
;
6688 b
->language
= language_ada
;
6689 b
->cond_string
= cond_string
;
6690 b
->exp_string
= exp_string
;
6697 /* Implement the "catch exception" command. */
6700 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6702 struct symtab_and_line sal
;
6704 char *addr_string
= NULL
;
6705 char *exp_string
= NULL
;
6706 char *cond_string
= NULL
;
6707 struct expression
*cond
= NULL
;
6708 struct breakpoint_ops
*ops
= NULL
;
6710 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6711 &cond_string
, &cond
, &ops
);
6712 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6713 cond_string
, cond
, ops
, tempflag
,
6717 /* Implement the "catch assert" command. */
6720 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6722 struct symtab_and_line sal
;
6723 char *addr_string
= NULL
;
6724 struct breakpoint_ops
*ops
= NULL
;
6726 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6727 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6728 tempflag
, from_tty
);
6731 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6732 inside a catch_errors */
6735 cover_target_enable_exception_callback (void *arg
)
6737 args_for_catchpoint_enable
*args
= arg
;
6738 struct symtab_and_line
*sal
;
6739 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6742 else if (sal
== (struct symtab_and_line
*) -1)
6745 return 1; /*is valid */
6749 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6752 /* The first argument may be an event name, such as "start" or "load".
6753 If so, then handle it as such. If it doesn't match an event name,
6754 then attempt to interpret it as an exception name. (This latter is
6755 the v4.16-and-earlier GDB meaning of the "catch" command.)
6757 First, try to find the bounds of what might be an event name. */
6758 char *arg1_start
= arg
;
6762 if (arg1_start
== NULL
)
6764 /* Old behaviour was to use pre-v-4.16 syntax */
6765 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6767 /* Now, this is not allowed */
6768 error (_("Catch requires an event name."));
6771 arg1_end
= ep_find_event_name_end (arg1_start
);
6772 if (arg1_end
== NULL
)
6773 error (_("catch requires an event"));
6774 arg1_length
= arg1_end
+ 1 - arg1_start
;
6776 /* Try to match what we found against known event names. */
6777 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6779 error (_("Catch of signal not yet implemented"));
6781 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6783 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6784 tempflag
, from_tty
);
6786 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6788 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6789 tempflag
, from_tty
);
6791 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6793 error (_("Catch of thread_start not yet implemented"));
6795 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6797 error (_("Catch of thread_exit not yet implemented"));
6799 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6801 error (_("Catch of thread_join not yet implemented"));
6803 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6805 error (_("Catch of start not yet implemented"));
6807 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6809 error (_("Catch of exit not yet implemented"));
6811 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6813 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6815 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6817 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6819 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6821 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6823 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6825 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6827 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6829 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6831 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6833 error (_("Catch of stop not yet implemented"));
6835 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6837 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6840 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6842 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6845 /* This doesn't appear to be an event name */
6849 /* Pre-v.4.16 behaviour was to treat the argument
6850 as the name of an exception */
6851 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6852 /* Now this is not allowed */
6853 error (_("Unknown event kind specified for catch"));
6859 catch_command (char *arg
, int from_tty
)
6861 catch_command_1 (arg
, 0, from_tty
);
6866 tcatch_command (char *arg
, int from_tty
)
6868 catch_command_1 (arg
, 1, from_tty
);
6871 /* Delete breakpoints by address or line. */
6874 clear_command (char *arg
, int from_tty
)
6876 struct breakpoint
*b
;
6877 VEC(breakpoint_p
) *found
= 0;
6880 struct symtabs_and_lines sals
;
6881 struct symtab_and_line sal
;
6886 sals
= decode_line_spec (arg
, 1);
6891 sals
.sals
= (struct symtab_and_line
*)
6892 xmalloc (sizeof (struct symtab_and_line
));
6893 make_cleanup (xfree
, sals
.sals
);
6894 init_sal (&sal
); /* initialize to zeroes */
6895 sal
.line
= default_breakpoint_line
;
6896 sal
.symtab
= default_breakpoint_symtab
;
6897 sal
.pc
= default_breakpoint_address
;
6898 if (sal
.symtab
== 0)
6899 error (_("No source file specified."));
6907 /* We don't call resolve_sal_pc here. That's not
6908 as bad as it seems, because all existing breakpoints
6909 typically have both file/line and pc set. So, if
6910 clear is given file/line, we can match this to existing
6911 breakpoint without obtaining pc at all.
6913 We only support clearing given the address explicitly
6914 present in breakpoint table. Say, we've set breakpoint
6915 at file:line. There were several PC values for that file:line,
6916 due to optimization, all in one block.
6917 We've picked one PC value. If "clear" is issued with another
6918 PC corresponding to the same file:line, the breakpoint won't
6919 be cleared. We probably can still clear the breakpoint, but
6920 since the other PC value is never presented to user, user
6921 can only find it by guessing, and it does not seem important
6924 /* For each line spec given, delete bps which correspond
6925 to it. Do it in two passes, solely to preserve the current
6926 behavior that from_tty is forced true if we delete more than
6930 for (i
= 0; i
< sals
.nelts
; i
++)
6932 /* If exact pc given, clear bpts at that pc.
6933 If line given (pc == 0), clear all bpts on specified line.
6934 If defaulting, clear all bpts on default line
6937 defaulting sal.pc != 0 tests to do
6942 1 0 <can't happen> */
6946 /* Find all matching breakpoints and add them to
6951 /* Are we going to delete b? */
6952 if (b
->type
!= bp_none
6953 && b
->type
!= bp_watchpoint
6954 && b
->type
!= bp_hardware_watchpoint
6955 && b
->type
!= bp_read_watchpoint
6956 && b
->type
!= bp_access_watchpoint
)
6958 struct bp_location
*loc
= b
->loc
;
6959 for (; loc
; loc
= loc
->next
)
6961 int pc_match
= sal
.pc
6962 && (loc
->address
== sal
.pc
)
6963 && (!section_is_overlay (loc
->section
)
6964 || loc
->section
== sal
.section
);
6965 int line_match
= ((default_match
|| (0 == sal
.pc
))
6966 && b
->source_file
!= NULL
6967 && sal
.symtab
!= NULL
6968 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6969 && b
->line_number
== sal
.line
);
6970 if (pc_match
|| line_match
)
6979 VEC_safe_push(breakpoint_p
, found
, b
);
6982 /* Now go thru the 'found' chain and delete them. */
6983 if (VEC_empty(breakpoint_p
, found
))
6986 error (_("No breakpoint at %s."), arg
);
6988 error (_("No breakpoint at this line."));
6991 if (VEC_length(breakpoint_p
, found
) > 1)
6992 from_tty
= 1; /* Always report if deleted more than one */
6995 if (VEC_length(breakpoint_p
, found
) == 1)
6996 printf_unfiltered (_("Deleted breakpoint "));
6998 printf_unfiltered (_("Deleted breakpoints "));
7000 breakpoints_changed ();
7002 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
7005 printf_unfiltered ("%d ", b
->number
);
7006 delete_breakpoint (b
);
7009 putchar_unfiltered ('\n');
7012 /* Delete breakpoint in BS if they are `delete' breakpoints and
7013 all breakpoints that are marked for deletion, whether hit or not.
7014 This is called after any breakpoint is hit, or after errors. */
7017 breakpoint_auto_delete (bpstat bs
)
7019 struct breakpoint
*b
, *temp
;
7021 for (; bs
; bs
= bs
->next
)
7022 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
->disposition
== disp_del
7024 delete_breakpoint (bs
->breakpoint_at
->owner
);
7026 ALL_BREAKPOINTS_SAFE (b
, temp
)
7028 if (b
->disposition
== disp_del_at_next_stop
)
7029 delete_breakpoint (b
);
7033 /* Remove locations of breakpoint BPT from
7034 the global list of breakpoint locations. */
7037 unlink_locations_from_global_list (struct breakpoint
*bpt
)
7039 /* This code assumes that the locations
7040 of a breakpoint are found in the global list
7041 in the same order, but not necessary adjacent. */
7042 struct bp_location
**tmp
= &bp_location_chain
;
7043 struct bp_location
*here
= bpt
->loc
;
7048 for (; *tmp
&& here
;)
7052 *tmp
= here
->global_next
;
7057 tmp
= &((*tmp
)->global_next
);
7062 /* Delete a breakpoint and clean up all traces of it in the data
7066 delete_breakpoint (struct breakpoint
*bpt
)
7068 struct breakpoint
*b
;
7070 struct bp_location
*loc
;
7072 gdb_assert (bpt
!= NULL
);
7074 /* Has this bp already been deleted? This can happen because multiple
7075 lists can hold pointers to bp's. bpstat lists are especial culprits.
7077 One example of this happening is a watchpoint's scope bp. When the
7078 scope bp triggers, we notice that the watchpoint is out of scope, and
7079 delete it. We also delete its scope bp. But the scope bp is marked
7080 "auto-deleting", and is already on a bpstat. That bpstat is then
7081 checked for auto-deleting bp's, which are deleted.
7083 A real solution to this problem might involve reference counts in bp's,
7084 and/or giving them pointers back to their referencing bpstat's, and
7085 teaching delete_breakpoint to only free a bp's storage when no more
7086 references were extent. A cheaper bandaid was chosen. */
7087 if (bpt
->type
== bp_none
)
7090 if (deprecated_delete_breakpoint_hook
)
7091 deprecated_delete_breakpoint_hook (bpt
);
7092 breakpoint_delete_event (bpt
->number
);
7094 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
7097 remove_breakpoint (loc
, mark_inserted
);
7099 free_valchain (loc
);
7104 if (loc
->function_name
)
7105 xfree (loc
->function_name
);
7108 if (breakpoint_chain
== bpt
)
7109 breakpoint_chain
= bpt
->next
;
7111 /* If we have callback-style exception catchpoints, don't go through
7112 the adjustments to the C++ runtime library etc. if the inferior
7113 isn't actually running. target_enable_exception_callback for a
7114 null target ops vector gives an undesirable error message, so we
7115 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
7116 exceptions are supported in this way, it's OK for now. FIXME */
7117 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
7119 /* Format possible error msg */
7120 char *message
= xstrprintf ("Error in deleting catchpoint %d:\n",
7122 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7123 args_for_catchpoint_enable args
;
7124 args
.kind
= bpt
->type
== bp_catch_catch
?
7125 EX_EVENT_CATCH
: EX_EVENT_THROW
;
7127 catch_errors (cover_target_enable_exception_callback
, &args
,
7128 message
, RETURN_MASK_ALL
);
7129 do_cleanups (cleanups
);
7136 b
->next
= bpt
->next
;
7140 unlink_locations_from_global_list (bpt
);
7142 check_duplicates (bpt
);
7144 if (bpt
->type
!= bp_hardware_watchpoint
7145 && bpt
->type
!= bp_read_watchpoint
7146 && bpt
->type
!= bp_access_watchpoint
7147 && bpt
->type
!= bp_catch_fork
7148 && bpt
->type
!= bp_catch_vfork
7149 && bpt
->type
!= bp_catch_exec
)
7150 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
7152 /* If this breakpoint location was inserted, and there is
7153 another breakpoint at the same address, we need to
7154 insert the other breakpoint. */
7157 struct bp_location
*loc2
;
7158 ALL_BP_LOCATIONS (loc2
)
7159 if (loc2
->address
== loc
->address
7160 && loc2
->section
== loc
->section
7162 && loc2
->owner
->enable_state
!= bp_disabled
7164 && !loc2
->shlib_disabled
7165 && loc2
->owner
->enable_state
!= bp_call_disabled
)
7169 /* We should never reach this point if there is a permanent
7170 breakpoint at the same address as the one being deleted.
7171 If there is a permanent breakpoint somewhere, it should
7172 always be the only one inserted. */
7173 if (loc2
->owner
->enable_state
== bp_permanent
)
7174 internal_error (__FILE__
, __LINE__
,
7175 _("another breakpoint was inserted on top of "
7176 "a permanent breakpoint"));
7178 memset (&loc2
->target_info
, 0, sizeof (loc2
->target_info
));
7179 loc2
->target_info
.placed_address
= loc2
->address
;
7180 if (b
->type
== bp_hardware_breakpoint
)
7181 val
= target_insert_hw_breakpoint (&loc2
->target_info
);
7183 val
= target_insert_breakpoint (&loc2
->target_info
);
7185 /* If there was an error in the insert, print a message, then stop execution. */
7188 struct ui_file
*tmp_error_stream
= mem_fileopen ();
7189 make_cleanup_ui_file_delete (tmp_error_stream
);
7192 if (b
->type
== bp_hardware_breakpoint
)
7194 fprintf_unfiltered (tmp_error_stream
,
7195 "Cannot insert hardware breakpoint %d.\n"
7196 "You may have requested too many hardware breakpoints.\n",
7201 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
7202 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
7203 deprecated_print_address_numeric (loc2
->address
, 1, tmp_error_stream
);
7204 fprintf_filtered (tmp_error_stream
, ": %s.\n",
7205 safe_strerror (val
));
7208 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
7209 target_terminal_ours_for_output ();
7210 error_stream(tmp_error_stream
);
7218 free_command_lines (&bpt
->commands
);
7219 if (bpt
->cond_string
!= NULL
)
7220 xfree (bpt
->cond_string
);
7221 if (bpt
->addr_string
!= NULL
)
7222 xfree (bpt
->addr_string
);
7223 if (bpt
->exp
!= NULL
)
7225 if (bpt
->exp_string
!= NULL
)
7226 xfree (bpt
->exp_string
);
7227 if (bpt
->val
!= NULL
)
7228 value_free (bpt
->val
);
7229 if (bpt
->source_file
!= NULL
)
7230 xfree (bpt
->source_file
);
7231 if (bpt
->dll_pathname
!= NULL
)
7232 xfree (bpt
->dll_pathname
);
7233 if (bpt
->triggered_dll_pathname
!= NULL
)
7234 xfree (bpt
->triggered_dll_pathname
);
7235 if (bpt
->exec_pathname
!= NULL
)
7236 xfree (bpt
->exec_pathname
);
7238 /* Be sure no bpstat's are pointing at it after it's been freed. */
7239 /* FIXME, how can we find all bpstat's?
7240 We just check stop_bpstat for now. Note that we cannot just
7241 remove bpstats pointing at bpt from the stop_bpstat list
7242 entirely, as breakpoint commands are associated with the bpstat;
7243 if we remove it here, then the later call to
7244 bpstat_do_actions (&stop_bpstat);
7245 in event-top.c won't do anything, and temporary breakpoints
7246 with commands won't work. */
7247 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
7248 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7250 bs
->breakpoint_at
= NULL
;
7252 /* bs->commands will be freed later. */
7254 /* On the chance that someone will soon try again to delete this same
7255 bp, we mark it as deleted before freeing its storage. */
7256 bpt
->type
= bp_none
;
7258 for (loc
= bpt
->loc
; loc
;)
7260 struct bp_location
*loc_next
= loc
->next
;
7268 do_delete_breakpoint_cleanup (void *b
)
7270 delete_breakpoint (b
);
7274 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7276 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7280 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
7282 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
7286 delete_command (char *arg
, int from_tty
)
7288 struct breakpoint
*b
, *temp
;
7294 int breaks_to_delete
= 0;
7296 /* Delete all breakpoints if no argument.
7297 Do not delete internal or call-dummy breakpoints, these
7298 have to be deleted with an explicit breakpoint number argument. */
7301 if (b
->type
!= bp_call_dummy
&&
7302 b
->type
!= bp_shlib_event
&&
7303 b
->type
!= bp_thread_event
&&
7304 b
->type
!= bp_overlay_event
&&
7307 breaks_to_delete
= 1;
7312 /* Ask user only if there are some breakpoints to delete. */
7314 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7316 ALL_BREAKPOINTS_SAFE (b
, temp
)
7318 if (b
->type
!= bp_call_dummy
&&
7319 b
->type
!= bp_shlib_event
&&
7320 b
->type
!= bp_thread_event
&&
7321 b
->type
!= bp_overlay_event
&&
7323 delete_breakpoint (b
);
7328 map_breakpoint_numbers (arg
, delete_breakpoint
);
7332 all_locations_are_pending (struct bp_location
*loc
)
7334 for (; loc
; loc
= loc
->next
)
7335 if (!loc
->shlib_disabled
)
7341 update_breakpoint_locations (struct breakpoint
*b
,
7342 struct symtabs_and_lines sals
)
7346 struct bp_location
*existing_locations
= b
->loc
;
7348 /* If there's no new locations, and all existing locations
7349 are pending, don't do anything. This optimizes
7350 the common case where all locations are in the same
7351 shared library, that was unloaded. We'd like to
7352 retain the location, so that when the library
7353 is loaded again, we don't loose the enabled/disabled
7354 status of the individual locations. */
7355 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7358 unlink_locations_from_global_list (b
);
7361 for (i
= 0; i
< sals
.nelts
; ++i
)
7363 struct bp_location
*new_loc
=
7364 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7366 /* Reparse conditions, they might contain references to the
7368 if (b
->cond_string
!= NULL
)
7370 struct gdb_exception e
;
7373 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7375 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7380 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7381 b
->number
, e
.message
);
7382 new_loc
->enabled
= 0;
7386 if (b
->source_file
!= NULL
)
7387 xfree (b
->source_file
);
7388 if (sals
.sals
[i
].symtab
== NULL
)
7389 b
->source_file
= NULL
;
7392 savestring (sals
.sals
[i
].symtab
->filename
,
7393 strlen (sals
.sals
[i
].symtab
->filename
));
7395 if (b
->line_number
== 0)
7396 b
->line_number
= sals
.sals
[i
].line
;
7399 /* If possible, carry over 'disable' status from existing breakpoints. */
7401 struct bp_location
*e
= existing_locations
;
7402 for (; e
; e
= e
->next
)
7404 if (!e
->enabled
&& e
->function_name
)
7406 struct bp_location
*l
= b
->loc
;
7407 for (; l
; l
= l
->next
)
7408 if (l
->function_name
7409 && strcmp (e
->function_name
, l
->function_name
) == 0)
7418 while (existing_locations
)
7420 struct bp_location
*next
= existing_locations
->next
;
7421 free_bp_location (existing_locations
);
7422 existing_locations
= next
;
7427 /* Reset a breakpoint given it's struct breakpoint * BINT.
7428 The value we return ends up being the return value from catch_errors.
7429 Unused in this case. */
7432 breakpoint_re_set_one (void *bint
)
7434 /* get past catch_errs */
7435 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7439 int *not_found_ptr
= ¬_found
;
7440 struct symtabs_and_lines sals
= {};
7441 struct symtabs_and_lines expanded
;
7443 enum enable_state save_enable
;
7444 struct gdb_exception e
;
7450 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7454 case bp_hardware_breakpoint
:
7456 case bp_catch_unload
:
7457 if (b
->addr_string
== NULL
)
7459 /* Anything without a string can't be re-set. */
7460 delete_breakpoint (b
);
7464 set_language (b
->language
);
7465 input_radix
= b
->input_radix
;
7467 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7469 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7474 int not_found_and_ok
= 0;
7475 /* For pending breakpoints, it's expected that parsing
7476 will fail until the right shared library is loaded.
7477 User has already told to create pending breakpoints and
7478 don't need extra messages. If breakpoint is in bp_shlib_disabled
7479 state, then user already saw the message about that breakpoint
7480 being disabled, and don't want to see more errors. */
7482 && (b
->condition_not_parsed
7483 || (b
->loc
&& b
->loc
->shlib_disabled
)
7484 || b
->enable_state
== bp_disabled
))
7485 not_found_and_ok
= 1;
7487 if (!not_found_and_ok
)
7489 /* We surely don't want to warn about the same breakpoint
7490 10 times. One solution, implemented here, is disable
7491 the breakpoint on error. Another solution would be to
7492 have separate 'warning emitted' flag. Since this
7493 happens only when a binary has changed, I don't know
7494 which approach is better. */
7495 b
->enable_state
= bp_disabled
;
7496 throw_exception (e
);
7503 gdb_assert (sals
.nelts
== 1);
7504 resolve_sal_pc (&sals
.sals
[0]);
7505 if (b
->condition_not_parsed
&& s
&& s
[0])
7507 char *cond_string
= 0;
7509 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7510 &cond_string
, &thread
);
7512 b
->cond_string
= cond_string
;
7514 b
->condition_not_parsed
= 0;
7516 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7517 update_breakpoint_locations (b
, expanded
);
7519 /* Now that this is re-enabled, check_duplicates
7521 check_duplicates (b
);
7527 case bp_hardware_watchpoint
:
7528 case bp_read_watchpoint
:
7529 case bp_access_watchpoint
:
7530 innermost_block
= NULL
;
7531 /* The issue arises of what context to evaluate this in. The
7532 same one as when it was set, but what does that mean when
7533 symbols have been re-read? We could save the filename and
7534 functionname, but if the context is more local than that, the
7535 best we could do would be something like how many levels deep
7536 and which index at that particular level, but that's going to
7537 be less stable than filenames or function names. */
7539 /* So for now, just use a global context. */
7543 /* Avoid re-freeing b->exp if an error during the call to
7544 parse_expression. */
7547 b
->exp
= parse_expression (b
->exp_string
);
7548 b
->exp_valid_block
= innermost_block
;
7549 mark
= value_mark ();
7552 value_free (b
->val
);
7553 /* Avoid re-freeing b->val if an error during the call to
7554 evaluate_expression. */
7557 b
->val
= evaluate_expression (b
->exp
);
7558 release_value (b
->val
);
7559 if (value_lazy (b
->val
) && breakpoint_enabled (b
))
7560 value_fetch_lazy (b
->val
);
7562 if (b
->cond_string
!= NULL
)
7567 xfree (b
->loc
->cond
);
7568 /* Avoid re-freeing b->exp if an error during the call
7570 b
->loc
->cond
= NULL
;
7572 b
->loc
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
7574 if (breakpoint_enabled (b
))
7576 value_free_to_mark (mark
);
7578 case bp_catch_catch
:
7579 case bp_catch_throw
:
7581 /* We needn't really do anything to reset these, since the mask
7582 that requests them is unaffected by e.g., new libraries being
7585 case bp_catch_vfork
:
7590 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7592 /* Delete longjmp and overlay event breakpoints; they will be
7593 reset later by breakpoint_re_set. */
7595 case bp_longjmp_resume
:
7596 case bp_overlay_event
:
7597 delete_breakpoint (b
);
7600 /* This breakpoint is special, it's set up when the inferior
7601 starts and we really don't want to touch it. */
7602 case bp_shlib_event
:
7604 /* Like bp_shlib_event, this breakpoint type is special.
7605 Once it is set up, we do not want to touch it. */
7606 case bp_thread_event
:
7608 /* Keep temporary breakpoints, which can be encountered when we step
7609 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7610 Otherwise these should have been blown away via the cleanup chain
7611 or by breakpoint_init_inferior when we rerun the executable. */
7614 case bp_watchpoint_scope
:
7616 case bp_step_resume
:
7623 /* Re-set all breakpoints after symbols have been re-loaded. */
7625 breakpoint_re_set (void)
7627 struct breakpoint
*b
, *temp
;
7628 enum language save_language
;
7629 int save_input_radix
;
7631 save_language
= current_language
->la_language
;
7632 save_input_radix
= input_radix
;
7633 ALL_BREAKPOINTS_SAFE (b
, temp
)
7635 /* Format possible error msg */
7636 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7638 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7639 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7640 do_cleanups (cleanups
);
7642 set_language (save_language
);
7643 input_radix
= save_input_radix
;
7645 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
7647 create_longjmp_breakpoint ("longjmp");
7648 create_longjmp_breakpoint ("_longjmp");
7649 create_longjmp_breakpoint ("siglongjmp");
7650 create_longjmp_breakpoint ("_siglongjmp");
7651 create_longjmp_breakpoint (NULL
);
7654 create_overlay_event_breakpoint ("_ovly_debug_event");
7657 /* Reset the thread number of this breakpoint:
7659 - If the breakpoint is for all threads, leave it as-is.
7660 - Else, reset it to the current thread for inferior_ptid. */
7662 breakpoint_re_set_thread (struct breakpoint
*b
)
7664 if (b
->thread
!= -1)
7666 if (in_thread_list (inferior_ptid
))
7667 b
->thread
= pid_to_thread_id (inferior_ptid
);
7671 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7672 If from_tty is nonzero, it prints a message to that effect,
7673 which ends with a period (no newline). */
7676 set_ignore_count (int bptnum
, int count
, int from_tty
)
7678 struct breakpoint
*b
;
7684 if (b
->number
== bptnum
)
7686 b
->ignore_count
= count
;
7690 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7692 else if (count
== 1)
7693 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7696 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7699 breakpoints_changed ();
7700 breakpoint_modify_event (b
->number
);
7704 error (_("No breakpoint number %d."), bptnum
);
7707 /* Clear the ignore counts of all breakpoints. */
7709 breakpoint_clear_ignore_counts (void)
7711 struct breakpoint
*b
;
7714 b
->ignore_count
= 0;
7717 /* Command to set ignore-count of breakpoint N to COUNT. */
7720 ignore_command (char *args
, int from_tty
)
7726 error_no_arg (_("a breakpoint number"));
7728 num
= get_number (&p
);
7730 error (_("bad breakpoint number: '%s'"), args
);
7732 error (_("Second argument (specified ignore-count) is missing."));
7734 set_ignore_count (num
,
7735 longest_to_int (value_as_long (parse_and_eval (p
))),
7738 printf_filtered ("\n");
7741 /* Call FUNCTION on each of the breakpoints
7742 whose numbers are given in ARGS. */
7745 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7750 struct breakpoint
*b
, *tmp
;
7754 error_no_arg (_("one or more breakpoint numbers"));
7761 num
= get_number_or_range (&p1
);
7764 warning (_("bad breakpoint number at or near '%s'"), p
);
7768 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7769 if (b
->number
== num
)
7771 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7774 if (related_breakpoint
)
7775 function (related_breakpoint
);
7779 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7785 static struct bp_location
*
7786 find_location_by_number (char *number
)
7788 char *dot
= strchr (number
, '.');
7792 struct breakpoint
*b
;
7793 struct bp_location
*loc
;
7798 bp_num
= get_number_or_range (&p1
);
7800 error (_("Bad breakpoint number '%s'"), number
);
7803 if (b
->number
== bp_num
)
7808 if (!b
|| b
->number
!= bp_num
)
7809 error (_("Bad breakpoint number '%s'"), number
);
7812 loc_num
= get_number_or_range (&p1
);
7814 error (_("Bad breakpoint location number '%s'"), number
);
7818 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7821 error (_("Bad breakpoint location number '%s'"), dot
+1);
7827 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7828 If from_tty is nonzero, it prints a message to that effect,
7829 which ends with a period (no newline). */
7832 disable_breakpoint (struct breakpoint
*bpt
)
7834 /* Never disable a watchpoint scope breakpoint; we want to
7835 hit them when we leave scope so we can delete both the
7836 watchpoint and its scope breakpoint at that time. */
7837 if (bpt
->type
== bp_watchpoint_scope
)
7840 /* You can't disable permanent breakpoints. */
7841 if (bpt
->enable_state
== bp_permanent
)
7844 bpt
->enable_state
= bp_disabled
;
7846 check_duplicates (bpt
);
7848 if (deprecated_modify_breakpoint_hook
)
7849 deprecated_modify_breakpoint_hook (bpt
);
7850 breakpoint_modify_event (bpt
->number
);
7854 disable_command (char *args
, int from_tty
)
7856 struct breakpoint
*bpt
;
7858 ALL_BREAKPOINTS (bpt
)
7862 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7867 case bp_catch_unload
:
7869 case bp_catch_vfork
:
7871 case bp_catch_catch
:
7872 case bp_catch_throw
:
7873 case bp_hardware_breakpoint
:
7875 case bp_hardware_watchpoint
:
7876 case bp_read_watchpoint
:
7877 case bp_access_watchpoint
:
7878 disable_breakpoint (bpt
);
7882 else if (strchr (args
, '.'))
7884 struct bp_location
*loc
= find_location_by_number (args
);
7887 check_duplicates (loc
->owner
);
7890 map_breakpoint_numbers (args
, disable_breakpoint
);
7894 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7896 int target_resources_ok
, other_type_used
;
7899 if (bpt
->type
== bp_hardware_breakpoint
)
7902 i
= hw_breakpoint_used_count ();
7903 target_resources_ok
=
7904 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7906 if (target_resources_ok
== 0)
7907 error (_("No hardware breakpoint support in the target."));
7908 else if (target_resources_ok
< 0)
7909 error (_("Hardware breakpoints used exceeds limit."));
7912 if (bpt
->type
== bp_watchpoint
||
7913 bpt
->type
== bp_hardware_watchpoint
||
7914 bpt
->type
== bp_read_watchpoint
||
7915 bpt
->type
== bp_access_watchpoint
)
7917 struct frame_id saved_frame_id
;
7919 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7920 if (bpt
->exp_valid_block
!= NULL
)
7922 struct frame_info
*fr
=
7923 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7926 printf_filtered (_("\
7927 Cannot enable watchpoint %d because the block in which its expression\n\
7928 is valid is not currently in scope.\n"), bpt
->number
);
7935 value_free (bpt
->val
);
7936 mark
= value_mark ();
7937 bpt
->val
= evaluate_expression (bpt
->exp
);
7938 release_value (bpt
->val
);
7939 if (value_lazy (bpt
->val
))
7940 value_fetch_lazy (bpt
->val
);
7942 if (bpt
->type
== bp_hardware_watchpoint
||
7943 bpt
->type
== bp_read_watchpoint
||
7944 bpt
->type
== bp_access_watchpoint
)
7946 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7947 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7949 /* Hack around 'unused var' error for some targets here */
7950 (void) mem_cnt
, (void) i
;
7951 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7952 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7953 /* we can consider of type is bp_hardware_watchpoint, convert to
7954 bp_watchpoint in the following condition */
7955 if (target_resources_ok
< 0)
7957 printf_filtered (_("\
7958 Cannot enable watchpoint %d because target watch resources\n\
7959 have been allocated for other watchpoints.\n"), bpt
->number
);
7960 value_free_to_mark (mark
);
7965 select_frame (frame_find_by_id (saved_frame_id
));
7966 value_free_to_mark (mark
);
7969 if (bpt
->enable_state
!= bp_permanent
)
7970 bpt
->enable_state
= bp_enabled
;
7971 bpt
->disposition
= disposition
;
7972 check_duplicates (bpt
);
7973 breakpoints_changed ();
7975 if (deprecated_modify_breakpoint_hook
)
7976 deprecated_modify_breakpoint_hook (bpt
);
7977 breakpoint_modify_event (bpt
->number
);
7982 enable_breakpoint (struct breakpoint
*bpt
)
7984 do_enable_breakpoint (bpt
, bpt
->disposition
);
7987 /* The enable command enables the specified breakpoints (or all defined
7988 breakpoints) so they once again become (or continue to be) effective
7989 in stopping the inferior. */
7992 enable_command (char *args
, int from_tty
)
7994 struct breakpoint
*bpt
;
7996 ALL_BREAKPOINTS (bpt
)
8000 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8005 case bp_catch_unload
:
8007 case bp_catch_vfork
:
8009 case bp_catch_catch
:
8010 case bp_catch_throw
:
8011 case bp_hardware_breakpoint
:
8013 case bp_hardware_watchpoint
:
8014 case bp_read_watchpoint
:
8015 case bp_access_watchpoint
:
8016 enable_breakpoint (bpt
);
8020 else if (strchr (args
, '.'))
8022 struct bp_location
*loc
= find_location_by_number (args
);
8025 check_duplicates (loc
->owner
);
8028 map_breakpoint_numbers (args
, enable_breakpoint
);
8032 enable_once_breakpoint (struct breakpoint
*bpt
)
8034 do_enable_breakpoint (bpt
, disp_disable
);
8038 enable_once_command (char *args
, int from_tty
)
8040 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8044 enable_delete_breakpoint (struct breakpoint
*bpt
)
8046 do_enable_breakpoint (bpt
, disp_del
);
8050 enable_delete_command (char *args
, int from_tty
)
8052 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8056 set_breakpoint_cmd (char *args
, int from_tty
)
8061 show_breakpoint_cmd (char *args
, int from_tty
)
8065 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8067 struct symtabs_and_lines
8068 decode_line_spec_1 (char *string
, int funfirstline
)
8070 struct symtabs_and_lines sals
;
8072 error (_("Empty line specification."));
8073 if (default_breakpoint_valid
)
8074 sals
= decode_line_1 (&string
, funfirstline
,
8075 default_breakpoint_symtab
,
8076 default_breakpoint_line
,
8077 (char ***) NULL
, NULL
);
8079 sals
= decode_line_1 (&string
, funfirstline
,
8080 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8082 error (_("Junk at end of line specification: %s"), string
);
8086 /* Create and insert a raw software breakpoint at PC. Return an
8087 identifier, which should be used to remove the breakpoint later.
8088 In general, places which call this should be using something on the
8089 breakpoint chain instead; this function should be eliminated
8093 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8095 struct bp_target_info
*bp_tgt
;
8097 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8098 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8100 bp_tgt
->placed_address
= pc
;
8101 if (target_insert_breakpoint (bp_tgt
) != 0)
8103 /* Could not insert the breakpoint. */
8111 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8114 deprecated_remove_raw_breakpoint (void *bp
)
8116 struct bp_target_info
*bp_tgt
= bp
;
8119 ret
= target_remove_breakpoint (bp_tgt
);
8125 /* One (or perhaps two) breakpoints used for software single stepping. */
8127 static void *single_step_breakpoints
[2];
8129 /* Create and insert a breakpoint for software single step. */
8132 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8136 if (single_step_breakpoints
[0] == NULL
)
8137 bpt_p
= &single_step_breakpoints
[0];
8140 gdb_assert (single_step_breakpoints
[1] == NULL
);
8141 bpt_p
= &single_step_breakpoints
[1];
8144 /* NOTE drow/2006-04-11: A future improvement to this function would be
8145 to only create the breakpoints once, and actually put them on the
8146 breakpoint chain. That would let us use set_raw_breakpoint. We could
8147 adjust the addresses each time they were needed. Doing this requires
8148 corresponding changes elsewhere where single step breakpoints are
8149 handled, however. So, for now, we use this. */
8151 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8153 error (_("Could not insert single-step breakpoint at 0x%s"),
8154 paddr_nz (next_pc
));
8157 /* Remove and delete any breakpoints used for software single step. */
8160 remove_single_step_breakpoints (void)
8162 gdb_assert (single_step_breakpoints
[0] != NULL
);
8164 /* See insert_single_step_breakpoint for more about this deprecated
8166 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8167 single_step_breakpoints
[0] = NULL
;
8169 if (single_step_breakpoints
[1] != NULL
)
8171 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8172 single_step_breakpoints
[1] = NULL
;
8176 /* Check whether a software single-step breakpoint is inserted at PC. */
8179 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8183 for (i
= 0; i
< 2; i
++)
8185 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8186 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8194 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8195 It is defined as a macro to prevent duplication.
8196 COMMAND should be a string constant containing the name of the command. */
8197 #define BREAK_ARGS_HELP(command) \
8198 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8199 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8200 If a line number is specified, break at start of code for that line.\n\
8201 If a function is specified, break at start of code for that function.\n\
8202 If an address is specified, break at that exact address.\n\
8203 With no LOCATION, uses current execution address of selected stack frame.\n\
8204 This is useful for breaking on return to a stack frame.\n\
8206 THREADNUM is the number from \"info threads\".\n\
8207 CONDITION is a boolean expression.\n\
8209 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8211 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8214 _initialize_breakpoint (void)
8216 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8217 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8218 struct cmd_list_element
*c
;
8220 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8222 breakpoint_chain
= 0;
8223 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8224 before a breakpoint is set. */
8225 breakpoint_count
= 0;
8227 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8228 Set ignore-count of breakpoint number N to COUNT.\n\
8229 Usage is `ignore N COUNT'."));
8231 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8233 add_com ("commands", class_breakpoint
, commands_command
, _("\
8234 Set commands to be executed when a breakpoint is hit.\n\
8235 Give breakpoint number as argument after \"commands\".\n\
8236 With no argument, the targeted breakpoint is the last one set.\n\
8237 The commands themselves follow starting on the next line.\n\
8238 Type a line containing \"end\" to indicate the end of them.\n\
8239 Give \"silent\" as the first line to make the breakpoint silent;\n\
8240 then no output is printed when it is hit, except what the commands print."));
8242 add_com ("condition", class_breakpoint
, condition_command
, _("\
8243 Specify breakpoint number N to break only if COND is true.\n\
8244 Usage is `condition N COND', where N is an integer and COND is an\n\
8245 expression to be evaluated whenever breakpoint N is reached."));
8247 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8248 Set a temporary breakpoint.\n\
8249 Like \"break\" except the breakpoint is only temporary,\n\
8250 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8251 by using \"enable delete\" on the breakpoint number.\n\
8253 BREAK_ARGS_HELP ("tbreak")));
8254 set_cmd_completer (c
, location_completer
);
8256 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8257 Set a hardware assisted breakpoint.\n\
8258 Like \"break\" except the breakpoint requires hardware support,\n\
8259 some target hardware may not have this support.\n\
8261 BREAK_ARGS_HELP ("hbreak")));
8262 set_cmd_completer (c
, location_completer
);
8264 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8265 Set a temporary hardware assisted breakpoint.\n\
8266 Like \"hbreak\" except the breakpoint is only temporary,\n\
8267 so it will be deleted when hit.\n\
8269 BREAK_ARGS_HELP ("thbreak")));
8270 set_cmd_completer (c
, location_completer
);
8272 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8273 Enable some breakpoints.\n\
8274 Give breakpoint numbers (separated by spaces) as arguments.\n\
8275 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8276 This is used to cancel the effect of the \"disable\" command.\n\
8277 With a subcommand you can enable temporarily."),
8278 &enablelist
, "enable ", 1, &cmdlist
);
8280 add_com ("ab", class_breakpoint
, enable_command
, _("\
8281 Enable some breakpoints.\n\
8282 Give breakpoint numbers (separated by spaces) as arguments.\n\
8283 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8284 This is used to cancel the effect of the \"disable\" command.\n\
8285 With a subcommand you can enable temporarily."));
8287 add_com_alias ("en", "enable", class_breakpoint
, 1);
8289 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8290 Enable some breakpoints.\n\
8291 Give breakpoint numbers (separated by spaces) as arguments.\n\
8292 This is used to cancel the effect of the \"disable\" command.\n\
8293 May be abbreviated to simply \"enable\".\n"),
8294 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8296 add_cmd ("once", no_class
, enable_once_command
, _("\
8297 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8298 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8301 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8302 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8303 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8306 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8307 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8308 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8311 add_cmd ("once", no_class
, enable_once_command
, _("\
8312 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8313 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8316 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8317 Disable some breakpoints.\n\
8318 Arguments are breakpoint numbers with spaces in between.\n\
8319 To disable all breakpoints, give no argument.\n\
8320 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8321 &disablelist
, "disable ", 1, &cmdlist
);
8322 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8323 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8325 add_com ("sb", class_breakpoint
, disable_command
, _("\
8326 Disable some breakpoints.\n\
8327 Arguments are breakpoint numbers with spaces in between.\n\
8328 To disable all breakpoints, give no argument.\n\
8329 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8331 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8332 Disable some breakpoints.\n\
8333 Arguments are breakpoint numbers with spaces in between.\n\
8334 To disable all breakpoints, give no argument.\n\
8335 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8336 This command may be abbreviated \"disable\"."),
8339 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8340 Delete some breakpoints or auto-display expressions.\n\
8341 Arguments are breakpoint numbers with spaces in between.\n\
8342 To delete all breakpoints, give no argument.\n\
8344 Also a prefix command for deletion of other GDB objects.\n\
8345 The \"unset\" command is also an alias for \"delete\"."),
8346 &deletelist
, "delete ", 1, &cmdlist
);
8347 add_com_alias ("d", "delete", class_breakpoint
, 1);
8348 add_com_alias ("del", "delete", class_breakpoint
, 1);
8350 add_com ("db", class_breakpoint
, delete_command
, _("\
8351 Delete some breakpoints.\n\
8352 Arguments are breakpoint numbers with spaces in between.\n\
8353 To delete all breakpoints, give no argument.\n"));
8355 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8356 Delete some breakpoints or auto-display expressions.\n\
8357 Arguments are breakpoint numbers with spaces in between.\n\
8358 To delete all breakpoints, give no argument.\n\
8359 This command may be abbreviated \"delete\"."),
8362 add_com ("clear", class_breakpoint
, clear_command
, _("\
8363 Clear breakpoint at specified line or function.\n\
8364 Argument may be line number, function name, or \"*\" and an address.\n\
8365 If line number is specified, all breakpoints in that line are cleared.\n\
8366 If function is specified, breakpoints at beginning of function are cleared.\n\
8367 If an address is specified, breakpoints at that address are cleared.\n\
8369 With no argument, clears all breakpoints in the line that the selected frame\n\
8372 See also the \"delete\" command which clears breakpoints by number."));
8374 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8375 Set breakpoint at specified line or function.\n"
8376 BREAK_ARGS_HELP ("break")));
8377 set_cmd_completer (c
, location_completer
);
8379 add_com_alias ("b", "break", class_run
, 1);
8380 add_com_alias ("br", "break", class_run
, 1);
8381 add_com_alias ("bre", "break", class_run
, 1);
8382 add_com_alias ("brea", "break", class_run
, 1);
8386 add_com_alias ("ba", "break", class_breakpoint
, 1);
8387 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8392 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8393 Break in function/address or break at a line in the current file."),
8394 &stoplist
, "stop ", 1, &cmdlist
);
8395 add_cmd ("in", class_breakpoint
, stopin_command
,
8396 _("Break in function or address."), &stoplist
);
8397 add_cmd ("at", class_breakpoint
, stopat_command
,
8398 _("Break at a line in the current file."), &stoplist
);
8399 add_com ("status", class_info
, breakpoints_info
, _("\
8400 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8401 The \"Type\" column indicates one of:\n\
8402 \tbreakpoint - normal breakpoint\n\
8403 \twatchpoint - watchpoint\n\
8404 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8405 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8406 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8407 address and file/line number respectively.\n\
8409 Convenience variable \"$_\" and default examine address for \"x\"\n\
8410 are set to the address of the last breakpoint listed unless the command\n\
8411 is prefixed with \"server \".\n\n\
8412 Convenience variable \"$bpnum\" contains the number of the last\n\
8416 add_info ("breakpoints", breakpoints_info
, _("\
8417 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8418 The \"Type\" column indicates one of:\n\
8419 \tbreakpoint - normal breakpoint\n\
8420 \twatchpoint - watchpoint\n\
8421 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8422 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8423 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8424 address and file/line number respectively.\n\
8426 Convenience variable \"$_\" and default examine address for \"x\"\n\
8427 are set to the address of the last breakpoint listed unless the command\n\
8428 is prefixed with \"server \".\n\n\
8429 Convenience variable \"$bpnum\" contains the number of the last\n\
8433 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8434 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8435 The \"Type\" column indicates one of:\n\
8436 \tbreakpoint - normal breakpoint\n\
8437 \twatchpoint - watchpoint\n\
8438 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8439 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8440 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8441 address and file/line number respectively.\n\
8443 Convenience variable \"$_\" and default examine address for \"x\"\n\
8444 are set to the address of the last breakpoint listed unless the command\n\
8445 is prefixed with \"server \".\n\n\
8446 Convenience variable \"$bpnum\" contains the number of the last\n\
8449 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8450 Status of all breakpoints, or breakpoint number NUMBER.\n\
8451 The \"Type\" column indicates one of:\n\
8452 \tbreakpoint - normal breakpoint\n\
8453 \twatchpoint - watchpoint\n\
8454 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8455 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8456 \tuntil - internal breakpoint used by the \"until\" command\n\
8457 \tfinish - internal breakpoint used by the \"finish\" command\n\
8458 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8459 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8460 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8461 address and file/line number respectively.\n\
8463 Convenience variable \"$_\" and default examine address for \"x\"\n\
8464 are set to the address of the last breakpoint listed unless the command\n\
8465 is prefixed with \"server \".\n\n\
8466 Convenience variable \"$bpnum\" contains the number of the last\n\
8468 &maintenanceinfolist
);
8470 add_com ("catch", class_breakpoint
, catch_command
, _("\
8471 Set catchpoints to catch events.\n\
8472 Raised signals may be caught:\n\
8473 \tcatch signal - all signals\n\
8474 \tcatch signal <signame> - a particular signal\n\
8475 Raised exceptions may be caught:\n\
8476 \tcatch throw - all exceptions, when thrown\n\
8477 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8478 \tcatch catch - all exceptions, when caught\n\
8479 \tcatch catch <exceptname> - a particular exception, when caught\n\
8480 Thread or process events may be caught:\n\
8481 \tcatch thread_start - any threads, just after creation\n\
8482 \tcatch thread_exit - any threads, just before expiration\n\
8483 \tcatch thread_join - any threads, just after joins\n\
8484 Process events may be caught:\n\
8485 \tcatch start - any processes, just after creation\n\
8486 \tcatch exit - any processes, just before expiration\n\
8487 \tcatch fork - calls to fork()\n\
8488 \tcatch vfork - calls to vfork()\n\
8489 \tcatch exec - calls to exec()\n\
8490 Dynamically-linked library events may be caught:\n\
8491 \tcatch load - loads of any library\n\
8492 \tcatch load <libname> - loads of a particular library\n\
8493 \tcatch unload - unloads of any library\n\
8494 \tcatch unload <libname> - unloads of a particular library\n\
8495 The act of your program's execution stopping may also be caught:\n\
8497 C++ exceptions may be caught:\n\
8498 \tcatch throw - all exceptions, when thrown\n\
8499 \tcatch catch - all exceptions, when caught\n\
8500 Ada exceptions may be caught:\n\
8501 \tcatch exception - all exceptions, when raised\n\
8502 \tcatch exception <name> - a particular exception, when raised\n\
8503 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8504 \tcatch assert - all failed assertions, when raised\n\
8506 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8507 after a fork or vfork is caught.\n\n\
8508 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8510 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8511 Set temporary catchpoints to catch events.\n\
8512 Args like \"catch\" command.\n\
8513 Like \"catch\" except the catchpoint is only temporary,\n\
8514 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8515 by using \"enable delete\" on the catchpoint number."));
8517 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8518 Set a watchpoint for an expression.\n\
8519 A watchpoint stops execution of your program whenever the value of\n\
8520 an expression changes."));
8521 set_cmd_completer (c
, location_completer
);
8523 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8524 Set a read watchpoint for an expression.\n\
8525 A watchpoint stops execution of your program whenever the value of\n\
8526 an expression is read."));
8527 set_cmd_completer (c
, location_completer
);
8529 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8530 Set a watchpoint for an expression.\n\
8531 A watchpoint stops execution of your program whenever the value of\n\
8532 an expression is either read or written."));
8533 set_cmd_completer (c
, location_completer
);
8535 add_info ("watchpoints", breakpoints_info
,
8536 _("Synonym for ``info breakpoints''."));
8539 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8540 respond to changes - contrary to the description. */
8541 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8542 &can_use_hw_watchpoints
, _("\
8543 Set debugger's willingness to use watchpoint hardware."), _("\
8544 Show debugger's willingness to use watchpoint hardware."), _("\
8545 If zero, gdb will not use hardware for new watchpoints, even if\n\
8546 such is available. (However, any hardware watchpoints that were\n\
8547 created before setting this to nonzero, will continue to use watchpoint\n\
8550 show_can_use_hw_watchpoints
,
8551 &setlist
, &showlist
);
8553 can_use_hw_watchpoints
= 1;
8555 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8556 Breakpoint specific settings\n\
8557 Configure various breakpoint-specific variables such as\n\
8558 pending breakpoint behavior"),
8559 &breakpoint_set_cmdlist
, "set breakpoint ",
8560 0/*allow-unknown*/, &setlist
);
8561 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8562 Breakpoint specific settings\n\
8563 Configure various breakpoint-specific variables such as\n\
8564 pending breakpoint behavior"),
8565 &breakpoint_show_cmdlist
, "show breakpoint ",
8566 0/*allow-unknown*/, &showlist
);
8568 add_setshow_auto_boolean_cmd ("pending", no_class
,
8569 &pending_break_support
, _("\
8570 Set debugger's behavior regarding pending breakpoints."), _("\
8571 Show debugger's behavior regarding pending breakpoints."), _("\
8572 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8573 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8574 an error. If auto, an unrecognized breakpoint location results in a\n\
8575 user-query to see if a pending breakpoint should be created."),
8577 show_pending_break_support
,
8578 &breakpoint_set_cmdlist
,
8579 &breakpoint_show_cmdlist
);
8581 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8583 add_setshow_boolean_cmd ("auto-hw", no_class
,
8584 &automatic_hardware_breakpoints
, _("\
8585 Set automatic usage of hardware breakpoints."), _("\
8586 Show automatic usage of hardware breakpoints."), _("\
8587 If set, the debugger will automatically use hardware breakpoints for\n\
8588 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8589 a warning will be emitted for such breakpoints."),
8591 show_automatic_hardware_breakpoints
,
8592 &breakpoint_set_cmdlist
,
8593 &breakpoint_show_cmdlist
);
8595 automatic_hardware_breakpoints
= 1;