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