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