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