1 /* Everything about breakpoints, for GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
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 2 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, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
28 #include "breakpoint.h"
30 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb_string.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
55 #include "gdb-events.h"
57 /* Prototypes for local functions. */
59 static void until_break_command_continuation (struct continuation_arg
*arg
);
61 static void catch_command_1 (char *, int, int);
63 static void enable_delete_command (char *, int);
65 static void enable_delete_breakpoint (struct breakpoint
*);
67 static void enable_once_command (char *, int);
69 static void enable_once_breakpoint (struct breakpoint
*);
71 static void disable_command (char *, int);
73 static void enable_command (char *, int);
75 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
77 static void ignore_command (char *, int);
79 static int breakpoint_re_set_one (void *);
81 static void clear_command (char *, int);
83 static void catch_command (char *, int);
85 static void watch_command (char *, int);
87 static int can_use_hardware_watchpoint (struct value
*);
89 extern void break_at_finish_command (char *, int);
90 extern void break_at_finish_at_depth_command (char *, int);
92 extern void tbreak_at_finish_command (char *, int);
94 static int break_command_1 (char *, int, int, struct breakpoint
*);
96 static void mention (struct breakpoint
*);
98 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
100 static void check_duplicates (struct breakpoint
*);
102 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
104 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
107 static void describe_other_breakpoints (CORE_ADDR
, asection
*);
109 static void breakpoints_info (char *, int);
111 static void breakpoint_1 (int, int);
113 static bpstat
bpstat_alloc (struct breakpoint
*, bpstat
);
115 static int breakpoint_cond_eval (void *);
117 static void cleanup_executing_breakpoints (void *);
119 static void commands_command (char *, int);
121 static void condition_command (char *, int);
123 static int get_number_trailer (char **, int);
125 static int do_captured_parse_breakpoint (struct ui_out
*, void *);
127 void set_breakpoint_count (int);
136 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
138 static enum print_stop_action
print_it_typical (bpstat
);
140 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
144 enum exception_event_kind kind
;
147 args_for_catchpoint_enable
;
149 static int watchpoint_check (void *);
151 static int cover_target_enable_exception_callback (void *);
153 static void maintenance_info_breakpoints (char *, int);
155 static void create_longjmp_breakpoint (char *);
157 static void create_overlay_event_breakpoint (char *);
159 static int hw_breakpoint_used_count (void);
161 static int hw_watchpoint_used_count (enum bptype
, int *);
163 static void hbreak_command (char *, int);
165 static void thbreak_command (char *, int);
167 static void watch_command_1 (char *, int, int);
169 static void rwatch_command (char *, int);
171 static void awatch_command (char *, int);
173 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
175 static void solib_load_unload_1 (char *hookname
,
178 char *cond_string
, enum bptype bp_kind
);
180 static void create_fork_vfork_event_catchpoint (int tempflag
,
182 enum bptype bp_kind
);
184 static void break_at_finish_at_depth_command_1 (char *arg
,
185 int flag
, int from_tty
);
187 static void break_at_finish_command_1 (char *arg
, int flag
, int from_tty
);
189 static void stop_command (char *arg
, int from_tty
);
191 static void stopin_command (char *arg
, int from_tty
);
193 static void stopat_command (char *arg
, int from_tty
);
195 static char *ep_find_event_name_end (char *arg
);
197 static char *ep_parse_optional_if_clause (char **arg
);
199 static char *ep_parse_optional_filename (char **arg
);
201 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
202 enum exception_event_kind ex_event
,
203 struct symtab_and_line
*sal
);
205 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
206 char *arg
, int tempflag
, int from_tty
);
208 static void tcatch_command (char *arg
, int from_tty
);
210 static void ep_skip_leading_whitespace (char **s
);
212 /* Prototypes for exported functions. */
214 /* If FALSE, gdb will not use hardware support for watchpoints, even
215 if such is available. */
216 static int can_use_hw_watchpoints
;
218 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
219 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
220 for unrecognized breakpoint locations.
221 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
222 static enum auto_boolean pending_break_support
;
224 void _initialize_breakpoint (void);
226 extern int addressprint
; /* Print machine addresses? */
228 /* Are we executing breakpoint commands? */
229 static int executing_breakpoint_commands
;
231 /* Are overlay event breakpoints enabled? */
232 static int overlay_events_enabled
;
234 /* Walk the following statement or block through all breakpoints.
235 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
238 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
240 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
241 for (B = breakpoint_chain; \
242 B ? (TMP=B->next, 1): 0; \
245 /* Similar iterators for the low-level breakpoints. */
247 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->next)
249 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
250 for (B = bp_location_chain; \
251 B ? (TMP=B->next, 1): 0; \
254 /* True if breakpoint hit counts should be displayed in breakpoint info. */
256 int show_breakpoint_hit_counts
= 1;
258 /* Chains of all breakpoints defined. */
260 struct breakpoint
*breakpoint_chain
;
262 struct bp_location
*bp_location_chain
;
264 /* Number of last breakpoint made. */
266 int breakpoint_count
;
268 /* Pointer to current exception event record */
269 static struct exception_event_record
*current_exception_event
;
271 /* Indicator of whether exception catchpoints should be nuked between
272 runs of a program. */
273 int deprecated_exception_catchpoints_are_fragile
= 0;
275 /* Indicator of when exception catchpoints set-up should be
276 reinitialized -- e.g. when program is re-run. */
277 int deprecated_exception_support_initialized
= 0;
279 /* This function returns a pointer to the string representation of the
280 pathname of the dynamically-linked library that has just been
283 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
284 or undefined results are guaranteed.
286 This string's contents are only valid immediately after the
287 inferior has stopped in the dynamic linker hook, and becomes
288 invalid as soon as the inferior is continued. Clients should make
289 a copy of this string if they wish to continue the inferior and
290 then access the string. */
292 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
293 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
296 /* This function returns a pointer to the string representation of the
297 pathname of the dynamically-linked library that has just been
300 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
301 TRUE, or undefined results are guaranteed.
303 This string's contents are only valid immediately after the
304 inferior has stopped in the dynamic linker hook, and becomes
305 invalid as soon as the inferior is continued. Clients should make
306 a copy of this string if they wish to continue the inferior and
307 then access the string. */
309 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
310 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
313 /* This function is called by the "catch load" command. It allows the
314 debugger to be notified by the dynamic linker when a specified
315 library file (or any library file, if filename is NULL) is loaded. */
317 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
318 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
319 error ("catch of library loads not yet implemented on this platform")
322 /* This function is called by the "catch unload" command. It allows
323 the debugger to be notified by the dynamic linker when a specified
324 library file (or any library file, if filename is NULL) is
327 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
328 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
329 error ("catch of library unloads not yet implemented on this platform")
332 /* Return whether a breakpoint is an active enabled breakpoint. */
334 breakpoint_enabled (struct breakpoint
*b
)
336 return (b
->enable_state
== bp_enabled
&& !b
->pending
);
339 /* Set breakpoint count to NUM. */
342 set_breakpoint_count (int num
)
344 breakpoint_count
= num
;
345 set_internalvar (lookup_internalvar ("bpnum"),
346 value_from_longest (builtin_type_int
, (LONGEST
) num
));
349 /* Used in run_command to zero the hit count when a new run starts. */
352 clear_breakpoint_hit_counts (void)
354 struct breakpoint
*b
;
360 /* Default address, symtab and line to put a breakpoint at
361 for "break" command with no arg.
362 if default_breakpoint_valid is zero, the other three are
363 not valid, and "break" with no arg is an error.
365 This set by print_stack_frame, which calls set_default_breakpoint. */
367 int default_breakpoint_valid
;
368 CORE_ADDR default_breakpoint_address
;
369 struct symtab
*default_breakpoint_symtab
;
370 int default_breakpoint_line
;
372 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
373 Advance *PP after the string and any trailing whitespace.
375 Currently the string can either be a number or "$" followed by the name
376 of a convenience variable. Making it an expression wouldn't work well
377 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
379 TRAILER is a character which can be found after the number; most
380 commonly this is `-'. If you don't want a trailer, use \0. */
382 get_number_trailer (char **pp
, int trailer
)
384 int retval
= 0; /* default */
388 /* Empty line means refer to the last breakpoint. */
389 return breakpoint_count
;
392 /* Make a copy of the name, so we can null-terminate it
393 to pass to lookup_internalvar(). */
398 while (isalnum (*p
) || *p
== '_')
400 varname
= (char *) alloca (p
- start
+ 1);
401 strncpy (varname
, start
, p
- start
);
402 varname
[p
- start
] = '\0';
403 val
= value_of_internalvar (lookup_internalvar (varname
));
404 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
405 retval
= (int) value_as_long (val
);
408 printf_filtered ("Convenience variable must have integer value.\n");
416 while (*p
>= '0' && *p
<= '9')
419 /* There is no number here. (e.g. "cond a == b"). */
421 /* Skip non-numeric token */
422 while (*p
&& !isspace((int) *p
))
424 /* Return zero, which caller must interpret as error. */
430 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
432 /* Trailing junk: return 0 and let caller print error msg. */
433 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
444 /* Like get_number_trailer, but don't allow a trailer. */
446 get_number (char **pp
)
448 return get_number_trailer (pp
, '\0');
451 /* Parse a number or a range.
452 * A number will be of the form handled by get_number.
453 * A range will be of the form <number1> - <number2>, and
454 * will represent all the integers between number1 and number2,
457 * While processing a range, this fuction is called iteratively;
458 * At each call it will return the next value in the range.
460 * At the beginning of parsing a range, the char pointer PP will
461 * be advanced past <number1> and left pointing at the '-' token.
462 * Subsequent calls will not advance the pointer until the range
463 * is completed. The call that completes the range will advance
464 * pointer PP past <number2>.
468 get_number_or_range (char **pp
)
470 static int last_retval
, end_value
;
471 static char *end_ptr
;
472 static int in_range
= 0;
476 /* Default case: pp is pointing either to a solo number,
477 or to the first number of a range. */
478 last_retval
= get_number_trailer (pp
, '-');
483 /* This is the start of a range (<number1> - <number2>).
484 Skip the '-', parse and remember the second number,
485 and also remember the end of the final token. */
489 while (isspace ((int) *end_ptr
))
490 end_ptr
++; /* skip white space */
491 end_value
= get_number (temp
);
492 if (end_value
< last_retval
)
494 error ("inverted range");
496 else if (end_value
== last_retval
)
498 /* degenerate range (number1 == number2). Advance the
499 token pointer so that the range will be treated as a
508 error ("negative value");
511 /* pp points to the '-' that betokens a range. All
512 number-parsing has already been done. Return the next
513 integer value (one greater than the saved previous value).
514 Do not advance the token pointer 'pp' until the end of range
517 if (++last_retval
== end_value
)
519 /* End of range reached; advance token pointer. */
529 /* condition N EXP -- set break condition of breakpoint N to EXP. */
532 condition_command (char *arg
, int from_tty
)
534 struct breakpoint
*b
;
539 error_no_arg ("breakpoint number");
542 bnum
= get_number (&p
);
544 error ("Bad breakpoint argument: '%s'", arg
);
547 if (b
->number
== bnum
)
554 if (b
->cond_string
!= NULL
)
555 xfree (b
->cond_string
);
560 b
->cond_string
= NULL
;
562 printf_filtered ("Breakpoint %d now unconditional.\n", bnum
);
567 /* I don't know if it matters whether this is the string the user
568 typed in or the decompiled expression. */
569 b
->cond_string
= savestring (arg
, strlen (arg
));
572 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->loc
->address
), 0);
574 error ("Junk at end of expression");
577 breakpoints_changed ();
578 breakpoint_modify_event (b
->number
);
582 error ("No breakpoint number %d.", bnum
);
586 commands_command (char *arg
, int from_tty
)
588 struct breakpoint
*b
;
591 struct command_line
*l
;
593 /* If we allowed this, we would have problems with when to
594 free the storage, if we change the commands currently
597 if (executing_breakpoint_commands
)
598 error ("Can't use the \"commands\" command among a breakpoint's commands.");
601 bnum
= get_number (&p
);
604 error ("Unexpected extra arguments following breakpoint number.");
607 if (b
->number
== bnum
)
609 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
611 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
612 l
= read_command_lines (tmpbuf
, from_tty
);
613 do_cleanups (cleanups
);
614 free_command_lines (&b
->commands
);
616 breakpoints_changed ();
617 breakpoint_modify_event (b
->number
);
620 error ("No breakpoint number %d.", bnum
);
623 /* Like target_read_memory() but if breakpoints are inserted, return
624 the shadow contents instead of the breakpoints themselves.
626 Read "memory data" from whatever target or inferior we have.
627 Returns zero if successful, errno value if not. EIO is used
628 for address out of bounds. If breakpoints are inserted, returns
629 shadow contents, not the breakpoints themselves. From breakpoint.c. */
632 deprecated_read_memory_nobpt (CORE_ADDR memaddr
, char *myaddr
, unsigned len
)
635 struct bp_location
*b
;
636 CORE_ADDR bp_addr
= 0;
639 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
640 /* No breakpoints on this machine. */
641 return target_read_memory (memaddr
, myaddr
, len
);
645 if (b
->owner
->type
== bp_none
)
646 warning ("reading through apparently deleted breakpoint #%d?",
649 if (b
->loc_type
!= bp_loc_software_breakpoint
)
653 /* Addresses and length of the part of the breakpoint that
655 /* XXXX The m68k, sh and h8300 have different local and remote
656 breakpoint values. BREAKPOINT_FROM_PC still manages to
657 correctly determine the breakpoints memory address and size
658 for these targets. */
659 bp_addr
= b
->address
;
661 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
666 if (bp_addr
+ bp_size
<= memaddr
)
667 /* The breakpoint is entirely before the chunk of memory we
670 if (bp_addr
>= memaddr
+ len
)
671 /* The breakpoint is entirely after the chunk of memory we are
674 /* Copy the breakpoint from the shadow contents, and recurse for
675 the things before and after. */
677 /* Offset within shadow_contents. */
680 if (bp_addr
< memaddr
)
682 /* Only copy the second part of the breakpoint. */
683 bp_size
-= memaddr
- bp_addr
;
684 bptoffset
= memaddr
- bp_addr
;
688 if (bp_addr
+ bp_size
> memaddr
+ len
)
690 /* Only copy the first part of the breakpoint. */
691 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
694 memcpy (myaddr
+ bp_addr
- memaddr
,
695 b
->shadow_contents
+ bptoffset
, bp_size
);
697 if (bp_addr
> memaddr
)
699 /* Copy the section of memory before the breakpoint. */
700 status
= deprecated_read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
705 if (bp_addr
+ bp_size
< memaddr
+ len
)
707 /* Copy the section of memory after the breakpoint. */
708 status
= deprecated_read_memory_nobpt (bp_addr
+ bp_size
,
709 myaddr
+ bp_addr
+ bp_size
- memaddr
,
710 memaddr
+ len
- (bp_addr
+ bp_size
));
717 /* Nothing overlaps. Just call read_memory_noerr. */
718 return target_read_memory (memaddr
, myaddr
, len
);
722 /* A wrapper function for inserting catchpoints. */
724 insert_catchpoint (struct ui_out
*uo
, void *args
)
726 struct breakpoint
*b
= (struct breakpoint
*) args
;
732 val
= target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
735 val
= target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
738 val
= target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
741 internal_error (__FILE__
, __LINE__
, "unknown breakpoint type");
746 throw_exception (RETURN_ERROR
);
751 /* Helper routine: free the value chain for a breakpoint (watchpoint). */
753 static void free_valchain (struct bp_location
*b
)
758 /* Free the saved value chain. We will construct a new one
759 the next time the watchpoint is inserted. */
760 for (v
= b
->owner
->val_chain
; v
; v
= n
)
765 b
->owner
->val_chain
= NULL
;
768 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
769 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
770 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
772 NOTE drow/2003-09-09: This routine could be broken down to an object-style
773 method for each breakpoint or catchpoint type. */
775 insert_bp_location (struct bp_location
*bpt
,
776 struct ui_file
*tmp_error_stream
,
777 int *disabled_breaks
, int *process_warning
,
778 int *hw_breakpoint_error
)
782 /* Permanent breakpoints cannot be inserted or removed. Disabled
783 breakpoints should not be inserted. */
784 if (!breakpoint_enabled (bpt
->owner
))
787 if (bpt
->inserted
|| bpt
->duplicate
)
790 if (bpt
->loc_type
== bp_loc_software_breakpoint
791 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
793 /* First check to see if we have to handle an overlay. */
794 if (overlay_debugging
== ovly_off
795 || bpt
->section
== NULL
796 || !(section_is_overlay (bpt
->section
)))
798 /* No overlay handling: just set the breakpoint. */
800 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
801 val
= target_insert_hw_breakpoint (bpt
->address
,
802 bpt
->shadow_contents
);
804 val
= target_insert_breakpoint (bpt
->address
,
805 bpt
->shadow_contents
);
809 /* This breakpoint is in an overlay section.
810 Shall we set a breakpoint at the LMA? */
811 if (!overlay_events_enabled
)
813 /* Yes -- overlay event support is not active,
814 so we must try to set a breakpoint at the LMA.
815 This will not work for a hardware breakpoint. */
816 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
817 warning ("hardware breakpoint %d not supported in overlay!\n",
821 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
823 /* Set a software (trap) breakpoint at the LMA. */
824 val
= target_insert_breakpoint (addr
, bpt
->shadow_contents
);
826 fprintf_unfiltered (tmp_error_stream
,
827 "Overlay breakpoint %d failed: in ROM?",
831 /* Shall we set a breakpoint at the VMA? */
832 if (section_is_mapped (bpt
->section
))
834 /* Yes. This overlay section is mapped into memory. */
835 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
836 val
= target_insert_hw_breakpoint (bpt
->address
,
837 bpt
->shadow_contents
);
839 val
= target_insert_breakpoint (bpt
->address
,
840 bpt
->shadow_contents
);
844 /* No. This breakpoint will not be inserted.
845 No error, but do not mark the bp as 'inserted'. */
852 /* Can't set the breakpoint. */
853 #if defined (DISABLE_UNSETTABLE_BREAK)
854 if (DISABLE_UNSETTABLE_BREAK (bpt
->address
))
856 /* See also: disable_breakpoints_in_shlibs. */
858 bpt
->owner
->enable_state
= bp_shlib_disabled
;
859 if (!*disabled_breaks
)
861 fprintf_unfiltered (tmp_error_stream
,
862 "Cannot insert breakpoint %d.\n",
864 fprintf_unfiltered (tmp_error_stream
,
865 "Temporarily disabling shared library breakpoints:\n");
867 *disabled_breaks
= 1;
868 fprintf_unfiltered (tmp_error_stream
,
869 "breakpoint #%d\n", bpt
->owner
->number
);
874 #ifdef ONE_PROCESS_WRITETEXT
875 *process_warning
= 1;
877 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
879 *hw_breakpoint_error
= 1;
880 fprintf_unfiltered (tmp_error_stream
,
881 "Cannot insert hardware breakpoint %d.\n",
886 fprintf_unfiltered (tmp_error_stream
,
887 "Cannot insert breakpoint %d.\n",
889 fprintf_filtered (tmp_error_stream
,
890 "Error accessing memory address ");
891 print_address_numeric (bpt
->address
, 1, tmp_error_stream
);
892 fprintf_filtered (tmp_error_stream
, ": %s.\n",
893 safe_strerror (val
));
904 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
905 /* NOTE drow/2003-09-08: This state only exists for removing
906 watchpoints. It's not clear that it's necessary... */
907 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
909 /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints
910 based on the expression. Ideally this should happen at a higher level,
911 and there should be one bp_location for each computed address we
912 must watch. As soon as a many-to-one mapping is available I'll
915 int within_current_scope
;
916 struct value
*mark
= value_mark ();
918 struct frame_id saved_frame_id
;
920 /* Save the current frame's ID so we can restore it after
921 evaluating the watchpoint expression on its own frame. */
922 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
923 took a frame parameter, so that we didn't have to change the
925 saved_frame_id
= get_frame_id (deprecated_selected_frame
);
927 /* Determine if the watchpoint is within scope. */
928 if (bpt
->owner
->exp_valid_block
== NULL
)
929 within_current_scope
= 1;
932 struct frame_info
*fi
;
933 fi
= frame_find_by_id (bpt
->owner
->watchpoint_frame
);
934 within_current_scope
= (fi
!= NULL
);
935 if (within_current_scope
)
939 if (within_current_scope
)
943 /* Evaluate the expression and cut the chain of values
944 produced off from the value chain.
946 Make sure the value returned isn't lazy; we use
947 laziness to determine what memory GDB actually needed
948 in order to compute the value of the expression. */
949 v
= evaluate_expression (bpt
->owner
->exp
);
951 value_release_to_mark (mark
);
953 bpt
->owner
->val_chain
= v
;
956 /* Look at each value on the value chain. */
957 for (; v
; v
= v
->next
)
959 /* If it's a memory location, and GDB actually needed
960 its contents to evaluate the expression, then we
962 if (VALUE_LVAL (v
) == lval_memory
965 struct type
*vtype
= check_typedef (value_type (v
));
967 /* We only watch structs and arrays if user asked
968 for it explicitly, never if they just happen to
969 appear in the middle of some value chain. */
970 if (v
== bpt
->owner
->val_chain
971 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
972 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
977 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
978 len
= TYPE_LENGTH (value_type (v
));
980 if (bpt
->owner
->type
== bp_read_watchpoint
)
982 else if (bpt
->owner
->type
== bp_access_watchpoint
)
985 val
= target_insert_watchpoint (addr
, len
, type
);
988 /* Don't exit the loop, try to insert
989 every value on the value chain. That's
990 because we will be removing all the
991 watches below, and removing a
992 watchpoint we didn't insert could have
1000 /* Failure to insert a watchpoint on any memory value in the
1001 value chain brings us here. */
1004 remove_breakpoint (bpt
, mark_uninserted
);
1005 *hw_breakpoint_error
= 1;
1006 fprintf_unfiltered (tmp_error_stream
,
1007 "Could not insert hardware watchpoint %d.\n",
1008 bpt
->owner
->number
);
1014 printf_filtered ("Hardware watchpoint %d deleted ", bpt
->owner
->number
);
1015 printf_filtered ("because the program has left the block \n");
1016 printf_filtered ("in which its expression is valid.\n");
1017 if (bpt
->owner
->related_breakpoint
)
1018 bpt
->owner
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1019 bpt
->owner
->disposition
= disp_del_at_next_stop
;
1022 /* Restore the selected frame. */
1023 select_frame (frame_find_by_id (saved_frame_id
));
1028 else if (ep_is_exception_catchpoint (bpt
->owner
))
1030 /* FIXME drow/2003-09-09: This code sets both a catchpoint and a
1031 breakpoint. Once again, it would be better if this was represented
1032 as two bp_locations. */
1034 /* If we get here, we must have a callback mechanism for exception
1035 events -- with g++ style embedded label support, we insert
1036 ordinary breakpoints and not catchpoints. */
1037 val
= target_insert_breakpoint (bpt
->address
, bpt
->shadow_contents
);
1040 /* Couldn't set breakpoint for some reason */
1041 fprintf_unfiltered (tmp_error_stream
,
1042 "Cannot insert catchpoint %d; disabling it.\n",
1043 bpt
->owner
->number
);
1044 fprintf_filtered (tmp_error_stream
,
1045 "Error accessing memory address ");
1046 print_address_numeric (bpt
->address
, 1, tmp_error_stream
);
1047 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1048 safe_strerror (val
));
1049 bpt
->owner
->enable_state
= bp_disabled
;
1053 /* Bp set, now make sure callbacks are enabled */
1054 /* Format possible error msg */
1055 char *message
= xstrprintf ("Error inserting catchpoint %d:\n",
1056 bpt
->owner
->number
);
1057 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
1059 args_for_catchpoint_enable args
;
1060 args
.kind
= bpt
->owner
->type
== bp_catch_catch
?
1061 EX_EVENT_CATCH
: EX_EVENT_THROW
;
1063 val
= catch_errors (cover_target_enable_exception_callback
,
1064 &args
, message
, RETURN_MASK_ALL
);
1065 do_cleanups (cleanups
);
1066 if (val
!= 0 && val
!= -1)
1069 /* Check if something went wrong; val == 0 can be ignored */
1072 /* something went wrong */
1073 fprintf_unfiltered (tmp_error_stream
,
1074 "Cannot insert catchpoint %d; disabling it.\n",
1075 bpt
->owner
->number
);
1076 bpt
->owner
->enable_state
= bp_disabled
;
1083 else if (bpt
->owner
->type
== bp_catch_fork
1084 || bpt
->owner
->type
== bp_catch_vfork
1085 || bpt
->owner
->type
== bp_catch_exec
)
1087 char *prefix
= xstrprintf ("warning: inserting catchpoint %d: ",
1088 bpt
->owner
->number
);
1089 struct cleanup
*cleanups
= make_cleanup (xfree
, prefix
);
1090 val
= catch_exceptions (uiout
, insert_catchpoint
, bpt
->owner
, prefix
,
1092 do_cleanups (cleanups
);
1094 bpt
->owner
->enable_state
= bp_disabled
;
1098 /* We've already printed an error message if there was a problem
1099 inserting this catchpoint, and we've disabled the catchpoint,
1100 so just return success. */
1107 /* insert_breakpoints is used when starting or continuing the program.
1108 remove_breakpoints is used when the program stops.
1109 Both return zero if successful,
1110 or an `errno' value if could not write the inferior. */
1113 insert_breakpoints (void)
1115 struct bp_location
*b
, *temp
;
1116 int return_val
= 0; /* return success code. */
1118 int disabled_breaks
= 0;
1119 int hw_breakpoint_error
= 0;
1120 int process_warning
= 0;
1122 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1123 make_cleanup_ui_file_delete (tmp_error_stream
);
1125 /* Explicitly mark the warning -- this will only be printed if
1126 there was an error. */
1127 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1129 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1131 /* Permanent breakpoints cannot be inserted or removed. Disabled
1132 breakpoints should not be inserted. */
1133 if (!breakpoint_enabled (b
->owner
))
1136 /* FIXME drow/2003-10-07: This code should be pushed elsewhere when
1137 hardware watchpoints are split into multiple loc breakpoints. */
1138 if ((b
->loc_type
== bp_loc_hardware_watchpoint
1139 || b
->owner
->type
== bp_watchpoint
) && !b
->owner
->val
)
1142 val
= evaluate_expression (b
->owner
->exp
);
1143 release_value (val
);
1144 if (VALUE_LAZY (val
))
1145 value_fetch_lazy (val
);
1146 b
->owner
->val
= val
;
1149 val
= insert_bp_location (b
, tmp_error_stream
,
1150 &disabled_breaks
, &process_warning
,
1151 &hw_breakpoint_error
);
1158 /* If a hardware breakpoint or watchpoint was inserted, add a
1159 message about possibly exhausted resources. */
1160 if (hw_breakpoint_error
)
1162 fprintf_unfiltered (tmp_error_stream
,
1163 "Could not insert hardware breakpoints:\n\
1164 You may have requested too many hardware breakpoints/watchpoints.\n");
1166 #ifdef ONE_PROCESS_WRITETEXT
1167 if (process_warning
)
1168 fprintf_unfiltered (tmp_error_stream
,
1169 "The same program may be running in another process.");
1171 target_terminal_ours_for_output ();
1172 error_stream (tmp_error_stream
);
1178 remove_breakpoints (void)
1180 struct bp_location
*b
;
1183 ALL_BP_LOCATIONS (b
)
1187 val
= remove_breakpoint (b
, mark_uninserted
);
1196 remove_hw_watchpoints (void)
1198 struct bp_location
*b
;
1201 ALL_BP_LOCATIONS (b
)
1203 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1205 val
= remove_breakpoint (b
, mark_uninserted
);
1214 reattach_breakpoints (int pid
)
1216 struct bp_location
*b
;
1218 struct cleanup
*old_chain
= save_inferior_ptid ();
1220 /* Set inferior_ptid; remove_breakpoint uses this global. */
1221 inferior_ptid
= pid_to_ptid (pid
);
1222 ALL_BP_LOCATIONS (b
)
1226 remove_breakpoint (b
, mark_inserted
);
1227 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1228 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
1230 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
1231 /* FIXME drow/2003-10-07: This doesn't handle any other kinds of
1232 breakpoints. It's wrong for watchpoints, for example. */
1235 do_cleanups (old_chain
);
1240 do_cleanups (old_chain
);
1245 update_breakpoints_after_exec (void)
1247 struct breakpoint
*b
;
1248 struct breakpoint
*temp
;
1250 /* Doing this first prevents the badness of having delete_breakpoint()
1251 write a breakpoint's current "shadow contents" to lift the bp. That
1252 shadow is NOT valid after an exec()! */
1253 mark_breakpoints_out ();
1255 ALL_BREAKPOINTS_SAFE (b
, temp
)
1257 /* Solib breakpoints must be explicitly reset after an exec(). */
1258 if (b
->type
== bp_shlib_event
)
1260 delete_breakpoint (b
);
1264 /* Thread event breakpoints must be set anew after an exec(),
1265 as must overlay event breakpoints. */
1266 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1268 delete_breakpoint (b
);
1272 /* Step-resume breakpoints are meaningless after an exec(). */
1273 if (b
->type
== bp_step_resume
)
1275 delete_breakpoint (b
);
1279 /* Ditto the sigtramp handler breakpoints. */
1280 if (b
->type
== bp_through_sigtramp
)
1282 delete_breakpoint (b
);
1286 /* Ditto the exception-handling catchpoints. */
1287 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1289 delete_breakpoint (b
);
1293 /* Don't delete an exec catchpoint, because else the inferior
1294 won't stop when it ought!
1296 Similarly, we probably ought to keep vfork catchpoints, 'cause
1297 on this target, we may not be able to stop when the vfork is
1298 seen, but only when the subsequent exec is seen. (And because
1299 deleting fork catchpoints here but not vfork catchpoints will
1300 seem mysterious to users, keep those too.)
1302 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1303 target address field, if any, is sufficient to have it be reset
1304 automagically. Certainly on HP-UX that's true.
1306 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1307 valid code address on some platforms (like the mn10300
1308 simulators). We shouldn't assign any special interpretation to
1309 a breakpoint with a zero address. And in fact, GDB doesn't ---
1310 I can't see what that comment above is talking about. As far
1311 as I can tell, setting the address of a
1312 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1313 is meaningless, since those are implemented with HP-UX kernel
1314 hackery, not by storing breakpoint instructions somewhere. */
1315 if ((b
->type
== bp_catch_exec
) ||
1316 (b
->type
== bp_catch_vfork
) ||
1317 (b
->type
== bp_catch_fork
))
1319 b
->loc
->address
= (CORE_ADDR
) NULL
;
1323 /* bp_finish is a special case. The only way we ought to be able
1324 to see one of these when an exec() has happened, is if the user
1325 caught a vfork, and then said "finish". Ordinarily a finish just
1326 carries them to the call-site of the current callee, by setting
1327 a temporary bp there and resuming. But in this case, the finish
1328 will carry them entirely through the vfork & exec.
1330 We don't want to allow a bp_finish to remain inserted now. But
1331 we can't safely delete it, 'cause finish_command has a handle to
1332 the bp on a bpstat, and will later want to delete it. There's a
1333 chance (and I've seen it happen) that if we delete the bp_finish
1334 here, that its storage will get reused by the time finish_command
1335 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1336 We really must allow finish_command to delete a bp_finish.
1338 In the absense of a general solution for the "how do we know
1339 it's safe to delete something others may have handles to?"
1340 problem, what we'll do here is just uninsert the bp_finish, and
1341 let finish_command delete it.
1343 (We know the bp_finish is "doomed" in the sense that it's
1344 momentary, and will be deleted as soon as finish_command sees
1345 the inferior stopped. So it doesn't matter that the bp's
1346 address is probably bogus in the new a.out, unlike e.g., the
1347 solib breakpoints.) */
1349 if (b
->type
== bp_finish
)
1354 /* Without a symbolic address, we have little hope of the
1355 pre-exec() address meaning the same thing in the post-exec()
1357 if (b
->addr_string
== NULL
)
1359 delete_breakpoint (b
);
1363 /* If this breakpoint has survived the above battery of checks, then
1364 it must have a symbolic address. Be sure that it gets reevaluated
1365 to a target address, rather than reusing the old evaluation.
1367 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1368 for bp_catch_exec and friends, I'm pretty sure this is entirely
1369 unnecessary. A call to breakpoint_re_set_one always recomputes
1370 the breakpoint's address from scratch, or deletes it if it can't.
1371 So I think this assignment could be deleted without effect. */
1372 b
->loc
->address
= (CORE_ADDR
) NULL
;
1374 /* FIXME what about longjmp breakpoints? Re-create them here? */
1375 create_overlay_event_breakpoint ("_ovly_debug_event");
1379 detach_breakpoints (int pid
)
1381 struct bp_location
*b
;
1383 struct cleanup
*old_chain
= save_inferior_ptid ();
1385 if (pid
== PIDGET (inferior_ptid
))
1386 error ("Cannot detach breakpoints of inferior_ptid");
1388 /* Set inferior_ptid; remove_breakpoint uses this global. */
1389 inferior_ptid
= pid_to_ptid (pid
);
1390 ALL_BP_LOCATIONS (b
)
1394 val
= remove_breakpoint (b
, mark_inserted
);
1397 do_cleanups (old_chain
);
1402 do_cleanups (old_chain
);
1407 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1411 if (b
->owner
->enable_state
== bp_permanent
)
1412 /* Permanent breakpoints cannot be inserted or removed. */
1415 if (b
->owner
->type
== bp_none
)
1416 warning ("attempted to remove apparently deleted breakpoint #%d?",
1419 if (b
->loc_type
== bp_loc_software_breakpoint
1420 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1422 /* "Normal" instruction breakpoint: either the standard
1423 trap-instruction bp (bp_breakpoint), or a
1424 bp_hardware_breakpoint. */
1426 /* First check to see if we have to handle an overlay. */
1427 if (overlay_debugging
== ovly_off
1428 || b
->section
== NULL
1429 || !(section_is_overlay (b
->section
)))
1431 /* No overlay handling: just remove the breakpoint. */
1433 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1434 val
= target_remove_hw_breakpoint (b
->address
,
1435 b
->shadow_contents
);
1437 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1441 /* This breakpoint is in an overlay section.
1442 Did we set a breakpoint at the LMA? */
1443 if (!overlay_events_enabled
)
1445 /* Yes -- overlay event support is not active, so we
1446 should have set a breakpoint at the LMA. Remove it.
1448 CORE_ADDR addr
= overlay_unmapped_address (b
->address
,
1450 /* Ignore any failures: if the LMA is in ROM, we will
1451 have already warned when we failed to insert it. */
1452 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1453 target_remove_hw_breakpoint (addr
, b
->shadow_contents
);
1455 target_remove_breakpoint (addr
, b
->shadow_contents
);
1457 /* Did we set a breakpoint at the VMA?
1458 If so, we will have marked the breakpoint 'inserted'. */
1461 /* Yes -- remove it. Previously we did not bother to
1462 remove the breakpoint if the section had been
1463 unmapped, but let's not rely on that being safe. We
1464 don't know what the overlay manager might do. */
1465 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1466 val
= target_remove_hw_breakpoint (b
->address
,
1467 b
->shadow_contents
);
1469 val
= target_remove_breakpoint (b
->address
,
1470 b
->shadow_contents
);
1474 /* No -- not inserted, so no need to remove. No error. */
1480 b
->inserted
= (is
== mark_inserted
);
1482 else if (b
->loc_type
== bp_loc_hardware_watchpoint
1483 && breakpoint_enabled (b
->owner
)
1489 b
->inserted
= (is
== mark_inserted
);
1490 /* Walk down the saved value chain. */
1491 for (v
= b
->owner
->val_chain
; v
; v
= v
->next
)
1493 /* For each memory reference remove the watchpoint
1495 if (VALUE_LVAL (v
) == lval_memory
1496 && ! VALUE_LAZY (v
))
1498 struct type
*vtype
= check_typedef (value_type (v
));
1500 if (v
== b
->owner
->val_chain
1501 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1502 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1507 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
1508 len
= TYPE_LENGTH (value_type (v
));
1510 if (b
->owner
->type
== bp_read_watchpoint
)
1512 else if (b
->owner
->type
== bp_access_watchpoint
)
1515 val
= target_remove_watchpoint (addr
, len
, type
);
1522 /* Failure to remove any of the hardware watchpoints comes here. */
1523 if ((is
== mark_uninserted
) && (b
->inserted
))
1524 warning ("Could not remove hardware watchpoint %d.",
1527 else if ((b
->owner
->type
== bp_catch_fork
||
1528 b
->owner
->type
== bp_catch_vfork
||
1529 b
->owner
->type
== bp_catch_exec
)
1530 && breakpoint_enabled (b
->owner
)
1534 switch (b
->owner
->type
)
1537 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1539 case bp_catch_vfork
:
1540 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1543 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1546 warning ("Internal error, %s line %d.", __FILE__
, __LINE__
);
1551 b
->inserted
= (is
== mark_inserted
);
1553 else if ((b
->owner
->type
== bp_catch_catch
||
1554 b
->owner
->type
== bp_catch_throw
)
1555 && breakpoint_enabled (b
->owner
)
1559 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1562 b
->inserted
= (is
== mark_inserted
);
1564 else if (ep_is_exception_catchpoint (b
->owner
)
1565 && b
->inserted
/* sometimes previous insert doesn't happen */
1566 && breakpoint_enabled (b
->owner
)
1570 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1574 b
->inserted
= (is
== mark_inserted
);
1580 /* Clear the "inserted" flag in all breakpoints. */
1583 mark_breakpoints_out (void)
1585 struct bp_location
*bpt
;
1587 ALL_BP_LOCATIONS (bpt
)
1591 /* Clear the "inserted" flag in all breakpoints and delete any
1592 breakpoints which should go away between runs of the program.
1594 Plus other such housekeeping that has to be done for breakpoints
1597 Note: this function gets called at the end of a run (by
1598 generic_mourn_inferior) and when a run begins (by
1599 init_wait_for_inferior). */
1604 breakpoint_init_inferior (enum inf_context context
)
1606 struct breakpoint
*b
, *temp
;
1607 struct bp_location
*bpt
;
1608 static int warning_needed
= 0;
1610 ALL_BP_LOCATIONS (bpt
)
1613 ALL_BREAKPOINTS_SAFE (b
, temp
)
1618 case bp_watchpoint_scope
:
1620 /* If the call dummy breakpoint is at the entry point it will
1621 cause problems when the inferior is rerun, so we better
1624 Also get rid of scope breakpoints. */
1625 delete_breakpoint (b
);
1629 case bp_hardware_watchpoint
:
1630 case bp_read_watchpoint
:
1631 case bp_access_watchpoint
:
1633 /* Likewise for watchpoints on local expressions. */
1634 if (b
->exp_valid_block
!= NULL
)
1635 delete_breakpoint (b
);
1636 if (context
== inf_starting
)
1638 /* Reset val field to force reread of starting value
1639 in insert_breakpoints. */
1641 value_free (b
->val
);
1646 /* Likewise for exception catchpoints in dynamic-linked
1647 executables where required */
1648 if (ep_is_exception_catchpoint (b
)
1649 && deprecated_exception_catchpoints_are_fragile
)
1652 delete_breakpoint (b
);
1658 if (deprecated_exception_catchpoints_are_fragile
)
1659 deprecated_exception_support_initialized
= 0;
1661 /* Don't issue the warning unless it's really needed... */
1662 if (warning_needed
&& (context
!= inf_exited
))
1664 warning ("Exception catchpoints from last run were deleted.");
1665 warning ("You must reinsert them explicitly.");
1670 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1671 exists at PC. It returns ordinary_breakpoint_here if it's an
1672 ordinary breakpoint, or permanent_breakpoint_here if it's a
1673 permanent breakpoint.
1674 - When continuing from a location with an ordinary breakpoint, we
1675 actually single step once before calling insert_breakpoints.
1676 - When continuing from a localion with a permanent breakpoint, we
1677 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1678 the target, to advance the PC past the breakpoint. */
1680 enum breakpoint_here
1681 breakpoint_here_p (CORE_ADDR pc
)
1683 struct bp_location
*bpt
;
1684 int any_breakpoint_here
= 0;
1686 ALL_BP_LOCATIONS (bpt
)
1688 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1689 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1692 if ((breakpoint_enabled (bpt
->owner
)
1693 || bpt
->owner
->enable_state
== bp_permanent
)
1694 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1696 if (overlay_debugging
1697 && section_is_overlay (bpt
->section
)
1698 && !section_is_mapped (bpt
->section
))
1699 continue; /* unmapped overlay -- can't be a match */
1700 else if (bpt
->owner
->enable_state
== bp_permanent
)
1701 return permanent_breakpoint_here
;
1703 any_breakpoint_here
= 1;
1707 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1711 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1712 but it only returns true if there is actually a breakpoint inserted
1716 breakpoint_inserted_here_p (CORE_ADDR pc
)
1718 struct bp_location
*bpt
;
1720 ALL_BP_LOCATIONS (bpt
)
1722 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1723 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1727 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1729 if (overlay_debugging
1730 && section_is_overlay (bpt
->section
)
1731 && !section_is_mapped (bpt
->section
))
1732 continue; /* unmapped overlay -- can't be a match */
1741 /* This function returns non-zero iff there is a software breakpoint
1745 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1747 struct bp_location
*bpt
;
1748 int any_breakpoint_here
= 0;
1750 ALL_BP_LOCATIONS (bpt
)
1752 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1755 if ((breakpoint_enabled (bpt
->owner
)
1756 || bpt
->owner
->enable_state
== bp_permanent
)
1758 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1760 if (overlay_debugging
1761 && section_is_overlay (bpt
->section
)
1762 && !section_is_mapped (bpt
->section
))
1763 continue; /* unmapped overlay -- can't be a match */
1772 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1773 PC is valid for process/thread PTID. */
1776 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1778 struct bp_location
*bpt
;
1781 thread
= pid_to_thread_id (ptid
);
1783 ALL_BP_LOCATIONS (bpt
)
1785 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1786 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1789 if ((breakpoint_enabled (bpt
->owner
)
1790 || bpt
->owner
->enable_state
== bp_permanent
)
1791 && bpt
->address
== pc
1792 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1794 if (overlay_debugging
1795 && section_is_overlay (bpt
->section
)
1796 && !section_is_mapped (bpt
->section
))
1797 continue; /* unmapped overlay -- can't be a match */
1807 /* bpstat stuff. External routines' interfaces are documented
1811 ep_is_catchpoint (struct breakpoint
*ep
)
1814 (ep
->type
== bp_catch_load
)
1815 || (ep
->type
== bp_catch_unload
)
1816 || (ep
->type
== bp_catch_fork
)
1817 || (ep
->type
== bp_catch_vfork
)
1818 || (ep
->type
== bp_catch_exec
)
1819 || (ep
->type
== bp_catch_catch
)
1820 || (ep
->type
== bp_catch_throw
);
1822 /* ??rehrauer: Add more kinds here, as are implemented... */
1826 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1829 (ep
->type
== bp_catch_load
)
1830 || (ep
->type
== bp_catch_unload
);
1834 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1837 (ep
->type
== bp_catch_catch
)
1838 || (ep
->type
== bp_catch_throw
);
1841 /* Clear a bpstat so that it says we are not at any breakpoint.
1842 Also free any storage that is part of a bpstat. */
1845 bpstat_clear (bpstat
*bsp
)
1856 if (p
->old_val
!= NULL
)
1857 value_free (p
->old_val
);
1858 free_command_lines (&p
->commands
);
1865 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1866 is part of the bpstat is copied as well. */
1869 bpstat_copy (bpstat bs
)
1873 bpstat retval
= NULL
;
1878 for (; bs
!= NULL
; bs
= bs
->next
)
1880 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1881 memcpy (tmp
, bs
, sizeof (*tmp
));
1882 if (bs
->commands
!= NULL
)
1883 tmp
->commands
= copy_command_lines (bs
->commands
);
1884 if (bs
->old_val
!= NULL
)
1885 tmp
->old_val
= value_copy (bs
->old_val
);
1888 /* This is the first thing in the chain. */
1898 /* Find the bpstat associated with this breakpoint */
1901 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1906 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1908 if (bsp
->breakpoint_at
== breakpoint
)
1914 /* Find a step_resume breakpoint associated with this bpstat.
1915 (If there are multiple step_resume bp's on the list, this function
1916 will arbitrarily pick one.)
1918 It is an error to use this function if BPSTAT doesn't contain a
1919 step_resume breakpoint.
1921 See wait_for_inferior's use of this function. */
1923 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1928 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1930 current_thread
= pid_to_thread_id (inferior_ptid
);
1932 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1934 if ((bsp
->breakpoint_at
!= NULL
) &&
1935 (bsp
->breakpoint_at
->type
== bp_step_resume
) &&
1936 (bsp
->breakpoint_at
->thread
== current_thread
||
1937 bsp
->breakpoint_at
->thread
== -1))
1938 return bsp
->breakpoint_at
;
1941 error ("Internal error (no step_resume breakpoint found)");
1945 /* Return the breakpoint number of the first breakpoint we are stopped
1946 at. *BSP upon return is a bpstat which points to the remaining
1947 breakpoints stopped at (but which is not guaranteed to be good for
1948 anything but further calls to bpstat_num).
1949 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1952 bpstat_num (bpstat
*bsp
)
1954 struct breakpoint
*b
;
1957 return 0; /* No more breakpoint values */
1960 b
= (*bsp
)->breakpoint_at
;
1961 *bsp
= (*bsp
)->next
;
1963 return -1; /* breakpoint that's been deleted since */
1965 return b
->number
; /* We have its number */
1969 /* Modify BS so that the actions will not be performed. */
1972 bpstat_clear_actions (bpstat bs
)
1974 for (; bs
!= NULL
; bs
= bs
->next
)
1976 free_command_lines (&bs
->commands
);
1977 if (bs
->old_val
!= NULL
)
1979 value_free (bs
->old_val
);
1985 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1987 cleanup_executing_breakpoints (void *ignore
)
1989 executing_breakpoint_commands
= 0;
1992 /* Execute all the commands associated with all the breakpoints at this
1993 location. Any of these commands could cause the process to proceed
1994 beyond this point, etc. We look out for such changes by checking
1995 the global "breakpoint_proceeded" after each command. */
1998 bpstat_do_actions (bpstat
*bsp
)
2001 struct cleanup
*old_chain
;
2003 /* Avoid endless recursion if a `source' command is contained
2005 if (executing_breakpoint_commands
)
2008 executing_breakpoint_commands
= 1;
2009 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2012 /* Note that (as of this writing), our callers all appear to
2013 be passing us the address of global stop_bpstat. And, if
2014 our calls to execute_control_command cause the inferior to
2015 proceed, that global (and hence, *bsp) will change.
2017 We must be careful to not touch *bsp unless the inferior
2018 has not proceeded. */
2020 /* This pointer will iterate over the list of bpstat's. */
2023 breakpoint_proceeded
= 0;
2024 for (; bs
!= NULL
; bs
= bs
->next
)
2026 struct command_line
*cmd
;
2027 struct cleanup
*this_cmd_tree_chain
;
2029 /* Take ownership of the BSP's command tree, if it has one.
2031 The command tree could legitimately contain commands like
2032 'step' and 'next', which call clear_proceed_status, which
2033 frees stop_bpstat's command tree. To make sure this doesn't
2034 free the tree we're executing out from under us, we need to
2035 take ownership of the tree ourselves. Since a given bpstat's
2036 commands are only executed once, we don't need to copy it; we
2037 can clear the pointer in the bpstat, and make sure we free
2038 the tree when we're done. */
2041 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2045 execute_control_command (cmd
);
2047 if (breakpoint_proceeded
)
2053 /* We can free this command tree now. */
2054 do_cleanups (this_cmd_tree_chain
);
2056 if (breakpoint_proceeded
)
2057 /* The inferior is proceeded by the command; bomb out now.
2058 The bpstat chain has been blown away by wait_for_inferior.
2059 But since execution has stopped again, there is a new bpstat
2060 to look at, so start over. */
2063 do_cleanups (old_chain
);
2066 /* This is the normal print function for a bpstat. In the future,
2067 much of this logic could (should?) be moved to bpstat_stop_status,
2068 by having it set different print_it values.
2070 Current scheme: When we stop, bpstat_print() is called. It loops
2071 through the bpstat list of things causing this stop, calling the
2072 print_bp_stop_message function on each one. The behavior of the
2073 print_bp_stop_message function depends on the print_it field of
2074 bpstat. If such field so indicates, call this function here.
2076 Return values from this routine (ultimately used by bpstat_print()
2077 and normal_stop() to decide what to do):
2078 PRINT_NOTHING: Means we already printed all we needed to print,
2079 don't print anything else.
2080 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2081 that something to be followed by a location.
2082 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2083 that something to be followed by a location.
2084 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2087 static enum print_stop_action
2088 print_it_typical (bpstat bs
)
2090 struct cleanup
*old_chain
, *ui_out_chain
;
2091 struct ui_stream
*stb
;
2092 stb
= ui_out_stream_new (uiout
);
2093 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2094 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2095 which has since been deleted. */
2096 if (bs
->breakpoint_at
== NULL
)
2097 return PRINT_UNKNOWN
;
2099 switch (bs
->breakpoint_at
->type
)
2102 case bp_hardware_breakpoint
:
2103 if (bs
->breakpoint_at
->loc
->address
!= bs
->breakpoint_at
->loc
->requested_address
)
2104 breakpoint_adjustment_warning (bs
->breakpoint_at
->loc
->requested_address
,
2105 bs
->breakpoint_at
->loc
->address
,
2106 bs
->breakpoint_at
->number
, 1);
2107 annotate_breakpoint (bs
->breakpoint_at
->number
);
2108 ui_out_text (uiout
, "\nBreakpoint ");
2109 if (ui_out_is_mi_like_p (uiout
))
2110 ui_out_field_string (uiout
, "reason", "breakpoint-hit");
2111 ui_out_field_int (uiout
, "bkptno", bs
->breakpoint_at
->number
);
2112 ui_out_text (uiout
, ", ");
2113 return PRINT_SRC_AND_LOC
;
2116 case bp_shlib_event
:
2117 /* Did we stop because the user set the stop_on_solib_events
2118 variable? (If so, we report this as a generic, "Stopped due
2119 to shlib event" message.) */
2120 printf_filtered ("Stopped due to shared library event\n");
2121 return PRINT_NOTHING
;
2124 case bp_thread_event
:
2125 /* Not sure how we will get here.
2126 GDB should not stop for these breakpoints. */
2127 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
2128 return PRINT_NOTHING
;
2131 case bp_overlay_event
:
2132 /* By analogy with the thread event, GDB should not stop for these. */
2133 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
2134 return PRINT_NOTHING
;
2138 annotate_catchpoint (bs
->breakpoint_at
->number
);
2139 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2140 printf_filtered ("loaded");
2141 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
2142 return PRINT_SRC_AND_LOC
;
2145 case bp_catch_unload
:
2146 annotate_catchpoint (bs
->breakpoint_at
->number
);
2147 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2148 printf_filtered ("unloaded");
2149 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
2150 return PRINT_SRC_AND_LOC
;
2154 annotate_catchpoint (bs
->breakpoint_at
->number
);
2155 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2156 printf_filtered ("forked");
2157 printf_filtered (" process %d), ",
2158 bs
->breakpoint_at
->forked_inferior_pid
);
2159 return PRINT_SRC_AND_LOC
;
2162 case bp_catch_vfork
:
2163 annotate_catchpoint (bs
->breakpoint_at
->number
);
2164 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2165 printf_filtered ("vforked");
2166 printf_filtered (" process %d), ",
2167 bs
->breakpoint_at
->forked_inferior_pid
);
2168 return PRINT_SRC_AND_LOC
;
2172 annotate_catchpoint (bs
->breakpoint_at
->number
);
2173 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2174 bs
->breakpoint_at
->number
,
2175 bs
->breakpoint_at
->exec_pathname
);
2176 return PRINT_SRC_AND_LOC
;
2179 case bp_catch_catch
:
2180 if (current_exception_event
&&
2181 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2183 annotate_catchpoint (bs
->breakpoint_at
->number
);
2184 printf_filtered ("\nCatchpoint %d (exception caught), ",
2185 bs
->breakpoint_at
->number
);
2186 printf_filtered ("throw location ");
2187 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2188 printf_filtered ("%s:%d",
2189 CURRENT_EXCEPTION_THROW_FILE
,
2190 CURRENT_EXCEPTION_THROW_LINE
);
2192 printf_filtered ("unknown");
2194 printf_filtered (", catch location ");
2195 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2196 printf_filtered ("%s:%d",
2197 CURRENT_EXCEPTION_CATCH_FILE
,
2198 CURRENT_EXCEPTION_CATCH_LINE
);
2200 printf_filtered ("unknown");
2202 printf_filtered ("\n");
2203 /* don't bother to print location frame info */
2204 return PRINT_SRC_ONLY
;
2208 /* really throw, some other bpstat will handle it */
2209 return PRINT_UNKNOWN
;
2213 case bp_catch_throw
:
2214 if (current_exception_event
&&
2215 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2217 annotate_catchpoint (bs
->breakpoint_at
->number
);
2218 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2219 bs
->breakpoint_at
->number
);
2220 printf_filtered ("throw location ");
2221 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2222 printf_filtered ("%s:%d",
2223 CURRENT_EXCEPTION_THROW_FILE
,
2224 CURRENT_EXCEPTION_THROW_LINE
);
2226 printf_filtered ("unknown");
2228 printf_filtered (", catch location ");
2229 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2230 printf_filtered ("%s:%d",
2231 CURRENT_EXCEPTION_CATCH_FILE
,
2232 CURRENT_EXCEPTION_CATCH_LINE
);
2234 printf_filtered ("unknown");
2236 printf_filtered ("\n");
2237 /* don't bother to print location frame info */
2238 return PRINT_SRC_ONLY
;
2242 /* really catch, some other bpstat will handle it */
2243 return PRINT_UNKNOWN
;
2248 case bp_hardware_watchpoint
:
2249 if (bs
->old_val
!= NULL
)
2251 annotate_watchpoint (bs
->breakpoint_at
->number
);
2252 if (ui_out_is_mi_like_p (uiout
))
2253 ui_out_field_string (uiout
, "reason", "watchpoint-trigger");
2254 mention (bs
->breakpoint_at
);
2255 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2256 ui_out_text (uiout
, "\nOld value = ");
2257 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2258 ui_out_field_stream (uiout
, "old", stb
);
2259 ui_out_text (uiout
, "\nNew value = ");
2260 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2261 ui_out_field_stream (uiout
, "new", stb
);
2262 do_cleanups (ui_out_chain
);
2263 ui_out_text (uiout
, "\n");
2264 value_free (bs
->old_val
);
2267 /* More than one watchpoint may have been triggered. */
2268 return PRINT_UNKNOWN
;
2271 case bp_read_watchpoint
:
2272 if (ui_out_is_mi_like_p (uiout
))
2273 ui_out_field_string (uiout
, "reason", "read-watchpoint-trigger");
2274 mention (bs
->breakpoint_at
);
2275 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2276 ui_out_text (uiout
, "\nValue = ");
2277 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2278 ui_out_field_stream (uiout
, "value", stb
);
2279 do_cleanups (ui_out_chain
);
2280 ui_out_text (uiout
, "\n");
2281 return PRINT_UNKNOWN
;
2284 case bp_access_watchpoint
:
2285 if (bs
->old_val
!= NULL
)
2287 annotate_watchpoint (bs
->breakpoint_at
->number
);
2288 if (ui_out_is_mi_like_p (uiout
))
2289 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2290 mention (bs
->breakpoint_at
);
2291 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2292 ui_out_text (uiout
, "\nOld value = ");
2293 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2294 ui_out_field_stream (uiout
, "old", stb
);
2295 value_free (bs
->old_val
);
2297 ui_out_text (uiout
, "\nNew value = ");
2301 mention (bs
->breakpoint_at
);
2302 if (ui_out_is_mi_like_p (uiout
))
2303 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2304 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2305 ui_out_text (uiout
, "\nValue = ");
2307 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0,Val_pretty_default
);
2308 ui_out_field_stream (uiout
, "new", stb
);
2309 do_cleanups (ui_out_chain
);
2310 ui_out_text (uiout
, "\n");
2311 return PRINT_UNKNOWN
;
2314 /* Fall through, we don't deal with these types of breakpoints
2318 if (ui_out_is_mi_like_p (uiout
))
2319 ui_out_field_string (uiout
, "reason", "function-finished");
2320 return PRINT_UNKNOWN
;
2324 if (ui_out_is_mi_like_p (uiout
))
2325 ui_out_field_string (uiout
, "reason", "location-reached");
2326 return PRINT_UNKNOWN
;
2331 case bp_longjmp_resume
:
2332 case bp_step_resume
:
2333 case bp_through_sigtramp
:
2334 case bp_watchpoint_scope
:
2337 return PRINT_UNKNOWN
;
2341 /* Generic routine for printing messages indicating why we
2342 stopped. The behavior of this function depends on the value
2343 'print_it' in the bpstat structure. Under some circumstances we
2344 may decide not to print anything here and delegate the task to
2347 static enum print_stop_action
2348 print_bp_stop_message (bpstat bs
)
2350 switch (bs
->print_it
)
2353 /* Nothing should be printed for this bpstat entry. */
2354 return PRINT_UNKNOWN
;
2358 /* We still want to print the frame, but we already printed the
2359 relevant messages. */
2360 return PRINT_SRC_AND_LOC
;
2363 case print_it_normal
:
2364 /* Normal case. Call the breakpoint's print_it method, or
2365 print_it_typical. */
2366 if (bs
->breakpoint_at
!= NULL
&& bs
->breakpoint_at
->ops
!= NULL
2367 && bs
->breakpoint_at
->ops
->print_it
!= NULL
)
2368 return bs
->breakpoint_at
->ops
->print_it (bs
->breakpoint_at
);
2370 return print_it_typical (bs
);
2374 internal_error (__FILE__
, __LINE__
,
2375 "print_bp_stop_message: unrecognized enum value");
2380 /* Print a message indicating what happened. This is called from
2381 normal_stop(). The input to this routine is the head of the bpstat
2382 list - a list of the eventpoints that caused this stop. This
2383 routine calls the generic print routine for printing a message
2384 about reasons for stopping. This will print (for example) the
2385 "Breakpoint n," part of the output. The return value of this
2388 PRINT_UNKNOWN: Means we printed nothing
2389 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2390 code to print the location. An example is
2391 "Breakpoint 1, " which should be followed by
2393 PRINT_SRC_ONLY: Means we printed something, but there is no need
2394 to also print the location part of the message.
2395 An example is the catch/throw messages, which
2396 don't require a location appended to the end.
2397 PRINT_NOTHING: We have done some printing and we don't need any
2398 further info to be printed.*/
2400 enum print_stop_action
2401 bpstat_print (bpstat bs
)
2405 /* Maybe another breakpoint in the chain caused us to stop.
2406 (Currently all watchpoints go on the bpstat whether hit or not.
2407 That probably could (should) be changed, provided care is taken
2408 with respect to bpstat_explains_signal). */
2409 for (; bs
; bs
= bs
->next
)
2411 val
= print_bp_stop_message (bs
);
2412 if (val
== PRINT_SRC_ONLY
2413 || val
== PRINT_SRC_AND_LOC
2414 || val
== PRINT_NOTHING
)
2418 /* We reached the end of the chain, or we got a null BS to start
2419 with and nothing was printed. */
2420 return PRINT_UNKNOWN
;
2423 /* Evaluate the expression EXP and return 1 if value is zero.
2424 This is used inside a catch_errors to evaluate the breakpoint condition.
2425 The argument is a "struct expression *" that has been cast to char * to
2426 make it pass through catch_errors. */
2429 breakpoint_cond_eval (void *exp
)
2431 struct value
*mark
= value_mark ();
2432 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2433 value_free_to_mark (mark
);
2437 /* Allocate a new bpstat and chain it to the current one. */
2440 bpstat_alloc (struct breakpoint
*b
, bpstat cbs
/* Current "bs" value */ )
2444 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2446 bs
->breakpoint_at
= b
;
2447 /* If the condition is false, etc., don't do the commands. */
2448 bs
->commands
= NULL
;
2450 bs
->print_it
= print_it_normal
;
2454 /* Possible return values for watchpoint_check (this can't be an enum
2455 because of check_errors). */
2456 /* The watchpoint has been deleted. */
2457 #define WP_DELETED 1
2458 /* The value has changed. */
2459 #define WP_VALUE_CHANGED 2
2460 /* The value has not changed. */
2461 #define WP_VALUE_NOT_CHANGED 3
2463 #define BP_TEMPFLAG 1
2464 #define BP_HARDWAREFLAG 2
2466 /* Check watchpoint condition. */
2469 watchpoint_check (void *p
)
2471 bpstat bs
= (bpstat
) p
;
2472 struct breakpoint
*b
;
2473 struct frame_info
*fr
;
2474 int within_current_scope
;
2476 b
= bs
->breakpoint_at
;
2478 if (b
->exp_valid_block
== NULL
)
2479 within_current_scope
= 1;
2482 /* There is no current frame at this moment. If we're going to have
2483 any chance of handling watchpoints on local variables, we'll need
2484 the frame chain (so we can determine if we're in scope). */
2485 reinit_frame_cache ();
2486 fr
= frame_find_by_id (b
->watchpoint_frame
);
2487 within_current_scope
= (fr
!= NULL
);
2488 /* in_function_epilogue_p() returns a non-zero value if we're still
2489 in the function but the stack frame has already been invalidated.
2490 Since we can't rely on the values of local variables after the
2491 stack has been destroyed, we are treating the watchpoint in that
2492 state as `not changed' without further checking.
2494 vinschen/2003-09-04: The former implementation left out the case
2495 that the watchpoint frame couldn't be found by frame_find_by_id()
2496 because the current PC is currently in an epilogue. Calling
2497 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2498 if ((!within_current_scope
|| fr
== get_current_frame ())
2499 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2500 return WP_VALUE_NOT_CHANGED
;
2501 if (fr
&& within_current_scope
)
2502 /* If we end up stopping, the current frame will get selected
2503 in normal_stop. So this call to select_frame won't affect
2508 if (within_current_scope
)
2510 /* We use value_{,free_to_}mark because it could be a
2511 *long* time before we return to the command level and
2512 call free_all_values. We can't call free_all_values because
2513 we might be in the middle of evaluating a function call. */
2515 struct value
*mark
= value_mark ();
2516 struct value
*new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
2517 if (!value_equal (b
->val
, new_val
))
2519 release_value (new_val
);
2520 value_free_to_mark (mark
);
2521 bs
->old_val
= b
->val
;
2523 /* We will stop here */
2524 return WP_VALUE_CHANGED
;
2528 /* Nothing changed, don't do anything. */
2529 value_free_to_mark (mark
);
2530 /* We won't stop here */
2531 return WP_VALUE_NOT_CHANGED
;
2536 /* This seems like the only logical thing to do because
2537 if we temporarily ignored the watchpoint, then when
2538 we reenter the block in which it is valid it contains
2539 garbage (in the case of a function, it may have two
2540 garbage values, one before and one after the prologue).
2541 So we can't even detect the first assignment to it and
2542 watch after that (since the garbage may or may not equal
2543 the first value assigned). */
2544 /* We print all the stop information in print_it_typical(), but
2545 in this case, by the time we call print_it_typical() this bp
2546 will be deleted already. So we have no choice but print the
2547 information here. */
2548 if (ui_out_is_mi_like_p (uiout
))
2549 ui_out_field_string (uiout
, "reason", "watchpoint-scope");
2550 ui_out_text (uiout
, "\nWatchpoint ");
2551 ui_out_field_int (uiout
, "wpnum", bs
->breakpoint_at
->number
);
2552 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2553 which its expression is valid.\n");
2555 if (b
->related_breakpoint
)
2556 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2557 b
->disposition
= disp_del_at_next_stop
;
2563 /* Get a bpstat associated with having just stopped at address
2564 BP_ADDR in thread PTID. STOPPED_BY_WATCHPOINT is 1 if the
2565 target thinks we stopped due to a hardware watchpoint, 0 if we
2566 know we did not trigger a hardware watchpoint, and -1 if we do not know. */
2568 /* Determine whether we stopped at a breakpoint, etc, or whether we
2569 don't understand this stop. Result is a chain of bpstat's such that:
2571 if we don't understand the stop, the result is a null pointer.
2573 if we understand why we stopped, the result is not null.
2575 Each element of the chain refers to a particular breakpoint or
2576 watchpoint at which we have stopped. (We may have stopped for
2577 several reasons concurrently.)
2579 Each element of the chain has valid next, breakpoint_at,
2580 commands, FIXME??? fields. */
2583 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
, int stopped_by_watchpoint
)
2585 struct breakpoint
*b
, *temp
;
2586 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2587 int real_breakpoint
= 0;
2588 /* Root of the chain of bpstat's */
2589 struct bpstats root_bs
[1];
2590 /* Pointer to the last thing in the chain currently. */
2591 bpstat bs
= root_bs
;
2592 int thread_id
= pid_to_thread_id (ptid
);
2594 ALL_BREAKPOINTS_SAFE (b
, temp
)
2596 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2599 if (b
->type
!= bp_watchpoint
2600 && b
->type
!= bp_hardware_watchpoint
2601 && b
->type
!= bp_read_watchpoint
2602 && b
->type
!= bp_access_watchpoint
2603 && b
->type
!= bp_hardware_breakpoint
2604 && b
->type
!= bp_catch_fork
2605 && b
->type
!= bp_catch_vfork
2606 && b
->type
!= bp_catch_exec
2607 && b
->type
!= bp_catch_catch
2608 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2610 if (b
->loc
->address
!= bp_addr
) /* address doesn't match */
2612 if (overlay_debugging
/* unmapped overlay section */
2613 && section_is_overlay (b
->loc
->section
)
2614 && !section_is_mapped (b
->loc
->section
))
2618 /* Continuable hardware watchpoints are treated as non-existent if the
2619 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2620 some data address). Otherwise gdb won't stop on a break instruction
2621 in the code (not from a breakpoint) when a hardware watchpoint has
2624 if ((b
->type
== bp_hardware_watchpoint
2625 || b
->type
== bp_read_watchpoint
2626 || b
->type
== bp_access_watchpoint
)
2627 && !stopped_by_watchpoint
)
2630 if (b
->type
== bp_hardware_breakpoint
)
2632 if (b
->loc
->address
!= bp_addr
)
2634 if (overlay_debugging
/* unmapped overlay section */
2635 && section_is_overlay (b
->loc
->section
)
2636 && !section_is_mapped (b
->loc
->section
))
2640 /* Is this a catchpoint of a load or unload? If so, did we
2641 get a load or unload of the specified library? If not,
2643 if ((b
->type
== bp_catch_load
)
2644 #if defined(SOLIB_HAVE_LOAD_EVENT)
2645 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2646 || ((b
->dll_pathname
!= NULL
)
2647 && (strcmp (b
->dll_pathname
,
2648 SOLIB_LOADED_LIBRARY_PATHNAME (
2649 PIDGET (inferior_ptid
)))
2655 if ((b
->type
== bp_catch_unload
)
2656 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2657 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2658 || ((b
->dll_pathname
!= NULL
)
2659 && (strcmp (b
->dll_pathname
,
2660 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2661 PIDGET (inferior_ptid
)))
2667 if ((b
->type
== bp_catch_fork
)
2668 && !inferior_has_forked (PIDGET (inferior_ptid
),
2669 &b
->forked_inferior_pid
))
2672 if ((b
->type
== bp_catch_vfork
)
2673 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2674 &b
->forked_inferior_pid
))
2677 if ((b
->type
== bp_catch_exec
)
2678 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2681 if (ep_is_exception_catchpoint (b
) &&
2682 !(current_exception_event
= target_get_current_exception_event ()))
2685 /* Come here if it's a watchpoint, or if the break address matches */
2687 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
2689 /* Watchpoints may change this, if not found to have triggered. */
2693 if (b
->type
== bp_watchpoint
||
2694 b
->type
== bp_hardware_watchpoint
)
2696 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2698 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2699 int e
= catch_errors (watchpoint_check
, bs
, message
,
2701 do_cleanups (cleanups
);
2705 /* We've already printed what needs to be printed. */
2706 /* Actually this is superfluous, because by the time we
2707 call print_it_typical() the wp will be already deleted,
2708 and the function will return immediately. */
2709 bs
->print_it
= print_it_done
;
2712 case WP_VALUE_CHANGED
:
2716 case WP_VALUE_NOT_CHANGED
:
2718 bs
->print_it
= print_it_noop
;
2725 /* Error from catch_errors. */
2726 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2727 if (b
->related_breakpoint
)
2728 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2729 b
->disposition
= disp_del_at_next_stop
;
2730 /* We've already printed what needs to be printed. */
2731 bs
->print_it
= print_it_done
;
2737 else if (b
->type
== bp_read_watchpoint
||
2738 b
->type
== bp_access_watchpoint
)
2744 if (!target_stopped_data_address (¤t_target
, &addr
))
2746 for (v
= b
->val_chain
; v
; v
= v
->next
)
2748 if (VALUE_LVAL (v
) == lval_memory
2749 && ! VALUE_LAZY (v
))
2751 struct type
*vtype
= check_typedef (value_type (v
));
2753 if (v
== b
->val_chain
2754 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2755 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2759 vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
2760 /* Exact match not required. Within range is
2762 if (addr
>= vaddr
&&
2763 addr
< vaddr
+ TYPE_LENGTH (value_type (v
)))
2770 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2772 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2773 int e
= catch_errors (watchpoint_check
, bs
, message
,
2775 do_cleanups (cleanups
);
2779 /* We've already printed what needs to be printed. */
2780 bs
->print_it
= print_it_done
;
2783 case WP_VALUE_CHANGED
:
2784 if (b
->type
== bp_read_watchpoint
)
2786 /* Don't stop: read watchpoints shouldn't fire if
2787 the value has changed. This is for targets
2788 which cannot set read-only watchpoints. */
2789 bs
->print_it
= print_it_noop
;
2795 case WP_VALUE_NOT_CHANGED
:
2802 /* Error from catch_errors. */
2803 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2804 if (b
->related_breakpoint
)
2805 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2806 b
->disposition
= disp_del_at_next_stop
;
2807 /* We've already printed what needs to be printed. */
2808 bs
->print_it
= print_it_done
;
2812 else /* found == 0 */
2814 /* This is a case where some watchpoint(s) triggered,
2815 but not at the address of this watchpoint (FOUND
2816 was left zero). So don't print anything for this
2818 bs
->print_it
= print_it_noop
;
2825 /* By definition, an encountered breakpoint is a triggered
2829 real_breakpoint
= 1;
2832 if (frame_id_p (b
->frame_id
)
2833 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2837 int value_is_zero
= 0;
2841 /* Need to select the frame, with all that implies
2842 so that the conditions will have the right context. */
2843 select_frame (get_current_frame ());
2845 = catch_errors (breakpoint_cond_eval
, (b
->cond
),
2846 "Error in testing breakpoint condition:\n",
2848 /* FIXME-someday, should give breakpoint # */
2851 if (b
->cond
&& value_is_zero
)
2854 /* Don't consider this a hit. */
2857 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2860 /* Don't consider this a hit. */
2863 else if (b
->ignore_count
> 0)
2866 annotate_ignore_count_change ();
2871 /* We will stop here */
2872 if (b
->disposition
== disp_disable
)
2873 b
->enable_state
= bp_disabled
;
2876 bs
->commands
= b
->commands
;
2878 (strcmp ("silent", bs
->commands
->line
) == 0
2879 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
2881 bs
->commands
= bs
->commands
->next
;
2884 bs
->commands
= copy_command_lines (bs
->commands
);
2887 /* Print nothing for this entry if we dont stop or if we dont print. */
2888 if (bs
->stop
== 0 || bs
->print
== 0)
2889 bs
->print_it
= print_it_noop
;
2892 bs
->next
= NULL
; /* Terminate the chain */
2893 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2895 /* The value of a hardware watchpoint hasn't changed, but the
2896 intermediate memory locations we are watching may have. */
2897 if (bs
&& !bs
->stop
&&
2898 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
2899 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
2900 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
2902 remove_breakpoints ();
2903 insert_breakpoints ();
2908 /* Tell what to do about this bpstat. */
2910 bpstat_what (bpstat bs
)
2912 /* Classify each bpstat as one of the following. */
2915 /* This bpstat element has no effect on the main_action. */
2918 /* There was a watchpoint, stop but don't print. */
2921 /* There was a watchpoint, stop and print. */
2924 /* There was a breakpoint but we're not stopping. */
2927 /* There was a breakpoint, stop but don't print. */
2930 /* There was a breakpoint, stop and print. */
2933 /* We hit the longjmp breakpoint. */
2936 /* We hit the longjmp_resume breakpoint. */
2939 /* We hit the step_resume breakpoint. */
2942 /* We hit the through_sigtramp breakpoint. */
2945 /* We hit the shared library event breakpoint. */
2948 /* We caught a shared library event. */
2951 /* This is just used to count how many enums there are. */
2955 /* Here is the table which drives this routine. So that we can
2956 format it pretty, we define some abbreviations for the
2957 enum bpstat_what codes. */
2958 #define kc BPSTAT_WHAT_KEEP_CHECKING
2959 #define ss BPSTAT_WHAT_STOP_SILENT
2960 #define sn BPSTAT_WHAT_STOP_NOISY
2961 #define sgl BPSTAT_WHAT_SINGLE
2962 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2963 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2964 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2965 #define sr BPSTAT_WHAT_STEP_RESUME
2966 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2967 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2968 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2970 /* "Can't happen." Might want to print an error message.
2971 abort() is not out of the question, but chances are GDB is just
2972 a bit confused, not unusable. */
2973 #define err BPSTAT_WHAT_STOP_NOISY
2975 /* Given an old action and a class, come up with a new action. */
2976 /* One interesting property of this table is that wp_silent is the same
2977 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2978 after stopping, the check for whether to step over a breakpoint
2979 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2980 reference to how we stopped. We retain separate wp_silent and
2981 bp_silent codes in case we want to change that someday.
2983 Another possibly interesting property of this table is that
2984 there's a partial ordering, priority-like, of the actions. Once
2985 you've decided that some action is appropriate, you'll never go
2986 back and decide something of a lower priority is better. The
2989 kc < clr sgl shl shlr slr sn sr ss ts
2990 sgl < clrs shl shlr slr sn sr ss ts
2991 slr < err shl shlr sn sr ss ts
2992 clr < clrs err shl shlr sn sr ss ts
2993 clrs < err shl shlr sn sr ss ts
2994 ss < shl shlr sn sr ts
3001 What I think this means is that we don't need a damned table
3002 here. If you just put the rows and columns in the right order,
3003 it'd look awfully regular. We could simply walk the bpstat list
3004 and choose the highest priority action we find, with a little
3005 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3006 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3007 is messy anyway). */
3009 /* step_resume entries: a step resume breakpoint overrides another
3010 breakpoint of signal handling (see comment in wait_for_inferior
3011 at where we set the step_resume breakpoint). */
3012 /* We handle the through_sigtramp_breakpoint the same way; having both
3013 one of those and a step_resume_breakpoint is probably very rare (?). */
3015 static const enum bpstat_what_main_action
3016 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3019 /* kc ss sn sgl slr clr clrs sr ts shl shlr
3022 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, ts
, shl
, shlr
},
3024 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
3026 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
3028 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, ts
, shl
, shlr
},
3030 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
3032 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
3034 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, ts
, shl
, shlr
},
3036 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, ts
, shl
, shlr
},
3038 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, ts
, shl
, shlr
},
3040 {ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, shl
, shlr
},
3042 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, shl
, ts
, shl
, shlr
},
3044 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, ts
, shlr
, shlr
}
3059 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3060 struct bpstat_what retval
;
3062 retval
.call_dummy
= 0;
3063 for (; bs
!= NULL
; bs
= bs
->next
)
3065 enum class bs_class
= no_effect
;
3066 if (bs
->breakpoint_at
== NULL
)
3067 /* I suspect this can happen if it was a momentary breakpoint
3068 which has since been deleted. */
3070 switch (bs
->breakpoint_at
->type
)
3076 case bp_hardware_breakpoint
:
3082 bs_class
= bp_noisy
;
3084 bs_class
= bp_silent
;
3087 bs_class
= bp_nostop
;
3090 case bp_hardware_watchpoint
:
3091 case bp_read_watchpoint
:
3092 case bp_access_watchpoint
:
3096 bs_class
= wp_noisy
;
3098 bs_class
= wp_silent
;
3101 /* There was a watchpoint, but we're not stopping.
3102 This requires no further action. */
3103 bs_class
= no_effect
;
3106 bs_class
= long_jump
;
3108 case bp_longjmp_resume
:
3109 bs_class
= long_resume
;
3111 case bp_step_resume
:
3114 bs_class
= step_resume
;
3117 /* It is for the wrong frame. */
3118 bs_class
= bp_nostop
;
3120 case bp_through_sigtramp
:
3121 bs_class
= through_sig
;
3123 case bp_watchpoint_scope
:
3124 bs_class
= bp_nostop
;
3126 case bp_shlib_event
:
3127 bs_class
= shlib_event
;
3129 case bp_thread_event
:
3130 case bp_overlay_event
:
3131 bs_class
= bp_nostop
;
3134 case bp_catch_unload
:
3135 /* Only if this catchpoint triggered should we cause the
3136 step-out-of-dld behaviour. Otherwise, we ignore this
3139 bs_class
= catch_shlib_event
;
3141 bs_class
= no_effect
;
3144 case bp_catch_vfork
:
3149 bs_class
= bp_noisy
;
3151 bs_class
= bp_silent
;
3154 /* There was a catchpoint, but we're not stopping.
3155 This requires no further action. */
3156 bs_class
= no_effect
;
3158 case bp_catch_catch
:
3159 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
3160 bs_class
= bp_nostop
;
3162 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3164 case bp_catch_throw
:
3165 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3166 bs_class
= bp_nostop
;
3168 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3171 /* Make sure the action is stop (silent or noisy),
3172 so infrun.c pops the dummy frame. */
3173 bs_class
= bp_silent
;
3174 retval
.call_dummy
= 1;
3177 current_action
= table
[(int) bs_class
][(int) current_action
];
3179 retval
.main_action
= current_action
;
3183 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3184 without hardware support). This isn't related to a specific bpstat,
3185 just to things like whether watchpoints are set. */
3188 bpstat_should_step (void)
3190 struct breakpoint
*b
;
3192 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3197 /* Nonzero if there are enabled hardware watchpoints. */
3199 bpstat_have_active_hw_watchpoints (void)
3201 struct bp_location
*bpt
;
3202 ALL_BP_LOCATIONS (bpt
)
3203 if (breakpoint_enabled (bpt
->owner
)
3205 && bpt
->loc_type
== bp_loc_hardware_watchpoint
)
3211 /* Given a bpstat that records zero or more triggered eventpoints, this
3212 function returns another bpstat which contains only the catchpoints
3213 on that first list, if any. */
3215 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3217 struct bpstats root_bs
[1];
3218 bpstat bs
= root_bs
;
3219 struct breakpoint
*ep
;
3222 bpstat_clear (cp_list
);
3223 root_bs
->next
= NULL
;
3225 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3227 /* Is this eventpoint a catchpoint? If not, ignore it. */
3228 ep
= ep_list
->breakpoint_at
;
3231 if ((ep
->type
!= bp_catch_load
) &&
3232 (ep
->type
!= bp_catch_unload
) &&
3233 (ep
->type
!= bp_catch_catch
) &&
3234 (ep
->type
!= bp_catch_throw
))
3235 /* pai: (temp) ADD fork/vfork here!! */
3238 /* Yes; add it to the list. */
3239 bs
= bpstat_alloc (ep
, bs
);
3244 #if defined(SOLIB_ADD)
3245 /* Also, for each triggered catchpoint, tag it with the name of
3246 the library that caused this trigger. (We copy the name now,
3247 because it's only guaranteed to be available NOW, when the
3248 catchpoint triggers. Clients who may wish to know the name
3249 later must get it from the catchpoint itself.) */
3250 if (ep
->triggered_dll_pathname
!= NULL
)
3251 xfree (ep
->triggered_dll_pathname
);
3252 if (ep
->type
== bp_catch_load
)
3253 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3254 PIDGET (inferior_ptid
));
3256 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3257 PIDGET (inferior_ptid
));
3259 dll_pathname
= NULL
;
3263 ep
->triggered_dll_pathname
= (char *)
3264 xmalloc (strlen (dll_pathname
) + 1);
3265 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3268 ep
->triggered_dll_pathname
= NULL
;
3274 /* Print B to gdb_stdout. */
3276 print_one_breakpoint (struct breakpoint
*b
,
3277 CORE_ADDR
*last_addr
)
3279 struct command_line
*l
;
3281 struct ep_type_description
3286 static struct ep_type_description bptypes
[] =
3288 {bp_none
, "?deleted?"},
3289 {bp_breakpoint
, "breakpoint"},
3290 {bp_hardware_breakpoint
, "hw breakpoint"},
3291 {bp_until
, "until"},
3292 {bp_finish
, "finish"},
3293 {bp_watchpoint
, "watchpoint"},
3294 {bp_hardware_watchpoint
, "hw watchpoint"},
3295 {bp_read_watchpoint
, "read watchpoint"},
3296 {bp_access_watchpoint
, "acc watchpoint"},
3297 {bp_longjmp
, "longjmp"},
3298 {bp_longjmp_resume
, "longjmp resume"},
3299 {bp_step_resume
, "step resume"},
3300 {bp_through_sigtramp
, "sigtramp"},
3301 {bp_watchpoint_scope
, "watchpoint scope"},
3302 {bp_call_dummy
, "call dummy"},
3303 {bp_shlib_event
, "shlib events"},
3304 {bp_thread_event
, "thread events"},
3305 {bp_overlay_event
, "overlay events"},
3306 {bp_catch_load
, "catch load"},
3307 {bp_catch_unload
, "catch unload"},
3308 {bp_catch_fork
, "catch fork"},
3309 {bp_catch_vfork
, "catch vfork"},
3310 {bp_catch_exec
, "catch exec"},
3311 {bp_catch_catch
, "catch catch"},
3312 {bp_catch_throw
, "catch throw"}
3315 static char *bpdisps
[] =
3316 {"del", "dstp", "dis", "keep"};
3317 static char bpenables
[] = "nynny";
3318 char wrap_indent
[80];
3319 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3320 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3321 struct cleanup
*bkpt_chain
;
3324 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3328 ui_out_field_int (uiout
, "number", b
->number
);
3332 if (((int) b
->type
> (sizeof (bptypes
) / sizeof (bptypes
[0])))
3333 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3334 internal_error (__FILE__
, __LINE__
,
3335 "bptypes table does not describe type #%d.",
3337 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3341 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3345 ui_out_field_fmt (uiout
, "enabled", "%c", bpenables
[(int) b
->enable_state
]);
3346 ui_out_spaces (uiout
, 2);
3349 strcpy (wrap_indent
, " ");
3352 if (TARGET_ADDR_BIT
<= 32)
3353 strcat (wrap_indent
, " ");
3355 strcat (wrap_indent
, " ");
3358 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3359 b
->ops
->print_one (b
, last_addr
);
3364 internal_error (__FILE__
, __LINE__
,
3365 "print_one_breakpoint: bp_none encountered\n");
3369 case bp_hardware_watchpoint
:
3370 case bp_read_watchpoint
:
3371 case bp_access_watchpoint
:
3372 /* Field 4, the address, is omitted (which makes the columns
3373 not line up too nicely with the headers, but the effect
3374 is relatively readable). */
3376 ui_out_field_skip (uiout
, "addr");
3378 print_expression (b
->exp
, stb
->stream
);
3379 ui_out_field_stream (uiout
, "what", stb
);
3383 case bp_catch_unload
:
3384 /* Field 4, the address, is omitted (which makes the columns
3385 not line up too nicely with the headers, but the effect
3386 is relatively readable). */
3388 ui_out_field_skip (uiout
, "addr");
3390 if (b
->dll_pathname
== NULL
)
3392 ui_out_field_string (uiout
, "what", "<any library>");
3393 ui_out_spaces (uiout
, 1);
3397 ui_out_text (uiout
, "library \"");
3398 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3399 ui_out_text (uiout
, "\" ");
3404 case bp_catch_vfork
:
3405 /* Field 4, the address, is omitted (which makes the columns
3406 not line up too nicely with the headers, but the effect
3407 is relatively readable). */
3409 ui_out_field_skip (uiout
, "addr");
3411 if (b
->forked_inferior_pid
!= 0)
3413 ui_out_text (uiout
, "process ");
3414 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3415 ui_out_spaces (uiout
, 1);
3419 /* Field 4, the address, is omitted (which makes the columns
3420 not line up too nicely with the headers, but the effect
3421 is relatively readable). */
3423 ui_out_field_skip (uiout
, "addr");
3425 if (b
->exec_pathname
!= NULL
)
3427 ui_out_text (uiout
, "program \"");
3428 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3429 ui_out_text (uiout
, "\" ");
3433 case bp_catch_catch
:
3434 /* Field 4, the address, is omitted (which makes the columns
3435 not line up too nicely with the headers, but the effect
3436 is relatively readable). */
3438 ui_out_field_skip (uiout
, "addr");
3440 ui_out_field_string (uiout
, "what", "exception catch");
3441 ui_out_spaces (uiout
, 1);
3444 case bp_catch_throw
:
3445 /* Field 4, the address, is omitted (which makes the columns
3446 not line up too nicely with the headers, but the effect
3447 is relatively readable). */
3449 ui_out_field_skip (uiout
, "addr");
3451 ui_out_field_string (uiout
, "what", "exception throw");
3452 ui_out_spaces (uiout
, 1);
3456 case bp_hardware_breakpoint
:
3460 case bp_longjmp_resume
:
3461 case bp_step_resume
:
3462 case bp_through_sigtramp
:
3463 case bp_watchpoint_scope
:
3465 case bp_shlib_event
:
3466 case bp_thread_event
:
3467 case bp_overlay_event
:
3472 ui_out_field_string (uiout
, "addr", "<PENDING>");
3474 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
3477 *last_addr
= b
->loc
->address
;
3480 sym
= find_pc_sect_function (b
->loc
->address
, b
->loc
->section
);
3483 ui_out_text (uiout
, "in ");
3484 ui_out_field_string (uiout
, "func",
3485 SYMBOL_PRINT_NAME (sym
));
3486 ui_out_wrap_hint (uiout
, wrap_indent
);
3487 ui_out_text (uiout
, " at ");
3489 ui_out_field_string (uiout
, "file", b
->source_file
);
3490 ui_out_text (uiout
, ":");
3491 ui_out_field_int (uiout
, "line", b
->line_number
);
3493 else if (b
->pending
)
3495 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3499 print_address_symbolic (b
->loc
->address
, stb
->stream
, demangle
, "");
3500 ui_out_field_stream (uiout
, "at", stb
);
3505 if (b
->thread
!= -1)
3507 /* FIXME: This seems to be redundant and lost here; see the
3508 "stop only in" line a little further down. */
3509 ui_out_text (uiout
, " thread ");
3510 ui_out_field_int (uiout
, "thread", b
->thread
);
3513 ui_out_text (uiout
, "\n");
3515 if (frame_id_p (b
->frame_id
))
3518 ui_out_text (uiout
, "\tstop only in stack frame at ");
3519 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3521 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3522 ui_out_text (uiout
, "\n");
3528 ui_out_text (uiout
, "\tstop only if ");
3529 print_expression (b
->cond
, stb
->stream
);
3530 ui_out_field_stream (uiout
, "cond", stb
);
3531 ui_out_text (uiout
, "\n");
3534 if (b
->pending
&& b
->cond_string
)
3537 ui_out_text (uiout
, "\tstop only if ");
3538 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3539 ui_out_text (uiout
, "\n");
3542 if (b
->thread
!= -1)
3544 /* FIXME should make an annotation for this */
3545 ui_out_text (uiout
, "\tstop only in thread ");
3546 ui_out_field_int (uiout
, "thread", b
->thread
);
3547 ui_out_text (uiout
, "\n");
3550 if (show_breakpoint_hit_counts
&& b
->hit_count
)
3552 /* FIXME should make an annotation for this */
3553 if (ep_is_catchpoint (b
))
3554 ui_out_text (uiout
, "\tcatchpoint");
3556 ui_out_text (uiout
, "\tbreakpoint");
3557 ui_out_text (uiout
, " already hit ");
3558 ui_out_field_int (uiout
, "times", b
->hit_count
);
3559 if (b
->hit_count
== 1)
3560 ui_out_text (uiout
, " time\n");
3562 ui_out_text (uiout
, " times\n");
3565 /* Output the count also if it is zero, but only if this is
3566 mi. FIXME: Should have a better test for this. */
3567 if (ui_out_is_mi_like_p (uiout
))
3568 if (show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3569 ui_out_field_int (uiout
, "times", b
->hit_count
);
3571 if (b
->ignore_count
)
3574 ui_out_text (uiout
, "\tignore next ");
3575 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3576 ui_out_text (uiout
, " hits\n");
3579 if ((l
= b
->commands
))
3581 struct cleanup
*script_chain
;
3584 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3585 print_command_lines (uiout
, l
, 4);
3586 do_cleanups (script_chain
);
3588 do_cleanups (bkpt_chain
);
3589 do_cleanups (old_chain
);
3592 struct captured_breakpoint_query_args
3598 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3600 struct captured_breakpoint_query_args
*args
= data
;
3601 struct breakpoint
*b
;
3602 CORE_ADDR dummy_addr
= 0;
3605 if (args
->bnum
== b
->number
)
3607 print_one_breakpoint (b
, &dummy_addr
);
3615 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
)
3617 struct captured_breakpoint_query_args args
;
3619 /* For the moment we don't trust print_one_breakpoint() to not throw
3621 return catch_exceptions (uiout
, do_captured_breakpoint_query
, &args
,
3622 NULL
, RETURN_MASK_ALL
);
3625 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3626 catchpoints, et.al.). */
3629 user_settable_breakpoint (const struct breakpoint
*b
)
3631 return (b
->type
== bp_breakpoint
3632 || b
->type
== bp_catch_load
3633 || b
->type
== bp_catch_unload
3634 || b
->type
== bp_catch_fork
3635 || b
->type
== bp_catch_vfork
3636 || b
->type
== bp_catch_exec
3637 || b
->type
== bp_catch_catch
3638 || b
->type
== bp_catch_throw
3639 || b
->type
== bp_hardware_breakpoint
3640 || b
->type
== bp_watchpoint
3641 || b
->type
== bp_read_watchpoint
3642 || b
->type
== bp_access_watchpoint
3643 || b
->type
== bp_hardware_watchpoint
);
3646 /* Print information on user settable breakpoint (watchpoint, etc)
3647 number BNUM. If BNUM is -1 print all user settable breakpoints.
3648 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3651 breakpoint_1 (int bnum
, int allflag
)
3653 struct breakpoint
*b
;
3654 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3655 int nr_printable_breakpoints
;
3656 struct cleanup
*bkpttbl_chain
;
3658 /* Compute the number of rows in the table. */
3659 nr_printable_breakpoints
= 0;
3662 || bnum
== b
->number
)
3664 if (allflag
|| user_settable_breakpoint (b
))
3665 nr_printable_breakpoints
++;
3670 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3674 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3677 if (nr_printable_breakpoints
> 0)
3678 annotate_breakpoints_headers ();
3679 if (nr_printable_breakpoints
> 0)
3681 ui_out_table_header (uiout
, 3, ui_left
, "number", "Num"); /* 1 */
3682 if (nr_printable_breakpoints
> 0)
3684 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3685 if (nr_printable_breakpoints
> 0)
3687 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3688 if (nr_printable_breakpoints
> 0)
3690 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3693 if (nr_printable_breakpoints
> 0)
3695 if (TARGET_ADDR_BIT
<= 32)
3696 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3698 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3700 if (nr_printable_breakpoints
> 0)
3702 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3703 ui_out_table_body (uiout
);
3704 if (nr_printable_breakpoints
> 0)
3705 annotate_breakpoints_table ();
3709 || bnum
== b
->number
)
3711 /* We only print out user settable breakpoints unless the
3713 if (allflag
|| user_settable_breakpoint (b
))
3714 print_one_breakpoint (b
, &last_addr
);
3717 do_cleanups (bkpttbl_chain
);
3719 if (nr_printable_breakpoints
== 0)
3722 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3724 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3729 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3730 that a comparison of an unsigned with -1 is always false. */
3731 if (last_addr
!= (CORE_ADDR
) -1)
3732 set_next_address (last_addr
);
3735 /* FIXME? Should this be moved up so that it is only called when
3736 there have been breakpoints? */
3737 annotate_breakpoints_table_end ();
3741 breakpoints_info (char *bnum_exp
, int from_tty
)
3746 bnum
= parse_and_eval_long (bnum_exp
);
3748 breakpoint_1 (bnum
, 0);
3752 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3757 bnum
= parse_and_eval_long (bnum_exp
);
3759 breakpoint_1 (bnum
, 1);
3762 /* Print a message describing any breakpoints set at PC. */
3765 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
)
3768 struct breakpoint
*b
;
3771 if (b
->loc
->address
== pc
) /* address match / overlay match */
3772 if (!b
->pending
&& (!overlay_debugging
|| b
->loc
->section
== section
))
3776 printf_filtered ("Note: breakpoint%s ", (others
> 1) ? "s" : "");
3778 if (b
->loc
->address
== pc
) /* address match / overlay match */
3779 if (!b
->pending
&& (!overlay_debugging
|| b
->loc
->section
== section
))
3782 printf_filtered ("%d%s%s ",
3784 ((b
->enable_state
== bp_disabled
||
3785 b
->enable_state
== bp_shlib_disabled
||
3786 b
->enable_state
== bp_call_disabled
)
3788 : b
->enable_state
== bp_permanent
3792 : ((others
== 1) ? " and" : ""));
3794 printf_filtered ("also set at pc ");
3795 print_address_numeric (pc
, 1, gdb_stdout
);
3796 printf_filtered (".\n");
3800 /* Set the default place to put a breakpoint
3801 for the `break' command with no arguments. */
3804 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3807 default_breakpoint_valid
= valid
;
3808 default_breakpoint_address
= addr
;
3809 default_breakpoint_symtab
= symtab
;
3810 default_breakpoint_line
= line
;
3813 /* Return true iff it is meaningful to use the address member of
3814 BPT. For some breakpoint types, the address member is irrelevant
3815 and it makes no sense to attempt to compare it to other addresses
3816 (or use it for any other purpose either).
3818 More specifically, each of the following breakpoint types will always
3819 have a zero valued address and we don't want check_duplicates() to mark
3820 breakpoints of any of these types to be a duplicate of an actual
3821 breakpoint at address zero:
3824 bp_hardware_watchpoint
3826 bp_access_watchpoint
3833 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3835 enum bptype type
= bpt
->type
;
3837 return (type
!= bp_watchpoint
3838 && type
!= bp_hardware_watchpoint
3839 && type
!= bp_read_watchpoint
3840 && type
!= bp_access_watchpoint
3841 && type
!= bp_catch_exec
3842 && type
!= bp_longjmp_resume
3843 && type
!= bp_catch_fork
3844 && type
!= bp_catch_vfork
);
3847 /* Rescan breakpoints at the same address and section as BPT,
3848 marking the first one as "first" and any others as "duplicates".
3849 This is so that the bpt instruction is only inserted once.
3850 If we have a permanent breakpoint at the same place as BPT, make
3851 that one the official one, and the rest as duplicates. */
3854 check_duplicates (struct breakpoint
*bpt
)
3856 struct bp_location
*b
;
3858 struct bp_location
*perm_bp
= 0;
3859 CORE_ADDR address
= bpt
->loc
->address
;
3860 asection
*section
= bpt
->loc
->section
;
3862 if (! breakpoint_address_is_meaningful (bpt
))
3865 ALL_BP_LOCATIONS (b
)
3866 if (b
->owner
->enable_state
!= bp_disabled
3867 && b
->owner
->enable_state
!= bp_shlib_disabled
3868 && !b
->owner
->pending
3869 && b
->owner
->enable_state
!= bp_call_disabled
3870 && b
->address
== address
/* address / overlay match */
3871 && (!overlay_debugging
|| b
->section
== section
)
3872 && breakpoint_address_is_meaningful (b
->owner
))
3874 /* Have we found a permanent breakpoint? */
3875 if (b
->owner
->enable_state
== bp_permanent
)
3882 b
->duplicate
= count
> 1;
3885 /* If we found a permanent breakpoint at this address, go over the
3886 list again and declare all the other breakpoints there to be the
3890 perm_bp
->duplicate
= 0;
3892 /* Permanent breakpoint should always be inserted. */
3893 if (! perm_bp
->inserted
)
3894 internal_error (__FILE__
, __LINE__
,
3895 "allegedly permanent breakpoint is not "
3896 "actually inserted");
3898 ALL_BP_LOCATIONS (b
)
3901 if (b
->owner
->enable_state
!= bp_disabled
3902 && b
->owner
->enable_state
!= bp_shlib_disabled
3903 && !b
->owner
->pending
3904 && b
->owner
->enable_state
!= bp_call_disabled
3905 && b
->address
== address
/* address / overlay match */
3906 && (!overlay_debugging
|| b
->section
== section
)
3907 && breakpoint_address_is_meaningful (b
->owner
))
3910 internal_error (__FILE__
, __LINE__
,
3911 "another breakpoint was inserted on top of "
3912 "a permanent breakpoint");
3921 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
3922 int bnum
, int have_bnum
)
3927 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
3928 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
3930 warning ("Breakpoint %d address previously adjusted from %s to %s.",
3931 bnum
, astr1
, astr2
);
3933 warning ("Breakpoint address adjusted from %s to %s.", astr1
, astr2
);
3936 /* Adjust a breakpoint's address to account for architectural constraints
3937 on breakpoint placement. Return the adjusted address. Note: Very
3938 few targets require this kind of adjustment. For most targets,
3939 this function is simply the identity function. */
3942 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
3944 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
3946 /* Very few targets need any kind of breakpoint adjustment. */
3949 else if (bptype
== bp_watchpoint
3950 || bptype
== bp_hardware_watchpoint
3951 || bptype
== bp_read_watchpoint
3952 || bptype
== bp_access_watchpoint
3953 || bptype
== bp_catch_fork
3954 || bptype
== bp_catch_vfork
3955 || bptype
== bp_catch_exec
)
3957 /* Watchpoints and the various bp_catch_* eventpoints should not
3958 have their addresses modified. */
3963 CORE_ADDR adjusted_bpaddr
;
3965 /* Some targets have architectural constraints on the placement
3966 of breakpoint instructions. Obtain the adjusted address. */
3967 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
3970 /* An adjusted breakpoint address can significantly alter
3971 a user's expectations. Print a warning if an adjustment
3973 if (adjusted_bpaddr
!= bpaddr
)
3974 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
3976 return adjusted_bpaddr
;
3980 /* Allocate a struct bp_location. */
3982 static struct bp_location
*
3983 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
3985 struct bp_location
*loc
, *loc_p
;
3987 loc
= xmalloc (sizeof (struct bp_location
));
3988 memset (loc
, 0, sizeof (*loc
));
3998 case bp_longjmp_resume
:
3999 case bp_step_resume
:
4000 case bp_through_sigtramp
:
4001 case bp_watchpoint_scope
:
4003 case bp_shlib_event
:
4004 case bp_thread_event
:
4005 case bp_overlay_event
:
4007 case bp_catch_unload
:
4008 loc
->loc_type
= bp_loc_software_breakpoint
;
4010 case bp_hardware_breakpoint
:
4011 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4013 case bp_hardware_watchpoint
:
4014 case bp_read_watchpoint
:
4015 case bp_access_watchpoint
:
4016 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4020 case bp_catch_vfork
:
4022 case bp_catch_catch
:
4023 case bp_catch_throw
:
4024 loc
->loc_type
= bp_loc_other
;
4027 internal_error (__FILE__
, __LINE__
, "unknown breakpoint type");
4030 /* Add this breakpoint to the end of the chain. */
4032 loc_p
= bp_location_chain
;
4034 bp_location_chain
= loc
;
4038 loc_p
= loc_p
->next
;
4045 /* set_raw_breakpoint() is a low level routine for allocating and
4046 partially initializing a breakpoint of type BPTYPE. The newly
4047 created breakpoint's address, section, source file name, and line
4048 number are provided by SAL. The newly created and partially
4049 initialized breakpoint is added to the breakpoint chain and
4050 is also returned as the value of this function.
4052 It is expected that the caller will complete the initialization of
4053 the newly created breakpoint struct as well as output any status
4054 information regarding the creation of a new breakpoint. In
4055 particular, set_raw_breakpoint() does NOT set the breakpoint
4056 number! Care should be taken to not allow an error() to occur
4057 prior to completing the initialization of the breakpoint. If this
4058 should happen, a bogus breakpoint will be left on the chain. */
4061 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4063 struct breakpoint
*b
, *b1
;
4065 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4066 memset (b
, 0, sizeof (*b
));
4067 b
->loc
= allocate_bp_location (b
, bptype
);
4068 b
->loc
->requested_address
= sal
.pc
;
4069 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4071 if (sal
.symtab
== NULL
)
4072 b
->source_file
= NULL
;
4074 b
->source_file
= savestring (sal
.symtab
->filename
,
4075 strlen (sal
.symtab
->filename
));
4076 b
->loc
->section
= sal
.section
;
4078 b
->language
= current_language
->la_language
;
4079 b
->input_radix
= input_radix
;
4081 b
->line_number
= sal
.line
;
4082 b
->enable_state
= bp_enabled
;
4085 b
->ignore_count
= 0;
4087 b
->frame_id
= null_frame_id
;
4088 b
->dll_pathname
= NULL
;
4089 b
->triggered_dll_pathname
= NULL
;
4090 b
->forked_inferior_pid
= 0;
4091 b
->exec_pathname
= NULL
;
4095 /* Add this breakpoint to the end of the chain
4096 so that a list of breakpoints will come out in order
4097 of increasing numbers. */
4099 b1
= breakpoint_chain
;
4101 breakpoint_chain
= b
;
4109 check_duplicates (b
);
4110 breakpoints_changed ();
4116 /* Note that the breakpoint object B describes a permanent breakpoint
4117 instruction, hard-wired into the inferior's code. */
4119 make_breakpoint_permanent (struct breakpoint
*b
)
4121 b
->enable_state
= bp_permanent
;
4123 /* By definition, permanent breakpoints are already present in the code. */
4124 b
->loc
->inserted
= 1;
4127 static struct breakpoint
*
4128 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4130 static int internal_breakpoint_number
= -1;
4131 struct symtab_and_line sal
;
4132 struct breakpoint
*b
;
4134 init_sal (&sal
); /* initialize to zeroes */
4137 sal
.section
= find_pc_overlay (sal
.pc
);
4139 b
= set_raw_breakpoint (sal
, type
);
4140 b
->number
= internal_breakpoint_number
--;
4141 b
->disposition
= disp_donttouch
;
4148 create_longjmp_breakpoint (char *func_name
)
4150 struct breakpoint
*b
;
4151 struct minimal_symbol
*m
;
4153 if (func_name
== NULL
)
4154 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4157 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4160 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4163 b
->enable_state
= bp_disabled
;
4166 b
->addr_string
= xstrdup (func_name
);
4169 /* Call this routine when stepping and nexting to enable a breakpoint
4170 if we do a longjmp(). When we hit that breakpoint, call
4171 set_longjmp_resume_breakpoint() to figure out where we are going. */
4174 enable_longjmp_breakpoint (void)
4176 struct breakpoint
*b
;
4179 if (b
->type
== bp_longjmp
)
4181 b
->enable_state
= bp_enabled
;
4182 check_duplicates (b
);
4187 disable_longjmp_breakpoint (void)
4189 struct breakpoint
*b
;
4192 if (b
->type
== bp_longjmp
4193 || b
->type
== bp_longjmp_resume
)
4195 b
->enable_state
= bp_disabled
;
4196 check_duplicates (b
);
4201 create_overlay_event_breakpoint (char *func_name
)
4203 struct breakpoint
*b
;
4204 struct minimal_symbol
*m
;
4206 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4209 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4211 b
->addr_string
= xstrdup (func_name
);
4213 if (overlay_debugging
== ovly_auto
)
4215 b
->enable_state
= bp_enabled
;
4216 overlay_events_enabled
= 1;
4220 b
->enable_state
= bp_disabled
;
4221 overlay_events_enabled
= 0;
4226 enable_overlay_breakpoints (void)
4228 struct breakpoint
*b
;
4231 if (b
->type
== bp_overlay_event
)
4233 b
->enable_state
= bp_enabled
;
4234 check_duplicates (b
);
4235 overlay_events_enabled
= 1;
4240 disable_overlay_breakpoints (void)
4242 struct breakpoint
*b
;
4245 if (b
->type
== bp_overlay_event
)
4247 b
->enable_state
= bp_disabled
;
4248 check_duplicates (b
);
4249 overlay_events_enabled
= 0;
4254 create_thread_event_breakpoint (CORE_ADDR address
)
4256 struct breakpoint
*b
;
4258 b
= create_internal_breakpoint (address
, bp_thread_event
);
4260 b
->enable_state
= bp_enabled
;
4261 /* addr_string has to be used or breakpoint_re_set will delete me. */
4262 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4268 remove_thread_event_breakpoints (void)
4270 struct breakpoint
*b
, *temp
;
4272 ALL_BREAKPOINTS_SAFE (b
, temp
)
4273 if (b
->type
== bp_thread_event
)
4274 delete_breakpoint (b
);
4277 struct captured_parse_breakpoint_args
4280 struct symtabs_and_lines
*sals_p
;
4281 char ***addr_string_p
;
4285 struct lang_and_radix
4291 /* Cleanup helper routine to restore the current language and
4294 do_restore_lang_radix_cleanup (void *old
)
4296 struct lang_and_radix
*p
= old
;
4297 set_language (p
->lang
);
4298 input_radix
= p
->radix
;
4301 /* Try and resolve a pending breakpoint. */
4303 resolve_pending_breakpoint (struct breakpoint
*b
)
4305 /* Try and reparse the breakpoint in case the shared library
4307 struct symtabs_and_lines sals
;
4308 struct symtab_and_line pending_sal
;
4309 char **cond_string
= (char **) NULL
;
4310 char *copy_arg
= b
->addr_string
;
4315 struct ui_file
*old_gdb_stderr
;
4316 struct lang_and_radix old_lr
;
4317 struct cleanup
*old_chain
;
4319 /* Set language, input-radix, then reissue breakpoint command.
4320 Ensure the language and input-radix are restored afterwards. */
4321 old_lr
.lang
= current_language
->la_language
;
4322 old_lr
.radix
= input_radix
;
4323 old_chain
= make_cleanup (do_restore_lang_radix_cleanup
, &old_lr
);
4325 set_language (b
->language
);
4326 input_radix
= b
->input_radix
;
4327 rc
= break_command_1 (b
->addr_string
, b
->flag
, b
->from_tty
, b
);
4329 if (rc
== GDB_RC_OK
)
4330 /* Pending breakpoint has been resolved. */
4331 printf_filtered ("Pending breakpoint \"%s\" resolved\n", b
->addr_string
);
4333 do_cleanups (old_chain
);
4339 remove_solib_event_breakpoints (void)
4341 struct breakpoint
*b
, *temp
;
4343 ALL_BREAKPOINTS_SAFE (b
, temp
)
4344 if (b
->type
== bp_shlib_event
)
4345 delete_breakpoint (b
);
4349 create_solib_event_breakpoint (CORE_ADDR address
)
4351 struct breakpoint
*b
;
4353 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4357 /* Disable any breakpoints that are on code in shared libraries. Only
4358 apply to enabled breakpoints, disabled ones can just stay disabled. */
4361 disable_breakpoints_in_shlibs (int silent
)
4363 struct breakpoint
*b
;
4364 int disabled_shlib_breaks
= 0;
4366 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4369 #if defined (PC_SOLIB)
4370 if (((b
->type
== bp_breakpoint
) ||
4371 (b
->type
== bp_hardware_breakpoint
)) &&
4372 breakpoint_enabled (b
) &&
4373 !b
->loc
->duplicate
&&
4374 PC_SOLIB (b
->loc
->address
))
4376 b
->enable_state
= bp_shlib_disabled
;
4379 if (!disabled_shlib_breaks
)
4381 target_terminal_ours_for_output ();
4382 warning ("Temporarily disabling shared library breakpoints:");
4384 disabled_shlib_breaks
= 1;
4385 warning ("breakpoint #%d ", b
->number
);
4392 /* Disable any breakpoints that are in in an unloaded shared library. Only
4393 apply to enabled breakpoints, disabled ones can just stay disabled. */
4396 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4398 struct breakpoint
*b
;
4399 int disabled_shlib_breaks
= 0;
4401 #if defined (PC_SOLIB)
4402 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4405 if ((b
->loc
->loc_type
== bp_loc_hardware_breakpoint
4406 || b
->loc
->loc_type
== bp_loc_software_breakpoint
)
4407 && breakpoint_enabled (b
)
4408 && !b
->loc
->duplicate
)
4410 char *so_name
= PC_SOLIB (b
->loc
->address
);
4412 && !strcmp (so_name
, solib
->so_name
))
4414 b
->enable_state
= bp_shlib_disabled
;
4415 /* At this point, we cannot rely on remove_breakpoint
4416 succeeding so we must mark the breakpoint as not inserted
4417 to prevent future errors occurring in remove_breakpoints. */
4418 b
->loc
->inserted
= 0;
4419 if (!disabled_shlib_breaks
)
4421 target_terminal_ours_for_output ();
4422 warning ("Temporarily disabling breakpoints for unloaded shared library \"%s\"",
4425 disabled_shlib_breaks
= 1;
4432 /* Try to reenable any breakpoints in shared libraries. */
4434 re_enable_breakpoints_in_shlibs (void)
4436 struct breakpoint
*b
, *tmp
;
4438 ALL_BREAKPOINTS_SAFE (b
, tmp
)
4440 if (b
->enable_state
== bp_shlib_disabled
)
4444 /* Do not reenable the breakpoint if the shared library
4445 is still not mapped in. */
4446 lib
= PC_SOLIB (b
->loc
->address
);
4447 if (lib
!= NULL
&& target_read_memory (b
->loc
->address
, buf
, 1) == 0)
4448 b
->enable_state
= bp_enabled
;
4450 else if (b
->pending
&& (b
->enable_state
== bp_enabled
))
4452 if (resolve_pending_breakpoint (b
) == GDB_RC_OK
)
4453 delete_breakpoint (b
);
4461 solib_load_unload_1 (char *hookname
, int tempflag
, char *dll_pathname
,
4462 char *cond_string
, enum bptype bp_kind
)
4464 struct breakpoint
*b
;
4465 struct symtabs_and_lines sals
;
4466 struct cleanup
*old_chain
;
4467 struct cleanup
*canonical_strings_chain
= NULL
;
4468 char *addr_start
= hookname
;
4469 char *addr_end
= NULL
;
4470 char **canonical
= (char **) NULL
;
4471 int thread
= -1; /* All threads. */
4473 /* Set a breakpoint on the specified hook. */
4474 sals
= decode_line_1 (&hookname
, 1, (struct symtab
*) NULL
, 0, &canonical
, NULL
);
4475 addr_end
= hookname
;
4477 if (sals
.nelts
== 0)
4479 warning ("Unable to set a breakpoint on dynamic linker callback.");
4480 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4481 warning ("GDB will be unable to track shl_load/shl_unload calls");
4484 if (sals
.nelts
!= 1)
4486 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4487 warning ("GDB will be unable to track shl_load/shl_unload calls");
4491 /* Make sure that all storage allocated in decode_line_1 gets freed
4492 in case the following errors out. */
4493 old_chain
= make_cleanup (xfree
, sals
.sals
);
4494 if (canonical
!= (char **) NULL
)
4496 make_cleanup (xfree
, canonical
);
4497 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
4498 if (canonical
[0] != NULL
)
4499 make_cleanup (xfree
, canonical
[0]);
4502 resolve_sal_pc (&sals
.sals
[0]);
4504 /* Remove the canonical strings from the cleanup, they are needed below. */
4505 if (canonical
!= (char **) NULL
)
4506 discard_cleanups (canonical_strings_chain
);
4508 b
= set_raw_breakpoint (sals
.sals
[0], bp_kind
);
4509 set_breakpoint_count (breakpoint_count
+ 1);
4510 b
->number
= breakpoint_count
;
4512 b
->cond_string
= (cond_string
== NULL
) ?
4513 NULL
: savestring (cond_string
, strlen (cond_string
));
4516 if (canonical
!= (char **) NULL
&& canonical
[0] != NULL
)
4517 b
->addr_string
= canonical
[0];
4518 else if (addr_start
)
4519 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
4521 b
->enable_state
= bp_enabled
;
4522 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4524 if (dll_pathname
== NULL
)
4525 b
->dll_pathname
= NULL
;
4528 b
->dll_pathname
= (char *) xmalloc (strlen (dll_pathname
) + 1);
4529 strcpy (b
->dll_pathname
, dll_pathname
);
4533 do_cleanups (old_chain
);
4537 create_solib_load_event_breakpoint (char *hookname
, int tempflag
,
4538 char *dll_pathname
, char *cond_string
)
4540 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4541 cond_string
, bp_catch_load
);
4545 create_solib_unload_event_breakpoint (char *hookname
, int tempflag
,
4546 char *dll_pathname
, char *cond_string
)
4548 solib_load_unload_1 (hookname
,tempflag
, dll_pathname
,
4549 cond_string
, bp_catch_unload
);
4553 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4554 enum bptype bp_kind
)
4556 struct symtab_and_line sal
;
4557 struct breakpoint
*b
;
4558 int thread
= -1; /* All threads. */
4565 b
= set_raw_breakpoint (sal
, bp_kind
);
4566 set_breakpoint_count (breakpoint_count
+ 1);
4567 b
->number
= breakpoint_count
;
4569 b
->cond_string
= (cond_string
== NULL
) ?
4570 NULL
: savestring (cond_string
, strlen (cond_string
));
4572 b
->addr_string
= NULL
;
4573 b
->enable_state
= bp_enabled
;
4574 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4575 b
->forked_inferior_pid
= 0;
4581 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4583 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4587 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4589 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4593 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4595 struct symtab_and_line sal
;
4596 struct breakpoint
*b
;
4597 int thread
= -1; /* All threads. */
4604 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4605 set_breakpoint_count (breakpoint_count
+ 1);
4606 b
->number
= breakpoint_count
;
4608 b
->cond_string
= (cond_string
== NULL
) ?
4609 NULL
: savestring (cond_string
, strlen (cond_string
));
4611 b
->addr_string
= NULL
;
4612 b
->enable_state
= bp_enabled
;
4613 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4619 hw_breakpoint_used_count (void)
4621 struct breakpoint
*b
;
4626 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4634 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4636 struct breakpoint
*b
;
4639 *other_type_used
= 0;
4642 if (breakpoint_enabled (b
))
4644 if (b
->type
== type
)
4646 else if ((b
->type
== bp_hardware_watchpoint
||
4647 b
->type
== bp_read_watchpoint
||
4648 b
->type
== bp_access_watchpoint
))
4649 *other_type_used
= 1;
4655 /* Call this after hitting the longjmp() breakpoint. Use this to set
4656 a new breakpoint at the target of the jmp_buf.
4658 FIXME - This ought to be done by setting a temporary breakpoint
4659 that gets deleted automatically... */
4662 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4664 struct breakpoint
*b
;
4667 if (b
->type
== bp_longjmp_resume
)
4669 b
->loc
->requested_address
= pc
;
4670 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4672 b
->enable_state
= bp_enabled
;
4673 b
->frame_id
= frame_id
;
4674 check_duplicates (b
);
4680 disable_watchpoints_before_interactive_call_start (void)
4682 struct breakpoint
*b
;
4686 if (((b
->type
== bp_watchpoint
)
4687 || (b
->type
== bp_hardware_watchpoint
)
4688 || (b
->type
== bp_read_watchpoint
)
4689 || (b
->type
== bp_access_watchpoint
)
4690 || ep_is_exception_catchpoint (b
))
4691 && breakpoint_enabled (b
))
4693 b
->enable_state
= bp_call_disabled
;
4694 check_duplicates (b
);
4700 enable_watchpoints_after_interactive_call_stop (void)
4702 struct breakpoint
*b
;
4706 if (((b
->type
== bp_watchpoint
)
4707 || (b
->type
== bp_hardware_watchpoint
)
4708 || (b
->type
== bp_read_watchpoint
)
4709 || (b
->type
== bp_access_watchpoint
)
4710 || ep_is_exception_catchpoint (b
))
4711 && (b
->enable_state
== bp_call_disabled
))
4713 b
->enable_state
= bp_enabled
;
4714 check_duplicates (b
);
4720 /* Set a breakpoint that will evaporate an end of command
4721 at address specified by SAL.
4722 Restrict it to frame FRAME if FRAME is nonzero. */
4725 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4728 struct breakpoint
*b
;
4729 b
= set_raw_breakpoint (sal
, type
);
4730 b
->enable_state
= bp_enabled
;
4731 b
->disposition
= disp_donttouch
;
4732 b
->frame_id
= frame_id
;
4734 /* If we're debugging a multi-threaded program, then we
4735 want momentary breakpoints to be active in only a
4736 single thread of control. */
4737 if (in_thread_list (inferior_ptid
))
4738 b
->thread
= pid_to_thread_id (inferior_ptid
);
4744 /* Tell the user we have just set a breakpoint B. */
4747 mention (struct breakpoint
*b
)
4750 struct cleanup
*old_chain
, *ui_out_chain
;
4751 struct ui_stream
*stb
;
4753 stb
= ui_out_stream_new (uiout
);
4754 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4756 /* FIXME: This is misplaced; mention() is called by things (like
4757 hitting a watchpoint) other than breakpoint creation. It should
4758 be possible to clean this up and at the same time replace the
4759 random calls to breakpoint_changed with this hook, as has already
4760 been done for deprecated_delete_breakpoint_hook and so on. */
4761 if (deprecated_create_breakpoint_hook
)
4762 deprecated_create_breakpoint_hook (b
);
4763 breakpoint_create_event (b
->number
);
4765 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4766 b
->ops
->print_mention (b
);
4771 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b
->number
);
4774 ui_out_text (uiout
, "Watchpoint ");
4775 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4776 ui_out_field_int (uiout
, "number", b
->number
);
4777 ui_out_text (uiout
, ": ");
4778 print_expression (b
->exp
, stb
->stream
);
4779 ui_out_field_stream (uiout
, "exp", stb
);
4780 do_cleanups (ui_out_chain
);
4782 case bp_hardware_watchpoint
:
4783 ui_out_text (uiout
, "Hardware watchpoint ");
4784 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4785 ui_out_field_int (uiout
, "number", b
->number
);
4786 ui_out_text (uiout
, ": ");
4787 print_expression (b
->exp
, stb
->stream
);
4788 ui_out_field_stream (uiout
, "exp", stb
);
4789 do_cleanups (ui_out_chain
);
4791 case bp_read_watchpoint
:
4792 ui_out_text (uiout
, "Hardware read watchpoint ");
4793 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4794 ui_out_field_int (uiout
, "number", b
->number
);
4795 ui_out_text (uiout
, ": ");
4796 print_expression (b
->exp
, stb
->stream
);
4797 ui_out_field_stream (uiout
, "exp", stb
);
4798 do_cleanups (ui_out_chain
);
4800 case bp_access_watchpoint
:
4801 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4802 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4803 ui_out_field_int (uiout
, "number", b
->number
);
4804 ui_out_text (uiout
, ": ");
4805 print_expression (b
->exp
, stb
->stream
);
4806 ui_out_field_stream (uiout
, "exp", stb
);
4807 do_cleanups (ui_out_chain
);
4810 if (ui_out_is_mi_like_p (uiout
))
4815 printf_filtered ("Breakpoint %d", b
->number
);
4818 case bp_hardware_breakpoint
:
4819 if (ui_out_is_mi_like_p (uiout
))
4824 printf_filtered ("Hardware assisted breakpoint %d", b
->number
);
4828 case bp_catch_unload
:
4829 printf_filtered ("Catchpoint %d (%s %s)",
4831 (b
->type
== bp_catch_load
) ? "load" : "unload",
4832 (b
->dll_pathname
!= NULL
) ?
4833 b
->dll_pathname
: "<any library>");
4836 case bp_catch_vfork
:
4837 printf_filtered ("Catchpoint %d (%s)",
4839 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4842 printf_filtered ("Catchpoint %d (exec)",
4845 case bp_catch_catch
:
4846 case bp_catch_throw
:
4847 printf_filtered ("Catchpoint %d (%s)",
4849 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4855 case bp_longjmp_resume
:
4856 case bp_step_resume
:
4857 case bp_through_sigtramp
:
4859 case bp_watchpoint_scope
:
4860 case bp_shlib_event
:
4861 case bp_thread_event
:
4862 case bp_overlay_event
:
4870 printf_filtered (" (%s) pending.", b
->addr_string
);
4874 if (addressprint
|| b
->source_file
== NULL
)
4876 printf_filtered (" at ");
4877 print_address_numeric (b
->loc
->address
, 1, gdb_stdout
);
4880 printf_filtered (": file %s, line %d.",
4881 b
->source_file
, b
->line_number
);
4884 do_cleanups (old_chain
);
4885 if (ui_out_is_mi_like_p (uiout
))
4887 printf_filtered ("\n");
4891 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4892 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4893 COND[i] and COND_STRING[i] values.
4895 The parameter PENDING_BP points to a pending breakpoint that is
4896 the basis of the breakpoints currently being created. The pending
4897 breakpoint may contain a separate condition string or commands
4898 that were added after the initial pending breakpoint was created.
4900 NOTE: If the function succeeds, the caller is expected to cleanup
4901 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4902 array contents). If the function fails (error() is called), the
4903 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4904 COND and SALS arrays and each of those arrays contents. */
4907 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
4908 struct expression
**cond
, char **cond_string
,
4909 enum bptype type
, enum bpdisp disposition
,
4910 int thread
, int ignore_count
, int from_tty
,
4911 struct breakpoint
*pending_bp
)
4913 if (type
== bp_hardware_breakpoint
)
4915 int i
= hw_breakpoint_used_count ();
4916 int target_resources_ok
=
4917 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4919 if (target_resources_ok
== 0)
4920 error ("No hardware breakpoint support in the target.");
4921 else if (target_resources_ok
< 0)
4922 error ("Hardware breakpoints used exceeds limit.");
4925 /* Now set all the breakpoints. */
4928 for (i
= 0; i
< sals
.nelts
; i
++)
4930 struct breakpoint
*b
;
4931 struct symtab_and_line sal
= sals
.sals
[i
];
4934 describe_other_breakpoints (sal
.pc
, sal
.section
);
4936 b
= set_raw_breakpoint (sal
, type
);
4937 set_breakpoint_count (breakpoint_count
+ 1);
4938 b
->number
= breakpoint_count
;
4942 b
->addr_string
= addr_string
[i
];
4944 /* addr_string has to be used or breakpoint_re_set will delete
4946 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4947 b
->cond_string
= cond_string
[i
];
4948 b
->ignore_count
= ignore_count
;
4949 b
->enable_state
= bp_enabled
;
4950 b
->disposition
= disposition
;
4951 /* If resolving a pending breakpoint, a check must be made to see if
4952 the user has specified a new condition or commands for the
4953 breakpoint. A new condition will override any condition that was
4954 initially specified with the initial breakpoint command. */
4958 if (pending_bp
->cond_string
)
4960 arg
= pending_bp
->cond_string
;
4961 b
->cond_string
= savestring (arg
, strlen (arg
));
4962 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->loc
->address
), 0);
4964 error ("Junk at end of pending breakpoint condition expression");
4966 /* If there are commands associated with the breakpoint, they should
4968 if (pending_bp
->commands
)
4969 b
->commands
= copy_command_lines (pending_bp
->commands
);
4971 /* We have to copy over the ignore_count and thread as well. */
4972 b
->ignore_count
= pending_bp
->ignore_count
;
4973 b
->thread
= pending_bp
->thread
;
4980 /* Parse ARG which is assumed to be a SAL specification possibly
4981 followed by conditionals. On return, SALS contains an array of SAL
4982 addresses found. ADDR_STRING contains a vector of (canonical)
4983 address strings. ARG points to the end of the SAL. */
4986 parse_breakpoint_sals (char **address
,
4987 struct symtabs_and_lines
*sals
,
4988 char ***addr_string
,
4991 char *addr_start
= *address
;
4992 *addr_string
= NULL
;
4993 /* If no arg given, or if first arg is 'if ', use the default
4995 if ((*address
) == NULL
4996 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
4998 if (default_breakpoint_valid
)
5000 struct symtab_and_line sal
;
5001 init_sal (&sal
); /* initialize to zeroes */
5002 sals
->sals
= (struct symtab_and_line
*)
5003 xmalloc (sizeof (struct symtab_and_line
));
5004 sal
.pc
= default_breakpoint_address
;
5005 sal
.line
= default_breakpoint_line
;
5006 sal
.symtab
= default_breakpoint_symtab
;
5007 sal
.section
= find_pc_overlay (sal
.pc
);
5008 sals
->sals
[0] = sal
;
5012 error ("No default breakpoint address now.");
5016 /* Force almost all breakpoints to be in terms of the
5017 current_source_symtab (which is decode_line_1's default). This
5018 should produce the results we want almost all of the time while
5019 leaving default_breakpoint_* alone.
5020 ObjC: However, don't match an Objective-C method name which
5021 may have a '+' or '-' succeeded by a '[' */
5023 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5025 if (default_breakpoint_valid
5027 || ((strchr ("+-", (*address
)[0]) != NULL
)
5028 && ((*address
)[1] != '['))))
5029 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5030 default_breakpoint_line
, addr_string
,
5033 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5034 addr_string
, not_found_ptr
);
5036 /* For any SAL that didn't have a canonical string, fill one in. */
5037 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5038 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5039 if (addr_start
!= (*address
))
5042 for (i
= 0; i
< sals
->nelts
; i
++)
5044 /* Add the string if not present. */
5045 if ((*addr_string
)[i
] == NULL
)
5046 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5052 /* Convert each SAL into a real PC. Verify that the PC can be
5053 inserted as a breakpoint. If it can't throw an error. */
5056 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5060 for (i
= 0; i
< sals
->nelts
; i
++)
5062 resolve_sal_pc (&sals
->sals
[i
]);
5064 /* It's possible for the PC to be nonzero, but still an illegal
5065 value on some targets.
5067 For example, on HP-UX if you start gdb, and before running the
5068 inferior you try to set a breakpoint on a shared library function
5069 "foo" where the inferior doesn't call "foo" directly but does
5070 pass its address to another function call, then we do find a
5071 minimal symbol for the "foo", but it's address is invalid.
5072 (Appears to be an index into a table that the loader sets up
5073 when the inferior is run.)
5075 Give the target a chance to bless sals.sals[i].pc before we
5076 try to make a breakpoint for it. */
5077 #ifdef DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE
5078 if (DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE (sals
->sals
[i
].pc
))
5080 if (address
== NULL
)
5081 error ("Cannot break without a running program.");
5083 error ("Cannot break on %s without a running program.",
5091 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5093 struct captured_parse_breakpoint_args
*args
= data
;
5095 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5096 args
->not_found_ptr
);
5101 /* Set a breakpoint according to ARG (function, linenum or *address)
5102 flag: first bit : 0 non-temporary, 1 temporary.
5103 second bit : 0 normal breakpoint, 1 hardware breakpoint.
5105 PENDING_BP is non-NULL when this function is being called to resolve
5106 a pending breakpoint. */
5109 break_command_1 (char *arg
, int flag
, int from_tty
, struct breakpoint
*pending_bp
)
5111 int tempflag
, hardwareflag
;
5112 struct symtabs_and_lines sals
;
5113 struct expression
**cond
= 0;
5114 struct symtab_and_line pending_sal
;
5115 char **cond_string
= (char **) NULL
;
5118 char *addr_start
= arg
;
5120 struct cleanup
*old_chain
;
5121 struct cleanup
*breakpoint_chain
= NULL
;
5122 struct captured_parse_breakpoint_args parse_args
;
5126 int ignore_count
= 0;
5129 hardwareflag
= flag
& BP_HARDWAREFLAG
;
5130 tempflag
= flag
& BP_TEMPFLAG
;
5136 parse_args
.arg_p
= &arg
;
5137 parse_args
.sals_p
= &sals
;
5138 parse_args
.addr_string_p
= &addr_string
;
5139 parse_args
.not_found_ptr
= ¬_found
;
5141 rc
= catch_exceptions_with_msg (uiout
, do_captured_parse_breakpoint
,
5142 &parse_args
, NULL
, &err_msg
,
5145 /* If caller is interested in rc value from parse, set value. */
5147 if (rc
!= GDB_RC_OK
)
5149 /* Check for file or function not found. */
5152 /* If called to resolve pending breakpoint, just return error code. */
5156 error_output_message (NULL
, err_msg
);
5159 /* If pending breakpoint support is turned off, throw error. */
5161 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5162 throw_exception (RETURN_ERROR
);
5164 /* If pending breakpoint support is auto query and the user selects
5165 no, then simply return the error code. */
5166 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5167 !nquery ("Make breakpoint pending on future shared library load? "))
5170 /* At this point, either the user was queried about setting a
5171 pending breakpoint and selected yes, or pending breakpoint
5172 behavior is on and thus a pending breakpoint is defaulted
5173 on behalf of the user. */
5174 copy_arg
= xstrdup (addr_start
);
5175 addr_string
= ©_arg
;
5177 sals
.sals
= &pending_sal
;
5184 else if (!sals
.nelts
)
5187 /* Create a chain of things that always need to be cleaned up. */
5188 old_chain
= make_cleanup (null_cleanup
, 0);
5192 /* Make sure that all storage allocated to SALS gets freed. */
5193 make_cleanup (xfree
, sals
.sals
);
5195 /* Cleanup the addr_string array but not its contents. */
5196 make_cleanup (xfree
, addr_string
);
5199 /* Allocate space for all the cond expressions. */
5200 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5201 make_cleanup (xfree
, cond
);
5203 /* Allocate space for all the cond strings. */
5204 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
5205 make_cleanup (xfree
, cond_string
);
5207 /* ----------------------------- SNIP -----------------------------
5208 Anything added to the cleanup chain beyond this point is assumed
5209 to be part of a breakpoint. If the breakpoint create succeeds
5210 then the memory is not reclaimed. */
5211 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5213 /* Mark the contents of the addr_string for cleanup. These go on
5214 the breakpoint_chain and only occure if the breakpoint create
5216 for (i
= 0; i
< sals
.nelts
; i
++)
5218 if (addr_string
[i
] != NULL
)
5219 make_cleanup (xfree
, addr_string
[i
]);
5222 /* Resolve all line numbers to PC's and verify that the addresses
5223 are ok for the target. */
5225 breakpoint_sals_to_pc (&sals
, addr_start
);
5227 /* Verify that condition can be parsed, before setting any
5228 breakpoints. Allocate a separate condition expression for each
5230 thread
= -1; /* No specific thread yet */
5233 for (i
= 0; i
< sals
.nelts
; i
++)
5240 char *cond_start
= NULL
;
5241 char *cond_end
= NULL
;
5242 while (*tok
== ' ' || *tok
== '\t')
5247 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5250 toklen
= end_tok
- tok
;
5252 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5254 tok
= cond_start
= end_tok
+ 1;
5255 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
),
5257 make_cleanup (xfree
, cond
[i
]);
5259 cond_string
[i
] = savestring (cond_start
,
5260 cond_end
- cond_start
);
5261 make_cleanup (xfree
, cond_string
[i
]);
5263 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5269 thread
= strtol (tok
, &tok
, 0);
5271 error ("Junk after thread keyword.");
5272 if (!valid_thread_id (thread
))
5273 error ("Unknown thread %d\n", thread
);
5276 error ("Junk at end of arguments.");
5279 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
5280 hardwareflag
? bp_hardware_breakpoint
5282 tempflag
? disp_del
: disp_donttouch
,
5283 thread
, ignore_count
, from_tty
,
5288 struct symtab_and_line sal
;
5289 struct breakpoint
*b
;
5294 make_cleanup (xfree
, copy_arg
);
5296 b
= set_raw_breakpoint (sal
, hardwareflag
? bp_hardware_breakpoint
5298 set_breakpoint_count (breakpoint_count
+ 1);
5299 b
->number
= breakpoint_count
;
5302 b
->addr_string
= *addr_string
;
5303 b
->cond_string
= *cond_string
;
5304 b
->ignore_count
= ignore_count
;
5306 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5307 b
->from_tty
= from_tty
;
5314 warning ("Multiple breakpoints were set.");
5315 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5317 /* That's it. Discard the cleanups for data inserted into the
5319 discard_cleanups (breakpoint_chain
);
5320 /* But cleanup everything else. */
5321 do_cleanups (old_chain
);
5326 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5327 linenum or *address) with COND and IGNORE_COUNT. */
5329 struct captured_breakpoint_args
5340 do_captured_breakpoint (void *data
)
5342 struct captured_breakpoint_args
*args
= data
;
5343 struct symtabs_and_lines sals
;
5344 struct expression
**cond
;
5345 struct cleanup
*old_chain
;
5346 struct cleanup
*breakpoint_chain
= NULL
;
5353 /* Parse the source and lines spec. Delay check that the expression
5354 didn't contain trailing garbage until after cleanups are in
5358 address_end
= args
->address
;
5360 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
, 0);
5365 /* Create a chain of things at always need to be cleaned up. */
5366 old_chain
= make_cleanup (null_cleanup
, 0);
5368 /* Always have a addr_string array, even if it is empty. */
5369 make_cleanup (xfree
, addr_string
);
5371 /* Make sure that all storage allocated to SALS gets freed. */
5372 make_cleanup (xfree
, sals
.sals
);
5374 /* Allocate space for all the cond expressions. */
5375 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5376 make_cleanup (xfree
, cond
);
5378 /* Allocate space for all the cond strings. */
5379 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
5380 make_cleanup (xfree
, cond_string
);
5382 /* ----------------------------- SNIP -----------------------------
5383 Anything added to the cleanup chain beyond this point is assumed
5384 to be part of a breakpoint. If the breakpoint create goes
5385 through then that memory is not cleaned up. */
5386 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5388 /* Mark the contents of the addr_string for cleanup. These go on
5389 the breakpoint_chain and only occure if the breakpoint create
5391 for (i
= 0; i
< sals
.nelts
; i
++)
5393 if (addr_string
[i
] != NULL
)
5394 make_cleanup (xfree
, addr_string
[i
]);
5397 /* Wait until now before checking for garbage at the end of the
5398 address. That way cleanups can take care of freeing any
5400 if (*address_end
!= '\0')
5401 error ("Garbage %s following breakpoint address", address_end
);
5403 /* Resolve all line numbers to PC's. */
5404 breakpoint_sals_to_pc (&sals
, args
->address
);
5406 /* Verify that conditions can be parsed, before setting any
5408 for (i
= 0; i
< sals
.nelts
; i
++)
5410 if (args
->condition
!= NULL
)
5412 char *tok
= args
->condition
;
5413 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
5415 error ("Garbage %s follows condition", tok
);
5416 make_cleanup (xfree
, cond
[i
]);
5417 cond_string
[i
] = xstrdup (args
->condition
);
5421 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
5422 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
5423 args
->tempflag
? disp_del
: disp_donttouch
,
5424 args
->thread
, args
->ignore_count
, 0/*from-tty*/,
5425 NULL
/*pending_bp*/);
5427 /* That's it. Discard the cleanups for data inserted into the
5429 discard_cleanups (breakpoint_chain
);
5430 /* But cleanup everything else. */
5431 do_cleanups (old_chain
);
5436 gdb_breakpoint (char *address
, char *condition
,
5437 int hardwareflag
, int tempflag
,
5438 int thread
, int ignore_count
)
5440 struct captured_breakpoint_args args
;
5441 args
.address
= address
;
5442 args
.condition
= condition
;
5443 args
.hardwareflag
= hardwareflag
;
5444 args
.tempflag
= tempflag
;
5445 args
.thread
= thread
;
5446 args
.ignore_count
= ignore_count
;
5447 return catch_errors (do_captured_breakpoint
, &args
,
5448 NULL
, RETURN_MASK_ALL
);
5453 break_at_finish_at_depth_command_1 (char *arg
, int flag
, int from_tty
)
5455 struct frame_info
*frame
;
5456 CORE_ADDR low
, high
, selected_pc
= 0;
5457 char *extra_args
= NULL
;
5459 int extra_args_len
= 0, if_arg
= 0;
5462 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
5465 if (default_breakpoint_valid
)
5467 if (deprecated_selected_frame
)
5469 selected_pc
= get_frame_pc (deprecated_selected_frame
);
5474 error ("No selected frame.");
5477 error ("No default breakpoint address now.");
5481 extra_args
= strchr (arg
, ' ');
5485 extra_args_len
= strlen (extra_args
);
5486 level_arg
= (char *) xmalloc (extra_args
- arg
);
5487 strncpy (level_arg
, arg
, extra_args
- arg
- 1);
5488 level_arg
[extra_args
- arg
- 1] = '\0';
5492 level_arg
= (char *) xmalloc (strlen (arg
) + 1);
5493 strcpy (level_arg
, arg
);
5496 frame
= parse_frame_specification (level_arg
);
5498 selected_pc
= get_frame_pc (frame
);
5505 extra_args_len
= strlen (arg
);
5510 if (find_pc_partial_function (selected_pc
, (char **) NULL
, &low
, &high
))
5514 addr_string
= xstrprintf ("*0x%s %s", paddr_nz (high
), extra_args
);
5516 addr_string
= xstrprintf ("*0x%s", paddr_nz (high
));
5517 break_command_1 (addr_string
, flag
, from_tty
, NULL
);
5518 xfree (addr_string
);
5521 error ("No function contains the specified address");
5524 error ("Unable to set breakpoint at procedure exit");
5529 break_at_finish_command_1 (char *arg
, int flag
, int from_tty
)
5531 char *addr_string
, *break_string
, *beg_addr_string
;
5532 CORE_ADDR low
, high
;
5533 struct symtabs_and_lines sals
;
5534 struct symtab_and_line sal
;
5535 struct cleanup
*old_chain
;
5536 char *extra_args
= NULL
;
5537 int extra_args_len
= 0;
5541 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
5543 if (default_breakpoint_valid
)
5545 if (deprecated_selected_frame
)
5547 addr_string
= xstrprintf ("*0x%s",
5548 paddr_nz (get_frame_pc (deprecated_selected_frame
)));
5553 error ("No selected frame.");
5556 error ("No default breakpoint address now.");
5560 addr_string
= (char *) xmalloc (strlen (arg
) + 1);
5561 strcpy (addr_string
, arg
);
5567 extra_args_len
= strlen (arg
);
5571 /* get the stuff after the function name or address */
5572 extra_args
= strchr (arg
, ' ');
5576 extra_args_len
= strlen (extra_args
);
5583 beg_addr_string
= addr_string
;
5584 sals
= decode_line_1 (&addr_string
, 1, (struct symtab
*) NULL
, 0,
5585 (char ***) NULL
, NULL
);
5587 xfree (beg_addr_string
);
5588 old_chain
= make_cleanup (xfree
, sals
.sals
);
5589 for (i
= 0; (i
< sals
.nelts
); i
++)
5592 if (find_pc_partial_function (sal
.pc
, (char **) NULL
, &low
, &high
))
5596 break_string
= xstrprintf ("*0x%s %s", paddr_nz (high
),
5599 break_string
= xstrprintf ("*0x%s", paddr_nz (high
));
5600 break_command_1 (break_string
, flag
, from_tty
, NULL
);
5601 xfree (break_string
);
5604 error ("No function contains the specified address");
5608 warning ("Multiple breakpoints were set.\n");
5609 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5611 do_cleanups (old_chain
);
5615 /* Helper function for break_command_1 and disassemble_command. */
5618 resolve_sal_pc (struct symtab_and_line
*sal
)
5622 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5624 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5625 error ("No line %d in file \"%s\".",
5626 sal
->line
, sal
->symtab
->filename
);
5630 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5632 struct blockvector
*bv
;
5637 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5640 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5641 sym
= block_function (b
);
5644 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5645 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5649 /* It really is worthwhile to have the section, so we'll just
5650 have to look harder. This case can be executed if we have
5651 line numbers but no functions (as can happen in assembly
5654 struct minimal_symbol
*msym
;
5656 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5658 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5665 break_command (char *arg
, int from_tty
)
5667 break_command_1 (arg
, 0, from_tty
, NULL
);
5671 break_at_finish_command (char *arg
, int from_tty
)
5673 break_at_finish_command_1 (arg
, 0, from_tty
);
5677 break_at_finish_at_depth_command (char *arg
, int from_tty
)
5679 break_at_finish_at_depth_command_1 (arg
, 0, from_tty
);
5683 tbreak_command (char *arg
, int from_tty
)
5685 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
, NULL
);
5689 tbreak_at_finish_command (char *arg
, int from_tty
)
5691 break_at_finish_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5695 hbreak_command (char *arg
, int from_tty
)
5697 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
, NULL
);
5701 thbreak_command (char *arg
, int from_tty
)
5703 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
, NULL
);
5707 stop_command (char *arg
, int from_tty
)
5709 printf_filtered ("Specify the type of breakpoint to set.\n\
5710 Usage: stop in <function | address>\n\
5715 stopin_command (char *arg
, int from_tty
)
5719 if (arg
== (char *) NULL
)
5721 else if (*arg
!= '*')
5726 /* look for a ':'. If this is a line number specification, then
5727 say it is bad, otherwise, it should be an address or
5728 function/method name */
5729 while (*argptr
&& !hasColon
)
5731 hasColon
= (*argptr
== ':');
5736 badInput
= (*argptr
!= ':'); /* Not a class::method */
5738 badInput
= isdigit (*arg
); /* a simple line number */
5742 printf_filtered ("Usage: stop in <function | address>\n");
5744 break_command_1 (arg
, 0, from_tty
, NULL
);
5748 stopat_command (char *arg
, int from_tty
)
5752 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5759 /* look for a ':'. If there is a '::' then get out, otherwise
5760 it is probably a line number. */
5761 while (*argptr
&& !hasColon
)
5763 hasColon
= (*argptr
== ':');
5768 badInput
= (*argptr
== ':'); /* we have class::method */
5770 badInput
= !isdigit (*arg
); /* not a line number */
5774 printf_filtered ("Usage: stop at <line>\n");
5776 break_command_1 (arg
, 0, from_tty
, NULL
);
5779 /* accessflag: hw_write: watch write,
5780 hw_read: watch read,
5781 hw_access: watch access (read or write) */
5783 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5785 struct breakpoint
*b
;
5786 struct symtab_and_line sal
;
5787 struct expression
*exp
;
5788 struct block
*exp_valid_block
;
5789 struct value
*val
, *mark
;
5790 struct frame_info
*frame
;
5791 struct frame_info
*prev_frame
= NULL
;
5792 char *exp_start
= NULL
;
5793 char *exp_end
= NULL
;
5794 char *tok
, *end_tok
;
5796 char *cond_start
= NULL
;
5797 char *cond_end
= NULL
;
5798 struct expression
*cond
= NULL
;
5799 int i
, other_type_used
, target_resources_ok
= 0;
5800 enum bptype bp_type
;
5803 init_sal (&sal
); /* initialize to zeroes */
5805 /* Parse arguments. */
5806 innermost_block
= NULL
;
5808 exp
= parse_exp_1 (&arg
, 0, 0);
5810 exp_valid_block
= innermost_block
;
5811 mark
= value_mark ();
5812 val
= evaluate_expression (exp
);
5813 release_value (val
);
5814 if (VALUE_LAZY (val
))
5815 value_fetch_lazy (val
);
5818 while (*tok
== ' ' || *tok
== '\t')
5822 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5825 toklen
= end_tok
- tok
;
5826 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5828 tok
= cond_start
= end_tok
+ 1;
5829 cond
= parse_exp_1 (&tok
, 0, 0);
5833 error ("Junk at end of command.");
5835 if (accessflag
== hw_read
)
5836 bp_type
= bp_read_watchpoint
;
5837 else if (accessflag
== hw_access
)
5838 bp_type
= bp_access_watchpoint
;
5840 bp_type
= bp_hardware_watchpoint
;
5842 mem_cnt
= can_use_hardware_watchpoint (val
);
5843 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5844 error ("Expression cannot be implemented with read/access watchpoint.");
5847 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5848 target_resources_ok
=
5849 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5851 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5852 error ("Target does not support this type of hardware watchpoint.");
5854 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5855 error ("Target can only support one kind of HW watchpoint at a time.");
5858 #if defined(HPUXHPPA)
5859 /* On HP-UX if you set a h/w
5860 watchpoint before the "run" command, the inferior dies with a e.g.,
5861 SIGILL once you start it. I initially believed this was due to a
5862 bad interaction between page protection traps and the initial
5863 startup sequence by the dynamic linker.
5865 However, I tried avoiding that by having HP-UX's implementation of
5866 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5867 yet, which forced slow watches before a "run" or "attach", and it
5868 still fails somewhere in the startup code.
5870 Until I figure out what's happening, I'm disallowing watches altogether
5871 before the "run" or "attach" command. We'll tell the user they must
5872 set watches after getting the program started. */
5873 if (!target_has_execution
)
5875 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5878 #endif /* HPUXHPPA */
5880 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5881 watchpoint could not be set. */
5882 if (!mem_cnt
|| target_resources_ok
<= 0)
5883 bp_type
= bp_watchpoint
;
5885 /* Now set up the breakpoint. */
5886 b
= set_raw_breakpoint (sal
, bp_type
);
5887 set_breakpoint_count (breakpoint_count
+ 1);
5888 b
->number
= breakpoint_count
;
5889 b
->disposition
= disp_donttouch
;
5891 b
->exp_valid_block
= exp_valid_block
;
5892 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5896 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5900 frame
= block_innermost_frame (exp_valid_block
);
5903 prev_frame
= get_prev_frame (frame
);
5904 b
->watchpoint_frame
= get_frame_id (frame
);
5908 memset (&b
->watchpoint_frame
, 0, sizeof (b
->watchpoint_frame
));
5911 /* If the expression is "local", then set up a "watchpoint scope"
5912 breakpoint at the point where we've left the scope of the watchpoint
5914 if (innermost_block
)
5918 struct breakpoint
*scope_breakpoint
;
5919 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5920 bp_watchpoint_scope
);
5922 scope_breakpoint
->enable_state
= bp_enabled
;
5924 /* Automatically delete the breakpoint when it hits. */
5925 scope_breakpoint
->disposition
= disp_del
;
5927 /* Only break in the proper frame (help with recursion). */
5928 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5930 /* Set the address at which we will stop. */
5931 scope_breakpoint
->loc
->requested_address
5932 = get_frame_pc (prev_frame
);
5933 scope_breakpoint
->loc
->address
5934 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5935 scope_breakpoint
->type
);
5937 /* The scope breakpoint is related to the watchpoint. We
5938 will need to act on them together. */
5939 b
->related_breakpoint
= scope_breakpoint
;
5942 value_free_to_mark (mark
);
5946 /* Return count of locations need to be watched and can be handled
5947 in hardware. If the watchpoint can not be handled
5948 in hardware return zero. */
5950 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5951 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5952 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5956 can_use_hardware_watchpoint (struct value
*v
)
5958 int found_memory_cnt
= 0;
5959 struct value
*head
= v
;
5961 /* Did the user specifically forbid us to use hardware watchpoints? */
5962 if (!can_use_hw_watchpoints
)
5965 /* Make sure that the value of the expression depends only upon
5966 memory contents, and values computed from them within GDB. If we
5967 find any register references or function calls, we can't use a
5968 hardware watchpoint.
5970 The idea here is that evaluating an expression generates a series
5971 of values, one holding the value of every subexpression. (The
5972 expression a*b+c has five subexpressions: a, b, a*b, c, and
5973 a*b+c.) GDB's values hold almost enough information to establish
5974 the criteria given above --- they identify memory lvalues,
5975 register lvalues, computed values, etcetera. So we can evaluate
5976 the expression, and then scan the chain of values that leaves
5977 behind to decide whether we can detect any possible change to the
5978 expression's final value using only hardware watchpoints.
5980 However, I don't think that the values returned by inferior
5981 function calls are special in any way. So this function may not
5982 notice that an expression involving an inferior function call
5983 can't be watched with hardware watchpoints. FIXME. */
5984 for (; v
; v
= v
->next
)
5986 if (VALUE_LVAL (v
) == lval_memory
)
5989 /* A lazy memory lvalue is one that GDB never needed to fetch;
5990 we either just used its address (e.g., `a' in `a.b') or
5991 we never needed it at all (e.g., `a' in `a,b'). */
5995 /* Ahh, memory we actually used! Check if we can cover
5996 it with hardware watchpoints. */
5997 struct type
*vtype
= check_typedef (value_type (v
));
5999 /* We only watch structs and arrays if user asked for it
6000 explicitly, never if they just happen to appear in a
6001 middle of some value chain. */
6003 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6004 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6006 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6007 int len
= TYPE_LENGTH (value_type (v
));
6009 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6016 else if (v
->lval
!= not_lval
&& v
->modifiable
== 0)
6017 return 0; /* ??? What does this represent? */
6018 else if (v
->lval
== lval_register
)
6019 return 0; /* cannot watch a register with a HW watchpoint */
6022 /* The expression itself looks suitable for using a hardware
6023 watchpoint, but give the target machine a chance to reject it. */
6024 return found_memory_cnt
;
6028 watch_command_wrapper (char *arg
, int from_tty
)
6030 watch_command (arg
, from_tty
);
6034 watch_command (char *arg
, int from_tty
)
6036 watch_command_1 (arg
, hw_write
, from_tty
);
6040 rwatch_command_wrapper (char *arg
, int from_tty
)
6042 rwatch_command (arg
, from_tty
);
6046 rwatch_command (char *arg
, int from_tty
)
6048 watch_command_1 (arg
, hw_read
, from_tty
);
6052 awatch_command_wrapper (char *arg
, int from_tty
)
6054 awatch_command (arg
, from_tty
);
6058 awatch_command (char *arg
, int from_tty
)
6060 watch_command_1 (arg
, hw_access
, from_tty
);
6064 /* Helper routines for the until_command routine in infcmd.c. Here
6065 because it uses the mechanisms of breakpoints. */
6067 /* This function is called by fetch_inferior_event via the
6068 cmd_continuation pointer, to complete the until command. It takes
6069 care of cleaning up the temporary breakpoints set up by the until
6072 until_break_command_continuation (struct continuation_arg
*arg
)
6074 struct cleanup
*cleanups
;
6076 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
6077 do_exec_cleanups (cleanups
);
6081 until_break_command (char *arg
, int from_tty
, int anywhere
)
6083 struct symtabs_and_lines sals
;
6084 struct symtab_and_line sal
;
6085 struct frame_info
*prev_frame
= get_prev_frame (deprecated_selected_frame
);
6086 struct breakpoint
*breakpoint
;
6087 struct cleanup
*old_chain
;
6088 struct continuation_arg
*arg1
;
6091 clear_proceed_status ();
6093 /* Set a breakpoint where the user wants it and at return from
6096 if (default_breakpoint_valid
)
6097 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6098 default_breakpoint_line
, (char ***) NULL
, NULL
);
6100 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6101 0, (char ***) NULL
, NULL
);
6103 if (sals
.nelts
!= 1)
6104 error ("Couldn't get information on specified line.");
6107 xfree (sals
.sals
); /* malloc'd, so freed */
6110 error ("Junk at end of arguments.");
6112 resolve_sal_pc (&sal
);
6115 /* If the user told us to continue until a specified location,
6116 we don't specify a frame at which we need to stop. */
6117 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6119 /* Otherwise, specify the current frame, because we want to stop only
6120 at the very same frame. */
6121 breakpoint
= set_momentary_breakpoint (sal
,
6122 get_frame_id (deprecated_selected_frame
),
6125 if (!target_can_async_p ())
6126 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6128 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
6130 /* If we are running asynchronously, and the target supports async
6131 execution, we are not waiting for the target to stop, in the call
6132 tp proceed, below. This means that we cannot delete the
6133 brekpoints until the target has actually stopped. The only place
6134 where we get a chance to do that is in fetch_inferior_event, so
6135 we must set things up for that. */
6137 if (target_can_async_p ())
6139 /* In this case the arg for the continuation is just the point
6140 in the exec_cleanups chain from where to start doing
6141 cleanups, because all the continuation does is the cleanups in
6142 the exec_cleanup_chain. */
6144 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
6146 arg1
->data
.pointer
= old_chain
;
6148 add_continuation (until_break_command_continuation
, arg1
);
6151 /* Keep within the current frame, or in frames called by the current
6155 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6156 sal
.pc
= get_frame_pc (prev_frame
);
6157 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6159 if (!target_can_async_p ())
6160 make_cleanup_delete_breakpoint (breakpoint
);
6162 make_exec_cleanup_delete_breakpoint (breakpoint
);
6165 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6166 /* Do the cleanups now, anly if we are not running asynchronously,
6167 of if we are, but the target is still synchronous. */
6168 if (!target_can_async_p ())
6169 do_cleanups (old_chain
);
6173 ep_skip_leading_whitespace (char **s
)
6175 if ((s
== NULL
) || (*s
== NULL
))
6177 while (isspace (**s
))
6181 /* This function examines a string, and attempts to find a token
6182 that might be an event name in the leading characters. If a
6183 possible match is found, a pointer to the last character of
6184 the token is returned. Else, NULL is returned. */
6187 ep_find_event_name_end (char *arg
)
6190 char *event_name_end
= NULL
;
6192 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6196 /* We break out of the loop when we find a token delimiter.
6197 Basically, we're looking for alphanumerics and underscores;
6198 anything else delimites the token. */
6201 if (!isalnum (*s
) && (*s
!= '_'))
6207 return event_name_end
;
6211 /* This function attempts to parse an optional "if <cond>" clause
6212 from the arg string. If one is not found, it returns NULL.
6214 Else, it returns a pointer to the condition string. (It does not
6215 attempt to evaluate the string against a particular block.) And,
6216 it updates arg to point to the first character following the parsed
6217 if clause in the arg string. */
6220 ep_parse_optional_if_clause (char **arg
)
6224 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6227 /* Skip the "if" keyword. */
6230 /* Skip any extra leading whitespace, and record the start of the
6231 condition string. */
6232 ep_skip_leading_whitespace (arg
);
6235 /* Assume that the condition occupies the remainder of the arg string. */
6236 (*arg
) += strlen (cond_string
);
6241 /* This function attempts to parse an optional filename from the arg
6242 string. If one is not found, it returns NULL.
6244 Else, it returns a pointer to the parsed filename. (This function
6245 makes no attempt to verify that a file of that name exists, or is
6246 accessible.) And, it updates arg to point to the first character
6247 following the parsed filename in the arg string.
6249 Note that clients needing to preserve the returned filename for
6250 future access should copy it to their own buffers. */
6252 ep_parse_optional_filename (char **arg
)
6254 static char filename
[1024];
6259 if ((*arg_p
== '\0') || isspace (*arg_p
))
6277 /* Commands to deal with catching events, such as signals, exceptions,
6278 process start/exit, etc. */
6282 catch_fork
, catch_vfork
6287 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6290 char *cond_string
= NULL
;
6292 ep_skip_leading_whitespace (&arg
);
6294 /* The allowed syntax is:
6296 catch [v]fork if <cond>
6298 First, check if there's an if clause. */
6299 cond_string
= ep_parse_optional_if_clause (&arg
);
6301 if ((*arg
!= '\0') && !isspace (*arg
))
6302 error ("Junk at end of arguments.");
6304 /* If this target supports it, create a fork or vfork catchpoint
6305 and enable reporting of such events. */
6309 create_fork_event_catchpoint (tempflag
, cond_string
);
6312 create_vfork_event_catchpoint (tempflag
, cond_string
);
6315 error ("unsupported or unknown fork kind; cannot catch it");
6321 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6323 char *cond_string
= NULL
;
6325 ep_skip_leading_whitespace (&arg
);
6327 /* The allowed syntax is:
6329 catch exec if <cond>
6331 First, check if there's an if clause. */
6332 cond_string
= ep_parse_optional_if_clause (&arg
);
6334 if ((*arg
!= '\0') && !isspace (*arg
))
6335 error ("Junk at end of arguments.");
6337 /* If this target supports it, create an exec catchpoint
6338 and enable reporting of such events. */
6339 create_exec_event_catchpoint (tempflag
, cond_string
);
6343 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6345 char *dll_pathname
= NULL
;
6346 char *cond_string
= NULL
;
6348 ep_skip_leading_whitespace (&arg
);
6350 /* The allowed syntax is:
6352 catch load if <cond>
6353 catch load <filename>
6354 catch load <filename> if <cond>
6356 The user is not allowed to specify the <filename> after an
6359 We'll ignore the pathological case of a file named "if".
6361 First, check if there's an if clause. If so, then there
6362 cannot be a filename. */
6363 cond_string
= ep_parse_optional_if_clause (&arg
);
6365 /* If there was an if clause, then there cannot be a filename.
6366 Else, there might be a filename and an if clause. */
6367 if (cond_string
== NULL
)
6369 dll_pathname
= ep_parse_optional_filename (&arg
);
6370 ep_skip_leading_whitespace (&arg
);
6371 cond_string
= ep_parse_optional_if_clause (&arg
);
6374 if ((*arg
!= '\0') && !isspace (*arg
))
6375 error ("Junk at end of arguments.");
6377 /* Create a load breakpoint that only triggers when a load of
6378 the specified dll (or any dll, if no pathname was specified)
6380 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6381 dll_pathname
, cond_string
);
6385 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6387 char *dll_pathname
= NULL
;
6388 char *cond_string
= NULL
;
6390 ep_skip_leading_whitespace (&arg
);
6392 /* The allowed syntax is:
6394 catch unload if <cond>
6395 catch unload <filename>
6396 catch unload <filename> if <cond>
6398 The user is not allowed to specify the <filename> after an
6401 We'll ignore the pathological case of a file named "if".
6403 First, check if there's an if clause. If so, then there
6404 cannot be a filename. */
6405 cond_string
= ep_parse_optional_if_clause (&arg
);
6407 /* If there was an if clause, then there cannot be a filename.
6408 Else, there might be a filename and an if clause. */
6409 if (cond_string
== NULL
)
6411 dll_pathname
= ep_parse_optional_filename (&arg
);
6412 ep_skip_leading_whitespace (&arg
);
6413 cond_string
= ep_parse_optional_if_clause (&arg
);
6416 if ((*arg
!= '\0') && !isspace (*arg
))
6417 error ("Junk at end of arguments.");
6419 /* Create an unload breakpoint that only triggers when an unload of
6420 the specified dll (or any dll, if no pathname was specified)
6422 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6423 dll_pathname
, cond_string
);
6426 /* Commands to deal with catching exceptions. */
6428 /* Set a breakpoint at the specified callback routine for an
6429 exception event callback */
6432 create_exception_catchpoint (int tempflag
, char *cond_string
,
6433 enum exception_event_kind ex_event
,
6434 struct symtab_and_line
*sal
)
6436 struct breakpoint
*b
;
6437 int thread
= -1; /* All threads. */
6440 if (!sal
) /* no exception support? */
6445 case EX_EVENT_THROW
:
6446 bptype
= bp_catch_throw
;
6448 case EX_EVENT_CATCH
:
6449 bptype
= bp_catch_catch
;
6451 default: /* error condition */
6452 error ("Internal error -- invalid catchpoint kind");
6455 b
= set_raw_breakpoint (*sal
, bptype
);
6456 set_breakpoint_count (breakpoint_count
+ 1);
6457 b
->number
= breakpoint_count
;
6459 b
->cond_string
= (cond_string
== NULL
) ?
6460 NULL
: savestring (cond_string
, strlen (cond_string
));
6462 b
->addr_string
= NULL
;
6463 b
->enable_state
= bp_enabled
;
6464 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6468 static enum print_stop_action
6469 print_exception_catchpoint (struct breakpoint
*b
)
6471 annotate_catchpoint (b
->number
);
6473 if (strstr (b
->addr_string
, "throw") != NULL
)
6474 printf_filtered ("\nCatchpoint %d (exception thrown)\n",
6477 printf_filtered ("\nCatchpoint %d (exception caught)\n",
6480 return PRINT_SRC_AND_LOC
;
6484 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6489 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6492 *last_addr
= b
->loc
->address
;
6493 if (strstr (b
->addr_string
, "throw") != NULL
)
6494 ui_out_field_string (uiout
, "what", "exception throw");
6496 ui_out_field_string (uiout
, "what", "exception catch");
6500 print_mention_exception_catchpoint (struct breakpoint
*b
)
6502 if (strstr (b
->addr_string
, "throw") != NULL
)
6503 printf_filtered ("Catchpoint %d (throw)", b
->number
);
6505 printf_filtered ("Catchpoint %d (catch)", b
->number
);
6508 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6509 print_exception_catchpoint
,
6510 print_one_exception_catchpoint
,
6511 print_mention_exception_catchpoint
6515 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6516 enum exception_event_kind ex_event
, int from_tty
)
6518 char *trigger_func_name
, *nameptr
;
6519 struct symtabs_and_lines sals
;
6520 struct breakpoint
*b
;
6522 if (ex_event
== EX_EVENT_CATCH
)
6523 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6525 trigger_func_name
= xstrdup ("__cxa_throw");
6527 nameptr
= trigger_func_name
;
6528 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6529 if (sals
.nelts
== 0)
6531 xfree (trigger_func_name
);
6535 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6536 set_breakpoint_count (breakpoint_count
+ 1);
6537 b
->number
= breakpoint_count
;
6539 b
->cond_string
= (cond_string
== NULL
) ?
6540 NULL
: savestring (cond_string
, strlen (cond_string
));
6542 b
->addr_string
= trigger_func_name
;
6543 b
->enable_state
= bp_enabled
;
6544 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6545 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6552 /* Deal with "catch catch" and "catch throw" commands */
6555 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6556 int tempflag
, int from_tty
)
6558 char *cond_string
= NULL
;
6559 struct symtab_and_line
*sal
= NULL
;
6561 ep_skip_leading_whitespace (&arg
);
6563 cond_string
= ep_parse_optional_if_clause (&arg
);
6565 if ((*arg
!= '\0') && !isspace (*arg
))
6566 error ("Junk at end of arguments.");
6568 if ((ex_event
!= EX_EVENT_THROW
) &&
6569 (ex_event
!= EX_EVENT_CATCH
))
6570 error ("Unsupported or unknown exception event; cannot catch it");
6572 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6575 /* See if we can find a callback routine */
6576 sal
= target_enable_exception_callback (ex_event
, 1);
6580 /* We have callbacks from the runtime system for exceptions.
6581 Set a breakpoint on the sal found, if no errors */
6582 if (sal
!= (struct symtab_and_line
*) -1)
6583 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6585 return; /* something went wrong with setting up callbacks */
6588 warning ("Unsupported with this platform/compiler combination.");
6591 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6592 inside a catch_errors */
6595 cover_target_enable_exception_callback (void *arg
)
6597 args_for_catchpoint_enable
*args
= arg
;
6598 struct symtab_and_line
*sal
;
6599 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6602 else if (sal
== (struct symtab_and_line
*) -1)
6605 return 1; /*is valid */
6609 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6612 /* The first argument may be an event name, such as "start" or "load".
6613 If so, then handle it as such. If it doesn't match an event name,
6614 then attempt to interpret it as an exception name. (This latter is
6615 the v4.16-and-earlier GDB meaning of the "catch" command.)
6617 First, try to find the bounds of what might be an event name. */
6618 char *arg1_start
= arg
;
6622 if (arg1_start
== NULL
)
6624 /* Old behaviour was to use pre-v-4.16 syntax */
6625 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6627 /* Now, this is not allowed */
6628 error ("Catch requires an event name.");
6631 arg1_end
= ep_find_event_name_end (arg1_start
);
6632 if (arg1_end
== NULL
)
6633 error ("catch requires an event");
6634 arg1_length
= arg1_end
+ 1 - arg1_start
;
6636 /* Try to match what we found against known event names. */
6637 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6639 error ("Catch of signal not yet implemented");
6641 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6643 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6644 tempflag
, from_tty
);
6646 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6648 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6649 tempflag
, from_tty
);
6651 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6653 error ("Catch of thread_start not yet implemented");
6655 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6657 error ("Catch of thread_exit not yet implemented");
6659 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6661 error ("Catch of thread_join not yet implemented");
6663 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6665 error ("Catch of start not yet implemented");
6667 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6669 error ("Catch of exit not yet implemented");
6671 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6673 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6675 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6677 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6679 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6681 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6683 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6685 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6687 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6689 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6691 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6693 error ("Catch of stop not yet implemented");
6696 /* This doesn't appear to be an event name */
6700 /* Pre-v.4.16 behaviour was to treat the argument
6701 as the name of an exception */
6702 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6703 /* Now this is not allowed */
6704 error ("Unknown event kind specified for catch");
6709 /* Used by the gui, could be made a worker for other things. */
6712 set_breakpoint_sal (struct symtab_and_line sal
)
6714 struct breakpoint
*b
;
6715 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6716 set_breakpoint_count (breakpoint_count
+ 1);
6717 b
->number
= breakpoint_count
;
6724 catch_command (char *arg
, int from_tty
)
6726 catch_command_1 (arg
, 0, from_tty
);
6731 tcatch_command (char *arg
, int from_tty
)
6733 catch_command_1 (arg
, 1, from_tty
);
6736 /* Delete breakpoints by address or line. */
6739 clear_command (char *arg
, int from_tty
)
6741 struct breakpoint
*b
, *tmp
, *prev
, *found
;
6743 struct symtabs_and_lines sals
;
6744 struct symtab_and_line sal
;
6749 sals
= decode_line_spec (arg
, 1);
6754 sals
.sals
= (struct symtab_and_line
*)
6755 xmalloc (sizeof (struct symtab_and_line
));
6756 make_cleanup (xfree
, sals
.sals
);
6757 init_sal (&sal
); /* initialize to zeroes */
6758 sal
.line
= default_breakpoint_line
;
6759 sal
.symtab
= default_breakpoint_symtab
;
6760 sal
.pc
= default_breakpoint_address
;
6761 if (sal
.symtab
== 0)
6762 error ("No source file specified.");
6770 /* For each line spec given, delete bps which correspond
6771 to it. Do it in two passes, solely to preserve the current
6772 behavior that from_tty is forced true if we delete more than
6776 for (i
= 0; i
< sals
.nelts
; i
++)
6778 /* If exact pc given, clear bpts at that pc.
6779 If line given (pc == 0), clear all bpts on specified line.
6780 If defaulting, clear all bpts on default line
6783 defaulting sal.pc != 0 tests to do
6788 1 0 <can't happen> */
6793 /* Find all matching breakpoints, remove them from the
6794 breakpoint chain, and add them to the 'found' chain. */
6795 ALL_BREAKPOINTS_SAFE (b
, tmp
)
6797 /* Are we going to delete b? */
6798 if (b
->type
!= bp_none
6799 && b
->type
!= bp_watchpoint
6800 && b
->type
!= bp_hardware_watchpoint
6801 && b
->type
!= bp_read_watchpoint
6802 && b
->type
!= bp_access_watchpoint
6803 /* Not if b is a watchpoint of any sort... */
6804 && (((sal
.pc
&& (b
->loc
->address
== sal
.pc
))
6805 && (!section_is_overlay (b
->loc
->section
)
6806 || b
->loc
->section
== sal
.section
))
6807 /* Yes, if sal.pc matches b (modulo overlays). */
6808 || ((default_match
|| (0 == sal
.pc
))
6809 && b
->source_file
!= NULL
6810 && sal
.symtab
!= NULL
6811 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6812 && b
->line_number
== sal
.line
)))
6813 /* Yes, if sal source file and line matches b. */
6815 /* Remove it from breakpoint_chain... */
6816 if (b
== breakpoint_chain
)
6818 /* b is at the head of the list */
6819 breakpoint_chain
= b
->next
;
6823 prev
->next
= b
->next
;
6825 /* And add it to 'found' chain. */
6831 /* Keep b, and keep a pointer to it. */
6836 /* Now go thru the 'found' chain and delete them. */
6840 error ("No breakpoint at %s.", arg
);
6842 error ("No breakpoint at this line.");
6846 from_tty
= 1; /* Always report if deleted more than one */
6848 printf_unfiltered ("Deleted breakpoint%s ", found
->next
? "s" : "");
6849 breakpoints_changed ();
6853 printf_unfiltered ("%d ", found
->number
);
6855 delete_breakpoint (found
);
6859 putchar_unfiltered ('\n');
6862 /* Delete breakpoint in BS if they are `delete' breakpoints and
6863 all breakpoints that are marked for deletion, whether hit or not.
6864 This is called after any breakpoint is hit, or after errors. */
6867 breakpoint_auto_delete (bpstat bs
)
6869 struct breakpoint
*b
, *temp
;
6871 for (; bs
; bs
= bs
->next
)
6872 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== disp_del
6874 delete_breakpoint (bs
->breakpoint_at
);
6876 ALL_BREAKPOINTS_SAFE (b
, temp
)
6878 if (b
->disposition
== disp_del_at_next_stop
)
6879 delete_breakpoint (b
);
6883 /* Delete a breakpoint and clean up all traces of it in the data
6887 delete_breakpoint (struct breakpoint
*bpt
)
6889 struct breakpoint
*b
;
6891 struct bp_location
*loc
;
6894 error ("Internal error (attempted to delete a NULL breakpoint)");
6897 /* Has this bp already been deleted? This can happen because multiple
6898 lists can hold pointers to bp's. bpstat lists are especial culprits.
6900 One example of this happening is a watchpoint's scope bp. When the
6901 scope bp triggers, we notice that the watchpoint is out of scope, and
6902 delete it. We also delete its scope bp. But the scope bp is marked
6903 "auto-deleting", and is already on a bpstat. That bpstat is then
6904 checked for auto-deleting bp's, which are deleted.
6906 A real solution to this problem might involve reference counts in bp's,
6907 and/or giving them pointers back to their referencing bpstat's, and
6908 teaching delete_breakpoint to only free a bp's storage when no more
6909 references were extent. A cheaper bandaid was chosen. */
6910 if (bpt
->type
== bp_none
)
6913 if (deprecated_delete_breakpoint_hook
)
6914 deprecated_delete_breakpoint_hook (bpt
);
6915 breakpoint_delete_event (bpt
->number
);
6917 if (bpt
->loc
->inserted
)
6918 remove_breakpoint (bpt
->loc
, mark_inserted
);
6920 free_valchain (bpt
->loc
);
6922 if (breakpoint_chain
== bpt
)
6923 breakpoint_chain
= bpt
->next
;
6925 if (bp_location_chain
== bpt
->loc
)
6926 bp_location_chain
= bpt
->loc
->next
;
6928 /* If we have callback-style exception catchpoints, don't go through
6929 the adjustments to the C++ runtime library etc. if the inferior
6930 isn't actually running. target_enable_exception_callback for a
6931 null target ops vector gives an undesirable error message, so we
6932 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6933 exceptions are supported in this way, it's OK for now. FIXME */
6934 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
6936 /* Format possible error msg */
6937 char *message
= xstrprintf ("Error in deleting catchpoint %d:\n",
6939 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
6940 args_for_catchpoint_enable args
;
6941 args
.kind
= bpt
->type
== bp_catch_catch
?
6942 EX_EVENT_CATCH
: EX_EVENT_THROW
;
6944 catch_errors (cover_target_enable_exception_callback
, &args
,
6945 message
, RETURN_MASK_ALL
);
6946 do_cleanups (cleanups
);
6953 b
->next
= bpt
->next
;
6957 ALL_BP_LOCATIONS (loc
)
6958 if (loc
->next
== bpt
->loc
)
6960 loc
->next
= bpt
->loc
->next
;
6964 check_duplicates (bpt
);
6965 /* If this breakpoint was inserted, and there is another breakpoint
6966 at the same address, we need to insert the other breakpoint. */
6967 if (bpt
->loc
->inserted
6968 && bpt
->type
!= bp_hardware_watchpoint
6969 && bpt
->type
!= bp_read_watchpoint
6970 && bpt
->type
!= bp_access_watchpoint
6971 && bpt
->type
!= bp_catch_fork
6972 && bpt
->type
!= bp_catch_vfork
6973 && bpt
->type
!= bp_catch_exec
)
6976 if (b
->loc
->address
== bpt
->loc
->address
6977 && b
->loc
->section
== bpt
->loc
->section
6978 && !b
->loc
->duplicate
6979 && b
->enable_state
!= bp_disabled
6980 && b
->enable_state
!= bp_shlib_disabled
6982 && b
->enable_state
!= bp_call_disabled
)
6986 /* We should never reach this point if there is a permanent
6987 breakpoint at the same address as the one being deleted.
6988 If there is a permanent breakpoint somewhere, it should
6989 always be the only one inserted. */
6990 if (b
->enable_state
== bp_permanent
)
6991 internal_error (__FILE__
, __LINE__
,
6992 "another breakpoint was inserted on top of "
6993 "a permanent breakpoint");
6995 if (b
->type
== bp_hardware_breakpoint
)
6996 val
= target_insert_hw_breakpoint (b
->loc
->address
, b
->loc
->shadow_contents
);
6998 val
= target_insert_breakpoint (b
->loc
->address
, b
->loc
->shadow_contents
);
7000 /* If there was an error in the insert, print a message, then stop execution. */
7003 struct ui_file
*tmp_error_stream
= mem_fileopen ();
7004 make_cleanup_ui_file_delete (tmp_error_stream
);
7007 if (b
->type
== bp_hardware_breakpoint
)
7009 fprintf_unfiltered (tmp_error_stream
,
7010 "Cannot insert hardware breakpoint %d.\n"
7011 "You may have requested too many hardware breakpoints.\n",
7016 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
7017 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
7018 print_address_numeric (b
->loc
->address
, 1, tmp_error_stream
);
7019 fprintf_filtered (tmp_error_stream
, ": %s.\n",
7020 safe_strerror (val
));
7023 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
7024 target_terminal_ours_for_output ();
7025 error_stream(tmp_error_stream
);
7028 b
->loc
->inserted
= 1;
7032 free_command_lines (&bpt
->commands
);
7035 if (bpt
->cond_string
!= NULL
)
7036 xfree (bpt
->cond_string
);
7037 if (bpt
->addr_string
!= NULL
)
7038 xfree (bpt
->addr_string
);
7039 if (bpt
->exp
!= NULL
)
7041 if (bpt
->exp_string
!= NULL
)
7042 xfree (bpt
->exp_string
);
7043 if (bpt
->val
!= NULL
)
7044 value_free (bpt
->val
);
7045 if (bpt
->source_file
!= NULL
)
7046 xfree (bpt
->source_file
);
7047 if (bpt
->dll_pathname
!= NULL
)
7048 xfree (bpt
->dll_pathname
);
7049 if (bpt
->triggered_dll_pathname
!= NULL
)
7050 xfree (bpt
->triggered_dll_pathname
);
7051 if (bpt
->exec_pathname
!= NULL
)
7052 xfree (bpt
->exec_pathname
);
7054 /* Be sure no bpstat's are pointing at it after it's been freed. */
7055 /* FIXME, how can we find all bpstat's?
7056 We just check stop_bpstat for now. */
7057 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
7058 if (bs
->breakpoint_at
== bpt
)
7060 bs
->breakpoint_at
= NULL
;
7062 /* bs->commands will be freed later. */
7064 /* On the chance that someone will soon try again to delete this same
7065 bp, we mark it as deleted before freeing its storage. */
7066 bpt
->type
= bp_none
;
7073 do_delete_breakpoint_cleanup (void *b
)
7075 delete_breakpoint (b
);
7079 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7081 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7085 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
7087 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
7091 delete_command (char *arg
, int from_tty
)
7093 struct breakpoint
*b
, *temp
;
7099 int breaks_to_delete
= 0;
7101 /* Delete all breakpoints if no argument.
7102 Do not delete internal or call-dummy breakpoints, these
7103 have to be deleted with an explicit breakpoint number argument. */
7106 if (b
->type
!= bp_call_dummy
&&
7107 b
->type
!= bp_shlib_event
&&
7108 b
->type
!= bp_thread_event
&&
7109 b
->type
!= bp_overlay_event
&&
7111 breaks_to_delete
= 1;
7114 /* Ask user only if there are some breakpoints to delete. */
7116 || (breaks_to_delete
&& query ("Delete all breakpoints? ")))
7118 ALL_BREAKPOINTS_SAFE (b
, temp
)
7120 if (b
->type
!= bp_call_dummy
&&
7121 b
->type
!= bp_shlib_event
&&
7122 b
->type
!= bp_thread_event
&&
7123 b
->type
!= bp_overlay_event
&&
7125 delete_breakpoint (b
);
7130 map_breakpoint_numbers (arg
, delete_breakpoint
);
7133 /* Reset a breakpoint given it's struct breakpoint * BINT.
7134 The value we return ends up being the return value from catch_errors.
7135 Unused in this case. */
7138 breakpoint_re_set_one (void *bint
)
7140 /* get past catch_errs */
7141 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7145 int *not_found_ptr
= NULL
;
7146 struct symtabs_and_lines sals
;
7148 enum enable_state save_enable
;
7153 warning ("attempted to reset apparently deleted breakpoint #%d?",
7157 case bp_hardware_breakpoint
:
7159 case bp_catch_unload
:
7160 if (b
->addr_string
== NULL
)
7162 /* Anything without a string can't be re-set. */
7163 delete_breakpoint (b
);
7166 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
7168 ``And a hack it is, although Apple's Darwin version of GDB
7169 contains an almost identical hack to implement a "future
7170 break" command. It seems to work in many real world cases,
7171 but it is easy to come up with a test case where the patch
7172 doesn't help at all.''
7174 ``It seems that the way GDB implements breakpoints - in -
7175 shared - libraries was designed for a.out shared library
7176 systems (SunOS 4) where shared libraries were loaded at a
7177 fixed address in memory. Since ELF shared libraries can (and
7178 will) be loaded at any address in memory, things break.
7179 Fixing this is not trivial. Therefore, I'm not sure whether
7180 we should add this hack to the branch only. I cannot
7181 guarantee that things will be fixed on the trunk in the near
7184 In case we have a problem, disable this breakpoint. We'll
7185 restore its status if we succeed. Don't disable a
7186 shlib_disabled breakpoint though. There's a fair chance we
7187 can't re-set it if the shared library it's in hasn't been
7193 save_enable
= b
->enable_state
;
7194 if (b
->enable_state
!= bp_shlib_disabled
)
7195 b
->enable_state
= bp_disabled
;
7197 /* If resetting a shlib-disabled breakpoint, we don't want to
7198 see an error message if it is not found since we will expect
7199 this to occur until the shared library is finally reloaded.
7200 We accomplish this by giving decode_line_1 a pointer to use
7201 for silent notification that the symbol is not found. */
7202 not_found_ptr
= ¬_found
;
7204 set_language (b
->language
);
7205 input_radix
= b
->input_radix
;
7207 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7209 for (i
= 0; i
< sals
.nelts
; i
++)
7211 resolve_sal_pc (&sals
.sals
[i
]);
7213 /* Reparse conditions, they might contain references to the
7215 if (b
->cond_string
!= NULL
)
7221 /* Avoid re-freeing b->exp if an error during the call
7225 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
7228 /* We need to re-set the breakpoint if the address changes... */
7229 if (b
->loc
->address
!= sals
.sals
[i
].pc
7230 /* ...or new and old breakpoints both have source files, and
7231 the source file name or the line number changes... */
7232 || (b
->source_file
!= NULL
7233 && sals
.sals
[i
].symtab
!= NULL
7234 && (strcmp (b
->source_file
, sals
.sals
[i
].symtab
->filename
) != 0
7235 || b
->line_number
!= sals
.sals
[i
].line
)
7237 /* ...or we switch between having a source file and not having
7239 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
7242 if (b
->source_file
!= NULL
)
7243 xfree (b
->source_file
);
7244 if (sals
.sals
[i
].symtab
== NULL
)
7245 b
->source_file
= NULL
;
7248 savestring (sals
.sals
[i
].symtab
->filename
,
7249 strlen (sals
.sals
[i
].symtab
->filename
));
7250 b
->line_number
= sals
.sals
[i
].line
;
7251 b
->loc
->requested_address
= sals
.sals
[i
].pc
;
7253 = adjust_breakpoint_address (b
->loc
->requested_address
,
7256 /* Used to check for duplicates here, but that can
7257 cause trouble, as it doesn't check for disabled
7262 /* Might be better to do this just once per breakpoint_re_set,
7263 rather than once for every breakpoint. */
7264 breakpoints_changed ();
7266 b
->loc
->section
= sals
.sals
[i
].section
;
7267 b
->enable_state
= save_enable
; /* Restore it, this worked. */
7270 /* Now that this is re-enabled, check_duplicates
7272 check_duplicates (b
);
7279 case bp_hardware_watchpoint
:
7280 case bp_read_watchpoint
:
7281 case bp_access_watchpoint
:
7282 innermost_block
= NULL
;
7283 /* The issue arises of what context to evaluate this in. The
7284 same one as when it was set, but what does that mean when
7285 symbols have been re-read? We could save the filename and
7286 functionname, but if the context is more local than that, the
7287 best we could do would be something like how many levels deep
7288 and which index at that particular level, but that's going to
7289 be less stable than filenames or function names. */
7291 /* So for now, just use a global context. */
7295 /* Avoid re-freeing b->exp if an error during the call to
7296 parse_expression. */
7299 b
->exp
= parse_expression (b
->exp_string
);
7300 b
->exp_valid_block
= innermost_block
;
7301 mark
= value_mark ();
7304 value_free (b
->val
);
7305 /* Avoid re-freeing b->val if an error during the call to
7306 evaluate_expression. */
7309 b
->val
= evaluate_expression (b
->exp
);
7310 release_value (b
->val
);
7311 if (VALUE_LAZY (b
->val
) && breakpoint_enabled (b
))
7312 value_fetch_lazy (b
->val
);
7314 if (b
->cond_string
!= NULL
)
7320 /* Avoid re-freeing b->exp if an error during the call
7324 b
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
7326 if (breakpoint_enabled (b
))
7328 value_free_to_mark (mark
);
7330 case bp_catch_catch
:
7331 case bp_catch_throw
:
7333 /* We needn't really do anything to reset these, since the mask
7334 that requests them is unaffected by e.g., new libraries being
7337 case bp_catch_vfork
:
7342 printf_filtered ("Deleting unknown breakpoint type %d\n", b
->type
);
7344 /* Delete longjmp and overlay event breakpoints; they will be
7345 reset later by breakpoint_re_set. */
7347 case bp_longjmp_resume
:
7348 case bp_overlay_event
:
7349 delete_breakpoint (b
);
7352 /* This breakpoint is special, it's set up when the inferior
7353 starts and we really don't want to touch it. */
7354 case bp_shlib_event
:
7356 /* Like bp_shlib_event, this breakpoint type is special.
7357 Once it is set up, we do not want to touch it. */
7358 case bp_thread_event
:
7360 /* Keep temporary breakpoints, which can be encountered when we step
7361 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7362 Otherwise these should have been blown away via the cleanup chain
7363 or by breakpoint_init_inferior when we rerun the executable. */
7366 case bp_watchpoint_scope
:
7368 case bp_step_resume
:
7375 /* Re-set all breakpoints after symbols have been re-loaded. */
7377 breakpoint_re_set (void)
7379 struct breakpoint
*b
, *temp
;
7380 enum language save_language
;
7381 int save_input_radix
;
7383 save_language
= current_language
->la_language
;
7384 save_input_radix
= input_radix
;
7385 ALL_BREAKPOINTS_SAFE (b
, temp
)
7387 /* Format possible error msg */
7388 char *message
= xstrprintf ("Error in re-setting breakpoint %d:\n",
7390 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7391 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7392 do_cleanups (cleanups
);
7394 set_language (save_language
);
7395 input_radix
= save_input_radix
;
7397 if (GET_LONGJMP_TARGET_P ())
7399 create_longjmp_breakpoint ("longjmp");
7400 create_longjmp_breakpoint ("_longjmp");
7401 create_longjmp_breakpoint ("siglongjmp");
7402 create_longjmp_breakpoint ("_siglongjmp");
7403 create_longjmp_breakpoint (NULL
);
7406 create_overlay_event_breakpoint ("_ovly_debug_event");
7409 /* Reset the thread number of this breakpoint:
7411 - If the breakpoint is for all threads, leave it as-is.
7412 - Else, reset it to the current thread for inferior_ptid. */
7414 breakpoint_re_set_thread (struct breakpoint
*b
)
7416 if (b
->thread
!= -1)
7418 if (in_thread_list (inferior_ptid
))
7419 b
->thread
= pid_to_thread_id (inferior_ptid
);
7423 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7424 If from_tty is nonzero, it prints a message to that effect,
7425 which ends with a period (no newline). */
7428 set_ignore_count (int bptnum
, int count
, int from_tty
)
7430 struct breakpoint
*b
;
7436 if (b
->number
== bptnum
)
7438 b
->ignore_count
= count
;
7442 printf_filtered ("Will stop next time breakpoint %d is reached.",
7444 else if (count
== 1)
7445 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7448 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7451 breakpoints_changed ();
7452 breakpoint_modify_event (b
->number
);
7456 error ("No breakpoint number %d.", bptnum
);
7459 /* Clear the ignore counts of all breakpoints. */
7461 breakpoint_clear_ignore_counts (void)
7463 struct breakpoint
*b
;
7466 b
->ignore_count
= 0;
7469 /* Command to set ignore-count of breakpoint N to COUNT. */
7472 ignore_command (char *args
, int from_tty
)
7478 error_no_arg ("a breakpoint number");
7480 num
= get_number (&p
);
7482 error ("bad breakpoint number: '%s'", args
);
7484 error ("Second argument (specified ignore-count) is missing.");
7486 set_ignore_count (num
,
7487 longest_to_int (value_as_long (parse_and_eval (p
))),
7490 printf_filtered ("\n");
7493 /* Call FUNCTION on each of the breakpoints
7494 whose numbers are given in ARGS. */
7497 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7502 struct breakpoint
*b
, *tmp
;
7506 error_no_arg ("one or more breakpoint numbers");
7513 num
= get_number_or_range (&p1
);
7516 warning ("bad breakpoint number at or near '%s'", p
);
7520 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7521 if (b
->number
== num
)
7523 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7526 if (related_breakpoint
)
7527 function (related_breakpoint
);
7531 printf_unfiltered ("No breakpoint number %d.\n", num
);
7537 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7538 If from_tty is nonzero, it prints a message to that effect,
7539 which ends with a period (no newline). */
7542 disable_breakpoint (struct breakpoint
*bpt
)
7544 /* Never disable a watchpoint scope breakpoint; we want to
7545 hit them when we leave scope so we can delete both the
7546 watchpoint and its scope breakpoint at that time. */
7547 if (bpt
->type
== bp_watchpoint_scope
)
7550 /* You can't disable permanent breakpoints. */
7551 if (bpt
->enable_state
== bp_permanent
)
7554 bpt
->enable_state
= bp_disabled
;
7556 check_duplicates (bpt
);
7558 if (deprecated_modify_breakpoint_hook
)
7559 deprecated_modify_breakpoint_hook (bpt
);
7560 breakpoint_modify_event (bpt
->number
);
7564 disable_command (char *args
, int from_tty
)
7566 struct breakpoint
*bpt
;
7568 ALL_BREAKPOINTS (bpt
)
7572 warning ("attempted to disable apparently deleted breakpoint #%d?",
7577 case bp_catch_unload
:
7579 case bp_catch_vfork
:
7581 case bp_catch_catch
:
7582 case bp_catch_throw
:
7583 case bp_hardware_breakpoint
:
7585 case bp_hardware_watchpoint
:
7586 case bp_read_watchpoint
:
7587 case bp_access_watchpoint
:
7588 disable_breakpoint (bpt
);
7593 map_breakpoint_numbers (args
, disable_breakpoint
);
7597 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7599 int target_resources_ok
, other_type_used
;
7602 if (bpt
->type
== bp_hardware_breakpoint
)
7605 i
= hw_breakpoint_used_count ();
7606 target_resources_ok
=
7607 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7609 if (target_resources_ok
== 0)
7610 error ("No hardware breakpoint support in the target.");
7611 else if (target_resources_ok
< 0)
7612 error ("Hardware breakpoints used exceeds limit.");
7617 if (bpt
->enable_state
!= bp_enabled
)
7619 /* When enabling a pending breakpoint, we need to check if the breakpoint
7620 is resolvable since shared libraries could have been loaded
7621 after the breakpoint was disabled. */
7622 breakpoints_changed ();
7623 if (resolve_pending_breakpoint (bpt
) == GDB_RC_OK
)
7625 delete_breakpoint (bpt
);
7628 bpt
->enable_state
= bp_enabled
;
7629 bpt
->disposition
= disposition
;
7632 else /* Not a pending breakpoint. */
7634 if (bpt
->enable_state
!= bp_permanent
)
7635 bpt
->enable_state
= bp_enabled
;
7636 bpt
->disposition
= disposition
;
7637 check_duplicates (bpt
);
7638 breakpoints_changed ();
7640 if (bpt
->type
== bp_watchpoint
||
7641 bpt
->type
== bp_hardware_watchpoint
||
7642 bpt
->type
== bp_read_watchpoint
||
7643 bpt
->type
== bp_access_watchpoint
)
7645 struct frame_id saved_frame_id
;
7647 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7648 if (bpt
->exp_valid_block
!= NULL
)
7650 struct frame_info
*fr
=
7651 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7655 Cannot enable watchpoint %d because the block in which its expression\n\
7656 is valid is not currently in scope.\n", bpt
->number
);
7657 bpt
->enable_state
= bp_disabled
;
7663 value_free (bpt
->val
);
7664 mark
= value_mark ();
7665 bpt
->val
= evaluate_expression (bpt
->exp
);
7666 release_value (bpt
->val
);
7667 if (VALUE_LAZY (bpt
->val
))
7668 value_fetch_lazy (bpt
->val
);
7670 if (bpt
->type
== bp_hardware_watchpoint
||
7671 bpt
->type
== bp_read_watchpoint
||
7672 bpt
->type
== bp_access_watchpoint
)
7674 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7675 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7677 /* Hack around 'unused var' error for some targets here */
7679 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7680 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7681 /* we can consider of type is bp_hardware_watchpoint, convert to
7682 bp_watchpoint in the following condition */
7683 if (target_resources_ok
< 0)
7686 Cannot enable watchpoint %d because target watch resources\n\
7687 have been allocated for other watchpoints.\n", bpt
->number
);
7688 bpt
->enable_state
= bp_disabled
;
7689 value_free_to_mark (mark
);
7694 select_frame (frame_find_by_id (saved_frame_id
));
7695 value_free_to_mark (mark
);
7699 if (deprecated_modify_breakpoint_hook
)
7700 deprecated_modify_breakpoint_hook (bpt
);
7701 breakpoint_modify_event (bpt
->number
);
7705 enable_breakpoint (struct breakpoint
*bpt
)
7707 do_enable_breakpoint (bpt
, bpt
->disposition
);
7710 /* The enable command enables the specified breakpoints (or all defined
7711 breakpoints) so they once again become (or continue to be) effective
7712 in stopping the inferior. */
7715 enable_command (char *args
, int from_tty
)
7717 struct breakpoint
*bpt
;
7719 ALL_BREAKPOINTS (bpt
)
7723 warning ("attempted to enable apparently deleted breakpoint #%d?",
7728 case bp_catch_unload
:
7730 case bp_catch_vfork
:
7732 case bp_catch_catch
:
7733 case bp_catch_throw
:
7734 case bp_hardware_breakpoint
:
7736 case bp_hardware_watchpoint
:
7737 case bp_read_watchpoint
:
7738 case bp_access_watchpoint
:
7739 enable_breakpoint (bpt
);
7744 map_breakpoint_numbers (args
, enable_breakpoint
);
7748 enable_once_breakpoint (struct breakpoint
*bpt
)
7750 do_enable_breakpoint (bpt
, disp_disable
);
7754 enable_once_command (char *args
, int from_tty
)
7756 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7760 enable_delete_breakpoint (struct breakpoint
*bpt
)
7762 do_enable_breakpoint (bpt
, disp_del
);
7766 enable_delete_command (char *args
, int from_tty
)
7768 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7772 set_breakpoint_cmd (char *args
, int from_tty
)
7777 show_breakpoint_cmd (char *args
, int from_tty
)
7781 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7783 struct symtabs_and_lines
7784 decode_line_spec_1 (char *string
, int funfirstline
)
7786 struct symtabs_and_lines sals
;
7788 error ("Empty line specification.");
7789 if (default_breakpoint_valid
)
7790 sals
= decode_line_1 (&string
, funfirstline
,
7791 default_breakpoint_symtab
,
7792 default_breakpoint_line
,
7793 (char ***) NULL
, NULL
);
7795 sals
= decode_line_1 (&string
, funfirstline
,
7796 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7798 error ("Junk at end of line specification: %s", string
);
7803 _initialize_breakpoint (void)
7805 static struct cmd_list_element
*breakpoint_set_cmdlist
;
7806 static struct cmd_list_element
*breakpoint_show_cmdlist
;
7807 struct cmd_list_element
*c
;
7810 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
7813 breakpoint_chain
= 0;
7814 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7815 before a breakpoint is set. */
7816 breakpoint_count
= 0;
7818 add_com ("ignore", class_breakpoint
, ignore_command
,
7819 "Set ignore-count of breakpoint number N to COUNT.\n\
7820 Usage is `ignore N COUNT'.");
7822 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7824 add_com ("commands", class_breakpoint
, commands_command
,
7825 "Set commands to be executed when a breakpoint is hit.\n\
7826 Give breakpoint number as argument after \"commands\".\n\
7827 With no argument, the targeted breakpoint is the last one set.\n\
7828 The commands themselves follow starting on the next line.\n\
7829 Type a line containing \"end\" to indicate the end of them.\n\
7830 Give \"silent\" as the first line to make the breakpoint silent;\n\
7831 then no output is printed when it is hit, except what the commands print.");
7833 add_com ("condition", class_breakpoint
, condition_command
,
7834 "Specify breakpoint number N to break only if COND is true.\n\
7835 Usage is `condition N COND', where N is an integer and COND is an\n\
7836 expression to be evaluated whenever breakpoint N is reached.");
7838 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
,
7839 "Set a temporary breakpoint. Args like \"break\" command.\n\
7840 Like \"break\" except the breakpoint is only temporary,\n\
7841 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7842 by using \"enable delete\" on the breakpoint number.");
7843 set_cmd_completer (c
, location_completer
);
7845 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
,
7846 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7847 Like \"break\" except the breakpoint requires hardware support,\n\
7848 some target hardware may not have this support.");
7849 set_cmd_completer (c
, location_completer
);
7851 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
,
7852 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7853 Like \"hbreak\" except the breakpoint is only temporary,\n\
7854 so it will be deleted when hit.");
7855 set_cmd_completer (c
, location_completer
);
7857 add_prefix_cmd ("enable", class_breakpoint
, enable_command
,
7858 "Enable some breakpoints.\n\
7859 Give breakpoint numbers (separated by spaces) as arguments.\n\
7860 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7861 This is used to cancel the effect of the \"disable\" command.\n\
7862 With a subcommand you can enable temporarily.",
7863 &enablelist
, "enable ", 1, &cmdlist
);
7865 add_com ("ab", class_breakpoint
, enable_command
,
7866 "Enable some breakpoints.\n\
7867 Give breakpoint numbers (separated by spaces) as arguments.\n\
7868 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7869 This is used to cancel the effect of the \"disable\" command.\n\
7870 With a subcommand you can enable temporarily.");
7872 add_com_alias ("en", "enable", class_breakpoint
, 1);
7874 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
,
7875 "Enable some breakpoints.\n\
7876 Give breakpoint numbers (separated by spaces) as arguments.\n\
7877 This is used to cancel the effect of the \"disable\" command.\n\
7878 May be abbreviated to simply \"enable\".\n",
7879 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
7881 add_cmd ("once", no_class
, enable_once_command
,
7882 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7883 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7886 add_cmd ("delete", no_class
, enable_delete_command
,
7887 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7888 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7891 add_cmd ("delete", no_class
, enable_delete_command
,
7892 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7893 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7896 add_cmd ("once", no_class
, enable_once_command
,
7897 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7898 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7901 add_prefix_cmd ("disable", class_breakpoint
, disable_command
,
7902 "Disable some breakpoints.\n\
7903 Arguments are breakpoint numbers with spaces in between.\n\
7904 To disable all breakpoints, give no argument.\n\
7905 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7906 &disablelist
, "disable ", 1, &cmdlist
);
7907 add_com_alias ("dis", "disable", class_breakpoint
, 1);
7908 add_com_alias ("disa", "disable", class_breakpoint
, 1);
7910 add_com ("sb", class_breakpoint
, disable_command
,
7911 "Disable some breakpoints.\n\
7912 Arguments are breakpoint numbers with spaces in between.\n\
7913 To disable all breakpoints, give no argument.\n\
7914 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7916 add_cmd ("breakpoints", class_alias
, disable_command
,
7917 "Disable some breakpoints.\n\
7918 Arguments are breakpoint numbers with spaces in between.\n\
7919 To disable all breakpoints, give no argument.\n\
7920 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7921 This command may be abbreviated \"disable\".",
7924 add_prefix_cmd ("delete", class_breakpoint
, delete_command
,
7925 "Delete some breakpoints or auto-display expressions.\n\
7926 Arguments are breakpoint numbers with spaces in between.\n\
7927 To delete all breakpoints, give no argument.\n\
7929 Also a prefix command for deletion of other GDB objects.\n\
7930 The \"unset\" command is also an alias for \"delete\".",
7931 &deletelist
, "delete ", 1, &cmdlist
);
7932 add_com_alias ("d", "delete", class_breakpoint
, 1);
7934 add_com ("db", class_breakpoint
, delete_command
,
7935 "Delete some breakpoints.\n\
7936 Arguments are breakpoint numbers with spaces in between.\n\
7937 To delete all breakpoints, give no argument.\n");
7939 add_cmd ("breakpoints", class_alias
, delete_command
,
7940 "Delete some breakpoints or auto-display expressions.\n\
7941 Arguments are breakpoint numbers with spaces in between.\n\
7942 To delete all breakpoints, give no argument.\n\
7943 This command may be abbreviated \"delete\".",
7946 add_com ("clear", class_breakpoint
, clear_command
,
7947 concat ("Clear breakpoint at specified line or function.\n\
7948 Argument may be line number, function name, or \"*\" and an address.\n\
7949 If line number is specified, all breakpoints in that line are cleared.\n\
7950 If function is specified, breakpoints at beginning of function are cleared.\n\
7951 If an address is specified, breakpoints at that address are cleared.\n\n",
7952 "With no argument, clears all breakpoints in the line that the selected frame\n\
7955 See also the \"delete\" command which clears breakpoints by number.", NULL
));
7957 c
= add_com ("break", class_breakpoint
, break_command
,
7958 concat ("Set breakpoint at specified line or function.\n\
7959 Argument may be line number, function name, or \"*\" and an address.\n\
7960 If line number is specified, break at start of code for that line.\n\
7961 If function is specified, break at start of code for that function.\n\
7962 If an address is specified, break at that exact address.\n",
7963 "With no arg, uses current execution address of selected stack frame.\n\
7964 This is useful for breaking on return to a stack frame.\n\
7966 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7968 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL
));
7969 set_cmd_completer (c
, location_completer
);
7971 add_com_alias ("b", "break", class_run
, 1);
7972 add_com_alias ("br", "break", class_run
, 1);
7973 add_com_alias ("bre", "break", class_run
, 1);
7974 add_com_alias ("brea", "break", class_run
, 1);
7978 add_com_alias ("ba", "break", class_breakpoint
, 1);
7979 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
7984 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
,
7985 "Break in function/address or break at a line in the current file.",
7986 &stoplist
, "stop ", 1, &cmdlist
);
7987 add_cmd ("in", class_breakpoint
, stopin_command
,
7988 "Break in function or address.\n", &stoplist
);
7989 add_cmd ("at", class_breakpoint
, stopat_command
,
7990 "Break at a line in the current file.\n", &stoplist
);
7991 add_com ("status", class_info
, breakpoints_info
,
7992 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7993 The \"Type\" column indicates one of:\n\
7994 \tbreakpoint - normal breakpoint\n\
7995 \twatchpoint - watchpoint\n\
7996 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7997 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7998 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7999 address and file/line number respectively.\n\n",
8000 "Convenience variable \"$_\" and default examine address for \"x\"\n\
8001 are set to the address of the last breakpoint listed.\n\n\
8002 Convenience variable \"$bpnum\" contains the number of the last\n\
8003 breakpoint set.", NULL
));
8006 add_info ("breakpoints", breakpoints_info
,
8007 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8008 The \"Type\" column indicates one of:\n\
8009 \tbreakpoint - normal breakpoint\n\
8010 \twatchpoint - watchpoint\n\
8011 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8012 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8013 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8014 address and file/line number respectively.\n\n",
8015 "Convenience variable \"$_\" and default examine address for \"x\"\n\
8016 are set to the address of the last breakpoint listed.\n\n\
8017 Convenience variable \"$bpnum\" contains the number of the last\n\
8018 breakpoint set.", NULL
));
8021 add_com ("lb", class_breakpoint
, breakpoints_info
,
8022 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8023 The \"Type\" column indicates one of:\n\
8024 \tbreakpoint - normal breakpoint\n\
8025 \twatchpoint - watchpoint\n\
8026 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8027 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8028 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8029 address and file/line number respectively.\n\n",
8030 "Convenience variable \"$_\" and default examine address for \"x\"\n\
8031 are set to the address of the last breakpoint listed.\n\n\
8032 Convenience variable \"$bpnum\" contains the number of the last\n\
8033 breakpoint set.", NULL
));
8035 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
,
8036 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
8037 The \"Type\" column indicates one of:\n\
8038 \tbreakpoint - normal breakpoint\n\
8039 \twatchpoint - watchpoint\n\
8040 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8041 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8042 \tuntil - internal breakpoint used by the \"until\" command\n\
8043 \tfinish - internal breakpoint used by the \"finish\" command\n",
8044 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8045 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8046 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8047 address and file/line number respectively.\n\n",
8048 "Convenience variable \"$_\" and default examine address for \"x\"\n\
8049 are set to the address of the last breakpoint listed.\n\n\
8050 Convenience variable \"$bpnum\" contains the number of the last\n\
8051 breakpoint set.", NULL
),
8052 &maintenanceinfolist
);
8054 add_com ("catch", class_breakpoint
, catch_command
,
8055 "Set catchpoints to catch events.\n\
8056 Raised signals may be caught:\n\
8057 \tcatch signal - all signals\n\
8058 \tcatch signal <signame> - a particular signal\n\
8059 Raised exceptions may be caught:\n\
8060 \tcatch throw - all exceptions, when thrown\n\
8061 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8062 \tcatch catch - all exceptions, when caught\n\
8063 \tcatch catch <exceptname> - a particular exception, when caught\n\
8064 Thread or process events may be caught:\n\
8065 \tcatch thread_start - any threads, just after creation\n\
8066 \tcatch thread_exit - any threads, just before expiration\n\
8067 \tcatch thread_join - any threads, just after joins\n\
8068 Process events may be caught:\n\
8069 \tcatch start - any processes, just after creation\n\
8070 \tcatch exit - any processes, just before expiration\n\
8071 \tcatch fork - calls to fork()\n\
8072 \tcatch vfork - calls to vfork()\n\
8073 \tcatch exec - calls to exec()\n\
8074 Dynamically-linked library events may be caught:\n\
8075 \tcatch load - loads of any library\n\
8076 \tcatch load <libname> - loads of a particular library\n\
8077 \tcatch unload - unloads of any library\n\
8078 \tcatch unload <libname> - unloads of a particular library\n\
8079 The act of your program's execution stopping may also be caught:\n\
8081 C++ exceptions may be caught:\n\
8082 \tcatch throw - all exceptions, when thrown\n\
8083 \tcatch catch - all exceptions, when caught\n\
8085 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8086 after a fork or vfork is caught.\n\n\
8087 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
8089 add_com ("tcatch", class_breakpoint
, tcatch_command
,
8090 "Set temporary catchpoints to catch events.\n\
8091 Args like \"catch\" command.\n\
8092 Like \"catch\" except the catchpoint is only temporary,\n\
8093 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8094 by using \"enable delete\" on the catchpoint number.");
8096 c
= add_com ("watch", class_breakpoint
, watch_command
,
8097 "Set a watchpoint for an expression.\n\
8098 A watchpoint stops execution of your program whenever the value of\n\
8099 an expression changes.");
8100 set_cmd_completer (c
, location_completer
);
8102 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
8103 "Set a read watchpoint for an expression.\n\
8104 A watchpoint stops execution of your program whenever the value of\n\
8105 an expression is read.");
8106 set_cmd_completer (c
, location_completer
);
8108 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
8109 "Set a watchpoint for an expression.\n\
8110 A watchpoint stops execution of your program whenever the value of\n\
8111 an expression is either read or written.");
8112 set_cmd_completer (c
, location_completer
);
8114 add_info ("watchpoints", breakpoints_info
,
8115 "Synonym for ``info breakpoints''.");
8118 c
= add_set_cmd ("can-use-hw-watchpoints", class_support
, var_zinteger
,
8119 (char *) &can_use_hw_watchpoints
,
8120 "Set debugger's willingness to use watchpoint hardware.\n\
8121 If zero, gdb will not use hardware for new watchpoints, even if\n\
8122 such is available. (However, any hardware watchpoints that were\n\
8123 created before setting this to nonzero, will continue to use watchpoint\n\
8126 deprecated_add_show_from_set (c
, &showlist
);
8128 can_use_hw_watchpoints
= 1;
8130 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, "\
8131 Breakpoint specific settings\n\
8132 Configure various breakpoint-specific variables such as\n\
8133 pending breakpoint behavior",
8134 &breakpoint_set_cmdlist
, "set breakpoint ",
8135 0/*allow-unknown*/, &setlist
);
8136 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, "\
8137 Breakpoint specific settings\n\
8138 Configure various breakpoint-specific variables such as\n\
8139 pending breakpoint behavior",
8140 &breakpoint_show_cmdlist
, "show breakpoint ",
8141 0/*allow-unknown*/, &showlist
);
8143 add_setshow_auto_boolean_cmd ("pending", no_class
, &pending_break_support
, "\
8144 Set debugger's behavior regarding pending breakpoints.", "\
8145 Show debugger's behavior regarding pending breakpoints.", "\
8146 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8147 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8148 an error. If auto, an unrecognized breakpoint location results in a\n\
8149 user-query to see if a pending breakpoint should be created.", "\
8150 Debugger's behavior regarding pending breakpoints is %s.",
8152 &breakpoint_set_cmdlist
,
8153 &breakpoint_show_cmdlist
);
8155 pending_break_support
= AUTO_BOOLEAN_AUTO
;