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