1 /* Everything about breakpoints, for GDB.
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "breakpoint.h"
26 #include "expression.h"
37 /* local function prototypes */
40 catch_command_1 PARAMS ((char *, int, int));
43 enable_delete_command PARAMS ((char *, int));
46 enable_delete_breakpoint PARAMS ((struct breakpoint *));
49 enable_once_command PARAMS ((char *, int));
52 enable_once_breakpoint PARAMS ((struct breakpoint *));
55 disable_command PARAMS ((char *, int));
58 disable_breakpoint PARAMS ((struct breakpoint *));
61 enable_command PARAMS ((char *, int));
64 enable_breakpoint PARAMS ((struct breakpoint *));
67 map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *)));
70 ignore_command PARAMS ((char *, int));
73 breakpoint_re_set_one PARAMS ((char *));
76 delete_command PARAMS ((char *, int));
79 clear_command PARAMS ((char *, int));
82 catch_command PARAMS ((char *, int));
84 static struct symtabs_and_lines
85 get_catch_sals PARAMS ((int));
88 watch_command PARAMS ((char *, int));
91 tbreak_command PARAMS ((char *, int));
94 break_command_1 PARAMS ((char *, int, int));
97 mention PARAMS ((struct breakpoint *));
99 static struct breakpoint *
100 set_raw_breakpoint PARAMS ((struct symtab_and_line));
103 check_duplicates PARAMS ((CORE_ADDR));
106 describe_other_breakpoints PARAMS ((CORE_ADDR));
109 watchpoints_info PARAMS ((char *, int));
112 breakpoints_info PARAMS ((char *, int));
115 breakpoint_1 PARAMS ((int, enum bptype, int));
118 bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
121 breakpoint_cond_eval PARAMS ((char *));
124 cleanup_executing_breakpoints PARAMS ((int));
127 commands_command PARAMS ((char *, int));
130 condition_command PARAMS ((char *, int));
133 get_number PARAMS ((char **));
136 set_breakpoint_count PARAMS ((int));
139 extern int addressprint; /* Print machine addresses? */
140 extern int demangle; /* Print de-mangled symbol names? */
142 /* Are we executing breakpoint commands? */
143 static int executing_breakpoint_commands;
145 /* Walk the following statement or block through all breakpoints.
146 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
149 #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
151 #define ALL_BREAKPOINTS_SAFE(b,tmp) \
152 for (b = breakpoint_chain; \
153 b? (tmp=b->next, 1): 0; \
156 /* Chain of all breakpoints defined. */
158 struct breakpoint *breakpoint_chain;
160 /* Number of last breakpoint made. */
162 static int breakpoint_count;
164 /* Set breakpoint count to NUM. */
166 set_breakpoint_count (num)
169 breakpoint_count = num;
170 set_internalvar (lookup_internalvar ("bpnum"),
171 value_from_longest (builtin_type_int, (LONGEST) num));
174 /* Default address, symtab and line to put a breakpoint at
175 for "break" command with no arg.
176 if default_breakpoint_valid is zero, the other three are
177 not valid, and "break" with no arg is an error.
179 This set by print_stack_frame, which calls set_default_breakpoint. */
181 int default_breakpoint_valid;
182 CORE_ADDR default_breakpoint_address;
183 struct symtab *default_breakpoint_symtab;
184 int default_breakpoint_line;
186 /* Flag indicating extra verbosity for xgdb. */
187 extern int xgdb_verbose;
189 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
190 Advance *PP after the string and any trailing whitespace.
192 Currently the string can either be a number or "$" followed by the name
193 of a convenience variable. Making it an expression wouldn't work well
194 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
203 /* Empty line means refer to the last breakpoint. */
204 return breakpoint_count;
207 /* Make a copy of the name, so we can null-terminate it
208 to pass to lookup_internalvar(). */
213 while (isalnum (*p) || *p == '_')
215 varname = (char *) alloca (p - start + 1);
216 strncpy (varname, start, p - start);
217 varname[p - start] = '\0';
218 val = value_of_internalvar (lookup_internalvar (varname));
219 if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
221 "Convenience variables used to specify breakpoints must have integer values."
223 retval = (int) value_as_long (val);
229 while (*p >= '0' && *p <= '9')
232 /* There is no number here. (e.g. "cond a == b"). */
233 error_no_arg ("breakpoint number");
236 if (!(isspace (*p) || *p == '\0'))
237 error ("breakpoint number expected");
244 /* condition N EXP -- set break condition of breakpoint N to EXP. */
247 condition_command (arg, from_tty)
251 register struct breakpoint *b;
256 error_no_arg ("breakpoint number");
259 bnum = get_number (&p);
262 if (b->number == bnum)
269 if (b->cond_string != NULL)
270 free (b->cond_string);
275 b->cond_string = NULL;
277 printf ("Breakpoint %d now unconditional.\n", bnum);
282 /* I don't know if it matters whether this is the string the user
283 typed in or the decompiled expression. */
284 b->cond_string = savestring (arg, strlen (arg));
285 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
287 error ("Junk at end of expression");
292 error ("No breakpoint number %d.", bnum);
297 commands_command (arg, from_tty)
301 register struct breakpoint *b;
304 struct command_line *l;
306 /* If we allowed this, we would have problems with when to
307 free the storage, if we change the commands currently
310 if (executing_breakpoint_commands)
311 error ("Can't use the \"commands\" command among a breakpoint's commands.");
314 bnum = get_number (&p);
316 error ("Unexpected extra arguments following breakpoint number.");
319 if (b->number == bnum)
321 if (from_tty && input_from_terminal_p ())
323 printf ("Type commands for when breakpoint %d is hit, one per line.\n\
324 End with a line saying just \"end\".\n", bnum);
327 l = read_command_lines ();
328 free_command_lines (&b->commands);
332 error ("No breakpoint number %d.", bnum);
335 extern int memory_breakpoint_size; /* from mem-break.c */
337 /* Like target_read_memory() but if breakpoints are inserted, return
338 the shadow contents instead of the breakpoints themselves.
340 Read "memory data" from whatever target or inferior we have.
341 Returns zero if successful, errno value if not. EIO is used
342 for address out of bounds. If breakpoints are inserted, returns
343 shadow contents, not the breakpoints themselves. From breakpoint.c. */
346 read_memory_nobpt (memaddr, myaddr, len)
352 struct breakpoint *b;
354 if (memory_breakpoint_size < 0)
355 /* No breakpoints on this machine. */
356 return target_read_memory (memaddr, myaddr, len);
360 if (b->type == bp_watchpoint || !b->inserted)
362 else if (b->address + memory_breakpoint_size <= memaddr)
363 /* The breakpoint is entirely before the chunk of memory
366 else if (b->address >= memaddr + len)
367 /* The breakpoint is entirely after the chunk of memory we
372 /* Copy the breakpoint from the shadow contents, and recurse
373 for the things before and after. */
375 /* Addresses and length of the part of the breakpoint that
377 CORE_ADDR membpt = b->address;
378 unsigned int bptlen = memory_breakpoint_size;
379 /* Offset within shadow_contents. */
382 if (membpt < memaddr)
384 /* Only copy the second part of the breakpoint. */
385 bptlen -= memaddr - membpt;
386 bptoffset = memaddr - membpt;
390 if (membpt + bptlen > memaddr + len)
392 /* Only copy the first part of the breakpoint. */
393 bptlen -= (membpt + bptlen) - (memaddr + len);
396 bcopy (b->shadow_contents + bptoffset,
397 myaddr + membpt - memaddr, bptlen);
399 if (membpt > memaddr)
401 /* Copy the section of memory before the breakpoint. */
402 status = read_memory_nobpt (memaddr, myaddr, membpt - memaddr);
407 if (membpt + bptlen < memaddr + len)
409 /* Copy the section of memory after the breakpoint. */
410 status = read_memory_nobpt
412 myaddr + membpt + bptlen - memaddr,
413 memaddr + len - (membpt + bptlen));
420 /* Nothing overlaps. Just call read_memory_noerr. */
421 return target_read_memory (memaddr, myaddr, len);
424 /* insert_breakpoints is used when starting or continuing the program.
425 remove_breakpoints is used when the program stops.
426 Both return zero if successful,
427 or an `errno' value if could not write the inferior. */
430 insert_breakpoints ()
432 register struct breakpoint *b;
434 int disabled_breaks = 0;
437 if (b->type != bp_watchpoint
438 && b->enable != disabled
442 val = target_insert_breakpoint(b->address, b->shadow_contents);
445 /* Can't set the breakpoint. */
446 #if defined (DISABLE_UNSETTABLE_BREAK)
447 if (DISABLE_UNSETTABLE_BREAK (b->address))
450 b->enable = disabled;
451 if (!disabled_breaks)
454 "Cannot insert breakpoint %d:\n", b->number);
455 printf_filtered ("Disabling shared library breakpoints:\n");
458 printf_filtered ("%d ", b->number);
463 fprintf (stderr, "Cannot insert breakpoint %d:\n", b->number);
464 #ifdef ONE_PROCESS_WRITETEXT
466 "The same program may be running in another process.\n");
468 memory_error (val, b->address); /* which bombs us out */
475 printf_filtered ("\n");
480 remove_breakpoints ()
482 register struct breakpoint *b;
485 #ifdef BREAKPOINT_DEBUG
486 printf ("Removing breakpoints.\n");
487 #endif /* BREAKPOINT_DEBUG */
490 if (b->type != bp_watchpoint && b->inserted)
492 val = target_remove_breakpoint(b->address, b->shadow_contents);
496 #ifdef BREAKPOINT_DEBUG
497 printf ("Removed breakpoint at %s",
498 local_hex_string(b->address));
499 printf (", shadow %s",
500 local_hex_string(b->shadow_contents[0]));
502 local_hex_string(b->shadow_contents[1]));
503 #endif /* BREAKPOINT_DEBUG */
509 /* Clear the "inserted" flag in all breakpoints.
510 This is done when the inferior is loaded. */
513 mark_breakpoints_out ()
515 register struct breakpoint *b;
521 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
522 When continuing from a location with a breakpoint,
523 we actually single step once before calling insert_breakpoints. */
526 breakpoint_here_p (pc)
529 register struct breakpoint *b;
532 if (b->enable != disabled && b->address == pc)
538 /* bpstat stuff. External routines' interfaces are documented
541 /* Clear a bpstat so that it says we are not at any breakpoint.
542 Also free any storage that is part of a bpstat. */
557 if (p->old_val != NULL)
558 value_free (p->old_val);
565 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
566 is part of the bpstat is copied as well. */
579 for (; bs != NULL; bs = bs->next)
581 tmp = (bpstat) xmalloc (sizeof (*tmp));
582 bcopy (bs, tmp, sizeof (*tmp));
584 /* This is the first thing in the chain. */
594 /* Find the bpstat associated with this breakpoint */
597 bpstat_find_breakpoint(bsp, breakpoint)
599 struct breakpoint *breakpoint;
601 if (bsp == NULL) return NULL;
603 for (;bsp != NULL; bsp = bsp->next) {
604 if (bsp->breakpoint_at == breakpoint) return bsp;
609 /* Return the breakpoint number of the first breakpoint we are stopped
610 at. *BSP upon return is a bpstat which points to the remaining
611 breakpoints stopped at (but which is not guaranteed to be good for
612 anything but further calls to bpstat_num).
613 Return 0 if passed a bpstat which does not indicate any breakpoints. */
619 struct breakpoint *b;
622 return 0; /* No more breakpoint values */
625 b = (*bsp)->breakpoint_at;
628 return -1; /* breakpoint that's been deleted since */
630 return b->number; /* We have its number */
634 /* Modify BS so that the actions will not be performed. */
637 bpstat_clear_actions (bs)
640 for (; bs != NULL; bs = bs->next)
643 if (bs->old_val != NULL)
645 value_free (bs->old_val);
651 /* Stub for cleaning up our state if we error-out of a breakpoint command */
654 cleanup_executing_breakpoints (ignore)
657 executing_breakpoint_commands = 0;
660 /* Execute all the commands associated with all the breakpoints at this
661 location. Any of these commands could cause the process to proceed
662 beyond this point, etc. We look out for such changes by checking
663 the global "breakpoint_proceeded" after each command. */
666 bpstat_do_actions (bsp)
670 struct cleanup *old_chain;
672 executing_breakpoint_commands = 1;
673 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
678 breakpoint_proceeded = 0;
679 for (; bs != NULL; bs = bs->next)
683 char *line = bs->commands->line;
684 bs->commands = bs->commands->next;
685 execute_command (line, 0);
686 /* If the inferior is proceeded by the command, bomb out now.
687 The bpstat chain has been blown away by wait_for_inferior.
688 But since execution has stopped again, there is a new bpstat
689 to look at, so start over. */
690 if (breakpoint_proceeded)
695 executing_breakpoint_commands = 0;
696 discard_cleanups (old_chain);
699 /* Print a message indicating what happened. Returns nonzero to
700 say that only the source line should be printed after this (zero
701 return means print the frame as well as the source line). */
707 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
708 which has since been deleted. */
710 || bs->breakpoint_at == NULL
711 || (bs->breakpoint_at->type != bp_breakpoint
712 && bs->breakpoint_at->type != bp_watchpoint))
715 /* If bpstat_stop_status says don't print, OK, we won't. An example
716 circumstance is when we single-stepped for both a watchpoint and
717 for a "stepi" instruction. The bpstat says that the watchpoint
718 explains the stop, but we shouldn't print because the watchpoint's
719 value didn't change -- and the real reason we are stopping here
720 rather than continuing to step (as the watchpoint would've had us do)
721 is because of the "stepi". */
725 if (bs->breakpoint_at->type == bp_breakpoint)
727 /* I think the user probably only wants to see one breakpoint
728 number, not all of them. */
729 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
733 if (bs->old_val != NULL)
735 printf_filtered ("\nWatchpoint %d, ", bs->breakpoint_at->number);
736 print_expression (bs->breakpoint_at->exp, stdout);
737 printf_filtered ("\nOld value = ");
738 value_print (bs->old_val, stdout, 0, Val_pretty_default);
739 printf_filtered ("\nNew value = ");
740 value_print (bs->breakpoint_at->val, stdout, 0,
742 printf_filtered ("\n");
743 value_free (bs->old_val);
748 /* Maybe another breakpoint in the chain caused us to stop.
749 (Currently all watchpoints go on the bpstat whether hit or
750 not. That probably could (should) be changed, provided care is taken
751 with respect to bpstat_explains_signal). */
753 return bpstat_print (bs->next);
755 fprintf_filtered (stderr, "gdb internal error: in bpstat_print\n");
759 /* Evaluate the expression EXP and return 1 if value is zero.
760 This is used inside a catch_errors to evaluate the breakpoint condition.
761 The argument is a "struct expression *" that has been cast to char * to
762 make it pass through catch_errors. */
765 breakpoint_cond_eval (exp)
768 return !value_true (evaluate_expression ((struct expression *)exp));
771 /* Allocate a new bpstat and chain it to the current one. */
774 bpstat_alloc (b, cbs)
775 register struct breakpoint *b;
776 bpstat cbs; /* Current "bs" value */
780 bs = (bpstat) xmalloc (sizeof (*bs));
782 bs->breakpoint_at = b;
783 /* If the condition is false, etc., don't do the commands. */
785 bs->momentary = b->disposition == delete;
790 /* Determine whether we stopped at a breakpoint, etc, or whether we
791 don't understand this stop. Result is a chain of bpstat's such that:
793 if we don't understand the stop, the result is a null pointer.
795 if we understand why we stopped, the result is not null, and
796 the first element of the chain contains summary "stop" and
797 "print" flags for the whole chain.
799 Each element of the chain refers to a particular breakpoint or
800 watchpoint at which we have stopped. (We may have stopped for
803 Each element of the chain has valid next, breakpoint_at,
804 commands, FIXME??? fields.
810 bpstat_stop_status (pc, frame_address)
812 FRAME_ADDR frame_address;
814 register struct breakpoint *b;
818 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
819 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
820 int real_breakpoint = 0;
822 /* Root of the chain of bpstat's */
823 struct bpstat root_bs[1];
824 /* Pointer to the last thing in the chain currently. */
827 /* Get the address where the breakpoint would have been. */
828 bp_addr = *pc - DECR_PC_AFTER_BREAK;
835 if (b->enable == disabled)
838 if (b->type != bp_watchpoint && b->address != bp_addr)
841 /* Come here if it's a watchpoint, or if the break address matches */
843 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
848 if (b->type == bp_watchpoint)
850 int within_current_scope;
851 if (b->exp_valid_block != NULL)
852 within_current_scope =
853 contained_in (get_selected_block (), b->exp_valid_block);
855 within_current_scope = 1;
857 if (within_current_scope)
859 /* We use value_{,free_to_}mark because it could be a
860 *long* time before we return to the command level and
861 call free_all_values. */
863 value mark = value_mark ();
864 value new_val = evaluate_expression (b->exp);
865 if (!value_equal (b->val, new_val))
867 release_value (new_val);
868 value_free_to_mark (mark);
869 bs->old_val = b->val;
871 /* We will stop here */
875 /* Nothing changed, don't do anything. */
876 value_free_to_mark (mark);
878 /* We won't stop here */
883 /* This seems like the only logical thing to do because
884 if we temporarily ignored the watchpoint, then when
885 we reenter the block in which it is valid it contains
886 garbage (in the case of a function, it may have two
887 garbage values, one before and one after the prologue).
888 So we can't even detect the first assignment to it and
889 watch after that (since the garbage may or may not equal
890 the first value assigned). */
891 b->enable = disabled;
893 Watchpoint %d disabled because the program has left the block in\n\
894 which its expression is valid.\n", b->number);
895 /* We won't stop here */
896 /* FIXME, maybe we should stop here!!! */
900 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
905 if (b->frame && b->frame != frame_address)
913 /* Need to select the frame, with all that implies
914 so that the conditions will have the right context. */
915 select_frame (get_current_frame (), 0);
917 = catch_errors (breakpoint_cond_eval, (char *)(b->cond),
918 "Error in testing breakpoint condition:\n");
919 /* FIXME-someday, should give breakpoint # */
922 if (b->cond && value_is_zero)
926 else if (b->ignore_count > 0)
933 /* We will stop here */
934 if (b->disposition == disable)
935 b->enable = disabled;
936 bs->commands = b->commands;
939 if (bs->commands && !strcmp ("silent", bs->commands->line))
941 bs->commands = bs->commands->next;
952 bs->next = NULL; /* Terminate the chain */
953 bs = root_bs->next; /* Re-grab the head of the chain */
958 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
962 #if defined (SHIFT_INST_REGS)
964 CORE_ADDR pc = read_register (PC_REGNUM);
965 CORE_ADDR npc = read_register (NPC_REGNUM);
968 write_register (NNPC_REGNUM, npc);
969 write_register (NPC_REGNUM, pc);
972 #else /* No SHIFT_INST_REGS. */
974 #endif /* No SHIFT_INST_REGS. */
976 #endif /* DECR_PC_AFTER_BREAK != 0. */
981 /* Nonzero if we should step constantly (e.g. watchpoints on machines
982 without hardware support). This isn't related to a specific bpstat,
983 just to things like whether watchpoints are set. */
986 bpstat_should_step ()
988 struct breakpoint *b;
990 if (b->enable == enabled && b->type == bp_watchpoint)
995 /* Print information on breakpoint number BNUM, or -1 if all.
996 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
997 is nonzero, process only watchpoints. */
1000 breakpoint_1 (bnum, type, allflag)
1005 register struct breakpoint *b;
1006 register struct command_line *l;
1007 register struct symbol *sym;
1008 CORE_ADDR last_addr = (CORE_ADDR)-1;
1009 int found_a_breakpoint = 0;
1010 static char *bptypes[] = {"breakpoint", "until", "finish", "watchpoint",
1011 "longjmp", "longjmp resume"};
1012 static char *bpdisps[] = {"del", "dis", "keep"};
1013 static char bpenables[] = "ny";
1015 if (!breakpoint_chain)
1017 printf_filtered ("No breakpoints or watchpoints.\n");
1023 || bnum == b->number)
1025 /* We only print out user settable breakpoints unless the allflag is set. */
1027 && b->type != bp_breakpoint
1028 && b->type != bp_watchpoint)
1031 if (!found_a_breakpoint++)
1032 printf_filtered ("Num Type Disp Enb %sWhat\n",
1033 addressprint ? "Address " : "");
1035 printf_filtered ("%-3d %-14s %-4s %-3c ",
1038 bpdisps[b->disposition],
1039 bpenables[b->enable]);
1043 print_expression (b->exp, stdout);
1049 case bp_longjmp_resume:
1051 printf_filtered ("%s ", local_hex_string_custom(b->address, "08"));
1053 last_addr = b->address;
1056 sym = find_pc_function (b->address);
1059 fputs_filtered ("in ", stdout);
1060 fputs_demangled (SYMBOL_NAME (sym), stdout, 1);
1061 fputs_filtered (" at ", stdout);
1063 fputs_filtered (b->symtab->filename, stdout);
1064 printf_filtered (":%d", b->line_number);
1067 print_address_symbolic (b->address, stdout, demangle, " ");
1070 printf_filtered ("\n");
1073 printf_filtered ("\tstop only in stack frame at %s\n",
1074 local_hex_string(b->frame));
1077 printf_filtered ("\tstop only if ");
1078 print_expression (b->cond, stdout);
1079 printf_filtered ("\n");
1081 if (b->ignore_count)
1082 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
1083 if ((l = b->commands))
1086 fputs_filtered ("\t", stdout);
1087 fputs_filtered (l->line, stdout);
1088 fputs_filtered ("\n", stdout);
1093 if (!found_a_breakpoint
1095 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
1097 /* Compare against (CORE_ADDR)-1 in case some compiler decides
1098 that a comparison of an unsigned with -1 is always false. */
1099 if (last_addr != (CORE_ADDR)-1)
1100 set_next_address (last_addr);
1105 breakpoints_info (bnum_exp, from_tty)
1112 bnum = parse_and_eval_address (bnum_exp);
1114 breakpoint_1 (bnum, bp_breakpoint, 0);
1119 all_breakpoints_info (bnum_exp, from_tty)
1126 bnum = parse_and_eval_address (bnum_exp);
1128 breakpoint_1 (bnum, bp_breakpoint, 1);
1133 watchpoints_info (bnum_exp, from_tty)
1140 bnum = parse_and_eval_address (bnum_exp);
1142 breakpoint_1 (bnum, bp_watchpoint, 0);
1145 /* Print a message describing any breakpoints set at PC. */
1148 describe_other_breakpoints (pc)
1149 register CORE_ADDR pc;
1151 register int others = 0;
1152 register struct breakpoint *b;
1155 if (b->address == pc)
1159 printf ("Note: breakpoint%s ", (others > 1) ? "s" : "");
1161 if (b->address == pc)
1166 (b->enable == disabled) ? " (disabled)" : "",
1167 (others > 1) ? "," : ((others == 1) ? " and" : ""));
1169 printf ("also set at pc %s.\n", local_hex_string(pc));
1173 /* Set the default place to put a breakpoint
1174 for the `break' command with no arguments. */
1177 set_default_breakpoint (valid, addr, symtab, line)
1180 struct symtab *symtab;
1183 default_breakpoint_valid = valid;
1184 default_breakpoint_address = addr;
1185 default_breakpoint_symtab = symtab;
1186 default_breakpoint_line = line;
1189 /* Rescan breakpoints at address ADDRESS,
1190 marking the first one as "first" and any others as "duplicates".
1191 This is so that the bpt instruction is only inserted once. */
1194 check_duplicates (address)
1197 register struct breakpoint *b;
1198 register int count = 0;
1200 if (address == 0) /* Watchpoints are uninteresting */
1204 if (b->enable != disabled && b->address == address)
1207 b->duplicate = count > 1;
1211 /* Low level routine to set a breakpoint.
1212 Takes as args the three things that every breakpoint must have.
1213 Returns the breakpoint object so caller can set other things.
1214 Does not set the breakpoint number!
1215 Does not print anything.
1217 ==> This routine should not be called if there is a chance of later
1218 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
1219 your arguments BEFORE calling this routine! */
1221 static struct breakpoint *
1222 set_raw_breakpoint (sal)
1223 struct symtab_and_line sal;
1225 register struct breakpoint *b, *b1;
1227 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
1228 bzero (b, sizeof *b);
1229 b->address = sal.pc;
1230 b->symtab = sal.symtab;
1231 b->line_number = sal.line;
1232 b->enable = enabled;
1235 b->ignore_count = 0;
1239 /* Add this breakpoint to the end of the chain
1240 so that a list of breakpoints will come out in order
1241 of increasing numbers. */
1243 b1 = breakpoint_chain;
1245 breakpoint_chain = b;
1253 check_duplicates (sal.pc);
1259 create_longjmp_breakpoint(func_name)
1263 struct symtab_and_line sal;
1264 struct breakpoint *b;
1265 static int internal_breakpoint_number = -1;
1267 if (func_name != NULL)
1269 struct minimal_symbol *m;
1271 m = lookup_minimal_symbol(func_name, (struct objfile *)NULL);
1273 sal.pc = m->address;
1283 b = set_raw_breakpoint(sal);
1286 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
1287 b->disposition = donttouch;
1288 b->enable = disabled;
1291 b->addr_string = strsave(func_name);
1292 b->number = internal_breakpoint_number--;
1295 /* Call this routine when stepping and nexting to enable a breakpoint if we do
1296 a longjmp(). When we hit that breakpoint, call
1297 set_longjmp_resume_breakpoint() to figure out where we are going. */
1300 enable_longjmp_breakpoint()
1302 register struct breakpoint *b;
1305 if (b->type == bp_longjmp)
1306 b->enable = enabled;
1310 disable_longjmp_breakpoint()
1312 register struct breakpoint *b;
1315 if (b->type == bp_longjmp
1316 || b->type == bp_longjmp_resume)
1317 b->enable = disabled;
1320 /* Call this after hitting the longjmp() breakpoint. Use this to set a new
1321 breakpoint at the target of the jmp_buf.
1323 FIXME - This ought to be done by setting a temporary breakpoint that gets
1324 deleted automatically...
1328 set_longjmp_resume_breakpoint(pc, frame)
1332 register struct breakpoint *b;
1335 if (b->type == bp_longjmp_resume)
1338 b->enable = enabled;
1340 b->frame = FRAME_FP(frame);
1347 /* Set a breakpoint that will evaporate an end of command
1348 at address specified by SAL.
1349 Restrict it to frame FRAME if FRAME is nonzero. */
1352 set_momentary_breakpoint (sal, frame, type)
1353 struct symtab_and_line sal;
1357 register struct breakpoint *b;
1358 b = set_raw_breakpoint (sal);
1360 b->enable = enabled;
1361 b->disposition = donttouch;
1362 b->frame = (frame ? FRAME_FP (frame) : 0);
1368 clear_momentary_breakpoints ()
1370 register struct breakpoint *b;
1372 if (b->disposition == delete)
1374 delete_breakpoint (b);
1380 /* Tell the user we have just set a breakpoint B. */
1383 struct breakpoint *b;
1388 printf_filtered ("Watchpoint %d: ", b->number);
1389 print_expression (b->exp, stdout);
1392 printf_filtered ("Breakpoint %d at %s", b->number,
1393 local_hex_string(b->address));
1395 printf_filtered (": file %s, line %d.",
1396 b->symtab->filename, b->line_number);
1398 printf_filtered ("\n");
1402 /* Nobody calls this currently. */
1403 /* Set a breakpoint from a symtab and line.
1404 If TEMPFLAG is nonzero, it is a temporary breakpoint.
1405 ADDR_STRING is a malloc'd string holding the name of where we are
1406 setting the breakpoint. This is used later to re-set it after the
1407 program is relinked and symbols are reloaded.
1408 Print the same confirmation messages that the breakpoint command prints. */
1411 set_breakpoint (s, line, tempflag, addr_string)
1417 register struct breakpoint *b;
1418 struct symtab_and_line sal;
1423 resolve_sal_pc (&sal); /* Might error out */
1424 describe_other_breakpoints (sal.pc);
1426 b = set_raw_breakpoint (sal);
1427 set_breakpoint_count (breakpoint_count + 1);
1428 b->number = breakpoint_count;
1429 b->type = bp_breakpoint;
1431 b->addr_string = addr_string;
1432 b->enable = enabled;
1433 b->disposition = tempflag ? delete : donttouch;
1439 /* Set a breakpoint according to ARG (function, linenum or *address)
1440 and make it temporary if TEMPFLAG is nonzero. */
1443 break_command_1 (arg, tempflag, from_tty)
1445 int tempflag, from_tty;
1447 struct symtabs_and_lines sals;
1448 struct symtab_and_line sal;
1449 register struct expression *cond = 0;
1450 register struct breakpoint *b;
1452 /* Pointers in arg to the start, and one past the end, of the condition. */
1453 char *cond_start = NULL;
1455 /* Pointers in arg to the start, and one past the end,
1456 of the address part. */
1457 char *addr_start = NULL;
1465 sal.line = sal.pc = sal.end = 0;
1468 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
1470 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1471 && (arg[2] == ' ' || arg[2] == '\t')))
1473 if (default_breakpoint_valid)
1475 sals.sals = (struct symtab_and_line *)
1476 xmalloc (sizeof (struct symtab_and_line));
1477 sal.pc = default_breakpoint_address;
1478 sal.line = default_breakpoint_line;
1479 sal.symtab = default_breakpoint_symtab;
1484 error ("No default breakpoint address now.");
1490 /* Force almost all breakpoints to be in terms of the
1491 current_source_symtab (which is decode_line_1's default). This
1492 should produce the results we want almost all of the time while
1493 leaving default_breakpoint_* alone. */
1494 if (default_breakpoint_valid
1495 && (!current_source_symtab
1496 || (arg && (*arg == '+' || *arg == '-'))))
1497 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1498 default_breakpoint_line);
1500 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1508 /* Resolve all line numbers to PC's, and verify that conditions
1509 can be parsed, before setting any breakpoints. */
1510 for (i = 0; i < sals.nelts; i++)
1512 resolve_sal_pc (&sals.sals[i]);
1516 if (arg[0] == 'i' && arg[1] == 'f'
1517 && (arg[2] == ' ' || arg[2] == '\t'))
1521 cond = parse_exp_1 (&arg, block_for_pc (sals.sals[i].pc), 0);
1525 error ("Junk at end of arguments.");
1529 /* Now set all the breakpoints. */
1530 for (i = 0; i < sals.nelts; i++)
1535 describe_other_breakpoints (sal.pc);
1537 b = set_raw_breakpoint (sal);
1538 set_breakpoint_count (breakpoint_count + 1);
1539 b->number = breakpoint_count;
1540 b->type = bp_breakpoint;
1544 b->addr_string = savestring (addr_start, addr_end - addr_start);
1546 b->cond_string = savestring (cond_start, cond_end - cond_start);
1548 b->enable = enabled;
1549 b->disposition = tempflag ? delete : donttouch;
1556 printf ("Multiple breakpoints were set.\n");
1557 printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1562 /* Helper function for break_command_1 and disassemble_command. */
1565 resolve_sal_pc (sal)
1566 struct symtab_and_line *sal;
1570 if (sal->pc == 0 && sal->symtab != 0)
1572 pc = find_line_pc (sal->symtab, sal->line);
1574 error ("No line %d in file \"%s\".",
1575 sal->line, sal->symtab->filename);
1581 break_command (arg, from_tty)
1585 break_command_1 (arg, 0, from_tty);
1589 tbreak_command (arg, from_tty)
1593 break_command_1 (arg, 1, from_tty);
1598 watch_command (arg, from_tty)
1602 struct breakpoint *b;
1603 struct symtab_and_line sal;
1604 struct expression *exp;
1605 struct block *exp_valid_block;
1612 /* Parse arguments. */
1613 innermost_block = NULL;
1614 exp = parse_expression (arg);
1615 exp_valid_block = innermost_block;
1616 val = evaluate_expression (exp);
1617 release_value (val);
1619 /* Now set up the breakpoint. */
1620 b = set_raw_breakpoint (sal);
1621 set_breakpoint_count (breakpoint_count + 1);
1622 b->number = breakpoint_count;
1623 b->type = bp_watchpoint;
1624 b->disposition = donttouch;
1626 b->exp_valid_block = exp_valid_block;
1629 b->cond_string = NULL;
1634 * Helper routine for the until_command routine in infcmd.c. Here
1635 * because it uses the mechanisms of breakpoints.
1639 until_break_command (arg, from_tty)
1643 struct symtabs_and_lines sals;
1644 struct symtab_and_line sal;
1645 FRAME prev_frame = get_prev_frame (selected_frame);
1646 struct breakpoint *breakpoint;
1647 struct cleanup *old_chain;
1649 clear_proceed_status ();
1651 /* Set a breakpoint where the user wants it and at return from
1654 if (default_breakpoint_valid)
1655 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1656 default_breakpoint_line);
1658 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1660 if (sals.nelts != 1)
1661 error ("Couldn't get information on specified line.");
1664 free (sals.sals); /* malloc'd, so freed */
1667 error ("Junk at end of arguments.");
1669 resolve_sal_pc (&sal);
1671 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
1673 old_chain = make_cleanup(delete_breakpoint, breakpoint);
1675 /* Keep within the current frame */
1679 struct frame_info *fi;
1681 fi = get_frame_info (prev_frame);
1682 sal = find_pc_line (fi->pc, 0);
1684 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
1685 make_cleanup(delete_breakpoint, breakpoint);
1688 proceed (-1, -1, 0);
1689 do_cleanups(old_chain);
1693 /* These aren't used; I don't konw what they were for. */
1694 /* Set a breakpoint at the catch clause for NAME. */
1696 catch_breakpoint (name)
1702 disable_catch_breakpoint ()
1707 delete_catch_breakpoint ()
1712 enable_catch_breakpoint ()
1719 struct sal_chain *next;
1720 struct symtab_and_line sal;
1724 /* This isn't used; I don't know what it was for. */
1725 /* For each catch clause identified in ARGS, run FUNCTION
1726 with that clause as an argument. */
1727 static struct symtabs_and_lines
1728 map_catch_names (args, function)
1732 register char *p = args;
1734 struct symtabs_and_lines sals;
1736 struct sal_chain *sal_chain = 0;
1740 error_no_arg ("one or more catch names");
1748 /* Don't swallow conditional part. */
1749 if (p1[0] == 'i' && p1[1] == 'f'
1750 && (p1[2] == ' ' || p1[2] == '\t'))
1756 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
1760 if (*p1 && *p1 != ' ' && *p1 != '\t')
1761 error ("Arguments must be catch names.");
1767 struct sal_chain *next
1768 = (struct sal_chain *)alloca (sizeof (struct sal_chain));
1769 next->next = sal_chain;
1770 next->sal = get_catch_sal (p);
1775 printf ("No catch clause for exception %s.\n", p);
1780 while (*p == ' ' || *p == '\t') p++;
1785 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
1787 static struct symtabs_and_lines
1788 get_catch_sals (this_level_only)
1789 int this_level_only;
1791 register struct blockvector *bl;
1792 register struct block *block;
1793 int index, have_default = 0;
1794 struct frame_info *fi;
1796 struct symtabs_and_lines sals;
1797 struct sal_chain *sal_chain = 0;
1798 char *blocks_searched;
1800 /* Not sure whether an error message is always the correct response,
1801 but it's better than a core dump. */
1802 if (selected_frame == NULL)
1803 error ("No selected frame.");
1804 block = get_frame_block (selected_frame);
1805 fi = get_frame_info (selected_frame);
1812 error ("No symbol table info available.\n");
1814 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
1815 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1816 bzero (blocks_searched, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1820 CORE_ADDR end = BLOCK_END (block) - 4;
1823 if (bl != blockvector_for_pc (end, &index))
1824 error ("blockvector blotch");
1825 if (BLOCKVECTOR_BLOCK (bl, index) != block)
1826 error ("blockvector botch");
1827 last_index = BLOCKVECTOR_NBLOCKS (bl);
1830 /* Don't print out blocks that have gone by. */
1831 while (index < last_index
1832 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
1835 while (index < last_index
1836 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
1838 if (blocks_searched[index] == 0)
1840 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
1843 register struct symbol *sym;
1845 nsyms = BLOCK_NSYMS (b);
1847 for (i = 0; i < nsyms; i++)
1849 sym = BLOCK_SYM (b, i);
1850 if (! strcmp (SYMBOL_NAME (sym), "default"))
1856 if (SYMBOL_CLASS (sym) == LOC_LABEL)
1858 struct sal_chain *next = (struct sal_chain *)
1859 alloca (sizeof (struct sal_chain));
1860 next->next = sal_chain;
1861 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
1865 blocks_searched[index] = 1;
1871 if (sal_chain && this_level_only)
1874 /* After handling the function's top-level block, stop.
1875 Don't continue to its superblock, the block of
1876 per-file symbols. */
1877 if (BLOCK_FUNCTION (block))
1879 block = BLOCK_SUPERBLOCK (block);
1884 struct sal_chain *tmp_chain;
1886 /* Count the number of entries. */
1887 for (index = 0, tmp_chain = sal_chain; tmp_chain;
1888 tmp_chain = tmp_chain->next)
1892 sals.sals = (struct symtab_and_line *)
1893 xmalloc (index * sizeof (struct symtab_and_line));
1894 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
1895 sals.sals[index] = sal_chain->sal;
1901 /* Commands to deal with catching exceptions. */
1904 catch_command_1 (arg, tempflag, from_tty)
1909 /* First, translate ARG into something we can deal with in terms
1912 struct symtabs_and_lines sals;
1913 struct symtab_and_line sal;
1914 register struct expression *cond = 0;
1915 register struct breakpoint *b;
1919 sal.line = sal.pc = sal.end = 0;
1922 /* If no arg given, or if first arg is 'if ', all active catch clauses
1923 are breakpointed. */
1925 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1926 && (arg[2] == ' ' || arg[2] == '\t')))
1928 /* Grab all active catch clauses. */
1929 sals = get_catch_sals (0);
1933 /* Grab selected catch clauses. */
1934 error ("catch NAME not implemeneted");
1936 /* This isn't used; I don't know what it was for. */
1937 sals = map_catch_names (arg, catch_breakpoint);
1945 for (i = 0; i < sals.nelts; i++)
1947 resolve_sal_pc (&sals.sals[i]);
1951 if (arg[0] == 'i' && arg[1] == 'f'
1952 && (arg[2] == ' ' || arg[2] == '\t'))
1953 cond = parse_exp_1 ((arg += 2, &arg),
1954 block_for_pc (sals.sals[i].pc), 0);
1956 error ("Junk at end of arguments.");
1961 for (i = 0; i < sals.nelts; i++)
1966 describe_other_breakpoints (sal.pc);
1968 b = set_raw_breakpoint (sal);
1969 set_breakpoint_count (breakpoint_count + 1);
1970 b->number = breakpoint_count;
1971 b->type = bp_breakpoint;
1973 b->enable = enabled;
1974 b->disposition = tempflag ? delete : donttouch;
1976 printf ("Breakpoint %d at %s", b->number, local_hex_string(b->address));
1978 printf (": file %s, line %d.", b->symtab->filename, b->line_number);
1984 printf ("Multiple breakpoints were set.\n");
1985 printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1991 /* These aren't used; I don't know what they were for. */
1992 /* Disable breakpoints on all catch clauses described in ARGS. */
1994 disable_catch (args)
1997 /* Map the disable command to catch clauses described in ARGS. */
2000 /* Enable breakpoints on all catch clauses described in ARGS. */
2005 /* Map the disable command to catch clauses described in ARGS. */
2008 /* Delete breakpoints on all catch clauses in the active scope. */
2013 /* Map the delete command to catch clauses described in ARGS. */
2018 catch_command (arg, from_tty)
2022 catch_command_1 (arg, 0, from_tty);
2026 clear_command (arg, from_tty)
2030 register struct breakpoint *b, *b1;
2031 struct symtabs_and_lines sals;
2032 struct symtab_and_line sal;
2033 register struct breakpoint *found;
2038 sals = decode_line_spec (arg, 1);
2042 sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
2043 sal.line = default_breakpoint_line;
2044 sal.symtab = default_breakpoint_symtab;
2046 if (sal.symtab == 0)
2047 error ("No source file specified.");
2053 for (i = 0; i < sals.nelts; i++)
2055 /* If exact pc given, clear bpts at that pc.
2056 But if sal.pc is zero, clear all bpts on specified line. */
2058 found = (struct breakpoint *) 0;
2059 while (breakpoint_chain
2060 && (sal.pc ? breakpoint_chain->address == sal.pc
2061 : (breakpoint_chain->symtab == sal.symtab
2062 && breakpoint_chain->line_number == sal.line)))
2064 b1 = breakpoint_chain;
2065 breakpoint_chain = b1->next;
2072 && b->next->type != bp_watchpoint
2073 && (sal.pc ? b->next->address == sal.pc
2074 : (b->next->symtab == sal.symtab
2075 && b->next->line_number == sal.line)))
2086 error ("No breakpoint at %s.", arg);
2088 error ("No breakpoint at this line.");
2091 if (found->next) from_tty = 1; /* Always report if deleted more than one */
2092 if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : "");
2095 if (from_tty) printf ("%d ", found->number);
2097 delete_breakpoint (found);
2100 if (from_tty) putchar ('\n');
2105 /* Delete breakpoint in BS if they are `delete' breakpoints.
2106 This is called after any breakpoint is hit, or after errors. */
2109 breakpoint_auto_delete (bs)
2112 for (; bs; bs = bs->next)
2113 if (bs->breakpoint_at && bs->breakpoint_at->disposition == delete)
2114 delete_breakpoint (bs->breakpoint_at);
2117 /* Delete a breakpoint and clean up all traces of it in the data structures. */
2120 delete_breakpoint (bpt)
2121 struct breakpoint *bpt;
2123 register struct breakpoint *b;
2127 target_remove_breakpoint(bpt->address, bpt->shadow_contents);
2129 if (breakpoint_chain == bpt)
2130 breakpoint_chain = bpt->next;
2135 b->next = bpt->next;
2139 check_duplicates (bpt->address);
2141 free_command_lines (&bpt->commands);
2144 if (bpt->cond_string != NULL)
2145 free (bpt->cond_string);
2146 if (bpt->addr_string != NULL)
2147 free (bpt->addr_string);
2149 if (xgdb_verbose && bpt->type == bp_breakpoint)
2150 printf ("breakpoint #%d deleted\n", bpt->number);
2152 /* Be sure no bpstat's are pointing at it after it's been freed. */
2153 /* FIXME, how can we find all bpstat's? We just check stop_bpstat for now. */
2154 for (bs = stop_bpstat; bs; bs = bs->next)
2155 if (bs->breakpoint_at == bpt)
2156 bs->breakpoint_at = NULL;
2161 delete_command (arg, from_tty)
2168 /* Ask user only if there are some breakpoints to delete. */
2170 || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0)))
2172 /* No arg; clear all breakpoints. */
2173 while (breakpoint_chain)
2174 delete_breakpoint (breakpoint_chain);
2178 map_breakpoint_numbers (arg, delete_breakpoint);
2181 /* Reset a breakpoint given it's struct breakpoint * BINT.
2182 The value we return ends up being the return value from catch_errors.
2183 Unused in this case. */
2186 breakpoint_re_set_one (bint)
2189 struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */
2191 struct symtabs_and_lines sals;
2193 enum enable save_enable;
2198 if (b->addr_string == NULL)
2200 /* Anything without a string can't be re-set. */
2201 delete_breakpoint (b);
2204 /* In case we have a problem, disable this breakpoint. We'll restore
2205 its status if we succeed. */
2206 save_enable = b->enable;
2207 b->enable = disabled;
2210 sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0);
2211 for (i = 0; i < sals.nelts; i++)
2213 resolve_sal_pc (&sals.sals[i]);
2214 if (b->symtab != sals.sals[i].symtab
2215 || b->line_number != sals.sals[i].line
2216 || b->address != sals.sals[i].pc)
2218 b->symtab = sals.sals[i].symtab;
2219 b->line_number = sals.sals[i].line;
2220 b->address = sals.sals[i].pc;
2222 if (b->cond_string != NULL)
2225 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
2228 check_duplicates (b->address);
2232 b->enable = save_enable; /* Restore it, this worked. */
2237 /* FIXME! This is the wrong thing to do.... */
2238 delete_breakpoint (b);
2241 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
2245 case bp_longjmp_resume:
2246 delete_breakpoint (b);
2253 /* Re-set all breakpoints after symbols have been re-loaded. */
2255 breakpoint_re_set ()
2257 struct breakpoint *b, *temp;
2258 static char message1[] = "Error in re-setting breakpoint %d:\n";
2259 char message[sizeof (message1) + 30 /* slop */];
2261 ALL_BREAKPOINTS_SAFE (b, temp)
2263 sprintf (message, message1, b->number); /* Format possible error msg */
2264 (void) catch_errors (breakpoint_re_set_one, (char *) b, message);
2267 create_longjmp_breakpoint("longjmp");
2268 create_longjmp_breakpoint("_longjmp");
2269 create_longjmp_breakpoint("siglongjmp");
2270 create_longjmp_breakpoint(NULL);
2273 /* Took this out (temporaliy at least), since it produces an extra
2274 blank line at startup. This messes up the gdbtests. -PB */
2275 /* Blank line to finish off all those mention() messages we just printed. */
2276 printf_filtered ("\n");
2280 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
2281 If from_tty is nonzero, it prints a message to that effect,
2282 which ends with a period (no newline). */
2285 set_ignore_count (bptnum, count, from_tty)
2286 int bptnum, count, from_tty;
2288 register struct breakpoint *b;
2294 if (b->number == bptnum)
2296 b->ignore_count = count;
2299 else if (count == 0)
2300 printf ("Will stop next time breakpoint %d is reached.", bptnum);
2301 else if (count == 1)
2302 printf ("Will ignore next crossing of breakpoint %d.", bptnum);
2304 printf ("Will ignore next %d crossings of breakpoint %d.",
2309 error ("No breakpoint number %d.", bptnum);
2312 /* Clear the ignore counts of all breakpoints. */
2314 breakpoint_clear_ignore_counts ()
2316 struct breakpoint *b;
2319 b->ignore_count = 0;
2322 /* Command to set ignore-count of breakpoint N to COUNT. */
2325 ignore_command (args, from_tty)
2333 error_no_arg ("a breakpoint number");
2335 num = get_number (&p);
2338 error ("Second argument (specified ignore-count) is missing.");
2340 set_ignore_count (num,
2341 longest_to_int (value_as_long (parse_and_eval (p))),
2346 /* Call FUNCTION on each of the breakpoints
2347 whose numbers are given in ARGS. */
2350 map_breakpoint_numbers (args, function)
2352 void (*function) PARAMS ((struct breakpoint *));
2354 register char *p = args;
2357 register struct breakpoint *b;
2360 error_no_arg ("one or more breakpoint numbers");
2366 num = get_number (&p1);
2369 if (b->number == num)
2374 printf ("No breakpoint number %d.\n", num);
2381 enable_breakpoint (bpt)
2382 struct breakpoint *bpt;
2384 bpt->enable = enabled;
2386 if (xgdb_verbose && bpt->type == bp_breakpoint)
2387 printf ("breakpoint #%d enabled\n", bpt->number);
2389 check_duplicates (bpt->address);
2390 if (bpt->type == bp_watchpoint)
2392 if (bpt->exp_valid_block != NULL
2393 && !contained_in (get_selected_block (), bpt->exp_valid_block))
2396 Cannot enable watchpoint %d because the block in which its expression\n\
2397 is valid is not currently in scope.\n", bpt->number);
2401 value_free (bpt->val);
2403 bpt->val = evaluate_expression (bpt->exp);
2404 release_value (bpt->val);
2410 enable_command (args, from_tty)
2414 struct breakpoint *bpt;
2416 ALL_BREAKPOINTS (bpt)
2417 enable_breakpoint (bpt);
2419 map_breakpoint_numbers (args, enable_breakpoint);
2423 disable_breakpoint (bpt)
2424 struct breakpoint *bpt;
2426 bpt->enable = disabled;
2428 if (xgdb_verbose && bpt->type == bp_breakpoint)
2429 printf ("breakpoint #%d disabled\n", bpt->number);
2431 check_duplicates (bpt->address);
2436 disable_command (args, from_tty)
2440 register struct breakpoint *bpt;
2442 ALL_BREAKPOINTS (bpt)
2443 disable_breakpoint (bpt);
2445 map_breakpoint_numbers (args, disable_breakpoint);
2449 enable_once_breakpoint (bpt)
2450 struct breakpoint *bpt;
2452 bpt->enable = enabled;
2453 bpt->disposition = disable;
2455 check_duplicates (bpt->address);
2460 enable_once_command (args, from_tty)
2464 map_breakpoint_numbers (args, enable_once_breakpoint);
2468 enable_delete_breakpoint (bpt)
2469 struct breakpoint *bpt;
2471 bpt->enable = enabled;
2472 bpt->disposition = delete;
2474 check_duplicates (bpt->address);
2479 enable_delete_command (args, from_tty)
2483 map_breakpoint_numbers (args, enable_delete_breakpoint);
2487 * Use default_breakpoint_'s, or nothing if they aren't valid.
2489 struct symtabs_and_lines
2490 decode_line_spec_1 (string, funfirstline)
2494 struct symtabs_and_lines sals;
2496 error ("Empty line specification.");
2497 if (default_breakpoint_valid)
2498 sals = decode_line_1 (&string, funfirstline,
2499 default_breakpoint_symtab, default_breakpoint_line);
2501 sals = decode_line_1 (&string, funfirstline, (struct symtab *)NULL, 0);
2503 error ("Junk at end of line specification: %s", string);
2508 /* Chain containing all defined enable commands. */
2510 extern struct cmd_list_element
2511 *enablelist, *disablelist,
2512 *deletelist, *enablebreaklist;
2514 extern struct cmd_list_element *cmdlist;
2517 _initialize_breakpoint ()
2519 breakpoint_chain = 0;
2520 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
2521 before a breakpoint is set. */
2522 breakpoint_count = 0;
2524 add_com ("ignore", class_breakpoint, ignore_command,
2525 "Set ignore-count of breakpoint number N to COUNT.");
2527 add_com ("commands", class_breakpoint, commands_command,
2528 "Set commands to be executed when a breakpoint is hit.\n\
2529 Give breakpoint number as argument after \"commands\".\n\
2530 With no argument, the targeted breakpoint is the last one set.\n\
2531 The commands themselves follow starting on the next line.\n\
2532 Type a line containing \"end\" to indicate the end of them.\n\
2533 Give \"silent\" as the first line to make the breakpoint silent;\n\
2534 then no output is printed when it is hit, except what the commands print.");
2536 add_com ("condition", class_breakpoint, condition_command,
2537 "Specify breakpoint number N to break only if COND is true.\n\
2538 N is an integer; COND is an expression to be evaluated whenever\n\
2539 breakpoint N is reached. ");
2541 add_com ("tbreak", class_breakpoint, tbreak_command,
2542 "Set a temporary breakpoint. Args like \"break\" command.\n\
2543 Like \"break\" except the breakpoint is only enabled temporarily,\n\
2544 so it will be disabled when hit. Equivalent to \"break\" followed\n\
2545 by using \"enable once\" on the breakpoint number.");
2547 add_prefix_cmd ("enable", class_breakpoint, enable_command,
2548 "Enable some breakpoints.\n\
2549 Give breakpoint numbers (separated by spaces) as arguments.\n\
2550 With no subcommand, breakpoints are enabled until you command otherwise.\n\
2551 This is used to cancel the effect of the \"disable\" command.\n\
2552 With a subcommand you can enable temporarily.",
2553 &enablelist, "enable ", 1, &cmdlist);
2555 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
2556 "Enable some breakpoints.\n\
2557 Give breakpoint numbers (separated by spaces) as arguments.\n\
2558 This is used to cancel the effect of the \"disable\" command.\n\
2559 May be abbreviated to simply \"enable\".\n",
2560 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
2562 add_cmd ("once", no_class, enable_once_command,
2563 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
2564 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2565 See the \"tbreak\" command which sets a breakpoint and enables it once.",
2568 add_cmd ("delete", no_class, enable_delete_command,
2569 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
2570 If a breakpoint is hit while enabled in this fashion, it is deleted.",
2573 add_cmd ("delete", no_class, enable_delete_command,
2574 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
2575 If a breakpoint is hit while enabled in this fashion, it is deleted.",
2578 add_cmd ("once", no_class, enable_once_command,
2579 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
2580 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2581 See the \"tbreak\" command which sets a breakpoint and enables it once.",
2584 add_prefix_cmd ("disable", class_breakpoint, disable_command,
2585 "Disable some breakpoints.\n\
2586 Arguments are breakpoint numbers with spaces in between.\n\
2587 To disable all breakpoints, give no argument.\n\
2588 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
2589 &disablelist, "disable ", 1, &cmdlist);
2590 add_com_alias ("dis", "disable", class_breakpoint, 1);
2591 add_com_alias ("disa", "disable", class_breakpoint, 1);
2593 add_cmd ("breakpoints", class_alias, disable_command,
2594 "Disable some breakpoints.\n\
2595 Arguments are breakpoint numbers with spaces in between.\n\
2596 To disable all breakpoints, give no argument.\n\
2597 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
2598 This command may be abbreviated \"disable\".",
2601 add_prefix_cmd ("delete", class_breakpoint, delete_command,
2602 "Delete some breakpoints or auto-display expressions.\n\
2603 Arguments are breakpoint numbers with spaces in between.\n\
2604 To delete all breakpoints, give no argument.\n\
2606 Also a prefix command for deletion of other GDB objects.\n\
2607 The \"unset\" command is also an alias for \"delete\".",
2608 &deletelist, "delete ", 1, &cmdlist);
2609 add_com_alias ("d", "delete", class_breakpoint, 1);
2611 add_cmd ("breakpoints", class_alias, delete_command,
2612 "Delete some breakpoints or auto-display expressions.\n\
2613 Arguments are breakpoint numbers with spaces in between.\n\
2614 To delete all breakpoints, give no argument.\n\
2615 This command may be abbreviated \"delete\".",
2618 add_com ("clear", class_breakpoint, clear_command,
2619 "Clear breakpoint at specified line or function.\n\
2620 Argument may be line number, function name, or \"*\" and an address.\n\
2621 If line number is specified, all breakpoints in that line are cleared.\n\
2622 If function is specified, breakpoints at beginning of function are cleared.\n\
2623 If an address is specified, breakpoints at that address are cleared.\n\n\
2624 With no argument, clears all breakpoints in the line that the selected frame\n\
2627 See also the \"delete\" command which clears breakpoints by number.");
2629 add_com ("break", class_breakpoint, break_command,
2630 "Set breakpoint at specified line or function.\n\
2631 Argument may be line number, function name, or \"*\" and an address.\n\
2632 If line number is specified, break at start of code for that line.\n\
2633 If function is specified, break at start of code for that function.\n\
2634 If an address is specified, break at that exact address.\n\
2635 With no arg, uses current execution address of selected stack frame.\n\
2636 This is useful for breaking on return to a stack frame.\n\
2638 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
2640 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2641 add_com_alias ("b", "break", class_run, 1);
2642 add_com_alias ("br", "break", class_run, 1);
2643 add_com_alias ("bre", "break", class_run, 1);
2644 add_com_alias ("brea", "break", class_run, 1);
2646 add_info ("breakpoints", breakpoints_info,
2647 "Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
2648 The \"Type\" column indicates one of:\n\
2649 \tbreakpoint - for normal breakpoints\n\
2650 \twatchpoint - for watchpoints\n\
2651 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
2652 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
2653 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
2654 address and file/line number respectively.\n\n\
2655 Convenience variable \"$_\" and default examine address for \"x\"\n\
2656 are set to the address of the last breakpoint listed.\n\n\
2657 Convenience variable \"$bpnum\" contains the number of the last\n\
2660 add_info ("all-breakpoints", all_breakpoints_info,
2661 "Status of all breakpoints, or breakpoint number NUMBER.\n\
2662 The \"Type\" column indicates one of:\n\
2663 \tbreakpoint - for normal breakpoints\n\
2664 \twatchpoint - for watchpoints\n\
2665 \tlongjmp - for internal breakpoints to handle stepping through longjmp()\n\
2666 \tlongjmp resume - for internal breakpoints at the target of longjmp()\n\
2667 \tuntil - for internal breakpoints used by the \"until\" command\n\
2668 \tfinish - for internal breakpoints used by the \"finish\" command\n\
2669 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
2670 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
2671 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
2672 address and file/line number respectively.\n\n\
2673 Convenience variable \"$_\" and default examine address for \"x\"\n\
2674 are set to the address of the last breakpoint listed.\n\n\
2675 Convenience variable \"$bpnum\" contains the number of the last\n\
2678 add_com ("catch", class_breakpoint, catch_command,
2679 "Set breakpoints to catch exceptions that are raised.\n\
2680 Argument may be a single exception to catch, multiple exceptions\n\
2681 to catch, or the default exception \"default\". If no arguments\n\
2682 are given, breakpoints are set at all exception handlers catch clauses\n\
2683 within the current scope.\n\
2685 A condition specified for the catch applies to all breakpoints set\n\
2686 with this command\n\
2688 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2690 add_com ("watch", class_breakpoint, watch_command,
2691 "Set a watchpoint for an expression.\n\
2692 A watchpoint stops execution of your program whenever the value of\n\
2693 an expression changes.");
2695 add_info ("watchpoints", watchpoints_info,
2696 "Status of all watchpoints, or watchpoint number NUMBER.\n\
2697 Second column is \"y\" for enabled watchpoints, \"n\" for disabled.");
2701 /* Where should this function go? It is used by AIX only. FIXME. */
2703 /* Breakpoint address relocation used to be done in breakpoint_re_set(). That
2704 approach the following problem:
2706 before running the program, if a file is list, then a breakpoint is
2707 set (just the line number), then if we switch into another file and run
2708 the program, just a line number as a breakpoint address was not
2709 descriptive enough and breakpoint was ending up in a different file's
2712 I don't think any other platform has this breakpoint relocation problem, so this
2713 is not an issue for other platforms. */
2716 fixup_breakpoints (low, high, delta)
2721 struct breakpoint *b;
2722 extern struct breakpoint *breakpoint_chain;
2726 if (b->address >= low && b->address <= high)
2727 b->address += delta;