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));
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);
228 while (*p >= '0' && *p <= '9')
231 /* There is no number here. (e.g. "cond a == b"). */
232 error_no_arg ("breakpoint number");
235 if (!(isspace (*p) || *p == '\0'))
236 error ("breakpoint number expected");
243 /* condition N EXP -- set break condition of breakpoint N to EXP. */
246 condition_command (arg, from_tty)
250 register struct breakpoint *b;
255 error_no_arg ("breakpoint number");
258 bnum = get_number (&p);
261 if (b->number == bnum)
268 if (b->cond_string != NULL)
269 free (b->cond_string);
274 b->cond_string = NULL;
276 printf ("Breakpoint %d now unconditional.\n", bnum);
281 /* I don't know if it matters whether this is the string the user
282 typed in or the decompiled expression. */
283 b->cond_string = savestring (arg, strlen (arg));
284 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
286 error ("Junk at end of expression");
291 error ("No breakpoint number %d.", bnum);
296 commands_command (arg, from_tty)
300 register struct breakpoint *b;
303 struct command_line *l;
305 /* If we allowed this, we would have problems with when to
306 free the storage, if we change the commands currently
309 if (executing_breakpoint_commands)
310 error ("Can't use the \"commands\" command among a breakpoint's commands.");
313 bnum = get_number (&p);
315 error ("Unexpected extra arguments following breakpoint number.");
318 if (b->number == bnum)
320 if (from_tty && input_from_terminal_p ())
322 printf ("Type commands for when breakpoint %d is hit, one per line.\n\
323 End with a line saying just \"end\".\n", bnum);
326 l = read_command_lines ();
327 free_command_lines (&b->commands);
331 error ("No breakpoint number %d.", bnum);
334 extern int memory_breakpoint_size; /* from mem-break.c */
336 /* Like target_read_memory() but if breakpoints are inserted, return
337 the shadow contents instead of the breakpoints themselves.
339 Read "memory data" from whatever target or inferior we have.
340 Returns zero if successful, errno value if not. EIO is used
341 for address out of bounds. If breakpoints are inserted, returns
342 shadow contents, not the breakpoints themselves. From breakpoint.c. */
345 read_memory_nobpt (memaddr, myaddr, len)
351 struct breakpoint *b;
353 if (memory_breakpoint_size < 0)
354 /* No breakpoints on this machine. */
355 return target_read_memory (memaddr, myaddr, len);
359 if (b->type == bp_watchpoint || !b->inserted)
361 else if (b->address + memory_breakpoint_size <= memaddr)
362 /* The breakpoint is entirely before the chunk of memory
365 else if (b->address >= memaddr + len)
366 /* The breakpoint is entirely after the chunk of memory we
371 /* Copy the breakpoint from the shadow contents, and recurse
372 for the things before and after. */
374 /* Addresses and length of the part of the breakpoint that
376 CORE_ADDR membpt = b->address;
377 unsigned int bptlen = memory_breakpoint_size;
378 /* Offset within shadow_contents. */
381 if (membpt < memaddr)
383 /* Only copy the second part of the breakpoint. */
384 bptlen -= memaddr - membpt;
385 bptoffset = memaddr - membpt;
389 if (membpt + bptlen > memaddr + len)
391 /* Only copy the first part of the breakpoint. */
392 bptlen -= (membpt + bptlen) - (memaddr + len);
395 bcopy (b->shadow_contents + bptoffset,
396 myaddr + membpt - memaddr, bptlen);
398 if (membpt > memaddr)
400 /* Copy the section of memory before the breakpoint. */
401 status = read_memory_nobpt (memaddr, myaddr, membpt - memaddr);
406 if (membpt + bptlen < memaddr + len)
408 /* Copy the section of memory after the breakpoint. */
409 status = read_memory_nobpt
411 myaddr + membpt + bptlen - memaddr,
412 memaddr + len - (membpt + bptlen));
419 /* Nothing overlaps. Just call read_memory_noerr. */
420 return target_read_memory (memaddr, myaddr, len);
423 /* insert_breakpoints is used when starting or continuing the program.
424 remove_breakpoints is used when the program stops.
425 Both return zero if successful,
426 or an `errno' value if could not write the inferior. */
429 insert_breakpoints ()
431 register struct breakpoint *b;
433 int disabled_breaks = 0;
436 if (b->type != bp_watchpoint
437 && b->enable != disabled
441 val = target_insert_breakpoint(b->address, b->shadow_contents);
444 /* Can't set the breakpoint. */
445 #if defined (DISABLE_UNSETTABLE_BREAK)
446 if (DISABLE_UNSETTABLE_BREAK (b->address))
449 b->enable = disabled;
450 if (!disabled_breaks)
453 "Cannot insert breakpoint %d:\n", b->number);
454 printf_filtered ("Disabling shared library breakpoints:\n");
457 printf_filtered ("%d ", b->number);
462 fprintf (stderr, "Cannot insert breakpoint %d:\n", b->number);
463 #ifdef ONE_PROCESS_WRITETEXT
465 "The same program may be running in another process.\n");
467 memory_error (val, b->address); /* which bombs us out */
474 printf_filtered ("\n");
479 remove_breakpoints ()
481 register struct breakpoint *b;
484 #ifdef BREAKPOINT_DEBUG
485 printf ("Removing breakpoints.\n");
486 #endif /* BREAKPOINT_DEBUG */
489 if (b->type != bp_watchpoint && b->inserted)
491 val = target_remove_breakpoint(b->address, b->shadow_contents);
495 #ifdef BREAKPOINT_DEBUG
496 printf ("Removed breakpoint at %s",
497 local_hex_string(b->address));
498 printf (", shadow %s",
499 local_hex_string(b->shadow_contents[0]));
501 local_hex_string(b->shadow_contents[1]));
502 #endif /* BREAKPOINT_DEBUG */
508 /* Clear the "inserted" flag in all breakpoints.
509 This is done when the inferior is loaded. */
512 mark_breakpoints_out ()
514 register struct breakpoint *b;
520 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
521 When continuing from a location with a breakpoint,
522 we actually single step once before calling insert_breakpoints. */
525 breakpoint_here_p (pc)
528 register struct breakpoint *b;
531 if (b->enable != disabled && b->address == pc)
537 /* bpstat stuff. External routines' interfaces are documented
540 /* Clear a bpstat so that it says we are not at any breakpoint.
541 Also free any storage that is part of a bpstat. */
556 if (p->old_val != NULL)
557 value_free (p->old_val);
564 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
565 is part of the bpstat is copied as well. */
578 for (; bs != NULL; bs = bs->next)
580 tmp = (bpstat) xmalloc (sizeof (*tmp));
581 bcopy (bs, tmp, sizeof (*tmp));
583 /* This is the first thing in the chain. */
593 /* Find the bpstat associated with this breakpoint */
596 bpstat_find_breakpoint(bsp, breakpoint)
598 struct breakpoint *breakpoint;
600 if (bsp == NULL) return NULL;
602 for (;bsp != NULL; bsp = bsp->next) {
603 if (bsp->breakpoint_at == breakpoint) return bsp;
608 /* Return the breakpoint number of the first breakpoint we are stopped
609 at. *BSP upon return is a bpstat which points to the remaining
610 breakpoints stopped at (but which is not guaranteed to be good for
611 anything but further calls to bpstat_num).
612 Return 0 if passed a bpstat which does not indicate any breakpoints. */
618 struct breakpoint *b;
621 return 0; /* No more breakpoint values */
624 b = (*bsp)->breakpoint_at;
627 return -1; /* breakpoint that's been deleted since */
629 return b->number; /* We have its number */
633 /* Modify BS so that the actions will not be performed. */
636 bpstat_clear_actions (bs)
639 for (; bs != NULL; bs = bs->next)
642 if (bs->old_val != NULL)
644 value_free (bs->old_val);
650 /* Stub for cleaning up our state if we error-out of a breakpoint command */
653 cleanup_executing_breakpoints (ignore)
656 executing_breakpoint_commands = 0;
659 /* Execute all the commands associated with all the breakpoints at this
660 location. Any of these commands could cause the process to proceed
661 beyond this point, etc. We look out for such changes by checking
662 the global "breakpoint_proceeded" after each command. */
665 bpstat_do_actions (bsp)
669 struct cleanup *old_chain;
671 executing_breakpoint_commands = 1;
672 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
677 breakpoint_proceeded = 0;
678 for (; bs != NULL; bs = bs->next)
682 char *line = bs->commands->line;
683 bs->commands = bs->commands->next;
684 execute_command (line, 0);
685 /* If the inferior is proceeded by the command, bomb out now.
686 The bpstat chain has been blown away by wait_for_inferior.
687 But since execution has stopped again, there is a new bpstat
688 to look at, so start over. */
689 if (breakpoint_proceeded)
694 executing_breakpoint_commands = 0;
695 discard_cleanups (old_chain);
698 /* Print a message indicating what happened. Returns nonzero to
699 say that only the source line should be printed after this (zero
700 return means print the frame as well as the source line). */
706 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
707 which has since been deleted. */
709 || bs->breakpoint_at == NULL
710 || (bs->breakpoint_at->type != bp_breakpoint
711 && bs->breakpoint_at->type != bp_watchpoint))
714 /* If bpstat_stop_status says don't print, OK, we won't. An example
715 circumstance is when we single-stepped for both a watchpoint and
716 for a "stepi" instruction. The bpstat says that the watchpoint
717 explains the stop, but we shouldn't print because the watchpoint's
718 value didn't change -- and the real reason we are stopping here
719 rather than continuing to step (as the watchpoint would've had us do)
720 is because of the "stepi". */
724 if (bs->breakpoint_at->type == bp_breakpoint)
726 /* I think the user probably only wants to see one breakpoint
727 number, not all of them. */
728 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
732 if (bs->old_val != NULL)
734 printf_filtered ("\nWatchpoint %d, ", bs->breakpoint_at->number);
735 print_expression (bs->breakpoint_at->exp, stdout);
736 printf_filtered ("\nOld value = ");
737 value_print (bs->old_val, stdout, 0, Val_pretty_default);
738 printf_filtered ("\nNew value = ");
739 value_print (bs->breakpoint_at->val, stdout, 0,
741 printf_filtered ("\n");
742 value_free (bs->old_val);
747 /* Maybe another breakpoint in the chain caused us to stop.
748 (Currently all watchpoints go on the bpstat whether hit or
749 not. That probably could (should) be changed, provided care is taken
750 with respect to bpstat_explains_signal). */
752 return bpstat_print (bs->next);
754 fprintf_filtered (stderr, "gdb internal error: in bpstat_print\n");
758 /* Evaluate the expression EXP and return 1 if value is zero.
759 This is used inside a catch_errors to evaluate the breakpoint condition.
760 The argument is a "struct expression *" that has been cast to char * to
761 make it pass through catch_errors. */
764 breakpoint_cond_eval (exp)
767 return !value_true (evaluate_expression ((struct expression *)exp));
770 /* Allocate a new bpstat and chain it to the current one. */
773 bpstat_alloc (b, cbs)
774 register struct breakpoint *b;
775 bpstat cbs; /* Current "bs" value */
779 bs = (bpstat) xmalloc (sizeof (*bs));
781 bs->breakpoint_at = b;
782 /* If the condition is false, etc., don't do the commands. */
784 bs->momentary = b->disposition == delete;
789 /* Determine whether we stopped at a breakpoint, etc, or whether we
790 don't understand this stop. Result is a chain of bpstat's such that:
792 if we don't understand the stop, the result is a null pointer.
794 if we understand why we stopped, the result is not null, and
795 the first element of the chain contains summary "stop" and
796 "print" flags for the whole chain.
798 Each element of the chain refers to a particular breakpoint or
799 watchpoint at which we have stopped. (We may have stopped for
802 Each element of the chain has valid next, breakpoint_at,
803 commands, FIXME??? fields.
809 bpstat_stop_status (pc, frame_address)
811 FRAME_ADDR frame_address;
813 register struct breakpoint *b;
817 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
818 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
819 int real_breakpoint = 0;
821 /* Root of the chain of bpstat's */
822 struct bpstat root_bs[1];
823 /* Pointer to the last thing in the chain currently. */
826 /* Get the address where the breakpoint would have been. */
827 bp_addr = *pc - DECR_PC_AFTER_BREAK;
834 if (b->enable == disabled)
837 if (b->type != bp_watchpoint && b->address != bp_addr)
840 /* Come here if it's a watchpoint, or if the break address matches */
842 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
847 if (b->type == bp_watchpoint)
849 int within_current_scope;
850 if (b->exp_valid_block != NULL)
851 within_current_scope =
852 contained_in (get_selected_block (), b->exp_valid_block);
854 within_current_scope = 1;
856 if (within_current_scope)
858 /* We use value_{,free_to_}mark because it could be a
859 *long* time before we return to the command level and
860 call free_all_values. */
862 value mark = value_mark ();
863 value new_val = evaluate_expression (b->exp);
864 if (!value_equal (b->val, new_val))
866 release_value (new_val);
867 value_free_to_mark (mark);
868 bs->old_val = b->val;
870 /* We will stop here */
874 /* Nothing changed, don't do anything. */
875 value_free_to_mark (mark);
877 /* We won't stop here */
882 /* This seems like the only logical thing to do because
883 if we temporarily ignored the watchpoint, then when
884 we reenter the block in which it is valid it contains
885 garbage (in the case of a function, it may have two
886 garbage values, one before and one after the prologue).
887 So we can't even detect the first assignment to it and
888 watch after that (since the garbage may or may not equal
889 the first value assigned). */
890 b->enable = disabled;
892 Watchpoint %d disabled because the program has left the block in\n\
893 which its expression is valid.\n", b->number);
894 /* We won't stop here */
895 /* FIXME, maybe we should stop here!!! */
899 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
904 if (b->frame && b->frame != frame_address)
912 /* Need to select the frame, with all that implies
913 so that the conditions will have the right context. */
914 select_frame (get_current_frame (), 0);
916 = catch_errors (breakpoint_cond_eval, (char *)(b->cond),
917 "Error in testing breakpoint condition:\n");
918 /* FIXME-someday, should give breakpoint # */
921 if (b->cond && value_is_zero)
925 else if (b->ignore_count > 0)
932 /* We will stop here */
933 if (b->disposition == disable)
934 b->enable = disabled;
935 bs->commands = b->commands;
938 if (bs->commands && !strcmp ("silent", bs->commands->line))
940 bs->commands = bs->commands->next;
951 bs->next = NULL; /* Terminate the chain */
952 bs = root_bs->next; /* Re-grab the head of the chain */
957 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
961 #if defined (SHIFT_INST_REGS)
963 CORE_ADDR pc = read_register (PC_REGNUM);
964 CORE_ADDR npc = read_register (NPC_REGNUM);
967 write_register (NNPC_REGNUM, npc);
968 write_register (NPC_REGNUM, pc);
971 #else /* No SHIFT_INST_REGS. */
973 #endif /* No SHIFT_INST_REGS. */
975 #endif /* DECR_PC_AFTER_BREAK != 0. */
980 /* Nonzero if we should step constantly (e.g. watchpoints on machines
981 without hardware support). This isn't related to a specific bpstat,
982 just to things like whether watchpoints are set. */
985 bpstat_should_step ()
987 struct breakpoint *b;
989 if (b->enable == enabled && b->type == bp_watchpoint)
994 /* Print information on breakpoint number BNUM, or -1 if all.
995 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
996 is nonzero, process only watchpoints. */
999 breakpoint_1 (bnum, type)
1003 register struct breakpoint *b;
1004 register struct command_line *l;
1005 register struct symbol *sym;
1006 CORE_ADDR last_addr = (CORE_ADDR)-1;
1007 int found_a_breakpoint = 0;
1008 static char *bptypes[] = {"breakpoint", "until", "finish", "watchpoint",
1009 "longjmp", "longjmp resume"};
1010 static char *bpdisps[] = {"del", "dis", ""};
1011 static char bpenables[] = "ny";
1013 if (!breakpoint_chain)
1015 printf_filtered ("No breakpoints or watchpoints.\n");
1021 || bnum == b->number)
1023 if (!found_a_breakpoint++)
1024 printf_filtered ("Num Type Disp Enb %sWhat\n",
1025 addressprint ? "Address " : "");
1027 printf_filtered ("%-3d %-10s %-4s %-3c ",
1030 bpdisps[b->disposition],
1031 bpenables[b->enable]);
1035 print_expression (b->exp, stdout);
1039 printf_filtered ("%s ", local_hex_string_custom(b->address, "08"));
1041 last_addr = b->address;
1044 sym = find_pc_function (b->address);
1047 fputs_filtered ("in ", stdout);
1048 fputs_demangled (SYMBOL_NAME (sym), stdout, 1);
1049 fputs_filtered (" at ", stdout);
1051 fputs_filtered (b->symtab->filename, stdout);
1052 printf_filtered (":%d", b->line_number);
1055 print_address_symbolic (b->address, stdout, demangle, " ");
1058 printf_filtered ("\n");
1061 printf_filtered ("\tstop only in stack frame at %s\n",
1062 local_hex_string(b->frame));
1065 printf_filtered ("\tstop only if ");
1066 print_expression (b->cond, stdout);
1067 printf_filtered ("\n");
1069 if (b->ignore_count)
1070 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
1071 if ((l = b->commands))
1074 fputs_filtered ("\t", stdout);
1075 fputs_filtered (l->line, stdout);
1076 fputs_filtered ("\n", stdout);
1081 if (!found_a_breakpoint
1083 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
1085 /* Compare against (CORE_ADDR)-1 in case some compiler decides
1086 that a comparison of an unsigned with -1 is always false. */
1087 if (last_addr != (CORE_ADDR)-1)
1088 set_next_address (last_addr);
1093 breakpoints_info (bnum_exp, from_tty)
1100 bnum = parse_and_eval_address (bnum_exp);
1102 breakpoint_1 (bnum, bp_breakpoint);
1107 watchpoints_info (bnum_exp, from_tty)
1114 bnum = parse_and_eval_address (bnum_exp);
1116 breakpoint_1 (bnum, bp_watchpoint);
1119 /* Print a message describing any breakpoints set at PC. */
1122 describe_other_breakpoints (pc)
1123 register CORE_ADDR pc;
1125 register int others = 0;
1126 register struct breakpoint *b;
1129 if (b->address == pc)
1133 printf ("Note: breakpoint%s ", (others > 1) ? "s" : "");
1135 if (b->address == pc)
1140 (b->enable == disabled) ? " (disabled)" : "",
1141 (others > 1) ? "," : ((others == 1) ? " and" : ""));
1143 printf ("also set at pc %s.\n", local_hex_string(pc));
1147 /* Set the default place to put a breakpoint
1148 for the `break' command with no arguments. */
1151 set_default_breakpoint (valid, addr, symtab, line)
1154 struct symtab *symtab;
1157 default_breakpoint_valid = valid;
1158 default_breakpoint_address = addr;
1159 default_breakpoint_symtab = symtab;
1160 default_breakpoint_line = line;
1163 /* Rescan breakpoints at address ADDRESS,
1164 marking the first one as "first" and any others as "duplicates".
1165 This is so that the bpt instruction is only inserted once. */
1168 check_duplicates (address)
1171 register struct breakpoint *b;
1172 register int count = 0;
1174 if (address == 0) /* Watchpoints are uninteresting */
1178 if (b->enable != disabled && b->address == address)
1181 b->duplicate = count > 1;
1185 /* Low level routine to set a breakpoint.
1186 Takes as args the three things that every breakpoint must have.
1187 Returns the breakpoint object so caller can set other things.
1188 Does not set the breakpoint number!
1189 Does not print anything.
1191 ==> This routine should not be called if there is a chance of later
1192 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
1193 your arguments BEFORE calling this routine! */
1195 static struct breakpoint *
1196 set_raw_breakpoint (sal)
1197 struct symtab_and_line sal;
1199 register struct breakpoint *b, *b1;
1201 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
1202 bzero (b, sizeof *b);
1203 b->address = sal.pc;
1204 b->symtab = sal.symtab;
1205 b->line_number = sal.line;
1206 b->enable = enabled;
1209 b->ignore_count = 0;
1213 /* Add this breakpoint to the end of the chain
1214 so that a list of breakpoints will come out in order
1215 of increasing numbers. */
1217 b1 = breakpoint_chain;
1219 breakpoint_chain = b;
1227 check_duplicates (sal.pc);
1232 struct breakpoint *longjmp_breakpoint = NULL;
1233 struct breakpoint *_longjmp_breakpoint = NULL;
1234 struct breakpoint *siglongjmp_breakpoint = NULL;
1235 struct breakpoint *longjmp_resume_breakpoint = NULL;
1238 create_longjmp_breakpoint_1(func_name, bpt)
1240 struct breakpoint **bpt;
1243 struct symtab_and_line sal;
1244 struct breakpoint *b;
1248 delete_breakpoint(*bpt);
1252 if (func_name != NULL)
1254 struct minimal_symbol *m;
1256 m = lookup_minimal_symbol(func_name, (struct objfile *)NULL);
1258 sal.pc = m->address;
1270 b = set_raw_breakpoint(sal);
1274 b->type = bp_longjmp;
1275 b->disposition = donttouch;
1276 b->enable = disabled;
1281 /* Call this routine each time we read a new executable or symbol table
1284 #ifdef GET_LONGJMP_TARGET
1286 create_longjmp_breakpoint()
1288 create_longjmp_breakpoint_1("longjmp", &longjmp_breakpoint);
1289 create_longjmp_breakpoint_1("_longjmp", &_longjmp_breakpoint);
1290 create_longjmp_breakpoint_1("siglongjmp", &siglongjmp_breakpoint);
1292 if ((longjmp_breakpoint || _longjmp_breakpoint || siglongjmp_breakpoint)
1293 && !longjmp_resume_breakpoint)
1295 create_longjmp_breakpoint_1(NULL, &longjmp_resume_breakpoint);
1296 if (longjmp_resume_breakpoint)
1297 longjmp_resume_breakpoint->type = bp_longjmp_resume;
1302 create_longjmp_breakpoint()
1307 /* Call this routine when stepping and nexting to enable a breakpoint if we do
1308 a longjmp(). When we hit that breakpoint, call
1309 set_longjmp_resume_breakpoint() to figure out where we are going. */
1312 enable_longjmp_breakpoint()
1314 if (longjmp_breakpoint)
1315 longjmp_breakpoint->enable = enabled;
1316 if (_longjmp_breakpoint)
1317 _longjmp_breakpoint->enable = enabled;
1318 if (siglongjmp_breakpoint)
1319 siglongjmp_breakpoint->enable = enabled;
1323 disable_longjmp_breakpoint()
1325 if (longjmp_breakpoint)
1326 longjmp_breakpoint->enable = disabled;
1327 if (_longjmp_breakpoint)
1328 _longjmp_breakpoint->enable = disabled;
1329 if (siglongjmp_breakpoint)
1330 siglongjmp_breakpoint->enable = disabled;
1331 if (longjmp_resume_breakpoint)
1332 longjmp_resume_breakpoint->enable = disabled;
1335 /* Call this after hitting the longjmp() breakpoint. Use this to set a new
1336 breakpoint at the target of the jmp_buf.
1340 set_longjmp_resume_breakpoint(pc, frame)
1344 longjmp_resume_breakpoint->address = pc;
1345 longjmp_resume_breakpoint->enable = enabled;
1347 longjmp_resume_breakpoint->frame = FRAME_FP(frame);
1349 longjmp_resume_breakpoint->frame = 0;
1352 /* Set a breakpoint that will evaporate an end of command
1353 at address specified by SAL.
1354 Restrict it to frame FRAME if FRAME is nonzero. */
1357 set_momentary_breakpoint (sal, frame, type)
1358 struct symtab_and_line sal;
1362 register struct breakpoint *b;
1363 b = set_raw_breakpoint (sal);
1365 b->enable = enabled;
1366 b->disposition = donttouch;
1367 b->frame = (frame ? FRAME_FP (frame) : 0);
1373 clear_momentary_breakpoints ()
1375 register struct breakpoint *b;
1377 if (b->disposition == delete)
1379 delete_breakpoint (b);
1385 /* Tell the user we have just set a breakpoint B. */
1388 struct breakpoint *b;
1393 printf_filtered ("Watchpoint %d: ", b->number);
1394 print_expression (b->exp, stdout);
1397 printf_filtered ("Breakpoint %d at %s", b->number,
1398 local_hex_string(b->address));
1400 printf_filtered (": file %s, line %d.",
1401 b->symtab->filename, b->line_number);
1403 printf_filtered ("\n");
1407 /* Nobody calls this currently. */
1408 /* Set a breakpoint from a symtab and line.
1409 If TEMPFLAG is nonzero, it is a temporary breakpoint.
1410 ADDR_STRING is a malloc'd string holding the name of where we are
1411 setting the breakpoint. This is used later to re-set it after the
1412 program is relinked and symbols are reloaded.
1413 Print the same confirmation messages that the breakpoint command prints. */
1416 set_breakpoint (s, line, tempflag, addr_string)
1422 register struct breakpoint *b;
1423 struct symtab_and_line sal;
1428 resolve_sal_pc (&sal); /* Might error out */
1429 describe_other_breakpoints (sal.pc);
1431 b = set_raw_breakpoint (sal);
1432 set_breakpoint_count (breakpoint_count + 1);
1433 b->number = breakpoint_count;
1434 b->type = bp_breakpoint;
1436 b->addr_string = addr_string;
1437 b->enable = enabled;
1438 b->disposition = tempflag ? delete : donttouch;
1444 /* Set a breakpoint according to ARG (function, linenum or *address)
1445 and make it temporary if TEMPFLAG is nonzero. */
1448 break_command_1 (arg, tempflag, from_tty)
1450 int tempflag, from_tty;
1452 struct symtabs_and_lines sals;
1453 struct symtab_and_line sal;
1454 register struct expression *cond = 0;
1455 register struct breakpoint *b;
1457 /* Pointers in arg to the start, and one past the end, of the condition. */
1458 char *cond_start = NULL;
1460 /* Pointers in arg to the start, and one past the end,
1461 of the address part. */
1462 char *addr_start = NULL;
1470 sal.line = sal.pc = sal.end = 0;
1473 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
1475 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1476 && (arg[2] == ' ' || arg[2] == '\t')))
1478 if (default_breakpoint_valid)
1480 sals.sals = (struct symtab_and_line *)
1481 xmalloc (sizeof (struct symtab_and_line));
1482 sal.pc = default_breakpoint_address;
1483 sal.line = default_breakpoint_line;
1484 sal.symtab = default_breakpoint_symtab;
1489 error ("No default breakpoint address now.");
1495 /* Force almost all breakpoints to be in terms of the
1496 current_source_symtab (which is decode_line_1's default). This
1497 should produce the results we want almost all of the time while
1498 leaving default_breakpoint_* alone. */
1499 if (default_breakpoint_valid
1500 && (!current_source_symtab
1501 || (arg && (*arg == '+' || *arg == '-'))))
1502 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1503 default_breakpoint_line);
1505 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1513 /* Resolve all line numbers to PC's, and verify that conditions
1514 can be parsed, before setting any breakpoints. */
1515 for (i = 0; i < sals.nelts; i++)
1517 resolve_sal_pc (&sals.sals[i]);
1521 if (arg[0] == 'i' && arg[1] == 'f'
1522 && (arg[2] == ' ' || arg[2] == '\t'))
1526 cond = parse_exp_1 (&arg, block_for_pc (sals.sals[i].pc), 0);
1530 error ("Junk at end of arguments.");
1534 /* Now set all the breakpoints. */
1535 for (i = 0; i < sals.nelts; i++)
1540 describe_other_breakpoints (sal.pc);
1542 b = set_raw_breakpoint (sal);
1543 set_breakpoint_count (breakpoint_count + 1);
1544 b->number = breakpoint_count;
1545 b->type = bp_breakpoint;
1549 b->addr_string = savestring (addr_start, addr_end - addr_start);
1551 b->cond_string = savestring (cond_start, cond_end - cond_start);
1553 b->enable = enabled;
1554 b->disposition = tempflag ? delete : donttouch;
1561 printf ("Multiple breakpoints were set.\n");
1562 printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1567 /* Helper function for break_command_1 and disassemble_command. */
1570 resolve_sal_pc (sal)
1571 struct symtab_and_line *sal;
1575 if (sal->pc == 0 && sal->symtab != 0)
1577 pc = find_line_pc (sal->symtab, sal->line);
1579 error ("No line %d in file \"%s\".",
1580 sal->line, sal->symtab->filename);
1586 break_command (arg, from_tty)
1590 break_command_1 (arg, 0, from_tty);
1594 tbreak_command (arg, from_tty)
1598 break_command_1 (arg, 1, from_tty);
1603 watch_command (arg, from_tty)
1607 struct breakpoint *b;
1608 struct symtab_and_line sal;
1609 struct expression *exp;
1610 struct block *exp_valid_block;
1617 /* Parse arguments. */
1618 innermost_block = NULL;
1619 exp = parse_expression (arg);
1620 exp_valid_block = innermost_block;
1621 val = evaluate_expression (exp);
1622 release_value (val);
1624 /* Now set up the breakpoint. */
1625 b = set_raw_breakpoint (sal);
1626 set_breakpoint_count (breakpoint_count + 1);
1627 b->number = breakpoint_count;
1628 b->type = bp_watchpoint;
1629 b->disposition = donttouch;
1631 b->exp_valid_block = exp_valid_block;
1634 b->cond_string = NULL;
1639 * Helper routine for the until_command routine in infcmd.c. Here
1640 * because it uses the mechanisms of breakpoints.
1644 until_break_command (arg, from_tty)
1648 struct symtabs_and_lines sals;
1649 struct symtab_and_line sal;
1650 FRAME prev_frame = get_prev_frame (selected_frame);
1651 struct breakpoint *breakpoint;
1652 struct cleanup *old_chain;
1654 clear_proceed_status ();
1656 /* Set a breakpoint where the user wants it and at return from
1659 if (default_breakpoint_valid)
1660 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1661 default_breakpoint_line);
1663 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1665 if (sals.nelts != 1)
1666 error ("Couldn't get information on specified line.");
1669 free (sals.sals); /* malloc'd, so freed */
1672 error ("Junk at end of arguments.");
1674 resolve_sal_pc (&sal);
1676 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
1678 old_chain = make_cleanup(delete_breakpoint, breakpoint);
1680 /* Keep within the current frame */
1684 struct frame_info *fi;
1686 fi = get_frame_info (prev_frame);
1687 sal = find_pc_line (fi->pc, 0);
1689 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
1690 make_cleanup(delete_breakpoint, breakpoint);
1693 proceed (-1, -1, 0);
1694 do_cleanups(old_chain);
1698 /* These aren't used; I don't konw what they were for. */
1699 /* Set a breakpoint at the catch clause for NAME. */
1701 catch_breakpoint (name)
1707 disable_catch_breakpoint ()
1712 delete_catch_breakpoint ()
1717 enable_catch_breakpoint ()
1724 struct sal_chain *next;
1725 struct symtab_and_line sal;
1729 /* This isn't used; I don't know what it was for. */
1730 /* For each catch clause identified in ARGS, run FUNCTION
1731 with that clause as an argument. */
1732 static struct symtabs_and_lines
1733 map_catch_names (args, function)
1737 register char *p = args;
1739 struct symtabs_and_lines sals;
1741 struct sal_chain *sal_chain = 0;
1745 error_no_arg ("one or more catch names");
1753 /* Don't swallow conditional part. */
1754 if (p1[0] == 'i' && p1[1] == 'f'
1755 && (p1[2] == ' ' || p1[2] == '\t'))
1761 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
1765 if (*p1 && *p1 != ' ' && *p1 != '\t')
1766 error ("Arguments must be catch names.");
1772 struct sal_chain *next
1773 = (struct sal_chain *)alloca (sizeof (struct sal_chain));
1774 next->next = sal_chain;
1775 next->sal = get_catch_sal (p);
1780 printf ("No catch clause for exception %s.\n", p);
1785 while (*p == ' ' || *p == '\t') p++;
1790 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
1792 static struct symtabs_and_lines
1793 get_catch_sals (this_level_only)
1794 int this_level_only;
1796 register struct blockvector *bl;
1797 register struct block *block;
1798 int index, have_default = 0;
1799 struct frame_info *fi;
1801 struct symtabs_and_lines sals;
1802 struct sal_chain *sal_chain = 0;
1803 char *blocks_searched;
1805 /* Not sure whether an error message is always the correct response,
1806 but it's better than a core dump. */
1807 if (selected_frame == NULL)
1808 error ("No selected frame.");
1809 block = get_frame_block (selected_frame);
1810 fi = get_frame_info (selected_frame);
1817 error ("No symbol table info available.\n");
1819 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
1820 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1821 bzero (blocks_searched, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1825 CORE_ADDR end = BLOCK_END (block) - 4;
1828 if (bl != blockvector_for_pc (end, &index))
1829 error ("blockvector blotch");
1830 if (BLOCKVECTOR_BLOCK (bl, index) != block)
1831 error ("blockvector botch");
1832 last_index = BLOCKVECTOR_NBLOCKS (bl);
1835 /* Don't print out blocks that have gone by. */
1836 while (index < last_index
1837 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
1840 while (index < last_index
1841 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
1843 if (blocks_searched[index] == 0)
1845 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
1848 register struct symbol *sym;
1850 nsyms = BLOCK_NSYMS (b);
1852 for (i = 0; i < nsyms; i++)
1854 sym = BLOCK_SYM (b, i);
1855 if (! strcmp (SYMBOL_NAME (sym), "default"))
1861 if (SYMBOL_CLASS (sym) == LOC_LABEL)
1863 struct sal_chain *next = (struct sal_chain *)
1864 alloca (sizeof (struct sal_chain));
1865 next->next = sal_chain;
1866 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
1870 blocks_searched[index] = 1;
1876 if (sal_chain && this_level_only)
1879 /* After handling the function's top-level block, stop.
1880 Don't continue to its superblock, the block of
1881 per-file symbols. */
1882 if (BLOCK_FUNCTION (block))
1884 block = BLOCK_SUPERBLOCK (block);
1889 struct sal_chain *tmp_chain;
1891 /* Count the number of entries. */
1892 for (index = 0, tmp_chain = sal_chain; tmp_chain;
1893 tmp_chain = tmp_chain->next)
1897 sals.sals = (struct symtab_and_line *)
1898 xmalloc (index * sizeof (struct symtab_and_line));
1899 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
1900 sals.sals[index] = sal_chain->sal;
1906 /* Commands to deal with catching exceptions. */
1909 catch_command_1 (arg, tempflag, from_tty)
1914 /* First, translate ARG into something we can deal with in terms
1917 struct symtabs_and_lines sals;
1918 struct symtab_and_line sal;
1919 register struct expression *cond = 0;
1920 register struct breakpoint *b;
1924 sal.line = sal.pc = sal.end = 0;
1927 /* If no arg given, or if first arg is 'if ', all active catch clauses
1928 are breakpointed. */
1930 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1931 && (arg[2] == ' ' || arg[2] == '\t')))
1933 /* Grab all active catch clauses. */
1934 sals = get_catch_sals (0);
1938 /* Grab selected catch clauses. */
1939 error ("catch NAME not implemeneted");
1941 /* This isn't used; I don't know what it was for. */
1942 sals = map_catch_names (arg, catch_breakpoint);
1950 for (i = 0; i < sals.nelts; i++)
1952 resolve_sal_pc (&sals.sals[i]);
1956 if (arg[0] == 'i' && arg[1] == 'f'
1957 && (arg[2] == ' ' || arg[2] == '\t'))
1958 cond = parse_exp_1 ((arg += 2, &arg),
1959 block_for_pc (sals.sals[i].pc), 0);
1961 error ("Junk at end of arguments.");
1966 for (i = 0; i < sals.nelts; i++)
1971 describe_other_breakpoints (sal.pc);
1973 b = set_raw_breakpoint (sal);
1974 set_breakpoint_count (breakpoint_count + 1);
1975 b->number = breakpoint_count;
1976 b->type = bp_breakpoint;
1978 b->enable = enabled;
1979 b->disposition = tempflag ? delete : donttouch;
1981 printf ("Breakpoint %d at %s", b->number, local_hex_string(b->address));
1983 printf (": file %s, line %d.", b->symtab->filename, b->line_number);
1989 printf ("Multiple breakpoints were set.\n");
1990 printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1996 /* These aren't used; I don't know what they were for. */
1997 /* Disable breakpoints on all catch clauses described in ARGS. */
1999 disable_catch (args)
2002 /* Map the disable command to catch clauses described in ARGS. */
2005 /* Enable breakpoints on all catch clauses described in ARGS. */
2010 /* Map the disable command to catch clauses described in ARGS. */
2013 /* Delete breakpoints on all catch clauses in the active scope. */
2018 /* Map the delete command to catch clauses described in ARGS. */
2023 catch_command (arg, from_tty)
2027 catch_command_1 (arg, 0, from_tty);
2031 clear_command (arg, from_tty)
2035 register struct breakpoint *b, *b1;
2036 struct symtabs_and_lines sals;
2037 struct symtab_and_line sal;
2038 register struct breakpoint *found;
2043 sals = decode_line_spec (arg, 1);
2047 sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
2048 sal.line = default_breakpoint_line;
2049 sal.symtab = default_breakpoint_symtab;
2051 if (sal.symtab == 0)
2052 error ("No source file specified.");
2058 for (i = 0; i < sals.nelts; i++)
2060 /* If exact pc given, clear bpts at that pc.
2061 But if sal.pc is zero, clear all bpts on specified line. */
2063 found = (struct breakpoint *) 0;
2064 while (breakpoint_chain
2065 && (sal.pc ? breakpoint_chain->address == sal.pc
2066 : (breakpoint_chain->symtab == sal.symtab
2067 && breakpoint_chain->line_number == sal.line)))
2069 b1 = breakpoint_chain;
2070 breakpoint_chain = b1->next;
2077 && b->next->type != bp_watchpoint
2078 && (sal.pc ? b->next->address == sal.pc
2079 : (b->next->symtab == sal.symtab
2080 && b->next->line_number == sal.line)))
2091 error ("No breakpoint at %s.", arg);
2093 error ("No breakpoint at this line.");
2096 if (found->next) from_tty = 1; /* Always report if deleted more than one */
2097 if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : "");
2100 if (from_tty) printf ("%d ", found->number);
2102 delete_breakpoint (found);
2105 if (from_tty) putchar ('\n');
2110 /* Delete breakpoint in BS if they are `delete' breakpoints.
2111 This is called after any breakpoint is hit, or after errors. */
2114 breakpoint_auto_delete (bs)
2117 for (; bs; bs = bs->next)
2118 if (bs->breakpoint_at && bs->breakpoint_at->disposition == delete)
2119 delete_breakpoint (bs->breakpoint_at);
2122 /* Delete a breakpoint and clean up all traces of it in the data structures. */
2125 delete_breakpoint (bpt)
2126 struct breakpoint *bpt;
2128 register struct breakpoint *b;
2132 target_remove_breakpoint(bpt->address, bpt->shadow_contents);
2134 if (breakpoint_chain == bpt)
2135 breakpoint_chain = bpt->next;
2140 b->next = bpt->next;
2144 check_duplicates (bpt->address);
2146 free_command_lines (&bpt->commands);
2149 if (bpt->cond_string != NULL)
2150 free (bpt->cond_string);
2151 if (bpt->addr_string != NULL)
2152 free (bpt->addr_string);
2154 if (xgdb_verbose && bpt->type == bp_breakpoint)
2155 printf ("breakpoint #%d deleted\n", bpt->number);
2157 /* Be sure no bpstat's are pointing at it after it's been freed. */
2158 /* FIXME, how can we find all bpstat's? We just check stop_bpstat for now. */
2159 for (bs = stop_bpstat; bs; bs = bs->next)
2160 if (bs->breakpoint_at == bpt)
2161 bs->breakpoint_at = NULL;
2166 delete_command (arg, from_tty)
2173 /* Ask user only if there are some breakpoints to delete. */
2175 || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0)))
2177 /* No arg; clear all breakpoints. */
2178 while (breakpoint_chain)
2179 delete_breakpoint (breakpoint_chain);
2183 map_breakpoint_numbers (arg, delete_breakpoint);
2186 /* Reset a breakpoint given it's struct breakpoint * BINT.
2187 The value we return ends up being the return value from catch_errors.
2188 Unused in this case. */
2191 breakpoint_re_set_one (bint)
2194 struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */
2196 struct symtabs_and_lines sals;
2198 enum enable save_enable;
2200 if (b->type != bp_watchpoint && b->addr_string != NULL)
2202 /* In case we have a problem, disable this breakpoint. We'll restore
2203 its status if we succeed. */
2204 save_enable = b->enable;
2205 b->enable = disabled;
2208 sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0);
2209 for (i = 0; i < sals.nelts; i++)
2211 resolve_sal_pc (&sals.sals[i]);
2212 b->symtab = sals.sals[i].symtab;
2213 b->line_number = sals.sals[i].line;
2214 b->address = sals.sals[i].pc;
2216 if (b->cond_string != NULL)
2219 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
2222 check_duplicates (b->address);
2224 b->enable = save_enable; /* Restore it, this worked. */
2231 /* Anything without a string can't be re-set. */
2232 delete_breakpoint (b);
2237 /* Re-set all breakpoints after symbols have been re-loaded. */
2239 breakpoint_re_set ()
2241 struct breakpoint *b, *temp;
2242 static char message1[] = "Error in re-setting breakpoint %d:\n";
2243 char message[sizeof (message1) + 30 /* slop */];
2245 ALL_BREAKPOINTS_SAFE (b, temp)
2247 b->symtab = 0; /* Be sure we don't point to old dead symtab */
2248 sprintf (message, message1, b->number); /* Format possible error msg */
2249 (void) catch_errors (breakpoint_re_set_one, (char *) b, message);
2252 /* Blank line to finish off all those mention() messages we just printed. */
2253 printf_filtered ("\n");
2256 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
2257 If from_tty is nonzero, it prints a message to that effect,
2258 which ends with a period (no newline). */
2261 set_ignore_count (bptnum, count, from_tty)
2262 int bptnum, count, from_tty;
2264 register struct breakpoint *b;
2270 if (b->number == bptnum)
2272 b->ignore_count = count;
2275 else if (count == 0)
2276 printf ("Will stop next time breakpoint %d is reached.", bptnum);
2277 else if (count == 1)
2278 printf ("Will ignore next crossing of breakpoint %d.", bptnum);
2280 printf ("Will ignore next %d crossings of breakpoint %d.",
2285 error ("No breakpoint number %d.", bptnum);
2288 /* Clear the ignore counts of all breakpoints. */
2290 breakpoint_clear_ignore_counts ()
2292 struct breakpoint *b;
2295 b->ignore_count = 0;
2298 /* Command to set ignore-count of breakpoint N to COUNT. */
2301 ignore_command (args, from_tty)
2309 error_no_arg ("a breakpoint number");
2311 num = get_number (&p);
2314 error ("Second argument (specified ignore-count) is missing.");
2316 set_ignore_count (num,
2317 longest_to_int (value_as_long (parse_and_eval (p))),
2322 /* Call FUNCTION on each of the breakpoints
2323 whose numbers are given in ARGS. */
2326 map_breakpoint_numbers (args, function)
2328 void (*function) PARAMS ((struct breakpoint *));
2330 register char *p = args;
2333 register struct breakpoint *b;
2336 error_no_arg ("one or more breakpoint numbers");
2342 num = get_number (&p1);
2345 if (b->number == num)
2350 printf ("No breakpoint number %d.\n", num);
2357 enable_breakpoint (bpt)
2358 struct breakpoint *bpt;
2360 bpt->enable = enabled;
2362 if (xgdb_verbose && bpt->type == bp_breakpoint)
2363 printf ("breakpoint #%d enabled\n", bpt->number);
2365 check_duplicates (bpt->address);
2366 if (bpt->type == bp_watchpoint)
2368 if (bpt->exp_valid_block != NULL
2369 && !contained_in (get_selected_block (), bpt->exp_valid_block))
2372 Cannot enable watchpoint %d because the block in which its expression\n\
2373 is valid is not currently in scope.\n", bpt->number);
2377 value_free (bpt->val);
2379 bpt->val = evaluate_expression (bpt->exp);
2380 release_value (bpt->val);
2386 enable_command (args, from_tty)
2390 struct breakpoint *bpt;
2392 ALL_BREAKPOINTS (bpt)
2393 enable_breakpoint (bpt);
2395 map_breakpoint_numbers (args, enable_breakpoint);
2399 disable_breakpoint (bpt)
2400 struct breakpoint *bpt;
2402 bpt->enable = disabled;
2404 if (xgdb_verbose && bpt->type == bp_breakpoint)
2405 printf ("breakpoint #%d disabled\n", bpt->number);
2407 check_duplicates (bpt->address);
2412 disable_command (args, from_tty)
2416 register struct breakpoint *bpt;
2418 ALL_BREAKPOINTS (bpt)
2419 disable_breakpoint (bpt);
2421 map_breakpoint_numbers (args, disable_breakpoint);
2425 enable_once_breakpoint (bpt)
2426 struct breakpoint *bpt;
2428 bpt->enable = enabled;
2429 bpt->disposition = disable;
2431 check_duplicates (bpt->address);
2436 enable_once_command (args, from_tty)
2440 map_breakpoint_numbers (args, enable_once_breakpoint);
2444 enable_delete_breakpoint (bpt)
2445 struct breakpoint *bpt;
2447 bpt->enable = enabled;
2448 bpt->disposition = delete;
2450 check_duplicates (bpt->address);
2455 enable_delete_command (args, from_tty)
2459 map_breakpoint_numbers (args, enable_delete_breakpoint);
2463 * Use default_breakpoint_'s, or nothing if they aren't valid.
2465 struct symtabs_and_lines
2466 decode_line_spec_1 (string, funfirstline)
2470 struct symtabs_and_lines sals;
2472 error ("Empty line specification.");
2473 if (default_breakpoint_valid)
2474 sals = decode_line_1 (&string, funfirstline,
2475 default_breakpoint_symtab, default_breakpoint_line);
2477 sals = decode_line_1 (&string, funfirstline, (struct symtab *)NULL, 0);
2479 error ("Junk at end of line specification: %s", string);
2484 /* Chain containing all defined enable commands. */
2486 extern struct cmd_list_element
2487 *enablelist, *disablelist,
2488 *deletelist, *enablebreaklist;
2490 extern struct cmd_list_element *cmdlist;
2493 _initialize_breakpoint ()
2495 breakpoint_chain = 0;
2496 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
2497 before a breakpoint is set. */
2498 breakpoint_count = 0;
2500 add_com ("ignore", class_breakpoint, ignore_command,
2501 "Set ignore-count of breakpoint number N to COUNT.");
2503 add_com ("commands", class_breakpoint, commands_command,
2504 "Set commands to be executed when a breakpoint is hit.\n\
2505 Give breakpoint number as argument after \"commands\".\n\
2506 With no argument, the targeted breakpoint is the last one set.\n\
2507 The commands themselves follow starting on the next line.\n\
2508 Type a line containing \"end\" to indicate the end of them.\n\
2509 Give \"silent\" as the first line to make the breakpoint silent;\n\
2510 then no output is printed when it is hit, except what the commands print.");
2512 add_com ("condition", class_breakpoint, condition_command,
2513 "Specify breakpoint number N to break only if COND is true.\n\
2514 N is an integer; COND is an expression to be evaluated whenever\n\
2515 breakpoint N is reached. ");
2517 add_com ("tbreak", class_breakpoint, tbreak_command,
2518 "Set a temporary breakpoint. Args like \"break\" command.\n\
2519 Like \"break\" except the breakpoint is only enabled temporarily,\n\
2520 so it will be disabled when hit. Equivalent to \"break\" followed\n\
2521 by using \"enable once\" on the breakpoint number.");
2523 add_prefix_cmd ("enable", class_breakpoint, enable_command,
2524 "Enable some breakpoints.\n\
2525 Give breakpoint numbers (separated by spaces) as arguments.\n\
2526 With no subcommand, breakpoints are enabled until you command otherwise.\n\
2527 This is used to cancel the effect of the \"disable\" command.\n\
2528 With a subcommand you can enable temporarily.",
2529 &enablelist, "enable ", 1, &cmdlist);
2531 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
2532 "Enable some breakpoints.\n\
2533 Give breakpoint numbers (separated by spaces) as arguments.\n\
2534 This is used to cancel the effect of the \"disable\" command.\n\
2535 May be abbreviated to simply \"enable\".\n",
2536 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
2538 add_cmd ("once", no_class, enable_once_command,
2539 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
2540 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2541 See the \"tbreak\" command which sets a breakpoint and enables it once.",
2544 add_cmd ("delete", no_class, enable_delete_command,
2545 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
2546 If a breakpoint is hit while enabled in this fashion, it is deleted.",
2549 add_cmd ("delete", no_class, enable_delete_command,
2550 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
2551 If a breakpoint is hit while enabled in this fashion, it is deleted.",
2554 add_cmd ("once", no_class, enable_once_command,
2555 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
2556 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2557 See the \"tbreak\" command which sets a breakpoint and enables it once.",
2560 add_prefix_cmd ("disable", class_breakpoint, disable_command,
2561 "Disable some breakpoints.\n\
2562 Arguments are breakpoint numbers with spaces in between.\n\
2563 To disable all breakpoints, give no argument.\n\
2564 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
2565 &disablelist, "disable ", 1, &cmdlist);
2566 add_com_alias ("dis", "disable", class_breakpoint, 1);
2567 add_com_alias ("disa", "disable", class_breakpoint, 1);
2569 add_cmd ("breakpoints", class_alias, disable_command,
2570 "Disable some breakpoints.\n\
2571 Arguments are breakpoint numbers with spaces in between.\n\
2572 To disable all breakpoints, give no argument.\n\
2573 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
2574 This command may be abbreviated \"disable\".",
2577 add_prefix_cmd ("delete", class_breakpoint, delete_command,
2578 "Delete some breakpoints or auto-display expressions.\n\
2579 Arguments are breakpoint numbers with spaces in between.\n\
2580 To delete all breakpoints, give no argument.\n\
2582 Also a prefix command for deletion of other GDB objects.\n\
2583 The \"unset\" command is also an alias for \"delete\".",
2584 &deletelist, "delete ", 1, &cmdlist);
2585 add_com_alias ("d", "delete", class_breakpoint, 1);
2587 add_cmd ("breakpoints", class_alias, delete_command,
2588 "Delete some breakpoints or auto-display expressions.\n\
2589 Arguments are breakpoint numbers with spaces in between.\n\
2590 To delete all breakpoints, give no argument.\n\
2591 This command may be abbreviated \"delete\".",
2594 add_com ("clear", class_breakpoint, clear_command,
2595 "Clear breakpoint at specified line or function.\n\
2596 Argument may be line number, function name, or \"*\" and an address.\n\
2597 If line number is specified, all breakpoints in that line are cleared.\n\
2598 If function is specified, breakpoints at beginning of function are cleared.\n\
2599 If an address is specified, breakpoints at that address are cleared.\n\n\
2600 With no argument, clears all breakpoints in the line that the selected frame\n\
2603 See also the \"delete\" command which clears breakpoints by number.");
2605 add_com ("break", class_breakpoint, break_command,
2606 "Set breakpoint at specified line or function.\n\
2607 Argument may be line number, function name, or \"*\" and an address.\n\
2608 If line number is specified, break at start of code for that line.\n\
2609 If function is specified, break at start of code for that function.\n\
2610 If an address is specified, break at that exact address.\n\
2611 With no arg, uses current execution address of selected stack frame.\n\
2612 This is useful for breaking on return to a stack frame.\n\
2614 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
2616 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2617 add_com_alias ("b", "break", class_run, 1);
2618 add_com_alias ("br", "break", class_run, 1);
2619 add_com_alias ("bre", "break", class_run, 1);
2620 add_com_alias ("brea", "break", class_run, 1);
2622 add_info ("breakpoints", breakpoints_info,
2623 "Status of all breakpoints, or breakpoint number NUMBER.\n\
2624 Second column is \"y\" for enabled breakpoint, \"n\" for disabled,\n\
2625 \"o\" for enabled once (disable when hit), \"d\" for enable but delete when hit.\n\
2626 Then come the address and the file/line number.\n\n\
2627 Convenience variable \"$_\" and default examine address for \"x\"\n\
2628 are set to the address of the last breakpoint listed.\n\n\
2629 Convenience variable \"$bpnum\" contains the number of the last\n\
2632 add_com ("catch", class_breakpoint, catch_command,
2633 "Set breakpoints to catch exceptions that are raised.\n\
2634 Argument may be a single exception to catch, multiple exceptions\n\
2635 to catch, or the default exception \"default\". If no arguments\n\
2636 are given, breakpoints are set at all exception handlers catch clauses\n\
2637 within the current scope.\n\
2639 A condition specified for the catch applies to all breakpoints set\n\
2640 with this command\n\
2642 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2644 add_com ("watch", class_breakpoint, watch_command,
2645 "Set a watchpoint for an expression.\n\
2646 A watchpoint stops execution of your program whenever the value of\n\
2647 an expression changes.");
2649 add_info ("watchpoints", watchpoints_info,
2650 "Status of all watchpoints, or watchpoint number NUMBER.\n\
2651 Second column is \"y\" for enabled watchpoints, \"n\" for disabled.");