1 /* Everything about breakpoints, for GDB.
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "breakpoint.h"
26 #include "expression.h"
39 /* local function prototypes */
42 catch_command_1 PARAMS ((char *, int, int));
45 enable_delete_command PARAMS ((char *, int));
48 enable_delete_breakpoint PARAMS ((struct breakpoint *));
51 enable_once_command PARAMS ((char *, int));
54 enable_once_breakpoint PARAMS ((struct breakpoint *));
57 disable_command PARAMS ((char *, int));
60 disable_breakpoint PARAMS ((struct breakpoint *));
63 enable_command PARAMS ((char *, int));
66 enable_breakpoint PARAMS ((struct breakpoint *));
69 map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *)));
72 ignore_command PARAMS ((char *, int));
75 breakpoint_re_set_one PARAMS ((char *));
78 delete_command PARAMS ((char *, int));
81 clear_command PARAMS ((char *, int));
84 catch_command PARAMS ((char *, int));
86 static struct symtabs_and_lines
87 get_catch_sals PARAMS ((int));
90 watch_command PARAMS ((char *, int));
93 can_use_hardware_watchpoint PARAMS ((struct breakpoint *));
96 tbreak_command PARAMS ((char *, int));
99 break_command_1 PARAMS ((char *, int, int));
102 mention PARAMS ((struct breakpoint *));
104 static struct breakpoint *
105 set_raw_breakpoint PARAMS ((struct symtab_and_line));
108 check_duplicates PARAMS ((CORE_ADDR));
111 describe_other_breakpoints PARAMS ((CORE_ADDR));
114 breakpoints_info PARAMS ((char *, int));
117 breakpoint_1 PARAMS ((int, int));
120 bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
123 breakpoint_cond_eval PARAMS ((char *));
126 cleanup_executing_breakpoints PARAMS ((int));
129 commands_command PARAMS ((char *, int));
132 condition_command PARAMS ((char *, int));
135 get_number PARAMS ((char **));
138 set_breakpoint_count PARAMS ((int));
141 remove_breakpoint PARAMS ((struct breakpoint *));
143 extern int addressprint; /* Print machine addresses? */
144 extern int demangle; /* Print de-mangled symbol names? */
146 /* Are we executing breakpoint commands? */
147 static int executing_breakpoint_commands;
149 /* Walk the following statement or block through all breakpoints.
150 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
153 #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
155 #define ALL_BREAKPOINTS_SAFE(b,tmp) \
156 for (b = breakpoint_chain; \
157 b? (tmp=b->next, 1): 0; \
160 /* By default no support for hardware watchpoints is assumed. */
161 #ifndef TARGET_CAN_USE_HARDWARE_WATCHPOINT
162 #define TARGET_CAN_USE_HARDWARE_WATCHPOINT(B) 0
163 #define target_remove_watchpoint(ADDR,LEN) -1
164 #define target_insert_watchpoint(ADDR,LEN) -1
167 /* Chain of all breakpoints defined. */
169 static struct breakpoint *breakpoint_chain;
171 /* Number of last breakpoint made. */
173 static int breakpoint_count;
175 /* Set breakpoint count to NUM. */
177 set_breakpoint_count (num)
180 breakpoint_count = num;
181 set_internalvar (lookup_internalvar ("bpnum"),
182 value_from_longest (builtin_type_int, (LONGEST) num));
185 /* Default address, symtab and line to put a breakpoint at
186 for "break" command with no arg.
187 if default_breakpoint_valid is zero, the other three are
188 not valid, and "break" with no arg is an error.
190 This set by print_stack_frame, which calls set_default_breakpoint. */
192 int default_breakpoint_valid;
193 CORE_ADDR default_breakpoint_address;
194 struct symtab *default_breakpoint_symtab;
195 int default_breakpoint_line;
197 /* Flag indicating extra verbosity for xgdb. */
198 extern int xgdb_verbose;
201 breakpoints_changed ()
203 if (annotation_level > 1)
205 target_terminal_ours ();
206 printf_unfiltered ("\n\032\032breakpoints-invalid\n");
210 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
211 Advance *PP after the string and any trailing whitespace.
213 Currently the string can either be a number or "$" followed by the name
214 of a convenience variable. Making it an expression wouldn't work well
215 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
224 /* Empty line means refer to the last breakpoint. */
225 return breakpoint_count;
228 /* Make a copy of the name, so we can null-terminate it
229 to pass to lookup_internalvar(). */
234 while (isalnum (*p) || *p == '_')
236 varname = (char *) alloca (p - start + 1);
237 strncpy (varname, start, p - start);
238 varname[p - start] = '\0';
239 val = value_of_internalvar (lookup_internalvar (varname));
240 if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
242 "Convenience variables used to specify breakpoints must have integer values."
244 retval = (int) value_as_long (val);
250 while (*p >= '0' && *p <= '9')
253 /* There is no number here. (e.g. "cond a == b"). */
254 error_no_arg ("breakpoint number");
257 if (!(isspace (*p) || *p == '\0'))
258 error ("breakpoint number expected");
265 /* condition N EXP -- set break condition of breakpoint N to EXP. */
268 condition_command (arg, from_tty)
272 register struct breakpoint *b;
277 error_no_arg ("breakpoint number");
280 bnum = get_number (&p);
283 if (b->number == bnum)
290 if (b->cond_string != NULL)
291 free ((PTR)b->cond_string);
296 b->cond_string = NULL;
298 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
303 /* I don't know if it matters whether this is the string the user
304 typed in or the decompiled expression. */
305 b->cond_string = savestring (arg, strlen (arg));
306 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
308 error ("Junk at end of expression");
313 error ("No breakpoint number %d.", bnum);
318 commands_command (arg, from_tty)
322 register struct breakpoint *b;
325 struct command_line *l;
327 /* If we allowed this, we would have problems with when to
328 free the storage, if we change the commands currently
331 if (executing_breakpoint_commands)
332 error ("Can't use the \"commands\" command among a breakpoint's commands.");
335 bnum = get_number (&p);
337 error ("Unexpected extra arguments following breakpoint number.");
340 if (b->number == bnum)
342 if (from_tty && input_from_terminal_p ())
343 printf_filtered ("Type commands for when breakpoint %d is hit, one per line.\n\
344 End with a line saying just \"end\".\n", bnum);
345 l = read_command_lines ();
346 free_command_lines (&b->commands);
348 breakpoints_changed ();
351 error ("No breakpoint number %d.", bnum);
354 extern int memory_breakpoint_size; /* from mem-break.c */
356 /* Like target_read_memory() but if breakpoints are inserted, return
357 the shadow contents instead of the breakpoints themselves.
359 Read "memory data" from whatever target or inferior we have.
360 Returns zero if successful, errno value if not. EIO is used
361 for address out of bounds. If breakpoints are inserted, returns
362 shadow contents, not the breakpoints themselves. From breakpoint.c. */
365 read_memory_nobpt (memaddr, myaddr, len)
371 struct breakpoint *b;
373 if (memory_breakpoint_size < 0)
374 /* No breakpoints on this machine. FIXME: This should be
375 dependent on the debugging target. Probably want
376 target_insert_breakpoint to return a size, saying how many
377 bytes of the shadow contents are used, or perhaps have
378 something like target_xfer_shadow. */
379 return target_read_memory (memaddr, myaddr, len);
383 if (b->type == bp_watchpoint
384 || b->type == bp_hardware_watchpoint
387 else if (b->address + memory_breakpoint_size <= memaddr)
388 /* The breakpoint is entirely before the chunk of memory
391 else if (b->address >= memaddr + len)
392 /* The breakpoint is entirely after the chunk of memory we
397 /* Copy the breakpoint from the shadow contents, and recurse
398 for the things before and after. */
400 /* Addresses and length of the part of the breakpoint that
402 CORE_ADDR membpt = b->address;
403 unsigned int bptlen = memory_breakpoint_size;
404 /* Offset within shadow_contents. */
407 if (membpt < memaddr)
409 /* Only copy the second part of the breakpoint. */
410 bptlen -= memaddr - membpt;
411 bptoffset = memaddr - membpt;
415 if (membpt + bptlen > memaddr + len)
417 /* Only copy the first part of the breakpoint. */
418 bptlen -= (membpt + bptlen) - (memaddr + len);
421 memcpy (myaddr + membpt - memaddr,
422 b->shadow_contents + bptoffset, bptlen);
424 if (membpt > memaddr)
426 /* Copy the section of memory before the breakpoint. */
427 status = read_memory_nobpt (memaddr, myaddr, membpt - memaddr);
432 if (membpt + bptlen < memaddr + len)
434 /* Copy the section of memory after the breakpoint. */
435 status = read_memory_nobpt
437 myaddr + membpt + bptlen - memaddr,
438 memaddr + len - (membpt + bptlen));
445 /* Nothing overlaps. Just call read_memory_noerr. */
446 return target_read_memory (memaddr, myaddr, len);
449 /* insert_breakpoints is used when starting or continuing the program.
450 remove_breakpoints is used when the program stops.
451 Both return zero if successful,
452 or an `errno' value if could not write the inferior. */
455 insert_breakpoints ()
457 register struct breakpoint *b;
459 int disabled_breaks = 0;
462 if (b->type != bp_watchpoint
463 && b->type != bp_hardware_watchpoint
464 && b->enable != disabled
468 val = target_insert_breakpoint(b->address, b->shadow_contents);
471 /* Can't set the breakpoint. */
472 #if defined (DISABLE_UNSETTABLE_BREAK)
473 if (DISABLE_UNSETTABLE_BREAK (b->address))
476 b->enable = disabled;
477 if (!disabled_breaks)
479 target_terminal_ours_for_output ();
480 fprintf_unfiltered (gdb_stderr,
481 "Cannot insert breakpoint %d:\n", b->number);
482 printf_filtered ("Disabling shared library breakpoints:\n");
485 printf_filtered ("%d ", b->number);
490 target_terminal_ours_for_output ();
491 fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number);
492 #ifdef ONE_PROCESS_WRITETEXT
493 fprintf_unfiltered (gdb_stderr,
494 "The same program may be running in another process.\n");
496 memory_error (val, b->address); /* which bombs us out */
502 else if (b->type == bp_hardware_watchpoint
503 && b->enable == enabled
508 int saved_level, within_current_scope;
509 value_ptr mark = value_mark ();
512 /* Save the current frame and level so we can restore it after
513 evaluating the watchpoint expression on its own frame. */
514 saved_frame = selected_frame;
515 saved_level = selected_frame_level;
517 /* Determine if the watchpoint is within scope. */
518 if (b->exp_valid_block == NULL)
519 within_current_scope = 1;
522 FRAME fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
523 within_current_scope = (fr != NULL);
524 if (within_current_scope)
525 select_frame (fr, -1);
528 if (within_current_scope)
530 /* Evaluate the expression and cut the chain of values
531 produced off from the value chain. */
532 v = evaluate_expression (b->exp);
533 value_release_to_mark (mark);
538 /* Look at each value on the value chain. */
539 for ( ; v; v=v->next)
541 /* If it's a memory location, then we must watch it. */
542 if (v->lval == lval_memory)
546 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
547 len = TYPE_LENGTH (VALUE_TYPE (v));
548 val = target_insert_watchpoint (addr, len);
557 /* Failure to insert a watchpoint on any memory value in the
558 value chain brings us here. */
560 warning ("Hardware watchpoint %d: Could not insert watchpoint\n",
566 Hardware watchpoint %d deleted because the program has left the block in\n\
567 which its expression is valid.\n", b->number);
568 if (b->related_breakpoint)
569 delete_breakpoint (b->related_breakpoint);
570 delete_breakpoint (b);
573 /* Restore the frame and level. */
574 select_frame (saved_frame, saved_level);
577 printf_filtered ("\n");
583 remove_breakpoints ()
585 register struct breakpoint *b;
592 val = remove_breakpoint (b);
602 remove_breakpoint (b)
603 struct breakpoint *b;
607 if (b->type != bp_watchpoint
608 && b->type != bp_hardware_watchpoint)
610 val = target_remove_breakpoint(b->address, b->shadow_contents);
615 else if (b->type == bp_hardware_watchpoint
616 && b->enable == enabled
622 /* Walk down the saved value chain. */
623 for (v = b->val_chain; v; v = v->next)
625 /* For each memory reference remove the watchpoint
627 if (v->lval == lval_memory)
631 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
632 len = TYPE_LENGTH (VALUE_TYPE (v));
633 val = target_remove_watchpoint (addr, len);
639 /* Failure to remove any of the hardware watchpoints comes here. */
641 error ("Hardware watchpoint %d: Could not remove watchpoint\n",
644 /* Free the saved value chain. We will construct a new one
645 the next time the watchpoint is inserted. */
646 for (v = b->val_chain; v; v = n)
656 /* Clear the "inserted" flag in all breakpoints. */
659 mark_breakpoints_out ()
661 register struct breakpoint *b;
667 /* Clear the "inserted" flag in all breakpoints and delete any breakpoints
668 which should go away between runs of the program. */
671 breakpoint_init_inferior ()
673 register struct breakpoint *b, *temp;
675 ALL_BREAKPOINTS_SAFE (b, temp)
679 /* If the call dummy breakpoint is at the entry point it will
680 cause problems when the inferior is rerun, so we better
682 if (b->type == bp_call_dummy)
683 delete_breakpoint (b);
685 /* Likewise for scope breakpoints. */
686 if (b->type == bp_watchpoint_scope)
687 delete_breakpoint (b);
689 /* Likewise for watchpoints on local expressions. */
690 if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint)
691 && b->exp_valid_block != NULL)
692 delete_breakpoint (b);
696 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
697 When continuing from a location with a breakpoint,
698 we actually single step once before calling insert_breakpoints. */
701 breakpoint_here_p (pc)
704 register struct breakpoint *b;
707 if (b->enable != disabled && b->address == pc)
713 /* Return nonzero if FRAME is a dummy frame. We can't use PC_IN_CALL_DUMMY
714 because figuring out the saved SP would take too much time, at least using
715 get_saved_register on the 68k. This means that for this function to
716 work right a port must use the bp_call_dummy breakpoint. */
719 frame_in_dummy (frame)
722 struct breakpoint *b;
727 static unsigned LONGEST dummy[] = CALL_DUMMY;
729 if (b->type == bp_call_dummy
730 && b->frame == frame->frame
732 /* We need to check the PC as well as the frame on the sparc,
733 for signals.exp in the testsuite. */
736 - sizeof (dummy) / sizeof (LONGEST) * REGISTER_SIZE))
737 && frame->pc <= b->address)
740 #endif /* CALL_DUMMY */
744 /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
745 is valid for process/thread PID. */
748 breakpoint_thread_match (pc, pid)
752 struct breakpoint *b;
755 thread = pid_to_thread_id (pid);
758 if (b->enable != disabled
760 && (b->thread == -1 || b->thread == thread))
767 /* bpstat stuff. External routines' interfaces are documented
770 /* Clear a bpstat so that it says we are not at any breakpoint.
771 Also free any storage that is part of a bpstat. */
786 if (p->old_val != NULL)
787 value_free (p->old_val);
794 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
795 is part of the bpstat is copied as well. */
803 bpstat retval = NULL;
808 for (; bs != NULL; bs = bs->next)
810 tmp = (bpstat) xmalloc (sizeof (*tmp));
811 memcpy (tmp, bs, sizeof (*tmp));
813 /* This is the first thing in the chain. */
823 /* Find the bpstat associated with this breakpoint */
826 bpstat_find_breakpoint(bsp, breakpoint)
828 struct breakpoint *breakpoint;
830 if (bsp == NULL) return NULL;
832 for (;bsp != NULL; bsp = bsp->next) {
833 if (bsp->breakpoint_at == breakpoint) return bsp;
838 /* Return the breakpoint number of the first breakpoint we are stopped
839 at. *BSP upon return is a bpstat which points to the remaining
840 breakpoints stopped at (but which is not guaranteed to be good for
841 anything but further calls to bpstat_num).
842 Return 0 if passed a bpstat which does not indicate any breakpoints. */
848 struct breakpoint *b;
851 return 0; /* No more breakpoint values */
854 b = (*bsp)->breakpoint_at;
857 return -1; /* breakpoint that's been deleted since */
859 return b->number; /* We have its number */
863 /* Modify BS so that the actions will not be performed. */
866 bpstat_clear_actions (bs)
869 for (; bs != NULL; bs = bs->next)
872 if (bs->old_val != NULL)
874 value_free (bs->old_val);
880 /* Stub for cleaning up our state if we error-out of a breakpoint command */
883 cleanup_executing_breakpoints (ignore)
886 executing_breakpoint_commands = 0;
889 /* Execute all the commands associated with all the breakpoints at this
890 location. Any of these commands could cause the process to proceed
891 beyond this point, etc. We look out for such changes by checking
892 the global "breakpoint_proceeded" after each command. */
895 bpstat_do_actions (bsp)
899 struct cleanup *old_chain;
901 executing_breakpoint_commands = 1;
902 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
907 breakpoint_proceeded = 0;
908 for (; bs != NULL; bs = bs->next)
912 char *line = bs->commands->line;
913 bs->commands = bs->commands->next;
914 execute_command (line, 0);
915 /* If the inferior is proceeded by the command, bomb out now.
916 The bpstat chain has been blown away by wait_for_inferior.
917 But since execution has stopped again, there is a new bpstat
918 to look at, so start over. */
919 if (breakpoint_proceeded)
924 executing_breakpoint_commands = 0;
925 discard_cleanups (old_chain);
928 /* This is the normal print_it function for a bpstat. In the future,
929 much of this logic could (should?) be moved to bpstat_stop_status,
930 by having it set different print_it functions. */
936 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
937 which has since been deleted. */
938 if (bs->breakpoint_at == NULL
939 || (bs->breakpoint_at->type != bp_breakpoint
940 && bs->breakpoint_at->type != bp_watchpoint
941 && bs->breakpoint_at->type != bp_hardware_watchpoint))
944 if (bs->breakpoint_at->type == bp_breakpoint)
946 /* I think the user probably only wants to see one breakpoint
947 number, not all of them. */
948 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
952 if (bs->old_val != NULL)
954 printf_filtered ("\nWatchpoint %d, ", bs->breakpoint_at->number);
955 print_expression (bs->breakpoint_at->exp, gdb_stdout);
956 printf_filtered ("\nOld value = ");
957 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
958 printf_filtered ("\nNew value = ");
959 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
961 printf_filtered ("\n");
962 value_free (bs->old_val);
964 /* More than one watchpoint may have been triggered. */
967 /* We can't deal with it. Maybe another member of the bpstat chain can. */
971 /* Print a message indicating what happened. Returns nonzero to
972 say that only the source line should be printed after this (zero
973 return means print the frame as well as the source line). */
974 /* Currently we always return zero. */
984 val = (*bs->print_it) (bs);
988 /* Maybe another breakpoint in the chain caused us to stop.
989 (Currently all watchpoints go on the bpstat whether hit or
990 not. That probably could (should) be changed, provided care is taken
991 with respect to bpstat_explains_signal). */
993 return bpstat_print (bs->next);
995 /* We reached the end of the chain without printing anything. */
999 /* Evaluate the expression EXP and return 1 if value is zero.
1000 This is used inside a catch_errors to evaluate the breakpoint condition.
1001 The argument is a "struct expression *" that has been cast to char * to
1002 make it pass through catch_errors. */
1005 breakpoint_cond_eval (exp)
1008 return !value_true (evaluate_expression ((struct expression *)exp));
1011 /* Allocate a new bpstat and chain it to the current one. */
1014 bpstat_alloc (b, cbs)
1015 register struct breakpoint *b;
1016 bpstat cbs; /* Current "bs" value */
1020 bs = (bpstat) xmalloc (sizeof (*bs));
1022 bs->breakpoint_at = b;
1023 /* If the condition is false, etc., don't do the commands. */
1024 bs->commands = NULL;
1026 bs->print_it = print_it_normal;
1032 /* Possible return values for watchpoint_check (this can't be an enum
1033 because of check_errors). */
1034 /* The watchpoint has been deleted. */
1035 #define WP_DELETED 1
1036 /* The value has changed. */
1037 #define WP_VALUE_CHANGED 2
1038 /* The value has not changed. */
1039 #define WP_VALUE_NOT_CHANGED 3
1041 /* Check watchpoint condition. */
1043 watchpoint_check (p)
1046 bpstat bs = (bpstat) p;
1047 struct breakpoint *b;
1048 FRAME saved_frame, fr;
1049 int within_current_scope, saved_level;
1051 /* Save the current frame and level so we can restore it after
1052 evaluating the watchpoint expression on its own frame. */
1053 saved_frame = selected_frame;
1054 saved_level = selected_frame_level;
1056 if (bs->breakpoint_at->exp_valid_block == NULL)
1057 within_current_scope = 1;
1060 fr = find_frame_addr_in_frame_chain (bs->breakpoint_at->watchpoint_frame);
1061 within_current_scope = (fr != NULL);
1062 if (within_current_scope)
1063 /* If we end up stopping, the current frame will get selected
1064 in normal_stop. So this call to select_frame won't affect
1066 select_frame (fr, -1);
1069 if (within_current_scope)
1071 /* We use value_{,free_to_}mark because it could be a
1072 *long* time before we return to the command level and
1073 call free_all_values. We can't call free_all_values because
1074 we might be in the middle of evaluating a function call. */
1076 value_ptr mark = value_mark ();
1077 value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
1078 if (!value_equal (bs->breakpoint_at->val, new_val))
1080 release_value (new_val);
1081 value_free_to_mark (mark);
1082 bs->old_val = bs->breakpoint_at->val;
1083 bs->breakpoint_at->val = new_val;
1084 /* We will stop here */
1085 select_frame (saved_frame, saved_level);
1086 return WP_VALUE_CHANGED;
1090 /* Nothing changed, don't do anything. */
1091 value_free_to_mark (mark);
1092 /* We won't stop here */
1093 select_frame (saved_frame, saved_level);
1094 return WP_VALUE_NOT_CHANGED;
1099 /* This seems like the only logical thing to do because
1100 if we temporarily ignored the watchpoint, then when
1101 we reenter the block in which it is valid it contains
1102 garbage (in the case of a function, it may have two
1103 garbage values, one before and one after the prologue).
1104 So we can't even detect the first assignment to it and
1105 watch after that (since the garbage may or may not equal
1106 the first value assigned). */
1108 Watchpoint %d deleted because the program has left the block in\n\
1109 which its expression is valid.\n", bs->breakpoint_at->number);
1110 if (bs->breakpoint_at->related_breakpoint)
1111 delete_breakpoint (bs->breakpoint_at->related_breakpoint);
1112 delete_breakpoint (bs->breakpoint_at);
1114 select_frame (saved_frame, saved_level);
1119 /* This is used when everything which needs to be printed has
1120 already been printed. But we still want to print the frame. */
1128 /* This is used when nothing should be printed for this bpstat entry. */
1137 /* Get a bpstat associated with having just stopped at address *PC
1138 and frame address FRAME_ADDRESS. Update *PC to point at the
1139 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
1140 if this is known to not be a real breakpoint (it could still be a
1141 watchpoint, though). */
1143 /* Determine whether we stopped at a breakpoint, etc, or whether we
1144 don't understand this stop. Result is a chain of bpstat's such that:
1146 if we don't understand the stop, the result is a null pointer.
1148 if we understand why we stopped, the result is not null.
1150 Each element of the chain refers to a particular breakpoint or
1151 watchpoint at which we have stopped. (We may have stopped for
1152 several reasons concurrently.)
1154 Each element of the chain has valid next, breakpoint_at,
1155 commands, FIXME??? fields.
1160 bpstat_stop_status (pc, frame_address, not_a_breakpoint)
1162 FRAME_ADDR frame_address;
1163 int not_a_breakpoint;
1165 register struct breakpoint *b;
1167 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1168 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
1169 int real_breakpoint = 0;
1171 /* Root of the chain of bpstat's */
1172 struct bpstat root_bs[1];
1173 /* Pointer to the last thing in the chain currently. */
1174 bpstat bs = root_bs;
1176 /* Get the address where the breakpoint would have been. */
1177 bp_addr = *pc - DECR_PC_AFTER_BREAK;
1181 if (b->enable == disabled)
1184 if (b->type != bp_watchpoint
1185 && b->type != bp_hardware_watchpoint
1186 && b->address != bp_addr)
1189 if (b->type != bp_watchpoint
1190 && b->type != bp_hardware_watchpoint
1191 && not_a_breakpoint)
1194 /* Come here if it's a watchpoint, or if the break address matches */
1196 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
1201 if (b->type == bp_watchpoint || b->type == bp_hardware_watchpoint)
1203 static char message1[] =
1204 "Error evaluating expression for watchpoint %d\n";
1205 char message[sizeof (message1) + 30 /* slop */];
1206 sprintf (message, message1, b->number);
1207 switch (catch_errors (watchpoint_check, (char *) bs, message,
1211 /* We've already printed what needs to be printed. */
1212 bs->print_it = print_it_done;
1215 case WP_VALUE_CHANGED:
1218 case WP_VALUE_NOT_CHANGED:
1220 bs->print_it = print_it_noop;
1227 /* Error from catch_errors. */
1228 printf_filtered ("Watchpoint %d deleted.\n", b->number);
1229 if (b->related_breakpoint)
1230 delete_breakpoint (b->related_breakpoint);
1231 delete_breakpoint (b);
1232 /* We've already printed what needs to be printed. */
1233 bs->print_it = print_it_done;
1239 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1241 real_breakpoint = 1;
1244 if (b->frame && b->frame != frame_address)
1248 int value_is_zero = 0;
1252 /* Need to select the frame, with all that implies
1253 so that the conditions will have the right context. */
1254 select_frame (get_current_frame (), 0);
1256 = catch_errors (breakpoint_cond_eval, (char *)(b->cond),
1257 "Error in testing breakpoint condition:\n",
1259 /* FIXME-someday, should give breakpoint # */
1262 if (b->cond && value_is_zero)
1266 else if (b->ignore_count > 0)
1273 /* We will stop here */
1274 if (b->disposition == disable)
1275 b->enable = disabled;
1276 bs->commands = b->commands;
1279 if (bs->commands && STREQ ("silent", bs->commands->line))
1281 bs->commands = bs->commands->next;
1286 /* Print nothing for this entry if we dont stop or if we dont print. */
1287 if (bs->stop == 0 || bs->print == 0)
1288 bs->print_it = print_it_noop;
1291 bs->next = NULL; /* Terminate the chain */
1292 bs = root_bs->next; /* Re-grab the head of the chain */
1293 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1296 if (real_breakpoint)
1299 #if defined (SHIFT_INST_REGS)
1301 #else /* No SHIFT_INST_REGS. */
1303 #endif /* No SHIFT_INST_REGS. */
1306 #endif /* DECR_PC_AFTER_BREAK != 0. */
1308 /* The value of a hardware watchpoint hasn't changed, but the
1309 intermediate memory locations we are watching may have. */
1310 if (bs && ! bs->stop
1311 && bs->breakpoint_at->type == bp_hardware_watchpoint)
1313 remove_breakpoints ();
1314 insert_breakpoints ();
1319 /* Tell what to do about this bpstat. */
1324 /* Classify each bpstat as one of the following. */
1326 /* This bpstat element has no effect on the main_action. */
1329 /* There was a watchpoint, stop but don't print. */
1332 /* There was a watchpoint, stop and print. */
1335 /* There was a breakpoint but we're not stopping. */
1338 /* There was a breakpoint, stop but don't print. */
1341 /* There was a breakpoint, stop and print. */
1344 /* We hit the longjmp breakpoint. */
1347 /* We hit the longjmp_resume breakpoint. */
1350 /* We hit the step_resume breakpoint. */
1353 /* We hit the through_sigtramp breakpoint. */
1356 /* This is just used to count how many enums there are. */
1360 /* Here is the table which drives this routine. So that we can
1361 format it pretty, we define some abbreviations for the
1362 enum bpstat_what codes. */
1363 #define keep_c BPSTAT_WHAT_KEEP_CHECKING
1364 #define stop_s BPSTAT_WHAT_STOP_SILENT
1365 #define stop_n BPSTAT_WHAT_STOP_NOISY
1366 #define single BPSTAT_WHAT_SINGLE
1367 #define setlr BPSTAT_WHAT_SET_LONGJMP_RESUME
1368 #define clrlr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
1369 #define clrlrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
1370 #define sr BPSTAT_WHAT_STEP_RESUME
1371 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
1373 /* "Can't happen." Might want to print an error message.
1374 abort() is not out of the question, but chances are GDB is just
1375 a bit confused, not unusable. */
1376 #define err BPSTAT_WHAT_STOP_NOISY
1378 /* Given an old action and a class, come up with a new action. */
1379 /* One interesting property of this table is that wp_silent is the same
1380 as bp_silent and wp_noisy is the same as bp_noisy. That is because
1381 after stopping, the check for whether to step over a breakpoint
1382 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
1383 reference to how we stopped. We retain separate wp_silent and bp_silent
1384 codes in case we want to change that someday. */
1386 /* step_resume entries: a step resume breakpoint overrides another
1387 breakpoint of signal handling (see comment in wait_for_inferior
1388 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
1389 /* We handle the through_sigtramp_breakpoint the same way; having both
1390 one of those and a step_resume_breakpoint is probably very rare (?). */
1392 static const enum bpstat_what_main_action
1393 table[(int)class_last][(int)BPSTAT_WHAT_LAST] =
1396 /* keep_c stop_s stop_n single setlr clrlr clrlrs sr ts
1398 /*no_effect*/ {keep_c,stop_s,stop_n,single, setlr , clrlr , clrlrs, sr, ts},
1399 /*wp_silent*/ {stop_s,stop_s,stop_n,stop_s, stop_s, stop_s, stop_s, sr, ts},
1400 /*wp_noisy*/ {stop_n,stop_n,stop_n,stop_n, stop_n, stop_n, stop_n, sr, ts},
1401 /*bp_nostop*/ {single,stop_s,stop_n,single, setlr , clrlrs, clrlrs, sr, ts},
1402 /*bp_silent*/ {stop_s,stop_s,stop_n,stop_s, stop_s, stop_s, stop_s, sr, ts},
1403 /*bp_noisy*/ {stop_n,stop_n,stop_n,stop_n, stop_n, stop_n, stop_n, sr, ts},
1404 /*long_jump*/ {setlr ,stop_s,stop_n,setlr , err , err , err , sr, ts},
1405 /*long_resume*/ {clrlr ,stop_s,stop_n,clrlrs, err , err , err , sr, ts},
1406 /*step_resume*/ {sr ,sr ,sr ,sr , sr , sr , sr , sr, ts},
1407 /*through_sig*/ {ts ,ts ,ts ,ts , ts , ts , ts , ts, ts}
1419 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
1420 struct bpstat_what retval;
1422 retval.call_dummy = 0;
1423 for (; bs != NULL; bs = bs->next)
1425 enum class bs_class = no_effect;
1426 if (bs->breakpoint_at == NULL)
1427 /* I suspect this can happen if it was a momentary breakpoint
1428 which has since been deleted. */
1430 switch (bs->breakpoint_at->type)
1438 bs_class = bp_noisy;
1440 bs_class = bp_silent;
1443 bs_class = bp_nostop;
1446 case bp_hardware_watchpoint:
1450 bs_class = wp_noisy;
1452 bs_class = wp_silent;
1455 /* There was a watchpoint, but we're not stopping. This requires
1456 no further action. */
1457 bs_class = no_effect;
1460 bs_class = long_jump;
1462 case bp_longjmp_resume:
1463 bs_class = long_resume;
1465 case bp_step_resume:
1468 bs_class = step_resume;
1471 /* It is for the wrong frame. */
1472 bs_class = bp_nostop;
1474 case bp_through_sigtramp:
1475 bs_class = through_sig;
1477 case bp_watchpoint_scope:
1478 bs_class = bp_nostop;
1482 /* Make sure the action is stop (silent or noisy), so infrun.c
1483 pops the dummy frame. */
1484 bs_class = bp_silent;
1485 retval.call_dummy = 1;
1488 current_action = table[(int)bs_class][(int)current_action];
1490 retval.main_action = current_action;
1494 /* Nonzero if we should step constantly (e.g. watchpoints on machines
1495 without hardware support). This isn't related to a specific bpstat,
1496 just to things like whether watchpoints are set. */
1499 bpstat_should_step ()
1501 struct breakpoint *b;
1503 if (b->enable == enabled && b->type == bp_watchpoint)
1508 /* Print information on breakpoint number BNUM, or -1 if all.
1509 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
1510 is nonzero, process only watchpoints. */
1513 breakpoint_1 (bnum, allflag)
1517 register struct breakpoint *b;
1518 register struct command_line *l;
1519 register struct symbol *sym;
1520 CORE_ADDR last_addr = (CORE_ADDR)-1;
1521 int found_a_breakpoint = 0;
1522 static char *bptypes[] = {"breakpoint", "until", "finish", "watchpoint",
1523 "hardware watchpoint", "longjmp",
1524 "longjmp resume", "step resume",
1525 "watchpoint scope", "call dummy" };
1526 static char *bpdisps[] = {"del", "dis", "keep"};
1527 static char bpenables[] = "ny";
1528 char wrap_indent[80];
1532 || bnum == b->number)
1534 /* We only print out user settable breakpoints unless the allflag is set. */
1536 && b->type != bp_breakpoint
1537 && b->type != bp_watchpoint
1538 && b->type != bp_hardware_watchpoint)
1541 if (!found_a_breakpoint++)
1543 if (annotation_level > 1)
1544 printf_filtered ("\n\032\032breakpoints-headers\n");
1546 if (annotation_level > 1)
1547 printf_filtered ("\n\032\032field 0\n");
1548 printf_filtered ("Num ");
1549 if (annotation_level > 1)
1550 printf_filtered ("\n\032\032field 1\n");
1551 printf_filtered ("Type ");
1552 if (annotation_level > 1)
1553 printf_filtered ("\n\032\032field 2\n");
1554 printf_filtered ("Disp ");
1555 if (annotation_level > 1)
1556 printf_filtered ("\n\032\032field 3\n");
1557 printf_filtered ("Enb ");
1560 if (annotation_level > 1)
1561 printf_filtered ("\n\032\032field 4\n");
1562 printf_filtered ("Address ");
1564 if (annotation_level > 1)
1565 printf_filtered ("\n\032\032field 5\n");
1566 printf_filtered ("What\n");
1568 if (annotation_level > 1)
1569 printf_filtered ("\n\032\032breakpoints-table\n");
1572 if (annotation_level > 1)
1573 printf_filtered ("\n\032\032record\n\n\032\032field 0\n");
1574 printf_filtered ("%-3d ", b->number);
1575 if (annotation_level > 1)
1576 printf_filtered ("\n\032\032field 1\n");
1577 printf_filtered ("%-14s ", bptypes[(int)b->type]);
1578 if (annotation_level > 1)
1579 printf_filtered ("\n\032\032field 2\n");
1580 printf_filtered ("%-4s ", bpdisps[(int)b->disposition]);
1581 if (annotation_level > 1)
1582 printf_filtered ("\n\032\032field 3\n");
1583 printf_filtered ("%-3c ", bpenables[(int)b->enable]);
1585 strcpy (wrap_indent, " ");
1587 strcat (wrap_indent, " ");
1591 case bp_hardware_watchpoint:
1592 /* Field 4, the address, is omitted (which makes the columns
1593 not line up too nicely with the headers, but the effect
1594 is relatively readable). */
1595 if (annotation_level > 1)
1596 printf_filtered ("\n\032\032field 5\n");
1597 print_expression (b->exp, gdb_stdout);
1604 case bp_longjmp_resume:
1605 case bp_step_resume:
1606 case bp_through_sigtramp:
1607 case bp_watchpoint_scope:
1611 if (annotation_level > 1)
1612 printf_filtered ("\n\032\032field 4\n");
1613 /* FIXME-32x64: need a print_address_numeric with
1617 local_hex_string_custom
1618 ((unsigned long) b->address, "08l"));
1621 if (annotation_level > 1)
1622 printf_filtered ("\n\032\032field 5\n");
1624 last_addr = b->address;
1627 sym = find_pc_function (b->address);
1630 fputs_filtered ("in ", gdb_stdout);
1631 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
1632 wrap_here (wrap_indent);
1633 fputs_filtered (" at ", gdb_stdout);
1635 fputs_filtered (b->source_file, gdb_stdout);
1636 printf_filtered (":%d", b->line_number);
1639 print_address_symbolic (b->address, gdb_stdout, demangle, " ");
1643 printf_filtered ("\n");
1647 if (annotation_level > 1)
1648 printf_filtered ("\n\032\032field 6\n");
1650 printf_filtered ("\tstop only in stack frame at ");
1651 print_address_numeric (b->frame, gdb_stdout);
1652 printf_filtered ("\n");
1657 if (annotation_level > 1)
1658 printf_filtered ("\n\032\032field 7\n");
1660 printf_filtered ("\tstop only if ");
1661 print_expression (b->cond, gdb_stdout);
1662 printf_filtered ("\n");
1665 if (b->ignore_count)
1667 if (annotation_level > 1)
1668 printf_filtered ("\n\032\032field 8\n");
1670 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
1673 if ((l = b->commands))
1675 if (annotation_level > 1)
1676 printf_filtered ("\n\032\032field 9\n");
1680 fputs_filtered ("\t", gdb_stdout);
1681 fputs_filtered (l->line, gdb_stdout);
1682 fputs_filtered ("\n", gdb_stdout);
1688 if (!found_a_breakpoint)
1691 printf_filtered ("No breakpoints or watchpoints.\n");
1693 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
1696 /* Compare against (CORE_ADDR)-1 in case some compiler decides
1697 that a comparison of an unsigned with -1 is always false. */
1698 if (last_addr != (CORE_ADDR)-1)
1699 set_next_address (last_addr);
1701 if (annotation_level > 1)
1702 printf_filtered ("\n\032\032breakpoints-table-end\n");
1707 breakpoints_info (bnum_exp, from_tty)
1714 bnum = parse_and_eval_address (bnum_exp);
1716 breakpoint_1 (bnum, 0);
1719 #if MAINTENANCE_CMDS
1723 maintenance_info_breakpoints (bnum_exp, from_tty)
1730 bnum = parse_and_eval_address (bnum_exp);
1732 breakpoint_1 (bnum, 1);
1737 /* Print a message describing any breakpoints set at PC. */
1740 describe_other_breakpoints (pc)
1741 register CORE_ADDR pc;
1743 register int others = 0;
1744 register struct breakpoint *b;
1747 if (b->address == pc)
1751 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
1753 if (b->address == pc)
1759 (b->enable == disabled) ? " (disabled)" : "",
1760 (others > 1) ? "," : ((others == 1) ? " and" : ""));
1762 printf_filtered ("also set at pc ");
1763 print_address_numeric (pc, gdb_stdout);
1764 printf_filtered (".\n");
1768 /* Set the default place to put a breakpoint
1769 for the `break' command with no arguments. */
1772 set_default_breakpoint (valid, addr, symtab, line)
1775 struct symtab *symtab;
1778 default_breakpoint_valid = valid;
1779 default_breakpoint_address = addr;
1780 default_breakpoint_symtab = symtab;
1781 default_breakpoint_line = line;
1784 /* Rescan breakpoints at address ADDRESS,
1785 marking the first one as "first" and any others as "duplicates".
1786 This is so that the bpt instruction is only inserted once. */
1789 check_duplicates (address)
1792 register struct breakpoint *b;
1793 register int count = 0;
1795 if (address == 0) /* Watchpoints are uninteresting */
1799 if (b->enable != disabled && b->address == address)
1802 b->duplicate = count > 1;
1806 /* Low level routine to set a breakpoint.
1807 Takes as args the three things that every breakpoint must have.
1808 Returns the breakpoint object so caller can set other things.
1809 Does not set the breakpoint number!
1810 Does not print anything.
1812 ==> This routine should not be called if there is a chance of later
1813 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
1814 your arguments BEFORE calling this routine! */
1816 static struct breakpoint *
1817 set_raw_breakpoint (sal)
1818 struct symtab_and_line sal;
1820 register struct breakpoint *b, *b1;
1822 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
1823 memset (b, 0, sizeof (*b));
1824 b->address = sal.pc;
1825 if (sal.symtab == NULL)
1826 b->source_file = NULL;
1828 b->source_file = savestring (sal.symtab->filename,
1829 strlen (sal.symtab->filename));
1831 b->line_number = sal.line;
1832 b->enable = enabled;
1835 b->ignore_count = 0;
1839 /* Add this breakpoint to the end of the chain
1840 so that a list of breakpoints will come out in order
1841 of increasing numbers. */
1843 b1 = breakpoint_chain;
1845 breakpoint_chain = b;
1853 check_duplicates (sal.pc);
1854 breakpoints_changed ();
1860 create_longjmp_breakpoint(func_name)
1863 struct symtab_and_line sal;
1864 struct breakpoint *b;
1865 static int internal_breakpoint_number = -1;
1867 if (func_name != NULL)
1869 struct minimal_symbol *m;
1871 m = lookup_minimal_symbol(func_name, (struct objfile *)NULL);
1873 sal.pc = SYMBOL_VALUE_ADDRESS (m);
1883 b = set_raw_breakpoint(sal);
1886 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
1887 b->disposition = donttouch;
1888 b->enable = disabled;
1891 b->addr_string = strsave(func_name);
1892 b->number = internal_breakpoint_number--;
1895 /* Call this routine when stepping and nexting to enable a breakpoint if we do
1896 a longjmp(). When we hit that breakpoint, call
1897 set_longjmp_resume_breakpoint() to figure out where we are going. */
1900 enable_longjmp_breakpoint()
1902 register struct breakpoint *b;
1905 if (b->type == bp_longjmp)
1907 b->enable = enabled;
1908 check_duplicates (b->address);
1913 disable_longjmp_breakpoint()
1915 register struct breakpoint *b;
1918 if ( b->type == bp_longjmp
1919 || b->type == bp_longjmp_resume)
1921 b->enable = disabled;
1922 check_duplicates (b->address);
1926 /* Call this after hitting the longjmp() breakpoint. Use this to set a new
1927 breakpoint at the target of the jmp_buf.
1929 FIXME - This ought to be done by setting a temporary breakpoint that gets
1930 deleted automatically...
1934 set_longjmp_resume_breakpoint(pc, frame)
1938 register struct breakpoint *b;
1941 if (b->type == bp_longjmp_resume)
1944 b->enable = enabled;
1946 b->frame = FRAME_FP(frame);
1949 check_duplicates (b->address);
1954 /* Set a breakpoint that will evaporate an end of command
1955 at address specified by SAL.
1956 Restrict it to frame FRAME if FRAME is nonzero. */
1959 set_momentary_breakpoint (sal, frame, type)
1960 struct symtab_and_line sal;
1964 register struct breakpoint *b;
1965 b = set_raw_breakpoint (sal);
1967 b->enable = enabled;
1968 b->disposition = donttouch;
1969 b->frame = (frame ? FRAME_FP (frame) : 0);
1975 clear_momentary_breakpoints ()
1977 register struct breakpoint *b;
1979 if (b->disposition == delete)
1981 delete_breakpoint (b);
1987 /* Tell the user we have just set a breakpoint B. */
1990 struct breakpoint *b;
1995 printf_filtered ("Watchpoint %d: ", b->number);
1996 print_expression (b->exp, gdb_stdout);
1998 case bp_hardware_watchpoint:
1999 printf_filtered ("Hardware watchpoint %d: ", b->number);
2000 print_expression (b->exp, gdb_stdout);
2003 printf_filtered ("Breakpoint %d at ", b->number);
2004 print_address_numeric (b->address, gdb_stdout);
2006 printf_filtered (": file %s, line %d.",
2007 b->source_file, b->line_number);
2012 case bp_longjmp_resume:
2013 case bp_step_resume:
2014 case bp_through_sigtramp:
2016 case bp_watchpoint_scope:
2019 printf_filtered ("\n");
2023 /* Nobody calls this currently. */
2024 /* Set a breakpoint from a symtab and line.
2025 If TEMPFLAG is nonzero, it is a temporary breakpoint.
2026 ADDR_STRING is a malloc'd string holding the name of where we are
2027 setting the breakpoint. This is used later to re-set it after the
2028 program is relinked and symbols are reloaded.
2029 Print the same confirmation messages that the breakpoint command prints. */
2032 set_breakpoint (s, line, tempflag, addr_string)
2038 register struct breakpoint *b;
2039 struct symtab_and_line sal;
2044 resolve_sal_pc (&sal); /* Might error out */
2045 describe_other_breakpoints (sal.pc);
2047 b = set_raw_breakpoint (sal);
2048 set_breakpoint_count (breakpoint_count + 1);
2049 b->number = breakpoint_count;
2050 b->type = bp_breakpoint;
2052 b->addr_string = addr_string;
2053 b->enable = enabled;
2054 b->disposition = tempflag ? delete : donttouch;
2060 /* Set a breakpoint according to ARG (function, linenum or *address)
2061 and make it temporary if TEMPFLAG is nonzero. */
2064 break_command_1 (arg, tempflag, from_tty)
2066 int tempflag, from_tty;
2068 struct symtabs_and_lines sals;
2069 struct symtab_and_line sal;
2070 register struct expression *cond = 0;
2071 register struct breakpoint *b;
2073 /* Pointers in arg to the start, and one past the end, of the condition. */
2074 char *cond_start = NULL;
2075 char *cond_end = NULL;
2076 /* Pointers in arg to the start, and one past the end,
2077 of the address part. */
2078 char *addr_start = NULL;
2079 char *addr_end = NULL;
2080 struct cleanup *old_chain;
2081 struct cleanup *canonical_strings_chain = NULL;
2082 char **canonical = (char **)NULL;
2089 sal.line = sal.pc = sal.end = 0;
2092 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
2094 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
2095 && (arg[2] == ' ' || arg[2] == '\t')))
2097 if (default_breakpoint_valid)
2099 sals.sals = (struct symtab_and_line *)
2100 xmalloc (sizeof (struct symtab_and_line));
2101 sal.pc = default_breakpoint_address;
2102 sal.line = default_breakpoint_line;
2103 sal.symtab = default_breakpoint_symtab;
2108 error ("No default breakpoint address now.");
2114 /* Force almost all breakpoints to be in terms of the
2115 current_source_symtab (which is decode_line_1's default). This
2116 should produce the results we want almost all of the time while
2117 leaving default_breakpoint_* alone. */
2118 if (default_breakpoint_valid
2119 && (!current_source_symtab
2120 || (arg && (*arg == '+' || *arg == '-'))))
2121 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
2122 default_breakpoint_line, &canonical);
2124 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, &canonical);
2132 /* Make sure that all storage allocated in decode_line_1 gets freed in case
2133 the following `for' loop errors out. */
2134 old_chain = make_cleanup (free, sals.sals);
2135 if (canonical != (char **)NULL)
2137 make_cleanup (free, canonical);
2138 canonical_strings_chain = make_cleanup (null_cleanup, 0);
2139 for (i = 0; i < sals.nelts; i++)
2141 if (canonical[i] != NULL)
2142 make_cleanup (free, canonical[i]);
2146 thread = -1; /* No specific thread yet */
2148 /* Resolve all line numbers to PC's, and verify that conditions
2149 can be parsed, before setting any breakpoints. */
2150 for (i = 0; i < sals.nelts; i++)
2152 char *tok, *end_tok;
2155 resolve_sal_pc (&sals.sals[i]);
2161 while (*tok == ' ' || *tok == '\t')
2166 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
2169 toklen = end_tok - tok;
2171 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
2173 tok = cond_start = end_tok + 1;
2174 cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
2177 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
2183 thread = strtol (tok, &tok, 0);
2185 error ("Junk after thread keyword.");
2186 if (!valid_thread_id (thread))
2187 error ("Unknown thread %d\n", thread);
2190 error ("Junk at end of arguments.");
2194 /* Remove the canonical strings from the cleanup, they are needed below. */
2195 if (canonical != (char **)NULL)
2196 discard_cleanups (canonical_strings_chain);
2198 /* Now set all the breakpoints. */
2199 for (i = 0; i < sals.nelts; i++)
2204 describe_other_breakpoints (sal.pc);
2206 b = set_raw_breakpoint (sal);
2207 set_breakpoint_count (breakpoint_count + 1);
2208 b->number = breakpoint_count;
2209 b->type = bp_breakpoint;
2213 /* If a canonical line spec is needed use that instead of the
2215 if (canonical != (char **)NULL && canonical[i] != NULL)
2216 b->addr_string = canonical[i];
2217 else if (addr_start)
2218 b->addr_string = savestring (addr_start, addr_end - addr_start);
2220 b->cond_string = savestring (cond_start, cond_end - cond_start);
2222 b->enable = enabled;
2223 b->disposition = tempflag ? delete : donttouch;
2230 printf_filtered ("Multiple breakpoints were set.\n");
2231 printf_filtered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
2233 do_cleanups (old_chain);
2236 /* Helper function for break_command_1 and disassemble_command. */
2239 resolve_sal_pc (sal)
2240 struct symtab_and_line *sal;
2244 if (sal->pc == 0 && sal->symtab != 0)
2246 pc = find_line_pc (sal->symtab, sal->line);
2248 error ("No line %d in file \"%s\".",
2249 sal->line, sal->symtab->filename);
2255 break_command (arg, from_tty)
2259 break_command_1 (arg, 0, from_tty);
2263 tbreak_command (arg, from_tty)
2267 break_command_1 (arg, 1, from_tty);
2272 watch_command (arg, from_tty)
2276 struct breakpoint *b;
2277 struct symtab_and_line sal;
2278 struct expression *exp;
2279 struct block *exp_valid_block;
2281 FRAME frame, prev_frame;
2287 /* Parse arguments. */
2288 innermost_block = NULL;
2289 exp = parse_expression (arg);
2290 exp_valid_block = innermost_block;
2291 val = evaluate_expression (exp);
2292 release_value (val);
2293 if (VALUE_LAZY (val))
2294 value_fetch_lazy (val);
2296 /* Now set up the breakpoint. */
2297 b = set_raw_breakpoint (sal);
2298 set_breakpoint_count (breakpoint_count + 1);
2299 b->number = breakpoint_count;
2300 b->disposition = donttouch;
2302 b->exp_valid_block = exp_valid_block;
2305 b->cond_string = NULL;
2306 b->exp_string = savestring (arg, strlen (arg));
2308 frame = block_innermost_frame (exp_valid_block);
2311 prev_frame = get_prev_frame (frame);
2312 b->watchpoint_frame = FRAME_FP (frame);
2315 b->watchpoint_frame = (CORE_ADDR)0;
2317 if (can_use_hardware_watchpoint (b))
2318 b->type = bp_hardware_watchpoint;
2320 b->type = bp_watchpoint;
2322 /* If the expression is "local", then set up a "watchpoint scope"
2323 breakpoint at the point where we've left the scope of the watchpoint
2325 if (innermost_block)
2327 struct breakpoint *scope_breakpoint;
2328 struct symtab_and_line scope_sal;
2332 scope_sal.pc = get_frame_pc (prev_frame);
2333 scope_sal.symtab = NULL;
2336 scope_breakpoint = set_raw_breakpoint (scope_sal);
2337 set_breakpoint_count (breakpoint_count + 1);
2338 scope_breakpoint->number = breakpoint_count;
2340 scope_breakpoint->type = bp_watchpoint_scope;
2341 scope_breakpoint->enable = enabled;
2343 /* Automatically delete the breakpoint when it hits. */
2344 scope_breakpoint->disposition = delete;
2346 /* Only break in the proper frame (help with recursion). */
2347 scope_breakpoint->frame = prev_frame->frame;
2349 /* Set the address at which we will stop. */
2350 scope_breakpoint->address = get_frame_pc (prev_frame);
2352 /* The scope breakpoint is related to the watchpoint. We
2353 will need to act on them together. */
2354 b->related_breakpoint = scope_breakpoint;
2361 /* Return nonzero if the watchpoint described by B can be handled
2362 completely in hardware. If the watchpoint can not be handled
2363 in hardware return zero. */
2366 can_use_hardware_watchpoint (b)
2367 struct breakpoint *b;
2369 value_ptr mark = value_mark ();
2370 value_ptr v = evaluate_expression (b->exp);
2371 int found_memory = 0;
2373 /* Make sure all the intermediate values are in memory. Also make sure
2374 we found at least one memory expression. Guards against watch 0x12345,
2375 which is meaningless, but could cause errors if one tries to insert a
2376 hardware watchpoint for the constant expression. */
2377 for ( ; v != mark; v = v->next)
2379 if (!(v->lval == lval_memory)
2380 || v->lval == not_lval
2381 || (v->lval != not_lval
2382 && v->modifiable == 0))
2385 if (v->lval == lval_memory)
2389 /* The expression itself looks suitable for using a hardware
2390 watchpoint, but give the target machine a chance to reject it. */
2391 return found_memory && TARGET_CAN_USE_HARDWARE_WATCHPOINT (b);
2396 * Helper routine for the until_command routine in infcmd.c. Here
2397 * because it uses the mechanisms of breakpoints.
2401 until_break_command (arg, from_tty)
2405 struct symtabs_and_lines sals;
2406 struct symtab_and_line sal;
2407 FRAME prev_frame = get_prev_frame (selected_frame);
2408 struct breakpoint *breakpoint;
2409 struct cleanup *old_chain;
2411 clear_proceed_status ();
2413 /* Set a breakpoint where the user wants it and at return from
2416 if (default_breakpoint_valid)
2417 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
2418 default_breakpoint_line, (char ***)NULL);
2420 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, (char ***)NULL);
2422 if (sals.nelts != 1)
2423 error ("Couldn't get information on specified line.");
2426 free ((PTR)sals.sals); /* malloc'd, so freed */
2429 error ("Junk at end of arguments.");
2431 resolve_sal_pc (&sal);
2433 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
2435 old_chain = make_cleanup(delete_breakpoint, breakpoint);
2437 /* Keep within the current frame */
2441 struct frame_info *fi;
2443 fi = get_frame_info (prev_frame);
2444 sal = find_pc_line (fi->pc, 0);
2446 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
2447 make_cleanup(delete_breakpoint, breakpoint);
2450 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
2451 do_cleanups(old_chain);
2455 /* These aren't used; I don't konw what they were for. */
2456 /* Set a breakpoint at the catch clause for NAME. */
2458 catch_breakpoint (name)
2464 disable_catch_breakpoint ()
2469 delete_catch_breakpoint ()
2474 enable_catch_breakpoint ()
2481 struct sal_chain *next;
2482 struct symtab_and_line sal;
2486 /* This isn't used; I don't know what it was for. */
2487 /* For each catch clause identified in ARGS, run FUNCTION
2488 with that clause as an argument. */
2489 static struct symtabs_and_lines
2490 map_catch_names (args, function)
2494 register char *p = args;
2496 struct symtabs_and_lines sals;
2498 struct sal_chain *sal_chain = 0;
2502 error_no_arg ("one or more catch names");
2510 /* Don't swallow conditional part. */
2511 if (p1[0] == 'i' && p1[1] == 'f'
2512 && (p1[2] == ' ' || p1[2] == '\t'))
2518 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
2522 if (*p1 && *p1 != ' ' && *p1 != '\t')
2523 error ("Arguments must be catch names.");
2529 struct sal_chain *next
2530 = (struct sal_chain *)alloca (sizeof (struct sal_chain));
2531 next->next = sal_chain;
2532 next->sal = get_catch_sal (p);
2537 printf_unfiltered ("No catch clause for exception %s.\n", p);
2542 while (*p == ' ' || *p == '\t') p++;
2547 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
2549 static struct symtabs_and_lines
2550 get_catch_sals (this_level_only)
2551 int this_level_only;
2553 register struct blockvector *bl;
2554 register struct block *block;
2555 int index, have_default = 0;
2556 struct frame_info *fi;
2558 struct symtabs_and_lines sals;
2559 struct sal_chain *sal_chain = 0;
2560 char *blocks_searched;
2562 /* Not sure whether an error message is always the correct response,
2563 but it's better than a core dump. */
2564 if (selected_frame == NULL)
2565 error ("No selected frame.");
2566 block = get_frame_block (selected_frame);
2567 fi = get_frame_info (selected_frame);
2574 error ("No symbol table info available.\n");
2576 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
2577 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
2578 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
2582 CORE_ADDR end = BLOCK_END (block) - 4;
2585 if (bl != blockvector_for_pc (end, &index))
2586 error ("blockvector blotch");
2587 if (BLOCKVECTOR_BLOCK (bl, index) != block)
2588 error ("blockvector botch");
2589 last_index = BLOCKVECTOR_NBLOCKS (bl);
2592 /* Don't print out blocks that have gone by. */
2593 while (index < last_index
2594 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
2597 while (index < last_index
2598 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
2600 if (blocks_searched[index] == 0)
2602 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
2605 register struct symbol *sym;
2607 nsyms = BLOCK_NSYMS (b);
2609 for (i = 0; i < nsyms; i++)
2611 sym = BLOCK_SYM (b, i);
2612 if (STREQ (SYMBOL_NAME (sym), "default"))
2618 if (SYMBOL_CLASS (sym) == LOC_LABEL)
2620 struct sal_chain *next = (struct sal_chain *)
2621 alloca (sizeof (struct sal_chain));
2622 next->next = sal_chain;
2623 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
2627 blocks_searched[index] = 1;
2633 if (sal_chain && this_level_only)
2636 /* After handling the function's top-level block, stop.
2637 Don't continue to its superblock, the block of
2638 per-file symbols. */
2639 if (BLOCK_FUNCTION (block))
2641 block = BLOCK_SUPERBLOCK (block);
2646 struct sal_chain *tmp_chain;
2648 /* Count the number of entries. */
2649 for (index = 0, tmp_chain = sal_chain; tmp_chain;
2650 tmp_chain = tmp_chain->next)
2654 sals.sals = (struct symtab_and_line *)
2655 xmalloc (index * sizeof (struct symtab_and_line));
2656 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
2657 sals.sals[index] = sal_chain->sal;
2663 /* Commands to deal with catching exceptions. */
2666 catch_command_1 (arg, tempflag, from_tty)
2671 /* First, translate ARG into something we can deal with in terms
2674 struct symtabs_and_lines sals;
2675 struct symtab_and_line sal;
2676 register struct expression *cond = 0;
2677 register struct breakpoint *b;
2681 sal.line = sal.pc = sal.end = 0;
2684 /* If no arg given, or if first arg is 'if ', all active catch clauses
2685 are breakpointed. */
2687 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
2688 && (arg[2] == ' ' || arg[2] == '\t')))
2690 /* Grab all active catch clauses. */
2691 sals = get_catch_sals (0);
2695 /* Grab selected catch clauses. */
2696 error ("catch NAME not implemented");
2698 /* This isn't used; I don't know what it was for. */
2699 sals = map_catch_names (arg, catch_breakpoint);
2707 for (i = 0; i < sals.nelts; i++)
2709 resolve_sal_pc (&sals.sals[i]);
2713 if (arg[0] == 'i' && arg[1] == 'f'
2714 && (arg[2] == ' ' || arg[2] == '\t'))
2715 cond = parse_exp_1 ((arg += 2, &arg),
2716 block_for_pc (sals.sals[i].pc), 0);
2718 error ("Junk at end of arguments.");
2723 for (i = 0; i < sals.nelts; i++)
2728 describe_other_breakpoints (sal.pc);
2730 b = set_raw_breakpoint (sal);
2731 set_breakpoint_count (breakpoint_count + 1);
2732 b->number = breakpoint_count;
2733 b->type = bp_breakpoint;
2735 b->enable = enabled;
2736 b->disposition = tempflag ? delete : donttouch;
2743 printf_unfiltered ("Multiple breakpoints were set.\n");
2744 printf_unfiltered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
2746 free ((PTR)sals.sals);
2750 /* These aren't used; I don't know what they were for. */
2751 /* Disable breakpoints on all catch clauses described in ARGS. */
2753 disable_catch (args)
2756 /* Map the disable command to catch clauses described in ARGS. */
2759 /* Enable breakpoints on all catch clauses described in ARGS. */
2764 /* Map the disable command to catch clauses described in ARGS. */
2767 /* Delete breakpoints on all catch clauses in the active scope. */
2772 /* Map the delete command to catch clauses described in ARGS. */
2777 catch_command (arg, from_tty)
2781 catch_command_1 (arg, 0, from_tty);
2785 clear_command (arg, from_tty)
2789 register struct breakpoint *b, *b1;
2790 struct symtabs_and_lines sals;
2791 struct symtab_and_line sal;
2792 register struct breakpoint *found;
2797 sals = decode_line_spec (arg, 1);
2801 sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
2802 sal.line = default_breakpoint_line;
2803 sal.symtab = default_breakpoint_symtab;
2805 if (sal.symtab == 0)
2806 error ("No source file specified.");
2812 for (i = 0; i < sals.nelts; i++)
2814 /* If exact pc given, clear bpts at that pc.
2815 But if sal.pc is zero, clear all bpts on specified line. */
2817 found = (struct breakpoint *) 0;
2818 while (breakpoint_chain
2820 ? breakpoint_chain->address == sal.pc
2821 : (breakpoint_chain->source_file != NULL
2822 && sal.symtab != NULL
2823 && STREQ (breakpoint_chain->source_file,
2824 sal.symtab->filename)
2825 && breakpoint_chain->line_number == sal.line)))
2827 b1 = breakpoint_chain;
2828 breakpoint_chain = b1->next;
2835 && b->next->type != bp_watchpoint
2836 && b->next->type != bp_hardware_watchpoint
2838 ? b->next->address == sal.pc
2839 : (b->next->source_file != NULL
2840 && sal.symtab != NULL
2841 && STREQ (b->next->source_file, sal.symtab->filename)
2842 && b->next->line_number == sal.line)))
2853 error ("No breakpoint at %s.", arg);
2855 error ("No breakpoint at this line.");
2858 if (found->next) from_tty = 1; /* Always report if deleted more than one */
2859 if (from_tty) printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
2860 breakpoints_changed ();
2863 if (from_tty) printf_unfiltered ("%d ", found->number);
2865 delete_breakpoint (found);
2868 if (from_tty) putchar_unfiltered ('\n');
2870 free ((PTR)sals.sals);
2873 /* Delete breakpoint in BS if they are `delete' breakpoints.
2874 This is called after any breakpoint is hit, or after errors. */
2877 breakpoint_auto_delete (bs)
2880 for (; bs; bs = bs->next)
2881 if (bs->breakpoint_at && bs->breakpoint_at->disposition == delete
2883 delete_breakpoint (bs->breakpoint_at);
2886 /* Delete a breakpoint and clean up all traces of it in the data structures. */
2889 delete_breakpoint (bpt)
2890 struct breakpoint *bpt;
2892 register struct breakpoint *b;
2896 remove_breakpoint (bpt);
2898 if (breakpoint_chain == bpt)
2899 breakpoint_chain = bpt->next;
2904 b->next = bpt->next;
2908 check_duplicates (bpt->address);
2909 /* If this breakpoint was inserted, and there is another breakpoint
2910 at the same address, we need to insert the other breakpoint. */
2912 && bpt->type != bp_hardware_watchpoint)
2915 if (b->address == bpt->address
2917 && b->enable != disabled)
2920 val = target_insert_breakpoint (b->address, b->shadow_contents);
2923 target_terminal_ours_for_output ();
2924 fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number);
2925 memory_error (val, b->address); /* which bombs us out */
2932 free_command_lines (&bpt->commands);
2935 if (bpt->cond_string != NULL)
2936 free (bpt->cond_string);
2937 if (bpt->addr_string != NULL)
2938 free (bpt->addr_string);
2939 if (bpt->exp_string != NULL)
2940 free (bpt->exp_string);
2941 if (bpt->source_file != NULL)
2942 free (bpt->source_file);
2944 breakpoints_changed ();
2946 /* Be sure no bpstat's are pointing at it after it's been freed. */
2947 /* FIXME, how can we find all bpstat's?
2948 We just check stop_bpstat for now. */
2949 for (bs = stop_bpstat; bs; bs = bs->next)
2950 if (bs->breakpoint_at == bpt)
2951 bs->breakpoint_at = NULL;
2956 delete_command (arg, from_tty)
2963 /* Ask user only if there are some breakpoints to delete. */
2965 || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0)))
2967 /* No arg; clear all breakpoints. */
2968 while (breakpoint_chain)
2969 delete_breakpoint (breakpoint_chain);
2973 map_breakpoint_numbers (arg, delete_breakpoint);
2976 /* Reset a breakpoint given it's struct breakpoint * BINT.
2977 The value we return ends up being the return value from catch_errors.
2978 Unused in this case. */
2981 breakpoint_re_set_one (bint)
2984 struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */
2986 struct symtabs_and_lines sals;
2988 enum enable save_enable;
2993 if (b->addr_string == NULL)
2995 /* Anything without a string can't be re-set. */
2996 delete_breakpoint (b);
2999 /* In case we have a problem, disable this breakpoint. We'll restore
3000 its status if we succeed. */
3001 save_enable = b->enable;
3002 b->enable = disabled;
3005 sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0, (char ***)NULL);
3006 for (i = 0; i < sals.nelts; i++)
3008 resolve_sal_pc (&sals.sals[i]);
3010 /* Reparse conditions, they might contain references to the
3012 if (b->cond_string != NULL)
3016 free ((PTR)b->cond);
3017 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
3020 /* We need to re-set the breakpoint if the address changes...*/
3021 if (b->address != sals.sals[i].pc
3022 /* ...or new and old breakpoints both have source files, and
3023 the source file name or the line number changes... */
3024 || (b->source_file != NULL
3025 && sals.sals[i].symtab != NULL
3026 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
3027 || b->line_number != sals.sals[i].line)
3029 /* ...or we switch between having a source file and not having
3031 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
3034 if (b->source_file != NULL)
3035 free (b->source_file);
3036 if (sals.sals[i].symtab == NULL)
3037 b->source_file = NULL;
3040 savestring (sals.sals[i].symtab->filename,
3041 strlen (sals.sals[i].symtab->filename));
3042 b->line_number = sals.sals[i].line;
3043 b->address = sals.sals[i].pc;
3045 check_duplicates (b->address);
3049 /* Might be better to do this just once per breakpoint_re_set,
3050 rather than once for every breakpoint. */
3051 breakpoints_changed ();
3053 b->enable = save_enable; /* Restore it, this worked. */
3055 free ((PTR)sals.sals);
3059 case bp_hardware_watchpoint:
3060 innermost_block = NULL;
3061 /* The issue arises of what context to evaluate this in. The same
3062 one as when it was set, but what does that mean when symbols have
3063 been re-read? We could save the filename and functionname, but
3064 if the context is more local than that, the best we could do would
3065 be something like how many levels deep and which index at that
3066 particular level, but that's going to be less stable than filenames
3067 or functionnames. */
3068 /* So for now, just use a global context. */
3069 b->exp = parse_expression (b->exp_string);
3070 b->exp_valid_block = innermost_block;
3071 b->val = evaluate_expression (b->exp);
3072 release_value (b->val);
3073 if (VALUE_LAZY (b->val))
3074 value_fetch_lazy (b->val);
3076 if (b->cond_string != NULL)
3079 b->cond = parse_exp_1 (&s, (struct block *)0, 0);
3081 if (b->enable == enabled)
3086 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
3091 case bp_longjmp_resume:
3092 case bp_watchpoint_scope:
3094 delete_breakpoint (b);
3101 /* Re-set all breakpoints after symbols have been re-loaded. */
3103 breakpoint_re_set ()
3105 struct breakpoint *b, *temp;
3106 static char message1[] = "Error in re-setting breakpoint %d:\n";
3107 char message[sizeof (message1) + 30 /* slop */];
3109 ALL_BREAKPOINTS_SAFE (b, temp)
3111 sprintf (message, message1, b->number); /* Format possible error msg */
3112 catch_errors (breakpoint_re_set_one, (char *) b, message,
3116 create_longjmp_breakpoint("longjmp");
3117 create_longjmp_breakpoint("_longjmp");
3118 create_longjmp_breakpoint("siglongjmp");
3119 create_longjmp_breakpoint(NULL);
3122 /* Took this out (temporaliy at least), since it produces an extra
3123 blank line at startup. This messes up the gdbtests. -PB */
3124 /* Blank line to finish off all those mention() messages we just printed. */
3125 printf_filtered ("\n");
3129 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
3130 If from_tty is nonzero, it prints a message to that effect,
3131 which ends with a period (no newline). */
3134 set_ignore_count (bptnum, count, from_tty)
3135 int bptnum, count, from_tty;
3137 register struct breakpoint *b;
3143 if (b->number == bptnum)
3145 b->ignore_count = count;
3148 else if (count == 0)
3149 printf_filtered ("Will stop next time breakpoint %d is reached.",
3151 else if (count == 1)
3152 printf_filtered ("Will ignore next crossing of breakpoint %d.",
3155 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
3157 breakpoints_changed ();
3161 error ("No breakpoint number %d.", bptnum);
3164 /* Clear the ignore counts of all breakpoints. */
3166 breakpoint_clear_ignore_counts ()
3168 struct breakpoint *b;
3171 b->ignore_count = 0;
3174 /* Command to set ignore-count of breakpoint N to COUNT. */
3177 ignore_command (args, from_tty)
3185 error_no_arg ("a breakpoint number");
3187 num = get_number (&p);
3190 error ("Second argument (specified ignore-count) is missing.");
3192 set_ignore_count (num,
3193 longest_to_int (value_as_long (parse_and_eval (p))),
3195 printf_filtered ("\n");
3196 breakpoints_changed ();
3199 /* Call FUNCTION on each of the breakpoints
3200 whose numbers are given in ARGS. */
3203 map_breakpoint_numbers (args, function)
3205 void (*function) PARAMS ((struct breakpoint *));
3207 register char *p = args;
3210 register struct breakpoint *b;
3213 error_no_arg ("one or more breakpoint numbers");
3219 num = get_number (&p1);
3222 if (b->number == num)
3224 struct breakpoint *related_breakpoint = b->related_breakpoint;
3226 if (related_breakpoint)
3227 function (related_breakpoint);
3230 printf_unfiltered ("No breakpoint number %d.\n", num);
3237 enable_breakpoint (bpt)
3238 struct breakpoint *bpt;
3240 FRAME save_selected_frame = NULL;
3241 int save_selected_frame_level = -1;
3243 bpt->enable = enabled;
3245 breakpoints_changed ();
3247 check_duplicates (bpt->address);
3248 if (bpt->type == bp_watchpoint || bpt->type == bp_hardware_watchpoint)
3250 if (bpt->exp_valid_block != NULL)
3252 FRAME fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
3256 Cannot enable watchpoint %d because the block in which its expression\n\
3257 is valid is not currently in scope.\n", bpt->number);
3258 bpt->enable = disabled;
3262 save_selected_frame = selected_frame;
3263 save_selected_frame_level = selected_frame_level;
3264 select_frame (fr, -1);
3267 value_free (bpt->val);
3269 bpt->val = evaluate_expression (bpt->exp);
3270 release_value (bpt->val);
3271 if (VALUE_LAZY (bpt->val))
3272 value_fetch_lazy (bpt->val);
3274 if (save_selected_frame_level >= 0)
3275 select_frame (save_selected_frame, save_selected_frame_level);
3281 enable_command (args, from_tty)
3285 struct breakpoint *bpt;
3287 ALL_BREAKPOINTS (bpt)
3292 case bp_hardware_watchpoint:
3293 enable_breakpoint (bpt);
3298 map_breakpoint_numbers (args, enable_breakpoint);
3302 disable_breakpoint (bpt)
3303 struct breakpoint *bpt;
3305 /* Never disable a watchpoint scope breakpoint; we want to
3306 hit them when we leave scope so we can delete both the
3307 watchpoint and its scope breakpoint at that time. */
3308 if (bpt->type == bp_watchpoint_scope)
3311 bpt->enable = disabled;
3313 breakpoints_changed ();
3315 check_duplicates (bpt->address);
3320 disable_command (args, from_tty)
3324 register struct breakpoint *bpt;
3326 ALL_BREAKPOINTS (bpt)
3331 case bp_hardware_watchpoint:
3332 disable_breakpoint (bpt);
3337 map_breakpoint_numbers (args, disable_breakpoint);
3341 enable_once_breakpoint (bpt)
3342 struct breakpoint *bpt;
3344 bpt->enable = enabled;
3345 bpt->disposition = disable;
3347 check_duplicates (bpt->address);
3348 breakpoints_changed ();
3353 enable_once_command (args, from_tty)
3357 map_breakpoint_numbers (args, enable_once_breakpoint);
3361 enable_delete_breakpoint (bpt)
3362 struct breakpoint *bpt;
3364 bpt->enable = enabled;
3365 bpt->disposition = delete;
3367 check_duplicates (bpt->address);
3368 breakpoints_changed ();
3373 enable_delete_command (args, from_tty)
3377 map_breakpoint_numbers (args, enable_delete_breakpoint);
3381 * Use default_breakpoint_'s, or nothing if they aren't valid.
3383 struct symtabs_and_lines
3384 decode_line_spec_1 (string, funfirstline)
3388 struct symtabs_and_lines sals;
3390 error ("Empty line specification.");
3391 if (default_breakpoint_valid)
3392 sals = decode_line_1 (&string, funfirstline,
3393 default_breakpoint_symtab, default_breakpoint_line,
3396 sals = decode_line_1 (&string, funfirstline,
3397 (struct symtab *)NULL, 0, (char ***)NULL);
3399 error ("Junk at end of line specification: %s", string);
3404 _initialize_breakpoint ()
3406 breakpoint_chain = 0;
3407 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
3408 before a breakpoint is set. */
3409 breakpoint_count = 0;
3411 add_com ("ignore", class_breakpoint, ignore_command,
3412 "Set ignore-count of breakpoint number N to COUNT.");
3414 add_com ("commands", class_breakpoint, commands_command,
3415 "Set commands to be executed when a breakpoint is hit.\n\
3416 Give breakpoint number as argument after \"commands\".\n\
3417 With no argument, the targeted breakpoint is the last one set.\n\
3418 The commands themselves follow starting on the next line.\n\
3419 Type a line containing \"end\" to indicate the end of them.\n\
3420 Give \"silent\" as the first line to make the breakpoint silent;\n\
3421 then no output is printed when it is hit, except what the commands print.");
3423 add_com ("condition", class_breakpoint, condition_command,
3424 "Specify breakpoint number N to break only if COND is true.\n\
3425 N is an integer; COND is an expression to be evaluated whenever\n\
3426 breakpoint N is reached. ");
3428 add_com ("tbreak", class_breakpoint, tbreak_command,
3429 "Set a temporary breakpoint. Args like \"break\" command.\n\
3430 Like \"break\" except the breakpoint is only temporary,\n\
3431 so it will be deleted when hit. Equivalent to \"break\" followed\n\
3432 by using \"enable delete\" on the breakpoint number.");
3434 add_prefix_cmd ("enable", class_breakpoint, enable_command,
3435 "Enable some breakpoints.\n\
3436 Give breakpoint numbers (separated by spaces) as arguments.\n\
3437 With no subcommand, breakpoints are enabled until you command otherwise.\n\
3438 This is used to cancel the effect of the \"disable\" command.\n\
3439 With a subcommand you can enable temporarily.",
3440 &enablelist, "enable ", 1, &cmdlist);
3442 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
3443 "Enable some breakpoints.\n\
3444 Give breakpoint numbers (separated by spaces) as arguments.\n\
3445 This is used to cancel the effect of the \"disable\" command.\n\
3446 May be abbreviated to simply \"enable\".\n",
3447 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
3449 add_cmd ("once", no_class, enable_once_command,
3450 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
3451 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
3454 add_cmd ("delete", no_class, enable_delete_command,
3455 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
3456 If a breakpoint is hit while enabled in this fashion, it is deleted.",
3459 add_cmd ("delete", no_class, enable_delete_command,
3460 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
3461 If a breakpoint is hit while enabled in this fashion, it is deleted.",
3464 add_cmd ("once", no_class, enable_once_command,
3465 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
3466 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
3469 add_prefix_cmd ("disable", class_breakpoint, disable_command,
3470 "Disable some breakpoints.\n\
3471 Arguments are breakpoint numbers with spaces in between.\n\
3472 To disable all breakpoints, give no argument.\n\
3473 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
3474 &disablelist, "disable ", 1, &cmdlist);
3475 add_com_alias ("dis", "disable", class_breakpoint, 1);
3476 add_com_alias ("disa", "disable", class_breakpoint, 1);
3478 add_cmd ("breakpoints", class_alias, disable_command,
3479 "Disable some breakpoints.\n\
3480 Arguments are breakpoint numbers with spaces in between.\n\
3481 To disable all breakpoints, give no argument.\n\
3482 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
3483 This command may be abbreviated \"disable\".",
3486 add_prefix_cmd ("delete", class_breakpoint, delete_command,
3487 "Delete some breakpoints or auto-display expressions.\n\
3488 Arguments are breakpoint numbers with spaces in between.\n\
3489 To delete all breakpoints, give no argument.\n\
3491 Also a prefix command for deletion of other GDB objects.\n\
3492 The \"unset\" command is also an alias for \"delete\".",
3493 &deletelist, "delete ", 1, &cmdlist);
3494 add_com_alias ("d", "delete", class_breakpoint, 1);
3496 add_cmd ("breakpoints", class_alias, delete_command,
3497 "Delete some breakpoints or auto-display expressions.\n\
3498 Arguments are breakpoint numbers with spaces in between.\n\
3499 To delete all breakpoints, give no argument.\n\
3500 This command may be abbreviated \"delete\".",
3503 add_com ("clear", class_breakpoint, clear_command,
3504 "Clear breakpoint at specified line or function.\n\
3505 Argument may be line number, function name, or \"*\" and an address.\n\
3506 If line number is specified, all breakpoints in that line are cleared.\n\
3507 If function is specified, breakpoints at beginning of function are cleared.\n\
3508 If an address is specified, breakpoints at that address are cleared.\n\n\
3509 With no argument, clears all breakpoints in the line that the selected frame\n\
3512 See also the \"delete\" command which clears breakpoints by number.");
3514 add_com ("break", class_breakpoint, break_command,
3515 "Set breakpoint at specified line or function.\n\
3516 Argument may be line number, function name, or \"*\" and an address.\n\
3517 If line number is specified, break at start of code for that line.\n\
3518 If function is specified, break at start of code for that function.\n\
3519 If an address is specified, break at that exact address.\n\
3520 With no arg, uses current execution address of selected stack frame.\n\
3521 This is useful for breaking on return to a stack frame.\n\
3523 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
3525 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
3526 add_com_alias ("b", "break", class_run, 1);
3527 add_com_alias ("br", "break", class_run, 1);
3528 add_com_alias ("bre", "break", class_run, 1);
3529 add_com_alias ("brea", "break", class_run, 1);
3531 add_info ("breakpoints", breakpoints_info,
3532 "Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
3533 The \"Type\" column indicates one of:\n\
3534 \tbreakpoint - normal breakpoint\n\
3535 \twatchpoint - watchpoint\n\
3536 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
3537 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
3538 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
3539 address and file/line number respectively.\n\n\
3540 Convenience variable \"$_\" and default examine address for \"x\"\n\
3541 are set to the address of the last breakpoint listed.\n\n\
3542 Convenience variable \"$bpnum\" contains the number of the last\n\
3545 #if MAINTENANCE_CMDS
3547 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
3548 "Status of all breakpoints, or breakpoint number NUMBER.\n\
3549 The \"Type\" column indicates one of:\n\
3550 \tbreakpoint - normal breakpoint\n\
3551 \twatchpoint - watchpoint\n\
3552 \tlongjmp - internal breakpoint used to step through longjmp()\n\
3553 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
3554 \tuntil - internal breakpoint used by the \"until\" command\n\
3555 \tfinish - internal breakpoint used by the \"finish\" command\n\
3556 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
3557 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
3558 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
3559 address and file/line number respectively.\n\n\
3560 Convenience variable \"$_\" and default examine address for \"x\"\n\
3561 are set to the address of the last breakpoint listed.\n\n\
3562 Convenience variable \"$bpnum\" contains the number of the last\n\
3564 &maintenanceinfolist);
3566 #endif /* MAINTENANCE_CMDS */
3568 add_com ("catch", class_breakpoint, catch_command,
3569 "Set breakpoints to catch exceptions that are raised.\n\
3570 Argument may be a single exception to catch, multiple exceptions\n\
3571 to catch, or the default exception \"default\". If no arguments\n\
3572 are given, breakpoints are set at all exception handlers catch clauses\n\
3573 within the current scope.\n\
3575 A condition specified for the catch applies to all breakpoints set\n\
3576 with this command\n\
3578 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
3580 add_com ("watch", class_breakpoint, watch_command,
3581 "Set a watchpoint for an expression.\n\
3582 A watchpoint stops execution of your program whenever the value of\n\
3583 an expression changes.");
3585 add_info ("watchpoints", breakpoints_info,
3586 "Synonym for ``info breakpoints''.");
3589 /* OK, when we call objfile_relocate, we need to relocate breakpoints
3590 too. breakpoint_re_set is not a good choice--for example, if
3591 addr_string contains just a line number without a file name the
3592 breakpoint might get set in a different file. In general, there is
3593 no need to go all the way back to the user's string (though this might
3594 work if some effort were made to canonicalize it), since symtabs and
3595 everything except addresses are still valid.
3597 Probably the best way to solve this is to have each breakpoint save
3598 the objfile and the section number that was used to set it (if set
3599 by "*addr", probably it is best to use find_pc_line to get a symtab
3600 and use the objfile and block_line_section for that symtab). Then
3601 objfile_relocate can call fixup_breakpoints with the objfile and
3602 the new_offsets, and it can relocate only the appropriate breakpoints. */
3604 #ifdef IBM6000_TARGET
3605 /* But for now, just kludge it based on the concept that before an
3606 objfile is relocated the breakpoint is below 0x10000000, and afterwards
3607 it is higher, so that way we only relocate each breakpoint once. */
3610 fixup_breakpoints (low, high, delta)
3615 struct breakpoint *b;
3619 if (b->address >= low && b->address <= high)
3620 b->address += delta;