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