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