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