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