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