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