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