1 /* Everything about breakpoints, for GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 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"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
53 #include "gdb-events.h"
55 /* Prototypes for local functions. */
57 static void until_break_command_continuation (struct continuation_arg
*arg
);
59 static void catch_command_1 (char *, int, int);
61 static void enable_delete_command (char *, int);
63 static void enable_delete_breakpoint (struct breakpoint
*);
65 static void enable_once_command (char *, int);
67 static void enable_once_breakpoint (struct breakpoint
*);
69 static void disable_command (char *, int);
71 static void enable_command (char *, int);
73 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
75 static void ignore_command (char *, int);
77 static int breakpoint_re_set_one (void *);
79 static void clear_command (char *, int);
81 static void catch_command (char *, 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 breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
102 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
);
104 static void describe_other_breakpoints (CORE_ADDR
, asection
*);
106 static void breakpoints_info (char *, int);
108 static void breakpoint_1 (int, int);
110 static bpstat
bpstat_alloc (struct breakpoint
*, bpstat
);
112 static int breakpoint_cond_eval (void *);
114 static void cleanup_executing_breakpoints (void *);
116 static void commands_command (char *, int);
118 static void condition_command (char *, int);
120 static int get_number_trailer (char **, int);
122 void set_breakpoint_count (int);
131 static int remove_breakpoint (struct breakpoint
*, insertion_state_t
);
133 static enum print_stop_action
print_it_typical (bpstat
);
135 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
139 enum exception_event_kind kind
;
142 args_for_catchpoint_enable
;
144 static int watchpoint_check (void *);
146 static int cover_target_enable_exception_callback (void *);
148 static void maintenance_info_breakpoints (char *, int);
150 static void create_longjmp_breakpoint (char *);
152 static void create_overlay_event_breakpoint (char *);
154 static int hw_breakpoint_used_count (void);
156 static int hw_watchpoint_used_count (enum bptype
, int *);
158 static void hbreak_command (char *, int);
160 static void thbreak_command (char *, int);
162 static void watch_command_1 (char *, int, int);
164 static void rwatch_command (char *, int);
166 static void awatch_command (char *, int);
168 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
170 static void solib_load_unload_1 (char *hookname
,
173 char *cond_string
, enum bptype bp_kind
);
175 static void create_fork_vfork_event_catchpoint (int tempflag
,
177 enum bptype bp_kind
);
179 static void break_at_finish_at_depth_command_1 (char *arg
,
180 int flag
, int from_tty
);
182 static void break_at_finish_command_1 (char *arg
, int flag
, int from_tty
);
184 static void stop_command (char *arg
, int from_tty
);
186 static void stopin_command (char *arg
, int from_tty
);
188 static void stopat_command (char *arg
, int from_tty
);
190 static char *ep_find_event_name_end (char *arg
);
192 static char *ep_parse_optional_if_clause (char **arg
);
194 static char *ep_parse_optional_filename (char **arg
);
196 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
197 static void catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
);
200 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
201 enum exception_event_kind ex_event
,
202 struct symtab_and_line
*sal
);
204 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
205 char *arg
, int tempflag
, int from_tty
);
207 static void tcatch_command (char *arg
, int from_tty
);
209 static void ep_skip_leading_whitespace (char **s
);
211 /* Prototypes for exported functions. */
213 /* If FALSE, gdb will not use hardware support for watchpoints, even
214 if such is available. */
215 static int can_use_hw_watchpoints
;
217 void _initialize_breakpoint (void);
219 extern int addressprint
; /* Print machine addresses? */
221 /* Are we executing breakpoint commands? */
222 static int executing_breakpoint_commands
;
224 /* Are overlay event breakpoints enabled? */
225 static int overlay_events_enabled
;
227 /* Walk the following statement or block through all breakpoints.
228 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
231 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
233 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
234 for (B = breakpoint_chain; \
235 B ? (TMP=B->next, 1): 0; \
238 /* Similar iterators for the low-level breakpoints. */
240 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->next)
242 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
243 for (B = bp_location_chain; \
244 B ? (TMP=B->next, 1): 0; \
247 /* True if SHIFT_INST_REGS defined, false otherwise. */
249 int must_shift_inst_regs
=
250 #if defined(SHIFT_INST_REGS)
257 /* True if breakpoint hit counts should be displayed in breakpoint info. */
259 int show_breakpoint_hit_counts
= 1;
261 /* Chains of all breakpoints defined. */
263 struct breakpoint
*breakpoint_chain
;
265 struct bp_location
*bp_location_chain
;
267 /* Number of last breakpoint made. */
269 int breakpoint_count
;
271 /* Pointer to current exception event record */
272 static struct exception_event_record
*current_exception_event
;
274 /* Indicator of whether exception catchpoints should be nuked
275 between runs of a program */
276 int exception_catchpoints_are_fragile
= 0;
278 /* Indicator of when exception catchpoints set-up should be
279 reinitialized -- e.g. when program is re-run */
280 int exception_support_initialized
= 0;
282 /* This function returns a pointer to the string representation of the
283 pathname of the dynamically-linked library that has just been
286 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
287 or undefined results are guaranteed.
289 This string's contents are only valid immediately after the
290 inferior has stopped in the dynamic linker hook, and becomes
291 invalid as soon as the inferior is continued. Clients should make
292 a copy of this string if they wish to continue the inferior and
293 then access the string. */
295 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
296 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
299 /* This function returns a pointer to the string representation of the
300 pathname of the dynamically-linked library that has just been
303 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
304 TRUE, or undefined results are guaranteed.
306 This string's contents are only valid immediately after the
307 inferior has stopped in the dynamic linker hook, and becomes
308 invalid as soon as the inferior is continued. Clients should make
309 a copy of this string if they wish to continue the inferior and
310 then access the string. */
312 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
313 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
316 /* This function is called by the "catch load" command. It allows the
317 debugger to be notified by the dynamic linker when a specified
318 library file (or any library file, if filename is NULL) is loaded. */
320 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
321 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
322 error ("catch of library loads not yet implemented on this platform")
325 /* This function is called by the "catch unload" command. It allows
326 the debugger to be notified by the dynamic linker when a specified
327 library file (or any library file, if filename is NULL) is
330 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
331 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
332 error ("catch of library unloads not yet implemented on this platform")
335 /* Set breakpoint count to NUM. */
338 set_breakpoint_count (int num
)
340 breakpoint_count
= num
;
341 set_internalvar (lookup_internalvar ("bpnum"),
342 value_from_longest (builtin_type_int
, (LONGEST
) num
));
345 /* Used in run_command to zero the hit count when a new run starts. */
348 clear_breakpoint_hit_counts (void)
350 struct breakpoint
*b
;
356 /* Default address, symtab and line to put a breakpoint at
357 for "break" command with no arg.
358 if default_breakpoint_valid is zero, the other three are
359 not valid, and "break" with no arg is an error.
361 This set by print_stack_frame, which calls set_default_breakpoint. */
363 int default_breakpoint_valid
;
364 CORE_ADDR default_breakpoint_address
;
365 struct symtab
*default_breakpoint_symtab
;
366 int default_breakpoint_line
;
368 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
369 Advance *PP after the string and any trailing whitespace.
371 Currently the string can either be a number or "$" followed by the name
372 of a convenience variable. Making it an expression wouldn't work well
373 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
375 TRAILER is a character which can be found after the number; most
376 commonly this is `-'. If you don't want a trailer, use \0. */
378 get_number_trailer (char **pp
, int trailer
)
380 int retval
= 0; /* default */
384 /* Empty line means refer to the last breakpoint. */
385 return breakpoint_count
;
388 /* Make a copy of the name, so we can null-terminate it
389 to pass to lookup_internalvar(). */
394 while (isalnum (*p
) || *p
== '_')
396 varname
= (char *) alloca (p
- start
+ 1);
397 strncpy (varname
, start
, p
- start
);
398 varname
[p
- start
] = '\0';
399 val
= value_of_internalvar (lookup_internalvar (varname
));
400 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
)
401 retval
= (int) value_as_long (val
);
404 printf_filtered ("Convenience variable must have integer value.\n");
412 while (*p
>= '0' && *p
<= '9')
415 /* There is no number here. (e.g. "cond a == b"). */
417 /* Skip non-numeric token */
418 while (*p
&& !isspace((int) *p
))
420 /* Return zero, which caller must interpret as error. */
426 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
428 /* Trailing junk: return 0 and let caller print error msg. */
429 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
440 /* Like get_number_trailer, but don't allow a trailer. */
442 get_number (char **pp
)
444 return get_number_trailer (pp
, '\0');
447 /* Parse a number or a range.
448 * A number will be of the form handled by get_number.
449 * A range will be of the form <number1> - <number2>, and
450 * will represent all the integers between number1 and number2,
453 * While processing a range, this fuction is called iteratively;
454 * At each call it will return the next value in the range.
456 * At the beginning of parsing a range, the char pointer PP will
457 * be advanced past <number1> and left pointing at the '-' token.
458 * Subsequent calls will not advance the pointer until the range
459 * is completed. The call that completes the range will advance
460 * pointer PP past <number2>.
464 get_number_or_range (char **pp
)
466 static int last_retval
, end_value
;
467 static char *end_ptr
;
468 static int in_range
= 0;
472 /* Default case: pp is pointing either to a solo number,
473 or to the first number of a range. */
474 last_retval
= get_number_trailer (pp
, '-');
479 /* This is the start of a range (<number1> - <number2>).
480 Skip the '-', parse and remember the second number,
481 and also remember the end of the final token. */
485 while (isspace ((int) *end_ptr
))
486 end_ptr
++; /* skip white space */
487 end_value
= get_number (temp
);
488 if (end_value
< last_retval
)
490 error ("inverted range");
492 else if (end_value
== last_retval
)
494 /* degenerate range (number1 == number2). Advance the
495 token pointer so that the range will be treated as a
504 error ("negative value");
507 /* pp points to the '-' that betokens a range. All
508 number-parsing has already been done. Return the next
509 integer value (one greater than the saved previous value).
510 Do not advance the token pointer 'pp' until the end of range
513 if (++last_retval
== end_value
)
515 /* End of range reached; advance token pointer. */
525 /* condition N EXP -- set break condition of breakpoint N to EXP. */
528 condition_command (char *arg
, int from_tty
)
530 struct breakpoint
*b
;
535 error_no_arg ("breakpoint number");
538 bnum
= get_number (&p
);
540 error ("Bad breakpoint argument: '%s'", arg
);
543 if (b
->number
== bnum
)
550 if (b
->cond_string
!= NULL
)
551 xfree (b
->cond_string
);
556 b
->cond_string
= NULL
;
558 printf_filtered ("Breakpoint %d now unconditional.\n", bnum
);
563 /* I don't know if it matters whether this is the string the user
564 typed in or the decompiled expression. */
565 b
->cond_string
= savestring (arg
, strlen (arg
));
566 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->loc
->address
), 0);
568 error ("Junk at end of expression");
570 breakpoints_changed ();
571 breakpoint_modify_event (b
->number
);
575 error ("No breakpoint number %d.", bnum
);
579 commands_command (char *arg
, int from_tty
)
581 struct breakpoint
*b
;
584 struct command_line
*l
;
586 /* If we allowed this, we would have problems with when to
587 free the storage, if we change the commands currently
590 if (executing_breakpoint_commands
)
591 error ("Can't use the \"commands\" command among a breakpoint's commands.");
594 bnum
= get_number (&p
);
597 error ("Unexpected extra arguments following breakpoint number.");
600 if (b
->number
== bnum
)
602 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
604 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
605 l
= read_command_lines (tmpbuf
, from_tty
);
606 do_cleanups (cleanups
);
607 free_command_lines (&b
->commands
);
609 breakpoints_changed ();
610 breakpoint_modify_event (b
->number
);
613 error ("No breakpoint number %d.", bnum
);
616 /* Like target_read_memory() but if breakpoints are inserted, return
617 the shadow contents instead of the breakpoints themselves.
619 Read "memory data" from whatever target or inferior we have.
620 Returns zero if successful, errno value if not. EIO is used
621 for address out of bounds. If breakpoints are inserted, returns
622 shadow contents, not the breakpoints themselves. From breakpoint.c. */
625 read_memory_nobpt (CORE_ADDR memaddr
, char *myaddr
, unsigned len
)
628 struct breakpoint
*b
;
629 CORE_ADDR bp_addr
= 0;
632 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
633 /* No breakpoints on this machine. */
634 return target_read_memory (memaddr
, myaddr
, len
);
638 if (b
->type
== bp_none
)
639 warning ("reading through apparently deleted breakpoint #%d?",
642 /* memory breakpoint? */
643 if (b
->type
== bp_watchpoint
644 || b
->type
== bp_hardware_watchpoint
645 || b
->type
== bp_read_watchpoint
646 || b
->type
== bp_access_watchpoint
)
649 if (!b
->loc
->inserted
)
651 /* Addresses and length of the part of the breakpoint that
653 /* XXXX The m68k, sh and h8300 have different local and remote
654 breakpoint values. BREAKPOINT_FROM_PC still manages to
655 correctly determine the breakpoints memory address and size
656 for these targets. */
657 bp_addr
= b
->loc
->address
;
659 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
664 if (bp_addr
+ bp_size
<= memaddr
)
665 /* The breakpoint is entirely before the chunk of memory we
668 if (bp_addr
>= memaddr
+ len
)
669 /* The breakpoint is entirely after the chunk of memory we are
672 /* Copy the breakpoint from the shadow contents, and recurse for
673 the things before and after. */
675 /* Offset within shadow_contents. */
678 if (bp_addr
< memaddr
)
680 /* Only copy the second part of the breakpoint. */
681 bp_size
-= memaddr
- bp_addr
;
682 bptoffset
= memaddr
- bp_addr
;
686 if (bp_addr
+ bp_size
> memaddr
+ len
)
688 /* Only copy the first part of the breakpoint. */
689 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
692 memcpy (myaddr
+ bp_addr
- memaddr
,
693 b
->loc
->shadow_contents
+ bptoffset
, bp_size
);
695 if (bp_addr
> memaddr
)
697 /* Copy the section of memory before the breakpoint. */
698 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
703 if (bp_addr
+ bp_size
< memaddr
+ len
)
705 /* Copy the section of memory after the breakpoint. */
706 status
= read_memory_nobpt (bp_addr
+ bp_size
,
707 myaddr
+ bp_addr
+ bp_size
- memaddr
,
708 memaddr
+ len
- (bp_addr
+ bp_size
));
715 /* Nothing overlaps. Just call read_memory_noerr. */
716 return target_read_memory (memaddr
, myaddr
, len
);
720 /* A wrapper function for inserting catchpoints. */
722 insert_catchpoint (struct ui_out
*uo
, void *args
)
724 struct breakpoint
*b
= (struct breakpoint
*) args
;
730 val
= target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
733 val
= target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
736 val
= target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
739 internal_error (__FILE__
, __LINE__
, "unknown breakpoint type");
744 throw_exception (RETURN_ERROR
);
749 /* insert_breakpoints is used when starting or continuing the program.
750 remove_breakpoints is used when the program stops.
751 Both return zero if successful,
752 or an `errno' value if could not write the inferior. */
755 insert_breakpoints (void)
757 struct breakpoint
*b
, *temp
;
758 int return_val
= 0; /* return success code. */
760 int disabled_breaks
= 0;
761 int hw_breakpoint_error
= 0;
762 #ifdef ONE_PROCESS_WRITETEXT
763 int process_warning
= 0;
766 struct ui_file
*tmp_error_stream
= mem_fileopen ();
767 make_cleanup_ui_file_delete (tmp_error_stream
);
769 /* Explicitly mark the warning -- this will only be printed if
770 there was an error. */
771 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
773 ALL_BREAKPOINTS_SAFE (b
, temp
)
775 /* Permanent breakpoints cannot be inserted or removed. Disabled
776 breakpoints should not be inserted. */
777 if (b
->enable_state
!= bp_enabled
)
780 if ((b
->type
== bp_watchpoint
781 || b
->type
== bp_hardware_watchpoint
782 || b
->type
== bp_read_watchpoint
783 || b
->type
== bp_access_watchpoint
) && (!b
->val
))
786 val
= evaluate_expression (b
->exp
);
788 if (VALUE_LAZY (val
))
789 value_fetch_lazy (val
);
792 if (b
->type
!= bp_watchpoint
793 && b
->type
!= bp_hardware_watchpoint
794 && b
->type
!= bp_read_watchpoint
795 && b
->type
!= bp_access_watchpoint
796 && b
->type
!= bp_catch_fork
797 && b
->type
!= bp_catch_vfork
798 && b
->type
!= bp_catch_exec
799 && b
->type
!= bp_catch_throw
800 && b
->type
!= bp_catch_catch
802 && !b
->loc
->duplicate
)
804 /* "Normal" instruction breakpoint: either the standard
805 trap-instruction bp (bp_breakpoint), or a
806 bp_hardware_breakpoint. */
808 /* First check to see if we have to handle an overlay. */
809 if (overlay_debugging
== ovly_off
810 || b
->section
== NULL
811 || !(section_is_overlay (b
->section
)))
813 /* No overlay handling: just set the breakpoint. */
815 if (b
->type
== bp_hardware_breakpoint
)
816 val
= target_insert_hw_breakpoint (b
->loc
->address
,
817 b
->loc
->shadow_contents
);
819 val
= target_insert_breakpoint (b
->loc
->address
, b
->loc
->shadow_contents
);
823 /* This breakpoint is in an overlay section.
824 Shall we set a breakpoint at the LMA? */
825 if (!overlay_events_enabled
)
827 /* Yes -- overlay event support is not active,
828 so we must try to set a breakpoint at the LMA.
829 This will not work for a hardware breakpoint. */
830 if (b
->type
== bp_hardware_breakpoint
)
831 warning ("hardware breakpoint %d not supported in overlay!\n",
835 CORE_ADDR addr
= overlay_unmapped_address (b
->loc
->address
,
837 /* Set a software (trap) breakpoint at the LMA. */
838 val
= target_insert_breakpoint (addr
, b
->loc
->shadow_contents
);
840 fprintf_unfiltered (tmp_error_stream
,
841 "Overlay breakpoint %d failed: in ROM?",
845 /* Shall we set a breakpoint at the VMA? */
846 if (section_is_mapped (b
->section
))
848 /* Yes. This overlay section is mapped into memory. */
849 if (b
->type
== bp_hardware_breakpoint
)
850 val
= target_insert_hw_breakpoint (b
->loc
->address
,
851 b
->loc
->shadow_contents
);
853 val
= target_insert_breakpoint (b
->loc
->address
,
854 b
->loc
->shadow_contents
);
858 /* No. This breakpoint will not be inserted.
859 No error, but do not mark the bp as 'inserted'. */
866 /* Can't set the breakpoint. */
867 #if defined (DISABLE_UNSETTABLE_BREAK)
868 if (DISABLE_UNSETTABLE_BREAK (b
->loc
->address
))
870 /* See also: disable_breakpoints_in_shlibs. */
872 b
->enable_state
= bp_shlib_disabled
;
873 if (!disabled_breaks
)
875 fprintf_unfiltered (tmp_error_stream
,
876 "Cannot insert breakpoint %d.\n",
878 fprintf_unfiltered (tmp_error_stream
,
879 "Temporarily disabling shared library breakpoints:\n");
882 fprintf_unfiltered (tmp_error_stream
,
883 "breakpoint #%d\n", b
->number
);
888 #ifdef ONE_PROCESS_WRITETEXT
891 if (b
->type
== bp_hardware_breakpoint
)
893 hw_breakpoint_error
= 1;
894 fprintf_unfiltered (tmp_error_stream
,
895 "Cannot insert hardware breakpoint %d.\n",
900 fprintf_unfiltered (tmp_error_stream
,
901 "Cannot insert breakpoint %d.\n",
903 fprintf_filtered (tmp_error_stream
,
904 "Error accessing memory address ");
905 print_address_numeric (b
->loc
->address
, 1, tmp_error_stream
);
906 fprintf_filtered (tmp_error_stream
, ": %s.\n",
907 safe_strerror (val
));
913 b
->loc
->inserted
= 1;
916 return_val
= val
; /* remember failure */
918 else if (ep_is_exception_catchpoint (b
)
920 && !b
->loc
->duplicate
)
923 /* If we get here, we must have a callback mechanism for exception
924 events -- with g++ style embedded label support, we insert
925 ordinary breakpoints and not catchpoints. */
926 val
= target_insert_breakpoint (b
->loc
->address
, b
->loc
->shadow_contents
);
929 /* Couldn't set breakpoint for some reason */
930 fprintf_unfiltered (tmp_error_stream
,
931 "Cannot insert catchpoint %d; disabling it.\n",
933 fprintf_filtered (tmp_error_stream
,
934 "Error accessing memory address ");
935 print_address_numeric (b
->loc
->address
, 1, tmp_error_stream
);
936 fprintf_filtered (tmp_error_stream
, ": %s.\n",
937 safe_strerror (val
));
938 b
->enable_state
= bp_disabled
;
942 /* Bp set, now make sure callbacks are enabled */
943 /* Format possible error msg */
944 char *message
= xstrprintf ("Error inserting catchpoint %d:\n",
946 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
948 args_for_catchpoint_enable args
;
949 args
.kind
= b
->type
== bp_catch_catch
?
950 EX_EVENT_CATCH
: EX_EVENT_THROW
;
952 val
= catch_errors (cover_target_enable_exception_callback
,
953 &args
, message
, RETURN_MASK_ALL
);
954 do_cleanups (cleanups
);
955 if (val
!= 0 && val
!= -1)
957 b
->loc
->inserted
= 1;
959 /* Check if something went wrong; val == 0 can be ignored */
962 /* something went wrong */
963 fprintf_unfiltered (tmp_error_stream
,
964 "Cannot insert catchpoint %d; disabling it.\n",
966 b
->enable_state
= bp_disabled
;
971 return_val
= val
; /* remember failure */
974 else if ((b
->type
== bp_hardware_watchpoint
||
975 b
->type
== bp_read_watchpoint
||
976 b
->type
== bp_access_watchpoint
)
977 && b
->disposition
!= disp_del_at_next_stop
979 && !b
->loc
->duplicate
)
981 struct frame_info
*saved_frame
;
982 int saved_level
, within_current_scope
;
983 struct value
*mark
= value_mark ();
986 /* Save the current frame and level so we can restore it after
987 evaluating the watchpoint expression on its own frame. */
988 saved_frame
= deprecated_selected_frame
;
989 saved_level
= frame_relative_level (deprecated_selected_frame
);
991 /* Determine if the watchpoint is within scope. */
992 if (b
->exp_valid_block
== NULL
)
993 within_current_scope
= 1;
996 struct frame_info
*fi
;
997 fi
= frame_find_by_id (b
->watchpoint_frame
);
998 within_current_scope
= (fi
!= NULL
);
999 if (within_current_scope
)
1003 if (within_current_scope
)
1005 /* Evaluate the expression and cut the chain of values
1006 produced off from the value chain.
1008 Make sure the value returned isn't lazy; we use
1009 laziness to determine what memory GDB actually needed
1010 in order to compute the value of the expression. */
1011 v
= evaluate_expression (b
->exp
);
1013 value_release_to_mark (mark
);
1016 b
->loc
->inserted
= 1;
1018 /* Look at each value on the value chain. */
1019 for (; v
; v
= v
->next
)
1021 /* If it's a memory location, and GDB actually needed
1022 its contents to evaluate the expression, then we
1024 if (VALUE_LVAL (v
) == lval_memory
1025 && ! VALUE_LAZY (v
))
1027 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
1029 /* We only watch structs and arrays if user asked
1030 for it explicitly, never if they just happen to
1031 appear in the middle of some value chain. */
1032 if (v
== b
->val_chain
1033 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1034 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1039 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1040 len
= TYPE_LENGTH (VALUE_TYPE (v
));
1042 if (b
->type
== bp_read_watchpoint
)
1044 else if (b
->type
== bp_access_watchpoint
)
1047 val
= target_insert_watchpoint (addr
, len
, type
);
1050 /* Don't exit the loop, try to insert
1051 every value on the value chain. That's
1052 because we will be removing all the
1053 watches below, and removing a
1054 watchpoint we didn't insert could have
1056 b
->loc
->inserted
= 0;
1062 /* Failure to insert a watchpoint on any memory value in the
1063 value chain brings us here. */
1064 if (!b
->loc
->inserted
)
1066 remove_breakpoint (b
, mark_uninserted
);
1067 hw_breakpoint_error
= 1;
1068 fprintf_unfiltered (tmp_error_stream
,
1069 "Could not insert hardware watchpoint %d.\n",
1076 printf_filtered ("Hardware watchpoint %d deleted ", b
->number
);
1077 printf_filtered ("because the program has left the block \n");
1078 printf_filtered ("in which its expression is valid.\n");
1079 if (b
->related_breakpoint
)
1080 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1081 b
->disposition
= disp_del_at_next_stop
;
1084 /* Restore the frame and level. */
1085 if ((saved_frame
!= deprecated_selected_frame
) ||
1086 (saved_level
!= frame_relative_level (deprecated_selected_frame
)))
1087 select_frame (saved_frame
);
1090 return_val
= val
; /* remember failure */
1092 else if ((b
->type
== bp_catch_fork
1093 || b
->type
== bp_catch_vfork
1094 || b
->type
== bp_catch_exec
)
1095 && !b
->loc
->inserted
1096 && !b
->loc
->duplicate
)
1098 char *prefix
= xstrprintf ("warning: inserting catchpoint %d: ",
1100 struct cleanup
*cleanups
= make_cleanup (xfree
, prefix
);
1101 val
= catch_exceptions (uiout
, insert_catchpoint
, b
, prefix
,
1103 do_cleanups (cleanups
);
1105 b
->enable_state
= bp_disabled
;
1107 b
->loc
->inserted
= 1;
1113 /* If a hardware breakpoint or watchpoint was inserted, add a
1114 message about possibly exhausted resources. */
1115 if (hw_breakpoint_error
)
1117 fprintf_unfiltered (tmp_error_stream
,
1118 "Could not insert hardware breakpoints:\n\
1119 You may have requested too many hardware breakpoints/watchpoints.\n");
1121 #ifdef ONE_PROCESS_WRITETEXT
1122 if (process_warning
)
1123 fprintf_unfiltered (tmp_error_stream
,
1124 "The same program may be running in another process.");
1126 target_terminal_ours_for_output ();
1127 error_stream (tmp_error_stream
);
1133 remove_breakpoints (void)
1135 struct breakpoint
*b
;
1140 if (b
->loc
->inserted
)
1142 val
= remove_breakpoint (b
, mark_uninserted
);
1151 remove_hw_watchpoints (void)
1153 struct breakpoint
*b
;
1158 if (b
->loc
->inserted
1159 && (b
->type
== bp_hardware_watchpoint
1160 || b
->type
== bp_read_watchpoint
1161 || b
->type
== bp_access_watchpoint
))
1163 val
= remove_breakpoint (b
, mark_uninserted
);
1172 reattach_breakpoints (int pid
)
1174 struct breakpoint
*b
;
1176 struct cleanup
*old_chain
= save_inferior_ptid ();
1178 /* Set inferior_ptid; remove_breakpoint uses this global. */
1179 inferior_ptid
= pid_to_ptid (pid
);
1182 if (b
->loc
->inserted
)
1184 remove_breakpoint (b
, mark_inserted
);
1185 if (b
->type
== bp_hardware_breakpoint
)
1186 val
= target_insert_hw_breakpoint (b
->loc
->address
, b
->loc
->shadow_contents
);
1188 val
= target_insert_breakpoint (b
->loc
->address
, b
->loc
->shadow_contents
);
1191 do_cleanups (old_chain
);
1196 do_cleanups (old_chain
);
1201 update_breakpoints_after_exec (void)
1203 struct breakpoint
*b
;
1204 struct breakpoint
*temp
;
1206 /* Doing this first prevents the badness of having delete_breakpoint()
1207 write a breakpoint's current "shadow contents" to lift the bp. That
1208 shadow is NOT valid after an exec()! */
1209 mark_breakpoints_out ();
1211 ALL_BREAKPOINTS_SAFE (b
, temp
)
1213 /* Solib breakpoints must be explicitly reset after an exec(). */
1214 if (b
->type
== bp_shlib_event
)
1216 delete_breakpoint (b
);
1220 /* Thread event breakpoints must be set anew after an exec(),
1221 as must overlay event breakpoints. */
1222 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1224 delete_breakpoint (b
);
1228 /* Step-resume breakpoints are meaningless after an exec(). */
1229 if (b
->type
== bp_step_resume
)
1231 delete_breakpoint (b
);
1235 /* Ditto the sigtramp handler breakpoints. */
1236 if (b
->type
== bp_through_sigtramp
)
1238 delete_breakpoint (b
);
1242 /* Ditto the exception-handling catchpoints. */
1243 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1245 delete_breakpoint (b
);
1249 /* Don't delete an exec catchpoint, because else the inferior
1250 won't stop when it ought!
1252 Similarly, we probably ought to keep vfork catchpoints, 'cause
1253 on this target, we may not be able to stop when the vfork is
1254 seen, but only when the subsequent exec is seen. (And because
1255 deleting fork catchpoints here but not vfork catchpoints will
1256 seem mysterious to users, keep those too.)
1258 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1259 target address field, if any, is sufficient to have it be reset
1260 automagically. Certainly on HP-UX that's true.
1262 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1263 valid code address on some platforms (like the mn10300
1264 simulators). We shouldn't assign any special interpretation to
1265 a breakpoint with a zero address. And in fact, GDB doesn't ---
1266 I can't see what that comment above is talking about. As far
1267 as I can tell, setting the address of a
1268 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1269 is meaningless, since those are implemented with HP-UX kernel
1270 hackery, not by storing breakpoint instructions somewhere. */
1271 if ((b
->type
== bp_catch_exec
) ||
1272 (b
->type
== bp_catch_vfork
) ||
1273 (b
->type
== bp_catch_fork
))
1275 b
->loc
->address
= (CORE_ADDR
) NULL
;
1279 /* bp_finish is a special case. The only way we ought to be able
1280 to see one of these when an exec() has happened, is if the user
1281 caught a vfork, and then said "finish". Ordinarily a finish just
1282 carries them to the call-site of the current callee, by setting
1283 a temporary bp there and resuming. But in this case, the finish
1284 will carry them entirely through the vfork & exec.
1286 We don't want to allow a bp_finish to remain inserted now. But
1287 we can't safely delete it, 'cause finish_command has a handle to
1288 the bp on a bpstat, and will later want to delete it. There's a
1289 chance (and I've seen it happen) that if we delete the bp_finish
1290 here, that its storage will get reused by the time finish_command
1291 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1292 We really must allow finish_command to delete a bp_finish.
1294 In the absense of a general solution for the "how do we know
1295 it's safe to delete something others may have handles to?"
1296 problem, what we'll do here is just uninsert the bp_finish, and
1297 let finish_command delete it.
1299 (We know the bp_finish is "doomed" in the sense that it's
1300 momentary, and will be deleted as soon as finish_command sees
1301 the inferior stopped. So it doesn't matter that the bp's
1302 address is probably bogus in the new a.out, unlike e.g., the
1303 solib breakpoints.) */
1305 if (b
->type
== bp_finish
)
1310 /* Without a symbolic address, we have little hope of the
1311 pre-exec() address meaning the same thing in the post-exec()
1313 if (b
->addr_string
== NULL
)
1315 delete_breakpoint (b
);
1319 /* If this breakpoint has survived the above battery of checks, then
1320 it must have a symbolic address. Be sure that it gets reevaluated
1321 to a target address, rather than reusing the old evaluation.
1323 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1324 for bp_catch_exec and friends, I'm pretty sure this is entirely
1325 unnecessary. A call to breakpoint_re_set_one always recomputes
1326 the breakpoint's address from scratch, or deletes it if it can't.
1327 So I think this assignment could be deleted without effect. */
1328 b
->loc
->address
= (CORE_ADDR
) NULL
;
1330 /* FIXME what about longjmp breakpoints? Re-create them here? */
1331 create_overlay_event_breakpoint ("_ovly_debug_event");
1335 detach_breakpoints (int pid
)
1337 struct breakpoint
*b
;
1339 struct cleanup
*old_chain
= save_inferior_ptid ();
1341 if (pid
== PIDGET (inferior_ptid
))
1342 error ("Cannot detach breakpoints of inferior_ptid");
1344 /* Set inferior_ptid; remove_breakpoint uses this global. */
1345 inferior_ptid
= pid_to_ptid (pid
);
1348 if (b
->loc
->inserted
)
1350 val
= remove_breakpoint (b
, mark_inserted
);
1353 do_cleanups (old_chain
);
1358 do_cleanups (old_chain
);
1363 remove_breakpoint (struct breakpoint
*b
, insertion_state_t is
)
1367 if (b
->enable_state
== bp_permanent
)
1368 /* Permanent breakpoints cannot be inserted or removed. */
1371 if (b
->type
== bp_none
)
1372 warning ("attempted to remove apparently deleted breakpoint #%d?",
1375 if (b
->type
!= bp_watchpoint
1376 && b
->type
!= bp_hardware_watchpoint
1377 && b
->type
!= bp_read_watchpoint
1378 && b
->type
!= bp_access_watchpoint
1379 && b
->type
!= bp_catch_fork
1380 && b
->type
!= bp_catch_vfork
1381 && b
->type
!= bp_catch_exec
1382 && b
->type
!= bp_catch_catch
1383 && b
->type
!= bp_catch_throw
)
1385 /* "Normal" instruction breakpoint: either the standard
1386 trap-instruction bp (bp_breakpoint), or a
1387 bp_hardware_breakpoint. */
1389 /* First check to see if we have to handle an overlay. */
1390 if (overlay_debugging
== ovly_off
1391 || b
->section
== NULL
1392 || !(section_is_overlay (b
->section
)))
1394 /* No overlay handling: just remove the breakpoint. */
1396 if (b
->type
== bp_hardware_breakpoint
)
1397 val
= target_remove_hw_breakpoint (b
->loc
->address
,
1398 b
->loc
->shadow_contents
);
1400 val
= target_remove_breakpoint (b
->loc
->address
, b
->loc
->shadow_contents
);
1404 /* This breakpoint is in an overlay section.
1405 Did we set a breakpoint at the LMA? */
1406 if (!overlay_events_enabled
)
1408 /* Yes -- overlay event support is not active, so we
1409 should have set a breakpoint at the LMA. Remove it.
1411 CORE_ADDR addr
= overlay_unmapped_address (b
->loc
->address
,
1413 /* Ignore any failures: if the LMA is in ROM, we will
1414 have already warned when we failed to insert it. */
1415 if (b
->type
!= bp_hardware_breakpoint
)
1416 target_remove_hw_breakpoint (addr
, b
->loc
->shadow_contents
);
1418 target_remove_breakpoint (addr
, b
->loc
->shadow_contents
);
1420 /* Did we set a breakpoint at the VMA?
1421 If so, we will have marked the breakpoint 'inserted'. */
1422 if (b
->loc
->inserted
)
1424 /* Yes -- remove it. Previously we did not bother to
1425 remove the breakpoint if the section had been
1426 unmapped, but let's not rely on that being safe. We
1427 don't know what the overlay manager might do. */
1428 if (b
->type
== bp_hardware_breakpoint
)
1429 val
= target_remove_hw_breakpoint (b
->loc
->address
,
1430 b
->loc
->shadow_contents
);
1432 val
= target_remove_breakpoint (b
->loc
->address
,
1433 b
->loc
->shadow_contents
);
1437 /* No -- not inserted, so no need to remove. No error. */
1443 b
->loc
->inserted
= (is
== mark_inserted
);
1445 else if ((b
->type
== bp_hardware_watchpoint
||
1446 b
->type
== bp_read_watchpoint
||
1447 b
->type
== bp_access_watchpoint
)
1448 && b
->enable_state
== bp_enabled
1449 && !b
->loc
->duplicate
)
1454 b
->loc
->inserted
= (is
== mark_inserted
);
1455 /* Walk down the saved value chain. */
1456 for (v
= b
->val_chain
; v
; v
= v
->next
)
1458 /* For each memory reference remove the watchpoint
1460 if (VALUE_LVAL (v
) == lval_memory
1461 && ! VALUE_LAZY (v
))
1463 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
1465 if (v
== b
->val_chain
1466 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1467 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1472 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1473 len
= TYPE_LENGTH (VALUE_TYPE (v
));
1475 if (b
->type
== bp_read_watchpoint
)
1477 else if (b
->type
== bp_access_watchpoint
)
1480 val
= target_remove_watchpoint (addr
, len
, type
);
1482 b
->loc
->inserted
= 1;
1487 /* Failure to remove any of the hardware watchpoints comes here. */
1488 if ((is
== mark_uninserted
) && (b
->loc
->inserted
))
1489 warning ("Could not remove hardware watchpoint %d.",
1492 /* Free the saved value chain. We will construct a new one
1493 the next time the watchpoint is inserted. */
1494 for (v
= b
->val_chain
; v
; v
= n
)
1499 b
->val_chain
= NULL
;
1501 else if ((b
->type
== bp_catch_fork
||
1502 b
->type
== bp_catch_vfork
||
1503 b
->type
== bp_catch_exec
)
1504 && b
->enable_state
== bp_enabled
1505 && !b
->loc
->duplicate
)
1511 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1513 case bp_catch_vfork
:
1514 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1517 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1520 warning ("Internal error, %s line %d.", __FILE__
, __LINE__
);
1525 b
->loc
->inserted
= (is
== mark_inserted
);
1527 else if ((b
->type
== bp_catch_catch
||
1528 b
->type
== bp_catch_throw
)
1529 && b
->enable_state
== bp_enabled
1530 && !b
->loc
->duplicate
)
1533 val
= target_remove_breakpoint (b
->loc
->address
, b
->loc
->shadow_contents
);
1536 b
->loc
->inserted
= (is
== mark_inserted
);
1538 else if (ep_is_exception_catchpoint (b
)
1539 && b
->loc
->inserted
/* sometimes previous insert doesn't happen */
1540 && b
->enable_state
== bp_enabled
1541 && !b
->loc
->duplicate
)
1544 val
= target_remove_breakpoint (b
->loc
->address
, b
->loc
->shadow_contents
);
1548 b
->loc
->inserted
= (is
== mark_inserted
);
1554 /* Clear the "inserted" flag in all breakpoints. */
1557 mark_breakpoints_out (void)
1559 struct breakpoint
*b
;
1562 b
->loc
->inserted
= 0;
1565 /* Clear the "inserted" flag in all breakpoints and delete any
1566 breakpoints which should go away between runs of the program.
1568 Plus other such housekeeping that has to be done for breakpoints
1571 Note: this function gets called at the end of a run (by
1572 generic_mourn_inferior) and when a run begins (by
1573 init_wait_for_inferior). */
1578 breakpoint_init_inferior (enum inf_context context
)
1580 struct breakpoint
*b
, *temp
;
1581 static int warning_needed
= 0;
1583 ALL_BREAKPOINTS_SAFE (b
, temp
)
1585 b
->loc
->inserted
= 0;
1590 case bp_watchpoint_scope
:
1592 /* If the call dummy breakpoint is at the entry point it will
1593 cause problems when the inferior is rerun, so we better
1596 Also get rid of scope breakpoints. */
1597 delete_breakpoint (b
);
1601 case bp_hardware_watchpoint
:
1602 case bp_read_watchpoint
:
1603 case bp_access_watchpoint
:
1605 /* Likewise for watchpoints on local expressions. */
1606 if (b
->exp_valid_block
!= NULL
)
1607 delete_breakpoint (b
);
1608 if (context
== inf_starting
)
1610 /* Reset val field to force reread of starting value
1611 in insert_breakpoints. */
1613 value_free (b
->val
);
1618 /* Likewise for exception catchpoints in dynamic-linked
1619 executables where required */
1620 if (ep_is_exception_catchpoint (b
) &&
1621 exception_catchpoints_are_fragile
)
1624 delete_breakpoint (b
);
1630 if (exception_catchpoints_are_fragile
)
1631 exception_support_initialized
= 0;
1633 /* Don't issue the warning unless it's really needed... */
1634 if (warning_needed
&& (context
!= inf_exited
))
1636 warning ("Exception catchpoints from last run were deleted.");
1637 warning ("You must reinsert them explicitly.");
1642 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1643 exists at PC. It returns ordinary_breakpoint_here if it's an
1644 ordinary breakpoint, or permanent_breakpoint_here if it's a
1645 permanent breakpoint.
1646 - When continuing from a location with an ordinary breakpoint, we
1647 actually single step once before calling insert_breakpoints.
1648 - When continuing from a localion with a permanent breakpoint, we
1649 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1650 the target, to advance the PC past the breakpoint. */
1652 enum breakpoint_here
1653 breakpoint_here_p (CORE_ADDR pc
)
1655 struct breakpoint
*b
;
1656 int any_breakpoint_here
= 0;
1659 if ((b
->enable_state
== bp_enabled
1660 || b
->enable_state
== bp_permanent
)
1661 && b
->loc
->address
== pc
) /* bp is enabled and matches pc */
1663 if (overlay_debugging
1664 && section_is_overlay (b
->section
)
1665 && !section_is_mapped (b
->section
))
1666 continue; /* unmapped overlay -- can't be a match */
1667 else if (b
->enable_state
== bp_permanent
)
1668 return permanent_breakpoint_here
;
1670 any_breakpoint_here
= 1;
1673 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1677 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1678 but it only returns true if there is actually a breakpoint inserted
1682 breakpoint_inserted_here_p (CORE_ADDR pc
)
1684 struct breakpoint
*b
;
1687 if (b
->loc
->inserted
1688 && b
->loc
->address
== pc
) /* bp is inserted and matches pc */
1690 if (overlay_debugging
1691 && section_is_overlay (b
->section
)
1692 && !section_is_mapped (b
->section
))
1693 continue; /* unmapped overlay -- can't be a match */
1701 /* Return nonzero if FRAME is a dummy frame. We can't use
1702 DEPRECATED_PC_IN_CALL_DUMMY because figuring out the saved SP would
1703 take too much time, at least using frame_register() on the 68k.
1704 This means that for this function to work right a port must use the
1705 bp_call_dummy breakpoint. */
1708 deprecated_frame_in_dummy (struct frame_info
*frame
)
1710 struct breakpoint
*b
;
1712 /* This function is used by two files: get_frame_type(), after first
1713 checking that !DEPRECATED_USE_GENERIC_DUMMY_FRAMES; and
1714 sparc-tdep.c, which doesn't yet use generic dummy frames anyway. */
1715 gdb_assert (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES
);
1719 if (b
->type
== bp_call_dummy
1720 && frame_id_eq (b
->frame_id
, get_frame_id (frame
))
1721 /* We need to check the PC as well as the frame on the sparc,
1722 for signals.exp in the testsuite. */
1723 && (get_frame_pc (frame
)
1725 - DEPRECATED_SIZEOF_CALL_DUMMY_WORDS
/ sizeof (LONGEST
) * DEPRECATED_REGISTER_SIZE
))
1726 && get_frame_pc (frame
) <= b
->loc
->address
)
1732 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1733 PC is valid for process/thread PID. */
1736 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1738 struct breakpoint
*b
;
1741 thread
= pid_to_thread_id (ptid
);
1744 if (b
->enable_state
!= bp_disabled
1745 && b
->enable_state
!= bp_shlib_disabled
1746 && b
->enable_state
!= bp_call_disabled
1747 && b
->loc
->address
== pc
1748 && (b
->thread
== -1 || b
->thread
== thread
))
1750 if (overlay_debugging
1751 && section_is_overlay (b
->section
)
1752 && !section_is_mapped (b
->section
))
1753 continue; /* unmapped overlay -- can't be a match */
1762 /* bpstat stuff. External routines' interfaces are documented
1766 ep_is_catchpoint (struct breakpoint
*ep
)
1769 (ep
->type
== bp_catch_load
)
1770 || (ep
->type
== bp_catch_unload
)
1771 || (ep
->type
== bp_catch_fork
)
1772 || (ep
->type
== bp_catch_vfork
)
1773 || (ep
->type
== bp_catch_exec
)
1774 || (ep
->type
== bp_catch_catch
)
1775 || (ep
->type
== bp_catch_throw
);
1777 /* ??rehrauer: Add more kinds here, as are implemented... */
1781 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1784 (ep
->type
== bp_catch_load
)
1785 || (ep
->type
== bp_catch_unload
);
1789 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1792 (ep
->type
== bp_catch_catch
)
1793 || (ep
->type
== bp_catch_throw
);
1796 /* Clear a bpstat so that it says we are not at any breakpoint.
1797 Also free any storage that is part of a bpstat. */
1800 bpstat_clear (bpstat
*bsp
)
1811 if (p
->old_val
!= NULL
)
1812 value_free (p
->old_val
);
1813 free_command_lines (&p
->commands
);
1820 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1821 is part of the bpstat is copied as well. */
1824 bpstat_copy (bpstat bs
)
1828 bpstat retval
= NULL
;
1833 for (; bs
!= NULL
; bs
= bs
->next
)
1835 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1836 memcpy (tmp
, bs
, sizeof (*tmp
));
1837 if (bs
->commands
!= NULL
)
1838 tmp
->commands
= copy_command_lines (bs
->commands
);
1839 if (bs
->old_val
!= NULL
)
1840 tmp
->old_val
= value_copy (bs
->old_val
);
1843 /* This is the first thing in the chain. */
1853 /* Find the bpstat associated with this breakpoint */
1856 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1861 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1863 if (bsp
->breakpoint_at
== breakpoint
)
1869 /* Find a step_resume breakpoint associated with this bpstat.
1870 (If there are multiple step_resume bp's on the list, this function
1871 will arbitrarily pick one.)
1873 It is an error to use this function if BPSTAT doesn't contain a
1874 step_resume breakpoint.
1876 See wait_for_inferior's use of this function. */
1878 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1883 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1885 current_thread
= pid_to_thread_id (inferior_ptid
);
1887 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1889 if ((bsp
->breakpoint_at
!= NULL
) &&
1890 (bsp
->breakpoint_at
->type
== bp_step_resume
) &&
1891 (bsp
->breakpoint_at
->thread
== current_thread
||
1892 bsp
->breakpoint_at
->thread
== -1))
1893 return bsp
->breakpoint_at
;
1896 error ("Internal error (no step_resume breakpoint found)");
1900 /* Return the breakpoint number of the first breakpoint we are stopped
1901 at. *BSP upon return is a bpstat which points to the remaining
1902 breakpoints stopped at (but which is not guaranteed to be good for
1903 anything but further calls to bpstat_num).
1904 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1907 bpstat_num (bpstat
*bsp
)
1909 struct breakpoint
*b
;
1912 return 0; /* No more breakpoint values */
1915 b
= (*bsp
)->breakpoint_at
;
1916 *bsp
= (*bsp
)->next
;
1918 return -1; /* breakpoint that's been deleted since */
1920 return b
->number
; /* We have its number */
1924 /* Modify BS so that the actions will not be performed. */
1927 bpstat_clear_actions (bpstat bs
)
1929 for (; bs
!= NULL
; bs
= bs
->next
)
1931 free_command_lines (&bs
->commands
);
1932 if (bs
->old_val
!= NULL
)
1934 value_free (bs
->old_val
);
1940 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1942 cleanup_executing_breakpoints (void *ignore
)
1944 executing_breakpoint_commands
= 0;
1947 /* Execute all the commands associated with all the breakpoints at this
1948 location. Any of these commands could cause the process to proceed
1949 beyond this point, etc. We look out for such changes by checking
1950 the global "breakpoint_proceeded" after each command. */
1953 bpstat_do_actions (bpstat
*bsp
)
1956 struct cleanup
*old_chain
;
1957 struct command_line
*cmd
;
1959 /* Avoid endless recursion if a `source' command is contained
1961 if (executing_breakpoint_commands
)
1964 executing_breakpoint_commands
= 1;
1965 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
1968 /* Note that (as of this writing), our callers all appear to
1969 be passing us the address of global stop_bpstat. And, if
1970 our calls to execute_control_command cause the inferior to
1971 proceed, that global (and hence, *bsp) will change.
1973 We must be careful to not touch *bsp unless the inferior
1974 has not proceeded. */
1976 /* This pointer will iterate over the list of bpstat's. */
1979 breakpoint_proceeded
= 0;
1980 for (; bs
!= NULL
; bs
= bs
->next
)
1985 execute_control_command (cmd
);
1987 if (breakpoint_proceeded
)
1992 if (breakpoint_proceeded
)
1993 /* The inferior is proceeded by the command; bomb out now.
1994 The bpstat chain has been blown away by wait_for_inferior.
1995 But since execution has stopped again, there is a new bpstat
1996 to look at, so start over. */
1999 free_command_lines (&bs
->commands
);
2001 do_cleanups (old_chain
);
2004 /* This is the normal print function for a bpstat. In the future,
2005 much of this logic could (should?) be moved to bpstat_stop_status,
2006 by having it set different print_it values.
2008 Current scheme: When we stop, bpstat_print() is called. It loops
2009 through the bpstat list of things causing this stop, calling the
2010 print_bp_stop_message function on each one. The behavior of the
2011 print_bp_stop_message function depends on the print_it field of
2012 bpstat. If such field so indicates, call this function here.
2014 Return values from this routine (ultimately used by bpstat_print()
2015 and normal_stop() to decide what to do):
2016 PRINT_NOTHING: Means we already printed all we needed to print,
2017 don't print anything else.
2018 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2019 that something to be followed by a location.
2020 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2021 that something to be followed by a location.
2022 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2025 static enum print_stop_action
2026 print_it_typical (bpstat bs
)
2028 struct cleanup
*old_chain
, *ui_out_chain
;
2029 struct ui_stream
*stb
;
2030 stb
= ui_out_stream_new (uiout
);
2031 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2032 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2033 which has since been deleted. */
2034 if (bs
->breakpoint_at
== NULL
)
2035 return PRINT_UNKNOWN
;
2037 switch (bs
->breakpoint_at
->type
)
2040 case bp_hardware_breakpoint
:
2041 if (bs
->breakpoint_at
->loc
->address
!= bs
->breakpoint_at
->loc
->requested_address
)
2042 breakpoint_adjustment_warning (bs
->breakpoint_at
->loc
->requested_address
,
2043 bs
->breakpoint_at
->loc
->address
,
2044 bs
->breakpoint_at
->number
, 1);
2045 annotate_breakpoint (bs
->breakpoint_at
->number
);
2046 ui_out_text (uiout
, "\nBreakpoint ");
2047 if (ui_out_is_mi_like_p (uiout
))
2048 ui_out_field_string (uiout
, "reason", "breakpoint-hit");
2049 ui_out_field_int (uiout
, "bkptno", bs
->breakpoint_at
->number
);
2050 ui_out_text (uiout
, ", ");
2051 return PRINT_SRC_AND_LOC
;
2054 case bp_shlib_event
:
2055 /* Did we stop because the user set the stop_on_solib_events
2056 variable? (If so, we report this as a generic, "Stopped due
2057 to shlib event" message.) */
2058 printf_filtered ("Stopped due to shared library event\n");
2059 return PRINT_NOTHING
;
2062 case bp_thread_event
:
2063 /* Not sure how we will get here.
2064 GDB should not stop for these breakpoints. */
2065 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
2066 return PRINT_NOTHING
;
2069 case bp_overlay_event
:
2070 /* By analogy with the thread event, GDB should not stop for these. */
2071 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
2072 return PRINT_NOTHING
;
2076 annotate_catchpoint (bs
->breakpoint_at
->number
);
2077 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2078 printf_filtered ("loaded");
2079 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
2080 return PRINT_SRC_AND_LOC
;
2083 case bp_catch_unload
:
2084 annotate_catchpoint (bs
->breakpoint_at
->number
);
2085 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2086 printf_filtered ("unloaded");
2087 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
2088 return PRINT_SRC_AND_LOC
;
2092 annotate_catchpoint (bs
->breakpoint_at
->number
);
2093 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2094 printf_filtered ("forked");
2095 printf_filtered (" process %d), ",
2096 bs
->breakpoint_at
->forked_inferior_pid
);
2097 return PRINT_SRC_AND_LOC
;
2100 case bp_catch_vfork
:
2101 annotate_catchpoint (bs
->breakpoint_at
->number
);
2102 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2103 printf_filtered ("vforked");
2104 printf_filtered (" process %d), ",
2105 bs
->breakpoint_at
->forked_inferior_pid
);
2106 return PRINT_SRC_AND_LOC
;
2110 annotate_catchpoint (bs
->breakpoint_at
->number
);
2111 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2112 bs
->breakpoint_at
->number
,
2113 bs
->breakpoint_at
->exec_pathname
);
2114 return PRINT_SRC_AND_LOC
;
2117 case bp_catch_catch
:
2118 if (current_exception_event
&&
2119 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2121 annotate_catchpoint (bs
->breakpoint_at
->number
);
2122 printf_filtered ("\nCatchpoint %d (exception caught), ",
2123 bs
->breakpoint_at
->number
);
2124 printf_filtered ("throw location ");
2125 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2126 printf_filtered ("%s:%d",
2127 CURRENT_EXCEPTION_THROW_FILE
,
2128 CURRENT_EXCEPTION_THROW_LINE
);
2130 printf_filtered ("unknown");
2132 printf_filtered (", catch location ");
2133 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2134 printf_filtered ("%s:%d",
2135 CURRENT_EXCEPTION_CATCH_FILE
,
2136 CURRENT_EXCEPTION_CATCH_LINE
);
2138 printf_filtered ("unknown");
2140 printf_filtered ("\n");
2141 /* don't bother to print location frame info */
2142 return PRINT_SRC_ONLY
;
2146 /* really throw, some other bpstat will handle it */
2147 return PRINT_UNKNOWN
;
2151 case bp_catch_throw
:
2152 if (current_exception_event
&&
2153 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2155 annotate_catchpoint (bs
->breakpoint_at
->number
);
2156 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2157 bs
->breakpoint_at
->number
);
2158 printf_filtered ("throw location ");
2159 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2160 printf_filtered ("%s:%d",
2161 CURRENT_EXCEPTION_THROW_FILE
,
2162 CURRENT_EXCEPTION_THROW_LINE
);
2164 printf_filtered ("unknown");
2166 printf_filtered (", catch location ");
2167 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2168 printf_filtered ("%s:%d",
2169 CURRENT_EXCEPTION_CATCH_FILE
,
2170 CURRENT_EXCEPTION_CATCH_LINE
);
2172 printf_filtered ("unknown");
2174 printf_filtered ("\n");
2175 /* don't bother to print location frame info */
2176 return PRINT_SRC_ONLY
;
2180 /* really catch, some other bpstat will handle it */
2181 return PRINT_UNKNOWN
;
2186 case bp_hardware_watchpoint
:
2187 if (bs
->old_val
!= NULL
)
2189 annotate_watchpoint (bs
->breakpoint_at
->number
);
2190 if (ui_out_is_mi_like_p (uiout
))
2191 ui_out_field_string (uiout
, "reason", "watchpoint-trigger");
2192 mention (bs
->breakpoint_at
);
2193 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2194 ui_out_text (uiout
, "\nOld value = ");
2195 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2196 ui_out_field_stream (uiout
, "old", stb
);
2197 ui_out_text (uiout
, "\nNew value = ");
2198 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2199 ui_out_field_stream (uiout
, "new", stb
);
2200 do_cleanups (ui_out_chain
);
2201 ui_out_text (uiout
, "\n");
2202 value_free (bs
->old_val
);
2205 /* More than one watchpoint may have been triggered. */
2206 return PRINT_UNKNOWN
;
2209 case bp_read_watchpoint
:
2210 if (ui_out_is_mi_like_p (uiout
))
2211 ui_out_field_string (uiout
, "reason", "read-watchpoint-trigger");
2212 mention (bs
->breakpoint_at
);
2213 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2214 ui_out_text (uiout
, "\nValue = ");
2215 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2216 ui_out_field_stream (uiout
, "value", stb
);
2217 do_cleanups (ui_out_chain
);
2218 ui_out_text (uiout
, "\n");
2219 return PRINT_UNKNOWN
;
2222 case bp_access_watchpoint
:
2223 if (bs
->old_val
!= NULL
)
2225 annotate_watchpoint (bs
->breakpoint_at
->number
);
2226 if (ui_out_is_mi_like_p (uiout
))
2227 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2228 mention (bs
->breakpoint_at
);
2229 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2230 ui_out_text (uiout
, "\nOld value = ");
2231 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2232 ui_out_field_stream (uiout
, "old", stb
);
2233 value_free (bs
->old_val
);
2235 ui_out_text (uiout
, "\nNew value = ");
2239 mention (bs
->breakpoint_at
);
2240 if (ui_out_is_mi_like_p (uiout
))
2241 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2242 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2243 ui_out_text (uiout
, "\nValue = ");
2245 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0,Val_pretty_default
);
2246 ui_out_field_stream (uiout
, "new", stb
);
2247 do_cleanups (ui_out_chain
);
2248 ui_out_text (uiout
, "\n");
2249 return PRINT_UNKNOWN
;
2252 /* Fall through, we don't deal with these types of breakpoints
2256 if (ui_out_is_mi_like_p (uiout
))
2257 ui_out_field_string (uiout
, "reason", "function-finished");
2258 return PRINT_UNKNOWN
;
2262 if (ui_out_is_mi_like_p (uiout
))
2263 ui_out_field_string (uiout
, "reason", "location-reached");
2264 return PRINT_UNKNOWN
;
2269 case bp_longjmp_resume
:
2270 case bp_step_resume
:
2271 case bp_through_sigtramp
:
2272 case bp_watchpoint_scope
:
2275 return PRINT_UNKNOWN
;
2279 /* Generic routine for printing messages indicating why we
2280 stopped. The behavior of this function depends on the value
2281 'print_it' in the bpstat structure. Under some circumstances we
2282 may decide not to print anything here and delegate the task to
2285 static enum print_stop_action
2286 print_bp_stop_message (bpstat bs
)
2288 switch (bs
->print_it
)
2291 /* Nothing should be printed for this bpstat entry. */
2292 return PRINT_UNKNOWN
;
2296 /* We still want to print the frame, but we already printed the
2297 relevant messages. */
2298 return PRINT_SRC_AND_LOC
;
2301 case print_it_normal
:
2302 /* Normal case. Call the breakpoint's print_it method, or
2303 print_it_typical. */
2304 if (bs
->breakpoint_at
!= NULL
&& bs
->breakpoint_at
->ops
!= NULL
2305 && bs
->breakpoint_at
->ops
->print_it
!= NULL
)
2306 return bs
->breakpoint_at
->ops
->print_it (bs
->breakpoint_at
);
2308 return print_it_typical (bs
);
2312 internal_error (__FILE__
, __LINE__
,
2313 "print_bp_stop_message: unrecognized enum value");
2318 /* Print a message indicating what happened. This is called from
2319 normal_stop(). The input to this routine is the head of the bpstat
2320 list - a list of the eventpoints that caused this stop. This
2321 routine calls the generic print routine for printing a message
2322 about reasons for stopping. This will print (for example) the
2323 "Breakpoint n," part of the output. The return value of this
2326 PRINT_UNKNOWN: Means we printed nothing
2327 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2328 code to print the location. An example is
2329 "Breakpoint 1, " which should be followed by
2331 PRINT_SRC_ONLY: Means we printed something, but there is no need
2332 to also print the location part of the message.
2333 An example is the catch/throw messages, which
2334 don't require a location appended to the end.
2335 PRINT_NOTHING: We have done some printing and we don't need any
2336 further info to be printed.*/
2338 enum print_stop_action
2339 bpstat_print (bpstat bs
)
2343 /* Maybe another breakpoint in the chain caused us to stop.
2344 (Currently all watchpoints go on the bpstat whether hit or not.
2345 That probably could (should) be changed, provided care is taken
2346 with respect to bpstat_explains_signal). */
2347 for (; bs
; bs
= bs
->next
)
2349 val
= print_bp_stop_message (bs
);
2350 if (val
== PRINT_SRC_ONLY
2351 || val
== PRINT_SRC_AND_LOC
2352 || val
== PRINT_NOTHING
)
2356 /* We reached the end of the chain, or we got a null BS to start
2357 with and nothing was printed. */
2358 return PRINT_UNKNOWN
;
2361 /* Evaluate the expression EXP and return 1 if value is zero.
2362 This is used inside a catch_errors to evaluate the breakpoint condition.
2363 The argument is a "struct expression *" that has been cast to char * to
2364 make it pass through catch_errors. */
2367 breakpoint_cond_eval (void *exp
)
2369 struct value
*mark
= value_mark ();
2370 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2371 value_free_to_mark (mark
);
2375 /* Allocate a new bpstat and chain it to the current one. */
2378 bpstat_alloc (struct breakpoint
*b
, bpstat cbs
/* Current "bs" value */ )
2382 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2384 bs
->breakpoint_at
= b
;
2385 /* If the condition is false, etc., don't do the commands. */
2386 bs
->commands
= NULL
;
2388 bs
->print_it
= print_it_normal
;
2392 /* Possible return values for watchpoint_check (this can't be an enum
2393 because of check_errors). */
2394 /* The watchpoint has been deleted. */
2395 #define WP_DELETED 1
2396 /* The value has changed. */
2397 #define WP_VALUE_CHANGED 2
2398 /* The value has not changed. */
2399 #define WP_VALUE_NOT_CHANGED 3
2401 #define BP_TEMPFLAG 1
2402 #define BP_HARDWAREFLAG 2
2404 /* Check watchpoint condition. */
2407 watchpoint_check (void *p
)
2409 bpstat bs
= (bpstat
) p
;
2410 struct breakpoint
*b
;
2411 struct frame_info
*fr
;
2412 int within_current_scope
;
2414 struct frame_id current_frame_id
;
2417 b
= bs
->breakpoint_at
;
2419 if (b
->exp_valid_block
== NULL
)
2420 within_current_scope
= 1;
2423 /* There is no current frame at this moment. If we're going to have
2424 any chance of handling watchpoints on local variables, we'll need
2425 the frame chain (so we can determine if we're in scope). */
2426 reinit_frame_cache ();
2427 fr
= frame_find_by_id (b
->watchpoint_frame
);
2428 within_current_scope
= (fr
!= NULL
);
2429 /* in_function_epilogue_p() returns a non-zero value if we're still
2430 in the function but the stack frame has already been invalidated.
2431 Since we can't rely on the values of local variables after the
2432 stack has been destroyed, we are treating the watchpoint in that
2433 state as `not changed' without further checking.
2435 vinschen/2003-09-04: The former implementation left out the case
2436 that the watchpoint frame couldn't be found by frame_find_by_id()
2437 because the current PC is currently in an epilogue. Calling
2438 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2439 if ((!within_current_scope
|| fr
== get_current_frame ())
2440 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2441 return WP_VALUE_NOT_CHANGED
;
2442 if (fr
&& within_current_scope
)
2443 /* If we end up stopping, the current frame will get selected
2444 in normal_stop. So this call to select_frame won't affect
2449 if (within_current_scope
)
2451 /* We use value_{,free_to_}mark because it could be a
2452 *long* time before we return to the command level and
2453 call free_all_values. We can't call free_all_values because
2454 we might be in the middle of evaluating a function call. */
2456 struct value
*mark
= value_mark ();
2457 struct value
*new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
2458 if (!value_equal (b
->val
, new_val
))
2460 release_value (new_val
);
2461 value_free_to_mark (mark
);
2462 bs
->old_val
= b
->val
;
2464 /* We will stop here */
2465 return WP_VALUE_CHANGED
;
2469 /* Nothing changed, don't do anything. */
2470 value_free_to_mark (mark
);
2471 /* We won't stop here */
2472 return WP_VALUE_NOT_CHANGED
;
2477 /* This seems like the only logical thing to do because
2478 if we temporarily ignored the watchpoint, then when
2479 we reenter the block in which it is valid it contains
2480 garbage (in the case of a function, it may have two
2481 garbage values, one before and one after the prologue).
2482 So we can't even detect the first assignment to it and
2483 watch after that (since the garbage may or may not equal
2484 the first value assigned). */
2485 /* We print all the stop information in print_it_typical(), but
2486 in this case, by the time we call print_it_typical() this bp
2487 will be deleted already. So we have no choice but print the
2488 information here. */
2489 if (ui_out_is_mi_like_p (uiout
))
2490 ui_out_field_string (uiout
, "reason", "watchpoint-scope");
2491 ui_out_text (uiout
, "\nWatchpoint ");
2492 ui_out_field_int (uiout
, "wpnum", bs
->breakpoint_at
->number
);
2493 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2494 which its expression is valid.\n");
2496 if (b
->related_breakpoint
)
2497 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2498 b
->disposition
= disp_del_at_next_stop
;
2504 /* Get a bpstat associated with having just stopped at address *PC
2505 and frame address CORE_ADDRESS. Update *PC to point at the
2506 breakpoint (if we hit a breakpoint). NOT_A_SW_BREAKPOINT is nonzero
2507 if this is known to not be a real breakpoint (it could still be a
2508 watchpoint, though). */
2510 /* Determine whether we stopped at a breakpoint, etc, or whether we
2511 don't understand this stop. Result is a chain of bpstat's such that:
2513 if we don't understand the stop, the result is a null pointer.
2515 if we understand why we stopped, the result is not null.
2517 Each element of the chain refers to a particular breakpoint or
2518 watchpoint at which we have stopped. (We may have stopped for
2519 several reasons concurrently.)
2521 Each element of the chain has valid next, breakpoint_at,
2522 commands, FIXME??? fields. */
2525 bpstat_stop_status (CORE_ADDR
*pc
, int not_a_sw_breakpoint
)
2527 struct breakpoint
*b
, *temp
;
2529 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2530 int real_breakpoint
= 0;
2531 /* Root of the chain of bpstat's */
2532 struct bpstats root_bs
[1];
2533 /* Pointer to the last thing in the chain currently. */
2534 bpstat bs
= root_bs
;
2536 /* Get the address where the breakpoint would have been. The
2537 "not_a_sw_breakpoint" argument is meant to distinguish between a
2538 breakpoint trap event and a trace/singlestep trap event. For a
2539 trace/singlestep trap event, we would not want to subtract
2540 DECR_PC_AFTER_BREAK from the PC. */
2542 bp_addr
= *pc
- (not_a_sw_breakpoint
? 0 : DECR_PC_AFTER_BREAK
);
2544 ALL_BREAKPOINTS_SAFE (b
, temp
)
2546 if (b
->enable_state
== bp_disabled
2547 || b
->enable_state
== bp_shlib_disabled
2548 || b
->enable_state
== bp_call_disabled
)
2551 if (b
->type
!= bp_watchpoint
2552 && b
->type
!= bp_hardware_watchpoint
2553 && b
->type
!= bp_read_watchpoint
2554 && b
->type
!= bp_access_watchpoint
2555 && b
->type
!= bp_hardware_breakpoint
2556 && b
->type
!= bp_catch_fork
2557 && b
->type
!= bp_catch_vfork
2558 && b
->type
!= bp_catch_exec
2559 && b
->type
!= bp_catch_catch
2560 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2562 if (b
->loc
->address
!= bp_addr
) /* address doesn't match */
2564 if (overlay_debugging
/* unmapped overlay section */
2565 && section_is_overlay (b
->section
)
2566 && !section_is_mapped (b
->section
))
2570 if (b
->type
== bp_hardware_breakpoint
)
2572 if (b
->loc
->address
!= (*pc
- DECR_PC_AFTER_HW_BREAK
))
2574 if (overlay_debugging
/* unmapped overlay section */
2575 && section_is_overlay (b
->section
)
2576 && !section_is_mapped (b
->section
))
2580 /* Is this a catchpoint of a load or unload? If so, did we
2581 get a load or unload of the specified library? If not,
2583 if ((b
->type
== bp_catch_load
)
2584 #if defined(SOLIB_HAVE_LOAD_EVENT)
2585 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2586 || ((b
->dll_pathname
!= NULL
)
2587 && (strcmp (b
->dll_pathname
,
2588 SOLIB_LOADED_LIBRARY_PATHNAME (
2589 PIDGET (inferior_ptid
)))
2595 if ((b
->type
== bp_catch_unload
)
2596 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2597 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2598 || ((b
->dll_pathname
!= NULL
)
2599 && (strcmp (b
->dll_pathname
,
2600 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2601 PIDGET (inferior_ptid
)))
2607 if ((b
->type
== bp_catch_fork
)
2608 && !inferior_has_forked (PIDGET (inferior_ptid
),
2609 &b
->forked_inferior_pid
))
2612 if ((b
->type
== bp_catch_vfork
)
2613 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2614 &b
->forked_inferior_pid
))
2617 if ((b
->type
== bp_catch_exec
)
2618 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2621 if (ep_is_exception_catchpoint (b
) &&
2622 !(current_exception_event
= target_get_current_exception_event ()))
2625 /* Come here if it's a watchpoint, or if the break address matches */
2627 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
2629 /* Watchpoints may change this, if not found to have triggered. */
2633 if (b
->type
== bp_watchpoint
||
2634 b
->type
== bp_hardware_watchpoint
)
2636 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2638 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2639 int e
= catch_errors (watchpoint_check
, bs
, message
,
2641 do_cleanups (cleanups
);
2645 /* We've already printed what needs to be printed. */
2646 /* Actually this is superfluous, because by the time we
2647 call print_it_typical() the wp will be already deleted,
2648 and the function will return immediately. */
2649 bs
->print_it
= print_it_done
;
2652 case WP_VALUE_CHANGED
:
2656 case WP_VALUE_NOT_CHANGED
:
2658 bs
->print_it
= print_it_noop
;
2665 /* Error from catch_errors. */
2666 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2667 if (b
->related_breakpoint
)
2668 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2669 b
->disposition
= disp_del_at_next_stop
;
2670 /* We've already printed what needs to be printed. */
2671 bs
->print_it
= print_it_done
;
2677 else if (b
->type
== bp_read_watchpoint
||
2678 b
->type
== bp_access_watchpoint
)
2684 addr
= target_stopped_data_address ();
2687 for (v
= b
->val_chain
; v
; v
= v
->next
)
2689 if (VALUE_LVAL (v
) == lval_memory
2690 && ! VALUE_LAZY (v
))
2692 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
2694 if (v
== b
->val_chain
2695 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2696 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2700 vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
2701 /* Exact match not required. Within range is
2703 if (addr
>= vaddr
&&
2704 addr
< vaddr
+ TYPE_LENGTH (VALUE_TYPE (v
)))
2711 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2713 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2714 int e
= catch_errors (watchpoint_check
, bs
, message
,
2716 do_cleanups (cleanups
);
2720 /* We've already printed what needs to be printed. */
2721 bs
->print_it
= print_it_done
;
2724 case WP_VALUE_CHANGED
:
2725 if (b
->type
== bp_read_watchpoint
)
2727 /* Don't stop: read watchpoints shouldn't fire if
2728 the value has changed. This is for targets
2729 which cannot set read-only watchpoints. */
2730 bs
->print_it
= print_it_noop
;
2736 case WP_VALUE_NOT_CHANGED
:
2743 /* Error from catch_errors. */
2744 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2745 if (b
->related_breakpoint
)
2746 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2747 b
->disposition
= disp_del_at_next_stop
;
2748 /* We've already printed what needs to be printed. */
2749 bs
->print_it
= print_it_done
;
2753 else /* found == 0 */
2755 /* This is a case where some watchpoint(s) triggered,
2756 but not at the address of this watchpoint (FOUND
2757 was left zero). So don't print anything for this
2759 bs
->print_it
= print_it_noop
;
2766 /* By definition, an encountered breakpoint is a triggered
2770 real_breakpoint
= 1;
2773 if (frame_id_p (b
->frame_id
)
2774 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2778 int value_is_zero
= 0;
2782 /* Need to select the frame, with all that implies
2783 so that the conditions will have the right context. */
2784 select_frame (get_current_frame ());
2786 = catch_errors (breakpoint_cond_eval
, (b
->cond
),
2787 "Error in testing breakpoint condition:\n",
2789 /* FIXME-someday, should give breakpoint # */
2792 if (b
->cond
&& value_is_zero
)
2795 /* Don't consider this a hit. */
2798 else if (b
->ignore_count
> 0)
2801 annotate_ignore_count_change ();
2806 /* We will stop here */
2807 if (b
->disposition
== disp_disable
)
2808 b
->enable_state
= bp_disabled
;
2811 bs
->commands
= b
->commands
;
2813 (STREQ ("silent", bs
->commands
->line
) ||
2814 (xdb_commands
&& STREQ ("Q", bs
->commands
->line
))))
2816 bs
->commands
= bs
->commands
->next
;
2819 bs
->commands
= copy_command_lines (bs
->commands
);
2822 /* Print nothing for this entry if we dont stop or if we dont print. */
2823 if (bs
->stop
== 0 || bs
->print
== 0)
2824 bs
->print_it
= print_it_noop
;
2827 bs
->next
= NULL
; /* Terminate the chain */
2828 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2830 if (real_breakpoint
&& bs
)
2832 if (bs
->breakpoint_at
->type
== bp_hardware_breakpoint
)
2834 if (DECR_PC_AFTER_HW_BREAK
!= 0)
2836 *pc
= *pc
- DECR_PC_AFTER_HW_BREAK
;
2842 if (DECR_PC_AFTER_BREAK
!= 0 || must_shift_inst_regs
)
2845 #if defined (SHIFT_INST_REGS)
2847 #else /* No SHIFT_INST_REGS. */
2849 #endif /* No SHIFT_INST_REGS. */
2854 /* The value of a hardware watchpoint hasn't changed, but the
2855 intermediate memory locations we are watching may have. */
2856 if (bs
&& !bs
->stop
&&
2857 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
2858 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
2859 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
2861 remove_breakpoints ();
2862 insert_breakpoints ();
2867 /* Tell what to do about this bpstat. */
2869 bpstat_what (bpstat bs
)
2871 /* Classify each bpstat as one of the following. */
2874 /* This bpstat element has no effect on the main_action. */
2877 /* There was a watchpoint, stop but don't print. */
2880 /* There was a watchpoint, stop and print. */
2883 /* There was a breakpoint but we're not stopping. */
2886 /* There was a breakpoint, stop but don't print. */
2889 /* There was a breakpoint, stop and print. */
2892 /* We hit the longjmp breakpoint. */
2895 /* We hit the longjmp_resume breakpoint. */
2898 /* We hit the step_resume breakpoint. */
2901 /* We hit the through_sigtramp breakpoint. */
2904 /* We hit the shared library event breakpoint. */
2907 /* We caught a shared library event. */
2910 /* This is just used to count how many enums there are. */
2914 /* Here is the table which drives this routine. So that we can
2915 format it pretty, we define some abbreviations for the
2916 enum bpstat_what codes. */
2917 #define kc BPSTAT_WHAT_KEEP_CHECKING
2918 #define ss BPSTAT_WHAT_STOP_SILENT
2919 #define sn BPSTAT_WHAT_STOP_NOISY
2920 #define sgl BPSTAT_WHAT_SINGLE
2921 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2922 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2923 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2924 #define sr BPSTAT_WHAT_STEP_RESUME
2925 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2926 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2927 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2929 /* "Can't happen." Might want to print an error message.
2930 abort() is not out of the question, but chances are GDB is just
2931 a bit confused, not unusable. */
2932 #define err BPSTAT_WHAT_STOP_NOISY
2934 /* Given an old action and a class, come up with a new action. */
2935 /* One interesting property of this table is that wp_silent is the same
2936 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2937 after stopping, the check for whether to step over a breakpoint
2938 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2939 reference to how we stopped. We retain separate wp_silent and
2940 bp_silent codes in case we want to change that someday.
2942 Another possibly interesting property of this table is that
2943 there's a partial ordering, priority-like, of the actions. Once
2944 you've decided that some action is appropriate, you'll never go
2945 back and decide something of a lower priority is better. The
2948 kc < clr sgl shl shlr slr sn sr ss ts
2949 sgl < clrs shl shlr slr sn sr ss ts
2950 slr < err shl shlr sn sr ss ts
2951 clr < clrs err shl shlr sn sr ss ts
2952 clrs < err shl shlr sn sr ss ts
2953 ss < shl shlr sn sr ts
2960 What I think this means is that we don't need a damned table
2961 here. If you just put the rows and columns in the right order,
2962 it'd look awfully regular. We could simply walk the bpstat list
2963 and choose the highest priority action we find, with a little
2964 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2965 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2966 is messy anyway). */
2968 /* step_resume entries: a step resume breakpoint overrides another
2969 breakpoint of signal handling (see comment in wait_for_inferior
2970 at first PC_IN_SIGTRAMP where we set the step_resume breakpoint). */
2971 /* We handle the through_sigtramp_breakpoint the same way; having both
2972 one of those and a step_resume_breakpoint is probably very rare (?). */
2974 static const enum bpstat_what_main_action
2975 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
2978 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2981 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, ts
, shl
, shlr
},
2983 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2985 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2987 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, ts
, shl
, shlr
},
2989 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2991 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2993 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, ts
, shl
, shlr
},
2995 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, ts
, shl
, shlr
},
2997 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, ts
, shl
, shlr
},
2999 {ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, shl
, shlr
},
3001 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, shl
, ts
, shl
, shlr
},
3003 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, ts
, shlr
, shlr
}
3018 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3019 struct bpstat_what retval
;
3021 retval
.call_dummy
= 0;
3022 for (; bs
!= NULL
; bs
= bs
->next
)
3024 enum class bs_class
= no_effect
;
3025 if (bs
->breakpoint_at
== NULL
)
3026 /* I suspect this can happen if it was a momentary breakpoint
3027 which has since been deleted. */
3029 switch (bs
->breakpoint_at
->type
)
3035 case bp_hardware_breakpoint
:
3041 bs_class
= bp_noisy
;
3043 bs_class
= bp_silent
;
3046 bs_class
= bp_nostop
;
3049 case bp_hardware_watchpoint
:
3050 case bp_read_watchpoint
:
3051 case bp_access_watchpoint
:
3055 bs_class
= wp_noisy
;
3057 bs_class
= wp_silent
;
3060 /* There was a watchpoint, but we're not stopping.
3061 This requires no further action. */
3062 bs_class
= no_effect
;
3065 bs_class
= long_jump
;
3067 case bp_longjmp_resume
:
3068 bs_class
= long_resume
;
3070 case bp_step_resume
:
3073 bs_class
= step_resume
;
3076 /* It is for the wrong frame. */
3077 bs_class
= bp_nostop
;
3079 case bp_through_sigtramp
:
3080 bs_class
= through_sig
;
3082 case bp_watchpoint_scope
:
3083 bs_class
= bp_nostop
;
3085 case bp_shlib_event
:
3086 bs_class
= shlib_event
;
3088 case bp_thread_event
:
3089 case bp_overlay_event
:
3090 bs_class
= bp_nostop
;
3093 case bp_catch_unload
:
3094 /* Only if this catchpoint triggered should we cause the
3095 step-out-of-dld behaviour. Otherwise, we ignore this
3098 bs_class
= catch_shlib_event
;
3100 bs_class
= no_effect
;
3103 case bp_catch_vfork
:
3108 bs_class
= bp_noisy
;
3110 bs_class
= bp_silent
;
3113 /* There was a catchpoint, but we're not stopping.
3114 This requires no further action. */
3115 bs_class
= no_effect
;
3117 case bp_catch_catch
:
3118 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
3119 bs_class
= bp_nostop
;
3121 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3123 case bp_catch_throw
:
3124 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3125 bs_class
= bp_nostop
;
3127 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3130 /* Make sure the action is stop (silent or noisy),
3131 so infrun.c pops the dummy frame. */
3132 bs_class
= bp_silent
;
3133 retval
.call_dummy
= 1;
3136 current_action
= table
[(int) bs_class
][(int) current_action
];
3138 retval
.main_action
= current_action
;
3142 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3143 without hardware support). This isn't related to a specific bpstat,
3144 just to things like whether watchpoints are set. */
3147 bpstat_should_step (void)
3149 struct breakpoint
*b
;
3151 if (b
->enable_state
== bp_enabled
&& b
->type
== bp_watchpoint
)
3156 /* Nonzero if there are enabled hardware watchpoints. */
3158 bpstat_have_active_hw_watchpoints (void)
3160 struct breakpoint
*b
;
3162 if ((b
->enable_state
== bp_enabled
) &&
3163 (b
->loc
->inserted
) &&
3164 ((b
->type
== bp_hardware_watchpoint
) ||
3165 (b
->type
== bp_read_watchpoint
) ||
3166 (b
->type
== bp_access_watchpoint
)))
3172 /* Given a bpstat that records zero or more triggered eventpoints, this
3173 function returns another bpstat which contains only the catchpoints
3174 on that first list, if any. */
3176 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3178 struct bpstats root_bs
[1];
3179 bpstat bs
= root_bs
;
3180 struct breakpoint
*ep
;
3183 bpstat_clear (cp_list
);
3184 root_bs
->next
= NULL
;
3186 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3188 /* Is this eventpoint a catchpoint? If not, ignore it. */
3189 ep
= ep_list
->breakpoint_at
;
3192 if ((ep
->type
!= bp_catch_load
) &&
3193 (ep
->type
!= bp_catch_unload
) &&
3194 (ep
->type
!= bp_catch_catch
) &&
3195 (ep
->type
!= bp_catch_throw
))
3196 /* pai: (temp) ADD fork/vfork here!! */
3199 /* Yes; add it to the list. */
3200 bs
= bpstat_alloc (ep
, bs
);
3205 #if defined(SOLIB_ADD)
3206 /* Also, for each triggered catchpoint, tag it with the name of
3207 the library that caused this trigger. (We copy the name now,
3208 because it's only guaranteed to be available NOW, when the
3209 catchpoint triggers. Clients who may wish to know the name
3210 later must get it from the catchpoint itself.) */
3211 if (ep
->triggered_dll_pathname
!= NULL
)
3212 xfree (ep
->triggered_dll_pathname
);
3213 if (ep
->type
== bp_catch_load
)
3214 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3215 PIDGET (inferior_ptid
));
3217 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3218 PIDGET (inferior_ptid
));
3220 dll_pathname
= NULL
;
3224 ep
->triggered_dll_pathname
= (char *)
3225 xmalloc (strlen (dll_pathname
) + 1);
3226 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3229 ep
->triggered_dll_pathname
= NULL
;
3235 /* Print B to gdb_stdout. */
3237 print_one_breakpoint (struct breakpoint
*b
,
3238 CORE_ADDR
*last_addr
)
3240 struct command_line
*l
;
3242 struct ep_type_description
3247 static struct ep_type_description bptypes
[] =
3249 {bp_none
, "?deleted?"},
3250 {bp_breakpoint
, "breakpoint"},
3251 {bp_hardware_breakpoint
, "hw breakpoint"},
3252 {bp_until
, "until"},
3253 {bp_finish
, "finish"},
3254 {bp_watchpoint
, "watchpoint"},
3255 {bp_hardware_watchpoint
, "hw watchpoint"},
3256 {bp_read_watchpoint
, "read watchpoint"},
3257 {bp_access_watchpoint
, "acc watchpoint"},
3258 {bp_longjmp
, "longjmp"},
3259 {bp_longjmp_resume
, "longjmp resume"},
3260 {bp_step_resume
, "step resume"},
3261 {bp_through_sigtramp
, "sigtramp"},
3262 {bp_watchpoint_scope
, "watchpoint scope"},
3263 {bp_call_dummy
, "call dummy"},
3264 {bp_shlib_event
, "shlib events"},
3265 {bp_thread_event
, "thread events"},
3266 {bp_overlay_event
, "overlay events"},
3267 {bp_catch_load
, "catch load"},
3268 {bp_catch_unload
, "catch unload"},
3269 {bp_catch_fork
, "catch fork"},
3270 {bp_catch_vfork
, "catch vfork"},
3271 {bp_catch_exec
, "catch exec"},
3272 {bp_catch_catch
, "catch catch"},
3273 {bp_catch_throw
, "catch throw"}
3276 static char *bpdisps
[] =
3277 {"del", "dstp", "dis", "keep"};
3278 static char bpenables
[] = "nynny";
3279 char wrap_indent
[80];
3280 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3281 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3282 struct cleanup
*bkpt_chain
;
3285 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3289 ui_out_field_int (uiout
, "number", b
->number
);
3293 if (((int) b
->type
> (sizeof (bptypes
) / sizeof (bptypes
[0])))
3294 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3295 internal_error (__FILE__
, __LINE__
,
3296 "bptypes table does not describe type #%d.",
3298 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3302 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3306 ui_out_field_fmt (uiout
, "enabled", "%c", bpenables
[(int) b
->enable_state
]);
3307 ui_out_spaces (uiout
, 2);
3310 strcpy (wrap_indent
, " ");
3313 if (TARGET_ADDR_BIT
<= 32)
3314 strcat (wrap_indent
, " ");
3316 strcat (wrap_indent
, " ");
3319 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3320 b
->ops
->print_one (b
, last_addr
);
3325 internal_error (__FILE__
, __LINE__
,
3326 "print_one_breakpoint: bp_none encountered\n");
3330 case bp_hardware_watchpoint
:
3331 case bp_read_watchpoint
:
3332 case bp_access_watchpoint
:
3333 /* Field 4, the address, is omitted (which makes the columns
3334 not line up too nicely with the headers, but the effect
3335 is relatively readable). */
3337 ui_out_field_skip (uiout
, "addr");
3339 print_expression (b
->exp
, stb
->stream
);
3340 ui_out_field_stream (uiout
, "what", stb
);
3344 case bp_catch_unload
:
3345 /* Field 4, the address, is omitted (which makes the columns
3346 not line up too nicely with the headers, but the effect
3347 is relatively readable). */
3349 ui_out_field_skip (uiout
, "addr");
3351 if (b
->dll_pathname
== NULL
)
3353 ui_out_field_string (uiout
, "what", "<any library>");
3354 ui_out_spaces (uiout
, 1);
3358 ui_out_text (uiout
, "library \"");
3359 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3360 ui_out_text (uiout
, "\" ");
3365 case bp_catch_vfork
:
3366 /* Field 4, the address, is omitted (which makes the columns
3367 not line up too nicely with the headers, but the effect
3368 is relatively readable). */
3370 ui_out_field_skip (uiout
, "addr");
3372 if (b
->forked_inferior_pid
!= 0)
3374 ui_out_text (uiout
, "process ");
3375 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3376 ui_out_spaces (uiout
, 1);
3380 /* Field 4, the address, is omitted (which makes the columns
3381 not line up too nicely with the headers, but the effect
3382 is relatively readable). */
3384 ui_out_field_skip (uiout
, "addr");
3386 if (b
->exec_pathname
!= NULL
)
3388 ui_out_text (uiout
, "program \"");
3389 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3390 ui_out_text (uiout
, "\" ");
3394 case bp_catch_catch
:
3395 /* Field 4, the address, is omitted (which makes the columns
3396 not line up too nicely with the headers, but the effect
3397 is relatively readable). */
3399 ui_out_field_skip (uiout
, "addr");
3401 ui_out_field_string (uiout
, "what", "exception catch");
3402 ui_out_spaces (uiout
, 1);
3405 case bp_catch_throw
:
3406 /* Field 4, the address, is omitted (which makes the columns
3407 not line up too nicely with the headers, but the effect
3408 is relatively readable). */
3410 ui_out_field_skip (uiout
, "addr");
3412 ui_out_field_string (uiout
, "what", "exception throw");
3413 ui_out_spaces (uiout
, 1);
3417 case bp_hardware_breakpoint
:
3421 case bp_longjmp_resume
:
3422 case bp_step_resume
:
3423 case bp_through_sigtramp
:
3424 case bp_watchpoint_scope
:
3426 case bp_shlib_event
:
3427 case bp_thread_event
:
3428 case bp_overlay_event
:
3432 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
3435 *last_addr
= b
->loc
->address
;
3438 sym
= find_pc_sect_function (b
->loc
->address
, b
->section
);
3441 ui_out_text (uiout
, "in ");
3442 ui_out_field_string (uiout
, "func",
3443 SYMBOL_PRINT_NAME (sym
));
3444 ui_out_wrap_hint (uiout
, wrap_indent
);
3445 ui_out_text (uiout
, " at ");
3447 ui_out_field_string (uiout
, "file", b
->source_file
);
3448 ui_out_text (uiout
, ":");
3449 ui_out_field_int (uiout
, "line", b
->line_number
);
3453 print_address_symbolic (b
->loc
->address
, stb
->stream
, demangle
, "");
3454 ui_out_field_stream (uiout
, "at", stb
);
3459 if (b
->thread
!= -1)
3461 /* FIXME: This seems to be redundant and lost here; see the
3462 "stop only in" line a little further down. */
3463 ui_out_text (uiout
, " thread ");
3464 ui_out_field_int (uiout
, "thread", b
->thread
);
3467 ui_out_text (uiout
, "\n");
3469 if (frame_id_p (b
->frame_id
))
3472 ui_out_text (uiout
, "\tstop only in stack frame at ");
3473 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3475 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3476 ui_out_text (uiout
, "\n");
3482 ui_out_text (uiout
, "\tstop only if ");
3483 print_expression (b
->cond
, stb
->stream
);
3484 ui_out_field_stream (uiout
, "cond", stb
);
3485 ui_out_text (uiout
, "\n");
3488 if (b
->thread
!= -1)
3490 /* FIXME should make an annotation for this */
3491 ui_out_text (uiout
, "\tstop only in thread ");
3492 ui_out_field_int (uiout
, "thread", b
->thread
);
3493 ui_out_text (uiout
, "\n");
3496 if (show_breakpoint_hit_counts
&& b
->hit_count
)
3498 /* FIXME should make an annotation for this */
3499 if (ep_is_catchpoint (b
))
3500 ui_out_text (uiout
, "\tcatchpoint");
3502 ui_out_text (uiout
, "\tbreakpoint");
3503 ui_out_text (uiout
, " already hit ");
3504 ui_out_field_int (uiout
, "times", b
->hit_count
);
3505 if (b
->hit_count
== 1)
3506 ui_out_text (uiout
, " time\n");
3508 ui_out_text (uiout
, " times\n");
3511 /* Output the count also if it is zero, but only if this is
3512 mi. FIXME: Should have a better test for this. */
3513 if (ui_out_is_mi_like_p (uiout
))
3514 if (show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3515 ui_out_field_int (uiout
, "times", b
->hit_count
);
3517 if (b
->ignore_count
)
3520 ui_out_text (uiout
, "\tignore next ");
3521 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3522 ui_out_text (uiout
, " hits\n");
3525 if ((l
= b
->commands
))
3527 struct cleanup
*script_chain
;
3530 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3531 print_command_lines (uiout
, l
, 4);
3532 do_cleanups (script_chain
);
3534 do_cleanups (bkpt_chain
);
3535 do_cleanups (old_chain
);
3538 struct captured_breakpoint_query_args
3544 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3546 struct captured_breakpoint_query_args
*args
= data
;
3547 struct breakpoint
*b
;
3548 CORE_ADDR dummy_addr
= 0;
3551 if (args
->bnum
== b
->number
)
3553 print_one_breakpoint (b
, &dummy_addr
);
3561 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
)
3563 struct captured_breakpoint_query_args args
;
3565 /* For the moment we don't trust print_one_breakpoint() to not throw
3567 return catch_exceptions (uiout
, do_captured_breakpoint_query
, &args
,
3568 NULL
, RETURN_MASK_ALL
);
3571 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3572 catchpoints, et.al.). */
3575 user_settable_breakpoint (const struct breakpoint
*b
)
3577 return (b
->type
== bp_breakpoint
3578 || b
->type
== bp_catch_load
3579 || b
->type
== bp_catch_unload
3580 || b
->type
== bp_catch_fork
3581 || b
->type
== bp_catch_vfork
3582 || b
->type
== bp_catch_exec
3583 || b
->type
== bp_catch_catch
3584 || b
->type
== bp_catch_throw
3585 || b
->type
== bp_hardware_breakpoint
3586 || b
->type
== bp_watchpoint
3587 || b
->type
== bp_read_watchpoint
3588 || b
->type
== bp_access_watchpoint
3589 || b
->type
== bp_hardware_watchpoint
);
3592 /* Print information on user settable breakpoint (watchpoint, etc)
3593 number BNUM. If BNUM is -1 print all user settable breakpoints.
3594 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3597 breakpoint_1 (int bnum
, int allflag
)
3599 struct breakpoint
*b
;
3600 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3601 int nr_printable_breakpoints
;
3602 struct cleanup
*bkpttbl_chain
;
3604 /* Compute the number of rows in the table. */
3605 nr_printable_breakpoints
= 0;
3608 || bnum
== b
->number
)
3610 if (allflag
|| user_settable_breakpoint (b
))
3611 nr_printable_breakpoints
++;
3616 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3620 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3623 if (nr_printable_breakpoints
> 0)
3624 annotate_breakpoints_headers ();
3625 if (nr_printable_breakpoints
> 0)
3627 ui_out_table_header (uiout
, 3, ui_left
, "number", "Num"); /* 1 */
3628 if (nr_printable_breakpoints
> 0)
3630 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3631 if (nr_printable_breakpoints
> 0)
3633 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3634 if (nr_printable_breakpoints
> 0)
3636 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3639 if (nr_printable_breakpoints
> 0)
3641 if (TARGET_ADDR_BIT
<= 32)
3642 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3644 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3646 if (nr_printable_breakpoints
> 0)
3648 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3649 ui_out_table_body (uiout
);
3650 if (nr_printable_breakpoints
> 0)
3651 annotate_breakpoints_table ();
3655 || bnum
== b
->number
)
3657 /* We only print out user settable breakpoints unless the
3659 if (allflag
|| user_settable_breakpoint (b
))
3660 print_one_breakpoint (b
, &last_addr
);
3663 do_cleanups (bkpttbl_chain
);
3665 if (nr_printable_breakpoints
== 0)
3668 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3670 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3675 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3676 that a comparison of an unsigned with -1 is always false. */
3677 if (last_addr
!= (CORE_ADDR
) -1)
3678 set_next_address (last_addr
);
3681 /* FIXME? Should this be moved up so that it is only called when
3682 there have been breakpoints? */
3683 annotate_breakpoints_table_end ();
3687 breakpoints_info (char *bnum_exp
, int from_tty
)
3692 bnum
= parse_and_eval_long (bnum_exp
);
3694 breakpoint_1 (bnum
, 0);
3698 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3703 bnum
= parse_and_eval_long (bnum_exp
);
3705 breakpoint_1 (bnum
, 1);
3708 /* Print a message describing any breakpoints set at PC. */
3711 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
)
3714 struct breakpoint
*b
;
3717 if (b
->loc
->address
== pc
) /* address match / overlay match */
3718 if (!overlay_debugging
|| b
->section
== section
)
3722 printf_filtered ("Note: breakpoint%s ", (others
> 1) ? "s" : "");
3724 if (b
->loc
->address
== pc
) /* address match / overlay match */
3725 if (!overlay_debugging
|| b
->section
== section
)
3728 printf_filtered ("%d%s%s ",
3730 ((b
->enable_state
== bp_disabled
||
3731 b
->enable_state
== bp_shlib_disabled
||
3732 b
->enable_state
== bp_call_disabled
)
3734 : b
->enable_state
== bp_permanent
3738 : ((others
== 1) ? " and" : ""));
3740 printf_filtered ("also set at pc ");
3741 print_address_numeric (pc
, 1, gdb_stdout
);
3742 printf_filtered (".\n");
3746 /* Set the default place to put a breakpoint
3747 for the `break' command with no arguments. */
3750 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3753 default_breakpoint_valid
= valid
;
3754 default_breakpoint_address
= addr
;
3755 default_breakpoint_symtab
= symtab
;
3756 default_breakpoint_line
= line
;
3759 /* Return true iff it is meaningful to use the address member of
3760 BPT. For some breakpoint types, the address member is irrelevant
3761 and it makes no sense to attempt to compare it to other addresses
3762 (or use it for any other purpose either).
3764 More specifically, each of the following breakpoint types will always
3765 have a zero valued address and we don't want check_duplicates() to mark
3766 breakpoints of any of these types to be a duplicate of an actual
3767 breakpoint at address zero:
3770 bp_hardware_watchpoint
3772 bp_access_watchpoint
3779 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3781 enum bptype type
= bpt
->type
;
3783 return (type
!= bp_watchpoint
3784 && type
!= bp_hardware_watchpoint
3785 && type
!= bp_read_watchpoint
3786 && type
!= bp_access_watchpoint
3787 && type
!= bp_catch_exec
3788 && type
!= bp_longjmp_resume
3789 && type
!= bp_catch_fork
3790 && type
!= bp_catch_vfork
);
3793 /* Rescan breakpoints at the same address and section as BPT,
3794 marking the first one as "first" and any others as "duplicates".
3795 This is so that the bpt instruction is only inserted once.
3796 If we have a permanent breakpoint at the same place as BPT, make
3797 that one the official one, and the rest as duplicates. */
3800 check_duplicates (struct breakpoint
*bpt
)
3802 struct breakpoint
*b
;
3804 struct breakpoint
*perm_bp
= 0;
3805 CORE_ADDR address
= bpt
->loc
->address
;
3806 asection
*section
= bpt
->section
;
3808 if (! breakpoint_address_is_meaningful (bpt
))
3812 if (b
->enable_state
!= bp_disabled
3813 && b
->enable_state
!= bp_shlib_disabled
3814 && b
->enable_state
!= bp_call_disabled
3815 && b
->loc
->address
== address
/* address / overlay match */
3816 && (!overlay_debugging
|| b
->section
== section
)
3817 && breakpoint_address_is_meaningful (b
))
3819 /* Have we found a permanent breakpoint? */
3820 if (b
->enable_state
== bp_permanent
)
3827 b
->loc
->duplicate
= count
> 1;
3830 /* If we found a permanent breakpoint at this address, go over the
3831 list again and declare all the other breakpoints there to be the
3835 perm_bp
->loc
->duplicate
= 0;
3837 /* Permanent breakpoint should always be inserted. */
3838 if (! perm_bp
->loc
->inserted
)
3839 internal_error (__FILE__
, __LINE__
,
3840 "allegedly permanent breakpoint is not "
3841 "actually inserted");
3846 if (b
->loc
->inserted
)
3847 internal_error (__FILE__
, __LINE__
,
3848 "another breakpoint was inserted on top of "
3849 "a permanent breakpoint");
3851 if (b
->enable_state
!= bp_disabled
3852 && b
->enable_state
!= bp_shlib_disabled
3853 && b
->enable_state
!= bp_call_disabled
3854 && b
->loc
->address
== address
/* address / overlay match */
3855 && (!overlay_debugging
|| b
->section
== section
)
3856 && breakpoint_address_is_meaningful (b
))
3857 b
->loc
->duplicate
= 1;
3863 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
3864 int bnum
, int have_bnum
)
3869 strcpy (astr1
, local_hex_string_custom ((unsigned long) from_addr
, "08l"));
3870 strcpy (astr2
, local_hex_string_custom ((unsigned long) to_addr
, "08l"));
3872 warning ("Breakpoint %d address previously adjusted from %s to %s.",
3873 bnum
, astr1
, astr2
);
3875 warning ("Breakpoint address adjusted from %s to %s.", astr1
, astr2
);
3878 /* Adjust a breakpoint's address to account for architectural constraints
3879 on breakpoint placement. Return the adjusted address. Note: Very
3880 few targets require this kind of adjustment. For most targets,
3881 this function is simply the identity function. */
3884 adjust_breakpoint_address (CORE_ADDR bpaddr
)
3886 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
3888 /* Very few targets need any kind of breakpoint adjustment. */
3893 CORE_ADDR adjusted_bpaddr
;
3895 /* Some targets have architectural constraints on the placement
3896 of breakpoint instructions. Obtain the adjusted address. */
3897 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
3900 /* An adjusted breakpoint address can significantly alter
3901 a user's expectations. Print a warning if an adjustment
3903 if (adjusted_bpaddr
!= bpaddr
)
3904 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
3906 return adjusted_bpaddr
;
3910 /* Allocate a struct bp_location. */
3912 struct bp_location
*
3913 allocate_bp_location (void)
3915 struct bp_location
*loc
, *loc_p
;
3917 loc
= xmalloc (sizeof (struct bp_location
));
3918 memset (loc
, 0, sizeof (*loc
));
3920 /* Add this breakpoint to the end of the chain. */
3922 loc_p
= bp_location_chain
;
3924 bp_location_chain
= loc
;
3928 loc_p
= loc_p
->next
;
3935 /* set_raw_breakpoint() is a low level routine for allocating and
3936 partially initializing a breakpoint of type BPTYPE. The newly
3937 created breakpoint's address, section, source file name, and line
3938 number are provided by SAL. The newly created and partially
3939 initialized breakpoint is added to the breakpoint chain and
3940 is also returned as the value of this function.
3942 It is expected that the caller will complete the initialization of
3943 the newly created breakpoint struct as well as output any status
3944 information regarding the creation of a new breakpoint. In
3945 particular, set_raw_breakpoint() does NOT set the breakpoint
3946 number! Care should be taken to not allow an error() to occur
3947 prior to completing the initialization of the breakpoint. If this
3948 should happen, a bogus breakpoint will be left on the chain. */
3951 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
3953 struct breakpoint
*b
, *b1
;
3955 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
3956 memset (b
, 0, sizeof (*b
));
3957 b
->loc
= allocate_bp_location ();
3958 b
->loc
->requested_address
= sal
.pc
;
3959 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
);
3960 if (sal
.symtab
== NULL
)
3961 b
->source_file
= NULL
;
3963 b
->source_file
= savestring (sal
.symtab
->filename
,
3964 strlen (sal
.symtab
->filename
));
3965 b
->section
= sal
.section
;
3967 b
->language
= current_language
->la_language
;
3968 b
->input_radix
= input_radix
;
3970 b
->line_number
= sal
.line
;
3971 b
->enable_state
= bp_enabled
;
3974 b
->ignore_count
= 0;
3976 b
->frame_id
= null_frame_id
;
3977 b
->dll_pathname
= NULL
;
3978 b
->triggered_dll_pathname
= NULL
;
3979 b
->forked_inferior_pid
= 0;
3980 b
->exec_pathname
= NULL
;
3983 /* Add this breakpoint to the end of the chain
3984 so that a list of breakpoints will come out in order
3985 of increasing numbers. */
3987 b1
= breakpoint_chain
;
3989 breakpoint_chain
= b
;
3997 check_duplicates (b
);
3998 breakpoints_changed ();
4004 /* Note that the breakpoint object B describes a permanent breakpoint
4005 instruction, hard-wired into the inferior's code. */
4007 make_breakpoint_permanent (struct breakpoint
*b
)
4009 b
->enable_state
= bp_permanent
;
4011 /* By definition, permanent breakpoints are already present in the code. */
4012 b
->loc
->inserted
= 1;
4015 static struct breakpoint
*
4016 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4018 static int internal_breakpoint_number
= -1;
4019 struct symtab_and_line sal
;
4020 struct breakpoint
*b
;
4022 init_sal (&sal
); /* initialize to zeroes */
4025 sal
.section
= find_pc_overlay (sal
.pc
);
4027 b
= set_raw_breakpoint (sal
, type
);
4028 b
->number
= internal_breakpoint_number
--;
4029 b
->disposition
= disp_donttouch
;
4036 create_longjmp_breakpoint (char *func_name
)
4038 struct breakpoint
*b
;
4039 struct minimal_symbol
*m
;
4041 if (func_name
== NULL
)
4042 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4045 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4048 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4051 b
->enable_state
= bp_disabled
;
4054 b
->addr_string
= xstrdup (func_name
);
4057 /* Call this routine when stepping and nexting to enable a breakpoint
4058 if we do a longjmp(). When we hit that breakpoint, call
4059 set_longjmp_resume_breakpoint() to figure out where we are going. */
4062 enable_longjmp_breakpoint (void)
4064 struct breakpoint
*b
;
4067 if (b
->type
== bp_longjmp
)
4069 b
->enable_state
= bp_enabled
;
4070 check_duplicates (b
);
4075 disable_longjmp_breakpoint (void)
4077 struct breakpoint
*b
;
4080 if (b
->type
== bp_longjmp
4081 || b
->type
== bp_longjmp_resume
)
4083 b
->enable_state
= bp_disabled
;
4084 check_duplicates (b
);
4089 create_overlay_event_breakpoint (char *func_name
)
4091 struct breakpoint
*b
;
4092 struct minimal_symbol
*m
;
4094 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4097 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4099 b
->addr_string
= xstrdup (func_name
);
4101 if (overlay_debugging
== ovly_auto
)
4103 b
->enable_state
= bp_enabled
;
4104 overlay_events_enabled
= 1;
4108 b
->enable_state
= bp_disabled
;
4109 overlay_events_enabled
= 0;
4114 enable_overlay_breakpoints (void)
4116 struct breakpoint
*b
;
4119 if (b
->type
== bp_overlay_event
)
4121 b
->enable_state
= bp_enabled
;
4122 check_duplicates (b
);
4123 overlay_events_enabled
= 1;
4128 disable_overlay_breakpoints (void)
4130 struct breakpoint
*b
;
4133 if (b
->type
== bp_overlay_event
)
4135 b
->enable_state
= bp_disabled
;
4136 check_duplicates (b
);
4137 overlay_events_enabled
= 0;
4142 create_thread_event_breakpoint (CORE_ADDR address
)
4144 struct breakpoint
*b
;
4146 b
= create_internal_breakpoint (address
, bp_thread_event
);
4148 b
->enable_state
= bp_enabled
;
4149 /* addr_string has to be used or breakpoint_re_set will delete me. */
4150 xasprintf (&b
->addr_string
, "*0x%s", paddr (b
->loc
->address
));
4156 remove_thread_event_breakpoints (void)
4158 struct breakpoint
*b
, *temp
;
4160 ALL_BREAKPOINTS_SAFE (b
, temp
)
4161 if (b
->type
== bp_thread_event
)
4162 delete_breakpoint (b
);
4167 remove_solib_event_breakpoints (void)
4169 struct breakpoint
*b
, *temp
;
4171 ALL_BREAKPOINTS_SAFE (b
, temp
)
4172 if (b
->type
== bp_shlib_event
)
4173 delete_breakpoint (b
);
4177 create_solib_event_breakpoint (CORE_ADDR address
)
4179 struct breakpoint
*b
;
4181 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4185 /* Disable any breakpoints that are on code in shared libraries. Only
4186 apply to enabled breakpoints, disabled ones can just stay disabled. */
4189 disable_breakpoints_in_shlibs (int silent
)
4191 struct breakpoint
*b
;
4192 int disabled_shlib_breaks
= 0;
4194 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4197 #if defined (PC_SOLIB)
4198 if (((b
->type
== bp_breakpoint
) ||
4199 (b
->type
== bp_hardware_breakpoint
)) &&
4200 b
->enable_state
== bp_enabled
&&
4201 !b
->loc
->duplicate
&&
4202 PC_SOLIB (b
->loc
->address
))
4204 b
->enable_state
= bp_shlib_disabled
;
4207 if (!disabled_shlib_breaks
)
4209 target_terminal_ours_for_output ();
4210 warning ("Temporarily disabling shared library breakpoints:");
4212 disabled_shlib_breaks
= 1;
4213 warning ("breakpoint #%d ", b
->number
);
4220 /* Try to reenable any breakpoints in shared libraries. */
4222 re_enable_breakpoints_in_shlibs (void)
4224 struct breakpoint
*b
;
4227 if (b
->enable_state
== bp_shlib_disabled
)
4231 /* Do not reenable the breakpoint if the shared library
4232 is still not mapped in. */
4233 if (target_read_memory (b
->loc
->address
, buf
, 1) == 0)
4234 b
->enable_state
= bp_enabled
;
4241 solib_load_unload_1 (char *hookname
, int tempflag
, char *dll_pathname
,
4242 char *cond_string
, enum bptype bp_kind
)
4244 struct breakpoint
*b
;
4245 struct symtabs_and_lines sals
;
4246 struct cleanup
*old_chain
;
4247 struct cleanup
*canonical_strings_chain
= NULL
;
4248 char *addr_start
= hookname
;
4249 char *addr_end
= NULL
;
4250 char **canonical
= (char **) NULL
;
4251 int thread
= -1; /* All threads. */
4253 /* Set a breakpoint on the specified hook. */
4254 sals
= decode_line_1 (&hookname
, 1, (struct symtab
*) NULL
, 0, &canonical
);
4255 addr_end
= hookname
;
4257 if (sals
.nelts
== 0)
4259 warning ("Unable to set a breakpoint on dynamic linker callback.");
4260 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4261 warning ("GDB will be unable to track shl_load/shl_unload calls");
4264 if (sals
.nelts
!= 1)
4266 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4267 warning ("GDB will be unable to track shl_load/shl_unload calls");
4271 /* Make sure that all storage allocated in decode_line_1 gets freed
4272 in case the following errors out. */
4273 old_chain
= make_cleanup (xfree
, sals
.sals
);
4274 if (canonical
!= (char **) NULL
)
4276 make_cleanup (xfree
, canonical
);
4277 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
4278 if (canonical
[0] != NULL
)
4279 make_cleanup (xfree
, canonical
[0]);
4282 resolve_sal_pc (&sals
.sals
[0]);
4284 /* Remove the canonical strings from the cleanup, they are needed below. */
4285 if (canonical
!= (char **) NULL
)
4286 discard_cleanups (canonical_strings_chain
);
4288 b
= set_raw_breakpoint (sals
.sals
[0], bp_kind
);
4289 set_breakpoint_count (breakpoint_count
+ 1);
4290 b
->number
= breakpoint_count
;
4292 b
->cond_string
= (cond_string
== NULL
) ?
4293 NULL
: savestring (cond_string
, strlen (cond_string
));
4296 if (canonical
!= (char **) NULL
&& canonical
[0] != NULL
)
4297 b
->addr_string
= canonical
[0];
4298 else if (addr_start
)
4299 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
4301 b
->enable_state
= bp_enabled
;
4302 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4304 if (dll_pathname
== NULL
)
4305 b
->dll_pathname
= NULL
;
4308 b
->dll_pathname
= (char *) xmalloc (strlen (dll_pathname
) + 1);
4309 strcpy (b
->dll_pathname
, dll_pathname
);
4313 do_cleanups (old_chain
);
4317 create_solib_load_event_breakpoint (char *hookname
, int tempflag
,
4318 char *dll_pathname
, char *cond_string
)
4320 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4321 cond_string
, bp_catch_load
);
4325 create_solib_unload_event_breakpoint (char *hookname
, int tempflag
,
4326 char *dll_pathname
, char *cond_string
)
4328 solib_load_unload_1 (hookname
,tempflag
, dll_pathname
,
4329 cond_string
, bp_catch_unload
);
4333 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4334 enum bptype bp_kind
)
4336 struct symtab_and_line sal
;
4337 struct breakpoint
*b
;
4338 int thread
= -1; /* All threads. */
4345 b
= set_raw_breakpoint (sal
, bp_kind
);
4346 set_breakpoint_count (breakpoint_count
+ 1);
4347 b
->number
= breakpoint_count
;
4349 b
->cond_string
= (cond_string
== NULL
) ?
4350 NULL
: savestring (cond_string
, strlen (cond_string
));
4352 b
->addr_string
= NULL
;
4353 b
->enable_state
= bp_enabled
;
4354 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4355 b
->forked_inferior_pid
= 0;
4361 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4363 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4367 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4369 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4373 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4375 struct symtab_and_line sal
;
4376 struct breakpoint
*b
;
4377 int thread
= -1; /* All threads. */
4384 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4385 set_breakpoint_count (breakpoint_count
+ 1);
4386 b
->number
= breakpoint_count
;
4388 b
->cond_string
= (cond_string
== NULL
) ?
4389 NULL
: savestring (cond_string
, strlen (cond_string
));
4391 b
->addr_string
= NULL
;
4392 b
->enable_state
= bp_enabled
;
4393 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4399 hw_breakpoint_used_count (void)
4401 struct breakpoint
*b
;
4406 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4414 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4416 struct breakpoint
*b
;
4419 *other_type_used
= 0;
4422 if (b
->enable_state
== bp_enabled
)
4424 if (b
->type
== type
)
4426 else if ((b
->type
== bp_hardware_watchpoint
||
4427 b
->type
== bp_read_watchpoint
||
4428 b
->type
== bp_access_watchpoint
)
4429 && b
->enable_state
== bp_enabled
)
4430 *other_type_used
= 1;
4436 /* Call this after hitting the longjmp() breakpoint. Use this to set
4437 a new breakpoint at the target of the jmp_buf.
4439 FIXME - This ought to be done by setting a temporary breakpoint
4440 that gets deleted automatically... */
4443 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4445 struct breakpoint
*b
;
4448 if (b
->type
== bp_longjmp_resume
)
4450 b
->loc
->requested_address
= pc
;
4451 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
);
4452 b
->enable_state
= bp_enabled
;
4453 b
->frame_id
= frame_id
;
4454 check_duplicates (b
);
4460 disable_watchpoints_before_interactive_call_start (void)
4462 struct breakpoint
*b
;
4466 if (((b
->type
== bp_watchpoint
)
4467 || (b
->type
== bp_hardware_watchpoint
)
4468 || (b
->type
== bp_read_watchpoint
)
4469 || (b
->type
== bp_access_watchpoint
)
4470 || ep_is_exception_catchpoint (b
))
4471 && (b
->enable_state
== bp_enabled
))
4473 b
->enable_state
= bp_call_disabled
;
4474 check_duplicates (b
);
4480 enable_watchpoints_after_interactive_call_stop (void)
4482 struct breakpoint
*b
;
4486 if (((b
->type
== bp_watchpoint
)
4487 || (b
->type
== bp_hardware_watchpoint
)
4488 || (b
->type
== bp_read_watchpoint
)
4489 || (b
->type
== bp_access_watchpoint
)
4490 || ep_is_exception_catchpoint (b
))
4491 && (b
->enable_state
== bp_call_disabled
))
4493 b
->enable_state
= bp_enabled
;
4494 check_duplicates (b
);
4500 /* Set a breakpoint that will evaporate an end of command
4501 at address specified by SAL.
4502 Restrict it to frame FRAME if FRAME is nonzero. */
4505 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4508 struct breakpoint
*b
;
4509 b
= set_raw_breakpoint (sal
, type
);
4510 b
->enable_state
= bp_enabled
;
4511 b
->disposition
= disp_donttouch
;
4512 b
->frame_id
= frame_id
;
4514 /* If we're debugging a multi-threaded program, then we
4515 want momentary breakpoints to be active in only a
4516 single thread of control. */
4517 if (in_thread_list (inferior_ptid
))
4518 b
->thread
= pid_to_thread_id (inferior_ptid
);
4524 /* Tell the user we have just set a breakpoint B. */
4527 mention (struct breakpoint
*b
)
4530 struct cleanup
*old_chain
, *ui_out_chain
;
4531 struct ui_stream
*stb
;
4533 stb
= ui_out_stream_new (uiout
);
4534 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4536 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4537 watchpoint) other than breakpoint creation. It should be possible to
4538 clean this up and at the same time replace the random calls to
4539 breakpoint_changed with this hook, as has already been done for
4540 delete_breakpoint_hook and so on. */
4541 if (create_breakpoint_hook
)
4542 create_breakpoint_hook (b
);
4543 breakpoint_create_event (b
->number
);
4545 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4546 b
->ops
->print_mention (b
);
4551 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b
->number
);
4554 ui_out_text (uiout
, "Watchpoint ");
4555 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4556 ui_out_field_int (uiout
, "number", b
->number
);
4557 ui_out_text (uiout
, ": ");
4558 print_expression (b
->exp
, stb
->stream
);
4559 ui_out_field_stream (uiout
, "exp", stb
);
4560 do_cleanups (ui_out_chain
);
4562 case bp_hardware_watchpoint
:
4563 ui_out_text (uiout
, "Hardware watchpoint ");
4564 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4565 ui_out_field_int (uiout
, "number", b
->number
);
4566 ui_out_text (uiout
, ": ");
4567 print_expression (b
->exp
, stb
->stream
);
4568 ui_out_field_stream (uiout
, "exp", stb
);
4569 do_cleanups (ui_out_chain
);
4571 case bp_read_watchpoint
:
4572 ui_out_text (uiout
, "Hardware read watchpoint ");
4573 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4574 ui_out_field_int (uiout
, "number", b
->number
);
4575 ui_out_text (uiout
, ": ");
4576 print_expression (b
->exp
, stb
->stream
);
4577 ui_out_field_stream (uiout
, "exp", stb
);
4578 do_cleanups (ui_out_chain
);
4580 case bp_access_watchpoint
:
4581 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4582 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4583 ui_out_field_int (uiout
, "number", b
->number
);
4584 ui_out_text (uiout
, ": ");
4585 print_expression (b
->exp
, stb
->stream
);
4586 ui_out_field_stream (uiout
, "exp", stb
);
4587 do_cleanups (ui_out_chain
);
4590 if (ui_out_is_mi_like_p (uiout
))
4595 printf_filtered ("Breakpoint %d", b
->number
);
4598 case bp_hardware_breakpoint
:
4599 if (ui_out_is_mi_like_p (uiout
))
4604 printf_filtered ("Hardware assisted breakpoint %d", b
->number
);
4608 case bp_catch_unload
:
4609 printf_filtered ("Catchpoint %d (%s %s)",
4611 (b
->type
== bp_catch_load
) ? "load" : "unload",
4612 (b
->dll_pathname
!= NULL
) ?
4613 b
->dll_pathname
: "<any library>");
4616 case bp_catch_vfork
:
4617 printf_filtered ("Catchpoint %d (%s)",
4619 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4622 printf_filtered ("Catchpoint %d (exec)",
4625 case bp_catch_catch
:
4626 case bp_catch_throw
:
4627 printf_filtered ("Catchpoint %d (%s)",
4629 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4635 case bp_longjmp_resume
:
4636 case bp_step_resume
:
4637 case bp_through_sigtramp
:
4639 case bp_watchpoint_scope
:
4640 case bp_shlib_event
:
4641 case bp_thread_event
:
4642 case bp_overlay_event
:
4648 if (addressprint
|| b
->source_file
== NULL
)
4650 printf_filtered (" at ");
4651 print_address_numeric (b
->loc
->address
, 1, gdb_stdout
);
4654 printf_filtered (": file %s, line %d.",
4655 b
->source_file
, b
->line_number
);
4657 do_cleanups (old_chain
);
4658 if (ui_out_is_mi_like_p (uiout
))
4660 printf_filtered ("\n");
4664 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4665 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4666 COND[i] and COND_STRING[i] values.
4668 NOTE: If the function succeeds, the caller is expected to cleanup
4669 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4670 array contents). If the function fails (error() is called), the
4671 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4672 COND and SALS arrays and each of those arrays contents. */
4675 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
4676 struct expression
**cond
, char **cond_string
,
4677 enum bptype type
, enum bpdisp disposition
,
4678 int thread
, int ignore_count
, int from_tty
)
4680 if (type
== bp_hardware_breakpoint
)
4682 int i
= hw_breakpoint_used_count ();
4683 int target_resources_ok
=
4684 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4686 if (target_resources_ok
== 0)
4687 error ("No hardware breakpoint support in the target.");
4688 else if (target_resources_ok
< 0)
4689 error ("Hardware breakpoints used exceeds limit.");
4692 /* Now set all the breakpoints. */
4695 for (i
= 0; i
< sals
.nelts
; i
++)
4697 struct breakpoint
*b
;
4698 struct symtab_and_line sal
= sals
.sals
[i
];
4701 describe_other_breakpoints (sal
.pc
, sal
.section
);
4703 b
= set_raw_breakpoint (sal
, type
);
4704 set_breakpoint_count (breakpoint_count
+ 1);
4705 b
->number
= breakpoint_count
;
4709 b
->addr_string
= addr_string
[i
];
4711 /* addr_string has to be used or breakpoint_re_set will delete
4713 xasprintf (&b
->addr_string
, "*0x%s", paddr (b
->loc
->address
));
4714 b
->cond_string
= cond_string
[i
];
4715 b
->ignore_count
= ignore_count
;
4716 b
->enable_state
= bp_enabled
;
4717 b
->disposition
= disposition
;
4723 /* Parse ARG which is assumed to be a SAL specification possibly
4724 followed by conditionals. On return, SALS contains an array of SAL
4725 addresses found. ADDR_STRING contains a vector of (canonical)
4726 address strings. ARG points to the end of the SAL. */
4729 parse_breakpoint_sals (char **address
,
4730 struct symtabs_and_lines
*sals
,
4731 char ***addr_string
)
4733 char *addr_start
= *address
;
4734 *addr_string
= NULL
;
4735 /* If no arg given, or if first arg is 'if ', use the default
4737 if ((*address
) == NULL
4738 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
4740 if (default_breakpoint_valid
)
4742 struct symtab_and_line sal
;
4743 init_sal (&sal
); /* initialize to zeroes */
4744 sals
->sals
= (struct symtab_and_line
*)
4745 xmalloc (sizeof (struct symtab_and_line
));
4746 sal
.pc
= default_breakpoint_address
;
4747 sal
.line
= default_breakpoint_line
;
4748 sal
.symtab
= default_breakpoint_symtab
;
4749 sal
.section
= find_pc_overlay (sal
.pc
);
4750 sals
->sals
[0] = sal
;
4754 error ("No default breakpoint address now.");
4758 /* Force almost all breakpoints to be in terms of the
4759 current_source_symtab (which is decode_line_1's default). This
4760 should produce the results we want almost all of the time while
4761 leaving default_breakpoint_* alone.
4762 ObjC: However, don't match an Objective-C method name which
4763 may have a '+' or '-' succeeded by a '[' */
4765 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
4767 if (default_breakpoint_valid
4769 || ((strchr ("+-", (*address
)[0]) != NULL
)
4770 && ((*address
)[1] != '['))))
4771 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
4772 default_breakpoint_line
, addr_string
);
4774 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0, addr_string
);
4776 /* For any SAL that didn't have a canonical string, fill one in. */
4777 if (sals
->nelts
> 0 && *addr_string
== NULL
)
4778 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
4779 if (addr_start
!= (*address
))
4782 for (i
= 0; i
< sals
->nelts
; i
++)
4784 /* Add the string if not present. */
4785 if ((*addr_string
)[i
] == NULL
)
4786 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
4792 /* Convert each SAL into a real PC. Verify that the PC can be
4793 inserted as a breakpoint. If it can't throw an error. */
4796 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
4800 for (i
= 0; i
< sals
->nelts
; i
++)
4802 resolve_sal_pc (&sals
->sals
[i
]);
4804 /* It's possible for the PC to be nonzero, but still an illegal
4805 value on some targets.
4807 For example, on HP-UX if you start gdb, and before running the
4808 inferior you try to set a breakpoint on a shared library function
4809 "foo" where the inferior doesn't call "foo" directly but does
4810 pass its address to another function call, then we do find a
4811 minimal symbol for the "foo", but it's address is invalid.
4812 (Appears to be an index into a table that the loader sets up
4813 when the inferior is run.)
4815 Give the target a chance to bless sals.sals[i].pc before we
4816 try to make a breakpoint for it. */
4817 if (PC_REQUIRES_RUN_BEFORE_USE (sals
->sals
[i
].pc
))
4819 if (address
== NULL
)
4820 error ("Cannot break without a running program.");
4822 error ("Cannot break on %s without a running program.",
4828 /* Set a breakpoint according to ARG (function, linenum or *address)
4829 flag: first bit : 0 non-temporary, 1 temporary.
4830 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4833 break_command_1 (char *arg
, int flag
, int from_tty
)
4835 int tempflag
, hardwareflag
;
4836 struct symtabs_and_lines sals
;
4837 struct expression
**cond
= 0;
4838 /* Pointers in arg to the start, and one past the end, of the
4840 char **cond_string
= (char **) NULL
;
4841 char *addr_start
= arg
;
4843 struct cleanup
*old_chain
;
4844 struct cleanup
*breakpoint_chain
= NULL
;
4847 int ignore_count
= 0;
4849 hardwareflag
= flag
& BP_HARDWAREFLAG
;
4850 tempflag
= flag
& BP_TEMPFLAG
;
4855 parse_breakpoint_sals (&arg
, &sals
, &addr_string
);
4860 /* Create a chain of things that always need to be cleaned up. */
4861 old_chain
= make_cleanup (null_cleanup
, 0);
4863 /* Make sure that all storage allocated to SALS gets freed. */
4864 make_cleanup (xfree
, sals
.sals
);
4866 /* Cleanup the addr_string array but not its contents. */
4867 make_cleanup (xfree
, addr_string
);
4869 /* Allocate space for all the cond expressions. */
4870 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4871 make_cleanup (xfree
, cond
);
4873 /* Allocate space for all the cond strings. */
4874 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4875 make_cleanup (xfree
, cond_string
);
4877 /* ----------------------------- SNIP -----------------------------
4878 Anything added to the cleanup chain beyond this point is assumed
4879 to be part of a breakpoint. If the breakpoint create succeeds
4880 then the memory is not reclaimed. */
4881 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4883 /* Mark the contents of the addr_string for cleanup. These go on
4884 the breakpoint_chain and only occure if the breakpoint create
4886 for (i
= 0; i
< sals
.nelts
; i
++)
4888 if (addr_string
[i
] != NULL
)
4889 make_cleanup (xfree
, addr_string
[i
]);
4892 /* Resolve all line numbers to PC's and verify that the addresses
4893 are ok for the target. */
4894 breakpoint_sals_to_pc (&sals
, addr_start
);
4896 /* Verify that condition can be parsed, before setting any
4897 breakpoints. Allocate a separate condition expression for each
4899 thread
= -1; /* No specific thread yet */
4900 for (i
= 0; i
< sals
.nelts
; i
++)
4907 char *cond_start
= NULL
;
4908 char *cond_end
= NULL
;
4909 while (*tok
== ' ' || *tok
== '\t')
4914 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
4917 toklen
= end_tok
- tok
;
4919 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
4921 tok
= cond_start
= end_tok
+ 1;
4922 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4923 make_cleanup (xfree
, cond
[i
]);
4925 cond_string
[i
] = savestring (cond_start
, cond_end
- cond_start
);
4926 make_cleanup (xfree
, cond_string
[i
]);
4928 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
4934 thread
= strtol (tok
, &tok
, 0);
4936 error ("Junk after thread keyword.");
4937 if (!valid_thread_id (thread
))
4938 error ("Unknown thread %d\n", thread
);
4941 error ("Junk at end of arguments.");
4945 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4946 hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4947 tempflag
? disp_del
: disp_donttouch
,
4948 thread
, ignore_count
, from_tty
);
4952 warning ("Multiple breakpoints were set.");
4953 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4955 /* That's it. Discard the cleanups for data inserted into the
4957 discard_cleanups (breakpoint_chain
);
4958 /* But cleanup everything else. */
4959 do_cleanups (old_chain
);
4962 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4963 linenum or *address) with COND and IGNORE_COUNT. */
4965 struct captured_breakpoint_args
4976 do_captured_breakpoint (void *data
)
4978 struct captured_breakpoint_args
*args
= data
;
4979 struct symtabs_and_lines sals
;
4980 struct expression
**cond
;
4981 struct cleanup
*old_chain
;
4982 struct cleanup
*breakpoint_chain
= NULL
;
4989 /* Parse the source and lines spec. Delay check that the expression
4990 didn't contain trailing garbage until after cleanups are in
4994 address_end
= args
->address
;
4996 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
);
5001 /* Create a chain of things at always need to be cleaned up. */
5002 old_chain
= make_cleanup (null_cleanup
, 0);
5004 /* Always have a addr_string array, even if it is empty. */
5005 make_cleanup (xfree
, addr_string
);
5007 /* Make sure that all storage allocated to SALS gets freed. */
5008 make_cleanup (xfree
, sals
.sals
);
5010 /* Allocate space for all the cond expressions. */
5011 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5012 make_cleanup (xfree
, cond
);
5014 /* Allocate space for all the cond strings. */
5015 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
5016 make_cleanup (xfree
, cond_string
);
5018 /* ----------------------------- SNIP -----------------------------
5019 Anything added to the cleanup chain beyond this point is assumed
5020 to be part of a breakpoint. If the breakpoint create goes
5021 through then that memory is not cleaned up. */
5022 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5024 /* Mark the contents of the addr_string for cleanup. These go on
5025 the breakpoint_chain and only occure if the breakpoint create
5027 for (i
= 0; i
< sals
.nelts
; i
++)
5029 if (addr_string
[i
] != NULL
)
5030 make_cleanup (xfree
, addr_string
[i
]);
5033 /* Wait until now before checking for garbage at the end of the
5034 address. That way cleanups can take care of freeing any
5036 if (*address_end
!= '\0')
5037 error ("Garbage %s following breakpoint address", address_end
);
5039 /* Resolve all line numbers to PC's. */
5040 breakpoint_sals_to_pc (&sals
, args
->address
);
5042 /* Verify that conditions can be parsed, before setting any
5044 for (i
= 0; i
< sals
.nelts
; i
++)
5046 if (args
->condition
!= NULL
)
5048 char *tok
= args
->condition
;
5049 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
5051 error ("Garbage %s follows condition", tok
);
5052 make_cleanup (xfree
, cond
[i
]);
5053 cond_string
[i
] = xstrdup (args
->condition
);
5057 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
5058 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
5059 args
->tempflag
? disp_del
: disp_donttouch
,
5060 args
->thread
, args
->ignore_count
, 0/*from-tty*/);
5062 /* That's it. Discard the cleanups for data inserted into the
5064 discard_cleanups (breakpoint_chain
);
5065 /* But cleanup everything else. */
5066 do_cleanups (old_chain
);
5071 gdb_breakpoint (char *address
, char *condition
,
5072 int hardwareflag
, int tempflag
,
5073 int thread
, int ignore_count
)
5075 struct captured_breakpoint_args args
;
5076 args
.address
= address
;
5077 args
.condition
= condition
;
5078 args
.hardwareflag
= hardwareflag
;
5079 args
.tempflag
= tempflag
;
5080 args
.thread
= thread
;
5081 args
.ignore_count
= ignore_count
;
5082 return catch_errors (do_captured_breakpoint
, &args
,
5083 NULL
, RETURN_MASK_ALL
);
5088 break_at_finish_at_depth_command_1 (char *arg
, int flag
, int from_tty
)
5090 struct frame_info
*frame
;
5091 CORE_ADDR low
, high
, selected_pc
= 0;
5092 char *extra_args
= NULL
;
5094 int extra_args_len
= 0, if_arg
= 0;
5097 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
5100 if (default_breakpoint_valid
)
5102 if (deprecated_selected_frame
)
5104 selected_pc
= get_frame_pc (deprecated_selected_frame
);
5109 error ("No selected frame.");
5112 error ("No default breakpoint address now.");
5116 extra_args
= strchr (arg
, ' ');
5120 extra_args_len
= strlen (extra_args
);
5121 level_arg
= (char *) xmalloc (extra_args
- arg
);
5122 strncpy (level_arg
, arg
, extra_args
- arg
- 1);
5123 level_arg
[extra_args
- arg
- 1] = '\0';
5127 level_arg
= (char *) xmalloc (strlen (arg
) + 1);
5128 strcpy (level_arg
, arg
);
5131 frame
= parse_frame_specification (level_arg
);
5133 selected_pc
= get_frame_pc (frame
);
5140 extra_args_len
= strlen (arg
);
5145 if (find_pc_partial_function (selected_pc
, (char **) NULL
, &low
, &high
))
5149 addr_string
= xstrprintf ("*0x%s %s", paddr_nz (high
), extra_args
);
5151 addr_string
= xstrprintf ("*0x%s", paddr_nz (high
));
5152 break_command_1 (addr_string
, flag
, from_tty
);
5153 xfree (addr_string
);
5156 error ("No function contains the specified address");
5159 error ("Unable to set breakpoint at procedure exit");
5164 break_at_finish_command_1 (char *arg
, int flag
, int from_tty
)
5166 char *addr_string
, *break_string
, *beg_addr_string
;
5167 CORE_ADDR low
, high
;
5168 struct symtabs_and_lines sals
;
5169 struct symtab_and_line sal
;
5170 struct cleanup
*old_chain
;
5171 char *extra_args
= NULL
;
5172 int extra_args_len
= 0;
5176 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
5178 if (default_breakpoint_valid
)
5180 if (deprecated_selected_frame
)
5182 addr_string
= xstrprintf ("*0x%s",
5183 paddr_nz (get_frame_pc (deprecated_selected_frame
)));
5188 error ("No selected frame.");
5191 error ("No default breakpoint address now.");
5195 addr_string
= (char *) xmalloc (strlen (arg
) + 1);
5196 strcpy (addr_string
, arg
);
5202 extra_args_len
= strlen (arg
);
5206 /* get the stuff after the function name or address */
5207 extra_args
= strchr (arg
, ' ');
5211 extra_args_len
= strlen (extra_args
);
5218 beg_addr_string
= addr_string
;
5219 sals
= decode_line_1 (&addr_string
, 1, (struct symtab
*) NULL
, 0,
5222 xfree (beg_addr_string
);
5223 old_chain
= make_cleanup (xfree
, sals
.sals
);
5224 for (i
= 0; (i
< sals
.nelts
); i
++)
5227 if (find_pc_partial_function (sal
.pc
, (char **) NULL
, &low
, &high
))
5231 break_string
= xstrprintf ("*0x%s %s", paddr_nz (high
),
5234 break_string
= xstrprintf ("*0x%s", paddr_nz (high
));
5235 break_command_1 (break_string
, flag
, from_tty
);
5236 xfree (break_string
);
5239 error ("No function contains the specified address");
5243 warning ("Multiple breakpoints were set.\n");
5244 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5246 do_cleanups (old_chain
);
5250 /* Helper function for break_command_1 and disassemble_command. */
5253 resolve_sal_pc (struct symtab_and_line
*sal
)
5257 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5259 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5260 error ("No line %d in file \"%s\".",
5261 sal
->line
, sal
->symtab
->filename
);
5265 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5267 struct blockvector
*bv
;
5272 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5275 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5276 sym
= block_function (b
);
5279 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5280 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5284 /* It really is worthwhile to have the section, so we'll just
5285 have to look harder. This case can be executed if we have
5286 line numbers but no functions (as can happen in assembly
5289 struct minimal_symbol
*msym
;
5291 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5293 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5300 break_command (char *arg
, int from_tty
)
5302 break_command_1 (arg
, 0, from_tty
);
5306 break_at_finish_command (char *arg
, int from_tty
)
5308 break_at_finish_command_1 (arg
, 0, from_tty
);
5312 break_at_finish_at_depth_command (char *arg
, int from_tty
)
5314 break_at_finish_at_depth_command_1 (arg
, 0, from_tty
);
5318 tbreak_command (char *arg
, int from_tty
)
5320 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5324 tbreak_at_finish_command (char *arg
, int from_tty
)
5326 break_at_finish_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5330 hbreak_command (char *arg
, int from_tty
)
5332 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5336 thbreak_command (char *arg
, int from_tty
)
5338 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5342 stop_command (char *arg
, int from_tty
)
5344 printf_filtered ("Specify the type of breakpoint to set.\n\
5345 Usage: stop in <function | address>\n\
5350 stopin_command (char *arg
, int from_tty
)
5354 if (arg
== (char *) NULL
)
5356 else if (*arg
!= '*')
5361 /* look for a ':'. If this is a line number specification, then
5362 say it is bad, otherwise, it should be an address or
5363 function/method name */
5364 while (*argptr
&& !hasColon
)
5366 hasColon
= (*argptr
== ':');
5371 badInput
= (*argptr
!= ':'); /* Not a class::method */
5373 badInput
= isdigit (*arg
); /* a simple line number */
5377 printf_filtered ("Usage: stop in <function | address>\n");
5379 break_command_1 (arg
, 0, from_tty
);
5383 stopat_command (char *arg
, int from_tty
)
5387 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5394 /* look for a ':'. If there is a '::' then get out, otherwise
5395 it is probably a line number. */
5396 while (*argptr
&& !hasColon
)
5398 hasColon
= (*argptr
== ':');
5403 badInput
= (*argptr
== ':'); /* we have class::method */
5405 badInput
= !isdigit (*arg
); /* not a line number */
5409 printf_filtered ("Usage: stop at <line>\n");
5411 break_command_1 (arg
, 0, from_tty
);
5414 /* accessflag: hw_write: watch write,
5415 hw_read: watch read,
5416 hw_access: watch access (read or write) */
5418 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5420 struct breakpoint
*b
;
5421 struct symtab_and_line sal
;
5422 struct expression
*exp
;
5423 struct block
*exp_valid_block
;
5424 struct value
*val
, *mark
;
5425 struct frame_info
*frame
;
5426 struct frame_info
*prev_frame
= NULL
;
5427 char *exp_start
= NULL
;
5428 char *exp_end
= NULL
;
5429 char *tok
, *end_tok
;
5431 char *cond_start
= NULL
;
5432 char *cond_end
= NULL
;
5433 struct expression
*cond
= NULL
;
5434 int i
, other_type_used
, target_resources_ok
= 0;
5435 enum bptype bp_type
;
5438 init_sal (&sal
); /* initialize to zeroes */
5440 /* Parse arguments. */
5441 innermost_block
= NULL
;
5443 exp
= parse_exp_1 (&arg
, 0, 0);
5445 exp_valid_block
= innermost_block
;
5446 mark
= value_mark ();
5447 val
= evaluate_expression (exp
);
5448 release_value (val
);
5449 if (VALUE_LAZY (val
))
5450 value_fetch_lazy (val
);
5453 while (*tok
== ' ' || *tok
== '\t')
5457 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5460 toklen
= end_tok
- tok
;
5461 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5463 tok
= cond_start
= end_tok
+ 1;
5464 cond
= parse_exp_1 (&tok
, 0, 0);
5468 error ("Junk at end of command.");
5470 if (accessflag
== hw_read
)
5471 bp_type
= bp_read_watchpoint
;
5472 else if (accessflag
== hw_access
)
5473 bp_type
= bp_access_watchpoint
;
5475 bp_type
= bp_hardware_watchpoint
;
5477 mem_cnt
= can_use_hardware_watchpoint (val
);
5478 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5479 error ("Expression cannot be implemented with read/access watchpoint.");
5482 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5483 target_resources_ok
=
5484 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5486 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5487 error ("Target does not support this type of hardware watchpoint.");
5489 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5490 error ("Target can only support one kind of HW watchpoint at a time.");
5493 #if defined(HPUXHPPA)
5494 /* On HP-UX if you set a h/w
5495 watchpoint before the "run" command, the inferior dies with a e.g.,
5496 SIGILL once you start it. I initially believed this was due to a
5497 bad interaction between page protection traps and the initial
5498 startup sequence by the dynamic linker.
5500 However, I tried avoiding that by having HP-UX's implementation of
5501 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5502 yet, which forced slow watches before a "run" or "attach", and it
5503 still fails somewhere in the startup code.
5505 Until I figure out what's happening, I'm disallowing watches altogether
5506 before the "run" or "attach" command. We'll tell the user they must
5507 set watches after getting the program started. */
5508 if (!target_has_execution
)
5510 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5513 #endif /* HPUXHPPA */
5515 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5516 watchpoint could not be set. */
5517 if (!mem_cnt
|| target_resources_ok
<= 0)
5518 bp_type
= bp_watchpoint
;
5520 /* Now set up the breakpoint. */
5521 b
= set_raw_breakpoint (sal
, bp_type
);
5522 set_breakpoint_count (breakpoint_count
+ 1);
5523 b
->number
= breakpoint_count
;
5524 b
->disposition
= disp_donttouch
;
5526 b
->exp_valid_block
= exp_valid_block
;
5527 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5531 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5535 frame
= block_innermost_frame (exp_valid_block
);
5538 prev_frame
= get_prev_frame (frame
);
5539 b
->watchpoint_frame
= get_frame_id (frame
);
5543 memset (&b
->watchpoint_frame
, 0, sizeof (b
->watchpoint_frame
));
5546 /* If the expression is "local", then set up a "watchpoint scope"
5547 breakpoint at the point where we've left the scope of the watchpoint
5549 if (innermost_block
)
5553 struct breakpoint
*scope_breakpoint
;
5554 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5555 bp_watchpoint_scope
);
5557 scope_breakpoint
->enable_state
= bp_enabled
;
5559 /* Automatically delete the breakpoint when it hits. */
5560 scope_breakpoint
->disposition
= disp_del
;
5562 /* Only break in the proper frame (help with recursion). */
5563 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5565 /* Set the address at which we will stop. */
5566 scope_breakpoint
->loc
->requested_address
5567 = get_frame_pc (prev_frame
);
5568 scope_breakpoint
->loc
->address
5569 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
);
5571 /* The scope breakpoint is related to the watchpoint. We
5572 will need to act on them together. */
5573 b
->related_breakpoint
= scope_breakpoint
;
5576 value_free_to_mark (mark
);
5580 /* Return count of locations need to be watched and can be handled
5581 in hardware. If the watchpoint can not be handled
5582 in hardware return zero. */
5584 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5585 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5586 ((BYTE_SIZE) <= (DEPRECATED_REGISTER_SIZE))
5589 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5590 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5591 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5595 can_use_hardware_watchpoint (struct value
*v
)
5597 int found_memory_cnt
= 0;
5598 struct value
*head
= v
;
5600 /* Did the user specifically forbid us to use hardware watchpoints? */
5601 if (!can_use_hw_watchpoints
)
5604 /* Make sure that the value of the expression depends only upon
5605 memory contents, and values computed from them within GDB. If we
5606 find any register references or function calls, we can't use a
5607 hardware watchpoint.
5609 The idea here is that evaluating an expression generates a series
5610 of values, one holding the value of every subexpression. (The
5611 expression a*b+c has five subexpressions: a, b, a*b, c, and
5612 a*b+c.) GDB's values hold almost enough information to establish
5613 the criteria given above --- they identify memory lvalues,
5614 register lvalues, computed values, etcetera. So we can evaluate
5615 the expression, and then scan the chain of values that leaves
5616 behind to decide whether we can detect any possible change to the
5617 expression's final value using only hardware watchpoints.
5619 However, I don't think that the values returned by inferior
5620 function calls are special in any way. So this function may not
5621 notice that an expression involving an inferior function call
5622 can't be watched with hardware watchpoints. FIXME. */
5623 for (; v
; v
= v
->next
)
5625 if (VALUE_LVAL (v
) == lval_memory
)
5628 /* A lazy memory lvalue is one that GDB never needed to fetch;
5629 we either just used its address (e.g., `a' in `a.b') or
5630 we never needed it at all (e.g., `a' in `a,b'). */
5634 /* Ahh, memory we actually used! Check if we can cover
5635 it with hardware watchpoints. */
5636 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
5638 /* We only watch structs and arrays if user asked for it
5639 explicitly, never if they just happen to appear in a
5640 middle of some value chain. */
5642 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5643 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5645 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
5646 int len
= TYPE_LENGTH (VALUE_TYPE (v
));
5648 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5655 else if (v
->lval
!= not_lval
&& v
->modifiable
== 0)
5656 return 0; /* ??? What does this represent? */
5657 else if (v
->lval
== lval_register
)
5658 return 0; /* cannot watch a register with a HW watchpoint */
5661 /* The expression itself looks suitable for using a hardware
5662 watchpoint, but give the target machine a chance to reject it. */
5663 return found_memory_cnt
;
5667 watch_command_wrapper (char *arg
, int from_tty
)
5669 watch_command (arg
, from_tty
);
5673 watch_command (char *arg
, int from_tty
)
5675 watch_command_1 (arg
, hw_write
, from_tty
);
5679 rwatch_command_wrapper (char *arg
, int from_tty
)
5681 rwatch_command (arg
, from_tty
);
5685 rwatch_command (char *arg
, int from_tty
)
5687 watch_command_1 (arg
, hw_read
, from_tty
);
5691 awatch_command_wrapper (char *arg
, int from_tty
)
5693 awatch_command (arg
, from_tty
);
5697 awatch_command (char *arg
, int from_tty
)
5699 watch_command_1 (arg
, hw_access
, from_tty
);
5703 /* Helper routines for the until_command routine in infcmd.c. Here
5704 because it uses the mechanisms of breakpoints. */
5706 /* This function is called by fetch_inferior_event via the
5707 cmd_continuation pointer, to complete the until command. It takes
5708 care of cleaning up the temporary breakpoints set up by the until
5711 until_break_command_continuation (struct continuation_arg
*arg
)
5713 struct cleanup
*cleanups
;
5715 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
5716 do_exec_cleanups (cleanups
);
5720 until_break_command (char *arg
, int from_tty
, int anywhere
)
5722 struct symtabs_and_lines sals
;
5723 struct symtab_and_line sal
;
5724 struct frame_info
*prev_frame
= get_prev_frame (deprecated_selected_frame
);
5725 struct breakpoint
*breakpoint
;
5726 struct cleanup
*old_chain
;
5727 struct continuation_arg
*arg1
;
5730 clear_proceed_status ();
5732 /* Set a breakpoint where the user wants it and at return from
5735 if (default_breakpoint_valid
)
5736 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
5737 default_breakpoint_line
, (char ***) NULL
);
5739 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
5740 0, (char ***) NULL
);
5742 if (sals
.nelts
!= 1)
5743 error ("Couldn't get information on specified line.");
5746 xfree (sals
.sals
); /* malloc'd, so freed */
5749 error ("Junk at end of arguments.");
5751 resolve_sal_pc (&sal
);
5754 /* If the user told us to continue until a specified location,
5755 we don't specify a frame at which we need to stop. */
5756 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
5758 /* Otherwise, specify the current frame, because we want to stop only
5759 at the very same frame. */
5760 breakpoint
= set_momentary_breakpoint (sal
,
5761 get_frame_id (deprecated_selected_frame
),
5764 if (!event_loop_p
|| !target_can_async_p ())
5765 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
5767 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
5769 /* If we are running asynchronously, and the target supports async
5770 execution, we are not waiting for the target to stop, in the call
5771 tp proceed, below. This means that we cannot delete the
5772 brekpoints until the target has actually stopped. The only place
5773 where we get a chance to do that is in fetch_inferior_event, so
5774 we must set things up for that. */
5776 if (event_loop_p
&& target_can_async_p ())
5778 /* In this case the arg for the continuation is just the point
5779 in the exec_cleanups chain from where to start doing
5780 cleanups, because all the continuation does is the cleanups in
5781 the exec_cleanup_chain. */
5783 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
5785 arg1
->data
.pointer
= old_chain
;
5787 add_continuation (until_break_command_continuation
, arg1
);
5790 /* Keep within the current frame, or in frames called by the current
5794 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
5795 sal
.pc
= get_frame_pc (prev_frame
);
5796 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
5798 if (!event_loop_p
|| !target_can_async_p ())
5799 make_cleanup_delete_breakpoint (breakpoint
);
5801 make_exec_cleanup_delete_breakpoint (breakpoint
);
5804 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
5805 /* Do the cleanups now, anly if we are not running asynchronously,
5806 of if we are, but the target is still synchronous. */
5807 if (!event_loop_p
|| !target_can_async_p ())
5808 do_cleanups (old_chain
);
5812 /* These aren't used; I don't konw what they were for. */
5813 /* Set a breakpoint at the catch clause for NAME. */
5815 catch_breakpoint (char *name
)
5820 disable_catch_breakpoint (void)
5825 delete_catch_breakpoint (void)
5830 enable_catch_breakpoint (void)
5836 ep_skip_leading_whitespace (char **s
)
5838 if ((s
== NULL
) || (*s
== NULL
))
5840 while (isspace (**s
))
5844 /* This function examines a string, and attempts to find a token
5845 that might be an event name in the leading characters. If a
5846 possible match is found, a pointer to the last character of
5847 the token is returned. Else, NULL is returned. */
5850 ep_find_event_name_end (char *arg
)
5853 char *event_name_end
= NULL
;
5855 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5859 /* We break out of the loop when we find a token delimiter.
5860 Basically, we're looking for alphanumerics and underscores;
5861 anything else delimites the token. */
5864 if (!isalnum (*s
) && (*s
!= '_'))
5870 return event_name_end
;
5874 /* This function attempts to parse an optional "if <cond>" clause
5875 from the arg string. If one is not found, it returns NULL.
5877 Else, it returns a pointer to the condition string. (It does not
5878 attempt to evaluate the string against a particular block.) And,
5879 it updates arg to point to the first character following the parsed
5880 if clause in the arg string. */
5883 ep_parse_optional_if_clause (char **arg
)
5887 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
5890 /* Skip the "if" keyword. */
5893 /* Skip any extra leading whitespace, and record the start of the
5894 condition string. */
5895 ep_skip_leading_whitespace (arg
);
5898 /* Assume that the condition occupies the remainder of the arg string. */
5899 (*arg
) += strlen (cond_string
);
5904 /* This function attempts to parse an optional filename from the arg
5905 string. If one is not found, it returns NULL.
5907 Else, it returns a pointer to the parsed filename. (This function
5908 makes no attempt to verify that a file of that name exists, or is
5909 accessible.) And, it updates arg to point to the first character
5910 following the parsed filename in the arg string.
5912 Note that clients needing to preserve the returned filename for
5913 future access should copy it to their own buffers. */
5915 ep_parse_optional_filename (char **arg
)
5917 static char filename
[1024];
5922 if ((*arg_p
== '\0') || isspace (*arg_p
))
5940 /* Commands to deal with catching events, such as signals, exceptions,
5941 process start/exit, etc. */
5945 catch_fork
, catch_vfork
5949 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5950 static void catch_fork_command_1 (catch_fork_kind fork_kind
,
5951 char *arg
, int tempflag
, int from_tty
);
5954 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
5957 char *cond_string
= NULL
;
5959 ep_skip_leading_whitespace (&arg
);
5961 /* The allowed syntax is:
5963 catch [v]fork if <cond>
5965 First, check if there's an if clause. */
5966 cond_string
= ep_parse_optional_if_clause (&arg
);
5968 if ((*arg
!= '\0') && !isspace (*arg
))
5969 error ("Junk at end of arguments.");
5971 /* If this target supports it, create a fork or vfork catchpoint
5972 and enable reporting of such events. */
5976 create_fork_event_catchpoint (tempflag
, cond_string
);
5979 create_vfork_event_catchpoint (tempflag
, cond_string
);
5982 error ("unsupported or unknown fork kind; cannot catch it");
5988 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5990 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
5992 char *cond_string
= NULL
;
5994 ep_skip_leading_whitespace (&arg
);
5996 /* The allowed syntax is:
5998 catch exec if <cond>
6000 First, check if there's an if clause. */
6001 cond_string
= ep_parse_optional_if_clause (&arg
);
6003 if ((*arg
!= '\0') && !isspace (*arg
))
6004 error ("Junk at end of arguments.");
6006 /* If this target supports it, create an exec catchpoint
6007 and enable reporting of such events. */
6008 create_exec_event_catchpoint (tempflag
, cond_string
);
6012 #if defined(SOLIB_ADD)
6014 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6016 char *dll_pathname
= NULL
;
6017 char *cond_string
= NULL
;
6019 ep_skip_leading_whitespace (&arg
);
6021 /* The allowed syntax is:
6023 catch load if <cond>
6024 catch load <filename>
6025 catch load <filename> if <cond>
6027 The user is not allowed to specify the <filename> after an
6030 We'll ignore the pathological case of a file named "if".
6032 First, check if there's an if clause. If so, then there
6033 cannot be a filename. */
6034 cond_string
= ep_parse_optional_if_clause (&arg
);
6036 /* If there was an if clause, then there cannot be a filename.
6037 Else, there might be a filename and an if clause. */
6038 if (cond_string
== NULL
)
6040 dll_pathname
= ep_parse_optional_filename (&arg
);
6041 ep_skip_leading_whitespace (&arg
);
6042 cond_string
= ep_parse_optional_if_clause (&arg
);
6045 if ((*arg
!= '\0') && !isspace (*arg
))
6046 error ("Junk at end of arguments.");
6048 /* Create a load breakpoint that only triggers when a load of
6049 the specified dll (or any dll, if no pathname was specified)
6051 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6052 dll_pathname
, cond_string
);
6056 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6058 char *dll_pathname
= NULL
;
6059 char *cond_string
= NULL
;
6061 ep_skip_leading_whitespace (&arg
);
6063 /* The allowed syntax is:
6065 catch unload if <cond>
6066 catch unload <filename>
6067 catch unload <filename> if <cond>
6069 The user is not allowed to specify the <filename> after an
6072 We'll ignore the pathological case of a file named "if".
6074 First, check if there's an if clause. If so, then there
6075 cannot be a filename. */
6076 cond_string
= ep_parse_optional_if_clause (&arg
);
6078 /* If there was an if clause, then there cannot be a filename.
6079 Else, there might be a filename and an if clause. */
6080 if (cond_string
== NULL
)
6082 dll_pathname
= ep_parse_optional_filename (&arg
);
6083 ep_skip_leading_whitespace (&arg
);
6084 cond_string
= ep_parse_optional_if_clause (&arg
);
6087 if ((*arg
!= '\0') && !isspace (*arg
))
6088 error ("Junk at end of arguments.");
6090 /* Create an unload breakpoint that only triggers when an unload of
6091 the specified dll (or any dll, if no pathname was specified)
6093 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6094 dll_pathname
, cond_string
);
6096 #endif /* SOLIB_ADD */
6098 /* Commands to deal with catching exceptions. */
6100 /* Set a breakpoint at the specified callback routine for an
6101 exception event callback */
6104 create_exception_catchpoint (int tempflag
, char *cond_string
,
6105 enum exception_event_kind ex_event
,
6106 struct symtab_and_line
*sal
)
6108 struct breakpoint
*b
;
6109 int thread
= -1; /* All threads. */
6112 if (!sal
) /* no exception support? */
6117 case EX_EVENT_THROW
:
6118 bptype
= bp_catch_throw
;
6120 case EX_EVENT_CATCH
:
6121 bptype
= bp_catch_catch
;
6123 default: /* error condition */
6124 error ("Internal error -- invalid catchpoint kind");
6127 b
= set_raw_breakpoint (*sal
, bptype
);
6128 set_breakpoint_count (breakpoint_count
+ 1);
6129 b
->number
= breakpoint_count
;
6131 b
->cond_string
= (cond_string
== NULL
) ?
6132 NULL
: savestring (cond_string
, strlen (cond_string
));
6134 b
->addr_string
= NULL
;
6135 b
->enable_state
= bp_enabled
;
6136 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6140 static enum print_stop_action
6141 print_exception_catchpoint (struct breakpoint
*b
)
6143 annotate_catchpoint (b
->number
);
6145 if (strstr (b
->addr_string
, "throw") != NULL
)
6146 printf_filtered ("\nCatchpoint %d (exception thrown)\n",
6149 printf_filtered ("\nCatchpoint %d (exception caught)\n",
6152 return PRINT_SRC_AND_LOC
;
6156 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6161 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6164 *last_addr
= b
->loc
->address
;
6165 if (strstr (b
->addr_string
, "throw") != NULL
)
6166 ui_out_field_string (uiout
, "what", "exception throw");
6168 ui_out_field_string (uiout
, "what", "exception catch");
6172 print_mention_exception_catchpoint (struct breakpoint
*b
)
6174 if (strstr (b
->addr_string
, "throw") != NULL
)
6175 printf_filtered ("Catchpoint %d (throw)", b
->number
);
6177 printf_filtered ("Catchpoint %d (catch)", b
->number
);
6180 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6181 print_exception_catchpoint
,
6182 print_one_exception_catchpoint
,
6183 print_mention_exception_catchpoint
6187 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6188 enum exception_event_kind ex_event
, int from_tty
)
6190 char *trigger_func_name
, *nameptr
;
6191 struct symtabs_and_lines sals
;
6192 struct breakpoint
*b
;
6194 if (ex_event
== EX_EVENT_CATCH
)
6195 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6197 trigger_func_name
= xstrdup ("__cxa_throw");
6199 nameptr
= trigger_func_name
;
6200 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
);
6201 if (sals
.nelts
== 0)
6203 xfree (trigger_func_name
);
6207 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6208 set_breakpoint_count (breakpoint_count
+ 1);
6209 b
->number
= breakpoint_count
;
6211 b
->cond_string
= (cond_string
== NULL
) ?
6212 NULL
: savestring (cond_string
, strlen (cond_string
));
6214 b
->addr_string
= trigger_func_name
;
6215 b
->enable_state
= bp_enabled
;
6216 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6217 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6224 /* Deal with "catch catch" and "catch throw" commands */
6227 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6228 int tempflag
, int from_tty
)
6230 char *cond_string
= NULL
;
6231 struct symtab_and_line
*sal
= NULL
;
6233 ep_skip_leading_whitespace (&arg
);
6235 cond_string
= ep_parse_optional_if_clause (&arg
);
6237 if ((*arg
!= '\0') && !isspace (*arg
))
6238 error ("Junk at end of arguments.");
6240 if ((ex_event
!= EX_EVENT_THROW
) &&
6241 (ex_event
!= EX_EVENT_CATCH
))
6242 error ("Unsupported or unknown exception event; cannot catch it");
6244 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6247 /* See if we can find a callback routine */
6248 sal
= target_enable_exception_callback (ex_event
, 1);
6252 /* We have callbacks from the runtime system for exceptions.
6253 Set a breakpoint on the sal found, if no errors */
6254 if (sal
!= (struct symtab_and_line
*) -1)
6255 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6257 return; /* something went wrong with setting up callbacks */
6260 warning ("Unsupported with this platform/compiler combination.");
6263 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6264 inside a catch_errors */
6267 cover_target_enable_exception_callback (void *arg
)
6269 args_for_catchpoint_enable
*args
= arg
;
6270 struct symtab_and_line
*sal
;
6271 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6274 else if (sal
== (struct symtab_and_line
*) -1)
6277 return 1; /*is valid */
6281 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6284 /* The first argument may be an event name, such as "start" or "load".
6285 If so, then handle it as such. If it doesn't match an event name,
6286 then attempt to interpret it as an exception name. (This latter is
6287 the v4.16-and-earlier GDB meaning of the "catch" command.)
6289 First, try to find the bounds of what might be an event name. */
6290 char *arg1_start
= arg
;
6294 if (arg1_start
== NULL
)
6296 /* Old behaviour was to use pre-v-4.16 syntax */
6297 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6299 /* Now, this is not allowed */
6300 error ("Catch requires an event name.");
6303 arg1_end
= ep_find_event_name_end (arg1_start
);
6304 if (arg1_end
== NULL
)
6305 error ("catch requires an event");
6306 arg1_length
= arg1_end
+ 1 - arg1_start
;
6308 /* Try to match what we found against known event names. */
6309 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6311 error ("Catch of signal not yet implemented");
6313 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6315 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6316 tempflag
, from_tty
);
6318 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6320 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6321 tempflag
, from_tty
);
6323 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6325 error ("Catch of thread_start not yet implemented");
6327 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6329 error ("Catch of thread_exit not yet implemented");
6331 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6333 error ("Catch of thread_join not yet implemented");
6335 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6337 error ("Catch of start not yet implemented");
6339 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6341 error ("Catch of exit not yet implemented");
6343 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6345 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6346 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6348 error ("Catch of fork not yet implemented");
6351 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6353 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6354 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6356 error ("Catch of vfork not yet implemented");
6359 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6361 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6362 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6364 error ("Catch of exec not yet implemented");
6367 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6369 #if defined(SOLIB_ADD)
6370 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6372 error ("Catch of load not implemented");
6375 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6377 #if defined(SOLIB_ADD)
6378 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6380 error ("Catch of load not implemented");
6383 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6385 error ("Catch of stop not yet implemented");
6388 /* This doesn't appear to be an event name */
6392 /* Pre-v.4.16 behaviour was to treat the argument
6393 as the name of an exception */
6394 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6395 /* Now this is not allowed */
6396 error ("Unknown event kind specified for catch");
6401 /* Used by the gui, could be made a worker for other things. */
6404 set_breakpoint_sal (struct symtab_and_line sal
)
6406 struct breakpoint
*b
;
6407 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6408 set_breakpoint_count (breakpoint_count
+ 1);
6409 b
->number
= breakpoint_count
;
6416 /* These aren't used; I don't know what they were for. */
6417 /* Disable breakpoints on all catch clauses described in ARGS. */
6419 disable_catch (char *args
)
6421 /* Map the disable command to catch clauses described in ARGS. */
6424 /* Enable breakpoints on all catch clauses described in ARGS. */
6426 enable_catch (char *args
)
6428 /* Map the disable command to catch clauses described in ARGS. */
6431 /* Delete breakpoints on all catch clauses in the active scope. */
6433 delete_catch (char *args
)
6435 /* Map the delete command to catch clauses described in ARGS. */
6440 catch_command (char *arg
, int from_tty
)
6442 catch_command_1 (arg
, 0, from_tty
);
6447 tcatch_command (char *arg
, int from_tty
)
6449 catch_command_1 (arg
, 1, from_tty
);
6452 /* Delete breakpoints by address or line. */
6455 clear_command (char *arg
, int from_tty
)
6457 struct breakpoint
*b
, *tmp
, *prev
, *found
;
6459 struct symtabs_and_lines sals
;
6460 struct symtab_and_line sal
;
6465 sals
= decode_line_spec (arg
, 1);
6470 sals
.sals
= (struct symtab_and_line
*)
6471 xmalloc (sizeof (struct symtab_and_line
));
6472 make_cleanup (xfree
, sals
.sals
);
6473 init_sal (&sal
); /* initialize to zeroes */
6474 sal
.line
= default_breakpoint_line
;
6475 sal
.symtab
= default_breakpoint_symtab
;
6476 sal
.pc
= default_breakpoint_address
;
6477 if (sal
.symtab
== 0)
6478 error ("No source file specified.");
6486 /* For each line spec given, delete bps which correspond
6487 to it. Do it in two passes, solely to preserve the current
6488 behavior that from_tty is forced true if we delete more than
6492 for (i
= 0; i
< sals
.nelts
; i
++)
6494 /* If exact pc given, clear bpts at that pc.
6495 If line given (pc == 0), clear all bpts on specified line.
6496 If defaulting, clear all bpts on default line
6499 defaulting sal.pc != 0 tests to do
6504 1 0 <can't happen> */
6509 /* Find all matching breakpoints, remove them from the
6510 breakpoint chain, and add them to the 'found' chain. */
6511 ALL_BREAKPOINTS_SAFE (b
, tmp
)
6513 /* Are we going to delete b? */
6514 if (b
->type
!= bp_none
6515 && b
->type
!= bp_watchpoint
6516 && b
->type
!= bp_hardware_watchpoint
6517 && b
->type
!= bp_read_watchpoint
6518 && b
->type
!= bp_access_watchpoint
6519 /* Not if b is a watchpoint of any sort... */
6520 && (((sal
.pc
&& (b
->loc
->address
== sal
.pc
))
6521 && (!section_is_overlay (b
->section
)
6522 || b
->section
== sal
.section
))
6523 /* Yes, if sal.pc matches b (modulo overlays). */
6524 || ((default_match
|| (0 == sal
.pc
))
6525 && b
->source_file
!= NULL
6526 && sal
.symtab
!= NULL
6527 && STREQ (b
->source_file
, sal
.symtab
->filename
)
6528 && b
->line_number
== sal
.line
)))
6529 /* Yes, if sal source file and line matches b. */
6531 /* Remove it from breakpoint_chain... */
6532 if (b
== breakpoint_chain
)
6534 /* b is at the head of the list */
6535 breakpoint_chain
= b
->next
;
6539 prev
->next
= b
->next
;
6541 /* And add it to 'found' chain. */
6547 /* Keep b, and keep a pointer to it. */
6552 /* Now go thru the 'found' chain and delete them. */
6556 error ("No breakpoint at %s.", arg
);
6558 error ("No breakpoint at this line.");
6562 from_tty
= 1; /* Always report if deleted more than one */
6564 printf_unfiltered ("Deleted breakpoint%s ", found
->next
? "s" : "");
6565 breakpoints_changed ();
6569 printf_unfiltered ("%d ", found
->number
);
6571 delete_breakpoint (found
);
6575 putchar_unfiltered ('\n');
6578 /* Delete breakpoint in BS if they are `delete' breakpoints and
6579 all breakpoints that are marked for deletion, whether hit or not.
6580 This is called after any breakpoint is hit, or after errors. */
6583 breakpoint_auto_delete (bpstat bs
)
6585 struct breakpoint
*b
, *temp
;
6587 for (; bs
; bs
= bs
->next
)
6588 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== disp_del
6590 delete_breakpoint (bs
->breakpoint_at
);
6592 ALL_BREAKPOINTS_SAFE (b
, temp
)
6594 if (b
->disposition
== disp_del_at_next_stop
)
6595 delete_breakpoint (b
);
6599 /* Delete a breakpoint and clean up all traces of it in the data
6603 delete_breakpoint (struct breakpoint
*bpt
)
6605 struct breakpoint
*b
;
6607 struct bp_location
*loc
;
6610 error ("Internal error (attempted to delete a NULL breakpoint)");
6613 /* Has this bp already been deleted? This can happen because multiple
6614 lists can hold pointers to bp's. bpstat lists are especial culprits.
6616 One example of this happening is a watchpoint's scope bp. When the
6617 scope bp triggers, we notice that the watchpoint is out of scope, and
6618 delete it. We also delete its scope bp. But the scope bp is marked
6619 "auto-deleting", and is already on a bpstat. That bpstat is then
6620 checked for auto-deleting bp's, which are deleted.
6622 A real solution to this problem might involve reference counts in bp's,
6623 and/or giving them pointers back to their referencing bpstat's, and
6624 teaching delete_breakpoint to only free a bp's storage when no more
6625 references were extent. A cheaper bandaid was chosen. */
6626 if (bpt
->type
== bp_none
)
6629 if (delete_breakpoint_hook
)
6630 delete_breakpoint_hook (bpt
);
6631 breakpoint_delete_event (bpt
->number
);
6633 if (bpt
->loc
->inserted
)
6634 remove_breakpoint (bpt
, mark_inserted
);
6636 if (breakpoint_chain
== bpt
)
6637 breakpoint_chain
= bpt
->next
;
6639 if (bp_location_chain
== bpt
->loc
)
6640 bp_location_chain
= bpt
->loc
->next
;
6642 /* If we have callback-style exception catchpoints, don't go through
6643 the adjustments to the C++ runtime library etc. if the inferior
6644 isn't actually running. target_enable_exception_callback for a
6645 null target ops vector gives an undesirable error message, so we
6646 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6647 exceptions are supported in this way, it's OK for now. FIXME */
6648 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
6650 /* Format possible error msg */
6651 char *message
= xstrprintf ("Error in deleting catchpoint %d:\n",
6653 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
6654 args_for_catchpoint_enable args
;
6655 args
.kind
= bpt
->type
== bp_catch_catch
?
6656 EX_EVENT_CATCH
: EX_EVENT_THROW
;
6658 catch_errors (cover_target_enable_exception_callback
, &args
,
6659 message
, RETURN_MASK_ALL
);
6660 do_cleanups (cleanups
);
6667 b
->next
= bpt
->next
;
6671 ALL_BP_LOCATIONS (loc
)
6672 if (loc
->next
== bpt
->loc
)
6674 loc
->next
= bpt
->loc
->next
;
6678 check_duplicates (bpt
);
6679 /* If this breakpoint was inserted, and there is another breakpoint
6680 at the same address, we need to insert the other breakpoint. */
6681 if (bpt
->loc
->inserted
6682 && bpt
->type
!= bp_hardware_watchpoint
6683 && bpt
->type
!= bp_read_watchpoint
6684 && bpt
->type
!= bp_access_watchpoint
6685 && bpt
->type
!= bp_catch_fork
6686 && bpt
->type
!= bp_catch_vfork
6687 && bpt
->type
!= bp_catch_exec
)
6690 if (b
->loc
->address
== bpt
->loc
->address
6691 && b
->section
== bpt
->section
6692 && !b
->loc
->duplicate
6693 && b
->enable_state
!= bp_disabled
6694 && b
->enable_state
!= bp_shlib_disabled
6695 && b
->enable_state
!= bp_call_disabled
)
6699 /* We should never reach this point if there is a permanent
6700 breakpoint at the same address as the one being deleted.
6701 If there is a permanent breakpoint somewhere, it should
6702 always be the only one inserted. */
6703 if (b
->enable_state
== bp_permanent
)
6704 internal_error (__FILE__
, __LINE__
,
6705 "another breakpoint was inserted on top of "
6706 "a permanent breakpoint");
6708 if (b
->type
== bp_hardware_breakpoint
)
6709 val
= target_insert_hw_breakpoint (b
->loc
->address
, b
->loc
->shadow_contents
);
6711 val
= target_insert_breakpoint (b
->loc
->address
, b
->loc
->shadow_contents
);
6713 /* If there was an error in the insert, print a message, then stop execution. */
6716 struct ui_file
*tmp_error_stream
= mem_fileopen ();
6717 make_cleanup_ui_file_delete (tmp_error_stream
);
6720 if (b
->type
== bp_hardware_breakpoint
)
6722 fprintf_unfiltered (tmp_error_stream
,
6723 "Cannot insert hardware breakpoint %d.\n"
6724 "You may have requested too many hardware breakpoints.\n",
6729 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
6730 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
6731 print_address_numeric (b
->loc
->address
, 1, tmp_error_stream
);
6732 fprintf_filtered (tmp_error_stream
, ": %s.\n",
6733 safe_strerror (val
));
6736 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
6737 target_terminal_ours_for_output ();
6738 error_stream(tmp_error_stream
);
6741 b
->loc
->inserted
= 1;
6745 free_command_lines (&bpt
->commands
);
6748 if (bpt
->cond_string
!= NULL
)
6749 xfree (bpt
->cond_string
);
6750 if (bpt
->addr_string
!= NULL
)
6751 xfree (bpt
->addr_string
);
6752 if (bpt
->exp
!= NULL
)
6754 if (bpt
->exp_string
!= NULL
)
6755 xfree (bpt
->exp_string
);
6756 if (bpt
->val
!= NULL
)
6757 value_free (bpt
->val
);
6758 if (bpt
->source_file
!= NULL
)
6759 xfree (bpt
->source_file
);
6760 if (bpt
->dll_pathname
!= NULL
)
6761 xfree (bpt
->dll_pathname
);
6762 if (bpt
->triggered_dll_pathname
!= NULL
)
6763 xfree (bpt
->triggered_dll_pathname
);
6764 if (bpt
->exec_pathname
!= NULL
)
6765 xfree (bpt
->exec_pathname
);
6767 /* Be sure no bpstat's are pointing at it after it's been freed. */
6768 /* FIXME, how can we find all bpstat's?
6769 We just check stop_bpstat for now. */
6770 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
6771 if (bs
->breakpoint_at
== bpt
)
6773 bs
->breakpoint_at
= NULL
;
6775 /* bs->commands will be freed later. */
6777 /* On the chance that someone will soon try again to delete this same
6778 bp, we mark it as deleted before freeing its storage. */
6779 bpt
->type
= bp_none
;
6786 do_delete_breakpoint_cleanup (void *b
)
6788 delete_breakpoint (b
);
6792 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
6794 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
6798 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
6800 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
6804 delete_command (char *arg
, int from_tty
)
6806 struct breakpoint
*b
, *temp
;
6812 int breaks_to_delete
= 0;
6814 /* Delete all breakpoints if no argument.
6815 Do not delete internal or call-dummy breakpoints, these
6816 have to be deleted with an explicit breakpoint number argument. */
6819 if (b
->type
!= bp_call_dummy
&&
6820 b
->type
!= bp_shlib_event
&&
6821 b
->type
!= bp_thread_event
&&
6822 b
->type
!= bp_overlay_event
&&
6824 breaks_to_delete
= 1;
6827 /* Ask user only if there are some breakpoints to delete. */
6829 || (breaks_to_delete
&& query ("Delete all breakpoints? ")))
6831 ALL_BREAKPOINTS_SAFE (b
, temp
)
6833 if (b
->type
!= bp_call_dummy
&&
6834 b
->type
!= bp_shlib_event
&&
6835 b
->type
!= bp_thread_event
&&
6836 b
->type
!= bp_overlay_event
&&
6838 delete_breakpoint (b
);
6843 map_breakpoint_numbers (arg
, delete_breakpoint
);
6846 /* Reset a breakpoint given it's struct breakpoint * BINT.
6847 The value we return ends up being the return value from catch_errors.
6848 Unused in this case. */
6851 breakpoint_re_set_one (void *bint
)
6853 /* get past catch_errs */
6854 struct breakpoint
*b
= (struct breakpoint
*) bint
;
6857 struct symtabs_and_lines sals
;
6859 enum enable_state save_enable
;
6864 warning ("attempted to reset apparently deleted breakpoint #%d?",
6868 case bp_hardware_breakpoint
:
6870 case bp_catch_unload
:
6871 if (b
->addr_string
== NULL
)
6873 /* Anything without a string can't be re-set. */
6874 delete_breakpoint (b
);
6877 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6879 ``And a hack it is, although Apple's Darwin version of GDB
6880 contains an almost identical hack to implement a "future
6881 break" command. It seems to work in many real world cases,
6882 but it is easy to come up with a test case where the patch
6883 doesn't help at all.''
6885 ``It seems that the way GDB implements breakpoints - in -
6886 shared - libraries was designed for a.out shared library
6887 systems (SunOS 4) where shared libraries were loaded at a
6888 fixed address in memory. Since ELF shared libraries can (and
6889 will) be loaded at any address in memory, things break.
6890 Fixing this is not trivial. Therefore, I'm not sure whether
6891 we should add this hack to the branch only. I cannot
6892 guarantee that things will be fixed on the trunk in the near
6895 In case we have a problem, disable this breakpoint. We'll
6896 restore its status if we succeed. Don't disable a
6897 shlib_disabled breakpoint though. There's a fair chance we
6898 can't re-set it if the shared library it's in hasn't been
6900 save_enable
= b
->enable_state
;
6901 if (b
->enable_state
!= bp_shlib_disabled
)
6902 b
->enable_state
= bp_disabled
;
6904 set_language (b
->language
);
6905 input_radix
= b
->input_radix
;
6907 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
);
6908 for (i
= 0; i
< sals
.nelts
; i
++)
6910 resolve_sal_pc (&sals
.sals
[i
]);
6912 /* Reparse conditions, they might contain references to the
6914 if (b
->cond_string
!= NULL
)
6919 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
6922 /* We need to re-set the breakpoint if the address changes... */
6923 if (b
->loc
->address
!= sals
.sals
[i
].pc
6924 /* ...or new and old breakpoints both have source files, and
6925 the source file name or the line number changes... */
6926 || (b
->source_file
!= NULL
6927 && sals
.sals
[i
].symtab
!= NULL
6928 && (!STREQ (b
->source_file
, sals
.sals
[i
].symtab
->filename
)
6929 || b
->line_number
!= sals
.sals
[i
].line
)
6931 /* ...or we switch between having a source file and not having
6933 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
6936 if (b
->source_file
!= NULL
)
6937 xfree (b
->source_file
);
6938 if (sals
.sals
[i
].symtab
== NULL
)
6939 b
->source_file
= NULL
;
6942 savestring (sals
.sals
[i
].symtab
->filename
,
6943 strlen (sals
.sals
[i
].symtab
->filename
));
6944 b
->line_number
= sals
.sals
[i
].line
;
6945 b
->loc
->requested_address
= sals
.sals
[i
].pc
;
6947 = adjust_breakpoint_address (b
->loc
->requested_address
);
6949 /* Used to check for duplicates here, but that can
6950 cause trouble, as it doesn't check for disabled
6955 /* Might be better to do this just once per breakpoint_re_set,
6956 rather than once for every breakpoint. */
6957 breakpoints_changed ();
6959 b
->section
= sals
.sals
[i
].section
;
6960 b
->enable_state
= save_enable
; /* Restore it, this worked. */
6963 /* Now that this is re-enabled, check_duplicates
6965 check_duplicates (b
);
6972 case bp_hardware_watchpoint
:
6973 case bp_read_watchpoint
:
6974 case bp_access_watchpoint
:
6975 innermost_block
= NULL
;
6976 /* The issue arises of what context to evaluate this in. The
6977 same one as when it was set, but what does that mean when
6978 symbols have been re-read? We could save the filename and
6979 functionname, but if the context is more local than that, the
6980 best we could do would be something like how many levels deep
6981 and which index at that particular level, but that's going to
6982 be less stable than filenames or function names. */
6984 /* So for now, just use a global context. */
6987 b
->exp
= parse_expression (b
->exp_string
);
6988 b
->exp_valid_block
= innermost_block
;
6989 mark
= value_mark ();
6991 value_free (b
->val
);
6992 b
->val
= evaluate_expression (b
->exp
);
6993 release_value (b
->val
);
6994 if (VALUE_LAZY (b
->val
) && b
->enable_state
== bp_enabled
)
6995 value_fetch_lazy (b
->val
);
6997 if (b
->cond_string
!= NULL
)
7002 b
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
7004 if (b
->enable_state
== bp_enabled
)
7006 value_free_to_mark (mark
);
7008 case bp_catch_catch
:
7009 case bp_catch_throw
:
7011 /* We needn't really do anything to reset these, since the mask
7012 that requests them is unaffected by e.g., new libraries being
7015 case bp_catch_vfork
:
7020 printf_filtered ("Deleting unknown breakpoint type %d\n", b
->type
);
7022 /* Delete longjmp and overlay event breakpoints; they will be
7023 reset later by breakpoint_re_set. */
7025 case bp_longjmp_resume
:
7026 case bp_overlay_event
:
7027 delete_breakpoint (b
);
7030 /* This breakpoint is special, it's set up when the inferior
7031 starts and we really don't want to touch it. */
7032 case bp_shlib_event
:
7034 /* Like bp_shlib_event, this breakpoint type is special.
7035 Once it is set up, we do not want to touch it. */
7036 case bp_thread_event
:
7038 /* Keep temporary breakpoints, which can be encountered when we step
7039 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7040 Otherwise these should have been blown away via the cleanup chain
7041 or by breakpoint_init_inferior when we rerun the executable. */
7044 case bp_watchpoint_scope
:
7046 case bp_step_resume
:
7053 /* Re-set all breakpoints after symbols have been re-loaded. */
7055 breakpoint_re_set (void)
7057 struct breakpoint
*b
, *temp
;
7058 enum language save_language
;
7059 int save_input_radix
;
7061 save_language
= current_language
->la_language
;
7062 save_input_radix
= input_radix
;
7063 ALL_BREAKPOINTS_SAFE (b
, temp
)
7065 /* Format possible error msg */
7066 char *message
= xstrprintf ("Error in re-setting breakpoint %d:\n",
7068 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7069 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7070 do_cleanups (cleanups
);
7072 set_language (save_language
);
7073 input_radix
= save_input_radix
;
7075 if (GET_LONGJMP_TARGET_P ())
7077 create_longjmp_breakpoint ("longjmp");
7078 create_longjmp_breakpoint ("_longjmp");
7079 create_longjmp_breakpoint ("siglongjmp");
7080 create_longjmp_breakpoint ("_siglongjmp");
7081 create_longjmp_breakpoint (NULL
);
7084 create_overlay_event_breakpoint ("_ovly_debug_event");
7087 /* Reset the thread number of this breakpoint:
7089 - If the breakpoint is for all threads, leave it as-is.
7090 - Else, reset it to the current thread for inferior_ptid. */
7092 breakpoint_re_set_thread (struct breakpoint
*b
)
7094 if (b
->thread
!= -1)
7096 if (in_thread_list (inferior_ptid
))
7097 b
->thread
= pid_to_thread_id (inferior_ptid
);
7101 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7102 If from_tty is nonzero, it prints a message to that effect,
7103 which ends with a period (no newline). */
7106 set_ignore_count (int bptnum
, int count
, int from_tty
)
7108 struct breakpoint
*b
;
7114 if (b
->number
== bptnum
)
7116 b
->ignore_count
= count
;
7120 printf_filtered ("Will stop next time breakpoint %d is reached.",
7122 else if (count
== 1)
7123 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7126 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7129 breakpoints_changed ();
7130 breakpoint_modify_event (b
->number
);
7134 error ("No breakpoint number %d.", bptnum
);
7137 /* Clear the ignore counts of all breakpoints. */
7139 breakpoint_clear_ignore_counts (void)
7141 struct breakpoint
*b
;
7144 b
->ignore_count
= 0;
7147 /* Command to set ignore-count of breakpoint N to COUNT. */
7150 ignore_command (char *args
, int from_tty
)
7156 error_no_arg ("a breakpoint number");
7158 num
= get_number (&p
);
7160 error ("bad breakpoint number: '%s'", args
);
7162 error ("Second argument (specified ignore-count) is missing.");
7164 set_ignore_count (num
,
7165 longest_to_int (value_as_long (parse_and_eval (p
))),
7168 printf_filtered ("\n");
7171 /* Call FUNCTION on each of the breakpoints
7172 whose numbers are given in ARGS. */
7175 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7180 struct breakpoint
*b
, *tmp
;
7184 error_no_arg ("one or more breakpoint numbers");
7191 num
= get_number_or_range (&p1
);
7194 warning ("bad breakpoint number at or near '%s'", p
);
7198 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7199 if (b
->number
== num
)
7201 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7204 if (related_breakpoint
)
7205 function (related_breakpoint
);
7209 printf_unfiltered ("No breakpoint number %d.\n", num
);
7215 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7216 If from_tty is nonzero, it prints a message to that effect,
7217 which ends with a period (no newline). */
7220 disable_breakpoint (struct breakpoint
*bpt
)
7222 /* Never disable a watchpoint scope breakpoint; we want to
7223 hit them when we leave scope so we can delete both the
7224 watchpoint and its scope breakpoint at that time. */
7225 if (bpt
->type
== bp_watchpoint_scope
)
7228 /* You can't disable permanent breakpoints. */
7229 if (bpt
->enable_state
== bp_permanent
)
7232 bpt
->enable_state
= bp_disabled
;
7234 check_duplicates (bpt
);
7236 if (modify_breakpoint_hook
)
7237 modify_breakpoint_hook (bpt
);
7238 breakpoint_modify_event (bpt
->number
);
7242 disable_command (char *args
, int from_tty
)
7244 struct breakpoint
*bpt
;
7246 ALL_BREAKPOINTS (bpt
)
7250 warning ("attempted to disable apparently deleted breakpoint #%d?",
7255 case bp_catch_unload
:
7257 case bp_catch_vfork
:
7259 case bp_catch_catch
:
7260 case bp_catch_throw
:
7261 case bp_hardware_breakpoint
:
7263 case bp_hardware_watchpoint
:
7264 case bp_read_watchpoint
:
7265 case bp_access_watchpoint
:
7266 disable_breakpoint (bpt
);
7271 map_breakpoint_numbers (args
, disable_breakpoint
);
7275 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7277 struct frame_info
*save_selected_frame
= NULL
;
7278 int save_selected_frame_level
= -1;
7279 int target_resources_ok
, other_type_used
;
7282 if (bpt
->type
== bp_hardware_breakpoint
)
7285 i
= hw_breakpoint_used_count ();
7286 target_resources_ok
=
7287 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7289 if (target_resources_ok
== 0)
7290 error ("No hardware breakpoint support in the target.");
7291 else if (target_resources_ok
< 0)
7292 error ("Hardware breakpoints used exceeds limit.");
7295 if (bpt
->enable_state
!= bp_permanent
)
7296 bpt
->enable_state
= bp_enabled
;
7297 bpt
->disposition
= disposition
;
7298 check_duplicates (bpt
);
7299 breakpoints_changed ();
7301 if (bpt
->type
== bp_watchpoint
||
7302 bpt
->type
== bp_hardware_watchpoint
||
7303 bpt
->type
== bp_read_watchpoint
||
7304 bpt
->type
== bp_access_watchpoint
)
7306 if (bpt
->exp_valid_block
!= NULL
)
7308 struct frame_info
*fr
=
7309 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7313 Cannot enable watchpoint %d because the block in which its expression\n\
7314 is valid is not currently in scope.\n", bpt
->number
);
7315 bpt
->enable_state
= bp_disabled
;
7319 save_selected_frame
= deprecated_selected_frame
;
7320 save_selected_frame_level
= frame_relative_level (deprecated_selected_frame
);
7324 value_free (bpt
->val
);
7325 mark
= value_mark ();
7326 bpt
->val
= evaluate_expression (bpt
->exp
);
7327 release_value (bpt
->val
);
7328 if (VALUE_LAZY (bpt
->val
))
7329 value_fetch_lazy (bpt
->val
);
7331 if (bpt
->type
== bp_hardware_watchpoint
||
7332 bpt
->type
== bp_read_watchpoint
||
7333 bpt
->type
== bp_access_watchpoint
)
7335 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7336 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7338 /* Hack around 'unused var' error for some targets here */
7340 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7341 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7342 /* we can consider of type is bp_hardware_watchpoint, convert to
7343 bp_watchpoint in the following condition */
7344 if (target_resources_ok
< 0)
7347 Cannot enable watchpoint %d because target watch resources\n\
7348 have been allocated for other watchpoints.\n", bpt
->number
);
7349 bpt
->enable_state
= bp_disabled
;
7350 value_free_to_mark (mark
);
7355 if (save_selected_frame_level
>= 0)
7356 select_frame (save_selected_frame
);
7357 value_free_to_mark (mark
);
7359 if (modify_breakpoint_hook
)
7360 modify_breakpoint_hook (bpt
);
7361 breakpoint_modify_event (bpt
->number
);
7365 enable_breakpoint (struct breakpoint
*bpt
)
7367 do_enable_breakpoint (bpt
, bpt
->disposition
);
7370 /* The enable command enables the specified breakpoints (or all defined
7371 breakpoints) so they once again become (or continue to be) effective
7372 in stopping the inferior. */
7375 enable_command (char *args
, int from_tty
)
7377 struct breakpoint
*bpt
;
7379 ALL_BREAKPOINTS (bpt
)
7383 warning ("attempted to enable apparently deleted breakpoint #%d?",
7388 case bp_catch_unload
:
7390 case bp_catch_vfork
:
7392 case bp_catch_catch
:
7393 case bp_catch_throw
:
7394 case bp_hardware_breakpoint
:
7396 case bp_hardware_watchpoint
:
7397 case bp_read_watchpoint
:
7398 case bp_access_watchpoint
:
7399 enable_breakpoint (bpt
);
7404 map_breakpoint_numbers (args
, enable_breakpoint
);
7408 enable_once_breakpoint (struct breakpoint
*bpt
)
7410 do_enable_breakpoint (bpt
, disp_disable
);
7414 enable_once_command (char *args
, int from_tty
)
7416 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7420 enable_delete_breakpoint (struct breakpoint
*bpt
)
7422 do_enable_breakpoint (bpt
, disp_del
);
7426 enable_delete_command (char *args
, int from_tty
)
7428 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7431 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7433 struct symtabs_and_lines
7434 decode_line_spec_1 (char *string
, int funfirstline
)
7436 struct symtabs_and_lines sals
;
7438 error ("Empty line specification.");
7439 if (default_breakpoint_valid
)
7440 sals
= decode_line_1 (&string
, funfirstline
,
7441 default_breakpoint_symtab
,
7442 default_breakpoint_line
,
7445 sals
= decode_line_1 (&string
, funfirstline
,
7446 (struct symtab
*) NULL
, 0, (char ***) NULL
);
7448 error ("Junk at end of line specification: %s", string
);
7453 _initialize_breakpoint (void)
7455 struct cmd_list_element
*c
;
7457 breakpoint_chain
= 0;
7458 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7459 before a breakpoint is set. */
7460 breakpoint_count
= 0;
7462 add_com ("ignore", class_breakpoint
, ignore_command
,
7463 "Set ignore-count of breakpoint number N to COUNT.\n\
7464 Usage is `ignore N COUNT'.");
7466 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7468 add_com ("commands", class_breakpoint
, commands_command
,
7469 "Set commands to be executed when a breakpoint is hit.\n\
7470 Give breakpoint number as argument after \"commands\".\n\
7471 With no argument, the targeted breakpoint is the last one set.\n\
7472 The commands themselves follow starting on the next line.\n\
7473 Type a line containing \"end\" to indicate the end of them.\n\
7474 Give \"silent\" as the first line to make the breakpoint silent;\n\
7475 then no output is printed when it is hit, except what the commands print.");
7477 add_com ("condition", class_breakpoint
, condition_command
,
7478 "Specify breakpoint number N to break only if COND is true.\n\
7479 Usage is `condition N COND', where N is an integer and COND is an\n\
7480 expression to be evaluated whenever breakpoint N is reached.");
7482 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
,
7483 "Set a temporary breakpoint. Args like \"break\" command.\n\
7484 Like \"break\" except the breakpoint is only temporary,\n\
7485 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7486 by using \"enable delete\" on the breakpoint number.");
7487 set_cmd_completer (c
, location_completer
);
7489 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
,
7490 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7491 Like \"break\" except the breakpoint requires hardware support,\n\
7492 some target hardware may not have this support.");
7493 set_cmd_completer (c
, location_completer
);
7495 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
,
7496 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7497 Like \"hbreak\" except the breakpoint is only temporary,\n\
7498 so it will be deleted when hit.");
7499 set_cmd_completer (c
, location_completer
);
7501 add_prefix_cmd ("enable", class_breakpoint
, enable_command
,
7502 "Enable some breakpoints.\n\
7503 Give breakpoint numbers (separated by spaces) as arguments.\n\
7504 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7505 This is used to cancel the effect of the \"disable\" command.\n\
7506 With a subcommand you can enable temporarily.",
7507 &enablelist
, "enable ", 1, &cmdlist
);
7509 add_com ("ab", class_breakpoint
, enable_command
,
7510 "Enable some breakpoints.\n\
7511 Give breakpoint numbers (separated by spaces) as arguments.\n\
7512 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7513 This is used to cancel the effect of the \"disable\" command.\n\
7514 With a subcommand you can enable temporarily.");
7516 add_com_alias ("en", "enable", class_breakpoint
, 1);
7518 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
,
7519 "Enable some breakpoints.\n\
7520 Give breakpoint numbers (separated by spaces) as arguments.\n\
7521 This is used to cancel the effect of the \"disable\" command.\n\
7522 May be abbreviated to simply \"enable\".\n",
7523 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
7525 add_cmd ("once", no_class
, enable_once_command
,
7526 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7527 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7530 add_cmd ("delete", no_class
, enable_delete_command
,
7531 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7532 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7535 add_cmd ("delete", no_class
, enable_delete_command
,
7536 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7537 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7540 add_cmd ("once", no_class
, enable_once_command
,
7541 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7542 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7545 add_prefix_cmd ("disable", class_breakpoint
, disable_command
,
7546 "Disable some breakpoints.\n\
7547 Arguments are breakpoint numbers with spaces in between.\n\
7548 To disable all breakpoints, give no argument.\n\
7549 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7550 &disablelist
, "disable ", 1, &cmdlist
);
7551 add_com_alias ("dis", "disable", class_breakpoint
, 1);
7552 add_com_alias ("disa", "disable", class_breakpoint
, 1);
7554 add_com ("sb", class_breakpoint
, disable_command
,
7555 "Disable some breakpoints.\n\
7556 Arguments are breakpoint numbers with spaces in between.\n\
7557 To disable all breakpoints, give no argument.\n\
7558 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7560 add_cmd ("breakpoints", class_alias
, disable_command
,
7561 "Disable some breakpoints.\n\
7562 Arguments are breakpoint numbers with spaces in between.\n\
7563 To disable all breakpoints, give no argument.\n\
7564 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7565 This command may be abbreviated \"disable\".",
7568 add_prefix_cmd ("delete", class_breakpoint
, delete_command
,
7569 "Delete some breakpoints or auto-display expressions.\n\
7570 Arguments are breakpoint numbers with spaces in between.\n\
7571 To delete all breakpoints, give no argument.\n\
7573 Also a prefix command for deletion of other GDB objects.\n\
7574 The \"unset\" command is also an alias for \"delete\".",
7575 &deletelist
, "delete ", 1, &cmdlist
);
7576 add_com_alias ("d", "delete", class_breakpoint
, 1);
7578 add_com ("db", class_breakpoint
, delete_command
,
7579 "Delete some breakpoints.\n\
7580 Arguments are breakpoint numbers with spaces in between.\n\
7581 To delete all breakpoints, give no argument.\n");
7583 add_cmd ("breakpoints", class_alias
, delete_command
,
7584 "Delete some breakpoints or auto-display expressions.\n\
7585 Arguments are breakpoint numbers with spaces in between.\n\
7586 To delete all breakpoints, give no argument.\n\
7587 This command may be abbreviated \"delete\".",
7590 add_com ("clear", class_breakpoint
, clear_command
,
7591 concat ("Clear breakpoint at specified line or function.\n\
7592 Argument may be line number, function name, or \"*\" and an address.\n\
7593 If line number is specified, all breakpoints in that line are cleared.\n\
7594 If function is specified, breakpoints at beginning of function are cleared.\n\
7595 If an address is specified, breakpoints at that address are cleared.\n\n",
7596 "With no argument, clears all breakpoints in the line that the selected frame\n\
7599 See also the \"delete\" command which clears breakpoints by number.", NULL
));
7601 c
= add_com ("break", class_breakpoint
, break_command
,
7602 concat ("Set breakpoint at specified line or function.\n\
7603 Argument may be line number, function name, or \"*\" and an address.\n\
7604 If line number is specified, break at start of code for that line.\n\
7605 If function is specified, break at start of code for that function.\n\
7606 If an address is specified, break at that exact address.\n",
7607 "With no arg, uses current execution address of selected stack frame.\n\
7608 This is useful for breaking on return to a stack frame.\n\
7610 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7612 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL
));
7613 set_cmd_completer (c
, location_completer
);
7615 add_com_alias ("b", "break", class_run
, 1);
7616 add_com_alias ("br", "break", class_run
, 1);
7617 add_com_alias ("bre", "break", class_run
, 1);
7618 add_com_alias ("brea", "break", class_run
, 1);
7622 add_com_alias ("ba", "break", class_breakpoint
, 1);
7623 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
7628 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
,
7629 "Break in function/address or break at a line in the current file.",
7630 &stoplist
, "stop ", 1, &cmdlist
);
7631 add_cmd ("in", class_breakpoint
, stopin_command
,
7632 "Break in function or address.\n", &stoplist
);
7633 add_cmd ("at", class_breakpoint
, stopat_command
,
7634 "Break at a line in the current file.\n", &stoplist
);
7635 add_com ("status", class_info
, breakpoints_info
,
7636 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7637 The \"Type\" column indicates one of:\n\
7638 \tbreakpoint - normal breakpoint\n\
7639 \twatchpoint - watchpoint\n\
7640 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7641 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7642 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7643 address and file/line number respectively.\n\n",
7644 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7645 are set to the address of the last breakpoint listed.\n\n\
7646 Convenience variable \"$bpnum\" contains the number of the last\n\
7647 breakpoint set.", NULL
));
7650 add_info ("breakpoints", breakpoints_info
,
7651 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7652 The \"Type\" column indicates one of:\n\
7653 \tbreakpoint - normal breakpoint\n\
7654 \twatchpoint - watchpoint\n\
7655 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7656 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7657 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7658 address and file/line number respectively.\n\n",
7659 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7660 are set to the address of the last breakpoint listed.\n\n\
7661 Convenience variable \"$bpnum\" contains the number of the last\n\
7662 breakpoint set.", NULL
));
7665 add_com ("lb", class_breakpoint
, breakpoints_info
,
7666 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7667 The \"Type\" column indicates one of:\n\
7668 \tbreakpoint - normal breakpoint\n\
7669 \twatchpoint - watchpoint\n\
7670 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7671 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7672 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7673 address and file/line number respectively.\n\n",
7674 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7675 are set to the address of the last breakpoint listed.\n\n\
7676 Convenience variable \"$bpnum\" contains the number of the last\n\
7677 breakpoint set.", NULL
));
7679 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
,
7680 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7681 The \"Type\" column indicates one of:\n\
7682 \tbreakpoint - normal breakpoint\n\
7683 \twatchpoint - watchpoint\n\
7684 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7685 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7686 \tuntil - internal breakpoint used by the \"until\" command\n\
7687 \tfinish - internal breakpoint used by the \"finish\" command\n",
7688 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7689 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7690 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7691 address and file/line number respectively.\n\n",
7692 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7693 are set to the address of the last breakpoint listed.\n\n\
7694 Convenience variable \"$bpnum\" contains the number of the last\n\
7695 breakpoint set.", NULL
),
7696 &maintenanceinfolist
);
7698 add_com ("catch", class_breakpoint
, catch_command
,
7699 "Set catchpoints to catch events.\n\
7700 Raised signals may be caught:\n\
7701 \tcatch signal - all signals\n\
7702 \tcatch signal <signame> - a particular signal\n\
7703 Raised exceptions may be caught:\n\
7704 \tcatch throw - all exceptions, when thrown\n\
7705 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7706 \tcatch catch - all exceptions, when caught\n\
7707 \tcatch catch <exceptname> - a particular exception, when caught\n\
7708 Thread or process events may be caught:\n\
7709 \tcatch thread_start - any threads, just after creation\n\
7710 \tcatch thread_exit - any threads, just before expiration\n\
7711 \tcatch thread_join - any threads, just after joins\n\
7712 Process events may be caught:\n\
7713 \tcatch start - any processes, just after creation\n\
7714 \tcatch exit - any processes, just before expiration\n\
7715 \tcatch fork - calls to fork()\n\
7716 \tcatch vfork - calls to vfork()\n\
7717 \tcatch exec - calls to exec()\n\
7718 Dynamically-linked library events may be caught:\n\
7719 \tcatch load - loads of any library\n\
7720 \tcatch load <libname> - loads of a particular library\n\
7721 \tcatch unload - unloads of any library\n\
7722 \tcatch unload <libname> - unloads of a particular library\n\
7723 The act of your program's execution stopping may also be caught:\n\
7725 C++ exceptions may be caught:\n\
7726 \tcatch throw - all exceptions, when thrown\n\
7727 \tcatch catch - all exceptions, when caught\n\
7729 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7730 after a fork or vfork is caught.\n\n\
7731 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7733 add_com ("tcatch", class_breakpoint
, tcatch_command
,
7734 "Set temporary catchpoints to catch events.\n\
7735 Args like \"catch\" command.\n\
7736 Like \"catch\" except the catchpoint is only temporary,\n\
7737 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7738 by using \"enable delete\" on the catchpoint number.");
7740 c
= add_com ("watch", class_breakpoint
, watch_command
,
7741 "Set a watchpoint for an expression.\n\
7742 A watchpoint stops execution of your program whenever the value of\n\
7743 an expression changes.");
7744 set_cmd_completer (c
, location_completer
);
7746 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
7747 "Set a read watchpoint for an expression.\n\
7748 A watchpoint stops execution of your program whenever the value of\n\
7749 an expression is read.");
7750 set_cmd_completer (c
, location_completer
);
7752 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
7753 "Set a watchpoint for an expression.\n\
7754 A watchpoint stops execution of your program whenever the value of\n\
7755 an expression is either read or written.");
7756 set_cmd_completer (c
, location_completer
);
7758 add_info ("watchpoints", breakpoints_info
,
7759 "Synonym for ``info breakpoints''.");
7762 c
= add_set_cmd ("can-use-hw-watchpoints", class_support
, var_zinteger
,
7763 (char *) &can_use_hw_watchpoints
,
7764 "Set debugger's willingness to use watchpoint hardware.\n\
7765 If zero, gdb will not use hardware for new watchpoints, even if\n\
7766 such is available. (However, any hardware watchpoints that were\n\
7767 created before setting this to nonzero, will continue to use watchpoint\n\
7770 add_show_from_set (c
, &showlist
);
7772 can_use_hw_watchpoints
= 1;