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 (struct breakpoint
*bpt
, enum bptype bp_type
)
3915 struct bp_location
*loc
, *loc_p
;
3917 loc
= xmalloc (sizeof (struct bp_location
));
3918 memset (loc
, 0, sizeof (*loc
));
3928 case bp_longjmp_resume
:
3929 case bp_step_resume
:
3930 case bp_through_sigtramp
:
3931 case bp_watchpoint_scope
:
3933 case bp_shlib_event
:
3934 case bp_thread_event
:
3935 case bp_overlay_event
:
3937 case bp_catch_unload
:
3938 loc
->loc_type
= bp_loc_software_breakpoint
;
3940 case bp_hardware_breakpoint
:
3941 loc
->loc_type
= bp_loc_hardware_breakpoint
;
3943 case bp_hardware_watchpoint
:
3944 case bp_read_watchpoint
:
3945 case bp_access_watchpoint
:
3946 loc
->loc_type
= bp_loc_hardware_watchpoint
;
3950 case bp_catch_vfork
:
3952 case bp_catch_catch
:
3953 case bp_catch_throw
:
3954 loc
->loc_type
= bp_loc_other
;
3957 internal_error (__FILE__
, __LINE__
, "unknown breakpoint type");
3960 /* Add this breakpoint to the end of the chain. */
3962 loc_p
= bp_location_chain
;
3964 bp_location_chain
= loc
;
3968 loc_p
= loc_p
->next
;
3975 /* set_raw_breakpoint() is a low level routine for allocating and
3976 partially initializing a breakpoint of type BPTYPE. The newly
3977 created breakpoint's address, section, source file name, and line
3978 number are provided by SAL. The newly created and partially
3979 initialized breakpoint is added to the breakpoint chain and
3980 is also returned as the value of this function.
3982 It is expected that the caller will complete the initialization of
3983 the newly created breakpoint struct as well as output any status
3984 information regarding the creation of a new breakpoint. In
3985 particular, set_raw_breakpoint() does NOT set the breakpoint
3986 number! Care should be taken to not allow an error() to occur
3987 prior to completing the initialization of the breakpoint. If this
3988 should happen, a bogus breakpoint will be left on the chain. */
3991 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
3993 struct breakpoint
*b
, *b1
;
3995 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
3996 memset (b
, 0, sizeof (*b
));
3997 b
->loc
= allocate_bp_location (b
, bptype
);
3998 b
->loc
->requested_address
= sal
.pc
;
3999 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
);
4000 if (sal
.symtab
== NULL
)
4001 b
->source_file
= NULL
;
4003 b
->source_file
= savestring (sal
.symtab
->filename
,
4004 strlen (sal
.symtab
->filename
));
4005 b
->section
= sal
.section
;
4007 b
->language
= current_language
->la_language
;
4008 b
->input_radix
= input_radix
;
4010 b
->line_number
= sal
.line
;
4011 b
->enable_state
= bp_enabled
;
4014 b
->ignore_count
= 0;
4016 b
->frame_id
= null_frame_id
;
4017 b
->dll_pathname
= NULL
;
4018 b
->triggered_dll_pathname
= NULL
;
4019 b
->forked_inferior_pid
= 0;
4020 b
->exec_pathname
= NULL
;
4023 /* Add this breakpoint to the end of the chain
4024 so that a list of breakpoints will come out in order
4025 of increasing numbers. */
4027 b1
= breakpoint_chain
;
4029 breakpoint_chain
= b
;
4037 check_duplicates (b
);
4038 breakpoints_changed ();
4044 /* Note that the breakpoint object B describes a permanent breakpoint
4045 instruction, hard-wired into the inferior's code. */
4047 make_breakpoint_permanent (struct breakpoint
*b
)
4049 b
->enable_state
= bp_permanent
;
4051 /* By definition, permanent breakpoints are already present in the code. */
4052 b
->loc
->inserted
= 1;
4055 static struct breakpoint
*
4056 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4058 static int internal_breakpoint_number
= -1;
4059 struct symtab_and_line sal
;
4060 struct breakpoint
*b
;
4062 init_sal (&sal
); /* initialize to zeroes */
4065 sal
.section
= find_pc_overlay (sal
.pc
);
4067 b
= set_raw_breakpoint (sal
, type
);
4068 b
->number
= internal_breakpoint_number
--;
4069 b
->disposition
= disp_donttouch
;
4076 create_longjmp_breakpoint (char *func_name
)
4078 struct breakpoint
*b
;
4079 struct minimal_symbol
*m
;
4081 if (func_name
== NULL
)
4082 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4085 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4088 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4091 b
->enable_state
= bp_disabled
;
4094 b
->addr_string
= xstrdup (func_name
);
4097 /* Call this routine when stepping and nexting to enable a breakpoint
4098 if we do a longjmp(). When we hit that breakpoint, call
4099 set_longjmp_resume_breakpoint() to figure out where we are going. */
4102 enable_longjmp_breakpoint (void)
4104 struct breakpoint
*b
;
4107 if (b
->type
== bp_longjmp
)
4109 b
->enable_state
= bp_enabled
;
4110 check_duplicates (b
);
4115 disable_longjmp_breakpoint (void)
4117 struct breakpoint
*b
;
4120 if (b
->type
== bp_longjmp
4121 || b
->type
== bp_longjmp_resume
)
4123 b
->enable_state
= bp_disabled
;
4124 check_duplicates (b
);
4129 create_overlay_event_breakpoint (char *func_name
)
4131 struct breakpoint
*b
;
4132 struct minimal_symbol
*m
;
4134 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4137 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4139 b
->addr_string
= xstrdup (func_name
);
4141 if (overlay_debugging
== ovly_auto
)
4143 b
->enable_state
= bp_enabled
;
4144 overlay_events_enabled
= 1;
4148 b
->enable_state
= bp_disabled
;
4149 overlay_events_enabled
= 0;
4154 enable_overlay_breakpoints (void)
4156 struct breakpoint
*b
;
4159 if (b
->type
== bp_overlay_event
)
4161 b
->enable_state
= bp_enabled
;
4162 check_duplicates (b
);
4163 overlay_events_enabled
= 1;
4168 disable_overlay_breakpoints (void)
4170 struct breakpoint
*b
;
4173 if (b
->type
== bp_overlay_event
)
4175 b
->enable_state
= bp_disabled
;
4176 check_duplicates (b
);
4177 overlay_events_enabled
= 0;
4182 create_thread_event_breakpoint (CORE_ADDR address
)
4184 struct breakpoint
*b
;
4186 b
= create_internal_breakpoint (address
, bp_thread_event
);
4188 b
->enable_state
= bp_enabled
;
4189 /* addr_string has to be used or breakpoint_re_set will delete me. */
4190 xasprintf (&b
->addr_string
, "*0x%s", paddr (b
->loc
->address
));
4196 remove_thread_event_breakpoints (void)
4198 struct breakpoint
*b
, *temp
;
4200 ALL_BREAKPOINTS_SAFE (b
, temp
)
4201 if (b
->type
== bp_thread_event
)
4202 delete_breakpoint (b
);
4207 remove_solib_event_breakpoints (void)
4209 struct breakpoint
*b
, *temp
;
4211 ALL_BREAKPOINTS_SAFE (b
, temp
)
4212 if (b
->type
== bp_shlib_event
)
4213 delete_breakpoint (b
);
4217 create_solib_event_breakpoint (CORE_ADDR address
)
4219 struct breakpoint
*b
;
4221 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4225 /* Disable any breakpoints that are on code in shared libraries. Only
4226 apply to enabled breakpoints, disabled ones can just stay disabled. */
4229 disable_breakpoints_in_shlibs (int silent
)
4231 struct breakpoint
*b
;
4232 int disabled_shlib_breaks
= 0;
4234 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4237 #if defined (PC_SOLIB)
4238 if (((b
->type
== bp_breakpoint
) ||
4239 (b
->type
== bp_hardware_breakpoint
)) &&
4240 b
->enable_state
== bp_enabled
&&
4241 !b
->loc
->duplicate
&&
4242 PC_SOLIB (b
->loc
->address
))
4244 b
->enable_state
= bp_shlib_disabled
;
4247 if (!disabled_shlib_breaks
)
4249 target_terminal_ours_for_output ();
4250 warning ("Temporarily disabling shared library breakpoints:");
4252 disabled_shlib_breaks
= 1;
4253 warning ("breakpoint #%d ", b
->number
);
4260 /* Try to reenable any breakpoints in shared libraries. */
4262 re_enable_breakpoints_in_shlibs (void)
4264 struct breakpoint
*b
;
4267 if (b
->enable_state
== bp_shlib_disabled
)
4271 /* Do not reenable the breakpoint if the shared library
4272 is still not mapped in. */
4273 if (target_read_memory (b
->loc
->address
, buf
, 1) == 0)
4274 b
->enable_state
= bp_enabled
;
4281 solib_load_unload_1 (char *hookname
, int tempflag
, char *dll_pathname
,
4282 char *cond_string
, enum bptype bp_kind
)
4284 struct breakpoint
*b
;
4285 struct symtabs_and_lines sals
;
4286 struct cleanup
*old_chain
;
4287 struct cleanup
*canonical_strings_chain
= NULL
;
4288 char *addr_start
= hookname
;
4289 char *addr_end
= NULL
;
4290 char **canonical
= (char **) NULL
;
4291 int thread
= -1; /* All threads. */
4293 /* Set a breakpoint on the specified hook. */
4294 sals
= decode_line_1 (&hookname
, 1, (struct symtab
*) NULL
, 0, &canonical
);
4295 addr_end
= hookname
;
4297 if (sals
.nelts
== 0)
4299 warning ("Unable to set a breakpoint on dynamic linker callback.");
4300 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4301 warning ("GDB will be unable to track shl_load/shl_unload calls");
4304 if (sals
.nelts
!= 1)
4306 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4307 warning ("GDB will be unable to track shl_load/shl_unload calls");
4311 /* Make sure that all storage allocated in decode_line_1 gets freed
4312 in case the following errors out. */
4313 old_chain
= make_cleanup (xfree
, sals
.sals
);
4314 if (canonical
!= (char **) NULL
)
4316 make_cleanup (xfree
, canonical
);
4317 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
4318 if (canonical
[0] != NULL
)
4319 make_cleanup (xfree
, canonical
[0]);
4322 resolve_sal_pc (&sals
.sals
[0]);
4324 /* Remove the canonical strings from the cleanup, they are needed below. */
4325 if (canonical
!= (char **) NULL
)
4326 discard_cleanups (canonical_strings_chain
);
4328 b
= set_raw_breakpoint (sals
.sals
[0], bp_kind
);
4329 set_breakpoint_count (breakpoint_count
+ 1);
4330 b
->number
= breakpoint_count
;
4332 b
->cond_string
= (cond_string
== NULL
) ?
4333 NULL
: savestring (cond_string
, strlen (cond_string
));
4336 if (canonical
!= (char **) NULL
&& canonical
[0] != NULL
)
4337 b
->addr_string
= canonical
[0];
4338 else if (addr_start
)
4339 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
4341 b
->enable_state
= bp_enabled
;
4342 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4344 if (dll_pathname
== NULL
)
4345 b
->dll_pathname
= NULL
;
4348 b
->dll_pathname
= (char *) xmalloc (strlen (dll_pathname
) + 1);
4349 strcpy (b
->dll_pathname
, dll_pathname
);
4353 do_cleanups (old_chain
);
4357 create_solib_load_event_breakpoint (char *hookname
, int tempflag
,
4358 char *dll_pathname
, char *cond_string
)
4360 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4361 cond_string
, bp_catch_load
);
4365 create_solib_unload_event_breakpoint (char *hookname
, int tempflag
,
4366 char *dll_pathname
, char *cond_string
)
4368 solib_load_unload_1 (hookname
,tempflag
, dll_pathname
,
4369 cond_string
, bp_catch_unload
);
4373 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4374 enum bptype bp_kind
)
4376 struct symtab_and_line sal
;
4377 struct breakpoint
*b
;
4378 int thread
= -1; /* All threads. */
4385 b
= set_raw_breakpoint (sal
, bp_kind
);
4386 set_breakpoint_count (breakpoint_count
+ 1);
4387 b
->number
= breakpoint_count
;
4389 b
->cond_string
= (cond_string
== NULL
) ?
4390 NULL
: savestring (cond_string
, strlen (cond_string
));
4392 b
->addr_string
= NULL
;
4393 b
->enable_state
= bp_enabled
;
4394 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4395 b
->forked_inferior_pid
= 0;
4401 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4403 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4407 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4409 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4413 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4415 struct symtab_and_line sal
;
4416 struct breakpoint
*b
;
4417 int thread
= -1; /* All threads. */
4424 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4425 set_breakpoint_count (breakpoint_count
+ 1);
4426 b
->number
= breakpoint_count
;
4428 b
->cond_string
= (cond_string
== NULL
) ?
4429 NULL
: savestring (cond_string
, strlen (cond_string
));
4431 b
->addr_string
= NULL
;
4432 b
->enable_state
= bp_enabled
;
4433 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4439 hw_breakpoint_used_count (void)
4441 struct breakpoint
*b
;
4446 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4454 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4456 struct breakpoint
*b
;
4459 *other_type_used
= 0;
4462 if (b
->enable_state
== bp_enabled
)
4464 if (b
->type
== type
)
4466 else if ((b
->type
== bp_hardware_watchpoint
||
4467 b
->type
== bp_read_watchpoint
||
4468 b
->type
== bp_access_watchpoint
)
4469 && b
->enable_state
== bp_enabled
)
4470 *other_type_used
= 1;
4476 /* Call this after hitting the longjmp() breakpoint. Use this to set
4477 a new breakpoint at the target of the jmp_buf.
4479 FIXME - This ought to be done by setting a temporary breakpoint
4480 that gets deleted automatically... */
4483 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4485 struct breakpoint
*b
;
4488 if (b
->type
== bp_longjmp_resume
)
4490 b
->loc
->requested_address
= pc
;
4491 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
);
4492 b
->enable_state
= bp_enabled
;
4493 b
->frame_id
= frame_id
;
4494 check_duplicates (b
);
4500 disable_watchpoints_before_interactive_call_start (void)
4502 struct breakpoint
*b
;
4506 if (((b
->type
== bp_watchpoint
)
4507 || (b
->type
== bp_hardware_watchpoint
)
4508 || (b
->type
== bp_read_watchpoint
)
4509 || (b
->type
== bp_access_watchpoint
)
4510 || ep_is_exception_catchpoint (b
))
4511 && (b
->enable_state
== bp_enabled
))
4513 b
->enable_state
= bp_call_disabled
;
4514 check_duplicates (b
);
4520 enable_watchpoints_after_interactive_call_stop (void)
4522 struct breakpoint
*b
;
4526 if (((b
->type
== bp_watchpoint
)
4527 || (b
->type
== bp_hardware_watchpoint
)
4528 || (b
->type
== bp_read_watchpoint
)
4529 || (b
->type
== bp_access_watchpoint
)
4530 || ep_is_exception_catchpoint (b
))
4531 && (b
->enable_state
== bp_call_disabled
))
4533 b
->enable_state
= bp_enabled
;
4534 check_duplicates (b
);
4540 /* Set a breakpoint that will evaporate an end of command
4541 at address specified by SAL.
4542 Restrict it to frame FRAME if FRAME is nonzero. */
4545 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4548 struct breakpoint
*b
;
4549 b
= set_raw_breakpoint (sal
, type
);
4550 b
->enable_state
= bp_enabled
;
4551 b
->disposition
= disp_donttouch
;
4552 b
->frame_id
= frame_id
;
4554 /* If we're debugging a multi-threaded program, then we
4555 want momentary breakpoints to be active in only a
4556 single thread of control. */
4557 if (in_thread_list (inferior_ptid
))
4558 b
->thread
= pid_to_thread_id (inferior_ptid
);
4564 /* Tell the user we have just set a breakpoint B. */
4567 mention (struct breakpoint
*b
)
4570 struct cleanup
*old_chain
, *ui_out_chain
;
4571 struct ui_stream
*stb
;
4573 stb
= ui_out_stream_new (uiout
);
4574 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4576 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4577 watchpoint) other than breakpoint creation. It should be possible to
4578 clean this up and at the same time replace the random calls to
4579 breakpoint_changed with this hook, as has already been done for
4580 delete_breakpoint_hook and so on. */
4581 if (create_breakpoint_hook
)
4582 create_breakpoint_hook (b
);
4583 breakpoint_create_event (b
->number
);
4585 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4586 b
->ops
->print_mention (b
);
4591 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b
->number
);
4594 ui_out_text (uiout
, "Watchpoint ");
4595 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4596 ui_out_field_int (uiout
, "number", b
->number
);
4597 ui_out_text (uiout
, ": ");
4598 print_expression (b
->exp
, stb
->stream
);
4599 ui_out_field_stream (uiout
, "exp", stb
);
4600 do_cleanups (ui_out_chain
);
4602 case bp_hardware_watchpoint
:
4603 ui_out_text (uiout
, "Hardware watchpoint ");
4604 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4605 ui_out_field_int (uiout
, "number", b
->number
);
4606 ui_out_text (uiout
, ": ");
4607 print_expression (b
->exp
, stb
->stream
);
4608 ui_out_field_stream (uiout
, "exp", stb
);
4609 do_cleanups (ui_out_chain
);
4611 case bp_read_watchpoint
:
4612 ui_out_text (uiout
, "Hardware read watchpoint ");
4613 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4614 ui_out_field_int (uiout
, "number", b
->number
);
4615 ui_out_text (uiout
, ": ");
4616 print_expression (b
->exp
, stb
->stream
);
4617 ui_out_field_stream (uiout
, "exp", stb
);
4618 do_cleanups (ui_out_chain
);
4620 case bp_access_watchpoint
:
4621 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4622 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4623 ui_out_field_int (uiout
, "number", b
->number
);
4624 ui_out_text (uiout
, ": ");
4625 print_expression (b
->exp
, stb
->stream
);
4626 ui_out_field_stream (uiout
, "exp", stb
);
4627 do_cleanups (ui_out_chain
);
4630 if (ui_out_is_mi_like_p (uiout
))
4635 printf_filtered ("Breakpoint %d", b
->number
);
4638 case bp_hardware_breakpoint
:
4639 if (ui_out_is_mi_like_p (uiout
))
4644 printf_filtered ("Hardware assisted breakpoint %d", b
->number
);
4648 case bp_catch_unload
:
4649 printf_filtered ("Catchpoint %d (%s %s)",
4651 (b
->type
== bp_catch_load
) ? "load" : "unload",
4652 (b
->dll_pathname
!= NULL
) ?
4653 b
->dll_pathname
: "<any library>");
4656 case bp_catch_vfork
:
4657 printf_filtered ("Catchpoint %d (%s)",
4659 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4662 printf_filtered ("Catchpoint %d (exec)",
4665 case bp_catch_catch
:
4666 case bp_catch_throw
:
4667 printf_filtered ("Catchpoint %d (%s)",
4669 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4675 case bp_longjmp_resume
:
4676 case bp_step_resume
:
4677 case bp_through_sigtramp
:
4679 case bp_watchpoint_scope
:
4680 case bp_shlib_event
:
4681 case bp_thread_event
:
4682 case bp_overlay_event
:
4688 if (addressprint
|| b
->source_file
== NULL
)
4690 printf_filtered (" at ");
4691 print_address_numeric (b
->loc
->address
, 1, gdb_stdout
);
4694 printf_filtered (": file %s, line %d.",
4695 b
->source_file
, b
->line_number
);
4697 do_cleanups (old_chain
);
4698 if (ui_out_is_mi_like_p (uiout
))
4700 printf_filtered ("\n");
4704 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4705 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4706 COND[i] and COND_STRING[i] values.
4708 NOTE: If the function succeeds, the caller is expected to cleanup
4709 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4710 array contents). If the function fails (error() is called), the
4711 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4712 COND and SALS arrays and each of those arrays contents. */
4715 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
4716 struct expression
**cond
, char **cond_string
,
4717 enum bptype type
, enum bpdisp disposition
,
4718 int thread
, int ignore_count
, int from_tty
)
4720 if (type
== bp_hardware_breakpoint
)
4722 int i
= hw_breakpoint_used_count ();
4723 int target_resources_ok
=
4724 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4726 if (target_resources_ok
== 0)
4727 error ("No hardware breakpoint support in the target.");
4728 else if (target_resources_ok
< 0)
4729 error ("Hardware breakpoints used exceeds limit.");
4732 /* Now set all the breakpoints. */
4735 for (i
= 0; i
< sals
.nelts
; i
++)
4737 struct breakpoint
*b
;
4738 struct symtab_and_line sal
= sals
.sals
[i
];
4741 describe_other_breakpoints (sal
.pc
, sal
.section
);
4743 b
= set_raw_breakpoint (sal
, type
);
4744 set_breakpoint_count (breakpoint_count
+ 1);
4745 b
->number
= breakpoint_count
;
4749 b
->addr_string
= addr_string
[i
];
4751 /* addr_string has to be used or breakpoint_re_set will delete
4753 xasprintf (&b
->addr_string
, "*0x%s", paddr (b
->loc
->address
));
4754 b
->cond_string
= cond_string
[i
];
4755 b
->ignore_count
= ignore_count
;
4756 b
->enable_state
= bp_enabled
;
4757 b
->disposition
= disposition
;
4763 /* Parse ARG which is assumed to be a SAL specification possibly
4764 followed by conditionals. On return, SALS contains an array of SAL
4765 addresses found. ADDR_STRING contains a vector of (canonical)
4766 address strings. ARG points to the end of the SAL. */
4769 parse_breakpoint_sals (char **address
,
4770 struct symtabs_and_lines
*sals
,
4771 char ***addr_string
)
4773 char *addr_start
= *address
;
4774 *addr_string
= NULL
;
4775 /* If no arg given, or if first arg is 'if ', use the default
4777 if ((*address
) == NULL
4778 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
4780 if (default_breakpoint_valid
)
4782 struct symtab_and_line sal
;
4783 init_sal (&sal
); /* initialize to zeroes */
4784 sals
->sals
= (struct symtab_and_line
*)
4785 xmalloc (sizeof (struct symtab_and_line
));
4786 sal
.pc
= default_breakpoint_address
;
4787 sal
.line
= default_breakpoint_line
;
4788 sal
.symtab
= default_breakpoint_symtab
;
4789 sal
.section
= find_pc_overlay (sal
.pc
);
4790 sals
->sals
[0] = sal
;
4794 error ("No default breakpoint address now.");
4798 /* Force almost all breakpoints to be in terms of the
4799 current_source_symtab (which is decode_line_1's default). This
4800 should produce the results we want almost all of the time while
4801 leaving default_breakpoint_* alone.
4802 ObjC: However, don't match an Objective-C method name which
4803 may have a '+' or '-' succeeded by a '[' */
4805 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
4807 if (default_breakpoint_valid
4809 || ((strchr ("+-", (*address
)[0]) != NULL
)
4810 && ((*address
)[1] != '['))))
4811 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
4812 default_breakpoint_line
, addr_string
);
4814 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0, addr_string
);
4816 /* For any SAL that didn't have a canonical string, fill one in. */
4817 if (sals
->nelts
> 0 && *addr_string
== NULL
)
4818 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
4819 if (addr_start
!= (*address
))
4822 for (i
= 0; i
< sals
->nelts
; i
++)
4824 /* Add the string if not present. */
4825 if ((*addr_string
)[i
] == NULL
)
4826 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
4832 /* Convert each SAL into a real PC. Verify that the PC can be
4833 inserted as a breakpoint. If it can't throw an error. */
4836 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
4840 for (i
= 0; i
< sals
->nelts
; i
++)
4842 resolve_sal_pc (&sals
->sals
[i
]);
4844 /* It's possible for the PC to be nonzero, but still an illegal
4845 value on some targets.
4847 For example, on HP-UX if you start gdb, and before running the
4848 inferior you try to set a breakpoint on a shared library function
4849 "foo" where the inferior doesn't call "foo" directly but does
4850 pass its address to another function call, then we do find a
4851 minimal symbol for the "foo", but it's address is invalid.
4852 (Appears to be an index into a table that the loader sets up
4853 when the inferior is run.)
4855 Give the target a chance to bless sals.sals[i].pc before we
4856 try to make a breakpoint for it. */
4857 if (PC_REQUIRES_RUN_BEFORE_USE (sals
->sals
[i
].pc
))
4859 if (address
== NULL
)
4860 error ("Cannot break without a running program.");
4862 error ("Cannot break on %s without a running program.",
4868 /* Set a breakpoint according to ARG (function, linenum or *address)
4869 flag: first bit : 0 non-temporary, 1 temporary.
4870 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4873 break_command_1 (char *arg
, int flag
, int from_tty
)
4875 int tempflag
, hardwareflag
;
4876 struct symtabs_and_lines sals
;
4877 struct expression
**cond
= 0;
4878 /* Pointers in arg to the start, and one past the end, of the
4880 char **cond_string
= (char **) NULL
;
4881 char *addr_start
= arg
;
4883 struct cleanup
*old_chain
;
4884 struct cleanup
*breakpoint_chain
= NULL
;
4887 int ignore_count
= 0;
4889 hardwareflag
= flag
& BP_HARDWAREFLAG
;
4890 tempflag
= flag
& BP_TEMPFLAG
;
4895 parse_breakpoint_sals (&arg
, &sals
, &addr_string
);
4900 /* Create a chain of things that always need to be cleaned up. */
4901 old_chain
= make_cleanup (null_cleanup
, 0);
4903 /* Make sure that all storage allocated to SALS gets freed. */
4904 make_cleanup (xfree
, sals
.sals
);
4906 /* Cleanup the addr_string array but not its contents. */
4907 make_cleanup (xfree
, addr_string
);
4909 /* Allocate space for all the cond expressions. */
4910 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4911 make_cleanup (xfree
, cond
);
4913 /* Allocate space for all the cond strings. */
4914 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4915 make_cleanup (xfree
, cond_string
);
4917 /* ----------------------------- SNIP -----------------------------
4918 Anything added to the cleanup chain beyond this point is assumed
4919 to be part of a breakpoint. If the breakpoint create succeeds
4920 then the memory is not reclaimed. */
4921 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4923 /* Mark the contents of the addr_string for cleanup. These go on
4924 the breakpoint_chain and only occure if the breakpoint create
4926 for (i
= 0; i
< sals
.nelts
; i
++)
4928 if (addr_string
[i
] != NULL
)
4929 make_cleanup (xfree
, addr_string
[i
]);
4932 /* Resolve all line numbers to PC's and verify that the addresses
4933 are ok for the target. */
4934 breakpoint_sals_to_pc (&sals
, addr_start
);
4936 /* Verify that condition can be parsed, before setting any
4937 breakpoints. Allocate a separate condition expression for each
4939 thread
= -1; /* No specific thread yet */
4940 for (i
= 0; i
< sals
.nelts
; i
++)
4947 char *cond_start
= NULL
;
4948 char *cond_end
= NULL
;
4949 while (*tok
== ' ' || *tok
== '\t')
4954 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
4957 toklen
= end_tok
- tok
;
4959 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
4961 tok
= cond_start
= end_tok
+ 1;
4962 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4963 make_cleanup (xfree
, cond
[i
]);
4965 cond_string
[i
] = savestring (cond_start
, cond_end
- cond_start
);
4966 make_cleanup (xfree
, cond_string
[i
]);
4968 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
4974 thread
= strtol (tok
, &tok
, 0);
4976 error ("Junk after thread keyword.");
4977 if (!valid_thread_id (thread
))
4978 error ("Unknown thread %d\n", thread
);
4981 error ("Junk at end of arguments.");
4985 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4986 hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4987 tempflag
? disp_del
: disp_donttouch
,
4988 thread
, ignore_count
, from_tty
);
4992 warning ("Multiple breakpoints were set.");
4993 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4995 /* That's it. Discard the cleanups for data inserted into the
4997 discard_cleanups (breakpoint_chain
);
4998 /* But cleanup everything else. */
4999 do_cleanups (old_chain
);
5002 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5003 linenum or *address) with COND and IGNORE_COUNT. */
5005 struct captured_breakpoint_args
5016 do_captured_breakpoint (void *data
)
5018 struct captured_breakpoint_args
*args
= data
;
5019 struct symtabs_and_lines sals
;
5020 struct expression
**cond
;
5021 struct cleanup
*old_chain
;
5022 struct cleanup
*breakpoint_chain
= NULL
;
5029 /* Parse the source and lines spec. Delay check that the expression
5030 didn't contain trailing garbage until after cleanups are in
5034 address_end
= args
->address
;
5036 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
);
5041 /* Create a chain of things at always need to be cleaned up. */
5042 old_chain
= make_cleanup (null_cleanup
, 0);
5044 /* Always have a addr_string array, even if it is empty. */
5045 make_cleanup (xfree
, addr_string
);
5047 /* Make sure that all storage allocated to SALS gets freed. */
5048 make_cleanup (xfree
, sals
.sals
);
5050 /* Allocate space for all the cond expressions. */
5051 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5052 make_cleanup (xfree
, cond
);
5054 /* Allocate space for all the cond strings. */
5055 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
5056 make_cleanup (xfree
, cond_string
);
5058 /* ----------------------------- SNIP -----------------------------
5059 Anything added to the cleanup chain beyond this point is assumed
5060 to be part of a breakpoint. If the breakpoint create goes
5061 through then that memory is not cleaned up. */
5062 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5064 /* Mark the contents of the addr_string for cleanup. These go on
5065 the breakpoint_chain and only occure if the breakpoint create
5067 for (i
= 0; i
< sals
.nelts
; i
++)
5069 if (addr_string
[i
] != NULL
)
5070 make_cleanup (xfree
, addr_string
[i
]);
5073 /* Wait until now before checking for garbage at the end of the
5074 address. That way cleanups can take care of freeing any
5076 if (*address_end
!= '\0')
5077 error ("Garbage %s following breakpoint address", address_end
);
5079 /* Resolve all line numbers to PC's. */
5080 breakpoint_sals_to_pc (&sals
, args
->address
);
5082 /* Verify that conditions can be parsed, before setting any
5084 for (i
= 0; i
< sals
.nelts
; i
++)
5086 if (args
->condition
!= NULL
)
5088 char *tok
= args
->condition
;
5089 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
5091 error ("Garbage %s follows condition", tok
);
5092 make_cleanup (xfree
, cond
[i
]);
5093 cond_string
[i
] = xstrdup (args
->condition
);
5097 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
5098 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
5099 args
->tempflag
? disp_del
: disp_donttouch
,
5100 args
->thread
, args
->ignore_count
, 0/*from-tty*/);
5102 /* That's it. Discard the cleanups for data inserted into the
5104 discard_cleanups (breakpoint_chain
);
5105 /* But cleanup everything else. */
5106 do_cleanups (old_chain
);
5111 gdb_breakpoint (char *address
, char *condition
,
5112 int hardwareflag
, int tempflag
,
5113 int thread
, int ignore_count
)
5115 struct captured_breakpoint_args args
;
5116 args
.address
= address
;
5117 args
.condition
= condition
;
5118 args
.hardwareflag
= hardwareflag
;
5119 args
.tempflag
= tempflag
;
5120 args
.thread
= thread
;
5121 args
.ignore_count
= ignore_count
;
5122 return catch_errors (do_captured_breakpoint
, &args
,
5123 NULL
, RETURN_MASK_ALL
);
5128 break_at_finish_at_depth_command_1 (char *arg
, int flag
, int from_tty
)
5130 struct frame_info
*frame
;
5131 CORE_ADDR low
, high
, selected_pc
= 0;
5132 char *extra_args
= NULL
;
5134 int extra_args_len
= 0, if_arg
= 0;
5137 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
5140 if (default_breakpoint_valid
)
5142 if (deprecated_selected_frame
)
5144 selected_pc
= get_frame_pc (deprecated_selected_frame
);
5149 error ("No selected frame.");
5152 error ("No default breakpoint address now.");
5156 extra_args
= strchr (arg
, ' ');
5160 extra_args_len
= strlen (extra_args
);
5161 level_arg
= (char *) xmalloc (extra_args
- arg
);
5162 strncpy (level_arg
, arg
, extra_args
- arg
- 1);
5163 level_arg
[extra_args
- arg
- 1] = '\0';
5167 level_arg
= (char *) xmalloc (strlen (arg
) + 1);
5168 strcpy (level_arg
, arg
);
5171 frame
= parse_frame_specification (level_arg
);
5173 selected_pc
= get_frame_pc (frame
);
5180 extra_args_len
= strlen (arg
);
5185 if (find_pc_partial_function (selected_pc
, (char **) NULL
, &low
, &high
))
5189 addr_string
= xstrprintf ("*0x%s %s", paddr_nz (high
), extra_args
);
5191 addr_string
= xstrprintf ("*0x%s", paddr_nz (high
));
5192 break_command_1 (addr_string
, flag
, from_tty
);
5193 xfree (addr_string
);
5196 error ("No function contains the specified address");
5199 error ("Unable to set breakpoint at procedure exit");
5204 break_at_finish_command_1 (char *arg
, int flag
, int from_tty
)
5206 char *addr_string
, *break_string
, *beg_addr_string
;
5207 CORE_ADDR low
, high
;
5208 struct symtabs_and_lines sals
;
5209 struct symtab_and_line sal
;
5210 struct cleanup
*old_chain
;
5211 char *extra_args
= NULL
;
5212 int extra_args_len
= 0;
5216 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
5218 if (default_breakpoint_valid
)
5220 if (deprecated_selected_frame
)
5222 addr_string
= xstrprintf ("*0x%s",
5223 paddr_nz (get_frame_pc (deprecated_selected_frame
)));
5228 error ("No selected frame.");
5231 error ("No default breakpoint address now.");
5235 addr_string
= (char *) xmalloc (strlen (arg
) + 1);
5236 strcpy (addr_string
, arg
);
5242 extra_args_len
= strlen (arg
);
5246 /* get the stuff after the function name or address */
5247 extra_args
= strchr (arg
, ' ');
5251 extra_args_len
= strlen (extra_args
);
5258 beg_addr_string
= addr_string
;
5259 sals
= decode_line_1 (&addr_string
, 1, (struct symtab
*) NULL
, 0,
5262 xfree (beg_addr_string
);
5263 old_chain
= make_cleanup (xfree
, sals
.sals
);
5264 for (i
= 0; (i
< sals
.nelts
); i
++)
5267 if (find_pc_partial_function (sal
.pc
, (char **) NULL
, &low
, &high
))
5271 break_string
= xstrprintf ("*0x%s %s", paddr_nz (high
),
5274 break_string
= xstrprintf ("*0x%s", paddr_nz (high
));
5275 break_command_1 (break_string
, flag
, from_tty
);
5276 xfree (break_string
);
5279 error ("No function contains the specified address");
5283 warning ("Multiple breakpoints were set.\n");
5284 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5286 do_cleanups (old_chain
);
5290 /* Helper function for break_command_1 and disassemble_command. */
5293 resolve_sal_pc (struct symtab_and_line
*sal
)
5297 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5299 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5300 error ("No line %d in file \"%s\".",
5301 sal
->line
, sal
->symtab
->filename
);
5305 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5307 struct blockvector
*bv
;
5312 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5315 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5316 sym
= block_function (b
);
5319 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5320 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5324 /* It really is worthwhile to have the section, so we'll just
5325 have to look harder. This case can be executed if we have
5326 line numbers but no functions (as can happen in assembly
5329 struct minimal_symbol
*msym
;
5331 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5333 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5340 break_command (char *arg
, int from_tty
)
5342 break_command_1 (arg
, 0, from_tty
);
5346 break_at_finish_command (char *arg
, int from_tty
)
5348 break_at_finish_command_1 (arg
, 0, from_tty
);
5352 break_at_finish_at_depth_command (char *arg
, int from_tty
)
5354 break_at_finish_at_depth_command_1 (arg
, 0, from_tty
);
5358 tbreak_command (char *arg
, int from_tty
)
5360 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5364 tbreak_at_finish_command (char *arg
, int from_tty
)
5366 break_at_finish_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5370 hbreak_command (char *arg
, int from_tty
)
5372 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5376 thbreak_command (char *arg
, int from_tty
)
5378 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5382 stop_command (char *arg
, int from_tty
)
5384 printf_filtered ("Specify the type of breakpoint to set.\n\
5385 Usage: stop in <function | address>\n\
5390 stopin_command (char *arg
, int from_tty
)
5394 if (arg
== (char *) NULL
)
5396 else if (*arg
!= '*')
5401 /* look for a ':'. If this is a line number specification, then
5402 say it is bad, otherwise, it should be an address or
5403 function/method name */
5404 while (*argptr
&& !hasColon
)
5406 hasColon
= (*argptr
== ':');
5411 badInput
= (*argptr
!= ':'); /* Not a class::method */
5413 badInput
= isdigit (*arg
); /* a simple line number */
5417 printf_filtered ("Usage: stop in <function | address>\n");
5419 break_command_1 (arg
, 0, from_tty
);
5423 stopat_command (char *arg
, int from_tty
)
5427 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5434 /* look for a ':'. If there is a '::' then get out, otherwise
5435 it is probably a line number. */
5436 while (*argptr
&& !hasColon
)
5438 hasColon
= (*argptr
== ':');
5443 badInput
= (*argptr
== ':'); /* we have class::method */
5445 badInput
= !isdigit (*arg
); /* not a line number */
5449 printf_filtered ("Usage: stop at <line>\n");
5451 break_command_1 (arg
, 0, from_tty
);
5454 /* accessflag: hw_write: watch write,
5455 hw_read: watch read,
5456 hw_access: watch access (read or write) */
5458 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5460 struct breakpoint
*b
;
5461 struct symtab_and_line sal
;
5462 struct expression
*exp
;
5463 struct block
*exp_valid_block
;
5464 struct value
*val
, *mark
;
5465 struct frame_info
*frame
;
5466 struct frame_info
*prev_frame
= NULL
;
5467 char *exp_start
= NULL
;
5468 char *exp_end
= NULL
;
5469 char *tok
, *end_tok
;
5471 char *cond_start
= NULL
;
5472 char *cond_end
= NULL
;
5473 struct expression
*cond
= NULL
;
5474 int i
, other_type_used
, target_resources_ok
= 0;
5475 enum bptype bp_type
;
5478 init_sal (&sal
); /* initialize to zeroes */
5480 /* Parse arguments. */
5481 innermost_block
= NULL
;
5483 exp
= parse_exp_1 (&arg
, 0, 0);
5485 exp_valid_block
= innermost_block
;
5486 mark
= value_mark ();
5487 val
= evaluate_expression (exp
);
5488 release_value (val
);
5489 if (VALUE_LAZY (val
))
5490 value_fetch_lazy (val
);
5493 while (*tok
== ' ' || *tok
== '\t')
5497 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5500 toklen
= end_tok
- tok
;
5501 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5503 tok
= cond_start
= end_tok
+ 1;
5504 cond
= parse_exp_1 (&tok
, 0, 0);
5508 error ("Junk at end of command.");
5510 if (accessflag
== hw_read
)
5511 bp_type
= bp_read_watchpoint
;
5512 else if (accessflag
== hw_access
)
5513 bp_type
= bp_access_watchpoint
;
5515 bp_type
= bp_hardware_watchpoint
;
5517 mem_cnt
= can_use_hardware_watchpoint (val
);
5518 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5519 error ("Expression cannot be implemented with read/access watchpoint.");
5522 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5523 target_resources_ok
=
5524 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5526 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5527 error ("Target does not support this type of hardware watchpoint.");
5529 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5530 error ("Target can only support one kind of HW watchpoint at a time.");
5533 #if defined(HPUXHPPA)
5534 /* On HP-UX if you set a h/w
5535 watchpoint before the "run" command, the inferior dies with a e.g.,
5536 SIGILL once you start it. I initially believed this was due to a
5537 bad interaction between page protection traps and the initial
5538 startup sequence by the dynamic linker.
5540 However, I tried avoiding that by having HP-UX's implementation of
5541 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5542 yet, which forced slow watches before a "run" or "attach", and it
5543 still fails somewhere in the startup code.
5545 Until I figure out what's happening, I'm disallowing watches altogether
5546 before the "run" or "attach" command. We'll tell the user they must
5547 set watches after getting the program started. */
5548 if (!target_has_execution
)
5550 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5553 #endif /* HPUXHPPA */
5555 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5556 watchpoint could not be set. */
5557 if (!mem_cnt
|| target_resources_ok
<= 0)
5558 bp_type
= bp_watchpoint
;
5560 /* Now set up the breakpoint. */
5561 b
= set_raw_breakpoint (sal
, bp_type
);
5562 set_breakpoint_count (breakpoint_count
+ 1);
5563 b
->number
= breakpoint_count
;
5564 b
->disposition
= disp_donttouch
;
5566 b
->exp_valid_block
= exp_valid_block
;
5567 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5571 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5575 frame
= block_innermost_frame (exp_valid_block
);
5578 prev_frame
= get_prev_frame (frame
);
5579 b
->watchpoint_frame
= get_frame_id (frame
);
5583 memset (&b
->watchpoint_frame
, 0, sizeof (b
->watchpoint_frame
));
5586 /* If the expression is "local", then set up a "watchpoint scope"
5587 breakpoint at the point where we've left the scope of the watchpoint
5589 if (innermost_block
)
5593 struct breakpoint
*scope_breakpoint
;
5594 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5595 bp_watchpoint_scope
);
5597 scope_breakpoint
->enable_state
= bp_enabled
;
5599 /* Automatically delete the breakpoint when it hits. */
5600 scope_breakpoint
->disposition
= disp_del
;
5602 /* Only break in the proper frame (help with recursion). */
5603 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5605 /* Set the address at which we will stop. */
5606 scope_breakpoint
->loc
->requested_address
5607 = get_frame_pc (prev_frame
);
5608 scope_breakpoint
->loc
->address
5609 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
);
5611 /* The scope breakpoint is related to the watchpoint. We
5612 will need to act on them together. */
5613 b
->related_breakpoint
= scope_breakpoint
;
5616 value_free_to_mark (mark
);
5620 /* Return count of locations need to be watched and can be handled
5621 in hardware. If the watchpoint can not be handled
5622 in hardware return zero. */
5624 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5625 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5626 ((BYTE_SIZE) <= (DEPRECATED_REGISTER_SIZE))
5629 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5630 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5631 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5635 can_use_hardware_watchpoint (struct value
*v
)
5637 int found_memory_cnt
= 0;
5638 struct value
*head
= v
;
5640 /* Did the user specifically forbid us to use hardware watchpoints? */
5641 if (!can_use_hw_watchpoints
)
5644 /* Make sure that the value of the expression depends only upon
5645 memory contents, and values computed from them within GDB. If we
5646 find any register references or function calls, we can't use a
5647 hardware watchpoint.
5649 The idea here is that evaluating an expression generates a series
5650 of values, one holding the value of every subexpression. (The
5651 expression a*b+c has five subexpressions: a, b, a*b, c, and
5652 a*b+c.) GDB's values hold almost enough information to establish
5653 the criteria given above --- they identify memory lvalues,
5654 register lvalues, computed values, etcetera. So we can evaluate
5655 the expression, and then scan the chain of values that leaves
5656 behind to decide whether we can detect any possible change to the
5657 expression's final value using only hardware watchpoints.
5659 However, I don't think that the values returned by inferior
5660 function calls are special in any way. So this function may not
5661 notice that an expression involving an inferior function call
5662 can't be watched with hardware watchpoints. FIXME. */
5663 for (; v
; v
= v
->next
)
5665 if (VALUE_LVAL (v
) == lval_memory
)
5668 /* A lazy memory lvalue is one that GDB never needed to fetch;
5669 we either just used its address (e.g., `a' in `a.b') or
5670 we never needed it at all (e.g., `a' in `a,b'). */
5674 /* Ahh, memory we actually used! Check if we can cover
5675 it with hardware watchpoints. */
5676 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
5678 /* We only watch structs and arrays if user asked for it
5679 explicitly, never if they just happen to appear in a
5680 middle of some value chain. */
5682 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5683 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5685 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
5686 int len
= TYPE_LENGTH (VALUE_TYPE (v
));
5688 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5695 else if (v
->lval
!= not_lval
&& v
->modifiable
== 0)
5696 return 0; /* ??? What does this represent? */
5697 else if (v
->lval
== lval_register
)
5698 return 0; /* cannot watch a register with a HW watchpoint */
5701 /* The expression itself looks suitable for using a hardware
5702 watchpoint, but give the target machine a chance to reject it. */
5703 return found_memory_cnt
;
5707 watch_command_wrapper (char *arg
, int from_tty
)
5709 watch_command (arg
, from_tty
);
5713 watch_command (char *arg
, int from_tty
)
5715 watch_command_1 (arg
, hw_write
, from_tty
);
5719 rwatch_command_wrapper (char *arg
, int from_tty
)
5721 rwatch_command (arg
, from_tty
);
5725 rwatch_command (char *arg
, int from_tty
)
5727 watch_command_1 (arg
, hw_read
, from_tty
);
5731 awatch_command_wrapper (char *arg
, int from_tty
)
5733 awatch_command (arg
, from_tty
);
5737 awatch_command (char *arg
, int from_tty
)
5739 watch_command_1 (arg
, hw_access
, from_tty
);
5743 /* Helper routines for the until_command routine in infcmd.c. Here
5744 because it uses the mechanisms of breakpoints. */
5746 /* This function is called by fetch_inferior_event via the
5747 cmd_continuation pointer, to complete the until command. It takes
5748 care of cleaning up the temporary breakpoints set up by the until
5751 until_break_command_continuation (struct continuation_arg
*arg
)
5753 struct cleanup
*cleanups
;
5755 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
5756 do_exec_cleanups (cleanups
);
5760 until_break_command (char *arg
, int from_tty
, int anywhere
)
5762 struct symtabs_and_lines sals
;
5763 struct symtab_and_line sal
;
5764 struct frame_info
*prev_frame
= get_prev_frame (deprecated_selected_frame
);
5765 struct breakpoint
*breakpoint
;
5766 struct cleanup
*old_chain
;
5767 struct continuation_arg
*arg1
;
5770 clear_proceed_status ();
5772 /* Set a breakpoint where the user wants it and at return from
5775 if (default_breakpoint_valid
)
5776 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
5777 default_breakpoint_line
, (char ***) NULL
);
5779 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
5780 0, (char ***) NULL
);
5782 if (sals
.nelts
!= 1)
5783 error ("Couldn't get information on specified line.");
5786 xfree (sals
.sals
); /* malloc'd, so freed */
5789 error ("Junk at end of arguments.");
5791 resolve_sal_pc (&sal
);
5794 /* If the user told us to continue until a specified location,
5795 we don't specify a frame at which we need to stop. */
5796 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
5798 /* Otherwise, specify the current frame, because we want to stop only
5799 at the very same frame. */
5800 breakpoint
= set_momentary_breakpoint (sal
,
5801 get_frame_id (deprecated_selected_frame
),
5804 if (!event_loop_p
|| !target_can_async_p ())
5805 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
5807 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
5809 /* If we are running asynchronously, and the target supports async
5810 execution, we are not waiting for the target to stop, in the call
5811 tp proceed, below. This means that we cannot delete the
5812 brekpoints until the target has actually stopped. The only place
5813 where we get a chance to do that is in fetch_inferior_event, so
5814 we must set things up for that. */
5816 if (event_loop_p
&& target_can_async_p ())
5818 /* In this case the arg for the continuation is just the point
5819 in the exec_cleanups chain from where to start doing
5820 cleanups, because all the continuation does is the cleanups in
5821 the exec_cleanup_chain. */
5823 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
5825 arg1
->data
.pointer
= old_chain
;
5827 add_continuation (until_break_command_continuation
, arg1
);
5830 /* Keep within the current frame, or in frames called by the current
5834 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
5835 sal
.pc
= get_frame_pc (prev_frame
);
5836 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
5838 if (!event_loop_p
|| !target_can_async_p ())
5839 make_cleanup_delete_breakpoint (breakpoint
);
5841 make_exec_cleanup_delete_breakpoint (breakpoint
);
5844 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
5845 /* Do the cleanups now, anly if we are not running asynchronously,
5846 of if we are, but the target is still synchronous. */
5847 if (!event_loop_p
|| !target_can_async_p ())
5848 do_cleanups (old_chain
);
5852 /* These aren't used; I don't konw what they were for. */
5853 /* Set a breakpoint at the catch clause for NAME. */
5855 catch_breakpoint (char *name
)
5860 disable_catch_breakpoint (void)
5865 delete_catch_breakpoint (void)
5870 enable_catch_breakpoint (void)
5876 ep_skip_leading_whitespace (char **s
)
5878 if ((s
== NULL
) || (*s
== NULL
))
5880 while (isspace (**s
))
5884 /* This function examines a string, and attempts to find a token
5885 that might be an event name in the leading characters. If a
5886 possible match is found, a pointer to the last character of
5887 the token is returned. Else, NULL is returned. */
5890 ep_find_event_name_end (char *arg
)
5893 char *event_name_end
= NULL
;
5895 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5899 /* We break out of the loop when we find a token delimiter.
5900 Basically, we're looking for alphanumerics and underscores;
5901 anything else delimites the token. */
5904 if (!isalnum (*s
) && (*s
!= '_'))
5910 return event_name_end
;
5914 /* This function attempts to parse an optional "if <cond>" clause
5915 from the arg string. If one is not found, it returns NULL.
5917 Else, it returns a pointer to the condition string. (It does not
5918 attempt to evaluate the string against a particular block.) And,
5919 it updates arg to point to the first character following the parsed
5920 if clause in the arg string. */
5923 ep_parse_optional_if_clause (char **arg
)
5927 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
5930 /* Skip the "if" keyword. */
5933 /* Skip any extra leading whitespace, and record the start of the
5934 condition string. */
5935 ep_skip_leading_whitespace (arg
);
5938 /* Assume that the condition occupies the remainder of the arg string. */
5939 (*arg
) += strlen (cond_string
);
5944 /* This function attempts to parse an optional filename from the arg
5945 string. If one is not found, it returns NULL.
5947 Else, it returns a pointer to the parsed filename. (This function
5948 makes no attempt to verify that a file of that name exists, or is
5949 accessible.) And, it updates arg to point to the first character
5950 following the parsed filename in the arg string.
5952 Note that clients needing to preserve the returned filename for
5953 future access should copy it to their own buffers. */
5955 ep_parse_optional_filename (char **arg
)
5957 static char filename
[1024];
5962 if ((*arg_p
== '\0') || isspace (*arg_p
))
5980 /* Commands to deal with catching events, such as signals, exceptions,
5981 process start/exit, etc. */
5985 catch_fork
, catch_vfork
5989 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5990 static void catch_fork_command_1 (catch_fork_kind fork_kind
,
5991 char *arg
, int tempflag
, int from_tty
);
5994 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
5997 char *cond_string
= NULL
;
5999 ep_skip_leading_whitespace (&arg
);
6001 /* The allowed syntax is:
6003 catch [v]fork if <cond>
6005 First, check if there's an if clause. */
6006 cond_string
= ep_parse_optional_if_clause (&arg
);
6008 if ((*arg
!= '\0') && !isspace (*arg
))
6009 error ("Junk at end of arguments.");
6011 /* If this target supports it, create a fork or vfork catchpoint
6012 and enable reporting of such events. */
6016 create_fork_event_catchpoint (tempflag
, cond_string
);
6019 create_vfork_event_catchpoint (tempflag
, cond_string
);
6022 error ("unsupported or unknown fork kind; cannot catch it");
6028 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6030 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6032 char *cond_string
= NULL
;
6034 ep_skip_leading_whitespace (&arg
);
6036 /* The allowed syntax is:
6038 catch exec if <cond>
6040 First, check if there's an if clause. */
6041 cond_string
= ep_parse_optional_if_clause (&arg
);
6043 if ((*arg
!= '\0') && !isspace (*arg
))
6044 error ("Junk at end of arguments.");
6046 /* If this target supports it, create an exec catchpoint
6047 and enable reporting of such events. */
6048 create_exec_event_catchpoint (tempflag
, cond_string
);
6052 #if defined(SOLIB_ADD)
6054 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6056 char *dll_pathname
= NULL
;
6057 char *cond_string
= NULL
;
6059 ep_skip_leading_whitespace (&arg
);
6061 /* The allowed syntax is:
6063 catch load if <cond>
6064 catch load <filename>
6065 catch load <filename> if <cond>
6067 The user is not allowed to specify the <filename> after an
6070 We'll ignore the pathological case of a file named "if".
6072 First, check if there's an if clause. If so, then there
6073 cannot be a filename. */
6074 cond_string
= ep_parse_optional_if_clause (&arg
);
6076 /* If there was an if clause, then there cannot be a filename.
6077 Else, there might be a filename and an if clause. */
6078 if (cond_string
== NULL
)
6080 dll_pathname
= ep_parse_optional_filename (&arg
);
6081 ep_skip_leading_whitespace (&arg
);
6082 cond_string
= ep_parse_optional_if_clause (&arg
);
6085 if ((*arg
!= '\0') && !isspace (*arg
))
6086 error ("Junk at end of arguments.");
6088 /* Create a load breakpoint that only triggers when a load of
6089 the specified dll (or any dll, if no pathname was specified)
6091 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6092 dll_pathname
, cond_string
);
6096 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6098 char *dll_pathname
= NULL
;
6099 char *cond_string
= NULL
;
6101 ep_skip_leading_whitespace (&arg
);
6103 /* The allowed syntax is:
6105 catch unload if <cond>
6106 catch unload <filename>
6107 catch unload <filename> if <cond>
6109 The user is not allowed to specify the <filename> after an
6112 We'll ignore the pathological case of a file named "if".
6114 First, check if there's an if clause. If so, then there
6115 cannot be a filename. */
6116 cond_string
= ep_parse_optional_if_clause (&arg
);
6118 /* If there was an if clause, then there cannot be a filename.
6119 Else, there might be a filename and an if clause. */
6120 if (cond_string
== NULL
)
6122 dll_pathname
= ep_parse_optional_filename (&arg
);
6123 ep_skip_leading_whitespace (&arg
);
6124 cond_string
= ep_parse_optional_if_clause (&arg
);
6127 if ((*arg
!= '\0') && !isspace (*arg
))
6128 error ("Junk at end of arguments.");
6130 /* Create an unload breakpoint that only triggers when an unload of
6131 the specified dll (or any dll, if no pathname was specified)
6133 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6134 dll_pathname
, cond_string
);
6136 #endif /* SOLIB_ADD */
6138 /* Commands to deal with catching exceptions. */
6140 /* Set a breakpoint at the specified callback routine for an
6141 exception event callback */
6144 create_exception_catchpoint (int tempflag
, char *cond_string
,
6145 enum exception_event_kind ex_event
,
6146 struct symtab_and_line
*sal
)
6148 struct breakpoint
*b
;
6149 int thread
= -1; /* All threads. */
6152 if (!sal
) /* no exception support? */
6157 case EX_EVENT_THROW
:
6158 bptype
= bp_catch_throw
;
6160 case EX_EVENT_CATCH
:
6161 bptype
= bp_catch_catch
;
6163 default: /* error condition */
6164 error ("Internal error -- invalid catchpoint kind");
6167 b
= set_raw_breakpoint (*sal
, bptype
);
6168 set_breakpoint_count (breakpoint_count
+ 1);
6169 b
->number
= breakpoint_count
;
6171 b
->cond_string
= (cond_string
== NULL
) ?
6172 NULL
: savestring (cond_string
, strlen (cond_string
));
6174 b
->addr_string
= NULL
;
6175 b
->enable_state
= bp_enabled
;
6176 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6180 static enum print_stop_action
6181 print_exception_catchpoint (struct breakpoint
*b
)
6183 annotate_catchpoint (b
->number
);
6185 if (strstr (b
->addr_string
, "throw") != NULL
)
6186 printf_filtered ("\nCatchpoint %d (exception thrown)\n",
6189 printf_filtered ("\nCatchpoint %d (exception caught)\n",
6192 return PRINT_SRC_AND_LOC
;
6196 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6201 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6204 *last_addr
= b
->loc
->address
;
6205 if (strstr (b
->addr_string
, "throw") != NULL
)
6206 ui_out_field_string (uiout
, "what", "exception throw");
6208 ui_out_field_string (uiout
, "what", "exception catch");
6212 print_mention_exception_catchpoint (struct breakpoint
*b
)
6214 if (strstr (b
->addr_string
, "throw") != NULL
)
6215 printf_filtered ("Catchpoint %d (throw)", b
->number
);
6217 printf_filtered ("Catchpoint %d (catch)", b
->number
);
6220 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6221 print_exception_catchpoint
,
6222 print_one_exception_catchpoint
,
6223 print_mention_exception_catchpoint
6227 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6228 enum exception_event_kind ex_event
, int from_tty
)
6230 char *trigger_func_name
, *nameptr
;
6231 struct symtabs_and_lines sals
;
6232 struct breakpoint
*b
;
6234 if (ex_event
== EX_EVENT_CATCH
)
6235 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6237 trigger_func_name
= xstrdup ("__cxa_throw");
6239 nameptr
= trigger_func_name
;
6240 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
);
6241 if (sals
.nelts
== 0)
6243 xfree (trigger_func_name
);
6247 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6248 set_breakpoint_count (breakpoint_count
+ 1);
6249 b
->number
= breakpoint_count
;
6251 b
->cond_string
= (cond_string
== NULL
) ?
6252 NULL
: savestring (cond_string
, strlen (cond_string
));
6254 b
->addr_string
= trigger_func_name
;
6255 b
->enable_state
= bp_enabled
;
6256 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6257 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6264 /* Deal with "catch catch" and "catch throw" commands */
6267 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6268 int tempflag
, int from_tty
)
6270 char *cond_string
= NULL
;
6271 struct symtab_and_line
*sal
= NULL
;
6273 ep_skip_leading_whitespace (&arg
);
6275 cond_string
= ep_parse_optional_if_clause (&arg
);
6277 if ((*arg
!= '\0') && !isspace (*arg
))
6278 error ("Junk at end of arguments.");
6280 if ((ex_event
!= EX_EVENT_THROW
) &&
6281 (ex_event
!= EX_EVENT_CATCH
))
6282 error ("Unsupported or unknown exception event; cannot catch it");
6284 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6287 /* See if we can find a callback routine */
6288 sal
= target_enable_exception_callback (ex_event
, 1);
6292 /* We have callbacks from the runtime system for exceptions.
6293 Set a breakpoint on the sal found, if no errors */
6294 if (sal
!= (struct symtab_and_line
*) -1)
6295 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6297 return; /* something went wrong with setting up callbacks */
6300 warning ("Unsupported with this platform/compiler combination.");
6303 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6304 inside a catch_errors */
6307 cover_target_enable_exception_callback (void *arg
)
6309 args_for_catchpoint_enable
*args
= arg
;
6310 struct symtab_and_line
*sal
;
6311 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6314 else if (sal
== (struct symtab_and_line
*) -1)
6317 return 1; /*is valid */
6321 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6324 /* The first argument may be an event name, such as "start" or "load".
6325 If so, then handle it as such. If it doesn't match an event name,
6326 then attempt to interpret it as an exception name. (This latter is
6327 the v4.16-and-earlier GDB meaning of the "catch" command.)
6329 First, try to find the bounds of what might be an event name. */
6330 char *arg1_start
= arg
;
6334 if (arg1_start
== NULL
)
6336 /* Old behaviour was to use pre-v-4.16 syntax */
6337 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6339 /* Now, this is not allowed */
6340 error ("Catch requires an event name.");
6343 arg1_end
= ep_find_event_name_end (arg1_start
);
6344 if (arg1_end
== NULL
)
6345 error ("catch requires an event");
6346 arg1_length
= arg1_end
+ 1 - arg1_start
;
6348 /* Try to match what we found against known event names. */
6349 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6351 error ("Catch of signal not yet implemented");
6353 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6355 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6356 tempflag
, from_tty
);
6358 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6360 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6361 tempflag
, from_tty
);
6363 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6365 error ("Catch of thread_start not yet implemented");
6367 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6369 error ("Catch of thread_exit not yet implemented");
6371 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6373 error ("Catch of thread_join not yet implemented");
6375 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6377 error ("Catch of start not yet implemented");
6379 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6381 error ("Catch of exit not yet implemented");
6383 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6385 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6386 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6388 error ("Catch of fork not yet implemented");
6391 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6393 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6394 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6396 error ("Catch of vfork not yet implemented");
6399 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6401 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6402 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6404 error ("Catch of exec not yet implemented");
6407 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6409 #if defined(SOLIB_ADD)
6410 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6412 error ("Catch of load not implemented");
6415 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6417 #if defined(SOLIB_ADD)
6418 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6420 error ("Catch of load not implemented");
6423 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6425 error ("Catch of stop not yet implemented");
6428 /* This doesn't appear to be an event name */
6432 /* Pre-v.4.16 behaviour was to treat the argument
6433 as the name of an exception */
6434 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6435 /* Now this is not allowed */
6436 error ("Unknown event kind specified for catch");
6441 /* Used by the gui, could be made a worker for other things. */
6444 set_breakpoint_sal (struct symtab_and_line sal
)
6446 struct breakpoint
*b
;
6447 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6448 set_breakpoint_count (breakpoint_count
+ 1);
6449 b
->number
= breakpoint_count
;
6456 /* These aren't used; I don't know what they were for. */
6457 /* Disable breakpoints on all catch clauses described in ARGS. */
6459 disable_catch (char *args
)
6461 /* Map the disable command to catch clauses described in ARGS. */
6464 /* Enable breakpoints on all catch clauses described in ARGS. */
6466 enable_catch (char *args
)
6468 /* Map the disable command to catch clauses described in ARGS. */
6471 /* Delete breakpoints on all catch clauses in the active scope. */
6473 delete_catch (char *args
)
6475 /* Map the delete command to catch clauses described in ARGS. */
6480 catch_command (char *arg
, int from_tty
)
6482 catch_command_1 (arg
, 0, from_tty
);
6487 tcatch_command (char *arg
, int from_tty
)
6489 catch_command_1 (arg
, 1, from_tty
);
6492 /* Delete breakpoints by address or line. */
6495 clear_command (char *arg
, int from_tty
)
6497 struct breakpoint
*b
, *tmp
, *prev
, *found
;
6499 struct symtabs_and_lines sals
;
6500 struct symtab_and_line sal
;
6505 sals
= decode_line_spec (arg
, 1);
6510 sals
.sals
= (struct symtab_and_line
*)
6511 xmalloc (sizeof (struct symtab_and_line
));
6512 make_cleanup (xfree
, sals
.sals
);
6513 init_sal (&sal
); /* initialize to zeroes */
6514 sal
.line
= default_breakpoint_line
;
6515 sal
.symtab
= default_breakpoint_symtab
;
6516 sal
.pc
= default_breakpoint_address
;
6517 if (sal
.symtab
== 0)
6518 error ("No source file specified.");
6526 /* For each line spec given, delete bps which correspond
6527 to it. Do it in two passes, solely to preserve the current
6528 behavior that from_tty is forced true if we delete more than
6532 for (i
= 0; i
< sals
.nelts
; i
++)
6534 /* If exact pc given, clear bpts at that pc.
6535 If line given (pc == 0), clear all bpts on specified line.
6536 If defaulting, clear all bpts on default line
6539 defaulting sal.pc != 0 tests to do
6544 1 0 <can't happen> */
6549 /* Find all matching breakpoints, remove them from the
6550 breakpoint chain, and add them to the 'found' chain. */
6551 ALL_BREAKPOINTS_SAFE (b
, tmp
)
6553 /* Are we going to delete b? */
6554 if (b
->type
!= bp_none
6555 && b
->type
!= bp_watchpoint
6556 && b
->type
!= bp_hardware_watchpoint
6557 && b
->type
!= bp_read_watchpoint
6558 && b
->type
!= bp_access_watchpoint
6559 /* Not if b is a watchpoint of any sort... */
6560 && (((sal
.pc
&& (b
->loc
->address
== sal
.pc
))
6561 && (!section_is_overlay (b
->section
)
6562 || b
->section
== sal
.section
))
6563 /* Yes, if sal.pc matches b (modulo overlays). */
6564 || ((default_match
|| (0 == sal
.pc
))
6565 && b
->source_file
!= NULL
6566 && sal
.symtab
!= NULL
6567 && STREQ (b
->source_file
, sal
.symtab
->filename
)
6568 && b
->line_number
== sal
.line
)))
6569 /* Yes, if sal source file and line matches b. */
6571 /* Remove it from breakpoint_chain... */
6572 if (b
== breakpoint_chain
)
6574 /* b is at the head of the list */
6575 breakpoint_chain
= b
->next
;
6579 prev
->next
= b
->next
;
6581 /* And add it to 'found' chain. */
6587 /* Keep b, and keep a pointer to it. */
6592 /* Now go thru the 'found' chain and delete them. */
6596 error ("No breakpoint at %s.", arg
);
6598 error ("No breakpoint at this line.");
6602 from_tty
= 1; /* Always report if deleted more than one */
6604 printf_unfiltered ("Deleted breakpoint%s ", found
->next
? "s" : "");
6605 breakpoints_changed ();
6609 printf_unfiltered ("%d ", found
->number
);
6611 delete_breakpoint (found
);
6615 putchar_unfiltered ('\n');
6618 /* Delete breakpoint in BS if they are `delete' breakpoints and
6619 all breakpoints that are marked for deletion, whether hit or not.
6620 This is called after any breakpoint is hit, or after errors. */
6623 breakpoint_auto_delete (bpstat bs
)
6625 struct breakpoint
*b
, *temp
;
6627 for (; bs
; bs
= bs
->next
)
6628 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== disp_del
6630 delete_breakpoint (bs
->breakpoint_at
);
6632 ALL_BREAKPOINTS_SAFE (b
, temp
)
6634 if (b
->disposition
== disp_del_at_next_stop
)
6635 delete_breakpoint (b
);
6639 /* Delete a breakpoint and clean up all traces of it in the data
6643 delete_breakpoint (struct breakpoint
*bpt
)
6645 struct breakpoint
*b
;
6647 struct bp_location
*loc
;
6650 error ("Internal error (attempted to delete a NULL breakpoint)");
6653 /* Has this bp already been deleted? This can happen because multiple
6654 lists can hold pointers to bp's. bpstat lists are especial culprits.
6656 One example of this happening is a watchpoint's scope bp. When the
6657 scope bp triggers, we notice that the watchpoint is out of scope, and
6658 delete it. We also delete its scope bp. But the scope bp is marked
6659 "auto-deleting", and is already on a bpstat. That bpstat is then
6660 checked for auto-deleting bp's, which are deleted.
6662 A real solution to this problem might involve reference counts in bp's,
6663 and/or giving them pointers back to their referencing bpstat's, and
6664 teaching delete_breakpoint to only free a bp's storage when no more
6665 references were extent. A cheaper bandaid was chosen. */
6666 if (bpt
->type
== bp_none
)
6669 if (delete_breakpoint_hook
)
6670 delete_breakpoint_hook (bpt
);
6671 breakpoint_delete_event (bpt
->number
);
6673 if (bpt
->loc
->inserted
)
6674 remove_breakpoint (bpt
, mark_inserted
);
6676 if (breakpoint_chain
== bpt
)
6677 breakpoint_chain
= bpt
->next
;
6679 if (bp_location_chain
== bpt
->loc
)
6680 bp_location_chain
= bpt
->loc
->next
;
6682 /* If we have callback-style exception catchpoints, don't go through
6683 the adjustments to the C++ runtime library etc. if the inferior
6684 isn't actually running. target_enable_exception_callback for a
6685 null target ops vector gives an undesirable error message, so we
6686 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6687 exceptions are supported in this way, it's OK for now. FIXME */
6688 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
6690 /* Format possible error msg */
6691 char *message
= xstrprintf ("Error in deleting catchpoint %d:\n",
6693 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
6694 args_for_catchpoint_enable args
;
6695 args
.kind
= bpt
->type
== bp_catch_catch
?
6696 EX_EVENT_CATCH
: EX_EVENT_THROW
;
6698 catch_errors (cover_target_enable_exception_callback
, &args
,
6699 message
, RETURN_MASK_ALL
);
6700 do_cleanups (cleanups
);
6707 b
->next
= bpt
->next
;
6711 ALL_BP_LOCATIONS (loc
)
6712 if (loc
->next
== bpt
->loc
)
6714 loc
->next
= bpt
->loc
->next
;
6718 check_duplicates (bpt
);
6719 /* If this breakpoint was inserted, and there is another breakpoint
6720 at the same address, we need to insert the other breakpoint. */
6721 if (bpt
->loc
->inserted
6722 && bpt
->type
!= bp_hardware_watchpoint
6723 && bpt
->type
!= bp_read_watchpoint
6724 && bpt
->type
!= bp_access_watchpoint
6725 && bpt
->type
!= bp_catch_fork
6726 && bpt
->type
!= bp_catch_vfork
6727 && bpt
->type
!= bp_catch_exec
)
6730 if (b
->loc
->address
== bpt
->loc
->address
6731 && b
->section
== bpt
->section
6732 && !b
->loc
->duplicate
6733 && b
->enable_state
!= bp_disabled
6734 && b
->enable_state
!= bp_shlib_disabled
6735 && b
->enable_state
!= bp_call_disabled
)
6739 /* We should never reach this point if there is a permanent
6740 breakpoint at the same address as the one being deleted.
6741 If there is a permanent breakpoint somewhere, it should
6742 always be the only one inserted. */
6743 if (b
->enable_state
== bp_permanent
)
6744 internal_error (__FILE__
, __LINE__
,
6745 "another breakpoint was inserted on top of "
6746 "a permanent breakpoint");
6748 if (b
->type
== bp_hardware_breakpoint
)
6749 val
= target_insert_hw_breakpoint (b
->loc
->address
, b
->loc
->shadow_contents
);
6751 val
= target_insert_breakpoint (b
->loc
->address
, b
->loc
->shadow_contents
);
6753 /* If there was an error in the insert, print a message, then stop execution. */
6756 struct ui_file
*tmp_error_stream
= mem_fileopen ();
6757 make_cleanup_ui_file_delete (tmp_error_stream
);
6760 if (b
->type
== bp_hardware_breakpoint
)
6762 fprintf_unfiltered (tmp_error_stream
,
6763 "Cannot insert hardware breakpoint %d.\n"
6764 "You may have requested too many hardware breakpoints.\n",
6769 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
6770 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
6771 print_address_numeric (b
->loc
->address
, 1, tmp_error_stream
);
6772 fprintf_filtered (tmp_error_stream
, ": %s.\n",
6773 safe_strerror (val
));
6776 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
6777 target_terminal_ours_for_output ();
6778 error_stream(tmp_error_stream
);
6781 b
->loc
->inserted
= 1;
6785 free_command_lines (&bpt
->commands
);
6788 if (bpt
->cond_string
!= NULL
)
6789 xfree (bpt
->cond_string
);
6790 if (bpt
->addr_string
!= NULL
)
6791 xfree (bpt
->addr_string
);
6792 if (bpt
->exp
!= NULL
)
6794 if (bpt
->exp_string
!= NULL
)
6795 xfree (bpt
->exp_string
);
6796 if (bpt
->val
!= NULL
)
6797 value_free (bpt
->val
);
6798 if (bpt
->source_file
!= NULL
)
6799 xfree (bpt
->source_file
);
6800 if (bpt
->dll_pathname
!= NULL
)
6801 xfree (bpt
->dll_pathname
);
6802 if (bpt
->triggered_dll_pathname
!= NULL
)
6803 xfree (bpt
->triggered_dll_pathname
);
6804 if (bpt
->exec_pathname
!= NULL
)
6805 xfree (bpt
->exec_pathname
);
6807 /* Be sure no bpstat's are pointing at it after it's been freed. */
6808 /* FIXME, how can we find all bpstat's?
6809 We just check stop_bpstat for now. */
6810 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
6811 if (bs
->breakpoint_at
== bpt
)
6813 bs
->breakpoint_at
= NULL
;
6815 /* bs->commands will be freed later. */
6817 /* On the chance that someone will soon try again to delete this same
6818 bp, we mark it as deleted before freeing its storage. */
6819 bpt
->type
= bp_none
;
6826 do_delete_breakpoint_cleanup (void *b
)
6828 delete_breakpoint (b
);
6832 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
6834 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
6838 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
6840 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
6844 delete_command (char *arg
, int from_tty
)
6846 struct breakpoint
*b
, *temp
;
6852 int breaks_to_delete
= 0;
6854 /* Delete all breakpoints if no argument.
6855 Do not delete internal or call-dummy breakpoints, these
6856 have to be deleted with an explicit breakpoint number argument. */
6859 if (b
->type
!= bp_call_dummy
&&
6860 b
->type
!= bp_shlib_event
&&
6861 b
->type
!= bp_thread_event
&&
6862 b
->type
!= bp_overlay_event
&&
6864 breaks_to_delete
= 1;
6867 /* Ask user only if there are some breakpoints to delete. */
6869 || (breaks_to_delete
&& query ("Delete all breakpoints? ")))
6871 ALL_BREAKPOINTS_SAFE (b
, temp
)
6873 if (b
->type
!= bp_call_dummy
&&
6874 b
->type
!= bp_shlib_event
&&
6875 b
->type
!= bp_thread_event
&&
6876 b
->type
!= bp_overlay_event
&&
6878 delete_breakpoint (b
);
6883 map_breakpoint_numbers (arg
, delete_breakpoint
);
6886 /* Reset a breakpoint given it's struct breakpoint * BINT.
6887 The value we return ends up being the return value from catch_errors.
6888 Unused in this case. */
6891 breakpoint_re_set_one (void *bint
)
6893 /* get past catch_errs */
6894 struct breakpoint
*b
= (struct breakpoint
*) bint
;
6897 struct symtabs_and_lines sals
;
6899 enum enable_state save_enable
;
6904 warning ("attempted to reset apparently deleted breakpoint #%d?",
6908 case bp_hardware_breakpoint
:
6910 case bp_catch_unload
:
6911 if (b
->addr_string
== NULL
)
6913 /* Anything without a string can't be re-set. */
6914 delete_breakpoint (b
);
6917 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6919 ``And a hack it is, although Apple's Darwin version of GDB
6920 contains an almost identical hack to implement a "future
6921 break" command. It seems to work in many real world cases,
6922 but it is easy to come up with a test case where the patch
6923 doesn't help at all.''
6925 ``It seems that the way GDB implements breakpoints - in -
6926 shared - libraries was designed for a.out shared library
6927 systems (SunOS 4) where shared libraries were loaded at a
6928 fixed address in memory. Since ELF shared libraries can (and
6929 will) be loaded at any address in memory, things break.
6930 Fixing this is not trivial. Therefore, I'm not sure whether
6931 we should add this hack to the branch only. I cannot
6932 guarantee that things will be fixed on the trunk in the near
6935 In case we have a problem, disable this breakpoint. We'll
6936 restore its status if we succeed. Don't disable a
6937 shlib_disabled breakpoint though. There's a fair chance we
6938 can't re-set it if the shared library it's in hasn't been
6940 save_enable
= b
->enable_state
;
6941 if (b
->enable_state
!= bp_shlib_disabled
)
6942 b
->enable_state
= bp_disabled
;
6944 set_language (b
->language
);
6945 input_radix
= b
->input_radix
;
6947 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
);
6948 for (i
= 0; i
< sals
.nelts
; i
++)
6950 resolve_sal_pc (&sals
.sals
[i
]);
6952 /* Reparse conditions, they might contain references to the
6954 if (b
->cond_string
!= NULL
)
6959 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
6962 /* We need to re-set the breakpoint if the address changes... */
6963 if (b
->loc
->address
!= sals
.sals
[i
].pc
6964 /* ...or new and old breakpoints both have source files, and
6965 the source file name or the line number changes... */
6966 || (b
->source_file
!= NULL
6967 && sals
.sals
[i
].symtab
!= NULL
6968 && (!STREQ (b
->source_file
, sals
.sals
[i
].symtab
->filename
)
6969 || b
->line_number
!= sals
.sals
[i
].line
)
6971 /* ...or we switch between having a source file and not having
6973 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
6976 if (b
->source_file
!= NULL
)
6977 xfree (b
->source_file
);
6978 if (sals
.sals
[i
].symtab
== NULL
)
6979 b
->source_file
= NULL
;
6982 savestring (sals
.sals
[i
].symtab
->filename
,
6983 strlen (sals
.sals
[i
].symtab
->filename
));
6984 b
->line_number
= sals
.sals
[i
].line
;
6985 b
->loc
->requested_address
= sals
.sals
[i
].pc
;
6987 = adjust_breakpoint_address (b
->loc
->requested_address
);
6989 /* Used to check for duplicates here, but that can
6990 cause trouble, as it doesn't check for disabled
6995 /* Might be better to do this just once per breakpoint_re_set,
6996 rather than once for every breakpoint. */
6997 breakpoints_changed ();
6999 b
->section
= sals
.sals
[i
].section
;
7000 b
->enable_state
= save_enable
; /* Restore it, this worked. */
7003 /* Now that this is re-enabled, check_duplicates
7005 check_duplicates (b
);
7012 case bp_hardware_watchpoint
:
7013 case bp_read_watchpoint
:
7014 case bp_access_watchpoint
:
7015 innermost_block
= NULL
;
7016 /* The issue arises of what context to evaluate this in. The
7017 same one as when it was set, but what does that mean when
7018 symbols have been re-read? We could save the filename and
7019 functionname, but if the context is more local than that, the
7020 best we could do would be something like how many levels deep
7021 and which index at that particular level, but that's going to
7022 be less stable than filenames or function names. */
7024 /* So for now, just use a global context. */
7027 b
->exp
= parse_expression (b
->exp_string
);
7028 b
->exp_valid_block
= innermost_block
;
7029 mark
= value_mark ();
7031 value_free (b
->val
);
7032 b
->val
= evaluate_expression (b
->exp
);
7033 release_value (b
->val
);
7034 if (VALUE_LAZY (b
->val
) && b
->enable_state
== bp_enabled
)
7035 value_fetch_lazy (b
->val
);
7037 if (b
->cond_string
!= NULL
)
7042 b
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
7044 if (b
->enable_state
== bp_enabled
)
7046 value_free_to_mark (mark
);
7048 case bp_catch_catch
:
7049 case bp_catch_throw
:
7051 /* We needn't really do anything to reset these, since the mask
7052 that requests them is unaffected by e.g., new libraries being
7055 case bp_catch_vfork
:
7060 printf_filtered ("Deleting unknown breakpoint type %d\n", b
->type
);
7062 /* Delete longjmp and overlay event breakpoints; they will be
7063 reset later by breakpoint_re_set. */
7065 case bp_longjmp_resume
:
7066 case bp_overlay_event
:
7067 delete_breakpoint (b
);
7070 /* This breakpoint is special, it's set up when the inferior
7071 starts and we really don't want to touch it. */
7072 case bp_shlib_event
:
7074 /* Like bp_shlib_event, this breakpoint type is special.
7075 Once it is set up, we do not want to touch it. */
7076 case bp_thread_event
:
7078 /* Keep temporary breakpoints, which can be encountered when we step
7079 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7080 Otherwise these should have been blown away via the cleanup chain
7081 or by breakpoint_init_inferior when we rerun the executable. */
7084 case bp_watchpoint_scope
:
7086 case bp_step_resume
:
7093 /* Re-set all breakpoints after symbols have been re-loaded. */
7095 breakpoint_re_set (void)
7097 struct breakpoint
*b
, *temp
;
7098 enum language save_language
;
7099 int save_input_radix
;
7101 save_language
= current_language
->la_language
;
7102 save_input_radix
= input_radix
;
7103 ALL_BREAKPOINTS_SAFE (b
, temp
)
7105 /* Format possible error msg */
7106 char *message
= xstrprintf ("Error in re-setting breakpoint %d:\n",
7108 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7109 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7110 do_cleanups (cleanups
);
7112 set_language (save_language
);
7113 input_radix
= save_input_radix
;
7115 if (GET_LONGJMP_TARGET_P ())
7117 create_longjmp_breakpoint ("longjmp");
7118 create_longjmp_breakpoint ("_longjmp");
7119 create_longjmp_breakpoint ("siglongjmp");
7120 create_longjmp_breakpoint ("_siglongjmp");
7121 create_longjmp_breakpoint (NULL
);
7124 create_overlay_event_breakpoint ("_ovly_debug_event");
7127 /* Reset the thread number of this breakpoint:
7129 - If the breakpoint is for all threads, leave it as-is.
7130 - Else, reset it to the current thread for inferior_ptid. */
7132 breakpoint_re_set_thread (struct breakpoint
*b
)
7134 if (b
->thread
!= -1)
7136 if (in_thread_list (inferior_ptid
))
7137 b
->thread
= pid_to_thread_id (inferior_ptid
);
7141 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7142 If from_tty is nonzero, it prints a message to that effect,
7143 which ends with a period (no newline). */
7146 set_ignore_count (int bptnum
, int count
, int from_tty
)
7148 struct breakpoint
*b
;
7154 if (b
->number
== bptnum
)
7156 b
->ignore_count
= count
;
7160 printf_filtered ("Will stop next time breakpoint %d is reached.",
7162 else if (count
== 1)
7163 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7166 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7169 breakpoints_changed ();
7170 breakpoint_modify_event (b
->number
);
7174 error ("No breakpoint number %d.", bptnum
);
7177 /* Clear the ignore counts of all breakpoints. */
7179 breakpoint_clear_ignore_counts (void)
7181 struct breakpoint
*b
;
7184 b
->ignore_count
= 0;
7187 /* Command to set ignore-count of breakpoint N to COUNT. */
7190 ignore_command (char *args
, int from_tty
)
7196 error_no_arg ("a breakpoint number");
7198 num
= get_number (&p
);
7200 error ("bad breakpoint number: '%s'", args
);
7202 error ("Second argument (specified ignore-count) is missing.");
7204 set_ignore_count (num
,
7205 longest_to_int (value_as_long (parse_and_eval (p
))),
7208 printf_filtered ("\n");
7211 /* Call FUNCTION on each of the breakpoints
7212 whose numbers are given in ARGS. */
7215 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7220 struct breakpoint
*b
, *tmp
;
7224 error_no_arg ("one or more breakpoint numbers");
7231 num
= get_number_or_range (&p1
);
7234 warning ("bad breakpoint number at or near '%s'", p
);
7238 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7239 if (b
->number
== num
)
7241 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7244 if (related_breakpoint
)
7245 function (related_breakpoint
);
7249 printf_unfiltered ("No breakpoint number %d.\n", num
);
7255 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7256 If from_tty is nonzero, it prints a message to that effect,
7257 which ends with a period (no newline). */
7260 disable_breakpoint (struct breakpoint
*bpt
)
7262 /* Never disable a watchpoint scope breakpoint; we want to
7263 hit them when we leave scope so we can delete both the
7264 watchpoint and its scope breakpoint at that time. */
7265 if (bpt
->type
== bp_watchpoint_scope
)
7268 /* You can't disable permanent breakpoints. */
7269 if (bpt
->enable_state
== bp_permanent
)
7272 bpt
->enable_state
= bp_disabled
;
7274 check_duplicates (bpt
);
7276 if (modify_breakpoint_hook
)
7277 modify_breakpoint_hook (bpt
);
7278 breakpoint_modify_event (bpt
->number
);
7282 disable_command (char *args
, int from_tty
)
7284 struct breakpoint
*bpt
;
7286 ALL_BREAKPOINTS (bpt
)
7290 warning ("attempted to disable apparently deleted breakpoint #%d?",
7295 case bp_catch_unload
:
7297 case bp_catch_vfork
:
7299 case bp_catch_catch
:
7300 case bp_catch_throw
:
7301 case bp_hardware_breakpoint
:
7303 case bp_hardware_watchpoint
:
7304 case bp_read_watchpoint
:
7305 case bp_access_watchpoint
:
7306 disable_breakpoint (bpt
);
7311 map_breakpoint_numbers (args
, disable_breakpoint
);
7315 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7317 struct frame_info
*save_selected_frame
= NULL
;
7318 int save_selected_frame_level
= -1;
7319 int target_resources_ok
, other_type_used
;
7322 if (bpt
->type
== bp_hardware_breakpoint
)
7325 i
= hw_breakpoint_used_count ();
7326 target_resources_ok
=
7327 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7329 if (target_resources_ok
== 0)
7330 error ("No hardware breakpoint support in the target.");
7331 else if (target_resources_ok
< 0)
7332 error ("Hardware breakpoints used exceeds limit.");
7335 if (bpt
->enable_state
!= bp_permanent
)
7336 bpt
->enable_state
= bp_enabled
;
7337 bpt
->disposition
= disposition
;
7338 check_duplicates (bpt
);
7339 breakpoints_changed ();
7341 if (bpt
->type
== bp_watchpoint
||
7342 bpt
->type
== bp_hardware_watchpoint
||
7343 bpt
->type
== bp_read_watchpoint
||
7344 bpt
->type
== bp_access_watchpoint
)
7346 if (bpt
->exp_valid_block
!= NULL
)
7348 struct frame_info
*fr
=
7349 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7353 Cannot enable watchpoint %d because the block in which its expression\n\
7354 is valid is not currently in scope.\n", bpt
->number
);
7355 bpt
->enable_state
= bp_disabled
;
7359 save_selected_frame
= deprecated_selected_frame
;
7360 save_selected_frame_level
= frame_relative_level (deprecated_selected_frame
);
7364 value_free (bpt
->val
);
7365 mark
= value_mark ();
7366 bpt
->val
= evaluate_expression (bpt
->exp
);
7367 release_value (bpt
->val
);
7368 if (VALUE_LAZY (bpt
->val
))
7369 value_fetch_lazy (bpt
->val
);
7371 if (bpt
->type
== bp_hardware_watchpoint
||
7372 bpt
->type
== bp_read_watchpoint
||
7373 bpt
->type
== bp_access_watchpoint
)
7375 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7376 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7378 /* Hack around 'unused var' error for some targets here */
7380 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7381 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7382 /* we can consider of type is bp_hardware_watchpoint, convert to
7383 bp_watchpoint in the following condition */
7384 if (target_resources_ok
< 0)
7387 Cannot enable watchpoint %d because target watch resources\n\
7388 have been allocated for other watchpoints.\n", bpt
->number
);
7389 bpt
->enable_state
= bp_disabled
;
7390 value_free_to_mark (mark
);
7395 if (save_selected_frame_level
>= 0)
7396 select_frame (save_selected_frame
);
7397 value_free_to_mark (mark
);
7399 if (modify_breakpoint_hook
)
7400 modify_breakpoint_hook (bpt
);
7401 breakpoint_modify_event (bpt
->number
);
7405 enable_breakpoint (struct breakpoint
*bpt
)
7407 do_enable_breakpoint (bpt
, bpt
->disposition
);
7410 /* The enable command enables the specified breakpoints (or all defined
7411 breakpoints) so they once again become (or continue to be) effective
7412 in stopping the inferior. */
7415 enable_command (char *args
, int from_tty
)
7417 struct breakpoint
*bpt
;
7419 ALL_BREAKPOINTS (bpt
)
7423 warning ("attempted to enable apparently deleted breakpoint #%d?",
7428 case bp_catch_unload
:
7430 case bp_catch_vfork
:
7432 case bp_catch_catch
:
7433 case bp_catch_throw
:
7434 case bp_hardware_breakpoint
:
7436 case bp_hardware_watchpoint
:
7437 case bp_read_watchpoint
:
7438 case bp_access_watchpoint
:
7439 enable_breakpoint (bpt
);
7444 map_breakpoint_numbers (args
, enable_breakpoint
);
7448 enable_once_breakpoint (struct breakpoint
*bpt
)
7450 do_enable_breakpoint (bpt
, disp_disable
);
7454 enable_once_command (char *args
, int from_tty
)
7456 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7460 enable_delete_breakpoint (struct breakpoint
*bpt
)
7462 do_enable_breakpoint (bpt
, disp_del
);
7466 enable_delete_command (char *args
, int from_tty
)
7468 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7471 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7473 struct symtabs_and_lines
7474 decode_line_spec_1 (char *string
, int funfirstline
)
7476 struct symtabs_and_lines sals
;
7478 error ("Empty line specification.");
7479 if (default_breakpoint_valid
)
7480 sals
= decode_line_1 (&string
, funfirstline
,
7481 default_breakpoint_symtab
,
7482 default_breakpoint_line
,
7485 sals
= decode_line_1 (&string
, funfirstline
,
7486 (struct symtab
*) NULL
, 0, (char ***) NULL
);
7488 error ("Junk at end of line specification: %s", string
);
7493 _initialize_breakpoint (void)
7495 struct cmd_list_element
*c
;
7497 breakpoint_chain
= 0;
7498 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7499 before a breakpoint is set. */
7500 breakpoint_count
= 0;
7502 add_com ("ignore", class_breakpoint
, ignore_command
,
7503 "Set ignore-count of breakpoint number N to COUNT.\n\
7504 Usage is `ignore N COUNT'.");
7506 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7508 add_com ("commands", class_breakpoint
, commands_command
,
7509 "Set commands to be executed when a breakpoint is hit.\n\
7510 Give breakpoint number as argument after \"commands\".\n\
7511 With no argument, the targeted breakpoint is the last one set.\n\
7512 The commands themselves follow starting on the next line.\n\
7513 Type a line containing \"end\" to indicate the end of them.\n\
7514 Give \"silent\" as the first line to make the breakpoint silent;\n\
7515 then no output is printed when it is hit, except what the commands print.");
7517 add_com ("condition", class_breakpoint
, condition_command
,
7518 "Specify breakpoint number N to break only if COND is true.\n\
7519 Usage is `condition N COND', where N is an integer and COND is an\n\
7520 expression to be evaluated whenever breakpoint N is reached.");
7522 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
,
7523 "Set a temporary breakpoint. Args like \"break\" command.\n\
7524 Like \"break\" except the breakpoint is only temporary,\n\
7525 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7526 by using \"enable delete\" on the breakpoint number.");
7527 set_cmd_completer (c
, location_completer
);
7529 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
,
7530 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7531 Like \"break\" except the breakpoint requires hardware support,\n\
7532 some target hardware may not have this support.");
7533 set_cmd_completer (c
, location_completer
);
7535 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
,
7536 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7537 Like \"hbreak\" except the breakpoint is only temporary,\n\
7538 so it will be deleted when hit.");
7539 set_cmd_completer (c
, location_completer
);
7541 add_prefix_cmd ("enable", class_breakpoint
, enable_command
,
7542 "Enable some breakpoints.\n\
7543 Give breakpoint numbers (separated by spaces) as arguments.\n\
7544 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7545 This is used to cancel the effect of the \"disable\" command.\n\
7546 With a subcommand you can enable temporarily.",
7547 &enablelist
, "enable ", 1, &cmdlist
);
7549 add_com ("ab", class_breakpoint
, enable_command
,
7550 "Enable some breakpoints.\n\
7551 Give breakpoint numbers (separated by spaces) as arguments.\n\
7552 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7553 This is used to cancel the effect of the \"disable\" command.\n\
7554 With a subcommand you can enable temporarily.");
7556 add_com_alias ("en", "enable", class_breakpoint
, 1);
7558 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
,
7559 "Enable some breakpoints.\n\
7560 Give breakpoint numbers (separated by spaces) as arguments.\n\
7561 This is used to cancel the effect of the \"disable\" command.\n\
7562 May be abbreviated to simply \"enable\".\n",
7563 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
7565 add_cmd ("once", no_class
, enable_once_command
,
7566 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7567 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7570 add_cmd ("delete", no_class
, enable_delete_command
,
7571 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7572 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7575 add_cmd ("delete", no_class
, enable_delete_command
,
7576 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7577 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7580 add_cmd ("once", no_class
, enable_once_command
,
7581 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7582 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7585 add_prefix_cmd ("disable", class_breakpoint
, disable_command
,
7586 "Disable some breakpoints.\n\
7587 Arguments are breakpoint numbers with spaces in between.\n\
7588 To disable all breakpoints, give no argument.\n\
7589 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7590 &disablelist
, "disable ", 1, &cmdlist
);
7591 add_com_alias ("dis", "disable", class_breakpoint
, 1);
7592 add_com_alias ("disa", "disable", class_breakpoint
, 1);
7594 add_com ("sb", class_breakpoint
, disable_command
,
7595 "Disable some breakpoints.\n\
7596 Arguments are breakpoint numbers with spaces in between.\n\
7597 To disable all breakpoints, give no argument.\n\
7598 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7600 add_cmd ("breakpoints", class_alias
, disable_command
,
7601 "Disable some breakpoints.\n\
7602 Arguments are breakpoint numbers with spaces in between.\n\
7603 To disable all breakpoints, give no argument.\n\
7604 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7605 This command may be abbreviated \"disable\".",
7608 add_prefix_cmd ("delete", class_breakpoint
, delete_command
,
7609 "Delete some breakpoints or auto-display expressions.\n\
7610 Arguments are breakpoint numbers with spaces in between.\n\
7611 To delete all breakpoints, give no argument.\n\
7613 Also a prefix command for deletion of other GDB objects.\n\
7614 The \"unset\" command is also an alias for \"delete\".",
7615 &deletelist
, "delete ", 1, &cmdlist
);
7616 add_com_alias ("d", "delete", class_breakpoint
, 1);
7618 add_com ("db", class_breakpoint
, delete_command
,
7619 "Delete some breakpoints.\n\
7620 Arguments are breakpoint numbers with spaces in between.\n\
7621 To delete all breakpoints, give no argument.\n");
7623 add_cmd ("breakpoints", class_alias
, delete_command
,
7624 "Delete some breakpoints or auto-display expressions.\n\
7625 Arguments are breakpoint numbers with spaces in between.\n\
7626 To delete all breakpoints, give no argument.\n\
7627 This command may be abbreviated \"delete\".",
7630 add_com ("clear", class_breakpoint
, clear_command
,
7631 concat ("Clear breakpoint at specified line or function.\n\
7632 Argument may be line number, function name, or \"*\" and an address.\n\
7633 If line number is specified, all breakpoints in that line are cleared.\n\
7634 If function is specified, breakpoints at beginning of function are cleared.\n\
7635 If an address is specified, breakpoints at that address are cleared.\n\n",
7636 "With no argument, clears all breakpoints in the line that the selected frame\n\
7639 See also the \"delete\" command which clears breakpoints by number.", NULL
));
7641 c
= add_com ("break", class_breakpoint
, break_command
,
7642 concat ("Set breakpoint at specified line or function.\n\
7643 Argument may be line number, function name, or \"*\" and an address.\n\
7644 If line number is specified, break at start of code for that line.\n\
7645 If function is specified, break at start of code for that function.\n\
7646 If an address is specified, break at that exact address.\n",
7647 "With no arg, uses current execution address of selected stack frame.\n\
7648 This is useful for breaking on return to a stack frame.\n\
7650 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7652 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL
));
7653 set_cmd_completer (c
, location_completer
);
7655 add_com_alias ("b", "break", class_run
, 1);
7656 add_com_alias ("br", "break", class_run
, 1);
7657 add_com_alias ("bre", "break", class_run
, 1);
7658 add_com_alias ("brea", "break", class_run
, 1);
7662 add_com_alias ("ba", "break", class_breakpoint
, 1);
7663 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
7668 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
,
7669 "Break in function/address or break at a line in the current file.",
7670 &stoplist
, "stop ", 1, &cmdlist
);
7671 add_cmd ("in", class_breakpoint
, stopin_command
,
7672 "Break in function or address.\n", &stoplist
);
7673 add_cmd ("at", class_breakpoint
, stopat_command
,
7674 "Break at a line in the current file.\n", &stoplist
);
7675 add_com ("status", class_info
, breakpoints_info
,
7676 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7677 The \"Type\" column indicates one of:\n\
7678 \tbreakpoint - normal breakpoint\n\
7679 \twatchpoint - watchpoint\n\
7680 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7681 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7682 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7683 address and file/line number respectively.\n\n",
7684 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7685 are set to the address of the last breakpoint listed.\n\n\
7686 Convenience variable \"$bpnum\" contains the number of the last\n\
7687 breakpoint set.", NULL
));
7690 add_info ("breakpoints", breakpoints_info
,
7691 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7692 The \"Type\" column indicates one of:\n\
7693 \tbreakpoint - normal breakpoint\n\
7694 \twatchpoint - watchpoint\n\
7695 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7696 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7697 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7698 address and file/line number respectively.\n\n",
7699 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7700 are set to the address of the last breakpoint listed.\n\n\
7701 Convenience variable \"$bpnum\" contains the number of the last\n\
7702 breakpoint set.", NULL
));
7705 add_com ("lb", class_breakpoint
, breakpoints_info
,
7706 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7707 The \"Type\" column indicates one of:\n\
7708 \tbreakpoint - normal breakpoint\n\
7709 \twatchpoint - watchpoint\n\
7710 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7711 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7712 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7713 address and file/line number respectively.\n\n",
7714 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7715 are set to the address of the last breakpoint listed.\n\n\
7716 Convenience variable \"$bpnum\" contains the number of the last\n\
7717 breakpoint set.", NULL
));
7719 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
,
7720 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7721 The \"Type\" column indicates one of:\n\
7722 \tbreakpoint - normal breakpoint\n\
7723 \twatchpoint - watchpoint\n\
7724 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7725 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7726 \tuntil - internal breakpoint used by the \"until\" command\n\
7727 \tfinish - internal breakpoint used by the \"finish\" command\n",
7728 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7729 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7730 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7731 address and file/line number respectively.\n\n",
7732 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7733 are set to the address of the last breakpoint listed.\n\n\
7734 Convenience variable \"$bpnum\" contains the number of the last\n\
7735 breakpoint set.", NULL
),
7736 &maintenanceinfolist
);
7738 add_com ("catch", class_breakpoint
, catch_command
,
7739 "Set catchpoints to catch events.\n\
7740 Raised signals may be caught:\n\
7741 \tcatch signal - all signals\n\
7742 \tcatch signal <signame> - a particular signal\n\
7743 Raised exceptions may be caught:\n\
7744 \tcatch throw - all exceptions, when thrown\n\
7745 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7746 \tcatch catch - all exceptions, when caught\n\
7747 \tcatch catch <exceptname> - a particular exception, when caught\n\
7748 Thread or process events may be caught:\n\
7749 \tcatch thread_start - any threads, just after creation\n\
7750 \tcatch thread_exit - any threads, just before expiration\n\
7751 \tcatch thread_join - any threads, just after joins\n\
7752 Process events may be caught:\n\
7753 \tcatch start - any processes, just after creation\n\
7754 \tcatch exit - any processes, just before expiration\n\
7755 \tcatch fork - calls to fork()\n\
7756 \tcatch vfork - calls to vfork()\n\
7757 \tcatch exec - calls to exec()\n\
7758 Dynamically-linked library events may be caught:\n\
7759 \tcatch load - loads of any library\n\
7760 \tcatch load <libname> - loads of a particular library\n\
7761 \tcatch unload - unloads of any library\n\
7762 \tcatch unload <libname> - unloads of a particular library\n\
7763 The act of your program's execution stopping may also be caught:\n\
7765 C++ exceptions may be caught:\n\
7766 \tcatch throw - all exceptions, when thrown\n\
7767 \tcatch catch - all exceptions, when caught\n\
7769 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7770 after a fork or vfork is caught.\n\n\
7771 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7773 add_com ("tcatch", class_breakpoint
, tcatch_command
,
7774 "Set temporary catchpoints to catch events.\n\
7775 Args like \"catch\" command.\n\
7776 Like \"catch\" except the catchpoint is only temporary,\n\
7777 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7778 by using \"enable delete\" on the catchpoint number.");
7780 c
= add_com ("watch", class_breakpoint
, watch_command
,
7781 "Set a watchpoint for an expression.\n\
7782 A watchpoint stops execution of your program whenever the value of\n\
7783 an expression changes.");
7784 set_cmd_completer (c
, location_completer
);
7786 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
7787 "Set a read watchpoint for an expression.\n\
7788 A watchpoint stops execution of your program whenever the value of\n\
7789 an expression is read.");
7790 set_cmd_completer (c
, location_completer
);
7792 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
7793 "Set a watchpoint for an expression.\n\
7794 A watchpoint stops execution of your program whenever the value of\n\
7795 an expression is either read or written.");
7796 set_cmd_completer (c
, location_completer
);
7798 add_info ("watchpoints", breakpoints_info
,
7799 "Synonym for ``info breakpoints''.");
7802 c
= add_set_cmd ("can-use-hw-watchpoints", class_support
, var_zinteger
,
7803 (char *) &can_use_hw_watchpoints
,
7804 "Set debugger's willingness to use watchpoint hardware.\n\
7805 If zero, gdb will not use hardware for new watchpoints, even if\n\
7806 such is available. (However, any hardware watchpoints that were\n\
7807 created before setting this to nonzero, will continue to use watchpoint\n\
7810 add_show_from_set (c
, &showlist
);
7812 can_use_hw_watchpoints
= 1;