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