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 static void create_longjmp_breakpoint (char *);
148 static void create_overlay_event_breakpoint (char *);
150 static int hw_breakpoint_used_count (void);
152 static int hw_watchpoint_used_count (enum bptype
, int *);
154 static void hbreak_command (char *, int);
156 static void thbreak_command (char *, int);
158 static void watch_command_1 (char *, int, int);
160 static void rwatch_command (char *, int);
162 static void awatch_command (char *, int);
164 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
166 static void solib_load_unload_1 (char *hookname
,
169 char *cond_string
, enum bptype bp_kind
);
171 static void create_fork_vfork_event_catchpoint (int tempflag
,
173 enum bptype bp_kind
);
175 static void break_at_finish_at_depth_command_1 (char *arg
,
176 int flag
, int from_tty
);
178 static void break_at_finish_command_1 (char *arg
, int flag
, int from_tty
);
180 static void stop_command (char *arg
, int from_tty
);
182 static void stopin_command (char *arg
, int from_tty
);
184 static void stopat_command (char *arg
, int from_tty
);
186 static char *ep_find_event_name_end (char *arg
);
188 static char *ep_parse_optional_if_clause (char **arg
);
190 static char *ep_parse_optional_filename (char **arg
);
192 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
193 static void catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
);
196 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
197 enum exception_event_kind ex_event
,
198 struct symtab_and_line
*sal
);
200 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
201 char *arg
, int tempflag
, int from_tty
);
203 static void tcatch_command (char *arg
, int from_tty
);
205 static void ep_skip_leading_whitespace (char **s
);
207 /* Prototypes for exported functions. */
209 /* If FALSE, gdb will not use hardware support for watchpoints, even
210 if such is available. */
211 static int can_use_hw_watchpoints
;
213 void _initialize_breakpoint (void);
215 extern int addressprint
; /* Print machine addresses? */
217 /* Are we executing breakpoint commands? */
218 static int executing_breakpoint_commands
;
220 /* Are overlay event breakpoints enabled? */
221 static int overlay_events_enabled
;
223 /* Walk the following statement or block through all breakpoints.
224 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
227 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
229 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
230 for (B = breakpoint_chain; \
231 B ? (TMP=B->next, 1): 0; \
234 /* True if SHIFT_INST_REGS defined, false otherwise. */
236 int must_shift_inst_regs
=
237 #if defined(SHIFT_INST_REGS)
244 /* True if breakpoint hit counts should be displayed in breakpoint info. */
246 int show_breakpoint_hit_counts
= 1;
248 /* Chain of all breakpoints defined. */
250 struct breakpoint
*breakpoint_chain
;
252 /* Number of last breakpoint made. */
254 int breakpoint_count
;
256 /* Pointer to current exception event record */
257 static struct exception_event_record
*current_exception_event
;
259 /* Indicator of whether exception catchpoints should be nuked
260 between runs of a program */
261 int exception_catchpoints_are_fragile
= 0;
263 /* Indicator of when exception catchpoints set-up should be
264 reinitialized -- e.g. when program is re-run */
265 int exception_support_initialized
= 0;
267 /* This function returns a pointer to the string representation of the
268 pathname of the dynamically-linked library that has just been
271 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
272 or undefined results are guaranteed.
274 This string's contents are only valid immediately after the
275 inferior has stopped in the dynamic linker hook, and becomes
276 invalid as soon as the inferior is continued. Clients should make
277 a copy of this string if they wish to continue the inferior and
278 then access the string. */
280 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
281 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
284 /* This function returns a pointer to the string representation of the
285 pathname of the dynamically-linked library that has just been
288 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
289 TRUE, or undefined results are guaranteed.
291 This string's contents are only valid immediately after the
292 inferior has stopped in the dynamic linker hook, and becomes
293 invalid as soon as the inferior is continued. Clients should make
294 a copy of this string if they wish to continue the inferior and
295 then access the string. */
297 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
298 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
301 /* This function is called by the "catch load" command. It allows the
302 debugger to be notified by the dynamic linker when a specified
303 library file (or any library file, if filename is NULL) is loaded. */
305 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
306 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
307 error ("catch of library loads not yet implemented on this platform")
310 /* This function is called by the "catch unload" command. It allows
311 the debugger to be notified by the dynamic linker when a specified
312 library file (or any library file, if filename is NULL) is
315 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
316 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
317 error ("catch of library unloads not yet implemented on this platform")
320 /* Set breakpoint count to NUM. */
323 set_breakpoint_count (int num
)
325 breakpoint_count
= num
;
326 set_internalvar (lookup_internalvar ("bpnum"),
327 value_from_longest (builtin_type_int
, (LONGEST
) num
));
330 /* Used in run_command to zero the hit count when a new run starts. */
333 clear_breakpoint_hit_counts (void)
335 struct breakpoint
*b
;
341 /* Default address, symtab and line to put a breakpoint at
342 for "break" command with no arg.
343 if default_breakpoint_valid is zero, the other three are
344 not valid, and "break" with no arg is an error.
346 This set by print_stack_frame, which calls set_default_breakpoint. */
348 int default_breakpoint_valid
;
349 CORE_ADDR default_breakpoint_address
;
350 struct symtab
*default_breakpoint_symtab
;
351 int default_breakpoint_line
;
353 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
354 Advance *PP after the string and any trailing whitespace.
356 Currently the string can either be a number or "$" followed by the name
357 of a convenience variable. Making it an expression wouldn't work well
358 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
360 TRAILER is a character which can be found after the number; most
361 commonly this is `-'. If you don't want a trailer, use \0. */
363 get_number_trailer (char **pp
, int trailer
)
365 int retval
= 0; /* default */
369 /* Empty line means refer to the last breakpoint. */
370 return breakpoint_count
;
373 /* Make a copy of the name, so we can null-terminate it
374 to pass to lookup_internalvar(). */
379 while (isalnum (*p
) || *p
== '_')
381 varname
= (char *) alloca (p
- start
+ 1);
382 strncpy (varname
, start
, p
- start
);
383 varname
[p
- start
] = '\0';
384 val
= value_of_internalvar (lookup_internalvar (varname
));
385 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
)
386 retval
= (int) value_as_long (val
);
389 printf_filtered ("Convenience variable must have integer value.\n");
397 while (*p
>= '0' && *p
<= '9')
400 /* There is no number here. (e.g. "cond a == b"). */
402 /* Skip non-numeric token */
403 while (*p
&& !isspace((int) *p
))
405 /* Return zero, which caller must interpret as error. */
411 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
413 /* Trailing junk: return 0 and let caller print error msg. */
414 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
425 /* Like get_number_trailer, but don't allow a trailer. */
427 get_number (char **pp
)
429 return get_number_trailer (pp
, '\0');
432 /* Parse a number or a range.
433 * A number will be of the form handled by get_number.
434 * A range will be of the form <number1> - <number2>, and
435 * will represent all the integers between number1 and number2,
438 * While processing a range, this fuction is called iteratively;
439 * At each call it will return the next value in the range.
441 * At the beginning of parsing a range, the char pointer PP will
442 * be advanced past <number1> and left pointing at the '-' token.
443 * Subsequent calls will not advance the pointer until the range
444 * is completed. The call that completes the range will advance
445 * pointer PP past <number2>.
449 get_number_or_range (char **pp
)
451 static int last_retval
, end_value
;
452 static char *end_ptr
;
453 static int in_range
= 0;
457 /* Default case: pp is pointing either to a solo number,
458 or to the first number of a range. */
459 last_retval
= get_number_trailer (pp
, '-');
464 /* This is the start of a range (<number1> - <number2>).
465 Skip the '-', parse and remember the second number,
466 and also remember the end of the final token. */
470 while (isspace ((int) *end_ptr
))
471 end_ptr
++; /* skip white space */
472 end_value
= get_number (temp
);
473 if (end_value
< last_retval
)
475 error ("inverted range");
477 else if (end_value
== last_retval
)
479 /* degenerate range (number1 == number2). Advance the
480 token pointer so that the range will be treated as a
489 error ("negative value");
492 /* pp points to the '-' that betokens a range. All
493 number-parsing has already been done. Return the next
494 integer value (one greater than the saved previous value).
495 Do not advance the token pointer 'pp' until the end of range
498 if (++last_retval
== end_value
)
500 /* End of range reached; advance token pointer. */
510 /* condition N EXP -- set break condition of breakpoint N to EXP. */
513 condition_command (char *arg
, int from_tty
)
515 register struct breakpoint
*b
;
520 error_no_arg ("breakpoint number");
523 bnum
= get_number (&p
);
525 error ("Bad breakpoint argument: '%s'", arg
);
528 if (b
->number
== bnum
)
535 if (b
->cond_string
!= NULL
)
536 xfree (b
->cond_string
);
541 b
->cond_string
= NULL
;
543 printf_filtered ("Breakpoint %d now unconditional.\n", bnum
);
548 /* I don't know if it matters whether this is the string the user
549 typed in or the decompiled expression. */
550 b
->cond_string
= savestring (arg
, strlen (arg
));
551 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->address
), 0);
553 error ("Junk at end of expression");
555 breakpoints_changed ();
559 error ("No breakpoint number %d.", bnum
);
564 commands_command (char *arg
, int from_tty
)
566 register struct breakpoint
*b
;
569 struct command_line
*l
;
571 /* If we allowed this, we would have problems with when to
572 free the storage, if we change the commands currently
575 if (executing_breakpoint_commands
)
576 error ("Can't use the \"commands\" command among a breakpoint's commands.");
579 bnum
= get_number (&p
);
582 error ("Unexpected extra arguments following breakpoint number.");
585 if (b
->number
== bnum
)
589 "Type commands for when breakpoint %d is hit, one per line.",
591 l
= read_command_lines (tmpbuf
, from_tty
);
592 free_command_lines (&b
->commands
);
594 breakpoints_changed ();
597 error ("No breakpoint number %d.", bnum
);
600 /* Like target_read_memory() but if breakpoints are inserted, return
601 the shadow contents instead of the breakpoints themselves.
603 Read "memory data" from whatever target or inferior we have.
604 Returns zero if successful, errno value if not. EIO is used
605 for address out of bounds. If breakpoints are inserted, returns
606 shadow contents, not the breakpoints themselves. From breakpoint.c. */
609 read_memory_nobpt (CORE_ADDR memaddr
, char *myaddr
, unsigned len
)
612 struct breakpoint
*b
;
613 CORE_ADDR bp_addr
= 0;
616 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
617 /* No breakpoints on this machine. */
618 return target_read_memory (memaddr
, myaddr
, len
);
622 if (b
->type
== bp_none
)
623 warning ("reading through apparently deleted breakpoint #%d?",
626 /* memory breakpoint? */
627 if (b
->type
== bp_watchpoint
628 || b
->type
== bp_hardware_watchpoint
629 || b
->type
== bp_read_watchpoint
630 || b
->type
== bp_access_watchpoint
)
635 /* Addresses and length of the part of the breakpoint that
637 /* XXXX The m68k, sh and h8300 have different local and remote
638 breakpoint values. BREAKPOINT_FROM_PC still manages to
639 correctly determine the breakpoints memory address and size
640 for these targets. */
641 bp_addr
= b
->address
;
643 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
648 if (bp_addr
+ bp_size
<= memaddr
)
649 /* The breakpoint is entirely before the chunk of memory we
652 if (bp_addr
>= memaddr
+ len
)
653 /* The breakpoint is entirely after the chunk of memory we are
656 /* Copy the breakpoint from the shadow contents, and recurse for
657 the things before and after. */
659 /* Offset within shadow_contents. */
662 if (bp_addr
< memaddr
)
664 /* Only copy the second part of the breakpoint. */
665 bp_size
-= memaddr
- bp_addr
;
666 bptoffset
= memaddr
- bp_addr
;
670 if (bp_addr
+ bp_size
> memaddr
+ len
)
672 /* Only copy the first part of the breakpoint. */
673 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
676 memcpy (myaddr
+ bp_addr
- memaddr
,
677 b
->shadow_contents
+ bptoffset
, bp_size
);
679 if (bp_addr
> memaddr
)
681 /* Copy the section of memory before the breakpoint. */
682 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
687 if (bp_addr
+ bp_size
< memaddr
+ len
)
689 /* Copy the section of memory after the breakpoint. */
690 status
= read_memory_nobpt (bp_addr
+ bp_size
,
691 myaddr
+ bp_addr
+ bp_size
- memaddr
,
692 memaddr
+ len
- (bp_addr
+ bp_size
));
699 /* Nothing overlaps. Just call read_memory_noerr. */
700 return target_read_memory (memaddr
, myaddr
, len
);
704 /* insert_breakpoints is used when starting or continuing the program.
705 remove_breakpoints is used when the program stops.
706 Both return zero if successful,
707 or an `errno' value if could not write the inferior. */
710 insert_breakpoints (void)
712 register struct breakpoint
*b
, *temp
;
713 int return_val
= 0; /* return success code. */
715 int disabled_breaks
= 0;
717 static char message1
[] = "Error inserting catchpoint %d:\n";
718 static char message
[sizeof (message1
) + 30];
721 ALL_BREAKPOINTS_SAFE (b
, temp
)
723 if (b
->enable_state
== bp_permanent
)
724 /* Permanent breakpoints cannot be inserted or removed. */
726 else if (b
->type
!= bp_watchpoint
727 && b
->type
!= bp_hardware_watchpoint
728 && b
->type
!= bp_read_watchpoint
729 && b
->type
!= bp_access_watchpoint
730 && b
->type
!= bp_catch_fork
731 && b
->type
!= bp_catch_vfork
732 && b
->type
!= bp_catch_exec
733 && b
->type
!= bp_catch_throw
734 && b
->type
!= bp_catch_catch
735 && b
->enable_state
!= bp_disabled
736 && b
->enable_state
!= bp_shlib_disabled
737 && b
->enable_state
!= bp_call_disabled
741 /* "Normal" instruction breakpoint: either the standard
742 trap-instruction bp (bp_breakpoint), or a
743 bp_hardware_breakpoint. */
745 /* First check to see if we have to handle an overlay. */
746 if (overlay_debugging
== ovly_off
747 || b
->section
== NULL
748 || !(section_is_overlay (b
->section
)))
750 /* No overlay handling: just set the breakpoint. */
752 if (b
->type
== bp_hardware_breakpoint
)
753 val
= target_insert_hw_breakpoint (b
->address
,
756 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
760 /* This breakpoint is in an overlay section.
761 Shall we set a breakpoint at the LMA? */
762 if (!overlay_events_enabled
)
764 /* Yes -- overlay event support is not active,
765 so we must try to set a breakpoint at the LMA.
766 This will not work for a hardware breakpoint. */
767 if (b
->type
== bp_hardware_breakpoint
)
768 warning ("hardware breakpoint %d not supported in overlay!\n",
772 CORE_ADDR addr
= overlay_unmapped_address (b
->address
,
774 /* Set a software (trap) breakpoint at the LMA. */
775 val
= target_insert_breakpoint (addr
, b
->shadow_contents
);
777 warning ("overlay breakpoint %d failed: in ROM?",
781 /* Shall we set a breakpoint at the VMA? */
782 if (section_is_mapped (b
->section
))
784 /* Yes. This overlay section is mapped into memory. */
785 if (b
->type
== bp_hardware_breakpoint
)
786 val
= target_insert_hw_breakpoint (b
->address
,
789 val
= target_insert_breakpoint (b
->address
,
794 /* No. This breakpoint will not be inserted.
795 No error, but do not mark the bp as 'inserted'. */
802 /* Can't set the breakpoint. */
803 #if defined (DISABLE_UNSETTABLE_BREAK)
804 if (DISABLE_UNSETTABLE_BREAK (b
->address
))
806 /* See also: disable_breakpoints_in_shlibs. */
808 b
->enable_state
= bp_shlib_disabled
;
809 if (!disabled_breaks
)
811 target_terminal_ours_for_output ();
812 warning ("Cannot insert breakpoint %d:", b
->number
);
813 warning ("Temporarily disabling shared library breakpoints:");
816 warning ("breakpoint #%d ", b
->number
);
821 target_terminal_ours_for_output ();
822 warning ("Cannot insert breakpoint %d:", b
->number
);
823 #ifdef ONE_PROCESS_WRITETEXT
824 warning ("The same program may be running in another process.");
826 memory_error (val
, b
->address
); /* which bombs us out */
833 return_val
= val
; /* remember failure */
835 else if (ep_is_exception_catchpoint (b
)
836 && b
->enable_state
!= bp_disabled
837 && b
->enable_state
!= bp_shlib_disabled
838 && b
->enable_state
!= bp_call_disabled
843 /* If we get here, we must have a callback mechanism for exception
844 events -- with g++ style embedded label support, we insert
845 ordinary breakpoints and not catchpoints. */
846 /* Format possible error message */
847 sprintf (message
, message1
, b
->number
);
849 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
852 /* Couldn't set breakpoint for some reason */
853 target_terminal_ours_for_output ();
854 warning ("Cannot insert catchpoint %d; disabling it.",
856 b
->enable_state
= bp_disabled
;
860 /* Bp set, now make sure callbacks are enabled */
862 args_for_catchpoint_enable args
;
863 args
.kind
= b
->type
== bp_catch_catch
?
864 EX_EVENT_CATCH
: EX_EVENT_THROW
;
866 val
= catch_errors (cover_target_enable_exception_callback
,
868 message
, RETURN_MASK_ALL
);
869 if (val
!= 0 && val
!= -1)
873 /* Check if something went wrong; val == 0 can be ignored */
876 /* something went wrong */
877 target_terminal_ours_for_output ();
878 warning ("Cannot insert catchpoint %d; disabling it.",
880 b
->enable_state
= bp_disabled
;
885 return_val
= val
; /* remember failure */
888 else if ((b
->type
== bp_hardware_watchpoint
||
889 b
->type
== bp_read_watchpoint
||
890 b
->type
== bp_access_watchpoint
)
891 && b
->enable_state
== bp_enabled
892 && b
->disposition
!= disp_del_at_next_stop
896 struct frame_info
*saved_frame
;
897 int saved_level
, within_current_scope
;
898 struct value
*mark
= value_mark ();
901 /* Save the current frame and level so we can restore it after
902 evaluating the watchpoint expression on its own frame. */
903 saved_frame
= selected_frame
;
904 saved_level
= frame_relative_level (selected_frame
);
906 /* Determine if the watchpoint is within scope. */
907 if (b
->exp_valid_block
== NULL
)
908 within_current_scope
= 1;
911 struct frame_info
*fi
;
912 fi
= frame_find_by_id (b
->watchpoint_frame
);
913 within_current_scope
= (fi
!= NULL
);
914 if (within_current_scope
)
918 if (within_current_scope
)
920 /* Evaluate the expression and cut the chain of values
921 produced off from the value chain.
923 Make sure the value returned isn't lazy; we use
924 laziness to determine what memory GDB actually needed
925 in order to compute the value of the expression. */
926 v
= evaluate_expression (b
->exp
);
928 value_release_to_mark (mark
);
933 /* Look at each value on the value chain. */
934 for (; v
; v
= v
->next
)
936 /* If it's a memory location, and GDB actually needed
937 its contents to evaluate the expression, then we
939 if (VALUE_LVAL (v
) == lval_memory
942 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
944 /* We only watch structs and arrays if user asked
945 for it explicitly, never if they just happen to
946 appear in the middle of some value chain. */
947 if (v
== b
->val_chain
948 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
949 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
954 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
955 len
= TYPE_LENGTH (VALUE_TYPE (v
));
957 if (b
->type
== bp_read_watchpoint
)
959 else if (b
->type
== bp_access_watchpoint
)
962 val
= target_insert_watchpoint (addr
, len
, type
);
965 /* Don't exit the loop, try to insert
966 every value on the value chain. That's
967 because we will be removing all the
968 watches below, and removing a
969 watchpoint we didn't insert could have
977 /* Failure to insert a watchpoint on any memory value in the
978 value chain brings us here. */
981 remove_breakpoint (b
, mark_uninserted
);
982 warning ("Could not insert hardware watchpoint %d.",
989 printf_filtered ("Hardware watchpoint %d deleted ", b
->number
);
990 printf_filtered ("because the program has left the block \n");
991 printf_filtered ("in which its expression is valid.\n");
992 if (b
->related_breakpoint
)
993 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
994 b
->disposition
= disp_del_at_next_stop
;
997 /* Restore the frame and level. */
998 if ((saved_frame
!= selected_frame
) ||
999 (saved_level
!= frame_relative_level (selected_frame
)))
1000 select_frame (saved_frame
);
1003 return_val
= val
; /* remember failure */
1005 else if ((b
->type
== bp_catch_fork
1006 || b
->type
== bp_catch_vfork
1007 || b
->type
== bp_catch_exec
)
1008 && b
->enable_state
== bp_enabled
1016 val
= target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
1018 case bp_catch_vfork
:
1019 val
= target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
1022 val
= target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
1025 warning ("Internal error, %s line %d.", __FILE__
, __LINE__
);
1030 target_terminal_ours_for_output ();
1031 warning ("Cannot insert catchpoint %d.", b
->number
);
1037 return_val
= val
; /* remember failure */
1046 remove_breakpoints (void)
1048 register struct breakpoint
*b
;
1055 val
= remove_breakpoint (b
, mark_uninserted
);
1064 remove_hw_watchpoints (void)
1066 register struct breakpoint
*b
;
1072 && (b
->type
== bp_hardware_watchpoint
1073 || b
->type
== bp_read_watchpoint
1074 || b
->type
== bp_access_watchpoint
))
1076 val
= remove_breakpoint (b
, mark_uninserted
);
1085 reattach_breakpoints (int pid
)
1087 register struct breakpoint
*b
;
1089 struct cleanup
*old_chain
= save_inferior_ptid ();
1091 /* Set inferior_ptid; remove_breakpoint uses this global. */
1092 inferior_ptid
= pid_to_ptid (pid
);
1097 remove_breakpoint (b
, mark_inserted
);
1098 if (b
->type
== bp_hardware_breakpoint
)
1099 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
1101 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
1104 do_cleanups (old_chain
);
1109 do_cleanups (old_chain
);
1114 update_breakpoints_after_exec (void)
1116 struct breakpoint
*b
;
1117 struct breakpoint
*temp
;
1119 /* Doing this first prevents the badness of having delete_breakpoint()
1120 write a breakpoint's current "shadow contents" to lift the bp. That
1121 shadow is NOT valid after an exec()! */
1122 mark_breakpoints_out ();
1124 ALL_BREAKPOINTS_SAFE (b
, temp
)
1126 /* Solib breakpoints must be explicitly reset after an exec(). */
1127 if (b
->type
== bp_shlib_event
)
1129 delete_breakpoint (b
);
1133 /* Thread event breakpoints must be set anew after an exec(),
1134 as must overlay event breakpoints. */
1135 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1137 delete_breakpoint (b
);
1141 /* Step-resume breakpoints are meaningless after an exec(). */
1142 if (b
->type
== bp_step_resume
)
1144 delete_breakpoint (b
);
1148 /* Ditto the sigtramp handler breakpoints. */
1149 if (b
->type
== bp_through_sigtramp
)
1151 delete_breakpoint (b
);
1155 /* Ditto the exception-handling catchpoints. */
1156 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1158 delete_breakpoint (b
);
1162 /* Don't delete an exec catchpoint, because else the inferior
1163 won't stop when it ought!
1165 Similarly, we probably ought to keep vfork catchpoints, 'cause
1166 on this target, we may not be able to stop when the vfork is
1167 seen, but only when the subsequent exec is seen. (And because
1168 deleting fork catchpoints here but not vfork catchpoints will
1169 seem mysterious to users, keep those too.)
1171 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1172 target address field, if any, is sufficient to have it be reset
1173 automagically. Certainly on HP-UX that's true.
1175 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1176 valid code address on some platforms (like the mn10200 and
1177 mn10300 simulators). We shouldn't assign any special
1178 interpretation to a breakpoint with a zero address. And in
1179 fact, GDB doesn't --- I can't see what that comment above is
1180 talking about. As far as I can tell, setting the address of a
1181 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1182 is meaningless, since those are implemented with HP-UX kernel
1183 hackery, not by storing breakpoint instructions somewhere. */
1184 if ((b
->type
== bp_catch_exec
) ||
1185 (b
->type
== bp_catch_vfork
) ||
1186 (b
->type
== bp_catch_fork
))
1188 b
->address
= (CORE_ADDR
) NULL
;
1192 /* bp_finish is a special case. The only way we ought to be able
1193 to see one of these when an exec() has happened, is if the user
1194 caught a vfork, and then said "finish". Ordinarily a finish just
1195 carries them to the call-site of the current callee, by setting
1196 a temporary bp there and resuming. But in this case, the finish
1197 will carry them entirely through the vfork & exec.
1199 We don't want to allow a bp_finish to remain inserted now. But
1200 we can't safely delete it, 'cause finish_command has a handle to
1201 the bp on a bpstat, and will later want to delete it. There's a
1202 chance (and I've seen it happen) that if we delete the bp_finish
1203 here, that its storage will get reused by the time finish_command
1204 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1205 We really must allow finish_command to delete a bp_finish.
1207 In the absense of a general solution for the "how do we know
1208 it's safe to delete something others may have handles to?"
1209 problem, what we'll do here is just uninsert the bp_finish, and
1210 let finish_command delete it.
1212 (We know the bp_finish is "doomed" in the sense that it's
1213 momentary, and will be deleted as soon as finish_command sees
1214 the inferior stopped. So it doesn't matter that the bp's
1215 address is probably bogus in the new a.out, unlike e.g., the
1216 solib breakpoints.) */
1218 if (b
->type
== bp_finish
)
1223 /* Without a symbolic address, we have little hope of the
1224 pre-exec() address meaning the same thing in the post-exec()
1226 if (b
->addr_string
== NULL
)
1228 delete_breakpoint (b
);
1232 /* If this breakpoint has survived the above battery of checks, then
1233 it must have a symbolic address. Be sure that it gets reevaluated
1234 to a target address, rather than reusing the old evaluation.
1236 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1237 for bp_catch_exec and friends, I'm pretty sure this is entirely
1238 unnecessary. A call to breakpoint_re_set_one always recomputes
1239 the breakpoint's address from scratch, or deletes it if it can't.
1240 So I think this assignment could be deleted without effect. */
1241 b
->address
= (CORE_ADDR
) NULL
;
1243 /* FIXME what about longjmp breakpoints? Re-create them here? */
1244 create_overlay_event_breakpoint ("_ovly_debug_event");
1248 detach_breakpoints (int pid
)
1250 register struct breakpoint
*b
;
1252 struct cleanup
*old_chain
= save_inferior_ptid ();
1254 if (pid
== PIDGET (inferior_ptid
))
1255 error ("Cannot detach breakpoints of inferior_ptid");
1257 /* Set inferior_ptid; remove_breakpoint uses this global. */
1258 inferior_ptid
= pid_to_ptid (pid
);
1263 val
= remove_breakpoint (b
, mark_inserted
);
1266 do_cleanups (old_chain
);
1271 do_cleanups (old_chain
);
1276 remove_breakpoint (struct breakpoint
*b
, insertion_state_t is
)
1280 if (b
->enable_state
== bp_permanent
)
1281 /* Permanent breakpoints cannot be inserted or removed. */
1284 if (b
->type
== bp_none
)
1285 warning ("attempted to remove apparently deleted breakpoint #%d?",
1288 if (b
->type
!= bp_watchpoint
1289 && b
->type
!= bp_hardware_watchpoint
1290 && b
->type
!= bp_read_watchpoint
1291 && b
->type
!= bp_access_watchpoint
1292 && b
->type
!= bp_catch_fork
1293 && b
->type
!= bp_catch_vfork
1294 && b
->type
!= bp_catch_exec
1295 && b
->type
!= bp_catch_catch
1296 && b
->type
!= bp_catch_throw
)
1298 /* "Normal" instruction breakpoint: either the standard
1299 trap-instruction bp (bp_breakpoint), or a
1300 bp_hardware_breakpoint. */
1302 /* First check to see if we have to handle an overlay. */
1303 if (overlay_debugging
== ovly_off
1304 || b
->section
== NULL
1305 || !(section_is_overlay (b
->section
)))
1307 /* No overlay handling: just remove the breakpoint. */
1309 if (b
->type
== bp_hardware_breakpoint
)
1310 val
= target_remove_hw_breakpoint (b
->address
,
1311 b
->shadow_contents
);
1313 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1317 /* This breakpoint is in an overlay section.
1318 Did we set a breakpoint at the LMA? */
1319 if (!overlay_events_enabled
)
1321 /* Yes -- overlay event support is not active, so we
1322 should have set a breakpoint at the LMA. Remove it.
1324 CORE_ADDR addr
= overlay_unmapped_address (b
->address
,
1326 /* Ignore any failures: if the LMA is in ROM, we will
1327 have already warned when we failed to insert it. */
1328 if (b
->type
!= bp_hardware_breakpoint
)
1329 target_remove_hw_breakpoint (addr
, b
->shadow_contents
);
1331 target_remove_breakpoint (addr
, b
->shadow_contents
);
1333 /* Did we set a breakpoint at the VMA?
1334 If so, we will have marked the breakpoint 'inserted'. */
1337 /* Yes -- remove it. Previously we did not bother to
1338 remove the breakpoint if the section had been
1339 unmapped, but let's not rely on that being safe. We
1340 don't know what the overlay manager might do. */
1341 if (b
->type
== bp_hardware_breakpoint
)
1342 val
= target_remove_hw_breakpoint (b
->address
,
1343 b
->shadow_contents
);
1345 val
= target_remove_breakpoint (b
->address
,
1346 b
->shadow_contents
);
1350 /* No -- not inserted, so no need to remove. No error. */
1356 b
->inserted
= (is
== mark_inserted
);
1358 else if ((b
->type
== bp_hardware_watchpoint
||
1359 b
->type
== bp_read_watchpoint
||
1360 b
->type
== bp_access_watchpoint
)
1361 && b
->enable_state
== bp_enabled
1367 b
->inserted
= (is
== mark_inserted
);
1368 /* Walk down the saved value chain. */
1369 for (v
= b
->val_chain
; v
; v
= v
->next
)
1371 /* For each memory reference remove the watchpoint
1373 if (VALUE_LVAL (v
) == lval_memory
1374 && ! VALUE_LAZY (v
))
1376 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
1378 if (v
== b
->val_chain
1379 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1380 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1385 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1386 len
= TYPE_LENGTH (VALUE_TYPE (v
));
1388 if (b
->type
== bp_read_watchpoint
)
1390 else if (b
->type
== bp_access_watchpoint
)
1393 val
= target_remove_watchpoint (addr
, len
, type
);
1400 /* Failure to remove any of the hardware watchpoints comes here. */
1401 if ((is
== mark_uninserted
) && (b
->inserted
))
1402 warning ("Could not remove hardware watchpoint %d.",
1405 /* Free the saved value chain. We will construct a new one
1406 the next time the watchpoint is inserted. */
1407 for (v
= b
->val_chain
; v
; v
= n
)
1412 b
->val_chain
= NULL
;
1414 else if ((b
->type
== bp_catch_fork
||
1415 b
->type
== bp_catch_vfork
||
1416 b
->type
== bp_catch_exec
)
1417 && b
->enable_state
== bp_enabled
1424 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1426 case bp_catch_vfork
:
1427 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1430 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1433 warning ("Internal error, %s line %d.", __FILE__
, __LINE__
);
1438 b
->inserted
= (is
== mark_inserted
);
1440 else if ((b
->type
== bp_catch_catch
||
1441 b
->type
== bp_catch_throw
)
1442 && b
->enable_state
== bp_enabled
1446 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1449 b
->inserted
= (is
== mark_inserted
);
1451 else if (ep_is_exception_catchpoint (b
)
1452 && b
->inserted
/* sometimes previous insert doesn't happen */
1453 && b
->enable_state
== bp_enabled
1457 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1461 b
->inserted
= (is
== mark_inserted
);
1467 /* Clear the "inserted" flag in all breakpoints. */
1470 mark_breakpoints_out (void)
1472 register struct breakpoint
*b
;
1478 /* Clear the "inserted" flag in all breakpoints and delete any
1479 breakpoints which should go away between runs of the program.
1481 Plus other such housekeeping that has to be done for breakpoints
1484 Note: this function gets called at the end of a run (by
1485 generic_mourn_inferior) and when a run begins (by
1486 init_wait_for_inferior). */
1491 breakpoint_init_inferior (enum inf_context context
)
1493 register struct breakpoint
*b
, *temp
;
1494 static int warning_needed
= 0;
1496 ALL_BREAKPOINTS_SAFE (b
, temp
)
1503 case bp_watchpoint_scope
:
1505 /* If the call dummy breakpoint is at the entry point it will
1506 cause problems when the inferior is rerun, so we better
1509 Also get rid of scope breakpoints. */
1510 delete_breakpoint (b
);
1514 case bp_hardware_watchpoint
:
1515 case bp_read_watchpoint
:
1516 case bp_access_watchpoint
:
1518 /* Likewise for watchpoints on local expressions. */
1519 if (b
->exp_valid_block
!= NULL
)
1520 delete_breakpoint (b
);
1523 /* Likewise for exception catchpoints in dynamic-linked
1524 executables where required */
1525 if (ep_is_exception_catchpoint (b
) &&
1526 exception_catchpoints_are_fragile
)
1529 delete_breakpoint (b
);
1535 if (exception_catchpoints_are_fragile
)
1536 exception_support_initialized
= 0;
1538 /* Don't issue the warning unless it's really needed... */
1539 if (warning_needed
&& (context
!= inf_exited
))
1541 warning ("Exception catchpoints from last run were deleted.");
1542 warning ("You must reinsert them explicitly.");
1547 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1548 exists at PC. It returns ordinary_breakpoint_here if it's an
1549 ordinary breakpoint, or permanent_breakpoint_here if it's a
1550 permanent breakpoint.
1551 - When continuing from a location with an ordinary breakpoint, we
1552 actually single step once before calling insert_breakpoints.
1553 - When continuing from a localion with a permanent breakpoint, we
1554 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1555 the target, to advance the PC past the breakpoint. */
1557 enum breakpoint_here
1558 breakpoint_here_p (CORE_ADDR pc
)
1560 register struct breakpoint
*b
;
1561 int any_breakpoint_here
= 0;
1564 if ((b
->enable_state
== bp_enabled
1565 || b
->enable_state
== bp_permanent
)
1566 && b
->address
== pc
) /* bp is enabled and matches pc */
1568 if (overlay_debugging
1569 && section_is_overlay (b
->section
)
1570 && !section_is_mapped (b
->section
))
1571 continue; /* unmapped overlay -- can't be a match */
1572 else if (b
->enable_state
== bp_permanent
)
1573 return permanent_breakpoint_here
;
1575 any_breakpoint_here
= 1;
1578 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1582 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1583 but it only returns true if there is actually a breakpoint inserted
1587 breakpoint_inserted_here_p (CORE_ADDR pc
)
1589 register struct breakpoint
*b
;
1593 && b
->address
== pc
) /* bp is inserted and matches pc */
1595 if (overlay_debugging
1596 && section_is_overlay (b
->section
)
1597 && !section_is_mapped (b
->section
))
1598 continue; /* unmapped overlay -- can't be a match */
1606 /* Return nonzero if FRAME is a dummy frame. We can't use
1607 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1608 much time, at least using get_saved_register on the 68k. This
1609 means that for this function to work right a port must use the
1610 bp_call_dummy breakpoint. */
1613 frame_in_dummy (struct frame_info
*frame
)
1615 struct breakpoint
*b
;
1620 if (USE_GENERIC_DUMMY_FRAMES
)
1621 return generic_pc_in_call_dummy (frame
->pc
, frame
->frame
, frame
->frame
);
1625 if (b
->type
== bp_call_dummy
1626 && b
->frame
== frame
->frame
1627 /* We need to check the PC as well as the frame on the sparc,
1628 for signals.exp in the testsuite. */
1631 - SIZEOF_CALL_DUMMY_WORDS
/ sizeof (LONGEST
) * REGISTER_SIZE
))
1632 && frame
->pc
<= b
->address
)
1638 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1639 PC is valid for process/thread PID. */
1642 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1644 struct breakpoint
*b
;
1647 thread
= pid_to_thread_id (ptid
);
1650 if (b
->enable_state
!= bp_disabled
1651 && b
->enable_state
!= bp_shlib_disabled
1652 && b
->enable_state
!= bp_call_disabled
1654 && (b
->thread
== -1 || b
->thread
== thread
))
1656 if (overlay_debugging
1657 && section_is_overlay (b
->section
)
1658 && !section_is_mapped (b
->section
))
1659 continue; /* unmapped overlay -- can't be a match */
1668 /* bpstat stuff. External routines' interfaces are documented
1672 ep_is_catchpoint (struct breakpoint
*ep
)
1675 (ep
->type
== bp_catch_load
)
1676 || (ep
->type
== bp_catch_unload
)
1677 || (ep
->type
== bp_catch_fork
)
1678 || (ep
->type
== bp_catch_vfork
)
1679 || (ep
->type
== bp_catch_exec
)
1680 || (ep
->type
== bp_catch_catch
)
1681 || (ep
->type
== bp_catch_throw
);
1683 /* ??rehrauer: Add more kinds here, as are implemented... */
1687 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1690 (ep
->type
== bp_catch_load
)
1691 || (ep
->type
== bp_catch_unload
);
1695 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1698 (ep
->type
== bp_catch_catch
)
1699 || (ep
->type
== bp_catch_throw
);
1702 /* Clear a bpstat so that it says we are not at any breakpoint.
1703 Also free any storage that is part of a bpstat. */
1706 bpstat_clear (bpstat
*bsp
)
1717 if (p
->old_val
!= NULL
)
1718 value_free (p
->old_val
);
1725 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1726 is part of the bpstat is copied as well. */
1729 bpstat_copy (bpstat bs
)
1733 bpstat retval
= NULL
;
1738 for (; bs
!= NULL
; bs
= bs
->next
)
1740 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1741 memcpy (tmp
, bs
, sizeof (*tmp
));
1743 /* This is the first thing in the chain. */
1753 /* Find the bpstat associated with this breakpoint */
1756 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1761 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1763 if (bsp
->breakpoint_at
== breakpoint
)
1769 /* Find a step_resume breakpoint associated with this bpstat.
1770 (If there are multiple step_resume bp's on the list, this function
1771 will arbitrarily pick one.)
1773 It is an error to use this function if BPSTAT doesn't contain a
1774 step_resume breakpoint.
1776 See wait_for_inferior's use of this function. */
1778 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1783 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1785 current_thread
= pid_to_thread_id (inferior_ptid
);
1787 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1789 if ((bsp
->breakpoint_at
!= NULL
) &&
1790 (bsp
->breakpoint_at
->type
== bp_step_resume
) &&
1791 (bsp
->breakpoint_at
->thread
== current_thread
||
1792 bsp
->breakpoint_at
->thread
== -1))
1793 return bsp
->breakpoint_at
;
1796 error ("Internal error (no step_resume breakpoint found)");
1800 /* Return the breakpoint number of the first breakpoint we are stopped
1801 at. *BSP upon return is a bpstat which points to the remaining
1802 breakpoints stopped at (but which is not guaranteed to be good for
1803 anything but further calls to bpstat_num).
1804 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1807 bpstat_num (bpstat
*bsp
)
1809 struct breakpoint
*b
;
1812 return 0; /* No more breakpoint values */
1815 b
= (*bsp
)->breakpoint_at
;
1816 *bsp
= (*bsp
)->next
;
1818 return -1; /* breakpoint that's been deleted since */
1820 return b
->number
; /* We have its number */
1824 /* Modify BS so that the actions will not be performed. */
1827 bpstat_clear_actions (bpstat bs
)
1829 for (; bs
!= NULL
; bs
= bs
->next
)
1831 bs
->commands
= NULL
;
1832 if (bs
->old_val
!= NULL
)
1834 value_free (bs
->old_val
);
1840 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1843 cleanup_executing_breakpoints (PTR ignore
)
1845 executing_breakpoint_commands
= 0;
1848 /* Execute all the commands associated with all the breakpoints at this
1849 location. Any of these commands could cause the process to proceed
1850 beyond this point, etc. We look out for such changes by checking
1851 the global "breakpoint_proceeded" after each command. */
1854 bpstat_do_actions (bpstat
*bsp
)
1857 struct cleanup
*old_chain
;
1858 struct command_line
*cmd
;
1860 /* Avoid endless recursion if a `source' command is contained
1862 if (executing_breakpoint_commands
)
1865 executing_breakpoint_commands
= 1;
1866 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
1869 /* Note that (as of this writing), our callers all appear to
1870 be passing us the address of global stop_bpstat. And, if
1871 our calls to execute_control_command cause the inferior to
1872 proceed, that global (and hence, *bsp) will change.
1874 We must be careful to not touch *bsp unless the inferior
1875 has not proceeded. */
1877 /* This pointer will iterate over the list of bpstat's. */
1880 breakpoint_proceeded
= 0;
1881 for (; bs
!= NULL
; bs
= bs
->next
)
1886 execute_control_command (cmd
);
1888 if (breakpoint_proceeded
)
1893 if (breakpoint_proceeded
)
1894 /* The inferior is proceeded by the command; bomb out now.
1895 The bpstat chain has been blown away by wait_for_inferior.
1896 But since execution has stopped again, there is a new bpstat
1897 to look at, so start over. */
1900 bs
->commands
= NULL
;
1903 executing_breakpoint_commands
= 0;
1904 discard_cleanups (old_chain
);
1907 /* This is the normal print function for a bpstat. In the future,
1908 much of this logic could (should?) be moved to bpstat_stop_status,
1909 by having it set different print_it values.
1911 Current scheme: When we stop, bpstat_print() is called. It loops
1912 through the bpstat list of things causing this stop, calling the
1913 print_bp_stop_message function on each one. The behavior of the
1914 print_bp_stop_message function depends on the print_it field of
1915 bpstat. If such field so indicates, call this function here.
1917 Return values from this routine (ultimately used by bpstat_print()
1918 and normal_stop() to decide what to do):
1919 PRINT_NOTHING: Means we already printed all we needed to print,
1920 don't print anything else.
1921 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1922 that something to be followed by a location.
1923 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1924 that something to be followed by a location.
1925 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
1928 static enum print_stop_action
1929 print_it_typical (bpstat bs
)
1931 struct cleanup
*old_chain
;
1932 struct ui_stream
*stb
;
1933 stb
= ui_out_stream_new (uiout
);
1934 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
1935 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1936 which has since been deleted. */
1937 if (bs
->breakpoint_at
== NULL
)
1938 return PRINT_UNKNOWN
;
1940 switch (bs
->breakpoint_at
->type
)
1943 case bp_hardware_breakpoint
:
1944 annotate_breakpoint (bs
->breakpoint_at
->number
);
1945 ui_out_text (uiout
, "\nBreakpoint ");
1946 if (ui_out_is_mi_like_p (uiout
))
1947 ui_out_field_string (uiout
, "reason", "breakpoint-hit");
1948 ui_out_field_int (uiout
, "bkptno", bs
->breakpoint_at
->number
);
1949 ui_out_text (uiout
, ", ");
1950 return PRINT_SRC_AND_LOC
;
1953 case bp_shlib_event
:
1954 /* Did we stop because the user set the stop_on_solib_events
1955 variable? (If so, we report this as a generic, "Stopped due
1956 to shlib event" message.) */
1957 printf_filtered ("Stopped due to shared library event\n");
1958 return PRINT_NOTHING
;
1961 case bp_thread_event
:
1962 /* Not sure how we will get here.
1963 GDB should not stop for these breakpoints. */
1964 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
1965 return PRINT_NOTHING
;
1968 case bp_overlay_event
:
1969 /* By analogy with the thread event, GDB should not stop for these. */
1970 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
1971 return PRINT_NOTHING
;
1975 annotate_catchpoint (bs
->breakpoint_at
->number
);
1976 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
1977 printf_filtered ("loaded");
1978 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
1979 return PRINT_SRC_AND_LOC
;
1982 case bp_catch_unload
:
1983 annotate_catchpoint (bs
->breakpoint_at
->number
);
1984 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
1985 printf_filtered ("unloaded");
1986 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
1987 return PRINT_SRC_AND_LOC
;
1991 annotate_catchpoint (bs
->breakpoint_at
->number
);
1992 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
1993 printf_filtered ("forked");
1994 printf_filtered (" process %d), ",
1995 bs
->breakpoint_at
->forked_inferior_pid
);
1996 return PRINT_SRC_AND_LOC
;
1999 case bp_catch_vfork
:
2000 annotate_catchpoint (bs
->breakpoint_at
->number
);
2001 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2002 printf_filtered ("vforked");
2003 printf_filtered (" process %d), ",
2004 bs
->breakpoint_at
->forked_inferior_pid
);
2005 return PRINT_SRC_AND_LOC
;
2009 annotate_catchpoint (bs
->breakpoint_at
->number
);
2010 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2011 bs
->breakpoint_at
->number
,
2012 bs
->breakpoint_at
->exec_pathname
);
2013 return PRINT_SRC_AND_LOC
;
2016 case bp_catch_catch
:
2017 if (current_exception_event
&&
2018 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2020 annotate_catchpoint (bs
->breakpoint_at
->number
);
2021 printf_filtered ("\nCatchpoint %d (exception caught), ",
2022 bs
->breakpoint_at
->number
);
2023 printf_filtered ("throw location ");
2024 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2025 printf_filtered ("%s:%d",
2026 CURRENT_EXCEPTION_THROW_FILE
,
2027 CURRENT_EXCEPTION_THROW_LINE
);
2029 printf_filtered ("unknown");
2031 printf_filtered (", catch location ");
2032 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2033 printf_filtered ("%s:%d",
2034 CURRENT_EXCEPTION_CATCH_FILE
,
2035 CURRENT_EXCEPTION_CATCH_LINE
);
2037 printf_filtered ("unknown");
2039 printf_filtered ("\n");
2040 /* don't bother to print location frame info */
2041 return PRINT_SRC_ONLY
;
2045 /* really throw, some other bpstat will handle it */
2046 return PRINT_UNKNOWN
;
2050 case bp_catch_throw
:
2051 if (current_exception_event
&&
2052 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2054 annotate_catchpoint (bs
->breakpoint_at
->number
);
2055 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2056 bs
->breakpoint_at
->number
);
2057 printf_filtered ("throw location ");
2058 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2059 printf_filtered ("%s:%d",
2060 CURRENT_EXCEPTION_THROW_FILE
,
2061 CURRENT_EXCEPTION_THROW_LINE
);
2063 printf_filtered ("unknown");
2065 printf_filtered (", catch location ");
2066 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2067 printf_filtered ("%s:%d",
2068 CURRENT_EXCEPTION_CATCH_FILE
,
2069 CURRENT_EXCEPTION_CATCH_LINE
);
2071 printf_filtered ("unknown");
2073 printf_filtered ("\n");
2074 /* don't bother to print location frame info */
2075 return PRINT_SRC_ONLY
;
2079 /* really catch, some other bpstat will handle it */
2080 return PRINT_UNKNOWN
;
2085 case bp_hardware_watchpoint
:
2086 if (bs
->old_val
!= NULL
)
2088 annotate_watchpoint (bs
->breakpoint_at
->number
);
2089 if (ui_out_is_mi_like_p (uiout
))
2090 ui_out_field_string (uiout
, "reason", "watchpoint-trigger");
2091 mention (bs
->breakpoint_at
);
2092 ui_out_tuple_begin (uiout
, "value");
2093 ui_out_text (uiout
, "\nOld value = ");
2094 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2095 ui_out_field_stream (uiout
, "old", stb
);
2096 ui_out_text (uiout
, "\nNew value = ");
2097 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2098 ui_out_field_stream (uiout
, "new", stb
);
2099 ui_out_tuple_end (uiout
);
2100 ui_out_text (uiout
, "\n");
2101 value_free (bs
->old_val
);
2104 /* More than one watchpoint may have been triggered. */
2105 return PRINT_UNKNOWN
;
2108 case bp_read_watchpoint
:
2109 if (ui_out_is_mi_like_p (uiout
))
2110 ui_out_field_string (uiout
, "reason", "read-watchpoint-trigger");
2111 mention (bs
->breakpoint_at
);
2112 ui_out_tuple_begin (uiout
, "value");
2113 ui_out_text (uiout
, "\nValue = ");
2114 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2115 ui_out_field_stream (uiout
, "value", stb
);
2116 ui_out_tuple_end (uiout
);
2117 ui_out_text (uiout
, "\n");
2118 return PRINT_UNKNOWN
;
2121 case bp_access_watchpoint
:
2122 if (bs
->old_val
!= NULL
)
2124 annotate_watchpoint (bs
->breakpoint_at
->number
);
2125 if (ui_out_is_mi_like_p (uiout
))
2126 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2127 mention (bs
->breakpoint_at
);
2128 ui_out_tuple_begin (uiout
, "value");
2129 ui_out_text (uiout
, "\nOld value = ");
2130 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2131 ui_out_field_stream (uiout
, "old", stb
);
2132 value_free (bs
->old_val
);
2134 ui_out_text (uiout
, "\nNew value = ");
2138 mention (bs
->breakpoint_at
);
2139 if (ui_out_is_mi_like_p (uiout
))
2140 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2141 ui_out_tuple_begin (uiout
, "value");
2142 ui_out_text (uiout
, "\nValue = ");
2144 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0,Val_pretty_default
);
2145 ui_out_field_stream (uiout
, "new", stb
);
2146 ui_out_tuple_end (uiout
);
2147 ui_out_text (uiout
, "\n");
2148 return PRINT_UNKNOWN
;
2151 /* Fall through, we don't deal with these types of breakpoints
2155 if (ui_out_is_mi_like_p (uiout
))
2156 ui_out_field_string (uiout
, "reason", "function-finished");
2157 return PRINT_UNKNOWN
;
2161 if (ui_out_is_mi_like_p (uiout
))
2162 ui_out_field_string (uiout
, "reason", "location-reached");
2163 return PRINT_UNKNOWN
;
2168 case bp_longjmp_resume
:
2169 case bp_step_resume
:
2170 case bp_through_sigtramp
:
2171 case bp_watchpoint_scope
:
2174 return PRINT_UNKNOWN
;
2178 /* Generic routine for printing messages indicating why we
2179 stopped. The behavior of this function depends on the value
2180 'print_it' in the bpstat structure. Under some circumstances we
2181 may decide not to print anything here and delegate the task to
2184 static enum print_stop_action
2185 print_bp_stop_message (bpstat bs
)
2187 switch (bs
->print_it
)
2190 /* Nothing should be printed for this bpstat entry. */
2191 return PRINT_UNKNOWN
;
2195 /* We still want to print the frame, but we already printed the
2196 relevant messages. */
2197 return PRINT_SRC_AND_LOC
;
2200 case print_it_normal
:
2201 /* Normal case, we handle everything in print_it_typical. */
2202 return print_it_typical (bs
);
2205 internal_error (__FILE__
, __LINE__
,
2206 "print_bp_stop_message: unrecognized enum value");
2211 /* Print a message indicating what happened. This is called from
2212 normal_stop(). The input to this routine is the head of the bpstat
2213 list - a list of the eventpoints that caused this stop. This
2214 routine calls the generic print routine for printing a message
2215 about reasons for stopping. This will print (for example) the
2216 "Breakpoint n," part of the output. The return value of this
2219 PRINT_UNKNOWN: Means we printed nothing
2220 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2221 code to print the location. An example is
2222 "Breakpoint 1, " which should be followed by
2224 PRINT_SRC_ONLY: Means we printed something, but there is no need
2225 to also print the location part of the message.
2226 An example is the catch/throw messages, which
2227 don't require a location appended to the end.
2228 PRINT_NOTHING: We have done some printing and we don't need any
2229 further info to be printed.*/
2231 enum print_stop_action
2232 bpstat_print (bpstat bs
)
2236 /* Maybe another breakpoint in the chain caused us to stop.
2237 (Currently all watchpoints go on the bpstat whether hit or not.
2238 That probably could (should) be changed, provided care is taken
2239 with respect to bpstat_explains_signal). */
2240 for (; bs
; bs
= bs
->next
)
2242 val
= print_bp_stop_message (bs
);
2243 if (val
== PRINT_SRC_ONLY
2244 || val
== PRINT_SRC_AND_LOC
2245 || val
== PRINT_NOTHING
)
2249 /* We reached the end of the chain, or we got a null BS to start
2250 with and nothing was printed. */
2251 return PRINT_UNKNOWN
;
2254 /* Evaluate the expression EXP and return 1 if value is zero.
2255 This is used inside a catch_errors to evaluate the breakpoint condition.
2256 The argument is a "struct expression *" that has been cast to char * to
2257 make it pass through catch_errors. */
2260 breakpoint_cond_eval (PTR exp
)
2262 struct value
*mark
= value_mark ();
2263 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2264 value_free_to_mark (mark
);
2268 /* Allocate a new bpstat and chain it to the current one. */
2271 bpstat_alloc (struct breakpoint
*b
, bpstat cbs
/* Current "bs" value */ )
2275 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2277 bs
->breakpoint_at
= b
;
2278 /* If the condition is false, etc., don't do the commands. */
2279 bs
->commands
= NULL
;
2281 bs
->print_it
= print_it_normal
;
2285 /* Possible return values for watchpoint_check (this can't be an enum
2286 because of check_errors). */
2287 /* The watchpoint has been deleted. */
2288 #define WP_DELETED 1
2289 /* The value has changed. */
2290 #define WP_VALUE_CHANGED 2
2291 /* The value has not changed. */
2292 #define WP_VALUE_NOT_CHANGED 3
2294 #define BP_TEMPFLAG 1
2295 #define BP_HARDWAREFLAG 2
2297 /* Check watchpoint condition. */
2300 watchpoint_check (PTR p
)
2302 bpstat bs
= (bpstat
) p
;
2303 struct breakpoint
*b
;
2304 struct frame_info
*fr
;
2305 int within_current_scope
;
2307 b
= bs
->breakpoint_at
;
2309 if (b
->exp_valid_block
== NULL
)
2310 within_current_scope
= 1;
2313 /* There is no current frame at this moment. If we're going to have
2314 any chance of handling watchpoints on local variables, we'll need
2315 the frame chain (so we can determine if we're in scope). */
2316 reinit_frame_cache ();
2317 fr
= frame_find_by_id (b
->watchpoint_frame
);
2318 within_current_scope
= (fr
!= NULL
);
2319 /* in_function_epilogue_p() returns a non-zero value if we're still
2320 in the function but the stack frame has already been invalidated.
2321 Since we can't rely on the values of local variables after the
2322 stack has been destroyed, we are treating the watchpoint in that
2323 state as `not changed' without further checking. */
2324 if (within_current_scope
&& fr
== get_current_frame ()
2325 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2326 return WP_VALUE_NOT_CHANGED
;
2327 if (within_current_scope
)
2328 /* If we end up stopping, the current frame will get selected
2329 in normal_stop. So this call to select_frame won't affect
2334 if (within_current_scope
)
2336 /* We use value_{,free_to_}mark because it could be a
2337 *long* time before we return to the command level and
2338 call free_all_values. We can't call free_all_values because
2339 we might be in the middle of evaluating a function call. */
2341 struct value
*mark
= value_mark ();
2342 struct value
*new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
2343 if (!value_equal (b
->val
, new_val
))
2345 release_value (new_val
);
2346 value_free_to_mark (mark
);
2347 bs
->old_val
= b
->val
;
2349 /* We will stop here */
2350 return WP_VALUE_CHANGED
;
2354 /* Nothing changed, don't do anything. */
2355 value_free_to_mark (mark
);
2356 /* We won't stop here */
2357 return WP_VALUE_NOT_CHANGED
;
2362 /* This seems like the only logical thing to do because
2363 if we temporarily ignored the watchpoint, then when
2364 we reenter the block in which it is valid it contains
2365 garbage (in the case of a function, it may have two
2366 garbage values, one before and one after the prologue).
2367 So we can't even detect the first assignment to it and
2368 watch after that (since the garbage may or may not equal
2369 the first value assigned). */
2370 /* We print all the stop information in print_it_typical(), but
2371 in this case, by the time we call print_it_typical() this bp
2372 will be deleted already. So we have no choice but print the
2373 information here. */
2374 if (ui_out_is_mi_like_p (uiout
))
2375 ui_out_field_string (uiout
, "reason", "watchpoint-scope");
2376 ui_out_text (uiout
, "\nWatchpoint ");
2377 ui_out_field_int (uiout
, "wpnum", bs
->breakpoint_at
->number
);
2378 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2379 which its expression is valid.\n");
2381 if (b
->related_breakpoint
)
2382 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2383 b
->disposition
= disp_del_at_next_stop
;
2389 /* Get a bpstat associated with having just stopped at address *PC
2390 and frame address CORE_ADDRESS. Update *PC to point at the
2391 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2392 if this is known to not be a real breakpoint (it could still be a
2393 watchpoint, though). */
2395 /* Determine whether we stopped at a breakpoint, etc, or whether we
2396 don't understand this stop. Result is a chain of bpstat's such that:
2398 if we don't understand the stop, the result is a null pointer.
2400 if we understand why we stopped, the result is not null.
2402 Each element of the chain refers to a particular breakpoint or
2403 watchpoint at which we have stopped. (We may have stopped for
2404 several reasons concurrently.)
2406 Each element of the chain has valid next, breakpoint_at,
2407 commands, FIXME??? fields. */
2410 bpstat_stop_status (CORE_ADDR
*pc
, int not_a_breakpoint
)
2412 register struct breakpoint
*b
, *temp
;
2414 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2415 int real_breakpoint
= 0;
2416 /* Root of the chain of bpstat's */
2417 struct bpstats root_bs
[1];
2418 /* Pointer to the last thing in the chain currently. */
2419 bpstat bs
= root_bs
;
2420 static char message1
[] =
2421 "Error evaluating expression for watchpoint %d\n";
2422 char message
[sizeof (message1
) + 30 /* slop */ ];
2424 /* Get the address where the breakpoint would have been.
2425 The "not_a_breakpoint" argument is meant to distinguish
2426 between a breakpoint trap event and a trace/singlestep
2427 trap event. For a trace/singlestep trap event, we would
2428 not want to subtract DECR_PC_AFTER_BREAK from the PC. */
2430 bp_addr
= *pc
- (not_a_breakpoint
&& !SOFTWARE_SINGLE_STEP_P () ?
2431 0 : DECR_PC_AFTER_BREAK
);
2433 ALL_BREAKPOINTS_SAFE (b
, temp
)
2435 if (b
->enable_state
== bp_disabled
2436 || b
->enable_state
== bp_shlib_disabled
2437 || b
->enable_state
== bp_call_disabled
)
2440 if (b
->type
!= bp_watchpoint
2441 && b
->type
!= bp_hardware_watchpoint
2442 && b
->type
!= bp_read_watchpoint
2443 && b
->type
!= bp_access_watchpoint
2444 && b
->type
!= bp_hardware_breakpoint
2445 && b
->type
!= bp_catch_fork
2446 && b
->type
!= bp_catch_vfork
2447 && b
->type
!= bp_catch_exec
2448 && b
->type
!= bp_catch_catch
2449 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2451 if (b
->address
!= bp_addr
) /* address doesn't match */
2453 if (overlay_debugging
/* unmapped overlay section */
2454 && section_is_overlay (b
->section
)
2455 && !section_is_mapped (b
->section
))
2459 if (b
->type
== bp_hardware_breakpoint
)
2461 if (b
->address
!= (*pc
- DECR_PC_AFTER_HW_BREAK
))
2463 if (overlay_debugging
/* unmapped overlay section */
2464 && section_is_overlay (b
->section
)
2465 && !section_is_mapped (b
->section
))
2469 /* Is this a catchpoint of a load or unload? If so, did we
2470 get a load or unload of the specified library? If not,
2472 if ((b
->type
== bp_catch_load
)
2473 #if defined(SOLIB_HAVE_LOAD_EVENT)
2474 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2475 || ((b
->dll_pathname
!= NULL
)
2476 && (strcmp (b
->dll_pathname
,
2477 SOLIB_LOADED_LIBRARY_PATHNAME (
2478 PIDGET (inferior_ptid
)))
2484 if ((b
->type
== bp_catch_unload
)
2485 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2486 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2487 || ((b
->dll_pathname
!= NULL
)
2488 && (strcmp (b
->dll_pathname
,
2489 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2490 PIDGET (inferior_ptid
)))
2496 if ((b
->type
== bp_catch_fork
)
2497 && !target_has_forked (PIDGET (inferior_ptid
),
2498 &b
->forked_inferior_pid
))
2501 if ((b
->type
== bp_catch_vfork
)
2502 && !target_has_vforked (PIDGET (inferior_ptid
),
2503 &b
->forked_inferior_pid
))
2506 if ((b
->type
== bp_catch_exec
)
2507 && !target_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2510 if (ep_is_exception_catchpoint (b
) &&
2511 !(current_exception_event
= target_get_current_exception_event ()))
2514 /* Come here if it's a watchpoint, or if the break address matches */
2516 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
2518 /* Watchpoints may change this, if not found to have triggered. */
2522 sprintf (message
, message1
, b
->number
);
2523 if (b
->type
== bp_watchpoint
||
2524 b
->type
== bp_hardware_watchpoint
)
2526 switch (catch_errors (watchpoint_check
, bs
, message
,
2530 /* We've already printed what needs to be printed. */
2531 /* Actually this is superfluous, because by the time we
2532 call print_it_typical() the wp will be already deleted,
2533 and the function will return immediately. */
2534 bs
->print_it
= print_it_done
;
2537 case WP_VALUE_CHANGED
:
2541 case WP_VALUE_NOT_CHANGED
:
2543 bs
->print_it
= print_it_noop
;
2550 /* Error from catch_errors. */
2551 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2552 if (b
->related_breakpoint
)
2553 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2554 b
->disposition
= disp_del_at_next_stop
;
2555 /* We've already printed what needs to be printed. */
2556 bs
->print_it
= print_it_done
;
2562 else if (b
->type
== bp_read_watchpoint
||
2563 b
->type
== bp_access_watchpoint
)
2569 addr
= target_stopped_data_address ();
2572 for (v
= b
->val_chain
; v
; v
= v
->next
)
2574 if (VALUE_LVAL (v
) == lval_memory
2575 && ! VALUE_LAZY (v
))
2577 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
2579 if (v
== b
->val_chain
2580 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2581 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2585 vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
2586 /* Exact match not required. Within range is
2588 if (addr
>= vaddr
&&
2589 addr
< vaddr
+ TYPE_LENGTH (VALUE_TYPE (v
)))
2595 switch (catch_errors (watchpoint_check
, bs
, message
,
2599 /* We've already printed what needs to be printed. */
2600 bs
->print_it
= print_it_done
;
2603 case WP_VALUE_CHANGED
:
2604 if (b
->type
== bp_read_watchpoint
)
2606 /* Don't stop: read watchpoints shouldn't fire if
2607 the value has changed. This is for targets which
2608 cannot set read-only watchpoints. */
2609 bs
->print_it
= print_it_noop
;
2615 case WP_VALUE_NOT_CHANGED
:
2622 /* Error from catch_errors. */
2623 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2624 if (b
->related_breakpoint
)
2625 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2626 b
->disposition
= disp_del_at_next_stop
;
2627 /* We've already printed what needs to be printed. */
2628 bs
->print_it
= print_it_done
;
2631 else /* found == 0 */
2633 /* This is a case where some watchpoint(s) triggered,
2634 but not at the address of this watchpoint (FOUND
2635 was left zero). So don't print anything for this
2637 bs
->print_it
= print_it_noop
;
2644 /* By definition, an encountered breakpoint is a triggered
2648 real_breakpoint
= 1;
2652 b
->frame
!= (get_current_frame ())->frame
)
2656 int value_is_zero
= 0;
2660 /* Need to select the frame, with all that implies
2661 so that the conditions will have the right context. */
2662 select_frame (get_current_frame ());
2664 = catch_errors (breakpoint_cond_eval
, (b
->cond
),
2665 "Error in testing breakpoint condition:\n",
2667 /* FIXME-someday, should give breakpoint # */
2670 if (b
->cond
&& value_is_zero
)
2673 /* Don't consider this a hit. */
2676 else if (b
->ignore_count
> 0)
2679 annotate_ignore_count_change ();
2684 /* We will stop here */
2685 if (b
->disposition
== disp_disable
)
2686 b
->enable_state
= bp_disabled
;
2687 bs
->commands
= b
->commands
;
2691 (STREQ ("silent", bs
->commands
->line
) ||
2692 (xdb_commands
&& STREQ ("Q", bs
->commands
->line
))))
2694 bs
->commands
= bs
->commands
->next
;
2699 /* Print nothing for this entry if we dont stop or if we dont print. */
2700 if (bs
->stop
== 0 || bs
->print
== 0)
2701 bs
->print_it
= print_it_noop
;
2704 bs
->next
= NULL
; /* Terminate the chain */
2705 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2707 if (real_breakpoint
&& bs
)
2709 if (bs
->breakpoint_at
->type
== bp_hardware_breakpoint
)
2711 if (DECR_PC_AFTER_HW_BREAK
!= 0)
2713 *pc
= *pc
- DECR_PC_AFTER_HW_BREAK
;
2719 if (DECR_PC_AFTER_BREAK
!= 0 || must_shift_inst_regs
)
2722 #if defined (SHIFT_INST_REGS)
2724 #else /* No SHIFT_INST_REGS. */
2726 #endif /* No SHIFT_INST_REGS. */
2731 /* The value of a hardware watchpoint hasn't changed, but the
2732 intermediate memory locations we are watching may have. */
2733 if (bs
&& !bs
->stop
&&
2734 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
2735 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
2736 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
2738 remove_breakpoints ();
2739 insert_breakpoints ();
2744 /* Tell what to do about this bpstat. */
2746 bpstat_what (bpstat bs
)
2748 /* Classify each bpstat as one of the following. */
2751 /* This bpstat element has no effect on the main_action. */
2754 /* There was a watchpoint, stop but don't print. */
2757 /* There was a watchpoint, stop and print. */
2760 /* There was a breakpoint but we're not stopping. */
2763 /* There was a breakpoint, stop but don't print. */
2766 /* There was a breakpoint, stop and print. */
2769 /* We hit the longjmp breakpoint. */
2772 /* We hit the longjmp_resume breakpoint. */
2775 /* We hit the step_resume breakpoint. */
2778 /* We hit the through_sigtramp breakpoint. */
2781 /* We hit the shared library event breakpoint. */
2784 /* We caught a shared library event. */
2787 /* This is just used to count how many enums there are. */
2791 /* Here is the table which drives this routine. So that we can
2792 format it pretty, we define some abbreviations for the
2793 enum bpstat_what codes. */
2794 #define kc BPSTAT_WHAT_KEEP_CHECKING
2795 #define ss BPSTAT_WHAT_STOP_SILENT
2796 #define sn BPSTAT_WHAT_STOP_NOISY
2797 #define sgl BPSTAT_WHAT_SINGLE
2798 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2799 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2800 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2801 #define sr BPSTAT_WHAT_STEP_RESUME
2802 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2803 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2804 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2806 /* "Can't happen." Might want to print an error message.
2807 abort() is not out of the question, but chances are GDB is just
2808 a bit confused, not unusable. */
2809 #define err BPSTAT_WHAT_STOP_NOISY
2811 /* Given an old action and a class, come up with a new action. */
2812 /* One interesting property of this table is that wp_silent is the same
2813 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2814 after stopping, the check for whether to step over a breakpoint
2815 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2816 reference to how we stopped. We retain separate wp_silent and
2817 bp_silent codes in case we want to change that someday.
2819 Another possibly interesting property of this table is that
2820 there's a partial ordering, priority-like, of the actions. Once
2821 you've decided that some action is appropriate, you'll never go
2822 back and decide something of a lower priority is better. The
2825 kc < clr sgl shl shlr slr sn sr ss ts
2826 sgl < clrs shl shlr slr sn sr ss ts
2827 slr < err shl shlr sn sr ss ts
2828 clr < clrs err shl shlr sn sr ss ts
2829 clrs < err shl shlr sn sr ss ts
2830 ss < shl shlr sn sr ts
2837 What I think this means is that we don't need a damned table
2838 here. If you just put the rows and columns in the right order,
2839 it'd look awfully regular. We could simply walk the bpstat list
2840 and choose the highest priority action we find, with a little
2841 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2842 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2843 is messy anyway). */
2845 /* step_resume entries: a step resume breakpoint overrides another
2846 breakpoint of signal handling (see comment in wait_for_inferior
2847 at first PC_IN_SIGTRAMP where we set the step_resume breakpoint). */
2848 /* We handle the through_sigtramp_breakpoint the same way; having both
2849 one of those and a step_resume_breakpoint is probably very rare (?). */
2851 static const enum bpstat_what_main_action
2852 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
2855 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2858 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, ts
, shl
, shlr
},
2860 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2862 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2864 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, ts
, shl
, shlr
},
2866 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2868 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2870 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, ts
, shl
, shlr
},
2872 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, ts
, shl
, shlr
},
2874 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, ts
, shl
, shlr
},
2876 {ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, shl
, shlr
},
2878 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, shl
, ts
, shl
, shlr
},
2880 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, ts
, shlr
, shlr
}
2895 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
2896 struct bpstat_what retval
;
2898 retval
.call_dummy
= 0;
2899 for (; bs
!= NULL
; bs
= bs
->next
)
2901 enum class bs_class
= no_effect
;
2902 if (bs
->breakpoint_at
== NULL
)
2903 /* I suspect this can happen if it was a momentary breakpoint
2904 which has since been deleted. */
2906 switch (bs
->breakpoint_at
->type
)
2912 case bp_hardware_breakpoint
:
2918 bs_class
= bp_noisy
;
2920 bs_class
= bp_silent
;
2923 bs_class
= bp_nostop
;
2926 case bp_hardware_watchpoint
:
2927 case bp_read_watchpoint
:
2928 case bp_access_watchpoint
:
2932 bs_class
= wp_noisy
;
2934 bs_class
= wp_silent
;
2937 /* There was a watchpoint, but we're not stopping.
2938 This requires no further action. */
2939 bs_class
= no_effect
;
2942 bs_class
= long_jump
;
2944 case bp_longjmp_resume
:
2945 bs_class
= long_resume
;
2947 case bp_step_resume
:
2950 bs_class
= step_resume
;
2953 /* It is for the wrong frame. */
2954 bs_class
= bp_nostop
;
2956 case bp_through_sigtramp
:
2957 bs_class
= through_sig
;
2959 case bp_watchpoint_scope
:
2960 bs_class
= bp_nostop
;
2962 case bp_shlib_event
:
2963 bs_class
= shlib_event
;
2965 case bp_thread_event
:
2966 case bp_overlay_event
:
2967 bs_class
= bp_nostop
;
2970 case bp_catch_unload
:
2971 /* Only if this catchpoint triggered should we cause the
2972 step-out-of-dld behaviour. Otherwise, we ignore this
2975 bs_class
= catch_shlib_event
;
2977 bs_class
= no_effect
;
2980 case bp_catch_vfork
:
2985 bs_class
= bp_noisy
;
2987 bs_class
= bp_silent
;
2990 /* There was a catchpoint, but we're not stopping.
2991 This requires no further action. */
2992 bs_class
= no_effect
;
2994 case bp_catch_catch
:
2995 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
2996 bs_class
= bp_nostop
;
2998 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3000 case bp_catch_throw
:
3001 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3002 bs_class
= bp_nostop
;
3004 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3007 /* Make sure the action is stop (silent or noisy),
3008 so infrun.c pops the dummy frame. */
3009 bs_class
= bp_silent
;
3010 retval
.call_dummy
= 1;
3013 current_action
= table
[(int) bs_class
][(int) current_action
];
3015 retval
.main_action
= current_action
;
3019 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3020 without hardware support). This isn't related to a specific bpstat,
3021 just to things like whether watchpoints are set. */
3024 bpstat_should_step (void)
3026 struct breakpoint
*b
;
3028 if (b
->enable_state
== bp_enabled
&& b
->type
== bp_watchpoint
)
3033 /* Nonzero if there are enabled hardware watchpoints. */
3035 bpstat_have_active_hw_watchpoints (void)
3037 struct breakpoint
*b
;
3039 if ((b
->enable_state
== bp_enabled
) &&
3041 ((b
->type
== bp_hardware_watchpoint
) ||
3042 (b
->type
== bp_read_watchpoint
) ||
3043 (b
->type
== bp_access_watchpoint
)))
3049 /* Given a bpstat that records zero or more triggered eventpoints, this
3050 function returns another bpstat which contains only the catchpoints
3051 on that first list, if any. */
3053 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3055 struct bpstats root_bs
[1];
3056 bpstat bs
= root_bs
;
3057 struct breakpoint
*ep
;
3060 bpstat_clear (cp_list
);
3061 root_bs
->next
= NULL
;
3063 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3065 /* Is this eventpoint a catchpoint? If not, ignore it. */
3066 ep
= ep_list
->breakpoint_at
;
3069 if ((ep
->type
!= bp_catch_load
) &&
3070 (ep
->type
!= bp_catch_unload
) &&
3071 (ep
->type
!= bp_catch_catch
) &&
3072 (ep
->type
!= bp_catch_throw
))
3073 /* pai: (temp) ADD fork/vfork here!! */
3076 /* Yes; add it to the list. */
3077 bs
= bpstat_alloc (ep
, bs
);
3082 #if defined(SOLIB_ADD)
3083 /* Also, for each triggered catchpoint, tag it with the name of
3084 the library that caused this trigger. (We copy the name now,
3085 because it's only guaranteed to be available NOW, when the
3086 catchpoint triggers. Clients who may wish to know the name
3087 later must get it from the catchpoint itself.) */
3088 if (ep
->triggered_dll_pathname
!= NULL
)
3089 xfree (ep
->triggered_dll_pathname
);
3090 if (ep
->type
== bp_catch_load
)
3091 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3092 PIDGET (inferior_ptid
));
3094 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3095 PIDGET (inferior_ptid
));
3097 dll_pathname
= NULL
;
3101 ep
->triggered_dll_pathname
= (char *)
3102 xmalloc (strlen (dll_pathname
) + 1);
3103 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3106 ep
->triggered_dll_pathname
= NULL
;
3112 /* Print B to gdb_stdout. */
3114 print_one_breakpoint (struct breakpoint
*b
,
3115 CORE_ADDR
*last_addr
)
3117 register struct command_line
*l
;
3118 register struct symbol
*sym
;
3119 struct ep_type_description
3124 static struct ep_type_description bptypes
[] =
3126 {bp_none
, "?deleted?"},
3127 {bp_breakpoint
, "breakpoint"},
3128 {bp_hardware_breakpoint
, "hw breakpoint"},
3129 {bp_until
, "until"},
3130 {bp_finish
, "finish"},
3131 {bp_watchpoint
, "watchpoint"},
3132 {bp_hardware_watchpoint
, "hw watchpoint"},
3133 {bp_read_watchpoint
, "read watchpoint"},
3134 {bp_access_watchpoint
, "acc watchpoint"},
3135 {bp_longjmp
, "longjmp"},
3136 {bp_longjmp_resume
, "longjmp resume"},
3137 {bp_step_resume
, "step resume"},
3138 {bp_through_sigtramp
, "sigtramp"},
3139 {bp_watchpoint_scope
, "watchpoint scope"},
3140 {bp_call_dummy
, "call dummy"},
3141 {bp_shlib_event
, "shlib events"},
3142 {bp_thread_event
, "thread events"},
3143 {bp_overlay_event
, "overlay events"},
3144 {bp_catch_load
, "catch load"},
3145 {bp_catch_unload
, "catch unload"},
3146 {bp_catch_fork
, "catch fork"},
3147 {bp_catch_vfork
, "catch vfork"},
3148 {bp_catch_exec
, "catch exec"},
3149 {bp_catch_catch
, "catch catch"},
3150 {bp_catch_throw
, "catch throw"}
3153 static char *bpdisps
[] =
3154 {"del", "dstp", "dis", "keep"};
3155 static char bpenables
[] = "nynny";
3156 char wrap_indent
[80];
3157 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3158 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3161 ui_out_tuple_begin (uiout
, "bkpt");
3165 ui_out_field_int (uiout
, "number", b
->number
);
3169 if (((int) b
->type
> (sizeof (bptypes
) / sizeof (bptypes
[0])))
3170 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3171 internal_error (__FILE__
, __LINE__
,
3172 "bptypes table does not describe type #%d.",
3174 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3178 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3182 ui_out_field_fmt (uiout
, "enabled", "%c", bpenables
[(int) b
->enable_state
]);
3183 ui_out_spaces (uiout
, 2);
3186 strcpy (wrap_indent
, " ");
3189 if (TARGET_ADDR_BIT
<= 32)
3190 strcat (wrap_indent
, " ");
3192 strcat (wrap_indent
, " ");
3197 internal_error (__FILE__
, __LINE__
,
3198 "print_one_breakpoint: bp_none encountered\n");
3202 case bp_hardware_watchpoint
:
3203 case bp_read_watchpoint
:
3204 case bp_access_watchpoint
:
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 print_expression (b
->exp
, stb
->stream
);
3212 ui_out_field_stream (uiout
, "what", stb
);
3216 case bp_catch_unload
:
3217 /* Field 4, the address, is omitted (which makes the columns
3218 not line up too nicely with the headers, but the effect
3219 is relatively readable). */
3221 ui_out_field_skip (uiout
, "addr");
3223 if (b
->dll_pathname
== NULL
)
3225 ui_out_field_string (uiout
, "what", "<any library>");
3226 ui_out_spaces (uiout
, 1);
3230 ui_out_text (uiout
, "library \"");
3231 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3232 ui_out_text (uiout
, "\" ");
3237 case bp_catch_vfork
:
3238 /* Field 4, the address, is omitted (which makes the columns
3239 not line up too nicely with the headers, but the effect
3240 is relatively readable). */
3242 ui_out_field_skip (uiout
, "addr");
3244 if (b
->forked_inferior_pid
!= 0)
3246 ui_out_text (uiout
, "process ");
3247 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3248 ui_out_spaces (uiout
, 1);
3252 /* Field 4, the address, is omitted (which makes the columns
3253 not line up too nicely with the headers, but the effect
3254 is relatively readable). */
3256 ui_out_field_skip (uiout
, "addr");
3258 if (b
->exec_pathname
!= NULL
)
3260 ui_out_text (uiout
, "program \"");
3261 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3262 ui_out_text (uiout
, "\" ");
3266 case bp_catch_catch
:
3267 /* Field 4, the address, is omitted (which makes the columns
3268 not line up too nicely with the headers, but the effect
3269 is relatively readable). */
3271 ui_out_field_skip (uiout
, "addr");
3273 ui_out_field_string (uiout
, "what", "exception catch");
3274 ui_out_spaces (uiout
, 1);
3277 case bp_catch_throw
:
3278 /* Field 4, the address, is omitted (which makes the columns
3279 not line up too nicely with the headers, but the effect
3280 is relatively readable). */
3282 ui_out_field_skip (uiout
, "addr");
3284 ui_out_field_string (uiout
, "what", "exception throw");
3285 ui_out_spaces (uiout
, 1);
3289 case bp_hardware_breakpoint
:
3293 case bp_longjmp_resume
:
3294 case bp_step_resume
:
3295 case bp_through_sigtramp
:
3296 case bp_watchpoint_scope
:
3298 case bp_shlib_event
:
3299 case bp_thread_event
:
3300 case bp_overlay_event
:
3304 ui_out_field_core_addr (uiout
, "addr", b
->address
);
3307 *last_addr
= b
->address
;
3310 sym
= find_pc_sect_function (b
->address
, b
->section
);
3313 ui_out_text (uiout
, "in ");
3314 ui_out_field_string (uiout
, "func",
3315 SYMBOL_SOURCE_NAME (sym
));
3316 ui_out_wrap_hint (uiout
, wrap_indent
);
3317 ui_out_text (uiout
, " at ");
3319 ui_out_field_string (uiout
, "file", b
->source_file
);
3320 ui_out_text (uiout
, ":");
3321 ui_out_field_int (uiout
, "line", b
->line_number
);
3325 print_address_symbolic (b
->address
, stb
->stream
, demangle
, "");
3326 ui_out_field_stream (uiout
, "at", stb
);
3331 if (b
->thread
!= -1)
3333 /* FIXME: This seems to be redundant and lost here; see the
3334 "stop only in" line a little further down. */
3335 ui_out_text (uiout
, " thread ");
3336 ui_out_field_int (uiout
, "thread", b
->thread
);
3339 ui_out_text (uiout
, "\n");
3344 ui_out_text (uiout
, "\tstop only in stack frame at ");
3345 ui_out_field_core_addr (uiout
, "frame", b
->frame
);
3346 ui_out_text (uiout
, "\n");
3352 ui_out_text (uiout
, "\tstop only if ");
3353 print_expression (b
->cond
, stb
->stream
);
3354 ui_out_field_stream (uiout
, "cond", stb
);
3355 ui_out_text (uiout
, "\n");
3358 if (b
->thread
!= -1)
3360 /* FIXME should make an annotation for this */
3361 ui_out_text (uiout
, "\tstop only in thread ");
3362 ui_out_field_int (uiout
, "thread", b
->thread
);
3363 ui_out_text (uiout
, "\n");
3366 if (show_breakpoint_hit_counts
&& b
->hit_count
)
3368 /* FIXME should make an annotation for this */
3369 if (ep_is_catchpoint (b
))
3370 ui_out_text (uiout
, "\tcatchpoint");
3372 ui_out_text (uiout
, "\tbreakpoint");
3373 ui_out_text (uiout
, " already hit ");
3374 ui_out_field_int (uiout
, "times", b
->hit_count
);
3375 if (b
->hit_count
== 1)
3376 ui_out_text (uiout
, " time\n");
3378 ui_out_text (uiout
, " times\n");
3381 /* Output the count also if it is zero, but only if this is
3382 mi. FIXME: Should have a better test for this. */
3383 if (ui_out_is_mi_like_p (uiout
))
3384 if (show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3385 ui_out_field_int (uiout
, "times", b
->hit_count
);
3387 if (b
->ignore_count
)
3390 ui_out_text (uiout
, "\tignore next ");
3391 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3392 ui_out_text (uiout
, " hits\n");
3395 if ((l
= b
->commands
))
3398 ui_out_tuple_begin (uiout
, "script");
3399 print_command_lines (uiout
, l
, 4);
3400 ui_out_tuple_end (uiout
);
3402 ui_out_tuple_end (uiout
);
3403 do_cleanups (old_chain
);
3406 struct captured_breakpoint_query_args
3412 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3414 struct captured_breakpoint_query_args
*args
= data
;
3415 register struct breakpoint
*b
;
3416 CORE_ADDR dummy_addr
= 0;
3419 if (args
->bnum
== b
->number
)
3421 print_one_breakpoint (b
, &dummy_addr
);
3429 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
)
3431 struct captured_breakpoint_query_args args
;
3433 /* For the moment we don't trust print_one_breakpoint() to not throw
3435 return catch_exceptions (uiout
, do_captured_breakpoint_query
, &args
,
3436 NULL
, RETURN_MASK_ALL
);
3439 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3440 catchpoints, et.al.). */
3443 user_settable_breakpoint (const struct breakpoint
*b
)
3445 return (b
->type
== bp_breakpoint
3446 || b
->type
== bp_catch_load
3447 || b
->type
== bp_catch_unload
3448 || b
->type
== bp_catch_fork
3449 || b
->type
== bp_catch_vfork
3450 || b
->type
== bp_catch_exec
3451 || b
->type
== bp_catch_catch
3452 || b
->type
== bp_catch_throw
3453 || b
->type
== bp_hardware_breakpoint
3454 || b
->type
== bp_watchpoint
3455 || b
->type
== bp_read_watchpoint
3456 || b
->type
== bp_access_watchpoint
3457 || b
->type
== bp_hardware_watchpoint
);
3460 /* Print information on user settable breakpoint (watchpoint, etc)
3461 number BNUM. If BNUM is -1 print all user settable breakpoints.
3462 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3465 breakpoint_1 (int bnum
, int allflag
)
3467 register struct breakpoint
*b
;
3468 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3469 int nr_printable_breakpoints
;
3471 /* Compute the number of rows in the table. */
3472 nr_printable_breakpoints
= 0;
3475 || bnum
== b
->number
)
3477 if (allflag
|| user_settable_breakpoint (b
))
3478 nr_printable_breakpoints
++;
3482 ui_out_table_begin (uiout
, 6, nr_printable_breakpoints
, "BreakpointTable");
3484 ui_out_table_begin (uiout
, 5, nr_printable_breakpoints
, "BreakpointTable");
3486 if (nr_printable_breakpoints
> 0)
3487 annotate_breakpoints_headers ();
3488 if (nr_printable_breakpoints
> 0)
3490 ui_out_table_header (uiout
, 3, ui_left
, "number", "Num"); /* 1 */
3491 if (nr_printable_breakpoints
> 0)
3493 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3494 if (nr_printable_breakpoints
> 0)
3496 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3497 if (nr_printable_breakpoints
> 0)
3499 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3502 if (nr_printable_breakpoints
> 0)
3504 if (TARGET_ADDR_BIT
<= 32)
3505 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3507 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3509 if (nr_printable_breakpoints
> 0)
3511 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3512 ui_out_table_body (uiout
);
3513 if (nr_printable_breakpoints
> 0)
3514 annotate_breakpoints_table ();
3518 || bnum
== b
->number
)
3520 /* We only print out user settable breakpoints unless the
3522 if (allflag
|| user_settable_breakpoint (b
))
3523 print_one_breakpoint (b
, &last_addr
);
3526 ui_out_table_end (uiout
);
3528 if (nr_printable_breakpoints
== 0)
3531 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3533 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3538 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3539 that a comparison of an unsigned with -1 is always false. */
3540 if (last_addr
!= (CORE_ADDR
) -1)
3541 set_next_address (last_addr
);
3544 /* FIXME? Should this be moved up so that it is only called when
3545 there have been breakpoints? */
3546 annotate_breakpoints_table_end ();
3551 breakpoints_info (char *bnum_exp
, int from_tty
)
3556 bnum
= parse_and_eval_long (bnum_exp
);
3558 breakpoint_1 (bnum
, 0);
3563 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3568 bnum
= parse_and_eval_long (bnum_exp
);
3570 breakpoint_1 (bnum
, 1);
3573 /* Print a message describing any breakpoints set at PC. */
3576 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
)
3578 register int others
= 0;
3579 register struct breakpoint
*b
;
3582 if (b
->address
== pc
) /* address match / overlay match */
3583 if (!overlay_debugging
|| b
->section
== section
)
3587 printf_filtered ("Note: breakpoint%s ", (others
> 1) ? "s" : "");
3589 if (b
->address
== pc
) /* address match / overlay match */
3590 if (!overlay_debugging
|| b
->section
== section
)
3593 printf_filtered ("%d%s%s ",
3595 ((b
->enable_state
== bp_disabled
||
3596 b
->enable_state
== bp_shlib_disabled
||
3597 b
->enable_state
== bp_call_disabled
)
3599 : b
->enable_state
== bp_permanent
3603 : ((others
== 1) ? " and" : ""));
3605 printf_filtered ("also set at pc ");
3606 print_address_numeric (pc
, 1, gdb_stdout
);
3607 printf_filtered (".\n");
3611 /* Set the default place to put a breakpoint
3612 for the `break' command with no arguments. */
3615 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3618 default_breakpoint_valid
= valid
;
3619 default_breakpoint_address
= addr
;
3620 default_breakpoint_symtab
= symtab
;
3621 default_breakpoint_line
= line
;
3624 /* Return true iff it is meaningful to use the address member of
3625 BPT. For some breakpoint types, the address member is irrelevant
3626 and it makes no sense to attempt to compare it to other addresses
3627 (or use it for any other purpose either).
3629 More specifically, each of the following breakpoint types will always
3630 have a zero valued address and we don't want check_duplicates() to mark
3631 breakpoints of any of these types to be a duplicate of an actual
3632 breakpoint at address zero:
3635 bp_hardware_watchpoint
3637 bp_access_watchpoint
3644 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3646 enum bptype type
= bpt
->type
;
3648 return (type
!= bp_watchpoint
3649 && type
!= bp_hardware_watchpoint
3650 && type
!= bp_read_watchpoint
3651 && type
!= bp_access_watchpoint
3652 && type
!= bp_catch_exec
3653 && type
!= bp_longjmp_resume
3654 && type
!= bp_catch_fork
3655 && type
!= bp_catch_vfork
);
3658 /* Rescan breakpoints at the same address and section as BPT,
3659 marking the first one as "first" and any others as "duplicates".
3660 This is so that the bpt instruction is only inserted once.
3661 If we have a permanent breakpoint at the same place as BPT, make
3662 that one the official one, and the rest as duplicates. */
3665 check_duplicates (struct breakpoint
*bpt
)
3667 register struct breakpoint
*b
;
3668 register int count
= 0;
3669 struct breakpoint
*perm_bp
= 0;
3670 CORE_ADDR address
= bpt
->address
;
3671 asection
*section
= bpt
->section
;
3673 if (! breakpoint_address_is_meaningful (bpt
))
3677 if (b
->enable_state
!= bp_disabled
3678 && b
->enable_state
!= bp_shlib_disabled
3679 && b
->enable_state
!= bp_call_disabled
3680 && b
->address
== address
/* address / overlay match */
3681 && (!overlay_debugging
|| b
->section
== section
)
3682 && breakpoint_address_is_meaningful (b
))
3684 /* Have we found a permanent breakpoint? */
3685 if (b
->enable_state
== bp_permanent
)
3692 b
->duplicate
= count
> 1;
3695 /* If we found a permanent breakpoint at this address, go over the
3696 list again and declare all the other breakpoints there to be the
3700 perm_bp
->duplicate
= 0;
3702 /* Permanent breakpoint should always be inserted. */
3703 if (! perm_bp
->inserted
)
3704 internal_error (__FILE__
, __LINE__
,
3705 "allegedly permanent breakpoint is not "
3706 "actually inserted");
3712 internal_error (__FILE__
, __LINE__
,
3713 "another breakpoint was inserted on top of "
3714 "a permanent breakpoint");
3716 if (b
->enable_state
!= bp_disabled
3717 && b
->enable_state
!= bp_shlib_disabled
3718 && b
->enable_state
!= bp_call_disabled
3719 && b
->address
== address
/* address / overlay match */
3720 && (!overlay_debugging
|| b
->section
== section
)
3721 && breakpoint_address_is_meaningful (b
))
3727 /* set_raw_breakpoint() is a low level routine for allocating and
3728 partially initializing a breakpoint of type BPTYPE. The newly
3729 created breakpoint's address, section, source file name, and line
3730 number are provided by SAL. The newly created and partially
3731 initialized breakpoint is added to the breakpoint chain and
3732 is also returned as the value of this function.
3734 It is expected that the caller will complete the initialization of
3735 the newly created breakpoint struct as well as output any status
3736 information regarding the creation of a new breakpoint. In
3737 particular, set_raw_breakpoint() does NOT set the breakpoint
3738 number! Care should be taken to not allow an error() to occur
3739 prior to completing the initialization of the breakpoint. If this
3740 should happen, a bogus breakpoint will be left on the chain. */
3743 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
3745 register struct breakpoint
*b
, *b1
;
3747 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
3748 memset (b
, 0, sizeof (*b
));
3749 b
->address
= sal
.pc
;
3750 if (sal
.symtab
== NULL
)
3751 b
->source_file
= NULL
;
3753 b
->source_file
= savestring (sal
.symtab
->filename
,
3754 strlen (sal
.symtab
->filename
));
3755 b
->section
= sal
.section
;
3757 b
->language
= current_language
->la_language
;
3758 b
->input_radix
= input_radix
;
3760 b
->line_number
= sal
.line
;
3761 b
->enable_state
= bp_enabled
;
3764 b
->ignore_count
= 0;
3767 b
->dll_pathname
= NULL
;
3768 b
->triggered_dll_pathname
= NULL
;
3769 b
->forked_inferior_pid
= 0;
3770 b
->exec_pathname
= NULL
;
3772 /* Add this breakpoint to the end of the chain
3773 so that a list of breakpoints will come out in order
3774 of increasing numbers. */
3776 b1
= breakpoint_chain
;
3778 breakpoint_chain
= b
;
3786 check_duplicates (b
);
3787 breakpoints_changed ();
3793 /* Note that the breakpoint object B describes a permanent breakpoint
3794 instruction, hard-wired into the inferior's code. */
3796 make_breakpoint_permanent (struct breakpoint
*b
)
3798 b
->enable_state
= bp_permanent
;
3800 /* By definition, permanent breakpoints are already present in the code. */
3804 static struct breakpoint
*
3805 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
3807 static int internal_breakpoint_number
= -1;
3808 struct symtab_and_line sal
;
3809 struct breakpoint
*b
;
3811 INIT_SAL (&sal
); /* initialize to zeroes */
3814 sal
.section
= find_pc_overlay (sal
.pc
);
3816 b
= set_raw_breakpoint (sal
, type
);
3817 b
->number
= internal_breakpoint_number
--;
3818 b
->disposition
= disp_donttouch
;
3825 create_longjmp_breakpoint (char *func_name
)
3827 struct breakpoint
*b
;
3828 struct minimal_symbol
*m
;
3830 if (func_name
== NULL
)
3831 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
3834 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
, NULL
)) == NULL
)
3837 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
3840 b
->enable_state
= bp_disabled
;
3843 b
->addr_string
= xstrdup (func_name
);
3846 /* Call this routine when stepping and nexting to enable a breakpoint
3847 if we do a longjmp(). When we hit that breakpoint, call
3848 set_longjmp_resume_breakpoint() to figure out where we are going. */
3851 enable_longjmp_breakpoint (void)
3853 register struct breakpoint
*b
;
3856 if (b
->type
== bp_longjmp
)
3858 b
->enable_state
= bp_enabled
;
3859 check_duplicates (b
);
3864 disable_longjmp_breakpoint (void)
3866 register struct breakpoint
*b
;
3869 if (b
->type
== bp_longjmp
3870 || b
->type
== bp_longjmp_resume
)
3872 b
->enable_state
= bp_disabled
;
3873 check_duplicates (b
);
3878 create_overlay_event_breakpoint (char *func_name
)
3880 struct breakpoint
*b
;
3881 struct minimal_symbol
*m
;
3883 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
, NULL
)) == NULL
)
3886 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
3888 b
->addr_string
= xstrdup (func_name
);
3890 if (overlay_debugging
== ovly_auto
)
3892 b
->enable_state
= bp_enabled
;
3893 overlay_events_enabled
= 1;
3897 b
->enable_state
= bp_disabled
;
3898 overlay_events_enabled
= 0;
3903 enable_overlay_breakpoints (void)
3905 register struct breakpoint
*b
;
3908 if (b
->type
== bp_overlay_event
)
3910 b
->enable_state
= bp_enabled
;
3911 check_duplicates (b
);
3912 overlay_events_enabled
= 1;
3917 disable_overlay_breakpoints (void)
3919 register struct breakpoint
*b
;
3922 if (b
->type
== bp_overlay_event
)
3924 b
->enable_state
= bp_disabled
;
3925 check_duplicates (b
);
3926 overlay_events_enabled
= 0;
3931 create_thread_event_breakpoint (CORE_ADDR address
)
3933 struct breakpoint
*b
;
3934 char addr_string
[80]; /* Surely an addr can't be longer than that. */
3936 b
= create_internal_breakpoint (address
, bp_thread_event
);
3938 b
->enable_state
= bp_enabled
;
3939 /* addr_string has to be used or breakpoint_re_set will delete me. */
3940 sprintf (addr_string
, "*0x%s", paddr (b
->address
));
3941 b
->addr_string
= xstrdup (addr_string
);
3947 remove_thread_event_breakpoints (void)
3949 struct breakpoint
*b
, *temp
;
3951 ALL_BREAKPOINTS_SAFE (b
, temp
)
3952 if (b
->type
== bp_thread_event
)
3953 delete_breakpoint (b
);
3958 remove_solib_event_breakpoints (void)
3960 register struct breakpoint
*b
, *temp
;
3962 ALL_BREAKPOINTS_SAFE (b
, temp
)
3963 if (b
->type
== bp_shlib_event
)
3964 delete_breakpoint (b
);
3968 create_solib_event_breakpoint (CORE_ADDR address
)
3970 struct breakpoint
*b
;
3972 b
= create_internal_breakpoint (address
, bp_shlib_event
);
3976 /* Disable any breakpoints that are on code in shared libraries. Only
3977 apply to enabled breakpoints, disabled ones can just stay disabled. */
3980 disable_breakpoints_in_shlibs (int silent
)
3982 struct breakpoint
*b
;
3983 int disabled_shlib_breaks
= 0;
3985 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
3988 #if defined (PC_SOLIB)
3989 if (((b
->type
== bp_breakpoint
) ||
3990 (b
->type
== bp_hardware_breakpoint
)) &&
3991 b
->enable_state
== bp_enabled
&&
3993 PC_SOLIB (b
->address
))
3995 b
->enable_state
= bp_shlib_disabled
;
3998 if (!disabled_shlib_breaks
)
4000 target_terminal_ours_for_output ();
4001 warning ("Temporarily disabling shared library breakpoints:");
4003 disabled_shlib_breaks
= 1;
4004 warning ("breakpoint #%d ", b
->number
);
4011 /* Try to reenable any breakpoints in shared libraries. */
4013 re_enable_breakpoints_in_shlibs (void)
4015 struct breakpoint
*b
;
4018 if (b
->enable_state
== bp_shlib_disabled
)
4022 /* Do not reenable the breakpoint if the shared library
4023 is still not mapped in. */
4024 if (target_read_memory (b
->address
, buf
, 1) == 0)
4025 b
->enable_state
= bp_enabled
;
4032 solib_load_unload_1 (char *hookname
, int tempflag
, char *dll_pathname
,
4033 char *cond_string
, enum bptype bp_kind
)
4035 struct breakpoint
*b
;
4036 struct symtabs_and_lines sals
;
4037 struct cleanup
*old_chain
;
4038 struct cleanup
*canonical_strings_chain
= NULL
;
4039 char *addr_start
= hookname
;
4040 char *addr_end
= NULL
;
4041 char **canonical
= (char **) NULL
;
4042 int thread
= -1; /* All threads. */
4044 /* Set a breakpoint on the specified hook. */
4045 sals
= decode_line_1 (&hookname
, 1, (struct symtab
*) NULL
, 0, &canonical
);
4046 addr_end
= hookname
;
4048 if (sals
.nelts
== 0)
4050 warning ("Unable to set a breakpoint on dynamic linker callback.");
4051 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4052 warning ("GDB will be unable to track shl_load/shl_unload calls");
4055 if (sals
.nelts
!= 1)
4057 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4058 warning ("GDB will be unable to track shl_load/shl_unload calls");
4062 /* Make sure that all storage allocated in decode_line_1 gets freed
4063 in case the following errors out. */
4064 old_chain
= make_cleanup (xfree
, sals
.sals
);
4065 if (canonical
!= (char **) NULL
)
4067 make_cleanup (xfree
, canonical
);
4068 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
4069 if (canonical
[0] != NULL
)
4070 make_cleanup (xfree
, canonical
[0]);
4073 resolve_sal_pc (&sals
.sals
[0]);
4075 /* Remove the canonical strings from the cleanup, they are needed below. */
4076 if (canonical
!= (char **) NULL
)
4077 discard_cleanups (canonical_strings_chain
);
4079 b
= set_raw_breakpoint (sals
.sals
[0], bp_kind
);
4080 set_breakpoint_count (breakpoint_count
+ 1);
4081 b
->number
= breakpoint_count
;
4083 b
->cond_string
= (cond_string
== NULL
) ?
4084 NULL
: savestring (cond_string
, strlen (cond_string
));
4087 if (canonical
!= (char **) NULL
&& canonical
[0] != NULL
)
4088 b
->addr_string
= canonical
[0];
4089 else if (addr_start
)
4090 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
4092 b
->enable_state
= bp_enabled
;
4093 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4095 if (dll_pathname
== NULL
)
4096 b
->dll_pathname
= NULL
;
4099 b
->dll_pathname
= (char *) xmalloc (strlen (dll_pathname
) + 1);
4100 strcpy (b
->dll_pathname
, dll_pathname
);
4104 do_cleanups (old_chain
);
4108 create_solib_load_event_breakpoint (char *hookname
, int tempflag
,
4109 char *dll_pathname
, char *cond_string
)
4111 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4112 cond_string
, bp_catch_load
);
4116 create_solib_unload_event_breakpoint (char *hookname
, int tempflag
,
4117 char *dll_pathname
, char *cond_string
)
4119 solib_load_unload_1 (hookname
,tempflag
, dll_pathname
,
4120 cond_string
, bp_catch_unload
);
4124 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4125 enum bptype bp_kind
)
4127 struct symtab_and_line sal
;
4128 struct breakpoint
*b
;
4129 int thread
= -1; /* All threads. */
4136 b
= set_raw_breakpoint (sal
, bp_kind
);
4137 set_breakpoint_count (breakpoint_count
+ 1);
4138 b
->number
= breakpoint_count
;
4140 b
->cond_string
= (cond_string
== NULL
) ?
4141 NULL
: savestring (cond_string
, strlen (cond_string
));
4143 b
->addr_string
= NULL
;
4144 b
->enable_state
= bp_enabled
;
4145 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4146 b
->forked_inferior_pid
= 0;
4152 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4154 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4158 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4160 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4164 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4166 struct symtab_and_line sal
;
4167 struct breakpoint
*b
;
4168 int thread
= -1; /* All threads. */
4175 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4176 set_breakpoint_count (breakpoint_count
+ 1);
4177 b
->number
= breakpoint_count
;
4179 b
->cond_string
= (cond_string
== NULL
) ?
4180 NULL
: savestring (cond_string
, strlen (cond_string
));
4182 b
->addr_string
= NULL
;
4183 b
->enable_state
= bp_enabled
;
4184 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4190 hw_breakpoint_used_count (void)
4192 register struct breakpoint
*b
;
4197 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4205 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4207 register struct breakpoint
*b
;
4210 *other_type_used
= 0;
4213 if (b
->enable_state
== bp_enabled
)
4215 if (b
->type
== type
)
4217 else if ((b
->type
== bp_hardware_watchpoint
||
4218 b
->type
== bp_read_watchpoint
||
4219 b
->type
== bp_access_watchpoint
)
4220 && b
->enable_state
== bp_enabled
)
4221 *other_type_used
= 1;
4227 /* Call this after hitting the longjmp() breakpoint. Use this to set
4228 a new breakpoint at the target of the jmp_buf.
4230 FIXME - This ought to be done by setting a temporary breakpoint
4231 that gets deleted automatically... */
4234 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_info
*frame
)
4236 register struct breakpoint
*b
;
4239 if (b
->type
== bp_longjmp_resume
)
4242 b
->enable_state
= bp_enabled
;
4244 b
->frame
= frame
->frame
;
4247 check_duplicates (b
);
4253 disable_watchpoints_before_interactive_call_start (void)
4255 struct breakpoint
*b
;
4259 if (((b
->type
== bp_watchpoint
)
4260 || (b
->type
== bp_hardware_watchpoint
)
4261 || (b
->type
== bp_read_watchpoint
)
4262 || (b
->type
== bp_access_watchpoint
)
4263 || ep_is_exception_catchpoint (b
))
4264 && (b
->enable_state
== bp_enabled
))
4266 b
->enable_state
= bp_call_disabled
;
4267 check_duplicates (b
);
4273 enable_watchpoints_after_interactive_call_stop (void)
4275 struct breakpoint
*b
;
4279 if (((b
->type
== bp_watchpoint
)
4280 || (b
->type
== bp_hardware_watchpoint
)
4281 || (b
->type
== bp_read_watchpoint
)
4282 || (b
->type
== bp_access_watchpoint
)
4283 || ep_is_exception_catchpoint (b
))
4284 && (b
->enable_state
== bp_call_disabled
))
4286 b
->enable_state
= bp_enabled
;
4287 check_duplicates (b
);
4293 /* Set a breakpoint that will evaporate an end of command
4294 at address specified by SAL.
4295 Restrict it to frame FRAME if FRAME is nonzero. */
4298 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_info
*frame
,
4301 register struct breakpoint
*b
;
4302 b
= set_raw_breakpoint (sal
, type
);
4303 b
->enable_state
= bp_enabled
;
4304 b
->disposition
= disp_donttouch
;
4305 b
->frame
= (frame
? frame
->frame
: 0);
4307 /* If we're debugging a multi-threaded program, then we
4308 want momentary breakpoints to be active in only a
4309 single thread of control. */
4310 if (in_thread_list (inferior_ptid
))
4311 b
->thread
= pid_to_thread_id (inferior_ptid
);
4317 /* Tell the user we have just set a breakpoint B. */
4320 mention (struct breakpoint
*b
)
4323 struct cleanup
*old_chain
;
4324 struct ui_stream
*stb
;
4326 stb
= ui_out_stream_new (uiout
);
4327 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4329 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4330 watchpoint) other than breakpoint creation. It should be possible to
4331 clean this up and at the same time replace the random calls to
4332 breakpoint_changed with this hook, as has already been done for
4333 delete_breakpoint_hook and so on. */
4334 if (create_breakpoint_hook
)
4335 create_breakpoint_hook (b
);
4336 breakpoint_create_event (b
->number
);
4341 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b
->number
);
4344 ui_out_text (uiout
, "Watchpoint ");
4345 ui_out_tuple_begin (uiout
, "wpt");
4346 ui_out_field_int (uiout
, "number", b
->number
);
4347 ui_out_text (uiout
, ": ");
4348 print_expression (b
->exp
, stb
->stream
);
4349 ui_out_field_stream (uiout
, "exp", stb
);
4350 ui_out_tuple_end (uiout
);
4352 case bp_hardware_watchpoint
:
4353 ui_out_text (uiout
, "Hardware watchpoint ");
4354 ui_out_tuple_begin (uiout
, "wpt");
4355 ui_out_field_int (uiout
, "number", b
->number
);
4356 ui_out_text (uiout
, ": ");
4357 print_expression (b
->exp
, stb
->stream
);
4358 ui_out_field_stream (uiout
, "exp", stb
);
4359 ui_out_tuple_end (uiout
);
4361 case bp_read_watchpoint
:
4362 ui_out_text (uiout
, "Hardware read watchpoint ");
4363 ui_out_tuple_begin (uiout
, "hw-rwpt");
4364 ui_out_field_int (uiout
, "number", b
->number
);
4365 ui_out_text (uiout
, ": ");
4366 print_expression (b
->exp
, stb
->stream
);
4367 ui_out_field_stream (uiout
, "exp", stb
);
4368 ui_out_tuple_end (uiout
);
4370 case bp_access_watchpoint
:
4371 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4372 ui_out_tuple_begin (uiout
, "hw-awpt");
4373 ui_out_field_int (uiout
, "number", b
->number
);
4374 ui_out_text (uiout
, ": ");
4375 print_expression (b
->exp
, stb
->stream
);
4376 ui_out_field_stream (uiout
, "exp", stb
);
4377 ui_out_tuple_end (uiout
);
4380 if (ui_out_is_mi_like_p (uiout
))
4385 printf_filtered ("Breakpoint %d", b
->number
);
4388 case bp_hardware_breakpoint
:
4389 if (ui_out_is_mi_like_p (uiout
))
4394 printf_filtered ("Hardware assisted breakpoint %d", b
->number
);
4398 case bp_catch_unload
:
4399 printf_filtered ("Catchpoint %d (%s %s)",
4401 (b
->type
== bp_catch_load
) ? "load" : "unload",
4402 (b
->dll_pathname
!= NULL
) ?
4403 b
->dll_pathname
: "<any library>");
4406 case bp_catch_vfork
:
4407 printf_filtered ("Catchpoint %d (%s)",
4409 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4412 printf_filtered ("Catchpoint %d (exec)",
4415 case bp_catch_catch
:
4416 case bp_catch_throw
:
4417 printf_filtered ("Catchpoint %d (%s)",
4419 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4425 case bp_longjmp_resume
:
4426 case bp_step_resume
:
4427 case bp_through_sigtramp
:
4429 case bp_watchpoint_scope
:
4430 case bp_shlib_event
:
4431 case bp_thread_event
:
4432 case bp_overlay_event
:
4437 if (addressprint
|| b
->source_file
== NULL
)
4439 printf_filtered (" at ");
4440 print_address_numeric (b
->address
, 1, gdb_stdout
);
4443 printf_filtered (": file %s, line %d.",
4444 b
->source_file
, b
->line_number
);
4446 do_cleanups (old_chain
);
4447 if (ui_out_is_mi_like_p (uiout
))
4449 printf_filtered ("\n");
4453 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4454 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4455 COND[i] and COND_STRING[i] values.
4457 NOTE: If the function succeeds, the caller is expected to cleanup
4458 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4459 array contents). If the function fails (error() is called), the
4460 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4461 COND and SALS arrays and each of those arrays contents. */
4464 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
4465 struct expression
**cond
, char **cond_string
,
4466 enum bptype type
, enum bpdisp disposition
,
4467 int thread
, int ignore_count
, int from_tty
)
4469 if (type
== bp_hardware_breakpoint
)
4471 int i
= hw_breakpoint_used_count ();
4472 int target_resources_ok
=
4473 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4475 if (target_resources_ok
== 0)
4476 error ("No hardware breakpoint support in the target.");
4477 else if (target_resources_ok
< 0)
4478 error ("Hardware breakpoints used exceeds limit.");
4481 /* Now set all the breakpoints. */
4484 for (i
= 0; i
< sals
.nelts
; i
++)
4486 struct breakpoint
*b
;
4487 struct symtab_and_line sal
= sals
.sals
[i
];
4490 describe_other_breakpoints (sal
.pc
, sal
.section
);
4492 b
= set_raw_breakpoint (sal
, type
);
4493 set_breakpoint_count (breakpoint_count
+ 1);
4494 b
->number
= breakpoint_count
;
4497 b
->addr_string
= addr_string
[i
];
4498 b
->cond_string
= cond_string
[i
];
4499 b
->ignore_count
= ignore_count
;
4500 b
->enable_state
= bp_enabled
;
4501 b
->disposition
= disposition
;
4507 /* Parse ARG which is assumed to be a SAL specification possibly
4508 followed by conditionals. On return, SALS contains an array of SAL
4509 addresses found. ADDR_STRING contains a vector of (canonical)
4510 address strings. ARG points to the end of the SAL. */
4513 parse_breakpoint_sals (char **address
,
4514 struct symtabs_and_lines
*sals
,
4515 char ***addr_string
)
4517 char *addr_start
= *address
;
4518 *addr_string
= NULL
;
4519 /* If no arg given, or if first arg is 'if ', use the default
4521 if ((*address
) == NULL
4522 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
4524 if (default_breakpoint_valid
)
4526 struct symtab_and_line sal
;
4527 INIT_SAL (&sal
); /* initialize to zeroes */
4528 sals
->sals
= (struct symtab_and_line
*)
4529 xmalloc (sizeof (struct symtab_and_line
));
4530 sal
.pc
= default_breakpoint_address
;
4531 sal
.line
= default_breakpoint_line
;
4532 sal
.symtab
= default_breakpoint_symtab
;
4533 sal
.section
= find_pc_overlay (sal
.pc
);
4534 sals
->sals
[0] = sal
;
4538 error ("No default breakpoint address now.");
4542 /* Force almost all breakpoints to be in terms of the
4543 current_source_symtab (which is decode_line_1's default). This
4544 should produce the results we want almost all of the time while
4545 leaving default_breakpoint_* alone. */
4546 if (default_breakpoint_valid
4547 && (!current_source_symtab
4548 || (strchr ("+-", (*address
)[0]) != NULL
)))
4549 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
4550 default_breakpoint_line
, addr_string
);
4552 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0, addr_string
);
4554 /* For any SAL that didn't have a canonical string, fill one in. */
4555 if (sals
->nelts
> 0 && *addr_string
== NULL
)
4556 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
4557 if (addr_start
!= (*address
))
4560 for (i
= 0; i
< sals
->nelts
; i
++)
4562 /* Add the string if not present. */
4563 if ((*addr_string
)[i
] == NULL
)
4564 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
4570 /* Convert each SAL into a real PC. Verify that the PC can be
4571 inserted as a breakpoint. If it can't throw an error. */
4574 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
4578 for (i
= 0; i
< sals
->nelts
; i
++)
4580 resolve_sal_pc (&sals
->sals
[i
]);
4582 /* It's possible for the PC to be nonzero, but still an illegal
4583 value on some targets.
4585 For example, on HP-UX if you start gdb, and before running the
4586 inferior you try to set a breakpoint on a shared library function
4587 "foo" where the inferior doesn't call "foo" directly but does
4588 pass its address to another function call, then we do find a
4589 minimal symbol for the "foo", but it's address is invalid.
4590 (Appears to be an index into a table that the loader sets up
4591 when the inferior is run.)
4593 Give the target a chance to bless sals.sals[i].pc before we
4594 try to make a breakpoint for it. */
4595 if (PC_REQUIRES_RUN_BEFORE_USE (sals
->sals
[i
].pc
))
4597 if (address
== NULL
)
4598 error ("Cannot break without a running program.");
4600 error ("Cannot break on %s without a running program.",
4606 /* Set a breakpoint according to ARG (function, linenum or *address)
4607 flag: first bit : 0 non-temporary, 1 temporary.
4608 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4611 break_command_1 (char *arg
, int flag
, int from_tty
)
4613 int tempflag
, hardwareflag
;
4614 struct symtabs_and_lines sals
;
4615 register struct expression
**cond
= 0;
4616 /* Pointers in arg to the start, and one past the end, of the
4618 char **cond_string
= (char **) NULL
;
4619 char *addr_start
= arg
;
4621 struct cleanup
*old_chain
;
4622 struct cleanup
*breakpoint_chain
= NULL
;
4625 int ignore_count
= 0;
4627 hardwareflag
= flag
& BP_HARDWAREFLAG
;
4628 tempflag
= flag
& BP_TEMPFLAG
;
4633 parse_breakpoint_sals (&arg
, &sals
, &addr_string
);
4638 /* Create a chain of things that always need to be cleaned up. */
4639 old_chain
= make_cleanup (null_cleanup
, 0);
4641 /* Make sure that all storage allocated to SALS gets freed. */
4642 make_cleanup (xfree
, sals
.sals
);
4644 /* Cleanup the addr_string array but not its contents. */
4645 make_cleanup (xfree
, addr_string
);
4647 /* Allocate space for all the cond expressions. */
4648 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4649 make_cleanup (xfree
, cond
);
4651 /* Allocate space for all the cond strings. */
4652 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4653 make_cleanup (xfree
, cond_string
);
4655 /* ----------------------------- SNIP -----------------------------
4656 Anything added to the cleanup chain beyond this point is assumed
4657 to be part of a breakpoint. If the breakpoint create succeeds
4658 then the memory is not reclaimed. */
4659 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4661 /* Mark the contents of the addr_string for cleanup. These go on
4662 the breakpoint_chain and only occure if the breakpoint create
4664 for (i
= 0; i
< sals
.nelts
; i
++)
4666 if (addr_string
[i
] != NULL
)
4667 make_cleanup (xfree
, addr_string
[i
]);
4670 /* Resolve all line numbers to PC's and verify that the addresses
4671 are ok for the target. */
4672 breakpoint_sals_to_pc (&sals
, addr_start
);
4674 /* Verify that condition can be parsed, before setting any
4675 breakpoints. Allocate a separate condition expression for each
4677 thread
= -1; /* No specific thread yet */
4678 for (i
= 0; i
< sals
.nelts
; i
++)
4685 char *cond_start
= NULL
;
4686 char *cond_end
= NULL
;
4687 while (*tok
== ' ' || *tok
== '\t')
4692 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
4695 toklen
= end_tok
- tok
;
4697 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
4699 tok
= cond_start
= end_tok
+ 1;
4700 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4701 make_cleanup (xfree
, cond
[i
]);
4703 cond_string
[i
] = savestring (cond_start
, cond_end
- cond_start
);
4704 make_cleanup (xfree
, cond_string
[i
]);
4706 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
4712 thread
= strtol (tok
, &tok
, 0);
4714 error ("Junk after thread keyword.");
4715 if (!valid_thread_id (thread
))
4716 error ("Unknown thread %d\n", thread
);
4719 error ("Junk at end of arguments.");
4723 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4724 hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4725 tempflag
? disp_del
: disp_donttouch
,
4726 thread
, ignore_count
, from_tty
);
4730 warning ("Multiple breakpoints were set.");
4731 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4733 /* That's it. Discard the cleanups for data inserted into the
4735 discard_cleanups (breakpoint_chain
);
4736 /* But cleanup everything else. */
4737 do_cleanups (old_chain
);
4740 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4741 linenum or *address) with COND and IGNORE_COUNT. */
4743 struct captured_breakpoint_args
4754 do_captured_breakpoint (void *data
)
4756 struct captured_breakpoint_args
*args
= data
;
4757 struct symtabs_and_lines sals
;
4758 register struct expression
**cond
;
4759 struct cleanup
*old_chain
;
4760 struct cleanup
*breakpoint_chain
= NULL
;
4767 /* Parse the source and lines spec. Delay check that the expression
4768 didn't contain trailing garbage until after cleanups are in
4772 address_end
= args
->address
;
4774 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
);
4779 /* Create a chain of things at always need to be cleaned up. */
4780 old_chain
= make_cleanup (null_cleanup
, 0);
4782 /* Always have a addr_string array, even if it is empty. */
4783 make_cleanup (xfree
, addr_string
);
4785 /* Make sure that all storage allocated to SALS gets freed. */
4786 make_cleanup (xfree
, sals
.sals
);
4788 /* Allocate space for all the cond expressions. */
4789 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4790 make_cleanup (xfree
, cond
);
4792 /* Allocate space for all the cond strings. */
4793 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4794 make_cleanup (xfree
, cond_string
);
4796 /* ----------------------------- SNIP -----------------------------
4797 Anything added to the cleanup chain beyond this point is assumed
4798 to be part of a breakpoint. If the breakpoint create goes
4799 through then that memory is not cleaned up. */
4800 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4802 /* Mark the contents of the addr_string for cleanup. These go on
4803 the breakpoint_chain and only occure if the breakpoint create
4805 for (i
= 0; i
< sals
.nelts
; i
++)
4807 if (addr_string
[i
] != NULL
)
4808 make_cleanup (xfree
, addr_string
[i
]);
4811 /* Wait until now before checking for garbage at the end of the
4812 address. That way cleanups can take care of freeing any
4814 if (*address_end
!= '\0')
4815 error ("Garbage %s following breakpoint address", address_end
);
4817 /* Resolve all line numbers to PC's. */
4818 breakpoint_sals_to_pc (&sals
, args
->address
);
4820 /* Verify that conditions can be parsed, before setting any
4822 for (i
= 0; i
< sals
.nelts
; i
++)
4824 if (args
->condition
!= NULL
)
4826 char *tok
= args
->condition
;
4827 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4829 error ("Garbage %s follows condition", tok
);
4830 make_cleanup (xfree
, cond
[i
]);
4831 cond_string
[i
] = xstrdup (args
->condition
);
4835 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4836 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4837 args
->tempflag
? disp_del
: disp_donttouch
,
4838 args
->thread
, args
->ignore_count
, 0/*from-tty*/);
4840 /* That's it. Discard the cleanups for data inserted into the
4842 discard_cleanups (breakpoint_chain
);
4843 /* But cleanup everything else. */
4844 do_cleanups (old_chain
);
4849 gdb_breakpoint (char *address
, char *condition
,
4850 int hardwareflag
, int tempflag
,
4851 int thread
, int ignore_count
)
4853 struct captured_breakpoint_args args
;
4854 args
.address
= address
;
4855 args
.condition
= condition
;
4856 args
.hardwareflag
= hardwareflag
;
4857 args
.tempflag
= tempflag
;
4858 args
.thread
= thread
;
4859 args
.ignore_count
= ignore_count
;
4860 return catch_errors (do_captured_breakpoint
, &args
,
4861 NULL
, RETURN_MASK_ALL
);
4866 break_at_finish_at_depth_command_1 (char *arg
, int flag
, int from_tty
)
4868 struct frame_info
*frame
;
4869 CORE_ADDR low
, high
, selected_pc
= 0;
4870 char *extra_args
= NULL
;
4873 int extra_args_len
= 0, if_arg
= 0;
4876 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
4879 if (default_breakpoint_valid
)
4883 selected_pc
= selected_frame
->pc
;
4888 error ("No selected frame.");
4891 error ("No default breakpoint address now.");
4895 extra_args
= strchr (arg
, ' ');
4899 extra_args_len
= strlen (extra_args
);
4900 level_arg
= (char *) xmalloc (extra_args
- arg
);
4901 strncpy (level_arg
, arg
, extra_args
- arg
- 1);
4902 level_arg
[extra_args
- arg
- 1] = '\0';
4906 level_arg
= (char *) xmalloc (strlen (arg
) + 1);
4907 strcpy (level_arg
, arg
);
4910 frame
= parse_frame_specification (level_arg
);
4912 selected_pc
= frame
->pc
;
4919 extra_args_len
= strlen (arg
);
4924 if (find_pc_partial_function (selected_pc
, (char **) NULL
, &low
, &high
))
4926 addr_string
= (char *) xmalloc (26 + extra_args_len
);
4928 sprintf (addr_string
, "*0x%s %s", paddr_nz (high
), extra_args
);
4930 sprintf (addr_string
, "*0x%s", paddr_nz (high
));
4931 break_command_1 (addr_string
, flag
, from_tty
);
4932 xfree (addr_string
);
4935 error ("No function contains the specified address");
4938 error ("Unable to set breakpoint at procedure exit");
4943 break_at_finish_command_1 (char *arg
, int flag
, int from_tty
)
4945 char *addr_string
, *break_string
, *beg_addr_string
;
4946 CORE_ADDR low
, high
;
4947 struct symtabs_and_lines sals
;
4948 struct symtab_and_line sal
;
4949 struct cleanup
*old_chain
;
4950 char *extra_args
= NULL
;
4951 int extra_args_len
= 0;
4955 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
4957 if (default_breakpoint_valid
)
4961 addr_string
= (char *) xmalloc (15);
4962 sprintf (addr_string
, "*0x%s", paddr_nz (selected_frame
->pc
));
4967 error ("No selected frame.");
4970 error ("No default breakpoint address now.");
4974 addr_string
= (char *) xmalloc (strlen (arg
) + 1);
4975 strcpy (addr_string
, arg
);
4981 extra_args_len
= strlen (arg
);
4985 /* get the stuff after the function name or address */
4986 extra_args
= strchr (arg
, ' ');
4990 extra_args_len
= strlen (extra_args
);
4997 beg_addr_string
= addr_string
;
4998 sals
= decode_line_1 (&addr_string
, 1, (struct symtab
*) NULL
, 0,
5001 xfree (beg_addr_string
);
5002 old_chain
= make_cleanup (xfree
, sals
.sals
);
5003 for (i
= 0; (i
< sals
.nelts
); i
++)
5006 if (find_pc_partial_function (sal
.pc
, (char **) NULL
, &low
, &high
))
5008 break_string
= (char *) xmalloc (extra_args_len
+ 26);
5010 sprintf (break_string
, "*0x%s %s", paddr_nz (high
), extra_args
);
5012 sprintf (break_string
, "*0x%s", paddr_nz (high
));
5013 break_command_1 (break_string
, flag
, from_tty
);
5014 xfree (break_string
);
5017 error ("No function contains the specified address");
5021 warning ("Multiple breakpoints were set.\n");
5022 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5024 do_cleanups (old_chain
);
5028 /* Helper function for break_command_1 and disassemble_command. */
5031 resolve_sal_pc (struct symtab_and_line
*sal
)
5035 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5037 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5038 error ("No line %d in file \"%s\".",
5039 sal
->line
, sal
->symtab
->filename
);
5043 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5045 struct blockvector
*bv
;
5050 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5053 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5054 sym
= block_function (b
);
5057 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5058 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5062 /* It really is worthwhile to have the section, so we'll just
5063 have to look harder. This case can be executed if we have
5064 line numbers but no functions (as can happen in assembly
5067 struct minimal_symbol
*msym
;
5069 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5071 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5078 break_command (char *arg
, int from_tty
)
5080 break_command_1 (arg
, 0, from_tty
);
5084 break_at_finish_command (char *arg
, int from_tty
)
5086 break_at_finish_command_1 (arg
, 0, from_tty
);
5090 break_at_finish_at_depth_command (char *arg
, int from_tty
)
5092 break_at_finish_at_depth_command_1 (arg
, 0, from_tty
);
5096 tbreak_command (char *arg
, int from_tty
)
5098 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5102 tbreak_at_finish_command (char *arg
, int from_tty
)
5104 break_at_finish_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5108 hbreak_command (char *arg
, int from_tty
)
5110 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5114 thbreak_command (char *arg
, int from_tty
)
5116 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5120 stop_command (char *arg
, int from_tty
)
5122 printf_filtered ("Specify the type of breakpoint to set.\n\
5123 Usage: stop in <function | address>\n\
5128 stopin_command (char *arg
, int from_tty
)
5132 if (arg
== (char *) NULL
)
5134 else if (*arg
!= '*')
5139 /* look for a ':'. If this is a line number specification, then
5140 say it is bad, otherwise, it should be an address or
5141 function/method name */
5142 while (*argptr
&& !hasColon
)
5144 hasColon
= (*argptr
== ':');
5149 badInput
= (*argptr
!= ':'); /* Not a class::method */
5151 badInput
= isdigit (*arg
); /* a simple line number */
5155 printf_filtered ("Usage: stop in <function | address>\n");
5157 break_command_1 (arg
, 0, from_tty
);
5161 stopat_command (char *arg
, int from_tty
)
5165 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5172 /* look for a ':'. If there is a '::' then get out, otherwise
5173 it is probably a line number. */
5174 while (*argptr
&& !hasColon
)
5176 hasColon
= (*argptr
== ':');
5181 badInput
= (*argptr
== ':'); /* we have class::method */
5183 badInput
= !isdigit (*arg
); /* not a line number */
5187 printf_filtered ("Usage: stop at <line>\n");
5189 break_command_1 (arg
, 0, from_tty
);
5193 /* accessflag: hw_write: watch write,
5194 hw_read: watch read,
5195 hw_access: watch access (read or write) */
5197 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5199 struct breakpoint
*b
;
5200 struct symtab_and_line sal
;
5201 struct expression
*exp
;
5202 struct block
*exp_valid_block
;
5203 struct value
*val
, *mark
;
5204 struct frame_info
*frame
;
5205 struct frame_info
*prev_frame
= NULL
;
5206 char *exp_start
= NULL
;
5207 char *exp_end
= NULL
;
5208 char *tok
, *end_tok
;
5210 char *cond_start
= NULL
;
5211 char *cond_end
= NULL
;
5212 struct expression
*cond
= NULL
;
5213 int i
, other_type_used
, target_resources_ok
= 0;
5214 enum bptype bp_type
;
5217 INIT_SAL (&sal
); /* initialize to zeroes */
5219 /* Parse arguments. */
5220 innermost_block
= NULL
;
5222 exp
= parse_exp_1 (&arg
, 0, 0);
5224 exp_valid_block
= innermost_block
;
5225 mark
= value_mark ();
5226 val
= evaluate_expression (exp
);
5227 release_value (val
);
5228 if (VALUE_LAZY (val
))
5229 value_fetch_lazy (val
);
5232 while (*tok
== ' ' || *tok
== '\t')
5236 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5239 toklen
= end_tok
- tok
;
5240 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5242 tok
= cond_start
= end_tok
+ 1;
5243 cond
= parse_exp_1 (&tok
, 0, 0);
5247 error ("Junk at end of command.");
5249 if (accessflag
== hw_read
)
5250 bp_type
= bp_read_watchpoint
;
5251 else if (accessflag
== hw_access
)
5252 bp_type
= bp_access_watchpoint
;
5254 bp_type
= bp_hardware_watchpoint
;
5256 mem_cnt
= can_use_hardware_watchpoint (val
);
5257 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5258 error ("Expression cannot be implemented with read/access watchpoint.");
5261 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5262 target_resources_ok
=
5263 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5265 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5266 error ("Target does not support this type of hardware watchpoint.");
5268 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5269 error ("Target can only support one kind of HW watchpoint at a time.");
5272 #if defined(HPUXHPPA)
5273 /* On HP-UX if you set a h/w
5274 watchpoint before the "run" command, the inferior dies with a e.g.,
5275 SIGILL once you start it. I initially believed this was due to a
5276 bad interaction between page protection traps and the initial
5277 startup sequence by the dynamic linker.
5279 However, I tried avoiding that by having HP-UX's implementation of
5280 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5281 yet, which forced slow watches before a "run" or "attach", and it
5282 still fails somewhere in the startup code.
5284 Until I figure out what's happening, I'm disallowing watches altogether
5285 before the "run" or "attach" command. We'll tell the user they must
5286 set watches after getting the program started. */
5287 if (!target_has_execution
)
5289 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5292 #endif /* HPUXHPPA */
5294 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5295 watchpoint could not be set. */
5296 if (!mem_cnt
|| target_resources_ok
<= 0)
5297 bp_type
= bp_watchpoint
;
5299 /* Now set up the breakpoint. */
5300 b
= set_raw_breakpoint (sal
, bp_type
);
5301 set_breakpoint_count (breakpoint_count
+ 1);
5302 b
->number
= breakpoint_count
;
5303 b
->disposition
= disp_donttouch
;
5305 b
->exp_valid_block
= exp_valid_block
;
5306 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5310 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5314 frame
= block_innermost_frame (exp_valid_block
);
5317 prev_frame
= get_prev_frame (frame
);
5318 get_frame_id (frame
, &b
->watchpoint_frame
);
5322 memset (&b
->watchpoint_frame
, 0, sizeof (b
->watchpoint_frame
));
5325 /* If the expression is "local", then set up a "watchpoint scope"
5326 breakpoint at the point where we've left the scope of the watchpoint
5328 if (innermost_block
)
5332 struct breakpoint
*scope_breakpoint
;
5333 struct symtab_and_line scope_sal
;
5335 INIT_SAL (&scope_sal
); /* initialize to zeroes */
5336 scope_sal
.pc
= get_frame_pc (prev_frame
);
5337 scope_sal
.section
= find_pc_overlay (scope_sal
.pc
);
5339 scope_breakpoint
= set_raw_breakpoint (scope_sal
,
5340 bp_watchpoint_scope
);
5341 set_breakpoint_count (breakpoint_count
+ 1);
5342 scope_breakpoint
->number
= breakpoint_count
;
5344 scope_breakpoint
->enable_state
= bp_enabled
;
5346 /* Automatically delete the breakpoint when it hits. */
5347 scope_breakpoint
->disposition
= disp_del
;
5349 /* Only break in the proper frame (help with recursion). */
5350 scope_breakpoint
->frame
= prev_frame
->frame
;
5352 /* Set the address at which we will stop. */
5353 scope_breakpoint
->address
= get_frame_pc (prev_frame
);
5355 /* The scope breakpoint is related to the watchpoint. We
5356 will need to act on them together. */
5357 b
->related_breakpoint
= scope_breakpoint
;
5360 value_free_to_mark (mark
);
5364 /* Return count of locations need to be watched and can be handled
5365 in hardware. If the watchpoint can not be handled
5366 in hardware return zero. */
5368 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5369 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5370 ((BYTE_SIZE) <= (REGISTER_SIZE))
5373 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5374 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5375 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5379 can_use_hardware_watchpoint (struct value
*v
)
5381 int found_memory_cnt
= 0;
5382 struct value
*head
= v
;
5384 /* Did the user specifically forbid us to use hardware watchpoints? */
5385 if (!can_use_hw_watchpoints
)
5388 /* Make sure that the value of the expression depends only upon
5389 memory contents, and values computed from them within GDB. If we
5390 find any register references or function calls, we can't use a
5391 hardware watchpoint.
5393 The idea here is that evaluating an expression generates a series
5394 of values, one holding the value of every subexpression. (The
5395 expression a*b+c has five subexpressions: a, b, a*b, c, and
5396 a*b+c.) GDB's values hold almost enough information to establish
5397 the criteria given above --- they identify memory lvalues,
5398 register lvalues, computed values, etcetera. So we can evaluate
5399 the expression, and then scan the chain of values that leaves
5400 behind to decide whether we can detect any possible change to the
5401 expression's final value using only hardware watchpoints.
5403 However, I don't think that the values returned by inferior
5404 function calls are special in any way. So this function may not
5405 notice that an expression involving an inferior function call
5406 can't be watched with hardware watchpoints. FIXME. */
5407 for (; v
; v
= v
->next
)
5409 if (VALUE_LVAL (v
) == lval_memory
)
5412 /* A lazy memory lvalue is one that GDB never needed to fetch;
5413 we either just used its address (e.g., `a' in `a.b') or
5414 we never needed it at all (e.g., `a' in `a,b'). */
5418 /* Ahh, memory we actually used! Check if we can cover
5419 it with hardware watchpoints. */
5420 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
5422 /* We only watch structs and arrays if user asked for it
5423 explicitly, never if they just happen to appear in a
5424 middle of some value chain. */
5426 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5427 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5429 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
5430 int len
= TYPE_LENGTH (VALUE_TYPE (v
));
5432 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5439 else if (v
->lval
!= not_lval
&& v
->modifiable
== 0)
5440 return 0; /* ??? What does this represent? */
5441 else if (v
->lval
== lval_register
)
5442 return 0; /* cannot watch a register with a HW watchpoint */
5445 /* The expression itself looks suitable for using a hardware
5446 watchpoint, but give the target machine a chance to reject it. */
5447 return found_memory_cnt
;
5451 watch_command_wrapper (char *arg
, int from_tty
)
5453 watch_command (arg
, from_tty
);
5457 watch_command (char *arg
, int from_tty
)
5459 watch_command_1 (arg
, hw_write
, from_tty
);
5463 rwatch_command_wrapper (char *arg
, int from_tty
)
5465 rwatch_command (arg
, from_tty
);
5469 rwatch_command (char *arg
, int from_tty
)
5471 watch_command_1 (arg
, hw_read
, from_tty
);
5475 awatch_command_wrapper (char *arg
, int from_tty
)
5477 awatch_command (arg
, from_tty
);
5481 awatch_command (char *arg
, int from_tty
)
5483 watch_command_1 (arg
, hw_access
, from_tty
);
5487 /* Helper routines for the until_command routine in infcmd.c. Here
5488 because it uses the mechanisms of breakpoints. */
5490 /* This function is called by fetch_inferior_event via the
5491 cmd_continuation pointer, to complete the until command. It takes
5492 care of cleaning up the temporary breakpoints set up by the until
5495 until_break_command_continuation (struct continuation_arg
*arg
)
5497 struct cleanup
*cleanups
;
5499 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
5500 do_exec_cleanups (cleanups
);
5505 until_break_command (char *arg
, int from_tty
)
5507 struct symtabs_and_lines sals
;
5508 struct symtab_and_line sal
;
5509 struct frame_info
*prev_frame
= get_prev_frame (selected_frame
);
5510 struct breakpoint
*breakpoint
;
5511 struct cleanup
*old_chain
;
5512 struct continuation_arg
*arg1
;
5515 clear_proceed_status ();
5517 /* Set a breakpoint where the user wants it and at return from
5520 if (default_breakpoint_valid
)
5521 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
5522 default_breakpoint_line
, (char ***) NULL
);
5524 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
5525 0, (char ***) NULL
);
5527 if (sals
.nelts
!= 1)
5528 error ("Couldn't get information on specified line.");
5531 xfree (sals
.sals
); /* malloc'd, so freed */
5534 error ("Junk at end of arguments.");
5536 resolve_sal_pc (&sal
);
5538 breakpoint
= set_momentary_breakpoint (sal
, selected_frame
, bp_until
);
5540 if (!event_loop_p
|| !target_can_async_p ())
5541 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
5543 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
5545 /* If we are running asynchronously, and the target supports async
5546 execution, we are not waiting for the target to stop, in the call
5547 tp proceed, below. This means that we cannot delete the
5548 brekpoints until the target has actually stopped. The only place
5549 where we get a chance to do that is in fetch_inferior_event, so
5550 we must set things up for that. */
5552 if (event_loop_p
&& target_can_async_p ())
5554 /* In this case the arg for the continuation is just the point
5555 in the exec_cleanups chain from where to start doing
5556 cleanups, because all the continuation does is the cleanups in
5557 the exec_cleanup_chain. */
5559 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
5561 arg1
->data
.pointer
= old_chain
;
5563 add_continuation (until_break_command_continuation
, arg1
);
5566 /* Keep within the current frame */
5570 sal
= find_pc_line (prev_frame
->pc
, 0);
5571 sal
.pc
= prev_frame
->pc
;
5572 breakpoint
= set_momentary_breakpoint (sal
, prev_frame
, bp_until
);
5573 if (!event_loop_p
|| !target_can_async_p ())
5574 make_cleanup_delete_breakpoint (breakpoint
);
5576 make_exec_cleanup_delete_breakpoint (breakpoint
);
5579 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
5580 /* Do the cleanups now, anly if we are not running asynchronously,
5581 of if we are, but the target is still synchronous. */
5582 if (!event_loop_p
|| !target_can_async_p ())
5583 do_cleanups (old_chain
);
5587 /* These aren't used; I don't konw what they were for. */
5588 /* Set a breakpoint at the catch clause for NAME. */
5590 catch_breakpoint (char *name
)
5595 disable_catch_breakpoint (void)
5600 delete_catch_breakpoint (void)
5605 enable_catch_breakpoint (void)
5612 struct sal_chain
*next
;
5613 struct symtab_and_line sal
;
5617 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5618 had been commented out in the v.4.16 sources, and stays
5619 disabled there now because "catch NAME" syntax isn't allowed.
5621 /* This isn't used; I don't know what it was for. */
5622 /* For each catch clause identified in ARGS, run FUNCTION
5623 with that clause as an argument. */
5624 static struct symtabs_and_lines
5625 map_catch_names (char *args
, int (*function
) ())
5627 register char *p
= args
;
5629 struct symtabs_and_lines sals
;
5631 struct sal_chain
*sal_chain
= 0;
5635 error_no_arg ("one or more catch names");
5643 /* Don't swallow conditional part. */
5644 if (p1
[0] == 'i' && p1
[1] == 'f'
5645 && (p1
[2] == ' ' || p1
[2] == '\t'))
5651 while (isalnum (*p1
) || *p1
== '_' || *p1
== '$')
5655 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
5656 error ("Arguments must be catch names.");
5662 struct sal_chain
*next
= (struct sal_chain
*)
5663 alloca (sizeof (struct sal_chain
));
5664 next
->next
= sal_chain
;
5665 next
->sal
= get_catch_sal (p
);
5670 printf_unfiltered ("No catch clause for exception %s.\n", p
);
5675 while (*p
== ' ' || *p
== '\t')
5681 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5683 static struct symtabs_and_lines
5684 get_catch_sals (int this_level_only
)
5686 register struct blockvector
*bl
;
5687 register struct block
*block
;
5688 int index
, have_default
= 0;
5690 struct symtabs_and_lines sals
;
5691 struct sal_chain
*sal_chain
= 0;
5692 char *blocks_searched
;
5694 /* Not sure whether an error message is always the correct response,
5695 but it's better than a core dump. */
5696 if (selected_frame
== NULL
)
5697 error ("No selected frame.");
5698 block
= get_frame_block (selected_frame
, 0);
5699 pc
= selected_frame
->pc
;
5705 error ("No symbol table info available.\n");
5707 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
5708 blocks_searched
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
5709 memset (blocks_searched
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
5713 CORE_ADDR end
= BLOCK_END (block
) - 4;
5716 if (bl
!= blockvector_for_pc (end
, &index
))
5717 error ("blockvector blotch");
5718 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
5719 error ("blockvector botch");
5720 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
5723 /* Don't print out blocks that have gone by. */
5724 while (index
< last_index
5725 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
5728 while (index
< last_index
5729 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
5731 if (blocks_searched
[index
] == 0)
5733 struct block
*b
= BLOCKVECTOR_BLOCK (bl
, index
);
5735 register struct symbol
*sym
;
5737 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
5739 if (STREQ (SYMBOL_NAME (sym
), "default"))
5745 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
5747 struct sal_chain
*next
= (struct sal_chain
*)
5748 alloca (sizeof (struct sal_chain
));
5749 next
->next
= sal_chain
;
5750 next
->sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
),
5755 blocks_searched
[index
] = 1;
5761 if (sal_chain
&& this_level_only
)
5764 /* After handling the function's top-level block, stop.
5765 Don't continue to its superblock, the block of
5766 per-file symbols. */
5767 if (BLOCK_FUNCTION (block
))
5769 block
= BLOCK_SUPERBLOCK (block
);
5774 struct sal_chain
*tmp_chain
;
5776 /* Count the number of entries. */
5777 for (index
= 0, tmp_chain
= sal_chain
; tmp_chain
;
5778 tmp_chain
= tmp_chain
->next
)
5782 sals
.sals
= (struct symtab_and_line
*)
5783 xmalloc (index
* sizeof (struct symtab_and_line
));
5784 for (index
= 0; sal_chain
; sal_chain
= sal_chain
->next
, index
++)
5785 sals
.sals
[index
] = sal_chain
->sal
;
5792 ep_skip_leading_whitespace (char **s
)
5794 if ((s
== NULL
) || (*s
== NULL
))
5796 while (isspace (**s
))
5800 /* This function examines a string, and attempts to find a token
5801 that might be an event name in the leading characters. If a
5802 possible match is found, a pointer to the last character of
5803 the token is returned. Else, NULL is returned. */
5806 ep_find_event_name_end (char *arg
)
5809 char *event_name_end
= NULL
;
5811 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5815 /* We break out of the loop when we find a token delimiter.
5816 Basically, we're looking for alphanumerics and underscores;
5817 anything else delimites the token. */
5820 if (!isalnum (*s
) && (*s
!= '_'))
5826 return event_name_end
;
5830 /* This function attempts to parse an optional "if <cond>" clause
5831 from the arg string. If one is not found, it returns NULL.
5833 Else, it returns a pointer to the condition string. (It does not
5834 attempt to evaluate the string against a particular block.) And,
5835 it updates arg to point to the first character following the parsed
5836 if clause in the arg string. */
5839 ep_parse_optional_if_clause (char **arg
)
5843 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
5846 /* Skip the "if" keyword. */
5849 /* Skip any extra leading whitespace, and record the start of the
5850 condition string. */
5851 ep_skip_leading_whitespace (arg
);
5854 /* Assume that the condition occupies the remainder of the arg string. */
5855 (*arg
) += strlen (cond_string
);
5860 /* This function attempts to parse an optional filename from the arg
5861 string. If one is not found, it returns NULL.
5863 Else, it returns a pointer to the parsed filename. (This function
5864 makes no attempt to verify that a file of that name exists, or is
5865 accessible.) And, it updates arg to point to the first character
5866 following the parsed filename in the arg string.
5868 Note that clients needing to preserve the returned filename for
5869 future access should copy it to their own buffers. */
5871 ep_parse_optional_filename (char **arg
)
5873 static char filename
[1024];
5878 if ((*arg_p
== '\0') || isspace (*arg_p
))
5896 /* Commands to deal with catching events, such as signals, exceptions,
5897 process start/exit, etc. */
5901 catch_fork
, catch_vfork
5905 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5906 static void catch_fork_command_1 (catch_fork_kind fork_kind
,
5907 char *arg
, int tempflag
, int from_tty
);
5910 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
5913 char *cond_string
= NULL
;
5915 ep_skip_leading_whitespace (&arg
);
5917 /* The allowed syntax is:
5919 catch [v]fork if <cond>
5921 First, check if there's an if clause. */
5922 cond_string
= ep_parse_optional_if_clause (&arg
);
5924 if ((*arg
!= '\0') && !isspace (*arg
))
5925 error ("Junk at end of arguments.");
5927 /* If this target supports it, create a fork or vfork catchpoint
5928 and enable reporting of such events. */
5932 create_fork_event_catchpoint (tempflag
, cond_string
);
5935 create_vfork_event_catchpoint (tempflag
, cond_string
);
5938 error ("unsupported or unknown fork kind; cannot catch it");
5944 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5946 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
5948 char *cond_string
= NULL
;
5950 ep_skip_leading_whitespace (&arg
);
5952 /* The allowed syntax is:
5954 catch exec if <cond>
5956 First, check if there's an if clause. */
5957 cond_string
= ep_parse_optional_if_clause (&arg
);
5959 if ((*arg
!= '\0') && !isspace (*arg
))
5960 error ("Junk at end of arguments.");
5962 /* If this target supports it, create an exec catchpoint
5963 and enable reporting of such events. */
5964 create_exec_event_catchpoint (tempflag
, cond_string
);
5968 #if defined(SOLIB_ADD)
5970 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
5972 char *dll_pathname
= NULL
;
5973 char *cond_string
= NULL
;
5975 ep_skip_leading_whitespace (&arg
);
5977 /* The allowed syntax is:
5979 catch load if <cond>
5980 catch load <filename>
5981 catch load <filename> if <cond>
5983 The user is not allowed to specify the <filename> after an
5986 We'll ignore the pathological case of a file named "if".
5988 First, check if there's an if clause. If so, then there
5989 cannot be a filename. */
5990 cond_string
= ep_parse_optional_if_clause (&arg
);
5992 /* If there was an if clause, then there cannot be a filename.
5993 Else, there might be a filename and an if clause. */
5994 if (cond_string
== NULL
)
5996 dll_pathname
= ep_parse_optional_filename (&arg
);
5997 ep_skip_leading_whitespace (&arg
);
5998 cond_string
= ep_parse_optional_if_clause (&arg
);
6001 if ((*arg
!= '\0') && !isspace (*arg
))
6002 error ("Junk at end of arguments.");
6004 /* Create a load breakpoint that only triggers when a load of
6005 the specified dll (or any dll, if no pathname was specified)
6007 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6008 dll_pathname
, cond_string
);
6012 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6014 char *dll_pathname
= NULL
;
6015 char *cond_string
= NULL
;
6017 ep_skip_leading_whitespace (&arg
);
6019 /* The allowed syntax is:
6021 catch unload if <cond>
6022 catch unload <filename>
6023 catch unload <filename> if <cond>
6025 The user is not allowed to specify the <filename> after an
6028 We'll ignore the pathological case of a file named "if".
6030 First, check if there's an if clause. If so, then there
6031 cannot be a filename. */
6032 cond_string
= ep_parse_optional_if_clause (&arg
);
6034 /* If there was an if clause, then there cannot be a filename.
6035 Else, there might be a filename and an if clause. */
6036 if (cond_string
== NULL
)
6038 dll_pathname
= ep_parse_optional_filename (&arg
);
6039 ep_skip_leading_whitespace (&arg
);
6040 cond_string
= ep_parse_optional_if_clause (&arg
);
6043 if ((*arg
!= '\0') && !isspace (*arg
))
6044 error ("Junk at end of arguments.");
6046 /* Create an unload breakpoint that only triggers when an unload of
6047 the specified dll (or any dll, if no pathname was specified)
6049 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6050 dll_pathname
, cond_string
);
6052 #endif /* SOLIB_ADD */
6054 /* Commands to deal with catching exceptions. */
6056 /* Set a breakpoint at the specified callback routine for an
6057 exception event callback */
6060 create_exception_catchpoint (int tempflag
, char *cond_string
,
6061 enum exception_event_kind ex_event
,
6062 struct symtab_and_line
*sal
)
6064 struct breakpoint
*b
;
6065 int thread
= -1; /* All threads. */
6068 if (!sal
) /* no exception support? */
6073 case EX_EVENT_THROW
:
6074 bptype
= bp_catch_throw
;
6076 case EX_EVENT_CATCH
:
6077 bptype
= bp_catch_catch
;
6079 default: /* error condition */
6080 error ("Internal error -- invalid catchpoint kind");
6083 b
= set_raw_breakpoint (*sal
, bptype
);
6084 set_breakpoint_count (breakpoint_count
+ 1);
6085 b
->number
= breakpoint_count
;
6087 b
->cond_string
= (cond_string
== NULL
) ?
6088 NULL
: savestring (cond_string
, strlen (cond_string
));
6090 b
->addr_string
= NULL
;
6091 b
->enable_state
= bp_enabled
;
6092 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6096 /* Deal with "catch catch" and "catch throw" commands */
6099 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6100 int tempflag
, int from_tty
)
6102 char *cond_string
= NULL
;
6103 struct symtab_and_line
*sal
= NULL
;
6105 ep_skip_leading_whitespace (&arg
);
6107 cond_string
= ep_parse_optional_if_clause (&arg
);
6109 if ((*arg
!= '\0') && !isspace (*arg
))
6110 error ("Junk at end of arguments.");
6112 if ((ex_event
!= EX_EVENT_THROW
) &&
6113 (ex_event
!= EX_EVENT_CATCH
))
6114 error ("Unsupported or unknown exception event; cannot catch it");
6116 /* See if we can find a callback routine */
6117 sal
= target_enable_exception_callback (ex_event
, 1);
6121 /* We have callbacks from the runtime system for exceptions.
6122 Set a breakpoint on the sal found, if no errors */
6123 if (sal
!= (struct symtab_and_line
*) -1)
6124 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6126 return; /* something went wrong with setting up callbacks */
6130 /* No callbacks from runtime system for exceptions.
6131 Try GNU C++ exception breakpoints using labels in debug info. */
6132 if (ex_event
== EX_EVENT_CATCH
)
6134 handle_gnu_4_16_catch_command (arg
, tempflag
, from_tty
);
6136 else if (ex_event
== EX_EVENT_THROW
)
6138 /* Set a breakpoint on __raise_exception () */
6140 warning ("Unsupported with this platform/compiler combination.");
6141 warning ("Perhaps you can achieve the effect you want by setting");
6142 warning ("a breakpoint on __raise_exception().");
6147 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6148 inside a catch_errors */
6151 cover_target_enable_exception_callback (PTR arg
)
6153 args_for_catchpoint_enable
*args
= arg
;
6154 struct symtab_and_line
*sal
;
6155 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6158 else if (sal
== (struct symtab_and_line
*) -1)
6161 return 1; /*is valid */
6166 /* This is the original v.4.16 and earlier version of the
6167 catch_command_1() function. Now that other flavours of "catch"
6168 have been introduced, and since exception handling can be handled
6169 in other ways (through target ops) also, this is used only for the
6170 GNU C++ exception handling system.
6171 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6172 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6173 there was no code in GDB 4.16 for "catch throw".
6175 Called from catch_exception_command_1 () */
6179 handle_gnu_4_16_catch_command (char *arg
, int tempflag
, int from_tty
)
6181 /* First, translate ARG into something we can deal with in terms
6184 struct symtabs_and_lines sals
;
6185 struct symtab_and_line sal
;
6186 register struct expression
*cond
= 0;
6187 register struct breakpoint
*b
;
6191 INIT_SAL (&sal
); /* initialize to zeroes */
6193 /* If no arg given, or if first arg is 'if ', all active catch clauses
6194 are breakpointed. */
6196 if (!arg
|| (arg
[0] == 'i' && arg
[1] == 'f'
6197 && (arg
[2] == ' ' || arg
[2] == '\t')))
6199 /* Grab all active catch clauses. */
6200 sals
= get_catch_sals (0);
6204 /* Grab selected catch clauses. */
6205 error ("catch NAME not implemented");
6208 /* Not sure why this code has been disabled. I'm leaving
6209 it disabled. We can never come here now anyway
6210 since we don't allow the "catch NAME" syntax.
6213 /* This isn't used; I don't know what it was for. */
6214 sals
= map_catch_names (arg
, catch_breakpoint
);
6222 for (i
= 0; i
< sals
.nelts
; i
++)
6224 resolve_sal_pc (&sals
.sals
[i
]);
6228 if (arg
[0] == 'i' && arg
[1] == 'f'
6229 && (arg
[2] == ' ' || arg
[2] == '\t'))
6230 cond
= parse_exp_1 ((arg
+= 2, &arg
),
6231 block_for_pc (sals
.sals
[i
].pc
), 0);
6233 error ("Junk at end of arguments.");
6238 for (i
= 0; i
< sals
.nelts
; i
++)
6243 describe_other_breakpoints (sal
.pc
, sal
.section
);
6245 /* Important -- this is an ordinary breakpoint. For platforms
6246 with callback support for exceptions,
6247 create_exception_catchpoint() will create special bp types
6248 (bp_catch_catch and bp_catch_throw), and there is code in
6249 insert_breakpoints() and elsewhere that depends on that. */
6250 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6251 set_breakpoint_count (breakpoint_count
+ 1);
6252 b
->number
= breakpoint_count
;
6255 b
->enable_state
= bp_enabled
;
6256 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6263 warning ("Multiple breakpoints were set.");
6264 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
6270 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6273 /* The first argument may be an event name, such as "start" or "load".
6274 If so, then handle it as such. If it doesn't match an event name,
6275 then attempt to interpret it as an exception name. (This latter is
6276 the v4.16-and-earlier GDB meaning of the "catch" command.)
6278 First, try to find the bounds of what might be an event name. */
6279 char *arg1_start
= arg
;
6283 if (arg1_start
== NULL
)
6285 /* Old behaviour was to use pre-v-4.16 syntax */
6286 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6288 /* Now, this is not allowed */
6289 error ("Catch requires an event name.");
6292 arg1_end
= ep_find_event_name_end (arg1_start
);
6293 if (arg1_end
== NULL
)
6294 error ("catch requires an event");
6295 arg1_length
= arg1_end
+ 1 - arg1_start
;
6297 /* Try to match what we found against known event names. */
6298 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6300 error ("Catch of signal not yet implemented");
6302 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6304 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6305 tempflag
, from_tty
);
6307 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6309 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6310 tempflag
, from_tty
);
6312 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6314 error ("Catch of thread_start not yet implemented");
6316 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6318 error ("Catch of thread_exit not yet implemented");
6320 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6322 error ("Catch of thread_join not yet implemented");
6324 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6326 error ("Catch of start not yet implemented");
6328 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6330 error ("Catch of exit not yet implemented");
6332 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6334 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6335 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6337 error ("Catch of fork not yet implemented");
6340 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6342 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6343 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6345 error ("Catch of vfork not yet implemented");
6348 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6350 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6351 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6353 error ("Catch of exec not yet implemented");
6356 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6358 #if defined(SOLIB_ADD)
6359 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6361 error ("Catch of load not implemented");
6364 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6366 #if defined(SOLIB_ADD)
6367 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6369 error ("Catch of load not implemented");
6372 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6374 error ("Catch of stop not yet implemented");
6377 /* This doesn't appear to be an event name */
6381 /* Pre-v.4.16 behaviour was to treat the argument
6382 as the name of an exception */
6383 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6384 /* Now this is not allowed */
6385 error ("Unknown event kind specified for catch");
6390 /* Used by the gui, could be made a worker for other things. */
6393 set_breakpoint_sal (struct symtab_and_line sal
)
6395 struct breakpoint
*b
;
6396 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6397 set_breakpoint_count (breakpoint_count
+ 1);
6398 b
->number
= breakpoint_count
;
6405 /* These aren't used; I don't know what they were for. */
6406 /* Disable breakpoints on all catch clauses described in ARGS. */
6408 disable_catch (char *args
)
6410 /* Map the disable command to catch clauses described in ARGS. */
6413 /* Enable breakpoints on all catch clauses described in ARGS. */
6415 enable_catch (char *args
)
6417 /* Map the disable command to catch clauses described in ARGS. */
6420 /* Delete breakpoints on all catch clauses in the active scope. */
6422 delete_catch (char *args
)
6424 /* Map the delete command to catch clauses described in ARGS. */
6429 catch_command (char *arg
, int from_tty
)
6431 catch_command_1 (arg
, 0, from_tty
);
6436 tcatch_command (char *arg
, int from_tty
)
6438 catch_command_1 (arg
, 1, from_tty
);
6441 /* Delete breakpoints by address or line. */
6444 clear_command (char *arg
, int from_tty
)
6446 struct breakpoint
*b
, *tmp
, *prev
, *found
;
6448 struct symtabs_and_lines sals
;
6449 struct symtab_and_line sal
;
6454 sals
= decode_line_spec (arg
, 1);
6459 sals
.sals
= (struct symtab_and_line
*)
6460 xmalloc (sizeof (struct symtab_and_line
));
6461 make_cleanup (xfree
, sals
.sals
);
6462 INIT_SAL (&sal
); /* initialize to zeroes */
6463 sal
.line
= default_breakpoint_line
;
6464 sal
.symtab
= default_breakpoint_symtab
;
6465 sal
.pc
= default_breakpoint_address
;
6466 if (sal
.symtab
== 0)
6467 error ("No source file specified.");
6475 /* For each line spec given, delete bps which correspond
6476 to it. Do it in two passes, solely to preserve the current
6477 behavior that from_tty is forced true if we delete more than
6481 for (i
= 0; i
< sals
.nelts
; i
++)
6483 /* If exact pc given, clear bpts at that pc.
6484 If line given (pc == 0), clear all bpts on specified line.
6485 If defaulting, clear all bpts on default line
6488 defaulting sal.pc != 0 tests to do
6493 1 0 <can't happen> */
6498 /* Find all matching breakpoints, remove them from the
6499 breakpoint chain, and add them to the 'found' chain. */
6500 ALL_BREAKPOINTS_SAFE (b
, tmp
)
6502 /* Are we going to delete b? */
6503 if (b
->type
!= bp_none
6504 && b
->type
!= bp_watchpoint
6505 && b
->type
!= bp_hardware_watchpoint
6506 && b
->type
!= bp_read_watchpoint
6507 && b
->type
!= bp_access_watchpoint
6508 /* Not if b is a watchpoint of any sort... */
6509 && (((sal
.pc
&& (b
->address
== sal
.pc
))
6510 && (!section_is_overlay (b
->section
)
6511 || b
->section
== sal
.section
))
6512 /* Yes, if sal.pc matches b (modulo overlays). */
6513 || ((default_match
|| (0 == sal
.pc
))
6514 && b
->source_file
!= NULL
6515 && sal
.symtab
!= NULL
6516 && STREQ (b
->source_file
, sal
.symtab
->filename
)
6517 && b
->line_number
== sal
.line
)))
6518 /* Yes, if sal source file and line matches b. */
6520 /* Remove it from breakpoint_chain... */
6521 if (b
== breakpoint_chain
)
6523 /* b is at the head of the list */
6524 breakpoint_chain
= b
->next
;
6528 prev
->next
= b
->next
;
6530 /* And add it to 'found' chain. */
6536 /* Keep b, and keep a pointer to it. */
6541 /* Now go thru the 'found' chain and delete them. */
6545 error ("No breakpoint at %s.", arg
);
6547 error ("No breakpoint at this line.");
6551 from_tty
= 1; /* Always report if deleted more than one */
6553 printf_unfiltered ("Deleted breakpoint%s ", found
->next
? "s" : "");
6554 breakpoints_changed ();
6558 printf_unfiltered ("%d ", found
->number
);
6560 delete_breakpoint (found
);
6564 putchar_unfiltered ('\n');
6567 /* Delete breakpoint in BS if they are `delete' breakpoints and
6568 all breakpoints that are marked for deletion, whether hit or not.
6569 This is called after any breakpoint is hit, or after errors. */
6572 breakpoint_auto_delete (bpstat bs
)
6574 struct breakpoint
*b
, *temp
;
6576 for (; bs
; bs
= bs
->next
)
6577 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== disp_del
6579 delete_breakpoint (bs
->breakpoint_at
);
6581 ALL_BREAKPOINTS_SAFE (b
, temp
)
6583 if (b
->disposition
== disp_del_at_next_stop
)
6584 delete_breakpoint (b
);
6588 /* Delete a breakpoint and clean up all traces of it in the data
6592 delete_breakpoint (struct breakpoint
*bpt
)
6594 register struct breakpoint
*b
;
6598 error ("Internal error (attempted to delete a NULL breakpoint)");
6601 /* Has this bp already been deleted? This can happen because multiple
6602 lists can hold pointers to bp's. bpstat lists are especial culprits.
6604 One example of this happening is a watchpoint's scope bp. When the
6605 scope bp triggers, we notice that the watchpoint is out of scope, and
6606 delete it. We also delete its scope bp. But the scope bp is marked
6607 "auto-deleting", and is already on a bpstat. That bpstat is then
6608 checked for auto-deleting bp's, which are deleted.
6610 A real solution to this problem might involve reference counts in bp's,
6611 and/or giving them pointers back to their referencing bpstat's, and
6612 teaching delete_breakpoint to only free a bp's storage when no more
6613 references were extent. A cheaper bandaid was chosen. */
6614 if (bpt
->type
== bp_none
)
6617 if (delete_breakpoint_hook
)
6618 delete_breakpoint_hook (bpt
);
6619 breakpoint_delete_event (bpt
->number
);
6622 remove_breakpoint (bpt
, mark_inserted
);
6624 if (breakpoint_chain
== bpt
)
6625 breakpoint_chain
= bpt
->next
;
6627 /* If we have callback-style exception catchpoints, don't go through
6628 the adjustments to the C++ runtime library etc. if the inferior
6629 isn't actually running. target_enable_exception_callback for a
6630 null target ops vector gives an undesirable error message, so we
6631 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6632 exceptions are supported in this way, it's OK for now. FIXME */
6633 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
6635 static char message1
[] = "Error in deleting catchpoint %d:\n";
6636 static char message
[sizeof (message1
) + 30];
6637 args_for_catchpoint_enable args
;
6639 /* Format possible error msg */
6640 sprintf (message
, message1
, bpt
->number
);
6641 args
.kind
= bpt
->type
== bp_catch_catch
?
6642 EX_EVENT_CATCH
: EX_EVENT_THROW
;
6644 catch_errors (cover_target_enable_exception_callback
, &args
,
6645 message
, RETURN_MASK_ALL
);
6652 b
->next
= bpt
->next
;
6656 check_duplicates (bpt
);
6657 /* If this breakpoint was inserted, and there is another breakpoint
6658 at the same address, we need to insert the other breakpoint. */
6660 && bpt
->type
!= bp_hardware_watchpoint
6661 && bpt
->type
!= bp_read_watchpoint
6662 && bpt
->type
!= bp_access_watchpoint
6663 && bpt
->type
!= bp_catch_fork
6664 && bpt
->type
!= bp_catch_vfork
6665 && bpt
->type
!= bp_catch_exec
)
6668 if (b
->address
== bpt
->address
6669 && b
->section
== bpt
->section
6671 && b
->enable_state
!= bp_disabled
6672 && b
->enable_state
!= bp_shlib_disabled
6673 && b
->enable_state
!= bp_call_disabled
)
6677 /* We should never reach this point if there is a permanent
6678 breakpoint at the same address as the one being deleted.
6679 If there is a permanent breakpoint somewhere, it should
6680 always be the only one inserted. */
6681 if (b
->enable_state
== bp_permanent
)
6682 internal_error (__FILE__
, __LINE__
,
6683 "another breakpoint was inserted on top of "
6684 "a permanent breakpoint");
6686 if (b
->type
== bp_hardware_breakpoint
)
6687 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
6689 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
6693 target_terminal_ours_for_output ();
6694 warning ("Cannot insert breakpoint %d:", b
->number
);
6695 memory_error (val
, b
->address
); /* which bombs us out */
6702 free_command_lines (&bpt
->commands
);
6705 if (bpt
->cond_string
!= NULL
)
6706 xfree (bpt
->cond_string
);
6707 if (bpt
->addr_string
!= NULL
)
6708 xfree (bpt
->addr_string
);
6709 if (bpt
->exp
!= NULL
)
6711 if (bpt
->exp_string
!= NULL
)
6712 xfree (bpt
->exp_string
);
6713 if (bpt
->val
!= NULL
)
6714 value_free (bpt
->val
);
6715 if (bpt
->source_file
!= NULL
)
6716 xfree (bpt
->source_file
);
6717 if (bpt
->dll_pathname
!= NULL
)
6718 xfree (bpt
->dll_pathname
);
6719 if (bpt
->triggered_dll_pathname
!= NULL
)
6720 xfree (bpt
->triggered_dll_pathname
);
6721 if (bpt
->exec_pathname
!= NULL
)
6722 xfree (bpt
->exec_pathname
);
6724 /* Be sure no bpstat's are pointing at it after it's been freed. */
6725 /* FIXME, how can we find all bpstat's?
6726 We just check stop_bpstat for now. */
6727 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
6728 if (bs
->breakpoint_at
== bpt
)
6730 bs
->breakpoint_at
= NULL
;
6732 /* we'd call bpstat_clear_actions, but that free's stuff and due
6733 to the multiple pointers pointing to one item with no
6734 reference counts found anywhere through out the bpstat's (how
6735 do you spell fragile?), we don't want to free things twice --
6736 better a memory leak than a corrupt malloc pool! */
6737 bs
->commands
= NULL
;
6740 /* On the chance that someone will soon try again to delete this same
6741 bp, we mark it as deleted before freeing its storage. */
6742 bpt
->type
= bp_none
;
6748 do_delete_breakpoint_cleanup (void *b
)
6750 delete_breakpoint (b
);
6754 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
6756 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
6760 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
6762 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
6766 delete_command (char *arg
, int from_tty
)
6768 struct breakpoint
*b
, *temp
;
6772 int breaks_to_delete
= 0;
6774 /* Delete all breakpoints if no argument.
6775 Do not delete internal or call-dummy breakpoints, these
6776 have to be deleted with an explicit breakpoint number argument. */
6779 if (b
->type
!= bp_call_dummy
&&
6780 b
->type
!= bp_shlib_event
&&
6781 b
->type
!= bp_thread_event
&&
6782 b
->type
!= bp_overlay_event
&&
6784 breaks_to_delete
= 1;
6787 /* Ask user only if there are some breakpoints to delete. */
6789 || (breaks_to_delete
&& query ("Delete all breakpoints? ")))
6791 ALL_BREAKPOINTS_SAFE (b
, temp
)
6793 if (b
->type
!= bp_call_dummy
&&
6794 b
->type
!= bp_shlib_event
&&
6795 b
->type
!= bp_thread_event
&&
6796 b
->type
!= bp_overlay_event
&&
6798 delete_breakpoint (b
);
6803 map_breakpoint_numbers (arg
, delete_breakpoint
);
6806 /* Reset a breakpoint given it's struct breakpoint * BINT.
6807 The value we return ends up being the return value from catch_errors.
6808 Unused in this case. */
6811 breakpoint_re_set_one (PTR bint
)
6813 /* get past catch_errs */
6814 struct breakpoint
*b
= (struct breakpoint
*) bint
;
6817 struct symtabs_and_lines sals
;
6819 enum enable_state save_enable
;
6824 warning ("attempted to reset apparently deleted breakpoint #%d?",
6828 case bp_hardware_breakpoint
:
6830 case bp_catch_unload
:
6831 if (b
->addr_string
== NULL
)
6833 /* Anything without a string can't be re-set. */
6834 delete_breakpoint (b
);
6837 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6839 ``And a hack it is, although Apple's Darwin version of GDB
6840 contains an almost identical hack to implement a "future
6841 break" command. It seems to work in many real world cases,
6842 but it is easy to come up with a test case where the patch
6843 doesn't help at all.''
6845 ``It seems that the way GDB implements breakpoints - in -
6846 shared - libraries was designed for a.out shared library
6847 systems (SunOS 4) where shared libraries were loaded at a
6848 fixed address in memory. Since ELF shared libraries can (and
6849 will) be loaded at any address in memory, things break.
6850 Fixing this is not trivial. Therefore, I'm not sure whether
6851 we should add this hack to the branch only. I cannot
6852 guarantee that things will be fixed on the trunk in the near
6855 In case we have a problem, disable this breakpoint. We'll
6856 restore its status if we succeed. Don't disable a
6857 shlib_disabled breakpoint though. There's a fair chance we
6858 can't re-set it if the shared library it's in hasn't been
6860 save_enable
= b
->enable_state
;
6861 if (b
->enable_state
!= bp_shlib_disabled
)
6862 b
->enable_state
= bp_disabled
;
6864 set_language (b
->language
);
6865 input_radix
= b
->input_radix
;
6867 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
);
6868 for (i
= 0; i
< sals
.nelts
; i
++)
6870 resolve_sal_pc (&sals
.sals
[i
]);
6872 /* Reparse conditions, they might contain references to the
6874 if (b
->cond_string
!= NULL
)
6879 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
6882 /* We need to re-set the breakpoint if the address changes... */
6883 if (b
->address
!= sals
.sals
[i
].pc
6884 /* ...or new and old breakpoints both have source files, and
6885 the source file name or the line number changes... */
6886 || (b
->source_file
!= NULL
6887 && sals
.sals
[i
].symtab
!= NULL
6888 && (!STREQ (b
->source_file
, sals
.sals
[i
].symtab
->filename
)
6889 || b
->line_number
!= sals
.sals
[i
].line
)
6891 /* ...or we switch between having a source file and not having
6893 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
6896 if (b
->source_file
!= NULL
)
6897 xfree (b
->source_file
);
6898 if (sals
.sals
[i
].symtab
== NULL
)
6899 b
->source_file
= NULL
;
6902 savestring (sals
.sals
[i
].symtab
->filename
,
6903 strlen (sals
.sals
[i
].symtab
->filename
));
6904 b
->line_number
= sals
.sals
[i
].line
;
6905 b
->address
= sals
.sals
[i
].pc
;
6907 /* Used to check for duplicates here, but that can
6908 cause trouble, as it doesn't check for disabled
6913 /* Might be better to do this just once per breakpoint_re_set,
6914 rather than once for every breakpoint. */
6915 breakpoints_changed ();
6917 b
->section
= sals
.sals
[i
].section
;
6918 b
->enable_state
= save_enable
; /* Restore it, this worked. */
6921 /* Now that this is re-enabled, check_duplicates
6923 check_duplicates (b
);
6930 case bp_hardware_watchpoint
:
6931 case bp_read_watchpoint
:
6932 case bp_access_watchpoint
:
6933 innermost_block
= NULL
;
6934 /* The issue arises of what context to evaluate this in. The
6935 same one as when it was set, but what does that mean when
6936 symbols have been re-read? We could save the filename and
6937 functionname, but if the context is more local than that, the
6938 best we could do would be something like how many levels deep
6939 and which index at that particular level, but that's going to
6940 be less stable than filenames or function names. */
6942 /* So for now, just use a global context. */
6945 b
->exp
= parse_expression (b
->exp_string
);
6946 b
->exp_valid_block
= innermost_block
;
6947 mark
= value_mark ();
6949 value_free (b
->val
);
6950 b
->val
= evaluate_expression (b
->exp
);
6951 release_value (b
->val
);
6952 if (VALUE_LAZY (b
->val
))
6953 value_fetch_lazy (b
->val
);
6955 if (b
->cond_string
!= NULL
)
6960 b
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
6962 if (b
->enable_state
== bp_enabled
)
6964 value_free_to_mark (mark
);
6966 case bp_catch_catch
:
6967 case bp_catch_throw
:
6969 /* We needn't really do anything to reset these, since the mask
6970 that requests them is unaffected by e.g., new libraries being
6973 case bp_catch_vfork
:
6978 printf_filtered ("Deleting unknown breakpoint type %d\n", b
->type
);
6980 /* Delete longjmp and overlay event breakpoints; they will be
6981 reset later by breakpoint_re_set. */
6983 case bp_longjmp_resume
:
6984 case bp_overlay_event
:
6985 delete_breakpoint (b
);
6988 /* This breakpoint is special, it's set up when the inferior
6989 starts and we really don't want to touch it. */
6990 case bp_shlib_event
:
6992 /* Like bp_shlib_event, this breakpoint type is special.
6993 Once it is set up, we do not want to touch it. */
6994 case bp_thread_event
:
6996 /* Keep temporary breakpoints, which can be encountered when we step
6997 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6998 Otherwise these should have been blown away via the cleanup chain
6999 or by breakpoint_init_inferior when we rerun the executable. */
7002 case bp_watchpoint_scope
:
7004 case bp_step_resume
:
7011 /* Re-set all breakpoints after symbols have been re-loaded. */
7013 breakpoint_re_set (void)
7015 struct breakpoint
*b
, *temp
;
7016 enum language save_language
;
7017 int save_input_radix
;
7018 static char message1
[] = "Error in re-setting breakpoint %d:\n";
7019 char message
[sizeof (message1
) + 30 /* slop */ ];
7021 save_language
= current_language
->la_language
;
7022 save_input_radix
= input_radix
;
7023 ALL_BREAKPOINTS_SAFE (b
, temp
)
7025 /* Format possible error msg */
7026 sprintf (message
, message1
, b
->number
);
7027 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7029 set_language (save_language
);
7030 input_radix
= save_input_radix
;
7032 if (GET_LONGJMP_TARGET_P ())
7034 create_longjmp_breakpoint ("longjmp");
7035 create_longjmp_breakpoint ("_longjmp");
7036 create_longjmp_breakpoint ("siglongjmp");
7037 create_longjmp_breakpoint ("_siglongjmp");
7038 create_longjmp_breakpoint (NULL
);
7041 create_overlay_event_breakpoint ("_ovly_debug_event");
7044 /* Reset the thread number of this breakpoint:
7046 - If the breakpoint is for all threads, leave it as-is.
7047 - Else, reset it to the current thread for inferior_ptid. */
7049 breakpoint_re_set_thread (struct breakpoint
*b
)
7051 if (b
->thread
!= -1)
7053 if (in_thread_list (inferior_ptid
))
7054 b
->thread
= pid_to_thread_id (inferior_ptid
);
7058 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7059 If from_tty is nonzero, it prints a message to that effect,
7060 which ends with a period (no newline). */
7063 set_ignore_count (int bptnum
, int count
, int from_tty
)
7065 register struct breakpoint
*b
;
7071 if (b
->number
== bptnum
)
7073 b
->ignore_count
= count
;
7076 else if (count
== 0)
7077 printf_filtered ("Will stop next time breakpoint %d is reached.",
7079 else if (count
== 1)
7080 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7083 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7085 breakpoints_changed ();
7089 error ("No breakpoint number %d.", bptnum
);
7092 /* Clear the ignore counts of all breakpoints. */
7094 breakpoint_clear_ignore_counts (void)
7096 struct breakpoint
*b
;
7099 b
->ignore_count
= 0;
7102 /* Command to set ignore-count of breakpoint N to COUNT. */
7105 ignore_command (char *args
, int from_tty
)
7111 error_no_arg ("a breakpoint number");
7113 num
= get_number (&p
);
7115 error ("bad breakpoint number: '%s'", args
);
7117 error ("Second argument (specified ignore-count) is missing.");
7119 set_ignore_count (num
,
7120 longest_to_int (value_as_long (parse_and_eval (p
))),
7122 printf_filtered ("\n");
7123 breakpoints_changed ();
7126 /* Call FUNCTION on each of the breakpoints
7127 whose numbers are given in ARGS. */
7130 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7132 register char *p
= args
;
7135 register struct breakpoint
*b
, *tmp
;
7139 error_no_arg ("one or more breakpoint numbers");
7146 num
= get_number_or_range (&p1
);
7149 warning ("bad breakpoint number at or near '%s'", p
);
7153 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7154 if (b
->number
== num
)
7156 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7159 if (related_breakpoint
)
7160 function (related_breakpoint
);
7164 printf_unfiltered ("No breakpoint number %d.\n", num
);
7170 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7171 If from_tty is nonzero, it prints a message to that effect,
7172 which ends with a period (no newline). */
7175 disable_breakpoint (struct breakpoint
*bpt
)
7177 /* Never disable a watchpoint scope breakpoint; we want to
7178 hit them when we leave scope so we can delete both the
7179 watchpoint and its scope breakpoint at that time. */
7180 if (bpt
->type
== bp_watchpoint_scope
)
7183 /* You can't disable permanent breakpoints. */
7184 if (bpt
->enable_state
== bp_permanent
)
7187 bpt
->enable_state
= bp_disabled
;
7189 check_duplicates (bpt
);
7191 if (modify_breakpoint_hook
)
7192 modify_breakpoint_hook (bpt
);
7193 breakpoint_modify_event (bpt
->number
);
7198 disable_command (char *args
, int from_tty
)
7200 register struct breakpoint
*bpt
;
7202 ALL_BREAKPOINTS (bpt
)
7206 warning ("attempted to disable apparently deleted breakpoint #%d?",
7211 case bp_catch_unload
:
7213 case bp_catch_vfork
:
7215 case bp_catch_catch
:
7216 case bp_catch_throw
:
7217 case bp_hardware_breakpoint
:
7219 case bp_hardware_watchpoint
:
7220 case bp_read_watchpoint
:
7221 case bp_access_watchpoint
:
7222 disable_breakpoint (bpt
);
7227 map_breakpoint_numbers (args
, disable_breakpoint
);
7231 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7233 struct frame_info
*save_selected_frame
= NULL
;
7234 int save_selected_frame_level
= -1;
7235 int target_resources_ok
, other_type_used
;
7238 if (bpt
->type
== bp_hardware_breakpoint
)
7241 i
= hw_breakpoint_used_count ();
7242 target_resources_ok
=
7243 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7245 if (target_resources_ok
== 0)
7246 error ("No hardware breakpoint support in the target.");
7247 else if (target_resources_ok
< 0)
7248 error ("Hardware breakpoints used exceeds limit.");
7251 if (bpt
->enable_state
!= bp_permanent
)
7252 bpt
->enable_state
= bp_enabled
;
7253 bpt
->disposition
= disposition
;
7254 check_duplicates (bpt
);
7255 breakpoints_changed ();
7257 if (bpt
->type
== bp_watchpoint
||
7258 bpt
->type
== bp_hardware_watchpoint
||
7259 bpt
->type
== bp_read_watchpoint
||
7260 bpt
->type
== bp_access_watchpoint
)
7262 if (bpt
->exp_valid_block
!= NULL
)
7264 struct frame_info
*fr
=
7265 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7269 Cannot enable watchpoint %d because the block in which its expression\n\
7270 is valid is not currently in scope.\n", bpt
->number
);
7271 bpt
->enable_state
= bp_disabled
;
7275 save_selected_frame
= selected_frame
;
7276 save_selected_frame_level
= frame_relative_level (selected_frame
);
7280 value_free (bpt
->val
);
7281 mark
= value_mark ();
7282 bpt
->val
= evaluate_expression (bpt
->exp
);
7283 release_value (bpt
->val
);
7284 if (VALUE_LAZY (bpt
->val
))
7285 value_fetch_lazy (bpt
->val
);
7287 if (bpt
->type
== bp_hardware_watchpoint
||
7288 bpt
->type
== bp_read_watchpoint
||
7289 bpt
->type
== bp_access_watchpoint
)
7291 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7292 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7294 /* Hack around 'unused var' error for some targets here */
7296 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7297 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7298 /* we can consider of type is bp_hardware_watchpoint, convert to
7299 bp_watchpoint in the following condition */
7300 if (target_resources_ok
< 0)
7303 Cannot enable watchpoint %d because target watch resources\n\
7304 have been allocated for other watchpoints.\n", bpt
->number
);
7305 bpt
->enable_state
= bp_disabled
;
7306 value_free_to_mark (mark
);
7311 if (save_selected_frame_level
>= 0)
7312 select_frame (save_selected_frame
);
7313 value_free_to_mark (mark
);
7315 if (modify_breakpoint_hook
)
7316 modify_breakpoint_hook (bpt
);
7317 breakpoint_modify_event (bpt
->number
);
7321 enable_breakpoint (struct breakpoint
*bpt
)
7323 do_enable_breakpoint (bpt
, bpt
->disposition
);
7326 /* The enable command enables the specified breakpoints (or all defined
7327 breakpoints) so they once again become (or continue to be) effective
7328 in stopping the inferior. */
7332 enable_command (char *args
, int from_tty
)
7334 register struct breakpoint
*bpt
;
7336 ALL_BREAKPOINTS (bpt
)
7340 warning ("attempted to enable apparently deleted breakpoint #%d?",
7345 case bp_catch_unload
:
7347 case bp_catch_vfork
:
7349 case bp_catch_catch
:
7350 case bp_catch_throw
:
7351 case bp_hardware_breakpoint
:
7353 case bp_hardware_watchpoint
:
7354 case bp_read_watchpoint
:
7355 case bp_access_watchpoint
:
7356 enable_breakpoint (bpt
);
7361 map_breakpoint_numbers (args
, enable_breakpoint
);
7365 enable_once_breakpoint (struct breakpoint
*bpt
)
7367 do_enable_breakpoint (bpt
, disp_disable
);
7372 enable_once_command (char *args
, int from_tty
)
7374 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7378 enable_delete_breakpoint (struct breakpoint
*bpt
)
7380 do_enable_breakpoint (bpt
, disp_del
);
7385 enable_delete_command (char *args
, int from_tty
)
7387 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7390 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7392 struct symtabs_and_lines
7393 decode_line_spec_1 (char *string
, int funfirstline
)
7395 struct symtabs_and_lines sals
;
7397 error ("Empty line specification.");
7398 if (default_breakpoint_valid
)
7399 sals
= decode_line_1 (&string
, funfirstline
,
7400 default_breakpoint_symtab
,
7401 default_breakpoint_line
,
7404 sals
= decode_line_1 (&string
, funfirstline
,
7405 (struct symtab
*) NULL
, 0, (char ***) NULL
);
7407 error ("Junk at end of line specification: %s", string
);
7412 _initialize_breakpoint (void)
7414 struct cmd_list_element
*c
;
7416 breakpoint_chain
= 0;
7417 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7418 before a breakpoint is set. */
7419 breakpoint_count
= 0;
7421 add_com ("ignore", class_breakpoint
, ignore_command
,
7422 "Set ignore-count of breakpoint number N to COUNT.\n\
7423 Usage is `ignore N COUNT'.");
7425 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7427 add_com ("commands", class_breakpoint
, commands_command
,
7428 "Set commands to be executed when a breakpoint is hit.\n\
7429 Give breakpoint number as argument after \"commands\".\n\
7430 With no argument, the targeted breakpoint is the last one set.\n\
7431 The commands themselves follow starting on the next line.\n\
7432 Type a line containing \"end\" to indicate the end of them.\n\
7433 Give \"silent\" as the first line to make the breakpoint silent;\n\
7434 then no output is printed when it is hit, except what the commands print.");
7436 add_com ("condition", class_breakpoint
, condition_command
,
7437 "Specify breakpoint number N to break only if COND is true.\n\
7438 Usage is `condition N COND', where N is an integer and COND is an\n\
7439 expression to be evaluated whenever breakpoint N is reached.");
7441 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
,
7442 "Set a temporary breakpoint. Args like \"break\" command.\n\
7443 Like \"break\" except the breakpoint is only temporary,\n\
7444 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7445 by using \"enable delete\" on the breakpoint number.");
7446 set_cmd_completer (c
, location_completer
);
7448 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
,
7449 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7450 Like \"break\" except the breakpoint requires hardware support,\n\
7451 some target hardware may not have this support.");
7452 set_cmd_completer (c
, location_completer
);
7454 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
,
7455 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7456 Like \"hbreak\" except the breakpoint is only temporary,\n\
7457 so it will be deleted when hit.");
7458 set_cmd_completer (c
, location_completer
);
7460 add_prefix_cmd ("enable", class_breakpoint
, enable_command
,
7461 "Enable some breakpoints.\n\
7462 Give breakpoint numbers (separated by spaces) as arguments.\n\
7463 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7464 This is used to cancel the effect of the \"disable\" command.\n\
7465 With a subcommand you can enable temporarily.",
7466 &enablelist
, "enable ", 1, &cmdlist
);
7468 add_com ("ab", class_breakpoint
, enable_command
,
7469 "Enable some breakpoints.\n\
7470 Give breakpoint numbers (separated by spaces) as arguments.\n\
7471 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7472 This is used to cancel the effect of the \"disable\" command.\n\
7473 With a subcommand you can enable temporarily.");
7475 add_com_alias ("en", "enable", class_breakpoint
, 1);
7477 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
,
7478 "Enable some breakpoints.\n\
7479 Give breakpoint numbers (separated by spaces) as arguments.\n\
7480 This is used to cancel the effect of the \"disable\" command.\n\
7481 May be abbreviated to simply \"enable\".\n",
7482 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
7484 add_cmd ("once", no_class
, enable_once_command
,
7485 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7486 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7489 add_cmd ("delete", no_class
, enable_delete_command
,
7490 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7491 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7494 add_cmd ("delete", no_class
, enable_delete_command
,
7495 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7496 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7499 add_cmd ("once", no_class
, enable_once_command
,
7500 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7501 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7504 add_prefix_cmd ("disable", class_breakpoint
, disable_command
,
7505 "Disable some breakpoints.\n\
7506 Arguments are breakpoint numbers with spaces in between.\n\
7507 To disable all breakpoints, give no argument.\n\
7508 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7509 &disablelist
, "disable ", 1, &cmdlist
);
7510 add_com_alias ("dis", "disable", class_breakpoint
, 1);
7511 add_com_alias ("disa", "disable", class_breakpoint
, 1);
7513 add_com ("sb", class_breakpoint
, disable_command
,
7514 "Disable some breakpoints.\n\
7515 Arguments are breakpoint numbers with spaces in between.\n\
7516 To disable all breakpoints, give no argument.\n\
7517 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7519 add_cmd ("breakpoints", class_alias
, disable_command
,
7520 "Disable some breakpoints.\n\
7521 Arguments are breakpoint numbers with spaces in between.\n\
7522 To disable all breakpoints, give no argument.\n\
7523 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7524 This command may be abbreviated \"disable\".",
7527 add_prefix_cmd ("delete", class_breakpoint
, delete_command
,
7528 "Delete some breakpoints or auto-display expressions.\n\
7529 Arguments are breakpoint numbers with spaces in between.\n\
7530 To delete all breakpoints, give no argument.\n\
7532 Also a prefix command for deletion of other GDB objects.\n\
7533 The \"unset\" command is also an alias for \"delete\".",
7534 &deletelist
, "delete ", 1, &cmdlist
);
7535 add_com_alias ("d", "delete", class_breakpoint
, 1);
7537 add_com ("db", class_breakpoint
, delete_command
,
7538 "Delete some breakpoints.\n\
7539 Arguments are breakpoint numbers with spaces in between.\n\
7540 To delete all breakpoints, give no argument.\n");
7542 add_cmd ("breakpoints", class_alias
, delete_command
,
7543 "Delete some breakpoints or auto-display expressions.\n\
7544 Arguments are breakpoint numbers with spaces in between.\n\
7545 To delete all breakpoints, give no argument.\n\
7546 This command may be abbreviated \"delete\".",
7549 add_com ("clear", class_breakpoint
, clear_command
,
7550 concat ("Clear breakpoint at specified line or function.\n\
7551 Argument may be line number, function name, or \"*\" and an address.\n\
7552 If line number is specified, all breakpoints in that line are cleared.\n\
7553 If function is specified, breakpoints at beginning of function are cleared.\n\
7554 If an address is specified, breakpoints at that address are cleared.\n\n",
7555 "With no argument, clears all breakpoints in the line that the selected frame\n\
7558 See also the \"delete\" command which clears breakpoints by number.", NULL
));
7560 c
= add_com ("break", class_breakpoint
, break_command
,
7561 concat ("Set breakpoint at specified line or function.\n\
7562 Argument may be line number, function name, or \"*\" and an address.\n\
7563 If line number is specified, break at start of code for that line.\n\
7564 If function is specified, break at start of code for that function.\n\
7565 If an address is specified, break at that exact address.\n",
7566 "With no arg, uses current execution address of selected stack frame.\n\
7567 This is useful for breaking on return to a stack frame.\n\
7569 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7571 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL
));
7572 set_cmd_completer (c
, location_completer
);
7574 add_com_alias ("b", "break", class_run
, 1);
7575 add_com_alias ("br", "break", class_run
, 1);
7576 add_com_alias ("bre", "break", class_run
, 1);
7577 add_com_alias ("brea", "break", class_run
, 1);
7581 add_com_alias ("ba", "break", class_breakpoint
, 1);
7582 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
7587 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
,
7588 "Break in function/address or break at a line in the current file.",
7589 &stoplist
, "stop ", 1, &cmdlist
);
7590 add_cmd ("in", class_breakpoint
, stopin_command
,
7591 "Break in function or address.\n", &stoplist
);
7592 add_cmd ("at", class_breakpoint
, stopat_command
,
7593 "Break at a line in the current file.\n", &stoplist
);
7594 add_com ("status", class_info
, breakpoints_info
,
7595 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7596 The \"Type\" column indicates one of:\n\
7597 \tbreakpoint - normal breakpoint\n\
7598 \twatchpoint - watchpoint\n\
7599 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7600 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7601 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7602 address and file/line number respectively.\n\n",
7603 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7604 are set to the address of the last breakpoint listed.\n\n\
7605 Convenience variable \"$bpnum\" contains the number of the last\n\
7606 breakpoint set.", NULL
));
7609 add_info ("breakpoints", breakpoints_info
,
7610 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7611 The \"Type\" column indicates one of:\n\
7612 \tbreakpoint - normal breakpoint\n\
7613 \twatchpoint - watchpoint\n\
7614 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7615 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7616 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7617 address and file/line number respectively.\n\n",
7618 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7619 are set to the address of the last breakpoint listed.\n\n\
7620 Convenience variable \"$bpnum\" contains the number of the last\n\
7621 breakpoint set.", NULL
));
7624 add_com ("lb", class_breakpoint
, breakpoints_info
,
7625 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7626 The \"Type\" column indicates one of:\n\
7627 \tbreakpoint - normal breakpoint\n\
7628 \twatchpoint - watchpoint\n\
7629 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7630 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7631 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7632 address and file/line number respectively.\n\n",
7633 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7634 are set to the address of the last breakpoint listed.\n\n\
7635 Convenience variable \"$bpnum\" contains the number of the last\n\
7636 breakpoint set.", NULL
));
7638 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
,
7639 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7640 The \"Type\" column indicates one of:\n\
7641 \tbreakpoint - normal breakpoint\n\
7642 \twatchpoint - watchpoint\n\
7643 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7644 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7645 \tuntil - internal breakpoint used by the \"until\" command\n\
7646 \tfinish - internal breakpoint used by the \"finish\" command\n",
7647 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7648 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7649 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7650 address and file/line number respectively.\n\n",
7651 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7652 are set to the address of the last breakpoint listed.\n\n\
7653 Convenience variable \"$bpnum\" contains the number of the last\n\
7654 breakpoint set.", NULL
),
7655 &maintenanceinfolist
);
7657 add_com ("catch", class_breakpoint
, catch_command
,
7658 "Set catchpoints to catch events.\n\
7659 Raised signals may be caught:\n\
7660 \tcatch signal - all signals\n\
7661 \tcatch signal <signame> - a particular signal\n\
7662 Raised exceptions may be caught:\n\
7663 \tcatch throw - all exceptions, when thrown\n\
7664 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7665 \tcatch catch - all exceptions, when caught\n\
7666 \tcatch catch <exceptname> - a particular exception, when caught\n\
7667 Thread or process events may be caught:\n\
7668 \tcatch thread_start - any threads, just after creation\n\
7669 \tcatch thread_exit - any threads, just before expiration\n\
7670 \tcatch thread_join - any threads, just after joins\n\
7671 Process events may be caught:\n\
7672 \tcatch start - any processes, just after creation\n\
7673 \tcatch exit - any processes, just before expiration\n\
7674 \tcatch fork - calls to fork()\n\
7675 \tcatch vfork - calls to vfork()\n\
7676 \tcatch exec - calls to exec()\n\
7677 Dynamically-linked library events may be caught:\n\
7678 \tcatch load - loads of any library\n\
7679 \tcatch load <libname> - loads of a particular library\n\
7680 \tcatch unload - unloads of any library\n\
7681 \tcatch unload <libname> - unloads of a particular library\n\
7682 The act of your program's execution stopping may also be caught:\n\
7684 C++ exceptions may be caught:\n\
7685 \tcatch throw - all exceptions, when thrown\n\
7686 \tcatch catch - all exceptions, when caught\n\
7688 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7689 after a fork or vfork is caught.\n\n\
7690 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7692 add_com ("tcatch", class_breakpoint
, tcatch_command
,
7693 "Set temporary catchpoints to catch events.\n\
7694 Args like \"catch\" command.\n\
7695 Like \"catch\" except the catchpoint is only temporary,\n\
7696 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7697 by using \"enable delete\" on the catchpoint number.");
7699 c
= add_com ("watch", class_breakpoint
, watch_command
,
7700 "Set a watchpoint for an expression.\n\
7701 A watchpoint stops execution of your program whenever the value of\n\
7702 an expression changes.");
7703 set_cmd_completer (c
, location_completer
);
7705 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
7706 "Set a read watchpoint for an expression.\n\
7707 A watchpoint stops execution of your program whenever the value of\n\
7708 an expression is read.");
7709 set_cmd_completer (c
, location_completer
);
7711 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
7712 "Set a watchpoint for an expression.\n\
7713 A watchpoint stops execution of your program whenever the value of\n\
7714 an expression is either read or written.");
7715 set_cmd_completer (c
, location_completer
);
7717 add_info ("watchpoints", breakpoints_info
,
7718 "Synonym for ``info breakpoints''.");
7721 c
= add_set_cmd ("can-use-hw-watchpoints", class_support
, var_zinteger
,
7722 (char *) &can_use_hw_watchpoints
,
7723 "Set debugger's willingness to use watchpoint hardware.\n\
7724 If zero, gdb will not use hardware for new watchpoints, even if\n\
7725 such is available. (However, any hardware watchpoints that were\n\
7726 created before setting this to nonzero, will continue to use watchpoint\n\
7729 add_show_from_set (c
, &showlist
);
7731 can_use_hw_watchpoints
= 1;