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