1 /* Everything about breakpoints, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 #include "breakpoint.h"
28 #include "expression.h"
34 #include "gdbthread.h"
37 #include "gdb_string.h"
43 #include "completer.h"
48 #include "gdb-events.h"
50 /* Prototypes for local functions. */
52 static void until_break_command_continuation (struct continuation_arg
*arg
);
54 static void catch_command_1 (char *, int, int);
56 static void enable_delete_command (char *, int);
58 static void enable_delete_breakpoint (struct breakpoint
*);
60 static void enable_once_command (char *, int);
62 static void enable_once_breakpoint (struct breakpoint
*);
64 static void disable_command (char *, int);
66 static void enable_command (char *, int);
68 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
70 static void ignore_command (char *, int);
72 static int breakpoint_re_set_one (PTR
);
74 static void clear_command (char *, int);
76 static void catch_command (char *, int);
78 static void handle_gnu_4_16_catch_command (char *, int, int);
80 static struct symtabs_and_lines
get_catch_sals (int);
82 static void watch_command (char *, int);
84 static int can_use_hardware_watchpoint (struct value
*);
86 static void break_at_finish_command (char *, int);
87 static void break_at_finish_at_depth_command (char *, int);
89 static void tbreak_at_finish_command (char *, int);
91 static void break_command_1 (char *, int, int);
93 static void mention (struct breakpoint
*);
95 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
97 static void check_duplicates (struct breakpoint
*);
99 static void describe_other_breakpoints (CORE_ADDR
, asection
*);
101 static void breakpoints_info (char *, int);
103 static void breakpoint_1 (int, int);
105 static bpstat
bpstat_alloc (struct breakpoint
*, bpstat
);
107 static int breakpoint_cond_eval (PTR
);
109 static void cleanup_executing_breakpoints (PTR
);
111 static void commands_command (char *, int);
113 static void condition_command (char *, int);
115 static int get_number_trailer (char **, int);
117 void set_breakpoint_count (int);
120 static struct breakpoint
*create_temp_exception_breakpoint (CORE_ADDR
);
130 static int remove_breakpoint (struct breakpoint
*, insertion_state_t
);
132 static enum print_stop_action
print_it_typical (bpstat
);
134 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
138 enum exception_event_kind kind
;
141 args_for_catchpoint_enable
;
143 static int watchpoint_check (PTR
);
145 static int cover_target_enable_exception_callback (PTR
);
147 static void maintenance_info_breakpoints (char *, int);
149 #ifdef GET_LONGJMP_TARGET
150 static void create_longjmp_breakpoint (char *);
153 static int hw_breakpoint_used_count (void);
155 static int hw_watchpoint_used_count (enum bptype
, int *);
157 static void hbreak_command (char *, int);
159 static void thbreak_command (char *, int);
161 static void watch_command_1 (char *, int, int);
163 static void rwatch_command (char *, int);
165 static void awatch_command (char *, int);
167 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
169 static void solib_load_unload_1 (char *hookname
,
172 char *cond_string
, enum bptype bp_kind
);
174 static void create_fork_vfork_event_catchpoint (int tempflag
,
176 enum bptype bp_kind
);
178 static void break_at_finish_at_depth_command_1 (char *arg
,
179 int flag
, int from_tty
);
181 static void break_at_finish_command_1 (char *arg
, int flag
, int from_tty
);
183 static void stop_command (char *arg
, int from_tty
);
185 static void stopin_command (char *arg
, int from_tty
);
187 static void stopat_command (char *arg
, int from_tty
);
189 static char *ep_find_event_name_end (char *arg
);
191 static char *ep_parse_optional_if_clause (char **arg
);
193 static char *ep_parse_optional_filename (char **arg
);
195 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
196 static void catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
);
199 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
200 enum exception_event_kind ex_event
,
201 struct symtab_and_line
*sal
);
203 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
204 char *arg
, int tempflag
, int from_tty
);
206 static void tcatch_command (char *arg
, int from_tty
);
208 static void ep_skip_leading_whitespace (char **s
);
210 /* Prototypes for exported functions. */
212 /* If FALSE, gdb will not use hardware support for watchpoints, even
213 if such is available. */
214 static int can_use_hw_watchpoints
;
216 void _initialize_breakpoint (void);
218 extern int addressprint
; /* Print machine addresses? */
220 static int internal_breakpoint_number
= -1;
222 /* Are we executing breakpoint commands? */
223 static int executing_breakpoint_commands
;
225 /* Walk the following statement or block through all breakpoints.
226 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
229 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
231 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
232 for (B = breakpoint_chain; \
233 B ? (TMP=B->next, 1): 0; \
236 /* True if SHIFT_INST_REGS defined, false otherwise. */
238 int must_shift_inst_regs
=
239 #if defined(SHIFT_INST_REGS)
246 /* True if breakpoint hit counts should be displayed in breakpoint info. */
248 int show_breakpoint_hit_counts
= 1;
250 /* Chain of all breakpoints defined. */
252 struct breakpoint
*breakpoint_chain
;
254 /* Number of last breakpoint made. */
256 int breakpoint_count
;
258 /* Pointer to current exception event record */
259 static struct exception_event_record
*current_exception_event
;
261 /* Indicator of whether exception catchpoints should be nuked
262 between runs of a program */
263 int exception_catchpoints_are_fragile
= 0;
265 /* Indicator of when exception catchpoints set-up should be
266 reinitialized -- e.g. when program is re-run */
267 int exception_support_initialized
= 0;
269 /* This function returns a pointer to the string representation of the
270 pathname of the dynamically-linked library that has just been
273 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
274 or undefined results are guaranteed.
276 This string's contents are only valid immediately after the
277 inferior has stopped in the dynamic linker hook, and becomes
278 invalid as soon as the inferior is continued. Clients should make
279 a copy of this string if they wish to continue the inferior and
280 then access the string. */
282 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
283 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
286 /* This function returns a pointer to the string representation of the
287 pathname of the dynamically-linked library that has just been
290 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
291 TRUE, or undefined results are guaranteed.
293 This string's contents are only valid immediately after the
294 inferior has stopped in the dynamic linker hook, and becomes
295 invalid as soon as the inferior is continued. Clients should make
296 a copy of this string if they wish to continue the inferior and
297 then access the string. */
299 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
300 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
303 /* This function is called by the "catch load" command. It allows the
304 debugger to be notified by the dynamic linker when a specified
305 library file (or any library file, if filename is NULL) is loaded. */
307 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
308 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
309 error ("catch of library loads not yet implemented on this platform")
312 /* This function is called by the "catch unload" command. It allows
313 the debugger to be notified by the dynamic linker when a specified
314 library file (or any library file, if filename is NULL) is
317 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
318 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
319 error ("catch of library unloads not yet implemented on this platform")
322 /* Set breakpoint count to NUM. */
325 set_breakpoint_count (int num
)
327 breakpoint_count
= num
;
328 set_internalvar (lookup_internalvar ("bpnum"),
329 value_from_longest (builtin_type_int
, (LONGEST
) num
));
332 /* Used in run_command to zero the hit count when a new run starts. */
335 clear_breakpoint_hit_counts (void)
337 struct breakpoint
*b
;
343 /* Default address, symtab and line to put a breakpoint at
344 for "break" command with no arg.
345 if default_breakpoint_valid is zero, the other three are
346 not valid, and "break" with no arg is an error.
348 This set by print_stack_frame, which calls set_default_breakpoint. */
350 int default_breakpoint_valid
;
351 CORE_ADDR default_breakpoint_address
;
352 struct symtab
*default_breakpoint_symtab
;
353 int default_breakpoint_line
;
355 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
356 Advance *PP after the string and any trailing whitespace.
358 Currently the string can either be a number or "$" followed by the name
359 of a convenience variable. Making it an expression wouldn't work well
360 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
362 TRAILER is a character which can be found after the number; most
363 commonly this is `-'. If you don't want a trailer, use \0. */
365 get_number_trailer (char **pp
, int trailer
)
367 int retval
= 0; /* default */
371 /* Empty line means refer to the last breakpoint. */
372 return breakpoint_count
;
375 /* Make a copy of the name, so we can null-terminate it
376 to pass to lookup_internalvar(). */
381 while (isalnum (*p
) || *p
== '_')
383 varname
= (char *) alloca (p
- start
+ 1);
384 strncpy (varname
, start
, p
- start
);
385 varname
[p
- start
] = '\0';
386 val
= value_of_internalvar (lookup_internalvar (varname
));
387 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
)
388 retval
= (int) value_as_long (val
);
391 printf_filtered ("Convenience variable must have integer value.\n");
399 while (*p
>= '0' && *p
<= '9')
402 /* There is no number here. (e.g. "cond a == b"). */
404 /* Skip non-numeric token */
405 while (*p
&& !isspace((int) *p
))
407 /* Return zero, which caller must interpret as error. */
413 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
415 /* Trailing junk: return 0 and let caller print error msg. */
416 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
427 /* Like get_number_trailer, but don't allow a trailer. */
429 get_number (char **pp
)
431 return get_number_trailer (pp
, '\0');
434 /* Parse a number or a range.
435 * A number will be of the form handled by get_number.
436 * A range will be of the form <number1> - <number2>, and
437 * will represent all the integers between number1 and number2,
440 * While processing a range, this fuction is called iteratively;
441 * At each call it will return the next value in the range.
443 * At the beginning of parsing a range, the char pointer PP will
444 * be advanced past <number1> and left pointing at the '-' token.
445 * Subsequent calls will not advance the pointer until the range
446 * is completed. The call that completes the range will advance
447 * pointer PP past <number2>.
451 get_number_or_range (char **pp
)
453 static int last_retval
, end_value
;
454 static char *end_ptr
;
455 static int in_range
= 0;
459 /* Default case: pp is pointing either to a solo number,
460 or to the first number of a range. */
461 last_retval
= get_number_trailer (pp
, '-');
466 /* This is the start of a range (<number1> - <number2>).
467 Skip the '-', parse and remember the second number,
468 and also remember the end of the final token. */
472 while (isspace ((int) *end_ptr
))
473 end_ptr
++; /* skip white space */
474 end_value
= get_number (temp
);
475 if (end_value
< last_retval
)
477 error ("inverted range");
479 else if (end_value
== last_retval
)
481 /* degenerate range (number1 == number2). Advance the
482 token pointer so that the range will be treated as a
491 error ("negative value");
494 /* pp points to the '-' that betokens a range. All
495 number-parsing has already been done. Return the next
496 integer value (one greater than the saved previous value).
497 Do not advance the token pointer 'pp' until the end of range
500 if (++last_retval
== end_value
)
502 /* End of range reached; advance token pointer. */
512 /* condition N EXP -- set break condition of breakpoint N to EXP. */
515 condition_command (char *arg
, int from_tty
)
517 register struct breakpoint
*b
;
522 error_no_arg ("breakpoint number");
525 bnum
= get_number (&p
);
527 error ("Bad breakpoint argument: '%s'", arg
);
530 if (b
->number
== bnum
)
537 if (b
->cond_string
!= NULL
)
538 xfree (b
->cond_string
);
543 b
->cond_string
= NULL
;
545 printf_filtered ("Breakpoint %d now unconditional.\n", bnum
);
550 /* I don't know if it matters whether this is the string the user
551 typed in or the decompiled expression. */
552 b
->cond_string
= savestring (arg
, strlen (arg
));
553 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->address
), 0);
555 error ("Junk at end of expression");
557 breakpoints_changed ();
561 error ("No breakpoint number %d.", bnum
);
566 commands_command (char *arg
, int from_tty
)
568 register struct breakpoint
*b
;
571 struct command_line
*l
;
573 /* If we allowed this, we would have problems with when to
574 free the storage, if we change the commands currently
577 if (executing_breakpoint_commands
)
578 error ("Can't use the \"commands\" command among a breakpoint's commands.");
581 bnum
= get_number (&p
);
584 error ("Unexpected extra arguments following breakpoint number.");
587 if (b
->number
== bnum
)
591 "Type commands for when breakpoint %d is hit, one per line.",
593 l
= read_command_lines (tmpbuf
, from_tty
);
594 free_command_lines (&b
->commands
);
596 breakpoints_changed ();
599 error ("No breakpoint number %d.", bnum
);
602 /* Like target_read_memory() but if breakpoints are inserted, return
603 the shadow contents instead of the breakpoints themselves.
605 Read "memory data" from whatever target or inferior we have.
606 Returns zero if successful, errno value if not. EIO is used
607 for address out of bounds. If breakpoints are inserted, returns
608 shadow contents, not the breakpoints themselves. From breakpoint.c. */
611 read_memory_nobpt (CORE_ADDR memaddr
, char *myaddr
, unsigned len
)
614 struct breakpoint
*b
;
615 CORE_ADDR bp_addr
= 0;
618 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
619 /* No breakpoints on this machine. */
620 return target_read_memory (memaddr
, myaddr
, len
);
624 if (b
->type
== bp_none
)
625 warning ("reading through apparently deleted breakpoint #%d?",
628 /* memory breakpoint? */
629 if (b
->type
== bp_watchpoint
630 || b
->type
== bp_hardware_watchpoint
631 || b
->type
== bp_read_watchpoint
632 || b
->type
== bp_access_watchpoint
)
637 /* Addresses and length of the part of the breakpoint that
639 /* XXXX The m68k, sh and h8300 have different local and remote
640 breakpoint values. BREAKPOINT_FROM_PC still manages to
641 correctly determine the breakpoints memory address and size
642 for these targets. */
643 bp_addr
= b
->address
;
645 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
650 if (bp_addr
+ bp_size
<= memaddr
)
651 /* The breakpoint is entirely before the chunk of memory we
654 if (bp_addr
>= memaddr
+ len
)
655 /* The breakpoint is entirely after the chunk of memory we are
658 /* Copy the breakpoint from the shadow contents, and recurse for
659 the things before and after. */
661 /* Offset within shadow_contents. */
664 if (bp_addr
< memaddr
)
666 /* Only copy the second part of the breakpoint. */
667 bp_size
-= memaddr
- bp_addr
;
668 bptoffset
= memaddr
- bp_addr
;
672 if (bp_addr
+ bp_size
> memaddr
+ len
)
674 /* Only copy the first part of the breakpoint. */
675 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
678 memcpy (myaddr
+ bp_addr
- memaddr
,
679 b
->shadow_contents
+ bptoffset
, bp_size
);
681 if (bp_addr
> memaddr
)
683 /* Copy the section of memory before the breakpoint. */
684 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
689 if (bp_addr
+ bp_size
< memaddr
+ len
)
691 /* Copy the section of memory after the breakpoint. */
692 status
= read_memory_nobpt (bp_addr
+ bp_size
,
693 myaddr
+ bp_addr
+ bp_size
- memaddr
,
694 memaddr
+ len
- (bp_addr
+ bp_size
));
701 /* Nothing overlaps. Just call read_memory_noerr. */
702 return target_read_memory (memaddr
, myaddr
, len
);
706 /* insert_breakpoints is used when starting or continuing the program.
707 remove_breakpoints is used when the program stops.
708 Both return zero if successful,
709 or an `errno' value if could not write the inferior. */
712 insert_breakpoints (void)
714 register struct breakpoint
*b
, *temp
;
715 int return_val
= 0; /* return success code. */
717 int disabled_breaks
= 0;
719 static char message1
[] = "Error inserting catchpoint %d:\n";
720 static char message
[sizeof (message1
) + 30];
723 ALL_BREAKPOINTS_SAFE (b
, temp
)
725 if (b
->enable
== permanent
)
726 /* Permanent breakpoints cannot be inserted or removed. */
728 else if (b
->type
!= bp_watchpoint
729 && b
->type
!= bp_hardware_watchpoint
730 && b
->type
!= bp_read_watchpoint
731 && b
->type
!= bp_access_watchpoint
732 && b
->type
!= bp_catch_fork
733 && b
->type
!= bp_catch_vfork
734 && b
->type
!= bp_catch_exec
735 && b
->type
!= bp_catch_throw
736 && b
->type
!= bp_catch_catch
737 && b
->enable
!= disabled
738 && b
->enable
!= shlib_disabled
739 && b
->enable
!= call_disabled
743 if (b
->type
== bp_hardware_breakpoint
)
744 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
747 /* Check to see if breakpoint is in an overlay section;
748 if so, we should set the breakpoint at the LMA address.
749 Only if the section is currently mapped should we ALSO
750 set a break at the VMA address. */
751 if (overlay_debugging
&& b
->section
&&
752 section_is_overlay (b
->section
))
756 addr
= overlay_unmapped_address (b
->address
, b
->section
);
757 val
= target_insert_breakpoint (addr
, b
->shadow_contents
);
758 /* This would be the time to check val, to see if the
759 breakpoint write to the load address succeeded.
760 However, this might be an ordinary occurrance, eg. if
761 the unmapped overlay is in ROM. */
762 val
= 0; /* in case unmapped address failed */
763 if (section_is_mapped (b
->section
))
764 val
= target_insert_breakpoint (b
->address
,
767 else /* ordinary (non-overlay) address */
768 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
772 /* Can't set the breakpoint. */
773 #if defined (DISABLE_UNSETTABLE_BREAK)
774 if (DISABLE_UNSETTABLE_BREAK (b
->address
))
776 /* See also: disable_breakpoints_in_shlibs. */
778 b
->enable
= shlib_disabled
;
779 if (!disabled_breaks
)
781 target_terminal_ours_for_output ();
782 warning ("Cannot insert breakpoint %d:", b
->number
);
783 warning ("Temporarily disabling shared library breakpoints:");
786 warning ("breakpoint #%d ", b
->number
);
791 target_terminal_ours_for_output ();
792 warning ("Cannot insert breakpoint %d:", b
->number
);
793 #ifdef ONE_PROCESS_WRITETEXT
794 warning ("The same program may be running in another process.");
796 memory_error (val
, b
->address
); /* which bombs us out */
803 return_val
= val
; /* remember failure */
805 else if (ep_is_exception_catchpoint (b
)
806 && b
->enable
!= disabled
807 && b
->enable
!= shlib_disabled
808 && b
->enable
!= call_disabled
813 /* If we get here, we must have a callback mechanism for exception
814 events -- with g++ style embedded label support, we insert
815 ordinary breakpoints and not catchpoints. */
816 /* Format possible error message */
817 sprintf (message
, message1
, b
->number
);
819 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
822 /* Couldn't set breakpoint for some reason */
823 target_terminal_ours_for_output ();
824 warning ("Cannot insert catchpoint %d; disabling it.",
826 b
->enable
= disabled
;
830 /* Bp set, now make sure callbacks are enabled */
832 args_for_catchpoint_enable args
;
833 args
.kind
= b
->type
== bp_catch_catch
?
834 EX_EVENT_CATCH
: EX_EVENT_THROW
;
836 val
= catch_errors (cover_target_enable_exception_callback
,
838 message
, RETURN_MASK_ALL
);
839 if (val
!= 0 && val
!= -1)
843 /* Check if something went wrong; val == 0 can be ignored */
846 /* something went wrong */
847 target_terminal_ours_for_output ();
848 warning ("Cannot insert catchpoint %d; disabling it.",
850 b
->enable
= disabled
;
855 return_val
= val
; /* remember failure */
858 else if ((b
->type
== bp_hardware_watchpoint
||
859 b
->type
== bp_read_watchpoint
||
860 b
->type
== bp_access_watchpoint
)
861 && b
->enable
== enabled
862 && b
->disposition
!= del_at_next_stop
866 struct frame_info
*saved_frame
;
867 int saved_level
, within_current_scope
;
868 value_ptr mark
= value_mark ();
871 /* Save the current frame and level so we can restore it after
872 evaluating the watchpoint expression on its own frame. */
873 saved_frame
= selected_frame
;
874 saved_level
= selected_frame_level
;
876 /* Determine if the watchpoint is within scope. */
877 if (b
->exp_valid_block
== NULL
)
878 within_current_scope
= 1;
881 struct frame_info
*fi
;
883 /* There might be no current frame at this moment if we are
884 resuming from a step over a breakpoint.
885 Set up current frame before trying to find the watchpoint
887 get_current_frame ();
888 fi
= find_frame_addr_in_frame_chain (b
->watchpoint_frame
);
889 within_current_scope
= (fi
!= NULL
);
890 if (within_current_scope
)
891 select_frame (fi
, -1);
894 if (within_current_scope
)
896 /* Evaluate the expression and cut the chain of values
897 produced off from the value chain.
899 Make sure the value returned isn't lazy; we use
900 laziness to determine what memory GDB actually needed
901 in order to compute the value of the expression. */
902 v
= evaluate_expression (b
->exp
);
904 value_release_to_mark (mark
);
909 /* Look at each value on the value chain. */
910 for (; v
; v
= v
->next
)
912 /* If it's a memory location, and GDB actually needed
913 its contents to evaluate the expression, then we
915 if (VALUE_LVAL (v
) == lval_memory
918 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
920 /* We only watch structs and arrays if user asked
921 for it explicitly, never if they just happen to
922 appear in the middle of some value chain. */
923 if (v
== b
->val_chain
924 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
925 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
930 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
931 len
= TYPE_LENGTH (VALUE_TYPE (v
));
933 if (b
->type
== bp_read_watchpoint
)
935 else if (b
->type
== bp_access_watchpoint
)
938 val
= target_insert_watchpoint (addr
, len
, type
);
941 /* Don't exit the loop, try to insert
942 every value on the value chain. That's
943 because we will be removing all the
944 watches below, and removing a
945 watchpoint we didn't insert could have
953 /* Failure to insert a watchpoint on any memory value in the
954 value chain brings us here. */
957 remove_breakpoint (b
, mark_uninserted
);
958 warning ("Could not insert hardware watchpoint %d.",
965 printf_filtered ("Hardware watchpoint %d deleted ", b
->number
);
966 printf_filtered ("because the program has left the block \n");
967 printf_filtered ("in which its expression is valid.\n");
968 if (b
->related_breakpoint
)
969 b
->related_breakpoint
->disposition
= del_at_next_stop
;
970 b
->disposition
= del_at_next_stop
;
973 /* Restore the frame and level. */
974 if ((saved_frame
!= selected_frame
) ||
975 (saved_level
!= selected_frame_level
))
976 select_frame (saved_frame
, saved_level
);
979 return_val
= val
; /* remember failure */
981 else if ((b
->type
== bp_catch_fork
982 || b
->type
== bp_catch_vfork
983 || b
->type
== bp_catch_exec
)
984 && b
->enable
== enabled
992 val
= target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
995 val
= target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
998 val
= target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
1001 warning ("Internal error, %s line %d.", __FILE__
, __LINE__
);
1006 target_terminal_ours_for_output ();
1007 warning ("Cannot insert catchpoint %d.", b
->number
);
1013 return_val
= val
; /* remember failure */
1022 remove_breakpoints (void)
1024 register struct breakpoint
*b
;
1031 val
= remove_breakpoint (b
, mark_uninserted
);
1040 remove_hw_watchpoints (void)
1042 register struct breakpoint
*b
;
1048 && (b
->type
== bp_hardware_watchpoint
1049 || b
->type
== bp_read_watchpoint
1050 || b
->type
== bp_access_watchpoint
))
1052 val
= remove_breakpoint (b
, mark_uninserted
);
1061 reattach_breakpoints (int pid
)
1063 register struct breakpoint
*b
;
1065 struct cleanup
*old_chain
= save_inferior_ptid ();
1067 /* Set inferior_ptid; remove_breakpoint uses this global. */
1068 inferior_ptid
= pid_to_ptid (pid
);
1073 remove_breakpoint (b
, mark_inserted
);
1074 if (b
->type
== bp_hardware_breakpoint
)
1075 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
1077 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
1080 do_cleanups (old_chain
);
1085 do_cleanups (old_chain
);
1090 update_breakpoints_after_exec (void)
1092 struct breakpoint
*b
;
1093 struct breakpoint
*temp
;
1095 /* Doing this first prevents the badness of having delete_breakpoint()
1096 write a breakpoint's current "shadow contents" to lift the bp. That
1097 shadow is NOT valid after an exec()! */
1098 mark_breakpoints_out ();
1100 ALL_BREAKPOINTS_SAFE (b
, temp
)
1102 /* Solib breakpoints must be explicitly reset after an exec(). */
1103 if (b
->type
== bp_shlib_event
)
1105 delete_breakpoint (b
);
1109 /* Thread event breakpoints must be set anew after an exec(). */
1110 if (b
->type
== bp_thread_event
)
1112 delete_breakpoint (b
);
1116 /* Step-resume breakpoints are meaningless after an exec(). */
1117 if (b
->type
== bp_step_resume
)
1119 delete_breakpoint (b
);
1123 /* Ditto the sigtramp handler breakpoints. */
1124 if (b
->type
== bp_through_sigtramp
)
1126 delete_breakpoint (b
);
1130 /* Ditto the exception-handling catchpoints. */
1131 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1133 delete_breakpoint (b
);
1137 /* Don't delete an exec catchpoint, because else the inferior
1138 won't stop when it ought!
1140 Similarly, we probably ought to keep vfork catchpoints, 'cause
1141 on this target, we may not be able to stop when the vfork is
1142 seen, but only when the subsequent exec is seen. (And because
1143 deleting fork catchpoints here but not vfork catchpoints will
1144 seem mysterious to users, keep those too.)
1146 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1147 target address field, if any, is sufficient to have it be reset
1148 automagically. Certainly on HP-UX that's true.
1150 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1151 valid code address on some platforms (like the mn10200 and
1152 mn10300 simulators). We shouldn't assign any special
1153 interpretation to a breakpoint with a zero address. And in
1154 fact, GDB doesn't --- I can't see what that comment above is
1155 talking about. As far as I can tell, setting the address of a
1156 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1157 is meaningless, since those are implemented with HP-UX kernel
1158 hackery, not by storing breakpoint instructions somewhere. */
1159 if ((b
->type
== bp_catch_exec
) ||
1160 (b
->type
== bp_catch_vfork
) ||
1161 (b
->type
== bp_catch_fork
))
1163 b
->address
= (CORE_ADDR
) NULL
;
1167 /* bp_finish is a special case. The only way we ought to be able
1168 to see one of these when an exec() has happened, is if the user
1169 caught a vfork, and then said "finish". Ordinarily a finish just
1170 carries them to the call-site of the current callee, by setting
1171 a temporary bp there and resuming. But in this case, the finish
1172 will carry them entirely through the vfork & exec.
1174 We don't want to allow a bp_finish to remain inserted now. But
1175 we can't safely delete it, 'cause finish_command has a handle to
1176 the bp on a bpstat, and will later want to delete it. There's a
1177 chance (and I've seen it happen) that if we delete the bp_finish
1178 here, that its storage will get reused by the time finish_command
1179 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1180 We really must allow finish_command to delete a bp_finish.
1182 In the absense of a general solution for the "how do we know
1183 it's safe to delete something others may have handles to?"
1184 problem, what we'll do here is just uninsert the bp_finish, and
1185 let finish_command delete it.
1187 (We know the bp_finish is "doomed" in the sense that it's
1188 momentary, and will be deleted as soon as finish_command sees
1189 the inferior stopped. So it doesn't matter that the bp's
1190 address is probably bogus in the new a.out, unlike e.g., the
1191 solib breakpoints.) */
1193 if (b
->type
== bp_finish
)
1198 /* Without a symbolic address, we have little hope of the
1199 pre-exec() address meaning the same thing in the post-exec()
1201 if (b
->addr_string
== NULL
)
1203 delete_breakpoint (b
);
1207 /* If this breakpoint has survived the above battery of checks, then
1208 it must have a symbolic address. Be sure that it gets reevaluated
1209 to a target address, rather than reusing the old evaluation.
1211 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1212 for bp_catch_exec and friends, I'm pretty sure this is entirely
1213 unnecessary. A call to breakpoint_re_set_one always recomputes
1214 the breakpoint's address from scratch, or deletes it if it can't.
1215 So I think this assignment could be deleted without effect. */
1216 b
->address
= (CORE_ADDR
) NULL
;
1221 detach_breakpoints (int pid
)
1223 register struct breakpoint
*b
;
1225 struct cleanup
*old_chain
= save_inferior_ptid ();
1227 if (pid
== PIDGET (inferior_ptid
))
1228 error ("Cannot detach breakpoints of inferior_ptid");
1230 /* Set inferior_ptid; remove_breakpoint uses this global. */
1231 inferior_ptid
= pid_to_ptid (pid
);
1236 val
= remove_breakpoint (b
, mark_inserted
);
1239 do_cleanups (old_chain
);
1244 do_cleanups (old_chain
);
1249 remove_breakpoint (struct breakpoint
*b
, insertion_state_t is
)
1253 if (b
->enable
== permanent
)
1254 /* Permanent breakpoints cannot be inserted or removed. */
1257 if (b
->type
== bp_none
)
1258 warning ("attempted to remove apparently deleted breakpoint #%d?",
1261 if (b
->type
!= bp_watchpoint
1262 && b
->type
!= bp_hardware_watchpoint
1263 && b
->type
!= bp_read_watchpoint
1264 && b
->type
!= bp_access_watchpoint
1265 && b
->type
!= bp_catch_fork
1266 && b
->type
!= bp_catch_vfork
1267 && b
->type
!= bp_catch_exec
1268 && b
->type
!= bp_catch_catch
1269 && b
->type
!= bp_catch_throw
)
1271 if (b
->type
== bp_hardware_breakpoint
)
1272 val
= target_remove_hw_breakpoint (b
->address
, b
->shadow_contents
);
1275 /* Check to see if breakpoint is in an overlay section;
1276 if so, we should remove the breakpoint at the LMA address.
1277 If that is not equal to the raw address, then we should
1278 presumably remove the breakpoint there as well. */
1279 if (overlay_debugging
&& b
->section
&&
1280 section_is_overlay (b
->section
))
1284 addr
= overlay_unmapped_address (b
->address
, b
->section
);
1285 val
= target_remove_breakpoint (addr
, b
->shadow_contents
);
1286 /* This would be the time to check val, to see if the
1287 shadow breakpoint write to the load address succeeded.
1288 However, this might be an ordinary occurrance, eg. if
1289 the unmapped overlay is in ROM. */
1290 val
= 0; /* in case unmapped address failed */
1291 if (section_is_mapped (b
->section
))
1292 val
= target_remove_breakpoint (b
->address
,
1293 b
->shadow_contents
);
1295 else /* ordinary (non-overlay) address */
1296 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1300 b
->inserted
= (is
== mark_inserted
);
1302 else if ((b
->type
== bp_hardware_watchpoint
||
1303 b
->type
== bp_read_watchpoint
||
1304 b
->type
== bp_access_watchpoint
)
1305 && b
->enable
== enabled
1310 b
->inserted
= (is
== mark_inserted
);
1311 /* Walk down the saved value chain. */
1312 for (v
= b
->val_chain
; v
; v
= v
->next
)
1314 /* For each memory reference remove the watchpoint
1316 if (VALUE_LVAL (v
) == lval_memory
1317 && ! VALUE_LAZY (v
))
1319 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
1321 if (v
== b
->val_chain
1322 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1323 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1328 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1329 len
= TYPE_LENGTH (VALUE_TYPE (v
));
1331 if (b
->type
== bp_read_watchpoint
)
1333 else if (b
->type
== bp_access_watchpoint
)
1336 val
= target_remove_watchpoint (addr
, len
, type
);
1343 /* Failure to remove any of the hardware watchpoints comes here. */
1344 if ((is
== mark_uninserted
) && (b
->inserted
))
1345 warning ("Could not remove hardware watchpoint %d.",
1348 /* Free the saved value chain. We will construct a new one
1349 the next time the watchpoint is inserted. */
1350 for (v
= b
->val_chain
; v
; v
= n
)
1355 b
->val_chain
= NULL
;
1357 else if ((b
->type
== bp_catch_fork
||
1358 b
->type
== bp_catch_vfork
||
1359 b
->type
== bp_catch_exec
)
1360 && b
->enable
== enabled
1367 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1369 case bp_catch_vfork
:
1370 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1373 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1376 warning ("Internal error, %s line %d.", __FILE__
, __LINE__
);
1381 b
->inserted
= (is
== mark_inserted
);
1383 else if ((b
->type
== bp_catch_catch
||
1384 b
->type
== bp_catch_throw
)
1385 && b
->enable
== enabled
1389 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1392 b
->inserted
= (is
== mark_inserted
);
1394 else if (ep_is_exception_catchpoint (b
)
1395 && b
->inserted
/* sometimes previous insert doesn't happen */
1396 && b
->enable
== enabled
1400 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1404 b
->inserted
= (is
== mark_inserted
);
1410 /* Clear the "inserted" flag in all breakpoints. */
1413 mark_breakpoints_out (void)
1415 register struct breakpoint
*b
;
1421 /* Clear the "inserted" flag in all breakpoints and delete any
1422 breakpoints which should go away between runs of the program.
1424 Plus other such housekeeping that has to be done for breakpoints
1427 Note: this function gets called at the end of a run (by
1428 generic_mourn_inferior) and when a run begins (by
1429 init_wait_for_inferior). */
1434 breakpoint_init_inferior (enum inf_context context
)
1436 register struct breakpoint
*b
, *temp
;
1437 static int warning_needed
= 0;
1439 ALL_BREAKPOINTS_SAFE (b
, temp
)
1446 case bp_watchpoint_scope
:
1448 /* If the call dummy breakpoint is at the entry point it will
1449 cause problems when the inferior is rerun, so we better
1452 Also get rid of scope breakpoints. */
1453 delete_breakpoint (b
);
1457 case bp_hardware_watchpoint
:
1458 case bp_read_watchpoint
:
1459 case bp_access_watchpoint
:
1461 /* Likewise for watchpoints on local expressions. */
1462 if (b
->exp_valid_block
!= NULL
)
1463 delete_breakpoint (b
);
1466 /* Likewise for exception catchpoints in dynamic-linked
1467 executables where required */
1468 if (ep_is_exception_catchpoint (b
) &&
1469 exception_catchpoints_are_fragile
)
1472 delete_breakpoint (b
);
1478 if (exception_catchpoints_are_fragile
)
1479 exception_support_initialized
= 0;
1481 /* Don't issue the warning unless it's really needed... */
1482 if (warning_needed
&& (context
!= inf_exited
))
1484 warning ("Exception catchpoints from last run were deleted.");
1485 warning ("You must reinsert them explicitly.");
1490 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1491 exists at PC. It returns ordinary_breakpoint_here if it's an
1492 ordinary breakpoint, or permanent_breakpoint_here if it's a
1493 permanent breakpoint.
1494 - When continuing from a location with an ordinary breakpoint, we
1495 actually single step once before calling insert_breakpoints.
1496 - When continuing from a localion with a permanent breakpoint, we
1497 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1498 the target, to advance the PC past the breakpoint. */
1500 enum breakpoint_here
1501 breakpoint_here_p (CORE_ADDR pc
)
1503 register struct breakpoint
*b
;
1504 int any_breakpoint_here
= 0;
1507 if ((b
->enable
== enabled
1508 || b
->enable
== permanent
)
1509 && b
->address
== pc
) /* bp is enabled and matches pc */
1511 if (overlay_debugging
&&
1512 section_is_overlay (b
->section
) &&
1513 !section_is_mapped (b
->section
))
1514 continue; /* unmapped overlay -- can't be a match */
1515 else if (b
->enable
== permanent
)
1516 return permanent_breakpoint_here
;
1518 any_breakpoint_here
= 1;
1521 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1525 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1526 but it only returns true if there is actually a breakpoint inserted
1530 breakpoint_inserted_here_p (CORE_ADDR pc
)
1532 register struct breakpoint
*b
;
1536 && b
->address
== pc
) /* bp is inserted and matches pc */
1538 if (overlay_debugging
&&
1539 section_is_overlay (b
->section
) &&
1540 !section_is_mapped (b
->section
))
1541 continue; /* unmapped overlay -- can't be a match */
1549 /* Return nonzero if FRAME is a dummy frame. We can't use
1550 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1551 much time, at least using get_saved_register on the 68k. This
1552 means that for this function to work right a port must use the
1553 bp_call_dummy breakpoint. */
1556 frame_in_dummy (struct frame_info
*frame
)
1558 struct breakpoint
*b
;
1563 if (USE_GENERIC_DUMMY_FRAMES
)
1564 return generic_pc_in_call_dummy (frame
->pc
, frame
->frame
, frame
->frame
);
1568 if (b
->type
== bp_call_dummy
1569 && b
->frame
== frame
->frame
1570 /* We need to check the PC as well as the frame on the sparc,
1571 for signals.exp in the testsuite. */
1574 - SIZEOF_CALL_DUMMY_WORDS
/ sizeof (LONGEST
) * REGISTER_SIZE
))
1575 && frame
->pc
<= b
->address
)
1581 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1582 PC is valid for process/thread PID. */
1585 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1587 struct breakpoint
*b
;
1590 thread
= pid_to_thread_id (ptid
);
1593 if (b
->enable
!= disabled
1594 && b
->enable
!= shlib_disabled
1595 && b
->enable
!= call_disabled
1597 && (b
->thread
== -1 || b
->thread
== thread
))
1599 if (overlay_debugging
&&
1600 section_is_overlay (b
->section
) &&
1601 !section_is_mapped (b
->section
))
1602 continue; /* unmapped overlay -- can't be a match */
1611 /* bpstat stuff. External routines' interfaces are documented
1615 ep_is_catchpoint (struct breakpoint
*ep
)
1618 (ep
->type
== bp_catch_load
)
1619 || (ep
->type
== bp_catch_unload
)
1620 || (ep
->type
== bp_catch_fork
)
1621 || (ep
->type
== bp_catch_vfork
)
1622 || (ep
->type
== bp_catch_exec
)
1623 || (ep
->type
== bp_catch_catch
)
1624 || (ep
->type
== bp_catch_throw
);
1626 /* ??rehrauer: Add more kinds here, as are implemented... */
1630 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1633 (ep
->type
== bp_catch_load
)
1634 || (ep
->type
== bp_catch_unload
);
1638 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1641 (ep
->type
== bp_catch_catch
)
1642 || (ep
->type
== bp_catch_throw
);
1645 /* Clear a bpstat so that it says we are not at any breakpoint.
1646 Also free any storage that is part of a bpstat. */
1649 bpstat_clear (bpstat
*bsp
)
1660 if (p
->old_val
!= NULL
)
1661 value_free (p
->old_val
);
1668 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1669 is part of the bpstat is copied as well. */
1672 bpstat_copy (bpstat bs
)
1676 bpstat retval
= NULL
;
1681 for (; bs
!= NULL
; bs
= bs
->next
)
1683 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1684 memcpy (tmp
, bs
, sizeof (*tmp
));
1686 /* This is the first thing in the chain. */
1696 /* Find the bpstat associated with this breakpoint */
1699 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1704 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1706 if (bsp
->breakpoint_at
== breakpoint
)
1712 /* Find a step_resume breakpoint associated with this bpstat.
1713 (If there are multiple step_resume bp's on the list, this function
1714 will arbitrarily pick one.)
1716 It is an error to use this function if BPSTAT doesn't contain a
1717 step_resume breakpoint.
1719 See wait_for_inferior's use of this function. */
1721 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1726 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1728 current_thread
= pid_to_thread_id (inferior_ptid
);
1730 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1732 if ((bsp
->breakpoint_at
!= NULL
) &&
1733 (bsp
->breakpoint_at
->type
== bp_step_resume
) &&
1734 (bsp
->breakpoint_at
->thread
== current_thread
||
1735 bsp
->breakpoint_at
->thread
== -1))
1736 return bsp
->breakpoint_at
;
1739 error ("Internal error (no step_resume breakpoint found)");
1743 /* Return the breakpoint number of the first breakpoint we are stopped
1744 at. *BSP upon return is a bpstat which points to the remaining
1745 breakpoints stopped at (but which is not guaranteed to be good for
1746 anything but further calls to bpstat_num).
1747 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1750 bpstat_num (bpstat
*bsp
)
1752 struct breakpoint
*b
;
1755 return 0; /* No more breakpoint values */
1758 b
= (*bsp
)->breakpoint_at
;
1759 *bsp
= (*bsp
)->next
;
1761 return -1; /* breakpoint that's been deleted since */
1763 return b
->number
; /* We have its number */
1767 /* Modify BS so that the actions will not be performed. */
1770 bpstat_clear_actions (bpstat bs
)
1772 for (; bs
!= NULL
; bs
= bs
->next
)
1774 bs
->commands
= NULL
;
1775 if (bs
->old_val
!= NULL
)
1777 value_free (bs
->old_val
);
1783 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1786 cleanup_executing_breakpoints (PTR ignore
)
1788 executing_breakpoint_commands
= 0;
1791 /* Execute all the commands associated with all the breakpoints at this
1792 location. Any of these commands could cause the process to proceed
1793 beyond this point, etc. We look out for such changes by checking
1794 the global "breakpoint_proceeded" after each command. */
1797 bpstat_do_actions (bpstat
*bsp
)
1800 struct cleanup
*old_chain
;
1801 struct command_line
*cmd
;
1803 /* Avoid endless recursion if a `source' command is contained
1805 if (executing_breakpoint_commands
)
1808 executing_breakpoint_commands
= 1;
1809 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
1812 /* Note that (as of this writing), our callers all appear to
1813 be passing us the address of global stop_bpstat. And, if
1814 our calls to execute_control_command cause the inferior to
1815 proceed, that global (and hence, *bsp) will change.
1817 We must be careful to not touch *bsp unless the inferior
1818 has not proceeded. */
1820 /* This pointer will iterate over the list of bpstat's. */
1823 breakpoint_proceeded
= 0;
1824 for (; bs
!= NULL
; bs
= bs
->next
)
1829 execute_control_command (cmd
);
1831 if (breakpoint_proceeded
)
1836 if (breakpoint_proceeded
)
1837 /* The inferior is proceeded by the command; bomb out now.
1838 The bpstat chain has been blown away by wait_for_inferior.
1839 But since execution has stopped again, there is a new bpstat
1840 to look at, so start over. */
1843 bs
->commands
= NULL
;
1846 executing_breakpoint_commands
= 0;
1847 discard_cleanups (old_chain
);
1850 /* This is the normal print function for a bpstat. In the future,
1851 much of this logic could (should?) be moved to bpstat_stop_status,
1852 by having it set different print_it values.
1854 Current scheme: When we stop, bpstat_print() is called. It loops
1855 through the bpstat list of things causing this stop, calling the
1856 print_bp_stop_message function on each one. The behavior of the
1857 print_bp_stop_message function depends on the print_it field of
1858 bpstat. If such field so indicates, call this function here.
1860 Return values from this routine (ultimately used by bpstat_print()
1861 and normal_stop() to decide what to do):
1862 PRINT_NOTHING: Means we already printed all we needed to print,
1863 don't print anything else.
1864 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1865 that something to be followed by a location.
1866 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1867 that something to be followed by a location.
1868 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
1871 static enum print_stop_action
1872 print_it_typical (bpstat bs
)
1875 struct cleanup
*old_chain
;
1876 struct ui_stream
*stb
;
1877 stb
= ui_out_stream_new (uiout
);
1878 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
1880 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1881 which has since been deleted. */
1882 if (bs
->breakpoint_at
== NULL
)
1883 return PRINT_UNKNOWN
;
1885 switch (bs
->breakpoint_at
->type
)
1888 case bp_hardware_breakpoint
:
1890 annotate_breakpoint (bs
->breakpoint_at
->number
);
1891 ui_out_text (uiout
, "\nBreakpoint ");
1892 if (ui_out_is_mi_like_p (uiout
))
1893 ui_out_field_string (uiout
, "reason", "breakpoint-hit");
1894 ui_out_field_int (uiout
, "bkptno", bs
->breakpoint_at
->number
);
1895 ui_out_text (uiout
, ", ");
1896 return PRINT_SRC_AND_LOC
;
1898 /* I think the user probably only wants to see one breakpoint
1899 number, not all of them. */
1900 annotate_breakpoint (bs
->breakpoint_at
->number
);
1901 printf_filtered ("\nBreakpoint %d, ", bs
->breakpoint_at
->number
);
1902 return PRINT_SRC_AND_LOC
;
1906 case bp_shlib_event
:
1907 /* Did we stop because the user set the stop_on_solib_events
1908 variable? (If so, we report this as a generic, "Stopped due
1909 to shlib event" message.) */
1910 printf_filtered ("Stopped due to shared library event\n");
1911 return PRINT_NOTHING
;
1914 case bp_thread_event
:
1915 /* Not sure how we will get here.
1916 GDB should not stop for these breakpoints. */
1917 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
1918 return PRINT_NOTHING
;
1922 annotate_catchpoint (bs
->breakpoint_at
->number
);
1923 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
1924 printf_filtered ("loaded");
1925 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
1926 return PRINT_SRC_AND_LOC
;
1929 case bp_catch_unload
:
1930 annotate_catchpoint (bs
->breakpoint_at
->number
);
1931 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
1932 printf_filtered ("unloaded");
1933 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
1934 return PRINT_SRC_AND_LOC
;
1938 annotate_catchpoint (bs
->breakpoint_at
->number
);
1939 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
1940 printf_filtered ("forked");
1941 printf_filtered (" process %d), ",
1942 bs
->breakpoint_at
->forked_inferior_pid
);
1943 return PRINT_SRC_AND_LOC
;
1946 case bp_catch_vfork
:
1947 annotate_catchpoint (bs
->breakpoint_at
->number
);
1948 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
1949 printf_filtered ("vforked");
1950 printf_filtered (" process %d), ",
1951 bs
->breakpoint_at
->forked_inferior_pid
);
1952 return PRINT_SRC_AND_LOC
;
1956 annotate_catchpoint (bs
->breakpoint_at
->number
);
1957 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
1958 bs
->breakpoint_at
->number
,
1959 bs
->breakpoint_at
->exec_pathname
);
1960 return PRINT_SRC_AND_LOC
;
1963 case bp_catch_catch
:
1964 if (current_exception_event
&&
1965 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
1967 annotate_catchpoint (bs
->breakpoint_at
->number
);
1968 printf_filtered ("\nCatchpoint %d (exception caught), ",
1969 bs
->breakpoint_at
->number
);
1970 printf_filtered ("throw location ");
1971 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
1972 printf_filtered ("%s:%d",
1973 CURRENT_EXCEPTION_THROW_FILE
,
1974 CURRENT_EXCEPTION_THROW_LINE
);
1976 printf_filtered ("unknown");
1978 printf_filtered (", catch location ");
1979 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
1980 printf_filtered ("%s:%d",
1981 CURRENT_EXCEPTION_CATCH_FILE
,
1982 CURRENT_EXCEPTION_CATCH_LINE
);
1984 printf_filtered ("unknown");
1986 printf_filtered ("\n");
1987 /* don't bother to print location frame info */
1988 return PRINT_SRC_ONLY
;
1992 /* really throw, some other bpstat will handle it */
1993 return PRINT_UNKNOWN
;
1997 case bp_catch_throw
:
1998 if (current_exception_event
&&
1999 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2001 annotate_catchpoint (bs
->breakpoint_at
->number
);
2002 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2003 bs
->breakpoint_at
->number
);
2004 printf_filtered ("throw location ");
2005 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2006 printf_filtered ("%s:%d",
2007 CURRENT_EXCEPTION_THROW_FILE
,
2008 CURRENT_EXCEPTION_THROW_LINE
);
2010 printf_filtered ("unknown");
2012 printf_filtered (", catch location ");
2013 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2014 printf_filtered ("%s:%d",
2015 CURRENT_EXCEPTION_CATCH_FILE
,
2016 CURRENT_EXCEPTION_CATCH_LINE
);
2018 printf_filtered ("unknown");
2020 printf_filtered ("\n");
2021 /* don't bother to print location frame info */
2022 return PRINT_SRC_ONLY
;
2026 /* really catch, some other bpstat will handle it */
2027 return PRINT_UNKNOWN
;
2032 case bp_hardware_watchpoint
:
2033 if (bs
->old_val
!= NULL
)
2035 annotate_watchpoint (bs
->breakpoint_at
->number
);
2037 if (ui_out_is_mi_like_p (uiout
))
2038 ui_out_field_string (uiout
, "reason", "watchpoint-trigger");
2039 mention (bs
->breakpoint_at
);
2040 ui_out_tuple_begin (uiout
, "value");
2041 ui_out_text (uiout
, "\nOld value = ");
2042 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2043 ui_out_field_stream (uiout
, "old", stb
);
2044 ui_out_text (uiout
, "\nNew value = ");
2045 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2046 ui_out_field_stream (uiout
, "new", stb
);
2047 ui_out_tuple_end (uiout
);
2048 ui_out_text (uiout
, "\n");
2050 mention (bs
->breakpoint_at
);
2051 printf_filtered ("\nOld value = ");
2052 value_print (bs
->old_val
, gdb_stdout
, 0, Val_pretty_default
);
2053 printf_filtered ("\nNew value = ");
2054 value_print (bs
->breakpoint_at
->val
, gdb_stdout
, 0,
2055 Val_pretty_default
);
2056 printf_filtered ("\n");
2058 value_free (bs
->old_val
);
2061 /* More than one watchpoint may have been triggered. */
2062 return PRINT_UNKNOWN
;
2065 case bp_read_watchpoint
:
2067 if (ui_out_is_mi_like_p (uiout
))
2068 ui_out_field_string (uiout
, "reason", "read-watchpoint-trigger");
2069 mention (bs
->breakpoint_at
);
2070 ui_out_tuple_begin (uiout
, "value");
2071 ui_out_text (uiout
, "\nValue = ");
2072 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2073 ui_out_field_stream (uiout
, "value", stb
);
2074 ui_out_tuple_end (uiout
);
2075 ui_out_text (uiout
, "\n");
2077 mention (bs
->breakpoint_at
);
2078 printf_filtered ("\nValue = ");
2079 value_print (bs
->breakpoint_at
->val
, gdb_stdout
, 0,
2080 Val_pretty_default
);
2081 printf_filtered ("\n");
2083 return PRINT_UNKNOWN
;
2086 case bp_access_watchpoint
:
2088 if (bs
->old_val
!= NULL
)
2090 annotate_watchpoint (bs
->breakpoint_at
->number
);
2091 if (ui_out_is_mi_like_p (uiout
))
2092 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2093 mention (bs
->breakpoint_at
);
2094 ui_out_tuple_begin (uiout
, "value");
2095 ui_out_text (uiout
, "\nOld value = ");
2096 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2097 ui_out_field_stream (uiout
, "old", stb
);
2098 value_free (bs
->old_val
);
2100 ui_out_text (uiout
, "\nNew value = ");
2104 mention (bs
->breakpoint_at
);
2105 if (ui_out_is_mi_like_p (uiout
))
2106 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2107 ui_out_tuple_begin (uiout
, "value");
2108 ui_out_text (uiout
, "\nValue = ");
2110 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0,Val_pretty_default
);
2111 ui_out_field_stream (uiout
, "new", stb
);
2112 ui_out_tuple_end (uiout
);
2113 ui_out_text (uiout
, "\n");
2115 if (bs
->old_val
!= NULL
)
2117 annotate_watchpoint (bs
->breakpoint_at
->number
);
2118 mention (bs
->breakpoint_at
);
2119 printf_filtered ("\nOld value = ");
2120 value_print (bs
->old_val
, gdb_stdout
, 0, Val_pretty_default
);
2121 value_free (bs
->old_val
);
2123 printf_filtered ("\nNew value = ");
2127 mention (bs
->breakpoint_at
);
2128 printf_filtered ("\nValue = ");
2130 value_print (bs
->breakpoint_at
->val
, gdb_stdout
, 0,
2131 Val_pretty_default
);
2132 printf_filtered ("\n");
2134 return PRINT_UNKNOWN
;
2137 /* Fall through, we don't deal with these types of breakpoints
2142 if (ui_out_is_mi_like_p (uiout
))
2143 ui_out_field_string (uiout
, "reason", "function-finished");
2145 return PRINT_UNKNOWN
;
2150 if (ui_out_is_mi_like_p (uiout
))
2151 ui_out_field_string (uiout
, "reason", "location-reached");
2153 return PRINT_UNKNOWN
;
2158 case bp_longjmp_resume
:
2159 case bp_step_resume
:
2160 case bp_through_sigtramp
:
2161 case bp_watchpoint_scope
:
2164 return PRINT_UNKNOWN
;
2168 /* Generic routine for printing messages indicating why we
2169 stopped. The behavior of this function depends on the value
2170 'print_it' in the bpstat structure. Under some circumstances we
2171 may decide not to print anything here and delegate the task to
2174 static enum print_stop_action
2175 print_bp_stop_message (bpstat bs
)
2177 switch (bs
->print_it
)
2180 /* Nothing should be printed for this bpstat entry. */
2181 return PRINT_UNKNOWN
;
2185 /* We still want to print the frame, but we already printed the
2186 relevant messages. */
2187 return PRINT_SRC_AND_LOC
;
2190 case print_it_normal
:
2191 /* Normal case, we handle everything in print_it_typical. */
2192 return print_it_typical (bs
);
2195 internal_error (__FILE__
, __LINE__
,
2196 "print_bp_stop_message: unrecognized enum value");
2201 /* Print a message indicating what happened. This is called from
2202 normal_stop(). The input to this routine is the head of the bpstat
2203 list - a list of the eventpoints that caused this stop. This
2204 routine calls the generic print routine for printing a message
2205 about reasons for stopping. This will print (for example) the
2206 "Breakpoint n," part of the output. The return value of this
2209 PRINT_UNKNOWN: Means we printed nothing
2210 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2211 code to print the location. An example is
2212 "Breakpoint 1, " which should be followed by
2214 PRINT_SRC_ONLY: Means we printed something, but there is no need
2215 to also print the location part of the message.
2216 An example is the catch/throw messages, which
2217 don't require a location appended to the end.
2218 PRINT_NOTHING: We have done some printing and we don't need any
2219 further info to be printed.*/
2221 enum print_stop_action
2222 bpstat_print (bpstat bs
)
2226 /* Maybe another breakpoint in the chain caused us to stop.
2227 (Currently all watchpoints go on the bpstat whether hit or not.
2228 That probably could (should) be changed, provided care is taken
2229 with respect to bpstat_explains_signal). */
2230 for (; bs
; bs
= bs
->next
)
2232 val
= print_bp_stop_message (bs
);
2233 if (val
== PRINT_SRC_ONLY
2234 || val
== PRINT_SRC_AND_LOC
2235 || val
== PRINT_NOTHING
)
2239 /* We reached the end of the chain, or we got a null BS to start
2240 with and nothing was printed. */
2241 return PRINT_UNKNOWN
;
2244 /* Evaluate the expression EXP and return 1 if value is zero.
2245 This is used inside a catch_errors to evaluate the breakpoint condition.
2246 The argument is a "struct expression *" that has been cast to char * to
2247 make it pass through catch_errors. */
2250 breakpoint_cond_eval (PTR exp
)
2252 value_ptr mark
= value_mark ();
2253 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2254 value_free_to_mark (mark
);
2258 /* Allocate a new bpstat and chain it to the current one. */
2261 bpstat_alloc (struct breakpoint
*b
, bpstat cbs
/* Current "bs" value */ )
2265 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2267 bs
->breakpoint_at
= b
;
2268 /* If the condition is false, etc., don't do the commands. */
2269 bs
->commands
= NULL
;
2271 bs
->print_it
= print_it_normal
;
2275 /* Possible return values for watchpoint_check (this can't be an enum
2276 because of check_errors). */
2277 /* The watchpoint has been deleted. */
2278 #define WP_DELETED 1
2279 /* The value has changed. */
2280 #define WP_VALUE_CHANGED 2
2281 /* The value has not changed. */
2282 #define WP_VALUE_NOT_CHANGED 3
2284 #define BP_TEMPFLAG 1
2285 #define BP_HARDWAREFLAG 2
2287 /* Check watchpoint condition. */
2290 watchpoint_check (PTR p
)
2292 bpstat bs
= (bpstat
) p
;
2293 struct breakpoint
*b
;
2294 struct frame_info
*fr
;
2295 int within_current_scope
;
2297 b
= bs
->breakpoint_at
;
2299 if (b
->exp_valid_block
== NULL
)
2300 within_current_scope
= 1;
2303 /* There is no current frame at this moment. If we're going to have
2304 any chance of handling watchpoints on local variables, we'll need
2305 the frame chain (so we can determine if we're in scope). */
2306 reinit_frame_cache ();
2307 fr
= find_frame_addr_in_frame_chain (b
->watchpoint_frame
);
2308 within_current_scope
= (fr
!= NULL
);
2309 if (within_current_scope
)
2310 /* If we end up stopping, the current frame will get selected
2311 in normal_stop. So this call to select_frame won't affect
2313 select_frame (fr
, -1);
2316 if (within_current_scope
)
2318 /* We use value_{,free_to_}mark because it could be a
2319 *long* time before we return to the command level and
2320 call free_all_values. We can't call free_all_values because
2321 we might be in the middle of evaluating a function call. */
2323 value_ptr mark
= value_mark ();
2324 value_ptr new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
2325 if (!value_equal (b
->val
, new_val
))
2327 release_value (new_val
);
2328 value_free_to_mark (mark
);
2329 bs
->old_val
= b
->val
;
2331 /* We will stop here */
2332 return WP_VALUE_CHANGED
;
2336 /* Nothing changed, don't do anything. */
2337 value_free_to_mark (mark
);
2338 /* We won't stop here */
2339 return WP_VALUE_NOT_CHANGED
;
2344 /* This seems like the only logical thing to do because
2345 if we temporarily ignored the watchpoint, then when
2346 we reenter the block in which it is valid it contains
2347 garbage (in the case of a function, it may have two
2348 garbage values, one before and one after the prologue).
2349 So we can't even detect the first assignment to it and
2350 watch after that (since the garbage may or may not equal
2351 the first value assigned). */
2352 /* We print all the stop information in print_it_typical(), but
2353 in this case, by the time we call print_it_typical() this bp
2354 will be deleted already. So we have no choice but print the
2355 information here. */
2357 if (ui_out_is_mi_like_p (uiout
))
2358 ui_out_field_string (uiout
, "reason", "watchpoint-scope");
2359 ui_out_text (uiout
, "\nWatchpoint ");
2360 ui_out_field_int (uiout
, "wpnum", bs
->breakpoint_at
->number
);
2361 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2362 which its expression is valid.\n");
2365 Watchpoint %d deleted because the program has left the block in\n\
2366 which its expression is valid.\n", bs
->breakpoint_at
->number
);
2369 if (b
->related_breakpoint
)
2370 b
->related_breakpoint
->disposition
= del_at_next_stop
;
2371 b
->disposition
= del_at_next_stop
;
2377 /* Get a bpstat associated with having just stopped at address *PC
2378 and frame address CORE_ADDRESS. Update *PC to point at the
2379 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2380 if this is known to not be a real breakpoint (it could still be a
2381 watchpoint, though). */
2383 /* Determine whether we stopped at a breakpoint, etc, or whether we
2384 don't understand this stop. Result is a chain of bpstat's such that:
2386 if we don't understand the stop, the result is a null pointer.
2388 if we understand why we stopped, the result is not null.
2390 Each element of the chain refers to a particular breakpoint or
2391 watchpoint at which we have stopped. (We may have stopped for
2392 several reasons concurrently.)
2394 Each element of the chain has valid next, breakpoint_at,
2395 commands, FIXME??? fields. */
2398 bpstat_stop_status (CORE_ADDR
*pc
, int not_a_breakpoint
)
2400 register struct breakpoint
*b
, *temp
;
2402 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2403 int real_breakpoint
= 0;
2404 /* Root of the chain of bpstat's */
2405 struct bpstats root_bs
[1];
2406 /* Pointer to the last thing in the chain currently. */
2407 bpstat bs
= root_bs
;
2408 static char message1
[] =
2409 "Error evaluating expression for watchpoint %d\n";
2410 char message
[sizeof (message1
) + 30 /* slop */ ];
2412 /* Get the address where the breakpoint would have been.
2413 The "not_a_breakpoint" argument is meant to distinguish
2414 between a breakpoint trap event and a trace/singlestep
2415 trap event. For a trace/singlestep trap event, we would
2416 not want to subtract DECR_PC_AFTER_BREAK from the PC. */
2418 bp_addr
= *pc
- (not_a_breakpoint
&& !SOFTWARE_SINGLE_STEP_P () ?
2419 0 : DECR_PC_AFTER_BREAK
);
2421 ALL_BREAKPOINTS_SAFE (b
, temp
)
2423 if (b
->enable
== disabled
2424 || b
->enable
== shlib_disabled
2425 || b
->enable
== call_disabled
)
2428 if (b
->type
!= bp_watchpoint
2429 && b
->type
!= bp_hardware_watchpoint
2430 && b
->type
!= bp_read_watchpoint
2431 && b
->type
!= bp_access_watchpoint
2432 && b
->type
!= bp_hardware_breakpoint
2433 && b
->type
!= bp_catch_fork
2434 && b
->type
!= bp_catch_vfork
2435 && b
->type
!= bp_catch_exec
2436 && b
->type
!= bp_catch_catch
2437 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2438 if (b
->address
!= bp_addr
|| /* address doesn't match or */
2439 (overlay_debugging
&& /* overlay doesn't match */
2440 section_is_overlay (b
->section
) &&
2441 !section_is_mapped (b
->section
)))
2444 if (b
->type
== bp_hardware_breakpoint
2445 && b
->address
!= (*pc
- DECR_PC_AFTER_HW_BREAK
))
2448 /* Is this a catchpoint of a load or unload? If so, did we
2449 get a load or unload of the specified library? If not,
2451 if ((b
->type
== bp_catch_load
)
2452 #if defined(SOLIB_HAVE_LOAD_EVENT)
2453 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2454 || ((b
->dll_pathname
!= NULL
)
2455 && (strcmp (b
->dll_pathname
,
2456 SOLIB_LOADED_LIBRARY_PATHNAME (
2457 PIDGET (inferior_ptid
)))
2463 if ((b
->type
== bp_catch_unload
)
2464 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2465 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2466 || ((b
->dll_pathname
!= NULL
)
2467 && (strcmp (b
->dll_pathname
,
2468 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2469 PIDGET (inferior_ptid
)))
2475 if ((b
->type
== bp_catch_fork
)
2476 && !target_has_forked (PIDGET (inferior_ptid
),
2477 &b
->forked_inferior_pid
))
2480 if ((b
->type
== bp_catch_vfork
)
2481 && !target_has_vforked (PIDGET (inferior_ptid
),
2482 &b
->forked_inferior_pid
))
2485 if ((b
->type
== bp_catch_exec
)
2486 && !target_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2489 if (ep_is_exception_catchpoint (b
) &&
2490 !(current_exception_event
= target_get_current_exception_event ()))
2493 /* Come here if it's a watchpoint, or if the break address matches */
2495 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
2497 /* Watchpoints may change this, if not found to have triggered. */
2501 sprintf (message
, message1
, b
->number
);
2502 if (b
->type
== bp_watchpoint
||
2503 b
->type
== bp_hardware_watchpoint
)
2505 switch (catch_errors (watchpoint_check
, bs
, message
,
2509 /* We've already printed what needs to be printed. */
2510 /* Actually this is superfluous, because by the time we
2511 call print_it_typical() the wp will be already deleted,
2512 and the function will return immediately. */
2513 bs
->print_it
= print_it_done
;
2516 case WP_VALUE_CHANGED
:
2520 case WP_VALUE_NOT_CHANGED
:
2522 bs
->print_it
= print_it_noop
;
2529 /* Error from catch_errors. */
2530 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2531 if (b
->related_breakpoint
)
2532 b
->related_breakpoint
->disposition
= del_at_next_stop
;
2533 b
->disposition
= del_at_next_stop
;
2534 /* We've already printed what needs to be printed. */
2535 bs
->print_it
= print_it_done
;
2541 else if (b
->type
== bp_read_watchpoint
||
2542 b
->type
== bp_access_watchpoint
)
2548 addr
= target_stopped_data_address ();
2551 for (v
= b
->val_chain
; v
; v
= v
->next
)
2553 if (VALUE_LVAL (v
) == lval_memory
2554 && ! VALUE_LAZY (v
))
2556 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
2558 if (v
== b
->val_chain
2559 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2560 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2564 vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
2565 /* Exact match not required. Within range is
2567 if (addr
>= vaddr
&&
2568 addr
< vaddr
+ TYPE_LENGTH (VALUE_TYPE (v
)))
2574 switch (catch_errors (watchpoint_check
, bs
, message
,
2578 /* We've already printed what needs to be printed. */
2579 bs
->print_it
= print_it_done
;
2582 case WP_VALUE_CHANGED
:
2583 if (b
->type
== bp_read_watchpoint
)
2585 /* Don't stop: read watchpoints shouldn't fire if
2586 the value has changed. This is for targets which
2587 cannot set read-only watchpoints. */
2588 bs
->print_it
= print_it_noop
;
2594 case WP_VALUE_NOT_CHANGED
:
2601 /* Error from catch_errors. */
2602 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2603 if (b
->related_breakpoint
)
2604 b
->related_breakpoint
->disposition
= del_at_next_stop
;
2605 b
->disposition
= del_at_next_stop
;
2606 /* We've already printed what needs to be printed. */
2607 bs
->print_it
= print_it_done
;
2610 else /* found == 0 */
2612 /* This is a case where some watchpoint(s) triggered,
2613 but not at the address of this watchpoint (FOUND
2614 was left zero). So don't print anything for this
2616 bs
->print_it
= print_it_noop
;
2623 /* By definition, an encountered breakpoint is a triggered
2627 real_breakpoint
= 1;
2631 b
->frame
!= (get_current_frame ())->frame
)
2635 int value_is_zero
= 0;
2639 /* Need to select the frame, with all that implies
2640 so that the conditions will have the right context. */
2641 select_frame (get_current_frame (), 0);
2643 = catch_errors (breakpoint_cond_eval
, (b
->cond
),
2644 "Error in testing breakpoint condition:\n",
2646 /* FIXME-someday, should give breakpoint # */
2649 if (b
->cond
&& value_is_zero
)
2652 /* Don't consider this a hit. */
2655 else if (b
->ignore_count
> 0)
2658 annotate_ignore_count_change ();
2663 /* We will stop here */
2664 if (b
->disposition
== disable
)
2665 b
->enable
= disabled
;
2666 bs
->commands
= b
->commands
;
2670 (STREQ ("silent", bs
->commands
->line
) ||
2671 (xdb_commands
&& STREQ ("Q", bs
->commands
->line
))))
2673 bs
->commands
= bs
->commands
->next
;
2678 /* Print nothing for this entry if we dont stop or if we dont print. */
2679 if (bs
->stop
== 0 || bs
->print
== 0)
2680 bs
->print_it
= print_it_noop
;
2683 bs
->next
= NULL
; /* Terminate the chain */
2684 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2686 if (real_breakpoint
&& bs
)
2688 if (bs
->breakpoint_at
->type
== bp_hardware_breakpoint
)
2690 if (DECR_PC_AFTER_HW_BREAK
!= 0)
2692 *pc
= *pc
- DECR_PC_AFTER_HW_BREAK
;
2698 if (DECR_PC_AFTER_BREAK
!= 0 || must_shift_inst_regs
)
2701 #if defined (SHIFT_INST_REGS)
2703 #else /* No SHIFT_INST_REGS. */
2705 #endif /* No SHIFT_INST_REGS. */
2710 /* The value of a hardware watchpoint hasn't changed, but the
2711 intermediate memory locations we are watching may have. */
2712 if (bs
&& !bs
->stop
&&
2713 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
2714 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
2715 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
2717 remove_breakpoints ();
2718 insert_breakpoints ();
2723 /* Tell what to do about this bpstat. */
2725 bpstat_what (bpstat bs
)
2727 /* Classify each bpstat as one of the following. */
2730 /* This bpstat element has no effect on the main_action. */
2733 /* There was a watchpoint, stop but don't print. */
2736 /* There was a watchpoint, stop and print. */
2739 /* There was a breakpoint but we're not stopping. */
2742 /* There was a breakpoint, stop but don't print. */
2745 /* There was a breakpoint, stop and print. */
2748 /* We hit the longjmp breakpoint. */
2751 /* We hit the longjmp_resume breakpoint. */
2754 /* We hit the step_resume breakpoint. */
2757 /* We hit the through_sigtramp breakpoint. */
2760 /* We hit the shared library event breakpoint. */
2763 /* We caught a shared library event. */
2766 /* This is just used to count how many enums there are. */
2770 /* Here is the table which drives this routine. So that we can
2771 format it pretty, we define some abbreviations for the
2772 enum bpstat_what codes. */
2773 #define kc BPSTAT_WHAT_KEEP_CHECKING
2774 #define ss BPSTAT_WHAT_STOP_SILENT
2775 #define sn BPSTAT_WHAT_STOP_NOISY
2776 #define sgl BPSTAT_WHAT_SINGLE
2777 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2778 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2779 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2780 #define sr BPSTAT_WHAT_STEP_RESUME
2781 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2782 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2783 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2785 /* "Can't happen." Might want to print an error message.
2786 abort() is not out of the question, but chances are GDB is just
2787 a bit confused, not unusable. */
2788 #define err BPSTAT_WHAT_STOP_NOISY
2790 /* Given an old action and a class, come up with a new action. */
2791 /* One interesting property of this table is that wp_silent is the same
2792 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2793 after stopping, the check for whether to step over a breakpoint
2794 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2795 reference to how we stopped. We retain separate wp_silent and
2796 bp_silent codes in case we want to change that someday.
2798 Another possibly interesting property of this table is that
2799 there's a partial ordering, priority-like, of the actions. Once
2800 you've decided that some action is appropriate, you'll never go
2801 back and decide something of a lower priority is better. The
2804 kc < clr sgl shl shlr slr sn sr ss ts
2805 sgl < clrs shl shlr slr sn sr ss ts
2806 slr < err shl shlr sn sr ss ts
2807 clr < clrs err shl shlr sn sr ss ts
2808 clrs < err shl shlr sn sr ss ts
2809 ss < shl shlr sn sr ts
2816 What I think this means is that we don't need a damned table
2817 here. If you just put the rows and columns in the right order,
2818 it'd look awfully regular. We could simply walk the bpstat list
2819 and choose the highest priority action we find, with a little
2820 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2821 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2822 is messy anyway). */
2824 /* step_resume entries: a step resume breakpoint overrides another
2825 breakpoint of signal handling (see comment in wait_for_inferior
2826 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2827 /* We handle the through_sigtramp_breakpoint the same way; having both
2828 one of those and a step_resume_breakpoint is probably very rare (?). */
2830 static const enum bpstat_what_main_action
2831 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
2834 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2837 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, ts
, shl
, shlr
},
2839 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2841 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2843 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, ts
, shl
, shlr
},
2845 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2847 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2849 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, ts
, shl
, shlr
},
2851 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, ts
, shl
, shlr
},
2853 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, ts
, shl
, shlr
},
2855 {ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, shl
, shlr
},
2857 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, shl
, ts
, shl
, shlr
},
2859 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, ts
, shlr
, shlr
}
2874 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
2875 struct bpstat_what retval
;
2877 retval
.call_dummy
= 0;
2878 for (; bs
!= NULL
; bs
= bs
->next
)
2880 enum class bs_class
= no_effect
;
2881 if (bs
->breakpoint_at
== NULL
)
2882 /* I suspect this can happen if it was a momentary breakpoint
2883 which has since been deleted. */
2885 switch (bs
->breakpoint_at
->type
)
2891 case bp_hardware_breakpoint
:
2897 bs_class
= bp_noisy
;
2899 bs_class
= bp_silent
;
2902 bs_class
= bp_nostop
;
2905 case bp_hardware_watchpoint
:
2906 case bp_read_watchpoint
:
2907 case bp_access_watchpoint
:
2911 bs_class
= wp_noisy
;
2913 bs_class
= wp_silent
;
2916 /* There was a watchpoint, but we're not stopping.
2917 This requires no further action. */
2918 bs_class
= no_effect
;
2921 bs_class
= long_jump
;
2923 case bp_longjmp_resume
:
2924 bs_class
= long_resume
;
2926 case bp_step_resume
:
2929 bs_class
= step_resume
;
2932 /* It is for the wrong frame. */
2933 bs_class
= bp_nostop
;
2935 case bp_through_sigtramp
:
2936 bs_class
= through_sig
;
2938 case bp_watchpoint_scope
:
2939 bs_class
= bp_nostop
;
2941 case bp_shlib_event
:
2942 bs_class
= shlib_event
;
2944 case bp_thread_event
:
2945 bs_class
= bp_nostop
;
2948 case bp_catch_unload
:
2949 /* Only if this catchpoint triggered should we cause the
2950 step-out-of-dld behaviour. Otherwise, we ignore this
2953 bs_class
= catch_shlib_event
;
2955 bs_class
= no_effect
;
2958 case bp_catch_vfork
:
2963 bs_class
= bp_noisy
;
2965 bs_class
= bp_silent
;
2968 /* There was a catchpoint, but we're not stopping.
2969 This requires no further action. */
2970 bs_class
= no_effect
;
2972 case bp_catch_catch
:
2973 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
2974 bs_class
= bp_nostop
;
2976 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
2978 case bp_catch_throw
:
2979 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
2980 bs_class
= bp_nostop
;
2982 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
2985 /* Make sure the action is stop (silent or noisy),
2986 so infrun.c pops the dummy frame. */
2987 bs_class
= bp_silent
;
2988 retval
.call_dummy
= 1;
2991 current_action
= table
[(int) bs_class
][(int) current_action
];
2993 retval
.main_action
= current_action
;
2997 /* Nonzero if we should step constantly (e.g. watchpoints on machines
2998 without hardware support). This isn't related to a specific bpstat,
2999 just to things like whether watchpoints are set. */
3002 bpstat_should_step (void)
3004 struct breakpoint
*b
;
3006 if (b
->enable
== enabled
&& b
->type
== bp_watchpoint
)
3011 /* Nonzero if there are enabled hardware watchpoints. */
3013 bpstat_have_active_hw_watchpoints (void)
3015 struct breakpoint
*b
;
3017 if ((b
->enable
== enabled
) &&
3019 ((b
->type
== bp_hardware_watchpoint
) ||
3020 (b
->type
== bp_read_watchpoint
) ||
3021 (b
->type
== bp_access_watchpoint
)))
3027 /* Given a bpstat that records zero or more triggered eventpoints, this
3028 function returns another bpstat which contains only the catchpoints
3029 on that first list, if any. */
3031 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3033 struct bpstats root_bs
[1];
3034 bpstat bs
= root_bs
;
3035 struct breakpoint
*ep
;
3038 bpstat_clear (cp_list
);
3039 root_bs
->next
= NULL
;
3041 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3043 /* Is this eventpoint a catchpoint? If not, ignore it. */
3044 ep
= ep_list
->breakpoint_at
;
3047 if ((ep
->type
!= bp_catch_load
) &&
3048 (ep
->type
!= bp_catch_unload
) &&
3049 (ep
->type
!= bp_catch_catch
) &&
3050 (ep
->type
!= bp_catch_throw
))
3051 /* pai: (temp) ADD fork/vfork here!! */
3054 /* Yes; add it to the list. */
3055 bs
= bpstat_alloc (ep
, bs
);
3060 #if defined(SOLIB_ADD)
3061 /* Also, for each triggered catchpoint, tag it with the name of
3062 the library that caused this trigger. (We copy the name now,
3063 because it's only guaranteed to be available NOW, when the
3064 catchpoint triggers. Clients who may wish to know the name
3065 later must get it from the catchpoint itself.) */
3066 if (ep
->triggered_dll_pathname
!= NULL
)
3067 xfree (ep
->triggered_dll_pathname
);
3068 if (ep
->type
== bp_catch_load
)
3069 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3070 PIDGET (inferior_ptid
));
3072 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3073 PIDGET (inferior_ptid
));
3075 dll_pathname
= NULL
;
3079 ep
->triggered_dll_pathname
= (char *)
3080 xmalloc (strlen (dll_pathname
) + 1);
3081 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3084 ep
->triggered_dll_pathname
= NULL
;
3090 /* Print B to gdb_stdout. */
3092 print_one_breakpoint (struct breakpoint
*b
,
3093 CORE_ADDR
*last_addr
)
3095 register struct command_line
*l
;
3096 register struct symbol
*sym
;
3097 struct ep_type_description
3102 static struct ep_type_description bptypes
[] =
3104 {bp_none
, "?deleted?"},
3105 {bp_breakpoint
, "breakpoint"},
3106 {bp_hardware_breakpoint
, "hw breakpoint"},
3107 {bp_until
, "until"},
3108 {bp_finish
, "finish"},
3109 {bp_watchpoint
, "watchpoint"},
3110 {bp_hardware_watchpoint
, "hw watchpoint"},
3111 {bp_read_watchpoint
, "read watchpoint"},
3112 {bp_access_watchpoint
, "acc watchpoint"},
3113 {bp_longjmp
, "longjmp"},
3114 {bp_longjmp_resume
, "longjmp resume"},
3115 {bp_step_resume
, "step resume"},
3116 {bp_through_sigtramp
, "sigtramp"},
3117 {bp_watchpoint_scope
, "watchpoint scope"},
3118 {bp_call_dummy
, "call dummy"},
3119 {bp_shlib_event
, "shlib events"},
3120 {bp_thread_event
, "thread events"},
3121 {bp_catch_load
, "catch load"},
3122 {bp_catch_unload
, "catch unload"},
3123 {bp_catch_fork
, "catch fork"},
3124 {bp_catch_vfork
, "catch vfork"},
3125 {bp_catch_exec
, "catch exec"},
3126 {bp_catch_catch
, "catch catch"},
3127 {bp_catch_throw
, "catch throw"}
3130 static char *bpdisps
[] =
3131 {"del", "dstp", "dis", "keep"};
3132 static char bpenables
[] = "nynny";
3133 char wrap_indent
[80];
3135 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3136 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3141 ui_out_tuple_begin (uiout
, "bkpt");
3147 ui_out_field_int (uiout
, "number", b
->number
);
3149 printf_filtered ("%-3d ", b
->number
);
3154 if (((int) b
->type
> (sizeof (bptypes
) / sizeof (bptypes
[0])))
3155 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3156 internal_error (__FILE__
, __LINE__
,
3157 "bptypes table does not describe type #%d.",
3160 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3162 printf_filtered ("%-14s ", bptypes
[(int) b
->type
].description
);
3168 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3170 printf_filtered ("%-4s ", bpdisps
[(int) b
->disposition
]);
3176 ui_out_field_fmt (uiout
, "enabled", "%c", bpenables
[(int) b
->enable
]);
3177 ui_out_spaces (uiout
, 2);
3179 printf_filtered ("%-3c ", bpenables
[(int) b
->enable
]);
3183 strcpy (wrap_indent
, " ");
3186 if (TARGET_ADDR_BIT
<= 32)
3187 strcat (wrap_indent
, " ");
3189 strcat (wrap_indent
, " ");
3194 internal_error (__FILE__
, __LINE__
,
3195 "print_one_breakpoint: bp_none encountered\n");
3199 case bp_hardware_watchpoint
:
3200 case bp_read_watchpoint
:
3201 case bp_access_watchpoint
:
3202 /* Field 4, the address, is omitted (which makes the columns
3203 not line up too nicely with the headers, but the effect
3204 is relatively readable). */
3207 ui_out_field_skip (uiout
, "addr");
3209 print_expression (b
->exp
, stb
->stream
);
3210 ui_out_field_stream (uiout
, "what", stb
);
3213 print_expression (b
->exp
, gdb_stdout
);
3218 case bp_catch_unload
:
3219 /* Field 4, the address, is omitted (which makes the columns
3220 not line up too nicely with the headers, but the effect
3221 is relatively readable). */
3224 ui_out_field_skip (uiout
, "addr");
3226 if (b
->dll_pathname
== NULL
)
3228 ui_out_field_string (uiout
, "what", "<any library>");
3229 ui_out_spaces (uiout
, 1);
3233 ui_out_text (uiout
, "library \"");
3234 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3235 ui_out_text (uiout
, "\" ");
3239 if (b
->dll_pathname
== NULL
)
3240 printf_filtered ("<any library> ");
3242 printf_filtered ("library \"%s\" ", b
->dll_pathname
);
3247 case bp_catch_vfork
:
3248 /* Field 4, the address, is omitted (which makes the columns
3249 not line up too nicely with the headers, but the effect
3250 is relatively readable). */
3253 ui_out_field_skip (uiout
, "addr");
3255 if (b
->forked_inferior_pid
!= 0)
3257 ui_out_text (uiout
, "process ");
3258 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3259 ui_out_spaces (uiout
, 1);
3263 if (b
->forked_inferior_pid
!= 0)
3264 printf_filtered ("process %d ", b
->forked_inferior_pid
);
3269 /* Field 4, the address, is omitted (which makes the columns
3270 not line up too nicely with the headers, but the effect
3271 is relatively readable). */
3274 ui_out_field_skip (uiout
, "addr");
3276 if (b
->exec_pathname
!= NULL
)
3278 ui_out_text (uiout
, "program \"");
3279 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3280 ui_out_text (uiout
, "\" ");
3284 if (b
->exec_pathname
!= NULL
)
3285 printf_filtered ("program \"%s\" ", b
->exec_pathname
);
3289 case bp_catch_catch
:
3290 /* Field 4, the address, is omitted (which makes the columns
3291 not line up too nicely with the headers, but the effect
3292 is relatively readable). */
3295 ui_out_field_skip (uiout
, "addr");
3297 ui_out_field_string (uiout
, "what", "exception catch");
3298 ui_out_spaces (uiout
, 1);
3301 printf_filtered ("exception catch ");
3305 case bp_catch_throw
:
3306 /* Field 4, the address, is omitted (which makes the columns
3307 not line up too nicely with the headers, but the effect
3308 is relatively readable). */
3311 ui_out_field_skip (uiout
, "addr");
3313 ui_out_field_string (uiout
, "what", "exception throw");
3314 ui_out_spaces (uiout
, 1);
3317 printf_filtered ("exception throw ");
3322 case bp_hardware_breakpoint
:
3326 case bp_longjmp_resume
:
3327 case bp_step_resume
:
3328 case bp_through_sigtramp
:
3329 case bp_watchpoint_scope
:
3331 case bp_shlib_event
:
3332 case bp_thread_event
:
3337 ui_out_field_core_addr (uiout
, "addr", b
->address
);
3340 *last_addr
= b
->address
;
3343 sym
= find_pc_sect_function (b
->address
, b
->section
);
3346 ui_out_text (uiout
, "in ");
3347 ui_out_field_string (uiout
, "func",
3348 SYMBOL_SOURCE_NAME (sym
));
3349 ui_out_wrap_hint (uiout
, wrap_indent
);
3350 ui_out_text (uiout
, " at ");
3352 ui_out_field_string (uiout
, "file", b
->source_file
);
3353 ui_out_text (uiout
, ":");
3354 ui_out_field_int (uiout
, "line", b
->line_number
);
3358 print_address_symbolic (b
->address
, stb
->stream
, demangle
, "");
3359 ui_out_field_stream (uiout
, "at", stb
);
3368 if (TARGET_ADDR_BIT
<= 32)
3369 tmp
= longest_local_hex_string_custom (b
->address
3370 & (CORE_ADDR
) 0xffffffff,
3373 tmp
= longest_local_hex_string_custom (b
->address
, "016l");
3375 printf_filtered ("%s ", tmp
);
3378 *last_addr
= b
->address
;
3381 sym
= find_pc_sect_function (b
->address
, b
->section
);
3384 fputs_filtered ("in ", gdb_stdout
);
3385 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), gdb_stdout
);
3386 wrap_here (wrap_indent
);
3387 fputs_filtered (" at ", gdb_stdout
);
3389 fputs_filtered (b
->source_file
, gdb_stdout
);
3390 printf_filtered (":%d", b
->line_number
);
3393 print_address_symbolic (b
->address
, gdb_stdout
, demangle
, " ");
3398 if (b
->thread
!= -1)
3401 /* FIXME: This seems to be redundant and lost here; see the
3402 "stop only in" line a little further down. */
3403 ui_out_text (uiout
, " thread ");
3404 ui_out_field_int (uiout
, "thread", b
->thread
);
3406 printf_filtered (" thread %d", b
->thread
);
3411 ui_out_text (uiout
, "\n");
3413 printf_filtered ("\n");
3420 ui_out_text (uiout
, "\tstop only in stack frame at ");
3421 ui_out_field_core_addr (uiout
, "frame", b
->frame
);
3422 ui_out_text (uiout
, "\n");
3424 printf_filtered ("\tstop only in stack frame at ");
3425 print_address_numeric (b
->frame
, 1, gdb_stdout
);
3426 printf_filtered ("\n");
3434 ui_out_text (uiout
, "\tstop only if ");
3435 print_expression (b
->cond
, stb
->stream
);
3436 ui_out_field_stream (uiout
, "cond", stb
);
3437 ui_out_text (uiout
, "\n");
3439 printf_filtered ("\tstop only if ");
3440 print_expression (b
->cond
, gdb_stdout
);
3441 printf_filtered ("\n");
3445 if (b
->thread
!= -1)
3447 /* FIXME should make an annotation for this */
3449 ui_out_text (uiout
, "\tstop only in thread ");
3450 ui_out_field_int (uiout
, "thread", b
->thread
);
3451 ui_out_text (uiout
, "\n");
3453 printf_filtered ("\tstop only in thread %d\n", b
->thread
);
3457 if (show_breakpoint_hit_counts
&& b
->hit_count
)
3459 /* FIXME should make an annotation for this */
3461 if (ep_is_catchpoint (b
))
3462 ui_out_text (uiout
, "\tcatchpoint");
3464 ui_out_text (uiout
, "\tbreakpoint");
3465 ui_out_text (uiout
, " already hit ");
3466 ui_out_field_int (uiout
, "times", b
->hit_count
);
3467 if (b
->hit_count
== 1)
3468 ui_out_text (uiout
, " time\n");
3470 ui_out_text (uiout
, " times\n");
3472 if (ep_is_catchpoint (b
))
3473 printf_filtered ("\tcatchpoint");
3475 printf_filtered ("\tbreakpoint");
3476 printf_filtered (" already hit %d time%s\n",
3477 b
->hit_count
, (b
->hit_count
== 1 ? "" : "s"));
3482 /* Output the count also if it is zero, but only if this is
3483 mi. FIXME: Should have a better test for this. */
3484 if (ui_out_is_mi_like_p (uiout
))
3485 if (show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3486 ui_out_field_int (uiout
, "times", b
->hit_count
);
3489 if (b
->ignore_count
)
3493 ui_out_text (uiout
, "\tignore next ");
3494 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3495 ui_out_text (uiout
, " hits\n");
3497 printf_filtered ("\tignore next %d hits\n", b
->ignore_count
);
3501 if ((l
= b
->commands
))
3505 ui_out_tuple_begin (uiout
, "script");
3506 print_command_lines (uiout
, l
, 4);
3507 ui_out_tuple_end (uiout
);
3511 print_command_line (l
, 4, gdb_stdout
);
3517 ui_out_tuple_end (uiout
);
3518 do_cleanups (old_chain
);
3522 struct captured_breakpoint_query_args
3528 do_captured_breakpoint_query (void *data
)
3530 struct captured_breakpoint_query_args
*args
= data
;
3531 register struct breakpoint
*b
;
3532 CORE_ADDR dummy_addr
= 0;
3535 if (args
->bnum
== b
->number
)
3537 print_one_breakpoint (b
, &dummy_addr
);
3545 gdb_breakpoint_query (/* output object, */ int bnum
)
3547 struct captured_breakpoint_query_args args
;
3549 /* For the moment we don't trust print_one_breakpoint() to not throw
3551 return catch_errors (do_captured_breakpoint_query
, &args
,
3552 NULL
, RETURN_MASK_ALL
);
3555 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3556 catchpoints, et.al.). */
3559 user_settable_breakpoint (const struct breakpoint
*b
)
3561 return (b
->type
== bp_breakpoint
3562 || b
->type
== bp_catch_load
3563 || b
->type
== bp_catch_unload
3564 || b
->type
== bp_catch_fork
3565 || b
->type
== bp_catch_vfork
3566 || b
->type
== bp_catch_exec
3567 || b
->type
== bp_catch_catch
3568 || b
->type
== bp_catch_throw
3569 || b
->type
== bp_hardware_breakpoint
3570 || b
->type
== bp_watchpoint
3571 || b
->type
== bp_read_watchpoint
3572 || b
->type
== bp_access_watchpoint
3573 || b
->type
== bp_hardware_watchpoint
);
3576 /* Print information on user settable breakpoint (watchpoint, etc)
3577 number BNUM. If BNUM is -1 print all user settable breakpoints.
3578 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3581 breakpoint_1 (int bnum
, int allflag
)
3583 register struct breakpoint
*b
;
3584 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3585 int nr_printable_breakpoints
;
3587 /* Compute the number of rows in the table. */
3588 nr_printable_breakpoints
= 0;
3591 || bnum
== b
->number
)
3593 if (allflag
|| user_settable_breakpoint (b
))
3594 nr_printable_breakpoints
++;
3599 ui_out_table_begin (uiout
, 6, nr_printable_breakpoints
, "BreakpointTable");
3601 ui_out_table_begin (uiout
, 5, nr_printable_breakpoints
, "BreakpointTable");
3605 if (nr_printable_breakpoints
> 0)
3606 annotate_breakpoints_headers ();
3607 if (nr_printable_breakpoints
> 0)
3609 ui_out_table_header (uiout
, 3, ui_left
, "number", "Num"); /* 1 */
3610 if (nr_printable_breakpoints
> 0)
3612 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3613 if (nr_printable_breakpoints
> 0)
3615 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3616 if (nr_printable_breakpoints
> 0)
3618 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3621 if (nr_printable_breakpoints
> 0)
3623 if (TARGET_ADDR_BIT
<= 32)
3624 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3626 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3628 if (nr_printable_breakpoints
> 0)
3630 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3631 ui_out_table_body (uiout
);
3632 if (nr_printable_breakpoints
> 0)
3633 annotate_breakpoints_table ();
3635 if (nr_printable_breakpoints
> 0)
3637 annotate_breakpoints_headers ();
3639 printf_filtered ("Num ");
3641 printf_filtered ("Type ");
3643 printf_filtered ("Disp ");
3645 printf_filtered ("Enb ");
3649 if (TARGET_ADDR_BIT
<= 32)
3650 printf_filtered ("Address ");
3652 printf_filtered ("Address ");
3655 printf_filtered ("What\n");
3656 annotate_breakpoints_table ();
3662 || bnum
== b
->number
)
3664 /* We only print out user settable breakpoints unless the
3666 if (allflag
|| user_settable_breakpoint (b
))
3667 print_one_breakpoint (b
, &last_addr
);
3672 ui_out_table_end (uiout
);
3675 if (nr_printable_breakpoints
== 0)
3679 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3681 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3685 printf_filtered ("No breakpoints or watchpoints.\n");
3687 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum
);
3692 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3693 that a comparison of an unsigned with -1 is always false. */
3694 if (last_addr
!= (CORE_ADDR
) -1)
3695 set_next_address (last_addr
);
3698 /* FIXME? Should this be moved up so that it is only called when
3699 there have been breakpoints? */
3700 annotate_breakpoints_table_end ();
3705 breakpoints_info (char *bnum_exp
, int from_tty
)
3710 bnum
= parse_and_eval_long (bnum_exp
);
3712 breakpoint_1 (bnum
, 0);
3717 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3722 bnum
= parse_and_eval_long (bnum_exp
);
3724 breakpoint_1 (bnum
, 1);
3727 /* Print a message describing any breakpoints set at PC. */
3730 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
)
3732 register int others
= 0;
3733 register struct breakpoint
*b
;
3736 if (b
->address
== pc
)
3737 if (overlay_debugging
== 0 ||
3738 b
->section
== section
)
3742 printf_filtered ("Note: breakpoint%s ", (others
> 1) ? "s" : "");
3744 if (b
->address
== pc
)
3745 if (overlay_debugging
== 0 ||
3746 b
->section
== section
)
3749 printf_filtered ("%d%s%s ",
3751 ((b
->enable
== disabled
||
3752 b
->enable
== shlib_disabled
||
3753 b
->enable
== call_disabled
) ? " (disabled)"
3754 : b
->enable
== permanent
? " (permanent)"
3757 : ((others
== 1) ? " and" : ""));
3759 printf_filtered ("also set at pc ");
3760 print_address_numeric (pc
, 1, gdb_stdout
);
3761 printf_filtered (".\n");
3765 /* Set the default place to put a breakpoint
3766 for the `break' command with no arguments. */
3769 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3772 default_breakpoint_valid
= valid
;
3773 default_breakpoint_address
= addr
;
3774 default_breakpoint_symtab
= symtab
;
3775 default_breakpoint_line
= line
;
3778 /* Return true iff it is meaningful to use the address member of
3779 BPT. For some breakpoint types, the address member is irrelevant
3780 and it makes no sense to attempt to compare it to other addresses
3781 (or use it for any other purpose either).
3783 More specifically, each of the following breakpoint types will always
3784 have a zero valued address and we don't want check_duplicates() to mark
3785 breakpoints of any of these types to be a duplicate of an actual
3786 breakpoint at address zero:
3789 bp_hardware_watchpoint
3791 bp_access_watchpoint
3798 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3800 enum bptype type
= bpt
->type
;
3802 return (type
!= bp_watchpoint
3803 && type
!= bp_hardware_watchpoint
3804 && type
!= bp_read_watchpoint
3805 && type
!= bp_access_watchpoint
3806 && type
!= bp_catch_exec
3807 && type
!= bp_longjmp_resume
3808 && type
!= bp_catch_fork
3809 && type
!= bp_catch_vfork
);
3812 /* Rescan breakpoints at the same address and section as BPT,
3813 marking the first one as "first" and any others as "duplicates".
3814 This is so that the bpt instruction is only inserted once.
3815 If we have a permanent breakpoint at the same place as BPT, make
3816 that one the official one, and the rest as duplicates. */
3819 check_duplicates (struct breakpoint
*bpt
)
3821 register struct breakpoint
*b
;
3822 register int count
= 0;
3823 struct breakpoint
*perm_bp
= 0;
3824 CORE_ADDR address
= bpt
->address
;
3825 asection
*section
= bpt
->section
;
3827 if (! breakpoint_address_is_meaningful (bpt
))
3831 if (b
->enable
!= disabled
3832 && b
->enable
!= shlib_disabled
3833 && b
->enable
!= call_disabled
3834 && b
->address
== address
3835 && (overlay_debugging
== 0 || b
->section
== section
)
3836 && breakpoint_address_is_meaningful (b
))
3838 /* Have we found a permanent breakpoint? */
3839 if (b
->enable
== permanent
)
3846 b
->duplicate
= count
> 1;
3849 /* If we found a permanent breakpoint at this address, go over the
3850 list again and declare all the other breakpoints there to be the
3854 perm_bp
->duplicate
= 0;
3856 /* Permanent breakpoint should always be inserted. */
3857 if (! perm_bp
->inserted
)
3858 internal_error (__FILE__
, __LINE__
,
3859 "allegedly permanent breakpoint is not "
3860 "actually inserted");
3866 internal_error (__FILE__
, __LINE__
,
3867 "another breakpoint was inserted on top of "
3868 "a permanent breakpoint");
3870 if (b
->enable
!= disabled
3871 && b
->enable
!= shlib_disabled
3872 && b
->enable
!= call_disabled
3873 && b
->address
== address
3874 && (overlay_debugging
== 0 || b
->section
== section
)
3875 && breakpoint_address_is_meaningful (b
))
3881 /* set_raw_breakpoint() is a low level routine for allocating and
3882 partially initializing a breakpoint of type BPTYPE. The newly
3883 created breakpoint's address, section, source file name, and line
3884 number are provided by SAL. The newly created and partially
3885 initialized breakpoint is added to the breakpoint chain and
3886 is also returned as the value of this function.
3888 It is expected that the caller will complete the initialization of
3889 the newly created breakpoint struct as well as output any status
3890 information regarding the creation of a new breakpoint. In
3891 particular, set_raw_breakpoint() does NOT set the breakpoint
3892 number! Care should be taken to not allow an error() to occur
3893 prior to completing the initialization of the breakpoint. If this
3894 should happen, a bogus breakpoint will be left on the chain. */
3897 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
3899 register struct breakpoint
*b
, *b1
;
3901 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
3902 memset (b
, 0, sizeof (*b
));
3903 b
->address
= sal
.pc
;
3904 if (sal
.symtab
== NULL
)
3905 b
->source_file
= NULL
;
3907 b
->source_file
= savestring (sal
.symtab
->filename
,
3908 strlen (sal
.symtab
->filename
));
3909 b
->section
= sal
.section
;
3911 b
->language
= current_language
->la_language
;
3912 b
->input_radix
= input_radix
;
3914 b
->line_number
= sal
.line
;
3915 b
->enable
= enabled
;
3918 b
->ignore_count
= 0;
3921 b
->dll_pathname
= NULL
;
3922 b
->triggered_dll_pathname
= NULL
;
3923 b
->forked_inferior_pid
= 0;
3924 b
->exec_pathname
= NULL
;
3926 /* Add this breakpoint to the end of the chain
3927 so that a list of breakpoints will come out in order
3928 of increasing numbers. */
3930 b1
= breakpoint_chain
;
3932 breakpoint_chain
= b
;
3940 check_duplicates (b
);
3941 breakpoints_changed ();
3947 /* Note that the breakpoint object B describes a permanent breakpoint
3948 instruction, hard-wired into the inferior's code. */
3950 make_breakpoint_permanent (struct breakpoint
*b
)
3952 b
->enable
= permanent
;
3954 /* By definition, permanent breakpoints are already present in the code. */
3958 #ifdef GET_LONGJMP_TARGET
3961 create_longjmp_breakpoint (char *func_name
)
3963 struct symtab_and_line sal
;
3964 struct breakpoint
*b
;
3966 INIT_SAL (&sal
); /* initialize to zeroes */
3967 if (func_name
!= NULL
)
3969 struct minimal_symbol
*m
;
3971 m
= lookup_minimal_symbol_text (func_name
, NULL
,
3972 (struct objfile
*) NULL
);
3974 sal
.pc
= SYMBOL_VALUE_ADDRESS (m
);
3978 sal
.section
= find_pc_overlay (sal
.pc
);
3979 b
= set_raw_breakpoint (sal
,
3980 func_name
!= NULL
? bp_longjmp
: bp_longjmp_resume
);
3982 b
->disposition
= donttouch
;
3983 b
->enable
= disabled
;
3986 b
->addr_string
= xstrdup (func_name
);
3987 b
->number
= internal_breakpoint_number
--;
3990 #endif /* #ifdef GET_LONGJMP_TARGET */
3992 /* Call this routine when stepping and nexting to enable a breakpoint
3993 if we do a longjmp(). When we hit that breakpoint, call
3994 set_longjmp_resume_breakpoint() to figure out where we are going. */
3997 enable_longjmp_breakpoint (void)
3999 register struct breakpoint
*b
;
4002 if (b
->type
== bp_longjmp
)
4004 b
->enable
= enabled
;
4005 check_duplicates (b
);
4010 disable_longjmp_breakpoint (void)
4012 register struct breakpoint
*b
;
4015 if (b
->type
== bp_longjmp
4016 || b
->type
== bp_longjmp_resume
)
4018 b
->enable
= disabled
;
4019 check_duplicates (b
);
4024 create_thread_event_breakpoint (CORE_ADDR address
)
4026 struct breakpoint
*b
;
4027 struct symtab_and_line sal
;
4028 char addr_string
[80]; /* Surely an addr can't be longer than that. */
4030 INIT_SAL (&sal
); /* initialize to zeroes */
4032 sal
.section
= find_pc_overlay (sal
.pc
);
4033 b
= set_raw_breakpoint (sal
, bp_thread_event
);
4035 b
->number
= internal_breakpoint_number
--;
4036 b
->disposition
= donttouch
;
4037 b
->enable
= enabled
;
4038 /* addr_string has to be used or breakpoint_re_set will delete me. */
4039 sprintf (addr_string
, "*0x%s", paddr (b
->address
));
4040 b
->addr_string
= xstrdup (addr_string
);
4046 remove_thread_event_breakpoints (void)
4048 struct breakpoint
*b
, *temp
;
4050 ALL_BREAKPOINTS_SAFE (b
, temp
)
4051 if (b
->type
== bp_thread_event
)
4052 delete_breakpoint (b
);
4057 remove_solib_event_breakpoints (void)
4059 register struct breakpoint
*b
, *temp
;
4061 ALL_BREAKPOINTS_SAFE (b
, temp
)
4062 if (b
->type
== bp_shlib_event
)
4063 delete_breakpoint (b
);
4067 create_solib_event_breakpoint (CORE_ADDR address
)
4069 struct breakpoint
*b
;
4070 struct symtab_and_line sal
;
4072 INIT_SAL (&sal
); /* initialize to zeroes */
4074 sal
.section
= find_pc_overlay (sal
.pc
);
4075 b
= set_raw_breakpoint (sal
, bp_shlib_event
);
4076 b
->number
= internal_breakpoint_number
--;
4077 b
->disposition
= donttouch
;
4082 /* Disable any breakpoints that are on code in shared libraries. Only
4083 apply to enabled breakpoints, disabled ones can just stay disabled. */
4086 disable_breakpoints_in_shlibs (int silent
)
4088 struct breakpoint
*b
;
4089 int disabled_shlib_breaks
= 0;
4091 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4094 #if defined (PC_SOLIB)
4095 if (((b
->type
== bp_breakpoint
) ||
4096 (b
->type
== bp_hardware_breakpoint
)) &&
4097 b
->enable
== enabled
&&
4099 PC_SOLIB (b
->address
))
4101 b
->enable
= shlib_disabled
;
4104 if (!disabled_shlib_breaks
)
4106 target_terminal_ours_for_output ();
4107 warning ("Temporarily disabling shared library breakpoints:");
4109 disabled_shlib_breaks
= 1;
4110 warning ("breakpoint #%d ", b
->number
);
4117 /* Try to reenable any breakpoints in shared libraries. */
4119 re_enable_breakpoints_in_shlibs (void)
4121 struct breakpoint
*b
;
4124 if (b
->enable
== shlib_disabled
)
4128 /* Do not reenable the breakpoint if the shared library
4129 is still not mapped in. */
4130 if (target_read_memory (b
->address
, buf
, 1) == 0)
4131 b
->enable
= enabled
;
4138 solib_load_unload_1 (char *hookname
, int tempflag
, char *dll_pathname
,
4139 char *cond_string
, enum bptype bp_kind
)
4141 struct breakpoint
*b
;
4142 struct symtabs_and_lines sals
;
4143 struct cleanup
*old_chain
;
4144 struct cleanup
*canonical_strings_chain
= NULL
;
4145 char *addr_start
= hookname
;
4146 char *addr_end
= NULL
;
4147 char **canonical
= (char **) NULL
;
4148 int thread
= -1; /* All threads. */
4150 /* Set a breakpoint on the specified hook. */
4151 sals
= decode_line_1 (&hookname
, 1, (struct symtab
*) NULL
, 0, &canonical
);
4152 addr_end
= hookname
;
4154 if (sals
.nelts
== 0)
4156 warning ("Unable to set a breakpoint on dynamic linker callback.");
4157 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4158 warning ("GDB will be unable to track shl_load/shl_unload calls");
4161 if (sals
.nelts
!= 1)
4163 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4164 warning ("GDB will be unable to track shl_load/shl_unload calls");
4168 /* Make sure that all storage allocated in decode_line_1 gets freed
4169 in case the following errors out. */
4170 old_chain
= make_cleanup (xfree
, sals
.sals
);
4171 if (canonical
!= (char **) NULL
)
4173 make_cleanup (xfree
, canonical
);
4174 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
4175 if (canonical
[0] != NULL
)
4176 make_cleanup (xfree
, canonical
[0]);
4179 resolve_sal_pc (&sals
.sals
[0]);
4181 /* Remove the canonical strings from the cleanup, they are needed below. */
4182 if (canonical
!= (char **) NULL
)
4183 discard_cleanups (canonical_strings_chain
);
4185 b
= set_raw_breakpoint (sals
.sals
[0], bp_kind
);
4186 set_breakpoint_count (breakpoint_count
+ 1);
4187 b
->number
= breakpoint_count
;
4189 b
->cond_string
= (cond_string
== NULL
) ?
4190 NULL
: savestring (cond_string
, strlen (cond_string
));
4193 if (canonical
!= (char **) NULL
&& canonical
[0] != NULL
)
4194 b
->addr_string
= canonical
[0];
4195 else if (addr_start
)
4196 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
4198 b
->enable
= enabled
;
4199 b
->disposition
= tempflag
? del
: donttouch
;
4201 if (dll_pathname
== NULL
)
4202 b
->dll_pathname
= NULL
;
4205 b
->dll_pathname
= (char *) xmalloc (strlen (dll_pathname
) + 1);
4206 strcpy (b
->dll_pathname
, dll_pathname
);
4210 do_cleanups (old_chain
);
4214 create_solib_load_event_breakpoint (char *hookname
, int tempflag
,
4215 char *dll_pathname
, char *cond_string
)
4217 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4218 cond_string
, bp_catch_load
);
4222 create_solib_unload_event_breakpoint (char *hookname
, int tempflag
,
4223 char *dll_pathname
, char *cond_string
)
4225 solib_load_unload_1 (hookname
,tempflag
, dll_pathname
,
4226 cond_string
, bp_catch_unload
);
4230 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4231 enum bptype bp_kind
)
4233 struct symtab_and_line sal
;
4234 struct breakpoint
*b
;
4235 int thread
= -1; /* All threads. */
4242 b
= set_raw_breakpoint (sal
, bp_kind
);
4243 set_breakpoint_count (breakpoint_count
+ 1);
4244 b
->number
= breakpoint_count
;
4246 b
->cond_string
= (cond_string
== NULL
) ?
4247 NULL
: savestring (cond_string
, strlen (cond_string
));
4249 b
->addr_string
= NULL
;
4250 b
->enable
= enabled
;
4251 b
->disposition
= tempflag
? del
: donttouch
;
4252 b
->forked_inferior_pid
= 0;
4258 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4260 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4264 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4266 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4270 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4272 struct symtab_and_line sal
;
4273 struct breakpoint
*b
;
4274 int thread
= -1; /* All threads. */
4281 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4282 set_breakpoint_count (breakpoint_count
+ 1);
4283 b
->number
= breakpoint_count
;
4285 b
->cond_string
= (cond_string
== NULL
) ?
4286 NULL
: savestring (cond_string
, strlen (cond_string
));
4288 b
->addr_string
= NULL
;
4289 b
->enable
= enabled
;
4290 b
->disposition
= tempflag
? del
: donttouch
;
4296 hw_breakpoint_used_count (void)
4298 register struct breakpoint
*b
;
4303 if (b
->type
== bp_hardware_breakpoint
&& b
->enable
== enabled
)
4311 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4313 register struct breakpoint
*b
;
4316 *other_type_used
= 0;
4319 if (b
->enable
== enabled
)
4321 if (b
->type
== type
)
4323 else if ((b
->type
== bp_hardware_watchpoint
||
4324 b
->type
== bp_read_watchpoint
||
4325 b
->type
== bp_access_watchpoint
)
4326 && b
->enable
== enabled
)
4327 *other_type_used
= 1;
4333 /* Call this after hitting the longjmp() breakpoint. Use this to set
4334 a new breakpoint at the target of the jmp_buf.
4336 FIXME - This ought to be done by setting a temporary breakpoint
4337 that gets deleted automatically... */
4340 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_info
*frame
)
4342 register struct breakpoint
*b
;
4345 if (b
->type
== bp_longjmp_resume
)
4348 b
->enable
= enabled
;
4350 b
->frame
= frame
->frame
;
4353 check_duplicates (b
);
4359 disable_watchpoints_before_interactive_call_start (void)
4361 struct breakpoint
*b
;
4365 if (((b
->type
== bp_watchpoint
)
4366 || (b
->type
== bp_hardware_watchpoint
)
4367 || (b
->type
== bp_read_watchpoint
)
4368 || (b
->type
== bp_access_watchpoint
)
4369 || ep_is_exception_catchpoint (b
))
4370 && (b
->enable
== enabled
))
4372 b
->enable
= call_disabled
;
4373 check_duplicates (b
);
4379 enable_watchpoints_after_interactive_call_stop (void)
4381 struct breakpoint
*b
;
4385 if (((b
->type
== bp_watchpoint
)
4386 || (b
->type
== bp_hardware_watchpoint
)
4387 || (b
->type
== bp_read_watchpoint
)
4388 || (b
->type
== bp_access_watchpoint
)
4389 || ep_is_exception_catchpoint (b
))
4390 && (b
->enable
== call_disabled
))
4392 b
->enable
= enabled
;
4393 check_duplicates (b
);
4399 /* Set a breakpoint that will evaporate an end of command
4400 at address specified by SAL.
4401 Restrict it to frame FRAME if FRAME is nonzero. */
4404 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_info
*frame
,
4407 register struct breakpoint
*b
;
4408 b
= set_raw_breakpoint (sal
, type
);
4409 b
->enable
= enabled
;
4410 b
->disposition
= donttouch
;
4411 b
->frame
= (frame
? frame
->frame
: 0);
4413 /* If we're debugging a multi-threaded program, then we
4414 want momentary breakpoints to be active in only a
4415 single thread of control. */
4416 if (in_thread_list (inferior_ptid
))
4417 b
->thread
= pid_to_thread_id (inferior_ptid
);
4423 /* Tell the user we have just set a breakpoint B. */
4426 mention (struct breakpoint
*b
)
4430 struct cleanup
*old_chain
;
4431 struct ui_stream
*stb
;
4433 stb
= ui_out_stream_new (uiout
);
4434 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4437 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4438 watchpoint) other than breakpoint creation. It should be possible to
4439 clean this up and at the same time replace the random calls to
4440 breakpoint_changed with this hook, as has already been done for
4441 delete_breakpoint_hook and so on. */
4442 if (create_breakpoint_hook
)
4443 create_breakpoint_hook (b
);
4444 breakpoint_create_event (b
->number
);
4449 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b
->number
);
4453 ui_out_text (uiout
, "Watchpoint ");
4454 ui_out_tuple_begin (uiout
, "wpt");
4455 ui_out_field_int (uiout
, "number", b
->number
);
4456 ui_out_text (uiout
, ": ");
4457 print_expression (b
->exp
, stb
->stream
);
4458 ui_out_field_stream (uiout
, "exp", stb
);
4459 ui_out_tuple_end (uiout
);
4461 case bp_hardware_watchpoint
:
4462 ui_out_text (uiout
, "Hardware watchpoint ");
4463 ui_out_tuple_begin (uiout
, "wpt");
4464 ui_out_field_int (uiout
, "number", b
->number
);
4465 ui_out_text (uiout
, ": ");
4466 print_expression (b
->exp
, stb
->stream
);
4467 ui_out_field_stream (uiout
, "exp", stb
);
4468 ui_out_tuple_end (uiout
);
4472 printf_filtered ("Watchpoint %d: ", b
->number
);
4473 print_expression (b
->exp
, gdb_stdout
);
4475 case bp_hardware_watchpoint
:
4476 printf_filtered ("Hardware watchpoint %d: ", b
->number
);
4477 print_expression (b
->exp
, gdb_stdout
);
4481 case bp_read_watchpoint
:
4482 ui_out_text (uiout
, "Hardware read watchpoint ");
4483 ui_out_tuple_begin (uiout
, "hw-rwpt");
4484 ui_out_field_int (uiout
, "number", b
->number
);
4485 ui_out_text (uiout
, ": ");
4486 print_expression (b
->exp
, stb
->stream
);
4487 ui_out_field_stream (uiout
, "exp", stb
);
4488 ui_out_tuple_end (uiout
);
4490 case bp_access_watchpoint
:
4491 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4492 ui_out_tuple_begin (uiout
, "hw-awpt");
4493 ui_out_field_int (uiout
, "number", b
->number
);
4494 ui_out_text (uiout
, ": ");
4495 print_expression (b
->exp
, stb
->stream
);
4496 ui_out_field_stream (uiout
, "exp", stb
);
4497 ui_out_tuple_end (uiout
);
4500 case bp_read_watchpoint
:
4501 printf_filtered ("Hardware read watchpoint %d: ", b
->number
);
4502 print_expression (b
->exp
, gdb_stdout
);
4504 case bp_access_watchpoint
:
4505 printf_filtered ("Hardware access (read/write) watchpoint %d: ",
4507 print_expression (b
->exp
, gdb_stdout
);
4512 if (ui_out_is_mi_like_p (uiout
))
4518 printf_filtered ("Breakpoint %d", b
->number
);
4521 case bp_hardware_breakpoint
:
4523 if (ui_out_is_mi_like_p (uiout
))
4529 printf_filtered ("Hardware assisted breakpoint %d", b
->number
);
4533 case bp_catch_unload
:
4534 printf_filtered ("Catchpoint %d (%s %s)",
4536 (b
->type
== bp_catch_load
) ? "load" : "unload",
4537 (b
->dll_pathname
!= NULL
) ?
4538 b
->dll_pathname
: "<any library>");
4541 case bp_catch_vfork
:
4542 printf_filtered ("Catchpoint %d (%s)",
4544 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4547 printf_filtered ("Catchpoint %d (exec)",
4550 case bp_catch_catch
:
4551 case bp_catch_throw
:
4552 printf_filtered ("Catchpoint %d (%s)",
4554 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4560 case bp_longjmp_resume
:
4561 case bp_step_resume
:
4562 case bp_through_sigtramp
:
4564 case bp_watchpoint_scope
:
4565 case bp_shlib_event
:
4566 case bp_thread_event
:
4571 if (addressprint
|| b
->source_file
== NULL
)
4573 printf_filtered (" at ");
4574 print_address_numeric (b
->address
, 1, gdb_stdout
);
4577 printf_filtered (": file %s, line %d.",
4578 b
->source_file
, b
->line_number
);
4581 do_cleanups (old_chain
);
4584 if (ui_out_is_mi_like_p (uiout
))
4587 printf_filtered ("\n");
4591 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4592 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4593 COND[i] and COND_STRING[i] values.
4595 NOTE: If the function succeeds, the caller is expected to cleanup
4596 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4597 array contents). If the function fails (error() is called), the
4598 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4599 COND and SALS arrays and each of those arrays contents. */
4602 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
4603 struct expression
**cond
, char **cond_string
,
4604 enum bptype type
, enum bpdisp disposition
,
4605 int thread
, int ignore_count
, int from_tty
)
4607 if (type
== bp_hardware_breakpoint
)
4609 int i
= hw_breakpoint_used_count ();
4610 int target_resources_ok
=
4611 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4613 if (target_resources_ok
== 0)
4614 error ("No hardware breakpoint support in the target.");
4615 else if (target_resources_ok
< 0)
4616 error ("Hardware breakpoints used exceeds limit.");
4619 /* Now set all the breakpoints. */
4622 for (i
= 0; i
< sals
.nelts
; i
++)
4624 struct breakpoint
*b
;
4625 struct symtab_and_line sal
= sals
.sals
[i
];
4628 describe_other_breakpoints (sal
.pc
, sal
.section
);
4630 b
= set_raw_breakpoint (sal
, type
);
4631 set_breakpoint_count (breakpoint_count
+ 1);
4632 b
->number
= breakpoint_count
;
4635 b
->addr_string
= addr_string
[i
];
4636 b
->cond_string
= cond_string
[i
];
4637 b
->ignore_count
= ignore_count
;
4638 b
->enable
= enabled
;
4639 b
->disposition
= disposition
;
4645 /* Parse ARG which is assumed to be a SAL specification possibly
4646 followed by conditionals. On return, SALS contains an array of SAL
4647 addresses found. ADDR_STRING contains a vector of (canonical)
4648 address strings. ARG points to the end of the SAL. */
4651 parse_breakpoint_sals (char **address
,
4652 struct symtabs_and_lines
*sals
,
4653 char ***addr_string
)
4655 char *addr_start
= *address
;
4656 *addr_string
= NULL
;
4657 /* If no arg given, or if first arg is 'if ', use the default
4659 if ((*address
) == NULL
4660 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
4662 if (default_breakpoint_valid
)
4664 struct symtab_and_line sal
;
4665 INIT_SAL (&sal
); /* initialize to zeroes */
4666 sals
->sals
= (struct symtab_and_line
*)
4667 xmalloc (sizeof (struct symtab_and_line
));
4668 sal
.pc
= default_breakpoint_address
;
4669 sal
.line
= default_breakpoint_line
;
4670 sal
.symtab
= default_breakpoint_symtab
;
4671 sal
.section
= find_pc_overlay (sal
.pc
);
4672 sals
->sals
[0] = sal
;
4676 error ("No default breakpoint address now.");
4680 /* Force almost all breakpoints to be in terms of the
4681 current_source_symtab (which is decode_line_1's default). This
4682 should produce the results we want almost all of the time while
4683 leaving default_breakpoint_* alone. */
4684 if (default_breakpoint_valid
4685 && (!current_source_symtab
4686 || (strchr ("+-", (*address
)[0]) != NULL
)))
4687 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
4688 default_breakpoint_line
, addr_string
);
4690 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0, addr_string
);
4692 /* For any SAL that didn't have a canonical string, fill one in. */
4693 if (sals
->nelts
> 0 && *addr_string
== NULL
)
4694 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
4695 if (addr_start
!= (*address
))
4698 for (i
= 0; i
< sals
->nelts
; i
++)
4700 /* Add the string if not present. */
4701 if ((*addr_string
)[i
] == NULL
)
4702 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
4708 /* Convert each SAL into a real PC. Verify that the PC can be
4709 inserted as a breakpoint. If it can't throw an error. */
4712 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
4716 for (i
= 0; i
< sals
->nelts
; i
++)
4718 resolve_sal_pc (&sals
->sals
[i
]);
4720 /* It's possible for the PC to be nonzero, but still an illegal
4721 value on some targets.
4723 For example, on HP-UX if you start gdb, and before running the
4724 inferior you try to set a breakpoint on a shared library function
4725 "foo" where the inferior doesn't call "foo" directly but does
4726 pass its address to another function call, then we do find a
4727 minimal symbol for the "foo", but it's address is invalid.
4728 (Appears to be an index into a table that the loader sets up
4729 when the inferior is run.)
4731 Give the target a chance to bless sals.sals[i].pc before we
4732 try to make a breakpoint for it. */
4733 if (PC_REQUIRES_RUN_BEFORE_USE (sals
->sals
[i
].pc
))
4735 if (address
== NULL
)
4736 error ("Cannot break without a running program.");
4738 error ("Cannot break on %s without a running program.",
4744 /* Set a breakpoint according to ARG (function, linenum or *address)
4745 flag: first bit : 0 non-temporary, 1 temporary.
4746 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4749 break_command_1 (char *arg
, int flag
, int from_tty
)
4751 int tempflag
, hardwareflag
;
4752 struct symtabs_and_lines sals
;
4753 register struct expression
**cond
= 0;
4754 /* Pointers in arg to the start, and one past the end, of the
4756 char **cond_string
= (char **) NULL
;
4757 char *addr_start
= arg
;
4759 struct cleanup
*old_chain
;
4760 struct cleanup
*breakpoint_chain
= NULL
;
4763 int ignore_count
= 0;
4765 hardwareflag
= flag
& BP_HARDWAREFLAG
;
4766 tempflag
= flag
& BP_TEMPFLAG
;
4771 parse_breakpoint_sals (&arg
, &sals
, &addr_string
);
4776 /* Create a chain of things that always need to be cleaned up. */
4777 old_chain
= make_cleanup (null_cleanup
, 0);
4779 /* Make sure that all storage allocated to SALS gets freed. */
4780 make_cleanup (xfree
, sals
.sals
);
4782 /* Cleanup the addr_string array but not its contents. */
4783 make_cleanup (xfree
, addr_string
);
4785 /* Allocate space for all the cond expressions. */
4786 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4787 make_cleanup (xfree
, cond
);
4789 /* Allocate space for all the cond strings. */
4790 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4791 make_cleanup (xfree
, cond_string
);
4793 /* ----------------------------- SNIP -----------------------------
4794 Anything added to the cleanup chain beyond this point is assumed
4795 to be part of a breakpoint. If the breakpoint create succeeds
4796 then the memory is not reclaimed. */
4797 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4799 /* Mark the contents of the addr_string for cleanup. These go on
4800 the breakpoint_chain and only occure if the breakpoint create
4802 for (i
= 0; i
< sals
.nelts
; i
++)
4804 if (addr_string
[i
] != NULL
)
4805 make_cleanup (xfree
, addr_string
[i
]);
4808 /* Resolve all line numbers to PC's and verify that the addresses
4809 are ok for the target. */
4810 breakpoint_sals_to_pc (&sals
, addr_start
);
4812 /* Verify that condition can be parsed, before setting any
4813 breakpoints. Allocate a separate condition expression for each
4815 thread
= -1; /* No specific thread yet */
4816 for (i
= 0; i
< sals
.nelts
; i
++)
4823 char *cond_start
= NULL
;
4824 char *cond_end
= NULL
;
4825 while (*tok
== ' ' || *tok
== '\t')
4830 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
4833 toklen
= end_tok
- tok
;
4835 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
4837 tok
= cond_start
= end_tok
+ 1;
4838 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4839 make_cleanup (xfree
, cond
[i
]);
4841 cond_string
[i
] = savestring (cond_start
, cond_end
- cond_start
);
4842 make_cleanup (xfree
, cond_string
[i
]);
4844 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
4850 thread
= strtol (tok
, &tok
, 0);
4852 error ("Junk after thread keyword.");
4853 if (!valid_thread_id (thread
))
4854 error ("Unknown thread %d\n", thread
);
4857 error ("Junk at end of arguments.");
4861 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4862 hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4863 tempflag
? del
: donttouch
,
4864 thread
, ignore_count
, from_tty
);
4868 warning ("Multiple breakpoints were set.");
4869 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4871 /* That's it. Discard the cleanups for data inserted into the
4873 discard_cleanups (breakpoint_chain
);
4874 /* But cleanup everything else. */
4875 do_cleanups (old_chain
);
4878 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4879 linenum or *address) with COND and IGNORE_COUNT. */
4881 struct captured_breakpoint_args
4892 do_captured_breakpoint (void *data
)
4894 struct captured_breakpoint_args
*args
= data
;
4895 struct symtabs_and_lines sals
;
4896 register struct expression
**cond
;
4897 struct cleanup
*old_chain
;
4898 struct cleanup
*breakpoint_chain
= NULL
;
4905 /* Parse the source and lines spec. Delay check that the expression
4906 didn't contain trailing garbage until after cleanups are in
4910 address_end
= args
->address
;
4912 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
);
4917 /* Create a chain of things at always need to be cleaned up. */
4918 old_chain
= make_cleanup (null_cleanup
, 0);
4920 /* Always have a addr_string array, even if it is empty. */
4921 make_cleanup (xfree
, addr_string
);
4923 /* Make sure that all storage allocated to SALS gets freed. */
4924 make_cleanup (xfree
, sals
.sals
);
4926 /* Allocate space for all the cond expressions. */
4927 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4928 make_cleanup (xfree
, cond
);
4930 /* Allocate space for all the cond strings. */
4931 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4932 make_cleanup (xfree
, cond_string
);
4934 /* ----------------------------- SNIP -----------------------------
4935 Anything added to the cleanup chain beyond this point is assumed
4936 to be part of a breakpoint. If the breakpoint create goes
4937 through then that memory is not cleaned up. */
4938 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4940 /* Mark the contents of the addr_string for cleanup. These go on
4941 the breakpoint_chain and only occure if the breakpoint create
4943 for (i
= 0; i
< sals
.nelts
; i
++)
4945 if (addr_string
[i
] != NULL
)
4946 make_cleanup (xfree
, addr_string
[i
]);
4949 /* Wait until now before checking for garbage at the end of the
4950 address. That way cleanups can take care of freeing any
4952 if (*address_end
!= '\0')
4953 error ("Garbage %s following breakpoint address", address_end
);
4955 /* Resolve all line numbers to PC's. */
4956 breakpoint_sals_to_pc (&sals
, args
->address
);
4958 /* Verify that conditions can be parsed, before setting any
4960 for (i
= 0; i
< sals
.nelts
; i
++)
4962 if (args
->condition
!= NULL
)
4964 char *tok
= args
->condition
;
4965 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4967 error ("Garbage %s follows condition", tok
);
4968 make_cleanup (xfree
, cond
[i
]);
4969 cond_string
[i
] = xstrdup (args
->condition
);
4973 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4974 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4975 args
->tempflag
? del
: donttouch
,
4976 args
->thread
, args
->ignore_count
, 0/*from-tty*/);
4978 /* That's it. Discard the cleanups for data inserted into the
4980 discard_cleanups (breakpoint_chain
);
4981 /* But cleanup everything else. */
4982 do_cleanups (old_chain
);
4987 gdb_breakpoint (char *address
, char *condition
,
4988 int hardwareflag
, int tempflag
,
4989 int thread
, int ignore_count
)
4991 struct captured_breakpoint_args args
;
4992 args
.address
= address
;
4993 args
.condition
= condition
;
4994 args
.hardwareflag
= hardwareflag
;
4995 args
.tempflag
= tempflag
;
4996 args
.thread
= thread
;
4997 args
.ignore_count
= ignore_count
;
4998 return catch_errors (do_captured_breakpoint
, &args
,
4999 NULL
, RETURN_MASK_ALL
);
5004 break_at_finish_at_depth_command_1 (char *arg
, int flag
, int from_tty
)
5006 struct frame_info
*frame
;
5007 CORE_ADDR low
, high
, selected_pc
= 0;
5008 char *extra_args
= NULL
;
5011 int extra_args_len
= 0, if_arg
= 0;
5014 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
5017 if (default_breakpoint_valid
)
5021 selected_pc
= selected_frame
->pc
;
5026 error ("No selected frame.");
5029 error ("No default breakpoint address now.");
5033 extra_args
= strchr (arg
, ' ');
5037 extra_args_len
= strlen (extra_args
);
5038 level_arg
= (char *) xmalloc (extra_args
- arg
);
5039 strncpy (level_arg
, arg
, extra_args
- arg
- 1);
5040 level_arg
[extra_args
- arg
- 1] = '\0';
5044 level_arg
= (char *) xmalloc (strlen (arg
) + 1);
5045 strcpy (level_arg
, arg
);
5048 frame
= parse_frame_specification (level_arg
);
5050 selected_pc
= frame
->pc
;
5057 extra_args_len
= strlen (arg
);
5062 if (find_pc_partial_function (selected_pc
, (char **) NULL
, &low
, &high
))
5064 addr_string
= (char *) xmalloc (26 + extra_args_len
);
5066 sprintf (addr_string
, "*0x%s %s", paddr_nz (high
), extra_args
);
5068 sprintf (addr_string
, "*0x%s", paddr_nz (high
));
5069 break_command_1 (addr_string
, flag
, from_tty
);
5070 xfree (addr_string
);
5073 error ("No function contains the specified address");
5076 error ("Unable to set breakpoint at procedure exit");
5081 break_at_finish_command_1 (char *arg
, int flag
, int from_tty
)
5083 char *addr_string
, *break_string
, *beg_addr_string
;
5084 CORE_ADDR low
, high
;
5085 struct symtabs_and_lines sals
;
5086 struct symtab_and_line sal
;
5087 struct cleanup
*old_chain
;
5088 char *extra_args
= NULL
;
5089 int extra_args_len
= 0;
5093 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
5095 if (default_breakpoint_valid
)
5099 addr_string
= (char *) xmalloc (15);
5100 sprintf (addr_string
, "*0x%s", paddr_nz (selected_frame
->pc
));
5105 error ("No selected frame.");
5108 error ("No default breakpoint address now.");
5112 addr_string
= (char *) xmalloc (strlen (arg
) + 1);
5113 strcpy (addr_string
, arg
);
5119 extra_args_len
= strlen (arg
);
5123 /* get the stuff after the function name or address */
5124 extra_args
= strchr (arg
, ' ');
5128 extra_args_len
= strlen (extra_args
);
5135 beg_addr_string
= addr_string
;
5136 sals
= decode_line_1 (&addr_string
, 1, (struct symtab
*) NULL
, 0,
5139 xfree (beg_addr_string
);
5140 old_chain
= make_cleanup (xfree
, sals
.sals
);
5141 for (i
= 0; (i
< sals
.nelts
); i
++)
5144 if (find_pc_partial_function (sal
.pc
, (char **) NULL
, &low
, &high
))
5146 break_string
= (char *) xmalloc (extra_args_len
+ 26);
5148 sprintf (break_string
, "*0x%s %s", paddr_nz (high
), extra_args
);
5150 sprintf (break_string
, "*0x%s", paddr_nz (high
));
5151 break_command_1 (break_string
, flag
, from_tty
);
5152 xfree (break_string
);
5155 error ("No function contains the specified address");
5159 warning ("Multiple breakpoints were set.\n");
5160 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5162 do_cleanups (old_chain
);
5166 /* Helper function for break_command_1 and disassemble_command. */
5169 resolve_sal_pc (struct symtab_and_line
*sal
)
5173 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5175 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5176 error ("No line %d in file \"%s\".",
5177 sal
->line
, sal
->symtab
->filename
);
5181 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5183 struct blockvector
*bv
;
5188 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5191 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5192 sym
= block_function (b
);
5195 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5196 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5200 /* It really is worthwhile to have the section, so we'll just
5201 have to look harder. This case can be executed if we have
5202 line numbers but no functions (as can happen in assembly
5205 struct minimal_symbol
*msym
;
5207 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5209 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5216 break_command (char *arg
, int from_tty
)
5218 break_command_1 (arg
, 0, from_tty
);
5222 break_at_finish_command (char *arg
, int from_tty
)
5224 break_at_finish_command_1 (arg
, 0, from_tty
);
5228 break_at_finish_at_depth_command (char *arg
, int from_tty
)
5230 break_at_finish_at_depth_command_1 (arg
, 0, from_tty
);
5234 tbreak_command (char *arg
, int from_tty
)
5236 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5240 tbreak_at_finish_command (char *arg
, int from_tty
)
5242 break_at_finish_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5246 hbreak_command (char *arg
, int from_tty
)
5248 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5252 thbreak_command (char *arg
, int from_tty
)
5254 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5258 stop_command (char *arg
, int from_tty
)
5260 printf_filtered ("Specify the type of breakpoint to set.\n\
5261 Usage: stop in <function | address>\n\
5266 stopin_command (char *arg
, int from_tty
)
5270 if (arg
== (char *) NULL
)
5272 else if (*arg
!= '*')
5277 /* look for a ':'. If this is a line number specification, then
5278 say it is bad, otherwise, it should be an address or
5279 function/method name */
5280 while (*argptr
&& !hasColon
)
5282 hasColon
= (*argptr
== ':');
5287 badInput
= (*argptr
!= ':'); /* Not a class::method */
5289 badInput
= isdigit (*arg
); /* a simple line number */
5293 printf_filtered ("Usage: stop in <function | address>\n");
5295 break_command_1 (arg
, 0, from_tty
);
5299 stopat_command (char *arg
, int from_tty
)
5303 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5310 /* look for a ':'. If there is a '::' then get out, otherwise
5311 it is probably a line number. */
5312 while (*argptr
&& !hasColon
)
5314 hasColon
= (*argptr
== ':');
5319 badInput
= (*argptr
== ':'); /* we have class::method */
5321 badInput
= !isdigit (*arg
); /* not a line number */
5325 printf_filtered ("Usage: stop at <line>\n");
5327 break_command_1 (arg
, 0, from_tty
);
5331 /* accessflag: hw_write: watch write,
5332 hw_read: watch read,
5333 hw_access: watch access (read or write) */
5335 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5337 struct breakpoint
*b
;
5338 struct symtab_and_line sal
;
5339 struct expression
*exp
;
5340 struct block
*exp_valid_block
;
5341 struct value
*val
, *mark
;
5342 struct frame_info
*frame
;
5343 struct frame_info
*prev_frame
= NULL
;
5344 char *exp_start
= NULL
;
5345 char *exp_end
= NULL
;
5346 char *tok
, *end_tok
;
5348 char *cond_start
= NULL
;
5349 char *cond_end
= NULL
;
5350 struct expression
*cond
= NULL
;
5351 int i
, other_type_used
, target_resources_ok
= 0;
5352 enum bptype bp_type
;
5355 INIT_SAL (&sal
); /* initialize to zeroes */
5357 /* Parse arguments. */
5358 innermost_block
= NULL
;
5360 exp
= parse_exp_1 (&arg
, 0, 0);
5362 exp_valid_block
= innermost_block
;
5363 mark
= value_mark ();
5364 val
= evaluate_expression (exp
);
5365 release_value (val
);
5366 if (VALUE_LAZY (val
))
5367 value_fetch_lazy (val
);
5370 while (*tok
== ' ' || *tok
== '\t')
5374 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5377 toklen
= end_tok
- tok
;
5378 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5380 tok
= cond_start
= end_tok
+ 1;
5381 cond
= parse_exp_1 (&tok
, 0, 0);
5385 error ("Junk at end of command.");
5387 if (accessflag
== hw_read
)
5388 bp_type
= bp_read_watchpoint
;
5389 else if (accessflag
== hw_access
)
5390 bp_type
= bp_access_watchpoint
;
5392 bp_type
= bp_hardware_watchpoint
;
5394 mem_cnt
= can_use_hardware_watchpoint (val
);
5395 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5396 error ("Expression cannot be implemented with read/access watchpoint.");
5399 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5400 target_resources_ok
=
5401 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5403 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5404 error ("Target does not support this type of hardware watchpoint.");
5406 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5407 error ("Target can only support one kind of HW watchpoint at a time.");
5410 #if defined(HPUXHPPA)
5411 /* On HP-UX if you set a h/w
5412 watchpoint before the "run" command, the inferior dies with a e.g.,
5413 SIGILL once you start it. I initially believed this was due to a
5414 bad interaction between page protection traps and the initial
5415 startup sequence by the dynamic linker.
5417 However, I tried avoiding that by having HP-UX's implementation of
5418 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5419 yet, which forced slow watches before a "run" or "attach", and it
5420 still fails somewhere in the startup code.
5422 Until I figure out what's happening, I'm disallowing watches altogether
5423 before the "run" or "attach" command. We'll tell the user they must
5424 set watches after getting the program started. */
5425 if (!target_has_execution
)
5427 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5430 #endif /* HPUXHPPA */
5432 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5433 watchpoint could not be set. */
5434 if (!mem_cnt
|| target_resources_ok
<= 0)
5435 bp_type
= bp_watchpoint
;
5437 /* Now set up the breakpoint. */
5438 b
= set_raw_breakpoint (sal
, bp_type
);
5439 set_breakpoint_count (breakpoint_count
+ 1);
5440 b
->number
= breakpoint_count
;
5441 b
->disposition
= donttouch
;
5443 b
->exp_valid_block
= exp_valid_block
;
5444 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5448 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5452 frame
= block_innermost_frame (exp_valid_block
);
5455 prev_frame
= get_prev_frame (frame
);
5456 b
->watchpoint_frame
= frame
->frame
;
5459 b
->watchpoint_frame
= (CORE_ADDR
) 0;
5461 /* If the expression is "local", then set up a "watchpoint scope"
5462 breakpoint at the point where we've left the scope of the watchpoint
5464 if (innermost_block
)
5468 struct breakpoint
*scope_breakpoint
;
5469 struct symtab_and_line scope_sal
;
5471 INIT_SAL (&scope_sal
); /* initialize to zeroes */
5472 scope_sal
.pc
= get_frame_pc (prev_frame
);
5473 scope_sal
.section
= find_pc_overlay (scope_sal
.pc
);
5475 scope_breakpoint
= set_raw_breakpoint (scope_sal
,
5476 bp_watchpoint_scope
);
5477 set_breakpoint_count (breakpoint_count
+ 1);
5478 scope_breakpoint
->number
= breakpoint_count
;
5480 scope_breakpoint
->enable
= enabled
;
5482 /* Automatically delete the breakpoint when it hits. */
5483 scope_breakpoint
->disposition
= del
;
5485 /* Only break in the proper frame (help with recursion). */
5486 scope_breakpoint
->frame
= prev_frame
->frame
;
5488 /* Set the address at which we will stop. */
5489 scope_breakpoint
->address
= get_frame_pc (prev_frame
);
5491 /* The scope breakpoint is related to the watchpoint. We
5492 will need to act on them together. */
5493 b
->related_breakpoint
= scope_breakpoint
;
5496 value_free_to_mark (mark
);
5500 /* Return count of locations need to be watched and can be handled
5501 in hardware. If the watchpoint can not be handled
5502 in hardware return zero. */
5504 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5505 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5506 ((BYTE_SIZE) <= (REGISTER_SIZE))
5509 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5510 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5511 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5515 can_use_hardware_watchpoint (struct value
*v
)
5517 int found_memory_cnt
= 0;
5518 struct value
*head
= v
;
5520 /* Did the user specifically forbid us to use hardware watchpoints? */
5521 if (!can_use_hw_watchpoints
)
5524 /* Make sure that the value of the expression depends only upon
5525 memory contents, and values computed from them within GDB. If we
5526 find any register references or function calls, we can't use a
5527 hardware watchpoint.
5529 The idea here is that evaluating an expression generates a series
5530 of values, one holding the value of every subexpression. (The
5531 expression a*b+c has five subexpressions: a, b, a*b, c, and
5532 a*b+c.) GDB's values hold almost enough information to establish
5533 the criteria given above --- they identify memory lvalues,
5534 register lvalues, computed values, etcetera. So we can evaluate
5535 the expression, and then scan the chain of values that leaves
5536 behind to decide whether we can detect any possible change to the
5537 expression's final value using only hardware watchpoints.
5539 However, I don't think that the values returned by inferior
5540 function calls are special in any way. So this function may not
5541 notice that an expression involving an inferior function call
5542 can't be watched with hardware watchpoints. FIXME. */
5543 for (; v
; v
= v
->next
)
5545 if (VALUE_LVAL (v
) == lval_memory
)
5548 /* A lazy memory lvalue is one that GDB never needed to fetch;
5549 we either just used its address (e.g., `a' in `a.b') or
5550 we never needed it at all (e.g., `a' in `a,b'). */
5554 /* Ahh, memory we actually used! Check if we can cover
5555 it with hardware watchpoints. */
5556 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
5558 /* We only watch structs and arrays if user asked for it
5559 explicitly, never if they just happen to appear in a
5560 middle of some value chain. */
5562 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5563 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5565 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
5566 int len
= TYPE_LENGTH (VALUE_TYPE (v
));
5568 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5575 else if (v
->lval
!= not_lval
&& v
->modifiable
== 0)
5576 return 0; /* ??? What does this represent? */
5577 else if (v
->lval
== lval_register
)
5578 return 0; /* cannot watch a register with a HW watchpoint */
5581 /* The expression itself looks suitable for using a hardware
5582 watchpoint, but give the target machine a chance to reject it. */
5583 return found_memory_cnt
;
5588 watch_command_wrapper (char *arg
, int from_tty
)
5590 watch_command (arg
, from_tty
);
5594 watch_command (char *arg
, int from_tty
)
5596 watch_command_1 (arg
, hw_write
, from_tty
);
5601 rwatch_command_wrapper (char *arg
, int from_tty
)
5603 rwatch_command (arg
, from_tty
);
5607 rwatch_command (char *arg
, int from_tty
)
5609 watch_command_1 (arg
, hw_read
, from_tty
);
5614 awatch_command_wrapper (char *arg
, int from_tty
)
5616 awatch_command (arg
, from_tty
);
5620 awatch_command (char *arg
, int from_tty
)
5622 watch_command_1 (arg
, hw_access
, from_tty
);
5626 /* Helper routines for the until_command routine in infcmd.c. Here
5627 because it uses the mechanisms of breakpoints. */
5629 /* This function is called by fetch_inferior_event via the
5630 cmd_continuation pointer, to complete the until command. It takes
5631 care of cleaning up the temporary breakpoints set up by the until
5634 until_break_command_continuation (struct continuation_arg
*arg
)
5636 struct cleanup
*cleanups
;
5638 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
5639 do_exec_cleanups (cleanups
);
5644 until_break_command (char *arg
, int from_tty
)
5646 struct symtabs_and_lines sals
;
5647 struct symtab_and_line sal
;
5648 struct frame_info
*prev_frame
= get_prev_frame (selected_frame
);
5649 struct breakpoint
*breakpoint
;
5650 struct cleanup
*old_chain
;
5651 struct continuation_arg
*arg1
;
5654 clear_proceed_status ();
5656 /* Set a breakpoint where the user wants it and at return from
5659 if (default_breakpoint_valid
)
5660 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
5661 default_breakpoint_line
, (char ***) NULL
);
5663 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
5664 0, (char ***) NULL
);
5666 if (sals
.nelts
!= 1)
5667 error ("Couldn't get information on specified line.");
5670 xfree (sals
.sals
); /* malloc'd, so freed */
5673 error ("Junk at end of arguments.");
5675 resolve_sal_pc (&sal
);
5677 breakpoint
= set_momentary_breakpoint (sal
, selected_frame
, bp_until
);
5679 if (!event_loop_p
|| !target_can_async_p ())
5680 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
5682 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
5684 /* If we are running asynchronously, and the target supports async
5685 execution, we are not waiting for the target to stop, in the call
5686 tp proceed, below. This means that we cannot delete the
5687 brekpoints until the target has actually stopped. The only place
5688 where we get a chance to do that is in fetch_inferior_event, so
5689 we must set things up for that. */
5691 if (event_loop_p
&& target_can_async_p ())
5693 /* In this case the arg for the continuation is just the point
5694 in the exec_cleanups chain from where to start doing
5695 cleanups, because all the continuation does is the cleanups in
5696 the exec_cleanup_chain. */
5698 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
5700 arg1
->data
.pointer
= old_chain
;
5702 add_continuation (until_break_command_continuation
, arg1
);
5705 /* Keep within the current frame */
5709 sal
= find_pc_line (prev_frame
->pc
, 0);
5710 sal
.pc
= prev_frame
->pc
;
5711 breakpoint
= set_momentary_breakpoint (sal
, prev_frame
, bp_until
);
5712 if (!event_loop_p
|| !target_can_async_p ())
5713 make_cleanup_delete_breakpoint (breakpoint
);
5715 make_exec_cleanup_delete_breakpoint (breakpoint
);
5718 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
5719 /* Do the cleanups now, anly if we are not running asynchronously,
5720 of if we are, but the target is still synchronous. */
5721 if (!event_loop_p
|| !target_can_async_p ())
5722 do_cleanups (old_chain
);
5726 /* These aren't used; I don't konw what they were for. */
5727 /* Set a breakpoint at the catch clause for NAME. */
5729 catch_breakpoint (char *name
)
5734 disable_catch_breakpoint (void)
5739 delete_catch_breakpoint (void)
5744 enable_catch_breakpoint (void)
5751 struct sal_chain
*next
;
5752 struct symtab_and_line sal
;
5756 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5757 had been commented out in the v.4.16 sources, and stays
5758 disabled there now because "catch NAME" syntax isn't allowed.
5760 /* This isn't used; I don't know what it was for. */
5761 /* For each catch clause identified in ARGS, run FUNCTION
5762 with that clause as an argument. */
5763 static struct symtabs_and_lines
5764 map_catch_names (char *args
, int (*function
) ())
5766 register char *p
= args
;
5768 struct symtabs_and_lines sals
;
5770 struct sal_chain
*sal_chain
= 0;
5774 error_no_arg ("one or more catch names");
5782 /* Don't swallow conditional part. */
5783 if (p1
[0] == 'i' && p1
[1] == 'f'
5784 && (p1
[2] == ' ' || p1
[2] == '\t'))
5790 while (isalnum (*p1
) || *p1
== '_' || *p1
== '$')
5794 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
5795 error ("Arguments must be catch names.");
5801 struct sal_chain
*next
= (struct sal_chain
*)
5802 alloca (sizeof (struct sal_chain
));
5803 next
->next
= sal_chain
;
5804 next
->sal
= get_catch_sal (p
);
5809 printf_unfiltered ("No catch clause for exception %s.\n", p
);
5814 while (*p
== ' ' || *p
== '\t')
5820 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5822 static struct symtabs_and_lines
5823 get_catch_sals (int this_level_only
)
5825 register struct blockvector
*bl
;
5826 register struct block
*block
;
5827 int index
, have_default
= 0;
5829 struct symtabs_and_lines sals
;
5830 struct sal_chain
*sal_chain
= 0;
5831 char *blocks_searched
;
5833 /* Not sure whether an error message is always the correct response,
5834 but it's better than a core dump. */
5835 if (selected_frame
== NULL
)
5836 error ("No selected frame.");
5837 block
= get_frame_block (selected_frame
);
5838 pc
= selected_frame
->pc
;
5844 error ("No symbol table info available.\n");
5846 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
5847 blocks_searched
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
5848 memset (blocks_searched
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
5852 CORE_ADDR end
= BLOCK_END (block
) - 4;
5855 if (bl
!= blockvector_for_pc (end
, &index
))
5856 error ("blockvector blotch");
5857 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
5858 error ("blockvector botch");
5859 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
5862 /* Don't print out blocks that have gone by. */
5863 while (index
< last_index
5864 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
5867 while (index
< last_index
5868 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
5870 if (blocks_searched
[index
] == 0)
5872 struct block
*b
= BLOCKVECTOR_BLOCK (bl
, index
);
5875 register struct symbol
*sym
;
5877 nsyms
= BLOCK_NSYMS (b
);
5879 for (i
= 0; i
< nsyms
; i
++)
5881 sym
= BLOCK_SYM (b
, i
);
5882 if (STREQ (SYMBOL_NAME (sym
), "default"))
5888 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
5890 struct sal_chain
*next
= (struct sal_chain
*)
5891 alloca (sizeof (struct sal_chain
));
5892 next
->next
= sal_chain
;
5893 next
->sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
),
5898 blocks_searched
[index
] = 1;
5904 if (sal_chain
&& this_level_only
)
5907 /* After handling the function's top-level block, stop.
5908 Don't continue to its superblock, the block of
5909 per-file symbols. */
5910 if (BLOCK_FUNCTION (block
))
5912 block
= BLOCK_SUPERBLOCK (block
);
5917 struct sal_chain
*tmp_chain
;
5919 /* Count the number of entries. */
5920 for (index
= 0, tmp_chain
= sal_chain
; tmp_chain
;
5921 tmp_chain
= tmp_chain
->next
)
5925 sals
.sals
= (struct symtab_and_line
*)
5926 xmalloc (index
* sizeof (struct symtab_and_line
));
5927 for (index
= 0; sal_chain
; sal_chain
= sal_chain
->next
, index
++)
5928 sals
.sals
[index
] = sal_chain
->sal
;
5935 ep_skip_leading_whitespace (char **s
)
5937 if ((s
== NULL
) || (*s
== NULL
))
5939 while (isspace (**s
))
5943 /* This function examines a string, and attempts to find a token
5944 that might be an event name in the leading characters. If a
5945 possible match is found, a pointer to the last character of
5946 the token is returned. Else, NULL is returned. */
5949 ep_find_event_name_end (char *arg
)
5952 char *event_name_end
= NULL
;
5954 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5958 /* We break out of the loop when we find a token delimiter.
5959 Basically, we're looking for alphanumerics and underscores;
5960 anything else delimites the token. */
5963 if (!isalnum (*s
) && (*s
!= '_'))
5969 return event_name_end
;
5973 /* This function attempts to parse an optional "if <cond>" clause
5974 from the arg string. If one is not found, it returns NULL.
5976 Else, it returns a pointer to the condition string. (It does not
5977 attempt to evaluate the string against a particular block.) And,
5978 it updates arg to point to the first character following the parsed
5979 if clause in the arg string. */
5982 ep_parse_optional_if_clause (char **arg
)
5986 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
5989 /* Skip the "if" keyword. */
5992 /* Skip any extra leading whitespace, and record the start of the
5993 condition string. */
5994 ep_skip_leading_whitespace (arg
);
5997 /* Assume that the condition occupies the remainder of the arg string. */
5998 (*arg
) += strlen (cond_string
);
6003 /* This function attempts to parse an optional filename from the arg
6004 string. If one is not found, it returns NULL.
6006 Else, it returns a pointer to the parsed filename. (This function
6007 makes no attempt to verify that a file of that name exists, or is
6008 accessible.) And, it updates arg to point to the first character
6009 following the parsed filename in the arg string.
6011 Note that clients needing to preserve the returned filename for
6012 future access should copy it to their own buffers. */
6014 ep_parse_optional_filename (char **arg
)
6016 static char filename
[1024];
6021 if ((*arg_p
== '\0') || isspace (*arg_p
))
6039 /* Commands to deal with catching events, such as signals, exceptions,
6040 process start/exit, etc. */
6044 catch_fork
, catch_vfork
6048 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
6049 static void catch_fork_command_1 (catch_fork_kind fork_kind
,
6050 char *arg
, int tempflag
, int from_tty
);
6053 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6056 char *cond_string
= NULL
;
6058 ep_skip_leading_whitespace (&arg
);
6060 /* The allowed syntax is:
6062 catch [v]fork if <cond>
6064 First, check if there's an if clause. */
6065 cond_string
= ep_parse_optional_if_clause (&arg
);
6067 if ((*arg
!= '\0') && !isspace (*arg
))
6068 error ("Junk at end of arguments.");
6070 /* If this target supports it, create a fork or vfork catchpoint
6071 and enable reporting of such events. */
6075 create_fork_event_catchpoint (tempflag
, cond_string
);
6078 create_vfork_event_catchpoint (tempflag
, cond_string
);
6081 error ("unsupported or unknown fork kind; cannot catch it");
6087 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6089 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6091 char *cond_string
= NULL
;
6093 ep_skip_leading_whitespace (&arg
);
6095 /* The allowed syntax is:
6097 catch exec if <cond>
6099 First, check if there's an if clause. */
6100 cond_string
= ep_parse_optional_if_clause (&arg
);
6102 if ((*arg
!= '\0') && !isspace (*arg
))
6103 error ("Junk at end of arguments.");
6105 /* If this target supports it, create an exec catchpoint
6106 and enable reporting of such events. */
6107 create_exec_event_catchpoint (tempflag
, cond_string
);
6111 #if defined(SOLIB_ADD)
6113 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6115 char *dll_pathname
= NULL
;
6116 char *cond_string
= NULL
;
6118 ep_skip_leading_whitespace (&arg
);
6120 /* The allowed syntax is:
6122 catch load if <cond>
6123 catch load <filename>
6124 catch load <filename> if <cond>
6126 The user is not allowed to specify the <filename> after an
6129 We'll ignore the pathological case of a file named "if".
6131 First, check if there's an if clause. If so, then there
6132 cannot be a filename. */
6133 cond_string
= ep_parse_optional_if_clause (&arg
);
6135 /* If there was an if clause, then there cannot be a filename.
6136 Else, there might be a filename and an if clause. */
6137 if (cond_string
== NULL
)
6139 dll_pathname
= ep_parse_optional_filename (&arg
);
6140 ep_skip_leading_whitespace (&arg
);
6141 cond_string
= ep_parse_optional_if_clause (&arg
);
6144 if ((*arg
!= '\0') && !isspace (*arg
))
6145 error ("Junk at end of arguments.");
6147 /* Create a load breakpoint that only triggers when a load of
6148 the specified dll (or any dll, if no pathname was specified)
6150 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6151 dll_pathname
, cond_string
);
6155 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6157 char *dll_pathname
= NULL
;
6158 char *cond_string
= NULL
;
6160 ep_skip_leading_whitespace (&arg
);
6162 /* The allowed syntax is:
6164 catch unload if <cond>
6165 catch unload <filename>
6166 catch unload <filename> if <cond>
6168 The user is not allowed to specify the <filename> after an
6171 We'll ignore the pathological case of a file named "if".
6173 First, check if there's an if clause. If so, then there
6174 cannot be a filename. */
6175 cond_string
= ep_parse_optional_if_clause (&arg
);
6177 /* If there was an if clause, then there cannot be a filename.
6178 Else, there might be a filename and an if clause. */
6179 if (cond_string
== NULL
)
6181 dll_pathname
= ep_parse_optional_filename (&arg
);
6182 ep_skip_leading_whitespace (&arg
);
6183 cond_string
= ep_parse_optional_if_clause (&arg
);
6186 if ((*arg
!= '\0') && !isspace (*arg
))
6187 error ("Junk at end of arguments.");
6189 /* Create an unload breakpoint that only triggers when an unload of
6190 the specified dll (or any dll, if no pathname was specified)
6192 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6193 dll_pathname
, cond_string
);
6195 #endif /* SOLIB_ADD */
6197 /* Commands to deal with catching exceptions. */
6199 /* Set a breakpoint at the specified callback routine for an
6200 exception event callback */
6203 create_exception_catchpoint (int tempflag
, char *cond_string
,
6204 enum exception_event_kind ex_event
,
6205 struct symtab_and_line
*sal
)
6207 struct breakpoint
*b
;
6208 int thread
= -1; /* All threads. */
6211 if (!sal
) /* no exception support? */
6216 case EX_EVENT_THROW
:
6217 bptype
= bp_catch_throw
;
6219 case EX_EVENT_CATCH
:
6220 bptype
= bp_catch_catch
;
6222 default: /* error condition */
6223 error ("Internal error -- invalid catchpoint kind");
6226 b
= set_raw_breakpoint (*sal
, bptype
);
6227 set_breakpoint_count (breakpoint_count
+ 1);
6228 b
->number
= breakpoint_count
;
6230 b
->cond_string
= (cond_string
== NULL
) ?
6231 NULL
: savestring (cond_string
, strlen (cond_string
));
6233 b
->addr_string
= NULL
;
6234 b
->enable
= enabled
;
6235 b
->disposition
= tempflag
? del
: donttouch
;
6239 /* Deal with "catch catch" and "catch throw" commands */
6242 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6243 int tempflag
, int from_tty
)
6245 char *cond_string
= NULL
;
6246 struct symtab_and_line
*sal
= NULL
;
6248 ep_skip_leading_whitespace (&arg
);
6250 cond_string
= ep_parse_optional_if_clause (&arg
);
6252 if ((*arg
!= '\0') && !isspace (*arg
))
6253 error ("Junk at end of arguments.");
6255 if ((ex_event
!= EX_EVENT_THROW
) &&
6256 (ex_event
!= EX_EVENT_CATCH
))
6257 error ("Unsupported or unknown exception event; cannot catch it");
6259 /* See if we can find a callback routine */
6260 sal
= target_enable_exception_callback (ex_event
, 1);
6264 /* We have callbacks from the runtime system for exceptions.
6265 Set a breakpoint on the sal found, if no errors */
6266 if (sal
!= (struct symtab_and_line
*) -1)
6267 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6269 return; /* something went wrong with setting up callbacks */
6273 /* No callbacks from runtime system for exceptions.
6274 Try GNU C++ exception breakpoints using labels in debug info. */
6275 if (ex_event
== EX_EVENT_CATCH
)
6277 handle_gnu_4_16_catch_command (arg
, tempflag
, from_tty
);
6279 else if (ex_event
== EX_EVENT_THROW
)
6281 /* Set a breakpoint on __raise_exception () */
6283 warning ("Unsupported with this platform/compiler combination.");
6284 warning ("Perhaps you can achieve the effect you want by setting");
6285 warning ("a breakpoint on __raise_exception().");
6290 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6291 inside a catch_errors */
6294 cover_target_enable_exception_callback (PTR arg
)
6296 args_for_catchpoint_enable
*args
= arg
;
6297 struct symtab_and_line
*sal
;
6298 sal
= target_enable_exception_callback (args
->kind
, args
->enable
);
6301 else if (sal
== (struct symtab_and_line
*) -1)
6304 return 1; /*is valid */
6309 /* This is the original v.4.16 and earlier version of the
6310 catch_command_1() function. Now that other flavours of "catch"
6311 have been introduced, and since exception handling can be handled
6312 in other ways (through target ops) also, this is used only for the
6313 GNU C++ exception handling system.
6314 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6315 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6316 there was no code in GDB 4.16 for "catch throw".
6318 Called from catch_exception_command_1 () */
6322 handle_gnu_4_16_catch_command (char *arg
, int tempflag
, int from_tty
)
6324 /* First, translate ARG into something we can deal with in terms
6327 struct symtabs_and_lines sals
;
6328 struct symtab_and_line sal
;
6329 register struct expression
*cond
= 0;
6330 register struct breakpoint
*b
;
6334 INIT_SAL (&sal
); /* initialize to zeroes */
6336 /* If no arg given, or if first arg is 'if ', all active catch clauses
6337 are breakpointed. */
6339 if (!arg
|| (arg
[0] == 'i' && arg
[1] == 'f'
6340 && (arg
[2] == ' ' || arg
[2] == '\t')))
6342 /* Grab all active catch clauses. */
6343 sals
= get_catch_sals (0);
6347 /* Grab selected catch clauses. */
6348 error ("catch NAME not implemented");
6351 /* Not sure why this code has been disabled. I'm leaving
6352 it disabled. We can never come here now anyway
6353 since we don't allow the "catch NAME" syntax.
6356 /* This isn't used; I don't know what it was for. */
6357 sals
= map_catch_names (arg
, catch_breakpoint
);
6365 for (i
= 0; i
< sals
.nelts
; i
++)
6367 resolve_sal_pc (&sals
.sals
[i
]);
6371 if (arg
[0] == 'i' && arg
[1] == 'f'
6372 && (arg
[2] == ' ' || arg
[2] == '\t'))
6373 cond
= parse_exp_1 ((arg
+= 2, &arg
),
6374 block_for_pc (sals
.sals
[i
].pc
), 0);
6376 error ("Junk at end of arguments.");
6381 for (i
= 0; i
< sals
.nelts
; i
++)
6386 describe_other_breakpoints (sal
.pc
, sal
.section
);
6388 /* Important -- this is an ordinary breakpoint. For platforms
6389 with callback support for exceptions,
6390 create_exception_catchpoint() will create special bp types
6391 (bp_catch_catch and bp_catch_throw), and there is code in
6392 insert_breakpoints() and elsewhere that depends on that. */
6393 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6394 set_breakpoint_count (breakpoint_count
+ 1);
6395 b
->number
= breakpoint_count
;
6398 b
->enable
= enabled
;
6399 b
->disposition
= tempflag
? del
: donttouch
;
6406 warning ("Multiple breakpoints were set.");
6407 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
6413 /* This creates a temporary internal breakpoint
6414 just to placate infrun */
6415 static struct breakpoint
*
6416 create_temp_exception_breakpoint (CORE_ADDR pc
)
6418 struct symtab_and_line sal
;
6419 struct breakpoint
*b
;
6426 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6428 b
->disposition
= del
;
6429 b
->enable
= enabled
;
6431 b
->number
= internal_breakpoint_number
--;
6437 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6440 /* The first argument may be an event name, such as "start" or "load".
6441 If so, then handle it as such. If it doesn't match an event name,
6442 then attempt to interpret it as an exception name. (This latter is
6443 the v4.16-and-earlier GDB meaning of the "catch" command.)
6445 First, try to find the bounds of what might be an event name. */
6446 char *arg1_start
= arg
;
6450 if (arg1_start
== NULL
)
6452 /* Old behaviour was to use pre-v-4.16 syntax */
6453 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6455 /* Now, this is not allowed */
6456 error ("Catch requires an event name.");
6459 arg1_end
= ep_find_event_name_end (arg1_start
);
6460 if (arg1_end
== NULL
)
6461 error ("catch requires an event");
6462 arg1_length
= arg1_end
+ 1 - arg1_start
;
6464 /* Try to match what we found against known event names. */
6465 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6467 error ("Catch of signal not yet implemented");
6469 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6471 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6472 tempflag
, from_tty
);
6474 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6476 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6477 tempflag
, from_tty
);
6479 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6481 error ("Catch of thread_start not yet implemented");
6483 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6485 error ("Catch of thread_exit not yet implemented");
6487 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6489 error ("Catch of thread_join not yet implemented");
6491 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6493 error ("Catch of start not yet implemented");
6495 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6497 error ("Catch of exit not yet implemented");
6499 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6501 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6502 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6504 error ("Catch of fork not yet implemented");
6507 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6509 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6510 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6512 error ("Catch of vfork not yet implemented");
6515 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6517 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6518 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6520 error ("Catch of exec not yet implemented");
6523 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6525 #if defined(SOLIB_ADD)
6526 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6528 error ("Catch of load not implemented");
6531 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6533 #if defined(SOLIB_ADD)
6534 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6536 error ("Catch of load not implemented");
6539 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6541 error ("Catch of stop not yet implemented");
6544 /* This doesn't appear to be an event name */
6548 /* Pre-v.4.16 behaviour was to treat the argument
6549 as the name of an exception */
6550 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6551 /* Now this is not allowed */
6552 error ("Unknown event kind specified for catch");
6557 /* Used by the gui, could be made a worker for other things. */
6560 set_breakpoint_sal (struct symtab_and_line sal
)
6562 struct breakpoint
*b
;
6563 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6564 set_breakpoint_count (breakpoint_count
+ 1);
6565 b
->number
= breakpoint_count
;
6572 /* These aren't used; I don't know what they were for. */
6573 /* Disable breakpoints on all catch clauses described in ARGS. */
6575 disable_catch (char *args
)
6577 /* Map the disable command to catch clauses described in ARGS. */
6580 /* Enable breakpoints on all catch clauses described in ARGS. */
6582 enable_catch (char *args
)
6584 /* Map the disable command to catch clauses described in ARGS. */
6587 /* Delete breakpoints on all catch clauses in the active scope. */
6589 delete_catch (char *args
)
6591 /* Map the delete command to catch clauses described in ARGS. */
6596 catch_command (char *arg
, int from_tty
)
6598 catch_command_1 (arg
, 0, from_tty
);
6603 tcatch_command (char *arg
, int from_tty
)
6605 catch_command_1 (arg
, 1, from_tty
);
6610 clear_command (char *arg
, int from_tty
)
6612 register struct breakpoint
*b
, *b1
;
6614 struct symtabs_and_lines sals
;
6615 struct symtab_and_line sal
;
6616 register struct breakpoint
*found
;
6621 sals
= decode_line_spec (arg
, 1);
6626 sals
.sals
= (struct symtab_and_line
*)
6627 xmalloc (sizeof (struct symtab_and_line
));
6628 INIT_SAL (&sal
); /* initialize to zeroes */
6629 sal
.line
= default_breakpoint_line
;
6630 sal
.symtab
= default_breakpoint_symtab
;
6631 sal
.pc
= default_breakpoint_address
;
6632 if (sal
.symtab
== 0)
6633 error ("No source file specified.");
6641 /* For each line spec given, delete bps which correspond
6642 to it. We do this in two loops: the first loop looks at
6643 the initial bp(s) in the chain which should be deleted,
6644 the second goes down the rest of the chain looking ahead
6645 one so it can take those bps off the chain without messing
6649 for (i
= 0; i
< sals
.nelts
; i
++)
6651 /* If exact pc given, clear bpts at that pc.
6652 If line given (pc == 0), clear all bpts on specified line.
6653 If defaulting, clear all bpts on default line
6656 defaulting sal.pc != 0 tests to do
6661 1 0 <can't happen> */
6664 found
= (struct breakpoint
*) 0;
6667 while (breakpoint_chain
6668 /* Why don't we check here that this is not
6669 a watchpoint, etc., as we do below?
6670 I can't make it fail, but don't know
6671 what's stopping the failure: a watchpoint
6672 of the same address as "sal.pc" should
6673 wind up being deleted. */
6675 && (((sal
.pc
&& (breakpoint_chain
->address
== sal
.pc
)) &&
6676 (overlay_debugging
== 0 ||
6677 breakpoint_chain
->section
== sal
.section
))
6678 || ((default_match
|| (0 == sal
.pc
))
6679 && breakpoint_chain
->source_file
!= NULL
6680 && sal
.symtab
!= NULL
6681 && STREQ (breakpoint_chain
->source_file
, sal
.symtab
->filename
)
6682 && breakpoint_chain
->line_number
== sal
.line
)))
6685 b1
= breakpoint_chain
;
6686 breakpoint_chain
= b1
->next
;
6694 && b
->next
->type
!= bp_none
6695 && b
->next
->type
!= bp_watchpoint
6696 && b
->next
->type
!= bp_hardware_watchpoint
6697 && b
->next
->type
!= bp_read_watchpoint
6698 && b
->next
->type
!= bp_access_watchpoint
6699 && (((sal
.pc
&& (b
->next
->address
== sal
.pc
)) &&
6700 (overlay_debugging
== 0 ||
6701 b
->next
->section
== sal
.section
))
6702 || ((default_match
|| (0 == sal
.pc
))
6703 && b
->next
->source_file
!= NULL
6704 && sal
.symtab
!= NULL
6705 && STREQ (b
->next
->source_file
, sal
.symtab
->filename
)
6706 && b
->next
->line_number
== sal
.line
)))
6719 error ("No breakpoint at %s.", arg
);
6721 error ("No breakpoint at this line.");
6725 from_tty
= 1; /* Always report if deleted more than one */
6727 printf_unfiltered ("Deleted breakpoint%s ", found
->next
? "s" : "");
6728 breakpoints_changed ();
6732 printf_unfiltered ("%d ", found
->number
);
6734 delete_breakpoint (found
);
6738 putchar_unfiltered ('\n');
6743 /* Delete breakpoint in BS if they are `delete' breakpoints and
6744 all breakpoints that are marked for deletion, whether hit or not.
6745 This is called after any breakpoint is hit, or after errors. */
6748 breakpoint_auto_delete (bpstat bs
)
6750 struct breakpoint
*b
, *temp
;
6752 for (; bs
; bs
= bs
->next
)
6753 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== del
6755 delete_breakpoint (bs
->breakpoint_at
);
6757 ALL_BREAKPOINTS_SAFE (b
, temp
)
6759 if (b
->disposition
== del_at_next_stop
)
6760 delete_breakpoint (b
);
6764 /* Delete a breakpoint and clean up all traces of it in the data
6768 delete_breakpoint (struct breakpoint
*bpt
)
6770 register struct breakpoint
*b
;
6774 error ("Internal error (attempted to delete a NULL breakpoint)");
6777 /* Has this bp already been deleted? This can happen because multiple
6778 lists can hold pointers to bp's. bpstat lists are especial culprits.
6780 One example of this happening is a watchpoint's scope bp. When the
6781 scope bp triggers, we notice that the watchpoint is out of scope, and
6782 delete it. We also delete its scope bp. But the scope bp is marked
6783 "auto-deleting", and is already on a bpstat. That bpstat is then
6784 checked for auto-deleting bp's, which are deleted.
6786 A real solution to this problem might involve reference counts in bp's,
6787 and/or giving them pointers back to their referencing bpstat's, and
6788 teaching delete_breakpoint to only free a bp's storage when no more
6789 references were extent. A cheaper bandaid was chosen. */
6790 if (bpt
->type
== bp_none
)
6793 if (delete_breakpoint_hook
)
6794 delete_breakpoint_hook (bpt
);
6795 breakpoint_delete_event (bpt
->number
);
6798 remove_breakpoint (bpt
, mark_inserted
);
6800 if (breakpoint_chain
== bpt
)
6801 breakpoint_chain
= bpt
->next
;
6803 /* If we have callback-style exception catchpoints, don't go through
6804 the adjustments to the C++ runtime library etc. if the inferior
6805 isn't actually running. target_enable_exception_callback for a
6806 null target ops vector gives an undesirable error message, so we
6807 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6808 exceptions are supported in this way, it's OK for now. FIXME */
6809 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
6811 static char message1
[] = "Error in deleting catchpoint %d:\n";
6812 static char message
[sizeof (message1
) + 30];
6813 args_for_catchpoint_enable args
;
6815 /* Format possible error msg */
6816 sprintf (message
, message1
, bpt
->number
);
6817 args
.kind
= bpt
->type
== bp_catch_catch
?
6818 EX_EVENT_CATCH
: EX_EVENT_THROW
;
6820 catch_errors (cover_target_enable_exception_callback
, &args
,
6821 message
, RETURN_MASK_ALL
);
6828 b
->next
= bpt
->next
;
6832 check_duplicates (bpt
);
6833 /* If this breakpoint was inserted, and there is another breakpoint
6834 at the same address, we need to insert the other breakpoint. */
6836 && bpt
->type
!= bp_hardware_watchpoint
6837 && bpt
->type
!= bp_read_watchpoint
6838 && bpt
->type
!= bp_access_watchpoint
6839 && bpt
->type
!= bp_catch_fork
6840 && bpt
->type
!= bp_catch_vfork
6841 && bpt
->type
!= bp_catch_exec
)
6844 if (b
->address
== bpt
->address
6845 && b
->section
== bpt
->section
6847 && b
->enable
!= disabled
6848 && b
->enable
!= shlib_disabled
6849 && b
->enable
!= call_disabled
)
6853 /* We should never reach this point if there is a permanent
6854 breakpoint at the same address as the one being deleted.
6855 If there is a permanent breakpoint somewhere, it should
6856 always be the only one inserted. */
6857 if (b
->enable
== permanent
)
6858 internal_error (__FILE__
, __LINE__
,
6859 "another breakpoint was inserted on top of "
6860 "a permanent breakpoint");
6862 if (b
->type
== bp_hardware_breakpoint
)
6863 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
6865 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
6869 target_terminal_ours_for_output ();
6870 warning ("Cannot insert breakpoint %d:", b
->number
);
6871 memory_error (val
, b
->address
); /* which bombs us out */
6878 free_command_lines (&bpt
->commands
);
6881 if (bpt
->cond_string
!= NULL
)
6882 xfree (bpt
->cond_string
);
6883 if (bpt
->addr_string
!= NULL
)
6884 xfree (bpt
->addr_string
);
6885 if (bpt
->exp
!= NULL
)
6887 if (bpt
->exp_string
!= NULL
)
6888 xfree (bpt
->exp_string
);
6889 if (bpt
->val
!= NULL
)
6890 value_free (bpt
->val
);
6891 if (bpt
->source_file
!= NULL
)
6892 xfree (bpt
->source_file
);
6893 if (bpt
->dll_pathname
!= NULL
)
6894 xfree (bpt
->dll_pathname
);
6895 if (bpt
->triggered_dll_pathname
!= NULL
)
6896 xfree (bpt
->triggered_dll_pathname
);
6897 if (bpt
->exec_pathname
!= NULL
)
6898 xfree (bpt
->exec_pathname
);
6900 /* Be sure no bpstat's are pointing at it after it's been freed. */
6901 /* FIXME, how can we find all bpstat's?
6902 We just check stop_bpstat for now. */
6903 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
6904 if (bs
->breakpoint_at
== bpt
)
6906 bs
->breakpoint_at
= NULL
;
6908 /* we'd call bpstat_clear_actions, but that free's stuff and due
6909 to the multiple pointers pointing to one item with no
6910 reference counts found anywhere through out the bpstat's (how
6911 do you spell fragile?), we don't want to free things twice --
6912 better a memory leak than a corrupt malloc pool! */
6913 bs
->commands
= NULL
;
6916 /* On the chance that someone will soon try again to delete this same
6917 bp, we mark it as deleted before freeing its storage. */
6918 bpt
->type
= bp_none
;
6924 do_delete_breakpoint_cleanup (void *b
)
6926 delete_breakpoint (b
);
6930 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
6932 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
6936 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
6938 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
6942 delete_command (char *arg
, int from_tty
)
6944 struct breakpoint
*b
, *temp
;
6948 int breaks_to_delete
= 0;
6950 /* Delete all breakpoints if no argument.
6951 Do not delete internal or call-dummy breakpoints, these
6952 have to be deleted with an explicit breakpoint number argument. */
6955 if (b
->type
!= bp_call_dummy
&&
6956 b
->type
!= bp_shlib_event
&&
6957 b
->type
!= bp_thread_event
&&
6959 breaks_to_delete
= 1;
6962 /* Ask user only if there are some breakpoints to delete. */
6964 || (breaks_to_delete
&& query ("Delete all breakpoints? ")))
6966 ALL_BREAKPOINTS_SAFE (b
, temp
)
6968 if (b
->type
!= bp_call_dummy
&&
6969 b
->type
!= bp_shlib_event
&&
6970 b
->type
!= bp_thread_event
&&
6972 delete_breakpoint (b
);
6977 map_breakpoint_numbers (arg
, delete_breakpoint
);
6980 /* Reset a breakpoint given it's struct breakpoint * BINT.
6981 The value we return ends up being the return value from catch_errors.
6982 Unused in this case. */
6985 breakpoint_re_set_one (PTR bint
)
6987 /* get past catch_errs */
6988 struct breakpoint
*b
= (struct breakpoint
*) bint
;
6991 struct symtabs_and_lines sals
;
6993 enum enable save_enable
;
6998 warning ("attempted to reset apparently deleted breakpoint #%d?",
7002 case bp_hardware_breakpoint
:
7004 case bp_catch_unload
:
7005 if (b
->addr_string
== NULL
)
7007 /* Anything without a string can't be re-set. */
7008 delete_breakpoint (b
);
7011 /* In case we have a problem, disable this breakpoint. We'll restore
7012 its status if we succeed. */
7013 save_enable
= b
->enable
;
7014 b
->enable
= disabled
;
7016 set_language (b
->language
);
7017 input_radix
= b
->input_radix
;
7019 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
);
7020 for (i
= 0; i
< sals
.nelts
; i
++)
7022 resolve_sal_pc (&sals
.sals
[i
]);
7024 /* Reparse conditions, they might contain references to the
7026 if (b
->cond_string
!= NULL
)
7031 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
7034 /* We need to re-set the breakpoint if the address changes... */
7035 if (b
->address
!= sals
.sals
[i
].pc
7036 /* ...or new and old breakpoints both have source files, and
7037 the source file name or the line number changes... */
7038 || (b
->source_file
!= NULL
7039 && sals
.sals
[i
].symtab
!= NULL
7040 && (!STREQ (b
->source_file
, sals
.sals
[i
].symtab
->filename
)
7041 || b
->line_number
!= sals
.sals
[i
].line
)
7043 /* ...or we switch between having a source file and not having
7045 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
7048 if (b
->source_file
!= NULL
)
7049 xfree (b
->source_file
);
7050 if (sals
.sals
[i
].symtab
== NULL
)
7051 b
->source_file
= NULL
;
7054 savestring (sals
.sals
[i
].symtab
->filename
,
7055 strlen (sals
.sals
[i
].symtab
->filename
));
7056 b
->line_number
= sals
.sals
[i
].line
;
7057 b
->address
= sals
.sals
[i
].pc
;
7059 /* Used to check for duplicates here, but that can
7060 cause trouble, as it doesn't check for disable
7065 /* Might be better to do this just once per breakpoint_re_set,
7066 rather than once for every breakpoint. */
7067 breakpoints_changed ();
7069 b
->section
= sals
.sals
[i
].section
;
7070 b
->enable
= save_enable
; /* Restore it, this worked. */
7073 /* Now that this is re-enabled, check_duplicates
7075 check_duplicates (b
);
7082 case bp_hardware_watchpoint
:
7083 case bp_read_watchpoint
:
7084 case bp_access_watchpoint
:
7085 innermost_block
= NULL
;
7086 /* The issue arises of what context to evaluate this in. The
7087 same one as when it was set, but what does that mean when
7088 symbols have been re-read? We could save the filename and
7089 functionname, but if the context is more local than that, the
7090 best we could do would be something like how many levels deep
7091 and which index at that particular level, but that's going to
7092 be less stable than filenames or function names. */
7094 /* So for now, just use a global context. */
7097 b
->exp
= parse_expression (b
->exp_string
);
7098 b
->exp_valid_block
= innermost_block
;
7099 mark
= value_mark ();
7101 value_free (b
->val
);
7102 b
->val
= evaluate_expression (b
->exp
);
7103 release_value (b
->val
);
7104 if (VALUE_LAZY (b
->val
))
7105 value_fetch_lazy (b
->val
);
7107 if (b
->cond_string
!= NULL
)
7112 b
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
7114 if (b
->enable
== enabled
)
7116 value_free_to_mark (mark
);
7118 case bp_catch_catch
:
7119 case bp_catch_throw
:
7121 /* We needn't really do anything to reset these, since the mask
7122 that requests them is unaffected by e.g., new libraries being
7125 case bp_catch_vfork
:
7130 printf_filtered ("Deleting unknown breakpoint type %d\n", b
->type
);
7132 /* Delete longjmp breakpoints, they will be reset later by
7133 breakpoint_re_set. */
7135 case bp_longjmp_resume
:
7136 delete_breakpoint (b
);
7139 /* This breakpoint is special, it's set up when the inferior
7140 starts and we really don't want to touch it. */
7141 case bp_shlib_event
:
7143 /* Like bp_shlib_event, this breakpoint type is special.
7144 Once it is set up, we do not want to touch it. */
7145 case bp_thread_event
:
7147 /* Keep temporary breakpoints, which can be encountered when we step
7148 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7149 Otherwise these should have been blown away via the cleanup chain
7150 or by breakpoint_init_inferior when we rerun the executable. */
7153 case bp_watchpoint_scope
:
7155 case bp_step_resume
:
7162 /* Re-set all breakpoints after symbols have been re-loaded. */
7164 breakpoint_re_set (void)
7166 struct breakpoint
*b
, *temp
;
7167 enum language save_language
;
7168 int save_input_radix
;
7169 static char message1
[] = "Error in re-setting breakpoint %d:\n";
7170 char message
[sizeof (message1
) + 30 /* slop */ ];
7172 save_language
= current_language
->la_language
;
7173 save_input_radix
= input_radix
;
7174 ALL_BREAKPOINTS_SAFE (b
, temp
)
7176 /* Format possible error msg */
7177 sprintf (message
, message1
, b
->number
);
7178 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7180 set_language (save_language
);
7181 input_radix
= save_input_radix
;
7183 #ifdef GET_LONGJMP_TARGET
7184 create_longjmp_breakpoint ("longjmp");
7185 create_longjmp_breakpoint ("_longjmp");
7186 create_longjmp_breakpoint ("siglongjmp");
7187 create_longjmp_breakpoint ("_siglongjmp");
7188 create_longjmp_breakpoint (NULL
);
7192 /* Took this out (temporarily at least), since it produces an extra
7193 blank line at startup. This messes up the gdbtests. -PB */
7194 /* Blank line to finish off all those mention() messages we just printed. */
7195 printf_filtered ("\n");
7199 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7200 If from_tty is nonzero, it prints a message to that effect,
7201 which ends with a period (no newline). */
7203 /* Reset the thread number of this breakpoint:
7205 - If the breakpoint is for all threads, leave it as-is.
7206 - Else, reset it to the current thread for inferior_ptid. */
7208 breakpoint_re_set_thread (struct breakpoint
*b
)
7210 if (b
->thread
!= -1)
7212 if (in_thread_list (inferior_ptid
))
7213 b
->thread
= pid_to_thread_id (inferior_ptid
);
7218 set_ignore_count (int bptnum
, int count
, int from_tty
)
7220 register struct breakpoint
*b
;
7226 if (b
->number
== bptnum
)
7228 b
->ignore_count
= count
;
7231 else if (count
== 0)
7232 printf_filtered ("Will stop next time breakpoint %d is reached.",
7234 else if (count
== 1)
7235 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7238 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7240 breakpoints_changed ();
7244 error ("No breakpoint number %d.", bptnum
);
7247 /* Clear the ignore counts of all breakpoints. */
7249 breakpoint_clear_ignore_counts (void)
7251 struct breakpoint
*b
;
7254 b
->ignore_count
= 0;
7257 /* Command to set ignore-count of breakpoint N to COUNT. */
7260 ignore_command (char *args
, int from_tty
)
7266 error_no_arg ("a breakpoint number");
7268 num
= get_number (&p
);
7270 error ("bad breakpoint number: '%s'", args
);
7272 error ("Second argument (specified ignore-count) is missing.");
7274 set_ignore_count (num
,
7275 longest_to_int (value_as_long (parse_and_eval (p
))),
7277 printf_filtered ("\n");
7278 breakpoints_changed ();
7281 /* Call FUNCTION on each of the breakpoints
7282 whose numbers are given in ARGS. */
7285 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7287 register char *p
= args
;
7290 register struct breakpoint
*b
, *tmp
;
7294 error_no_arg ("one or more breakpoint numbers");
7301 num
= get_number_or_range (&p1
);
7304 warning ("bad breakpoint number at or near '%s'", p
);
7308 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7309 if (b
->number
== num
)
7311 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7314 if (related_breakpoint
)
7315 function (related_breakpoint
);
7319 printf_unfiltered ("No breakpoint number %d.\n", num
);
7326 disable_breakpoint (struct breakpoint
*bpt
)
7328 /* Never disable a watchpoint scope breakpoint; we want to
7329 hit them when we leave scope so we can delete both the
7330 watchpoint and its scope breakpoint at that time. */
7331 if (bpt
->type
== bp_watchpoint_scope
)
7334 /* You can't disable permanent breakpoints. */
7335 if (bpt
->enable
== permanent
)
7338 bpt
->enable
= disabled
;
7340 check_duplicates (bpt
);
7342 if (modify_breakpoint_hook
)
7343 modify_breakpoint_hook (bpt
);
7344 breakpoint_modify_event (bpt
->number
);
7349 disable_command (char *args
, int from_tty
)
7351 register struct breakpoint
*bpt
;
7353 ALL_BREAKPOINTS (bpt
)
7357 warning ("attempted to disable apparently deleted breakpoint #%d?",
7362 case bp_catch_unload
:
7364 case bp_catch_vfork
:
7366 case bp_catch_catch
:
7367 case bp_catch_throw
:
7368 case bp_hardware_breakpoint
:
7370 case bp_hardware_watchpoint
:
7371 case bp_read_watchpoint
:
7372 case bp_access_watchpoint
:
7373 disable_breakpoint (bpt
);
7378 map_breakpoint_numbers (args
, disable_breakpoint
);
7382 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7384 struct frame_info
*save_selected_frame
= NULL
;
7385 int save_selected_frame_level
= -1;
7386 int target_resources_ok
, other_type_used
;
7389 if (bpt
->type
== bp_hardware_breakpoint
)
7392 i
= hw_breakpoint_used_count ();
7393 target_resources_ok
=
7394 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7396 if (target_resources_ok
== 0)
7397 error ("No hardware breakpoint support in the target.");
7398 else if (target_resources_ok
< 0)
7399 error ("Hardware breakpoints used exceeds limit.");
7402 if (bpt
->enable
!= permanent
)
7403 bpt
->enable
= enabled
;
7404 bpt
->disposition
= disposition
;
7405 check_duplicates (bpt
);
7406 breakpoints_changed ();
7408 if (bpt
->type
== bp_watchpoint
||
7409 bpt
->type
== bp_hardware_watchpoint
||
7410 bpt
->type
== bp_read_watchpoint
||
7411 bpt
->type
== bp_access_watchpoint
)
7413 if (bpt
->exp_valid_block
!= NULL
)
7415 struct frame_info
*fr
=
7417 /* Ensure that we have the current frame. Else, this
7418 next query may pessimistically be answered as, "No,
7419 not within current scope". */
7420 get_current_frame ();
7421 fr
= find_frame_addr_in_frame_chain (bpt
->watchpoint_frame
);
7425 Cannot enable watchpoint %d because the block in which its expression\n\
7426 is valid is not currently in scope.\n", bpt
->number
);
7427 bpt
->enable
= disabled
;
7431 save_selected_frame
= selected_frame
;
7432 save_selected_frame_level
= selected_frame_level
;
7433 select_frame (fr
, -1);
7436 value_free (bpt
->val
);
7437 mark
= value_mark ();
7438 bpt
->val
= evaluate_expression (bpt
->exp
);
7439 release_value (bpt
->val
);
7440 if (VALUE_LAZY (bpt
->val
))
7441 value_fetch_lazy (bpt
->val
);
7443 if (bpt
->type
== bp_hardware_watchpoint
||
7444 bpt
->type
== bp_read_watchpoint
||
7445 bpt
->type
== bp_access_watchpoint
)
7447 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7448 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7450 /* Hack around 'unused var' error for some targets here */
7452 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7453 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7454 /* we can consider of type is bp_hardware_watchpoint, convert to
7455 bp_watchpoint in the following condition */
7456 if (target_resources_ok
< 0)
7459 Cannot enable watchpoint %d because target watch resources\n\
7460 have been allocated for other watchpoints.\n", bpt
->number
);
7461 bpt
->enable
= disabled
;
7462 value_free_to_mark (mark
);
7467 if (save_selected_frame_level
>= 0)
7468 select_frame (save_selected_frame
, save_selected_frame_level
);
7469 value_free_to_mark (mark
);
7471 if (modify_breakpoint_hook
)
7472 modify_breakpoint_hook (bpt
);
7473 breakpoint_modify_event (bpt
->number
);
7477 enable_breakpoint (struct breakpoint
*bpt
)
7479 do_enable_breakpoint (bpt
, bpt
->disposition
);
7482 /* The enable command enables the specified breakpoints (or all defined
7483 breakpoints) so they once again become (or continue to be) effective
7484 in stopping the inferior. */
7488 enable_command (char *args
, int from_tty
)
7490 register struct breakpoint
*bpt
;
7492 ALL_BREAKPOINTS (bpt
)
7496 warning ("attempted to enable apparently deleted breakpoint #%d?",
7501 case bp_catch_unload
:
7503 case bp_catch_vfork
:
7505 case bp_catch_catch
:
7506 case bp_catch_throw
:
7507 case bp_hardware_breakpoint
:
7509 case bp_hardware_watchpoint
:
7510 case bp_read_watchpoint
:
7511 case bp_access_watchpoint
:
7512 enable_breakpoint (bpt
);
7517 map_breakpoint_numbers (args
, enable_breakpoint
);
7521 enable_once_breakpoint (struct breakpoint
*bpt
)
7523 do_enable_breakpoint (bpt
, disable
);
7528 enable_once_command (char *args
, int from_tty
)
7530 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7534 enable_delete_breakpoint (struct breakpoint
*bpt
)
7536 do_enable_breakpoint (bpt
, del
);
7541 enable_delete_command (char *args
, int from_tty
)
7543 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7546 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7548 struct symtabs_and_lines
7549 decode_line_spec_1 (char *string
, int funfirstline
)
7551 struct symtabs_and_lines sals
;
7553 error ("Empty line specification.");
7554 if (default_breakpoint_valid
)
7555 sals
= decode_line_1 (&string
, funfirstline
,
7556 default_breakpoint_symtab
,
7557 default_breakpoint_line
,
7560 sals
= decode_line_1 (&string
, funfirstline
,
7561 (struct symtab
*) NULL
, 0, (char ***) NULL
);
7563 error ("Junk at end of line specification: %s", string
);
7568 _initialize_breakpoint (void)
7570 struct cmd_list_element
*c
;
7572 breakpoint_chain
= 0;
7573 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7574 before a breakpoint is set. */
7575 breakpoint_count
= 0;
7577 add_com ("ignore", class_breakpoint
, ignore_command
,
7578 "Set ignore-count of breakpoint number N to COUNT.\n\
7579 Usage is `ignore N COUNT'.");
7581 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7583 add_com ("commands", class_breakpoint
, commands_command
,
7584 "Set commands to be executed when a breakpoint is hit.\n\
7585 Give breakpoint number as argument after \"commands\".\n\
7586 With no argument, the targeted breakpoint is the last one set.\n\
7587 The commands themselves follow starting on the next line.\n\
7588 Type a line containing \"end\" to indicate the end of them.\n\
7589 Give \"silent\" as the first line to make the breakpoint silent;\n\
7590 then no output is printed when it is hit, except what the commands print.");
7592 add_com ("condition", class_breakpoint
, condition_command
,
7593 "Specify breakpoint number N to break only if COND is true.\n\
7594 Usage is `condition N COND', where N is an integer and COND is an\n\
7595 expression to be evaluated whenever breakpoint N is reached. ");
7597 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
,
7598 "Set a temporary breakpoint. Args like \"break\" command.\n\
7599 Like \"break\" except the breakpoint is only temporary,\n\
7600 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7601 by using \"enable delete\" on the breakpoint number.");
7602 c
->completer
= location_completer
;
7604 c
= add_com ("txbreak", class_breakpoint
, tbreak_at_finish_command
,
7605 "Set temporary breakpoint at procedure exit. Either there should\n\
7606 be no argument or the argument must be a depth.\n");
7607 c
->completer
= location_completer
;
7609 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
,
7610 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7611 Like \"break\" except the breakpoint requires hardware support,\n\
7612 some target hardware may not have this support.");
7613 c
->completer
= location_completer
;
7615 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
,
7616 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7617 Like \"hbreak\" except the breakpoint is only temporary,\n\
7618 so it will be deleted when hit.");
7619 c
->completer
= location_completer
;
7621 add_prefix_cmd ("enable", class_breakpoint
, enable_command
,
7622 "Enable some breakpoints.\n\
7623 Give breakpoint numbers (separated by spaces) as arguments.\n\
7624 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7625 This is used to cancel the effect of the \"disable\" command.\n\
7626 With a subcommand you can enable temporarily.",
7627 &enablelist
, "enable ", 1, &cmdlist
);
7629 add_com ("ab", class_breakpoint
, enable_command
,
7630 "Enable some breakpoints.\n\
7631 Give breakpoint numbers (separated by spaces) as arguments.\n\
7632 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7633 This is used to cancel the effect of the \"disable\" command.\n\
7634 With a subcommand you can enable temporarily.");
7636 add_com_alias ("en", "enable", class_breakpoint
, 1);
7638 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
,
7639 "Enable some breakpoints.\n\
7640 Give breakpoint numbers (separated by spaces) as arguments.\n\
7641 This is used to cancel the effect of the \"disable\" command.\n\
7642 May be abbreviated to simply \"enable\".\n",
7643 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
7645 add_cmd ("once", no_class
, enable_once_command
,
7646 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7647 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7650 add_cmd ("delete", no_class
, enable_delete_command
,
7651 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7652 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7655 add_cmd ("delete", no_class
, enable_delete_command
,
7656 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7657 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7660 add_cmd ("once", no_class
, enable_once_command
,
7661 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7662 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7665 add_prefix_cmd ("disable", class_breakpoint
, disable_command
,
7666 "Disable some breakpoints.\n\
7667 Arguments are breakpoint numbers with spaces in between.\n\
7668 To disable all breakpoints, give no argument.\n\
7669 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7670 &disablelist
, "disable ", 1, &cmdlist
);
7671 add_com_alias ("dis", "disable", class_breakpoint
, 1);
7672 add_com_alias ("disa", "disable", class_breakpoint
, 1);
7674 add_com ("sb", class_breakpoint
, disable_command
,
7675 "Disable some breakpoints.\n\
7676 Arguments are breakpoint numbers with spaces in between.\n\
7677 To disable all breakpoints, give no argument.\n\
7678 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7680 add_cmd ("breakpoints", class_alias
, disable_command
,
7681 "Disable some breakpoints.\n\
7682 Arguments are breakpoint numbers with spaces in between.\n\
7683 To disable all breakpoints, give no argument.\n\
7684 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7685 This command may be abbreviated \"disable\".",
7688 add_prefix_cmd ("delete", class_breakpoint
, delete_command
,
7689 "Delete some breakpoints or auto-display expressions.\n\
7690 Arguments are breakpoint numbers with spaces in between.\n\
7691 To delete all breakpoints, give no argument.\n\
7693 Also a prefix command for deletion of other GDB objects.\n\
7694 The \"unset\" command is also an alias for \"delete\".",
7695 &deletelist
, "delete ", 1, &cmdlist
);
7696 add_com_alias ("d", "delete", class_breakpoint
, 1);
7698 add_com ("db", class_breakpoint
, delete_command
,
7699 "Delete some breakpoints.\n\
7700 Arguments are breakpoint numbers with spaces in between.\n\
7701 To delete all breakpoints, give no argument.\n");
7703 add_cmd ("breakpoints", class_alias
, delete_command
,
7704 "Delete some breakpoints or auto-display expressions.\n\
7705 Arguments are breakpoint numbers with spaces in between.\n\
7706 To delete all breakpoints, give no argument.\n\
7707 This command may be abbreviated \"delete\".",
7710 add_com ("clear", class_breakpoint
, clear_command
,
7711 concat ("Clear breakpoint at specified line or function.\n\
7712 Argument may be line number, function name, or \"*\" and an address.\n\
7713 If line number is specified, all breakpoints in that line are cleared.\n\
7714 If function is specified, breakpoints at beginning of function are cleared.\n\
7715 If an address is specified, breakpoints at that address are cleared.\n\n",
7716 "With no argument, clears all breakpoints in the line that the selected frame\n\
7719 See also the \"delete\" command which clears breakpoints by number.", NULL
));
7721 c
= add_com ("break", class_breakpoint
, break_command
,
7722 concat ("Set breakpoint at specified line or function.\n\
7723 Argument may be line number, function name, or \"*\" and an address.\n\
7724 If line number is specified, break at start of code for that line.\n\
7725 If function is specified, break at start of code for that function.\n\
7726 If an address is specified, break at that exact address.\n",
7727 "With no arg, uses current execution address of selected stack frame.\n\
7728 This is useful for breaking on return to a stack frame.\n\
7730 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7732 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL
));
7733 c
->completer
= location_completer
;
7735 add_com_alias ("b", "break", class_run
, 1);
7736 add_com_alias ("br", "break", class_run
, 1);
7737 add_com_alias ("bre", "break", class_run
, 1);
7738 add_com_alias ("brea", "break", class_run
, 1);
7740 add_com ("xbreak", class_breakpoint
, break_at_finish_command
,
7741 concat ("Set breakpoint at procedure exit. \n\
7742 Argument may be function name, or \"*\" and an address.\n\
7743 If function is specified, break at end of code for that function.\n\
7744 If an address is specified, break at the end of the function that contains \n\
7745 that exact address.\n",
7746 "With no arg, uses current execution address of selected stack frame.\n\
7747 This is useful for breaking on return to a stack frame.\n\
7749 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7751 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL
));
7752 add_com_alias ("xb", "xbreak", class_breakpoint
, 1);
7753 add_com_alias ("xbr", "xbreak", class_breakpoint
, 1);
7754 add_com_alias ("xbre", "xbreak", class_breakpoint
, 1);
7755 add_com_alias ("xbrea", "xbreak", class_breakpoint
, 1);
7759 add_com_alias ("ba", "break", class_breakpoint
, 1);
7760 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
7761 add_com ("bx", class_breakpoint
, break_at_finish_at_depth_command
,
7762 "Set breakpoint at procedure exit. Either there should\n\
7763 be no argument or the argument must be a depth.\n");
7768 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
,
7769 "Break in function/address or break at a line in the current file.",
7770 &stoplist
, "stop ", 1, &cmdlist
);
7771 add_cmd ("in", class_breakpoint
, stopin_command
,
7772 "Break in function or address.\n", &stoplist
);
7773 add_cmd ("at", class_breakpoint
, stopat_command
,
7774 "Break at a line in the current file.\n", &stoplist
);
7775 add_com ("status", class_info
, breakpoints_info
,
7776 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7777 The \"Type\" column indicates one of:\n\
7778 \tbreakpoint - normal breakpoint\n\
7779 \twatchpoint - watchpoint\n\
7780 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7781 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7782 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7783 address and file/line number respectively.\n\n",
7784 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7785 are set to the address of the last breakpoint listed.\n\n\
7786 Convenience variable \"$bpnum\" contains the number of the last\n\
7787 breakpoint set.", NULL
));
7790 add_info ("breakpoints", breakpoints_info
,
7791 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7792 The \"Type\" column indicates one of:\n\
7793 \tbreakpoint - normal breakpoint\n\
7794 \twatchpoint - watchpoint\n\
7795 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7796 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7797 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7798 address and file/line number respectively.\n\n",
7799 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7800 are set to the address of the last breakpoint listed.\n\n\
7801 Convenience variable \"$bpnum\" contains the number of the last\n\
7802 breakpoint set.", NULL
));
7805 add_com ("lb", class_breakpoint
, breakpoints_info
,
7806 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7807 The \"Type\" column indicates one of:\n\
7808 \tbreakpoint - normal breakpoint\n\
7809 \twatchpoint - watchpoint\n\
7810 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7811 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7812 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7813 address and file/line number respectively.\n\n",
7814 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7815 are set to the address of the last breakpoint listed.\n\n\
7816 Convenience variable \"$bpnum\" contains the number of the last\n\
7817 breakpoint set.", NULL
));
7819 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
,
7820 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7821 The \"Type\" column indicates one of:\n\
7822 \tbreakpoint - normal breakpoint\n\
7823 \twatchpoint - watchpoint\n\
7824 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7825 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7826 \tuntil - internal breakpoint used by the \"until\" command\n\
7827 \tfinish - internal breakpoint used by the \"finish\" command\n",
7828 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7829 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7830 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7831 address and file/line number respectively.\n\n",
7832 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7833 are set to the address of the last breakpoint listed.\n\n\
7834 Convenience variable \"$bpnum\" contains the number of the last\n\
7835 breakpoint set.", NULL
),
7836 &maintenanceinfolist
);
7838 add_com ("catch", class_breakpoint
, catch_command
,
7839 "Set catchpoints to catch events.\n\
7840 Raised signals may be caught:\n\
7841 \tcatch signal - all signals\n\
7842 \tcatch signal <signame> - a particular signal\n\
7843 Raised exceptions may be caught:\n\
7844 \tcatch throw - all exceptions, when thrown\n\
7845 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7846 \tcatch catch - all exceptions, when caught\n\
7847 \tcatch catch <exceptname> - a particular exception, when caught\n\
7848 Thread or process events may be caught:\n\
7849 \tcatch thread_start - any threads, just after creation\n\
7850 \tcatch thread_exit - any threads, just before expiration\n\
7851 \tcatch thread_join - any threads, just after joins\n\
7852 Process events may be caught:\n\
7853 \tcatch start - any processes, just after creation\n\
7854 \tcatch exit - any processes, just before expiration\n\
7855 \tcatch fork - calls to fork()\n\
7856 \tcatch vfork - calls to vfork()\n\
7857 \tcatch exec - calls to exec()\n\
7858 Dynamically-linked library events may be caught:\n\
7859 \tcatch load - loads of any library\n\
7860 \tcatch load <libname> - loads of a particular library\n\
7861 \tcatch unload - unloads of any library\n\
7862 \tcatch unload <libname> - unloads of a particular library\n\
7863 The act of your program's execution stopping may also be caught:\n\
7865 C++ exceptions may be caught:\n\
7866 \tcatch throw - all exceptions, when thrown\n\
7867 \tcatch catch - all exceptions, when caught\n\
7869 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7870 after a fork or vfork is caught.\n\n\
7871 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7873 add_com ("tcatch", class_breakpoint
, tcatch_command
,
7874 "Set temporary catchpoints to catch events.\n\
7875 Args like \"catch\" command.\n\
7876 Like \"catch\" except the catchpoint is only temporary,\n\
7877 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7878 by using \"enable delete\" on the catchpoint number.");
7880 c
= add_com ("watch", class_breakpoint
, watch_command
,
7881 "Set a watchpoint for an expression.\n\
7882 A watchpoint stops execution of your program whenever the value of\n\
7883 an expression changes.");
7884 c
->completer
= location_completer
;
7886 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
7887 "Set a read watchpoint for an expression.\n\
7888 A watchpoint stops execution of your program whenever the value of\n\
7889 an expression is read.");
7890 c
->completer
= location_completer
;
7892 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
7893 "Set a watchpoint for an expression.\n\
7894 A watchpoint stops execution of your program whenever the value of\n\
7895 an expression is either read or written.");
7896 c
->completer
= location_completer
;
7898 add_info ("watchpoints", breakpoints_info
,
7899 "Synonym for ``info breakpoints''.");
7902 c
= add_set_cmd ("can-use-hw-watchpoints", class_support
, var_zinteger
,
7903 (char *) &can_use_hw_watchpoints
,
7904 "Set debugger's willingness to use watchpoint hardware.\n\
7905 If zero, gdb will not use hardware for new watchpoints, even if\n\
7906 such is available. (However, any hardware watchpoints that were\n\
7907 created before setting this to nonzero, will continue to use watchpoint\n\
7910 add_show_from_set (c
, &showlist
);
7912 can_use_hw_watchpoints
= 1;