]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/breakpoint.c
Only support interworking and pic for ELF or COFF targets
[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 symtab_and_line sal;
3419 struct cleanup *old_chain;
3420 struct cleanup *canonical_strings_chain = NULL;
3421 int i;
3422 char *addr_start = hookname;
3423 char *addr_end = NULL;
3424 char **canonical = (char **) NULL;
3425 int thread = -1; /* All threads. */
3426
c906108c
SS
3427 /* Set a breakpoint on the specified hook. */
3428 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
3429 addr_end = hookname;
c5aa993b 3430
c906108c
SS
3431 if (sals.nelts == 0)
3432 {
3433 warning ("Unable to set a breakpoint on dynamic linker callback.");
3434 warning ("Suggest linking with /opt/langtools/lib/end.o.");
3435 warning ("GDB will be unable to track shl_load/shl_unload calls");
3436 return;
3437 }
3438 if (sals.nelts != 1)
3439 {
53a5351d 3440 warning ("Unable to set unique breakpoint on dynamic linker callback.");
c906108c
SS
3441 warning ("GDB will be unable to track shl_load/shl_unload calls");
3442 return;
3443 }
3444
53a5351d
JM
3445 /* Make sure that all storage allocated in decode_line_1 gets freed
3446 in case the following errors out. */
c906108c 3447 old_chain = make_cleanup (free, sals.sals);
c5aa993b 3448 if (canonical != (char **) NULL)
c906108c
SS
3449 {
3450 make_cleanup (free, canonical);
3451 canonical_strings_chain = make_cleanup (null_cleanup, 0);
3452 if (canonical[0] != NULL)
c5aa993b 3453 make_cleanup (free, canonical[0]);
c906108c 3454 }
c5aa993b 3455
c906108c 3456 resolve_sal_pc (&sals.sals[0]);
c5aa993b 3457
c906108c 3458 /* Remove the canonical strings from the cleanup, they are needed below. */
c5aa993b 3459 if (canonical != (char **) NULL)
c906108c 3460 discard_cleanups (canonical_strings_chain);
c5aa993b 3461
c906108c
SS
3462 b = set_raw_breakpoint (sals.sals[0]);
3463 set_breakpoint_count (breakpoint_count + 1);
3464 b->number = breakpoint_count;
3465 b->cond = NULL;
53a5351d
JM
3466 b->cond_string = (cond_string == NULL) ?
3467 NULL : savestring (cond_string, strlen (cond_string));
c906108c 3468 b->thread = thread;
c5aa993b
JM
3469
3470 if (canonical != (char **) NULL && canonical[0] != NULL)
c906108c
SS
3471 b->addr_string = canonical[0];
3472 else if (addr_start)
3473 b->addr_string = savestring (addr_start, addr_end - addr_start);
c5aa993b 3474
c906108c
SS
3475 b->enable = enabled;
3476 b->disposition = tempflag ? del : donttouch;
c5aa993b 3477
c906108c
SS
3478 if (dll_pathname == NULL)
3479 b->dll_pathname = NULL;
3480 else
3481 {
3482 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
3483 strcpy (b->dll_pathname, dll_pathname);
3484 }
3485 b->type = bp_kind;
c5aa993b 3486
c906108c
SS
3487 mention (b);
3488 do_cleanups (old_chain);
3489}
3490
3491void
53a5351d
JM
3492create_solib_load_event_breakpoint (hookname, tempflag,
3493 dll_pathname, cond_string)
c5aa993b
JM
3494 char *hookname;
3495 int tempflag;
3496 char *dll_pathname;
3497 char *cond_string;
c906108c 3498{
53a5351d
JM
3499 solib_load_unload_1 (hookname, tempflag, dll_pathname,
3500 cond_string, bp_catch_load);
c906108c
SS
3501}
3502
3503void
53a5351d
JM
3504create_solib_unload_event_breakpoint (hookname, tempflag,
3505 dll_pathname, cond_string)
c5aa993b
JM
3506 char *hookname;
3507 int tempflag;
3508 char *dll_pathname;
3509 char *cond_string;
c906108c 3510{
53a5351d
JM
3511 solib_load_unload_1 (hookname,tempflag, dll_pathname,
3512 cond_string, bp_catch_unload);
c906108c
SS
3513}
3514
3515static void
3516create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_kind)
7a292a7a
SS
3517 int tempflag;
3518 char *cond_string;
3519 enum bptype bp_kind;
c906108c 3520{
c5aa993b
JM
3521 struct symtab_and_line sal;
3522 struct breakpoint *b;
3523 int thread = -1; /* All threads. */
3524
3525 INIT_SAL (&sal);
c906108c
SS
3526 sal.pc = 0;
3527 sal.symtab = NULL;
3528 sal.line = 0;
c5aa993b 3529
c906108c
SS
3530 b = set_raw_breakpoint (sal);
3531 set_breakpoint_count (breakpoint_count + 1);
3532 b->number = breakpoint_count;
3533 b->cond = NULL;
53a5351d
JM
3534 b->cond_string = (cond_string == NULL) ?
3535 NULL : savestring (cond_string, strlen (cond_string));
c906108c
SS
3536 b->thread = thread;
3537 b->addr_string = NULL;
3538 b->enable = enabled;
3539 b->disposition = tempflag ? del : donttouch;
3540 b->forked_inferior_pid = 0;
c5aa993b 3541
c906108c 3542 b->type = bp_kind;
c5aa993b 3543
c906108c
SS
3544 mention (b);
3545}
3546
3547void
3548create_fork_event_catchpoint (tempflag, cond_string)
c5aa993b
JM
3549 int tempflag;
3550 char *cond_string;
c906108c
SS
3551{
3552 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
3553}
c5aa993b 3554
c906108c
SS
3555void
3556create_vfork_event_catchpoint (tempflag, cond_string)
c5aa993b
JM
3557 int tempflag;
3558 char *cond_string;
c906108c
SS
3559{
3560 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
3561}
3562
3563void
3564create_exec_event_catchpoint (tempflag, cond_string)
c5aa993b
JM
3565 int tempflag;
3566 char *cond_string;
c906108c 3567{
c5aa993b
JM
3568 struct symtab_and_line sal;
3569 struct breakpoint *b;
3570 int thread = -1; /* All threads. */
c906108c 3571
c5aa993b 3572 INIT_SAL (&sal);
c906108c
SS
3573 sal.pc = 0;
3574 sal.symtab = NULL;
3575 sal.line = 0;
3576
3577 b = set_raw_breakpoint (sal);
3578 set_breakpoint_count (breakpoint_count + 1);
3579 b->number = breakpoint_count;
3580 b->cond = NULL;
53a5351d
JM
3581 b->cond_string = (cond_string == NULL) ?
3582 NULL : savestring (cond_string, strlen (cond_string));
c906108c
SS
3583 b->thread = thread;
3584 b->addr_string = NULL;
3585 b->enable = enabled;
3586 b->disposition = tempflag ? del : donttouch;
3587
3588 b->type = bp_catch_exec;
3589
3590 mention (b);
3591}
3592
3593static int
c5aa993b 3594hw_breakpoint_used_count ()
c906108c
SS
3595{
3596 register struct breakpoint *b;
3597 int i = 0;
3598
3599 ALL_BREAKPOINTS (b)
c5aa993b
JM
3600 {
3601 if (b->type == bp_hardware_breakpoint && b->enable == enabled)
3602 i++;
3603 }
c906108c
SS
3604
3605 return i;
3606}
3607
3608static int
c5aa993b
JM
3609hw_watchpoint_used_count (type, other_type_used)
3610 enum bptype type;
3611 int *other_type_used;
c906108c
SS
3612{
3613 register struct breakpoint *b;
3614 int i = 0;
3615
3616 *other_type_used = 0;
3617 ALL_BREAKPOINTS (b)
c5aa993b
JM
3618 {
3619 if (b->enable == enabled)
3620 {
3621 if (b->type == type)
3622 i++;
3623 else if ((b->type == bp_hardware_watchpoint ||
3624 b->type == bp_read_watchpoint ||
3625 b->type == bp_access_watchpoint)
3626 && b->enable == enabled)
3627 *other_type_used = 1;
3628 }
3629 }
c906108c
SS
3630 return i;
3631}
3632
53a5351d
JM
3633/* Call this after hitting the longjmp() breakpoint. Use this to set
3634 a new breakpoint at the target of the jmp_buf.
c906108c 3635
53a5351d
JM
3636 FIXME - This ought to be done by setting a temporary breakpoint
3637 that gets deleted automatically... */
c906108c
SS
3638
3639void
c5aa993b 3640set_longjmp_resume_breakpoint (pc, frame)
c906108c
SS
3641 CORE_ADDR pc;
3642 struct frame_info *frame;
3643{
3644 register struct breakpoint *b;
3645
3646 ALL_BREAKPOINTS (b)
3647 if (b->type == bp_longjmp_resume)
c5aa993b
JM
3648 {
3649 b->address = pc;
3650 b->enable = enabled;
3651 if (frame != NULL)
3652 b->frame = frame->frame;
3653 else
3654 b->frame = 0;
3655 check_duplicates (b->address, b->section);
3656 return;
3657 }
c906108c
SS
3658}
3659
3660void
3661disable_watchpoints_before_interactive_call_start ()
3662{
c5aa993b 3663 struct breakpoint *b;
c906108c
SS
3664
3665 ALL_BREAKPOINTS (b)
c5aa993b
JM
3666 {
3667 if (((b->type == bp_watchpoint)
3668 || (b->type == bp_hardware_watchpoint)
3669 || (b->type == bp_read_watchpoint)
3670 || (b->type == bp_access_watchpoint)
3671 || ep_is_exception_catchpoint (b))
3672 && (b->enable == enabled))
3673 {
3674 b->enable = call_disabled;
3675 check_duplicates (b->address, b->section);
3676 }
3677 }
c906108c
SS
3678}
3679
3680void
3681enable_watchpoints_after_interactive_call_stop ()
3682{
c5aa993b 3683 struct breakpoint *b;
c906108c
SS
3684
3685 ALL_BREAKPOINTS (b)
c5aa993b
JM
3686 {
3687 if (((b->type == bp_watchpoint)
3688 || (b->type == bp_hardware_watchpoint)
3689 || (b->type == bp_read_watchpoint)
3690 || (b->type == bp_access_watchpoint)
3691 || ep_is_exception_catchpoint (b))
3692 && (b->enable == call_disabled))
3693 {
3694 b->enable = enabled;
3695 check_duplicates (b->address, b->section);
3696 }
3697 }
c906108c
SS
3698}
3699
3700
3701/* Set a breakpoint that will evaporate an end of command
3702 at address specified by SAL.
3703 Restrict it to frame FRAME if FRAME is nonzero. */
3704
3705struct breakpoint *
3706set_momentary_breakpoint (sal, frame, type)
3707 struct symtab_and_line sal;
3708 struct frame_info *frame;
3709 enum bptype type;
3710{
3711 register struct breakpoint *b;
3712 b = set_raw_breakpoint (sal);
3713 b->type = type;
3714 b->enable = enabled;
3715 b->disposition = donttouch;
3716 b->frame = (frame ? frame->frame : 0);
3717
3718 /* If we're debugging a multi-threaded program, then we
3719 want momentary breakpoints to be active in only a
3720 single thread of control. */
3721 if (in_thread_list (inferior_pid))
3722 b->thread = pid_to_thread_id (inferior_pid);
3723
3724 return b;
3725}
c906108c 3726\f
c5aa993b 3727
c906108c
SS
3728/* Tell the user we have just set a breakpoint B. */
3729
3730static void
3731mention (b)
3732 struct breakpoint *b;
3733{
3734 int say_where = 0;
3735
3736 /* FIXME: This is misplaced; mention() is called by things (like hitting a
3737 watchpoint) other than breakpoint creation. It should be possible to
3738 clean this up and at the same time replace the random calls to
3739 breakpoint_changed with this hook, as has already been done for
3740 delete_breakpoint_hook and so on. */
3741 if (create_breakpoint_hook)
3742 create_breakpoint_hook (b);
104c1213 3743 breakpoint_create_event (b->number);
c906108c
SS
3744
3745 switch (b->type)
3746 {
3747 case bp_none:
3748 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
3749 break;
3750 case bp_watchpoint:
3751 printf_filtered ("Watchpoint %d: ", b->number);
3752 print_expression (b->exp, gdb_stdout);
3753 break;
3754 case bp_hardware_watchpoint:
3755 printf_filtered ("Hardware watchpoint %d: ", b->number);
3756 print_expression (b->exp, gdb_stdout);
3757 break;
3758 case bp_read_watchpoint:
3759 printf_filtered ("Hardware read watchpoint %d: ", b->number);
3760 print_expression (b->exp, gdb_stdout);
3761 break;
3762 case bp_access_watchpoint:
53a5351d
JM
3763 printf_filtered ("Hardware access (read/write) watchpoint %d: ",
3764 b->number);
c906108c
SS
3765 print_expression (b->exp, gdb_stdout);
3766 break;
3767 case bp_breakpoint:
3768 printf_filtered ("Breakpoint %d", b->number);
3769 say_where = 1;
3770 break;
3771 case bp_hardware_breakpoint:
3772 printf_filtered ("Hardware assisted breakpoint %d", b->number);
3773 say_where = 1;
3774 break;
3775 case bp_catch_load:
3776 case bp_catch_unload:
3777 printf_filtered ("Catchpoint %d (%s %s)",
c5aa993b
JM
3778 b->number,
3779 (b->type == bp_catch_load) ? "load" : "unload",
53a5351d
JM
3780 (b->dll_pathname != NULL) ?
3781 b->dll_pathname : "<any library>");
c906108c
SS
3782 break;
3783 case bp_catch_fork:
3784 case bp_catch_vfork:
3785 printf_filtered ("Catchpoint %d (%s)",
c5aa993b
JM
3786 b->number,
3787 (b->type == bp_catch_fork) ? "fork" : "vfork");
c906108c
SS
3788 break;
3789 case bp_catch_exec:
3790 printf_filtered ("Catchpoint %d (exec)",
c5aa993b 3791 b->number);
c906108c
SS
3792 break;
3793 case bp_catch_catch:
3794 case bp_catch_throw:
3795 printf_filtered ("Catchpoint %d (%s)",
c5aa993b
JM
3796 b->number,
3797 (b->type == bp_catch_catch) ? "catch" : "throw");
c906108c
SS
3798 break;
3799
3800 case bp_until:
3801 case bp_finish:
3802 case bp_longjmp:
3803 case bp_longjmp_resume:
3804 case bp_step_resume:
3805 case bp_through_sigtramp:
3806 case bp_call_dummy:
3807 case bp_watchpoint_scope:
3808 case bp_shlib_event:
3809 break;
3810 }
3811 if (say_where)
3812 {
3813 if (addressprint || b->source_file == NULL)
3814 {
3815 printf_filtered (" at ");
3816 print_address_numeric (b->address, 1, gdb_stdout);
3817 }
3818 if (b->source_file)
3819 printf_filtered (": file %s, line %d.",
3820 b->source_file, b->line_number);
c5aa993b
JM
3821 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, b, 1));
3822 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
c906108c
SS
3823 }
3824 printf_filtered ("\n");
3825}
c906108c 3826\f
c5aa993b 3827
c906108c
SS
3828/* Set a breakpoint according to ARG (function, linenum or *address)
3829 flag: first bit : 0 non-temporary, 1 temporary.
c5aa993b 3830 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
c906108c
SS
3831
3832static void
3833break_command_1 (arg, flag, from_tty)
3834 char *arg;
3835 int flag, from_tty;
3836{
3837 int tempflag, hardwareflag;
3838 struct symtabs_and_lines sals;
3839 struct symtab_and_line sal;
3840 register struct expression *cond = 0;
3841 register struct breakpoint *b;
3842
3843 /* Pointers in arg to the start, and one past the end, of the condition. */
3844 char *cond_start = NULL;
3845 char *cond_end = NULL;
3846 /* Pointers in arg to the start, and one past the end,
3847 of the address part. */
3848 char *addr_start = NULL;
3849 char *addr_end = NULL;
3850 struct cleanup *old_chain;
3851 struct cleanup *canonical_strings_chain = NULL;
c5aa993b 3852 char **canonical = (char **) NULL;
c906108c
SS
3853 int i;
3854 int thread;
3855
3856 hardwareflag = flag & BP_HARDWAREFLAG;
3857 tempflag = flag & BP_TEMPFLAG;
3858
3859 sals.sals = NULL;
3860 sals.nelts = 0;
3861
c5aa993b 3862 INIT_SAL (&sal); /* initialize to zeroes */
c906108c
SS
3863
3864 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
3865
c5aa993b 3866 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
c906108c
SS
3867 && (arg[2] == ' ' || arg[2] == '\t')))
3868 {
3869 if (default_breakpoint_valid)
3870 {
c5aa993b 3871 sals.sals = (struct symtab_and_line *)
c906108c
SS
3872 xmalloc (sizeof (struct symtab_and_line));
3873 sal.pc = default_breakpoint_address;
3874 sal.line = default_breakpoint_line;
3875 sal.symtab = default_breakpoint_symtab;
c5aa993b 3876 sal.section = find_pc_overlay (sal.pc);
c906108c
SS
3877 sals.sals[0] = sal;
3878 sals.nelts = 1;
3879 }
3880 else
3881 error ("No default breakpoint address now.");
3882 }
3883 else
3884 {
3885 addr_start = arg;
3886
3887 /* Force almost all breakpoints to be in terms of the
c5aa993b
JM
3888 current_source_symtab (which is decode_line_1's default). This
3889 should produce the results we want almost all of the time while
3890 leaving default_breakpoint_* alone. */
c906108c
SS
3891 if (default_breakpoint_valid
3892 && (!current_source_symtab
3893 || (arg && (*arg == '+' || *arg == '-'))))
3894 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
3895 default_breakpoint_line, &canonical);
3896 else
c5aa993b 3897 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, &canonical);
c906108c
SS
3898
3899 addr_end = arg;
3900 }
c5aa993b
JM
3901
3902 if (!sals.nelts)
c906108c
SS
3903 return;
3904
53a5351d
JM
3905 /* Make sure that all storage allocated in decode_line_1 gets freed
3906 in case the following `for' loop errors out. */
c906108c 3907 old_chain = make_cleanup (free, sals.sals);
c5aa993b 3908 if (canonical != (char **) NULL)
c906108c
SS
3909 {
3910 make_cleanup (free, canonical);
3911 canonical_strings_chain = make_cleanup (null_cleanup, 0);
3912 for (i = 0; i < sals.nelts; i++)
3913 {
3914 if (canonical[i] != NULL)
3915 make_cleanup (free, canonical[i]);
3916 }
3917 }
3918
3919 thread = -1; /* No specific thread yet */
3920
3921 /* Resolve all line numbers to PC's, and verify that conditions
3922 can be parsed, before setting any breakpoints. */
3923 for (i = 0; i < sals.nelts; i++)
3924 {
3925 char *tok, *end_tok;
3926 int toklen;
3927
3928 resolve_sal_pc (&sals.sals[i]);
3929
3930 /* It's possible for the PC to be nonzero, but still an illegal
3931 value on some targets.
3932
3933 For example, on HP-UX if you start gdb, and before running the
3934 inferior you try to set a breakpoint on a shared library function
3935 "foo" where the inferior doesn't call "foo" directly but does
3936 pass its address to another function call, then we do find a
3937 minimal symbol for the "foo", but it's address is invalid.
3938 (Appears to be an index into a table that the loader sets up
3939 when the inferior is run.)
3940
3941 Give the target a chance to bless sals.sals[i].pc before we
3942 try to make a breakpoint for it. */
c5aa993b
JM
3943 if (PC_REQUIRES_RUN_BEFORE_USE (sals.sals[i].pc))
3944 {
53a5351d
JM
3945 error ("Cannot break on %s without a running program.",
3946 addr_start);
c5aa993b
JM
3947 }
3948
c906108c
SS
3949 tok = arg;
3950
3951 while (tok && *tok)
3952 {
3953 while (*tok == ' ' || *tok == '\t')
3954 tok++;
3955
3956 end_tok = tok;
3957
3958 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
3959 end_tok++;
3960
3961 toklen = end_tok - tok;
3962
3963 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
3964 {
3965 tok = cond_start = end_tok + 1;
3966 cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
3967 cond_end = tok;
3968 }
3969 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
3970 {
3971 char *tmptok;
3972
3973 tok = end_tok + 1;
3974 tmptok = tok;
3975 thread = strtol (tok, &tok, 0);
3976 if (tok == tmptok)
3977 error ("Junk after thread keyword.");
3978 if (!valid_thread_id (thread))
3979 error ("Unknown thread %d\n", thread);
3980 }
3981 else
3982 error ("Junk at end of arguments.");
3983 }
3984 }
3985 if (hardwareflag)
3986 {
3987 int i, target_resources_ok;
3988
c5aa993b 3989 i = hw_breakpoint_used_count ();
53a5351d
JM
3990 target_resources_ok =
3991 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
3992 i + sals.nelts, 0);
c906108c
SS
3993 if (target_resources_ok == 0)
3994 error ("No hardware breakpoint support in the target.");
3995 else if (target_resources_ok < 0)
c5aa993b 3996 error ("Hardware breakpoints used exceeds limit.");
c906108c
SS
3997 }
3998
3999 /* Remove the canonical strings from the cleanup, they are needed below. */
c5aa993b 4000 if (canonical != (char **) NULL)
c906108c
SS
4001 discard_cleanups (canonical_strings_chain);
4002
4003 /* Now set all the breakpoints. */
4004 for (i = 0; i < sals.nelts; i++)
4005 {
4006 sal = sals.sals[i];
4007
4008 if (from_tty)
4009 describe_other_breakpoints (sal.pc, sal.section);
4010
4011 b = set_raw_breakpoint (sal);
4012 set_breakpoint_count (breakpoint_count + 1);
4013 b->number = breakpoint_count;
4014 b->type = hardwareflag ? bp_hardware_breakpoint : bp_breakpoint;
4015 b->cond = cond;
4016 b->thread = thread;
4017
4018 /* If a canonical line spec is needed use that instead of the
c5aa993b
JM
4019 command string. */
4020 if (canonical != (char **) NULL && canonical[i] != NULL)
c906108c
SS
4021 b->addr_string = canonical[i];
4022 else if (addr_start)
4023 b->addr_string = savestring (addr_start, addr_end - addr_start);
4024 if (cond_start)
4025 b->cond_string = savestring (cond_start, cond_end - cond_start);
c5aa993b 4026
c906108c
SS
4027 b->enable = enabled;
4028 b->disposition = tempflag ? del : donttouch;
4029 mention (b);
4030 }
4031
4032 if (sals.nelts > 1)
4033 {
53a5351d
JM
4034 warning ("Multiple breakpoints were set.");
4035 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
c906108c
SS
4036 }
4037 do_cleanups (old_chain);
4038}
4039
4040static void
4041break_at_finish_at_depth_command_1 (arg, flag, from_tty)
4042 char *arg;
4043 int flag;
4044 int from_tty;
4045{
4046 struct frame_info *frame;
4047 CORE_ADDR low, high, selected_pc = 0;
4048 char *extra_args, *level_arg, *addr_string;
4049 int extra_args_len = 0, if_arg = 0;
4050
4051 if (!arg ||
4052 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4053 {
4054
4055 if (default_breakpoint_valid)
4056 {
4057 if (selected_frame)
4058 {
4059 selected_pc = selected_frame->pc;
4060 if (arg)
4061 if_arg = 1;
4062 }
4063 else
4064 error ("No selected frame.");
4065 }
4066 else
4067 error ("No default breakpoint address now.");
4068 }
4069 else
4070 {
4071 extra_args = strchr (arg, ' ');
4072 if (extra_args)
4073 {
4074 extra_args++;
4075 extra_args_len = strlen (extra_args);
4076 level_arg = (char *) xmalloc (extra_args - arg);
4077 strncpy (level_arg, arg, extra_args - arg - 1);
4078 level_arg[extra_args - arg - 1] = '\0';
4079 }
4080 else
4081 {
4082 level_arg = (char *) xmalloc (strlen (arg) + 1);
4083 strcpy (level_arg, arg);
4084 }
4085
4086 frame = parse_frame_specification (level_arg);
4087 if (frame)
4088 selected_pc = frame->pc;
4089 else
4090 selected_pc = 0;
4091 }
4092 if (if_arg)
4093 {
4094 extra_args = arg;
c5aa993b 4095 extra_args_len = strlen (arg);
c906108c
SS
4096 }
4097
4098 if (selected_pc)
4099 {
c5aa993b 4100 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
c906108c
SS
4101 {
4102 addr_string = (char *) xmalloc (26 + extra_args_len);
4103 if (extra_args_len)
4104 sprintf (addr_string, "*0x%x %s", high, extra_args);
4105 else
4106 sprintf (addr_string, "*0x%x", high);
4107 break_command_1 (addr_string, flag, from_tty);
4108 free (addr_string);
4109 }
4110 else
4111 error ("No function contains the specified address");
4112 }
4113 else
4114 error ("Unable to set breakpoint at procedure exit");
4115}
4116
4117
4118static void
4119break_at_finish_command_1 (arg, flag, from_tty)
4120 char *arg;
4121 int flag;
4122 int from_tty;
4123{
4124 char *addr_string, *break_string, *beg_addr_string;
4125 CORE_ADDR low, high;
4126 struct symtabs_and_lines sals;
4127 struct symtab_and_line sal;
4128 struct cleanup *old_chain;
4129 char *extra_args;
4130 int extra_args_len = 0;
4131 int i, if_arg = 0;
4132
4133 if (!arg ||
4134 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4135 {
4136 if (default_breakpoint_valid)
4137 {
4138 if (selected_frame)
4139 {
4140 addr_string = (char *) xmalloc (15);
4141 sprintf (addr_string, "*0x%x", selected_frame->pc);
4142 if (arg)
4143 if_arg = 1;
4144 }
4145 else
4146 error ("No selected frame.");
4147 }
4148 else
4149 error ("No default breakpoint address now.");
4150 }
4151 else
4152 {
4153 addr_string = (char *) xmalloc (strlen (arg) + 1);
4154 strcpy (addr_string, arg);
4155 }
4156
4157 if (if_arg)
4158 {
4159 extra_args = arg;
c5aa993b
JM
4160 extra_args_len = strlen (arg);
4161 }
4162 else if (arg)
4163 {
4164 /* get the stuff after the function name or address */
4165 extra_args = strchr (arg, ' ');
4166 if (extra_args)
4167 {
4168 extra_args++;
4169 extra_args_len = strlen (extra_args);
4170 }
c906108c 4171 }
c906108c
SS
4172
4173 sals.sals = NULL;
4174 sals.nelts = 0;
4175
c5aa993b
JM
4176 beg_addr_string = addr_string;
4177 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
4178 (char ***) NULL);
c906108c
SS
4179
4180 free (beg_addr_string);
4181 old_chain = make_cleanup (free, sals.sals);
4182 for (i = 0; (i < sals.nelts); i++)
4183 {
4184 sal = sals.sals[i];
c5aa993b 4185 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
c906108c
SS
4186 {
4187 break_string = (char *) xmalloc (extra_args_len + 26);
4188 if (extra_args_len)
4189 sprintf (break_string, "*0x%x %s", high, extra_args);
4190 else
4191 sprintf (break_string, "*0x%x", high);
4192 break_command_1 (break_string, flag, from_tty);
c5aa993b 4193 free (break_string);
c906108c
SS
4194 }
4195 else
4196 error ("No function contains the specified address");
4197 }
4198 if (sals.nelts > 1)
4199 {
53a5351d
JM
4200 warning ("Multiple breakpoints were set.\n");
4201 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
c906108c 4202 }
c5aa993b 4203 do_cleanups (old_chain);
c906108c
SS
4204}
4205
4206
4207/* Helper function for break_command_1 and disassemble_command. */
4208
4209void
4210resolve_sal_pc (sal)
4211 struct symtab_and_line *sal;
4212{
4213 CORE_ADDR pc;
4214
4215 if (sal->pc == 0 && sal->symtab != NULL)
4216 {
4217 if (!find_line_pc (sal->symtab, sal->line, &pc))
4218 error ("No line %d in file \"%s\".",
4219 sal->line, sal->symtab->filename);
4220 sal->pc = pc;
4221 }
4222
4223 if (sal->section == 0 && sal->symtab != NULL)
4224 {
4225 struct blockvector *bv;
c5aa993b
JM
4226 struct block *b;
4227 struct symbol *sym;
4228 int index;
c906108c 4229
c5aa993b 4230 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
c906108c
SS
4231 if (bv != NULL)
4232 {
c5aa993b 4233 b = BLOCKVECTOR_BLOCK (bv, index);
c906108c
SS
4234 sym = block_function (b);
4235 if (sym != NULL)
4236 {
4237 fixup_symbol_section (sym, sal->symtab->objfile);
4238 sal->section = SYMBOL_BFD_SECTION (sym);
4239 }
4240 else
4241 {
4242 /* It really is worthwhile to have the section, so we'll just
c5aa993b
JM
4243 have to look harder. This case can be executed if we have
4244 line numbers but no functions (as can happen in assembly
4245 source). */
c906108c 4246
c5aa993b 4247 struct minimal_symbol *msym;
c906108c
SS
4248
4249 msym = lookup_minimal_symbol_by_pc (sal->pc);
4250 if (msym)
4251 sal->section = SYMBOL_BFD_SECTION (msym);
4252 }
4253 }
4254 }
4255}
4256
4257void
4258break_command (arg, from_tty)
4259 char *arg;
4260 int from_tty;
4261{
4262 break_command_1 (arg, 0, from_tty);
4263}
4264
7a292a7a 4265static void
c906108c
SS
4266break_at_finish_command (arg, from_tty)
4267 char *arg;
4268 int from_tty;
4269{
4270 break_at_finish_command_1 (arg, 0, from_tty);
4271}
4272
7a292a7a 4273static void
c906108c
SS
4274break_at_finish_at_depth_command (arg, from_tty)
4275 char *arg;
4276 int from_tty;
4277{
4278 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
4279}
4280
4281void
4282tbreak_command (arg, from_tty)
4283 char *arg;
4284 int from_tty;
4285{
4286 break_command_1 (arg, BP_TEMPFLAG, from_tty);
4287}
4288
7a292a7a 4289static void
c906108c
SS
4290tbreak_at_finish_command (arg, from_tty)
4291 char *arg;
4292 int from_tty;
4293{
4294 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
4295}
4296
4297static void
4298hbreak_command (arg, from_tty)
4299 char *arg;
4300 int from_tty;
4301{
4302 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
4303}
4304
4305static void
4306thbreak_command (arg, from_tty)
4307 char *arg;
4308 int from_tty;
4309{
4310 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
4311}
4312
4313static void
4314stop_command (arg, from_tty)
4315 char *arg;
4316 int from_tty;
4317{
4318 printf_filtered ("Specify the type of breakpoint to set.\n\
4319Usage: stop in <function | address>\n\
4320 stop at <line>\n");
4321}
4322
4323static void
4324stopin_command (arg, from_tty)
4325 char *arg;
4326 int from_tty;
4327{
4328 int badInput = 0;
4329
c5aa993b 4330 if (arg == (char *) NULL)
c906108c
SS
4331 badInput = 1;
4332 else if (*arg != '*')
4333 {
4334 char *argptr = arg;
4335 int hasColon = 0;
4336
53a5351d
JM
4337 /* look for a ':'. If this is a line number specification, then
4338 say it is bad, otherwise, it should be an address or
4339 function/method name */
c906108c 4340 while (*argptr && !hasColon)
c5aa993b
JM
4341 {
4342 hasColon = (*argptr == ':');
4343 argptr++;
4344 }
c906108c
SS
4345
4346 if (hasColon)
c5aa993b 4347 badInput = (*argptr != ':'); /* Not a class::method */
c906108c 4348 else
c5aa993b 4349 badInput = isdigit (*arg); /* a simple line number */
c906108c
SS
4350 }
4351
4352 if (badInput)
c5aa993b 4353 printf_filtered ("Usage: stop in <function | address>\n");
c906108c
SS
4354 else
4355 break_command_1 (arg, 0, from_tty);
4356}
4357
4358static void
4359stopat_command (arg, from_tty)
4360 char *arg;
4361 int from_tty;
4362{
4363 int badInput = 0;
4364
c5aa993b 4365 if (arg == (char *) NULL || *arg == '*') /* no line number */
c906108c
SS
4366 badInput = 1;
4367 else
4368 {
4369 char *argptr = arg;
4370 int hasColon = 0;
4371
4372 /* look for a ':'. If there is a '::' then get out, otherwise
c5aa993b 4373 it is probably a line number. */
c906108c 4374 while (*argptr && !hasColon)
c5aa993b
JM
4375 {
4376 hasColon = (*argptr == ':');
4377 argptr++;
4378 }
c906108c
SS
4379
4380 if (hasColon)
c5aa993b 4381 badInput = (*argptr == ':'); /* we have class::method */
c906108c 4382 else
c5aa993b 4383 badInput = !isdigit (*arg); /* not a line number */
c906108c
SS
4384 }
4385
4386 if (badInput)
c5aa993b 4387 printf_filtered ("Usage: stop at <line>\n");
c906108c
SS
4388 else
4389 break_command_1 (arg, 0, from_tty);
4390}
4391
4392/* ARGSUSED */
53a5351d
JM
4393/* accessflag: hw_write: watch write,
4394 hw_read: watch read,
4395 hw_access: watch access (read or write) */
c906108c
SS
4396static void
4397watch_command_1 (arg, accessflag, from_tty)
4398 char *arg;
4399 int accessflag;
4400 int from_tty;
4401{
4402 struct breakpoint *b;
4403 struct symtab_and_line sal;
4404 struct expression *exp;
4405 struct block *exp_valid_block;
4406 struct value *val, *mark;
4407 struct frame_info *frame;
4408 struct frame_info *prev_frame = NULL;
4409 char *exp_start = NULL;
4410 char *exp_end = NULL;
4411 char *tok, *end_tok;
4412 int toklen;
4413 char *cond_start = NULL;
4414 char *cond_end = NULL;
4415 struct expression *cond = NULL;
4416 int i, other_type_used, target_resources_ok = 0;
4417 enum bptype bp_type;
4418 int mem_cnt = 0;
4419
c5aa993b
JM
4420 INIT_SAL (&sal); /* initialize to zeroes */
4421
c906108c
SS
4422 /* Parse arguments. */
4423 innermost_block = NULL;
4424 exp_start = arg;
4425 exp = parse_exp_1 (&arg, 0, 0);
4426 exp_end = arg;
4427 exp_valid_block = innermost_block;
4428 mark = value_mark ();
4429 val = evaluate_expression (exp);
4430 release_value (val);
4431 if (VALUE_LAZY (val))
4432 value_fetch_lazy (val);
4433
4434 tok = arg;
4435 while (*tok == ' ' || *tok == '\t')
4436 tok++;
4437 end_tok = tok;
4438
4439 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4440 end_tok++;
4441
4442 toklen = end_tok - tok;
4443 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4444 {
4445 tok = cond_start = end_tok + 1;
4446 cond = parse_exp_1 (&tok, 0, 0);
4447 cond_end = tok;
4448 }
4449 if (*tok)
c5aa993b 4450 error ("Junk at end of command.");
c906108c 4451
53a5351d 4452 if (accessflag == hw_read)
c5aa993b 4453 bp_type = bp_read_watchpoint;
53a5351d 4454 else if (accessflag == hw_access)
c5aa993b
JM
4455 bp_type = bp_access_watchpoint;
4456 else
4457 bp_type = bp_hardware_watchpoint;
c906108c
SS
4458
4459 mem_cnt = can_use_hardware_watchpoint (val);
4460 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
4461 error ("Expression cannot be implemented with read/access watchpoint.");
c5aa993b
JM
4462 if (mem_cnt != 0)
4463 {
4464 i = hw_watchpoint_used_count (bp_type, &other_type_used);
53a5351d
JM
4465 target_resources_ok =
4466 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
4467 other_type_used);
c5aa993b 4468 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
53a5351d
JM
4469 error ("Target does not support this type of hardware watchpoint.");
4470
c5aa993b 4471 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
53a5351d 4472 error ("Target can only support one kind of HW watchpoint at a time.");
c5aa993b 4473 }
c906108c
SS
4474
4475#if defined(HPUXHPPA)
c5aa993b 4476 /* On HP-UX if you set a h/w
c906108c
SS
4477 watchpoint before the "run" command, the inferior dies with a e.g.,
4478 SIGILL once you start it. I initially believed this was due to a
4479 bad interaction between page protection traps and the initial
4480 startup sequence by the dynamic linker.
4481
4482 However, I tried avoiding that by having HP-UX's implementation of
4483 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_pid
4484 yet, which forced slow watches before a "run" or "attach", and it
4485 still fails somewhere in the startup code.
4486
4487 Until I figure out what's happening, I'm disallowing watches altogether
4488 before the "run" or "attach" command. We'll tell the user they must
4489 set watches after getting the program started. */
c5aa993b 4490 if (!target_has_execution)
c906108c
SS
4491 {
4492 warning ("can't do that without a running program; try \"break main\", \"run\" first");
4493 return;
4494 }
4495#endif /* HPUXHPPA */
c5aa993b 4496
c906108c
SS
4497 /* Now set up the breakpoint. */
4498 b = set_raw_breakpoint (sal);
4499 set_breakpoint_count (breakpoint_count + 1);
4500 b->number = breakpoint_count;
4501 b->disposition = donttouch;
4502 b->exp = exp;
4503 b->exp_valid_block = exp_valid_block;
4504 b->exp_string = savestring (exp_start, exp_end - exp_start);
4505 b->val = val;
4506 b->cond = cond;
4507 if (cond_start)
4508 b->cond_string = savestring (cond_start, cond_end - cond_start);
4509 else
4510 b->cond_string = 0;
c5aa993b 4511
c906108c
SS
4512 frame = block_innermost_frame (exp_valid_block);
4513 if (frame)
4514 {
4515 prev_frame = get_prev_frame (frame);
4516 b->watchpoint_frame = frame->frame;
4517 }
4518 else
c5aa993b 4519 b->watchpoint_frame = (CORE_ADDR) 0;
c906108c
SS
4520
4521 if (mem_cnt && target_resources_ok > 0)
4522 b->type = bp_type;
4523 else
4524 b->type = bp_watchpoint;
4525
4526 /* If the expression is "local", then set up a "watchpoint scope"
4527 breakpoint at the point where we've left the scope of the watchpoint
4528 expression. */
4529 if (innermost_block)
4530 {
4531 if (prev_frame)
4532 {
4533 struct breakpoint *scope_breakpoint;
4534 struct symtab_and_line scope_sal;
4535
4536 INIT_SAL (&scope_sal); /* initialize to zeroes */
c5aa993b 4537 scope_sal.pc = get_frame_pc (prev_frame);
c906108c
SS
4538 scope_sal.section = find_pc_overlay (scope_sal.pc);
4539
4540 scope_breakpoint = set_raw_breakpoint (scope_sal);
4541 set_breakpoint_count (breakpoint_count + 1);
4542 scope_breakpoint->number = breakpoint_count;
4543
4544 scope_breakpoint->type = bp_watchpoint_scope;
4545 scope_breakpoint->enable = enabled;
4546
4547 /* Automatically delete the breakpoint when it hits. */
4548 scope_breakpoint->disposition = del;
4549
4550 /* Only break in the proper frame (help with recursion). */
4551 scope_breakpoint->frame = prev_frame->frame;
4552
4553 /* Set the address at which we will stop. */
4554 scope_breakpoint->address = get_frame_pc (prev_frame);
4555
4556 /* The scope breakpoint is related to the watchpoint. We
4557 will need to act on them together. */
4558 b->related_breakpoint = scope_breakpoint;
4559 }
4560 }
4561 value_free_to_mark (mark);
4562 mention (b);
4563}
4564
4565/* Return count of locations need to be watched and can be handled
4566 in hardware. If the watchpoint can not be handled
4567 in hardware return zero. */
4568
4569#if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
53a5351d
JM
4570#define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
4571 ((BYTE_SIZE) <= (REGISTER_SIZE))
4572#endif
4573
4574#if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
4575#define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
4576 TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN)
c906108c
SS
4577#endif
4578
4579static int
4580can_use_hardware_watchpoint (v)
4581 struct value *v;
4582{
4583 int found_memory_cnt = 0;
4584
4585 /* Did the user specifically forbid us to use hardware watchpoints? */
c5aa993b 4586 if (!can_use_hw_watchpoints)
c906108c 4587 return 0;
c5aa993b 4588
c906108c
SS
4589 /* Make sure all the intermediate values are in memory. Also make sure
4590 we found at least one memory expression. Guards against watch 0x12345,
4591 which is meaningless, but could cause errors if one tries to insert a
4592 hardware watchpoint for the constant expression. */
c5aa993b 4593 for (; v; v = v->next)
c906108c
SS
4594 {
4595 if (v->lval == lval_memory)
4596 {
53a5351d
JM
4597 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
4598 int len = TYPE_LENGTH (VALUE_TYPE (v));
4599
4600 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
4601 return 0;
4602 else
c906108c 4603 found_memory_cnt++;
c5aa993b 4604 }
c906108c 4605 else if (v->lval != not_lval && v->modifiable == 0)
53a5351d
JM
4606 return 0; /* ??? What does this represent? */
4607 else if (v->lval == lval_register)
4608 return 0; /* cannot watch a register with a HW watchpoint */
c906108c
SS
4609 }
4610
4611 /* The expression itself looks suitable for using a hardware
4612 watchpoint, but give the target machine a chance to reject it. */
4613 return found_memory_cnt;
4614}
4615
c5aa993b
JM
4616static void
4617watch_command (arg, from_tty)
c906108c
SS
4618 char *arg;
4619 int from_tty;
4620{
53a5351d 4621 watch_command_1 (arg, hw_write, from_tty);
c906108c
SS
4622}
4623
c5aa993b
JM
4624static void
4625rwatch_command (arg, from_tty)
c906108c
SS
4626 char *arg;
4627 int from_tty;
4628{
53a5351d 4629 watch_command_1 (arg, hw_read, from_tty);
c906108c
SS
4630}
4631
c5aa993b
JM
4632static void
4633awatch_command (arg, from_tty)
c906108c
SS
4634 char *arg;
4635 int from_tty;
4636{
53a5351d 4637 watch_command_1 (arg, hw_access, from_tty);
c906108c 4638}
c906108c 4639\f
c5aa993b 4640
43ff13b4 4641/* Helper routines for the until_command routine in infcmd.c. Here
c906108c
SS
4642 because it uses the mechanisms of breakpoints. */
4643
43ff13b4
JM
4644/* This function is called by fetch_inferior_event via the
4645 cmd_continuation pointer, to complete the until command. It takes
4646 care of cleaning up the temporary breakpoints set up by the until
4647 command. */
4648void
4649until_break_command_continuation (arg)
4650 struct continuation_arg *arg;
4651{
4652 /* Do all the exec cleanups, which at this point should only be the
4653 one set up in the first part of the until_break_command
4654 function. */
4655 do_exec_cleanups (ALL_CLEANUPS);
4656}
4657
c906108c
SS
4658/* ARGSUSED */
4659void
4660until_break_command (arg, from_tty)
4661 char *arg;
4662 int from_tty;
4663{
4664 struct symtabs_and_lines sals;
4665 struct symtab_and_line sal;
4666 struct frame_info *prev_frame = get_prev_frame (selected_frame);
4667 struct breakpoint *breakpoint;
4668 struct cleanup *old_chain;
43ff13b4 4669 struct continuation_arg *arg1, *arg2;
c906108c
SS
4670
4671 clear_proceed_status ();
4672
4673 /* Set a breakpoint where the user wants it and at return from
4674 this function */
c5aa993b 4675
c906108c
SS
4676 if (default_breakpoint_valid)
4677 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
c5aa993b 4678 default_breakpoint_line, (char ***) NULL);
c906108c 4679 else
53a5351d
JM
4680 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
4681 0, (char ***) NULL);
c5aa993b 4682
c906108c
SS
4683 if (sals.nelts != 1)
4684 error ("Couldn't get information on specified line.");
c5aa993b 4685
c906108c 4686 sal = sals.sals[0];
c5aa993b
JM
4687 free ((PTR) sals.sals); /* malloc'd, so freed */
4688
c906108c
SS
4689 if (*arg)
4690 error ("Junk at end of arguments.");
c5aa993b 4691
c906108c 4692 resolve_sal_pc (&sal);
c5aa993b 4693
c906108c 4694 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
c5aa993b 4695
43ff13b4 4696 if (!async_p || !target_has_async)
53a5351d
JM
4697 old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint,
4698 breakpoint);
43ff13b4
JM
4699 else
4700 make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4701
4702 /* If we are running asynchronously, and the target supports async
4703 execution, we are not waiting for the target to stop, in the call
4704 tp proceed, below. This means that we cannot delete the
4705 brekpoints until the target has actually stopped. The only place
4706 where we get a chance to do that is in fetch_inferior_event, so
4707 we must set things up for that. */
4708
4709 if (async_p && target_has_async)
4710 {
4711 /* In this case we don't need args for the continuation, because
c5aa993b
JM
4712 all it needs to do is do the cleanups in the
4713 exec_cleanup_chain, which will be only those inserted by this
4714 function. We can get away by using ALL_CLEANUPS. */
43ff13b4
JM
4715 add_continuation (until_break_command_continuation, NULL);
4716 }
c906108c
SS
4717
4718 /* Keep within the current frame */
c5aa993b 4719
c906108c
SS
4720 if (prev_frame)
4721 {
4722 sal = find_pc_line (prev_frame->pc, 0);
4723 sal.pc = prev_frame->pc;
4724 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
43ff13b4
JM
4725 if (!async_p || !target_has_async)
4726 make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4727 else
4728 make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
c906108c 4729 }
c5aa993b 4730
c906108c 4731 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
43ff13b4
JM
4732 /* Do the cleanups now, anly if we are not running asynchronously,
4733 of if we are, but the target is still synchronous. */
4734 if (!async_p || !target_has_async)
c5aa993b 4735 do_cleanups (old_chain);
c906108c
SS
4736}
4737\f
4738#if 0
4739/* These aren't used; I don't konw what they were for. */
4740/* Set a breakpoint at the catch clause for NAME. */
4741static int
4742catch_breakpoint (name)
4743 char *name;
4744{
4745}
4746
4747static int
4748disable_catch_breakpoint ()
4749{
4750}
4751
4752static int
4753delete_catch_breakpoint ()
4754{
4755}
4756
4757static int
4758enable_catch_breakpoint ()
4759{
4760}
4761#endif /* 0 */
4762
4763struct sal_chain
4764{
4765 struct sal_chain *next;
4766 struct symtab_and_line sal;
4767};
4768
7a292a7a 4769#if 0
c906108c
SS
4770/* Not really used -- invocation in handle_gnu_4_16_catch_command
4771 had been commented out in the v.4.16 sources, and stays
4772 disabled there now because "catch NAME" syntax isn't allowed.
4773 pai/1997-07-11 */
4774/* This isn't used; I don't know what it was for. */
4775/* For each catch clause identified in ARGS, run FUNCTION
4776 with that clause as an argument. */
4777static struct symtabs_and_lines
4778map_catch_names (args, function)
4779 char *args;
c5aa993b 4780 int (*function) ();
c906108c
SS
4781{
4782 register char *p = args;
4783 register char *p1;
4784 struct symtabs_and_lines sals;
4785#if 0
4786 struct sal_chain *sal_chain = 0;
4787#endif
4788
4789 if (p == 0)
4790 error_no_arg ("one or more catch names");
4791
4792 sals.nelts = 0;
4793 sals.sals = NULL;
4794
4795 while (*p)
4796 {
4797 p1 = p;
4798 /* Don't swallow conditional part. */
4799 if (p1[0] == 'i' && p1[1] == 'f'
4800 && (p1[2] == ' ' || p1[2] == '\t'))
4801 break;
4802
4803 if (isalpha (*p1))
4804 {
4805 p1++;
4806 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
4807 p1++;
4808 }
4809
4810 if (*p1 && *p1 != ' ' && *p1 != '\t')
4811 error ("Arguments must be catch names.");
4812
4813 *p1 = 0;
4814#if 0
4815 if (function (p))
4816 {
4817 struct sal_chain *next = (struct sal_chain *)
c5aa993b 4818 alloca (sizeof (struct sal_chain));
c906108c
SS
4819 next->next = sal_chain;
4820 next->sal = get_catch_sal (p);
4821 sal_chain = next;
4822 goto win;
4823 }
4824#endif
4825 printf_unfiltered ("No catch clause for exception %s.\n", p);
4826#if 0
4827 win:
4828#endif
4829 p = p1;
c5aa993b
JM
4830 while (*p == ' ' || *p == '\t')
4831 p++;
c906108c
SS
4832 }
4833}
7a292a7a 4834#endif
c906108c
SS
4835
4836/* This shares a lot of code with `print_frame_label_vars' from stack.c. */
4837
4838static struct symtabs_and_lines
4839get_catch_sals (this_level_only)
4840 int this_level_only;
4841{
4842 register struct blockvector *bl;
4843 register struct block *block;
4844 int index, have_default = 0;
4845 CORE_ADDR pc;
4846 struct symtabs_and_lines sals;
4847 struct sal_chain *sal_chain = 0;
4848 char *blocks_searched;
4849
4850 /* Not sure whether an error message is always the correct response,
4851 but it's better than a core dump. */
4852 if (selected_frame == NULL)
4853 error ("No selected frame.");
4854 block = get_frame_block (selected_frame);
4855 pc = selected_frame->pc;
4856
4857 sals.nelts = 0;
4858 sals.sals = NULL;
4859
4860 if (block == 0)
4861 error ("No symbol table info available.\n");
4862
4863 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
4864 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
4865 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
4866
4867 while (block != 0)
4868 {
4869 CORE_ADDR end = BLOCK_END (block) - 4;
4870 int last_index;
4871
4872 if (bl != blockvector_for_pc (end, &index))
4873 error ("blockvector blotch");
4874 if (BLOCKVECTOR_BLOCK (bl, index) != block)
4875 error ("blockvector botch");
4876 last_index = BLOCKVECTOR_NBLOCKS (bl);
4877 index += 1;
4878
4879 /* Don't print out blocks that have gone by. */
4880 while (index < last_index
4881 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
4882 index++;
4883
4884 while (index < last_index
4885 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
4886 {
4887 if (blocks_searched[index] == 0)
4888 {
4889 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
4890 int nsyms;
4891 register int i;
4892 register struct symbol *sym;
4893
4894 nsyms = BLOCK_NSYMS (b);
4895
4896 for (i = 0; i < nsyms; i++)
4897 {
4898 sym = BLOCK_SYM (b, i);
4899 if (STREQ (SYMBOL_NAME (sym), "default"))
4900 {
4901 if (have_default)
4902 continue;
4903 have_default = 1;
4904 }
4905 if (SYMBOL_CLASS (sym) == LOC_LABEL)
4906 {
4907 struct sal_chain *next = (struct sal_chain *)
c5aa993b 4908 alloca (sizeof (struct sal_chain));
c906108c 4909 next->next = sal_chain;
53a5351d
JM
4910 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
4911 0);
c906108c
SS
4912 sal_chain = next;
4913 }
4914 }
4915 blocks_searched[index] = 1;
4916 }
4917 index++;
4918 }
4919 if (have_default)
4920 break;
4921 if (sal_chain && this_level_only)
4922 break;
4923
4924 /* After handling the function's top-level block, stop.
c5aa993b
JM
4925 Don't continue to its superblock, the block of
4926 per-file symbols. */
c906108c
SS
4927 if (BLOCK_FUNCTION (block))
4928 break;
4929 block = BLOCK_SUPERBLOCK (block);
4930 }
4931
4932 if (sal_chain)
4933 {
4934 struct sal_chain *tmp_chain;
4935
4936 /* Count the number of entries. */
4937 for (index = 0, tmp_chain = sal_chain; tmp_chain;
4938 tmp_chain = tmp_chain->next)
4939 index++;
4940
4941 sals.nelts = index;
4942 sals.sals = (struct symtab_and_line *)
4943 xmalloc (index * sizeof (struct symtab_and_line));
4944 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
4945 sals.sals[index] = sal_chain->sal;
4946 }
4947
4948 return sals;
4949}
4950
4951static void
4952ep_skip_leading_whitespace (s)
7a292a7a 4953 char **s;
c906108c 4954{
c5aa993b
JM
4955 if ((s == NULL) || (*s == NULL))
4956 return;
4957 while (isspace (**s))
4958 *s += 1;
c906108c 4959}
c5aa993b 4960
c906108c
SS
4961/* This function examines a string, and attempts to find a token
4962 that might be an event name in the leading characters. If a
4963 possible match is found, a pointer to the last character of
4964 the token is returned. Else, NULL is returned. */
53a5351d 4965
c906108c
SS
4966static char *
4967ep_find_event_name_end (arg)
7a292a7a 4968 char *arg;
c906108c 4969{
c5aa993b
JM
4970 char *s = arg;
4971 char *event_name_end = NULL;
4972
c906108c
SS
4973 /* If we could depend upon the presense of strrpbrk, we'd use that... */
4974 if (arg == NULL)
4975 return NULL;
c5aa993b 4976
c906108c 4977 /* We break out of the loop when we find a token delimiter.
c5aa993b
JM
4978 Basically, we're looking for alphanumerics and underscores;
4979 anything else delimites the token. */
c906108c
SS
4980 while (*s != '\0')
4981 {
c5aa993b
JM
4982 if (!isalnum (*s) && (*s != '_'))
4983 break;
c906108c
SS
4984 event_name_end = s;
4985 s++;
4986 }
c5aa993b 4987
c906108c
SS
4988 return event_name_end;
4989}
4990
c5aa993b 4991
c906108c
SS
4992/* This function attempts to parse an optional "if <cond>" clause
4993 from the arg string. If one is not found, it returns NULL.
c5aa993b 4994
c906108c
SS
4995 Else, it returns a pointer to the condition string. (It does not
4996 attempt to evaluate the string against a particular block.) And,
4997 it updates arg to point to the first character following the parsed
4998 if clause in the arg string. */
53a5351d 4999
c906108c
SS
5000static char *
5001ep_parse_optional_if_clause (arg)
7a292a7a 5002 char **arg;
c906108c 5003{
c5aa993b
JM
5004 char *cond_string;
5005
5006 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
c906108c 5007 return NULL;
c5aa993b 5008
c906108c
SS
5009 /* Skip the "if" keyword. */
5010 (*arg) += 2;
c5aa993b 5011
c906108c
SS
5012 /* Skip any extra leading whitespace, and record the start of the
5013 condition string. */
5014 ep_skip_leading_whitespace (arg);
5015 cond_string = *arg;
c5aa993b 5016
c906108c
SS
5017 /* Assume that the condition occupies the remainder of the arg string. */
5018 (*arg) += strlen (cond_string);
c5aa993b 5019
c906108c
SS
5020 return cond_string;
5021}
c5aa993b 5022
c906108c
SS
5023/* This function attempts to parse an optional filename from the arg
5024 string. If one is not found, it returns NULL.
c5aa993b 5025
c906108c
SS
5026 Else, it returns a pointer to the parsed filename. (This function
5027 makes no attempt to verify that a file of that name exists, or is
5028 accessible.) And, it updates arg to point to the first character
5029 following the parsed filename in the arg string.
c5aa993b 5030
c906108c
SS
5031 Note that clients needing to preserve the returned filename for
5032 future access should copy it to their own buffers. */
5033static char *
5034ep_parse_optional_filename (arg)
7a292a7a 5035 char **arg;
c906108c 5036{
c5aa993b
JM
5037 static char filename[1024];
5038 char *arg_p = *arg;
5039 int i;
5040 char c;
5041
c906108c
SS
5042 if ((*arg_p == '\0') || isspace (*arg_p))
5043 return NULL;
c5aa993b
JM
5044
5045 for (i = 0;; i++)
c906108c
SS
5046 {
5047 c = *arg_p;
5048 if (isspace (c))
c5aa993b 5049 c = '\0';
c906108c
SS
5050 filename[i] = c;
5051 if (c == '\0')
c5aa993b 5052 break;
c906108c
SS
5053 arg_p++;
5054 }
5055 *arg = arg_p;
c5aa993b 5056
c906108c
SS
5057 return filename;
5058}
c5aa993b 5059
c906108c
SS
5060/* Commands to deal with catching events, such as signals, exceptions,
5061 process start/exit, etc. */
c5aa993b
JM
5062
5063typedef enum
5064{
5065 catch_fork, catch_vfork
5066}
5067catch_fork_kind;
5068
53a5351d
JM
5069static void catch_fork_command_1 PARAMS ((catch_fork_kind fork_kind,
5070 char *arg,
5071 int tempflag,
5072 int from_tty));
7a292a7a 5073
c906108c
SS
5074static void
5075catch_fork_command_1 (fork_kind, arg, tempflag, from_tty)
7a292a7a
SS
5076 catch_fork_kind fork_kind;
5077 char *arg;
5078 int tempflag;
5079 int from_tty;
c906108c 5080{
c5aa993b
JM
5081 char *cond_string = NULL;
5082
c906108c 5083 ep_skip_leading_whitespace (&arg);
c5aa993b 5084
c906108c 5085 /* The allowed syntax is:
c5aa993b
JM
5086 catch [v]fork
5087 catch [v]fork if <cond>
5088
c906108c
SS
5089 First, check if there's an if clause. */
5090 cond_string = ep_parse_optional_if_clause (&arg);
c5aa993b 5091
c906108c
SS
5092 if ((*arg != '\0') && !isspace (*arg))
5093 error ("Junk at end of arguments.");
c5aa993b 5094
c906108c
SS
5095 /* If this target supports it, create a fork or vfork catchpoint
5096 and enable reporting of such events. */
c5aa993b
JM
5097 switch (fork_kind)
5098 {
5099 case catch_fork:
c906108c
SS
5100 create_fork_event_catchpoint (tempflag, cond_string);
5101 break;
c5aa993b 5102 case catch_vfork:
c906108c
SS
5103 create_vfork_event_catchpoint (tempflag, cond_string);
5104 break;
c5aa993b 5105 default:
c906108c
SS
5106 error ("unsupported or unknown fork kind; cannot catch it");
5107 break;
c5aa993b 5108 }
c906108c
SS
5109}
5110
5111static void
5112catch_exec_command_1 (arg, tempflag, from_tty)
7a292a7a
SS
5113 char *arg;
5114 int tempflag;
5115 int from_tty;
c906108c 5116{
c5aa993b 5117 char *cond_string = NULL;
c906108c
SS
5118
5119 ep_skip_leading_whitespace (&arg);
5120
5121 /* The allowed syntax is:
c5aa993b
JM
5122 catch exec
5123 catch exec if <cond>
c906108c
SS
5124
5125 First, check if there's an if clause. */
5126 cond_string = ep_parse_optional_if_clause (&arg);
5127
5128 if ((*arg != '\0') && !isspace (*arg))
5129 error ("Junk at end of arguments.");
5130
5131 /* If this target supports it, create an exec catchpoint
5132 and enable reporting of such events. */
5133 create_exec_event_catchpoint (tempflag, cond_string);
5134}
c5aa993b 5135
c906108c
SS
5136#if defined(SOLIB_ADD)
5137static void
5138catch_load_command_1 (arg, tempflag, from_tty)
c5aa993b
JM
5139 char *arg;
5140 int tempflag;
5141 int from_tty;
c906108c 5142{
c5aa993b
JM
5143 char *dll_pathname = NULL;
5144 char *cond_string = NULL;
5145
c906108c 5146 ep_skip_leading_whitespace (&arg);
c5aa993b 5147
c906108c 5148 /* The allowed syntax is:
c5aa993b
JM
5149 catch load
5150 catch load if <cond>
5151 catch load <filename>
5152 catch load <filename> if <cond>
5153
c906108c
SS
5154 The user is not allowed to specify the <filename> after an
5155 if clause.
c5aa993b 5156
c906108c 5157 We'll ignore the pathological case of a file named "if".
c5aa993b 5158
c906108c
SS
5159 First, check if there's an if clause. If so, then there
5160 cannot be a filename. */
5161 cond_string = ep_parse_optional_if_clause (&arg);
c5aa993b 5162
c906108c
SS
5163 /* If there was an if clause, then there cannot be a filename.
5164 Else, there might be a filename and an if clause. */
5165 if (cond_string == NULL)
5166 {
5167 dll_pathname = ep_parse_optional_filename (&arg);
5168 ep_skip_leading_whitespace (&arg);
5169 cond_string = ep_parse_optional_if_clause (&arg);
5170 }
c5aa993b 5171
c906108c
SS
5172 if ((*arg != '\0') && !isspace (*arg))
5173 error ("Junk at end of arguments.");
c5aa993b 5174
c906108c
SS
5175 /* Create a load breakpoint that only triggers when a load of
5176 the specified dll (or any dll, if no pathname was specified)
5177 occurs. */
53a5351d
JM
5178 SOLIB_CREATE_CATCH_LOAD_HOOK (inferior_pid, tempflag,
5179 dll_pathname, cond_string);
c906108c 5180}
c5aa993b 5181
c906108c
SS
5182static void
5183catch_unload_command_1 (arg, tempflag, from_tty)
c5aa993b
JM
5184 char *arg;
5185 int tempflag;
5186 int from_tty;
c906108c 5187{
c5aa993b
JM
5188 char *dll_pathname = NULL;
5189 char *cond_string = NULL;
5190
c906108c 5191 ep_skip_leading_whitespace (&arg);
c5aa993b 5192
c906108c 5193 /* The allowed syntax is:
c5aa993b
JM
5194 catch unload
5195 catch unload if <cond>
5196 catch unload <filename>
5197 catch unload <filename> if <cond>
5198
c906108c
SS
5199 The user is not allowed to specify the <filename> after an
5200 if clause.
c5aa993b 5201
c906108c 5202 We'll ignore the pathological case of a file named "if".
c5aa993b 5203
c906108c
SS
5204 First, check if there's an if clause. If so, then there
5205 cannot be a filename. */
5206 cond_string = ep_parse_optional_if_clause (&arg);
c5aa993b 5207
c906108c
SS
5208 /* If there was an if clause, then there cannot be a filename.
5209 Else, there might be a filename and an if clause. */
5210 if (cond_string == NULL)
5211 {
5212 dll_pathname = ep_parse_optional_filename (&arg);
5213 ep_skip_leading_whitespace (&arg);
5214 cond_string = ep_parse_optional_if_clause (&arg);
5215 }
c5aa993b 5216
c906108c
SS
5217 if ((*arg != '\0') && !isspace (*arg))
5218 error ("Junk at end of arguments.");
c5aa993b 5219
c906108c
SS
5220 /* Create an unload breakpoint that only triggers when an unload of
5221 the specified dll (or any dll, if no pathname was specified)
5222 occurs. */
53a5351d
JM
5223 SOLIB_CREATE_CATCH_UNLOAD_HOOK (inferior_pid, tempflag,
5224 dll_pathname, cond_string);
c906108c
SS
5225}
5226#endif /* SOLIB_ADD */
5227
5228/* Commands to deal with catching exceptions. */
5229
5230/* Set a breakpoint at the specified callback routine for an
c5aa993b 5231 exception event callback */
c906108c
SS
5232
5233static void
5234create_exception_catchpoint (tempflag, cond_string, ex_event, sal)
7a292a7a
SS
5235 int tempflag;
5236 char *cond_string;
5237 enum exception_event_kind ex_event;
5238 struct symtab_and_line *sal;
c906108c 5239{
c5aa993b
JM
5240 struct breakpoint *b;
5241 int i;
5242 int thread = -1; /* All threads. */
c906108c 5243
c5aa993b 5244 if (!sal) /* no exception support? */
c906108c
SS
5245 return;
5246
5247 b = set_raw_breakpoint (*sal);
5248 set_breakpoint_count (breakpoint_count + 1);
5249 b->number = breakpoint_count;
5250 b->cond = NULL;
53a5351d
JM
5251 b->cond_string = (cond_string == NULL) ?
5252 NULL : savestring (cond_string, strlen (cond_string));
c906108c
SS
5253 b->thread = thread;
5254 b->addr_string = NULL;
5255 b->enable = enabled;
5256 b->disposition = tempflag ? del : donttouch;
5257 switch (ex_event)
5258 {
c5aa993b
JM
5259 case EX_EVENT_THROW:
5260 b->type = bp_catch_throw;
5261 break;
5262 case EX_EVENT_CATCH:
5263 b->type = bp_catch_catch;
5264 break;
5265 default: /* error condition */
5266 b->type = bp_none;
5267 b->enable = disabled;
5268 error ("Internal error -- invalid catchpoint kind");
c906108c
SS
5269 }
5270 mention (b);
5271}
5272
c5aa993b 5273/* Deal with "catch catch" and "catch throw" commands */
c906108c
SS
5274
5275static void
5276catch_exception_command_1 (ex_event, arg, tempflag, from_tty)
7a292a7a
SS
5277 enum exception_event_kind ex_event;
5278 char *arg;
5279 int tempflag;
5280 int from_tty;
c906108c 5281{
c5aa993b
JM
5282 char *cond_string = NULL;
5283 struct symtab_and_line *sal = NULL;
5284
c906108c 5285 ep_skip_leading_whitespace (&arg);
c5aa993b 5286
c906108c
SS
5287 cond_string = ep_parse_optional_if_clause (&arg);
5288
5289 if ((*arg != '\0') && !isspace (*arg))
5290 error ("Junk at end of arguments.");
5291
5292 if ((ex_event != EX_EVENT_THROW) &&
5293 (ex_event != EX_EVENT_CATCH))
5294 error ("Unsupported or unknown exception event; cannot catch it");
5295
5296 /* See if we can find a callback routine */
5297 sal = target_enable_exception_callback (ex_event, 1);
5298
c5aa993b 5299 if (sal)
c906108c
SS
5300 {
5301 /* We have callbacks from the runtime system for exceptions.
c5aa993b 5302 Set a breakpoint on the sal found, if no errors */
c906108c 5303 if (sal != (struct symtab_and_line *) -1)
c5aa993b 5304 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
c906108c 5305 else
53a5351d 5306 return; /* something went wrong with setting up callbacks */
c906108c 5307 }
c5aa993b 5308 else
c906108c
SS
5309 {
5310 /* No callbacks from runtime system for exceptions.
5311 Try GNU C++ exception breakpoints using labels in debug info. */
5312 if (ex_event == EX_EVENT_CATCH)
c5aa993b
JM
5313 {
5314 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
5315 }
c906108c 5316 else if (ex_event == EX_EVENT_THROW)
c5aa993b
JM
5317 {
5318 /* Set a breakpoint on __raise_exception () */
5319
53a5351d
JM
5320 warning ("Unsupported with this platform/compiler combination.");
5321 warning ("Perhaps you can achieve the effect you want by setting");
5322 warning ("a breakpoint on __raise_exception().");
c5aa993b 5323 }
c906108c
SS
5324 }
5325}
5326
5327/* Cover routine to allow wrapping target_enable_exception_catchpoints
5328 inside a catch_errors */
5329
5330static int
5331cover_target_enable_exception_callback (arg)
c5aa993b 5332 PTR arg;
c906108c
SS
5333{
5334 args_for_catchpoint_enable *args = arg;
5335 struct symtab_and_line *sal;
5336 sal = target_enable_exception_callback (args->kind, args->enable);
5337 if (sal == NULL)
5338 return 0;
5339 else if (sal == (struct symtab_and_line *) -1)
5340 return -1;
5341 else
c5aa993b 5342 return 1; /*is valid */
c906108c
SS
5343}
5344
5345
5346
5347/* This is the original v.4.16 and earlier version of the
5348 catch_command_1() function. Now that other flavours of "catch"
5349 have been introduced, and since exception handling can be handled
5350 in other ways (through target ops) also, this is used only for the
5351 GNU C++ exception handling system.
5352 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
5353 "catch NAME" is now no longer allowed in catch_command_1(). Also,
5354 there was no code in GDB 4.16 for "catch throw".
c5aa993b 5355
c906108c
SS
5356 Called from catch_exception_command_1 () */
5357
5358
5359static void
5360handle_gnu_4_16_catch_command (arg, tempflag, from_tty)
5361 char *arg;
5362 int tempflag;
5363 int from_tty;
5364{
5365 /* First, translate ARG into something we can deal with in terms
5366 of breakpoints. */
5367
5368 struct symtabs_and_lines sals;
5369 struct symtab_and_line sal;
5370 register struct expression *cond = 0;
5371 register struct breakpoint *b;
5372 char *save_arg;
5373 int i;
5374
c5aa993b 5375 INIT_SAL (&sal); /* initialize to zeroes */
c906108c
SS
5376
5377 /* If no arg given, or if first arg is 'if ', all active catch clauses
5378 are breakpointed. */
5379
c5aa993b 5380 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
c906108c
SS
5381 && (arg[2] == ' ' || arg[2] == '\t')))
5382 {
5383 /* Grab all active catch clauses. */
5384 sals = get_catch_sals (0);
5385 }
5386 else
5387 {
5388 /* Grab selected catch clauses. */
5389 error ("catch NAME not implemented");
5390
5391#if 0
5392 /* Not sure why this code has been disabled. I'm leaving
5393 it disabled. We can never come here now anyway
5394 since we don't allow the "catch NAME" syntax.
c5aa993b 5395 pai/1997-07-11 */
c906108c
SS
5396
5397 /* This isn't used; I don't know what it was for. */
5398 sals = map_catch_names (arg, catch_breakpoint);
5399#endif
5400 }
5401
c5aa993b 5402 if (!sals.nelts)
c906108c
SS
5403 return;
5404
5405 save_arg = arg;
5406 for (i = 0; i < sals.nelts; i++)
5407 {
5408 resolve_sal_pc (&sals.sals[i]);
c5aa993b 5409
c906108c
SS
5410 while (arg && *arg)
5411 {
5412 if (arg[0] == 'i' && arg[1] == 'f'
5413 && (arg[2] == ' ' || arg[2] == '\t'))
c5aa993b 5414 cond = parse_exp_1 ((arg += 2, &arg),
c906108c
SS
5415 block_for_pc (sals.sals[i].pc), 0);
5416 else
5417 error ("Junk at end of arguments.");
5418 }
5419 arg = save_arg;
5420 }
5421
5422 for (i = 0; i < sals.nelts; i++)
5423 {
5424 sal = sals.sals[i];
5425
5426 if (from_tty)
5427 describe_other_breakpoints (sal.pc, sal.section);
5428
5429 b = set_raw_breakpoint (sal);
5430 set_breakpoint_count (breakpoint_count + 1);
5431 b->number = breakpoint_count;
53a5351d
JM
5432
5433 /* Important -- this is an ordinary breakpoint. For platforms
5434 with callback support for exceptions,
5435 create_exception_catchpoint() will create special bp types
5436 (bp_catch_catch and bp_catch_throw), and there is code in
5437 insert_breakpoints() and elsewhere that depends on that. */
5438 b->type = bp_breakpoint;
c906108c
SS
5439
5440 b->cond = cond;
5441 b->enable = enabled;
5442 b->disposition = tempflag ? del : donttouch;
5443
5444 mention (b);
5445 }
5446
5447 if (sals.nelts > 1)
5448 {
53a5351d
JM
5449 warning ("Multiple breakpoints were set.");
5450 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
c906108c 5451 }
c5aa993b 5452 free ((PTR) sals.sals);
c906108c
SS
5453}
5454
5455#if 0
5456/* This creates a temporary internal breakpoint
5457 just to placate infrun */
5458static struct breakpoint *
5459create_temp_exception_breakpoint (pc)
c5aa993b 5460 CORE_ADDR pc;
c906108c
SS
5461{
5462 struct symtab_and_line sal;
5463 struct breakpoint *b;
5464
c5aa993b 5465 INIT_SAL (&sal);
c906108c
SS
5466 sal.pc = pc;
5467 sal.symtab = NULL;
5468 sal.line = 0;
5469
5470 b = set_raw_breakpoint (sal);
5471 if (!b)
5472 error ("Internal error -- couldn't set temp exception breakpoint");
5473
5474 b->type = bp_breakpoint;
5475 b->disposition = del;
5476 b->enable = enabled;
5477 b->silent = 1;
5478 b->number = internal_breakpoint_number--;
5479 return b;
5480}
5481#endif
5482
5483static void
5484catch_command_1 (arg, tempflag, from_tty)
c5aa993b
JM
5485 char *arg;
5486 int tempflag;
5487 int from_tty;
c906108c 5488{
c5aa993b 5489
c906108c
SS
5490 /* The first argument may be an event name, such as "start" or "load".
5491 If so, then handle it as such. If it doesn't match an event name,
5492 then attempt to interpret it as an exception name. (This latter is
5493 the v4.16-and-earlier GDB meaning of the "catch" command.)
c5aa993b 5494
c906108c 5495 First, try to find the bounds of what might be an event name. */
c5aa993b
JM
5496 char *arg1_start = arg;
5497 char *arg1_end;
5498 int arg1_length;
5499
c906108c
SS
5500 if (arg1_start == NULL)
5501 {
c5aa993b 5502 /* Old behaviour was to use pre-v-4.16 syntax */
c906108c
SS
5503 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
5504 /* return; */
c5aa993b 5505 /* Now, this is not allowed */
c906108c
SS
5506 error ("Catch requires an event name.");
5507
5508 }
5509 arg1_end = ep_find_event_name_end (arg1_start);
5510 if (arg1_end == NULL)
5511 error ("catch requires an event");
5512 arg1_length = arg1_end + 1 - arg1_start;
c5aa993b 5513
c906108c
SS
5514 /* Try to match what we found against known event names. */
5515 if (strncmp (arg1_start, "signal", arg1_length) == 0)
5516 {
5517 error ("Catch of signal not yet implemented");
5518 }
5519 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
5520 {
53a5351d
JM
5521 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
5522 tempflag, from_tty);
c906108c
SS
5523 }
5524 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
5525 {
53a5351d
JM
5526 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
5527 tempflag, from_tty);
c906108c
SS
5528 }
5529 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
5530 {
5531 error ("Catch of thread_start not yet implemented");
5532 }
5533 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
5534 {
5535 error ("Catch of thread_exit not yet implemented");
5536 }
5537 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
5538 {
5539 error ("Catch of thread_join not yet implemented");
5540 }
5541 else if (strncmp (arg1_start, "start", arg1_length) == 0)
5542 {
5543 error ("Catch of start not yet implemented");
5544 }
5545 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
5546 {
5547 error ("Catch of exit not yet implemented");
5548 }
5549 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
5550 {
5551#if defined(CHILD_INSERT_FORK_CATCHPOINT)
c5aa993b 5552 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
c906108c
SS
5553#else
5554 error ("Catch of fork not yet implemented");
5555#endif
5556 }
5557 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
5558 {
5559#if defined(CHILD_INSERT_VFORK_CATCHPOINT)
c5aa993b 5560 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
c906108c
SS
5561#else
5562 error ("Catch of vfork not yet implemented");
5563#endif
5564 }
5565 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
5566 {
5567#if defined(CHILD_INSERT_EXEC_CATCHPOINT)
c5aa993b 5568 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
c906108c
SS
5569#else
5570 error ("Catch of exec not yet implemented");
5571#endif
5572 }
5573 else if (strncmp (arg1_start, "load", arg1_length) == 0)
5574 {
5575#if defined(SOLIB_ADD)
c5aa993b 5576 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
c906108c
SS
5577#else
5578 error ("Catch of load not implemented");
5579#endif
5580 }
5581 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
5582 {
5583#if defined(SOLIB_ADD)
c5aa993b 5584 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
c906108c
SS
5585#else
5586 error ("Catch of load not implemented");
5587#endif
5588 }
5589 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
5590 {
5591 error ("Catch of stop not yet implemented");
5592 }
c5aa993b 5593
c906108c
SS
5594 /* This doesn't appear to be an event name */
5595
5596 else
5597 {
5598 /* Pre-v.4.16 behaviour was to treat the argument
c5aa993b 5599 as the name of an exception */
c906108c 5600 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
c5aa993b 5601 /* Now this is not allowed */
c906108c
SS
5602 error ("Unknown event kind specified for catch");
5603
5604 }
5605}
5606
5607/* Used by the gui, could be made a worker for other things. */
5608
5609struct breakpoint *
5610set_breakpoint_sal (sal)
5611 struct symtab_and_line sal;
5612{
5613 struct breakpoint *b;
5614 b = set_raw_breakpoint (sal);
5615 set_breakpoint_count (breakpoint_count + 1);
5616 b->number = breakpoint_count;
5617 b->type = bp_breakpoint;
5618 b->cond = 0;
5619 b->thread = -1;
5620 return b;
5621}
5622
5623#if 0
5624/* These aren't used; I don't know what they were for. */
5625/* Disable breakpoints on all catch clauses described in ARGS. */
5626static void
5627disable_catch (args)
5628 char *args;
5629{
5630 /* Map the disable command to catch clauses described in ARGS. */
5631}
5632
5633/* Enable breakpoints on all catch clauses described in ARGS. */
5634static void
5635enable_catch (args)
5636 char *args;
5637{
5638 /* Map the disable command to catch clauses described in ARGS. */
5639}
5640
5641/* Delete breakpoints on all catch clauses in the active scope. */
5642static void
5643delete_catch (args)
5644 char *args;
5645{
5646 /* Map the delete command to catch clauses described in ARGS. */
5647}
5648#endif /* 0 */
5649
5650static void
5651catch_command (arg, from_tty)
5652 char *arg;
5653 int from_tty;
5654{
5655 catch_command_1 (arg, 0, from_tty);
5656}
5657\f
5658
5659static void
5660tcatch_command (arg, from_tty)
5661 char *arg;
5662 int from_tty;
5663{
5664 catch_command_1 (arg, 1, from_tty);
5665}
5666
5667
5668static void
5669clear_command (arg, from_tty)
5670 char *arg;
5671 int from_tty;
5672{
5673 register struct breakpoint *b, *b1;
5674 int default_match;
5675 struct symtabs_and_lines sals;
5676 struct symtab_and_line sal;
5677 register struct breakpoint *found;
5678 int i;
5679
5680 if (arg)
5681 {
5682 sals = decode_line_spec (arg, 1);
5683 default_match = 0;
5684 }
5685 else
5686 {
c5aa993b 5687 sals.sals = (struct symtab_and_line *)
c906108c 5688 xmalloc (sizeof (struct symtab_and_line));
c5aa993b 5689 INIT_SAL (&sal); /* initialize to zeroes */
c906108c
SS
5690 sal.line = default_breakpoint_line;
5691 sal.symtab = default_breakpoint_symtab;
5692 sal.pc = default_breakpoint_address;
5693 if (sal.symtab == 0)
5694 error ("No source file specified.");
5695
5696 sals.sals[0] = sal;
5697 sals.nelts = 1;
5698
5699 default_match = 1;
5700 }
5701
5702 /* For each line spec given, delete bps which correspond
5703 to it. We do this in two loops: the first loop looks at
5704 the initial bp(s) in the chain which should be deleted,
5705 the second goes down the rest of the chain looking ahead
5706 one so it can take those bps off the chain without messing
5707 up the chain. */
5708
5709
5710 for (i = 0; i < sals.nelts; i++)
5711 {
5712 /* If exact pc given, clear bpts at that pc.
c5aa993b
JM
5713 If line given (pc == 0), clear all bpts on specified line.
5714 If defaulting, clear all bpts on default line
c906108c 5715 or at default pc.
c5aa993b
JM
5716
5717 defaulting sal.pc != 0 tests to do
5718
5719 0 1 pc
5720 1 1 pc _and_ line
5721 0 0 line
5722 1 0 <can't happen> */
c906108c
SS
5723
5724 sal = sals.sals[i];
5725 found = (struct breakpoint *) 0;
5726
5727
5728 while (breakpoint_chain
c5aa993b
JM
5729 /* Why don't we check here that this is not
5730 a watchpoint, etc., as we do below?
5731 I can't make it fail, but don't know
5732 what's stopping the failure: a watchpoint
5733 of the same address as "sal.pc" should
5734 wind up being deleted. */
5735
5736 && (((sal.pc && (breakpoint_chain->address == sal.pc)) &&
5737 (overlay_debugging == 0 ||
5738 breakpoint_chain->section == sal.section))
5739 || ((default_match || (0 == sal.pc))
5740 && breakpoint_chain->source_file != NULL
5741 && sal.symtab != NULL
5742 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
5743 && breakpoint_chain->line_number == sal.line)))
c906108c
SS
5744
5745 {
5746 b1 = breakpoint_chain;
5747 breakpoint_chain = b1->next;
5748 b1->next = found;
5749 found = b1;
5750 }
5751
5752 ALL_BREAKPOINTS (b)
5753
c5aa993b
JM
5754 while (b->next
5755 && b->next->type != bp_none
5756 && b->next->type != bp_watchpoint
5757 && b->next->type != bp_hardware_watchpoint
5758 && b->next->type != bp_read_watchpoint
5759 && b->next->type != bp_access_watchpoint
5760 && (((sal.pc && (b->next->address == sal.pc)) &&
5761 (overlay_debugging == 0 ||
5762 b->next->section == sal.section))
5763 || ((default_match || (0 == sal.pc))
5764 && b->next->source_file != NULL
5765 && sal.symtab != NULL
5766 && STREQ (b->next->source_file, sal.symtab->filename)
5767 && b->next->line_number == sal.line)))
c906108c
SS
5768
5769
c5aa993b
JM
5770 {
5771 b1 = b->next;
5772 b->next = b1->next;
5773 b1->next = found;
5774 found = b1;
5775 }
c906108c
SS
5776
5777 if (found == 0)
5778 {
5779 if (arg)
5780 error ("No breakpoint at %s.", arg);
5781 else
5782 error ("No breakpoint at this line.");
5783 }
5784
c5aa993b
JM
5785 if (found->next)
5786 from_tty = 1; /* Always report if deleted more than one */
5787 if (from_tty)
5788 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
c906108c
SS
5789 breakpoints_changed ();
5790 while (found)
5791 {
c5aa993b
JM
5792 if (from_tty)
5793 printf_unfiltered ("%d ", found->number);
c906108c
SS
5794 b1 = found->next;
5795 delete_breakpoint (found);
5796 found = b1;
5797 }
c5aa993b
JM
5798 if (from_tty)
5799 putchar_unfiltered ('\n');
c906108c 5800 }
c5aa993b 5801 free ((PTR) sals.sals);
c906108c
SS
5802}
5803\f
5804/* Delete breakpoint in BS if they are `delete' breakpoints and
5805 all breakpoints that are marked for deletion, whether hit or not.
5806 This is called after any breakpoint is hit, or after errors. */
5807
5808void
5809breakpoint_auto_delete (bs)
5810 bpstat bs;
5811{
5812 struct breakpoint *b, *temp;
5813
5814 for (; bs; bs = bs->next)
c5aa993b 5815 if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
c906108c
SS
5816 && bs->stop)
5817 delete_breakpoint (bs->breakpoint_at);
5818
5819 ALL_BREAKPOINTS_SAFE (b, temp)
c5aa993b
JM
5820 {
5821 if (b->disposition == del_at_next_stop)
5822 delete_breakpoint (b);
5823 }
c906108c
SS
5824}
5825
53a5351d
JM
5826/* Delete a breakpoint and clean up all traces of it in the data
5827 structures. */
c906108c
SS
5828
5829void
5830delete_breakpoint (bpt)
5831 struct breakpoint *bpt;
5832{
5833 register struct breakpoint *b;
5834 register bpstat bs;
5835
5836 if (bpt == NULL)
5837 error ("Internal error (attempted to delete a NULL breakpoint)");
5838
5839
5840 /* Has this bp already been deleted? This can happen because multiple
5841 lists can hold pointers to bp's. bpstat lists are especial culprits.
5842
5843 One example of this happening is a watchpoint's scope bp. When the
5844 scope bp triggers, we notice that the watchpoint is out of scope, and
5845 delete it. We also delete its scope bp. But the scope bp is marked
5846 "auto-deleting", and is already on a bpstat. That bpstat is then
5847 checked for auto-deleting bp's, which are deleted.
5848
5849 A real solution to this problem might involve reference counts in bp's,
5850 and/or giving them pointers back to their referencing bpstat's, and
5851 teaching delete_breakpoint to only free a bp's storage when no more
5852 references were extent. A cheaper bandaid was chosen. */
5853 if (bpt->type == bp_none)
5854 return;
5855
5856 if (delete_breakpoint_hook)
5857 delete_breakpoint_hook (bpt);
104c1213 5858 breakpoint_delete_event (bpt->number);
c906108c
SS
5859
5860 if (bpt->inserted)
5861 remove_breakpoint (bpt, mark_uninserted);
c5aa993b 5862
c906108c
SS
5863 if (breakpoint_chain == bpt)
5864 breakpoint_chain = bpt->next;
5865
5866 /* If we have callback-style exception catchpoints, don't go through
5867 the adjustments to the C++ runtime library etc. if the inferior
5868 isn't actually running. target_enable_exception_callback for a
5869 null target ops vector gives an undesirable error message, so we
5870 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
c5aa993b 5871 exceptions are supported in this way, it's OK for now. FIXME */
c906108c
SS
5872 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
5873 {
5874 static char message1[] = "Error in deleting catchpoint %d:\n";
5875 static char message[sizeof (message1) + 30];
5876 args_for_catchpoint_enable args;
5877
53a5351d
JM
5878 /* Format possible error msg */
5879 sprintf (message, message1, bpt->number);
5880 args.kind = bpt->type == bp_catch_catch ?
5881 EX_EVENT_CATCH : EX_EVENT_THROW;
c906108c
SS
5882 args.enable = 0;
5883 catch_errors (cover_target_enable_exception_callback, &args,
5884 message, RETURN_MASK_ALL);
5885 }
5886
5887
5888 ALL_BREAKPOINTS (b)
5889 if (b->next == bpt)
c5aa993b
JM
5890 {
5891 b->next = bpt->next;
5892 break;
5893 }
c906108c
SS
5894
5895 /* Before turning off the visuals for the bp, check to see that
5896 there are no other bps at the same address. */
5897 if (tui_version)
5898 {
5899 int clearIt;
5900
5901 ALL_BREAKPOINTS (b)
c5aa993b
JM
5902 {
5903 clearIt = (b->address != bpt->address);
5904 if (!clearIt)
5905 break;
5906 }
c906108c
SS
5907
5908 if (clearIt)
c5aa993b
JM
5909 {
5910 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, bpt, 0));
5911 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
5912 }
c906108c
SS
5913 }
5914
5915 check_duplicates (bpt->address, bpt->section);
5916 /* If this breakpoint was inserted, and there is another breakpoint
5917 at the same address, we need to insert the other breakpoint. */
5918 if (bpt->inserted
5919 && bpt->type != bp_hardware_watchpoint
5920 && bpt->type != bp_read_watchpoint
5921 && bpt->type != bp_access_watchpoint
5922 && bpt->type != bp_catch_fork
5923 && bpt->type != bp_catch_vfork
5924 && bpt->type != bp_catch_exec)
5925 {
5926 ALL_BREAKPOINTS (b)
5927 if (b->address == bpt->address
5928 && b->section == bpt->section
5929 && !b->duplicate
5930 && b->enable != disabled
5931 && b->enable != shlib_disabled
5932 && b->enable != call_disabled)
c5aa993b
JM
5933 {
5934 int val;
53a5351d
JM
5935
5936 if (b->type == bp_hardware_breakpoint)
5937 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
5938 else
5939 val = target_insert_breakpoint (b->address, b->shadow_contents);
5940
c5aa993b
JM
5941 if (val != 0)
5942 {
5943 target_terminal_ours_for_output ();
53a5351d 5944 warning ("Cannot insert breakpoint %d:", b->number);
c5aa993b
JM
5945 memory_error (val, b->address); /* which bombs us out */
5946 }
5947 else
5948 b->inserted = 1;
5949 }
c906108c
SS
5950 }
5951
5952 free_command_lines (&bpt->commands);
5953 if (bpt->cond)
5954 free (bpt->cond);
5955 if (bpt->cond_string != NULL)
5956 free (bpt->cond_string);
5957 if (bpt->addr_string != NULL)
5958 free (bpt->addr_string);
5959 if (bpt->exp != NULL)
5960 free (bpt->exp);
5961 if (bpt->exp_string != NULL)
5962 free (bpt->exp_string);
5963 if (bpt->val != NULL)
5964 value_free (bpt->val);
5965 if (bpt->source_file != NULL)
5966 free (bpt->source_file);
5967 if (bpt->dll_pathname != NULL)
5968 free (bpt->dll_pathname);
5969 if (bpt->triggered_dll_pathname != NULL)
5970 free (bpt->triggered_dll_pathname);
5971 if (bpt->exec_pathname != NULL)
5972 free (bpt->exec_pathname);
5973
5974 /* Be sure no bpstat's are pointing at it after it's been freed. */
5975 /* FIXME, how can we find all bpstat's?
5976 We just check stop_bpstat for now. */
5977 for (bs = stop_bpstat; bs; bs = bs->next)
5978 if (bs->breakpoint_at == bpt)
5979 {
5980 bs->breakpoint_at = NULL;
5981
5982 /* we'd call bpstat_clear_actions, but that free's stuff and due
5983 to the multiple pointers pointing to one item with no
5984 reference counts found anywhere through out the bpstat's (how
5985 do you spell fragile?), we don't want to free things twice --
5986 better a memory leak than a corrupt malloc pool! */
5987 bs->commands = NULL;
5988 bs->old_val = NULL;
5989 }
5990 /* On the chance that someone will soon try again to delete this same
5991 bp, we mark it as deleted before freeing its storage. */
5992 bpt->type = bp_none;
5993
c5aa993b 5994 free ((PTR) bpt);
c906108c
SS
5995}
5996
5997void
5998delete_command (arg, from_tty)
5999 char *arg;
6000 int from_tty;
6001{
6002 struct breakpoint *b, *temp;
6003
6004 if (arg == 0)
6005 {
6006 int breaks_to_delete = 0;
6007
6008 /* Delete all breakpoints if no argument.
c5aa993b
JM
6009 Do not delete internal or call-dummy breakpoints, these
6010 have to be deleted with an explicit breakpoint number argument. */
6011 ALL_BREAKPOINTS (b)
6012 {
6013 if (b->type != bp_call_dummy &&
6014 b->type != bp_shlib_event &&
6015 b->number >= 0)
6016 breaks_to_delete = 1;
6017 }
c906108c
SS
6018
6019 /* Ask user only if there are some breakpoints to delete. */
6020 if (!from_tty
6021 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6022 {
c5aa993b
JM
6023 ALL_BREAKPOINTS_SAFE (b, temp)
6024 {
6025 if (b->type != bp_call_dummy &&
6026 b->type != bp_shlib_event &&
6027 b->number >= 0)
6028 delete_breakpoint (b);
6029 }
c906108c
SS
6030 }
6031 }
6032 else
6033 map_breakpoint_numbers (arg, delete_breakpoint);
6034}
6035
6036/* Reset a breakpoint given it's struct breakpoint * BINT.
6037 The value we return ends up being the return value from catch_errors.
6038 Unused in this case. */
6039
6040static int
6041breakpoint_re_set_one (bint)
6042 PTR bint;
6043{
53a5351d
JM
6044 /* get past catch_errs */
6045 struct breakpoint *b = (struct breakpoint *) bint;
c906108c
SS
6046 struct value *mark;
6047 int i;
6048 struct symtabs_and_lines sals;
6049 char *s;
6050 enum enable save_enable;
6051
6052 switch (b->type)
6053 {
6054 case bp_none:
53a5351d
JM
6055 warning ("attempted to reset apparently deleted breakpoint #%d?",
6056 b->number);
c906108c
SS
6057 return 0;
6058 case bp_breakpoint:
6059 case bp_hardware_breakpoint:
6060 case bp_catch_load:
6061 case bp_catch_unload:
6062 if (b->addr_string == NULL)
6063 {
6064 /* Anything without a string can't be re-set. */
6065 delete_breakpoint (b);
6066 return 0;
6067 }
6068 /* In case we have a problem, disable this breakpoint. We'll restore
c5aa993b 6069 its status if we succeed. */
c906108c
SS
6070 save_enable = b->enable;
6071 b->enable = disabled;
6072
6073 set_language (b->language);
6074 input_radix = b->input_radix;
6075 s = b->addr_string;
c5aa993b 6076 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
c906108c
SS
6077 for (i = 0; i < sals.nelts; i++)
6078 {
6079 resolve_sal_pc (&sals.sals[i]);
6080
6081 /* Reparse conditions, they might contain references to the
6082 old symtab. */
6083 if (b->cond_string != NULL)
6084 {
6085 s = b->cond_string;
6086 if (b->cond)
c5aa993b 6087 free ((PTR) b->cond);
c906108c
SS
6088 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6089 }
6090
c5aa993b 6091 /* We need to re-set the breakpoint if the address changes... */
c906108c 6092 if (b->address != sals.sals[i].pc
c5aa993b
JM
6093 /* ...or new and old breakpoints both have source files, and
6094 the source file name or the line number changes... */
c906108c
SS
6095 || (b->source_file != NULL
6096 && sals.sals[i].symtab != NULL
6097 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6098 || b->line_number != sals.sals[i].line)
c906108c 6099 )
c5aa993b
JM
6100 /* ...or we switch between having a source file and not having
6101 one. */
6102 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6103 )
c906108c
SS
6104 {
6105 if (b->source_file != NULL)
6106 free (b->source_file);
6107 if (sals.sals[i].symtab == NULL)
6108 b->source_file = NULL;
6109 else
6110 b->source_file =
6111 savestring (sals.sals[i].symtab->filename,
6112 strlen (sals.sals[i].symtab->filename));
6113 b->line_number = sals.sals[i].line;
6114 b->address = sals.sals[i].pc;
6115
c5aa993b
JM
6116 /* Used to check for duplicates here, but that can
6117 cause trouble, as it doesn't check for disable
6118 breakpoints. */
c906108c
SS
6119
6120 mention (b);
6121
6122 /* Might be better to do this just once per breakpoint_re_set,
c5aa993b 6123 rather than once for every breakpoint. */
c906108c
SS
6124 breakpoints_changed ();
6125 }
6126 b->section = sals.sals[i].section;
6127 b->enable = save_enable; /* Restore it, this worked. */
6128
6129
c5aa993b 6130 /* Now that this is re-enabled, check_duplicates
c906108c 6131 can be used. */
c5aa993b 6132 check_duplicates (b->address, b->section);
c906108c
SS
6133
6134 }
c5aa993b 6135 free ((PTR) sals.sals);
c906108c
SS
6136 break;
6137
6138 case bp_watchpoint:
6139 case bp_hardware_watchpoint:
6140 case bp_read_watchpoint:
6141 case bp_access_watchpoint:
6142 innermost_block = NULL;
53a5351d
JM
6143 /* The issue arises of what context to evaluate this in. The
6144 same one as when it was set, but what does that mean when
6145 symbols have been re-read? We could save the filename and
6146 functionname, but if the context is more local than that, the
6147 best we could do would be something like how many levels deep
6148 and which index at that particular level, but that's going to
6149 be less stable than filenames or function names. */
6150
c906108c
SS
6151 /* So for now, just use a global context. */
6152 if (b->exp)
c5aa993b 6153 free ((PTR) b->exp);
c906108c
SS
6154 b->exp = parse_expression (b->exp_string);
6155 b->exp_valid_block = innermost_block;
6156 mark = value_mark ();
6157 if (b->val)
6158 value_free (b->val);
6159 b->val = evaluate_expression (b->exp);
6160 release_value (b->val);
6161 if (VALUE_LAZY (b->val))
6162 value_fetch_lazy (b->val);
6163
6164 if (b->cond_string != NULL)
6165 {
6166 s = b->cond_string;
6167 if (b->cond)
c5aa993b
JM
6168 free ((PTR) b->cond);
6169 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
c906108c
SS
6170 }
6171 if (b->enable == enabled)
6172 mention (b);
6173 value_free_to_mark (mark);
6174 break;
c5aa993b
JM
6175 case bp_catch_catch:
6176 case bp_catch_throw:
c906108c 6177 break;
c5aa993b
JM
6178 /* We needn't really do anything to reset these, since the mask
6179 that requests them is unaffected by e.g., new libraries being
6180 loaded. */
c906108c
SS
6181 case bp_catch_fork:
6182 case bp_catch_vfork:
6183 case bp_catch_exec:
6184 break;
c5aa993b 6185
c906108c
SS
6186 default:
6187 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
6188 /* fall through */
c5aa993b
JM
6189 /* Delete longjmp breakpoints, they will be reset later by
6190 breakpoint_re_set. */
c906108c
SS
6191 case bp_longjmp:
6192 case bp_longjmp_resume:
6193 delete_breakpoint (b);
6194 break;
6195
c5aa993b
JM
6196 /* This breakpoint is special, it's set up when the inferior
6197 starts and we really don't want to touch it. */
c906108c
SS
6198 case bp_shlib_event:
6199
c5aa993b
JM
6200 /* Keep temporary breakpoints, which can be encountered when we step
6201 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6202 Otherwise these should have been blown away via the cleanup chain
6203 or by breakpoint_init_inferior when we rerun the executable. */
c906108c
SS
6204 case bp_until:
6205 case bp_finish:
6206 case bp_watchpoint_scope:
6207 case bp_call_dummy:
6208 case bp_step_resume:
6209 break;
6210 }
6211
6212 return 0;
6213}
6214
6215/* Re-set all breakpoints after symbols have been re-loaded. */
6216void
6217breakpoint_re_set ()
6218{
6219 struct breakpoint *b, *temp;
6220 enum language save_language;
6221 int save_input_radix;
6222 static char message1[] = "Error in re-setting breakpoint %d:\n";
c5aa993b
JM
6223 char message[sizeof (message1) + 30 /* slop */ ];
6224
c906108c
SS
6225 save_language = current_language->la_language;
6226 save_input_radix = input_radix;
6227 ALL_BREAKPOINTS_SAFE (b, temp)
c5aa993b 6228 {
53a5351d
JM
6229 /* Format possible error msg */
6230 sprintf (message, message1, b->number);
c5aa993b
JM
6231 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
6232 }
c906108c
SS
6233 set_language (save_language);
6234 input_radix = save_input_radix;
6235
6236#ifdef GET_LONGJMP_TARGET
6237 create_longjmp_breakpoint ("longjmp");
6238 create_longjmp_breakpoint ("_longjmp");
6239 create_longjmp_breakpoint ("siglongjmp");
6240 create_longjmp_breakpoint ("_siglongjmp");
6241 create_longjmp_breakpoint (NULL);
6242#endif
6243
6244#if 0
6245 /* Took this out (temporarily at least), since it produces an extra
6246 blank line at startup. This messes up the gdbtests. -PB */
6247 /* Blank line to finish off all those mention() messages we just printed. */
6248 printf_filtered ("\n");
6249#endif
6250}
6251\f
6252/* Set ignore-count of breakpoint number BPTNUM to COUNT.
6253 If from_tty is nonzero, it prints a message to that effect,
6254 which ends with a period (no newline). */
6255
6256/* Reset the thread number of this breakpoint:
6257
6258 - If the breakpoint is for all threads, leave it as-is.
6259 - Else, reset it to the current thread for inferior_pid. */
6260void
6261breakpoint_re_set_thread (b)
c5aa993b 6262 struct breakpoint *b;
c906108c
SS
6263{
6264 if (b->thread != -1)
6265 {
6266 if (in_thread_list (inferior_pid))
c5aa993b 6267 b->thread = pid_to_thread_id (inferior_pid);
c906108c
SS
6268 }
6269}
6270
6271void
6272set_ignore_count (bptnum, count, from_tty)
6273 int bptnum, count, from_tty;
6274{
6275 register struct breakpoint *b;
6276
6277 if (count < 0)
6278 count = 0;
6279
6280 ALL_BREAKPOINTS (b)
6281 if (b->number == bptnum)
c5aa993b
JM
6282 {
6283 b->ignore_count = count;
6284 if (!from_tty)
c906108c 6285 return;
c5aa993b
JM
6286 else if (count == 0)
6287 printf_filtered ("Will stop next time breakpoint %d is reached.",
6288 bptnum);
6289 else if (count == 1)
6290 printf_filtered ("Will ignore next crossing of breakpoint %d.",
6291 bptnum);
6292 else
6293 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
6294 count, bptnum);
6295 breakpoints_changed ();
6296 return;
6297 }
c906108c
SS
6298
6299 error ("No breakpoint number %d.", bptnum);
6300}
6301
6302/* Clear the ignore counts of all breakpoints. */
6303void
6304breakpoint_clear_ignore_counts ()
6305{
6306 struct breakpoint *b;
6307
6308 ALL_BREAKPOINTS (b)
6309 b->ignore_count = 0;
6310}
6311
6312/* Command to set ignore-count of breakpoint N to COUNT. */
6313
6314static void
6315ignore_command (args, from_tty)
6316 char *args;
6317 int from_tty;
6318{
6319 char *p = args;
6320 register int num;
6321
6322 if (p == 0)
6323 error_no_arg ("a breakpoint number");
c5aa993b 6324
c906108c
SS
6325 num = get_number (&p);
6326
6327 if (*p == 0)
6328 error ("Second argument (specified ignore-count) is missing.");
6329
6330 set_ignore_count (num,
6331 longest_to_int (value_as_long (parse_and_eval (p))),
6332 from_tty);
6333 printf_filtered ("\n");
6334 breakpoints_changed ();
6335}
6336\f
6337/* Call FUNCTION on each of the breakpoints
6338 whose numbers are given in ARGS. */
6339
6340static void
6341map_breakpoint_numbers (args, function)
6342 char *args;
6343 void (*function) PARAMS ((struct breakpoint *));
6344{
6345 register char *p = args;
6346 char *p1;
6347 register int num;
6348 register struct breakpoint *b;
6349
6350 if (p == 0)
6351 error_no_arg ("one or more breakpoint numbers");
6352
6353 while (*p)
6354 {
6355 p1 = p;
c5aa993b 6356
c906108c
SS
6357 num = get_number (&p1);
6358
6359 ALL_BREAKPOINTS (b)
6360 if (b->number == num)
c5aa993b
JM
6361 {
6362 struct breakpoint *related_breakpoint = b->related_breakpoint;
6363 function (b);
6364 if (related_breakpoint)
6365 function (related_breakpoint);
6366 goto win;
6367 }
c906108c
SS
6368 printf_unfiltered ("No breakpoint number %d.\n", num);
6369 win:
6370 p = p1;
6371 }
6372}
6373
6374void
6375disable_breakpoint (bpt)
6376 struct breakpoint *bpt;
6377{
6378 /* Never disable a watchpoint scope breakpoint; we want to
6379 hit them when we leave scope so we can delete both the
6380 watchpoint and its scope breakpoint at that time. */
6381 if (bpt->type == bp_watchpoint_scope)
6382 return;
6383
6384 bpt->enable = disabled;
6385
6386 check_duplicates (bpt->address, bpt->section);
6387
6388 if (modify_breakpoint_hook)
6389 modify_breakpoint_hook (bpt);
104c1213 6390 breakpoint_modify_event (bpt->number);
c906108c
SS
6391}
6392
6393/* ARGSUSED */
6394static void
6395disable_command (args, from_tty)
6396 char *args;
6397 int from_tty;
6398{
6399 register struct breakpoint *bpt;
6400 if (args == 0)
6401 ALL_BREAKPOINTS (bpt)
6402 switch (bpt->type)
c5aa993b
JM
6403 {
6404 case bp_none:
53a5351d
JM
6405 warning ("attempted to disable apparently deleted breakpoint #%d?",
6406 bpt->number);
c5aa993b
JM
6407 continue;
6408 case bp_breakpoint:
6409 case bp_catch_load:
6410 case bp_catch_unload:
6411 case bp_catch_fork:
6412 case bp_catch_vfork:
6413 case bp_catch_exec:
6414 case bp_catch_catch:
6415 case bp_catch_throw:
6416 case bp_hardware_breakpoint:
6417 case bp_watchpoint:
6418 case bp_hardware_watchpoint:
6419 case bp_read_watchpoint:
6420 case bp_access_watchpoint:
6421 disable_breakpoint (bpt);
6422 default:
6423 continue;
6424 }
c906108c
SS
6425 else
6426 map_breakpoint_numbers (args, disable_breakpoint);
6427}
6428
6429static void
6430do_enable_breakpoint (bpt, disposition)
6431 struct breakpoint *bpt;
6432 enum bpdisp disposition;
6433{
6434 struct frame_info *save_selected_frame = NULL;
6435 int save_selected_frame_level = -1;
6436 int target_resources_ok, other_type_used;
6437 struct value *mark;
6438
6439 if (bpt->type == bp_hardware_breakpoint)
6440 {
6441 int i;
c5aa993b 6442 i = hw_breakpoint_used_count ();
53a5351d
JM
6443 target_resources_ok =
6444 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
6445 i + 1, 0);
c906108c 6446 if (target_resources_ok == 0)
c5aa993b 6447 error ("No hardware breakpoint support in the target.");
c906108c 6448 else if (target_resources_ok < 0)
c5aa993b 6449 error ("Hardware breakpoints used exceeds limit.");
c906108c
SS
6450 }
6451
6452 bpt->enable = enabled;
6453 bpt->disposition = disposition;
6454 check_duplicates (bpt->address, bpt->section);
6455 breakpoints_changed ();
6456
53a5351d
JM
6457 if (bpt->type == bp_watchpoint ||
6458 bpt->type == bp_hardware_watchpoint ||
6459 bpt->type == bp_read_watchpoint ||
6460 bpt->type == bp_access_watchpoint)
c906108c
SS
6461 {
6462 if (bpt->exp_valid_block != NULL)
6463 {
6464 struct frame_info *fr =
6465
c5aa993b
JM
6466 /* Ensure that we have the current frame. Else, this
6467 next query may pessimistically be answered as, "No,
6468 not within current scope". */
6469 get_current_frame ();
6470 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
c906108c
SS
6471 if (fr == NULL)
6472 {
6473 printf_filtered ("\
6474Cannot enable watchpoint %d because the block in which its expression\n\
6475is valid is not currently in scope.\n", bpt->number);
6476 bpt->enable = disabled;
6477 return;
6478 }
6479
6480 save_selected_frame = selected_frame;
6481 save_selected_frame_level = selected_frame_level;
6482 select_frame (fr, -1);
6483 }
6484
6485 value_free (bpt->val);
6486 mark = value_mark ();
6487 bpt->val = evaluate_expression (bpt->exp);
6488 release_value (bpt->val);
6489 if (VALUE_LAZY (bpt->val))
6490 value_fetch_lazy (bpt->val);
6491
6492 if (bpt->type == bp_hardware_watchpoint ||
c5aa993b
JM
6493 bpt->type == bp_read_watchpoint ||
6494 bpt->type == bp_access_watchpoint)
6495 {
6496 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
6497 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
6498
6499 /* Hack around 'unused var' error for some targets here */
6500 (void) mem_cnt, i;
6501 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
6502 bpt->type, i + mem_cnt, other_type_used);
6503 /* we can consider of type is bp_hardware_watchpoint, convert to
6504 bp_watchpoint in the following condition */
6505 if (target_resources_ok < 0)
6506 {
6507 printf_filtered ("\
c906108c
SS
6508Cannot enable watchpoint %d because target watch resources\n\
6509have been allocated for other watchpoints.\n", bpt->number);
c5aa993b
JM
6510 bpt->enable = disabled;
6511 value_free_to_mark (mark);
6512 return;
6513 }
6514 }
c906108c
SS
6515
6516 if (save_selected_frame_level >= 0)
53a5351d
JM
6517 select_and_print_frame (save_selected_frame,
6518 save_selected_frame_level);
c906108c
SS
6519 value_free_to_mark (mark);
6520 }
6521 if (modify_breakpoint_hook)
6522 modify_breakpoint_hook (bpt);
104c1213 6523 breakpoint_modify_event (bpt->number);
c906108c
SS
6524}
6525
6526void
6527enable_breakpoint (bpt)
6528 struct breakpoint *bpt;
6529{
6530 do_enable_breakpoint (bpt, bpt->disposition);
6531}
6532
6533/* The enable command enables the specified breakpoints (or all defined
6534 breakpoints) so they once again become (or continue to be) effective
6535 in stopping the inferior. */
6536
6537/* ARGSUSED */
6538static void
6539enable_command (args, from_tty)
6540 char *args;
6541 int from_tty;
6542{
6543 register struct breakpoint *bpt;
6544 if (args == 0)
6545 ALL_BREAKPOINTS (bpt)
6546 switch (bpt->type)
c5aa993b
JM
6547 {
6548 case bp_none:
53a5351d
JM
6549 warning ("attempted to enable apparently deleted breakpoint #%d?",
6550 bpt->number);
c5aa993b
JM
6551 continue;
6552 case bp_breakpoint:
6553 case bp_catch_load:
6554 case bp_catch_unload:
6555 case bp_catch_fork:
6556 case bp_catch_vfork:
6557 case bp_catch_exec:
6558 case bp_catch_catch:
6559 case bp_catch_throw:
6560 case bp_hardware_breakpoint:
6561 case bp_watchpoint:
6562 case bp_hardware_watchpoint:
6563 case bp_read_watchpoint:
6564 case bp_access_watchpoint:
6565 enable_breakpoint (bpt);
6566 default:
6567 continue;
6568 }
c906108c
SS
6569 else
6570 map_breakpoint_numbers (args, enable_breakpoint);
6571}
6572
6573static void
6574enable_once_breakpoint (bpt)
6575 struct breakpoint *bpt;
6576{
6577 do_enable_breakpoint (bpt, disable);
6578}
6579
6580/* ARGSUSED */
6581static void
6582enable_once_command (args, from_tty)
6583 char *args;
6584 int from_tty;
6585{
6586 map_breakpoint_numbers (args, enable_once_breakpoint);
6587}
6588
6589static void
6590enable_delete_breakpoint (bpt)
6591 struct breakpoint *bpt;
6592{
6593 do_enable_breakpoint (bpt, del);
6594}
6595
6596/* ARGSUSED */
6597static void
6598enable_delete_command (args, from_tty)
6599 char *args;
6600 int from_tty;
6601{
6602 map_breakpoint_numbers (args, enable_delete_breakpoint);
6603}
6604\f
6605/* Use default_breakpoint_'s, or nothing if they aren't valid. */
6606
6607struct symtabs_and_lines
6608decode_line_spec_1 (string, funfirstline)
6609 char *string;
6610 int funfirstline;
6611{
6612 struct symtabs_and_lines sals;
6613 if (string == 0)
6614 error ("Empty line specification.");
6615 if (default_breakpoint_valid)
6616 sals = decode_line_1 (&string, funfirstline,
53a5351d
JM
6617 default_breakpoint_symtab,
6618 default_breakpoint_line,
c5aa993b 6619 (char ***) NULL);
c906108c
SS
6620 else
6621 sals = decode_line_1 (&string, funfirstline,
c5aa993b 6622 (struct symtab *) NULL, 0, (char ***) NULL);
c906108c
SS
6623 if (*string)
6624 error ("Junk at end of line specification: %s", string);
6625 return sals;
6626}
6627\f
6628void
6629_initialize_breakpoint ()
6630{
6631 struct cmd_list_element *c;
6632
6633 breakpoint_chain = 0;
6634 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
6635 before a breakpoint is set. */
6636 breakpoint_count = 0;
6637
6638 add_com ("ignore", class_breakpoint, ignore_command,
6639 "Set ignore-count of breakpoint number N to COUNT.\n\
6640Usage is `ignore N COUNT'.");
6641 if (xdb_commands)
c5aa993b 6642 add_com_alias ("bc", "ignore", class_breakpoint, 1);
c906108c
SS
6643
6644 add_com ("commands", class_breakpoint, commands_command,
6645 "Set commands to be executed when a breakpoint is hit.\n\
6646Give breakpoint number as argument after \"commands\".\n\
6647With no argument, the targeted breakpoint is the last one set.\n\
6648The commands themselves follow starting on the next line.\n\
6649Type a line containing \"end\" to indicate the end of them.\n\
6650Give \"silent\" as the first line to make the breakpoint silent;\n\
6651then no output is printed when it is hit, except what the commands print.");
6652
6653 add_com ("condition", class_breakpoint, condition_command,
6654 "Specify breakpoint number N to break only if COND is true.\n\
6655Usage is `condition N COND', where N is an integer and COND is an\n\
6656expression to be evaluated whenever breakpoint N is reached. ");
6657
6658 add_com ("tbreak", class_breakpoint, tbreak_command,
6659 "Set a temporary breakpoint. Args like \"break\" command.\n\
6660Like \"break\" except the breakpoint is only temporary,\n\
6661so it will be deleted when hit. Equivalent to \"break\" followed\n\
6662by using \"enable delete\" on the breakpoint number.");
c5aa993b
JM
6663 add_com ("txbreak", class_breakpoint, tbreak_at_finish_command,
6664 "Set temporary breakpoint at procedure exit. Either there should\n\
c906108c
SS
6665be no argument or the argument must be a depth.\n");
6666
6667 add_com ("hbreak", class_breakpoint, hbreak_command,
6668 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
6669Like \"break\" except the breakpoint requires hardware support,\n\
6670some target hardware may not have this support.");
6671
6672 add_com ("thbreak", class_breakpoint, thbreak_command,
6673 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
6674Like \"hbreak\" except the breakpoint is only temporary,\n\
6675so it will be deleted when hit.");
6676
6677 add_prefix_cmd ("enable", class_breakpoint, enable_command,
6678 "Enable some breakpoints.\n\
6679Give breakpoint numbers (separated by spaces) as arguments.\n\
6680With no subcommand, breakpoints are enabled until you command otherwise.\n\
6681This is used to cancel the effect of the \"disable\" command.\n\
6682With a subcommand you can enable temporarily.",
6683 &enablelist, "enable ", 1, &cmdlist);
6684 if (xdb_commands)
c5aa993b
JM
6685 add_com ("ab", class_breakpoint, enable_command,
6686 "Enable some breakpoints.\n\
c906108c
SS
6687Give breakpoint numbers (separated by spaces) as arguments.\n\
6688With no subcommand, breakpoints are enabled until you command otherwise.\n\
6689This is used to cancel the effect of the \"disable\" command.\n\
6690With a subcommand you can enable temporarily.");
6691
6692 add_com_alias ("en", "enable", class_breakpoint, 1);
6693
6694 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
c5aa993b 6695 "Enable some breakpoints.\n\
c906108c
SS
6696Give breakpoint numbers (separated by spaces) as arguments.\n\
6697This is used to cancel the effect of the \"disable\" command.\n\
6698May be abbreviated to simply \"enable\".\n",
c5aa993b 6699 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
c906108c
SS
6700
6701 add_cmd ("once", no_class, enable_once_command,
6702 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
6703If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
6704 &enablebreaklist);
6705
6706 add_cmd ("delete", no_class, enable_delete_command,
6707 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
6708If a breakpoint is hit while enabled in this fashion, it is deleted.",
6709 &enablebreaklist);
6710
6711 add_cmd ("delete", no_class, enable_delete_command,
6712 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
6713If a breakpoint is hit while enabled in this fashion, it is deleted.",
6714 &enablelist);
6715
6716 add_cmd ("once", no_class, enable_once_command,
6717 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
6718If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
6719 &enablelist);
6720
6721 add_prefix_cmd ("disable", class_breakpoint, disable_command,
c5aa993b 6722 "Disable some breakpoints.\n\
c906108c
SS
6723Arguments are breakpoint numbers with spaces in between.\n\
6724To disable all breakpoints, give no argument.\n\
6725A disabled breakpoint is not forgotten, but has no effect until reenabled.",
6726 &disablelist, "disable ", 1, &cmdlist);
6727 add_com_alias ("dis", "disable", class_breakpoint, 1);
6728 add_com_alias ("disa", "disable", class_breakpoint, 1);
6729 if (xdb_commands)
c5aa993b
JM
6730 add_com ("sb", class_breakpoint, disable_command,
6731 "Disable some breakpoints.\n\
c906108c
SS
6732Arguments are breakpoint numbers with spaces in between.\n\
6733To disable all breakpoints, give no argument.\n\
6734A disabled breakpoint is not forgotten, but has no effect until reenabled.");
6735
6736 add_cmd ("breakpoints", class_alias, disable_command,
6737 "Disable some breakpoints.\n\
6738Arguments are breakpoint numbers with spaces in between.\n\
6739To disable all breakpoints, give no argument.\n\
6740A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
6741This command may be abbreviated \"disable\".",
6742 &disablelist);
6743
6744 add_prefix_cmd ("delete", class_breakpoint, delete_command,
c5aa993b 6745 "Delete some breakpoints or auto-display expressions.\n\
c906108c
SS
6746Arguments are breakpoint numbers with spaces in between.\n\
6747To delete all breakpoints, give no argument.\n\
6748\n\
6749Also a prefix command for deletion of other GDB objects.\n\
6750The \"unset\" command is also an alias for \"delete\".",
6751 &deletelist, "delete ", 1, &cmdlist);
6752 add_com_alias ("d", "delete", class_breakpoint, 1);
6753 if (xdb_commands)
6754 add_com ("db", class_breakpoint, delete_command,
c5aa993b 6755 "Delete some breakpoints.\n\
c906108c
SS
6756Arguments are breakpoint numbers with spaces in between.\n\
6757To delete all breakpoints, give no argument.\n");
6758
6759 add_cmd ("breakpoints", class_alias, delete_command,
6760 "Delete some breakpoints or auto-display expressions.\n\
6761Arguments are breakpoint numbers with spaces in between.\n\
6762To delete all breakpoints, give no argument.\n\
6763This command may be abbreviated \"delete\".",
6764 &deletelist);
6765
6766 add_com ("clear", class_breakpoint, clear_command,
6767 concat ("Clear breakpoint at specified line or function.\n\
6768Argument may be line number, function name, or \"*\" and an address.\n\
6769If line number is specified, all breakpoints in that line are cleared.\n\
6770If function is specified, breakpoints at beginning of function are cleared.\n\
6771If an address is specified, breakpoints at that address are cleared.\n\n",
c5aa993b 6772 "With no argument, clears all breakpoints in the line that the selected frame\n\
c906108c
SS
6773is executing in.\n\
6774\n\
6775See also the \"delete\" command which clears breakpoints by number.", NULL));
6776
6777 add_com ("break", class_breakpoint, break_command,
6778 concat ("Set breakpoint at specified line or function.\n\
6779Argument may be line number, function name, or \"*\" and an address.\n\
6780If line number is specified, break at start of code for that line.\n\
6781If function is specified, break at start of code for that function.\n\
6782If an address is specified, break at that exact address.\n",
c5aa993b 6783 "With no arg, uses current execution address of selected stack frame.\n\
c906108c
SS
6784This is useful for breaking on return to a stack frame.\n\
6785\n\
6786Multiple breakpoints at one place are permitted, and useful if conditional.\n\
6787\n\
6788Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
6789 add_com_alias ("b", "break", class_run, 1);
6790 add_com_alias ("br", "break", class_run, 1);
6791 add_com_alias ("bre", "break", class_run, 1);
6792 add_com_alias ("brea", "break", class_run, 1);
6793
c5aa993b
JM
6794 add_com ("xbreak", class_breakpoint, break_at_finish_command,
6795 concat ("Set breakpoint at procedure exit. \n\
c906108c
SS
6796Argument may be function name, or \"*\" and an address.\n\
6797If function is specified, break at end of code for that function.\n\
6798If an address is specified, break at the end of the function that contains \n\
6799that exact address.\n",
c5aa993b 6800 "With no arg, uses current execution address of selected stack frame.\n\
c906108c
SS
6801This is useful for breaking on return to a stack frame.\n\
6802\n\
6803Multiple breakpoints at one place are permitted, and useful if conditional.\n\
6804\n\
6805Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
6806 add_com_alias ("xb", "xbreak", class_breakpoint, 1);
6807 add_com_alias ("xbr", "xbreak", class_breakpoint, 1);
6808 add_com_alias ("xbre", "xbreak", class_breakpoint, 1);
6809 add_com_alias ("xbrea", "xbreak", class_breakpoint, 1);
6810
6811 if (xdb_commands)
6812 {
6813 add_com_alias ("ba", "break", class_breakpoint, 1);
6814 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
6815 add_com ("bx", class_breakpoint, break_at_finish_at_depth_command,
c5aa993b 6816 "Set breakpoint at procedure exit. Either there should\n\
c906108c
SS
6817be no argument or the argument must be a depth.\n");
6818 }
6819
6820 if (dbx_commands)
6821 {
c5aa993b
JM
6822 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
6823 "Break in function/address or break at a line in the current file.",
6824 &stoplist, "stop ", 1, &cmdlist);
6825 add_cmd ("in", class_breakpoint, stopin_command,
6826 "Break in function or address.\n", &stoplist);
6827 add_cmd ("at", class_breakpoint, stopat_command,
6828 "Break at a line in the current file.\n", &stoplist);
6829 add_com ("status", class_info, breakpoints_info,
6830 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
6831The \"Type\" column indicates one of:\n\
6832\tbreakpoint - normal breakpoint\n\
6833\twatchpoint - watchpoint\n\
6834The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6835the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6836breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6837address and file/line number respectively.\n\n",
c5aa993b 6838 "Convenience variable \"$_\" and default examine address for \"x\"\n\
c906108c
SS
6839are set to the address of the last breakpoint listed.\n\n\
6840Convenience variable \"$bpnum\" contains the number of the last\n\
6841breakpoint set.", NULL));
6842 }
6843
6844 add_info ("breakpoints", breakpoints_info,
6845 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
6846The \"Type\" column indicates one of:\n\
6847\tbreakpoint - normal breakpoint\n\
6848\twatchpoint - watchpoint\n\
6849The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6850the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6851breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6852address and file/line number respectively.\n\n",
c5aa993b 6853 "Convenience variable \"$_\" and default examine address for \"x\"\n\
c906108c
SS
6854are set to the address of the last breakpoint listed.\n\n\
6855Convenience variable \"$bpnum\" contains the number of the last\n\
6856breakpoint set.", NULL));
6857
6858 if (xdb_commands)
c5aa993b
JM
6859 add_com ("lb", class_breakpoint, breakpoints_info,
6860 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
6861The \"Type\" column indicates one of:\n\
6862\tbreakpoint - normal breakpoint\n\
6863\twatchpoint - watchpoint\n\
6864The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
6865the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6866breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6867address and file/line number respectively.\n\n",
c5aa993b 6868 "Convenience variable \"$_\" and default examine address for \"x\"\n\
c906108c
SS
6869are set to the address of the last breakpoint listed.\n\n\
6870Convenience variable \"$bpnum\" contains the number of the last\n\
6871breakpoint set.", NULL));
6872
c906108c 6873 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
c5aa993b 6874 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
6875The \"Type\" column indicates one of:\n\
6876\tbreakpoint - normal breakpoint\n\
6877\twatchpoint - watchpoint\n\
6878\tlongjmp - internal breakpoint used to step through longjmp()\n\
6879\tlongjmp resume - internal breakpoint at the target of longjmp()\n\
6880\tuntil - internal breakpoint used by the \"until\" command\n\
6881\tfinish - internal breakpoint used by the \"finish\" command\n",
c5aa993b 6882 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
c906108c
SS
6883the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
6884breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
6885address and file/line number respectively.\n\n",
c5aa993b 6886 "Convenience variable \"$_\" and default examine address for \"x\"\n\
c906108c
SS
6887are set to the address of the last breakpoint listed.\n\n\
6888Convenience variable \"$bpnum\" contains the number of the last\n\
6889breakpoint set.", NULL),
6890 &maintenanceinfolist);
6891
c906108c 6892 add_com ("catch", class_breakpoint, catch_command,
c5aa993b 6893 "Set catchpoints to catch events.\n\
c906108c
SS
6894Raised signals may be caught:\n\
6895\tcatch signal - all signals\n\
6896\tcatch signal <signame> - a particular signal\n\
6897Raised exceptions may be caught:\n\
6898\tcatch throw - all exceptions, when thrown\n\
6899\tcatch throw <exceptname> - a particular exception, when thrown\n\
6900\tcatch catch - all exceptions, when caught\n\
6901\tcatch catch <exceptname> - a particular exception, when caught\n\
6902Thread or process events may be caught:\n\
6903\tcatch thread_start - any threads, just after creation\n\
6904\tcatch thread_exit - any threads, just before expiration\n\
6905\tcatch thread_join - any threads, just after joins\n\
6906Process events may be caught:\n\
6907\tcatch start - any processes, just after creation\n\
6908\tcatch exit - any processes, just before expiration\n\
6909\tcatch fork - calls to fork()\n\
6910\tcatch vfork - calls to vfork()\n\
6911\tcatch exec - calls to exec()\n\
6912Dynamically-linked library events may be caught:\n\
6913\tcatch load - loads of any library\n\
6914\tcatch load <libname> - loads of a particular library\n\
6915\tcatch unload - unloads of any library\n\
6916\tcatch unload <libname> - unloads of a particular library\n\
6917The act of your program's execution stopping may also be caught:\n\
6918\tcatch stop\n\n\
6919C++ exceptions may be caught:\n\
6920\tcatch throw - all exceptions, when thrown\n\
6921\tcatch catch - all exceptions, when caught\n\
6922\n\
6923Do \"help set follow-fork-mode\" for info on debugging your program\n\
6924after a fork or vfork is caught.\n\n\
6925Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
c5aa993b 6926
c906108c 6927 add_com ("tcatch", class_breakpoint, tcatch_command,
c5aa993b 6928 "Set temporary catchpoints to catch events.\n\
c906108c
SS
6929Args like \"catch\" command.\n\
6930Like \"catch\" except the catchpoint is only temporary,\n\
6931so it will be deleted when hit. Equivalent to \"catch\" followed\n\
6932by using \"enable delete\" on the catchpoint number.");
c5aa993b
JM
6933
6934 add_com ("watch", class_breakpoint, watch_command,
c906108c
SS
6935 "Set a watchpoint for an expression.\n\
6936A watchpoint stops execution of your program whenever the value of\n\
6937an expression changes.");
6938
6939 add_com ("rwatch", class_breakpoint, rwatch_command,
6940 "Set a read watchpoint for an expression.\n\
6941A watchpoint stops execution of your program whenever the value of\n\
6942an expression is read.");
6943
6944 add_com ("awatch", class_breakpoint, awatch_command,
6945 "Set a watchpoint for an expression.\n\
6946A watchpoint stops execution of your program whenever the value of\n\
6947an expression is either read or written.");
6948
6949 add_info ("watchpoints", breakpoints_info,
6950 "Synonym for ``info breakpoints''.");
6951
6952
6953 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
c5aa993b
JM
6954 (char *) &can_use_hw_watchpoints,
6955 "Set debugger's willingness to use watchpoint hardware.\n\
c906108c
SS
6956If zero, gdb will not use hardware for new watchpoints, even if\n\
6957such is available. (However, any hardware watchpoints that were\n\
6958created before setting this to nonzero, will continue to use watchpoint\n\
6959hardware.)",
c5aa993b 6960 &setlist);
c906108c
SS
6961 add_show_from_set (c, &showlist);
6962
6963 can_use_hw_watchpoints = 1;
6964}