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. */
25 #include "breakpoint.h"
27 #include "expression.h"
38 /* local function prototypes */
41 catch_command_1 PARAMS ((char *, int, int));
44 enable_delete_command PARAMS ((char *, int));
47 enable_delete_breakpoint PARAMS ((struct breakpoint *));
50 enable_once_command PARAMS ((char *, int));
53 enable_once_breakpoint PARAMS ((struct breakpoint *));
56 disable_command PARAMS ((char *, int));
59 disable_breakpoint PARAMS ((struct breakpoint *));
62 enable_command PARAMS ((char *, int));
65 enable_breakpoint PARAMS ((struct breakpoint *));
68 map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *)));
71 ignore_command PARAMS ((char *, int));
74 breakpoint_re_set_one PARAMS ((char *));
77 delete_command PARAMS ((char *, int));
80 clear_command PARAMS ((char *, int));
83 catch_command PARAMS ((char *, int));
85 static struct symtabs_and_lines
86 get_catch_sals PARAMS ((int));
89 watch_command PARAMS ((char *, int));
92 tbreak_command PARAMS ((char *, int));
95 break_command_1 PARAMS ((char *, int, int));
98 mention PARAMS ((struct breakpoint *));
100 static struct breakpoint *
101 set_raw_breakpoint PARAMS ((struct symtab_and_line));
104 check_duplicates PARAMS ((CORE_ADDR));
107 describe_other_breakpoints PARAMS ((CORE_ADDR));
110 watchpoints_info PARAMS ((char *, int));
113 breakpoints_info PARAMS ((char *, int));
116 breakpoint_1 PARAMS ((int, int));
119 bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
122 breakpoint_cond_eval PARAMS ((char *));
125 cleanup_executing_breakpoints PARAMS ((int));
128 commands_command PARAMS ((char *, int));
131 condition_command PARAMS ((char *, int));
134 get_number PARAMS ((char **));
137 set_breakpoint_count PARAMS ((int));
140 extern int addressprint; /* Print machine addresses? */
141 extern int demangle; /* Print de-mangled symbol names? */
143 /* Are we executing breakpoint commands? */
144 static int executing_breakpoint_commands;
146 #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
148 /* Chain of all breakpoints defined. */
150 struct breakpoint *breakpoint_chain;
152 /* Number of last breakpoint made. */
154 static int breakpoint_count;
156 /* Set breakpoint count to NUM. */
158 set_breakpoint_count (num)
161 breakpoint_count = num;
162 set_internalvar (lookup_internalvar ("bpnum"),
163 value_from_longest (builtin_type_int, (LONGEST) num));
166 /* Default address, symtab and line to put a breakpoint at
167 for "break" command with no arg.
168 if default_breakpoint_valid is zero, the other three are
169 not valid, and "break" with no arg is an error.
171 This set by print_stack_frame, which calls set_default_breakpoint. */
173 int default_breakpoint_valid;
174 CORE_ADDR default_breakpoint_address;
175 struct symtab *default_breakpoint_symtab;
176 int default_breakpoint_line;
178 /* Flag indicating extra verbosity for xgdb. */
179 extern int xgdb_verbose;
181 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
182 Advance *PP after the string and any trailing whitespace.
184 Currently the string can either be a number or "$" followed by the name
185 of a convenience variable. Making it an expression wouldn't work well
186 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
195 /* Empty line means refer to the last breakpoint. */
196 return breakpoint_count;
199 /* Make a copy of the name, so we can null-terminate it
200 to pass to lookup_internalvar(). */
205 while (isalnum (*p) || *p == '_')
207 varname = (char *) alloca (p - start + 1);
208 strncpy (varname, start, p - start);
209 varname[p - start] = '\0';
210 val = value_of_internalvar (lookup_internalvar (varname));
211 if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
213 "Convenience variables used to specify breakpoints must have integer values."
215 retval = (int) value_as_long (val);
219 while (*p >= '0' && *p <= '9')
222 /* There is no number here. (e.g. "cond a == b"). */
223 error_no_arg ("breakpoint number");
226 if (!(isspace (*p) || *p == '\0'))
227 error ("breakpoint number expected");
234 /* condition N EXP -- set break condition of breakpoint N to EXP. */
237 condition_command (arg, from_tty)
241 register struct breakpoint *b;
246 error_no_arg ("breakpoint number");
249 bnum = get_number (&p);
252 if (b->number == bnum)
259 if (b->cond_string != NULL)
260 free (b->cond_string);
265 b->cond_string = NULL;
267 printf ("Breakpoint %d now unconditional.\n", bnum);
272 /* I don't know if it matters whether this is the string the user
273 typed in or the decompiled expression. */
274 b->cond_string = savestring (arg, strlen (arg));
275 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
277 error ("Junk at end of expression");
282 error ("No breakpoint number %d.", bnum);
287 commands_command (arg, from_tty)
291 register struct breakpoint *b;
294 struct command_line *l;
296 /* If we allowed this, we would have problems with when to
297 free the storage, if we change the commands currently
300 if (executing_breakpoint_commands)
301 error ("Can't use the \"commands\" command among a breakpoint's commands.");
304 bnum = get_number (&p);
306 error ("Unexpected extra arguments following breakpoint number.");
309 if (b->number == bnum)
311 if (from_tty && input_from_terminal_p ())
313 printf ("Type commands for when breakpoint %d is hit, one per line.\n\
314 End with a line saying just \"end\".\n", bnum);
317 l = read_command_lines ();
318 free_command_lines (&b->commands);
322 error ("No breakpoint number %d.", bnum);
325 extern int memory_breakpoint_size; /* from mem-break.c */
327 /* Like target_read_memory() but if breakpoints are inserted, return
328 the shadow contents instead of the breakpoints themselves.
330 Read "memory data" from whatever target or inferior we have.
331 Returns zero if successful, errno value if not. EIO is used
332 for address out of bounds. If breakpoints are inserted, returns
333 shadow contents, not the breakpoints themselves. From breakpoint.c. */
336 read_memory_nobpt (memaddr, myaddr, len)
342 struct breakpoint *b;
344 if (memory_breakpoint_size < 0)
345 /* No breakpoints on this machine. */
346 return target_read_memory (memaddr, myaddr, len);
350 if (b->type == bp_watchpoint || !b->inserted)
352 else if (b->address + memory_breakpoint_size <= memaddr)
353 /* The breakpoint is entirely before the chunk of memory
356 else if (b->address >= memaddr + len)
357 /* The breakpoint is entirely after the chunk of memory we
362 /* Copy the breakpoint from the shadow contents, and recurse
363 for the things before and after. */
365 /* Addresses and length of the part of the breakpoint that
367 CORE_ADDR membpt = b->address;
368 unsigned int bptlen = memory_breakpoint_size;
369 /* Offset within shadow_contents. */
372 if (membpt < memaddr)
374 /* Only copy the second part of the breakpoint. */
375 bptlen -= memaddr - membpt;
376 bptoffset = memaddr - membpt;
380 if (membpt + bptlen > memaddr + len)
382 /* Only copy the first part of the breakpoint. */
383 bptlen -= (membpt + bptlen) - (memaddr + len);
386 bcopy (b->shadow_contents + bptoffset,
387 myaddr + membpt - memaddr, bptlen);
389 if (membpt > memaddr)
391 /* Copy the section of memory before the breakpoint. */
392 status = read_memory_nobpt (memaddr, myaddr, membpt - memaddr);
397 if (membpt + bptlen < memaddr + len)
399 /* Copy the section of memory after the breakpoint. */
400 status = read_memory_nobpt
402 myaddr + membpt + bptlen - memaddr,
403 memaddr + len - (membpt + bptlen));
410 /* Nothing overlaps. Just call read_memory_noerr. */
411 return target_read_memory (memaddr, myaddr, len);
414 /* insert_breakpoints is used when starting or continuing the program.
415 remove_breakpoints is used when the program stops.
416 Both return zero if successful,
417 or an `errno' value if could not write the inferior. */
420 insert_breakpoints ()
422 register struct breakpoint *b;
424 int disabled_breaks = 0;
427 if (b->type != bp_watchpoint
428 && b->enable != disabled
432 val = target_insert_breakpoint(b->address, b->shadow_contents);
435 /* Can't set the breakpoint. */
436 #if defined (DISABLE_UNSETTABLE_BREAK)
437 if (DISABLE_UNSETTABLE_BREAK (b->address))
440 b->enable = disabled;
441 if (!disabled_breaks)
444 "Cannot insert breakpoint %d:\n", b->number);
445 printf_filtered ("Disabling shared library breakpoints:\n");
448 printf_filtered ("%d ", b->number);
453 fprintf (stderr, "Cannot insert breakpoint %d:\n", b->number);
454 #ifdef ONE_PROCESS_WRITETEXT
456 "The same program may be running in another process.\n");
458 memory_error (val, b->address); /* which bombs us out */
465 printf_filtered ("\n");
470 remove_breakpoints ()
472 register struct breakpoint *b;
475 #ifdef BREAKPOINT_DEBUG
476 printf ("Removing breakpoints.\n");
477 #endif /* BREAKPOINT_DEBUG */
480 if (b->type != bp_watchpoint && b->inserted)
482 val = target_remove_breakpoint(b->address, b->shadow_contents);
486 #ifdef BREAKPOINT_DEBUG
487 printf ("Removed breakpoint at %s",
488 local_hex_string(b->address));
489 printf (", shadow %s",
490 local_hex_string(b->shadow_contents[0]));
492 local_hex_string(b->shadow_contents[1]));
493 #endif /* BREAKPOINT_DEBUG */
499 /* Clear the "inserted" flag in all breakpoints.
500 This is done when the inferior is loaded. */
503 mark_breakpoints_out ()
505 register struct breakpoint *b;
511 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
512 When continuing from a location with a breakpoint,
513 we actually single step once before calling insert_breakpoints. */
516 breakpoint_here_p (pc)
519 register struct breakpoint *b;
522 if (b->enable != disabled && b->address == pc)
528 /* bpstat stuff. External routines' interfaces are documented
531 /* Clear a bpstat so that it says we are not at any breakpoint.
532 Also free any storage that is part of a bpstat. */
547 if (p->old_val != NULL)
548 value_free (p->old_val);
555 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
556 is part of the bpstat is copied as well. */
569 for (; bs != NULL; bs = bs->next)
571 tmp = (bpstat) xmalloc (sizeof (*tmp));
572 bcopy (bs, tmp, sizeof (*tmp));
574 /* This is the first thing in the chain. */
584 /* Find the bpstat associated with this breakpoint */
587 bpstat_find_breakpoint(bsp, breakpoint)
589 struct breakpoint *breakpoint;
591 if (bsp == NULL) return NULL;
593 for (;bsp != NULL; bsp = bsp->next) {
594 if (bsp->breakpoint_at == breakpoint) return bsp;
599 /* Return the breakpoint number of the first breakpoint we are stopped
600 at. *BSP upon return is a bpstat which points to the remaining
601 breakpoints stopped at (but which is not guaranteed to be good for
602 anything but further calls to bpstat_num).
603 Return 0 if passed a bpstat which does not indicate any breakpoints. */
609 struct breakpoint *b;
612 return 0; /* No more breakpoint values */
615 b = (*bsp)->breakpoint_at;
618 return -1; /* breakpoint that's been deleted since */
620 return b->number; /* We have its number */
624 /* Modify BS so that the actions will not be performed. */
627 bpstat_clear_actions (bs)
630 for (; bs != NULL; bs = bs->next)
633 if (bs->old_val != NULL)
635 value_free (bs->old_val);
641 /* Stub for cleaning up our state if we error-out of a breakpoint command */
644 cleanup_executing_breakpoints (ignore)
647 executing_breakpoint_commands = 0;
650 /* Execute all the commands associated with all the breakpoints at this
651 location. Any of these commands could cause the process to proceed
652 beyond this point, etc. We look out for such changes by checking
653 the global "breakpoint_proceeded" after each command. */
656 bpstat_do_actions (bsp)
660 struct cleanup *old_chain;
662 executing_breakpoint_commands = 1;
663 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
668 breakpoint_proceeded = 0;
669 for (; bs != NULL; bs = bs->next)
673 char *line = bs->commands->line;
674 bs->commands = bs->commands->next;
675 execute_command (line, 0);
676 /* If the inferior is proceeded by the command, bomb out now.
677 The bpstat chain has been blown away by wait_for_inferior.
678 But since execution has stopped again, there is a new bpstat
679 to look at, so start over. */
680 if (breakpoint_proceeded)
685 executing_breakpoint_commands = 0;
686 discard_cleanups (old_chain);
689 /* Print a message indicating what happened. Returns nonzero to
690 say that only the source line should be printed after this (zero
691 return means print the frame as well as the source line). */
697 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
698 which has since been deleted. */
700 || bs->breakpoint_at == NULL
701 || (bs->breakpoint_at->type != bp_breakpoint
702 && bs->breakpoint_at->type != bp_watchpoint))
705 /* If bpstat_stop_status says don't print, OK, we won't. An example
706 circumstance is when we single-stepped for both a watchpoint and
707 for a "stepi" instruction. The bpstat says that the watchpoint
708 explains the stop, but we shouldn't print because the watchpoint's
709 value didn't change -- and the real reason we are stopping here
710 rather than continuing to step (as the watchpoint would've had us do)
711 is because of the "stepi". */
715 if (bs->breakpoint_at->type == bp_breakpoint)
717 /* I think the user probably only wants to see one breakpoint
718 number, not all of them. */
719 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
723 if (bs->old_val != NULL)
725 printf_filtered ("\nWatchpoint %d, ", bs->breakpoint_at->number);
726 print_expression (bs->breakpoint_at->exp, stdout);
727 printf_filtered ("\nOld value = ");
728 value_print (bs->old_val, stdout, 0, Val_pretty_default);
729 printf_filtered ("\nNew value = ");
730 value_print (bs->breakpoint_at->val, stdout, 0,
732 printf_filtered ("\n");
733 value_free (bs->old_val);
738 /* Maybe another breakpoint in the chain caused us to stop.
739 (Currently all watchpoints go on the bpstat whether hit or
740 not. That probably could (should) be changed, provided care is taken
741 with respect to bpstat_explains_signal). */
743 return bpstat_print (bs->next);
745 fprintf_filtered (stderr, "gdb internal error: in bpstat_print\n");
749 /* Evaluate the expression EXP and return 1 if value is zero.
750 This is used inside a catch_errors to evaluate the breakpoint condition.
751 The argument is a "struct expression *" that has been cast to char * to
752 make it pass through catch_errors. */
755 breakpoint_cond_eval (exp)
758 return !value_true (evaluate_expression ((struct expression *)exp));
761 /* Allocate a new bpstat and chain it to the current one. */
764 bpstat_alloc (b, cbs)
765 register struct breakpoint *b;
766 bpstat cbs; /* Current "bs" value */
770 bs = (bpstat) xmalloc (sizeof (*bs));
772 bs->breakpoint_at = b;
773 /* If the condition is false, etc., don't do the commands. */
775 bs->momentary = b->disposition == delete;
780 /* Determine whether we stopped at a breakpoint, etc, or whether we
781 don't understand this stop. Result is a chain of bpstat's such that:
783 if we don't understand the stop, the result is a null pointer.
785 if we understand why we stopped, the result is not null, and
786 the first element of the chain contains summary "stop" and
787 "print" flags for the whole chain.
789 Each element of the chain refers to a particular breakpoint or
790 watchpoint at which we have stopped. (We may have stopped for
793 Each element of the chain has valid next, breakpoint_at,
794 commands, FIXME??? fields.
800 bpstat_stop_status (pc, frame_address)
802 FRAME_ADDR frame_address;
804 register struct breakpoint *b;
808 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
809 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
810 int real_breakpoint = 0;
812 /* Root of the chain of bpstat's */
813 struct bpstat__struct root_bs[1];
814 /* Pointer to the last thing in the chain currently. */
817 /* Get the address where the breakpoint would have been. */
818 bp_addr = *pc - DECR_PC_AFTER_BREAK;
825 if (b->enable == disabled)
828 if (b->type != bp_watchpoint && b->address != bp_addr)
831 /* Come here if it's a watchpoint, or if the break address matches */
833 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
838 if (b->type == bp_watchpoint)
840 int within_current_scope;
841 if (b->exp_valid_block != NULL)
842 within_current_scope =
843 contained_in (get_selected_block (), b->exp_valid_block);
845 within_current_scope = 1;
847 if (within_current_scope)
849 /* We use value_{,free_to_}mark because it could be a
850 *long* time before we return to the command level and
851 call free_all_values. */
853 value mark = value_mark ();
854 value new_val = evaluate_expression (b->exp);
855 if (!value_equal (b->val, new_val))
857 release_value (new_val);
858 value_free_to_mark (mark);
859 bs->old_val = b->val;
861 /* We will stop here */
865 /* Nothing changed, don't do anything. */
866 value_free_to_mark (mark);
868 /* We won't stop here */
873 /* This seems like the only logical thing to do because
874 if we temporarily ignored the watchpoint, then when
875 we reenter the block in which it is valid it contains
876 garbage (in the case of a function, it may have two
877 garbage values, one before and one after the prologue).
878 So we can't even detect the first assignment to it and
879 watch after that (since the garbage may or may not equal
880 the first value assigned). */
881 b->enable = disabled;
883 Watchpoint %d disabled because the program has left the block in\n\
884 which its expression is valid.\n", b->number);
885 /* We won't stop here */
886 /* FIXME, maybe we should stop here!!! */
890 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
895 if (b->frame && b->frame != frame_address)
903 /* Need to select the frame, with all that implies
904 so that the conditions will have the right context. */
905 select_frame (get_current_frame (), 0);
907 = catch_errors (breakpoint_cond_eval, (char *)(b->cond),
908 "Error in testing breakpoint condition:\n");
909 /* FIXME-someday, should give breakpoint # */
912 if (b->cond && value_is_zero)
916 else if (b->ignore_count > 0)
923 /* We will stop here */
924 if (b->disposition == disable)
925 b->enable = disabled;
926 bs->commands = b->commands;
929 if (bs->commands && !strcmp ("silent", bs->commands->line))
931 bs->commands = bs->commands->next;
942 bs->next = NULL; /* Terminate the chain */
943 bs = root_bs->next; /* Re-grab the head of the chain */
948 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
952 #if defined (SHIFT_INST_REGS)
954 CORE_ADDR pc = read_register (PC_REGNUM);
955 CORE_ADDR npc = read_register (NPC_REGNUM);
958 write_register (NNPC_REGNUM, npc);
959 write_register (NPC_REGNUM, pc);
962 #else /* No SHIFT_INST_REGS. */
964 #endif /* No SHIFT_INST_REGS. */
966 #endif /* DECR_PC_AFTER_BREAK != 0. */
971 /* Nonzero if we should step constantly (e.g. watchpoints on machines
972 without hardware support). This isn't related to a specific bpstat,
973 just to things like whether watchpoints are set. */
976 bpstat_should_step ()
978 struct breakpoint *b;
980 if (b->enable == enabled && b->type == bp_watchpoint)
985 /* Print information on breakpoint number BNUM, or -1 if all.
986 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
987 is nonzero, process only watchpoints. */
990 breakpoint_1 (bnum, type)
994 register struct breakpoint *b;
995 register struct command_line *l;
996 register struct symbol *sym;
997 CORE_ADDR last_addr = (CORE_ADDR)-1;
998 int found_a_breakpoint = 0;
999 static char *bptypes[] = {"breakpoint", "until", "finish", "watchpoint",
1000 "longjmp", "longjmp resume"};
1001 static char *bpdisps[] = {"del", "dis", ""};
1002 static char bpenables[] = "ny";
1004 if (!breakpoint_chain)
1006 printf_filtered ("No breakpoints or watchpoints.\n");
1012 || bnum == b->number)
1014 if (!found_a_breakpoint++)
1015 printf_filtered ("Num Type Disp Enb %sWhat\n",
1016 addressprint ? "Address " : "");
1018 printf_filtered ("%-3d %-10s %-4s %-3c ",
1021 bpdisps[b->disposition],
1022 bpenables[b->enable]);
1026 print_expression (b->exp, stdout);
1030 printf_filtered ("%s ", local_hex_string_custom(b->address, "08"));
1032 last_addr = b->address;
1035 sym = find_pc_function (b->address);
1038 fputs_filtered ("in ", stdout);
1039 fputs_demangled (SYMBOL_NAME (sym), stdout, 1);
1040 fputs_filtered (" at ", stdout);
1042 fputs_filtered (b->symtab->filename, stdout);
1043 printf_filtered (":%d", b->line_number);
1046 print_address_symbolic (b->address, stdout, demangle, " ");
1049 printf_filtered ("\n");
1052 printf_filtered ("\tstop only in stack frame at %s\n",
1053 local_hex_string(b->frame));
1056 printf_filtered ("\tstop only if ");
1057 print_expression (b->cond, stdout);
1058 printf_filtered ("\n");
1060 if (b->ignore_count)
1061 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
1062 if ((l = b->commands))
1065 fputs_filtered ("\t", stdout);
1066 fputs_filtered (l->line, stdout);
1067 fputs_filtered ("\n", stdout);
1072 if (!found_a_breakpoint
1074 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
1076 /* Compare against (CORE_ADDR)-1 in case some compiler decides
1077 that a comparison of an unsigned with -1 is always false. */
1078 if (last_addr != (CORE_ADDR)-1)
1079 set_next_address (last_addr);
1084 breakpoints_info (bnum_exp, from_tty)
1091 bnum = parse_and_eval_address (bnum_exp);
1093 breakpoint_1 (bnum, bp_breakpoint);
1098 watchpoints_info (bnum_exp, from_tty)
1105 bnum = parse_and_eval_address (bnum_exp);
1107 breakpoint_1 (bnum, bp_watchpoint);
1110 /* Print a message describing any breakpoints set at PC. */
1113 describe_other_breakpoints (pc)
1114 register CORE_ADDR pc;
1116 register int others = 0;
1117 register struct breakpoint *b;
1120 if (b->address == pc)
1124 printf ("Note: breakpoint%s ", (others > 1) ? "s" : "");
1126 if (b->address == pc)
1131 (b->enable == disabled) ? " (disabled)" : "",
1132 (others > 1) ? "," : ((others == 1) ? " and" : ""));
1134 printf ("also set at pc %s.\n", local_hex_string(pc));
1138 /* Set the default place to put a breakpoint
1139 for the `break' command with no arguments. */
1142 set_default_breakpoint (valid, addr, symtab, line)
1145 struct symtab *symtab;
1148 default_breakpoint_valid = valid;
1149 default_breakpoint_address = addr;
1150 default_breakpoint_symtab = symtab;
1151 default_breakpoint_line = line;
1154 /* Rescan breakpoints at address ADDRESS,
1155 marking the first one as "first" and any others as "duplicates".
1156 This is so that the bpt instruction is only inserted once. */
1159 check_duplicates (address)
1162 register struct breakpoint *b;
1163 register int count = 0;
1165 if (address == 0) /* Watchpoints are uninteresting */
1169 if (b->enable != disabled && b->address == address)
1172 b->duplicate = count > 1;
1176 /* Low level routine to set a breakpoint.
1177 Takes as args the three things that every breakpoint must have.
1178 Returns the breakpoint object so caller can set other things.
1179 Does not set the breakpoint number!
1180 Does not print anything.
1182 ==> This routine should not be called if there is a chance of later
1183 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
1184 your arguments BEFORE calling this routine! */
1186 static struct breakpoint *
1187 set_raw_breakpoint (sal)
1188 struct symtab_and_line sal;
1190 register struct breakpoint *b, *b1;
1192 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
1193 bzero (b, sizeof *b);
1194 b->address = sal.pc;
1195 b->symtab = sal.symtab;
1196 b->line_number = sal.line;
1197 b->enable = enabled;
1200 b->ignore_count = 0;
1204 /* Add this breakpoint to the end of the chain
1205 so that a list of breakpoints will come out in order
1206 of increasing numbers. */
1208 b1 = breakpoint_chain;
1210 breakpoint_chain = b;
1218 check_duplicates (sal.pc);
1223 struct breakpoint *longjmp_breakpoint = NULL;
1224 struct breakpoint *_longjmp_breakpoint = NULL;
1225 struct breakpoint *siglongjmp_breakpoint = NULL;
1226 struct breakpoint *longjmp_resume_breakpoint = NULL;
1229 create_longjmp_breakpoint_1(func_name, bpt)
1231 struct breakpoint **bpt;
1234 struct symtab_and_line sal;
1235 struct breakpoint *b;
1239 delete_breakpoint(*bpt);
1243 if (func_name != NULL)
1245 struct minimal_symbol *m;
1247 m = lookup_minimal_symbol(func_name, (struct objfile *)NULL);
1249 sal.pc = m->address;
1261 b = set_raw_breakpoint(sal);
1265 b->type = bp_longjmp;
1266 b->disposition = donttouch;
1267 b->enable = disabled;
1272 /* Call this routine each time we read a new executable or symbol table
1275 #ifdef GET_LONGJMP_TARGET
1277 create_longjmp_breakpoint()
1279 create_longjmp_breakpoint_1("longjmp", &longjmp_breakpoint);
1280 create_longjmp_breakpoint_1("_longjmp", &_longjmp_breakpoint);
1281 create_longjmp_breakpoint_1("siglongjmp", &siglongjmp_breakpoint);
1283 if ((longjmp_breakpoint || _longjmp_breakpoint || siglongjmp_breakpoint)
1284 && !longjmp_resume_breakpoint)
1286 create_longjmp_breakpoint_1(NULL, &longjmp_resume_breakpoint);
1287 if (longjmp_resume_breakpoint)
1288 longjmp_resume_breakpoint->type = bp_longjmp_resume;
1293 create_longjmp_breakpoint()
1298 /* Call this routine when stepping and nexting to enable a breakpoint if we do
1299 a longjmp(). When we hit that breakpoint, call
1300 set_longjmp_resume_breakpoint() to figure out where we are going. */
1303 enable_longjmp_breakpoint()
1305 if (longjmp_breakpoint)
1306 longjmp_breakpoint->enable = enabled;
1307 if (_longjmp_breakpoint)
1308 _longjmp_breakpoint->enable = enabled;
1309 if (siglongjmp_breakpoint)
1310 siglongjmp_breakpoint->enable = enabled;
1314 disable_longjmp_breakpoint()
1316 if (longjmp_breakpoint)
1317 longjmp_breakpoint->enable = disabled;
1318 if (_longjmp_breakpoint)
1319 _longjmp_breakpoint->enable = disabled;
1320 if (siglongjmp_breakpoint)
1321 siglongjmp_breakpoint->enable = disabled;
1322 if (longjmp_resume_breakpoint)
1323 longjmp_resume_breakpoint->enable = disabled;
1326 /* Call this after hitting the longjmp() breakpoint. Use this to set a new
1327 breakpoint at the target of the jmp_buf.
1331 set_longjmp_resume_breakpoint(pc, frame)
1335 longjmp_resume_breakpoint->address = pc;
1336 longjmp_resume_breakpoint->enable = enabled;
1338 longjmp_resume_breakpoint->frame = FRAME_FP(frame);
1340 longjmp_resume_breakpoint->frame = 0;
1343 /* Set a breakpoint that will evaporate an end of command
1344 at address specified by SAL.
1345 Restrict it to frame FRAME if FRAME is nonzero. */
1348 set_momentary_breakpoint (sal, frame, type)
1349 struct symtab_and_line sal;
1353 register struct breakpoint *b;
1354 b = set_raw_breakpoint (sal);
1356 b->enable = enabled;
1357 b->disposition = donttouch;
1358 b->frame = (frame ? FRAME_FP (frame) : 0);
1364 clear_momentary_breakpoints ()
1366 register struct breakpoint *b;
1368 if (b->disposition == delete)
1370 delete_breakpoint (b);
1376 /* Tell the user we have just set a breakpoint B. */
1379 struct breakpoint *b;
1384 printf_filtered ("Watchpoint %d: ", b->number);
1385 print_expression (b->exp, stdout);
1388 printf_filtered ("Breakpoint %d at %s", b->number,
1389 local_hex_string(b->address));
1391 printf_filtered (": file %s, line %d.",
1392 b->symtab->filename, b->line_number);
1394 printf_filtered ("\n");
1398 /* Nobody calls this currently. */
1399 /* Set a breakpoint from a symtab and line.
1400 If TEMPFLAG is nonzero, it is a temporary breakpoint.
1401 ADDR_STRING is a malloc'd string holding the name of where we are
1402 setting the breakpoint. This is used later to re-set it after the
1403 program is relinked and symbols are reloaded.
1404 Print the same confirmation messages that the breakpoint command prints. */
1407 set_breakpoint (s, line, tempflag, addr_string)
1413 register struct breakpoint *b;
1414 struct symtab_and_line sal;
1419 resolve_sal_pc (&sal); /* Might error out */
1420 describe_other_breakpoints (sal.pc);
1422 b = set_raw_breakpoint (sal);
1423 set_breakpoint_count (breakpoint_count + 1);
1424 b->number = breakpoint_count;
1425 b->type = bp_breakpoint;
1427 b->addr_string = addr_string;
1428 b->enable = enabled;
1429 b->disposition = tempflag ? delete : donttouch;
1435 /* Set a breakpoint according to ARG (function, linenum or *address)
1436 and make it temporary if TEMPFLAG is nonzero. */
1439 break_command_1 (arg, tempflag, from_tty)
1441 int tempflag, from_tty;
1443 struct symtabs_and_lines sals;
1444 struct symtab_and_line sal;
1445 register struct expression *cond = 0;
1446 register struct breakpoint *b;
1448 /* Pointers in arg to the start, and one past the end, of the condition. */
1449 char *cond_start = NULL;
1451 /* Pointers in arg to the start, and one past the end,
1452 of the address part. */
1453 char *addr_start = NULL;
1461 sal.line = sal.pc = sal.end = 0;
1464 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
1466 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1467 && (arg[2] == ' ' || arg[2] == '\t')))
1469 if (default_breakpoint_valid)
1471 sals.sals = (struct symtab_and_line *)
1472 xmalloc (sizeof (struct symtab_and_line));
1473 sal.pc = default_breakpoint_address;
1474 sal.line = default_breakpoint_line;
1475 sal.symtab = default_breakpoint_symtab;
1480 error ("No default breakpoint address now.");
1486 /* Force almost all breakpoints to be in terms of the
1487 current_source_symtab (which is decode_line_1's default). This
1488 should produce the results we want almost all of the time while
1489 leaving default_breakpoint_* alone. */
1490 if (default_breakpoint_valid
1491 && (!current_source_symtab
1492 || (arg && (*arg == '+' || *arg == '-'))))
1493 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1494 default_breakpoint_line);
1496 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1504 /* Resolve all line numbers to PC's, and verify that conditions
1505 can be parsed, before setting any breakpoints. */
1506 for (i = 0; i < sals.nelts; i++)
1508 resolve_sal_pc (&sals.sals[i]);
1512 if (arg[0] == 'i' && arg[1] == 'f'
1513 && (arg[2] == ' ' || arg[2] == '\t'))
1517 cond = parse_exp_1 (&arg, block_for_pc (sals.sals[i].pc), 0);
1521 error ("Junk at end of arguments.");
1525 /* Now set all the breakpoints. */
1526 for (i = 0; i < sals.nelts; i++)
1531 describe_other_breakpoints (sal.pc);
1533 b = set_raw_breakpoint (sal);
1534 set_breakpoint_count (breakpoint_count + 1);
1535 b->number = breakpoint_count;
1536 b->type = bp_breakpoint;
1540 b->addr_string = savestring (addr_start, addr_end - addr_start);
1542 b->cond_string = savestring (cond_start, cond_end - cond_start);
1544 b->enable = enabled;
1545 b->disposition = tempflag ? delete : donttouch;
1552 printf ("Multiple breakpoints were set.\n");
1553 printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1558 /* Helper function for break_command_1 and disassemble_command. */
1561 resolve_sal_pc (sal)
1562 struct symtab_and_line *sal;
1566 if (sal->pc == 0 && sal->symtab != 0)
1568 pc = find_line_pc (sal->symtab, sal->line);
1570 error ("No line %d in file \"%s\".",
1571 sal->line, sal->symtab->filename);
1577 break_command (arg, from_tty)
1581 break_command_1 (arg, 0, from_tty);
1585 tbreak_command (arg, from_tty)
1589 break_command_1 (arg, 1, from_tty);
1594 watch_command (arg, from_tty)
1598 struct breakpoint *b;
1599 struct symtab_and_line sal;
1600 struct expression *exp;
1601 struct block *exp_valid_block;
1608 /* Parse arguments. */
1609 innermost_block = NULL;
1610 exp = parse_expression (arg);
1611 exp_valid_block = innermost_block;
1612 val = evaluate_expression (exp);
1613 release_value (val);
1615 /* Now set up the breakpoint. */
1616 b = set_raw_breakpoint (sal);
1617 set_breakpoint_count (breakpoint_count + 1);
1618 b->number = breakpoint_count;
1619 b->type = bp_watchpoint;
1620 b->disposition = donttouch;
1622 b->exp_valid_block = exp_valid_block;
1625 b->cond_string = NULL;
1630 * Helper routine for the until_command routine in infcmd.c. Here
1631 * because it uses the mechanisms of breakpoints.
1635 until_break_command (arg, from_tty)
1639 struct symtabs_and_lines sals;
1640 struct symtab_and_line sal;
1641 FRAME prev_frame = get_prev_frame (selected_frame);
1642 struct breakpoint *breakpoint;
1643 struct cleanup *old_chain;
1645 clear_proceed_status ();
1647 /* Set a breakpoint where the user wants it and at return from
1650 if (default_breakpoint_valid)
1651 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1652 default_breakpoint_line);
1654 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1656 if (sals.nelts != 1)
1657 error ("Couldn't get information on specified line.");
1660 free (sals.sals); /* malloc'd, so freed */
1663 error ("Junk at end of arguments.");
1665 resolve_sal_pc (&sal);
1667 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
1669 old_chain = make_cleanup(delete_breakpoint, breakpoint);
1671 /* Keep within the current frame */
1675 struct frame_info *fi;
1677 fi = get_frame_info (prev_frame);
1678 sal = find_pc_line (fi->pc, 0);
1680 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
1681 make_cleanup(delete_breakpoint, breakpoint);
1684 proceed (-1, -1, 0);
1685 do_cleanups(old_chain);
1689 /* These aren't used; I don't konw what they were for. */
1690 /* Set a breakpoint at the catch clause for NAME. */
1692 catch_breakpoint (name)
1698 disable_catch_breakpoint ()
1703 delete_catch_breakpoint ()
1708 enable_catch_breakpoint ()
1715 struct sal_chain *next;
1716 struct symtab_and_line sal;
1720 /* This isn't used; I don't know what it was for. */
1721 /* For each catch clause identified in ARGS, run FUNCTION
1722 with that clause as an argument. */
1723 static struct symtabs_and_lines
1724 map_catch_names (args, function)
1728 register char *p = args;
1730 struct symtabs_and_lines sals;
1732 struct sal_chain *sal_chain = 0;
1736 error_no_arg ("one or more catch names");
1744 /* Don't swallow conditional part. */
1745 if (p1[0] == 'i' && p1[1] == 'f'
1746 && (p1[2] == ' ' || p1[2] == '\t'))
1752 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
1756 if (*p1 && *p1 != ' ' && *p1 != '\t')
1757 error ("Arguments must be catch names.");
1763 struct sal_chain *next
1764 = (struct sal_chain *)alloca (sizeof (struct sal_chain));
1765 next->next = sal_chain;
1766 next->sal = get_catch_sal (p);
1771 printf ("No catch clause for exception %s.\n", p);
1776 while (*p == ' ' || *p == '\t') p++;
1781 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
1783 static struct symtabs_and_lines
1784 get_catch_sals (this_level_only)
1785 int this_level_only;
1787 register struct blockvector *bl;
1788 register struct block *block;
1789 int index, have_default = 0;
1790 struct frame_info *fi;
1792 struct symtabs_and_lines sals;
1793 struct sal_chain *sal_chain = 0;
1794 char *blocks_searched;
1796 /* Not sure whether an error message is always the correct response,
1797 but it's better than a core dump. */
1798 if (selected_frame == NULL)
1799 error ("No selected frame.");
1800 block = get_frame_block (selected_frame);
1801 fi = get_frame_info (selected_frame);
1808 error ("No symbol table info available.\n");
1810 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
1811 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1812 bzero (blocks_searched, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1816 CORE_ADDR end = BLOCK_END (block) - 4;
1819 if (bl != blockvector_for_pc (end, &index))
1820 error ("blockvector blotch");
1821 if (BLOCKVECTOR_BLOCK (bl, index) != block)
1822 error ("blockvector botch");
1823 last_index = BLOCKVECTOR_NBLOCKS (bl);
1826 /* Don't print out blocks that have gone by. */
1827 while (index < last_index
1828 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
1831 while (index < last_index
1832 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
1834 if (blocks_searched[index] == 0)
1836 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
1839 register struct symbol *sym;
1841 nsyms = BLOCK_NSYMS (b);
1843 for (i = 0; i < nsyms; i++)
1845 sym = BLOCK_SYM (b, i);
1846 if (! strcmp (SYMBOL_NAME (sym), "default"))
1852 if (SYMBOL_CLASS (sym) == LOC_LABEL)
1854 struct sal_chain *next = (struct sal_chain *)
1855 alloca (sizeof (struct sal_chain));
1856 next->next = sal_chain;
1857 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
1861 blocks_searched[index] = 1;
1867 if (sal_chain && this_level_only)
1870 /* After handling the function's top-level block, stop.
1871 Don't continue to its superblock, the block of
1872 per-file symbols. */
1873 if (BLOCK_FUNCTION (block))
1875 block = BLOCK_SUPERBLOCK (block);
1880 struct sal_chain *tmp_chain;
1882 /* Count the number of entries. */
1883 for (index = 0, tmp_chain = sal_chain; tmp_chain;
1884 tmp_chain = tmp_chain->next)
1888 sals.sals = (struct symtab_and_line *)
1889 xmalloc (index * sizeof (struct symtab_and_line));
1890 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
1891 sals.sals[index] = sal_chain->sal;
1897 /* Commands to deal with catching exceptions. */
1900 catch_command_1 (arg, tempflag, from_tty)
1905 /* First, translate ARG into something we can deal with in terms
1908 struct symtabs_and_lines sals;
1909 struct symtab_and_line sal;
1910 register struct expression *cond = 0;
1911 register struct breakpoint *b;
1915 sal.line = sal.pc = sal.end = 0;
1918 /* If no arg given, or if first arg is 'if ', all active catch clauses
1919 are breakpointed. */
1921 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1922 && (arg[2] == ' ' || arg[2] == '\t')))
1924 /* Grab all active catch clauses. */
1925 sals = get_catch_sals (0);
1929 /* Grab selected catch clauses. */
1930 error ("catch NAME not implemeneted");
1932 /* This isn't used; I don't know what it was for. */
1933 sals = map_catch_names (arg, catch_breakpoint);
1941 for (i = 0; i < sals.nelts; i++)
1943 resolve_sal_pc (&sals.sals[i]);
1947 if (arg[0] == 'i' && arg[1] == 'f'
1948 && (arg[2] == ' ' || arg[2] == '\t'))
1949 cond = parse_exp_1 ((arg += 2, &arg),
1950 block_for_pc (sals.sals[i].pc), 0);
1952 error ("Junk at end of arguments.");
1957 for (i = 0; i < sals.nelts; i++)
1962 describe_other_breakpoints (sal.pc);
1964 b = set_raw_breakpoint (sal);
1965 set_breakpoint_count (breakpoint_count + 1);
1966 b->number = breakpoint_count;
1967 b->type = bp_breakpoint;
1969 b->enable = enabled;
1970 b->disposition = tempflag ? delete : donttouch;
1972 printf ("Breakpoint %d at %s", b->number, local_hex_string(b->address));
1974 printf (": file %s, line %d.", b->symtab->filename, b->line_number);
1980 printf ("Multiple breakpoints were set.\n");
1981 printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1987 /* These aren't used; I don't know what they were for. */
1988 /* Disable breakpoints on all catch clauses described in ARGS. */
1990 disable_catch (args)
1993 /* Map the disable command to catch clauses described in ARGS. */
1996 /* Enable breakpoints on all catch clauses described in ARGS. */
2001 /* Map the disable command to catch clauses described in ARGS. */
2004 /* Delete breakpoints on all catch clauses in the active scope. */
2009 /* Map the delete command to catch clauses described in ARGS. */
2014 catch_command (arg, from_tty)
2018 catch_command_1 (arg, 0, from_tty);
2022 clear_command (arg, from_tty)
2026 register struct breakpoint *b, *b1;
2027 struct symtabs_and_lines sals;
2028 struct symtab_and_line sal;
2029 register struct breakpoint *found;
2034 sals = decode_line_spec (arg, 1);
2038 sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
2039 sal.line = default_breakpoint_line;
2040 sal.symtab = default_breakpoint_symtab;
2042 if (sal.symtab == 0)
2043 error ("No source file specified.");
2049 for (i = 0; i < sals.nelts; i++)
2051 /* If exact pc given, clear bpts at that pc.
2052 But if sal.pc is zero, clear all bpts on specified line. */
2054 found = (struct breakpoint *) 0;
2055 while (breakpoint_chain
2056 && (sal.pc ? breakpoint_chain->address == sal.pc
2057 : (breakpoint_chain->symtab == sal.symtab
2058 && breakpoint_chain->line_number == sal.line)))
2060 b1 = breakpoint_chain;
2061 breakpoint_chain = b1->next;
2068 && b->next->type != bp_watchpoint
2069 && (sal.pc ? b->next->address == sal.pc
2070 : (b->next->symtab == sal.symtab
2071 && b->next->line_number == sal.line)))
2082 error ("No breakpoint at %s.", arg);
2084 error ("No breakpoint at this line.");
2087 if (found->next) from_tty = 1; /* Always report if deleted more than one */
2088 if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : "");
2091 if (from_tty) printf ("%d ", found->number);
2093 delete_breakpoint (found);
2096 if (from_tty) putchar ('\n');
2101 /* Delete breakpoint in BS if they are `delete' breakpoints.
2102 This is called after any breakpoint is hit, or after errors. */
2105 breakpoint_auto_delete (bs)
2108 for (; bs; bs = bs->next)
2109 if (bs->breakpoint_at && bs->breakpoint_at->disposition == delete)
2110 delete_breakpoint (bs->breakpoint_at);
2113 /* Delete a breakpoint and clean up all traces of it in the data structures. */
2116 delete_breakpoint (bpt)
2117 struct breakpoint *bpt;
2119 register struct breakpoint *b;
2123 target_remove_breakpoint(bpt->address, bpt->shadow_contents);
2125 if (breakpoint_chain == bpt)
2126 breakpoint_chain = bpt->next;
2131 b->next = bpt->next;
2135 check_duplicates (bpt->address);
2137 free_command_lines (&bpt->commands);
2140 if (bpt->cond_string != NULL)
2141 free (bpt->cond_string);
2142 if (bpt->addr_string != NULL)
2143 free (bpt->addr_string);
2145 if (xgdb_verbose && bpt->type == bp_breakpoint)
2146 printf ("breakpoint #%d deleted\n", bpt->number);
2148 /* Be sure no bpstat's are pointing at it after it's been freed. */
2149 /* FIXME, how can we find all bpstat's? We just check stop_bpstat for now. */
2150 for (bs = stop_bpstat; bs; bs = bs->next)
2151 if (bs->breakpoint_at == bpt)
2152 bs->breakpoint_at = NULL;
2157 delete_command (arg, from_tty)
2164 /* Ask user only if there are some breakpoints to delete. */
2166 || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0)))
2168 /* No arg; clear all breakpoints. */
2169 while (breakpoint_chain)
2170 delete_breakpoint (breakpoint_chain);
2174 map_breakpoint_numbers (arg, delete_breakpoint);
2177 /* Reset a breakpoint given it's struct breakpoint * BINT.
2178 The value we return ends up being the return value from catch_errors.
2179 Unused in this case. */
2182 breakpoint_re_set_one (bint)
2185 struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */
2187 struct symtabs_and_lines sals;
2189 enum enable save_enable;
2191 if (b->type != bp_watchpoint && b->addr_string != NULL)
2193 /* In case we have a problem, disable this breakpoint. We'll restore
2194 its status if we succeed. */
2195 save_enable = b->enable;
2196 b->enable = disabled;
2199 sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0);
2200 for (i = 0; i < sals.nelts; i++)
2202 resolve_sal_pc (&sals.sals[i]);
2203 b->symtab = sals.sals[i].symtab;
2204 b->line_number = sals.sals[i].line;
2205 b->address = sals.sals[i].pc;
2207 if (b->cond_string != NULL)
2210 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
2213 check_duplicates (b->address);
2215 b->enable = save_enable; /* Restore it, this worked. */
2222 /* Anything without a string can't be re-set. */
2223 delete_breakpoint (b);
2228 /* Re-set all breakpoints after symbols have been re-loaded. */
2230 breakpoint_re_set ()
2232 struct breakpoint *b;
2233 static char message1[] = "Error in re-setting breakpoint %d:\n";
2234 char message[sizeof (message1) + 30 /* slop */];
2238 b->symtab = 0; /* Be sure we don't point to old dead symtab */
2239 sprintf (message, message1, b->number); /* Format possible error msg */
2240 (void) catch_errors (breakpoint_re_set_one, (char *) b, message);
2243 /* Blank line to finish off all those mention() messages we just printed. */
2244 printf_filtered ("\n");
2247 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
2248 If from_tty is nonzero, it prints a message to that effect,
2249 which ends with a period (no newline). */
2252 set_ignore_count (bptnum, count, from_tty)
2253 int bptnum, count, from_tty;
2255 register struct breakpoint *b;
2261 if (b->number == bptnum)
2263 b->ignore_count = count;
2266 else if (count == 0)
2267 printf ("Will stop next time breakpoint %d is reached.", bptnum);
2268 else if (count == 1)
2269 printf ("Will ignore next crossing of breakpoint %d.", bptnum);
2271 printf ("Will ignore next %d crossings of breakpoint %d.",
2276 error ("No breakpoint number %d.", bptnum);
2279 /* Clear the ignore counts of all breakpoints. */
2281 breakpoint_clear_ignore_counts ()
2283 struct breakpoint *b;
2286 b->ignore_count = 0;
2289 /* Command to set ignore-count of breakpoint N to COUNT. */
2292 ignore_command (args, from_tty)
2300 error_no_arg ("a breakpoint number");
2302 num = get_number (&p);
2305 error ("Second argument (specified ignore-count) is missing.");
2307 set_ignore_count (num,
2308 longest_to_int (value_as_long (parse_and_eval (p))),
2313 /* Call FUNCTION on each of the breakpoints
2314 whose numbers are given in ARGS. */
2317 map_breakpoint_numbers (args, function)
2319 void (*function) PARAMS ((struct breakpoint *));
2321 register char *p = args;
2324 register struct breakpoint *b;
2327 error_no_arg ("one or more breakpoint numbers");
2333 num = get_number (&p1);
2336 if (b->number == num)
2341 printf ("No breakpoint number %d.\n", num);
2348 enable_breakpoint (bpt)
2349 struct breakpoint *bpt;
2351 bpt->enable = enabled;
2353 if (xgdb_verbose && bpt->type == bp_breakpoint)
2354 printf ("breakpoint #%d enabled\n", bpt->number);
2356 check_duplicates (bpt->address);
2357 if (bpt->type == bp_watchpoint)
2359 if (bpt->exp_valid_block != NULL
2360 && !contained_in (get_selected_block (), bpt->exp_valid_block))
2363 Cannot enable watchpoint %d because the block in which its expression\n\
2364 is valid is not currently in scope.\n", bpt->number);
2368 value_free (bpt->val);
2370 bpt->val = evaluate_expression (bpt->exp);
2371 release_value (bpt->val);
2377 enable_command (args, from_tty)
2381 struct breakpoint *bpt;
2383 ALL_BREAKPOINTS (bpt)
2384 enable_breakpoint (bpt);
2386 map_breakpoint_numbers (args, enable_breakpoint);
2390 disable_breakpoint (bpt)
2391 struct breakpoint *bpt;
2393 bpt->enable = disabled;
2395 if (xgdb_verbose && bpt->type == bp_breakpoint)
2396 printf ("breakpoint #%d disabled\n", bpt->number);
2398 check_duplicates (bpt->address);
2403 disable_command (args, from_tty)
2407 register struct breakpoint *bpt;
2409 ALL_BREAKPOINTS (bpt)
2410 disable_breakpoint (bpt);
2412 map_breakpoint_numbers (args, disable_breakpoint);
2416 enable_once_breakpoint (bpt)
2417 struct breakpoint *bpt;
2419 bpt->enable = enabled;
2420 bpt->disposition = disable;
2422 check_duplicates (bpt->address);
2427 enable_once_command (args, from_tty)
2431 map_breakpoint_numbers (args, enable_once_breakpoint);
2435 enable_delete_breakpoint (bpt)
2436 struct breakpoint *bpt;
2438 bpt->enable = enabled;
2439 bpt->disposition = delete;
2441 check_duplicates (bpt->address);
2446 enable_delete_command (args, from_tty)
2450 map_breakpoint_numbers (args, enable_delete_breakpoint);
2454 * Use default_breakpoint_'s, or nothing if they aren't valid.
2456 struct symtabs_and_lines
2457 decode_line_spec_1 (string, funfirstline)
2461 struct symtabs_and_lines sals;
2463 error ("Empty line specification.");
2464 if (default_breakpoint_valid)
2465 sals = decode_line_1 (&string, funfirstline,
2466 default_breakpoint_symtab, default_breakpoint_line);
2468 sals = decode_line_1 (&string, funfirstline, (struct symtab *)NULL, 0);
2470 error ("Junk at end of line specification: %s", string);
2475 /* Chain containing all defined enable commands. */
2477 extern struct cmd_list_element
2478 *enablelist, *disablelist,
2479 *deletelist, *enablebreaklist;
2481 extern struct cmd_list_element *cmdlist;
2484 _initialize_breakpoint ()
2486 breakpoint_chain = 0;
2487 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
2488 before a breakpoint is set. */
2489 breakpoint_count = 0;
2491 add_com ("ignore", class_breakpoint, ignore_command,
2492 "Set ignore-count of breakpoint number N to COUNT.");
2494 add_com ("commands", class_breakpoint, commands_command,
2495 "Set commands to be executed when a breakpoint is hit.\n\
2496 Give breakpoint number as argument after \"commands\".\n\
2497 With no argument, the targeted breakpoint is the last one set.\n\
2498 The commands themselves follow starting on the next line.\n\
2499 Type a line containing \"end\" to indicate the end of them.\n\
2500 Give \"silent\" as the first line to make the breakpoint silent;\n\
2501 then no output is printed when it is hit, except what the commands print.");
2503 add_com ("condition", class_breakpoint, condition_command,
2504 "Specify breakpoint number N to break only if COND is true.\n\
2505 N is an integer; COND is an expression to be evaluated whenever\n\
2506 breakpoint N is reached. ");
2508 add_com ("tbreak", class_breakpoint, tbreak_command,
2509 "Set a temporary breakpoint. Args like \"break\" command.\n\
2510 Like \"break\" except the breakpoint is only enabled temporarily,\n\
2511 so it will be disabled when hit. Equivalent to \"break\" followed\n\
2512 by using \"enable once\" on the breakpoint number.");
2514 add_prefix_cmd ("enable", class_breakpoint, enable_command,
2515 "Enable some breakpoints.\n\
2516 Give breakpoint numbers (separated by spaces) as arguments.\n\
2517 With no subcommand, breakpoints are enabled until you command otherwise.\n\
2518 This is used to cancel the effect of the \"disable\" command.\n\
2519 With a subcommand you can enable temporarily.",
2520 &enablelist, "enable ", 1, &cmdlist);
2522 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
2523 "Enable some breakpoints.\n\
2524 Give breakpoint numbers (separated by spaces) as arguments.\n\
2525 This is used to cancel the effect of the \"disable\" command.\n\
2526 May be abbreviated to simply \"enable\".\n",
2527 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
2529 add_cmd ("once", no_class, enable_once_command,
2530 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
2531 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2532 See the \"tbreak\" command which sets a breakpoint and enables it once.",
2535 add_cmd ("delete", no_class, enable_delete_command,
2536 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
2537 If a breakpoint is hit while enabled in this fashion, it is deleted.",
2540 add_cmd ("delete", no_class, enable_delete_command,
2541 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
2542 If a breakpoint is hit while enabled in this fashion, it is deleted.",
2545 add_cmd ("once", no_class, enable_once_command,
2546 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
2547 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2548 See the \"tbreak\" command which sets a breakpoint and enables it once.",
2551 add_prefix_cmd ("disable", class_breakpoint, disable_command,
2552 "Disable some breakpoints.\n\
2553 Arguments are breakpoint numbers with spaces in between.\n\
2554 To disable all breakpoints, give no argument.\n\
2555 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
2556 &disablelist, "disable ", 1, &cmdlist);
2557 add_com_alias ("dis", "disable", class_breakpoint, 1);
2558 add_com_alias ("disa", "disable", class_breakpoint, 1);
2560 add_cmd ("breakpoints", class_alias, disable_command,
2561 "Disable some breakpoints.\n\
2562 Arguments are breakpoint numbers with spaces in between.\n\
2563 To disable all breakpoints, give no argument.\n\
2564 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
2565 This command may be abbreviated \"disable\".",
2568 add_prefix_cmd ("delete", class_breakpoint, delete_command,
2569 "Delete some breakpoints or auto-display expressions.\n\
2570 Arguments are breakpoint numbers with spaces in between.\n\
2571 To delete all breakpoints, give no argument.\n\
2573 Also a prefix command for deletion of other GDB objects.\n\
2574 The \"unset\" command is also an alias for \"delete\".",
2575 &deletelist, "delete ", 1, &cmdlist);
2576 add_com_alias ("d", "delete", class_breakpoint, 1);
2578 add_cmd ("breakpoints", class_alias, delete_command,
2579 "Delete some breakpoints or auto-display expressions.\n\
2580 Arguments are breakpoint numbers with spaces in between.\n\
2581 To delete all breakpoints, give no argument.\n\
2582 This command may be abbreviated \"delete\".",
2585 add_com ("clear", class_breakpoint, clear_command,
2586 "Clear breakpoint at specified line or function.\n\
2587 Argument may be line number, function name, or \"*\" and an address.\n\
2588 If line number is specified, all breakpoints in that line are cleared.\n\
2589 If function is specified, breakpoints at beginning of function are cleared.\n\
2590 If an address is specified, breakpoints at that address are cleared.\n\n\
2591 With no argument, clears all breakpoints in the line that the selected frame\n\
2594 See also the \"delete\" command which clears breakpoints by number.");
2596 add_com ("break", class_breakpoint, break_command,
2597 "Set breakpoint at specified line or function.\n\
2598 Argument may be line number, function name, or \"*\" and an address.\n\
2599 If line number is specified, break at start of code for that line.\n\
2600 If function is specified, break at start of code for that function.\n\
2601 If an address is specified, break at that exact address.\n\
2602 With no arg, uses current execution address of selected stack frame.\n\
2603 This is useful for breaking on return to a stack frame.\n\
2605 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
2607 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2608 add_com_alias ("b", "break", class_run, 1);
2609 add_com_alias ("br", "break", class_run, 1);
2610 add_com_alias ("bre", "break", class_run, 1);
2611 add_com_alias ("brea", "break", class_run, 1);
2613 add_info ("breakpoints", breakpoints_info,
2614 "Status of all breakpoints, or breakpoint number NUMBER.\n\
2615 Second column is \"y\" for enabled breakpoint, \"n\" for disabled,\n\
2616 \"o\" for enabled once (disable when hit), \"d\" for enable but delete when hit.\n\
2617 Then come the address and the file/line number.\n\n\
2618 Convenience variable \"$_\" and default examine address for \"x\"\n\
2619 are set to the address of the last breakpoint listed.\n\n\
2620 Convenience variable \"$bpnum\" contains the number of the last\n\
2623 add_com ("catch", class_breakpoint, catch_command,
2624 "Set breakpoints to catch exceptions that are raised.\n\
2625 Argument may be a single exception to catch, multiple exceptions\n\
2626 to catch, or the default exception \"default\". If no arguments\n\
2627 are given, breakpoints are set at all exception handlers catch clauses\n\
2628 within the current scope.\n\
2630 A condition specified for the catch applies to all breakpoints set\n\
2631 with this command\n\
2633 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2635 add_com ("watch", class_breakpoint, watch_command,
2636 "Set a watchpoint for an expression.\n\
2637 A watchpoint stops execution of your program whenever the value of\n\
2638 an expression changes.");
2640 add_info ("watchpoints", watchpoints_info,
2641 "Status of all watchpoints, or watchpoint number NUMBER.\n\
2642 Second column is \"y\" for enabled watchpoints, \"n\" for disabled.");