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