1 /* Everything about breakpoints, for GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
28 #include "breakpoint.h"
30 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb_string.h"
45 #include "completer.h"
49 #include "gdb-events.h"
51 /* Prototypes for local functions. */
53 static void until_break_command_continuation (struct continuation_arg
*arg
);
55 static void catch_command_1 (char *, int, int);
57 static void enable_delete_command (char *, int);
59 static void enable_delete_breakpoint (struct breakpoint
*);
61 static void enable_once_command (char *, int);
63 static void enable_once_breakpoint (struct breakpoint
*);
65 static void disable_command (char *, int);
67 static void enable_command (char *, int);
69 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
71 static void ignore_command (char *, int);
73 static int breakpoint_re_set_one (PTR
);
75 static void clear_command (char *, int);
77 static void catch_command (char *, int);
79 static void handle_gnu_4_16_catch_command (char *, int, int);
81 static struct symtabs_and_lines
get_catch_sals (int);
83 static void watch_command (char *, int);
85 static int can_use_hardware_watchpoint (struct value
*);
87 extern void break_at_finish_command (char *, int);
88 extern void break_at_finish_at_depth_command (char *, int);
90 extern void tbreak_at_finish_command (char *, int);
92 static void break_command_1 (char *, int, int);
94 static void mention (struct breakpoint
*);
96 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
98 static void check_duplicates (struct breakpoint
*);
100 static void describe_other_breakpoints (CORE_ADDR
, asection
*);
102 static void breakpoints_info (char *, int);
104 static void breakpoint_1 (int, int);
106 static bpstat
bpstat_alloc (struct breakpoint
*, bpstat
);
108 static int breakpoint_cond_eval (PTR
);
110 static void cleanup_executing_breakpoints (PTR
);
112 static void commands_command (char *, int);
114 static void condition_command (char *, int);
116 static int get_number_trailer (char **, int);
118 void set_breakpoint_count (int);
127 static int remove_breakpoint (struct breakpoint
*, insertion_state_t
);
129 static enum print_stop_action
print_it_typical (bpstat
);
131 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
135 enum exception_event_kind kind
;
138 args_for_catchpoint_enable
;
140 static int watchpoint_check (PTR
);
142 static int cover_target_enable_exception_callback (PTR
);
144 static void maintenance_info_breakpoints (char *, int);
146 #ifdef GET_LONGJMP_TARGET
147 static void create_longjmp_breakpoint (char *);
150 static void create_overlay_event_breakpoint (char *);
152 static int hw_breakpoint_used_count (void);
154 static int hw_watchpoint_used_count (enum bptype
, int *);
156 static void hbreak_command (char *, int);
158 static void thbreak_command (char *, int);
160 static void watch_command_1 (char *, int, int);
162 static void rwatch_command (char *, int);
164 static void awatch_command (char *, int);
166 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
168 static void solib_load_unload_1 (char *hookname
,
171 char *cond_string
, enum bptype bp_kind
);
173 static void create_fork_vfork_event_catchpoint (int tempflag
,
175 enum bptype bp_kind
);
177 static void break_at_finish_at_depth_command_1 (char *arg
,
178 int flag
, int from_tty
);
180 static void break_at_finish_command_1 (char *arg
, int flag
, int from_tty
);
182 static void stop_command (char *arg
, int from_tty
);
184 static void stopin_command (char *arg
, int from_tty
);
186 static void stopat_command (char *arg
, int from_tty
);
188 static char *ep_find_event_name_end (char *arg
);
190 static char *ep_parse_optional_if_clause (char **arg
);
192 static char *ep_parse_optional_filename (char **arg
);
194 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
195 static void catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
);
198 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
199 enum exception_event_kind ex_event
,
200 struct symtab_and_line
*sal
);
202 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
203 char *arg
, int tempflag
, int from_tty
);
205 static void tcatch_command (char *arg
, int from_tty
);
207 static void ep_skip_leading_whitespace (char **s
);
209 /* Prototypes for exported functions. */
211 /* If FALSE, gdb will not use hardware support for watchpoints, even
212 if such is available. */
213 static int can_use_hw_watchpoints
;
215 void _initialize_breakpoint (void);
217 extern int addressprint
; /* Print machine addresses? */
219 /* Are we executing breakpoint commands? */
220 static int executing_breakpoint_commands
;
222 /* Walk the following statement or block through all breakpoints.
223 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
226 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
228 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
229 for (B = breakpoint_chain; \
230 B ? (TMP=B->next, 1): 0; \
233 /* True if SHIFT_INST_REGS defined, false otherwise. */
235 int must_shift_inst_regs
=
236 #if defined(SHIFT_INST_REGS)
243 /* True if breakpoint hit counts should be displayed in breakpoint info. */
245 int show_breakpoint_hit_counts
= 1;
247 /* Chain of all breakpoints defined. */
249 struct breakpoint
*breakpoint_chain
;
251 /* Number of last breakpoint made. */
253 int breakpoint_count
;
255 /* Pointer to current exception event record */
256 static struct exception_event_record
*current_exception_event
;
258 /* Indicator of whether exception catchpoints should be nuked
259 between runs of a program */
260 int exception_catchpoints_are_fragile
= 0;
262 /* Indicator of when exception catchpoints set-up should be
263 reinitialized -- e.g. when program is re-run */
264 int exception_support_initialized
= 0;
266 /* This function returns a pointer to the string representation of the
267 pathname of the dynamically-linked library that has just been
270 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
271 or undefined results are guaranteed.
273 This string's contents are only valid immediately after the
274 inferior has stopped in the dynamic linker hook, and becomes
275 invalid as soon as the inferior is continued. Clients should make
276 a copy of this string if they wish to continue the inferior and
277 then access the string. */
279 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
280 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
283 /* This function returns a pointer to the string representation of the
284 pathname of the dynamically-linked library that has just been
287 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
288 TRUE, or undefined results are guaranteed.
290 This string's contents are only valid immediately after the
291 inferior has stopped in the dynamic linker hook, and becomes
292 invalid as soon as the inferior is continued. Clients should make
293 a copy of this string if they wish to continue the inferior and
294 then access the string. */
296 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
297 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
300 /* This function is called by the "catch load" command. It allows the
301 debugger to be notified by the dynamic linker when a specified
302 library file (or any library file, if filename is NULL) is loaded. */
304 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
305 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
306 error ("catch of library loads not yet implemented on this platform")
309 /* This function is called by the "catch unload" command. It allows
310 the debugger to be notified by the dynamic linker when a specified
311 library file (or any library file, if filename is NULL) is
314 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
315 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
316 error ("catch of library unloads not yet implemented on this platform")
319 /* Set breakpoint count to NUM. */
322 set_breakpoint_count (int num
)
324 breakpoint_count
= num
;
325 set_internalvar (lookup_internalvar ("bpnum"),
326 value_from_longest (builtin_type_int
, (LONGEST
) num
));
329 /* Used in run_command to zero the hit count when a new run starts. */
332 clear_breakpoint_hit_counts (void)
334 struct breakpoint
*b
;
340 /* Default address, symtab and line to put a breakpoint at
341 for "break" command with no arg.
342 if default_breakpoint_valid is zero, the other three are
343 not valid, and "break" with no arg is an error.
345 This set by print_stack_frame, which calls set_default_breakpoint. */
347 int default_breakpoint_valid
;
348 CORE_ADDR default_breakpoint_address
;
349 struct symtab
*default_breakpoint_symtab
;
350 int default_breakpoint_line
;
352 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
353 Advance *PP after the string and any trailing whitespace.
355 Currently the string can either be a number or "$" followed by the name
356 of a convenience variable. Making it an expression wouldn't work well
357 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
359 TRAILER is a character which can be found after the number; most
360 commonly this is `-'. If you don't want a trailer, use \0. */
362 get_number_trailer (char **pp
, int trailer
)
364 int retval
= 0; /* default */
368 /* Empty line means refer to the last breakpoint. */
369 return breakpoint_count
;
372 /* Make a copy of the name, so we can null-terminate it
373 to pass to lookup_internalvar(). */
378 while (isalnum (*p
) || *p
== '_')
380 varname
= (char *) alloca (p
- start
+ 1);
381 strncpy (varname
, start
, p
- start
);
382 varname
[p
- start
] = '\0';
383 val
= value_of_internalvar (lookup_internalvar (varname
));
384 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
)
385 retval
= (int) value_as_long (val
);
388 printf_filtered ("Convenience variable must have integer value.\n");
396 while (*p
>= '0' && *p
<= '9')
399 /* There is no number here. (e.g. "cond a == b"). */
401 /* Skip non-numeric token */
402 while (*p
&& !isspace((int) *p
))
404 /* Return zero, which caller must interpret as error. */
410 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
412 /* Trailing junk: return 0 and let caller print error msg. */
413 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
424 /* Like get_number_trailer, but don't allow a trailer. */
426 get_number (char **pp
)
428 return get_number_trailer (pp
, '\0');
431 /* Parse a number or a range.
432 * A number will be of the form handled by get_number.
433 * A range will be of the form <number1> - <number2>, and
434 * will represent all the integers between number1 and number2,
437 * While processing a range, this fuction is called iteratively;
438 * At each call it will return the next value in the range.
440 * At the beginning of parsing a range, the char pointer PP will
441 * be advanced past <number1> and left pointing at the '-' token.
442 * Subsequent calls will not advance the pointer until the range
443 * is completed. The call that completes the range will advance
444 * pointer PP past <number2>.
448 get_number_or_range (char **pp
)
450 static int last_retval
, end_value
;
451 static char *end_ptr
;
452 static int in_range
= 0;
456 /* Default case: pp is pointing either to a solo number,
457 or to the first number of a range. */
458 last_retval
= get_number_trailer (pp
, '-');
463 /* This is the start of a range (<number1> - <number2>).
464 Skip the '-', parse and remember the second number,
465 and also remember the end of the final token. */
469 while (isspace ((int) *end_ptr
))
470 end_ptr
++; /* skip white space */
471 end_value
= get_number (temp
);
472 if (end_value
< last_retval
)
474 error ("inverted range");
476 else if (end_value
== last_retval
)
478 /* degenerate range (number1 == number2). Advance the
479 token pointer so that the range will be treated as a
488 error ("negative value");
491 /* pp points to the '-' that betokens a range. All
492 number-parsing has already been done. Return the next
493 integer value (one greater than the saved previous value).
494 Do not advance the token pointer 'pp' until the end of range
497 if (++last_retval
== end_value
)
499 /* End of range reached; advance token pointer. */
509 /* condition N EXP -- set break condition of breakpoint N to EXP. */
512 condition_command (char *arg
, int from_tty
)
514 register struct breakpoint
*b
;
519 error_no_arg ("breakpoint number");
522 bnum
= get_number (&p
);
524 error ("Bad breakpoint argument: '%s'", arg
);
527 if (b
->number
== bnum
)
534 if (b
->cond_string
!= NULL
)
535 xfree (b
->cond_string
);
540 b
->cond_string
= NULL
;
542 printf_filtered ("Breakpoint %d now unconditional.\n", bnum
);
547 /* I don't know if it matters whether this is the string the user
548 typed in or the decompiled expression. */
549 b
->cond_string
= savestring (arg
, strlen (arg
));
550 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->address
), 0);
552 error ("Junk at end of expression");
554 breakpoints_changed ();
558 error ("No breakpoint number %d.", bnum
);
563 commands_command (char *arg
, int from_tty
)
565 register struct breakpoint
*b
;
568 struct command_line
*l
;
570 /* If we allowed this, we would have problems with when to
571 free the storage, if we change the commands currently
574 if (executing_breakpoint_commands
)
575 error ("Can't use the \"commands\" command among a breakpoint's commands.");
578 bnum
= get_number (&p
);
581 error ("Unexpected extra arguments following breakpoint number.");
584 if (b
->number
== bnum
)
588 "Type commands for when breakpoint %d is hit, one per line.",
590 l
= read_command_lines (tmpbuf
, from_tty
);
591 free_command_lines (&b
->commands
);
593 breakpoints_changed ();
596 error ("No breakpoint number %d.", bnum
);
599 /* Like target_read_memory() but if breakpoints are inserted, return
600 the shadow contents instead of the breakpoints themselves.
602 Read "memory data" from whatever target or inferior we have.
603 Returns zero if successful, errno value if not. EIO is used
604 for address out of bounds. If breakpoints are inserted, returns
605 shadow contents, not the breakpoints themselves. From breakpoint.c. */
608 read_memory_nobpt (CORE_ADDR memaddr
, char *myaddr
, unsigned len
)
611 struct breakpoint
*b
;
612 CORE_ADDR bp_addr
= 0;
615 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
616 /* No breakpoints on this machine. */
617 return target_read_memory (memaddr
, myaddr
, len
);
621 if (b
->type
== bp_none
)
622 warning ("reading through apparently deleted breakpoint #%d?",
625 /* memory breakpoint? */
626 if (b
->type
== bp_watchpoint
627 || b
->type
== bp_hardware_watchpoint
628 || b
->type
== bp_read_watchpoint
629 || b
->type
== bp_access_watchpoint
)
634 /* Addresses and length of the part of the breakpoint that
636 /* XXXX The m68k, sh and h8300 have different local and remote
637 breakpoint values. BREAKPOINT_FROM_PC still manages to
638 correctly determine the breakpoints memory address and size
639 for these targets. */
640 bp_addr
= b
->address
;
642 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
647 if (bp_addr
+ bp_size
<= memaddr
)
648 /* The breakpoint is entirely before the chunk of memory we
651 if (bp_addr
>= memaddr
+ len
)
652 /* The breakpoint is entirely after the chunk of memory we are
655 /* Copy the breakpoint from the shadow contents, and recurse for
656 the things before and after. */
658 /* Offset within shadow_contents. */
661 if (bp_addr
< memaddr
)
663 /* Only copy the second part of the breakpoint. */
664 bp_size
-= memaddr
- bp_addr
;
665 bptoffset
= memaddr
- bp_addr
;
669 if (bp_addr
+ bp_size
> memaddr
+ len
)
671 /* Only copy the first part of the breakpoint. */
672 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
675 memcpy (myaddr
+ bp_addr
- memaddr
,
676 b
->shadow_contents
+ bptoffset
, bp_size
);
678 if (bp_addr
> memaddr
)
680 /* Copy the section of memory before the breakpoint. */
681 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
686 if (bp_addr
+ bp_size
< memaddr
+ len
)
688 /* Copy the section of memory after the breakpoint. */
689 status
= read_memory_nobpt (bp_addr
+ bp_size
,
690 myaddr
+ bp_addr
+ bp_size
- memaddr
,
691 memaddr
+ len
- (bp_addr
+ bp_size
));
698 /* Nothing overlaps. Just call read_memory_noerr. */
699 return target_read_memory (memaddr
, myaddr
, len
);
703 /* insert_breakpoints is used when starting or continuing the program.
704 remove_breakpoints is used when the program stops.
705 Both return zero if successful,
706 or an `errno' value if could not write the inferior. */
709 insert_breakpoints (void)
711 register struct breakpoint
*b
, *temp
;
712 int return_val
= 0; /* return success code. */
714 int disabled_breaks
= 0;
716 static char message1
[] = "Error inserting catchpoint %d:\n";
717 static char message
[sizeof (message1
) + 30];
720 ALL_BREAKPOINTS_SAFE (b
, temp
)
722 if (b
->enable_state
== bp_permanent
)
723 /* Permanent breakpoints cannot be inserted or removed. */
725 else if (b
->type
!= bp_watchpoint
726 && b
->type
!= bp_hardware_watchpoint
727 && b
->type
!= bp_read_watchpoint
728 && b
->type
!= bp_access_watchpoint
729 && b
->type
!= bp_catch_fork
730 && b
->type
!= bp_catch_vfork
731 && b
->type
!= bp_catch_exec
732 && b
->type
!= bp_catch_throw
733 && b
->type
!= bp_catch_catch
734 && b
->enable_state
!= bp_disabled
735 && b
->enable_state
!= bp_shlib_disabled
736 && b
->enable_state
!= bp_call_disabled
740 if (b
->type
== bp_hardware_breakpoint
)
741 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
744 /* Check to see if breakpoint is in an overlay section;
745 if so, we should set the breakpoint at the LMA address.
746 Only if the section is currently mapped should we ALSO
747 set a break at the VMA address. */
748 if (overlay_debugging
&& b
->section
749 && section_is_overlay (b
->section
))
753 addr
= overlay_unmapped_address (b
->address
, b
->section
);
754 val
= target_insert_breakpoint (addr
, b
->shadow_contents
);
755 /* This would be the time to check val, to see if the
756 breakpoint write to the load address succeeded.
757 However, this might be an ordinary occurrance, eg. if
758 the unmapped overlay is in ROM. */
759 val
= 0; /* in case unmapped address failed */
760 if (section_is_mapped (b
->section
))
761 val
= target_insert_breakpoint (b
->address
,
764 else /* ordinary (non-overlay) address */
765 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
769 /* Can't set the breakpoint. */
770 #if defined (DISABLE_UNSETTABLE_BREAK)
771 if (DISABLE_UNSETTABLE_BREAK (b
->address
))
773 /* See also: disable_breakpoints_in_shlibs. */
775 b
->enable_state
= bp_shlib_disabled
;
776 if (!disabled_breaks
)
778 target_terminal_ours_for_output ();
779 warning ("Cannot insert breakpoint %d:", b
->number
);
780 warning ("Temporarily disabling shared library breakpoints:");
783 warning ("breakpoint #%d ", b
->number
);
788 target_terminal_ours_for_output ();
789 warning ("Cannot insert breakpoint %d:", b
->number
);
790 #ifdef ONE_PROCESS_WRITETEXT
791 warning ("The same program may be running in another process.");
793 memory_error (val
, b
->address
); /* which bombs us out */
800 return_val
= val
; /* remember failure */
802 else if (ep_is_exception_catchpoint (b
)
803 && b
->enable_state
!= bp_disabled
804 && b
->enable_state
!= bp_shlib_disabled
805 && b
->enable_state
!= bp_call_disabled
810 /* If we get here, we must have a callback mechanism for exception
811 events -- with g++ style embedded label support, we insert
812 ordinary breakpoints and not catchpoints. */
813 /* Format possible error message */
814 sprintf (message
, message1
, b
->number
);
816 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
819 /* Couldn't set breakpoint for some reason */
820 target_terminal_ours_for_output ();
821 warning ("Cannot insert catchpoint %d; disabling it.",
823 b
->enable_state
= bp_disabled
;
827 /* Bp set, now make sure callbacks are enabled */
829 args_for_catchpoint_enable args
;
830 args
.kind
= b
->type
== bp_catch_catch
?
831 EX_EVENT_CATCH
: EX_EVENT_THROW
;
833 val
= catch_errors (cover_target_enable_exception_callback
,
835 message
, RETURN_MASK_ALL
);
836 if (val
!= 0 && val
!= -1)
840 /* Check if something went wrong; val == 0 can be ignored */
843 /* something went wrong */
844 target_terminal_ours_for_output ();
845 warning ("Cannot insert catchpoint %d; disabling it.",
847 b
->enable_state
= bp_disabled
;
852 return_val
= val
; /* remember failure */
855 else if ((b
->type
== bp_hardware_watchpoint
||
856 b
->type
== bp_read_watchpoint
||
857 b
->type
== bp_access_watchpoint
)
858 && b
->enable_state
== bp_enabled
859 && b
->disposition
!= disp_del_at_next_stop
863 struct frame_info
*saved_frame
;
864 int saved_level
, within_current_scope
;
865 struct value
*mark
= value_mark ();
868 /* Save the current frame and level so we can restore it after
869 evaluating the watchpoint expression on its own frame. */
870 saved_frame
= selected_frame
;
871 saved_level
= selected_frame_level
;
873 /* Determine if the watchpoint is within scope. */
874 if (b
->exp_valid_block
== NULL
)
875 within_current_scope
= 1;
878 struct frame_info
*fi
;
880 /* There might be no current frame at this moment if we are
881 resuming from a step over a breakpoint.
882 Set up current frame before trying to find the watchpoint
884 get_current_frame ();
885 fi
= find_frame_addr_in_frame_chain (b
->watchpoint_frame
);
886 within_current_scope
= (fi
!= NULL
);
887 if (within_current_scope
)
888 select_frame (fi
, -1);
891 if (within_current_scope
)
893 /* Evaluate the expression and cut the chain of values
894 produced off from the value chain.
896 Make sure the value returned isn't lazy; we use
897 laziness to determine what memory GDB actually needed
898 in order to compute the value of the expression. */
899 v
= evaluate_expression (b
->exp
);
901 value_release_to_mark (mark
);
906 /* Look at each value on the value chain. */
907 for (; v
; v
= v
->next
)
909 /* If it's a memory location, and GDB actually needed
910 its contents to evaluate the expression, then we
912 if (VALUE_LVAL (v
) == lval_memory
915 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
917 /* We only watch structs and arrays if user asked
918 for it explicitly, never if they just happen to
919 appear in the middle of some value chain. */
920 if (v
== b
->val_chain
921 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
922 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
927 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
928 len
= TYPE_LENGTH (VALUE_TYPE (v
));
930 if (b
->type
== bp_read_watchpoint
)
932 else if (b
->type
== bp_access_watchpoint
)
935 val
= target_insert_watchpoint (addr
, len
, type
);
938 /* Don't exit the loop, try to insert
939 every value on the value chain. That's
940 because we will be removing all the
941 watches below, and removing a
942 watchpoint we didn't insert could have
950 /* Failure to insert a watchpoint on any memory value in the
951 value chain brings us here. */
954 remove_breakpoint (b
, mark_uninserted
);
955 warning ("Could not insert hardware watchpoint %d.",
962 printf_filtered ("Hardware watchpoint %d deleted ", b
->number
);
963 printf_filtered ("because the program has left the block \n");
964 printf_filtered ("in which its expression is valid.\n");
965 if (b
->related_breakpoint
)
966 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
967 b
->disposition
= disp_del_at_next_stop
;
970 /* Restore the frame and level. */
971 if ((saved_frame
!= selected_frame
) ||
972 (saved_level
!= selected_frame_level
))
973 select_frame (saved_frame
, saved_level
);
976 return_val
= val
; /* remember failure */
978 else if ((b
->type
== bp_catch_fork
979 || b
->type
== bp_catch_vfork
980 || b
->type
== bp_catch_exec
)
981 && b
->enable_state
== bp_enabled
989 val
= target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
992 val
= target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
995 val
= target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
998 warning ("Internal error, %s line %d.", __FILE__
, __LINE__
);
1003 target_terminal_ours_for_output ();
1004 warning ("Cannot insert catchpoint %d.", b
->number
);
1010 return_val
= val
; /* remember failure */
1019 remove_breakpoints (void)
1021 register struct breakpoint
*b
;
1028 val
= remove_breakpoint (b
, mark_uninserted
);
1037 remove_hw_watchpoints (void)
1039 register struct breakpoint
*b
;
1045 && (b
->type
== bp_hardware_watchpoint
1046 || b
->type
== bp_read_watchpoint
1047 || b
->type
== bp_access_watchpoint
))
1049 val
= remove_breakpoint (b
, mark_uninserted
);
1058 reattach_breakpoints (int pid
)
1060 register struct breakpoint
*b
;
1062 struct cleanup
*old_chain
= save_inferior_ptid ();
1064 /* Set inferior_ptid; remove_breakpoint uses this global. */
1065 inferior_ptid
= pid_to_ptid (pid
);
1070 remove_breakpoint (b
, mark_inserted
);
1071 if (b
->type
== bp_hardware_breakpoint
)
1072 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
1074 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
1077 do_cleanups (old_chain
);
1082 do_cleanups (old_chain
);
1087 update_breakpoints_after_exec (void)
1089 struct breakpoint
*b
;
1090 struct breakpoint
*temp
;
1092 /* Doing this first prevents the badness of having delete_breakpoint()
1093 write a breakpoint's current "shadow contents" to lift the bp. That
1094 shadow is NOT valid after an exec()! */
1095 mark_breakpoints_out ();
1097 ALL_BREAKPOINTS_SAFE (b
, temp
)
1099 /* Solib breakpoints must be explicitly reset after an exec(). */
1100 if (b
->type
== bp_shlib_event
)
1102 delete_breakpoint (b
);
1106 /* Thread event breakpoints must be set anew after an exec(),
1107 as must overlay event breakpoints. */
1108 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1110 delete_breakpoint (b
);
1114 /* Step-resume breakpoints are meaningless after an exec(). */
1115 if (b
->type
== bp_step_resume
)
1117 delete_breakpoint (b
);
1121 /* Ditto the sigtramp handler breakpoints. */
1122 if (b
->type
== bp_through_sigtramp
)
1124 delete_breakpoint (b
);
1128 /* Ditto the exception-handling catchpoints. */
1129 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1131 delete_breakpoint (b
);
1135 /* Don't delete an exec catchpoint, because else the inferior
1136 won't stop when it ought!
1138 Similarly, we probably ought to keep vfork catchpoints, 'cause
1139 on this target, we may not be able to stop when the vfork is
1140 seen, but only when the subsequent exec is seen. (And because
1141 deleting fork catchpoints here but not vfork catchpoints will
1142 seem mysterious to users, keep those too.)
1144 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1145 target address field, if any, is sufficient to have it be reset
1146 automagically. Certainly on HP-UX that's true.
1148 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1149 valid code address on some platforms (like the mn10200 and
1150 mn10300 simulators). We shouldn't assign any special
1151 interpretation to a breakpoint with a zero address. And in
1152 fact, GDB doesn't --- I can't see what that comment above is
1153 talking about. As far as I can tell, setting the address of a
1154 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1155 is meaningless, since those are implemented with HP-UX kernel
1156 hackery, not by storing breakpoint instructions somewhere. */
1157 if ((b
->type
== bp_catch_exec
) ||
1158 (b
->type
== bp_catch_vfork
) ||
1159 (b
->type
== bp_catch_fork
))
1161 b
->address
= (CORE_ADDR
) NULL
;
1165 /* bp_finish is a special case. The only way we ought to be able
1166 to see one of these when an exec() has happened, is if the user
1167 caught a vfork, and then said "finish". Ordinarily a finish just
1168 carries them to the call-site of the current callee, by setting
1169 a temporary bp there and resuming. But in this case, the finish
1170 will carry them entirely through the vfork & exec.
1172 We don't want to allow a bp_finish to remain inserted now. But
1173 we can't safely delete it, 'cause finish_command has a handle to
1174 the bp on a bpstat, and will later want to delete it. There's a
1175 chance (and I've seen it happen) that if we delete the bp_finish
1176 here, that its storage will get reused by the time finish_command
1177 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1178 We really must allow finish_command to delete a bp_finish.
1180 In the absense of a general solution for the "how do we know
1181 it's safe to delete something others may have handles to?"
1182 problem, what we'll do here is just uninsert the bp_finish, and
1183 let finish_command delete it.
1185 (We know the bp_finish is "doomed" in the sense that it's
1186 momentary, and will be deleted as soon as finish_command sees
1187 the inferior stopped. So it doesn't matter that the bp's
1188 address is probably bogus in the new a.out, unlike e.g., the
1189 solib breakpoints.) */
1191 if (b
->type
== bp_finish
)
1196 /* Without a symbolic address, we have little hope of the
1197 pre-exec() address meaning the same thing in the post-exec()
1199 if (b
->addr_string
== NULL
)
1201 delete_breakpoint (b
);
1205 /* If this breakpoint has survived the above battery of checks, then
1206 it must have a symbolic address. Be sure that it gets reevaluated
1207 to a target address, rather than reusing the old evaluation.
1209 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1210 for bp_catch_exec and friends, I'm pretty sure this is entirely
1211 unnecessary. A call to breakpoint_re_set_one always recomputes
1212 the breakpoint's address from scratch, or deletes it if it can't.
1213 So I think this assignment could be deleted without effect. */
1214 b
->address
= (CORE_ADDR
) NULL
;
1216 /* FIXME what about longjmp breakpoints? Re-create them here? */
1217 create_overlay_event_breakpoint ("_ovly_debug_event");
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_state
== bp_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_state
== bp_enabled
1311 b
->inserted
= (is
== mark_inserted
);
1312 /* Walk down the saved value chain. */
1313 for (v
= b
->val_chain
; v
; v
= v
->next
)
1315 /* For each memory reference remove the watchpoint
1317 if (VALUE_LVAL (v
) == lval_memory
1318 && ! VALUE_LAZY (v
))
1320 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
1322 if (v
== b
->val_chain
1323 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1324 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1329 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1330 len
= TYPE_LENGTH (VALUE_TYPE (v
));
1332 if (b
->type
== bp_read_watchpoint
)
1334 else if (b
->type
== bp_access_watchpoint
)
1337 val
= target_remove_watchpoint (addr
, len
, type
);
1344 /* Failure to remove any of the hardware watchpoints comes here. */
1345 if ((is
== mark_uninserted
) && (b
->inserted
))
1346 warning ("Could not remove hardware watchpoint %d.",
1349 /* Free the saved value chain. We will construct a new one
1350 the next time the watchpoint is inserted. */
1351 for (v
= b
->val_chain
; v
; v
= n
)
1356 b
->val_chain
= NULL
;
1358 else if ((b
->type
== bp_catch_fork
||
1359 b
->type
== bp_catch_vfork
||
1360 b
->type
== bp_catch_exec
)
1361 && b
->enable_state
== bp_enabled
1368 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1370 case bp_catch_vfork
:
1371 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1374 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1377 warning ("Internal error, %s line %d.", __FILE__
, __LINE__
);
1382 b
->inserted
= (is
== mark_inserted
);
1384 else if ((b
->type
== bp_catch_catch
||
1385 b
->type
== bp_catch_throw
)
1386 && b
->enable_state
== bp_enabled
1390 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1393 b
->inserted
= (is
== mark_inserted
);
1395 else if (ep_is_exception_catchpoint (b
)
1396 && b
->inserted
/* sometimes previous insert doesn't happen */
1397 && b
->enable_state
== bp_enabled
1401 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1405 b
->inserted
= (is
== mark_inserted
);
1411 /* Clear the "inserted" flag in all breakpoints. */
1414 mark_breakpoints_out (void)
1416 register struct breakpoint
*b
;
1422 /* Clear the "inserted" flag in all breakpoints and delete any
1423 breakpoints which should go away between runs of the program.
1425 Plus other such housekeeping that has to be done for breakpoints
1428 Note: this function gets called at the end of a run (by
1429 generic_mourn_inferior) and when a run begins (by
1430 init_wait_for_inferior). */
1435 breakpoint_init_inferior (enum inf_context context
)
1437 register struct breakpoint
*b
, *temp
;
1438 static int warning_needed
= 0;
1440 ALL_BREAKPOINTS_SAFE (b
, temp
)
1447 case bp_watchpoint_scope
:
1449 /* If the call dummy breakpoint is at the entry point it will
1450 cause problems when the inferior is rerun, so we better
1453 Also get rid of scope breakpoints. */
1454 delete_breakpoint (b
);
1458 case bp_hardware_watchpoint
:
1459 case bp_read_watchpoint
:
1460 case bp_access_watchpoint
:
1462 /* Likewise for watchpoints on local expressions. */
1463 if (b
->exp_valid_block
!= NULL
)
1464 delete_breakpoint (b
);
1467 /* Likewise for exception catchpoints in dynamic-linked
1468 executables where required */
1469 if (ep_is_exception_catchpoint (b
) &&
1470 exception_catchpoints_are_fragile
)
1473 delete_breakpoint (b
);
1479 if (exception_catchpoints_are_fragile
)
1480 exception_support_initialized
= 0;
1482 /* Don't issue the warning unless it's really needed... */
1483 if (warning_needed
&& (context
!= inf_exited
))
1485 warning ("Exception catchpoints from last run were deleted.");
1486 warning ("You must reinsert them explicitly.");
1491 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1492 exists at PC. It returns ordinary_breakpoint_here if it's an
1493 ordinary breakpoint, or permanent_breakpoint_here if it's a
1494 permanent breakpoint.
1495 - When continuing from a location with an ordinary breakpoint, we
1496 actually single step once before calling insert_breakpoints.
1497 - When continuing from a localion with a permanent breakpoint, we
1498 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1499 the target, to advance the PC past the breakpoint. */
1501 enum breakpoint_here
1502 breakpoint_here_p (CORE_ADDR pc
)
1504 register struct breakpoint
*b
;
1505 int any_breakpoint_here
= 0;
1508 if ((b
->enable_state
== bp_enabled
1509 || b
->enable_state
== bp_permanent
)
1510 && b
->address
== pc
) /* bp is enabled and matches pc */
1512 if (overlay_debugging
1513 && section_is_overlay (b
->section
)
1514 && !section_is_mapped (b
->section
))
1515 continue; /* unmapped overlay -- can't be a match */
1516 else if (b
->enable_state
== bp_permanent
)
1517 return permanent_breakpoint_here
;
1519 any_breakpoint_here
= 1;
1522 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1526 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1527 but it only returns true if there is actually a breakpoint inserted
1531 breakpoint_inserted_here_p (CORE_ADDR pc
)
1533 register struct breakpoint
*b
;
1537 && b
->address
== pc
) /* bp is inserted and matches pc */
1539 if (overlay_debugging
1540 && section_is_overlay (b
->section
)
1541 && !section_is_mapped (b
->section
))
1542 continue; /* unmapped overlay -- can't be a match */
1550 /* Return nonzero if FRAME is a dummy frame. We can't use
1551 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1552 much time, at least using get_saved_register on the 68k. This
1553 means that for this function to work right a port must use the
1554 bp_call_dummy breakpoint. */
1557 frame_in_dummy (struct frame_info
*frame
)
1559 struct breakpoint
*b
;
1564 if (USE_GENERIC_DUMMY_FRAMES
)
1565 return generic_pc_in_call_dummy (frame
->pc
, frame
->frame
, frame
->frame
);
1569 if (b
->type
== bp_call_dummy
1570 && b
->frame
== frame
->frame
1571 /* We need to check the PC as well as the frame on the sparc,
1572 for signals.exp in the testsuite. */
1575 - SIZEOF_CALL_DUMMY_WORDS
/ sizeof (LONGEST
) * REGISTER_SIZE
))
1576 && frame
->pc
<= b
->address
)
1582 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1583 PC is valid for process/thread PID. */
1586 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1588 struct breakpoint
*b
;
1591 thread
= pid_to_thread_id (ptid
);
1594 if (b
->enable_state
!= bp_disabled
1595 && b
->enable_state
!= bp_shlib_disabled
1596 && b
->enable_state
!= bp_call_disabled
1598 && (b
->thread
== -1 || b
->thread
== thread
))
1600 if (overlay_debugging
1601 && section_is_overlay (b
->section
)
1602 && !section_is_mapped (b
->section
))
1603 continue; /* unmapped overlay -- can't be a match */
1612 /* bpstat stuff. External routines' interfaces are documented
1616 ep_is_catchpoint (struct breakpoint
*ep
)
1619 (ep
->type
== bp_catch_load
)
1620 || (ep
->type
== bp_catch_unload
)
1621 || (ep
->type
== bp_catch_fork
)
1622 || (ep
->type
== bp_catch_vfork
)
1623 || (ep
->type
== bp_catch_exec
)
1624 || (ep
->type
== bp_catch_catch
)
1625 || (ep
->type
== bp_catch_throw
);
1627 /* ??rehrauer: Add more kinds here, as are implemented... */
1631 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1634 (ep
->type
== bp_catch_load
)
1635 || (ep
->type
== bp_catch_unload
);
1639 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1642 (ep
->type
== bp_catch_catch
)
1643 || (ep
->type
== bp_catch_throw
);
1646 /* Clear a bpstat so that it says we are not at any breakpoint.
1647 Also free any storage that is part of a bpstat. */
1650 bpstat_clear (bpstat
*bsp
)
1661 if (p
->old_val
!= NULL
)
1662 value_free (p
->old_val
);
1669 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1670 is part of the bpstat is copied as well. */
1673 bpstat_copy (bpstat bs
)
1677 bpstat retval
= NULL
;
1682 for (; bs
!= NULL
; bs
= bs
->next
)
1684 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1685 memcpy (tmp
, bs
, sizeof (*tmp
));
1687 /* This is the first thing in the chain. */
1697 /* Find the bpstat associated with this breakpoint */
1700 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1705 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1707 if (bsp
->breakpoint_at
== breakpoint
)
1713 /* Find a step_resume breakpoint associated with this bpstat.
1714 (If there are multiple step_resume bp's on the list, this function
1715 will arbitrarily pick one.)
1717 It is an error to use this function if BPSTAT doesn't contain a
1718 step_resume breakpoint.
1720 See wait_for_inferior's use of this function. */
1722 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1727 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1729 current_thread
= pid_to_thread_id (inferior_ptid
);
1731 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1733 if ((bsp
->breakpoint_at
!= NULL
) &&
1734 (bsp
->breakpoint_at
->type
== bp_step_resume
) &&
1735 (bsp
->breakpoint_at
->thread
== current_thread
||
1736 bsp
->breakpoint_at
->thread
== -1))
1737 return bsp
->breakpoint_at
;
1740 error ("Internal error (no step_resume breakpoint found)");
1744 /* Return the breakpoint number of the first breakpoint we are stopped
1745 at. *BSP upon return is a bpstat which points to the remaining
1746 breakpoints stopped at (but which is not guaranteed to be good for
1747 anything but further calls to bpstat_num).
1748 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1751 bpstat_num (bpstat
*bsp
)
1753 struct breakpoint
*b
;
1756 return 0; /* No more breakpoint values */
1759 b
= (*bsp
)->breakpoint_at
;
1760 *bsp
= (*bsp
)->next
;
1762 return -1; /* breakpoint that's been deleted since */
1764 return b
->number
; /* We have its number */
1768 /* Modify BS so that the actions will not be performed. */
1771 bpstat_clear_actions (bpstat bs
)
1773 for (; bs
!= NULL
; bs
= bs
->next
)
1775 bs
->commands
= NULL
;
1776 if (bs
->old_val
!= NULL
)
1778 value_free (bs
->old_val
);
1784 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1787 cleanup_executing_breakpoints (PTR ignore
)
1789 executing_breakpoint_commands
= 0;
1792 /* Execute all the commands associated with all the breakpoints at this
1793 location. Any of these commands could cause the process to proceed
1794 beyond this point, etc. We look out for such changes by checking
1795 the global "breakpoint_proceeded" after each command. */
1798 bpstat_do_actions (bpstat
*bsp
)
1801 struct cleanup
*old_chain
;
1802 struct command_line
*cmd
;
1804 /* Avoid endless recursion if a `source' command is contained
1806 if (executing_breakpoint_commands
)
1809 executing_breakpoint_commands
= 1;
1810 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
1813 /* Note that (as of this writing), our callers all appear to
1814 be passing us the address of global stop_bpstat. And, if
1815 our calls to execute_control_command cause the inferior to
1816 proceed, that global (and hence, *bsp) will change.
1818 We must be careful to not touch *bsp unless the inferior
1819 has not proceeded. */
1821 /* This pointer will iterate over the list of bpstat's. */
1824 breakpoint_proceeded
= 0;
1825 for (; bs
!= NULL
; bs
= bs
->next
)
1830 execute_control_command (cmd
);
1832 if (breakpoint_proceeded
)
1837 if (breakpoint_proceeded
)
1838 /* The inferior is proceeded by the command; bomb out now.
1839 The bpstat chain has been blown away by wait_for_inferior.
1840 But since execution has stopped again, there is a new bpstat
1841 to look at, so start over. */
1844 bs
->commands
= NULL
;
1847 executing_breakpoint_commands
= 0;
1848 discard_cleanups (old_chain
);
1851 /* This is the normal print function for a bpstat. In the future,
1852 much of this logic could (should?) be moved to bpstat_stop_status,
1853 by having it set different print_it values.
1855 Current scheme: When we stop, bpstat_print() is called. It loops
1856 through the bpstat list of things causing this stop, calling the
1857 print_bp_stop_message function on each one. The behavior of the
1858 print_bp_stop_message function depends on the print_it field of
1859 bpstat. If such field so indicates, call this function here.
1861 Return values from this routine (ultimately used by bpstat_print()
1862 and normal_stop() to decide what to do):
1863 PRINT_NOTHING: Means we already printed all we needed to print,
1864 don't print anything else.
1865 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1866 that something to be followed by a location.
1867 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1868 that something to be followed by a location.
1869 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
1872 static enum print_stop_action
1873 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
);
1879 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1880 which has since been deleted. */
1881 if (bs
->breakpoint_at
== NULL
)
1882 return PRINT_UNKNOWN
;
1884 switch (bs
->breakpoint_at
->type
)
1887 case bp_hardware_breakpoint
:
1888 annotate_breakpoint (bs
->breakpoint_at
->number
);
1889 ui_out_text (uiout
, "\nBreakpoint ");
1890 if (ui_out_is_mi_like_p (uiout
))
1891 ui_out_field_string (uiout
, "reason", "breakpoint-hit");
1892 ui_out_field_int (uiout
, "bkptno", bs
->breakpoint_at
->number
);
1893 ui_out_text (uiout
, ", ");
1894 return PRINT_SRC_AND_LOC
;
1897 case bp_shlib_event
:
1898 /* Did we stop because the user set the stop_on_solib_events
1899 variable? (If so, we report this as a generic, "Stopped due
1900 to shlib event" message.) */
1901 printf_filtered ("Stopped due to shared library event\n");
1902 return PRINT_NOTHING
;
1905 case bp_thread_event
:
1906 /* Not sure how we will get here.
1907 GDB should not stop for these breakpoints. */
1908 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
1909 return PRINT_NOTHING
;
1912 case bp_overlay_event
:
1913 /* By analogy with the thread event, GDB should not stop for these. */
1914 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
1915 return PRINT_NOTHING
;
1919 annotate_catchpoint (bs
->breakpoint_at
->number
);
1920 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
1921 printf_filtered ("loaded");
1922 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
1923 return PRINT_SRC_AND_LOC
;
1926 case bp_catch_unload
:
1927 annotate_catchpoint (bs
->breakpoint_at
->number
);
1928 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
1929 printf_filtered ("unloaded");
1930 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
1931 return PRINT_SRC_AND_LOC
;
1935 annotate_catchpoint (bs
->breakpoint_at
->number
);
1936 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
1937 printf_filtered ("forked");
1938 printf_filtered (" process %d), ",
1939 bs
->breakpoint_at
->forked_inferior_pid
);
1940 return PRINT_SRC_AND_LOC
;
1943 case bp_catch_vfork
:
1944 annotate_catchpoint (bs
->breakpoint_at
->number
);
1945 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
1946 printf_filtered ("vforked");
1947 printf_filtered (" process %d), ",
1948 bs
->breakpoint_at
->forked_inferior_pid
);
1949 return PRINT_SRC_AND_LOC
;
1953 annotate_catchpoint (bs
->breakpoint_at
->number
);
1954 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
1955 bs
->breakpoint_at
->number
,
1956 bs
->breakpoint_at
->exec_pathname
);
1957 return PRINT_SRC_AND_LOC
;
1960 case bp_catch_catch
:
1961 if (current_exception_event
&&
1962 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
1964 annotate_catchpoint (bs
->breakpoint_at
->number
);
1965 printf_filtered ("\nCatchpoint %d (exception caught), ",
1966 bs
->breakpoint_at
->number
);
1967 printf_filtered ("throw location ");
1968 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
1969 printf_filtered ("%s:%d",
1970 CURRENT_EXCEPTION_THROW_FILE
,
1971 CURRENT_EXCEPTION_THROW_LINE
);
1973 printf_filtered ("unknown");
1975 printf_filtered (", catch location ");
1976 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
1977 printf_filtered ("%s:%d",
1978 CURRENT_EXCEPTION_CATCH_FILE
,
1979 CURRENT_EXCEPTION_CATCH_LINE
);
1981 printf_filtered ("unknown");
1983 printf_filtered ("\n");
1984 /* don't bother to print location frame info */
1985 return PRINT_SRC_ONLY
;
1989 /* really throw, some other bpstat will handle it */
1990 return PRINT_UNKNOWN
;
1994 case bp_catch_throw
:
1995 if (current_exception_event
&&
1996 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
1998 annotate_catchpoint (bs
->breakpoint_at
->number
);
1999 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2000 bs
->breakpoint_at
->number
);
2001 printf_filtered ("throw location ");
2002 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2003 printf_filtered ("%s:%d",
2004 CURRENT_EXCEPTION_THROW_FILE
,
2005 CURRENT_EXCEPTION_THROW_LINE
);
2007 printf_filtered ("unknown");
2009 printf_filtered (", catch location ");
2010 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2011 printf_filtered ("%s:%d",
2012 CURRENT_EXCEPTION_CATCH_FILE
,
2013 CURRENT_EXCEPTION_CATCH_LINE
);
2015 printf_filtered ("unknown");
2017 printf_filtered ("\n");
2018 /* don't bother to print location frame info */
2019 return PRINT_SRC_ONLY
;
2023 /* really catch, some other bpstat will handle it */
2024 return PRINT_UNKNOWN
;
2029 case bp_hardware_watchpoint
:
2030 if (bs
->old_val
!= NULL
)
2032 annotate_watchpoint (bs
->breakpoint_at
->number
);
2033 if (ui_out_is_mi_like_p (uiout
))
2034 ui_out_field_string (uiout
, "reason", "watchpoint-trigger");
2035 mention (bs
->breakpoint_at
);
2036 ui_out_tuple_begin (uiout
, "value");
2037 ui_out_text (uiout
, "\nOld value = ");
2038 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2039 ui_out_field_stream (uiout
, "old", stb
);
2040 ui_out_text (uiout
, "\nNew value = ");
2041 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2042 ui_out_field_stream (uiout
, "new", stb
);
2043 ui_out_tuple_end (uiout
);
2044 ui_out_text (uiout
, "\n");
2045 value_free (bs
->old_val
);
2048 /* More than one watchpoint may have been triggered. */
2049 return PRINT_UNKNOWN
;
2052 case bp_read_watchpoint
:
2053 if (ui_out_is_mi_like_p (uiout
))
2054 ui_out_field_string (uiout
, "reason", "read-watchpoint-trigger");
2055 mention (bs
->breakpoint_at
);
2056 ui_out_tuple_begin (uiout
, "value");
2057 ui_out_text (uiout
, "\nValue = ");
2058 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2059 ui_out_field_stream (uiout
, "value", stb
);
2060 ui_out_tuple_end (uiout
);
2061 ui_out_text (uiout
, "\n");
2062 return PRINT_UNKNOWN
;
2065 case bp_access_watchpoint
:
2066 if (bs
->old_val
!= NULL
)
2068 annotate_watchpoint (bs
->breakpoint_at
->number
);
2069 if (ui_out_is_mi_like_p (uiout
))
2070 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2071 mention (bs
->breakpoint_at
);
2072 ui_out_tuple_begin (uiout
, "value");
2073 ui_out_text (uiout
, "\nOld value = ");
2074 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2075 ui_out_field_stream (uiout
, "old", stb
);
2076 value_free (bs
->old_val
);
2078 ui_out_text (uiout
, "\nNew value = ");
2082 mention (bs
->breakpoint_at
);
2083 if (ui_out_is_mi_like_p (uiout
))
2084 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2085 ui_out_tuple_begin (uiout
, "value");
2086 ui_out_text (uiout
, "\nValue = ");
2088 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0,Val_pretty_default
);
2089 ui_out_field_stream (uiout
, "new", stb
);
2090 ui_out_tuple_end (uiout
);
2091 ui_out_text (uiout
, "\n");
2092 return PRINT_UNKNOWN
;
2095 /* Fall through, we don't deal with these types of breakpoints
2099 if (ui_out_is_mi_like_p (uiout
))
2100 ui_out_field_string (uiout
, "reason", "function-finished");
2101 return PRINT_UNKNOWN
;
2105 if (ui_out_is_mi_like_p (uiout
))
2106 ui_out_field_string (uiout
, "reason", "location-reached");
2107 return PRINT_UNKNOWN
;
2112 case bp_longjmp_resume
:
2113 case bp_step_resume
:
2114 case bp_through_sigtramp
:
2115 case bp_watchpoint_scope
:
2118 return PRINT_UNKNOWN
;
2122 /* Generic routine for printing messages indicating why we
2123 stopped. The behavior of this function depends on the value
2124 'print_it' in the bpstat structure. Under some circumstances we
2125 may decide not to print anything here and delegate the task to
2128 static enum print_stop_action
2129 print_bp_stop_message (bpstat bs
)
2131 switch (bs
->print_it
)
2134 /* Nothing should be printed for this bpstat entry. */
2135 return PRINT_UNKNOWN
;
2139 /* We still want to print the frame, but we already printed the
2140 relevant messages. */
2141 return PRINT_SRC_AND_LOC
;
2144 case print_it_normal
:
2145 /* Normal case, we handle everything in print_it_typical. */
2146 return print_it_typical (bs
);
2149 internal_error (__FILE__
, __LINE__
,
2150 "print_bp_stop_message: unrecognized enum value");
2155 /* Print a message indicating what happened. This is called from
2156 normal_stop(). The input to this routine is the head of the bpstat
2157 list - a list of the eventpoints that caused this stop. This
2158 routine calls the generic print routine for printing a message
2159 about reasons for stopping. This will print (for example) the
2160 "Breakpoint n," part of the output. The return value of this
2163 PRINT_UNKNOWN: Means we printed nothing
2164 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2165 code to print the location. An example is
2166 "Breakpoint 1, " which should be followed by
2168 PRINT_SRC_ONLY: Means we printed something, but there is no need
2169 to also print the location part of the message.
2170 An example is the catch/throw messages, which
2171 don't require a location appended to the end.
2172 PRINT_NOTHING: We have done some printing and we don't need any
2173 further info to be printed.*/
2175 enum print_stop_action
2176 bpstat_print (bpstat bs
)
2180 /* Maybe another breakpoint in the chain caused us to stop.
2181 (Currently all watchpoints go on the bpstat whether hit or not.
2182 That probably could (should) be changed, provided care is taken
2183 with respect to bpstat_explains_signal). */
2184 for (; bs
; bs
= bs
->next
)
2186 val
= print_bp_stop_message (bs
);
2187 if (val
== PRINT_SRC_ONLY
2188 || val
== PRINT_SRC_AND_LOC
2189 || val
== PRINT_NOTHING
)
2193 /* We reached the end of the chain, or we got a null BS to start
2194 with and nothing was printed. */
2195 return PRINT_UNKNOWN
;
2198 /* Evaluate the expression EXP and return 1 if value is zero.
2199 This is used inside a catch_errors to evaluate the breakpoint condition.
2200 The argument is a "struct expression *" that has been cast to char * to
2201 make it pass through catch_errors. */
2204 breakpoint_cond_eval (PTR exp
)
2206 struct value
*mark
= value_mark ();
2207 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2208 value_free_to_mark (mark
);
2212 /* Allocate a new bpstat and chain it to the current one. */
2215 bpstat_alloc (struct breakpoint
*b
, bpstat cbs
/* Current "bs" value */ )
2219 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2221 bs
->breakpoint_at
= b
;
2222 /* If the condition is false, etc., don't do the commands. */
2223 bs
->commands
= NULL
;
2225 bs
->print_it
= print_it_normal
;
2229 /* Possible return values for watchpoint_check (this can't be an enum
2230 because of check_errors). */
2231 /* The watchpoint has been deleted. */
2232 #define WP_DELETED 1
2233 /* The value has changed. */
2234 #define WP_VALUE_CHANGED 2
2235 /* The value has not changed. */
2236 #define WP_VALUE_NOT_CHANGED 3
2238 #define BP_TEMPFLAG 1
2239 #define BP_HARDWAREFLAG 2
2241 /* Check watchpoint condition. */
2244 watchpoint_check (PTR p
)
2246 bpstat bs
= (bpstat
) p
;
2247 struct breakpoint
*b
;
2248 struct frame_info
*fr
;
2249 int within_current_scope
;
2251 b
= bs
->breakpoint_at
;
2253 if (b
->exp_valid_block
== NULL
)
2254 within_current_scope
= 1;
2257 /* There is no current frame at this moment. If we're going to have
2258 any chance of handling watchpoints on local variables, we'll need
2259 the frame chain (so we can determine if we're in scope). */
2260 reinit_frame_cache ();
2261 fr
= find_frame_addr_in_frame_chain (b
->watchpoint_frame
);
2262 within_current_scope
= (fr
!= NULL
);
2263 /* in_function_epilogue_p() returns a non-zero value if we're still
2264 in the function but the stack frame has already been invalidated.
2265 Since we can't rely on the values of local variables after the
2266 stack has been destroyed, we are treating the watchpoint in that
2267 state as `not changed' without further checking. */
2268 if (within_current_scope
&& fr
== get_current_frame ()
2269 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2270 return WP_VALUE_NOT_CHANGED
;
2271 if (within_current_scope
)
2272 /* If we end up stopping, the current frame will get selected
2273 in normal_stop. So this call to select_frame won't affect
2275 select_frame (fr
, -1);
2278 if (within_current_scope
)
2280 /* We use value_{,free_to_}mark because it could be a
2281 *long* time before we return to the command level and
2282 call free_all_values. We can't call free_all_values because
2283 we might be in the middle of evaluating a function call. */
2285 struct value
*mark
= value_mark ();
2286 struct value
*new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
2287 if (!value_equal (b
->val
, new_val
))
2289 release_value (new_val
);
2290 value_free_to_mark (mark
);
2291 bs
->old_val
= b
->val
;
2293 /* We will stop here */
2294 return WP_VALUE_CHANGED
;
2298 /* Nothing changed, don't do anything. */
2299 value_free_to_mark (mark
);
2300 /* We won't stop here */
2301 return WP_VALUE_NOT_CHANGED
;
2306 /* This seems like the only logical thing to do because
2307 if we temporarily ignored the watchpoint, then when
2308 we reenter the block in which it is valid it contains
2309 garbage (in the case of a function, it may have two
2310 garbage values, one before and one after the prologue).
2311 So we can't even detect the first assignment to it and
2312 watch after that (since the garbage may or may not equal
2313 the first value assigned). */
2314 /* We print all the stop information in print_it_typical(), but
2315 in this case, by the time we call print_it_typical() this bp
2316 will be deleted already. So we have no choice but print the
2317 information here. */
2318 if (ui_out_is_mi_like_p (uiout
))
2319 ui_out_field_string (uiout
, "reason", "watchpoint-scope");
2320 ui_out_text (uiout
, "\nWatchpoint ");
2321 ui_out_field_int (uiout
, "wpnum", bs
->breakpoint_at
->number
);
2322 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2323 which its expression is valid.\n");
2325 if (b
->related_breakpoint
)
2326 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2327 b
->disposition
= disp_del_at_next_stop
;
2333 /* Get a bpstat associated with having just stopped at address *PC
2334 and frame address CORE_ADDRESS. Update *PC to point at the
2335 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2336 if this is known to not be a real breakpoint (it could still be a
2337 watchpoint, though). */
2339 /* Determine whether we stopped at a breakpoint, etc, or whether we
2340 don't understand this stop. Result is a chain of bpstat's such that:
2342 if we don't understand the stop, the result is a null pointer.
2344 if we understand why we stopped, the result is not null.
2346 Each element of the chain refers to a particular breakpoint or
2347 watchpoint at which we have stopped. (We may have stopped for
2348 several reasons concurrently.)
2350 Each element of the chain has valid next, breakpoint_at,
2351 commands, FIXME??? fields. */
2354 bpstat_stop_status (CORE_ADDR
*pc
, int not_a_breakpoint
)
2356 register struct breakpoint
*b
, *temp
;
2358 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2359 int real_breakpoint
= 0;
2360 /* Root of the chain of bpstat's */
2361 struct bpstats root_bs
[1];
2362 /* Pointer to the last thing in the chain currently. */
2363 bpstat bs
= root_bs
;
2364 static char message1
[] =
2365 "Error evaluating expression for watchpoint %d\n";
2366 char message
[sizeof (message1
) + 30 /* slop */ ];
2368 /* Get the address where the breakpoint would have been.
2369 The "not_a_breakpoint" argument is meant to distinguish
2370 between a breakpoint trap event and a trace/singlestep
2371 trap event. For a trace/singlestep trap event, we would
2372 not want to subtract DECR_PC_AFTER_BREAK from the PC. */
2374 bp_addr
= *pc
- (not_a_breakpoint
&& !SOFTWARE_SINGLE_STEP_P () ?
2375 0 : DECR_PC_AFTER_BREAK
);
2377 ALL_BREAKPOINTS_SAFE (b
, temp
)
2379 if (b
->enable_state
== bp_disabled
2380 || b
->enable_state
== bp_shlib_disabled
2381 || b
->enable_state
== bp_call_disabled
)
2384 if (b
->type
!= bp_watchpoint
2385 && b
->type
!= bp_hardware_watchpoint
2386 && b
->type
!= bp_read_watchpoint
2387 && b
->type
!= bp_access_watchpoint
2388 && b
->type
!= bp_hardware_breakpoint
2389 && b
->type
!= bp_catch_fork
2390 && b
->type
!= bp_catch_vfork
2391 && b
->type
!= bp_catch_exec
2392 && b
->type
!= bp_catch_catch
2393 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2395 if (b
->address
!= bp_addr
) /* address doesn't match */
2397 if (overlay_debugging
/* unmapped overlay section */
2398 && section_is_overlay (b
->section
)
2399 && !section_is_mapped (b
->section
))
2403 if (b
->type
== bp_hardware_breakpoint
2404 && b
->address
!= (*pc
- DECR_PC_AFTER_HW_BREAK
))
2407 /* Is this a catchpoint of a load or unload? If so, did we
2408 get a load or unload of the specified library? If not,
2410 if ((b
->type
== bp_catch_load
)
2411 #if defined(SOLIB_HAVE_LOAD_EVENT)
2412 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2413 || ((b
->dll_pathname
!= NULL
)
2414 && (strcmp (b
->dll_pathname
,
2415 SOLIB_LOADED_LIBRARY_PATHNAME (
2416 PIDGET (inferior_ptid
)))
2422 if ((b
->type
== bp_catch_unload
)
2423 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2424 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2425 || ((b
->dll_pathname
!= NULL
)
2426 && (strcmp (b
->dll_pathname
,
2427 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2428 PIDGET (inferior_ptid
)))
2434 if ((b
->type
== bp_catch_fork
)
2435 && !target_has_forked (PIDGET (inferior_ptid
),
2436 &b
->forked_inferior_pid
))
2439 if ((b
->type
== bp_catch_vfork
)
2440 && !target_has_vforked (PIDGET (inferior_ptid
),
2441 &b
->forked_inferior_pid
))
2444 if ((b
->type
== bp_catch_exec
)
2445 && !target_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2448 if (ep_is_exception_catchpoint (b
) &&
2449 !(current_exception_event
= target_get_current_exception_event ()))
2452 /* Come here if it's a watchpoint, or if the break address matches */
2454 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
2456 /* Watchpoints may change this, if not found to have triggered. */
2460 sprintf (message
, message1
, b
->number
);
2461 if (b
->type
== bp_watchpoint
||
2462 b
->type
== bp_hardware_watchpoint
)
2464 switch (catch_errors (watchpoint_check
, bs
, message
,
2468 /* We've already printed what needs to be printed. */
2469 /* Actually this is superfluous, because by the time we
2470 call print_it_typical() the wp will be already deleted,
2471 and the function will return immediately. */
2472 bs
->print_it
= print_it_done
;
2475 case WP_VALUE_CHANGED
:
2479 case WP_VALUE_NOT_CHANGED
:
2481 bs
->print_it
= print_it_noop
;
2488 /* Error from catch_errors. */
2489 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2490 if (b
->related_breakpoint
)
2491 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2492 b
->disposition
= disp_del_at_next_stop
;
2493 /* We've already printed what needs to be printed. */
2494 bs
->print_it
= print_it_done
;
2500 else if (b
->type
== bp_read_watchpoint
||
2501 b
->type
== bp_access_watchpoint
)
2507 addr
= target_stopped_data_address ();
2510 for (v
= b
->val_chain
; v
; v
= v
->next
)
2512 if (VALUE_LVAL (v
) == lval_memory
2513 && ! VALUE_LAZY (v
))
2515 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
2517 if (v
== b
->val_chain
2518 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2519 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2523 vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
2524 /* Exact match not required. Within range is
2526 if (addr
>= vaddr
&&
2527 addr
< vaddr
+ TYPE_LENGTH (VALUE_TYPE (v
)))
2533 switch (catch_errors (watchpoint_check
, bs
, message
,
2537 /* We've already printed what needs to be printed. */
2538 bs
->print_it
= print_it_done
;
2541 case WP_VALUE_CHANGED
:
2542 if (b
->type
== bp_read_watchpoint
)
2544 /* Don't stop: read watchpoints shouldn't fire if
2545 the value has changed. This is for targets which
2546 cannot set read-only watchpoints. */
2547 bs
->print_it
= print_it_noop
;
2553 case WP_VALUE_NOT_CHANGED
:
2560 /* Error from catch_errors. */
2561 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2562 if (b
->related_breakpoint
)
2563 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2564 b
->disposition
= disp_del_at_next_stop
;
2565 /* We've already printed what needs to be printed. */
2566 bs
->print_it
= print_it_done
;
2569 else /* found == 0 */
2571 /* This is a case where some watchpoint(s) triggered,
2572 but not at the address of this watchpoint (FOUND
2573 was left zero). So don't print anything for this
2575 bs
->print_it
= print_it_noop
;
2582 /* By definition, an encountered breakpoint is a triggered
2586 real_breakpoint
= 1;
2590 b
->frame
!= (get_current_frame ())->frame
)
2594 int value_is_zero
= 0;
2598 /* Need to select the frame, with all that implies
2599 so that the conditions will have the right context. */
2600 select_frame (get_current_frame (), 0);
2602 = catch_errors (breakpoint_cond_eval
, (b
->cond
),
2603 "Error in testing breakpoint condition:\n",
2605 /* FIXME-someday, should give breakpoint # */
2608 if (b
->cond
&& value_is_zero
)
2611 /* Don't consider this a hit. */
2614 else if (b
->ignore_count
> 0)
2617 annotate_ignore_count_change ();
2622 /* We will stop here */
2623 if (b
->disposition
== disp_disable
)
2624 b
->enable_state
= bp_disabled
;
2625 bs
->commands
= b
->commands
;
2629 (STREQ ("silent", bs
->commands
->line
) ||
2630 (xdb_commands
&& STREQ ("Q", bs
->commands
->line
))))
2632 bs
->commands
= bs
->commands
->next
;
2637 /* Print nothing for this entry if we dont stop or if we dont print. */
2638 if (bs
->stop
== 0 || bs
->print
== 0)
2639 bs
->print_it
= print_it_noop
;
2642 bs
->next
= NULL
; /* Terminate the chain */
2643 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2645 if (real_breakpoint
&& bs
)
2647 if (bs
->breakpoint_at
->type
== bp_hardware_breakpoint
)
2649 if (DECR_PC_AFTER_HW_BREAK
!= 0)
2651 *pc
= *pc
- DECR_PC_AFTER_HW_BREAK
;
2657 if (DECR_PC_AFTER_BREAK
!= 0 || must_shift_inst_regs
)
2660 #if defined (SHIFT_INST_REGS)
2662 #else /* No SHIFT_INST_REGS. */
2664 #endif /* No SHIFT_INST_REGS. */
2669 /* The value of a hardware watchpoint hasn't changed, but the
2670 intermediate memory locations we are watching may have. */
2671 if (bs
&& !bs
->stop
&&
2672 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
2673 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
2674 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
2676 remove_breakpoints ();
2677 insert_breakpoints ();
2682 /* Tell what to do about this bpstat. */
2684 bpstat_what (bpstat bs
)
2686 /* Classify each bpstat as one of the following. */
2689 /* This bpstat element has no effect on the main_action. */
2692 /* There was a watchpoint, stop but don't print. */
2695 /* There was a watchpoint, stop and print. */
2698 /* There was a breakpoint but we're not stopping. */
2701 /* There was a breakpoint, stop but don't print. */
2704 /* There was a breakpoint, stop and print. */
2707 /* We hit the longjmp breakpoint. */
2710 /* We hit the longjmp_resume breakpoint. */
2713 /* We hit the step_resume breakpoint. */
2716 /* We hit the through_sigtramp breakpoint. */
2719 /* We hit the shared library event breakpoint. */
2722 /* We caught a shared library event. */
2725 /* This is just used to count how many enums there are. */
2729 /* Here is the table which drives this routine. So that we can
2730 format it pretty, we define some abbreviations for the
2731 enum bpstat_what codes. */
2732 #define kc BPSTAT_WHAT_KEEP_CHECKING
2733 #define ss BPSTAT_WHAT_STOP_SILENT
2734 #define sn BPSTAT_WHAT_STOP_NOISY
2735 #define sgl BPSTAT_WHAT_SINGLE
2736 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2737 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2738 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2739 #define sr BPSTAT_WHAT_STEP_RESUME
2740 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2741 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2742 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2744 /* "Can't happen." Might want to print an error message.
2745 abort() is not out of the question, but chances are GDB is just
2746 a bit confused, not unusable. */
2747 #define err BPSTAT_WHAT_STOP_NOISY
2749 /* Given an old action and a class, come up with a new action. */
2750 /* One interesting property of this table is that wp_silent is the same
2751 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2752 after stopping, the check for whether to step over a breakpoint
2753 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2754 reference to how we stopped. We retain separate wp_silent and
2755 bp_silent codes in case we want to change that someday.
2757 Another possibly interesting property of this table is that
2758 there's a partial ordering, priority-like, of the actions. Once
2759 you've decided that some action is appropriate, you'll never go
2760 back and decide something of a lower priority is better. The
2763 kc < clr sgl shl shlr slr sn sr ss ts
2764 sgl < clrs shl shlr slr sn sr ss ts
2765 slr < err shl shlr sn sr ss ts
2766 clr < clrs err shl shlr sn sr ss ts
2767 clrs < err shl shlr sn sr ss ts
2768 ss < shl shlr sn sr ts
2775 What I think this means is that we don't need a damned table
2776 here. If you just put the rows and columns in the right order,
2777 it'd look awfully regular. We could simply walk the bpstat list
2778 and choose the highest priority action we find, with a little
2779 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2780 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2781 is messy anyway). */
2783 /* step_resume entries: a step resume breakpoint overrides another
2784 breakpoint of signal handling (see comment in wait_for_inferior
2785 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2786 /* We handle the through_sigtramp_breakpoint the same way; having both
2787 one of those and a step_resume_breakpoint is probably very rare (?). */
2789 static const enum bpstat_what_main_action
2790 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
2793 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2796 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, ts
, shl
, shlr
},
2798 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2800 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2802 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, ts
, shl
, shlr
},
2804 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2806 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2808 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, ts
, shl
, shlr
},
2810 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, ts
, shl
, shlr
},
2812 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, ts
, shl
, shlr
},
2814 {ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, shl
, shlr
},
2816 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, shl
, ts
, shl
, shlr
},
2818 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, ts
, shlr
, shlr
}
2833 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
2834 struct bpstat_what retval
;
2836 retval
.call_dummy
= 0;
2837 for (; bs
!= NULL
; bs
= bs
->next
)
2839 enum class bs_class
= no_effect
;
2840 if (bs
->breakpoint_at
== NULL
)
2841 /* I suspect this can happen if it was a momentary breakpoint
2842 which has since been deleted. */
2844 switch (bs
->breakpoint_at
->type
)
2850 case bp_hardware_breakpoint
:
2856 bs_class
= bp_noisy
;
2858 bs_class
= bp_silent
;
2861 bs_class
= bp_nostop
;
2864 case bp_hardware_watchpoint
:
2865 case bp_read_watchpoint
:
2866 case bp_access_watchpoint
:
2870 bs_class
= wp_noisy
;
2872 bs_class
= wp_silent
;
2875 /* There was a watchpoint, but we're not stopping.
2876 This requires no further action. */
2877 bs_class
= no_effect
;
2880 bs_class
= long_jump
;
2882 case bp_longjmp_resume
:
2883 bs_class
= long_resume
;
2885 case bp_step_resume
:
2888 bs_class
= step_resume
;
2891 /* It is for the wrong frame. */
2892 bs_class
= bp_nostop
;
2894 case bp_through_sigtramp
:
2895 bs_class
= through_sig
;
2897 case bp_watchpoint_scope
:
2898 bs_class
= bp_nostop
;
2900 case bp_shlib_event
:
2901 bs_class
= shlib_event
;
2903 case bp_thread_event
:
2904 case bp_overlay_event
:
2905 bs_class
= bp_nostop
;
2908 case bp_catch_unload
:
2909 /* Only if this catchpoint triggered should we cause the
2910 step-out-of-dld behaviour. Otherwise, we ignore this
2913 bs_class
= catch_shlib_event
;
2915 bs_class
= no_effect
;
2918 case bp_catch_vfork
:
2923 bs_class
= bp_noisy
;
2925 bs_class
= bp_silent
;
2928 /* There was a catchpoint, but we're not stopping.
2929 This requires no further action. */
2930 bs_class
= no_effect
;
2932 case bp_catch_catch
:
2933 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
2934 bs_class
= bp_nostop
;
2936 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
2938 case bp_catch_throw
:
2939 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
2940 bs_class
= bp_nostop
;
2942 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
2945 /* Make sure the action is stop (silent or noisy),
2946 so infrun.c pops the dummy frame. */
2947 bs_class
= bp_silent
;
2948 retval
.call_dummy
= 1;
2951 current_action
= table
[(int) bs_class
][(int) current_action
];
2953 retval
.main_action
= current_action
;
2957 /* Nonzero if we should step constantly (e.g. watchpoints on machines
2958 without hardware support). This isn't related to a specific bpstat,
2959 just to things like whether watchpoints are set. */
2962 bpstat_should_step (void)
2964 struct breakpoint
*b
;
2966 if (b
->enable_state
== bp_enabled
&& b
->type
== bp_watchpoint
)
2971 /* Nonzero if there are enabled hardware watchpoints. */
2973 bpstat_have_active_hw_watchpoints (void)
2975 struct breakpoint
*b
;
2977 if ((b
->enable_state
== bp_enabled
) &&
2979 ((b
->type
== bp_hardware_watchpoint
) ||
2980 (b
->type
== bp_read_watchpoint
) ||
2981 (b
->type
== bp_access_watchpoint
)))
2987 /* Given a bpstat that records zero or more triggered eventpoints, this
2988 function returns another bpstat which contains only the catchpoints
2989 on that first list, if any. */
2991 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
2993 struct bpstats root_bs
[1];
2994 bpstat bs
= root_bs
;
2995 struct breakpoint
*ep
;
2998 bpstat_clear (cp_list
);
2999 root_bs
->next
= NULL
;
3001 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3003 /* Is this eventpoint a catchpoint? If not, ignore it. */
3004 ep
= ep_list
->breakpoint_at
;
3007 if ((ep
->type
!= bp_catch_load
) &&
3008 (ep
->type
!= bp_catch_unload
) &&
3009 (ep
->type
!= bp_catch_catch
) &&
3010 (ep
->type
!= bp_catch_throw
))
3011 /* pai: (temp) ADD fork/vfork here!! */
3014 /* Yes; add it to the list. */
3015 bs
= bpstat_alloc (ep
, bs
);
3020 #if defined(SOLIB_ADD)
3021 /* Also, for each triggered catchpoint, tag it with the name of
3022 the library that caused this trigger. (We copy the name now,
3023 because it's only guaranteed to be available NOW, when the
3024 catchpoint triggers. Clients who may wish to know the name
3025 later must get it from the catchpoint itself.) */
3026 if (ep
->triggered_dll_pathname
!= NULL
)
3027 xfree (ep
->triggered_dll_pathname
);
3028 if (ep
->type
== bp_catch_load
)
3029 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3030 PIDGET (inferior_ptid
));
3032 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3033 PIDGET (inferior_ptid
));
3035 dll_pathname
= NULL
;
3039 ep
->triggered_dll_pathname
= (char *)
3040 xmalloc (strlen (dll_pathname
) + 1);
3041 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3044 ep
->triggered_dll_pathname
= NULL
;
3050 /* Print B to gdb_stdout. */
3052 print_one_breakpoint (struct breakpoint
*b
,
3053 CORE_ADDR
*last_addr
)
3055 register struct command_line
*l
;
3056 register struct symbol
*sym
;
3057 struct ep_type_description
3062 static struct ep_type_description bptypes
[] =
3064 {bp_none
, "?deleted?"},
3065 {bp_breakpoint
, "breakpoint"},
3066 {bp_hardware_breakpoint
, "hw breakpoint"},
3067 {bp_until
, "until"},
3068 {bp_finish
, "finish"},
3069 {bp_watchpoint
, "watchpoint"},
3070 {bp_hardware_watchpoint
, "hw watchpoint"},
3071 {bp_read_watchpoint
, "read watchpoint"},
3072 {bp_access_watchpoint
, "acc watchpoint"},
3073 {bp_longjmp
, "longjmp"},
3074 {bp_longjmp_resume
, "longjmp resume"},
3075 {bp_step_resume
, "step resume"},
3076 {bp_through_sigtramp
, "sigtramp"},
3077 {bp_watchpoint_scope
, "watchpoint scope"},
3078 {bp_call_dummy
, "call dummy"},
3079 {bp_shlib_event
, "shlib events"},
3080 {bp_thread_event
, "thread events"},
3081 {bp_overlay_event
, "overlay events"},
3082 {bp_catch_load
, "catch load"},
3083 {bp_catch_unload
, "catch unload"},
3084 {bp_catch_fork
, "catch fork"},
3085 {bp_catch_vfork
, "catch vfork"},
3086 {bp_catch_exec
, "catch exec"},
3087 {bp_catch_catch
, "catch catch"},
3088 {bp_catch_throw
, "catch throw"}
3091 static char *bpdisps
[] =
3092 {"del", "dstp", "dis", "keep"};
3093 static char bpenables
[] = "nynny";
3094 char wrap_indent
[80];
3095 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3096 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3099 ui_out_tuple_begin (uiout
, "bkpt");
3103 ui_out_field_int (uiout
, "number", b
->number
);
3107 if (((int) b
->type
> (sizeof (bptypes
) / sizeof (bptypes
[0])))
3108 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3109 internal_error (__FILE__
, __LINE__
,
3110 "bptypes table does not describe type #%d.",
3112 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3116 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3120 ui_out_field_fmt (uiout
, "enabled", "%c", bpenables
[(int) b
->enable_state
]);
3121 ui_out_spaces (uiout
, 2);
3124 strcpy (wrap_indent
, " ");
3127 if (TARGET_ADDR_BIT
<= 32)
3128 strcat (wrap_indent
, " ");
3130 strcat (wrap_indent
, " ");
3135 internal_error (__FILE__
, __LINE__
,
3136 "print_one_breakpoint: bp_none encountered\n");
3140 case bp_hardware_watchpoint
:
3141 case bp_read_watchpoint
:
3142 case bp_access_watchpoint
:
3143 /* Field 4, the address, is omitted (which makes the columns
3144 not line up too nicely with the headers, but the effect
3145 is relatively readable). */
3147 ui_out_field_skip (uiout
, "addr");
3149 print_expression (b
->exp
, stb
->stream
);
3150 ui_out_field_stream (uiout
, "what", stb
);
3154 case bp_catch_unload
:
3155 /* Field 4, the address, is omitted (which makes the columns
3156 not line up too nicely with the headers, but the effect
3157 is relatively readable). */
3159 ui_out_field_skip (uiout
, "addr");
3161 if (b
->dll_pathname
== NULL
)
3163 ui_out_field_string (uiout
, "what", "<any library>");
3164 ui_out_spaces (uiout
, 1);
3168 ui_out_text (uiout
, "library \"");
3169 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3170 ui_out_text (uiout
, "\" ");
3175 case bp_catch_vfork
:
3176 /* Field 4, the address, is omitted (which makes the columns
3177 not line up too nicely with the headers, but the effect
3178 is relatively readable). */
3180 ui_out_field_skip (uiout
, "addr");
3182 if (b
->forked_inferior_pid
!= 0)
3184 ui_out_text (uiout
, "process ");
3185 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3186 ui_out_spaces (uiout
, 1);
3190 /* Field 4, the address, is omitted (which makes the columns
3191 not line up too nicely with the headers, but the effect
3192 is relatively readable). */
3194 ui_out_field_skip (uiout
, "addr");
3196 if (b
->exec_pathname
!= NULL
)
3198 ui_out_text (uiout
, "program \"");
3199 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3200 ui_out_text (uiout
, "\" ");
3204 case bp_catch_catch
:
3205 /* Field 4, the address, is omitted (which makes the columns
3206 not line up too nicely with the headers, but the effect
3207 is relatively readable). */
3209 ui_out_field_skip (uiout
, "addr");
3211 ui_out_field_string (uiout
, "what", "exception catch");
3212 ui_out_spaces (uiout
, 1);
3215 case bp_catch_throw
:
3216 /* Field 4, the address, is omitted (which makes the columns
3217 not line up too nicely with the headers, but the effect
3218 is relatively readable). */
3220 ui_out_field_skip (uiout
, "addr");
3222 ui_out_field_string (uiout
, "what", "exception throw");
3223 ui_out_spaces (uiout
, 1);
3227 case bp_hardware_breakpoint
:
3231 case bp_longjmp_resume
:
3232 case bp_step_resume
:
3233 case bp_through_sigtramp
:
3234 case bp_watchpoint_scope
:
3236 case bp_shlib_event
:
3237 case bp_thread_event
:
3238 case bp_overlay_event
:
3242 ui_out_field_core_addr (uiout
, "addr", b
->address
);
3245 *last_addr
= b
->address
;
3248 sym
= find_pc_sect_function (b
->address
, b
->section
);
3251 ui_out_text (uiout
, "in ");
3252 ui_out_field_string (uiout
, "func",
3253 SYMBOL_SOURCE_NAME (sym
));
3254 ui_out_wrap_hint (uiout
, wrap_indent
);
3255 ui_out_text (uiout
, " at ");
3257 ui_out_field_string (uiout
, "file", b
->source_file
);
3258 ui_out_text (uiout
, ":");
3259 ui_out_field_int (uiout
, "line", b
->line_number
);
3263 print_address_symbolic (b
->address
, stb
->stream
, demangle
, "");
3264 ui_out_field_stream (uiout
, "at", stb
);
3269 if (b
->thread
!= -1)
3271 /* FIXME: This seems to be redundant and lost here; see the
3272 "stop only in" line a little further down. */
3273 ui_out_text (uiout
, " thread ");
3274 ui_out_field_int (uiout
, "thread", b
->thread
);
3277 ui_out_text (uiout
, "\n");
3282 ui_out_text (uiout
, "\tstop only in stack frame at ");
3283 ui_out_field_core_addr (uiout
, "frame", b
->frame
);
3284 ui_out_text (uiout
, "\n");
3290 ui_out_text (uiout
, "\tstop only if ");
3291 print_expression (b
->cond
, stb
->stream
);
3292 ui_out_field_stream (uiout
, "cond", stb
);
3293 ui_out_text (uiout
, "\n");
3296 if (b
->thread
!= -1)
3298 /* FIXME should make an annotation for this */
3299 ui_out_text (uiout
, "\tstop only in thread ");
3300 ui_out_field_int (uiout
, "thread", b
->thread
);
3301 ui_out_text (uiout
, "\n");
3304 if (show_breakpoint_hit_counts
&& b
->hit_count
)
3306 /* FIXME should make an annotation for this */
3307 if (ep_is_catchpoint (b
))
3308 ui_out_text (uiout
, "\tcatchpoint");
3310 ui_out_text (uiout
, "\tbreakpoint");
3311 ui_out_text (uiout
, " already hit ");
3312 ui_out_field_int (uiout
, "times", b
->hit_count
);
3313 if (b
->hit_count
== 1)
3314 ui_out_text (uiout
, " time\n");
3316 ui_out_text (uiout
, " times\n");
3319 /* Output the count also if it is zero, but only if this is
3320 mi. FIXME: Should have a better test for this. */
3321 if (ui_out_is_mi_like_p (uiout
))
3322 if (show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3323 ui_out_field_int (uiout
, "times", b
->hit_count
);
3325 if (b
->ignore_count
)
3328 ui_out_text (uiout
, "\tignore next ");
3329 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3330 ui_out_text (uiout
, " hits\n");
3333 if ((l
= b
->commands
))
3336 ui_out_tuple_begin (uiout
, "script");
3337 print_command_lines (uiout
, l
, 4);
3338 ui_out_tuple_end (uiout
);
3340 ui_out_tuple_end (uiout
);
3341 do_cleanups (old_chain
);
3344 struct captured_breakpoint_query_args
3350 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3352 struct captured_breakpoint_query_args
*args
= data
;
3353 register struct breakpoint
*b
;
3354 CORE_ADDR dummy_addr
= 0;
3357 if (args
->bnum
== b
->number
)
3359 print_one_breakpoint (b
, &dummy_addr
);
3367 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
)
3369 struct captured_breakpoint_query_args args
;
3371 /* For the moment we don't trust print_one_breakpoint() to not throw
3373 return catch_exceptions (uiout
, do_captured_breakpoint_query
, &args
,
3374 NULL
, RETURN_MASK_ALL
);
3377 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3378 catchpoints, et.al.). */
3381 user_settable_breakpoint (const struct breakpoint
*b
)
3383 return (b
->type
== bp_breakpoint
3384 || b
->type
== bp_catch_load
3385 || b
->type
== bp_catch_unload
3386 || b
->type
== bp_catch_fork
3387 || b
->type
== bp_catch_vfork
3388 || b
->type
== bp_catch_exec
3389 || b
->type
== bp_catch_catch
3390 || b
->type
== bp_catch_throw
3391 || b
->type
== bp_hardware_breakpoint
3392 || b
->type
== bp_watchpoint
3393 || b
->type
== bp_read_watchpoint
3394 || b
->type
== bp_access_watchpoint
3395 || b
->type
== bp_hardware_watchpoint
);
3398 /* Print information on user settable breakpoint (watchpoint, etc)
3399 number BNUM. If BNUM is -1 print all user settable breakpoints.
3400 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3403 breakpoint_1 (int bnum
, int allflag
)
3405 register struct breakpoint
*b
;
3406 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3407 int nr_printable_breakpoints
;
3409 /* Compute the number of rows in the table. */
3410 nr_printable_breakpoints
= 0;
3413 || bnum
== b
->number
)
3415 if (allflag
|| user_settable_breakpoint (b
))
3416 nr_printable_breakpoints
++;
3420 ui_out_table_begin (uiout
, 6, nr_printable_breakpoints
, "BreakpointTable");
3422 ui_out_table_begin (uiout
, 5, nr_printable_breakpoints
, "BreakpointTable");
3424 if (nr_printable_breakpoints
> 0)
3425 annotate_breakpoints_headers ();
3426 if (nr_printable_breakpoints
> 0)
3428 ui_out_table_header (uiout
, 3, ui_left
, "number", "Num"); /* 1 */
3429 if (nr_printable_breakpoints
> 0)
3431 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3432 if (nr_printable_breakpoints
> 0)
3434 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3435 if (nr_printable_breakpoints
> 0)
3437 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3440 if (nr_printable_breakpoints
> 0)
3442 if (TARGET_ADDR_BIT
<= 32)
3443 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3445 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3447 if (nr_printable_breakpoints
> 0)
3449 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3450 ui_out_table_body (uiout
);
3451 if (nr_printable_breakpoints
> 0)
3452 annotate_breakpoints_table ();
3456 || bnum
== b
->number
)
3458 /* We only print out user settable breakpoints unless the
3460 if (allflag
|| user_settable_breakpoint (b
))
3461 print_one_breakpoint (b
, &last_addr
);
3464 ui_out_table_end (uiout
);
3466 if (nr_printable_breakpoints
== 0)
3469 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3471 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3476 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3477 that a comparison of an unsigned with -1 is always false. */
3478 if (last_addr
!= (CORE_ADDR
) -1)
3479 set_next_address (last_addr
);
3482 /* FIXME? Should this be moved up so that it is only called when
3483 there have been breakpoints? */
3484 annotate_breakpoints_table_end ();
3489 breakpoints_info (char *bnum_exp
, int from_tty
)
3494 bnum
= parse_and_eval_long (bnum_exp
);
3496 breakpoint_1 (bnum
, 0);
3501 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3506 bnum
= parse_and_eval_long (bnum_exp
);
3508 breakpoint_1 (bnum
, 1);
3511 /* Print a message describing any breakpoints set at PC. */
3514 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
)
3516 register int others
= 0;
3517 register struct breakpoint
*b
;
3520 if (b
->address
== pc
) /* address match / overlay match */
3521 if (!overlay_debugging
|| b
->section
== section
)
3525 printf_filtered ("Note: breakpoint%s ", (others
> 1) ? "s" : "");
3527 if (b
->address
== pc
) /* address match / overlay match */
3528 if (!overlay_debugging
|| b
->section
== section
)
3531 printf_filtered ("%d%s%s ",
3533 ((b
->enable_state
== bp_disabled
||
3534 b
->enable_state
== bp_shlib_disabled
||
3535 b
->enable_state
== bp_call_disabled
)
3537 : b
->enable_state
== bp_permanent
3541 : ((others
== 1) ? " and" : ""));
3543 printf_filtered ("also set at pc ");
3544 print_address_numeric (pc
, 1, gdb_stdout
);
3545 printf_filtered (".\n");
3549 /* Set the default place to put a breakpoint
3550 for the `break' command with no arguments. */
3553 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3556 default_breakpoint_valid
= valid
;
3557 default_breakpoint_address
= addr
;
3558 default_breakpoint_symtab
= symtab
;
3559 default_breakpoint_line
= line
;
3562 /* Return true iff it is meaningful to use the address member of
3563 BPT. For some breakpoint types, the address member is irrelevant
3564 and it makes no sense to attempt to compare it to other addresses
3565 (or use it for any other purpose either).
3567 More specifically, each of the following breakpoint types will always
3568 have a zero valued address and we don't want check_duplicates() to mark
3569 breakpoints of any of these types to be a duplicate of an actual
3570 breakpoint at address zero:
3573 bp_hardware_watchpoint
3575 bp_access_watchpoint
3582 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3584 enum bptype type
= bpt
->type
;
3586 return (type
!= bp_watchpoint
3587 && type
!= bp_hardware_watchpoint
3588 && type
!= bp_read_watchpoint
3589 && type
!= bp_access_watchpoint
3590 && type
!= bp_catch_exec
3591 && type
!= bp_longjmp_resume
3592 && type
!= bp_catch_fork
3593 && type
!= bp_catch_vfork
);
3596 /* Rescan breakpoints at the same address and section as BPT,
3597 marking the first one as "first" and any others as "duplicates".
3598 This is so that the bpt instruction is only inserted once.
3599 If we have a permanent breakpoint at the same place as BPT, make
3600 that one the official one, and the rest as duplicates. */
3603 check_duplicates (struct breakpoint
*bpt
)
3605 register struct breakpoint
*b
;
3606 register int count
= 0;
3607 struct breakpoint
*perm_bp
= 0;
3608 CORE_ADDR address
= bpt
->address
;
3609 asection
*section
= bpt
->section
;
3611 if (! breakpoint_address_is_meaningful (bpt
))
3615 if (b
->enable_state
!= bp_disabled
3616 && b
->enable_state
!= bp_shlib_disabled
3617 && b
->enable_state
!= bp_call_disabled
3618 && b
->address
== address
/* address / overlay match */
3619 && (!overlay_debugging
|| b
->section
== section
)
3620 && breakpoint_address_is_meaningful (b
))
3622 /* Have we found a permanent breakpoint? */
3623 if (b
->enable_state
== bp_permanent
)
3630 b
->duplicate
= count
> 1;
3633 /* If we found a permanent breakpoint at this address, go over the
3634 list again and declare all the other breakpoints there to be the
3638 perm_bp
->duplicate
= 0;
3640 /* Permanent breakpoint should always be inserted. */
3641 if (! perm_bp
->inserted
)
3642 internal_error (__FILE__
, __LINE__
,
3643 "allegedly permanent breakpoint is not "
3644 "actually inserted");
3650 internal_error (__FILE__
, __LINE__
,
3651 "another breakpoint was inserted on top of "
3652 "a permanent breakpoint");
3654 if (b
->enable_state
!= bp_disabled
3655 && b
->enable_state
!= bp_shlib_disabled
3656 && b
->enable_state
!= bp_call_disabled
3657 && b
->address
== address
/* address / overlay match */
3658 && (!overlay_debugging
|| b
->section
== section
)
3659 && breakpoint_address_is_meaningful (b
))
3665 /* set_raw_breakpoint() is a low level routine for allocating and
3666 partially initializing a breakpoint of type BPTYPE. The newly
3667 created breakpoint's address, section, source file name, and line
3668 number are provided by SAL. The newly created and partially
3669 initialized breakpoint is added to the breakpoint chain and
3670 is also returned as the value of this function.
3672 It is expected that the caller will complete the initialization of
3673 the newly created breakpoint struct as well as output any status
3674 information regarding the creation of a new breakpoint. In
3675 particular, set_raw_breakpoint() does NOT set the breakpoint
3676 number! Care should be taken to not allow an error() to occur
3677 prior to completing the initialization of the breakpoint. If this
3678 should happen, a bogus breakpoint will be left on the chain. */
3681 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
3683 register struct breakpoint
*b
, *b1
;
3685 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
3686 memset (b
, 0, sizeof (*b
));
3687 b
->address
= sal
.pc
;
3688 if (sal
.symtab
== NULL
)
3689 b
->source_file
= NULL
;
3691 b
->source_file
= savestring (sal
.symtab
->filename
,
3692 strlen (sal
.symtab
->filename
));
3693 b
->section
= sal
.section
;
3695 b
->language
= current_language
->la_language
;
3696 b
->input_radix
= input_radix
;
3698 b
->line_number
= sal
.line
;
3699 b
->enable_state
= bp_enabled
;
3702 b
->ignore_count
= 0;
3705 b
->dll_pathname
= NULL
;
3706 b
->triggered_dll_pathname
= NULL
;
3707 b
->forked_inferior_pid
= 0;
3708 b
->exec_pathname
= NULL
;
3710 /* Add this breakpoint to the end of the chain
3711 so that a list of breakpoints will come out in order
3712 of increasing numbers. */
3714 b1
= breakpoint_chain
;
3716 breakpoint_chain
= b
;
3724 check_duplicates (b
);
3725 breakpoints_changed ();
3731 /* Note that the breakpoint object B describes a permanent breakpoint
3732 instruction, hard-wired into the inferior's code. */
3734 make_breakpoint_permanent (struct breakpoint
*b
)
3736 b
->enable_state
= bp_permanent
;
3738 /* By definition, permanent breakpoints are already present in the code. */
3742 static struct breakpoint
*
3743 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
3745 static int internal_breakpoint_number
= -1;
3746 struct symtab_and_line sal
;
3747 struct breakpoint
*b
;
3749 INIT_SAL (&sal
); /* initialize to zeroes */
3752 sal
.section
= find_pc_overlay (sal
.pc
);
3754 b
= set_raw_breakpoint (sal
, type
);
3755 b
->number
= internal_breakpoint_number
--;
3756 b
->disposition
= disp_donttouch
;
3761 #ifdef GET_LONGJMP_TARGET
3764 create_longjmp_breakpoint (char *func_name
)
3766 struct breakpoint
*b
;
3767 struct minimal_symbol
*m
;
3769 if (func_name
== NULL
)
3770 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
3773 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
, NULL
)) == NULL
)
3776 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
3779 b
->enable_state
= bp_disabled
;
3782 b
->addr_string
= xstrdup (func_name
);
3785 #endif /* #ifdef GET_LONGJMP_TARGET */
3787 /* Call this routine when stepping and nexting to enable a breakpoint
3788 if we do a longjmp(). When we hit that breakpoint, call
3789 set_longjmp_resume_breakpoint() to figure out where we are going. */
3792 enable_longjmp_breakpoint (void)
3794 register struct breakpoint
*b
;
3797 if (b
->type
== bp_longjmp
)
3799 b
->enable_state
= bp_enabled
;
3800 check_duplicates (b
);
3805 disable_longjmp_breakpoint (void)
3807 register struct breakpoint
*b
;
3810 if (b
->type
== bp_longjmp
3811 || b
->type
== bp_longjmp_resume
)
3813 b
->enable_state
= bp_disabled
;
3814 check_duplicates (b
);
3819 create_overlay_event_breakpoint (char *func_name
)
3821 struct breakpoint
*b
;
3822 struct minimal_symbol
*m
;
3824 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
, NULL
)) == NULL
)
3827 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
3829 b
->addr_string
= xstrdup (func_name
);
3831 if (overlay_debugging
== ovly_auto
)
3832 b
->enable_state
= bp_enabled
;
3834 b
->enable_state
= bp_disabled
;
3838 enable_overlay_breakpoints (void)
3840 register struct breakpoint
*b
;
3843 if (b
->type
== bp_overlay_event
)
3845 b
->enable_state
= bp_enabled
;
3846 check_duplicates (b
);
3851 disable_overlay_breakpoints (void)
3853 register struct breakpoint
*b
;
3856 if (b
->type
== bp_overlay_event
)
3858 b
->enable_state
= bp_disabled
;
3859 check_duplicates (b
);
3864 create_thread_event_breakpoint (CORE_ADDR address
)
3866 struct breakpoint
*b
;
3867 char addr_string
[80]; /* Surely an addr can't be longer than that. */
3869 b
= create_internal_breakpoint (address
, bp_thread_event
);
3871 b
->enable_state
= bp_enabled
;
3872 /* addr_string has to be used or breakpoint_re_set will delete me. */
3873 sprintf (addr_string
, "*0x%s", paddr (b
->address
));
3874 b
->addr_string
= xstrdup (addr_string
);
3880 remove_thread_event_breakpoints (void)
3882 struct breakpoint
*b
, *temp
;
3884 ALL_BREAKPOINTS_SAFE (b
, temp
)
3885 if (b
->type
== bp_thread_event
)
3886 delete_breakpoint (b
);
3891 remove_solib_event_breakpoints (void)
3893 register struct breakpoint
*b
, *temp
;
3895 ALL_BREAKPOINTS_SAFE (b
, temp
)
3896 if (b
->type
== bp_shlib_event
)
3897 delete_breakpoint (b
);
3901 create_solib_event_breakpoint (CORE_ADDR address
)
3903 struct breakpoint
*b
;
3905 b
= create_internal_breakpoint (address
, bp_shlib_event
);
3909 /* Disable any breakpoints that are on code in shared libraries. Only
3910 apply to enabled breakpoints, disabled ones can just stay disabled. */
3913 disable_breakpoints_in_shlibs (int silent
)
3915 struct breakpoint
*b
;
3916 int disabled_shlib_breaks
= 0;
3918 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
3921 #if defined (PC_SOLIB)
3922 if (((b
->type
== bp_breakpoint
) ||
3923 (b
->type
== bp_hardware_breakpoint
)) &&
3924 b
->enable_state
== bp_enabled
&&
3926 PC_SOLIB (b
->address
))
3928 b
->enable_state
= bp_shlib_disabled
;
3931 if (!disabled_shlib_breaks
)
3933 target_terminal_ours_for_output ();
3934 warning ("Temporarily disabling shared library breakpoints:");
3936 disabled_shlib_breaks
= 1;
3937 warning ("breakpoint #%d ", b
->number
);
3944 /* Try to reenable any breakpoints in shared libraries. */
3946 re_enable_breakpoints_in_shlibs (void)
3948 struct breakpoint
*b
;
3951 if (b
->enable_state
== bp_shlib_disabled
)
3955 /* Do not reenable the breakpoint if the shared library
3956 is still not mapped in. */
3957 if (target_read_memory (b
->address
, buf
, 1) == 0)
3958 b
->enable_state
= bp_enabled
;
3965 solib_load_unload_1 (char *hookname
, int tempflag
, char *dll_pathname
,
3966 char *cond_string
, enum bptype bp_kind
)
3968 struct breakpoint
*b
;
3969 struct symtabs_and_lines sals
;
3970 struct cleanup
*old_chain
;
3971 struct cleanup
*canonical_strings_chain
= NULL
;
3972 char *addr_start
= hookname
;
3973 char *addr_end
= NULL
;
3974 char **canonical
= (char **) NULL
;
3975 int thread
= -1; /* All threads. */
3977 /* Set a breakpoint on the specified hook. */
3978 sals
= decode_line_1 (&hookname
, 1, (struct symtab
*) NULL
, 0, &canonical
);
3979 addr_end
= hookname
;
3981 if (sals
.nelts
== 0)
3983 warning ("Unable to set a breakpoint on dynamic linker callback.");
3984 warning ("Suggest linking with /opt/langtools/lib/end.o.");
3985 warning ("GDB will be unable to track shl_load/shl_unload calls");
3988 if (sals
.nelts
!= 1)
3990 warning ("Unable to set unique breakpoint on dynamic linker callback.");
3991 warning ("GDB will be unable to track shl_load/shl_unload calls");
3995 /* Make sure that all storage allocated in decode_line_1 gets freed
3996 in case the following errors out. */
3997 old_chain
= make_cleanup (xfree
, sals
.sals
);
3998 if (canonical
!= (char **) NULL
)
4000 make_cleanup (xfree
, canonical
);
4001 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
4002 if (canonical
[0] != NULL
)
4003 make_cleanup (xfree
, canonical
[0]);
4006 resolve_sal_pc (&sals
.sals
[0]);
4008 /* Remove the canonical strings from the cleanup, they are needed below. */
4009 if (canonical
!= (char **) NULL
)
4010 discard_cleanups (canonical_strings_chain
);
4012 b
= set_raw_breakpoint (sals
.sals
[0], bp_kind
);
4013 set_breakpoint_count (breakpoint_count
+ 1);
4014 b
->number
= breakpoint_count
;
4016 b
->cond_string
= (cond_string
== NULL
) ?
4017 NULL
: savestring (cond_string
, strlen (cond_string
));
4020 if (canonical
!= (char **) NULL
&& canonical
[0] != NULL
)
4021 b
->addr_string
= canonical
[0];
4022 else if (addr_start
)
4023 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
4025 b
->enable_state
= bp_enabled
;
4026 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4028 if (dll_pathname
== NULL
)
4029 b
->dll_pathname
= NULL
;
4032 b
->dll_pathname
= (char *) xmalloc (strlen (dll_pathname
) + 1);
4033 strcpy (b
->dll_pathname
, dll_pathname
);
4037 do_cleanups (old_chain
);
4041 create_solib_load_event_breakpoint (char *hookname
, int tempflag
,
4042 char *dll_pathname
, char *cond_string
)
4044 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4045 cond_string
, bp_catch_load
);
4049 create_solib_unload_event_breakpoint (char *hookname
, int tempflag
,
4050 char *dll_pathname
, char *cond_string
)
4052 solib_load_unload_1 (hookname
,tempflag
, dll_pathname
,
4053 cond_string
, bp_catch_unload
);
4057 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4058 enum bptype bp_kind
)
4060 struct symtab_and_line sal
;
4061 struct breakpoint
*b
;
4062 int thread
= -1; /* All threads. */
4069 b
= set_raw_breakpoint (sal
, bp_kind
);
4070 set_breakpoint_count (breakpoint_count
+ 1);
4071 b
->number
= breakpoint_count
;
4073 b
->cond_string
= (cond_string
== NULL
) ?
4074 NULL
: savestring (cond_string
, strlen (cond_string
));
4076 b
->addr_string
= NULL
;
4077 b
->enable_state
= bp_enabled
;
4078 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4079 b
->forked_inferior_pid
= 0;
4085 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4087 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4091 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4093 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4097 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4099 struct symtab_and_line sal
;
4100 struct breakpoint
*b
;
4101 int thread
= -1; /* All threads. */
4108 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4109 set_breakpoint_count (breakpoint_count
+ 1);
4110 b
->number
= breakpoint_count
;
4112 b
->cond_string
= (cond_string
== NULL
) ?
4113 NULL
: savestring (cond_string
, strlen (cond_string
));
4115 b
->addr_string
= NULL
;
4116 b
->enable_state
= bp_enabled
;
4117 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4123 hw_breakpoint_used_count (void)
4125 register struct breakpoint
*b
;
4130 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4138 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4140 register struct breakpoint
*b
;
4143 *other_type_used
= 0;
4146 if (b
->enable_state
== bp_enabled
)
4148 if (b
->type
== type
)
4150 else if ((b
->type
== bp_hardware_watchpoint
||
4151 b
->type
== bp_read_watchpoint
||
4152 b
->type
== bp_access_watchpoint
)
4153 && b
->enable_state
== bp_enabled
)
4154 *other_type_used
= 1;
4160 /* Call this after hitting the longjmp() breakpoint. Use this to set
4161 a new breakpoint at the target of the jmp_buf.
4163 FIXME - This ought to be done by setting a temporary breakpoint
4164 that gets deleted automatically... */
4167 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_info
*frame
)
4169 register struct breakpoint
*b
;
4172 if (b
->type
== bp_longjmp_resume
)
4175 b
->enable_state
= bp_enabled
;
4177 b
->frame
= frame
->frame
;
4180 check_duplicates (b
);
4186 disable_watchpoints_before_interactive_call_start (void)
4188 struct breakpoint
*b
;
4192 if (((b
->type
== bp_watchpoint
)
4193 || (b
->type
== bp_hardware_watchpoint
)
4194 || (b
->type
== bp_read_watchpoint
)
4195 || (b
->type
== bp_access_watchpoint
)
4196 || ep_is_exception_catchpoint (b
))
4197 && (b
->enable_state
== bp_enabled
))
4199 b
->enable_state
= bp_call_disabled
;
4200 check_duplicates (b
);
4206 enable_watchpoints_after_interactive_call_stop (void)
4208 struct breakpoint
*b
;
4212 if (((b
->type
== bp_watchpoint
)
4213 || (b
->type
== bp_hardware_watchpoint
)
4214 || (b
->type
== bp_read_watchpoint
)
4215 || (b
->type
== bp_access_watchpoint
)
4216 || ep_is_exception_catchpoint (b
))
4217 && (b
->enable_state
== bp_call_disabled
))
4219 b
->enable_state
= bp_enabled
;
4220 check_duplicates (b
);
4226 /* Set a breakpoint that will evaporate an end of command
4227 at address specified by SAL.
4228 Restrict it to frame FRAME if FRAME is nonzero. */
4231 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_info
*frame
,
4234 register struct breakpoint
*b
;
4235 b
= set_raw_breakpoint (sal
, type
);
4236 b
->enable_state
= bp_enabled
;
4237 b
->disposition
= disp_donttouch
;
4238 b
->frame
= (frame
? frame
->frame
: 0);
4240 /* If we're debugging a multi-threaded program, then we
4241 want momentary breakpoints to be active in only a
4242 single thread of control. */
4243 if (in_thread_list (inferior_ptid
))
4244 b
->thread
= pid_to_thread_id (inferior_ptid
);
4250 /* Tell the user we have just set a breakpoint B. */
4253 mention (struct breakpoint
*b
)
4256 struct cleanup
*old_chain
;
4257 struct ui_stream
*stb
;
4259 stb
= ui_out_stream_new (uiout
);
4260 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4262 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4263 watchpoint) other than breakpoint creation. It should be possible to
4264 clean this up and at the same time replace the random calls to
4265 breakpoint_changed with this hook, as has already been done for
4266 delete_breakpoint_hook and so on. */
4267 if (create_breakpoint_hook
)
4268 create_breakpoint_hook (b
);
4269 breakpoint_create_event (b
->number
);
4274 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b
->number
);
4277 ui_out_text (uiout
, "Watchpoint ");
4278 ui_out_tuple_begin (uiout
, "wpt");
4279 ui_out_field_int (uiout
, "number", b
->number
);
4280 ui_out_text (uiout
, ": ");
4281 print_expression (b
->exp
, stb
->stream
);
4282 ui_out_field_stream (uiout
, "exp", stb
);
4283 ui_out_tuple_end (uiout
);
4285 case bp_hardware_watchpoint
:
4286 ui_out_text (uiout
, "Hardware watchpoint ");
4287 ui_out_tuple_begin (uiout
, "wpt");
4288 ui_out_field_int (uiout
, "number", b
->number
);
4289 ui_out_text (uiout
, ": ");
4290 print_expression (b
->exp
, stb
->stream
);
4291 ui_out_field_stream (uiout
, "exp", stb
);
4292 ui_out_tuple_end (uiout
);
4294 case bp_read_watchpoint
:
4295 ui_out_text (uiout
, "Hardware read watchpoint ");
4296 ui_out_tuple_begin (uiout
, "hw-rwpt");
4297 ui_out_field_int (uiout
, "number", b
->number
);
4298 ui_out_text (uiout
, ": ");
4299 print_expression (b
->exp
, stb
->stream
);
4300 ui_out_field_stream (uiout
, "exp", stb
);
4301 ui_out_tuple_end (uiout
);
4303 case bp_access_watchpoint
:
4304 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4305 ui_out_tuple_begin (uiout
, "hw-awpt");
4306 ui_out_field_int (uiout
, "number", b
->number
);
4307 ui_out_text (uiout
, ": ");
4308 print_expression (b
->exp
, stb
->stream
);
4309 ui_out_field_stream (uiout
, "exp", stb
);
4310 ui_out_tuple_end (uiout
);
4313 if (ui_out_is_mi_like_p (uiout
))
4318 printf_filtered ("Breakpoint %d", b
->number
);
4321 case bp_hardware_breakpoint
:
4322 if (ui_out_is_mi_like_p (uiout
))
4327 printf_filtered ("Hardware assisted breakpoint %d", b
->number
);
4331 case bp_catch_unload
:
4332 printf_filtered ("Catchpoint %d (%s %s)",
4334 (b
->type
== bp_catch_load
) ? "load" : "unload",
4335 (b
->dll_pathname
!= NULL
) ?
4336 b
->dll_pathname
: "<any library>");
4339 case bp_catch_vfork
:
4340 printf_filtered ("Catchpoint %d (%s)",
4342 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4345 printf_filtered ("Catchpoint %d (exec)",
4348 case bp_catch_catch
:
4349 case bp_catch_throw
:
4350 printf_filtered ("Catchpoint %d (%s)",
4352 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4358 case bp_longjmp_resume
:
4359 case bp_step_resume
:
4360 case bp_through_sigtramp
:
4362 case bp_watchpoint_scope
:
4363 case bp_shlib_event
:
4364 case bp_thread_event
:
4365 case bp_overlay_event
:
4370 if (addressprint
|| b
->source_file
== NULL
)
4372 printf_filtered (" at ");
4373 print_address_numeric (b
->address
, 1, gdb_stdout
);
4376 printf_filtered (": file %s, line %d.",
4377 b
->source_file
, b
->line_number
);
4379 do_cleanups (old_chain
);
4380 if (ui_out_is_mi_like_p (uiout
))
4382 printf_filtered ("\n");
4386 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4387 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4388 COND[i] and COND_STRING[i] values.
4390 NOTE: If the function succeeds, the caller is expected to cleanup
4391 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4392 array contents). If the function fails (error() is called), the
4393 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4394 COND and SALS arrays and each of those arrays contents. */
4397 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
4398 struct expression
**cond
, char **cond_string
,
4399 enum bptype type
, enum bpdisp disposition
,
4400 int thread
, int ignore_count
, int from_tty
)
4402 if (type
== bp_hardware_breakpoint
)
4404 int i
= hw_breakpoint_used_count ();
4405 int target_resources_ok
=
4406 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4408 if (target_resources_ok
== 0)
4409 error ("No hardware breakpoint support in the target.");
4410 else if (target_resources_ok
< 0)
4411 error ("Hardware breakpoints used exceeds limit.");
4414 /* Now set all the breakpoints. */
4417 for (i
= 0; i
< sals
.nelts
; i
++)
4419 struct breakpoint
*b
;
4420 struct symtab_and_line sal
= sals
.sals
[i
];
4423 describe_other_breakpoints (sal
.pc
, sal
.section
);
4425 b
= set_raw_breakpoint (sal
, type
);
4426 set_breakpoint_count (breakpoint_count
+ 1);
4427 b
->number
= breakpoint_count
;
4430 b
->addr_string
= addr_string
[i
];
4431 b
->cond_string
= cond_string
[i
];
4432 b
->ignore_count
= ignore_count
;
4433 b
->enable_state
= bp_enabled
;
4434 b
->disposition
= disposition
;
4440 /* Parse ARG which is assumed to be a SAL specification possibly
4441 followed by conditionals. On return, SALS contains an array of SAL
4442 addresses found. ADDR_STRING contains a vector of (canonical)
4443 address strings. ARG points to the end of the SAL. */
4446 parse_breakpoint_sals (char **address
,
4447 struct symtabs_and_lines
*sals
,
4448 char ***addr_string
)
4450 char *addr_start
= *address
;
4451 *addr_string
= NULL
;
4452 /* If no arg given, or if first arg is 'if ', use the default
4454 if ((*address
) == NULL
4455 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
4457 if (default_breakpoint_valid
)
4459 struct symtab_and_line sal
;
4460 INIT_SAL (&sal
); /* initialize to zeroes */
4461 sals
->sals
= (struct symtab_and_line
*)
4462 xmalloc (sizeof (struct symtab_and_line
));
4463 sal
.pc
= default_breakpoint_address
;
4464 sal
.line
= default_breakpoint_line
;
4465 sal
.symtab
= default_breakpoint_symtab
;
4466 sal
.section
= find_pc_overlay (sal
.pc
);
4467 sals
->sals
[0] = sal
;
4471 error ("No default breakpoint address now.");
4475 /* Force almost all breakpoints to be in terms of the
4476 current_source_symtab (which is decode_line_1's default). This
4477 should produce the results we want almost all of the time while
4478 leaving default_breakpoint_* alone. */
4479 if (default_breakpoint_valid
4480 && (!current_source_symtab
4481 || (strchr ("+-", (*address
)[0]) != NULL
)))
4482 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
4483 default_breakpoint_line
, addr_string
);
4485 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0, addr_string
);
4487 /* For any SAL that didn't have a canonical string, fill one in. */
4488 if (sals
->nelts
> 0 && *addr_string
== NULL
)
4489 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
4490 if (addr_start
!= (*address
))
4493 for (i
= 0; i
< sals
->nelts
; i
++)
4495 /* Add the string if not present. */
4496 if ((*addr_string
)[i
] == NULL
)
4497 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
4503 /* Convert each SAL into a real PC. Verify that the PC can be
4504 inserted as a breakpoint. If it can't throw an error. */
4507 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
4511 for (i
= 0; i
< sals
->nelts
; i
++)
4513 resolve_sal_pc (&sals
->sals
[i
]);
4515 /* It's possible for the PC to be nonzero, but still an illegal
4516 value on some targets.
4518 For example, on HP-UX if you start gdb, and before running the
4519 inferior you try to set a breakpoint on a shared library function
4520 "foo" where the inferior doesn't call "foo" directly but does
4521 pass its address to another function call, then we do find a
4522 minimal symbol for the "foo", but it's address is invalid.
4523 (Appears to be an index into a table that the loader sets up
4524 when the inferior is run.)
4526 Give the target a chance to bless sals.sals[i].pc before we
4527 try to make a breakpoint for it. */
4528 if (PC_REQUIRES_RUN_BEFORE_USE (sals
->sals
[i
].pc
))
4530 if (address
== NULL
)
4531 error ("Cannot break without a running program.");
4533 error ("Cannot break on %s without a running program.",
4539 /* Set a breakpoint according to ARG (function, linenum or *address)
4540 flag: first bit : 0 non-temporary, 1 temporary.
4541 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4544 break_command_1 (char *arg
, int flag
, int from_tty
)
4546 int tempflag
, hardwareflag
;
4547 struct symtabs_and_lines sals
;
4548 register struct expression
**cond
= 0;
4549 /* Pointers in arg to the start, and one past the end, of the
4551 char **cond_string
= (char **) NULL
;
4552 char *addr_start
= arg
;
4554 struct cleanup
*old_chain
;
4555 struct cleanup
*breakpoint_chain
= NULL
;
4558 int ignore_count
= 0;
4560 hardwareflag
= flag
& BP_HARDWAREFLAG
;
4561 tempflag
= flag
& BP_TEMPFLAG
;
4566 parse_breakpoint_sals (&arg
, &sals
, &addr_string
);
4571 /* Create a chain of things that always need to be cleaned up. */
4572 old_chain
= make_cleanup (null_cleanup
, 0);
4574 /* Make sure that all storage allocated to SALS gets freed. */
4575 make_cleanup (xfree
, sals
.sals
);
4577 /* Cleanup the addr_string array but not its contents. */
4578 make_cleanup (xfree
, addr_string
);
4580 /* Allocate space for all the cond expressions. */
4581 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4582 make_cleanup (xfree
, cond
);
4584 /* Allocate space for all the cond strings. */
4585 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4586 make_cleanup (xfree
, cond_string
);
4588 /* ----------------------------- SNIP -----------------------------
4589 Anything added to the cleanup chain beyond this point is assumed
4590 to be part of a breakpoint. If the breakpoint create succeeds
4591 then the memory is not reclaimed. */
4592 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4594 /* Mark the contents of the addr_string for cleanup. These go on
4595 the breakpoint_chain and only occure if the breakpoint create
4597 for (i
= 0; i
< sals
.nelts
; i
++)
4599 if (addr_string
[i
] != NULL
)
4600 make_cleanup (xfree
, addr_string
[i
]);
4603 /* Resolve all line numbers to PC's and verify that the addresses
4604 are ok for the target. */
4605 breakpoint_sals_to_pc (&sals
, addr_start
);
4607 /* Verify that condition can be parsed, before setting any
4608 breakpoints. Allocate a separate condition expression for each
4610 thread
= -1; /* No specific thread yet */
4611 for (i
= 0; i
< sals
.nelts
; i
++)
4618 char *cond_start
= NULL
;
4619 char *cond_end
= NULL
;
4620 while (*tok
== ' ' || *tok
== '\t')
4625 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
4628 toklen
= end_tok
- tok
;
4630 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
4632 tok
= cond_start
= end_tok
+ 1;
4633 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4634 make_cleanup (xfree
, cond
[i
]);
4636 cond_string
[i
] = savestring (cond_start
, cond_end
- cond_start
);
4637 make_cleanup (xfree
, cond_string
[i
]);
4639 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
4645 thread
= strtol (tok
, &tok
, 0);
4647 error ("Junk after thread keyword.");
4648 if (!valid_thread_id (thread
))
4649 error ("Unknown thread %d\n", thread
);
4652 error ("Junk at end of arguments.");
4656 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4657 hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4658 tempflag
? disp_del
: disp_donttouch
,
4659 thread
, ignore_count
, from_tty
);
4663 warning ("Multiple breakpoints were set.");
4664 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4666 /* That's it. Discard the cleanups for data inserted into the
4668 discard_cleanups (breakpoint_chain
);
4669 /* But cleanup everything else. */
4670 do_cleanups (old_chain
);
4673 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4674 linenum or *address) with COND and IGNORE_COUNT. */
4676 struct captured_breakpoint_args
4687 do_captured_breakpoint (void *data
)
4689 struct captured_breakpoint_args
*args
= data
;
4690 struct symtabs_and_lines sals
;
4691 register struct expression
**cond
;
4692 struct cleanup
*old_chain
;
4693 struct cleanup
*breakpoint_chain
= NULL
;
4700 /* Parse the source and lines spec. Delay check that the expression
4701 didn't contain trailing garbage until after cleanups are in
4705 address_end
= args
->address
;
4707 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
);
4712 /* Create a chain of things at always need to be cleaned up. */
4713 old_chain
= make_cleanup (null_cleanup
, 0);
4715 /* Always have a addr_string array, even if it is empty. */
4716 make_cleanup (xfree
, addr_string
);
4718 /* Make sure that all storage allocated to SALS gets freed. */
4719 make_cleanup (xfree
, sals
.sals
);
4721 /* Allocate space for all the cond expressions. */
4722 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4723 make_cleanup (xfree
, cond
);
4725 /* Allocate space for all the cond strings. */
4726 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4727 make_cleanup (xfree
, cond_string
);
4729 /* ----------------------------- SNIP -----------------------------
4730 Anything added to the cleanup chain beyond this point is assumed
4731 to be part of a breakpoint. If the breakpoint create goes
4732 through then that memory is not cleaned up. */
4733 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4735 /* Mark the contents of the addr_string for cleanup. These go on
4736 the breakpoint_chain and only occure if the breakpoint create
4738 for (i
= 0; i
< sals
.nelts
; i
++)
4740 if (addr_string
[i
] != NULL
)
4741 make_cleanup (xfree
, addr_string
[i
]);
4744 /* Wait until now before checking for garbage at the end of the
4745 address. That way cleanups can take care of freeing any
4747 if (*address_end
!= '\0')
4748 error ("Garbage %s following breakpoint address", address_end
);
4750 /* Resolve all line numbers to PC's. */
4751 breakpoint_sals_to_pc (&sals
, args
->address
);
4753 /* Verify that conditions can be parsed, before setting any
4755 for (i
= 0; i
< sals
.nelts
; i
++)
4757 if (args
->condition
!= NULL
)
4759 char *tok
= args
->condition
;
4760 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4762 error ("Garbage %s follows condition", tok
);
4763 make_cleanup (xfree
, cond
[i
]);
4764 cond_string
[i
] = xstrdup (args
->condition
);
4768 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4769 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4770 args
->tempflag
? disp_del
: disp_donttouch
,
4771 args
->thread
, args
->ignore_count
, 0/*from-tty*/);
4773 /* That's it. Discard the cleanups for data inserted into the
4775 discard_cleanups (breakpoint_chain
);
4776 /* But cleanup everything else. */
4777 do_cleanups (old_chain
);
4782 gdb_breakpoint (char *address
, char *condition
,
4783 int hardwareflag
, int tempflag
,
4784 int thread
, int ignore_count
)
4786 struct captured_breakpoint_args args
;
4787 args
.address
= address
;
4788 args
.condition
= condition
;
4789 args
.hardwareflag
= hardwareflag
;
4790 args
.tempflag
= tempflag
;
4791 args
.thread
= thread
;
4792 args
.ignore_count
= ignore_count
;
4793 return catch_errors (do_captured_breakpoint
, &args
,
4794 NULL
, RETURN_MASK_ALL
);
4799 break_at_finish_at_depth_command_1 (char *arg
, int flag
, int from_tty
)
4801 struct frame_info
*frame
;
4802 CORE_ADDR low
, high
, selected_pc
= 0;
4803 char *extra_args
= NULL
;
4806 int extra_args_len
= 0, if_arg
= 0;
4809 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
4812 if (default_breakpoint_valid
)
4816 selected_pc
= selected_frame
->pc
;
4821 error ("No selected frame.");
4824 error ("No default breakpoint address now.");
4828 extra_args
= strchr (arg
, ' ');
4832 extra_args_len
= strlen (extra_args
);
4833 level_arg
= (char *) xmalloc (extra_args
- arg
);
4834 strncpy (level_arg
, arg
, extra_args
- arg
- 1);
4835 level_arg
[extra_args
- arg
- 1] = '\0';
4839 level_arg
= (char *) xmalloc (strlen (arg
) + 1);
4840 strcpy (level_arg
, arg
);
4843 frame
= parse_frame_specification (level_arg
);
4845 selected_pc
= frame
->pc
;
4852 extra_args_len
= strlen (arg
);
4857 if (find_pc_partial_function (selected_pc
, (char **) NULL
, &low
, &high
))
4859 addr_string
= (char *) xmalloc (26 + extra_args_len
);
4861 sprintf (addr_string
, "*0x%s %s", paddr_nz (high
), extra_args
);
4863 sprintf (addr_string
, "*0x%s", paddr_nz (high
));
4864 break_command_1 (addr_string
, flag
, from_tty
);
4865 xfree (addr_string
);
4868 error ("No function contains the specified address");
4871 error ("Unable to set breakpoint at procedure exit");
4876 break_at_finish_command_1 (char *arg
, int flag
, int from_tty
)
4878 char *addr_string
, *break_string
, *beg_addr_string
;
4879 CORE_ADDR low
, high
;
4880 struct symtabs_and_lines sals
;
4881 struct symtab_and_line sal
;
4882 struct cleanup
*old_chain
;
4883 char *extra_args
= NULL
;
4884 int extra_args_len
= 0;
4888 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
4890 if (default_breakpoint_valid
)
4894 addr_string
= (char *) xmalloc (15);
4895 sprintf (addr_string
, "*0x%s", paddr_nz (selected_frame
->pc
));
4900 error ("No selected frame.");
4903 error ("No default breakpoint address now.");
4907 addr_string
= (char *) xmalloc (strlen (arg
) + 1);
4908 strcpy (addr_string
, arg
);
4914 extra_args_len
= strlen (arg
);
4918 /* get the stuff after the function name or address */
4919 extra_args
= strchr (arg
, ' ');
4923 extra_args_len
= strlen (extra_args
);
4930 beg_addr_string
= addr_string
;
4931 sals
= decode_line_1 (&addr_string
, 1, (struct symtab
*) NULL
, 0,
4934 xfree (beg_addr_string
);
4935 old_chain
= make_cleanup (xfree
, sals
.sals
);
4936 for (i
= 0; (i
< sals
.nelts
); i
++)
4939 if (find_pc_partial_function (sal
.pc
, (char **) NULL
, &low
, &high
))
4941 break_string
= (char *) xmalloc (extra_args_len
+ 26);
4943 sprintf (break_string
, "*0x%s %s", paddr_nz (high
), extra_args
);
4945 sprintf (break_string
, "*0x%s", paddr_nz (high
));
4946 break_command_1 (break_string
, flag
, from_tty
);
4947 xfree (break_string
);
4950 error ("No function contains the specified address");
4954 warning ("Multiple breakpoints were set.\n");
4955 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4957 do_cleanups (old_chain
);
4961 /* Helper function for break_command_1 and disassemble_command. */
4964 resolve_sal_pc (struct symtab_and_line
*sal
)
4968 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
4970 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
4971 error ("No line %d in file \"%s\".",
4972 sal
->line
, sal
->symtab
->filename
);
4976 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
4978 struct blockvector
*bv
;
4983 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
4986 b
= BLOCKVECTOR_BLOCK (bv
, index
);
4987 sym
= block_function (b
);
4990 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
4991 sal
->section
= SYMBOL_BFD_SECTION (sym
);
4995 /* It really is worthwhile to have the section, so we'll just
4996 have to look harder. This case can be executed if we have
4997 line numbers but no functions (as can happen in assembly
5000 struct minimal_symbol
*msym
;
5002 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5004 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5011 break_command (char *arg
, int from_tty
)
5013 break_command_1 (arg
, 0, from_tty
);
5017 break_at_finish_command (char *arg
, int from_tty
)
5019 break_at_finish_command_1 (arg
, 0, from_tty
);
5023 break_at_finish_at_depth_command (char *arg
, int from_tty
)
5025 break_at_finish_at_depth_command_1 (arg
, 0, from_tty
);
5029 tbreak_command (char *arg
, int from_tty
)
5031 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5035 tbreak_at_finish_command (char *arg
, int from_tty
)
5037 break_at_finish_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5041 hbreak_command (char *arg
, int from_tty
)
5043 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5047 thbreak_command (char *arg
, int from_tty
)
5049 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5053 stop_command (char *arg
, int from_tty
)
5055 printf_filtered ("Specify the type of breakpoint to set.\n\
5056 Usage: stop in <function | address>\n\
5061 stopin_command (char *arg
, int from_tty
)
5065 if (arg
== (char *) NULL
)
5067 else if (*arg
!= '*')
5072 /* look for a ':'. If this is a line number specification, then
5073 say it is bad, otherwise, it should be an address or
5074 function/method name */
5075 while (*argptr
&& !hasColon
)
5077 hasColon
= (*argptr
== ':');
5082 badInput
= (*argptr
!= ':'); /* Not a class::method */
5084 badInput
= isdigit (*arg
); /* a simple line number */
5088 printf_filtered ("Usage: stop in <function | address>\n");
5090 break_command_1 (arg
, 0, from_tty
);
5094 stopat_command (char *arg
, int from_tty
)
5098 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5105 /* look for a ':'. If there is a '::' then get out, otherwise
5106 it is probably a line number. */
5107 while (*argptr
&& !hasColon
)
5109 hasColon
= (*argptr
== ':');
5114 badInput
= (*argptr
== ':'); /* we have class::method */
5116 badInput
= !isdigit (*arg
); /* not a line number */
5120 printf_filtered ("Usage: stop at <line>\n");
5122 break_command_1 (arg
, 0, from_tty
);
5126 /* accessflag: hw_write: watch write,
5127 hw_read: watch read,
5128 hw_access: watch access (read or write) */
5130 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5132 struct breakpoint
*b
;
5133 struct symtab_and_line sal
;
5134 struct expression
*exp
;
5135 struct block
*exp_valid_block
;
5136 struct value
*val
, *mark
;
5137 struct frame_info
*frame
;
5138 struct frame_info
*prev_frame
= NULL
;
5139 char *exp_start
= NULL
;
5140 char *exp_end
= NULL
;
5141 char *tok
, *end_tok
;
5143 char *cond_start
= NULL
;
5144 char *cond_end
= NULL
;
5145 struct expression
*cond
= NULL
;
5146 int i
, other_type_used
, target_resources_ok
= 0;
5147 enum bptype bp_type
;
5150 INIT_SAL (&sal
); /* initialize to zeroes */
5152 /* Parse arguments. */
5153 innermost_block
= NULL
;
5155 exp
= parse_exp_1 (&arg
, 0, 0);
5157 exp_valid_block
= innermost_block
;
5158 mark
= value_mark ();
5159 val
= evaluate_expression (exp
);
5160 release_value (val
);
5161 if (VALUE_LAZY (val
))
5162 value_fetch_lazy (val
);
5165 while (*tok
== ' ' || *tok
== '\t')
5169 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5172 toklen
= end_tok
- tok
;
5173 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5175 tok
= cond_start
= end_tok
+ 1;
5176 cond
= parse_exp_1 (&tok
, 0, 0);
5180 error ("Junk at end of command.");
5182 if (accessflag
== hw_read
)
5183 bp_type
= bp_read_watchpoint
;
5184 else if (accessflag
== hw_access
)
5185 bp_type
= bp_access_watchpoint
;
5187 bp_type
= bp_hardware_watchpoint
;
5189 mem_cnt
= can_use_hardware_watchpoint (val
);
5190 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5191 error ("Expression cannot be implemented with read/access watchpoint.");
5194 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5195 target_resources_ok
=
5196 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5198 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5199 error ("Target does not support this type of hardware watchpoint.");
5201 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5202 error ("Target can only support one kind of HW watchpoint at a time.");
5205 #if defined(HPUXHPPA)
5206 /* On HP-UX if you set a h/w
5207 watchpoint before the "run" command, the inferior dies with a e.g.,
5208 SIGILL once you start it. I initially believed this was due to a
5209 bad interaction between page protection traps and the initial
5210 startup sequence by the dynamic linker.
5212 However, I tried avoiding that by having HP-UX's implementation of
5213 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5214 yet, which forced slow watches before a "run" or "attach", and it
5215 still fails somewhere in the startup code.
5217 Until I figure out what's happening, I'm disallowing watches altogether
5218 before the "run" or "attach" command. We'll tell the user they must
5219 set watches after getting the program started. */
5220 if (!target_has_execution
)
5222 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5225 #endif /* HPUXHPPA */
5227 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5228 watchpoint could not be set. */
5229 if (!mem_cnt
|| target_resources_ok
<= 0)
5230 bp_type
= bp_watchpoint
;
5232 /* Now set up the breakpoint. */
5233 b
= set_raw_breakpoint (sal
, bp_type
);
5234 set_breakpoint_count (breakpoint_count
+ 1);
5235 b
->number
= breakpoint_count
;
5236 b
->disposition
= disp_donttouch
;
5238 b
->exp_valid_block
= exp_valid_block
;
5239 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5243 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5247 frame
= block_innermost_frame (exp_valid_block
);
5250 prev_frame
= get_prev_frame (frame
);
5251 b
->watchpoint_frame
= frame
->frame
;
5254 b
->watchpoint_frame
= (CORE_ADDR
) 0;
5256 /* If the expression is "local", then set up a "watchpoint scope"
5257 breakpoint at the point where we've left the scope of the watchpoint
5259 if (innermost_block
)
5263 struct breakpoint
*scope_breakpoint
;
5264 struct symtab_and_line scope_sal
;
5266 INIT_SAL (&scope_sal
); /* initialize to zeroes */
5267 scope_sal
.pc
= get_frame_pc (prev_frame
);
5268 scope_sal
.section
= find_pc_overlay (scope_sal
.pc
);
5270 scope_breakpoint
= set_raw_breakpoint (scope_sal
,
5271 bp_watchpoint_scope
);
5272 set_breakpoint_count (breakpoint_count
+ 1);
5273 scope_breakpoint
->number
= breakpoint_count
;
5275 scope_breakpoint
->enable_state
= bp_enabled
;
5277 /* Automatically delete the breakpoint when it hits. */
5278 scope_breakpoint
->disposition
= disp_del
;
5280 /* Only break in the proper frame (help with recursion). */
5281 scope_breakpoint
->frame
= prev_frame
->frame
;
5283 /* Set the address at which we will stop. */
5284 scope_breakpoint
->address
= get_frame_pc (prev_frame
);
5286 /* The scope breakpoint is related to the watchpoint. We
5287 will need to act on them together. */
5288 b
->related_breakpoint
= scope_breakpoint
;
5291 value_free_to_mark (mark
);
5295 /* Return count of locations need to be watched and can be handled
5296 in hardware. If the watchpoint can not be handled
5297 in hardware return zero. */
5299 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5300 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5301 ((BYTE_SIZE) <= (REGISTER_SIZE))
5304 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5305 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5306 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5310 can_use_hardware_watchpoint (struct value
*v
)
5312 int found_memory_cnt
= 0;
5313 struct value
*head
= v
;
5315 /* Did the user specifically forbid us to use hardware watchpoints? */
5316 if (!can_use_hw_watchpoints
)
5319 /* Make sure that the value of the expression depends only upon
5320 memory contents, and values computed from them within GDB. If we
5321 find any register references or function calls, we can't use a
5322 hardware watchpoint.
5324 The idea here is that evaluating an expression generates a series
5325 of values, one holding the value of every subexpression. (The
5326 expression a*b+c has five subexpressions: a, b, a*b, c, and
5327 a*b+c.) GDB's values hold almost enough information to establish
5328 the criteria given above --- they identify memory lvalues,
5329 register lvalues, computed values, etcetera. So we can evaluate
5330 the expression, and then scan the chain of values that leaves
5331 behind to decide whether we can detect any possible change to the
5332 expression's final value using only hardware watchpoints.
5334 However, I don't think that the values returned by inferior
5335 function calls are special in any way. So this function may not
5336 notice that an expression involving an inferior function call
5337 can't be watched with hardware watchpoints. FIXME. */
5338 for (; v
; v
= v
->next
)
5340 if (VALUE_LVAL (v
) == lval_memory
)
5343 /* A lazy memory lvalue is one that GDB never needed to fetch;
5344 we either just used its address (e.g., `a' in `a.b') or
5345 we never needed it at all (e.g., `a' in `a,b'). */
5349 /* Ahh, memory we actually used! Check if we can cover
5350 it with hardware watchpoints. */
5351 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
5353 /* We only watch structs and arrays if user asked for it
5354 explicitly, never if they just happen to appear in a
5355 middle of some value chain. */
5357 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5358 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5360 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
5361 int len
= TYPE_LENGTH (VALUE_TYPE (v
));
5363 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5370 else if (v
->lval
!= not_lval
&& v
->modifiable
== 0)
5371 return 0; /* ??? What does this represent? */
5372 else if (v
->lval
== lval_register
)
5373 return 0; /* cannot watch a register with a HW watchpoint */
5376 /* The expression itself looks suitable for using a hardware
5377 watchpoint, but give the target machine a chance to reject it. */
5378 return found_memory_cnt
;
5382 watch_command_wrapper (char *arg
, int from_tty
)
5384 watch_command (arg
, from_tty
);
5388 watch_command (char *arg
, int from_tty
)
5390 watch_command_1 (arg
, hw_write
, from_tty
);
5394 rwatch_command_wrapper (char *arg
, int from_tty
)
5396 rwatch_command (arg
, from_tty
);
5400 rwatch_command (char *arg
, int from_tty
)
5402 watch_command_1 (arg
, hw_read
, from_tty
);
5406 awatch_command_wrapper (char *arg
, int from_tty
)
5408 awatch_command (arg
, from_tty
);
5412 awatch_command (char *arg
, int from_tty
)
5414 watch_command_1 (arg
, hw_access
, from_tty
);
5418 /* Helper routines for the until_command routine in infcmd.c. Here
5419 because it uses the mechanisms of breakpoints. */
5421 /* This function is called by fetch_inferior_event via the
5422 cmd_continuation pointer, to complete the until command. It takes
5423 care of cleaning up the temporary breakpoints set up by the until
5426 until_break_command_continuation (struct continuation_arg
*arg
)
5428 struct cleanup
*cleanups
;
5430 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
5431 do_exec_cleanups (cleanups
);
5436 until_break_command (char *arg
, int from_tty
)
5438 struct symtabs_and_lines sals
;
5439 struct symtab_and_line sal
;
5440 struct frame_info
*prev_frame
= get_prev_frame (selected_frame
);
5441 struct breakpoint
*breakpoint
;
5442 struct cleanup
*old_chain
;
5443 struct continuation_arg
*arg1
;
5446 clear_proceed_status ();
5448 /* Set a breakpoint where the user wants it and at return from
5451 if (default_breakpoint_valid
)
5452 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
5453 default_breakpoint_line
, (char ***) NULL
);
5455 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
5456 0, (char ***) NULL
);
5458 if (sals
.nelts
!= 1)
5459 error ("Couldn't get information on specified line.");
5462 xfree (sals
.sals
); /* malloc'd, so freed */
5465 error ("Junk at end of arguments.");
5467 resolve_sal_pc (&sal
);
5469 breakpoint
= set_momentary_breakpoint (sal
, selected_frame
, bp_until
);
5471 if (!event_loop_p
|| !target_can_async_p ())
5472 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
5474 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
5476 /* If we are running asynchronously, and the target supports async
5477 execution, we are not waiting for the target to stop, in the call
5478 tp proceed, below. This means that we cannot delete the
5479 brekpoints until the target has actually stopped. The only place
5480 where we get a chance to do that is in fetch_inferior_event, so
5481 we must set things up for that. */
5483 if (event_loop_p
&& target_can_async_p ())
5485 /* In this case the arg for the continuation is just the point
5486 in the exec_cleanups chain from where to start doing
5487 cleanups, because all the continuation does is the cleanups in
5488 the exec_cleanup_chain. */
5490 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
5492 arg1
->data
.pointer
= old_chain
;
5494 add_continuation (until_break_command_continuation
, arg1
);
5497 /* Keep within the current frame */
5501 sal
= find_pc_line (prev_frame
->pc
, 0);
5502 sal
.pc
= prev_frame
->pc
;
5503 breakpoint
= set_momentary_breakpoint (sal
, prev_frame
, bp_until
);
5504 if (!event_loop_p
|| !target_can_async_p ())
5505 make_cleanup_delete_breakpoint (breakpoint
);
5507 make_exec_cleanup_delete_breakpoint (breakpoint
);
5510 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
5511 /* Do the cleanups now, anly if we are not running asynchronously,
5512 of if we are, but the target is still synchronous. */
5513 if (!event_loop_p
|| !target_can_async_p ())
5514 do_cleanups (old_chain
);
5518 /* These aren't used; I don't konw what they were for. */
5519 /* Set a breakpoint at the catch clause for NAME. */
5521 catch_breakpoint (char *name
)
5526 disable_catch_breakpoint (void)
5531 delete_catch_breakpoint (void)
5536 enable_catch_breakpoint (void)
5543 struct sal_chain
*next
;
5544 struct symtab_and_line sal
;
5548 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5549 had been commented out in the v.4.16 sources, and stays
5550 disabled there now because "catch NAME" syntax isn't allowed.
5552 /* This isn't used; I don't know what it was for. */
5553 /* For each catch clause identified in ARGS, run FUNCTION
5554 with that clause as an argument. */
5555 static struct symtabs_and_lines
5556 map_catch_names (char *args
, int (*function
) ())
5558 register char *p
= args
;
5560 struct symtabs_and_lines sals
;
5562 struct sal_chain
*sal_chain
= 0;
5566 error_no_arg ("one or more catch names");
5574 /* Don't swallow conditional part. */
5575 if (p1
[0] == 'i' && p1
[1] == 'f'
5576 && (p1
[2] == ' ' || p1
[2] == '\t'))
5582 while (isalnum (*p1
) || *p1
== '_' || *p1
== '$')
5586 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
5587 error ("Arguments must be catch names.");
5593 struct sal_chain
*next
= (struct sal_chain
*)
5594 alloca (sizeof (struct sal_chain
));
5595 next
->next
= sal_chain
;
5596 next
->sal
= get_catch_sal (p
);
5601 printf_unfiltered ("No catch clause for exception %s.\n", p
);
5606 while (*p
== ' ' || *p
== '\t')
5612 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5614 static struct symtabs_and_lines
5615 get_catch_sals (int this_level_only
)
5617 register struct blockvector
*bl
;
5618 register struct block
*block
;
5619 int index
, have_default
= 0;
5621 struct symtabs_and_lines sals
;
5622 struct sal_chain
*sal_chain
= 0;
5623 char *blocks_searched
;
5625 /* Not sure whether an error message is always the correct response,
5626 but it's better than a core dump. */
5627 if (selected_frame
== NULL
)
5628 error ("No selected frame.");
5629 block
= get_frame_block (selected_frame
);
5630 pc
= selected_frame
->pc
;
5636 error ("No symbol table info available.\n");
5638 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
5639 blocks_searched
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
5640 memset (blocks_searched
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
5644 CORE_ADDR end
= BLOCK_END (block
) - 4;
5647 if (bl
!= blockvector_for_pc (end
, &index
))
5648 error ("blockvector blotch");
5649 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
5650 error ("blockvector botch");
5651 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
5654 /* Don't print out blocks that have gone by. */
5655 while (index
< last_index
5656 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
5659 while (index
< last_index
5660 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
5662 if (blocks_searched
[index
] == 0)
5664 struct block
*b
= BLOCKVECTOR_BLOCK (bl
, index
);
5666 register struct symbol
*sym
;
5668 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
5670 if (STREQ (SYMBOL_NAME (sym
), "default"))
5676 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
5678 struct sal_chain
*next
= (struct sal_chain
*)
5679 alloca (sizeof (struct sal_chain
));
5680 next
->next
= sal_chain
;
5681 next
->sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
),
5686 blocks_searched
[index
] = 1;
5692 if (sal_chain
&& this_level_only
)
5695 /* After handling the function's top-level block, stop.
5696 Don't continue to its superblock, the block of
5697 per-file symbols. */
5698 if (BLOCK_FUNCTION (block
))
5700 block
= BLOCK_SUPERBLOCK (block
);
5705 struct sal_chain
*tmp_chain
;
5707 /* Count the number of entries. */
5708 for (index
= 0, tmp_chain
= sal_chain
; tmp_chain
;
5709 tmp_chain
= tmp_chain
->next
)
5713 sals
.sals
= (struct symtab_and_line
*)
5714 xmalloc (index
* sizeof (struct symtab_and_line
));
5715 for (index
= 0; sal_chain
; sal_chain
= sal_chain
->next
, index
++)
5716 sals
.sals
[index
] = sal_chain
->sal
;
5723 ep_skip_leading_whitespace (char **s
)
5725 if ((s
== NULL
) || (*s
== NULL
))
5727 while (isspace (**s
))
5731 /* This function examines a string, and attempts to find a token
5732 that might be an event name in the leading characters. If a
5733 possible match is found, a pointer to the last character of
5734 the token is returned. Else, NULL is returned. */
5737 ep_find_event_name_end (char *arg
)
5740 char *event_name_end
= NULL
;
5742 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5746 /* We break out of the loop when we find a token delimiter.
5747 Basically, we're looking for alphanumerics and underscores;
5748 anything else delimites the token. */
5751 if (!isalnum (*s
) && (*s
!= '_'))
5757 return event_name_end
;
5761 /* This function attempts to parse an optional "if <cond>" clause
5762 from the arg string. If one is not found, it returns NULL.
5764 Else, it returns a pointer to the condition string. (It does not
5765 attempt to evaluate the string against a particular block.) And,
5766 it updates arg to point to the first character following the parsed
5767 if clause in the arg string. */
5770 ep_parse_optional_if_clause (char **arg
)
5774 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
5777 /* Skip the "if" keyword. */
5780 /* Skip any extra leading whitespace, and record the start of the
5781 condition string. */
5782 ep_skip_leading_whitespace (arg
);
5785 /* Assume that the condition occupies the remainder of the arg string. */
5786 (*arg
) += strlen (cond_string
);
5791 /* This function attempts to parse an optional filename from the arg
5792 string. If one is not found, it returns NULL.
5794 Else, it returns a pointer to the parsed filename. (This function
5795 makes no attempt to verify that a file of that name exists, or is
5796 accessible.) And, it updates arg to point to the first character
5797 following the parsed filename in the arg string.
5799 Note that clients needing to preserve the returned filename for
5800 future access should copy it to their own buffers. */
5802 ep_parse_optional_filename (char **arg
)
5804 static char filename
[1024];
5809 if ((*arg_p
== '\0') || isspace (*arg_p
))
5827 /* Commands to deal with catching events, such as signals, exceptions,
5828 process start/exit, etc. */
5832 catch_fork
, catch_vfork
5836 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5837 static void catch_fork_command_1 (catch_fork_kind fork_kind
,
5838 char *arg
, int tempflag
, int from_tty
);
5841 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
5844 char *cond_string
= NULL
;
5846 ep_skip_leading_whitespace (&arg
);
5848 /* The allowed syntax is:
5850 catch [v]fork if <cond>
5852 First, check if there's an if clause. */
5853 cond_string
= ep_parse_optional_if_clause (&arg
);
5855 if ((*arg
!= '\0') && !isspace (*arg
))
5856 error ("Junk at end of arguments.");
5858 /* If this target supports it, create a fork or vfork catchpoint
5859 and enable reporting of such events. */
5863 create_fork_event_catchpoint (tempflag
, cond_string
);
5866 create_vfork_event_catchpoint (tempflag
, cond_string
);
5869 error ("unsupported or unknown fork kind; cannot catch it");
5875 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5877 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
5879 char *cond_string
= NULL
;
5881 ep_skip_leading_whitespace (&arg
);
5883 /* The allowed syntax is:
5885 catch exec if <cond>
5887 First, check if there's an if clause. */
5888 cond_string
= ep_parse_optional_if_clause (&arg
);
5890 if ((*arg
!= '\0') && !isspace (*arg
))
5891 error ("Junk at end of arguments.");
5893 /* If this target supports it, create an exec catchpoint
5894 and enable reporting of such events. */
5895 create_exec_event_catchpoint (tempflag
, cond_string
);
5899 #if defined(SOLIB_ADD)
5901 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
5903 char *dll_pathname
= NULL
;
5904 char *cond_string
= NULL
;
5906 ep_skip_leading_whitespace (&arg
);
5908 /* The allowed syntax is:
5910 catch load if <cond>
5911 catch load <filename>
5912 catch load <filename> if <cond>
5914 The user is not allowed to specify the <filename> after an
5917 We'll ignore the pathological case of a file named "if".
5919 First, check if there's an if clause. If so, then there
5920 cannot be a filename. */
5921 cond_string
= ep_parse_optional_if_clause (&arg
);
5923 /* If there was an if clause, then there cannot be a filename.
5924 Else, there might be a filename and an if clause. */
5925 if (cond_string
== NULL
)
5927 dll_pathname
= ep_parse_optional_filename (&arg
);
5928 ep_skip_leading_whitespace (&arg
);
5929 cond_string
= ep_parse_optional_if_clause (&arg
);
5932 if ((*arg
!= '\0') && !isspace (*arg
))
5933 error ("Junk at end of arguments.");
5935 /* Create a load breakpoint that only triggers when a load of
5936 the specified dll (or any dll, if no pathname was specified)
5938 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
5939 dll_pathname
, cond_string
);
5943 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
5945 char *dll_pathname
= NULL
;
5946 char *cond_string
= NULL
;
5948 ep_skip_leading_whitespace (&arg
);
5950 /* The allowed syntax is:
5952 catch unload if <cond>
5953 catch unload <filename>
5954 catch unload <filename> if <cond>
5956 The user is not allowed to specify the <filename> after an
5959 We'll ignore the pathological case of a file named "if".
5961 First, check if there's an if clause. If so, then there
5962 cannot be a filename. */
5963 cond_string
= ep_parse_optional_if_clause (&arg
);
5965 /* If there was an if clause, then there cannot be a filename.
5966 Else, there might be a filename and an if clause. */
5967 if (cond_string
== NULL
)
5969 dll_pathname
= ep_parse_optional_filename (&arg
);
5970 ep_skip_leading_whitespace (&arg
);
5971 cond_string
= ep_parse_optional_if_clause (&arg
);
5974 if ((*arg
!= '\0') && !isspace (*arg
))
5975 error ("Junk at end of arguments.");
5977 /* Create an unload breakpoint that only triggers when an unload of
5978 the specified dll (or any dll, if no pathname was specified)
5980 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
5981 dll_pathname
, cond_string
);
5983 #endif /* SOLIB_ADD */
5985 /* Commands to deal with catching exceptions. */
5987 /* Set a breakpoint at the specified callback routine for an
5988 exception event callback */
5991 create_exception_catchpoint (int tempflag
, char *cond_string
,
5992 enum exception_event_kind ex_event
,
5993 struct symtab_and_line
*sal
)
5995 struct breakpoint
*b
;
5996 int thread
= -1; /* All threads. */
5999 if (!sal
) /* no exception support? */
6004 case EX_EVENT_THROW
:
6005 bptype
= bp_catch_throw
;
6007 case EX_EVENT_CATCH
:
6008 bptype
= bp_catch_catch
;
6010 default: /* error condition */
6011 error ("Internal error -- invalid catchpoint kind");
6014 b
= set_raw_breakpoint (*sal
, bptype
);
6015 set_breakpoint_count (breakpoint_count
+ 1);
6016 b
->number
= breakpoint_count
;
6018 b
->cond_string
= (cond_string
== NULL
) ?
6019 NULL
: savestring (cond_string
, strlen (cond_string
));
6021 b
->addr_string
= NULL
;
6022 b
->enable_state
= bp_enabled
;
6023 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6027 /* Deal with "catch catch" and "catch throw" commands */
6030 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6031 int tempflag
, int from_tty
)
6033 char *cond_string
= NULL
;
6034 struct symtab_and_line
*sal
= NULL
;
6036 ep_skip_leading_whitespace (&arg
);
6038 cond_string
= ep_parse_optional_if_clause (&arg
);
6040 if ((*arg
!= '\0') && !isspace (*arg
))
6041 error ("Junk at end of arguments.");
6043 if ((ex_event
!= EX_EVENT_THROW
) &&
6044 (ex_event
!= EX_EVENT_CATCH
))
6045 error ("Unsupported or unknown exception event; cannot catch it");
6047 /* See if we can find a callback routine */
6048 sal
= target_enable_exception_callback (ex_event
, 1);
6052 /* We have callbacks from the runtime system for exceptions.
6053 Set a breakpoint on the sal found, if no errors */
6054 if (sal
!= (struct symtab_and_line
*) -1)
6055 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6057 return; /* something went wrong with setting up callbacks */
6061 /* No callbacks from runtime system for exceptions.
6062 Try GNU C++ exception breakpoints using labels in debug info. */
6063 if (ex_event
== EX_EVENT_CATCH
)
6065 handle_gnu_4_16_catch_command (arg
, tempflag
, from_tty
);
6067 else if (ex_event
== EX_EVENT_THROW
)
6069 /* Set a breakpoint on __raise_exception () */
6071 warning ("Unsupported with this platform/compiler combination.");
6072 warning ("Perhaps you can achieve the effect you want by setting");
6073 warning ("a breakpoint on __raise_exception().");
6078 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6079 inside a catch_errors */
6082 cover_target_enable_exception_callback (PTR arg
)
6084 args_for_catchpoint_enable
*args
= arg
;
6085 struct symtab_and_line
*sal
;
6086 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6089 else if (sal
== (struct symtab_and_line
*) -1)
6092 return 1; /*is valid */
6097 /* This is the original v.4.16 and earlier version of the
6098 catch_command_1() function. Now that other flavours of "catch"
6099 have been introduced, and since exception handling can be handled
6100 in other ways (through target ops) also, this is used only for the
6101 GNU C++ exception handling system.
6102 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6103 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6104 there was no code in GDB 4.16 for "catch throw".
6106 Called from catch_exception_command_1 () */
6110 handle_gnu_4_16_catch_command (char *arg
, int tempflag
, int from_tty
)
6112 /* First, translate ARG into something we can deal with in terms
6115 struct symtabs_and_lines sals
;
6116 struct symtab_and_line sal
;
6117 register struct expression
*cond
= 0;
6118 register struct breakpoint
*b
;
6122 INIT_SAL (&sal
); /* initialize to zeroes */
6124 /* If no arg given, or if first arg is 'if ', all active catch clauses
6125 are breakpointed. */
6127 if (!arg
|| (arg
[0] == 'i' && arg
[1] == 'f'
6128 && (arg
[2] == ' ' || arg
[2] == '\t')))
6130 /* Grab all active catch clauses. */
6131 sals
= get_catch_sals (0);
6135 /* Grab selected catch clauses. */
6136 error ("catch NAME not implemented");
6139 /* Not sure why this code has been disabled. I'm leaving
6140 it disabled. We can never come here now anyway
6141 since we don't allow the "catch NAME" syntax.
6144 /* This isn't used; I don't know what it was for. */
6145 sals
= map_catch_names (arg
, catch_breakpoint
);
6153 for (i
= 0; i
< sals
.nelts
; i
++)
6155 resolve_sal_pc (&sals
.sals
[i
]);
6159 if (arg
[0] == 'i' && arg
[1] == 'f'
6160 && (arg
[2] == ' ' || arg
[2] == '\t'))
6161 cond
= parse_exp_1 ((arg
+= 2, &arg
),
6162 block_for_pc (sals
.sals
[i
].pc
), 0);
6164 error ("Junk at end of arguments.");
6169 for (i
= 0; i
< sals
.nelts
; i
++)
6174 describe_other_breakpoints (sal
.pc
, sal
.section
);
6176 /* Important -- this is an ordinary breakpoint. For platforms
6177 with callback support for exceptions,
6178 create_exception_catchpoint() will create special bp types
6179 (bp_catch_catch and bp_catch_throw), and there is code in
6180 insert_breakpoints() and elsewhere that depends on that. */
6181 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6182 set_breakpoint_count (breakpoint_count
+ 1);
6183 b
->number
= breakpoint_count
;
6186 b
->enable_state
= bp_enabled
;
6187 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6194 warning ("Multiple breakpoints were set.");
6195 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
6201 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6204 /* The first argument may be an event name, such as "start" or "load".
6205 If so, then handle it as such. If it doesn't match an event name,
6206 then attempt to interpret it as an exception name. (This latter is
6207 the v4.16-and-earlier GDB meaning of the "catch" command.)
6209 First, try to find the bounds of what might be an event name. */
6210 char *arg1_start
= arg
;
6214 if (arg1_start
== NULL
)
6216 /* Old behaviour was to use pre-v-4.16 syntax */
6217 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6219 /* Now, this is not allowed */
6220 error ("Catch requires an event name.");
6223 arg1_end
= ep_find_event_name_end (arg1_start
);
6224 if (arg1_end
== NULL
)
6225 error ("catch requires an event");
6226 arg1_length
= arg1_end
+ 1 - arg1_start
;
6228 /* Try to match what we found against known event names. */
6229 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6231 error ("Catch of signal not yet implemented");
6233 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6235 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6236 tempflag
, from_tty
);
6238 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6240 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6241 tempflag
, from_tty
);
6243 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6245 error ("Catch of thread_start not yet implemented");
6247 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6249 error ("Catch of thread_exit not yet implemented");
6251 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6253 error ("Catch of thread_join not yet implemented");
6255 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6257 error ("Catch of start not yet implemented");
6259 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6261 error ("Catch of exit not yet implemented");
6263 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6265 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6266 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6268 error ("Catch of fork not yet implemented");
6271 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6273 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6274 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6276 error ("Catch of vfork not yet implemented");
6279 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6281 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6282 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6284 error ("Catch of exec not yet implemented");
6287 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6289 #if defined(SOLIB_ADD)
6290 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6292 error ("Catch of load not implemented");
6295 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6297 #if defined(SOLIB_ADD)
6298 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6300 error ("Catch of load not implemented");
6303 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6305 error ("Catch of stop not yet implemented");
6308 /* This doesn't appear to be an event name */
6312 /* Pre-v.4.16 behaviour was to treat the argument
6313 as the name of an exception */
6314 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6315 /* Now this is not allowed */
6316 error ("Unknown event kind specified for catch");
6321 /* Used by the gui, could be made a worker for other things. */
6324 set_breakpoint_sal (struct symtab_and_line sal
)
6326 struct breakpoint
*b
;
6327 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6328 set_breakpoint_count (breakpoint_count
+ 1);
6329 b
->number
= breakpoint_count
;
6336 /* These aren't used; I don't know what they were for. */
6337 /* Disable breakpoints on all catch clauses described in ARGS. */
6339 disable_catch (char *args
)
6341 /* Map the disable command to catch clauses described in ARGS. */
6344 /* Enable breakpoints on all catch clauses described in ARGS. */
6346 enable_catch (char *args
)
6348 /* Map the disable command to catch clauses described in ARGS. */
6351 /* Delete breakpoints on all catch clauses in the active scope. */
6353 delete_catch (char *args
)
6355 /* Map the delete command to catch clauses described in ARGS. */
6360 catch_command (char *arg
, int from_tty
)
6362 catch_command_1 (arg
, 0, from_tty
);
6367 tcatch_command (char *arg
, int from_tty
)
6369 catch_command_1 (arg
, 1, from_tty
);
6374 clear_command (char *arg
, int from_tty
)
6376 register struct breakpoint
*b
, *b1
;
6378 struct symtabs_and_lines sals
;
6379 struct symtab_and_line sal
;
6380 register struct breakpoint
*found
;
6385 sals
= decode_line_spec (arg
, 1);
6390 sals
.sals
= (struct symtab_and_line
*)
6391 xmalloc (sizeof (struct symtab_and_line
));
6392 INIT_SAL (&sal
); /* initialize to zeroes */
6393 sal
.line
= default_breakpoint_line
;
6394 sal
.symtab
= default_breakpoint_symtab
;
6395 sal
.pc
= default_breakpoint_address
;
6396 if (sal
.symtab
== 0)
6397 error ("No source file specified.");
6405 /* For each line spec given, delete bps which correspond
6406 to it. We do this in two loops: the first loop looks at
6407 the initial bp(s) in the chain which should be deleted,
6408 the second goes down the rest of the chain looking ahead
6409 one so it can take those bps off the chain without messing
6413 for (i
= 0; i
< sals
.nelts
; i
++)
6415 /* If exact pc given, clear bpts at that pc.
6416 If line given (pc == 0), clear all bpts on specified line.
6417 If defaulting, clear all bpts on default line
6420 defaulting sal.pc != 0 tests to do
6425 1 0 <can't happen> */
6428 found
= (struct breakpoint
*) 0;
6431 while (breakpoint_chain
6432 /* Why don't we check here that this is not
6433 a watchpoint, etc., as we do below?
6434 I can't make it fail, but don't know
6435 what's stopping the failure: a watchpoint
6436 of the same address as "sal.pc" should
6437 wind up being deleted. */
6439 && (((sal
.pc
&& (breakpoint_chain
->address
== sal
.pc
))
6440 && (!overlay_debugging
6441 || breakpoint_chain
->section
== sal
.section
))
6442 || ((default_match
|| (0 == sal
.pc
))
6443 && breakpoint_chain
->source_file
!= NULL
6444 && sal
.symtab
!= NULL
6445 && STREQ (breakpoint_chain
->source_file
, sal
.symtab
->filename
)
6446 && breakpoint_chain
->line_number
== sal
.line
)))
6449 b1
= breakpoint_chain
;
6450 breakpoint_chain
= b1
->next
;
6457 && b
->next
->type
!= bp_none
6458 && b
->next
->type
!= bp_watchpoint
6459 && b
->next
->type
!= bp_hardware_watchpoint
6460 && b
->next
->type
!= bp_read_watchpoint
6461 && b
->next
->type
!= bp_access_watchpoint
6462 && (((sal
.pc
&& (b
->next
->address
== sal
.pc
))
6463 && (!overlay_debugging
|| b
->next
->section
== sal
.section
))
6464 || ((default_match
|| (0 == sal
.pc
))
6465 && b
->next
->source_file
!= NULL
6466 && sal
.symtab
!= NULL
6467 && STREQ (b
->next
->source_file
, sal
.symtab
->filename
)
6468 && b
->next
->line_number
== sal
.line
)))
6481 error ("No breakpoint at %s.", arg
);
6483 error ("No breakpoint at this line.");
6487 from_tty
= 1; /* Always report if deleted more than one */
6489 printf_unfiltered ("Deleted breakpoint%s ", found
->next
? "s" : "");
6490 breakpoints_changed ();
6494 printf_unfiltered ("%d ", found
->number
);
6496 delete_breakpoint (found
);
6500 putchar_unfiltered ('\n');
6505 /* Delete breakpoint in BS if they are `delete' breakpoints and
6506 all breakpoints that are marked for deletion, whether hit or not.
6507 This is called after any breakpoint is hit, or after errors. */
6510 breakpoint_auto_delete (bpstat bs
)
6512 struct breakpoint
*b
, *temp
;
6514 for (; bs
; bs
= bs
->next
)
6515 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== disp_del
6517 delete_breakpoint (bs
->breakpoint_at
);
6519 ALL_BREAKPOINTS_SAFE (b
, temp
)
6521 if (b
->disposition
== disp_del_at_next_stop
)
6522 delete_breakpoint (b
);
6526 /* Delete a breakpoint and clean up all traces of it in the data
6530 delete_breakpoint (struct breakpoint
*bpt
)
6532 register struct breakpoint
*b
;
6536 error ("Internal error (attempted to delete a NULL breakpoint)");
6539 /* Has this bp already been deleted? This can happen because multiple
6540 lists can hold pointers to bp's. bpstat lists are especial culprits.
6542 One example of this happening is a watchpoint's scope bp. When the
6543 scope bp triggers, we notice that the watchpoint is out of scope, and
6544 delete it. We also delete its scope bp. But the scope bp is marked
6545 "auto-deleting", and is already on a bpstat. That bpstat is then
6546 checked for auto-deleting bp's, which are deleted.
6548 A real solution to this problem might involve reference counts in bp's,
6549 and/or giving them pointers back to their referencing bpstat's, and
6550 teaching delete_breakpoint to only free a bp's storage when no more
6551 references were extent. A cheaper bandaid was chosen. */
6552 if (bpt
->type
== bp_none
)
6555 if (delete_breakpoint_hook
)
6556 delete_breakpoint_hook (bpt
);
6557 breakpoint_delete_event (bpt
->number
);
6560 remove_breakpoint (bpt
, mark_inserted
);
6562 if (breakpoint_chain
== bpt
)
6563 breakpoint_chain
= bpt
->next
;
6565 /* If we have callback-style exception catchpoints, don't go through
6566 the adjustments to the C++ runtime library etc. if the inferior
6567 isn't actually running. target_enable_exception_callback for a
6568 null target ops vector gives an undesirable error message, so we
6569 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6570 exceptions are supported in this way, it's OK for now. FIXME */
6571 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
6573 static char message1
[] = "Error in deleting catchpoint %d:\n";
6574 static char message
[sizeof (message1
) + 30];
6575 args_for_catchpoint_enable args
;
6577 /* Format possible error msg */
6578 sprintf (message
, message1
, bpt
->number
);
6579 args
.kind
= bpt
->type
== bp_catch_catch
?
6580 EX_EVENT_CATCH
: EX_EVENT_THROW
;
6582 catch_errors (cover_target_enable_exception_callback
, &args
,
6583 message
, RETURN_MASK_ALL
);
6590 b
->next
= bpt
->next
;
6594 check_duplicates (bpt
);
6595 /* If this breakpoint was inserted, and there is another breakpoint
6596 at the same address, we need to insert the other breakpoint. */
6598 && bpt
->type
!= bp_hardware_watchpoint
6599 && bpt
->type
!= bp_read_watchpoint
6600 && bpt
->type
!= bp_access_watchpoint
6601 && bpt
->type
!= bp_catch_fork
6602 && bpt
->type
!= bp_catch_vfork
6603 && bpt
->type
!= bp_catch_exec
)
6606 if (b
->address
== bpt
->address
6607 && b
->section
== bpt
->section
6609 && b
->enable_state
!= bp_disabled
6610 && b
->enable_state
!= bp_shlib_disabled
6611 && b
->enable_state
!= bp_call_disabled
)
6615 /* We should never reach this point if there is a permanent
6616 breakpoint at the same address as the one being deleted.
6617 If there is a permanent breakpoint somewhere, it should
6618 always be the only one inserted. */
6619 if (b
->enable_state
== bp_permanent
)
6620 internal_error (__FILE__
, __LINE__
,
6621 "another breakpoint was inserted on top of "
6622 "a permanent breakpoint");
6624 if (b
->type
== bp_hardware_breakpoint
)
6625 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
6627 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
6631 target_terminal_ours_for_output ();
6632 warning ("Cannot insert breakpoint %d:", b
->number
);
6633 memory_error (val
, b
->address
); /* which bombs us out */
6640 free_command_lines (&bpt
->commands
);
6643 if (bpt
->cond_string
!= NULL
)
6644 xfree (bpt
->cond_string
);
6645 if (bpt
->addr_string
!= NULL
)
6646 xfree (bpt
->addr_string
);
6647 if (bpt
->exp
!= NULL
)
6649 if (bpt
->exp_string
!= NULL
)
6650 xfree (bpt
->exp_string
);
6651 if (bpt
->val
!= NULL
)
6652 value_free (bpt
->val
);
6653 if (bpt
->source_file
!= NULL
)
6654 xfree (bpt
->source_file
);
6655 if (bpt
->dll_pathname
!= NULL
)
6656 xfree (bpt
->dll_pathname
);
6657 if (bpt
->triggered_dll_pathname
!= NULL
)
6658 xfree (bpt
->triggered_dll_pathname
);
6659 if (bpt
->exec_pathname
!= NULL
)
6660 xfree (bpt
->exec_pathname
);
6662 /* Be sure no bpstat's are pointing at it after it's been freed. */
6663 /* FIXME, how can we find all bpstat's?
6664 We just check stop_bpstat for now. */
6665 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
6666 if (bs
->breakpoint_at
== bpt
)
6668 bs
->breakpoint_at
= NULL
;
6670 /* we'd call bpstat_clear_actions, but that free's stuff and due
6671 to the multiple pointers pointing to one item with no
6672 reference counts found anywhere through out the bpstat's (how
6673 do you spell fragile?), we don't want to free things twice --
6674 better a memory leak than a corrupt malloc pool! */
6675 bs
->commands
= NULL
;
6678 /* On the chance that someone will soon try again to delete this same
6679 bp, we mark it as deleted before freeing its storage. */
6680 bpt
->type
= bp_none
;
6686 do_delete_breakpoint_cleanup (void *b
)
6688 delete_breakpoint (b
);
6692 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
6694 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
6698 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
6700 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
6704 delete_command (char *arg
, int from_tty
)
6706 struct breakpoint
*b
, *temp
;
6710 int breaks_to_delete
= 0;
6712 /* Delete all breakpoints if no argument.
6713 Do not delete internal or call-dummy breakpoints, these
6714 have to be deleted with an explicit breakpoint number argument. */
6717 if (b
->type
!= bp_call_dummy
&&
6718 b
->type
!= bp_shlib_event
&&
6719 b
->type
!= bp_thread_event
&&
6720 b
->type
!= bp_overlay_event
&&
6722 breaks_to_delete
= 1;
6725 /* Ask user only if there are some breakpoints to delete. */
6727 || (breaks_to_delete
&& query ("Delete all breakpoints? ")))
6729 ALL_BREAKPOINTS_SAFE (b
, temp
)
6731 if (b
->type
!= bp_call_dummy
&&
6732 b
->type
!= bp_shlib_event
&&
6733 b
->type
!= bp_thread_event
&&
6734 b
->type
!= bp_overlay_event
&&
6736 delete_breakpoint (b
);
6741 map_breakpoint_numbers (arg
, delete_breakpoint
);
6744 /* Reset a breakpoint given it's struct breakpoint * BINT.
6745 The value we return ends up being the return value from catch_errors.
6746 Unused in this case. */
6749 breakpoint_re_set_one (PTR bint
)
6751 /* get past catch_errs */
6752 struct breakpoint
*b
= (struct breakpoint
*) bint
;
6755 struct symtabs_and_lines sals
;
6757 enum enable_state save_enable
;
6762 warning ("attempted to reset apparently deleted breakpoint #%d?",
6766 case bp_hardware_breakpoint
:
6768 case bp_catch_unload
:
6769 if (b
->addr_string
== NULL
)
6771 /* Anything without a string can't be re-set. */
6772 delete_breakpoint (b
);
6775 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6777 ``And a hack it is, although Apple's Darwin version of GDB
6778 contains an almost identical hack to implement a "future
6779 break" command. It seems to work in many real world cases,
6780 but it is easy to come up with a test case where the patch
6781 doesn't help at all.''
6783 ``It seems that the way GDB implements breakpoints - in -
6784 shared - libraries was designed for a.out shared library
6785 systems (SunOS 4) where shared libraries were loaded at a
6786 fixed address in memory. Since ELF shared libraries can (and
6787 will) be loaded at any address in memory, things break.
6788 Fixing this is not trivial. Therefore, I'm not sure whether
6789 we should add this hack to the branch only. I cannot
6790 guarantee that things will be fixed on the trunk in the near
6793 In case we have a problem, disable this breakpoint. We'll
6794 restore its status if we succeed. Don't disable a
6795 shlib_disabled breakpoint though. There's a fair chance we
6796 can't re-set it if the shared library it's in hasn't been
6798 save_enable
= b
->enable_state
;
6799 if (b
->enable_state
!= bp_shlib_disabled
)
6800 b
->enable_state
= bp_disabled
;
6802 set_language (b
->language
);
6803 input_radix
= b
->input_radix
;
6805 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
);
6806 for (i
= 0; i
< sals
.nelts
; i
++)
6808 resolve_sal_pc (&sals
.sals
[i
]);
6810 /* Reparse conditions, they might contain references to the
6812 if (b
->cond_string
!= NULL
)
6817 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
6820 /* We need to re-set the breakpoint if the address changes... */
6821 if (b
->address
!= sals
.sals
[i
].pc
6822 /* ...or new and old breakpoints both have source files, and
6823 the source file name or the line number changes... */
6824 || (b
->source_file
!= NULL
6825 && sals
.sals
[i
].symtab
!= NULL
6826 && (!STREQ (b
->source_file
, sals
.sals
[i
].symtab
->filename
)
6827 || b
->line_number
!= sals
.sals
[i
].line
)
6829 /* ...or we switch between having a source file and not having
6831 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
6834 if (b
->source_file
!= NULL
)
6835 xfree (b
->source_file
);
6836 if (sals
.sals
[i
].symtab
== NULL
)
6837 b
->source_file
= NULL
;
6840 savestring (sals
.sals
[i
].symtab
->filename
,
6841 strlen (sals
.sals
[i
].symtab
->filename
));
6842 b
->line_number
= sals
.sals
[i
].line
;
6843 b
->address
= sals
.sals
[i
].pc
;
6845 /* Used to check for duplicates here, but that can
6846 cause trouble, as it doesn't check for disabled
6851 /* Might be better to do this just once per breakpoint_re_set,
6852 rather than once for every breakpoint. */
6853 breakpoints_changed ();
6855 b
->section
= sals
.sals
[i
].section
;
6856 b
->enable_state
= save_enable
; /* Restore it, this worked. */
6859 /* Now that this is re-enabled, check_duplicates
6861 check_duplicates (b
);
6868 case bp_hardware_watchpoint
:
6869 case bp_read_watchpoint
:
6870 case bp_access_watchpoint
:
6871 innermost_block
= NULL
;
6872 /* The issue arises of what context to evaluate this in. The
6873 same one as when it was set, but what does that mean when
6874 symbols have been re-read? We could save the filename and
6875 functionname, but if the context is more local than that, the
6876 best we could do would be something like how many levels deep
6877 and which index at that particular level, but that's going to
6878 be less stable than filenames or function names. */
6880 /* So for now, just use a global context. */
6883 b
->exp
= parse_expression (b
->exp_string
);
6884 b
->exp_valid_block
= innermost_block
;
6885 mark
= value_mark ();
6887 value_free (b
->val
);
6888 b
->val
= evaluate_expression (b
->exp
);
6889 release_value (b
->val
);
6890 if (VALUE_LAZY (b
->val
))
6891 value_fetch_lazy (b
->val
);
6893 if (b
->cond_string
!= NULL
)
6898 b
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
6900 if (b
->enable_state
== bp_enabled
)
6902 value_free_to_mark (mark
);
6904 case bp_catch_catch
:
6905 case bp_catch_throw
:
6907 /* We needn't really do anything to reset these, since the mask
6908 that requests them is unaffected by e.g., new libraries being
6911 case bp_catch_vfork
:
6916 printf_filtered ("Deleting unknown breakpoint type %d\n", b
->type
);
6918 /* Delete longjmp and overlay event breakpoints; they will be
6919 reset later by breakpoint_re_set. */
6921 case bp_longjmp_resume
:
6922 case bp_overlay_event
:
6923 delete_breakpoint (b
);
6926 /* This breakpoint is special, it's set up when the inferior
6927 starts and we really don't want to touch it. */
6928 case bp_shlib_event
:
6930 /* Like bp_shlib_event, this breakpoint type is special.
6931 Once it is set up, we do not want to touch it. */
6932 case bp_thread_event
:
6934 /* Keep temporary breakpoints, which can be encountered when we step
6935 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6936 Otherwise these should have been blown away via the cleanup chain
6937 or by breakpoint_init_inferior when we rerun the executable. */
6940 case bp_watchpoint_scope
:
6942 case bp_step_resume
:
6949 /* Re-set all breakpoints after symbols have been re-loaded. */
6951 breakpoint_re_set (void)
6953 struct breakpoint
*b
, *temp
;
6954 enum language save_language
;
6955 int save_input_radix
;
6956 static char message1
[] = "Error in re-setting breakpoint %d:\n";
6957 char message
[sizeof (message1
) + 30 /* slop */ ];
6959 save_language
= current_language
->la_language
;
6960 save_input_radix
= input_radix
;
6961 ALL_BREAKPOINTS_SAFE (b
, temp
)
6963 /* Format possible error msg */
6964 sprintf (message
, message1
, b
->number
);
6965 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
6967 set_language (save_language
);
6968 input_radix
= save_input_radix
;
6970 #ifdef GET_LONGJMP_TARGET
6971 create_longjmp_breakpoint ("longjmp");
6972 create_longjmp_breakpoint ("_longjmp");
6973 create_longjmp_breakpoint ("siglongjmp");
6974 create_longjmp_breakpoint ("_siglongjmp");
6975 create_longjmp_breakpoint (NULL
);
6978 create_overlay_event_breakpoint ("_ovly_debug_event");
6981 /* Reset the thread number of this breakpoint:
6983 - If the breakpoint is for all threads, leave it as-is.
6984 - Else, reset it to the current thread for inferior_ptid. */
6986 breakpoint_re_set_thread (struct breakpoint
*b
)
6988 if (b
->thread
!= -1)
6990 if (in_thread_list (inferior_ptid
))
6991 b
->thread
= pid_to_thread_id (inferior_ptid
);
6995 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
6996 If from_tty is nonzero, it prints a message to that effect,
6997 which ends with a period (no newline). */
7000 set_ignore_count (int bptnum
, int count
, int from_tty
)
7002 register struct breakpoint
*b
;
7008 if (b
->number
== bptnum
)
7010 b
->ignore_count
= count
;
7013 else if (count
== 0)
7014 printf_filtered ("Will stop next time breakpoint %d is reached.",
7016 else if (count
== 1)
7017 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7020 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7022 breakpoints_changed ();
7026 error ("No breakpoint number %d.", bptnum
);
7029 /* Clear the ignore counts of all breakpoints. */
7031 breakpoint_clear_ignore_counts (void)
7033 struct breakpoint
*b
;
7036 b
->ignore_count
= 0;
7039 /* Command to set ignore-count of breakpoint N to COUNT. */
7042 ignore_command (char *args
, int from_tty
)
7048 error_no_arg ("a breakpoint number");
7050 num
= get_number (&p
);
7052 error ("bad breakpoint number: '%s'", args
);
7054 error ("Second argument (specified ignore-count) is missing.");
7056 set_ignore_count (num
,
7057 longest_to_int (value_as_long (parse_and_eval (p
))),
7059 printf_filtered ("\n");
7060 breakpoints_changed ();
7063 /* Call FUNCTION on each of the breakpoints
7064 whose numbers are given in ARGS. */
7067 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7069 register char *p
= args
;
7072 register struct breakpoint
*b
, *tmp
;
7076 error_no_arg ("one or more breakpoint numbers");
7083 num
= get_number_or_range (&p1
);
7086 warning ("bad breakpoint number at or near '%s'", p
);
7090 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7091 if (b
->number
== num
)
7093 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7096 if (related_breakpoint
)
7097 function (related_breakpoint
);
7101 printf_unfiltered ("No breakpoint number %d.\n", num
);
7107 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7108 If from_tty is nonzero, it prints a message to that effect,
7109 which ends with a period (no newline). */
7112 disable_breakpoint (struct breakpoint
*bpt
)
7114 /* Never disable a watchpoint scope breakpoint; we want to
7115 hit them when we leave scope so we can delete both the
7116 watchpoint and its scope breakpoint at that time. */
7117 if (bpt
->type
== bp_watchpoint_scope
)
7120 /* You can't disable permanent breakpoints. */
7121 if (bpt
->enable_state
== bp_permanent
)
7124 bpt
->enable_state
= bp_disabled
;
7126 check_duplicates (bpt
);
7128 if (modify_breakpoint_hook
)
7129 modify_breakpoint_hook (bpt
);
7130 breakpoint_modify_event (bpt
->number
);
7135 disable_command (char *args
, int from_tty
)
7137 register struct breakpoint
*bpt
;
7139 ALL_BREAKPOINTS (bpt
)
7143 warning ("attempted to disable apparently deleted breakpoint #%d?",
7148 case bp_catch_unload
:
7150 case bp_catch_vfork
:
7152 case bp_catch_catch
:
7153 case bp_catch_throw
:
7154 case bp_hardware_breakpoint
:
7156 case bp_hardware_watchpoint
:
7157 case bp_read_watchpoint
:
7158 case bp_access_watchpoint
:
7159 disable_breakpoint (bpt
);
7164 map_breakpoint_numbers (args
, disable_breakpoint
);
7168 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7170 struct frame_info
*save_selected_frame
= NULL
;
7171 int save_selected_frame_level
= -1;
7172 int target_resources_ok
, other_type_used
;
7175 if (bpt
->type
== bp_hardware_breakpoint
)
7178 i
= hw_breakpoint_used_count ();
7179 target_resources_ok
=
7180 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7182 if (target_resources_ok
== 0)
7183 error ("No hardware breakpoint support in the target.");
7184 else if (target_resources_ok
< 0)
7185 error ("Hardware breakpoints used exceeds limit.");
7188 if (bpt
->enable_state
!= bp_permanent
)
7189 bpt
->enable_state
= bp_enabled
;
7190 bpt
->disposition
= disposition
;
7191 check_duplicates (bpt
);
7192 breakpoints_changed ();
7194 if (bpt
->type
== bp_watchpoint
||
7195 bpt
->type
== bp_hardware_watchpoint
||
7196 bpt
->type
== bp_read_watchpoint
||
7197 bpt
->type
== bp_access_watchpoint
)
7199 if (bpt
->exp_valid_block
!= NULL
)
7201 struct frame_info
*fr
=
7203 /* Ensure that we have the current frame. Else, this
7204 next query may pessimistically be answered as, "No,
7205 not within current scope". */
7206 get_current_frame ();
7207 fr
= find_frame_addr_in_frame_chain (bpt
->watchpoint_frame
);
7211 Cannot enable watchpoint %d because the block in which its expression\n\
7212 is valid is not currently in scope.\n", bpt
->number
);
7213 bpt
->enable_state
= bp_disabled
;
7217 save_selected_frame
= selected_frame
;
7218 save_selected_frame_level
= selected_frame_level
;
7219 select_frame (fr
, -1);
7222 value_free (bpt
->val
);
7223 mark
= value_mark ();
7224 bpt
->val
= evaluate_expression (bpt
->exp
);
7225 release_value (bpt
->val
);
7226 if (VALUE_LAZY (bpt
->val
))
7227 value_fetch_lazy (bpt
->val
);
7229 if (bpt
->type
== bp_hardware_watchpoint
||
7230 bpt
->type
== bp_read_watchpoint
||
7231 bpt
->type
== bp_access_watchpoint
)
7233 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7234 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7236 /* Hack around 'unused var' error for some targets here */
7238 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7239 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7240 /* we can consider of type is bp_hardware_watchpoint, convert to
7241 bp_watchpoint in the following condition */
7242 if (target_resources_ok
< 0)
7245 Cannot enable watchpoint %d because target watch resources\n\
7246 have been allocated for other watchpoints.\n", bpt
->number
);
7247 bpt
->enable_state
= bp_disabled
;
7248 value_free_to_mark (mark
);
7253 if (save_selected_frame_level
>= 0)
7254 select_frame (save_selected_frame
, save_selected_frame_level
);
7255 value_free_to_mark (mark
);
7257 if (modify_breakpoint_hook
)
7258 modify_breakpoint_hook (bpt
);
7259 breakpoint_modify_event (bpt
->number
);
7263 enable_breakpoint (struct breakpoint
*bpt
)
7265 do_enable_breakpoint (bpt
, bpt
->disposition
);
7268 /* The enable command enables the specified breakpoints (or all defined
7269 breakpoints) so they once again become (or continue to be) effective
7270 in stopping the inferior. */
7274 enable_command (char *args
, int from_tty
)
7276 register struct breakpoint
*bpt
;
7278 ALL_BREAKPOINTS (bpt
)
7282 warning ("attempted to enable apparently deleted breakpoint #%d?",
7287 case bp_catch_unload
:
7289 case bp_catch_vfork
:
7291 case bp_catch_catch
:
7292 case bp_catch_throw
:
7293 case bp_hardware_breakpoint
:
7295 case bp_hardware_watchpoint
:
7296 case bp_read_watchpoint
:
7297 case bp_access_watchpoint
:
7298 enable_breakpoint (bpt
);
7303 map_breakpoint_numbers (args
, enable_breakpoint
);
7307 enable_once_breakpoint (struct breakpoint
*bpt
)
7309 do_enable_breakpoint (bpt
, disp_disable
);
7314 enable_once_command (char *args
, int from_tty
)
7316 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7320 enable_delete_breakpoint (struct breakpoint
*bpt
)
7322 do_enable_breakpoint (bpt
, disp_del
);
7327 enable_delete_command (char *args
, int from_tty
)
7329 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7332 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7334 struct symtabs_and_lines
7335 decode_line_spec_1 (char *string
, int funfirstline
)
7337 struct symtabs_and_lines sals
;
7339 error ("Empty line specification.");
7340 if (default_breakpoint_valid
)
7341 sals
= decode_line_1 (&string
, funfirstline
,
7342 default_breakpoint_symtab
,
7343 default_breakpoint_line
,
7346 sals
= decode_line_1 (&string
, funfirstline
,
7347 (struct symtab
*) NULL
, 0, (char ***) NULL
);
7349 error ("Junk at end of line specification: %s", string
);
7354 _initialize_breakpoint (void)
7356 struct cmd_list_element
*c
;
7358 breakpoint_chain
= 0;
7359 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7360 before a breakpoint is set. */
7361 breakpoint_count
= 0;
7363 add_com ("ignore", class_breakpoint
, ignore_command
,
7364 "Set ignore-count of breakpoint number N to COUNT.\n\
7365 Usage is `ignore N COUNT'.");
7367 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7369 add_com ("commands", class_breakpoint
, commands_command
,
7370 "Set commands to be executed when a breakpoint is hit.\n\
7371 Give breakpoint number as argument after \"commands\".\n\
7372 With no argument, the targeted breakpoint is the last one set.\n\
7373 The commands themselves follow starting on the next line.\n\
7374 Type a line containing \"end\" to indicate the end of them.\n\
7375 Give \"silent\" as the first line to make the breakpoint silent;\n\
7376 then no output is printed when it is hit, except what the commands print.");
7378 add_com ("condition", class_breakpoint
, condition_command
,
7379 "Specify breakpoint number N to break only if COND is true.\n\
7380 Usage is `condition N COND', where N is an integer and COND is an\n\
7381 expression to be evaluated whenever breakpoint N is reached. ");
7383 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
,
7384 "Set a temporary breakpoint. Args like \"break\" command.\n\
7385 Like \"break\" except the breakpoint is only temporary,\n\
7386 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7387 by using \"enable delete\" on the breakpoint number.");
7388 c
->completer
= location_completer
;
7390 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
,
7391 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7392 Like \"break\" except the breakpoint requires hardware support,\n\
7393 some target hardware may not have this support.");
7394 c
->completer
= location_completer
;
7396 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
,
7397 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7398 Like \"hbreak\" except the breakpoint is only temporary,\n\
7399 so it will be deleted when hit.");
7400 c
->completer
= location_completer
;
7402 add_prefix_cmd ("enable", class_breakpoint
, enable_command
,
7403 "Enable some breakpoints.\n\
7404 Give breakpoint numbers (separated by spaces) as arguments.\n\
7405 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7406 This is used to cancel the effect of the \"disable\" command.\n\
7407 With a subcommand you can enable temporarily.",
7408 &enablelist
, "enable ", 1, &cmdlist
);
7410 add_com ("ab", class_breakpoint
, enable_command
,
7411 "Enable some breakpoints.\n\
7412 Give breakpoint numbers (separated by spaces) as arguments.\n\
7413 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7414 This is used to cancel the effect of the \"disable\" command.\n\
7415 With a subcommand you can enable temporarily.");
7417 add_com_alias ("en", "enable", class_breakpoint
, 1);
7419 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
,
7420 "Enable some breakpoints.\n\
7421 Give breakpoint numbers (separated by spaces) as arguments.\n\
7422 This is used to cancel the effect of the \"disable\" command.\n\
7423 May be abbreviated to simply \"enable\".\n",
7424 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
7426 add_cmd ("once", no_class
, enable_once_command
,
7427 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7428 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7431 add_cmd ("delete", no_class
, enable_delete_command
,
7432 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7433 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7436 add_cmd ("delete", no_class
, enable_delete_command
,
7437 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7438 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7441 add_cmd ("once", no_class
, enable_once_command
,
7442 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7443 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7446 add_prefix_cmd ("disable", class_breakpoint
, disable_command
,
7447 "Disable some breakpoints.\n\
7448 Arguments are breakpoint numbers with spaces in between.\n\
7449 To disable all breakpoints, give no argument.\n\
7450 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7451 &disablelist
, "disable ", 1, &cmdlist
);
7452 add_com_alias ("dis", "disable", class_breakpoint
, 1);
7453 add_com_alias ("disa", "disable", class_breakpoint
, 1);
7455 add_com ("sb", class_breakpoint
, disable_command
,
7456 "Disable some breakpoints.\n\
7457 Arguments are breakpoint numbers with spaces in between.\n\
7458 To disable all breakpoints, give no argument.\n\
7459 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7461 add_cmd ("breakpoints", class_alias
, disable_command
,
7462 "Disable some breakpoints.\n\
7463 Arguments are breakpoint numbers with spaces in between.\n\
7464 To disable all breakpoints, give no argument.\n\
7465 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7466 This command may be abbreviated \"disable\".",
7469 add_prefix_cmd ("delete", class_breakpoint
, delete_command
,
7470 "Delete some breakpoints or auto-display expressions.\n\
7471 Arguments are breakpoint numbers with spaces in between.\n\
7472 To delete all breakpoints, give no argument.\n\
7474 Also a prefix command for deletion of other GDB objects.\n\
7475 The \"unset\" command is also an alias for \"delete\".",
7476 &deletelist
, "delete ", 1, &cmdlist
);
7477 add_com_alias ("d", "delete", class_breakpoint
, 1);
7479 add_com ("db", class_breakpoint
, delete_command
,
7480 "Delete some breakpoints.\n\
7481 Arguments are breakpoint numbers with spaces in between.\n\
7482 To delete all breakpoints, give no argument.\n");
7484 add_cmd ("breakpoints", class_alias
, delete_command
,
7485 "Delete some breakpoints or auto-display expressions.\n\
7486 Arguments are breakpoint numbers with spaces in between.\n\
7487 To delete all breakpoints, give no argument.\n\
7488 This command may be abbreviated \"delete\".",
7491 add_com ("clear", class_breakpoint
, clear_command
,
7492 concat ("Clear breakpoint at specified line or function.\n\
7493 Argument may be line number, function name, or \"*\" and an address.\n\
7494 If line number is specified, all breakpoints in that line are cleared.\n\
7495 If function is specified, breakpoints at beginning of function are cleared.\n\
7496 If an address is specified, breakpoints at that address are cleared.\n\n",
7497 "With no argument, clears all breakpoints in the line that the selected frame\n\
7500 See also the \"delete\" command which clears breakpoints by number.", NULL
));
7502 c
= add_com ("break", class_breakpoint
, break_command
,
7503 concat ("Set breakpoint at specified line or function.\n\
7504 Argument may be line number, function name, or \"*\" and an address.\n\
7505 If line number is specified, break at start of code for that line.\n\
7506 If function is specified, break at start of code for that function.\n\
7507 If an address is specified, break at that exact address.\n",
7508 "With no arg, uses current execution address of selected stack frame.\n\
7509 This is useful for breaking on return to a stack frame.\n\
7511 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7513 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL
));
7514 c
->completer
= location_completer
;
7516 add_com_alias ("b", "break", class_run
, 1);
7517 add_com_alias ("br", "break", class_run
, 1);
7518 add_com_alias ("bre", "break", class_run
, 1);
7519 add_com_alias ("brea", "break", class_run
, 1);
7523 add_com_alias ("ba", "break", class_breakpoint
, 1);
7524 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
7529 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
,
7530 "Break in function/address or break at a line in the current file.",
7531 &stoplist
, "stop ", 1, &cmdlist
);
7532 add_cmd ("in", class_breakpoint
, stopin_command
,
7533 "Break in function or address.\n", &stoplist
);
7534 add_cmd ("at", class_breakpoint
, stopat_command
,
7535 "Break at a line in the current file.\n", &stoplist
);
7536 add_com ("status", class_info
, breakpoints_info
,
7537 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7538 The \"Type\" column indicates one of:\n\
7539 \tbreakpoint - normal breakpoint\n\
7540 \twatchpoint - watchpoint\n\
7541 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7542 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7543 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7544 address and file/line number respectively.\n\n",
7545 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7546 are set to the address of the last breakpoint listed.\n\n\
7547 Convenience variable \"$bpnum\" contains the number of the last\n\
7548 breakpoint set.", NULL
));
7551 add_info ("breakpoints", breakpoints_info
,
7552 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7553 The \"Type\" column indicates one of:\n\
7554 \tbreakpoint - normal breakpoint\n\
7555 \twatchpoint - watchpoint\n\
7556 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7557 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7558 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7559 address and file/line number respectively.\n\n",
7560 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7561 are set to the address of the last breakpoint listed.\n\n\
7562 Convenience variable \"$bpnum\" contains the number of the last\n\
7563 breakpoint set.", NULL
));
7566 add_com ("lb", class_breakpoint
, breakpoints_info
,
7567 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7568 The \"Type\" column indicates one of:\n\
7569 \tbreakpoint - normal breakpoint\n\
7570 \twatchpoint - watchpoint\n\
7571 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7572 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7573 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7574 address and file/line number respectively.\n\n",
7575 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7576 are set to the address of the last breakpoint listed.\n\n\
7577 Convenience variable \"$bpnum\" contains the number of the last\n\
7578 breakpoint set.", NULL
));
7580 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
,
7581 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7582 The \"Type\" column indicates one of:\n\
7583 \tbreakpoint - normal breakpoint\n\
7584 \twatchpoint - watchpoint\n\
7585 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7586 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7587 \tuntil - internal breakpoint used by the \"until\" command\n\
7588 \tfinish - internal breakpoint used by the \"finish\" command\n",
7589 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7590 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7591 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7592 address and file/line number respectively.\n\n",
7593 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7594 are set to the address of the last breakpoint listed.\n\n\
7595 Convenience variable \"$bpnum\" contains the number of the last\n\
7596 breakpoint set.", NULL
),
7597 &maintenanceinfolist
);
7599 add_com ("catch", class_breakpoint
, catch_command
,
7600 "Set catchpoints to catch events.\n\
7601 Raised signals may be caught:\n\
7602 \tcatch signal - all signals\n\
7603 \tcatch signal <signame> - a particular signal\n\
7604 Raised exceptions may be caught:\n\
7605 \tcatch throw - all exceptions, when thrown\n\
7606 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7607 \tcatch catch - all exceptions, when caught\n\
7608 \tcatch catch <exceptname> - a particular exception, when caught\n\
7609 Thread or process events may be caught:\n\
7610 \tcatch thread_start - any threads, just after creation\n\
7611 \tcatch thread_exit - any threads, just before expiration\n\
7612 \tcatch thread_join - any threads, just after joins\n\
7613 Process events may be caught:\n\
7614 \tcatch start - any processes, just after creation\n\
7615 \tcatch exit - any processes, just before expiration\n\
7616 \tcatch fork - calls to fork()\n\
7617 \tcatch vfork - calls to vfork()\n\
7618 \tcatch exec - calls to exec()\n\
7619 Dynamically-linked library events may be caught:\n\
7620 \tcatch load - loads of any library\n\
7621 \tcatch load <libname> - loads of a particular library\n\
7622 \tcatch unload - unloads of any library\n\
7623 \tcatch unload <libname> - unloads of a particular library\n\
7624 The act of your program's execution stopping may also be caught:\n\
7626 C++ exceptions may be caught:\n\
7627 \tcatch throw - all exceptions, when thrown\n\
7628 \tcatch catch - all exceptions, when caught\n\
7630 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7631 after a fork or vfork is caught.\n\n\
7632 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7634 add_com ("tcatch", class_breakpoint
, tcatch_command
,
7635 "Set temporary catchpoints to catch events.\n\
7636 Args like \"catch\" command.\n\
7637 Like \"catch\" except the catchpoint is only temporary,\n\
7638 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7639 by using \"enable delete\" on the catchpoint number.");
7641 c
= add_com ("watch", class_breakpoint
, watch_command
,
7642 "Set a watchpoint for an expression.\n\
7643 A watchpoint stops execution of your program whenever the value of\n\
7644 an expression changes.");
7645 c
->completer
= location_completer
;
7647 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
7648 "Set a read watchpoint for an expression.\n\
7649 A watchpoint stops execution of your program whenever the value of\n\
7650 an expression is read.");
7651 c
->completer
= location_completer
;
7653 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
7654 "Set a watchpoint for an expression.\n\
7655 A watchpoint stops execution of your program whenever the value of\n\
7656 an expression is either read or written.");
7657 c
->completer
= location_completer
;
7659 add_info ("watchpoints", breakpoints_info
,
7660 "Synonym for ``info breakpoints''.");
7663 c
= add_set_cmd ("can-use-hw-watchpoints", class_support
, var_zinteger
,
7664 (char *) &can_use_hw_watchpoints
,
7665 "Set debugger's willingness to use watchpoint hardware.\n\
7666 If zero, gdb will not use hardware for new watchpoints, even if\n\
7667 such is available. (However, any hardware watchpoints that were\n\
7668 created before setting this to nonzero, will continue to use watchpoint\n\
7671 add_show_from_set (c
, &showlist
);
7673 can_use_hw_watchpoints
= 1;