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, enum bptype, 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 /* Walk the following statement or block through all breakpoints.
147 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
150 #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
152 #define ALL_BREAKPOINTS_SAFE(b,tmp) \
153 for (b = breakpoint_chain; \
154 b? (tmp=b->next, 1): 0; \
157 /* Chain of all breakpoints defined. */
159 struct breakpoint *breakpoint_chain;
161 /* Number of last breakpoint made. */
163 static int breakpoint_count;
165 /* Set breakpoint count to NUM. */
167 set_breakpoint_count (num)
170 breakpoint_count = num;
171 set_internalvar (lookup_internalvar ("bpnum"),
172 value_from_longest (builtin_type_int, (LONGEST) num));
175 /* Default address, symtab and line to put a breakpoint at
176 for "break" command with no arg.
177 if default_breakpoint_valid is zero, the other three are
178 not valid, and "break" with no arg is an error.
180 This set by print_stack_frame, which calls set_default_breakpoint. */
182 int default_breakpoint_valid;
183 CORE_ADDR default_breakpoint_address;
184 struct symtab *default_breakpoint_symtab;
185 int default_breakpoint_line;
187 /* Flag indicating extra verbosity for xgdb. */
188 extern int xgdb_verbose;
190 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
191 Advance *PP after the string and any trailing whitespace.
193 Currently the string can either be a number or "$" followed by the name
194 of a convenience variable. Making it an expression wouldn't work well
195 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
204 /* Empty line means refer to the last breakpoint. */
205 return breakpoint_count;
208 /* Make a copy of the name, so we can null-terminate it
209 to pass to lookup_internalvar(). */
214 while (isalnum (*p) || *p == '_')
216 varname = (char *) alloca (p - start + 1);
217 strncpy (varname, start, p - start);
218 varname[p - start] = '\0';
219 val = value_of_internalvar (lookup_internalvar (varname));
220 if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
222 "Convenience variables used to specify breakpoints must have integer values."
224 retval = (int) value_as_long (val);
230 while (*p >= '0' && *p <= '9')
233 /* There is no number here. (e.g. "cond a == b"). */
234 error_no_arg ("breakpoint number");
237 if (!(isspace (*p) || *p == '\0'))
238 error ("breakpoint number expected");
245 /* condition N EXP -- set break condition of breakpoint N to EXP. */
248 condition_command (arg, from_tty)
252 register struct breakpoint *b;
257 error_no_arg ("breakpoint number");
260 bnum = get_number (&p);
263 if (b->number == bnum)
270 if (b->cond_string != NULL)
271 free (b->cond_string);
276 b->cond_string = NULL;
278 printf ("Breakpoint %d now unconditional.\n", bnum);
283 /* I don't know if it matters whether this is the string the user
284 typed in or the decompiled expression. */
285 b->cond_string = savestring (arg, strlen (arg));
286 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
288 error ("Junk at end of expression");
293 error ("No breakpoint number %d.", bnum);
298 commands_command (arg, from_tty)
302 register struct breakpoint *b;
305 struct command_line *l;
307 /* If we allowed this, we would have problems with when to
308 free the storage, if we change the commands currently
311 if (executing_breakpoint_commands)
312 error ("Can't use the \"commands\" command among a breakpoint's commands.");
315 bnum = get_number (&p);
317 error ("Unexpected extra arguments following breakpoint number.");
320 if (b->number == bnum)
322 if (from_tty && input_from_terminal_p ())
324 printf ("Type commands for when breakpoint %d is hit, one per line.\n\
325 End with a line saying just \"end\".\n", bnum);
328 l = read_command_lines ();
329 free_command_lines (&b->commands);
333 error ("No breakpoint number %d.", bnum);
336 extern int memory_breakpoint_size; /* from mem-break.c */
338 /* Like target_read_memory() but if breakpoints are inserted, return
339 the shadow contents instead of the breakpoints themselves.
341 Read "memory data" from whatever target or inferior we have.
342 Returns zero if successful, errno value if not. EIO is used
343 for address out of bounds. If breakpoints are inserted, returns
344 shadow contents, not the breakpoints themselves. From breakpoint.c. */
347 read_memory_nobpt (memaddr, myaddr, len)
353 struct breakpoint *b;
355 if (memory_breakpoint_size < 0)
356 /* No breakpoints on this machine. */
357 return target_read_memory (memaddr, myaddr, len);
361 if (b->type == bp_watchpoint || !b->inserted)
363 else if (b->address + memory_breakpoint_size <= memaddr)
364 /* The breakpoint is entirely before the chunk of memory
367 else if (b->address >= memaddr + len)
368 /* The breakpoint is entirely after the chunk of memory we
373 /* Copy the breakpoint from the shadow contents, and recurse
374 for the things before and after. */
376 /* Addresses and length of the part of the breakpoint that
378 CORE_ADDR membpt = b->address;
379 unsigned int bptlen = memory_breakpoint_size;
380 /* Offset within shadow_contents. */
383 if (membpt < memaddr)
385 /* Only copy the second part of the breakpoint. */
386 bptlen -= memaddr - membpt;
387 bptoffset = memaddr - membpt;
391 if (membpt + bptlen > memaddr + len)
393 /* Only copy the first part of the breakpoint. */
394 bptlen -= (membpt + bptlen) - (memaddr + len);
397 bcopy (b->shadow_contents + bptoffset,
398 myaddr + membpt - memaddr, bptlen);
400 if (membpt > memaddr)
402 /* Copy the section of memory before the breakpoint. */
403 status = read_memory_nobpt (memaddr, myaddr, membpt - memaddr);
408 if (membpt + bptlen < memaddr + len)
410 /* Copy the section of memory after the breakpoint. */
411 status = read_memory_nobpt
413 myaddr + membpt + bptlen - memaddr,
414 memaddr + len - (membpt + bptlen));
421 /* Nothing overlaps. Just call read_memory_noerr. */
422 return target_read_memory (memaddr, myaddr, len);
425 /* insert_breakpoints is used when starting or continuing the program.
426 remove_breakpoints is used when the program stops.
427 Both return zero if successful,
428 or an `errno' value if could not write the inferior. */
431 insert_breakpoints ()
433 register struct breakpoint *b;
435 int disabled_breaks = 0;
438 if (b->type != bp_watchpoint
439 && b->enable != disabled
443 val = target_insert_breakpoint(b->address, b->shadow_contents);
446 /* Can't set the breakpoint. */
447 #if defined (DISABLE_UNSETTABLE_BREAK)
448 if (DISABLE_UNSETTABLE_BREAK (b->address))
451 b->enable = disabled;
452 if (!disabled_breaks)
455 "Cannot insert breakpoint %d:\n", b->number);
456 printf_filtered ("Disabling shared library breakpoints:\n");
459 printf_filtered ("%d ", b->number);
464 fprintf (stderr, "Cannot insert breakpoint %d:\n", b->number);
465 #ifdef ONE_PROCESS_WRITETEXT
467 "The same program may be running in another process.\n");
469 memory_error (val, b->address); /* which bombs us out */
476 printf_filtered ("\n");
481 remove_breakpoints ()
483 register struct breakpoint *b;
486 #ifdef BREAKPOINT_DEBUG
487 printf ("Removing breakpoints.\n");
488 #endif /* BREAKPOINT_DEBUG */
491 if (b->type != bp_watchpoint && b->inserted)
493 val = target_remove_breakpoint(b->address, b->shadow_contents);
497 #ifdef BREAKPOINT_DEBUG
498 printf ("Removed breakpoint at %s",
499 local_hex_string(b->address));
500 printf (", shadow %s",
501 local_hex_string(b->shadow_contents[0]));
503 local_hex_string(b->shadow_contents[1]));
504 #endif /* BREAKPOINT_DEBUG */
510 /* Clear the "inserted" flag in all breakpoints.
511 This is done when the inferior is loaded. */
514 mark_breakpoints_out ()
516 register struct breakpoint *b;
522 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
523 When continuing from a location with a breakpoint,
524 we actually single step once before calling insert_breakpoints. */
527 breakpoint_here_p (pc)
530 register struct breakpoint *b;
533 if (b->enable != disabled && b->address == pc)
539 /* bpstat stuff. External routines' interfaces are documented
542 /* Clear a bpstat so that it says we are not at any breakpoint.
543 Also free any storage that is part of a bpstat. */
558 if (p->old_val != NULL)
559 value_free (p->old_val);
566 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
567 is part of the bpstat is copied as well. */
580 for (; bs != NULL; bs = bs->next)
582 tmp = (bpstat) xmalloc (sizeof (*tmp));
583 bcopy (bs, tmp, sizeof (*tmp));
585 /* This is the first thing in the chain. */
595 /* Find the bpstat associated with this breakpoint */
598 bpstat_find_breakpoint(bsp, breakpoint)
600 struct breakpoint *breakpoint;
602 if (bsp == NULL) return NULL;
604 for (;bsp != NULL; bsp = bsp->next) {
605 if (bsp->breakpoint_at == breakpoint) return bsp;
610 /* Return the breakpoint number of the first breakpoint we are stopped
611 at. *BSP upon return is a bpstat which points to the remaining
612 breakpoints stopped at (but which is not guaranteed to be good for
613 anything but further calls to bpstat_num).
614 Return 0 if passed a bpstat which does not indicate any breakpoints. */
620 struct breakpoint *b;
623 return 0; /* No more breakpoint values */
626 b = (*bsp)->breakpoint_at;
629 return -1; /* breakpoint that's been deleted since */
631 return b->number; /* We have its number */
635 /* Modify BS so that the actions will not be performed. */
638 bpstat_clear_actions (bs)
641 for (; bs != NULL; bs = bs->next)
644 if (bs->old_val != NULL)
646 value_free (bs->old_val);
652 /* Stub for cleaning up our state if we error-out of a breakpoint command */
655 cleanup_executing_breakpoints (ignore)
658 executing_breakpoint_commands = 0;
661 /* Execute all the commands associated with all the breakpoints at this
662 location. Any of these commands could cause the process to proceed
663 beyond this point, etc. We look out for such changes by checking
664 the global "breakpoint_proceeded" after each command. */
667 bpstat_do_actions (bsp)
671 struct cleanup *old_chain;
673 executing_breakpoint_commands = 1;
674 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
679 breakpoint_proceeded = 0;
680 for (; bs != NULL; bs = bs->next)
684 char *line = bs->commands->line;
685 bs->commands = bs->commands->next;
686 execute_command (line, 0);
687 /* If the inferior is proceeded by the command, bomb out now.
688 The bpstat chain has been blown away by wait_for_inferior.
689 But since execution has stopped again, there is a new bpstat
690 to look at, so start over. */
691 if (breakpoint_proceeded)
696 executing_breakpoint_commands = 0;
697 discard_cleanups (old_chain);
700 /* Print a message indicating what happened. Returns nonzero to
701 say that only the source line should be printed after this (zero
702 return means print the frame as well as the source line). */
708 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
709 which has since been deleted. */
711 || bs->breakpoint_at == NULL
712 || (bs->breakpoint_at->type != bp_breakpoint
713 && bs->breakpoint_at->type != bp_watchpoint))
716 /* If bpstat_stop_status says don't print, OK, we won't. An example
717 circumstance is when we single-stepped for both a watchpoint and
718 for a "stepi" instruction. The bpstat says that the watchpoint
719 explains the stop, but we shouldn't print because the watchpoint's
720 value didn't change -- and the real reason we are stopping here
721 rather than continuing to step (as the watchpoint would've had us do)
722 is because of the "stepi". */
726 if (bs->breakpoint_at->type == bp_breakpoint)
728 /* I think the user probably only wants to see one breakpoint
729 number, not all of them. */
730 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
734 if (bs->old_val != NULL)
736 printf_filtered ("\nWatchpoint %d, ", bs->breakpoint_at->number);
737 print_expression (bs->breakpoint_at->exp, stdout);
738 printf_filtered ("\nOld value = ");
739 value_print (bs->old_val, stdout, 0, Val_pretty_default);
740 printf_filtered ("\nNew value = ");
741 value_print (bs->breakpoint_at->val, stdout, 0,
743 printf_filtered ("\n");
744 value_free (bs->old_val);
749 /* Maybe another breakpoint in the chain caused us to stop.
750 (Currently all watchpoints go on the bpstat whether hit or
751 not. That probably could (should) be changed, provided care is taken
752 with respect to bpstat_explains_signal). */
754 return bpstat_print (bs->next);
756 fprintf_filtered (stderr, "gdb internal error: in bpstat_print\n");
760 /* Evaluate the expression EXP and return 1 if value is zero.
761 This is used inside a catch_errors to evaluate the breakpoint condition.
762 The argument is a "struct expression *" that has been cast to char * to
763 make it pass through catch_errors. */
766 breakpoint_cond_eval (exp)
769 return !value_true (evaluate_expression ((struct expression *)exp));
772 /* Allocate a new bpstat and chain it to the current one. */
775 bpstat_alloc (b, cbs)
776 register struct breakpoint *b;
777 bpstat cbs; /* Current "bs" value */
781 bs = (bpstat) xmalloc (sizeof (*bs));
783 bs->breakpoint_at = b;
784 /* If the condition is false, etc., don't do the commands. */
786 bs->momentary = b->disposition == delete;
791 /* Determine whether we stopped at a breakpoint, etc, or whether we
792 don't understand this stop. Result is a chain of bpstat's such that:
794 if we don't understand the stop, the result is a null pointer.
796 if we understand why we stopped, the result is not null, and
797 the first element of the chain contains summary "stop" and
798 "print" flags for the whole chain.
800 Each element of the chain refers to a particular breakpoint or
801 watchpoint at which we have stopped. (We may have stopped for
804 Each element of the chain has valid next, breakpoint_at,
805 commands, FIXME??? fields.
811 bpstat_stop_status (pc, frame_address)
813 FRAME_ADDR frame_address;
815 register struct breakpoint *b;
819 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
820 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
821 int real_breakpoint = 0;
823 /* Root of the chain of bpstat's */
824 struct bpstat root_bs[1];
825 /* Pointer to the last thing in the chain currently. */
828 /* Get the address where the breakpoint would have been. */
829 bp_addr = *pc - DECR_PC_AFTER_BREAK;
836 if (b->enable == disabled)
839 if (b->type != bp_watchpoint && b->address != bp_addr)
842 /* Come here if it's a watchpoint, or if the break address matches */
844 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
849 if (b->type == bp_watchpoint)
851 int within_current_scope;
852 if (b->exp_valid_block != NULL)
853 within_current_scope =
854 contained_in (get_selected_block (), b->exp_valid_block);
856 within_current_scope = 1;
858 if (within_current_scope)
860 /* We use value_{,free_to_}mark because it could be a
861 *long* time before we return to the command level and
862 call free_all_values. */
864 value mark = value_mark ();
865 value new_val = evaluate_expression (b->exp);
866 if (!value_equal (b->val, new_val))
868 release_value (new_val);
869 value_free_to_mark (mark);
870 bs->old_val = b->val;
872 /* We will stop here */
876 /* Nothing changed, don't do anything. */
877 value_free_to_mark (mark);
879 /* We won't stop here */
884 /* This seems like the only logical thing to do because
885 if we temporarily ignored the watchpoint, then when
886 we reenter the block in which it is valid it contains
887 garbage (in the case of a function, it may have two
888 garbage values, one before and one after the prologue).
889 So we can't even detect the first assignment to it and
890 watch after that (since the garbage may or may not equal
891 the first value assigned). */
892 b->enable = disabled;
894 Watchpoint %d disabled because the program has left the block in\n\
895 which its expression is valid.\n", b->number);
896 /* We won't stop here */
897 /* FIXME, maybe we should stop here!!! */
901 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
906 if (b->frame && b->frame != frame_address)
914 /* Need to select the frame, with all that implies
915 so that the conditions will have the right context. */
916 select_frame (get_current_frame (), 0);
918 = catch_errors (breakpoint_cond_eval, (char *)(b->cond),
919 "Error in testing breakpoint condition:\n");
920 /* FIXME-someday, should give breakpoint # */
923 if (b->cond && value_is_zero)
927 else if (b->ignore_count > 0)
934 /* We will stop here */
935 if (b->disposition == disable)
936 b->enable = disabled;
937 bs->commands = b->commands;
940 if (bs->commands && !strcmp ("silent", bs->commands->line))
942 bs->commands = bs->commands->next;
953 bs->next = NULL; /* Terminate the chain */
954 bs = root_bs->next; /* Re-grab the head of the chain */
959 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
963 #if defined (SHIFT_INST_REGS)
965 CORE_ADDR pc = read_register (PC_REGNUM);
966 CORE_ADDR npc = read_register (NPC_REGNUM);
969 write_register (NNPC_REGNUM, npc);
970 write_register (NPC_REGNUM, pc);
973 #else /* No SHIFT_INST_REGS. */
975 #endif /* No SHIFT_INST_REGS. */
977 #endif /* DECR_PC_AFTER_BREAK != 0. */
982 /* Nonzero if we should step constantly (e.g. watchpoints on machines
983 without hardware support). This isn't related to a specific bpstat,
984 just to things like whether watchpoints are set. */
987 bpstat_should_step ()
989 struct breakpoint *b;
991 if (b->enable == enabled && b->type == bp_watchpoint)
996 /* Print information on breakpoint number BNUM, or -1 if all.
997 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
998 is nonzero, process only watchpoints. */
1001 breakpoint_1 (bnum, type, allflag)
1006 register struct breakpoint *b;
1007 register struct command_line *l;
1008 register struct symbol *sym;
1009 CORE_ADDR last_addr = (CORE_ADDR)-1;
1010 int found_a_breakpoint = 0;
1011 static char *bptypes[] = {"breakpoint", "until", "finish", "watchpoint",
1012 "longjmp", "longjmp resume"};
1013 static char *bpdisps[] = {"del", "dis", "keep"};
1014 static char bpenables[] = "ny";
1016 if (!breakpoint_chain)
1018 printf_filtered ("No breakpoints or watchpoints.\n");
1024 || bnum == b->number)
1026 /* We only print out user settable breakpoints unless the allflag is set. */
1028 && b->type != bp_breakpoint
1029 && b->type != bp_watchpoint)
1032 if (!found_a_breakpoint++)
1033 printf_filtered ("Num Type Disp Enb %sWhat\n",
1034 addressprint ? "Address " : "");
1036 printf_filtered ("%-3d %-14s %-4s %-3c ",
1039 bpdisps[b->disposition],
1040 bpenables[b->enable]);
1044 print_expression (b->exp, stdout);
1050 case bp_longjmp_resume:
1052 printf_filtered ("%s ", local_hex_string_custom(b->address, "08"));
1054 last_addr = b->address;
1057 sym = find_pc_function (b->address);
1060 fputs_filtered ("in ", stdout);
1061 fputs_demangled (SYMBOL_NAME (sym), stdout, 1);
1062 fputs_filtered (" at ", stdout);
1064 fputs_filtered (b->symtab->filename, stdout);
1065 printf_filtered (":%d", b->line_number);
1068 print_address_symbolic (b->address, stdout, demangle, " ");
1071 printf_filtered ("\n");
1074 printf_filtered ("\tstop only in stack frame at %s\n",
1075 local_hex_string(b->frame));
1078 printf_filtered ("\tstop only if ");
1079 print_expression (b->cond, stdout);
1080 printf_filtered ("\n");
1082 if (b->ignore_count)
1083 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
1084 if ((l = b->commands))
1087 fputs_filtered ("\t", stdout);
1088 fputs_filtered (l->line, stdout);
1089 fputs_filtered ("\n", stdout);
1094 if (!found_a_breakpoint
1096 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
1098 /* Compare against (CORE_ADDR)-1 in case some compiler decides
1099 that a comparison of an unsigned with -1 is always false. */
1100 if (last_addr != (CORE_ADDR)-1)
1101 set_next_address (last_addr);
1106 breakpoints_info (bnum_exp, from_tty)
1113 bnum = parse_and_eval_address (bnum_exp);
1115 breakpoint_1 (bnum, bp_breakpoint, 0);
1120 all_breakpoints_info (bnum_exp, from_tty)
1127 bnum = parse_and_eval_address (bnum_exp);
1129 breakpoint_1 (bnum, bp_breakpoint, 1);
1134 watchpoints_info (bnum_exp, from_tty)
1141 bnum = parse_and_eval_address (bnum_exp);
1143 breakpoint_1 (bnum, bp_watchpoint, 0);
1146 /* Print a message describing any breakpoints set at PC. */
1149 describe_other_breakpoints (pc)
1150 register CORE_ADDR pc;
1152 register int others = 0;
1153 register struct breakpoint *b;
1156 if (b->address == pc)
1160 printf ("Note: breakpoint%s ", (others > 1) ? "s" : "");
1162 if (b->address == pc)
1167 (b->enable == disabled) ? " (disabled)" : "",
1168 (others > 1) ? "," : ((others == 1) ? " and" : ""));
1170 printf ("also set at pc %s.\n", local_hex_string(pc));
1174 /* Set the default place to put a breakpoint
1175 for the `break' command with no arguments. */
1178 set_default_breakpoint (valid, addr, symtab, line)
1181 struct symtab *symtab;
1184 default_breakpoint_valid = valid;
1185 default_breakpoint_address = addr;
1186 default_breakpoint_symtab = symtab;
1187 default_breakpoint_line = line;
1190 /* Rescan breakpoints at address ADDRESS,
1191 marking the first one as "first" and any others as "duplicates".
1192 This is so that the bpt instruction is only inserted once. */
1195 check_duplicates (address)
1198 register struct breakpoint *b;
1199 register int count = 0;
1201 if (address == 0) /* Watchpoints are uninteresting */
1205 if (b->enable != disabled && b->address == address)
1208 b->duplicate = count > 1;
1212 /* Low level routine to set a breakpoint.
1213 Takes as args the three things that every breakpoint must have.
1214 Returns the breakpoint object so caller can set other things.
1215 Does not set the breakpoint number!
1216 Does not print anything.
1218 ==> This routine should not be called if there is a chance of later
1219 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
1220 your arguments BEFORE calling this routine! */
1222 static struct breakpoint *
1223 set_raw_breakpoint (sal)
1224 struct symtab_and_line sal;
1226 register struct breakpoint *b, *b1;
1228 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
1229 bzero (b, sizeof *b);
1230 b->address = sal.pc;
1231 b->symtab = sal.symtab;
1232 b->line_number = sal.line;
1233 b->enable = enabled;
1236 b->ignore_count = 0;
1240 /* Add this breakpoint to the end of the chain
1241 so that a list of breakpoints will come out in order
1242 of increasing numbers. */
1244 b1 = breakpoint_chain;
1246 breakpoint_chain = b;
1254 check_duplicates (sal.pc);
1260 create_longjmp_breakpoint(func_name)
1264 struct symtab_and_line sal;
1265 struct breakpoint *b;
1266 static int internal_breakpoint_number = -1;
1268 if (func_name != NULL)
1270 struct minimal_symbol *m;
1272 m = lookup_minimal_symbol(func_name, (struct objfile *)NULL);
1274 sal.pc = m->address;
1284 b = set_raw_breakpoint(sal);
1287 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
1288 b->disposition = donttouch;
1289 b->enable = disabled;
1292 b->addr_string = strsave(func_name);
1293 b->number = internal_breakpoint_number--;
1296 /* Call this routine when stepping and nexting to enable a breakpoint if we do
1297 a longjmp(). When we hit that breakpoint, call
1298 set_longjmp_resume_breakpoint() to figure out where we are going. */
1301 enable_longjmp_breakpoint()
1303 register struct breakpoint *b;
1306 if (b->type == bp_longjmp)
1307 b->enable = enabled;
1311 disable_longjmp_breakpoint()
1313 register struct breakpoint *b;
1316 if (b->type == bp_longjmp
1317 || b->type == bp_longjmp_resume)
1318 b->enable = disabled;
1321 /* Call this after hitting the longjmp() breakpoint. Use this to set a new
1322 breakpoint at the target of the jmp_buf.
1324 FIXME - This ought to be done by setting a temporary breakpoint that gets
1325 deleted automatically...
1329 set_longjmp_resume_breakpoint(pc, frame)
1333 register struct breakpoint *b;
1336 if (b->type == bp_longjmp_resume)
1339 b->enable = enabled;
1341 b->frame = FRAME_FP(frame);
1348 /* Set a breakpoint that will evaporate an end of command
1349 at address specified by SAL.
1350 Restrict it to frame FRAME if FRAME is nonzero. */
1353 set_momentary_breakpoint (sal, frame, type)
1354 struct symtab_and_line sal;
1358 register struct breakpoint *b;
1359 b = set_raw_breakpoint (sal);
1361 b->enable = enabled;
1362 b->disposition = donttouch;
1363 b->frame = (frame ? FRAME_FP (frame) : 0);
1369 clear_momentary_breakpoints ()
1371 register struct breakpoint *b;
1373 if (b->disposition == delete)
1375 delete_breakpoint (b);
1381 /* Tell the user we have just set a breakpoint B. */
1384 struct breakpoint *b;
1389 printf_filtered ("Watchpoint %d: ", b->number);
1390 print_expression (b->exp, stdout);
1393 printf_filtered ("Breakpoint %d at %s", b->number,
1394 local_hex_string(b->address));
1396 printf_filtered (": file %s, line %d.",
1397 b->symtab->filename, b->line_number);
1399 printf_filtered ("\n");
1403 /* Nobody calls this currently. */
1404 /* Set a breakpoint from a symtab and line.
1405 If TEMPFLAG is nonzero, it is a temporary breakpoint.
1406 ADDR_STRING is a malloc'd string holding the name of where we are
1407 setting the breakpoint. This is used later to re-set it after the
1408 program is relinked and symbols are reloaded.
1409 Print the same confirmation messages that the breakpoint command prints. */
1412 set_breakpoint (s, line, tempflag, addr_string)
1418 register struct breakpoint *b;
1419 struct symtab_and_line sal;
1424 resolve_sal_pc (&sal); /* Might error out */
1425 describe_other_breakpoints (sal.pc);
1427 b = set_raw_breakpoint (sal);
1428 set_breakpoint_count (breakpoint_count + 1);
1429 b->number = breakpoint_count;
1430 b->type = bp_breakpoint;
1432 b->addr_string = addr_string;
1433 b->enable = enabled;
1434 b->disposition = tempflag ? delete : donttouch;
1440 /* Set a breakpoint according to ARG (function, linenum or *address)
1441 and make it temporary if TEMPFLAG is nonzero. */
1444 break_command_1 (arg, tempflag, from_tty)
1446 int tempflag, from_tty;
1448 struct symtabs_and_lines sals;
1449 struct symtab_and_line sal;
1450 register struct expression *cond = 0;
1451 register struct breakpoint *b;
1453 /* Pointers in arg to the start, and one past the end, of the condition. */
1454 char *cond_start = NULL;
1456 /* Pointers in arg to the start, and one past the end,
1457 of the address part. */
1458 char *addr_start = NULL;
1466 sal.line = sal.pc = sal.end = 0;
1469 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
1471 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1472 && (arg[2] == ' ' || arg[2] == '\t')))
1474 if (default_breakpoint_valid)
1476 sals.sals = (struct symtab_and_line *)
1477 xmalloc (sizeof (struct symtab_and_line));
1478 sal.pc = default_breakpoint_address;
1479 sal.line = default_breakpoint_line;
1480 sal.symtab = default_breakpoint_symtab;
1485 error ("No default breakpoint address now.");
1491 /* Force almost all breakpoints to be in terms of the
1492 current_source_symtab (which is decode_line_1's default). This
1493 should produce the results we want almost all of the time while
1494 leaving default_breakpoint_* alone. */
1495 if (default_breakpoint_valid
1496 && (!current_source_symtab
1497 || (arg && (*arg == '+' || *arg == '-'))))
1498 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1499 default_breakpoint_line);
1501 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1509 /* Resolve all line numbers to PC's, and verify that conditions
1510 can be parsed, before setting any breakpoints. */
1511 for (i = 0; i < sals.nelts; i++)
1513 resolve_sal_pc (&sals.sals[i]);
1517 if (arg[0] == 'i' && arg[1] == 'f'
1518 && (arg[2] == ' ' || arg[2] == '\t'))
1522 cond = parse_exp_1 (&arg, block_for_pc (sals.sals[i].pc), 0);
1526 error ("Junk at end of arguments.");
1530 /* Now set all the breakpoints. */
1531 for (i = 0; i < sals.nelts; i++)
1536 describe_other_breakpoints (sal.pc);
1538 b = set_raw_breakpoint (sal);
1539 set_breakpoint_count (breakpoint_count + 1);
1540 b->number = breakpoint_count;
1541 b->type = bp_breakpoint;
1545 b->addr_string = savestring (addr_start, addr_end - addr_start);
1547 b->cond_string = savestring (cond_start, cond_end - cond_start);
1549 b->enable = enabled;
1550 b->disposition = tempflag ? delete : donttouch;
1557 printf ("Multiple breakpoints were set.\n");
1558 printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1563 /* Helper function for break_command_1 and disassemble_command. */
1566 resolve_sal_pc (sal)
1567 struct symtab_and_line *sal;
1571 if (sal->pc == 0 && sal->symtab != 0)
1573 pc = find_line_pc (sal->symtab, sal->line);
1575 error ("No line %d in file \"%s\".",
1576 sal->line, sal->symtab->filename);
1582 break_command (arg, from_tty)
1586 break_command_1 (arg, 0, from_tty);
1590 tbreak_command (arg, from_tty)
1594 break_command_1 (arg, 1, from_tty);
1599 watch_command (arg, from_tty)
1603 struct breakpoint *b;
1604 struct symtab_and_line sal;
1605 struct expression *exp;
1606 struct block *exp_valid_block;
1613 /* Parse arguments. */
1614 innermost_block = NULL;
1615 exp = parse_expression (arg);
1616 exp_valid_block = innermost_block;
1617 val = evaluate_expression (exp);
1618 release_value (val);
1620 /* Now set up the breakpoint. */
1621 b = set_raw_breakpoint (sal);
1622 set_breakpoint_count (breakpoint_count + 1);
1623 b->number = breakpoint_count;
1624 b->type = bp_watchpoint;
1625 b->disposition = donttouch;
1627 b->exp_valid_block = exp_valid_block;
1630 b->cond_string = NULL;
1635 * Helper routine for the until_command routine in infcmd.c. Here
1636 * because it uses the mechanisms of breakpoints.
1640 until_break_command (arg, from_tty)
1644 struct symtabs_and_lines sals;
1645 struct symtab_and_line sal;
1646 FRAME prev_frame = get_prev_frame (selected_frame);
1647 struct breakpoint *breakpoint;
1648 struct cleanup *old_chain;
1650 clear_proceed_status ();
1652 /* Set a breakpoint where the user wants it and at return from
1655 if (default_breakpoint_valid)
1656 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1657 default_breakpoint_line);
1659 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1661 if (sals.nelts != 1)
1662 error ("Couldn't get information on specified line.");
1665 free (sals.sals); /* malloc'd, so freed */
1668 error ("Junk at end of arguments.");
1670 resolve_sal_pc (&sal);
1672 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
1674 old_chain = make_cleanup(delete_breakpoint, breakpoint);
1676 /* Keep within the current frame */
1680 struct frame_info *fi;
1682 fi = get_frame_info (prev_frame);
1683 sal = find_pc_line (fi->pc, 0);
1685 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
1686 make_cleanup(delete_breakpoint, breakpoint);
1689 proceed (-1, -1, 0);
1690 do_cleanups(old_chain);
1694 /* These aren't used; I don't konw what they were for. */
1695 /* Set a breakpoint at the catch clause for NAME. */
1697 catch_breakpoint (name)
1703 disable_catch_breakpoint ()
1708 delete_catch_breakpoint ()
1713 enable_catch_breakpoint ()
1720 struct sal_chain *next;
1721 struct symtab_and_line sal;
1725 /* This isn't used; I don't know what it was for. */
1726 /* For each catch clause identified in ARGS, run FUNCTION
1727 with that clause as an argument. */
1728 static struct symtabs_and_lines
1729 map_catch_names (args, function)
1733 register char *p = args;
1735 struct symtabs_and_lines sals;
1737 struct sal_chain *sal_chain = 0;
1741 error_no_arg ("one or more catch names");
1749 /* Don't swallow conditional part. */
1750 if (p1[0] == 'i' && p1[1] == 'f'
1751 && (p1[2] == ' ' || p1[2] == '\t'))
1757 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
1761 if (*p1 && *p1 != ' ' && *p1 != '\t')
1762 error ("Arguments must be catch names.");
1768 struct sal_chain *next
1769 = (struct sal_chain *)alloca (sizeof (struct sal_chain));
1770 next->next = sal_chain;
1771 next->sal = get_catch_sal (p);
1776 printf ("No catch clause for exception %s.\n", p);
1781 while (*p == ' ' || *p == '\t') p++;
1786 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
1788 static struct symtabs_and_lines
1789 get_catch_sals (this_level_only)
1790 int this_level_only;
1792 register struct blockvector *bl;
1793 register struct block *block;
1794 int index, have_default = 0;
1795 struct frame_info *fi;
1797 struct symtabs_and_lines sals;
1798 struct sal_chain *sal_chain = 0;
1799 char *blocks_searched;
1801 /* Not sure whether an error message is always the correct response,
1802 but it's better than a core dump. */
1803 if (selected_frame == NULL)
1804 error ("No selected frame.");
1805 block = get_frame_block (selected_frame);
1806 fi = get_frame_info (selected_frame);
1813 error ("No symbol table info available.\n");
1815 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
1816 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1817 bzero (blocks_searched, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1821 CORE_ADDR end = BLOCK_END (block) - 4;
1824 if (bl != blockvector_for_pc (end, &index))
1825 error ("blockvector blotch");
1826 if (BLOCKVECTOR_BLOCK (bl, index) != block)
1827 error ("blockvector botch");
1828 last_index = BLOCKVECTOR_NBLOCKS (bl);
1831 /* Don't print out blocks that have gone by. */
1832 while (index < last_index
1833 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
1836 while (index < last_index
1837 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
1839 if (blocks_searched[index] == 0)
1841 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
1844 register struct symbol *sym;
1846 nsyms = BLOCK_NSYMS (b);
1848 for (i = 0; i < nsyms; i++)
1850 sym = BLOCK_SYM (b, i);
1851 if (! strcmp (SYMBOL_NAME (sym), "default"))
1857 if (SYMBOL_CLASS (sym) == LOC_LABEL)
1859 struct sal_chain *next = (struct sal_chain *)
1860 alloca (sizeof (struct sal_chain));
1861 next->next = sal_chain;
1862 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
1866 blocks_searched[index] = 1;
1872 if (sal_chain && this_level_only)
1875 /* After handling the function's top-level block, stop.
1876 Don't continue to its superblock, the block of
1877 per-file symbols. */
1878 if (BLOCK_FUNCTION (block))
1880 block = BLOCK_SUPERBLOCK (block);
1885 struct sal_chain *tmp_chain;
1887 /* Count the number of entries. */
1888 for (index = 0, tmp_chain = sal_chain; tmp_chain;
1889 tmp_chain = tmp_chain->next)
1893 sals.sals = (struct symtab_and_line *)
1894 xmalloc (index * sizeof (struct symtab_and_line));
1895 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
1896 sals.sals[index] = sal_chain->sal;
1902 /* Commands to deal with catching exceptions. */
1905 catch_command_1 (arg, tempflag, from_tty)
1910 /* First, translate ARG into something we can deal with in terms
1913 struct symtabs_and_lines sals;
1914 struct symtab_and_line sal;
1915 register struct expression *cond = 0;
1916 register struct breakpoint *b;
1920 sal.line = sal.pc = sal.end = 0;
1923 /* If no arg given, or if first arg is 'if ', all active catch clauses
1924 are breakpointed. */
1926 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1927 && (arg[2] == ' ' || arg[2] == '\t')))
1929 /* Grab all active catch clauses. */
1930 sals = get_catch_sals (0);
1934 /* Grab selected catch clauses. */
1935 error ("catch NAME not implemeneted");
1937 /* This isn't used; I don't know what it was for. */
1938 sals = map_catch_names (arg, catch_breakpoint);
1946 for (i = 0; i < sals.nelts; i++)
1948 resolve_sal_pc (&sals.sals[i]);
1952 if (arg[0] == 'i' && arg[1] == 'f'
1953 && (arg[2] == ' ' || arg[2] == '\t'))
1954 cond = parse_exp_1 ((arg += 2, &arg),
1955 block_for_pc (sals.sals[i].pc), 0);
1957 error ("Junk at end of arguments.");
1962 for (i = 0; i < sals.nelts; i++)
1967 describe_other_breakpoints (sal.pc);
1969 b = set_raw_breakpoint (sal);
1970 set_breakpoint_count (breakpoint_count + 1);
1971 b->number = breakpoint_count;
1972 b->type = bp_breakpoint;
1974 b->enable = enabled;
1975 b->disposition = tempflag ? delete : donttouch;
1977 printf ("Breakpoint %d at %s", b->number, local_hex_string(b->address));
1979 printf (": file %s, line %d.", b->symtab->filename, b->line_number);
1985 printf ("Multiple breakpoints were set.\n");
1986 printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1992 /* These aren't used; I don't know what they were for. */
1993 /* Disable breakpoints on all catch clauses described in ARGS. */
1995 disable_catch (args)
1998 /* Map the disable command to catch clauses described in ARGS. */
2001 /* Enable breakpoints on all catch clauses described in ARGS. */
2006 /* Map the disable command to catch clauses described in ARGS. */
2009 /* Delete breakpoints on all catch clauses in the active scope. */
2014 /* Map the delete command to catch clauses described in ARGS. */
2019 catch_command (arg, from_tty)
2023 catch_command_1 (arg, 0, from_tty);
2027 clear_command (arg, from_tty)
2031 register struct breakpoint *b, *b1;
2032 struct symtabs_and_lines sals;
2033 struct symtab_and_line sal;
2034 register struct breakpoint *found;
2039 sals = decode_line_spec (arg, 1);
2043 sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
2044 sal.line = default_breakpoint_line;
2045 sal.symtab = default_breakpoint_symtab;
2047 if (sal.symtab == 0)
2048 error ("No source file specified.");
2054 for (i = 0; i < sals.nelts; i++)
2056 /* If exact pc given, clear bpts at that pc.
2057 But if sal.pc is zero, clear all bpts on specified line. */
2059 found = (struct breakpoint *) 0;
2060 while (breakpoint_chain
2061 && (sal.pc ? breakpoint_chain->address == sal.pc
2062 : (breakpoint_chain->symtab == sal.symtab
2063 && breakpoint_chain->line_number == sal.line)))
2065 b1 = breakpoint_chain;
2066 breakpoint_chain = b1->next;
2073 && b->next->type != bp_watchpoint
2074 && (sal.pc ? b->next->address == sal.pc
2075 : (b->next->symtab == sal.symtab
2076 && b->next->line_number == sal.line)))
2087 error ("No breakpoint at %s.", arg);
2089 error ("No breakpoint at this line.");
2092 if (found->next) from_tty = 1; /* Always report if deleted more than one */
2093 if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : "");
2096 if (from_tty) printf ("%d ", found->number);
2098 delete_breakpoint (found);
2101 if (from_tty) putchar ('\n');
2106 /* Delete breakpoint in BS if they are `delete' breakpoints.
2107 This is called after any breakpoint is hit, or after errors. */
2110 breakpoint_auto_delete (bs)
2113 for (; bs; bs = bs->next)
2114 if (bs->breakpoint_at && bs->breakpoint_at->disposition == delete)
2115 delete_breakpoint (bs->breakpoint_at);
2118 /* Delete a breakpoint and clean up all traces of it in the data structures. */
2121 delete_breakpoint (bpt)
2122 struct breakpoint *bpt;
2124 register struct breakpoint *b;
2128 target_remove_breakpoint(bpt->address, bpt->shadow_contents);
2130 if (breakpoint_chain == bpt)
2131 breakpoint_chain = bpt->next;
2136 b->next = bpt->next;
2140 check_duplicates (bpt->address);
2142 free_command_lines (&bpt->commands);
2145 if (bpt->cond_string != NULL)
2146 free (bpt->cond_string);
2147 if (bpt->addr_string != NULL)
2148 free (bpt->addr_string);
2150 if (xgdb_verbose && bpt->type == bp_breakpoint)
2151 printf ("breakpoint #%d deleted\n", bpt->number);
2153 /* Be sure no bpstat's are pointing at it after it's been freed. */
2154 /* FIXME, how can we find all bpstat's? We just check stop_bpstat for now. */
2155 for (bs = stop_bpstat; bs; bs = bs->next)
2156 if (bs->breakpoint_at == bpt)
2157 bs->breakpoint_at = NULL;
2162 delete_command (arg, from_tty)
2169 /* Ask user only if there are some breakpoints to delete. */
2171 || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0)))
2173 /* No arg; clear all breakpoints. */
2174 while (breakpoint_chain)
2175 delete_breakpoint (breakpoint_chain);
2179 map_breakpoint_numbers (arg, delete_breakpoint);
2182 /* Reset a breakpoint given it's struct breakpoint * BINT.
2183 The value we return ends up being the return value from catch_errors.
2184 Unused in this case. */
2187 breakpoint_re_set_one (bint)
2190 struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */
2192 struct symtabs_and_lines sals;
2194 enum enable save_enable;
2199 if (b->addr_string == NULL)
2201 /* Anything without a string can't be re-set. */
2202 delete_breakpoint (b);
2205 /* In case we have a problem, disable this breakpoint. We'll restore
2206 its status if we succeed. */
2207 save_enable = b->enable;
2208 b->enable = disabled;
2211 sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0);
2212 for (i = 0; i < sals.nelts; i++)
2214 resolve_sal_pc (&sals.sals[i]);
2215 if (b->symtab != sals.sals[i].symtab
2216 || b->line_number != sals.sals[i].line
2217 || b->address != sals.sals[i].pc)
2219 b->symtab = sals.sals[i].symtab;
2220 b->line_number = sals.sals[i].line;
2221 b->address = sals.sals[i].pc;
2223 if (b->cond_string != NULL)
2226 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
2229 check_duplicates (b->address);
2233 b->enable = save_enable; /* Restore it, this worked. */
2238 /* FIXME! This is the wrong thing to do.... */
2239 delete_breakpoint (b);
2242 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
2246 case bp_longjmp_resume:
2247 delete_breakpoint (b);
2254 /* Re-set all breakpoints after symbols have been re-loaded. */
2256 breakpoint_re_set ()
2258 struct breakpoint *b, *temp;
2259 static char message1[] = "Error in re-setting breakpoint %d:\n";
2260 char message[sizeof (message1) + 30 /* slop */];
2262 ALL_BREAKPOINTS_SAFE (b, temp)
2264 sprintf (message, message1, b->number); /* Format possible error msg */
2265 (void) catch_errors (breakpoint_re_set_one, (char *) b, message);
2268 create_longjmp_breakpoint("longjmp");
2269 create_longjmp_breakpoint("_longjmp");
2270 create_longjmp_breakpoint("siglongjmp");
2271 create_longjmp_breakpoint(NULL);
2273 /* Blank line to finish off all those mention() messages we just printed. */
2274 printf_filtered ("\n");
2277 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
2278 If from_tty is nonzero, it prints a message to that effect,
2279 which ends with a period (no newline). */
2282 set_ignore_count (bptnum, count, from_tty)
2283 int bptnum, count, from_tty;
2285 register struct breakpoint *b;
2291 if (b->number == bptnum)
2293 b->ignore_count = count;
2296 else if (count == 0)
2297 printf ("Will stop next time breakpoint %d is reached.", bptnum);
2298 else if (count == 1)
2299 printf ("Will ignore next crossing of breakpoint %d.", bptnum);
2301 printf ("Will ignore next %d crossings of breakpoint %d.",
2306 error ("No breakpoint number %d.", bptnum);
2309 /* Clear the ignore counts of all breakpoints. */
2311 breakpoint_clear_ignore_counts ()
2313 struct breakpoint *b;
2316 b->ignore_count = 0;
2319 /* Command to set ignore-count of breakpoint N to COUNT. */
2322 ignore_command (args, from_tty)
2330 error_no_arg ("a breakpoint number");
2332 num = get_number (&p);
2335 error ("Second argument (specified ignore-count) is missing.");
2337 set_ignore_count (num,
2338 longest_to_int (value_as_long (parse_and_eval (p))),
2343 /* Call FUNCTION on each of the breakpoints
2344 whose numbers are given in ARGS. */
2347 map_breakpoint_numbers (args, function)
2349 void (*function) PARAMS ((struct breakpoint *));
2351 register char *p = args;
2354 register struct breakpoint *b;
2357 error_no_arg ("one or more breakpoint numbers");
2363 num = get_number (&p1);
2366 if (b->number == num)
2371 printf ("No breakpoint number %d.\n", num);
2378 enable_breakpoint (bpt)
2379 struct breakpoint *bpt;
2381 bpt->enable = enabled;
2383 if (xgdb_verbose && bpt->type == bp_breakpoint)
2384 printf ("breakpoint #%d enabled\n", bpt->number);
2386 check_duplicates (bpt->address);
2387 if (bpt->type == bp_watchpoint)
2389 if (bpt->exp_valid_block != NULL
2390 && !contained_in (get_selected_block (), bpt->exp_valid_block))
2393 Cannot enable watchpoint %d because the block in which its expression\n\
2394 is valid is not currently in scope.\n", bpt->number);
2398 value_free (bpt->val);
2400 bpt->val = evaluate_expression (bpt->exp);
2401 release_value (bpt->val);
2407 enable_command (args, from_tty)
2411 struct breakpoint *bpt;
2413 ALL_BREAKPOINTS (bpt)
2414 enable_breakpoint (bpt);
2416 map_breakpoint_numbers (args, enable_breakpoint);
2420 disable_breakpoint (bpt)
2421 struct breakpoint *bpt;
2423 bpt->enable = disabled;
2425 if (xgdb_verbose && bpt->type == bp_breakpoint)
2426 printf ("breakpoint #%d disabled\n", bpt->number);
2428 check_duplicates (bpt->address);
2433 disable_command (args, from_tty)
2437 register struct breakpoint *bpt;
2439 ALL_BREAKPOINTS (bpt)
2440 disable_breakpoint (bpt);
2442 map_breakpoint_numbers (args, disable_breakpoint);
2446 enable_once_breakpoint (bpt)
2447 struct breakpoint *bpt;
2449 bpt->enable = enabled;
2450 bpt->disposition = disable;
2452 check_duplicates (bpt->address);
2457 enable_once_command (args, from_tty)
2461 map_breakpoint_numbers (args, enable_once_breakpoint);
2465 enable_delete_breakpoint (bpt)
2466 struct breakpoint *bpt;
2468 bpt->enable = enabled;
2469 bpt->disposition = delete;
2471 check_duplicates (bpt->address);
2476 enable_delete_command (args, from_tty)
2480 map_breakpoint_numbers (args, enable_delete_breakpoint);
2484 * Use default_breakpoint_'s, or nothing if they aren't valid.
2486 struct symtabs_and_lines
2487 decode_line_spec_1 (string, funfirstline)
2491 struct symtabs_and_lines sals;
2493 error ("Empty line specification.");
2494 if (default_breakpoint_valid)
2495 sals = decode_line_1 (&string, funfirstline,
2496 default_breakpoint_symtab, default_breakpoint_line);
2498 sals = decode_line_1 (&string, funfirstline, (struct symtab *)NULL, 0);
2500 error ("Junk at end of line specification: %s", string);
2505 /* Chain containing all defined enable commands. */
2507 extern struct cmd_list_element
2508 *enablelist, *disablelist,
2509 *deletelist, *enablebreaklist;
2511 extern struct cmd_list_element *cmdlist;
2514 _initialize_breakpoint ()
2516 breakpoint_chain = 0;
2517 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
2518 before a breakpoint is set. */
2519 breakpoint_count = 0;
2521 add_com ("ignore", class_breakpoint, ignore_command,
2522 "Set ignore-count of breakpoint number N to COUNT.");
2524 add_com ("commands", class_breakpoint, commands_command,
2525 "Set commands to be executed when a breakpoint is hit.\n\
2526 Give breakpoint number as argument after \"commands\".\n\
2527 With no argument, the targeted breakpoint is the last one set.\n\
2528 The commands themselves follow starting on the next line.\n\
2529 Type a line containing \"end\" to indicate the end of them.\n\
2530 Give \"silent\" as the first line to make the breakpoint silent;\n\
2531 then no output is printed when it is hit, except what the commands print.");
2533 add_com ("condition", class_breakpoint, condition_command,
2534 "Specify breakpoint number N to break only if COND is true.\n\
2535 N is an integer; COND is an expression to be evaluated whenever\n\
2536 breakpoint N is reached. ");
2538 add_com ("tbreak", class_breakpoint, tbreak_command,
2539 "Set a temporary breakpoint. Args like \"break\" command.\n\
2540 Like \"break\" except the breakpoint is only enabled temporarily,\n\
2541 so it will be disabled when hit. Equivalent to \"break\" followed\n\
2542 by using \"enable once\" on the breakpoint number.");
2544 add_prefix_cmd ("enable", class_breakpoint, enable_command,
2545 "Enable some breakpoints.\n\
2546 Give breakpoint numbers (separated by spaces) as arguments.\n\
2547 With no subcommand, breakpoints are enabled until you command otherwise.\n\
2548 This is used to cancel the effect of the \"disable\" command.\n\
2549 With a subcommand you can enable temporarily.",
2550 &enablelist, "enable ", 1, &cmdlist);
2552 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
2553 "Enable some breakpoints.\n\
2554 Give breakpoint numbers (separated by spaces) as arguments.\n\
2555 This is used to cancel the effect of the \"disable\" command.\n\
2556 May be abbreviated to simply \"enable\".\n",
2557 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
2559 add_cmd ("once", no_class, enable_once_command,
2560 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
2561 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2562 See the \"tbreak\" command which sets a breakpoint and enables it once.",
2565 add_cmd ("delete", no_class, enable_delete_command,
2566 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
2567 If a breakpoint is hit while enabled in this fashion, it is deleted.",
2570 add_cmd ("delete", no_class, enable_delete_command,
2571 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
2572 If a breakpoint is hit while enabled in this fashion, it is deleted.",
2575 add_cmd ("once", no_class, enable_once_command,
2576 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
2577 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2578 See the \"tbreak\" command which sets a breakpoint and enables it once.",
2581 add_prefix_cmd ("disable", class_breakpoint, disable_command,
2582 "Disable some breakpoints.\n\
2583 Arguments are breakpoint numbers with spaces in between.\n\
2584 To disable all breakpoints, give no argument.\n\
2585 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
2586 &disablelist, "disable ", 1, &cmdlist);
2587 add_com_alias ("dis", "disable", class_breakpoint, 1);
2588 add_com_alias ("disa", "disable", class_breakpoint, 1);
2590 add_cmd ("breakpoints", class_alias, disable_command,
2591 "Disable some breakpoints.\n\
2592 Arguments are breakpoint numbers with spaces in between.\n\
2593 To disable all breakpoints, give no argument.\n\
2594 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
2595 This command may be abbreviated \"disable\".",
2598 add_prefix_cmd ("delete", class_breakpoint, delete_command,
2599 "Delete some breakpoints or auto-display expressions.\n\
2600 Arguments are breakpoint numbers with spaces in between.\n\
2601 To delete all breakpoints, give no argument.\n\
2603 Also a prefix command for deletion of other GDB objects.\n\
2604 The \"unset\" command is also an alias for \"delete\".",
2605 &deletelist, "delete ", 1, &cmdlist);
2606 add_com_alias ("d", "delete", class_breakpoint, 1);
2608 add_cmd ("breakpoints", class_alias, delete_command,
2609 "Delete some breakpoints or auto-display expressions.\n\
2610 Arguments are breakpoint numbers with spaces in between.\n\
2611 To delete all breakpoints, give no argument.\n\
2612 This command may be abbreviated \"delete\".",
2615 add_com ("clear", class_breakpoint, clear_command,
2616 "Clear breakpoint at specified line or function.\n\
2617 Argument may be line number, function name, or \"*\" and an address.\n\
2618 If line number is specified, all breakpoints in that line are cleared.\n\
2619 If function is specified, breakpoints at beginning of function are cleared.\n\
2620 If an address is specified, breakpoints at that address are cleared.\n\n\
2621 With no argument, clears all breakpoints in the line that the selected frame\n\
2624 See also the \"delete\" command which clears breakpoints by number.");
2626 add_com ("break", class_breakpoint, break_command,
2627 "Set breakpoint at specified line or function.\n\
2628 Argument may be line number, function name, or \"*\" and an address.\n\
2629 If line number is specified, break at start of code for that line.\n\
2630 If function is specified, break at start of code for that function.\n\
2631 If an address is specified, break at that exact address.\n\
2632 With no arg, uses current execution address of selected stack frame.\n\
2633 This is useful for breaking on return to a stack frame.\n\
2635 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
2637 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2638 add_com_alias ("b", "break", class_run, 1);
2639 add_com_alias ("br", "break", class_run, 1);
2640 add_com_alias ("bre", "break", class_run, 1);
2641 add_com_alias ("brea", "break", class_run, 1);
2643 add_info ("breakpoints", breakpoints_info,
2644 "Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
2645 The \"Type\" column indicates one of:\n\
2646 \tbreakpoint - for normal breakpoints\n\
2647 \twatchpoint - for watchpoints\n\
2648 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
2649 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
2650 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
2651 address and file/line number respectively.\n\n\
2652 Convenience variable \"$_\" and default examine address for \"x\"\n\
2653 are set to the address of the last breakpoint listed.\n\n\
2654 Convenience variable \"$bpnum\" contains the number of the last\n\
2657 add_info ("all-breakpoints", all_breakpoints_info,
2658 "Status of all breakpoints, or breakpoint number NUMBER.\n\
2659 The \"Type\" column indicates one of:\n\
2660 \tbreakpoint - for normal breakpoints\n\
2661 \twatchpoint - for watchpoints\n\
2662 \tlongjmp - for internal breakpoints to handle stepping through longjmp()\n\
2663 \tlongjmp resume - for internal breakpoints at the target of longjmp()\n\
2664 \tuntil - for internal breakpoints used by the \"until\" command\n\
2665 \tfinish - for internal breakpoints used by the \"finish\" command\n\
2666 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
2667 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
2668 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
2669 address and file/line number respectively.\n\n\
2670 Convenience variable \"$_\" and default examine address for \"x\"\n\
2671 are set to the address of the last breakpoint listed.\n\n\
2672 Convenience variable \"$bpnum\" contains the number of the last\n\
2675 add_com ("catch", class_breakpoint, catch_command,
2676 "Set breakpoints to catch exceptions that are raised.\n\
2677 Argument may be a single exception to catch, multiple exceptions\n\
2678 to catch, or the default exception \"default\". If no arguments\n\
2679 are given, breakpoints are set at all exception handlers catch clauses\n\
2680 within the current scope.\n\
2682 A condition specified for the catch applies to all breakpoints set\n\
2683 with this command\n\
2685 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2687 add_com ("watch", class_breakpoint, watch_command,
2688 "Set a watchpoint for an expression.\n\
2689 A watchpoint stops execution of your program whenever the value of\n\
2690 an expression changes.");
2692 add_info ("watchpoints", watchpoints_info,
2693 "Status of all watchpoints, or watchpoint number NUMBER.\n\
2694 Second column is \"y\" for enabled watchpoints, \"n\" for disabled.");