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