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