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