* infrun.c, infcmd.c, breakpoint.c, main.c, symfile.c,
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
1 /* Everything about breakpoints, for GDB.
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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. */
19
20 #include <stdio.h>
21 #include <ctype.h>
22 #include "defs.h"
23 #include "symtab.h"
24 #include "frame.h"
25 #include "breakpoint.h"
26 #include "gdbtypes.h"
27 #include "expression.h"
28 #include "gdbcore.h"
29 #include "gdbcmd.h"
30 #include "value.h"
31 #include "ctype.h"
32 #include "command.h"
33 #include "inferior.h"
34 #include "target.h"
35 #include "language.h"
36 #include <string.h>
37
38 /* local function prototypes */
39
40 static void
41 catch_command_1 PARAMS ((char *, int, int));
42
43 static void
44 enable_delete_command PARAMS ((char *, int));
45
46 static void
47 enable_delete_breakpoint PARAMS ((struct breakpoint *));
48
49 static void
50 enable_once_command PARAMS ((char *, int));
51
52 static void
53 enable_once_breakpoint PARAMS ((struct breakpoint *));
54
55 static void
56 disable_command PARAMS ((char *, int));
57
58 static void
59 disable_breakpoint PARAMS ((struct breakpoint *));
60
61 static void
62 enable_command PARAMS ((char *, int));
63
64 static void
65 enable_breakpoint PARAMS ((struct breakpoint *));
66
67 static void
68 map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *)));
69
70 static void
71 ignore_command PARAMS ((char *, int));
72
73 static int
74 breakpoint_re_set_one PARAMS ((char *));
75
76 static void
77 delete_command PARAMS ((char *, int));
78
79 static void
80 clear_command PARAMS ((char *, int));
81
82 static void
83 catch_command PARAMS ((char *, int));
84
85 static struct symtabs_and_lines
86 get_catch_sals PARAMS ((int));
87
88 static void
89 watch_command PARAMS ((char *, int));
90
91 static void
92 tbreak_command PARAMS ((char *, int));
93
94 static void
95 break_command_1 PARAMS ((char *, int, int));
96
97 static void
98 mention PARAMS ((struct breakpoint *));
99
100 static struct breakpoint *
101 set_raw_breakpoint PARAMS ((struct symtab_and_line));
102
103 static void
104 check_duplicates PARAMS ((CORE_ADDR));
105
106 static void
107 describe_other_breakpoints PARAMS ((CORE_ADDR));
108
109 static void
110 watchpoints_info PARAMS ((char *, int));
111
112 static void
113 breakpoints_info PARAMS ((char *, int));
114
115 static void
116 breakpoint_1 PARAMS ((int, int));
117
118 static bpstat
119 bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
120
121 static int
122 breakpoint_cond_eval PARAMS ((char *));
123
124 static void
125 cleanup_executing_breakpoints PARAMS ((int));
126
127 static void
128 commands_command PARAMS ((char *, int));
129
130 static void
131 condition_command PARAMS ((char *, int));
132
133 static int
134 get_number PARAMS ((char **));
135
136 static void
137 set_breakpoint_count PARAMS ((int));
138
139
140 extern int addressprint; /* Print machine addresses? */
141 extern int demangle; /* Print de-mangled symbol names? */
142
143 /* Are we executing breakpoint commands? */
144 static int executing_breakpoint_commands;
145
146 #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
147
148 /* Chain of all breakpoints defined. */
149
150 struct breakpoint *breakpoint_chain;
151
152 /* Number of last breakpoint made. */
153
154 static int breakpoint_count;
155
156 /* Set breakpoint count to NUM. */
157 static void
158 set_breakpoint_count (num)
159 int num;
160 {
161 breakpoint_count = num;
162 set_internalvar (lookup_internalvar ("bpnum"),
163 value_from_longest (builtin_type_int, (LONGEST) num));
164 }
165
166 /* Default address, symtab and line to put a breakpoint at
167 for "break" command with no arg.
168 if default_breakpoint_valid is zero, the other three are
169 not valid, and "break" with no arg is an error.
170
171 This set by print_stack_frame, which calls set_default_breakpoint. */
172
173 int default_breakpoint_valid;
174 CORE_ADDR default_breakpoint_address;
175 struct symtab *default_breakpoint_symtab;
176 int default_breakpoint_line;
177
178 /* Flag indicating extra verbosity for xgdb. */
179 extern int xgdb_verbose;
180 \f
181 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
182 Advance *PP after the string and any trailing whitespace.
183
184 Currently the string can either be a number or "$" followed by the name
185 of a convenience variable. Making it an expression wouldn't work well
186 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
187 static int
188 get_number (pp)
189 char **pp;
190 {
191 int retval;
192 char *p = *pp;
193
194 if (p == NULL)
195 /* Empty line means refer to the last breakpoint. */
196 return breakpoint_count;
197 else if (*p == '$')
198 {
199 /* Make a copy of the name, so we can null-terminate it
200 to pass to lookup_internalvar(). */
201 char *varname;
202 char *start = ++p;
203 value val;
204
205 while (isalnum (*p) || *p == '_')
206 p++;
207 varname = (char *) alloca (p - start + 1);
208 strncpy (varname, start, p - start);
209 varname[p - start] = '\0';
210 val = value_of_internalvar (lookup_internalvar (varname));
211 if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
212 error (
213 "Convenience variables used to specify breakpoints must have integer values."
214 );
215 retval = (int) value_as_long (val);
216 }
217 else
218 {
219 while (*p >= '0' && *p <= '9')
220 ++p;
221 if (p == *pp)
222 /* There is no number here. (e.g. "cond a == b"). */
223 error_no_arg ("breakpoint number");
224 retval = atoi (*pp);
225 }
226 if (!(isspace (*p) || *p == '\0'))
227 error ("breakpoint number expected");
228 while (isspace (*p))
229 p++;
230 *pp = p;
231 return retval;
232 }
233 \f
234 /* condition N EXP -- set break condition of breakpoint N to EXP. */
235
236 static void
237 condition_command (arg, from_tty)
238 char *arg;
239 int from_tty;
240 {
241 register struct breakpoint *b;
242 char *p;
243 register int bnum;
244
245 if (arg == 0)
246 error_no_arg ("breakpoint number");
247
248 p = arg;
249 bnum = get_number (&p);
250
251 ALL_BREAKPOINTS (b)
252 if (b->number == bnum)
253 {
254 if (b->cond)
255 {
256 free (b->cond);
257 b->cond = 0;
258 }
259 if (b->cond_string != NULL)
260 free (b->cond_string);
261
262 if (*p == 0)
263 {
264 b->cond = 0;
265 b->cond_string = NULL;
266 if (from_tty)
267 printf ("Breakpoint %d now unconditional.\n", bnum);
268 }
269 else
270 {
271 arg = p;
272 /* I don't know if it matters whether this is the string the user
273 typed in or the decompiled expression. */
274 b->cond_string = savestring (arg, strlen (arg));
275 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
276 if (*arg)
277 error ("Junk at end of expression");
278 }
279 return;
280 }
281
282 error ("No breakpoint number %d.", bnum);
283 }
284
285 /* ARGSUSED */
286 static void
287 commands_command (arg, from_tty)
288 char *arg;
289 int from_tty;
290 {
291 register struct breakpoint *b;
292 char *p;
293 register int bnum;
294 struct command_line *l;
295
296 /* If we allowed this, we would have problems with when to
297 free the storage, if we change the commands currently
298 being read from. */
299
300 if (executing_breakpoint_commands)
301 error ("Can't use the \"commands\" command among a breakpoint's commands.");
302
303 p = arg;
304 bnum = get_number (&p);
305 if (p && *p)
306 error ("Unexpected extra arguments following breakpoint number.");
307
308 ALL_BREAKPOINTS (b)
309 if (b->number == bnum)
310 {
311 if (from_tty && input_from_terminal_p ())
312 {
313 printf ("Type commands for when breakpoint %d is hit, one per line.\n\
314 End with a line saying just \"end\".\n", bnum);
315 fflush (stdout);
316 }
317 l = read_command_lines ();
318 free_command_lines (&b->commands);
319 b->commands = l;
320 return;
321 }
322 error ("No breakpoint number %d.", bnum);
323 }
324 \f
325 extern int memory_breakpoint_size; /* from mem-break.c */
326
327 /* Like target_read_memory() but if breakpoints are inserted, return
328 the shadow contents instead of the breakpoints themselves.
329
330 Read "memory data" from whatever target or inferior we have.
331 Returns zero if successful, errno value if not. EIO is used
332 for address out of bounds. If breakpoints are inserted, returns
333 shadow contents, not the breakpoints themselves. From breakpoint.c. */
334
335 int
336 read_memory_nobpt (memaddr, myaddr, len)
337 CORE_ADDR memaddr;
338 char *myaddr;
339 unsigned len;
340 {
341 int status;
342 struct breakpoint *b;
343
344 if (memory_breakpoint_size < 0)
345 /* No breakpoints on this machine. */
346 return target_read_memory (memaddr, myaddr, len);
347
348 ALL_BREAKPOINTS (b)
349 {
350 if (b->type == bp_watchpoint || !b->inserted)
351 continue;
352 else if (b->address + memory_breakpoint_size <= memaddr)
353 /* The breakpoint is entirely before the chunk of memory
354 we are reading. */
355 continue;
356 else if (b->address >= memaddr + len)
357 /* The breakpoint is entirely after the chunk of memory we
358 are reading. */
359 continue;
360 else
361 {
362 /* Copy the breakpoint from the shadow contents, and recurse
363 for the things before and after. */
364
365 /* Addresses and length of the part of the breakpoint that
366 we need to copy. */
367 CORE_ADDR membpt = b->address;
368 unsigned int bptlen = memory_breakpoint_size;
369 /* Offset within shadow_contents. */
370 int bptoffset = 0;
371
372 if (membpt < memaddr)
373 {
374 /* Only copy the second part of the breakpoint. */
375 bptlen -= memaddr - membpt;
376 bptoffset = memaddr - membpt;
377 membpt = memaddr;
378 }
379
380 if (membpt + bptlen > memaddr + len)
381 {
382 /* Only copy the first part of the breakpoint. */
383 bptlen -= (membpt + bptlen) - (memaddr + len);
384 }
385
386 bcopy (b->shadow_contents + bptoffset,
387 myaddr + membpt - memaddr, bptlen);
388
389 if (membpt > memaddr)
390 {
391 /* Copy the section of memory before the breakpoint. */
392 status = read_memory_nobpt (memaddr, myaddr, membpt - memaddr);
393 if (status != 0)
394 return status;
395 }
396
397 if (membpt + bptlen < memaddr + len)
398 {
399 /* Copy the section of memory after the breakpoint. */
400 status = read_memory_nobpt
401 (membpt + bptlen,
402 myaddr + membpt + bptlen - memaddr,
403 memaddr + len - (membpt + bptlen));
404 if (status != 0)
405 return status;
406 }
407 return 0;
408 }
409 }
410 /* Nothing overlaps. Just call read_memory_noerr. */
411 return target_read_memory (memaddr, myaddr, len);
412 }
413 \f
414 /* insert_breakpoints is used when starting or continuing the program.
415 remove_breakpoints is used when the program stops.
416 Both return zero if successful,
417 or an `errno' value if could not write the inferior. */
418
419 int
420 insert_breakpoints ()
421 {
422 register struct breakpoint *b;
423 int val = 0;
424 int disabled_breaks = 0;
425
426 ALL_BREAKPOINTS (b)
427 if (b->type != bp_watchpoint
428 && b->enable != disabled
429 && ! b->inserted
430 && ! b->duplicate)
431 {
432 val = target_insert_breakpoint(b->address, b->shadow_contents);
433 if (val)
434 {
435 /* Can't set the breakpoint. */
436 #if defined (DISABLE_UNSETTABLE_BREAK)
437 if (DISABLE_UNSETTABLE_BREAK (b->address))
438 {
439 val = 0;
440 b->enable = disabled;
441 if (!disabled_breaks)
442 {
443 fprintf (stderr,
444 "Cannot insert breakpoint %d:\n", b->number);
445 printf_filtered ("Disabling shared library breakpoints:\n");
446 }
447 disabled_breaks = 1;
448 printf_filtered ("%d ", b->number);
449 }
450 else
451 #endif
452 {
453 fprintf (stderr, "Cannot insert breakpoint %d:\n", b->number);
454 #ifdef ONE_PROCESS_WRITETEXT
455 fprintf (stderr,
456 "The same program may be running in another process.\n");
457 #endif
458 memory_error (val, b->address); /* which bombs us out */
459 }
460 }
461 else
462 b->inserted = 1;
463 }
464 if (disabled_breaks)
465 printf_filtered ("\n");
466 return val;
467 }
468
469 int
470 remove_breakpoints ()
471 {
472 register struct breakpoint *b;
473 int val;
474
475 #ifdef BREAKPOINT_DEBUG
476 printf ("Removing breakpoints.\n");
477 #endif /* BREAKPOINT_DEBUG */
478
479 ALL_BREAKPOINTS (b)
480 if (b->type != bp_watchpoint && b->inserted)
481 {
482 val = target_remove_breakpoint(b->address, b->shadow_contents);
483 if (val)
484 return val;
485 b->inserted = 0;
486 #ifdef BREAKPOINT_DEBUG
487 printf ("Removed breakpoint at %s",
488 local_hex_string(b->address));
489 printf (", shadow %s",
490 local_hex_string(b->shadow_contents[0]));
491 printf (", %s.\n",
492 local_hex_string(b->shadow_contents[1]));
493 #endif /* BREAKPOINT_DEBUG */
494 }
495
496 return 0;
497 }
498
499 /* Clear the "inserted" flag in all breakpoints.
500 This is done when the inferior is loaded. */
501
502 void
503 mark_breakpoints_out ()
504 {
505 register struct breakpoint *b;
506
507 ALL_BREAKPOINTS (b)
508 b->inserted = 0;
509 }
510
511 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
512 When continuing from a location with a breakpoint,
513 we actually single step once before calling insert_breakpoints. */
514
515 int
516 breakpoint_here_p (pc)
517 CORE_ADDR pc;
518 {
519 register struct breakpoint *b;
520
521 ALL_BREAKPOINTS (b)
522 if (b->enable != disabled && b->address == pc)
523 return 1;
524
525 return 0;
526 }
527 \f
528 /* bpstat stuff. External routines' interfaces are documented
529 in breakpoint.h. */
530
531 /* Clear a bpstat so that it says we are not at any breakpoint.
532 Also free any storage that is part of a bpstat. */
533
534 void
535 bpstat_clear (bsp)
536 bpstat *bsp;
537 {
538 bpstat p;
539 bpstat q;
540
541 if (bsp == 0)
542 return;
543 p = *bsp;
544 while (p != NULL)
545 {
546 q = p->next;
547 if (p->old_val != NULL)
548 value_free (p->old_val);
549 free (p);
550 p = q;
551 }
552 *bsp = NULL;
553 }
554
555 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
556 is part of the bpstat is copied as well. */
557
558 bpstat
559 bpstat_copy (bs)
560 bpstat bs;
561 {
562 bpstat p = NULL;
563 bpstat tmp;
564 bpstat retval;
565
566 if (bs == NULL)
567 return bs;
568
569 for (; bs != NULL; bs = bs->next)
570 {
571 tmp = (bpstat) xmalloc (sizeof (*tmp));
572 bcopy (bs, tmp, sizeof (*tmp));
573 if (p == NULL)
574 /* This is the first thing in the chain. */
575 retval = tmp;
576 else
577 p->next = tmp;
578 p = tmp;
579 }
580 p->next = NULL;
581 return retval;
582 }
583
584 /* Find the bpstat associated with this breakpoint */
585
586 bpstat
587 bpstat_find_breakpoint(bsp, breakpoint)
588 bpstat bsp;
589 struct breakpoint *breakpoint;
590 {
591 if (bsp == NULL) return NULL;
592
593 for (;bsp != NULL; bsp = bsp->next) {
594 if (bsp->breakpoint_at == breakpoint) return bsp;
595 }
596 return NULL;
597 }
598
599 /* Return the breakpoint number of the first breakpoint we are stopped
600 at. *BSP upon return is a bpstat which points to the remaining
601 breakpoints stopped at (but which is not guaranteed to be good for
602 anything but further calls to bpstat_num).
603 Return 0 if passed a bpstat which does not indicate any breakpoints. */
604
605 int
606 bpstat_num (bsp)
607 bpstat *bsp;
608 {
609 struct breakpoint *b;
610
611 if ((*bsp) == NULL)
612 return 0; /* No more breakpoint values */
613 else
614 {
615 b = (*bsp)->breakpoint_at;
616 *bsp = (*bsp)->next;
617 if (b == NULL)
618 return -1; /* breakpoint that's been deleted since */
619 else
620 return b->number; /* We have its number */
621 }
622 }
623
624 /* Modify BS so that the actions will not be performed. */
625
626 void
627 bpstat_clear_actions (bs)
628 bpstat bs;
629 {
630 for (; bs != NULL; bs = bs->next)
631 {
632 bs->commands = NULL;
633 if (bs->old_val != NULL)
634 {
635 value_free (bs->old_val);
636 bs->old_val = NULL;
637 }
638 }
639 }
640
641 /* Stub for cleaning up our state if we error-out of a breakpoint command */
642 /* ARGSUSED */
643 static void
644 cleanup_executing_breakpoints (ignore)
645 int ignore;
646 {
647 executing_breakpoint_commands = 0;
648 }
649
650 /* Execute all the commands associated with all the breakpoints at this
651 location. Any of these commands could cause the process to proceed
652 beyond this point, etc. We look out for such changes by checking
653 the global "breakpoint_proceeded" after each command. */
654
655 void
656 bpstat_do_actions (bsp)
657 bpstat *bsp;
658 {
659 bpstat bs;
660 struct cleanup *old_chain;
661
662 executing_breakpoint_commands = 1;
663 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
664
665 top:
666 bs = *bsp;
667
668 breakpoint_proceeded = 0;
669 for (; bs != NULL; bs = bs->next)
670 {
671 while (bs->commands)
672 {
673 char *line = bs->commands->line;
674 bs->commands = bs->commands->next;
675 execute_command (line, 0);
676 /* If the inferior is proceeded by the command, bomb out now.
677 The bpstat chain has been blown away by wait_for_inferior.
678 But since execution has stopped again, there is a new bpstat
679 to look at, so start over. */
680 if (breakpoint_proceeded)
681 goto top;
682 }
683 }
684
685 executing_breakpoint_commands = 0;
686 discard_cleanups (old_chain);
687 }
688
689 /* Print a message indicating what happened. Returns nonzero to
690 say that only the source line should be printed after this (zero
691 return means print the frame as well as the source line). */
692
693 int
694 bpstat_print (bs)
695 bpstat bs;
696 {
697 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
698 which has since been deleted. */
699 if (bs == NULL
700 || bs->breakpoint_at == NULL
701 || (bs->breakpoint_at->type != bp_breakpoint
702 && bs->breakpoint_at->type != bp_watchpoint))
703 return 0;
704
705 /* If bpstat_stop_status says don't print, OK, we won't. An example
706 circumstance is when we single-stepped for both a watchpoint and
707 for a "stepi" instruction. The bpstat says that the watchpoint
708 explains the stop, but we shouldn't print because the watchpoint's
709 value didn't change -- and the real reason we are stopping here
710 rather than continuing to step (as the watchpoint would've had us do)
711 is because of the "stepi". */
712 if (!bs->print)
713 return 0;
714
715 if (bs->breakpoint_at->type == bp_breakpoint)
716 {
717 /* I think the user probably only wants to see one breakpoint
718 number, not all of them. */
719 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
720 return 0;
721 }
722
723 if (bs->old_val != NULL)
724 {
725 printf_filtered ("\nWatchpoint %d, ", bs->breakpoint_at->number);
726 print_expression (bs->breakpoint_at->exp, stdout);
727 printf_filtered ("\nOld value = ");
728 value_print (bs->old_val, stdout, 0, Val_pretty_default);
729 printf_filtered ("\nNew value = ");
730 value_print (bs->breakpoint_at->val, stdout, 0,
731 Val_pretty_default);
732 printf_filtered ("\n");
733 value_free (bs->old_val);
734 bs->old_val = NULL;
735 return 1;
736 }
737
738 /* Maybe another breakpoint in the chain caused us to stop.
739 (Currently all watchpoints go on the bpstat whether hit or
740 not. That probably could (should) be changed, provided care is taken
741 with respect to bpstat_explains_signal). */
742 if (bs->next)
743 return bpstat_print (bs->next);
744
745 fprintf_filtered (stderr, "gdb internal error: in bpstat_print\n");
746 return 0;
747 }
748
749 /* Evaluate the expression EXP and return 1 if value is zero.
750 This is used inside a catch_errors to evaluate the breakpoint condition.
751 The argument is a "struct expression *" that has been cast to char * to
752 make it pass through catch_errors. */
753
754 static int
755 breakpoint_cond_eval (exp)
756 char *exp;
757 {
758 return !value_true (evaluate_expression ((struct expression *)exp));
759 }
760
761 /* Allocate a new bpstat and chain it to the current one. */
762
763 static bpstat
764 bpstat_alloc (b, cbs)
765 register struct breakpoint *b;
766 bpstat cbs; /* Current "bs" value */
767 {
768 bpstat bs;
769
770 bs = (bpstat) xmalloc (sizeof (*bs));
771 cbs->next = bs;
772 bs->breakpoint_at = b;
773 /* If the condition is false, etc., don't do the commands. */
774 bs->commands = NULL;
775 bs->momentary = b->disposition == delete;
776 bs->old_val = NULL;
777 return bs;
778 }
779
780 /* Determine whether we stopped at a breakpoint, etc, or whether we
781 don't understand this stop. Result is a chain of bpstat's such that:
782
783 if we don't understand the stop, the result is a null pointer.
784
785 if we understand why we stopped, the result is not null, and
786 the first element of the chain contains summary "stop" and
787 "print" flags for the whole chain.
788
789 Each element of the chain refers to a particular breakpoint or
790 watchpoint at which we have stopped. (We may have stopped for
791 several reasons.)
792
793 Each element of the chain has valid next, breakpoint_at,
794 commands, FIXME??? fields.
795
796 */
797
798
799 bpstat
800 bpstat_stop_status (pc, frame_address)
801 CORE_ADDR *pc;
802 FRAME_ADDR frame_address;
803 {
804 register struct breakpoint *b;
805 int stop = 0;
806 int print = 0;
807 CORE_ADDR bp_addr;
808 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
809 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
810 int real_breakpoint = 0;
811 #endif
812 /* Root of the chain of bpstat's */
813 struct bpstat__struct root_bs[1];
814 /* Pointer to the last thing in the chain currently. */
815 bpstat bs = root_bs;
816
817 /* Get the address where the breakpoint would have been. */
818 bp_addr = *pc - DECR_PC_AFTER_BREAK;
819
820 ALL_BREAKPOINTS (b)
821 {
822 int this_bp_stop;
823 int this_bp_print;
824
825 if (b->enable == disabled)
826 continue;
827
828 if (b->type != bp_watchpoint && b->address != bp_addr)
829 continue;
830
831 /* Come here if it's a watchpoint, or if the break address matches */
832
833 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
834
835 this_bp_stop = 1;
836 this_bp_print = 1;
837
838 if (b->type == bp_watchpoint)
839 {
840 int within_current_scope;
841 if (b->exp_valid_block != NULL)
842 within_current_scope =
843 contained_in (get_selected_block (), b->exp_valid_block);
844 else
845 within_current_scope = 1;
846
847 if (within_current_scope)
848 {
849 /* We use value_{,free_to_}mark because it could be a
850 *long* time before we return to the command level and
851 call free_all_values. */
852
853 value mark = value_mark ();
854 value new_val = evaluate_expression (b->exp);
855 if (!value_equal (b->val, new_val))
856 {
857 release_value (new_val);
858 value_free_to_mark (mark);
859 bs->old_val = b->val;
860 b->val = new_val;
861 /* We will stop here */
862 }
863 else
864 {
865 /* Nothing changed, don't do anything. */
866 value_free_to_mark (mark);
867 continue;
868 /* We won't stop here */
869 }
870 }
871 else
872 {
873 /* This seems like the only logical thing to do because
874 if we temporarily ignored the watchpoint, then when
875 we reenter the block in which it is valid it contains
876 garbage (in the case of a function, it may have two
877 garbage values, one before and one after the prologue).
878 So we can't even detect the first assignment to it and
879 watch after that (since the garbage may or may not equal
880 the first value assigned). */
881 b->enable = disabled;
882 printf_filtered ("\
883 Watchpoint %d disabled because the program has left the block in\n\
884 which its expression is valid.\n", b->number);
885 /* We won't stop here */
886 /* FIXME, maybe we should stop here!!! */
887 continue;
888 }
889 }
890 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
891 else
892 real_breakpoint = 1;
893 #endif
894
895 if (b->frame && b->frame != frame_address)
896 this_bp_stop = 0;
897 else
898 {
899 int value_is_zero;
900
901 if (b->cond)
902 {
903 /* Need to select the frame, with all that implies
904 so that the conditions will have the right context. */
905 select_frame (get_current_frame (), 0);
906 value_is_zero
907 = catch_errors (breakpoint_cond_eval, (char *)(b->cond),
908 "Error in testing breakpoint condition:\n");
909 /* FIXME-someday, should give breakpoint # */
910 free_all_values ();
911 }
912 if (b->cond && value_is_zero)
913 {
914 this_bp_stop = 0;
915 }
916 else if (b->ignore_count > 0)
917 {
918 b->ignore_count--;
919 this_bp_stop = 0;
920 }
921 else
922 {
923 /* We will stop here */
924 if (b->disposition == disable)
925 b->enable = disabled;
926 bs->commands = b->commands;
927 if (b->silent)
928 this_bp_print = 0;
929 if (bs->commands && !strcmp ("silent", bs->commands->line))
930 {
931 bs->commands = bs->commands->next;
932 this_bp_print = 0;
933 }
934 }
935 }
936 if (this_bp_stop)
937 stop = 1;
938 if (this_bp_print)
939 print = 1;
940 }
941
942 bs->next = NULL; /* Terminate the chain */
943 bs = root_bs->next; /* Re-grab the head of the chain */
944 if (bs)
945 {
946 bs->stop = stop;
947 bs->print = print;
948 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
949 if (real_breakpoint)
950 {
951 *pc = bp_addr;
952 #if defined (SHIFT_INST_REGS)
953 {
954 CORE_ADDR pc = read_register (PC_REGNUM);
955 CORE_ADDR npc = read_register (NPC_REGNUM);
956 if (pc != npc)
957 {
958 write_register (NNPC_REGNUM, npc);
959 write_register (NPC_REGNUM, pc);
960 }
961 }
962 #else /* No SHIFT_INST_REGS. */
963 write_pc (bp_addr);
964 #endif /* No SHIFT_INST_REGS. */
965 }
966 #endif /* DECR_PC_AFTER_BREAK != 0. */
967 }
968 return bs;
969 }
970
971 /* Nonzero if we should step constantly (e.g. watchpoints on machines
972 without hardware support). This isn't related to a specific bpstat,
973 just to things like whether watchpoints are set. */
974
975 int
976 bpstat_should_step ()
977 {
978 struct breakpoint *b;
979 ALL_BREAKPOINTS (b)
980 if (b->enable == enabled && b->type == bp_watchpoint)
981 return 1;
982 return 0;
983 }
984 \f
985 /* Print information on breakpoint number BNUM, or -1 if all.
986 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
987 is nonzero, process only watchpoints. */
988
989 static void
990 breakpoint_1 (bnum, type)
991 int bnum;
992 enum bptype type;
993 {
994 register struct breakpoint *b;
995 register struct command_line *l;
996 register struct symbol *sym;
997 CORE_ADDR last_addr = (CORE_ADDR)-1;
998 int found_a_breakpoint = 0;
999 static char *bptypes[] = {"breakpoint", "until", "finish", "watchpoint",
1000 "longjmp", "longjmp resume"};
1001 static char *bpdisps[] = {"del", "dis", ""};
1002 static char bpenables[] = "ny";
1003
1004 if (!breakpoint_chain)
1005 {
1006 printf_filtered ("No breakpoints or watchpoints.\n");
1007 return;
1008 }
1009
1010 ALL_BREAKPOINTS (b)
1011 if (bnum == -1
1012 || bnum == b->number)
1013 {
1014 if (!found_a_breakpoint++)
1015 printf_filtered ("Num Type Disp Enb %sWhat\n",
1016 addressprint ? "Address " : "");
1017
1018 printf_filtered ("%-3d %-10s %-4s %-3c ",
1019 b->number,
1020 bptypes[b->type],
1021 bpdisps[b->disposition],
1022 bpenables[b->enable]);
1023 switch (b->type)
1024 {
1025 case bp_watchpoint:
1026 print_expression (b->exp, stdout);
1027 break;
1028 case bp_breakpoint:
1029 if (addressprint)
1030 printf_filtered ("%s ", local_hex_string_custom(b->address, "08"));
1031
1032 last_addr = b->address;
1033 if (b->symtab)
1034 {
1035 sym = find_pc_function (b->address);
1036 if (sym)
1037 {
1038 fputs_filtered ("in ", stdout);
1039 fputs_demangled (SYMBOL_NAME (sym), stdout, 1);
1040 fputs_filtered (" at ", stdout);
1041 }
1042 fputs_filtered (b->symtab->filename, stdout);
1043 printf_filtered (":%d", b->line_number);
1044 }
1045 else
1046 print_address_symbolic (b->address, stdout, demangle, " ");
1047 }
1048
1049 printf_filtered ("\n");
1050
1051 if (b->frame)
1052 printf_filtered ("\tstop only in stack frame at %s\n",
1053 local_hex_string(b->frame));
1054 if (b->cond)
1055 {
1056 printf_filtered ("\tstop only if ");
1057 print_expression (b->cond, stdout);
1058 printf_filtered ("\n");
1059 }
1060 if (b->ignore_count)
1061 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
1062 if ((l = b->commands))
1063 while (l)
1064 {
1065 fputs_filtered ("\t", stdout);
1066 fputs_filtered (l->line, stdout);
1067 fputs_filtered ("\n", stdout);
1068 l = l->next;
1069 }
1070 }
1071
1072 if (!found_a_breakpoint
1073 && bnum != -1)
1074 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
1075 else
1076 /* Compare against (CORE_ADDR)-1 in case some compiler decides
1077 that a comparison of an unsigned with -1 is always false. */
1078 if (last_addr != (CORE_ADDR)-1)
1079 set_next_address (last_addr);
1080 }
1081
1082 /* ARGSUSED */
1083 static void
1084 breakpoints_info (bnum_exp, from_tty)
1085 char *bnum_exp;
1086 int from_tty;
1087 {
1088 int bnum = -1;
1089
1090 if (bnum_exp)
1091 bnum = parse_and_eval_address (bnum_exp);
1092
1093 breakpoint_1 (bnum, bp_breakpoint);
1094 }
1095
1096 /* ARGSUSED */
1097 static void
1098 watchpoints_info (bnum_exp, from_tty)
1099 char *bnum_exp;
1100 int from_tty;
1101 {
1102 int bnum = -1;
1103
1104 if (bnum_exp)
1105 bnum = parse_and_eval_address (bnum_exp);
1106
1107 breakpoint_1 (bnum, bp_watchpoint);
1108 }
1109
1110 /* Print a message describing any breakpoints set at PC. */
1111
1112 static void
1113 describe_other_breakpoints (pc)
1114 register CORE_ADDR pc;
1115 {
1116 register int others = 0;
1117 register struct breakpoint *b;
1118
1119 ALL_BREAKPOINTS (b)
1120 if (b->address == pc)
1121 others++;
1122 if (others > 0)
1123 {
1124 printf ("Note: breakpoint%s ", (others > 1) ? "s" : "");
1125 ALL_BREAKPOINTS (b)
1126 if (b->address == pc)
1127 {
1128 others--;
1129 printf ("%d%s%s ",
1130 b->number,
1131 (b->enable == disabled) ? " (disabled)" : "",
1132 (others > 1) ? "," : ((others == 1) ? " and" : ""));
1133 }
1134 printf ("also set at pc %s.\n", local_hex_string(pc));
1135 }
1136 }
1137 \f
1138 /* Set the default place to put a breakpoint
1139 for the `break' command with no arguments. */
1140
1141 void
1142 set_default_breakpoint (valid, addr, symtab, line)
1143 int valid;
1144 CORE_ADDR addr;
1145 struct symtab *symtab;
1146 int line;
1147 {
1148 default_breakpoint_valid = valid;
1149 default_breakpoint_address = addr;
1150 default_breakpoint_symtab = symtab;
1151 default_breakpoint_line = line;
1152 }
1153
1154 /* Rescan breakpoints at address ADDRESS,
1155 marking the first one as "first" and any others as "duplicates".
1156 This is so that the bpt instruction is only inserted once. */
1157
1158 static void
1159 check_duplicates (address)
1160 CORE_ADDR address;
1161 {
1162 register struct breakpoint *b;
1163 register int count = 0;
1164
1165 if (address == 0) /* Watchpoints are uninteresting */
1166 return;
1167
1168 ALL_BREAKPOINTS (b)
1169 if (b->enable != disabled && b->address == address)
1170 {
1171 count++;
1172 b->duplicate = count > 1;
1173 }
1174 }
1175
1176 /* Low level routine to set a breakpoint.
1177 Takes as args the three things that every breakpoint must have.
1178 Returns the breakpoint object so caller can set other things.
1179 Does not set the breakpoint number!
1180 Does not print anything.
1181
1182 ==> This routine should not be called if there is a chance of later
1183 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
1184 your arguments BEFORE calling this routine! */
1185
1186 static struct breakpoint *
1187 set_raw_breakpoint (sal)
1188 struct symtab_and_line sal;
1189 {
1190 register struct breakpoint *b, *b1;
1191
1192 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
1193 bzero (b, sizeof *b);
1194 b->address = sal.pc;
1195 b->symtab = sal.symtab;
1196 b->line_number = sal.line;
1197 b->enable = enabled;
1198 b->next = 0;
1199 b->silent = 0;
1200 b->ignore_count = 0;
1201 b->commands = NULL;
1202 b->frame = 0;
1203
1204 /* Add this breakpoint to the end of the chain
1205 so that a list of breakpoints will come out in order
1206 of increasing numbers. */
1207
1208 b1 = breakpoint_chain;
1209 if (b1 == 0)
1210 breakpoint_chain = b;
1211 else
1212 {
1213 while (b1->next)
1214 b1 = b1->next;
1215 b1->next = b;
1216 }
1217
1218 check_duplicates (sal.pc);
1219
1220 return b;
1221 }
1222
1223 struct breakpoint *longjmp_breakpoint = NULL;
1224 struct breakpoint *_longjmp_breakpoint = NULL;
1225 struct breakpoint *siglongjmp_breakpoint = NULL;
1226 struct breakpoint *longjmp_resume_breakpoint = NULL;
1227
1228 static void
1229 create_longjmp_breakpoint_1(func_name, bpt)
1230 char *func_name;
1231 struct breakpoint **bpt;
1232 {
1233 int i;
1234 struct symtab_and_line sal;
1235 struct breakpoint *b;
1236
1237 if (*bpt != NULL)
1238 {
1239 delete_breakpoint(*bpt);
1240 *bpt = NULL;
1241 }
1242
1243 if (func_name != NULL)
1244 {
1245 struct minimal_symbol *m;
1246
1247 m = lookup_minimal_symbol(func_name, (struct objfile *)NULL);
1248 if (m)
1249 sal.pc = m->address;
1250 else
1251 return;
1252 }
1253 else
1254 sal.pc = 0;
1255
1256 sal.symtab = NULL;
1257 sal.line = 0;
1258 if (*bpt != NULL)
1259 b = *bpt;
1260 else
1261 b = set_raw_breakpoint(sal);
1262
1263 if (!b) return;
1264
1265 b->type = bp_longjmp;
1266 b->disposition = donttouch;
1267 b->enable = disabled;
1268 b->silent = 1;
1269 *bpt = b;
1270 }
1271
1272 /* Call this routine each time we read a new executable or symbol table
1273 file. */
1274
1275 #ifdef GET_LONGJMP_TARGET
1276 void
1277 create_longjmp_breakpoint()
1278 {
1279 create_longjmp_breakpoint_1("longjmp", &longjmp_breakpoint);
1280 create_longjmp_breakpoint_1("_longjmp", &_longjmp_breakpoint);
1281 create_longjmp_breakpoint_1("siglongjmp", &siglongjmp_breakpoint);
1282
1283 if ((longjmp_breakpoint || _longjmp_breakpoint || siglongjmp_breakpoint)
1284 && !longjmp_resume_breakpoint)
1285 {
1286 create_longjmp_breakpoint_1(NULL, &longjmp_resume_breakpoint);
1287 if (longjmp_resume_breakpoint)
1288 longjmp_resume_breakpoint->type = bp_longjmp_resume;
1289 }
1290 }
1291 #else
1292 void
1293 create_longjmp_breakpoint()
1294 {
1295 }
1296 #endif
1297
1298 /* Call this routine when stepping and nexting to enable a breakpoint if we do
1299 a longjmp(). When we hit that breakpoint, call
1300 set_longjmp_resume_breakpoint() to figure out where we are going. */
1301
1302 void
1303 enable_longjmp_breakpoint()
1304 {
1305 if (longjmp_breakpoint)
1306 longjmp_breakpoint->enable = enabled;
1307 if (_longjmp_breakpoint)
1308 _longjmp_breakpoint->enable = enabled;
1309 if (siglongjmp_breakpoint)
1310 siglongjmp_breakpoint->enable = enabled;
1311 }
1312
1313 void
1314 disable_longjmp_breakpoint()
1315 {
1316 if (longjmp_breakpoint)
1317 longjmp_breakpoint->enable = disabled;
1318 if (_longjmp_breakpoint)
1319 _longjmp_breakpoint->enable = disabled;
1320 if (siglongjmp_breakpoint)
1321 siglongjmp_breakpoint->enable = disabled;
1322 if (longjmp_resume_breakpoint)
1323 longjmp_resume_breakpoint->enable = disabled;
1324 }
1325
1326 /* Call this after hitting the longjmp() breakpoint. Use this to set a new
1327 breakpoint at the target of the jmp_buf.
1328 */
1329
1330 void
1331 set_longjmp_resume_breakpoint(pc, frame)
1332 CORE_ADDR pc;
1333 FRAME frame;
1334 {
1335 longjmp_resume_breakpoint->address = pc;
1336 longjmp_resume_breakpoint->enable = enabled;
1337 if (frame != NULL)
1338 longjmp_resume_breakpoint->frame = FRAME_FP(frame);
1339 else
1340 longjmp_resume_breakpoint->frame = 0;
1341 }
1342
1343 /* Set a breakpoint that will evaporate an end of command
1344 at address specified by SAL.
1345 Restrict it to frame FRAME if FRAME is nonzero. */
1346
1347 struct breakpoint *
1348 set_momentary_breakpoint (sal, frame, type)
1349 struct symtab_and_line sal;
1350 FRAME frame;
1351 enum bptype type;
1352 {
1353 register struct breakpoint *b;
1354 b = set_raw_breakpoint (sal);
1355 b->type = type;
1356 b->enable = enabled;
1357 b->disposition = donttouch;
1358 b->frame = (frame ? FRAME_FP (frame) : 0);
1359 return b;
1360 }
1361
1362 #if 0
1363 void
1364 clear_momentary_breakpoints ()
1365 {
1366 register struct breakpoint *b;
1367 ALL_BREAKPOINTS (b)
1368 if (b->disposition == delete)
1369 {
1370 delete_breakpoint (b);
1371 break;
1372 }
1373 }
1374 #endif
1375 \f
1376 /* Tell the user we have just set a breakpoint B. */
1377 static void
1378 mention (b)
1379 struct breakpoint *b;
1380 {
1381 switch (b->type)
1382 {
1383 case bp_watchpoint:
1384 printf_filtered ("Watchpoint %d: ", b->number);
1385 print_expression (b->exp, stdout);
1386 break;
1387 case bp_breakpoint:
1388 printf_filtered ("Breakpoint %d at %s", b->number,
1389 local_hex_string(b->address));
1390 if (b->symtab)
1391 printf_filtered (": file %s, line %d.",
1392 b->symtab->filename, b->line_number);
1393 }
1394 printf_filtered ("\n");
1395 }
1396
1397 #if 0
1398 /* Nobody calls this currently. */
1399 /* Set a breakpoint from a symtab and line.
1400 If TEMPFLAG is nonzero, it is a temporary breakpoint.
1401 ADDR_STRING is a malloc'd string holding the name of where we are
1402 setting the breakpoint. This is used later to re-set it after the
1403 program is relinked and symbols are reloaded.
1404 Print the same confirmation messages that the breakpoint command prints. */
1405
1406 void
1407 set_breakpoint (s, line, tempflag, addr_string)
1408 struct symtab *s;
1409 int line;
1410 int tempflag;
1411 char *addr_string;
1412 {
1413 register struct breakpoint *b;
1414 struct symtab_and_line sal;
1415
1416 sal.symtab = s;
1417 sal.line = line;
1418 sal.pc = 0;
1419 resolve_sal_pc (&sal); /* Might error out */
1420 describe_other_breakpoints (sal.pc);
1421
1422 b = set_raw_breakpoint (sal);
1423 set_breakpoint_count (breakpoint_count + 1);
1424 b->number = breakpoint_count;
1425 b->type = bp_breakpoint;
1426 b->cond = 0;
1427 b->addr_string = addr_string;
1428 b->enable = enabled;
1429 b->disposition = tempflag ? delete : donttouch;
1430
1431 mention (b);
1432 }
1433 #endif /* 0 */
1434 \f
1435 /* Set a breakpoint according to ARG (function, linenum or *address)
1436 and make it temporary if TEMPFLAG is nonzero. */
1437
1438 static void
1439 break_command_1 (arg, tempflag, from_tty)
1440 char *arg;
1441 int tempflag, from_tty;
1442 {
1443 struct symtabs_and_lines sals;
1444 struct symtab_and_line sal;
1445 register struct expression *cond = 0;
1446 register struct breakpoint *b;
1447
1448 /* Pointers in arg to the start, and one past the end, of the condition. */
1449 char *cond_start = NULL;
1450 char *cond_end;
1451 /* Pointers in arg to the start, and one past the end,
1452 of the address part. */
1453 char *addr_start = NULL;
1454 char *addr_end;
1455
1456 int i;
1457
1458 sals.sals = NULL;
1459 sals.nelts = 0;
1460
1461 sal.line = sal.pc = sal.end = 0;
1462 sal.symtab = 0;
1463
1464 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
1465
1466 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1467 && (arg[2] == ' ' || arg[2] == '\t')))
1468 {
1469 if (default_breakpoint_valid)
1470 {
1471 sals.sals = (struct symtab_and_line *)
1472 xmalloc (sizeof (struct symtab_and_line));
1473 sal.pc = default_breakpoint_address;
1474 sal.line = default_breakpoint_line;
1475 sal.symtab = default_breakpoint_symtab;
1476 sals.sals[0] = sal;
1477 sals.nelts = 1;
1478 }
1479 else
1480 error ("No default breakpoint address now.");
1481 }
1482 else
1483 {
1484 addr_start = arg;
1485
1486 /* Force almost all breakpoints to be in terms of the
1487 current_source_symtab (which is decode_line_1's default). This
1488 should produce the results we want almost all of the time while
1489 leaving default_breakpoint_* alone. */
1490 if (default_breakpoint_valid
1491 && (!current_source_symtab
1492 || (arg && (*arg == '+' || *arg == '-'))))
1493 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1494 default_breakpoint_line);
1495 else
1496 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1497
1498 addr_end = arg;
1499 }
1500
1501 if (! sals.nelts)
1502 return;
1503
1504 /* Resolve all line numbers to PC's, and verify that conditions
1505 can be parsed, before setting any breakpoints. */
1506 for (i = 0; i < sals.nelts; i++)
1507 {
1508 resolve_sal_pc (&sals.sals[i]);
1509
1510 while (arg && *arg)
1511 {
1512 if (arg[0] == 'i' && arg[1] == 'f'
1513 && (arg[2] == ' ' || arg[2] == '\t'))
1514 {
1515 arg += 2;
1516 cond_start = arg;
1517 cond = parse_exp_1 (&arg, block_for_pc (sals.sals[i].pc), 0);
1518 cond_end = arg;
1519 }
1520 else
1521 error ("Junk at end of arguments.");
1522 }
1523 }
1524
1525 /* Now set all the breakpoints. */
1526 for (i = 0; i < sals.nelts; i++)
1527 {
1528 sal = sals.sals[i];
1529
1530 if (from_tty)
1531 describe_other_breakpoints (sal.pc);
1532
1533 b = set_raw_breakpoint (sal);
1534 set_breakpoint_count (breakpoint_count + 1);
1535 b->number = breakpoint_count;
1536 b->type = bp_breakpoint;
1537 b->cond = cond;
1538
1539 if (addr_start)
1540 b->addr_string = savestring (addr_start, addr_end - addr_start);
1541 if (cond_start)
1542 b->cond_string = savestring (cond_start, cond_end - cond_start);
1543
1544 b->enable = enabled;
1545 b->disposition = tempflag ? delete : donttouch;
1546
1547 mention (b);
1548 }
1549
1550 if (sals.nelts > 1)
1551 {
1552 printf ("Multiple breakpoints were set.\n");
1553 printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1554 }
1555 free (sals.sals);
1556 }
1557
1558 /* Helper function for break_command_1 and disassemble_command. */
1559
1560 void
1561 resolve_sal_pc (sal)
1562 struct symtab_and_line *sal;
1563 {
1564 CORE_ADDR pc;
1565
1566 if (sal->pc == 0 && sal->symtab != 0)
1567 {
1568 pc = find_line_pc (sal->symtab, sal->line);
1569 if (pc == 0)
1570 error ("No line %d in file \"%s\".",
1571 sal->line, sal->symtab->filename);
1572 sal->pc = pc;
1573 }
1574 }
1575
1576 void
1577 break_command (arg, from_tty)
1578 char *arg;
1579 int from_tty;
1580 {
1581 break_command_1 (arg, 0, from_tty);
1582 }
1583
1584 static void
1585 tbreak_command (arg, from_tty)
1586 char *arg;
1587 int from_tty;
1588 {
1589 break_command_1 (arg, 1, from_tty);
1590 }
1591
1592 /* ARGSUSED */
1593 static void
1594 watch_command (arg, from_tty)
1595 char *arg;
1596 int from_tty;
1597 {
1598 struct breakpoint *b;
1599 struct symtab_and_line sal;
1600 struct expression *exp;
1601 struct block *exp_valid_block;
1602 struct value *val;
1603
1604 sal.pc = 0;
1605 sal.symtab = NULL;
1606 sal.line = 0;
1607
1608 /* Parse arguments. */
1609 innermost_block = NULL;
1610 exp = parse_expression (arg);
1611 exp_valid_block = innermost_block;
1612 val = evaluate_expression (exp);
1613 release_value (val);
1614
1615 /* Now set up the breakpoint. */
1616 b = set_raw_breakpoint (sal);
1617 set_breakpoint_count (breakpoint_count + 1);
1618 b->number = breakpoint_count;
1619 b->type = bp_watchpoint;
1620 b->disposition = donttouch;
1621 b->exp = exp;
1622 b->exp_valid_block = exp_valid_block;
1623 b->val = val;
1624 b->cond = 0;
1625 b->cond_string = NULL;
1626 mention (b);
1627 }
1628 \f
1629 /*
1630 * Helper routine for the until_command routine in infcmd.c. Here
1631 * because it uses the mechanisms of breakpoints.
1632 */
1633 /* ARGSUSED */
1634 void
1635 until_break_command (arg, from_tty)
1636 char *arg;
1637 int from_tty;
1638 {
1639 struct symtabs_and_lines sals;
1640 struct symtab_and_line sal;
1641 FRAME prev_frame = get_prev_frame (selected_frame);
1642 struct breakpoint *breakpoint;
1643 struct cleanup *old_chain;
1644
1645 clear_proceed_status ();
1646
1647 /* Set a breakpoint where the user wants it and at return from
1648 this function */
1649
1650 if (default_breakpoint_valid)
1651 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1652 default_breakpoint_line);
1653 else
1654 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1655
1656 if (sals.nelts != 1)
1657 error ("Couldn't get information on specified line.");
1658
1659 sal = sals.sals[0];
1660 free (sals.sals); /* malloc'd, so freed */
1661
1662 if (*arg)
1663 error ("Junk at end of arguments.");
1664
1665 resolve_sal_pc (&sal);
1666
1667 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
1668
1669 old_chain = make_cleanup(delete_breakpoint, breakpoint);
1670
1671 /* Keep within the current frame */
1672
1673 if (prev_frame)
1674 {
1675 struct frame_info *fi;
1676
1677 fi = get_frame_info (prev_frame);
1678 sal = find_pc_line (fi->pc, 0);
1679 sal.pc = fi->pc;
1680 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
1681 make_cleanup(delete_breakpoint, breakpoint);
1682 }
1683
1684 proceed (-1, -1, 0);
1685 do_cleanups(old_chain);
1686 }
1687 \f
1688 #if 0
1689 /* These aren't used; I don't konw what they were for. */
1690 /* Set a breakpoint at the catch clause for NAME. */
1691 static int
1692 catch_breakpoint (name)
1693 char *name;
1694 {
1695 }
1696
1697 static int
1698 disable_catch_breakpoint ()
1699 {
1700 }
1701
1702 static int
1703 delete_catch_breakpoint ()
1704 {
1705 }
1706
1707 static int
1708 enable_catch_breakpoint ()
1709 {
1710 }
1711 #endif /* 0 */
1712
1713 struct sal_chain
1714 {
1715 struct sal_chain *next;
1716 struct symtab_and_line sal;
1717 };
1718
1719 #if 0
1720 /* This isn't used; I don't know what it was for. */
1721 /* For each catch clause identified in ARGS, run FUNCTION
1722 with that clause as an argument. */
1723 static struct symtabs_and_lines
1724 map_catch_names (args, function)
1725 char *args;
1726 int (*function)();
1727 {
1728 register char *p = args;
1729 register char *p1;
1730 struct symtabs_and_lines sals;
1731 #if 0
1732 struct sal_chain *sal_chain = 0;
1733 #endif
1734
1735 if (p == 0)
1736 error_no_arg ("one or more catch names");
1737
1738 sals.nelts = 0;
1739 sals.sals = NULL;
1740
1741 while (*p)
1742 {
1743 p1 = p;
1744 /* Don't swallow conditional part. */
1745 if (p1[0] == 'i' && p1[1] == 'f'
1746 && (p1[2] == ' ' || p1[2] == '\t'))
1747 break;
1748
1749 if (isalpha (*p1))
1750 {
1751 p1++;
1752 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
1753 p1++;
1754 }
1755
1756 if (*p1 && *p1 != ' ' && *p1 != '\t')
1757 error ("Arguments must be catch names.");
1758
1759 *p1 = 0;
1760 #if 0
1761 if (function (p))
1762 {
1763 struct sal_chain *next
1764 = (struct sal_chain *)alloca (sizeof (struct sal_chain));
1765 next->next = sal_chain;
1766 next->sal = get_catch_sal (p);
1767 sal_chain = next;
1768 goto win;
1769 }
1770 #endif
1771 printf ("No catch clause for exception %s.\n", p);
1772 #if 0
1773 win:
1774 #endif
1775 p = p1;
1776 while (*p == ' ' || *p == '\t') p++;
1777 }
1778 }
1779 #endif /* 0 */
1780
1781 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
1782
1783 static struct symtabs_and_lines
1784 get_catch_sals (this_level_only)
1785 int this_level_only;
1786 {
1787 register struct blockvector *bl;
1788 register struct block *block;
1789 int index, have_default = 0;
1790 struct frame_info *fi;
1791 CORE_ADDR pc;
1792 struct symtabs_and_lines sals;
1793 struct sal_chain *sal_chain = 0;
1794 char *blocks_searched;
1795
1796 /* Not sure whether an error message is always the correct response,
1797 but it's better than a core dump. */
1798 if (selected_frame == NULL)
1799 error ("No selected frame.");
1800 block = get_frame_block (selected_frame);
1801 fi = get_frame_info (selected_frame);
1802 pc = fi->pc;
1803
1804 sals.nelts = 0;
1805 sals.sals = NULL;
1806
1807 if (block == 0)
1808 error ("No symbol table info available.\n");
1809
1810 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
1811 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1812 bzero (blocks_searched, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1813
1814 while (block != 0)
1815 {
1816 CORE_ADDR end = BLOCK_END (block) - 4;
1817 int last_index;
1818
1819 if (bl != blockvector_for_pc (end, &index))
1820 error ("blockvector blotch");
1821 if (BLOCKVECTOR_BLOCK (bl, index) != block)
1822 error ("blockvector botch");
1823 last_index = BLOCKVECTOR_NBLOCKS (bl);
1824 index += 1;
1825
1826 /* Don't print out blocks that have gone by. */
1827 while (index < last_index
1828 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
1829 index++;
1830
1831 while (index < last_index
1832 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
1833 {
1834 if (blocks_searched[index] == 0)
1835 {
1836 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
1837 int nsyms;
1838 register int i;
1839 register struct symbol *sym;
1840
1841 nsyms = BLOCK_NSYMS (b);
1842
1843 for (i = 0; i < nsyms; i++)
1844 {
1845 sym = BLOCK_SYM (b, i);
1846 if (! strcmp (SYMBOL_NAME (sym), "default"))
1847 {
1848 if (have_default)
1849 continue;
1850 have_default = 1;
1851 }
1852 if (SYMBOL_CLASS (sym) == LOC_LABEL)
1853 {
1854 struct sal_chain *next = (struct sal_chain *)
1855 alloca (sizeof (struct sal_chain));
1856 next->next = sal_chain;
1857 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
1858 sal_chain = next;
1859 }
1860 }
1861 blocks_searched[index] = 1;
1862 }
1863 index++;
1864 }
1865 if (have_default)
1866 break;
1867 if (sal_chain && this_level_only)
1868 break;
1869
1870 /* After handling the function's top-level block, stop.
1871 Don't continue to its superblock, the block of
1872 per-file symbols. */
1873 if (BLOCK_FUNCTION (block))
1874 break;
1875 block = BLOCK_SUPERBLOCK (block);
1876 }
1877
1878 if (sal_chain)
1879 {
1880 struct sal_chain *tmp_chain;
1881
1882 /* Count the number of entries. */
1883 for (index = 0, tmp_chain = sal_chain; tmp_chain;
1884 tmp_chain = tmp_chain->next)
1885 index++;
1886
1887 sals.nelts = index;
1888 sals.sals = (struct symtab_and_line *)
1889 xmalloc (index * sizeof (struct symtab_and_line));
1890 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
1891 sals.sals[index] = sal_chain->sal;
1892 }
1893
1894 return sals;
1895 }
1896
1897 /* Commands to deal with catching exceptions. */
1898
1899 static void
1900 catch_command_1 (arg, tempflag, from_tty)
1901 char *arg;
1902 int tempflag;
1903 int from_tty;
1904 {
1905 /* First, translate ARG into something we can deal with in terms
1906 of breakpoints. */
1907
1908 struct symtabs_and_lines sals;
1909 struct symtab_and_line sal;
1910 register struct expression *cond = 0;
1911 register struct breakpoint *b;
1912 char *save_arg;
1913 int i;
1914
1915 sal.line = sal.pc = sal.end = 0;
1916 sal.symtab = 0;
1917
1918 /* If no arg given, or if first arg is 'if ', all active catch clauses
1919 are breakpointed. */
1920
1921 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1922 && (arg[2] == ' ' || arg[2] == '\t')))
1923 {
1924 /* Grab all active catch clauses. */
1925 sals = get_catch_sals (0);
1926 }
1927 else
1928 {
1929 /* Grab selected catch clauses. */
1930 error ("catch NAME not implemeneted");
1931 #if 0
1932 /* This isn't used; I don't know what it was for. */
1933 sals = map_catch_names (arg, catch_breakpoint);
1934 #endif
1935 }
1936
1937 if (! sals.nelts)
1938 return;
1939
1940 save_arg = arg;
1941 for (i = 0; i < sals.nelts; i++)
1942 {
1943 resolve_sal_pc (&sals.sals[i]);
1944
1945 while (arg && *arg)
1946 {
1947 if (arg[0] == 'i' && arg[1] == 'f'
1948 && (arg[2] == ' ' || arg[2] == '\t'))
1949 cond = parse_exp_1 ((arg += 2, &arg),
1950 block_for_pc (sals.sals[i].pc), 0);
1951 else
1952 error ("Junk at end of arguments.");
1953 }
1954 arg = save_arg;
1955 }
1956
1957 for (i = 0; i < sals.nelts; i++)
1958 {
1959 sal = sals.sals[i];
1960
1961 if (from_tty)
1962 describe_other_breakpoints (sal.pc);
1963
1964 b = set_raw_breakpoint (sal);
1965 set_breakpoint_count (breakpoint_count + 1);
1966 b->number = breakpoint_count;
1967 b->type = bp_breakpoint;
1968 b->cond = cond;
1969 b->enable = enabled;
1970 b->disposition = tempflag ? delete : donttouch;
1971
1972 printf ("Breakpoint %d at %s", b->number, local_hex_string(b->address));
1973 if (b->symtab)
1974 printf (": file %s, line %d.", b->symtab->filename, b->line_number);
1975 printf ("\n");
1976 }
1977
1978 if (sals.nelts > 1)
1979 {
1980 printf ("Multiple breakpoints were set.\n");
1981 printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1982 }
1983 free (sals.sals);
1984 }
1985
1986 #if 0
1987 /* These aren't used; I don't know what they were for. */
1988 /* Disable breakpoints on all catch clauses described in ARGS. */
1989 static void
1990 disable_catch (args)
1991 char *args;
1992 {
1993 /* Map the disable command to catch clauses described in ARGS. */
1994 }
1995
1996 /* Enable breakpoints on all catch clauses described in ARGS. */
1997 static void
1998 enable_catch (args)
1999 char *args;
2000 {
2001 /* Map the disable command to catch clauses described in ARGS. */
2002 }
2003
2004 /* Delete breakpoints on all catch clauses in the active scope. */
2005 static void
2006 delete_catch (args)
2007 char *args;
2008 {
2009 /* Map the delete command to catch clauses described in ARGS. */
2010 }
2011 #endif /* 0 */
2012
2013 static void
2014 catch_command (arg, from_tty)
2015 char *arg;
2016 int from_tty;
2017 {
2018 catch_command_1 (arg, 0, from_tty);
2019 }
2020 \f
2021 static void
2022 clear_command (arg, from_tty)
2023 char *arg;
2024 int from_tty;
2025 {
2026 register struct breakpoint *b, *b1;
2027 struct symtabs_and_lines sals;
2028 struct symtab_and_line sal;
2029 register struct breakpoint *found;
2030 int i;
2031
2032 if (arg)
2033 {
2034 sals = decode_line_spec (arg, 1);
2035 }
2036 else
2037 {
2038 sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
2039 sal.line = default_breakpoint_line;
2040 sal.symtab = default_breakpoint_symtab;
2041 sal.pc = 0;
2042 if (sal.symtab == 0)
2043 error ("No source file specified.");
2044
2045 sals.sals[0] = sal;
2046 sals.nelts = 1;
2047 }
2048
2049 for (i = 0; i < sals.nelts; i++)
2050 {
2051 /* If exact pc given, clear bpts at that pc.
2052 But if sal.pc is zero, clear all bpts on specified line. */
2053 sal = sals.sals[i];
2054 found = (struct breakpoint *) 0;
2055 while (breakpoint_chain
2056 && (sal.pc ? breakpoint_chain->address == sal.pc
2057 : (breakpoint_chain->symtab == sal.symtab
2058 && breakpoint_chain->line_number == sal.line)))
2059 {
2060 b1 = breakpoint_chain;
2061 breakpoint_chain = b1->next;
2062 b1->next = found;
2063 found = b1;
2064 }
2065
2066 ALL_BREAKPOINTS (b)
2067 while (b->next
2068 && b->next->type != bp_watchpoint
2069 && (sal.pc ? b->next->address == sal.pc
2070 : (b->next->symtab == sal.symtab
2071 && b->next->line_number == sal.line)))
2072 {
2073 b1 = b->next;
2074 b->next = b1->next;
2075 b1->next = found;
2076 found = b1;
2077 }
2078
2079 if (found == 0)
2080 {
2081 if (arg)
2082 error ("No breakpoint at %s.", arg);
2083 else
2084 error ("No breakpoint at this line.");
2085 }
2086
2087 if (found->next) from_tty = 1; /* Always report if deleted more than one */
2088 if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : "");
2089 while (found)
2090 {
2091 if (from_tty) printf ("%d ", found->number);
2092 b1 = found->next;
2093 delete_breakpoint (found);
2094 found = b1;
2095 }
2096 if (from_tty) putchar ('\n');
2097 }
2098 free (sals.sals);
2099 }
2100 \f
2101 /* Delete breakpoint in BS if they are `delete' breakpoints.
2102 This is called after any breakpoint is hit, or after errors. */
2103
2104 void
2105 breakpoint_auto_delete (bs)
2106 bpstat bs;
2107 {
2108 for (; bs; bs = bs->next)
2109 if (bs->breakpoint_at && bs->breakpoint_at->disposition == delete)
2110 delete_breakpoint (bs->breakpoint_at);
2111 }
2112
2113 /* Delete a breakpoint and clean up all traces of it in the data structures. */
2114
2115 void
2116 delete_breakpoint (bpt)
2117 struct breakpoint *bpt;
2118 {
2119 register struct breakpoint *b;
2120 register bpstat bs;
2121
2122 if (bpt->inserted)
2123 target_remove_breakpoint(bpt->address, bpt->shadow_contents);
2124
2125 if (breakpoint_chain == bpt)
2126 breakpoint_chain = bpt->next;
2127
2128 ALL_BREAKPOINTS (b)
2129 if (b->next == bpt)
2130 {
2131 b->next = bpt->next;
2132 break;
2133 }
2134
2135 check_duplicates (bpt->address);
2136
2137 free_command_lines (&bpt->commands);
2138 if (bpt->cond)
2139 free (bpt->cond);
2140 if (bpt->cond_string != NULL)
2141 free (bpt->cond_string);
2142 if (bpt->addr_string != NULL)
2143 free (bpt->addr_string);
2144
2145 if (xgdb_verbose && bpt->type == bp_breakpoint)
2146 printf ("breakpoint #%d deleted\n", bpt->number);
2147
2148 /* Be sure no bpstat's are pointing at it after it's been freed. */
2149 /* FIXME, how can we find all bpstat's? We just check stop_bpstat for now. */
2150 for (bs = stop_bpstat; bs; bs = bs->next)
2151 if (bs->breakpoint_at == bpt)
2152 bs->breakpoint_at = NULL;
2153 free (bpt);
2154 }
2155
2156 static void
2157 delete_command (arg, from_tty)
2158 char *arg;
2159 int from_tty;
2160 {
2161
2162 if (arg == 0)
2163 {
2164 /* Ask user only if there are some breakpoints to delete. */
2165 if (!from_tty
2166 || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0)))
2167 {
2168 /* No arg; clear all breakpoints. */
2169 while (breakpoint_chain)
2170 delete_breakpoint (breakpoint_chain);
2171 }
2172 }
2173 else
2174 map_breakpoint_numbers (arg, delete_breakpoint);
2175 }
2176
2177 /* Reset a breakpoint given it's struct breakpoint * BINT.
2178 The value we return ends up being the return value from catch_errors.
2179 Unused in this case. */
2180
2181 static int
2182 breakpoint_re_set_one (bint)
2183 char *bint;
2184 {
2185 struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */
2186 int i;
2187 struct symtabs_and_lines sals;
2188 char *s;
2189 enum enable save_enable;
2190
2191 if (b->type != bp_watchpoint && b->addr_string != NULL)
2192 {
2193 /* In case we have a problem, disable this breakpoint. We'll restore
2194 its status if we succeed. */
2195 save_enable = b->enable;
2196 b->enable = disabled;
2197
2198 s = b->addr_string;
2199 sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0);
2200 for (i = 0; i < sals.nelts; i++)
2201 {
2202 resolve_sal_pc (&sals.sals[i]);
2203 b->symtab = sals.sals[i].symtab;
2204 b->line_number = sals.sals[i].line;
2205 b->address = sals.sals[i].pc;
2206
2207 if (b->cond_string != NULL)
2208 {
2209 s = b->cond_string;
2210 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
2211 }
2212
2213 check_duplicates (b->address);
2214
2215 b->enable = save_enable; /* Restore it, this worked. */
2216 mention (b);
2217 }
2218 free (sals.sals);
2219 }
2220 else
2221 {
2222 /* Anything without a string can't be re-set. */
2223 delete_breakpoint (b);
2224 }
2225 return 0;
2226 }
2227
2228 /* Re-set all breakpoints after symbols have been re-loaded. */
2229 void
2230 breakpoint_re_set ()
2231 {
2232 struct breakpoint *b;
2233 static char message1[] = "Error in re-setting breakpoint %d:\n";
2234 char message[sizeof (message1) + 30 /* slop */];
2235
2236 ALL_BREAKPOINTS (b)
2237 {
2238 b->symtab = 0; /* Be sure we don't point to old dead symtab */
2239 sprintf (message, message1, b->number); /* Format possible error msg */
2240 (void) catch_errors (breakpoint_re_set_one, (char *) b, message);
2241 }
2242
2243 /* Blank line to finish off all those mention() messages we just printed. */
2244 printf_filtered ("\n");
2245 }
2246 \f
2247 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
2248 If from_tty is nonzero, it prints a message to that effect,
2249 which ends with a period (no newline). */
2250
2251 void
2252 set_ignore_count (bptnum, count, from_tty)
2253 int bptnum, count, from_tty;
2254 {
2255 register struct breakpoint *b;
2256
2257 if (count < 0)
2258 count = 0;
2259
2260 ALL_BREAKPOINTS (b)
2261 if (b->number == bptnum)
2262 {
2263 b->ignore_count = count;
2264 if (!from_tty)
2265 return;
2266 else if (count == 0)
2267 printf ("Will stop next time breakpoint %d is reached.", bptnum);
2268 else if (count == 1)
2269 printf ("Will ignore next crossing of breakpoint %d.", bptnum);
2270 else
2271 printf ("Will ignore next %d crossings of breakpoint %d.",
2272 count, bptnum);
2273 return;
2274 }
2275
2276 error ("No breakpoint number %d.", bptnum);
2277 }
2278
2279 /* Clear the ignore counts of all breakpoints. */
2280 void
2281 breakpoint_clear_ignore_counts ()
2282 {
2283 struct breakpoint *b;
2284
2285 ALL_BREAKPOINTS (b)
2286 b->ignore_count = 0;
2287 }
2288
2289 /* Command to set ignore-count of breakpoint N to COUNT. */
2290
2291 static void
2292 ignore_command (args, from_tty)
2293 char *args;
2294 int from_tty;
2295 {
2296 char *p = args;
2297 register int num;
2298
2299 if (p == 0)
2300 error_no_arg ("a breakpoint number");
2301
2302 num = get_number (&p);
2303
2304 if (*p == 0)
2305 error ("Second argument (specified ignore-count) is missing.");
2306
2307 set_ignore_count (num,
2308 longest_to_int (value_as_long (parse_and_eval (p))),
2309 from_tty);
2310 printf ("\n");
2311 }
2312 \f
2313 /* Call FUNCTION on each of the breakpoints
2314 whose numbers are given in ARGS. */
2315
2316 static void
2317 map_breakpoint_numbers (args, function)
2318 char *args;
2319 void (*function) PARAMS ((struct breakpoint *));
2320 {
2321 register char *p = args;
2322 char *p1;
2323 register int num;
2324 register struct breakpoint *b;
2325
2326 if (p == 0)
2327 error_no_arg ("one or more breakpoint numbers");
2328
2329 while (*p)
2330 {
2331 p1 = p;
2332
2333 num = get_number (&p1);
2334
2335 ALL_BREAKPOINTS (b)
2336 if (b->number == num)
2337 {
2338 function (b);
2339 goto win;
2340 }
2341 printf ("No breakpoint number %d.\n", num);
2342 win:
2343 p = p1;
2344 }
2345 }
2346
2347 static void
2348 enable_breakpoint (bpt)
2349 struct breakpoint *bpt;
2350 {
2351 bpt->enable = enabled;
2352
2353 if (xgdb_verbose && bpt->type == bp_breakpoint)
2354 printf ("breakpoint #%d enabled\n", bpt->number);
2355
2356 check_duplicates (bpt->address);
2357 if (bpt->type == bp_watchpoint)
2358 {
2359 if (bpt->exp_valid_block != NULL
2360 && !contained_in (get_selected_block (), bpt->exp_valid_block))
2361 {
2362 printf_filtered ("\
2363 Cannot enable watchpoint %d because the block in which its expression\n\
2364 is valid is not currently in scope.\n", bpt->number);
2365 return;
2366 }
2367
2368 value_free (bpt->val);
2369
2370 bpt->val = evaluate_expression (bpt->exp);
2371 release_value (bpt->val);
2372 }
2373 }
2374
2375 /* ARGSUSED */
2376 static void
2377 enable_command (args, from_tty)
2378 char *args;
2379 int from_tty;
2380 {
2381 struct breakpoint *bpt;
2382 if (args == 0)
2383 ALL_BREAKPOINTS (bpt)
2384 enable_breakpoint (bpt);
2385 else
2386 map_breakpoint_numbers (args, enable_breakpoint);
2387 }
2388
2389 static void
2390 disable_breakpoint (bpt)
2391 struct breakpoint *bpt;
2392 {
2393 bpt->enable = disabled;
2394
2395 if (xgdb_verbose && bpt->type == bp_breakpoint)
2396 printf ("breakpoint #%d disabled\n", bpt->number);
2397
2398 check_duplicates (bpt->address);
2399 }
2400
2401 /* ARGSUSED */
2402 static void
2403 disable_command (args, from_tty)
2404 char *args;
2405 int from_tty;
2406 {
2407 register struct breakpoint *bpt;
2408 if (args == 0)
2409 ALL_BREAKPOINTS (bpt)
2410 disable_breakpoint (bpt);
2411 else
2412 map_breakpoint_numbers (args, disable_breakpoint);
2413 }
2414
2415 static void
2416 enable_once_breakpoint (bpt)
2417 struct breakpoint *bpt;
2418 {
2419 bpt->enable = enabled;
2420 bpt->disposition = disable;
2421
2422 check_duplicates (bpt->address);
2423 }
2424
2425 /* ARGSUSED */
2426 static void
2427 enable_once_command (args, from_tty)
2428 char *args;
2429 int from_tty;
2430 {
2431 map_breakpoint_numbers (args, enable_once_breakpoint);
2432 }
2433
2434 static void
2435 enable_delete_breakpoint (bpt)
2436 struct breakpoint *bpt;
2437 {
2438 bpt->enable = enabled;
2439 bpt->disposition = delete;
2440
2441 check_duplicates (bpt->address);
2442 }
2443
2444 /* ARGSUSED */
2445 static void
2446 enable_delete_command (args, from_tty)
2447 char *args;
2448 int from_tty;
2449 {
2450 map_breakpoint_numbers (args, enable_delete_breakpoint);
2451 }
2452 \f
2453 /*
2454 * Use default_breakpoint_'s, or nothing if they aren't valid.
2455 */
2456 struct symtabs_and_lines
2457 decode_line_spec_1 (string, funfirstline)
2458 char *string;
2459 int funfirstline;
2460 {
2461 struct symtabs_and_lines sals;
2462 if (string == 0)
2463 error ("Empty line specification.");
2464 if (default_breakpoint_valid)
2465 sals = decode_line_1 (&string, funfirstline,
2466 default_breakpoint_symtab, default_breakpoint_line);
2467 else
2468 sals = decode_line_1 (&string, funfirstline, (struct symtab *)NULL, 0);
2469 if (*string)
2470 error ("Junk at end of line specification: %s", string);
2471 return sals;
2472 }
2473 \f
2474
2475 /* Chain containing all defined enable commands. */
2476
2477 extern struct cmd_list_element
2478 *enablelist, *disablelist,
2479 *deletelist, *enablebreaklist;
2480
2481 extern struct cmd_list_element *cmdlist;
2482
2483 void
2484 _initialize_breakpoint ()
2485 {
2486 breakpoint_chain = 0;
2487 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
2488 before a breakpoint is set. */
2489 breakpoint_count = 0;
2490
2491 add_com ("ignore", class_breakpoint, ignore_command,
2492 "Set ignore-count of breakpoint number N to COUNT.");
2493
2494 add_com ("commands", class_breakpoint, commands_command,
2495 "Set commands to be executed when a breakpoint is hit.\n\
2496 Give breakpoint number as argument after \"commands\".\n\
2497 With no argument, the targeted breakpoint is the last one set.\n\
2498 The commands themselves follow starting on the next line.\n\
2499 Type a line containing \"end\" to indicate the end of them.\n\
2500 Give \"silent\" as the first line to make the breakpoint silent;\n\
2501 then no output is printed when it is hit, except what the commands print.");
2502
2503 add_com ("condition", class_breakpoint, condition_command,
2504 "Specify breakpoint number N to break only if COND is true.\n\
2505 N is an integer; COND is an expression to be evaluated whenever\n\
2506 breakpoint N is reached. ");
2507
2508 add_com ("tbreak", class_breakpoint, tbreak_command,
2509 "Set a temporary breakpoint. Args like \"break\" command.\n\
2510 Like \"break\" except the breakpoint is only enabled temporarily,\n\
2511 so it will be disabled when hit. Equivalent to \"break\" followed\n\
2512 by using \"enable once\" on the breakpoint number.");
2513
2514 add_prefix_cmd ("enable", class_breakpoint, enable_command,
2515 "Enable some breakpoints.\n\
2516 Give breakpoint numbers (separated by spaces) as arguments.\n\
2517 With no subcommand, breakpoints are enabled until you command otherwise.\n\
2518 This is used to cancel the effect of the \"disable\" command.\n\
2519 With a subcommand you can enable temporarily.",
2520 &enablelist, "enable ", 1, &cmdlist);
2521
2522 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
2523 "Enable some breakpoints.\n\
2524 Give breakpoint numbers (separated by spaces) as arguments.\n\
2525 This is used to cancel the effect of the \"disable\" command.\n\
2526 May be abbreviated to simply \"enable\".\n",
2527 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
2528
2529 add_cmd ("once", no_class, enable_once_command,
2530 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
2531 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2532 See the \"tbreak\" command which sets a breakpoint and enables it once.",
2533 &enablebreaklist);
2534
2535 add_cmd ("delete", no_class, enable_delete_command,
2536 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
2537 If a breakpoint is hit while enabled in this fashion, it is deleted.",
2538 &enablebreaklist);
2539
2540 add_cmd ("delete", no_class, enable_delete_command,
2541 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
2542 If a breakpoint is hit while enabled in this fashion, it is deleted.",
2543 &enablelist);
2544
2545 add_cmd ("once", no_class, enable_once_command,
2546 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
2547 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2548 See the \"tbreak\" command which sets a breakpoint and enables it once.",
2549 &enablelist);
2550
2551 add_prefix_cmd ("disable", class_breakpoint, disable_command,
2552 "Disable some breakpoints.\n\
2553 Arguments are breakpoint numbers with spaces in between.\n\
2554 To disable all breakpoints, give no argument.\n\
2555 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
2556 &disablelist, "disable ", 1, &cmdlist);
2557 add_com_alias ("dis", "disable", class_breakpoint, 1);
2558 add_com_alias ("disa", "disable", class_breakpoint, 1);
2559
2560 add_cmd ("breakpoints", class_alias, disable_command,
2561 "Disable some breakpoints.\n\
2562 Arguments are breakpoint numbers with spaces in between.\n\
2563 To disable all breakpoints, give no argument.\n\
2564 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
2565 This command may be abbreviated \"disable\".",
2566 &disablelist);
2567
2568 add_prefix_cmd ("delete", class_breakpoint, delete_command,
2569 "Delete some breakpoints or auto-display expressions.\n\
2570 Arguments are breakpoint numbers with spaces in between.\n\
2571 To delete all breakpoints, give no argument.\n\
2572 \n\
2573 Also a prefix command for deletion of other GDB objects.\n\
2574 The \"unset\" command is also an alias for \"delete\".",
2575 &deletelist, "delete ", 1, &cmdlist);
2576 add_com_alias ("d", "delete", class_breakpoint, 1);
2577
2578 add_cmd ("breakpoints", class_alias, delete_command,
2579 "Delete some breakpoints or auto-display expressions.\n\
2580 Arguments are breakpoint numbers with spaces in between.\n\
2581 To delete all breakpoints, give no argument.\n\
2582 This command may be abbreviated \"delete\".",
2583 &deletelist);
2584
2585 add_com ("clear", class_breakpoint, clear_command,
2586 "Clear breakpoint at specified line or function.\n\
2587 Argument may be line number, function name, or \"*\" and an address.\n\
2588 If line number is specified, all breakpoints in that line are cleared.\n\
2589 If function is specified, breakpoints at beginning of function are cleared.\n\
2590 If an address is specified, breakpoints at that address are cleared.\n\n\
2591 With no argument, clears all breakpoints in the line that the selected frame\n\
2592 is executing in.\n\
2593 \n\
2594 See also the \"delete\" command which clears breakpoints by number.");
2595
2596 add_com ("break", class_breakpoint, break_command,
2597 "Set breakpoint at specified line or function.\n\
2598 Argument may be line number, function name, or \"*\" and an address.\n\
2599 If line number is specified, break at start of code for that line.\n\
2600 If function is specified, break at start of code for that function.\n\
2601 If an address is specified, break at that exact address.\n\
2602 With no arg, uses current execution address of selected stack frame.\n\
2603 This is useful for breaking on return to a stack frame.\n\
2604 \n\
2605 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
2606 \n\
2607 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2608 add_com_alias ("b", "break", class_run, 1);
2609 add_com_alias ("br", "break", class_run, 1);
2610 add_com_alias ("bre", "break", class_run, 1);
2611 add_com_alias ("brea", "break", class_run, 1);
2612
2613 add_info ("breakpoints", breakpoints_info,
2614 "Status of all breakpoints, or breakpoint number NUMBER.\n\
2615 Second column is \"y\" for enabled breakpoint, \"n\" for disabled,\n\
2616 \"o\" for enabled once (disable when hit), \"d\" for enable but delete when hit.\n\
2617 Then come the address and the file/line number.\n\n\
2618 Convenience variable \"$_\" and default examine address for \"x\"\n\
2619 are set to the address of the last breakpoint listed.\n\n\
2620 Convenience variable \"$bpnum\" contains the number of the last\n\
2621 breakpoint set.");
2622
2623 add_com ("catch", class_breakpoint, catch_command,
2624 "Set breakpoints to catch exceptions that are raised.\n\
2625 Argument may be a single exception to catch, multiple exceptions\n\
2626 to catch, or the default exception \"default\". If no arguments\n\
2627 are given, breakpoints are set at all exception handlers catch clauses\n\
2628 within the current scope.\n\
2629 \n\
2630 A condition specified for the catch applies to all breakpoints set\n\
2631 with this command\n\
2632 \n\
2633 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2634
2635 add_com ("watch", class_breakpoint, watch_command,
2636 "Set a watchpoint for an expression.\n\
2637 A watchpoint stops execution of your program whenever the value of\n\
2638 an expression changes.");
2639
2640 add_info ("watchpoints", watchpoints_info,
2641 "Status of all watchpoints, or watchpoint number NUMBER.\n\
2642 Second column is \"y\" for enabled watchpoints, \"n\" for disabled.");
2643 }
This page took 0.078896 seconds and 5 git commands to generate.