]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/breakpoint.c
Fix many sins which will come up in 32 bit x 64 bit GDB, and
[thirdparty/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 "defs.h"
21 #include <ctype.h>
22 #include "symtab.h"
23 #include "frame.h"
24 #include "breakpoint.h"
25 #include "gdbtypes.h"
26 #include "expression.h"
27 #include "gdbcore.h"
28 #include "gdbcmd.h"
29 #include "value.h"
30 #include "ctype.h"
31 #include "command.h"
32 #include "inferior.h"
33 #include "thread.h"
34 #include "target.h"
35 #include "language.h"
36 #include <string.h>
37 #include "demangle.h"
38
39 /* local function prototypes */
40
41 static void
42 catch_command_1 PARAMS ((char *, int, int));
43
44 static void
45 enable_delete_command PARAMS ((char *, int));
46
47 static void
48 enable_delete_breakpoint PARAMS ((struct breakpoint *));
49
50 static void
51 enable_once_command PARAMS ((char *, int));
52
53 static void
54 enable_once_breakpoint PARAMS ((struct breakpoint *));
55
56 static void
57 disable_command PARAMS ((char *, int));
58
59 static void
60 disable_breakpoint PARAMS ((struct breakpoint *));
61
62 static void
63 enable_command PARAMS ((char *, int));
64
65 static void
66 enable_breakpoint PARAMS ((struct breakpoint *));
67
68 static void
69 map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *)));
70
71 static void
72 ignore_command PARAMS ((char *, int));
73
74 static int
75 breakpoint_re_set_one PARAMS ((char *));
76
77 static void
78 delete_command PARAMS ((char *, int));
79
80 static void
81 clear_command PARAMS ((char *, int));
82
83 static void
84 catch_command PARAMS ((char *, int));
85
86 static struct symtabs_and_lines
87 get_catch_sals PARAMS ((int));
88
89 static void
90 watch_command PARAMS ((char *, int));
91
92 static void
93 tbreak_command PARAMS ((char *, int));
94
95 static void
96 break_command_1 PARAMS ((char *, int, int));
97
98 static void
99 mention PARAMS ((struct breakpoint *));
100
101 static struct breakpoint *
102 set_raw_breakpoint PARAMS ((struct symtab_and_line));
103
104 static void
105 check_duplicates PARAMS ((CORE_ADDR));
106
107 static void
108 describe_other_breakpoints PARAMS ((CORE_ADDR));
109
110 static void
111 breakpoints_info PARAMS ((char *, int));
112
113 static void
114 breakpoint_1 PARAMS ((int, int));
115
116 static bpstat
117 bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
118
119 static int
120 breakpoint_cond_eval PARAMS ((char *));
121
122 static void
123 cleanup_executing_breakpoints PARAMS ((int));
124
125 static void
126 commands_command PARAMS ((char *, int));
127
128 static void
129 condition_command PARAMS ((char *, int));
130
131 static int
132 get_number PARAMS ((char **));
133
134 static void
135 set_breakpoint_count PARAMS ((int));
136
137
138 extern int addressprint; /* Print machine addresses? */
139 extern int demangle; /* Print de-mangled symbol names? */
140
141 /* Are we executing breakpoint commands? */
142 static int executing_breakpoint_commands;
143
144 /* Walk the following statement or block through all breakpoints.
145 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
146 breakpoint. */
147
148 #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
149
150 #define ALL_BREAKPOINTS_SAFE(b,tmp) \
151 for (b = breakpoint_chain; \
152 b? (tmp=b->next, 1): 0; \
153 b = tmp)
154
155 /* Chain of all breakpoints defined. */
156
157 static struct breakpoint *breakpoint_chain;
158
159 /* Number of last breakpoint made. */
160
161 static int breakpoint_count;
162
163 /* Set breakpoint count to NUM. */
164 static void
165 set_breakpoint_count (num)
166 int num;
167 {
168 breakpoint_count = num;
169 set_internalvar (lookup_internalvar ("bpnum"),
170 value_from_longest (builtin_type_int, (LONGEST) num));
171 }
172
173 /* Default address, symtab and line to put a breakpoint at
174 for "break" command with no arg.
175 if default_breakpoint_valid is zero, the other three are
176 not valid, and "break" with no arg is an error.
177
178 This set by print_stack_frame, which calls set_default_breakpoint. */
179
180 int default_breakpoint_valid;
181 CORE_ADDR default_breakpoint_address;
182 struct symtab *default_breakpoint_symtab;
183 int default_breakpoint_line;
184
185 /* Flag indicating extra verbosity for xgdb. */
186 extern int xgdb_verbose;
187 \f
188 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
189 Advance *PP after the string and any trailing whitespace.
190
191 Currently the string can either be a number or "$" followed by the name
192 of a convenience variable. Making it an expression wouldn't work well
193 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
194 static int
195 get_number (pp)
196 char **pp;
197 {
198 int retval;
199 char *p = *pp;
200
201 if (p == NULL)
202 /* Empty line means refer to the last breakpoint. */
203 return breakpoint_count;
204 else if (*p == '$')
205 {
206 /* Make a copy of the name, so we can null-terminate it
207 to pass to lookup_internalvar(). */
208 char *varname;
209 char *start = ++p;
210 value val;
211
212 while (isalnum (*p) || *p == '_')
213 p++;
214 varname = (char *) alloca (p - start + 1);
215 strncpy (varname, start, p - start);
216 varname[p - start] = '\0';
217 val = value_of_internalvar (lookup_internalvar (varname));
218 if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
219 error (
220 "Convenience variables used to specify breakpoints must have integer values."
221 );
222 retval = (int) value_as_long (val);
223 }
224 else
225 {
226 if (*p == '-')
227 ++p;
228 while (*p >= '0' && *p <= '9')
229 ++p;
230 if (p == *pp)
231 /* There is no number here. (e.g. "cond a == b"). */
232 error_no_arg ("breakpoint number");
233 retval = atoi (*pp);
234 }
235 if (!(isspace (*p) || *p == '\0'))
236 error ("breakpoint number expected");
237 while (isspace (*p))
238 p++;
239 *pp = p;
240 return retval;
241 }
242 \f
243 /* condition N EXP -- set break condition of breakpoint N to EXP. */
244
245 static void
246 condition_command (arg, from_tty)
247 char *arg;
248 int from_tty;
249 {
250 register struct breakpoint *b;
251 char *p;
252 register int bnum;
253
254 if (arg == 0)
255 error_no_arg ("breakpoint number");
256
257 p = arg;
258 bnum = get_number (&p);
259
260 ALL_BREAKPOINTS (b)
261 if (b->number == bnum)
262 {
263 if (b->cond)
264 {
265 free ((PTR)b->cond);
266 b->cond = 0;
267 }
268 if (b->cond_string != NULL)
269 free ((PTR)b->cond_string);
270
271 if (*p == 0)
272 {
273 b->cond = 0;
274 b->cond_string = NULL;
275 if (from_tty)
276 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
277 }
278 else
279 {
280 arg = p;
281 /* I don't know if it matters whether this is the string the user
282 typed in or the decompiled expression. */
283 b->cond_string = savestring (arg, strlen (arg));
284 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
285 if (*arg)
286 error ("Junk at end of expression");
287 }
288 return;
289 }
290
291 error ("No breakpoint number %d.", bnum);
292 }
293
294 /* ARGSUSED */
295 static void
296 commands_command (arg, from_tty)
297 char *arg;
298 int from_tty;
299 {
300 register struct breakpoint *b;
301 char *p;
302 register int bnum;
303 struct command_line *l;
304
305 /* If we allowed this, we would have problems with when to
306 free the storage, if we change the commands currently
307 being read from. */
308
309 if (executing_breakpoint_commands)
310 error ("Can't use the \"commands\" command among a breakpoint's commands.");
311
312 p = arg;
313 bnum = get_number (&p);
314 if (p && *p)
315 error ("Unexpected extra arguments following breakpoint number.");
316
317 ALL_BREAKPOINTS (b)
318 if (b->number == bnum)
319 {
320 if (from_tty && input_from_terminal_p ())
321 printf_filtered ("Type commands for when breakpoint %d is hit, one per line.\n\
322 End with a line saying just \"end\".\n", bnum);
323 l = read_command_lines ();
324 free_command_lines (&b->commands);
325 b->commands = l;
326 return;
327 }
328 error ("No breakpoint number %d.", bnum);
329 }
330 \f
331 extern int memory_breakpoint_size; /* from mem-break.c */
332
333 /* Like target_read_memory() but if breakpoints are inserted, return
334 the shadow contents instead of the breakpoints themselves.
335
336 Read "memory data" from whatever target or inferior we have.
337 Returns zero if successful, errno value if not. EIO is used
338 for address out of bounds. If breakpoints are inserted, returns
339 shadow contents, not the breakpoints themselves. From breakpoint.c. */
340
341 int
342 read_memory_nobpt (memaddr, myaddr, len)
343 CORE_ADDR memaddr;
344 char *myaddr;
345 unsigned len;
346 {
347 int status;
348 struct breakpoint *b;
349
350 if (memory_breakpoint_size < 0)
351 /* No breakpoints on this machine. FIXME: This should be
352 dependent on the debugging target. Probably want
353 target_insert_breakpoint to return a size, saying how many
354 bytes of the shadow contents are used, or perhaps have
355 something like target_xfer_shadow. */
356 return target_read_memory (memaddr, myaddr, len);
357
358 ALL_BREAKPOINTS (b)
359 {
360 if (b->type == bp_watchpoint || !b->inserted)
361 continue;
362 else if (b->address + memory_breakpoint_size <= memaddr)
363 /* The breakpoint is entirely before the chunk of memory
364 we are reading. */
365 continue;
366 else if (b->address >= memaddr + len)
367 /* The breakpoint is entirely after the chunk of memory we
368 are reading. */
369 continue;
370 else
371 {
372 /* Copy the breakpoint from the shadow contents, and recurse
373 for the things before and after. */
374
375 /* Addresses and length of the part of the breakpoint that
376 we need to copy. */
377 CORE_ADDR membpt = b->address;
378 unsigned int bptlen = memory_breakpoint_size;
379 /* Offset within shadow_contents. */
380 int bptoffset = 0;
381
382 if (membpt < memaddr)
383 {
384 /* Only copy the second part of the breakpoint. */
385 bptlen -= memaddr - membpt;
386 bptoffset = memaddr - membpt;
387 membpt = memaddr;
388 }
389
390 if (membpt + bptlen > memaddr + len)
391 {
392 /* Only copy the first part of the breakpoint. */
393 bptlen -= (membpt + bptlen) - (memaddr + len);
394 }
395
396 memcpy (myaddr + membpt - memaddr,
397 b->shadow_contents + bptoffset, bptlen);
398
399 if (membpt > memaddr)
400 {
401 /* Copy the section of memory before the breakpoint. */
402 status = read_memory_nobpt (memaddr, myaddr, membpt - memaddr);
403 if (status != 0)
404 return status;
405 }
406
407 if (membpt + bptlen < memaddr + len)
408 {
409 /* Copy the section of memory after the breakpoint. */
410 status = read_memory_nobpt
411 (membpt + bptlen,
412 myaddr + membpt + bptlen - memaddr,
413 memaddr + len - (membpt + bptlen));
414 if (status != 0)
415 return status;
416 }
417 return 0;
418 }
419 }
420 /* Nothing overlaps. Just call read_memory_noerr. */
421 return target_read_memory (memaddr, myaddr, len);
422 }
423 \f
424 /* insert_breakpoints is used when starting or continuing the program.
425 remove_breakpoints is used when the program stops.
426 Both return zero if successful,
427 or an `errno' value if could not write the inferior. */
428
429 int
430 insert_breakpoints ()
431 {
432 register struct breakpoint *b;
433 int val = 0;
434 int disabled_breaks = 0;
435
436 ALL_BREAKPOINTS (b)
437 if (b->type != bp_watchpoint
438 && b->enable != disabled
439 && ! b->inserted
440 && ! b->duplicate)
441 {
442 val = target_insert_breakpoint(b->address, b->shadow_contents);
443 if (val)
444 {
445 /* Can't set the breakpoint. */
446 #if defined (DISABLE_UNSETTABLE_BREAK)
447 if (DISABLE_UNSETTABLE_BREAK (b->address))
448 {
449 val = 0;
450 b->enable = disabled;
451 if (!disabled_breaks)
452 {
453 target_terminal_ours_for_output ();
454 fprintf_unfiltered (gdb_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 target_terminal_ours_for_output ();
465 fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number);
466 #ifdef ONE_PROCESS_WRITETEXT
467 fprintf_unfiltered (gdb_stderr,
468 "The same program may be running in another process.\n");
469 #endif
470 memory_error (val, b->address); /* which bombs us out */
471 }
472 }
473 else
474 b->inserted = 1;
475 }
476 if (disabled_breaks)
477 printf_filtered ("\n");
478 return val;
479 }
480
481 int
482 remove_breakpoints ()
483 {
484 register struct breakpoint *b;
485 int val;
486
487 ALL_BREAKPOINTS (b)
488 if (b->type != bp_watchpoint && b->inserted)
489 {
490 val = target_remove_breakpoint(b->address, b->shadow_contents);
491 if (val)
492 return val;
493 b->inserted = 0;
494 }
495
496 return 0;
497 }
498
499 /* Clear the "inserted" flag in all breakpoints. */
500
501 void
502 mark_breakpoints_out ()
503 {
504 register struct breakpoint *b;
505
506 ALL_BREAKPOINTS (b)
507 b->inserted = 0;
508 }
509
510 /* Clear the "inserted" flag in all breakpoints and delete any breakpoints
511 which should go away between runs of the program. */
512
513 void
514 breakpoint_init_inferior ()
515 {
516 register struct breakpoint *b, *temp;
517
518 ALL_BREAKPOINTS_SAFE (b, temp)
519 {
520 b->inserted = 0;
521
522 /* If the call dummy breakpoint is at the entry point it will
523 cause problems when the inferior is rerun, so we better
524 get rid of it. */
525 if (b->type == bp_call_dummy)
526 delete_breakpoint (b);
527 }
528 }
529
530 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
531 When continuing from a location with a breakpoint,
532 we actually single step once before calling insert_breakpoints. */
533
534 int
535 breakpoint_here_p (pc)
536 CORE_ADDR pc;
537 {
538 register struct breakpoint *b;
539
540 ALL_BREAKPOINTS (b)
541 if (b->enable != disabled && b->address == pc)
542 return 1;
543
544 return 0;
545 }
546
547 /* Return nonzero if FRAME is a dummy frame. We can't use PC_IN_CALL_DUMMY
548 because figuring out the saved SP would take too much time, at least using
549 get_saved_register on the 68k. This means that for this function to
550 work right a port must use the bp_call_dummy breakpoint. */
551
552 int
553 frame_in_dummy (frame)
554 FRAME frame;
555 {
556 struct breakpoint *b;
557
558 #ifdef CALL_DUMMY
559 ALL_BREAKPOINTS (b)
560 {
561 static unsigned LONGEST dummy[] = CALL_DUMMY;
562
563 if (b->type == bp_call_dummy
564 && b->frame == frame->frame
565
566 /* We need to check the PC as well as the frame on the sparc,
567 for signals.exp in the testsuite. */
568 && (frame->pc
569 >= (b->address
570 - sizeof (dummy) / sizeof (LONGEST) * REGISTER_SIZE))
571 && frame->pc <= b->address)
572 return 1;
573 }
574 #endif /* CALL_DUMMY */
575 return 0;
576 }
577
578 /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
579 is valid for process/thread PID. */
580
581 int
582 breakpoint_thread_match (pc, pid)
583 CORE_ADDR pc;
584 int pid;
585 {
586 struct breakpoint *b;
587 int thread;
588
589 thread = pid_to_thread_id (pid);
590
591 ALL_BREAKPOINTS (b)
592 if (b->enable != disabled
593 && b->address == pc
594 && (b->thread == -1 || b->thread == thread))
595 return 1;
596
597 return 0;
598 }
599
600 \f
601 /* bpstat stuff. External routines' interfaces are documented
602 in breakpoint.h. */
603
604 /* Clear a bpstat so that it says we are not at any breakpoint.
605 Also free any storage that is part of a bpstat. */
606
607 void
608 bpstat_clear (bsp)
609 bpstat *bsp;
610 {
611 bpstat p;
612 bpstat q;
613
614 if (bsp == 0)
615 return;
616 p = *bsp;
617 while (p != NULL)
618 {
619 q = p->next;
620 if (p->old_val != NULL)
621 value_free (p->old_val);
622 free ((PTR)p);
623 p = q;
624 }
625 *bsp = NULL;
626 }
627
628 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
629 is part of the bpstat is copied as well. */
630
631 bpstat
632 bpstat_copy (bs)
633 bpstat bs;
634 {
635 bpstat p = NULL;
636 bpstat tmp;
637 bpstat retval = NULL;
638
639 if (bs == NULL)
640 return bs;
641
642 for (; bs != NULL; bs = bs->next)
643 {
644 tmp = (bpstat) xmalloc (sizeof (*tmp));
645 memcpy (tmp, bs, sizeof (*tmp));
646 if (p == NULL)
647 /* This is the first thing in the chain. */
648 retval = tmp;
649 else
650 p->next = tmp;
651 p = tmp;
652 }
653 p->next = NULL;
654 return retval;
655 }
656
657 /* Find the bpstat associated with this breakpoint */
658
659 bpstat
660 bpstat_find_breakpoint(bsp, breakpoint)
661 bpstat bsp;
662 struct breakpoint *breakpoint;
663 {
664 if (bsp == NULL) return NULL;
665
666 for (;bsp != NULL; bsp = bsp->next) {
667 if (bsp->breakpoint_at == breakpoint) return bsp;
668 }
669 return NULL;
670 }
671
672 /* Return the breakpoint number of the first breakpoint we are stopped
673 at. *BSP upon return is a bpstat which points to the remaining
674 breakpoints stopped at (but which is not guaranteed to be good for
675 anything but further calls to bpstat_num).
676 Return 0 if passed a bpstat which does not indicate any breakpoints. */
677
678 int
679 bpstat_num (bsp)
680 bpstat *bsp;
681 {
682 struct breakpoint *b;
683
684 if ((*bsp) == NULL)
685 return 0; /* No more breakpoint values */
686 else
687 {
688 b = (*bsp)->breakpoint_at;
689 *bsp = (*bsp)->next;
690 if (b == NULL)
691 return -1; /* breakpoint that's been deleted since */
692 else
693 return b->number; /* We have its number */
694 }
695 }
696
697 /* Modify BS so that the actions will not be performed. */
698
699 void
700 bpstat_clear_actions (bs)
701 bpstat bs;
702 {
703 for (; bs != NULL; bs = bs->next)
704 {
705 bs->commands = NULL;
706 if (bs->old_val != NULL)
707 {
708 value_free (bs->old_val);
709 bs->old_val = NULL;
710 }
711 }
712 }
713
714 /* Stub for cleaning up our state if we error-out of a breakpoint command */
715 /* ARGSUSED */
716 static void
717 cleanup_executing_breakpoints (ignore)
718 int ignore;
719 {
720 executing_breakpoint_commands = 0;
721 }
722
723 /* Execute all the commands associated with all the breakpoints at this
724 location. Any of these commands could cause the process to proceed
725 beyond this point, etc. We look out for such changes by checking
726 the global "breakpoint_proceeded" after each command. */
727
728 void
729 bpstat_do_actions (bsp)
730 bpstat *bsp;
731 {
732 bpstat bs;
733 struct cleanup *old_chain;
734
735 executing_breakpoint_commands = 1;
736 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
737
738 top:
739 bs = *bsp;
740
741 breakpoint_proceeded = 0;
742 for (; bs != NULL; bs = bs->next)
743 {
744 while (bs->commands)
745 {
746 char *line = bs->commands->line;
747 bs->commands = bs->commands->next;
748 execute_command (line, 0);
749 /* If the inferior is proceeded by the command, bomb out now.
750 The bpstat chain has been blown away by wait_for_inferior.
751 But since execution has stopped again, there is a new bpstat
752 to look at, so start over. */
753 if (breakpoint_proceeded)
754 goto top;
755 }
756 }
757
758 executing_breakpoint_commands = 0;
759 discard_cleanups (old_chain);
760 }
761
762 /* This is the normal print_it function for a bpstat. In the future,
763 much of this logic could (should?) be moved to bpstat_stop_status,
764 by having it set different print_it functions. */
765
766 static int
767 print_it_normal (bs)
768 bpstat bs;
769 {
770 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
771 which has since been deleted. */
772 if (bs->breakpoint_at == NULL
773 || (bs->breakpoint_at->type != bp_breakpoint
774 && bs->breakpoint_at->type != bp_watchpoint))
775 return 0;
776
777 if (bs->breakpoint_at->type == bp_breakpoint)
778 {
779 /* I think the user probably only wants to see one breakpoint
780 number, not all of them. */
781 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
782 return 0;
783 }
784
785 if (bs->old_val != NULL)
786 {
787 printf_filtered ("\nWatchpoint %d, ", bs->breakpoint_at->number);
788 print_expression (bs->breakpoint_at->exp, gdb_stdout);
789 printf_filtered ("\nOld value = ");
790 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
791 printf_filtered ("\nNew value = ");
792 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
793 Val_pretty_default);
794 printf_filtered ("\n");
795 value_free (bs->old_val);
796 bs->old_val = NULL;
797 return 0;
798 }
799 /* We can't deal with it. Maybe another member of the bpstat chain can. */
800 return -1;
801 }
802
803 /* Print a message indicating what happened. Returns nonzero to
804 say that only the source line should be printed after this (zero
805 return means print the frame as well as the source line). */
806 /* Currently we always return zero. */
807 int
808 bpstat_print (bs)
809 bpstat bs;
810 {
811 int val;
812
813 if (bs == NULL)
814 return 0;
815
816 val = (*bs->print_it) (bs);
817 if (val >= 0)
818 return val;
819
820 /* Maybe another breakpoint in the chain caused us to stop.
821 (Currently all watchpoints go on the bpstat whether hit or
822 not. That probably could (should) be changed, provided care is taken
823 with respect to bpstat_explains_signal). */
824 if (bs->next)
825 return bpstat_print (bs->next);
826
827 /* We reached the end of the chain without printing anything. */
828 return 0;
829 }
830
831 /* Evaluate the expression EXP and return 1 if value is zero.
832 This is used inside a catch_errors to evaluate the breakpoint condition.
833 The argument is a "struct expression *" that has been cast to char * to
834 make it pass through catch_errors. */
835
836 static int
837 breakpoint_cond_eval (exp)
838 char *exp;
839 {
840 return !value_true (evaluate_expression ((struct expression *)exp));
841 }
842
843 /* Allocate a new bpstat and chain it to the current one. */
844
845 static bpstat
846 bpstat_alloc (b, cbs)
847 register struct breakpoint *b;
848 bpstat cbs; /* Current "bs" value */
849 {
850 bpstat bs;
851
852 bs = (bpstat) xmalloc (sizeof (*bs));
853 cbs->next = bs;
854 bs->breakpoint_at = b;
855 /* If the condition is false, etc., don't do the commands. */
856 bs->commands = NULL;
857 bs->old_val = NULL;
858 bs->print_it = print_it_normal;
859 return bs;
860 }
861 \f
862 /* Return the frame which we can use to evaluate the expression
863 whose valid block is valid_block, or NULL if not in scope.
864
865 This whole concept is probably not the way to do things (it is incredibly
866 slow being the main reason, not to mention fragile (e.g. the sparc
867 frame pointer being fetched as 0 bug causes it to stop)). Instead,
868 introduce a version of "struct frame" which survives over calls to the
869 inferior, but which is better than FRAME_ADDR in the sense that it lets
870 us evaluate expressions relative to that frame (on some machines, it
871 can just be a FRAME_ADDR). Save one of those instead of (or in addition
872 to) the exp_valid_block, and then use it to evaluate the watchpoint
873 expression, with no need to do all this backtracing every time.
874
875 Or better yet, what if it just copied the struct frame and its next
876 frame? Off the top of my head, I would think that would work
877 because things like (a29k) rsize and msize, or (sparc) bottom just
878 depend on the frame, and aren't going to be different just because
879 the inferior has done something. Trying to recalculate them
880 strikes me as a lot of work, possibly even impossible. Saving the
881 next frame is needed at least on a29k, where get_saved_register
882 uses fi->next->saved_msp. For figuring out whether that frame is
883 still on the stack, I guess this needs to be machine-specific (e.g.
884 a29k) but I think
885
886 read_fp () INNER_THAN watchpoint_frame->frame
887
888 would generally work.
889
890 Of course the scope of the expression could be less than a whole
891 function; perhaps if the innermost frame is the one which the
892 watchpoint is relative to (another machine-specific thing, usually
893
894 FRAMELESS_FUNCTION_INVOCATION (get_current_frame(), fromleaf)
895 read_fp () == wp_frame->frame
896 && !fromleaf
897
898 ), *then* it could do a
899
900 contained_in (get_current_block (), wp->exp_valid_block).
901
902 */
903
904 FRAME
905 within_scope (valid_block)
906 struct block *valid_block;
907 {
908 FRAME fr = get_current_frame ();
909 struct frame_info *fi = get_frame_info (fr);
910 CORE_ADDR func_start;
911
912 /* If caller_pc_valid is true, we are stepping through
913 a function prologue, which is bounded by callee_func_start
914 (inclusive) and callee_prologue_end (exclusive).
915 caller_pc is the pc of the caller.
916
917 Yes, this is hairy. */
918 static int caller_pc_valid = 0;
919 static CORE_ADDR caller_pc;
920 static CORE_ADDR callee_func_start;
921 static CORE_ADDR callee_prologue_end;
922
923 find_pc_partial_function (fi->pc, (PTR)NULL, &func_start, (CORE_ADDR *)NULL);
924 func_start += FUNCTION_START_OFFSET;
925 if (fi->pc == func_start)
926 {
927 /* We just called a function. The only other case I
928 can think of where the pc would equal the pc of the
929 start of a function is a frameless function (i.e.
930 no prologue) where we branch back to the start
931 of the function. In that case, SKIP_PROLOGUE won't
932 find one, and we'll clear caller_pc_valid a few lines
933 down. */
934 caller_pc_valid = 1;
935 caller_pc = SAVED_PC_AFTER_CALL (fr);
936 callee_func_start = func_start;
937 SKIP_PROLOGUE (func_start);
938 callee_prologue_end = func_start;
939 }
940 if (caller_pc_valid)
941 {
942 if (fi->pc < callee_func_start
943 || fi->pc >= callee_prologue_end)
944 caller_pc_valid = 0;
945 }
946
947 if (contained_in (block_for_pc (caller_pc_valid
948 ? caller_pc
949 : fi->pc),
950 valid_block))
951 {
952 return fr;
953 }
954 fr = get_prev_frame (fr);
955
956 /* If any active frame is in the exp_valid_block, then it's
957 OK. Note that this might not be the same invocation of
958 the exp_valid_block that we were watching a little while
959 ago, or the same one as when the watchpoint was set (e.g.
960 we are watching a local variable in a recursive function.
961 When we return from a recursive invocation, then we are
962 suddenly watching a different instance of the variable).
963
964 At least for now I am going to consider this a feature. */
965 for (; fr != NULL; fr = get_prev_frame (fr))
966 {
967 fi = get_frame_info (fr);
968 if (contained_in (block_for_pc (fi->pc),
969 valid_block))
970 {
971 return fr;
972 }
973 }
974 return NULL;
975 }
976
977 /* Possible return values for watchpoint_check (this can't be an enum
978 because of check_errors). */
979 /* The watchpoint has been disabled. */
980 #define WP_DISABLED 1
981 /* The value has changed. */
982 #define WP_VALUE_CHANGED 2
983 /* The value has not changed. */
984 #define WP_VALUE_NOT_CHANGED 3
985
986 /* Check watchpoint condition. */
987 static int
988 watchpoint_check (p)
989 char *p;
990 {
991 bpstat bs = (bpstat) p;
992 FRAME fr;
993
994 int within_current_scope;
995 if (bs->breakpoint_at->exp_valid_block == NULL)
996 within_current_scope = 1;
997 else
998 {
999 fr = within_scope (bs->breakpoint_at->exp_valid_block);
1000 within_current_scope = fr != NULL;
1001 if (within_current_scope)
1002 /* If we end up stopping, the current frame will get selected
1003 in normal_stop. So this call to select_frame won't affect
1004 the user. */
1005 select_frame (fr, -1);
1006 }
1007
1008 if (within_current_scope)
1009 {
1010 /* We use value_{,free_to_}mark because it could be a
1011 *long* time before we return to the command level and
1012 call free_all_values. We can't call free_all_values because
1013 we might be in the middle of evaluating a function call. */
1014
1015 value mark = value_mark ();
1016 value new_val = evaluate_expression (bs->breakpoint_at->exp);
1017 if (!value_equal (bs->breakpoint_at->val, new_val))
1018 {
1019 release_value (new_val);
1020 value_free_to_mark (mark);
1021 bs->old_val = bs->breakpoint_at->val;
1022 bs->breakpoint_at->val = new_val;
1023 /* We will stop here */
1024 return WP_VALUE_CHANGED;
1025 }
1026 else
1027 {
1028 /* Nothing changed, don't do anything. */
1029 value_free_to_mark (mark);
1030 /* We won't stop here */
1031 return WP_VALUE_NOT_CHANGED;
1032 }
1033 }
1034 else
1035 {
1036 /* This seems like the only logical thing to do because
1037 if we temporarily ignored the watchpoint, then when
1038 we reenter the block in which it is valid it contains
1039 garbage (in the case of a function, it may have two
1040 garbage values, one before and one after the prologue).
1041 So we can't even detect the first assignment to it and
1042 watch after that (since the garbage may or may not equal
1043 the first value assigned). */
1044 bs->breakpoint_at->enable = disabled;
1045 printf_filtered ("\
1046 Watchpoint %d disabled because the program has left the block in\n\
1047 which its expression is valid.\n", bs->breakpoint_at->number);
1048 return WP_DISABLED;
1049 }
1050 }
1051
1052 /* This is used when everything which needs to be printed has
1053 already been printed. But we still want to print the frame. */
1054 static int
1055 print_it_done (bs)
1056 bpstat bs;
1057 {
1058 return 0;
1059 }
1060
1061 /* This is used when nothing should be printed for this bpstat entry. */
1062
1063 static int
1064 print_it_noop (bs)
1065 bpstat bs;
1066 {
1067 return -1;
1068 }
1069
1070 /* Get a bpstat associated with having just stopped at address *PC
1071 and frame address FRAME_ADDRESS. Update *PC to point at the
1072 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
1073 if this is known to not be a real breakpoint (it could still be a
1074 watchpoint, though). */
1075
1076 /* Determine whether we stopped at a breakpoint, etc, or whether we
1077 don't understand this stop. Result is a chain of bpstat's such that:
1078
1079 if we don't understand the stop, the result is a null pointer.
1080
1081 if we understand why we stopped, the result is not null.
1082
1083 Each element of the chain refers to a particular breakpoint or
1084 watchpoint at which we have stopped. (We may have stopped for
1085 several reasons concurrently.)
1086
1087 Each element of the chain has valid next, breakpoint_at,
1088 commands, FIXME??? fields.
1089
1090 */
1091
1092 bpstat
1093 bpstat_stop_status (pc, frame_address, not_a_breakpoint)
1094 CORE_ADDR *pc;
1095 FRAME_ADDR frame_address;
1096 int not_a_breakpoint;
1097 {
1098 register struct breakpoint *b;
1099 CORE_ADDR bp_addr;
1100 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1101 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
1102 int real_breakpoint = 0;
1103 #endif
1104 /* Root of the chain of bpstat's */
1105 struct bpstat root_bs[1];
1106 /* Pointer to the last thing in the chain currently. */
1107 bpstat bs = root_bs;
1108
1109 /* Get the address where the breakpoint would have been. */
1110 bp_addr = *pc - DECR_PC_AFTER_BREAK;
1111
1112 ALL_BREAKPOINTS (b)
1113 {
1114 if (b->enable == disabled)
1115 continue;
1116
1117 if (b->type != bp_watchpoint && b->address != bp_addr)
1118 continue;
1119
1120 if (b->type != bp_watchpoint && not_a_breakpoint)
1121 continue;
1122
1123 /* Come here if it's a watchpoint, or if the break address matches */
1124
1125 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
1126
1127 bs->stop = 1;
1128 bs->print = 1;
1129
1130 if (b->type == bp_watchpoint)
1131 {
1132 static char message1[] =
1133 "Error evaluating expression for watchpoint %d\n";
1134 char message[sizeof (message1) + 30 /* slop */];
1135 sprintf (message, message1, b->number);
1136 switch (catch_errors (watchpoint_check, (char *) bs, message,
1137 RETURN_MASK_ALL))
1138 {
1139 case WP_DISABLED:
1140 /* We've already printed what needs to be printed. */
1141 bs->print_it = print_it_done;
1142 /* Stop. */
1143 break;
1144 case WP_VALUE_CHANGED:
1145 /* Stop. */
1146 break;
1147 case WP_VALUE_NOT_CHANGED:
1148 /* Don't stop. */
1149 bs->print_it = print_it_noop;
1150 bs->stop = 0;
1151 continue;
1152 default:
1153 /* Can't happen. */
1154 /* FALLTHROUGH */
1155 case 0:
1156 /* Error from catch_errors. */
1157 b->enable = disabled;
1158 printf_filtered ("Watchpoint %d disabled.\n", b->number);
1159 /* We've already printed what needs to be printed. */
1160 bs->print_it = print_it_done;
1161 /* Stop. */
1162 break;
1163 }
1164 }
1165 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1166 else
1167 real_breakpoint = 1;
1168 #endif
1169
1170 if (b->frame && b->frame != frame_address)
1171 bs->stop = 0;
1172 else
1173 {
1174 int value_is_zero = 0;
1175
1176 if (b->cond)
1177 {
1178 /* Need to select the frame, with all that implies
1179 so that the conditions will have the right context. */
1180 select_frame (get_current_frame (), 0);
1181 value_is_zero
1182 = catch_errors (breakpoint_cond_eval, (char *)(b->cond),
1183 "Error in testing breakpoint condition:\n",
1184 RETURN_MASK_ALL);
1185 /* FIXME-someday, should give breakpoint # */
1186 free_all_values ();
1187 }
1188 if (b->cond && value_is_zero)
1189 {
1190 bs->stop = 0;
1191 }
1192 else if (b->ignore_count > 0)
1193 {
1194 b->ignore_count--;
1195 bs->stop = 0;
1196 }
1197 else
1198 {
1199 /* We will stop here */
1200 if (b->disposition == disable)
1201 b->enable = disabled;
1202 bs->commands = b->commands;
1203 if (b->silent)
1204 bs->print = 0;
1205 if (bs->commands && STREQ ("silent", bs->commands->line))
1206 {
1207 bs->commands = bs->commands->next;
1208 bs->print = 0;
1209 }
1210 }
1211 }
1212 /* Print nothing for this entry if we dont stop or if we dont print. */
1213 if (bs->stop == 0 || bs->print == 0)
1214 bs->print_it = print_it_noop;
1215 }
1216
1217 bs->next = NULL; /* Terminate the chain */
1218 bs = root_bs->next; /* Re-grab the head of the chain */
1219 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1220 if (bs)
1221 {
1222 if (real_breakpoint)
1223 {
1224 *pc = bp_addr;
1225 #if defined (SHIFT_INST_REGS)
1226 SHIFT_INST_REGS();
1227 #else /* No SHIFT_INST_REGS. */
1228 write_pc (bp_addr);
1229 #endif /* No SHIFT_INST_REGS. */
1230 }
1231 }
1232 #endif /* DECR_PC_AFTER_BREAK != 0. */
1233 return bs;
1234 }
1235 \f
1236 /* Tell what to do about this bpstat. */
1237 struct bpstat_what
1238 bpstat_what (bs)
1239 bpstat bs;
1240 {
1241 /* Classify each bpstat as one of the following. */
1242 enum class {
1243 /* This bpstat element has no effect on the main_action. */
1244 no_effect = 0,
1245
1246 /* There was a watchpoint, stop but don't print. */
1247 wp_silent,
1248
1249 /* There was a watchpoint, stop and print. */
1250 wp_noisy,
1251
1252 /* There was a breakpoint but we're not stopping. */
1253 bp_nostop,
1254
1255 /* There was a breakpoint, stop but don't print. */
1256 bp_silent,
1257
1258 /* There was a breakpoint, stop and print. */
1259 bp_noisy,
1260
1261 /* We hit the longjmp breakpoint. */
1262 long_jump,
1263
1264 /* We hit the longjmp_resume breakpoint. */
1265 long_resume,
1266
1267 /* We hit the step_resume breakpoint. */
1268 step_resume,
1269
1270 /* This is just used to count how many enums there are. */
1271 class_last
1272 };
1273
1274 /* Here is the table which drives this routine. So that we can
1275 format it pretty, we define some abbreviations for the
1276 enum bpstat_what codes. */
1277 #define keep_c BPSTAT_WHAT_KEEP_CHECKING
1278 #define stop_s BPSTAT_WHAT_STOP_SILENT
1279 #define stop_n BPSTAT_WHAT_STOP_NOISY
1280 #define single BPSTAT_WHAT_SINGLE
1281 #define setlr BPSTAT_WHAT_SET_LONGJMP_RESUME
1282 #define clrlr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
1283 #define clrlrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
1284 #define sr BPSTAT_WHAT_STEP_RESUME
1285
1286 /* "Can't happen." Might want to print an error message.
1287 abort() is not out of the question, but chances are GDB is just
1288 a bit confused, not unusable. */
1289 #define err BPSTAT_WHAT_STOP_NOISY
1290
1291 /* Given an old action and a class, come up with a new action. */
1292 /* One interesting property of this table is that wp_silent is the same
1293 as bp_silent and wp_noisy is the same as bp_noisy. That is because
1294 after stopping, the check for whether to step over a breakpoint
1295 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
1296 reference to how we stopped. We retain separate wp_silent and bp_silent
1297 codes in case we want to change that someday. */
1298
1299 /* step_resume entries: a step resume breakpoint overrides another
1300 breakpoint of signal handling (see comment in wait_for_inferior
1301 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
1302
1303 static const enum bpstat_what_main_action
1304 table[(int)class_last][(int)BPSTAT_WHAT_LAST] =
1305 {
1306 /* old action */
1307 /* keep_c stop_s stop_n single setlr clrlr clrlrs sr */
1308
1309 /*no_effect*/ {keep_c, stop_s, stop_n, single, setlr , clrlr , clrlrs, sr},
1310 /*wp_silent*/ {stop_s, stop_s, stop_n, stop_s, stop_s, stop_s, stop_s, sr},
1311 /*wp_noisy*/ {stop_n, stop_n, stop_n, stop_n, stop_n, stop_n, stop_n, sr},
1312 /*bp_nostop*/ {single, stop_s, stop_n, single, setlr , clrlrs, clrlrs, sr},
1313 /*bp_silent*/ {stop_s, stop_s, stop_n, stop_s, stop_s, stop_s, stop_s, sr},
1314 /*bp_noisy*/ {stop_n, stop_n, stop_n, stop_n, stop_n, stop_n, stop_n, sr},
1315 /*long_jump*/ {setlr , stop_s, stop_n, setlr , err , err , err , sr},
1316 /*long_resume*/ {clrlr , stop_s, stop_n, clrlrs, err , err , err , sr},
1317 /*step_resume*/ {sr , sr , sr , sr , sr , sr , sr , sr}
1318 };
1319 #undef keep_c
1320 #undef stop_s
1321 #undef stop_n
1322 #undef single
1323 #undef setlr
1324 #undef clrlr
1325 #undef clrlrs
1326 #undef err
1327 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
1328 struct bpstat_what retval;
1329
1330 retval.call_dummy = 0;
1331 for (; bs != NULL; bs = bs->next)
1332 {
1333 enum class bs_class = no_effect;
1334 if (bs->breakpoint_at == NULL)
1335 /* I suspect this can happen if it was a momentary breakpoint
1336 which has since been deleted. */
1337 continue;
1338 switch (bs->breakpoint_at->type)
1339 {
1340 case bp_breakpoint:
1341 case bp_until:
1342 case bp_finish:
1343 if (bs->stop)
1344 {
1345 if (bs->print)
1346 bs_class = bp_noisy;
1347 else
1348 bs_class = bp_silent;
1349 }
1350 else
1351 bs_class = bp_nostop;
1352 break;
1353 case bp_watchpoint:
1354 if (bs->stop)
1355 {
1356 if (bs->print)
1357 bs_class = wp_noisy;
1358 else
1359 bs_class = wp_silent;
1360 }
1361 else
1362 /* There was a watchpoint, but we're not stopping. This requires
1363 no further action. */
1364 bs_class = no_effect;
1365 break;
1366 case bp_longjmp:
1367 bs_class = long_jump;
1368 break;
1369 case bp_longjmp_resume:
1370 bs_class = long_resume;
1371 break;
1372 case bp_step_resume:
1373 #if 0
1374 /* Need to temporarily disable this until we can fix the bug
1375 with nexting over a breakpoint with ->stop clear causing
1376 an infinite loop. For now, treat the breakpoint as having
1377 been hit even if the frame is wrong. */
1378 if (bs->stop)
1379 {
1380 #endif
1381 bs_class = step_resume;
1382 #if 0
1383 }
1384 else
1385 /* It is for the wrong frame. */
1386 bs_class = bp_nostop;
1387 #endif
1388 break;
1389 case bp_call_dummy:
1390 /* Make sure the action is stop (silent or noisy), so infrun.c
1391 pops the dummy frame. */
1392 bs_class = bp_silent;
1393 retval.call_dummy = 1;
1394 break;
1395 }
1396 current_action = table[(int)bs_class][(int)current_action];
1397 }
1398 retval.main_action = current_action;
1399 return retval;
1400 }
1401
1402 /* Nonzero if we should step constantly (e.g. watchpoints on machines
1403 without hardware support). This isn't related to a specific bpstat,
1404 just to things like whether watchpoints are set. */
1405
1406 int
1407 bpstat_should_step ()
1408 {
1409 struct breakpoint *b;
1410 ALL_BREAKPOINTS (b)
1411 if (b->enable == enabled && b->type == bp_watchpoint)
1412 return 1;
1413 return 0;
1414 }
1415 \f
1416 /* Print information on breakpoint number BNUM, or -1 if all.
1417 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
1418 is nonzero, process only watchpoints. */
1419
1420 static void
1421 breakpoint_1 (bnum, allflag)
1422 int bnum;
1423 int allflag;
1424 {
1425 register struct breakpoint *b;
1426 register struct command_line *l;
1427 register struct symbol *sym;
1428 CORE_ADDR last_addr = (CORE_ADDR)-1;
1429 int found_a_breakpoint = 0;
1430 static char *bptypes[] = {"breakpoint", "until", "finish", "watchpoint",
1431 "longjmp", "longjmp resume", "step resume",
1432 "call dummy" };
1433 static char *bpdisps[] = {"del", "dis", "keep"};
1434 static char bpenables[] = "ny";
1435 char wrap_indent[80];
1436
1437 ALL_BREAKPOINTS (b)
1438 if (bnum == -1
1439 || bnum == b->number)
1440 {
1441 /* We only print out user settable breakpoints unless the allflag is set. */
1442 if (!allflag
1443 && b->type != bp_breakpoint
1444 && b->type != bp_watchpoint)
1445 continue;
1446
1447 if (!found_a_breakpoint++)
1448 printf_filtered ("Num Type Disp Enb %sWhat\n",
1449 addressprint ? "Address " : "");
1450
1451 printf_filtered ("%-3d %-14s %-4s %-3c ",
1452 b->number,
1453 bptypes[(int)b->type],
1454 bpdisps[(int)b->disposition],
1455 bpenables[(int)b->enable]);
1456 strcpy (wrap_indent, " ");
1457 if (addressprint)
1458 strcat (wrap_indent, " ");
1459 switch (b->type)
1460 {
1461 case bp_watchpoint:
1462 print_expression (b->exp, gdb_stdout);
1463 break;
1464
1465 case bp_breakpoint:
1466 case bp_until:
1467 case bp_finish:
1468 case bp_longjmp:
1469 case bp_longjmp_resume:
1470 case bp_step_resume:
1471 case bp_call_dummy:
1472 if (addressprint)
1473 printf_filtered ("%s ", local_hex_string_custom ((unsigned long) b->address, "08l"));
1474
1475 last_addr = b->address;
1476 if (b->source_file)
1477 {
1478 sym = find_pc_function (b->address);
1479 if (sym)
1480 {
1481 fputs_filtered ("in ", gdb_stdout);
1482 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
1483 wrap_here (wrap_indent);
1484 fputs_filtered (" at ", gdb_stdout);
1485 }
1486 fputs_filtered (b->source_file, gdb_stdout);
1487 printf_filtered (":%d", b->line_number);
1488 }
1489 else
1490 print_address_symbolic (b->address, gdb_stdout, demangle, " ");
1491 break;
1492 }
1493
1494 printf_filtered ("\n");
1495
1496 if (b->frame)
1497 {
1498 printf_filtered ("\tstop only in stack frame at ");
1499 print_address_numeric (b->frame, gdb_stdout);
1500 printf_filtered ("\n");
1501 if (b->cond)
1502 {
1503 printf_filtered ("\tstop only if ");
1504 print_expression (b->cond, gdb_stdout);
1505 printf_filtered ("\n");
1506 }
1507 if (b->ignore_count)
1508 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
1509 if ((l = b->commands))
1510 while (l)
1511 {
1512 fputs_filtered ("\t", gdb_stdout);
1513 fputs_filtered (l->line, gdb_stdout);
1514 fputs_filtered ("\n", gdb_stdout);
1515 l = l->next;
1516 }
1517 }
1518
1519 if (!found_a_breakpoint)
1520 {
1521 if (bnum == -1)
1522 printf_filtered ("No breakpoints or watchpoints.\n");
1523 else
1524 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
1525 }
1526 else
1527 /* Compare against (CORE_ADDR)-1 in case some compiler decides
1528 that a comparison of an unsigned with -1 is always false. */
1529 if (last_addr != (CORE_ADDR)-1)
1530 set_next_address (last_addr);
1531 }
1532
1533 /* ARGSUSED */
1534 static void
1535 breakpoints_info (bnum_exp, from_tty)
1536 char *bnum_exp;
1537 int from_tty;
1538 {
1539 int bnum = -1;
1540
1541 if (bnum_exp)
1542 bnum = parse_and_eval_address (bnum_exp);
1543
1544 breakpoint_1 (bnum, 0);
1545 }
1546
1547 #if MAINTENANCE_CMDS
1548
1549 /* ARGSUSED */
1550 static void
1551 maintenance_info_breakpoints (bnum_exp, from_tty)
1552 char *bnum_exp;
1553 int from_tty;
1554 {
1555 int bnum = -1;
1556
1557 if (bnum_exp)
1558 bnum = parse_and_eval_address (bnum_exp);
1559
1560 breakpoint_1 (bnum, 1);
1561 }
1562
1563 #endif
1564
1565 /* Print a message describing any breakpoints set at PC. */
1566
1567 static void
1568 describe_other_breakpoints (pc)
1569 register CORE_ADDR pc;
1570 {
1571 register int others = 0;
1572 register struct breakpoint *b;
1573
1574 ALL_BREAKPOINTS (b)
1575 if (b->address == pc)
1576 others++;
1577 if (others > 0)
1578 {
1579 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
1580 ALL_BREAKPOINTS (b)
1581 if (b->address == pc)
1582 {
1583 others--;
1584 printf_filtered
1585 ("%d%s%s ",
1586 b->number,
1587 (b->enable == disabled) ? " (disabled)" : "",
1588 (others > 1) ? "," : ((others == 1) ? " and" : ""));
1589 }
1590 printf_filtered ("also set at pc ");
1591 print_address_numeric (pc, gdb_stdout);
1592 printf_filtered (".\n");
1593 }
1594 }
1595 \f
1596 /* Set the default place to put a breakpoint
1597 for the `break' command with no arguments. */
1598
1599 void
1600 set_default_breakpoint (valid, addr, symtab, line)
1601 int valid;
1602 CORE_ADDR addr;
1603 struct symtab *symtab;
1604 int line;
1605 {
1606 default_breakpoint_valid = valid;
1607 default_breakpoint_address = addr;
1608 default_breakpoint_symtab = symtab;
1609 default_breakpoint_line = line;
1610 }
1611
1612 /* Rescan breakpoints at address ADDRESS,
1613 marking the first one as "first" and any others as "duplicates".
1614 This is so that the bpt instruction is only inserted once. */
1615
1616 static void
1617 check_duplicates (address)
1618 CORE_ADDR address;
1619 {
1620 register struct breakpoint *b;
1621 register int count = 0;
1622
1623 if (address == 0) /* Watchpoints are uninteresting */
1624 return;
1625
1626 ALL_BREAKPOINTS (b)
1627 if (b->enable != disabled && b->address == address)
1628 {
1629 count++;
1630 b->duplicate = count > 1;
1631 }
1632 }
1633
1634 /* Low level routine to set a breakpoint.
1635 Takes as args the three things that every breakpoint must have.
1636 Returns the breakpoint object so caller can set other things.
1637 Does not set the breakpoint number!
1638 Does not print anything.
1639
1640 ==> This routine should not be called if there is a chance of later
1641 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
1642 your arguments BEFORE calling this routine! */
1643
1644 static struct breakpoint *
1645 set_raw_breakpoint (sal)
1646 struct symtab_and_line sal;
1647 {
1648 register struct breakpoint *b, *b1;
1649
1650 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
1651 memset (b, 0, sizeof (*b));
1652 b->address = sal.pc;
1653 if (sal.symtab == NULL)
1654 b->source_file = NULL;
1655 else
1656 b->source_file = savestring (sal.symtab->filename,
1657 strlen (sal.symtab->filename));
1658 b->thread = -1;
1659 b->line_number = sal.line;
1660 b->enable = enabled;
1661 b->next = 0;
1662 b->silent = 0;
1663 b->ignore_count = 0;
1664 b->commands = NULL;
1665 b->frame = 0;
1666
1667 /* Add this breakpoint to the end of the chain
1668 so that a list of breakpoints will come out in order
1669 of increasing numbers. */
1670
1671 b1 = breakpoint_chain;
1672 if (b1 == 0)
1673 breakpoint_chain = b;
1674 else
1675 {
1676 while (b1->next)
1677 b1 = b1->next;
1678 b1->next = b;
1679 }
1680
1681 check_duplicates (sal.pc);
1682
1683 return b;
1684 }
1685
1686 static void
1687 create_longjmp_breakpoint(func_name)
1688 char *func_name;
1689 {
1690 struct symtab_and_line sal;
1691 struct breakpoint *b;
1692 static int internal_breakpoint_number = -1;
1693
1694 if (func_name != NULL)
1695 {
1696 struct minimal_symbol *m;
1697
1698 m = lookup_minimal_symbol(func_name, (struct objfile *)NULL);
1699 if (m)
1700 sal.pc = SYMBOL_VALUE_ADDRESS (m);
1701 else
1702 return;
1703 }
1704 else
1705 sal.pc = 0;
1706
1707 sal.symtab = NULL;
1708 sal.line = 0;
1709
1710 b = set_raw_breakpoint(sal);
1711 if (!b) return;
1712
1713 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
1714 b->disposition = donttouch;
1715 b->enable = disabled;
1716 b->silent = 1;
1717 if (func_name)
1718 b->addr_string = strsave(func_name);
1719 b->number = internal_breakpoint_number--;
1720 }
1721
1722 /* Call this routine when stepping and nexting to enable a breakpoint if we do
1723 a longjmp(). When we hit that breakpoint, call
1724 set_longjmp_resume_breakpoint() to figure out where we are going. */
1725
1726 void
1727 enable_longjmp_breakpoint()
1728 {
1729 register struct breakpoint *b;
1730
1731 ALL_BREAKPOINTS (b)
1732 if (b->type == bp_longjmp)
1733 {
1734 b->enable = enabled;
1735 check_duplicates (b->address);
1736 }
1737 }
1738
1739 void
1740 disable_longjmp_breakpoint()
1741 {
1742 register struct breakpoint *b;
1743
1744 ALL_BREAKPOINTS (b)
1745 if ( b->type == bp_longjmp
1746 || b->type == bp_longjmp_resume)
1747 {
1748 b->enable = disabled;
1749 check_duplicates (b->address);
1750 }
1751 }
1752
1753 /* Call this after hitting the longjmp() breakpoint. Use this to set a new
1754 breakpoint at the target of the jmp_buf.
1755
1756 FIXME - This ought to be done by setting a temporary breakpoint that gets
1757 deleted automatically...
1758 */
1759
1760 void
1761 set_longjmp_resume_breakpoint(pc, frame)
1762 CORE_ADDR pc;
1763 FRAME frame;
1764 {
1765 register struct breakpoint *b;
1766
1767 ALL_BREAKPOINTS (b)
1768 if (b->type == bp_longjmp_resume)
1769 {
1770 b->address = pc;
1771 b->enable = enabled;
1772 if (frame != NULL)
1773 b->frame = FRAME_FP(frame);
1774 else
1775 b->frame = 0;
1776 check_duplicates (b->address);
1777 return;
1778 }
1779 }
1780
1781 /* Set a breakpoint that will evaporate an end of command
1782 at address specified by SAL.
1783 Restrict it to frame FRAME if FRAME is nonzero. */
1784
1785 struct breakpoint *
1786 set_momentary_breakpoint (sal, frame, type)
1787 struct symtab_and_line sal;
1788 FRAME frame;
1789 enum bptype type;
1790 {
1791 register struct breakpoint *b;
1792 b = set_raw_breakpoint (sal);
1793 b->type = type;
1794 b->enable = enabled;
1795 b->disposition = donttouch;
1796 b->frame = (frame ? FRAME_FP (frame) : 0);
1797 return b;
1798 }
1799
1800 #if 0
1801 void
1802 clear_momentary_breakpoints ()
1803 {
1804 register struct breakpoint *b;
1805 ALL_BREAKPOINTS (b)
1806 if (b->disposition == delete)
1807 {
1808 delete_breakpoint (b);
1809 break;
1810 }
1811 }
1812 #endif
1813 \f
1814 /* Tell the user we have just set a breakpoint B. */
1815 static void
1816 mention (b)
1817 struct breakpoint *b;
1818 {
1819 switch (b->type)
1820 {
1821 case bp_watchpoint:
1822 printf_filtered ("Watchpoint %d: ", b->number);
1823 print_expression (b->exp, gdb_stdout);
1824 break;
1825 case bp_breakpoint:
1826 printf_filtered ("Breakpoint %d at ", b->number);
1827 print_address_numeric (b->address);
1828 if (b->source_file)
1829 printf_filtered (": file %s, line %d.",
1830 b->source_file, b->line_number);
1831 break;
1832 case bp_until:
1833 case bp_finish:
1834 case bp_longjmp:
1835 case bp_longjmp_resume:
1836 case bp_step_resume:
1837 case bp_call_dummy:
1838 break;
1839 }
1840 printf_filtered ("\n");
1841 }
1842
1843 #if 0
1844 /* Nobody calls this currently. */
1845 /* Set a breakpoint from a symtab and line.
1846 If TEMPFLAG is nonzero, it is a temporary breakpoint.
1847 ADDR_STRING is a malloc'd string holding the name of where we are
1848 setting the breakpoint. This is used later to re-set it after the
1849 program is relinked and symbols are reloaded.
1850 Print the same confirmation messages that the breakpoint command prints. */
1851
1852 void
1853 set_breakpoint (s, line, tempflag, addr_string)
1854 struct symtab *s;
1855 int line;
1856 int tempflag;
1857 char *addr_string;
1858 {
1859 register struct breakpoint *b;
1860 struct symtab_and_line sal;
1861
1862 sal.symtab = s;
1863 sal.line = line;
1864 sal.pc = 0;
1865 resolve_sal_pc (&sal); /* Might error out */
1866 describe_other_breakpoints (sal.pc);
1867
1868 b = set_raw_breakpoint (sal);
1869 set_breakpoint_count (breakpoint_count + 1);
1870 b->number = breakpoint_count;
1871 b->type = bp_breakpoint;
1872 b->cond = 0;
1873 b->addr_string = addr_string;
1874 b->enable = enabled;
1875 b->disposition = tempflag ? delete : donttouch;
1876
1877 mention (b);
1878 }
1879 #endif /* 0 */
1880 \f
1881 /* Set a breakpoint according to ARG (function, linenum or *address)
1882 and make it temporary if TEMPFLAG is nonzero. */
1883
1884 static void
1885 break_command_1 (arg, tempflag, from_tty)
1886 char *arg;
1887 int tempflag, from_tty;
1888 {
1889 struct symtabs_and_lines sals;
1890 struct symtab_and_line sal;
1891 register struct expression *cond = 0;
1892 register struct breakpoint *b;
1893
1894 /* Pointers in arg to the start, and one past the end, of the condition. */
1895 char *cond_start = NULL;
1896 char *cond_end = NULL;
1897 /* Pointers in arg to the start, and one past the end,
1898 of the address part. */
1899 char *addr_start = NULL;
1900 char *addr_end = NULL;
1901 struct cleanup *old_chain;
1902 struct cleanup *canonical_strings_chain = NULL;
1903 char **canonical = (char **)NULL;
1904 int i;
1905 int thread;
1906
1907 sals.sals = NULL;
1908 sals.nelts = 0;
1909
1910 sal.line = sal.pc = sal.end = 0;
1911 sal.symtab = 0;
1912
1913 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
1914
1915 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1916 && (arg[2] == ' ' || arg[2] == '\t')))
1917 {
1918 if (default_breakpoint_valid)
1919 {
1920 sals.sals = (struct symtab_and_line *)
1921 xmalloc (sizeof (struct symtab_and_line));
1922 sal.pc = default_breakpoint_address;
1923 sal.line = default_breakpoint_line;
1924 sal.symtab = default_breakpoint_symtab;
1925 sals.sals[0] = sal;
1926 sals.nelts = 1;
1927 }
1928 else
1929 error ("No default breakpoint address now.");
1930 }
1931 else
1932 {
1933 addr_start = arg;
1934
1935 /* Force almost all breakpoints to be in terms of the
1936 current_source_symtab (which is decode_line_1's default). This
1937 should produce the results we want almost all of the time while
1938 leaving default_breakpoint_* alone. */
1939 if (default_breakpoint_valid
1940 && (!current_source_symtab
1941 || (arg && (*arg == '+' || *arg == '-'))))
1942 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1943 default_breakpoint_line, &canonical);
1944 else
1945 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, &canonical);
1946
1947 addr_end = arg;
1948 }
1949
1950 if (! sals.nelts)
1951 return;
1952
1953 /* Make sure that all storage allocated in decode_line_1 gets freed in case
1954 the following `for' loop errors out. */
1955 old_chain = make_cleanup (free, sals.sals);
1956 if (canonical != (char **)NULL)
1957 {
1958 make_cleanup (free, canonical);
1959 canonical_strings_chain = make_cleanup (null_cleanup, 0);
1960 for (i = 0; i < sals.nelts; i++)
1961 {
1962 if (canonical[i] != NULL)
1963 make_cleanup (free, canonical[i]);
1964 }
1965 }
1966
1967 thread = -1; /* No specific thread yet */
1968
1969 /* Resolve all line numbers to PC's, and verify that conditions
1970 can be parsed, before setting any breakpoints. */
1971 for (i = 0; i < sals.nelts; i++)
1972 {
1973 char *tok, *end_tok;
1974 int toklen;
1975
1976 resolve_sal_pc (&sals.sals[i]);
1977
1978 tok = arg;
1979
1980 while (tok && *tok)
1981 {
1982 while (*tok == ' ' || *tok == '\t')
1983 tok++;
1984
1985 end_tok = tok;
1986
1987 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
1988 end_tok++;
1989
1990 toklen = end_tok - tok;
1991
1992 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
1993 {
1994 tok = cond_start = end_tok + 1;
1995 cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
1996 cond_end = tok;
1997 }
1998 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
1999 {
2000 char *tmptok;
2001
2002 tok = end_tok + 1;
2003 tmptok = tok;
2004 thread = strtol (tok, &tok, 0);
2005 if (tok == tmptok)
2006 error ("Junk after thread keyword.");
2007 if (!valid_thread_id (thread))
2008 error ("Unknown thread %d\n", thread);
2009 }
2010 else
2011 error ("Junk at end of arguments.");
2012 }
2013 }
2014
2015 /* Remove the canonical strings from the cleanup, they are needed below. */
2016 if (canonical != (char **)NULL)
2017 discard_cleanups (canonical_strings_chain);
2018
2019 /* Now set all the breakpoints. */
2020 for (i = 0; i < sals.nelts; i++)
2021 {
2022 sal = sals.sals[i];
2023
2024 if (from_tty)
2025 describe_other_breakpoints (sal.pc);
2026
2027 b = set_raw_breakpoint (sal);
2028 set_breakpoint_count (breakpoint_count + 1);
2029 b->number = breakpoint_count;
2030 b->type = bp_breakpoint;
2031 b->cond = cond;
2032 b->thread = thread;
2033
2034 /* If a canonical line spec is needed use that instead of the
2035 command string. */
2036 if (canonical != (char **)NULL && canonical[i] != NULL)
2037 b->addr_string = canonical[i];
2038 else if (addr_start)
2039 b->addr_string = savestring (addr_start, addr_end - addr_start);
2040 if (cond_start)
2041 b->cond_string = savestring (cond_start, cond_end - cond_start);
2042
2043 b->enable = enabled;
2044 b->disposition = tempflag ? delete : donttouch;
2045
2046 mention (b);
2047 }
2048
2049 if (sals.nelts > 1)
2050 {
2051 printf_filtered ("Multiple breakpoints were set.\n");
2052 printf_filtered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
2053 }
2054 do_cleanups (old_chain);
2055 }
2056
2057 /* Helper function for break_command_1 and disassemble_command. */
2058
2059 void
2060 resolve_sal_pc (sal)
2061 struct symtab_and_line *sal;
2062 {
2063 CORE_ADDR pc;
2064
2065 if (sal->pc == 0 && sal->symtab != 0)
2066 {
2067 pc = find_line_pc (sal->symtab, sal->line);
2068 if (pc == 0)
2069 error ("No line %d in file \"%s\".",
2070 sal->line, sal->symtab->filename);
2071 sal->pc = pc;
2072 }
2073 }
2074
2075 void
2076 break_command (arg, from_tty)
2077 char *arg;
2078 int from_tty;
2079 {
2080 break_command_1 (arg, 0, from_tty);
2081 }
2082
2083 static void
2084 tbreak_command (arg, from_tty)
2085 char *arg;
2086 int from_tty;
2087 {
2088 break_command_1 (arg, 1, from_tty);
2089 }
2090
2091 /* ARGSUSED */
2092 static void
2093 watch_command (arg, from_tty)
2094 char *arg;
2095 int from_tty;
2096 {
2097 struct breakpoint *b;
2098 struct symtab_and_line sal;
2099 struct expression *exp;
2100 struct block *exp_valid_block;
2101 struct value *val;
2102
2103 sal.pc = 0;
2104 sal.symtab = NULL;
2105 sal.line = 0;
2106
2107 /* Parse arguments. */
2108 innermost_block = NULL;
2109 exp = parse_expression (arg);
2110 exp_valid_block = innermost_block;
2111 val = evaluate_expression (exp);
2112 release_value (val);
2113 if (VALUE_LAZY (val))
2114 value_fetch_lazy (val);
2115
2116 /* Now set up the breakpoint. */
2117 b = set_raw_breakpoint (sal);
2118 set_breakpoint_count (breakpoint_count + 1);
2119 b->number = breakpoint_count;
2120 b->type = bp_watchpoint;
2121 b->disposition = donttouch;
2122 b->exp = exp;
2123 b->exp_valid_block = exp_valid_block;
2124 b->val = val;
2125 b->cond = 0;
2126 b->cond_string = NULL;
2127 b->exp_string = savestring (arg, strlen (arg));
2128 mention (b);
2129 }
2130 \f
2131 /*
2132 * Helper routine for the until_command routine in infcmd.c. Here
2133 * because it uses the mechanisms of breakpoints.
2134 */
2135 /* ARGSUSED */
2136 void
2137 until_break_command (arg, from_tty)
2138 char *arg;
2139 int from_tty;
2140 {
2141 struct symtabs_and_lines sals;
2142 struct symtab_and_line sal;
2143 FRAME prev_frame = get_prev_frame (selected_frame);
2144 struct breakpoint *breakpoint;
2145 struct cleanup *old_chain;
2146
2147 clear_proceed_status ();
2148
2149 /* Set a breakpoint where the user wants it and at return from
2150 this function */
2151
2152 if (default_breakpoint_valid)
2153 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
2154 default_breakpoint_line, (char ***)NULL);
2155 else
2156 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, (char ***)NULL);
2157
2158 if (sals.nelts != 1)
2159 error ("Couldn't get information on specified line.");
2160
2161 sal = sals.sals[0];
2162 free ((PTR)sals.sals); /* malloc'd, so freed */
2163
2164 if (*arg)
2165 error ("Junk at end of arguments.");
2166
2167 resolve_sal_pc (&sal);
2168
2169 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
2170
2171 old_chain = make_cleanup(delete_breakpoint, breakpoint);
2172
2173 /* Keep within the current frame */
2174
2175 if (prev_frame)
2176 {
2177 struct frame_info *fi;
2178
2179 fi = get_frame_info (prev_frame);
2180 sal = find_pc_line (fi->pc, 0);
2181 sal.pc = fi->pc;
2182 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
2183 make_cleanup(delete_breakpoint, breakpoint);
2184 }
2185
2186 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
2187 do_cleanups(old_chain);
2188 }
2189 \f
2190 #if 0
2191 /* These aren't used; I don't konw what they were for. */
2192 /* Set a breakpoint at the catch clause for NAME. */
2193 static int
2194 catch_breakpoint (name)
2195 char *name;
2196 {
2197 }
2198
2199 static int
2200 disable_catch_breakpoint ()
2201 {
2202 }
2203
2204 static int
2205 delete_catch_breakpoint ()
2206 {
2207 }
2208
2209 static int
2210 enable_catch_breakpoint ()
2211 {
2212 }
2213 #endif /* 0 */
2214
2215 struct sal_chain
2216 {
2217 struct sal_chain *next;
2218 struct symtab_and_line sal;
2219 };
2220
2221 #if 0
2222 /* This isn't used; I don't know what it was for. */
2223 /* For each catch clause identified in ARGS, run FUNCTION
2224 with that clause as an argument. */
2225 static struct symtabs_and_lines
2226 map_catch_names (args, function)
2227 char *args;
2228 int (*function)();
2229 {
2230 register char *p = args;
2231 register char *p1;
2232 struct symtabs_and_lines sals;
2233 #if 0
2234 struct sal_chain *sal_chain = 0;
2235 #endif
2236
2237 if (p == 0)
2238 error_no_arg ("one or more catch names");
2239
2240 sals.nelts = 0;
2241 sals.sals = NULL;
2242
2243 while (*p)
2244 {
2245 p1 = p;
2246 /* Don't swallow conditional part. */
2247 if (p1[0] == 'i' && p1[1] == 'f'
2248 && (p1[2] == ' ' || p1[2] == '\t'))
2249 break;
2250
2251 if (isalpha (*p1))
2252 {
2253 p1++;
2254 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
2255 p1++;
2256 }
2257
2258 if (*p1 && *p1 != ' ' && *p1 != '\t')
2259 error ("Arguments must be catch names.");
2260
2261 *p1 = 0;
2262 #if 0
2263 if (function (p))
2264 {
2265 struct sal_chain *next
2266 = (struct sal_chain *)alloca (sizeof (struct sal_chain));
2267 next->next = sal_chain;
2268 next->sal = get_catch_sal (p);
2269 sal_chain = next;
2270 goto win;
2271 }
2272 #endif
2273 printf_unfiltered ("No catch clause for exception %s.\n", p);
2274 #if 0
2275 win:
2276 #endif
2277 p = p1;
2278 while (*p == ' ' || *p == '\t') p++;
2279 }
2280 }
2281 #endif /* 0 */
2282
2283 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
2284
2285 static struct symtabs_and_lines
2286 get_catch_sals (this_level_only)
2287 int this_level_only;
2288 {
2289 register struct blockvector *bl;
2290 register struct block *block;
2291 int index, have_default = 0;
2292 struct frame_info *fi;
2293 CORE_ADDR pc;
2294 struct symtabs_and_lines sals;
2295 struct sal_chain *sal_chain = 0;
2296 char *blocks_searched;
2297
2298 /* Not sure whether an error message is always the correct response,
2299 but it's better than a core dump. */
2300 if (selected_frame == NULL)
2301 error ("No selected frame.");
2302 block = get_frame_block (selected_frame);
2303 fi = get_frame_info (selected_frame);
2304 pc = fi->pc;
2305
2306 sals.nelts = 0;
2307 sals.sals = NULL;
2308
2309 if (block == 0)
2310 error ("No symbol table info available.\n");
2311
2312 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
2313 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
2314 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
2315
2316 while (block != 0)
2317 {
2318 CORE_ADDR end = BLOCK_END (block) - 4;
2319 int last_index;
2320
2321 if (bl != blockvector_for_pc (end, &index))
2322 error ("blockvector blotch");
2323 if (BLOCKVECTOR_BLOCK (bl, index) != block)
2324 error ("blockvector botch");
2325 last_index = BLOCKVECTOR_NBLOCKS (bl);
2326 index += 1;
2327
2328 /* Don't print out blocks that have gone by. */
2329 while (index < last_index
2330 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
2331 index++;
2332
2333 while (index < last_index
2334 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
2335 {
2336 if (blocks_searched[index] == 0)
2337 {
2338 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
2339 int nsyms;
2340 register int i;
2341 register struct symbol *sym;
2342
2343 nsyms = BLOCK_NSYMS (b);
2344
2345 for (i = 0; i < nsyms; i++)
2346 {
2347 sym = BLOCK_SYM (b, i);
2348 if (STREQ (SYMBOL_NAME (sym), "default"))
2349 {
2350 if (have_default)
2351 continue;
2352 have_default = 1;
2353 }
2354 if (SYMBOL_CLASS (sym) == LOC_LABEL)
2355 {
2356 struct sal_chain *next = (struct sal_chain *)
2357 alloca (sizeof (struct sal_chain));
2358 next->next = sal_chain;
2359 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
2360 sal_chain = next;
2361 }
2362 }
2363 blocks_searched[index] = 1;
2364 }
2365 index++;
2366 }
2367 if (have_default)
2368 break;
2369 if (sal_chain && this_level_only)
2370 break;
2371
2372 /* After handling the function's top-level block, stop.
2373 Don't continue to its superblock, the block of
2374 per-file symbols. */
2375 if (BLOCK_FUNCTION (block))
2376 break;
2377 block = BLOCK_SUPERBLOCK (block);
2378 }
2379
2380 if (sal_chain)
2381 {
2382 struct sal_chain *tmp_chain;
2383
2384 /* Count the number of entries. */
2385 for (index = 0, tmp_chain = sal_chain; tmp_chain;
2386 tmp_chain = tmp_chain->next)
2387 index++;
2388
2389 sals.nelts = index;
2390 sals.sals = (struct symtab_and_line *)
2391 xmalloc (index * sizeof (struct symtab_and_line));
2392 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
2393 sals.sals[index] = sal_chain->sal;
2394 }
2395
2396 return sals;
2397 }
2398
2399 /* Commands to deal with catching exceptions. */
2400
2401 static void
2402 catch_command_1 (arg, tempflag, from_tty)
2403 char *arg;
2404 int tempflag;
2405 int from_tty;
2406 {
2407 /* First, translate ARG into something we can deal with in terms
2408 of breakpoints. */
2409
2410 struct symtabs_and_lines sals;
2411 struct symtab_and_line sal;
2412 register struct expression *cond = 0;
2413 register struct breakpoint *b;
2414 char *save_arg;
2415 int i;
2416
2417 sal.line = sal.pc = sal.end = 0;
2418 sal.symtab = 0;
2419
2420 /* If no arg given, or if first arg is 'if ', all active catch clauses
2421 are breakpointed. */
2422
2423 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
2424 && (arg[2] == ' ' || arg[2] == '\t')))
2425 {
2426 /* Grab all active catch clauses. */
2427 sals = get_catch_sals (0);
2428 }
2429 else
2430 {
2431 /* Grab selected catch clauses. */
2432 error ("catch NAME not implemented");
2433 #if 0
2434 /* This isn't used; I don't know what it was for. */
2435 sals = map_catch_names (arg, catch_breakpoint);
2436 #endif
2437 }
2438
2439 if (! sals.nelts)
2440 return;
2441
2442 save_arg = arg;
2443 for (i = 0; i < sals.nelts; i++)
2444 {
2445 resolve_sal_pc (&sals.sals[i]);
2446
2447 while (arg && *arg)
2448 {
2449 if (arg[0] == 'i' && arg[1] == 'f'
2450 && (arg[2] == ' ' || arg[2] == '\t'))
2451 cond = parse_exp_1 ((arg += 2, &arg),
2452 block_for_pc (sals.sals[i].pc), 0);
2453 else
2454 error ("Junk at end of arguments.");
2455 }
2456 arg = save_arg;
2457 }
2458
2459 for (i = 0; i < sals.nelts; i++)
2460 {
2461 sal = sals.sals[i];
2462
2463 if (from_tty)
2464 describe_other_breakpoints (sal.pc);
2465
2466 b = set_raw_breakpoint (sal);
2467 set_breakpoint_count (breakpoint_count + 1);
2468 b->number = breakpoint_count;
2469 b->type = bp_breakpoint;
2470 b->cond = cond;
2471 b->enable = enabled;
2472 b->disposition = tempflag ? delete : donttouch;
2473
2474 mention (b);
2475 }
2476
2477 if (sals.nelts > 1)
2478 {
2479 printf_unfiltered ("Multiple breakpoints were set.\n");
2480 printf_unfiltered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
2481 }
2482 free ((PTR)sals.sals);
2483 }
2484
2485 #if 0
2486 /* These aren't used; I don't know what they were for. */
2487 /* Disable breakpoints on all catch clauses described in ARGS. */
2488 static void
2489 disable_catch (args)
2490 char *args;
2491 {
2492 /* Map the disable command to catch clauses described in ARGS. */
2493 }
2494
2495 /* Enable breakpoints on all catch clauses described in ARGS. */
2496 static void
2497 enable_catch (args)
2498 char *args;
2499 {
2500 /* Map the disable command to catch clauses described in ARGS. */
2501 }
2502
2503 /* Delete breakpoints on all catch clauses in the active scope. */
2504 static void
2505 delete_catch (args)
2506 char *args;
2507 {
2508 /* Map the delete command to catch clauses described in ARGS. */
2509 }
2510 #endif /* 0 */
2511
2512 static void
2513 catch_command (arg, from_tty)
2514 char *arg;
2515 int from_tty;
2516 {
2517 catch_command_1 (arg, 0, from_tty);
2518 }
2519 \f
2520 static void
2521 clear_command (arg, from_tty)
2522 char *arg;
2523 int from_tty;
2524 {
2525 register struct breakpoint *b, *b1;
2526 struct symtabs_and_lines sals;
2527 struct symtab_and_line sal;
2528 register struct breakpoint *found;
2529 int i;
2530
2531 if (arg)
2532 {
2533 sals = decode_line_spec (arg, 1);
2534 }
2535 else
2536 {
2537 sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
2538 sal.line = default_breakpoint_line;
2539 sal.symtab = default_breakpoint_symtab;
2540 sal.pc = 0;
2541 if (sal.symtab == 0)
2542 error ("No source file specified.");
2543
2544 sals.sals[0] = sal;
2545 sals.nelts = 1;
2546 }
2547
2548 for (i = 0; i < sals.nelts; i++)
2549 {
2550 /* If exact pc given, clear bpts at that pc.
2551 But if sal.pc is zero, clear all bpts on specified line. */
2552 sal = sals.sals[i];
2553 found = (struct breakpoint *) 0;
2554 while (breakpoint_chain
2555 && (sal.pc
2556 ? breakpoint_chain->address == sal.pc
2557 : (breakpoint_chain->source_file != NULL
2558 && sal.symtab != NULL
2559 && STREQ (breakpoint_chain->source_file,
2560 sal.symtab->filename)
2561 && breakpoint_chain->line_number == sal.line)))
2562 {
2563 b1 = breakpoint_chain;
2564 breakpoint_chain = b1->next;
2565 b1->next = found;
2566 found = b1;
2567 }
2568
2569 ALL_BREAKPOINTS (b)
2570 while (b->next
2571 && b->next->type != bp_watchpoint
2572 && (sal.pc
2573 ? b->next->address == sal.pc
2574 : (b->next->source_file != NULL
2575 && sal.symtab != NULL
2576 && STREQ (b->next->source_file, sal.symtab->filename)
2577 && b->next->line_number == sal.line)))
2578 {
2579 b1 = b->next;
2580 b->next = b1->next;
2581 b1->next = found;
2582 found = b1;
2583 }
2584
2585 if (found == 0)
2586 {
2587 if (arg)
2588 error ("No breakpoint at %s.", arg);
2589 else
2590 error ("No breakpoint at this line.");
2591 }
2592
2593 if (found->next) from_tty = 1; /* Always report if deleted more than one */
2594 if (from_tty) printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
2595 while (found)
2596 {
2597 if (from_tty) printf_unfiltered ("%d ", found->number);
2598 b1 = found->next;
2599 delete_breakpoint (found);
2600 found = b1;
2601 }
2602 if (from_tty) putchar_unfiltered ('\n');
2603 }
2604 free ((PTR)sals.sals);
2605 }
2606 \f
2607 /* Delete breakpoint in BS if they are `delete' breakpoints.
2608 This is called after any breakpoint is hit, or after errors. */
2609
2610 void
2611 breakpoint_auto_delete (bs)
2612 bpstat bs;
2613 {
2614 for (; bs; bs = bs->next)
2615 if (bs->breakpoint_at && bs->breakpoint_at->disposition == delete
2616 && bs->stop)
2617 delete_breakpoint (bs->breakpoint_at);
2618 }
2619
2620 /* Delete a breakpoint and clean up all traces of it in the data structures. */
2621
2622 void
2623 delete_breakpoint (bpt)
2624 struct breakpoint *bpt;
2625 {
2626 register struct breakpoint *b;
2627 register bpstat bs;
2628
2629 if (bpt->inserted)
2630 target_remove_breakpoint(bpt->address, bpt->shadow_contents);
2631
2632 if (breakpoint_chain == bpt)
2633 breakpoint_chain = bpt->next;
2634
2635 ALL_BREAKPOINTS (b)
2636 if (b->next == bpt)
2637 {
2638 b->next = bpt->next;
2639 break;
2640 }
2641
2642 check_duplicates (bpt->address);
2643 /* If this breakpoint was inserted, and there is another breakpoint
2644 at the same address, we need to insert the other breakpoint. */
2645 if (bpt->inserted)
2646 {
2647 ALL_BREAKPOINTS (b)
2648 if (b->address == bpt->address
2649 && !b->duplicate
2650 && b->enable != disabled)
2651 {
2652 int val;
2653 val = target_insert_breakpoint (b->address, b->shadow_contents);
2654 if (val != 0)
2655 {
2656 target_terminal_ours_for_output ();
2657 fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number);
2658 memory_error (val, b->address); /* which bombs us out */
2659 }
2660 else
2661 b->inserted = 1;
2662 }
2663 }
2664
2665 free_command_lines (&bpt->commands);
2666 if (bpt->cond)
2667 free (bpt->cond);
2668 if (bpt->cond_string != NULL)
2669 free (bpt->cond_string);
2670 if (bpt->addr_string != NULL)
2671 free (bpt->addr_string);
2672 if (bpt->exp_string != NULL)
2673 free (bpt->exp_string);
2674 if (bpt->source_file != NULL)
2675 free (bpt->source_file);
2676
2677 if (xgdb_verbose && bpt->type == bp_breakpoint)
2678 {
2679 target_terminal_ours_for_output ();
2680 printf_unfiltered ("breakpoint #%d deleted\n", bpt->number);
2681 }
2682
2683 /* Be sure no bpstat's are pointing at it after it's been freed. */
2684 /* FIXME, how can we find all bpstat's?
2685 We just check stop_bpstat for now. */
2686 for (bs = stop_bpstat; bs; bs = bs->next)
2687 if (bs->breakpoint_at == bpt)
2688 bs->breakpoint_at = NULL;
2689 free ((PTR)bpt);
2690 }
2691
2692 static void
2693 delete_command (arg, from_tty)
2694 char *arg;
2695 int from_tty;
2696 {
2697
2698 if (arg == 0)
2699 {
2700 /* Ask user only if there are some breakpoints to delete. */
2701 if (!from_tty
2702 || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0)))
2703 {
2704 /* No arg; clear all breakpoints. */
2705 while (breakpoint_chain)
2706 delete_breakpoint (breakpoint_chain);
2707 }
2708 }
2709 else
2710 map_breakpoint_numbers (arg, delete_breakpoint);
2711 }
2712
2713 /* Reset a breakpoint given it's struct breakpoint * BINT.
2714 The value we return ends up being the return value from catch_errors.
2715 Unused in this case. */
2716
2717 static int
2718 breakpoint_re_set_one (bint)
2719 char *bint;
2720 {
2721 struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */
2722 int i;
2723 struct symtabs_and_lines sals;
2724 char *s;
2725 enum enable save_enable;
2726
2727 switch (b->type)
2728 {
2729 case bp_breakpoint:
2730 if (b->addr_string == NULL)
2731 {
2732 /* Anything without a string can't be re-set. */
2733 delete_breakpoint (b);
2734 return 0;
2735 }
2736 /* In case we have a problem, disable this breakpoint. We'll restore
2737 its status if we succeed. */
2738 save_enable = b->enable;
2739 b->enable = disabled;
2740
2741 s = b->addr_string;
2742 sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0, (char ***)NULL);
2743 for (i = 0; i < sals.nelts; i++)
2744 {
2745 resolve_sal_pc (&sals.sals[i]);
2746
2747 /* Reparse conditions, they might contain references to the
2748 old symtab. */
2749 if (b->cond_string != NULL)
2750 {
2751 s = b->cond_string;
2752 if (b->cond)
2753 free ((PTR)b->cond);
2754 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
2755 }
2756
2757 /* We need to re-set the breakpoint if the address changes...*/
2758 if (b->address != sals.sals[i].pc
2759 /* ...or new and old breakpoints both have source files, and
2760 the source file name or the line number changes... */
2761 || (b->source_file != NULL
2762 && sals.sals[i].symtab != NULL
2763 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
2764 || b->line_number != sals.sals[i].line)
2765 )
2766 /* ...or we switch between having a source file and not having
2767 one. */
2768 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
2769 )
2770 {
2771 if (b->source_file != NULL)
2772 free (b->source_file);
2773 if (sals.sals[i].symtab == NULL)
2774 b->source_file = NULL;
2775 else
2776 b->source_file =
2777 savestring (sals.sals[i].symtab->filename,
2778 strlen (sals.sals[i].symtab->filename));
2779 b->line_number = sals.sals[i].line;
2780 b->address = sals.sals[i].pc;
2781
2782 check_duplicates (b->address);
2783
2784 mention (b);
2785 }
2786 b->enable = save_enable; /* Restore it, this worked. */
2787 }
2788 free ((PTR)sals.sals);
2789 break;
2790
2791 case bp_watchpoint:
2792 innermost_block = NULL;
2793 /* The issue arises of what context to evaluate this in. The same
2794 one as when it was set, but what does that mean when symbols have
2795 been re-read? We could save the filename and functionname, but
2796 if the context is more local than that, the best we could do would
2797 be something like how many levels deep and which index at that
2798 particular level, but that's going to be less stable than filenames
2799 or functionnames. */
2800 /* So for now, just use a global context. */
2801 b->exp = parse_expression (b->exp_string);
2802 b->exp_valid_block = innermost_block;
2803 b->val = evaluate_expression (b->exp);
2804 release_value (b->val);
2805 if (VALUE_LAZY (b->val))
2806 value_fetch_lazy (b->val);
2807
2808 if (b->cond_string != NULL)
2809 {
2810 s = b->cond_string;
2811 b->cond = parse_exp_1 (&s, (struct block *)0, 0);
2812 }
2813 if (b->enable == enabled)
2814 mention (b);
2815 break;
2816
2817 default:
2818 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
2819 /* fall through */
2820 case bp_until:
2821 case bp_finish:
2822 case bp_longjmp:
2823 case bp_longjmp_resume:
2824 case bp_call_dummy:
2825 delete_breakpoint (b);
2826 break;
2827 }
2828
2829 return 0;
2830 }
2831
2832 /* Re-set all breakpoints after symbols have been re-loaded. */
2833 void
2834 breakpoint_re_set ()
2835 {
2836 struct breakpoint *b, *temp;
2837 static char message1[] = "Error in re-setting breakpoint %d:\n";
2838 char message[sizeof (message1) + 30 /* slop */];
2839
2840 ALL_BREAKPOINTS_SAFE (b, temp)
2841 {
2842 sprintf (message, message1, b->number); /* Format possible error msg */
2843 catch_errors (breakpoint_re_set_one, (char *) b, message,
2844 RETURN_MASK_ALL);
2845 }
2846
2847 create_longjmp_breakpoint("longjmp");
2848 create_longjmp_breakpoint("_longjmp");
2849 create_longjmp_breakpoint("siglongjmp");
2850 create_longjmp_breakpoint(NULL);
2851
2852 #if 0
2853 /* Took this out (temporaliy at least), since it produces an extra
2854 blank line at startup. This messes up the gdbtests. -PB */
2855 /* Blank line to finish off all those mention() messages we just printed. */
2856 printf_filtered ("\n");
2857 #endif
2858 }
2859 \f
2860 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
2861 If from_tty is nonzero, it prints a message to that effect,
2862 which ends with a period (no newline). */
2863
2864 void
2865 set_ignore_count (bptnum, count, from_tty)
2866 int bptnum, count, from_tty;
2867 {
2868 register struct breakpoint *b;
2869
2870 if (count < 0)
2871 count = 0;
2872
2873 ALL_BREAKPOINTS (b)
2874 if (b->number == bptnum)
2875 {
2876 b->ignore_count = count;
2877 if (!from_tty)
2878 return;
2879 else if (count == 0)
2880 printf_filtered ("Will stop next time breakpoint %d is reached.",
2881 bptnum);
2882 else if (count == 1)
2883 printf_filtered ("Will ignore next crossing of breakpoint %d.",
2884 bptnum);
2885 else
2886 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
2887 count, bptnum);
2888 return;
2889 }
2890
2891 error ("No breakpoint number %d.", bptnum);
2892 }
2893
2894 /* Clear the ignore counts of all breakpoints. */
2895 void
2896 breakpoint_clear_ignore_counts ()
2897 {
2898 struct breakpoint *b;
2899
2900 ALL_BREAKPOINTS (b)
2901 b->ignore_count = 0;
2902 }
2903
2904 /* Command to set ignore-count of breakpoint N to COUNT. */
2905
2906 static void
2907 ignore_command (args, from_tty)
2908 char *args;
2909 int from_tty;
2910 {
2911 char *p = args;
2912 register int num;
2913
2914 if (p == 0)
2915 error_no_arg ("a breakpoint number");
2916
2917 num = get_number (&p);
2918
2919 if (*p == 0)
2920 error ("Second argument (specified ignore-count) is missing.");
2921
2922 set_ignore_count (num,
2923 longest_to_int (value_as_long (parse_and_eval (p))),
2924 from_tty);
2925 printf_filtered ("\n");
2926 }
2927 \f
2928 /* Call FUNCTION on each of the breakpoints
2929 whose numbers are given in ARGS. */
2930
2931 static void
2932 map_breakpoint_numbers (args, function)
2933 char *args;
2934 void (*function) PARAMS ((struct breakpoint *));
2935 {
2936 register char *p = args;
2937 char *p1;
2938 register int num;
2939 register struct breakpoint *b;
2940
2941 if (p == 0)
2942 error_no_arg ("one or more breakpoint numbers");
2943
2944 while (*p)
2945 {
2946 p1 = p;
2947
2948 num = get_number (&p1);
2949
2950 ALL_BREAKPOINTS (b)
2951 if (b->number == num)
2952 {
2953 function (b);
2954 goto win;
2955 }
2956 printf_unfiltered ("No breakpoint number %d.\n", num);
2957 win:
2958 p = p1;
2959 }
2960 }
2961
2962 static void
2963 enable_breakpoint (bpt)
2964 struct breakpoint *bpt;
2965 {
2966 FRAME save_selected_frame = NULL;
2967 int save_selected_frame_level = -1;
2968
2969 bpt->enable = enabled;
2970
2971 if (xgdb_verbose && bpt->type == bp_breakpoint)
2972 printf_unfiltered ("breakpoint #%d enabled\n", bpt->number);
2973
2974 check_duplicates (bpt->address);
2975 if (bpt->type == bp_watchpoint)
2976 {
2977 if (bpt->exp_valid_block != NULL)
2978 {
2979 FRAME fr = within_scope (bpt->exp_valid_block);
2980 if (fr == NULL)
2981 {
2982 printf_filtered ("\
2983 Cannot enable watchpoint %d because the block in which its expression\n\
2984 is valid is not currently in scope.\n", bpt->number);
2985 bpt->enable = disabled;
2986 return;
2987 }
2988 save_selected_frame = selected_frame;
2989 save_selected_frame_level = selected_frame_level;
2990 select_frame (fr, -1);
2991 }
2992
2993 value_free (bpt->val);
2994
2995 bpt->val = evaluate_expression (bpt->exp);
2996 release_value (bpt->val);
2997 if (VALUE_LAZY (bpt->val))
2998 value_fetch_lazy (bpt->val);
2999
3000 if (save_selected_frame_level >= 0)
3001 select_frame (save_selected_frame, save_selected_frame_level);
3002 }
3003 }
3004
3005 /* ARGSUSED */
3006 static void
3007 enable_command (args, from_tty)
3008 char *args;
3009 int from_tty;
3010 {
3011 struct breakpoint *bpt;
3012 if (args == 0)
3013 ALL_BREAKPOINTS (bpt)
3014 switch (bpt->type)
3015 {
3016 case bp_breakpoint:
3017 case bp_watchpoint:
3018 enable_breakpoint (bpt);
3019 default:
3020 continue;
3021 }
3022 else
3023 map_breakpoint_numbers (args, enable_breakpoint);
3024 }
3025
3026 static void
3027 disable_breakpoint (bpt)
3028 struct breakpoint *bpt;
3029 {
3030 bpt->enable = disabled;
3031
3032 if (xgdb_verbose && bpt->type == bp_breakpoint)
3033 printf_filtered ("breakpoint #%d disabled\n", bpt->number);
3034
3035 check_duplicates (bpt->address);
3036 }
3037
3038 /* ARGSUSED */
3039 static void
3040 disable_command (args, from_tty)
3041 char *args;
3042 int from_tty;
3043 {
3044 register struct breakpoint *bpt;
3045 if (args == 0)
3046 ALL_BREAKPOINTS (bpt)
3047 switch (bpt->type)
3048 {
3049 case bp_breakpoint:
3050 case bp_watchpoint:
3051 disable_breakpoint (bpt);
3052 default:
3053 continue;
3054 }
3055 else
3056 map_breakpoint_numbers (args, disable_breakpoint);
3057 }
3058
3059 static void
3060 enable_once_breakpoint (bpt)
3061 struct breakpoint *bpt;
3062 {
3063 bpt->enable = enabled;
3064 bpt->disposition = disable;
3065
3066 check_duplicates (bpt->address);
3067 }
3068
3069 /* ARGSUSED */
3070 static void
3071 enable_once_command (args, from_tty)
3072 char *args;
3073 int from_tty;
3074 {
3075 map_breakpoint_numbers (args, enable_once_breakpoint);
3076 }
3077
3078 static void
3079 enable_delete_breakpoint (bpt)
3080 struct breakpoint *bpt;
3081 {
3082 bpt->enable = enabled;
3083 bpt->disposition = delete;
3084
3085 check_duplicates (bpt->address);
3086 }
3087
3088 /* ARGSUSED */
3089 static void
3090 enable_delete_command (args, from_tty)
3091 char *args;
3092 int from_tty;
3093 {
3094 map_breakpoint_numbers (args, enable_delete_breakpoint);
3095 }
3096 \f
3097 /*
3098 * Use default_breakpoint_'s, or nothing if they aren't valid.
3099 */
3100 struct symtabs_and_lines
3101 decode_line_spec_1 (string, funfirstline)
3102 char *string;
3103 int funfirstline;
3104 {
3105 struct symtabs_and_lines sals;
3106 if (string == 0)
3107 error ("Empty line specification.");
3108 if (default_breakpoint_valid)
3109 sals = decode_line_1 (&string, funfirstline,
3110 default_breakpoint_symtab, default_breakpoint_line,
3111 (char ***)NULL);
3112 else
3113 sals = decode_line_1 (&string, funfirstline,
3114 (struct symtab *)NULL, 0, (char ***)NULL);
3115 if (*string)
3116 error ("Junk at end of line specification: %s", string);
3117 return sals;
3118 }
3119 \f
3120 void
3121 _initialize_breakpoint ()
3122 {
3123 breakpoint_chain = 0;
3124 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
3125 before a breakpoint is set. */
3126 breakpoint_count = 0;
3127
3128 add_com ("ignore", class_breakpoint, ignore_command,
3129 "Set ignore-count of breakpoint number N to COUNT.");
3130
3131 add_com ("commands", class_breakpoint, commands_command,
3132 "Set commands to be executed when a breakpoint is hit.\n\
3133 Give breakpoint number as argument after \"commands\".\n\
3134 With no argument, the targeted breakpoint is the last one set.\n\
3135 The commands themselves follow starting on the next line.\n\
3136 Type a line containing \"end\" to indicate the end of them.\n\
3137 Give \"silent\" as the first line to make the breakpoint silent;\n\
3138 then no output is printed when it is hit, except what the commands print.");
3139
3140 add_com ("condition", class_breakpoint, condition_command,
3141 "Specify breakpoint number N to break only if COND is true.\n\
3142 N is an integer; COND is an expression to be evaluated whenever\n\
3143 breakpoint N is reached. ");
3144
3145 add_com ("tbreak", class_breakpoint, tbreak_command,
3146 "Set a temporary breakpoint. Args like \"break\" command.\n\
3147 Like \"break\" except the breakpoint is only enabled temporarily,\n\
3148 so it will be disabled when hit. Equivalent to \"break\" followed\n\
3149 by using \"enable once\" on the breakpoint number.");
3150
3151 add_prefix_cmd ("enable", class_breakpoint, enable_command,
3152 "Enable some breakpoints.\n\
3153 Give breakpoint numbers (separated by spaces) as arguments.\n\
3154 With no subcommand, breakpoints are enabled until you command otherwise.\n\
3155 This is used to cancel the effect of the \"disable\" command.\n\
3156 With a subcommand you can enable temporarily.",
3157 &enablelist, "enable ", 1, &cmdlist);
3158
3159 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
3160 "Enable some breakpoints.\n\
3161 Give breakpoint numbers (separated by spaces) as arguments.\n\
3162 This is used to cancel the effect of the \"disable\" command.\n\
3163 May be abbreviated to simply \"enable\".\n",
3164 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
3165
3166 add_cmd ("once", no_class, enable_once_command,
3167 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
3168 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
3169 See the \"tbreak\" command which sets a breakpoint and enables it once.",
3170 &enablebreaklist);
3171
3172 add_cmd ("delete", no_class, enable_delete_command,
3173 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
3174 If a breakpoint is hit while enabled in this fashion, it is deleted.",
3175 &enablebreaklist);
3176
3177 add_cmd ("delete", no_class, enable_delete_command,
3178 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
3179 If a breakpoint is hit while enabled in this fashion, it is deleted.",
3180 &enablelist);
3181
3182 add_cmd ("once", no_class, enable_once_command,
3183 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
3184 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
3185 See the \"tbreak\" command which sets a breakpoint and enables it once.",
3186 &enablelist);
3187
3188 add_prefix_cmd ("disable", class_breakpoint, disable_command,
3189 "Disable some breakpoints.\n\
3190 Arguments are breakpoint numbers with spaces in between.\n\
3191 To disable all breakpoints, give no argument.\n\
3192 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
3193 &disablelist, "disable ", 1, &cmdlist);
3194 add_com_alias ("dis", "disable", class_breakpoint, 1);
3195 add_com_alias ("disa", "disable", class_breakpoint, 1);
3196
3197 add_cmd ("breakpoints", class_alias, disable_command,
3198 "Disable some breakpoints.\n\
3199 Arguments are breakpoint numbers with spaces in between.\n\
3200 To disable all breakpoints, give no argument.\n\
3201 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
3202 This command may be abbreviated \"disable\".",
3203 &disablelist);
3204
3205 add_prefix_cmd ("delete", class_breakpoint, delete_command,
3206 "Delete some breakpoints or auto-display expressions.\n\
3207 Arguments are breakpoint numbers with spaces in between.\n\
3208 To delete all breakpoints, give no argument.\n\
3209 \n\
3210 Also a prefix command for deletion of other GDB objects.\n\
3211 The \"unset\" command is also an alias for \"delete\".",
3212 &deletelist, "delete ", 1, &cmdlist);
3213 add_com_alias ("d", "delete", class_breakpoint, 1);
3214
3215 add_cmd ("breakpoints", class_alias, delete_command,
3216 "Delete some breakpoints or auto-display expressions.\n\
3217 Arguments are breakpoint numbers with spaces in between.\n\
3218 To delete all breakpoints, give no argument.\n\
3219 This command may be abbreviated \"delete\".",
3220 &deletelist);
3221
3222 add_com ("clear", class_breakpoint, clear_command,
3223 "Clear breakpoint at specified line or function.\n\
3224 Argument may be line number, function name, or \"*\" and an address.\n\
3225 If line number is specified, all breakpoints in that line are cleared.\n\
3226 If function is specified, breakpoints at beginning of function are cleared.\n\
3227 If an address is specified, breakpoints at that address are cleared.\n\n\
3228 With no argument, clears all breakpoints in the line that the selected frame\n\
3229 is executing in.\n\
3230 \n\
3231 See also the \"delete\" command which clears breakpoints by number.");
3232
3233 add_com ("break", class_breakpoint, break_command,
3234 "Set breakpoint at specified line or function.\n\
3235 Argument may be line number, function name, or \"*\" and an address.\n\
3236 If line number is specified, break at start of code for that line.\n\
3237 If function is specified, break at start of code for that function.\n\
3238 If an address is specified, break at that exact address.\n\
3239 With no arg, uses current execution address of selected stack frame.\n\
3240 This is useful for breaking on return to a stack frame.\n\
3241 \n\
3242 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
3243 \n\
3244 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
3245 add_com_alias ("b", "break", class_run, 1);
3246 add_com_alias ("br", "break", class_run, 1);
3247 add_com_alias ("bre", "break", class_run, 1);
3248 add_com_alias ("brea", "break", class_run, 1);
3249
3250 add_info ("breakpoints", breakpoints_info,
3251 "Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
3252 The \"Type\" column indicates one of:\n\
3253 \tbreakpoint - normal breakpoint\n\
3254 \twatchpoint - watchpoint\n\
3255 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
3256 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
3257 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
3258 address and file/line number respectively.\n\n\
3259 Convenience variable \"$_\" and default examine address for \"x\"\n\
3260 are set to the address of the last breakpoint listed.\n\n\
3261 Convenience variable \"$bpnum\" contains the number of the last\n\
3262 breakpoint set.");
3263
3264 #if MAINTENANCE_CMDS
3265
3266 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
3267 "Status of all breakpoints, or breakpoint number NUMBER.\n\
3268 The \"Type\" column indicates one of:\n\
3269 \tbreakpoint - normal breakpoint\n\
3270 \twatchpoint - watchpoint\n\
3271 \tlongjmp - internal breakpoint used to step through longjmp()\n\
3272 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
3273 \tuntil - internal breakpoint used by the \"until\" command\n\
3274 \tfinish - internal breakpoint used by the \"finish\" command\n\
3275 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
3276 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
3277 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
3278 address and file/line number respectively.\n\n\
3279 Convenience variable \"$_\" and default examine address for \"x\"\n\
3280 are set to the address of the last breakpoint listed.\n\n\
3281 Convenience variable \"$bpnum\" contains the number of the last\n\
3282 breakpoint set.",
3283 &maintenanceinfolist);
3284
3285 #endif /* MAINTENANCE_CMDS */
3286
3287 add_com ("catch", class_breakpoint, catch_command,
3288 "Set breakpoints to catch exceptions that are raised.\n\
3289 Argument may be a single exception to catch, multiple exceptions\n\
3290 to catch, or the default exception \"default\". If no arguments\n\
3291 are given, breakpoints are set at all exception handlers catch clauses\n\
3292 within the current scope.\n\
3293 \n\
3294 A condition specified for the catch applies to all breakpoints set\n\
3295 with this command\n\
3296 \n\
3297 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
3298
3299 add_com ("watch", class_breakpoint, watch_command,
3300 "Set a watchpoint for an expression.\n\
3301 A watchpoint stops execution of your program whenever the value of\n\
3302 an expression changes.");
3303
3304 add_info ("watchpoints", breakpoints_info,
3305 "Synonym for ``info breakpoints''.");
3306 }
3307
3308 /* OK, when we call objfile_relocate, we need to relocate breakpoints
3309 too. breakpoint_re_set is not a good choice--for example, if
3310 addr_string contains just a line number without a file name the
3311 breakpoint might get set in a different file. In general, there is
3312 no need to go all the way back to the user's string (though this might
3313 work if some effort were made to canonicalize it), since symtabs and
3314 everything except addresses are still valid.
3315
3316 Probably the best way to solve this is to have each breakpoint save
3317 the objfile and the section number that was used to set it (if set
3318 by "*addr", probably it is best to use find_pc_line to get a symtab
3319 and use the objfile and block_line_section for that symtab). Then
3320 objfile_relocate can call fixup_breakpoints with the objfile and
3321 the new_offsets, and it can relocate only the appropriate breakpoints. */
3322
3323 #ifdef IBM6000_TARGET
3324 /* But for now, just kludge it based on the concept that before an
3325 objfile is relocated the breakpoint is below 0x10000000, and afterwards
3326 it is higher, so that way we only relocate each breakpoint once. */
3327
3328 void
3329 fixup_breakpoints (low, high, delta)
3330 CORE_ADDR low;
3331 CORE_ADDR high;
3332 CORE_ADDR delta;
3333 {
3334 struct breakpoint *b;
3335
3336 ALL_BREAKPOINTS (b)
3337 {
3338 if (b->address >= low && b->address <= high)
3339 b->address += delta;
3340 }
3341 }
3342 #endif