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