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 breakpoints_info PARAMS ((char *, int));
112 breakpoint_1 PARAMS ((int, enum bptype, int));
115 bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
118 breakpoint_cond_eval PARAMS ((char *));
121 cleanup_executing_breakpoints PARAMS ((int));
124 commands_command PARAMS ((char *, int));
127 condition_command PARAMS ((char *, int));
130 get_number PARAMS ((char **));
133 set_breakpoint_count PARAMS ((int));
136 extern int addressprint; /* Print machine addresses? */
137 extern int demangle; /* Print de-mangled symbol names? */
139 /* Are we executing breakpoint commands? */
140 static int executing_breakpoint_commands;
142 /* Walk the following statement or block through all breakpoints.
143 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
146 #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
148 #define ALL_BREAKPOINTS_SAFE(b,tmp) \
149 for (b = breakpoint_chain; \
150 b? (tmp=b->next, 1): 0; \
153 /* Chain of all breakpoints defined. */
155 struct breakpoint *breakpoint_chain;
157 /* Number of last breakpoint made. */
159 static int breakpoint_count;
161 /* Set breakpoint count to NUM. */
163 set_breakpoint_count (num)
166 breakpoint_count = num;
167 set_internalvar (lookup_internalvar ("bpnum"),
168 value_from_longest (builtin_type_int, (LONGEST) num));
171 /* Default address, symtab and line to put a breakpoint at
172 for "break" command with no arg.
173 if default_breakpoint_valid is zero, the other three are
174 not valid, and "break" with no arg is an error.
176 This set by print_stack_frame, which calls set_default_breakpoint. */
178 int default_breakpoint_valid;
179 CORE_ADDR default_breakpoint_address;
180 struct symtab *default_breakpoint_symtab;
181 int default_breakpoint_line;
183 /* Flag indicating extra verbosity for xgdb. */
184 extern int xgdb_verbose;
186 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
187 Advance *PP after the string and any trailing whitespace.
189 Currently the string can either be a number or "$" followed by the name
190 of a convenience variable. Making it an expression wouldn't work well
191 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
200 /* Empty line means refer to the last breakpoint. */
201 return breakpoint_count;
204 /* Make a copy of the name, so we can null-terminate it
205 to pass to lookup_internalvar(). */
210 while (isalnum (*p) || *p == '_')
212 varname = (char *) alloca (p - start + 1);
213 strncpy (varname, start, p - start);
214 varname[p - start] = '\0';
215 val = value_of_internalvar (lookup_internalvar (varname));
216 if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
218 "Convenience variables used to specify breakpoints must have integer values."
220 retval = (int) value_as_long (val);
226 while (*p >= '0' && *p <= '9')
229 /* There is no number here. (e.g. "cond a == b"). */
230 error_no_arg ("breakpoint number");
233 if (!(isspace (*p) || *p == '\0'))
234 error ("breakpoint number expected");
241 /* condition N EXP -- set break condition of breakpoint N to EXP. */
244 condition_command (arg, from_tty)
248 register struct breakpoint *b;
253 error_no_arg ("breakpoint number");
256 bnum = get_number (&p);
259 if (b->number == bnum)
266 if (b->cond_string != NULL)
267 free ((PTR)b->cond_string);
272 b->cond_string = NULL;
274 printf ("Breakpoint %d now unconditional.\n", bnum);
279 /* I don't know if it matters whether this is the string the user
280 typed in or the decompiled expression. */
281 b->cond_string = savestring (arg, strlen (arg));
282 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
284 error ("Junk at end of expression");
289 error ("No breakpoint number %d.", bnum);
294 commands_command (arg, from_tty)
298 register struct breakpoint *b;
301 struct command_line *l;
303 /* If we allowed this, we would have problems with when to
304 free the storage, if we change the commands currently
307 if (executing_breakpoint_commands)
308 error ("Can't use the \"commands\" command among a breakpoint's commands.");
311 bnum = get_number (&p);
313 error ("Unexpected extra arguments following breakpoint number.");
316 if (b->number == bnum)
318 if (from_tty && input_from_terminal_p ())
320 printf ("Type commands for when breakpoint %d is hit, one per line.\n\
321 End with a line saying just \"end\".\n", bnum);
324 l = read_command_lines ();
325 free_command_lines (&b->commands);
329 error ("No breakpoint number %d.", bnum);
332 extern int memory_breakpoint_size; /* from mem-break.c */
334 /* Like target_read_memory() but if breakpoints are inserted, return
335 the shadow contents instead of the breakpoints themselves.
337 Read "memory data" from whatever target or inferior we have.
338 Returns zero if successful, errno value if not. EIO is used
339 for address out of bounds. If breakpoints are inserted, returns
340 shadow contents, not the breakpoints themselves. From breakpoint.c. */
343 read_memory_nobpt (memaddr, myaddr, len)
349 struct breakpoint *b;
351 if (memory_breakpoint_size < 0)
352 /* No breakpoints on this machine. */
353 return target_read_memory (memaddr, myaddr, len);
357 if (b->type == bp_watchpoint || !b->inserted)
359 else if (b->address + memory_breakpoint_size <= memaddr)
360 /* The breakpoint is entirely before the chunk of memory
363 else if (b->address >= memaddr + len)
364 /* The breakpoint is entirely after the chunk of memory we
369 /* Copy the breakpoint from the shadow contents, and recurse
370 for the things before and after. */
372 /* Addresses and length of the part of the breakpoint that
374 CORE_ADDR membpt = b->address;
375 unsigned int bptlen = memory_breakpoint_size;
376 /* Offset within shadow_contents. */
379 if (membpt < memaddr)
381 /* Only copy the second part of the breakpoint. */
382 bptlen -= memaddr - membpt;
383 bptoffset = memaddr - membpt;
387 if (membpt + bptlen > memaddr + len)
389 /* Only copy the first part of the breakpoint. */
390 bptlen -= (membpt + bptlen) - (memaddr + len);
393 bcopy (b->shadow_contents + bptoffset,
394 myaddr + membpt - memaddr, bptlen);
396 if (membpt > memaddr)
398 /* Copy the section of memory before the breakpoint. */
399 status = read_memory_nobpt (memaddr, myaddr, membpt - memaddr);
404 if (membpt + bptlen < memaddr + len)
406 /* Copy the section of memory after the breakpoint. */
407 status = read_memory_nobpt
409 myaddr + membpt + bptlen - memaddr,
410 memaddr + len - (membpt + bptlen));
417 /* Nothing overlaps. Just call read_memory_noerr. */
418 return target_read_memory (memaddr, myaddr, len);
421 /* insert_breakpoints is used when starting or continuing the program.
422 remove_breakpoints is used when the program stops.
423 Both return zero if successful,
424 or an `errno' value if could not write the inferior. */
427 insert_breakpoints ()
429 register struct breakpoint *b;
431 int disabled_breaks = 0;
434 if (b->type != bp_watchpoint
435 && b->enable != disabled
439 val = target_insert_breakpoint(b->address, b->shadow_contents);
442 /* Can't set the breakpoint. */
443 #if defined (DISABLE_UNSETTABLE_BREAK)
444 if (DISABLE_UNSETTABLE_BREAK (b->address))
447 b->enable = disabled;
448 if (!disabled_breaks)
451 "Cannot insert breakpoint %d:\n", b->number);
452 printf_filtered ("Disabling shared library breakpoints:\n");
455 printf_filtered ("%d ", b->number);
460 fprintf (stderr, "Cannot insert breakpoint %d:\n", b->number);
461 #ifdef ONE_PROCESS_WRITETEXT
463 "The same program may be running in another process.\n");
465 memory_error (val, b->address); /* which bombs us out */
472 printf_filtered ("\n");
477 remove_breakpoints ()
479 register struct breakpoint *b;
482 #ifdef BREAKPOINT_DEBUG
483 printf ("Removing breakpoints.\n");
484 #endif /* BREAKPOINT_DEBUG */
487 if (b->type != bp_watchpoint && b->inserted)
489 val = target_remove_breakpoint(b->address, b->shadow_contents);
493 #ifdef BREAKPOINT_DEBUG
494 printf ("Removed breakpoint at %s",
495 local_hex_string(b->address));
496 printf (", shadow %s",
497 local_hex_string(b->shadow_contents[0]));
499 local_hex_string(b->shadow_contents[1]));
500 #endif /* BREAKPOINT_DEBUG */
506 /* Clear the "inserted" flag in all breakpoints.
507 This is done when the inferior is loaded. */
510 mark_breakpoints_out ()
512 register struct breakpoint *b;
518 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
519 When continuing from a location with a breakpoint,
520 we actually single step once before calling insert_breakpoints. */
523 breakpoint_here_p (pc)
526 register struct breakpoint *b;
529 if (b->enable != disabled && b->address == pc)
535 /* bpstat stuff. External routines' interfaces are documented
538 /* Clear a bpstat so that it says we are not at any breakpoint.
539 Also free any storage that is part of a bpstat. */
554 if (p->old_val != NULL)
555 value_free (p->old_val);
562 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
563 is part of the bpstat is copied as well. */
576 for (; bs != NULL; bs = bs->next)
578 tmp = (bpstat) xmalloc (sizeof (*tmp));
579 bcopy (bs, tmp, sizeof (*tmp));
581 /* This is the first thing in the chain. */
591 /* Find the bpstat associated with this breakpoint */
594 bpstat_find_breakpoint(bsp, breakpoint)
596 struct breakpoint *breakpoint;
598 if (bsp == NULL) return NULL;
600 for (;bsp != NULL; bsp = bsp->next) {
601 if (bsp->breakpoint_at == breakpoint) return bsp;
606 /* Return the breakpoint number of the first breakpoint we are stopped
607 at. *BSP upon return is a bpstat which points to the remaining
608 breakpoints stopped at (but which is not guaranteed to be good for
609 anything but further calls to bpstat_num).
610 Return 0 if passed a bpstat which does not indicate any breakpoints. */
616 struct breakpoint *b;
619 return 0; /* No more breakpoint values */
622 b = (*bsp)->breakpoint_at;
625 return -1; /* breakpoint that's been deleted since */
627 return b->number; /* We have its number */
631 /* Modify BS so that the actions will not be performed. */
634 bpstat_clear_actions (bs)
637 for (; bs != NULL; bs = bs->next)
640 if (bs->old_val != NULL)
642 value_free (bs->old_val);
648 /* Stub for cleaning up our state if we error-out of a breakpoint command */
651 cleanup_executing_breakpoints (ignore)
654 executing_breakpoint_commands = 0;
657 /* Execute all the commands associated with all the breakpoints at this
658 location. Any of these commands could cause the process to proceed
659 beyond this point, etc. We look out for such changes by checking
660 the global "breakpoint_proceeded" after each command. */
663 bpstat_do_actions (bsp)
667 struct cleanup *old_chain;
669 executing_breakpoint_commands = 1;
670 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
675 breakpoint_proceeded = 0;
676 for (; bs != NULL; bs = bs->next)
680 char *line = bs->commands->line;
681 bs->commands = bs->commands->next;
682 execute_command (line, 0);
683 /* If the inferior is proceeded by the command, bomb out now.
684 The bpstat chain has been blown away by wait_for_inferior.
685 But since execution has stopped again, there is a new bpstat
686 to look at, so start over. */
687 if (breakpoint_proceeded)
692 executing_breakpoint_commands = 0;
693 discard_cleanups (old_chain);
696 /* Print a message indicating what happened. Returns nonzero to
697 say that only the source line should be printed after this (zero
698 return means print the frame as well as the source line). */
704 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
705 which has since been deleted. */
707 || bs->breakpoint_at == NULL
708 || (bs->breakpoint_at->type != bp_breakpoint
709 && bs->breakpoint_at->type != bp_watchpoint))
712 /* If bpstat_stop_status says don't print, OK, we won't. An example
713 circumstance is when we single-stepped for both a watchpoint and
714 for a "stepi" instruction. The bpstat says that the watchpoint
715 explains the stop, but we shouldn't print because the watchpoint's
716 value didn't change -- and the real reason we are stopping here
717 rather than continuing to step (as the watchpoint would've had us do)
718 is because of the "stepi". */
722 if (bs->breakpoint_at->type == bp_breakpoint)
724 /* I think the user probably only wants to see one breakpoint
725 number, not all of them. */
726 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
730 if (bs->old_val != NULL)
732 printf_filtered ("\nWatchpoint %d, ", bs->breakpoint_at->number);
733 print_expression (bs->breakpoint_at->exp, stdout);
734 printf_filtered ("\nOld value = ");
735 value_print (bs->old_val, stdout, 0, Val_pretty_default);
736 printf_filtered ("\nNew value = ");
737 value_print (bs->breakpoint_at->val, stdout, 0,
739 printf_filtered ("\n");
740 value_free (bs->old_val);
745 /* Maybe another breakpoint in the chain caused us to stop.
746 (Currently all watchpoints go on the bpstat whether hit or
747 not. That probably could (should) be changed, provided care is taken
748 with respect to bpstat_explains_signal). */
750 return bpstat_print (bs->next);
752 fprintf_filtered (stderr, "gdb internal error: in bpstat_print\n");
756 /* Evaluate the expression EXP and return 1 if value is zero.
757 This is used inside a catch_errors to evaluate the breakpoint condition.
758 The argument is a "struct expression *" that has been cast to char * to
759 make it pass through catch_errors. */
762 breakpoint_cond_eval (exp)
765 return !value_true (evaluate_expression ((struct expression *)exp));
768 /* Allocate a new bpstat and chain it to the current one. */
771 bpstat_alloc (b, cbs)
772 register struct breakpoint *b;
773 bpstat cbs; /* Current "bs" value */
777 bs = (bpstat) xmalloc (sizeof (*bs));
779 bs->breakpoint_at = b;
780 /* If the condition is false, etc., don't do the commands. */
782 bs->momentary = b->disposition == delete;
787 /* Determine whether we stopped at a breakpoint, etc, or whether we
788 don't understand this stop. Result is a chain of bpstat's such that:
790 if we don't understand the stop, the result is a null pointer.
792 if we understand why we stopped, the result is not null, and
793 the first element of the chain contains summary "stop" and
794 "print" flags for the whole chain.
796 Each element of the chain refers to a particular breakpoint or
797 watchpoint at which we have stopped. (We may have stopped for
800 Each element of the chain has valid next, breakpoint_at,
801 commands, FIXME??? fields.
807 bpstat_stop_status (pc, frame_address)
809 FRAME_ADDR frame_address;
811 register struct breakpoint *b;
815 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
816 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
817 int real_breakpoint = 0;
819 /* Root of the chain of bpstat's */
820 struct bpstat root_bs[1];
821 /* Pointer to the last thing in the chain currently. */
824 /* Get the address where the breakpoint would have been. */
825 bp_addr = *pc - DECR_PC_AFTER_BREAK;
832 if (b->enable == disabled)
835 if (b->type != bp_watchpoint && b->address != bp_addr)
838 /* Come here if it's a watchpoint, or if the break address matches */
840 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
845 if (b->type == bp_watchpoint)
847 int within_current_scope;
848 if (b->exp_valid_block != NULL)
849 within_current_scope =
850 contained_in (get_selected_block (), b->exp_valid_block);
852 within_current_scope = 1;
854 if (within_current_scope)
856 /* We use value_{,free_to_}mark because it could be a
857 *long* time before we return to the command level and
858 call free_all_values. */
860 value mark = value_mark ();
861 value new_val = evaluate_expression (b->exp);
862 if (!value_equal (b->val, new_val))
864 release_value (new_val);
865 value_free_to_mark (mark);
866 bs->old_val = b->val;
868 /* We will stop here */
872 /* Nothing changed, don't do anything. */
873 value_free_to_mark (mark);
875 /* We won't stop here */
880 /* This seems like the only logical thing to do because
881 if we temporarily ignored the watchpoint, then when
882 we reenter the block in which it is valid it contains
883 garbage (in the case of a function, it may have two
884 garbage values, one before and one after the prologue).
885 So we can't even detect the first assignment to it and
886 watch after that (since the garbage may or may not equal
887 the first value assigned). */
888 b->enable = disabled;
890 Watchpoint %d disabled because the program has left the block in\n\
891 which its expression is valid.\n", b->number);
892 /* We won't stop here */
893 /* FIXME, maybe we should stop here!!! */
897 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
902 if (b->frame && b->frame != frame_address)
910 /* Need to select the frame, with all that implies
911 so that the conditions will have the right context. */
912 select_frame (get_current_frame (), 0);
914 = catch_errors (breakpoint_cond_eval, (char *)(b->cond),
915 "Error in testing breakpoint condition:\n");
916 /* FIXME-someday, should give breakpoint # */
919 if (b->cond && value_is_zero)
923 else if (b->ignore_count > 0)
930 /* We will stop here */
931 if (b->disposition == disable)
932 b->enable = disabled;
933 bs->commands = b->commands;
936 if (bs->commands && !strcmp ("silent", bs->commands->line))
938 bs->commands = bs->commands->next;
949 bs->next = NULL; /* Terminate the chain */
950 bs = root_bs->next; /* Re-grab the head of the chain */
955 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
959 #if defined (SHIFT_INST_REGS)
961 CORE_ADDR pc = read_register (PC_REGNUM);
962 CORE_ADDR npc = read_register (NPC_REGNUM);
965 write_register (NNPC_REGNUM, npc);
966 write_register (NPC_REGNUM, pc);
969 #else /* No SHIFT_INST_REGS. */
971 #endif /* No SHIFT_INST_REGS. */
973 #endif /* DECR_PC_AFTER_BREAK != 0. */
978 /* Nonzero if we should step constantly (e.g. watchpoints on machines
979 without hardware support). This isn't related to a specific bpstat,
980 just to things like whether watchpoints are set. */
983 bpstat_should_step ()
985 struct breakpoint *b;
987 if (b->enable == enabled && b->type == bp_watchpoint)
992 /* Print information on breakpoint number BNUM, or -1 if all.
993 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
994 is nonzero, process only watchpoints. */
997 breakpoint_1 (bnum, allflag)
1001 register struct breakpoint *b;
1002 register struct command_line *l;
1003 register struct symbol *sym;
1004 CORE_ADDR last_addr = (CORE_ADDR)-1;
1005 int found_a_breakpoint = 0;
1006 static char *bptypes[] = {"breakpoint", "until", "finish", "watchpoint",
1007 "longjmp", "longjmp resume"};
1008 static char *bpdisps[] = {"del", "dis", "keep"};
1009 static char bpenables[] = "ny";
1011 if (!breakpoint_chain)
1013 printf_filtered ("No breakpoints or watchpoints.\n");
1019 || bnum == b->number)
1021 /* We only print out user settable breakpoints unless the allflag is set. */
1023 && b->type != bp_breakpoint
1024 && b->type != bp_watchpoint)
1027 if (!found_a_breakpoint++)
1028 printf_filtered ("Num Type Disp Enb %sWhat\n",
1029 addressprint ? "Address " : "");
1031 printf_filtered ("%-3d %-14s %-4s %-3c ",
1034 bpdisps[b->disposition],
1035 bpenables[b->enable]);
1039 print_expression (b->exp, stdout);
1045 case bp_longjmp_resume:
1047 printf_filtered ("%s ", local_hex_string_custom(b->address, "08"));
1049 last_addr = b->address;
1052 sym = find_pc_function (b->address);
1055 fputs_filtered ("in ", stdout);
1056 fputs_demangled (SYMBOL_NAME (sym), stdout, 1);
1057 fputs_filtered (" at ", stdout);
1059 fputs_filtered (b->symtab->filename, stdout);
1060 printf_filtered (":%d", b->line_number);
1063 print_address_symbolic (b->address, stdout, demangle, " ");
1066 printf_filtered ("\n");
1069 printf_filtered ("\tstop only in stack frame at %s\n",
1070 local_hex_string(b->frame));
1073 printf_filtered ("\tstop only if ");
1074 print_expression (b->cond, stdout);
1075 printf_filtered ("\n");
1077 if (b->ignore_count)
1078 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
1079 if ((l = b->commands))
1082 fputs_filtered ("\t", stdout);
1083 fputs_filtered (l->line, stdout);
1084 fputs_filtered ("\n", stdout);
1089 if (!found_a_breakpoint
1091 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
1093 /* Compare against (CORE_ADDR)-1 in case some compiler decides
1094 that a comparison of an unsigned with -1 is always false. */
1095 if (last_addr != (CORE_ADDR)-1)
1096 set_next_address (last_addr);
1101 breakpoints_info (bnum_exp, from_tty)
1108 bnum = parse_and_eval_address (bnum_exp);
1110 breakpoint_1 (bnum, 0);
1115 all_breakpoints_info (bnum_exp, from_tty)
1122 bnum = parse_and_eval_address (bnum_exp);
1124 breakpoint_1 (bnum, 1);
1127 /* Print a message describing any breakpoints set at PC. */
1130 describe_other_breakpoints (pc)
1131 register CORE_ADDR pc;
1133 register int others = 0;
1134 register struct breakpoint *b;
1137 if (b->address == pc)
1141 printf ("Note: breakpoint%s ", (others > 1) ? "s" : "");
1143 if (b->address == pc)
1148 (b->enable == disabled) ? " (disabled)" : "",
1149 (others > 1) ? "," : ((others == 1) ? " and" : ""));
1151 printf ("also set at pc %s.\n", local_hex_string(pc));
1155 /* Set the default place to put a breakpoint
1156 for the `break' command with no arguments. */
1159 set_default_breakpoint (valid, addr, symtab, line)
1162 struct symtab *symtab;
1165 default_breakpoint_valid = valid;
1166 default_breakpoint_address = addr;
1167 default_breakpoint_symtab = symtab;
1168 default_breakpoint_line = line;
1171 /* Rescan breakpoints at address ADDRESS,
1172 marking the first one as "first" and any others as "duplicates".
1173 This is so that the bpt instruction is only inserted once. */
1176 check_duplicates (address)
1179 register struct breakpoint *b;
1180 register int count = 0;
1182 if (address == 0) /* Watchpoints are uninteresting */
1186 if (b->enable != disabled && b->address == address)
1189 b->duplicate = count > 1;
1193 /* Low level routine to set a breakpoint.
1194 Takes as args the three things that every breakpoint must have.
1195 Returns the breakpoint object so caller can set other things.
1196 Does not set the breakpoint number!
1197 Does not print anything.
1199 ==> This routine should not be called if there is a chance of later
1200 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
1201 your arguments BEFORE calling this routine! */
1203 static struct breakpoint *
1204 set_raw_breakpoint (sal)
1205 struct symtab_and_line sal;
1207 register struct breakpoint *b, *b1;
1209 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
1210 bzero (b, sizeof *b);
1211 b->address = sal.pc;
1212 b->symtab = sal.symtab;
1213 b->line_number = sal.line;
1214 b->enable = enabled;
1217 b->ignore_count = 0;
1221 /* Add this breakpoint to the end of the chain
1222 so that a list of breakpoints will come out in order
1223 of increasing numbers. */
1225 b1 = breakpoint_chain;
1227 breakpoint_chain = b;
1235 check_duplicates (sal.pc);
1241 create_longjmp_breakpoint(func_name)
1244 struct symtab_and_line sal;
1245 struct breakpoint *b;
1246 static int internal_breakpoint_number = -1;
1248 if (func_name != NULL)
1250 struct minimal_symbol *m;
1252 m = lookup_minimal_symbol(func_name, (struct objfile *)NULL);
1254 sal.pc = m->address;
1264 b = set_raw_breakpoint(sal);
1267 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
1268 b->disposition = donttouch;
1269 b->enable = disabled;
1272 b->addr_string = strsave(func_name);
1273 b->number = internal_breakpoint_number--;
1276 /* Call this routine when stepping and nexting to enable a breakpoint if we do
1277 a longjmp(). When we hit that breakpoint, call
1278 set_longjmp_resume_breakpoint() to figure out where we are going. */
1281 enable_longjmp_breakpoint()
1283 register struct breakpoint *b;
1286 if (b->type == bp_longjmp)
1287 b->enable = enabled;
1291 disable_longjmp_breakpoint()
1293 register struct breakpoint *b;
1296 if (b->type == bp_longjmp
1297 || b->type == bp_longjmp_resume)
1298 b->enable = disabled;
1301 /* Call this after hitting the longjmp() breakpoint. Use this to set a new
1302 breakpoint at the target of the jmp_buf.
1304 FIXME - This ought to be done by setting a temporary breakpoint that gets
1305 deleted automatically...
1309 set_longjmp_resume_breakpoint(pc, frame)
1313 register struct breakpoint *b;
1316 if (b->type == bp_longjmp_resume)
1319 b->enable = enabled;
1321 b->frame = FRAME_FP(frame);
1328 /* Set a breakpoint that will evaporate an end of command
1329 at address specified by SAL.
1330 Restrict it to frame FRAME if FRAME is nonzero. */
1333 set_momentary_breakpoint (sal, frame, type)
1334 struct symtab_and_line sal;
1338 register struct breakpoint *b;
1339 b = set_raw_breakpoint (sal);
1341 b->enable = enabled;
1342 b->disposition = donttouch;
1343 b->frame = (frame ? FRAME_FP (frame) : 0);
1349 clear_momentary_breakpoints ()
1351 register struct breakpoint *b;
1353 if (b->disposition == delete)
1355 delete_breakpoint (b);
1361 /* Tell the user we have just set a breakpoint B. */
1364 struct breakpoint *b;
1369 printf_filtered ("Watchpoint %d: ", b->number);
1370 print_expression (b->exp, stdout);
1373 printf_filtered ("Breakpoint %d at %s", b->number,
1374 local_hex_string(b->address));
1376 printf_filtered (": file %s, line %d.",
1377 b->symtab->filename, b->line_number);
1379 printf_filtered ("\n");
1383 /* Nobody calls this currently. */
1384 /* Set a breakpoint from a symtab and line.
1385 If TEMPFLAG is nonzero, it is a temporary breakpoint.
1386 ADDR_STRING is a malloc'd string holding the name of where we are
1387 setting the breakpoint. This is used later to re-set it after the
1388 program is relinked and symbols are reloaded.
1389 Print the same confirmation messages that the breakpoint command prints. */
1392 set_breakpoint (s, line, tempflag, addr_string)
1398 register struct breakpoint *b;
1399 struct symtab_and_line sal;
1404 resolve_sal_pc (&sal); /* Might error out */
1405 describe_other_breakpoints (sal.pc);
1407 b = set_raw_breakpoint (sal);
1408 set_breakpoint_count (breakpoint_count + 1);
1409 b->number = breakpoint_count;
1410 b->type = bp_breakpoint;
1412 b->addr_string = addr_string;
1413 b->enable = enabled;
1414 b->disposition = tempflag ? delete : donttouch;
1420 /* Set a breakpoint according to ARG (function, linenum or *address)
1421 and make it temporary if TEMPFLAG is nonzero. */
1424 break_command_1 (arg, tempflag, from_tty)
1426 int tempflag, from_tty;
1428 struct symtabs_and_lines sals;
1429 struct symtab_and_line sal;
1430 register struct expression *cond = 0;
1431 register struct breakpoint *b;
1433 /* Pointers in arg to the start, and one past the end, of the condition. */
1434 char *cond_start = NULL;
1436 /* Pointers in arg to the start, and one past the end,
1437 of the address part. */
1438 char *addr_start = NULL;
1446 sal.line = sal.pc = sal.end = 0;
1449 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
1451 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1452 && (arg[2] == ' ' || arg[2] == '\t')))
1454 if (default_breakpoint_valid)
1456 sals.sals = (struct symtab_and_line *)
1457 xmalloc (sizeof (struct symtab_and_line));
1458 sal.pc = default_breakpoint_address;
1459 sal.line = default_breakpoint_line;
1460 sal.symtab = default_breakpoint_symtab;
1465 error ("No default breakpoint address now.");
1471 /* Force almost all breakpoints to be in terms of the
1472 current_source_symtab (which is decode_line_1's default). This
1473 should produce the results we want almost all of the time while
1474 leaving default_breakpoint_* alone. */
1475 if (default_breakpoint_valid
1476 && (!current_source_symtab
1477 || (arg && (*arg == '+' || *arg == '-'))))
1478 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1479 default_breakpoint_line);
1481 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1489 /* Resolve all line numbers to PC's, and verify that conditions
1490 can be parsed, before setting any breakpoints. */
1491 for (i = 0; i < sals.nelts; i++)
1493 resolve_sal_pc (&sals.sals[i]);
1497 if (arg[0] == 'i' && arg[1] == 'f'
1498 && (arg[2] == ' ' || arg[2] == '\t'))
1502 cond = parse_exp_1 (&arg, block_for_pc (sals.sals[i].pc), 0);
1506 error ("Junk at end of arguments.");
1510 /* Now set all the breakpoints. */
1511 for (i = 0; i < sals.nelts; i++)
1516 describe_other_breakpoints (sal.pc);
1518 b = set_raw_breakpoint (sal);
1519 set_breakpoint_count (breakpoint_count + 1);
1520 b->number = breakpoint_count;
1521 b->type = bp_breakpoint;
1525 b->addr_string = savestring (addr_start, addr_end - addr_start);
1527 b->cond_string = savestring (cond_start, cond_end - cond_start);
1529 b->enable = enabled;
1530 b->disposition = tempflag ? delete : donttouch;
1537 printf ("Multiple breakpoints were set.\n");
1538 printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1540 free ((PTR)sals.sals);
1543 /* Helper function for break_command_1 and disassemble_command. */
1546 resolve_sal_pc (sal)
1547 struct symtab_and_line *sal;
1551 if (sal->pc == 0 && sal->symtab != 0)
1553 pc = find_line_pc (sal->symtab, sal->line);
1555 error ("No line %d in file \"%s\".",
1556 sal->line, sal->symtab->filename);
1562 break_command (arg, from_tty)
1566 break_command_1 (arg, 0, from_tty);
1570 tbreak_command (arg, from_tty)
1574 break_command_1 (arg, 1, from_tty);
1579 watch_command (arg, from_tty)
1583 struct breakpoint *b;
1584 struct symtab_and_line sal;
1585 struct expression *exp;
1586 struct block *exp_valid_block;
1593 /* Parse arguments. */
1594 innermost_block = NULL;
1595 exp = parse_expression (arg);
1596 exp_valid_block = innermost_block;
1597 val = evaluate_expression (exp);
1598 release_value (val);
1600 /* Now set up the breakpoint. */
1601 b = set_raw_breakpoint (sal);
1602 set_breakpoint_count (breakpoint_count + 1);
1603 b->number = breakpoint_count;
1604 b->type = bp_watchpoint;
1605 b->disposition = donttouch;
1607 b->exp_valid_block = exp_valid_block;
1610 b->cond_string = NULL;
1615 * Helper routine for the until_command routine in infcmd.c. Here
1616 * because it uses the mechanisms of breakpoints.
1620 until_break_command (arg, from_tty)
1624 struct symtabs_and_lines sals;
1625 struct symtab_and_line sal;
1626 FRAME prev_frame = get_prev_frame (selected_frame);
1627 struct breakpoint *breakpoint;
1628 struct cleanup *old_chain;
1630 clear_proceed_status ();
1632 /* Set a breakpoint where the user wants it and at return from
1635 if (default_breakpoint_valid)
1636 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1637 default_breakpoint_line);
1639 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1641 if (sals.nelts != 1)
1642 error ("Couldn't get information on specified line.");
1645 free ((PTR)sals.sals); /* malloc'd, so freed */
1648 error ("Junk at end of arguments.");
1650 resolve_sal_pc (&sal);
1652 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
1654 old_chain = make_cleanup(delete_breakpoint, breakpoint);
1656 /* Keep within the current frame */
1660 struct frame_info *fi;
1662 fi = get_frame_info (prev_frame);
1663 sal = find_pc_line (fi->pc, 0);
1665 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
1666 make_cleanup(delete_breakpoint, breakpoint);
1669 proceed (-1, -1, 0);
1670 do_cleanups(old_chain);
1674 /* These aren't used; I don't konw what they were for. */
1675 /* Set a breakpoint at the catch clause for NAME. */
1677 catch_breakpoint (name)
1683 disable_catch_breakpoint ()
1688 delete_catch_breakpoint ()
1693 enable_catch_breakpoint ()
1700 struct sal_chain *next;
1701 struct symtab_and_line sal;
1705 /* This isn't used; I don't know what it was for. */
1706 /* For each catch clause identified in ARGS, run FUNCTION
1707 with that clause as an argument. */
1708 static struct symtabs_and_lines
1709 map_catch_names (args, function)
1713 register char *p = args;
1715 struct symtabs_and_lines sals;
1717 struct sal_chain *sal_chain = 0;
1721 error_no_arg ("one or more catch names");
1729 /* Don't swallow conditional part. */
1730 if (p1[0] == 'i' && p1[1] == 'f'
1731 && (p1[2] == ' ' || p1[2] == '\t'))
1737 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
1741 if (*p1 && *p1 != ' ' && *p1 != '\t')
1742 error ("Arguments must be catch names.");
1748 struct sal_chain *next
1749 = (struct sal_chain *)alloca (sizeof (struct sal_chain));
1750 next->next = sal_chain;
1751 next->sal = get_catch_sal (p);
1756 printf ("No catch clause for exception %s.\n", p);
1761 while (*p == ' ' || *p == '\t') p++;
1766 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
1768 static struct symtabs_and_lines
1769 get_catch_sals (this_level_only)
1770 int this_level_only;
1772 register struct blockvector *bl;
1773 register struct block *block;
1774 int index, have_default = 0;
1775 struct frame_info *fi;
1777 struct symtabs_and_lines sals;
1778 struct sal_chain *sal_chain = 0;
1779 char *blocks_searched;
1781 /* Not sure whether an error message is always the correct response,
1782 but it's better than a core dump. */
1783 if (selected_frame == NULL)
1784 error ("No selected frame.");
1785 block = get_frame_block (selected_frame);
1786 fi = get_frame_info (selected_frame);
1793 error ("No symbol table info available.\n");
1795 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
1796 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1797 bzero (blocks_searched, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1801 CORE_ADDR end = BLOCK_END (block) - 4;
1804 if (bl != blockvector_for_pc (end, &index))
1805 error ("blockvector blotch");
1806 if (BLOCKVECTOR_BLOCK (bl, index) != block)
1807 error ("blockvector botch");
1808 last_index = BLOCKVECTOR_NBLOCKS (bl);
1811 /* Don't print out blocks that have gone by. */
1812 while (index < last_index
1813 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
1816 while (index < last_index
1817 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
1819 if (blocks_searched[index] == 0)
1821 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
1824 register struct symbol *sym;
1826 nsyms = BLOCK_NSYMS (b);
1828 for (i = 0; i < nsyms; i++)
1830 sym = BLOCK_SYM (b, i);
1831 if (! strcmp (SYMBOL_NAME (sym), "default"))
1837 if (SYMBOL_CLASS (sym) == LOC_LABEL)
1839 struct sal_chain *next = (struct sal_chain *)
1840 alloca (sizeof (struct sal_chain));
1841 next->next = sal_chain;
1842 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
1846 blocks_searched[index] = 1;
1852 if (sal_chain && this_level_only)
1855 /* After handling the function's top-level block, stop.
1856 Don't continue to its superblock, the block of
1857 per-file symbols. */
1858 if (BLOCK_FUNCTION (block))
1860 block = BLOCK_SUPERBLOCK (block);
1865 struct sal_chain *tmp_chain;
1867 /* Count the number of entries. */
1868 for (index = 0, tmp_chain = sal_chain; tmp_chain;
1869 tmp_chain = tmp_chain->next)
1873 sals.sals = (struct symtab_and_line *)
1874 xmalloc (index * sizeof (struct symtab_and_line));
1875 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
1876 sals.sals[index] = sal_chain->sal;
1882 /* Commands to deal with catching exceptions. */
1885 catch_command_1 (arg, tempflag, from_tty)
1890 /* First, translate ARG into something we can deal with in terms
1893 struct symtabs_and_lines sals;
1894 struct symtab_and_line sal;
1895 register struct expression *cond = 0;
1896 register struct breakpoint *b;
1900 sal.line = sal.pc = sal.end = 0;
1903 /* If no arg given, or if first arg is 'if ', all active catch clauses
1904 are breakpointed. */
1906 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1907 && (arg[2] == ' ' || arg[2] == '\t')))
1909 /* Grab all active catch clauses. */
1910 sals = get_catch_sals (0);
1914 /* Grab selected catch clauses. */
1915 error ("catch NAME not implemeneted");
1917 /* This isn't used; I don't know what it was for. */
1918 sals = map_catch_names (arg, catch_breakpoint);
1926 for (i = 0; i < sals.nelts; i++)
1928 resolve_sal_pc (&sals.sals[i]);
1932 if (arg[0] == 'i' && arg[1] == 'f'
1933 && (arg[2] == ' ' || arg[2] == '\t'))
1934 cond = parse_exp_1 ((arg += 2, &arg),
1935 block_for_pc (sals.sals[i].pc), 0);
1937 error ("Junk at end of arguments.");
1942 for (i = 0; i < sals.nelts; i++)
1947 describe_other_breakpoints (sal.pc);
1949 b = set_raw_breakpoint (sal);
1950 set_breakpoint_count (breakpoint_count + 1);
1951 b->number = breakpoint_count;
1952 b->type = bp_breakpoint;
1954 b->enable = enabled;
1955 b->disposition = tempflag ? delete : donttouch;
1957 printf ("Breakpoint %d at %s", b->number, local_hex_string(b->address));
1959 printf (": file %s, line %d.", b->symtab->filename, b->line_number);
1965 printf ("Multiple breakpoints were set.\n");
1966 printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1968 free ((PTR)sals.sals);
1972 /* These aren't used; I don't know what they were for. */
1973 /* Disable breakpoints on all catch clauses described in ARGS. */
1975 disable_catch (args)
1978 /* Map the disable command to catch clauses described in ARGS. */
1981 /* Enable breakpoints on all catch clauses described in ARGS. */
1986 /* Map the disable command to catch clauses described in ARGS. */
1989 /* Delete breakpoints on all catch clauses in the active scope. */
1994 /* Map the delete command to catch clauses described in ARGS. */
1999 catch_command (arg, from_tty)
2003 catch_command_1 (arg, 0, from_tty);
2007 clear_command (arg, from_tty)
2011 register struct breakpoint *b, *b1;
2012 struct symtabs_and_lines sals;
2013 struct symtab_and_line sal;
2014 register struct breakpoint *found;
2019 sals = decode_line_spec (arg, 1);
2023 sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
2024 sal.line = default_breakpoint_line;
2025 sal.symtab = default_breakpoint_symtab;
2027 if (sal.symtab == 0)
2028 error ("No source file specified.");
2034 for (i = 0; i < sals.nelts; i++)
2036 /* If exact pc given, clear bpts at that pc.
2037 But if sal.pc is zero, clear all bpts on specified line. */
2039 found = (struct breakpoint *) 0;
2040 while (breakpoint_chain
2041 && (sal.pc ? breakpoint_chain->address == sal.pc
2042 : (breakpoint_chain->symtab == sal.symtab
2043 && breakpoint_chain->line_number == sal.line)))
2045 b1 = breakpoint_chain;
2046 breakpoint_chain = b1->next;
2053 && b->next->type != bp_watchpoint
2054 && (sal.pc ? b->next->address == sal.pc
2055 : (b->next->symtab == sal.symtab
2056 && b->next->line_number == sal.line)))
2067 error ("No breakpoint at %s.", arg);
2069 error ("No breakpoint at this line.");
2072 if (found->next) from_tty = 1; /* Always report if deleted more than one */
2073 if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : "");
2076 if (from_tty) printf ("%d ", found->number);
2078 delete_breakpoint (found);
2081 if (from_tty) putchar ('\n');
2083 free ((PTR)sals.sals);
2086 /* Delete breakpoint in BS if they are `delete' breakpoints.
2087 This is called after any breakpoint is hit, or after errors. */
2090 breakpoint_auto_delete (bs)
2093 for (; bs; bs = bs->next)
2094 if (bs->breakpoint_at && bs->breakpoint_at->disposition == delete)
2095 delete_breakpoint (bs->breakpoint_at);
2098 /* Delete a breakpoint and clean up all traces of it in the data structures. */
2101 delete_breakpoint (bpt)
2102 struct breakpoint *bpt;
2104 register struct breakpoint *b;
2108 target_remove_breakpoint(bpt->address, bpt->shadow_contents);
2110 if (breakpoint_chain == bpt)
2111 breakpoint_chain = bpt->next;
2116 b->next = bpt->next;
2120 check_duplicates (bpt->address);
2122 free_command_lines (&bpt->commands);
2124 free ((PTR)bpt->cond);
2125 if (bpt->cond_string != NULL)
2126 free ((PTR)bpt->cond_string);
2127 if (bpt->addr_string != NULL)
2128 free ((PTR)bpt->addr_string);
2130 if (xgdb_verbose && bpt->type == bp_breakpoint)
2131 printf ("breakpoint #%d deleted\n", bpt->number);
2133 /* Be sure no bpstat's are pointing at it after it's been freed. */
2134 /* FIXME, how can we find all bpstat's? We just check stop_bpstat for now. */
2135 for (bs = stop_bpstat; bs; bs = bs->next)
2136 if (bs->breakpoint_at == bpt)
2137 bs->breakpoint_at = NULL;
2142 delete_command (arg, from_tty)
2149 /* Ask user only if there are some breakpoints to delete. */
2151 || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0)))
2153 /* No arg; clear all breakpoints. */
2154 while (breakpoint_chain)
2155 delete_breakpoint (breakpoint_chain);
2159 map_breakpoint_numbers (arg, delete_breakpoint);
2162 /* Reset a breakpoint given it's struct breakpoint * BINT.
2163 The value we return ends up being the return value from catch_errors.
2164 Unused in this case. */
2167 breakpoint_re_set_one (bint)
2170 struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */
2172 struct symtabs_and_lines sals;
2174 enum enable save_enable;
2179 if (b->addr_string == NULL)
2181 /* Anything without a string can't be re-set. */
2182 delete_breakpoint (b);
2185 /* In case we have a problem, disable this breakpoint. We'll restore
2186 its status if we succeed. */
2187 save_enable = b->enable;
2188 b->enable = disabled;
2191 sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0);
2192 for (i = 0; i < sals.nelts; i++)
2194 resolve_sal_pc (&sals.sals[i]);
2195 if (b->symtab != sals.sals[i].symtab
2196 || b->line_number != sals.sals[i].line
2197 || b->address != sals.sals[i].pc)
2199 b->symtab = sals.sals[i].symtab;
2200 b->line_number = sals.sals[i].line;
2201 b->address = sals.sals[i].pc;
2203 if (b->cond_string != NULL)
2206 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
2209 check_duplicates (b->address);
2213 b->enable = save_enable; /* Restore it, this worked. */
2215 free ((PTR)sals.sals);
2218 /* FIXME! This is the wrong thing to do.... */
2219 delete_breakpoint (b);
2222 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
2226 case bp_longjmp_resume:
2227 delete_breakpoint (b);
2234 /* Re-set all breakpoints after symbols have been re-loaded. */
2236 breakpoint_re_set ()
2238 struct breakpoint *b, *temp;
2239 static char message1[] = "Error in re-setting breakpoint %d:\n";
2240 char message[sizeof (message1) + 30 /* slop */];
2242 ALL_BREAKPOINTS_SAFE (b, temp)
2244 sprintf (message, message1, b->number); /* Format possible error msg */
2245 (void) catch_errors (breakpoint_re_set_one, (char *) b, message);
2248 create_longjmp_breakpoint("longjmp");
2249 create_longjmp_breakpoint("_longjmp");
2250 create_longjmp_breakpoint("siglongjmp");
2251 create_longjmp_breakpoint(NULL);
2254 /* Took this out (temporaliy at least), since it produces an extra
2255 blank line at startup. This messes up the gdbtests. -PB */
2256 /* Blank line to finish off all those mention() messages we just printed. */
2257 printf_filtered ("\n");
2261 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
2262 If from_tty is nonzero, it prints a message to that effect,
2263 which ends with a period (no newline). */
2266 set_ignore_count (bptnum, count, from_tty)
2267 int bptnum, count, from_tty;
2269 register struct breakpoint *b;
2275 if (b->number == bptnum)
2277 b->ignore_count = count;
2280 else if (count == 0)
2281 printf ("Will stop next time breakpoint %d is reached.", bptnum);
2282 else if (count == 1)
2283 printf ("Will ignore next crossing of breakpoint %d.", bptnum);
2285 printf ("Will ignore next %d crossings of breakpoint %d.",
2290 error ("No breakpoint number %d.", bptnum);
2293 /* Clear the ignore counts of all breakpoints. */
2295 breakpoint_clear_ignore_counts ()
2297 struct breakpoint *b;
2300 b->ignore_count = 0;
2303 /* Command to set ignore-count of breakpoint N to COUNT. */
2306 ignore_command (args, from_tty)
2314 error_no_arg ("a breakpoint number");
2316 num = get_number (&p);
2319 error ("Second argument (specified ignore-count) is missing.");
2321 set_ignore_count (num,
2322 longest_to_int (value_as_long (parse_and_eval (p))),
2327 /* Call FUNCTION on each of the breakpoints
2328 whose numbers are given in ARGS. */
2331 map_breakpoint_numbers (args, function)
2333 void (*function) PARAMS ((struct breakpoint *));
2335 register char *p = args;
2338 register struct breakpoint *b;
2341 error_no_arg ("one or more breakpoint numbers");
2347 num = get_number (&p1);
2350 if (b->number == num)
2355 printf ("No breakpoint number %d.\n", num);
2362 enable_breakpoint (bpt)
2363 struct breakpoint *bpt;
2365 bpt->enable = enabled;
2367 if (xgdb_verbose && bpt->type == bp_breakpoint)
2368 printf ("breakpoint #%d enabled\n", bpt->number);
2370 check_duplicates (bpt->address);
2371 if (bpt->type == bp_watchpoint)
2373 if (bpt->exp_valid_block != NULL
2374 && !contained_in (get_selected_block (), bpt->exp_valid_block))
2377 Cannot enable watchpoint %d because the block in which its expression\n\
2378 is valid is not currently in scope.\n", bpt->number);
2382 value_free (bpt->val);
2384 bpt->val = evaluate_expression (bpt->exp);
2385 release_value (bpt->val);
2391 enable_command (args, from_tty)
2395 struct breakpoint *bpt;
2397 ALL_BREAKPOINTS (bpt)
2398 enable_breakpoint (bpt);
2400 map_breakpoint_numbers (args, enable_breakpoint);
2404 disable_breakpoint (bpt)
2405 struct breakpoint *bpt;
2407 bpt->enable = disabled;
2409 if (xgdb_verbose && bpt->type == bp_breakpoint)
2410 printf ("breakpoint #%d disabled\n", bpt->number);
2412 check_duplicates (bpt->address);
2417 disable_command (args, from_tty)
2421 register struct breakpoint *bpt;
2423 ALL_BREAKPOINTS (bpt)
2424 disable_breakpoint (bpt);
2426 map_breakpoint_numbers (args, disable_breakpoint);
2430 enable_once_breakpoint (bpt)
2431 struct breakpoint *bpt;
2433 bpt->enable = enabled;
2434 bpt->disposition = disable;
2436 check_duplicates (bpt->address);
2441 enable_once_command (args, from_tty)
2445 map_breakpoint_numbers (args, enable_once_breakpoint);
2449 enable_delete_breakpoint (bpt)
2450 struct breakpoint *bpt;
2452 bpt->enable = enabled;
2453 bpt->disposition = delete;
2455 check_duplicates (bpt->address);
2460 enable_delete_command (args, from_tty)
2464 map_breakpoint_numbers (args, enable_delete_breakpoint);
2468 * Use default_breakpoint_'s, or nothing if they aren't valid.
2470 struct symtabs_and_lines
2471 decode_line_spec_1 (string, funfirstline)
2475 struct symtabs_and_lines sals;
2477 error ("Empty line specification.");
2478 if (default_breakpoint_valid)
2479 sals = decode_line_1 (&string, funfirstline,
2480 default_breakpoint_symtab, default_breakpoint_line);
2482 sals = decode_line_1 (&string, funfirstline, (struct symtab *)NULL, 0);
2484 error ("Junk at end of line specification: %s", string);
2489 /* Chain containing all defined enable commands. */
2491 extern struct cmd_list_element
2492 *enablelist, *disablelist,
2493 *deletelist, *enablebreaklist;
2495 extern struct cmd_list_element *cmdlist;
2498 _initialize_breakpoint ()
2500 breakpoint_chain = 0;
2501 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
2502 before a breakpoint is set. */
2503 breakpoint_count = 0;
2505 add_com ("ignore", class_breakpoint, ignore_command,
2506 "Set ignore-count of breakpoint number N to COUNT.");
2508 add_com ("commands", class_breakpoint, commands_command,
2509 "Set commands to be executed when a breakpoint is hit.\n\
2510 Give breakpoint number as argument after \"commands\".\n\
2511 With no argument, the targeted breakpoint is the last one set.\n\
2512 The commands themselves follow starting on the next line.\n\
2513 Type a line containing \"end\" to indicate the end of them.\n\
2514 Give \"silent\" as the first line to make the breakpoint silent;\n\
2515 then no output is printed when it is hit, except what the commands print.");
2517 add_com ("condition", class_breakpoint, condition_command,
2518 "Specify breakpoint number N to break only if COND is true.\n\
2519 N is an integer; COND is an expression to be evaluated whenever\n\
2520 breakpoint N is reached. ");
2522 add_com ("tbreak", class_breakpoint, tbreak_command,
2523 "Set a temporary breakpoint. Args like \"break\" command.\n\
2524 Like \"break\" except the breakpoint is only enabled temporarily,\n\
2525 so it will be disabled when hit. Equivalent to \"break\" followed\n\
2526 by using \"enable once\" on the breakpoint number.");
2528 add_prefix_cmd ("enable", class_breakpoint, enable_command,
2529 "Enable some breakpoints.\n\
2530 Give breakpoint numbers (separated by spaces) as arguments.\n\
2531 With no subcommand, breakpoints are enabled until you command otherwise.\n\
2532 This is used to cancel the effect of the \"disable\" command.\n\
2533 With a subcommand you can enable temporarily.",
2534 &enablelist, "enable ", 1, &cmdlist);
2536 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
2537 "Enable some breakpoints.\n\
2538 Give breakpoint numbers (separated by spaces) as arguments.\n\
2539 This is used to cancel the effect of the \"disable\" command.\n\
2540 May be abbreviated to simply \"enable\".\n",
2541 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
2543 add_cmd ("once", no_class, enable_once_command,
2544 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
2545 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2546 See the \"tbreak\" command which sets a breakpoint and enables it once.",
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 ("delete", no_class, enable_delete_command,
2555 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
2556 If a breakpoint is hit while enabled in this fashion, it is deleted.",
2559 add_cmd ("once", no_class, enable_once_command,
2560 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
2561 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2562 See the \"tbreak\" command which sets a breakpoint and enables it once.",
2565 add_prefix_cmd ("disable", class_breakpoint, disable_command,
2566 "Disable some breakpoints.\n\
2567 Arguments are breakpoint numbers with spaces in between.\n\
2568 To disable all breakpoints, give no argument.\n\
2569 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
2570 &disablelist, "disable ", 1, &cmdlist);
2571 add_com_alias ("dis", "disable", class_breakpoint, 1);
2572 add_com_alias ("disa", "disable", class_breakpoint, 1);
2574 add_cmd ("breakpoints", class_alias, disable_command,
2575 "Disable some breakpoints.\n\
2576 Arguments are breakpoint numbers with spaces in between.\n\
2577 To disable all breakpoints, give no argument.\n\
2578 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
2579 This command may be abbreviated \"disable\".",
2582 add_prefix_cmd ("delete", class_breakpoint, delete_command,
2583 "Delete some breakpoints or auto-display expressions.\n\
2584 Arguments are breakpoint numbers with spaces in between.\n\
2585 To delete all breakpoints, give no argument.\n\
2587 Also a prefix command for deletion of other GDB objects.\n\
2588 The \"unset\" command is also an alias for \"delete\".",
2589 &deletelist, "delete ", 1, &cmdlist);
2590 add_com_alias ("d", "delete", class_breakpoint, 1);
2592 add_cmd ("breakpoints", class_alias, delete_command,
2593 "Delete some breakpoints or auto-display expressions.\n\
2594 Arguments are breakpoint numbers with spaces in between.\n\
2595 To delete all breakpoints, give no argument.\n\
2596 This command may be abbreviated \"delete\".",
2599 add_com ("clear", class_breakpoint, clear_command,
2600 "Clear breakpoint at specified line or function.\n\
2601 Argument may be line number, function name, or \"*\" and an address.\n\
2602 If line number is specified, all breakpoints in that line are cleared.\n\
2603 If function is specified, breakpoints at beginning of function are cleared.\n\
2604 If an address is specified, breakpoints at that address are cleared.\n\n\
2605 With no argument, clears all breakpoints in the line that the selected frame\n\
2608 See also the \"delete\" command which clears breakpoints by number.");
2610 add_com ("break", class_breakpoint, break_command,
2611 "Set breakpoint at specified line or function.\n\
2612 Argument may be line number, function name, or \"*\" and an address.\n\
2613 If line number is specified, break at start of code for that line.\n\
2614 If function is specified, break at start of code for that function.\n\
2615 If an address is specified, break at that exact address.\n\
2616 With no arg, uses current execution address of selected stack frame.\n\
2617 This is useful for breaking on return to a stack frame.\n\
2619 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
2621 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2622 add_com_alias ("b", "break", class_run, 1);
2623 add_com_alias ("br", "break", class_run, 1);
2624 add_com_alias ("bre", "break", class_run, 1);
2625 add_com_alias ("brea", "break", class_run, 1);
2627 add_info ("breakpoints", breakpoints_info,
2628 "Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
2629 The \"Type\" column indicates one of:\n\
2630 \tbreakpoint - for normal breakpoints\n\
2631 \twatchpoint - for watchpoints\n\
2632 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
2633 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
2634 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
2635 address and file/line number respectively.\n\n\
2636 Convenience variable \"$_\" and default examine address for \"x\"\n\
2637 are set to the address of the last breakpoint listed.\n\n\
2638 Convenience variable \"$bpnum\" contains the number of the last\n\
2641 add_info ("all-breakpoints", all_breakpoints_info,
2642 "Status of all breakpoints, or breakpoint number NUMBER.\n\
2643 The \"Type\" column indicates one of:\n\
2644 \tbreakpoint - for normal breakpoints\n\
2645 \twatchpoint - for watchpoints\n\
2646 \tlongjmp - for internal breakpoints to handle stepping through longjmp()\n\
2647 \tlongjmp resume - for internal breakpoints at the target of longjmp()\n\
2648 \tuntil - for internal breakpoints used by the \"until\" command\n\
2649 \tfinish - for internal breakpoints used by the \"finish\" command\n\
2650 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
2651 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
2652 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
2653 address and file/line number respectively.\n\n\
2654 Convenience variable \"$_\" and default examine address for \"x\"\n\
2655 are set to the address of the last breakpoint listed.\n\n\
2656 Convenience variable \"$bpnum\" contains the number of the last\n\
2659 add_com ("catch", class_breakpoint, catch_command,
2660 "Set breakpoints to catch exceptions that are raised.\n\
2661 Argument may be a single exception to catch, multiple exceptions\n\
2662 to catch, or the default exception \"default\". If no arguments\n\
2663 are given, breakpoints are set at all exception handlers catch clauses\n\
2664 within the current scope.\n\
2666 A condition specified for the catch applies to all breakpoints set\n\
2667 with this command\n\
2669 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2671 add_com ("watch", class_breakpoint, watch_command,
2672 "Set a watchpoint for an expression.\n\
2673 A watchpoint stops execution of your program whenever the value of\n\
2674 an expression changes.");
2676 add_info ("watchpoints", breakpoints_info,
2677 "Synonym for ``info breakpoints''.");
2681 /* Where should this function go? It is used by AIX only. FIXME. */
2683 /* Breakpoint address relocation used to be done in breakpoint_re_set(). That
2684 approach the following problem:
2686 before running the program, if a file is list, then a breakpoint is
2687 set (just the line number), then if we switch into another file and run
2688 the program, just a line number as a breakpoint address was not
2689 descriptive enough and breakpoint was ending up in a different file's
2692 I don't think any other platform has this breakpoint relocation problem, so this
2693 is not an issue for other platforms. */
2696 fixup_breakpoints (low, high, delta)
2701 struct breakpoint *b;
2702 extern struct breakpoint *breakpoint_chain;
2706 if (b->address >= low && b->address <= high)
2707 b->address += delta;