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