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