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