]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/breakpoint.c
import gdb-1999-09-08 snapshot
[thirdparty/binutils-gdb.git] / gdb / breakpoint.c
CommitLineData
c906108c
SS
1/* Everything about breakpoints, for GDB.
2 Copyright 1986, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
c5aa993b 3 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
c906108c 11
c5aa993b
JM
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
c906108c 16
c5aa993b
JM
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
c906108c
SS
21
22#include "defs.h"
23#include <ctype.h>
24#include "symtab.h"
25#include "frame.h"
26#include "breakpoint.h"
27#include "gdbtypes.h"
28#include "expression.h"
29#include "gdbcore.h"
30#include "gdbcmd.h"
31#include "value.h"
32#include "command.h"
33#include "inferior.h"
34#include "gdbthread.h"
35#include "target.h"
36#include "language.h"
37#include "gdb_string.h"
38#include "demangle.h"
39#include "annotate.h"
40#include "symfile.h"
41#include "objfiles.h"
42
104c1213
JM
43#include "gdb-events.h"
44
c906108c
SS
45/* Prototypes for local functions. */
46
47static void
48catch_command_1 PARAMS ((char *, int, int));
49
50static void
51enable_delete_command PARAMS ((char *, int));
52
53static void
54enable_delete_breakpoint PARAMS ((struct breakpoint *));
55
56static void
57enable_once_command PARAMS ((char *, int));
58
59static void
60enable_once_breakpoint PARAMS ((struct breakpoint *));
61
62static void
63disable_command PARAMS ((char *, int));
64
65static void
66enable_command PARAMS ((char *, int));
67
68static void
c5aa993b 69map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *)));
c906108c
SS
70
71static void
72ignore_command PARAMS ((char *, int));
73
74static int breakpoint_re_set_one PARAMS ((PTR));
75
76static void
77clear_command PARAMS ((char *, int));
78
79static void
80catch_command PARAMS ((char *, int));
81
82static void
83handle_gnu_4_16_catch_command PARAMS ((char *, int, int));
84
85static struct symtabs_and_lines
86get_catch_sals PARAMS ((int));
87
88static void
89watch_command PARAMS ((char *, int));
90
91static int
92can_use_hardware_watchpoint PARAMS ((struct value *));
93
7a292a7a
SS
94static void break_at_finish_command PARAMS ((char *, int));
95static void break_at_finish_at_depth_command PARAMS ((char *, int));
96
c906108c
SS
97void
98tbreak_command PARAMS ((char *, int));
99
7a292a7a
SS
100static void tbreak_at_finish_command PARAMS ((char *, int));
101
c906108c
SS
102static void
103break_command_1 PARAMS ((char *, int, int));
104
105static void
106mention PARAMS ((struct breakpoint *));
107
108struct breakpoint *
c5aa993b 109 set_raw_breakpoint PARAMS ((struct symtab_and_line));
c906108c
SS
110
111static void
112check_duplicates PARAMS ((CORE_ADDR, asection *));
113
114static void
115describe_other_breakpoints PARAMS ((CORE_ADDR, asection *));
116
117static void
118breakpoints_info PARAMS ((char *, int));
119
120static void
121breakpoint_1 PARAMS ((int, int));
122
123static bpstat
c5aa993b 124 bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
c906108c
SS
125
126static int breakpoint_cond_eval PARAMS ((PTR));
127
128static void
129cleanup_executing_breakpoints PARAMS ((PTR));
130
131static void
132commands_command PARAMS ((char *, int));
133
134static void
135condition_command PARAMS ((char *, int));
136
137static int
138get_number PARAMS ((char **));
139
140void
141set_breakpoint_count PARAMS ((int));
142
143#if 0
144static struct breakpoint *
c5aa993b 145 create_temp_exception_breakpoint PARAMS ((CORE_ADDR));
c906108c
SS
146#endif
147
c5aa993b
JM
148typedef enum
149 {
150 mark_inserted,
151 mark_uninserted
152 }
153insertion_state_t;
c906108c
SS
154
155static int
156remove_breakpoint PARAMS ((struct breakpoint *, insertion_state_t));
157
158static int print_it_normal PARAMS ((bpstat));
159
c5aa993b
JM
160typedef struct
161 {
162 enum exception_event_kind kind;
163 int enable;
164 }
165args_for_catchpoint_enable;
c906108c
SS
166
167static int watchpoint_check PARAMS ((PTR));
168
169static int cover_target_enable_exception_callback PARAMS ((PTR));
170
171static int print_it_done PARAMS ((bpstat));
172
173static int print_it_noop PARAMS ((bpstat));
174
175static void maintenance_info_breakpoints PARAMS ((char *, int));
176
177#ifdef GET_LONGJMP_TARGET
178static void create_longjmp_breakpoint PARAMS ((char *));
179#endif
180
181static int hw_breakpoint_used_count PARAMS ((void));
182
183static int hw_watchpoint_used_count PARAMS ((enum bptype, int *));
184
185static void hbreak_command PARAMS ((char *, int));
186
187static void thbreak_command PARAMS ((char *, int));
188
189static void watch_command_1 PARAMS ((char *, int, int));
190
191static void rwatch_command PARAMS ((char *, int));
192
193static void awatch_command PARAMS ((char *, int));
194
195static void do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp));
196
53a5351d
JM
197static void solib_load_unload_1 PARAMS ((char *hookname,
198 int tempflag,
199 char *dll_pathname,
200 char *cond_string,
201 enum bptype bp_kind));
7a292a7a 202
53a5351d
JM
203static void create_fork_vfork_event_catchpoint PARAMS ((int tempflag,
204 char *cond_string,
205 enum bptype bp_kind));
7a292a7a 206
53a5351d
JM
207static void break_at_finish_at_depth_command_1 PARAMS ((char *arg,
208 int flag,
209 int from_tty));
7a292a7a 210
53a5351d
JM
211static void break_at_finish_command_1 PARAMS ((char *arg,
212 int flag,
213 int from_tty));
7a292a7a
SS
214
215static void stop_command PARAMS ((char *arg, int from_tty));
216
217static void stopin_command PARAMS ((char *arg, int from_tty));
218
219static void stopat_command PARAMS ((char *arg, int from_tty));
220
221static char *ep_find_event_name_end PARAMS ((char *arg));
222
223static char *ep_parse_optional_if_clause PARAMS ((char **arg));
224
225static char *ep_parse_optional_filename PARAMS ((char **arg));
226
53a5351d
JM
227static void catch_exec_command_1 PARAMS ((char *arg, int tempflag,
228 int from_tty));
7a292a7a 229
53a5351d
JM
230static void create_exception_catchpoint
231 PARAMS ((int tempflag, char *cond_string,
232 enum exception_event_kind ex_event,
233 struct symtab_and_line * sal));
7a292a7a 234
53a5351d
JM
235static void catch_exception_command_1
236 PARAMS ((enum exception_event_kind ex_event,
237 char *arg, int tempflag, int from_tty));
7a292a7a
SS
238
239static void tcatch_command PARAMS ((char *arg, int from_tty));
240
241static void ep_skip_leading_whitespace PARAMS ((char **s));
242
c906108c
SS
243/* Prototypes for exported functions. */
244
245static void
246awatch_command PARAMS ((char *, int));
247
248static void
249do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp));
250
251/* If FALSE, gdb will not use hardware support for watchpoints, even
252 if such is available. */
253static int can_use_hw_watchpoints;
254
255void delete_command PARAMS ((char *, int));
256
257void _initialize_breakpoint PARAMS ((void));
258
259void set_breakpoint_count PARAMS ((int));
260
c5aa993b 261extern int addressprint; /* Print machine addresses? */
c906108c
SS
262
263#if defined (GET_LONGJMP_TARGET) || defined (SOLIB_ADD)
264static int internal_breakpoint_number = -1;
265#endif
266
267/* Are we executing breakpoint commands? */
268static int executing_breakpoint_commands;
269
270/* Walk the following statement or block through all breakpoints.
271 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
272 breakpoint. */
273
274#define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
275
276#define ALL_BREAKPOINTS_SAFE(b,tmp) \
277 for (b = breakpoint_chain; \
278 b? (tmp=b->next, 1): 0; \
279 b = tmp)
280
281/* True if SHIFT_INST_REGS defined, false otherwise. */
282
283int must_shift_inst_regs =
284#if defined(SHIFT_INST_REGS)
2851
286#else
2870
288#endif
c5aa993b 289 ;
c906108c
SS
290
291/* True if breakpoint hit counts should be displayed in breakpoint info. */
292
293int show_breakpoint_hit_counts = 1;
294
295/* Chain of all breakpoints defined. */
296
297struct breakpoint *breakpoint_chain;
298
299/* Number of last breakpoint made. */
300
301int breakpoint_count;
302
c5aa993b
JM
303/* Pointer to current exception event record */
304static struct exception_event_record *current_exception_event;
c906108c
SS
305
306/* Indicator of whether exception catchpoints should be nuked
307 between runs of a program */
308int exception_catchpoints_are_fragile = 0;
c5aa993b 309
c906108c
SS
310/* Indicator of when exception catchpoints set-up should be
311 reinitialized -- e.g. when program is re-run */
312int exception_support_initialized = 0;
313
314/* This function returns a pointer to the string representation of the
315 pathname of the dynamically-linked library that has just been
316 loaded.
317
318 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
319 or undefined results are guaranteed.
320
321 This string's contents are only valid immediately after the
322 inferior has stopped in the dynamic linker hook, and becomes
323 invalid as soon as the inferior is continued. Clients should make
324 a copy of this string if they wish to continue the inferior and
325 then access the string. */
326
327#ifndef SOLIB_LOADED_LIBRARY_PATHNAME
328#define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
329#endif
330
331/* This function returns a pointer to the string representation of the
332 pathname of the dynamically-linked library that has just been
333 unloaded.
334
335 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
336 TRUE, or undefined results are guaranteed.
337
338 This string's contents are only valid immediately after the
339 inferior has stopped in the dynamic linker hook, and becomes
340 invalid as soon as the inferior is continued. Clients should make
341 a copy of this string if they wish to continue the inferior and
342 then access the string. */
343
344#ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
345#define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
346#endif
347
348/* This function is called by the "catch load" command. It allows the
349 debugger to be notified by the dynamic linker when a specified
350 library file (or any library file, if filename is NULL) is loaded. */
351
352#ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
353#define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
354 error ("catch of library loads not yet implemented on this platform")
355#endif
356
357/* This function is called by the "catch unload" command. It allows
358 the debugger to be notified by the dynamic linker when a specified
359 library file (or any library file, if filename is NULL) is
360 unloaded. */
361
362#ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
363#define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
364 error ("catch of library unloads not yet implemented on this platform")
365#endif
366
367/* Set breakpoint count to NUM. */
368
369void
370set_breakpoint_count (num)
371 int num;
372{
373 breakpoint_count = num;
374 set_internalvar (lookup_internalvar ("bpnum"),
375 value_from_longest (builtin_type_int, (LONGEST) num));
376}
377
378/* Used in run_command to zero the hit count when a new run starts. */
379
380void
381clear_breakpoint_hit_counts ()
382{
383 struct breakpoint *b;
384
385 ALL_BREAKPOINTS (b)
386 b->hit_count = 0;
387}
388
389/* Default address, symtab and line to put a breakpoint at
390 for "break" command with no arg.
391 if default_breakpoint_valid is zero, the other three are
392 not valid, and "break" with no arg is an error.
393
394 This set by print_stack_frame, which calls set_default_breakpoint. */
395
396int default_breakpoint_valid;
397CORE_ADDR default_breakpoint_address;
398struct symtab *default_breakpoint_symtab;
399int default_breakpoint_line;
400\f
401/* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
402 Advance *PP after the string and any trailing whitespace.
403
404 Currently the string can either be a number or "$" followed by the name
405 of a convenience variable. Making it an expression wouldn't work well
406 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
407static int
408get_number (pp)
409 char **pp;
410{
411 int retval;
412 char *p = *pp;
413
414 if (p == NULL)
415 /* Empty line means refer to the last breakpoint. */
416 return breakpoint_count;
417 else if (*p == '$')
418 {
419 /* Make a copy of the name, so we can null-terminate it
c5aa993b 420 to pass to lookup_internalvar(). */
c906108c
SS
421 char *varname;
422 char *start = ++p;
423 value_ptr val;
424
425 while (isalnum (*p) || *p == '_')
426 p++;
427 varname = (char *) alloca (p - start + 1);
428 strncpy (varname, start, p - start);
429 varname[p - start] = '\0';
430 val = value_of_internalvar (lookup_internalvar (varname));
431 if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
432 error (
53a5351d 433 "Convenience variables used to specify breakpoints must have integer values."
c5aa993b 434 );
c906108c
SS
435 retval = (int) value_as_long (val);
436 }
437 else
438 {
439 if (*p == '-')
440 ++p;
441 while (*p >= '0' && *p <= '9')
442 ++p;
443 if (p == *pp)
444 /* There is no number here. (e.g. "cond a == b"). */
445 error_no_arg ("breakpoint number");
446 retval = atoi (*pp);
447 }
448 if (!(isspace (*p) || *p == '\0'))
449 error ("breakpoint number expected");
450 while (isspace (*p))
451 p++;
452 *pp = p;
453 return retval;
454}
455\f
456/* condition N EXP -- set break condition of breakpoint N to EXP. */
457
458static void
459condition_command (arg, from_tty)
460 char *arg;
461 int from_tty;
462{
463 register struct breakpoint *b;
464 char *p;
465 register int bnum;
466
467 if (arg == 0)
468 error_no_arg ("breakpoint number");
469
470 p = arg;
471 bnum = get_number (&p);
472
473 ALL_BREAKPOINTS (b)
474 if (b->number == bnum)
c5aa993b
JM
475 {
476 if (b->cond)
477 {
478 free ((PTR) b->cond);
479 b->cond = 0;
480 }
481 if (b->cond_string != NULL)
482 free ((PTR) b->cond_string);
c906108c 483
c5aa993b
JM
484 if (*p == 0)
485 {
486 b->cond = 0;
487 b->cond_string = NULL;
488 if (from_tty)
489 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
490 }
491 else
492 {
493 arg = p;
494 /* I don't know if it matters whether this is the string the user
495 typed in or the decompiled expression. */
496 b->cond_string = savestring (arg, strlen (arg));
497 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
498 if (*arg)
499 error ("Junk at end of expression");
500 }
501 breakpoints_changed ();
502 return;
503 }
c906108c
SS
504
505 error ("No breakpoint number %d.", bnum);
506}
507
508/* ARGSUSED */
509static void
510commands_command (arg, from_tty)
511 char *arg;
512 int from_tty;
513{
514 register struct breakpoint *b;
515 char *p;
516 register int bnum;
517 struct command_line *l;
518
519 /* If we allowed this, we would have problems with when to
520 free the storage, if we change the commands currently
521 being read from. */
522
523 if (executing_breakpoint_commands)
524 error ("Can't use the \"commands\" command among a breakpoint's commands.");
525
526 p = arg;
527 bnum = get_number (&p);
528 if (p && *p)
529 error ("Unexpected extra arguments following breakpoint number.");
c5aa993b 530
c906108c
SS
531 ALL_BREAKPOINTS (b)
532 if (b->number == bnum)
c5aa993b
JM
533 {
534 char tmpbuf[128];
53a5351d
JM
535 sprintf (tmpbuf,
536 "Type commands for when breakpoint %d is hit, one per line.",
537 bnum);
c5aa993b
JM
538 l = read_command_lines (tmpbuf, from_tty);
539 free_command_lines (&b->commands);
540 b->commands = l;
541 breakpoints_changed ();
542 return;
543 }
c906108c
SS
544 error ("No breakpoint number %d.", bnum);
545}
546\f
547/* Like target_read_memory() but if breakpoints are inserted, return
548 the shadow contents instead of the breakpoints themselves.
549
550 Read "memory data" from whatever target or inferior we have.
551 Returns zero if successful, errno value if not. EIO is used
552 for address out of bounds. If breakpoints are inserted, returns
553 shadow contents, not the breakpoints themselves. From breakpoint.c. */
554
555int
556read_memory_nobpt (memaddr, myaddr, len)
557 CORE_ADDR memaddr;
558 char *myaddr;
559 unsigned len;
560{
561 int status;
562 struct breakpoint *b;
563 CORE_ADDR bp_addr = 0;
564 int bp_size = 0;
565
566 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
567 /* No breakpoints on this machine. */
568 return target_read_memory (memaddr, myaddr, len);
c5aa993b 569
c906108c 570 ALL_BREAKPOINTS (b)
c5aa993b
JM
571 {
572 if (b->type == bp_none)
53a5351d
JM
573 warning ("reading through apparently deleted breakpoint #%d?",
574 b->number);
c5aa993b
JM
575
576 /* memory breakpoint? */
577 if (b->type == bp_watchpoint
578 || b->type == bp_hardware_watchpoint
579 || b->type == bp_read_watchpoint
580 || b->type == bp_access_watchpoint)
581 continue;
582 /* bp in memory? */
583 if (!b->inserted)
584 continue;
585 /* Addresses and length of the part of the breakpoint that
586 we need to copy. */
587 /* XXXX The m68k, sh and h8300 have different local and remote
588 breakpoint values. BREAKPOINT_FROM_PC still manages to
589 correctly determine the breakpoints memory address and size
590 for these targets. */
591 bp_addr = b->address;
592 bp_size = 0;
593 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
594 continue;
595 if (bp_size == 0)
596 /* bp isn't valid */
597 continue;
598 if (bp_addr + bp_size <= memaddr)
599 /* The breakpoint is entirely before the chunk of memory we
600 are reading. */
601 continue;
602 if (bp_addr >= memaddr + len)
603 /* The breakpoint is entirely after the chunk of memory we are
604 reading. */
605 continue;
606 /* Copy the breakpoint from the shadow contents, and recurse for
607 the things before and after. */
c906108c 608 {
c5aa993b
JM
609 /* Offset within shadow_contents. */
610 int bptoffset = 0;
c906108c 611
c5aa993b
JM
612 if (bp_addr < memaddr)
613 {
614 /* Only copy the second part of the breakpoint. */
615 bp_size -= memaddr - bp_addr;
616 bptoffset = memaddr - bp_addr;
617 bp_addr = memaddr;
618 }
619
620 if (bp_addr + bp_size > memaddr + len)
621 {
622 /* Only copy the first part of the breakpoint. */
623 bp_size -= (bp_addr + bp_size) - (memaddr + len);
624 }
625
626 memcpy (myaddr + bp_addr - memaddr,
627 b->shadow_contents + bptoffset, bp_size);
628
629 if (bp_addr > memaddr)
630 {
631 /* Copy the section of memory before the breakpoint. */
632 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
633 if (status != 0)
634 return status;
635 }
636
637 if (bp_addr + bp_size < memaddr + len)
638 {
639 /* Copy the section of memory after the breakpoint. */
640 status = read_memory_nobpt
641 (bp_addr + bp_size,
642 myaddr + bp_addr + bp_size - memaddr,
643 memaddr + len - (bp_addr + bp_size));
644 if (status != 0)
645 return status;
646 }
647 return 0;
c906108c 648 }
c5aa993b 649 }
c906108c
SS
650 /* Nothing overlaps. Just call read_memory_noerr. */
651 return target_read_memory (memaddr, myaddr, len);
652}
c906108c 653\f
c5aa993b 654
c906108c
SS
655/* insert_breakpoints is used when starting or continuing the program.
656 remove_breakpoints is used when the program stops.
657 Both return zero if successful,
658 or an `errno' value if could not write the inferior. */
659
660int
661insert_breakpoints ()
662{
663 register struct breakpoint *b, *temp;
53a5351d 664 int return_val = 0; /* return success code. */
c906108c
SS
665 int val = 0;
666 int disabled_breaks = 0;
667
668 static char message1[] = "Error inserting catchpoint %d:\n";
669 static char message[sizeof (message1) + 30];
670
671
672 ALL_BREAKPOINTS_SAFE (b, temp)
c5aa993b
JM
673 {
674 if (b->type != bp_watchpoint
675 && b->type != bp_hardware_watchpoint
676 && b->type != bp_read_watchpoint
677 && b->type != bp_access_watchpoint
678 && b->type != bp_catch_fork
679 && b->type != bp_catch_vfork
680 && b->type != bp_catch_exec
681 && b->type != bp_catch_throw
682 && b->type != bp_catch_catch
683 && b->enable != disabled
684 && b->enable != shlib_disabled
685 && b->enable != call_disabled
686 && !b->inserted
687 && !b->duplicate)
688 {
689 if (b->type == bp_hardware_breakpoint)
690 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
691 else
692 {
693 /* Check to see if breakpoint is in an overlay section;
694 if so, we should set the breakpoint at the LMA address.
695 Only if the section is currently mapped should we ALSO
696 set a break at the VMA address. */
697 if (overlay_debugging && b->section &&
698 section_is_overlay (b->section))
699 {
700 CORE_ADDR addr;
701
702 addr = overlay_unmapped_address (b->address, b->section);
703 val = target_insert_breakpoint (addr, b->shadow_contents);
704 /* This would be the time to check val, to see if the
705 breakpoint write to the load address succeeded.
706 However, this might be an ordinary occurrance, eg. if
707 the unmapped overlay is in ROM. */
708 val = 0; /* in case unmapped address failed */
709 if (section_is_mapped (b->section))
710 val = target_insert_breakpoint (b->address,
711 b->shadow_contents);
712 }
713 else /* ordinary (non-overlay) address */
714 val = target_insert_breakpoint (b->address, b->shadow_contents);
715 }
716 if (val)
717 {
718 /* Can't set the breakpoint. */
c906108c 719#if defined (DISABLE_UNSETTABLE_BREAK)
c5aa993b
JM
720 if (DISABLE_UNSETTABLE_BREAK (b->address))
721 {
722 /* See also: disable_breakpoints_in_shlibs. */
723 val = 0;
724 b->enable = shlib_disabled;
725 if (!disabled_breaks)
726 {
727 target_terminal_ours_for_output ();
53a5351d
JM
728 warning ("Cannot insert breakpoint %d:", b->number);
729 warning ("Temporarily disabling shared library breakpoints:");
c5aa993b
JM
730 }
731 disabled_breaks = 1;
53a5351d 732 warning ("breakpoint #%d ", b->number);
c5aa993b
JM
733 }
734 else
c906108c 735#endif
c5aa993b
JM
736 {
737 target_terminal_ours_for_output ();
53a5351d 738 warning ("Cannot insert breakpoint %d:", b->number);
c906108c 739#ifdef ONE_PROCESS_WRITETEXT
53a5351d 740 warning ("The same program may be running in another process.");
c906108c 741#endif
53a5351d 742 memory_error (val, b->address); /* which bombs us out */
c5aa993b
JM
743 }
744 }
745 else
746 b->inserted = 1;
53a5351d
JM
747
748 if (val)
749 return_val = val; /* remember failure */
c5aa993b 750 }
c906108c 751 else if (ep_is_exception_catchpoint (b)
c5aa993b
JM
752 && b->enable != disabled
753 && b->enable != shlib_disabled
754 && b->enable != call_disabled
755 && !b->inserted
756 && !b->duplicate)
c906108c
SS
757
758 {
c5aa993b
JM
759 /* If we get here, we must have a callback mechanism for exception
760 events -- with g++ style embedded label support, we insert
761 ordinary breakpoints and not catchpoints. */
53a5351d
JM
762 /* Format possible error message */
763 sprintf (message, message1, b->number);
c5aa993b
JM
764
765 val = target_insert_breakpoint (b->address, b->shadow_contents);
766 if (val)
767 {
768 /* Couldn't set breakpoint for some reason */
769 target_terminal_ours_for_output ();
53a5351d
JM
770 warning ("Cannot insert catchpoint %d; disabling it.",
771 b->number);
c5aa993b
JM
772 b->enable = disabled;
773 }
774 else
775 {
776 /* Bp set, now make sure callbacks are enabled */
c906108c 777 int val;
c5aa993b 778 args_for_catchpoint_enable args;
53a5351d
JM
779 args.kind = b->type == bp_catch_catch ?
780 EX_EVENT_CATCH : EX_EVENT_THROW;
c906108c
SS
781 args.enable = 1;
782 val = catch_errors (cover_target_enable_exception_callback,
783 &args,
784 message, RETURN_MASK_ALL);
785 if (val != 0 && val != -1)
786 {
787 b->inserted = 1;
788 }
c5aa993b 789 /* Check if something went wrong; val == 0 can be ignored */
c906108c
SS
790 if (val == -1)
791 {
c5aa993b 792 /* something went wrong */
c906108c 793 target_terminal_ours_for_output ();
53a5351d
JM
794 warning ("Cannot insert catchpoint %d; disabling it.",
795 b->number);
c906108c
SS
796 b->enable = disabled;
797 }
c5aa993b 798 }
53a5351d
JM
799
800 if (val)
801 return_val = val; /* remember failure */
c906108c
SS
802 }
803
c5aa993b
JM
804 else if ((b->type == bp_hardware_watchpoint ||
805 b->type == bp_read_watchpoint ||
806 b->type == bp_access_watchpoint)
807 && b->enable == enabled
808 && !b->inserted
809 && !b->duplicate)
810 {
811 struct frame_info *saved_frame;
812 int saved_level, within_current_scope;
813 value_ptr mark = value_mark ();
814 value_ptr v;
815
816 /* Save the current frame and level so we can restore it after
817 evaluating the watchpoint expression on its own frame. */
818 saved_frame = selected_frame;
819 saved_level = selected_frame_level;
820
821 /* Determine if the watchpoint is within scope. */
822 if (b->exp_valid_block == NULL)
823 within_current_scope = 1;
824 else
825 {
826 struct frame_info *fi;
827
828 /* There might be no current frame at this moment if we are
829 resuming from a step over a breakpoint.
830 Set up current frame before trying to find the watchpoint
831 frame. */
832 get_current_frame ();
833 fi = find_frame_addr_in_frame_chain (b->watchpoint_frame);
834 within_current_scope = (fi != NULL);
835 if (within_current_scope)
836 select_frame (fi, -1);
837 }
838
839 if (within_current_scope)
840 {
841 /* Evaluate the expression and cut the chain of values
842 produced off from the value chain. */
843 v = evaluate_expression (b->exp);
844 value_release_to_mark (mark);
845
846 b->val_chain = v;
847 b->inserted = 1;
848
849 /* Look at each value on the value chain. */
850 for (; v; v = v->next)
851 {
852 /* If it's a memory location, then we must watch it. */
853 if (v->lval == lval_memory)
854 {
855 int addr, len, type;
856
857 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
858 len = TYPE_LENGTH (VALUE_TYPE (v));
53a5351d 859 type = hw_write;
c5aa993b 860 if (b->type == bp_read_watchpoint)
53a5351d 861 type = hw_read;
c5aa993b 862 else if (b->type == bp_access_watchpoint)
53a5351d 863 type = hw_access;
c5aa993b
JM
864
865 val = target_insert_watchpoint (addr, len, type);
866 if (val == -1)
867 {
868 b->inserted = 0;
869 break;
870 }
871 val = 0;
872 }
873 }
874 /* Failure to insert a watchpoint on any memory value in the
875 value chain brings us here. */
876 if (!b->inserted)
53a5351d
JM
877 {
878 remove_breakpoint (b, mark_uninserted);
879 warning ("Could not insert hardware watchpoint %d.",
880 b->number);
881 val = -1;
882 }
c5aa993b
JM
883 }
884 else
885 {
53a5351d
JM
886 printf_filtered ("Hardware watchpoint %d deleted", b->number);
887 printf_filtered ("because the program has left the block \n");
888 printf_filtered ("in which its expression is valid.\n");
c5aa993b
JM
889 if (b->related_breakpoint)
890 b->related_breakpoint->disposition = del_at_next_stop;
891 b->disposition = del_at_next_stop;
892 }
c906108c 893
c5aa993b
JM
894 /* Restore the frame and level. */
895 if ((saved_frame != selected_frame) ||
896 (saved_level != selected_frame_level))
897 select_and_print_frame (saved_frame, saved_level);
53a5351d
JM
898
899 if (val)
900 return_val = val; /* remember failure */
c5aa993b
JM
901 }
902 else if ((b->type == bp_catch_fork
903 || b->type == bp_catch_vfork
904 || b->type == bp_catch_exec)
905 && b->enable == enabled
906 && !b->inserted
907 && !b->duplicate)
908 {
909 val = -1;
910 switch (b->type)
911 {
912 case bp_catch_fork:
913 val = target_insert_fork_catchpoint (inferior_pid);
914 break;
915 case bp_catch_vfork:
916 val = target_insert_vfork_catchpoint (inferior_pid);
917 break;
918 case bp_catch_exec:
919 val = target_insert_exec_catchpoint (inferior_pid);
920 break;
921 default:
53a5351d 922 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
c5aa993b
JM
923 break;
924 }
925 if (val < 0)
926 {
927 target_terminal_ours_for_output ();
53a5351d 928 warning ("Cannot insert catchpoint %d.", b->number);
c5aa993b
JM
929 }
930 else
931 b->inserted = 1;
53a5351d
JM
932
933 if (val)
934 return_val = val; /* remember failure */
c5aa993b
JM
935 }
936 }
c906108c 937
53a5351d 938 return return_val;
c906108c
SS
939}
940
941
942int
943remove_breakpoints ()
944{
945 register struct breakpoint *b;
946 int val;
947
948 ALL_BREAKPOINTS (b)
c5aa993b
JM
949 {
950 if (b->inserted)
951 {
952 val = remove_breakpoint (b, mark_uninserted);
953 if (val != 0)
954 return val;
955 }
956 }
c906108c
SS
957 return 0;
958}
959
960int
961reattach_breakpoints (pid)
c5aa993b 962 int pid;
c906108c
SS
963{
964 register struct breakpoint *b;
965 int val;
c5aa993b 966 int saved_inferior_pid = inferior_pid;
c906108c 967
53a5351d
JM
968 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
969 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
c906108c 970 ALL_BREAKPOINTS (b)
c5aa993b
JM
971 {
972 if (b->inserted)
973 {
974 remove_breakpoint (b, mark_inserted);
975 if (b->type == bp_hardware_breakpoint)
976 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
977 else
978 val = target_insert_breakpoint (b->address, b->shadow_contents);
979 if (val != 0)
980 {
981 inferior_pid = saved_inferior_pid;
982 return val;
983 }
984 }
985 }
c906108c
SS
986 inferior_pid = saved_inferior_pid;
987 return 0;
988}
989
990void
991update_breakpoints_after_exec ()
992{
c5aa993b
JM
993 struct breakpoint *b;
994 struct breakpoint *temp;
c906108c
SS
995
996 /* Doing this first prevents the badness of having delete_breakpoint()
997 write a breakpoint's current "shadow contents" to lift the bp. That
998 shadow is NOT valid after an exec()! */
999 mark_breakpoints_out ();
1000
1001 ALL_BREAKPOINTS_SAFE (b, temp)
c5aa993b
JM
1002 {
1003 /* Solib breakpoints must be explicitly reset after an exec(). */
1004 if (b->type == bp_shlib_event)
1005 {
1006 delete_breakpoint (b);
1007 continue;
1008 }
c906108c 1009
c5aa993b
JM
1010 /* Step-resume breakpoints are meaningless after an exec(). */
1011 if (b->type == bp_step_resume)
1012 {
1013 delete_breakpoint (b);
1014 continue;
1015 }
1016
1017 /* Ditto the sigtramp handler breakpoints. */
1018 if (b->type == bp_through_sigtramp)
1019 {
1020 delete_breakpoint (b);
1021 continue;
1022 }
1023
1024 /* Ditto the exception-handling catchpoints. */
1025 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1026 {
1027 delete_breakpoint (b);
1028 continue;
1029 }
1030
1031 /* Don't delete an exec catchpoint, because else the inferior
1032 won't stop when it ought!
1033
1034 Similarly, we probably ought to keep vfork catchpoints, 'cause
53a5351d
JM
1035 on this target, we may not be able to stop when the vfork is
1036 seen, but only when the subsequent exec is seen. (And because
1037 deleting fork catchpoints here but not vfork catchpoints will
1038 seem mysterious to users, keep those too.)
c5aa993b
JM
1039
1040 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1041 target address field, if any, is sufficient to have it be reset
1042 automagically. Certainly on HP-UX that's true. */
1043 if ((b->type == bp_catch_exec) ||
1044 (b->type == bp_catch_vfork) ||
1045 (b->type == bp_catch_fork))
1046 {
1047 b->address = (CORE_ADDR) NULL;
1048 continue;
1049 }
1050
1051 /* bp_finish is a special case. The only way we ought to be able
1052 to see one of these when an exec() has happened, is if the user
1053 caught a vfork, and then said "finish". Ordinarily a finish just
1054 carries them to the call-site of the current callee, by setting
1055 a temporary bp there and resuming. But in this case, the finish
1056 will carry them entirely through the vfork & exec.
1057
1058 We don't want to allow a bp_finish to remain inserted now. But
1059 we can't safely delete it, 'cause finish_command has a handle to
1060 the bp on a bpstat, and will later want to delete it. There's a
1061 chance (and I've seen it happen) that if we delete the bp_finish
1062 here, that its storage will get reused by the time finish_command
1063 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1064 We really must allow finish_command to delete a bp_finish.
1065
53a5351d
JM
1066 In the absense of a general solution for the "how do we know
1067 it's safe to delete something others may have handles to?"
1068 problem, what we'll do here is just uninsert the bp_finish, and
1069 let finish_command delete it.
1070
1071 (We know the bp_finish is "doomed" in the sense that it's
1072 momentary, and will be deleted as soon as finish_command sees
1073 the inferior stopped. So it doesn't matter that the bp's
1074 address is probably bogus in the new a.out, unlike e.g., the
1075 solib breakpoints.) */
c5aa993b 1076
c5aa993b
JM
1077 if (b->type == bp_finish)
1078 {
1079 continue;
1080 }
1081
1082 /* Without a symbolic address, we have little hope of the
1083 pre-exec() address meaning the same thing in the post-exec()
1084 a.out. */
1085 if (b->addr_string == NULL)
1086 {
1087 delete_breakpoint (b);
1088 continue;
1089 }
1090
1091 /* If this breakpoint has survived the above battery of checks, then
1092 it must have a symbolic address. Be sure that it gets reevaluated
1093 to a target address, rather than reusing the old evaluation. */
1094 b->address = (CORE_ADDR) NULL;
1095 }
c906108c
SS
1096}
1097
1098int
1099detach_breakpoints (pid)
c5aa993b 1100 int pid;
c906108c
SS
1101{
1102 register struct breakpoint *b;
1103 int val;
c5aa993b
JM
1104 int saved_inferior_pid = inferior_pid;
1105
c906108c
SS
1106 if (pid == inferior_pid)
1107 error ("Cannot detach breakpoints of inferior_pid");
c5aa993b 1108
53a5351d
JM
1109 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
1110 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
c906108c 1111 ALL_BREAKPOINTS (b)
c5aa993b
JM
1112 {
1113 if (b->inserted)
1114 {
1115 val = remove_breakpoint (b, mark_inserted);
1116 if (val != 0)
1117 {
1118 inferior_pid = saved_inferior_pid;
1119 return val;
1120 }
1121 }
1122 }
c906108c
SS
1123 inferior_pid = saved_inferior_pid;
1124 return 0;
1125}
1126
1127static int
1128remove_breakpoint (b, is)
1129 struct breakpoint *b;
c5aa993b 1130 insertion_state_t is;
c906108c
SS
1131{
1132 int val;
c5aa993b 1133
c906108c 1134 if (b->type == bp_none)
53a5351d
JM
1135 warning ("attempted to remove apparently deleted breakpoint #%d?",
1136 b->number);
c906108c
SS
1137
1138 if (b->type != bp_watchpoint
1139 && b->type != bp_hardware_watchpoint
1140 && b->type != bp_read_watchpoint
1141 && b->type != bp_access_watchpoint
1142 && b->type != bp_catch_fork
1143 && b->type != bp_catch_vfork
1144 && b->type != bp_catch_exec
1145 && b->type != bp_catch_catch
1146 && b->type != bp_catch_throw)
c5aa993b 1147
c906108c
SS
1148 {
1149 if (b->type == bp_hardware_breakpoint)
c5aa993b 1150 val = target_remove_hw_breakpoint (b->address, b->shadow_contents);
c906108c
SS
1151 else
1152 {
1153 /* Check to see if breakpoint is in an overlay section;
1154 if so, we should remove the breakpoint at the LMA address.
1155 If that is not equal to the raw address, then we should
1156 presumable remove the breakpoint there as well. */
c5aa993b 1157 if (overlay_debugging && b->section &&
c906108c
SS
1158 section_is_overlay (b->section))
1159 {
1160 CORE_ADDR addr;
1161
1162 addr = overlay_unmapped_address (b->address, b->section);
1163 val = target_remove_breakpoint (addr, b->shadow_contents);
1164 /* This would be the time to check val, to see if the
c5aa993b
JM
1165 shadow breakpoint write to the load address succeeded.
1166 However, this might be an ordinary occurrance, eg. if
1167 the unmapped overlay is in ROM. */
1168 val = 0; /* in case unmapped address failed */
c906108c 1169 if (section_is_mapped (b->section))
c5aa993b 1170 val = target_remove_breakpoint (b->address,
c906108c
SS
1171 b->shadow_contents);
1172 }
c5aa993b
JM
1173 else /* ordinary (non-overlay) address */
1174 val = target_remove_breakpoint (b->address, b->shadow_contents);
c906108c
SS
1175 }
1176 if (val)
1177 return val;
1178 b->inserted = (is == mark_inserted);
1179 }
1180 else if ((b->type == bp_hardware_watchpoint ||
c5aa993b
JM
1181 b->type == bp_read_watchpoint ||
1182 b->type == bp_access_watchpoint)
c906108c 1183 && b->enable == enabled
c5aa993b 1184 && !b->duplicate)
c906108c
SS
1185 {
1186 value_ptr v, n;
c5aa993b 1187
c906108c
SS
1188 b->inserted = (is == mark_inserted);
1189 /* Walk down the saved value chain. */
1190 for (v = b->val_chain; v; v = v->next)
1191 {
1192 /* For each memory reference remove the watchpoint
1193 at that address. */
1194 if (v->lval == lval_memory)
1195 {
1196 int addr, len, type;
c5aa993b 1197
c906108c
SS
1198 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1199 len = TYPE_LENGTH (VALUE_TYPE (v));
53a5351d 1200 type = hw_write;
c906108c 1201 if (b->type == bp_read_watchpoint)
53a5351d 1202 type = hw_read;
c906108c 1203 else if (b->type == bp_access_watchpoint)
53a5351d 1204 type = hw_access;
c906108c
SS
1205
1206 val = target_remove_watchpoint (addr, len, type);
1207 if (val == -1)
1208 b->inserted = 1;
1209 val = 0;
1210 }
1211 }
1212 /* Failure to remove any of the hardware watchpoints comes here. */
1213 if ((is == mark_uninserted) && (b->inserted))
53a5351d 1214 warning ("Could not remove hardware watchpoint %d.",
c906108c 1215 b->number);
c5aa993b 1216
c906108c 1217 /* Free the saved value chain. We will construct a new one
c5aa993b 1218 the next time the watchpoint is inserted. */
c906108c
SS
1219 for (v = b->val_chain; v; v = n)
1220 {
1221 n = v->next;
1222 value_free (v);
1223 }
1224 b->val_chain = NULL;
1225 }
1226 else if ((b->type == bp_catch_fork ||
c5aa993b
JM
1227 b->type == bp_catch_vfork ||
1228 b->type == bp_catch_exec)
c906108c 1229 && b->enable == enabled
c5aa993b 1230 && !b->duplicate)
c906108c
SS
1231 {
1232 val = -1;
1233 switch (b->type)
c5aa993b
JM
1234 {
1235 case bp_catch_fork:
1236 val = target_remove_fork_catchpoint (inferior_pid);
1237 break;
1238 case bp_catch_vfork:
1239 val = target_remove_vfork_catchpoint (inferior_pid);
1240 break;
1241 case bp_catch_exec:
1242 val = target_remove_exec_catchpoint (inferior_pid);
1243 break;
ac9a91a7 1244 default:
53a5351d 1245 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
ac9a91a7 1246 break;
c5aa993b 1247 }
c906108c
SS
1248 if (val)
1249 return val;
1250 b->inserted = (is == mark_inserted);
1251 }
1252 else if ((b->type == bp_catch_catch ||
c5aa993b
JM
1253 b->type == bp_catch_throw)
1254 && b->enable == enabled
1255 && !b->duplicate)
c906108c
SS
1256 {
1257
c5aa993b 1258 val = target_remove_breakpoint (b->address, b->shadow_contents);
c906108c 1259 if (val)
c5aa993b 1260 return val;
c906108c
SS
1261 b->inserted = (is == mark_inserted);
1262 }
1263 else if (ep_is_exception_catchpoint (b)
c5aa993b
JM
1264 && b->inserted /* sometimes previous insert doesn't happen */
1265 && b->enable == enabled
1266 && !b->duplicate)
c906108c
SS
1267 {
1268
c5aa993b 1269 val = target_remove_breakpoint (b->address, b->shadow_contents);
c906108c 1270 if (val)
c5aa993b
JM
1271 return val;
1272
c906108c
SS
1273 b->inserted = (is == mark_inserted);
1274 }
1275
1276 return 0;
1277}
1278
1279/* Clear the "inserted" flag in all breakpoints. */
1280
1281void
1282mark_breakpoints_out ()
1283{
1284 register struct breakpoint *b;
1285
1286 ALL_BREAKPOINTS (b)
1287 b->inserted = 0;
1288}
1289
53a5351d
JM
1290/* Clear the "inserted" flag in all breakpoints and delete any
1291 breakpoints which should go away between runs of the program.
c906108c
SS
1292
1293 Plus other such housekeeping that has to be done for breakpoints
1294 between runs.
1295
53a5351d
JM
1296 Note: this function gets called at the end of a run (by
1297 generic_mourn_inferior) and when a run begins (by
1298 init_wait_for_inferior). */
c906108c
SS
1299
1300
1301
1302void
1303breakpoint_init_inferior (context)
c5aa993b 1304 enum inf_context context;
c906108c
SS
1305{
1306 register struct breakpoint *b, *temp;
1307 static int warning_needed = 0;
1308
1309 ALL_BREAKPOINTS_SAFE (b, temp)
c5aa993b
JM
1310 {
1311 b->inserted = 0;
c906108c 1312
c5aa993b
JM
1313 switch (b->type)
1314 {
1315 case bp_call_dummy:
1316 case bp_watchpoint_scope:
c906108c 1317
c5aa993b
JM
1318 /* If the call dummy breakpoint is at the entry point it will
1319 cause problems when the inferior is rerun, so we better
1320 get rid of it.
c906108c 1321
c5aa993b
JM
1322 Also get rid of scope breakpoints. */
1323 delete_breakpoint (b);
1324 break;
c906108c 1325
c5aa993b
JM
1326 case bp_watchpoint:
1327 case bp_hardware_watchpoint:
1328 case bp_read_watchpoint:
1329 case bp_access_watchpoint:
c906108c 1330
c5aa993b
JM
1331 /* Likewise for watchpoints on local expressions. */
1332 if (b->exp_valid_block != NULL)
1333 delete_breakpoint (b);
1334 break;
1335 default:
1336 /* Likewise for exception catchpoints in dynamic-linked
1337 executables where required */
1338 if (ep_is_exception_catchpoint (b) &&
1339 exception_catchpoints_are_fragile)
1340 {
1341 warning_needed = 1;
c906108c 1342 delete_breakpoint (b);
c5aa993b
JM
1343 }
1344 break;
1345 }
1346 }
c906108c
SS
1347
1348 if (exception_catchpoints_are_fragile)
1349 exception_support_initialized = 0;
1350
c5aa993b 1351 /* Don't issue the warning unless it's really needed... */
c906108c
SS
1352 if (warning_needed && (context != inf_exited))
1353 {
53a5351d
JM
1354 warning ("Exception catchpoints from last run were deleted.");
1355 warning ("You must reinsert them explicitly.");
c906108c 1356 warning_needed = 0;
c5aa993b 1357 }
c906108c
SS
1358}
1359
53a5351d
JM
1360/* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at
1361 PC. When continuing from a location with a breakpoint, we actually
1362 single step once before calling insert_breakpoints. */
c906108c
SS
1363
1364int
1365breakpoint_here_p (pc)
1366 CORE_ADDR pc;
1367{
1368 register struct breakpoint *b;
1369
1370 ALL_BREAKPOINTS (b)
1371 if (b->enable == enabled
1372 && b->enable != shlib_disabled
1373 && b->enable != call_disabled
1374 && b->address == pc) /* bp is enabled and matches pc */
c5aa993b
JM
1375 {
1376 if (overlay_debugging &&
1377 section_is_overlay (b->section) &&
1378 !section_is_mapped (b->section))
1379 continue; /* unmapped overlay -- can't be a match */
1380 else
1381 return 1;
1382 }
c906108c
SS
1383
1384 return 0;
1385}
1386
53a5351d
JM
1387/* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1388 but it only returns true if there is actually a breakpoint inserted
1389 at PC. */
c906108c
SS
1390
1391int
1392breakpoint_inserted_here_p (pc)
1393 CORE_ADDR pc;
1394{
1395 register struct breakpoint *b;
1396
1397 ALL_BREAKPOINTS (b)
1398 if (b->inserted
1399 && b->address == pc) /* bp is inserted and matches pc */
c5aa993b
JM
1400 {
1401 if (overlay_debugging &&
1402 section_is_overlay (b->section) &&
1403 !section_is_mapped (b->section))
1404 continue; /* unmapped overlay -- can't be a match */
1405 else
1406 return 1;
1407 }
c906108c
SS
1408
1409 return 0;
1410}
1411
53a5351d
JM
1412/* Return nonzero if FRAME is a dummy frame. We can't use
1413 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1414 much time, at least using get_saved_register on the 68k. This
1415 means that for this function to work right a port must use the
1416 bp_call_dummy breakpoint. */
c906108c
SS
1417
1418int
1419frame_in_dummy (frame)
1420 struct frame_info *frame;
1421{
c906108c
SS
1422 struct breakpoint *b;
1423
c5aa993b 1424 if (!CALL_DUMMY_P)
7a292a7a
SS
1425 return 0;
1426
1427 if (USE_GENERIC_DUMMY_FRAMES)
1428 return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame);
c5aa993b 1429
c906108c 1430 ALL_BREAKPOINTS (b)
c5aa993b
JM
1431 {
1432 if (b->type == bp_call_dummy
1433 && b->frame == frame->frame
1434 /* We need to check the PC as well as the frame on the sparc,
1435 for signals.exp in the testsuite. */
1436 && (frame->pc
1437 >= (b->address
1438 - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE))
1439 && frame->pc <= b->address)
1440 return 1;
1441 }
c906108c
SS
1442 return 0;
1443}
1444
1445/* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
1446 is valid for process/thread PID. */
1447
1448int
1449breakpoint_thread_match (pc, pid)
1450 CORE_ADDR pc;
1451 int pid;
1452{
1453 struct breakpoint *b;
1454 int thread;
1455
1456 thread = pid_to_thread_id (pid);
1457
1458 ALL_BREAKPOINTS (b)
1459 if (b->enable != disabled
1460 && b->enable != shlib_disabled
1461 && b->enable != call_disabled
1462 && b->address == pc
1463 && (b->thread == -1 || b->thread == thread))
c5aa993b
JM
1464 {
1465 if (overlay_debugging &&
1466 section_is_overlay (b->section) &&
1467 !section_is_mapped (b->section))
1468 continue; /* unmapped overlay -- can't be a match */
1469 else
1470 return 1;
1471 }
c906108c
SS
1472
1473 return 0;
1474}
c906108c 1475\f
c5aa993b 1476
c906108c
SS
1477/* bpstat stuff. External routines' interfaces are documented
1478 in breakpoint.h. */
1479
1480int
1481ep_is_catchpoint (ep)
c5aa993b 1482 struct breakpoint *ep;
c906108c
SS
1483{
1484 return
1485 (ep->type == bp_catch_load)
1486 || (ep->type == bp_catch_unload)
1487 || (ep->type == bp_catch_fork)
1488 || (ep->type == bp_catch_vfork)
1489 || (ep->type == bp_catch_exec)
1490 || (ep->type == bp_catch_catch)
1491 || (ep->type == bp_catch_throw)
1492
1493
c5aa993b 1494 /* ??rehrauer: Add more kinds here, as are implemented... */
c906108c
SS
1495 ;
1496}
c5aa993b 1497
c906108c
SS
1498int
1499ep_is_shlib_catchpoint (ep)
c5aa993b 1500 struct breakpoint *ep;
c906108c
SS
1501{
1502 return
1503 (ep->type == bp_catch_load)
1504 || (ep->type == bp_catch_unload)
1505 ;
1506}
1507
1508int
1509ep_is_exception_catchpoint (ep)
c5aa993b 1510 struct breakpoint *ep;
c906108c
SS
1511{
1512 return
1513 (ep->type == bp_catch_catch)
1514 || (ep->type == bp_catch_throw)
1515 ;
1516}
1517
1518/* Clear a bpstat so that it says we are not at any breakpoint.
1519 Also free any storage that is part of a bpstat. */
1520
1521void
1522bpstat_clear (bsp)
1523 bpstat *bsp;
1524{
1525 bpstat p;
1526 bpstat q;
1527
1528 if (bsp == 0)
1529 return;
1530 p = *bsp;
1531 while (p != NULL)
1532 {
1533 q = p->next;
1534 if (p->old_val != NULL)
1535 value_free (p->old_val);
c5aa993b 1536 free ((PTR) p);
c906108c
SS
1537 p = q;
1538 }
1539 *bsp = NULL;
1540}
1541
1542/* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1543 is part of the bpstat is copied as well. */
1544
1545bpstat
1546bpstat_copy (bs)
1547 bpstat bs;
1548{
1549 bpstat p = NULL;
1550 bpstat tmp;
1551 bpstat retval = NULL;
1552
1553 if (bs == NULL)
1554 return bs;
1555
1556 for (; bs != NULL; bs = bs->next)
1557 {
1558 tmp = (bpstat) xmalloc (sizeof (*tmp));
1559 memcpy (tmp, bs, sizeof (*tmp));
1560 if (p == NULL)
1561 /* This is the first thing in the chain. */
1562 retval = tmp;
1563 else
1564 p->next = tmp;
1565 p = tmp;
1566 }
1567 p->next = NULL;
1568 return retval;
1569}
1570
1571/* Find the bpstat associated with this breakpoint */
1572
1573bpstat
c5aa993b 1574bpstat_find_breakpoint (bsp, breakpoint)
c906108c
SS
1575 bpstat bsp;
1576 struct breakpoint *breakpoint;
1577{
c5aa993b
JM
1578 if (bsp == NULL)
1579 return NULL;
c906108c 1580
c5aa993b
JM
1581 for (; bsp != NULL; bsp = bsp->next)
1582 {
1583 if (bsp->breakpoint_at == breakpoint)
1584 return bsp;
1585 }
c906108c
SS
1586 return NULL;
1587}
1588
1589/* Find a step_resume breakpoint associated with this bpstat.
1590 (If there are multiple step_resume bp's on the list, this function
1591 will arbitrarily pick one.)
1592
1593 It is an error to use this function if BPSTAT doesn't contain a
1594 step_resume breakpoint.
1595
1596 See wait_for_inferior's use of this function. */
1597struct breakpoint *
1598bpstat_find_step_resume_breakpoint (bsp)
c5aa993b 1599 bpstat bsp;
c906108c
SS
1600{
1601 if (bsp == NULL)
1602 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1603
1604 for (; bsp != NULL; bsp = bsp->next)
1605 {
1606 if ((bsp->breakpoint_at != NULL) &&
c5aa993b
JM
1607 (bsp->breakpoint_at->type == bp_step_resume))
1608 return bsp->breakpoint_at;
c906108c
SS
1609 }
1610
1611 error ("Internal error (no step_resume breakpoint found)");
1612}
1613
1614
1615/* Return the breakpoint number of the first breakpoint we are stopped
1616 at. *BSP upon return is a bpstat which points to the remaining
1617 breakpoints stopped at (but which is not guaranteed to be good for
1618 anything but further calls to bpstat_num).
1619 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1620
1621int
1622bpstat_num (bsp)
1623 bpstat *bsp;
1624{
1625 struct breakpoint *b;
1626
1627 if ((*bsp) == NULL)
1628 return 0; /* No more breakpoint values */
1629 else
1630 {
1631 b = (*bsp)->breakpoint_at;
1632 *bsp = (*bsp)->next;
1633 if (b == NULL)
1634 return -1; /* breakpoint that's been deleted since */
1635 else
c5aa993b 1636 return b->number; /* We have its number */
c906108c
SS
1637 }
1638}
1639
1640/* Modify BS so that the actions will not be performed. */
1641
1642void
1643bpstat_clear_actions (bs)
1644 bpstat bs;
1645{
1646 for (; bs != NULL; bs = bs->next)
1647 {
1648 bs->commands = NULL;
1649 if (bs->old_val != NULL)
1650 {
1651 value_free (bs->old_val);
1652 bs->old_val = NULL;
1653 }
1654 }
1655}
1656
1657/* Stub for cleaning up our state if we error-out of a breakpoint command */
1658/* ARGSUSED */
1659static void
1660cleanup_executing_breakpoints (ignore)
1661 PTR ignore;
1662{
1663 executing_breakpoint_commands = 0;
1664}
1665
1666/* Execute all the commands associated with all the breakpoints at this
1667 location. Any of these commands could cause the process to proceed
1668 beyond this point, etc. We look out for such changes by checking
1669 the global "breakpoint_proceeded" after each command. */
1670
1671void
1672bpstat_do_actions (bsp)
1673 bpstat *bsp;
1674{
1675 bpstat bs;
1676 struct cleanup *old_chain;
1677 struct command_line *cmd;
1678
1679 /* Avoid endless recursion if a `source' command is contained
1680 in bs->commands. */
1681 if (executing_breakpoint_commands)
1682 return;
1683
1684 executing_breakpoint_commands = 1;
1685 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1686
1687top:
1688 /* Note that (as of this writing), our callers all appear to
1689 be passing us the address of global stop_bpstat. And, if
1690 our calls to execute_control_command cause the inferior to
1691 proceed, that global (and hence, *bsp) will change.
1692
1693 We must be careful to not touch *bsp unless the inferior
1694 has not proceeded. */
1695
1696 /* This pointer will iterate over the list of bpstat's. */
1697 bs = *bsp;
1698
1699 breakpoint_proceeded = 0;
1700 for (; bs != NULL; bs = bs->next)
1701 {
1702 cmd = bs->commands;
1703 while (cmd != NULL)
1704 {
1705 execute_control_command (cmd);
1706
1707 if (breakpoint_proceeded)
1708 break;
1709 else
1710 cmd = cmd->next;
1711 }
1712 if (breakpoint_proceeded)
1713 /* The inferior is proceeded by the command; bomb out now.
1714 The bpstat chain has been blown away by wait_for_inferior.
1715 But since execution has stopped again, there is a new bpstat
1716 to look at, so start over. */
1717 goto top;
1718 else
1719 bs->commands = NULL;
1720 }
1721
1722 executing_breakpoint_commands = 0;
1723 discard_cleanups (old_chain);
1724}
1725
1726/* This is the normal print_it function for a bpstat. In the future,
1727 much of this logic could (should?) be moved to bpstat_stop_status,
1728 by having it set different print_it functions.
1729
1730 Current scheme: When we stop, bpstat_print() is called.
1731 It loops through the bpstat list of things causing this stop,
1732 calling the print_it function for each one. The default
1733 print_it function, used for breakpoints, is print_it_normal().
1734 (Also see print_it_noop() and print_it_done()).
c5aa993b 1735
c906108c
SS
1736 Return values from this routine (used by bpstat_print() to
1737 decide what to do):
1738 1: Means we printed something, and we do *not* desire that
c5aa993b 1739 something to be followed by a location.
c906108c 1740 0: Means we printed something, and we *do* desire that
c5aa993b 1741 something to be followed by a location.
c906108c
SS
1742 -1: Means we printed nothing. */
1743
1744static int
1745print_it_normal (bs)
1746 bpstat bs;
1747{
1748 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1749 which has since been deleted. */
1750 if (bs->breakpoint_at == NULL
1751 || (bs->breakpoint_at->type != bp_breakpoint
c5aa993b
JM
1752 && bs->breakpoint_at->type != bp_catch_load
1753 && bs->breakpoint_at->type != bp_catch_unload
1754 && bs->breakpoint_at->type != bp_catch_fork
1755 && bs->breakpoint_at->type != bp_catch_vfork
1756 && bs->breakpoint_at->type != bp_catch_exec
1757 && bs->breakpoint_at->type != bp_catch_catch
1758 && bs->breakpoint_at->type != bp_catch_throw
c906108c
SS
1759 && bs->breakpoint_at->type != bp_hardware_breakpoint
1760 && bs->breakpoint_at->type != bp_watchpoint
1761 && bs->breakpoint_at->type != bp_read_watchpoint
1762 && bs->breakpoint_at->type != bp_access_watchpoint
1763 && bs->breakpoint_at->type != bp_hardware_watchpoint))
1764 return -1;
1765
1766 if (ep_is_shlib_catchpoint (bs->breakpoint_at))
1767 {
1768 annotate_catchpoint (bs->breakpoint_at->number);
1769 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1770 if (bs->breakpoint_at->type == bp_catch_load)
c5aa993b 1771 printf_filtered ("loaded");
c906108c 1772 else if (bs->breakpoint_at->type == bp_catch_unload)
c5aa993b 1773 printf_filtered ("unloaded");
c906108c
SS
1774 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1775 return 0;
1776 }
1777 else if (bs->breakpoint_at->type == bp_catch_fork ||
c5aa993b 1778 bs->breakpoint_at->type == bp_catch_vfork)
c906108c
SS
1779 {
1780 annotate_catchpoint (bs->breakpoint_at->number);
1781 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1782 if (bs->breakpoint_at->type == bp_catch_fork)
c5aa993b 1783 printf_filtered ("forked");
c906108c 1784 else if (bs->breakpoint_at->type == bp_catch_vfork)
c5aa993b 1785 printf_filtered ("vforked");
53a5351d
JM
1786 printf_filtered (" process %d), ",
1787 bs->breakpoint_at->forked_inferior_pid);
c906108c
SS
1788 return 0;
1789 }
1790 else if (bs->breakpoint_at->type == bp_catch_exec)
1791 {
1792 annotate_catchpoint (bs->breakpoint_at->number);
1793 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
c5aa993b
JM
1794 bs->breakpoint_at->number,
1795 bs->breakpoint_at->exec_pathname);
c906108c
SS
1796 return 0;
1797 }
c5aa993b 1798 else if (bs->breakpoint_at->type == bp_catch_catch)
c906108c 1799 {
53a5351d
JM
1800 if (current_exception_event &&
1801 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
c5aa993b
JM
1802 {
1803 annotate_catchpoint (bs->breakpoint_at->number);
53a5351d
JM
1804 printf_filtered ("\nCatchpoint %d (exception caught), ",
1805 bs->breakpoint_at->number);
c5aa993b
JM
1806 printf_filtered ("throw location ");
1807 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1808 printf_filtered ("%s:%d",
1809 CURRENT_EXCEPTION_THROW_FILE,
1810 CURRENT_EXCEPTION_THROW_LINE);
1811 else
1812 printf_filtered ("unknown");
1813
1814 printf_filtered (", catch location ");
1815 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
1816 printf_filtered ("%s:%d",
1817 CURRENT_EXCEPTION_CATCH_FILE,
1818 CURRENT_EXCEPTION_CATCH_LINE);
1819 else
1820 printf_filtered ("unknown");
1821
1822 printf_filtered ("\n");
53a5351d 1823 return 1; /* don't bother to print location frame info */
c5aa993b 1824 }
c906108c 1825 else
c5aa993b 1826 {
53a5351d 1827 return -1; /* really throw, some other bpstat will handle it */
c5aa993b 1828 }
c906108c
SS
1829 }
1830 else if (bs->breakpoint_at->type == bp_catch_throw)
1831 {
53a5351d
JM
1832 if (current_exception_event &&
1833 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
c5aa993b
JM
1834 {
1835 annotate_catchpoint (bs->breakpoint_at->number);
53a5351d
JM
1836 printf_filtered ("\nCatchpoint %d (exception thrown), ",
1837 bs->breakpoint_at->number);
c5aa993b
JM
1838 printf_filtered ("throw location ");
1839 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1840 printf_filtered ("%s:%d",
1841 CURRENT_EXCEPTION_THROW_FILE,
1842 CURRENT_EXCEPTION_THROW_LINE);
1843 else
1844 printf_filtered ("unknown");
1845
1846 printf_filtered (", catch location ");
1847 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
1848 printf_filtered ("%s:%d",
1849 CURRENT_EXCEPTION_CATCH_FILE,
1850 CURRENT_EXCEPTION_CATCH_LINE);
1851 else
1852 printf_filtered ("unknown");
1853
1854 printf_filtered ("\n");
53a5351d 1855 return 1; /* don't bother to print location frame info */
c5aa993b 1856 }
c906108c 1857 else
c5aa993b 1858 {
53a5351d 1859 return -1; /* really catch, some other bpstat willhandle it */
c5aa993b 1860 }
c906108c
SS
1861 }
1862
1863 else if (bs->breakpoint_at->type == bp_breakpoint ||
c5aa993b 1864 bs->breakpoint_at->type == bp_hardware_breakpoint)
c906108c
SS
1865 {
1866 /* I think the user probably only wants to see one breakpoint
c5aa993b 1867 number, not all of them. */
c906108c
SS
1868 annotate_breakpoint (bs->breakpoint_at->number);
1869 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
1870 return 0;
1871 }
1872 else if ((bs->old_val != NULL) &&
c5aa993b
JM
1873 (bs->breakpoint_at->type == bp_watchpoint ||
1874 bs->breakpoint_at->type == bp_access_watchpoint ||
1875 bs->breakpoint_at->type == bp_hardware_watchpoint))
c906108c
SS
1876 {
1877 annotate_watchpoint (bs->breakpoint_at->number);
1878 mention (bs->breakpoint_at);
1879 printf_filtered ("\nOld value = ");
1880 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
1881 printf_filtered ("\nNew value = ");
1882 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
1883 Val_pretty_default);
1884 printf_filtered ("\n");
1885 value_free (bs->old_val);
1886 bs->old_val = NULL;
1887 /* More than one watchpoint may have been triggered. */
1888 return -1;
1889 }
1890 else if (bs->breakpoint_at->type == bp_access_watchpoint ||
1891 bs->breakpoint_at->type == bp_read_watchpoint)
1892 {
1893 mention (bs->breakpoint_at);
1894 printf_filtered ("\nValue = ");
1895 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
c5aa993b 1896 Val_pretty_default);
c906108c
SS
1897 printf_filtered ("\n");
1898 return -1;
1899 }
53a5351d
JM
1900 /* We can't deal with it.
1901 Maybe another member of the bpstat chain can. */
c906108c
SS
1902 return -1;
1903}
1904
1905/* Print a message indicating what happened.
1906 This is called from normal_stop().
1907 The input to this routine is the head of the bpstat list - a list
1908 of the eventpoints that caused this stop.
1909 This routine calls the "print_it" routine(s) associated
1910 with these eventpoints. This will print (for example)
1911 the "Breakpoint n," part of the output.
1912 The return value of this routine is one of:
1913
1914 -1: Means we printed nothing
1915 0: Means we printed something, and expect subsequent
c5aa993b
JM
1916 code to print the location. An example is
1917 "Breakpoint 1, " which should be followed by
1918 the location.
c906108c 1919 1 : Means we printed something, but there is no need
c5aa993b
JM
1920 to also print the location part of the message.
1921 An example is the catch/throw messages, which
1922 don't require a location appended to the end. */
c906108c
SS
1923
1924int
1925bpstat_print (bs)
1926 bpstat bs;
1927{
1928 int val;
c5aa993b 1929
c906108c
SS
1930 if (bs == NULL)
1931 return -1;
1932
1933 val = (*bs->print_it) (bs);
1934 if (val >= 0)
1935 return val;
c5aa993b 1936
c906108c 1937 /* Maybe another breakpoint in the chain caused us to stop.
53a5351d
JM
1938 (Currently all watchpoints go on the bpstat whether hit or not.
1939 That probably could (should) be changed, provided care is taken
c906108c
SS
1940 with respect to bpstat_explains_signal). */
1941 if (bs->next)
1942 return bpstat_print (bs->next);
1943
1944 /* We reached the end of the chain without printing anything. */
1945 return -1;
1946}
1947
1948/* Evaluate the expression EXP and return 1 if value is zero.
1949 This is used inside a catch_errors to evaluate the breakpoint condition.
1950 The argument is a "struct expression *" that has been cast to char * to
1951 make it pass through catch_errors. */
1952
1953static int
1954breakpoint_cond_eval (exp)
1955 PTR exp;
1956{
1957 value_ptr mark = value_mark ();
c5aa993b 1958 int i = !value_true (evaluate_expression ((struct expression *) exp));
c906108c
SS
1959 value_free_to_mark (mark);
1960 return i;
1961}
1962
1963/* Allocate a new bpstat and chain it to the current one. */
1964
1965static bpstat
1966bpstat_alloc (b, cbs)
1967 register struct breakpoint *b;
c5aa993b 1968 bpstat cbs; /* Current "bs" value */
c906108c
SS
1969{
1970 bpstat bs;
1971
1972 bs = (bpstat) xmalloc (sizeof (*bs));
1973 cbs->next = bs;
1974 bs->breakpoint_at = b;
1975 /* If the condition is false, etc., don't do the commands. */
1976 bs->commands = NULL;
1977 bs->old_val = NULL;
1978 bs->print_it = print_it_normal;
1979 return bs;
1980}
1981\f
1982/* Possible return values for watchpoint_check (this can't be an enum
1983 because of check_errors). */
1984/* The watchpoint has been deleted. */
1985#define WP_DELETED 1
1986/* The value has changed. */
1987#define WP_VALUE_CHANGED 2
1988/* The value has not changed. */
1989#define WP_VALUE_NOT_CHANGED 3
1990
1991#define BP_TEMPFLAG 1
1992#define BP_HARDWAREFLAG 2
1993
1994/* Check watchpoint condition. */
1995
1996static int
1997watchpoint_check (p)
1998 PTR p;
1999{
2000 bpstat bs = (bpstat) p;
2001 struct breakpoint *b;
2002 struct frame_info *fr;
2003 int within_current_scope;
2004
2005 b = bs->breakpoint_at;
2006
2007 if (b->exp_valid_block == NULL)
2008 within_current_scope = 1;
2009 else
2010 {
2011 /* There is no current frame at this moment. If we're going to have
c5aa993b
JM
2012 any chance of handling watchpoints on local variables, we'll need
2013 the frame chain (so we can determine if we're in scope). */
2014 reinit_frame_cache ();
c906108c
SS
2015 fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
2016 within_current_scope = (fr != NULL);
2017 if (within_current_scope)
2018 /* If we end up stopping, the current frame will get selected
2019 in normal_stop. So this call to select_frame won't affect
2020 the user. */
2021 select_frame (fr, -1);
2022 }
c5aa993b 2023
c906108c
SS
2024 if (within_current_scope)
2025 {
2026 /* We use value_{,free_to_}mark because it could be a
2027 *long* time before we return to the command level and
c5aa993b
JM
2028 call free_all_values. We can't call free_all_values because
2029 we might be in the middle of evaluating a function call. */
c906108c
SS
2030
2031 value_ptr mark = value_mark ();
2032 value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
2033 if (!value_equal (b->val, new_val))
2034 {
2035 release_value (new_val);
2036 value_free_to_mark (mark);
2037 bs->old_val = b->val;
2038 b->val = new_val;
2039 /* We will stop here */
2040 return WP_VALUE_CHANGED;
2041 }
2042 else
2043 {
2044 /* Nothing changed, don't do anything. */
2045 value_free_to_mark (mark);
2046 /* We won't stop here */
2047 return WP_VALUE_NOT_CHANGED;
2048 }
2049 }
2050 else
2051 {
2052 /* This seems like the only logical thing to do because
c5aa993b
JM
2053 if we temporarily ignored the watchpoint, then when
2054 we reenter the block in which it is valid it contains
2055 garbage (in the case of a function, it may have two
2056 garbage values, one before and one after the prologue).
2057 So we can't even detect the first assignment to it and
2058 watch after that (since the garbage may or may not equal
2059 the first value assigned). */
c906108c
SS
2060 printf_filtered ("\
2061Watchpoint %d deleted because the program has left the block in\n\
2062which its expression is valid.\n", bs->breakpoint_at->number);
2063 if (b->related_breakpoint)
2064 b->related_breakpoint->disposition = del_at_next_stop;
2065 b->disposition = del_at_next_stop;
2066
2067 return WP_DELETED;
2068 }
2069}
2070
2071/* This is used when everything which needs to be printed has
2072 already been printed. But we still want to print the frame. */
2073
2074/* Background: When we stop, bpstat_print() is called.
2075 It loops through the bpstat list of things causing this stop,
2076 calling the print_it function for each one. The default
2077 print_it function, used for breakpoints, is print_it_normal().
2078 Also see print_it_noop() and print_it_done() are the other
2079 two possibilities. See comments in bpstat_print() and
2080 in header of print_it_normal() for more detail. */
2081
2082static int
2083print_it_done (bs)
2084 bpstat bs;
2085{
2086 return 0;
2087}
2088
2089/* This is used when nothing should be printed for this bpstat entry. */
2090/* Background: When we stop, bpstat_print() is called.
2091 It loops through the bpstat list of things causing this stop,
2092 calling the print_it function for each one. The default
2093 print_it function, used for breakpoints, is print_it_normal().
2094 Also see print_it_noop() and print_it_done() are the other
2095 two possibilities. See comments in bpstat_print() and
2096 in header of print_it_normal() for more detail. */
2097
2098static int
2099print_it_noop (bs)
2100 bpstat bs;
2101{
2102 return -1;
2103}
2104
2105/* Get a bpstat associated with having just stopped at address *PC
2106 and frame address CORE_ADDRESS. Update *PC to point at the
2107 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2108 if this is known to not be a real breakpoint (it could still be a
2109 watchpoint, though). */
2110
2111/* Determine whether we stopped at a breakpoint, etc, or whether we
2112 don't understand this stop. Result is a chain of bpstat's such that:
2113
c5aa993b 2114 if we don't understand the stop, the result is a null pointer.
c906108c 2115
c5aa993b 2116 if we understand why we stopped, the result is not null.
c906108c 2117
c5aa993b
JM
2118 Each element of the chain refers to a particular breakpoint or
2119 watchpoint at which we have stopped. (We may have stopped for
2120 several reasons concurrently.)
c906108c 2121
c5aa993b
JM
2122 Each element of the chain has valid next, breakpoint_at,
2123 commands, FIXME??? fields. */
c906108c
SS
2124
2125bpstat
2126bpstat_stop_status (pc, not_a_breakpoint)
2127 CORE_ADDR *pc;
2128 int not_a_breakpoint;
2129{
2130 register struct breakpoint *b, *temp;
2131 CORE_ADDR bp_addr;
2132 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2133 int real_breakpoint = 0;
2134 /* Root of the chain of bpstat's */
2135 struct bpstats root_bs[1];
2136 /* Pointer to the last thing in the chain currently. */
2137 bpstat bs = root_bs;
2138 static char message1[] =
c5aa993b
JM
2139 "Error evaluating expression for watchpoint %d\n";
2140 char message[sizeof (message1) + 30 /* slop */ ];
c906108c
SS
2141
2142 /* Get the address where the breakpoint would have been. */
2143 bp_addr = *pc - DECR_PC_AFTER_BREAK;
2144
2145 ALL_BREAKPOINTS_SAFE (b, temp)
c5aa993b
JM
2146 {
2147 if (b->enable == disabled
2148 || b->enable == shlib_disabled
2149 || b->enable == call_disabled)
2150 continue;
2151
2152 if (b->type != bp_watchpoint
2153 && b->type != bp_hardware_watchpoint
2154 && b->type != bp_read_watchpoint
2155 && b->type != bp_access_watchpoint
2156 && b->type != bp_hardware_breakpoint
2157 && b->type != bp_catch_fork
2158 && b->type != bp_catch_vfork
2159 && b->type != bp_catch_exec
2160 && b->type != bp_catch_catch
2161 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2162 if (b->address != bp_addr || /* address doesn't match or */
2163 (overlay_debugging && /* overlay doesn't match */
2164 section_is_overlay (b->section) &&
2165 !section_is_mapped (b->section)))
c906108c
SS
2166 continue;
2167
c5aa993b
JM
2168 if (b->type == bp_hardware_breakpoint
2169 && b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2170 continue;
2171
2172 if (b->type != bp_watchpoint
2173 && b->type != bp_hardware_watchpoint
2174 && b->type != bp_read_watchpoint
2175 && b->type != bp_access_watchpoint
2176 && not_a_breakpoint)
2177 continue;
2178
2179 /* Is this a catchpoint of a load or unload? If so, did we
2180 get a load or unload of the specified library? If not,
2181 ignore it. */
2182 if ((b->type == bp_catch_load)
c906108c 2183#if defined(SOLIB_HAVE_LOAD_EVENT)
c5aa993b
JM
2184 && (!SOLIB_HAVE_LOAD_EVENT (inferior_pid)
2185 || ((b->dll_pathname != NULL)
53a5351d
JM
2186 && (strcmp (b->dll_pathname,
2187 SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid))
2188 != 0)))
c906108c 2189#endif
c5aa993b
JM
2190 )
2191 continue;
2192
2193 if ((b->type == bp_catch_unload)
c906108c 2194#if defined(SOLIB_HAVE_UNLOAD_EVENT)
c5aa993b
JM
2195 && (!SOLIB_HAVE_UNLOAD_EVENT (inferior_pid)
2196 || ((b->dll_pathname != NULL)
53a5351d
JM
2197 && (strcmp (b->dll_pathname,
2198 SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid))
2199 != 0)))
c906108c 2200#endif
c5aa993b
JM
2201 )
2202 continue;
c906108c 2203
c5aa993b
JM
2204 if ((b->type == bp_catch_fork)
2205 && !target_has_forked (inferior_pid, &b->forked_inferior_pid))
2206 continue;
c906108c 2207
c5aa993b
JM
2208 if ((b->type == bp_catch_vfork)
2209 && !target_has_vforked (inferior_pid, &b->forked_inferior_pid))
2210 continue;
c906108c 2211
c5aa993b
JM
2212 if ((b->type == bp_catch_exec)
2213 && !target_has_execd (inferior_pid, &b->exec_pathname))
2214 continue;
c906108c 2215
c5aa993b
JM
2216 if (ep_is_exception_catchpoint (b) &&
2217 !(current_exception_event = target_get_current_exception_event ()))
2218 continue;
c906108c 2219
c5aa993b
JM
2220 /* Come here if it's a watchpoint, or if the break address matches */
2221
2222 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2223
2224 /* Watchpoints may change this, if not found to have triggered. */
2225 bs->stop = 1;
2226 bs->print = 1;
2227
2228 sprintf (message, message1, b->number);
53a5351d
JM
2229 if (b->type == bp_watchpoint ||
2230 b->type == bp_hardware_watchpoint)
c5aa993b 2231 {
53a5351d
JM
2232 switch (catch_errors (watchpoint_check, bs, message,
2233 RETURN_MASK_ALL))
c5aa993b
JM
2234 {
2235 case WP_DELETED:
2236 /* We've already printed what needs to be printed. */
2237 bs->print_it = print_it_done;
2238 /* Stop. */
2239 break;
2240 case WP_VALUE_CHANGED:
2241 /* Stop. */
2242 ++(b->hit_count);
2243 break;
2244 case WP_VALUE_NOT_CHANGED:
2245 /* Don't stop. */
2246 bs->print_it = print_it_noop;
2247 bs->stop = 0;
2248 /* Don't consider this a hit. */
2249 --(b->hit_count);
2250 continue;
2251 default:
2252 /* Can't happen. */
2253 /* FALLTHROUGH */
2254 case 0:
2255 /* Error from catch_errors. */
2256 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2257 if (b->related_breakpoint)
2258 b->related_breakpoint->disposition = del_at_next_stop;
2259 b->disposition = del_at_next_stop;
2260 /* We've already printed what needs to be printed. */
2261 bs->print_it = print_it_done;
2262
2263 /* Stop. */
2264 break;
2265 }
2266 }
53a5351d
JM
2267 else if (b->type == bp_read_watchpoint ||
2268 b->type == bp_access_watchpoint)
c5aa993b
JM
2269 {
2270 CORE_ADDR addr;
2271 value_ptr v;
2272 int found = 0;
2273
2274 addr = target_stopped_data_address ();
2275 if (addr == 0)
2276 continue;
2277 for (v = b->val_chain; v; v = v->next)
2278 {
2279 if (v->lval == lval_memory)
2280 {
2281 CORE_ADDR vaddr;
2282
2283 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
53a5351d
JM
2284 /* Exact match not required. Within range is sufficient.
2285 */
2286 if (addr >= vaddr &&
2287 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
c5aa993b
JM
2288 found = 1;
2289 }
2290 }
2291 if (found)
53a5351d
JM
2292 switch (catch_errors (watchpoint_check, bs, message,
2293 RETURN_MASK_ALL))
c906108c
SS
2294 {
2295 case WP_DELETED:
2296 /* We've already printed what needs to be printed. */
2297 bs->print_it = print_it_done;
2298 /* Stop. */
2299 break;
2300 case WP_VALUE_CHANGED:
c5aa993b 2301 case WP_VALUE_NOT_CHANGED:
c906108c
SS
2302 /* Stop. */
2303 ++(b->hit_count);
2304 break;
c906108c
SS
2305 default:
2306 /* Can't happen. */
c906108c
SS
2307 case 0:
2308 /* Error from catch_errors. */
2309 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2310 if (b->related_breakpoint)
2311 b->related_breakpoint->disposition = del_at_next_stop;
2312 b->disposition = del_at_next_stop;
2313 /* We've already printed what needs to be printed. */
2314 bs->print_it = print_it_done;
c906108c
SS
2315 break;
2316 }
53a5351d
JM
2317 else /* found == 0 */
2318 {
2319 /* This is a case where some watchpoint(s) triggered,
2320 but not at the address of this watchpoint (FOUND
2321 was left zero). So don't print anything for this
2322 watchpoint. */
2323 bs->print_it = print_it_noop;
2324 bs->stop = 0;
2325 continue;
2326 }
c5aa993b
JM
2327 }
2328 else
2329 {
2330 /* By definition, an encountered breakpoint is a triggered
2331 breakpoint. */
2332 ++(b->hit_count);
c906108c 2333
c5aa993b
JM
2334 real_breakpoint = 1;
2335 }
2336
2337 if (b->frame && b->frame != (get_current_frame ())->frame &&
2338 (b->type == bp_step_resume &&
2339 (INNER_THAN (get_current_frame ()->frame, b->frame))))
2340 bs->stop = 0;
2341 else
2342 {
2343 int value_is_zero = 0;
2344
2345 if (b->cond)
2346 {
2347 /* Need to select the frame, with all that implies
2348 so that the conditions will have the right context. */
2349 select_frame (get_current_frame (), 0);
2350 value_is_zero
2351 = catch_errors (breakpoint_cond_eval, (b->cond),
2352 "Error in testing breakpoint condition:\n",
2353 RETURN_MASK_ALL);
2354 /* FIXME-someday, should give breakpoint # */
2355 free_all_values ();
2356 }
2357 if (b->cond && value_is_zero)
2358 {
2359 bs->stop = 0;
2360 /* Don't consider this a hit. */
2361 --(b->hit_count);
2362 }
2363 else if (b->ignore_count > 0)
2364 {
2365 b->ignore_count--;
2366 bs->stop = 0;
2367 }
2368 else
2369 {
2370 /* We will stop here */
2371 if (b->disposition == disable)
2372 b->enable = disabled;
2373 bs->commands = b->commands;
2374 if (b->silent)
2375 bs->print = 0;
2376 if (bs->commands &&
2377 (STREQ ("silent", bs->commands->line) ||
2378 (xdb_commands && STREQ ("Q", bs->commands->line))))
2379 {
2380 bs->commands = bs->commands->next;
c906108c 2381 bs->print = 0;
c5aa993b
JM
2382 }
2383 }
2384 }
2385 /* Print nothing for this entry if we dont stop or if we dont print. */
2386 if (bs->stop == 0 || bs->print == 0)
2387 bs->print_it = print_it_noop;
2388 }
c906108c
SS
2389
2390 bs->next = NULL; /* Terminate the chain */
2391 bs = root_bs->next; /* Re-grab the head of the chain */
2392
2393 if (real_breakpoint && bs)
2394 {
c5aa993b 2395 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
c906108c 2396 {
c5aa993b 2397 if (DECR_PC_AFTER_HW_BREAK != 0)
c906108c
SS
2398 {
2399 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2400 write_pc (*pc);
2401 }
2402 }
2403 else
2404 {
2405 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2406 {
2407 *pc = bp_addr;
2408#if defined (SHIFT_INST_REGS)
c5aa993b 2409 SHIFT_INST_REGS ();
c906108c
SS
2410#else /* No SHIFT_INST_REGS. */
2411 write_pc (bp_addr);
2412#endif /* No SHIFT_INST_REGS. */
2413 }
2414 }
2415 }
2416
2417 /* The value of a hardware watchpoint hasn't changed, but the
2418 intermediate memory locations we are watching may have. */
c5aa993b 2419 if (bs && !bs->stop &&
c906108c
SS
2420 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2421 bs->breakpoint_at->type == bp_read_watchpoint ||
2422 bs->breakpoint_at->type == bp_access_watchpoint))
2423 {
2424 remove_breakpoints ();
2425 insert_breakpoints ();
2426 }
2427 return bs;
2428}
2429\f
2430/* Tell what to do about this bpstat. */
2431struct bpstat_what
2432bpstat_what (bs)
2433 bpstat bs;
2434{
2435 /* Classify each bpstat as one of the following. */
c5aa993b
JM
2436 enum class
2437 {
2438 /* This bpstat element has no effect on the main_action. */
2439 no_effect = 0,
2440
2441 /* There was a watchpoint, stop but don't print. */
2442 wp_silent,
c906108c 2443
c5aa993b
JM
2444 /* There was a watchpoint, stop and print. */
2445 wp_noisy,
c906108c 2446
c5aa993b
JM
2447 /* There was a breakpoint but we're not stopping. */
2448 bp_nostop,
c906108c 2449
c5aa993b
JM
2450 /* There was a breakpoint, stop but don't print. */
2451 bp_silent,
c906108c 2452
c5aa993b
JM
2453 /* There was a breakpoint, stop and print. */
2454 bp_noisy,
c906108c 2455
c5aa993b
JM
2456 /* We hit the longjmp breakpoint. */
2457 long_jump,
c906108c 2458
c5aa993b
JM
2459 /* We hit the longjmp_resume breakpoint. */
2460 long_resume,
c906108c 2461
c5aa993b
JM
2462 /* We hit the step_resume breakpoint. */
2463 step_resume,
c906108c 2464
c5aa993b
JM
2465 /* We hit the through_sigtramp breakpoint. */
2466 through_sig,
c906108c 2467
c5aa993b
JM
2468 /* We hit the shared library event breakpoint. */
2469 shlib_event,
c906108c 2470
c5aa993b
JM
2471 /* We caught a shared library event. */
2472 catch_shlib_event,
c906108c 2473
c5aa993b
JM
2474 /* This is just used to count how many enums there are. */
2475 class_last
c906108c
SS
2476 };
2477
2478 /* Here is the table which drives this routine. So that we can
2479 format it pretty, we define some abbreviations for the
2480 enum bpstat_what codes. */
2481#define kc BPSTAT_WHAT_KEEP_CHECKING
2482#define ss BPSTAT_WHAT_STOP_SILENT
2483#define sn BPSTAT_WHAT_STOP_NOISY
2484#define sgl BPSTAT_WHAT_SINGLE
2485#define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2486#define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2487#define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2488#define sr BPSTAT_WHAT_STEP_RESUME
2489#define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2490#define shl BPSTAT_WHAT_CHECK_SHLIBS
2491#define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2492
2493/* "Can't happen." Might want to print an error message.
2494 abort() is not out of the question, but chances are GDB is just
2495 a bit confused, not unusable. */
2496#define err BPSTAT_WHAT_STOP_NOISY
2497
2498 /* Given an old action and a class, come up with a new action. */
2499 /* One interesting property of this table is that wp_silent is the same
2500 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2501 after stopping, the check for whether to step over a breakpoint
2502 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
53a5351d
JM
2503 reference to how we stopped. We retain separate wp_silent and
2504 bp_silent codes in case we want to change that someday.
43ff13b4
JM
2505
2506 Another possibly interesting property of this table is that
2507 there's a partial ordering, priority-like, of the actions. Once
2508 you've decided that some action is appropriate, you'll never go
2509 back and decide something of a lower priority is better. The
2510 ordering is:
2511
c5aa993b
JM
2512 kc < clr sgl shl slr sn sr ss ts
2513 sgl < clrs shl shlr slr sn sr ss ts
2514 slr < err shl shlr sn sr ss ts
2515 clr < clrs err shl shlr sn sr ss ts
2516 clrs < err shl shlr sn sr ss ts
2517 ss < shl shlr sn sr ts
2518 sn < shl shlr sr ts
2519 sr < shl shlr ts
2520 shl < shlr
2521 ts <
2522 shlr <
2523
43ff13b4
JM
2524 What I think this means is that we don't need a damned table
2525 here. If you just put the rows and columns in the right order,
2526 it'd look awfully regular. We could simply walk the bpstat list
2527 and choose the highest priority action we find, with a little
2528 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2529 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2530 is messy anyway). */
c906108c
SS
2531
2532 /* step_resume entries: a step resume breakpoint overrides another
2533 breakpoint of signal handling (see comment in wait_for_inferior
2534 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2535 /* We handle the through_sigtramp_breakpoint the same way; having both
2536 one of those and a step_resume_breakpoint is probably very rare (?). */
2537
2538 static const enum bpstat_what_main_action
c5aa993b
JM
2539 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2540 {
2541 /* old action */
2542 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2543 */
2544/*no_effect */
2545 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2546/*wp_silent */
2547 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2548/*wp_noisy */
2549 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2550/*bp_nostop */
2551 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2552/*bp_silent */
2553 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2554/*bp_noisy */
2555 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2556/*long_jump */
2557 {slr, ss, sn, slr, err, err, err, sr, ts, shl, shlr},
2558/*long_resume */
2559 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2560/*step_resume */
2561 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2562/*through_sig */
2563 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2564/*shlib */
2565 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2566/*catch_shlib */
2567 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2568 };
c906108c
SS
2569
2570#undef kc
2571#undef ss
2572#undef sn
2573#undef sgl
2574#undef slr
2575#undef clr
2576#undef clrs
2577#undef err
2578#undef sr
2579#undef ts
2580#undef shl
2581#undef shlr
2582 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2583 struct bpstat_what retval;
2584
2585 retval.call_dummy = 0;
2586 for (; bs != NULL; bs = bs->next)
2587 {
2588 enum class bs_class = no_effect;
2589 if (bs->breakpoint_at == NULL)
2590 /* I suspect this can happen if it was a momentary breakpoint
2591 which has since been deleted. */
2592 continue;
2593 switch (bs->breakpoint_at->type)
2594 {
2595 case bp_none:
2596 continue;
2597
2598 case bp_breakpoint:
2599 case bp_hardware_breakpoint:
2600 case bp_until:
2601 case bp_finish:
2602 if (bs->stop)
2603 {
2604 if (bs->print)
2605 bs_class = bp_noisy;
2606 else
2607 bs_class = bp_silent;
2608 }
2609 else
2610 bs_class = bp_nostop;
2611 break;
2612 case bp_watchpoint:
2613 case bp_hardware_watchpoint:
2614 case bp_read_watchpoint:
2615 case bp_access_watchpoint:
2616 if (bs->stop)
2617 {
2618 if (bs->print)
2619 bs_class = wp_noisy;
2620 else
2621 bs_class = wp_silent;
2622 }
2623 else
53a5351d
JM
2624 /* There was a watchpoint, but we're not stopping.
2625 This requires no further action. */
c906108c
SS
2626 bs_class = no_effect;
2627 break;
2628 case bp_longjmp:
2629 bs_class = long_jump;
2630 break;
2631 case bp_longjmp_resume:
2632 bs_class = long_resume;
2633 break;
2634 case bp_step_resume:
2635 if (bs->stop)
2636 {
2637 bs_class = step_resume;
2638 }
2639 else
2640 /* It is for the wrong frame. */
2641 bs_class = bp_nostop;
2642 break;
2643 case bp_through_sigtramp:
2644 bs_class = through_sig;
2645 break;
2646 case bp_watchpoint_scope:
2647 bs_class = bp_nostop;
2648 break;
c5aa993b
JM
2649 case bp_shlib_event:
2650 bs_class = shlib_event;
2651 break;
2652 case bp_catch_load:
2653 case bp_catch_unload:
2654 /* Only if this catchpoint triggered should we cause the
2655 step-out-of-dld behaviour. Otherwise, we ignore this
2656 catchpoint. */
2657 if (bs->stop)
2658 bs_class = catch_shlib_event;
2659 else
2660 bs_class = no_effect;
2661 break;
2662 case bp_catch_fork:
2663 case bp_catch_vfork:
2664 case bp_catch_exec:
2665 if (bs->stop)
2666 {
2667 if (bs->print)
2668 bs_class = bp_noisy;
2669 else
2670 bs_class = bp_silent;
2671 }
2672 else
53a5351d
JM
2673 /* There was a catchpoint, but we're not stopping.
2674 This requires no further action. */
c5aa993b
JM
2675 bs_class = no_effect;
2676 break;
2677 case bp_catch_catch:
2678 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
2679 bs_class = bp_nostop;
2680 else if (bs->stop)
2681 bs_class = bs->print ? bp_noisy : bp_silent;
2682 break;
2683 case bp_catch_throw:
2684 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
2685 bs_class = bp_nostop;
2686 else if (bs->stop)
2687 bs_class = bs->print ? bp_noisy : bp_silent;
c906108c 2688 break;
c906108c 2689 case bp_call_dummy:
53a5351d
JM
2690 /* Make sure the action is stop (silent or noisy),
2691 so infrun.c pops the dummy frame. */
c906108c
SS
2692 bs_class = bp_silent;
2693 retval.call_dummy = 1;
2694 break;
2695 }
c5aa993b 2696 current_action = table[(int) bs_class][(int) current_action];
c906108c
SS
2697 }
2698 retval.main_action = current_action;
2699 return retval;
2700}
2701
2702/* Nonzero if we should step constantly (e.g. watchpoints on machines
2703 without hardware support). This isn't related to a specific bpstat,
2704 just to things like whether watchpoints are set. */
2705
c5aa993b 2706int
c906108c
SS
2707bpstat_should_step ()
2708{
2709 struct breakpoint *b;
2710 ALL_BREAKPOINTS (b)
2711 if (b->enable == enabled && b->type == bp_watchpoint)
c5aa993b 2712 return 1;
c906108c
SS
2713 return 0;
2714}
2715
2716/* Nonzero if there are enabled hardware watchpoints. */
2717int
2718bpstat_have_active_hw_watchpoints ()
2719{
2720 struct breakpoint *b;
2721 ALL_BREAKPOINTS (b)
2722 if ((b->enable == enabled) &&
c5aa993b
JM
2723 (b->inserted) &&
2724 ((b->type == bp_hardware_watchpoint) ||
2725 (b->type == bp_read_watchpoint) ||
2726 (b->type == bp_access_watchpoint)))
2727 return 1;
c906108c
SS
2728 return 0;
2729}
c906108c 2730\f
c5aa993b 2731
c906108c
SS
2732/* Given a bpstat that records zero or more triggered eventpoints, this
2733 function returns another bpstat which contains only the catchpoints
2734 on that first list, if any. */
2735void
2736bpstat_get_triggered_catchpoints (ep_list, cp_list)
c5aa993b
JM
2737 bpstat ep_list;
2738 bpstat *cp_list;
2739{
2740 struct bpstats root_bs[1];
2741 bpstat bs = root_bs;
2742 struct breakpoint *ep;
2743 char *dll_pathname;
2744
c906108c
SS
2745 bpstat_clear (cp_list);
2746 root_bs->next = NULL;
c5aa993b
JM
2747
2748 for (; ep_list != NULL; ep_list = ep_list->next)
c906108c
SS
2749 {
2750 /* Is this eventpoint a catchpoint? If not, ignore it. */
2751 ep = ep_list->breakpoint_at;
2752 if (ep == NULL)
c5aa993b
JM
2753 break;
2754 if ((ep->type != bp_catch_load) &&
2755 (ep->type != bp_catch_unload) &&
2756 (ep->type != bp_catch_catch) &&
53a5351d
JM
2757 (ep->type != bp_catch_throw))
2758 /* pai: (temp) ADD fork/vfork here!! */
c5aa993b
JM
2759 continue;
2760
c906108c
SS
2761 /* Yes; add it to the list. */
2762 bs = bpstat_alloc (ep, bs);
2763 *bs = *ep_list;
2764 bs->next = NULL;
2765 bs = root_bs->next;
c5aa993b 2766
c906108c
SS
2767#if defined(SOLIB_ADD)
2768 /* Also, for each triggered catchpoint, tag it with the name of
2769 the library that caused this trigger. (We copy the name now,
2770 because it's only guaranteed to be available NOW, when the
2771 catchpoint triggers. Clients who may wish to know the name
2772 later must get it from the catchpoint itself.) */
2773 if (ep->triggered_dll_pathname != NULL)
c5aa993b 2774 free (ep->triggered_dll_pathname);
c906108c 2775 if (ep->type == bp_catch_load)
c5aa993b 2776 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid);
c906108c 2777 else
c5aa993b 2778 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid);
c906108c
SS
2779#else
2780 dll_pathname = NULL;
2781#endif
2782 if (dll_pathname)
2783 {
53a5351d
JM
2784 ep->triggered_dll_pathname = (char *)
2785 xmalloc (strlen (dll_pathname) + 1);
c906108c
SS
2786 strcpy (ep->triggered_dll_pathname, dll_pathname);
2787 }
2788 else
2789 ep->triggered_dll_pathname = NULL;
2790 }
c5aa993b 2791
c906108c
SS
2792 *cp_list = bs;
2793}
2794
2795/* Print information on breakpoint number BNUM, or -1 if all.
2796 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
2797 is nonzero, process only watchpoints. */
2798
c5aa993b
JM
2799typedef struct
2800{
2801 enum bptype type;
2802 char *description;
2803}
2804ep_type_description_t;
c906108c
SS
2805
2806static void
2807breakpoint_1 (bnum, allflag)
2808 int bnum;
2809 int allflag;
2810{
2811 register struct breakpoint *b;
2812 register struct command_line *l;
2813 register struct symbol *sym;
c5aa993b 2814 CORE_ADDR last_addr = (CORE_ADDR) - 1;
c906108c 2815 int found_a_breakpoint = 0;
c5aa993b 2816 static ep_type_description_t bptypes[] =
c906108c 2817 {
c5aa993b
JM
2818 {bp_none, "?deleted?"},
2819 {bp_breakpoint, "breakpoint"},
c906108c 2820 {bp_hardware_breakpoint, "hw breakpoint"},
c5aa993b
JM
2821 {bp_until, "until"},
2822 {bp_finish, "finish"},
2823 {bp_watchpoint, "watchpoint"},
c906108c 2824 {bp_hardware_watchpoint, "hw watchpoint"},
c5aa993b
JM
2825 {bp_read_watchpoint, "read watchpoint"},
2826 {bp_access_watchpoint, "acc watchpoint"},
2827 {bp_longjmp, "longjmp"},
2828 {bp_longjmp_resume, "longjmp resume"},
2829 {bp_step_resume, "step resume"},
2830 {bp_through_sigtramp, "sigtramp"},
2831 {bp_watchpoint_scope, "watchpoint scope"},
2832 {bp_call_dummy, "call dummy"},
2833 {bp_shlib_event, "shlib events"},
2834 {bp_catch_load, "catch load"},
2835 {bp_catch_unload, "catch unload"},
2836 {bp_catch_fork, "catch fork"},
2837 {bp_catch_vfork, "catch vfork"},
2838 {bp_catch_exec, "catch exec"},
2839 {bp_catch_catch, "catch catch"},
2840 {bp_catch_throw, "catch throw"}
2841 };
2842
2843 static char *bpdisps[] =
2844 {"del", "dstp", "dis", "keep"};
c906108c
SS
2845 static char bpenables[] = "nyn";
2846 char wrap_indent[80];
2847
392a587b 2848
53a5351d 2849
c906108c
SS
2850 ALL_BREAKPOINTS (b)
2851 if (bnum == -1
2852 || bnum == b->number)
c5aa993b 2853 {
c906108c 2854/* We only print out user settable breakpoints unless the allflag is set. */
c5aa993b
JM
2855 if (!allflag
2856 && b->type != bp_breakpoint
2857 && b->type != bp_catch_load
2858 && b->type != bp_catch_unload
2859 && b->type != bp_catch_fork
2860 && b->type != bp_catch_vfork
2861 && b->type != bp_catch_exec
2862 && b->type != bp_catch_catch
2863 && b->type != bp_catch_throw
2864 && b->type != bp_hardware_breakpoint
2865 && b->type != bp_watchpoint
2866 && b->type != bp_read_watchpoint
2867 && b->type != bp_access_watchpoint
2868 && b->type != bp_hardware_watchpoint)
2869 continue;
c906108c 2870
c5aa993b
JM
2871 if (!found_a_breakpoint++)
2872 {
2873 annotate_breakpoints_headers ();
2874
2875 annotate_field (0);
2876 printf_filtered ("Num ");
2877 annotate_field (1);
2878 printf_filtered ("Type ");
2879 annotate_field (2);
2880 printf_filtered ("Disp ");
2881 annotate_field (3);
2882 printf_filtered ("Enb ");
2883 if (addressprint)
2884 {
2885 annotate_field (4);
2886 printf_filtered ("Address ");
2887 }
2888 annotate_field (5);
2889 printf_filtered ("What\n");
c906108c 2890
c5aa993b
JM
2891 annotate_breakpoints_table ();
2892 }
c906108c 2893
c5aa993b
JM
2894 annotate_record ();
2895 annotate_field (0);
2896 printf_filtered ("%-3d ", b->number);
2897 annotate_field (1);
2898 if ((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
2899 error ("bptypes table does not describe type #%d.", (int) b->type);
2900 if ((int) b->type != bptypes[(int) b->type].type)
2901 error ("bptypes table does not describe type #%d?", (int) b->type);
2902 printf_filtered ("%-14s ", bptypes[(int) b->type].description);
2903 annotate_field (2);
2904 printf_filtered ("%-4s ", bpdisps[(int) b->disposition]);
2905 annotate_field (3);
2906 printf_filtered ("%-3c ", bpenables[(int) b->enable]);
2907
2908 strcpy (wrap_indent, " ");
2909 if (addressprint)
2910 strcat (wrap_indent, " ");
2911 switch (b->type)
2912 {
2913 case bp_watchpoint:
2914 case bp_hardware_watchpoint:
2915 case bp_read_watchpoint:
2916 case bp_access_watchpoint:
2917 /* Field 4, the address, is omitted (which makes the columns
2918 not line up too nicely with the headers, but the effect
2919 is relatively readable). */
2920 annotate_field (5);
2921 print_expression (b->exp, gdb_stdout);
2922 break;
c906108c 2923
c5aa993b
JM
2924 case bp_catch_load:
2925 case bp_catch_unload:
2926 /* Field 4, the address, is omitted (which makes the columns
2927 not line up too nicely with the headers, but the effect
2928 is relatively readable). */
2929 annotate_field (5);
2930 if (b->dll_pathname == NULL)
2931 printf_filtered ("<any library> ");
2932 else
2933 printf_filtered ("library \"%s\" ", b->dll_pathname);
2934 break;
c906108c 2935
c5aa993b
JM
2936 case bp_catch_fork:
2937 case bp_catch_vfork:
2938 /* Field 4, the address, is omitted (which makes the columns
2939 not line up too nicely with the headers, but the effect
2940 is relatively readable). */
2941 annotate_field (5);
2942 if (b->forked_inferior_pid != 0)
2943 printf_filtered ("process %d ", b->forked_inferior_pid);
2944 break;
c906108c 2945
c5aa993b
JM
2946 case bp_catch_exec:
2947 /* Field 4, the address, is omitted (which makes the columns
2948 not line up too nicely with the headers, but the effect
2949 is relatively readable). */
2950 annotate_field (5);
2951 if (b->exec_pathname != NULL)
2952 printf_filtered ("program \"%s\" ", b->exec_pathname);
2953 break;
2954 case bp_catch_catch:
2955 /* Field 4, the address, is omitted (which makes the columns
2956 not line up too nicely with the headers, but the effect
2957 is relatively readable). */
2958 annotate_field (5);
2959 printf_filtered ("exception catch ");
2960 break;
2961 case bp_catch_throw:
2962 /* Field 4, the address, is omitted (which makes the columns
2963 not line up too nicely with the headers, but the effect
2964 is relatively readable). */
2965 annotate_field (5);
2966 printf_filtered ("exception throw ");
2967 break;
c906108c 2968
c5aa993b
JM
2969 case bp_breakpoint:
2970 case bp_hardware_breakpoint:
2971 case bp_until:
2972 case bp_finish:
2973 case bp_longjmp:
2974 case bp_longjmp_resume:
2975 case bp_step_resume:
2976 case bp_through_sigtramp:
2977 case bp_watchpoint_scope:
2978 case bp_call_dummy:
2979 case bp_shlib_event:
2980 if (addressprint)
2981 {
2982 annotate_field (4);
2983 /* FIXME-32x64: need a print_address_numeric with
2984 field width */
2985 printf_filtered
2986 ("%s ",
2987 local_hex_string_custom
2988 ((unsigned long) b->address, "08l"));
2989 }
c906108c 2990
c5aa993b 2991 annotate_field (5);
c906108c 2992
c5aa993b
JM
2993 last_addr = b->address;
2994 if (b->source_file)
2995 {
2996 sym = find_pc_sect_function (b->address, b->section);
2997 if (sym)
2998 {
2999 fputs_filtered ("in ", gdb_stdout);
3000 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
3001 wrap_here (wrap_indent);
3002 fputs_filtered (" at ", gdb_stdout);
3003 }
3004 fputs_filtered (b->source_file, gdb_stdout);
3005 printf_filtered (":%d", b->line_number);
3006 }
3007 else
3008 print_address_symbolic (b->address, gdb_stdout, demangle, " ");
3009 break;
3010 }
c906108c 3011
c5aa993b
JM
3012 if (b->thread != -1)
3013 printf_filtered (" thread %d", b->thread);
c906108c 3014
c5aa993b 3015 printf_filtered ("\n");
c906108c 3016
c5aa993b
JM
3017 if (b->frame)
3018 {
3019 annotate_field (6);
c906108c 3020
c5aa993b
JM
3021 printf_filtered ("\tstop only in stack frame at ");
3022 print_address_numeric (b->frame, 1, gdb_stdout);
3023 printf_filtered ("\n");
3024 }
c906108c 3025
c5aa993b
JM
3026 if (b->cond)
3027 {
3028 annotate_field (7);
c906108c 3029
c5aa993b
JM
3030 printf_filtered ("\tstop only if ");
3031 print_expression (b->cond, gdb_stdout);
3032 printf_filtered ("\n");
3033 }
3034
3035 if (b->thread != -1)
3036 {
3037 /* FIXME should make an annotation for this */
3038 printf_filtered ("\tstop only in thread %d\n", b->thread);
3039 }
3040
3041 if (show_breakpoint_hit_counts && b->hit_count)
3042 {
3043 /* FIXME should make an annotation for this */
3044 if (ep_is_catchpoint (b))
3045 printf_filtered ("\tcatchpoint");
3046 else
3047 printf_filtered ("\tbreakpoint");
3048 printf_filtered (" already hit %d time%s\n",
3049 b->hit_count, (b->hit_count == 1 ? "" : "s"));
3050 }
3051
3052 if (b->ignore_count)
3053 {
3054 annotate_field (8);
3055
3056 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
3057 }
3058
3059 if ((l = b->commands))
3060 {
3061 annotate_field (9);
3062
3063 while (l)
3064 {
3065 print_command_line (l, 4, gdb_stdout);
3066 l = l->next;
3067 }
3068 }
3069 }
c906108c
SS
3070
3071 if (!found_a_breakpoint)
3072 {
3073 if (bnum == -1)
c5aa993b 3074 printf_filtered ("No breakpoints or watchpoints.\n");
c906108c 3075 else
c5aa993b 3076 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
c906108c
SS
3077 }
3078 else
3079 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3080 that a comparison of an unsigned with -1 is always false. */
c5aa993b
JM
3081 if (last_addr != (CORE_ADDR) - 1)
3082 set_next_address (last_addr);
c906108c
SS
3083
3084 annotate_breakpoints_table_end ();
3085}
3086
3087/* ARGSUSED */
3088static void
3089breakpoints_info (bnum_exp, from_tty)
3090 char *bnum_exp;
3091 int from_tty;
3092{
3093 int bnum = -1;
3094
3095 if (bnum_exp)
3096 bnum = parse_and_eval_address (bnum_exp);
3097
3098 breakpoint_1 (bnum, 0);
3099}
3100
c906108c 3101/* ARGSUSED */
7a292a7a 3102static void
c906108c
SS
3103maintenance_info_breakpoints (bnum_exp, from_tty)
3104 char *bnum_exp;
3105 int from_tty;
3106{
3107 int bnum = -1;
3108
3109 if (bnum_exp)
3110 bnum = parse_and_eval_address (bnum_exp);
3111
3112 breakpoint_1 (bnum, 1);
3113}
3114
c906108c
SS
3115/* Print a message describing any breakpoints set at PC. */
3116
3117static void
3118describe_other_breakpoints (pc, section)
3119 CORE_ADDR pc;
3120 asection *section;
3121{
3122 register int others = 0;
3123 register struct breakpoint *b;
3124
3125 ALL_BREAKPOINTS (b)
3126 if (b->address == pc)
c5aa993b
JM
3127 if (overlay_debugging == 0 ||
3128 b->section == section)
3129 others++;
c906108c
SS
3130 if (others > 0)
3131 {
3132 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3133 ALL_BREAKPOINTS (b)
3134 if (b->address == pc)
c5aa993b
JM
3135 if (overlay_debugging == 0 ||
3136 b->section == section)
3137 {
3138 others--;
3139 printf_filtered
3140 ("%d%s%s ",
3141 b->number,
53a5351d
JM
3142 ((b->enable == disabled ||
3143 b->enable == shlib_disabled ||
3144 b->enable == call_disabled)
c5aa993b
JM
3145 ? " (disabled)" : ""),
3146 (others > 1) ? "," : ((others == 1) ? " and" : ""));
3147 }
c906108c
SS
3148 printf_filtered ("also set at pc ");
3149 print_address_numeric (pc, 1, gdb_stdout);
3150 printf_filtered (".\n");
3151 }
3152}
3153\f
3154/* Set the default place to put a breakpoint
3155 for the `break' command with no arguments. */
3156
3157void
3158set_default_breakpoint (valid, addr, symtab, line)
3159 int valid;
3160 CORE_ADDR addr;
3161 struct symtab *symtab;
3162 int line;
3163{
3164 default_breakpoint_valid = valid;
3165 default_breakpoint_address = addr;
3166 default_breakpoint_symtab = symtab;
3167 default_breakpoint_line = line;
3168}
3169
3170/* Rescan breakpoints at address ADDRESS,
3171 marking the first one as "first" and any others as "duplicates".
3172 This is so that the bpt instruction is only inserted once. */
3173
3174static void
3175check_duplicates (address, section)
3176 CORE_ADDR address;
3177 asection *section;
3178{
3179 register struct breakpoint *b;
3180 register int count = 0;
3181
3182 if (address == 0) /* Watchpoints are uninteresting */
3183 return;
3184
3185 ALL_BREAKPOINTS (b)
3186 if (b->enable != disabled
3187 && b->enable != shlib_disabled
3188 && b->enable != call_disabled
3189 && b->address == address
3190 && (overlay_debugging == 0 || b->section == section))
c5aa993b
JM
3191 {
3192 count++;
3193 b->duplicate = count > 1;
3194 }
c906108c
SS
3195}
3196
3197/* Low level routine to set a breakpoint.
3198 Takes as args the three things that every breakpoint must have.
3199 Returns the breakpoint object so caller can set other things.
3200 Does not set the breakpoint number!
3201 Does not print anything.
3202
3203 ==> This routine should not be called if there is a chance of later
3204 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
3205 your arguments BEFORE calling this routine! */
3206
3207struct breakpoint *
3208set_raw_breakpoint (sal)
3209 struct symtab_and_line sal;
3210{
3211 register struct breakpoint *b, *b1;
3212
3213 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3214 memset (b, 0, sizeof (*b));
3215 b->address = sal.pc;
3216 if (sal.symtab == NULL)
3217 b->source_file = NULL;
3218 else
3219 b->source_file = savestring (sal.symtab->filename,
3220 strlen (sal.symtab->filename));
3221 b->section = sal.section;
3222 b->language = current_language->la_language;
3223 b->input_radix = input_radix;
3224 b->thread = -1;
3225 b->line_number = sal.line;
3226 b->enable = enabled;
3227 b->next = 0;
3228 b->silent = 0;
3229 b->ignore_count = 0;
3230 b->commands = NULL;
3231 b->frame = 0;
3232 b->dll_pathname = NULL;
3233 b->triggered_dll_pathname = NULL;
3234 b->forked_inferior_pid = 0;
3235 b->exec_pathname = NULL;
3236
3237 /* Add this breakpoint to the end of the chain
3238 so that a list of breakpoints will come out in order
3239 of increasing numbers. */
3240
3241 b1 = breakpoint_chain;
3242 if (b1 == 0)
3243 breakpoint_chain = b;
3244 else
3245 {
3246 while (b1->next)
3247 b1 = b1->next;
3248 b1->next = b;
3249 }
3250
3251 check_duplicates (sal.pc, sal.section);
3252 breakpoints_changed ();
3253
3254 return b;
3255}
3256
3257#ifdef GET_LONGJMP_TARGET
3258
3259static void
3260create_longjmp_breakpoint (func_name)
3261 char *func_name;
3262{
3263 struct symtab_and_line sal;
3264 struct breakpoint *b;
3265
c5aa993b 3266 INIT_SAL (&sal); /* initialize to zeroes */
c906108c
SS
3267 if (func_name != NULL)
3268 {
3269 struct minimal_symbol *m;
3270
53a5351d
JM
3271 m = lookup_minimal_symbol_text (func_name, NULL,
3272 (struct objfile *) NULL);
c906108c
SS
3273 if (m)
3274 sal.pc = SYMBOL_VALUE_ADDRESS (m);
3275 else
3276 return;
3277 }
3278 sal.section = find_pc_overlay (sal.pc);
3279 b = set_raw_breakpoint (sal);
c5aa993b
JM
3280 if (!b)
3281 return;
c906108c
SS
3282
3283 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
3284 b->disposition = donttouch;
3285 b->enable = disabled;
3286 b->silent = 1;
3287 if (func_name)
c5aa993b 3288 b->addr_string = strsave (func_name);
c906108c
SS
3289 b->number = internal_breakpoint_number--;
3290}
3291
c5aa993b 3292#endif /* #ifdef GET_LONGJMP_TARGET */
c906108c 3293
53a5351d
JM
3294/* Call this routine when stepping and nexting to enable a breakpoint
3295 if we do a longjmp(). When we hit that breakpoint, call
c906108c
SS
3296 set_longjmp_resume_breakpoint() to figure out where we are going. */
3297
3298void
c5aa993b 3299enable_longjmp_breakpoint ()
c906108c
SS
3300{
3301 register struct breakpoint *b;
3302
3303 ALL_BREAKPOINTS (b)
3304 if (b->type == bp_longjmp)
c5aa993b
JM
3305 {
3306 b->enable = enabled;
3307 check_duplicates (b->address, b->section);
3308 }
c906108c
SS
3309}
3310
3311void
c5aa993b 3312disable_longjmp_breakpoint ()
c906108c
SS
3313{
3314 register struct breakpoint *b;
3315
3316 ALL_BREAKPOINTS (b)
c5aa993b 3317 if (b->type == bp_longjmp
c906108c 3318 || b->type == bp_longjmp_resume)
c5aa993b
JM
3319 {
3320 b->enable = disabled;
3321 check_duplicates (b->address, b->section);
3322 }
c906108c
SS
3323}
3324
3325#ifdef SOLIB_ADD
3326void
3327remove_solib_event_breakpoints ()
3328{
3329 register struct breakpoint *b, *temp;
3330
3331 ALL_BREAKPOINTS_SAFE (b, temp)
3332 if (b->type == bp_shlib_event)
c5aa993b 3333 delete_breakpoint (b);
c906108c
SS
3334}
3335
3336void
3337create_solib_event_breakpoint (address)
3338 CORE_ADDR address;
3339{
3340 struct breakpoint *b;
3341 struct symtab_and_line sal;
3342
c5aa993b 3343 INIT_SAL (&sal); /* initialize to zeroes */
c906108c
SS
3344 sal.pc = address;
3345 sal.section = find_pc_overlay (sal.pc);
3346 b = set_raw_breakpoint (sal);
3347 b->number = internal_breakpoint_number--;
3348 b->disposition = donttouch;
3349 b->type = bp_shlib_event;
3350}
3351
104c1213
JM
3352/* Disable any breakpoints that are on code in shared libraries. Only
3353 apply to enabled breakpoints, disabled ones can just stay disabled. */
3354
c906108c
SS
3355void
3356disable_breakpoints_in_shlibs (silent)
3357 int silent;
3358{
c5aa993b
JM
3359 struct breakpoint *b;
3360 int disabled_shlib_breaks = 0;
c906108c
SS
3361
3362 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
3363 ALL_BREAKPOINTS (b)
c5aa993b 3364 {
c906108c 3365#if defined (PC_SOLIB)
c5aa993b
JM
3366 if (((b->type == bp_breakpoint) ||
3367 (b->type == bp_hardware_breakpoint)) &&
104c1213 3368 b->enable == enabled &&
c5aa993b
JM
3369 !b->duplicate &&
3370 PC_SOLIB (b->address))
3371 {
3372 b->enable = shlib_disabled;
3373 if (!silent)
3374 {
3375 if (!disabled_shlib_breaks)
3376 {
3377 target_terminal_ours_for_output ();
53a5351d 3378 warning ("Temporarily disabling shared library breakpoints:");
c5aa993b
JM
3379 }
3380 disabled_shlib_breaks = 1;
53a5351d 3381 warning ("breakpoint #%d ", b->number);
c5aa993b
JM
3382 }
3383 }
c906108c 3384#endif
c5aa993b 3385 }
c906108c
SS
3386}
3387
3388/* Try to reenable any breakpoints in shared libraries. */
3389void
3390re_enable_breakpoints_in_shlibs ()
3391{
3392 struct breakpoint *b;
3393
3394 ALL_BREAKPOINTS (b)
3395 if (b->enable == shlib_disabled)
c5aa993b
JM
3396 {
3397 char buf[1];
c906108c 3398
c5aa993b
JM
3399 /* Do not reenable the breakpoint if the shared library
3400 is still not mapped in. */
3401 if (target_read_memory (b->address, buf, 1) == 0)
3402 b->enable = enabled;
3403 }
c906108c
SS
3404}
3405
3406#endif
3407
3408static void
53a5351d 3409solib_load_unload_1 (hookname, tempflag, dll_pathname, cond_string, bp_kind)
7a292a7a
SS
3410 char *hookname;
3411 int tempflag;
3412 char *dll_pathname;
3413 char *cond_string;
3414 enum bptype bp_kind;
c906108c 3415{
c5aa993b 3416 struct breakpoint *b;
c906108c 3417 struct symtabs_and_lines sals;
c5aa993b
JM
3418 struct cleanup *old_chain;
3419 struct cleanup *canonical_strings_chain = NULL;
c5aa993b
JM
3420 char *addr_start = hookname;
3421 char *addr_end = NULL;
3422 char **canonical = (char **) NULL;
3423 int thread = -1; /* All threads. */
3424
c906108c
SS
3425 /* Set a breakpoint on the specified hook. */
3426 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
3427 addr_end = hookname;
c5aa993b 3428
c906108c
SS
3429 if (sals.nelts == 0)
3430 {
3431 warning ("Unable to set a breakpoint on dynamic linker callback.");
3432 warning ("Suggest linking with /opt/langtools/lib/end.o.");
3433 warning ("GDB will be unable to track shl_load/shl_unload calls");
3434 return;
3435 }
3436 if (sals.nelts != 1)
3437 {
53a5351d 3438 warning ("Unable to set unique breakpoint on dynamic linker callback.");
c906108c
SS
3439 warning ("GDB will be unable to track shl_load/shl_unload calls");
3440 return;
3441 }
3442
53a5351d
JM
3443 /* Make sure that all storage allocated in decode_line_1 gets freed
3444 in case the following errors out. */
c906108c 3445 old_chain = make_cleanup (free, sals.sals);
c5aa993b 3446 if (canonical != (char **) NULL)
c906108c
SS
3447 {
3448 make_cleanup (free, canonical);
3449 canonical_strings_chain = make_cleanup (null_cleanup, 0);
3450 if (canonical[0] != NULL)
c5aa993b 3451 make_cleanup (free, canonical[0]);
c906108c 3452 }
c5aa993b 3453
c906108c 3454 resolve_sal_pc (&sals.sals[0]);
c5aa993b 3455
c906108c 3456 /* Remove the canonical strings from the cleanup, they are needed below. */
c5aa993b 3457 if (canonical != (char **) NULL)
c906108c 3458 discard_cleanups (canonical_strings_chain);
c5aa993b 3459
c906108c
SS
3460 b = set_raw_breakpoint (sals.sals[0]);
3461 set_breakpoint_count (breakpoint_count + 1);
3462 b->number = breakpoint_count;
3463 b->cond = NULL;
53a5351d
JM
3464 b->cond_string = (cond_string == NULL) ?
3465 NULL : savestring (cond_string, strlen (cond_string));
c906108c 3466 b->thread = thread;
c5aa993b
JM
3467
3468 if (canonical != (char **) NULL && canonical[0] != NULL)
c906108c
SS
3469 b->addr_string = canonical[0];
3470 else if (addr_start)
3471 b->addr_string = savestring (addr_start, addr_end - addr_start);
c5aa993b 3472
c906108c
SS
3473 b->enable = enabled;
3474 b->disposition = tempflag ? del : donttouch;
c5aa993b 3475
c906108c
SS
3476 if (dll_pathname == NULL)
3477 b->dll_pathname = NULL;
3478 else
3479 {
3480 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
3481 strcpy (b->dll_pathname, dll_pathname);
3482 }
3483 b->type = bp_kind;
c5aa993b 3484
c906108c
SS
3485 mention (b);
3486 do_cleanups (old_chain);
3487}
3488
3489void
53a5351d
JM
3490create_solib_load_event_breakpoint (hookname, tempflag,
3491 dll_pathname, cond_string)
c5aa993b
JM
3492 char *hookname;
3493 int tempflag;
3494 char *dll_pathname;
3495 char *cond_string;
c906108c 3496{
53a5351d
JM
3497 solib_load_unload_1 (hookname, tempflag, dll_pathname,
3498 cond_string, bp_catch_load);
c906108c
SS
3499}
3500
3501void
53a5351d
JM
3502create_solib_unload_event_breakpoint (hookname, tempflag,
3503 dll_pathname, cond_string)
c5aa993b
JM
3504 char *hookname;
3505 int tempflag;
3506 char *dll_pathname;
3507 char *cond_string;
c906108c 3508{
53a5351d
JM
3509 solib_load_unload_1 (hookname,tempflag, dll_pathname,
3510 cond_string, bp_catch_unload);
c906108c
SS
3511}
3512
3513static void
3514create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_kind)
7a292a7a
SS
3515 int tempflag;
3516 char *cond_string;
3517 enum bptype bp_kind;
c906108c 3518{
c5aa993b
JM
3519 struct symtab_and_line sal;
3520 struct breakpoint *b;
3521 int thread = -1; /* All threads. */
3522
3523 INIT_SAL (&sal);
c906108c
SS
3524 sal.pc = 0;
3525 sal.symtab = NULL;
3526 sal.line = 0;
c5aa993b 3527
c906108c
SS
3528 b = set_raw_breakpoint (sal);
3529 set_breakpoint_count (breakpoint_count + 1);
3530 b->number = breakpoint_count;
3531 b->cond = NULL;
53a5351d
JM
3532 b->cond_string = (cond_string == NULL) ?
3533 NULL : savestring (cond_string, strlen (cond_string));
c906108c
SS
3534 b->thread = thread;
3535 b->addr_string = NULL;
3536 b->enable = enabled;
3537 b->disposition = tempflag ? del : donttouch;
3538 b->forked_inferior_pid = 0;
c5aa993b 3539
c906108c 3540 b->type = bp_kind;
c5aa993b 3541
c906108c
SS
3542 mention (b);
3543}
3544
3545void
3546create_fork_event_catchpoint (tempflag, cond_string)
c5aa993b
JM
3547 int tempflag;
3548 char *cond_string;
c906108c
SS
3549{
3550 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
3551}
c5aa993b 3552
c906108c
SS
3553void
3554create_vfork_event_catchpoint (tempflag, cond_string)
c5aa993b
JM
3555 int tempflag;
3556 char *cond_string;
c906108c
SS
3557{
3558 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
3559}
3560
3561void
3562create_exec_event_catchpoint (tempflag, cond_string)
c5aa993b
JM
3563 int tempflag;
3564 char *cond_string;
c906108c 3565{
c5aa993b
JM
3566 struct symtab_and_line sal;
3567 struct breakpoint *b;
3568 int thread = -1; /* All threads. */
c906108c 3569
c5aa993b 3570 INIT_SAL (&sal);
c906108c
SS
3571 sal.pc = 0;
3572 sal.symtab = NULL;
3573 sal.line = 0;
3574
3575 b = set_raw_breakpoint (sal);
3576 set_breakpoint_count (breakpoint_count + 1);
3577 b->number = breakpoint_count;
3578 b->cond = NULL;
53a5351d
JM
3579 b->cond_string = (cond_string == NULL) ?
3580 NULL : savestring (cond_string, strlen (cond_string));
c906108c
SS
3581 b->thread = thread;
3582 b->addr_string = NULL;
3583 b->enable = enabled;
3584 b->disposition = tempflag ? del : donttouch;
3585
3586 b->type = bp_catch_exec;
3587
3588 mention (b);
3589}
3590
3591static int
c5aa993b 3592hw_breakpoint_used_count ()
c906108c
SS
3593{
3594 register struct breakpoint *b;
3595 int i = 0;
3596
3597 ALL_BREAKPOINTS (b)
c5aa993b
JM
3598 {
3599 if (b->type == bp_hardware_breakpoint && b->enable == enabled)
3600 i++;
3601 }
c906108c
SS
3602
3603 return i;
3604}
3605
3606static int
c5aa993b
JM
3607hw_watchpoint_used_count (type, other_type_used)
3608 enum bptype type;
3609 int *other_type_used;
c906108c
SS
3610{
3611 register struct breakpoint *b;
3612 int i = 0;
3613
3614 *other_type_used = 0;
3615 ALL_BREAKPOINTS (b)
c5aa993b
JM
3616 {
3617 if (b->enable == enabled)
3618 {
3619 if (b->type == type)
3620 i++;
3621 else if ((b->type == bp_hardware_watchpoint ||
3622 b->type == bp_read_watchpoint ||
3623 b->type == bp_access_watchpoint)
3624 && b->enable == enabled)
3625 *other_type_used = 1;
3626 }
3627 }
c906108c
SS
3628 return i;
3629}
3630
53a5351d
JM
3631/* Call this after hitting the longjmp() breakpoint. Use this to set
3632 a new breakpoint at the target of the jmp_buf.
c906108c 3633
53a5351d
JM
3634 FIXME - This ought to be done by setting a temporary breakpoint
3635 that gets deleted automatically... */
c906108c
SS
3636
3637void
c5aa993b 3638set_longjmp_resume_breakpoint (pc, frame)
c906108c
SS
3639 CORE_ADDR pc;
3640 struct frame_info *frame;
3641{
3642 register struct breakpoint *b;
3643
3644 ALL_BREAKPOINTS (b)
3645 if (b->type == bp_longjmp_resume)
c5aa993b
JM
3646 {
3647 b->address = pc;
3648 b->enable = enabled;
3649 if (frame != NULL)
3650 b->frame = frame->frame;
3651 else
3652 b->frame = 0;
3653 check_duplicates (b->address, b->section);
3654 return;
3655 }
c906108c
SS
3656}
3657
3658void
3659disable_watchpoints_before_interactive_call_start ()
3660{
c5aa993b 3661 struct breakpoint *b;
c906108c
SS
3662
3663 ALL_BREAKPOINTS (b)
c5aa993b
JM
3664 {
3665 if (((b->type == bp_watchpoint)
3666 || (b->type == bp_hardware_watchpoint)
3667 || (b->type == bp_read_watchpoint)
3668 || (b->type == bp_access_watchpoint)
3669 || ep_is_exception_catchpoint (b))
3670 && (b->enable == enabled))
3671 {
3672 b->enable = call_disabled;
3673 check_duplicates (b->address, b->section);
3674 }
3675 }
c906108c
SS
3676}
3677
3678void
3679enable_watchpoints_after_interactive_call_stop ()
3680{
c5aa993b 3681 struct breakpoint *b;
c906108c
SS
3682
3683 ALL_BREAKPOINTS (b)
c5aa993b
JM
3684 {
3685 if (((b->type == bp_watchpoint)
3686 || (b->type == bp_hardware_watchpoint)
3687 || (b->type == bp_read_watchpoint)
3688 || (b->type == bp_access_watchpoint)
3689 || ep_is_exception_catchpoint (b))
3690 && (b->enable == call_disabled))
3691 {
3692 b->enable = enabled;
3693 check_duplicates (b->address, b->section);
3694 }
3695 }
c906108c
SS
3696}
3697
3698
3699/* Set a breakpoint that will evaporate an end of command
3700 at address specified by SAL.
3701 Restrict it to frame FRAME if FRAME is nonzero. */
3702
3703struct breakpoint *
3704set_momentary_breakpoint (sal, frame, type)
3705 struct symtab_and_line sal;
3706 struct frame_info *frame;
3707 enum bptype type;
3708{
3709 register struct breakpoint *b;
3710 b = set_raw_breakpoint (sal);
3711 b->type = type;
3712 b->enable = enabled;
3713 b->disposition = donttouch;
3714 b->frame = (frame ? frame->frame : 0);
3715
3716 /* If we're debugging a multi-threaded program, then we
3717 want momentary breakpoints to be active in only a
3718 single thread of control. */
3719 if (in_thread_list (inferior_pid))
3720 b->thread = pid_to_thread_id (inferior_pid);
3721
3722 return b;
3723}
c906108c 3724\f
c5aa993b 3725
c906108c
SS
3726/* Tell the user we have just set a breakpoint B. */
3727
3728static void
3729mention (b)
3730 struct breakpoint *b;
3731{
3732 int say_where = 0;
3733
3734 /* FIXME: This is misplaced; mention() is called by things (like hitting a
3735 watchpoint) other than breakpoint creation. It should be possible to
3736 clean this up and at the same time replace the random calls to
3737 breakpoint_changed with this hook, as has already been done for
3738 delete_breakpoint_hook and so on. */
3739 if (create_breakpoint_hook)
3740 create_breakpoint_hook (b);
104c1213 3741 breakpoint_create_event (b->number);
c906108c
SS
3742
3743 switch (b->type)
3744 {
3745 case bp_none:
3746 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
3747 break;
3748 case bp_watchpoint:
3749 printf_filtered ("Watchpoint %d: ", b->number);
3750 print_expression (b->exp, gdb_stdout);
3751 break;
3752 case bp_hardware_watchpoint:
3753 printf_filtered ("Hardware watchpoint %d: ", b->number);
3754 print_expression (b->exp, gdb_stdout);
3755 break;
3756 case bp_read_watchpoint:
3757 printf_filtered ("Hardware read watchpoint %d: ", b->number);
3758 print_expression (b->exp, gdb_stdout);
3759 break;
3760 case bp_access_watchpoint:
53a5351d
JM
3761 printf_filtered ("Hardware access (read/write) watchpoint %d: ",
3762 b->number);
c906108c
SS
3763 print_expression (b->exp, gdb_stdout);
3764 break;
3765 case bp_breakpoint:
3766 printf_filtered ("Breakpoint %d", b->number);
3767 say_where = 1;
3768 break;
3769 case bp_hardware_breakpoint:
3770 printf_filtered ("Hardware assisted breakpoint %d", b->number);
3771 say_where = 1;
3772 break;
3773 case bp_catch_load:
3774 case bp_catch_unload:
3775 printf_filtered ("Catchpoint %d (%s %s)",
c5aa993b
JM
3776 b->number,
3777 (b->type == bp_catch_load) ? "load" : "unload",
53a5351d
JM
3778 (b->dll_pathname != NULL) ?
3779 b->dll_pathname : "<any library>");
c906108c
SS
3780 break;
3781 case bp_catch_fork:
3782 case bp_catch_vfork:
3783 printf_filtered ("Catchpoint %d (%s)",
c5aa993b
JM
3784 b->number,
3785 (b->type == bp_catch_fork) ? "fork" : "vfork");
c906108c
SS
3786 break;
3787 case bp_catch_exec:
3788 printf_filtered ("Catchpoint %d (exec)",
c5aa993b 3789 b->number);
c906108c
SS
3790 break;
3791 case bp_catch_catch:
3792 case bp_catch_throw:
3793 printf_filtered ("Catchpoint %d (%s)",
c5aa993b
JM
3794 b->number,
3795 (b->type == bp_catch_catch) ? "catch" : "throw");
c906108c
SS
3796 break;
3797
3798 case bp_until:
3799 case bp_finish:
3800 case bp_longjmp:
3801 case bp_longjmp_resume:
3802 case bp_step_resume:
3803 case bp_through_sigtramp:
3804 case bp_call_dummy:
3805 case bp_watchpoint_scope:
3806 case bp_shlib_event:
3807 break;
3808 }
3809 if (say_where)
3810 {
3811 if (addressprint || b->source_file == NULL)
3812 {
3813 printf_filtered (" at ");
3814 print_address_numeric (b->address, 1, gdb_stdout);
3815 }
3816 if (b->source_file)
3817 printf_filtered (": file %s, line %d.",
3818 b->source_file, b->line_number);
c5aa993b
JM
3819 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, b, 1));
3820 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
c906108c
SS
3821 }
3822 printf_filtered ("\n");
3823}
c906108c 3824\f
c5aa993b 3825
c906108c
SS
3826/* Set a breakpoint according to ARG (function, linenum or *address)
3827 flag: first bit : 0 non-temporary, 1 temporary.
c5aa993b 3828 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
c906108c
SS
3829
3830static void
3831break_command_1 (arg, flag, from_tty)
3832 char *arg;
3833 int flag, from_tty;
3834{
3835 int tempflag, hardwareflag;
3836 struct symtabs_and_lines sals;
3837 struct symtab_and_line sal;
3838 register struct expression *cond = 0;
3839 register struct breakpoint *b;
3840
3841 /* Pointers in arg to the start, and one past the end, of the condition. */
3842 char *cond_start = NULL;
3843 char *cond_end = NULL;
3844 /* Pointers in arg to the start, and one past the end,
3845 of the address part. */
3846 char *addr_start = NULL;
3847 char *addr_end = NULL;
3848 struct cleanup *old_chain;
3849 struct cleanup *canonical_strings_chain = NULL;
c5aa993b 3850 char **canonical = (char **) NULL;
c906108c
SS
3851 int i;
3852 int thread;
3853
3854 hardwareflag = flag & BP_HARDWAREFLAG;
3855 tempflag = flag & BP_TEMPFLAG;
3856
3857 sals.sals = NULL;
3858 sals.nelts = 0;
3859
c5aa993b 3860 INIT_SAL (&sal); /* initialize to zeroes */
c906108c
SS
3861
3862 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
3863
c5aa993b 3864 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
c906108c
SS
3865 && (arg[2] == ' ' || arg[2] == '\t')))
3866 {
3867 if (default_breakpoint_valid)
3868 {
c5aa993b 3869 sals.sals = (struct symtab_and_line *)
c906108c
SS
3870 xmalloc (sizeof (struct symtab_and_line));
3871 sal.pc = default_breakpoint_address;
3872 sal.line = default_breakpoint_line;
3873 sal.symtab = default_breakpoint_symtab;
c5aa993b 3874 sal.section = find_pc_overlay (sal.pc);
c906108c
SS
3875 sals.sals[0] = sal;
3876 sals.nelts = 1;
3877 }
3878 else
3879 error ("No default breakpoint address now.");
3880 }
3881 else
3882 {
3883 addr_start = arg;
3884
3885 /* Force almost all breakpoints to be in terms of the
c5aa993b
JM
3886 current_source_symtab (which is decode_line_1's default). This
3887 should produce the results we want almost all of the time while
3888 leaving default_breakpoint_* alone. */
c906108c
SS
3889 if (default_breakpoint_valid
3890 && (!current_source_symtab
3891 || (arg && (*arg == '+' || *arg == '-'))))
3892 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
3893 default_breakpoint_line, &canonical);
3894 else
c5aa993b 3895 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, &canonical);
c906108c
SS
3896
3897 addr_end = arg;
3898 }
c5aa993b
JM
3899
3900 if (!sals.nelts)
c906108c
SS
3901 return;
3902
53a5351d
JM
3903 /* Make sure that all storage allocated in decode_line_1 gets freed
3904 in case the following `for' loop errors out. */
c906108c 3905 old_chain = make_cleanup (free, sals.sals);
c5aa993b 3906 if (canonical != (char **) NULL)
c906108c
SS
3907 {
3908 make_cleanup (free, canonical);
3909 canonical_strings_chain = make_cleanup (null_cleanup, 0);
3910 for (i = 0; i < sals.nelts; i++)
3911 {
3912 if (canonical[i] != NULL)
3913 make_cleanup (free, canonical[i]);
3914 }
3915 }
3916
3917 thread = -1; /* No specific thread yet */
3918
3919 /* Resolve all line numbers to PC's, and verify that conditions
3920 can be parsed, before setting any breakpoints. */
3921 for (i = 0; i < sals.nelts; i++)
3922 {
3923 char *tok, *end_tok;
3924 int toklen;
3925
3926 resolve_sal_pc (&sals.sals[i]);
3927
3928 /* It's possible for the PC to be nonzero, but still an illegal
3929 value on some targets.
3930
3931 For example, on HP-UX if you start gdb, and before running the
3932 inferior you try to set a breakpoint on a shared library function
3933 "foo" where the inferior doesn't call "foo" directly but does
3934 pass its address to another function call, then we do find a
3935 minimal symbol for the "foo", but it's address is invalid.
3936 (Appears to be an index into a table that the loader sets up
3937 when the inferior is run.)
3938
3939 Give the target a chance to bless sals.sals[i].pc before we
3940 try to make a breakpoint for it. */
c5aa993b
JM
3941 if (PC_REQUIRES_RUN_BEFORE_USE (sals.sals[i].pc))
3942 {
53a5351d
JM
3943 error ("Cannot break on %s without a running program.",
3944 addr_start);
c5aa993b
JM
3945 }
3946
c906108c
SS
3947 tok = arg;
3948
3949 while (tok && *tok)
3950 {
3951 while (*tok == ' ' || *tok == '\t')
3952 tok++;
3953
3954 end_tok = tok;
3955
3956 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
3957 end_tok++;
3958
3959 toklen = end_tok - tok;
3960
3961 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
3962 {
3963 tok = cond_start = end_tok + 1;
3964 cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
3965 cond_end = tok;
3966 }
3967 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
3968 {
3969 char *tmptok;
3970
3971 tok = end_tok + 1;
3972 tmptok = tok;
3973 thread = strtol (tok, &tok, 0);
3974 if (tok == tmptok)
3975 error ("Junk after thread keyword.");
3976 if (!valid_thread_id (thread))
3977 error ("Unknown thread %d\n", thread);
3978 }
3979 else
3980 error ("Junk at end of arguments.");
3981 }
3982 }
3983 if (hardwareflag)
3984 {
3985 int i, target_resources_ok;
3986
c5aa993b 3987 i = hw_breakpoint_used_count ();
53a5351d
JM
3988 target_resources_ok =
3989 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
3990 i + sals.nelts, 0);
c906108c
SS
3991 if (target_resources_ok == 0)
3992 error ("No hardware breakpoint support in the target.");
3993 else if (target_resources_ok < 0)
c5aa993b 3994 error ("Hardware breakpoints used exceeds limit.");
c906108c
SS
3995 }
3996
3997 /* Remove the canonical strings from the cleanup, they are needed below. */
c5aa993b 3998 if (canonical != (char **) NULL)
c906108c
SS
3999 discard_cleanups (canonical_strings_chain);
4000
4001 /* Now set all the breakpoints. */
4002 for (i = 0; i < sals.nelts; i++)
4003 {
4004 sal = sals.sals[i];
4005
4006 if (from_tty)
4007 describe_other_breakpoints (sal.pc, sal.section);
4008
4009 b = set_raw_breakpoint (sal);
4010 set_breakpoint_count (breakpoint_count + 1);
4011 b->number = breakpoint_count;
4012 b->type = hardwareflag ? bp_hardware_breakpoint : bp_breakpoint;
4013 b->cond = cond;
4014 b->thread = thread;
4015
4016 /* If a canonical line spec is needed use that instead of the
c5aa993b
JM
4017 command string. */
4018 if (canonical != (char **) NULL && canonical[i] != NULL)
c906108c
SS
4019 b->addr_string = canonical[i];
4020 else if (addr_start)
4021 b->addr_string = savestring (addr_start, addr_end - addr_start);
4022 if (cond_start)
4023 b->cond_string = savestring (cond_start, cond_end - cond_start);
c5aa993b 4024
c906108c
SS
4025 b->enable = enabled;
4026 b->disposition = tempflag ? del : donttouch;
4027 mention (b);
4028 }
4029
4030 if (sals.nelts > 1)
4031 {
53a5351d
JM
4032 warning ("Multiple breakpoints were set.");
4033 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
c906108c
SS
4034 }
4035 do_cleanups (old_chain);
4036}
4037
4038static void
4039break_at_finish_at_depth_command_1 (arg, flag, from_tty)
4040 char *arg;
4041 int flag;
4042 int from_tty;
4043{
4044 struct frame_info *frame;
4045 CORE_ADDR low, high, selected_pc = 0;
4046 char *extra_args, *level_arg, *addr_string;
4047 int extra_args_len = 0, if_arg = 0;
4048
4049 if (!arg ||
4050 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4051 {
4052
4053 if (default_breakpoint_valid)
4054 {
4055 if (selected_frame)
4056 {
4057 selected_pc = selected_frame->pc;
4058 if (arg)
4059 if_arg = 1;
4060 }
4061 else
4062 error ("No selected frame.");
4063 }
4064 else
4065 error ("No default breakpoint address now.");
4066 }
4067 else
4068 {
4069 extra_args = strchr (arg, ' ');
4070 if (extra_args)
4071 {
4072 extra_args++;
4073 extra_args_len = strlen (extra_args);
4074 level_arg = (char *) xmalloc (extra_args - arg);
4075 strncpy (level_arg, arg, extra_args - arg - 1);
4076 level_arg[extra_args - arg - 1] = '\0';
4077 }
4078 else
4079 {
4080 level_arg = (char *) xmalloc (strlen (arg) + 1);
4081 strcpy (level_arg, arg);
4082 }
4083
4084 frame = parse_frame_specification (level_arg);
4085 if (frame)
4086 selected_pc = frame->pc;
4087 else
4088 selected_pc = 0;
4089 }
4090 if (if_arg)
4091 {
4092 extra_args = arg;
c5aa993b 4093 extra_args_len = strlen (arg);
c906108c
SS
4094 }
4095
4096 if (selected_pc)
4097 {
c5aa993b 4098 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
c906108c
SS
4099 {
4100 addr_string = (char *) xmalloc (26 + extra_args_len);
4101 if (extra_args_len)
d4f3574e 4102 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
c906108c 4103 else
d4f3574e 4104 sprintf (addr_string, "*0x%s", paddr_nz (high));
c906108c
SS
4105 break_command_1 (addr_string, flag, from_tty);
4106 free (addr_string);
4107 }
4108 else
4109 error ("No function contains the specified address");
4110 }
4111 else
4112 error ("Unable to set breakpoint at procedure exit");
4113}
4114
4115
4116static void
4117break_at_finish_command_1 (arg, flag, from_tty)
4118 char *arg;
4119 int flag;
4120 int from_tty;
4121{
4122 char *addr_string, *break_string, *beg_addr_string;
4123 CORE_ADDR low, high;
4124 struct symtabs_and_lines sals;
4125 struct symtab_and_line sal;
4126 struct cleanup *old_chain;
4127 char *extra_args;
4128 int extra_args_len = 0;
4129 int i, if_arg = 0;
4130
4131 if (!arg ||
4132 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4133 {
4134 if (default_breakpoint_valid)
4135 {
4136 if (selected_frame)
4137 {
4138 addr_string = (char *) xmalloc (15);
d4f3574e 4139 sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
c906108c
SS
4140 if (arg)
4141 if_arg = 1;
4142 }
4143 else
4144 error ("No selected frame.");
4145 }
4146 else
4147 error ("No default breakpoint address now.");
4148 }
4149 else
4150 {
4151 addr_string = (char *) xmalloc (strlen (arg) + 1);
4152 strcpy (addr_string, arg);
4153 }
4154
4155 if (if_arg)
4156 {
4157 extra_args = arg;
c5aa993b
JM
4158 extra_args_len = strlen (arg);
4159 }
4160 else if (arg)
4161 {
4162 /* get the stuff after the function name or address */
4163 extra_args = strchr (arg, ' ');
4164 if (extra_args)
4165 {
4166 extra_args++;
4167 extra_args_len = strlen (extra_args);
4168 }
c906108c 4169 }
c906108c
SS
4170
4171 sals.sals = NULL;
4172 sals.nelts = 0;
4173
c5aa993b
JM
4174 beg_addr_string = addr_string;
4175 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
4176 (char ***) NULL);
c906108c
SS
4177
4178 free (beg_addr_string);
4179 old_chain = make_cleanup (free, sals.sals);
4180 for (i = 0; (i < sals.nelts); i++)
4181 {
4182 sal = sals.sals[i];
c5aa993b 4183 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
c906108c
SS
4184 {
4185 break_string = (char *) xmalloc (extra_args_len + 26);
4186 if (extra_args_len)
d4f3574e 4187 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
c906108c 4188 else
d4f3574e 4189 sprintf (break_string, "*0x%s", paddr_nz (high));
c906108c 4190 break_command_1 (break_string, flag, from_tty);
c5aa993b 4191 free (break_string);
c906108c
SS
4192 }
4193 else
4194 error ("No function contains the specified address");
4195 }
4196 if (sals.nelts > 1)
4197 {
53a5351d
JM
4198 warning ("Multiple breakpoints were set.\n");
4199 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
c906108c 4200 }
c5aa993b 4201 do_cleanups (old_chain);
c906108c
SS
4202}
4203
4204
4205/* Helper function for break_command_1 and disassemble_command. */
4206
4207void
4208resolve_sal_pc (sal)
4209 struct symtab_and_line *sal;
4210{
4211 CORE_ADDR pc;
4212
4213 if (sal->pc == 0 && sal->symtab != NULL)
4214 {
4215 if (!find_line_pc (sal->symtab, sal->line, &pc))
4216 error ("No line %d in file \"%s\".",
4217 sal->line, sal->symtab->filename);
4218 sal->pc = pc;
4219 }
4220
4221 if (sal->section == 0 && sal->symtab != NULL)
4222 {
4223 struct blockvector *bv;
c5aa993b
JM
4224 struct block *b;
4225 struct symbol *sym;
4226 int index;
c906108c 4227
c5aa993b 4228 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
c906108c
SS
4229 if (bv != NULL)
4230 {
c5aa993b 4231 b = BLOCKVECTOR_BLOCK (bv, index);
c906108c
SS
4232 sym = block_function (b);
4233 if (sym != NULL)
4234 {
4235 fixup_symbol_section (sym, sal->symtab->objfile);
4236 sal->section = SYMBOL_BFD_SECTION (sym);
4237 }
4238 else
4239 {
4240 /* It really is worthwhile to have the section, so we'll just
c5aa993b
JM
4241 have to look harder. This case can be executed if we have
4242 line numbers but no functions (as can happen in assembly
4243 source). */
c906108c 4244
c5aa993b 4245 struct minimal_symbol *msym;
c906108c
SS
4246
4247 msym = lookup_minimal_symbol_by_pc (sal->pc);
4248 if (msym)
4249 sal->section = SYMBOL_BFD_SECTION (msym);
4250 }
4251 }
4252 }
4253}
4254
4255void
4256break_command (arg, from_tty)
4257 char *arg;
4258 int from_tty;
4259{
4260 break_command_1 (arg, 0, from_tty);
4261}
4262
7a292a7a 4263static void
c906108c
SS
4264break_at_finish_command (arg, from_tty)
4265 char *arg;
4266 int from_tty;
4267{
4268 break_at_finish_command_1 (arg, 0, from_tty);
4269}
4270
7a292a7a 4271static void
c906108c
SS
4272break_at_finish_at_depth_command (arg, from_tty)
4273 char *arg;
4274 int from_tty;
4275{
4276 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
4277}
4278
4279void
4280tbreak_command (arg, from_tty)
4281 char *arg;
4282 int from_tty;
4283{
4284 break_command_1 (arg, BP_TEMPFLAG, from_tty);
4285}
4286
7a292a7a 4287static void
c906108c
SS
4288tbreak_at_finish_command (arg, from_tty)
4289 char *arg;
4290 int from_tty;
4291{
4292 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
4293}
4294
4295static void
4296hbreak_command (arg, from_tty)
4297 char *arg;
4298 int from_tty;
4299{
4300 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
4301}
4302
4303static void
4304thbreak_command (arg, from_tty)
4305 char *arg;
4306 int from_tty;
4307{
4308 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
4309}
4310
4311static void
4312stop_command (arg, from_tty)
4313 char *arg;
4314 int from_tty;
4315{
4316 printf_filtered ("Specify the type of breakpoint to set.\n\
4317Usage: stop in <function | address>\n\
4318 stop at <line>\n");
4319}
4320
4321static void
4322stopin_command (arg, from_tty)
4323 char *arg;
4324 int from_tty;
4325{
4326 int badInput = 0;
4327
c5aa993b 4328 if (arg == (char *) NULL)
c906108c
SS
4329 badInput = 1;
4330 else if (*arg != '*')
4331 {
4332 char *argptr = arg;
4333 int hasColon = 0;
4334
53a5351d
JM
4335 /* look for a ':'. If this is a line number specification, then
4336 say it is bad, otherwise, it should be an address or
4337 function/method name */
c906108c 4338 while (*argptr && !hasColon)
c5aa993b
JM
4339 {
4340 hasColon = (*argptr == ':');
4341 argptr++;
4342 }
c906108c
SS
4343
4344 if (hasColon)
c5aa993b 4345 badInput = (*argptr != ':'); /* Not a class::method */
c906108c 4346 else
c5aa993b 4347 badInput = isdigit (*arg); /* a simple line number */
c906108c
SS
4348 }
4349
4350 if (badInput)
c5aa993b 4351 printf_filtered ("Usage: stop in <function | address>\n");
c906108c
SS
4352 else
4353 break_command_1 (arg, 0, from_tty);
4354}
4355
4356static void
4357stopat_command (arg, from_tty)
4358 char *arg;
4359 int from_tty;
4360{
4361 int badInput = 0;
4362
c5aa993b 4363 if (arg == (char *) NULL || *arg == '*') /* no line number */
c906108c
SS
4364 badInput = 1;
4365 else
4366 {
4367 char *argptr = arg;
4368 int hasColon = 0;
4369
4370 /* look for a ':'. If there is a '::' then get out, otherwise
c5aa993b 4371 it is probably a line number. */
c906108c 4372 while (*argptr && !hasColon)
c5aa993b
JM
4373 {
4374 hasColon = (*argptr == ':');
4375 argptr++;
4376 }
c906108c
SS
4377
4378 if (hasColon)
c5aa993b 4379 badInput = (*argptr == ':'); /* we have class::method */
c906108c 4380 else
c5aa993b 4381 badInput = !isdigit (*arg); /* not a line number */
c906108c
SS
4382 }
4383
4384 if (badInput)
c5aa993b 4385 printf_filtered ("Usage: stop at <line>\n");
c906108c
SS
4386 else
4387 break_command_1 (arg, 0, from_tty);
4388}
4389
4390/* ARGSUSED */
53a5351d
JM
4391/* accessflag: hw_write: watch write,
4392 hw_read: watch read,
4393 hw_access: watch access (read or write) */
c906108c
SS
4394static void
4395watch_command_1 (arg, accessflag, from_tty)
4396 char *arg;
4397 int accessflag;
4398 int from_tty;
4399{
4400 struct breakpoint *b;
4401 struct symtab_and_line sal;
4402 struct expression *exp;
4403 struct block *exp_valid_block;
4404 struct value *val, *mark;
4405 struct frame_info *frame;
4406 struct frame_info *prev_frame = NULL;
4407 char *exp_start = NULL;
4408 char *exp_end = NULL;
4409 char *tok, *end_tok;
4410 int toklen;
4411 char *cond_start = NULL;
4412 char *cond_end = NULL;
4413 struct expression *cond = NULL;
4414 int i, other_type_used, target_resources_ok = 0;
4415 enum bptype bp_type;
4416 int mem_cnt = 0;
4417
c5aa993b
JM
4418 INIT_SAL (&sal); /* initialize to zeroes */
4419
c906108c
SS
4420 /* Parse arguments. */
4421 innermost_block = NULL;
4422 exp_start = arg;
4423 exp = parse_exp_1 (&arg, 0, 0);
4424 exp_end = arg;
4425 exp_valid_block = innermost_block;
4426 mark = value_mark ();
4427 val = evaluate_expression (exp);
4428 release_value (val);
4429 if (VALUE_LAZY (val))
4430 value_fetch_lazy (val);
4431
4432 tok = arg;
4433 while (*tok == ' ' || *tok == '\t')
4434 tok++;
4435 end_tok = tok;
4436
4437 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4438 end_tok++;
4439
4440 toklen = end_tok - tok;
4441 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4442 {
4443 tok = cond_start = end_tok + 1;
4444 cond = parse_exp_1 (&tok, 0, 0);
4445 cond_end = tok;
4446 }
4447 if (*tok)
c5aa993b 4448 error ("Junk at end of command.");
c906108c 4449
53a5351d 4450 if (accessflag == hw_read)
c5aa993b 4451 bp_type = bp_read_watchpoint;
53a5351d 4452 else if (accessflag == hw_access)
c5aa993b
JM
4453 bp_type = bp_access_watchpoint;
4454 else
4455 bp_type = bp_hardware_watchpoint;
c906108c
SS
4456
4457 mem_cnt = can_use_hardware_watchpoint (val);
4458 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
4459 error ("Expression cannot be implemented with read/access watchpoint.");
c5aa993b
JM
4460 if (mem_cnt != 0)
4461 {
4462 i = hw_watchpoint_used_count (bp_type, &other_type_used);
53a5351d
JM
4463 target_resources_ok =
4464 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
4465 other_type_used);
c5aa993b 4466 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
53a5351d
JM
4467 error ("Target does not support this type of hardware watchpoint.");
4468
c5aa993b 4469 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
53a5351d 4470 error ("Target can only support one kind of HW watchpoint at a time.");
c5aa993b 4471 }
c906108c
SS
4472
4473#if defined(HPUXHPPA)
c5aa993b 4474 /* On HP-UX if you set a h/w
c906108c
SS
4475 watchpoint before the "run" command, the inferior dies with a e.g.,
4476 SIGILL once you start it. I initially believed this was due to a
4477 bad interaction between page protection traps and the initial
4478 startup sequence by the dynamic linker.
4479
4480 However, I tried avoiding that by having HP-UX's implementation of
4481 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_pid
4482 yet, which forced slow watches before a "run" or "attach", and it
4483 still fails somewhere in the startup code.
4484
4485 Until I figure out what's happening, I'm disallowing watches altogether
4486 before the "run" or "attach" command. We'll tell the user they must
4487 set watches after getting the program started. */
c5aa993b 4488 if (!target_has_execution)
c906108c
SS
4489 {
4490 warning ("can't do that without a running program; try \"break main\", \"run\" first");
4491 return;
4492 }
4493#endif /* HPUXHPPA */
c5aa993b 4494
c906108c
SS
4495 /* Now set up the breakpoint. */
4496 b = set_raw_breakpoint (sal);
4497 set_breakpoint_count (breakpoint_count + 1);
4498 b->number = breakpoint_count;
4499 b->disposition = donttouch;
4500 b->exp = exp;
4501 b->exp_valid_block = exp_valid_block;
4502 b->exp_string = savestring (exp_start, exp_end - exp_start);
4503 b->val = val;
4504 b->cond = cond;
4505 if (cond_start)
4506 b->cond_string = savestring (cond_start, cond_end - cond_start);
4507 else
4508 b->cond_string = 0;
c5aa993b 4509
c906108c
SS
4510 frame = block_innermost_frame (exp_valid_block);
4511 if (frame)
4512 {
4513 prev_frame = get_prev_frame (frame);
4514 b->watchpoint_frame = frame->frame;
4515 }
4516 else
c5aa993b 4517 b->watchpoint_frame = (CORE_ADDR) 0;
c906108c
SS
4518
4519 if (mem_cnt && target_resources_ok > 0)
4520 b->type = bp_type;
4521 else
4522 b->type = bp_watchpoint;
4523
4524 /* If the expression is "local", then set up a "watchpoint scope"
4525 breakpoint at the point where we've left the scope of the watchpoint
4526 expression. */
4527 if (innermost_block)
4528 {
4529 if (prev_frame)
4530 {
4531 struct breakpoint *scope_breakpoint;
4532 struct symtab_and_line scope_sal;
4533
4534 INIT_SAL (&scope_sal); /* initialize to zeroes */
c5aa993b 4535 scope_sal.pc = get_frame_pc (prev_frame);
c906108c
SS
4536 scope_sal.section = find_pc_overlay (scope_sal.pc);
4537
4538 scope_breakpoint = set_raw_breakpoint (scope_sal);
4539 set_breakpoint_count (breakpoint_count + 1);
4540 scope_breakpoint->number = breakpoint_count;
4541
4542 scope_breakpoint->type = bp_watchpoint_scope;
4543 scope_breakpoint->enable = enabled;
4544
4545 /* Automatically delete the breakpoint when it hits. */
4546 scope_breakpoint->disposition = del;
4547
4548 /* Only break in the proper frame (help with recursion). */
4549 scope_breakpoint->frame = prev_frame->frame;
4550
4551 /* Set the address at which we will stop. */
4552 scope_breakpoint->address = get_frame_pc (prev_frame);
4553
4554 /* The scope breakpoint is related to the watchpoint. We
4555 will need to act on them together. */
4556 b->related_breakpoint = scope_breakpoint;
4557 }
4558 }
4559 value_free_to_mark (mark);
4560 mention (b);
4561}
4562
4563/* Return count of locations need to be watched and can be handled
4564 in hardware. If the watchpoint can not be handled
4565 in hardware return zero. */
4566
4567#if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
53a5351d
JM
4568#define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
4569 ((BYTE_SIZE) <= (REGISTER_SIZE))
4570#endif
4571
4572#if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
4573#define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
4574 TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN)
c906108c
SS
4575#endif
4576
4577static int
4578can_use_hardware_watchpoint (v)
4579 struct value *v;
4580{
4581 int found_memory_cnt = 0;
4582
4583 /* Did the user specifically forbid us to use hardware watchpoints? */
c5aa993b 4584 if (!can_use_hw_watchpoints)
c906108c 4585 return 0;
c5aa993b 4586
c906108c
SS
4587 /* Make sure all the intermediate values are in memory. Also make sure
4588 we found at least one memory expression. Guards against watch 0x12345,
4589 which is meaningless, but could cause errors if one tries to insert a
4590 hardware watchpoint for the constant expression. */
c5aa993b 4591 for (; v; v = v->next)
c906108c
SS
4592 {
4593 if (v->lval == lval_memory)
4594 {
53a5351d
JM
4595 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
4596 int len = TYPE_LENGTH (VALUE_TYPE (v));
4597
4598 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
4599 return 0;
4600 else
c906108c 4601 found_memory_cnt++;
c5aa993b 4602 }
c906108c 4603 else if (v->lval != not_lval && v->modifiable == 0)
53a5351d
JM
4604 return 0; /* ??? What does this represent? */
4605 else if (v->lval == lval_register)
4606 return 0; /* cannot watch a register with a HW watchpoint */
c906108c
SS
4607 }
4608
4609 /* The expression itself looks suitable for using a hardware
4610 watchpoint, but give the target machine a chance to reject it. */
4611 return found_memory_cnt;
4612}
4613
c5aa993b
JM
4614static void
4615watch_command (arg, from_tty)
c906108c
SS
4616 char *arg;
4617 int from_tty;
4618{
53a5351d 4619 watch_command_1 (arg, hw_write, from_tty);
c906108c
SS
4620}
4621
c5aa993b
JM
4622static void
4623rwatch_command (arg, from_tty)
c906108c
SS
4624 char *arg;
4625 int from_tty;
4626{
53a5351d 4627 watch_command_1 (arg, hw_read, from_tty);
c906108c
SS
4628}
4629
c5aa993b
JM
4630static void
4631awatch_command (arg, from_tty)
c906108c
SS
4632 char *arg;
4633 int from_tty;
4634{
53a5351d 4635 watch_command_1 (arg, hw_access, from_tty);
c906108c 4636}
c906108c 4637\f
c5aa993b 4638
43ff13b4 4639/* Helper routines for the until_command routine in infcmd.c. Here
c906108c
SS
4640 because it uses the mechanisms of breakpoints. */
4641
43ff13b4
JM
4642/* This function is called by fetch_inferior_event via the
4643 cmd_continuation pointer, to complete the until command. It takes
4644 care of cleaning up the temporary breakpoints set up by the until
4645 command. */
4646void
4647until_break_command_continuation (arg)
4648 struct continuation_arg *arg;
4649{
4650 /* Do all the exec cleanups, which at this point should only be the
4651 one set up in the first part of the until_break_command
4652 function. */
4653 do_exec_cleanups (ALL_CLEANUPS);
4654}
4655
c906108c
SS
4656/* ARGSUSED */
4657void
4658until_break_command (arg, from_tty)
4659 char *arg;
4660 int from_tty;
4661{
4662 struct symtabs_and_lines sals;
4663 struct symtab_and_line sal;
4664 struct frame_info *prev_frame = get_prev_frame (selected_frame);
4665 struct breakpoint *breakpoint;
4666 struct cleanup *old_chain;
4667
4668 clear_proceed_status ();
4669
4670 /* Set a breakpoint where the user wants it and at return from
4671 this function */
c5aa993b 4672
c906108c
SS
4673 if (default_breakpoint_valid)
4674 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
c5aa993b 4675 default_breakpoint_line, (char ***) NULL);
c906108c 4676 else
53a5351d
JM
4677 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
4678 0, (char ***) NULL);
c5aa993b 4679
c906108c
SS
4680 if (sals.nelts != 1)
4681 error ("Couldn't get information on specified line.");
c5aa993b 4682
c906108c 4683 sal = sals.sals[0];
c5aa993b
JM
4684 free ((PTR) sals.sals); /* malloc'd, so freed */
4685
c906108c
SS
4686 if (*arg)
4687 error ("Junk at end of arguments.");
c5aa993b 4688
c906108c 4689 resolve_sal_pc (&sal);
c5aa993b 4690
c906108c 4691 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
c5aa993b 4692
43ff13b4 4693 if (!async_p || !target_has_async)
53a5351d
JM
4694 old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint,
4695 breakpoint);
43ff13b4
JM
4696 else
4697 make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4698
4699 /* If we are running asynchronously, and the target supports async
4700 execution, we are not waiting for the target to stop, in the call
4701 tp proceed, below. This means that we cannot delete the
4702 brekpoints until the target has actually stopped. The only place
4703 where we get a chance to do that is in fetch_inferior_event, so
4704 we must set things up for that. */
4705
4706 if (async_p && target_has_async)
4707 {
4708 /* In this case we don't need args for the continuation, because
c5aa993b
JM
4709 all it needs to do is do the cleanups in the
4710 exec_cleanup_chain, which will be only those inserted by this
4711 function. We can get away by using ALL_CLEANUPS. */
43ff13b4
JM
4712 add_continuation (until_break_command_continuation, NULL);
4713 }
c906108c
SS
4714
4715 /* Keep within the current frame */
c5aa993b 4716
c906108c
SS
4717 if (prev_frame)
4718 {
4719 sal = find_pc_line (prev_frame->pc, 0);
4720 sal.pc = prev_frame->pc;
4721 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
43ff13b4
JM
4722 if (!async_p || !target_has_async)
4723 make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4724 else
4725 make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
c906108c 4726 }
c5aa993b 4727
c906108c 4728 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
43ff13b4
JM
4729 /* Do the cleanups now, anly if we are not running asynchronously,
4730 of if we are, but the target is still synchronous. */
4731 if (!async_p || !target_has_async)
c5aa993b 4732 do_cleanups (old_chain);
c906108c
SS
4733}
4734\f
4735#if 0
4736/* These aren't used; I don't konw what they were for. */
4737/* Set a breakpoint at the catch clause for NAME. */
4738static int
4739catch_breakpoint (name)
4740 char *name;
4741{
4742}
4743
4744static int
4745disable_catch_breakpoint ()
4746{
4747}
4748
4749static int
4750delete_catch_breakpoint ()
4751{
4752}
4753
4754static int
4755enable_catch_breakpoint ()
4756{
4757}
4758#endif /* 0 */
4759
4760struct sal_chain
4761{
4762 struct sal_chain *next;
4763 struct symtab_and_line sal;
4764};
4765
7a292a7a 4766#if 0
c906108c
SS
4767/* Not really used -- invocation in handle_gnu_4_16_catch_command
4768 had been commented out in the v.4.16 sources, and stays
4769 disabled there now because "catch NAME" syntax isn't allowed.
4770 pai/1997-07-11 */
4771/* This isn't used; I don't know what it was for. */
4772/* For each catch clause identified in ARGS, run FUNCTION
4773 with that clause as an argument. */
4774static struct symtabs_and_lines
4775map_catch_names (args, function)
4776 char *args;
c5aa993b 4777 int (*function) ();
c906108c
SS
4778{
4779 register char *p = args;
4780 register char *p1;
4781 struct symtabs_and_lines sals;
4782#if 0
4783 struct sal_chain *sal_chain = 0;
4784#endif
4785
4786 if (p == 0)
4787 error_no_arg ("one or more catch names");
4788
4789 sals.nelts = 0;
4790 sals.sals = NULL;
4791
4792 while (*p)
4793 {
4794 p1 = p;
4795 /* Don't swallow conditional part. */
4796 if (p1[0] == 'i' && p1[1] == 'f'
4797 && (p1[2] == ' ' || p1[2] == '\t'))
4798 break;
4799
4800 if (isalpha (*p1))
4801 {
4802 p1++;
4803 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
4804 p1++;
4805 }
4806
4807 if (*p1 && *p1 != ' ' && *p1 != '\t')
4808 error ("Arguments must be catch names.");
4809
4810 *p1 = 0;
4811#if 0
4812 if (function (p))
4813 {
4814 struct sal_chain *next = (struct sal_chain *)
c5aa993b 4815 alloca (sizeof (struct sal_chain));
c906108c
SS
4816 next->next = sal_chain;
4817 next->sal = get_catch_sal (p);
4818 sal_chain = next;
4819 goto win;
4820 }
4821#endif
4822 printf_unfiltered ("No catch clause for exception %s.\n", p);
4823#if 0
4824 win:
4825#endif
4826 p = p1;
c5aa993b
JM
4827 while (*p == ' ' || *p == '\t')
4828 p++;
c906108c
SS
4829 }
4830}
7a292a7a 4831#endif
c906108c
SS
4832
4833/* This shares a lot of code with `print_frame_label_vars' from stack.c. */
4834
4835static struct symtabs_and_lines
4836get_catch_sals (this_level_only)
4837 int this_level_only;
4838{
4839 register struct blockvector *bl;
4840 register struct block *block;
4841 int index, have_default = 0;
4842 CORE_ADDR pc;
4843 struct symtabs_and_lines sals;
4844 struct sal_chain *sal_chain = 0;
4845 char *blocks_searched;
4846
4847 /* Not sure whether an error message is always the correct response,
4848 but it's better than a core dump. */
4849 if (selected_frame == NULL)
4850 error ("No selected frame.");
4851 block = get_frame_block (selected_frame);
4852 pc = selected_frame->pc;
4853
4854 sals.nelts = 0;
4855 sals.sals = NULL;
4856
4857 if (block == 0)
4858 error ("No symbol table info available.\n");
4859
4860 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
4861 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
4862 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
4863
4864 while (block != 0)
4865 {
4866 CORE_ADDR end = BLOCK_END (block) - 4;
4867 int last_index;
4868
4869 if (bl != blockvector_for_pc (end, &index))
4870 error ("blockvector blotch");
4871 if (BLOCKVECTOR_BLOCK (bl, index) != block)
4872 error ("blockvector botch");
4873 last_index = BLOCKVECTOR_NBLOCKS (bl);
4874 index += 1;
4875
4876 /* Don't print out blocks that have gone by. */
4877 while (index < last_index
4878 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
4879 index++;
4880
4881 while (index < last_index
4882 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
4883 {
4884 if (blocks_searched[index] == 0)
4885 {
4886 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
4887 int nsyms;
4888 register int i;
4889 register struct symbol *sym;
4890
4891 nsyms = BLOCK_NSYMS (b);
4892
4893 for (i = 0; i < nsyms; i++)
4894 {
4895 sym = BLOCK_SYM (b, i);
4896 if (STREQ (SYMBOL_NAME (sym), "default"))
4897 {
4898 if (have_default)
4899 continue;
4900 have_default = 1;
4901 }
4902 if (SYMBOL_CLASS (sym) == LOC_LABEL)
4903 {
4904 struct sal_chain *next = (struct sal_chain *)
c5aa993b 4905 alloca (sizeof (struct sal_chain));
c906108c 4906 next->next = sal_chain;
53a5351d
JM
4907 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
4908 0);
c906108c
SS
4909 sal_chain = next;
4910 }
4911 }
4912 blocks_searched[index] = 1;
4913 }
4914 index++;
4915 }
4916 if (have_default)
4917 break;
4918 if (sal_chain && this_level_only)
4919 break;
4920
4921 /* After handling the function's top-level block, stop.
c5aa993b
JM
4922 Don't continue to its superblock, the block of
4923 per-file symbols. */
c906108c
SS
4924 if (BLOCK_FUNCTION (block))
4925 break;
4926 block = BLOCK_SUPERBLOCK (block);
4927 }
4928
4929 if (sal_chain)
4930 {
4931 struct sal_chain *tmp_chain;
4932
4933 /* Count the number of entries. */
4934 for (index = 0, tmp_chain = sal_chain; tmp_chain;
4935 tmp_chain = tmp_chain->next)
4936 index++;
4937
4938 sals.nelts = index;
4939 sals.sals = (struct symtab_and_line *)
4940 xmalloc (index * sizeof (struct symtab_and_line));
4941 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
4942 sals.sals[index] = sal_chain->sal;
4943 }
4944
4945 return sals;
4946}
4947
4948static void
4949ep_skip_leading_whitespace (s)
7a292a7a 4950 char **s;
c906108c 4951{
c5aa993b
JM
4952 if ((s == NULL) || (*s == NULL))
4953 return;
4954 while (isspace (**s))
4955 *s += 1;
c906108c 4956}
c5aa993b 4957
c906108c
SS
4958/* This function examines a string, and attempts to find a token
4959 that might be an event name in the leading characters. If a
4960 possible match is found, a pointer to the last character of
4961 the token is returned. Else, NULL is returned. */
53a5351d 4962
c906108c
SS
4963static char *
4964ep_find_event_name_end (arg)
7a292a7a 4965 char *arg;
c906108c 4966{
c5aa993b
JM
4967 char *s = arg;
4968 char *event_name_end = NULL;
4969
c906108c
SS
4970 /* If we could depend upon the presense of strrpbrk, we'd use that... */
4971 if (arg == NULL)
4972 return NULL;
c5aa993b 4973
c906108c 4974 /* We break out of the loop when we find a token delimiter.
c5aa993b
JM
4975 Basically, we're looking for alphanumerics and underscores;
4976 anything else delimites the token. */
c906108c
SS
4977 while (*s != '\0')
4978 {
c5aa993b
JM
4979 if (!isalnum (*s) && (*s != '_'))
4980 break;
c906108c
SS
4981 event_name_end = s;
4982 s++;
4983 }
c5aa993b 4984
c906108c
SS
4985 return event_name_end;
4986}
4987
c5aa993b 4988
c906108c
SS
4989/* This function attempts to parse an optional "if <cond>" clause
4990 from the arg string. If one is not found, it returns NULL.
c5aa993b 4991
c906108c
SS
4992 Else, it returns a pointer to the condition string. (It does not
4993 attempt to evaluate the string against a particular block.) And,
4994 it updates arg to point to the first character following the parsed
4995 if clause in the arg string. */
53a5351d 4996
c906108c
SS
4997static char *
4998ep_parse_optional_if_clause (arg)
7a292a7a 4999 char **arg;
c906108c 5000{
c5aa993b
JM
5001 char *cond_string;
5002
5003 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
c906108c 5004 return NULL;
c5aa993b 5005
c906108c
SS
5006 /* Skip the "if" keyword. */
5007 (*arg) += 2;
c5aa993b 5008
c906108c
SS
5009 /* Skip any extra leading whitespace, and record the start of the
5010 condition string. */
5011 ep_skip_leading_whitespace (arg);
5012 cond_string = *arg;
c5aa993b 5013
c906108c
SS
5014 /* Assume that the condition occupies the remainder of the arg string. */
5015 (*arg) += strlen (cond_string);
c5aa993b 5016
c906108c
SS
5017 return cond_string;
5018}
c5aa993b 5019
c906108c
SS
5020/* This function attempts to parse an optional filename from the arg
5021 string. If one is not found, it returns NULL.
c5aa993b 5022
c906108c
SS
5023 Else, it returns a pointer to the parsed filename. (This function
5024 makes no attempt to verify that a file of that name exists, or is
5025 accessible.) And, it updates arg to point to the first character
5026 following the parsed filename in the arg string.
c5aa993b 5027
c906108c
SS
5028 Note that clients needing to preserve the returned filename for
5029 future access should copy it to their own buffers. */
5030static char *
5031ep_parse_optional_filename (arg)
7a292a7a 5032 char **arg;
c906108c 5033{
c5aa993b
JM
5034 static char filename[1024];
5035 char *arg_p = *arg;
5036 int i;
5037 char c;
5038
c906108c
SS
5039 if ((*arg_p == '\0') || isspace (*arg_p))
5040 return NULL;
c5aa993b
JM
5041
5042 for (i = 0;; i++)
c906108c
SS
5043 {
5044 c = *arg_p;
5045 if (isspace (c))
c5aa993b 5046 c = '\0';
c906108c
SS
5047 filename[i] = c;
5048 if (c == '\0')
c5aa993b 5049 break;
c906108c
SS
5050 arg_p++;
5051 }
5052 *arg = arg_p;
c5aa993b 5053
c906108c
SS
5054 return filename;
5055}
c5aa993b 5056
c906108c
SS
5057/* Commands to deal with catching events, such as signals, exceptions,
5058 process start/exit, etc. */
c5aa993b
JM
5059
5060typedef enum
5061{
5062 catch_fork, catch_vfork
5063}
5064catch_fork_kind;
5065
53a5351d
JM
5066static void catch_fork_command_1 PARAMS ((catch_fork_kind fork_kind,
5067 char *arg,
5068 int tempflag,
5069 int from_tty));
7a292a7a 5070
c906108c
SS
5071static void
5072catch_fork_command_1 (fork_kind, arg, tempflag, from_tty)
7a292a7a
SS
5073 catch_fork_kind fork_kind;
5074 char *arg;
5075 int tempflag;
5076 int from_tty;
c906108c 5077{
c5aa993b
JM
5078 char *cond_string = NULL;
5079
c906108c 5080 ep_skip_leading_whitespace (&arg);
c5aa993b 5081
c906108c 5082 /* The allowed syntax is:
c5aa993b
JM
5083 catch [v]fork
5084 catch [v]fork if <cond>
5085
c906108c
SS
5086 First, check if there's an if clause. */
5087 cond_string = ep_parse_optional_if_clause (&arg);
c5aa993b 5088
c906108c
SS
5089 if ((*arg != '\0') && !isspace (*arg))
5090 error ("Junk at end of arguments.");
c5aa993b 5091
c906108c
SS
5092 /* If this target supports it, create a fork or vfork catchpoint
5093 and enable reporting of such events. */
c5aa993b
JM
5094 switch (fork_kind)
5095 {
5096 case catch_fork:
c906108c
SS
5097 create_fork_event_catchpoint (tempflag, cond_string);
5098 break;
c5aa993b 5099 case catch_vfork:
c906108c
SS
5100 create_vfork_event_catchpoint (tempflag, cond_string);
5101 break;
c5aa993b 5102 default:
c906108c
SS
5103 error ("unsupported or unknown fork kind; cannot catch it");
5104 break;
c5aa993b 5105 }
c906108c
SS
5106}
5107
5108static void
5109catch_exec_command_1 (arg, tempflag, from_tty)
7a292a7a
SS
5110 char *arg;
5111 int tempflag;
5112 int from_tty;
c906108c 5113{
c5aa993b 5114 char *cond_string = NULL;
c906108c
SS
5115
5116 ep_skip_leading_whitespace (&arg);
5117
5118 /* The allowed syntax is:
c5aa993b
JM
5119 catch exec
5120 catch exec if <cond>
c906108c
SS
5121
5122 First, check if there's an if clause. */
5123 cond_string = ep_parse_optional_if_clause (&arg);
5124
5125 if ((*arg != '\0') && !isspace (*arg))
5126 error ("Junk at end of arguments.");
5127
5128 /* If this target supports it, create an exec catchpoint
5129 and enable reporting of such events. */
5130 create_exec_event_catchpoint (tempflag, cond_string);
5131}
c5aa993b 5132
c906108c
SS
5133#if defined(SOLIB_ADD)
5134static void
5135catch_load_command_1 (arg, tempflag, from_tty)
c5aa993b
JM
5136 char *arg;
5137 int tempflag;
5138 int from_tty;
c906108c 5139{
c5aa993b
JM
5140 char *dll_pathname = NULL;
5141 char *cond_string = NULL;
5142
c906108c 5143 ep_skip_leading_whitespace (&arg);
c5aa993b 5144
c906108c 5145 /* The allowed syntax is:
c5aa993b
JM
5146 catch load
5147 catch load if <cond>
5148 catch load <filename>
5149 catch load <filename> if <cond>
5150
c906108c
SS
5151 The user is not allowed to specify the <filename> after an
5152 if clause.
c5aa993b 5153
c906108c 5154 We'll ignore the pathological case of a file named "if".
c5aa993b 5155
c906108c
SS
5156 First, check if there's an if clause. If so, then there
5157 cannot be a filename. */
5158 cond_string = ep_parse_optional_if_clause (&arg);
c5aa993b 5159
c906108c
SS
5160 /* If there was an if clause, then there cannot be a filename.
5161 Else, there might be a filename and an if clause. */
5162 if (cond_string == NULL)
5163 {
5164 dll_pathname = ep_parse_optional_filename (&arg);
5165 ep_skip_leading_whitespace (&arg);
5166 cond_string = ep_parse_optional_if_clause (&arg);
5167 }
c5aa993b 5168
c906108c
SS
5169 if ((*arg != '\0') && !isspace (*arg))
5170 error ("Junk at end of arguments.");
c5aa993b 5171
c906108c
SS
5172 /* Create a load breakpoint that only triggers when a load of
5173 the specified dll (or any dll, if no pathname was specified)
5174 occurs. */
53a5351d
JM
5175 SOLIB_CREATE_CATCH_LOAD_HOOK (inferior_pid, tempflag,
5176 dll_pathname, cond_string);
c906108c 5177}
c5aa993b 5178
c906108c
SS
5179static void
5180catch_unload_command_1 (arg, tempflag, from_tty)
c5aa993b
JM
5181 char *arg;
5182 int tempflag;
5183 int from_tty;
c906108c 5184{
c5aa993b
JM
5185 char *dll_pathname = NULL;
5186 char *cond_string = NULL;
5187
c906108c 5188 ep_skip_leading_whitespace (&arg);
c5aa993b 5189
c906108c 5190 /* The allowed syntax is:
c5aa993b
JM
5191 catch unload
5192 catch unload if <cond>
5193 catch unload <filename>
5194 catch unload <filename> if <cond>
5195
c906108c
SS
5196 The user is not allowed to specify the <filename> after an
5197 if clause.
c5aa993b 5198
c906108c 5199 We'll ignore the pathological case of a file named "if".
c5aa993b 5200
c906108c
SS
5201 First, check if there's an if clause. If so, then there
5202 cannot be a filename. */
5203 cond_string = ep_parse_optional_if_clause (&arg);
c5aa993b 5204
c906108c
SS
5205 /* If there was an if clause, then there cannot be a filename.
5206 Else, there might be a filename and an if clause. */
5207 if (cond_string == NULL)
5208 {
5209 dll_pathname = ep_parse_optional_filename (&arg);
5210 ep_skip_leading_whitespace (&arg);
5211 cond_string = ep_parse_optional_if_clause (&arg);
5212 }
c5aa993b 5213
c906108c
SS
5214 if ((*arg != '\0') && !isspace (*arg))
5215 error ("Junk at end of arguments.");
c5aa993b 5216
c906108c
SS
5217 /* Create an unload breakpoint that only triggers when an unload of
5218 the specified dll (or any dll, if no pathname was specified)
5219 occurs. */
53a5351d
JM
5220 SOLIB_CREATE_CATCH_UNLOAD_HOOK (inferior_pid, tempflag,
5221 dll_pathname, cond_string);
c906108c
SS
5222}
5223#endif /* SOLIB_ADD */
5224
5225/* Commands to deal with catching exceptions. */
5226
5227/* Set a breakpoint at the specified callback routine for an
c5aa993b 5228 exception event callback */
c906108c
SS
5229
5230static void
5231create_exception_catchpoint (tempflag, cond_string, ex_event, sal)
7a292a7a
SS
5232 int tempflag;
5233 char *cond_string;
5234 enum exception_event_kind ex_event;
5235 struct symtab_and_line *sal;
c906108c 5236{
c5aa993b 5237 struct breakpoint *b;
c5aa993b 5238 int thread = -1; /* All threads. */
c906108c 5239
c5aa993b 5240 if (!sal) /* no exception support? */
c906108c
SS
5241 return;
5242
5243 b = set_raw_breakpoint (*sal);
5244 set_breakpoint_count (breakpoint_count + 1);
5245 b->number = breakpoint_count;
5246 b->cond = NULL;
53a5351d
JM
5247 b->cond_string = (cond_string == NULL) ?
5248 NULL : savestring (cond_string, strlen (cond_string));
c906108c
SS
5249 b->thread = thread;
5250 b->addr_string = NULL;
5251 b->enable = enabled;
5252 b->disposition = tempflag ? del : donttouch;
5253 switch (ex_event)
5254 {
c5aa993b
JM
5255 case EX_EVENT_THROW:
5256 b->type = bp_catch_throw;
5257 break;
5258 case EX_EVENT_CATCH:
5259 b->type = bp_catch_catch;
5260 break;
5261 default: /* error condition */
5262 b->type = bp_none;
5263 b->enable = disabled;
5264 error ("Internal error -- invalid catchpoint kind");
c906108c
SS
5265 }
5266 mention (b);
5267}
5268
c5aa993b 5269/* Deal with "catch catch" and "catch throw" commands */
c906108c
SS
5270
5271static void
5272catch_exception_command_1 (ex_event, arg, tempflag, from_tty)
7a292a7a
SS
5273 enum exception_event_kind ex_event;
5274 char *arg;
5275 int tempflag;
5276 int from_tty;
c906108c 5277{
c5aa993b
JM
5278 char *cond_string = NULL;
5279 struct symtab_and_line *sal = NULL;
5280
c906108c 5281 ep_skip_leading_whitespace (&arg);
c5aa993b 5282
c906108c
SS
5283 cond_string = ep_parse_optional_if_clause (&arg);
5284
5285 if ((*arg != '\0') && !isspace (*arg))
5286 error ("Junk at end of arguments.");
5287
5288 if ((ex_event != EX_EVENT_THROW) &&
5289 (ex_event != EX_EVENT_CATCH))
5290 error ("Unsupported or unknown exception event; cannot catch it");
5291
5292 /* See if we can find a callback routine */
5293 sal = target_enable_exception_callback (ex_event, 1);
5294
c5aa993b 5295 if (sal)
c906108c
SS
5296 {
5297 /* We have callbacks from the runtime system for exceptions.
c5aa993b 5298 Set a breakpoint on the sal found, if no errors */
c906108c 5299 if (sal != (struct symtab_and_line *) -1)
c5aa993b 5300 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
c906108c 5301 else
53a5351d 5302 return; /* something went wrong with setting up callbacks */
c906108c 5303 }
c5aa993b 5304 else
c906108c
SS
5305 {
5306 /* No callbacks from runtime system for exceptions.
5307 Try GNU C++ exception breakpoints using labels in debug info. */
5308 if (ex_event == EX_EVENT_CATCH)
c5aa993b
JM
5309 {
5310 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
5311 }
c906108c 5312 else if (ex_event == EX_EVENT_THROW)
c5aa993b
JM
5313 {
5314 /* Set a breakpoint on __raise_exception () */
5315
53a5351d
JM
5316 warning ("Unsupported with this platform/compiler combination.");
5317 warning ("Perhaps you can achieve the effect you want by setting");
5318 warning ("a breakpoint on __raise_exception().");
c5aa993b 5319 }
c906108c
SS
5320 }
5321}
5322
5323/* Cover routine to allow wrapping target_enable_exception_catchpoints
5324 inside a catch_errors */
5325
5326static int
5327cover_target_enable_exception_callback (arg)
c5aa993b 5328 PTR arg;
c906108c
SS
5329{
5330 args_for_catchpoint_enable *args = arg;
5331 struct symtab_and_line *sal;
5332 sal = target_enable_exception_callback (args->kind, args->enable);
5333 if (sal == NULL)
5334 return 0;
5335 else if (sal == (struct symtab_and_line *) -1)
5336 return -1;
5337 else
c5aa993b 5338 return 1; /*is valid */
c906108c
SS
5339}
5340
5341
5342
5343/* This is the original v.4.16 and earlier version of the
5344 catch_command_1() function. Now that other flavours of "catch"
5345 have been introduced, and since exception handling can be handled
5346 in other ways (through target ops) also, this is used only for the
5347 GNU C++ exception handling system.
5348 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
5349 "catch NAME" is now no longer allowed in catch_command_1(). Also,
5350 there was no code in GDB 4.16 for "catch throw".
c5aa993b 5351
c906108c
SS
5352 Called from catch_exception_command_1 () */
5353
5354
5355static void
5356handle_gnu_4_16_catch_command (arg, tempflag, from_tty)
5357 char *arg;
5358 int tempflag;
5359 int from_tty;
5360{
5361 /* First, translate ARG into something we can deal with in terms
5362 of breakpoints. */
5363
5364 struct symtabs_and_lines sals;
5365 struct symtab_and_line sal;
5366 register struct expression *cond = 0;
5367 register struct breakpoint *b;
5368 char *save_arg;
5369 int i;
5370
c5aa993b 5371 INIT_SAL (&sal); /* initialize to zeroes */
c906108c
SS
5372
5373 /* If no arg given, or if first arg is 'if ', all active catch clauses
5374 are breakpointed. */
5375
c5aa993b 5376 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
c906108c
SS
5377 && (arg[2] == ' ' || arg[2] == '\t')))
5378 {
5379 /* Grab all active catch clauses. */
5380 sals = get_catch_sals (0);
5381 }
5382 else
5383 {
5384 /* Grab selected catch clauses. */
5385 error ("catch NAME not implemented");
5386
5387#if 0
5388 /* Not sure why this code has been disabled. I'm leaving
5389 it disabled. We can never come here now anyway
5390 since we don't allow the "catch NAME" syntax.
c5aa993b 5391 pai/1997-07-11 */
c906108c
SS
5392
5393 /* This isn't used; I don't know what it was for. */
5394 sals = map_catch_names (arg, catch_breakpoint);
5395#endif
5396 }
5397
c5aa993b 5398 if (!sals.nelts)
c906108c
SS
5399 return;
5400
5401 save_arg = arg;
5402 for (i = 0; i < sals.nelts; i++)
5403 {
5404 resolve_sal_pc (&sals.sals[i]);
c5aa993b 5405
c906108c
SS
5406 while (arg && *arg)
5407 {
5408 if (arg[0] == 'i' && arg[1] == 'f'
5409 && (arg[2] == ' ' || arg[2] == '\t'))
c5aa993b 5410 cond = parse_exp_1 ((arg += 2, &arg),
c906108c
SS
5411 block_for_pc (sals.sals[i].pc), 0);
5412 else
5413 error ("Junk at end of arguments.");
5414 }
5415 arg = save_arg;
5416 }
5417
5418 for (i = 0; i < sals.nelts; i++)
5419 {
5420 sal = sals.sals[i];
5421
5422 if (from_tty)
5423 describe_other_breakpoints (sal.pc, sal.section);
5424
5425 b = set_raw_breakpoint (sal);
5426 set_breakpoint_count (breakpoint_count + 1);
5427 b->number = breakpoint_count;
53a5351d
JM
5428
5429 /* Important -- this is an ordinary breakpoint. For platforms
5430 with callback support for exceptions,
5431 create_exception_catchpoint() will create special bp types
5432 (bp_catch_catch and bp_catch_throw), and there is code in
5433 insert_breakpoints() and elsewhere that depends on that. */
5434 b->type = bp_breakpoint;
c906108c
SS
5435
5436 b->cond = cond;
5437 b->enable = enabled;
5438 b->disposition = tempflag ? del : donttouch;
5439
5440 mention (b);
5441 }
5442
5443 if (sals.nelts > 1)
5444 {
53a5351d
JM
5445 warning ("Multiple breakpoints were set.");
5446 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
c906108c 5447 }
c5aa993b 5448 free ((PTR) sals.sals);
c906108c
SS
5449}
5450
5451#if 0
5452/* This creates a temporary internal breakpoint
5453 just to placate infrun */
5454static struct breakpoint *
5455create_temp_exception_breakpoint (pc)
c5aa993b 5456 CORE_ADDR pc;
c906108c
SS
5457{
5458 struct symtab_and_line sal;
5459 struct breakpoint *b;
5460
c5aa993b 5461 INIT_SAL (&sal);
c906108c
SS
5462 sal.pc = pc;
5463 sal.symtab = NULL;
5464 sal.line = 0;
5465
5466 b = set_raw_breakpoint (sal);
5467 if (!b)
5468 error ("Internal error -- couldn't set temp exception breakpoint");
5469
5470 b->type = bp_breakpoint;
5471 b->disposition = del;
5472 b->enable = enabled;
5473 b->silent = 1;
5474 b->number = internal_breakpoint_number--;
5475 return b;
5476}
5477#endif
5478
5479static void
5480catch_command_1 (arg, tempflag, from_tty)
c5aa993b
JM
5481 char *arg;
5482 int tempflag;
5483 int from_tty;
c906108c 5484{
c5aa993b 5485
c906108c
SS
5486 /* The first argument may be an event name, such as "start" or "load".
5487 If so, then handle it as such. If it doesn't match an event name,
5488 then attempt to interpret it as an exception name. (This latter is
5489 the v4.16-and-earlier GDB meaning of the "catch" command.)
c5aa993b 5490
c906108c 5491 First, try to find the bounds of what might be an event name. */
c5aa993b
JM
5492 char *arg1_start = arg;
5493 char *arg1_end;
5494 int arg1_length;
5495
c906108c
SS
5496 if (arg1_start == NULL)
5497 {
c5aa993b 5498 /* Old behaviour was to use pre-v-4.16 syntax */
c906108c
SS
5499 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
5500 /* return; */
c5aa993b 5501 /* Now, this is not allowed */
c906108c
SS
5502 error ("Catch requires an event name.");
5503
5504 }
5505 arg1_end = ep_find_event_name_end (arg1_start);
5506 if (arg1_end == NULL)
5507 error ("catch requires an event");
5508 arg1_length = arg1_end + 1 - arg1_start;
c5aa993b 5509
c906108c
SS
5510 /* Try to match what we found against known event names. */
5511 if (strncmp (arg1_start, "signal", arg1_length) == 0)
5512 {
5513 error ("Catch of signal not yet implemented");
5514 }
5515 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
5516 {
53a5351d
JM
5517 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
5518 tempflag, from_tty);
c906108c
SS
5519 }
5520 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
5521 {
53a5351d
JM
5522 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
5523 tempflag, from_tty);
c906108c
SS
5524 }
5525 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
5526 {
5527 error ("Catch of thread_start not yet implemented");
5528 }
5529 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
5530 {
5531 error ("Catch of thread_exit not yet implemented");
5532 }
5533 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
5534 {
5535 error ("Catch of thread_join not yet implemented");
5536 }
5537 else if (strncmp (arg1_start, "start", arg1_length) == 0)
5538 {
5539 error ("Catch of start not yet implemented");
5540 }
5541 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
5542 {
5543 error ("Catch of exit not yet implemented");
5544 }
5545 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
5546 {
5547#if defined(CHILD_INSERT_FORK_CATCHPOINT)
c5aa993b 5548 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
c906108c
SS
5549#else
5550 error ("Catch of fork not yet implemented");
5551#endif
5552 }
5553 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
5554 {
5555#if defined(CHILD_INSERT_VFORK_CATCHPOINT)
c5aa993b 5556 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
c906108c
SS
5557#else
5558 error ("Catch of vfork not yet implemented");
5559#endif
5560 }
5561 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
5562 {
5563#if defined(CHILD_INSERT_EXEC_CATCHPOINT)
c5aa993b 5564 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
c906108c
SS
5565#else
5566 error ("Catch of exec not yet implemented");
5567#endif
5568 }
5569 else if (strncmp (arg1_start, "load", arg1_length) == 0)
5570 {
5571#if defined(SOLIB_ADD)
c5aa993b 5572 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
c906108c
SS
5573#else
5574 error ("Catch of load not implemented");
5575#endif
5576 }
5577 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
5578 {
5579#if defined(SOLIB_ADD)
c5aa993b 5580 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
c906108c
SS
5581#else
5582 error ("Catch of load not implemented");
5583#endif
5584 }
5585 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
5586 {
5587 error ("Catch of stop not yet implemented");
5588 }
c5aa993b 5589
c906108c
SS
5590 /* This doesn't appear to be an event name */
5591
5592 else
5593 {
5594 /* Pre-v.4.16 behaviour was to treat the argument
c5aa993b 5595 as the name of an exception */
c906108c 5596 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
c5aa993b 5597 /* Now this is not allowed */
c906108c
SS
5598 error ("Unknown event kind specified for catch");
5599
5600 }
5601}
5602
5603/* Used by the gui, could be made a worker for other things. */
5604
5605struct breakpoint *
5606set_breakpoint_sal (sal)
5607 struct symtab_and_line sal;
5608{
5609 struct breakpoint *b;
5610 b = set_raw_breakpoint (sal);
5611 set_breakpoint_count (breakpoint_count + 1);
5612 b->number = breakpoint_count;
5613 b->type = bp_breakpoint;
5614 b->cond = 0;
5615 b->thread = -1;
5616 return b;
5617}
5618
5619#if 0
5620/* These aren't used; I don't know what they were for. */
5621/* Disable breakpoints on all catch clauses described in ARGS. */
5622static void
5623disable_catch (args)
5624 char *args;
5625{
5626 /* Map the disable command to catch clauses described in ARGS. */
5627}
5628
5629/* Enable breakpoints on all catch clauses described in ARGS. */
5630static void
5631enable_catch (args)
5632 char *args;
5633{
5634 /* Map the disable command to catch clauses described in ARGS. */
5635}
5636
5637/* Delete breakpoints on all catch clauses in the active scope. */
5638static void
5639delete_catch (args)
5640 char *args;
5641{
5642 /* Map the delete command to catch clauses described in ARGS. */
5643}
5644#endif /* 0 */
5645
5646static void
5647catch_command (arg, from_tty)
5648 char *arg;
5649 int from_tty;
5650{
5651 catch_command_1 (arg, 0, from_tty);
5652}
5653\f
5654
5655static void
5656tcatch_command (arg, from_tty)
5657 char *arg;
5658 int from_tty;
5659{
5660 catch_command_1 (arg, 1, from_tty);
5661}
5662
5663
5664static void
5665clear_command (arg, from_tty)
5666 char *arg;
5667 int from_tty;
5668{
5669 register struct breakpoint *b, *b1;
5670 int default_match;
5671 struct symtabs_and_lines sals;
5672 struct symtab_and_line sal;
5673 register struct breakpoint *found;
5674 int i;
5675
5676 if (arg)
5677 {
5678 sals = decode_line_spec (arg, 1);
5679 default_match = 0;
5680 }
5681 else
5682 {
c5aa993b 5683 sals.sals = (struct symtab_and_line *)
c906108c 5684 xmalloc (sizeof (struct symtab_and_line));
c5aa993b 5685 INIT_SAL (&sal); /* initialize to zeroes */
c906108c
SS
5686 sal.line = default_breakpoint_line;
5687 sal.symtab = default_breakpoint_symtab;
5688 sal.pc = default_breakpoint_address;
5689 if (sal.symtab == 0)
5690 error ("No source file specified.");
5691
5692 sals.sals[0] = sal;
5693 sals.nelts = 1;
5694
5695 default_match = 1;
5696 }
5697
5698 /* For each line spec given, delete bps which correspond
5699 to it. We do this in two loops: the first loop looks at
5700 the initial bp(s) in the chain which should be deleted,
5701 the second goes down the rest of the chain looking ahead
5702 one so it can take those bps off the chain without messing
5703 up the chain. */
5704
5705
5706 for (i = 0; i < sals.nelts; i++)
5707 {
5708 /* If exact pc given, clear bpts at that pc.
c5aa993b
JM
5709 If line given (pc == 0), clear all bpts on specified line.
5710 If defaulting, clear all bpts on default line
c906108c 5711 or at default pc.
c5aa993b
JM
5712
5713 defaulting sal.pc != 0 tests to do
5714
5715 0 1 pc
5716 1 1 pc _and_ line
5717 0 0 line
5718 1 0 <can't happen> */
c906108c
SS
5719
5720 sal = sals.sals[i];
5721 found = (struct breakpoint *) 0;
5722
5723
5724 while (breakpoint_chain
c5aa993b
JM
5725 /* Why don't we check here that this is not
5726 a watchpoint, etc., as we do below?
5727 I can't make it fail, but don't know
5728 what's stopping the failure: a watchpoint
5729 of the same address as "sal.pc" should
5730 wind up being deleted. */
5731
5732 && (((sal.pc && (breakpoint_chain->address == sal.pc)) &&
5733 (overlay_debugging == 0 ||
5734 breakpoint_chain->section == sal.section))
5735 || ((default_match || (0 == sal.pc))
5736 && breakpoint_chain->source_file != NULL
5737 && sal.symtab != NULL
5738 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
5739 && breakpoint_chain->line_number == sal.line)))
c906108c
SS
5740
5741 {
5742 b1 = breakpoint_chain;
5743 breakpoint_chain = b1->next;
5744 b1->next = found;
5745 found = b1;
5746 }
5747
5748 ALL_BREAKPOINTS (b)
5749
c5aa993b
JM
5750 while (b->next
5751 && b->next->type != bp_none
5752 && b->next->type != bp_watchpoint
5753 && b->next->type != bp_hardware_watchpoint
5754 && b->next->type != bp_read_watchpoint
5755 && b->next->type != bp_access_watchpoint
5756 && (((sal.pc && (b->next->address == sal.pc)) &&
5757 (overlay_debugging == 0 ||
5758 b->next->section == sal.section))
5759 || ((default_match || (0 == sal.pc))
5760 && b->next->source_file != NULL
5761 && sal.symtab != NULL
5762 && STREQ (b->next->source_file, sal.symtab->filename)
5763 && b->next->line_number == sal.line)))
c906108c
SS
5764
5765
c5aa993b
JM
5766 {
5767 b1 = b->next;
5768 b->next = b1->next;
5769 b1->next = found;
5770 found = b1;
5771 }
c906108c
SS
5772
5773 if (found == 0)
5774 {
5775 if (arg)
5776 error ("No breakpoint at %s.", arg);
5777 else
5778 error ("No breakpoint at this line.");
5779 }
5780
c5aa993b
JM
5781 if (found->next)
5782 from_tty = 1; /* Always report if deleted more than one */
5783 if (from_tty)
5784 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
c906108c
SS
5785 breakpoints_changed ();
5786 while (found)
5787 {
c5aa993b
JM
5788 if (from_tty)
5789 printf_unfiltered ("%d ", found->number);
c906108c
SS
5790 b1 = found->next;
5791 delete_breakpoint (found);
5792 found = b1;
5793 }
c5aa993b
JM
5794 if (from_tty)
5795 putchar_unfiltered ('\n');
c906108c 5796 }
c5aa993b 5797 free ((PTR) sals.sals);
c906108c
SS
5798}
5799\f
5800/* Delete breakpoint in BS if they are `delete' breakpoints and
5801 all breakpoints that are marked for deletion, whether hit or not.
5802 This is called after any breakpoint is hit, or after errors. */
5803
5804void
5805breakpoint_auto_delete (bs)
5806 bpstat bs;
5807{
5808 struct breakpoint *b, *temp;
5809
5810 for (; bs; bs = bs->next)
c5aa993b 5811 if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
c906108c
SS
5812 && bs->stop)
5813 delete_breakpoint (bs->breakpoint_at);
5814
5815 ALL_BREAKPOINTS_SAFE (b, temp)
c5aa993b
JM
5816 {
5817 if (b->disposition == del_at_next_stop)
5818 delete_breakpoint (b);
5819 }
c906108c
SS
5820}
5821
53a5351d
JM
5822/* Delete a breakpoint and clean up all traces of it in the data
5823 structures. */
c906108c
SS
5824
5825void
5826delete_breakpoint (bpt)
5827 struct breakpoint *bpt;
5828{
5829 register struct breakpoint *b;
5830 register bpstat bs;
5831
5832 if (bpt == NULL)
5833 error ("Internal error (attempted to delete a NULL breakpoint)");
5834
5835
5836 /* Has this bp already been deleted? This can happen because multiple
5837 lists can hold pointers to bp's. bpstat lists are especial culprits.
5838
5839 One example of this happening is a watchpoint's scope bp. When the
5840 scope bp triggers, we notice that the watchpoint is out of scope, and
5841 delete it. We also delete its scope bp. But the scope bp is marked
5842 "auto-deleting", and is already on a bpstat. That bpstat is then
5843 checked for auto-deleting bp's, which are deleted.
5844
5845 A real solution to this problem might involve reference counts in bp's,
5846 and/or giving them pointers back to their referencing bpstat's, and
5847 teaching delete_breakpoint to only free a bp's storage when no more
5848 references were extent. A cheaper bandaid was chosen. */
5849 if (bpt->type == bp_none)
5850 return;
5851
5852 if (delete_breakpoint_hook)
5853 delete_breakpoint_hook (bpt);
104c1213 5854 breakpoint_delete_event (bpt->number);
c906108c
SS
5855
5856 if (bpt->inserted)
5857 remove_breakpoint (bpt, mark_uninserted);
c5aa993b 5858
c906108c
SS
5859 if (breakpoint_chain == bpt)
5860 breakpoint_chain = bpt->next;
5861
5862 /* If we have callback-style exception catchpoints, don't go through
5863 the adjustments to the C++ runtime library etc. if the inferior
5864 isn't actually running. target_enable_exception_callback for a
5865 null target ops vector gives an undesirable error message, so we
5866 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
c5aa993b 5867 exceptions are supported in this way, it's OK for now. FIXME */
c906108c
SS
5868 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
5869 {
5870 static char message1[] = "Error in deleting catchpoint %d:\n";
5871 static char message[sizeof (message1) + 30];
5872 args_for_catchpoint_enable args;
5873
53a5351d
JM
5874 /* Format possible error msg */
5875 sprintf (message, message1, bpt->number);
5876 args.kind = bpt->type == bp_catch_catch ?
5877 EX_EVENT_CATCH : EX_EVENT_THROW;
c906108c
SS
5878 args.enable = 0;
5879 catch_errors (cover_target_enable_exception_callback, &args,
5880 message, RETURN_MASK_ALL);
5881 }
5882
5883
5884 ALL_BREAKPOINTS (b)
5885 if (b->next == bpt)
c5aa993b
JM
5886 {
5887 b->next = bpt->next;
5888 break;
5889 }
c906108c
SS
5890
5891 /* Before turning off the visuals for the bp, check to see that
5892 there are no other bps at the same address. */
5893 if (tui_version)
5894 {
5895 int clearIt;
5896
5897 ALL_BREAKPOINTS (b)
c5aa993b
JM
5898 {
5899 clearIt = (b->address != bpt->address);
5900 if (!clearIt)
5901 break;
5902 }
c906108c
SS
5903
5904 if (clearIt)
c5aa993b
JM
5905 {
5906 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, bpt, 0));
5907 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
5908 }
c906108c
SS
5909 }
5910
5911 check_duplicates (bpt->address, bpt->section);
5912 /* If this breakpoint was inserted, and there is another breakpoint
5913 at the same address, we need to insert the other breakpoint. */
5914 if (bpt->inserted
5915 && bpt->type != bp_hardware_watchpoint
5916 && bpt->type != bp_read_watchpoint
5917 && bpt->type != bp_access_watchpoint
5918 && bpt->type != bp_catch_fork
5919 && bpt->type != bp_catch_vfork
5920 && bpt->type != bp_catch_exec)
5921 {
5922 ALL_BREAKPOINTS (b)
5923 if (b->address == bpt->address
5924 && b->section == bpt->section
5925 && !b->duplicate
5926 && b->enable != disabled
5927 && b->enable != shlib_disabled
5928 && b->enable != call_disabled)
c5aa993b
JM
5929 {
5930 int val;
53a5351d
JM
5931
5932 if (b->type == bp_hardware_breakpoint)
5933 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
5934 else
5935 val = target_insert_breakpoint (b->address, b->shadow_contents);
5936
c5aa993b
JM
5937 if (val != 0)
5938 {
5939 target_terminal_ours_for_output ();
53a5351d 5940 warning ("Cannot insert breakpoint %d:", b->number);
c5aa993b
JM
5941 memory_error (val, b->address); /* which bombs us out */
5942 }
5943 else
5944 b->inserted = 1;
5945 }
c906108c
SS
5946 }
5947
5948 free_command_lines (&bpt->commands);
5949 if (bpt->cond)
5950 free (bpt->cond);
5951 if (bpt->cond_string != NULL)
5952 free (bpt->cond_string);
5953 if (bpt->addr_string != NULL)
5954 free (bpt->addr_string);
5955 if (bpt->exp != NULL)
5956 free (bpt->exp);
5957 if (bpt->exp_string != NULL)
5958 free (bpt->exp_string);
5959 if (bpt->val != NULL)
5960 value_free (bpt->val);
5961 if (bpt->source_file != NULL)
5962 free (bpt->source_file);
5963 if (bpt->dll_pathname != NULL)
5964 free (bpt->dll_pathname);
5965 if (bpt->triggered_dll_pathname != NULL)
5966 free (bpt->triggered_dll_pathname);
5967 if (bpt->exec_pathname != NULL)
5968 free (bpt->exec_pathname);
5969
5970 /* Be sure no bpstat's are pointing at it after it's been freed. */
5971 /* FIXME, how can we find all bpstat's?
5972 We just check stop_bpstat for now. */
5973 for (bs = stop_bpstat; bs; bs = bs->next)
5974 if (bs->breakpoint_at == bpt)
5975 {
5976 bs->breakpoint_at = NULL;
5977
5978 /* we'd call bpstat_clear_actions, but that free's stuff and due
5979 to the multiple pointers pointing to one item with no
5980 reference counts found anywhere through out the bpstat's (how
5981 do you spell fragile?), we don't want to free things twice --
5982 better a memory leak than a corrupt malloc pool! */
5983 bs->commands = NULL;
5984 bs->old_val = NULL;
5985 }
5986 /* On the chance that someone will soon try again to delete this same
5987 bp, we mark it as deleted before freeing its storage. */
5988 bpt->type = bp_none;
5989
c5aa993b 5990 free ((PTR) bpt);
c906108c
SS
5991}
5992
5993void
5994delete_command (arg, from_tty)
5995 char *arg;
5996 int from_tty;
5997{
5998 struct breakpoint *b, *temp;
5999
6000 if (arg == 0)
6001 {
6002 int breaks_to_delete = 0;
6003
6004 /* Delete all breakpoints if no argument.
c5aa993b
JM
6005 Do not delete internal or call-dummy breakpoints, these
6006 have to be deleted with an explicit breakpoint number argument. */
6007 ALL_BREAKPOINTS (b)
6008 {
6009 if (b->type != bp_call_dummy &&
6010 b->type != bp_shlib_event &&
6011 b->number >= 0)
6012 breaks_to_delete = 1;
6013 }
c906108c
SS
6014
6015 /* Ask user only if there are some breakpoints to delete. */
6016 if (!from_tty
6017 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6018 {
c5aa993b
JM
6019 ALL_BREAKPOINTS_SAFE (b, temp)
6020 {
6021 if (b->type != bp_call_dummy &&
6022 b->type != bp_shlib_event &&
6023 b->number >= 0)
6024 delete_breakpoint (b);
6025 }
c906108c
SS
6026 }
6027 }
6028 else
6029 map_breakpoint_numbers (arg, delete_breakpoint);
6030}
6031
6032/* Reset a breakpoint given it's struct breakpoint * BINT.
6033 The value we return ends up being the return value from catch_errors.
6034 Unused in this case. */
6035
6036static int
6037breakpoint_re_set_one (bint)
6038 PTR bint;
6039{
53a5351d
JM
6040 /* get past catch_errs */
6041 struct breakpoint *b = (struct breakpoint *) bint;
c906108c
SS
6042 struct value *mark;
6043 int i;
6044 struct symtabs_and_lines sals;
6045 char *s;
6046 enum enable save_enable;
6047
6048 switch (b->type)
6049 {
6050 case bp_none:
53a5351d
JM
6051 warning ("attempted to reset apparently deleted breakpoint #%d?",
6052 b->number);
c906108c
SS
6053 return 0;
6054 case bp_breakpoint:
6055 case bp_hardware_breakpoint:
6056 case bp_catch_load:
6057 case bp_catch_unload:
6058 if (b->addr_string == NULL)
6059 {
6060 /* Anything without a string can't be re-set. */
6061 delete_breakpoint (b);
6062 return 0;
6063 }
6064 /* In case we have a problem, disable this breakpoint. We'll restore
c5aa993b 6065 its status if we succeed. */
c906108c
SS
6066 save_enable = b->enable;
6067 b->enable = disabled;
6068
6069 set_language (b->language);
6070 input_radix = b->input_radix;
6071 s = b->addr_string;
c5aa993b 6072 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
c906108c
SS
6073 for (i = 0; i < sals.nelts; i++)
6074 {
6075 resolve_sal_pc (&sals.sals[i]);
6076
6077 /* Reparse conditions, they might contain references to the
6078 old symtab. */
6079 if (b->cond_string != NULL)
6080 {
6081 s = b->cond_string;
6082 if (b->cond)
c5aa993b 6083 free ((PTR) b->cond);
c906108c
SS
6084 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6085 }
6086
c5aa993b 6087 /* We need to re-set the breakpoint if the address changes... */
c906108c 6088 if (b->address != sals.sals[i].pc
c5aa993b
JM
6089 /* ...or new and old breakpoints both have source files, and
6090 the source file name or the line number changes... */
c906108c
SS
6091 || (b->source_file != NULL
6092 && sals.sals[i].symtab != NULL
6093 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6094 || b->line_number != sals.sals[i].line)
c906108c 6095 )
c5aa993b
JM
6096 /* ...or we switch between having a source file and not having
6097 one. */
6098 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6099 )
c906108c
SS
6100 {
6101 if (b->source_file != NULL)
6102 free (b->source_file);
6103 if (sals.sals[i].symtab == NULL)
6104 b->source_file = NULL;
6105 else
6106 b->source_file =
6107 savestring (sals.sals[i].symtab->filename,
6108 strlen (sals.sals[i].symtab->filename));
6109 b->line_number = sals.sals[i].line;
6110 b->address = sals.sals[i].pc;
6111
c5aa993b
JM
6112 /* Used to check for duplicates here, but that can
6113 cause trouble, as it doesn't check for disable
6114 breakpoints. */
c906108c
SS
6115
6116 mention (b);
6117
6118 /* Might be better to do this just once per breakpoint_re_set,
c5aa993b 6119 rather than once for every breakpoint. */
c906108c
SS
6120 breakpoints_changed ();
6121 }
6122 b->section = sals.sals[i].section;
6123 b->enable = save_enable; /* Restore it, this worked. */
6124
6125
c5aa993b 6126 /* Now that this is re-enabled, check_duplicates
c906108c 6127 can be used. */
c5aa993b 6128 check_duplicates (b->address, b->section);
c906108c
SS
6129
6130 }
c5aa993b 6131 free ((PTR) sals.sals);
c906108c
SS
6132 break;
6133
6134 case bp_watchpoint:
6135 case bp_hardware_watchpoint:
6136 case bp_read_watchpoint:
6137 case bp_access_watchpoint:
6138 innermost_block = NULL;
53a5351d
JM
6139 /* The issue arises of what context to evaluate this in. The
6140 same one as when it was set, but what does that mean when
6141 symbols have been re-read? We could save the filename and
6142 functionname, but if the context is more local than that, the
6143 best we could do would be something like how many levels deep
6144 and which index at that particular level, but that's going to
6145 be less stable than filenames or function names. */
6146
c906108c
SS
6147 /* So for now, just use a global context. */
6148 if (b->exp)
c5aa993b 6149 free ((PTR) b->exp);
c906108c
SS
6150 b->exp = parse_expression (b->exp_string);
6151 b->exp_valid_block = innermost_block;
6152 mark = value_mark ();
6153 if (b->val)
6154 value_free (b->val);
6155 b->val = evaluate_expression (b->exp);
6156 release_value (b->val);
6157 if (VALUE_LAZY (b->val))
6158 value_fetch_lazy (b->val);
6159
6160 if (b->cond_string != NULL)
6161 {
6162 s = b->cond_string;
6163 if (b->cond)
c5aa993b
JM
6164 free ((PTR) b->cond);
6165 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
c906108c
SS
6166 }
6167 if (b->enable == enabled)
6168 mention (b);
6169 value_free_to_mark (mark);
6170 break;
c5aa993b
JM
6171 case bp_catch_catch:
6172 case bp_catch_throw:
c906108c 6173 break;
c5aa993b
JM
6174 /* We needn't really do anything to reset these, since the mask
6175 that requests them is unaffected by e.g., new libraries being
6176 loaded. */
c906108c
SS
6177 case bp_catch_fork:
6178 case bp_catch_vfork:
6179 case bp_catch_exec:
6180 break;
c5aa993b 6181
c906108c
SS
6182 default:
6183 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
6184 /* fall through */
c5aa993b
JM
6185 /* Delete longjmp breakpoints, they will be reset later by
6186 breakpoint_re_set. */
c906108c
SS
6187 case bp_longjmp:
6188 case bp_longjmp_resume:
6189 delete_breakpoint (b);
6190 break;
6191
c5aa993b
JM
6192 /* This breakpoint is special, it's set up when the inferior
6193 starts and we really don't want to touch it. */
c906108c
SS
6194 case bp_shlib_event:
6195
c5aa993b
JM
6196 /* Keep temporary breakpoints, which can be encountered when we step
6197 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6198 Otherwise these should have been blown away via the cleanup chain
6199 or by breakpoint_init_inferior when we rerun the executable. */
c906108c
SS
6200 case bp_until:
6201 case bp_finish:
6202 case bp_watchpoint_scope:
6203 case bp_call_dummy:
6204 case bp_step_resume:
6205 break;
6206 }
6207
6208 return 0;
6209}
6210
6211/* Re-set all breakpoints after symbols have been re-loaded. */
6212void
6213breakpoint_re_set ()
6214{
6215 struct breakpoint *b, *temp;
6216 enum language save_language;
6217 int save_input_radix;
6218 static char message1[] = "Error in re-setting breakpoint %d:\n";
c5aa993b
JM
6219 char message[sizeof (message1) + 30 /* slop */ ];
6220
c906108c
SS
6221 save_language = current_language->la_language;
6222 save_input_radix = input_radix;
6223 ALL_BREAKPOINTS_SAFE (b, temp)
c5aa993b 6224 {
53a5351d
JM
6225 /* Format possible error msg */
6226 sprintf (message, message1, b->number);
c5aa993b
JM
6227 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
6228 }
c906108c
SS
6229 set_language (save_language);
6230 input_radix = save_input_radix;
6231
6232#ifdef GET_LONGJMP_TARGET
6233 create_longjmp_breakpoint ("longjmp");
6234 create_longjmp_breakpoint ("_longjmp");
6235 create_longjmp_breakpoint ("siglongjmp");
6236 create_longjmp_breakpoint ("_siglongjmp");
6237 create_longjmp_breakpoint (NULL);
6238#endif
6239
6240#if 0
6241 /* Took this out (temporarily at least), since it produces an extra
6242 blank line at startup. This messes up the gdbtests. -PB */
6243 /* Blank line to finish off all those mention() messages we just printed. */
6244 printf_filtered ("\n");
6245#endif
6246}
6247\f
6248/* Set ignore-count of breakpoint number BPTNUM to COUNT.
6249 If from_tty is nonzero, it prints a message to that effect,
6250 which ends with a period (no newline). */
6251
6252/* Reset the thread number of this breakpoint:
6253
6254 - If the breakpoint is for all threads, leave it as-is.
6255 - Else, reset it to the current thread for inferior_pid. */
6256void
6257breakpoint_re_set_thread (b)
c5aa993b 6258 struct breakpoint *b;
c906108c
SS
6259{
6260 if (b->thread != -1)
6261 {
6262 if (in_thread_list (inferior_pid))
c5aa993b 6263 b->thread = pid_to_thread_id (inferior_pid);
c906108c
SS
6264 }
6265}
6266
6267void
6268set_ignore_count (bptnum, count, from_tty)
6269 int bptnum, count, from_tty;
6270{
6271 register struct breakpoint *b;
6272
6273 if (count < 0)
6274 count = 0;
6275
6276 ALL_BREAKPOINTS (b)
6277 if (b->number == bptnum)
c5aa993b
JM
6278 {
6279 b->ignore_count = count;
6280 if (!from_tty)
c906108c 6281 return;
c5aa993b
JM
6282 else if (count == 0)
6283 printf_filtered ("Will stop next time breakpoint %d is reached.",
6284 bptnum);
6285 else if (count == 1)
6286 printf_filtered ("Will ignore next crossing of breakpoint %d.",
6287 bptnum);
6288 else
6289 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
6290 count, bptnum);
6291 breakpoints_changed ();
6292 return;
6293 }
c906108c
SS
6294
6295 error ("No breakpoint number %d.", bptnum);
6296}
6297
6298/* Clear the ignore counts of all breakpoints. */
6299void
6300breakpoint_clear_ignore_counts ()
6301{
6302 struct breakpoint *b;
6303
6304 ALL_BREAKPOINTS (b)
6305 b->ignore_count = 0;
6306}
6307
6308/* Command to set ignore-count of breakpoint N to COUNT. */
6309
6310static void
6311ignore_command (args, from_tty)
6312 char *args;
6313 int from_tty;
6314{
6315 char *p = args;
6316 register int num;
6317
6318 if (p == 0)
6319 error_no_arg ("a breakpoint number");
c5aa993b 6320
c906108c
SS
6321 num = get_number (&p);
6322
6323 if (*p == 0)
6324 error ("Second argument (specified ignore-count) is missing.");
6325
6326 set_ignore_count (num,
6327 longest_to_int (value_as_long (parse_and_eval (p))),
6328 from_tty);
6329 printf_filtered ("\n");
6330 breakpoints_changed ();
6331}
6332\f
6333/* Call FUNCTION on each of the breakpoints
6334 whose numbers are given in ARGS. */
6335
6336static void
6337map_breakpoint_numbers (args, function)
6338 char *args;
6339 void (*function) PARAMS ((struct breakpoint *));
6340{
6341 register char *p = args;
6342 char *p1;
6343 register int num;
6344 register struct breakpoint *b;
6345
6346 if (p == 0)
6347 error_no_arg ("one or more breakpoint numbers");
6348
6349 while (*p)
6350 {
6351 p1 = p;
c5aa993b 6352
c906108c
SS
6353 num = get_number (&p1);
6354
6355 ALL_BREAKPOINTS (b)
6356 if (b->number == num)
c5aa993b
JM
6357 {
6358 struct breakpoint *related_breakpoint = b->related_breakpoint;
6359 function (b);
6360 if (related_breakpoint)
6361 function (related_breakpoint);
6362 goto win;
6363 }
c906108c
SS
6364 printf_unfiltered ("No breakpoint number %d.\n", num);
6365 win:
6366 p = p1;
6367 }
6368}
6369
6370void
6371disable_breakpoint (bpt)
6372 struct breakpoint *bpt;
6373{
6374 /* Never disable a watchpoint scope breakpoint; we want to
6375 hit them when we leave scope so we can delete both the
6376 watchpoint and its scope breakpoint at that time. */
6377 if (bpt->type == bp_watchpoint_scope)
6378 return;
6379
6380 bpt->enable = disabled;
6381
6382 check_duplicates (bpt->address, bpt->section);
6383
6384 if (modify_breakpoint_hook)
6385 modify_breakpoint_hook (bpt);
104c1213 6386 breakpoint_modify_event (bpt->number);
c906108c
SS
6387}
6388
6389/* ARGSUSED */
6390static void
6391disable_command (args, from_tty)
6392 char *args;
6393 int from_tty;
6394{
6395 register struct breakpoint *bpt;
6396 if (args == 0)
6397 ALL_BREAKPOINTS (bpt)
6398 switch (bpt->type)
c5aa993b
JM
6399 {
6400 case bp_none:
53a5351d
JM
6401 warning ("attempted to disable apparently deleted breakpoint #%d?",
6402 bpt->number);
c5aa993b
JM
6403 continue;
6404 case bp_breakpoint:
6405 case bp_catch_load:
6406 case bp_catch_unload:
6407 case bp_catch_fork:
6408 case bp_catch_vfork:
6409 case bp_catch_exec:
6410 case bp_catch_catch:
6411 case bp_catch_throw:
6412 case bp_hardware_breakpoint:
6413 case bp_watchpoint:
6414 case bp_hardware_watchpoint:
6415 case bp_read_watchpoint:
6416 case bp_access_watchpoint:
6417 disable_breakpoint (bpt);
6418 default:
6419 continue;
6420 }
c906108c
SS
6421 else
6422 map_breakpoint_numbers (args, disable_breakpoint);
6423}
6424
6425static void
6426do_enable_breakpoint (bpt, disposition)
6427 struct breakpoint *bpt;
6428 enum bpdisp disposition;
6429{
6430 struct frame_info *save_selected_frame = NULL;
6431 int save_selected_frame_level = -1;
6432 int target_resources_ok, other_type_used;
6433 struct value *mark;
6434
6435 if (bpt->type == bp_hardware_breakpoint)
6436 {
6437 int i;
c5aa993b 6438 i = hw_breakpoint_used_count ();
53a5351d
JM
6439 target_resources_ok =
6440 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
6441 i + 1, 0);
c906108c 6442 if (target_resources_ok == 0)
c5aa993b 6443 error ("No hardware breakpoint support in the target.");
c906108c 6444 else if (target_resources_ok < 0)
c5aa993b 6445 error ("Hardware breakpoints used exceeds limit.");
c906108c
SS
6446 }
6447
6448 bpt->enable = enabled;
6449 bpt->disposition = disposition;
6450 check_duplicates (bpt->address, bpt->section);
6451 breakpoints_changed ();
6452
53a5351d
JM
6453 if (bpt->type == bp_watchpoint ||
6454 bpt->type == bp_hardware_watchpoint ||
6455 bpt->type == bp_read_watchpoint ||
6456 bpt->type == bp_access_watchpoint)
c906108c
SS
6457 {
6458 if (bpt->exp_valid_block != NULL)
6459 {
6460 struct frame_info *fr =
6461
c5aa993b
JM
6462 /* Ensure that we have the current frame. Else, this
6463 next query may pessimistically be answered as, "No,
6464 not within current scope". */
6465 get_current_frame ();
6466 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
c906108c
SS
6467 if (fr == NULL)
6468 {
6469 printf_filtered ("\
6470Cannot enable watchpoint %d because the block in which its expression\n\
6471is valid is not currently in scope.\n", bpt->number);
6472 bpt->enable = disabled;
6473 return;
6474 }
6475
6476 save_selected_frame = selected_frame;
6477 save_selected_frame_level = selected_frame_level;
6478 select_frame (fr, -1);
6479 }
6480
6481 value_free (bpt->val);
6482 mark = value_mark ();
6483 bpt->val = evaluate_expression (bpt->exp);
6484 release_value (bpt->val);
6485 if (VALUE_LAZY (bpt->val))
6486 value_fetch_lazy (bpt->val);
6487
6488 if (bpt->type == bp_hardware_watchpoint ||
c5aa993b
JM
6489 bpt->type == bp_read_watchpoint ||
6490 bpt->type == bp_access_watchpoint)
6491 {
6492 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
6493 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
6494
6495 /* Hack around 'unused var' error for some targets here */
6496 (void) mem_cnt, i;
6497 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
6498 bpt->type, i + mem_cnt, other_type_used);
6499 /* we can consider of type is bp_hardware_watchpoint, convert to
6500 bp_watchpoint in the following condition */
6501 if (target_resources_ok < 0)
6502 {
6503 printf_filtered ("\
c906108c
SS
6504Cannot enable watchpoint %d because target watch resources\n\
6505have been allocated for other watchpoints.\n", bpt->number);
c5aa993b
JM
6506 bpt->enable = disabled;
6507 value_free_to_mark (mark);
6508 return;
6509 }
6510 }
c906108c
SS
6511
6512 if (save_selected_frame_level >= 0)
53a5351d
JM
6513 select_and_print_frame (save_selected_frame,
6514 save_selected_frame_level);
c906108c
SS
6515 value_free_to_mark (mark);
6516 }
6517 if (modify_breakpoint_hook)
6518 modify_breakpoint_hook (bpt);
104c1213 6519 breakpoint_modify_event (bpt->number);
c906108c
SS
6520}
6521
6522void
6523enable_breakpoint (bpt)
6524 struct breakpoint *bpt;
6525{
6526 do_enable_breakpoint (bpt, bpt->disposition);
6527}
6528
6529/* The enable command enables the specified breakpoints (or all defined
6530 breakpoints) so they once again become (or continue to be) effective
6531 in stopping the inferior. */
6532
6533/* ARGSUSED */
6534static void
6535enable_command (args, from_tty)
6536 char *args;
6537 int from_tty;
6538{
6539 register struct breakpoint *bpt;
6540 if (args == 0)
6541 ALL_BREAKPOINTS (bpt)
6542 switch (bpt->type)
c5aa993b
JM
6543 {
6544 case bp_none:
53a5351d
JM
6545 warning ("attempted to enable apparently deleted breakpoint #%d?",
6546 bpt->number);
c5aa993b
JM
6547 continue;
6548 case bp_breakpoint:
6549 case bp_catch_load:
6550 case bp_catch_unload:
6551 case bp_catch_fork:
6552 case bp_catch_vfork:
6553 case bp_catch_exec:
6554 case bp_catch_catch:
6555 case bp_catch_throw:
6556 case bp_hardware_breakpoint:
6557 case bp_watchpoint:
6558 case bp_hardware_watchpoint:
6559 case bp_read_watchpoint:
6560 case bp_access_watchpoint:
6561 enable_breakpoint (bpt);
6562 default:
6563 continue;
6564 }
c906108c
SS
6565 else
6566 map_breakpoint_numbers (args, enable_breakpoint);
6567}
6568
6569static void
6570enable_once_breakpoint (bpt)
6571 struct breakpoint *bpt;
6572{
6573 do_enable_breakpoint (bpt, disable);
6574}
6575
6576/* ARGSUSED */
6577static void
6578enable_once_command (args, from_tty)
6579 char *args;
6580 int from_tty;
6581{
6582 map_breakpoint_numbers (args, enable_once_breakpoint);
6583}
6584
6585static void
6586enable_delete_breakpoint (bpt)
6587 struct breakpoint *bpt;
6588{
6589 do_enable_breakpoint (bpt, del);
6590}
6591
6592/* ARGSUSED */
6593static void
6594enable_delete_command (args, from_tty)
6595 char *args;
6596 int from_tty;
6597{
6598 map_breakpoint_numbers (args, enable_delete_breakpoint);
6599}
6600\f
6601/* Use default_breakpoint_'s, or nothing if they aren't valid. */
6602
6603struct symtabs_and_lines
6604decode_line_spec_1 (string, funfirstline)
6605 char *string;
6606 int funfirstline;
6607{
6608 struct symtabs_and_lines sals;
6609 if (string == 0)
6610 error ("Empty line specification.");
6611 if (default_breakpoint_valid)
6612 sals = decode_line_1 (&string, funfirstline,
53a5351d
JM
6613 default_breakpoint_symtab,
6614 default_breakpoint_line,
c5aa993b 6615 (char ***) NULL);
c906108c
SS
6616 else
6617 sals = decode_line_1 (&string, funfirstline,
c5aa993b 6618 (struct symtab *) NULL, 0, (char ***) NULL);
c906108c
SS
6619 if (*string)
6620 error ("Junk at end of line specification: %s", string);
6621 return sals;
6622}
6623\f
6624void
6625_initialize_breakpoint ()
6626{
6627 struct cmd_list_element *c;
6628
6629 breakpoint_chain = 0;
6630 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
6631 before a breakpoint is set. */
6632 breakpoint_count = 0;
6633
6634 add_com ("ignore", class_breakpoint, ignore_command,
6635 "Set ignore-count of breakpoint number N to COUNT.\n\
6636Usage is `ignore N COUNT'.");
6637 if (xdb_commands)
c5aa993b 6638 add_com_alias ("bc", "ignore", class_breakpoint, 1);
c906108c
SS
6639
6640 add_com ("commands", class_breakpoint, commands_command,
6641 "Set commands to be executed when a breakpoint is hit.\n\
6642Give breakpoint number as argument after \"commands\".\n\
6643With no argument, the targeted breakpoint is the last one set.\n\
6644The commands themselves follow starting on the next line.\n\
6645Type a line containing \"end\" to indicate the end of them.\n\
6646Give \"silent\" as the first line to make the breakpoint silent;\n\
6647then no output is printed when it is hit, except what the commands print.");
6648
6649 add_com ("condition", class_breakpoint, condition_command,
6650 "Specify breakpoint number N to break only if COND is true.\n\
6651Usage is `condition N COND', where N is an integer and COND is an\n\
6652expression to be evaluated whenever breakpoint N is reached. ");
6653
6654 add_com ("tbreak", class_breakpoint, tbreak_command,
6655 "Set a temporary breakpoint. Args like \"break\" command.\n\
6656Like \"break\" except the breakpoint is only temporary,\n\
6657so it will be deleted when hit. Equivalent to \"break\" followed\n\
6658by using \"enable delete\" on the breakpoint number.");
c5aa993b
JM
6659 add_com ("txbreak", class_breakpoint, tbreak_at_finish_command,
6660 "Set temporary breakpoint at procedure exit. Either there should\n\
c906108c
SS
6661be no argument or the argument must be a depth.\n");
6662
6663 add_com ("hbreak", class_breakpoint, hbreak_command,
6664 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
6665Like \"break\" except the breakpoint requires hardware support,\n\
6666some target hardware may not have this support.");
6667
6668 add_com ("thbreak", class_breakpoint, thbreak_command,
6669 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
6670Like \"hbreak\" except the breakpoint is only temporary,\n\
6671so it will be deleted when hit.");
6672
6673 add_prefix_cmd ("enable", class_breakpoint, enable_command,
6674 "Enable some breakpoints.\n\
6675Give breakpoint numbers (separated by spaces) as arguments.\n\
6676With no subcommand, breakpoints are enabled until you command otherwise.\n\
6677This is used to cancel the effect of the \"disable\" command.\n\
6678With a subcommand you can enable temporarily.",
6679 &enablelist, "enable ", 1, &cmdlist);
6680 if (xdb_commands)
c5aa993b
JM
6681 add_com ("ab", class_breakpoint, enable_command,
6682 "Enable some breakpoints.\n\
c906108c
SS
6683Give breakpoint numbers (separated by spaces) as arguments.\n\
6684With no subcommand, breakpoints are enabled until you command otherwise.\n\
6685This is used to cancel the effect of the \"disable\" command.\n\
6686With a subcommand you can enable temporarily.");
6687
6688 add_com_alias ("en", "enable", class_breakpoint, 1);
6689
6690 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
c5aa993b 6691 "Enable some breakpoints.\n\
c906108c
SS
6692Give breakpoint numbers (separated by spaces) as arguments.\n\
6693This is used to cancel the effect of the \"disable\" command.\n\
6694May be abbreviated to simply \"enable\".\n",
c5aa993b 6695 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
c906108c
SS
6696
6697 add_cmd ("once", no_class, enable_once_command,
6698 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
6699If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
6700 &enablebreaklist);
6701
6702 add_cmd ("delete", no_class, enable_delete_command,
6703 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
6704If a breakpoint is hit while enabled in this fashion, it is deleted.",
6705 &enablebreaklist);
6706
6707 add_cmd ("delete", no_class, enable_delete_command,
6708 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
6709If a breakpoint is hit while enabled in this fashion, it is deleted.",
6710 &enablelist);
6711
6712 add_cmd ("once", no_class, enable_once_command,
6713 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
6714If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
6715 &enablelist);
6716
6717 add_prefix_cmd ("disable", class_breakpoint, disable_command,
c5aa993b 6718 "Disable some breakpoints.\n\
c906108c
SS
6719Arguments are breakpoint numbers with spaces in between.\n\
6720To disable all breakpoints, give no argument.\n\
6721A disabled breakpoint is not forgotten, but has no effect until reenabled.",
6722 &disablelist, "disable ", 1, &cmdlist);
6723 add_com_alias ("dis", "disable", class_breakpoint, 1);
6724 add_com_alias ("disa", "disable", class_breakpoint, 1);
6725 if (xdb_commands)
c5aa993b
JM
6726 add_com ("sb", class_breakpoint, disable_command,
6727 "Disable some breakpoints.\n\
c906108c
SS
6728Arguments are breakpoint numbers with spaces in between.\n\
6729To disable all breakpoints, give no argument.\n\
6730A disabled breakpoint is not forgotten, but has no effect until reenabled.");
6731
6732 add_cmd ("breakpoints", class_alias, disable_command,
6733 "Disable some breakpoints.\n\
6734Arguments are breakpoint numbers with spaces in between.\n\
6735To disable all breakpoints, give no argument.\n\
6736A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
6737This command may be abbreviated \"disable\".",
6738 &disablelist);
6739
6740 add_prefix_cmd ("delete", class_breakpoint, delete_command,
c5aa993b 6741 "Delete some breakpoints or auto-display expressions.\n\
c906108c
SS
6742Arguments are breakpoint numbers with spaces in between.\n\
6743To delete all breakpoints, give no argument.\n\
6744\n\
6745Also a prefix command for deletion of other GDB objects.\n\
6746The \"unset\" command is also an alias for \"delete\".",
6747 &deletelist, "delete ", 1, &cmdlist);
6748 add_com_alias ("d", "delete", class_breakpoint, 1);
6749 if (xdb_commands)
6750 add_com ("db", class_breakpoint, delete_command,
c5aa993b 6751 "Delete some breakpoints.\n\
c906108c
SS
6752Arguments are breakpoint numbers with spaces in between.\n\
6753To delete all breakpoints, give no argument.\n");
6754
6755 add_cmd ("breakpoints", class_alias, delete_command,
6756 "Delete some breakpoints or auto-display expressions.\n\
6757Arguments are breakpoint numbers with spaces in between.\n\
6758To delete all breakpoints, give no argument.\n\
6759This command may be abbreviated \"delete\".",
6760 &deletelist);
6761
6762 add_com ("clear", class_breakpoint, clear_command,
6763 concat ("Clear breakpoint at specified line or function.\n\
6764Argument may be line number, function name, or \"*\" and an address.\n\
6765If line number is specified, all breakpoints in that line are cleared.\n\
6766If function is specified, breakpoints at beginning of function are cleared.\n\
6767If an address is specified, breakpoints at that address are cleared.\n\n",
c5aa993b 6768 "With no argument, clears all breakpoints in the line that the selected frame\n\
c906108c
SS
6769is executing in.\n\
6770\n\
6771See also the \"delete\" command which clears breakpoints by number.", NULL));
6772
6773 add_com ("break", class_breakpoint, break_command,
6774 concat ("Set breakpoint at specified line or function.\n\
6775Argument may be line number, function name, or \"*\" and an address.\n\
6776If line number is specified, break at start of code for that line.\n\
6777If function is specified, break at start of code for that function.\n\
6778If an address is specified, break at that exact address.\n",
c5aa993b 6779 "With no arg, uses current execution address of selected stack frame.\n\
c906108c
SS
6780This is useful for breaking on return to a stack frame.\n\
6781\n\
6782Multiple breakpoints at one place are permitted, and useful if conditional.\n\
6783\n\
6784Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
6785 add_com_alias ("b", "break", class_run, 1);
6786 add_com_alias ("br", "break", class_run, 1);
6787 add_com_alias ("bre", "break", class_run, 1);
6788 add_com_alias ("brea", "break", class_run, 1);
6789
c5aa993b
JM
6790 add_com ("xbreak", class_breakpoint, break_at_finish_command,
6791 concat ("Set breakpoint at procedure exit. \n\
c906108c
SS
6792Argument may be function name, or \"*\" and an address.\n\
6793If function is specified, break at end of code for that function.\n\
6794If an address is specified, break at the end of the function that contains \n\
6795that exact address.\n",
c5aa993b 6796 "With no arg, uses current execution address of selected stack frame.\n\
c906108c
SS
6797This is useful for breaking on return to a stack frame.\n\
6798\n\
6799Multiple breakpoints at one place are permitted, and useful if conditional.\n\
6800\n\
6801Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
6802 add_com_alias ("xb", "xbreak", class_breakpoint, 1);
6803 add_com_alias ("xbr", "xbreak", class_breakpoint, 1);
6804 add_com_alias ("xbre", "xbreak", class_breakpoint, 1);
6805 add_com_alias ("xbrea", "xbreak", class_breakpoint, 1);
6806
6807 if (xdb_commands)
6808 {
6809 add_com_alias ("ba", "break", class_breakpoint, 1);
6810 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
6811 add_com ("bx", class_breakpoint, break_at_finish_at_depth_command,
c5aa993b 6812 "Set breakpoint at procedure exit. Either there should\n\
c906108c
SS
6813be no argument or the argument must be a depth.\n");
6814 }
6815
6816 if (dbx_commands)
6817 {
c5aa993b
JM
6818 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
6819 "Break in function/address or break at a line in the current file.",
6820 &stoplist, "stop ", 1, &cmdlist);
6821 add_cmd ("in", class_breakpoint, stopin_command,
6822 "Break in function or address.\n", &stoplist);
6823 add_cmd ("at", class_breakpoint, stopat_command,
6824 "Break at a line in the current file.\n", &stoplist);
6825 add_com ("status", class_info, breakpoints_info,
6826 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
6827The \"Type\" column indicates one of:\n\
6828\tbreakpoint - normal breakpoint\n\
6829\twatchpoint - watchpoint\n\
6830The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6831the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6832breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6833address and file/line number respectively.\n\n",
c5aa993b 6834 "Convenience variable \"$_\" and default examine address for \"x\"\n\
c906108c
SS
6835are set to the address of the last breakpoint listed.\n\n\
6836Convenience variable \"$bpnum\" contains the number of the last\n\
6837breakpoint set.", NULL));
6838 }
6839
6840 add_info ("breakpoints", breakpoints_info,
6841 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
6842The \"Type\" column indicates one of:\n\
6843\tbreakpoint - normal breakpoint\n\
6844\twatchpoint - watchpoint\n\
6845The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6846the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6847breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6848address and file/line number respectively.\n\n",
c5aa993b 6849 "Convenience variable \"$_\" and default examine address for \"x\"\n\
c906108c
SS
6850are set to the address of the last breakpoint listed.\n\n\
6851Convenience variable \"$bpnum\" contains the number of the last\n\
6852breakpoint set.", NULL));
6853
6854 if (xdb_commands)
c5aa993b
JM
6855 add_com ("lb", class_breakpoint, breakpoints_info,
6856 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
6857The \"Type\" column indicates one of:\n\
6858\tbreakpoint - normal breakpoint\n\
6859\twatchpoint - watchpoint\n\
6860The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6861the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6862breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6863address and file/line number respectively.\n\n",
c5aa993b 6864 "Convenience variable \"$_\" and default examine address for \"x\"\n\
c906108c
SS
6865are set to the address of the last breakpoint listed.\n\n\
6866Convenience variable \"$bpnum\" contains the number of the last\n\
6867breakpoint set.", NULL));
6868
c906108c 6869 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
c5aa993b 6870 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
6871The \"Type\" column indicates one of:\n\
6872\tbreakpoint - normal breakpoint\n\
6873\twatchpoint - watchpoint\n\
6874\tlongjmp - internal breakpoint used to step through longjmp()\n\
6875\tlongjmp resume - internal breakpoint at the target of longjmp()\n\
6876\tuntil - internal breakpoint used by the \"until\" command\n\
6877\tfinish - internal breakpoint used by the \"finish\" command\n",
c5aa993b 6878 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
c906108c
SS
6879the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6880breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6881address and file/line number respectively.\n\n",
c5aa993b 6882 "Convenience variable \"$_\" and default examine address for \"x\"\n\
c906108c
SS
6883are set to the address of the last breakpoint listed.\n\n\
6884Convenience variable \"$bpnum\" contains the number of the last\n\
6885breakpoint set.", NULL),
6886 &maintenanceinfolist);
6887
c906108c 6888 add_com ("catch", class_breakpoint, catch_command,
c5aa993b 6889 "Set catchpoints to catch events.\n\
c906108c
SS
6890Raised signals may be caught:\n\
6891\tcatch signal - all signals\n\
6892\tcatch signal <signame> - a particular signal\n\
6893Raised exceptions may be caught:\n\
6894\tcatch throw - all exceptions, when thrown\n\
6895\tcatch throw <exceptname> - a particular exception, when thrown\n\
6896\tcatch catch - all exceptions, when caught\n\
6897\tcatch catch <exceptname> - a particular exception, when caught\n\
6898Thread or process events may be caught:\n\
6899\tcatch thread_start - any threads, just after creation\n\
6900\tcatch thread_exit - any threads, just before expiration\n\
6901\tcatch thread_join - any threads, just after joins\n\
6902Process events may be caught:\n\
6903\tcatch start - any processes, just after creation\n\
6904\tcatch exit - any processes, just before expiration\n\
6905\tcatch fork - calls to fork()\n\
6906\tcatch vfork - calls to vfork()\n\
6907\tcatch exec - calls to exec()\n\
6908Dynamically-linked library events may be caught:\n\
6909\tcatch load - loads of any library\n\
6910\tcatch load <libname> - loads of a particular library\n\
6911\tcatch unload - unloads of any library\n\
6912\tcatch unload <libname> - unloads of a particular library\n\
6913The act of your program's execution stopping may also be caught:\n\
6914\tcatch stop\n\n\
6915C++ exceptions may be caught:\n\
6916\tcatch throw - all exceptions, when thrown\n\
6917\tcatch catch - all exceptions, when caught\n\
6918\n\
6919Do \"help set follow-fork-mode\" for info on debugging your program\n\
6920after a fork or vfork is caught.\n\n\
6921Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
c5aa993b 6922
c906108c 6923 add_com ("tcatch", class_breakpoint, tcatch_command,
c5aa993b 6924 "Set temporary catchpoints to catch events.\n\
c906108c
SS
6925Args like \"catch\" command.\n\
6926Like \"catch\" except the catchpoint is only temporary,\n\
6927so it will be deleted when hit. Equivalent to \"catch\" followed\n\
6928by using \"enable delete\" on the catchpoint number.");
c5aa993b
JM
6929
6930 add_com ("watch", class_breakpoint, watch_command,
c906108c
SS
6931 "Set a watchpoint for an expression.\n\
6932A watchpoint stops execution of your program whenever the value of\n\
6933an expression changes.");
6934
6935 add_com ("rwatch", class_breakpoint, rwatch_command,
6936 "Set a read watchpoint for an expression.\n\
6937A watchpoint stops execution of your program whenever the value of\n\
6938an expression is read.");
6939
6940 add_com ("awatch", class_breakpoint, awatch_command,
6941 "Set a watchpoint for an expression.\n\
6942A watchpoint stops execution of your program whenever the value of\n\
6943an expression is either read or written.");
6944
6945 add_info ("watchpoints", breakpoints_info,
6946 "Synonym for ``info breakpoints''.");
6947
6948
6949 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
c5aa993b
JM
6950 (char *) &can_use_hw_watchpoints,
6951 "Set debugger's willingness to use watchpoint hardware.\n\
c906108c
SS
6952If zero, gdb will not use hardware for new watchpoints, even if\n\
6953such is available. (However, any hardware watchpoints that were\n\
6954created before setting this to nonzero, will continue to use watchpoint\n\
6955hardware.)",
c5aa993b 6956 &setlist);
c906108c
SS
6957 add_show_from_set (c, &showlist);
6958
6959 can_use_hw_watchpoints = 1;
6960}