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