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;
1270 delete_breakpoint(*bpt);
1274 if (func_name != NULL)
1276 struct minimal_symbol *m;
1278 m = lookup_minimal_symbol(func_name, (struct objfile *)NULL);
1280 sal.pc = m->address;
1290 b = set_raw_breakpoint(sal);
1293 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
1294 b->disposition = donttouch;
1295 b->enable = disabled;
1298 b->addr_string = strsave(func_name);
1299 b->number = internal_breakpoint_number--;
1302 /* Call this routine when stepping and nexting to enable a breakpoint if we do
1303 a longjmp(). When we hit that breakpoint, call
1304 set_longjmp_resume_breakpoint() to figure out where we are going. */
1307 enable_longjmp_breakpoint()
1309 register struct breakpoint *b;
1312 if (b->type == bp_longjmp)
1313 b->enable = enabled;
1317 disable_longjmp_breakpoint()
1319 register struct breakpoint *b;
1322 if (b->type == bp_longjmp
1323 || b->type == bp_longjmp_resume)
1324 b->enable = disabled;
1327 /* Call this after hitting the longjmp() breakpoint. Use this to set a new
1328 breakpoint at the target of the jmp_buf.
1330 FIXME - This ought to be done by setting a temporary breakpoint that gets
1331 deleted automatically...
1335 set_longjmp_resume_breakpoint(pc, frame)
1339 register struct breakpoint *b;
1342 if (b->type == bp_longjmp_resume)
1345 b->enable = enabled;
1347 b->frame = FRAME_FP(frame);
1354 /* Set a breakpoint that will evaporate an end of command
1355 at address specified by SAL.
1356 Restrict it to frame FRAME if FRAME is nonzero. */
1359 set_momentary_breakpoint (sal, frame, type)
1360 struct symtab_and_line sal;
1364 register struct breakpoint *b;
1365 b = set_raw_breakpoint (sal);
1367 b->enable = enabled;
1368 b->disposition = donttouch;
1369 b->frame = (frame ? FRAME_FP (frame) : 0);
1375 clear_momentary_breakpoints ()
1377 register struct breakpoint *b;
1379 if (b->disposition == delete)
1381 delete_breakpoint (b);
1387 /* Tell the user we have just set a breakpoint B. */
1390 struct breakpoint *b;
1395 printf_filtered ("Watchpoint %d: ", b->number);
1396 print_expression (b->exp, stdout);
1399 printf_filtered ("Breakpoint %d at %s", b->number,
1400 local_hex_string(b->address));
1402 printf_filtered (": file %s, line %d.",
1403 b->symtab->filename, b->line_number);
1405 printf_filtered ("\n");
1409 /* Nobody calls this currently. */
1410 /* Set a breakpoint from a symtab and line.
1411 If TEMPFLAG is nonzero, it is a temporary breakpoint.
1412 ADDR_STRING is a malloc'd string holding the name of where we are
1413 setting the breakpoint. This is used later to re-set it after the
1414 program is relinked and symbols are reloaded.
1415 Print the same confirmation messages that the breakpoint command prints. */
1418 set_breakpoint (s, line, tempflag, addr_string)
1424 register struct breakpoint *b;
1425 struct symtab_and_line sal;
1430 resolve_sal_pc (&sal); /* Might error out */
1431 describe_other_breakpoints (sal.pc);
1433 b = set_raw_breakpoint (sal);
1434 set_breakpoint_count (breakpoint_count + 1);
1435 b->number = breakpoint_count;
1436 b->type = bp_breakpoint;
1438 b->addr_string = addr_string;
1439 b->enable = enabled;
1440 b->disposition = tempflag ? delete : donttouch;
1446 /* Set a breakpoint according to ARG (function, linenum or *address)
1447 and make it temporary if TEMPFLAG is nonzero. */
1450 break_command_1 (arg, tempflag, from_tty)
1452 int tempflag, from_tty;
1454 struct symtabs_and_lines sals;
1455 struct symtab_and_line sal;
1456 register struct expression *cond = 0;
1457 register struct breakpoint *b;
1459 /* Pointers in arg to the start, and one past the end, of the condition. */
1460 char *cond_start = NULL;
1462 /* Pointers in arg to the start, and one past the end,
1463 of the address part. */
1464 char *addr_start = NULL;
1472 sal.line = sal.pc = sal.end = 0;
1475 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
1477 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1478 && (arg[2] == ' ' || arg[2] == '\t')))
1480 if (default_breakpoint_valid)
1482 sals.sals = (struct symtab_and_line *)
1483 xmalloc (sizeof (struct symtab_and_line));
1484 sal.pc = default_breakpoint_address;
1485 sal.line = default_breakpoint_line;
1486 sal.symtab = default_breakpoint_symtab;
1491 error ("No default breakpoint address now.");
1497 /* Force almost all breakpoints to be in terms of the
1498 current_source_symtab (which is decode_line_1's default). This
1499 should produce the results we want almost all of the time while
1500 leaving default_breakpoint_* alone. */
1501 if (default_breakpoint_valid
1502 && (!current_source_symtab
1503 || (arg && (*arg == '+' || *arg == '-'))))
1504 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1505 default_breakpoint_line);
1507 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1515 /* Resolve all line numbers to PC's, and verify that conditions
1516 can be parsed, before setting any breakpoints. */
1517 for (i = 0; i < sals.nelts; i++)
1519 resolve_sal_pc (&sals.sals[i]);
1523 if (arg[0] == 'i' && arg[1] == 'f'
1524 && (arg[2] == ' ' || arg[2] == '\t'))
1528 cond = parse_exp_1 (&arg, block_for_pc (sals.sals[i].pc), 0);
1532 error ("Junk at end of arguments.");
1536 /* Now set all the breakpoints. */
1537 for (i = 0; i < sals.nelts; i++)
1542 describe_other_breakpoints (sal.pc);
1544 b = set_raw_breakpoint (sal);
1545 set_breakpoint_count (breakpoint_count + 1);
1546 b->number = breakpoint_count;
1547 b->type = bp_breakpoint;
1551 b->addr_string = savestring (addr_start, addr_end - addr_start);
1553 b->cond_string = savestring (cond_start, cond_end - cond_start);
1555 b->enable = enabled;
1556 b->disposition = tempflag ? delete : donttouch;
1563 printf ("Multiple breakpoints were set.\n");
1564 printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1569 /* Helper function for break_command_1 and disassemble_command. */
1572 resolve_sal_pc (sal)
1573 struct symtab_and_line *sal;
1577 if (sal->pc == 0 && sal->symtab != 0)
1579 pc = find_line_pc (sal->symtab, sal->line);
1581 error ("No line %d in file \"%s\".",
1582 sal->line, sal->symtab->filename);
1588 break_command (arg, from_tty)
1592 break_command_1 (arg, 0, from_tty);
1596 tbreak_command (arg, from_tty)
1600 break_command_1 (arg, 1, from_tty);
1605 watch_command (arg, from_tty)
1609 struct breakpoint *b;
1610 struct symtab_and_line sal;
1611 struct expression *exp;
1612 struct block *exp_valid_block;
1619 /* Parse arguments. */
1620 innermost_block = NULL;
1621 exp = parse_expression (arg);
1622 exp_valid_block = innermost_block;
1623 val = evaluate_expression (exp);
1624 release_value (val);
1626 /* Now set up the breakpoint. */
1627 b = set_raw_breakpoint (sal);
1628 set_breakpoint_count (breakpoint_count + 1);
1629 b->number = breakpoint_count;
1630 b->type = bp_watchpoint;
1631 b->disposition = donttouch;
1633 b->exp_valid_block = exp_valid_block;
1636 b->cond_string = NULL;
1641 * Helper routine for the until_command routine in infcmd.c. Here
1642 * because it uses the mechanisms of breakpoints.
1646 until_break_command (arg, from_tty)
1650 struct symtabs_and_lines sals;
1651 struct symtab_and_line sal;
1652 FRAME prev_frame = get_prev_frame (selected_frame);
1653 struct breakpoint *breakpoint;
1654 struct cleanup *old_chain;
1656 clear_proceed_status ();
1658 /* Set a breakpoint where the user wants it and at return from
1661 if (default_breakpoint_valid)
1662 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1663 default_breakpoint_line);
1665 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1667 if (sals.nelts != 1)
1668 error ("Couldn't get information on specified line.");
1671 free (sals.sals); /* malloc'd, so freed */
1674 error ("Junk at end of arguments.");
1676 resolve_sal_pc (&sal);
1678 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
1680 old_chain = make_cleanup(delete_breakpoint, breakpoint);
1682 /* Keep within the current frame */
1686 struct frame_info *fi;
1688 fi = get_frame_info (prev_frame);
1689 sal = find_pc_line (fi->pc, 0);
1691 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
1692 make_cleanup(delete_breakpoint, breakpoint);
1695 proceed (-1, -1, 0);
1696 do_cleanups(old_chain);
1700 /* These aren't used; I don't konw what they were for. */
1701 /* Set a breakpoint at the catch clause for NAME. */
1703 catch_breakpoint (name)
1709 disable_catch_breakpoint ()
1714 delete_catch_breakpoint ()
1719 enable_catch_breakpoint ()
1726 struct sal_chain *next;
1727 struct symtab_and_line sal;
1731 /* This isn't used; I don't know what it was for. */
1732 /* For each catch clause identified in ARGS, run FUNCTION
1733 with that clause as an argument. */
1734 static struct symtabs_and_lines
1735 map_catch_names (args, function)
1739 register char *p = args;
1741 struct symtabs_and_lines sals;
1743 struct sal_chain *sal_chain = 0;
1747 error_no_arg ("one or more catch names");
1755 /* Don't swallow conditional part. */
1756 if (p1[0] == 'i' && p1[1] == 'f'
1757 && (p1[2] == ' ' || p1[2] == '\t'))
1763 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
1767 if (*p1 && *p1 != ' ' && *p1 != '\t')
1768 error ("Arguments must be catch names.");
1774 struct sal_chain *next
1775 = (struct sal_chain *)alloca (sizeof (struct sal_chain));
1776 next->next = sal_chain;
1777 next->sal = get_catch_sal (p);
1782 printf ("No catch clause for exception %s.\n", p);
1787 while (*p == ' ' || *p == '\t') p++;
1792 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
1794 static struct symtabs_and_lines
1795 get_catch_sals (this_level_only)
1796 int this_level_only;
1798 register struct blockvector *bl;
1799 register struct block *block;
1800 int index, have_default = 0;
1801 struct frame_info *fi;
1803 struct symtabs_and_lines sals;
1804 struct sal_chain *sal_chain = 0;
1805 char *blocks_searched;
1807 /* Not sure whether an error message is always the correct response,
1808 but it's better than a core dump. */
1809 if (selected_frame == NULL)
1810 error ("No selected frame.");
1811 block = get_frame_block (selected_frame);
1812 fi = get_frame_info (selected_frame);
1819 error ("No symbol table info available.\n");
1821 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
1822 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1823 bzero (blocks_searched, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1827 CORE_ADDR end = BLOCK_END (block) - 4;
1830 if (bl != blockvector_for_pc (end, &index))
1831 error ("blockvector blotch");
1832 if (BLOCKVECTOR_BLOCK (bl, index) != block)
1833 error ("blockvector botch");
1834 last_index = BLOCKVECTOR_NBLOCKS (bl);
1837 /* Don't print out blocks that have gone by. */
1838 while (index < last_index
1839 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
1842 while (index < last_index
1843 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
1845 if (blocks_searched[index] == 0)
1847 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
1850 register struct symbol *sym;
1852 nsyms = BLOCK_NSYMS (b);
1854 for (i = 0; i < nsyms; i++)
1856 sym = BLOCK_SYM (b, i);
1857 if (! strcmp (SYMBOL_NAME (sym), "default"))
1863 if (SYMBOL_CLASS (sym) == LOC_LABEL)
1865 struct sal_chain *next = (struct sal_chain *)
1866 alloca (sizeof (struct sal_chain));
1867 next->next = sal_chain;
1868 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
1872 blocks_searched[index] = 1;
1878 if (sal_chain && this_level_only)
1881 /* After handling the function's top-level block, stop.
1882 Don't continue to its superblock, the block of
1883 per-file symbols. */
1884 if (BLOCK_FUNCTION (block))
1886 block = BLOCK_SUPERBLOCK (block);
1891 struct sal_chain *tmp_chain;
1893 /* Count the number of entries. */
1894 for (index = 0, tmp_chain = sal_chain; tmp_chain;
1895 tmp_chain = tmp_chain->next)
1899 sals.sals = (struct symtab_and_line *)
1900 xmalloc (index * sizeof (struct symtab_and_line));
1901 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
1902 sals.sals[index] = sal_chain->sal;
1908 /* Commands to deal with catching exceptions. */
1911 catch_command_1 (arg, tempflag, from_tty)
1916 /* First, translate ARG into something we can deal with in terms
1919 struct symtabs_and_lines sals;
1920 struct symtab_and_line sal;
1921 register struct expression *cond = 0;
1922 register struct breakpoint *b;
1926 sal.line = sal.pc = sal.end = 0;
1929 /* If no arg given, or if first arg is 'if ', all active catch clauses
1930 are breakpointed. */
1932 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1933 && (arg[2] == ' ' || arg[2] == '\t')))
1935 /* Grab all active catch clauses. */
1936 sals = get_catch_sals (0);
1940 /* Grab selected catch clauses. */
1941 error ("catch NAME not implemeneted");
1943 /* This isn't used; I don't know what it was for. */
1944 sals = map_catch_names (arg, catch_breakpoint);
1952 for (i = 0; i < sals.nelts; i++)
1954 resolve_sal_pc (&sals.sals[i]);
1958 if (arg[0] == 'i' && arg[1] == 'f'
1959 && (arg[2] == ' ' || arg[2] == '\t'))
1960 cond = parse_exp_1 ((arg += 2, &arg),
1961 block_for_pc (sals.sals[i].pc), 0);
1963 error ("Junk at end of arguments.");
1968 for (i = 0; i < sals.nelts; i++)
1973 describe_other_breakpoints (sal.pc);
1975 b = set_raw_breakpoint (sal);
1976 set_breakpoint_count (breakpoint_count + 1);
1977 b->number = breakpoint_count;
1978 b->type = bp_breakpoint;
1980 b->enable = enabled;
1981 b->disposition = tempflag ? delete : donttouch;
1983 printf ("Breakpoint %d at %s", b->number, local_hex_string(b->address));
1985 printf (": file %s, line %d.", b->symtab->filename, b->line_number);
1991 printf ("Multiple breakpoints were set.\n");
1992 printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1998 /* These aren't used; I don't know what they were for. */
1999 /* Disable breakpoints on all catch clauses described in ARGS. */
2001 disable_catch (args)
2004 /* Map the disable command to catch clauses described in ARGS. */
2007 /* Enable breakpoints on all catch clauses described in ARGS. */
2012 /* Map the disable command to catch clauses described in ARGS. */
2015 /* Delete breakpoints on all catch clauses in the active scope. */
2020 /* Map the delete command to catch clauses described in ARGS. */
2025 catch_command (arg, from_tty)
2029 catch_command_1 (arg, 0, from_tty);
2033 clear_command (arg, from_tty)
2037 register struct breakpoint *b, *b1;
2038 struct symtabs_and_lines sals;
2039 struct symtab_and_line sal;
2040 register struct breakpoint *found;
2045 sals = decode_line_spec (arg, 1);
2049 sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
2050 sal.line = default_breakpoint_line;
2051 sal.symtab = default_breakpoint_symtab;
2053 if (sal.symtab == 0)
2054 error ("No source file specified.");
2060 for (i = 0; i < sals.nelts; i++)
2062 /* If exact pc given, clear bpts at that pc.
2063 But if sal.pc is zero, clear all bpts on specified line. */
2065 found = (struct breakpoint *) 0;
2066 while (breakpoint_chain
2067 && (sal.pc ? breakpoint_chain->address == sal.pc
2068 : (breakpoint_chain->symtab == sal.symtab
2069 && breakpoint_chain->line_number == sal.line)))
2071 b1 = breakpoint_chain;
2072 breakpoint_chain = b1->next;
2079 && b->next->type != bp_watchpoint
2080 && (sal.pc ? b->next->address == sal.pc
2081 : (b->next->symtab == sal.symtab
2082 && b->next->line_number == sal.line)))
2093 error ("No breakpoint at %s.", arg);
2095 error ("No breakpoint at this line.");
2098 if (found->next) from_tty = 1; /* Always report if deleted more than one */
2099 if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : "");
2102 if (from_tty) printf ("%d ", found->number);
2104 delete_breakpoint (found);
2107 if (from_tty) putchar ('\n');
2112 /* Delete breakpoint in BS if they are `delete' breakpoints.
2113 This is called after any breakpoint is hit, or after errors. */
2116 breakpoint_auto_delete (bs)
2119 for (; bs; bs = bs->next)
2120 if (bs->breakpoint_at && bs->breakpoint_at->disposition == delete)
2121 delete_breakpoint (bs->breakpoint_at);
2124 /* Delete a breakpoint and clean up all traces of it in the data structures. */
2127 delete_breakpoint (bpt)
2128 struct breakpoint *bpt;
2130 register struct breakpoint *b;
2134 target_remove_breakpoint(bpt->address, bpt->shadow_contents);
2136 if (breakpoint_chain == bpt)
2137 breakpoint_chain = bpt->next;
2142 b->next = bpt->next;
2146 check_duplicates (bpt->address);
2148 free_command_lines (&bpt->commands);
2151 if (bpt->cond_string != NULL)
2152 free (bpt->cond_string);
2153 if (bpt->addr_string != NULL)
2154 free (bpt->addr_string);
2156 if (xgdb_verbose && bpt->type == bp_breakpoint)
2157 printf ("breakpoint #%d deleted\n", bpt->number);
2159 /* Be sure no bpstat's are pointing at it after it's been freed. */
2160 /* FIXME, how can we find all bpstat's? We just check stop_bpstat for now. */
2161 for (bs = stop_bpstat; bs; bs = bs->next)
2162 if (bs->breakpoint_at == bpt)
2163 bs->breakpoint_at = NULL;
2168 delete_command (arg, from_tty)
2175 /* Ask user only if there are some breakpoints to delete. */
2177 || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0)))
2179 /* No arg; clear all breakpoints. */
2180 while (breakpoint_chain)
2181 delete_breakpoint (breakpoint_chain);
2185 map_breakpoint_numbers (arg, delete_breakpoint);
2188 /* Reset a breakpoint given it's struct breakpoint * BINT.
2189 The value we return ends up being the return value from catch_errors.
2190 Unused in this case. */
2193 breakpoint_re_set_one (bint)
2196 struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */
2198 struct symtabs_and_lines sals;
2200 enum enable save_enable;
2205 if (b->addr_string == NULL)
2207 /* Anything without a string can't be re-set. */
2208 delete_breakpoint (b);
2211 /* In case we have a problem, disable this breakpoint. We'll restore
2212 its status if we succeed. */
2213 save_enable = b->enable;
2214 b->enable = disabled;
2217 sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0);
2218 for (i = 0; i < sals.nelts; i++)
2220 resolve_sal_pc (&sals.sals[i]);
2221 b->symtab = sals.sals[i].symtab;
2222 b->line_number = sals.sals[i].line;
2223 b->address = sals.sals[i].pc;
2225 if (b->cond_string != NULL)
2228 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
2231 check_duplicates (b->address);
2233 b->enable = save_enable; /* Restore it, this worked. */
2239 /* FIXME! This is the wrong thing to do.... */
2240 delete_breakpoint (b);
2243 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
2247 case bp_longjmp_resume:
2248 delete_breakpoint (b);
2255 /* Re-set all breakpoints after symbols have been re-loaded. */
2257 breakpoint_re_set ()
2259 struct breakpoint *b, *temp;
2260 static char message1[] = "Error in re-setting breakpoint %d:\n";
2261 char message[sizeof (message1) + 30 /* slop */];
2263 ALL_BREAKPOINTS_SAFE (b, temp)
2265 b->symtab = 0; /* Be sure we don't point to old dead symtab */
2266 sprintf (message, message1, b->number); /* Format possible error msg */
2267 (void) catch_errors (breakpoint_re_set_one, (char *) b, message);
2270 create_longjmp_breakpoint("longjmp");
2271 create_longjmp_breakpoint("_longjmp");
2272 create_longjmp_breakpoint("siglongjmp");
2273 create_longjmp_breakpoint(NULL);
2275 /* Blank line to finish off all those mention() messages we just printed. */
2276 printf_filtered ("\n");
2279 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
2280 If from_tty is nonzero, it prints a message to that effect,
2281 which ends with a period (no newline). */
2284 set_ignore_count (bptnum, count, from_tty)
2285 int bptnum, count, from_tty;
2287 register struct breakpoint *b;
2293 if (b->number == bptnum)
2295 b->ignore_count = count;
2298 else if (count == 0)
2299 printf ("Will stop next time breakpoint %d is reached.", bptnum);
2300 else if (count == 1)
2301 printf ("Will ignore next crossing of breakpoint %d.", bptnum);
2303 printf ("Will ignore next %d crossings of breakpoint %d.",
2308 error ("No breakpoint number %d.", bptnum);
2311 /* Clear the ignore counts of all breakpoints. */
2313 breakpoint_clear_ignore_counts ()
2315 struct breakpoint *b;
2318 b->ignore_count = 0;
2321 /* Command to set ignore-count of breakpoint N to COUNT. */
2324 ignore_command (args, from_tty)
2332 error_no_arg ("a breakpoint number");
2334 num = get_number (&p);
2337 error ("Second argument (specified ignore-count) is missing.");
2339 set_ignore_count (num,
2340 longest_to_int (value_as_long (parse_and_eval (p))),
2345 /* Call FUNCTION on each of the breakpoints
2346 whose numbers are given in ARGS. */
2349 map_breakpoint_numbers (args, function)
2351 void (*function) PARAMS ((struct breakpoint *));
2353 register char *p = args;
2356 register struct breakpoint *b;
2359 error_no_arg ("one or more breakpoint numbers");
2365 num = get_number (&p1);
2368 if (b->number == num)
2373 printf ("No breakpoint number %d.\n", num);
2380 enable_breakpoint (bpt)
2381 struct breakpoint *bpt;
2383 bpt->enable = enabled;
2385 if (xgdb_verbose && bpt->type == bp_breakpoint)
2386 printf ("breakpoint #%d enabled\n", bpt->number);
2388 check_duplicates (bpt->address);
2389 if (bpt->type == bp_watchpoint)
2391 if (bpt->exp_valid_block != NULL
2392 && !contained_in (get_selected_block (), bpt->exp_valid_block))
2395 Cannot enable watchpoint %d because the block in which its expression\n\
2396 is valid is not currently in scope.\n", bpt->number);
2400 value_free (bpt->val);
2402 bpt->val = evaluate_expression (bpt->exp);
2403 release_value (bpt->val);
2409 enable_command (args, from_tty)
2413 struct breakpoint *bpt;
2415 ALL_BREAKPOINTS (bpt)
2416 enable_breakpoint (bpt);
2418 map_breakpoint_numbers (args, enable_breakpoint);
2422 disable_breakpoint (bpt)
2423 struct breakpoint *bpt;
2425 bpt->enable = disabled;
2427 if (xgdb_verbose && bpt->type == bp_breakpoint)
2428 printf ("breakpoint #%d disabled\n", bpt->number);
2430 check_duplicates (bpt->address);
2435 disable_command (args, from_tty)
2439 register struct breakpoint *bpt;
2441 ALL_BREAKPOINTS (bpt)
2442 disable_breakpoint (bpt);
2444 map_breakpoint_numbers (args, disable_breakpoint);
2448 enable_once_breakpoint (bpt)
2449 struct breakpoint *bpt;
2451 bpt->enable = enabled;
2452 bpt->disposition = disable;
2454 check_duplicates (bpt->address);
2459 enable_once_command (args, from_tty)
2463 map_breakpoint_numbers (args, enable_once_breakpoint);
2467 enable_delete_breakpoint (bpt)
2468 struct breakpoint *bpt;
2470 bpt->enable = enabled;
2471 bpt->disposition = delete;
2473 check_duplicates (bpt->address);
2478 enable_delete_command (args, from_tty)
2482 map_breakpoint_numbers (args, enable_delete_breakpoint);
2486 * Use default_breakpoint_'s, or nothing if they aren't valid.
2488 struct symtabs_and_lines
2489 decode_line_spec_1 (string, funfirstline)
2493 struct symtabs_and_lines sals;
2495 error ("Empty line specification.");
2496 if (default_breakpoint_valid)
2497 sals = decode_line_1 (&string, funfirstline,
2498 default_breakpoint_symtab, default_breakpoint_line);
2500 sals = decode_line_1 (&string, funfirstline, (struct symtab *)NULL, 0);
2502 error ("Junk at end of line specification: %s", string);
2507 /* Chain containing all defined enable commands. */
2509 extern struct cmd_list_element
2510 *enablelist, *disablelist,
2511 *deletelist, *enablebreaklist;
2513 extern struct cmd_list_element *cmdlist;
2516 _initialize_breakpoint ()
2518 breakpoint_chain = 0;
2519 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
2520 before a breakpoint is set. */
2521 breakpoint_count = 0;
2523 add_com ("ignore", class_breakpoint, ignore_command,
2524 "Set ignore-count of breakpoint number N to COUNT.");
2526 add_com ("commands", class_breakpoint, commands_command,
2527 "Set commands to be executed when a breakpoint is hit.\n\
2528 Give breakpoint number as argument after \"commands\".\n\
2529 With no argument, the targeted breakpoint is the last one set.\n\
2530 The commands themselves follow starting on the next line.\n\
2531 Type a line containing \"end\" to indicate the end of them.\n\
2532 Give \"silent\" as the first line to make the breakpoint silent;\n\
2533 then no output is printed when it is hit, except what the commands print.");
2535 add_com ("condition", class_breakpoint, condition_command,
2536 "Specify breakpoint number N to break only if COND is true.\n\
2537 N is an integer; COND is an expression to be evaluated whenever\n\
2538 breakpoint N is reached. ");
2540 add_com ("tbreak", class_breakpoint, tbreak_command,
2541 "Set a temporary breakpoint. Args like \"break\" command.\n\
2542 Like \"break\" except the breakpoint is only enabled temporarily,\n\
2543 so it will be disabled when hit. Equivalent to \"break\" followed\n\
2544 by using \"enable once\" on the breakpoint number.");
2546 add_prefix_cmd ("enable", class_breakpoint, enable_command,
2547 "Enable some breakpoints.\n\
2548 Give breakpoint numbers (separated by spaces) as arguments.\n\
2549 With no subcommand, breakpoints are enabled until you command otherwise.\n\
2550 This is used to cancel the effect of the \"disable\" command.\n\
2551 With a subcommand you can enable temporarily.",
2552 &enablelist, "enable ", 1, &cmdlist);
2554 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
2555 "Enable some breakpoints.\n\
2556 Give breakpoint numbers (separated by spaces) as arguments.\n\
2557 This is used to cancel the effect of the \"disable\" command.\n\
2558 May be abbreviated to simply \"enable\".\n",
2559 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
2561 add_cmd ("once", no_class, enable_once_command,
2562 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
2563 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2564 See the \"tbreak\" command which sets a breakpoint and enables it once.",
2567 add_cmd ("delete", no_class, enable_delete_command,
2568 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
2569 If a breakpoint is hit while enabled in this fashion, it is deleted.",
2572 add_cmd ("delete", no_class, enable_delete_command,
2573 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
2574 If a breakpoint is hit while enabled in this fashion, it is deleted.",
2577 add_cmd ("once", no_class, enable_once_command,
2578 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
2579 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2580 See the \"tbreak\" command which sets a breakpoint and enables it once.",
2583 add_prefix_cmd ("disable", class_breakpoint, disable_command,
2584 "Disable some breakpoints.\n\
2585 Arguments are breakpoint numbers with spaces in between.\n\
2586 To disable all breakpoints, give no argument.\n\
2587 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
2588 &disablelist, "disable ", 1, &cmdlist);
2589 add_com_alias ("dis", "disable", class_breakpoint, 1);
2590 add_com_alias ("disa", "disable", class_breakpoint, 1);
2592 add_cmd ("breakpoints", class_alias, disable_command,
2593 "Disable some breakpoints.\n\
2594 Arguments are breakpoint numbers with spaces in between.\n\
2595 To disable all breakpoints, give no argument.\n\
2596 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
2597 This command may be abbreviated \"disable\".",
2600 add_prefix_cmd ("delete", class_breakpoint, delete_command,
2601 "Delete some breakpoints or auto-display expressions.\n\
2602 Arguments are breakpoint numbers with spaces in between.\n\
2603 To delete all breakpoints, give no argument.\n\
2605 Also a prefix command for deletion of other GDB objects.\n\
2606 The \"unset\" command is also an alias for \"delete\".",
2607 &deletelist, "delete ", 1, &cmdlist);
2608 add_com_alias ("d", "delete", class_breakpoint, 1);
2610 add_cmd ("breakpoints", class_alias, delete_command,
2611 "Delete some breakpoints or auto-display expressions.\n\
2612 Arguments are breakpoint numbers with spaces in between.\n\
2613 To delete all breakpoints, give no argument.\n\
2614 This command may be abbreviated \"delete\".",
2617 add_com ("clear", class_breakpoint, clear_command,
2618 "Clear breakpoint at specified line or function.\n\
2619 Argument may be line number, function name, or \"*\" and an address.\n\
2620 If line number is specified, all breakpoints in that line are cleared.\n\
2621 If function is specified, breakpoints at beginning of function are cleared.\n\
2622 If an address is specified, breakpoints at that address are cleared.\n\n\
2623 With no argument, clears all breakpoints in the line that the selected frame\n\
2626 See also the \"delete\" command which clears breakpoints by number.");
2628 add_com ("break", class_breakpoint, break_command,
2629 "Set breakpoint at specified line or function.\n\
2630 Argument may be line number, function name, or \"*\" and an address.\n\
2631 If line number is specified, break at start of code for that line.\n\
2632 If function is specified, break at start of code for that function.\n\
2633 If an address is specified, break at that exact address.\n\
2634 With no arg, uses current execution address of selected stack frame.\n\
2635 This is useful for breaking on return to a stack frame.\n\
2637 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
2639 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2640 add_com_alias ("b", "break", class_run, 1);
2641 add_com_alias ("br", "break", class_run, 1);
2642 add_com_alias ("bre", "break", class_run, 1);
2643 add_com_alias ("brea", "break", class_run, 1);
2645 add_info ("breakpoints", breakpoints_info,
2646 "Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
2647 The \"Type\" column indicates one of:\n\
2648 \tbreakpoint - for normal breakpoints\n\
2649 \twatchpoint - for watchpoints\n\
2650 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
2651 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
2652 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
2653 address and file/line number respectively.\n\n\
2654 Convenience variable \"$_\" and default examine address for \"x\"\n\
2655 are set to the address of the last breakpoint listed.\n\n\
2656 Convenience variable \"$bpnum\" contains the number of the last\n\
2659 add_info ("all-breakpoints", all_breakpoints_info,
2660 "Status of all breakpoints, or breakpoint number NUMBER.\n\
2661 The \"Type\" column indicates one of:\n\
2662 \tbreakpoint - for normal breakpoints\n\
2663 \twatchpoint - for watchpoints\n\
2664 \tlongjmp - for internal breakpoints to handle stepping through longjmp()\n\
2665 \tlongjmp resume - for internal breakpoints at the target of longjmp()\n\
2666 \tuntil - for internal breakpoints used by the \"until\" command\n\
2667 \tfinish - for internal breakpoints used by the \"finish\" command\n\
2668 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
2669 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
2670 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
2671 address and file/line number respectively.\n\n\
2672 Convenience variable \"$_\" and default examine address for \"x\"\n\
2673 are set to the address of the last breakpoint listed.\n\n\
2674 Convenience variable \"$bpnum\" contains the number of the last\n\
2677 add_com ("catch", class_breakpoint, catch_command,
2678 "Set breakpoints to catch exceptions that are raised.\n\
2679 Argument may be a single exception to catch, multiple exceptions\n\
2680 to catch, or the default exception \"default\". If no arguments\n\
2681 are given, breakpoints are set at all exception handlers catch clauses\n\
2682 within the current scope.\n\
2684 A condition specified for the catch applies to all breakpoints set\n\
2685 with this command\n\
2687 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2689 add_com ("watch", class_breakpoint, watch_command,
2690 "Set a watchpoint for an expression.\n\
2691 A watchpoint stops execution of your program whenever the value of\n\
2692 an expression changes.");
2694 add_info ("watchpoints", watchpoints_info,
2695 "Status of all watchpoints, or watchpoint number NUMBER.\n\
2696 Second column is \"y\" for enabled watchpoints, \"n\" for disabled.");