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