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