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