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