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