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