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