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