1 /* Everything about breakpoints, for GDB.
2 Copyright 1986, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #include "breakpoint.h"
27 #include "expression.h"
33 #include "gdbthread.h"
36 #include "gdb_string.h"
42 /* Prototypes for local functions. */
44 static void catch_command_1
PARAMS ((char *, int, int));
46 static void enable_delete_command
PARAMS ((char *, int));
48 static void enable_delete_breakpoint
PARAMS ((struct breakpoint
*));
50 static void enable_once_command
PARAMS ((char *, int));
52 static void enable_once_breakpoint
PARAMS ((struct breakpoint
*));
54 static void disable_command
PARAMS ((char *, int));
56 static void enable_command
PARAMS ((char *, int));
58 static void map_breakpoint_numbers
PARAMS ((char *,
59 void (*)(struct breakpoint
*)));
61 static void ignore_command
PARAMS ((char *, int));
63 static int breakpoint_re_set_one
PARAMS ((char *));
65 static void clear_command
PARAMS ((char *, int));
67 static void catch_command
PARAMS ((char *, int));
69 static struct symtabs_and_lines get_catch_sals
PARAMS ((int));
71 static void watch_command
PARAMS ((char *, int));
73 static int can_use_hardware_watchpoint
PARAMS ((struct value
*));
75 static void tbreak_command
PARAMS ((char *, int));
77 static void break_command_1
PARAMS ((char *, int, int));
79 static void mention
PARAMS ((struct breakpoint
*));
81 struct breakpoint
*set_raw_breakpoint
PARAMS ((struct symtab_and_line
));
83 static void check_duplicates
PARAMS ((CORE_ADDR
, asection
*));
85 static void describe_other_breakpoints
PARAMS ((CORE_ADDR
, asection
*));
87 static void breakpoints_info
PARAMS ((char *, int));
89 static void breakpoint_1
PARAMS ((int, int));
91 static bpstat bpstat_alloc
PARAMS ((struct breakpoint
*, bpstat
));
93 static int breakpoint_cond_eval
PARAMS ((char *));
95 static void cleanup_executing_breakpoints
PARAMS ((PTR
));
97 static void commands_command
PARAMS ((char *, int));
99 static void condition_command
PARAMS ((char *, int));
101 static int get_number
PARAMS ((char **));
103 static int remove_breakpoint
PARAMS ((struct breakpoint
*));
105 static int print_it_normal
PARAMS ((bpstat
));
107 static int watchpoint_check
PARAMS ((char *));
109 static int print_it_done
PARAMS ((bpstat
));
111 static int print_it_noop
PARAMS ((bpstat
));
113 static void maintenance_info_breakpoints
PARAMS ((char *, int));
115 #ifdef GET_LONGJMP_TARGET
116 static void create_longjmp_breakpoint
PARAMS ((char *));
119 static int hw_breakpoint_used_count
PARAMS ((void));
121 static int hw_watchpoint_used_count
PARAMS ((enum bptype
, int *));
123 static void hbreak_command
PARAMS ((char *, int));
125 static void thbreak_command
PARAMS ((char *, int));
127 static void watch_command_1
PARAMS ((char *, int, int));
129 static void rwatch_command
PARAMS ((char *, int));
131 static void awatch_command
PARAMS ((char *, int));
133 static void do_enable_breakpoint
PARAMS ((struct breakpoint
*, enum bpdisp
));
135 /* Prototypes for exported functions. */
137 void delete_command
PARAMS ((char *, int));
139 void _initialize_breakpoint
PARAMS ((void));
141 void set_breakpoint_count
PARAMS ((int));
143 extern int addressprint
; /* Print machine addresses? */
145 #if defined (GET_LONGJMP_TARGET) || defined (SOLIB_ADD)
146 static int internal_breakpoint_number
= -1;
149 /* Are we executing breakpoint commands? */
150 static int executing_breakpoint_commands
;
152 /* Walk the following statement or block through all breakpoints.
153 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
156 #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
158 #define ALL_BREAKPOINTS_SAFE(b,tmp) \
159 for (b = breakpoint_chain; \
160 b? (tmp=b->next, 1): 0; \
163 /* True if SHIFT_INST_REGS defined, false otherwise. */
165 int must_shift_inst_regs
=
166 #if defined(SHIFT_INST_REGS)
173 /* True if breakpoint hit counts should be displayed in breakpoint info. */
175 int show_breakpoint_hit_counts
= 1;
177 /* Chain of all breakpoints defined. */
179 struct breakpoint
*breakpoint_chain
;
181 /* Number of last breakpoint made. */
183 int breakpoint_count
;
185 /* Set breakpoint count to NUM. */
188 set_breakpoint_count (num
)
191 breakpoint_count
= num
;
192 set_internalvar (lookup_internalvar ("bpnum"),
193 value_from_longest (builtin_type_int
, (LONGEST
) num
));
196 /* Used in run_command to zero the hit count when a new run starts. */
199 clear_breakpoint_hit_counts ()
201 struct breakpoint
*b
;
207 /* Default address, symtab and line to put a breakpoint at
208 for "break" command with no arg.
209 if default_breakpoint_valid is zero, the other three are
210 not valid, and "break" with no arg is an error.
212 This set by print_stack_frame, which calls set_default_breakpoint. */
214 int default_breakpoint_valid
;
215 CORE_ADDR default_breakpoint_address
;
216 struct symtab
*default_breakpoint_symtab
;
217 int default_breakpoint_line
;
219 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
220 Advance *PP after the string and any trailing whitespace.
222 Currently the string can either be a number or "$" followed by the name
223 of a convenience variable. Making it an expression wouldn't work well
224 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
233 /* Empty line means refer to the last breakpoint. */
234 return breakpoint_count
;
237 /* Make a copy of the name, so we can null-terminate it
238 to pass to lookup_internalvar(). */
243 while (isalnum (*p
) || *p
== '_')
245 varname
= (char *) alloca (p
- start
+ 1);
246 strncpy (varname
, start
, p
- start
);
247 varname
[p
- start
] = '\0';
248 val
= value_of_internalvar (lookup_internalvar (varname
));
249 if (TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_INT
)
251 "Convenience variables used to specify breakpoints must have integer values."
253 retval
= (int) value_as_long (val
);
259 while (*p
>= '0' && *p
<= '9')
262 /* There is no number here. (e.g. "cond a == b"). */
263 error_no_arg ("breakpoint number");
266 if (!(isspace (*p
) || *p
== '\0'))
267 error ("breakpoint number expected");
274 /* condition N EXP -- set break condition of breakpoint N to EXP. */
277 condition_command (arg
, from_tty
)
281 register struct breakpoint
*b
;
286 error_no_arg ("breakpoint number");
289 bnum
= get_number (&p
);
292 if (b
->number
== bnum
)
299 if (b
->cond_string
!= NULL
)
300 free ((PTR
)b
->cond_string
);
305 b
->cond_string
= NULL
;
307 printf_filtered ("Breakpoint %d now unconditional.\n", bnum
);
312 /* I don't know if it matters whether this is the string the user
313 typed in or the decompiled expression. */
314 b
->cond_string
= savestring (arg
, strlen (arg
));
315 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->address
), 0);
317 error ("Junk at end of expression");
319 breakpoints_changed ();
323 error ("No breakpoint number %d.", bnum
);
328 commands_command (arg
, from_tty
)
332 register struct breakpoint
*b
;
335 struct command_line
*l
;
337 /* If we allowed this, we would have problems with when to
338 free the storage, if we change the commands currently
341 if (executing_breakpoint_commands
)
342 error ("Can't use the \"commands\" command among a breakpoint's commands.");
345 bnum
= get_number (&p
);
347 error ("Unexpected extra arguments following breakpoint number.");
350 if (b
->number
== bnum
)
353 sprintf (tmpbuf
, "Type commands for when breakpoint %d is hit, one per line.", bnum
);
354 l
= read_command_lines (tmpbuf
, from_tty
);
355 free_command_lines (&b
->commands
);
357 breakpoints_changed ();
360 error ("No breakpoint number %d.", bnum
);
363 extern int memory_breakpoint_size
; /* from mem-break.c */
365 /* Like target_read_memory() but if breakpoints are inserted, return
366 the shadow contents instead of the breakpoints themselves.
368 Read "memory data" from whatever target or inferior we have.
369 Returns zero if successful, errno value if not. EIO is used
370 for address out of bounds. If breakpoints are inserted, returns
371 shadow contents, not the breakpoints themselves. From breakpoint.c. */
374 read_memory_nobpt (memaddr
, myaddr
, len
)
380 struct breakpoint
*b
;
382 if (memory_breakpoint_size
< 0)
383 /* No breakpoints on this machine. FIXME: This should be
384 dependent on the debugging target. Probably want
385 target_insert_breakpoint to return a size, saying how many
386 bytes of the shadow contents are used, or perhaps have
387 something like target_xfer_shadow. */
388 return target_read_memory (memaddr
, myaddr
, len
);
392 if (b
->type
== bp_watchpoint
393 || b
->type
== bp_hardware_watchpoint
394 || b
->type
== bp_read_watchpoint
395 || b
->type
== bp_access_watchpoint
398 else if (b
->address
+ memory_breakpoint_size
<= memaddr
)
399 /* The breakpoint is entirely before the chunk of memory
402 else if (b
->address
>= memaddr
+ len
)
403 /* The breakpoint is entirely after the chunk of memory we
408 /* Copy the breakpoint from the shadow contents, and recurse
409 for the things before and after. */
411 /* Addresses and length of the part of the breakpoint that
413 CORE_ADDR membpt
= b
->address
;
414 unsigned int bptlen
= memory_breakpoint_size
;
415 /* Offset within shadow_contents. */
418 if (membpt
< memaddr
)
420 /* Only copy the second part of the breakpoint. */
421 bptlen
-= memaddr
- membpt
;
422 bptoffset
= memaddr
- membpt
;
426 if (membpt
+ bptlen
> memaddr
+ len
)
428 /* Only copy the first part of the breakpoint. */
429 bptlen
-= (membpt
+ bptlen
) - (memaddr
+ len
);
432 memcpy (myaddr
+ membpt
- memaddr
,
433 b
->shadow_contents
+ bptoffset
, bptlen
);
435 if (membpt
> memaddr
)
437 /* Copy the section of memory before the breakpoint. */
438 status
= read_memory_nobpt (memaddr
, myaddr
, membpt
- memaddr
);
443 if (membpt
+ bptlen
< memaddr
+ len
)
445 /* Copy the section of memory after the breakpoint. */
446 status
= read_memory_nobpt
448 myaddr
+ membpt
+ bptlen
- memaddr
,
449 memaddr
+ len
- (membpt
+ bptlen
));
456 /* Nothing overlaps. Just call read_memory_noerr. */
457 return target_read_memory (memaddr
, myaddr
, len
);
460 /* insert_breakpoints is used when starting or continuing the program.
461 remove_breakpoints is used when the program stops.
462 Both return zero if successful,
463 or an `errno' value if could not write the inferior. */
466 insert_breakpoints ()
468 register struct breakpoint
*b
, *temp
;
470 int disabled_breaks
= 0;
472 ALL_BREAKPOINTS_SAFE (b
, temp
)
473 if (b
->type
!= bp_watchpoint
474 && b
->type
!= bp_hardware_watchpoint
475 && b
->type
!= bp_read_watchpoint
476 && b
->type
!= bp_access_watchpoint
477 && b
->enable
!= disabled
478 && b
->enable
!= shlib_disabled
482 if (b
->type
== bp_hardware_breakpoint
)
483 val
= target_insert_hw_breakpoint(b
->address
, b
->shadow_contents
);
486 /* Check to see if breakpoint is in an overlay section;
487 if so, we should set the breakpoint at the LMA address.
488 Only if the section is currently mapped should we ALSO
489 set a break at the VMA address. */
490 if (overlay_debugging
&& b
->section
&&
491 section_is_overlay (b
->section
))
495 addr
= overlay_unmapped_address (b
->address
, b
->section
);
496 val
= target_insert_breakpoint (addr
, b
->shadow_contents
);
497 /* This would be the time to check val, to see if the
498 breakpoint write to the load address succeeded.
499 However, this might be an ordinary occurrance, eg. if
500 the unmapped overlay is in ROM. */
501 val
= 0; /* in case unmapped address failed */
502 if (section_is_mapped (b
->section
))
503 val
= target_insert_breakpoint (b
->address
,
506 else /* ordinary (non-overlay) address */
507 val
= target_insert_breakpoint(b
->address
, b
->shadow_contents
);
511 /* Can't set the breakpoint. */
512 #if defined (DISABLE_UNSETTABLE_BREAK)
513 if (DISABLE_UNSETTABLE_BREAK (b
->address
))
516 b
->enable
= shlib_disabled
;
517 if (!disabled_breaks
)
519 target_terminal_ours_for_output ();
520 fprintf_unfiltered (gdb_stderr
,
521 "Cannot insert breakpoint %d:\n", b
->number
);
522 printf_filtered ("Temporarily disabling shared library breakpoints:\n");
525 printf_filtered ("%d ", b
->number
);
530 target_terminal_ours_for_output ();
531 fprintf_unfiltered (gdb_stderr
, "Cannot insert breakpoint %d:\n", b
->number
);
532 #ifdef ONE_PROCESS_WRITETEXT
533 fprintf_unfiltered (gdb_stderr
,
534 "The same program may be running in another process.\n");
536 memory_error (val
, b
->address
); /* which bombs us out */
542 else if ((b
->type
== bp_hardware_watchpoint
||
543 b
->type
== bp_read_watchpoint
||
544 b
->type
== bp_access_watchpoint
)
545 && b
->enable
== enabled
549 struct frame_info
*saved_frame
;
550 int saved_level
, within_current_scope
;
551 value_ptr mark
= value_mark ();
554 /* Save the current frame and level so we can restore it after
555 evaluating the watchpoint expression on its own frame. */
556 saved_frame
= selected_frame
;
557 saved_level
= selected_frame_level
;
559 /* Determine if the watchpoint is within scope. */
560 if (b
->exp_valid_block
== NULL
)
561 within_current_scope
= 1;
564 struct frame_info
*fi
;
566 /* There might be no current frame at this moment if we are
567 resuming from a step over a breakpoint.
568 Set up current frame before trying to find the watchpoint
570 get_current_frame ();
571 fi
= find_frame_addr_in_frame_chain (b
->watchpoint_frame
);
572 within_current_scope
= (fi
!= NULL
);
573 if (within_current_scope
)
574 select_frame (fi
, -1);
577 if (within_current_scope
)
579 /* Evaluate the expression and cut the chain of values
580 produced off from the value chain. */
581 v
= evaluate_expression (b
->exp
);
582 value_release_to_mark (mark
);
587 /* Look at each value on the value chain. */
588 for ( ; v
; v
=v
->next
)
590 /* If it's a memory location, then we must watch it. */
591 if (v
->lval
== lval_memory
)
595 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
596 len
= TYPE_LENGTH (VALUE_TYPE (v
));
598 if (b
->type
== bp_read_watchpoint
)
600 else if (b
->type
== bp_access_watchpoint
)
603 val
= target_insert_watchpoint (addr
, len
, type
);
612 /* Failure to insert a watchpoint on any memory value in the
613 value chain brings us here. */
615 warning ("Hardware watchpoint %d: Could not insert watchpoint\n",
621 Hardware watchpoint %d deleted because the program has left the block in\n\
622 which its expression is valid.\n", b
->number
);
623 if (b
->related_breakpoint
)
624 b
->related_breakpoint
->disposition
= del_at_next_stop
;
625 b
->disposition
= del_at_next_stop
;
628 /* Restore the frame and level. */
629 select_frame (saved_frame
, saved_level
);
632 printf_filtered ("\n");
638 remove_breakpoints ()
640 register struct breakpoint
*b
;
647 val
= remove_breakpoint (b
);
657 remove_breakpoint (b
)
658 struct breakpoint
*b
;
662 if (b
->type
!= bp_watchpoint
663 && b
->type
!= bp_hardware_watchpoint
664 && b
->type
!= bp_read_watchpoint
665 && b
->type
!= bp_access_watchpoint
)
667 if (b
->type
== bp_hardware_breakpoint
)
668 val
= target_remove_hw_breakpoint(b
->address
, b
->shadow_contents
);
671 /* Check to see if breakpoint is in an overlay section;
672 if so, we should remove the breakpoint at the LMA address.
673 If that is not equal to the raw address, then we should
674 presumable remove the breakpoint there as well. */
675 if (overlay_debugging
&& b
->section
&&
676 section_is_overlay (b
->section
))
680 addr
= overlay_unmapped_address (b
->address
, b
->section
);
681 val
= target_remove_breakpoint (addr
, b
->shadow_contents
);
682 /* This would be the time to check val, to see if the
683 shadow breakpoint write to the load address succeeded.
684 However, this might be an ordinary occurrance, eg. if
685 the unmapped overlay is in ROM. */
686 val
= 0; /* in case unmapped address failed */
687 if (section_is_mapped (b
->section
))
688 val
= target_remove_breakpoint (b
->address
,
691 else /* ordinary (non-overlay) address */
692 val
= target_remove_breakpoint(b
->address
, b
->shadow_contents
);
698 else if ((b
->type
== bp_hardware_watchpoint
||
699 b
->type
== bp_read_watchpoint
||
700 b
->type
== bp_access_watchpoint
)
701 && b
->enable
== enabled
707 /* Walk down the saved value chain. */
708 for (v
= b
->val_chain
; v
; v
= v
->next
)
710 /* For each memory reference remove the watchpoint
712 if (v
->lval
== lval_memory
)
716 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
717 len
= TYPE_LENGTH (VALUE_TYPE (v
));
719 if (b
->type
== bp_read_watchpoint
)
721 else if (b
->type
== bp_access_watchpoint
)
724 val
= target_remove_watchpoint (addr
, len
, type
);
730 /* Failure to remove any of the hardware watchpoints comes here. */
732 warning ("Hardware watchpoint %d: Could not remove watchpoint\n",
735 /* Free the saved value chain. We will construct a new one
736 the next time the watchpoint is inserted. */
737 for (v
= b
->val_chain
; v
; v
= n
)
747 /* Clear the "inserted" flag in all breakpoints. */
750 mark_breakpoints_out ()
752 register struct breakpoint
*b
;
758 /* Clear the "inserted" flag in all breakpoints and delete any breakpoints
759 which should go away between runs of the program. */
762 breakpoint_init_inferior ()
764 register struct breakpoint
*b
, *temp
;
766 ALL_BREAKPOINTS_SAFE (b
, temp
)
773 case bp_watchpoint_scope
:
775 /* If the call dummy breakpoint is at the entry point it will
776 cause problems when the inferior is rerun, so we better
779 Also get rid of scope breakpoints. */
780 delete_breakpoint (b
);
784 case bp_hardware_watchpoint
:
785 case bp_read_watchpoint
:
786 case bp_access_watchpoint
:
788 /* Likewise for watchpoints on local expressions. */
789 if (b
->exp_valid_block
!= NULL
)
790 delete_breakpoint (b
);
799 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
800 When continuing from a location with a breakpoint,
801 we actually single step once before calling insert_breakpoints. */
804 breakpoint_here_p (pc
)
807 register struct breakpoint
*b
;
810 if (b
->enable
== enabled
811 && b
->address
== pc
) /* bp is enabled and matches pc */
813 if (overlay_debugging
&&
814 section_is_overlay (b
->section
) &&
815 !section_is_mapped (b
->section
))
816 continue; /* unmapped overlay -- can't be a match */
824 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(), but it
825 only returns true if there is actually a breakpoint inserted at PC. */
828 breakpoint_inserted_here_p (pc
)
831 register struct breakpoint
*b
;
835 && b
->address
== pc
) /* bp is inserted and matches pc */
837 if (overlay_debugging
&&
838 section_is_overlay (b
->section
) &&
839 !section_is_mapped (b
->section
))
840 continue; /* unmapped overlay -- can't be a match */
848 /* Return nonzero if FRAME is a dummy frame. We can't use PC_IN_CALL_DUMMY
849 because figuring out the saved SP would take too much time, at least using
850 get_saved_register on the 68k. This means that for this function to
851 work right a port must use the bp_call_dummy breakpoint. */
854 frame_in_dummy (frame
)
855 struct frame_info
*frame
;
858 #ifdef USE_GENERIC_DUMMY_FRAMES
859 return generic_pc_in_call_dummy (frame
->pc
, frame
->frame
);
861 struct breakpoint
*b
;
865 static ULONGEST dummy
[] = CALL_DUMMY
;
867 if (b
->type
== bp_call_dummy
868 && b
->frame
== frame
->frame
870 /* We need to check the PC as well as the frame on the sparc,
871 for signals.exp in the testsuite. */
874 - sizeof (dummy
) / sizeof (LONGEST
) * REGISTER_SIZE
))
875 && frame
->pc
<= b
->address
)
878 #endif /* GENERIC_DUMMY_FRAMES */
879 #endif /* CALL_DUMMY */
883 /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
884 is valid for process/thread PID. */
887 breakpoint_thread_match (pc
, pid
)
891 struct breakpoint
*b
;
894 thread
= pid_to_thread_id (pid
);
897 if (b
->enable
!= disabled
898 && b
->enable
!= shlib_disabled
900 && (b
->thread
== -1 || b
->thread
== thread
))
902 if (overlay_debugging
&&
903 section_is_overlay (b
->section
) &&
904 !section_is_mapped (b
->section
))
905 continue; /* unmapped overlay -- can't be a match */
914 /* bpstat stuff. External routines' interfaces are documented
917 /* Clear a bpstat so that it says we are not at any breakpoint.
918 Also free any storage that is part of a bpstat. */
933 if (p
->old_val
!= NULL
)
934 value_free (p
->old_val
);
941 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
942 is part of the bpstat is copied as well. */
950 bpstat retval
= NULL
;
955 for (; bs
!= NULL
; bs
= bs
->next
)
957 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
958 memcpy (tmp
, bs
, sizeof (*tmp
));
960 /* This is the first thing in the chain. */
970 /* Find the bpstat associated with this breakpoint */
973 bpstat_find_breakpoint(bsp
, breakpoint
)
975 struct breakpoint
*breakpoint
;
977 if (bsp
== NULL
) return NULL
;
979 for (;bsp
!= NULL
; bsp
= bsp
->next
) {
980 if (bsp
->breakpoint_at
== breakpoint
) return bsp
;
985 /* Return the breakpoint number of the first breakpoint we are stopped
986 at. *BSP upon return is a bpstat which points to the remaining
987 breakpoints stopped at (but which is not guaranteed to be good for
988 anything but further calls to bpstat_num).
989 Return 0 if passed a bpstat which does not indicate any breakpoints. */
995 struct breakpoint
*b
;
998 return 0; /* No more breakpoint values */
1001 b
= (*bsp
)->breakpoint_at
;
1002 *bsp
= (*bsp
)->next
;
1004 return -1; /* breakpoint that's been deleted since */
1006 return b
->number
; /* We have its number */
1010 /* Modify BS so that the actions will not be performed. */
1013 bpstat_clear_actions (bs
)
1016 for (; bs
!= NULL
; bs
= bs
->next
)
1018 bs
->commands
= NULL
;
1019 if (bs
->old_val
!= NULL
)
1021 value_free (bs
->old_val
);
1027 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1030 cleanup_executing_breakpoints (ignore
)
1033 executing_breakpoint_commands
= 0;
1036 /* Execute all the commands associated with all the breakpoints at this
1037 location. Any of these commands could cause the process to proceed
1038 beyond this point, etc. We look out for such changes by checking
1039 the global "breakpoint_proceeded" after each command. */
1042 bpstat_do_actions (bsp
)
1046 struct cleanup
*old_chain
;
1047 struct command_line
*cmd
;
1049 /* Avoid endless recursion if a `source' command is contained
1051 if (executing_breakpoint_commands
)
1054 executing_breakpoint_commands
= 1;
1055 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
1060 breakpoint_proceeded
= 0;
1061 for (; bs
!= NULL
; bs
= bs
->next
)
1066 execute_control_command (cmd
);
1069 if (breakpoint_proceeded
)
1070 /* The inferior is proceeded by the command; bomb out now.
1071 The bpstat chain has been blown away by wait_for_inferior.
1072 But since execution has stopped again, there is a new bpstat
1073 to look at, so start over. */
1076 bs
->commands
= NULL
;
1079 executing_breakpoint_commands
= 0;
1080 discard_cleanups (old_chain
);
1083 /* This is the normal print_it function for a bpstat. In the future,
1084 much of this logic could (should?) be moved to bpstat_stop_status,
1085 by having it set different print_it functions. */
1088 print_it_normal (bs
)
1091 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1092 which has since been deleted. */
1093 if (bs
->breakpoint_at
== NULL
1094 || (bs
->breakpoint_at
->type
!= bp_breakpoint
1095 && bs
->breakpoint_at
->type
!= bp_hardware_breakpoint
1096 && bs
->breakpoint_at
->type
!= bp_watchpoint
1097 && bs
->breakpoint_at
->type
!= bp_read_watchpoint
1098 && bs
->breakpoint_at
->type
!= bp_access_watchpoint
1099 && bs
->breakpoint_at
->type
!= bp_hardware_watchpoint
))
1102 if (bs
->breakpoint_at
->type
== bp_breakpoint
||
1103 bs
->breakpoint_at
->type
== bp_hardware_breakpoint
)
1105 /* I think the user probably only wants to see one breakpoint
1106 number, not all of them. */
1107 annotate_breakpoint (bs
->breakpoint_at
->number
);
1108 printf_filtered ("\nBreakpoint %d, ", bs
->breakpoint_at
->number
);
1111 else if ((bs
->old_val
!= NULL
) &&
1112 (bs
->breakpoint_at
->type
== bp_watchpoint
||
1113 bs
->breakpoint_at
->type
== bp_access_watchpoint
||
1114 bs
->breakpoint_at
->type
== bp_hardware_watchpoint
))
1116 annotate_watchpoint (bs
->breakpoint_at
->number
);
1117 mention (bs
->breakpoint_at
);
1118 printf_filtered ("\nOld value = ");
1119 value_print (bs
->old_val
, gdb_stdout
, 0, Val_pretty_default
);
1120 printf_filtered ("\nNew value = ");
1121 value_print (bs
->breakpoint_at
->val
, gdb_stdout
, 0,
1122 Val_pretty_default
);
1123 printf_filtered ("\n");
1124 value_free (bs
->old_val
);
1126 /* More than one watchpoint may have been triggered. */
1129 else if (bs
->breakpoint_at
->type
== bp_access_watchpoint
||
1130 bs
->breakpoint_at
->type
== bp_read_watchpoint
)
1132 mention (bs
->breakpoint_at
);
1133 printf_filtered ("\nValue = ");
1134 value_print (bs
->breakpoint_at
->val
, gdb_stdout
, 0,
1135 Val_pretty_default
);
1136 printf_filtered ("\n");
1139 /* We can't deal with it. Maybe another member of the bpstat chain can. */
1143 /* Print a message indicating what happened. Returns nonzero to
1144 say that only the source line should be printed after this (zero
1145 return means print the frame as well as the source line). */
1146 /* Currently we always return zero. */
1156 val
= (*bs
->print_it
) (bs
);
1160 /* Maybe another breakpoint in the chain caused us to stop.
1161 (Currently all watchpoints go on the bpstat whether hit or
1162 not. That probably could (should) be changed, provided care is taken
1163 with respect to bpstat_explains_signal). */
1165 return bpstat_print (bs
->next
);
1167 /* We reached the end of the chain without printing anything. */
1171 /* Evaluate the expression EXP and return 1 if value is zero.
1172 This is used inside a catch_errors to evaluate the breakpoint condition.
1173 The argument is a "struct expression *" that has been cast to char * to
1174 make it pass through catch_errors. */
1177 breakpoint_cond_eval (exp
)
1180 value_ptr mark
= value_mark ();
1181 int i
= !value_true (evaluate_expression ((struct expression
*)exp
));
1182 value_free_to_mark (mark
);
1186 /* Allocate a new bpstat and chain it to the current one. */
1189 bpstat_alloc (b
, cbs
)
1190 register struct breakpoint
*b
;
1191 bpstat cbs
; /* Current "bs" value */
1195 bs
= (bpstat
) xmalloc (sizeof (*bs
));
1197 bs
->breakpoint_at
= b
;
1198 /* If the condition is false, etc., don't do the commands. */
1199 bs
->commands
= NULL
;
1201 bs
->print_it
= print_it_normal
;
1205 /* Possible return values for watchpoint_check (this can't be an enum
1206 because of check_errors). */
1207 /* The watchpoint has been deleted. */
1208 #define WP_DELETED 1
1209 /* The value has changed. */
1210 #define WP_VALUE_CHANGED 2
1211 /* The value has not changed. */
1212 #define WP_VALUE_NOT_CHANGED 3
1214 #define BP_TEMPFLAG 1
1215 #define BP_HARDWAREFLAG 2
1217 /* Check watchpoint condition. */
1220 watchpoint_check (p
)
1223 bpstat bs
= (bpstat
) p
;
1224 struct breakpoint
*b
;
1225 struct frame_info
*fr
;
1226 int within_current_scope
;
1228 b
= bs
->breakpoint_at
;
1230 if (b
->exp_valid_block
== NULL
)
1231 within_current_scope
= 1;
1234 /* There is no current frame at this moment. If we're going to have
1235 any chance of handling watchpoints on local variables, we'll need
1236 the frame chain (so we can determine if we're in scope). */
1237 reinit_frame_cache();
1238 fr
= find_frame_addr_in_frame_chain (b
->watchpoint_frame
);
1239 within_current_scope
= (fr
!= NULL
);
1240 if (within_current_scope
)
1241 /* If we end up stopping, the current frame will get selected
1242 in normal_stop. So this call to select_frame won't affect
1244 select_frame (fr
, -1);
1247 if (within_current_scope
)
1249 /* We use value_{,free_to_}mark because it could be a
1250 *long* time before we return to the command level and
1251 call free_all_values. We can't call free_all_values because
1252 we might be in the middle of evaluating a function call. */
1254 value_ptr mark
= value_mark ();
1255 value_ptr new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
1256 if (!value_equal (b
->val
, new_val
))
1258 release_value (new_val
);
1259 value_free_to_mark (mark
);
1260 bs
->old_val
= b
->val
;
1262 /* We will stop here */
1263 return WP_VALUE_CHANGED
;
1267 /* Nothing changed, don't do anything. */
1268 value_free_to_mark (mark
);
1269 /* We won't stop here */
1270 return WP_VALUE_NOT_CHANGED
;
1275 /* This seems like the only logical thing to do because
1276 if we temporarily ignored the watchpoint, then when
1277 we reenter the block in which it is valid it contains
1278 garbage (in the case of a function, it may have two
1279 garbage values, one before and one after the prologue).
1280 So we can't even detect the first assignment to it and
1281 watch after that (since the garbage may or may not equal
1282 the first value assigned). */
1284 Watchpoint %d deleted because the program has left the block in\n\
1285 which its expression is valid.\n", bs
->breakpoint_at
->number
);
1286 if (b
->related_breakpoint
)
1287 b
->related_breakpoint
->disposition
= del_at_next_stop
;
1288 b
->disposition
= del_at_next_stop
;
1294 /* This is used when everything which needs to be printed has
1295 already been printed. But we still want to print the frame. */
1303 /* This is used when nothing should be printed for this bpstat entry. */
1312 /* Get a bpstat associated with having just stopped at address *PC
1313 and frame address CORE_ADDRESS. Update *PC to point at the
1314 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
1315 if this is known to not be a real breakpoint (it could still be a
1316 watchpoint, though). */
1318 /* Determine whether we stopped at a breakpoint, etc, or whether we
1319 don't understand this stop. Result is a chain of bpstat's such that:
1321 if we don't understand the stop, the result is a null pointer.
1323 if we understand why we stopped, the result is not null.
1325 Each element of the chain refers to a particular breakpoint or
1326 watchpoint at which we have stopped. (We may have stopped for
1327 several reasons concurrently.)
1329 Each element of the chain has valid next, breakpoint_at,
1330 commands, FIXME??? fields.
1335 bpstat_stop_status (pc
, not_a_breakpoint
)
1337 int not_a_breakpoint
;
1339 register struct breakpoint
*b
, *temp
;
1341 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
1342 int real_breakpoint
= 0;
1343 /* Root of the chain of bpstat's */
1344 struct bpstats root_bs
[1];
1345 /* Pointer to the last thing in the chain currently. */
1346 bpstat bs
= root_bs
;
1347 static char message1
[] =
1348 "Error evaluating expression for watchpoint %d\n";
1349 char message
[sizeof (message1
) + 30 /* slop */];
1351 /* Get the address where the breakpoint would have been. */
1352 bp_addr
= *pc
- DECR_PC_AFTER_BREAK
;
1354 ALL_BREAKPOINTS_SAFE (b
, temp
)
1356 if (b
->enable
== disabled
1357 || b
->enable
== shlib_disabled
)
1360 if (b
->type
!= bp_watchpoint
1361 && b
->type
!= bp_hardware_watchpoint
1362 && b
->type
!= bp_read_watchpoint
1363 && b
->type
!= bp_access_watchpoint
1364 && b
->type
!= bp_hardware_breakpoint
) /* a non-watchpoint bp */
1365 if (b
->address
!= bp_addr
|| /* address doesn't match or */
1366 (overlay_debugging
&& /* overlay doesn't match */
1367 section_is_overlay (b
->section
) &&
1368 !section_is_mapped (b
->section
)))
1371 if (b
->type
== bp_hardware_breakpoint
1372 && b
->address
!= (bp_addr
- DECR_PC_AFTER_HW_BREAK
))
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 && not_a_breakpoint
)
1382 /* Come here if it's a watchpoint, or if the break address matches */
1386 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
1391 sprintf (message
, message1
, b
->number
);
1392 if (b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1394 switch (catch_errors (watchpoint_check
, (char *) bs
, message
,
1398 /* We've already printed what needs to be printed. */
1399 bs
->print_it
= print_it_done
;
1402 case WP_VALUE_CHANGED
:
1405 case WP_VALUE_NOT_CHANGED
:
1407 bs
->print_it
= print_it_noop
;
1409 /* Don't consider this a hit. */
1416 /* Error from catch_errors. */
1417 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
1418 if (b
->related_breakpoint
)
1419 b
->related_breakpoint
->disposition
= del_at_next_stop
;
1420 b
->disposition
= del_at_next_stop
;
1421 /* We've already printed what needs to be printed. */
1422 bs
->print_it
= print_it_done
;
1428 else if (b
->type
== bp_read_watchpoint
|| b
->type
== bp_access_watchpoint
)
1434 addr
= target_stopped_data_address();
1435 if (addr
== 0) continue;
1436 for (v
= b
->val_chain
; v
; v
= v
->next
)
1438 if (v
->lval
== lval_memory
)
1442 vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1448 switch (catch_errors (watchpoint_check
, (char *) bs
, message
,
1452 /* We've already printed what needs to be printed. */
1453 bs
->print_it
= print_it_done
;
1456 case WP_VALUE_CHANGED
:
1457 case WP_VALUE_NOT_CHANGED
:
1463 /* Error from catch_errors. */
1464 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
1465 if (b
->related_breakpoint
)
1466 b
->related_breakpoint
->disposition
= del_at_next_stop
;
1467 b
->disposition
= del_at_next_stop
;
1468 /* We've already printed what needs to be printed. */
1469 bs
->print_it
= print_it_done
;
1473 else if (DECR_PC_AFTER_BREAK
!= 0 || must_shift_inst_regs
)
1474 real_breakpoint
= 1;
1476 if (b
->frame
&& b
->frame
!= (get_current_frame ())->frame
&&
1477 (b
->type
== bp_step_resume
&&
1478 (get_current_frame ())->frame INNER_THAN b
->frame
))
1482 int value_is_zero
= 0;
1486 /* Need to select the frame, with all that implies
1487 so that the conditions will have the right context. */
1488 select_frame (get_current_frame (), 0);
1490 = catch_errors (breakpoint_cond_eval
, (char *)(b
->cond
),
1491 "Error in testing breakpoint condition:\n",
1493 /* FIXME-someday, should give breakpoint # */
1496 if (b
->cond
&& value_is_zero
)
1499 /* Don't consider this a hit. */
1502 else if (b
->ignore_count
> 0)
1509 /* We will stop here */
1510 if (b
->disposition
== disable
)
1511 b
->enable
= disabled
;
1512 bs
->commands
= b
->commands
;
1515 if (bs
->commands
&& STREQ ("silent", bs
->commands
->line
))
1517 bs
->commands
= bs
->commands
->next
;
1522 /* Print nothing for this entry if we dont stop or if we dont print. */
1523 if (bs
->stop
== 0 || bs
->print
== 0)
1524 bs
->print_it
= print_it_noop
;
1527 bs
->next
= NULL
; /* Terminate the chain */
1528 bs
= root_bs
->next
; /* Re-grab the head of the chain */
1530 if ((DECR_PC_AFTER_BREAK
!= 0 || must_shift_inst_regs
) && bs
)
1532 if (real_breakpoint
)
1535 #if defined (SHIFT_INST_REGS)
1537 #else /* No SHIFT_INST_REGS. */
1539 #endif /* No SHIFT_INST_REGS. */
1543 /* The value of a hardware watchpoint hasn't changed, but the
1544 intermediate memory locations we are watching may have. */
1545 if (bs
&& ! bs
->stop
&&
1546 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
1547 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
1548 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
1550 remove_breakpoints ();
1551 insert_breakpoints ();
1556 /* Tell what to do about this bpstat. */
1561 /* Classify each bpstat as one of the following. */
1563 /* This bpstat element has no effect on the main_action. */
1566 /* There was a watchpoint, stop but don't print. */
1569 /* There was a watchpoint, stop and print. */
1572 /* There was a breakpoint but we're not stopping. */
1575 /* There was a breakpoint, stop but don't print. */
1578 /* There was a breakpoint, stop and print. */
1581 /* We hit the longjmp breakpoint. */
1584 /* We hit the longjmp_resume breakpoint. */
1587 /* We hit the step_resume breakpoint. */
1590 /* We hit the through_sigtramp breakpoint. */
1593 /* We hit the shared library event breakpoint. */
1596 /* This is just used to count how many enums there are. */
1600 /* Here is the table which drives this routine. So that we can
1601 format it pretty, we define some abbreviations for the
1602 enum bpstat_what codes. */
1603 #define kc BPSTAT_WHAT_KEEP_CHECKING
1604 #define ss BPSTAT_WHAT_STOP_SILENT
1605 #define sn BPSTAT_WHAT_STOP_NOISY
1606 #define sgl BPSTAT_WHAT_SINGLE
1607 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
1608 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
1609 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
1610 #define sr BPSTAT_WHAT_STEP_RESUME
1611 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
1612 #define shl BPSTAT_WHAT_CHECK_SHLIBS
1614 /* "Can't happen." Might want to print an error message.
1615 abort() is not out of the question, but chances are GDB is just
1616 a bit confused, not unusable. */
1617 #define err BPSTAT_WHAT_STOP_NOISY
1619 /* Given an old action and a class, come up with a new action. */
1620 /* One interesting property of this table is that wp_silent is the same
1621 as bp_silent and wp_noisy is the same as bp_noisy. That is because
1622 after stopping, the check for whether to step over a breakpoint
1623 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
1624 reference to how we stopped. We retain separate wp_silent and bp_silent
1625 codes in case we want to change that someday. */
1627 /* step_resume entries: a step resume breakpoint overrides another
1628 breakpoint of signal handling (see comment in wait_for_inferior
1629 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
1630 /* We handle the through_sigtramp_breakpoint the same way; having both
1631 one of those and a step_resume_breakpoint is probably very rare (?). */
1633 static const enum bpstat_what_main_action
1634 table
[(int)class_last
][(int)BPSTAT_WHAT_LAST
] =
1637 /* kc ss sn sgl slr clr clrs sr ts shl
1639 /*no_effect*/ {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, ts
, shl
},
1640 /*wp_silent*/ {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
},
1641 /*wp_noisy*/ {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
},
1642 /*bp_nostop*/ {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, ts
, shl
},
1643 /*bp_silent*/ {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
},
1644 /*bp_noisy*/ {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
},
1645 /*long_jump*/ {slr
, ss
, sn
, slr
, err
, err
, err
, sr
, ts
, shl
},
1646 /*long_resume*/ {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, ts
, shl
},
1647 /*step_resume*/ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, ts
, shl
},
1648 /*through_sig*/ {ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, shl
},
1649 /*shlib*/ {shl
, shl
, shl
, shl
, shl
, shl
, shl
, shl
, ts
, shl
}
1662 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
1663 struct bpstat_what retval
;
1665 retval
.call_dummy
= 0;
1666 for (; bs
!= NULL
; bs
= bs
->next
)
1668 enum class bs_class
= no_effect
;
1669 if (bs
->breakpoint_at
== NULL
)
1670 /* I suspect this can happen if it was a momentary breakpoint
1671 which has since been deleted. */
1673 switch (bs
->breakpoint_at
->type
)
1676 case bp_hardware_breakpoint
:
1682 bs_class
= bp_noisy
;
1684 bs_class
= bp_silent
;
1687 bs_class
= bp_nostop
;
1690 case bp_hardware_watchpoint
:
1691 case bp_read_watchpoint
:
1692 case bp_access_watchpoint
:
1696 bs_class
= wp_noisy
;
1698 bs_class
= wp_silent
;
1701 /* There was a watchpoint, but we're not stopping. This requires
1702 no further action. */
1703 bs_class
= no_effect
;
1706 bs_class
= long_jump
;
1708 case bp_longjmp_resume
:
1709 bs_class
= long_resume
;
1711 case bp_step_resume
:
1714 bs_class
= step_resume
;
1717 /* It is for the wrong frame. */
1718 bs_class
= bp_nostop
;
1720 case bp_through_sigtramp
:
1721 bs_class
= through_sig
;
1723 case bp_watchpoint_scope
:
1724 bs_class
= bp_nostop
;
1726 case bp_shlib_event
:
1727 bs_class
= shlib_event
;
1730 /* Make sure the action is stop (silent or noisy), so infrun.c
1731 pops the dummy frame. */
1732 bs_class
= bp_silent
;
1733 retval
.call_dummy
= 1;
1736 current_action
= table
[(int)bs_class
][(int)current_action
];
1738 retval
.main_action
= current_action
;
1742 /* Nonzero if we should step constantly (e.g. watchpoints on machines
1743 without hardware support). This isn't related to a specific bpstat,
1744 just to things like whether watchpoints are set. */
1747 bpstat_should_step ()
1749 struct breakpoint
*b
;
1751 if (b
->enable
== enabled
&& b
->type
== bp_watchpoint
)
1756 /* Print information on breakpoint number BNUM, or -1 if all.
1757 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
1758 is nonzero, process only watchpoints. */
1761 breakpoint_1 (bnum
, allflag
)
1765 register struct breakpoint
*b
;
1766 register struct command_line
*l
;
1767 register struct symbol
*sym
;
1768 CORE_ADDR last_addr
= (CORE_ADDR
)-1;
1769 int found_a_breakpoint
= 0;
1770 static char *bptypes
[] = {"breakpoint", "hw breakpoint",
1771 "until", "finish", "watchpoint",
1772 "hw watchpoint", "read watchpoint",
1773 "acc watchpoint", "longjmp",
1774 "longjmp resume", "step resume",
1776 "watchpoint scope", "call dummy",
1778 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
1779 static char bpenables
[] = "nyn";
1780 char wrap_indent
[80];
1784 || bnum
== b
->number
)
1786 /* We only print out user settable breakpoints unless the allflag is set. */
1788 && b
->type
!= bp_breakpoint
1789 && b
->type
!= bp_hardware_breakpoint
1790 && b
->type
!= bp_watchpoint
1791 && b
->type
!= bp_read_watchpoint
1792 && b
->type
!= bp_access_watchpoint
1793 && b
->type
!= bp_hardware_watchpoint
)
1796 if (!found_a_breakpoint
++)
1798 annotate_breakpoints_headers ();
1801 printf_filtered ("Num ");
1803 printf_filtered ("Type ");
1805 printf_filtered ("Disp ");
1807 printf_filtered ("Enb ");
1811 printf_filtered ("Address ");
1814 printf_filtered ("What\n");
1816 annotate_breakpoints_table ();
1821 printf_filtered ("%-3d ", b
->number
);
1823 printf_filtered ("%-14s ", bptypes
[(int)b
->type
]);
1825 printf_filtered ("%-4s ", bpdisps
[(int)b
->disposition
]);
1827 printf_filtered ("%-3c ", bpenables
[(int)b
->enable
]);
1829 strcpy (wrap_indent
, " ");
1831 strcat (wrap_indent
, " ");
1835 case bp_hardware_watchpoint
:
1836 case bp_read_watchpoint
:
1837 case bp_access_watchpoint
:
1838 /* Field 4, the address, is omitted (which makes the columns
1839 not line up too nicely with the headers, but the effect
1840 is relatively readable). */
1842 print_expression (b
->exp
, gdb_stdout
);
1846 case bp_hardware_breakpoint
:
1850 case bp_longjmp_resume
:
1851 case bp_step_resume
:
1852 case bp_through_sigtramp
:
1853 case bp_watchpoint_scope
:
1855 case bp_shlib_event
:
1859 /* FIXME-32x64: need a print_address_numeric with
1863 local_hex_string_custom
1864 ((unsigned long) b
->address
, "08l"));
1869 last_addr
= b
->address
;
1872 sym
= find_pc_sect_function (b
->address
, b
->section
);
1875 fputs_filtered ("in ", gdb_stdout
);
1876 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), gdb_stdout
);
1877 wrap_here (wrap_indent
);
1878 fputs_filtered (" at ", gdb_stdout
);
1880 fputs_filtered (b
->source_file
, gdb_stdout
);
1881 printf_filtered (":%d", b
->line_number
);
1884 print_address_symbolic (b
->address
, gdb_stdout
, demangle
, " ");
1888 printf_filtered ("\n");
1894 printf_filtered ("\tstop only in stack frame at ");
1895 print_address_numeric (b
->frame
, 1, gdb_stdout
);
1896 printf_filtered ("\n");
1903 printf_filtered ("\tstop only if ");
1904 print_expression (b
->cond
, gdb_stdout
);
1905 printf_filtered ("\n");
1908 if (b
->thread
!= -1)
1910 /* FIXME should make an annotation for this */
1911 printf_filtered ("\tstop only in thread %d\n", b
->thread
);
1914 if (show_breakpoint_hit_counts
&& b
->hit_count
)
1916 /* FIXME should make an annotation for this */
1918 printf_filtered ("\tbreakpoint already hit %d time%s\n",
1919 b
->hit_count
, (b
->hit_count
== 1 ? "" : "s"));
1922 if (b
->ignore_count
)
1926 printf_filtered ("\tignore next %d hits\n", b
->ignore_count
);
1929 if ((l
= b
->commands
))
1935 print_command_line (l
, 4);
1941 if (!found_a_breakpoint
)
1944 printf_filtered ("No breakpoints or watchpoints.\n");
1946 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum
);
1949 /* Compare against (CORE_ADDR)-1 in case some compiler decides
1950 that a comparison of an unsigned with -1 is always false. */
1951 if (last_addr
!= (CORE_ADDR
)-1)
1952 set_next_address (last_addr
);
1954 annotate_breakpoints_table_end ();
1959 breakpoints_info (bnum_exp
, from_tty
)
1966 bnum
= parse_and_eval_address (bnum_exp
);
1968 breakpoint_1 (bnum
, 0);
1971 #if MAINTENANCE_CMDS
1975 maintenance_info_breakpoints (bnum_exp
, from_tty
)
1982 bnum
= parse_and_eval_address (bnum_exp
);
1984 breakpoint_1 (bnum
, 1);
1989 /* Print a message describing any breakpoints set at PC. */
1992 describe_other_breakpoints (pc
, section
)
1996 register int others
= 0;
1997 register struct breakpoint
*b
;
2000 if (b
->address
== pc
)
2001 if (overlay_debugging
== 0 ||
2002 b
->section
== section
)
2006 printf_filtered ("Note: breakpoint%s ", (others
> 1) ? "s" : "");
2008 if (b
->address
== pc
)
2009 if (overlay_debugging
== 0 ||
2010 b
->section
== section
)
2016 ((b
->enable
== disabled
|| b
->enable
== shlib_disabled
)
2017 ? " (disabled)" : ""),
2018 (others
> 1) ? "," : ((others
== 1) ? " and" : ""));
2020 printf_filtered ("also set at pc ");
2021 print_address_numeric (pc
, 1, gdb_stdout
);
2022 printf_filtered (".\n");
2026 /* Set the default place to put a breakpoint
2027 for the `break' command with no arguments. */
2030 set_default_breakpoint (valid
, addr
, symtab
, line
)
2033 struct symtab
*symtab
;
2036 default_breakpoint_valid
= valid
;
2037 default_breakpoint_address
= addr
;
2038 default_breakpoint_symtab
= symtab
;
2039 default_breakpoint_line
= line
;
2042 /* Rescan breakpoints at address ADDRESS,
2043 marking the first one as "first" and any others as "duplicates".
2044 This is so that the bpt instruction is only inserted once. */
2047 check_duplicates (address
, section
)
2051 register struct breakpoint
*b
;
2052 register int count
= 0;
2054 if (address
== 0) /* Watchpoints are uninteresting */
2058 if (b
->enable
!= disabled
2059 && b
->enable
!= shlib_disabled
2060 && b
->address
== address
2061 && (overlay_debugging
== 0 || b
->section
== section
))
2064 b
->duplicate
= count
> 1;
2068 /* Low level routine to set a breakpoint.
2069 Takes as args the three things that every breakpoint must have.
2070 Returns the breakpoint object so caller can set other things.
2071 Does not set the breakpoint number!
2072 Does not print anything.
2074 ==> This routine should not be called if there is a chance of later
2075 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
2076 your arguments BEFORE calling this routine! */
2079 set_raw_breakpoint (sal
)
2080 struct symtab_and_line sal
;
2082 register struct breakpoint
*b
, *b1
;
2084 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
2085 memset (b
, 0, sizeof (*b
));
2086 b
->address
= sal
.pc
;
2087 if (sal
.symtab
== NULL
)
2088 b
->source_file
= NULL
;
2090 b
->source_file
= savestring (sal
.symtab
->filename
,
2091 strlen (sal
.symtab
->filename
));
2092 b
->section
= sal
.section
;
2093 b
->language
= current_language
->la_language
;
2094 b
->input_radix
= input_radix
;
2096 b
->line_number
= sal
.line
;
2097 b
->enable
= enabled
;
2100 b
->ignore_count
= 0;
2104 /* Add this breakpoint to the end of the chain
2105 so that a list of breakpoints will come out in order
2106 of increasing numbers. */
2108 b1
= breakpoint_chain
;
2110 breakpoint_chain
= b
;
2118 check_duplicates (sal
.pc
, sal
.section
);
2119 breakpoints_changed ();
2124 #ifdef GET_LONGJMP_TARGET
2127 create_longjmp_breakpoint (func_name
)
2130 struct symtab_and_line sal
;
2131 struct breakpoint
*b
;
2133 INIT_SAL (&sal
); /* initialize to zeroes */
2134 if (func_name
!= NULL
)
2136 struct minimal_symbol
*m
;
2138 m
= lookup_minimal_symbol_text (func_name
, NULL
, (struct objfile
*)NULL
);
2140 sal
.pc
= SYMBOL_VALUE_ADDRESS (m
);
2144 sal
.section
= find_pc_overlay (sal
.pc
);
2145 b
= set_raw_breakpoint (sal
);
2148 b
->type
= func_name
!= NULL
? bp_longjmp
: bp_longjmp_resume
;
2149 b
->disposition
= donttouch
;
2150 b
->enable
= disabled
;
2153 b
->addr_string
= strsave(func_name
);
2154 b
->number
= internal_breakpoint_number
--;
2157 #endif /* #ifdef GET_LONGJMP_TARGET */
2159 /* Call this routine when stepping and nexting to enable a breakpoint if we do
2160 a longjmp(). When we hit that breakpoint, call
2161 set_longjmp_resume_breakpoint() to figure out where we are going. */
2164 enable_longjmp_breakpoint()
2166 register struct breakpoint
*b
;
2169 if (b
->type
== bp_longjmp
)
2171 b
->enable
= enabled
;
2172 check_duplicates (b
->address
, b
->section
);
2177 disable_longjmp_breakpoint()
2179 register struct breakpoint
*b
;
2182 if ( b
->type
== bp_longjmp
2183 || b
->type
== bp_longjmp_resume
)
2185 b
->enable
= disabled
;
2186 check_duplicates (b
->address
, b
->section
);
2192 remove_solib_event_breakpoints ()
2194 register struct breakpoint
*b
, *temp
;
2196 ALL_BREAKPOINTS_SAFE (b
, temp
)
2197 if (b
->type
== bp_shlib_event
)
2198 delete_breakpoint (b
);
2202 create_solib_event_breakpoint (address
)
2205 struct breakpoint
*b
;
2206 struct symtab_and_line sal
;
2208 INIT_SAL (&sal
); /* initialize to zeroes */
2210 sal
.section
= find_pc_overlay (sal
.pc
);
2211 b
= set_raw_breakpoint (sal
);
2212 b
->number
= internal_breakpoint_number
--;
2213 b
->disposition
= donttouch
;
2214 b
->type
= bp_shlib_event
;
2217 /* Try to reenable any breakpoints in shared libraries. */
2219 re_enable_breakpoints_in_shlibs ()
2221 struct breakpoint
*b
;
2224 if (b
->enable
== shlib_disabled
)
2228 /* Do not reenable the breakpoint if the shared library
2229 is still not mapped in. */
2230 if (target_read_memory (b
->address
, buf
, 1) == 0)
2231 b
->enable
= enabled
;
2238 hw_breakpoint_used_count()
2240 register struct breakpoint
*b
;
2245 if (b
->type
== bp_hardware_breakpoint
&& b
->enable
== enabled
)
2253 hw_watchpoint_used_count(type
, other_type_used
)
2255 int *other_type_used
;
2257 register struct breakpoint
*b
;
2260 *other_type_used
= 0;
2263 if (b
->enable
== enabled
)
2265 if (b
->type
== type
) i
++;
2266 else if ((b
->type
== bp_hardware_watchpoint
||
2267 b
->type
== bp_read_watchpoint
||
2268 b
->type
== bp_access_watchpoint
)
2269 && b
->enable
== enabled
)
2270 *other_type_used
= 1;
2276 /* Call this after hitting the longjmp() breakpoint. Use this to set a new
2277 breakpoint at the target of the jmp_buf.
2279 FIXME - This ought to be done by setting a temporary breakpoint that gets
2280 deleted automatically...
2284 set_longjmp_resume_breakpoint(pc
, frame
)
2286 struct frame_info
*frame
;
2288 register struct breakpoint
*b
;
2291 if (b
->type
== bp_longjmp_resume
)
2294 b
->enable
= enabled
;
2296 b
->frame
= frame
->frame
;
2299 check_duplicates (b
->address
, b
->section
);
2304 /* Set a breakpoint that will evaporate an end of command
2305 at address specified by SAL.
2306 Restrict it to frame FRAME if FRAME is nonzero. */
2309 set_momentary_breakpoint (sal
, frame
, type
)
2310 struct symtab_and_line sal
;
2311 struct frame_info
*frame
;
2314 register struct breakpoint
*b
;
2315 b
= set_raw_breakpoint (sal
);
2317 b
->enable
= enabled
;
2318 b
->disposition
= donttouch
;
2319 b
->frame
= (frame
? frame
->frame
: 0);
2321 /* If we're debugging a multi-threaded program, then we
2322 want momentary breakpoints to be active in only a
2323 single thread of control. */
2324 if (in_thread_list (inferior_pid
))
2325 b
->thread
= pid_to_thread_id (inferior_pid
);
2331 /* Tell the user we have just set a breakpoint B. */
2335 struct breakpoint
*b
;
2339 /* FIXME: This is misplaced; mention() is called by things (like hitting a
2340 watchpoint) other than breakpoint creation. It should be possible to
2341 clean this up and at the same time replace the random calls to
2342 breakpoint_changed with this hook, as has already been done for
2343 delete_breakpoint_hook and so on. */
2344 if (create_breakpoint_hook
)
2345 create_breakpoint_hook (b
);
2350 printf_filtered ("Watchpoint %d: ", b
->number
);
2351 print_expression (b
->exp
, gdb_stdout
);
2353 case bp_hardware_watchpoint
:
2354 printf_filtered ("Hardware watchpoint %d: ", b
->number
);
2355 print_expression (b
->exp
, gdb_stdout
);
2357 case bp_read_watchpoint
:
2358 printf_filtered ("Hardware read watchpoint %d: ", b
->number
);
2359 print_expression (b
->exp
, gdb_stdout
);
2361 case bp_access_watchpoint
:
2362 printf_filtered ("Hardware access(read/write) watchpoint %d: ",b
->number
);
2363 print_expression (b
->exp
, gdb_stdout
);
2366 printf_filtered ("Breakpoint %d", b
->number
);
2369 case bp_hardware_breakpoint
:
2370 printf_filtered ("Hardware assisted breakpoint %d", b
->number
);
2376 case bp_longjmp_resume
:
2377 case bp_step_resume
:
2378 case bp_through_sigtramp
:
2380 case bp_watchpoint_scope
:
2381 case bp_shlib_event
:
2386 if (addressprint
|| b
->source_file
== NULL
)
2388 printf_filtered (" at ");
2389 print_address_numeric (b
->address
, 1, gdb_stdout
);
2392 printf_filtered (": file %s, line %d.",
2393 b
->source_file
, b
->line_number
);
2395 printf_filtered ("\n");
2399 /* Set a breakpoint according to ARG (function, linenum or *address)
2400 flag: first bit : 0 non-temporary, 1 temporary.
2401 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
2404 break_command_1 (arg
, flag
, from_tty
)
2408 int tempflag
, hardwareflag
;
2409 struct symtabs_and_lines sals
;
2410 struct symtab_and_line sal
;
2411 register struct expression
*cond
= 0;
2412 register struct breakpoint
*b
;
2414 /* Pointers in arg to the start, and one past the end, of the condition. */
2415 char *cond_start
= NULL
;
2416 char *cond_end
= NULL
;
2417 /* Pointers in arg to the start, and one past the end,
2418 of the address part. */
2419 char *addr_start
= NULL
;
2420 char *addr_end
= NULL
;
2421 struct cleanup
*old_chain
;
2422 struct cleanup
*canonical_strings_chain
= NULL
;
2423 char **canonical
= (char **)NULL
;
2427 hardwareflag
= flag
& BP_HARDWAREFLAG
;
2428 tempflag
= flag
& BP_TEMPFLAG
;
2433 INIT_SAL (&sal
); /* initialize to zeroes */
2435 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
2437 if (!arg
|| (arg
[0] == 'i' && arg
[1] == 'f'
2438 && (arg
[2] == ' ' || arg
[2] == '\t')))
2440 if (default_breakpoint_valid
)
2442 sals
.sals
= (struct symtab_and_line
*)
2443 xmalloc (sizeof (struct symtab_and_line
));
2444 sal
.pc
= default_breakpoint_address
;
2445 sal
.line
= default_breakpoint_line
;
2446 sal
.symtab
= default_breakpoint_symtab
;
2447 sal
.section
= find_pc_overlay (sal
.pc
);
2452 error ("No default breakpoint address now.");
2458 /* Force almost all breakpoints to be in terms of the
2459 current_source_symtab (which is decode_line_1's default). This
2460 should produce the results we want almost all of the time while
2461 leaving default_breakpoint_* alone. */
2462 if (default_breakpoint_valid
2463 && (!current_source_symtab
2464 || (arg
&& (*arg
== '+' || *arg
== '-'))))
2465 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
2466 default_breakpoint_line
, &canonical
);
2468 sals
= decode_line_1 (&arg
, 1, (struct symtab
*)NULL
, 0, &canonical
);
2476 /* Make sure that all storage allocated in decode_line_1 gets freed in case
2477 the following `for' loop errors out. */
2478 old_chain
= make_cleanup (free
, sals
.sals
);
2479 if (canonical
!= (char **)NULL
)
2481 make_cleanup (free
, canonical
);
2482 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
2483 for (i
= 0; i
< sals
.nelts
; i
++)
2485 if (canonical
[i
] != NULL
)
2486 make_cleanup (free
, canonical
[i
]);
2490 thread
= -1; /* No specific thread yet */
2492 /* Resolve all line numbers to PC's, and verify that conditions
2493 can be parsed, before setting any breakpoints. */
2494 for (i
= 0; i
< sals
.nelts
; i
++)
2496 char *tok
, *end_tok
;
2499 resolve_sal_pc (&sals
.sals
[i
]);
2505 while (*tok
== ' ' || *tok
== '\t')
2510 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
2513 toklen
= end_tok
- tok
;
2515 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
2517 tok
= cond_start
= end_tok
+ 1;
2518 cond
= parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
2521 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
2527 thread
= strtol (tok
, &tok
, 0);
2529 error ("Junk after thread keyword.");
2530 if (!valid_thread_id (thread
))
2531 error ("Unknown thread %d\n", thread
);
2534 error ("Junk at end of arguments.");
2539 int i
, target_resources_ok
;
2541 i
= hw_breakpoint_used_count ();
2542 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
2543 bp_hardware_breakpoint
, i
+ sals
.nelts
, 0);
2544 if (target_resources_ok
== 0)
2545 error ("No hardware breakpoint support in the target.");
2546 else if (target_resources_ok
< 0)
2547 error ("Hardware breakpoints used exceeds limit.");
2550 /* Remove the canonical strings from the cleanup, they are needed below. */
2551 if (canonical
!= (char **)NULL
)
2552 discard_cleanups (canonical_strings_chain
);
2554 /* Now set all the breakpoints. */
2555 for (i
= 0; i
< sals
.nelts
; i
++)
2560 describe_other_breakpoints (sal
.pc
, sal
.section
);
2562 b
= set_raw_breakpoint (sal
);
2563 set_breakpoint_count (breakpoint_count
+ 1);
2564 b
->number
= breakpoint_count
;
2565 b
->type
= hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
;
2569 /* If a canonical line spec is needed use that instead of the
2571 if (canonical
!= (char **)NULL
&& canonical
[i
] != NULL
)
2572 b
->addr_string
= canonical
[i
];
2573 else if (addr_start
)
2574 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
2576 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
2578 b
->enable
= enabled
;
2579 b
->disposition
= tempflag
? del
: donttouch
;
2585 printf_filtered ("Multiple breakpoints were set.\n");
2586 printf_filtered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
2588 do_cleanups (old_chain
);
2591 /* Helper function for break_command_1 and disassemble_command. */
2594 resolve_sal_pc (sal
)
2595 struct symtab_and_line
*sal
;
2599 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
2601 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
2602 error ("No line %d in file \"%s\".",
2603 sal
->line
, sal
->symtab
->filename
);
2607 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
2609 struct blockvector
*bv
;
2614 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
2617 b
= BLOCKVECTOR_BLOCK (bv
, index
);
2618 sym
= block_function (b
);
2621 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
2622 sal
->section
= SYMBOL_BFD_SECTION (sym
);
2626 /* It really is worthwhile to have the section, so we'll just
2627 have to look harder. This case can be executed if we have
2628 line numbers but no functions (as can happen in assembly
2631 struct minimal_symbol
*msym
;
2633 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
2635 sal
->section
= SYMBOL_BFD_SECTION (msym
);
2642 break_command (arg
, from_tty
)
2646 break_command_1 (arg
, 0, from_tty
);
2650 tbreak_command (arg
, from_tty
)
2654 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
2658 hbreak_command (arg
, from_tty
)
2662 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
2666 thbreak_command (arg
, from_tty
)
2670 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
2674 /* accessflag: 0: watch write, 1: watch read, 2: watch access(read or write)
2677 watch_command_1 (arg
, accessflag
, from_tty
)
2682 struct breakpoint
*b
;
2683 struct symtab_and_line sal
;
2684 struct expression
*exp
;
2685 struct block
*exp_valid_block
;
2686 struct value
*val
, *mark
;
2687 struct frame_info
*frame
;
2688 struct frame_info
*prev_frame
= NULL
;
2689 char *exp_start
= NULL
;
2690 char *exp_end
= NULL
;
2691 char *tok
, *end_tok
;
2693 char *cond_start
= NULL
;
2694 char *cond_end
= NULL
;
2695 struct expression
*cond
= NULL
;
2696 int i
, other_type_used
, target_resources_ok
= 0;
2697 enum bptype bp_type
;
2700 INIT_SAL (&sal
); /* initialize to zeroes */
2702 /* Parse arguments. */
2703 innermost_block
= NULL
;
2705 exp
= parse_exp_1 (&arg
, 0, 0);
2707 exp_valid_block
= innermost_block
;
2708 mark
= value_mark ();
2709 val
= evaluate_expression (exp
);
2710 release_value (val
);
2711 if (VALUE_LAZY (val
))
2712 value_fetch_lazy (val
);
2715 while (*tok
== ' ' || *tok
== '\t')
2719 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
2722 toklen
= end_tok
- tok
;
2723 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
2725 tok
= cond_start
= end_tok
+ 1;
2726 cond
= parse_exp_1 (&tok
, 0, 0);
2730 error("Junk at end of command.");
2732 if (accessflag
== 1) bp_type
= bp_read_watchpoint
;
2733 else if (accessflag
== 2) bp_type
= bp_access_watchpoint
;
2734 else bp_type
= bp_hardware_watchpoint
;
2736 mem_cnt
= can_use_hardware_watchpoint (val
);
2737 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
2738 error ("Expression cannot be implemented with read/access watchpoint.");
2740 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
2741 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
2742 bp_type
, i
+ mem_cnt
, other_type_used
);
2743 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
2744 error ("Target does not have this type of hardware watchpoint support.");
2745 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
2746 error ("Target resources have been allocated for other types of watchpoints.");
2749 /* Now set up the breakpoint. */
2750 b
= set_raw_breakpoint (sal
);
2751 set_breakpoint_count (breakpoint_count
+ 1);
2752 b
->number
= breakpoint_count
;
2753 b
->disposition
= donttouch
;
2755 b
->exp_valid_block
= exp_valid_block
;
2756 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
2760 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
2764 frame
= block_innermost_frame (exp_valid_block
);
2767 prev_frame
= get_prev_frame (frame
);
2768 b
->watchpoint_frame
= frame
->frame
;
2771 b
->watchpoint_frame
= (CORE_ADDR
)0;
2773 if (mem_cnt
&& target_resources_ok
> 0)
2776 b
->type
= bp_watchpoint
;
2778 /* If the expression is "local", then set up a "watchpoint scope"
2779 breakpoint at the point where we've left the scope of the watchpoint
2781 if (innermost_block
)
2785 struct breakpoint
*scope_breakpoint
;
2786 struct symtab_and_line scope_sal
;
2788 INIT_SAL (&scope_sal
); /* initialize to zeroes */
2789 scope_sal
.pc
= get_frame_pc (prev_frame
);
2790 scope_sal
.section
= find_pc_overlay (scope_sal
.pc
);
2792 scope_breakpoint
= set_raw_breakpoint (scope_sal
);
2793 set_breakpoint_count (breakpoint_count
+ 1);
2794 scope_breakpoint
->number
= breakpoint_count
;
2796 scope_breakpoint
->type
= bp_watchpoint_scope
;
2797 scope_breakpoint
->enable
= enabled
;
2799 /* Automatically delete the breakpoint when it hits. */
2800 scope_breakpoint
->disposition
= del
;
2802 /* Only break in the proper frame (help with recursion). */
2803 scope_breakpoint
->frame
= prev_frame
->frame
;
2805 /* Set the address at which we will stop. */
2806 scope_breakpoint
->address
= get_frame_pc (prev_frame
);
2808 /* The scope breakpoint is related to the watchpoint. We
2809 will need to act on them together. */
2810 b
->related_breakpoint
= scope_breakpoint
;
2813 value_free_to_mark (mark
);
2817 /* Return count of locations need to be watched and can be handled
2818 in hardware. If the watchpoint can not be handled
2819 in hardware return zero. */
2822 can_use_hardware_watchpoint (v
)
2825 int found_memory_cnt
= 0;
2827 /* Make sure all the intermediate values are in memory. Also make sure
2828 we found at least one memory expression. Guards against watch 0x12345,
2829 which is meaningless, but could cause errors if one tries to insert a
2830 hardware watchpoint for the constant expression. */
2831 for ( ; v
; v
= v
->next
)
2833 if (v
->lval
== lval_memory
)
2835 if (TYPE_LENGTH (VALUE_TYPE (v
)) <= REGISTER_SIZE
)
2838 else if (v
->lval
!= not_lval
&& v
->modifiable
== 0)
2842 /* The expression itself looks suitable for using a hardware
2843 watchpoint, but give the target machine a chance to reject it. */
2844 return found_memory_cnt
;
2847 static void watch_command (arg
, from_tty
)
2851 watch_command_1 (arg
, 0, from_tty
);
2854 static void rwatch_command (arg
, from_tty
)
2858 watch_command_1 (arg
, 1, from_tty
);
2861 static void awatch_command (arg
, from_tty
)
2865 watch_command_1 (arg
, 2, from_tty
);
2869 /* Helper routine for the until_command routine in infcmd.c. Here
2870 because it uses the mechanisms of breakpoints. */
2874 until_break_command (arg
, from_tty
)
2878 struct symtabs_and_lines sals
;
2879 struct symtab_and_line sal
;
2880 struct frame_info
*prev_frame
= get_prev_frame (selected_frame
);
2881 struct breakpoint
*breakpoint
;
2882 struct cleanup
*old_chain
;
2884 clear_proceed_status ();
2886 /* Set a breakpoint where the user wants it and at return from
2889 if (default_breakpoint_valid
)
2890 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
2891 default_breakpoint_line
, (char ***)NULL
);
2893 sals
= decode_line_1 (&arg
, 1, (struct symtab
*)NULL
, 0, (char ***)NULL
);
2895 if (sals
.nelts
!= 1)
2896 error ("Couldn't get information on specified line.");
2899 free ((PTR
)sals
.sals
); /* malloc'd, so freed */
2902 error ("Junk at end of arguments.");
2904 resolve_sal_pc (&sal
);
2906 breakpoint
= set_momentary_breakpoint (sal
, selected_frame
, bp_until
);
2908 old_chain
= make_cleanup ((make_cleanup_func
) delete_breakpoint
, breakpoint
);
2910 /* Keep within the current frame */
2914 sal
= find_pc_line (prev_frame
->pc
, 0);
2915 sal
.pc
= prev_frame
->pc
;
2916 breakpoint
= set_momentary_breakpoint (sal
, prev_frame
, bp_until
);
2917 make_cleanup ((make_cleanup_func
) delete_breakpoint
, breakpoint
);
2920 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
2921 do_cleanups(old_chain
);
2925 /* These aren't used; I don't konw what they were for. */
2926 /* Set a breakpoint at the catch clause for NAME. */
2928 catch_breakpoint (name
)
2934 disable_catch_breakpoint ()
2939 delete_catch_breakpoint ()
2944 enable_catch_breakpoint ()
2951 struct sal_chain
*next
;
2952 struct symtab_and_line sal
;
2956 /* This isn't used; I don't know what it was for. */
2957 /* For each catch clause identified in ARGS, run FUNCTION
2958 with that clause as an argument. */
2959 static struct symtabs_and_lines
2960 map_catch_names (args
, function
)
2964 register char *p
= args
;
2966 struct symtabs_and_lines sals
;
2968 struct sal_chain
*sal_chain
= 0;
2972 error_no_arg ("one or more catch names");
2980 /* Don't swallow conditional part. */
2981 if (p1
[0] == 'i' && p1
[1] == 'f'
2982 && (p1
[2] == ' ' || p1
[2] == '\t'))
2988 while (isalnum (*p1
) || *p1
== '_' || *p1
== '$')
2992 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
2993 error ("Arguments must be catch names.");
2999 struct sal_chain
*next
= (struct sal_chain
*)
3000 alloca (sizeof (struct sal_chain
));
3001 next
->next
= sal_chain
;
3002 next
->sal
= get_catch_sal (p
);
3007 printf_unfiltered ("No catch clause for exception %s.\n", p
);
3012 while (*p
== ' ' || *p
== '\t') p
++;
3017 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
3019 static struct symtabs_and_lines
3020 get_catch_sals (this_level_only
)
3021 int this_level_only
;
3023 register struct blockvector
*bl
;
3024 register struct block
*block
;
3025 int index
, have_default
= 0;
3027 struct symtabs_and_lines sals
;
3028 struct sal_chain
*sal_chain
= 0;
3029 char *blocks_searched
;
3031 /* Not sure whether an error message is always the correct response,
3032 but it's better than a core dump. */
3033 if (selected_frame
== NULL
)
3034 error ("No selected frame.");
3035 block
= get_frame_block (selected_frame
);
3036 pc
= selected_frame
->pc
;
3042 error ("No symbol table info available.\n");
3044 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
3045 blocks_searched
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
3046 memset (blocks_searched
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
3050 CORE_ADDR end
= BLOCK_END (block
) - 4;
3053 if (bl
!= blockvector_for_pc (end
, &index
))
3054 error ("blockvector blotch");
3055 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
3056 error ("blockvector botch");
3057 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
3060 /* Don't print out blocks that have gone by. */
3061 while (index
< last_index
3062 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
3065 while (index
< last_index
3066 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
3068 if (blocks_searched
[index
] == 0)
3070 struct block
*b
= BLOCKVECTOR_BLOCK (bl
, index
);
3073 register struct symbol
*sym
;
3075 nsyms
= BLOCK_NSYMS (b
);
3077 for (i
= 0; i
< nsyms
; i
++)
3079 sym
= BLOCK_SYM (b
, i
);
3080 if (STREQ (SYMBOL_NAME (sym
), "default"))
3086 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
3088 struct sal_chain
*next
= (struct sal_chain
*)
3089 alloca (sizeof (struct sal_chain
));
3090 next
->next
= sal_chain
;
3091 next
->sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
3095 blocks_searched
[index
] = 1;
3101 if (sal_chain
&& this_level_only
)
3104 /* After handling the function's top-level block, stop.
3105 Don't continue to its superblock, the block of
3106 per-file symbols. */
3107 if (BLOCK_FUNCTION (block
))
3109 block
= BLOCK_SUPERBLOCK (block
);
3114 struct sal_chain
*tmp_chain
;
3116 /* Count the number of entries. */
3117 for (index
= 0, tmp_chain
= sal_chain
; tmp_chain
;
3118 tmp_chain
= tmp_chain
->next
)
3122 sals
.sals
= (struct symtab_and_line
*)
3123 xmalloc (index
* sizeof (struct symtab_and_line
));
3124 for (index
= 0; sal_chain
; sal_chain
= sal_chain
->next
, index
++)
3125 sals
.sals
[index
] = sal_chain
->sal
;
3131 /* Commands to deal with catching exceptions. */
3134 catch_command_1 (arg
, tempflag
, from_tty
)
3139 /* First, translate ARG into something we can deal with in terms
3142 struct symtabs_and_lines sals
;
3143 struct symtab_and_line sal
;
3144 register struct expression
*cond
= 0;
3145 register struct breakpoint
*b
;
3149 INIT_SAL (&sal
); /* initialize to zeroes */
3151 /* If no arg given, or if first arg is 'if ', all active catch clauses
3152 are breakpointed. */
3154 if (!arg
|| (arg
[0] == 'i' && arg
[1] == 'f'
3155 && (arg
[2] == ' ' || arg
[2] == '\t')))
3157 /* Grab all active catch clauses. */
3158 sals
= get_catch_sals (0);
3162 /* Grab selected catch clauses. */
3163 error ("catch NAME not implemented");
3165 /* This isn't used; I don't know what it was for. */
3166 sals
= map_catch_names (arg
, catch_breakpoint
);
3174 for (i
= 0; i
< sals
.nelts
; i
++)
3176 resolve_sal_pc (&sals
.sals
[i
]);
3180 if (arg
[0] == 'i' && arg
[1] == 'f'
3181 && (arg
[2] == ' ' || arg
[2] == '\t'))
3182 cond
= parse_exp_1 ((arg
+= 2, &arg
),
3183 block_for_pc (sals
.sals
[i
].pc
), 0);
3185 error ("Junk at end of arguments.");
3190 for (i
= 0; i
< sals
.nelts
; i
++)
3195 describe_other_breakpoints (sal
.pc
, sal
.section
);
3197 b
= set_raw_breakpoint (sal
);
3198 set_breakpoint_count (breakpoint_count
+ 1);
3199 b
->number
= breakpoint_count
;
3200 b
->type
= bp_breakpoint
;
3202 b
->enable
= enabled
;
3203 b
->disposition
= tempflag
? del
: donttouch
;
3210 printf_unfiltered ("Multiple breakpoints were set.\n");
3211 printf_unfiltered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
3213 free ((PTR
)sals
.sals
);
3216 /* Used by the gui, could be made a worker for other things. */
3219 set_breakpoint_sal (sal
)
3220 struct symtab_and_line sal
;
3222 struct breakpoint
*b
;
3223 b
= set_raw_breakpoint (sal
);
3224 set_breakpoint_count (breakpoint_count
+ 1);
3225 b
->number
= breakpoint_count
;
3226 b
->type
= bp_breakpoint
;
3233 /* These aren't used; I don't know what they were for. */
3234 /* Disable breakpoints on all catch clauses described in ARGS. */
3236 disable_catch (args
)
3239 /* Map the disable command to catch clauses described in ARGS. */
3242 /* Enable breakpoints on all catch clauses described in ARGS. */
3247 /* Map the disable command to catch clauses described in ARGS. */
3250 /* Delete breakpoints on all catch clauses in the active scope. */
3255 /* Map the delete command to catch clauses described in ARGS. */
3260 catch_command (arg
, from_tty
)
3264 catch_command_1 (arg
, 0, from_tty
);
3268 clear_command (arg
, from_tty
)
3272 register struct breakpoint
*b
, *b1
;
3273 struct symtabs_and_lines sals
;
3274 struct symtab_and_line sal
;
3275 register struct breakpoint
*found
;
3280 sals
= decode_line_spec (arg
, 1);
3284 sals
.sals
= (struct symtab_and_line
*)
3285 xmalloc (sizeof (struct symtab_and_line
));
3286 INIT_SAL (&sal
); /* initialize to zeroes */
3287 sal
.line
= default_breakpoint_line
;
3288 sal
.symtab
= default_breakpoint_symtab
;
3289 if (sal
.symtab
== 0)
3290 error ("No source file specified.");
3296 for (i
= 0; i
< sals
.nelts
; i
++)
3298 /* If exact pc given, clear bpts at that pc.
3299 But if sal.pc is zero, clear all bpts on specified line. */
3301 found
= (struct breakpoint
*) 0;
3303 while (breakpoint_chain
3305 ? (breakpoint_chain
->address
== sal
.pc
&&
3306 (overlay_debugging
== 0 ||
3307 breakpoint_chain
->section
== sal
.section
))
3308 : (breakpoint_chain
->source_file
!= NULL
3309 && sal
.symtab
!= NULL
3310 && STREQ (breakpoint_chain
->source_file
,
3311 sal
.symtab
->filename
)
3312 && breakpoint_chain
->line_number
== sal
.line
)))
3314 b1
= breakpoint_chain
;
3315 breakpoint_chain
= b1
->next
;
3322 && b
->next
->type
!= bp_watchpoint
3323 && b
->next
->type
!= bp_hardware_watchpoint
3324 && b
->next
->type
!= bp_read_watchpoint
3325 && b
->next
->type
!= bp_access_watchpoint
3327 ? (b
->next
->address
== sal
.pc
&&
3328 (overlay_debugging
== 0 ||
3329 b
->next
->section
== sal
.section
))
3330 : (b
->next
->source_file
!= NULL
3331 && sal
.symtab
!= NULL
3332 && STREQ (b
->next
->source_file
, sal
.symtab
->filename
)
3333 && b
->next
->line_number
== sal
.line
)))
3344 error ("No breakpoint at %s.", arg
);
3346 error ("No breakpoint at this line.");
3349 if (found
->next
) from_tty
= 1; /* Always report if deleted more than one */
3350 if (from_tty
) printf_unfiltered ("Deleted breakpoint%s ", found
->next
? "s" : "");
3351 breakpoints_changed ();
3354 if (from_tty
) printf_unfiltered ("%d ", found
->number
);
3356 delete_breakpoint (found
);
3359 if (from_tty
) putchar_unfiltered ('\n');
3361 free ((PTR
)sals
.sals
);
3364 /* Delete breakpoint in BS if they are `delete' breakpoints and
3365 all breakpoints that are marked for deletion, whether hit or not.
3366 This is called after any breakpoint is hit, or after errors. */
3369 breakpoint_auto_delete (bs
)
3372 struct breakpoint
*b
, *temp
;
3374 for (; bs
; bs
= bs
->next
)
3375 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== del
3377 delete_breakpoint (bs
->breakpoint_at
);
3379 ALL_BREAKPOINTS_SAFE (b
, temp
)
3381 if (b
->disposition
== del_at_next_stop
)
3382 delete_breakpoint (b
);
3386 /* Delete a breakpoint and clean up all traces of it in the data structures. */
3389 delete_breakpoint (bpt
)
3390 struct breakpoint
*bpt
;
3392 register struct breakpoint
*b
;
3395 if (delete_breakpoint_hook
)
3396 delete_breakpoint_hook (bpt
);
3399 remove_breakpoint (bpt
);
3401 if (breakpoint_chain
== bpt
)
3402 breakpoint_chain
= bpt
->next
;
3407 b
->next
= bpt
->next
;
3411 check_duplicates (bpt
->address
, bpt
->section
);
3412 /* If this breakpoint was inserted, and there is another breakpoint
3413 at the same address, we need to insert the other breakpoint. */
3415 && bpt
->type
!= bp_hardware_watchpoint
3416 && bpt
->type
!= bp_read_watchpoint
3417 && bpt
->type
!= bp_access_watchpoint
)
3420 if (b
->address
== bpt
->address
3421 && b
->section
== bpt
->section
3423 && b
->enable
!= disabled
3424 && b
->enable
!= shlib_disabled
)
3427 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
3430 target_terminal_ours_for_output ();
3431 fprintf_unfiltered (gdb_stderr
, "Cannot insert breakpoint %d:\n", b
->number
);
3432 memory_error (val
, b
->address
); /* which bombs us out */
3439 free_command_lines (&bpt
->commands
);
3442 if (bpt
->cond_string
!= NULL
)
3443 free (bpt
->cond_string
);
3444 if (bpt
->addr_string
!= NULL
)
3445 free (bpt
->addr_string
);
3446 if (bpt
->exp
!= NULL
)
3448 if (bpt
->exp_string
!= NULL
)
3449 free (bpt
->exp_string
);
3450 if (bpt
->val
!= NULL
)
3451 value_free (bpt
->val
);
3452 if (bpt
->source_file
!= NULL
)
3453 free (bpt
->source_file
);
3455 /* Be sure no bpstat's are pointing at it after it's been freed. */
3456 /* FIXME, how can we find all bpstat's?
3457 We just check stop_bpstat for now. */
3458 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
3459 if (bs
->breakpoint_at
== bpt
)
3460 bs
->breakpoint_at
= NULL
;
3465 delete_command (arg
, from_tty
)
3469 struct breakpoint
*b
, *temp
;
3473 int breaks_to_delete
= 0;
3475 /* Delete all breakpoints if no argument.
3476 Do not delete internal or call-dummy breakpoints, these
3477 have to be deleted with an explicit breakpoint number argument. */
3480 if (b
->type
!= bp_call_dummy
&& b
->number
>= 0)
3481 breaks_to_delete
= 1;
3484 /* Ask user only if there are some breakpoints to delete. */
3486 || (breaks_to_delete
&& query ("Delete all breakpoints? ")))
3488 ALL_BREAKPOINTS_SAFE (b
, temp
)
3490 if (b
->type
!= bp_call_dummy
&& b
->number
>= 0)
3491 delete_breakpoint (b
);
3496 map_breakpoint_numbers (arg
, delete_breakpoint
);
3499 /* Reset a breakpoint given it's struct breakpoint * BINT.
3500 The value we return ends up being the return value from catch_errors.
3501 Unused in this case. */
3504 breakpoint_re_set_one (bint
)
3507 struct breakpoint
*b
= (struct breakpoint
*)bint
; /* get past catch_errs */
3510 struct symtabs_and_lines sals
;
3512 enum enable save_enable
;
3517 case bp_hardware_breakpoint
:
3518 if (b
->addr_string
== NULL
)
3520 /* Anything without a string can't be re-set. */
3521 delete_breakpoint (b
);
3524 /* In case we have a problem, disable this breakpoint. We'll restore
3525 its status if we succeed. */
3526 save_enable
= b
->enable
;
3527 b
->enable
= disabled
;
3529 set_language (b
->language
);
3530 input_radix
= b
->input_radix
;
3532 sals
= decode_line_1 (&s
, 1, (struct symtab
*)NULL
, 0, (char ***)NULL
);
3533 for (i
= 0; i
< sals
.nelts
; i
++)
3535 resolve_sal_pc (&sals
.sals
[i
]);
3537 /* Reparse conditions, they might contain references to the
3539 if (b
->cond_string
!= NULL
)
3543 free ((PTR
)b
->cond
);
3544 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
3547 /* We need to re-set the breakpoint if the address changes...*/
3548 if (b
->address
!= sals
.sals
[i
].pc
3549 /* ...or new and old breakpoints both have source files, and
3550 the source file name or the line number changes... */
3551 || (b
->source_file
!= NULL
3552 && sals
.sals
[i
].symtab
!= NULL
3553 && (!STREQ (b
->source_file
, sals
.sals
[i
].symtab
->filename
)
3554 || b
->line_number
!= sals
.sals
[i
].line
)
3556 /* ...or we switch between having a source file and not having
3558 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
3561 if (b
->source_file
!= NULL
)
3562 free (b
->source_file
);
3563 if (sals
.sals
[i
].symtab
== NULL
)
3564 b
->source_file
= NULL
;
3567 savestring (sals
.sals
[i
].symtab
->filename
,
3568 strlen (sals
.sals
[i
].symtab
->filename
));
3569 b
->line_number
= sals
.sals
[i
].line
;
3570 b
->address
= sals
.sals
[i
].pc
;
3571 check_duplicates (b
->address
, b
->section
);
3575 /* Might be better to do this just once per breakpoint_re_set,
3576 rather than once for every breakpoint. */
3577 breakpoints_changed ();
3579 b
->section
= sals
.sals
[i
].section
;
3580 b
->enable
= save_enable
; /* Restore it, this worked. */
3582 free ((PTR
)sals
.sals
);
3586 case bp_hardware_watchpoint
:
3587 case bp_read_watchpoint
:
3588 case bp_access_watchpoint
:
3589 innermost_block
= NULL
;
3590 /* The issue arises of what context to evaluate this in. The same
3591 one as when it was set, but what does that mean when symbols have
3592 been re-read? We could save the filename and functionname, but
3593 if the context is more local than that, the best we could do would
3594 be something like how many levels deep and which index at that
3595 particular level, but that's going to be less stable than filenames
3596 or functionnames. */
3597 /* So for now, just use a global context. */
3600 b
->exp
= parse_expression (b
->exp_string
);
3601 b
->exp_valid_block
= innermost_block
;
3602 mark
= value_mark ();
3604 value_free (b
->val
);
3605 b
->val
= evaluate_expression (b
->exp
);
3606 release_value (b
->val
);
3607 if (VALUE_LAZY (b
->val
))
3608 value_fetch_lazy (b
->val
);
3610 if (b
->cond_string
!= NULL
)
3614 free ((PTR
)b
->cond
);
3615 b
->cond
= parse_exp_1 (&s
, (struct block
*)0, 0);
3617 if (b
->enable
== enabled
)
3619 value_free_to_mark (mark
);
3623 printf_filtered ("Deleting unknown breakpoint type %d\n", b
->type
);
3625 /* Delete longjmp breakpoints, they will be reset later by
3626 breakpoint_re_set. */
3628 case bp_longjmp_resume
:
3629 delete_breakpoint (b
);
3632 /* This breakpoint is special, it's set up when the inferior
3633 starts and we really don't want to touch it. */
3634 case bp_shlib_event
:
3636 /* Keep temporary breakpoints, which can be encountered when we step
3637 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
3638 Otherwise these should have been blown away via the cleanup chain
3639 or by breakpoint_init_inferior when we rerun the executable. */
3642 case bp_watchpoint_scope
:
3644 case bp_step_resume
:
3651 /* Re-set all breakpoints after symbols have been re-loaded. */
3653 breakpoint_re_set ()
3655 struct breakpoint
*b
, *temp
;
3656 enum language save_language
;
3657 int save_input_radix
;
3658 static char message1
[] = "Error in re-setting breakpoint %d:\n";
3659 char message
[sizeof (message1
) + 30 /* slop */];
3661 save_language
= current_language
->la_language
;
3662 save_input_radix
= input_radix
;
3663 ALL_BREAKPOINTS_SAFE (b
, temp
)
3665 sprintf (message
, message1
, b
->number
); /* Format possible error msg */
3666 catch_errors (breakpoint_re_set_one
, (char *) b
, message
,
3669 set_language (save_language
);
3670 input_radix
= save_input_radix
;
3672 #ifdef GET_LONGJMP_TARGET
3673 create_longjmp_breakpoint ("longjmp");
3674 create_longjmp_breakpoint ("_longjmp");
3675 create_longjmp_breakpoint ("siglongjmp");
3676 create_longjmp_breakpoint ("_siglongjmp");
3677 create_longjmp_breakpoint (NULL
);
3681 /* Took this out (temporarily at least), since it produces an extra
3682 blank line at startup. This messes up the gdbtests. -PB */
3683 /* Blank line to finish off all those mention() messages we just printed. */
3684 printf_filtered ("\n");
3688 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
3689 If from_tty is nonzero, it prints a message to that effect,
3690 which ends with a period (no newline). */
3693 set_ignore_count (bptnum
, count
, from_tty
)
3694 int bptnum
, count
, from_tty
;
3696 register struct breakpoint
*b
;
3702 if (b
->number
== bptnum
)
3704 b
->ignore_count
= count
;
3707 else if (count
== 0)
3708 printf_filtered ("Will stop next time breakpoint %d is reached.",
3710 else if (count
== 1)
3711 printf_filtered ("Will ignore next crossing of breakpoint %d.",
3714 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
3716 breakpoints_changed ();
3720 error ("No breakpoint number %d.", bptnum
);
3723 /* Clear the ignore counts of all breakpoints. */
3725 breakpoint_clear_ignore_counts ()
3727 struct breakpoint
*b
;
3730 b
->ignore_count
= 0;
3733 /* Command to set ignore-count of breakpoint N to COUNT. */
3736 ignore_command (args
, from_tty
)
3744 error_no_arg ("a breakpoint number");
3746 num
= get_number (&p
);
3749 error ("Second argument (specified ignore-count) is missing.");
3751 set_ignore_count (num
,
3752 longest_to_int (value_as_long (parse_and_eval (p
))),
3754 printf_filtered ("\n");
3755 breakpoints_changed ();
3758 /* Call FUNCTION on each of the breakpoints
3759 whose numbers are given in ARGS. */
3762 map_breakpoint_numbers (args
, function
)
3764 void (*function
) PARAMS ((struct breakpoint
*));
3766 register char *p
= args
;
3769 register struct breakpoint
*b
;
3772 error_no_arg ("one or more breakpoint numbers");
3778 num
= get_number (&p1
);
3781 if (b
->number
== num
)
3783 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
3785 if (related_breakpoint
)
3786 function (related_breakpoint
);
3789 printf_unfiltered ("No breakpoint number %d.\n", num
);
3796 disable_breakpoint (bpt
)
3797 struct breakpoint
*bpt
;
3799 /* Never disable a watchpoint scope breakpoint; we want to
3800 hit them when we leave scope so we can delete both the
3801 watchpoint and its scope breakpoint at that time. */
3802 if (bpt
->type
== bp_watchpoint_scope
)
3805 bpt
->enable
= disabled
;
3807 check_duplicates (bpt
->address
, bpt
->section
);
3809 if (modify_breakpoint_hook
)
3810 modify_breakpoint_hook (bpt
);
3815 disable_command (args
, from_tty
)
3819 register struct breakpoint
*bpt
;
3821 ALL_BREAKPOINTS (bpt
)
3825 case bp_hardware_breakpoint
:
3827 case bp_hardware_watchpoint
:
3828 case bp_read_watchpoint
:
3829 case bp_access_watchpoint
:
3830 disable_breakpoint (bpt
);
3835 map_breakpoint_numbers (args
, disable_breakpoint
);
3839 do_enable_breakpoint (bpt
, disposition
)
3840 struct breakpoint
*bpt
;
3841 enum bpdisp disposition
;
3843 struct frame_info
*save_selected_frame
= NULL
;
3844 int save_selected_frame_level
= -1;
3845 int target_resources_ok
, other_type_used
;
3848 if (bpt
->type
== bp_hardware_breakpoint
)
3851 i
= hw_breakpoint_used_count();
3852 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3853 bp_hardware_breakpoint
, i
+1, 0);
3854 if (target_resources_ok
== 0)
3855 error ("No hardware breakpoint support in the target.");
3856 else if (target_resources_ok
< 0)
3857 error ("Hardware breakpoints used exceeds limit.");
3860 bpt
->enable
= enabled
;
3861 bpt
->disposition
= disposition
;
3862 check_duplicates (bpt
->address
, bpt
->section
);
3863 breakpoints_changed ();
3865 if (bpt
->type
== bp_watchpoint
|| bpt
->type
== bp_hardware_watchpoint
||
3866 bpt
->type
== bp_read_watchpoint
|| bpt
->type
== bp_access_watchpoint
)
3868 if (bpt
->exp_valid_block
!= NULL
)
3870 struct frame_info
*fr
=
3871 find_frame_addr_in_frame_chain (bpt
->watchpoint_frame
);
3875 Cannot enable watchpoint %d because the block in which its expression\n\
3876 is valid is not currently in scope.\n", bpt
->number
);
3877 bpt
->enable
= disabled
;
3881 save_selected_frame
= selected_frame
;
3882 save_selected_frame_level
= selected_frame_level
;
3883 select_frame (fr
, -1);
3886 value_free (bpt
->val
);
3887 mark
= value_mark ();
3888 bpt
->val
= evaluate_expression (bpt
->exp
);
3889 release_value (bpt
->val
);
3890 if (VALUE_LAZY (bpt
->val
))
3891 value_fetch_lazy (bpt
->val
);
3893 if (bpt
->type
== bp_hardware_watchpoint
||
3894 bpt
->type
== bp_read_watchpoint
||
3895 bpt
->type
== bp_access_watchpoint
)
3897 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
3898 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
3900 /* Hack around 'unused var' error for some targets here */
3902 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3903 bpt
->type
, i
+ mem_cnt
, other_type_used
);
3904 /* we can consider of type is bp_hardware_watchpoint, convert to
3905 bp_watchpoint in the following condition */
3906 if (target_resources_ok
< 0)
3909 Cannot enable watchpoint %d because target watch resources\n\
3910 have been allocated for other watchpoints.\n", bpt
->number
);
3911 bpt
->enable
= disabled
;
3912 value_free_to_mark (mark
);
3917 if (save_selected_frame_level
>= 0)
3918 select_frame (save_selected_frame
, save_selected_frame_level
);
3919 value_free_to_mark (mark
);
3921 if (modify_breakpoint_hook
)
3922 modify_breakpoint_hook (bpt
);
3926 enable_breakpoint (bpt
)
3927 struct breakpoint
*bpt
;
3929 do_enable_breakpoint (bpt
, bpt
->disposition
);
3932 /* The enable command enables the specified breakpoints (or all defined
3933 breakpoints) so they once again become (or continue to be) effective
3934 in stopping the inferior. */
3938 enable_command (args
, from_tty
)
3942 register struct breakpoint
*bpt
;
3944 ALL_BREAKPOINTS (bpt
)
3948 case bp_hardware_breakpoint
:
3950 case bp_hardware_watchpoint
:
3951 case bp_read_watchpoint
:
3952 case bp_access_watchpoint
:
3953 enable_breakpoint (bpt
);
3958 map_breakpoint_numbers (args
, enable_breakpoint
);
3962 enable_once_breakpoint (bpt
)
3963 struct breakpoint
*bpt
;
3965 do_enable_breakpoint (bpt
, disable
);
3970 enable_once_command (args
, from_tty
)
3974 map_breakpoint_numbers (args
, enable_once_breakpoint
);
3978 enable_delete_breakpoint (bpt
)
3979 struct breakpoint
*bpt
;
3981 do_enable_breakpoint (bpt
, del
);
3986 enable_delete_command (args
, from_tty
)
3990 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
3993 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
3995 struct symtabs_and_lines
3996 decode_line_spec_1 (string
, funfirstline
)
4000 struct symtabs_and_lines sals
;
4002 error ("Empty line specification.");
4003 if (default_breakpoint_valid
)
4004 sals
= decode_line_1 (&string
, funfirstline
,
4005 default_breakpoint_symtab
, default_breakpoint_line
,
4008 sals
= decode_line_1 (&string
, funfirstline
,
4009 (struct symtab
*)NULL
, 0, (char ***)NULL
);
4011 error ("Junk at end of line specification: %s", string
);
4016 _initialize_breakpoint ()
4018 breakpoint_chain
= 0;
4019 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
4020 before a breakpoint is set. */
4021 breakpoint_count
= 0;
4023 add_com ("ignore", class_breakpoint
, ignore_command
,
4024 "Set ignore-count of breakpoint number N to COUNT.\n\
4025 Usage is `ignore N COUNT'.");
4027 add_com ("commands", class_breakpoint
, commands_command
,
4028 "Set commands to be executed when a breakpoint is hit.\n\
4029 Give breakpoint number as argument after \"commands\".\n\
4030 With no argument, the targeted breakpoint is the last one set.\n\
4031 The commands themselves follow starting on the next line.\n\
4032 Type a line containing \"end\" to indicate the end of them.\n\
4033 Give \"silent\" as the first line to make the breakpoint silent;\n\
4034 then no output is printed when it is hit, except what the commands print.");
4036 add_com ("condition", class_breakpoint
, condition_command
,
4037 "Specify breakpoint number N to break only if COND is true.\n\
4038 Usage is `condition N COND', where N is an integer and COND is an\n\
4039 expression to be evaluated whenever breakpoint N is reached. ");
4041 add_com ("tbreak", class_breakpoint
, tbreak_command
,
4042 "Set a temporary breakpoint. Args like \"break\" command.\n\
4043 Like \"break\" except the breakpoint is only temporary,\n\
4044 so it will be deleted when hit. Equivalent to \"break\" followed\n\
4045 by using \"enable delete\" on the breakpoint number.");
4047 add_com ("hbreak", class_breakpoint
, hbreak_command
,
4048 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
4049 Like \"break\" except the breakpoint requires hardware support,\n\
4050 some target hardware may not have this support.");
4052 add_com ("thbreak", class_breakpoint
, thbreak_command
,
4053 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
4054 Like \"hbreak\" except the breakpoint is only temporary,\n\
4055 so it will be deleted when hit.");
4057 add_prefix_cmd ("enable", class_breakpoint
, enable_command
,
4058 "Enable some breakpoints.\n\
4059 Give breakpoint numbers (separated by spaces) as arguments.\n\
4060 With no subcommand, breakpoints are enabled until you command otherwise.\n\
4061 This is used to cancel the effect of the \"disable\" command.\n\
4062 With a subcommand you can enable temporarily.",
4063 &enablelist
, "enable ", 1, &cmdlist
);
4065 add_com_alias ("en", "enable", class_breakpoint
, 1);
4067 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
,
4068 "Enable some breakpoints.\n\
4069 Give breakpoint numbers (separated by spaces) as arguments.\n\
4070 This is used to cancel the effect of the \"disable\" command.\n\
4071 May be abbreviated to simply \"enable\".\n",
4072 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
4074 add_cmd ("once", no_class
, enable_once_command
,
4075 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
4076 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
4079 add_cmd ("delete", no_class
, enable_delete_command
,
4080 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
4081 If a breakpoint is hit while enabled in this fashion, it is deleted.",
4084 add_cmd ("delete", no_class
, enable_delete_command
,
4085 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
4086 If a breakpoint is hit while enabled in this fashion, it is deleted.",
4089 add_cmd ("once", no_class
, enable_once_command
,
4090 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
4091 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
4094 add_prefix_cmd ("disable", class_breakpoint
, disable_command
,
4095 "Disable some breakpoints.\n\
4096 Arguments are breakpoint numbers with spaces in between.\n\
4097 To disable all breakpoints, give no argument.\n\
4098 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
4099 &disablelist
, "disable ", 1, &cmdlist
);
4100 add_com_alias ("dis", "disable", class_breakpoint
, 1);
4101 add_com_alias ("disa", "disable", class_breakpoint
, 1);
4103 add_cmd ("breakpoints", class_alias
, disable_command
,
4104 "Disable some breakpoints.\n\
4105 Arguments are breakpoint numbers with spaces in between.\n\
4106 To disable all breakpoints, give no argument.\n\
4107 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
4108 This command may be abbreviated \"disable\".",
4111 add_prefix_cmd ("delete", class_breakpoint
, delete_command
,
4112 "Delete some breakpoints or auto-display expressions.\n\
4113 Arguments are breakpoint numbers with spaces in between.\n\
4114 To delete all breakpoints, give no argument.\n\
4116 Also a prefix command for deletion of other GDB objects.\n\
4117 The \"unset\" command is also an alias for \"delete\".",
4118 &deletelist
, "delete ", 1, &cmdlist
);
4119 add_com_alias ("d", "delete", class_breakpoint
, 1);
4121 add_cmd ("breakpoints", class_alias
, delete_command
,
4122 "Delete some breakpoints or auto-display expressions.\n\
4123 Arguments are breakpoint numbers with spaces in between.\n\
4124 To delete all breakpoints, give no argument.\n\
4125 This command may be abbreviated \"delete\".",
4128 add_com ("clear", class_breakpoint
, clear_command
,
4129 concat ("Clear breakpoint at specified line or function.\n\
4130 Argument may be line number, function name, or \"*\" and an address.\n\
4131 If line number is specified, all breakpoints in that line are cleared.\n\
4132 If function is specified, breakpoints at beginning of function are cleared.\n\
4133 If an address is specified, breakpoints at that address are cleared.\n\n",
4134 "With no argument, clears all breakpoints in the line that the selected frame\n\
4137 See also the \"delete\" command which clears breakpoints by number.", NULL
));
4139 add_com ("break", class_breakpoint
, break_command
,
4140 concat ("Set breakpoint at specified line or function.\n\
4141 Argument may be line number, function name, or \"*\" and an address.\n\
4142 If line number is specified, break at start of code for that line.\n\
4143 If function is specified, break at start of code for that function.\n\
4144 If an address is specified, break at that exact address.\n",
4145 "With no arg, uses current execution address of selected stack frame.\n\
4146 This is useful for breaking on return to a stack frame.\n\
4148 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
4150 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL
));
4151 add_com_alias ("b", "break", class_run
, 1);
4152 add_com_alias ("br", "break", class_run
, 1);
4153 add_com_alias ("bre", "break", class_run
, 1);
4154 add_com_alias ("brea", "break", class_run
, 1);
4156 add_info ("breakpoints", breakpoints_info
,
4157 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
4158 The \"Type\" column indicates one of:\n\
4159 \tbreakpoint - normal breakpoint\n\
4160 \twatchpoint - watchpoint\n\
4161 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
4162 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
4163 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
4164 address and file/line number respectively.\n\n",
4165 "Convenience variable \"$_\" and default examine address for \"x\"\n\
4166 are set to the address of the last breakpoint listed.\n\n\
4167 Convenience variable \"$bpnum\" contains the number of the last\n\
4168 breakpoint set.", NULL
));
4170 #if MAINTENANCE_CMDS
4172 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
,
4173 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
4174 The \"Type\" column indicates one of:\n\
4175 \tbreakpoint - normal breakpoint\n\
4176 \twatchpoint - watchpoint\n\
4177 \tlongjmp - internal breakpoint used to step through longjmp()\n\
4178 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
4179 \tuntil - internal breakpoint used by the \"until\" command\n\
4180 \tfinish - internal breakpoint used by the \"finish\" command\n",
4181 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
4182 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
4183 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
4184 address and file/line number respectively.\n\n",
4185 "Convenience variable \"$_\" and default examine address for \"x\"\n\
4186 are set to the address of the last breakpoint listed.\n\n\
4187 Convenience variable \"$bpnum\" contains the number of the last\n\
4188 breakpoint set.", NULL
),
4189 &maintenanceinfolist
);
4191 #endif /* MAINTENANCE_CMDS */
4193 add_com ("catch", class_breakpoint
, catch_command
,
4194 "Set breakpoints to catch exceptions that are raised.\n\
4195 Argument may be a single exception to catch, multiple exceptions\n\
4196 to catch, or the default exception \"default\". If no arguments\n\
4197 are given, breakpoints are set at all exception handlers catch clauses\n\
4198 within the current scope.\n\
4200 A condition specified for the catch applies to all breakpoints set\n\
4201 with this command\n\
4203 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
4205 add_com ("watch", class_breakpoint
, watch_command
,
4206 "Set a watchpoint for an expression.\n\
4207 A watchpoint stops execution of your program whenever the value of\n\
4208 an expression changes.");
4210 add_com ("rwatch", class_breakpoint
, rwatch_command
,
4211 "Set a read watchpoint for an expression.\n\
4212 A watchpoint stops execution of your program whenever the value of\n\
4213 an expression is read.");
4215 add_com ("awatch", class_breakpoint
, awatch_command
,
4216 "Set a watchpoint for an expression.\n\
4217 A watchpoint stops execution of your program whenever the value of\n\
4218 an expression is either read or written.");
4220 add_info ("watchpoints", breakpoints_info
,
4221 "Synonym for ``info breakpoints''.");