* sunos.c (sunos_read_dynamic_info): Assume that dynamic info
[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"
199b2450 33#include "thread.h"
bd5635a1 34#include "target.h"
d3b9c0df 35#include "language.h"
bd5635a1 36#include <string.h>
423e9664 37#include "demangle.h"
bd5635a1 38
30875e1c
SG
39/* local function prototypes */
40
41static void
42catch_command_1 PARAMS ((char *, int, int));
43
44static void
45enable_delete_command PARAMS ((char *, int));
46
47static void
48enable_delete_breakpoint PARAMS ((struct breakpoint *));
49
50static void
51enable_once_command PARAMS ((char *, int));
52
53static void
54enable_once_breakpoint PARAMS ((struct breakpoint *));
55
56static void
57disable_command PARAMS ((char *, int));
58
59static void
60disable_breakpoint PARAMS ((struct breakpoint *));
61
62static void
63enable_command PARAMS ((char *, int));
64
65static void
66enable_breakpoint PARAMS ((struct breakpoint *));
67
68static void
69map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *)));
70
71static void
72ignore_command PARAMS ((char *, int));
73
74static int
75breakpoint_re_set_one PARAMS ((char *));
76
77static void
78delete_command PARAMS ((char *, int));
79
80static void
81clear_command PARAMS ((char *, int));
82
83static void
84catch_command PARAMS ((char *, int));
85
86static struct symtabs_and_lines
87get_catch_sals PARAMS ((int));
88
89static void
90watch_command PARAMS ((char *, int));
91
92static void
93tbreak_command PARAMS ((char *, int));
94
95static void
96break_command_1 PARAMS ((char *, int, int));
97
98static void
99mention PARAMS ((struct breakpoint *));
100
101static struct breakpoint *
102set_raw_breakpoint PARAMS ((struct symtab_and_line));
103
104static void
105check_duplicates PARAMS ((CORE_ADDR));
106
107static void
108describe_other_breakpoints PARAMS ((CORE_ADDR));
109
30875e1c
SG
110static void
111breakpoints_info PARAMS ((char *, int));
112
113static void
423e9664 114breakpoint_1 PARAMS ((int, int));
30875e1c
SG
115
116static bpstat
117bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
118
119static int
120breakpoint_cond_eval PARAMS ((char *));
121
122static void
123cleanup_executing_breakpoints PARAMS ((int));
124
125static void
126commands_command PARAMS ((char *, int));
127
128static void
129condition_command PARAMS ((char *, int));
130
131static int
132get_number PARAMS ((char **));
133
134static void
135set_breakpoint_count PARAMS ((int));
136
137
bd5635a1
RP
138extern int addressprint; /* Print machine addresses? */
139extern int demangle; /* Print de-mangled symbol names? */
140
bd5635a1
RP
141/* Are we executing breakpoint commands? */
142static int executing_breakpoint_commands;
143
cba0d141
JG
144/* Walk the following statement or block through all breakpoints.
145 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
146 breakpoint. */
147
bd5635a1
RP
148#define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
149
cba0d141
JG
150#define ALL_BREAKPOINTS_SAFE(b,tmp) \
151 for (b = breakpoint_chain; \
152 b? (tmp=b->next, 1): 0; \
153 b = tmp)
154
bd5635a1
RP
155/* Chain of all breakpoints defined. */
156
05052b63 157static struct breakpoint *breakpoint_chain;
bd5635a1
RP
158
159/* Number of last breakpoint made. */
160
161static int breakpoint_count;
162
163/* Set breakpoint count to NUM. */
164static void
165set_breakpoint_count (num)
166 int num;
167{
168 breakpoint_count = num;
169 set_internalvar (lookup_internalvar ("bpnum"),
06b6c733 170 value_from_longest (builtin_type_int, (LONGEST) num));
bd5635a1
RP
171}
172
173/* Default address, symtab and line to put a breakpoint at
174 for "break" command with no arg.
175 if default_breakpoint_valid is zero, the other three are
176 not valid, and "break" with no arg is an error.
177
178 This set by print_stack_frame, which calls set_default_breakpoint. */
179
180int default_breakpoint_valid;
181CORE_ADDR default_breakpoint_address;
182struct symtab *default_breakpoint_symtab;
183int default_breakpoint_line;
184
bd5635a1
RP
185/* Flag indicating extra verbosity for xgdb. */
186extern int xgdb_verbose;
187\f
188/* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
189 Advance *PP after the string and any trailing whitespace.
190
191 Currently the string can either be a number or "$" followed by the name
192 of a convenience variable. Making it an expression wouldn't work well
193 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
194static int
195get_number (pp)
196 char **pp;
197{
198 int retval;
199 char *p = *pp;
200
201 if (p == NULL)
202 /* Empty line means refer to the last breakpoint. */
203 return breakpoint_count;
204 else if (*p == '$')
205 {
206 /* Make a copy of the name, so we can null-terminate it
207 to pass to lookup_internalvar(). */
208 char *varname;
209 char *start = ++p;
82a2edfb 210 value_ptr val;
bd5635a1
RP
211
212 while (isalnum (*p) || *p == '_')
213 p++;
214 varname = (char *) alloca (p - start + 1);
215 strncpy (varname, start, p - start);
216 varname[p - start] = '\0';
217 val = value_of_internalvar (lookup_internalvar (varname));
218 if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
219 error (
220"Convenience variables used to specify breakpoints must have integer values."
221 );
222 retval = (int) value_as_long (val);
223 }
224 else
225 {
80ba48f5
SG
226 if (*p == '-')
227 ++p;
bd5635a1
RP
228 while (*p >= '0' && *p <= '9')
229 ++p;
230 if (p == *pp)
231 /* There is no number here. (e.g. "cond a == b"). */
232 error_no_arg ("breakpoint number");
233 retval = atoi (*pp);
234 }
235 if (!(isspace (*p) || *p == '\0'))
236 error ("breakpoint number expected");
237 while (isspace (*p))
238 p++;
239 *pp = p;
240 return retval;
241}
242\f
243/* condition N EXP -- set break condition of breakpoint N to EXP. */
244
245static void
246condition_command (arg, from_tty)
247 char *arg;
248 int from_tty;
249{
250 register struct breakpoint *b;
251 char *p;
252 register int bnum;
253
254 if (arg == 0)
255 error_no_arg ("breakpoint number");
256
257 p = arg;
258 bnum = get_number (&p);
259
260 ALL_BREAKPOINTS (b)
261 if (b->number == bnum)
262 {
263 if (b->cond)
264 {
c8950965 265 free ((PTR)b->cond);
bd5635a1
RP
266 b->cond = 0;
267 }
268 if (b->cond_string != NULL)
c8950965 269 free ((PTR)b->cond_string);
bd5635a1
RP
270
271 if (*p == 0)
272 {
273 b->cond = 0;
274 b->cond_string = NULL;
275 if (from_tty)
423e9664 276 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
bd5635a1
RP
277 }
278 else
279 {
280 arg = p;
281 /* I don't know if it matters whether this is the string the user
282 typed in or the decompiled expression. */
283 b->cond_string = savestring (arg, strlen (arg));
d3b9c0df 284 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
bd5635a1
RP
285 if (*arg)
286 error ("Junk at end of expression");
287 }
288 return;
289 }
290
291 error ("No breakpoint number %d.", bnum);
292}
293
bdbd5f50 294/* ARGSUSED */
bd5635a1
RP
295static void
296commands_command (arg, from_tty)
297 char *arg;
298 int from_tty;
299{
300 register struct breakpoint *b;
301 char *p;
302 register int bnum;
303 struct command_line *l;
304
305 /* If we allowed this, we would have problems with when to
306 free the storage, if we change the commands currently
307 being read from. */
308
309 if (executing_breakpoint_commands)
310 error ("Can't use the \"commands\" command among a breakpoint's commands.");
311
312 p = arg;
313 bnum = get_number (&p);
314 if (p && *p)
315 error ("Unexpected extra arguments following breakpoint number.");
316
317 ALL_BREAKPOINTS (b)
318 if (b->number == bnum)
319 {
bdbd5f50 320 if (from_tty && input_from_terminal_p ())
9b280a7f 321 printf_filtered ("Type commands for when breakpoint %d is hit, one per line.\n\
bd5635a1 322End with a line saying just \"end\".\n", bnum);
bd5635a1
RP
323 l = read_command_lines ();
324 free_command_lines (&b->commands);
325 b->commands = l;
326 return;
327 }
328 error ("No breakpoint number %d.", bnum);
329}
330\f
31ef19fc
JK
331extern int memory_breakpoint_size; /* from mem-break.c */
332
333/* Like target_read_memory() but if breakpoints are inserted, return
30875e1c
SG
334 the shadow contents instead of the breakpoints themselves.
335
336 Read "memory data" from whatever target or inferior we have.
337 Returns zero if successful, errno value if not. EIO is used
338 for address out of bounds. If breakpoints are inserted, returns
339 shadow contents, not the breakpoints themselves. From breakpoint.c. */
340
31ef19fc
JK
341int
342read_memory_nobpt (memaddr, myaddr, len)
343 CORE_ADDR memaddr;
344 char *myaddr;
345 unsigned len;
346{
347 int status;
348 struct breakpoint *b;
349
350 if (memory_breakpoint_size < 0)
5af4f5f6
JK
351 /* No breakpoints on this machine. FIXME: This should be
352 dependent on the debugging target. Probably want
353 target_insert_breakpoint to return a size, saying how many
354 bytes of the shadow contents are used, or perhaps have
355 something like target_xfer_shadow. */
31ef19fc
JK
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
4ed3a9ea
FF
396 memcpy (myaddr + membpt - memaddr,
397 b->shadow_contents + bptoffset, bptlen);
31ef19fc
JK
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 {
05052b63 453 target_terminal_ours_for_output ();
199b2450 454 fprintf_unfiltered (gdb_stderr,
2d313932 455 "Cannot insert breakpoint %d:\n", b->number);
bd5635a1
RP
456 printf_filtered ("Disabling shared library breakpoints:\n");
457 }
458 disabled_breaks = 1;
459 printf_filtered ("%d ", b->number);
460 }
461 else
462#endif
463 {
05052b63 464 target_terminal_ours_for_output ();
199b2450 465 fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number);
d3b9c0df 466#ifdef ONE_PROCESS_WRITETEXT
199b2450 467 fprintf_unfiltered (gdb_stderr,
2d313932 468 "The same program may be running in another process.\n");
d3b9c0df 469#endif
bd5635a1
RP
470 memory_error (val, b->address); /* which bombs us out */
471 }
472 }
473 else
474 b->inserted = 1;
475 }
476 if (disabled_breaks)
477 printf_filtered ("\n");
478 return val;
479}
480
481int
482remove_breakpoints ()
483{
484 register struct breakpoint *b;
485 int val;
486
bd5635a1 487 ALL_BREAKPOINTS (b)
30875e1c 488 if (b->type != bp_watchpoint && b->inserted)
bd5635a1
RP
489 {
490 val = target_remove_breakpoint(b->address, b->shadow_contents);
491 if (val)
492 return val;
493 b->inserted = 0;
bd5635a1
RP
494 }
495
496 return 0;
497}
498
cf3e377e 499/* Clear the "inserted" flag in all breakpoints. */
bd5635a1
RP
500
501void
502mark_breakpoints_out ()
503{
504 register struct breakpoint *b;
505
506 ALL_BREAKPOINTS (b)
507 b->inserted = 0;
508}
509
cf3e377e
JK
510/* Clear the "inserted" flag in all breakpoints and delete any breakpoints
511 which should go away between runs of the program. */
512
513void
514breakpoint_init_inferior ()
515{
516 register struct breakpoint *b, *temp;
517
518 ALL_BREAKPOINTS_SAFE (b, temp)
519 {
520 b->inserted = 0;
521
522 /* If the call dummy breakpoint is at the entry point it will
523 cause problems when the inferior is rerun, so we better
524 get rid of it. */
525 if (b->type == bp_call_dummy)
526 delete_breakpoint (b);
527 }
528}
529
bd5635a1
RP
530/* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
531 When continuing from a location with a breakpoint,
532 we actually single step once before calling insert_breakpoints. */
533
534int
535breakpoint_here_p (pc)
536 CORE_ADDR pc;
537{
538 register struct breakpoint *b;
539
540 ALL_BREAKPOINTS (b)
541 if (b->enable != disabled && b->address == pc)
542 return 1;
543
544 return 0;
545}
199b2450 546
05052b63
JK
547/* Return nonzero if FRAME is a dummy frame. We can't use PC_IN_CALL_DUMMY
548 because figuring out the saved SP would take too much time, at least using
549 get_saved_register on the 68k. This means that for this function to
550 work right a port must use the bp_call_dummy breakpoint. */
551
552int
553frame_in_dummy (frame)
554 FRAME frame;
555{
556 struct breakpoint *b;
557
d7e7e851 558#ifdef CALL_DUMMY
05052b63
JK
559 ALL_BREAKPOINTS (b)
560 {
d7e7e851
JK
561 static unsigned LONGEST dummy[] = CALL_DUMMY;
562
05052b63 563 if (b->type == bp_call_dummy
d7e7e851
JK
564 && b->frame == frame->frame
565
566 /* We need to check the PC as well as the frame on the sparc,
567 for signals.exp in the testsuite. */
568 && (frame->pc
569 >= (b->address
570 - sizeof (dummy) / sizeof (LONGEST) * REGISTER_SIZE))
571 && frame->pc <= b->address)
05052b63
JK
572 return 1;
573 }
d7e7e851 574#endif /* CALL_DUMMY */
05052b63
JK
575 return 0;
576}
577
199b2450
TL
578/* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
579 is valid for process/thread PID. */
580
581int
582breakpoint_thread_match (pc, pid)
583 CORE_ADDR pc;
584 int pid;
585{
586 struct breakpoint *b;
587 int thread;
588
589 thread = pid_to_thread_id (pid);
590
591 ALL_BREAKPOINTS (b)
592 if (b->enable != disabled
593 && b->address == pc
594 && (b->thread == -1 || b->thread == thread))
595 return 1;
596
597 return 0;
598}
599
bd5635a1
RP
600\f
601/* bpstat stuff. External routines' interfaces are documented
602 in breakpoint.h. */
30875e1c
SG
603
604/* Clear a bpstat so that it says we are not at any breakpoint.
605 Also free any storage that is part of a bpstat. */
606
bd5635a1
RP
607void
608bpstat_clear (bsp)
609 bpstat *bsp;
610{
611 bpstat p;
612 bpstat q;
613
614 if (bsp == 0)
615 return;
616 p = *bsp;
617 while (p != NULL)
618 {
619 q = p->next;
620 if (p->old_val != NULL)
621 value_free (p->old_val);
c8950965 622 free ((PTR)p);
bd5635a1
RP
623 p = q;
624 }
625 *bsp = NULL;
626}
627
30875e1c
SG
628/* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
629 is part of the bpstat is copied as well. */
630
bd5635a1
RP
631bpstat
632bpstat_copy (bs)
633 bpstat bs;
634{
635 bpstat p = NULL;
636 bpstat tmp;
fee933f1 637 bpstat retval = NULL;
bd5635a1
RP
638
639 if (bs == NULL)
640 return bs;
641
642 for (; bs != NULL; bs = bs->next)
643 {
644 tmp = (bpstat) xmalloc (sizeof (*tmp));
4ed3a9ea 645 memcpy (tmp, bs, sizeof (*tmp));
bd5635a1
RP
646 if (p == NULL)
647 /* This is the first thing in the chain. */
648 retval = tmp;
649 else
650 p->next = tmp;
651 p = tmp;
652 }
653 p->next = NULL;
654 return retval;
655}
656
30875e1c
SG
657/* Find the bpstat associated with this breakpoint */
658
659bpstat
660bpstat_find_breakpoint(bsp, breakpoint)
661 bpstat bsp;
662 struct breakpoint *breakpoint;
663{
664 if (bsp == NULL) return NULL;
665
666 for (;bsp != NULL; bsp = bsp->next) {
667 if (bsp->breakpoint_at == breakpoint) return bsp;
668 }
669 return NULL;
670}
671
672/* Return the breakpoint number of the first breakpoint we are stopped
673 at. *BSP upon return is a bpstat which points to the remaining
674 breakpoints stopped at (but which is not guaranteed to be good for
675 anything but further calls to bpstat_num).
676 Return 0 if passed a bpstat which does not indicate any breakpoints. */
677
bd5635a1
RP
678int
679bpstat_num (bsp)
680 bpstat *bsp;
681{
682 struct breakpoint *b;
683
684 if ((*bsp) == NULL)
685 return 0; /* No more breakpoint values */
686 else
687 {
688 b = (*bsp)->breakpoint_at;
689 *bsp = (*bsp)->next;
690 if (b == NULL)
691 return -1; /* breakpoint that's been deleted since */
692 else
693 return b->number; /* We have its number */
694 }
695}
696
30875e1c
SG
697/* Modify BS so that the actions will not be performed. */
698
bd5635a1
RP
699void
700bpstat_clear_actions (bs)
701 bpstat bs;
702{
703 for (; bs != NULL; bs = bs->next)
704 {
705 bs->commands = NULL;
706 if (bs->old_val != NULL)
707 {
708 value_free (bs->old_val);
709 bs->old_val = NULL;
710 }
711 }
712}
713
bdbd5f50
JG
714/* Stub for cleaning up our state if we error-out of a breakpoint command */
715/* ARGSUSED */
716static void
717cleanup_executing_breakpoints (ignore)
718 int ignore;
719{
720 executing_breakpoint_commands = 0;
721}
722
bd5635a1
RP
723/* Execute all the commands associated with all the breakpoints at this
724 location. Any of these commands could cause the process to proceed
725 beyond this point, etc. We look out for such changes by checking
726 the global "breakpoint_proceeded" after each command. */
30875e1c 727
bd5635a1
RP
728void
729bpstat_do_actions (bsp)
730 bpstat *bsp;
731{
732 bpstat bs;
bdbd5f50
JG
733 struct cleanup *old_chain;
734
735 executing_breakpoint_commands = 1;
736 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
bd5635a1
RP
737
738top:
739 bs = *bsp;
740
bd5635a1
RP
741 breakpoint_proceeded = 0;
742 for (; bs != NULL; bs = bs->next)
743 {
744 while (bs->commands)
745 {
746 char *line = bs->commands->line;
747 bs->commands = bs->commands->next;
748 execute_command (line, 0);
749 /* If the inferior is proceeded by the command, bomb out now.
750 The bpstat chain has been blown away by wait_for_inferior.
751 But since execution has stopped again, there is a new bpstat
752 to look at, so start over. */
753 if (breakpoint_proceeded)
754 goto top;
755 }
756 }
bd5635a1
RP
757
758 executing_breakpoint_commands = 0;
bdbd5f50 759 discard_cleanups (old_chain);
bd5635a1
RP
760}
761
8af68e4e
JK
762/* This is the normal print_it function for a bpstat. In the future,
763 much of this logic could (should?) be moved to bpstat_stop_status,
764 by having it set different print_it functions. */
30875e1c 765
8af68e4e
JK
766static int
767print_it_normal (bs)
bd5635a1
RP
768 bpstat bs;
769{
770 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
771 which has since been deleted. */
8af68e4e 772 if (bs->breakpoint_at == NULL
30875e1c
SG
773 || (bs->breakpoint_at->type != bp_breakpoint
774 && bs->breakpoint_at->type != bp_watchpoint))
bd5635a1 775 return 0;
bd5635a1 776
30875e1c 777 if (bs->breakpoint_at->type == bp_breakpoint)
bd5635a1
RP
778 {
779 /* I think the user probably only wants to see one breakpoint
780 number, not all of them. */
781 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
782 return 0;
783 }
784
785 if (bs->old_val != NULL)
786 {
787 printf_filtered ("\nWatchpoint %d, ", bs->breakpoint_at->number);
199b2450 788 print_expression (bs->breakpoint_at->exp, gdb_stdout);
bd5635a1 789 printf_filtered ("\nOld value = ");
199b2450 790 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
bd5635a1 791 printf_filtered ("\nNew value = ");
199b2450 792 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
bd5635a1
RP
793 Val_pretty_default);
794 printf_filtered ("\n");
795 value_free (bs->old_val);
796 bs->old_val = NULL;
3f031adf 797 return 0;
bd5635a1 798 }
8af68e4e
JK
799 /* We can't deal with it. Maybe another member of the bpstat chain can. */
800 return -1;
801}
802
803/* Print a message indicating what happened. Returns nonzero to
804 say that only the source line should be printed after this (zero
805 return means print the frame as well as the source line). */
3f031adf 806/* Currently we always return zero. */
8af68e4e
JK
807int
808bpstat_print (bs)
809 bpstat bs;
810{
811 int val;
812
813 if (bs == NULL)
814 return 0;
bd5635a1 815
8af68e4e
JK
816 val = (*bs->print_it) (bs);
817 if (val >= 0)
818 return val;
819
fcb887ff
JK
820 /* Maybe another breakpoint in the chain caused us to stop.
821 (Currently all watchpoints go on the bpstat whether hit or
822 not. That probably could (should) be changed, provided care is taken
823 with respect to bpstat_explains_signal). */
824 if (bs->next)
825 return bpstat_print (bs->next);
826
cabd4da6 827 /* We reached the end of the chain without printing anything. */
bd5635a1
RP
828 return 0;
829}
830
831/* Evaluate the expression EXP and return 1 if value is zero.
832 This is used inside a catch_errors to evaluate the breakpoint condition.
bdbd5f50 833 The argument is a "struct expression *" that has been cast to char * to
bd5635a1
RP
834 make it pass through catch_errors. */
835
836static int
837breakpoint_cond_eval (exp)
bdbd5f50 838 char *exp;
bd5635a1 839{
d3b9c0df 840 return !value_true (evaluate_expression ((struct expression *)exp));
bd5635a1
RP
841}
842
843/* Allocate a new bpstat and chain it to the current one. */
844
845static bpstat
846bpstat_alloc (b, cbs)
847 register struct breakpoint *b;
848 bpstat cbs; /* Current "bs" value */
849{
850 bpstat bs;
851
852 bs = (bpstat) xmalloc (sizeof (*bs));
853 cbs->next = bs;
854 bs->breakpoint_at = b;
855 /* If the condition is false, etc., don't do the commands. */
856 bs->commands = NULL;
bd5635a1 857 bs->old_val = NULL;
8af68e4e 858 bs->print_it = print_it_normal;
bd5635a1
RP
859 return bs;
860}
fa99ebe1
JK
861\f
862/* Return the frame which we can use to evaluate the expression
863 whose valid block is valid_block, or NULL if not in scope.
864
865 This whole concept is probably not the way to do things (it is incredibly
866 slow being the main reason, not to mention fragile (e.g. the sparc
867 frame pointer being fetched as 0 bug causes it to stop)). Instead,
868 introduce a version of "struct frame" which survives over calls to the
869 inferior, but which is better than FRAME_ADDR in the sense that it lets
870 us evaluate expressions relative to that frame (on some machines, it
871 can just be a FRAME_ADDR). Save one of those instead of (or in addition
872 to) the exp_valid_block, and then use it to evaluate the watchpoint
873 expression, with no need to do all this backtracing every time.
874
875 Or better yet, what if it just copied the struct frame and its next
876 frame? Off the top of my head, I would think that would work
877 because things like (a29k) rsize and msize, or (sparc) bottom just
878 depend on the frame, and aren't going to be different just because
879 the inferior has done something. Trying to recalculate them
880 strikes me as a lot of work, possibly even impossible. Saving the
881 next frame is needed at least on a29k, where get_saved_register
882 uses fi->next->saved_msp. For figuring out whether that frame is
883 still on the stack, I guess this needs to be machine-specific (e.g.
884 a29k) but I think
885
fe675038 886 read_fp () INNER_THAN watchpoint_frame->frame
fa99ebe1
JK
887
888 would generally work.
889
890 Of course the scope of the expression could be less than a whole
891 function; perhaps if the innermost frame is the one which the
892 watchpoint is relative to (another machine-specific thing, usually
893
894 FRAMELESS_FUNCTION_INVOCATION (get_current_frame(), fromleaf)
fe675038 895 read_fp () == wp_frame->frame
fa99ebe1
JK
896 && !fromleaf
897
898 ), *then* it could do a
899
900 contained_in (get_current_block (), wp->exp_valid_block).
901
902 */
903
904FRAME
905within_scope (valid_block)
906 struct block *valid_block;
907{
908 FRAME fr = get_current_frame ();
909 struct frame_info *fi = get_frame_info (fr);
910 CORE_ADDR func_start;
911
912 /* If caller_pc_valid is true, we are stepping through
913 a function prologue, which is bounded by callee_func_start
914 (inclusive) and callee_prologue_end (exclusive).
915 caller_pc is the pc of the caller.
916
917 Yes, this is hairy. */
918 static int caller_pc_valid = 0;
919 static CORE_ADDR caller_pc;
920 static CORE_ADDR callee_func_start;
921 static CORE_ADDR callee_prologue_end;
922
f1ed4330 923 find_pc_partial_function (fi->pc, (PTR)NULL, &func_start, (CORE_ADDR *)NULL);
fa99ebe1
JK
924 func_start += FUNCTION_START_OFFSET;
925 if (fi->pc == func_start)
926 {
927 /* We just called a function. The only other case I
928 can think of where the pc would equal the pc of the
929 start of a function is a frameless function (i.e.
930 no prologue) where we branch back to the start
931 of the function. In that case, SKIP_PROLOGUE won't
932 find one, and we'll clear caller_pc_valid a few lines
933 down. */
934 caller_pc_valid = 1;
935 caller_pc = SAVED_PC_AFTER_CALL (fr);
936 callee_func_start = func_start;
937 SKIP_PROLOGUE (func_start);
938 callee_prologue_end = func_start;
939 }
940 if (caller_pc_valid)
941 {
942 if (fi->pc < callee_func_start
943 || fi->pc >= callee_prologue_end)
944 caller_pc_valid = 0;
945 }
946
947 if (contained_in (block_for_pc (caller_pc_valid
948 ? caller_pc
949 : fi->pc),
950 valid_block))
951 {
952 return fr;
953 }
954 fr = get_prev_frame (fr);
955
956 /* If any active frame is in the exp_valid_block, then it's
957 OK. Note that this might not be the same invocation of
958 the exp_valid_block that we were watching a little while
959 ago, or the same one as when the watchpoint was set (e.g.
960 we are watching a local variable in a recursive function.
961 When we return from a recursive invocation, then we are
962 suddenly watching a different instance of the variable).
963
964 At least for now I am going to consider this a feature. */
965 for (; fr != NULL; fr = get_prev_frame (fr))
966 {
967 fi = get_frame_info (fr);
968 if (contained_in (block_for_pc (fi->pc),
969 valid_block))
970 {
971 return fr;
972 }
973 }
974 return NULL;
975}
bd5635a1 976
8af68e4e
JK
977/* Possible return values for watchpoint_check (this can't be an enum
978 because of check_errors). */
979/* The watchpoint has been disabled. */
980#define WP_DISABLED 1
981/* The value has changed. */
982#define WP_VALUE_CHANGED 2
983/* The value has not changed. */
984#define WP_VALUE_NOT_CHANGED 3
985
986/* Check watchpoint condition. */
987static int
988watchpoint_check (p)
fe675038 989 char *p;
8af68e4e
JK
990{
991 bpstat bs = (bpstat) p;
fa99ebe1 992 FRAME fr;
8af68e4e
JK
993
994 int within_current_scope;
fa99ebe1 995 if (bs->breakpoint_at->exp_valid_block == NULL)
8af68e4e 996 within_current_scope = 1;
fa99ebe1
JK
997 else
998 {
999 fr = within_scope (bs->breakpoint_at->exp_valid_block);
1000 within_current_scope = fr != NULL;
1001 if (within_current_scope)
1002 /* If we end up stopping, the current frame will get selected
1003 in normal_stop. So this call to select_frame won't affect
1004 the user. */
1005 select_frame (fr, -1);
1006 }
1007
8af68e4e
JK
1008 if (within_current_scope)
1009 {
1010 /* We use value_{,free_to_}mark because it could be a
1011 *long* time before we return to the command level and
cef4c2e7
PS
1012 call free_all_values. We can't call free_all_values because
1013 we might be in the middle of evaluating a function call. */
8af68e4e 1014
82a2edfb
JK
1015 value_ptr mark = value_mark ();
1016 value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
8af68e4e
JK
1017 if (!value_equal (bs->breakpoint_at->val, new_val))
1018 {
1019 release_value (new_val);
1020 value_free_to_mark (mark);
1021 bs->old_val = bs->breakpoint_at->val;
1022 bs->breakpoint_at->val = new_val;
1023 /* We will stop here */
1024 return WP_VALUE_CHANGED;
1025 }
1026 else
1027 {
1028 /* Nothing changed, don't do anything. */
1029 value_free_to_mark (mark);
1030 /* We won't stop here */
1031 return WP_VALUE_NOT_CHANGED;
1032 }
1033 }
1034 else
1035 {
1036 /* This seems like the only logical thing to do because
1037 if we temporarily ignored the watchpoint, then when
1038 we reenter the block in which it is valid it contains
1039 garbage (in the case of a function, it may have two
1040 garbage values, one before and one after the prologue).
1041 So we can't even detect the first assignment to it and
1042 watch after that (since the garbage may or may not equal
1043 the first value assigned). */
1044 bs->breakpoint_at->enable = disabled;
1045 printf_filtered ("\
1046Watchpoint %d disabled because the program has left the block in\n\
1047which its expression is valid.\n", bs->breakpoint_at->number);
1048 return WP_DISABLED;
1049 }
1050}
1051
1052/* This is used when everything which needs to be printed has
1053 already been printed. But we still want to print the frame. */
1054static int
cabd4da6 1055print_it_done (bs)
8af68e4e
JK
1056 bpstat bs;
1057{
1058 return 0;
1059}
1060
cabd4da6
JK
1061/* This is used when nothing should be printed for this bpstat entry. */
1062
1063static int
1064print_it_noop (bs)
1065 bpstat bs;
1066{
1067 return -1;
1068}
1069
cb6b0202
JK
1070/* Get a bpstat associated with having just stopped at address *PC
1071 and frame address FRAME_ADDRESS. Update *PC to point at the
1072 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
1073 if this is known to not be a real breakpoint (it could still be a
1074 watchpoint, though). */
1075
bd5635a1
RP
1076/* Determine whether we stopped at a breakpoint, etc, or whether we
1077 don't understand this stop. Result is a chain of bpstat's such that:
1078
1079 if we don't understand the stop, the result is a null pointer.
1080
cb6b0202 1081 if we understand why we stopped, the result is not null.
bd5635a1
RP
1082
1083 Each element of the chain refers to a particular breakpoint or
1084 watchpoint at which we have stopped. (We may have stopped for
2d313932 1085 several reasons concurrently.)
bd5635a1
RP
1086
1087 Each element of the chain has valid next, breakpoint_at,
1088 commands, FIXME??? fields.
1089
1090 */
1091
bd5635a1 1092bpstat
cb6b0202 1093bpstat_stop_status (pc, frame_address, not_a_breakpoint)
bd5635a1
RP
1094 CORE_ADDR *pc;
1095 FRAME_ADDR frame_address;
cb6b0202 1096 int not_a_breakpoint;
bd5635a1
RP
1097{
1098 register struct breakpoint *b;
bd5635a1 1099 CORE_ADDR bp_addr;
bdbd5f50 1100#if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
bd5635a1
RP
1101 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
1102 int real_breakpoint = 0;
bdbd5f50 1103#endif
bd5635a1 1104 /* Root of the chain of bpstat's */
cba0d141 1105 struct bpstat root_bs[1];
bd5635a1
RP
1106 /* Pointer to the last thing in the chain currently. */
1107 bpstat bs = root_bs;
1108
1109 /* Get the address where the breakpoint would have been. */
1110 bp_addr = *pc - DECR_PC_AFTER_BREAK;
1111
1112 ALL_BREAKPOINTS (b)
1113 {
bd5635a1
RP
1114 if (b->enable == disabled)
1115 continue;
30875e1c
SG
1116
1117 if (b->type != bp_watchpoint && b->address != bp_addr)
bd5635a1
RP
1118 continue;
1119
cb6b0202
JK
1120 if (b->type != bp_watchpoint && not_a_breakpoint)
1121 continue;
1122
30875e1c
SG
1123 /* Come here if it's a watchpoint, or if the break address matches */
1124
bd5635a1
RP
1125 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
1126
cabd4da6
JK
1127 bs->stop = 1;
1128 bs->print = 1;
bd5635a1 1129
30875e1c 1130 if (b->type == bp_watchpoint)
bd5635a1 1131 {
8af68e4e
JK
1132 static char message1[] =
1133 "Error evaluating expression for watchpoint %d\n";
1134 char message[sizeof (message1) + 30 /* slop */];
1135 sprintf (message, message1, b->number);
fe675038
JK
1136 switch (catch_errors (watchpoint_check, (char *) bs, message,
1137 RETURN_MASK_ALL))
bd5635a1 1138 {
8af68e4e
JK
1139 case WP_DISABLED:
1140 /* We've already printed what needs to be printed. */
cabd4da6 1141 bs->print_it = print_it_done;
8af68e4e
JK
1142 /* Stop. */
1143 break;
1144 case WP_VALUE_CHANGED:
1145 /* Stop. */
1146 break;
1147 case WP_VALUE_NOT_CHANGED:
1148 /* Don't stop. */
cabd4da6
JK
1149 bs->print_it = print_it_noop;
1150 bs->stop = 0;
bd5635a1 1151 continue;
8af68e4e
JK
1152 default:
1153 /* Can't happen. */
1154 /* FALLTHROUGH */
1155 case 0:
1156 /* Error from catch_errors. */
1157 b->enable = disabled;
1158 printf_filtered ("Watchpoint %d disabled.\n", b->number);
1159 /* We've already printed what needs to be printed. */
cabd4da6 1160 bs->print_it = print_it_done;
8af68e4e
JK
1161 /* Stop. */
1162 break;
bd5635a1
RP
1163 }
1164 }
bdbd5f50 1165#if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
bd5635a1
RP
1166 else
1167 real_breakpoint = 1;
bdbd5f50 1168#endif
bd5635a1
RP
1169
1170 if (b->frame && b->frame != frame_address)
cabd4da6 1171 bs->stop = 0;
bd5635a1
RP
1172 else
1173 {
fee933f1 1174 int value_is_zero = 0;
bd5635a1
RP
1175
1176 if (b->cond)
1177 {
1178 /* Need to select the frame, with all that implies
1179 so that the conditions will have the right context. */
1180 select_frame (get_current_frame (), 0);
bdbd5f50
JG
1181 value_is_zero
1182 = catch_errors (breakpoint_cond_eval, (char *)(b->cond),
fe675038
JK
1183 "Error in testing breakpoint condition:\n",
1184 RETURN_MASK_ALL);
06b6c733 1185 /* FIXME-someday, should give breakpoint # */
bd5635a1
RP
1186 free_all_values ();
1187 }
bdbd5f50 1188 if (b->cond && value_is_zero)
bd5635a1 1189 {
cabd4da6 1190 bs->stop = 0;
bd5635a1
RP
1191 }
1192 else if (b->ignore_count > 0)
1193 {
1194 b->ignore_count--;
cabd4da6 1195 bs->stop = 0;
bd5635a1
RP
1196 }
1197 else
1198 {
1199 /* We will stop here */
30875e1c 1200 if (b->disposition == disable)
bd5635a1
RP
1201 b->enable = disabled;
1202 bs->commands = b->commands;
1203 if (b->silent)
cabd4da6 1204 bs->print = 0;
2d313932 1205 if (bs->commands && STREQ ("silent", bs->commands->line))
bd5635a1
RP
1206 {
1207 bs->commands = bs->commands->next;
cabd4da6 1208 bs->print = 0;
bd5635a1
RP
1209 }
1210 }
1211 }
cabd4da6
JK
1212 /* Print nothing for this entry if we dont stop or if we dont print. */
1213 if (bs->stop == 0 || bs->print == 0)
1214 bs->print_it = print_it_noop;
bd5635a1
RP
1215 }
1216
1217 bs->next = NULL; /* Terminate the chain */
1218 bs = root_bs->next; /* Re-grab the head of the chain */
cabd4da6 1219#if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
bd5635a1
RP
1220 if (bs)
1221 {
bd5635a1
RP
1222 if (real_breakpoint)
1223 {
1224 *pc = bp_addr;
1225#if defined (SHIFT_INST_REGS)
817ac7f8 1226 SHIFT_INST_REGS();
bd5635a1
RP
1227#else /* No SHIFT_INST_REGS. */
1228 write_pc (bp_addr);
1229#endif /* No SHIFT_INST_REGS. */
1230 }
bd5635a1 1231 }
cabd4da6 1232#endif /* DECR_PC_AFTER_BREAK != 0. */
bd5635a1
RP
1233 return bs;
1234}
cabd4da6
JK
1235\f
1236/* Tell what to do about this bpstat. */
fe675038 1237struct bpstat_what
cabd4da6
JK
1238bpstat_what (bs)
1239 bpstat bs;
1240{
1241 /* Classify each bpstat as one of the following. */
1242 enum class {
fe675038
JK
1243 /* This bpstat element has no effect on the main_action. */
1244 no_effect = 0,
cabd4da6
JK
1245
1246 /* There was a watchpoint, stop but don't print. */
1247 wp_silent,
1248
1249 /* There was a watchpoint, stop and print. */
1250 wp_noisy,
1251
1252 /* There was a breakpoint but we're not stopping. */
1253 bp_nostop,
1254
1255 /* There was a breakpoint, stop but don't print. */
1256 bp_silent,
1257
1258 /* There was a breakpoint, stop and print. */
1259 bp_noisy,
1260
1261 /* We hit the longjmp breakpoint. */
1262 long_jump,
1263
1264 /* We hit the longjmp_resume breakpoint. */
1265 long_resume,
1266
d7e7e851
JK
1267 /* We hit the step_resume breakpoint. */
1268 step_resume,
1269
bcc37718
JK
1270 /* We hit the through_sigtramp breakpoint. */
1271 through_sig,
1272
cabd4da6
JK
1273 /* This is just used to count how many enums there are. */
1274 class_last
1275 };
1276
1277 /* Here is the table which drives this routine. So that we can
1278 format it pretty, we define some abbreviations for the
1279 enum bpstat_what codes. */
1280#define keep_c BPSTAT_WHAT_KEEP_CHECKING
1281#define stop_s BPSTAT_WHAT_STOP_SILENT
1282#define stop_n BPSTAT_WHAT_STOP_NOISY
1283#define single BPSTAT_WHAT_SINGLE
1284#define setlr BPSTAT_WHAT_SET_LONGJMP_RESUME
1285#define clrlr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
1286#define clrlrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
d7e7e851 1287#define sr BPSTAT_WHAT_STEP_RESUME
bcc37718 1288#define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
d7e7e851 1289
cabd4da6
JK
1290/* "Can't happen." Might want to print an error message.
1291 abort() is not out of the question, but chances are GDB is just
1292 a bit confused, not unusable. */
1293#define err BPSTAT_WHAT_STOP_NOISY
1294
1295 /* Given an old action and a class, come up with a new action. */
84d59861
JK
1296 /* One interesting property of this table is that wp_silent is the same
1297 as bp_silent and wp_noisy is the same as bp_noisy. That is because
1298 after stopping, the check for whether to step over a breakpoint
1299 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
1300 reference to how we stopped. We retain separate wp_silent and bp_silent
1301 codes in case we want to change that someday. */
d7e7e851
JK
1302
1303 /* step_resume entries: a step resume breakpoint overrides another
1304 breakpoint of signal handling (see comment in wait_for_inferior
1305 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
bcc37718
JK
1306 /* We handle the through_sigtramp_breakpoint the same way; having both
1307 one of those and a step_resume_breakpoint is probably very rare (?). */
d7e7e851 1308
fe675038 1309 static const enum bpstat_what_main_action
cabd4da6
JK
1310 table[(int)class_last][(int)BPSTAT_WHAT_LAST] =
1311 {
1312 /* old action */
bcc37718
JK
1313 /* keep_c stop_s stop_n single setlr clrlr clrlrs sr ts
1314 */
1315/*no_effect*/ {keep_c,stop_s,stop_n,single, setlr , clrlr , clrlrs, sr, ts},
1316/*wp_silent*/ {stop_s,stop_s,stop_n,stop_s, stop_s, stop_s, stop_s, sr, ts},
1317/*wp_noisy*/ {stop_n,stop_n,stop_n,stop_n, stop_n, stop_n, stop_n, sr, ts},
1318/*bp_nostop*/ {single,stop_s,stop_n,single, setlr , clrlrs, clrlrs, sr, ts},
1319/*bp_silent*/ {stop_s,stop_s,stop_n,stop_s, stop_s, stop_s, stop_s, sr, ts},
1320/*bp_noisy*/ {stop_n,stop_n,stop_n,stop_n, stop_n, stop_n, stop_n, sr, ts},
1321/*long_jump*/ {setlr ,stop_s,stop_n,setlr , err , err , err , sr, ts},
1322/*long_resume*/ {clrlr ,stop_s,stop_n,clrlrs, err , err , err , sr, ts},
1323/*step_resume*/ {sr ,sr ,sr ,sr , sr , sr , sr , sr, ts},
1324/*through_sig*/ {ts ,ts ,ts ,ts , ts , ts , ts , ts, ts}
cabd4da6
JK
1325 };
1326#undef keep_c
1327#undef stop_s
1328#undef stop_n
1329#undef single
1330#undef setlr
1331#undef clrlr
1332#undef clrlrs
1333#undef err
bcc37718
JK
1334#undef sr
1335#undef ts
fe675038 1336 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
84d59861 1337 struct bpstat_what retval;
cabd4da6 1338
cef4c2e7 1339 retval.call_dummy = 0;
cabd4da6
JK
1340 for (; bs != NULL; bs = bs->next)
1341 {
fee933f1 1342 enum class bs_class = no_effect;
cabd4da6
JK
1343 if (bs->breakpoint_at == NULL)
1344 /* I suspect this can happen if it was a momentary breakpoint
1345 which has since been deleted. */
1346 continue;
1347 switch (bs->breakpoint_at->type)
1348 {
1349 case bp_breakpoint:
1350 case bp_until:
1351 case bp_finish:
1352 if (bs->stop)
1353 {
1354 if (bs->print)
1355 bs_class = bp_noisy;
1356 else
1357 bs_class = bp_silent;
1358 }
1359 else
1360 bs_class = bp_nostop;
1361 break;
1362 case bp_watchpoint:
1363 if (bs->stop)
1364 {
1365 if (bs->print)
1366 bs_class = wp_noisy;
1367 else
1368 bs_class = wp_silent;
1369 }
1370 else
fe675038
JK
1371 /* There was a watchpoint, but we're not stopping. This requires
1372 no further action. */
1373 bs_class = no_effect;
cabd4da6
JK
1374 break;
1375 case bp_longjmp:
1376 bs_class = long_jump;
1377 break;
1378 case bp_longjmp_resume:
1379 bs_class = long_resume;
1380 break;
fe675038 1381 case bp_step_resume:
fe675038
JK
1382 if (bs->stop)
1383 {
d7e7e851 1384 bs_class = step_resume;
fe675038
JK
1385 }
1386 else
1387 /* It is for the wrong frame. */
1388 bs_class = bp_nostop;
bcc37718
JK
1389 break;
1390 case bp_through_sigtramp:
1391 bs_class = through_sig;
fe675038 1392 break;
84d59861
JK
1393 case bp_call_dummy:
1394 /* Make sure the action is stop (silent or noisy), so infrun.c
1395 pops the dummy frame. */
1396 bs_class = bp_silent;
1397 retval.call_dummy = 1;
bb7b3800 1398 break;
cabd4da6
JK
1399 }
1400 current_action = table[(int)bs_class][(int)current_action];
1401 }
84d59861
JK
1402 retval.main_action = current_action;
1403 return retval;
cabd4da6 1404}
bd5635a1 1405
30875e1c
SG
1406/* Nonzero if we should step constantly (e.g. watchpoints on machines
1407 without hardware support). This isn't related to a specific bpstat,
1408 just to things like whether watchpoints are set. */
1409
bd5635a1
RP
1410int
1411bpstat_should_step ()
1412{
1413 struct breakpoint *b;
1414 ALL_BREAKPOINTS (b)
30875e1c 1415 if (b->enable == enabled && b->type == bp_watchpoint)
bd5635a1
RP
1416 return 1;
1417 return 0;
1418}
1419\f
1420/* Print information on breakpoint number BNUM, or -1 if all.
1421 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
1422 is nonzero, process only watchpoints. */
1423
1424static void
c8950965 1425breakpoint_1 (bnum, allflag)
bd5635a1 1426 int bnum;
80ba48f5 1427 int allflag;
bd5635a1
RP
1428{
1429 register struct breakpoint *b;
1430 register struct command_line *l;
1431 register struct symbol *sym;
1432 CORE_ADDR last_addr = (CORE_ADDR)-1;
30875e1c
SG
1433 int found_a_breakpoint = 0;
1434 static char *bptypes[] = {"breakpoint", "until", "finish", "watchpoint",
bb7b3800
JK
1435 "longjmp", "longjmp resume", "step resume",
1436 "call dummy" };
80ba48f5 1437 static char *bpdisps[] = {"del", "dis", "keep"};
30875e1c 1438 static char bpenables[] = "ny";
0a62ff36 1439 char wrap_indent[80];
30875e1c 1440
bd5635a1 1441 ALL_BREAKPOINTS (b)
30875e1c
SG
1442 if (bnum == -1
1443 || bnum == b->number)
bd5635a1 1444 {
80ba48f5
SG
1445/* We only print out user settable breakpoints unless the allflag is set. */
1446 if (!allflag
1447 && b->type != bp_breakpoint
1448 && b->type != bp_watchpoint)
1449 continue;
1450
30875e1c 1451 if (!found_a_breakpoint++)
80ba48f5 1452 printf_filtered ("Num Type Disp Enb %sWhat\n",
30875e1c
SG
1453 addressprint ? "Address " : "");
1454
80ba48f5 1455 printf_filtered ("%-3d %-14s %-4s %-3c ",
30875e1c 1456 b->number,
423e9664
SG
1457 bptypes[(int)b->type],
1458 bpdisps[(int)b->disposition],
1459 bpenables[(int)b->enable]);
0a62ff36
JK
1460 strcpy (wrap_indent, " ");
1461 if (addressprint)
1462 strcat (wrap_indent, " ");
30875e1c 1463 switch (b->type)
bd5635a1 1464 {
30875e1c 1465 case bp_watchpoint:
199b2450 1466 print_expression (b->exp, gdb_stdout);
30875e1c 1467 break;
84d59861 1468
30875e1c 1469 case bp_breakpoint:
80ba48f5
SG
1470 case bp_until:
1471 case bp_finish:
1472 case bp_longjmp:
1473 case bp_longjmp_resume:
84d59861 1474 case bp_step_resume:
bcc37718 1475 case bp_through_sigtramp:
bb7b3800 1476 case bp_call_dummy:
bd5635a1 1477 if (addressprint)
cef4c2e7 1478 printf_filtered ("%s ", local_hex_string_custom ((unsigned long) b->address, "08l"));
bd5635a1
RP
1479
1480 last_addr = b->address;
d889f6b7 1481 if (b->source_file)
bd5635a1
RP
1482 {
1483 sym = find_pc_function (b->address);
1484 if (sym)
1485 {
199b2450
TL
1486 fputs_filtered ("in ", gdb_stdout);
1487 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
0a62ff36 1488 wrap_here (wrap_indent);
199b2450 1489 fputs_filtered (" at ", gdb_stdout);
bd5635a1 1490 }
199b2450 1491 fputs_filtered (b->source_file, gdb_stdout);
bd5635a1
RP
1492 printf_filtered (":%d", b->line_number);
1493 }
1494 else
199b2450 1495 print_address_symbolic (b->address, gdb_stdout, demangle, " ");
fee933f1 1496 break;
bd5635a1
RP
1497 }
1498
1499 printf_filtered ("\n");
1500
1501 if (b->frame)
833e0d94
JK
1502 {
1503 printf_filtered ("\tstop only in stack frame at ");
1504 print_address_numeric (b->frame, gdb_stdout);
1505 printf_filtered ("\n");
bcc37718 1506 }
bd5635a1
RP
1507 if (b->cond)
1508 {
1509 printf_filtered ("\tstop only if ");
199b2450 1510 print_expression (b->cond, gdb_stdout);
bd5635a1
RP
1511 printf_filtered ("\n");
1512 }
1513 if (b->ignore_count)
1514 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
1515 if ((l = b->commands))
1516 while (l)
1517 {
199b2450
TL
1518 fputs_filtered ("\t", gdb_stdout);
1519 fputs_filtered (l->line, gdb_stdout);
1520 fputs_filtered ("\n", gdb_stdout);
bd5635a1
RP
1521 l = l->next;
1522 }
1523 }
1524
fee933f1
RP
1525 if (!found_a_breakpoint)
1526 {
1527 if (bnum == -1)
1528 printf_filtered ("No breakpoints or watchpoints.\n");
1529 else
1530 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
1531 }
30875e1c
SG
1532 else
1533 /* Compare against (CORE_ADDR)-1 in case some compiler decides
1534 that a comparison of an unsigned with -1 is always false. */
1535 if (last_addr != (CORE_ADDR)-1)
1536 set_next_address (last_addr);
bd5635a1
RP
1537}
1538
bdbd5f50 1539/* ARGSUSED */
bd5635a1
RP
1540static void
1541breakpoints_info (bnum_exp, from_tty)
1542 char *bnum_exp;
1543 int from_tty;
1544{
1545 int bnum = -1;
1546
1547 if (bnum_exp)
1548 bnum = parse_and_eval_address (bnum_exp);
1549
c8950965 1550 breakpoint_1 (bnum, 0);
80ba48f5
SG
1551}
1552
9b280a7f
JG
1553#if MAINTENANCE_CMDS
1554
80ba48f5
SG
1555/* ARGSUSED */
1556static void
9b280a7f 1557maintenance_info_breakpoints (bnum_exp, from_tty)
80ba48f5
SG
1558 char *bnum_exp;
1559 int from_tty;
1560{
1561 int bnum = -1;
1562
1563 if (bnum_exp)
1564 bnum = parse_and_eval_address (bnum_exp);
1565
c8950965 1566 breakpoint_1 (bnum, 1);
bd5635a1
RP
1567}
1568
9b280a7f
JG
1569#endif
1570
bd5635a1
RP
1571/* Print a message describing any breakpoints set at PC. */
1572
1573static void
1574describe_other_breakpoints (pc)
1575 register CORE_ADDR pc;
1576{
1577 register int others = 0;
1578 register struct breakpoint *b;
1579
1580 ALL_BREAKPOINTS (b)
1581 if (b->address == pc)
1582 others++;
1583 if (others > 0)
1584 {
833e0d94 1585 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
bd5635a1
RP
1586 ALL_BREAKPOINTS (b)
1587 if (b->address == pc)
1588 {
1589 others--;
833e0d94
JK
1590 printf_filtered
1591 ("%d%s%s ",
1592 b->number,
1593 (b->enable == disabled) ? " (disabled)" : "",
1594 (others > 1) ? "," : ((others == 1) ? " and" : ""));
bd5635a1 1595 }
833e0d94
JK
1596 printf_filtered ("also set at pc ");
1597 print_address_numeric (pc, gdb_stdout);
1598 printf_filtered (".\n");
bd5635a1
RP
1599 }
1600}
1601\f
1602/* Set the default place to put a breakpoint
1603 for the `break' command with no arguments. */
1604
1605void
1606set_default_breakpoint (valid, addr, symtab, line)
1607 int valid;
1608 CORE_ADDR addr;
1609 struct symtab *symtab;
1610 int line;
1611{
1612 default_breakpoint_valid = valid;
1613 default_breakpoint_address = addr;
1614 default_breakpoint_symtab = symtab;
1615 default_breakpoint_line = line;
1616}
1617
1618/* Rescan breakpoints at address ADDRESS,
1619 marking the first one as "first" and any others as "duplicates".
1620 This is so that the bpt instruction is only inserted once. */
1621
1622static void
1623check_duplicates (address)
1624 CORE_ADDR address;
1625{
1626 register struct breakpoint *b;
1627 register int count = 0;
1628
30875e1c 1629 if (address == 0) /* Watchpoints are uninteresting */
f266e564
JK
1630 return;
1631
bd5635a1
RP
1632 ALL_BREAKPOINTS (b)
1633 if (b->enable != disabled && b->address == address)
1634 {
1635 count++;
1636 b->duplicate = count > 1;
1637 }
1638}
1639
1640/* Low level routine to set a breakpoint.
1641 Takes as args the three things that every breakpoint must have.
1642 Returns the breakpoint object so caller can set other things.
1643 Does not set the breakpoint number!
f266e564
JK
1644 Does not print anything.
1645
1646 ==> This routine should not be called if there is a chance of later
1647 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
1648 your arguments BEFORE calling this routine! */
bd5635a1
RP
1649
1650static struct breakpoint *
1651set_raw_breakpoint (sal)
1652 struct symtab_and_line sal;
1653{
1654 register struct breakpoint *b, *b1;
1655
1656 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4ed3a9ea 1657 memset (b, 0, sizeof (*b));
bd5635a1 1658 b->address = sal.pc;
d889f6b7
JK
1659 if (sal.symtab == NULL)
1660 b->source_file = NULL;
1661 else
1662 b->source_file = savestring (sal.symtab->filename,
1663 strlen (sal.symtab->filename));
199b2450 1664 b->thread = -1;
bd5635a1
RP
1665 b->line_number = sal.line;
1666 b->enable = enabled;
1667 b->next = 0;
1668 b->silent = 0;
1669 b->ignore_count = 0;
1670 b->commands = NULL;
30875e1c 1671 b->frame = 0;
bd5635a1
RP
1672
1673 /* Add this breakpoint to the end of the chain
1674 so that a list of breakpoints will come out in order
1675 of increasing numbers. */
1676
1677 b1 = breakpoint_chain;
1678 if (b1 == 0)
1679 breakpoint_chain = b;
1680 else
1681 {
1682 while (b1->next)
1683 b1 = b1->next;
1684 b1->next = b;
1685 }
1686
1687 check_duplicates (sal.pc);
1688
1689 return b;
1690}
1691
30875e1c 1692static void
80ba48f5 1693create_longjmp_breakpoint(func_name)
30875e1c 1694 char *func_name;
30875e1c 1695{
30875e1c
SG
1696 struct symtab_and_line sal;
1697 struct breakpoint *b;
80ba48f5 1698 static int internal_breakpoint_number = -1;
30875e1c 1699
30875e1c
SG
1700 if (func_name != NULL)
1701 {
1702 struct minimal_symbol *m;
1703
1704 m = lookup_minimal_symbol(func_name, (struct objfile *)NULL);
1705 if (m)
2d313932 1706 sal.pc = SYMBOL_VALUE_ADDRESS (m);
30875e1c
SG
1707 else
1708 return;
1709 }
1710 else
1711 sal.pc = 0;
1712
1713 sal.symtab = NULL;
1714 sal.line = 0;
30875e1c 1715
80ba48f5 1716 b = set_raw_breakpoint(sal);
30875e1c
SG
1717 if (!b) return;
1718
80ba48f5 1719 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
30875e1c
SG
1720 b->disposition = donttouch;
1721 b->enable = disabled;
1722 b->silent = 1;
80ba48f5
SG
1723 if (func_name)
1724 b->addr_string = strsave(func_name);
1725 b->number = internal_breakpoint_number--;
30875e1c 1726}
30875e1c
SG
1727
1728/* Call this routine when stepping and nexting to enable a breakpoint if we do
1729 a longjmp(). When we hit that breakpoint, call
1730 set_longjmp_resume_breakpoint() to figure out where we are going. */
1731
1732void
1733enable_longjmp_breakpoint()
1734{
80ba48f5
SG
1735 register struct breakpoint *b;
1736
1737 ALL_BREAKPOINTS (b)
1738 if (b->type == bp_longjmp)
9b280a7f
JG
1739 {
1740 b->enable = enabled;
1741 check_duplicates (b->address);
1742 }
30875e1c
SG
1743}
1744
1745void
1746disable_longjmp_breakpoint()
1747{
80ba48f5
SG
1748 register struct breakpoint *b;
1749
1750 ALL_BREAKPOINTS (b)
9b280a7f 1751 if ( b->type == bp_longjmp
80ba48f5 1752 || b->type == bp_longjmp_resume)
9b280a7f
JG
1753 {
1754 b->enable = disabled;
1755 check_duplicates (b->address);
1756 }
30875e1c
SG
1757}
1758
1759/* Call this after hitting the longjmp() breakpoint. Use this to set a new
1760 breakpoint at the target of the jmp_buf.
80ba48f5
SG
1761
1762 FIXME - This ought to be done by setting a temporary breakpoint that gets
1763 deleted automatically...
30875e1c
SG
1764*/
1765
1766void
1767set_longjmp_resume_breakpoint(pc, frame)
1768 CORE_ADDR pc;
1769 FRAME frame;
1770{
80ba48f5
SG
1771 register struct breakpoint *b;
1772
1773 ALL_BREAKPOINTS (b)
1774 if (b->type == bp_longjmp_resume)
1775 {
1776 b->address = pc;
1777 b->enable = enabled;
1778 if (frame != NULL)
1779 b->frame = FRAME_FP(frame);
1780 else
1781 b->frame = 0;
9b280a7f 1782 check_duplicates (b->address);
80ba48f5
SG
1783 return;
1784 }
30875e1c
SG
1785}
1786
bd5635a1
RP
1787/* Set a breakpoint that will evaporate an end of command
1788 at address specified by SAL.
1789 Restrict it to frame FRAME if FRAME is nonzero. */
1790
30875e1c
SG
1791struct breakpoint *
1792set_momentary_breakpoint (sal, frame, type)
bd5635a1
RP
1793 struct symtab_and_line sal;
1794 FRAME frame;
30875e1c 1795 enum bptype type;
bd5635a1
RP
1796{
1797 register struct breakpoint *b;
1798 b = set_raw_breakpoint (sal);
30875e1c
SG
1799 b->type = type;
1800 b->enable = enabled;
1801 b->disposition = donttouch;
bd5635a1 1802 b->frame = (frame ? FRAME_FP (frame) : 0);
30875e1c 1803 return b;
bd5635a1
RP
1804}
1805
30875e1c 1806#if 0
bd5635a1
RP
1807void
1808clear_momentary_breakpoints ()
1809{
1810 register struct breakpoint *b;
1811 ALL_BREAKPOINTS (b)
30875e1c 1812 if (b->disposition == delete)
bd5635a1
RP
1813 {
1814 delete_breakpoint (b);
1815 break;
1816 }
1817}
30875e1c 1818#endif
bd5635a1
RP
1819\f
1820/* Tell the user we have just set a breakpoint B. */
1821static void
1822mention (b)
1823 struct breakpoint *b;
1824{
30875e1c 1825 switch (b->type)
bd5635a1 1826 {
30875e1c 1827 case bp_watchpoint:
bd5635a1 1828 printf_filtered ("Watchpoint %d: ", b->number);
199b2450 1829 print_expression (b->exp, gdb_stdout);
30875e1c
SG
1830 break;
1831 case bp_breakpoint:
833e0d94 1832 printf_filtered ("Breakpoint %d at ", b->number);
bcc37718 1833 print_address_numeric (b->address, gdb_stdout);
d889f6b7 1834 if (b->source_file)
bd5635a1 1835 printf_filtered (": file %s, line %d.",
d889f6b7 1836 b->source_file, b->line_number);
51b57ded
FF
1837 break;
1838 case bp_until:
1839 case bp_finish:
1840 case bp_longjmp:
1841 case bp_longjmp_resume:
fee933f1 1842 case bp_step_resume:
bcc37718 1843 case bp_through_sigtramp:
199b2450 1844 case bp_call_dummy:
51b57ded 1845 break;
bd5635a1
RP
1846 }
1847 printf_filtered ("\n");
1848}
1849
1850#if 0
1851/* Nobody calls this currently. */
1852/* Set a breakpoint from a symtab and line.
1853 If TEMPFLAG is nonzero, it is a temporary breakpoint.
1854 ADDR_STRING is a malloc'd string holding the name of where we are
1855 setting the breakpoint. This is used later to re-set it after the
1856 program is relinked and symbols are reloaded.
1857 Print the same confirmation messages that the breakpoint command prints. */
1858
1859void
1860set_breakpoint (s, line, tempflag, addr_string)
1861 struct symtab *s;
1862 int line;
1863 int tempflag;
1864 char *addr_string;
1865{
1866 register struct breakpoint *b;
1867 struct symtab_and_line sal;
1868
1869 sal.symtab = s;
1870 sal.line = line;
30875e1c
SG
1871 sal.pc = 0;
1872 resolve_sal_pc (&sal); /* Might error out */
1873 describe_other_breakpoints (sal.pc);
bd5635a1 1874
30875e1c
SG
1875 b = set_raw_breakpoint (sal);
1876 set_breakpoint_count (breakpoint_count + 1);
1877 b->number = breakpoint_count;
1878 b->type = bp_breakpoint;
1879 b->cond = 0;
1880 b->addr_string = addr_string;
1881 b->enable = enabled;
1882 b->disposition = tempflag ? delete : donttouch;
bd5635a1 1883
30875e1c 1884 mention (b);
bd5635a1 1885}
30875e1c 1886#endif /* 0 */
bd5635a1
RP
1887\f
1888/* Set a breakpoint according to ARG (function, linenum or *address)
1889 and make it temporary if TEMPFLAG is nonzero. */
1890
1891static void
1892break_command_1 (arg, tempflag, from_tty)
1893 char *arg;
1894 int tempflag, from_tty;
1895{
1896 struct symtabs_and_lines sals;
1897 struct symtab_and_line sal;
1898 register struct expression *cond = 0;
1899 register struct breakpoint *b;
1900
1901 /* Pointers in arg to the start, and one past the end, of the condition. */
1902 char *cond_start = NULL;
fee933f1 1903 char *cond_end = NULL;
bd5635a1
RP
1904 /* Pointers in arg to the start, and one past the end,
1905 of the address part. */
1906 char *addr_start = NULL;
fee933f1 1907 char *addr_end = NULL;
d889f6b7 1908 struct cleanup *old_chain;
fee933f1 1909 struct cleanup *canonical_strings_chain = NULL;
d889f6b7 1910 char **canonical = (char **)NULL;
bd5635a1 1911 int i;
199b2450 1912 int thread;
bd5635a1
RP
1913
1914 sals.sals = NULL;
1915 sals.nelts = 0;
1916
1917 sal.line = sal.pc = sal.end = 0;
1918 sal.symtab = 0;
1919
1920 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
1921
1922 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
1923 && (arg[2] == ' ' || arg[2] == '\t')))
1924 {
1925 if (default_breakpoint_valid)
1926 {
1927 sals.sals = (struct symtab_and_line *)
1928 xmalloc (sizeof (struct symtab_and_line));
1929 sal.pc = default_breakpoint_address;
1930 sal.line = default_breakpoint_line;
1931 sal.symtab = default_breakpoint_symtab;
1932 sals.sals[0] = sal;
1933 sals.nelts = 1;
1934 }
1935 else
1936 error ("No default breakpoint address now.");
1937 }
1938 else
1939 {
1940 addr_start = arg;
1941
1942 /* Force almost all breakpoints to be in terms of the
1943 current_source_symtab (which is decode_line_1's default). This
1944 should produce the results we want almost all of the time while
1945 leaving default_breakpoint_* alone. */
1946 if (default_breakpoint_valid
1947 && (!current_source_symtab
1948 || (arg && (*arg == '+' || *arg == '-'))))
1949 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
d889f6b7 1950 default_breakpoint_line, &canonical);
bd5635a1 1951 else
d889f6b7 1952 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, &canonical);
bd5635a1
RP
1953
1954 addr_end = arg;
1955 }
1956
1957 if (! sals.nelts)
1958 return;
1959
d889f6b7
JK
1960 /* Make sure that all storage allocated in decode_line_1 gets freed in case
1961 the following `for' loop errors out. */
1962 old_chain = make_cleanup (free, sals.sals);
1963 if (canonical != (char **)NULL)
1964 {
1965 make_cleanup (free, canonical);
1966 canonical_strings_chain = make_cleanup (null_cleanup, 0);
1967 for (i = 0; i < sals.nelts; i++)
1968 {
1969 if (canonical[i] != NULL)
1970 make_cleanup (free, canonical[i]);
1971 }
1972 }
1973
199b2450
TL
1974 thread = -1; /* No specific thread yet */
1975
30875e1c
SG
1976 /* Resolve all line numbers to PC's, and verify that conditions
1977 can be parsed, before setting any breakpoints. */
bd5635a1
RP
1978 for (i = 0; i < sals.nelts; i++)
1979 {
199b2450
TL
1980 char *tok, *end_tok;
1981 int toklen;
1982
30875e1c 1983 resolve_sal_pc (&sals.sals[i]);
bd5635a1 1984
199b2450
TL
1985 tok = arg;
1986
1987 while (tok && *tok)
bd5635a1 1988 {
199b2450
TL
1989 while (*tok == ' ' || *tok == '\t')
1990 tok++;
1991
1992 end_tok = tok;
1993
1994 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
1995 end_tok++;
1996
1997 toklen = end_tok - tok;
1998
1999 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
2000 {
2001 tok = cond_start = end_tok + 1;
2002 cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
2003 cond_end = tok;
2004 }
2005 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
bd5635a1 2006 {
199b2450
TL
2007 char *tmptok;
2008
2009 tok = end_tok + 1;
2010 tmptok = tok;
2011 thread = strtol (tok, &tok, 0);
2012 if (tok == tmptok)
2013 error ("Junk after thread keyword.");
2014 if (!valid_thread_id (thread))
2015 error ("Unknown thread %d\n", thread);
bd5635a1
RP
2016 }
2017 else
2018 error ("Junk at end of arguments.");
2019 }
bd5635a1
RP
2020 }
2021
d889f6b7
JK
2022 /* Remove the canonical strings from the cleanup, they are needed below. */
2023 if (canonical != (char **)NULL)
2024 discard_cleanups (canonical_strings_chain);
2025
30875e1c 2026 /* Now set all the breakpoints. */
bd5635a1
RP
2027 for (i = 0; i < sals.nelts; i++)
2028 {
2029 sal = sals.sals[i];
2030
2031 if (from_tty)
2032 describe_other_breakpoints (sal.pc);
2033
2034 b = set_raw_breakpoint (sal);
2035 set_breakpoint_count (breakpoint_count + 1);
2036 b->number = breakpoint_count;
30875e1c 2037 b->type = bp_breakpoint;
bd5635a1 2038 b->cond = cond;
199b2450 2039 b->thread = thread;
0a97f6c4 2040
d889f6b7
JK
2041 /* If a canonical line spec is needed use that instead of the
2042 command string. */
2043 if (canonical != (char **)NULL && canonical[i] != NULL)
2044 b->addr_string = canonical[i];
2045 else if (addr_start)
bd5635a1
RP
2046 b->addr_string = savestring (addr_start, addr_end - addr_start);
2047 if (cond_start)
2048 b->cond_string = savestring (cond_start, cond_end - cond_start);
2049
30875e1c
SG
2050 b->enable = enabled;
2051 b->disposition = tempflag ? delete : donttouch;
bd5635a1
RP
2052
2053 mention (b);
2054 }
2055
2056 if (sals.nelts > 1)
2057 {
833e0d94
JK
2058 printf_filtered ("Multiple breakpoints were set.\n");
2059 printf_filtered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
bd5635a1 2060 }
d889f6b7 2061 do_cleanups (old_chain);
bd5635a1
RP
2062}
2063
30875e1c
SG
2064/* Helper function for break_command_1 and disassemble_command. */
2065
2066void
2067resolve_sal_pc (sal)
2068 struct symtab_and_line *sal;
2069{
2070 CORE_ADDR pc;
2071
2072 if (sal->pc == 0 && sal->symtab != 0)
2073 {
2074 pc = find_line_pc (sal->symtab, sal->line);
2075 if (pc == 0)
2076 error ("No line %d in file \"%s\".",
2077 sal->line, sal->symtab->filename);
2078 sal->pc = pc;
2079 }
2080}
2081
bd5635a1
RP
2082void
2083break_command (arg, from_tty)
2084 char *arg;
2085 int from_tty;
2086{
2087 break_command_1 (arg, 0, from_tty);
2088}
2089
2090static void
2091tbreak_command (arg, from_tty)
2092 char *arg;
2093 int from_tty;
2094{
2095 break_command_1 (arg, 1, from_tty);
2096}
2097
bdbd5f50 2098/* ARGSUSED */
bd5635a1
RP
2099static void
2100watch_command (arg, from_tty)
2101 char *arg;
2102 int from_tty;
2103{
2104 struct breakpoint *b;
2105 struct symtab_and_line sal;
f266e564
JK
2106 struct expression *exp;
2107 struct block *exp_valid_block;
2108 struct value *val;
bd5635a1 2109
30875e1c 2110 sal.pc = 0;
bd5635a1
RP
2111 sal.symtab = NULL;
2112 sal.line = 0;
2113
f266e564
JK
2114 /* Parse arguments. */
2115 innermost_block = NULL;
d3b9c0df 2116 exp = parse_expression (arg);
f266e564
JK
2117 exp_valid_block = innermost_block;
2118 val = evaluate_expression (exp);
2119 release_value (val);
2d313932
JK
2120 if (VALUE_LAZY (val))
2121 value_fetch_lazy (val);
f266e564
JK
2122
2123 /* Now set up the breakpoint. */
bd5635a1
RP
2124 b = set_raw_breakpoint (sal);
2125 set_breakpoint_count (breakpoint_count + 1);
2126 b->number = breakpoint_count;
30875e1c
SG
2127 b->type = bp_watchpoint;
2128 b->disposition = donttouch;
f266e564
JK
2129 b->exp = exp;
2130 b->exp_valid_block = exp_valid_block;
2131 b->val = val;
bd5635a1
RP
2132 b->cond = 0;
2133 b->cond_string = NULL;
0eaaa46a 2134 b->exp_string = savestring (arg, strlen (arg));
bd5635a1
RP
2135 mention (b);
2136}
2137\f
2138/*
2139 * Helper routine for the until_command routine in infcmd.c. Here
2140 * because it uses the mechanisms of breakpoints.
2141 */
bdbd5f50 2142/* ARGSUSED */
bd5635a1
RP
2143void
2144until_break_command (arg, from_tty)
2145 char *arg;
2146 int from_tty;
2147{
2148 struct symtabs_and_lines sals;
2149 struct symtab_and_line sal;
2150 FRAME prev_frame = get_prev_frame (selected_frame);
30875e1c
SG
2151 struct breakpoint *breakpoint;
2152 struct cleanup *old_chain;
bd5635a1
RP
2153
2154 clear_proceed_status ();
2155
2156 /* Set a breakpoint where the user wants it and at return from
2157 this function */
2158
2159 if (default_breakpoint_valid)
2160 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
d889f6b7 2161 default_breakpoint_line, (char ***)NULL);
bd5635a1 2162 else
d889f6b7 2163 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, (char ***)NULL);
bd5635a1
RP
2164
2165 if (sals.nelts != 1)
2166 error ("Couldn't get information on specified line.");
2167
2168 sal = sals.sals[0];
c8950965 2169 free ((PTR)sals.sals); /* malloc'd, so freed */
bd5635a1
RP
2170
2171 if (*arg)
2172 error ("Junk at end of arguments.");
2173
30875e1c 2174 resolve_sal_pc (&sal);
bd5635a1 2175
30875e1c 2176 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
bd5635a1 2177
30875e1c
SG
2178 old_chain = make_cleanup(delete_breakpoint, breakpoint);
2179
bd5635a1
RP
2180 /* Keep within the current frame */
2181
2182 if (prev_frame)
2183 {
2184 struct frame_info *fi;
2185
2186 fi = get_frame_info (prev_frame);
2187 sal = find_pc_line (fi->pc, 0);
2188 sal.pc = fi->pc;
30875e1c
SG
2189 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
2190 make_cleanup(delete_breakpoint, breakpoint);
bd5635a1
RP
2191 }
2192
d7e7e851 2193 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
30875e1c 2194 do_cleanups(old_chain);
bd5635a1
RP
2195}
2196\f
bdbd5f50
JG
2197#if 0
2198/* These aren't used; I don't konw what they were for. */
bd5635a1
RP
2199/* Set a breakpoint at the catch clause for NAME. */
2200static int
2201catch_breakpoint (name)
2202 char *name;
2203{
2204}
2205
2206static int
2207disable_catch_breakpoint ()
2208{
2209}
2210
2211static int
2212delete_catch_breakpoint ()
2213{
2214}
2215
2216static int
2217enable_catch_breakpoint ()
2218{
2219}
bdbd5f50 2220#endif /* 0 */
bd5635a1
RP
2221
2222struct sal_chain
2223{
2224 struct sal_chain *next;
2225 struct symtab_and_line sal;
2226};
2227
bdbd5f50
JG
2228#if 0
2229/* This isn't used; I don't know what it was for. */
bd5635a1
RP
2230/* For each catch clause identified in ARGS, run FUNCTION
2231 with that clause as an argument. */
2232static struct symtabs_and_lines
2233map_catch_names (args, function)
2234 char *args;
2235 int (*function)();
2236{
2237 register char *p = args;
2238 register char *p1;
2239 struct symtabs_and_lines sals;
bdbd5f50 2240#if 0
bd5635a1 2241 struct sal_chain *sal_chain = 0;
bdbd5f50 2242#endif
bd5635a1
RP
2243
2244 if (p == 0)
2245 error_no_arg ("one or more catch names");
2246
2247 sals.nelts = 0;
2248 sals.sals = NULL;
2249
2250 while (*p)
2251 {
2252 p1 = p;
2253 /* Don't swallow conditional part. */
2254 if (p1[0] == 'i' && p1[1] == 'f'
2255 && (p1[2] == ' ' || p1[2] == '\t'))
2256 break;
2257
2258 if (isalpha (*p1))
2259 {
2260 p1++;
2261 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
2262 p1++;
2263 }
2264
2265 if (*p1 && *p1 != ' ' && *p1 != '\t')
2266 error ("Arguments must be catch names.");
2267
2268 *p1 = 0;
2269#if 0
2270 if (function (p))
2271 {
2272 struct sal_chain *next
2273 = (struct sal_chain *)alloca (sizeof (struct sal_chain));
2274 next->next = sal_chain;
2275 next->sal = get_catch_sal (p);
2276 sal_chain = next;
2277 goto win;
2278 }
2279#endif
199b2450 2280 printf_unfiltered ("No catch clause for exception %s.\n", p);
bdbd5f50 2281#if 0
bd5635a1 2282 win:
bdbd5f50 2283#endif
bd5635a1
RP
2284 p = p1;
2285 while (*p == ' ' || *p == '\t') p++;
2286 }
2287}
bdbd5f50 2288#endif /* 0 */
bd5635a1
RP
2289
2290/* This shares a lot of code with `print_frame_label_vars' from stack.c. */
2291
2292static struct symtabs_and_lines
2293get_catch_sals (this_level_only)
2294 int this_level_only;
2295{
bd5635a1 2296 register struct blockvector *bl;
777bef06 2297 register struct block *block;
bd5635a1 2298 int index, have_default = 0;
777bef06
JK
2299 struct frame_info *fi;
2300 CORE_ADDR pc;
bd5635a1
RP
2301 struct symtabs_and_lines sals;
2302 struct sal_chain *sal_chain = 0;
2303 char *blocks_searched;
2304
777bef06
JK
2305 /* Not sure whether an error message is always the correct response,
2306 but it's better than a core dump. */
2307 if (selected_frame == NULL)
2308 error ("No selected frame.");
2309 block = get_frame_block (selected_frame);
2310 fi = get_frame_info (selected_frame);
2311 pc = fi->pc;
2312
bd5635a1
RP
2313 sals.nelts = 0;
2314 sals.sals = NULL;
2315
2316 if (block == 0)
2317 error ("No symbol table info available.\n");
2318
2319 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
2320 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
4ed3a9ea 2321 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
bd5635a1
RP
2322
2323 while (block != 0)
2324 {
2325 CORE_ADDR end = BLOCK_END (block) - 4;
2326 int last_index;
2327
2328 if (bl != blockvector_for_pc (end, &index))
2329 error ("blockvector blotch");
2330 if (BLOCKVECTOR_BLOCK (bl, index) != block)
2331 error ("blockvector botch");
2332 last_index = BLOCKVECTOR_NBLOCKS (bl);
2333 index += 1;
2334
2335 /* Don't print out blocks that have gone by. */
2336 while (index < last_index
2337 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
2338 index++;
2339
2340 while (index < last_index
2341 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
2342 {
2343 if (blocks_searched[index] == 0)
2344 {
2345 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
2346 int nsyms;
2347 register int i;
2348 register struct symbol *sym;
2349
2350 nsyms = BLOCK_NSYMS (b);
2351
2352 for (i = 0; i < nsyms; i++)
2353 {
2354 sym = BLOCK_SYM (b, i);
2d313932 2355 if (STREQ (SYMBOL_NAME (sym), "default"))
bd5635a1
RP
2356 {
2357 if (have_default)
2358 continue;
2359 have_default = 1;
2360 }
2361 if (SYMBOL_CLASS (sym) == LOC_LABEL)
2362 {
2363 struct sal_chain *next = (struct sal_chain *)
2364 alloca (sizeof (struct sal_chain));
2365 next->next = sal_chain;
2366 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
2367 sal_chain = next;
2368 }
2369 }
2370 blocks_searched[index] = 1;
2371 }
2372 index++;
2373 }
2374 if (have_default)
2375 break;
2376 if (sal_chain && this_level_only)
2377 break;
2378
2379 /* After handling the function's top-level block, stop.
2380 Don't continue to its superblock, the block of
2381 per-file symbols. */
2382 if (BLOCK_FUNCTION (block))
2383 break;
2384 block = BLOCK_SUPERBLOCK (block);
2385 }
2386
2387 if (sal_chain)
2388 {
2389 struct sal_chain *tmp_chain;
2390
2391 /* Count the number of entries. */
2392 for (index = 0, tmp_chain = sal_chain; tmp_chain;
2393 tmp_chain = tmp_chain->next)
2394 index++;
2395
2396 sals.nelts = index;
2397 sals.sals = (struct symtab_and_line *)
2398 xmalloc (index * sizeof (struct symtab_and_line));
2399 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
2400 sals.sals[index] = sal_chain->sal;
2401 }
2402
2403 return sals;
2404}
2405
2406/* Commands to deal with catching exceptions. */
2407
30875e1c 2408static void
bd5635a1
RP
2409catch_command_1 (arg, tempflag, from_tty)
2410 char *arg;
2411 int tempflag;
2412 int from_tty;
2413{
2414 /* First, translate ARG into something we can deal with in terms
2415 of breakpoints. */
2416
2417 struct symtabs_and_lines sals;
2418 struct symtab_and_line sal;
2419 register struct expression *cond = 0;
2420 register struct breakpoint *b;
2421 char *save_arg;
2422 int i;
bd5635a1
RP
2423
2424 sal.line = sal.pc = sal.end = 0;
2425 sal.symtab = 0;
2426
2427 /* If no arg given, or if first arg is 'if ', all active catch clauses
2428 are breakpointed. */
2429
2430 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
2431 && (arg[2] == ' ' || arg[2] == '\t')))
2432 {
2433 /* Grab all active catch clauses. */
2434 sals = get_catch_sals (0);
2435 }
2436 else
2437 {
2438 /* Grab selected catch clauses. */
fe675038 2439 error ("catch NAME not implemented");
bdbd5f50
JG
2440#if 0
2441 /* This isn't used; I don't know what it was for. */
bd5635a1 2442 sals = map_catch_names (arg, catch_breakpoint);
bdbd5f50 2443#endif
bd5635a1
RP
2444 }
2445
2446 if (! sals.nelts)
2447 return;
2448
2449 save_arg = arg;
2450 for (i = 0; i < sals.nelts; i++)
2451 {
30875e1c 2452 resolve_sal_pc (&sals.sals[i]);
bd5635a1
RP
2453
2454 while (arg && *arg)
2455 {
2456 if (arg[0] == 'i' && arg[1] == 'f'
2457 && (arg[2] == ' ' || arg[2] == '\t'))
30875e1c
SG
2458 cond = parse_exp_1 ((arg += 2, &arg),
2459 block_for_pc (sals.sals[i].pc), 0);
bd5635a1
RP
2460 else
2461 error ("Junk at end of arguments.");
2462 }
2463 arg = save_arg;
bd5635a1
RP
2464 }
2465
2466 for (i = 0; i < sals.nelts; i++)
2467 {
2468 sal = sals.sals[i];
2469
2470 if (from_tty)
2471 describe_other_breakpoints (sal.pc);
2472
2473 b = set_raw_breakpoint (sal);
30875e1c
SG
2474 set_breakpoint_count (breakpoint_count + 1);
2475 b->number = breakpoint_count;
2476 b->type = bp_breakpoint;
bd5635a1 2477 b->cond = cond;
30875e1c
SG
2478 b->enable = enabled;
2479 b->disposition = tempflag ? delete : donttouch;
bd5635a1 2480
d889f6b7 2481 mention (b);
bd5635a1
RP
2482 }
2483
2484 if (sals.nelts > 1)
2485 {
199b2450
TL
2486 printf_unfiltered ("Multiple breakpoints were set.\n");
2487 printf_unfiltered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
bd5635a1 2488 }
c8950965 2489 free ((PTR)sals.sals);
bd5635a1
RP
2490}
2491
bdbd5f50
JG
2492#if 0
2493/* These aren't used; I don't know what they were for. */
bd5635a1
RP
2494/* Disable breakpoints on all catch clauses described in ARGS. */
2495static void
2496disable_catch (args)
2497 char *args;
2498{
2499 /* Map the disable command to catch clauses described in ARGS. */
2500}
2501
2502/* Enable breakpoints on all catch clauses described in ARGS. */
2503static void
2504enable_catch (args)
2505 char *args;
2506{
2507 /* Map the disable command to catch clauses described in ARGS. */
2508}
2509
2510/* Delete breakpoints on all catch clauses in the active scope. */
2511static void
2512delete_catch (args)
2513 char *args;
2514{
2515 /* Map the delete command to catch clauses described in ARGS. */
2516}
bdbd5f50 2517#endif /* 0 */
bd5635a1
RP
2518
2519static void
2520catch_command (arg, from_tty)
2521 char *arg;
2522 int from_tty;
2523{
2524 catch_command_1 (arg, 0, from_tty);
2525}
2526\f
2527static void
2528clear_command (arg, from_tty)
2529 char *arg;
2530 int from_tty;
2531{
2532 register struct breakpoint *b, *b1;
2533 struct symtabs_and_lines sals;
2534 struct symtab_and_line sal;
2535 register struct breakpoint *found;
2536 int i;
2537
2538 if (arg)
2539 {
2540 sals = decode_line_spec (arg, 1);
2541 }
2542 else
2543 {
2544 sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
2545 sal.line = default_breakpoint_line;
2546 sal.symtab = default_breakpoint_symtab;
2547 sal.pc = 0;
2548 if (sal.symtab == 0)
2549 error ("No source file specified.");
2550
2551 sals.sals[0] = sal;
2552 sals.nelts = 1;
2553 }
2554
2555 for (i = 0; i < sals.nelts; i++)
2556 {
2557 /* If exact pc given, clear bpts at that pc.
2558 But if sal.pc is zero, clear all bpts on specified line. */
2559 sal = sals.sals[i];
2560 found = (struct breakpoint *) 0;
2561 while (breakpoint_chain
d889f6b7
JK
2562 && (sal.pc
2563 ? breakpoint_chain->address == sal.pc
2564 : (breakpoint_chain->source_file != NULL
2565 && sal.symtab != NULL
2566 && STREQ (breakpoint_chain->source_file,
2567 sal.symtab->filename)
bd5635a1
RP
2568 && breakpoint_chain->line_number == sal.line)))
2569 {
2570 b1 = breakpoint_chain;
2571 breakpoint_chain = b1->next;
2572 b1->next = found;
2573 found = b1;
2574 }
2575
2576 ALL_BREAKPOINTS (b)
2577 while (b->next
30875e1c 2578 && b->next->type != bp_watchpoint
d889f6b7
JK
2579 && (sal.pc
2580 ? b->next->address == sal.pc
2581 : (b->next->source_file != NULL
2582 && sal.symtab != NULL
2583 && STREQ (b->next->source_file, sal.symtab->filename)
bd5635a1
RP
2584 && b->next->line_number == sal.line)))
2585 {
2586 b1 = b->next;
2587 b->next = b1->next;
2588 b1->next = found;
2589 found = b1;
2590 }
2591
2592 if (found == 0)
2593 {
2594 if (arg)
2595 error ("No breakpoint at %s.", arg);
2596 else
2597 error ("No breakpoint at this line.");
2598 }
2599
2600 if (found->next) from_tty = 1; /* Always report if deleted more than one */
199b2450 2601 if (from_tty) printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
bd5635a1
RP
2602 while (found)
2603 {
199b2450 2604 if (from_tty) printf_unfiltered ("%d ", found->number);
bd5635a1
RP
2605 b1 = found->next;
2606 delete_breakpoint (found);
2607 found = b1;
2608 }
199b2450 2609 if (from_tty) putchar_unfiltered ('\n');
bd5635a1 2610 }
c8950965 2611 free ((PTR)sals.sals);
bd5635a1
RP
2612}
2613\f
2614/* Delete breakpoint in BS if they are `delete' breakpoints.
2615 This is called after any breakpoint is hit, or after errors. */
2616
2617void
2618breakpoint_auto_delete (bs)
2619 bpstat bs;
2620{
2621 for (; bs; bs = bs->next)
cef4c2e7
PS
2622 if (bs->breakpoint_at && bs->breakpoint_at->disposition == delete
2623 && bs->stop)
bd5635a1
RP
2624 delete_breakpoint (bs->breakpoint_at);
2625}
2626
2627/* Delete a breakpoint and clean up all traces of it in the data structures. */
2628
30875e1c 2629void
bd5635a1
RP
2630delete_breakpoint (bpt)
2631 struct breakpoint *bpt;
2632{
2633 register struct breakpoint *b;
2634 register bpstat bs;
2635
2636 if (bpt->inserted)
fe675038 2637 target_remove_breakpoint(bpt->address, bpt->shadow_contents);
bd5635a1
RP
2638
2639 if (breakpoint_chain == bpt)
2640 breakpoint_chain = bpt->next;
2641
2642 ALL_BREAKPOINTS (b)
2643 if (b->next == bpt)
2644 {
2645 b->next = bpt->next;
2646 break;
2647 }
2648
2649 check_duplicates (bpt->address);
fe675038
JK
2650 /* If this breakpoint was inserted, and there is another breakpoint
2651 at the same address, we need to insert the other breakpoint. */
2652 if (bpt->inserted)
2653 {
2654 ALL_BREAKPOINTS (b)
ebad9e90
JK
2655 if (b->address == bpt->address
2656 && !b->duplicate
2657 && b->enable != disabled)
fe675038
JK
2658 {
2659 int val;
2660 val = target_insert_breakpoint (b->address, b->shadow_contents);
2661 if (val != 0)
2662 {
05052b63 2663 target_terminal_ours_for_output ();
199b2450 2664 fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number);
fe675038
JK
2665 memory_error (val, b->address); /* which bombs us out */
2666 }
2667 else
2668 b->inserted = 1;
2669 }
2670 }
bd5635a1
RP
2671
2672 free_command_lines (&bpt->commands);
2673 if (bpt->cond)
d889f6b7 2674 free (bpt->cond);
bd5635a1 2675 if (bpt->cond_string != NULL)
d889f6b7 2676 free (bpt->cond_string);
bd5635a1 2677 if (bpt->addr_string != NULL)
d889f6b7 2678 free (bpt->addr_string);
0eaaa46a 2679 if (bpt->exp_string != NULL)
d889f6b7
JK
2680 free (bpt->exp_string);
2681 if (bpt->source_file != NULL)
2682 free (bpt->source_file);
bd5635a1 2683
30875e1c 2684 if (xgdb_verbose && bpt->type == bp_breakpoint)
05052b63
JK
2685 {
2686 target_terminal_ours_for_output ();
2687 printf_unfiltered ("breakpoint #%d deleted\n", bpt->number);
2688 }
bd5635a1
RP
2689
2690 /* Be sure no bpstat's are pointing at it after it's been freed. */
05052b63
JK
2691 /* FIXME, how can we find all bpstat's?
2692 We just check stop_bpstat for now. */
bd5635a1
RP
2693 for (bs = stop_bpstat; bs; bs = bs->next)
2694 if (bs->breakpoint_at == bpt)
2695 bs->breakpoint_at = NULL;
c8950965 2696 free ((PTR)bpt);
bd5635a1
RP
2697}
2698
bd5635a1
RP
2699static void
2700delete_command (arg, from_tty)
2701 char *arg;
2702 int from_tty;
2703{
2704
2705 if (arg == 0)
2706 {
2707 /* Ask user only if there are some breakpoints to delete. */
2708 if (!from_tty
2709 || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0)))
2710 {
2711 /* No arg; clear all breakpoints. */
2712 while (breakpoint_chain)
2713 delete_breakpoint (breakpoint_chain);
2714 }
2715 }
2716 else
2717 map_breakpoint_numbers (arg, delete_breakpoint);
2718}
2719
bdbd5f50
JG
2720/* Reset a breakpoint given it's struct breakpoint * BINT.
2721 The value we return ends up being the return value from catch_errors.
2722 Unused in this case. */
2723
2724static int
bd5635a1 2725breakpoint_re_set_one (bint)
bdbd5f50 2726 char *bint;
bd5635a1
RP
2727{
2728 struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */
2729 int i;
2730 struct symtabs_and_lines sals;
bd5635a1 2731 char *s;
30875e1c 2732 enum enable save_enable;
bd5635a1 2733
80ba48f5 2734 switch (b->type)
bd5635a1 2735 {
80ba48f5
SG
2736 case bp_breakpoint:
2737 if (b->addr_string == NULL)
2738 {
2739 /* Anything without a string can't be re-set. */
2740 delete_breakpoint (b);
2741 return 0;
2742 }
30875e1c
SG
2743 /* In case we have a problem, disable this breakpoint. We'll restore
2744 its status if we succeed. */
2745 save_enable = b->enable;
2746 b->enable = disabled;
2747
bd5635a1 2748 s = b->addr_string;
d889f6b7 2749 sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0, (char ***)NULL);
bd5635a1
RP
2750 for (i = 0; i < sals.nelts; i++)
2751 {
30875e1c 2752 resolve_sal_pc (&sals.sals[i]);
fee933f1
RP
2753
2754 /* Reparse conditions, they might contain references to the
2755 old symtab. */
2756 if (b->cond_string != NULL)
2757 {
2758 s = b->cond_string;
2759 if (b->cond)
2760 free ((PTR)b->cond);
2761 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
2762 }
2763
2764 /* We need to re-set the breakpoint if the address changes...*/
d889f6b7 2765 if (b->address != sals.sals[i].pc
fee933f1
RP
2766 /* ...or new and old breakpoints both have source files, and
2767 the source file name or the line number changes... */
d889f6b7
JK
2768 || (b->source_file != NULL
2769 && sals.sals[i].symtab != NULL
2770 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
2771 || b->line_number != sals.sals[i].line)
fee933f1
RP
2772 )
2773 /* ...or we switch between having a source file and not having
2774 one. */
2775 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
2776 )
bd5635a1 2777 {
d889f6b7
JK
2778 if (b->source_file != NULL)
2779 free (b->source_file);
2780 if (sals.sals[i].symtab == NULL)
2781 b->source_file = NULL;
2782 else
2783 b->source_file =
2784 savestring (sals.sals[i].symtab->filename,
2785 strlen (sals.sals[i].symtab->filename));
8537ba60
SG
2786 b->line_number = sals.sals[i].line;
2787 b->address = sals.sals[i].pc;
bd5635a1 2788
8537ba60 2789 check_duplicates (b->address);
bd5635a1 2790
8537ba60
SG
2791 mention (b);
2792 }
30875e1c 2793 b->enable = save_enable; /* Restore it, this worked. */
bd5635a1 2794 }
c8950965 2795 free ((PTR)sals.sals);
80ba48f5 2796 break;
2d313932 2797
80ba48f5 2798 case bp_watchpoint:
0eaaa46a 2799 innermost_block = NULL;
0a97f6c4
JK
2800 /* The issue arises of what context to evaluate this in. The same
2801 one as when it was set, but what does that mean when symbols have
2802 been re-read? We could save the filename and functionname, but
2803 if the context is more local than that, the best we could do would
2804 be something like how many levels deep and which index at that
2805 particular level, but that's going to be less stable than filenames
2806 or functionnames. */
2807 /* So for now, just use a global context. */
0eaaa46a
JK
2808 b->exp = parse_expression (b->exp_string);
2809 b->exp_valid_block = innermost_block;
2810 b->val = evaluate_expression (b->exp);
2811 release_value (b->val);
2812 if (VALUE_LAZY (b->val))
2813 value_fetch_lazy (b->val);
2814
2d313932
JK
2815 if (b->cond_string != NULL)
2816 {
2817 s = b->cond_string;
2818 b->cond = parse_exp_1 (&s, (struct block *)0, 0);
2819 }
cabd4da6
JK
2820 if (b->enable == enabled)
2821 mention (b);
80ba48f5 2822 break;
2d313932 2823
80ba48f5
SG
2824 default:
2825 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
2d313932 2826 /* fall through */
80ba48f5
SG
2827 case bp_until:
2828 case bp_finish:
2829 case bp_longjmp:
2830 case bp_longjmp_resume:
cf3e377e 2831 case bp_call_dummy:
80ba48f5
SG
2832 delete_breakpoint (b);
2833 break;
bd5635a1 2834 }
80ba48f5 2835
bdbd5f50 2836 return 0;
bd5635a1
RP
2837}
2838
2839/* Re-set all breakpoints after symbols have been re-loaded. */
2840void
2841breakpoint_re_set ()
2842{
cba0d141 2843 struct breakpoint *b, *temp;
30875e1c
SG
2844 static char message1[] = "Error in re-setting breakpoint %d:\n";
2845 char message[sizeof (message1) + 30 /* slop */];
bd5635a1 2846
cba0d141 2847 ALL_BREAKPOINTS_SAFE (b, temp)
bd5635a1 2848 {
2d313932 2849 sprintf (message, message1, b->number); /* Format possible error msg */
fe675038
JK
2850 catch_errors (breakpoint_re_set_one, (char *) b, message,
2851 RETURN_MASK_ALL);
bd5635a1
RP
2852 }
2853
80ba48f5
SG
2854 create_longjmp_breakpoint("longjmp");
2855 create_longjmp_breakpoint("_longjmp");
2856 create_longjmp_breakpoint("siglongjmp");
2857 create_longjmp_breakpoint(NULL);
2858
1eeba686
PB
2859#if 0
2860 /* Took this out (temporaliy at least), since it produces an extra
2861 blank line at startup. This messes up the gdbtests. -PB */
bd5635a1
RP
2862 /* Blank line to finish off all those mention() messages we just printed. */
2863 printf_filtered ("\n");
1eeba686 2864#endif
bd5635a1
RP
2865}
2866\f
2867/* Set ignore-count of breakpoint number BPTNUM to COUNT.
2868 If from_tty is nonzero, it prints a message to that effect,
2869 which ends with a period (no newline). */
2870
2871void
2872set_ignore_count (bptnum, count, from_tty)
2873 int bptnum, count, from_tty;
2874{
2875 register struct breakpoint *b;
2876
2877 if (count < 0)
2878 count = 0;
2879
2880 ALL_BREAKPOINTS (b)
2881 if (b->number == bptnum)
2882 {
2883 b->ignore_count = count;
2884 if (!from_tty)
2885 return;
2886 else if (count == 0)
423e9664
SG
2887 printf_filtered ("Will stop next time breakpoint %d is reached.",
2888 bptnum);
bd5635a1 2889 else if (count == 1)
423e9664
SG
2890 printf_filtered ("Will ignore next crossing of breakpoint %d.",
2891 bptnum);
bd5635a1 2892 else
423e9664 2893 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
bd5635a1
RP
2894 count, bptnum);
2895 return;
2896 }
2897
2898 error ("No breakpoint number %d.", bptnum);
2899}
2900
2901/* Clear the ignore counts of all breakpoints. */
2902void
2903breakpoint_clear_ignore_counts ()
2904{
2905 struct breakpoint *b;
2906
2907 ALL_BREAKPOINTS (b)
2908 b->ignore_count = 0;
2909}
2910
2911/* Command to set ignore-count of breakpoint N to COUNT. */
2912
2913static void
2914ignore_command (args, from_tty)
2915 char *args;
2916 int from_tty;
2917{
2918 char *p = args;
2919 register int num;
2920
2921 if (p == 0)
2922 error_no_arg ("a breakpoint number");
2923
2924 num = get_number (&p);
2925
2926 if (*p == 0)
2927 error ("Second argument (specified ignore-count) is missing.");
2928
bdbd5f50
JG
2929 set_ignore_count (num,
2930 longest_to_int (value_as_long (parse_and_eval (p))),
2931 from_tty);
423e9664 2932 printf_filtered ("\n");
bd5635a1
RP
2933}
2934\f
2935/* Call FUNCTION on each of the breakpoints
2936 whose numbers are given in ARGS. */
2937
2938static void
2939map_breakpoint_numbers (args, function)
2940 char *args;
30875e1c 2941 void (*function) PARAMS ((struct breakpoint *));
bd5635a1
RP
2942{
2943 register char *p = args;
2944 char *p1;
2945 register int num;
2946 register struct breakpoint *b;
2947
2948 if (p == 0)
2949 error_no_arg ("one or more breakpoint numbers");
2950
2951 while (*p)
2952 {
2953 p1 = p;
2954
2955 num = get_number (&p1);
2956
2957 ALL_BREAKPOINTS (b)
2958 if (b->number == num)
2959 {
2960 function (b);
2961 goto win;
2962 }
199b2450 2963 printf_unfiltered ("No breakpoint number %d.\n", num);
bd5635a1
RP
2964 win:
2965 p = p1;
2966 }
2967}
2968
2969static void
2970enable_breakpoint (bpt)
2971 struct breakpoint *bpt;
2972{
fee933f1 2973 FRAME save_selected_frame = NULL;
fa99ebe1
JK
2974 int save_selected_frame_level = -1;
2975
bd5635a1
RP
2976 bpt->enable = enabled;
2977
30875e1c 2978 if (xgdb_verbose && bpt->type == bp_breakpoint)
199b2450 2979 printf_unfiltered ("breakpoint #%d enabled\n", bpt->number);
bd5635a1
RP
2980
2981 check_duplicates (bpt->address);
30875e1c 2982 if (bpt->type == bp_watchpoint)
bd5635a1 2983 {
fa99ebe1 2984 if (bpt->exp_valid_block != NULL)
f266e564 2985 {
fa99ebe1
JK
2986 FRAME fr = within_scope (bpt->exp_valid_block);
2987 if (fr == NULL)
2988 {
2989 printf_filtered ("\
f266e564
JK
2990Cannot enable watchpoint %d because the block in which its expression\n\
2991is valid is not currently in scope.\n", bpt->number);
fa99ebe1
JK
2992 bpt->enable = disabled;
2993 return;
2994 }
2995 save_selected_frame = selected_frame;
2996 save_selected_frame_level = selected_frame_level;
2997 select_frame (fr, -1);
f266e564
JK
2998 }
2999
bd5635a1
RP
3000 value_free (bpt->val);
3001
3002 bpt->val = evaluate_expression (bpt->exp);
3003 release_value (bpt->val);
2d313932
JK
3004 if (VALUE_LAZY (bpt->val))
3005 value_fetch_lazy (bpt->val);
fa99ebe1
JK
3006
3007 if (save_selected_frame_level >= 0)
3008 select_frame (save_selected_frame, save_selected_frame_level);
bd5635a1
RP
3009 }
3010}
3011
bdbd5f50 3012/* ARGSUSED */
bd5635a1
RP
3013static void
3014enable_command (args, from_tty)
3015 char *args;
3016 int from_tty;
3017{
3018 struct breakpoint *bpt;
3019 if (args == 0)
3020 ALL_BREAKPOINTS (bpt)
423e9664
SG
3021 switch (bpt->type)
3022 {
3023 case bp_breakpoint:
3024 case bp_watchpoint:
3025 enable_breakpoint (bpt);
3026 default:
3027 continue;
3028 }
bd5635a1
RP
3029 else
3030 map_breakpoint_numbers (args, enable_breakpoint);
3031}
3032
3033static void
3034disable_breakpoint (bpt)
3035 struct breakpoint *bpt;
3036{
3037 bpt->enable = disabled;
3038
30875e1c 3039 if (xgdb_verbose && bpt->type == bp_breakpoint)
423e9664 3040 printf_filtered ("breakpoint #%d disabled\n", bpt->number);
bd5635a1
RP
3041
3042 check_duplicates (bpt->address);
3043}
3044
bdbd5f50 3045/* ARGSUSED */
bd5635a1
RP
3046static void
3047disable_command (args, from_tty)
3048 char *args;
3049 int from_tty;
3050{
3051 register struct breakpoint *bpt;
3052 if (args == 0)
3053 ALL_BREAKPOINTS (bpt)
423e9664
SG
3054 switch (bpt->type)
3055 {
3056 case bp_breakpoint:
3057 case bp_watchpoint:
3058 disable_breakpoint (bpt);
3059 default:
3060 continue;
3061 }
bd5635a1
RP
3062 else
3063 map_breakpoint_numbers (args, disable_breakpoint);
3064}
3065
3066static void
3067enable_once_breakpoint (bpt)
3068 struct breakpoint *bpt;
3069{
30875e1c
SG
3070 bpt->enable = enabled;
3071 bpt->disposition = disable;
bd5635a1
RP
3072
3073 check_duplicates (bpt->address);
3074}
3075
bdbd5f50 3076/* ARGSUSED */
bd5635a1
RP
3077static void
3078enable_once_command (args, from_tty)
3079 char *args;
3080 int from_tty;
3081{
3082 map_breakpoint_numbers (args, enable_once_breakpoint);
3083}
3084
3085static void
3086enable_delete_breakpoint (bpt)
3087 struct breakpoint *bpt;
3088{
30875e1c
SG
3089 bpt->enable = enabled;
3090 bpt->disposition = delete;
bd5635a1
RP
3091
3092 check_duplicates (bpt->address);
3093}
3094
bdbd5f50 3095/* ARGSUSED */
bd5635a1
RP
3096static void
3097enable_delete_command (args, from_tty)
3098 char *args;
3099 int from_tty;
3100{
3101 map_breakpoint_numbers (args, enable_delete_breakpoint);
3102}
3103\f
3104/*
3105 * Use default_breakpoint_'s, or nothing if they aren't valid.
3106 */
3107struct symtabs_and_lines
3108decode_line_spec_1 (string, funfirstline)
3109 char *string;
3110 int funfirstline;
3111{
3112 struct symtabs_and_lines sals;
3113 if (string == 0)
3114 error ("Empty line specification.");
3115 if (default_breakpoint_valid)
3116 sals = decode_line_1 (&string, funfirstline,
d889f6b7
JK
3117 default_breakpoint_symtab, default_breakpoint_line,
3118 (char ***)NULL);
bd5635a1 3119 else
d889f6b7
JK
3120 sals = decode_line_1 (&string, funfirstline,
3121 (struct symtab *)NULL, 0, (char ***)NULL);
bd5635a1
RP
3122 if (*string)
3123 error ("Junk at end of line specification: %s", string);
3124 return sals;
3125}
3126\f
bd5635a1
RP
3127void
3128_initialize_breakpoint ()
3129{
3130 breakpoint_chain = 0;
3131 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
3132 before a breakpoint is set. */
3133 breakpoint_count = 0;
3134
3135 add_com ("ignore", class_breakpoint, ignore_command,
3136 "Set ignore-count of breakpoint number N to COUNT.");
3137
3138 add_com ("commands", class_breakpoint, commands_command,
3139 "Set commands to be executed when a breakpoint is hit.\n\
3140Give breakpoint number as argument after \"commands\".\n\
3141With no argument, the targeted breakpoint is the last one set.\n\
3142The commands themselves follow starting on the next line.\n\
3143Type a line containing \"end\" to indicate the end of them.\n\
3144Give \"silent\" as the first line to make the breakpoint silent;\n\
3145then no output is printed when it is hit, except what the commands print.");
3146
3147 add_com ("condition", class_breakpoint, condition_command,
3148 "Specify breakpoint number N to break only if COND is true.\n\
d3b9c0df
JG
3149N is an integer; COND is an expression to be evaluated whenever\n\
3150breakpoint N is reached. ");
bd5635a1
RP
3151
3152 add_com ("tbreak", class_breakpoint, tbreak_command,
3153 "Set a temporary breakpoint. Args like \"break\" command.\n\
3154Like \"break\" except the breakpoint is only enabled temporarily,\n\
3155so it will be disabled when hit. Equivalent to \"break\" followed\n\
3156by using \"enable once\" on the breakpoint number.");
3157
3158 add_prefix_cmd ("enable", class_breakpoint, enable_command,
3159 "Enable some breakpoints.\n\
3160Give breakpoint numbers (separated by spaces) as arguments.\n\
3161With no subcommand, breakpoints are enabled until you command otherwise.\n\
3162This is used to cancel the effect of the \"disable\" command.\n\
3163With a subcommand you can enable temporarily.",
3164 &enablelist, "enable ", 1, &cmdlist);
3165
3166 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
3167 "Enable some breakpoints.\n\
3168Give breakpoint numbers (separated by spaces) as arguments.\n\
3169This is used to cancel the effect of the \"disable\" command.\n\
3170May be abbreviated to simply \"enable\".\n",
3171 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
3172
3173 add_cmd ("once", no_class, enable_once_command,
3174 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
3175If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
3176See the \"tbreak\" command which sets a breakpoint and enables it once.",
3177 &enablebreaklist);
3178
3179 add_cmd ("delete", no_class, enable_delete_command,
3180 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
3181If a breakpoint is hit while enabled in this fashion, it is deleted.",
3182 &enablebreaklist);
3183
3184 add_cmd ("delete", no_class, enable_delete_command,
3185 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
3186If a breakpoint is hit while enabled in this fashion, it is deleted.",
3187 &enablelist);
3188
3189 add_cmd ("once", no_class, enable_once_command,
3190 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
3191If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
3192See the \"tbreak\" command which sets a breakpoint and enables it once.",
3193 &enablelist);
3194
3195 add_prefix_cmd ("disable", class_breakpoint, disable_command,
3196 "Disable some breakpoints.\n\
3197Arguments are breakpoint numbers with spaces in between.\n\
3198To disable all breakpoints, give no argument.\n\
3199A disabled breakpoint is not forgotten, but has no effect until reenabled.",
3200 &disablelist, "disable ", 1, &cmdlist);
3201 add_com_alias ("dis", "disable", class_breakpoint, 1);
3202 add_com_alias ("disa", "disable", class_breakpoint, 1);
3203
3204 add_cmd ("breakpoints", class_alias, disable_command,
3205 "Disable some breakpoints.\n\
3206Arguments are breakpoint numbers with spaces in between.\n\
3207To disable all breakpoints, give no argument.\n\
3208A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
3209This command may be abbreviated \"disable\".",
3210 &disablelist);
3211
3212 add_prefix_cmd ("delete", class_breakpoint, delete_command,
3213 "Delete some breakpoints or auto-display expressions.\n\
3214Arguments are breakpoint numbers with spaces in between.\n\
3215To delete all breakpoints, give no argument.\n\
3216\n\
3217Also a prefix command for deletion of other GDB objects.\n\
3218The \"unset\" command is also an alias for \"delete\".",
3219 &deletelist, "delete ", 1, &cmdlist);
3220 add_com_alias ("d", "delete", class_breakpoint, 1);
bd5635a1
RP
3221
3222 add_cmd ("breakpoints", class_alias, delete_command,
3223 "Delete some breakpoints or auto-display expressions.\n\
3224Arguments are breakpoint numbers with spaces in between.\n\
3225To delete all breakpoints, give no argument.\n\
3226This command may be abbreviated \"delete\".",
3227 &deletelist);
3228
3229 add_com ("clear", class_breakpoint, clear_command,
3230 "Clear breakpoint at specified line or function.\n\
3231Argument may be line number, function name, or \"*\" and an address.\n\
3232If line number is specified, all breakpoints in that line are cleared.\n\
3233If function is specified, breakpoints at beginning of function are cleared.\n\
3234If an address is specified, breakpoints at that address are cleared.\n\n\
3235With no argument, clears all breakpoints in the line that the selected frame\n\
3236is executing in.\n\
3237\n\
3238See also the \"delete\" command which clears breakpoints by number.");
3239
3240 add_com ("break", class_breakpoint, break_command,
3241 "Set breakpoint at specified line or function.\n\
3242Argument may be line number, function name, or \"*\" and an address.\n\
3243If line number is specified, break at start of code for that line.\n\
3244If function is specified, break at start of code for that function.\n\
3245If an address is specified, break at that exact address.\n\
3246With no arg, uses current execution address of selected stack frame.\n\
3247This is useful for breaking on return to a stack frame.\n\
3248\n\
3249Multiple breakpoints at one place are permitted, and useful if conditional.\n\
3250\n\
3251Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
3252 add_com_alias ("b", "break", class_run, 1);
3253 add_com_alias ("br", "break", class_run, 1);
3254 add_com_alias ("bre", "break", class_run, 1);
3255 add_com_alias ("brea", "break", class_run, 1);
3256
3257 add_info ("breakpoints", breakpoints_info,
80ba48f5
SG
3258 "Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
3259The \"Type\" column indicates one of:\n\
423e9664
SG
3260\tbreakpoint - normal breakpoint\n\
3261\twatchpoint - watchpoint\n\
80ba48f5
SG
3262The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
3263the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
3264breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
3265address and file/line number respectively.\n\n\
3266Convenience variable \"$_\" and default examine address for \"x\"\n\
3267are set to the address of the last breakpoint listed.\n\n\
3268Convenience variable \"$bpnum\" contains the number of the last\n\
3269breakpoint set.");
3270
9b280a7f
JG
3271#if MAINTENANCE_CMDS
3272
3273 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
bd5635a1 3274 "Status of all breakpoints, or breakpoint number NUMBER.\n\
80ba48f5 3275The \"Type\" column indicates one of:\n\
423e9664
SG
3276\tbreakpoint - normal breakpoint\n\
3277\twatchpoint - watchpoint\n\
3278\tlongjmp - internal breakpoint used to step through longjmp()\n\
3279\tlongjmp resume - internal breakpoint at the target of longjmp()\n\
3280\tuntil - internal breakpoint used by the \"until\" command\n\
3281\tfinish - internal breakpoint used by the \"finish\" command\n\
80ba48f5
SG
3282The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
3283the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
3284breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
3285address and file/line number respectively.\n\n\
bd5635a1
RP
3286Convenience variable \"$_\" and default examine address for \"x\"\n\
3287are set to the address of the last breakpoint listed.\n\n\
3288Convenience variable \"$bpnum\" contains the number of the last\n\
9b280a7f
JG
3289breakpoint set.",
3290 &maintenanceinfolist);
3291
3292#endif /* MAINTENANCE_CMDS */
bd5635a1
RP
3293
3294 add_com ("catch", class_breakpoint, catch_command,
3295 "Set breakpoints to catch exceptions that are raised.\n\
3296Argument may be a single exception to catch, multiple exceptions\n\
3297to catch, or the default exception \"default\". If no arguments\n\
3298are given, breakpoints are set at all exception handlers catch clauses\n\
3299within the current scope.\n\
3300\n\
3301A condition specified for the catch applies to all breakpoints set\n\
3302with this command\n\
3303\n\
3304Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
3305
3306 add_com ("watch", class_breakpoint, watch_command,
3307 "Set a watchpoint for an expression.\n\
3308A watchpoint stops execution of your program whenever the value of\n\
3309an expression changes.");
3310
c8950965
JG
3311 add_info ("watchpoints", breakpoints_info,
3312 "Synonym for ``info breakpoints''.");
bd5635a1 3313}
1eeba686 3314
2d313932
JK
3315/* OK, when we call objfile_relocate, we need to relocate breakpoints
3316 too. breakpoint_re_set is not a good choice--for example, if
3317 addr_string contains just a line number without a file name the
3318 breakpoint might get set in a different file. In general, there is
3319 no need to go all the way back to the user's string (though this might
3320 work if some effort were made to canonicalize it), since symtabs and
3321 everything except addresses are still valid.
1eeba686 3322
2d313932
JK
3323 Probably the best way to solve this is to have each breakpoint save
3324 the objfile and the section number that was used to set it (if set
3325 by "*addr", probably it is best to use find_pc_line to get a symtab
3326 and use the objfile and block_line_section for that symtab). Then
3327 objfile_relocate can call fixup_breakpoints with the objfile and
3328 the new_offsets, and it can relocate only the appropriate breakpoints. */
1eeba686 3329
2d313932
JK
3330#ifdef IBM6000_TARGET
3331/* But for now, just kludge it based on the concept that before an
3332 objfile is relocated the breakpoint is below 0x10000000, and afterwards
3333 it is higher, so that way we only relocate each breakpoint once. */
1eeba686 3334
1eeba686
PB
3335void
3336fixup_breakpoints (low, high, delta)
3337 CORE_ADDR low;
3338 CORE_ADDR high;
3339 CORE_ADDR delta;
3340{
3341 struct breakpoint *b;
1eeba686
PB
3342
3343 ALL_BREAKPOINTS (b)
3344 {
3345 if (b->address >= low && b->address <= high)
3346 b->address += delta;
3347 }
3348}
3349#endif
This page took 0.28769 seconds and 4 git commands to generate.