*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
1 /* Everything about breakpoints, for GDB.
2 Copyright (C) 1986, 1987, 1989, 1990 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 GDB is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
9 any later version.
10
11 GDB is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GDB; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #include <stdio.h>
21 #include <ctype.h>
22 #include "defs.h"
23 #include "param.h"
24 #include "symtab.h"
25 #include "frame.h"
26 #include "breakpoint.h"
27 #include "expression.h"
28 #include "gdbcore.h"
29 #include "gdbcmd.h"
30 #include "value.h"
31 #include "ctype.h"
32 #include "command.h"
33 #include "inferior.h"
34 #include "target.h"
35 #include <string.h>
36
37 extern int addressprint; /* Print machine addresses? */
38 extern int demangle; /* Print de-mangled symbol names? */
39
40 extern int catch_errors ();
41 extern void set_next_address (); /* ...for x/ command */
42
43 /* Are we executing breakpoint commands? */
44 static int executing_breakpoint_commands;
45
46 /* States of enablement of breakpoint.
47 `temporary' means disable when hit.
48 `delete' means delete when hit. */
49
50 enum enable { disabled, enabled, temporary, delete};
51
52 /* Not that the ->silent field is not currently used by any commands
53 (though the code is in there if it was to be, and set_raw_breakpoint
54 does set it to 0). I implemented it because I thought it would be
55 useful for a hack I had to put in; I'm going to leave it in because
56 I can see how there might be times when it would indeed be useful */
57
58 /* This is for a breakpoint or a watchpoint. */
59
60 struct breakpoint
61 {
62 struct breakpoint *next;
63 /* Number assigned to distinguish breakpoints. */
64 int number;
65 /* Address to break at, or NULL if not a breakpoint. */
66 CORE_ADDR address;
67 /* Line number of this address. Redundant. Only matters if address
68 is non-NULL. */
69 int line_number;
70 /* Symtab of file of this address. Redundant. Only matters if address
71 is non-NULL. */
72 struct symtab *symtab;
73 /* Zero means disabled; remember the info but don't break here. */
74 enum enable enable;
75 /* Non-zero means a silent breakpoint (don't print frame info
76 if we stop here). */
77 unsigned char silent;
78 /* Number of stops at this breakpoint that should
79 be continued automatically before really stopping. */
80 int ignore_count;
81 /* "Real" contents of byte where breakpoint has been inserted.
82 Valid only when breakpoints are in the program. Under the complete
83 control of the target insert_breakpoint and remove_breakpoint routines.
84 No other code should assume anything about the value(s) here. */
85 char shadow_contents[BREAKPOINT_MAX];
86 /* Nonzero if this breakpoint is now inserted. Only matters if address
87 is non-NULL. */
88 char inserted;
89 /* Nonzero if this is not the first breakpoint in the list
90 for the given address. Only matters if address is non-NULL. */
91 char duplicate;
92 /* Chain of command lines to execute when this breakpoint is hit. */
93 struct command_line *commands;
94 /* Stack depth (address of frame). If nonzero, break only if fp
95 equals this. */
96 FRAME_ADDR frame;
97 /* Conditional. Break only if this expression's value is nonzero. */
98 struct expression *cond;
99
100 /* String we used to set the breakpoint (malloc'd). Only matters if
101 address is non-NULL. */
102 char *addr_string;
103 /* String form of the breakpoint condition (malloc'd), or NULL if there
104 is no condition. */
105 char *cond_string;
106
107 /* The expression we are watching, or NULL if not a watchpoint. */
108 struct expression *exp;
109 /* The largest block within which it is valid, or NULL if it is
110 valid anywhere (e.g. consists just of global symbols). */
111 struct block *exp_valid_block;
112 /* Value of the watchpoint the last time we checked it. */
113 value val;
114 };
115
116 #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
117
118 /* Chain of all breakpoints defined. */
119
120 struct breakpoint *breakpoint_chain;
121
122 /* Number of last breakpoint made. */
123
124 static int breakpoint_count;
125
126 /* Set breakpoint count to NUM. */
127 static void
128 set_breakpoint_count (num)
129 int num;
130 {
131 breakpoint_count = num;
132 set_internalvar (lookup_internalvar ("bpnum"),
133 value_from_long (builtin_type_int, (LONGEST) num));
134 }
135
136 /* Default address, symtab and line to put a breakpoint at
137 for "break" command with no arg.
138 if default_breakpoint_valid is zero, the other three are
139 not valid, and "break" with no arg is an error.
140
141 This set by print_stack_frame, which calls set_default_breakpoint. */
142
143 int default_breakpoint_valid;
144 CORE_ADDR default_breakpoint_address;
145 struct symtab *default_breakpoint_symtab;
146 int default_breakpoint_line;
147
148 static void delete_breakpoint ();
149 void breakpoint_auto_delete ();
150
151 /* Flag indicating extra verbosity for xgdb. */
152 extern int xgdb_verbose;
153 \f
154 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
155 Advance *PP after the string and any trailing whitespace.
156
157 Currently the string can either be a number or "$" followed by the name
158 of a convenience variable. Making it an expression wouldn't work well
159 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
160 static int
161 get_number (pp)
162 char **pp;
163 {
164 int retval;
165 char *p = *pp;
166
167 if (p == NULL)
168 /* Empty line means refer to the last breakpoint. */
169 return breakpoint_count;
170 else if (*p == '$')
171 {
172 /* Make a copy of the name, so we can null-terminate it
173 to pass to lookup_internalvar(). */
174 char *varname;
175 char *start = ++p;
176 value val;
177
178 while (isalnum (*p) || *p == '_')
179 p++;
180 varname = (char *) alloca (p - start + 1);
181 strncpy (varname, start, p - start);
182 varname[p - start] = '\0';
183 val = value_of_internalvar (lookup_internalvar (varname));
184 if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
185 error (
186 "Convenience variables used to specify breakpoints must have integer values."
187 );
188 retval = (int) value_as_long (val);
189 }
190 else
191 {
192 while (*p >= '0' && *p <= '9')
193 ++p;
194 if (p == *pp)
195 /* There is no number here. (e.g. "cond a == b"). */
196 error_no_arg ("breakpoint number");
197 retval = atoi (*pp);
198 }
199 if (!(isspace (*p) || *p == '\0'))
200 error ("breakpoint number expected");
201 while (isspace (*p))
202 p++;
203 *pp = p;
204 return retval;
205 }
206 \f
207 /* condition N EXP -- set break condition of breakpoint N to EXP. */
208
209 static void
210 condition_command (arg, from_tty)
211 char *arg;
212 int from_tty;
213 {
214 register struct breakpoint *b;
215 char *p;
216 register int bnum;
217
218 if (arg == 0)
219 error_no_arg ("breakpoint number");
220
221 p = arg;
222 bnum = get_number (&p);
223
224 ALL_BREAKPOINTS (b)
225 if (b->number == bnum)
226 {
227 if (b->cond)
228 {
229 free (b->cond);
230 b->cond = 0;
231 }
232 if (b->cond_string != NULL)
233 free (b->cond_string);
234
235 if (*p == 0)
236 {
237 b->cond = 0;
238 b->cond_string = NULL;
239 if (from_tty)
240 printf ("Breakpoint %d now unconditional.\n", bnum);
241 }
242 else
243 {
244 arg = p;
245 /* I don't know if it matters whether this is the string the user
246 typed in or the decompiled expression. */
247 b->cond_string = savestring (arg, strlen (arg));
248 b->cond = parse_c_1 (&arg, block_for_pc (b->address), 0);
249 if (*arg)
250 error ("Junk at end of expression");
251 }
252 return;
253 }
254
255 error ("No breakpoint number %d.", bnum);
256 }
257
258 static void
259 commands_command (arg, from_tty)
260 char *arg;
261 int from_tty;
262 {
263 register struct breakpoint *b;
264 char *p;
265 register int bnum;
266 struct command_line *l;
267
268 /* If we allowed this, we would have problems with when to
269 free the storage, if we change the commands currently
270 being read from. */
271
272 if (executing_breakpoint_commands)
273 error ("Can't use the \"commands\" command among a breakpoint's commands.");
274
275 p = arg;
276 bnum = get_number (&p);
277 if (p && *p)
278 error ("Unexpected extra arguments following breakpoint number.");
279
280 ALL_BREAKPOINTS (b)
281 if (b->number == bnum)
282 {
283 if (input_from_terminal_p ())
284 {
285 printf ("Type commands for when breakpoint %d is hit, one per line.\n\
286 End with a line saying just \"end\".\n", bnum);
287 fflush (stdout);
288 }
289 l = read_command_lines ();
290 free_command_lines (&b->commands);
291 b->commands = l;
292 return;
293 }
294 error ("No breakpoint number %d.", bnum);
295 }
296 \f
297 /* insert_breakpoints is used when starting or continuing the program.
298 remove_breakpoints is used when the program stops.
299 Both return zero if successful,
300 or an `errno' value if could not write the inferior. */
301
302 int
303 insert_breakpoints ()
304 {
305 register struct breakpoint *b;
306 int val = 0;
307 int disabled_breaks = 0;
308
309 ALL_BREAKPOINTS (b)
310 if (b->address != NULL
311 && b->enable != disabled
312 && ! b->inserted
313 && ! b->duplicate)
314 {
315 val = target_insert_breakpoint(b->address, b->shadow_contents);
316 if (val)
317 {
318 /* Can't set the breakpoint. */
319 #if defined (DISABLE_UNSETTABLE_BREAK)
320 if (DISABLE_UNSETTABLE_BREAK (b->address))
321 {
322 val = 0;
323 b->enable = disabled;
324 if (!disabled_breaks)
325 {
326 fprintf (stderr,
327 "Cannot insert breakpoint %d:\n", b->number);
328 printf_filtered ("Disabling shared library breakpoints:\n");
329 }
330 disabled_breaks = 1;
331 printf_filtered ("%d ", b->number);
332 }
333 else
334 #endif
335 {
336 fprintf (stderr, "Cannot insert breakpoint %d:\n", b->number);
337 memory_error (val, b->address); /* which bombs us out */
338 }
339 }
340 else
341 b->inserted = 1;
342 }
343 if (disabled_breaks)
344 printf_filtered ("\n");
345 return val;
346 }
347
348 int
349 remove_breakpoints ()
350 {
351 register struct breakpoint *b;
352 int val;
353
354 #ifdef BREAKPOINT_DEBUG
355 printf ("Removing breakpoints.\n");
356 #endif /* BREAKPOINT_DEBUG */
357
358 ALL_BREAKPOINTS (b)
359 if (b->address != NULL && b->inserted)
360 {
361 val = target_remove_breakpoint(b->address, b->shadow_contents);
362 if (val)
363 return val;
364 b->inserted = 0;
365 #ifdef BREAKPOINT_DEBUG
366 printf ("Removed breakpoint at 0x%x, shadow 0x%x, 0x%x.\n",
367 b->address, b->shadow_contents[0], b->shadow_contents[1]);
368 #endif /* BREAKPOINT_DEBUG */
369 }
370
371 return 0;
372 }
373
374 /* Clear the "inserted" flag in all breakpoints.
375 This is done when the inferior is loaded. */
376
377 void
378 mark_breakpoints_out ()
379 {
380 register struct breakpoint *b;
381
382 ALL_BREAKPOINTS (b)
383 b->inserted = 0;
384 }
385
386 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
387 When continuing from a location with a breakpoint,
388 we actually single step once before calling insert_breakpoints. */
389
390 int
391 breakpoint_here_p (pc)
392 CORE_ADDR pc;
393 {
394 register struct breakpoint *b;
395
396 ALL_BREAKPOINTS (b)
397 if (b->enable != disabled && b->address == pc)
398 return 1;
399
400 return 0;
401 }
402 \f
403 /* bpstat stuff. External routines' interfaces are documented
404 in breakpoint.h. */
405 void
406 bpstat_clear (bsp)
407 bpstat *bsp;
408 {
409 bpstat p;
410 bpstat q;
411
412 if (bsp == 0)
413 return;
414 p = *bsp;
415 while (p != NULL)
416 {
417 q = p->next;
418 if (p->old_val != NULL)
419 value_free (p->old_val);
420 free (p);
421 p = q;
422 }
423 *bsp = NULL;
424 }
425
426 bpstat
427 bpstat_copy (bs)
428 bpstat bs;
429 {
430 bpstat p = NULL;
431 bpstat tmp;
432 bpstat retval;
433
434 if (bs == NULL)
435 return bs;
436
437 for (; bs != NULL; bs = bs->next)
438 {
439 tmp = (bpstat) xmalloc (sizeof (*tmp));
440 bcopy (bs, tmp, sizeof (*tmp));
441 if (p == NULL)
442 /* This is the first thing in the chain. */
443 retval = tmp;
444 else
445 p->next = tmp;
446 p = tmp;
447 }
448 p->next = NULL;
449 return retval;
450 }
451
452 int
453 bpstat_num (bsp)
454 bpstat *bsp;
455 {
456 struct breakpoint *b;
457
458 if ((*bsp) == NULL)
459 return 0; /* No more breakpoint values */
460 else
461 {
462 b = (*bsp)->breakpoint_at;
463 *bsp = (*bsp)->next;
464 if (b == NULL)
465 return -1; /* breakpoint that's been deleted since */
466 else
467 return b->number; /* We have its number */
468 }
469 }
470
471 void
472 bpstat_clear_actions (bs)
473 bpstat bs;
474 {
475 for (; bs != NULL; bs = bs->next)
476 {
477 bs->commands = NULL;
478 if (bs->old_val != NULL)
479 {
480 value_free (bs->old_val);
481 bs->old_val = NULL;
482 }
483 }
484 }
485
486 /* Execute all the commands associated with all the breakpoints at this
487 location. Any of these commands could cause the process to proceed
488 beyond this point, etc. We look out for such changes by checking
489 the global "breakpoint_proceeded" after each command. */
490 void
491 bpstat_do_actions (bsp)
492 bpstat *bsp;
493 {
494 bpstat bs;
495
496 top:
497 bs = *bsp;
498
499 executing_breakpoint_commands = 1;
500 breakpoint_proceeded = 0;
501 for (; bs != NULL; bs = bs->next)
502 {
503 while (bs->commands)
504 {
505 char *line = bs->commands->line;
506 bs->commands = bs->commands->next;
507 execute_command (line, 0);
508 /* If the inferior is proceeded by the command, bomb out now.
509 The bpstat chain has been blown away by wait_for_inferior.
510 But since execution has stopped again, there is a new bpstat
511 to look at, so start over. */
512 if (breakpoint_proceeded)
513 goto top;
514 }
515 }
516 clear_momentary_breakpoints ();
517
518 executing_breakpoint_commands = 0;
519 }
520
521 int
522 bpstat_print (bs)
523 bpstat bs;
524 {
525 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
526 which has since been deleted. */
527 if (bs == NULL || bs->breakpoint_at == NULL)
528 return 0;
529
530 /* If bpstat_stop_status says don't print, OK, we won't. An example
531 circumstance is when we single-stepped for both a watchpoint and
532 for a "stepi" instruction. The bpstat says that the watchpoint
533 explains the stop, but we shouldn't print because the watchpoint's
534 value didn't change -- and the real reason we are stopping here
535 rather than continuing to step (as the watchpoint would've had us do)
536 is because of the "stepi". */
537 if (!bs->print)
538 return 0;
539
540 if (bs->breakpoint_at->address != NULL)
541 {
542 /* I think the user probably only wants to see one breakpoint
543 number, not all of them. */
544 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
545 return 0;
546 }
547
548 if (bs->old_val != NULL)
549 {
550 printf_filtered ("\nWatchpoint %d, ", bs->breakpoint_at->number);
551 print_expression (bs->breakpoint_at->exp, stdout);
552 printf_filtered ("\nOld value = ");
553 value_print (bs->old_val, stdout, 0, Val_pretty_default);
554 printf_filtered ("\nNew value = ");
555 value_print (bs->breakpoint_at->val, stdout, 0,
556 Val_pretty_default);
557 printf_filtered ("\n");
558 value_free (bs->old_val);
559 bs->old_val = NULL;
560 return 1;
561 }
562
563 fprintf_filtered (stderr, "gdb internal error: in bpstat_print\n");
564 return 0;
565 }
566
567 /* Evaluate the expression EXP and return 1 if value is zero.
568 This is used inside a catch_errors to evaluate the breakpoint condition.
569 The argument is a "struct expression *" that has been cast to int to
570 make it pass through catch_errors. */
571
572 static int
573 breakpoint_cond_eval (exp)
574 int exp;
575 {
576 return value_zerop (evaluate_expression ((struct expression *)exp));
577 }
578
579 /* Allocate a new bpstat and chain it to the current one. */
580
581 static bpstat
582 bpstat_alloc (b, cbs)
583 register struct breakpoint *b;
584 bpstat cbs; /* Current "bs" value */
585 {
586 bpstat bs;
587
588 bs = (bpstat) xmalloc (sizeof (*bs));
589 cbs->next = bs;
590 bs->breakpoint_at = b;
591 /* If the condition is false, etc., don't do the commands. */
592 bs->commands = NULL;
593 bs->momentary = b->number == -3;
594 bs->old_val = NULL;
595 return bs;
596 }
597
598 /* Determine whether we stopped at a breakpoint, etc, or whether we
599 don't understand this stop. Result is a chain of bpstat's such that:
600
601 if we don't understand the stop, the result is a null pointer.
602
603 if we understand why we stopped, the result is not null, and
604 the first element of the chain contains summary "stop" and
605 "print" flags for the whole chain.
606
607 Each element of the chain refers to a particular breakpoint or
608 watchpoint at which we have stopped. (We may have stopped for
609 several reasons.)
610
611 Each element of the chain has valid next, breakpoint_at,
612 commands, FIXME??? fields.
613
614 */
615
616
617 bpstat
618 bpstat_stop_status (pc, frame_address)
619 CORE_ADDR *pc;
620 FRAME_ADDR frame_address;
621 {
622 register struct breakpoint *b;
623 int stop = 0;
624 int print = 0;
625 CORE_ADDR bp_addr;
626 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
627 int real_breakpoint = 0;
628 /* Root of the chain of bpstat's */
629 struct bpstat__struct root_bs[1];
630 /* Pointer to the last thing in the chain currently. */
631 bpstat bs = root_bs;
632
633 /* Get the address where the breakpoint would have been. */
634 bp_addr = *pc - DECR_PC_AFTER_BREAK;
635
636 ALL_BREAKPOINTS (b)
637 {
638 int this_bp_stop;
639 int this_bp_print;
640
641 if (b->enable == disabled)
642 continue;
643 if (b->address != NULL && b->address != bp_addr)
644 continue;
645
646 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
647
648 this_bp_stop = 1;
649 this_bp_print = 1;
650
651 if (b->exp != NULL) /* Watchpoint */
652 {
653 int within_current_scope;
654 if (b->exp_valid_block != NULL)
655 within_current_scope =
656 contained_in (get_selected_block (), b->exp_valid_block);
657 else
658 within_current_scope = 1;
659
660 if (within_current_scope)
661 {
662 value new_val = evaluate_expression (b->exp);
663 release_value (new_val);
664 if (!value_equal (b->val, new_val))
665 {
666 bs->old_val = b->val;
667 b->val = new_val;
668 /* We will stop here */
669 }
670 else
671 {
672 /* Nothing changed, don't do anything. */
673 value_free (new_val);
674 continue;
675 /* We won't stop here */
676 }
677 }
678 else
679 {
680 /* This seems like the only logical thing to do because
681 if we temporarily ignored the watchpoint, then when
682 we reenter the block in which it is valid it contains
683 garbage (in the case of a function, it may have two
684 garbage values, one before and one after the prologue).
685 So we can't even detect the first assignment to it and
686 watch after that (since the garbage may or may not equal
687 the first value assigned). */
688 b->enable = disabled;
689 printf_filtered ("\
690 Watchpoint %d disabled because the program has left the block in\n\
691 which its expression is valid.\n", b->number);
692 /* We won't stop here */
693 /* FIXME, maybe we should stop here!!! */
694 continue;
695 }
696 }
697 else
698 real_breakpoint = 1;
699
700 if (b->frame && b->frame != frame_address)
701 this_bp_stop = 0;
702 else
703 {
704 int value_zero;
705
706 if (b->cond)
707 {
708 /* Need to select the frame, with all that implies
709 so that the conditions will have the right context. */
710 select_frame (get_current_frame (), 0);
711 value_zero
712 = catch_errors (breakpoint_cond_eval, (int)(b->cond),
713 "Error occurred in testing breakpoint condition.");
714 free_all_values ();
715 }
716 if (b->cond && value_zero)
717 {
718 this_bp_stop = 0;
719 }
720 else if (b->ignore_count > 0)
721 {
722 b->ignore_count--;
723 this_bp_stop = 0;
724 }
725 else
726 {
727 /* We will stop here */
728 if (b->enable == temporary)
729 b->enable = disabled;
730 bs->commands = b->commands;
731 if (b->silent)
732 this_bp_print = 0;
733 if (bs->commands && !strcmp ("silent", bs->commands->line))
734 {
735 bs->commands = bs->commands->next;
736 this_bp_print = 0;
737 }
738 }
739 }
740 if (this_bp_stop)
741 stop = 1;
742 if (this_bp_print)
743 print = 1;
744 }
745
746 bs->next = NULL; /* Terminate the chain */
747 bs = root_bs->next; /* Re-grab the head of the chain */
748 if (bs)
749 {
750 bs->stop = stop;
751 bs->print = print;
752 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
753 if (real_breakpoint)
754 {
755 *pc = bp_addr;
756 #if defined (SHIFT_INST_REGS)
757 {
758 CORE_ADDR pc = read_register (PC_REGNUM);
759 CORE_ADDR npc = read_register (NPC_REGNUM);
760 if (pc != npc)
761 {
762 write_register (NNPC_REGNUM, npc);
763 write_register (NPC_REGNUM, pc);
764 }
765 }
766 #else /* No SHIFT_INST_REGS. */
767 write_pc (bp_addr);
768 #endif /* No SHIFT_INST_REGS. */
769 }
770 #endif /* DECR_PC_AFTER_BREAK != 0. */
771 }
772 return bs;
773 }
774
775 int
776 bpstat_should_step ()
777 {
778 struct breakpoint *b;
779 ALL_BREAKPOINTS (b)
780 if (b->enable != disabled && b->exp != NULL)
781 return 1;
782 return 0;
783 }
784 \f
785 /* Print information on breakpoint number BNUM, or -1 if all.
786 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
787 is nonzero, process only watchpoints. */
788
789 static void
790 breakpoint_1 (bnum, watchpoints)
791 int bnum;
792 int watchpoints;
793 {
794 register struct breakpoint *b;
795 register struct command_line *l;
796 register struct symbol *sym;
797 CORE_ADDR last_addr = (CORE_ADDR)-1;
798 int header_printed = 0;
799
800 ALL_BREAKPOINTS (b)
801 if (bnum == -1 || bnum == b->number)
802 {
803 if (b->address == NULL && !watchpoints)
804 {
805 if (bnum == -1)
806 continue;
807 error ("That is a watchpoint, not a breakpoint.");
808 }
809 if (b->address != NULL && watchpoints)
810 {
811 if (bnum == -1)
812 continue;
813 error ("That is a breakpoint, not a watchpoint.");
814 }
815
816 if (!header_printed)
817 {
818 if (watchpoints)
819 printf_filtered (" Enb Expression\n");
820 else if (addressprint)
821 printf_filtered (" Enb Address Where\n");
822 else
823 printf_filtered (" Enb Where\n");
824 header_printed = 1;
825 }
826
827 printf_filtered ("#%-3d %c ", b->number, "nyod"[(int) b->enable]);
828 if (b->address == NULL) {
829 printf_filtered (" ");
830 print_expression (b->exp, stdout);
831 } else {
832 if (addressprint)
833 printf_filtered (" 0x%08x ", b->address);
834
835 last_addr = b->address;
836 if (b->symtab)
837 {
838 sym = find_pc_function (b->address);
839 if (sym)
840 {
841 fputs_filtered (" in ", stdout);
842 fputs_demangled (SYMBOL_NAME (sym), stdout, 1);
843 fputs_filtered (" at ", stdout);
844 }
845 fputs_filtered (b->symtab->filename, stdout);
846 printf_filtered (":%d", b->line_number);
847 }
848 else
849 print_address_symbolic (b->address, stdout, demangle);
850 }
851
852 printf_filtered ("\n");
853
854 if (b->frame)
855 printf_filtered ("\tstop only in stack frame at 0x%x\n", b->frame);
856 if (b->cond)
857 {
858 printf_filtered ("\tstop only if ");
859 print_expression (b->cond, stdout);
860 printf_filtered ("\n");
861 }
862 if (b->ignore_count)
863 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
864 if ((l = b->commands))
865 while (l)
866 {
867 fputs_filtered ("\t", stdout);
868 fputs_filtered (l->line, stdout);
869 fputs_filtered ("\n", stdout);
870 l = l->next;
871 }
872 }
873
874 if (!header_printed)
875 {
876 char *which = watchpoints ? "watch" : "break";
877 if (bnum == -1)
878 printf_filtered ("No %spoints.\n", which);
879 else
880 printf_filtered ("No %spoint numbered %d.\n", which, bnum);
881 }
882
883 /* Compare against (CORE_ADDR)-1 in case some compiler decides
884 that a comparison of an unsigned with -1 is always false. */
885 if (last_addr != (CORE_ADDR)-1)
886 set_next_address (last_addr);
887 }
888
889 static void
890 breakpoints_info (bnum_exp, from_tty)
891 char *bnum_exp;
892 int from_tty;
893 {
894 int bnum = -1;
895
896 if (bnum_exp)
897 bnum = parse_and_eval_address (bnum_exp);
898
899 breakpoint_1 (bnum, 0);
900 }
901
902 static void
903 watchpoints_info (bnum_exp, from_tty)
904 char *bnum_exp;
905 int from_tty;
906 {
907 int bnum = -1;
908
909 if (bnum_exp)
910 bnum = parse_and_eval_address (bnum_exp);
911
912 breakpoint_1 (bnum, 1);
913 }
914
915 /* Print a message describing any breakpoints set at PC. */
916
917 static void
918 describe_other_breakpoints (pc)
919 register CORE_ADDR pc;
920 {
921 register int others = 0;
922 register struct breakpoint *b;
923
924 ALL_BREAKPOINTS (b)
925 if (b->address == pc)
926 others++;
927 if (others > 0)
928 {
929 printf ("Note: breakpoint%s ", (others > 1) ? "s" : "");
930 ALL_BREAKPOINTS (b)
931 if (b->address == pc)
932 {
933 others--;
934 printf ("%d%s%s ",
935 b->number,
936 (b->enable == disabled) ? " (disabled)" : "",
937 (others > 1) ? "," : ((others == 1) ? " and" : ""));
938 }
939 printf ("also set at pc 0x%x.\n", pc);
940 }
941 }
942 \f
943 /* Set the default place to put a breakpoint
944 for the `break' command with no arguments. */
945
946 void
947 set_default_breakpoint (valid, addr, symtab, line)
948 int valid;
949 CORE_ADDR addr;
950 struct symtab *symtab;
951 int line;
952 {
953 default_breakpoint_valid = valid;
954 default_breakpoint_address = addr;
955 default_breakpoint_symtab = symtab;
956 default_breakpoint_line = line;
957 }
958
959 /* Rescan breakpoints at address ADDRESS,
960 marking the first one as "first" and any others as "duplicates".
961 This is so that the bpt instruction is only inserted once. */
962
963 static void
964 check_duplicates (address)
965 CORE_ADDR address;
966 {
967 register struct breakpoint *b;
968 register int count = 0;
969
970 if (address == NULL) /* Watchpoints are uninteresting */
971 return;
972
973 ALL_BREAKPOINTS (b)
974 if (b->enable != disabled && b->address == address)
975 {
976 count++;
977 b->duplicate = count > 1;
978 }
979 }
980
981 /* Low level routine to set a breakpoint.
982 Takes as args the three things that every breakpoint must have.
983 Returns the breakpoint object so caller can set other things.
984 Does not set the breakpoint number!
985 Does not print anything.
986
987 ==> This routine should not be called if there is a chance of later
988 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
989 your arguments BEFORE calling this routine! */
990
991 static struct breakpoint *
992 set_raw_breakpoint (sal)
993 struct symtab_and_line sal;
994 {
995 register struct breakpoint *b, *b1;
996
997 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
998 bzero (b, sizeof *b);
999 b->address = sal.pc;
1000 b->symtab = sal.symtab;
1001 b->line_number = sal.line;
1002 b->enable = enabled;
1003 b->next = 0;
1004 b->silent = 0;
1005 b->ignore_count = 0;
1006 b->commands = NULL;
1007 b->frame = NULL;
1008
1009 /* Add this breakpoint to the end of the chain
1010 so that a list of breakpoints will come out in order
1011 of increasing numbers. */
1012
1013 b1 = breakpoint_chain;
1014 if (b1 == 0)
1015 breakpoint_chain = b;
1016 else
1017 {
1018 while (b1->next)
1019 b1 = b1->next;
1020 b1->next = b;
1021 }
1022
1023 check_duplicates (sal.pc);
1024
1025 return b;
1026 }
1027
1028 /* Set a breakpoint that will evaporate an end of command
1029 at address specified by SAL.
1030 Restrict it to frame FRAME if FRAME is nonzero. */
1031
1032 void
1033 set_momentary_breakpoint (sal, frame)
1034 struct symtab_and_line sal;
1035 FRAME frame;
1036 {
1037 register struct breakpoint *b;
1038 b = set_raw_breakpoint (sal);
1039 b->number = -3;
1040 b->enable = delete;
1041 b->frame = (frame ? FRAME_FP (frame) : 0);
1042 }
1043
1044 void
1045 clear_momentary_breakpoints ()
1046 {
1047 register struct breakpoint *b;
1048 ALL_BREAKPOINTS (b)
1049 if (b->number == -3)
1050 {
1051 delete_breakpoint (b);
1052 break;
1053 }
1054 }
1055 \f
1056 /* Tell the user we have just set a breakpoint B. */
1057 static void
1058 mention (b)
1059 struct breakpoint *b;
1060 {
1061 if (b->exp)
1062 {
1063 printf_filtered ("Watchpoint %d: ", b->number);
1064 print_expression (b->exp, stdout);
1065 }
1066 else
1067 {
1068 printf_filtered ("Breakpoint %d at 0x%x", b->number, b->address);
1069 if (b->symtab)
1070 printf_filtered (": file %s, line %d.",
1071 b->symtab->filename, b->line_number);
1072 }
1073 printf_filtered ("\n");
1074 }
1075
1076 #if 0
1077 /* Nobody calls this currently. */
1078 /* Set a breakpoint from a symtab and line.
1079 If TEMPFLAG is nonzero, it is a temporary breakpoint.
1080 ADDR_STRING is a malloc'd string holding the name of where we are
1081 setting the breakpoint. This is used later to re-set it after the
1082 program is relinked and symbols are reloaded.
1083 Print the same confirmation messages that the breakpoint command prints. */
1084
1085 void
1086 set_breakpoint (s, line, tempflag, addr_string)
1087 struct symtab *s;
1088 int line;
1089 int tempflag;
1090 char *addr_string;
1091 {
1092 register struct breakpoint *b;
1093 struct symtab_and_line sal;
1094
1095 sal.symtab = s;
1096 sal.line = line;
1097 sal.pc = find_line_pc (sal.symtab, sal.line);
1098 if (sal.pc == 0)
1099 error ("No line %d in file \"%s\".\n", sal.line, sal.symtab->filename);
1100 else
1101 {
1102 describe_other_breakpoints (sal.pc);
1103
1104 b = set_raw_breakpoint (sal);
1105 set_breakpoint_count (breakpoint_count + 1);
1106 b->number = breakpoint_count;
1107 b->cond = 0;
1108 b->addr_string = addr_string;
1109 if (tempflag)
1110 b->enable = temporary;
1111
1112 mention (b);
1113 }
1114 }
1115 #endif
1116 \f
1117 /* Set a breakpoint according to ARG (function, linenum or *address)
1118 and make it temporary if TEMPFLAG is nonzero. */
1119
1120 static void
1121 break_command_1 (arg, tempflag, from_tty)
1122 char *arg;
1123 int tempflag, from_tty;
1124 {
1125 struct symtabs_and_lines sals;
1126 struct symtab_and_line sal;
1127 register struct expression *cond = 0;
1128 register struct breakpoint *b;
1129
1130 /* Pointers in arg to the start, and one past the end, of the condition. */
1131 char *cond_start = NULL;
1132 char *cond_end;
1133 /* Pointers in arg to the start, and one past the end,
1134 of the address part. */
1135 char *addr_start = NULL;
1136 char *addr_end;
1137
1138 int i;
1139 CORE_ADDR pc;
1140
1141 sals.sals = NULL;
1142 sals.nelts = 0;
1143
1144 sal.line = sal.pc = sal.end = 0;
1145 sal.symtab = 0;
1146
1147 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
1148
1149 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1150 && (arg[2] == ' ' || arg[2] == '\t')))
1151 {
1152 if (default_breakpoint_valid)
1153 {
1154 sals.sals = (struct symtab_and_line *)
1155 xmalloc (sizeof (struct symtab_and_line));
1156 sal.pc = default_breakpoint_address;
1157 sal.line = default_breakpoint_line;
1158 sal.symtab = default_breakpoint_symtab;
1159 sals.sals[0] = sal;
1160 sals.nelts = 1;
1161 }
1162 else
1163 error ("No default breakpoint address now.");
1164 }
1165 else
1166 {
1167 addr_start = arg;
1168
1169 /* Force almost all breakpoints to be in terms of the
1170 current_source_symtab (which is decode_line_1's default). This
1171 should produce the results we want almost all of the time while
1172 leaving default_breakpoint_* alone. */
1173 if (default_breakpoint_valid
1174 && (!current_source_symtab
1175 || (arg && (*arg == '+' || *arg == '-'))))
1176 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1177 default_breakpoint_line);
1178 else
1179 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1180
1181 addr_end = arg;
1182 }
1183
1184 if (! sals.nelts)
1185 return;
1186
1187 for (i = 0; i < sals.nelts; i++)
1188 {
1189 sal = sals.sals[i];
1190 if (sal.pc == 0 && sal.symtab != 0)
1191 {
1192 pc = find_line_pc (sal.symtab, sal.line);
1193 if (pc == 0)
1194 error ("No line %d in file \"%s\".",
1195 sal.line, sal.symtab->filename);
1196 }
1197 else
1198 pc = sal.pc;
1199
1200 while (arg && *arg)
1201 {
1202 if (arg[0] == 'i' && arg[1] == 'f'
1203 && (arg[2] == ' ' || arg[2] == '\t'))
1204 {
1205 arg += 2;
1206 cond_start = arg;
1207 cond = parse_c_1 (&arg, block_for_pc (pc), 0);
1208 cond_end = arg;
1209 }
1210 else
1211 error ("Junk at end of arguments.");
1212 }
1213 sals.sals[i].pc = pc;
1214 }
1215
1216 for (i = 0; i < sals.nelts; i++)
1217 {
1218 sal = sals.sals[i];
1219
1220 if (from_tty)
1221 describe_other_breakpoints (sal.pc);
1222
1223 b = set_raw_breakpoint (sal);
1224 set_breakpoint_count (breakpoint_count + 1);
1225 b->number = breakpoint_count;
1226 b->cond = cond;
1227
1228 if (addr_start)
1229 b->addr_string = savestring (addr_start, addr_end - addr_start);
1230 if (cond_start)
1231 b->cond_string = savestring (cond_start, cond_end - cond_start);
1232
1233 if (tempflag)
1234 b->enable = temporary;
1235
1236 mention (b);
1237 }
1238
1239 if (sals.nelts > 1)
1240 {
1241 printf ("Multiple breakpoints were set.\n");
1242 printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1243 }
1244 free (sals.sals);
1245 }
1246
1247 void
1248 break_command (arg, from_tty)
1249 char *arg;
1250 int from_tty;
1251 {
1252 break_command_1 (arg, 0, from_tty);
1253 }
1254
1255 static void
1256 tbreak_command (arg, from_tty)
1257 char *arg;
1258 int from_tty;
1259 {
1260 break_command_1 (arg, 1, from_tty);
1261 }
1262
1263 static void
1264 watch_command (arg, from_tty)
1265 char *arg;
1266 int from_tty;
1267 {
1268 struct breakpoint *b;
1269 struct symtab_and_line sal;
1270 struct expression *exp;
1271 struct block *exp_valid_block;
1272 struct value *val;
1273
1274 sal.pc = NULL;
1275 sal.symtab = NULL;
1276 sal.line = 0;
1277
1278 /* Parse arguments. */
1279 innermost_block = NULL;
1280 exp = parse_c_expression (arg);
1281 exp_valid_block = innermost_block;
1282 val = evaluate_expression (exp);
1283 release_value (val);
1284
1285 /* Now set up the breakpoint. */
1286 b = set_raw_breakpoint (sal);
1287 set_breakpoint_count (breakpoint_count + 1);
1288 b->number = breakpoint_count;
1289 b->exp = exp;
1290 b->exp_valid_block = exp_valid_block;
1291 b->val = val;
1292 b->cond = 0;
1293 b->cond_string = NULL;
1294 mention (b);
1295 }
1296 \f
1297 /*
1298 * Helper routine for the until_command routine in infcmd.c. Here
1299 * because it uses the mechanisms of breakpoints.
1300 */
1301 void
1302 until_break_command (arg, from_tty)
1303 char *arg;
1304 int from_tty;
1305 {
1306 struct symtabs_and_lines sals;
1307 struct symtab_and_line sal;
1308 FRAME prev_frame = get_prev_frame (selected_frame);
1309
1310 clear_proceed_status ();
1311
1312 /* Set a breakpoint where the user wants it and at return from
1313 this function */
1314
1315 if (default_breakpoint_valid)
1316 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1317 default_breakpoint_line);
1318 else
1319 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1320
1321 if (sals.nelts != 1)
1322 error ("Couldn't get information on specified line.");
1323
1324 sal = sals.sals[0];
1325 free (sals.sals); /* malloc'd, so freed */
1326
1327 if (*arg)
1328 error ("Junk at end of arguments.");
1329
1330 if (sal.pc == 0 && sal.symtab != 0)
1331 sal.pc = find_line_pc (sal.symtab, sal.line);
1332
1333 if (sal.pc == 0)
1334 error ("No line %d in file \"%s\".", sal.line, sal.symtab->filename);
1335
1336 set_momentary_breakpoint (sal, selected_frame);
1337
1338 /* Keep within the current frame */
1339
1340 if (prev_frame)
1341 {
1342 struct frame_info *fi;
1343
1344 fi = get_frame_info (prev_frame);
1345 sal = find_pc_line (fi->pc, 0);
1346 sal.pc = fi->pc;
1347 set_momentary_breakpoint (sal, prev_frame);
1348 }
1349
1350 proceed (-1, -1, 0);
1351 }
1352 \f
1353 /* Set a breakpoint at the catch clause for NAME. */
1354 static int
1355 catch_breakpoint (name)
1356 char *name;
1357 {
1358 }
1359
1360 static int
1361 disable_catch_breakpoint ()
1362 {
1363 }
1364
1365 static int
1366 delete_catch_breakpoint ()
1367 {
1368 }
1369
1370 static int
1371 enable_catch_breakpoint ()
1372 {
1373 }
1374
1375 struct sal_chain
1376 {
1377 struct sal_chain *next;
1378 struct symtab_and_line sal;
1379 };
1380
1381 /* For each catch clause identified in ARGS, run FUNCTION
1382 with that clause as an argument. */
1383 static struct symtabs_and_lines
1384 map_catch_names (args, function)
1385 char *args;
1386 int (*function)();
1387 {
1388 register char *p = args;
1389 register char *p1;
1390 struct symtabs_and_lines sals;
1391 struct sal_chain *sal_chain = 0;
1392
1393 if (p == 0)
1394 error_no_arg ("one or more catch names");
1395
1396 sals.nelts = 0;
1397 sals.sals = NULL;
1398
1399 while (*p)
1400 {
1401 p1 = p;
1402 /* Don't swallow conditional part. */
1403 if (p1[0] == 'i' && p1[1] == 'f'
1404 && (p1[2] == ' ' || p1[2] == '\t'))
1405 break;
1406
1407 if (isalpha (*p1))
1408 {
1409 p1++;
1410 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
1411 p1++;
1412 }
1413
1414 if (*p1 && *p1 != ' ' && *p1 != '\t')
1415 error ("Arguments must be catch names.");
1416
1417 *p1 = 0;
1418 #if 0
1419 if (function (p))
1420 {
1421 struct sal_chain *next
1422 = (struct sal_chain *)alloca (sizeof (struct sal_chain));
1423 next->next = sal_chain;
1424 next->sal = get_catch_sal (p);
1425 sal_chain = next;
1426 goto win;
1427 }
1428 #endif
1429 printf ("No catch clause for exception %s.\n", p);
1430 win:
1431 p = p1;
1432 while (*p == ' ' || *p == '\t') p++;
1433 }
1434 }
1435
1436 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
1437
1438 static struct symtabs_and_lines
1439 get_catch_sals (this_level_only)
1440 int this_level_only;
1441 {
1442 extern struct blockvector *blockvector_for_pc ();
1443 register struct blockvector *bl;
1444 register struct block *block = get_frame_block (selected_frame);
1445 int index, have_default = 0;
1446 struct frame_info *fi = get_frame_info (selected_frame);
1447 CORE_ADDR pc = fi->pc;
1448 struct symtabs_and_lines sals;
1449 struct sal_chain *sal_chain = 0;
1450 char *blocks_searched;
1451
1452 sals.nelts = 0;
1453 sals.sals = NULL;
1454
1455 if (block == 0)
1456 error ("No symbol table info available.\n");
1457
1458 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
1459 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1460 bzero (blocks_searched, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1461
1462 while (block != 0)
1463 {
1464 CORE_ADDR end = BLOCK_END (block) - 4;
1465 int last_index;
1466
1467 if (bl != blockvector_for_pc (end, &index))
1468 error ("blockvector blotch");
1469 if (BLOCKVECTOR_BLOCK (bl, index) != block)
1470 error ("blockvector botch");
1471 last_index = BLOCKVECTOR_NBLOCKS (bl);
1472 index += 1;
1473
1474 /* Don't print out blocks that have gone by. */
1475 while (index < last_index
1476 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
1477 index++;
1478
1479 while (index < last_index
1480 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
1481 {
1482 if (blocks_searched[index] == 0)
1483 {
1484 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
1485 int nsyms;
1486 register int i;
1487 register struct symbol *sym;
1488
1489 nsyms = BLOCK_NSYMS (b);
1490
1491 for (i = 0; i < nsyms; i++)
1492 {
1493 sym = BLOCK_SYM (b, i);
1494 if (! strcmp (SYMBOL_NAME (sym), "default"))
1495 {
1496 if (have_default)
1497 continue;
1498 have_default = 1;
1499 }
1500 if (SYMBOL_CLASS (sym) == LOC_LABEL)
1501 {
1502 struct sal_chain *next = (struct sal_chain *)
1503 alloca (sizeof (struct sal_chain));
1504 next->next = sal_chain;
1505 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
1506 sal_chain = next;
1507 }
1508 }
1509 blocks_searched[index] = 1;
1510 }
1511 index++;
1512 }
1513 if (have_default)
1514 break;
1515 if (sal_chain && this_level_only)
1516 break;
1517
1518 /* After handling the function's top-level block, stop.
1519 Don't continue to its superblock, the block of
1520 per-file symbols. */
1521 if (BLOCK_FUNCTION (block))
1522 break;
1523 block = BLOCK_SUPERBLOCK (block);
1524 }
1525
1526 if (sal_chain)
1527 {
1528 struct sal_chain *tmp_chain;
1529
1530 /* Count the number of entries. */
1531 for (index = 0, tmp_chain = sal_chain; tmp_chain;
1532 tmp_chain = tmp_chain->next)
1533 index++;
1534
1535 sals.nelts = index;
1536 sals.sals = (struct symtab_and_line *)
1537 xmalloc (index * sizeof (struct symtab_and_line));
1538 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
1539 sals.sals[index] = sal_chain->sal;
1540 }
1541
1542 return sals;
1543 }
1544
1545 /* Commands to deal with catching exceptions. */
1546
1547 void
1548 catch_command_1 (arg, tempflag, from_tty)
1549 char *arg;
1550 int tempflag;
1551 int from_tty;
1552 {
1553 /* First, translate ARG into something we can deal with in terms
1554 of breakpoints. */
1555
1556 struct symtabs_and_lines sals;
1557 struct symtab_and_line sal;
1558 register struct expression *cond = 0;
1559 register struct breakpoint *b;
1560 char *save_arg;
1561 int i;
1562 CORE_ADDR pc;
1563
1564 sal.line = sal.pc = sal.end = 0;
1565 sal.symtab = 0;
1566
1567 /* If no arg given, or if first arg is 'if ', all active catch clauses
1568 are breakpointed. */
1569
1570 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1571 && (arg[2] == ' ' || arg[2] == '\t')))
1572 {
1573 /* Grab all active catch clauses. */
1574 sals = get_catch_sals (0);
1575 }
1576 else
1577 {
1578 /* Grab selected catch clauses. */
1579 error ("catch NAME not implemeneted");
1580 sals = map_catch_names (arg, catch_breakpoint);
1581 }
1582
1583 if (! sals.nelts)
1584 return;
1585
1586 save_arg = arg;
1587 for (i = 0; i < sals.nelts; i++)
1588 {
1589 sal = sals.sals[i];
1590 if (sal.pc == 0 && sal.symtab != 0)
1591 {
1592 pc = find_line_pc (sal.symtab, sal.line);
1593 if (pc == 0)
1594 error ("No line %d in file \"%s\".",
1595 sal.line, sal.symtab->filename);
1596 }
1597 else
1598 pc = sal.pc;
1599
1600 while (arg && *arg)
1601 {
1602 if (arg[0] == 'i' && arg[1] == 'f'
1603 && (arg[2] == ' ' || arg[2] == '\t'))
1604 cond = (struct expression *) parse_c_1 ((arg += 2, &arg),
1605 block_for_pc (pc), 0);
1606 else
1607 error ("Junk at end of arguments.");
1608 }
1609 arg = save_arg;
1610 sals.sals[i].pc = pc;
1611 }
1612
1613 for (i = 0; i < sals.nelts; i++)
1614 {
1615 sal = sals.sals[i];
1616
1617 if (from_tty)
1618 describe_other_breakpoints (sal.pc);
1619
1620 b = set_raw_breakpoint (sal);
1621 b->number = ++breakpoint_count;
1622 b->cond = cond;
1623 if (tempflag)
1624 b->enable = temporary;
1625
1626 printf ("Breakpoint %d at 0x%x", b->number, b->address);
1627 if (b->symtab)
1628 printf (": file %s, line %d.", b->symtab->filename, b->line_number);
1629 printf ("\n");
1630 }
1631
1632 if (sals.nelts > 1)
1633 {
1634 printf ("Multiple breakpoints were set.\n");
1635 printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1636 }
1637 free (sals.sals);
1638 }
1639
1640 /* Disable breakpoints on all catch clauses described in ARGS. */
1641 static void
1642 disable_catch (args)
1643 char *args;
1644 {
1645 /* Map the disable command to catch clauses described in ARGS. */
1646 }
1647
1648 /* Enable breakpoints on all catch clauses described in ARGS. */
1649 static void
1650 enable_catch (args)
1651 char *args;
1652 {
1653 /* Map the disable command to catch clauses described in ARGS. */
1654 }
1655
1656 /* Delete breakpoints on all catch clauses in the active scope. */
1657 static void
1658 delete_catch (args)
1659 char *args;
1660 {
1661 /* Map the delete command to catch clauses described in ARGS. */
1662 }
1663
1664 static void
1665 catch_command (arg, from_tty)
1666 char *arg;
1667 int from_tty;
1668 {
1669 catch_command_1 (arg, 0, from_tty);
1670 }
1671 \f
1672 static void
1673 clear_command (arg, from_tty)
1674 char *arg;
1675 int from_tty;
1676 {
1677 register struct breakpoint *b, *b1;
1678 struct symtabs_and_lines sals;
1679 struct symtab_and_line sal;
1680 register struct breakpoint *found;
1681 int i;
1682
1683 if (arg)
1684 {
1685 sals = decode_line_spec (arg, 1);
1686 }
1687 else
1688 {
1689 sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
1690 sal.line = default_breakpoint_line;
1691 sal.symtab = default_breakpoint_symtab;
1692 sal.pc = 0;
1693 if (sal.symtab == 0)
1694 error ("No source file specified.");
1695
1696 sals.sals[0] = sal;
1697 sals.nelts = 1;
1698 }
1699
1700 for (i = 0; i < sals.nelts; i++)
1701 {
1702 /* If exact pc given, clear bpts at that pc.
1703 But if sal.pc is zero, clear all bpts on specified line. */
1704 sal = sals.sals[i];
1705 found = (struct breakpoint *) 0;
1706 while (breakpoint_chain
1707 && (sal.pc ? breakpoint_chain->address == sal.pc
1708 : (breakpoint_chain->symtab == sal.symtab
1709 && breakpoint_chain->line_number == sal.line)))
1710 {
1711 b1 = breakpoint_chain;
1712 breakpoint_chain = b1->next;
1713 b1->next = found;
1714 found = b1;
1715 }
1716
1717 ALL_BREAKPOINTS (b)
1718 while (b->next
1719 && b->next->address != NULL
1720 && (sal.pc ? b->next->address == sal.pc
1721 : (b->next->symtab == sal.symtab
1722 && b->next->line_number == sal.line)))
1723 {
1724 b1 = b->next;
1725 b->next = b1->next;
1726 b1->next = found;
1727 found = b1;
1728 }
1729
1730 if (found == 0)
1731 {
1732 if (arg)
1733 error ("No breakpoint at %s.", arg);
1734 else
1735 error ("No breakpoint at this line.");
1736 }
1737
1738 if (found->next) from_tty = 1; /* Always report if deleted more than one */
1739 if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : "");
1740 while (found)
1741 {
1742 if (from_tty) printf ("%d ", found->number);
1743 b1 = found->next;
1744 delete_breakpoint (found);
1745 found = b1;
1746 }
1747 if (from_tty) putchar ('\n');
1748 }
1749 free (sals.sals);
1750 }
1751 \f
1752 /* Delete breakpoint in BS if they are `delete' breakpoints.
1753 This is called after any breakpoint is hit, or after errors. */
1754
1755 void
1756 breakpoint_auto_delete (bs)
1757 bpstat bs;
1758 {
1759 for (; bs; bs = bs->next)
1760 if (bs->breakpoint_at && bs->breakpoint_at->enable == delete)
1761 delete_breakpoint (bs->breakpoint_at);
1762 }
1763
1764 /* Delete a breakpoint and clean up all traces of it in the data structures. */
1765
1766 static void
1767 delete_breakpoint (bpt)
1768 struct breakpoint *bpt;
1769 {
1770 register struct breakpoint *b;
1771 register bpstat bs;
1772
1773 if (bpt->inserted)
1774 target_remove_breakpoint(bpt->address, bpt->shadow_contents);
1775
1776 if (breakpoint_chain == bpt)
1777 breakpoint_chain = bpt->next;
1778
1779 ALL_BREAKPOINTS (b)
1780 if (b->next == bpt)
1781 {
1782 b->next = bpt->next;
1783 break;
1784 }
1785
1786 check_duplicates (bpt->address);
1787
1788 free_command_lines (&bpt->commands);
1789 if (bpt->cond)
1790 free (bpt->cond);
1791 if (bpt->cond_string != NULL)
1792 free (bpt->cond_string);
1793 if (bpt->addr_string != NULL)
1794 free (bpt->addr_string);
1795
1796 if (xgdb_verbose && bpt->number >=0)
1797 printf ("breakpoint #%d deleted\n", bpt->number);
1798
1799 /* Be sure no bpstat's are pointing at it after it's been freed. */
1800 /* FIXME, how can we find all bpstat's? We just check stop_bpstat for now. */
1801 for (bs = stop_bpstat; bs; bs = bs->next)
1802 if (bs->breakpoint_at == bpt)
1803 bs->breakpoint_at = NULL;
1804 free (bpt);
1805 }
1806
1807 static void map_breakpoint_numbers ();
1808
1809 static void
1810 delete_command (arg, from_tty)
1811 char *arg;
1812 int from_tty;
1813 {
1814
1815 if (arg == 0)
1816 {
1817 /* Ask user only if there are some breakpoints to delete. */
1818 if (!from_tty
1819 || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0)))
1820 {
1821 /* No arg; clear all breakpoints. */
1822 while (breakpoint_chain)
1823 delete_breakpoint (breakpoint_chain);
1824 }
1825 }
1826 else
1827 map_breakpoint_numbers (arg, delete_breakpoint);
1828 }
1829
1830 static void
1831 breakpoint_re_set_one (bint)
1832 int bint;
1833 {
1834 struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */
1835 int i;
1836 struct symtabs_and_lines sals;
1837 struct symtab_and_line sal;
1838 char *s;
1839
1840 if (b->address != NULL && b->addr_string != NULL)
1841 {
1842 s = b->addr_string;
1843 sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0);
1844 for (i = 0; i < sals.nelts; i++)
1845 {
1846 sal = sals.sals[i];
1847
1848 b->symtab = sal.symtab;
1849 b->line_number = sal.line;
1850 if (sal.pc == 0 && sal.symtab != 0)
1851 {
1852 sal.pc = find_line_pc (sal.symtab, sal.line);
1853 if (sal.pc == 0)
1854 error ("No line %d in file \"%s\".",
1855 sal.line, sal.symtab->filename);
1856 }
1857 b->address = sal.pc;
1858
1859 if (b->cond_string != NULL)
1860 {
1861 s = b->cond_string;
1862 b->cond = parse_c_1 (&s, block_for_pc (sal.pc), 0);
1863 }
1864
1865 check_duplicates (b->address);
1866
1867 mention (b);
1868 }
1869 free (sals.sals);
1870 }
1871 else
1872 {
1873 /* Anything without a string can't be re-set. */
1874 delete_breakpoint (b);
1875 }
1876 }
1877
1878 /* Re-set all breakpoints after symbols have been re-loaded. */
1879 void
1880 breakpoint_re_set ()
1881 {
1882 struct breakpoint *b;
1883
1884 ALL_BREAKPOINTS (b)
1885 {
1886 b->symtab = 0; /* Be sure we don't point to old dead symtab */
1887 (void) catch_errors (breakpoint_re_set_one, (int) b,
1888 "Error in re-setting breakpoint");
1889 }
1890
1891 /* Blank line to finish off all those mention() messages we just printed. */
1892 printf_filtered ("\n");
1893 }
1894 \f
1895 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
1896 If from_tty is nonzero, it prints a message to that effect,
1897 which ends with a period (no newline). */
1898
1899 void
1900 set_ignore_count (bptnum, count, from_tty)
1901 int bptnum, count, from_tty;
1902 {
1903 register struct breakpoint *b;
1904
1905 if (count < 0)
1906 count = 0;
1907
1908 ALL_BREAKPOINTS (b)
1909 if (b->number == bptnum)
1910 {
1911 b->ignore_count = count;
1912 if (!from_tty)
1913 return;
1914 else if (count == 0)
1915 printf ("Will stop next time breakpoint %d is reached.", bptnum);
1916 else if (count == 1)
1917 printf ("Will ignore next crossing of breakpoint %d.", bptnum);
1918 else
1919 printf ("Will ignore next %d crossings of breakpoint %d.",
1920 count, bptnum);
1921 return;
1922 }
1923
1924 error ("No breakpoint number %d.", bptnum);
1925 }
1926
1927 /* Clear the ignore counts of all breakpoints. */
1928 void
1929 breakpoint_clear_ignore_counts ()
1930 {
1931 struct breakpoint *b;
1932
1933 ALL_BREAKPOINTS (b)
1934 b->ignore_count = 0;
1935 }
1936
1937 /* Command to set ignore-count of breakpoint N to COUNT. */
1938
1939 static void
1940 ignore_command (args, from_tty)
1941 char *args;
1942 int from_tty;
1943 {
1944 char *p = args;
1945 register int num;
1946
1947 if (p == 0)
1948 error_no_arg ("a breakpoint number");
1949
1950 num = get_number (&p);
1951
1952 if (*p == 0)
1953 error ("Second argument (specified ignore-count) is missing.");
1954
1955 set_ignore_count (num, parse_and_eval_address (p), from_tty);
1956 printf ("\n");
1957 }
1958 \f
1959 /* Call FUNCTION on each of the breakpoints
1960 whose numbers are given in ARGS. */
1961
1962 static void
1963 map_breakpoint_numbers (args, function)
1964 char *args;
1965 void (*function) ();
1966 {
1967 register char *p = args;
1968 char *p1;
1969 register int num;
1970 register struct breakpoint *b;
1971
1972 if (p == 0)
1973 error_no_arg ("one or more breakpoint numbers");
1974
1975 while (*p)
1976 {
1977 p1 = p;
1978
1979 num = get_number (&p1);
1980
1981 ALL_BREAKPOINTS (b)
1982 if (b->number == num)
1983 {
1984 function (b);
1985 goto win;
1986 }
1987 printf ("No breakpoint number %d.\n", num);
1988 win:
1989 p = p1;
1990 }
1991 }
1992
1993 static void
1994 enable_breakpoint (bpt)
1995 struct breakpoint *bpt;
1996 {
1997 bpt->enable = enabled;
1998
1999 if (xgdb_verbose && bpt->number >= 0)
2000 printf ("breakpoint #%d enabled\n", bpt->number);
2001
2002 check_duplicates (bpt->address);
2003 if (bpt->val != NULL)
2004 {
2005 if (bpt->exp_valid_block != NULL
2006 && !contained_in (get_selected_block (), bpt->exp_valid_block))
2007 {
2008 printf_filtered ("\
2009 Cannot enable watchpoint %d because the block in which its expression\n\
2010 is valid is not currently in scope.\n", bpt->number);
2011 return;
2012 }
2013
2014 value_free (bpt->val);
2015
2016 bpt->val = evaluate_expression (bpt->exp);
2017 release_value (bpt->val);
2018 }
2019 }
2020
2021 static void
2022 enable_command (args, from_tty)
2023 char *args;
2024 int from_tty;
2025 {
2026 struct breakpoint *bpt;
2027 if (args == 0)
2028 ALL_BREAKPOINTS (bpt)
2029 enable_breakpoint (bpt);
2030 else
2031 map_breakpoint_numbers (args, enable_breakpoint);
2032 }
2033
2034 static void
2035 disable_breakpoint (bpt)
2036 struct breakpoint *bpt;
2037 {
2038 bpt->enable = disabled;
2039
2040 if (xgdb_verbose && bpt->number >= 0)
2041 printf ("breakpoint #%d disabled\n", bpt->number);
2042
2043 check_duplicates (bpt->address);
2044 }
2045
2046 static void
2047 disable_command (args, from_tty)
2048 char *args;
2049 int from_tty;
2050 {
2051 register struct breakpoint *bpt;
2052 if (args == 0)
2053 ALL_BREAKPOINTS (bpt)
2054 disable_breakpoint (bpt);
2055 else
2056 map_breakpoint_numbers (args, disable_breakpoint);
2057 }
2058
2059 static void
2060 enable_once_breakpoint (bpt)
2061 struct breakpoint *bpt;
2062 {
2063 bpt->enable = temporary;
2064
2065 check_duplicates (bpt->address);
2066 }
2067
2068 static void
2069 enable_once_command (args, from_tty)
2070 char *args;
2071 int from_tty;
2072 {
2073 map_breakpoint_numbers (args, enable_once_breakpoint);
2074 }
2075
2076 static void
2077 enable_delete_breakpoint (bpt)
2078 struct breakpoint *bpt;
2079 {
2080 bpt->enable = delete;
2081
2082 check_duplicates (bpt->address);
2083 }
2084
2085 static void
2086 enable_delete_command (args, from_tty)
2087 char *args;
2088 int from_tty;
2089 {
2090 map_breakpoint_numbers (args, enable_delete_breakpoint);
2091 }
2092 \f
2093 /*
2094 * Use default_breakpoint_'s, or nothing if they aren't valid.
2095 */
2096 struct symtabs_and_lines
2097 decode_line_spec_1 (string, funfirstline)
2098 char *string;
2099 int funfirstline;
2100 {
2101 struct symtabs_and_lines sals;
2102 if (string == 0)
2103 error ("Empty line specification.");
2104 if (default_breakpoint_valid)
2105 sals = decode_line_1 (&string, funfirstline,
2106 default_breakpoint_symtab, default_breakpoint_line);
2107 else
2108 sals = decode_line_1 (&string, funfirstline, (struct symtab *)NULL, 0);
2109 if (*string)
2110 error ("Junk at end of line specification: %s", string);
2111 return sals;
2112 }
2113 \f
2114
2115 /* Chain containing all defined enable commands. */
2116
2117 extern struct cmd_list_element
2118 *enablelist, *disablelist,
2119 *deletelist, *enablebreaklist;
2120
2121 extern struct cmd_list_element *cmdlist;
2122
2123 void
2124 _initialize_breakpoint ()
2125 {
2126 breakpoint_chain = 0;
2127 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
2128 before a breakpoint is set. */
2129 breakpoint_count = 0;
2130
2131 add_com ("ignore", class_breakpoint, ignore_command,
2132 "Set ignore-count of breakpoint number N to COUNT.");
2133
2134 add_com ("commands", class_breakpoint, commands_command,
2135 "Set commands to be executed when a breakpoint is hit.\n\
2136 Give breakpoint number as argument after \"commands\".\n\
2137 With no argument, the targeted breakpoint is the last one set.\n\
2138 The commands themselves follow starting on the next line.\n\
2139 Type a line containing \"end\" to indicate the end of them.\n\
2140 Give \"silent\" as the first line to make the breakpoint silent;\n\
2141 then no output is printed when it is hit, except what the commands print.");
2142
2143 add_com ("condition", class_breakpoint, condition_command,
2144 "Specify breakpoint number N to break only if COND is true.\n\
2145 N is an integer; COND is a C expression to be evaluated whenever\n\
2146 breakpoint N is reached. Actually break only when COND is nonzero.");
2147
2148 add_com ("tbreak", class_breakpoint, tbreak_command,
2149 "Set a temporary breakpoint. Args like \"break\" command.\n\
2150 Like \"break\" except the breakpoint is only enabled temporarily,\n\
2151 so it will be disabled when hit. Equivalent to \"break\" followed\n\
2152 by using \"enable once\" on the breakpoint number.");
2153
2154 add_prefix_cmd ("enable", class_breakpoint, enable_command,
2155 "Enable some breakpoints.\n\
2156 Give breakpoint numbers (separated by spaces) as arguments.\n\
2157 With no subcommand, breakpoints are enabled until you command otherwise.\n\
2158 This is used to cancel the effect of the \"disable\" command.\n\
2159 With a subcommand you can enable temporarily.",
2160 &enablelist, "enable ", 1, &cmdlist);
2161
2162 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
2163 "Enable some breakpoints.\n\
2164 Give breakpoint numbers (separated by spaces) as arguments.\n\
2165 This is used to cancel the effect of the \"disable\" command.\n\
2166 May be abbreviated to simply \"enable\".\n",
2167 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
2168
2169 add_cmd ("once", no_class, enable_once_command,
2170 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
2171 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2172 See the \"tbreak\" command which sets a breakpoint and enables it once.",
2173 &enablebreaklist);
2174
2175 add_cmd ("delete", no_class, enable_delete_command,
2176 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
2177 If a breakpoint is hit while enabled in this fashion, it is deleted.",
2178 &enablebreaklist);
2179
2180 add_cmd ("delete", no_class, enable_delete_command,
2181 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
2182 If a breakpoint is hit while enabled in this fashion, it is deleted.",
2183 &enablelist);
2184
2185 add_cmd ("once", no_class, enable_once_command,
2186 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
2187 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2188 See the \"tbreak\" command which sets a breakpoint and enables it once.",
2189 &enablelist);
2190
2191 add_prefix_cmd ("disable", class_breakpoint, disable_command,
2192 "Disable some breakpoints.\n\
2193 Arguments are breakpoint numbers with spaces in between.\n\
2194 To disable all breakpoints, give no argument.\n\
2195 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
2196 &disablelist, "disable ", 1, &cmdlist);
2197 add_com_alias ("dis", "disable", class_breakpoint, 1);
2198 add_com_alias ("disa", "disable", class_breakpoint, 1);
2199
2200 add_cmd ("breakpoints", class_alias, disable_command,
2201 "Disable some breakpoints.\n\
2202 Arguments are breakpoint numbers with spaces in between.\n\
2203 To disable all breakpoints, give no argument.\n\
2204 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
2205 This command may be abbreviated \"disable\".",
2206 &disablelist);
2207
2208 add_prefix_cmd ("delete", class_breakpoint, delete_command,
2209 "Delete some breakpoints or auto-display expressions.\n\
2210 Arguments are breakpoint numbers with spaces in between.\n\
2211 To delete all breakpoints, give no argument.\n\
2212 \n\
2213 Also a prefix command for deletion of other GDB objects.\n\
2214 The \"unset\" command is also an alias for \"delete\".",
2215 &deletelist, "delete ", 1, &cmdlist);
2216 add_com_alias ("d", "delete", class_breakpoint, 1);
2217
2218 add_cmd ("breakpoints", class_alias, delete_command,
2219 "Delete some breakpoints or auto-display expressions.\n\
2220 Arguments are breakpoint numbers with spaces in between.\n\
2221 To delete all breakpoints, give no argument.\n\
2222 This command may be abbreviated \"delete\".",
2223 &deletelist);
2224
2225 add_com ("clear", class_breakpoint, clear_command,
2226 "Clear breakpoint at specified line or function.\n\
2227 Argument may be line number, function name, or \"*\" and an address.\n\
2228 If line number is specified, all breakpoints in that line are cleared.\n\
2229 If function is specified, breakpoints at beginning of function are cleared.\n\
2230 If an address is specified, breakpoints at that address are cleared.\n\n\
2231 With no argument, clears all breakpoints in the line that the selected frame\n\
2232 is executing in.\n\
2233 \n\
2234 See also the \"delete\" command which clears breakpoints by number.");
2235
2236 add_com ("break", class_breakpoint, break_command,
2237 "Set breakpoint at specified line or function.\n\
2238 Argument may be line number, function name, or \"*\" and an address.\n\
2239 If line number is specified, break at start of code for that line.\n\
2240 If function is specified, break at start of code for that function.\n\
2241 If an address is specified, break at that exact address.\n\
2242 With no arg, uses current execution address of selected stack frame.\n\
2243 This is useful for breaking on return to a stack frame.\n\
2244 \n\
2245 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
2246 \n\
2247 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2248 add_com_alias ("b", "break", class_run, 1);
2249 add_com_alias ("br", "break", class_run, 1);
2250 add_com_alias ("bre", "break", class_run, 1);
2251 add_com_alias ("brea", "break", class_run, 1);
2252
2253 add_info ("breakpoints", breakpoints_info,
2254 "Status of all breakpoints, or breakpoint number NUMBER.\n\
2255 Second column is \"y\" for enabled breakpoint, \"n\" for disabled,\n\
2256 \"o\" for enabled once (disable when hit), \"d\" for enable but delete when hit.\n\
2257 Then come the address and the file/line number.\n\n\
2258 Convenience variable \"$_\" and default examine address for \"x\"\n\
2259 are set to the address of the last breakpoint listed.\n\n\
2260 Convenience variable \"$bpnum\" contains the number of the last\n\
2261 breakpoint set.");
2262
2263 add_com ("catch", class_breakpoint, catch_command,
2264 "Set breakpoints to catch exceptions that are raised.\n\
2265 Argument may be a single exception to catch, multiple exceptions\n\
2266 to catch, or the default exception \"default\". If no arguments\n\
2267 are given, breakpoints are set at all exception handlers catch clauses\n\
2268 within the current scope.\n\
2269 \n\
2270 A condition specified for the catch applies to all breakpoints set\n\
2271 with this command\n\
2272 \n\
2273 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2274
2275 add_com ("watch", class_breakpoint, watch_command,
2276 "Set a watchpoint for an expression.\n\
2277 A watchpoint stops execution of your program whenever the value of\n\
2278 an expression changes.");
2279
2280 add_info ("watchpoints", watchpoints_info,
2281 "Status of all watchpoints, or watchpoint number NUMBER.\n\
2282 Second column is \"y\" for enabled watchpoints, \"n\" for disabled.");
2283 }
This page took 0.072837 seconds and 5 git commands to generate.