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