1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "breakpoint.h"
28 #include "expression.h"
34 #include "gdbthread.h"
37 #include "gdb_string.h"
44 #include "completer.h"
47 #include "cli/cli-script.h"
48 #include "gdb_assert.h"
53 #include "exceptions.h"
58 #include "gdb-events.h"
59 #include "mi/mi-common.h"
61 /* Prototypes for local functions. */
63 static void until_break_command_continuation (struct continuation_arg
*arg
);
65 static void catch_command_1 (char *, int, int);
67 static void enable_delete_command (char *, int);
69 static void enable_delete_breakpoint (struct breakpoint
*);
71 static void enable_once_command (char *, int);
73 static void enable_once_breakpoint (struct breakpoint
*);
75 static void disable_command (char *, int);
77 static void enable_command (char *, int);
79 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
81 static void ignore_command (char *, int);
83 static int breakpoint_re_set_one (void *);
85 static void clear_command (char *, int);
87 static void catch_command (char *, int);
89 static void watch_command (char *, int);
91 static int can_use_hardware_watchpoint (struct value
*);
93 static int break_command_1 (char *, int, int);
95 static void mention (struct breakpoint
*);
97 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
99 static void check_duplicates (struct breakpoint
*);
101 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
103 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
106 static void describe_other_breakpoints (CORE_ADDR
, asection
*, int);
108 static void breakpoints_info (char *, int);
110 static void breakpoint_1 (int, int);
112 static bpstat
bpstat_alloc (struct bp_location
*, bpstat
);
114 static int breakpoint_cond_eval (void *);
116 static void cleanup_executing_breakpoints (void *);
118 static void commands_command (char *, int);
120 static void condition_command (char *, int);
122 static int get_number_trailer (char **, int);
124 void set_breakpoint_count (int);
133 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
135 static enum print_stop_action
print_it_typical (bpstat
);
137 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
141 enum exception_event_kind kind
;
144 args_for_catchpoint_enable
;
146 static int watchpoint_check (void *);
148 static int cover_target_enable_exception_callback (void *);
150 static void maintenance_info_breakpoints (char *, int);
152 static void create_longjmp_breakpoint (char *);
154 static void create_overlay_event_breakpoint (char *);
156 static int hw_breakpoint_used_count (void);
158 static int hw_watchpoint_used_count (enum bptype
, int *);
160 static void hbreak_command (char *, int);
162 static void thbreak_command (char *, int);
164 static void watch_command_1 (char *, int, int);
166 static void rwatch_command (char *, int);
168 static void awatch_command (char *, int);
170 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
172 static void create_fork_vfork_event_catchpoint (int tempflag
,
174 enum bptype bp_kind
);
176 static void stop_command (char *arg
, int from_tty
);
178 static void stopin_command (char *arg
, int from_tty
);
180 static void stopat_command (char *arg
, int from_tty
);
182 static char *ep_find_event_name_end (char *arg
);
184 static char *ep_parse_optional_if_clause (char **arg
);
186 static char *ep_parse_optional_filename (char **arg
);
188 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
189 enum exception_event_kind ex_event
,
190 struct symtab_and_line
*sal
);
192 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
193 char *arg
, int tempflag
, int from_tty
);
195 static void tcatch_command (char *arg
, int from_tty
);
197 static void ep_skip_leading_whitespace (char **s
);
199 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
201 static void free_bp_location (struct bp_location
*loc
);
203 /* Prototypes for exported functions. */
205 /* If FALSE, gdb will not use hardware support for watchpoints, even
206 if such is available. */
207 static int can_use_hw_watchpoints
;
210 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
211 struct cmd_list_element
*c
,
214 fprintf_filtered (file
, _("\
215 Debugger's willingness to use watchpoint hardware is %s.\n"),
219 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
220 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
221 for unrecognized breakpoint locations.
222 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
223 static enum auto_boolean pending_break_support
;
225 show_pending_break_support (struct ui_file
*file
, int from_tty
,
226 struct cmd_list_element
*c
,
229 fprintf_filtered (file
, _("\
230 Debugger's behavior regarding pending breakpoints is %s.\n"),
234 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
235 set with "break" but falling in read-only memory.
236 If 0, gdb will warn about such breakpoints, but won't automatically
237 use hardware breakpoints. */
238 static int automatic_hardware_breakpoints
;
240 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
241 struct cmd_list_element
*c
,
244 fprintf_filtered (file
, _("\
245 Automatic usage of hardware breakpoints is %s.\n"),
250 void _initialize_breakpoint (void);
252 extern int addressprint
; /* Print machine addresses? */
254 /* Are we executing breakpoint commands? */
255 static int executing_breakpoint_commands
;
257 /* Are overlay event breakpoints enabled? */
258 static int overlay_events_enabled
;
260 /* Walk the following statement or block through all breakpoints.
261 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
264 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
266 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
267 for (B = breakpoint_chain; \
268 B ? (TMP=B->next, 1): 0; \
271 /* Similar iterators for the low-level breakpoints. */
273 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
275 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
276 for (B = bp_location_chain; \
277 B ? (TMP=B->global_next, 1): 0; \
280 /* True if breakpoint hit counts should be displayed in breakpoint info. */
282 int show_breakpoint_hit_counts
= 1;
284 /* Chains of all breakpoints defined. */
286 struct breakpoint
*breakpoint_chain
;
288 struct bp_location
*bp_location_chain
;
290 /* Number of last breakpoint made. */
292 int breakpoint_count
;
294 /* Pointer to current exception event record */
295 static struct exception_event_record
*current_exception_event
;
297 /* This function returns a pointer to the string representation of the
298 pathname of the dynamically-linked library that has just been
301 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
302 or undefined results are guaranteed.
304 This string's contents are only valid immediately after the
305 inferior has stopped in the dynamic linker hook, and becomes
306 invalid as soon as the inferior is continued. Clients should make
307 a copy of this string if they wish to continue the inferior and
308 then access the string. */
310 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
311 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
314 /* This function returns a pointer to the string representation of the
315 pathname of the dynamically-linked library that has just been
318 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
319 TRUE, or undefined results are guaranteed.
321 This string's contents are only valid immediately after the
322 inferior has stopped in the dynamic linker hook, and becomes
323 invalid as soon as the inferior is continued. Clients should make
324 a copy of this string if they wish to continue the inferior and
325 then access the string. */
327 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
328 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
331 /* This function is called by the "catch load" command. It allows the
332 debugger to be notified by the dynamic linker when a specified
333 library file (or any library file, if filename is NULL) is loaded. */
335 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
336 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
337 error (_("catch of library loads not yet implemented on this platform"))
340 /* This function is called by the "catch unload" command. It allows
341 the debugger to be notified by the dynamic linker when a specified
342 library file (or any library file, if filename is NULL) is
345 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
346 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
347 error (_("catch of library unloads not yet implemented on this platform"))
350 /* Return whether a breakpoint is an active enabled breakpoint. */
352 breakpoint_enabled (struct breakpoint
*b
)
354 return (b
->enable_state
== bp_enabled
);
357 /* Set breakpoint count to NUM. */
360 set_breakpoint_count (int num
)
362 breakpoint_count
= num
;
363 set_internalvar (lookup_internalvar ("bpnum"),
364 value_from_longest (builtin_type_int
, (LONGEST
) num
));
367 /* Used in run_command to zero the hit count when a new run starts. */
370 clear_breakpoint_hit_counts (void)
372 struct breakpoint
*b
;
378 /* Default address, symtab and line to put a breakpoint at
379 for "break" command with no arg.
380 if default_breakpoint_valid is zero, the other three are
381 not valid, and "break" with no arg is an error.
383 This set by print_stack_frame, which calls set_default_breakpoint. */
385 int default_breakpoint_valid
;
386 CORE_ADDR default_breakpoint_address
;
387 struct symtab
*default_breakpoint_symtab
;
388 int default_breakpoint_line
;
390 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
391 Advance *PP after the string and any trailing whitespace.
393 Currently the string can either be a number or "$" followed by the name
394 of a convenience variable. Making it an expression wouldn't work well
395 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
397 If the string is a NULL pointer, that denotes the last breakpoint.
399 TRAILER is a character which can be found after the number; most
400 commonly this is `-'. If you don't want a trailer, use \0. */
402 get_number_trailer (char **pp
, int trailer
)
404 int retval
= 0; /* default */
408 /* Empty line means refer to the last breakpoint. */
409 return breakpoint_count
;
412 /* Make a copy of the name, so we can null-terminate it
413 to pass to lookup_internalvar(). */
418 while (isalnum (*p
) || *p
== '_')
420 varname
= (char *) alloca (p
- start
+ 1);
421 strncpy (varname
, start
, p
- start
);
422 varname
[p
- start
] = '\0';
423 val
= value_of_internalvar (lookup_internalvar (varname
));
424 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
425 retval
= (int) value_as_long (val
);
428 printf_filtered (_("Convenience variable must have integer value.\n"));
436 while (*p
>= '0' && *p
<= '9')
439 /* There is no number here. (e.g. "cond a == b"). */
441 /* Skip non-numeric token */
442 while (*p
&& !isspace((int) *p
))
444 /* Return zero, which caller must interpret as error. */
450 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
452 /* Trailing junk: return 0 and let caller print error msg. */
453 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
464 /* Like get_number_trailer, but don't allow a trailer. */
466 get_number (char **pp
)
468 return get_number_trailer (pp
, '\0');
471 /* Parse a number or a range.
472 * A number will be of the form handled by get_number.
473 * A range will be of the form <number1> - <number2>, and
474 * will represent all the integers between number1 and number2,
477 * While processing a range, this fuction is called iteratively;
478 * At each call it will return the next value in the range.
480 * At the beginning of parsing a range, the char pointer PP will
481 * be advanced past <number1> and left pointing at the '-' token.
482 * Subsequent calls will not advance the pointer until the range
483 * is completed. The call that completes the range will advance
484 * pointer PP past <number2>.
488 get_number_or_range (char **pp
)
490 static int last_retval
, end_value
;
491 static char *end_ptr
;
492 static int in_range
= 0;
496 /* Default case: pp is pointing either to a solo number,
497 or to the first number of a range. */
498 last_retval
= get_number_trailer (pp
, '-');
503 /* This is the start of a range (<number1> - <number2>).
504 Skip the '-', parse and remember the second number,
505 and also remember the end of the final token. */
509 while (isspace ((int) *end_ptr
))
510 end_ptr
++; /* skip white space */
511 end_value
= get_number (temp
);
512 if (end_value
< last_retval
)
514 error (_("inverted range"));
516 else if (end_value
== last_retval
)
518 /* degenerate range (number1 == number2). Advance the
519 token pointer so that the range will be treated as a
528 error (_("negative value"));
531 /* pp points to the '-' that betokens a range. All
532 number-parsing has already been done. Return the next
533 integer value (one greater than the saved previous value).
534 Do not advance the token pointer 'pp' until the end of range
537 if (++last_retval
== end_value
)
539 /* End of range reached; advance token pointer. */
549 /* condition N EXP -- set break condition of breakpoint N to EXP. */
552 condition_command (char *arg
, int from_tty
)
554 struct breakpoint
*b
;
559 error_no_arg (_("breakpoint number"));
562 bnum
= get_number (&p
);
564 error (_("Bad breakpoint argument: '%s'"), arg
);
567 if (b
->number
== bnum
)
569 struct bp_location
*loc
= b
->loc
;
570 for (; loc
; loc
= loc
->next
)
578 if (b
->cond_string
!= NULL
)
579 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
));
593 b
->condition_not_parsed
= 0;
594 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
597 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
599 error (_("Junk at end of expression"));
602 breakpoints_changed ();
603 breakpoint_modify_event (b
->number
);
607 error (_("No breakpoint number %d."), bnum
);
611 commands_command (char *arg
, int from_tty
)
613 struct breakpoint
*b
;
616 struct command_line
*l
;
618 /* If we allowed this, we would have problems with when to
619 free the storage, if we change the commands currently
622 if (executing_breakpoint_commands
)
623 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
626 bnum
= get_number (&p
);
629 error (_("Unexpected extra arguments following breakpoint number."));
632 if (b
->number
== bnum
)
634 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
636 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
637 l
= read_command_lines (tmpbuf
, from_tty
);
638 do_cleanups (cleanups
);
639 free_command_lines (&b
->commands
);
641 breakpoints_changed ();
642 breakpoint_modify_event (b
->number
);
645 error (_("No breakpoint number %d."), bnum
);
648 /* Like commands_command, but instead of reading the commands from
649 input stream, takes them from an already parsed command structure.
651 This is used by cli-script.c to DTRT with breakpoint commands
652 that are part of if and while bodies. */
653 enum command_control_type
654 commands_from_control_command (char *arg
, struct command_line
*cmd
)
656 struct breakpoint
*b
;
660 /* If we allowed this, we would have problems with when to
661 free the storage, if we change the commands currently
664 if (executing_breakpoint_commands
)
665 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
667 /* An empty string for the breakpoint number means the last
668 breakpoint, but get_number expects a NULL pointer. */
673 bnum
= get_number (&p
);
676 error (_("Unexpected extra arguments following breakpoint number."));
679 if (b
->number
== bnum
)
681 free_command_lines (&b
->commands
);
682 if (cmd
->body_count
!= 1)
683 error (_("Invalid \"commands\" block structure."));
684 /* We need to copy the commands because if/while will free the
685 list after it finishes execution. */
686 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
687 breakpoints_changed ();
688 breakpoint_modify_event (b
->number
);
689 return simple_control
;
691 error (_("No breakpoint number %d."), bnum
);
694 /* Like target_read_memory() but if breakpoints are inserted, return
695 the shadow contents instead of the breakpoints themselves.
697 Read "memory data" from whatever target or inferior we have.
698 Returns zero if successful, errno value if not. EIO is used
699 for address out of bounds. If breakpoints are inserted, returns
700 shadow contents, not the breakpoints themselves. From breakpoint.c. */
703 read_memory_nobpt (CORE_ADDR memaddr
, gdb_byte
*myaddr
, unsigned len
)
706 struct bp_location
*b
;
707 CORE_ADDR bp_addr
= 0;
710 if (gdbarch_breakpoint_from_pc (current_gdbarch
, &bp_addr
, &bp_size
) == NULL
)
711 /* No breakpoints on this machine. */
712 return target_read_memory (memaddr
, myaddr
, len
);
716 if (b
->owner
->type
== bp_none
)
717 warning (_("reading through apparently deleted breakpoint #%d?"),
720 if (b
->loc_type
!= bp_loc_software_breakpoint
)
724 /* Addresses and length of the part of the breakpoint that
726 bp_addr
= b
->target_info
.placed_address
;
727 bp_size
= b
->target_info
.shadow_len
;
729 /* bp isn't valid, or doesn't shadow memory. */
731 if (bp_addr
+ bp_size
<= memaddr
)
732 /* The breakpoint is entirely before the chunk of memory we
735 if (bp_addr
>= memaddr
+ len
)
736 /* The breakpoint is entirely after the chunk of memory we are
739 /* Copy the breakpoint from the shadow contents, and recurse for
740 the things before and after. */
742 /* Offset within shadow_contents. */
745 if (bp_addr
< memaddr
)
747 /* Only copy the second part of the breakpoint. */
748 bp_size
-= memaddr
- bp_addr
;
749 bptoffset
= memaddr
- bp_addr
;
753 if (bp_addr
+ bp_size
> memaddr
+ len
)
755 /* Only copy the first part of the breakpoint. */
756 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
759 memcpy (myaddr
+ bp_addr
- memaddr
,
760 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
762 if (bp_addr
> memaddr
)
764 /* Copy the section of memory before the breakpoint. */
765 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
770 if (bp_addr
+ bp_size
< memaddr
+ len
)
772 /* Copy the section of memory after the breakpoint. */
773 status
= read_memory_nobpt (bp_addr
+ bp_size
,
774 myaddr
+ bp_addr
+ bp_size
- memaddr
,
775 memaddr
+ len
- (bp_addr
+ bp_size
));
782 /* Nothing overlaps. Just call read_memory_noerr. */
783 return target_read_memory (memaddr
, myaddr
, len
);
787 /* A wrapper function for inserting catchpoints. */
789 insert_catchpoint (struct ui_out
*uo
, void *args
)
791 struct breakpoint
*b
= (struct breakpoint
*) args
;
797 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
800 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
803 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
806 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
811 /* Helper routine: free the value chain for a breakpoint (watchpoint). */
814 free_valchain (struct bp_location
*b
)
819 /* Free the saved value chain. We will construct a new one
820 the next time the watchpoint is inserted. */
821 for (v
= b
->owner
->val_chain
; v
; v
= n
)
826 b
->owner
->val_chain
= NULL
;
829 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
830 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
831 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
833 NOTE drow/2003-09-09: This routine could be broken down to an object-style
834 method for each breakpoint or catchpoint type. */
836 insert_bp_location (struct bp_location
*bpt
,
837 struct ui_file
*tmp_error_stream
,
838 int *disabled_breaks
, int *process_warning
,
839 int *hw_breakpoint_error
)
843 /* Permanent breakpoints cannot be inserted or removed. Disabled
844 breakpoints should not be inserted. */
845 if (!breakpoint_enabled (bpt
->owner
))
848 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->inserted
|| bpt
->duplicate
)
851 /* Initialize the target-specific information. */
852 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
853 bpt
->target_info
.placed_address
= bpt
->address
;
855 if (bpt
->loc_type
== bp_loc_software_breakpoint
856 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
858 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
860 /* If the explicitly specified breakpoint type
861 is not hardware breakpoint, check the memory map to see
862 if the breakpoint address is in read only memory or not.
863 Two important cases are:
864 - location type is not hardware breakpoint, memory
865 is readonly. We change the type of the location to
867 - location type is hardware breakpoint, memory is read-write.
868 This means we've previously made the location hardware one, but
869 then the memory map changed, so we undo.
871 When breakpoints are removed, remove_breakpoints will
872 use location types we've just set here, the only possible
873 problem is that memory map has changed during running program,
874 but it's not going to work anyway with current gdb. */
875 struct mem_region
*mr
876 = lookup_mem_region (bpt
->target_info
.placed_address
);
880 if (automatic_hardware_breakpoints
)
883 enum bp_loc_type new_type
;
885 if (mr
->attrib
.mode
!= MEM_RW
)
886 new_type
= bp_loc_hardware_breakpoint
;
888 new_type
= bp_loc_software_breakpoint
;
890 if (new_type
!= bpt
->loc_type
)
893 bpt
->loc_type
= new_type
;
896 fprintf_filtered (gdb_stdout
, _("\
897 Note: automatically using hardware breakpoints for read-only addresses.\n"));
902 else if (bpt
->loc_type
== bp_loc_software_breakpoint
903 && mr
->attrib
.mode
!= MEM_RW
)
904 warning (_("cannot set software breakpoint at readonly address %s"),
905 paddr (bpt
->address
));
909 /* First check to see if we have to handle an overlay. */
910 if (overlay_debugging
== ovly_off
911 || bpt
->section
== NULL
912 || !(section_is_overlay (bpt
->section
)))
914 /* No overlay handling: just set the breakpoint. */
916 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
917 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
919 val
= target_insert_breakpoint (&bpt
->target_info
);
923 /* This breakpoint is in an overlay section.
924 Shall we set a breakpoint at the LMA? */
925 if (!overlay_events_enabled
)
927 /* Yes -- overlay event support is not active,
928 so we must try to set a breakpoint at the LMA.
929 This will not work for a hardware breakpoint. */
930 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
931 warning (_("hardware breakpoint %d not supported in overlay!"),
935 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
937 /* Set a software (trap) breakpoint at the LMA. */
938 bpt
->overlay_target_info
= bpt
->target_info
;
939 bpt
->overlay_target_info
.placed_address
= addr
;
940 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
942 fprintf_unfiltered (tmp_error_stream
,
943 "Overlay breakpoint %d failed: in ROM?",
947 /* Shall we set a breakpoint at the VMA? */
948 if (section_is_mapped (bpt
->section
))
950 /* Yes. This overlay section is mapped into memory. */
951 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
952 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
954 val
= target_insert_breakpoint (&bpt
->target_info
);
958 /* No. This breakpoint will not be inserted.
959 No error, but do not mark the bp as 'inserted'. */
966 /* Can't set the breakpoint. */
967 if (solib_address (bpt
->address
))
969 /* See also: disable_breakpoints_in_shlibs. */
971 bpt
->shlib_disabled
= 1;
972 if (!*disabled_breaks
)
974 fprintf_unfiltered (tmp_error_stream
,
975 "Cannot insert breakpoint %d.\n",
977 fprintf_unfiltered (tmp_error_stream
,
978 "Temporarily disabling shared library breakpoints:\n");
980 *disabled_breaks
= 1;
981 fprintf_unfiltered (tmp_error_stream
,
982 "breakpoint #%d\n", bpt
->owner
->number
);
986 #ifdef ONE_PROCESS_WRITETEXT
987 *process_warning
= 1;
989 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
991 *hw_breakpoint_error
= 1;
992 fprintf_unfiltered (tmp_error_stream
,
993 "Cannot insert hardware breakpoint %d.\n",
998 fprintf_unfiltered (tmp_error_stream
,
999 "Cannot insert breakpoint %d.\n",
1000 bpt
->owner
->number
);
1001 fprintf_filtered (tmp_error_stream
,
1002 "Error accessing memory address ");
1003 deprecated_print_address_numeric (bpt
->address
, 1, tmp_error_stream
);
1004 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1005 safe_strerror (val
));
1016 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1017 /* NOTE drow/2003-09-08: This state only exists for removing
1018 watchpoints. It's not clear that it's necessary... */
1019 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1021 /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints
1022 based on the expression. Ideally this should happen at a higher level,
1023 and there should be one bp_location for each computed address we
1024 must watch. As soon as a many-to-one mapping is available I'll
1027 int within_current_scope
;
1028 struct value
*mark
= value_mark ();
1030 struct frame_id saved_frame_id
;
1032 /* Save the current frame's ID so we can restore it after
1033 evaluating the watchpoint expression on its own frame. */
1034 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1035 took a frame parameter, so that we didn't have to change the
1037 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1039 /* Determine if the watchpoint is within scope. */
1040 if (bpt
->owner
->exp_valid_block
== NULL
)
1041 within_current_scope
= 1;
1044 struct frame_info
*fi
;
1045 fi
= frame_find_by_id (bpt
->owner
->watchpoint_frame
);
1046 within_current_scope
= (fi
!= NULL
);
1047 if (within_current_scope
)
1051 if (within_current_scope
)
1053 free_valchain (bpt
);
1055 /* Evaluate the expression and cut the chain of values
1056 produced off from the value chain.
1058 Make sure the value returned isn't lazy; we use
1059 laziness to determine what memory GDB actually needed
1060 in order to compute the value of the expression. */
1061 v
= evaluate_expression (bpt
->owner
->exp
);
1063 value_release_to_mark (mark
);
1065 bpt
->owner
->val_chain
= v
;
1068 /* Look at each value on the value chain. */
1069 for (; v
; v
= value_next (v
))
1071 /* If it's a memory location, and GDB actually needed
1072 its contents to evaluate the expression, then we
1074 if (VALUE_LVAL (v
) == lval_memory
1075 && ! value_lazy (v
))
1077 struct type
*vtype
= check_typedef (value_type (v
));
1079 /* We only watch structs and arrays if user asked
1080 for it explicitly, never if they just happen to
1081 appear in the middle of some value chain. */
1082 if (v
== bpt
->owner
->val_chain
1083 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1084 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1089 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
1090 len
= TYPE_LENGTH (value_type (v
));
1092 if (bpt
->owner
->type
== bp_read_watchpoint
)
1094 else if (bpt
->owner
->type
== bp_access_watchpoint
)
1097 val
= target_insert_watchpoint (addr
, len
, type
);
1100 /* Don't exit the loop, try to insert
1101 every value on the value chain. That's
1102 because we will be removing all the
1103 watches below, and removing a
1104 watchpoint we didn't insert could have
1112 /* Failure to insert a watchpoint on any memory value in the
1113 value chain brings us here. */
1116 remove_breakpoint (bpt
, mark_uninserted
);
1117 *hw_breakpoint_error
= 1;
1118 fprintf_unfiltered (tmp_error_stream
,
1119 "Could not insert hardware watchpoint %d.\n",
1120 bpt
->owner
->number
);
1126 printf_filtered (_("\
1127 Hardware watchpoint %d deleted because the program has left the block \n\
1128 in which its expression is valid.\n"),
1129 bpt
->owner
->number
);
1130 if (bpt
->owner
->related_breakpoint
)
1131 bpt
->owner
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1132 bpt
->owner
->disposition
= disp_del_at_next_stop
;
1135 /* Restore the selected frame. */
1136 select_frame (frame_find_by_id (saved_frame_id
));
1141 else if (ep_is_exception_catchpoint (bpt
->owner
))
1143 /* FIXME drow/2003-09-09: This code sets both a catchpoint and a
1144 breakpoint. Once again, it would be better if this was represented
1145 as two bp_locations. */
1147 /* If we get here, we must have a callback mechanism for exception
1148 events -- with g++ style embedded label support, we insert
1149 ordinary breakpoints and not catchpoints. */
1150 val
= target_insert_breakpoint (&bpt
->target_info
);
1153 /* Couldn't set breakpoint for some reason */
1154 fprintf_unfiltered (tmp_error_stream
,
1155 "Cannot insert catchpoint %d; disabling it.\n",
1156 bpt
->owner
->number
);
1157 fprintf_filtered (tmp_error_stream
,
1158 "Error accessing memory address ");
1159 deprecated_print_address_numeric (bpt
->address
, 1, tmp_error_stream
);
1160 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1161 safe_strerror (val
));
1162 bpt
->owner
->enable_state
= bp_disabled
;
1166 /* Bp set, now make sure callbacks are enabled */
1167 /* Format possible error msg */
1168 char *message
= xstrprintf ("Error inserting catchpoint %d:\n",
1169 bpt
->owner
->number
);
1170 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
1172 args_for_catchpoint_enable args
;
1173 args
.kind
= bpt
->owner
->type
== bp_catch_catch
?
1174 EX_EVENT_CATCH
: EX_EVENT_THROW
;
1176 val
= catch_errors (cover_target_enable_exception_callback
,
1177 &args
, message
, RETURN_MASK_ALL
);
1178 do_cleanups (cleanups
);
1179 if (val
!= 0 && val
!= -1)
1182 /* Check if something went wrong; val == 0 can be ignored */
1185 /* something went wrong */
1186 fprintf_unfiltered (tmp_error_stream
,
1187 "Cannot insert catchpoint %d; disabling it.\n",
1188 bpt
->owner
->number
);
1189 bpt
->owner
->enable_state
= bp_disabled
;
1196 else if (bpt
->owner
->type
== bp_catch_fork
1197 || bpt
->owner
->type
== bp_catch_vfork
1198 || bpt
->owner
->type
== bp_catch_exec
)
1200 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1201 bpt
->owner
, RETURN_MASK_ERROR
);
1202 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1203 bpt
->owner
->number
);
1205 bpt
->owner
->enable_state
= bp_disabled
;
1209 /* We've already printed an error message if there was a problem
1210 inserting this catchpoint, and we've disabled the catchpoint,
1211 so just return success. */
1218 /* insert_breakpoints is used when starting or continuing the program.
1219 remove_breakpoints is used when the program stops.
1220 Both return zero if successful,
1221 or an `errno' value if could not write the inferior. */
1224 insert_breakpoints (void)
1226 struct bp_location
*b
, *temp
;
1227 int return_val
= 0; /* return success code. */
1229 int disabled_breaks
= 0;
1230 int hw_breakpoint_error
= 0;
1231 int process_warning
= 0;
1233 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1234 make_cleanup_ui_file_delete (tmp_error_stream
);
1236 /* Explicitly mark the warning -- this will only be printed if
1237 there was an error. */
1238 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1240 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1242 /* Permanent breakpoints cannot be inserted or removed. Disabled
1243 breakpoints should not be inserted. */
1244 if (!breakpoint_enabled (b
->owner
))
1247 /* There is no point inserting thread-specific breakpoints if the
1248 thread no longer exists. */
1249 if (b
->owner
->thread
!= -1
1250 && !valid_thread_id (b
->owner
->thread
))
1253 /* FIXME drow/2003-10-07: This code should be pushed elsewhere when
1254 hardware watchpoints are split into multiple loc breakpoints. */
1255 if ((b
->loc_type
== bp_loc_hardware_watchpoint
1256 || b
->owner
->type
== bp_watchpoint
) && !b
->owner
->val
)
1259 val
= evaluate_expression (b
->owner
->exp
);
1260 release_value (val
);
1261 if (value_lazy (val
))
1262 value_fetch_lazy (val
);
1263 b
->owner
->val
= val
;
1266 val
= insert_bp_location (b
, tmp_error_stream
,
1267 &disabled_breaks
, &process_warning
,
1268 &hw_breakpoint_error
);
1275 /* If a hardware breakpoint or watchpoint was inserted, add a
1276 message about possibly exhausted resources. */
1277 if (hw_breakpoint_error
)
1279 fprintf_unfiltered (tmp_error_stream
,
1280 "Could not insert hardware breakpoints:\n\
1281 You may have requested too many hardware breakpoints/watchpoints.\n");
1283 #ifdef ONE_PROCESS_WRITETEXT
1284 if (process_warning
)
1285 fprintf_unfiltered (tmp_error_stream
,
1286 "The same program may be running in another process.");
1288 target_terminal_ours_for_output ();
1289 error_stream (tmp_error_stream
);
1295 remove_breakpoints (void)
1297 struct bp_location
*b
;
1300 ALL_BP_LOCATIONS (b
)
1304 val
= remove_breakpoint (b
, mark_uninserted
);
1313 remove_hw_watchpoints (void)
1315 struct bp_location
*b
;
1318 ALL_BP_LOCATIONS (b
)
1320 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1322 val
= remove_breakpoint (b
, mark_uninserted
);
1331 reattach_breakpoints (int pid
)
1333 struct bp_location
*b
;
1335 struct cleanup
*old_chain
= save_inferior_ptid ();
1336 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1337 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1339 make_cleanup_ui_file_delete (tmp_error_stream
);
1341 inferior_ptid
= pid_to_ptid (pid
);
1342 ALL_BP_LOCATIONS (b
)
1347 val
= insert_bp_location (b
, tmp_error_stream
,
1348 &dummy1
, &dummy2
, &dummy3
);
1351 do_cleanups (old_chain
);
1356 do_cleanups (old_chain
);
1361 update_breakpoints_after_exec (void)
1363 struct breakpoint
*b
;
1364 struct breakpoint
*temp
;
1366 /* Doing this first prevents the badness of having delete_breakpoint()
1367 write a breakpoint's current "shadow contents" to lift the bp. That
1368 shadow is NOT valid after an exec()! */
1369 mark_breakpoints_out ();
1371 ALL_BREAKPOINTS_SAFE (b
, temp
)
1373 /* Solib breakpoints must be explicitly reset after an exec(). */
1374 if (b
->type
== bp_shlib_event
)
1376 delete_breakpoint (b
);
1380 /* Thread event breakpoints must be set anew after an exec(),
1381 as must overlay event breakpoints. */
1382 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1384 delete_breakpoint (b
);
1388 /* Step-resume breakpoints are meaningless after an exec(). */
1389 if (b
->type
== bp_step_resume
)
1391 delete_breakpoint (b
);
1395 /* Ditto the exception-handling catchpoints. */
1396 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1398 delete_breakpoint (b
);
1402 /* Don't delete an exec catchpoint, because else the inferior
1403 won't stop when it ought!
1405 Similarly, we probably ought to keep vfork catchpoints, 'cause
1406 on this target, we may not be able to stop when the vfork is
1407 seen, but only when the subsequent exec is seen. (And because
1408 deleting fork catchpoints here but not vfork catchpoints will
1409 seem mysterious to users, keep those too.) */
1410 if ((b
->type
== bp_catch_exec
) ||
1411 (b
->type
== bp_catch_vfork
) ||
1412 (b
->type
== bp_catch_fork
))
1417 /* bp_finish is a special case. The only way we ought to be able
1418 to see one of these when an exec() has happened, is if the user
1419 caught a vfork, and then said "finish". Ordinarily a finish just
1420 carries them to the call-site of the current callee, by setting
1421 a temporary bp there and resuming. But in this case, the finish
1422 will carry them entirely through the vfork & exec.
1424 We don't want to allow a bp_finish to remain inserted now. But
1425 we can't safely delete it, 'cause finish_command has a handle to
1426 the bp on a bpstat, and will later want to delete it. There's a
1427 chance (and I've seen it happen) that if we delete the bp_finish
1428 here, that its storage will get reused by the time finish_command
1429 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1430 We really must allow finish_command to delete a bp_finish.
1432 In the absense of a general solution for the "how do we know
1433 it's safe to delete something others may have handles to?"
1434 problem, what we'll do here is just uninsert the bp_finish, and
1435 let finish_command delete it.
1437 (We know the bp_finish is "doomed" in the sense that it's
1438 momentary, and will be deleted as soon as finish_command sees
1439 the inferior stopped. So it doesn't matter that the bp's
1440 address is probably bogus in the new a.out, unlike e.g., the
1441 solib breakpoints.) */
1443 if (b
->type
== bp_finish
)
1448 /* Without a symbolic address, we have little hope of the
1449 pre-exec() address meaning the same thing in the post-exec()
1451 if (b
->addr_string
== NULL
)
1453 delete_breakpoint (b
);
1457 /* FIXME what about longjmp breakpoints? Re-create them here? */
1458 create_overlay_event_breakpoint ("_ovly_debug_event");
1462 detach_breakpoints (int pid
)
1464 struct bp_location
*b
;
1466 struct cleanup
*old_chain
= save_inferior_ptid ();
1468 if (pid
== PIDGET (inferior_ptid
))
1469 error (_("Cannot detach breakpoints of inferior_ptid"));
1471 /* Set inferior_ptid; remove_breakpoint uses this global. */
1472 inferior_ptid
= pid_to_ptid (pid
);
1473 ALL_BP_LOCATIONS (b
)
1477 val
= remove_breakpoint (b
, mark_inserted
);
1480 do_cleanups (old_chain
);
1485 do_cleanups (old_chain
);
1490 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1494 if (b
->owner
->enable_state
== bp_permanent
)
1495 /* Permanent breakpoints cannot be inserted or removed. */
1498 if (b
->owner
->type
== bp_none
)
1499 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1502 if (b
->loc_type
== bp_loc_software_breakpoint
1503 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1505 /* "Normal" instruction breakpoint: either the standard
1506 trap-instruction bp (bp_breakpoint), or a
1507 bp_hardware_breakpoint. */
1509 /* First check to see if we have to handle an overlay. */
1510 if (overlay_debugging
== ovly_off
1511 || b
->section
== NULL
1512 || !(section_is_overlay (b
->section
)))
1514 /* No overlay handling: just remove the breakpoint. */
1516 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1517 val
= target_remove_hw_breakpoint (&b
->target_info
);
1519 val
= target_remove_breakpoint (&b
->target_info
);
1523 /* This breakpoint is in an overlay section.
1524 Did we set a breakpoint at the LMA? */
1525 if (!overlay_events_enabled
)
1527 /* Yes -- overlay event support is not active, so we
1528 should have set a breakpoint at the LMA. Remove it.
1530 /* Ignore any failures: if the LMA is in ROM, we will
1531 have already warned when we failed to insert it. */
1532 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1533 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1535 target_remove_breakpoint (&b
->overlay_target_info
);
1537 /* Did we set a breakpoint at the VMA?
1538 If so, we will have marked the breakpoint 'inserted'. */
1541 /* Yes -- remove it. Previously we did not bother to
1542 remove the breakpoint if the section had been
1543 unmapped, but let's not rely on that being safe. We
1544 don't know what the overlay manager might do. */
1545 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1546 val
= target_remove_hw_breakpoint (&b
->target_info
);
1548 /* However, we should remove *software* breakpoints only
1549 if the section is still mapped, or else we overwrite
1550 wrong code with the saved shadow contents. */
1551 else if (section_is_mapped (b
->section
))
1552 val
= target_remove_breakpoint (&b
->target_info
);
1558 /* No -- not inserted, so no need to remove. No error. */
1564 b
->inserted
= (is
== mark_inserted
);
1566 else if (b
->loc_type
== bp_loc_hardware_watchpoint
1567 && breakpoint_enabled (b
->owner
)
1573 b
->inserted
= (is
== mark_inserted
);
1574 /* Walk down the saved value chain. */
1575 for (v
= b
->owner
->val_chain
; v
; v
= value_next (v
))
1577 /* For each memory reference remove the watchpoint
1579 if (VALUE_LVAL (v
) == lval_memory
1580 && ! value_lazy (v
))
1582 struct type
*vtype
= check_typedef (value_type (v
));
1584 if (v
== b
->owner
->val_chain
1585 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1586 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1591 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
1592 len
= TYPE_LENGTH (value_type (v
));
1594 if (b
->owner
->type
== bp_read_watchpoint
)
1596 else if (b
->owner
->type
== bp_access_watchpoint
)
1599 val
= target_remove_watchpoint (addr
, len
, type
);
1606 /* Failure to remove any of the hardware watchpoints comes here. */
1607 if ((is
== mark_uninserted
) && (b
->inserted
))
1608 warning (_("Could not remove hardware watchpoint %d."),
1611 else if ((b
->owner
->type
== bp_catch_fork
||
1612 b
->owner
->type
== bp_catch_vfork
||
1613 b
->owner
->type
== bp_catch_exec
)
1614 && breakpoint_enabled (b
->owner
)
1618 switch (b
->owner
->type
)
1621 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1623 case bp_catch_vfork
:
1624 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1627 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1630 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1635 b
->inserted
= (is
== mark_inserted
);
1637 else if ((b
->owner
->type
== bp_catch_catch
||
1638 b
->owner
->type
== bp_catch_throw
)
1639 && breakpoint_enabled (b
->owner
)
1642 val
= target_remove_breakpoint (&b
->target_info
);
1645 b
->inserted
= (is
== mark_inserted
);
1651 /* Clear the "inserted" flag in all breakpoints. */
1654 mark_breakpoints_out (void)
1656 struct bp_location
*bpt
;
1658 ALL_BP_LOCATIONS (bpt
)
1662 /* Clear the "inserted" flag in all breakpoints and delete any
1663 breakpoints which should go away between runs of the program.
1665 Plus other such housekeeping that has to be done for breakpoints
1668 Note: this function gets called at the end of a run (by
1669 generic_mourn_inferior) and when a run begins (by
1670 init_wait_for_inferior). */
1675 breakpoint_init_inferior (enum inf_context context
)
1677 struct breakpoint
*b
, *temp
;
1678 struct bp_location
*bpt
;
1680 ALL_BP_LOCATIONS (bpt
)
1683 ALL_BREAKPOINTS_SAFE (b
, temp
)
1688 case bp_watchpoint_scope
:
1690 /* If the call dummy breakpoint is at the entry point it will
1691 cause problems when the inferior is rerun, so we better
1694 Also get rid of scope breakpoints. */
1695 delete_breakpoint (b
);
1699 case bp_hardware_watchpoint
:
1700 case bp_read_watchpoint
:
1701 case bp_access_watchpoint
:
1703 /* Likewise for watchpoints on local expressions. */
1704 if (b
->exp_valid_block
!= NULL
)
1705 delete_breakpoint (b
);
1706 else if (context
== inf_starting
)
1708 /* Reset val field to force reread of starting value
1709 in insert_breakpoints. */
1711 value_free (b
->val
);
1721 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1722 exists at PC. It returns ordinary_breakpoint_here if it's an
1723 ordinary breakpoint, or permanent_breakpoint_here if it's a
1724 permanent breakpoint.
1725 - When continuing from a location with an ordinary breakpoint, we
1726 actually single step once before calling insert_breakpoints.
1727 - When continuing from a localion with a permanent breakpoint, we
1728 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1729 the target, to advance the PC past the breakpoint. */
1731 enum breakpoint_here
1732 breakpoint_here_p (CORE_ADDR pc
)
1734 struct bp_location
*bpt
;
1735 int any_breakpoint_here
= 0;
1737 ALL_BP_LOCATIONS (bpt
)
1739 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1740 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1743 if ((breakpoint_enabled (bpt
->owner
)
1744 || bpt
->owner
->enable_state
== bp_permanent
)
1745 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1747 if (overlay_debugging
1748 && section_is_overlay (bpt
->section
)
1749 && !section_is_mapped (bpt
->section
))
1750 continue; /* unmapped overlay -- can't be a match */
1751 else if (bpt
->owner
->enable_state
== bp_permanent
)
1752 return permanent_breakpoint_here
;
1754 any_breakpoint_here
= 1;
1758 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1762 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1763 but it only returns true if there is actually a breakpoint inserted
1767 breakpoint_inserted_here_p (CORE_ADDR pc
)
1769 struct bp_location
*bpt
;
1771 ALL_BP_LOCATIONS (bpt
)
1773 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1774 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1778 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1780 if (overlay_debugging
1781 && section_is_overlay (bpt
->section
)
1782 && !section_is_mapped (bpt
->section
))
1783 continue; /* unmapped overlay -- can't be a match */
1789 /* Also check for software single-step breakpoints. */
1790 if (single_step_breakpoint_inserted_here_p (pc
))
1796 /* This function returns non-zero iff there is a software breakpoint
1800 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1802 struct bp_location
*bpt
;
1803 int any_breakpoint_here
= 0;
1805 ALL_BP_LOCATIONS (bpt
)
1807 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
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
&& bsp
->breakpoint_at
->owner
== 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
->owner
->type
== bp_step_resume
) &&
1998 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
1999 bsp
->breakpoint_at
->owner
->thread
== -1))
2000 return bsp
->breakpoint_at
->owner
;
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 /* We assume we'll never have several bpstats that
2025 correspond to a single breakpoint -- otherwise,
2026 this function might return the same number more
2027 than once and this will look ugly. */
2028 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2029 *bsp
= (*bsp
)->next
;
2031 return -1; /* breakpoint that's been deleted since */
2033 *num
= b
->number
; /* We have its number */
2037 /* Modify BS so that the actions will not be performed. */
2040 bpstat_clear_actions (bpstat bs
)
2042 for (; bs
!= NULL
; bs
= bs
->next
)
2044 free_command_lines (&bs
->commands
);
2045 if (bs
->old_val
!= NULL
)
2047 value_free (bs
->old_val
);
2053 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2055 cleanup_executing_breakpoints (void *ignore
)
2057 executing_breakpoint_commands
= 0;
2060 /* Execute all the commands associated with all the breakpoints at this
2061 location. Any of these commands could cause the process to proceed
2062 beyond this point, etc. We look out for such changes by checking
2063 the global "breakpoint_proceeded" after each command. */
2066 bpstat_do_actions (bpstat
*bsp
)
2069 struct cleanup
*old_chain
;
2071 /* Avoid endless recursion if a `source' command is contained
2073 if (executing_breakpoint_commands
)
2076 executing_breakpoint_commands
= 1;
2077 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2080 /* Note that (as of this writing), our callers all appear to
2081 be passing us the address of global stop_bpstat. And, if
2082 our calls to execute_control_command cause the inferior to
2083 proceed, that global (and hence, *bsp) will change.
2085 We must be careful to not touch *bsp unless the inferior
2086 has not proceeded. */
2088 /* This pointer will iterate over the list of bpstat's. */
2091 breakpoint_proceeded
= 0;
2092 for (; bs
!= NULL
; bs
= bs
->next
)
2094 struct command_line
*cmd
;
2095 struct cleanup
*this_cmd_tree_chain
;
2097 /* Take ownership of the BSP's command tree, if it has one.
2099 The command tree could legitimately contain commands like
2100 'step' and 'next', which call clear_proceed_status, which
2101 frees stop_bpstat's command tree. To make sure this doesn't
2102 free the tree we're executing out from under us, we need to
2103 take ownership of the tree ourselves. Since a given bpstat's
2104 commands are only executed once, we don't need to copy it; we
2105 can clear the pointer in the bpstat, and make sure we free
2106 the tree when we're done. */
2109 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2113 execute_control_command (cmd
);
2115 if (breakpoint_proceeded
)
2121 /* We can free this command tree now. */
2122 do_cleanups (this_cmd_tree_chain
);
2124 if (breakpoint_proceeded
)
2125 /* The inferior is proceeded by the command; bomb out now.
2126 The bpstat chain has been blown away by wait_for_inferior.
2127 But since execution has stopped again, there is a new bpstat
2128 to look at, so start over. */
2131 do_cleanups (old_chain
);
2134 /* This is the normal print function for a bpstat. In the future,
2135 much of this logic could (should?) be moved to bpstat_stop_status,
2136 by having it set different print_it values.
2138 Current scheme: When we stop, bpstat_print() is called. It loops
2139 through the bpstat list of things causing this stop, calling the
2140 print_bp_stop_message function on each one. The behavior of the
2141 print_bp_stop_message function depends on the print_it field of
2142 bpstat. If such field so indicates, call this function here.
2144 Return values from this routine (ultimately used by bpstat_print()
2145 and normal_stop() to decide what to do):
2146 PRINT_NOTHING: Means we already printed all we needed to print,
2147 don't print anything else.
2148 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2149 that something to be followed by a location.
2150 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2151 that something to be followed by a location.
2152 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2155 static enum print_stop_action
2156 print_it_typical (bpstat bs
)
2158 struct cleanup
*old_chain
, *ui_out_chain
;
2159 struct breakpoint
*b
;
2160 struct bp_location
*bl
;
2161 struct ui_stream
*stb
;
2162 stb
= ui_out_stream_new (uiout
);
2163 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2164 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2165 which has since been deleted. */
2166 if (bs
->breakpoint_at
== NULL
)
2167 return PRINT_UNKNOWN
;
2168 bl
= bs
->breakpoint_at
;
2174 case bp_hardware_breakpoint
:
2175 if (bl
->address
!= bl
->requested_address
)
2176 breakpoint_adjustment_warning (bl
->requested_address
,
2179 annotate_breakpoint (b
->number
);
2180 ui_out_text (uiout
, "\nBreakpoint ");
2181 if (ui_out_is_mi_like_p (uiout
))
2182 ui_out_field_string (uiout
, "reason",
2183 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2184 ui_out_field_int (uiout
, "bkptno", b
->number
);
2185 ui_out_text (uiout
, ", ");
2186 return PRINT_SRC_AND_LOC
;
2189 case bp_shlib_event
:
2190 /* Did we stop because the user set the stop_on_solib_events
2191 variable? (If so, we report this as a generic, "Stopped due
2192 to shlib event" message.) */
2193 printf_filtered (_("Stopped due to shared library event\n"));
2194 return PRINT_NOTHING
;
2197 case bp_thread_event
:
2198 /* Not sure how we will get here.
2199 GDB should not stop for these breakpoints. */
2200 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2201 return PRINT_NOTHING
;
2204 case bp_overlay_event
:
2205 /* By analogy with the thread event, GDB should not stop for these. */
2206 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2207 return PRINT_NOTHING
;
2211 annotate_catchpoint (b
->number
);
2212 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2214 b
->triggered_dll_pathname
);
2215 return PRINT_SRC_AND_LOC
;
2218 case bp_catch_unload
:
2219 annotate_catchpoint (b
->number
);
2220 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2222 b
->triggered_dll_pathname
);
2223 return PRINT_SRC_AND_LOC
;
2227 annotate_catchpoint (b
->number
);
2228 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2230 b
->forked_inferior_pid
);
2231 return PRINT_SRC_AND_LOC
;
2234 case bp_catch_vfork
:
2235 annotate_catchpoint (b
->number
);
2236 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2238 b
->forked_inferior_pid
);
2239 return PRINT_SRC_AND_LOC
;
2243 annotate_catchpoint (b
->number
);
2244 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2247 return PRINT_SRC_AND_LOC
;
2250 case bp_catch_catch
:
2251 if (current_exception_event
&&
2252 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2254 annotate_catchpoint (b
->number
);
2255 printf_filtered (_("\nCatchpoint %d (exception caught), "),
2257 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2258 printf_filtered (_("throw location %s:%d, "),
2259 CURRENT_EXCEPTION_THROW_FILE
,
2260 CURRENT_EXCEPTION_THROW_LINE
);
2262 printf_filtered (_("throw location unknown, "));
2264 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2265 printf_filtered (_("catch location %s:%d\n"),
2266 CURRENT_EXCEPTION_CATCH_FILE
,
2267 CURRENT_EXCEPTION_CATCH_LINE
);
2269 printf_filtered (_("catch location unknown\n"));
2271 /* don't bother to print location frame info */
2272 return PRINT_SRC_ONLY
;
2276 /* really throw, some other bpstat will handle it */
2277 return PRINT_UNKNOWN
;
2281 case bp_catch_throw
:
2282 if (current_exception_event
&&
2283 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2285 annotate_catchpoint (b
->number
);
2286 printf_filtered (_("\nCatchpoint %d (exception thrown), "),
2288 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2289 printf_filtered (_("throw location %s:%d, "),
2290 CURRENT_EXCEPTION_THROW_FILE
,
2291 CURRENT_EXCEPTION_THROW_LINE
);
2293 printf_filtered (_("throw location unknown, "));
2295 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2296 printf_filtered (_("catch location %s:%d\n"),
2297 CURRENT_EXCEPTION_CATCH_FILE
,
2298 CURRENT_EXCEPTION_CATCH_LINE
);
2300 printf_filtered (_("catch location unknown\n"));
2302 /* don't bother to print location frame info */
2303 return PRINT_SRC_ONLY
;
2307 /* really catch, some other bpstat will handle it */
2308 return PRINT_UNKNOWN
;
2313 case bp_hardware_watchpoint
:
2314 if (bs
->old_val
!= NULL
)
2316 annotate_watchpoint (b
->number
);
2317 if (ui_out_is_mi_like_p (uiout
))
2320 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2322 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2323 ui_out_text (uiout
, "\nOld value = ");
2324 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2325 ui_out_field_stream (uiout
, "old", stb
);
2326 ui_out_text (uiout
, "\nNew value = ");
2327 value_print (b
->val
, stb
->stream
, 0, Val_pretty_default
);
2328 ui_out_field_stream (uiout
, "new", stb
);
2329 do_cleanups (ui_out_chain
);
2330 ui_out_text (uiout
, "\n");
2331 value_free (bs
->old_val
);
2334 /* More than one watchpoint may have been triggered. */
2335 return PRINT_UNKNOWN
;
2338 case bp_read_watchpoint
:
2339 if (ui_out_is_mi_like_p (uiout
))
2342 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2344 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2345 ui_out_text (uiout
, "\nValue = ");
2346 value_print (b
->val
, stb
->stream
, 0, Val_pretty_default
);
2347 ui_out_field_stream (uiout
, "value", stb
);
2348 do_cleanups (ui_out_chain
);
2349 ui_out_text (uiout
, "\n");
2350 return PRINT_UNKNOWN
;
2353 case bp_access_watchpoint
:
2354 if (bs
->old_val
!= NULL
)
2356 annotate_watchpoint (b
->number
);
2357 if (ui_out_is_mi_like_p (uiout
))
2360 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2362 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2363 ui_out_text (uiout
, "\nOld value = ");
2364 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2365 ui_out_field_stream (uiout
, "old", stb
);
2366 value_free (bs
->old_val
);
2368 ui_out_text (uiout
, "\nNew value = ");
2373 if (ui_out_is_mi_like_p (uiout
))
2376 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2377 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2378 ui_out_text (uiout
, "\nValue = ");
2380 value_print (b
->val
, stb
->stream
, 0,Val_pretty_default
);
2381 ui_out_field_stream (uiout
, "new", stb
);
2382 do_cleanups (ui_out_chain
);
2383 ui_out_text (uiout
, "\n");
2384 return PRINT_UNKNOWN
;
2387 /* Fall through, we don't deal with these types of breakpoints
2391 if (ui_out_is_mi_like_p (uiout
))
2394 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2395 return PRINT_UNKNOWN
;
2399 if (ui_out_is_mi_like_p (uiout
))
2402 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2403 return PRINT_UNKNOWN
;
2408 case bp_longjmp_resume
:
2409 case bp_step_resume
:
2410 case bp_watchpoint_scope
:
2413 return PRINT_UNKNOWN
;
2417 /* Generic routine for printing messages indicating why we
2418 stopped. The behavior of this function depends on the value
2419 'print_it' in the bpstat structure. Under some circumstances we
2420 may decide not to print anything here and delegate the task to
2423 static enum print_stop_action
2424 print_bp_stop_message (bpstat bs
)
2426 switch (bs
->print_it
)
2429 /* Nothing should be printed for this bpstat entry. */
2430 return PRINT_UNKNOWN
;
2434 /* We still want to print the frame, but we already printed the
2435 relevant messages. */
2436 return PRINT_SRC_AND_LOC
;
2439 case print_it_normal
:
2441 struct bp_location
*bl
= bs
->breakpoint_at
;
2442 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2444 /* Normal case. Call the breakpoint's print_it method, or
2445 print_it_typical. */
2446 /* FIXME: how breakpoint can ever be NULL here? */
2447 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2448 return b
->ops
->print_it (b
);
2450 return print_it_typical (bs
);
2455 internal_error (__FILE__
, __LINE__
,
2456 _("print_bp_stop_message: unrecognized enum value"));
2461 /* Print a message indicating what happened. This is called from
2462 normal_stop(). The input to this routine is the head of the bpstat
2463 list - a list of the eventpoints that caused this stop. This
2464 routine calls the generic print routine for printing a message
2465 about reasons for stopping. This will print (for example) the
2466 "Breakpoint n," part of the output. The return value of this
2469 PRINT_UNKNOWN: Means we printed nothing
2470 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2471 code to print the location. An example is
2472 "Breakpoint 1, " which should be followed by
2474 PRINT_SRC_ONLY: Means we printed something, but there is no need
2475 to also print the location part of the message.
2476 An example is the catch/throw messages, which
2477 don't require a location appended to the end.
2478 PRINT_NOTHING: We have done some printing and we don't need any
2479 further info to be printed.*/
2481 enum print_stop_action
2482 bpstat_print (bpstat bs
)
2486 /* Maybe another breakpoint in the chain caused us to stop.
2487 (Currently all watchpoints go on the bpstat whether hit or not.
2488 That probably could (should) be changed, provided care is taken
2489 with respect to bpstat_explains_signal). */
2490 for (; bs
; bs
= bs
->next
)
2492 val
= print_bp_stop_message (bs
);
2493 if (val
== PRINT_SRC_ONLY
2494 || val
== PRINT_SRC_AND_LOC
2495 || val
== PRINT_NOTHING
)
2499 /* We reached the end of the chain, or we got a null BS to start
2500 with and nothing was printed. */
2501 return PRINT_UNKNOWN
;
2504 /* Evaluate the expression EXP and return 1 if value is zero.
2505 This is used inside a catch_errors to evaluate the breakpoint condition.
2506 The argument is a "struct expression *" that has been cast to char * to
2507 make it pass through catch_errors. */
2510 breakpoint_cond_eval (void *exp
)
2512 struct value
*mark
= value_mark ();
2513 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2514 value_free_to_mark (mark
);
2518 /* Allocate a new bpstat and chain it to the current one. */
2521 bpstat_alloc (struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2525 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2527 bs
->breakpoint_at
= bl
;
2528 /* If the condition is false, etc., don't do the commands. */
2529 bs
->commands
= NULL
;
2531 bs
->print_it
= print_it_normal
;
2535 /* The target has stopped with waitstatus WS. Check if any hardware
2536 watchpoints have triggered, according to the target. */
2539 watchpoints_triggered (struct target_waitstatus
*ws
)
2541 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2543 struct breakpoint
*b
;
2545 if (!stopped_by_watchpoint
)
2547 /* We were not stopped by a watchpoint. Mark all watchpoints
2548 as not triggered. */
2550 if (b
->type
== bp_hardware_watchpoint
2551 || b
->type
== bp_read_watchpoint
2552 || b
->type
== bp_access_watchpoint
)
2553 b
->watchpoint_triggered
= watch_triggered_no
;
2558 if (!target_stopped_data_address (¤t_target
, &addr
))
2560 /* We were stopped by a watchpoint, but we don't know where.
2561 Mark all watchpoints as unknown. */
2563 if (b
->type
== bp_hardware_watchpoint
2564 || b
->type
== bp_read_watchpoint
2565 || b
->type
== bp_access_watchpoint
)
2566 b
->watchpoint_triggered
= watch_triggered_unknown
;
2568 return stopped_by_watchpoint
;
2571 /* The target could report the data address. Mark watchpoints
2572 affected by this data address as triggered, and all others as not
2576 if (b
->type
== bp_hardware_watchpoint
2577 || b
->type
== bp_read_watchpoint
2578 || b
->type
== bp_access_watchpoint
)
2582 b
->watchpoint_triggered
= watch_triggered_no
;
2583 for (v
= b
->val_chain
; v
; v
= value_next (v
))
2585 if (VALUE_LVAL (v
) == lval_memory
&& ! value_lazy (v
))
2587 struct type
*vtype
= check_typedef (value_type (v
));
2589 if (v
== b
->val_chain
2590 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2591 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2595 vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
2596 /* Exact match not required. Within range is
2599 && addr
< vaddr
+ TYPE_LENGTH (value_type (v
)))
2601 b
->watchpoint_triggered
= watch_triggered_yes
;
2612 /* Possible return values for watchpoint_check (this can't be an enum
2613 because of check_errors). */
2614 /* The watchpoint has been deleted. */
2615 #define WP_DELETED 1
2616 /* The value has changed. */
2617 #define WP_VALUE_CHANGED 2
2618 /* The value has not changed. */
2619 #define WP_VALUE_NOT_CHANGED 3
2621 #define BP_TEMPFLAG 1
2622 #define BP_HARDWAREFLAG 2
2624 /* Check watchpoint condition. */
2627 watchpoint_check (void *p
)
2629 bpstat bs
= (bpstat
) p
;
2630 struct breakpoint
*b
;
2631 struct frame_info
*fr
;
2632 int within_current_scope
;
2634 b
= bs
->breakpoint_at
->owner
;
2636 if (b
->exp_valid_block
== NULL
)
2637 within_current_scope
= 1;
2640 /* There is no current frame at this moment. If we're going to have
2641 any chance of handling watchpoints on local variables, we'll need
2642 the frame chain (so we can determine if we're in scope). */
2643 reinit_frame_cache ();
2644 fr
= frame_find_by_id (b
->watchpoint_frame
);
2645 within_current_scope
= (fr
!= NULL
);
2647 /* If we've gotten confused in the unwinder, we might have
2648 returned a frame that can't describe this variable. */
2649 if (within_current_scope
2650 && block_function (b
->exp_valid_block
) != get_frame_function (fr
))
2651 within_current_scope
= 0;
2653 /* in_function_epilogue_p() returns a non-zero value if we're still
2654 in the function but the stack frame has already been invalidated.
2655 Since we can't rely on the values of local variables after the
2656 stack has been destroyed, we are treating the watchpoint in that
2657 state as `not changed' without further checking.
2659 vinschen/2003-09-04: The former implementation left out the case
2660 that the watchpoint frame couldn't be found by frame_find_by_id()
2661 because the current PC is currently in an epilogue. Calling
2662 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2663 if ((!within_current_scope
|| fr
== get_current_frame ())
2664 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2665 return WP_VALUE_NOT_CHANGED
;
2666 if (fr
&& within_current_scope
)
2667 /* If we end up stopping, the current frame will get selected
2668 in normal_stop. So this call to select_frame won't affect
2673 if (within_current_scope
)
2675 /* We use value_{,free_to_}mark because it could be a
2676 *long* time before we return to the command level and
2677 call free_all_values. We can't call free_all_values because
2678 we might be in the middle of evaluating a function call. */
2680 struct value
*mark
= value_mark ();
2681 struct value
*new_val
= evaluate_expression (b
->exp
);
2682 if (!value_equal (b
->val
, new_val
))
2684 release_value (new_val
);
2685 value_free_to_mark (mark
);
2686 bs
->old_val
= b
->val
;
2688 /* We will stop here */
2689 return WP_VALUE_CHANGED
;
2693 /* Nothing changed, don't do anything. */
2694 value_free_to_mark (mark
);
2695 /* We won't stop here */
2696 return WP_VALUE_NOT_CHANGED
;
2701 /* This seems like the only logical thing to do because
2702 if we temporarily ignored the watchpoint, then when
2703 we reenter the block in which it is valid it contains
2704 garbage (in the case of a function, it may have two
2705 garbage values, one before and one after the prologue).
2706 So we can't even detect the first assignment to it and
2707 watch after that (since the garbage may or may not equal
2708 the first value assigned). */
2709 /* We print all the stop information in print_it_typical(), but
2710 in this case, by the time we call print_it_typical() this bp
2711 will be deleted already. So we have no choice but print the
2712 information here. */
2713 if (ui_out_is_mi_like_p (uiout
))
2715 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2716 ui_out_text (uiout
, "\nWatchpoint ");
2717 ui_out_field_int (uiout
, "wpnum", b
->number
);
2718 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2719 which its expression is valid.\n");
2721 if (b
->related_breakpoint
)
2722 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2723 b
->disposition
= disp_del_at_next_stop
;
2729 /* Get a bpstat associated with having just stopped at address
2730 BP_ADDR in thread PTID.
2732 Determine whether we stopped at a breakpoint, etc, or whether we
2733 don't understand this stop. Result is a chain of bpstat's such that:
2735 if we don't understand the stop, the result is a null pointer.
2737 if we understand why we stopped, the result is not null.
2739 Each element of the chain refers to a particular breakpoint or
2740 watchpoint at which we have stopped. (We may have stopped for
2741 several reasons concurrently.)
2743 Each element of the chain has valid next, breakpoint_at,
2744 commands, FIXME??? fields. */
2747 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
2749 struct breakpoint
*b
= NULL
;
2750 struct bp_location
*bl
;
2751 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2752 int real_breakpoint
= 0;
2753 /* Root of the chain of bpstat's */
2754 struct bpstats root_bs
[1];
2755 /* Pointer to the last thing in the chain currently. */
2756 bpstat bs
= root_bs
;
2757 int thread_id
= pid_to_thread_id (ptid
);
2759 ALL_BP_LOCATIONS (bl
)
2763 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2766 if (b
->type
!= bp_watchpoint
2767 && b
->type
!= bp_hardware_watchpoint
2768 && b
->type
!= bp_read_watchpoint
2769 && b
->type
!= bp_access_watchpoint
2770 && b
->type
!= bp_hardware_breakpoint
2771 && b
->type
!= bp_catch_fork
2772 && b
->type
!= bp_catch_vfork
2773 && b
->type
!= bp_catch_exec
2774 && b
->type
!= bp_catch_catch
2775 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2777 if (bl
->address
!= bp_addr
) /* address doesn't match */
2779 if (overlay_debugging
/* unmapped overlay section */
2780 && section_is_overlay (bl
->section
)
2781 && !section_is_mapped (bl
->section
))
2785 /* Continuable hardware watchpoints are treated as non-existent if the
2786 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2787 some data address). Otherwise gdb won't stop on a break instruction
2788 in the code (not from a breakpoint) when a hardware watchpoint has
2789 been defined. Also skip watchpoints which we know did not trigger
2790 (did not match the data address). */
2792 if ((b
->type
== bp_hardware_watchpoint
2793 || b
->type
== bp_read_watchpoint
2794 || b
->type
== bp_access_watchpoint
)
2795 && b
->watchpoint_triggered
== watch_triggered_no
)
2798 if (b
->type
== bp_hardware_breakpoint
)
2800 if (bl
->address
!= bp_addr
)
2802 if (overlay_debugging
/* unmapped overlay section */
2803 && section_is_overlay (bl
->section
)
2804 && !section_is_mapped (bl
->section
))
2808 /* Is this a catchpoint of a load or unload? If so, did we
2809 get a load or unload of the specified library? If not,
2811 if ((b
->type
== bp_catch_load
)
2812 #if defined(SOLIB_HAVE_LOAD_EVENT)
2813 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2814 || ((b
->dll_pathname
!= NULL
)
2815 && (strcmp (b
->dll_pathname
,
2816 SOLIB_LOADED_LIBRARY_PATHNAME (
2817 PIDGET (inferior_ptid
)))
2823 if ((b
->type
== bp_catch_unload
)
2824 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2825 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2826 || ((b
->dll_pathname
!= NULL
)
2827 && (strcmp (b
->dll_pathname
,
2828 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2829 PIDGET (inferior_ptid
)))
2835 if ((b
->type
== bp_catch_fork
)
2836 && !inferior_has_forked (PIDGET (inferior_ptid
),
2837 &b
->forked_inferior_pid
))
2840 if ((b
->type
== bp_catch_vfork
)
2841 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2842 &b
->forked_inferior_pid
))
2845 if ((b
->type
== bp_catch_exec
)
2846 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2849 if (ep_is_exception_catchpoint (b
) &&
2850 !(current_exception_event
= target_get_current_exception_event ()))
2853 /* Come here if it's a watchpoint, or if the break address matches */
2855 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
2857 /* Watchpoints may change this, if not found to have triggered. */
2861 if (b
->type
== bp_watchpoint
2862 || b
->type
== bp_read_watchpoint
2863 || b
->type
== bp_access_watchpoint
2864 || b
->type
== bp_hardware_watchpoint
)
2868 int must_check_value
= 0;
2870 if (b
->type
== bp_watchpoint
)
2871 /* For a software watchpoint, we must always check the
2873 must_check_value
= 1;
2874 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2875 /* We have a hardware watchpoint (read, write, or access)
2876 and the target earlier reported an address watched by
2878 must_check_value
= 1;
2879 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2880 && b
->type
== bp_hardware_watchpoint
)
2881 /* We were stopped by a hardware watchpoint, but the target could
2882 not report the data address. We must check the watchpoint's
2883 value. Access and read watchpoints are out of luck; without
2884 a data address, we can't figure it out. */
2885 must_check_value
= 1;
2887 if (must_check_value
)
2889 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2891 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2892 int e
= catch_errors (watchpoint_check
, bs
, message
,
2894 do_cleanups (cleanups
);
2898 /* We've already printed what needs to be printed. */
2899 bs
->print_it
= print_it_done
;
2902 case WP_VALUE_CHANGED
:
2903 if (b
->type
== bp_read_watchpoint
)
2905 /* Don't stop: read watchpoints shouldn't fire if
2906 the value has changed. This is for targets
2907 which cannot set read-only watchpoints. */
2908 bs
->print_it
= print_it_noop
;
2914 case WP_VALUE_NOT_CHANGED
:
2915 if (b
->type
== bp_hardware_watchpoint
2916 || b
->type
== bp_watchpoint
)
2918 /* Don't stop: write watchpoints shouldn't fire if
2919 the value hasn't changed. */
2920 bs
->print_it
= print_it_noop
;
2930 /* Error from catch_errors. */
2931 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2932 if (b
->related_breakpoint
)
2933 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2934 b
->disposition
= disp_del_at_next_stop
;
2935 /* We've already printed what needs to be printed. */
2936 bs
->print_it
= print_it_done
;
2940 else /* must_check_value == 0 */
2942 /* This is a case where some watchpoint(s) triggered, but
2943 not at the address of this watchpoint, or else no
2944 watchpoint triggered after all. So don't print
2945 anything for this watchpoint. */
2946 bs
->print_it
= print_it_noop
;
2953 /* By definition, an encountered breakpoint is a triggered
2957 real_breakpoint
= 1;
2960 if (frame_id_p (b
->frame_id
)
2961 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2965 int value_is_zero
= 0;
2967 /* If this is a scope breakpoint, mark the associated
2968 watchpoint as triggered so that we will handle the
2969 out-of-scope event. We'll get to the watchpoint next
2971 if (b
->type
== bp_watchpoint_scope
)
2972 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2976 /* Need to select the frame, with all that implies
2977 so that the conditions will have the right context. */
2978 select_frame (get_current_frame ());
2980 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2981 "Error in testing breakpoint condition:\n",
2983 /* FIXME-someday, should give breakpoint # */
2986 if (bl
->cond
&& value_is_zero
)
2989 /* Don't consider this a hit. */
2992 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2995 /* Don't consider this a hit. */
2998 else if (b
->ignore_count
> 0)
3001 annotate_ignore_count_change ();
3004 else if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3005 /* We do not stop for these. */
3009 /* We will stop here */
3010 if (b
->disposition
== disp_disable
)
3011 b
->enable_state
= bp_disabled
;
3014 bs
->commands
= b
->commands
;
3016 (strcmp ("silent", bs
->commands
->line
) == 0
3017 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3019 bs
->commands
= bs
->commands
->next
;
3022 bs
->commands
= copy_command_lines (bs
->commands
);
3025 /* Print nothing for this entry if we dont stop or if we dont print. */
3026 if (bs
->stop
== 0 || bs
->print
== 0)
3027 bs
->print_it
= print_it_noop
;
3030 bs
->next
= NULL
; /* Terminate the chain */
3031 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3033 /* If we aren't stopping, the value of some hardware watchpoint may
3034 not have changed, but the intermediate memory locations we are
3035 watching may have. Don't bother if we're stopping; this will get
3037 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3042 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3044 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3045 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3046 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3048 remove_breakpoints ();
3049 insert_breakpoints ();
3053 return root_bs
->next
;
3056 /* Tell what to do about this bpstat. */
3058 bpstat_what (bpstat bs
)
3060 /* Classify each bpstat as one of the following. */
3063 /* This bpstat element has no effect on the main_action. */
3066 /* There was a watchpoint, stop but don't print. */
3069 /* There was a watchpoint, stop and print. */
3072 /* There was a breakpoint but we're not stopping. */
3075 /* There was a breakpoint, stop but don't print. */
3078 /* There was a breakpoint, stop and print. */
3081 /* We hit the longjmp breakpoint. */
3084 /* We hit the longjmp_resume breakpoint. */
3087 /* We hit the step_resume breakpoint. */
3090 /* We hit the shared library event breakpoint. */
3093 /* We caught a shared library event. */
3096 /* This is just used to count how many enums there are. */
3100 /* Here is the table which drives this routine. So that we can
3101 format it pretty, we define some abbreviations for the
3102 enum bpstat_what codes. */
3103 #define kc BPSTAT_WHAT_KEEP_CHECKING
3104 #define ss BPSTAT_WHAT_STOP_SILENT
3105 #define sn BPSTAT_WHAT_STOP_NOISY
3106 #define sgl BPSTAT_WHAT_SINGLE
3107 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3108 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3109 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
3110 #define sr BPSTAT_WHAT_STEP_RESUME
3111 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3112 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3114 /* "Can't happen." Might want to print an error message.
3115 abort() is not out of the question, but chances are GDB is just
3116 a bit confused, not unusable. */
3117 #define err BPSTAT_WHAT_STOP_NOISY
3119 /* Given an old action and a class, come up with a new action. */
3120 /* One interesting property of this table is that wp_silent is the same
3121 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3122 after stopping, the check for whether to step over a breakpoint
3123 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3124 reference to how we stopped. We retain separate wp_silent and
3125 bp_silent codes in case we want to change that someday.
3127 Another possibly interesting property of this table is that
3128 there's a partial ordering, priority-like, of the actions. Once
3129 you've decided that some action is appropriate, you'll never go
3130 back and decide something of a lower priority is better. The
3133 kc < clr sgl shl shlr slr sn sr ss
3134 sgl < clrs shl shlr slr sn sr ss
3135 slr < err shl shlr sn sr ss
3136 clr < clrs err shl shlr sn sr ss
3137 clrs < err shl shlr sn sr ss
3144 What I think this means is that we don't need a damned table
3145 here. If you just put the rows and columns in the right order,
3146 it'd look awfully regular. We could simply walk the bpstat list
3147 and choose the highest priority action we find, with a little
3148 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3149 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3150 is messy anyway). */
3152 /* step_resume entries: a step resume breakpoint overrides another
3153 breakpoint of signal handling (see comment in wait_for_inferior
3154 at where we set the step_resume breakpoint). */
3156 static const enum bpstat_what_main_action
3157 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3160 /* kc ss sn sgl slr clr clrs sr shl shlr
3163 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, shl
, shlr
},
3165 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3167 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3169 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, shl
, shlr
},
3171 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, shl
, shlr
},
3173 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3175 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, shl
, shlr
},
3177 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, shl
, shlr
},
3179 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3181 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3183 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3198 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3199 struct bpstat_what retval
;
3201 retval
.call_dummy
= 0;
3202 for (; bs
!= NULL
; bs
= bs
->next
)
3204 enum class bs_class
= no_effect
;
3205 if (bs
->breakpoint_at
== NULL
)
3206 /* I suspect this can happen if it was a momentary breakpoint
3207 which has since been deleted. */
3209 switch (bs
->breakpoint_at
->owner
->type
)
3215 case bp_hardware_breakpoint
:
3221 bs_class
= bp_noisy
;
3223 bs_class
= bp_silent
;
3226 bs_class
= bp_nostop
;
3229 case bp_hardware_watchpoint
:
3230 case bp_read_watchpoint
:
3231 case bp_access_watchpoint
:
3235 bs_class
= wp_noisy
;
3237 bs_class
= wp_silent
;
3240 /* There was a watchpoint, but we're not stopping.
3241 This requires no further action. */
3242 bs_class
= no_effect
;
3245 bs_class
= long_jump
;
3247 case bp_longjmp_resume
:
3248 bs_class
= long_resume
;
3250 case bp_step_resume
:
3253 bs_class
= step_resume
;
3256 /* It is for the wrong frame. */
3257 bs_class
= bp_nostop
;
3259 case bp_watchpoint_scope
:
3260 bs_class
= bp_nostop
;
3262 case bp_shlib_event
:
3263 bs_class
= shlib_event
;
3265 case bp_thread_event
:
3266 case bp_overlay_event
:
3267 bs_class
= bp_nostop
;
3270 case bp_catch_unload
:
3271 /* Only if this catchpoint triggered should we cause the
3272 step-out-of-dld behaviour. Otherwise, we ignore this
3275 bs_class
= catch_shlib_event
;
3277 bs_class
= no_effect
;
3280 case bp_catch_vfork
:
3285 bs_class
= bp_noisy
;
3287 bs_class
= bp_silent
;
3290 /* There was a catchpoint, but we're not stopping.
3291 This requires no further action. */
3292 bs_class
= no_effect
;
3294 case bp_catch_catch
:
3295 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
3296 bs_class
= bp_nostop
;
3298 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3300 case bp_catch_throw
:
3301 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3302 bs_class
= bp_nostop
;
3304 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3307 /* Make sure the action is stop (silent or noisy),
3308 so infrun.c pops the dummy frame. */
3309 bs_class
= bp_silent
;
3310 retval
.call_dummy
= 1;
3313 current_action
= table
[(int) bs_class
][(int) current_action
];
3315 retval
.main_action
= current_action
;
3319 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3320 without hardware support). This isn't related to a specific bpstat,
3321 just to things like whether watchpoints are set. */
3324 bpstat_should_step (void)
3326 struct breakpoint
*b
;
3328 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3333 /* Nonzero if there are enabled hardware watchpoints. */
3335 bpstat_have_active_hw_watchpoints (void)
3337 struct bp_location
*bpt
;
3338 ALL_BP_LOCATIONS (bpt
)
3339 if (breakpoint_enabled (bpt
->owner
)
3341 && bpt
->loc_type
== bp_loc_hardware_watchpoint
)
3347 /* Given a bpstat that records zero or more triggered eventpoints, this
3348 function returns another bpstat which contains only the catchpoints
3349 on that first list, if any. */
3351 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3353 struct bpstats root_bs
[1];
3354 bpstat bs
= root_bs
;
3355 struct breakpoint
*ep
;
3358 bpstat_clear (cp_list
);
3359 root_bs
->next
= NULL
;
3361 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3363 /* Is this eventpoint a catchpoint? If not, ignore it. */
3364 ep
= ep_list
->breakpoint_at
->owner
;
3367 if ((ep
->type
!= bp_catch_load
) &&
3368 (ep
->type
!= bp_catch_unload
) &&
3369 (ep
->type
!= bp_catch_catch
) &&
3370 (ep
->type
!= bp_catch_throw
))
3371 /* pai: (temp) ADD fork/vfork here!! */
3374 /* Yes; add it to the list. */
3375 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3380 #if defined(SOLIB_ADD)
3381 /* Also, for each triggered catchpoint, tag it with the name of
3382 the library that caused this trigger. (We copy the name now,
3383 because it's only guaranteed to be available NOW, when the
3384 catchpoint triggers. Clients who may wish to know the name
3385 later must get it from the catchpoint itself.) */
3386 if (ep
->triggered_dll_pathname
!= NULL
)
3387 xfree (ep
->triggered_dll_pathname
);
3388 if (ep
->type
== bp_catch_load
)
3389 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3390 PIDGET (inferior_ptid
));
3392 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3393 PIDGET (inferior_ptid
));
3395 dll_pathname
= NULL
;
3399 ep
->triggered_dll_pathname
= (char *)
3400 xmalloc (strlen (dll_pathname
) + 1);
3401 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3404 ep
->triggered_dll_pathname
= NULL
;
3410 static void print_breakpoint_location (struct breakpoint
*b
,
3411 struct bp_location
*loc
,
3413 struct ui_stream
*stb
)
3418 = find_pc_sect_function (loc
->address
, loc
->section
);
3421 ui_out_text (uiout
, "in ");
3422 ui_out_field_string (uiout
, "func",
3423 SYMBOL_PRINT_NAME (sym
));
3424 ui_out_wrap_hint (uiout
, wrap_indent
);
3425 ui_out_text (uiout
, " at ");
3427 ui_out_field_string (uiout
, "file", b
->source_file
);
3428 ui_out_text (uiout
, ":");
3430 if (ui_out_is_mi_like_p (uiout
))
3432 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3433 char *fullname
= symtab_to_fullname (sal
.symtab
);
3436 ui_out_field_string (uiout
, "fullname", fullname
);
3439 ui_out_field_int (uiout
, "line", b
->line_number
);
3443 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3447 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3448 ui_out_field_stream (uiout
, "at", stb
);
3452 /* Print B to gdb_stdout. */
3454 print_one_breakpoint_location (struct breakpoint
*b
,
3455 struct bp_location
*loc
,
3457 CORE_ADDR
*last_addr
)
3459 struct command_line
*l
;
3461 struct ep_type_description
3466 static struct ep_type_description bptypes
[] =
3468 {bp_none
, "?deleted?"},
3469 {bp_breakpoint
, "breakpoint"},
3470 {bp_hardware_breakpoint
, "hw breakpoint"},
3471 {bp_until
, "until"},
3472 {bp_finish
, "finish"},
3473 {bp_watchpoint
, "watchpoint"},
3474 {bp_hardware_watchpoint
, "hw watchpoint"},
3475 {bp_read_watchpoint
, "read watchpoint"},
3476 {bp_access_watchpoint
, "acc watchpoint"},
3477 {bp_longjmp
, "longjmp"},
3478 {bp_longjmp_resume
, "longjmp resume"},
3479 {bp_step_resume
, "step resume"},
3480 {bp_watchpoint_scope
, "watchpoint scope"},
3481 {bp_call_dummy
, "call dummy"},
3482 {bp_shlib_event
, "shlib events"},
3483 {bp_thread_event
, "thread events"},
3484 {bp_overlay_event
, "overlay events"},
3485 {bp_catch_load
, "catch load"},
3486 {bp_catch_unload
, "catch unload"},
3487 {bp_catch_fork
, "catch fork"},
3488 {bp_catch_vfork
, "catch vfork"},
3489 {bp_catch_exec
, "catch exec"},
3490 {bp_catch_catch
, "catch catch"},
3491 {bp_catch_throw
, "catch throw"}
3494 static char *bpdisps
[] =
3495 {"del", "dstp", "dis", "keep"};
3496 static char bpenables
[] = "nynny";
3497 char wrap_indent
[80];
3498 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3499 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3500 struct cleanup
*bkpt_chain
;
3502 int header_of_multiple
= 0;
3503 int part_of_multiple
= (loc
!= NULL
);
3505 gdb_assert (!loc
|| loc_number
!= 0);
3506 /* See comment in print_one_breakpoint concerning
3507 treatment of breakpoints with single disabled
3511 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3512 header_of_multiple
= 1;
3517 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3521 if (part_of_multiple
)
3524 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3525 ui_out_field_string (uiout
, "number", formatted
);
3530 ui_out_field_int (uiout
, "number", b
->number
);
3535 if (part_of_multiple
)
3536 ui_out_field_skip (uiout
, "type");
3539 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3540 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3541 internal_error (__FILE__
, __LINE__
,
3542 _("bptypes table does not describe type #%d."),
3544 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3549 if (part_of_multiple
)
3550 ui_out_field_skip (uiout
, "disp");
3552 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3557 if (part_of_multiple
)
3558 ui_out_field_string (uiout
, "enabled",
3560 ? (loc
->enabled
? "y(p)" : "n(p)")
3561 : (loc
->enabled
? "y" : "n"));
3564 int pending
= (b
->loc
== NULL
|| b
->loc
->shlib_disabled
);
3565 /* For header of multiple, there's no point showing pending
3566 state -- it will be apparent from the locations. */
3567 if (header_of_multiple
)
3569 ui_out_field_fmt (uiout
, "enabled", "%c%s",
3570 bpenables
[(int) b
->enable_state
],
3571 pending
? "(p)" : "");
3573 ui_out_spaces (uiout
, 3);
3578 strcpy (wrap_indent
, " ");
3581 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3582 strcat (wrap_indent
, " ");
3584 strcat (wrap_indent
, " ");
3587 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3589 /* Although the print_one can possibly print
3590 all locations, calling it here is not likely
3591 to get any nice result. So, make sure there's
3592 just one location. */
3593 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3594 b
->ops
->print_one (b
, last_addr
);
3600 internal_error (__FILE__
, __LINE__
,
3601 _("print_one_breakpoint: bp_none encountered\n"));
3605 case bp_hardware_watchpoint
:
3606 case bp_read_watchpoint
:
3607 case bp_access_watchpoint
:
3608 /* Field 4, the address, is omitted (which makes the columns
3609 not line up too nicely with the headers, but the effect
3610 is relatively readable). */
3612 ui_out_field_skip (uiout
, "addr");
3614 print_expression (b
->exp
, stb
->stream
);
3615 ui_out_field_stream (uiout
, "what", stb
);
3619 case bp_catch_unload
:
3620 /* Field 4, the address, is omitted (which makes the columns
3621 not line up too nicely with the headers, but the effect
3622 is relatively readable). */
3624 ui_out_field_skip (uiout
, "addr");
3626 if (b
->dll_pathname
== NULL
)
3628 ui_out_field_string (uiout
, "what", "<any library>");
3629 ui_out_spaces (uiout
, 1);
3633 ui_out_text (uiout
, "library \"");
3634 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3635 ui_out_text (uiout
, "\" ");
3640 case bp_catch_vfork
:
3641 /* Field 4, the address, is omitted (which makes the columns
3642 not line up too nicely with the headers, but the effect
3643 is relatively readable). */
3645 ui_out_field_skip (uiout
, "addr");
3647 if (b
->forked_inferior_pid
!= 0)
3649 ui_out_text (uiout
, "process ");
3650 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3651 ui_out_spaces (uiout
, 1);
3656 /* Field 4, the address, is omitted (which makes the columns
3657 not line up too nicely with the headers, but the effect
3658 is relatively readable). */
3660 ui_out_field_skip (uiout
, "addr");
3662 if (b
->exec_pathname
!= NULL
)
3664 ui_out_text (uiout
, "program \"");
3665 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3666 ui_out_text (uiout
, "\" ");
3670 case bp_catch_catch
:
3671 /* Field 4, the address, is omitted (which makes the columns
3672 not line up too nicely with the headers, but the effect
3673 is relatively readable). */
3675 ui_out_field_skip (uiout
, "addr");
3677 ui_out_field_string (uiout
, "what", "exception catch");
3678 ui_out_spaces (uiout
, 1);
3681 case bp_catch_throw
:
3682 /* Field 4, the address, is omitted (which makes the columns
3683 not line up too nicely with the headers, but the effect
3684 is relatively readable). */
3686 ui_out_field_skip (uiout
, "addr");
3688 ui_out_field_string (uiout
, "what", "exception throw");
3689 ui_out_spaces (uiout
, 1);
3693 case bp_hardware_breakpoint
:
3697 case bp_longjmp_resume
:
3698 case bp_step_resume
:
3699 case bp_watchpoint_scope
:
3701 case bp_shlib_event
:
3702 case bp_thread_event
:
3703 case bp_overlay_event
:
3708 ui_out_field_string (uiout
, "addr", "<PENDING>");
3709 else if (header_of_multiple
)
3710 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3712 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3715 if (!header_of_multiple
)
3716 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3718 *last_addr
= b
->loc
->address
;
3722 if (!part_of_multiple
&& b
->thread
!= -1)
3724 /* FIXME: This seems to be redundant and lost here; see the
3725 "stop only in" line a little further down. */
3726 ui_out_text (uiout
, " thread ");
3727 ui_out_field_int (uiout
, "thread", b
->thread
);
3730 ui_out_text (uiout
, "\n");
3732 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3735 ui_out_text (uiout
, "\tstop only in stack frame at ");
3736 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3738 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3739 ui_out_text (uiout
, "\n");
3742 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3744 /* We do not print the condition for Ada exception catchpoints
3745 because the condition is an internal implementation detail
3746 that we do not want to expose to the user. */
3748 ui_out_text (uiout
, "\tstop only if ");
3749 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3750 ui_out_text (uiout
, "\n");
3753 if (!part_of_multiple
&& b
->thread
!= -1)
3755 /* FIXME should make an annotation for this */
3756 ui_out_text (uiout
, "\tstop only in thread ");
3757 ui_out_field_int (uiout
, "thread", b
->thread
);
3758 ui_out_text (uiout
, "\n");
3761 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3763 /* FIXME should make an annotation for this */
3764 if (ep_is_catchpoint (b
))
3765 ui_out_text (uiout
, "\tcatchpoint");
3767 ui_out_text (uiout
, "\tbreakpoint");
3768 ui_out_text (uiout
, " already hit ");
3769 ui_out_field_int (uiout
, "times", b
->hit_count
);
3770 if (b
->hit_count
== 1)
3771 ui_out_text (uiout
, " time\n");
3773 ui_out_text (uiout
, " times\n");
3776 /* Output the count also if it is zero, but only if this is
3777 mi. FIXME: Should have a better test for this. */
3778 if (ui_out_is_mi_like_p (uiout
))
3779 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3780 ui_out_field_int (uiout
, "times", b
->hit_count
);
3782 if (!part_of_multiple
&& b
->ignore_count
)
3785 ui_out_text (uiout
, "\tignore next ");
3786 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3787 ui_out_text (uiout
, " hits\n");
3790 if (!part_of_multiple
&& (l
= b
->commands
))
3792 struct cleanup
*script_chain
;
3795 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3796 print_command_lines (uiout
, l
, 4);
3797 do_cleanups (script_chain
);
3799 do_cleanups (bkpt_chain
);
3800 do_cleanups (old_chain
);
3804 print_one_breakpoint (struct breakpoint
*b
,
3805 CORE_ADDR
*last_addr
)
3807 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3809 /* If this breakpoint has custom print function,
3810 it's already printed. Otherwise, print individual
3811 locations, if any. */
3812 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3814 /* If breakpoint has a single location that is
3815 disabled, we print it as if it had
3816 several locations, since otherwise it's hard to
3817 represent "breakpoint enabled, location disabled"
3820 && (b
->loc
->next
|| !b
->loc
->enabled
)
3821 && !ui_out_is_mi_like_p (uiout
))
3823 struct bp_location
*loc
;
3825 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3826 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3832 struct captured_breakpoint_query_args
3838 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3840 struct captured_breakpoint_query_args
*args
= data
;
3841 struct breakpoint
*b
;
3842 CORE_ADDR dummy_addr
= 0;
3845 if (args
->bnum
== b
->number
)
3847 print_one_breakpoint (b
, &dummy_addr
);
3855 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3857 struct captured_breakpoint_query_args args
;
3859 /* For the moment we don't trust print_one_breakpoint() to not throw
3861 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3862 error_message
, RETURN_MASK_ALL
) < 0)
3868 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3869 catchpoints, et.al.). */
3872 user_settable_breakpoint (const struct breakpoint
*b
)
3874 return (b
->type
== bp_breakpoint
3875 || b
->type
== bp_catch_load
3876 || b
->type
== bp_catch_unload
3877 || b
->type
== bp_catch_fork
3878 || b
->type
== bp_catch_vfork
3879 || b
->type
== bp_catch_exec
3880 || b
->type
== bp_catch_catch
3881 || b
->type
== bp_catch_throw
3882 || b
->type
== bp_hardware_breakpoint
3883 || b
->type
== bp_watchpoint
3884 || b
->type
== bp_read_watchpoint
3885 || b
->type
== bp_access_watchpoint
3886 || b
->type
== bp_hardware_watchpoint
);
3889 /* Print information on user settable breakpoint (watchpoint, etc)
3890 number BNUM. If BNUM is -1 print all user settable breakpoints.
3891 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3894 breakpoint_1 (int bnum
, int allflag
)
3896 struct breakpoint
*b
;
3897 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3898 int nr_printable_breakpoints
;
3899 struct cleanup
*bkpttbl_chain
;
3901 /* Compute the number of rows in the table. */
3902 nr_printable_breakpoints
= 0;
3905 || bnum
== b
->number
)
3907 if (allflag
|| user_settable_breakpoint (b
))
3908 nr_printable_breakpoints
++;
3913 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3917 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3920 if (nr_printable_breakpoints
> 0)
3921 annotate_breakpoints_headers ();
3922 if (nr_printable_breakpoints
> 0)
3924 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3925 if (nr_printable_breakpoints
> 0)
3927 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3928 if (nr_printable_breakpoints
> 0)
3930 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3931 if (nr_printable_breakpoints
> 0)
3933 ui_out_table_header (uiout
, 4, ui_left
, "enabled", "Enb"); /* 4 */
3936 if (nr_printable_breakpoints
> 0)
3938 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3939 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3941 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3943 if (nr_printable_breakpoints
> 0)
3945 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3946 ui_out_table_body (uiout
);
3947 if (nr_printable_breakpoints
> 0)
3948 annotate_breakpoints_table ();
3952 || bnum
== b
->number
)
3954 /* We only print out user settable breakpoints unless the
3956 if (allflag
|| user_settable_breakpoint (b
))
3957 print_one_breakpoint (b
, &last_addr
);
3960 do_cleanups (bkpttbl_chain
);
3962 if (nr_printable_breakpoints
== 0)
3965 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3967 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3972 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3973 that a comparison of an unsigned with -1 is always false. */
3974 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
3975 set_next_address (last_addr
);
3978 /* FIXME? Should this be moved up so that it is only called when
3979 there have been breakpoints? */
3980 annotate_breakpoints_table_end ();
3984 breakpoints_info (char *bnum_exp
, int from_tty
)
3989 bnum
= parse_and_eval_long (bnum_exp
);
3991 breakpoint_1 (bnum
, 0);
3995 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4000 bnum
= parse_and_eval_long (bnum_exp
);
4002 breakpoint_1 (bnum
, 1);
4006 breakpoint_has_pc (struct breakpoint
*b
, CORE_ADDR pc
, asection
*section
)
4008 struct bp_location
*bl
= b
->loc
;
4009 for (; bl
; bl
= bl
->next
)
4011 if (bl
->address
== pc
4012 && (!overlay_debugging
|| bl
->section
== section
))
4018 /* Print a message describing any breakpoints set at PC. */
4021 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
4024 struct breakpoint
*b
;
4027 others
+= breakpoint_has_pc (b
, pc
, section
);
4031 printf_filtered (_("Note: breakpoint "));
4032 else /* if (others == ???) */
4033 printf_filtered (_("Note: breakpoints "));
4035 if (breakpoint_has_pc (b
, pc
, section
))
4038 printf_filtered ("%d", b
->number
);
4039 if (b
->thread
== -1 && thread
!= -1)
4040 printf_filtered (" (all threads)");
4041 else if (b
->thread
!= -1)
4042 printf_filtered (" (thread %d)", b
->thread
);
4043 printf_filtered ("%s%s ",
4044 ((b
->enable_state
== bp_disabled
||
4045 b
->enable_state
== bp_call_disabled
)
4047 : b
->enable_state
== bp_permanent
4051 : ((others
== 1) ? " and" : ""));
4053 printf_filtered (_("also set at pc "));
4054 deprecated_print_address_numeric (pc
, 1, gdb_stdout
);
4055 printf_filtered (".\n");
4059 /* Set the default place to put a breakpoint
4060 for the `break' command with no arguments. */
4063 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4066 default_breakpoint_valid
= valid
;
4067 default_breakpoint_address
= addr
;
4068 default_breakpoint_symtab
= symtab
;
4069 default_breakpoint_line
= line
;
4072 /* Return true iff it is meaningful to use the address member of
4073 BPT. For some breakpoint types, the address member is irrelevant
4074 and it makes no sense to attempt to compare it to other addresses
4075 (or use it for any other purpose either).
4077 More specifically, each of the following breakpoint types will always
4078 have a zero valued address and we don't want check_duplicates() to mark
4079 breakpoints of any of these types to be a duplicate of an actual
4080 breakpoint at address zero:
4083 bp_hardware_watchpoint
4085 bp_access_watchpoint
4092 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4094 enum bptype type
= bpt
->type
;
4096 return (type
!= bp_watchpoint
4097 && type
!= bp_hardware_watchpoint
4098 && type
!= bp_read_watchpoint
4099 && type
!= bp_access_watchpoint
4100 && type
!= bp_catch_exec
4101 && type
!= bp_longjmp_resume
4102 && type
!= bp_catch_fork
4103 && type
!= bp_catch_vfork
);
4106 /* Rescan breakpoints at the same address and section as BPT,
4107 marking the first one as "first" and any others as "duplicates".
4108 This is so that the bpt instruction is only inserted once.
4109 If we have a permanent breakpoint at the same place as BPT, make
4110 that one the official one, and the rest as duplicates. */
4113 check_duplicates_for (CORE_ADDR address
, asection
*section
)
4115 struct bp_location
*b
;
4117 struct bp_location
*perm_bp
= 0;
4119 ALL_BP_LOCATIONS (b
)
4120 if (b
->owner
->enable_state
!= bp_disabled
4121 && b
->owner
->enable_state
!= bp_call_disabled
4123 && !b
->shlib_disabled
4124 && b
->address
== address
/* address / overlay match */
4125 && (!overlay_debugging
|| b
->section
== section
)
4126 && breakpoint_address_is_meaningful (b
->owner
))
4128 /* Have we found a permanent breakpoint? */
4129 if (b
->owner
->enable_state
== bp_permanent
)
4136 b
->duplicate
= count
> 1;
4139 /* If we found a permanent breakpoint at this address, go over the
4140 list again and declare all the other breakpoints there to be the
4144 perm_bp
->duplicate
= 0;
4146 /* Permanent breakpoint should always be inserted. */
4147 if (! perm_bp
->inserted
)
4148 internal_error (__FILE__
, __LINE__
,
4149 _("allegedly permanent breakpoint is not "
4150 "actually inserted"));
4152 ALL_BP_LOCATIONS (b
)
4155 if (b
->owner
->enable_state
!= bp_disabled
4156 && b
->owner
->enable_state
!= bp_call_disabled
4157 && b
->enabled
&& !b
->shlib_disabled
4158 && b
->address
== address
/* address / overlay match */
4159 && (!overlay_debugging
|| b
->section
== section
)
4160 && breakpoint_address_is_meaningful (b
->owner
))
4163 internal_error (__FILE__
, __LINE__
,
4164 _("another breakpoint was inserted on top of "
4165 "a permanent breakpoint"));
4174 check_duplicates (struct breakpoint
*bpt
)
4176 struct bp_location
*bl
= bpt
->loc
;
4178 if (! breakpoint_address_is_meaningful (bpt
))
4181 for (; bl
; bl
= bl
->next
)
4182 check_duplicates_for (bl
->address
, bl
->section
);
4186 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4187 int bnum
, int have_bnum
)
4192 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4193 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4195 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4196 bnum
, astr1
, astr2
);
4198 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4201 /* Adjust a breakpoint's address to account for architectural constraints
4202 on breakpoint placement. Return the adjusted address. Note: Very
4203 few targets require this kind of adjustment. For most targets,
4204 this function is simply the identity function. */
4207 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4209 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4211 /* Very few targets need any kind of breakpoint adjustment. */
4214 else if (bptype
== bp_watchpoint
4215 || bptype
== bp_hardware_watchpoint
4216 || bptype
== bp_read_watchpoint
4217 || bptype
== bp_access_watchpoint
4218 || bptype
== bp_catch_fork
4219 || bptype
== bp_catch_vfork
4220 || bptype
== bp_catch_exec
)
4222 /* Watchpoints and the various bp_catch_* eventpoints should not
4223 have their addresses modified. */
4228 CORE_ADDR adjusted_bpaddr
;
4230 /* Some targets have architectural constraints on the placement
4231 of breakpoint instructions. Obtain the adjusted address. */
4232 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4235 /* An adjusted breakpoint address can significantly alter
4236 a user's expectations. Print a warning if an adjustment
4238 if (adjusted_bpaddr
!= bpaddr
)
4239 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4241 return adjusted_bpaddr
;
4245 /* Allocate a struct bp_location. */
4247 static struct bp_location
*
4248 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4250 struct bp_location
*loc
, *loc_p
;
4252 loc
= xmalloc (sizeof (struct bp_location
));
4253 memset (loc
, 0, sizeof (*loc
));
4257 loc
->shlib_disabled
= 0;
4266 case bp_longjmp_resume
:
4267 case bp_step_resume
:
4268 case bp_watchpoint_scope
:
4270 case bp_shlib_event
:
4271 case bp_thread_event
:
4272 case bp_overlay_event
:
4274 case bp_catch_unload
:
4275 loc
->loc_type
= bp_loc_software_breakpoint
;
4277 case bp_hardware_breakpoint
:
4278 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4280 case bp_hardware_watchpoint
:
4281 case bp_read_watchpoint
:
4282 case bp_access_watchpoint
:
4283 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4287 case bp_catch_vfork
:
4289 case bp_catch_catch
:
4290 case bp_catch_throw
:
4291 loc
->loc_type
= bp_loc_other
;
4294 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4297 /* Add this breakpoint to the end of the chain. */
4299 loc_p
= bp_location_chain
;
4301 bp_location_chain
= loc
;
4304 while (loc_p
->global_next
)
4305 loc_p
= loc_p
->global_next
;
4306 loc_p
->global_next
= loc
;
4312 static void free_bp_location (struct bp_location
*loc
)
4319 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4320 that has type BPTYPE and has no locations as yet. */
4322 static struct breakpoint
*
4323 set_raw_breakpoint_without_location (enum bptype bptype
)
4325 struct breakpoint
*b
, *b1
;
4327 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4328 memset (b
, 0, sizeof (*b
));
4331 b
->language
= current_language
->la_language
;
4332 b
->input_radix
= input_radix
;
4334 b
->enable_state
= bp_enabled
;
4337 b
->ignore_count
= 0;
4339 b
->frame_id
= null_frame_id
;
4340 b
->dll_pathname
= NULL
;
4341 b
->triggered_dll_pathname
= NULL
;
4342 b
->forked_inferior_pid
= 0;
4343 b
->exec_pathname
= NULL
;
4345 b
->condition_not_parsed
= 0;
4347 /* Add this breakpoint to the end of the chain
4348 so that a list of breakpoints will come out in order
4349 of increasing numbers. */
4351 b1
= breakpoint_chain
;
4353 breakpoint_chain
= b
;
4363 /* Initialize loc->function_name. */
4365 set_breakpoint_location_function (struct bp_location
*loc
)
4367 if (loc
->owner
->type
== bp_breakpoint
4368 || loc
->owner
->type
== bp_hardware_breakpoint
)
4370 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4372 if (loc
->function_name
)
4373 loc
->function_name
= xstrdup (loc
->function_name
);
4377 /* set_raw_breakpoint is a low level routine for allocating and
4378 partially initializing a breakpoint of type BPTYPE. The newly
4379 created breakpoint's address, section, source file name, and line
4380 number are provided by SAL. The newly created and partially
4381 initialized breakpoint is added to the breakpoint chain and
4382 is also returned as the value of this function.
4384 It is expected that the caller will complete the initialization of
4385 the newly created breakpoint struct as well as output any status
4386 information regarding the creation of a new breakpoint. In
4387 particular, set_raw_breakpoint does NOT set the breakpoint
4388 number! Care should be taken to not allow an error to occur
4389 prior to completing the initialization of the breakpoint. If this
4390 should happen, a bogus breakpoint will be left on the chain. */
4393 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4395 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4396 CORE_ADDR adjusted_address
;
4398 /* Adjust the breakpoint's address prior to allocating a location.
4399 Once we call allocate_bp_location(), that mostly uninitialized
4400 location will be placed on the location chain. Adjustment of the
4401 breakpoint may cause read_memory_nobpt() to be called and we do
4402 not want its scan of the location chain to find a breakpoint and
4403 location that's only been partially initialized. */
4404 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4406 b
->loc
= allocate_bp_location (b
, bptype
);
4407 b
->loc
->requested_address
= sal
.pc
;
4408 b
->loc
->address
= adjusted_address
;
4410 if (sal
.symtab
== NULL
)
4411 b
->source_file
= NULL
;
4413 b
->source_file
= savestring (sal
.symtab
->filename
,
4414 strlen (sal
.symtab
->filename
));
4415 b
->loc
->section
= sal
.section
;
4416 b
->line_number
= sal
.line
;
4418 set_breakpoint_location_function (b
->loc
);
4420 check_duplicates (b
);
4421 breakpoints_changed ();
4427 /* Note that the breakpoint object B describes a permanent breakpoint
4428 instruction, hard-wired into the inferior's code. */
4430 make_breakpoint_permanent (struct breakpoint
*b
)
4432 struct bp_location
*bl
;
4433 b
->enable_state
= bp_permanent
;
4435 /* By definition, permanent breakpoints are already present in the code.
4436 Mark all locations as inserted. For now, make_breakpoint_permanent
4437 is called in just one place, so it's hard to say if it's reasonable
4438 to have permanent breakpoint with multiple locations or not,
4439 but it's easy to implmement. */
4440 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4444 static struct breakpoint
*
4445 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4447 static int internal_breakpoint_number
= -1;
4448 struct symtab_and_line sal
;
4449 struct breakpoint
*b
;
4451 init_sal (&sal
); /* initialize to zeroes */
4454 sal
.section
= find_pc_overlay (sal
.pc
);
4456 b
= set_raw_breakpoint (sal
, type
);
4457 b
->number
= internal_breakpoint_number
--;
4458 b
->disposition
= disp_donttouch
;
4465 create_longjmp_breakpoint (char *func_name
)
4467 struct breakpoint
*b
;
4468 struct minimal_symbol
*m
;
4470 if (func_name
== NULL
)
4471 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4474 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4477 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4480 b
->enable_state
= bp_disabled
;
4483 b
->addr_string
= xstrdup (func_name
);
4486 /* Call this routine when stepping and nexting to enable a breakpoint
4487 if we do a longjmp(). When we hit that breakpoint, call
4488 set_longjmp_resume_breakpoint() to figure out where we are going. */
4491 enable_longjmp_breakpoint (void)
4493 struct breakpoint
*b
;
4496 if (b
->type
== bp_longjmp
)
4498 b
->enable_state
= bp_enabled
;
4499 check_duplicates (b
);
4504 disable_longjmp_breakpoint (void)
4506 struct breakpoint
*b
;
4509 if (b
->type
== bp_longjmp
4510 || b
->type
== bp_longjmp_resume
)
4512 b
->enable_state
= bp_disabled
;
4513 check_duplicates (b
);
4518 create_overlay_event_breakpoint (char *func_name
)
4520 struct breakpoint
*b
;
4521 struct minimal_symbol
*m
;
4523 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4526 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4528 b
->addr_string
= xstrdup (func_name
);
4530 if (overlay_debugging
== ovly_auto
)
4532 b
->enable_state
= bp_enabled
;
4533 overlay_events_enabled
= 1;
4537 b
->enable_state
= bp_disabled
;
4538 overlay_events_enabled
= 0;
4543 enable_overlay_breakpoints (void)
4545 struct breakpoint
*b
;
4548 if (b
->type
== bp_overlay_event
)
4550 b
->enable_state
= bp_enabled
;
4551 check_duplicates (b
);
4552 overlay_events_enabled
= 1;
4557 disable_overlay_breakpoints (void)
4559 struct breakpoint
*b
;
4562 if (b
->type
== bp_overlay_event
)
4564 b
->enable_state
= bp_disabled
;
4565 check_duplicates (b
);
4566 overlay_events_enabled
= 0;
4571 create_thread_event_breakpoint (CORE_ADDR address
)
4573 struct breakpoint
*b
;
4575 b
= create_internal_breakpoint (address
, bp_thread_event
);
4577 b
->enable_state
= bp_enabled
;
4578 /* addr_string has to be used or breakpoint_re_set will delete me. */
4579 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4585 remove_thread_event_breakpoints (void)
4587 struct breakpoint
*b
, *temp
;
4589 ALL_BREAKPOINTS_SAFE (b
, temp
)
4590 if (b
->type
== bp_thread_event
)
4591 delete_breakpoint (b
);
4594 struct captured_parse_breakpoint_args
4597 struct symtabs_and_lines
*sals_p
;
4598 char ***addr_string_p
;
4602 struct lang_and_radix
4610 remove_solib_event_breakpoints (void)
4612 struct breakpoint
*b
, *temp
;
4614 ALL_BREAKPOINTS_SAFE (b
, temp
)
4615 if (b
->type
== bp_shlib_event
)
4616 delete_breakpoint (b
);
4620 create_solib_event_breakpoint (CORE_ADDR address
)
4622 struct breakpoint
*b
;
4624 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4628 /* Disable any breakpoints that are on code in shared libraries. Only
4629 apply to enabled breakpoints, disabled ones can just stay disabled. */
4632 disable_breakpoints_in_shlibs (void)
4634 struct bp_location
*loc
;
4635 int disabled_shlib_breaks
= 0;
4637 ALL_BP_LOCATIONS (loc
)
4639 struct breakpoint
*b
= loc
->owner
;
4640 /* We apply the check to all breakpoints, including disabled
4641 for those with loc->duplicate set. This is so that when breakpoint
4642 becomes enabled, or the duplicate is removed, gdb will try to insert
4643 all breakpoints. If we don't set shlib_disabled here, we'll try
4644 to insert those breakpoints and fail. */
4645 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4646 && !loc
->shlib_disabled
4648 && PC_SOLIB (loc
->address
)
4650 && solib_address (loc
->address
)
4654 loc
->shlib_disabled
= 1;
4659 /* Disable any breakpoints that are in in an unloaded shared library. Only
4660 apply to enabled breakpoints, disabled ones can just stay disabled. */
4663 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4665 struct bp_location
*loc
;
4666 int disabled_shlib_breaks
= 0;
4668 ALL_BP_LOCATIONS (loc
)
4670 struct breakpoint
*b
= loc
->owner
;
4671 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4672 || loc
->loc_type
== bp_loc_software_breakpoint
)
4673 && !loc
->shlib_disabled
)
4676 char *so_name
= PC_SOLIB (loc
->address
);
4678 char *so_name
= solib_address (loc
->address
);
4680 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4682 loc
->shlib_disabled
= 1;
4683 /* At this point, we cannot rely on remove_breakpoint
4684 succeeding so we must mark the breakpoint as not inserted
4685 to prevent future errors occurring in remove_breakpoints. */
4687 if (!disabled_shlib_breaks
)
4689 target_terminal_ours_for_output ();
4690 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4693 disabled_shlib_breaks
= 1;
4700 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4701 enum bptype bp_kind
)
4703 struct symtab_and_line sal
;
4704 struct breakpoint
*b
;
4705 int thread
= -1; /* All threads. */
4712 b
= set_raw_breakpoint (sal
, bp_kind
);
4713 set_breakpoint_count (breakpoint_count
+ 1);
4714 b
->number
= breakpoint_count
;
4715 b
->cond_string
= (cond_string
== NULL
) ?
4716 NULL
: savestring (cond_string
, strlen (cond_string
));
4718 b
->addr_string
= NULL
;
4719 b
->enable_state
= bp_enabled
;
4720 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4721 b
->forked_inferior_pid
= 0;
4727 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4729 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4733 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4735 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4739 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4741 struct symtab_and_line sal
;
4742 struct breakpoint
*b
;
4743 int thread
= -1; /* All threads. */
4750 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4751 set_breakpoint_count (breakpoint_count
+ 1);
4752 b
->number
= breakpoint_count
;
4753 b
->cond_string
= (cond_string
== NULL
) ?
4754 NULL
: savestring (cond_string
, strlen (cond_string
));
4756 b
->addr_string
= NULL
;
4757 b
->enable_state
= bp_enabled
;
4758 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4764 hw_breakpoint_used_count (void)
4766 struct breakpoint
*b
;
4771 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4779 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4781 struct breakpoint
*b
;
4784 *other_type_used
= 0;
4787 if (breakpoint_enabled (b
))
4789 if (b
->type
== type
)
4791 else if ((b
->type
== bp_hardware_watchpoint
||
4792 b
->type
== bp_read_watchpoint
||
4793 b
->type
== bp_access_watchpoint
))
4794 *other_type_used
= 1;
4800 /* Call this after hitting the longjmp() breakpoint. Use this to set
4801 a new breakpoint at the target of the jmp_buf.
4803 FIXME - This ought to be done by setting a temporary breakpoint
4804 that gets deleted automatically... */
4807 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4809 struct breakpoint
*b
;
4812 if (b
->type
== bp_longjmp_resume
)
4814 b
->loc
->requested_address
= pc
;
4815 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4817 b
->enable_state
= bp_enabled
;
4818 b
->frame_id
= frame_id
;
4819 check_duplicates (b
);
4825 disable_watchpoints_before_interactive_call_start (void)
4827 struct breakpoint
*b
;
4831 if (((b
->type
== bp_watchpoint
)
4832 || (b
->type
== bp_hardware_watchpoint
)
4833 || (b
->type
== bp_read_watchpoint
)
4834 || (b
->type
== bp_access_watchpoint
)
4835 || ep_is_exception_catchpoint (b
))
4836 && breakpoint_enabled (b
))
4838 b
->enable_state
= bp_call_disabled
;
4839 check_duplicates (b
);
4845 enable_watchpoints_after_interactive_call_stop (void)
4847 struct breakpoint
*b
;
4851 if (((b
->type
== bp_watchpoint
)
4852 || (b
->type
== bp_hardware_watchpoint
)
4853 || (b
->type
== bp_read_watchpoint
)
4854 || (b
->type
== bp_access_watchpoint
)
4855 || ep_is_exception_catchpoint (b
))
4856 && (b
->enable_state
== bp_call_disabled
))
4858 b
->enable_state
= bp_enabled
;
4859 check_duplicates (b
);
4865 /* Set a breakpoint that will evaporate an end of command
4866 at address specified by SAL.
4867 Restrict it to frame FRAME if FRAME is nonzero. */
4870 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4873 struct breakpoint
*b
;
4874 b
= set_raw_breakpoint (sal
, type
);
4875 b
->enable_state
= bp_enabled
;
4876 b
->disposition
= disp_donttouch
;
4877 b
->frame_id
= frame_id
;
4879 /* If we're debugging a multi-threaded program, then we
4880 want momentary breakpoints to be active in only a
4881 single thread of control. */
4882 if (in_thread_list (inferior_ptid
))
4883 b
->thread
= pid_to_thread_id (inferior_ptid
);
4889 /* Tell the user we have just set a breakpoint B. */
4892 mention (struct breakpoint
*b
)
4895 struct cleanup
*old_chain
, *ui_out_chain
;
4896 struct ui_stream
*stb
;
4898 stb
= ui_out_stream_new (uiout
);
4899 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4901 /* FIXME: This is misplaced; mention() is called by things (like
4902 hitting a watchpoint) other than breakpoint creation. It should
4903 be possible to clean this up and at the same time replace the
4904 random calls to breakpoint_changed with this hook, as has already
4905 been done for deprecated_delete_breakpoint_hook and so on. */
4906 if (deprecated_create_breakpoint_hook
)
4907 deprecated_create_breakpoint_hook (b
);
4908 breakpoint_create_event (b
->number
);
4910 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4911 b
->ops
->print_mention (b
);
4916 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4919 ui_out_text (uiout
, "Watchpoint ");
4920 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4921 ui_out_field_int (uiout
, "number", b
->number
);
4922 ui_out_text (uiout
, ": ");
4923 print_expression (b
->exp
, stb
->stream
);
4924 ui_out_field_stream (uiout
, "exp", stb
);
4925 do_cleanups (ui_out_chain
);
4927 case bp_hardware_watchpoint
:
4928 ui_out_text (uiout
, "Hardware watchpoint ");
4929 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4930 ui_out_field_int (uiout
, "number", b
->number
);
4931 ui_out_text (uiout
, ": ");
4932 print_expression (b
->exp
, stb
->stream
);
4933 ui_out_field_stream (uiout
, "exp", stb
);
4934 do_cleanups (ui_out_chain
);
4936 case bp_read_watchpoint
:
4937 ui_out_text (uiout
, "Hardware read watchpoint ");
4938 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4939 ui_out_field_int (uiout
, "number", b
->number
);
4940 ui_out_text (uiout
, ": ");
4941 print_expression (b
->exp
, stb
->stream
);
4942 ui_out_field_stream (uiout
, "exp", stb
);
4943 do_cleanups (ui_out_chain
);
4945 case bp_access_watchpoint
:
4946 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4947 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4948 ui_out_field_int (uiout
, "number", b
->number
);
4949 ui_out_text (uiout
, ": ");
4950 print_expression (b
->exp
, stb
->stream
);
4951 ui_out_field_stream (uiout
, "exp", stb
);
4952 do_cleanups (ui_out_chain
);
4955 if (ui_out_is_mi_like_p (uiout
))
4960 printf_filtered (_("Breakpoint %d"), b
->number
);
4963 case bp_hardware_breakpoint
:
4964 if (ui_out_is_mi_like_p (uiout
))
4969 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4973 case bp_catch_unload
:
4974 printf_filtered (_("Catchpoint %d (%s %s)"),
4976 (b
->type
== bp_catch_load
) ? "load" : "unload",
4977 (b
->dll_pathname
!= NULL
) ?
4978 b
->dll_pathname
: "<any library>");
4981 case bp_catch_vfork
:
4982 printf_filtered (_("Catchpoint %d (%s)"),
4984 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4987 printf_filtered (_("Catchpoint %d (exec)"),
4990 case bp_catch_catch
:
4991 case bp_catch_throw
:
4992 printf_filtered (_("Catchpoint %d (%s)"),
4994 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
5000 case bp_longjmp_resume
:
5001 case bp_step_resume
:
5003 case bp_watchpoint_scope
:
5004 case bp_shlib_event
:
5005 case bp_thread_event
:
5006 case bp_overlay_event
:
5012 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5016 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5020 if (addressprint
|| b
->source_file
== NULL
)
5022 printf_filtered (" at ");
5023 deprecated_print_address_numeric (b
->loc
->address
, 1, gdb_stdout
);
5026 printf_filtered (": file %s, line %d.",
5027 b
->source_file
, b
->line_number
);
5031 struct bp_location
*loc
= b
->loc
;
5033 for (; loc
; loc
= loc
->next
)
5035 printf_filtered (" (%d locations)", n
);
5040 do_cleanups (old_chain
);
5041 if (ui_out_is_mi_like_p (uiout
))
5043 printf_filtered ("\n");
5047 static struct bp_location
*
5048 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5049 const struct symtab_and_line
*sal
)
5051 struct bp_location
*loc
, **tmp
;
5053 loc
= allocate_bp_location (b
, bptype
);
5054 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5057 loc
->requested_address
= sal
->pc
;
5058 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5060 loc
->section
= sal
->section
;
5062 set_breakpoint_location_function (loc
);
5066 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5067 as textual description of the location, and COND_STRING
5068 as condition expression. */
5071 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5073 enum bptype type
, enum bpdisp disposition
,
5074 int thread
, int ignore_count
, int from_tty
)
5076 struct breakpoint
*b
= NULL
;
5079 if (type
== bp_hardware_breakpoint
)
5081 int i
= hw_breakpoint_used_count ();
5082 int target_resources_ok
=
5083 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5085 if (target_resources_ok
== 0)
5086 error (_("No hardware breakpoint support in the target."));
5087 else if (target_resources_ok
< 0)
5088 error (_("Hardware breakpoints used exceeds limit."));
5091 for (i
= 0; i
< sals
.nelts
; ++i
)
5093 struct symtab_and_line sal
= sals
.sals
[i
];
5094 struct bp_location
*loc
;
5097 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5101 b
= set_raw_breakpoint (sal
, type
);
5102 set_breakpoint_count (breakpoint_count
+ 1);
5103 b
->number
= breakpoint_count
;
5106 b
->cond_string
= cond_string
;
5107 b
->ignore_count
= ignore_count
;
5108 b
->enable_state
= bp_enabled
;
5109 b
->disposition
= disposition
;
5115 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5120 char *arg
= b
->cond_string
;
5121 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5123 error (_("Garbage %s follows condition"), arg
);
5128 b
->addr_string
= addr_string
;
5130 /* addr_string has to be used or breakpoint_re_set will delete
5132 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5137 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5138 elements to fill the void space. */
5139 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5141 int i
= index_to_remove
+1;
5142 int last_index
= sal
->nelts
-1;
5144 for (;i
<= last_index
; ++i
)
5145 sal
->sals
[i
-1] = sal
->sals
[i
];
5150 /* If appropriate, obtains all sals that correspond
5151 to the same file and line as SAL. This is done
5152 only if SAL does not have explicit PC and has
5153 line and file information. If we got just a single
5154 expanded sal, return the original.
5156 Otherwise, if SAL.explicit_line is not set, filter out
5157 all sals for which the name of enclosing function
5158 is different from SAL. This makes sure that if we have
5159 breakpoint originally set in template instantiation, say
5160 foo<int>(), we won't expand SAL to locations at the same
5161 line in all existing instantiations of 'foo'.
5164 struct symtabs_and_lines
5165 expand_line_sal_maybe (struct symtab_and_line sal
)
5167 struct symtabs_and_lines expanded
;
5168 CORE_ADDR original_pc
= sal
.pc
;
5169 char *original_function
= NULL
;
5173 /* If we have explicit pc, don't expand.
5174 If we have no line number, we can't expand. */
5175 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5178 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5179 expanded
.sals
[0] = sal
;
5184 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5186 expanded
= expand_line_sal (sal
);
5187 if (expanded
.nelts
== 1)
5189 /* We had one sal, we got one sal. Without futher
5190 processing, just return the original sal. */
5191 xfree (expanded
.sals
);
5193 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5194 sal
.pc
= original_pc
;
5195 expanded
.sals
[0] = sal
;
5199 if (!sal
.explicit_line
)
5201 CORE_ADDR func_addr
, func_end
;
5202 for (i
= 0; i
< expanded
.nelts
; ++i
)
5204 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5205 char *this_function
;
5206 if (find_pc_partial_function (pc
, &this_function
,
5207 &func_addr
, &func_end
))
5209 if (this_function
&&
5210 strcmp (this_function
, original_function
) != 0)
5212 remove_sal (&expanded
, i
);
5215 else if (func_addr
== pc
)
5217 /* We're at beginning of a function, and should
5219 struct symbol
*sym
= find_pc_function (pc
);
5221 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5224 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5231 if (expanded
.nelts
<= 1)
5233 /* This is un ugly workaround. If we get zero
5234 expanded sals then something is really wrong.
5235 Fix that by returnign the original sal. */
5236 xfree (expanded
.sals
);
5238 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5239 sal
.pc
= original_pc
;
5240 expanded
.sals
[0] = sal
;
5247 for (i
= 0; i
< expanded
.nelts
; ++i
)
5248 if (expanded
.sals
[i
].pc
== original_pc
)
5259 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5260 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5261 value. COND_STRING, if not NULL, specified the condition to be
5262 used for all breakpoints. Essentially the only case where
5263 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5264 function. In that case, it's still not possible to specify
5265 separate conditions for different overloaded functions, so
5266 we take just a single condition string.
5268 NOTE: If the function succeeds, the caller is expected to cleanup
5269 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5270 array contents). If the function fails (error() is called), the
5271 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5272 COND and SALS arrays and each of those arrays contents. */
5275 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5277 enum bptype type
, enum bpdisp disposition
,
5278 int thread
, int ignore_count
, int from_tty
)
5281 for (i
= 0; i
< sals
.nelts
; ++i
)
5283 struct symtabs_and_lines expanded
=
5284 expand_line_sal_maybe (sals
.sals
[i
]);
5286 create_breakpoint (expanded
, addr_string
[i
],
5287 cond_string
, type
, disposition
,
5288 thread
, ignore_count
, from_tty
);
5292 /* Parse ARG which is assumed to be a SAL specification possibly
5293 followed by conditionals. On return, SALS contains an array of SAL
5294 addresses found. ADDR_STRING contains a vector of (canonical)
5295 address strings. ARG points to the end of the SAL. */
5298 parse_breakpoint_sals (char **address
,
5299 struct symtabs_and_lines
*sals
,
5300 char ***addr_string
,
5303 char *addr_start
= *address
;
5304 *addr_string
= NULL
;
5305 /* If no arg given, or if first arg is 'if ', use the default
5307 if ((*address
) == NULL
5308 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5310 if (default_breakpoint_valid
)
5312 struct symtab_and_line sal
;
5313 init_sal (&sal
); /* initialize to zeroes */
5314 sals
->sals
= (struct symtab_and_line
*)
5315 xmalloc (sizeof (struct symtab_and_line
));
5316 sal
.pc
= default_breakpoint_address
;
5317 sal
.line
= default_breakpoint_line
;
5318 sal
.symtab
= default_breakpoint_symtab
;
5319 sal
.section
= find_pc_overlay (sal
.pc
);
5320 sals
->sals
[0] = sal
;
5324 error (_("No default breakpoint address now."));
5328 /* Force almost all breakpoints to be in terms of the
5329 current_source_symtab (which is decode_line_1's default). This
5330 should produce the results we want almost all of the time while
5331 leaving default_breakpoint_* alone.
5332 ObjC: However, don't match an Objective-C method name which
5333 may have a '+' or '-' succeeded by a '[' */
5335 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5337 if (default_breakpoint_valid
5339 || ((strchr ("+-", (*address
)[0]) != NULL
)
5340 && ((*address
)[1] != '['))))
5341 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5342 default_breakpoint_line
, addr_string
,
5345 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5346 addr_string
, not_found_ptr
);
5348 /* For any SAL that didn't have a canonical string, fill one in. */
5349 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5350 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5351 if (addr_start
!= (*address
))
5354 for (i
= 0; i
< sals
->nelts
; i
++)
5356 /* Add the string if not present. */
5357 if ((*addr_string
)[i
] == NULL
)
5358 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5364 /* Convert each SAL into a real PC. Verify that the PC can be
5365 inserted as a breakpoint. If it can't throw an error. */
5368 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5372 for (i
= 0; i
< sals
->nelts
; i
++)
5373 resolve_sal_pc (&sals
->sals
[i
]);
5377 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5379 struct captured_parse_breakpoint_args
*args
= data
;
5381 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5382 args
->not_found_ptr
);
5385 /* Given TOK, a string specification of condition and thread, as
5386 accepted by the 'break' command, extract the condition
5387 string and thread number and set *COND_STRING and *THREAD.
5388 PC identifies the context at which the condition should be parsed.
5389 If no condition is found, *COND_STRING is set to NULL.
5390 If no thread is found, *THREAD is set to -1. */
5392 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5393 char **cond_string
, int *thread
)
5395 *cond_string
= NULL
;
5401 char *cond_start
= NULL
;
5402 char *cond_end
= NULL
;
5403 while (*tok
== ' ' || *tok
== '\t')
5408 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5411 toklen
= end_tok
- tok
;
5413 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5415 tok
= cond_start
= end_tok
+ 1;
5416 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5418 *cond_string
= savestring (cond_start
,
5419 cond_end
- cond_start
);
5421 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5427 *thread
= strtol (tok
, &tok
, 0);
5429 error (_("Junk after thread keyword."));
5430 if (!valid_thread_id (*thread
))
5431 error (_("Unknown thread %d."), *thread
);
5434 error (_("Junk at end of arguments."));
5438 /* Set a breakpoint according to ARG (function, linenum or *address)
5439 flag: first bit : 0 non-temporary, 1 temporary.
5440 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
5443 break_command_1 (char *arg
, int flag
, int from_tty
)
5445 struct gdb_exception e
;
5446 int tempflag
, hardwareflag
;
5447 struct symtabs_and_lines sals
;
5448 struct symtab_and_line pending_sal
;
5449 char *cond_string
= NULL
;
5452 char *addr_start
= arg
;
5454 struct cleanup
*old_chain
;
5455 struct cleanup
*breakpoint_chain
= NULL
;
5456 struct captured_parse_breakpoint_args parse_args
;
5460 int ignore_count
= 0;
5463 hardwareflag
= flag
& BP_HARDWAREFLAG
;
5464 tempflag
= flag
& BP_TEMPFLAG
;
5470 parse_args
.arg_p
= &arg
;
5471 parse_args
.sals_p
= &sals
;
5472 parse_args
.addr_string_p
= &addr_string
;
5473 parse_args
.not_found_ptr
= ¬_found
;
5475 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5476 &parse_args
, RETURN_MASK_ALL
);
5478 /* If caller is interested in rc value from parse, set value. */
5482 exception_print (gdb_stderr
, e
);
5487 case NOT_FOUND_ERROR
:
5489 exception_print (gdb_stderr
, e
);
5491 /* If pending breakpoint support is turned off, throw
5494 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5495 deprecated_throw_reason (RETURN_ERROR
);
5497 /* If pending breakpoint support is auto query and the user
5498 selects no, then simply return the error code. */
5499 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5500 !nquery ("Make breakpoint pending on future shared library load? "))
5503 /* At this point, either the user was queried about setting
5504 a pending breakpoint and selected yes, or pending
5505 breakpoint behavior is on and thus a pending breakpoint
5506 is defaulted on behalf of the user. */
5507 copy_arg
= xstrdup (addr_start
);
5508 addr_string
= ©_arg
;
5510 sals
.sals
= &pending_sal
;
5515 exception_print (gdb_stderr
, e
);
5523 /* Create a chain of things that always need to be cleaned up. */
5524 old_chain
= make_cleanup (null_cleanup
, 0);
5528 /* Make sure that all storage allocated to SALS gets freed. */
5529 make_cleanup (xfree
, sals
.sals
);
5531 /* Cleanup the addr_string array but not its contents. */
5532 make_cleanup (xfree
, addr_string
);
5535 /* ----------------------------- SNIP -----------------------------
5536 Anything added to the cleanup chain beyond this point is assumed
5537 to be part of a breakpoint. If the breakpoint create succeeds
5538 then the memory is not reclaimed. */
5539 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5541 /* Mark the contents of the addr_string for cleanup. These go on
5542 the breakpoint_chain and only occure if the breakpoint create
5544 for (i
= 0; i
< sals
.nelts
; i
++)
5546 if (addr_string
[i
] != NULL
)
5547 make_cleanup (xfree
, addr_string
[i
]);
5550 /* Resolve all line numbers to PC's and verify that the addresses
5551 are ok for the target. */
5553 breakpoint_sals_to_pc (&sals
, addr_start
);
5555 /* Verify that condition can be parsed, before setting any
5556 breakpoints. Allocate a separate condition expression for each
5560 /* Here we only parse 'arg' to separate condition
5561 from thread number, so parsing in context of first
5562 sal is OK. When setting the breakpoint we'll
5563 re-parse it in context of each sal. */
5564 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5566 make_cleanup (xfree
, cond_string
);
5567 create_breakpoints (sals
, addr_string
, cond_string
,
5568 hardwareflag
? bp_hardware_breakpoint
5570 tempflag
? disp_del
: disp_donttouch
,
5571 thread
, ignore_count
, from_tty
);
5575 struct symtab_and_line sal
= {0};
5576 struct breakpoint
*b
;
5578 make_cleanup (xfree
, copy_arg
);
5580 b
= set_raw_breakpoint_without_location (hardwareflag
5581 ? bp_hardware_breakpoint
5583 set_breakpoint_count (breakpoint_count
+ 1);
5584 b
->number
= breakpoint_count
;
5586 b
->addr_string
= addr_string
[0];
5587 b
->cond_string
= cond_string
;
5588 b
->ignore_count
= ignore_count
;
5589 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5590 b
->from_tty
= from_tty
;
5592 b
->condition_not_parsed
= 1;
5597 warning (_("Multiple breakpoints were set.\n"
5598 "Use the \"delete\" command to delete unwanted breakpoints."));
5599 /* That's it. Discard the cleanups for data inserted into the
5601 discard_cleanups (breakpoint_chain
);
5602 /* But cleanup everything else. */
5603 do_cleanups (old_chain
);
5608 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5609 linenum or *address) with COND and IGNORE_COUNT. */
5611 struct captured_breakpoint_args
5622 do_captured_breakpoint (struct ui_out
*uiout
, void *data
)
5624 struct captured_breakpoint_args
*args
= data
;
5625 struct symtabs_and_lines sals
;
5626 struct expression
**cond
;
5627 struct cleanup
*old_chain
;
5628 struct cleanup
*breakpoint_chain
= NULL
;
5631 char *cond_string
= 0;
5635 /* Parse the source and lines spec. Delay check that the expression
5636 didn't contain trailing garbage until after cleanups are in
5640 address_end
= args
->address
;
5642 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
, 0);
5647 /* Create a chain of things at always need to be cleaned up. */
5648 old_chain
= make_cleanup (null_cleanup
, 0);
5650 /* Always have a addr_string array, even if it is empty. */
5651 make_cleanup (xfree
, addr_string
);
5653 /* Make sure that all storage allocated to SALS gets freed. */
5654 make_cleanup (xfree
, sals
.sals
);
5656 /* Allocate space for all the cond expressions. */
5657 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5658 make_cleanup (xfree
, cond
);
5660 /* ----------------------------- SNIP -----------------------------
5661 Anything added to the cleanup chain beyond this point is assumed
5662 to be part of a breakpoint. If the breakpoint create goes
5663 through then that memory is not cleaned up. */
5664 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5666 /* Mark the contents of the addr_string for cleanup. These go on
5667 the breakpoint_chain and only occure if the breakpoint create
5669 for (i
= 0; i
< sals
.nelts
; i
++)
5671 if (addr_string
[i
] != NULL
)
5672 make_cleanup (xfree
, addr_string
[i
]);
5675 /* Wait until now before checking for garbage at the end of the
5676 address. That way cleanups can take care of freeing any
5678 if (*address_end
!= '\0')
5679 error (_("Garbage %s following breakpoint address"), address_end
);
5681 /* Resolve all line numbers to PC's. */
5682 breakpoint_sals_to_pc (&sals
, args
->address
);
5684 if (args
->condition
!= NULL
)
5686 cond_string
= xstrdup (args
->condition
);
5687 make_cleanup (xfree
, cond_string
);
5690 create_breakpoints (sals
, addr_string
, args
->condition
,
5691 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
5692 args
->tempflag
? disp_del
: disp_donttouch
,
5693 args
->thread
, args
->ignore_count
, 0/*from-tty*/);
5695 /* That's it. Discard the cleanups for data inserted into the
5697 discard_cleanups (breakpoint_chain
);
5698 /* But cleanup everything else. */
5699 do_cleanups (old_chain
);
5704 gdb_breakpoint (char *address
, char *condition
,
5705 int hardwareflag
, int tempflag
,
5706 int thread
, int ignore_count
,
5707 char **error_message
)
5709 struct captured_breakpoint_args args
;
5710 args
.address
= address
;
5711 args
.condition
= condition
;
5712 args
.hardwareflag
= hardwareflag
;
5713 args
.tempflag
= tempflag
;
5714 args
.thread
= thread
;
5715 args
.ignore_count
= ignore_count
;
5716 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint
, &args
,
5717 error_message
, RETURN_MASK_ALL
) < 0)
5724 /* Helper function for break_command_1 and disassemble_command. */
5727 resolve_sal_pc (struct symtab_and_line
*sal
)
5731 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5733 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5734 error (_("No line %d in file \"%s\"."),
5735 sal
->line
, sal
->symtab
->filename
);
5739 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5741 struct blockvector
*bv
;
5746 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5749 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5750 sym
= block_function (b
);
5753 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5754 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5758 /* It really is worthwhile to have the section, so we'll just
5759 have to look harder. This case can be executed if we have
5760 line numbers but no functions (as can happen in assembly
5763 struct minimal_symbol
*msym
;
5765 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5767 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5774 break_command (char *arg
, int from_tty
)
5776 break_command_1 (arg
, 0, from_tty
);
5780 tbreak_command (char *arg
, int from_tty
)
5782 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5786 hbreak_command (char *arg
, int from_tty
)
5788 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5792 thbreak_command (char *arg
, int from_tty
)
5794 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5798 stop_command (char *arg
, int from_tty
)
5800 printf_filtered (_("Specify the type of breakpoint to set.\n\
5801 Usage: stop in <function | address>\n\
5802 stop at <line>\n"));
5806 stopin_command (char *arg
, int from_tty
)
5810 if (arg
== (char *) NULL
)
5812 else if (*arg
!= '*')
5817 /* look for a ':'. If this is a line number specification, then
5818 say it is bad, otherwise, it should be an address or
5819 function/method name */
5820 while (*argptr
&& !hasColon
)
5822 hasColon
= (*argptr
== ':');
5827 badInput
= (*argptr
!= ':'); /* Not a class::method */
5829 badInput
= isdigit (*arg
); /* a simple line number */
5833 printf_filtered (_("Usage: stop in <function | address>\n"));
5835 break_command_1 (arg
, 0, from_tty
);
5839 stopat_command (char *arg
, int from_tty
)
5843 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5850 /* look for a ':'. If there is a '::' then get out, otherwise
5851 it is probably a line number. */
5852 while (*argptr
&& !hasColon
)
5854 hasColon
= (*argptr
== ':');
5859 badInput
= (*argptr
== ':'); /* we have class::method */
5861 badInput
= !isdigit (*arg
); /* not a line number */
5865 printf_filtered (_("Usage: stop at <line>\n"));
5867 break_command_1 (arg
, 0, from_tty
);
5870 /* accessflag: hw_write: watch write,
5871 hw_read: watch read,
5872 hw_access: watch access (read or write) */
5874 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5876 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5877 struct symtab_and_line sal
;
5878 struct expression
*exp
;
5879 struct block
*exp_valid_block
;
5880 struct value
*val
, *mark
;
5881 struct frame_info
*frame
;
5882 struct frame_info
*prev_frame
= NULL
;
5883 char *exp_start
= NULL
;
5884 char *exp_end
= NULL
;
5885 char *tok
, *end_tok
;
5887 char *cond_start
= NULL
;
5888 char *cond_end
= NULL
;
5889 struct expression
*cond
= NULL
;
5890 int i
, other_type_used
, target_resources_ok
= 0;
5891 enum bptype bp_type
;
5894 init_sal (&sal
); /* initialize to zeroes */
5896 /* Parse arguments. */
5897 innermost_block
= NULL
;
5899 exp
= parse_exp_1 (&arg
, 0, 0);
5901 exp_valid_block
= innermost_block
;
5902 mark
= value_mark ();
5903 val
= evaluate_expression (exp
);
5904 release_value (val
);
5905 if (value_lazy (val
))
5906 value_fetch_lazy (val
);
5909 while (*tok
== ' ' || *tok
== '\t')
5913 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5916 toklen
= end_tok
- tok
;
5917 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5919 tok
= cond_start
= end_tok
+ 1;
5920 cond
= parse_exp_1 (&tok
, 0, 0);
5924 error (_("Junk at end of command."));
5926 if (accessflag
== hw_read
)
5927 bp_type
= bp_read_watchpoint
;
5928 else if (accessflag
== hw_access
)
5929 bp_type
= bp_access_watchpoint
;
5931 bp_type
= bp_hardware_watchpoint
;
5933 mem_cnt
= can_use_hardware_watchpoint (val
);
5934 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5935 error (_("Expression cannot be implemented with read/access watchpoint."));
5938 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5939 target_resources_ok
=
5940 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5942 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5943 error (_("Target does not support this type of hardware watchpoint."));
5945 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5946 error (_("Target can only support one kind of HW watchpoint at a time."));
5949 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5950 watchpoint could not be set. */
5951 if (!mem_cnt
|| target_resources_ok
<= 0)
5952 bp_type
= bp_watchpoint
;
5954 frame
= block_innermost_frame (exp_valid_block
);
5956 prev_frame
= get_prev_frame (frame
);
5960 /* If the expression is "local", then set up a "watchpoint scope"
5961 breakpoint at the point where we've left the scope of the watchpoint
5962 expression. Create the scope breakpoint before the watchpoint, so
5963 that we will encounter it first in bpstat_stop_status. */
5964 if (innermost_block
&& prev_frame
)
5966 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5967 bp_watchpoint_scope
);
5969 scope_breakpoint
->enable_state
= bp_enabled
;
5971 /* Automatically delete the breakpoint when it hits. */
5972 scope_breakpoint
->disposition
= disp_del
;
5974 /* Only break in the proper frame (help with recursion). */
5975 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5977 /* Set the address at which we will stop. */
5978 scope_breakpoint
->loc
->requested_address
5979 = get_frame_pc (prev_frame
);
5980 scope_breakpoint
->loc
->address
5981 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5982 scope_breakpoint
->type
);
5985 /* Now set up the breakpoint. */
5986 b
= set_raw_breakpoint (sal
, bp_type
);
5987 set_breakpoint_count (breakpoint_count
+ 1);
5988 b
->number
= breakpoint_count
;
5989 b
->disposition
= disp_donttouch
;
5991 b
->exp_valid_block
= exp_valid_block
;
5992 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5994 b
->loc
->cond
= cond
;
5996 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6001 b
->watchpoint_frame
= get_frame_id (frame
);
6003 memset (&b
->watchpoint_frame
, 0, sizeof (b
->watchpoint_frame
));
6005 if (scope_breakpoint
!= NULL
)
6007 /* The scope breakpoint is related to the watchpoint. We will
6008 need to act on them together. */
6009 b
->related_breakpoint
= scope_breakpoint
;
6010 scope_breakpoint
->related_breakpoint
= b
;
6013 value_free_to_mark (mark
);
6017 /* Return count of locations need to be watched and can be handled
6018 in hardware. If the watchpoint can not be handled
6019 in hardware return zero. */
6022 can_use_hardware_watchpoint (struct value
*v
)
6024 int found_memory_cnt
= 0;
6025 struct value
*head
= v
;
6027 /* Did the user specifically forbid us to use hardware watchpoints? */
6028 if (!can_use_hw_watchpoints
)
6031 /* Make sure that the value of the expression depends only upon
6032 memory contents, and values computed from them within GDB. If we
6033 find any register references or function calls, we can't use a
6034 hardware watchpoint.
6036 The idea here is that evaluating an expression generates a series
6037 of values, one holding the value of every subexpression. (The
6038 expression a*b+c has five subexpressions: a, b, a*b, c, and
6039 a*b+c.) GDB's values hold almost enough information to establish
6040 the criteria given above --- they identify memory lvalues,
6041 register lvalues, computed values, etcetera. So we can evaluate
6042 the expression, and then scan the chain of values that leaves
6043 behind to decide whether we can detect any possible change to the
6044 expression's final value using only hardware watchpoints.
6046 However, I don't think that the values returned by inferior
6047 function calls are special in any way. So this function may not
6048 notice that an expression involving an inferior function call
6049 can't be watched with hardware watchpoints. FIXME. */
6050 for (; v
; v
= value_next (v
))
6052 if (VALUE_LVAL (v
) == lval_memory
)
6055 /* A lazy memory lvalue is one that GDB never needed to fetch;
6056 we either just used its address (e.g., `a' in `a.b') or
6057 we never needed it at all (e.g., `a' in `a,b'). */
6061 /* Ahh, memory we actually used! Check if we can cover
6062 it with hardware watchpoints. */
6063 struct type
*vtype
= check_typedef (value_type (v
));
6065 /* We only watch structs and arrays if user asked for it
6066 explicitly, never if they just happen to appear in a
6067 middle of some value chain. */
6069 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6070 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6072 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6073 int len
= TYPE_LENGTH (value_type (v
));
6075 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6082 else if (VALUE_LVAL (v
) != not_lval
6083 && deprecated_value_modifiable (v
) == 0)
6084 return 0; /* ??? What does this represent? */
6085 else if (VALUE_LVAL (v
) == lval_register
)
6086 return 0; /* cannot watch a register with a HW watchpoint */
6089 /* The expression itself looks suitable for using a hardware
6090 watchpoint, but give the target machine a chance to reject it. */
6091 return found_memory_cnt
;
6095 watch_command_wrapper (char *arg
, int from_tty
)
6097 watch_command (arg
, from_tty
);
6101 watch_command (char *arg
, int from_tty
)
6103 watch_command_1 (arg
, hw_write
, from_tty
);
6107 rwatch_command_wrapper (char *arg
, int from_tty
)
6109 rwatch_command (arg
, from_tty
);
6113 rwatch_command (char *arg
, int from_tty
)
6115 watch_command_1 (arg
, hw_read
, from_tty
);
6119 awatch_command_wrapper (char *arg
, int from_tty
)
6121 awatch_command (arg
, from_tty
);
6125 awatch_command (char *arg
, int from_tty
)
6127 watch_command_1 (arg
, hw_access
, from_tty
);
6131 /* Helper routines for the until_command routine in infcmd.c. Here
6132 because it uses the mechanisms of breakpoints. */
6134 /* This function is called by fetch_inferior_event via the
6135 cmd_continuation pointer, to complete the until command. It takes
6136 care of cleaning up the temporary breakpoints set up by the until
6139 until_break_command_continuation (struct continuation_arg
*arg
)
6141 struct cleanup
*cleanups
;
6143 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
6144 do_exec_cleanups (cleanups
);
6148 until_break_command (char *arg
, int from_tty
, int anywhere
)
6150 struct symtabs_and_lines sals
;
6151 struct symtab_and_line sal
;
6152 struct frame_info
*frame
= get_selected_frame (NULL
);
6153 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6154 struct breakpoint
*breakpoint
;
6155 struct cleanup
*old_chain
;
6156 struct continuation_arg
*arg1
;
6159 clear_proceed_status ();
6161 /* Set a breakpoint where the user wants it and at return from
6164 if (default_breakpoint_valid
)
6165 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6166 default_breakpoint_line
, (char ***) NULL
, NULL
);
6168 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6169 0, (char ***) NULL
, NULL
);
6171 if (sals
.nelts
!= 1)
6172 error (_("Couldn't get information on specified line."));
6175 xfree (sals
.sals
); /* malloc'd, so freed */
6178 error (_("Junk at end of arguments."));
6180 resolve_sal_pc (&sal
);
6183 /* If the user told us to continue until a specified location,
6184 we don't specify a frame at which we need to stop. */
6185 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6187 /* Otherwise, specify the current frame, because we want to stop only
6188 at the very same frame. */
6189 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6192 if (!target_can_async_p ())
6193 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6195 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
6197 /* If we are running asynchronously, and the target supports async
6198 execution, we are not waiting for the target to stop, in the call
6199 tp proceed, below. This means that we cannot delete the
6200 brekpoints until the target has actually stopped. The only place
6201 where we get a chance to do that is in fetch_inferior_event, so
6202 we must set things up for that. */
6204 if (target_can_async_p ())
6206 /* In this case the arg for the continuation is just the point
6207 in the exec_cleanups chain from where to start doing
6208 cleanups, because all the continuation does is the cleanups in
6209 the exec_cleanup_chain. */
6211 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6213 arg1
->data
.pointer
= old_chain
;
6215 add_continuation (until_break_command_continuation
, arg1
);
6218 /* Keep within the current frame, or in frames called by the current
6222 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6223 sal
.pc
= get_frame_pc (prev_frame
);
6224 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6226 if (!target_can_async_p ())
6227 make_cleanup_delete_breakpoint (breakpoint
);
6229 make_exec_cleanup_delete_breakpoint (breakpoint
);
6232 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6233 /* Do the cleanups now, anly if we are not running asynchronously,
6234 of if we are, but the target is still synchronous. */
6235 if (!target_can_async_p ())
6236 do_cleanups (old_chain
);
6240 ep_skip_leading_whitespace (char **s
)
6242 if ((s
== NULL
) || (*s
== NULL
))
6244 while (isspace (**s
))
6248 /* This function examines a string, and attempts to find a token
6249 that might be an event name in the leading characters. If a
6250 possible match is found, a pointer to the last character of
6251 the token is returned. Else, NULL is returned. */
6254 ep_find_event_name_end (char *arg
)
6257 char *event_name_end
= NULL
;
6259 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6263 /* We break out of the loop when we find a token delimiter.
6264 Basically, we're looking for alphanumerics and underscores;
6265 anything else delimites the token. */
6268 if (!isalnum (*s
) && (*s
!= '_'))
6274 return event_name_end
;
6278 /* This function attempts to parse an optional "if <cond>" clause
6279 from the arg string. If one is not found, it returns NULL.
6281 Else, it returns a pointer to the condition string. (It does not
6282 attempt to evaluate the string against a particular block.) And,
6283 it updates arg to point to the first character following the parsed
6284 if clause in the arg string. */
6287 ep_parse_optional_if_clause (char **arg
)
6291 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6294 /* Skip the "if" keyword. */
6297 /* Skip any extra leading whitespace, and record the start of the
6298 condition string. */
6299 ep_skip_leading_whitespace (arg
);
6302 /* Assume that the condition occupies the remainder of the arg string. */
6303 (*arg
) += strlen (cond_string
);
6308 /* This function attempts to parse an optional filename from the arg
6309 string. If one is not found, it returns NULL.
6311 Else, it returns a pointer to the parsed filename. (This function
6312 makes no attempt to verify that a file of that name exists, or is
6313 accessible.) And, it updates arg to point to the first character
6314 following the parsed filename in the arg string.
6316 Note that clients needing to preserve the returned filename for
6317 future access should copy it to their own buffers. */
6319 ep_parse_optional_filename (char **arg
)
6321 static char filename
[1024];
6326 if ((*arg_p
== '\0') || isspace (*arg_p
))
6344 /* Commands to deal with catching events, such as signals, exceptions,
6345 process start/exit, etc. */
6349 catch_fork
, catch_vfork
6354 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6357 char *cond_string
= NULL
;
6359 ep_skip_leading_whitespace (&arg
);
6361 /* The allowed syntax is:
6363 catch [v]fork if <cond>
6365 First, check if there's an if clause. */
6366 cond_string
= ep_parse_optional_if_clause (&arg
);
6368 if ((*arg
!= '\0') && !isspace (*arg
))
6369 error (_("Junk at end of arguments."));
6371 /* If this target supports it, create a fork or vfork catchpoint
6372 and enable reporting of such events. */
6376 create_fork_event_catchpoint (tempflag
, cond_string
);
6379 create_vfork_event_catchpoint (tempflag
, cond_string
);
6382 error (_("unsupported or unknown fork kind; cannot catch it"));
6388 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6390 char *cond_string
= NULL
;
6392 ep_skip_leading_whitespace (&arg
);
6394 /* The allowed syntax is:
6396 catch exec if <cond>
6398 First, check if there's an if clause. */
6399 cond_string
= ep_parse_optional_if_clause (&arg
);
6401 if ((*arg
!= '\0') && !isspace (*arg
))
6402 error (_("Junk at end of arguments."));
6404 /* If this target supports it, create an exec catchpoint
6405 and enable reporting of such events. */
6406 create_exec_event_catchpoint (tempflag
, cond_string
);
6410 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6412 char *dll_pathname
= NULL
;
6413 char *cond_string
= NULL
;
6415 ep_skip_leading_whitespace (&arg
);
6417 /* The allowed syntax is:
6419 catch load if <cond>
6420 catch load <filename>
6421 catch load <filename> if <cond>
6423 The user is not allowed to specify the <filename> after an
6426 We'll ignore the pathological case of a file named "if".
6428 First, check if there's an if clause. If so, then there
6429 cannot be a filename. */
6430 cond_string
= ep_parse_optional_if_clause (&arg
);
6432 /* If there was an if clause, then there cannot be a filename.
6433 Else, there might be a filename and an if clause. */
6434 if (cond_string
== NULL
)
6436 dll_pathname
= ep_parse_optional_filename (&arg
);
6437 ep_skip_leading_whitespace (&arg
);
6438 cond_string
= ep_parse_optional_if_clause (&arg
);
6441 if ((*arg
!= '\0') && !isspace (*arg
))
6442 error (_("Junk at end of arguments."));
6444 /* Create a load breakpoint that only triggers when a load of
6445 the specified dll (or any dll, if no pathname was specified)
6447 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6448 dll_pathname
, cond_string
);
6452 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6454 char *dll_pathname
= NULL
;
6455 char *cond_string
= NULL
;
6457 ep_skip_leading_whitespace (&arg
);
6459 /* The allowed syntax is:
6461 catch unload if <cond>
6462 catch unload <filename>
6463 catch unload <filename> if <cond>
6465 The user is not allowed to specify the <filename> after an
6468 We'll ignore the pathological case of a file named "if".
6470 First, check if there's an if clause. If so, then there
6471 cannot be a filename. */
6472 cond_string
= ep_parse_optional_if_clause (&arg
);
6474 /* If there was an if clause, then there cannot be a filename.
6475 Else, there might be a filename and an if clause. */
6476 if (cond_string
== NULL
)
6478 dll_pathname
= ep_parse_optional_filename (&arg
);
6479 ep_skip_leading_whitespace (&arg
);
6480 cond_string
= ep_parse_optional_if_clause (&arg
);
6483 if ((*arg
!= '\0') && !isspace (*arg
))
6484 error (_("Junk at end of arguments."));
6486 /* Create an unload breakpoint that only triggers when an unload of
6487 the specified dll (or any dll, if no pathname was specified)
6489 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6490 dll_pathname
, cond_string
);
6493 /* Commands to deal with catching exceptions. */
6495 /* Set a breakpoint at the specified callback routine for an
6496 exception event callback */
6499 create_exception_catchpoint (int tempflag
, char *cond_string
,
6500 enum exception_event_kind ex_event
,
6501 struct symtab_and_line
*sal
)
6503 struct breakpoint
*b
;
6504 int thread
= -1; /* All threads. */
6507 if (!sal
) /* no exception support? */
6512 case EX_EVENT_THROW
:
6513 bptype
= bp_catch_throw
;
6515 case EX_EVENT_CATCH
:
6516 bptype
= bp_catch_catch
;
6518 default: /* error condition */
6519 error (_("Internal error -- invalid catchpoint kind"));
6522 b
= set_raw_breakpoint (*sal
, bptype
);
6523 set_breakpoint_count (breakpoint_count
+ 1);
6524 b
->number
= breakpoint_count
;
6525 b
->cond_string
= (cond_string
== NULL
) ?
6526 NULL
: savestring (cond_string
, strlen (cond_string
));
6528 b
->addr_string
= NULL
;
6529 b
->enable_state
= bp_enabled
;
6530 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6534 static enum print_stop_action
6535 print_exception_catchpoint (struct breakpoint
*b
)
6537 annotate_catchpoint (b
->number
);
6539 if (strstr (b
->addr_string
, "throw") != NULL
)
6540 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6543 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6546 return PRINT_SRC_AND_LOC
;
6550 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6555 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6558 *last_addr
= b
->loc
->address
;
6559 if (strstr (b
->addr_string
, "throw") != NULL
)
6560 ui_out_field_string (uiout
, "what", "exception throw");
6562 ui_out_field_string (uiout
, "what", "exception catch");
6566 print_mention_exception_catchpoint (struct breakpoint
*b
)
6568 if (strstr (b
->addr_string
, "throw") != NULL
)
6569 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6571 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6574 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6575 print_exception_catchpoint
,
6576 print_one_exception_catchpoint
,
6577 print_mention_exception_catchpoint
6581 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6582 enum exception_event_kind ex_event
, int from_tty
)
6584 char *trigger_func_name
, *nameptr
;
6585 struct symtabs_and_lines sals
;
6586 struct breakpoint
*b
;
6588 if (ex_event
== EX_EVENT_CATCH
)
6589 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6591 trigger_func_name
= xstrdup ("__cxa_throw");
6593 nameptr
= trigger_func_name
;
6594 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6595 if (sals
.nelts
== 0)
6597 xfree (trigger_func_name
);
6601 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6602 set_breakpoint_count (breakpoint_count
+ 1);
6603 b
->number
= breakpoint_count
;
6604 b
->cond_string
= (cond_string
== NULL
) ?
6605 NULL
: savestring (cond_string
, strlen (cond_string
));
6607 b
->addr_string
= trigger_func_name
;
6608 b
->enable_state
= bp_enabled
;
6609 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6610 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6617 /* Deal with "catch catch" and "catch throw" commands */
6620 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6621 int tempflag
, int from_tty
)
6623 char *cond_string
= NULL
;
6624 struct symtab_and_line
*sal
= NULL
;
6626 ep_skip_leading_whitespace (&arg
);
6628 cond_string
= ep_parse_optional_if_clause (&arg
);
6630 if ((*arg
!= '\0') && !isspace (*arg
))
6631 error (_("Junk at end of arguments."));
6633 if ((ex_event
!= EX_EVENT_THROW
) &&
6634 (ex_event
!= EX_EVENT_CATCH
))
6635 error (_("Unsupported or unknown exception event; cannot catch it"));
6637 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6640 /* See if we can find a callback routine */
6641 sal
= target_enable_exception_callback (ex_event
, 1);
6645 /* We have callbacks from the runtime system for exceptions.
6646 Set a breakpoint on the sal found, if no errors */
6647 if (sal
!= (struct symtab_and_line
*) -1)
6648 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6650 return; /* something went wrong with setting up callbacks */
6653 warning (_("Unsupported with this platform/compiler combination."));
6656 /* Create a breakpoint struct for Ada exception catchpoints. */
6659 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6663 struct expression
*cond
,
6664 struct breakpoint_ops
*ops
,
6668 struct breakpoint
*b
;
6672 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6673 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6674 version for exception catchpoints, because two catchpoints
6675 used for different exception names will use the same address.
6676 In this case, a "breakpoint ... also set at..." warning is
6677 unproductive. Besides. the warning phrasing is also a bit
6678 inapropriate, we should use the word catchpoint, and tell
6679 the user what type of catchpoint it is. The above is good
6680 enough for now, though. */
6683 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6684 set_breakpoint_count (breakpoint_count
+ 1);
6686 b
->enable_state
= bp_enabled
;
6687 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6688 b
->number
= breakpoint_count
;
6689 b
->ignore_count
= 0;
6690 b
->loc
->cond
= cond
;
6691 b
->addr_string
= addr_string
;
6692 b
->language
= language_ada
;
6693 b
->cond_string
= cond_string
;
6694 b
->exp_string
= exp_string
;
6697 b
->from_tty
= from_tty
;
6702 /* Implement the "catch exception" command. */
6705 catch_ada_exception_command (char *arg
, int tempflag
, int from_tty
)
6707 struct symtab_and_line sal
;
6709 char *addr_string
= NULL
;
6710 char *exp_string
= NULL
;
6711 char *cond_string
= NULL
;
6712 struct expression
*cond
= NULL
;
6713 struct breakpoint_ops
*ops
= NULL
;
6715 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6716 &cond_string
, &cond
, &ops
);
6717 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6718 cond_string
, cond
, ops
, tempflag
,
6722 /* Implement the "catch assert" command. */
6725 catch_assert_command (char *arg
, int tempflag
, int from_tty
)
6727 struct symtab_and_line sal
;
6728 char *addr_string
= NULL
;
6729 struct breakpoint_ops
*ops
= NULL
;
6731 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6732 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6733 tempflag
, from_tty
);
6736 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6737 inside a catch_errors */
6740 cover_target_enable_exception_callback (void *arg
)
6742 args_for_catchpoint_enable
*args
= arg
;
6743 struct symtab_and_line
*sal
;
6744 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6747 else if (sal
== (struct symtab_and_line
*) -1)
6750 return 1; /*is valid */
6754 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6757 /* The first argument may be an event name, such as "start" or "load".
6758 If so, then handle it as such. If it doesn't match an event name,
6759 then attempt to interpret it as an exception name. (This latter is
6760 the v4.16-and-earlier GDB meaning of the "catch" command.)
6762 First, try to find the bounds of what might be an event name. */
6763 char *arg1_start
= arg
;
6767 if (arg1_start
== NULL
)
6769 /* Old behaviour was to use pre-v-4.16 syntax */
6770 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6772 /* Now, this is not allowed */
6773 error (_("Catch requires an event name."));
6776 arg1_end
= ep_find_event_name_end (arg1_start
);
6777 if (arg1_end
== NULL
)
6778 error (_("catch requires an event"));
6779 arg1_length
= arg1_end
+ 1 - arg1_start
;
6781 /* Try to match what we found against known event names. */
6782 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6784 error (_("Catch of signal not yet implemented"));
6786 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6788 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6789 tempflag
, from_tty
);
6791 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6793 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6794 tempflag
, from_tty
);
6796 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6798 error (_("Catch of thread_start not yet implemented"));
6800 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6802 error (_("Catch of thread_exit not yet implemented"));
6804 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6806 error (_("Catch of thread_join not yet implemented"));
6808 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6810 error (_("Catch of start not yet implemented"));
6812 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6814 error (_("Catch of exit not yet implemented"));
6816 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6818 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6820 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6822 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6824 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6826 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6828 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6830 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6832 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6834 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6836 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6838 error (_("Catch of stop not yet implemented"));
6840 else if (strncmp (arg1_start
, "exception", arg1_length
) == 0)
6842 catch_ada_exception_command (arg1_end
+ 1, tempflag
, from_tty
);
6845 else if (strncmp (arg1_start
, "assert", arg1_length
) == 0)
6847 catch_assert_command (arg1_end
+ 1, tempflag
, from_tty
);
6850 /* This doesn't appear to be an event name */
6854 /* Pre-v.4.16 behaviour was to treat the argument
6855 as the name of an exception */
6856 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6857 /* Now this is not allowed */
6858 error (_("Unknown event kind specified for catch"));
6864 catch_command (char *arg
, int from_tty
)
6866 catch_command_1 (arg
, 0, from_tty
);
6871 tcatch_command (char *arg
, int from_tty
)
6873 catch_command_1 (arg
, 1, from_tty
);
6876 /* Delete breakpoints by address or line. */
6879 clear_command (char *arg
, int from_tty
)
6881 struct breakpoint
*b
;
6882 VEC(breakpoint_p
) *found
= 0;
6885 struct symtabs_and_lines sals
;
6886 struct symtab_and_line sal
;
6891 sals
= decode_line_spec (arg
, 1);
6896 sals
.sals
= (struct symtab_and_line
*)
6897 xmalloc (sizeof (struct symtab_and_line
));
6898 make_cleanup (xfree
, sals
.sals
);
6899 init_sal (&sal
); /* initialize to zeroes */
6900 sal
.line
= default_breakpoint_line
;
6901 sal
.symtab
= default_breakpoint_symtab
;
6902 sal
.pc
= default_breakpoint_address
;
6903 if (sal
.symtab
== 0)
6904 error (_("No source file specified."));
6912 /* We don't call resolve_sal_pc here. That's not
6913 as bad as it seems, because all existing breakpoints
6914 typically have both file/line and pc set. So, if
6915 clear is given file/line, we can match this to existing
6916 breakpoint without obtaining pc at all.
6918 We only support clearing given the address explicitly
6919 present in breakpoint table. Say, we've set breakpoint
6920 at file:line. There were several PC values for that file:line,
6921 due to optimization, all in one block.
6922 We've picked one PC value. If "clear" is issued with another
6923 PC corresponding to the same file:line, the breakpoint won't
6924 be cleared. We probably can still clear the breakpoint, but
6925 since the other PC value is never presented to user, user
6926 can only find it by guessing, and it does not seem important
6929 /* For each line spec given, delete bps which correspond
6930 to it. Do it in two passes, solely to preserve the current
6931 behavior that from_tty is forced true if we delete more than
6935 for (i
= 0; i
< sals
.nelts
; i
++)
6937 /* If exact pc given, clear bpts at that pc.
6938 If line given (pc == 0), clear all bpts on specified line.
6939 If defaulting, clear all bpts on default line
6942 defaulting sal.pc != 0 tests to do
6947 1 0 <can't happen> */
6951 /* Find all matching breakpoints and add them to
6956 /* Are we going to delete b? */
6957 if (b
->type
!= bp_none
6958 && b
->type
!= bp_watchpoint
6959 && b
->type
!= bp_hardware_watchpoint
6960 && b
->type
!= bp_read_watchpoint
6961 && b
->type
!= bp_access_watchpoint
)
6963 struct bp_location
*loc
= b
->loc
;
6964 for (; loc
; loc
= loc
->next
)
6966 int pc_match
= sal
.pc
6967 && (loc
->address
== sal
.pc
)
6968 && (!section_is_overlay (loc
->section
)
6969 || loc
->section
== sal
.section
);
6970 int line_match
= ((default_match
|| (0 == sal
.pc
))
6971 && b
->source_file
!= NULL
6972 && sal
.symtab
!= NULL
6973 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6974 && b
->line_number
== sal
.line
);
6975 if (pc_match
|| line_match
)
6984 VEC_safe_push(breakpoint_p
, found
, b
);
6987 /* Now go thru the 'found' chain and delete them. */
6988 if (VEC_empty(breakpoint_p
, found
))
6991 error (_("No breakpoint at %s."), arg
);
6993 error (_("No breakpoint at this line."));
6996 if (VEC_length(breakpoint_p
, found
) > 1)
6997 from_tty
= 1; /* Always report if deleted more than one */
7000 if (VEC_length(breakpoint_p
, found
) == 1)
7001 printf_unfiltered (_("Deleted breakpoint "));
7003 printf_unfiltered (_("Deleted breakpoints "));
7005 breakpoints_changed ();
7007 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
7010 printf_unfiltered ("%d ", b
->number
);
7011 delete_breakpoint (b
);
7014 putchar_unfiltered ('\n');
7017 /* Delete breakpoint in BS if they are `delete' breakpoints and
7018 all breakpoints that are marked for deletion, whether hit or not.
7019 This is called after any breakpoint is hit, or after errors. */
7022 breakpoint_auto_delete (bpstat bs
)
7024 struct breakpoint
*b
, *temp
;
7026 for (; bs
; bs
= bs
->next
)
7027 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
->disposition
== disp_del
7029 delete_breakpoint (bs
->breakpoint_at
->owner
);
7031 ALL_BREAKPOINTS_SAFE (b
, temp
)
7033 if (b
->disposition
== disp_del_at_next_stop
)
7034 delete_breakpoint (b
);
7038 /* Remove locations of breakpoint BPT from
7039 the global list of breakpoint locations. */
7042 unlink_locations_from_global_list (struct breakpoint
*bpt
)
7044 /* This code assumes that the locations
7045 of a breakpoint are found in the global list
7046 in the same order, but not necessary adjacent. */
7047 struct bp_location
**tmp
= &bp_location_chain
;
7048 struct bp_location
*here
= bpt
->loc
;
7053 for (; *tmp
&& here
;)
7057 *tmp
= here
->global_next
;
7062 tmp
= &((*tmp
)->global_next
);
7067 /* Delete a breakpoint and clean up all traces of it in the data
7071 delete_breakpoint (struct breakpoint
*bpt
)
7073 struct breakpoint
*b
;
7075 struct bp_location
*loc
;
7077 gdb_assert (bpt
!= NULL
);
7079 /* Has this bp already been deleted? This can happen because multiple
7080 lists can hold pointers to bp's. bpstat lists are especial culprits.
7082 One example of this happening is a watchpoint's scope bp. When the
7083 scope bp triggers, we notice that the watchpoint is out of scope, and
7084 delete it. We also delete its scope bp. But the scope bp is marked
7085 "auto-deleting", and is already on a bpstat. That bpstat is then
7086 checked for auto-deleting bp's, which are deleted.
7088 A real solution to this problem might involve reference counts in bp's,
7089 and/or giving them pointers back to their referencing bpstat's, and
7090 teaching delete_breakpoint to only free a bp's storage when no more
7091 references were extent. A cheaper bandaid was chosen. */
7092 if (bpt
->type
== bp_none
)
7095 if (deprecated_delete_breakpoint_hook
)
7096 deprecated_delete_breakpoint_hook (bpt
);
7097 breakpoint_delete_event (bpt
->number
);
7099 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
7102 remove_breakpoint (loc
, mark_inserted
);
7104 free_valchain (loc
);
7109 if (loc
->function_name
)
7110 xfree (loc
->function_name
);
7113 if (breakpoint_chain
== bpt
)
7114 breakpoint_chain
= bpt
->next
;
7116 /* If we have callback-style exception catchpoints, don't go through
7117 the adjustments to the C++ runtime library etc. if the inferior
7118 isn't actually running. target_enable_exception_callback for a
7119 null target ops vector gives an undesirable error message, so we
7120 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
7121 exceptions are supported in this way, it's OK for now. FIXME */
7122 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
7124 /* Format possible error msg */
7125 char *message
= xstrprintf ("Error in deleting catchpoint %d:\n",
7127 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7128 args_for_catchpoint_enable args
;
7129 args
.kind
= bpt
->type
== bp_catch_catch
?
7130 EX_EVENT_CATCH
: EX_EVENT_THROW
;
7132 catch_errors (cover_target_enable_exception_callback
, &args
,
7133 message
, RETURN_MASK_ALL
);
7134 do_cleanups (cleanups
);
7141 b
->next
= bpt
->next
;
7145 unlink_locations_from_global_list (bpt
);
7147 check_duplicates (bpt
);
7149 if (bpt
->type
!= bp_hardware_watchpoint
7150 && bpt
->type
!= bp_read_watchpoint
7151 && bpt
->type
!= bp_access_watchpoint
7152 && bpt
->type
!= bp_catch_fork
7153 && bpt
->type
!= bp_catch_vfork
7154 && bpt
->type
!= bp_catch_exec
)
7155 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
7157 /* If this breakpoint location was inserted, and there is
7158 another breakpoint at the same address, we need to
7159 insert the other breakpoint. */
7162 struct bp_location
*loc2
;
7163 ALL_BP_LOCATIONS (loc2
)
7164 if (loc2
->address
== loc
->address
7165 && loc2
->section
== loc
->section
7167 && loc2
->owner
->enable_state
!= bp_disabled
7169 && !loc2
->shlib_disabled
7170 && loc2
->owner
->enable_state
!= bp_call_disabled
)
7174 /* We should never reach this point if there is a permanent
7175 breakpoint at the same address as the one being deleted.
7176 If there is a permanent breakpoint somewhere, it should
7177 always be the only one inserted. */
7178 if (loc2
->owner
->enable_state
== bp_permanent
)
7179 internal_error (__FILE__
, __LINE__
,
7180 _("another breakpoint was inserted on top of "
7181 "a permanent breakpoint"));
7183 memset (&loc2
->target_info
, 0, sizeof (loc2
->target_info
));
7184 loc2
->target_info
.placed_address
= loc2
->address
;
7185 if (b
->type
== bp_hardware_breakpoint
)
7186 val
= target_insert_hw_breakpoint (&loc2
->target_info
);
7188 val
= target_insert_breakpoint (&loc2
->target_info
);
7190 /* If there was an error in the insert, print a message, then stop execution. */
7193 struct ui_file
*tmp_error_stream
= mem_fileopen ();
7194 make_cleanup_ui_file_delete (tmp_error_stream
);
7197 if (b
->type
== bp_hardware_breakpoint
)
7199 fprintf_unfiltered (tmp_error_stream
,
7200 "Cannot insert hardware breakpoint %d.\n"
7201 "You may have requested too many hardware breakpoints.\n",
7206 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
7207 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
7208 deprecated_print_address_numeric (loc2
->address
, 1, tmp_error_stream
);
7209 fprintf_filtered (tmp_error_stream
, ": %s.\n",
7210 safe_strerror (val
));
7213 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
7214 target_terminal_ours_for_output ();
7215 error_stream(tmp_error_stream
);
7223 free_command_lines (&bpt
->commands
);
7224 if (bpt
->cond_string
!= NULL
)
7225 xfree (bpt
->cond_string
);
7226 if (bpt
->addr_string
!= NULL
)
7227 xfree (bpt
->addr_string
);
7228 if (bpt
->exp
!= NULL
)
7230 if (bpt
->exp_string
!= NULL
)
7231 xfree (bpt
->exp_string
);
7232 if (bpt
->val
!= NULL
)
7233 value_free (bpt
->val
);
7234 if (bpt
->source_file
!= NULL
)
7235 xfree (bpt
->source_file
);
7236 if (bpt
->dll_pathname
!= NULL
)
7237 xfree (bpt
->dll_pathname
);
7238 if (bpt
->triggered_dll_pathname
!= NULL
)
7239 xfree (bpt
->triggered_dll_pathname
);
7240 if (bpt
->exec_pathname
!= NULL
)
7241 xfree (bpt
->exec_pathname
);
7243 /* Be sure no bpstat's are pointing at it after it's been freed. */
7244 /* FIXME, how can we find all bpstat's?
7245 We just check stop_bpstat for now. Note that we cannot just
7246 remove bpstats pointing at bpt from the stop_bpstat list
7247 entirely, as breakpoint commands are associated with the bpstat;
7248 if we remove it here, then the later call to
7249 bpstat_do_actions (&stop_bpstat);
7250 in event-top.c won't do anything, and temporary breakpoints
7251 with commands won't work. */
7252 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
7253 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7255 bs
->breakpoint_at
= NULL
;
7257 /* bs->commands will be freed later. */
7259 /* On the chance that someone will soon try again to delete this same
7260 bp, we mark it as deleted before freeing its storage. */
7261 bpt
->type
= bp_none
;
7263 for (loc
= bpt
->loc
; loc
;)
7265 struct bp_location
*loc_next
= loc
->next
;
7273 do_delete_breakpoint_cleanup (void *b
)
7275 delete_breakpoint (b
);
7279 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7281 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7285 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
7287 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
7291 delete_command (char *arg
, int from_tty
)
7293 struct breakpoint
*b
, *temp
;
7299 int breaks_to_delete
= 0;
7301 /* Delete all breakpoints if no argument.
7302 Do not delete internal or call-dummy breakpoints, these
7303 have to be deleted with an explicit breakpoint number argument. */
7306 if (b
->type
!= bp_call_dummy
&&
7307 b
->type
!= bp_shlib_event
&&
7308 b
->type
!= bp_thread_event
&&
7309 b
->type
!= bp_overlay_event
&&
7312 breaks_to_delete
= 1;
7317 /* Ask user only if there are some breakpoints to delete. */
7319 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7321 ALL_BREAKPOINTS_SAFE (b
, temp
)
7323 if (b
->type
!= bp_call_dummy
&&
7324 b
->type
!= bp_shlib_event
&&
7325 b
->type
!= bp_thread_event
&&
7326 b
->type
!= bp_overlay_event
&&
7328 delete_breakpoint (b
);
7333 map_breakpoint_numbers (arg
, delete_breakpoint
);
7337 all_locations_are_pending (struct bp_location
*loc
)
7339 for (; loc
; loc
= loc
->next
)
7340 if (!loc
->shlib_disabled
)
7346 update_breakpoint_locations (struct breakpoint
*b
,
7347 struct symtabs_and_lines sals
)
7351 struct bp_location
*existing_locations
= b
->loc
;
7353 /* If there's no new locations, and all existing locations
7354 are pending, don't do anything. This optimizes
7355 the common case where all locations are in the same
7356 shared library, that was unloaded. We'd like to
7357 retain the location, so that when the library
7358 is loaded again, we don't loose the enabled/disabled
7359 status of the individual locations. */
7360 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7363 unlink_locations_from_global_list (b
);
7366 for (i
= 0; i
< sals
.nelts
; ++i
)
7368 struct bp_location
*new_loc
=
7369 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7371 /* Reparse conditions, they might contain references to the
7373 if (b
->cond_string
!= NULL
)
7375 struct gdb_exception e
;
7378 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7380 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7385 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7386 b
->number
, e
.message
);
7387 new_loc
->enabled
= 0;
7391 if (b
->source_file
!= NULL
)
7392 xfree (b
->source_file
);
7393 if (sals
.sals
[i
].symtab
== NULL
)
7394 b
->source_file
= NULL
;
7397 savestring (sals
.sals
[i
].symtab
->filename
,
7398 strlen (sals
.sals
[i
].symtab
->filename
));
7400 if (b
->line_number
== 0)
7401 b
->line_number
= sals
.sals
[i
].line
;
7404 /* If possible, carry over 'disable' status from existing breakpoints. */
7406 struct bp_location
*e
= existing_locations
;
7407 for (; e
; e
= e
->next
)
7409 if (!e
->enabled
&& e
->function_name
)
7411 struct bp_location
*l
= b
->loc
;
7412 for (; l
; l
= l
->next
)
7413 if (l
->function_name
7414 && strcmp (e
->function_name
, l
->function_name
) == 0)
7423 while (existing_locations
)
7425 struct bp_location
*next
= existing_locations
->next
;
7426 free_bp_location (existing_locations
);
7427 existing_locations
= next
;
7432 /* Reset a breakpoint given it's struct breakpoint * BINT.
7433 The value we return ends up being the return value from catch_errors.
7434 Unused in this case. */
7437 breakpoint_re_set_one (void *bint
)
7439 /* get past catch_errs */
7440 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7444 int *not_found_ptr
= ¬_found
;
7445 struct symtabs_and_lines sals
= {};
7446 struct symtabs_and_lines expanded
;
7448 enum enable_state save_enable
;
7449 struct gdb_exception e
;
7455 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7459 case bp_hardware_breakpoint
:
7461 case bp_catch_unload
:
7462 if (b
->addr_string
== NULL
)
7464 /* Anything without a string can't be re-set. */
7465 delete_breakpoint (b
);
7469 set_language (b
->language
);
7470 input_radix
= b
->input_radix
;
7472 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7474 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7479 int not_found_and_ok
= 0;
7480 /* For pending breakpoints, it's expected that parsing
7481 will fail until the right shared library is loaded.
7482 User has already told to create pending breakpoints and
7483 don't need extra messages. If breakpoint is in bp_shlib_disabled
7484 state, then user already saw the message about that breakpoint
7485 being disabled, and don't want to see more errors. */
7487 && (b
->condition_not_parsed
7488 || (b
->loc
&& b
->loc
->shlib_disabled
)
7489 || b
->enable_state
== bp_disabled
))
7490 not_found_and_ok
= 1;
7492 if (!not_found_and_ok
)
7494 /* We surely don't want to warn about the same breakpoint
7495 10 times. One solution, implemented here, is disable
7496 the breakpoint on error. Another solution would be to
7497 have separate 'warning emitted' flag. Since this
7498 happens only when a binary has changed, I don't know
7499 which approach is better. */
7500 b
->enable_state
= bp_disabled
;
7501 throw_exception (e
);
7508 gdb_assert (sals
.nelts
== 1);
7509 resolve_sal_pc (&sals
.sals
[0]);
7510 if (b
->condition_not_parsed
&& s
&& s
[0])
7512 char *cond_string
= 0;
7514 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7515 &cond_string
, &thread
);
7517 b
->cond_string
= cond_string
;
7519 b
->condition_not_parsed
= 0;
7521 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7522 update_breakpoint_locations (b
, expanded
);
7524 /* Now that this is re-enabled, check_duplicates
7526 check_duplicates (b
);
7532 case bp_hardware_watchpoint
:
7533 case bp_read_watchpoint
:
7534 case bp_access_watchpoint
:
7535 innermost_block
= NULL
;
7536 /* The issue arises of what context to evaluate this in. The
7537 same one as when it was set, but what does that mean when
7538 symbols have been re-read? We could save the filename and
7539 functionname, but if the context is more local than that, the
7540 best we could do would be something like how many levels deep
7541 and which index at that particular level, but that's going to
7542 be less stable than filenames or function names. */
7544 /* So for now, just use a global context. */
7548 /* Avoid re-freeing b->exp if an error during the call to
7549 parse_expression. */
7552 b
->exp
= parse_expression (b
->exp_string
);
7553 b
->exp_valid_block
= innermost_block
;
7554 mark
= value_mark ();
7557 value_free (b
->val
);
7558 /* Avoid re-freeing b->val if an error during the call to
7559 evaluate_expression. */
7562 b
->val
= evaluate_expression (b
->exp
);
7563 release_value (b
->val
);
7564 if (value_lazy (b
->val
) && breakpoint_enabled (b
))
7565 value_fetch_lazy (b
->val
);
7567 if (b
->cond_string
!= NULL
)
7572 xfree (b
->loc
->cond
);
7573 /* Avoid re-freeing b->exp if an error during the call
7575 b
->loc
->cond
= NULL
;
7577 b
->loc
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
7579 if (breakpoint_enabled (b
))
7581 value_free_to_mark (mark
);
7583 case bp_catch_catch
:
7584 case bp_catch_throw
:
7586 /* We needn't really do anything to reset these, since the mask
7587 that requests them is unaffected by e.g., new libraries being
7590 case bp_catch_vfork
:
7595 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7597 /* Delete longjmp and overlay event breakpoints; they will be
7598 reset later by breakpoint_re_set. */
7600 case bp_longjmp_resume
:
7601 case bp_overlay_event
:
7602 delete_breakpoint (b
);
7605 /* This breakpoint is special, it's set up when the inferior
7606 starts and we really don't want to touch it. */
7607 case bp_shlib_event
:
7609 /* Like bp_shlib_event, this breakpoint type is special.
7610 Once it is set up, we do not want to touch it. */
7611 case bp_thread_event
:
7613 /* Keep temporary breakpoints, which can be encountered when we step
7614 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7615 Otherwise these should have been blown away via the cleanup chain
7616 or by breakpoint_init_inferior when we rerun the executable. */
7619 case bp_watchpoint_scope
:
7621 case bp_step_resume
:
7628 /* Re-set all breakpoints after symbols have been re-loaded. */
7630 breakpoint_re_set (void)
7632 struct breakpoint
*b
, *temp
;
7633 enum language save_language
;
7634 int save_input_radix
;
7636 save_language
= current_language
->la_language
;
7637 save_input_radix
= input_radix
;
7638 ALL_BREAKPOINTS_SAFE (b
, temp
)
7640 /* Format possible error msg */
7641 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7643 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7644 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7645 do_cleanups (cleanups
);
7647 set_language (save_language
);
7648 input_radix
= save_input_radix
;
7650 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
7652 create_longjmp_breakpoint ("longjmp");
7653 create_longjmp_breakpoint ("_longjmp");
7654 create_longjmp_breakpoint ("siglongjmp");
7655 create_longjmp_breakpoint ("_siglongjmp");
7656 create_longjmp_breakpoint (NULL
);
7659 create_overlay_event_breakpoint ("_ovly_debug_event");
7662 /* Reset the thread number of this breakpoint:
7664 - If the breakpoint is for all threads, leave it as-is.
7665 - Else, reset it to the current thread for inferior_ptid. */
7667 breakpoint_re_set_thread (struct breakpoint
*b
)
7669 if (b
->thread
!= -1)
7671 if (in_thread_list (inferior_ptid
))
7672 b
->thread
= pid_to_thread_id (inferior_ptid
);
7676 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7677 If from_tty is nonzero, it prints a message to that effect,
7678 which ends with a period (no newline). */
7681 set_ignore_count (int bptnum
, int count
, int from_tty
)
7683 struct breakpoint
*b
;
7689 if (b
->number
== bptnum
)
7691 b
->ignore_count
= count
;
7695 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7697 else if (count
== 1)
7698 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7701 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7704 breakpoints_changed ();
7705 breakpoint_modify_event (b
->number
);
7709 error (_("No breakpoint number %d."), bptnum
);
7712 /* Clear the ignore counts of all breakpoints. */
7714 breakpoint_clear_ignore_counts (void)
7716 struct breakpoint
*b
;
7719 b
->ignore_count
= 0;
7722 /* Command to set ignore-count of breakpoint N to COUNT. */
7725 ignore_command (char *args
, int from_tty
)
7731 error_no_arg (_("a breakpoint number"));
7733 num
= get_number (&p
);
7735 error (_("bad breakpoint number: '%s'"), args
);
7737 error (_("Second argument (specified ignore-count) is missing."));
7739 set_ignore_count (num
,
7740 longest_to_int (value_as_long (parse_and_eval (p
))),
7743 printf_filtered ("\n");
7746 /* Call FUNCTION on each of the breakpoints
7747 whose numbers are given in ARGS. */
7750 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7755 struct breakpoint
*b
, *tmp
;
7759 error_no_arg (_("one or more breakpoint numbers"));
7766 num
= get_number_or_range (&p1
);
7769 warning (_("bad breakpoint number at or near '%s'"), p
);
7773 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7774 if (b
->number
== num
)
7776 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7779 if (related_breakpoint
)
7780 function (related_breakpoint
);
7784 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7790 static struct bp_location
*
7791 find_location_by_number (char *number
)
7793 char *dot
= strchr (number
, '.');
7797 struct breakpoint
*b
;
7798 struct bp_location
*loc
;
7803 bp_num
= get_number_or_range (&p1
);
7805 error (_("Bad breakpoint number '%s'"), number
);
7808 if (b
->number
== bp_num
)
7813 if (!b
|| b
->number
!= bp_num
)
7814 error (_("Bad breakpoint number '%s'"), number
);
7817 loc_num
= get_number_or_range (&p1
);
7819 error (_("Bad breakpoint location number '%s'"), number
);
7823 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7826 error (_("Bad breakpoint location number '%s'"), dot
+1);
7832 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7833 If from_tty is nonzero, it prints a message to that effect,
7834 which ends with a period (no newline). */
7837 disable_breakpoint (struct breakpoint
*bpt
)
7839 /* Never disable a watchpoint scope breakpoint; we want to
7840 hit them when we leave scope so we can delete both the
7841 watchpoint and its scope breakpoint at that time. */
7842 if (bpt
->type
== bp_watchpoint_scope
)
7845 /* You can't disable permanent breakpoints. */
7846 if (bpt
->enable_state
== bp_permanent
)
7849 bpt
->enable_state
= bp_disabled
;
7851 check_duplicates (bpt
);
7853 if (deprecated_modify_breakpoint_hook
)
7854 deprecated_modify_breakpoint_hook (bpt
);
7855 breakpoint_modify_event (bpt
->number
);
7859 disable_command (char *args
, int from_tty
)
7861 struct breakpoint
*bpt
;
7863 ALL_BREAKPOINTS (bpt
)
7867 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7872 case bp_catch_unload
:
7874 case bp_catch_vfork
:
7876 case bp_catch_catch
:
7877 case bp_catch_throw
:
7878 case bp_hardware_breakpoint
:
7880 case bp_hardware_watchpoint
:
7881 case bp_read_watchpoint
:
7882 case bp_access_watchpoint
:
7883 disable_breakpoint (bpt
);
7887 else if (strchr (args
, '.'))
7889 struct bp_location
*loc
= find_location_by_number (args
);
7892 check_duplicates (loc
->owner
);
7895 map_breakpoint_numbers (args
, disable_breakpoint
);
7899 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7901 int target_resources_ok
, other_type_used
;
7904 if (bpt
->type
== bp_hardware_breakpoint
)
7907 i
= hw_breakpoint_used_count ();
7908 target_resources_ok
=
7909 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7911 if (target_resources_ok
== 0)
7912 error (_("No hardware breakpoint support in the target."));
7913 else if (target_resources_ok
< 0)
7914 error (_("Hardware breakpoints used exceeds limit."));
7917 if (bpt
->type
== bp_watchpoint
||
7918 bpt
->type
== bp_hardware_watchpoint
||
7919 bpt
->type
== bp_read_watchpoint
||
7920 bpt
->type
== bp_access_watchpoint
)
7922 struct frame_id saved_frame_id
;
7924 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7925 if (bpt
->exp_valid_block
!= NULL
)
7927 struct frame_info
*fr
=
7928 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7931 printf_filtered (_("\
7932 Cannot enable watchpoint %d because the block in which its expression\n\
7933 is valid is not currently in scope.\n"), bpt
->number
);
7940 value_free (bpt
->val
);
7941 mark
= value_mark ();
7942 bpt
->val
= evaluate_expression (bpt
->exp
);
7943 release_value (bpt
->val
);
7944 if (value_lazy (bpt
->val
))
7945 value_fetch_lazy (bpt
->val
);
7947 if (bpt
->type
== bp_hardware_watchpoint
||
7948 bpt
->type
== bp_read_watchpoint
||
7949 bpt
->type
== bp_access_watchpoint
)
7951 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7952 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7954 /* Hack around 'unused var' error for some targets here */
7955 (void) mem_cnt
, (void) i
;
7956 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7957 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7958 /* we can consider of type is bp_hardware_watchpoint, convert to
7959 bp_watchpoint in the following condition */
7960 if (target_resources_ok
< 0)
7962 printf_filtered (_("\
7963 Cannot enable watchpoint %d because target watch resources\n\
7964 have been allocated for other watchpoints.\n"), bpt
->number
);
7965 value_free_to_mark (mark
);
7970 select_frame (frame_find_by_id (saved_frame_id
));
7971 value_free_to_mark (mark
);
7974 if (bpt
->enable_state
!= bp_permanent
)
7975 bpt
->enable_state
= bp_enabled
;
7976 bpt
->disposition
= disposition
;
7977 check_duplicates (bpt
);
7978 breakpoints_changed ();
7980 if (deprecated_modify_breakpoint_hook
)
7981 deprecated_modify_breakpoint_hook (bpt
);
7982 breakpoint_modify_event (bpt
->number
);
7987 enable_breakpoint (struct breakpoint
*bpt
)
7989 do_enable_breakpoint (bpt
, bpt
->disposition
);
7992 /* The enable command enables the specified breakpoints (or all defined
7993 breakpoints) so they once again become (or continue to be) effective
7994 in stopping the inferior. */
7997 enable_command (char *args
, int from_tty
)
7999 struct breakpoint
*bpt
;
8001 ALL_BREAKPOINTS (bpt
)
8005 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8010 case bp_catch_unload
:
8012 case bp_catch_vfork
:
8014 case bp_catch_catch
:
8015 case bp_catch_throw
:
8016 case bp_hardware_breakpoint
:
8018 case bp_hardware_watchpoint
:
8019 case bp_read_watchpoint
:
8020 case bp_access_watchpoint
:
8021 enable_breakpoint (bpt
);
8025 else if (strchr (args
, '.'))
8027 struct bp_location
*loc
= find_location_by_number (args
);
8030 check_duplicates (loc
->owner
);
8033 map_breakpoint_numbers (args
, enable_breakpoint
);
8037 enable_once_breakpoint (struct breakpoint
*bpt
)
8039 do_enable_breakpoint (bpt
, disp_disable
);
8043 enable_once_command (char *args
, int from_tty
)
8045 map_breakpoint_numbers (args
, enable_once_breakpoint
);
8049 enable_delete_breakpoint (struct breakpoint
*bpt
)
8051 do_enable_breakpoint (bpt
, disp_del
);
8055 enable_delete_command (char *args
, int from_tty
)
8057 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8061 set_breakpoint_cmd (char *args
, int from_tty
)
8066 show_breakpoint_cmd (char *args
, int from_tty
)
8070 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8072 struct symtabs_and_lines
8073 decode_line_spec_1 (char *string
, int funfirstline
)
8075 struct symtabs_and_lines sals
;
8077 error (_("Empty line specification."));
8078 if (default_breakpoint_valid
)
8079 sals
= decode_line_1 (&string
, funfirstline
,
8080 default_breakpoint_symtab
,
8081 default_breakpoint_line
,
8082 (char ***) NULL
, NULL
);
8084 sals
= decode_line_1 (&string
, funfirstline
,
8085 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8087 error (_("Junk at end of line specification: %s"), string
);
8091 /* Create and insert a raw software breakpoint at PC. Return an
8092 identifier, which should be used to remove the breakpoint later.
8093 In general, places which call this should be using something on the
8094 breakpoint chain instead; this function should be eliminated
8098 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8100 struct bp_target_info
*bp_tgt
;
8102 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8103 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8105 bp_tgt
->placed_address
= pc
;
8106 if (target_insert_breakpoint (bp_tgt
) != 0)
8108 /* Could not insert the breakpoint. */
8116 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8119 deprecated_remove_raw_breakpoint (void *bp
)
8121 struct bp_target_info
*bp_tgt
= bp
;
8124 ret
= target_remove_breakpoint (bp_tgt
);
8130 /* One (or perhaps two) breakpoints used for software single stepping. */
8132 static void *single_step_breakpoints
[2];
8134 /* Create and insert a breakpoint for software single step. */
8137 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8141 if (single_step_breakpoints
[0] == NULL
)
8142 bpt_p
= &single_step_breakpoints
[0];
8145 gdb_assert (single_step_breakpoints
[1] == NULL
);
8146 bpt_p
= &single_step_breakpoints
[1];
8149 /* NOTE drow/2006-04-11: A future improvement to this function would be
8150 to only create the breakpoints once, and actually put them on the
8151 breakpoint chain. That would let us use set_raw_breakpoint. We could
8152 adjust the addresses each time they were needed. Doing this requires
8153 corresponding changes elsewhere where single step breakpoints are
8154 handled, however. So, for now, we use this. */
8156 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8158 error (_("Could not insert single-step breakpoint at 0x%s"),
8159 paddr_nz (next_pc
));
8162 /* Remove and delete any breakpoints used for software single step. */
8165 remove_single_step_breakpoints (void)
8167 gdb_assert (single_step_breakpoints
[0] != NULL
);
8169 /* See insert_single_step_breakpoint for more about this deprecated
8171 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8172 single_step_breakpoints
[0] = NULL
;
8174 if (single_step_breakpoints
[1] != NULL
)
8176 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8177 single_step_breakpoints
[1] = NULL
;
8181 /* Check whether a software single-step breakpoint is inserted at PC. */
8184 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8188 for (i
= 0; i
< 2; i
++)
8190 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8191 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8199 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8200 It is defined as a macro to prevent duplication.
8201 COMMAND should be a string constant containing the name of the command. */
8202 #define BREAK_ARGS_HELP(command) \
8203 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8204 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8205 If a line number is specified, break at start of code for that line.\n\
8206 If a function is specified, break at start of code for that function.\n\
8207 If an address is specified, break at that exact address.\n\
8208 With no LOCATION, uses current execution address of selected stack frame.\n\
8209 This is useful for breaking on return to a stack frame.\n\
8211 THREADNUM is the number from \"info threads\".\n\
8212 CONDITION is a boolean expression.\n\
8214 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8216 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8219 _initialize_breakpoint (void)
8221 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8222 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8223 struct cmd_list_element
*c
;
8225 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8227 breakpoint_chain
= 0;
8228 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8229 before a breakpoint is set. */
8230 breakpoint_count
= 0;
8232 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8233 Set ignore-count of breakpoint number N to COUNT.\n\
8234 Usage is `ignore N COUNT'."));
8236 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8238 add_com ("commands", class_breakpoint
, commands_command
, _("\
8239 Set commands to be executed when a breakpoint is hit.\n\
8240 Give breakpoint number as argument after \"commands\".\n\
8241 With no argument, the targeted breakpoint is the last one set.\n\
8242 The commands themselves follow starting on the next line.\n\
8243 Type a line containing \"end\" to indicate the end of them.\n\
8244 Give \"silent\" as the first line to make the breakpoint silent;\n\
8245 then no output is printed when it is hit, except what the commands print."));
8247 add_com ("condition", class_breakpoint
, condition_command
, _("\
8248 Specify breakpoint number N to break only if COND is true.\n\
8249 Usage is `condition N COND', where N is an integer and COND is an\n\
8250 expression to be evaluated whenever breakpoint N is reached."));
8252 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8253 Set a temporary breakpoint.\n\
8254 Like \"break\" except the breakpoint is only temporary,\n\
8255 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8256 by using \"enable delete\" on the breakpoint number.\n\
8258 BREAK_ARGS_HELP ("tbreak")));
8259 set_cmd_completer (c
, location_completer
);
8261 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8262 Set a hardware assisted breakpoint.\n\
8263 Like \"break\" except the breakpoint requires hardware support,\n\
8264 some target hardware may not have this support.\n\
8266 BREAK_ARGS_HELP ("hbreak")));
8267 set_cmd_completer (c
, location_completer
);
8269 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8270 Set a temporary hardware assisted breakpoint.\n\
8271 Like \"hbreak\" except the breakpoint is only temporary,\n\
8272 so it will be deleted when hit.\n\
8274 BREAK_ARGS_HELP ("thbreak")));
8275 set_cmd_completer (c
, location_completer
);
8277 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8278 Enable some breakpoints.\n\
8279 Give breakpoint numbers (separated by spaces) as arguments.\n\
8280 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8281 This is used to cancel the effect of the \"disable\" command.\n\
8282 With a subcommand you can enable temporarily."),
8283 &enablelist
, "enable ", 1, &cmdlist
);
8285 add_com ("ab", class_breakpoint
, enable_command
, _("\
8286 Enable some breakpoints.\n\
8287 Give breakpoint numbers (separated by spaces) as arguments.\n\
8288 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8289 This is used to cancel the effect of the \"disable\" command.\n\
8290 With a subcommand you can enable temporarily."));
8292 add_com_alias ("en", "enable", class_breakpoint
, 1);
8294 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8295 Enable some breakpoints.\n\
8296 Give breakpoint numbers (separated by spaces) as arguments.\n\
8297 This is used to cancel the effect of the \"disable\" command.\n\
8298 May be abbreviated to simply \"enable\".\n"),
8299 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8301 add_cmd ("once", no_class
, enable_once_command
, _("\
8302 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8303 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8306 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8307 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8308 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8311 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8312 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8313 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8316 add_cmd ("once", no_class
, enable_once_command
, _("\
8317 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8318 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8321 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8322 Disable some breakpoints.\n\
8323 Arguments are breakpoint numbers with spaces in between.\n\
8324 To disable all breakpoints, give no argument.\n\
8325 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8326 &disablelist
, "disable ", 1, &cmdlist
);
8327 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8328 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8330 add_com ("sb", class_breakpoint
, disable_command
, _("\
8331 Disable some breakpoints.\n\
8332 Arguments are breakpoint numbers with spaces in between.\n\
8333 To disable all breakpoints, give no argument.\n\
8334 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8336 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8337 Disable some breakpoints.\n\
8338 Arguments are breakpoint numbers with spaces in between.\n\
8339 To disable all breakpoints, give no argument.\n\
8340 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8341 This command may be abbreviated \"disable\"."),
8344 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8345 Delete some breakpoints or auto-display expressions.\n\
8346 Arguments are breakpoint numbers with spaces in between.\n\
8347 To delete all breakpoints, give no argument.\n\
8349 Also a prefix command for deletion of other GDB objects.\n\
8350 The \"unset\" command is also an alias for \"delete\"."),
8351 &deletelist
, "delete ", 1, &cmdlist
);
8352 add_com_alias ("d", "delete", class_breakpoint
, 1);
8353 add_com_alias ("del", "delete", class_breakpoint
, 1);
8355 add_com ("db", class_breakpoint
, delete_command
, _("\
8356 Delete some breakpoints.\n\
8357 Arguments are breakpoint numbers with spaces in between.\n\
8358 To delete all breakpoints, give no argument.\n"));
8360 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8361 Delete some breakpoints or auto-display expressions.\n\
8362 Arguments are breakpoint numbers with spaces in between.\n\
8363 To delete all breakpoints, give no argument.\n\
8364 This command may be abbreviated \"delete\"."),
8367 add_com ("clear", class_breakpoint
, clear_command
, _("\
8368 Clear breakpoint at specified line or function.\n\
8369 Argument may be line number, function name, or \"*\" and an address.\n\
8370 If line number is specified, all breakpoints in that line are cleared.\n\
8371 If function is specified, breakpoints at beginning of function are cleared.\n\
8372 If an address is specified, breakpoints at that address are cleared.\n\
8374 With no argument, clears all breakpoints in the line that the selected frame\n\
8377 See also the \"delete\" command which clears breakpoints by number."));
8379 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8380 Set breakpoint at specified line or function.\n"
8381 BREAK_ARGS_HELP ("break")));
8382 set_cmd_completer (c
, location_completer
);
8384 add_com_alias ("b", "break", class_run
, 1);
8385 add_com_alias ("br", "break", class_run
, 1);
8386 add_com_alias ("bre", "break", class_run
, 1);
8387 add_com_alias ("brea", "break", class_run
, 1);
8391 add_com_alias ("ba", "break", class_breakpoint
, 1);
8392 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8397 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8398 Break in function/address or break at a line in the current file."),
8399 &stoplist
, "stop ", 1, &cmdlist
);
8400 add_cmd ("in", class_breakpoint
, stopin_command
,
8401 _("Break in function or address."), &stoplist
);
8402 add_cmd ("at", class_breakpoint
, stopat_command
,
8403 _("Break at a line in the current file."), &stoplist
);
8404 add_com ("status", class_info
, breakpoints_info
, _("\
8405 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8406 The \"Type\" column indicates one of:\n\
8407 \tbreakpoint - normal breakpoint\n\
8408 \twatchpoint - watchpoint\n\
8409 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8410 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8411 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8412 address and file/line number respectively.\n\
8414 Convenience variable \"$_\" and default examine address for \"x\"\n\
8415 are set to the address of the last breakpoint listed unless the command\n\
8416 is prefixed with \"server \".\n\n\
8417 Convenience variable \"$bpnum\" contains the number of the last\n\
8421 add_info ("breakpoints", breakpoints_info
, _("\
8422 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8423 The \"Type\" column indicates one of:\n\
8424 \tbreakpoint - normal breakpoint\n\
8425 \twatchpoint - watchpoint\n\
8426 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8427 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8428 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8429 address and file/line number respectively.\n\
8431 Convenience variable \"$_\" and default examine address for \"x\"\n\
8432 are set to the address of the last breakpoint listed unless the command\n\
8433 is prefixed with \"server \".\n\n\
8434 Convenience variable \"$bpnum\" contains the number of the last\n\
8438 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8439 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8440 The \"Type\" column indicates one of:\n\
8441 \tbreakpoint - normal breakpoint\n\
8442 \twatchpoint - watchpoint\n\
8443 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8444 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8445 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8446 address and file/line number respectively.\n\
8448 Convenience variable \"$_\" and default examine address for \"x\"\n\
8449 are set to the address of the last breakpoint listed unless the command\n\
8450 is prefixed with \"server \".\n\n\
8451 Convenience variable \"$bpnum\" contains the number of the last\n\
8454 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8455 Status of all breakpoints, or breakpoint number NUMBER.\n\
8456 The \"Type\" column indicates one of:\n\
8457 \tbreakpoint - normal breakpoint\n\
8458 \twatchpoint - watchpoint\n\
8459 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8460 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8461 \tuntil - internal breakpoint used by the \"until\" command\n\
8462 \tfinish - internal breakpoint used by the \"finish\" command\n\
8463 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8464 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8465 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8466 address and file/line number respectively.\n\
8468 Convenience variable \"$_\" and default examine address for \"x\"\n\
8469 are set to the address of the last breakpoint listed unless the command\n\
8470 is prefixed with \"server \".\n\n\
8471 Convenience variable \"$bpnum\" contains the number of the last\n\
8473 &maintenanceinfolist
);
8475 add_com ("catch", class_breakpoint
, catch_command
, _("\
8476 Set catchpoints to catch events.\n\
8477 Raised signals may be caught:\n\
8478 \tcatch signal - all signals\n\
8479 \tcatch signal <signame> - a particular signal\n\
8480 Raised exceptions may be caught:\n\
8481 \tcatch throw - all exceptions, when thrown\n\
8482 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8483 \tcatch catch - all exceptions, when caught\n\
8484 \tcatch catch <exceptname> - a particular exception, when caught\n\
8485 Thread or process events may be caught:\n\
8486 \tcatch thread_start - any threads, just after creation\n\
8487 \tcatch thread_exit - any threads, just before expiration\n\
8488 \tcatch thread_join - any threads, just after joins\n\
8489 Process events may be caught:\n\
8490 \tcatch start - any processes, just after creation\n\
8491 \tcatch exit - any processes, just before expiration\n\
8492 \tcatch fork - calls to fork()\n\
8493 \tcatch vfork - calls to vfork()\n\
8494 \tcatch exec - calls to exec()\n\
8495 Dynamically-linked library events may be caught:\n\
8496 \tcatch load - loads of any library\n\
8497 \tcatch load <libname> - loads of a particular library\n\
8498 \tcatch unload - unloads of any library\n\
8499 \tcatch unload <libname> - unloads of a particular library\n\
8500 The act of your program's execution stopping may also be caught:\n\
8502 C++ exceptions may be caught:\n\
8503 \tcatch throw - all exceptions, when thrown\n\
8504 \tcatch catch - all exceptions, when caught\n\
8505 Ada exceptions may be caught:\n\
8506 \tcatch exception - all exceptions, when raised\n\
8507 \tcatch exception <name> - a particular exception, when raised\n\
8508 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8509 \tcatch assert - all failed assertions, when raised\n\
8511 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8512 after a fork or vfork is caught.\n\n\
8513 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8515 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8516 Set temporary catchpoints to catch events.\n\
8517 Args like \"catch\" command.\n\
8518 Like \"catch\" except the catchpoint is only temporary,\n\
8519 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8520 by using \"enable delete\" on the catchpoint number."));
8522 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8523 Set a watchpoint for an expression.\n\
8524 A watchpoint stops execution of your program whenever the value of\n\
8525 an expression changes."));
8526 set_cmd_completer (c
, location_completer
);
8528 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8529 Set a read watchpoint for an expression.\n\
8530 A watchpoint stops execution of your program whenever the value of\n\
8531 an expression is read."));
8532 set_cmd_completer (c
, location_completer
);
8534 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8535 Set a watchpoint for an expression.\n\
8536 A watchpoint stops execution of your program whenever the value of\n\
8537 an expression is either read or written."));
8538 set_cmd_completer (c
, location_completer
);
8540 add_info ("watchpoints", breakpoints_info
,
8541 _("Synonym for ``info breakpoints''."));
8544 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8545 respond to changes - contrary to the description. */
8546 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8547 &can_use_hw_watchpoints
, _("\
8548 Set debugger's willingness to use watchpoint hardware."), _("\
8549 Show debugger's willingness to use watchpoint hardware."), _("\
8550 If zero, gdb will not use hardware for new watchpoints, even if\n\
8551 such is available. (However, any hardware watchpoints that were\n\
8552 created before setting this to nonzero, will continue to use watchpoint\n\
8555 show_can_use_hw_watchpoints
,
8556 &setlist
, &showlist
);
8558 can_use_hw_watchpoints
= 1;
8560 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8561 Breakpoint specific settings\n\
8562 Configure various breakpoint-specific variables such as\n\
8563 pending breakpoint behavior"),
8564 &breakpoint_set_cmdlist
, "set breakpoint ",
8565 0/*allow-unknown*/, &setlist
);
8566 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8567 Breakpoint specific settings\n\
8568 Configure various breakpoint-specific variables such as\n\
8569 pending breakpoint behavior"),
8570 &breakpoint_show_cmdlist
, "show breakpoint ",
8571 0/*allow-unknown*/, &showlist
);
8573 add_setshow_auto_boolean_cmd ("pending", no_class
,
8574 &pending_break_support
, _("\
8575 Set debugger's behavior regarding pending breakpoints."), _("\
8576 Show debugger's behavior regarding pending breakpoints."), _("\
8577 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8578 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8579 an error. If auto, an unrecognized breakpoint location results in a\n\
8580 user-query to see if a pending breakpoint should be created."),
8582 show_pending_break_support
,
8583 &breakpoint_set_cmdlist
,
8584 &breakpoint_show_cmdlist
);
8586 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8588 add_setshow_boolean_cmd ("auto-hw", no_class
,
8589 &automatic_hardware_breakpoints
, _("\
8590 Set automatic usage of hardware breakpoints."), _("\
8591 Show automatic usage of hardware breakpoints."), _("\
8592 If set, the debugger will automatically use hardware breakpoints for\n\
8593 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8594 a warning will be emitted for such breakpoints."),
8596 show_automatic_hardware_breakpoints
,
8597 &breakpoint_set_cmdlist
,
8598 &breakpoint_show_cmdlist
);
8600 automatic_hardware_breakpoints
= 1;