1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "breakpoint.h"
28 #include "expression.h"
34 #include "gdbthread.h"
37 #include "gdb_string.h"
44 #include "completer.h"
47 #include "cli/cli-script.h"
48 #include "gdb_assert.h"
53 #include "exceptions.h"
58 #include "gdb-events.h"
59 #include "mi/mi-common.h"
61 /* Prototypes for local functions. */
63 static void until_break_command_continuation (struct continuation_arg
*arg
);
65 static void catch_command_1 (char *, int, int);
67 static void enable_delete_command (char *, int);
69 static void enable_delete_breakpoint (struct breakpoint
*);
71 static void enable_once_command (char *, int);
73 static void enable_once_breakpoint (struct breakpoint
*);
75 static void disable_command (char *, int);
77 static void enable_command (char *, int);
79 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
81 static void ignore_command (char *, int);
83 static int breakpoint_re_set_one (void *);
85 static void clear_command (char *, int);
87 static void catch_command (char *, int);
89 static void watch_command (char *, int);
91 static int can_use_hardware_watchpoint (struct value
*);
93 static int break_command_1 (char *, int, int, struct breakpoint
*);
95 static void mention (struct breakpoint
*);
97 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
99 static void check_duplicates (struct breakpoint
*);
101 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
103 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
106 static void describe_other_breakpoints (CORE_ADDR
, asection
*, int);
108 static void breakpoints_info (char *, int);
110 static void breakpoint_1 (int, int);
112 static bpstat
bpstat_alloc (struct breakpoint
*, bpstat
);
114 static int breakpoint_cond_eval (void *);
116 static void cleanup_executing_breakpoints (void *);
118 static void commands_command (char *, int);
120 static void condition_command (char *, int);
122 static int get_number_trailer (char **, int);
124 void set_breakpoint_count (int);
133 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
135 static enum print_stop_action
print_it_typical (bpstat
);
137 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
141 enum exception_event_kind kind
;
144 args_for_catchpoint_enable
;
146 static int watchpoint_check (void *);
148 static int cover_target_enable_exception_callback (void *);
150 static void maintenance_info_breakpoints (char *, int);
152 static void create_longjmp_breakpoint (char *);
154 static void create_overlay_event_breakpoint (char *);
156 static int hw_breakpoint_used_count (void);
158 static int hw_watchpoint_used_count (enum bptype
, int *);
160 static void hbreak_command (char *, int);
162 static void thbreak_command (char *, int);
164 static void watch_command_1 (char *, int, int);
166 static void rwatch_command (char *, int);
168 static void awatch_command (char *, int);
170 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
172 static void solib_load_unload_1 (char *hookname
,
175 char *cond_string
, enum bptype bp_kind
);
177 static void create_fork_vfork_event_catchpoint (int tempflag
,
179 enum bptype bp_kind
);
181 static void stop_command (char *arg
, int from_tty
);
183 static void stopin_command (char *arg
, int from_tty
);
185 static void stopat_command (char *arg
, int from_tty
);
187 static char *ep_find_event_name_end (char *arg
);
189 static char *ep_parse_optional_if_clause (char **arg
);
191 static char *ep_parse_optional_filename (char **arg
);
193 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
194 enum exception_event_kind ex_event
,
195 struct symtab_and_line
*sal
);
197 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
198 char *arg
, int tempflag
, int from_tty
);
200 static void tcatch_command (char *arg
, int from_tty
);
202 static void ep_skip_leading_whitespace (char **s
);
204 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
206 /* Prototypes for exported functions. */
208 /* If FALSE, gdb will not use hardware support for watchpoints, even
209 if such is available. */
210 static int can_use_hw_watchpoints
;
213 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
214 struct cmd_list_element
*c
,
217 fprintf_filtered (file
, _("\
218 Debugger's willingness to use watchpoint hardware is %s.\n"),
222 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
223 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
224 for unrecognized breakpoint locations.
225 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
226 static enum auto_boolean pending_break_support
;
228 show_pending_break_support (struct ui_file
*file
, int from_tty
,
229 struct cmd_list_element
*c
,
232 fprintf_filtered (file
, _("\
233 Debugger's behavior regarding pending breakpoints is %s.\n"),
237 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
238 set with "break" but falling in read-only memory.
239 If 0, gdb will warn about such breakpoints, but won't automatically
240 use hardware breakpoints. */
241 static int automatic_hardware_breakpoints
;
243 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
244 struct cmd_list_element
*c
,
247 fprintf_filtered (file
, _("\
248 Automatic usage of hardware breakpoints is %s.\n"),
253 void _initialize_breakpoint (void);
255 extern int addressprint
; /* Print machine addresses? */
257 /* Are we executing breakpoint commands? */
258 static int executing_breakpoint_commands
;
260 /* Are overlay event breakpoints enabled? */
261 static int overlay_events_enabled
;
263 /* Walk the following statement or block through all breakpoints.
264 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
267 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
269 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
270 for (B = breakpoint_chain; \
271 B ? (TMP=B->next, 1): 0; \
274 /* Similar iterators for the low-level breakpoints. */
276 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->next)
278 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
279 for (B = bp_location_chain; \
280 B ? (TMP=B->next, 1): 0; \
283 /* True if breakpoint hit counts should be displayed in breakpoint info. */
285 int show_breakpoint_hit_counts
= 1;
287 /* Chains of all breakpoints defined. */
289 struct breakpoint
*breakpoint_chain
;
291 struct bp_location
*bp_location_chain
;
293 /* Number of last breakpoint made. */
295 int breakpoint_count
;
297 /* Pointer to current exception event record */
298 static struct exception_event_record
*current_exception_event
;
300 /* This function returns a pointer to the string representation of the
301 pathname of the dynamically-linked library that has just been
304 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
305 or undefined results are guaranteed.
307 This string's contents are only valid immediately after the
308 inferior has stopped in the dynamic linker hook, and becomes
309 invalid as soon as the inferior is continued. Clients should make
310 a copy of this string if they wish to continue the inferior and
311 then access the string. */
313 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
314 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
317 /* This function returns a pointer to the string representation of the
318 pathname of the dynamically-linked library that has just been
321 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
322 TRUE, or undefined results are guaranteed.
324 This string's contents are only valid immediately after the
325 inferior has stopped in the dynamic linker hook, and becomes
326 invalid as soon as the inferior is continued. Clients should make
327 a copy of this string if they wish to continue the inferior and
328 then access the string. */
330 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
331 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
334 /* This function is called by the "catch load" command. It allows the
335 debugger to be notified by the dynamic linker when a specified
336 library file (or any library file, if filename is NULL) is loaded. */
338 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
339 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
340 error (_("catch of library loads not yet implemented on this platform"))
343 /* This function is called by the "catch unload" command. It allows
344 the debugger to be notified by the dynamic linker when a specified
345 library file (or any library file, if filename is NULL) is
348 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
349 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
350 error (_("catch of library unloads not yet implemented on this platform"))
353 /* Return whether a breakpoint is an active enabled breakpoint. */
355 breakpoint_enabled (struct breakpoint
*b
)
357 return (b
->enable_state
== bp_enabled
&& !b
->pending
);
360 /* Set breakpoint count to NUM. */
363 set_breakpoint_count (int num
)
365 breakpoint_count
= num
;
366 set_internalvar (lookup_internalvar ("bpnum"),
367 value_from_longest (builtin_type_int
, (LONGEST
) num
));
370 /* Used in run_command to zero the hit count when a new run starts. */
373 clear_breakpoint_hit_counts (void)
375 struct breakpoint
*b
;
381 /* Default address, symtab and line to put a breakpoint at
382 for "break" command with no arg.
383 if default_breakpoint_valid is zero, the other three are
384 not valid, and "break" with no arg is an error.
386 This set by print_stack_frame, which calls set_default_breakpoint. */
388 int default_breakpoint_valid
;
389 CORE_ADDR default_breakpoint_address
;
390 struct symtab
*default_breakpoint_symtab
;
391 int default_breakpoint_line
;
393 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
394 Advance *PP after the string and any trailing whitespace.
396 Currently the string can either be a number or "$" followed by the name
397 of a convenience variable. Making it an expression wouldn't work well
398 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
400 If the string is a NULL pointer, that denotes the last breakpoint.
402 TRAILER is a character which can be found after the number; most
403 commonly this is `-'. If you don't want a trailer, use \0. */
405 get_number_trailer (char **pp
, int trailer
)
407 int retval
= 0; /* default */
411 /* Empty line means refer to the last breakpoint. */
412 return breakpoint_count
;
415 /* Make a copy of the name, so we can null-terminate it
416 to pass to lookup_internalvar(). */
421 while (isalnum (*p
) || *p
== '_')
423 varname
= (char *) alloca (p
- start
+ 1);
424 strncpy (varname
, start
, p
- start
);
425 varname
[p
- start
] = '\0';
426 val
= value_of_internalvar (lookup_internalvar (varname
));
427 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
428 retval
= (int) value_as_long (val
);
431 printf_filtered (_("Convenience variable must have integer value.\n"));
439 while (*p
>= '0' && *p
<= '9')
442 /* There is no number here. (e.g. "cond a == b"). */
444 /* Skip non-numeric token */
445 while (*p
&& !isspace((int) *p
))
447 /* Return zero, which caller must interpret as error. */
453 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
455 /* Trailing junk: return 0 and let caller print error msg. */
456 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
467 /* Like get_number_trailer, but don't allow a trailer. */
469 get_number (char **pp
)
471 return get_number_trailer (pp
, '\0');
474 /* Parse a number or a range.
475 * A number will be of the form handled by get_number.
476 * A range will be of the form <number1> - <number2>, and
477 * will represent all the integers between number1 and number2,
480 * While processing a range, this fuction is called iteratively;
481 * At each call it will return the next value in the range.
483 * At the beginning of parsing a range, the char pointer PP will
484 * be advanced past <number1> and left pointing at the '-' token.
485 * Subsequent calls will not advance the pointer until the range
486 * is completed. The call that completes the range will advance
487 * pointer PP past <number2>.
491 get_number_or_range (char **pp
)
493 static int last_retval
, end_value
;
494 static char *end_ptr
;
495 static int in_range
= 0;
499 /* Default case: pp is pointing either to a solo number,
500 or to the first number of a range. */
501 last_retval
= get_number_trailer (pp
, '-');
506 /* This is the start of a range (<number1> - <number2>).
507 Skip the '-', parse and remember the second number,
508 and also remember the end of the final token. */
512 while (isspace ((int) *end_ptr
))
513 end_ptr
++; /* skip white space */
514 end_value
= get_number (temp
);
515 if (end_value
< last_retval
)
517 error (_("inverted range"));
519 else if (end_value
== last_retval
)
521 /* degenerate range (number1 == number2). Advance the
522 token pointer so that the range will be treated as a
531 error (_("negative value"));
534 /* pp points to the '-' that betokens a range. All
535 number-parsing has already been done. Return the next
536 integer value (one greater than the saved previous value).
537 Do not advance the token pointer 'pp' until the end of range
540 if (++last_retval
== end_value
)
542 /* End of range reached; advance token pointer. */
552 /* condition N EXP -- set break condition of breakpoint N to EXP. */
555 condition_command (char *arg
, int from_tty
)
557 struct breakpoint
*b
;
562 error_no_arg (_("breakpoint number"));
565 bnum
= get_number (&p
);
567 error (_("Bad breakpoint argument: '%s'"), arg
);
570 if (b
->number
== bnum
)
577 if (b
->cond_string
!= NULL
)
578 xfree (b
->cond_string
);
583 b
->cond_string
= NULL
;
585 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
590 /* I don't know if it matters whether this is the string the user
591 typed in or the decompiled expression. */
592 b
->cond_string
= savestring (arg
, strlen (arg
));
595 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->loc
->address
), 0);
597 error (_("Junk at end of expression"));
600 breakpoints_changed ();
601 breakpoint_modify_event (b
->number
);
605 error (_("No breakpoint number %d."), bnum
);
609 commands_command (char *arg
, int from_tty
)
611 struct breakpoint
*b
;
614 struct command_line
*l
;
616 /* If we allowed this, we would have problems with when to
617 free the storage, if we change the commands currently
620 if (executing_breakpoint_commands
)
621 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
624 bnum
= get_number (&p
);
627 error (_("Unexpected extra arguments following breakpoint number."));
630 if (b
->number
== bnum
)
632 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
634 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
635 l
= read_command_lines (tmpbuf
, from_tty
);
636 do_cleanups (cleanups
);
637 free_command_lines (&b
->commands
);
639 breakpoints_changed ();
640 breakpoint_modify_event (b
->number
);
643 error (_("No breakpoint number %d."), bnum
);
646 /* Like commands_command, but instead of reading the commands from
647 input stream, takes them from an already parsed command structure.
649 This is used by cli-script.c to DTRT with breakpoint commands
650 that are part of if and while bodies. */
651 enum command_control_type
652 commands_from_control_command (char *arg
, struct command_line
*cmd
)
654 struct breakpoint
*b
;
658 /* If we allowed this, we would have problems with when to
659 free the storage, if we change the commands currently
662 if (executing_breakpoint_commands
)
663 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
665 /* An empty string for the breakpoint number means the last
666 breakpoint, but get_number expects a NULL pointer. */
671 bnum
= get_number (&p
);
674 error (_("Unexpected extra arguments following breakpoint number."));
677 if (b
->number
== bnum
)
679 free_command_lines (&b
->commands
);
680 if (cmd
->body_count
!= 1)
681 error (_("Invalid \"commands\" block structure."));
682 /* We need to copy the commands because if/while will free the
683 list after it finishes execution. */
684 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
685 breakpoints_changed ();
686 breakpoint_modify_event (b
->number
);
687 return simple_control
;
689 error (_("No breakpoint number %d."), bnum
);
692 /* Like target_read_memory() but if breakpoints are inserted, return
693 the shadow contents instead of the breakpoints themselves.
695 Read "memory data" from whatever target or inferior we have.
696 Returns zero if successful, errno value if not. EIO is used
697 for address out of bounds. If breakpoints are inserted, returns
698 shadow contents, not the breakpoints themselves. From breakpoint.c. */
701 read_memory_nobpt (CORE_ADDR memaddr
, gdb_byte
*myaddr
, unsigned len
)
704 struct bp_location
*b
;
705 CORE_ADDR bp_addr
= 0;
708 if (gdbarch_breakpoint_from_pc (current_gdbarch
, &bp_addr
, &bp_size
) == NULL
)
709 /* No breakpoints on this machine. */
710 return target_read_memory (memaddr
, myaddr
, len
);
714 if (b
->owner
->type
== bp_none
)
715 warning (_("reading through apparently deleted breakpoint #%d?"),
718 if (b
->loc_type
!= bp_loc_software_breakpoint
)
722 /* Addresses and length of the part of the breakpoint that
724 bp_addr
= b
->target_info
.placed_address
;
725 bp_size
= b
->target_info
.shadow_len
;
727 /* bp isn't valid, or doesn't shadow memory. */
729 if (bp_addr
+ bp_size
<= memaddr
)
730 /* The breakpoint is entirely before the chunk of memory we
733 if (bp_addr
>= memaddr
+ len
)
734 /* The breakpoint is entirely after the chunk of memory we are
737 /* Copy the breakpoint from the shadow contents, and recurse for
738 the things before and after. */
740 /* Offset within shadow_contents. */
743 if (bp_addr
< memaddr
)
745 /* Only copy the second part of the breakpoint. */
746 bp_size
-= memaddr
- bp_addr
;
747 bptoffset
= memaddr
- bp_addr
;
751 if (bp_addr
+ bp_size
> memaddr
+ len
)
753 /* Only copy the first part of the breakpoint. */
754 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
757 memcpy (myaddr
+ bp_addr
- memaddr
,
758 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
760 if (bp_addr
> memaddr
)
762 /* Copy the section of memory before the breakpoint. */
763 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
768 if (bp_addr
+ bp_size
< memaddr
+ len
)
770 /* Copy the section of memory after the breakpoint. */
771 status
= read_memory_nobpt (bp_addr
+ bp_size
,
772 myaddr
+ bp_addr
+ bp_size
- memaddr
,
773 memaddr
+ len
- (bp_addr
+ bp_size
));
780 /* Nothing overlaps. Just call read_memory_noerr. */
781 return target_read_memory (memaddr
, myaddr
, len
);
785 /* A wrapper function for inserting catchpoints. */
787 insert_catchpoint (struct ui_out
*uo
, void *args
)
789 struct breakpoint
*b
= (struct breakpoint
*) args
;
795 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
798 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
801 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
804 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
809 /* Helper routine: free the value chain for a breakpoint (watchpoint). */
812 free_valchain (struct bp_location
*b
)
817 /* Free the saved value chain. We will construct a new one
818 the next time the watchpoint is inserted. */
819 for (v
= b
->owner
->val_chain
; v
; v
= n
)
824 b
->owner
->val_chain
= NULL
;
827 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
828 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
829 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
831 NOTE drow/2003-09-09: This routine could be broken down to an object-style
832 method for each breakpoint or catchpoint type. */
834 insert_bp_location (struct bp_location
*bpt
,
835 struct ui_file
*tmp_error_stream
,
836 int *disabled_breaks
, int *process_warning
,
837 int *hw_breakpoint_error
)
841 /* Permanent breakpoints cannot be inserted or removed. Disabled
842 breakpoints should not be inserted. */
843 if (!breakpoint_enabled (bpt
->owner
))
846 if (bpt
->inserted
|| bpt
->duplicate
)
849 /* Initialize the target-specific information. */
850 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
851 bpt
->target_info
.placed_address
= bpt
->address
;
853 if (bpt
->loc_type
== bp_loc_software_breakpoint
854 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
856 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
858 /* If the explicitly specified breakpoint type
859 is not hardware breakpoint, check the memory map to see
860 if the breakpoint address is in read only memory or not.
861 Two important cases are:
862 - location type is not hardware breakpoint, memory
863 is readonly. We change the type of the location to
865 - location type is hardware breakpoint, memory is read-write.
866 This means we've previously made the location hardware one, but
867 then the memory map changed, so we undo.
869 When breakpoints are removed, remove_breakpoints will
870 use location types we've just set here, the only possible
871 problem is that memory map has changed during running program,
872 but it's not going to work anyway with current gdb. */
873 struct mem_region
*mr
874 = lookup_mem_region (bpt
->target_info
.placed_address
);
878 if (automatic_hardware_breakpoints
)
881 enum bp_loc_type new_type
;
883 if (mr
->attrib
.mode
!= MEM_RW
)
884 new_type
= bp_loc_hardware_breakpoint
;
886 new_type
= bp_loc_software_breakpoint
;
888 if (new_type
!= bpt
->loc_type
)
891 bpt
->loc_type
= new_type
;
894 fprintf_filtered (gdb_stdout
, _("\
895 Note: automatically using hardware breakpoints for read-only addresses.\n"));
900 else if (bpt
->loc_type
== bp_loc_software_breakpoint
901 && mr
->attrib
.mode
!= MEM_RW
)
902 warning (_("cannot set software breakpoint at readonly address %s"),
903 paddr (bpt
->address
));
907 /* First check to see if we have to handle an overlay. */
908 if (overlay_debugging
== ovly_off
909 || bpt
->section
== NULL
910 || !(section_is_overlay (bpt
->section
)))
912 /* No overlay handling: just set the breakpoint. */
914 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
915 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
917 val
= target_insert_breakpoint (&bpt
->target_info
);
921 /* This breakpoint is in an overlay section.
922 Shall we set a breakpoint at the LMA? */
923 if (!overlay_events_enabled
)
925 /* Yes -- overlay event support is not active,
926 so we must try to set a breakpoint at the LMA.
927 This will not work for a hardware breakpoint. */
928 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
929 warning (_("hardware breakpoint %d not supported in overlay!"),
933 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
935 /* Set a software (trap) breakpoint at the LMA. */
936 bpt
->overlay_target_info
= bpt
->target_info
;
937 bpt
->overlay_target_info
.placed_address
= addr
;
938 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
940 fprintf_unfiltered (tmp_error_stream
,
941 "Overlay breakpoint %d failed: in ROM?",
945 /* Shall we set a breakpoint at the VMA? */
946 if (section_is_mapped (bpt
->section
))
948 /* Yes. This overlay section is mapped into memory. */
949 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
950 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
952 val
= target_insert_breakpoint (&bpt
->target_info
);
956 /* No. This breakpoint will not be inserted.
957 No error, but do not mark the bp as 'inserted'. */
964 /* Can't set the breakpoint. */
965 if (solib_address (bpt
->address
))
967 /* See also: disable_breakpoints_in_shlibs. */
969 bpt
->owner
->enable_state
= bp_shlib_disabled
;
970 if (!*disabled_breaks
)
972 fprintf_unfiltered (tmp_error_stream
,
973 "Cannot insert breakpoint %d.\n",
975 fprintf_unfiltered (tmp_error_stream
,
976 "Temporarily disabling shared library breakpoints:\n");
978 *disabled_breaks
= 1;
979 fprintf_unfiltered (tmp_error_stream
,
980 "breakpoint #%d\n", bpt
->owner
->number
);
984 #ifdef ONE_PROCESS_WRITETEXT
985 *process_warning
= 1;
987 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
989 *hw_breakpoint_error
= 1;
990 fprintf_unfiltered (tmp_error_stream
,
991 "Cannot insert hardware breakpoint %d.\n",
996 fprintf_unfiltered (tmp_error_stream
,
997 "Cannot insert breakpoint %d.\n",
999 fprintf_filtered (tmp_error_stream
,
1000 "Error accessing memory address ");
1001 deprecated_print_address_numeric (bpt
->address
, 1, tmp_error_stream
);
1002 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1003 safe_strerror (val
));
1014 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1015 /* NOTE drow/2003-09-08: This state only exists for removing
1016 watchpoints. It's not clear that it's necessary... */
1017 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1019 /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints
1020 based on the expression. Ideally this should happen at a higher level,
1021 and there should be one bp_location for each computed address we
1022 must watch. As soon as a many-to-one mapping is available I'll
1025 int within_current_scope
;
1026 struct value
*mark
= value_mark ();
1028 struct frame_id saved_frame_id
;
1030 /* Save the current frame's ID so we can restore it after
1031 evaluating the watchpoint expression on its own frame. */
1032 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1033 took a frame parameter, so that we didn't have to change the
1035 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1037 /* Determine if the watchpoint is within scope. */
1038 if (bpt
->owner
->exp_valid_block
== NULL
)
1039 within_current_scope
= 1;
1042 struct frame_info
*fi
;
1043 fi
= frame_find_by_id (bpt
->owner
->watchpoint_frame
);
1044 within_current_scope
= (fi
!= NULL
);
1045 if (within_current_scope
)
1049 if (within_current_scope
)
1051 free_valchain (bpt
);
1053 /* Evaluate the expression and cut the chain of values
1054 produced off from the value chain.
1056 Make sure the value returned isn't lazy; we use
1057 laziness to determine what memory GDB actually needed
1058 in order to compute the value of the expression. */
1059 v
= evaluate_expression (bpt
->owner
->exp
);
1061 value_release_to_mark (mark
);
1063 bpt
->owner
->val_chain
= v
;
1066 /* Look at each value on the value chain. */
1067 for (; v
; v
= value_next (v
))
1069 /* If it's a memory location, and GDB actually needed
1070 its contents to evaluate the expression, then we
1072 if (VALUE_LVAL (v
) == lval_memory
1073 && ! value_lazy (v
))
1075 struct type
*vtype
= check_typedef (value_type (v
));
1077 /* We only watch structs and arrays if user asked
1078 for it explicitly, never if they just happen to
1079 appear in the middle of some value chain. */
1080 if (v
== bpt
->owner
->val_chain
1081 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1082 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1087 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
1088 len
= TYPE_LENGTH (value_type (v
));
1090 if (bpt
->owner
->type
== bp_read_watchpoint
)
1092 else if (bpt
->owner
->type
== bp_access_watchpoint
)
1095 val
= target_insert_watchpoint (addr
, len
, type
);
1098 /* Don't exit the loop, try to insert
1099 every value on the value chain. That's
1100 because we will be removing all the
1101 watches below, and removing a
1102 watchpoint we didn't insert could have
1110 /* Failure to insert a watchpoint on any memory value in the
1111 value chain brings us here. */
1114 remove_breakpoint (bpt
, mark_uninserted
);
1115 *hw_breakpoint_error
= 1;
1116 fprintf_unfiltered (tmp_error_stream
,
1117 "Could not insert hardware watchpoint %d.\n",
1118 bpt
->owner
->number
);
1124 printf_filtered (_("\
1125 Hardware watchpoint %d deleted because the program has left the block \n\
1126 in which its expression is valid.\n"),
1127 bpt
->owner
->number
);
1128 if (bpt
->owner
->related_breakpoint
)
1129 bpt
->owner
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1130 bpt
->owner
->disposition
= disp_del_at_next_stop
;
1133 /* Restore the selected frame. */
1134 select_frame (frame_find_by_id (saved_frame_id
));
1139 else if (ep_is_exception_catchpoint (bpt
->owner
))
1141 /* FIXME drow/2003-09-09: This code sets both a catchpoint and a
1142 breakpoint. Once again, it would be better if this was represented
1143 as two bp_locations. */
1145 /* If we get here, we must have a callback mechanism for exception
1146 events -- with g++ style embedded label support, we insert
1147 ordinary breakpoints and not catchpoints. */
1148 val
= target_insert_breakpoint (&bpt
->target_info
);
1151 /* Couldn't set breakpoint for some reason */
1152 fprintf_unfiltered (tmp_error_stream
,
1153 "Cannot insert catchpoint %d; disabling it.\n",
1154 bpt
->owner
->number
);
1155 fprintf_filtered (tmp_error_stream
,
1156 "Error accessing memory address ");
1157 deprecated_print_address_numeric (bpt
->address
, 1, tmp_error_stream
);
1158 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1159 safe_strerror (val
));
1160 bpt
->owner
->enable_state
= bp_disabled
;
1164 /* Bp set, now make sure callbacks are enabled */
1165 /* Format possible error msg */
1166 char *message
= xstrprintf ("Error inserting catchpoint %d:\n",
1167 bpt
->owner
->number
);
1168 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
1170 args_for_catchpoint_enable args
;
1171 args
.kind
= bpt
->owner
->type
== bp_catch_catch
?
1172 EX_EVENT_CATCH
: EX_EVENT_THROW
;
1174 val
= catch_errors (cover_target_enable_exception_callback
,
1175 &args
, message
, RETURN_MASK_ALL
);
1176 do_cleanups (cleanups
);
1177 if (val
!= 0 && val
!= -1)
1180 /* Check if something went wrong; val == 0 can be ignored */
1183 /* something went wrong */
1184 fprintf_unfiltered (tmp_error_stream
,
1185 "Cannot insert catchpoint %d; disabling it.\n",
1186 bpt
->owner
->number
);
1187 bpt
->owner
->enable_state
= bp_disabled
;
1194 else if (bpt
->owner
->type
== bp_catch_fork
1195 || bpt
->owner
->type
== bp_catch_vfork
1196 || bpt
->owner
->type
== bp_catch_exec
)
1198 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1199 bpt
->owner
, RETURN_MASK_ERROR
);
1200 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1201 bpt
->owner
->number
);
1203 bpt
->owner
->enable_state
= bp_disabled
;
1207 /* We've already printed an error message if there was a problem
1208 inserting this catchpoint, and we've disabled the catchpoint,
1209 so just return success. */
1216 /* insert_breakpoints is used when starting or continuing the program.
1217 remove_breakpoints is used when the program stops.
1218 Both return zero if successful,
1219 or an `errno' value if could not write the inferior. */
1222 insert_breakpoints (void)
1224 struct bp_location
*b
, *temp
;
1225 int return_val
= 0; /* return success code. */
1227 int disabled_breaks
= 0;
1228 int hw_breakpoint_error
= 0;
1229 int process_warning
= 0;
1231 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1232 make_cleanup_ui_file_delete (tmp_error_stream
);
1234 /* Explicitly mark the warning -- this will only be printed if
1235 there was an error. */
1236 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1238 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1240 /* Permanent breakpoints cannot be inserted or removed. Disabled
1241 breakpoints should not be inserted. */
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 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 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 struct bp_location
*bpt
;
1801 int any_breakpoint_here
= 0;
1803 ALL_BP_LOCATIONS (bpt
)
1805 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1808 if ((breakpoint_enabled (bpt
->owner
)
1809 || bpt
->owner
->enable_state
== bp_permanent
)
1811 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1813 if (overlay_debugging
1814 && section_is_overlay (bpt
->section
)
1815 && !section_is_mapped (bpt
->section
))
1816 continue; /* unmapped overlay -- can't be a match */
1822 /* Also check for software single-step breakpoints. */
1823 if (single_step_breakpoint_inserted_here_p (pc
))
1829 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1830 PC is valid for process/thread PTID. */
1833 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1835 struct bp_location
*bpt
;
1838 thread
= pid_to_thread_id (ptid
);
1840 ALL_BP_LOCATIONS (bpt
)
1842 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1843 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1846 if ((breakpoint_enabled (bpt
->owner
)
1847 || bpt
->owner
->enable_state
== bp_permanent
)
1848 && bpt
->address
== pc
1849 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1851 if (overlay_debugging
1852 && section_is_overlay (bpt
->section
)
1853 && !section_is_mapped (bpt
->section
))
1854 continue; /* unmapped overlay -- can't be a match */
1864 /* bpstat stuff. External routines' interfaces are documented
1868 ep_is_catchpoint (struct breakpoint
*ep
)
1871 (ep
->type
== bp_catch_load
)
1872 || (ep
->type
== bp_catch_unload
)
1873 || (ep
->type
== bp_catch_fork
)
1874 || (ep
->type
== bp_catch_vfork
)
1875 || (ep
->type
== bp_catch_exec
)
1876 || (ep
->type
== bp_catch_catch
)
1877 || (ep
->type
== bp_catch_throw
);
1879 /* ??rehrauer: Add more kinds here, as are implemented... */
1883 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1886 (ep
->type
== bp_catch_load
)
1887 || (ep
->type
== bp_catch_unload
);
1891 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1894 (ep
->type
== bp_catch_catch
)
1895 || (ep
->type
== bp_catch_throw
);
1899 bpstat_free (bpstat bs
)
1901 if (bs
->old_val
!= NULL
)
1902 value_free (bs
->old_val
);
1903 free_command_lines (&bs
->commands
);
1907 /* Clear a bpstat so that it says we are not at any breakpoint.
1908 Also free any storage that is part of a bpstat. */
1911 bpstat_clear (bpstat
*bsp
)
1928 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1929 is part of the bpstat is copied as well. */
1932 bpstat_copy (bpstat bs
)
1936 bpstat retval
= NULL
;
1941 for (; bs
!= NULL
; bs
= bs
->next
)
1943 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1944 memcpy (tmp
, bs
, sizeof (*tmp
));
1945 if (bs
->commands
!= NULL
)
1946 tmp
->commands
= copy_command_lines (bs
->commands
);
1947 if (bs
->old_val
!= NULL
)
1948 tmp
->old_val
= value_copy (bs
->old_val
);
1951 /* This is the first thing in the chain. */
1961 /* Find the bpstat associated with this breakpoint */
1964 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1969 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1971 if (bsp
->breakpoint_at
== breakpoint
)
1977 /* Find a step_resume breakpoint associated with this bpstat.
1978 (If there are multiple step_resume bp's on the list, this function
1979 will arbitrarily pick one.)
1981 It is an error to use this function if BPSTAT doesn't contain a
1982 step_resume breakpoint.
1984 See wait_for_inferior's use of this function. */
1986 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1990 gdb_assert (bsp
!= NULL
);
1992 current_thread
= pid_to_thread_id (inferior_ptid
);
1994 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1996 if ((bsp
->breakpoint_at
!= NULL
) &&
1997 (bsp
->breakpoint_at
->type
== bp_step_resume
) &&
1998 (bsp
->breakpoint_at
->thread
== current_thread
||
1999 bsp
->breakpoint_at
->thread
== -1))
2000 return bsp
->breakpoint_at
;
2003 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2007 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2008 at. *BSP upon return is a bpstat which points to the remaining
2009 breakpoints stopped at (but which is not guaranteed to be good for
2010 anything but further calls to bpstat_num).
2011 Return 0 if passed a bpstat which does not indicate any breakpoints.
2012 Return -1 if stopped at a breakpoint that has been deleted since
2014 Return 1 otherwise. */
2017 bpstat_num (bpstat
*bsp
, int *num
)
2019 struct breakpoint
*b
;
2022 return 0; /* No more breakpoint values */
2024 b
= (*bsp
)->breakpoint_at
;
2025 *bsp
= (*bsp
)->next
;
2027 return -1; /* breakpoint that's been deleted since */
2029 *num
= b
->number
; /* We have its number */
2033 /* Modify BS so that the actions will not be performed. */
2036 bpstat_clear_actions (bpstat bs
)
2038 for (; bs
!= NULL
; bs
= bs
->next
)
2040 free_command_lines (&bs
->commands
);
2041 if (bs
->old_val
!= NULL
)
2043 value_free (bs
->old_val
);
2049 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2051 cleanup_executing_breakpoints (void *ignore
)
2053 executing_breakpoint_commands
= 0;
2056 /* Execute all the commands associated with all the breakpoints at this
2057 location. Any of these commands could cause the process to proceed
2058 beyond this point, etc. We look out for such changes by checking
2059 the global "breakpoint_proceeded" after each command. */
2062 bpstat_do_actions (bpstat
*bsp
)
2065 struct cleanup
*old_chain
;
2067 /* Avoid endless recursion if a `source' command is contained
2069 if (executing_breakpoint_commands
)
2072 executing_breakpoint_commands
= 1;
2073 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2076 /* Note that (as of this writing), our callers all appear to
2077 be passing us the address of global stop_bpstat. And, if
2078 our calls to execute_control_command cause the inferior to
2079 proceed, that global (and hence, *bsp) will change.
2081 We must be careful to not touch *bsp unless the inferior
2082 has not proceeded. */
2084 /* This pointer will iterate over the list of bpstat's. */
2087 breakpoint_proceeded
= 0;
2088 for (; bs
!= NULL
; bs
= bs
->next
)
2090 struct command_line
*cmd
;
2091 struct cleanup
*this_cmd_tree_chain
;
2093 /* Take ownership of the BSP's command tree, if it has one.
2095 The command tree could legitimately contain commands like
2096 'step' and 'next', which call clear_proceed_status, which
2097 frees stop_bpstat's command tree. To make sure this doesn't
2098 free the tree we're executing out from under us, we need to
2099 take ownership of the tree ourselves. Since a given bpstat's
2100 commands are only executed once, we don't need to copy it; we
2101 can clear the pointer in the bpstat, and make sure we free
2102 the tree when we're done. */
2105 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2109 execute_control_command (cmd
);
2111 if (breakpoint_proceeded
)
2117 /* We can free this command tree now. */
2118 do_cleanups (this_cmd_tree_chain
);
2120 if (breakpoint_proceeded
)
2121 /* The inferior is proceeded by the command; bomb out now.
2122 The bpstat chain has been blown away by wait_for_inferior.
2123 But since execution has stopped again, there is a new bpstat
2124 to look at, so start over. */
2127 do_cleanups (old_chain
);
2130 /* This is the normal print function for a bpstat. In the future,
2131 much of this logic could (should?) be moved to bpstat_stop_status,
2132 by having it set different print_it values.
2134 Current scheme: When we stop, bpstat_print() is called. It loops
2135 through the bpstat list of things causing this stop, calling the
2136 print_bp_stop_message function on each one. The behavior of the
2137 print_bp_stop_message function depends on the print_it field of
2138 bpstat. If such field so indicates, call this function here.
2140 Return values from this routine (ultimately used by bpstat_print()
2141 and normal_stop() to decide what to do):
2142 PRINT_NOTHING: Means we already printed all we needed to print,
2143 don't print anything else.
2144 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2145 that something to be followed by a location.
2146 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2147 that something to be followed by a location.
2148 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2151 static enum print_stop_action
2152 print_it_typical (bpstat bs
)
2154 struct cleanup
*old_chain
, *ui_out_chain
;
2155 struct ui_stream
*stb
;
2156 stb
= ui_out_stream_new (uiout
);
2157 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2158 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2159 which has since been deleted. */
2160 if (bs
->breakpoint_at
== NULL
)
2161 return PRINT_UNKNOWN
;
2163 switch (bs
->breakpoint_at
->type
)
2166 case bp_hardware_breakpoint
:
2167 if (bs
->breakpoint_at
->loc
->address
!= bs
->breakpoint_at
->loc
->requested_address
)
2168 breakpoint_adjustment_warning (bs
->breakpoint_at
->loc
->requested_address
,
2169 bs
->breakpoint_at
->loc
->address
,
2170 bs
->breakpoint_at
->number
, 1);
2171 annotate_breakpoint (bs
->breakpoint_at
->number
);
2172 ui_out_text (uiout
, "\nBreakpoint ");
2173 if (ui_out_is_mi_like_p (uiout
))
2174 ui_out_field_string (uiout
, "reason",
2175 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2176 ui_out_field_int (uiout
, "bkptno", bs
->breakpoint_at
->number
);
2177 ui_out_text (uiout
, ", ");
2178 return PRINT_SRC_AND_LOC
;
2181 case bp_shlib_event
:
2182 /* Did we stop because the user set the stop_on_solib_events
2183 variable? (If so, we report this as a generic, "Stopped due
2184 to shlib event" message.) */
2185 printf_filtered (_("Stopped due to shared library event\n"));
2186 return PRINT_NOTHING
;
2189 case bp_thread_event
:
2190 /* Not sure how we will get here.
2191 GDB should not stop for these breakpoints. */
2192 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2193 return PRINT_NOTHING
;
2196 case bp_overlay_event
:
2197 /* By analogy with the thread event, GDB should not stop for these. */
2198 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2199 return PRINT_NOTHING
;
2203 annotate_catchpoint (bs
->breakpoint_at
->number
);
2204 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2205 bs
->breakpoint_at
->number
,
2206 bs
->breakpoint_at
->triggered_dll_pathname
);
2207 return PRINT_SRC_AND_LOC
;
2210 case bp_catch_unload
:
2211 annotate_catchpoint (bs
->breakpoint_at
->number
);
2212 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2213 bs
->breakpoint_at
->number
,
2214 bs
->breakpoint_at
->triggered_dll_pathname
);
2215 return PRINT_SRC_AND_LOC
;
2219 annotate_catchpoint (bs
->breakpoint_at
->number
);
2220 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2221 bs
->breakpoint_at
->number
,
2222 bs
->breakpoint_at
->forked_inferior_pid
);
2223 return PRINT_SRC_AND_LOC
;
2226 case bp_catch_vfork
:
2227 annotate_catchpoint (bs
->breakpoint_at
->number
);
2228 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2229 bs
->breakpoint_at
->number
,
2230 bs
->breakpoint_at
->forked_inferior_pid
);
2231 return PRINT_SRC_AND_LOC
;
2235 annotate_catchpoint (bs
->breakpoint_at
->number
);
2236 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2237 bs
->breakpoint_at
->number
,
2238 bs
->breakpoint_at
->exec_pathname
);
2239 return PRINT_SRC_AND_LOC
;
2242 case bp_catch_catch
:
2243 if (current_exception_event
&&
2244 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2246 annotate_catchpoint (bs
->breakpoint_at
->number
);
2247 printf_filtered (_("\nCatchpoint %d (exception caught), "),
2248 bs
->breakpoint_at
->number
);
2249 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2250 printf_filtered (_("throw location %s:%d, "),
2251 CURRENT_EXCEPTION_THROW_FILE
,
2252 CURRENT_EXCEPTION_THROW_LINE
);
2254 printf_filtered (_("throw location unknown, "));
2256 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2257 printf_filtered (_("catch location %s:%d\n"),
2258 CURRENT_EXCEPTION_CATCH_FILE
,
2259 CURRENT_EXCEPTION_CATCH_LINE
);
2261 printf_filtered (_("catch location unknown\n"));
2263 /* don't bother to print location frame info */
2264 return PRINT_SRC_ONLY
;
2268 /* really throw, some other bpstat will handle it */
2269 return PRINT_UNKNOWN
;
2273 case bp_catch_throw
:
2274 if (current_exception_event
&&
2275 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2277 annotate_catchpoint (bs
->breakpoint_at
->number
);
2278 printf_filtered (_("\nCatchpoint %d (exception thrown), "),
2279 bs
->breakpoint_at
->number
);
2280 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2281 printf_filtered (_("throw location %s:%d, "),
2282 CURRENT_EXCEPTION_THROW_FILE
,
2283 CURRENT_EXCEPTION_THROW_LINE
);
2285 printf_filtered (_("throw location unknown, "));
2287 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2288 printf_filtered (_("catch location %s:%d\n"),
2289 CURRENT_EXCEPTION_CATCH_FILE
,
2290 CURRENT_EXCEPTION_CATCH_LINE
);
2292 printf_filtered (_("catch location unknown\n"));
2294 /* don't bother to print location frame info */
2295 return PRINT_SRC_ONLY
;
2299 /* really catch, some other bpstat will handle it */
2300 return PRINT_UNKNOWN
;
2305 case bp_hardware_watchpoint
:
2306 if (bs
->old_val
!= NULL
)
2308 annotate_watchpoint (bs
->breakpoint_at
->number
);
2309 if (ui_out_is_mi_like_p (uiout
))
2312 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2313 mention (bs
->breakpoint_at
);
2314 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2315 ui_out_text (uiout
, "\nOld value = ");
2316 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2317 ui_out_field_stream (uiout
, "old", stb
);
2318 ui_out_text (uiout
, "\nNew value = ");
2319 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2320 ui_out_field_stream (uiout
, "new", stb
);
2321 do_cleanups (ui_out_chain
);
2322 ui_out_text (uiout
, "\n");
2323 value_free (bs
->old_val
);
2326 /* More than one watchpoint may have been triggered. */
2327 return PRINT_UNKNOWN
;
2330 case bp_read_watchpoint
:
2331 if (ui_out_is_mi_like_p (uiout
))
2334 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2335 mention (bs
->breakpoint_at
);
2336 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2337 ui_out_text (uiout
, "\nValue = ");
2338 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2339 ui_out_field_stream (uiout
, "value", stb
);
2340 do_cleanups (ui_out_chain
);
2341 ui_out_text (uiout
, "\n");
2342 return PRINT_UNKNOWN
;
2345 case bp_access_watchpoint
:
2346 if (bs
->old_val
!= NULL
)
2348 annotate_watchpoint (bs
->breakpoint_at
->number
);
2349 if (ui_out_is_mi_like_p (uiout
))
2352 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2353 mention (bs
->breakpoint_at
);
2354 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2355 ui_out_text (uiout
, "\nOld value = ");
2356 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2357 ui_out_field_stream (uiout
, "old", stb
);
2358 value_free (bs
->old_val
);
2360 ui_out_text (uiout
, "\nNew value = ");
2364 mention (bs
->breakpoint_at
);
2365 if (ui_out_is_mi_like_p (uiout
))
2368 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2369 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2370 ui_out_text (uiout
, "\nValue = ");
2372 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0,Val_pretty_default
);
2373 ui_out_field_stream (uiout
, "new", stb
);
2374 do_cleanups (ui_out_chain
);
2375 ui_out_text (uiout
, "\n");
2376 return PRINT_UNKNOWN
;
2379 /* Fall through, we don't deal with these types of breakpoints
2383 if (ui_out_is_mi_like_p (uiout
))
2386 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2387 return PRINT_UNKNOWN
;
2391 if (ui_out_is_mi_like_p (uiout
))
2394 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2395 return PRINT_UNKNOWN
;
2400 case bp_longjmp_resume
:
2401 case bp_step_resume
:
2402 case bp_watchpoint_scope
:
2405 return PRINT_UNKNOWN
;
2409 /* Generic routine for printing messages indicating why we
2410 stopped. The behavior of this function depends on the value
2411 'print_it' in the bpstat structure. Under some circumstances we
2412 may decide not to print anything here and delegate the task to
2415 static enum print_stop_action
2416 print_bp_stop_message (bpstat bs
)
2418 switch (bs
->print_it
)
2421 /* Nothing should be printed for this bpstat entry. */
2422 return PRINT_UNKNOWN
;
2426 /* We still want to print the frame, but we already printed the
2427 relevant messages. */
2428 return PRINT_SRC_AND_LOC
;
2431 case print_it_normal
:
2432 /* Normal case. Call the breakpoint's print_it method, or
2433 print_it_typical. */
2434 if (bs
->breakpoint_at
!= NULL
&& bs
->breakpoint_at
->ops
!= NULL
2435 && bs
->breakpoint_at
->ops
->print_it
!= NULL
)
2436 return bs
->breakpoint_at
->ops
->print_it (bs
->breakpoint_at
);
2438 return print_it_typical (bs
);
2442 internal_error (__FILE__
, __LINE__
,
2443 _("print_bp_stop_message: unrecognized enum value"));
2448 /* Print a message indicating what happened. This is called from
2449 normal_stop(). The input to this routine is the head of the bpstat
2450 list - a list of the eventpoints that caused this stop. This
2451 routine calls the generic print routine for printing a message
2452 about reasons for stopping. This will print (for example) the
2453 "Breakpoint n," part of the output. The return value of this
2456 PRINT_UNKNOWN: Means we printed nothing
2457 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2458 code to print the location. An example is
2459 "Breakpoint 1, " which should be followed by
2461 PRINT_SRC_ONLY: Means we printed something, but there is no need
2462 to also print the location part of the message.
2463 An example is the catch/throw messages, which
2464 don't require a location appended to the end.
2465 PRINT_NOTHING: We have done some printing and we don't need any
2466 further info to be printed.*/
2468 enum print_stop_action
2469 bpstat_print (bpstat bs
)
2473 /* Maybe another breakpoint in the chain caused us to stop.
2474 (Currently all watchpoints go on the bpstat whether hit or not.
2475 That probably could (should) be changed, provided care is taken
2476 with respect to bpstat_explains_signal). */
2477 for (; bs
; bs
= bs
->next
)
2479 val
= print_bp_stop_message (bs
);
2480 if (val
== PRINT_SRC_ONLY
2481 || val
== PRINT_SRC_AND_LOC
2482 || val
== PRINT_NOTHING
)
2486 /* We reached the end of the chain, or we got a null BS to start
2487 with and nothing was printed. */
2488 return PRINT_UNKNOWN
;
2491 /* Evaluate the expression EXP and return 1 if value is zero.
2492 This is used inside a catch_errors to evaluate the breakpoint condition.
2493 The argument is a "struct expression *" that has been cast to char * to
2494 make it pass through catch_errors. */
2497 breakpoint_cond_eval (void *exp
)
2499 struct value
*mark
= value_mark ();
2500 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2501 value_free_to_mark (mark
);
2505 /* Allocate a new bpstat and chain it to the current one. */
2508 bpstat_alloc (struct breakpoint
*b
, bpstat cbs
/* Current "bs" value */ )
2512 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2514 bs
->breakpoint_at
= b
;
2515 /* If the condition is false, etc., don't do the commands. */
2516 bs
->commands
= NULL
;
2518 bs
->print_it
= print_it_normal
;
2522 /* Possible return values for watchpoint_check (this can't be an enum
2523 because of check_errors). */
2524 /* The watchpoint has been deleted. */
2525 #define WP_DELETED 1
2526 /* The value has changed. */
2527 #define WP_VALUE_CHANGED 2
2528 /* The value has not changed. */
2529 #define WP_VALUE_NOT_CHANGED 3
2531 #define BP_TEMPFLAG 1
2532 #define BP_HARDWAREFLAG 2
2534 /* Check watchpoint condition. */
2537 watchpoint_check (void *p
)
2539 bpstat bs
= (bpstat
) p
;
2540 struct breakpoint
*b
;
2541 struct frame_info
*fr
;
2542 int within_current_scope
;
2544 b
= bs
->breakpoint_at
;
2546 if (b
->exp_valid_block
== NULL
)
2547 within_current_scope
= 1;
2550 /* There is no current frame at this moment. If we're going to have
2551 any chance of handling watchpoints on local variables, we'll need
2552 the frame chain (so we can determine if we're in scope). */
2553 reinit_frame_cache ();
2554 fr
= frame_find_by_id (b
->watchpoint_frame
);
2555 within_current_scope
= (fr
!= NULL
);
2557 /* If we've gotten confused in the unwinder, we might have
2558 returned a frame that can't describe this variable. */
2559 if (within_current_scope
2560 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2561 within_current_scope
= 0;
2563 /* in_function_epilogue_p() returns a non-zero value if we're still
2564 in the function but the stack frame has already been invalidated.
2565 Since we can't rely on the values of local variables after the
2566 stack has been destroyed, we are treating the watchpoint in that
2567 state as `not changed' without further checking.
2569 vinschen/2003-09-04: The former implementation left out the case
2570 that the watchpoint frame couldn't be found by frame_find_by_id()
2571 because the current PC is currently in an epilogue. Calling
2572 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2573 if ((!within_current_scope
|| fr
== get_current_frame ())
2574 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2575 return WP_VALUE_NOT_CHANGED
;
2576 if (fr
&& within_current_scope
)
2577 /* If we end up stopping, the current frame will get selected
2578 in normal_stop. So this call to select_frame won't affect
2583 if (within_current_scope
)
2585 /* We use value_{,free_to_}mark because it could be a
2586 *long* time before we return to the command level and
2587 call free_all_values. We can't call free_all_values because
2588 we might be in the middle of evaluating a function call. */
2590 struct value
*mark
= value_mark ();
2591 struct value
*new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
2592 if (!value_equal (b
->val
, new_val
))
2594 release_value (new_val
);
2595 value_free_to_mark (mark
);
2596 bs
->old_val
= b
->val
;
2598 /* We will stop here */
2599 return WP_VALUE_CHANGED
;
2603 /* Nothing changed, don't do anything. */
2604 value_free_to_mark (mark
);
2605 /* We won't stop here */
2606 return WP_VALUE_NOT_CHANGED
;
2611 /* This seems like the only logical thing to do because
2612 if we temporarily ignored the watchpoint, then when
2613 we reenter the block in which it is valid it contains
2614 garbage (in the case of a function, it may have two
2615 garbage values, one before and one after the prologue).
2616 So we can't even detect the first assignment to it and
2617 watch after that (since the garbage may or may not equal
2618 the first value assigned). */
2619 /* We print all the stop information in print_it_typical(), but
2620 in this case, by the time we call print_it_typical() this bp
2621 will be deleted already. So we have no choice but print the
2622 information here. */
2623 if (ui_out_is_mi_like_p (uiout
))
2625 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2626 ui_out_text (uiout
, "\nWatchpoint ");
2627 ui_out_field_int (uiout
, "wpnum", bs
->breakpoint_at
->number
);
2628 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2629 which its expression is valid.\n");
2631 if (b
->related_breakpoint
)
2632 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2633 b
->disposition
= disp_del_at_next_stop
;
2639 /* Get a bpstat associated with having just stopped at address
2640 BP_ADDR in thread PTID. STOPPED_BY_WATCHPOINT is 1 if the
2641 target thinks we stopped due to a hardware watchpoint, 0 if we
2642 know we did not trigger a hardware watchpoint, and -1 if we do not know. */
2644 /* Determine whether we stopped at a breakpoint, etc, or whether we
2645 don't understand this stop. Result is a chain of bpstat's such that:
2647 if we don't understand the stop, the result is a null pointer.
2649 if we understand why we stopped, the result is not null.
2651 Each element of the chain refers to a particular breakpoint or
2652 watchpoint at which we have stopped. (We may have stopped for
2653 several reasons concurrently.)
2655 Each element of the chain has valid next, breakpoint_at,
2656 commands, FIXME??? fields. */
2659 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
, int stopped_by_watchpoint
)
2661 struct breakpoint
*b
, *temp
;
2662 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2663 int real_breakpoint
= 0;
2664 /* Root of the chain of bpstat's */
2665 struct bpstats root_bs
[1];
2666 /* Pointer to the last thing in the chain currently. */
2667 bpstat bs
= root_bs
;
2668 int thread_id
= pid_to_thread_id (ptid
);
2670 ALL_BREAKPOINTS_SAFE (b
, temp
)
2672 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2675 if (b
->type
!= bp_watchpoint
2676 && b
->type
!= bp_hardware_watchpoint
2677 && b
->type
!= bp_read_watchpoint
2678 && b
->type
!= bp_access_watchpoint
2679 && b
->type
!= bp_hardware_breakpoint
2680 && b
->type
!= bp_catch_fork
2681 && b
->type
!= bp_catch_vfork
2682 && b
->type
!= bp_catch_exec
2683 && b
->type
!= bp_catch_catch
2684 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2686 if (b
->loc
->address
!= bp_addr
) /* address doesn't match */
2688 if (overlay_debugging
/* unmapped overlay section */
2689 && section_is_overlay (b
->loc
->section
)
2690 && !section_is_mapped (b
->loc
->section
))
2694 /* Continuable hardware watchpoints are treated as non-existent if the
2695 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2696 some data address). Otherwise gdb won't stop on a break instruction
2697 in the code (not from a breakpoint) when a hardware watchpoint has
2700 if ((b
->type
== bp_hardware_watchpoint
2701 || b
->type
== bp_read_watchpoint
2702 || b
->type
== bp_access_watchpoint
)
2703 && !stopped_by_watchpoint
)
2706 if (b
->type
== bp_hardware_breakpoint
)
2708 if (b
->loc
->address
!= bp_addr
)
2710 if (overlay_debugging
/* unmapped overlay section */
2711 && section_is_overlay (b
->loc
->section
)
2712 && !section_is_mapped (b
->loc
->section
))
2716 /* Is this a catchpoint of a load or unload? If so, did we
2717 get a load or unload of the specified library? If not,
2719 if ((b
->type
== bp_catch_load
)
2720 #if defined(SOLIB_HAVE_LOAD_EVENT)
2721 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2722 || ((b
->dll_pathname
!= NULL
)
2723 && (strcmp (b
->dll_pathname
,
2724 SOLIB_LOADED_LIBRARY_PATHNAME (
2725 PIDGET (inferior_ptid
)))
2731 if ((b
->type
== bp_catch_unload
)
2732 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2733 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2734 || ((b
->dll_pathname
!= NULL
)
2735 && (strcmp (b
->dll_pathname
,
2736 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2737 PIDGET (inferior_ptid
)))
2743 if ((b
->type
== bp_catch_fork
)
2744 && !inferior_has_forked (PIDGET (inferior_ptid
),
2745 &b
->forked_inferior_pid
))
2748 if ((b
->type
== bp_catch_vfork
)
2749 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2750 &b
->forked_inferior_pid
))
2753 if ((b
->type
== bp_catch_exec
)
2754 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2757 if (ep_is_exception_catchpoint (b
) &&
2758 !(current_exception_event
= target_get_current_exception_event ()))
2761 /* Come here if it's a watchpoint, or if the break address matches */
2763 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
2765 /* Watchpoints may change this, if not found to have triggered. */
2769 if (b
->type
== bp_watchpoint
||
2770 b
->type
== bp_hardware_watchpoint
)
2772 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2774 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2775 int e
= catch_errors (watchpoint_check
, bs
, message
,
2777 do_cleanups (cleanups
);
2781 /* We've already printed what needs to be printed. */
2782 /* Actually this is superfluous, because by the time we
2783 call print_it_typical() the wp will be already deleted,
2784 and the function will return immediately. */
2785 bs
->print_it
= print_it_done
;
2788 case WP_VALUE_CHANGED
:
2792 case WP_VALUE_NOT_CHANGED
:
2794 bs
->print_it
= print_it_noop
;
2801 /* Error from catch_errors. */
2802 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2803 if (b
->related_breakpoint
)
2804 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2805 b
->disposition
= disp_del_at_next_stop
;
2806 /* We've already printed what needs to be printed. */
2807 bs
->print_it
= print_it_done
;
2813 else if (b
->type
== bp_read_watchpoint
||
2814 b
->type
== bp_access_watchpoint
)
2820 if (!target_stopped_data_address (¤t_target
, &addr
))
2822 for (v
= b
->val_chain
; v
; v
= value_next (v
))
2824 if (VALUE_LVAL (v
) == lval_memory
2825 && ! value_lazy (v
))
2827 struct type
*vtype
= check_typedef (value_type (v
));
2829 if (v
== b
->val_chain
2830 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2831 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2835 vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
2836 /* Exact match not required. Within range is
2838 if (addr
>= vaddr
&&
2839 addr
< vaddr
+ TYPE_LENGTH (value_type (v
)))
2846 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2848 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2849 int e
= catch_errors (watchpoint_check
, bs
, message
,
2851 do_cleanups (cleanups
);
2855 /* We've already printed what needs to be printed. */
2856 bs
->print_it
= print_it_done
;
2859 case WP_VALUE_CHANGED
:
2860 if (b
->type
== bp_read_watchpoint
)
2862 /* Don't stop: read watchpoints shouldn't fire if
2863 the value has changed. This is for targets
2864 which cannot set read-only watchpoints. */
2865 bs
->print_it
= print_it_noop
;
2871 case WP_VALUE_NOT_CHANGED
:
2878 /* Error from catch_errors. */
2879 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2880 if (b
->related_breakpoint
)
2881 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2882 b
->disposition
= disp_del_at_next_stop
;
2883 /* We've already printed what needs to be printed. */
2884 bs
->print_it
= print_it_done
;
2888 else /* found == 0 */
2890 /* This is a case where some watchpoint(s) triggered,
2891 but not at the address of this watchpoint (FOUND
2892 was left zero). So don't print anything for this
2894 bs
->print_it
= print_it_noop
;
2901 /* By definition, an encountered breakpoint is a triggered
2905 real_breakpoint
= 1;
2908 if (frame_id_p (b
->frame_id
)
2909 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2913 int value_is_zero
= 0;
2917 /* Need to select the frame, with all that implies
2918 so that the conditions will have the right context. */
2919 select_frame (get_current_frame ());
2921 = catch_errors (breakpoint_cond_eval
, (b
->cond
),
2922 "Error in testing breakpoint condition:\n",
2924 /* FIXME-someday, should give breakpoint # */
2927 if (b
->cond
&& value_is_zero
)
2930 /* Don't consider this a hit. */
2933 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2936 /* Don't consider this a hit. */
2939 else if (b
->ignore_count
> 0)
2942 annotate_ignore_count_change ();
2947 /* We will stop here */
2948 if (b
->disposition
== disp_disable
)
2949 b
->enable_state
= bp_disabled
;
2952 bs
->commands
= b
->commands
;
2954 (strcmp ("silent", bs
->commands
->line
) == 0
2955 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
2957 bs
->commands
= bs
->commands
->next
;
2960 bs
->commands
= copy_command_lines (bs
->commands
);
2963 /* Print nothing for this entry if we dont stop or if we dont print. */
2964 if (bs
->stop
== 0 || bs
->print
== 0)
2965 bs
->print_it
= print_it_noop
;
2968 bs
->next
= NULL
; /* Terminate the chain */
2969 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2971 /* The value of a hardware watchpoint hasn't changed, but the
2972 intermediate memory locations we are watching may have. */
2973 if (bs
&& !bs
->stop
&&
2974 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
2975 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
2976 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
2978 remove_breakpoints ();
2979 insert_breakpoints ();
2984 /* Tell what to do about this bpstat. */
2986 bpstat_what (bpstat bs
)
2988 /* Classify each bpstat as one of the following. */
2991 /* This bpstat element has no effect on the main_action. */
2994 /* There was a watchpoint, stop but don't print. */
2997 /* There was a watchpoint, stop and print. */
3000 /* There was a breakpoint but we're not stopping. */
3003 /* There was a breakpoint, stop but don't print. */
3006 /* There was a breakpoint, stop and print. */
3009 /* We hit the longjmp breakpoint. */
3012 /* We hit the longjmp_resume breakpoint. */
3015 /* We hit the step_resume breakpoint. */
3018 /* We hit the shared library event breakpoint. */
3021 /* We caught a shared library event. */
3024 /* This is just used to count how many enums there are. */
3028 /* Here is the table which drives this routine. So that we can
3029 format it pretty, we define some abbreviations for the
3030 enum bpstat_what codes. */
3031 #define kc BPSTAT_WHAT_KEEP_CHECKING
3032 #define ss BPSTAT_WHAT_STOP_SILENT
3033 #define sn BPSTAT_WHAT_STOP_NOISY
3034 #define sgl BPSTAT_WHAT_SINGLE
3035 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3036 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3037 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
3038 #define sr BPSTAT_WHAT_STEP_RESUME
3039 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3040 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3042 /* "Can't happen." Might want to print an error message.
3043 abort() is not out of the question, but chances are GDB is just
3044 a bit confused, not unusable. */
3045 #define err BPSTAT_WHAT_STOP_NOISY
3047 /* Given an old action and a class, come up with a new action. */
3048 /* One interesting property of this table is that wp_silent is the same
3049 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3050 after stopping, the check for whether to step over a breakpoint
3051 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3052 reference to how we stopped. We retain separate wp_silent and
3053 bp_silent codes in case we want to change that someday.
3055 Another possibly interesting property of this table is that
3056 there's a partial ordering, priority-like, of the actions. Once
3057 you've decided that some action is appropriate, you'll never go
3058 back and decide something of a lower priority is better. The
3061 kc < clr sgl shl shlr slr sn sr ss
3062 sgl < clrs shl shlr slr sn sr ss
3063 slr < err shl shlr sn sr ss
3064 clr < clrs err shl shlr sn sr ss
3065 clrs < err shl shlr sn sr ss
3072 What I think this means is that we don't need a damned table
3073 here. If you just put the rows and columns in the right order,
3074 it'd look awfully regular. We could simply walk the bpstat list
3075 and choose the highest priority action we find, with a little
3076 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3077 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3078 is messy anyway). */
3080 /* step_resume entries: a step resume breakpoint overrides another
3081 breakpoint of signal handling (see comment in wait_for_inferior
3082 at where we set the step_resume breakpoint). */
3084 static const enum bpstat_what_main_action
3085 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3088 /* kc ss sn sgl slr clr clrs sr shl shlr
3091 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, shl
, shlr
},
3093 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3095 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3097 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, shl
, shlr
},
3099 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3101 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3103 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, shl
, shlr
},
3105 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, shl
, shlr
},
3107 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3109 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3111 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3126 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3127 struct bpstat_what retval
;
3129 retval
.call_dummy
= 0;
3130 for (; bs
!= NULL
; bs
= bs
->next
)
3132 enum class bs_class
= no_effect
;
3133 if (bs
->breakpoint_at
== NULL
)
3134 /* I suspect this can happen if it was a momentary breakpoint
3135 which has since been deleted. */
3137 switch (bs
->breakpoint_at
->type
)
3143 case bp_hardware_breakpoint
:
3149 bs_class
= bp_noisy
;
3151 bs_class
= bp_silent
;
3154 bs_class
= bp_nostop
;
3157 case bp_hardware_watchpoint
:
3158 case bp_read_watchpoint
:
3159 case bp_access_watchpoint
:
3163 bs_class
= wp_noisy
;
3165 bs_class
= wp_silent
;
3168 /* There was a watchpoint, but we're not stopping.
3169 This requires no further action. */
3170 bs_class
= no_effect
;
3173 bs_class
= long_jump
;
3175 case bp_longjmp_resume
:
3176 bs_class
= long_resume
;
3178 case bp_step_resume
:
3181 bs_class
= step_resume
;
3184 /* It is for the wrong frame. */
3185 bs_class
= bp_nostop
;
3187 case bp_watchpoint_scope
:
3188 bs_class
= bp_nostop
;
3190 case bp_shlib_event
:
3191 bs_class
= shlib_event
;
3193 case bp_thread_event
:
3194 case bp_overlay_event
:
3195 bs_class
= bp_nostop
;
3198 case bp_catch_unload
:
3199 /* Only if this catchpoint triggered should we cause the
3200 step-out-of-dld behaviour. Otherwise, we ignore this
3203 bs_class
= catch_shlib_event
;
3205 bs_class
= no_effect
;
3208 case bp_catch_vfork
:
3213 bs_class
= bp_noisy
;
3215 bs_class
= bp_silent
;
3218 /* There was a catchpoint, but we're not stopping.
3219 This requires no further action. */
3220 bs_class
= no_effect
;
3222 case bp_catch_catch
:
3223 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
3224 bs_class
= bp_nostop
;
3226 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3228 case bp_catch_throw
:
3229 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3230 bs_class
= bp_nostop
;
3232 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3235 /* Make sure the action is stop (silent or noisy),
3236 so infrun.c pops the dummy frame. */
3237 bs_class
= bp_silent
;
3238 retval
.call_dummy
= 1;
3241 current_action
= table
[(int) bs_class
][(int) current_action
];
3243 retval
.main_action
= current_action
;
3247 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3248 without hardware support). This isn't related to a specific bpstat,
3249 just to things like whether watchpoints are set. */
3252 bpstat_should_step (void)
3254 struct breakpoint
*b
;
3256 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3261 /* Nonzero if there are enabled hardware watchpoints. */
3263 bpstat_have_active_hw_watchpoints (void)
3265 struct bp_location
*bpt
;
3266 ALL_BP_LOCATIONS (bpt
)
3267 if (breakpoint_enabled (bpt
->owner
)
3269 && bpt
->loc_type
== bp_loc_hardware_watchpoint
)
3275 /* Given a bpstat that records zero or more triggered eventpoints, this
3276 function returns another bpstat which contains only the catchpoints
3277 on that first list, if any. */
3279 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3281 struct bpstats root_bs
[1];
3282 bpstat bs
= root_bs
;
3283 struct breakpoint
*ep
;
3286 bpstat_clear (cp_list
);
3287 root_bs
->next
= NULL
;
3289 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3291 /* Is this eventpoint a catchpoint? If not, ignore it. */
3292 ep
= ep_list
->breakpoint_at
;
3295 if ((ep
->type
!= bp_catch_load
) &&
3296 (ep
->type
!= bp_catch_unload
) &&
3297 (ep
->type
!= bp_catch_catch
) &&
3298 (ep
->type
!= bp_catch_throw
))
3299 /* pai: (temp) ADD fork/vfork here!! */
3302 /* Yes; add it to the list. */
3303 bs
= bpstat_alloc (ep
, bs
);
3308 #if defined(SOLIB_ADD)
3309 /* Also, for each triggered catchpoint, tag it with the name of
3310 the library that caused this trigger. (We copy the name now,
3311 because it's only guaranteed to be available NOW, when the
3312 catchpoint triggers. Clients who may wish to know the name
3313 later must get it from the catchpoint itself.) */
3314 if (ep
->triggered_dll_pathname
!= NULL
)
3315 xfree (ep
->triggered_dll_pathname
);
3316 if (ep
->type
== bp_catch_load
)
3317 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3318 PIDGET (inferior_ptid
));
3320 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3321 PIDGET (inferior_ptid
));
3323 dll_pathname
= NULL
;
3327 ep
->triggered_dll_pathname
= (char *)
3328 xmalloc (strlen (dll_pathname
) + 1);
3329 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3332 ep
->triggered_dll_pathname
= NULL
;
3338 /* Print B to gdb_stdout. */
3340 print_one_breakpoint (struct breakpoint
*b
,
3341 CORE_ADDR
*last_addr
)
3343 struct command_line
*l
;
3345 struct ep_type_description
3350 static struct ep_type_description bptypes
[] =
3352 {bp_none
, "?deleted?"},
3353 {bp_breakpoint
, "breakpoint"},
3354 {bp_hardware_breakpoint
, "hw breakpoint"},
3355 {bp_until
, "until"},
3356 {bp_finish
, "finish"},
3357 {bp_watchpoint
, "watchpoint"},
3358 {bp_hardware_watchpoint
, "hw watchpoint"},
3359 {bp_read_watchpoint
, "read watchpoint"},
3360 {bp_access_watchpoint
, "acc watchpoint"},
3361 {bp_longjmp
, "longjmp"},
3362 {bp_longjmp_resume
, "longjmp resume"},
3363 {bp_step_resume
, "step resume"},
3364 {bp_watchpoint_scope
, "watchpoint scope"},
3365 {bp_call_dummy
, "call dummy"},
3366 {bp_shlib_event
, "shlib events"},
3367 {bp_thread_event
, "thread events"},
3368 {bp_overlay_event
, "overlay events"},
3369 {bp_catch_load
, "catch load"},
3370 {bp_catch_unload
, "catch unload"},
3371 {bp_catch_fork
, "catch fork"},
3372 {bp_catch_vfork
, "catch vfork"},
3373 {bp_catch_exec
, "catch exec"},
3374 {bp_catch_catch
, "catch catch"},
3375 {bp_catch_throw
, "catch throw"}
3378 static char *bpdisps
[] =
3379 {"del", "dstp", "dis", "keep"};
3380 static char bpenables
[] = "nynny";
3381 char wrap_indent
[80];
3382 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3383 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3384 struct cleanup
*bkpt_chain
;
3387 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3391 ui_out_field_int (uiout
, "number", b
->number
);
3395 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3396 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3397 internal_error (__FILE__
, __LINE__
,
3398 _("bptypes table does not describe type #%d."),
3400 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3404 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3408 ui_out_field_fmt (uiout
, "enabled", "%c", bpenables
[(int) b
->enable_state
]);
3409 ui_out_spaces (uiout
, 2);
3412 strcpy (wrap_indent
, " ");
3415 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3416 strcat (wrap_indent
, " ");
3418 strcat (wrap_indent
, " ");
3421 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3422 b
->ops
->print_one (b
, last_addr
);
3427 internal_error (__FILE__
, __LINE__
,
3428 _("print_one_breakpoint: bp_none encountered\n"));
3432 case bp_hardware_watchpoint
:
3433 case bp_read_watchpoint
:
3434 case bp_access_watchpoint
:
3435 /* Field 4, the address, is omitted (which makes the columns
3436 not line up too nicely with the headers, but the effect
3437 is relatively readable). */
3439 ui_out_field_skip (uiout
, "addr");
3441 print_expression (b
->exp
, stb
->stream
);
3442 ui_out_field_stream (uiout
, "what", stb
);
3446 case bp_catch_unload
:
3447 /* Field 4, the address, is omitted (which makes the columns
3448 not line up too nicely with the headers, but the effect
3449 is relatively readable). */
3451 ui_out_field_skip (uiout
, "addr");
3453 if (b
->dll_pathname
== NULL
)
3455 ui_out_field_string (uiout
, "what", "<any library>");
3456 ui_out_spaces (uiout
, 1);
3460 ui_out_text (uiout
, "library \"");
3461 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3462 ui_out_text (uiout
, "\" ");
3467 case bp_catch_vfork
:
3468 /* Field 4, the address, is omitted (which makes the columns
3469 not line up too nicely with the headers, but the effect
3470 is relatively readable). */
3472 ui_out_field_skip (uiout
, "addr");
3474 if (b
->forked_inferior_pid
!= 0)
3476 ui_out_text (uiout
, "process ");
3477 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3478 ui_out_spaces (uiout
, 1);
3483 /* Field 4, the address, is omitted (which makes the columns
3484 not line up too nicely with the headers, but the effect
3485 is relatively readable). */
3487 ui_out_field_skip (uiout
, "addr");
3489 if (b
->exec_pathname
!= NULL
)
3491 ui_out_text (uiout
, "program \"");
3492 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3493 ui_out_text (uiout
, "\" ");
3497 case bp_catch_catch
:
3498 /* Field 4, the address, is omitted (which makes the columns
3499 not line up too nicely with the headers, but the effect
3500 is relatively readable). */
3502 ui_out_field_skip (uiout
, "addr");
3504 ui_out_field_string (uiout
, "what", "exception catch");
3505 ui_out_spaces (uiout
, 1);
3508 case bp_catch_throw
:
3509 /* Field 4, the address, is omitted (which makes the columns
3510 not line up too nicely with the headers, but the effect
3511 is relatively readable). */
3513 ui_out_field_skip (uiout
, "addr");
3515 ui_out_field_string (uiout
, "what", "exception throw");
3516 ui_out_spaces (uiout
, 1);
3520 case bp_hardware_breakpoint
:
3524 case bp_longjmp_resume
:
3525 case bp_step_resume
:
3526 case bp_watchpoint_scope
:
3528 case bp_shlib_event
:
3529 case bp_thread_event
:
3530 case bp_overlay_event
:
3535 ui_out_field_string (uiout
, "addr", "<PENDING>");
3537 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
3540 *last_addr
= b
->loc
->address
;
3543 sym
= find_pc_sect_function (b
->loc
->address
, b
->loc
->section
);
3546 ui_out_text (uiout
, "in ");
3547 ui_out_field_string (uiout
, "func",
3548 SYMBOL_PRINT_NAME (sym
));
3549 ui_out_wrap_hint (uiout
, wrap_indent
);
3550 ui_out_text (uiout
, " at ");
3552 ui_out_field_string (uiout
, "file", b
->source_file
);
3553 ui_out_text (uiout
, ":");
3555 if (ui_out_is_mi_like_p (uiout
))
3557 struct symtab_and_line sal
= find_pc_line (b
->loc
->address
, 0);
3558 char *fullname
= symtab_to_fullname (sal
.symtab
);
3561 ui_out_field_string (uiout
, "fullname", fullname
);
3564 ui_out_field_int (uiout
, "line", b
->line_number
);
3566 else if (b
->pending
)
3568 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3572 print_address_symbolic (b
->loc
->address
, stb
->stream
, demangle
, "");
3573 ui_out_field_stream (uiout
, "at", stb
);
3578 if (b
->thread
!= -1)
3580 /* FIXME: This seems to be redundant and lost here; see the
3581 "stop only in" line a little further down. */
3582 ui_out_text (uiout
, " thread ");
3583 ui_out_field_int (uiout
, "thread", b
->thread
);
3586 ui_out_text (uiout
, "\n");
3588 if (frame_id_p (b
->frame_id
))
3591 ui_out_text (uiout
, "\tstop only in stack frame at ");
3592 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3594 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3595 ui_out_text (uiout
, "\n");
3598 if (b
->cond
&& !ada_exception_catchpoint_p (b
))
3600 /* We do not print the condition for Ada exception catchpoints
3601 because the condition is an internal implementation detail
3602 that we do not want to expose to the user. */
3604 ui_out_text (uiout
, "\tstop only if ");
3605 print_expression (b
->cond
, stb
->stream
);
3606 ui_out_field_stream (uiout
, "cond", stb
);
3607 ui_out_text (uiout
, "\n");
3610 if (b
->pending
&& b
->cond_string
)
3613 ui_out_text (uiout
, "\tstop only if ");
3614 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3615 ui_out_text (uiout
, "\n");
3618 if (b
->thread
!= -1)
3620 /* FIXME should make an annotation for this */
3621 ui_out_text (uiout
, "\tstop only in thread ");
3622 ui_out_field_int (uiout
, "thread", b
->thread
);
3623 ui_out_text (uiout
, "\n");
3626 if (show_breakpoint_hit_counts
&& b
->hit_count
)
3628 /* FIXME should make an annotation for this */
3629 if (ep_is_catchpoint (b
))
3630 ui_out_text (uiout
, "\tcatchpoint");
3632 ui_out_text (uiout
, "\tbreakpoint");
3633 ui_out_text (uiout
, " already hit ");
3634 ui_out_field_int (uiout
, "times", b
->hit_count
);
3635 if (b
->hit_count
== 1)
3636 ui_out_text (uiout
, " time\n");
3638 ui_out_text (uiout
, " times\n");
3641 /* Output the count also if it is zero, but only if this is
3642 mi. FIXME: Should have a better test for this. */
3643 if (ui_out_is_mi_like_p (uiout
))
3644 if (show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3645 ui_out_field_int (uiout
, "times", b
->hit_count
);
3647 if (b
->ignore_count
)
3650 ui_out_text (uiout
, "\tignore next ");
3651 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3652 ui_out_text (uiout
, " hits\n");
3655 if ((l
= b
->commands
))
3657 struct cleanup
*script_chain
;
3660 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3661 print_command_lines (uiout
, l
, 4);
3662 do_cleanups (script_chain
);
3664 do_cleanups (bkpt_chain
);
3665 do_cleanups (old_chain
);
3668 struct captured_breakpoint_query_args
3674 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3676 struct captured_breakpoint_query_args
*args
= data
;
3677 struct breakpoint
*b
;
3678 CORE_ADDR dummy_addr
= 0;
3681 if (args
->bnum
== b
->number
)
3683 print_one_breakpoint (b
, &dummy_addr
);
3691 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3693 struct captured_breakpoint_query_args args
;
3695 /* For the moment we don't trust print_one_breakpoint() to not throw
3697 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3698 error_message
, RETURN_MASK_ALL
) < 0)
3704 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3705 catchpoints, et.al.). */
3708 user_settable_breakpoint (const struct breakpoint
*b
)
3710 return (b
->type
== bp_breakpoint
3711 || b
->type
== bp_catch_load
3712 || b
->type
== bp_catch_unload
3713 || b
->type
== bp_catch_fork
3714 || b
->type
== bp_catch_vfork
3715 || b
->type
== bp_catch_exec
3716 || b
->type
== bp_catch_catch
3717 || b
->type
== bp_catch_throw
3718 || b
->type
== bp_hardware_breakpoint
3719 || b
->type
== bp_watchpoint
3720 || b
->type
== bp_read_watchpoint
3721 || b
->type
== bp_access_watchpoint
3722 || b
->type
== bp_hardware_watchpoint
);
3725 /* Print information on user settable breakpoint (watchpoint, etc)
3726 number BNUM. If BNUM is -1 print all user settable breakpoints.
3727 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3730 breakpoint_1 (int bnum
, int allflag
)
3732 struct breakpoint
*b
;
3733 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3734 int nr_printable_breakpoints
;
3735 struct cleanup
*bkpttbl_chain
;
3737 /* Compute the number of rows in the table. */
3738 nr_printable_breakpoints
= 0;
3741 || bnum
== b
->number
)
3743 if (allflag
|| user_settable_breakpoint (b
))
3744 nr_printable_breakpoints
++;
3749 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3753 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3756 if (nr_printable_breakpoints
> 0)
3757 annotate_breakpoints_headers ();
3758 if (nr_printable_breakpoints
> 0)
3760 ui_out_table_header (uiout
, 3, ui_left
, "number", "Num"); /* 1 */
3761 if (nr_printable_breakpoints
> 0)
3763 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3764 if (nr_printable_breakpoints
> 0)
3766 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3767 if (nr_printable_breakpoints
> 0)
3769 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3772 if (nr_printable_breakpoints
> 0)
3774 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3775 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3777 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3779 if (nr_printable_breakpoints
> 0)
3781 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3782 ui_out_table_body (uiout
);
3783 if (nr_printable_breakpoints
> 0)
3784 annotate_breakpoints_table ();
3788 || bnum
== b
->number
)
3790 /* We only print out user settable breakpoints unless the
3792 if (allflag
|| user_settable_breakpoint (b
))
3793 print_one_breakpoint (b
, &last_addr
);
3796 do_cleanups (bkpttbl_chain
);
3798 if (nr_printable_breakpoints
== 0)
3801 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3803 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3808 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3809 that a comparison of an unsigned with -1 is always false. */
3810 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3811 set_next_address (last_addr
);
3814 /* FIXME? Should this be moved up so that it is only called when
3815 there have been breakpoints? */
3816 annotate_breakpoints_table_end ();
3820 breakpoints_info (char *bnum_exp
, int from_tty
)
3825 bnum
= parse_and_eval_long (bnum_exp
);
3827 breakpoint_1 (bnum
, 0);
3831 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3836 bnum
= parse_and_eval_long (bnum_exp
);
3838 breakpoint_1 (bnum
, 1);
3841 /* Print a message describing any breakpoints set at PC. */
3844 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
3847 struct breakpoint
*b
;
3850 if (b
->loc
->address
== pc
) /* address match / overlay match */
3851 if (!b
->pending
&& (!overlay_debugging
|| b
->loc
->section
== section
))
3856 printf_filtered (_("Note: breakpoint "));
3857 else /* if (others == ???) */
3858 printf_filtered (_("Note: breakpoints "));
3860 if (b
->loc
->address
== pc
) /* address match / overlay match */
3861 if (!b
->pending
&& (!overlay_debugging
|| b
->loc
->section
== section
))
3864 printf_filtered ("%d", b
->number
);
3865 if (b
->thread
== -1 && thread
!= -1)
3866 printf_filtered (" (all threads)");
3867 else if (b
->thread
!= -1)
3868 printf_filtered (" (thread %d)", b
->thread
);
3869 printf_filtered ("%s%s ",
3870 ((b
->enable_state
== bp_disabled
||
3871 b
->enable_state
== bp_shlib_disabled
||
3872 b
->enable_state
== bp_call_disabled
)
3874 : b
->enable_state
== bp_permanent
3878 : ((others
== 1) ? " and" : ""));
3880 printf_filtered (_("also set at pc "));
3881 deprecated_print_address_numeric (pc
, 1, gdb_stdout
);
3882 printf_filtered (".\n");
3886 /* Set the default place to put a breakpoint
3887 for the `break' command with no arguments. */
3890 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3893 default_breakpoint_valid
= valid
;
3894 default_breakpoint_address
= addr
;
3895 default_breakpoint_symtab
= symtab
;
3896 default_breakpoint_line
= line
;
3899 /* Return true iff it is meaningful to use the address member of
3900 BPT. For some breakpoint types, the address member is irrelevant
3901 and it makes no sense to attempt to compare it to other addresses
3902 (or use it for any other purpose either).
3904 More specifically, each of the following breakpoint types will always
3905 have a zero valued address and we don't want check_duplicates() to mark
3906 breakpoints of any of these types to be a duplicate of an actual
3907 breakpoint at address zero:
3910 bp_hardware_watchpoint
3912 bp_access_watchpoint
3919 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3921 enum bptype type
= bpt
->type
;
3923 return (type
!= bp_watchpoint
3924 && type
!= bp_hardware_watchpoint
3925 && type
!= bp_read_watchpoint
3926 && type
!= bp_access_watchpoint
3927 && type
!= bp_catch_exec
3928 && type
!= bp_longjmp_resume
3929 && type
!= bp_catch_fork
3930 && type
!= bp_catch_vfork
);
3933 /* Rescan breakpoints at the same address and section as BPT,
3934 marking the first one as "first" and any others as "duplicates".
3935 This is so that the bpt instruction is only inserted once.
3936 If we have a permanent breakpoint at the same place as BPT, make
3937 that one the official one, and the rest as duplicates. */
3940 check_duplicates (struct breakpoint
*bpt
)
3942 struct bp_location
*b
;
3944 struct bp_location
*perm_bp
= 0;
3945 CORE_ADDR address
= bpt
->loc
->address
;
3946 asection
*section
= bpt
->loc
->section
;
3948 if (! breakpoint_address_is_meaningful (bpt
))
3951 ALL_BP_LOCATIONS (b
)
3952 if (b
->owner
->enable_state
!= bp_disabled
3953 && b
->owner
->enable_state
!= bp_shlib_disabled
3954 && !b
->owner
->pending
3955 && b
->owner
->enable_state
!= bp_call_disabled
3956 && b
->address
== address
/* address / overlay match */
3957 && (!overlay_debugging
|| b
->section
== section
)
3958 && breakpoint_address_is_meaningful (b
->owner
))
3960 /* Have we found a permanent breakpoint? */
3961 if (b
->owner
->enable_state
== bp_permanent
)
3968 b
->duplicate
= count
> 1;
3971 /* If we found a permanent breakpoint at this address, go over the
3972 list again and declare all the other breakpoints there to be the
3976 perm_bp
->duplicate
= 0;
3978 /* Permanent breakpoint should always be inserted. */
3979 if (! perm_bp
->inserted
)
3980 internal_error (__FILE__
, __LINE__
,
3981 _("allegedly permanent breakpoint is not "
3982 "actually inserted"));
3984 ALL_BP_LOCATIONS (b
)
3987 if (b
->owner
->enable_state
!= bp_disabled
3988 && b
->owner
->enable_state
!= bp_shlib_disabled
3989 && !b
->owner
->pending
3990 && b
->owner
->enable_state
!= bp_call_disabled
3991 && b
->address
== address
/* address / overlay match */
3992 && (!overlay_debugging
|| b
->section
== section
)
3993 && breakpoint_address_is_meaningful (b
->owner
))
3996 internal_error (__FILE__
, __LINE__
,
3997 _("another breakpoint was inserted on top of "
3998 "a permanent breakpoint"));
4007 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4008 int bnum
, int have_bnum
)
4013 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4014 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4016 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4017 bnum
, astr1
, astr2
);
4019 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4022 /* Adjust a breakpoint's address to account for architectural constraints
4023 on breakpoint placement. Return the adjusted address. Note: Very
4024 few targets require this kind of adjustment. For most targets,
4025 this function is simply the identity function. */
4028 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4030 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4032 /* Very few targets need any kind of breakpoint adjustment. */
4035 else if (bptype
== bp_watchpoint
4036 || bptype
== bp_hardware_watchpoint
4037 || bptype
== bp_read_watchpoint
4038 || bptype
== bp_access_watchpoint
4039 || bptype
== bp_catch_fork
4040 || bptype
== bp_catch_vfork
4041 || bptype
== bp_catch_exec
)
4043 /* Watchpoints and the various bp_catch_* eventpoints should not
4044 have their addresses modified. */
4049 CORE_ADDR adjusted_bpaddr
;
4051 /* Some targets have architectural constraints on the placement
4052 of breakpoint instructions. Obtain the adjusted address. */
4053 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4056 /* An adjusted breakpoint address can significantly alter
4057 a user's expectations. Print a warning if an adjustment
4059 if (adjusted_bpaddr
!= bpaddr
)
4060 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4062 return adjusted_bpaddr
;
4066 /* Allocate a struct bp_location. */
4068 static struct bp_location
*
4069 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4071 struct bp_location
*loc
, *loc_p
;
4073 loc
= xmalloc (sizeof (struct bp_location
));
4074 memset (loc
, 0, sizeof (*loc
));
4084 case bp_longjmp_resume
:
4085 case bp_step_resume
:
4086 case bp_watchpoint_scope
:
4088 case bp_shlib_event
:
4089 case bp_thread_event
:
4090 case bp_overlay_event
:
4092 case bp_catch_unload
:
4093 loc
->loc_type
= bp_loc_software_breakpoint
;
4095 case bp_hardware_breakpoint
:
4096 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4098 case bp_hardware_watchpoint
:
4099 case bp_read_watchpoint
:
4100 case bp_access_watchpoint
:
4101 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4105 case bp_catch_vfork
:
4107 case bp_catch_catch
:
4108 case bp_catch_throw
:
4109 loc
->loc_type
= bp_loc_other
;
4112 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4115 /* Add this breakpoint to the end of the chain. */
4117 loc_p
= bp_location_chain
;
4119 bp_location_chain
= loc
;
4123 loc_p
= loc_p
->next
;
4130 /* set_raw_breakpoint() is a low level routine for allocating and
4131 partially initializing a breakpoint of type BPTYPE. The newly
4132 created breakpoint's address, section, source file name, and line
4133 number are provided by SAL. The newly created and partially
4134 initialized breakpoint is added to the breakpoint chain and
4135 is also returned as the value of this function.
4137 It is expected that the caller will complete the initialization of
4138 the newly created breakpoint struct as well as output any status
4139 information regarding the creation of a new breakpoint. In
4140 particular, set_raw_breakpoint() does NOT set the breakpoint
4141 number! Care should be taken to not allow an error() to occur
4142 prior to completing the initialization of the breakpoint. If this
4143 should happen, a bogus breakpoint will be left on the chain. */
4146 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4148 struct breakpoint
*b
, *b1
;
4149 CORE_ADDR adjusted_address
;
4151 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4152 memset (b
, 0, sizeof (*b
));
4154 /* Adjust the breakpoint's address prior to allocating a location.
4155 Once we call allocate_bp_location(), that mostly uninitialized
4156 location will be placed on the location chain. Adjustment of the
4157 breakpoint may cause read_memory_nobpt() to be called and we do
4158 not want its scan of the location chain to find a breakpoint and
4159 location that's only been partially initialized. */
4160 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4162 b
->loc
= allocate_bp_location (b
, bptype
);
4163 b
->loc
->requested_address
= sal
.pc
;
4164 b
->loc
->address
= adjusted_address
;
4166 if (sal
.symtab
== NULL
)
4167 b
->source_file
= NULL
;
4169 b
->source_file
= savestring (sal
.symtab
->filename
,
4170 strlen (sal
.symtab
->filename
));
4171 b
->loc
->section
= sal
.section
;
4173 b
->language
= current_language
->la_language
;
4174 b
->input_radix
= input_radix
;
4176 b
->line_number
= sal
.line
;
4177 b
->enable_state
= bp_enabled
;
4180 b
->ignore_count
= 0;
4182 b
->frame_id
= null_frame_id
;
4183 b
->dll_pathname
= NULL
;
4184 b
->triggered_dll_pathname
= NULL
;
4185 b
->forked_inferior_pid
= 0;
4186 b
->exec_pathname
= NULL
;
4190 /* Add this breakpoint to the end of the chain
4191 so that a list of breakpoints will come out in order
4192 of increasing numbers. */
4194 b1
= breakpoint_chain
;
4196 breakpoint_chain
= b
;
4204 check_duplicates (b
);
4205 breakpoints_changed ();
4211 /* Note that the breakpoint object B describes a permanent breakpoint
4212 instruction, hard-wired into the inferior's code. */
4214 make_breakpoint_permanent (struct breakpoint
*b
)
4216 b
->enable_state
= bp_permanent
;
4218 /* By definition, permanent breakpoints are already present in the code. */
4219 b
->loc
->inserted
= 1;
4222 static struct breakpoint
*
4223 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4225 static int internal_breakpoint_number
= -1;
4226 struct symtab_and_line sal
;
4227 struct breakpoint
*b
;
4229 init_sal (&sal
); /* initialize to zeroes */
4232 sal
.section
= find_pc_overlay (sal
.pc
);
4234 b
= set_raw_breakpoint (sal
, type
);
4235 b
->number
= internal_breakpoint_number
--;
4236 b
->disposition
= disp_donttouch
;
4243 create_longjmp_breakpoint (char *func_name
)
4245 struct breakpoint
*b
;
4246 struct minimal_symbol
*m
;
4248 if (func_name
== NULL
)
4249 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4252 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4255 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4258 b
->enable_state
= bp_disabled
;
4261 b
->addr_string
= xstrdup (func_name
);
4264 /* Call this routine when stepping and nexting to enable a breakpoint
4265 if we do a longjmp(). When we hit that breakpoint, call
4266 set_longjmp_resume_breakpoint() to figure out where we are going. */
4269 enable_longjmp_breakpoint (void)
4271 struct breakpoint
*b
;
4274 if (b
->type
== bp_longjmp
)
4276 b
->enable_state
= bp_enabled
;
4277 check_duplicates (b
);
4282 disable_longjmp_breakpoint (void)
4284 struct breakpoint
*b
;
4287 if (b
->type
== bp_longjmp
4288 || b
->type
== bp_longjmp_resume
)
4290 b
->enable_state
= bp_disabled
;
4291 check_duplicates (b
);
4296 create_overlay_event_breakpoint (char *func_name
)
4298 struct breakpoint
*b
;
4299 struct minimal_symbol
*m
;
4301 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4304 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4306 b
->addr_string
= xstrdup (func_name
);
4308 if (overlay_debugging
== ovly_auto
)
4310 b
->enable_state
= bp_enabled
;
4311 overlay_events_enabled
= 1;
4315 b
->enable_state
= bp_disabled
;
4316 overlay_events_enabled
= 0;
4321 enable_overlay_breakpoints (void)
4323 struct breakpoint
*b
;
4326 if (b
->type
== bp_overlay_event
)
4328 b
->enable_state
= bp_enabled
;
4329 check_duplicates (b
);
4330 overlay_events_enabled
= 1;
4335 disable_overlay_breakpoints (void)
4337 struct breakpoint
*b
;
4340 if (b
->type
== bp_overlay_event
)
4342 b
->enable_state
= bp_disabled
;
4343 check_duplicates (b
);
4344 overlay_events_enabled
= 0;
4349 create_thread_event_breakpoint (CORE_ADDR address
)
4351 struct breakpoint
*b
;
4353 b
= create_internal_breakpoint (address
, bp_thread_event
);
4355 b
->enable_state
= bp_enabled
;
4356 /* addr_string has to be used or breakpoint_re_set will delete me. */
4357 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4363 remove_thread_event_breakpoints (void)
4365 struct breakpoint
*b
, *temp
;
4367 ALL_BREAKPOINTS_SAFE (b
, temp
)
4368 if (b
->type
== bp_thread_event
)
4369 delete_breakpoint (b
);
4372 struct captured_parse_breakpoint_args
4375 struct symtabs_and_lines
*sals_p
;
4376 char ***addr_string_p
;
4380 struct lang_and_radix
4386 /* Cleanup helper routine to restore the current language and
4389 do_restore_lang_radix_cleanup (void *old
)
4391 struct lang_and_radix
*p
= old
;
4392 set_language (p
->lang
);
4393 input_radix
= p
->radix
;
4396 /* Try and resolve a pending breakpoint. */
4398 resolve_pending_breakpoint (struct breakpoint
*b
)
4400 /* Try and reparse the breakpoint in case the shared library
4402 struct symtabs_and_lines sals
;
4403 struct symtab_and_line pending_sal
;
4404 char **cond_string
= (char **) NULL
;
4405 char *copy_arg
= b
->addr_string
;
4410 struct ui_file
*old_gdb_stderr
;
4411 struct lang_and_radix old_lr
;
4412 struct cleanup
*old_chain
;
4414 /* Set language, input-radix, then reissue breakpoint command.
4415 Ensure the language and input-radix are restored afterwards. */
4416 old_lr
.lang
= current_language
->la_language
;
4417 old_lr
.radix
= input_radix
;
4418 old_chain
= make_cleanup (do_restore_lang_radix_cleanup
, &old_lr
);
4420 set_language (b
->language
);
4421 input_radix
= b
->input_radix
;
4422 rc
= break_command_1 (b
->addr_string
, b
->flag
, b
->from_tty
, b
);
4424 if (rc
== GDB_RC_OK
)
4425 /* Pending breakpoint has been resolved. */
4426 printf_filtered (_("Pending breakpoint \"%s\" resolved\n"), b
->addr_string
);
4428 do_cleanups (old_chain
);
4433 remove_solib_event_breakpoints (void)
4435 struct breakpoint
*b
, *temp
;
4437 ALL_BREAKPOINTS_SAFE (b
, temp
)
4438 if (b
->type
== bp_shlib_event
)
4439 delete_breakpoint (b
);
4443 create_solib_event_breakpoint (CORE_ADDR address
)
4445 struct breakpoint
*b
;
4447 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4451 /* Disable any breakpoints that are on code in shared libraries. Only
4452 apply to enabled breakpoints, disabled ones can just stay disabled. */
4455 disable_breakpoints_in_shlibs (void)
4457 struct breakpoint
*b
;
4458 int disabled_shlib_breaks
= 0;
4462 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4463 && breakpoint_enabled (b
) && !b
->loc
->duplicate
4465 && PC_SOLIB (b
->loc
->address
)
4467 && solib_address (b
->loc
->address
)
4470 b
->enable_state
= bp_shlib_disabled
;
4474 /* Disable any breakpoints that are in in an unloaded shared library. Only
4475 apply to enabled breakpoints, disabled ones can just stay disabled. */
4478 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4480 struct breakpoint
*b
;
4481 int disabled_shlib_breaks
= 0;
4485 if ((b
->loc
->loc_type
== bp_loc_hardware_breakpoint
4486 || b
->loc
->loc_type
== bp_loc_software_breakpoint
)
4487 && breakpoint_enabled (b
) && !b
->loc
->duplicate
)
4490 char *so_name
= PC_SOLIB (b
->loc
->address
);
4492 char *so_name
= solib_address (b
->loc
->address
);
4494 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4496 b
->enable_state
= bp_shlib_disabled
;
4497 /* At this point, we cannot rely on remove_breakpoint
4498 succeeding so we must mark the breakpoint as not inserted
4499 to prevent future errors occurring in remove_breakpoints. */
4500 b
->loc
->inserted
= 0;
4501 if (!disabled_shlib_breaks
)
4503 target_terminal_ours_for_output ();
4504 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4507 disabled_shlib_breaks
= 1;
4513 /* Try to reenable any breakpoints in shared libraries. */
4515 re_enable_breakpoints_in_shlibs (void)
4517 struct breakpoint
*b
, *tmp
;
4519 ALL_BREAKPOINTS_SAFE (b
, tmp
)
4521 if (b
->enable_state
== bp_shlib_disabled
)
4526 /* Do not reenable the breakpoint if the shared library is
4527 still not mapped in. */
4529 lib
= PC_SOLIB (b
->loc
->address
);
4531 lib
= solib_address (b
->loc
->address
);
4533 if (lib
!= NULL
&& target_read_memory (b
->loc
->address
, buf
, 1) == 0)
4534 b
->enable_state
= bp_enabled
;
4536 else if (b
->pending
&& (b
->enable_state
== bp_enabled
))
4538 if (resolve_pending_breakpoint (b
) == GDB_RC_OK
)
4539 delete_breakpoint (b
);
4545 solib_load_unload_1 (char *hookname
, int tempflag
, char *dll_pathname
,
4546 char *cond_string
, enum bptype bp_kind
)
4548 struct breakpoint
*b
;
4549 struct symtabs_and_lines sals
;
4550 struct cleanup
*old_chain
;
4551 struct cleanup
*canonical_strings_chain
= NULL
;
4552 char *addr_start
= hookname
;
4553 char *addr_end
= NULL
;
4554 char **canonical
= (char **) NULL
;
4555 int thread
= -1; /* All threads. */
4557 /* Set a breakpoint on the specified hook. */
4558 sals
= decode_line_1 (&hookname
, 1, (struct symtab
*) NULL
,
4559 0, &canonical
, NULL
);
4560 addr_end
= hookname
;
4562 if (sals
.nelts
== 0)
4564 warning (_("Unable to set a breakpoint on dynamic linker callback.\n"
4565 "Suggest linking with /opt/langtools/lib/end.o.\n"
4566 "GDB will be unable to track shl_load/shl_unload calls."));
4569 if (sals
.nelts
!= 1)
4571 warning (_("Unable to set unique breakpoint on dynamic linker callback.\n"
4572 "GDB will be unable to track shl_load/shl_unload calls."));
4576 /* Make sure that all storage allocated in decode_line_1 gets freed
4577 in case the following errors out. */
4578 old_chain
= make_cleanup (xfree
, sals
.sals
);
4579 if (canonical
!= (char **) NULL
)
4581 make_cleanup (xfree
, canonical
);
4582 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
4583 if (canonical
[0] != NULL
)
4584 make_cleanup (xfree
, canonical
[0]);
4587 resolve_sal_pc (&sals
.sals
[0]);
4589 /* Remove the canonical strings from the cleanup, they are needed below. */
4590 if (canonical
!= (char **) NULL
)
4591 discard_cleanups (canonical_strings_chain
);
4593 b
= set_raw_breakpoint (sals
.sals
[0], bp_kind
);
4594 set_breakpoint_count (breakpoint_count
+ 1);
4595 b
->number
= breakpoint_count
;
4597 b
->cond_string
= (cond_string
== NULL
) ?
4598 NULL
: savestring (cond_string
, strlen (cond_string
));
4601 if (canonical
!= (char **) NULL
&& canonical
[0] != NULL
)
4602 b
->addr_string
= canonical
[0];
4603 else if (addr_start
)
4604 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
4606 b
->enable_state
= bp_enabled
;
4607 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4609 if (dll_pathname
== NULL
)
4610 b
->dll_pathname
= NULL
;
4613 b
->dll_pathname
= (char *) xmalloc (strlen (dll_pathname
) + 1);
4614 strcpy (b
->dll_pathname
, dll_pathname
);
4618 do_cleanups (old_chain
);
4622 create_solib_load_event_breakpoint (char *hookname
, int tempflag
,
4623 char *dll_pathname
, char *cond_string
)
4625 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4626 cond_string
, bp_catch_load
);
4630 create_solib_unload_event_breakpoint (char *hookname
, int tempflag
,
4631 char *dll_pathname
, char *cond_string
)
4633 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4634 cond_string
, bp_catch_unload
);
4638 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4639 enum bptype bp_kind
)
4641 struct symtab_and_line sal
;
4642 struct breakpoint
*b
;
4643 int thread
= -1; /* All threads. */
4650 b
= set_raw_breakpoint (sal
, bp_kind
);
4651 set_breakpoint_count (breakpoint_count
+ 1);
4652 b
->number
= breakpoint_count
;
4654 b
->cond_string
= (cond_string
== NULL
) ?
4655 NULL
: savestring (cond_string
, strlen (cond_string
));
4657 b
->addr_string
= NULL
;
4658 b
->enable_state
= bp_enabled
;
4659 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4660 b
->forked_inferior_pid
= 0;
4666 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4668 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4672 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4674 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4678 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4680 struct symtab_and_line sal
;
4681 struct breakpoint
*b
;
4682 int thread
= -1; /* All threads. */
4689 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4690 set_breakpoint_count (breakpoint_count
+ 1);
4691 b
->number
= breakpoint_count
;
4693 b
->cond_string
= (cond_string
== NULL
) ?
4694 NULL
: savestring (cond_string
, strlen (cond_string
));
4696 b
->addr_string
= NULL
;
4697 b
->enable_state
= bp_enabled
;
4698 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4704 hw_breakpoint_used_count (void)
4706 struct breakpoint
*b
;
4711 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4719 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4721 struct breakpoint
*b
;
4724 *other_type_used
= 0;
4727 if (breakpoint_enabled (b
))
4729 if (b
->type
== type
)
4731 else if ((b
->type
== bp_hardware_watchpoint
||
4732 b
->type
== bp_read_watchpoint
||
4733 b
->type
== bp_access_watchpoint
))
4734 *other_type_used
= 1;
4740 /* Call this after hitting the longjmp() breakpoint. Use this to set
4741 a new breakpoint at the target of the jmp_buf.
4743 FIXME - This ought to be done by setting a temporary breakpoint
4744 that gets deleted automatically... */
4747 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4749 struct breakpoint
*b
;
4752 if (b
->type
== bp_longjmp_resume
)
4754 b
->loc
->requested_address
= pc
;
4755 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4757 b
->enable_state
= bp_enabled
;
4758 b
->frame_id
= frame_id
;
4759 check_duplicates (b
);
4765 disable_watchpoints_before_interactive_call_start (void)
4767 struct breakpoint
*b
;
4771 if (((b
->type
== bp_watchpoint
)
4772 || (b
->type
== bp_hardware_watchpoint
)
4773 || (b
->type
== bp_read_watchpoint
)
4774 || (b
->type
== bp_access_watchpoint
)
4775 || ep_is_exception_catchpoint (b
))
4776 && breakpoint_enabled (b
))
4778 b
->enable_state
= bp_call_disabled
;
4779 check_duplicates (b
);
4785 enable_watchpoints_after_interactive_call_stop (void)
4787 struct breakpoint
*b
;
4791 if (((b
->type
== bp_watchpoint
)
4792 || (b
->type
== bp_hardware_watchpoint
)
4793 || (b
->type
== bp_read_watchpoint
)
4794 || (b
->type
== bp_access_watchpoint
)
4795 || ep_is_exception_catchpoint (b
))
4796 && (b
->enable_state
== bp_call_disabled
))
4798 b
->enable_state
= bp_enabled
;
4799 check_duplicates (b
);
4805 /* Set a breakpoint that will evaporate an end of command
4806 at address specified by SAL.
4807 Restrict it to frame FRAME if FRAME is nonzero. */
4810 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4813 struct breakpoint
*b
;
4814 b
= set_raw_breakpoint (sal
, type
);
4815 b
->enable_state
= bp_enabled
;
4816 b
->disposition
= disp_donttouch
;
4817 b
->frame_id
= frame_id
;
4819 /* If we're debugging a multi-threaded program, then we
4820 want momentary breakpoints to be active in only a
4821 single thread of control. */
4822 if (in_thread_list (inferior_ptid
))
4823 b
->thread
= pid_to_thread_id (inferior_ptid
);
4829 /* Tell the user we have just set a breakpoint B. */
4832 mention (struct breakpoint
*b
)
4835 struct cleanup
*old_chain
, *ui_out_chain
;
4836 struct ui_stream
*stb
;
4838 stb
= ui_out_stream_new (uiout
);
4839 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4841 /* FIXME: This is misplaced; mention() is called by things (like
4842 hitting a watchpoint) other than breakpoint creation. It should
4843 be possible to clean this up and at the same time replace the
4844 random calls to breakpoint_changed with this hook, as has already
4845 been done for deprecated_delete_breakpoint_hook and so on. */
4846 if (deprecated_create_breakpoint_hook
)
4847 deprecated_create_breakpoint_hook (b
);
4848 breakpoint_create_event (b
->number
);
4850 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4851 b
->ops
->print_mention (b
);
4856 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4859 ui_out_text (uiout
, "Watchpoint ");
4860 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4861 ui_out_field_int (uiout
, "number", b
->number
);
4862 ui_out_text (uiout
, ": ");
4863 print_expression (b
->exp
, stb
->stream
);
4864 ui_out_field_stream (uiout
, "exp", stb
);
4865 do_cleanups (ui_out_chain
);
4867 case bp_hardware_watchpoint
:
4868 ui_out_text (uiout
, "Hardware watchpoint ");
4869 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4870 ui_out_field_int (uiout
, "number", b
->number
);
4871 ui_out_text (uiout
, ": ");
4872 print_expression (b
->exp
, stb
->stream
);
4873 ui_out_field_stream (uiout
, "exp", stb
);
4874 do_cleanups (ui_out_chain
);
4876 case bp_read_watchpoint
:
4877 ui_out_text (uiout
, "Hardware read watchpoint ");
4878 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4879 ui_out_field_int (uiout
, "number", b
->number
);
4880 ui_out_text (uiout
, ": ");
4881 print_expression (b
->exp
, stb
->stream
);
4882 ui_out_field_stream (uiout
, "exp", stb
);
4883 do_cleanups (ui_out_chain
);
4885 case bp_access_watchpoint
:
4886 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4887 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4888 ui_out_field_int (uiout
, "number", b
->number
);
4889 ui_out_text (uiout
, ": ");
4890 print_expression (b
->exp
, stb
->stream
);
4891 ui_out_field_stream (uiout
, "exp", stb
);
4892 do_cleanups (ui_out_chain
);
4895 if (ui_out_is_mi_like_p (uiout
))
4900 printf_filtered (_("Breakpoint %d"), b
->number
);
4903 case bp_hardware_breakpoint
:
4904 if (ui_out_is_mi_like_p (uiout
))
4909 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4913 case bp_catch_unload
:
4914 printf_filtered (_("Catchpoint %d (%s %s)"),
4916 (b
->type
== bp_catch_load
) ? "load" : "unload",
4917 (b
->dll_pathname
!= NULL
) ?
4918 b
->dll_pathname
: "<any library>");
4921 case bp_catch_vfork
:
4922 printf_filtered (_("Catchpoint %d (%s)"),
4924 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4927 printf_filtered (_("Catchpoint %d (exec)"),
4930 case bp_catch_catch
:
4931 case bp_catch_throw
:
4932 printf_filtered (_("Catchpoint %d (%s)"),
4934 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4940 case bp_longjmp_resume
:
4941 case bp_step_resume
:
4943 case bp_watchpoint_scope
:
4944 case bp_shlib_event
:
4945 case bp_thread_event
:
4946 case bp_overlay_event
:
4952 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4956 printf_filtered (_(" (%s) pending."), b
->addr_string
);
4960 if (addressprint
|| b
->source_file
== NULL
)
4962 printf_filtered (" at ");
4963 deprecated_print_address_numeric (b
->loc
->address
, 1, gdb_stdout
);
4966 printf_filtered (": file %s, line %d.",
4967 b
->source_file
, b
->line_number
);
4970 do_cleanups (old_chain
);
4971 if (ui_out_is_mi_like_p (uiout
))
4973 printf_filtered ("\n");
4977 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4978 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4979 COND[i] and COND_STRING[i] values.
4981 The parameter PENDING_BP points to a pending breakpoint that is
4982 the basis of the breakpoints currently being created. The pending
4983 breakpoint may contain a separate condition string or commands
4984 that were added after the initial pending breakpoint was created.
4986 NOTE: If the function succeeds, the caller is expected to cleanup
4987 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4988 array contents). If the function fails (error() is called), the
4989 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4990 COND and SALS arrays and each of those arrays contents. */
4993 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
4994 struct expression
**cond
, char **cond_string
,
4995 enum bptype type
, enum bpdisp disposition
,
4996 int thread
, int ignore_count
, int from_tty
,
4997 struct breakpoint
*pending_bp
)
4999 if (type
== bp_hardware_breakpoint
)
5001 int i
= hw_breakpoint_used_count ();
5002 int target_resources_ok
=
5003 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5005 if (target_resources_ok
== 0)
5006 error (_("No hardware breakpoint support in the target."));
5007 else if (target_resources_ok
< 0)
5008 error (_("Hardware breakpoints used exceeds limit."));
5011 /* Now set all the breakpoints. */
5014 for (i
= 0; i
< sals
.nelts
; i
++)
5016 struct breakpoint
*b
;
5017 struct symtab_and_line sal
= sals
.sals
[i
];
5020 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5022 b
= set_raw_breakpoint (sal
, type
);
5023 set_breakpoint_count (breakpoint_count
+ 1);
5024 b
->number
= breakpoint_count
;
5028 b
->addr_string
= addr_string
[i
];
5030 /* addr_string has to be used or breakpoint_re_set will delete
5032 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5033 b
->cond_string
= cond_string
[i
];
5034 b
->ignore_count
= ignore_count
;
5035 b
->enable_state
= bp_enabled
;
5036 b
->disposition
= disposition
;
5037 /* If resolving a pending breakpoint, a check must be made to see if
5038 the user has specified a new condition or commands for the
5039 breakpoint. A new condition will override any condition that was
5040 initially specified with the initial breakpoint command. */
5044 if (pending_bp
->cond_string
)
5046 arg
= pending_bp
->cond_string
;
5047 b
->cond_string
= savestring (arg
, strlen (arg
));
5048 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->loc
->address
), 0);
5050 error (_("Junk at end of pending breakpoint condition expression"));
5052 /* If there are commands associated with the breakpoint, they should
5054 if (pending_bp
->commands
)
5055 b
->commands
= copy_command_lines (pending_bp
->commands
);
5057 /* We have to copy over the ignore_count and thread as well. */
5058 b
->ignore_count
= pending_bp
->ignore_count
;
5059 b
->thread
= pending_bp
->thread
;
5066 /* Parse ARG which is assumed to be a SAL specification possibly
5067 followed by conditionals. On return, SALS contains an array of SAL
5068 addresses found. ADDR_STRING contains a vector of (canonical)
5069 address strings. ARG points to the end of the SAL. */
5072 parse_breakpoint_sals (char **address
,
5073 struct symtabs_and_lines
*sals
,
5074 char ***addr_string
,
5077 char *addr_start
= *address
;
5078 *addr_string
= NULL
;
5079 /* If no arg given, or if first arg is 'if ', use the default
5081 if ((*address
) == NULL
5082 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5084 if (default_breakpoint_valid
)
5086 struct symtab_and_line sal
;
5087 init_sal (&sal
); /* initialize to zeroes */
5088 sals
->sals
= (struct symtab_and_line
*)
5089 xmalloc (sizeof (struct symtab_and_line
));
5090 sal
.pc
= default_breakpoint_address
;
5091 sal
.line
= default_breakpoint_line
;
5092 sal
.symtab
= default_breakpoint_symtab
;
5093 sal
.section
= find_pc_overlay (sal
.pc
);
5094 sals
->sals
[0] = sal
;
5098 error (_("No default breakpoint address now."));
5102 /* Force almost all breakpoints to be in terms of the
5103 current_source_symtab (which is decode_line_1's default). This
5104 should produce the results we want almost all of the time while
5105 leaving default_breakpoint_* alone.
5106 ObjC: However, don't match an Objective-C method name which
5107 may have a '+' or '-' succeeded by a '[' */
5109 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5111 if (default_breakpoint_valid
5113 || ((strchr ("+-", (*address
)[0]) != NULL
)
5114 && ((*address
)[1] != '['))))
5115 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5116 default_breakpoint_line
, addr_string
,
5119 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5120 addr_string
, not_found_ptr
);
5122 /* For any SAL that didn't have a canonical string, fill one in. */
5123 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5124 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5125 if (addr_start
!= (*address
))
5128 for (i
= 0; i
< sals
->nelts
; i
++)
5130 /* Add the string if not present. */
5131 if ((*addr_string
)[i
] == NULL
)
5132 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5138 /* Convert each SAL into a real PC. Verify that the PC can be
5139 inserted as a breakpoint. If it can't throw an error. */
5142 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5146 for (i
= 0; i
< sals
->nelts
; i
++)
5148 resolve_sal_pc (&sals
->sals
[i
]);
5150 /* It's possible for the PC to be nonzero, but still an illegal
5151 value on some targets.
5153 For example, on HP-UX if you start gdb, and before running the
5154 inferior you try to set a breakpoint on a shared library function
5155 "foo" where the inferior doesn't call "foo" directly but does
5156 pass its address to another function call, then we do find a
5157 minimal symbol for the "foo", but it's address is invalid.
5158 (Appears to be an index into a table that the loader sets up
5159 when the inferior is run.)
5161 Give the target a chance to bless sals.sals[i].pc before we
5162 try to make a breakpoint for it. */
5163 #ifdef DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE
5164 if (DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE (sals
->sals
[i
].pc
))
5166 if (address
== NULL
)
5167 error (_("Cannot break without a running program."));
5169 error (_("Cannot break on %s without a running program."),
5177 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5179 struct captured_parse_breakpoint_args
*args
= data
;
5181 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5182 args
->not_found_ptr
);
5185 /* Set a breakpoint according to ARG (function, linenum or *address)
5186 flag: first bit : 0 non-temporary, 1 temporary.
5187 second bit : 0 normal breakpoint, 1 hardware breakpoint.
5189 PENDING_BP is non-NULL when this function is being called to resolve
5190 a pending breakpoint. */
5193 break_command_1 (char *arg
, int flag
, int from_tty
, struct breakpoint
*pending_bp
)
5195 struct gdb_exception e
;
5196 int tempflag
, hardwareflag
;
5197 struct symtabs_and_lines sals
;
5198 struct expression
**cond
= 0;
5199 struct symtab_and_line pending_sal
;
5200 char **cond_string
= (char **) NULL
;
5203 char *addr_start
= arg
;
5205 struct cleanup
*old_chain
;
5206 struct cleanup
*breakpoint_chain
= NULL
;
5207 struct captured_parse_breakpoint_args parse_args
;
5211 int ignore_count
= 0;
5214 hardwareflag
= flag
& BP_HARDWAREFLAG
;
5215 tempflag
= flag
& BP_TEMPFLAG
;
5221 parse_args
.arg_p
= &arg
;
5222 parse_args
.sals_p
= &sals
;
5223 parse_args
.addr_string_p
= &addr_string
;
5224 parse_args
.not_found_ptr
= ¬_found
;
5226 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5227 &parse_args
, RETURN_MASK_ALL
);
5229 /* If caller is interested in rc value from parse, set value. */
5233 exception_print (gdb_stderr
, e
);
5238 case NOT_FOUND_ERROR
:
5239 /* If called to resolve pending breakpoint, just return
5244 exception_print (gdb_stderr
, e
);
5246 /* If pending breakpoint support is turned off, throw
5249 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5250 deprecated_throw_reason (RETURN_ERROR
);
5252 /* If pending breakpoint support is auto query and the user
5253 selects no, then simply return the error code. */
5254 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5255 !nquery ("Make breakpoint pending on future shared library load? "))
5258 /* At this point, either the user was queried about setting
5259 a pending breakpoint and selected yes, or pending
5260 breakpoint behavior is on and thus a pending breakpoint
5261 is defaulted on behalf of the user. */
5262 copy_arg
= xstrdup (addr_start
);
5263 addr_string
= ©_arg
;
5265 sals
.sals
= &pending_sal
;
5270 exception_print (gdb_stderr
, e
);
5278 /* Create a chain of things that always need to be cleaned up. */
5279 old_chain
= make_cleanup (null_cleanup
, 0);
5283 /* Make sure that all storage allocated to SALS gets freed. */
5284 make_cleanup (xfree
, sals
.sals
);
5286 /* Cleanup the addr_string array but not its contents. */
5287 make_cleanup (xfree
, addr_string
);
5290 /* Allocate space for all the cond expressions. */
5291 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5292 make_cleanup (xfree
, cond
);
5294 /* Allocate space for all the cond strings. */
5295 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
5296 make_cleanup (xfree
, cond_string
);
5298 /* ----------------------------- SNIP -----------------------------
5299 Anything added to the cleanup chain beyond this point is assumed
5300 to be part of a breakpoint. If the breakpoint create succeeds
5301 then the memory is not reclaimed. */
5302 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5304 /* Mark the contents of the addr_string for cleanup. These go on
5305 the breakpoint_chain and only occure if the breakpoint create
5307 for (i
= 0; i
< sals
.nelts
; i
++)
5309 if (addr_string
[i
] != NULL
)
5310 make_cleanup (xfree
, addr_string
[i
]);
5313 /* Resolve all line numbers to PC's and verify that the addresses
5314 are ok for the target. */
5316 breakpoint_sals_to_pc (&sals
, addr_start
);
5318 /* Verify that condition can be parsed, before setting any
5319 breakpoints. Allocate a separate condition expression for each
5321 thread
= -1; /* No specific thread yet */
5324 for (i
= 0; i
< sals
.nelts
; i
++)
5331 char *cond_start
= NULL
;
5332 char *cond_end
= NULL
;
5333 while (*tok
== ' ' || *tok
== '\t')
5338 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5341 toklen
= end_tok
- tok
;
5343 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5345 tok
= cond_start
= end_tok
+ 1;
5346 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
),
5348 make_cleanup (xfree
, cond
[i
]);
5350 cond_string
[i
] = savestring (cond_start
,
5351 cond_end
- cond_start
);
5352 make_cleanup (xfree
, cond_string
[i
]);
5354 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5360 thread
= strtol (tok
, &tok
, 0);
5362 error (_("Junk after thread keyword."));
5363 if (!valid_thread_id (thread
))
5364 error (_("Unknown thread %d."), thread
);
5367 error (_("Junk at end of arguments."));
5370 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
5371 hardwareflag
? bp_hardware_breakpoint
5373 tempflag
? disp_del
: disp_donttouch
,
5374 thread
, ignore_count
, from_tty
,
5379 struct symtab_and_line sal
;
5380 struct breakpoint
*b
;
5385 make_cleanup (xfree
, copy_arg
);
5387 b
= set_raw_breakpoint (sal
, hardwareflag
? bp_hardware_breakpoint
5389 set_breakpoint_count (breakpoint_count
+ 1);
5390 b
->number
= breakpoint_count
;
5393 b
->addr_string
= *addr_string
;
5394 b
->cond_string
= *cond_string
;
5395 b
->ignore_count
= ignore_count
;
5397 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5398 b
->from_tty
= from_tty
;
5404 warning (_("Multiple breakpoints were set.\n"
5405 "Use the \"delete\" command to delete unwanted breakpoints."));
5406 /* That's it. Discard the cleanups for data inserted into the
5408 discard_cleanups (breakpoint_chain
);
5409 /* But cleanup everything else. */
5410 do_cleanups (old_chain
);
5415 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5416 linenum or *address) with COND and IGNORE_COUNT. */
5418 struct captured_breakpoint_args
5429 do_captured_breakpoint (struct ui_out
*uiout
, void *data
)
5431 struct captured_breakpoint_args
*args
= data
;
5432 struct symtabs_and_lines sals
;
5433 struct expression
**cond
;
5434 struct cleanup
*old_chain
;
5435 struct cleanup
*breakpoint_chain
= NULL
;
5442 /* Parse the source and lines spec. Delay check that the expression
5443 didn't contain trailing garbage until after cleanups are in
5447 address_end
= args
->address
;
5449 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
, 0);
5454 /* Create a chain of things at always need to be cleaned up. */
5455 old_chain
= make_cleanup (null_cleanup
, 0);
5457 /* Always have a addr_string array, even if it is empty. */
5458 make_cleanup (xfree
, addr_string
);
5460 /* Make sure that all storage allocated to SALS gets freed. */
5461 make_cleanup (xfree
, sals
.sals
);
5463 /* Allocate space for all the cond expressions. */
5464 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5465 make_cleanup (xfree
, cond
);
5467 /* Allocate space for all the cond strings. */
5468 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
5469 make_cleanup (xfree
, cond_string
);
5471 /* ----------------------------- SNIP -----------------------------
5472 Anything added to the cleanup chain beyond this point is assumed
5473 to be part of a breakpoint. If the breakpoint create goes
5474 through then that memory is not cleaned up. */
5475 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5477 /* Mark the contents of the addr_string for cleanup. These go on
5478 the breakpoint_chain and only occure if the breakpoint create
5480 for (i
= 0; i
< sals
.nelts
; i
++)
5482 if (addr_string
[i
] != NULL
)
5483 make_cleanup (xfree
, addr_string
[i
]);
5486 /* Wait until now before checking for garbage at the end of the
5487 address. That way cleanups can take care of freeing any
5489 if (*address_end
!= '\0')
5490 error (_("Garbage %s following breakpoint address"), address_end
);
5492 /* Resolve all line numbers to PC's. */
5493 breakpoint_sals_to_pc (&sals
, args
->address
);
5495 /* Verify that conditions can be parsed, before setting any
5497 for (i
= 0; i
< sals
.nelts
; i
++)
5499 if (args
->condition
!= NULL
)
5501 char *tok
= args
->condition
;
5502 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
5504 error (_("Garbage %s follows condition"), tok
);
5505 make_cleanup (xfree
, cond
[i
]);
5506 cond_string
[i
] = xstrdup (args
->condition
);
5510 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
5511 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
5512 args
->tempflag
? disp_del
: disp_donttouch
,
5513 args
->thread
, args
->ignore_count
, 0/*from-tty*/,
5514 NULL
/*pending_bp*/);
5516 /* That's it. Discard the cleanups for data inserted into the
5518 discard_cleanups (breakpoint_chain
);
5519 /* But cleanup everything else. */
5520 do_cleanups (old_chain
);
5525 gdb_breakpoint (char *address
, char *condition
,
5526 int hardwareflag
, int tempflag
,
5527 int thread
, int ignore_count
,
5528 char **error_message
)
5530 struct captured_breakpoint_args args
;
5531 args
.address
= address
;
5532 args
.condition
= condition
;
5533 args
.hardwareflag
= hardwareflag
;
5534 args
.tempflag
= tempflag
;
5535 args
.thread
= thread
;
5536 args
.ignore_count
= ignore_count
;
5537 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint
, &args
,
5538 error_message
, RETURN_MASK_ALL
) < 0)
5545 /* Helper function for break_command_1 and disassemble_command. */
5548 resolve_sal_pc (struct symtab_and_line
*sal
)
5552 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5554 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5555 error (_("No line %d in file \"%s\"."),
5556 sal
->line
, sal
->symtab
->filename
);
5560 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5562 struct blockvector
*bv
;
5567 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5570 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5571 sym
= block_function (b
);
5574 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5575 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5579 /* It really is worthwhile to have the section, so we'll just
5580 have to look harder. This case can be executed if we have
5581 line numbers but no functions (as can happen in assembly
5584 struct minimal_symbol
*msym
;
5586 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5588 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5595 break_command (char *arg
, int from_tty
)
5597 break_command_1 (arg
, 0, from_tty
, NULL
);
5601 tbreak_command (char *arg
, int from_tty
)
5603 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
, NULL
);
5607 hbreak_command (char *arg
, int from_tty
)
5609 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
, NULL
);
5613 thbreak_command (char *arg
, int from_tty
)
5615 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
, NULL
);
5619 stop_command (char *arg
, int from_tty
)
5621 printf_filtered (_("Specify the type of breakpoint to set.\n\
5622 Usage: stop in <function | address>\n\
5623 stop at <line>\n"));
5627 stopin_command (char *arg
, int from_tty
)
5631 if (arg
== (char *) NULL
)
5633 else if (*arg
!= '*')
5638 /* look for a ':'. If this is a line number specification, then
5639 say it is bad, otherwise, it should be an address or
5640 function/method name */
5641 while (*argptr
&& !hasColon
)
5643 hasColon
= (*argptr
== ':');
5648 badInput
= (*argptr
!= ':'); /* Not a class::method */
5650 badInput
= isdigit (*arg
); /* a simple line number */
5654 printf_filtered (_("Usage: stop in <function | address>\n"));
5656 break_command_1 (arg
, 0, from_tty
, NULL
);
5660 stopat_command (char *arg
, int from_tty
)
5664 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5671 /* look for a ':'. If there is a '::' then get out, otherwise
5672 it is probably a line number. */
5673 while (*argptr
&& !hasColon
)
5675 hasColon
= (*argptr
== ':');
5680 badInput
= (*argptr
== ':'); /* we have class::method */
5682 badInput
= !isdigit (*arg
); /* not a line number */
5686 printf_filtered (_("Usage: stop at <line>\n"));
5688 break_command_1 (arg
, 0, from_tty
, NULL
);
5691 /* accessflag: hw_write: watch write,
5692 hw_read: watch read,
5693 hw_access: watch access (read or write) */
5695 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5697 struct breakpoint
*b
;
5698 struct symtab_and_line sal
;
5699 struct expression
*exp
;
5700 struct block
*exp_valid_block
;
5701 struct value
*val
, *mark
;
5702 struct frame_info
*frame
;
5703 struct frame_info
*prev_frame
= NULL
;
5704 char *exp_start
= NULL
;
5705 char *exp_end
= NULL
;
5706 char *tok
, *end_tok
;
5708 char *cond_start
= NULL
;
5709 char *cond_end
= NULL
;
5710 struct expression
*cond
= NULL
;
5711 int i
, other_type_used
, target_resources_ok
= 0;
5712 enum bptype bp_type
;
5715 init_sal (&sal
); /* initialize to zeroes */
5717 /* Parse arguments. */
5718 innermost_block
= NULL
;
5720 exp
= parse_exp_1 (&arg
, 0, 0);
5722 exp_valid_block
= innermost_block
;
5723 mark
= value_mark ();
5724 val
= evaluate_expression (exp
);
5725 release_value (val
);
5726 if (value_lazy (val
))
5727 value_fetch_lazy (val
);
5730 while (*tok
== ' ' || *tok
== '\t')
5734 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5737 toklen
= end_tok
- tok
;
5738 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5740 tok
= cond_start
= end_tok
+ 1;
5741 cond
= parse_exp_1 (&tok
, 0, 0);
5745 error (_("Junk at end of command."));
5747 if (accessflag
== hw_read
)
5748 bp_type
= bp_read_watchpoint
;
5749 else if (accessflag
== hw_access
)
5750 bp_type
= bp_access_watchpoint
;
5752 bp_type
= bp_hardware_watchpoint
;
5754 mem_cnt
= can_use_hardware_watchpoint (val
);
5755 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5756 error (_("Expression cannot be implemented with read/access watchpoint."));
5759 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5760 target_resources_ok
=
5761 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5763 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5764 error (_("Target does not support this type of hardware watchpoint."));
5766 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5767 error (_("Target can only support one kind of HW watchpoint at a time."));
5770 #if defined(HPUXHPPA)
5771 /* On HP-UX if you set a h/w
5772 watchpoint before the "run" command, the inferior dies with a e.g.,
5773 SIGILL once you start it. I initially believed this was due to a
5774 bad interaction between page protection traps and the initial
5775 startup sequence by the dynamic linker.
5777 However, I tried avoiding that by having HP-UX's implementation of
5778 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5779 yet, which forced slow watches before a "run" or "attach", and it
5780 still fails somewhere in the startup code.
5782 Until I figure out what's happening, I'm disallowing watches altogether
5783 before the "run" or "attach" command. We'll tell the user they must
5784 set watches after getting the program started. */
5785 if (!target_has_execution
)
5787 warning (_("can't do that without a running program; try \"break main\"), \"run\" first");
5790 #endif /* HPUXHPPA */
5792 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5793 watchpoint could not be set. */
5794 if (!mem_cnt
|| target_resources_ok
<= 0)
5795 bp_type
= bp_watchpoint
;
5797 /* Now set up the breakpoint. */
5798 b
= set_raw_breakpoint (sal
, bp_type
);
5799 set_breakpoint_count (breakpoint_count
+ 1);
5800 b
->number
= breakpoint_count
;
5801 b
->disposition
= disp_donttouch
;
5803 b
->exp_valid_block
= exp_valid_block
;
5804 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5808 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5812 frame
= block_innermost_frame (exp_valid_block
);
5815 prev_frame
= get_prev_frame (frame
);
5816 b
->watchpoint_frame
= get_frame_id (frame
);
5820 memset (&b
->watchpoint_frame
, 0, sizeof (b
->watchpoint_frame
));
5823 /* If the expression is "local", then set up a "watchpoint scope"
5824 breakpoint at the point where we've left the scope of the watchpoint
5826 if (innermost_block
)
5830 struct breakpoint
*scope_breakpoint
;
5831 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5832 bp_watchpoint_scope
);
5834 scope_breakpoint
->enable_state
= bp_enabled
;
5836 /* Automatically delete the breakpoint when it hits. */
5837 scope_breakpoint
->disposition
= disp_del
;
5839 /* Only break in the proper frame (help with recursion). */
5840 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5842 /* Set the address at which we will stop. */
5843 scope_breakpoint
->loc
->requested_address
5844 = get_frame_pc (prev_frame
);
5845 scope_breakpoint
->loc
->address
5846 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5847 scope_breakpoint
->type
);
5849 /* The scope breakpoint is related to the watchpoint. We
5850 will need to act on them together. */
5851 b
->related_breakpoint
= scope_breakpoint
;
5854 value_free_to_mark (mark
);
5858 /* Return count of locations need to be watched and can be handled
5859 in hardware. If the watchpoint can not be handled
5860 in hardware return zero. */
5863 can_use_hardware_watchpoint (struct value
*v
)
5865 int found_memory_cnt
= 0;
5866 struct value
*head
= v
;
5868 /* Did the user specifically forbid us to use hardware watchpoints? */
5869 if (!can_use_hw_watchpoints
)
5872 /* Make sure that the value of the expression depends only upon
5873 memory contents, and values computed from them within GDB. If we
5874 find any register references or function calls, we can't use a
5875 hardware watchpoint.
5877 The idea here is that evaluating an expression generates a series
5878 of values, one holding the value of every subexpression. (The
5879 expression a*b+c has five subexpressions: a, b, a*b, c, and
5880 a*b+c.) GDB's values hold almost enough information to establish
5881 the criteria given above --- they identify memory lvalues,
5882 register lvalues, computed values, etcetera. So we can evaluate
5883 the expression, and then scan the chain of values that leaves
5884 behind to decide whether we can detect any possible change to the
5885 expression's final value using only hardware watchpoints.
5887 However, I don't think that the values returned by inferior
5888 function calls are special in any way. So this function may not
5889 notice that an expression involving an inferior function call
5890 can't be watched with hardware watchpoints. FIXME. */
5891 for (; v
; v
= value_next (v
))
5893 if (VALUE_LVAL (v
) == lval_memory
)
5896 /* A lazy memory lvalue is one that GDB never needed to fetch;
5897 we either just used its address (e.g., `a' in `a.b') or
5898 we never needed it at all (e.g., `a' in `a,b'). */
5902 /* Ahh, memory we actually used! Check if we can cover
5903 it with hardware watchpoints. */
5904 struct type
*vtype
= check_typedef (value_type (v
));
5906 /* We only watch structs and arrays if user asked for it
5907 explicitly, never if they just happen to appear in a
5908 middle of some value chain. */
5910 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5911 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5913 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
5914 int len
= TYPE_LENGTH (value_type (v
));
5916 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5923 else if (VALUE_LVAL (v
) != not_lval
5924 && deprecated_value_modifiable (v
) == 0)
5925 return 0; /* ??? What does this represent? */
5926 else if (VALUE_LVAL (v
) == lval_register
)
5927 return 0; /* cannot watch a register with a HW watchpoint */
5930 /* The expression itself looks suitable for using a hardware
5931 watchpoint, but give the target machine a chance to reject it. */
5932 return found_memory_cnt
;
5936 watch_command_wrapper (char *arg
, int from_tty
)
5938 watch_command (arg
, from_tty
);
5942 watch_command (char *arg
, int from_tty
)
5944 watch_command_1 (arg
, hw_write
, from_tty
);
5948 rwatch_command_wrapper (char *arg
, int from_tty
)
5950 rwatch_command (arg
, from_tty
);
5954 rwatch_command (char *arg
, int from_tty
)
5956 watch_command_1 (arg
, hw_read
, from_tty
);
5960 awatch_command_wrapper (char *arg
, int from_tty
)
5962 awatch_command (arg
, from_tty
);
5966 awatch_command (char *arg
, int from_tty
)
5968 watch_command_1 (arg
, hw_access
, from_tty
);
5972 /* Helper routines for the until_command routine in infcmd.c. Here
5973 because it uses the mechanisms of breakpoints. */
5975 /* This function is called by fetch_inferior_event via the
5976 cmd_continuation pointer, to complete the until command. It takes
5977 care of cleaning up the temporary breakpoints set up by the until
5980 until_break_command_continuation (struct continuation_arg
*arg
)
5982 struct cleanup
*cleanups
;
5984 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
5985 do_exec_cleanups (cleanups
);
5989 until_break_command (char *arg
, int from_tty
, int anywhere
)
5991 struct symtabs_and_lines sals
;
5992 struct symtab_and_line sal
;
5993 struct frame_info
*frame
= get_selected_frame (NULL
);
5994 struct frame_info
*prev_frame
= get_prev_frame (frame
);
5995 struct breakpoint
*breakpoint
;
5996 struct cleanup
*old_chain
;
5997 struct continuation_arg
*arg1
;
6000 clear_proceed_status ();
6002 /* Set a breakpoint where the user wants it and at return from
6005 if (default_breakpoint_valid
)
6006 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6007 default_breakpoint_line
, (char ***) NULL
, NULL
);
6009 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6010 0, (char ***) NULL
, NULL
);
6012 if (sals
.nelts
!= 1)
6013 error (_("Couldn't get information on specified line."));
6016 xfree (sals
.sals
); /* malloc'd, so freed */
6019 error (_("Junk at end of arguments."));
6021 resolve_sal_pc (&sal
);
6024 /* If the user told us to continue until a specified location,
6025 we don't specify a frame at which we need to stop. */
6026 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6028 /* Otherwise, specify the current frame, because we want to stop only
6029 at the very same frame. */
6030 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6033 if (!target_can_async_p ())
6034 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6036 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
6038 /* If we are running asynchronously, and the target supports async
6039 execution, we are not waiting for the target to stop, in the call
6040 tp proceed, below. This means that we cannot delete the
6041 brekpoints until the target has actually stopped. The only place
6042 where we get a chance to do that is in fetch_inferior_event, so
6043 we must set things up for that. */
6045 if (target_can_async_p ())
6047 /* In this case the arg for the continuation is just the point
6048 in the exec_cleanups chain from where to start doing
6049 cleanups, because all the continuation does is the cleanups in
6050 the exec_cleanup_chain. */
6052 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6054 arg1
->data
.pointer
= old_chain
;
6056 add_continuation (until_break_command_continuation
, arg1
);
6059 /* Keep within the current frame, or in frames called by the current
6063 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6064 sal
.pc
= get_frame_pc (prev_frame
);
6065 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6067 if (!target_can_async_p ())
6068 make_cleanup_delete_breakpoint (breakpoint
);
6070 make_exec_cleanup_delete_breakpoint (breakpoint
);
6073 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6074 /* Do the cleanups now, anly if we are not running asynchronously,
6075 of if we are, but the target is still synchronous. */
6076 if (!target_can_async_p ())
6077 do_cleanups (old_chain
);
6081 ep_skip_leading_whitespace (char **s
)
6083 if ((s
== NULL
) || (*s
== NULL
))
6085 while (isspace (**s
))
6089 /* This function examines a string, and attempts to find a token
6090 that might be an event name in the leading characters. If a
6091 possible match is found, a pointer to the last character of
6092 the token is returned. Else, NULL is returned. */
6095 ep_find_event_name_end (char *arg
)
6098 char *event_name_end
= NULL
;
6100 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6104 /* We break out of the loop when we find a token delimiter.
6105 Basically, we're looking for alphanumerics and underscores;
6106 anything else delimites the token. */
6109 if (!isalnum (*s
) && (*s
!= '_'))
6115 return event_name_end
;
6119 /* This function attempts to parse an optional "if <cond>" clause
6120 from the arg string. If one is not found, it returns NULL.
6122 Else, it returns a pointer to the condition string. (It does not
6123 attempt to evaluate the string against a particular block.) And,
6124 it updates arg to point to the first character following the parsed
6125 if clause in the arg string. */
6128 ep_parse_optional_if_clause (char **arg
)
6132 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6135 /* Skip the "if" keyword. */
6138 /* Skip any extra leading whitespace, and record the start of the
6139 condition string. */
6140 ep_skip_leading_whitespace (arg
);
6143 /* Assume that the condition occupies the remainder of the arg string. */
6144 (*arg
) += strlen (cond_string
);
6149 /* This function attempts to parse an optional filename from the arg
6150 string. If one is not found, it returns NULL.
6152 Else, it returns a pointer to the parsed filename. (This function
6153 makes no attempt to verify that a file of that name exists, or is
6154 accessible.) And, it updates arg to point to the first character
6155 following the parsed filename in the arg string.
6157 Note that clients needing to preserve the returned filename for
6158 future access should copy it to their own buffers. */
6160 ep_parse_optional_filename (char **arg
)
6162 static char filename
[1024];
6167 if ((*arg_p
== '\0') || isspace (*arg_p
))
6185 /* Commands to deal with catching events, such as signals, exceptions,
6186 process start/exit, etc. */
6190 catch_fork
, catch_vfork
6195 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6198 char *cond_string
= NULL
;
6200 ep_skip_leading_whitespace (&arg
);
6202 /* The allowed syntax is:
6204 catch [v]fork if <cond>
6206 First, check if there's an if clause. */
6207 cond_string
= ep_parse_optional_if_clause (&arg
);
6209 if ((*arg
!= '\0') && !isspace (*arg
))
6210 error (_("Junk at end of arguments."));
6212 /* If this target supports it, create a fork or vfork catchpoint
6213 and enable reporting of such events. */
6217 create_fork_event_catchpoint (tempflag
, cond_string
);
6220 create_vfork_event_catchpoint (tempflag
, cond_string
);
6223 error (_("unsupported or unknown fork kind; cannot catch it"));
6229 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6231 char *cond_string
= NULL
;
6233 ep_skip_leading_whitespace (&arg
);
6235 /* The allowed syntax is:
6237 catch exec if <cond>
6239 First, check if there's an if clause. */
6240 cond_string
= ep_parse_optional_if_clause (&arg
);
6242 if ((*arg
!= '\0') && !isspace (*arg
))
6243 error (_("Junk at end of arguments."));
6245 /* If this target supports it, create an exec catchpoint
6246 and enable reporting of such events. */
6247 create_exec_event_catchpoint (tempflag
, cond_string
);
6251 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6253 char *dll_pathname
= NULL
;
6254 char *cond_string
= NULL
;
6256 ep_skip_leading_whitespace (&arg
);
6258 /* The allowed syntax is:
6260 catch load if <cond>
6261 catch load <filename>
6262 catch load <filename> if <cond>
6264 The user is not allowed to specify the <filename> after an
6267 We'll ignore the pathological case of a file named "if".
6269 First, check if there's an if clause. If so, then there
6270 cannot be a filename. */
6271 cond_string
= ep_parse_optional_if_clause (&arg
);
6273 /* If there was an if clause, then there cannot be a filename.
6274 Else, there might be a filename and an if clause. */
6275 if (cond_string
== NULL
)
6277 dll_pathname
= ep_parse_optional_filename (&arg
);
6278 ep_skip_leading_whitespace (&arg
);
6279 cond_string
= ep_parse_optional_if_clause (&arg
);
6282 if ((*arg
!= '\0') && !isspace (*arg
))
6283 error (_("Junk at end of arguments."));
6285 /* Create a load breakpoint that only triggers when a load of
6286 the specified dll (or any dll, if no pathname was specified)
6288 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6289 dll_pathname
, cond_string
);
6293 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6295 char *dll_pathname
= NULL
;
6296 char *cond_string
= NULL
;
6298 ep_skip_leading_whitespace (&arg
);
6300 /* The allowed syntax is:
6302 catch unload if <cond>
6303 catch unload <filename>
6304 catch unload <filename> if <cond>
6306 The user is not allowed to specify the <filename> after an
6309 We'll ignore the pathological case of a file named "if".
6311 First, check if there's an if clause. If so, then there
6312 cannot be a filename. */
6313 cond_string
= ep_parse_optional_if_clause (&arg
);
6315 /* If there was an if clause, then there cannot be a filename.
6316 Else, there might be a filename and an if clause. */
6317 if (cond_string
== NULL
)
6319 dll_pathname
= ep_parse_optional_filename (&arg
);
6320 ep_skip_leading_whitespace (&arg
);
6321 cond_string
= ep_parse_optional_if_clause (&arg
);
6324 if ((*arg
!= '\0') && !isspace (*arg
))
6325 error (_("Junk at end of arguments."));
6327 /* Create an unload breakpoint that only triggers when an unload of
6328 the specified dll (or any dll, if no pathname was specified)
6330 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6331 dll_pathname
, cond_string
);
6334 /* Commands to deal with catching exceptions. */
6336 /* Set a breakpoint at the specified callback routine for an
6337 exception event callback */
6340 create_exception_catchpoint (int tempflag
, char *cond_string
,
6341 enum exception_event_kind ex_event
,
6342 struct symtab_and_line
*sal
)
6344 struct breakpoint
*b
;
6345 int thread
= -1; /* All threads. */
6348 if (!sal
) /* no exception support? */
6353 case EX_EVENT_THROW
:
6354 bptype
= bp_catch_throw
;
6356 case EX_EVENT_CATCH
:
6357 bptype
= bp_catch_catch
;
6359 default: /* error condition */
6360 error (_("Internal error -- invalid catchpoint kind"));
6363 b
= set_raw_breakpoint (*sal
, bptype
);
6364 set_breakpoint_count (breakpoint_count
+ 1);
6365 b
->number
= breakpoint_count
;
6367 b
->cond_string
= (cond_string
== NULL
) ?
6368 NULL
: savestring (cond_string
, strlen (cond_string
));
6370 b
->addr_string
= NULL
;
6371 b
->enable_state
= bp_enabled
;
6372 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6376 static enum print_stop_action
6377 print_exception_catchpoint (struct breakpoint
*b
)
6379 annotate_catchpoint (b
->number
);
6381 if (strstr (b
->addr_string
, "throw") != NULL
)
6382 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6385 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6388 return PRINT_SRC_AND_LOC
;
6392 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6397 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6400 *last_addr
= b
->loc
->address
;
6401 if (strstr (b
->addr_string
, "throw") != NULL
)
6402 ui_out_field_string (uiout
, "what", "exception throw");
6404 ui_out_field_string (uiout
, "what", "exception catch");
6408 print_mention_exception_catchpoint (struct breakpoint
*b
)
6410 if (strstr (b
->addr_string
, "throw") != NULL
)
6411 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6413 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6416 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6417 print_exception_catchpoint
,
6418 print_one_exception_catchpoint
,
6419 print_mention_exception_catchpoint
6423 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6424 enum exception_event_kind ex_event
, int from_tty
)
6426 char *trigger_func_name
, *nameptr
;
6427 struct symtabs_and_lines sals
;
6428 struct breakpoint
*b
;
6430 if (ex_event
== EX_EVENT_CATCH
)
6431 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6433 trigger_func_name
= xstrdup ("__cxa_throw");
6435 nameptr
= trigger_func_name
;
6436 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6437 if (sals
.nelts
== 0)
6439 xfree (trigger_func_name
);
6443 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6444 set_breakpoint_count (breakpoint_count
+ 1);
6445 b
->number
= breakpoint_count
;
6447 b
->cond_string
= (cond_string
== NULL
) ?
6448 NULL
: savestring (cond_string
, strlen (cond_string
));
6450 b
->addr_string
= trigger_func_name
;
6451 b
->enable_state
= bp_enabled
;
6452 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6453 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6460 /* Deal with "catch catch" and "catch throw" commands */
6463 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6464 int tempflag
, int from_tty
)
6466 char *cond_string
= NULL
;
6467 struct symtab_and_line
*sal
= NULL
;
6469 ep_skip_leading_whitespace (&arg
);
6471 cond_string
= ep_parse_optional_if_clause (&arg
);
6473 if ((*arg
!= '\0') && !isspace (*arg
))
6474 error (_("Junk at end of arguments."));
6476 if ((ex_event
!= EX_EVENT_THROW
) &&
6477 (ex_event
!= EX_EVENT_CATCH
))
6478 error (_("Unsupported or unknown exception event; cannot catch it"));
6480 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6483 /* See if we can find a callback routine */
6484 sal
= target_enable_exception_callback (ex_event
, 1);
6488 /* We have callbacks from the runtime system for exceptions.
6489 Set a breakpoint on the sal found, if no errors */
6490 if (sal
!= (struct symtab_and_line
*) -1)
6491 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6493 return; /* something went wrong with setting up callbacks */
6496 warning (_("Unsupported with this platform/compiler combination."));
6499 /* Create a breakpoint struct for Ada exception catchpoints. */
6502 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6506 struct expression
*cond
,
6507 struct breakpoint_ops
*ops
,
6511 struct breakpoint
*b
;
6515 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6516 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6517 version for exception catchpoints, because two catchpoints
6518 used for different exception names will use the same address.
6519 In this case, a "breakpoint ... also set at..." warning is
6520 unproductive. Besides. the warning phrasing is also a bit
6521 inapropriate, we should use the word catchpoint, and tell
6522 the user what type of catchpoint it is. The above is good
6523 enough for now, though. */
6526 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6527 set_breakpoint_count (breakpoint_count
+ 1);
6529 b
->enable_state
= bp_enabled
;
6530 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6531 b
->number
= breakpoint_count
;
6532 b
->ignore_count
= 0;
6534 b
->addr_string
= addr_string
;
6535 b
->language
= language_ada
;
6536 b
->cond_string
= cond_string
;
6537 b
->exp_string
= exp_string
;
6540 b
->from_tty
= from_tty
;
6545 /* Implement the "catch exception" command. */
6548 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6550 struct symtab_and_line sal
;
6552 char *addr_string
= NULL
;
6553 char *exp_string
= NULL
;
6554 char *cond_string
= NULL
;
6555 struct expression
*cond
= NULL
;
6556 struct breakpoint_ops
*ops
= NULL
;
6558 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6559 &cond_string
, &cond
, &ops
);
6560 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6561 cond_string
, cond
, ops
, tempflag
,
6565 /* Implement the "catch assert" command. */
6568 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6570 struct symtab_and_line sal
;
6571 char *addr_string
= NULL
;
6572 struct breakpoint_ops
*ops
= NULL
;
6574 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6575 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6576 tempflag
, from_tty
);
6579 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6580 inside a catch_errors */
6583 cover_target_enable_exception_callback (void *arg
)
6585 args_for_catchpoint_enable
*args
= arg
;
6586 struct symtab_and_line
*sal
;
6587 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6590 else if (sal
== (struct symtab_and_line
*) -1)
6593 return 1; /*is valid */
6597 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6600 /* The first argument may be an event name, such as "start" or "load".
6601 If so, then handle it as such. If it doesn't match an event name,
6602 then attempt to interpret it as an exception name. (This latter is
6603 the v4.16-and-earlier GDB meaning of the "catch" command.)
6605 First, try to find the bounds of what might be an event name. */
6606 char *arg1_start
= arg
;
6610 if (arg1_start
== NULL
)
6612 /* Old behaviour was to use pre-v-4.16 syntax */
6613 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6615 /* Now, this is not allowed */
6616 error (_("Catch requires an event name."));
6619 arg1_end
= ep_find_event_name_end (arg1_start
);
6620 if (arg1_end
== NULL
)
6621 error (_("catch requires an event"));
6622 arg1_length
= arg1_end
+ 1 - arg1_start
;
6624 /* Try to match what we found against known event names. */
6625 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6627 error (_("Catch of signal not yet implemented"));
6629 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6631 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6632 tempflag
, from_tty
);
6634 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6636 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6637 tempflag
, from_tty
);
6639 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6641 error (_("Catch of thread_start not yet implemented"));
6643 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6645 error (_("Catch of thread_exit not yet implemented"));
6647 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6649 error (_("Catch of thread_join not yet implemented"));
6651 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6653 error (_("Catch of start not yet implemented"));
6655 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6657 error (_("Catch of exit not yet implemented"));
6659 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6661 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6663 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6665 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6667 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6669 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6671 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6673 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6675 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6677 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6679 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6681 error (_("Catch of stop not yet implemented"));
6683 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6685 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6688 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6690 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6693 /* This doesn't appear to be an event name */
6697 /* Pre-v.4.16 behaviour was to treat the argument
6698 as the name of an exception */
6699 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6700 /* Now this is not allowed */
6701 error (_("Unknown event kind specified for catch"));
6706 /* Used by the gui, could be made a worker for other things. */
6709 set_breakpoint_sal (struct symtab_and_line sal
)
6711 struct breakpoint
*b
;
6712 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6713 set_breakpoint_count (breakpoint_count
+ 1);
6714 b
->number
= breakpoint_count
;
6721 catch_command (char *arg
, int from_tty
)
6723 catch_command_1 (arg
, 0, from_tty
);
6728 tcatch_command (char *arg
, int from_tty
)
6730 catch_command_1 (arg
, 1, from_tty
);
6733 /* Delete breakpoints by address or line. */
6736 clear_command (char *arg
, int from_tty
)
6738 struct breakpoint
*b
, *tmp
, *prev
, *found
;
6740 struct symtabs_and_lines sals
;
6741 struct symtab_and_line sal
;
6746 sals
= decode_line_spec (arg
, 1);
6751 sals
.sals
= (struct symtab_and_line
*)
6752 xmalloc (sizeof (struct symtab_and_line
));
6753 make_cleanup (xfree
, sals
.sals
);
6754 init_sal (&sal
); /* initialize to zeroes */
6755 sal
.line
= default_breakpoint_line
;
6756 sal
.symtab
= default_breakpoint_symtab
;
6757 sal
.pc
= default_breakpoint_address
;
6758 if (sal
.symtab
== 0)
6759 error (_("No source file specified."));
6767 /* For each line spec given, delete bps which correspond
6768 to it. Do it in two passes, solely to preserve the current
6769 behavior that from_tty is forced true if we delete more than
6773 for (i
= 0; i
< sals
.nelts
; i
++)
6775 /* If exact pc given, clear bpts at that pc.
6776 If line given (pc == 0), clear all bpts on specified line.
6777 If defaulting, clear all bpts on default line
6780 defaulting sal.pc != 0 tests to do
6785 1 0 <can't happen> */
6790 /* Find all matching breakpoints, remove them from the
6791 breakpoint chain, and add them to the 'found' chain. */
6792 ALL_BREAKPOINTS_SAFE (b
, tmp
)
6794 /* Are we going to delete b? */
6795 if (b
->type
!= bp_none
6796 && b
->type
!= bp_watchpoint
6797 && b
->type
!= bp_hardware_watchpoint
6798 && b
->type
!= bp_read_watchpoint
6799 && b
->type
!= bp_access_watchpoint
6800 /* Not if b is a watchpoint of any sort... */
6801 && (((sal
.pc
&& (b
->loc
->address
== sal
.pc
))
6802 && (!section_is_overlay (b
->loc
->section
)
6803 || b
->loc
->section
== sal
.section
))
6804 /* Yes, if sal.pc matches b (modulo overlays). */
6805 || ((default_match
|| (0 == sal
.pc
))
6806 && b
->source_file
!= NULL
6807 && sal
.symtab
!= NULL
6808 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6809 && b
->line_number
== sal
.line
)))
6810 /* Yes, if sal source file and line matches b. */
6812 /* Remove it from breakpoint_chain... */
6813 if (b
== breakpoint_chain
)
6815 /* b is at the head of the list */
6816 breakpoint_chain
= b
->next
;
6820 prev
->next
= b
->next
;
6822 /* And add it to 'found' chain. */
6828 /* Keep b, and keep a pointer to it. */
6833 /* Now go thru the 'found' chain and delete them. */
6837 error (_("No breakpoint at %s."), arg
);
6839 error (_("No breakpoint at this line."));
6843 from_tty
= 1; /* Always report if deleted more than one */
6847 printf_unfiltered (_("Deleted breakpoint "));
6849 printf_unfiltered (_("Deleted breakpoints "));
6851 breakpoints_changed ();
6855 printf_unfiltered ("%d ", found
->number
);
6857 delete_breakpoint (found
);
6861 putchar_unfiltered ('\n');
6864 /* Delete breakpoint in BS if they are `delete' breakpoints and
6865 all breakpoints that are marked for deletion, whether hit or not.
6866 This is called after any breakpoint is hit, or after errors. */
6869 breakpoint_auto_delete (bpstat bs
)
6871 struct breakpoint
*b
, *temp
;
6873 for (; bs
; bs
= bs
->next
)
6874 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== disp_del
6876 delete_breakpoint (bs
->breakpoint_at
);
6878 ALL_BREAKPOINTS_SAFE (b
, temp
)
6880 if (b
->disposition
== disp_del_at_next_stop
)
6881 delete_breakpoint (b
);
6885 /* Delete a breakpoint and clean up all traces of it in the data
6889 delete_breakpoint (struct breakpoint
*bpt
)
6891 struct breakpoint
*b
;
6893 struct bp_location
*loc
;
6895 gdb_assert (bpt
!= NULL
);
6897 /* Has this bp already been deleted? This can happen because multiple
6898 lists can hold pointers to bp's. bpstat lists are especial culprits.
6900 One example of this happening is a watchpoint's scope bp. When the
6901 scope bp triggers, we notice that the watchpoint is out of scope, and
6902 delete it. We also delete its scope bp. But the scope bp is marked
6903 "auto-deleting", and is already on a bpstat. That bpstat is then
6904 checked for auto-deleting bp's, which are deleted.
6906 A real solution to this problem might involve reference counts in bp's,
6907 and/or giving them pointers back to their referencing bpstat's, and
6908 teaching delete_breakpoint to only free a bp's storage when no more
6909 references were extent. A cheaper bandaid was chosen. */
6910 if (bpt
->type
== bp_none
)
6913 if (deprecated_delete_breakpoint_hook
)
6914 deprecated_delete_breakpoint_hook (bpt
);
6915 breakpoint_delete_event (bpt
->number
);
6917 if (bpt
->loc
->inserted
)
6918 remove_breakpoint (bpt
->loc
, mark_inserted
);
6920 free_valchain (bpt
->loc
);
6922 if (breakpoint_chain
== bpt
)
6923 breakpoint_chain
= bpt
->next
;
6925 if (bp_location_chain
== bpt
->loc
)
6926 bp_location_chain
= bpt
->loc
->next
;
6928 /* If we have callback-style exception catchpoints, don't go through
6929 the adjustments to the C++ runtime library etc. if the inferior
6930 isn't actually running. target_enable_exception_callback for a
6931 null target ops vector gives an undesirable error message, so we
6932 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6933 exceptions are supported in this way, it's OK for now. FIXME */
6934 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
6936 /* Format possible error msg */
6937 char *message
= xstrprintf ("Error in deleting catchpoint %d:\n",
6939 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
6940 args_for_catchpoint_enable args
;
6941 args
.kind
= bpt
->type
== bp_catch_catch
?
6942 EX_EVENT_CATCH
: EX_EVENT_THROW
;
6944 catch_errors (cover_target_enable_exception_callback
, &args
,
6945 message
, RETURN_MASK_ALL
);
6946 do_cleanups (cleanups
);
6953 b
->next
= bpt
->next
;
6957 ALL_BP_LOCATIONS (loc
)
6958 if (loc
->next
== bpt
->loc
)
6960 loc
->next
= bpt
->loc
->next
;
6964 check_duplicates (bpt
);
6965 /* If this breakpoint was inserted, and there is another breakpoint
6966 at the same address, we need to insert the other breakpoint. */
6967 if (bpt
->loc
->inserted
6968 && bpt
->type
!= bp_hardware_watchpoint
6969 && bpt
->type
!= bp_read_watchpoint
6970 && bpt
->type
!= bp_access_watchpoint
6971 && bpt
->type
!= bp_catch_fork
6972 && bpt
->type
!= bp_catch_vfork
6973 && bpt
->type
!= bp_catch_exec
)
6976 if (b
->loc
->address
== bpt
->loc
->address
6977 && b
->loc
->section
== bpt
->loc
->section
6978 && !b
->loc
->duplicate
6979 && b
->enable_state
!= bp_disabled
6980 && b
->enable_state
!= bp_shlib_disabled
6982 && b
->enable_state
!= bp_call_disabled
)
6986 /* We should never reach this point if there is a permanent
6987 breakpoint at the same address as the one being deleted.
6988 If there is a permanent breakpoint somewhere, it should
6989 always be the only one inserted. */
6990 if (b
->enable_state
== bp_permanent
)
6991 internal_error (__FILE__
, __LINE__
,
6992 _("another breakpoint was inserted on top of "
6993 "a permanent breakpoint"));
6995 memset (&b
->loc
->target_info
, 0, sizeof (b
->loc
->target_info
));
6996 b
->loc
->target_info
.placed_address
= b
->loc
->address
;
6997 if (b
->type
== bp_hardware_breakpoint
)
6998 val
= target_insert_hw_breakpoint (&b
->loc
->target_info
);
7000 val
= target_insert_breakpoint (&b
->loc
->target_info
);
7002 /* If there was an error in the insert, print a message, then stop execution. */
7005 struct ui_file
*tmp_error_stream
= mem_fileopen ();
7006 make_cleanup_ui_file_delete (tmp_error_stream
);
7009 if (b
->type
== bp_hardware_breakpoint
)
7011 fprintf_unfiltered (tmp_error_stream
,
7012 "Cannot insert hardware breakpoint %d.\n"
7013 "You may have requested too many hardware breakpoints.\n",
7018 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
7019 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
7020 deprecated_print_address_numeric (b
->loc
->address
, 1, tmp_error_stream
);
7021 fprintf_filtered (tmp_error_stream
, ": %s.\n",
7022 safe_strerror (val
));
7025 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
7026 target_terminal_ours_for_output ();
7027 error_stream(tmp_error_stream
);
7030 b
->loc
->inserted
= 1;
7034 free_command_lines (&bpt
->commands
);
7037 if (bpt
->cond_string
!= NULL
)
7038 xfree (bpt
->cond_string
);
7039 if (bpt
->addr_string
!= NULL
)
7040 xfree (bpt
->addr_string
);
7041 if (bpt
->exp
!= NULL
)
7043 if (bpt
->exp_string
!= NULL
)
7044 xfree (bpt
->exp_string
);
7045 if (bpt
->val
!= NULL
)
7046 value_free (bpt
->val
);
7047 if (bpt
->source_file
!= NULL
)
7048 xfree (bpt
->source_file
);
7049 if (bpt
->dll_pathname
!= NULL
)
7050 xfree (bpt
->dll_pathname
);
7051 if (bpt
->triggered_dll_pathname
!= NULL
)
7052 xfree (bpt
->triggered_dll_pathname
);
7053 if (bpt
->exec_pathname
!= NULL
)
7054 xfree (bpt
->exec_pathname
);
7056 /* Be sure no bpstat's are pointing at it after it's been freed. */
7057 /* FIXME, how can we find all bpstat's?
7058 We just check stop_bpstat for now. Note that we cannot just
7059 remove bpstats pointing at bpt from the stop_bpstat list
7060 entirely, as breakpoint commands are associated with the bpstat;
7061 if we remove it here, then the later call to
7062 bpstat_do_actions (&stop_bpstat);
7063 in event-top.c won't do anything, and temporary breakpoints
7064 with commands won't work. */
7065 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
7066 if (bs
->breakpoint_at
== bpt
)
7068 bs
->breakpoint_at
= NULL
;
7070 /* bs->commands will be freed later. */
7072 /* On the chance that someone will soon try again to delete this same
7073 bp, we mark it as deleted before freeing its storage. */
7074 bpt
->type
= bp_none
;
7081 do_delete_breakpoint_cleanup (void *b
)
7083 delete_breakpoint (b
);
7087 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7089 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7093 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
7095 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
7099 delete_command (char *arg
, int from_tty
)
7101 struct breakpoint
*b
, *temp
;
7107 int breaks_to_delete
= 0;
7109 /* Delete all breakpoints if no argument.
7110 Do not delete internal or call-dummy breakpoints, these
7111 have to be deleted with an explicit breakpoint number argument. */
7114 if (b
->type
!= bp_call_dummy
&&
7115 b
->type
!= bp_shlib_event
&&
7116 b
->type
!= bp_thread_event
&&
7117 b
->type
!= bp_overlay_event
&&
7120 breaks_to_delete
= 1;
7125 /* Ask user only if there are some breakpoints to delete. */
7127 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7129 ALL_BREAKPOINTS_SAFE (b
, temp
)
7131 if (b
->type
!= bp_call_dummy
&&
7132 b
->type
!= bp_shlib_event
&&
7133 b
->type
!= bp_thread_event
&&
7134 b
->type
!= bp_overlay_event
&&
7136 delete_breakpoint (b
);
7141 map_breakpoint_numbers (arg
, delete_breakpoint
);
7144 /* Reset a breakpoint given it's struct breakpoint * BINT.
7145 The value we return ends up being the return value from catch_errors.
7146 Unused in this case. */
7149 breakpoint_re_set_one (void *bint
)
7151 /* get past catch_errs */
7152 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7156 int *not_found_ptr
= NULL
;
7157 struct symtabs_and_lines sals
;
7159 enum enable_state save_enable
;
7164 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7168 case bp_hardware_breakpoint
:
7170 case bp_catch_unload
:
7171 if (b
->addr_string
== NULL
)
7173 /* Anything without a string can't be re-set. */
7174 delete_breakpoint (b
);
7177 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
7179 ``And a hack it is, although Apple's Darwin version of GDB
7180 contains an almost identical hack to implement a "future
7181 break" command. It seems to work in many real world cases,
7182 but it is easy to come up with a test case where the patch
7183 doesn't help at all.''
7185 ``It seems that the way GDB implements breakpoints - in -
7186 shared - libraries was designed for a.out shared library
7187 systems (SunOS 4) where shared libraries were loaded at a
7188 fixed address in memory. Since ELF shared libraries can (and
7189 will) be loaded at any address in memory, things break.
7190 Fixing this is not trivial. Therefore, I'm not sure whether
7191 we should add this hack to the branch only. I cannot
7192 guarantee that things will be fixed on the trunk in the near
7195 In case we have a problem, disable this breakpoint. We'll
7196 restore its status if we succeed. Don't disable a
7197 shlib_disabled breakpoint though. There's a fair chance we
7198 can't re-set it if the shared library it's in hasn't been
7204 save_enable
= b
->enable_state
;
7205 if (b
->enable_state
!= bp_shlib_disabled
)
7206 b
->enable_state
= bp_disabled
;
7208 /* If resetting a shlib-disabled breakpoint, we don't want to
7209 see an error message if it is not found since we will expect
7210 this to occur until the shared library is finally reloaded.
7211 We accomplish this by giving decode_line_1 a pointer to use
7212 for silent notification that the symbol is not found. */
7213 not_found_ptr
= ¬_found
;
7215 set_language (b
->language
);
7216 input_radix
= b
->input_radix
;
7218 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7220 for (i
= 0; i
< sals
.nelts
; i
++)
7222 resolve_sal_pc (&sals
.sals
[i
]);
7224 /* Reparse conditions, they might contain references to the
7226 if (b
->cond_string
!= NULL
)
7232 /* Avoid re-freeing b->exp if an error during the call
7236 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
7239 /* We need to re-set the breakpoint if the address changes... */
7240 if (b
->loc
->address
!= sals
.sals
[i
].pc
7241 /* ...or new and old breakpoints both have source files, and
7242 the source file name or the line number changes... */
7243 || (b
->source_file
!= NULL
7244 && sals
.sals
[i
].symtab
!= NULL
7245 && (strcmp (b
->source_file
, sals
.sals
[i
].symtab
->filename
) != 0
7246 || b
->line_number
!= sals
.sals
[i
].line
)
7248 /* ...or we switch between having a source file and not having
7250 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
7253 if (b
->source_file
!= NULL
)
7254 xfree (b
->source_file
);
7255 if (sals
.sals
[i
].symtab
== NULL
)
7256 b
->source_file
= NULL
;
7259 savestring (sals
.sals
[i
].symtab
->filename
,
7260 strlen (sals
.sals
[i
].symtab
->filename
));
7261 b
->line_number
= sals
.sals
[i
].line
;
7262 b
->loc
->requested_address
= sals
.sals
[i
].pc
;
7264 = adjust_breakpoint_address (b
->loc
->requested_address
,
7267 /* Used to check for duplicates here, but that can
7268 cause trouble, as it doesn't check for disabled
7273 /* Might be better to do this just once per breakpoint_re_set,
7274 rather than once for every breakpoint. */
7275 breakpoints_changed ();
7277 b
->loc
->section
= sals
.sals
[i
].section
;
7278 b
->enable_state
= save_enable
; /* Restore it, this worked. */
7281 /* Now that this is re-enabled, check_duplicates
7283 check_duplicates (b
);
7290 case bp_hardware_watchpoint
:
7291 case bp_read_watchpoint
:
7292 case bp_access_watchpoint
:
7293 innermost_block
= NULL
;
7294 /* The issue arises of what context to evaluate this in. The
7295 same one as when it was set, but what does that mean when
7296 symbols have been re-read? We could save the filename and
7297 functionname, but if the context is more local than that, the
7298 best we could do would be something like how many levels deep
7299 and which index at that particular level, but that's going to
7300 be less stable than filenames or function names. */
7302 /* So for now, just use a global context. */
7306 /* Avoid re-freeing b->exp if an error during the call to
7307 parse_expression. */
7310 b
->exp
= parse_expression (b
->exp_string
);
7311 b
->exp_valid_block
= innermost_block
;
7312 mark
= value_mark ();
7315 value_free (b
->val
);
7316 /* Avoid re-freeing b->val if an error during the call to
7317 evaluate_expression. */
7320 b
->val
= evaluate_expression (b
->exp
);
7321 release_value (b
->val
);
7322 if (value_lazy (b
->val
) && breakpoint_enabled (b
))
7323 value_fetch_lazy (b
->val
);
7325 if (b
->cond_string
!= NULL
)
7331 /* Avoid re-freeing b->exp if an error during the call
7335 b
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
7337 if (breakpoint_enabled (b
))
7339 value_free_to_mark (mark
);
7341 case bp_catch_catch
:
7342 case bp_catch_throw
:
7344 /* We needn't really do anything to reset these, since the mask
7345 that requests them is unaffected by e.g., new libraries being
7348 case bp_catch_vfork
:
7353 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7355 /* Delete longjmp and overlay event breakpoints; they will be
7356 reset later by breakpoint_re_set. */
7358 case bp_longjmp_resume
:
7359 case bp_overlay_event
:
7360 delete_breakpoint (b
);
7363 /* This breakpoint is special, it's set up when the inferior
7364 starts and we really don't want to touch it. */
7365 case bp_shlib_event
:
7367 /* Like bp_shlib_event, this breakpoint type is special.
7368 Once it is set up, we do not want to touch it. */
7369 case bp_thread_event
:
7371 /* Keep temporary breakpoints, which can be encountered when we step
7372 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7373 Otherwise these should have been blown away via the cleanup chain
7374 or by breakpoint_init_inferior when we rerun the executable. */
7377 case bp_watchpoint_scope
:
7379 case bp_step_resume
:
7386 /* Re-set all breakpoints after symbols have been re-loaded. */
7388 breakpoint_re_set (void)
7390 struct breakpoint
*b
, *temp
;
7391 enum language save_language
;
7392 int save_input_radix
;
7394 save_language
= current_language
->la_language
;
7395 save_input_radix
= input_radix
;
7396 ALL_BREAKPOINTS_SAFE (b
, temp
)
7398 /* Format possible error msg */
7399 char *message
= xstrprintf ("Error in re-setting breakpoint %d:\n",
7401 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7402 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7403 do_cleanups (cleanups
);
7405 set_language (save_language
);
7406 input_radix
= save_input_radix
;
7408 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
7410 create_longjmp_breakpoint ("longjmp");
7411 create_longjmp_breakpoint ("_longjmp");
7412 create_longjmp_breakpoint ("siglongjmp");
7413 create_longjmp_breakpoint ("_siglongjmp");
7414 create_longjmp_breakpoint (NULL
);
7417 create_overlay_event_breakpoint ("_ovly_debug_event");
7420 /* Reset the thread number of this breakpoint:
7422 - If the breakpoint is for all threads, leave it as-is.
7423 - Else, reset it to the current thread for inferior_ptid. */
7425 breakpoint_re_set_thread (struct breakpoint
*b
)
7427 if (b
->thread
!= -1)
7429 if (in_thread_list (inferior_ptid
))
7430 b
->thread
= pid_to_thread_id (inferior_ptid
);
7434 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7435 If from_tty is nonzero, it prints a message to that effect,
7436 which ends with a period (no newline). */
7439 set_ignore_count (int bptnum
, int count
, int from_tty
)
7441 struct breakpoint
*b
;
7447 if (b
->number
== bptnum
)
7449 b
->ignore_count
= count
;
7453 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7455 else if (count
== 1)
7456 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7459 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7462 breakpoints_changed ();
7463 breakpoint_modify_event (b
->number
);
7467 error (_("No breakpoint number %d."), bptnum
);
7470 /* Clear the ignore counts of all breakpoints. */
7472 breakpoint_clear_ignore_counts (void)
7474 struct breakpoint
*b
;
7477 b
->ignore_count
= 0;
7480 /* Command to set ignore-count of breakpoint N to COUNT. */
7483 ignore_command (char *args
, int from_tty
)
7489 error_no_arg (_("a breakpoint number"));
7491 num
= get_number (&p
);
7493 error (_("bad breakpoint number: '%s'"), args
);
7495 error (_("Second argument (specified ignore-count) is missing."));
7497 set_ignore_count (num
,
7498 longest_to_int (value_as_long (parse_and_eval (p
))),
7501 printf_filtered ("\n");
7504 /* Call FUNCTION on each of the breakpoints
7505 whose numbers are given in ARGS. */
7508 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7513 struct breakpoint
*b
, *tmp
;
7517 error_no_arg (_("one or more breakpoint numbers"));
7524 num
= get_number_or_range (&p1
);
7527 warning (_("bad breakpoint number at or near '%s'"), p
);
7531 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7532 if (b
->number
== num
)
7534 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7537 if (related_breakpoint
)
7538 function (related_breakpoint
);
7542 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7548 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7549 If from_tty is nonzero, it prints a message to that effect,
7550 which ends with a period (no newline). */
7553 disable_breakpoint (struct breakpoint
*bpt
)
7555 /* Never disable a watchpoint scope breakpoint; we want to
7556 hit them when we leave scope so we can delete both the
7557 watchpoint and its scope breakpoint at that time. */
7558 if (bpt
->type
== bp_watchpoint_scope
)
7561 /* You can't disable permanent breakpoints. */
7562 if (bpt
->enable_state
== bp_permanent
)
7565 bpt
->enable_state
= bp_disabled
;
7567 check_duplicates (bpt
);
7569 if (deprecated_modify_breakpoint_hook
)
7570 deprecated_modify_breakpoint_hook (bpt
);
7571 breakpoint_modify_event (bpt
->number
);
7575 disable_command (char *args
, int from_tty
)
7577 struct breakpoint
*bpt
;
7579 ALL_BREAKPOINTS (bpt
)
7583 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7588 case bp_catch_unload
:
7590 case bp_catch_vfork
:
7592 case bp_catch_catch
:
7593 case bp_catch_throw
:
7594 case bp_hardware_breakpoint
:
7596 case bp_hardware_watchpoint
:
7597 case bp_read_watchpoint
:
7598 case bp_access_watchpoint
:
7599 disable_breakpoint (bpt
);
7604 map_breakpoint_numbers (args
, disable_breakpoint
);
7608 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7610 int target_resources_ok
, other_type_used
;
7613 if (bpt
->type
== bp_hardware_breakpoint
)
7616 i
= hw_breakpoint_used_count ();
7617 target_resources_ok
=
7618 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7620 if (target_resources_ok
== 0)
7621 error (_("No hardware breakpoint support in the target."));
7622 else if (target_resources_ok
< 0)
7623 error (_("Hardware breakpoints used exceeds limit."));
7628 if (bpt
->enable_state
!= bp_enabled
)
7630 /* When enabling a pending breakpoint, we need to check if the breakpoint
7631 is resolvable since shared libraries could have been loaded
7632 after the breakpoint was disabled. */
7633 breakpoints_changed ();
7634 if (resolve_pending_breakpoint (bpt
) == GDB_RC_OK
)
7636 delete_breakpoint (bpt
);
7639 bpt
->enable_state
= bp_enabled
;
7640 bpt
->disposition
= disposition
;
7643 else /* Not a pending breakpoint. */
7645 if (bpt
->enable_state
!= bp_permanent
)
7646 bpt
->enable_state
= bp_enabled
;
7647 bpt
->disposition
= disposition
;
7648 check_duplicates (bpt
);
7649 breakpoints_changed ();
7651 if (bpt
->type
== bp_watchpoint
||
7652 bpt
->type
== bp_hardware_watchpoint
||
7653 bpt
->type
== bp_read_watchpoint
||
7654 bpt
->type
== bp_access_watchpoint
)
7656 struct frame_id saved_frame_id
;
7658 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7659 if (bpt
->exp_valid_block
!= NULL
)
7661 struct frame_info
*fr
=
7662 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7665 printf_filtered (_("\
7666 Cannot enable watchpoint %d because the block in which its expression\n\
7667 is valid is not currently in scope.\n"), bpt
->number
);
7668 bpt
->enable_state
= bp_disabled
;
7674 value_free (bpt
->val
);
7675 mark
= value_mark ();
7676 bpt
->val
= evaluate_expression (bpt
->exp
);
7677 release_value (bpt
->val
);
7678 if (value_lazy (bpt
->val
))
7679 value_fetch_lazy (bpt
->val
);
7681 if (bpt
->type
== bp_hardware_watchpoint
||
7682 bpt
->type
== bp_read_watchpoint
||
7683 bpt
->type
== bp_access_watchpoint
)
7685 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7686 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7688 /* Hack around 'unused var' error for some targets here */
7689 (void) mem_cnt
, (void) i
;
7690 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7691 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7692 /* we can consider of type is bp_hardware_watchpoint, convert to
7693 bp_watchpoint in the following condition */
7694 if (target_resources_ok
< 0)
7696 printf_filtered (_("\
7697 Cannot enable watchpoint %d because target watch resources\n\
7698 have been allocated for other watchpoints.\n"), bpt
->number
);
7699 bpt
->enable_state
= bp_disabled
;
7700 value_free_to_mark (mark
);
7705 select_frame (frame_find_by_id (saved_frame_id
));
7706 value_free_to_mark (mark
);
7710 if (deprecated_modify_breakpoint_hook
)
7711 deprecated_modify_breakpoint_hook (bpt
);
7712 breakpoint_modify_event (bpt
->number
);
7716 enable_breakpoint (struct breakpoint
*bpt
)
7718 do_enable_breakpoint (bpt
, bpt
->disposition
);
7721 /* The enable command enables the specified breakpoints (or all defined
7722 breakpoints) so they once again become (or continue to be) effective
7723 in stopping the inferior. */
7726 enable_command (char *args
, int from_tty
)
7728 struct breakpoint
*bpt
;
7730 ALL_BREAKPOINTS (bpt
)
7734 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7739 case bp_catch_unload
:
7741 case bp_catch_vfork
:
7743 case bp_catch_catch
:
7744 case bp_catch_throw
:
7745 case bp_hardware_breakpoint
:
7747 case bp_hardware_watchpoint
:
7748 case bp_read_watchpoint
:
7749 case bp_access_watchpoint
:
7750 enable_breakpoint (bpt
);
7755 map_breakpoint_numbers (args
, enable_breakpoint
);
7759 enable_once_breakpoint (struct breakpoint
*bpt
)
7761 do_enable_breakpoint (bpt
, disp_disable
);
7765 enable_once_command (char *args
, int from_tty
)
7767 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7771 enable_delete_breakpoint (struct breakpoint
*bpt
)
7773 do_enable_breakpoint (bpt
, disp_del
);
7777 enable_delete_command (char *args
, int from_tty
)
7779 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7783 set_breakpoint_cmd (char *args
, int from_tty
)
7788 show_breakpoint_cmd (char *args
, int from_tty
)
7792 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7794 struct symtabs_and_lines
7795 decode_line_spec_1 (char *string
, int funfirstline
)
7797 struct symtabs_and_lines sals
;
7799 error (_("Empty line specification."));
7800 if (default_breakpoint_valid
)
7801 sals
= decode_line_1 (&string
, funfirstline
,
7802 default_breakpoint_symtab
,
7803 default_breakpoint_line
,
7804 (char ***) NULL
, NULL
);
7806 sals
= decode_line_1 (&string
, funfirstline
,
7807 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7809 error (_("Junk at end of line specification: %s"), string
);
7813 /* Create and insert a raw software breakpoint at PC. Return an
7814 identifier, which should be used to remove the breakpoint later.
7815 In general, places which call this should be using something on the
7816 breakpoint chain instead; this function should be eliminated
7820 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7822 struct bp_target_info
*bp_tgt
;
7824 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7825 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7827 bp_tgt
->placed_address
= pc
;
7828 if (target_insert_breakpoint (bp_tgt
) != 0)
7830 /* Could not insert the breakpoint. */
7838 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7841 deprecated_remove_raw_breakpoint (void *bp
)
7843 struct bp_target_info
*bp_tgt
= bp
;
7846 ret
= target_remove_breakpoint (bp_tgt
);
7852 /* One (or perhaps two) breakpoints used for software single stepping. */
7854 static void *single_step_breakpoints
[2];
7856 /* Create and insert a breakpoint for software single step. */
7859 insert_single_step_breakpoint (CORE_ADDR next_pc
)
7863 if (single_step_breakpoints
[0] == NULL
)
7864 bpt_p
= &single_step_breakpoints
[0];
7867 gdb_assert (single_step_breakpoints
[1] == NULL
);
7868 bpt_p
= &single_step_breakpoints
[1];
7871 /* NOTE drow/2006-04-11: A future improvement to this function would be
7872 to only create the breakpoints once, and actually put them on the
7873 breakpoint chain. That would let us use set_raw_breakpoint. We could
7874 adjust the addresses each time they were needed. Doing this requires
7875 corresponding changes elsewhere where single step breakpoints are
7876 handled, however. So, for now, we use this. */
7878 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
7880 error (_("Could not insert single-step breakpoint at 0x%s"),
7881 paddr_nz (next_pc
));
7884 /* Remove and delete any breakpoints used for software single step. */
7887 remove_single_step_breakpoints (void)
7889 gdb_assert (single_step_breakpoints
[0] != NULL
);
7891 /* See insert_single_step_breakpoint for more about this deprecated
7893 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
7894 single_step_breakpoints
[0] = NULL
;
7896 if (single_step_breakpoints
[1] != NULL
)
7898 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
7899 single_step_breakpoints
[1] = NULL
;
7903 /* Check whether a software single-step breakpoint is inserted at PC. */
7906 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
7910 for (i
= 0; i
< 2; i
++)
7912 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
7913 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
7921 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
7922 It is defined as a macro to prevent duplication.
7923 COMMAND should be a string constant containing the name of the command. */
7924 #define BREAK_ARGS_HELP(command) \
7925 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
7926 LOCATION may be a line number, function name, or \"*\" and an address.\n\
7927 If a line number is specified, break at start of code for that line.\n\
7928 If a function is specified, break at start of code for that function.\n\
7929 If an address is specified, break at that exact address.\n\
7930 With no LOCATION, uses current execution address of selected stack frame.\n\
7931 This is useful for breaking on return to a stack frame.\n\
7933 THREADNUM is the number from \"info threads\".\n\
7934 CONDITION is a boolean expression.\n\
7936 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7938 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
7941 _initialize_breakpoint (void)
7943 static struct cmd_list_element
*breakpoint_set_cmdlist
;
7944 static struct cmd_list_element
*breakpoint_show_cmdlist
;
7945 struct cmd_list_element
*c
;
7947 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
7949 breakpoint_chain
= 0;
7950 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7951 before a breakpoint is set. */
7952 breakpoint_count
= 0;
7954 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
7955 Set ignore-count of breakpoint number N to COUNT.\n\
7956 Usage is `ignore N COUNT'."));
7958 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7960 add_com ("commands", class_breakpoint
, commands_command
, _("\
7961 Set commands to be executed when a breakpoint is hit.\n\
7962 Give breakpoint number as argument after \"commands\".\n\
7963 With no argument, the targeted breakpoint is the last one set.\n\
7964 The commands themselves follow starting on the next line.\n\
7965 Type a line containing \"end\" to indicate the end of them.\n\
7966 Give \"silent\" as the first line to make the breakpoint silent;\n\
7967 then no output is printed when it is hit, except what the commands print."));
7969 add_com ("condition", class_breakpoint
, condition_command
, _("\
7970 Specify breakpoint number N to break only if COND is true.\n\
7971 Usage is `condition N COND', where N is an integer and COND is an\n\
7972 expression to be evaluated whenever breakpoint N is reached."));
7974 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
7975 Set a temporary breakpoint.\n\
7976 Like \"break\" except the breakpoint is only temporary,\n\
7977 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7978 by using \"enable delete\" on the breakpoint number.\n\
7980 BREAK_ARGS_HELP ("tbreak")));
7981 set_cmd_completer (c
, location_completer
);
7983 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
7984 Set a hardware assisted breakpoint.\n\
7985 Like \"break\" except the breakpoint requires hardware support,\n\
7986 some target hardware may not have this support.\n\
7988 BREAK_ARGS_HELP ("hbreak")));
7989 set_cmd_completer (c
, location_completer
);
7991 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
7992 Set a temporary hardware assisted breakpoint.\n\
7993 Like \"hbreak\" except the breakpoint is only temporary,\n\
7994 so it will be deleted when hit.\n\
7996 BREAK_ARGS_HELP ("thbreak")));
7997 set_cmd_completer (c
, location_completer
);
7999 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8000 Enable some breakpoints.\n\
8001 Give breakpoint numbers (separated by spaces) as arguments.\n\
8002 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8003 This is used to cancel the effect of the \"disable\" command.\n\
8004 With a subcommand you can enable temporarily."),
8005 &enablelist
, "enable ", 1, &cmdlist
);
8007 add_com ("ab", class_breakpoint
, enable_command
, _("\
8008 Enable some breakpoints.\n\
8009 Give breakpoint numbers (separated by spaces) as arguments.\n\
8010 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8011 This is used to cancel the effect of the \"disable\" command.\n\
8012 With a subcommand you can enable temporarily."));
8014 add_com_alias ("en", "enable", class_breakpoint
, 1);
8016 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8017 Enable some breakpoints.\n\
8018 Give breakpoint numbers (separated by spaces) as arguments.\n\
8019 This is used to cancel the effect of the \"disable\" command.\n\
8020 May be abbreviated to simply \"enable\".\n"),
8021 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8023 add_cmd ("once", no_class
, enable_once_command
, _("\
8024 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8025 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8028 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8029 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8030 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8033 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8034 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8035 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8038 add_cmd ("once", no_class
, enable_once_command
, _("\
8039 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8040 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8043 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8044 Disable some breakpoints.\n\
8045 Arguments are breakpoint numbers with spaces in between.\n\
8046 To disable all breakpoints, give no argument.\n\
8047 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8048 &disablelist
, "disable ", 1, &cmdlist
);
8049 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8050 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8052 add_com ("sb", class_breakpoint
, disable_command
, _("\
8053 Disable some breakpoints.\n\
8054 Arguments are breakpoint numbers with spaces in between.\n\
8055 To disable all breakpoints, give no argument.\n\
8056 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8058 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8059 Disable some breakpoints.\n\
8060 Arguments are breakpoint numbers with spaces in between.\n\
8061 To disable all breakpoints, give no argument.\n\
8062 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8063 This command may be abbreviated \"disable\"."),
8066 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8067 Delete some breakpoints or auto-display expressions.\n\
8068 Arguments are breakpoint numbers with spaces in between.\n\
8069 To delete all breakpoints, give no argument.\n\
8071 Also a prefix command for deletion of other GDB objects.\n\
8072 The \"unset\" command is also an alias for \"delete\"."),
8073 &deletelist
, "delete ", 1, &cmdlist
);
8074 add_com_alias ("d", "delete", class_breakpoint
, 1);
8075 add_com_alias ("del", "delete", class_breakpoint
, 1);
8077 add_com ("db", class_breakpoint
, delete_command
, _("\
8078 Delete some breakpoints.\n\
8079 Arguments are breakpoint numbers with spaces in between.\n\
8080 To delete all breakpoints, give no argument.\n"));
8082 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8083 Delete some breakpoints or auto-display expressions.\n\
8084 Arguments are breakpoint numbers with spaces in between.\n\
8085 To delete all breakpoints, give no argument.\n\
8086 This command may be abbreviated \"delete\"."),
8089 add_com ("clear", class_breakpoint
, clear_command
, _("\
8090 Clear breakpoint at specified line or function.\n\
8091 Argument may be line number, function name, or \"*\" and an address.\n\
8092 If line number is specified, all breakpoints in that line are cleared.\n\
8093 If function is specified, breakpoints at beginning of function are cleared.\n\
8094 If an address is specified, breakpoints at that address are cleared.\n\
8096 With no argument, clears all breakpoints in the line that the selected frame\n\
8099 See also the \"delete\" command which clears breakpoints by number."));
8101 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8102 Set breakpoint at specified line or function.\n"
8103 BREAK_ARGS_HELP ("break")));
8104 set_cmd_completer (c
, location_completer
);
8106 add_com_alias ("b", "break", class_run
, 1);
8107 add_com_alias ("br", "break", class_run
, 1);
8108 add_com_alias ("bre", "break", class_run
, 1);
8109 add_com_alias ("brea", "break", class_run
, 1);
8113 add_com_alias ("ba", "break", class_breakpoint
, 1);
8114 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8119 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8120 Break in function/address or break at a line in the current file."),
8121 &stoplist
, "stop ", 1, &cmdlist
);
8122 add_cmd ("in", class_breakpoint
, stopin_command
,
8123 _("Break in function or address."), &stoplist
);
8124 add_cmd ("at", class_breakpoint
, stopat_command
,
8125 _("Break at a line in the current file."), &stoplist
);
8126 add_com ("status", class_info
, breakpoints_info
, _("\
8127 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8128 The \"Type\" column indicates one of:\n\
8129 \tbreakpoint - normal breakpoint\n\
8130 \twatchpoint - watchpoint\n\
8131 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8132 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8133 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8134 address and file/line number respectively.\n\
8136 Convenience variable \"$_\" and default examine address for \"x\"\n\
8137 are set to the address of the last breakpoint listed unless the command\n\
8138 is prefixed with \"server \".\n\n\
8139 Convenience variable \"$bpnum\" contains the number of the last\n\
8143 add_info ("breakpoints", breakpoints_info
, _("\
8144 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8145 The \"Type\" column indicates one of:\n\
8146 \tbreakpoint - normal breakpoint\n\
8147 \twatchpoint - watchpoint\n\
8148 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8149 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8150 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8151 address and file/line number respectively.\n\
8153 Convenience variable \"$_\" and default examine address for \"x\"\n\
8154 are set to the address of the last breakpoint listed unless the command\n\
8155 is prefixed with \"server \".\n\n\
8156 Convenience variable \"$bpnum\" contains the number of the last\n\
8160 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8161 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8162 The \"Type\" column indicates one of:\n\
8163 \tbreakpoint - normal breakpoint\n\
8164 \twatchpoint - watchpoint\n\
8165 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8166 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8167 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8168 address and file/line number respectively.\n\
8170 Convenience variable \"$_\" and default examine address for \"x\"\n\
8171 are set to the address of the last breakpoint listed unless the command\n\
8172 is prefixed with \"server \".\n\n\
8173 Convenience variable \"$bpnum\" contains the number of the last\n\
8176 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8177 Status of all breakpoints, or breakpoint number NUMBER.\n\
8178 The \"Type\" column indicates one of:\n\
8179 \tbreakpoint - normal breakpoint\n\
8180 \twatchpoint - watchpoint\n\
8181 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8182 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8183 \tuntil - internal breakpoint used by the \"until\" command\n\
8184 \tfinish - internal breakpoint used by the \"finish\" command\n\
8185 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8186 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8187 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8188 address and file/line number respectively.\n\
8190 Convenience variable \"$_\" and default examine address for \"x\"\n\
8191 are set to the address of the last breakpoint listed unless the command\n\
8192 is prefixed with \"server \".\n\n\
8193 Convenience variable \"$bpnum\" contains the number of the last\n\
8195 &maintenanceinfolist
);
8197 add_com ("catch", class_breakpoint
, catch_command
, _("\
8198 Set catchpoints to catch events.\n\
8199 Raised signals may be caught:\n\
8200 \tcatch signal - all signals\n\
8201 \tcatch signal <signame> - a particular signal\n\
8202 Raised exceptions may be caught:\n\
8203 \tcatch throw - all exceptions, when thrown\n\
8204 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8205 \tcatch catch - all exceptions, when caught\n\
8206 \tcatch catch <exceptname> - a particular exception, when caught\n\
8207 Thread or process events may be caught:\n\
8208 \tcatch thread_start - any threads, just after creation\n\
8209 \tcatch thread_exit - any threads, just before expiration\n\
8210 \tcatch thread_join - any threads, just after joins\n\
8211 Process events may be caught:\n\
8212 \tcatch start - any processes, just after creation\n\
8213 \tcatch exit - any processes, just before expiration\n\
8214 \tcatch fork - calls to fork()\n\
8215 \tcatch vfork - calls to vfork()\n\
8216 \tcatch exec - calls to exec()\n\
8217 Dynamically-linked library events may be caught:\n\
8218 \tcatch load - loads of any library\n\
8219 \tcatch load <libname> - loads of a particular library\n\
8220 \tcatch unload - unloads of any library\n\
8221 \tcatch unload <libname> - unloads of a particular library\n\
8222 The act of your program's execution stopping may also be caught:\n\
8224 C++ exceptions may be caught:\n\
8225 \tcatch throw - all exceptions, when thrown\n\
8226 \tcatch catch - all exceptions, when caught\n\
8227 Ada exceptions may be caught:\n\
8228 \tcatch exception - all exceptions, when raised\n\
8229 \tcatch exception <name> - a particular exception, when raised\n\
8230 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8231 \tcatch assert - all failed assertions, when raised\n\
8233 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8234 after a fork or vfork is caught.\n\n\
8235 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8237 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8238 Set temporary catchpoints to catch events.\n\
8239 Args like \"catch\" command.\n\
8240 Like \"catch\" except the catchpoint is only temporary,\n\
8241 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8242 by using \"enable delete\" on the catchpoint number."));
8244 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8245 Set a watchpoint for an expression.\n\
8246 A watchpoint stops execution of your program whenever the value of\n\
8247 an expression changes."));
8248 set_cmd_completer (c
, location_completer
);
8250 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8251 Set a read watchpoint for an expression.\n\
8252 A watchpoint stops execution of your program whenever the value of\n\
8253 an expression is read."));
8254 set_cmd_completer (c
, location_completer
);
8256 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8257 Set a watchpoint for an expression.\n\
8258 A watchpoint stops execution of your program whenever the value of\n\
8259 an expression is either read or written."));
8260 set_cmd_completer (c
, location_completer
);
8262 add_info ("watchpoints", breakpoints_info
,
8263 _("Synonym for ``info breakpoints''."));
8266 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8267 respond to changes - contrary to the description. */
8268 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8269 &can_use_hw_watchpoints
, _("\
8270 Set debugger's willingness to use watchpoint hardware."), _("\
8271 Show debugger's willingness to use watchpoint hardware."), _("\
8272 If zero, gdb will not use hardware for new watchpoints, even if\n\
8273 such is available. (However, any hardware watchpoints that were\n\
8274 created before setting this to nonzero, will continue to use watchpoint\n\
8277 show_can_use_hw_watchpoints
,
8278 &setlist
, &showlist
);
8280 can_use_hw_watchpoints
= 1;
8282 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8283 Breakpoint specific settings\n\
8284 Configure various breakpoint-specific variables such as\n\
8285 pending breakpoint behavior"),
8286 &breakpoint_set_cmdlist
, "set breakpoint ",
8287 0/*allow-unknown*/, &setlist
);
8288 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8289 Breakpoint specific settings\n\
8290 Configure various breakpoint-specific variables such as\n\
8291 pending breakpoint behavior"),
8292 &breakpoint_show_cmdlist
, "show breakpoint ",
8293 0/*allow-unknown*/, &showlist
);
8295 add_setshow_auto_boolean_cmd ("pending", no_class
,
8296 &pending_break_support
, _("\
8297 Set debugger's behavior regarding pending breakpoints."), _("\
8298 Show debugger's behavior regarding pending breakpoints."), _("\
8299 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8300 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8301 an error. If auto, an unrecognized breakpoint location results in a\n\
8302 user-query to see if a pending breakpoint should be created."),
8304 show_pending_break_support
,
8305 &breakpoint_set_cmdlist
,
8306 &breakpoint_show_cmdlist
);
8308 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8310 add_setshow_boolean_cmd ("auto-hw", no_class
,
8311 &automatic_hardware_breakpoints
, _("\
8312 Set automatic usage of hardware breakpoints."), _("\
8313 Show automatic usage of hardware breakpoints."), _("\
8314 If set, the debugger will automatically use hardware breakpoints for\n\
8315 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8316 a warning will be emitted for such breakpoints."),
8318 show_automatic_hardware_breakpoints
,
8319 &breakpoint_set_cmdlist
,
8320 &breakpoint_show_cmdlist
);
8322 automatic_hardware_breakpoints
= 1;