1 /* Everything about breakpoints, for GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
28 #include "breakpoint.h"
30 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb_string.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
53 #include "gdb-events.h"
55 /* Prototypes for local functions. */
57 static void until_break_command_continuation (struct continuation_arg *arg);
59 static void catch_command_1 (char *, int, int);
61 static void enable_delete_command (char *, int);
63 static void enable_delete_breakpoint (struct breakpoint *);
65 static void enable_once_command (char *, int);
67 static void enable_once_breakpoint (struct breakpoint *);
69 static void disable_command (char *, int);
71 static void enable_command (char *, int);
73 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
75 static void ignore_command (char *, int);
77 static int breakpoint_re_set_one (void *);
79 static void clear_command (char *, int);
81 static void catch_command (char *, int);
83 static void watch_command (char *, int);
85 static int can_use_hardware_watchpoint (struct value *);
87 extern void break_at_finish_command (char *, int);
88 extern void break_at_finish_at_depth_command (char *, int);
90 extern void tbreak_at_finish_command (char *, int);
92 static void break_command_1 (char *, int, int);
94 static void mention (struct breakpoint *);
96 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
98 static void check_duplicates (struct breakpoint *);
100 static void describe_other_breakpoints (CORE_ADDR, asection *);
102 static void breakpoints_info (char *, int);
104 static void breakpoint_1 (int, int);
106 static bpstat bpstat_alloc (struct breakpoint *, bpstat);
108 static int breakpoint_cond_eval (void *);
110 static void cleanup_executing_breakpoints (void *);
112 static void commands_command (char *, int);
114 static void condition_command (char *, int);
116 static int get_number_trailer (char **, int);
118 void set_breakpoint_count (int);
127 static int remove_breakpoint (struct breakpoint *, insertion_state_t);
129 static enum print_stop_action print_it_typical (bpstat);
131 static enum print_stop_action print_bp_stop_message (bpstat bs);
135 enum exception_event_kind kind;
138 args_for_catchpoint_enable;
140 static int watchpoint_check (void *);
142 static int cover_target_enable_exception_callback (void *);
144 static void maintenance_info_breakpoints (char *, int);
146 static void create_longjmp_breakpoint (char *);
148 static void create_overlay_event_breakpoint (char *);
150 static int hw_breakpoint_used_count (void);
152 static int hw_watchpoint_used_count (enum bptype, int *);
154 static void hbreak_command (char *, int);
156 static void thbreak_command (char *, int);
158 static void watch_command_1 (char *, int, int);
160 static void rwatch_command (char *, int);
162 static void awatch_command (char *, int);
164 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
166 static void solib_load_unload_1 (char *hookname,
169 char *cond_string, enum bptype bp_kind);
171 static void create_fork_vfork_event_catchpoint (int tempflag,
173 enum bptype bp_kind);
175 static void break_at_finish_at_depth_command_1 (char *arg,
176 int flag, int from_tty);
178 static void break_at_finish_command_1 (char *arg, int flag, int from_tty);
180 static void stop_command (char *arg, int from_tty);
182 static void stopin_command (char *arg, int from_tty);
184 static void stopat_command (char *arg, int from_tty);
186 static char *ep_find_event_name_end (char *arg);
188 static char *ep_parse_optional_if_clause (char **arg);
190 static char *ep_parse_optional_filename (char **arg);
192 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
193 static void catch_exec_command_1 (char *arg, int tempflag, int from_tty);
196 static void create_exception_catchpoint (int tempflag, char *cond_string,
197 enum exception_event_kind ex_event,
198 struct symtab_and_line *sal);
200 static void catch_exception_command_1 (enum exception_event_kind ex_event,
201 char *arg, int tempflag, int from_tty);
203 static void tcatch_command (char *arg, int from_tty);
205 static void ep_skip_leading_whitespace (char **s);
207 /* Prototypes for exported functions. */
209 /* If FALSE, gdb will not use hardware support for watchpoints, even
210 if such is available. */
211 static int can_use_hw_watchpoints;
213 void _initialize_breakpoint (void);
215 extern int addressprint; /* Print machine addresses? */
217 /* Are we executing breakpoint commands? */
218 static int executing_breakpoint_commands;
220 /* Are overlay event breakpoints enabled? */
221 static int overlay_events_enabled;
223 /* Walk the following statement or block through all breakpoints.
224 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
227 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
229 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
230 for (B = breakpoint_chain; \
231 B ? (TMP=B->next, 1): 0; \
234 /* True if SHIFT_INST_REGS defined, false otherwise. */
236 int must_shift_inst_regs =
237 #if defined(SHIFT_INST_REGS)
244 /* True if breakpoint hit counts should be displayed in breakpoint info. */
246 int show_breakpoint_hit_counts = 1;
248 /* Chain of all breakpoints defined. */
250 struct breakpoint *breakpoint_chain;
252 /* Number of last breakpoint made. */
254 int breakpoint_count;
256 /* Pointer to current exception event record */
257 static struct exception_event_record *current_exception_event;
259 /* Indicator of whether exception catchpoints should be nuked
260 between runs of a program */
261 int exception_catchpoints_are_fragile = 0;
263 /* Indicator of when exception catchpoints set-up should be
264 reinitialized -- e.g. when program is re-run */
265 int exception_support_initialized = 0;
267 /* This function returns a pointer to the string representation of the
268 pathname of the dynamically-linked library that has just been
271 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
272 or undefined results are guaranteed.
274 This string's contents are only valid immediately after the
275 inferior has stopped in the dynamic linker hook, and becomes
276 invalid as soon as the inferior is continued. Clients should make
277 a copy of this string if they wish to continue the inferior and
278 then access the string. */
280 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
281 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
284 /* This function returns a pointer to the string representation of the
285 pathname of the dynamically-linked library that has just been
288 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
289 TRUE, or undefined results are guaranteed.
291 This string's contents are only valid immediately after the
292 inferior has stopped in the dynamic linker hook, and becomes
293 invalid as soon as the inferior is continued. Clients should make
294 a copy of this string if they wish to continue the inferior and
295 then access the string. */
297 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
298 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
301 /* This function is called by the "catch load" command. It allows the
302 debugger to be notified by the dynamic linker when a specified
303 library file (or any library file, if filename is NULL) is loaded. */
305 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
306 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
307 error ("catch of library loads not yet implemented on this platform")
310 /* This function is called by the "catch unload" command. It allows
311 the debugger to be notified by the dynamic linker when a specified
312 library file (or any library file, if filename is NULL) is
315 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
316 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
317 error ("catch of library unloads not yet implemented on this platform")
320 /* Set breakpoint count to NUM. */
323 set_breakpoint_count (int num)
325 breakpoint_count = num;
326 set_internalvar (lookup_internalvar ("bpnum"),
327 value_from_longest (builtin_type_int, (LONGEST) num));
330 /* Used in run_command to zero the hit count when a new run starts. */
333 clear_breakpoint_hit_counts (void)
335 struct breakpoint *b;
341 /* Default address, symtab and line to put a breakpoint at
342 for "break" command with no arg.
343 if default_breakpoint_valid is zero, the other three are
344 not valid, and "break" with no arg is an error.
346 This set by print_stack_frame, which calls set_default_breakpoint. */
348 int default_breakpoint_valid;
349 CORE_ADDR default_breakpoint_address;
350 struct symtab *default_breakpoint_symtab;
351 int default_breakpoint_line;
353 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
354 Advance *PP after the string and any trailing whitespace.
356 Currently the string can either be a number or "$" followed by the name
357 of a convenience variable. Making it an expression wouldn't work well
358 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
360 TRAILER is a character which can be found after the number; most
361 commonly this is `-'. If you don't want a trailer, use \0. */
363 get_number_trailer (char **pp, int trailer)
365 int retval = 0; /* default */
369 /* Empty line means refer to the last breakpoint. */
370 return breakpoint_count;
373 /* Make a copy of the name, so we can null-terminate it
374 to pass to lookup_internalvar(). */
379 while (isalnum (*p) || *p == '_')
381 varname = (char *) alloca (p - start + 1);
382 strncpy (varname, start, p - start);
383 varname[p - start] = '\0';
384 val = value_of_internalvar (lookup_internalvar (varname));
385 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
386 retval = (int) value_as_long (val);
389 printf_filtered ("Convenience variable must have integer value.\n");
397 while (*p >= '0' && *p <= '9')
400 /* There is no number here. (e.g. "cond a == b"). */
402 /* Skip non-numeric token */
403 while (*p && !isspace((int) *p))
405 /* Return zero, which caller must interpret as error. */
411 if (!(isspace (*p) || *p == '\0' || *p == trailer))
413 /* Trailing junk: return 0 and let caller print error msg. */
414 while (!(isspace (*p) || *p == '\0' || *p == trailer))
425 /* Like get_number_trailer, but don't allow a trailer. */
427 get_number (char **pp)
429 return get_number_trailer (pp, '\0');
432 /* Parse a number or a range.
433 * A number will be of the form handled by get_number.
434 * A range will be of the form <number1> - <number2>, and
435 * will represent all the integers between number1 and number2,
438 * While processing a range, this fuction is called iteratively;
439 * At each call it will return the next value in the range.
441 * At the beginning of parsing a range, the char pointer PP will
442 * be advanced past <number1> and left pointing at the '-' token.
443 * Subsequent calls will not advance the pointer until the range
444 * is completed. The call that completes the range will advance
445 * pointer PP past <number2>.
449 get_number_or_range (char **pp)
451 static int last_retval, end_value;
452 static char *end_ptr;
453 static int in_range = 0;
457 /* Default case: pp is pointing either to a solo number,
458 or to the first number of a range. */
459 last_retval = get_number_trailer (pp, '-');
464 /* This is the start of a range (<number1> - <number2>).
465 Skip the '-', parse and remember the second number,
466 and also remember the end of the final token. */
470 while (isspace ((int) *end_ptr))
471 end_ptr++; /* skip white space */
472 end_value = get_number (temp);
473 if (end_value < last_retval)
475 error ("inverted range");
477 else if (end_value == last_retval)
479 /* degenerate range (number1 == number2). Advance the
480 token pointer so that the range will be treated as a
489 error ("negative value");
492 /* pp points to the '-' that betokens a range. All
493 number-parsing has already been done. Return the next
494 integer value (one greater than the saved previous value).
495 Do not advance the token pointer 'pp' until the end of range
498 if (++last_retval == end_value)
500 /* End of range reached; advance token pointer. */
510 /* condition N EXP -- set break condition of breakpoint N to EXP. */
513 condition_command (char *arg, int from_tty)
515 register struct breakpoint *b;
520 error_no_arg ("breakpoint number");
523 bnum = get_number (&p);
525 error ("Bad breakpoint argument: '%s'", arg);
528 if (b->number == bnum)
535 if (b->cond_string != NULL)
536 xfree (b->cond_string);
541 b->cond_string = NULL;
543 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
548 /* I don't know if it matters whether this is the string the user
549 typed in or the decompiled expression. */
550 b->cond_string = savestring (arg, strlen (arg));
551 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
553 error ("Junk at end of expression");
555 breakpoints_changed ();
556 breakpoint_modify_event (b->number);
560 error ("No breakpoint number %d.", bnum);
565 commands_command (char *arg, int from_tty)
567 register struct breakpoint *b;
570 struct command_line *l;
572 /* If we allowed this, we would have problems with when to
573 free the storage, if we change the commands currently
576 if (executing_breakpoint_commands)
577 error ("Can't use the \"commands\" command among a breakpoint's commands.");
580 bnum = get_number (&p);
583 error ("Unexpected extra arguments following breakpoint number.");
586 if (b->number == bnum)
590 "Type commands for when breakpoint %d is hit, one per line.",
592 l = read_command_lines (tmpbuf, from_tty);
593 free_command_lines (&b->commands);
595 breakpoints_changed ();
596 breakpoint_modify_event (b->number);
599 error ("No breakpoint number %d.", bnum);
602 /* Like target_read_memory() but if breakpoints are inserted, return
603 the shadow contents instead of the breakpoints themselves.
605 Read "memory data" from whatever target or inferior we have.
606 Returns zero if successful, errno value if not. EIO is used
607 for address out of bounds. If breakpoints are inserted, returns
608 shadow contents, not the breakpoints themselves. From breakpoint.c. */
611 read_memory_nobpt (CORE_ADDR memaddr, char *myaddr, unsigned len)
614 struct breakpoint *b;
615 CORE_ADDR bp_addr = 0;
618 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
619 /* No breakpoints on this machine. */
620 return target_read_memory (memaddr, myaddr, len);
624 if (b->type == bp_none)
625 warning ("reading through apparently deleted breakpoint #%d?",
628 /* memory breakpoint? */
629 if (b->type == bp_watchpoint
630 || b->type == bp_hardware_watchpoint
631 || b->type == bp_read_watchpoint
632 || b->type == bp_access_watchpoint)
637 /* Addresses and length of the part of the breakpoint that
639 /* XXXX The m68k, sh and h8300 have different local and remote
640 breakpoint values. BREAKPOINT_FROM_PC still manages to
641 correctly determine the breakpoints memory address and size
642 for these targets. */
643 bp_addr = b->address;
645 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
650 if (bp_addr + bp_size <= memaddr)
651 /* The breakpoint is entirely before the chunk of memory we
654 if (bp_addr >= memaddr + len)
655 /* The breakpoint is entirely after the chunk of memory we are
658 /* Copy the breakpoint from the shadow contents, and recurse for
659 the things before and after. */
661 /* Offset within shadow_contents. */
664 if (bp_addr < memaddr)
666 /* Only copy the second part of the breakpoint. */
667 bp_size -= memaddr - bp_addr;
668 bptoffset = memaddr - bp_addr;
672 if (bp_addr + bp_size > memaddr + len)
674 /* Only copy the first part of the breakpoint. */
675 bp_size -= (bp_addr + bp_size) - (memaddr + len);
678 memcpy (myaddr + bp_addr - memaddr,
679 b->shadow_contents + bptoffset, bp_size);
681 if (bp_addr > memaddr)
683 /* Copy the section of memory before the breakpoint. */
684 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
689 if (bp_addr + bp_size < memaddr + len)
691 /* Copy the section of memory after the breakpoint. */
692 status = read_memory_nobpt (bp_addr + bp_size,
693 myaddr + bp_addr + bp_size - memaddr,
694 memaddr + len - (bp_addr + bp_size));
701 /* Nothing overlaps. Just call read_memory_noerr. */
702 return target_read_memory (memaddr, myaddr, len);
706 /* insert_breakpoints is used when starting or continuing the program.
707 remove_breakpoints is used when the program stops.
708 Both return zero if successful,
709 or an `errno' value if could not write the inferior. */
712 insert_breakpoints (void)
714 register struct breakpoint *b, *temp;
715 int return_val = 0; /* return success code. */
717 int disabled_breaks = 0;
718 int hw_breakpoint_error = 0;
719 #ifdef ONE_PROCESS_WRITETEXT
720 int process_warning = 0;
723 static char message1[] = "Error inserting catchpoint %d:\n";
724 static char message[sizeof (message1) + 30];
726 struct ui_file *tmp_error_stream = mem_fileopen ();
727 make_cleanup_ui_file_delete (tmp_error_stream);
729 /* Explicitly mark the warning -- this will only be printed if
730 there was an error. */
731 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
733 ALL_BREAKPOINTS_SAFE (b, temp)
735 /* Permanent breakpoints cannot be inserted or removed. Disabled
736 breakpoints should not be inserted. */
737 if (b->enable_state != bp_enabled)
740 if ((b->type == bp_watchpoint
741 || b->type == bp_hardware_watchpoint
742 || b->type == bp_read_watchpoint
743 || b->type == bp_access_watchpoint) && (!b->val))
746 val = evaluate_expression (b->exp);
748 if (VALUE_LAZY (val))
749 value_fetch_lazy (val);
752 if (b->type != bp_watchpoint
753 && b->type != bp_hardware_watchpoint
754 && b->type != bp_read_watchpoint
755 && b->type != bp_access_watchpoint
756 && b->type != bp_catch_fork
757 && b->type != bp_catch_vfork
758 && b->type != bp_catch_exec
759 && b->type != bp_catch_throw
760 && b->type != bp_catch_catch
764 /* "Normal" instruction breakpoint: either the standard
765 trap-instruction bp (bp_breakpoint), or a
766 bp_hardware_breakpoint. */
768 /* First check to see if we have to handle an overlay. */
769 if (overlay_debugging == ovly_off
770 || b->section == NULL
771 || !(section_is_overlay (b->section)))
773 /* No overlay handling: just set the breakpoint. */
775 if (b->type == bp_hardware_breakpoint)
776 val = target_insert_hw_breakpoint (b->address,
779 val = target_insert_breakpoint (b->address, b->shadow_contents);
783 /* This breakpoint is in an overlay section.
784 Shall we set a breakpoint at the LMA? */
785 if (!overlay_events_enabled)
787 /* Yes -- overlay event support is not active,
788 so we must try to set a breakpoint at the LMA.
789 This will not work for a hardware breakpoint. */
790 if (b->type == bp_hardware_breakpoint)
791 warning ("hardware breakpoint %d not supported in overlay!\n",
795 CORE_ADDR addr = overlay_unmapped_address (b->address,
797 /* Set a software (trap) breakpoint at the LMA. */
798 val = target_insert_breakpoint (addr, b->shadow_contents);
800 fprintf_unfiltered (tmp_error_stream,
801 "Overlay breakpoint %d failed: in ROM?",
805 /* Shall we set a breakpoint at the VMA? */
806 if (section_is_mapped (b->section))
808 /* Yes. This overlay section is mapped into memory. */
809 if (b->type == bp_hardware_breakpoint)
810 val = target_insert_hw_breakpoint (b->address,
813 val = target_insert_breakpoint (b->address,
818 /* No. This breakpoint will not be inserted.
819 No error, but do not mark the bp as 'inserted'. */
826 /* Can't set the breakpoint. */
827 #if defined (DISABLE_UNSETTABLE_BREAK)
828 if (DISABLE_UNSETTABLE_BREAK (b->address))
830 /* See also: disable_breakpoints_in_shlibs. */
832 b->enable_state = bp_shlib_disabled;
833 if (!disabled_breaks)
835 fprintf_unfiltered (tmp_error_stream,
836 "Cannot insert breakpoint %d.\n",
838 fprintf_unfiltered (tmp_error_stream,
839 "Temporarily disabling shared library breakpoints:\n");
842 fprintf_unfiltered (tmp_error_stream,
843 "breakpoint #%d\n", b->number);
848 #ifdef ONE_PROCESS_WRITETEXT
851 if (b->type == bp_hardware_breakpoint)
853 hw_breakpoint_error = 1;
854 fprintf_unfiltered (tmp_error_stream,
855 "Cannot insert hardware breakpoint %d.\n",
860 fprintf_unfiltered (tmp_error_stream,
861 "Cannot insert breakpoint %d.\n",
863 fprintf_filtered (tmp_error_stream,
864 "Error accessing memory address ");
865 print_address_numeric (b->address, 1, tmp_error_stream);
866 fprintf_filtered (tmp_error_stream, ": %s.\n",
867 safe_strerror (val));
876 return_val = val; /* remember failure */
878 else if (ep_is_exception_catchpoint (b)
883 /* If we get here, we must have a callback mechanism for exception
884 events -- with g++ style embedded label support, we insert
885 ordinary breakpoints and not catchpoints. */
886 /* Format possible error message */
887 sprintf (message, message1, b->number);
889 val = target_insert_breakpoint (b->address, b->shadow_contents);
892 /* Couldn't set breakpoint for some reason */
893 fprintf_unfiltered (tmp_error_stream,
894 "Cannot insert catchpoint %d; disabling it.\n",
896 fprintf_filtered (tmp_error_stream,
897 "Error accessing memory address ");
898 print_address_numeric (b->address, 1, tmp_error_stream);
899 fprintf_filtered (tmp_error_stream, ": %s.\n",
900 safe_strerror (val));
901 b->enable_state = bp_disabled;
905 /* Bp set, now make sure callbacks are enabled */
907 args_for_catchpoint_enable args;
908 args.kind = b->type == bp_catch_catch ?
909 EX_EVENT_CATCH : EX_EVENT_THROW;
911 val = catch_errors (cover_target_enable_exception_callback,
913 message, RETURN_MASK_ALL);
914 if (val != 0 && val != -1)
918 /* Check if something went wrong; val == 0 can be ignored */
921 /* something went wrong */
922 fprintf_unfiltered (tmp_error_stream,
923 "Cannot insert catchpoint %d; disabling it.\n",
925 b->enable_state = bp_disabled;
930 return_val = val; /* remember failure */
933 else if ((b->type == bp_hardware_watchpoint ||
934 b->type == bp_read_watchpoint ||
935 b->type == bp_access_watchpoint)
936 && b->disposition != disp_del_at_next_stop
940 struct frame_info *saved_frame;
941 int saved_level, within_current_scope;
942 struct value *mark = value_mark ();
945 /* Save the current frame and level so we can restore it after
946 evaluating the watchpoint expression on its own frame. */
947 saved_frame = deprecated_selected_frame;
948 saved_level = frame_relative_level (deprecated_selected_frame);
950 /* Determine if the watchpoint is within scope. */
951 if (b->exp_valid_block == NULL)
952 within_current_scope = 1;
955 struct frame_info *fi;
956 fi = frame_find_by_id (b->watchpoint_frame);
957 within_current_scope = (fi != NULL);
958 if (within_current_scope)
962 if (within_current_scope)
964 /* Evaluate the expression and cut the chain of values
965 produced off from the value chain.
967 Make sure the value returned isn't lazy; we use
968 laziness to determine what memory GDB actually needed
969 in order to compute the value of the expression. */
970 v = evaluate_expression (b->exp);
972 value_release_to_mark (mark);
977 /* Look at each value on the value chain. */
978 for (; v; v = v->next)
980 /* If it's a memory location, and GDB actually needed
981 its contents to evaluate the expression, then we
983 if (VALUE_LVAL (v) == lval_memory
986 struct type *vtype = check_typedef (VALUE_TYPE (v));
988 /* We only watch structs and arrays if user asked
989 for it explicitly, never if they just happen to
990 appear in the middle of some value chain. */
991 if (v == b->val_chain
992 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
993 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
998 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
999 len = TYPE_LENGTH (VALUE_TYPE (v));
1001 if (b->type == bp_read_watchpoint)
1003 else if (b->type == bp_access_watchpoint)
1006 val = target_insert_watchpoint (addr, len, type);
1009 /* Don't exit the loop, try to insert
1010 every value on the value chain. That's
1011 because we will be removing all the
1012 watches below, and removing a
1013 watchpoint we didn't insert could have
1021 /* Failure to insert a watchpoint on any memory value in the
1022 value chain brings us here. */
1025 remove_breakpoint (b, mark_uninserted);
1026 hw_breakpoint_error = 1;
1027 fprintf_unfiltered (tmp_error_stream,
1028 "Could not insert hardware watchpoint %d.\n",
1035 printf_filtered ("Hardware watchpoint %d deleted ", b->number);
1036 printf_filtered ("because the program has left the block \n");
1037 printf_filtered ("in which its expression is valid.\n");
1038 if (b->related_breakpoint)
1039 b->related_breakpoint->disposition = disp_del_at_next_stop;
1040 b->disposition = disp_del_at_next_stop;
1043 /* Restore the frame and level. */
1044 if ((saved_frame != deprecated_selected_frame) ||
1045 (saved_level != frame_relative_level (deprecated_selected_frame)))
1046 select_frame (saved_frame);
1049 return_val = val; /* remember failure */
1051 else if ((b->type == bp_catch_fork
1052 || b->type == bp_catch_vfork
1053 || b->type == bp_catch_exec)
1061 val = target_insert_fork_catchpoint (PIDGET (inferior_ptid));
1063 case bp_catch_vfork:
1064 val = target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
1067 val = target_insert_exec_catchpoint (PIDGET (inferior_ptid));
1070 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1075 fprintf_unfiltered (tmp_error_stream,
1076 "Cannot insert catchpoint %d.", b->number);
1082 return_val = val; /* remember failure */
1088 /* If a hardware breakpoint or watchpoint was inserted, add a
1089 message about possibly exhausted resources. */
1090 if (hw_breakpoint_error)
1092 fprintf_unfiltered (tmp_error_stream,
1093 "Could not insert hardware breakpoints:\n\
1094 You may have requested too many hardware breakpoints/watchpoints.\n");
1096 #ifdef ONE_PROCESS_WRITETEXT
1097 if (process_warning)
1098 fprintf_unfiltered (tmp_error_stream,
1099 "The same program may be running in another process.");
1101 target_terminal_ours_for_output ();
1102 error_stream (tmp_error_stream);
1108 remove_breakpoints (void)
1110 register struct breakpoint *b;
1117 val = remove_breakpoint (b, mark_uninserted);
1126 remove_hw_watchpoints (void)
1128 register struct breakpoint *b;
1134 && (b->type == bp_hardware_watchpoint
1135 || b->type == bp_read_watchpoint
1136 || b->type == bp_access_watchpoint))
1138 val = remove_breakpoint (b, mark_uninserted);
1147 reattach_breakpoints (int pid)
1149 register struct breakpoint *b;
1151 struct cleanup *old_chain = save_inferior_ptid ();
1153 /* Set inferior_ptid; remove_breakpoint uses this global. */
1154 inferior_ptid = pid_to_ptid (pid);
1159 remove_breakpoint (b, mark_inserted);
1160 if (b->type == bp_hardware_breakpoint)
1161 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1163 val = target_insert_breakpoint (b->address, b->shadow_contents);
1166 do_cleanups (old_chain);
1171 do_cleanups (old_chain);
1176 update_breakpoints_after_exec (void)
1178 struct breakpoint *b;
1179 struct breakpoint *temp;
1181 /* Doing this first prevents the badness of having delete_breakpoint()
1182 write a breakpoint's current "shadow contents" to lift the bp. That
1183 shadow is NOT valid after an exec()! */
1184 mark_breakpoints_out ();
1186 ALL_BREAKPOINTS_SAFE (b, temp)
1188 /* Solib breakpoints must be explicitly reset after an exec(). */
1189 if (b->type == bp_shlib_event)
1191 delete_breakpoint (b);
1195 /* Thread event breakpoints must be set anew after an exec(),
1196 as must overlay event breakpoints. */
1197 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1199 delete_breakpoint (b);
1203 /* Step-resume breakpoints are meaningless after an exec(). */
1204 if (b->type == bp_step_resume)
1206 delete_breakpoint (b);
1210 /* Ditto the sigtramp handler breakpoints. */
1211 if (b->type == bp_through_sigtramp)
1213 delete_breakpoint (b);
1217 /* Ditto the exception-handling catchpoints. */
1218 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1220 delete_breakpoint (b);
1224 /* Don't delete an exec catchpoint, because else the inferior
1225 won't stop when it ought!
1227 Similarly, we probably ought to keep vfork catchpoints, 'cause
1228 on this target, we may not be able to stop when the vfork is
1229 seen, but only when the subsequent exec is seen. (And because
1230 deleting fork catchpoints here but not vfork catchpoints will
1231 seem mysterious to users, keep those too.)
1233 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1234 target address field, if any, is sufficient to have it be reset
1235 automagically. Certainly on HP-UX that's true.
1237 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1238 valid code address on some platforms (like the OBSOLETE mn10200
1239 and mn10300 simulators). We shouldn't assign any special
1240 interpretation to a breakpoint with a zero address. And in
1241 fact, GDB doesn't --- I can't see what that comment above is
1242 talking about. As far as I can tell, setting the address of a
1243 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1244 is meaningless, since those are implemented with HP-UX kernel
1245 hackery, not by storing breakpoint instructions somewhere. */
1246 if ((b->type == bp_catch_exec) ||
1247 (b->type == bp_catch_vfork) ||
1248 (b->type == bp_catch_fork))
1250 b->address = (CORE_ADDR) NULL;
1254 /* bp_finish is a special case. The only way we ought to be able
1255 to see one of these when an exec() has happened, is if the user
1256 caught a vfork, and then said "finish". Ordinarily a finish just
1257 carries them to the call-site of the current callee, by setting
1258 a temporary bp there and resuming. But in this case, the finish
1259 will carry them entirely through the vfork & exec.
1261 We don't want to allow a bp_finish to remain inserted now. But
1262 we can't safely delete it, 'cause finish_command has a handle to
1263 the bp on a bpstat, and will later want to delete it. There's a
1264 chance (and I've seen it happen) that if we delete the bp_finish
1265 here, that its storage will get reused by the time finish_command
1266 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1267 We really must allow finish_command to delete a bp_finish.
1269 In the absense of a general solution for the "how do we know
1270 it's safe to delete something others may have handles to?"
1271 problem, what we'll do here is just uninsert the bp_finish, and
1272 let finish_command delete it.
1274 (We know the bp_finish is "doomed" in the sense that it's
1275 momentary, and will be deleted as soon as finish_command sees
1276 the inferior stopped. So it doesn't matter that the bp's
1277 address is probably bogus in the new a.out, unlike e.g., the
1278 solib breakpoints.) */
1280 if (b->type == bp_finish)
1285 /* Without a symbolic address, we have little hope of the
1286 pre-exec() address meaning the same thing in the post-exec()
1288 if (b->addr_string == NULL)
1290 delete_breakpoint (b);
1294 /* If this breakpoint has survived the above battery of checks, then
1295 it must have a symbolic address. Be sure that it gets reevaluated
1296 to a target address, rather than reusing the old evaluation.
1298 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1299 for bp_catch_exec and friends, I'm pretty sure this is entirely
1300 unnecessary. A call to breakpoint_re_set_one always recomputes
1301 the breakpoint's address from scratch, or deletes it if it can't.
1302 So I think this assignment could be deleted without effect. */
1303 b->address = (CORE_ADDR) NULL;
1305 /* FIXME what about longjmp breakpoints? Re-create them here? */
1306 create_overlay_event_breakpoint ("_ovly_debug_event");
1310 detach_breakpoints (int pid)
1312 register struct breakpoint *b;
1314 struct cleanup *old_chain = save_inferior_ptid ();
1316 if (pid == PIDGET (inferior_ptid))
1317 error ("Cannot detach breakpoints of inferior_ptid");
1319 /* Set inferior_ptid; remove_breakpoint uses this global. */
1320 inferior_ptid = pid_to_ptid (pid);
1325 val = remove_breakpoint (b, mark_inserted);
1328 do_cleanups (old_chain);
1333 do_cleanups (old_chain);
1338 remove_breakpoint (struct breakpoint *b, insertion_state_t is)
1342 if (b->enable_state == bp_permanent)
1343 /* Permanent breakpoints cannot be inserted or removed. */
1346 if (b->type == bp_none)
1347 warning ("attempted to remove apparently deleted breakpoint #%d?",
1350 if (b->type != bp_watchpoint
1351 && b->type != bp_hardware_watchpoint
1352 && b->type != bp_read_watchpoint
1353 && b->type != bp_access_watchpoint
1354 && b->type != bp_catch_fork
1355 && b->type != bp_catch_vfork
1356 && b->type != bp_catch_exec
1357 && b->type != bp_catch_catch
1358 && b->type != bp_catch_throw)
1360 /* "Normal" instruction breakpoint: either the standard
1361 trap-instruction bp (bp_breakpoint), or a
1362 bp_hardware_breakpoint. */
1364 /* First check to see if we have to handle an overlay. */
1365 if (overlay_debugging == ovly_off
1366 || b->section == NULL
1367 || !(section_is_overlay (b->section)))
1369 /* No overlay handling: just remove the breakpoint. */
1371 if (b->type == bp_hardware_breakpoint)
1372 val = target_remove_hw_breakpoint (b->address,
1373 b->shadow_contents);
1375 val = target_remove_breakpoint (b->address, b->shadow_contents);
1379 /* This breakpoint is in an overlay section.
1380 Did we set a breakpoint at the LMA? */
1381 if (!overlay_events_enabled)
1383 /* Yes -- overlay event support is not active, so we
1384 should have set a breakpoint at the LMA. Remove it.
1386 CORE_ADDR addr = overlay_unmapped_address (b->address,
1388 /* Ignore any failures: if the LMA is in ROM, we will
1389 have already warned when we failed to insert it. */
1390 if (b->type != bp_hardware_breakpoint)
1391 target_remove_hw_breakpoint (addr, b->shadow_contents);
1393 target_remove_breakpoint (addr, b->shadow_contents);
1395 /* Did we set a breakpoint at the VMA?
1396 If so, we will have marked the breakpoint 'inserted'. */
1399 /* Yes -- remove it. Previously we did not bother to
1400 remove the breakpoint if the section had been
1401 unmapped, but let's not rely on that being safe. We
1402 don't know what the overlay manager might do. */
1403 if (b->type == bp_hardware_breakpoint)
1404 val = target_remove_hw_breakpoint (b->address,
1405 b->shadow_contents);
1407 val = target_remove_breakpoint (b->address,
1408 b->shadow_contents);
1412 /* No -- not inserted, so no need to remove. No error. */
1418 b->inserted = (is == mark_inserted);
1420 else if ((b->type == bp_hardware_watchpoint ||
1421 b->type == bp_read_watchpoint ||
1422 b->type == bp_access_watchpoint)
1423 && b->enable_state == bp_enabled
1429 b->inserted = (is == mark_inserted);
1430 /* Walk down the saved value chain. */
1431 for (v = b->val_chain; v; v = v->next)
1433 /* For each memory reference remove the watchpoint
1435 if (VALUE_LVAL (v) == lval_memory
1436 && ! VALUE_LAZY (v))
1438 struct type *vtype = check_typedef (VALUE_TYPE (v));
1440 if (v == b->val_chain
1441 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1442 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1447 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1448 len = TYPE_LENGTH (VALUE_TYPE (v));
1450 if (b->type == bp_read_watchpoint)
1452 else if (b->type == bp_access_watchpoint)
1455 val = target_remove_watchpoint (addr, len, type);
1462 /* Failure to remove any of the hardware watchpoints comes here. */
1463 if ((is == mark_uninserted) && (b->inserted))
1464 warning ("Could not remove hardware watchpoint %d.",
1467 /* Free the saved value chain. We will construct a new one
1468 the next time the watchpoint is inserted. */
1469 for (v = b->val_chain; v; v = n)
1474 b->val_chain = NULL;
1476 else if ((b->type == bp_catch_fork ||
1477 b->type == bp_catch_vfork ||
1478 b->type == bp_catch_exec)
1479 && b->enable_state == bp_enabled
1486 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1488 case bp_catch_vfork:
1489 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1492 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1495 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1500 b->inserted = (is == mark_inserted);
1502 else if ((b->type == bp_catch_catch ||
1503 b->type == bp_catch_throw)
1504 && b->enable_state == bp_enabled
1508 val = target_remove_breakpoint (b->address, b->shadow_contents);
1511 b->inserted = (is == mark_inserted);
1513 else if (ep_is_exception_catchpoint (b)
1514 && b->inserted /* sometimes previous insert doesn't happen */
1515 && b->enable_state == bp_enabled
1519 val = target_remove_breakpoint (b->address, b->shadow_contents);
1523 b->inserted = (is == mark_inserted);
1529 /* Clear the "inserted" flag in all breakpoints. */
1532 mark_breakpoints_out (void)
1534 register struct breakpoint *b;
1540 /* Clear the "inserted" flag in all breakpoints and delete any
1541 breakpoints which should go away between runs of the program.
1543 Plus other such housekeeping that has to be done for breakpoints
1546 Note: this function gets called at the end of a run (by
1547 generic_mourn_inferior) and when a run begins (by
1548 init_wait_for_inferior). */
1553 breakpoint_init_inferior (enum inf_context context)
1555 register struct breakpoint *b, *temp;
1556 static int warning_needed = 0;
1558 ALL_BREAKPOINTS_SAFE (b, temp)
1565 case bp_watchpoint_scope:
1567 /* If the call dummy breakpoint is at the entry point it will
1568 cause problems when the inferior is rerun, so we better
1571 Also get rid of scope breakpoints. */
1572 delete_breakpoint (b);
1576 case bp_hardware_watchpoint:
1577 case bp_read_watchpoint:
1578 case bp_access_watchpoint:
1580 /* Likewise for watchpoints on local expressions. */
1581 if (b->exp_valid_block != NULL)
1582 delete_breakpoint (b);
1583 if (context == inf_starting)
1585 /* Reset val field to force reread of starting value
1586 in insert_breakpoints. */
1588 value_free (b->val);
1593 /* Likewise for exception catchpoints in dynamic-linked
1594 executables where required */
1595 if (ep_is_exception_catchpoint (b) &&
1596 exception_catchpoints_are_fragile)
1599 delete_breakpoint (b);
1605 if (exception_catchpoints_are_fragile)
1606 exception_support_initialized = 0;
1608 /* Don't issue the warning unless it's really needed... */
1609 if (warning_needed && (context != inf_exited))
1611 warning ("Exception catchpoints from last run were deleted.");
1612 warning ("You must reinsert them explicitly.");
1617 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1618 exists at PC. It returns ordinary_breakpoint_here if it's an
1619 ordinary breakpoint, or permanent_breakpoint_here if it's a
1620 permanent breakpoint.
1621 - When continuing from a location with an ordinary breakpoint, we
1622 actually single step once before calling insert_breakpoints.
1623 - When continuing from a localion with a permanent breakpoint, we
1624 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1625 the target, to advance the PC past the breakpoint. */
1627 enum breakpoint_here
1628 breakpoint_here_p (CORE_ADDR pc)
1630 register struct breakpoint *b;
1631 int any_breakpoint_here = 0;
1634 if ((b->enable_state == bp_enabled
1635 || b->enable_state == bp_permanent)
1636 && b->address == pc) /* bp is enabled and matches pc */
1638 if (overlay_debugging
1639 && section_is_overlay (b->section)
1640 && !section_is_mapped (b->section))
1641 continue; /* unmapped overlay -- can't be a match */
1642 else if (b->enable_state == bp_permanent)
1643 return permanent_breakpoint_here;
1645 any_breakpoint_here = 1;
1648 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1652 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1653 but it only returns true if there is actually a breakpoint inserted
1657 breakpoint_inserted_here_p (CORE_ADDR pc)
1659 register struct breakpoint *b;
1663 && b->address == pc) /* bp is inserted and matches pc */
1665 if (overlay_debugging
1666 && section_is_overlay (b->section)
1667 && !section_is_mapped (b->section))
1668 continue; /* unmapped overlay -- can't be a match */
1676 /* Return nonzero if FRAME is a dummy frame. We can't use
1677 DEPRECATED_PC_IN_CALL_DUMMY because figuring out the saved SP would
1678 take too much time, at least using frame_register() on the 68k.
1679 This means that for this function to work right a port must use the
1680 bp_call_dummy breakpoint. */
1683 deprecated_frame_in_dummy (struct frame_info *frame)
1685 struct breakpoint *b;
1687 /* This function is used by two files: get_frame_type(), after first
1688 checking that !DEPRECATED_USE_GENERIC_DUMMY_FRAMES; and
1689 sparc-tdep.c, which doesn't yet use generic dummy frames anyway. */
1690 gdb_assert (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES);
1694 if (b->type == bp_call_dummy
1695 && frame_id_eq (b->frame_id, get_frame_id (frame))
1696 /* We need to check the PC as well as the frame on the sparc,
1697 for signals.exp in the testsuite. */
1698 && (get_frame_pc (frame)
1700 - DEPRECATED_SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * DEPRECATED_REGISTER_SIZE))
1701 && get_frame_pc (frame) <= b->address)
1707 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1708 PC is valid for process/thread PID. */
1711 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1713 struct breakpoint *b;
1716 thread = pid_to_thread_id (ptid);
1719 if (b->enable_state != bp_disabled
1720 && b->enable_state != bp_shlib_disabled
1721 && b->enable_state != bp_call_disabled
1723 && (b->thread == -1 || b->thread == thread))
1725 if (overlay_debugging
1726 && section_is_overlay (b->section)
1727 && !section_is_mapped (b->section))
1728 continue; /* unmapped overlay -- can't be a match */
1737 /* bpstat stuff. External routines' interfaces are documented
1741 ep_is_catchpoint (struct breakpoint *ep)
1744 (ep->type == bp_catch_load)
1745 || (ep->type == bp_catch_unload)
1746 || (ep->type == bp_catch_fork)
1747 || (ep->type == bp_catch_vfork)
1748 || (ep->type == bp_catch_exec)
1749 || (ep->type == bp_catch_catch)
1750 || (ep->type == bp_catch_throw);
1752 /* ??rehrauer: Add more kinds here, as are implemented... */
1756 ep_is_shlib_catchpoint (struct breakpoint *ep)
1759 (ep->type == bp_catch_load)
1760 || (ep->type == bp_catch_unload);
1764 ep_is_exception_catchpoint (struct breakpoint *ep)
1767 (ep->type == bp_catch_catch)
1768 || (ep->type == bp_catch_throw);
1771 /* Clear a bpstat so that it says we are not at any breakpoint.
1772 Also free any storage that is part of a bpstat. */
1775 bpstat_clear (bpstat *bsp)
1786 if (p->old_val != NULL)
1787 value_free (p->old_val);
1788 free_command_lines (&p->commands);
1795 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1796 is part of the bpstat is copied as well. */
1799 bpstat_copy (bpstat bs)
1803 bpstat retval = NULL;
1808 for (; bs != NULL; bs = bs->next)
1810 tmp = (bpstat) xmalloc (sizeof (*tmp));
1811 memcpy (tmp, bs, sizeof (*tmp));
1812 if (bs->commands != NULL)
1813 tmp->commands = copy_command_lines (bs->commands);
1814 if (bs->old_val != NULL)
1815 tmp->old_val = value_copy (bs->old_val);
1818 /* This is the first thing in the chain. */
1828 /* Find the bpstat associated with this breakpoint */
1831 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1836 for (; bsp != NULL; bsp = bsp->next)
1838 if (bsp->breakpoint_at == breakpoint)
1844 /* Find a step_resume breakpoint associated with this bpstat.
1845 (If there are multiple step_resume bp's on the list, this function
1846 will arbitrarily pick one.)
1848 It is an error to use this function if BPSTAT doesn't contain a
1849 step_resume breakpoint.
1851 See wait_for_inferior's use of this function. */
1853 bpstat_find_step_resume_breakpoint (bpstat bsp)
1858 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1860 current_thread = pid_to_thread_id (inferior_ptid);
1862 for (; bsp != NULL; bsp = bsp->next)
1864 if ((bsp->breakpoint_at != NULL) &&
1865 (bsp->breakpoint_at->type == bp_step_resume) &&
1866 (bsp->breakpoint_at->thread == current_thread ||
1867 bsp->breakpoint_at->thread == -1))
1868 return bsp->breakpoint_at;
1871 error ("Internal error (no step_resume breakpoint found)");
1875 /* Return the breakpoint number of the first breakpoint we are stopped
1876 at. *BSP upon return is a bpstat which points to the remaining
1877 breakpoints stopped at (but which is not guaranteed to be good for
1878 anything but further calls to bpstat_num).
1879 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1882 bpstat_num (bpstat *bsp)
1884 struct breakpoint *b;
1887 return 0; /* No more breakpoint values */
1890 b = (*bsp)->breakpoint_at;
1891 *bsp = (*bsp)->next;
1893 return -1; /* breakpoint that's been deleted since */
1895 return b->number; /* We have its number */
1899 /* Modify BS so that the actions will not be performed. */
1902 bpstat_clear_actions (bpstat bs)
1904 for (; bs != NULL; bs = bs->next)
1906 free_command_lines (&bs->commands);
1907 if (bs->old_val != NULL)
1909 value_free (bs->old_val);
1915 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1918 cleanup_executing_breakpoints (void *ignore)
1920 executing_breakpoint_commands = 0;
1923 /* Execute all the commands associated with all the breakpoints at this
1924 location. Any of these commands could cause the process to proceed
1925 beyond this point, etc. We look out for such changes by checking
1926 the global "breakpoint_proceeded" after each command. */
1929 bpstat_do_actions (bpstat *bsp)
1932 struct cleanup *old_chain;
1933 struct command_line *cmd;
1935 /* Avoid endless recursion if a `source' command is contained
1937 if (executing_breakpoint_commands)
1940 executing_breakpoint_commands = 1;
1941 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1944 /* Note that (as of this writing), our callers all appear to
1945 be passing us the address of global stop_bpstat. And, if
1946 our calls to execute_control_command cause the inferior to
1947 proceed, that global (and hence, *bsp) will change.
1949 We must be careful to not touch *bsp unless the inferior
1950 has not proceeded. */
1952 /* This pointer will iterate over the list of bpstat's. */
1955 breakpoint_proceeded = 0;
1956 for (; bs != NULL; bs = bs->next)
1961 execute_control_command (cmd);
1963 if (breakpoint_proceeded)
1968 if (breakpoint_proceeded)
1969 /* The inferior is proceeded by the command; bomb out now.
1970 The bpstat chain has been blown away by wait_for_inferior.
1971 But since execution has stopped again, there is a new bpstat
1972 to look at, so start over. */
1975 free_command_lines (&bs->commands);
1977 do_cleanups (old_chain);
1980 /* This is the normal print function for a bpstat. In the future,
1981 much of this logic could (should?) be moved to bpstat_stop_status,
1982 by having it set different print_it values.
1984 Current scheme: When we stop, bpstat_print() is called. It loops
1985 through the bpstat list of things causing this stop, calling the
1986 print_bp_stop_message function on each one. The behavior of the
1987 print_bp_stop_message function depends on the print_it field of
1988 bpstat. If such field so indicates, call this function here.
1990 Return values from this routine (ultimately used by bpstat_print()
1991 and normal_stop() to decide what to do):
1992 PRINT_NOTHING: Means we already printed all we needed to print,
1993 don't print anything else.
1994 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1995 that something to be followed by a location.
1996 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1997 that something to be followed by a location.
1998 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2001 static enum print_stop_action
2002 print_it_typical (bpstat bs)
2004 struct cleanup *old_chain, *ui_out_chain;
2005 struct ui_stream *stb;
2006 stb = ui_out_stream_new (uiout);
2007 old_chain = make_cleanup_ui_out_stream_delete (stb);
2008 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2009 which has since been deleted. */
2010 if (bs->breakpoint_at == NULL)
2011 return PRINT_UNKNOWN;
2013 switch (bs->breakpoint_at->type)
2016 case bp_hardware_breakpoint:
2017 annotate_breakpoint (bs->breakpoint_at->number);
2018 ui_out_text (uiout, "\nBreakpoint ");
2019 if (ui_out_is_mi_like_p (uiout))
2020 ui_out_field_string (uiout, "reason", "breakpoint-hit");
2021 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
2022 ui_out_text (uiout, ", ");
2023 return PRINT_SRC_AND_LOC;
2026 case bp_shlib_event:
2027 /* Did we stop because the user set the stop_on_solib_events
2028 variable? (If so, we report this as a generic, "Stopped due
2029 to shlib event" message.) */
2030 printf_filtered ("Stopped due to shared library event\n");
2031 return PRINT_NOTHING;
2034 case bp_thread_event:
2035 /* Not sure how we will get here.
2036 GDB should not stop for these breakpoints. */
2037 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
2038 return PRINT_NOTHING;
2041 case bp_overlay_event:
2042 /* By analogy with the thread event, GDB should not stop for these. */
2043 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
2044 return PRINT_NOTHING;
2048 annotate_catchpoint (bs->breakpoint_at->number);
2049 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2050 printf_filtered ("loaded");
2051 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2052 return PRINT_SRC_AND_LOC;
2055 case bp_catch_unload:
2056 annotate_catchpoint (bs->breakpoint_at->number);
2057 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2058 printf_filtered ("unloaded");
2059 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2060 return PRINT_SRC_AND_LOC;
2064 annotate_catchpoint (bs->breakpoint_at->number);
2065 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2066 printf_filtered ("forked");
2067 printf_filtered (" process %d), ",
2068 bs->breakpoint_at->forked_inferior_pid);
2069 return PRINT_SRC_AND_LOC;
2072 case bp_catch_vfork:
2073 annotate_catchpoint (bs->breakpoint_at->number);
2074 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2075 printf_filtered ("vforked");
2076 printf_filtered (" process %d), ",
2077 bs->breakpoint_at->forked_inferior_pid);
2078 return PRINT_SRC_AND_LOC;
2082 annotate_catchpoint (bs->breakpoint_at->number);
2083 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2084 bs->breakpoint_at->number,
2085 bs->breakpoint_at->exec_pathname);
2086 return PRINT_SRC_AND_LOC;
2089 case bp_catch_catch:
2090 if (current_exception_event &&
2091 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
2093 annotate_catchpoint (bs->breakpoint_at->number);
2094 printf_filtered ("\nCatchpoint %d (exception caught), ",
2095 bs->breakpoint_at->number);
2096 printf_filtered ("throw location ");
2097 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2098 printf_filtered ("%s:%d",
2099 CURRENT_EXCEPTION_THROW_FILE,
2100 CURRENT_EXCEPTION_THROW_LINE);
2102 printf_filtered ("unknown");
2104 printf_filtered (", catch location ");
2105 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2106 printf_filtered ("%s:%d",
2107 CURRENT_EXCEPTION_CATCH_FILE,
2108 CURRENT_EXCEPTION_CATCH_LINE);
2110 printf_filtered ("unknown");
2112 printf_filtered ("\n");
2113 /* don't bother to print location frame info */
2114 return PRINT_SRC_ONLY;
2118 /* really throw, some other bpstat will handle it */
2119 return PRINT_UNKNOWN;
2123 case bp_catch_throw:
2124 if (current_exception_event &&
2125 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2127 annotate_catchpoint (bs->breakpoint_at->number);
2128 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2129 bs->breakpoint_at->number);
2130 printf_filtered ("throw location ");
2131 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2132 printf_filtered ("%s:%d",
2133 CURRENT_EXCEPTION_THROW_FILE,
2134 CURRENT_EXCEPTION_THROW_LINE);
2136 printf_filtered ("unknown");
2138 printf_filtered (", catch location ");
2139 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2140 printf_filtered ("%s:%d",
2141 CURRENT_EXCEPTION_CATCH_FILE,
2142 CURRENT_EXCEPTION_CATCH_LINE);
2144 printf_filtered ("unknown");
2146 printf_filtered ("\n");
2147 /* don't bother to print location frame info */
2148 return PRINT_SRC_ONLY;
2152 /* really catch, some other bpstat will handle it */
2153 return PRINT_UNKNOWN;
2158 case bp_hardware_watchpoint:
2159 if (bs->old_val != NULL)
2161 annotate_watchpoint (bs->breakpoint_at->number);
2162 if (ui_out_is_mi_like_p (uiout))
2163 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2164 mention (bs->breakpoint_at);
2165 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2166 ui_out_text (uiout, "\nOld value = ");
2167 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2168 ui_out_field_stream (uiout, "old", stb);
2169 ui_out_text (uiout, "\nNew value = ");
2170 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2171 ui_out_field_stream (uiout, "new", stb);
2172 do_cleanups (ui_out_chain);
2173 ui_out_text (uiout, "\n");
2174 value_free (bs->old_val);
2177 /* More than one watchpoint may have been triggered. */
2178 return PRINT_UNKNOWN;
2181 case bp_read_watchpoint:
2182 if (ui_out_is_mi_like_p (uiout))
2183 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2184 mention (bs->breakpoint_at);
2185 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2186 ui_out_text (uiout, "\nValue = ");
2187 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2188 ui_out_field_stream (uiout, "value", stb);
2189 do_cleanups (ui_out_chain);
2190 ui_out_text (uiout, "\n");
2191 return PRINT_UNKNOWN;
2194 case bp_access_watchpoint:
2195 if (bs->old_val != NULL)
2197 annotate_watchpoint (bs->breakpoint_at->number);
2198 if (ui_out_is_mi_like_p (uiout))
2199 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2200 mention (bs->breakpoint_at);
2201 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2202 ui_out_text (uiout, "\nOld value = ");
2203 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2204 ui_out_field_stream (uiout, "old", stb);
2205 value_free (bs->old_val);
2207 ui_out_text (uiout, "\nNew value = ");
2211 mention (bs->breakpoint_at);
2212 if (ui_out_is_mi_like_p (uiout))
2213 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2214 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2215 ui_out_text (uiout, "\nValue = ");
2217 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2218 ui_out_field_stream (uiout, "new", stb);
2219 do_cleanups (ui_out_chain);
2220 ui_out_text (uiout, "\n");
2221 return PRINT_UNKNOWN;
2224 /* Fall through, we don't deal with these types of breakpoints
2228 if (ui_out_is_mi_like_p (uiout))
2229 ui_out_field_string (uiout, "reason", "function-finished");
2230 return PRINT_UNKNOWN;
2234 if (ui_out_is_mi_like_p (uiout))
2235 ui_out_field_string (uiout, "reason", "location-reached");
2236 return PRINT_UNKNOWN;
2241 case bp_longjmp_resume:
2242 case bp_step_resume:
2243 case bp_through_sigtramp:
2244 case bp_watchpoint_scope:
2247 return PRINT_UNKNOWN;
2251 /* Generic routine for printing messages indicating why we
2252 stopped. The behavior of this function depends on the value
2253 'print_it' in the bpstat structure. Under some circumstances we
2254 may decide not to print anything here and delegate the task to
2257 static enum print_stop_action
2258 print_bp_stop_message (bpstat bs)
2260 switch (bs->print_it)
2263 /* Nothing should be printed for this bpstat entry. */
2264 return PRINT_UNKNOWN;
2268 /* We still want to print the frame, but we already printed the
2269 relevant messages. */
2270 return PRINT_SRC_AND_LOC;
2273 case print_it_normal:
2274 /* Normal case. Call the breakpoint's print_it method, or
2275 print_it_typical. */
2276 if (bs->breakpoint_at != NULL && bs->breakpoint_at->ops != NULL
2277 && bs->breakpoint_at->ops->print_it != NULL)
2278 return bs->breakpoint_at->ops->print_it (bs->breakpoint_at);
2280 return print_it_typical (bs);
2284 internal_error (__FILE__, __LINE__,
2285 "print_bp_stop_message: unrecognized enum value");
2290 /* Print a message indicating what happened. This is called from
2291 normal_stop(). The input to this routine is the head of the bpstat
2292 list - a list of the eventpoints that caused this stop. This
2293 routine calls the generic print routine for printing a message
2294 about reasons for stopping. This will print (for example) the
2295 "Breakpoint n," part of the output. The return value of this
2298 PRINT_UNKNOWN: Means we printed nothing
2299 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2300 code to print the location. An example is
2301 "Breakpoint 1, " which should be followed by
2303 PRINT_SRC_ONLY: Means we printed something, but there is no need
2304 to also print the location part of the message.
2305 An example is the catch/throw messages, which
2306 don't require a location appended to the end.
2307 PRINT_NOTHING: We have done some printing and we don't need any
2308 further info to be printed.*/
2310 enum print_stop_action
2311 bpstat_print (bpstat bs)
2315 /* Maybe another breakpoint in the chain caused us to stop.
2316 (Currently all watchpoints go on the bpstat whether hit or not.
2317 That probably could (should) be changed, provided care is taken
2318 with respect to bpstat_explains_signal). */
2319 for (; bs; bs = bs->next)
2321 val = print_bp_stop_message (bs);
2322 if (val == PRINT_SRC_ONLY
2323 || val == PRINT_SRC_AND_LOC
2324 || val == PRINT_NOTHING)
2328 /* We reached the end of the chain, or we got a null BS to start
2329 with and nothing was printed. */
2330 return PRINT_UNKNOWN;
2333 /* Evaluate the expression EXP and return 1 if value is zero.
2334 This is used inside a catch_errors to evaluate the breakpoint condition.
2335 The argument is a "struct expression *" that has been cast to char * to
2336 make it pass through catch_errors. */
2339 breakpoint_cond_eval (void *exp)
2341 struct value *mark = value_mark ();
2342 int i = !value_true (evaluate_expression ((struct expression *) exp));
2343 value_free_to_mark (mark);
2347 /* Allocate a new bpstat and chain it to the current one. */
2350 bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
2354 bs = (bpstat) xmalloc (sizeof (*bs));
2356 bs->breakpoint_at = b;
2357 /* If the condition is false, etc., don't do the commands. */
2358 bs->commands = NULL;
2360 bs->print_it = print_it_normal;
2364 /* Possible return values for watchpoint_check (this can't be an enum
2365 because of check_errors). */
2366 /* The watchpoint has been deleted. */
2367 #define WP_DELETED 1
2368 /* The value has changed. */
2369 #define WP_VALUE_CHANGED 2
2370 /* The value has not changed. */
2371 #define WP_VALUE_NOT_CHANGED 3
2373 #define BP_TEMPFLAG 1
2374 #define BP_HARDWAREFLAG 2
2376 /* Check watchpoint condition. */
2379 watchpoint_check (void *p)
2381 bpstat bs = (bpstat) p;
2382 struct breakpoint *b;
2383 struct frame_info *fr;
2384 int within_current_scope;
2386 b = bs->breakpoint_at;
2388 if (b->exp_valid_block == NULL)
2389 within_current_scope = 1;
2392 /* There is no current frame at this moment. If we're going to have
2393 any chance of handling watchpoints on local variables, we'll need
2394 the frame chain (so we can determine if we're in scope). */
2395 reinit_frame_cache ();
2396 fr = frame_find_by_id (b->watchpoint_frame);
2397 within_current_scope = (fr != NULL);
2398 /* in_function_epilogue_p() returns a non-zero value if we're still
2399 in the function but the stack frame has already been invalidated.
2400 Since we can't rely on the values of local variables after the
2401 stack has been destroyed, we are treating the watchpoint in that
2402 state as `not changed' without further checking. */
2403 if (within_current_scope && fr == get_current_frame ()
2404 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2405 return WP_VALUE_NOT_CHANGED;
2406 if (within_current_scope)
2407 /* If we end up stopping, the current frame will get selected
2408 in normal_stop. So this call to select_frame won't affect
2413 if (within_current_scope)
2415 /* We use value_{,free_to_}mark because it could be a
2416 *long* time before we return to the command level and
2417 call free_all_values. We can't call free_all_values because
2418 we might be in the middle of evaluating a function call. */
2420 struct value *mark = value_mark ();
2421 struct value *new_val = evaluate_expression (bs->breakpoint_at->exp);
2422 if (!value_equal (b->val, new_val))
2424 release_value (new_val);
2425 value_free_to_mark (mark);
2426 bs->old_val = b->val;
2428 /* We will stop here */
2429 return WP_VALUE_CHANGED;
2433 /* Nothing changed, don't do anything. */
2434 value_free_to_mark (mark);
2435 /* We won't stop here */
2436 return WP_VALUE_NOT_CHANGED;
2441 /* This seems like the only logical thing to do because
2442 if we temporarily ignored the watchpoint, then when
2443 we reenter the block in which it is valid it contains
2444 garbage (in the case of a function, it may have two
2445 garbage values, one before and one after the prologue).
2446 So we can't even detect the first assignment to it and
2447 watch after that (since the garbage may or may not equal
2448 the first value assigned). */
2449 /* We print all the stop information in print_it_typical(), but
2450 in this case, by the time we call print_it_typical() this bp
2451 will be deleted already. So we have no choice but print the
2452 information here. */
2453 if (ui_out_is_mi_like_p (uiout))
2454 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2455 ui_out_text (uiout, "\nWatchpoint ");
2456 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2457 ui_out_text (uiout, " deleted because the program has left the block in\n\
2458 which its expression is valid.\n");
2460 if (b->related_breakpoint)
2461 b->related_breakpoint->disposition = disp_del_at_next_stop;
2462 b->disposition = disp_del_at_next_stop;
2468 /* Get a bpstat associated with having just stopped at address *PC
2469 and frame address CORE_ADDRESS. Update *PC to point at the
2470 breakpoint (if we hit a breakpoint). NOT_A_SW_BREAKPOINT is nonzero
2471 if this is known to not be a real breakpoint (it could still be a
2472 watchpoint, though). */
2474 /* Determine whether we stopped at a breakpoint, etc, or whether we
2475 don't understand this stop. Result is a chain of bpstat's such that:
2477 if we don't understand the stop, the result is a null pointer.
2479 if we understand why we stopped, the result is not null.
2481 Each element of the chain refers to a particular breakpoint or
2482 watchpoint at which we have stopped. (We may have stopped for
2483 several reasons concurrently.)
2485 Each element of the chain has valid next, breakpoint_at,
2486 commands, FIXME??? fields. */
2489 bpstat_stop_status (CORE_ADDR *pc, int not_a_sw_breakpoint)
2491 register struct breakpoint *b, *temp;
2493 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2494 int real_breakpoint = 0;
2495 /* Root of the chain of bpstat's */
2496 struct bpstats root_bs[1];
2497 /* Pointer to the last thing in the chain currently. */
2498 bpstat bs = root_bs;
2499 static char message1[] =
2500 "Error evaluating expression for watchpoint %d\n";
2501 char message[sizeof (message1) + 30 /* slop */ ];
2503 /* Get the address where the breakpoint would have been. The
2504 "not_a_sw_breakpoint" argument is meant to distinguish between a
2505 breakpoint trap event and a trace/singlestep trap event. For a
2506 trace/singlestep trap event, we would not want to subtract
2507 DECR_PC_AFTER_BREAK from the PC. */
2509 bp_addr = *pc - (not_a_sw_breakpoint ? 0 : DECR_PC_AFTER_BREAK);
2511 ALL_BREAKPOINTS_SAFE (b, temp)
2513 if (b->enable_state == bp_disabled
2514 || b->enable_state == bp_shlib_disabled
2515 || b->enable_state == bp_call_disabled)
2518 if (b->type != bp_watchpoint
2519 && b->type != bp_hardware_watchpoint
2520 && b->type != bp_read_watchpoint
2521 && b->type != bp_access_watchpoint
2522 && b->type != bp_hardware_breakpoint
2523 && b->type != bp_catch_fork
2524 && b->type != bp_catch_vfork
2525 && b->type != bp_catch_exec
2526 && b->type != bp_catch_catch
2527 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2529 if (b->address != bp_addr) /* address doesn't match */
2531 if (overlay_debugging /* unmapped overlay section */
2532 && section_is_overlay (b->section)
2533 && !section_is_mapped (b->section))
2537 if (b->type == bp_hardware_breakpoint)
2539 if (b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2541 if (overlay_debugging /* unmapped overlay section */
2542 && section_is_overlay (b->section)
2543 && !section_is_mapped (b->section))
2547 /* Is this a catchpoint of a load or unload? If so, did we
2548 get a load or unload of the specified library? If not,
2550 if ((b->type == bp_catch_load)
2551 #if defined(SOLIB_HAVE_LOAD_EVENT)
2552 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2553 || ((b->dll_pathname != NULL)
2554 && (strcmp (b->dll_pathname,
2555 SOLIB_LOADED_LIBRARY_PATHNAME (
2556 PIDGET (inferior_ptid)))
2562 if ((b->type == bp_catch_unload)
2563 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2564 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2565 || ((b->dll_pathname != NULL)
2566 && (strcmp (b->dll_pathname,
2567 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2568 PIDGET (inferior_ptid)))
2574 if ((b->type == bp_catch_fork)
2575 && !inferior_has_forked (PIDGET (inferior_ptid),
2576 &b->forked_inferior_pid))
2579 if ((b->type == bp_catch_vfork)
2580 && !inferior_has_vforked (PIDGET (inferior_ptid),
2581 &b->forked_inferior_pid))
2584 if ((b->type == bp_catch_exec)
2585 && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2588 if (ep_is_exception_catchpoint (b) &&
2589 !(current_exception_event = target_get_current_exception_event ()))
2592 /* Come here if it's a watchpoint, or if the break address matches */
2594 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2596 /* Watchpoints may change this, if not found to have triggered. */
2600 sprintf (message, message1, b->number);
2601 if (b->type == bp_watchpoint ||
2602 b->type == bp_hardware_watchpoint)
2604 switch (catch_errors (watchpoint_check, bs, message,
2608 /* We've already printed what needs to be printed. */
2609 /* Actually this is superfluous, because by the time we
2610 call print_it_typical() the wp will be already deleted,
2611 and the function will return immediately. */
2612 bs->print_it = print_it_done;
2615 case WP_VALUE_CHANGED:
2619 case WP_VALUE_NOT_CHANGED:
2621 bs->print_it = print_it_noop;
2628 /* Error from catch_errors. */
2629 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2630 if (b->related_breakpoint)
2631 b->related_breakpoint->disposition = disp_del_at_next_stop;
2632 b->disposition = disp_del_at_next_stop;
2633 /* We've already printed what needs to be printed. */
2634 bs->print_it = print_it_done;
2640 else if (b->type == bp_read_watchpoint ||
2641 b->type == bp_access_watchpoint)
2647 addr = target_stopped_data_address ();
2650 for (v = b->val_chain; v; v = v->next)
2652 if (VALUE_LVAL (v) == lval_memory
2653 && ! VALUE_LAZY (v))
2655 struct type *vtype = check_typedef (VALUE_TYPE (v));
2657 if (v == b->val_chain
2658 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2659 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2663 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2664 /* Exact match not required. Within range is
2666 if (addr >= vaddr &&
2667 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2673 switch (catch_errors (watchpoint_check, bs, message,
2677 /* We've already printed what needs to be printed. */
2678 bs->print_it = print_it_done;
2681 case WP_VALUE_CHANGED:
2682 if (b->type == bp_read_watchpoint)
2684 /* Don't stop: read watchpoints shouldn't fire if
2685 the value has changed. This is for targets which
2686 cannot set read-only watchpoints. */
2687 bs->print_it = print_it_noop;
2693 case WP_VALUE_NOT_CHANGED:
2700 /* Error from catch_errors. */
2701 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2702 if (b->related_breakpoint)
2703 b->related_breakpoint->disposition = disp_del_at_next_stop;
2704 b->disposition = disp_del_at_next_stop;
2705 /* We've already printed what needs to be printed. */
2706 bs->print_it = print_it_done;
2709 else /* found == 0 */
2711 /* This is a case where some watchpoint(s) triggered,
2712 but not at the address of this watchpoint (FOUND
2713 was left zero). So don't print anything for this
2715 bs->print_it = print_it_noop;
2722 /* By definition, an encountered breakpoint is a triggered
2726 real_breakpoint = 1;
2729 if (frame_id_p (b->frame_id)
2730 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
2734 int value_is_zero = 0;
2738 /* Need to select the frame, with all that implies
2739 so that the conditions will have the right context. */
2740 select_frame (get_current_frame ());
2742 = catch_errors (breakpoint_cond_eval, (b->cond),
2743 "Error in testing breakpoint condition:\n",
2745 /* FIXME-someday, should give breakpoint # */
2748 if (b->cond && value_is_zero)
2751 /* Don't consider this a hit. */
2754 else if (b->ignore_count > 0)
2757 annotate_ignore_count_change ();
2762 /* We will stop here */
2763 if (b->disposition == disp_disable)
2764 b->enable_state = bp_disabled;
2767 bs->commands = b->commands;
2769 (STREQ ("silent", bs->commands->line) ||
2770 (xdb_commands && STREQ ("Q", bs->commands->line))))
2772 bs->commands = bs->commands->next;
2775 bs->commands = copy_command_lines (bs->commands);
2778 /* Print nothing for this entry if we dont stop or if we dont print. */
2779 if (bs->stop == 0 || bs->print == 0)
2780 bs->print_it = print_it_noop;
2783 bs->next = NULL; /* Terminate the chain */
2784 bs = root_bs->next; /* Re-grab the head of the chain */
2786 if (real_breakpoint && bs)
2788 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2790 if (DECR_PC_AFTER_HW_BREAK != 0)
2792 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2798 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2801 #if defined (SHIFT_INST_REGS)
2803 #else /* No SHIFT_INST_REGS. */
2805 #endif /* No SHIFT_INST_REGS. */
2810 /* The value of a hardware watchpoint hasn't changed, but the
2811 intermediate memory locations we are watching may have. */
2812 if (bs && !bs->stop &&
2813 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2814 bs->breakpoint_at->type == bp_read_watchpoint ||
2815 bs->breakpoint_at->type == bp_access_watchpoint))
2817 remove_breakpoints ();
2818 insert_breakpoints ();
2823 /* Tell what to do about this bpstat. */
2825 bpstat_what (bpstat bs)
2827 /* Classify each bpstat as one of the following. */
2830 /* This bpstat element has no effect on the main_action. */
2833 /* There was a watchpoint, stop but don't print. */
2836 /* There was a watchpoint, stop and print. */
2839 /* There was a breakpoint but we're not stopping. */
2842 /* There was a breakpoint, stop but don't print. */
2845 /* There was a breakpoint, stop and print. */
2848 /* We hit the longjmp breakpoint. */
2851 /* We hit the longjmp_resume breakpoint. */
2854 /* We hit the step_resume breakpoint. */
2857 /* We hit the through_sigtramp breakpoint. */
2860 /* We hit the shared library event breakpoint. */
2863 /* We caught a shared library event. */
2866 /* This is just used to count how many enums there are. */
2870 /* Here is the table which drives this routine. So that we can
2871 format it pretty, we define some abbreviations for the
2872 enum bpstat_what codes. */
2873 #define kc BPSTAT_WHAT_KEEP_CHECKING
2874 #define ss BPSTAT_WHAT_STOP_SILENT
2875 #define sn BPSTAT_WHAT_STOP_NOISY
2876 #define sgl BPSTAT_WHAT_SINGLE
2877 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2878 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2879 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2880 #define sr BPSTAT_WHAT_STEP_RESUME
2881 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2882 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2883 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2885 /* "Can't happen." Might want to print an error message.
2886 abort() is not out of the question, but chances are GDB is just
2887 a bit confused, not unusable. */
2888 #define err BPSTAT_WHAT_STOP_NOISY
2890 /* Given an old action and a class, come up with a new action. */
2891 /* One interesting property of this table is that wp_silent is the same
2892 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2893 after stopping, the check for whether to step over a breakpoint
2894 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2895 reference to how we stopped. We retain separate wp_silent and
2896 bp_silent codes in case we want to change that someday.
2898 Another possibly interesting property of this table is that
2899 there's a partial ordering, priority-like, of the actions. Once
2900 you've decided that some action is appropriate, you'll never go
2901 back and decide something of a lower priority is better. The
2904 kc < clr sgl shl shlr slr sn sr ss ts
2905 sgl < clrs shl shlr slr sn sr ss ts
2906 slr < err shl shlr sn sr ss ts
2907 clr < clrs err shl shlr sn sr ss ts
2908 clrs < err shl shlr sn sr ss ts
2909 ss < shl shlr sn sr ts
2916 What I think this means is that we don't need a damned table
2917 here. If you just put the rows and columns in the right order,
2918 it'd look awfully regular. We could simply walk the bpstat list
2919 and choose the highest priority action we find, with a little
2920 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2921 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2922 is messy anyway). */
2924 /* step_resume entries: a step resume breakpoint overrides another
2925 breakpoint of signal handling (see comment in wait_for_inferior
2926 at first PC_IN_SIGTRAMP where we set the step_resume breakpoint). */
2927 /* We handle the through_sigtramp_breakpoint the same way; having both
2928 one of those and a step_resume_breakpoint is probably very rare (?). */
2930 static const enum bpstat_what_main_action
2931 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2934 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2937 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2939 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2941 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2943 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2945 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2947 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2949 {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr},
2951 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2953 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2955 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2957 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2959 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2974 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2975 struct bpstat_what retval;
2977 retval.call_dummy = 0;
2978 for (; bs != NULL; bs = bs->next)
2980 enum class bs_class = no_effect;
2981 if (bs->breakpoint_at == NULL)
2982 /* I suspect this can happen if it was a momentary breakpoint
2983 which has since been deleted. */
2985 switch (bs->breakpoint_at->type)
2991 case bp_hardware_breakpoint:
2997 bs_class = bp_noisy;
2999 bs_class = bp_silent;
3002 bs_class = bp_nostop;
3005 case bp_hardware_watchpoint:
3006 case bp_read_watchpoint:
3007 case bp_access_watchpoint:
3011 bs_class = wp_noisy;
3013 bs_class = wp_silent;
3016 /* There was a watchpoint, but we're not stopping.
3017 This requires no further action. */
3018 bs_class = no_effect;
3021 bs_class = long_jump;
3023 case bp_longjmp_resume:
3024 bs_class = long_resume;
3026 case bp_step_resume:
3029 bs_class = step_resume;
3032 /* It is for the wrong frame. */
3033 bs_class = bp_nostop;
3035 case bp_through_sigtramp:
3036 bs_class = through_sig;
3038 case bp_watchpoint_scope:
3039 bs_class = bp_nostop;
3041 case bp_shlib_event:
3042 bs_class = shlib_event;
3044 case bp_thread_event:
3045 case bp_overlay_event:
3046 bs_class = bp_nostop;
3049 case bp_catch_unload:
3050 /* Only if this catchpoint triggered should we cause the
3051 step-out-of-dld behaviour. Otherwise, we ignore this
3054 bs_class = catch_shlib_event;
3056 bs_class = no_effect;
3059 case bp_catch_vfork:
3064 bs_class = bp_noisy;
3066 bs_class = bp_silent;
3069 /* There was a catchpoint, but we're not stopping.
3070 This requires no further action. */
3071 bs_class = no_effect;
3073 case bp_catch_catch:
3074 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
3075 bs_class = bp_nostop;
3077 bs_class = bs->print ? bp_noisy : bp_silent;
3079 case bp_catch_throw:
3080 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
3081 bs_class = bp_nostop;
3083 bs_class = bs->print ? bp_noisy : bp_silent;
3086 /* Make sure the action is stop (silent or noisy),
3087 so infrun.c pops the dummy frame. */
3088 bs_class = bp_silent;
3089 retval.call_dummy = 1;
3092 current_action = table[(int) bs_class][(int) current_action];
3094 retval.main_action = current_action;
3098 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3099 without hardware support). This isn't related to a specific bpstat,
3100 just to things like whether watchpoints are set. */
3103 bpstat_should_step (void)
3105 struct breakpoint *b;
3107 if (b->enable_state == bp_enabled && b->type == bp_watchpoint)
3112 /* Nonzero if there are enabled hardware watchpoints. */
3114 bpstat_have_active_hw_watchpoints (void)
3116 struct breakpoint *b;
3118 if ((b->enable_state == bp_enabled) &&
3120 ((b->type == bp_hardware_watchpoint) ||
3121 (b->type == bp_read_watchpoint) ||
3122 (b->type == bp_access_watchpoint)))
3128 /* Given a bpstat that records zero or more triggered eventpoints, this
3129 function returns another bpstat which contains only the catchpoints
3130 on that first list, if any. */
3132 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3134 struct bpstats root_bs[1];
3135 bpstat bs = root_bs;
3136 struct breakpoint *ep;
3139 bpstat_clear (cp_list);
3140 root_bs->next = NULL;
3142 for (; ep_list != NULL; ep_list = ep_list->next)
3144 /* Is this eventpoint a catchpoint? If not, ignore it. */
3145 ep = ep_list->breakpoint_at;
3148 if ((ep->type != bp_catch_load) &&
3149 (ep->type != bp_catch_unload) &&
3150 (ep->type != bp_catch_catch) &&
3151 (ep->type != bp_catch_throw))
3152 /* pai: (temp) ADD fork/vfork here!! */
3155 /* Yes; add it to the list. */
3156 bs = bpstat_alloc (ep, bs);
3161 #if defined(SOLIB_ADD)
3162 /* Also, for each triggered catchpoint, tag it with the name of
3163 the library that caused this trigger. (We copy the name now,
3164 because it's only guaranteed to be available NOW, when the
3165 catchpoint triggers. Clients who may wish to know the name
3166 later must get it from the catchpoint itself.) */
3167 if (ep->triggered_dll_pathname != NULL)
3168 xfree (ep->triggered_dll_pathname);
3169 if (ep->type == bp_catch_load)
3170 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3171 PIDGET (inferior_ptid));
3173 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3174 PIDGET (inferior_ptid));
3176 dll_pathname = NULL;
3180 ep->triggered_dll_pathname = (char *)
3181 xmalloc (strlen (dll_pathname) + 1);
3182 strcpy (ep->triggered_dll_pathname, dll_pathname);
3185 ep->triggered_dll_pathname = NULL;
3191 /* Print B to gdb_stdout. */
3193 print_one_breakpoint (struct breakpoint *b,
3194 CORE_ADDR *last_addr)
3196 register struct command_line *l;
3197 register struct symbol *sym;
3198 struct ep_type_description
3203 static struct ep_type_description bptypes[] =
3205 {bp_none, "?deleted?"},
3206 {bp_breakpoint, "breakpoint"},
3207 {bp_hardware_breakpoint, "hw breakpoint"},
3208 {bp_until, "until"},
3209 {bp_finish, "finish"},
3210 {bp_watchpoint, "watchpoint"},
3211 {bp_hardware_watchpoint, "hw watchpoint"},
3212 {bp_read_watchpoint, "read watchpoint"},
3213 {bp_access_watchpoint, "acc watchpoint"},
3214 {bp_longjmp, "longjmp"},
3215 {bp_longjmp_resume, "longjmp resume"},
3216 {bp_step_resume, "step resume"},
3217 {bp_through_sigtramp, "sigtramp"},
3218 {bp_watchpoint_scope, "watchpoint scope"},
3219 {bp_call_dummy, "call dummy"},
3220 {bp_shlib_event, "shlib events"},
3221 {bp_thread_event, "thread events"},
3222 {bp_overlay_event, "overlay events"},
3223 {bp_catch_load, "catch load"},
3224 {bp_catch_unload, "catch unload"},
3225 {bp_catch_fork, "catch fork"},
3226 {bp_catch_vfork, "catch vfork"},
3227 {bp_catch_exec, "catch exec"},
3228 {bp_catch_catch, "catch catch"},
3229 {bp_catch_throw, "catch throw"}
3232 static char *bpdisps[] =
3233 {"del", "dstp", "dis", "keep"};
3234 static char bpenables[] = "nynny";
3235 char wrap_indent[80];
3236 struct ui_stream *stb = ui_out_stream_new (uiout);
3237 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3238 struct cleanup *bkpt_chain;
3241 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3245 ui_out_field_int (uiout, "number", b->number);
3249 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3250 || ((int) b->type != bptypes[(int) b->type].type))
3251 internal_error (__FILE__, __LINE__,
3252 "bptypes table does not describe type #%d.",
3254 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3258 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3262 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]);
3263 ui_out_spaces (uiout, 2);
3266 strcpy (wrap_indent, " ");
3269 if (TARGET_ADDR_BIT <= 32)
3270 strcat (wrap_indent, " ");
3272 strcat (wrap_indent, " ");
3275 if (b->ops != NULL && b->ops->print_one != NULL)
3276 b->ops->print_one (b, last_addr);
3281 internal_error (__FILE__, __LINE__,
3282 "print_one_breakpoint: bp_none encountered\n");
3286 case bp_hardware_watchpoint:
3287 case bp_read_watchpoint:
3288 case bp_access_watchpoint:
3289 /* Field 4, the address, is omitted (which makes the columns
3290 not line up too nicely with the headers, but the effect
3291 is relatively readable). */
3293 ui_out_field_skip (uiout, "addr");
3295 print_expression (b->exp, stb->stream);
3296 ui_out_field_stream (uiout, "what", stb);
3300 case bp_catch_unload:
3301 /* Field 4, the address, is omitted (which makes the columns
3302 not line up too nicely with the headers, but the effect
3303 is relatively readable). */
3305 ui_out_field_skip (uiout, "addr");
3307 if (b->dll_pathname == NULL)
3309 ui_out_field_string (uiout, "what", "<any library>");
3310 ui_out_spaces (uiout, 1);
3314 ui_out_text (uiout, "library \"");
3315 ui_out_field_string (uiout, "what", b->dll_pathname);
3316 ui_out_text (uiout, "\" ");
3321 case bp_catch_vfork:
3322 /* Field 4, the address, is omitted (which makes the columns
3323 not line up too nicely with the headers, but the effect
3324 is relatively readable). */
3326 ui_out_field_skip (uiout, "addr");
3328 if (b->forked_inferior_pid != 0)
3330 ui_out_text (uiout, "process ");
3331 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3332 ui_out_spaces (uiout, 1);
3336 /* Field 4, the address, is omitted (which makes the columns
3337 not line up too nicely with the headers, but the effect
3338 is relatively readable). */
3340 ui_out_field_skip (uiout, "addr");
3342 if (b->exec_pathname != NULL)
3344 ui_out_text (uiout, "program \"");
3345 ui_out_field_string (uiout, "what", b->exec_pathname);
3346 ui_out_text (uiout, "\" ");
3350 case bp_catch_catch:
3351 /* Field 4, the address, is omitted (which makes the columns
3352 not line up too nicely with the headers, but the effect
3353 is relatively readable). */
3355 ui_out_field_skip (uiout, "addr");
3357 ui_out_field_string (uiout, "what", "exception catch");
3358 ui_out_spaces (uiout, 1);
3361 case bp_catch_throw:
3362 /* Field 4, the address, is omitted (which makes the columns
3363 not line up too nicely with the headers, but the effect
3364 is relatively readable). */
3366 ui_out_field_skip (uiout, "addr");
3368 ui_out_field_string (uiout, "what", "exception throw");
3369 ui_out_spaces (uiout, 1);
3373 case bp_hardware_breakpoint:
3377 case bp_longjmp_resume:
3378 case bp_step_resume:
3379 case bp_through_sigtramp:
3380 case bp_watchpoint_scope:
3382 case bp_shlib_event:
3383 case bp_thread_event:
3384 case bp_overlay_event:
3388 ui_out_field_core_addr (uiout, "addr", b->address);
3391 *last_addr = b->address;
3394 sym = find_pc_sect_function (b->address, b->section);
3397 ui_out_text (uiout, "in ");
3398 ui_out_field_string (uiout, "func",
3399 SYMBOL_PRINT_NAME (sym));
3400 ui_out_wrap_hint (uiout, wrap_indent);
3401 ui_out_text (uiout, " at ");
3403 ui_out_field_string (uiout, "file", b->source_file);
3404 ui_out_text (uiout, ":");
3405 ui_out_field_int (uiout, "line", b->line_number);
3409 print_address_symbolic (b->address, stb->stream, demangle, "");
3410 ui_out_field_stream (uiout, "at", stb);
3415 if (b->thread != -1)
3417 /* FIXME: This seems to be redundant and lost here; see the
3418 "stop only in" line a little further down. */
3419 ui_out_text (uiout, " thread ");
3420 ui_out_field_int (uiout, "thread", b->thread);
3423 ui_out_text (uiout, "\n");
3425 if (frame_id_p (b->frame_id))
3428 ui_out_text (uiout, "\tstop only in stack frame at ");
3429 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3431 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3432 ui_out_text (uiout, "\n");
3438 ui_out_text (uiout, "\tstop only if ");
3439 print_expression (b->cond, stb->stream);
3440 ui_out_field_stream (uiout, "cond", stb);
3441 ui_out_text (uiout, "\n");
3444 if (b->thread != -1)
3446 /* FIXME should make an annotation for this */
3447 ui_out_text (uiout, "\tstop only in thread ");
3448 ui_out_field_int (uiout, "thread", b->thread);
3449 ui_out_text (uiout, "\n");
3452 if (show_breakpoint_hit_counts && b->hit_count)
3454 /* FIXME should make an annotation for this */
3455 if (ep_is_catchpoint (b))
3456 ui_out_text (uiout, "\tcatchpoint");
3458 ui_out_text (uiout, "\tbreakpoint");
3459 ui_out_text (uiout, " already hit ");
3460 ui_out_field_int (uiout, "times", b->hit_count);
3461 if (b->hit_count == 1)
3462 ui_out_text (uiout, " time\n");
3464 ui_out_text (uiout, " times\n");
3467 /* Output the count also if it is zero, but only if this is
3468 mi. FIXME: Should have a better test for this. */
3469 if (ui_out_is_mi_like_p (uiout))
3470 if (show_breakpoint_hit_counts && b->hit_count == 0)
3471 ui_out_field_int (uiout, "times", b->hit_count);
3473 if (b->ignore_count)
3476 ui_out_text (uiout, "\tignore next ");
3477 ui_out_field_int (uiout, "ignore", b->ignore_count);
3478 ui_out_text (uiout, " hits\n");
3481 if ((l = b->commands))
3483 struct cleanup *script_chain;
3486 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3487 print_command_lines (uiout, l, 4);
3488 do_cleanups (script_chain);
3490 do_cleanups (bkpt_chain);
3491 do_cleanups (old_chain);
3494 struct captured_breakpoint_query_args
3500 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3502 struct captured_breakpoint_query_args *args = data;
3503 register struct breakpoint *b;
3504 CORE_ADDR dummy_addr = 0;
3507 if (args->bnum == b->number)
3509 print_one_breakpoint (b, &dummy_addr);
3517 gdb_breakpoint_query (struct ui_out *uiout, int bnum)
3519 struct captured_breakpoint_query_args args;
3521 /* For the moment we don't trust print_one_breakpoint() to not throw
3523 return catch_exceptions (uiout, do_captured_breakpoint_query, &args,
3524 NULL, RETURN_MASK_ALL);
3527 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3528 catchpoints, et.al.). */
3531 user_settable_breakpoint (const struct breakpoint *b)
3533 return (b->type == bp_breakpoint
3534 || b->type == bp_catch_load
3535 || b->type == bp_catch_unload
3536 || b->type == bp_catch_fork
3537 || b->type == bp_catch_vfork
3538 || b->type == bp_catch_exec
3539 || b->type == bp_catch_catch
3540 || b->type == bp_catch_throw
3541 || b->type == bp_hardware_breakpoint
3542 || b->type == bp_watchpoint
3543 || b->type == bp_read_watchpoint
3544 || b->type == bp_access_watchpoint
3545 || b->type == bp_hardware_watchpoint);
3548 /* Print information on user settable breakpoint (watchpoint, etc)
3549 number BNUM. If BNUM is -1 print all user settable breakpoints.
3550 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3553 breakpoint_1 (int bnum, int allflag)
3555 register struct breakpoint *b;
3556 CORE_ADDR last_addr = (CORE_ADDR) -1;
3557 int nr_printable_breakpoints;
3558 struct cleanup *bkpttbl_chain;
3560 /* Compute the number of rows in the table. */
3561 nr_printable_breakpoints = 0;
3564 || bnum == b->number)
3566 if (allflag || user_settable_breakpoint (b))
3567 nr_printable_breakpoints++;
3572 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3576 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3579 if (nr_printable_breakpoints > 0)
3580 annotate_breakpoints_headers ();
3581 if (nr_printable_breakpoints > 0)
3583 ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */
3584 if (nr_printable_breakpoints > 0)
3586 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3587 if (nr_printable_breakpoints > 0)
3589 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3590 if (nr_printable_breakpoints > 0)
3592 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3595 if (nr_printable_breakpoints > 0)
3597 if (TARGET_ADDR_BIT <= 32)
3598 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3600 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3602 if (nr_printable_breakpoints > 0)
3604 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3605 ui_out_table_body (uiout);
3606 if (nr_printable_breakpoints > 0)
3607 annotate_breakpoints_table ();
3611 || bnum == b->number)
3613 /* We only print out user settable breakpoints unless the
3615 if (allflag || user_settable_breakpoint (b))
3616 print_one_breakpoint (b, &last_addr);
3619 do_cleanups (bkpttbl_chain);
3621 if (nr_printable_breakpoints == 0)
3624 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3626 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3631 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3632 that a comparison of an unsigned with -1 is always false. */
3633 if (last_addr != (CORE_ADDR) -1)
3634 set_next_address (last_addr);
3637 /* FIXME? Should this be moved up so that it is only called when
3638 there have been breakpoints? */
3639 annotate_breakpoints_table_end ();
3644 breakpoints_info (char *bnum_exp, int from_tty)
3649 bnum = parse_and_eval_long (bnum_exp);
3651 breakpoint_1 (bnum, 0);
3656 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3661 bnum = parse_and_eval_long (bnum_exp);
3663 breakpoint_1 (bnum, 1);
3666 /* Print a message describing any breakpoints set at PC. */
3669 describe_other_breakpoints (CORE_ADDR pc, asection *section)
3671 register int others = 0;
3672 register struct breakpoint *b;
3675 if (b->address == pc) /* address match / overlay match */
3676 if (!overlay_debugging || b->section == section)
3680 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3682 if (b->address == pc) /* address match / overlay match */
3683 if (!overlay_debugging || b->section == section)
3686 printf_filtered ("%d%s%s ",
3688 ((b->enable_state == bp_disabled ||
3689 b->enable_state == bp_shlib_disabled ||
3690 b->enable_state == bp_call_disabled)
3692 : b->enable_state == bp_permanent
3696 : ((others == 1) ? " and" : ""));
3698 printf_filtered ("also set at pc ");
3699 print_address_numeric (pc, 1, gdb_stdout);
3700 printf_filtered (".\n");
3704 /* Set the default place to put a breakpoint
3705 for the `break' command with no arguments. */
3708 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3711 default_breakpoint_valid = valid;
3712 default_breakpoint_address = addr;
3713 default_breakpoint_symtab = symtab;
3714 default_breakpoint_line = line;
3717 /* Return true iff it is meaningful to use the address member of
3718 BPT. For some breakpoint types, the address member is irrelevant
3719 and it makes no sense to attempt to compare it to other addresses
3720 (or use it for any other purpose either).
3722 More specifically, each of the following breakpoint types will always
3723 have a zero valued address and we don't want check_duplicates() to mark
3724 breakpoints of any of these types to be a duplicate of an actual
3725 breakpoint at address zero:
3728 bp_hardware_watchpoint
3730 bp_access_watchpoint
3737 breakpoint_address_is_meaningful (struct breakpoint *bpt)
3739 enum bptype type = bpt->type;
3741 return (type != bp_watchpoint
3742 && type != bp_hardware_watchpoint
3743 && type != bp_read_watchpoint
3744 && type != bp_access_watchpoint
3745 && type != bp_catch_exec
3746 && type != bp_longjmp_resume
3747 && type != bp_catch_fork
3748 && type != bp_catch_vfork);
3751 /* Rescan breakpoints at the same address and section as BPT,
3752 marking the first one as "first" and any others as "duplicates".
3753 This is so that the bpt instruction is only inserted once.
3754 If we have a permanent breakpoint at the same place as BPT, make
3755 that one the official one, and the rest as duplicates. */
3758 check_duplicates (struct breakpoint *bpt)
3760 register struct breakpoint *b;
3761 register int count = 0;
3762 struct breakpoint *perm_bp = 0;
3763 CORE_ADDR address = bpt->address;
3764 asection *section = bpt->section;
3766 if (! breakpoint_address_is_meaningful (bpt))
3770 if (b->enable_state != bp_disabled
3771 && b->enable_state != bp_shlib_disabled
3772 && b->enable_state != bp_call_disabled
3773 && b->address == address /* address / overlay match */
3774 && (!overlay_debugging || b->section == section)
3775 && breakpoint_address_is_meaningful (b))
3777 /* Have we found a permanent breakpoint? */
3778 if (b->enable_state == bp_permanent)
3785 b->duplicate = count > 1;
3788 /* If we found a permanent breakpoint at this address, go over the
3789 list again and declare all the other breakpoints there to be the
3793 perm_bp->duplicate = 0;
3795 /* Permanent breakpoint should always be inserted. */
3796 if (! perm_bp->inserted)
3797 internal_error (__FILE__, __LINE__,
3798 "allegedly permanent breakpoint is not "
3799 "actually inserted");
3805 internal_error (__FILE__, __LINE__,
3806 "another breakpoint was inserted on top of "
3807 "a permanent breakpoint");
3809 if (b->enable_state != bp_disabled
3810 && b->enable_state != bp_shlib_disabled
3811 && b->enable_state != bp_call_disabled
3812 && b->address == address /* address / overlay match */
3813 && (!overlay_debugging || b->section == section)
3814 && breakpoint_address_is_meaningful (b))
3820 /* set_raw_breakpoint() is a low level routine for allocating and
3821 partially initializing a breakpoint of type BPTYPE. The newly
3822 created breakpoint's address, section, source file name, and line
3823 number are provided by SAL. The newly created and partially
3824 initialized breakpoint is added to the breakpoint chain and
3825 is also returned as the value of this function.
3827 It is expected that the caller will complete the initialization of
3828 the newly created breakpoint struct as well as output any status
3829 information regarding the creation of a new breakpoint. In
3830 particular, set_raw_breakpoint() does NOT set the breakpoint
3831 number! Care should be taken to not allow an error() to occur
3832 prior to completing the initialization of the breakpoint. If this
3833 should happen, a bogus breakpoint will be left on the chain. */
3836 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
3838 register struct breakpoint *b, *b1;
3840 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3841 memset (b, 0, sizeof (*b));
3842 b->address = sal.pc;
3843 if (sal.symtab == NULL)
3844 b->source_file = NULL;
3846 b->source_file = savestring (sal.symtab->filename,
3847 strlen (sal.symtab->filename));
3848 b->section = sal.section;
3850 b->language = current_language->la_language;
3851 b->input_radix = input_radix;
3853 b->line_number = sal.line;
3854 b->enable_state = bp_enabled;
3857 b->ignore_count = 0;
3859 b->frame_id = null_frame_id;
3860 b->dll_pathname = NULL;
3861 b->triggered_dll_pathname = NULL;
3862 b->forked_inferior_pid = 0;
3863 b->exec_pathname = NULL;
3866 /* Add this breakpoint to the end of the chain
3867 so that a list of breakpoints will come out in order
3868 of increasing numbers. */
3870 b1 = breakpoint_chain;
3872 breakpoint_chain = b;
3880 check_duplicates (b);
3881 breakpoints_changed ();
3887 /* Note that the breakpoint object B describes a permanent breakpoint
3888 instruction, hard-wired into the inferior's code. */
3890 make_breakpoint_permanent (struct breakpoint *b)
3892 b->enable_state = bp_permanent;
3894 /* By definition, permanent breakpoints are already present in the code. */
3898 static struct breakpoint *
3899 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
3901 static int internal_breakpoint_number = -1;
3902 struct symtab_and_line sal;
3903 struct breakpoint *b;
3905 init_sal (&sal); /* initialize to zeroes */
3908 sal.section = find_pc_overlay (sal.pc);
3910 b = set_raw_breakpoint (sal, type);
3911 b->number = internal_breakpoint_number--;
3912 b->disposition = disp_donttouch;
3919 create_longjmp_breakpoint (char *func_name)
3921 struct breakpoint *b;
3922 struct minimal_symbol *m;
3924 if (func_name == NULL)
3925 b = create_internal_breakpoint (0, bp_longjmp_resume);
3928 if ((m = lookup_minimal_symbol_text (func_name, NULL, NULL)) == NULL)
3931 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
3934 b->enable_state = bp_disabled;
3937 b->addr_string = xstrdup (func_name);
3940 /* Call this routine when stepping and nexting to enable a breakpoint
3941 if we do a longjmp(). When we hit that breakpoint, call
3942 set_longjmp_resume_breakpoint() to figure out where we are going. */
3945 enable_longjmp_breakpoint (void)
3947 register struct breakpoint *b;
3950 if (b->type == bp_longjmp)
3952 b->enable_state = bp_enabled;
3953 check_duplicates (b);
3958 disable_longjmp_breakpoint (void)
3960 register struct breakpoint *b;
3963 if (b->type == bp_longjmp
3964 || b->type == bp_longjmp_resume)
3966 b->enable_state = bp_disabled;
3967 check_duplicates (b);
3972 create_overlay_event_breakpoint (char *func_name)
3974 struct breakpoint *b;
3975 struct minimal_symbol *m;
3977 if ((m = lookup_minimal_symbol_text (func_name, NULL, NULL)) == NULL)
3980 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
3982 b->addr_string = xstrdup (func_name);
3984 if (overlay_debugging == ovly_auto)
3986 b->enable_state = bp_enabled;
3987 overlay_events_enabled = 1;
3991 b->enable_state = bp_disabled;
3992 overlay_events_enabled = 0;
3997 enable_overlay_breakpoints (void)
3999 register struct breakpoint *b;
4002 if (b->type == bp_overlay_event)
4004 b->enable_state = bp_enabled;
4005 check_duplicates (b);
4006 overlay_events_enabled = 1;
4011 disable_overlay_breakpoints (void)
4013 register struct breakpoint *b;
4016 if (b->type == bp_overlay_event)
4018 b->enable_state = bp_disabled;
4019 check_duplicates (b);
4020 overlay_events_enabled = 0;
4025 create_thread_event_breakpoint (CORE_ADDR address)
4027 struct breakpoint *b;
4029 b = create_internal_breakpoint (address, bp_thread_event);
4031 b->enable_state = bp_enabled;
4032 /* addr_string has to be used or breakpoint_re_set will delete me. */
4033 xasprintf (&b->addr_string, "*0x%s", paddr (b->address));
4039 remove_thread_event_breakpoints (void)
4041 struct breakpoint *b, *temp;
4043 ALL_BREAKPOINTS_SAFE (b, temp)
4044 if (b->type == bp_thread_event)
4045 delete_breakpoint (b);
4050 remove_solib_event_breakpoints (void)
4052 register struct breakpoint *b, *temp;
4054 ALL_BREAKPOINTS_SAFE (b, temp)
4055 if (b->type == bp_shlib_event)
4056 delete_breakpoint (b);
4060 create_solib_event_breakpoint (CORE_ADDR address)
4062 struct breakpoint *b;
4064 b = create_internal_breakpoint (address, bp_shlib_event);
4068 /* Disable any breakpoints that are on code in shared libraries. Only
4069 apply to enabled breakpoints, disabled ones can just stay disabled. */
4072 disable_breakpoints_in_shlibs (int silent)
4074 struct breakpoint *b;
4075 int disabled_shlib_breaks = 0;
4077 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4080 #if defined (PC_SOLIB)
4081 if (((b->type == bp_breakpoint) ||
4082 (b->type == bp_hardware_breakpoint)) &&
4083 b->enable_state == bp_enabled &&
4085 PC_SOLIB (b->address))
4087 b->enable_state = bp_shlib_disabled;
4090 if (!disabled_shlib_breaks)
4092 target_terminal_ours_for_output ();
4093 warning ("Temporarily disabling shared library breakpoints:");
4095 disabled_shlib_breaks = 1;
4096 warning ("breakpoint #%d ", b->number);
4103 /* Try to reenable any breakpoints in shared libraries. */
4105 re_enable_breakpoints_in_shlibs (void)
4107 struct breakpoint *b;
4110 if (b->enable_state == bp_shlib_disabled)
4114 /* Do not reenable the breakpoint if the shared library
4115 is still not mapped in. */
4116 if (target_read_memory (b->address, buf, 1) == 0)
4117 b->enable_state = bp_enabled;
4124 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
4125 char *cond_string, enum bptype bp_kind)
4127 struct breakpoint *b;
4128 struct symtabs_and_lines sals;
4129 struct cleanup *old_chain;
4130 struct cleanup *canonical_strings_chain = NULL;
4131 char *addr_start = hookname;
4132 char *addr_end = NULL;
4133 char **canonical = (char **) NULL;
4134 int thread = -1; /* All threads. */
4136 /* Set a breakpoint on the specified hook. */
4137 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
4138 addr_end = hookname;
4140 if (sals.nelts == 0)
4142 warning ("Unable to set a breakpoint on dynamic linker callback.");
4143 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4144 warning ("GDB will be unable to track shl_load/shl_unload calls");
4147 if (sals.nelts != 1)
4149 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4150 warning ("GDB will be unable to track shl_load/shl_unload calls");
4154 /* Make sure that all storage allocated in decode_line_1 gets freed
4155 in case the following errors out. */
4156 old_chain = make_cleanup (xfree, sals.sals);
4157 if (canonical != (char **) NULL)
4159 make_cleanup (xfree, canonical);
4160 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4161 if (canonical[0] != NULL)
4162 make_cleanup (xfree, canonical[0]);
4165 resolve_sal_pc (&sals.sals[0]);
4167 /* Remove the canonical strings from the cleanup, they are needed below. */
4168 if (canonical != (char **) NULL)
4169 discard_cleanups (canonical_strings_chain);
4171 b = set_raw_breakpoint (sals.sals[0], bp_kind);
4172 set_breakpoint_count (breakpoint_count + 1);
4173 b->number = breakpoint_count;
4175 b->cond_string = (cond_string == NULL) ?
4176 NULL : savestring (cond_string, strlen (cond_string));
4179 if (canonical != (char **) NULL && canonical[0] != NULL)
4180 b->addr_string = canonical[0];
4181 else if (addr_start)
4182 b->addr_string = savestring (addr_start, addr_end - addr_start);
4184 b->enable_state = bp_enabled;
4185 b->disposition = tempflag ? disp_del : disp_donttouch;
4187 if (dll_pathname == NULL)
4188 b->dll_pathname = NULL;
4191 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4192 strcpy (b->dll_pathname, dll_pathname);
4196 do_cleanups (old_chain);
4200 create_solib_load_event_breakpoint (char *hookname, int tempflag,
4201 char *dll_pathname, char *cond_string)
4203 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4204 cond_string, bp_catch_load);
4208 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4209 char *dll_pathname, char *cond_string)
4211 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4212 cond_string, bp_catch_unload);
4216 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4217 enum bptype bp_kind)
4219 struct symtab_and_line sal;
4220 struct breakpoint *b;
4221 int thread = -1; /* All threads. */
4228 b = set_raw_breakpoint (sal, bp_kind);
4229 set_breakpoint_count (breakpoint_count + 1);
4230 b->number = breakpoint_count;
4232 b->cond_string = (cond_string == NULL) ?
4233 NULL : savestring (cond_string, strlen (cond_string));
4235 b->addr_string = NULL;
4236 b->enable_state = bp_enabled;
4237 b->disposition = tempflag ? disp_del : disp_donttouch;
4238 b->forked_inferior_pid = 0;
4244 create_fork_event_catchpoint (int tempflag, char *cond_string)
4246 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4250 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4252 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4256 create_exec_event_catchpoint (int tempflag, char *cond_string)
4258 struct symtab_and_line sal;
4259 struct breakpoint *b;
4260 int thread = -1; /* All threads. */
4267 b = set_raw_breakpoint (sal, bp_catch_exec);
4268 set_breakpoint_count (breakpoint_count + 1);
4269 b->number = breakpoint_count;
4271 b->cond_string = (cond_string == NULL) ?
4272 NULL : savestring (cond_string, strlen (cond_string));
4274 b->addr_string = NULL;
4275 b->enable_state = bp_enabled;
4276 b->disposition = tempflag ? disp_del : disp_donttouch;
4282 hw_breakpoint_used_count (void)
4284 register struct breakpoint *b;
4289 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4297 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4299 register struct breakpoint *b;
4302 *other_type_used = 0;
4305 if (b->enable_state == bp_enabled)
4307 if (b->type == type)
4309 else if ((b->type == bp_hardware_watchpoint ||
4310 b->type == bp_read_watchpoint ||
4311 b->type == bp_access_watchpoint)
4312 && b->enable_state == bp_enabled)
4313 *other_type_used = 1;
4319 /* Call this after hitting the longjmp() breakpoint. Use this to set
4320 a new breakpoint at the target of the jmp_buf.
4322 FIXME - This ought to be done by setting a temporary breakpoint
4323 that gets deleted automatically... */
4326 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id)
4328 register struct breakpoint *b;
4331 if (b->type == bp_longjmp_resume)
4334 b->enable_state = bp_enabled;
4335 b->frame_id = frame_id;
4336 check_duplicates (b);
4342 disable_watchpoints_before_interactive_call_start (void)
4344 struct breakpoint *b;
4348 if (((b->type == bp_watchpoint)
4349 || (b->type == bp_hardware_watchpoint)
4350 || (b->type == bp_read_watchpoint)
4351 || (b->type == bp_access_watchpoint)
4352 || ep_is_exception_catchpoint (b))
4353 && (b->enable_state == bp_enabled))
4355 b->enable_state = bp_call_disabled;
4356 check_duplicates (b);
4362 enable_watchpoints_after_interactive_call_stop (void)
4364 struct breakpoint *b;
4368 if (((b->type == bp_watchpoint)
4369 || (b->type == bp_hardware_watchpoint)
4370 || (b->type == bp_read_watchpoint)
4371 || (b->type == bp_access_watchpoint)
4372 || ep_is_exception_catchpoint (b))
4373 && (b->enable_state == bp_call_disabled))
4375 b->enable_state = bp_enabled;
4376 check_duplicates (b);
4382 /* Set a breakpoint that will evaporate an end of command
4383 at address specified by SAL.
4384 Restrict it to frame FRAME if FRAME is nonzero. */
4387 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
4390 register struct breakpoint *b;
4391 b = set_raw_breakpoint (sal, type);
4392 b->enable_state = bp_enabled;
4393 b->disposition = disp_donttouch;
4394 b->frame_id = frame_id;
4396 /* If we're debugging a multi-threaded program, then we
4397 want momentary breakpoints to be active in only a
4398 single thread of control. */
4399 if (in_thread_list (inferior_ptid))
4400 b->thread = pid_to_thread_id (inferior_ptid);
4406 /* Tell the user we have just set a breakpoint B. */
4409 mention (struct breakpoint *b)
4412 struct cleanup *old_chain, *ui_out_chain;
4413 struct ui_stream *stb;
4415 stb = ui_out_stream_new (uiout);
4416 old_chain = make_cleanup_ui_out_stream_delete (stb);
4418 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4419 watchpoint) other than breakpoint creation. It should be possible to
4420 clean this up and at the same time replace the random calls to
4421 breakpoint_changed with this hook, as has already been done for
4422 delete_breakpoint_hook and so on. */
4423 if (create_breakpoint_hook)
4424 create_breakpoint_hook (b);
4425 breakpoint_create_event (b->number);
4427 if (b->ops != NULL && b->ops->print_mention != NULL)
4428 b->ops->print_mention (b);
4433 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4436 ui_out_text (uiout, "Watchpoint ");
4437 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4438 ui_out_field_int (uiout, "number", b->number);
4439 ui_out_text (uiout, ": ");
4440 print_expression (b->exp, stb->stream);
4441 ui_out_field_stream (uiout, "exp", stb);
4442 do_cleanups (ui_out_chain);
4444 case bp_hardware_watchpoint:
4445 ui_out_text (uiout, "Hardware watchpoint ");
4446 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4447 ui_out_field_int (uiout, "number", b->number);
4448 ui_out_text (uiout, ": ");
4449 print_expression (b->exp, stb->stream);
4450 ui_out_field_stream (uiout, "exp", stb);
4451 do_cleanups (ui_out_chain);
4453 case bp_read_watchpoint:
4454 ui_out_text (uiout, "Hardware read watchpoint ");
4455 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
4456 ui_out_field_int (uiout, "number", b->number);
4457 ui_out_text (uiout, ": ");
4458 print_expression (b->exp, stb->stream);
4459 ui_out_field_stream (uiout, "exp", stb);
4460 do_cleanups (ui_out_chain);
4462 case bp_access_watchpoint:
4463 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4464 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
4465 ui_out_field_int (uiout, "number", b->number);
4466 ui_out_text (uiout, ": ");
4467 print_expression (b->exp, stb->stream);
4468 ui_out_field_stream (uiout, "exp", stb);
4469 do_cleanups (ui_out_chain);
4472 if (ui_out_is_mi_like_p (uiout))
4477 printf_filtered ("Breakpoint %d", b->number);
4480 case bp_hardware_breakpoint:
4481 if (ui_out_is_mi_like_p (uiout))
4486 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4490 case bp_catch_unload:
4491 printf_filtered ("Catchpoint %d (%s %s)",
4493 (b->type == bp_catch_load) ? "load" : "unload",
4494 (b->dll_pathname != NULL) ?
4495 b->dll_pathname : "<any library>");
4498 case bp_catch_vfork:
4499 printf_filtered ("Catchpoint %d (%s)",
4501 (b->type == bp_catch_fork) ? "fork" : "vfork");
4504 printf_filtered ("Catchpoint %d (exec)",
4507 case bp_catch_catch:
4508 case bp_catch_throw:
4509 printf_filtered ("Catchpoint %d (%s)",
4511 (b->type == bp_catch_catch) ? "catch" : "throw");
4517 case bp_longjmp_resume:
4518 case bp_step_resume:
4519 case bp_through_sigtramp:
4521 case bp_watchpoint_scope:
4522 case bp_shlib_event:
4523 case bp_thread_event:
4524 case bp_overlay_event:
4530 if (addressprint || b->source_file == NULL)
4532 printf_filtered (" at ");
4533 print_address_numeric (b->address, 1, gdb_stdout);
4536 printf_filtered (": file %s, line %d.",
4537 b->source_file, b->line_number);
4539 do_cleanups (old_chain);
4540 if (ui_out_is_mi_like_p (uiout))
4542 printf_filtered ("\n");
4546 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4547 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4548 COND[i] and COND_STRING[i] values.
4550 NOTE: If the function succeeds, the caller is expected to cleanup
4551 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4552 array contents). If the function fails (error() is called), the
4553 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4554 COND and SALS arrays and each of those arrays contents. */
4557 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4558 struct expression **cond, char **cond_string,
4559 enum bptype type, enum bpdisp disposition,
4560 int thread, int ignore_count, int from_tty)
4562 if (type == bp_hardware_breakpoint)
4564 int i = hw_breakpoint_used_count ();
4565 int target_resources_ok =
4566 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4568 if (target_resources_ok == 0)
4569 error ("No hardware breakpoint support in the target.");
4570 else if (target_resources_ok < 0)
4571 error ("Hardware breakpoints used exceeds limit.");
4574 /* Now set all the breakpoints. */
4577 for (i = 0; i < sals.nelts; i++)
4579 struct breakpoint *b;
4580 struct symtab_and_line sal = sals.sals[i];
4583 describe_other_breakpoints (sal.pc, sal.section);
4585 b = set_raw_breakpoint (sal, type);
4586 set_breakpoint_count (breakpoint_count + 1);
4587 b->number = breakpoint_count;
4591 b->addr_string = addr_string[i];
4593 /* addr_string has to be used or breakpoint_re_set will delete
4595 xasprintf (&b->addr_string, "*0x%s", paddr (b->address));
4596 b->cond_string = cond_string[i];
4597 b->ignore_count = ignore_count;
4598 b->enable_state = bp_enabled;
4599 b->disposition = disposition;
4605 /* Parse ARG which is assumed to be a SAL specification possibly
4606 followed by conditionals. On return, SALS contains an array of SAL
4607 addresses found. ADDR_STRING contains a vector of (canonical)
4608 address strings. ARG points to the end of the SAL. */
4611 parse_breakpoint_sals (char **address,
4612 struct symtabs_and_lines *sals,
4613 char ***addr_string)
4615 char *addr_start = *address;
4616 *addr_string = NULL;
4617 /* If no arg given, or if first arg is 'if ', use the default
4619 if ((*address) == NULL
4620 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4622 if (default_breakpoint_valid)
4624 struct symtab_and_line sal;
4625 init_sal (&sal); /* initialize to zeroes */
4626 sals->sals = (struct symtab_and_line *)
4627 xmalloc (sizeof (struct symtab_and_line));
4628 sal.pc = default_breakpoint_address;
4629 sal.line = default_breakpoint_line;
4630 sal.symtab = default_breakpoint_symtab;
4631 sal.section = find_pc_overlay (sal.pc);
4632 sals->sals[0] = sal;
4636 error ("No default breakpoint address now.");
4640 /* Force almost all breakpoints to be in terms of the
4641 current_source_symtab (which is decode_line_1's default). This
4642 should produce the results we want almost all of the time while
4643 leaving default_breakpoint_* alone.
4644 ObjC: However, don't match an Objective-C method name which
4645 may have a '+' or '-' succeeded by a '[' */
4647 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
4649 if (default_breakpoint_valid
4651 || ((strchr ("+-", (*address)[0]) != NULL)
4652 && ((*address)[1] != '['))))
4653 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4654 default_breakpoint_line, addr_string);
4656 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
4658 /* For any SAL that didn't have a canonical string, fill one in. */
4659 if (sals->nelts > 0 && *addr_string == NULL)
4660 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4661 if (addr_start != (*address))
4664 for (i = 0; i < sals->nelts; i++)
4666 /* Add the string if not present. */
4667 if ((*addr_string)[i] == NULL)
4668 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
4674 /* Convert each SAL into a real PC. Verify that the PC can be
4675 inserted as a breakpoint. If it can't throw an error. */
4678 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4682 for (i = 0; i < sals->nelts; i++)
4684 resolve_sal_pc (&sals->sals[i]);
4686 /* It's possible for the PC to be nonzero, but still an illegal
4687 value on some targets.
4689 For example, on HP-UX if you start gdb, and before running the
4690 inferior you try to set a breakpoint on a shared library function
4691 "foo" where the inferior doesn't call "foo" directly but does
4692 pass its address to another function call, then we do find a
4693 minimal symbol for the "foo", but it's address is invalid.
4694 (Appears to be an index into a table that the loader sets up
4695 when the inferior is run.)
4697 Give the target a chance to bless sals.sals[i].pc before we
4698 try to make a breakpoint for it. */
4699 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
4701 if (address == NULL)
4702 error ("Cannot break without a running program.");
4704 error ("Cannot break on %s without a running program.",
4710 /* Set a breakpoint according to ARG (function, linenum or *address)
4711 flag: first bit : 0 non-temporary, 1 temporary.
4712 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4715 break_command_1 (char *arg, int flag, int from_tty)
4717 int tempflag, hardwareflag;
4718 struct symtabs_and_lines sals;
4719 register struct expression **cond = 0;
4720 /* Pointers in arg to the start, and one past the end, of the
4722 char **cond_string = (char **) NULL;
4723 char *addr_start = arg;
4725 struct cleanup *old_chain;
4726 struct cleanup *breakpoint_chain = NULL;
4729 int ignore_count = 0;
4731 hardwareflag = flag & BP_HARDWAREFLAG;
4732 tempflag = flag & BP_TEMPFLAG;
4737 parse_breakpoint_sals (&arg, &sals, &addr_string);
4742 /* Create a chain of things that always need to be cleaned up. */
4743 old_chain = make_cleanup (null_cleanup, 0);
4745 /* Make sure that all storage allocated to SALS gets freed. */
4746 make_cleanup (xfree, sals.sals);
4748 /* Cleanup the addr_string array but not its contents. */
4749 make_cleanup (xfree, addr_string);
4751 /* Allocate space for all the cond expressions. */
4752 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4753 make_cleanup (xfree, cond);
4755 /* Allocate space for all the cond strings. */
4756 cond_string = xcalloc (sals.nelts, sizeof (char **));
4757 make_cleanup (xfree, cond_string);
4759 /* ----------------------------- SNIP -----------------------------
4760 Anything added to the cleanup chain beyond this point is assumed
4761 to be part of a breakpoint. If the breakpoint create succeeds
4762 then the memory is not reclaimed. */
4763 breakpoint_chain = make_cleanup (null_cleanup, 0);
4765 /* Mark the contents of the addr_string for cleanup. These go on
4766 the breakpoint_chain and only occure if the breakpoint create
4768 for (i = 0; i < sals.nelts; i++)
4770 if (addr_string[i] != NULL)
4771 make_cleanup (xfree, addr_string[i]);
4774 /* Resolve all line numbers to PC's and verify that the addresses
4775 are ok for the target. */
4776 breakpoint_sals_to_pc (&sals, addr_start);
4778 /* Verify that condition can be parsed, before setting any
4779 breakpoints. Allocate a separate condition expression for each
4781 thread = -1; /* No specific thread yet */
4782 for (i = 0; i < sals.nelts; i++)
4789 char *cond_start = NULL;
4790 char *cond_end = NULL;
4791 while (*tok == ' ' || *tok == '\t')
4796 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4799 toklen = end_tok - tok;
4801 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4803 tok = cond_start = end_tok + 1;
4804 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4805 make_cleanup (xfree, cond[i]);
4807 cond_string[i] = savestring (cond_start, cond_end - cond_start);
4808 make_cleanup (xfree, cond_string[i]);
4810 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4816 thread = strtol (tok, &tok, 0);
4818 error ("Junk after thread keyword.");
4819 if (!valid_thread_id (thread))
4820 error ("Unknown thread %d\n", thread);
4823 error ("Junk at end of arguments.");
4827 create_breakpoints (sals, addr_string, cond, cond_string,
4828 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4829 tempflag ? disp_del : disp_donttouch,
4830 thread, ignore_count, from_tty);
4834 warning ("Multiple breakpoints were set.");
4835 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4837 /* That's it. Discard the cleanups for data inserted into the
4839 discard_cleanups (breakpoint_chain);
4840 /* But cleanup everything else. */
4841 do_cleanups (old_chain);
4844 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4845 linenum or *address) with COND and IGNORE_COUNT. */
4847 struct captured_breakpoint_args
4858 do_captured_breakpoint (void *data)
4860 struct captured_breakpoint_args *args = data;
4861 struct symtabs_and_lines sals;
4862 register struct expression **cond;
4863 struct cleanup *old_chain;
4864 struct cleanup *breakpoint_chain = NULL;
4871 /* Parse the source and lines spec. Delay check that the expression
4872 didn't contain trailing garbage until after cleanups are in
4876 address_end = args->address;
4878 parse_breakpoint_sals (&address_end, &sals, &addr_string);
4883 /* Create a chain of things at always need to be cleaned up. */
4884 old_chain = make_cleanup (null_cleanup, 0);
4886 /* Always have a addr_string array, even if it is empty. */
4887 make_cleanup (xfree, addr_string);
4889 /* Make sure that all storage allocated to SALS gets freed. */
4890 make_cleanup (xfree, sals.sals);
4892 /* Allocate space for all the cond expressions. */
4893 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4894 make_cleanup (xfree, cond);
4896 /* Allocate space for all the cond strings. */
4897 cond_string = xcalloc (sals.nelts, sizeof (char **));
4898 make_cleanup (xfree, cond_string);
4900 /* ----------------------------- SNIP -----------------------------
4901 Anything added to the cleanup chain beyond this point is assumed
4902 to be part of a breakpoint. If the breakpoint create goes
4903 through then that memory is not cleaned up. */
4904 breakpoint_chain = make_cleanup (null_cleanup, 0);
4906 /* Mark the contents of the addr_string for cleanup. These go on
4907 the breakpoint_chain and only occure if the breakpoint create
4909 for (i = 0; i < sals.nelts; i++)
4911 if (addr_string[i] != NULL)
4912 make_cleanup (xfree, addr_string[i]);
4915 /* Wait until now before checking for garbage at the end of the
4916 address. That way cleanups can take care of freeing any
4918 if (*address_end != '\0')
4919 error ("Garbage %s following breakpoint address", address_end);
4921 /* Resolve all line numbers to PC's. */
4922 breakpoint_sals_to_pc (&sals, args->address);
4924 /* Verify that conditions can be parsed, before setting any
4926 for (i = 0; i < sals.nelts; i++)
4928 if (args->condition != NULL)
4930 char *tok = args->condition;
4931 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4933 error ("Garbage %s follows condition", tok);
4934 make_cleanup (xfree, cond[i]);
4935 cond_string[i] = xstrdup (args->condition);
4939 create_breakpoints (sals, addr_string, cond, cond_string,
4940 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4941 args->tempflag ? disp_del : disp_donttouch,
4942 args->thread, args->ignore_count, 0/*from-tty*/);
4944 /* That's it. Discard the cleanups for data inserted into the
4946 discard_cleanups (breakpoint_chain);
4947 /* But cleanup everything else. */
4948 do_cleanups (old_chain);
4953 gdb_breakpoint (char *address, char *condition,
4954 int hardwareflag, int tempflag,
4955 int thread, int ignore_count)
4957 struct captured_breakpoint_args args;
4958 args.address = address;
4959 args.condition = condition;
4960 args.hardwareflag = hardwareflag;
4961 args.tempflag = tempflag;
4962 args.thread = thread;
4963 args.ignore_count = ignore_count;
4964 return catch_errors (do_captured_breakpoint, &args,
4965 NULL, RETURN_MASK_ALL);
4970 break_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty)
4972 struct frame_info *frame;
4973 CORE_ADDR low, high, selected_pc = 0;
4974 char *extra_args = NULL;
4977 int extra_args_len = 0, if_arg = 0;
4980 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4983 if (default_breakpoint_valid)
4985 if (deprecated_selected_frame)
4987 selected_pc = get_frame_pc (deprecated_selected_frame);
4992 error ("No selected frame.");
4995 error ("No default breakpoint address now.");
4999 extra_args = strchr (arg, ' ');
5003 extra_args_len = strlen (extra_args);
5004 level_arg = (char *) xmalloc (extra_args - arg);
5005 strncpy (level_arg, arg, extra_args - arg - 1);
5006 level_arg[extra_args - arg - 1] = '\0';
5010 level_arg = (char *) xmalloc (strlen (arg) + 1);
5011 strcpy (level_arg, arg);
5014 frame = parse_frame_specification (level_arg);
5016 selected_pc = get_frame_pc (frame);
5023 extra_args_len = strlen (arg);
5028 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
5030 addr_string = (char *) xmalloc (26 + extra_args_len);
5032 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
5034 sprintf (addr_string, "*0x%s", paddr_nz (high));
5035 break_command_1 (addr_string, flag, from_tty);
5036 xfree (addr_string);
5039 error ("No function contains the specified address");
5042 error ("Unable to set breakpoint at procedure exit");
5047 break_at_finish_command_1 (char *arg, int flag, int from_tty)
5049 char *addr_string, *break_string, *beg_addr_string;
5050 CORE_ADDR low, high;
5051 struct symtabs_and_lines sals;
5052 struct symtab_and_line sal;
5053 struct cleanup *old_chain;
5054 char *extra_args = NULL;
5055 int extra_args_len = 0;
5059 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5061 if (default_breakpoint_valid)
5063 if (deprecated_selected_frame)
5065 addr_string = (char *) xmalloc (15);
5066 sprintf (addr_string, "*0x%s",
5067 paddr_nz (get_frame_pc (deprecated_selected_frame)));
5072 error ("No selected frame.");
5075 error ("No default breakpoint address now.");
5079 addr_string = (char *) xmalloc (strlen (arg) + 1);
5080 strcpy (addr_string, arg);
5086 extra_args_len = strlen (arg);
5090 /* get the stuff after the function name or address */
5091 extra_args = strchr (arg, ' ');
5095 extra_args_len = strlen (extra_args);
5102 beg_addr_string = addr_string;
5103 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
5106 xfree (beg_addr_string);
5107 old_chain = make_cleanup (xfree, sals.sals);
5108 for (i = 0; (i < sals.nelts); i++)
5111 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
5113 break_string = (char *) xmalloc (extra_args_len + 26);
5115 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
5117 sprintf (break_string, "*0x%s", paddr_nz (high));
5118 break_command_1 (break_string, flag, from_tty);
5119 xfree (break_string);
5122 error ("No function contains the specified address");
5126 warning ("Multiple breakpoints were set.\n");
5127 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5129 do_cleanups (old_chain);
5133 /* Helper function for break_command_1 and disassemble_command. */
5136 resolve_sal_pc (struct symtab_and_line *sal)
5140 if (sal->pc == 0 && sal->symtab != NULL)
5142 if (!find_line_pc (sal->symtab, sal->line, &pc))
5143 error ("No line %d in file \"%s\".",
5144 sal->line, sal->symtab->filename);
5148 if (sal->section == 0 && sal->symtab != NULL)
5150 struct blockvector *bv;
5155 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5158 b = BLOCKVECTOR_BLOCK (bv, index);
5159 sym = block_function (b);
5162 fixup_symbol_section (sym, sal->symtab->objfile);
5163 sal->section = SYMBOL_BFD_SECTION (sym);
5167 /* It really is worthwhile to have the section, so we'll just
5168 have to look harder. This case can be executed if we have
5169 line numbers but no functions (as can happen in assembly
5172 struct minimal_symbol *msym;
5174 msym = lookup_minimal_symbol_by_pc (sal->pc);
5176 sal->section = SYMBOL_BFD_SECTION (msym);
5183 break_command (char *arg, int from_tty)
5185 break_command_1 (arg, 0, from_tty);
5189 break_at_finish_command (char *arg, int from_tty)
5191 break_at_finish_command_1 (arg, 0, from_tty);
5195 break_at_finish_at_depth_command (char *arg, int from_tty)
5197 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5201 tbreak_command (char *arg, int from_tty)
5203 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5207 tbreak_at_finish_command (char *arg, int from_tty)
5209 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5213 hbreak_command (char *arg, int from_tty)
5215 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5219 thbreak_command (char *arg, int from_tty)
5221 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5225 stop_command (char *arg, int from_tty)
5227 printf_filtered ("Specify the type of breakpoint to set.\n\
5228 Usage: stop in <function | address>\n\
5233 stopin_command (char *arg, int from_tty)
5237 if (arg == (char *) NULL)
5239 else if (*arg != '*')
5244 /* look for a ':'. If this is a line number specification, then
5245 say it is bad, otherwise, it should be an address or
5246 function/method name */
5247 while (*argptr && !hasColon)
5249 hasColon = (*argptr == ':');
5254 badInput = (*argptr != ':'); /* Not a class::method */
5256 badInput = isdigit (*arg); /* a simple line number */
5260 printf_filtered ("Usage: stop in <function | address>\n");
5262 break_command_1 (arg, 0, from_tty);
5266 stopat_command (char *arg, int from_tty)
5270 if (arg == (char *) NULL || *arg == '*') /* no line number */
5277 /* look for a ':'. If there is a '::' then get out, otherwise
5278 it is probably a line number. */
5279 while (*argptr && !hasColon)
5281 hasColon = (*argptr == ':');
5286 badInput = (*argptr == ':'); /* we have class::method */
5288 badInput = !isdigit (*arg); /* not a line number */
5292 printf_filtered ("Usage: stop at <line>\n");
5294 break_command_1 (arg, 0, from_tty);
5298 /* accessflag: hw_write: watch write,
5299 hw_read: watch read,
5300 hw_access: watch access (read or write) */
5302 watch_command_1 (char *arg, int accessflag, int from_tty)
5304 struct breakpoint *b;
5305 struct symtab_and_line sal;
5306 struct expression *exp;
5307 struct block *exp_valid_block;
5308 struct value *val, *mark;
5309 struct frame_info *frame;
5310 struct frame_info *prev_frame = NULL;
5311 char *exp_start = NULL;
5312 char *exp_end = NULL;
5313 char *tok, *end_tok;
5315 char *cond_start = NULL;
5316 char *cond_end = NULL;
5317 struct expression *cond = NULL;
5318 int i, other_type_used, target_resources_ok = 0;
5319 enum bptype bp_type;
5322 init_sal (&sal); /* initialize to zeroes */
5324 /* Parse arguments. */
5325 innermost_block = NULL;
5327 exp = parse_exp_1 (&arg, 0, 0);
5329 exp_valid_block = innermost_block;
5330 mark = value_mark ();
5331 val = evaluate_expression (exp);
5332 release_value (val);
5333 if (VALUE_LAZY (val))
5334 value_fetch_lazy (val);
5337 while (*tok == ' ' || *tok == '\t')
5341 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5344 toklen = end_tok - tok;
5345 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5347 tok = cond_start = end_tok + 1;
5348 cond = parse_exp_1 (&tok, 0, 0);
5352 error ("Junk at end of command.");
5354 if (accessflag == hw_read)
5355 bp_type = bp_read_watchpoint;
5356 else if (accessflag == hw_access)
5357 bp_type = bp_access_watchpoint;
5359 bp_type = bp_hardware_watchpoint;
5361 mem_cnt = can_use_hardware_watchpoint (val);
5362 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5363 error ("Expression cannot be implemented with read/access watchpoint.");
5366 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5367 target_resources_ok =
5368 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5370 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5371 error ("Target does not support this type of hardware watchpoint.");
5373 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5374 error ("Target can only support one kind of HW watchpoint at a time.");
5377 #if defined(HPUXHPPA)
5378 /* On HP-UX if you set a h/w
5379 watchpoint before the "run" command, the inferior dies with a e.g.,
5380 SIGILL once you start it. I initially believed this was due to a
5381 bad interaction between page protection traps and the initial
5382 startup sequence by the dynamic linker.
5384 However, I tried avoiding that by having HP-UX's implementation of
5385 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5386 yet, which forced slow watches before a "run" or "attach", and it
5387 still fails somewhere in the startup code.
5389 Until I figure out what's happening, I'm disallowing watches altogether
5390 before the "run" or "attach" command. We'll tell the user they must
5391 set watches after getting the program started. */
5392 if (!target_has_execution)
5394 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5397 #endif /* HPUXHPPA */
5399 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5400 watchpoint could not be set. */
5401 if (!mem_cnt || target_resources_ok <= 0)
5402 bp_type = bp_watchpoint;
5404 /* Now set up the breakpoint. */
5405 b = set_raw_breakpoint (sal, bp_type);
5406 set_breakpoint_count (breakpoint_count + 1);
5407 b->number = breakpoint_count;
5408 b->disposition = disp_donttouch;
5410 b->exp_valid_block = exp_valid_block;
5411 b->exp_string = savestring (exp_start, exp_end - exp_start);
5415 b->cond_string = savestring (cond_start, cond_end - cond_start);
5419 frame = block_innermost_frame (exp_valid_block);
5422 prev_frame = get_prev_frame (frame);
5423 b->watchpoint_frame = get_frame_id (frame);
5427 memset (&b->watchpoint_frame, 0, sizeof (b->watchpoint_frame));
5430 /* If the expression is "local", then set up a "watchpoint scope"
5431 breakpoint at the point where we've left the scope of the watchpoint
5433 if (innermost_block)
5437 struct breakpoint *scope_breakpoint;
5438 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
5439 bp_watchpoint_scope);
5441 scope_breakpoint->enable_state = bp_enabled;
5443 /* Automatically delete the breakpoint when it hits. */
5444 scope_breakpoint->disposition = disp_del;
5446 /* Only break in the proper frame (help with recursion). */
5447 scope_breakpoint->frame_id = get_frame_id (prev_frame);
5449 /* Set the address at which we will stop. */
5450 scope_breakpoint->address = get_frame_pc (prev_frame);
5452 /* The scope breakpoint is related to the watchpoint. We
5453 will need to act on them together. */
5454 b->related_breakpoint = scope_breakpoint;
5457 value_free_to_mark (mark);
5461 /* Return count of locations need to be watched and can be handled
5462 in hardware. If the watchpoint can not be handled
5463 in hardware return zero. */
5465 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5466 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5467 ((BYTE_SIZE) <= (DEPRECATED_REGISTER_SIZE))
5470 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5471 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5472 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5476 can_use_hardware_watchpoint (struct value *v)
5478 int found_memory_cnt = 0;
5479 struct value *head = v;
5481 /* Did the user specifically forbid us to use hardware watchpoints? */
5482 if (!can_use_hw_watchpoints)
5485 /* Make sure that the value of the expression depends only upon
5486 memory contents, and values computed from them within GDB. If we
5487 find any register references or function calls, we can't use a
5488 hardware watchpoint.
5490 The idea here is that evaluating an expression generates a series
5491 of values, one holding the value of every subexpression. (The
5492 expression a*b+c has five subexpressions: a, b, a*b, c, and
5493 a*b+c.) GDB's values hold almost enough information to establish
5494 the criteria given above --- they identify memory lvalues,
5495 register lvalues, computed values, etcetera. So we can evaluate
5496 the expression, and then scan the chain of values that leaves
5497 behind to decide whether we can detect any possible change to the
5498 expression's final value using only hardware watchpoints.
5500 However, I don't think that the values returned by inferior
5501 function calls are special in any way. So this function may not
5502 notice that an expression involving an inferior function call
5503 can't be watched with hardware watchpoints. FIXME. */
5504 for (; v; v = v->next)
5506 if (VALUE_LVAL (v) == lval_memory)
5509 /* A lazy memory lvalue is one that GDB never needed to fetch;
5510 we either just used its address (e.g., `a' in `a.b') or
5511 we never needed it at all (e.g., `a' in `a,b'). */
5515 /* Ahh, memory we actually used! Check if we can cover
5516 it with hardware watchpoints. */
5517 struct type *vtype = check_typedef (VALUE_TYPE (v));
5519 /* We only watch structs and arrays if user asked for it
5520 explicitly, never if they just happen to appear in a
5521 middle of some value chain. */
5523 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5524 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5526 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5527 int len = TYPE_LENGTH (VALUE_TYPE (v));
5529 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5536 else if (v->lval != not_lval && v->modifiable == 0)
5537 return 0; /* ??? What does this represent? */
5538 else if (v->lval == lval_register)
5539 return 0; /* cannot watch a register with a HW watchpoint */
5542 /* The expression itself looks suitable for using a hardware
5543 watchpoint, but give the target machine a chance to reject it. */
5544 return found_memory_cnt;
5548 watch_command_wrapper (char *arg, int from_tty)
5550 watch_command (arg, from_tty);
5554 watch_command (char *arg, int from_tty)
5556 watch_command_1 (arg, hw_write, from_tty);
5560 rwatch_command_wrapper (char *arg, int from_tty)
5562 rwatch_command (arg, from_tty);
5566 rwatch_command (char *arg, int from_tty)
5568 watch_command_1 (arg, hw_read, from_tty);
5572 awatch_command_wrapper (char *arg, int from_tty)
5574 awatch_command (arg, from_tty);
5578 awatch_command (char *arg, int from_tty)
5580 watch_command_1 (arg, hw_access, from_tty);
5584 /* Helper routines for the until_command routine in infcmd.c. Here
5585 because it uses the mechanisms of breakpoints. */
5587 /* This function is called by fetch_inferior_event via the
5588 cmd_continuation pointer, to complete the until command. It takes
5589 care of cleaning up the temporary breakpoints set up by the until
5592 until_break_command_continuation (struct continuation_arg *arg)
5594 struct cleanup *cleanups;
5596 cleanups = (struct cleanup *) arg->data.pointer;
5597 do_exec_cleanups (cleanups);
5602 until_break_command (char *arg, int from_tty, int anywhere)
5604 struct symtabs_and_lines sals;
5605 struct symtab_and_line sal;
5606 struct frame_info *prev_frame = get_prev_frame (deprecated_selected_frame);
5607 struct breakpoint *breakpoint;
5608 struct cleanup *old_chain;
5609 struct continuation_arg *arg1;
5612 clear_proceed_status ();
5614 /* Set a breakpoint where the user wants it and at return from
5617 if (default_breakpoint_valid)
5618 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5619 default_breakpoint_line, (char ***) NULL);
5621 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5622 0, (char ***) NULL);
5624 if (sals.nelts != 1)
5625 error ("Couldn't get information on specified line.");
5628 xfree (sals.sals); /* malloc'd, so freed */
5631 error ("Junk at end of arguments.");
5633 resolve_sal_pc (&sal);
5636 /* If the user told us to continue until a specified location,
5637 we don't specify a frame at which we need to stop. */
5638 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
5640 /* Otherwise, specify the current frame, because we want to stop only
5641 at the very same frame. */
5642 breakpoint = set_momentary_breakpoint (sal,
5643 get_frame_id (deprecated_selected_frame),
5646 if (!event_loop_p || !target_can_async_p ())
5647 old_chain = make_cleanup_delete_breakpoint (breakpoint);
5649 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
5651 /* If we are running asynchronously, and the target supports async
5652 execution, we are not waiting for the target to stop, in the call
5653 tp proceed, below. This means that we cannot delete the
5654 brekpoints until the target has actually stopped. The only place
5655 where we get a chance to do that is in fetch_inferior_event, so
5656 we must set things up for that. */
5658 if (event_loop_p && target_can_async_p ())
5660 /* In this case the arg for the continuation is just the point
5661 in the exec_cleanups chain from where to start doing
5662 cleanups, because all the continuation does is the cleanups in
5663 the exec_cleanup_chain. */
5665 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5667 arg1->data.pointer = old_chain;
5669 add_continuation (until_break_command_continuation, arg1);
5672 /* Keep within the current frame, or in frames called by the current
5676 sal = find_pc_line (get_frame_pc (prev_frame), 0);
5677 sal.pc = get_frame_pc (prev_frame);
5678 breakpoint = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
5680 if (!event_loop_p || !target_can_async_p ())
5681 make_cleanup_delete_breakpoint (breakpoint);
5683 make_exec_cleanup_delete_breakpoint (breakpoint);
5686 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5687 /* Do the cleanups now, anly if we are not running asynchronously,
5688 of if we are, but the target is still synchronous. */
5689 if (!event_loop_p || !target_can_async_p ())
5690 do_cleanups (old_chain);
5694 /* These aren't used; I don't konw what they were for. */
5695 /* Set a breakpoint at the catch clause for NAME. */
5697 catch_breakpoint (char *name)
5702 disable_catch_breakpoint (void)
5707 delete_catch_breakpoint (void)
5712 enable_catch_breakpoint (void)
5718 ep_skip_leading_whitespace (char **s)
5720 if ((s == NULL) || (*s == NULL))
5722 while (isspace (**s))
5726 /* This function examines a string, and attempts to find a token
5727 that might be an event name in the leading characters. If a
5728 possible match is found, a pointer to the last character of
5729 the token is returned. Else, NULL is returned. */
5732 ep_find_event_name_end (char *arg)
5735 char *event_name_end = NULL;
5737 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5741 /* We break out of the loop when we find a token delimiter.
5742 Basically, we're looking for alphanumerics and underscores;
5743 anything else delimites the token. */
5746 if (!isalnum (*s) && (*s != '_'))
5752 return event_name_end;
5756 /* This function attempts to parse an optional "if <cond>" clause
5757 from the arg string. If one is not found, it returns NULL.
5759 Else, it returns a pointer to the condition string. (It does not
5760 attempt to evaluate the string against a particular block.) And,
5761 it updates arg to point to the first character following the parsed
5762 if clause in the arg string. */
5765 ep_parse_optional_if_clause (char **arg)
5769 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5772 /* Skip the "if" keyword. */
5775 /* Skip any extra leading whitespace, and record the start of the
5776 condition string. */
5777 ep_skip_leading_whitespace (arg);
5780 /* Assume that the condition occupies the remainder of the arg string. */
5781 (*arg) += strlen (cond_string);
5786 /* This function attempts to parse an optional filename from the arg
5787 string. If one is not found, it returns NULL.
5789 Else, it returns a pointer to the parsed filename. (This function
5790 makes no attempt to verify that a file of that name exists, or is
5791 accessible.) And, it updates arg to point to the first character
5792 following the parsed filename in the arg string.
5794 Note that clients needing to preserve the returned filename for
5795 future access should copy it to their own buffers. */
5797 ep_parse_optional_filename (char **arg)
5799 static char filename[1024];
5804 if ((*arg_p == '\0') || isspace (*arg_p))
5822 /* Commands to deal with catching events, such as signals, exceptions,
5823 process start/exit, etc. */
5827 catch_fork, catch_vfork
5831 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5832 static void catch_fork_command_1 (catch_fork_kind fork_kind,
5833 char *arg, int tempflag, int from_tty);
5836 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
5839 char *cond_string = NULL;
5841 ep_skip_leading_whitespace (&arg);
5843 /* The allowed syntax is:
5845 catch [v]fork if <cond>
5847 First, check if there's an if clause. */
5848 cond_string = ep_parse_optional_if_clause (&arg);
5850 if ((*arg != '\0') && !isspace (*arg))
5851 error ("Junk at end of arguments.");
5853 /* If this target supports it, create a fork or vfork catchpoint
5854 and enable reporting of such events. */
5858 create_fork_event_catchpoint (tempflag, cond_string);
5861 create_vfork_event_catchpoint (tempflag, cond_string);
5864 error ("unsupported or unknown fork kind; cannot catch it");
5870 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5872 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
5874 char *cond_string = NULL;
5876 ep_skip_leading_whitespace (&arg);
5878 /* The allowed syntax is:
5880 catch exec if <cond>
5882 First, check if there's an if clause. */
5883 cond_string = ep_parse_optional_if_clause (&arg);
5885 if ((*arg != '\0') && !isspace (*arg))
5886 error ("Junk at end of arguments.");
5888 /* If this target supports it, create an exec catchpoint
5889 and enable reporting of such events. */
5890 create_exec_event_catchpoint (tempflag, cond_string);
5894 #if defined(SOLIB_ADD)
5896 catch_load_command_1 (char *arg, int tempflag, int from_tty)
5898 char *dll_pathname = NULL;
5899 char *cond_string = NULL;
5901 ep_skip_leading_whitespace (&arg);
5903 /* The allowed syntax is:
5905 catch load if <cond>
5906 catch load <filename>
5907 catch load <filename> if <cond>
5909 The user is not allowed to specify the <filename> after an
5912 We'll ignore the pathological case of a file named "if".
5914 First, check if there's an if clause. If so, then there
5915 cannot be a filename. */
5916 cond_string = ep_parse_optional_if_clause (&arg);
5918 /* If there was an if clause, then there cannot be a filename.
5919 Else, there might be a filename and an if clause. */
5920 if (cond_string == NULL)
5922 dll_pathname = ep_parse_optional_filename (&arg);
5923 ep_skip_leading_whitespace (&arg);
5924 cond_string = ep_parse_optional_if_clause (&arg);
5927 if ((*arg != '\0') && !isspace (*arg))
5928 error ("Junk at end of arguments.");
5930 /* Create a load breakpoint that only triggers when a load of
5931 the specified dll (or any dll, if no pathname was specified)
5933 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
5934 dll_pathname, cond_string);
5938 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
5940 char *dll_pathname = NULL;
5941 char *cond_string = NULL;
5943 ep_skip_leading_whitespace (&arg);
5945 /* The allowed syntax is:
5947 catch unload if <cond>
5948 catch unload <filename>
5949 catch unload <filename> if <cond>
5951 The user is not allowed to specify the <filename> after an
5954 We'll ignore the pathological case of a file named "if".
5956 First, check if there's an if clause. If so, then there
5957 cannot be a filename. */
5958 cond_string = ep_parse_optional_if_clause (&arg);
5960 /* If there was an if clause, then there cannot be a filename.
5961 Else, there might be a filename and an if clause. */
5962 if (cond_string == NULL)
5964 dll_pathname = ep_parse_optional_filename (&arg);
5965 ep_skip_leading_whitespace (&arg);
5966 cond_string = ep_parse_optional_if_clause (&arg);
5969 if ((*arg != '\0') && !isspace (*arg))
5970 error ("Junk at end of arguments.");
5972 /* Create an unload breakpoint that only triggers when an unload of
5973 the specified dll (or any dll, if no pathname was specified)
5975 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
5976 dll_pathname, cond_string);
5978 #endif /* SOLIB_ADD */
5980 /* Commands to deal with catching exceptions. */
5982 /* Set a breakpoint at the specified callback routine for an
5983 exception event callback */
5986 create_exception_catchpoint (int tempflag, char *cond_string,
5987 enum exception_event_kind ex_event,
5988 struct symtab_and_line *sal)
5990 struct breakpoint *b;
5991 int thread = -1; /* All threads. */
5994 if (!sal) /* no exception support? */
5999 case EX_EVENT_THROW:
6000 bptype = bp_catch_throw;
6002 case EX_EVENT_CATCH:
6003 bptype = bp_catch_catch;
6005 default: /* error condition */
6006 error ("Internal error -- invalid catchpoint kind");
6009 b = set_raw_breakpoint (*sal, bptype);
6010 set_breakpoint_count (breakpoint_count + 1);
6011 b->number = breakpoint_count;
6013 b->cond_string = (cond_string == NULL) ?
6014 NULL : savestring (cond_string, strlen (cond_string));
6016 b->addr_string = NULL;
6017 b->enable_state = bp_enabled;
6018 b->disposition = tempflag ? disp_del : disp_donttouch;
6022 static enum print_stop_action
6023 print_exception_catchpoint (struct breakpoint *b)
6025 annotate_catchpoint (b->number);
6027 if (strstr (b->addr_string, "throw") != NULL)
6028 printf_filtered ("\nCatchpoint %d (exception thrown)\n",
6031 printf_filtered ("\nCatchpoint %d (exception caught)\n",
6034 return PRINT_SRC_AND_LOC;
6038 print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6043 ui_out_field_core_addr (uiout, "addr", b->address);
6046 *last_addr = b->address;
6047 if (strstr (b->addr_string, "throw") != NULL)
6048 ui_out_field_string (uiout, "what", "exception throw");
6050 ui_out_field_string (uiout, "what", "exception catch");
6054 print_mention_exception_catchpoint (struct breakpoint *b)
6056 if (strstr (b->addr_string, "throw") != NULL)
6057 printf_filtered ("Catchpoint %d (throw)", b->number);
6059 printf_filtered ("Catchpoint %d (catch)", b->number);
6062 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6063 print_exception_catchpoint,
6064 print_one_exception_catchpoint,
6065 print_mention_exception_catchpoint
6069 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6070 enum exception_event_kind ex_event, int from_tty)
6072 char *trigger_func_name, *nameptr;
6073 struct symtabs_and_lines sals;
6074 struct breakpoint *b;
6076 if (ex_event == EX_EVENT_CATCH)
6077 trigger_func_name = xstrdup ("__cxa_begin_catch");
6079 trigger_func_name = xstrdup ("__cxa_throw");
6081 nameptr = trigger_func_name;
6082 sals = decode_line_1 (&nameptr, 1, NULL, 0, NULL);
6083 if (sals.nelts == 0)
6085 free (trigger_func_name);
6089 b = set_raw_breakpoint (sals.sals[0], bp_breakpoint);
6090 set_breakpoint_count (breakpoint_count + 1);
6091 b->number = breakpoint_count;
6093 b->cond_string = (cond_string == NULL) ?
6094 NULL : savestring (cond_string, strlen (cond_string));
6096 b->addr_string = trigger_func_name;
6097 b->enable_state = bp_enabled;
6098 b->disposition = tempflag ? disp_del : disp_donttouch;
6099 b->ops = &gnu_v3_exception_catchpoint_ops;
6106 /* Deal with "catch catch" and "catch throw" commands */
6109 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6110 int tempflag, int from_tty)
6112 char *cond_string = NULL;
6113 struct symtab_and_line *sal = NULL;
6115 ep_skip_leading_whitespace (&arg);
6117 cond_string = ep_parse_optional_if_clause (&arg);
6119 if ((*arg != '\0') && !isspace (*arg))
6120 error ("Junk at end of arguments.");
6122 if ((ex_event != EX_EVENT_THROW) &&
6123 (ex_event != EX_EVENT_CATCH))
6124 error ("Unsupported or unknown exception event; cannot catch it");
6126 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6129 /* See if we can find a callback routine */
6130 sal = target_enable_exception_callback (ex_event, 1);
6134 /* We have callbacks from the runtime system for exceptions.
6135 Set a breakpoint on the sal found, if no errors */
6136 if (sal != (struct symtab_and_line *) -1)
6137 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6139 return; /* something went wrong with setting up callbacks */
6142 warning ("Unsupported with this platform/compiler combination.");
6145 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6146 inside a catch_errors */
6149 cover_target_enable_exception_callback (void *arg)
6151 args_for_catchpoint_enable *args = arg;
6152 struct symtab_and_line *sal;
6153 sal = target_enable_exception_callback (args->kind, args->enable_p);
6156 else if (sal == (struct symtab_and_line *) -1)
6159 return 1; /*is valid */
6163 catch_command_1 (char *arg, int tempflag, int from_tty)
6166 /* The first argument may be an event name, such as "start" or "load".
6167 If so, then handle it as such. If it doesn't match an event name,
6168 then attempt to interpret it as an exception name. (This latter is
6169 the v4.16-and-earlier GDB meaning of the "catch" command.)
6171 First, try to find the bounds of what might be an event name. */
6172 char *arg1_start = arg;
6176 if (arg1_start == NULL)
6178 /* Old behaviour was to use pre-v-4.16 syntax */
6179 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6181 /* Now, this is not allowed */
6182 error ("Catch requires an event name.");
6185 arg1_end = ep_find_event_name_end (arg1_start);
6186 if (arg1_end == NULL)
6187 error ("catch requires an event");
6188 arg1_length = arg1_end + 1 - arg1_start;
6190 /* Try to match what we found against known event names. */
6191 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6193 error ("Catch of signal not yet implemented");
6195 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6197 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6198 tempflag, from_tty);
6200 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6202 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6203 tempflag, from_tty);
6205 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6207 error ("Catch of thread_start not yet implemented");
6209 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6211 error ("Catch of thread_exit not yet implemented");
6213 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6215 error ("Catch of thread_join not yet implemented");
6217 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6219 error ("Catch of start not yet implemented");
6221 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6223 error ("Catch of exit not yet implemented");
6225 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6227 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6228 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6230 error ("Catch of fork not yet implemented");
6233 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6235 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6236 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6238 error ("Catch of vfork not yet implemented");
6241 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6243 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6244 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6246 error ("Catch of exec not yet implemented");
6249 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6251 #if defined(SOLIB_ADD)
6252 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6254 error ("Catch of load not implemented");
6257 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6259 #if defined(SOLIB_ADD)
6260 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6262 error ("Catch of load not implemented");
6265 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6267 error ("Catch of stop not yet implemented");
6270 /* This doesn't appear to be an event name */
6274 /* Pre-v.4.16 behaviour was to treat the argument
6275 as the name of an exception */
6276 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6277 /* Now this is not allowed */
6278 error ("Unknown event kind specified for catch");
6283 /* Used by the gui, could be made a worker for other things. */
6286 set_breakpoint_sal (struct symtab_and_line sal)
6288 struct breakpoint *b;
6289 b = set_raw_breakpoint (sal, bp_breakpoint);
6290 set_breakpoint_count (breakpoint_count + 1);
6291 b->number = breakpoint_count;
6298 /* These aren't used; I don't know what they were for. */
6299 /* Disable breakpoints on all catch clauses described in ARGS. */
6301 disable_catch (char *args)
6303 /* Map the disable command to catch clauses described in ARGS. */
6306 /* Enable breakpoints on all catch clauses described in ARGS. */
6308 enable_catch (char *args)
6310 /* Map the disable command to catch clauses described in ARGS. */
6313 /* Delete breakpoints on all catch clauses in the active scope. */
6315 delete_catch (char *args)
6317 /* Map the delete command to catch clauses described in ARGS. */
6322 catch_command (char *arg, int from_tty)
6324 catch_command_1 (arg, 0, from_tty);
6329 tcatch_command (char *arg, int from_tty)
6331 catch_command_1 (arg, 1, from_tty);
6334 /* Delete breakpoints by address or line. */
6337 clear_command (char *arg, int from_tty)
6339 struct breakpoint *b, *tmp, *prev, *found;
6341 struct symtabs_and_lines sals;
6342 struct symtab_and_line sal;
6347 sals = decode_line_spec (arg, 1);
6352 sals.sals = (struct symtab_and_line *)
6353 xmalloc (sizeof (struct symtab_and_line));
6354 make_cleanup (xfree, sals.sals);
6355 init_sal (&sal); /* initialize to zeroes */
6356 sal.line = default_breakpoint_line;
6357 sal.symtab = default_breakpoint_symtab;
6358 sal.pc = default_breakpoint_address;
6359 if (sal.symtab == 0)
6360 error ("No source file specified.");
6368 /* For each line spec given, delete bps which correspond
6369 to it. Do it in two passes, solely to preserve the current
6370 behavior that from_tty is forced true if we delete more than
6374 for (i = 0; i < sals.nelts; i++)
6376 /* If exact pc given, clear bpts at that pc.
6377 If line given (pc == 0), clear all bpts on specified line.
6378 If defaulting, clear all bpts on default line
6381 defaulting sal.pc != 0 tests to do
6386 1 0 <can't happen> */
6391 /* Find all matching breakpoints, remove them from the
6392 breakpoint chain, and add them to the 'found' chain. */
6393 ALL_BREAKPOINTS_SAFE (b, tmp)
6395 /* Are we going to delete b? */
6396 if (b->type != bp_none
6397 && b->type != bp_watchpoint
6398 && b->type != bp_hardware_watchpoint
6399 && b->type != bp_read_watchpoint
6400 && b->type != bp_access_watchpoint
6401 /* Not if b is a watchpoint of any sort... */
6402 && (((sal.pc && (b->address == sal.pc))
6403 && (!section_is_overlay (b->section)
6404 || b->section == sal.section))
6405 /* Yes, if sal.pc matches b (modulo overlays). */
6406 || ((default_match || (0 == sal.pc))
6407 && b->source_file != NULL
6408 && sal.symtab != NULL
6409 && STREQ (b->source_file, sal.symtab->filename)
6410 && b->line_number == sal.line)))
6411 /* Yes, if sal source file and line matches b. */
6413 /* Remove it from breakpoint_chain... */
6414 if (b == breakpoint_chain)
6416 /* b is at the head of the list */
6417 breakpoint_chain = b->next;
6421 prev->next = b->next;
6423 /* And add it to 'found' chain. */
6429 /* Keep b, and keep a pointer to it. */
6434 /* Now go thru the 'found' chain and delete them. */
6438 error ("No breakpoint at %s.", arg);
6440 error ("No breakpoint at this line.");
6444 from_tty = 1; /* Always report if deleted more than one */
6446 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6447 breakpoints_changed ();
6451 printf_unfiltered ("%d ", found->number);
6453 delete_breakpoint (found);
6457 putchar_unfiltered ('\n');
6460 /* Delete breakpoint in BS if they are `delete' breakpoints and
6461 all breakpoints that are marked for deletion, whether hit or not.
6462 This is called after any breakpoint is hit, or after errors. */
6465 breakpoint_auto_delete (bpstat bs)
6467 struct breakpoint *b, *temp;
6469 for (; bs; bs = bs->next)
6470 if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del
6472 delete_breakpoint (bs->breakpoint_at);
6474 ALL_BREAKPOINTS_SAFE (b, temp)
6476 if (b->disposition == disp_del_at_next_stop)
6477 delete_breakpoint (b);
6481 /* Delete a breakpoint and clean up all traces of it in the data
6485 delete_breakpoint (struct breakpoint *bpt)
6487 register struct breakpoint *b;
6491 error ("Internal error (attempted to delete a NULL breakpoint)");
6494 /* Has this bp already been deleted? This can happen because multiple
6495 lists can hold pointers to bp's. bpstat lists are especial culprits.
6497 One example of this happening is a watchpoint's scope bp. When the
6498 scope bp triggers, we notice that the watchpoint is out of scope, and
6499 delete it. We also delete its scope bp. But the scope bp is marked
6500 "auto-deleting", and is already on a bpstat. That bpstat is then
6501 checked for auto-deleting bp's, which are deleted.
6503 A real solution to this problem might involve reference counts in bp's,
6504 and/or giving them pointers back to their referencing bpstat's, and
6505 teaching delete_breakpoint to only free a bp's storage when no more
6506 references were extent. A cheaper bandaid was chosen. */
6507 if (bpt->type == bp_none)
6510 if (delete_breakpoint_hook)
6511 delete_breakpoint_hook (bpt);
6512 breakpoint_delete_event (bpt->number);
6515 remove_breakpoint (bpt, mark_inserted);
6517 if (breakpoint_chain == bpt)
6518 breakpoint_chain = bpt->next;
6520 /* If we have callback-style exception catchpoints, don't go through
6521 the adjustments to the C++ runtime library etc. if the inferior
6522 isn't actually running. target_enable_exception_callback for a
6523 null target ops vector gives an undesirable error message, so we
6524 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6525 exceptions are supported in this way, it's OK for now. FIXME */
6526 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6528 static char message1[] = "Error in deleting catchpoint %d:\n";
6529 static char message[sizeof (message1) + 30];
6530 args_for_catchpoint_enable args;
6532 /* Format possible error msg */
6533 sprintf (message, message1, bpt->number);
6534 args.kind = bpt->type == bp_catch_catch ?
6535 EX_EVENT_CATCH : EX_EVENT_THROW;
6537 catch_errors (cover_target_enable_exception_callback, &args,
6538 message, RETURN_MASK_ALL);
6545 b->next = bpt->next;
6549 check_duplicates (bpt);
6550 /* If this breakpoint was inserted, and there is another breakpoint
6551 at the same address, we need to insert the other breakpoint. */
6553 && bpt->type != bp_hardware_watchpoint
6554 && bpt->type != bp_read_watchpoint
6555 && bpt->type != bp_access_watchpoint
6556 && bpt->type != bp_catch_fork
6557 && bpt->type != bp_catch_vfork
6558 && bpt->type != bp_catch_exec)
6561 if (b->address == bpt->address
6562 && b->section == bpt->section
6564 && b->enable_state != bp_disabled
6565 && b->enable_state != bp_shlib_disabled
6566 && b->enable_state != bp_call_disabled)
6570 /* We should never reach this point if there is a permanent
6571 breakpoint at the same address as the one being deleted.
6572 If there is a permanent breakpoint somewhere, it should
6573 always be the only one inserted. */
6574 if (b->enable_state == bp_permanent)
6575 internal_error (__FILE__, __LINE__,
6576 "another breakpoint was inserted on top of "
6577 "a permanent breakpoint");
6579 if (b->type == bp_hardware_breakpoint)
6580 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6582 val = target_insert_breakpoint (b->address, b->shadow_contents);
6584 /* If there was an error in the insert, print a message, then stop execution. */
6587 struct ui_file *tmp_error_stream = mem_fileopen ();
6588 make_cleanup_ui_file_delete (tmp_error_stream);
6591 if (b->type == bp_hardware_breakpoint)
6593 fprintf_unfiltered (tmp_error_stream,
6594 "Cannot insert hardware breakpoint %d.\n"
6595 "You may have requested too many hardware breakpoints.\n",
6600 fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number);
6601 fprintf_filtered (tmp_error_stream, "Error accessing memory address ");
6602 print_address_numeric (b->address, 1, tmp_error_stream);
6603 fprintf_filtered (tmp_error_stream, ": %s.\n",
6604 safe_strerror (val));
6607 fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process.");
6608 target_terminal_ours_for_output ();
6609 error_stream(tmp_error_stream);
6616 free_command_lines (&bpt->commands);
6619 if (bpt->cond_string != NULL)
6620 xfree (bpt->cond_string);
6621 if (bpt->addr_string != NULL)
6622 xfree (bpt->addr_string);
6623 if (bpt->exp != NULL)
6625 if (bpt->exp_string != NULL)
6626 xfree (bpt->exp_string);
6627 if (bpt->val != NULL)
6628 value_free (bpt->val);
6629 if (bpt->source_file != NULL)
6630 xfree (bpt->source_file);
6631 if (bpt->dll_pathname != NULL)
6632 xfree (bpt->dll_pathname);
6633 if (bpt->triggered_dll_pathname != NULL)
6634 xfree (bpt->triggered_dll_pathname);
6635 if (bpt->exec_pathname != NULL)
6636 xfree (bpt->exec_pathname);
6638 /* Be sure no bpstat's are pointing at it after it's been freed. */
6639 /* FIXME, how can we find all bpstat's?
6640 We just check stop_bpstat for now. */
6641 for (bs = stop_bpstat; bs; bs = bs->next)
6642 if (bs->breakpoint_at == bpt)
6644 bs->breakpoint_at = NULL;
6646 /* bs->commands will be freed later. */
6648 /* On the chance that someone will soon try again to delete this same
6649 bp, we mark it as deleted before freeing its storage. */
6650 bpt->type = bp_none;
6656 do_delete_breakpoint_cleanup (void *b)
6658 delete_breakpoint (b);
6662 make_cleanup_delete_breakpoint (struct breakpoint *b)
6664 return make_cleanup (do_delete_breakpoint_cleanup, b);
6668 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
6670 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
6674 delete_command (char *arg, int from_tty)
6676 struct breakpoint *b, *temp;
6682 int breaks_to_delete = 0;
6684 /* Delete all breakpoints if no argument.
6685 Do not delete internal or call-dummy breakpoints, these
6686 have to be deleted with an explicit breakpoint number argument. */
6689 if (b->type != bp_call_dummy &&
6690 b->type != bp_shlib_event &&
6691 b->type != bp_thread_event &&
6692 b->type != bp_overlay_event &&
6694 breaks_to_delete = 1;
6697 /* Ask user only if there are some breakpoints to delete. */
6699 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6701 ALL_BREAKPOINTS_SAFE (b, temp)
6703 if (b->type != bp_call_dummy &&
6704 b->type != bp_shlib_event &&
6705 b->type != bp_thread_event &&
6706 b->type != bp_overlay_event &&
6708 delete_breakpoint (b);
6713 map_breakpoint_numbers (arg, delete_breakpoint);
6716 /* Reset a breakpoint given it's struct breakpoint * BINT.
6717 The value we return ends up being the return value from catch_errors.
6718 Unused in this case. */
6721 breakpoint_re_set_one (void *bint)
6723 /* get past catch_errs */
6724 struct breakpoint *b = (struct breakpoint *) bint;
6727 struct symtabs_and_lines sals;
6729 enum enable_state save_enable;
6734 warning ("attempted to reset apparently deleted breakpoint #%d?",
6738 case bp_hardware_breakpoint:
6740 case bp_catch_unload:
6741 if (b->addr_string == NULL)
6743 /* Anything without a string can't be re-set. */
6744 delete_breakpoint (b);
6747 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6749 ``And a hack it is, although Apple's Darwin version of GDB
6750 contains an almost identical hack to implement a "future
6751 break" command. It seems to work in many real world cases,
6752 but it is easy to come up with a test case where the patch
6753 doesn't help at all.''
6755 ``It seems that the way GDB implements breakpoints - in -
6756 shared - libraries was designed for a.out shared library
6757 systems (SunOS 4) where shared libraries were loaded at a
6758 fixed address in memory. Since ELF shared libraries can (and
6759 will) be loaded at any address in memory, things break.
6760 Fixing this is not trivial. Therefore, I'm not sure whether
6761 we should add this hack to the branch only. I cannot
6762 guarantee that things will be fixed on the trunk in the near
6765 In case we have a problem, disable this breakpoint. We'll
6766 restore its status if we succeed. Don't disable a
6767 shlib_disabled breakpoint though. There's a fair chance we
6768 can't re-set it if the shared library it's in hasn't been
6770 save_enable = b->enable_state;
6771 if (b->enable_state != bp_shlib_disabled)
6772 b->enable_state = bp_disabled;
6774 set_language (b->language);
6775 input_radix = b->input_radix;
6777 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
6778 for (i = 0; i < sals.nelts; i++)
6780 resolve_sal_pc (&sals.sals[i]);
6782 /* Reparse conditions, they might contain references to the
6784 if (b->cond_string != NULL)
6789 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6792 /* We need to re-set the breakpoint if the address changes... */
6793 if (b->address != sals.sals[i].pc
6794 /* ...or new and old breakpoints both have source files, and
6795 the source file name or the line number changes... */
6796 || (b->source_file != NULL
6797 && sals.sals[i].symtab != NULL
6798 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6799 || b->line_number != sals.sals[i].line)
6801 /* ...or we switch between having a source file and not having
6803 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6806 if (b->source_file != NULL)
6807 xfree (b->source_file);
6808 if (sals.sals[i].symtab == NULL)
6809 b->source_file = NULL;
6812 savestring (sals.sals[i].symtab->filename,
6813 strlen (sals.sals[i].symtab->filename));
6814 b->line_number = sals.sals[i].line;
6815 b->address = sals.sals[i].pc;
6817 /* Used to check for duplicates here, but that can
6818 cause trouble, as it doesn't check for disabled
6823 /* Might be better to do this just once per breakpoint_re_set,
6824 rather than once for every breakpoint. */
6825 breakpoints_changed ();
6827 b->section = sals.sals[i].section;
6828 b->enable_state = save_enable; /* Restore it, this worked. */
6831 /* Now that this is re-enabled, check_duplicates
6833 check_duplicates (b);
6840 case bp_hardware_watchpoint:
6841 case bp_read_watchpoint:
6842 case bp_access_watchpoint:
6843 innermost_block = NULL;
6844 /* The issue arises of what context to evaluate this in. The
6845 same one as when it was set, but what does that mean when
6846 symbols have been re-read? We could save the filename and
6847 functionname, but if the context is more local than that, the
6848 best we could do would be something like how many levels deep
6849 and which index at that particular level, but that's going to
6850 be less stable than filenames or function names. */
6852 /* So for now, just use a global context. */
6855 b->exp = parse_expression (b->exp_string);
6856 b->exp_valid_block = innermost_block;
6857 mark = value_mark ();
6859 value_free (b->val);
6860 b->val = evaluate_expression (b->exp);
6861 release_value (b->val);
6862 if (VALUE_LAZY (b->val) && b->enable_state == bp_enabled)
6863 value_fetch_lazy (b->val);
6865 if (b->cond_string != NULL)
6870 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
6872 if (b->enable_state == bp_enabled)
6874 value_free_to_mark (mark);
6876 case bp_catch_catch:
6877 case bp_catch_throw:
6879 /* We needn't really do anything to reset these, since the mask
6880 that requests them is unaffected by e.g., new libraries being
6883 case bp_catch_vfork:
6888 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
6890 /* Delete longjmp and overlay event breakpoints; they will be
6891 reset later by breakpoint_re_set. */
6893 case bp_longjmp_resume:
6894 case bp_overlay_event:
6895 delete_breakpoint (b);
6898 /* This breakpoint is special, it's set up when the inferior
6899 starts and we really don't want to touch it. */
6900 case bp_shlib_event:
6902 /* Like bp_shlib_event, this breakpoint type is special.
6903 Once it is set up, we do not want to touch it. */
6904 case bp_thread_event:
6906 /* Keep temporary breakpoints, which can be encountered when we step
6907 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6908 Otherwise these should have been blown away via the cleanup chain
6909 or by breakpoint_init_inferior when we rerun the executable. */
6912 case bp_watchpoint_scope:
6914 case bp_step_resume:
6921 /* Re-set all breakpoints after symbols have been re-loaded. */
6923 breakpoint_re_set (void)
6925 struct breakpoint *b, *temp;
6926 enum language save_language;
6927 int save_input_radix;
6928 static char message1[] = "Error in re-setting breakpoint %d:\n";
6929 char message[sizeof (message1) + 30 /* slop */ ];
6931 save_language = current_language->la_language;
6932 save_input_radix = input_radix;
6933 ALL_BREAKPOINTS_SAFE (b, temp)
6935 /* Format possible error msg */
6936 sprintf (message, message1, b->number);
6937 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
6939 set_language (save_language);
6940 input_radix = save_input_radix;
6942 if (GET_LONGJMP_TARGET_P ())
6944 create_longjmp_breakpoint ("longjmp");
6945 create_longjmp_breakpoint ("_longjmp");
6946 create_longjmp_breakpoint ("siglongjmp");
6947 create_longjmp_breakpoint ("_siglongjmp");
6948 create_longjmp_breakpoint (NULL);
6951 create_overlay_event_breakpoint ("_ovly_debug_event");
6954 /* Reset the thread number of this breakpoint:
6956 - If the breakpoint is for all threads, leave it as-is.
6957 - Else, reset it to the current thread for inferior_ptid. */
6959 breakpoint_re_set_thread (struct breakpoint *b)
6961 if (b->thread != -1)
6963 if (in_thread_list (inferior_ptid))
6964 b->thread = pid_to_thread_id (inferior_ptid);
6968 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
6969 If from_tty is nonzero, it prints a message to that effect,
6970 which ends with a period (no newline). */
6973 set_ignore_count (int bptnum, int count, int from_tty)
6975 register struct breakpoint *b;
6981 if (b->number == bptnum)
6983 b->ignore_count = count;
6987 printf_filtered ("Will stop next time breakpoint %d is reached.",
6989 else if (count == 1)
6990 printf_filtered ("Will ignore next crossing of breakpoint %d.",
6993 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
6996 breakpoints_changed ();
6997 breakpoint_modify_event (b->number);
7001 error ("No breakpoint number %d.", bptnum);
7004 /* Clear the ignore counts of all breakpoints. */
7006 breakpoint_clear_ignore_counts (void)
7008 struct breakpoint *b;
7011 b->ignore_count = 0;
7014 /* Command to set ignore-count of breakpoint N to COUNT. */
7017 ignore_command (char *args, int from_tty)
7023 error_no_arg ("a breakpoint number");
7025 num = get_number (&p);
7027 error ("bad breakpoint number: '%s'", args);
7029 error ("Second argument (specified ignore-count) is missing.");
7031 set_ignore_count (num,
7032 longest_to_int (value_as_long (parse_and_eval (p))),
7035 printf_filtered ("\n");
7038 /* Call FUNCTION on each of the breakpoints
7039 whose numbers are given in ARGS. */
7042 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7044 register char *p = args;
7047 register struct breakpoint *b, *tmp;
7051 error_no_arg ("one or more breakpoint numbers");
7058 num = get_number_or_range (&p1);
7061 warning ("bad breakpoint number at or near '%s'", p);
7065 ALL_BREAKPOINTS_SAFE (b, tmp)
7066 if (b->number == num)
7068 struct breakpoint *related_breakpoint = b->related_breakpoint;
7071 if (related_breakpoint)
7072 function (related_breakpoint);
7076 printf_unfiltered ("No breakpoint number %d.\n", num);
7082 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7083 If from_tty is nonzero, it prints a message to that effect,
7084 which ends with a period (no newline). */
7087 disable_breakpoint (struct breakpoint *bpt)
7089 /* Never disable a watchpoint scope breakpoint; we want to
7090 hit them when we leave scope so we can delete both the
7091 watchpoint and its scope breakpoint at that time. */
7092 if (bpt->type == bp_watchpoint_scope)
7095 /* You can't disable permanent breakpoints. */
7096 if (bpt->enable_state == bp_permanent)
7099 bpt->enable_state = bp_disabled;
7101 check_duplicates (bpt);
7103 if (modify_breakpoint_hook)
7104 modify_breakpoint_hook (bpt);
7105 breakpoint_modify_event (bpt->number);
7110 disable_command (char *args, int from_tty)
7112 register struct breakpoint *bpt;
7114 ALL_BREAKPOINTS (bpt)
7118 warning ("attempted to disable apparently deleted breakpoint #%d?",
7123 case bp_catch_unload:
7125 case bp_catch_vfork:
7127 case bp_catch_catch:
7128 case bp_catch_throw:
7129 case bp_hardware_breakpoint:
7131 case bp_hardware_watchpoint:
7132 case bp_read_watchpoint:
7133 case bp_access_watchpoint:
7134 disable_breakpoint (bpt);
7139 map_breakpoint_numbers (args, disable_breakpoint);
7143 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7145 struct frame_info *save_selected_frame = NULL;
7146 int save_selected_frame_level = -1;
7147 int target_resources_ok, other_type_used;
7150 if (bpt->type == bp_hardware_breakpoint)
7153 i = hw_breakpoint_used_count ();
7154 target_resources_ok =
7155 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7157 if (target_resources_ok == 0)
7158 error ("No hardware breakpoint support in the target.");
7159 else if (target_resources_ok < 0)
7160 error ("Hardware breakpoints used exceeds limit.");
7163 if (bpt->enable_state != bp_permanent)
7164 bpt->enable_state = bp_enabled;
7165 bpt->disposition = disposition;
7166 check_duplicates (bpt);
7167 breakpoints_changed ();
7169 if (bpt->type == bp_watchpoint ||
7170 bpt->type == bp_hardware_watchpoint ||
7171 bpt->type == bp_read_watchpoint ||
7172 bpt->type == bp_access_watchpoint)
7174 if (bpt->exp_valid_block != NULL)
7176 struct frame_info *fr =
7177 fr = frame_find_by_id (bpt->watchpoint_frame);
7181 Cannot enable watchpoint %d because the block in which its expression\n\
7182 is valid is not currently in scope.\n", bpt->number);
7183 bpt->enable_state = bp_disabled;
7187 save_selected_frame = deprecated_selected_frame;
7188 save_selected_frame_level = frame_relative_level (deprecated_selected_frame);
7192 value_free (bpt->val);
7193 mark = value_mark ();
7194 bpt->val = evaluate_expression (bpt->exp);
7195 release_value (bpt->val);
7196 if (VALUE_LAZY (bpt->val))
7197 value_fetch_lazy (bpt->val);
7199 if (bpt->type == bp_hardware_watchpoint ||
7200 bpt->type == bp_read_watchpoint ||
7201 bpt->type == bp_access_watchpoint)
7203 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7204 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7206 /* Hack around 'unused var' error for some targets here */
7208 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7209 bpt->type, i + mem_cnt, other_type_used);
7210 /* we can consider of type is bp_hardware_watchpoint, convert to
7211 bp_watchpoint in the following condition */
7212 if (target_resources_ok < 0)
7215 Cannot enable watchpoint %d because target watch resources\n\
7216 have been allocated for other watchpoints.\n", bpt->number);
7217 bpt->enable_state = bp_disabled;
7218 value_free_to_mark (mark);
7223 if (save_selected_frame_level >= 0)
7224 select_frame (save_selected_frame);
7225 value_free_to_mark (mark);
7227 if (modify_breakpoint_hook)
7228 modify_breakpoint_hook (bpt);
7229 breakpoint_modify_event (bpt->number);
7233 enable_breakpoint (struct breakpoint *bpt)
7235 do_enable_breakpoint (bpt, bpt->disposition);
7238 /* The enable command enables the specified breakpoints (or all defined
7239 breakpoints) so they once again become (or continue to be) effective
7240 in stopping the inferior. */
7244 enable_command (char *args, int from_tty)
7246 register struct breakpoint *bpt;
7248 ALL_BREAKPOINTS (bpt)
7252 warning ("attempted to enable apparently deleted breakpoint #%d?",
7257 case bp_catch_unload:
7259 case bp_catch_vfork:
7261 case bp_catch_catch:
7262 case bp_catch_throw:
7263 case bp_hardware_breakpoint:
7265 case bp_hardware_watchpoint:
7266 case bp_read_watchpoint:
7267 case bp_access_watchpoint:
7268 enable_breakpoint (bpt);
7273 map_breakpoint_numbers (args, enable_breakpoint);
7277 enable_once_breakpoint (struct breakpoint *bpt)
7279 do_enable_breakpoint (bpt, disp_disable);
7284 enable_once_command (char *args, int from_tty)
7286 map_breakpoint_numbers (args, enable_once_breakpoint);
7290 enable_delete_breakpoint (struct breakpoint *bpt)
7292 do_enable_breakpoint (bpt, disp_del);
7297 enable_delete_command (char *args, int from_tty)
7299 map_breakpoint_numbers (args, enable_delete_breakpoint);
7302 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7304 struct symtabs_and_lines
7305 decode_line_spec_1 (char *string, int funfirstline)
7307 struct symtabs_and_lines sals;
7309 error ("Empty line specification.");
7310 if (default_breakpoint_valid)
7311 sals = decode_line_1 (&string, funfirstline,
7312 default_breakpoint_symtab,
7313 default_breakpoint_line,
7316 sals = decode_line_1 (&string, funfirstline,
7317 (struct symtab *) NULL, 0, (char ***) NULL);
7319 error ("Junk at end of line specification: %s", string);
7324 _initialize_breakpoint (void)
7326 struct cmd_list_element *c;
7328 breakpoint_chain = 0;
7329 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7330 before a breakpoint is set. */
7331 breakpoint_count = 0;
7333 add_com ("ignore", class_breakpoint, ignore_command,
7334 "Set ignore-count of breakpoint number N to COUNT.\n\
7335 Usage is `ignore N COUNT'.");
7337 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7339 add_com ("commands", class_breakpoint, commands_command,
7340 "Set commands to be executed when a breakpoint is hit.\n\
7341 Give breakpoint number as argument after \"commands\".\n\
7342 With no argument, the targeted breakpoint is the last one set.\n\
7343 The commands themselves follow starting on the next line.\n\
7344 Type a line containing \"end\" to indicate the end of them.\n\
7345 Give \"silent\" as the first line to make the breakpoint silent;\n\
7346 then no output is printed when it is hit, except what the commands print.");
7348 add_com ("condition", class_breakpoint, condition_command,
7349 "Specify breakpoint number N to break only if COND is true.\n\
7350 Usage is `condition N COND', where N is an integer and COND is an\n\
7351 expression to be evaluated whenever breakpoint N is reached.");
7353 c = add_com ("tbreak", class_breakpoint, tbreak_command,
7354 "Set a temporary breakpoint. Args like \"break\" command.\n\
7355 Like \"break\" except the breakpoint is only temporary,\n\
7356 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7357 by using \"enable delete\" on the breakpoint number.");
7358 set_cmd_completer (c, location_completer);
7360 c = add_com ("hbreak", class_breakpoint, hbreak_command,
7361 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7362 Like \"break\" except the breakpoint requires hardware support,\n\
7363 some target hardware may not have this support.");
7364 set_cmd_completer (c, location_completer);
7366 c = add_com ("thbreak", class_breakpoint, thbreak_command,
7367 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7368 Like \"hbreak\" except the breakpoint is only temporary,\n\
7369 so it will be deleted when hit.");
7370 set_cmd_completer (c, location_completer);
7372 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7373 "Enable some breakpoints.\n\
7374 Give breakpoint numbers (separated by spaces) as arguments.\n\
7375 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7376 This is used to cancel the effect of the \"disable\" command.\n\
7377 With a subcommand you can enable temporarily.",
7378 &enablelist, "enable ", 1, &cmdlist);
7380 add_com ("ab", class_breakpoint, enable_command,
7381 "Enable some breakpoints.\n\
7382 Give breakpoint numbers (separated by spaces) as arguments.\n\
7383 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7384 This is used to cancel the effect of the \"disable\" command.\n\
7385 With a subcommand you can enable temporarily.");
7387 add_com_alias ("en", "enable", class_breakpoint, 1);
7389 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7390 "Enable some breakpoints.\n\
7391 Give breakpoint numbers (separated by spaces) as arguments.\n\
7392 This is used to cancel the effect of the \"disable\" command.\n\
7393 May be abbreviated to simply \"enable\".\n",
7394 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7396 add_cmd ("once", no_class, enable_once_command,
7397 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7398 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7401 add_cmd ("delete", no_class, enable_delete_command,
7402 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7403 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7406 add_cmd ("delete", no_class, enable_delete_command,
7407 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7408 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7411 add_cmd ("once", no_class, enable_once_command,
7412 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7413 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7416 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7417 "Disable some breakpoints.\n\
7418 Arguments are breakpoint numbers with spaces in between.\n\
7419 To disable all breakpoints, give no argument.\n\
7420 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7421 &disablelist, "disable ", 1, &cmdlist);
7422 add_com_alias ("dis", "disable", class_breakpoint, 1);
7423 add_com_alias ("disa", "disable", class_breakpoint, 1);
7425 add_com ("sb", class_breakpoint, disable_command,
7426 "Disable some breakpoints.\n\
7427 Arguments are breakpoint numbers with spaces in between.\n\
7428 To disable all breakpoints, give no argument.\n\
7429 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7431 add_cmd ("breakpoints", class_alias, disable_command,
7432 "Disable some breakpoints.\n\
7433 Arguments are breakpoint numbers with spaces in between.\n\
7434 To disable all breakpoints, give no argument.\n\
7435 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7436 This command may be abbreviated \"disable\".",
7439 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7440 "Delete some breakpoints or auto-display expressions.\n\
7441 Arguments are breakpoint numbers with spaces in between.\n\
7442 To delete all breakpoints, give no argument.\n\
7444 Also a prefix command for deletion of other GDB objects.\n\
7445 The \"unset\" command is also an alias for \"delete\".",
7446 &deletelist, "delete ", 1, &cmdlist);
7447 add_com_alias ("d", "delete", class_breakpoint, 1);
7449 add_com ("db", class_breakpoint, delete_command,
7450 "Delete some breakpoints.\n\
7451 Arguments are breakpoint numbers with spaces in between.\n\
7452 To delete all breakpoints, give no argument.\n");
7454 add_cmd ("breakpoints", class_alias, delete_command,
7455 "Delete some breakpoints or auto-display expressions.\n\
7456 Arguments are breakpoint numbers with spaces in between.\n\
7457 To delete all breakpoints, give no argument.\n\
7458 This command may be abbreviated \"delete\".",
7461 add_com ("clear", class_breakpoint, clear_command,
7462 concat ("Clear breakpoint at specified line or function.\n\
7463 Argument may be line number, function name, or \"*\" and an address.\n\
7464 If line number is specified, all breakpoints in that line are cleared.\n\
7465 If function is specified, breakpoints at beginning of function are cleared.\n\
7466 If an address is specified, breakpoints at that address are cleared.\n\n",
7467 "With no argument, clears all breakpoints in the line that the selected frame\n\
7470 See also the \"delete\" command which clears breakpoints by number.", NULL));
7472 c = add_com ("break", class_breakpoint, break_command,
7473 concat ("Set breakpoint at specified line or function.\n\
7474 Argument may be line number, function name, or \"*\" and an address.\n\
7475 If line number is specified, break at start of code for that line.\n\
7476 If function is specified, break at start of code for that function.\n\
7477 If an address is specified, break at that exact address.\n",
7478 "With no arg, uses current execution address of selected stack frame.\n\
7479 This is useful for breaking on return to a stack frame.\n\
7481 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7483 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7484 set_cmd_completer (c, location_completer);
7486 add_com_alias ("b", "break", class_run, 1);
7487 add_com_alias ("br", "break", class_run, 1);
7488 add_com_alias ("bre", "break", class_run, 1);
7489 add_com_alias ("brea", "break", class_run, 1);
7493 add_com_alias ("ba", "break", class_breakpoint, 1);
7494 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7499 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7500 "Break in function/address or break at a line in the current file.",
7501 &stoplist, "stop ", 1, &cmdlist);
7502 add_cmd ("in", class_breakpoint, stopin_command,
7503 "Break in function or address.\n", &stoplist);
7504 add_cmd ("at", class_breakpoint, stopat_command,
7505 "Break at a line in the current file.\n", &stoplist);
7506 add_com ("status", class_info, breakpoints_info,
7507 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7508 The \"Type\" column indicates one of:\n\
7509 \tbreakpoint - normal breakpoint\n\
7510 \twatchpoint - watchpoint\n\
7511 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7512 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7513 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7514 address and file/line number respectively.\n\n",
7515 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7516 are set to the address of the last breakpoint listed.\n\n\
7517 Convenience variable \"$bpnum\" contains the number of the last\n\
7518 breakpoint set.", NULL));
7521 add_info ("breakpoints", breakpoints_info,
7522 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7523 The \"Type\" column indicates one of:\n\
7524 \tbreakpoint - normal breakpoint\n\
7525 \twatchpoint - watchpoint\n\
7526 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7527 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7528 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7529 address and file/line number respectively.\n\n",
7530 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7531 are set to the address of the last breakpoint listed.\n\n\
7532 Convenience variable \"$bpnum\" contains the number of the last\n\
7533 breakpoint set.", NULL));
7536 add_com ("lb", class_breakpoint, breakpoints_info,
7537 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7538 The \"Type\" column indicates one of:\n\
7539 \tbreakpoint - normal breakpoint\n\
7540 \twatchpoint - watchpoint\n\
7541 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7542 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7543 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7544 address and file/line number respectively.\n\n",
7545 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7546 are set to the address of the last breakpoint listed.\n\n\
7547 Convenience variable \"$bpnum\" contains the number of the last\n\
7548 breakpoint set.", NULL));
7550 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7551 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7552 The \"Type\" column indicates one of:\n\
7553 \tbreakpoint - normal breakpoint\n\
7554 \twatchpoint - watchpoint\n\
7555 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7556 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7557 \tuntil - internal breakpoint used by the \"until\" command\n\
7558 \tfinish - internal breakpoint used by the \"finish\" command\n",
7559 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7560 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7561 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7562 address and file/line number respectively.\n\n",
7563 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7564 are set to the address of the last breakpoint listed.\n\n\
7565 Convenience variable \"$bpnum\" contains the number of the last\n\
7566 breakpoint set.", NULL),
7567 &maintenanceinfolist);
7569 add_com ("catch", class_breakpoint, catch_command,
7570 "Set catchpoints to catch events.\n\
7571 Raised signals may be caught:\n\
7572 \tcatch signal - all signals\n\
7573 \tcatch signal <signame> - a particular signal\n\
7574 Raised exceptions may be caught:\n\
7575 \tcatch throw - all exceptions, when thrown\n\
7576 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7577 \tcatch catch - all exceptions, when caught\n\
7578 \tcatch catch <exceptname> - a particular exception, when caught\n\
7579 Thread or process events may be caught:\n\
7580 \tcatch thread_start - any threads, just after creation\n\
7581 \tcatch thread_exit - any threads, just before expiration\n\
7582 \tcatch thread_join - any threads, just after joins\n\
7583 Process events may be caught:\n\
7584 \tcatch start - any processes, just after creation\n\
7585 \tcatch exit - any processes, just before expiration\n\
7586 \tcatch fork - calls to fork()\n\
7587 \tcatch vfork - calls to vfork()\n\
7588 \tcatch exec - calls to exec()\n\
7589 Dynamically-linked library events may be caught:\n\
7590 \tcatch load - loads of any library\n\
7591 \tcatch load <libname> - loads of a particular library\n\
7592 \tcatch unload - unloads of any library\n\
7593 \tcatch unload <libname> - unloads of a particular library\n\
7594 The act of your program's execution stopping may also be caught:\n\
7596 C++ exceptions may be caught:\n\
7597 \tcatch throw - all exceptions, when thrown\n\
7598 \tcatch catch - all exceptions, when caught\n\
7600 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7601 after a fork or vfork is caught.\n\n\
7602 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7604 add_com ("tcatch", class_breakpoint, tcatch_command,
7605 "Set temporary catchpoints to catch events.\n\
7606 Args like \"catch\" command.\n\
7607 Like \"catch\" except the catchpoint is only temporary,\n\
7608 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7609 by using \"enable delete\" on the catchpoint number.");
7611 c = add_com ("watch", class_breakpoint, watch_command,
7612 "Set a watchpoint for an expression.\n\
7613 A watchpoint stops execution of your program whenever the value of\n\
7614 an expression changes.");
7615 set_cmd_completer (c, location_completer);
7617 c = add_com ("rwatch", class_breakpoint, rwatch_command,
7618 "Set a read watchpoint for an expression.\n\
7619 A watchpoint stops execution of your program whenever the value of\n\
7620 an expression is read.");
7621 set_cmd_completer (c, location_completer);
7623 c = add_com ("awatch", class_breakpoint, awatch_command,
7624 "Set a watchpoint for an expression.\n\
7625 A watchpoint stops execution of your program whenever the value of\n\
7626 an expression is either read or written.");
7627 set_cmd_completer (c, location_completer);
7629 add_info ("watchpoints", breakpoints_info,
7630 "Synonym for ``info breakpoints''.");
7633 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
7634 (char *) &can_use_hw_watchpoints,
7635 "Set debugger's willingness to use watchpoint hardware.\n\
7636 If zero, gdb will not use hardware for new watchpoints, even if\n\
7637 such is available. (However, any hardware watchpoints that were\n\
7638 created before setting this to nonzero, will continue to use watchpoint\n\
7641 add_show_from_set (c, &showlist);
7643 can_use_hw_watchpoints = 1;