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 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"
45 #include "completer.h"
48 #include "cli/cli-script.h"
50 #include "gdb-events.h"
52 /* Prototypes for local functions. */
54 static void until_break_command_continuation (struct continuation_arg *arg);
56 static void catch_command_1 (char *, int, int);
58 static void enable_delete_command (char *, int);
60 static void enable_delete_breakpoint (struct breakpoint *);
62 static void enable_once_command (char *, int);
64 static void enable_once_breakpoint (struct breakpoint *);
66 static void disable_command (char *, int);
68 static void enable_command (char *, int);
70 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
72 static void ignore_command (char *, int);
74 static int breakpoint_re_set_one (PTR);
76 static void clear_command (char *, int);
78 static void catch_command (char *, int);
80 static void handle_gnu_4_16_catch_command (char *, int, int);
82 static struct symtabs_and_lines get_catch_sals (int);
84 static void watch_command (char *, int);
86 static int can_use_hardware_watchpoint (struct value *);
88 extern void break_at_finish_command (char *, int);
89 extern void break_at_finish_at_depth_command (char *, int);
91 extern void tbreak_at_finish_command (char *, int);
93 static void break_command_1 (char *, int, int);
95 static void mention (struct breakpoint *);
97 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
99 static void check_duplicates (struct breakpoint *);
101 static void describe_other_breakpoints (CORE_ADDR, asection *);
103 static void breakpoints_info (char *, int);
105 static void breakpoint_1 (int, int);
107 static bpstat bpstat_alloc (struct breakpoint *, bpstat);
109 static int breakpoint_cond_eval (PTR);
111 static void cleanup_executing_breakpoints (PTR);
113 static void commands_command (char *, int);
115 static void condition_command (char *, int);
117 static int get_number_trailer (char **, int);
119 void set_breakpoint_count (int);
128 static int remove_breakpoint (struct breakpoint *, insertion_state_t);
130 static enum print_stop_action print_it_typical (bpstat);
132 static enum print_stop_action print_bp_stop_message (bpstat bs);
136 enum exception_event_kind kind;
139 args_for_catchpoint_enable;
141 static int watchpoint_check (PTR);
143 static int cover_target_enable_exception_callback (PTR);
145 static void maintenance_info_breakpoints (char *, int);
147 static void create_longjmp_breakpoint (char *);
149 static void create_overlay_event_breakpoint (char *);
151 static int hw_breakpoint_used_count (void);
153 static int hw_watchpoint_used_count (enum bptype, int *);
155 static void hbreak_command (char *, int);
157 static void thbreak_command (char *, int);
159 static void watch_command_1 (char *, int, int);
161 static void rwatch_command (char *, int);
163 static void awatch_command (char *, int);
165 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
167 static void solib_load_unload_1 (char *hookname,
170 char *cond_string, enum bptype bp_kind);
172 static void create_fork_vfork_event_catchpoint (int tempflag,
174 enum bptype bp_kind);
176 static void break_at_finish_at_depth_command_1 (char *arg,
177 int flag, int from_tty);
179 static void break_at_finish_command_1 (char *arg, int flag, int from_tty);
181 static void stop_command (char *arg, int from_tty);
183 static void stopin_command (char *arg, int from_tty);
185 static void stopat_command (char *arg, int from_tty);
187 static char *ep_find_event_name_end (char *arg);
189 static char *ep_parse_optional_if_clause (char **arg);
191 static char *ep_parse_optional_filename (char **arg);
193 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
194 static void catch_exec_command_1 (char *arg, int tempflag, int from_tty);
197 static void create_exception_catchpoint (int tempflag, char *cond_string,
198 enum exception_event_kind ex_event,
199 struct symtab_and_line *sal);
201 static void catch_exception_command_1 (enum exception_event_kind ex_event,
202 char *arg, int tempflag, int from_tty);
204 static void tcatch_command (char *arg, int from_tty);
206 static void ep_skip_leading_whitespace (char **s);
208 /* Prototypes for exported functions. */
210 /* If FALSE, gdb will not use hardware support for watchpoints, even
211 if such is available. */
212 static int can_use_hw_watchpoints;
214 void _initialize_breakpoint (void);
216 extern int addressprint; /* Print machine addresses? */
218 /* Are we executing breakpoint commands? */
219 static int executing_breakpoint_commands;
221 /* Are overlay event breakpoints enabled? */
222 static int overlay_events_enabled;
224 /* Walk the following statement or block through all breakpoints.
225 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
228 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
230 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
231 for (B = breakpoint_chain; \
232 B ? (TMP=B->next, 1): 0; \
235 /* True if SHIFT_INST_REGS defined, false otherwise. */
237 int must_shift_inst_regs =
238 #if defined(SHIFT_INST_REGS)
245 /* True if breakpoint hit counts should be displayed in breakpoint info. */
247 int show_breakpoint_hit_counts = 1;
249 /* Chain of all breakpoints defined. */
251 struct breakpoint *breakpoint_chain;
253 /* Number of last breakpoint made. */
255 int breakpoint_count;
257 /* Pointer to current exception event record */
258 static struct exception_event_record *current_exception_event;
260 /* Indicator of whether exception catchpoints should be nuked
261 between runs of a program */
262 int exception_catchpoints_are_fragile = 0;
264 /* Indicator of when exception catchpoints set-up should be
265 reinitialized -- e.g. when program is re-run */
266 int exception_support_initialized = 0;
268 /* This function returns a pointer to the string representation of the
269 pathname of the dynamically-linked library that has just been
272 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
273 or undefined results are guaranteed.
275 This string's contents are only valid immediately after the
276 inferior has stopped in the dynamic linker hook, and becomes
277 invalid as soon as the inferior is continued. Clients should make
278 a copy of this string if they wish to continue the inferior and
279 then access the string. */
281 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
282 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
285 /* This function returns a pointer to the string representation of the
286 pathname of the dynamically-linked library that has just been
289 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
290 TRUE, or undefined results are guaranteed.
292 This string's contents are only valid immediately after the
293 inferior has stopped in the dynamic linker hook, and becomes
294 invalid as soon as the inferior is continued. Clients should make
295 a copy of this string if they wish to continue the inferior and
296 then access the string. */
298 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
299 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
302 /* This function is called by the "catch load" command. It allows the
303 debugger to be notified by the dynamic linker when a specified
304 library file (or any library file, if filename is NULL) is loaded. */
306 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
307 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
308 error ("catch of library loads not yet implemented on this platform")
311 /* This function is called by the "catch unload" command. It allows
312 the debugger to be notified by the dynamic linker when a specified
313 library file (or any library file, if filename is NULL) is
316 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
317 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
318 error ("catch of library unloads not yet implemented on this platform")
321 /* Set breakpoint count to NUM. */
324 set_breakpoint_count (int num)
326 breakpoint_count = num;
327 set_internalvar (lookup_internalvar ("bpnum"),
328 value_from_longest (builtin_type_int, (LONGEST) num));
331 /* Used in run_command to zero the hit count when a new run starts. */
334 clear_breakpoint_hit_counts (void)
336 struct breakpoint *b;
342 /* Default address, symtab and line to put a breakpoint at
343 for "break" command with no arg.
344 if default_breakpoint_valid is zero, the other three are
345 not valid, and "break" with no arg is an error.
347 This set by print_stack_frame, which calls set_default_breakpoint. */
349 int default_breakpoint_valid;
350 CORE_ADDR default_breakpoint_address;
351 struct symtab *default_breakpoint_symtab;
352 int default_breakpoint_line;
354 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
355 Advance *PP after the string and any trailing whitespace.
357 Currently the string can either be a number or "$" followed by the name
358 of a convenience variable. Making it an expression wouldn't work well
359 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
361 TRAILER is a character which can be found after the number; most
362 commonly this is `-'. If you don't want a trailer, use \0. */
364 get_number_trailer (char **pp, int trailer)
366 int retval = 0; /* default */
370 /* Empty line means refer to the last breakpoint. */
371 return breakpoint_count;
374 /* Make a copy of the name, so we can null-terminate it
375 to pass to lookup_internalvar(). */
380 while (isalnum (*p) || *p == '_')
382 varname = (char *) alloca (p - start + 1);
383 strncpy (varname, start, p - start);
384 varname[p - start] = '\0';
385 val = value_of_internalvar (lookup_internalvar (varname));
386 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
387 retval = (int) value_as_long (val);
390 printf_filtered ("Convenience variable must have integer value.\n");
398 while (*p >= '0' && *p <= '9')
401 /* There is no number here. (e.g. "cond a == b"). */
403 /* Skip non-numeric token */
404 while (*p && !isspace((int) *p))
406 /* Return zero, which caller must interpret as error. */
412 if (!(isspace (*p) || *p == '\0' || *p == trailer))
414 /* Trailing junk: return 0 and let caller print error msg. */
415 while (!(isspace (*p) || *p == '\0' || *p == trailer))
426 /* Like get_number_trailer, but don't allow a trailer. */
428 get_number (char **pp)
430 return get_number_trailer (pp, '\0');
433 /* Parse a number or a range.
434 * A number will be of the form handled by get_number.
435 * A range will be of the form <number1> - <number2>, and
436 * will represent all the integers between number1 and number2,
439 * While processing a range, this fuction is called iteratively;
440 * At each call it will return the next value in the range.
442 * At the beginning of parsing a range, the char pointer PP will
443 * be advanced past <number1> and left pointing at the '-' token.
444 * Subsequent calls will not advance the pointer until the range
445 * is completed. The call that completes the range will advance
446 * pointer PP past <number2>.
450 get_number_or_range (char **pp)
452 static int last_retval, end_value;
453 static char *end_ptr;
454 static int in_range = 0;
458 /* Default case: pp is pointing either to a solo number,
459 or to the first number of a range. */
460 last_retval = get_number_trailer (pp, '-');
465 /* This is the start of a range (<number1> - <number2>).
466 Skip the '-', parse and remember the second number,
467 and also remember the end of the final token. */
471 while (isspace ((int) *end_ptr))
472 end_ptr++; /* skip white space */
473 end_value = get_number (temp);
474 if (end_value < last_retval)
476 error ("inverted range");
478 else if (end_value == last_retval)
480 /* degenerate range (number1 == number2). Advance the
481 token pointer so that the range will be treated as a
490 error ("negative value");
493 /* pp points to the '-' that betokens a range. All
494 number-parsing has already been done. Return the next
495 integer value (one greater than the saved previous value).
496 Do not advance the token pointer 'pp' until the end of range
499 if (++last_retval == end_value)
501 /* End of range reached; advance token pointer. */
511 /* condition N EXP -- set break condition of breakpoint N to EXP. */
514 condition_command (char *arg, int from_tty)
516 register struct breakpoint *b;
521 error_no_arg ("breakpoint number");
524 bnum = get_number (&p);
526 error ("Bad breakpoint argument: '%s'", arg);
529 if (b->number == bnum)
536 if (b->cond_string != NULL)
537 xfree (b->cond_string);
542 b->cond_string = NULL;
544 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
549 /* I don't know if it matters whether this is the string the user
550 typed in or the decompiled expression. */
551 b->cond_string = savestring (arg, strlen (arg));
552 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
554 error ("Junk at end of expression");
556 breakpoints_changed ();
557 breakpoint_modify_event (b->number);
561 error ("No breakpoint number %d.", bnum);
566 commands_command (char *arg, int from_tty)
568 register struct breakpoint *b;
571 struct command_line *l;
573 /* If we allowed this, we would have problems with when to
574 free the storage, if we change the commands currently
577 if (executing_breakpoint_commands)
578 error ("Can't use the \"commands\" command among a breakpoint's commands.");
581 bnum = get_number (&p);
584 error ("Unexpected extra arguments following breakpoint number.");
587 if (b->number == bnum)
591 "Type commands for when breakpoint %d is hit, one per line.",
593 l = read_command_lines (tmpbuf, from_tty);
594 free_command_lines (&b->commands);
596 breakpoints_changed ();
597 breakpoint_modify_event (b->number);
600 error ("No breakpoint number %d.", bnum);
603 /* Like target_read_memory() but if breakpoints are inserted, return
604 the shadow contents instead of the breakpoints themselves.
606 Read "memory data" from whatever target or inferior we have.
607 Returns zero if successful, errno value if not. EIO is used
608 for address out of bounds. If breakpoints are inserted, returns
609 shadow contents, not the breakpoints themselves. From breakpoint.c. */
612 read_memory_nobpt (CORE_ADDR memaddr, char *myaddr, unsigned len)
615 struct breakpoint *b;
616 CORE_ADDR bp_addr = 0;
619 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
620 /* No breakpoints on this machine. */
621 return target_read_memory (memaddr, myaddr, len);
625 if (b->type == bp_none)
626 warning ("reading through apparently deleted breakpoint #%d?",
629 /* memory breakpoint? */
630 if (b->type == bp_watchpoint
631 || b->type == bp_hardware_watchpoint
632 || b->type == bp_read_watchpoint
633 || b->type == bp_access_watchpoint)
638 /* Addresses and length of the part of the breakpoint that
640 /* XXXX The m68k, sh and h8300 have different local and remote
641 breakpoint values. BREAKPOINT_FROM_PC still manages to
642 correctly determine the breakpoints memory address and size
643 for these targets. */
644 bp_addr = b->address;
646 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
651 if (bp_addr + bp_size <= memaddr)
652 /* The breakpoint is entirely before the chunk of memory we
655 if (bp_addr >= memaddr + len)
656 /* The breakpoint is entirely after the chunk of memory we are
659 /* Copy the breakpoint from the shadow contents, and recurse for
660 the things before and after. */
662 /* Offset within shadow_contents. */
665 if (bp_addr < memaddr)
667 /* Only copy the second part of the breakpoint. */
668 bp_size -= memaddr - bp_addr;
669 bptoffset = memaddr - bp_addr;
673 if (bp_addr + bp_size > memaddr + len)
675 /* Only copy the first part of the breakpoint. */
676 bp_size -= (bp_addr + bp_size) - (memaddr + len);
679 memcpy (myaddr + bp_addr - memaddr,
680 b->shadow_contents + bptoffset, bp_size);
682 if (bp_addr > memaddr)
684 /* Copy the section of memory before the breakpoint. */
685 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
690 if (bp_addr + bp_size < memaddr + len)
692 /* Copy the section of memory after the breakpoint. */
693 status = read_memory_nobpt (bp_addr + bp_size,
694 myaddr + bp_addr + bp_size - memaddr,
695 memaddr + len - (bp_addr + bp_size));
702 /* Nothing overlaps. Just call read_memory_noerr. */
703 return target_read_memory (memaddr, myaddr, len);
707 /* insert_breakpoints is used when starting or continuing the program.
708 remove_breakpoints is used when the program stops.
709 Both return zero if successful,
710 or an `errno' value if could not write the inferior. */
713 insert_breakpoints (void)
715 register struct breakpoint *b, *temp;
716 int return_val = 0; /* return success code. */
718 int disabled_breaks = 0;
719 int hw_breakpoint_error = 0;
720 int process_warning = 0;
722 static char message1[] = "Error inserting catchpoint %d:\n";
723 static char message[sizeof (message1) + 30];
725 #ifdef ONE_PROCESS_WRITETEXT
729 struct ui_file *tmp_error_stream = mem_fileopen ();
730 make_cleanup_ui_file_delete (tmp_error_stream);
732 /* Explicitly mark the warning -- this will only be printed if
733 there was an error. */
734 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
736 ALL_BREAKPOINTS_SAFE (b, temp)
738 if (b->enable_state == bp_permanent)
739 /* Permanent breakpoints cannot be inserted or removed. */
741 if ((b->type == bp_watchpoint
742 || b->type == bp_hardware_watchpoint
743 || b->type == bp_read_watchpoint
744 || b->type == bp_access_watchpoint) && (!b->val))
747 val = evaluate_expression (b->exp);
749 if (VALUE_LAZY (val))
750 value_fetch_lazy (val);
753 if (b->type != bp_watchpoint
754 && b->type != bp_hardware_watchpoint
755 && b->type != bp_read_watchpoint
756 && b->type != bp_access_watchpoint
757 && b->type != bp_catch_fork
758 && b->type != bp_catch_vfork
759 && b->type != bp_catch_exec
760 && b->type != bp_catch_throw
761 && b->type != bp_catch_catch
762 && b->enable_state != bp_disabled
763 && b->enable_state != bp_shlib_disabled
764 && b->enable_state != bp_call_disabled
768 /* "Normal" instruction breakpoint: either the standard
769 trap-instruction bp (bp_breakpoint), or a
770 bp_hardware_breakpoint. */
772 /* First check to see if we have to handle an overlay. */
773 if (overlay_debugging == ovly_off
774 || b->section == NULL
775 || !(section_is_overlay (b->section)))
777 /* No overlay handling: just set the breakpoint. */
779 if (b->type == bp_hardware_breakpoint)
780 val = target_insert_hw_breakpoint (b->address,
783 val = target_insert_breakpoint (b->address, b->shadow_contents);
787 /* This breakpoint is in an overlay section.
788 Shall we set a breakpoint at the LMA? */
789 if (!overlay_events_enabled)
791 /* Yes -- overlay event support is not active,
792 so we must try to set a breakpoint at the LMA.
793 This will not work for a hardware breakpoint. */
794 if (b->type == bp_hardware_breakpoint)
795 warning ("hardware breakpoint %d not supported in overlay!\n",
799 CORE_ADDR addr = overlay_unmapped_address (b->address,
801 /* Set a software (trap) breakpoint at the LMA. */
802 val = target_insert_breakpoint (addr, b->shadow_contents);
804 fprintf_unfiltered (tmp_error_stream,
805 "Overlay breakpoint %d failed: in ROM?",
809 /* Shall we set a breakpoint at the VMA? */
810 if (section_is_mapped (b->section))
812 /* Yes. This overlay section is mapped into memory. */
813 if (b->type == bp_hardware_breakpoint)
814 val = target_insert_hw_breakpoint (b->address,
817 val = target_insert_breakpoint (b->address,
822 /* No. This breakpoint will not be inserted.
823 No error, but do not mark the bp as 'inserted'. */
830 /* Can't set the breakpoint. */
831 #if defined (DISABLE_UNSETTABLE_BREAK)
832 if (DISABLE_UNSETTABLE_BREAK (b->address))
834 /* See also: disable_breakpoints_in_shlibs. */
836 b->enable_state = bp_shlib_disabled;
837 if (!disabled_breaks)
839 fprintf_unfiltered (tmp_error_stream,
840 "Cannot insert breakpoint %d.\n", b->number);
841 fprintf_unfiltered (tmp_error_stream,
842 "Temporarily disabling shared library breakpoints:\n");
845 fprintf_unfiltered (tmp_error_stream, "breakpoint #%d\n", b->number);
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, "Cannot insert breakpoint %d.\n", b->number);
861 fprintf_filtered (tmp_error_stream, "Error accessing memory address ");
862 print_address_numeric (b->address, 1, tmp_error_stream);
863 fprintf_filtered (tmp_error_stream, ": %s.\n",
864 safe_strerror (val));
873 return_val = val; /* remember failure */
875 else if (ep_is_exception_catchpoint (b)
876 && b->enable_state != bp_disabled
877 && b->enable_state != bp_shlib_disabled
878 && b->enable_state != bp_call_disabled
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, "Error accessing memory address ");
897 print_address_numeric (b->address, 1, tmp_error_stream);
898 fprintf_filtered (tmp_error_stream, ": %s.\n",
899 safe_strerror (val));
900 b->enable_state = bp_disabled;
904 /* Bp set, now make sure callbacks are enabled */
906 args_for_catchpoint_enable args;
907 args.kind = b->type == bp_catch_catch ?
908 EX_EVENT_CATCH : EX_EVENT_THROW;
910 val = catch_errors (cover_target_enable_exception_callback,
912 message, RETURN_MASK_ALL);
913 if (val != 0 && val != -1)
917 /* Check if something went wrong; val == 0 can be ignored */
920 /* something went wrong */
921 fprintf_unfiltered (tmp_error_stream,
922 "Cannot insert catchpoint %d; disabling it.\n",
924 b->enable_state = bp_disabled;
929 return_val = val; /* remember failure */
932 else if ((b->type == bp_hardware_watchpoint ||
933 b->type == bp_read_watchpoint ||
934 b->type == bp_access_watchpoint)
935 && b->enable_state == bp_enabled
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 = selected_frame;
948 saved_level = frame_relative_level (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 process_warning = 1;
1026 remove_breakpoint (b, mark_uninserted);
1027 hw_breakpoint_error = 1;
1028 fprintf_unfiltered (tmp_error_stream,
1029 "Cannot insert hardware watchpoint %d.\n", b->number);
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 != selected_frame) ||
1045 (saved_level != frame_relative_level (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)
1054 && b->enable_state == bp_enabled
1062 val = target_insert_fork_catchpoint (PIDGET (inferior_ptid));
1064 case bp_catch_vfork:
1065 val = target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
1068 val = target_insert_exec_catchpoint (PIDGET (inferior_ptid));
1071 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1076 fprintf_unfiltered (tmp_error_stream, "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, "Could not insert hardware breakpoints:\n"
1093 "You may have requested too many hardware breakpoints/watchpoints.\n");
1096 if (process_warning)
1097 fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process.");
1099 target_terminal_ours_for_output ();
1100 error_stream (tmp_error_stream);
1106 remove_breakpoints (void)
1108 register struct breakpoint *b;
1115 val = remove_breakpoint (b, mark_uninserted);
1124 remove_hw_watchpoints (void)
1126 register struct breakpoint *b;
1132 && (b->type == bp_hardware_watchpoint
1133 || b->type == bp_read_watchpoint
1134 || b->type == bp_access_watchpoint))
1136 val = remove_breakpoint (b, mark_uninserted);
1145 reattach_breakpoints (int pid)
1147 register struct breakpoint *b;
1149 struct cleanup *old_chain = save_inferior_ptid ();
1151 /* Set inferior_ptid; remove_breakpoint uses this global. */
1152 inferior_ptid = pid_to_ptid (pid);
1157 remove_breakpoint (b, mark_inserted);
1158 if (b->type == bp_hardware_breakpoint)
1159 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1161 val = target_insert_breakpoint (b->address, b->shadow_contents);
1164 do_cleanups (old_chain);
1169 do_cleanups (old_chain);
1174 update_breakpoints_after_exec (void)
1176 struct breakpoint *b;
1177 struct breakpoint *temp;
1179 /* Doing this first prevents the badness of having delete_breakpoint()
1180 write a breakpoint's current "shadow contents" to lift the bp. That
1181 shadow is NOT valid after an exec()! */
1182 mark_breakpoints_out ();
1184 ALL_BREAKPOINTS_SAFE (b, temp)
1186 /* Solib breakpoints must be explicitly reset after an exec(). */
1187 if (b->type == bp_shlib_event)
1189 delete_breakpoint (b);
1193 /* Thread event breakpoints must be set anew after an exec(),
1194 as must overlay event breakpoints. */
1195 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1197 delete_breakpoint (b);
1201 /* Step-resume breakpoints are meaningless after an exec(). */
1202 if (b->type == bp_step_resume)
1204 delete_breakpoint (b);
1208 /* Ditto the sigtramp handler breakpoints. */
1209 if (b->type == bp_through_sigtramp)
1211 delete_breakpoint (b);
1215 /* Ditto the exception-handling catchpoints. */
1216 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1218 delete_breakpoint (b);
1222 /* Don't delete an exec catchpoint, because else the inferior
1223 won't stop when it ought!
1225 Similarly, we probably ought to keep vfork catchpoints, 'cause
1226 on this target, we may not be able to stop when the vfork is
1227 seen, but only when the subsequent exec is seen. (And because
1228 deleting fork catchpoints here but not vfork catchpoints will
1229 seem mysterious to users, keep those too.)
1231 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1232 target address field, if any, is sufficient to have it be reset
1233 automagically. Certainly on HP-UX that's true.
1235 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1236 valid code address on some platforms (like the mn10200 and
1237 mn10300 simulators). We shouldn't assign any special
1238 interpretation to a breakpoint with a zero address. And in
1239 fact, GDB doesn't --- I can't see what that comment above is
1240 talking about. As far as I can tell, setting the address of a
1241 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1242 is meaningless, since those are implemented with HP-UX kernel
1243 hackery, not by storing breakpoint instructions somewhere. */
1244 if ((b->type == bp_catch_exec) ||
1245 (b->type == bp_catch_vfork) ||
1246 (b->type == bp_catch_fork))
1248 b->address = (CORE_ADDR) NULL;
1252 /* bp_finish is a special case. The only way we ought to be able
1253 to see one of these when an exec() has happened, is if the user
1254 caught a vfork, and then said "finish". Ordinarily a finish just
1255 carries them to the call-site of the current callee, by setting
1256 a temporary bp there and resuming. But in this case, the finish
1257 will carry them entirely through the vfork & exec.
1259 We don't want to allow a bp_finish to remain inserted now. But
1260 we can't safely delete it, 'cause finish_command has a handle to
1261 the bp on a bpstat, and will later want to delete it. There's a
1262 chance (and I've seen it happen) that if we delete the bp_finish
1263 here, that its storage will get reused by the time finish_command
1264 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1265 We really must allow finish_command to delete a bp_finish.
1267 In the absense of a general solution for the "how do we know
1268 it's safe to delete something others may have handles to?"
1269 problem, what we'll do here is just uninsert the bp_finish, and
1270 let finish_command delete it.
1272 (We know the bp_finish is "doomed" in the sense that it's
1273 momentary, and will be deleted as soon as finish_command sees
1274 the inferior stopped. So it doesn't matter that the bp's
1275 address is probably bogus in the new a.out, unlike e.g., the
1276 solib breakpoints.) */
1278 if (b->type == bp_finish)
1283 /* Without a symbolic address, we have little hope of the
1284 pre-exec() address meaning the same thing in the post-exec()
1286 if (b->addr_string == NULL)
1288 delete_breakpoint (b);
1292 /* If this breakpoint has survived the above battery of checks, then
1293 it must have a symbolic address. Be sure that it gets reevaluated
1294 to a target address, rather than reusing the old evaluation.
1296 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1297 for bp_catch_exec and friends, I'm pretty sure this is entirely
1298 unnecessary. A call to breakpoint_re_set_one always recomputes
1299 the breakpoint's address from scratch, or deletes it if it can't.
1300 So I think this assignment could be deleted without effect. */
1301 b->address = (CORE_ADDR) NULL;
1303 /* FIXME what about longjmp breakpoints? Re-create them here? */
1304 create_overlay_event_breakpoint ("_ovly_debug_event");
1308 detach_breakpoints (int pid)
1310 register struct breakpoint *b;
1312 struct cleanup *old_chain = save_inferior_ptid ();
1314 if (pid == PIDGET (inferior_ptid))
1315 error ("Cannot detach breakpoints of inferior_ptid");
1317 /* Set inferior_ptid; remove_breakpoint uses this global. */
1318 inferior_ptid = pid_to_ptid (pid);
1323 val = remove_breakpoint (b, mark_inserted);
1326 do_cleanups (old_chain);
1331 do_cleanups (old_chain);
1336 remove_breakpoint (struct breakpoint *b, insertion_state_t is)
1340 if (b->enable_state == bp_permanent)
1341 /* Permanent breakpoints cannot be inserted or removed. */
1344 if (b->type == bp_none)
1345 warning ("attempted to remove apparently deleted breakpoint #%d?",
1348 if (b->type != bp_watchpoint
1349 && b->type != bp_hardware_watchpoint
1350 && b->type != bp_read_watchpoint
1351 && b->type != bp_access_watchpoint
1352 && b->type != bp_catch_fork
1353 && b->type != bp_catch_vfork
1354 && b->type != bp_catch_exec
1355 && b->type != bp_catch_catch
1356 && b->type != bp_catch_throw)
1358 /* "Normal" instruction breakpoint: either the standard
1359 trap-instruction bp (bp_breakpoint), or a
1360 bp_hardware_breakpoint. */
1362 /* First check to see if we have to handle an overlay. */
1363 if (overlay_debugging == ovly_off
1364 || b->section == NULL
1365 || !(section_is_overlay (b->section)))
1367 /* No overlay handling: just remove the breakpoint. */
1369 if (b->type == bp_hardware_breakpoint)
1370 val = target_remove_hw_breakpoint (b->address,
1371 b->shadow_contents);
1373 val = target_remove_breakpoint (b->address, b->shadow_contents);
1377 /* This breakpoint is in an overlay section.
1378 Did we set a breakpoint at the LMA? */
1379 if (!overlay_events_enabled)
1381 /* Yes -- overlay event support is not active, so we
1382 should have set a breakpoint at the LMA. Remove it.
1384 CORE_ADDR addr = overlay_unmapped_address (b->address,
1386 /* Ignore any failures: if the LMA is in ROM, we will
1387 have already warned when we failed to insert it. */
1388 if (b->type != bp_hardware_breakpoint)
1389 target_remove_hw_breakpoint (addr, b->shadow_contents);
1391 target_remove_breakpoint (addr, b->shadow_contents);
1393 /* Did we set a breakpoint at the VMA?
1394 If so, we will have marked the breakpoint 'inserted'. */
1397 /* Yes -- remove it. Previously we did not bother to
1398 remove the breakpoint if the section had been
1399 unmapped, but let's not rely on that being safe. We
1400 don't know what the overlay manager might do. */
1401 if (b->type == bp_hardware_breakpoint)
1402 val = target_remove_hw_breakpoint (b->address,
1403 b->shadow_contents);
1405 val = target_remove_breakpoint (b->address,
1406 b->shadow_contents);
1410 /* No -- not inserted, so no need to remove. No error. */
1416 b->inserted = (is == mark_inserted);
1418 else if ((b->type == bp_hardware_watchpoint ||
1419 b->type == bp_read_watchpoint ||
1420 b->type == bp_access_watchpoint)
1421 && b->enable_state == bp_enabled
1427 b->inserted = (is == mark_inserted);
1428 /* Walk down the saved value chain. */
1429 for (v = b->val_chain; v; v = v->next)
1431 /* For each memory reference remove the watchpoint
1433 if (VALUE_LVAL (v) == lval_memory
1434 && ! VALUE_LAZY (v))
1436 struct type *vtype = check_typedef (VALUE_TYPE (v));
1438 if (v == b->val_chain
1439 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1440 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1445 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1446 len = TYPE_LENGTH (VALUE_TYPE (v));
1448 if (b->type == bp_read_watchpoint)
1450 else if (b->type == bp_access_watchpoint)
1453 val = target_remove_watchpoint (addr, len, type);
1460 /* Failure to remove any of the hardware watchpoints comes here. */
1461 if ((is == mark_uninserted) && (b->inserted))
1462 warning ("Could not remove hardware watchpoint %d.",
1465 /* Free the saved value chain. We will construct a new one
1466 the next time the watchpoint is inserted. */
1467 for (v = b->val_chain; v; v = n)
1472 b->val_chain = NULL;
1474 else if ((b->type == bp_catch_fork ||
1475 b->type == bp_catch_vfork ||
1476 b->type == bp_catch_exec)
1477 && b->enable_state == bp_enabled
1484 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1486 case bp_catch_vfork:
1487 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1490 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1493 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1498 b->inserted = (is == mark_inserted);
1500 else if ((b->type == bp_catch_catch ||
1501 b->type == bp_catch_throw)
1502 && b->enable_state == bp_enabled
1506 val = target_remove_breakpoint (b->address, b->shadow_contents);
1509 b->inserted = (is == mark_inserted);
1511 else if (ep_is_exception_catchpoint (b)
1512 && b->inserted /* sometimes previous insert doesn't happen */
1513 && b->enable_state == bp_enabled
1517 val = target_remove_breakpoint (b->address, b->shadow_contents);
1521 b->inserted = (is == mark_inserted);
1527 /* Clear the "inserted" flag in all breakpoints. */
1530 mark_breakpoints_out (void)
1532 register struct breakpoint *b;
1538 /* Clear the "inserted" flag in all breakpoints and delete any
1539 breakpoints which should go away between runs of the program.
1541 Plus other such housekeeping that has to be done for breakpoints
1544 Note: this function gets called at the end of a run (by
1545 generic_mourn_inferior) and when a run begins (by
1546 init_wait_for_inferior). */
1551 breakpoint_init_inferior (enum inf_context context)
1553 register struct breakpoint *b, *temp;
1554 static int warning_needed = 0;
1556 ALL_BREAKPOINTS_SAFE (b, temp)
1563 case bp_watchpoint_scope:
1565 /* If the call dummy breakpoint is at the entry point it will
1566 cause problems when the inferior is rerun, so we better
1569 Also get rid of scope breakpoints. */
1570 delete_breakpoint (b);
1574 case bp_hardware_watchpoint:
1575 case bp_read_watchpoint:
1576 case bp_access_watchpoint:
1578 /* Likewise for watchpoints on local expressions. */
1579 if (b->exp_valid_block != NULL)
1580 delete_breakpoint (b);
1581 if (context == inf_starting)
1583 /* Reset val field to force reread of starting value
1584 in insert_breakpoints. */
1586 value_free (b->val);
1591 /* Likewise for exception catchpoints in dynamic-linked
1592 executables where required */
1593 if (ep_is_exception_catchpoint (b) &&
1594 exception_catchpoints_are_fragile)
1597 delete_breakpoint (b);
1603 if (exception_catchpoints_are_fragile)
1604 exception_support_initialized = 0;
1606 /* Don't issue the warning unless it's really needed... */
1607 if (warning_needed && (context != inf_exited))
1609 warning ("Exception catchpoints from last run were deleted.");
1610 warning ("You must reinsert them explicitly.");
1615 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1616 exists at PC. It returns ordinary_breakpoint_here if it's an
1617 ordinary breakpoint, or permanent_breakpoint_here if it's a
1618 permanent breakpoint.
1619 - When continuing from a location with an ordinary breakpoint, we
1620 actually single step once before calling insert_breakpoints.
1621 - When continuing from a localion with a permanent breakpoint, we
1622 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1623 the target, to advance the PC past the breakpoint. */
1625 enum breakpoint_here
1626 breakpoint_here_p (CORE_ADDR pc)
1628 register struct breakpoint *b;
1629 int any_breakpoint_here = 0;
1632 if ((b->enable_state == bp_enabled
1633 || b->enable_state == bp_permanent)
1634 && b->address == pc) /* bp is enabled and matches pc */
1636 if (overlay_debugging
1637 && section_is_overlay (b->section)
1638 && !section_is_mapped (b->section))
1639 continue; /* unmapped overlay -- can't be a match */
1640 else if (b->enable_state == bp_permanent)
1641 return permanent_breakpoint_here;
1643 any_breakpoint_here = 1;
1646 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1650 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1651 but it only returns true if there is actually a breakpoint inserted
1655 breakpoint_inserted_here_p (CORE_ADDR pc)
1657 register struct breakpoint *b;
1661 && b->address == pc) /* bp is inserted and matches pc */
1663 if (overlay_debugging
1664 && section_is_overlay (b->section)
1665 && !section_is_mapped (b->section))
1666 continue; /* unmapped overlay -- can't be a match */
1674 /* Return nonzero if FRAME is a dummy frame. We can't use
1675 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1676 much time, at least using get_saved_register on the 68k. This
1677 means that for this function to work right a port must use the
1678 bp_call_dummy breakpoint. */
1681 frame_in_dummy (struct frame_info *frame)
1683 struct breakpoint *b;
1688 if (USE_GENERIC_DUMMY_FRAMES)
1689 return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame);
1693 if (b->type == bp_call_dummy
1694 && b->frame == frame->frame
1695 /* We need to check the PC as well as the frame on the sparc,
1696 for signals.exp in the testsuite. */
1699 - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE))
1700 && frame->pc <= b->address)
1706 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1707 PC is valid for process/thread PID. */
1710 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1712 struct breakpoint *b;
1715 thread = pid_to_thread_id (ptid);
1718 if (b->enable_state != bp_disabled
1719 && b->enable_state != bp_shlib_disabled
1720 && b->enable_state != bp_call_disabled
1722 && (b->thread == -1 || b->thread == thread))
1724 if (overlay_debugging
1725 && section_is_overlay (b->section)
1726 && !section_is_mapped (b->section))
1727 continue; /* unmapped overlay -- can't be a match */
1736 /* bpstat stuff. External routines' interfaces are documented
1740 ep_is_catchpoint (struct breakpoint *ep)
1743 (ep->type == bp_catch_load)
1744 || (ep->type == bp_catch_unload)
1745 || (ep->type == bp_catch_fork)
1746 || (ep->type == bp_catch_vfork)
1747 || (ep->type == bp_catch_exec)
1748 || (ep->type == bp_catch_catch)
1749 || (ep->type == bp_catch_throw);
1751 /* ??rehrauer: Add more kinds here, as are implemented... */
1755 ep_is_shlib_catchpoint (struct breakpoint *ep)
1758 (ep->type == bp_catch_load)
1759 || (ep->type == bp_catch_unload);
1763 ep_is_exception_catchpoint (struct breakpoint *ep)
1766 (ep->type == bp_catch_catch)
1767 || (ep->type == bp_catch_throw);
1770 /* Clear a bpstat so that it says we are not at any breakpoint.
1771 Also free any storage that is part of a bpstat. */
1774 bpstat_clear (bpstat *bsp)
1785 if (p->old_val != NULL)
1786 value_free (p->old_val);
1787 free_command_lines (&p->commands);
1794 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1795 is part of the bpstat is copied as well. */
1798 bpstat_copy (bpstat bs)
1802 bpstat retval = NULL;
1807 for (; bs != NULL; bs = bs->next)
1809 tmp = (bpstat) xmalloc (sizeof (*tmp));
1810 memcpy (tmp, bs, sizeof (*tmp));
1812 /* This is the first thing in the chain. */
1822 /* Find the bpstat associated with this breakpoint */
1825 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1830 for (; bsp != NULL; bsp = bsp->next)
1832 if (bsp->breakpoint_at == breakpoint)
1838 /* Find a step_resume breakpoint associated with this bpstat.
1839 (If there are multiple step_resume bp's on the list, this function
1840 will arbitrarily pick one.)
1842 It is an error to use this function if BPSTAT doesn't contain a
1843 step_resume breakpoint.
1845 See wait_for_inferior's use of this function. */
1847 bpstat_find_step_resume_breakpoint (bpstat bsp)
1852 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1854 current_thread = pid_to_thread_id (inferior_ptid);
1856 for (; bsp != NULL; bsp = bsp->next)
1858 if ((bsp->breakpoint_at != NULL) &&
1859 (bsp->breakpoint_at->type == bp_step_resume) &&
1860 (bsp->breakpoint_at->thread == current_thread ||
1861 bsp->breakpoint_at->thread == -1))
1862 return bsp->breakpoint_at;
1865 error ("Internal error (no step_resume breakpoint found)");
1869 /* Return the breakpoint number of the first breakpoint we are stopped
1870 at. *BSP upon return is a bpstat which points to the remaining
1871 breakpoints stopped at (but which is not guaranteed to be good for
1872 anything but further calls to bpstat_num).
1873 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1876 bpstat_num (bpstat *bsp)
1878 struct breakpoint *b;
1881 return 0; /* No more breakpoint values */
1884 b = (*bsp)->breakpoint_at;
1885 *bsp = (*bsp)->next;
1887 return -1; /* breakpoint that's been deleted since */
1889 return b->number; /* We have its number */
1893 /* Modify BS so that the actions will not be performed. */
1896 bpstat_clear_actions (bpstat bs)
1898 for (; bs != NULL; bs = bs->next)
1900 free_command_lines (&bs->commands);
1901 if (bs->old_val != NULL)
1903 value_free (bs->old_val);
1909 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1912 cleanup_executing_breakpoints (PTR ignore)
1914 executing_breakpoint_commands = 0;
1917 /* Execute all the commands associated with all the breakpoints at this
1918 location. Any of these commands could cause the process to proceed
1919 beyond this point, etc. We look out for such changes by checking
1920 the global "breakpoint_proceeded" after each command. */
1923 bpstat_do_actions (bpstat *bsp)
1926 struct cleanup *old_chain;
1927 struct command_line *cmd;
1929 /* Avoid endless recursion if a `source' command is contained
1931 if (executing_breakpoint_commands)
1934 executing_breakpoint_commands = 1;
1935 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1938 /* Note that (as of this writing), our callers all appear to
1939 be passing us the address of global stop_bpstat. And, if
1940 our calls to execute_control_command cause the inferior to
1941 proceed, that global (and hence, *bsp) will change.
1943 We must be careful to not touch *bsp unless the inferior
1944 has not proceeded. */
1946 /* This pointer will iterate over the list of bpstat's. */
1949 breakpoint_proceeded = 0;
1950 for (; bs != NULL; bs = bs->next)
1955 execute_control_command (cmd);
1957 if (breakpoint_proceeded)
1962 if (breakpoint_proceeded)
1963 /* The inferior is proceeded by the command; bomb out now.
1964 The bpstat chain has been blown away by wait_for_inferior.
1965 But since execution has stopped again, there is a new bpstat
1966 to look at, so start over. */
1969 free_command_lines (&bs->commands);
1971 do_cleanups (old_chain);
1974 /* This is the normal print function for a bpstat. In the future,
1975 much of this logic could (should?) be moved to bpstat_stop_status,
1976 by having it set different print_it values.
1978 Current scheme: When we stop, bpstat_print() is called. It loops
1979 through the bpstat list of things causing this stop, calling the
1980 print_bp_stop_message function on each one. The behavior of the
1981 print_bp_stop_message function depends on the print_it field of
1982 bpstat. If such field so indicates, call this function here.
1984 Return values from this routine (ultimately used by bpstat_print()
1985 and normal_stop() to decide what to do):
1986 PRINT_NOTHING: Means we already printed all we needed to print,
1987 don't print anything else.
1988 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1989 that something to be followed by a location.
1990 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1991 that something to be followed by a location.
1992 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
1995 static enum print_stop_action
1996 print_it_typical (bpstat bs)
1998 struct cleanup *old_chain;
1999 struct ui_stream *stb;
2000 stb = ui_out_stream_new (uiout);
2001 old_chain = make_cleanup_ui_out_stream_delete (stb);
2002 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2003 which has since been deleted. */
2004 if (bs->breakpoint_at == NULL)
2005 return PRINT_UNKNOWN;
2007 switch (bs->breakpoint_at->type)
2010 case bp_hardware_breakpoint:
2011 annotate_breakpoint (bs->breakpoint_at->number);
2012 ui_out_text (uiout, "\nBreakpoint ");
2013 if (ui_out_is_mi_like_p (uiout))
2014 ui_out_field_string (uiout, "reason", "breakpoint-hit");
2015 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
2016 ui_out_text (uiout, ", ");
2017 return PRINT_SRC_AND_LOC;
2020 case bp_shlib_event:
2021 /* Did we stop because the user set the stop_on_solib_events
2022 variable? (If so, we report this as a generic, "Stopped due
2023 to shlib event" message.) */
2024 printf_filtered ("Stopped due to shared library event\n");
2025 return PRINT_NOTHING;
2028 case bp_thread_event:
2029 /* Not sure how we will get here.
2030 GDB should not stop for these breakpoints. */
2031 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
2032 return PRINT_NOTHING;
2035 case bp_overlay_event:
2036 /* By analogy with the thread event, GDB should not stop for these. */
2037 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
2038 return PRINT_NOTHING;
2042 annotate_catchpoint (bs->breakpoint_at->number);
2043 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2044 printf_filtered ("loaded");
2045 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2046 return PRINT_SRC_AND_LOC;
2049 case bp_catch_unload:
2050 annotate_catchpoint (bs->breakpoint_at->number);
2051 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2052 printf_filtered ("unloaded");
2053 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2054 return PRINT_SRC_AND_LOC;
2058 annotate_catchpoint (bs->breakpoint_at->number);
2059 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2060 printf_filtered ("forked");
2061 printf_filtered (" process %d), ",
2062 bs->breakpoint_at->forked_inferior_pid);
2063 return PRINT_SRC_AND_LOC;
2066 case bp_catch_vfork:
2067 annotate_catchpoint (bs->breakpoint_at->number);
2068 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2069 printf_filtered ("vforked");
2070 printf_filtered (" process %d), ",
2071 bs->breakpoint_at->forked_inferior_pid);
2072 return PRINT_SRC_AND_LOC;
2076 annotate_catchpoint (bs->breakpoint_at->number);
2077 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2078 bs->breakpoint_at->number,
2079 bs->breakpoint_at->exec_pathname);
2080 return PRINT_SRC_AND_LOC;
2083 case bp_catch_catch:
2084 if (current_exception_event &&
2085 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
2087 annotate_catchpoint (bs->breakpoint_at->number);
2088 printf_filtered ("\nCatchpoint %d (exception caught), ",
2089 bs->breakpoint_at->number);
2090 printf_filtered ("throw location ");
2091 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2092 printf_filtered ("%s:%d",
2093 CURRENT_EXCEPTION_THROW_FILE,
2094 CURRENT_EXCEPTION_THROW_LINE);
2096 printf_filtered ("unknown");
2098 printf_filtered (", catch location ");
2099 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2100 printf_filtered ("%s:%d",
2101 CURRENT_EXCEPTION_CATCH_FILE,
2102 CURRENT_EXCEPTION_CATCH_LINE);
2104 printf_filtered ("unknown");
2106 printf_filtered ("\n");
2107 /* don't bother to print location frame info */
2108 return PRINT_SRC_ONLY;
2112 /* really throw, some other bpstat will handle it */
2113 return PRINT_UNKNOWN;
2117 case bp_catch_throw:
2118 if (current_exception_event &&
2119 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2121 annotate_catchpoint (bs->breakpoint_at->number);
2122 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2123 bs->breakpoint_at->number);
2124 printf_filtered ("throw location ");
2125 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2126 printf_filtered ("%s:%d",
2127 CURRENT_EXCEPTION_THROW_FILE,
2128 CURRENT_EXCEPTION_THROW_LINE);
2130 printf_filtered ("unknown");
2132 printf_filtered (", catch location ");
2133 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2134 printf_filtered ("%s:%d",
2135 CURRENT_EXCEPTION_CATCH_FILE,
2136 CURRENT_EXCEPTION_CATCH_LINE);
2138 printf_filtered ("unknown");
2140 printf_filtered ("\n");
2141 /* don't bother to print location frame info */
2142 return PRINT_SRC_ONLY;
2146 /* really catch, some other bpstat will handle it */
2147 return PRINT_UNKNOWN;
2152 case bp_hardware_watchpoint:
2153 if (bs->old_val != NULL)
2155 annotate_watchpoint (bs->breakpoint_at->number);
2156 if (ui_out_is_mi_like_p (uiout))
2157 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2158 mention (bs->breakpoint_at);
2159 ui_out_tuple_begin (uiout, "value");
2160 ui_out_text (uiout, "\nOld value = ");
2161 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2162 ui_out_field_stream (uiout, "old", stb);
2163 ui_out_text (uiout, "\nNew value = ");
2164 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2165 ui_out_field_stream (uiout, "new", stb);
2166 ui_out_tuple_end (uiout);
2167 ui_out_text (uiout, "\n");
2168 value_free (bs->old_val);
2171 /* More than one watchpoint may have been triggered. */
2172 return PRINT_UNKNOWN;
2175 case bp_read_watchpoint:
2176 if (ui_out_is_mi_like_p (uiout))
2177 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2178 mention (bs->breakpoint_at);
2179 ui_out_tuple_begin (uiout, "value");
2180 ui_out_text (uiout, "\nValue = ");
2181 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2182 ui_out_field_stream (uiout, "value", stb);
2183 ui_out_tuple_end (uiout);
2184 ui_out_text (uiout, "\n");
2185 return PRINT_UNKNOWN;
2188 case bp_access_watchpoint:
2189 if (bs->old_val != NULL)
2191 annotate_watchpoint (bs->breakpoint_at->number);
2192 if (ui_out_is_mi_like_p (uiout))
2193 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2194 mention (bs->breakpoint_at);
2195 ui_out_tuple_begin (uiout, "value");
2196 ui_out_text (uiout, "\nOld value = ");
2197 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2198 ui_out_field_stream (uiout, "old", stb);
2199 value_free (bs->old_val);
2201 ui_out_text (uiout, "\nNew value = ");
2205 mention (bs->breakpoint_at);
2206 if (ui_out_is_mi_like_p (uiout))
2207 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2208 ui_out_tuple_begin (uiout, "value");
2209 ui_out_text (uiout, "\nValue = ");
2211 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2212 ui_out_field_stream (uiout, "new", stb);
2213 ui_out_tuple_end (uiout);
2214 ui_out_text (uiout, "\n");
2215 return PRINT_UNKNOWN;
2218 /* Fall through, we don't deal with these types of breakpoints
2222 if (ui_out_is_mi_like_p (uiout))
2223 ui_out_field_string (uiout, "reason", "function-finished");
2224 return PRINT_UNKNOWN;
2228 if (ui_out_is_mi_like_p (uiout))
2229 ui_out_field_string (uiout, "reason", "location-reached");
2230 return PRINT_UNKNOWN;
2235 case bp_longjmp_resume:
2236 case bp_step_resume:
2237 case bp_through_sigtramp:
2238 case bp_watchpoint_scope:
2241 return PRINT_UNKNOWN;
2245 /* Generic routine for printing messages indicating why we
2246 stopped. The behavior of this function depends on the value
2247 'print_it' in the bpstat structure. Under some circumstances we
2248 may decide not to print anything here and delegate the task to
2251 static enum print_stop_action
2252 print_bp_stop_message (bpstat bs)
2254 switch (bs->print_it)
2257 /* Nothing should be printed for this bpstat entry. */
2258 return PRINT_UNKNOWN;
2262 /* We still want to print the frame, but we already printed the
2263 relevant messages. */
2264 return PRINT_SRC_AND_LOC;
2267 case print_it_normal:
2268 /* Normal case, we handle everything in print_it_typical. */
2269 return print_it_typical (bs);
2272 internal_error (__FILE__, __LINE__,
2273 "print_bp_stop_message: unrecognized enum value");
2278 /* Print a message indicating what happened. This is called from
2279 normal_stop(). The input to this routine is the head of the bpstat
2280 list - a list of the eventpoints that caused this stop. This
2281 routine calls the generic print routine for printing a message
2282 about reasons for stopping. This will print (for example) the
2283 "Breakpoint n," part of the output. The return value of this
2286 PRINT_UNKNOWN: Means we printed nothing
2287 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2288 code to print the location. An example is
2289 "Breakpoint 1, " which should be followed by
2291 PRINT_SRC_ONLY: Means we printed something, but there is no need
2292 to also print the location part of the message.
2293 An example is the catch/throw messages, which
2294 don't require a location appended to the end.
2295 PRINT_NOTHING: We have done some printing and we don't need any
2296 further info to be printed.*/
2298 enum print_stop_action
2299 bpstat_print (bpstat bs)
2303 /* Maybe another breakpoint in the chain caused us to stop.
2304 (Currently all watchpoints go on the bpstat whether hit or not.
2305 That probably could (should) be changed, provided care is taken
2306 with respect to bpstat_explains_signal). */
2307 for (; bs; bs = bs->next)
2309 val = print_bp_stop_message (bs);
2310 if (val == PRINT_SRC_ONLY
2311 || val == PRINT_SRC_AND_LOC
2312 || val == PRINT_NOTHING)
2316 /* We reached the end of the chain, or we got a null BS to start
2317 with and nothing was printed. */
2318 return PRINT_UNKNOWN;
2321 /* Evaluate the expression EXP and return 1 if value is zero.
2322 This is used inside a catch_errors to evaluate the breakpoint condition.
2323 The argument is a "struct expression *" that has been cast to char * to
2324 make it pass through catch_errors. */
2327 breakpoint_cond_eval (PTR exp)
2329 struct value *mark = value_mark ();
2330 int i = !value_true (evaluate_expression ((struct expression *) exp));
2331 value_free_to_mark (mark);
2335 /* Allocate a new bpstat and chain it to the current one. */
2338 bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
2342 bs = (bpstat) xmalloc (sizeof (*bs));
2344 bs->breakpoint_at = b;
2345 /* If the condition is false, etc., don't do the commands. */
2346 bs->commands = NULL;
2348 bs->print_it = print_it_normal;
2352 /* Possible return values for watchpoint_check (this can't be an enum
2353 because of check_errors). */
2354 /* The watchpoint has been deleted. */
2355 #define WP_DELETED 1
2356 /* The value has changed. */
2357 #define WP_VALUE_CHANGED 2
2358 /* The value has not changed. */
2359 #define WP_VALUE_NOT_CHANGED 3
2361 #define BP_TEMPFLAG 1
2362 #define BP_HARDWAREFLAG 2
2364 /* Check watchpoint condition. */
2367 watchpoint_check (PTR p)
2369 bpstat bs = (bpstat) p;
2370 struct breakpoint *b;
2371 struct frame_info *fr;
2372 int within_current_scope;
2374 b = bs->breakpoint_at;
2376 if (b->exp_valid_block == NULL)
2377 within_current_scope = 1;
2380 /* There is no current frame at this moment. If we're going to have
2381 any chance of handling watchpoints on local variables, we'll need
2382 the frame chain (so we can determine if we're in scope). */
2383 reinit_frame_cache ();
2384 fr = frame_find_by_id (b->watchpoint_frame);
2385 within_current_scope = (fr != NULL);
2386 /* in_function_epilogue_p() returns a non-zero value if we're still
2387 in the function but the stack frame has already been invalidated.
2388 Since we can't rely on the values of local variables after the
2389 stack has been destroyed, we are treating the watchpoint in that
2390 state as `not changed' without further checking. */
2391 if (within_current_scope && fr == get_current_frame ()
2392 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2393 return WP_VALUE_NOT_CHANGED;
2394 if (within_current_scope)
2395 /* If we end up stopping, the current frame will get selected
2396 in normal_stop. So this call to select_frame won't affect
2401 if (within_current_scope)
2403 /* We use value_{,free_to_}mark because it could be a
2404 *long* time before we return to the command level and
2405 call free_all_values. We can't call free_all_values because
2406 we might be in the middle of evaluating a function call. */
2408 struct value *mark = value_mark ();
2409 struct value *new_val = evaluate_expression (bs->breakpoint_at->exp);
2410 if (!value_equal (b->val, new_val))
2412 release_value (new_val);
2413 value_free_to_mark (mark);
2414 bs->old_val = b->val;
2416 /* We will stop here */
2417 return WP_VALUE_CHANGED;
2421 /* Nothing changed, don't do anything. */
2422 value_free_to_mark (mark);
2423 /* We won't stop here */
2424 return WP_VALUE_NOT_CHANGED;
2429 /* This seems like the only logical thing to do because
2430 if we temporarily ignored the watchpoint, then when
2431 we reenter the block in which it is valid it contains
2432 garbage (in the case of a function, it may have two
2433 garbage values, one before and one after the prologue).
2434 So we can't even detect the first assignment to it and
2435 watch after that (since the garbage may or may not equal
2436 the first value assigned). */
2437 /* We print all the stop information in print_it_typical(), but
2438 in this case, by the time we call print_it_typical() this bp
2439 will be deleted already. So we have no choice but print the
2440 information here. */
2441 if (ui_out_is_mi_like_p (uiout))
2442 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2443 ui_out_text (uiout, "\nWatchpoint ");
2444 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2445 ui_out_text (uiout, " deleted because the program has left the block in\n\
2446 which its expression is valid.\n");
2448 if (b->related_breakpoint)
2449 b->related_breakpoint->disposition = disp_del_at_next_stop;
2450 b->disposition = disp_del_at_next_stop;
2456 /* Get a bpstat associated with having just stopped at address *PC
2457 and frame address CORE_ADDRESS. Update *PC to point at the
2458 breakpoint (if we hit a breakpoint). NOT_A_SW_BREAKPOINT is nonzero
2459 if this is known to not be a real breakpoint (it could still be a
2460 watchpoint, though). */
2462 /* Determine whether we stopped at a breakpoint, etc, or whether we
2463 don't understand this stop. Result is a chain of bpstat's such that:
2465 if we don't understand the stop, the result is a null pointer.
2467 if we understand why we stopped, the result is not null.
2469 Each element of the chain refers to a particular breakpoint or
2470 watchpoint at which we have stopped. (We may have stopped for
2471 several reasons concurrently.)
2473 Each element of the chain has valid next, breakpoint_at,
2474 commands, FIXME??? fields. */
2477 bpstat_stop_status (CORE_ADDR *pc, int not_a_sw_breakpoint)
2479 register struct breakpoint *b, *temp;
2481 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2482 int real_breakpoint = 0;
2483 /* Root of the chain of bpstat's */
2484 struct bpstats root_bs[1];
2485 /* Pointer to the last thing in the chain currently. */
2486 bpstat bs = root_bs;
2487 static char message1[] =
2488 "Error evaluating expression for watchpoint %d\n";
2489 char message[sizeof (message1) + 30 /* slop */ ];
2491 /* Get the address where the breakpoint would have been. The
2492 "not_a_sw_breakpoint" argument is meant to distinguish between a
2493 breakpoint trap event and a trace/singlestep trap event. For a
2494 trace/singlestep trap event, we would not want to subtract
2495 DECR_PC_AFTER_BREAK from the PC. */
2497 bp_addr = *pc - (not_a_sw_breakpoint ? 0 : DECR_PC_AFTER_BREAK);
2499 ALL_BREAKPOINTS_SAFE (b, temp)
2501 if (b->enable_state == bp_disabled
2502 || b->enable_state == bp_shlib_disabled
2503 || b->enable_state == bp_call_disabled)
2506 if (b->type != bp_watchpoint
2507 && b->type != bp_hardware_watchpoint
2508 && b->type != bp_read_watchpoint
2509 && b->type != bp_access_watchpoint
2510 && b->type != bp_hardware_breakpoint
2511 && b->type != bp_catch_fork
2512 && b->type != bp_catch_vfork
2513 && b->type != bp_catch_exec
2514 && b->type != bp_catch_catch
2515 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2517 if (b->address != bp_addr) /* address doesn't match */
2519 if (overlay_debugging /* unmapped overlay section */
2520 && section_is_overlay (b->section)
2521 && !section_is_mapped (b->section))
2525 if (b->type == bp_hardware_breakpoint)
2527 if (b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2529 if (overlay_debugging /* unmapped overlay section */
2530 && section_is_overlay (b->section)
2531 && !section_is_mapped (b->section))
2535 /* Is this a catchpoint of a load or unload? If so, did we
2536 get a load or unload of the specified library? If not,
2538 if ((b->type == bp_catch_load)
2539 #if defined(SOLIB_HAVE_LOAD_EVENT)
2540 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2541 || ((b->dll_pathname != NULL)
2542 && (strcmp (b->dll_pathname,
2543 SOLIB_LOADED_LIBRARY_PATHNAME (
2544 PIDGET (inferior_ptid)))
2550 if ((b->type == bp_catch_unload)
2551 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2552 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2553 || ((b->dll_pathname != NULL)
2554 && (strcmp (b->dll_pathname,
2555 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2556 PIDGET (inferior_ptid)))
2562 if ((b->type == bp_catch_fork)
2563 && !target_has_forked (PIDGET (inferior_ptid),
2564 &b->forked_inferior_pid))
2567 if ((b->type == bp_catch_vfork)
2568 && !target_has_vforked (PIDGET (inferior_ptid),
2569 &b->forked_inferior_pid))
2572 if ((b->type == bp_catch_exec)
2573 && !target_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2576 if (ep_is_exception_catchpoint (b) &&
2577 !(current_exception_event = target_get_current_exception_event ()))
2580 /* Come here if it's a watchpoint, or if the break address matches */
2582 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2584 /* Watchpoints may change this, if not found to have triggered. */
2588 sprintf (message, message1, b->number);
2589 if (b->type == bp_watchpoint ||
2590 b->type == bp_hardware_watchpoint)
2592 switch (catch_errors (watchpoint_check, bs, message,
2596 /* We've already printed what needs to be printed. */
2597 /* Actually this is superfluous, because by the time we
2598 call print_it_typical() the wp will be already deleted,
2599 and the function will return immediately. */
2600 bs->print_it = print_it_done;
2603 case WP_VALUE_CHANGED:
2607 case WP_VALUE_NOT_CHANGED:
2609 bs->print_it = print_it_noop;
2616 /* Error from catch_errors. */
2617 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2618 if (b->related_breakpoint)
2619 b->related_breakpoint->disposition = disp_del_at_next_stop;
2620 b->disposition = disp_del_at_next_stop;
2621 /* We've already printed what needs to be printed. */
2622 bs->print_it = print_it_done;
2628 else if (b->type == bp_read_watchpoint ||
2629 b->type == bp_access_watchpoint)
2635 addr = target_stopped_data_address ();
2638 for (v = b->val_chain; v; v = v->next)
2640 if (VALUE_LVAL (v) == lval_memory
2641 && ! VALUE_LAZY (v))
2643 struct type *vtype = check_typedef (VALUE_TYPE (v));
2645 if (v == b->val_chain
2646 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2647 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2651 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2652 /* Exact match not required. Within range is
2654 if (addr >= vaddr &&
2655 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2661 switch (catch_errors (watchpoint_check, bs, message,
2665 /* We've already printed what needs to be printed. */
2666 bs->print_it = print_it_done;
2669 case WP_VALUE_CHANGED:
2670 if (b->type == bp_read_watchpoint)
2672 /* Don't stop: read watchpoints shouldn't fire if
2673 the value has changed. This is for targets which
2674 cannot set read-only watchpoints. */
2675 bs->print_it = print_it_noop;
2681 case WP_VALUE_NOT_CHANGED:
2688 /* Error from catch_errors. */
2689 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2690 if (b->related_breakpoint)
2691 b->related_breakpoint->disposition = disp_del_at_next_stop;
2692 b->disposition = disp_del_at_next_stop;
2693 /* We've already printed what needs to be printed. */
2694 bs->print_it = print_it_done;
2697 else /* found == 0 */
2699 /* This is a case where some watchpoint(s) triggered,
2700 but not at the address of this watchpoint (FOUND
2701 was left zero). So don't print anything for this
2703 bs->print_it = print_it_noop;
2710 /* By definition, an encountered breakpoint is a triggered
2714 real_breakpoint = 1;
2718 b->frame != (get_current_frame ())->frame)
2722 int value_is_zero = 0;
2726 /* Need to select the frame, with all that implies
2727 so that the conditions will have the right context. */
2728 select_frame (get_current_frame ());
2730 = catch_errors (breakpoint_cond_eval, (b->cond),
2731 "Error in testing breakpoint condition:\n",
2733 /* FIXME-someday, should give breakpoint # */
2736 if (b->cond && value_is_zero)
2739 /* Don't consider this a hit. */
2742 else if (b->ignore_count > 0)
2745 annotate_ignore_count_change ();
2750 /* We will stop here */
2751 if (b->disposition == disp_disable)
2752 b->enable_state = bp_disabled;
2753 bs->commands = copy_command_lines (b->commands);
2757 (STREQ ("silent", bs->commands->line) ||
2758 (xdb_commands && STREQ ("Q", bs->commands->line))))
2760 bs->commands = bs->commands->next;
2765 /* Print nothing for this entry if we dont stop or if we dont print. */
2766 if (bs->stop == 0 || bs->print == 0)
2767 bs->print_it = print_it_noop;
2770 bs->next = NULL; /* Terminate the chain */
2771 bs = root_bs->next; /* Re-grab the head of the chain */
2773 if (real_breakpoint && bs)
2775 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2777 if (DECR_PC_AFTER_HW_BREAK != 0)
2779 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2785 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2788 #if defined (SHIFT_INST_REGS)
2790 #else /* No SHIFT_INST_REGS. */
2792 #endif /* No SHIFT_INST_REGS. */
2797 /* The value of a hardware watchpoint hasn't changed, but the
2798 intermediate memory locations we are watching may have. */
2799 if (bs && !bs->stop &&
2800 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2801 bs->breakpoint_at->type == bp_read_watchpoint ||
2802 bs->breakpoint_at->type == bp_access_watchpoint))
2804 remove_breakpoints ();
2805 insert_breakpoints ();
2810 /* Tell what to do about this bpstat. */
2812 bpstat_what (bpstat bs)
2814 /* Classify each bpstat as one of the following. */
2817 /* This bpstat element has no effect on the main_action. */
2820 /* There was a watchpoint, stop but don't print. */
2823 /* There was a watchpoint, stop and print. */
2826 /* There was a breakpoint but we're not stopping. */
2829 /* There was a breakpoint, stop but don't print. */
2832 /* There was a breakpoint, stop and print. */
2835 /* We hit the longjmp breakpoint. */
2838 /* We hit the longjmp_resume breakpoint. */
2841 /* We hit the step_resume breakpoint. */
2844 /* We hit the through_sigtramp breakpoint. */
2847 /* We hit the shared library event breakpoint. */
2850 /* We caught a shared library event. */
2853 /* This is just used to count how many enums there are. */
2857 /* Here is the table which drives this routine. So that we can
2858 format it pretty, we define some abbreviations for the
2859 enum bpstat_what codes. */
2860 #define kc BPSTAT_WHAT_KEEP_CHECKING
2861 #define ss BPSTAT_WHAT_STOP_SILENT
2862 #define sn BPSTAT_WHAT_STOP_NOISY
2863 #define sgl BPSTAT_WHAT_SINGLE
2864 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2865 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2866 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2867 #define sr BPSTAT_WHAT_STEP_RESUME
2868 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2869 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2870 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2872 /* "Can't happen." Might want to print an error message.
2873 abort() is not out of the question, but chances are GDB is just
2874 a bit confused, not unusable. */
2875 #define err BPSTAT_WHAT_STOP_NOISY
2877 /* Given an old action and a class, come up with a new action. */
2878 /* One interesting property of this table is that wp_silent is the same
2879 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2880 after stopping, the check for whether to step over a breakpoint
2881 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2882 reference to how we stopped. We retain separate wp_silent and
2883 bp_silent codes in case we want to change that someday.
2885 Another possibly interesting property of this table is that
2886 there's a partial ordering, priority-like, of the actions. Once
2887 you've decided that some action is appropriate, you'll never go
2888 back and decide something of a lower priority is better. The
2891 kc < clr sgl shl shlr slr sn sr ss ts
2892 sgl < clrs shl shlr slr sn sr ss ts
2893 slr < err shl shlr sn sr ss ts
2894 clr < clrs err shl shlr sn sr ss ts
2895 clrs < err shl shlr sn sr ss ts
2896 ss < shl shlr sn sr ts
2903 What I think this means is that we don't need a damned table
2904 here. If you just put the rows and columns in the right order,
2905 it'd look awfully regular. We could simply walk the bpstat list
2906 and choose the highest priority action we find, with a little
2907 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2908 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2909 is messy anyway). */
2911 /* step_resume entries: a step resume breakpoint overrides another
2912 breakpoint of signal handling (see comment in wait_for_inferior
2913 at first PC_IN_SIGTRAMP where we set the step_resume breakpoint). */
2914 /* We handle the through_sigtramp_breakpoint the same way; having both
2915 one of those and a step_resume_breakpoint is probably very rare (?). */
2917 static const enum bpstat_what_main_action
2918 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2921 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2924 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2926 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2928 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2930 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2932 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2934 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2936 {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr},
2938 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2940 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2942 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2944 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2946 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2961 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2962 struct bpstat_what retval;
2964 retval.call_dummy = 0;
2965 for (; bs != NULL; bs = bs->next)
2967 enum class bs_class = no_effect;
2968 if (bs->breakpoint_at == NULL)
2969 /* I suspect this can happen if it was a momentary breakpoint
2970 which has since been deleted. */
2972 switch (bs->breakpoint_at->type)
2978 case bp_hardware_breakpoint:
2984 bs_class = bp_noisy;
2986 bs_class = bp_silent;
2989 bs_class = bp_nostop;
2992 case bp_hardware_watchpoint:
2993 case bp_read_watchpoint:
2994 case bp_access_watchpoint:
2998 bs_class = wp_noisy;
3000 bs_class = wp_silent;
3003 /* There was a watchpoint, but we're not stopping.
3004 This requires no further action. */
3005 bs_class = no_effect;
3008 bs_class = long_jump;
3010 case bp_longjmp_resume:
3011 bs_class = long_resume;
3013 case bp_step_resume:
3016 bs_class = step_resume;
3019 /* It is for the wrong frame. */
3020 bs_class = bp_nostop;
3022 case bp_through_sigtramp:
3023 bs_class = through_sig;
3025 case bp_watchpoint_scope:
3026 bs_class = bp_nostop;
3028 case bp_shlib_event:
3029 bs_class = shlib_event;
3031 case bp_thread_event:
3032 case bp_overlay_event:
3033 bs_class = bp_nostop;
3036 case bp_catch_unload:
3037 /* Only if this catchpoint triggered should we cause the
3038 step-out-of-dld behaviour. Otherwise, we ignore this
3041 bs_class = catch_shlib_event;
3043 bs_class = no_effect;
3046 case bp_catch_vfork:
3051 bs_class = bp_noisy;
3053 bs_class = bp_silent;
3056 /* There was a catchpoint, but we're not stopping.
3057 This requires no further action. */
3058 bs_class = no_effect;
3060 case bp_catch_catch:
3061 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
3062 bs_class = bp_nostop;
3064 bs_class = bs->print ? bp_noisy : bp_silent;
3066 case bp_catch_throw:
3067 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
3068 bs_class = bp_nostop;
3070 bs_class = bs->print ? bp_noisy : bp_silent;
3073 /* Make sure the action is stop (silent or noisy),
3074 so infrun.c pops the dummy frame. */
3075 bs_class = bp_silent;
3076 retval.call_dummy = 1;
3079 current_action = table[(int) bs_class][(int) current_action];
3081 retval.main_action = current_action;
3085 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3086 without hardware support). This isn't related to a specific bpstat,
3087 just to things like whether watchpoints are set. */
3090 bpstat_should_step (void)
3092 struct breakpoint *b;
3094 if (b->enable_state == bp_enabled && b->type == bp_watchpoint)
3099 /* Nonzero if there are enabled hardware watchpoints. */
3101 bpstat_have_active_hw_watchpoints (void)
3103 struct breakpoint *b;
3105 if ((b->enable_state == bp_enabled) &&
3107 ((b->type == bp_hardware_watchpoint) ||
3108 (b->type == bp_read_watchpoint) ||
3109 (b->type == bp_access_watchpoint)))
3115 /* Given a bpstat that records zero or more triggered eventpoints, this
3116 function returns another bpstat which contains only the catchpoints
3117 on that first list, if any. */
3119 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3121 struct bpstats root_bs[1];
3122 bpstat bs = root_bs;
3123 struct breakpoint *ep;
3126 bpstat_clear (cp_list);
3127 root_bs->next = NULL;
3129 for (; ep_list != NULL; ep_list = ep_list->next)
3131 /* Is this eventpoint a catchpoint? If not, ignore it. */
3132 ep = ep_list->breakpoint_at;
3135 if ((ep->type != bp_catch_load) &&
3136 (ep->type != bp_catch_unload) &&
3137 (ep->type != bp_catch_catch) &&
3138 (ep->type != bp_catch_throw))
3139 /* pai: (temp) ADD fork/vfork here!! */
3142 /* Yes; add it to the list. */
3143 bs = bpstat_alloc (ep, bs);
3148 #if defined(SOLIB_ADD)
3149 /* Also, for each triggered catchpoint, tag it with the name of
3150 the library that caused this trigger. (We copy the name now,
3151 because it's only guaranteed to be available NOW, when the
3152 catchpoint triggers. Clients who may wish to know the name
3153 later must get it from the catchpoint itself.) */
3154 if (ep->triggered_dll_pathname != NULL)
3155 xfree (ep->triggered_dll_pathname);
3156 if (ep->type == bp_catch_load)
3157 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3158 PIDGET (inferior_ptid));
3160 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3161 PIDGET (inferior_ptid));
3163 dll_pathname = NULL;
3167 ep->triggered_dll_pathname = (char *)
3168 xmalloc (strlen (dll_pathname) + 1);
3169 strcpy (ep->triggered_dll_pathname, dll_pathname);
3172 ep->triggered_dll_pathname = NULL;
3178 /* Print B to gdb_stdout. */
3180 print_one_breakpoint (struct breakpoint *b,
3181 CORE_ADDR *last_addr)
3183 register struct command_line *l;
3184 register struct symbol *sym;
3185 struct ep_type_description
3190 static struct ep_type_description bptypes[] =
3192 {bp_none, "?deleted?"},
3193 {bp_breakpoint, "breakpoint"},
3194 {bp_hardware_breakpoint, "hw breakpoint"},
3195 {bp_until, "until"},
3196 {bp_finish, "finish"},
3197 {bp_watchpoint, "watchpoint"},
3198 {bp_hardware_watchpoint, "hw watchpoint"},
3199 {bp_read_watchpoint, "read watchpoint"},
3200 {bp_access_watchpoint, "acc watchpoint"},
3201 {bp_longjmp, "longjmp"},
3202 {bp_longjmp_resume, "longjmp resume"},
3203 {bp_step_resume, "step resume"},
3204 {bp_through_sigtramp, "sigtramp"},
3205 {bp_watchpoint_scope, "watchpoint scope"},
3206 {bp_call_dummy, "call dummy"},
3207 {bp_shlib_event, "shlib events"},
3208 {bp_thread_event, "thread events"},
3209 {bp_overlay_event, "overlay events"},
3210 {bp_catch_load, "catch load"},
3211 {bp_catch_unload, "catch unload"},
3212 {bp_catch_fork, "catch fork"},
3213 {bp_catch_vfork, "catch vfork"},
3214 {bp_catch_exec, "catch exec"},
3215 {bp_catch_catch, "catch catch"},
3216 {bp_catch_throw, "catch throw"}
3219 static char *bpdisps[] =
3220 {"del", "dstp", "dis", "keep"};
3221 static char bpenables[] = "nynny";
3222 char wrap_indent[80];
3223 struct ui_stream *stb = ui_out_stream_new (uiout);
3224 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3227 ui_out_tuple_begin (uiout, "bkpt");
3231 ui_out_field_int (uiout, "number", b->number);
3235 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3236 || ((int) b->type != bptypes[(int) b->type].type))
3237 internal_error (__FILE__, __LINE__,
3238 "bptypes table does not describe type #%d.",
3240 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3244 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3248 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]);
3249 ui_out_spaces (uiout, 2);
3252 strcpy (wrap_indent, " ");
3255 if (TARGET_ADDR_BIT <= 32)
3256 strcat (wrap_indent, " ");
3258 strcat (wrap_indent, " ");
3263 internal_error (__FILE__, __LINE__,
3264 "print_one_breakpoint: bp_none encountered\n");
3268 case bp_hardware_watchpoint:
3269 case bp_read_watchpoint:
3270 case bp_access_watchpoint:
3271 /* Field 4, the address, is omitted (which makes the columns
3272 not line up too nicely with the headers, but the effect
3273 is relatively readable). */
3275 ui_out_field_skip (uiout, "addr");
3277 print_expression (b->exp, stb->stream);
3278 ui_out_field_stream (uiout, "what", stb);
3282 case bp_catch_unload:
3283 /* Field 4, the address, is omitted (which makes the columns
3284 not line up too nicely with the headers, but the effect
3285 is relatively readable). */
3287 ui_out_field_skip (uiout, "addr");
3289 if (b->dll_pathname == NULL)
3291 ui_out_field_string (uiout, "what", "<any library>");
3292 ui_out_spaces (uiout, 1);
3296 ui_out_text (uiout, "library \"");
3297 ui_out_field_string (uiout, "what", b->dll_pathname);
3298 ui_out_text (uiout, "\" ");
3303 case bp_catch_vfork:
3304 /* Field 4, the address, is omitted (which makes the columns
3305 not line up too nicely with the headers, but the effect
3306 is relatively readable). */
3308 ui_out_field_skip (uiout, "addr");
3310 if (b->forked_inferior_pid != 0)
3312 ui_out_text (uiout, "process ");
3313 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3314 ui_out_spaces (uiout, 1);
3318 /* Field 4, the address, is omitted (which makes the columns
3319 not line up too nicely with the headers, but the effect
3320 is relatively readable). */
3322 ui_out_field_skip (uiout, "addr");
3324 if (b->exec_pathname != NULL)
3326 ui_out_text (uiout, "program \"");
3327 ui_out_field_string (uiout, "what", b->exec_pathname);
3328 ui_out_text (uiout, "\" ");
3332 case bp_catch_catch:
3333 /* Field 4, the address, is omitted (which makes the columns
3334 not line up too nicely with the headers, but the effect
3335 is relatively readable). */
3337 ui_out_field_skip (uiout, "addr");
3339 ui_out_field_string (uiout, "what", "exception catch");
3340 ui_out_spaces (uiout, 1);
3343 case bp_catch_throw:
3344 /* Field 4, the address, is omitted (which makes the columns
3345 not line up too nicely with the headers, but the effect
3346 is relatively readable). */
3348 ui_out_field_skip (uiout, "addr");
3350 ui_out_field_string (uiout, "what", "exception throw");
3351 ui_out_spaces (uiout, 1);
3355 case bp_hardware_breakpoint:
3359 case bp_longjmp_resume:
3360 case bp_step_resume:
3361 case bp_through_sigtramp:
3362 case bp_watchpoint_scope:
3364 case bp_shlib_event:
3365 case bp_thread_event:
3366 case bp_overlay_event:
3370 ui_out_field_core_addr (uiout, "addr", b->address);
3373 *last_addr = b->address;
3376 sym = find_pc_sect_function (b->address, b->section);
3379 ui_out_text (uiout, "in ");
3380 ui_out_field_string (uiout, "func",
3381 SYMBOL_SOURCE_NAME (sym));
3382 ui_out_wrap_hint (uiout, wrap_indent);
3383 ui_out_text (uiout, " at ");
3385 ui_out_field_string (uiout, "file", b->source_file);
3386 ui_out_text (uiout, ":");
3387 ui_out_field_int (uiout, "line", b->line_number);
3391 print_address_symbolic (b->address, stb->stream, demangle, "");
3392 ui_out_field_stream (uiout, "at", stb);
3397 if (b->thread != -1)
3399 /* FIXME: This seems to be redundant and lost here; see the
3400 "stop only in" line a little further down. */
3401 ui_out_text (uiout, " thread ");
3402 ui_out_field_int (uiout, "thread", b->thread);
3405 ui_out_text (uiout, "\n");
3410 ui_out_text (uiout, "\tstop only in stack frame at ");
3411 ui_out_field_core_addr (uiout, "frame", b->frame);
3412 ui_out_text (uiout, "\n");
3418 ui_out_text (uiout, "\tstop only if ");
3419 print_expression (b->cond, stb->stream);
3420 ui_out_field_stream (uiout, "cond", stb);
3421 ui_out_text (uiout, "\n");
3424 if (b->thread != -1)
3426 /* FIXME should make an annotation for this */
3427 ui_out_text (uiout, "\tstop only in thread ");
3428 ui_out_field_int (uiout, "thread", b->thread);
3429 ui_out_text (uiout, "\n");
3432 if (show_breakpoint_hit_counts && b->hit_count)
3434 /* FIXME should make an annotation for this */
3435 if (ep_is_catchpoint (b))
3436 ui_out_text (uiout, "\tcatchpoint");
3438 ui_out_text (uiout, "\tbreakpoint");
3439 ui_out_text (uiout, " already hit ");
3440 ui_out_field_int (uiout, "times", b->hit_count);
3441 if (b->hit_count == 1)
3442 ui_out_text (uiout, " time\n");
3444 ui_out_text (uiout, " times\n");
3447 /* Output the count also if it is zero, but only if this is
3448 mi. FIXME: Should have a better test for this. */
3449 if (ui_out_is_mi_like_p (uiout))
3450 if (show_breakpoint_hit_counts && b->hit_count == 0)
3451 ui_out_field_int (uiout, "times", b->hit_count);
3453 if (b->ignore_count)
3456 ui_out_text (uiout, "\tignore next ");
3457 ui_out_field_int (uiout, "ignore", b->ignore_count);
3458 ui_out_text (uiout, " hits\n");
3461 if ((l = b->commands))
3464 ui_out_tuple_begin (uiout, "script");
3465 print_command_lines (uiout, l, 4);
3466 ui_out_tuple_end (uiout);
3468 ui_out_tuple_end (uiout);
3469 do_cleanups (old_chain);
3472 struct captured_breakpoint_query_args
3478 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3480 struct captured_breakpoint_query_args *args = data;
3481 register struct breakpoint *b;
3482 CORE_ADDR dummy_addr = 0;
3485 if (args->bnum == b->number)
3487 print_one_breakpoint (b, &dummy_addr);
3495 gdb_breakpoint_query (struct ui_out *uiout, int bnum)
3497 struct captured_breakpoint_query_args args;
3499 /* For the moment we don't trust print_one_breakpoint() to not throw
3501 return catch_exceptions (uiout, do_captured_breakpoint_query, &args,
3502 NULL, RETURN_MASK_ALL);
3505 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3506 catchpoints, et.al.). */
3509 user_settable_breakpoint (const struct breakpoint *b)
3511 return (b->type == bp_breakpoint
3512 || b->type == bp_catch_load
3513 || b->type == bp_catch_unload
3514 || b->type == bp_catch_fork
3515 || b->type == bp_catch_vfork
3516 || b->type == bp_catch_exec
3517 || b->type == bp_catch_catch
3518 || b->type == bp_catch_throw
3519 || b->type == bp_hardware_breakpoint
3520 || b->type == bp_watchpoint
3521 || b->type == bp_read_watchpoint
3522 || b->type == bp_access_watchpoint
3523 || b->type == bp_hardware_watchpoint);
3526 /* Print information on user settable breakpoint (watchpoint, etc)
3527 number BNUM. If BNUM is -1 print all user settable breakpoints.
3528 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3531 breakpoint_1 (int bnum, int allflag)
3533 register struct breakpoint *b;
3534 CORE_ADDR last_addr = (CORE_ADDR) -1;
3535 int nr_printable_breakpoints;
3537 /* Compute the number of rows in the table. */
3538 nr_printable_breakpoints = 0;
3541 || bnum == b->number)
3543 if (allflag || user_settable_breakpoint (b))
3544 nr_printable_breakpoints++;
3548 ui_out_table_begin (uiout, 6, nr_printable_breakpoints, "BreakpointTable");
3550 ui_out_table_begin (uiout, 5, nr_printable_breakpoints, "BreakpointTable");
3552 if (nr_printable_breakpoints > 0)
3553 annotate_breakpoints_headers ();
3554 if (nr_printable_breakpoints > 0)
3556 ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */
3557 if (nr_printable_breakpoints > 0)
3559 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3560 if (nr_printable_breakpoints > 0)
3562 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3563 if (nr_printable_breakpoints > 0)
3565 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3568 if (nr_printable_breakpoints > 0)
3570 if (TARGET_ADDR_BIT <= 32)
3571 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3573 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3575 if (nr_printable_breakpoints > 0)
3577 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3578 ui_out_table_body (uiout);
3579 if (nr_printable_breakpoints > 0)
3580 annotate_breakpoints_table ();
3584 || bnum == b->number)
3586 /* We only print out user settable breakpoints unless the
3588 if (allflag || user_settable_breakpoint (b))
3589 print_one_breakpoint (b, &last_addr);
3592 ui_out_table_end (uiout);
3594 if (nr_printable_breakpoints == 0)
3597 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3599 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3604 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3605 that a comparison of an unsigned with -1 is always false. */
3606 if (last_addr != (CORE_ADDR) -1)
3607 set_next_address (last_addr);
3610 /* FIXME? Should this be moved up so that it is only called when
3611 there have been breakpoints? */
3612 annotate_breakpoints_table_end ();
3617 breakpoints_info (char *bnum_exp, int from_tty)
3622 bnum = parse_and_eval_long (bnum_exp);
3624 breakpoint_1 (bnum, 0);
3629 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3634 bnum = parse_and_eval_long (bnum_exp);
3636 breakpoint_1 (bnum, 1);
3639 /* Print a message describing any breakpoints set at PC. */
3642 describe_other_breakpoints (CORE_ADDR pc, asection *section)
3644 register int others = 0;
3645 register struct breakpoint *b;
3648 if (b->address == pc) /* address match / overlay match */
3649 if (!overlay_debugging || b->section == section)
3653 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3655 if (b->address == pc) /* address match / overlay match */
3656 if (!overlay_debugging || b->section == section)
3659 printf_filtered ("%d%s%s ",
3661 ((b->enable_state == bp_disabled ||
3662 b->enable_state == bp_shlib_disabled ||
3663 b->enable_state == bp_call_disabled)
3665 : b->enable_state == bp_permanent
3669 : ((others == 1) ? " and" : ""));
3671 printf_filtered ("also set at pc ");
3672 print_address_numeric (pc, 1, gdb_stdout);
3673 printf_filtered (".\n");
3677 /* Set the default place to put a breakpoint
3678 for the `break' command with no arguments. */
3681 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3684 default_breakpoint_valid = valid;
3685 default_breakpoint_address = addr;
3686 default_breakpoint_symtab = symtab;
3687 default_breakpoint_line = line;
3690 /* Return true iff it is meaningful to use the address member of
3691 BPT. For some breakpoint types, the address member is irrelevant
3692 and it makes no sense to attempt to compare it to other addresses
3693 (or use it for any other purpose either).
3695 More specifically, each of the following breakpoint types will always
3696 have a zero valued address and we don't want check_duplicates() to mark
3697 breakpoints of any of these types to be a duplicate of an actual
3698 breakpoint at address zero:
3701 bp_hardware_watchpoint
3703 bp_access_watchpoint
3710 breakpoint_address_is_meaningful (struct breakpoint *bpt)
3712 enum bptype type = bpt->type;
3714 return (type != bp_watchpoint
3715 && type != bp_hardware_watchpoint
3716 && type != bp_read_watchpoint
3717 && type != bp_access_watchpoint
3718 && type != bp_catch_exec
3719 && type != bp_longjmp_resume
3720 && type != bp_catch_fork
3721 && type != bp_catch_vfork);
3724 /* Rescan breakpoints at the same address and section as BPT,
3725 marking the first one as "first" and any others as "duplicates".
3726 This is so that the bpt instruction is only inserted once.
3727 If we have a permanent breakpoint at the same place as BPT, make
3728 that one the official one, and the rest as duplicates. */
3731 check_duplicates (struct breakpoint *bpt)
3733 register struct breakpoint *b;
3734 register int count = 0;
3735 struct breakpoint *perm_bp = 0;
3736 CORE_ADDR address = bpt->address;
3737 asection *section = bpt->section;
3739 if (! breakpoint_address_is_meaningful (bpt))
3743 if (b->enable_state != bp_disabled
3744 && b->enable_state != bp_shlib_disabled
3745 && b->enable_state != bp_call_disabled
3746 && b->address == address /* address / overlay match */
3747 && (!overlay_debugging || b->section == section)
3748 && breakpoint_address_is_meaningful (b))
3750 /* Have we found a permanent breakpoint? */
3751 if (b->enable_state == bp_permanent)
3758 b->duplicate = count > 1;
3761 /* If we found a permanent breakpoint at this address, go over the
3762 list again and declare all the other breakpoints there to be the
3766 perm_bp->duplicate = 0;
3768 /* Permanent breakpoint should always be inserted. */
3769 if (! perm_bp->inserted)
3770 internal_error (__FILE__, __LINE__,
3771 "allegedly permanent breakpoint is not "
3772 "actually inserted");
3778 internal_error (__FILE__, __LINE__,
3779 "another breakpoint was inserted on top of "
3780 "a permanent breakpoint");
3782 if (b->enable_state != bp_disabled
3783 && b->enable_state != bp_shlib_disabled
3784 && b->enable_state != bp_call_disabled
3785 && b->address == address /* address / overlay match */
3786 && (!overlay_debugging || b->section == section)
3787 && breakpoint_address_is_meaningful (b))
3793 /* set_raw_breakpoint() is a low level routine for allocating and
3794 partially initializing a breakpoint of type BPTYPE. The newly
3795 created breakpoint's address, section, source file name, and line
3796 number are provided by SAL. The newly created and partially
3797 initialized breakpoint is added to the breakpoint chain and
3798 is also returned as the value of this function.
3800 It is expected that the caller will complete the initialization of
3801 the newly created breakpoint struct as well as output any status
3802 information regarding the creation of a new breakpoint. In
3803 particular, set_raw_breakpoint() does NOT set the breakpoint
3804 number! Care should be taken to not allow an error() to occur
3805 prior to completing the initialization of the breakpoint. If this
3806 should happen, a bogus breakpoint will be left on the chain. */
3809 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
3811 register struct breakpoint *b, *b1;
3813 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3814 memset (b, 0, sizeof (*b));
3815 b->address = sal.pc;
3816 if (sal.symtab == NULL)
3817 b->source_file = NULL;
3819 b->source_file = savestring (sal.symtab->filename,
3820 strlen (sal.symtab->filename));
3821 b->section = sal.section;
3823 b->language = current_language->la_language;
3824 b->input_radix = input_radix;
3826 b->line_number = sal.line;
3827 b->enable_state = bp_enabled;
3830 b->ignore_count = 0;
3833 b->dll_pathname = NULL;
3834 b->triggered_dll_pathname = NULL;
3835 b->forked_inferior_pid = 0;
3836 b->exec_pathname = NULL;
3838 /* Add this breakpoint to the end of the chain
3839 so that a list of breakpoints will come out in order
3840 of increasing numbers. */
3842 b1 = breakpoint_chain;
3844 breakpoint_chain = b;
3852 check_duplicates (b);
3853 breakpoints_changed ();
3859 /* Note that the breakpoint object B describes a permanent breakpoint
3860 instruction, hard-wired into the inferior's code. */
3862 make_breakpoint_permanent (struct breakpoint *b)
3864 b->enable_state = bp_permanent;
3866 /* By definition, permanent breakpoints are already present in the code. */
3870 static struct breakpoint *
3871 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
3873 static int internal_breakpoint_number = -1;
3874 struct symtab_and_line sal;
3875 struct breakpoint *b;
3877 INIT_SAL (&sal); /* initialize to zeroes */
3880 sal.section = find_pc_overlay (sal.pc);
3882 b = set_raw_breakpoint (sal, type);
3883 b->number = internal_breakpoint_number--;
3884 b->disposition = disp_donttouch;
3891 create_longjmp_breakpoint (char *func_name)
3893 struct breakpoint *b;
3894 struct minimal_symbol *m;
3896 if (func_name == NULL)
3897 b = create_internal_breakpoint (0, bp_longjmp_resume);
3900 if ((m = lookup_minimal_symbol_text (func_name, NULL, NULL)) == NULL)
3903 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
3906 b->enable_state = bp_disabled;
3909 b->addr_string = xstrdup (func_name);
3912 /* Call this routine when stepping and nexting to enable a breakpoint
3913 if we do a longjmp(). When we hit that breakpoint, call
3914 set_longjmp_resume_breakpoint() to figure out where we are going. */
3917 enable_longjmp_breakpoint (void)
3919 register struct breakpoint *b;
3922 if (b->type == bp_longjmp)
3924 b->enable_state = bp_enabled;
3925 check_duplicates (b);
3930 disable_longjmp_breakpoint (void)
3932 register struct breakpoint *b;
3935 if (b->type == bp_longjmp
3936 || b->type == bp_longjmp_resume)
3938 b->enable_state = bp_disabled;
3939 check_duplicates (b);
3944 create_overlay_event_breakpoint (char *func_name)
3946 struct breakpoint *b;
3947 struct minimal_symbol *m;
3949 if ((m = lookup_minimal_symbol_text (func_name, NULL, NULL)) == NULL)
3952 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
3954 b->addr_string = xstrdup (func_name);
3956 if (overlay_debugging == ovly_auto)
3958 b->enable_state = bp_enabled;
3959 overlay_events_enabled = 1;
3963 b->enable_state = bp_disabled;
3964 overlay_events_enabled = 0;
3969 enable_overlay_breakpoints (void)
3971 register struct breakpoint *b;
3974 if (b->type == bp_overlay_event)
3976 b->enable_state = bp_enabled;
3977 check_duplicates (b);
3978 overlay_events_enabled = 1;
3983 disable_overlay_breakpoints (void)
3985 register struct breakpoint *b;
3988 if (b->type == bp_overlay_event)
3990 b->enable_state = bp_disabled;
3991 check_duplicates (b);
3992 overlay_events_enabled = 0;
3997 create_thread_event_breakpoint (CORE_ADDR address)
3999 struct breakpoint *b;
4000 char addr_string[80]; /* Surely an addr can't be longer than that. */
4002 b = create_internal_breakpoint (address, bp_thread_event);
4004 b->enable_state = bp_enabled;
4005 /* addr_string has to be used or breakpoint_re_set will delete me. */
4006 sprintf (addr_string, "*0x%s", paddr (b->address));
4007 b->addr_string = xstrdup (addr_string);
4013 remove_thread_event_breakpoints (void)
4015 struct breakpoint *b, *temp;
4017 ALL_BREAKPOINTS_SAFE (b, temp)
4018 if (b->type == bp_thread_event)
4019 delete_breakpoint (b);
4024 remove_solib_event_breakpoints (void)
4026 register struct breakpoint *b, *temp;
4028 ALL_BREAKPOINTS_SAFE (b, temp)
4029 if (b->type == bp_shlib_event)
4030 delete_breakpoint (b);
4034 create_solib_event_breakpoint (CORE_ADDR address)
4036 struct breakpoint *b;
4038 b = create_internal_breakpoint (address, bp_shlib_event);
4042 /* Disable any breakpoints that are on code in shared libraries. Only
4043 apply to enabled breakpoints, disabled ones can just stay disabled. */
4046 disable_breakpoints_in_shlibs (int silent)
4048 struct breakpoint *b;
4049 int disabled_shlib_breaks = 0;
4051 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4054 #if defined (PC_SOLIB)
4055 if (((b->type == bp_breakpoint) ||
4056 (b->type == bp_hardware_breakpoint)) &&
4057 b->enable_state == bp_enabled &&
4059 PC_SOLIB (b->address))
4061 b->enable_state = bp_shlib_disabled;
4064 if (!disabled_shlib_breaks)
4066 target_terminal_ours_for_output ();
4067 warning ("Temporarily disabling shared library breakpoints:");
4069 disabled_shlib_breaks = 1;
4070 warning ("breakpoint #%d ", b->number);
4077 /* Try to reenable any breakpoints in shared libraries. */
4079 re_enable_breakpoints_in_shlibs (void)
4081 struct breakpoint *b;
4084 if (b->enable_state == bp_shlib_disabled)
4088 /* Do not reenable the breakpoint if the shared library
4089 is still not mapped in. */
4090 if (target_read_memory (b->address, buf, 1) == 0)
4091 b->enable_state = bp_enabled;
4098 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
4099 char *cond_string, enum bptype bp_kind)
4101 struct breakpoint *b;
4102 struct symtabs_and_lines sals;
4103 struct cleanup *old_chain;
4104 struct cleanup *canonical_strings_chain = NULL;
4105 char *addr_start = hookname;
4106 char *addr_end = NULL;
4107 char **canonical = (char **) NULL;
4108 int thread = -1; /* All threads. */
4110 /* Set a breakpoint on the specified hook. */
4111 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
4112 addr_end = hookname;
4114 if (sals.nelts == 0)
4116 warning ("Unable to set a breakpoint on dynamic linker callback.");
4117 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4118 warning ("GDB will be unable to track shl_load/shl_unload calls");
4121 if (sals.nelts != 1)
4123 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4124 warning ("GDB will be unable to track shl_load/shl_unload calls");
4128 /* Make sure that all storage allocated in decode_line_1 gets freed
4129 in case the following errors out. */
4130 old_chain = make_cleanup (xfree, sals.sals);
4131 if (canonical != (char **) NULL)
4133 make_cleanup (xfree, canonical);
4134 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4135 if (canonical[0] != NULL)
4136 make_cleanup (xfree, canonical[0]);
4139 resolve_sal_pc (&sals.sals[0]);
4141 /* Remove the canonical strings from the cleanup, they are needed below. */
4142 if (canonical != (char **) NULL)
4143 discard_cleanups (canonical_strings_chain);
4145 b = set_raw_breakpoint (sals.sals[0], bp_kind);
4146 set_breakpoint_count (breakpoint_count + 1);
4147 b->number = breakpoint_count;
4149 b->cond_string = (cond_string == NULL) ?
4150 NULL : savestring (cond_string, strlen (cond_string));
4153 if (canonical != (char **) NULL && canonical[0] != NULL)
4154 b->addr_string = canonical[0];
4155 else if (addr_start)
4156 b->addr_string = savestring (addr_start, addr_end - addr_start);
4158 b->enable_state = bp_enabled;
4159 b->disposition = tempflag ? disp_del : disp_donttouch;
4161 if (dll_pathname == NULL)
4162 b->dll_pathname = NULL;
4165 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4166 strcpy (b->dll_pathname, dll_pathname);
4170 do_cleanups (old_chain);
4174 create_solib_load_event_breakpoint (char *hookname, int tempflag,
4175 char *dll_pathname, char *cond_string)
4177 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4178 cond_string, bp_catch_load);
4182 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4183 char *dll_pathname, char *cond_string)
4185 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4186 cond_string, bp_catch_unload);
4190 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4191 enum bptype bp_kind)
4193 struct symtab_and_line sal;
4194 struct breakpoint *b;
4195 int thread = -1; /* All threads. */
4202 b = set_raw_breakpoint (sal, bp_kind);
4203 set_breakpoint_count (breakpoint_count + 1);
4204 b->number = breakpoint_count;
4206 b->cond_string = (cond_string == NULL) ?
4207 NULL : savestring (cond_string, strlen (cond_string));
4209 b->addr_string = NULL;
4210 b->enable_state = bp_enabled;
4211 b->disposition = tempflag ? disp_del : disp_donttouch;
4212 b->forked_inferior_pid = 0;
4218 create_fork_event_catchpoint (int tempflag, char *cond_string)
4220 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4224 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4226 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4230 create_exec_event_catchpoint (int tempflag, char *cond_string)
4232 struct symtab_and_line sal;
4233 struct breakpoint *b;
4234 int thread = -1; /* All threads. */
4241 b = set_raw_breakpoint (sal, bp_catch_exec);
4242 set_breakpoint_count (breakpoint_count + 1);
4243 b->number = breakpoint_count;
4245 b->cond_string = (cond_string == NULL) ?
4246 NULL : savestring (cond_string, strlen (cond_string));
4248 b->addr_string = NULL;
4249 b->enable_state = bp_enabled;
4250 b->disposition = tempflag ? disp_del : disp_donttouch;
4256 hw_breakpoint_used_count (void)
4258 register struct breakpoint *b;
4263 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4271 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4273 register struct breakpoint *b;
4276 *other_type_used = 0;
4279 if (b->enable_state == bp_enabled)
4281 if (b->type == type)
4283 else if ((b->type == bp_hardware_watchpoint ||
4284 b->type == bp_read_watchpoint ||
4285 b->type == bp_access_watchpoint)
4286 && b->enable_state == bp_enabled)
4287 *other_type_used = 1;
4293 /* Call this after hitting the longjmp() breakpoint. Use this to set
4294 a new breakpoint at the target of the jmp_buf.
4296 FIXME - This ought to be done by setting a temporary breakpoint
4297 that gets deleted automatically... */
4300 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_info *frame)
4302 register struct breakpoint *b;
4305 if (b->type == bp_longjmp_resume)
4308 b->enable_state = bp_enabled;
4310 b->frame = frame->frame;
4313 check_duplicates (b);
4319 disable_watchpoints_before_interactive_call_start (void)
4321 struct breakpoint *b;
4325 if (((b->type == bp_watchpoint)
4326 || (b->type == bp_hardware_watchpoint)
4327 || (b->type == bp_read_watchpoint)
4328 || (b->type == bp_access_watchpoint)
4329 || ep_is_exception_catchpoint (b))
4330 && (b->enable_state == bp_enabled))
4332 b->enable_state = bp_call_disabled;
4333 check_duplicates (b);
4339 enable_watchpoints_after_interactive_call_stop (void)
4341 struct breakpoint *b;
4345 if (((b->type == bp_watchpoint)
4346 || (b->type == bp_hardware_watchpoint)
4347 || (b->type == bp_read_watchpoint)
4348 || (b->type == bp_access_watchpoint)
4349 || ep_is_exception_catchpoint (b))
4350 && (b->enable_state == bp_call_disabled))
4352 b->enable_state = bp_enabled;
4353 check_duplicates (b);
4359 /* Set a breakpoint that will evaporate an end of command
4360 at address specified by SAL.
4361 Restrict it to frame FRAME if FRAME is nonzero. */
4364 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_info *frame,
4367 register struct breakpoint *b;
4368 b = set_raw_breakpoint (sal, type);
4369 b->enable_state = bp_enabled;
4370 b->disposition = disp_donttouch;
4371 b->frame = (frame ? frame->frame : 0);
4373 /* If we're debugging a multi-threaded program, then we
4374 want momentary breakpoints to be active in only a
4375 single thread of control. */
4376 if (in_thread_list (inferior_ptid))
4377 b->thread = pid_to_thread_id (inferior_ptid);
4383 /* Tell the user we have just set a breakpoint B. */
4386 mention (struct breakpoint *b)
4389 struct cleanup *old_chain;
4390 struct ui_stream *stb;
4392 stb = ui_out_stream_new (uiout);
4393 old_chain = make_cleanup_ui_out_stream_delete (stb);
4395 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4396 watchpoint) other than breakpoint creation. It should be possible to
4397 clean this up and at the same time replace the random calls to
4398 breakpoint_changed with this hook, as has already been done for
4399 delete_breakpoint_hook and so on. */
4400 if (create_breakpoint_hook)
4401 create_breakpoint_hook (b);
4402 breakpoint_create_event (b->number);
4407 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4410 ui_out_text (uiout, "Watchpoint ");
4411 ui_out_tuple_begin (uiout, "wpt");
4412 ui_out_field_int (uiout, "number", b->number);
4413 ui_out_text (uiout, ": ");
4414 print_expression (b->exp, stb->stream);
4415 ui_out_field_stream (uiout, "exp", stb);
4416 ui_out_tuple_end (uiout);
4418 case bp_hardware_watchpoint:
4419 ui_out_text (uiout, "Hardware watchpoint ");
4420 ui_out_tuple_begin (uiout, "wpt");
4421 ui_out_field_int (uiout, "number", b->number);
4422 ui_out_text (uiout, ": ");
4423 print_expression (b->exp, stb->stream);
4424 ui_out_field_stream (uiout, "exp", stb);
4425 ui_out_tuple_end (uiout);
4427 case bp_read_watchpoint:
4428 ui_out_text (uiout, "Hardware read watchpoint ");
4429 ui_out_tuple_begin (uiout, "hw-rwpt");
4430 ui_out_field_int (uiout, "number", b->number);
4431 ui_out_text (uiout, ": ");
4432 print_expression (b->exp, stb->stream);
4433 ui_out_field_stream (uiout, "exp", stb);
4434 ui_out_tuple_end (uiout);
4436 case bp_access_watchpoint:
4437 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4438 ui_out_tuple_begin (uiout, "hw-awpt");
4439 ui_out_field_int (uiout, "number", b->number);
4440 ui_out_text (uiout, ": ");
4441 print_expression (b->exp, stb->stream);
4442 ui_out_field_stream (uiout, "exp", stb);
4443 ui_out_tuple_end (uiout);
4446 if (ui_out_is_mi_like_p (uiout))
4451 printf_filtered ("Breakpoint %d", b->number);
4454 case bp_hardware_breakpoint:
4455 if (ui_out_is_mi_like_p (uiout))
4460 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4464 case bp_catch_unload:
4465 printf_filtered ("Catchpoint %d (%s %s)",
4467 (b->type == bp_catch_load) ? "load" : "unload",
4468 (b->dll_pathname != NULL) ?
4469 b->dll_pathname : "<any library>");
4472 case bp_catch_vfork:
4473 printf_filtered ("Catchpoint %d (%s)",
4475 (b->type == bp_catch_fork) ? "fork" : "vfork");
4478 printf_filtered ("Catchpoint %d (exec)",
4481 case bp_catch_catch:
4482 case bp_catch_throw:
4483 printf_filtered ("Catchpoint %d (%s)",
4485 (b->type == bp_catch_catch) ? "catch" : "throw");
4491 case bp_longjmp_resume:
4492 case bp_step_resume:
4493 case bp_through_sigtramp:
4495 case bp_watchpoint_scope:
4496 case bp_shlib_event:
4497 case bp_thread_event:
4498 case bp_overlay_event:
4503 if (addressprint || b->source_file == NULL)
4505 printf_filtered (" at ");
4506 print_address_numeric (b->address, 1, gdb_stdout);
4509 printf_filtered (": file %s, line %d.",
4510 b->source_file, b->line_number);
4512 do_cleanups (old_chain);
4513 if (ui_out_is_mi_like_p (uiout))
4515 printf_filtered ("\n");
4519 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4520 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4521 COND[i] and COND_STRING[i] values.
4523 NOTE: If the function succeeds, the caller is expected to cleanup
4524 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4525 array contents). If the function fails (error() is called), the
4526 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4527 COND and SALS arrays and each of those arrays contents. */
4530 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4531 struct expression **cond, char **cond_string,
4532 enum bptype type, enum bpdisp disposition,
4533 int thread, int ignore_count, int from_tty)
4535 if (type == bp_hardware_breakpoint)
4537 int i = hw_breakpoint_used_count ();
4538 int target_resources_ok =
4539 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4541 if (target_resources_ok == 0)
4542 error ("No hardware breakpoint support in the target.");
4543 else if (target_resources_ok < 0)
4544 error ("Hardware breakpoints used exceeds limit.");
4547 /* Now set all the breakpoints. */
4550 for (i = 0; i < sals.nelts; i++)
4552 struct breakpoint *b;
4553 struct symtab_and_line sal = sals.sals[i];
4556 describe_other_breakpoints (sal.pc, sal.section);
4558 b = set_raw_breakpoint (sal, type);
4559 set_breakpoint_count (breakpoint_count + 1);
4560 b->number = breakpoint_count;
4563 b->addr_string = addr_string[i];
4564 b->cond_string = cond_string[i];
4565 b->ignore_count = ignore_count;
4566 b->enable_state = bp_enabled;
4567 b->disposition = disposition;
4573 /* Parse ARG which is assumed to be a SAL specification possibly
4574 followed by conditionals. On return, SALS contains an array of SAL
4575 addresses found. ADDR_STRING contains a vector of (canonical)
4576 address strings. ARG points to the end of the SAL. */
4579 parse_breakpoint_sals (char **address,
4580 struct symtabs_and_lines *sals,
4581 char ***addr_string)
4583 char *addr_start = *address;
4584 *addr_string = NULL;
4585 /* If no arg given, or if first arg is 'if ', use the default
4587 if ((*address) == NULL
4588 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4590 if (default_breakpoint_valid)
4592 struct symtab_and_line sal;
4593 INIT_SAL (&sal); /* initialize to zeroes */
4594 sals->sals = (struct symtab_and_line *)
4595 xmalloc (sizeof (struct symtab_and_line));
4596 sal.pc = default_breakpoint_address;
4597 sal.line = default_breakpoint_line;
4598 sal.symtab = default_breakpoint_symtab;
4599 sal.section = find_pc_overlay (sal.pc);
4600 sals->sals[0] = sal;
4604 error ("No default breakpoint address now.");
4608 /* Force almost all breakpoints to be in terms of the
4609 current_source_symtab (which is decode_line_1's default). This
4610 should produce the results we want almost all of the time while
4611 leaving default_breakpoint_* alone. */
4612 if (default_breakpoint_valid
4613 && (!current_source_symtab
4614 || (strchr ("+-", (*address)[0]) != NULL)))
4615 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4616 default_breakpoint_line, addr_string);
4618 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
4620 /* For any SAL that didn't have a canonical string, fill one in. */
4621 if (sals->nelts > 0 && *addr_string == NULL)
4622 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4623 if (addr_start != (*address))
4626 for (i = 0; i < sals->nelts; i++)
4628 /* Add the string if not present. */
4629 if ((*addr_string)[i] == NULL)
4630 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
4636 /* Convert each SAL into a real PC. Verify that the PC can be
4637 inserted as a breakpoint. If it can't throw an error. */
4640 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4644 for (i = 0; i < sals->nelts; i++)
4646 resolve_sal_pc (&sals->sals[i]);
4648 /* It's possible for the PC to be nonzero, but still an illegal
4649 value on some targets.
4651 For example, on HP-UX if you start gdb, and before running the
4652 inferior you try to set a breakpoint on a shared library function
4653 "foo" where the inferior doesn't call "foo" directly but does
4654 pass its address to another function call, then we do find a
4655 minimal symbol for the "foo", but it's address is invalid.
4656 (Appears to be an index into a table that the loader sets up
4657 when the inferior is run.)
4659 Give the target a chance to bless sals.sals[i].pc before we
4660 try to make a breakpoint for it. */
4661 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
4663 if (address == NULL)
4664 error ("Cannot break without a running program.");
4666 error ("Cannot break on %s without a running program.",
4672 /* Set a breakpoint according to ARG (function, linenum or *address)
4673 flag: first bit : 0 non-temporary, 1 temporary.
4674 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4677 break_command_1 (char *arg, int flag, int from_tty)
4679 int tempflag, hardwareflag;
4680 struct symtabs_and_lines sals;
4681 register struct expression **cond = 0;
4682 /* Pointers in arg to the start, and one past the end, of the
4684 char **cond_string = (char **) NULL;
4685 char *addr_start = arg;
4687 struct cleanup *old_chain;
4688 struct cleanup *breakpoint_chain = NULL;
4691 int ignore_count = 0;
4693 hardwareflag = flag & BP_HARDWAREFLAG;
4694 tempflag = flag & BP_TEMPFLAG;
4699 parse_breakpoint_sals (&arg, &sals, &addr_string);
4704 /* Create a chain of things that always need to be cleaned up. */
4705 old_chain = make_cleanup (null_cleanup, 0);
4707 /* Make sure that all storage allocated to SALS gets freed. */
4708 make_cleanup (xfree, sals.sals);
4710 /* Cleanup the addr_string array but not its contents. */
4711 make_cleanup (xfree, addr_string);
4713 /* Allocate space for all the cond expressions. */
4714 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4715 make_cleanup (xfree, cond);
4717 /* Allocate space for all the cond strings. */
4718 cond_string = xcalloc (sals.nelts, sizeof (char **));
4719 make_cleanup (xfree, cond_string);
4721 /* ----------------------------- SNIP -----------------------------
4722 Anything added to the cleanup chain beyond this point is assumed
4723 to be part of a breakpoint. If the breakpoint create succeeds
4724 then the memory is not reclaimed. */
4725 breakpoint_chain = make_cleanup (null_cleanup, 0);
4727 /* Mark the contents of the addr_string for cleanup. These go on
4728 the breakpoint_chain and only occure if the breakpoint create
4730 for (i = 0; i < sals.nelts; i++)
4732 if (addr_string[i] != NULL)
4733 make_cleanup (xfree, addr_string[i]);
4736 /* Resolve all line numbers to PC's and verify that the addresses
4737 are ok for the target. */
4738 breakpoint_sals_to_pc (&sals, addr_start);
4740 /* Verify that condition can be parsed, before setting any
4741 breakpoints. Allocate a separate condition expression for each
4743 thread = -1; /* No specific thread yet */
4744 for (i = 0; i < sals.nelts; i++)
4751 char *cond_start = NULL;
4752 char *cond_end = NULL;
4753 while (*tok == ' ' || *tok == '\t')
4758 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4761 toklen = end_tok - tok;
4763 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4765 tok = cond_start = end_tok + 1;
4766 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4767 make_cleanup (xfree, cond[i]);
4769 cond_string[i] = savestring (cond_start, cond_end - cond_start);
4770 make_cleanup (xfree, cond_string[i]);
4772 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4778 thread = strtol (tok, &tok, 0);
4780 error ("Junk after thread keyword.");
4781 if (!valid_thread_id (thread))
4782 error ("Unknown thread %d\n", thread);
4785 error ("Junk at end of arguments.");
4789 create_breakpoints (sals, addr_string, cond, cond_string,
4790 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4791 tempflag ? disp_del : disp_donttouch,
4792 thread, ignore_count, from_tty);
4796 warning ("Multiple breakpoints were set.");
4797 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4799 /* That's it. Discard the cleanups for data inserted into the
4801 discard_cleanups (breakpoint_chain);
4802 /* But cleanup everything else. */
4803 do_cleanups (old_chain);
4806 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4807 linenum or *address) with COND and IGNORE_COUNT. */
4809 struct captured_breakpoint_args
4820 do_captured_breakpoint (void *data)
4822 struct captured_breakpoint_args *args = data;
4823 struct symtabs_and_lines sals;
4824 register struct expression **cond;
4825 struct cleanup *old_chain;
4826 struct cleanup *breakpoint_chain = NULL;
4833 /* Parse the source and lines spec. Delay check that the expression
4834 didn't contain trailing garbage until after cleanups are in
4838 address_end = args->address;
4840 parse_breakpoint_sals (&address_end, &sals, &addr_string);
4845 /* Create a chain of things at always need to be cleaned up. */
4846 old_chain = make_cleanup (null_cleanup, 0);
4848 /* Always have a addr_string array, even if it is empty. */
4849 make_cleanup (xfree, addr_string);
4851 /* Make sure that all storage allocated to SALS gets freed. */
4852 make_cleanup (xfree, sals.sals);
4854 /* Allocate space for all the cond expressions. */
4855 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4856 make_cleanup (xfree, cond);
4858 /* Allocate space for all the cond strings. */
4859 cond_string = xcalloc (sals.nelts, sizeof (char **));
4860 make_cleanup (xfree, cond_string);
4862 /* ----------------------------- SNIP -----------------------------
4863 Anything added to the cleanup chain beyond this point is assumed
4864 to be part of a breakpoint. If the breakpoint create goes
4865 through then that memory is not cleaned up. */
4866 breakpoint_chain = make_cleanup (null_cleanup, 0);
4868 /* Mark the contents of the addr_string for cleanup. These go on
4869 the breakpoint_chain and only occure if the breakpoint create
4871 for (i = 0; i < sals.nelts; i++)
4873 if (addr_string[i] != NULL)
4874 make_cleanup (xfree, addr_string[i]);
4877 /* Wait until now before checking for garbage at the end of the
4878 address. That way cleanups can take care of freeing any
4880 if (*address_end != '\0')
4881 error ("Garbage %s following breakpoint address", address_end);
4883 /* Resolve all line numbers to PC's. */
4884 breakpoint_sals_to_pc (&sals, args->address);
4886 /* Verify that conditions can be parsed, before setting any
4888 for (i = 0; i < sals.nelts; i++)
4890 if (args->condition != NULL)
4892 char *tok = args->condition;
4893 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4895 error ("Garbage %s follows condition", tok);
4896 make_cleanup (xfree, cond[i]);
4897 cond_string[i] = xstrdup (args->condition);
4901 create_breakpoints (sals, addr_string, cond, cond_string,
4902 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4903 args->tempflag ? disp_del : disp_donttouch,
4904 args->thread, args->ignore_count, 0/*from-tty*/);
4906 /* That's it. Discard the cleanups for data inserted into the
4908 discard_cleanups (breakpoint_chain);
4909 /* But cleanup everything else. */
4910 do_cleanups (old_chain);
4915 gdb_breakpoint (char *address, char *condition,
4916 int hardwareflag, int tempflag,
4917 int thread, int ignore_count)
4919 struct captured_breakpoint_args args;
4920 args.address = address;
4921 args.condition = condition;
4922 args.hardwareflag = hardwareflag;
4923 args.tempflag = tempflag;
4924 args.thread = thread;
4925 args.ignore_count = ignore_count;
4926 return catch_errors (do_captured_breakpoint, &args,
4927 NULL, RETURN_MASK_ALL);
4932 break_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty)
4934 struct frame_info *frame;
4935 CORE_ADDR low, high, selected_pc = 0;
4936 char *extra_args = NULL;
4939 int extra_args_len = 0, if_arg = 0;
4942 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4945 if (default_breakpoint_valid)
4949 selected_pc = selected_frame->pc;
4954 error ("No selected frame.");
4957 error ("No default breakpoint address now.");
4961 extra_args = strchr (arg, ' ');
4965 extra_args_len = strlen (extra_args);
4966 level_arg = (char *) xmalloc (extra_args - arg);
4967 strncpy (level_arg, arg, extra_args - arg - 1);
4968 level_arg[extra_args - arg - 1] = '\0';
4972 level_arg = (char *) xmalloc (strlen (arg) + 1);
4973 strcpy (level_arg, arg);
4976 frame = parse_frame_specification (level_arg);
4978 selected_pc = frame->pc;
4985 extra_args_len = strlen (arg);
4990 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
4992 addr_string = (char *) xmalloc (26 + extra_args_len);
4994 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
4996 sprintf (addr_string, "*0x%s", paddr_nz (high));
4997 break_command_1 (addr_string, flag, from_tty);
4998 xfree (addr_string);
5001 error ("No function contains the specified address");
5004 error ("Unable to set breakpoint at procedure exit");
5009 break_at_finish_command_1 (char *arg, int flag, int from_tty)
5011 char *addr_string, *break_string, *beg_addr_string;
5012 CORE_ADDR low, high;
5013 struct symtabs_and_lines sals;
5014 struct symtab_and_line sal;
5015 struct cleanup *old_chain;
5016 char *extra_args = NULL;
5017 int extra_args_len = 0;
5021 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5023 if (default_breakpoint_valid)
5027 addr_string = (char *) xmalloc (15);
5028 sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
5033 error ("No selected frame.");
5036 error ("No default breakpoint address now.");
5040 addr_string = (char *) xmalloc (strlen (arg) + 1);
5041 strcpy (addr_string, arg);
5047 extra_args_len = strlen (arg);
5051 /* get the stuff after the function name or address */
5052 extra_args = strchr (arg, ' ');
5056 extra_args_len = strlen (extra_args);
5063 beg_addr_string = addr_string;
5064 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
5067 xfree (beg_addr_string);
5068 old_chain = make_cleanup (xfree, sals.sals);
5069 for (i = 0; (i < sals.nelts); i++)
5072 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
5074 break_string = (char *) xmalloc (extra_args_len + 26);
5076 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
5078 sprintf (break_string, "*0x%s", paddr_nz (high));
5079 break_command_1 (break_string, flag, from_tty);
5080 xfree (break_string);
5083 error ("No function contains the specified address");
5087 warning ("Multiple breakpoints were set.\n");
5088 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5090 do_cleanups (old_chain);
5094 /* Helper function for break_command_1 and disassemble_command. */
5097 resolve_sal_pc (struct symtab_and_line *sal)
5101 if (sal->pc == 0 && sal->symtab != NULL)
5103 if (!find_line_pc (sal->symtab, sal->line, &pc))
5104 error ("No line %d in file \"%s\".",
5105 sal->line, sal->symtab->filename);
5109 if (sal->section == 0 && sal->symtab != NULL)
5111 struct blockvector *bv;
5116 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5119 b = BLOCKVECTOR_BLOCK (bv, index);
5120 sym = block_function (b);
5123 fixup_symbol_section (sym, sal->symtab->objfile);
5124 sal->section = SYMBOL_BFD_SECTION (sym);
5128 /* It really is worthwhile to have the section, so we'll just
5129 have to look harder. This case can be executed if we have
5130 line numbers but no functions (as can happen in assembly
5133 struct minimal_symbol *msym;
5135 msym = lookup_minimal_symbol_by_pc (sal->pc);
5137 sal->section = SYMBOL_BFD_SECTION (msym);
5144 break_command (char *arg, int from_tty)
5146 break_command_1 (arg, 0, from_tty);
5150 break_at_finish_command (char *arg, int from_tty)
5152 break_at_finish_command_1 (arg, 0, from_tty);
5156 break_at_finish_at_depth_command (char *arg, int from_tty)
5158 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5162 tbreak_command (char *arg, int from_tty)
5164 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5168 tbreak_at_finish_command (char *arg, int from_tty)
5170 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5174 hbreak_command (char *arg, int from_tty)
5176 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5180 thbreak_command (char *arg, int from_tty)
5182 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5186 stop_command (char *arg, int from_tty)
5188 printf_filtered ("Specify the type of breakpoint to set.\n\
5189 Usage: stop in <function | address>\n\
5194 stopin_command (char *arg, int from_tty)
5198 if (arg == (char *) NULL)
5200 else if (*arg != '*')
5205 /* look for a ':'. If this is a line number specification, then
5206 say it is bad, otherwise, it should be an address or
5207 function/method name */
5208 while (*argptr && !hasColon)
5210 hasColon = (*argptr == ':');
5215 badInput = (*argptr != ':'); /* Not a class::method */
5217 badInput = isdigit (*arg); /* a simple line number */
5221 printf_filtered ("Usage: stop in <function | address>\n");
5223 break_command_1 (arg, 0, from_tty);
5227 stopat_command (char *arg, int from_tty)
5231 if (arg == (char *) NULL || *arg == '*') /* no line number */
5238 /* look for a ':'. If there is a '::' then get out, otherwise
5239 it is probably a line number. */
5240 while (*argptr && !hasColon)
5242 hasColon = (*argptr == ':');
5247 badInput = (*argptr == ':'); /* we have class::method */
5249 badInput = !isdigit (*arg); /* not a line number */
5253 printf_filtered ("Usage: stop at <line>\n");
5255 break_command_1 (arg, 0, from_tty);
5259 /* accessflag: hw_write: watch write,
5260 hw_read: watch read,
5261 hw_access: watch access (read or write) */
5263 watch_command_1 (char *arg, int accessflag, int from_tty)
5265 struct breakpoint *b;
5266 struct symtab_and_line sal;
5267 struct expression *exp;
5268 struct block *exp_valid_block;
5269 struct value *val, *mark;
5270 struct frame_info *frame;
5271 struct frame_info *prev_frame = NULL;
5272 char *exp_start = NULL;
5273 char *exp_end = NULL;
5274 char *tok, *end_tok;
5276 char *cond_start = NULL;
5277 char *cond_end = NULL;
5278 struct expression *cond = NULL;
5279 int i, other_type_used, target_resources_ok = 0;
5280 enum bptype bp_type;
5283 INIT_SAL (&sal); /* initialize to zeroes */
5285 /* Parse arguments. */
5286 innermost_block = NULL;
5288 exp = parse_exp_1 (&arg, 0, 0);
5290 exp_valid_block = innermost_block;
5291 mark = value_mark ();
5292 val = evaluate_expression (exp);
5293 release_value (val);
5294 if (VALUE_LAZY (val))
5295 value_fetch_lazy (val);
5298 while (*tok == ' ' || *tok == '\t')
5302 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5305 toklen = end_tok - tok;
5306 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5308 tok = cond_start = end_tok + 1;
5309 cond = parse_exp_1 (&tok, 0, 0);
5313 error ("Junk at end of command.");
5315 if (accessflag == hw_read)
5316 bp_type = bp_read_watchpoint;
5317 else if (accessflag == hw_access)
5318 bp_type = bp_access_watchpoint;
5320 bp_type = bp_hardware_watchpoint;
5322 mem_cnt = can_use_hardware_watchpoint (val);
5323 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5324 error ("Expression cannot be implemented with read/access watchpoint.");
5327 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5328 target_resources_ok =
5329 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5331 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5332 error ("Target does not support this type of hardware watchpoint.");
5334 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5335 error ("Target can only support one kind of HW watchpoint at a time.");
5338 #if defined(HPUXHPPA)
5339 /* On HP-UX if you set a h/w
5340 watchpoint before the "run" command, the inferior dies with a e.g.,
5341 SIGILL once you start it. I initially believed this was due to a
5342 bad interaction between page protection traps and the initial
5343 startup sequence by the dynamic linker.
5345 However, I tried avoiding that by having HP-UX's implementation of
5346 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5347 yet, which forced slow watches before a "run" or "attach", and it
5348 still fails somewhere in the startup code.
5350 Until I figure out what's happening, I'm disallowing watches altogether
5351 before the "run" or "attach" command. We'll tell the user they must
5352 set watches after getting the program started. */
5353 if (!target_has_execution)
5355 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5358 #endif /* HPUXHPPA */
5360 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5361 watchpoint could not be set. */
5362 if (!mem_cnt || target_resources_ok <= 0)
5363 bp_type = bp_watchpoint;
5365 /* Now set up the breakpoint. */
5366 b = set_raw_breakpoint (sal, bp_type);
5367 set_breakpoint_count (breakpoint_count + 1);
5368 b->number = breakpoint_count;
5369 b->disposition = disp_donttouch;
5371 b->exp_valid_block = exp_valid_block;
5372 b->exp_string = savestring (exp_start, exp_end - exp_start);
5376 b->cond_string = savestring (cond_start, cond_end - cond_start);
5380 frame = block_innermost_frame (exp_valid_block);
5383 prev_frame = get_prev_frame (frame);
5384 get_frame_id (frame, &b->watchpoint_frame);
5388 memset (&b->watchpoint_frame, 0, sizeof (b->watchpoint_frame));
5391 /* If the expression is "local", then set up a "watchpoint scope"
5392 breakpoint at the point where we've left the scope of the watchpoint
5394 if (innermost_block)
5398 struct breakpoint *scope_breakpoint;
5399 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
5400 bp_watchpoint_scope);
5402 scope_breakpoint->enable_state = bp_enabled;
5404 /* Automatically delete the breakpoint when it hits. */
5405 scope_breakpoint->disposition = disp_del;
5407 /* Only break in the proper frame (help with recursion). */
5408 scope_breakpoint->frame = prev_frame->frame;
5410 /* Set the address at which we will stop. */
5411 scope_breakpoint->address = get_frame_pc (prev_frame);
5413 /* The scope breakpoint is related to the watchpoint. We
5414 will need to act on them together. */
5415 b->related_breakpoint = scope_breakpoint;
5418 value_free_to_mark (mark);
5422 /* Return count of locations need to be watched and can be handled
5423 in hardware. If the watchpoint can not be handled
5424 in hardware return zero. */
5426 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5427 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5428 ((BYTE_SIZE) <= (REGISTER_SIZE))
5431 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5432 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5433 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5437 can_use_hardware_watchpoint (struct value *v)
5439 int found_memory_cnt = 0;
5440 struct value *head = v;
5442 /* Did the user specifically forbid us to use hardware watchpoints? */
5443 if (!can_use_hw_watchpoints)
5446 /* Make sure that the value of the expression depends only upon
5447 memory contents, and values computed from them within GDB. If we
5448 find any register references or function calls, we can't use a
5449 hardware watchpoint.
5451 The idea here is that evaluating an expression generates a series
5452 of values, one holding the value of every subexpression. (The
5453 expression a*b+c has five subexpressions: a, b, a*b, c, and
5454 a*b+c.) GDB's values hold almost enough information to establish
5455 the criteria given above --- they identify memory lvalues,
5456 register lvalues, computed values, etcetera. So we can evaluate
5457 the expression, and then scan the chain of values that leaves
5458 behind to decide whether we can detect any possible change to the
5459 expression's final value using only hardware watchpoints.
5461 However, I don't think that the values returned by inferior
5462 function calls are special in any way. So this function may not
5463 notice that an expression involving an inferior function call
5464 can't be watched with hardware watchpoints. FIXME. */
5465 for (; v; v = v->next)
5467 if (VALUE_LVAL (v) == lval_memory)
5470 /* A lazy memory lvalue is one that GDB never needed to fetch;
5471 we either just used its address (e.g., `a' in `a.b') or
5472 we never needed it at all (e.g., `a' in `a,b'). */
5476 /* Ahh, memory we actually used! Check if we can cover
5477 it with hardware watchpoints. */
5478 struct type *vtype = check_typedef (VALUE_TYPE (v));
5480 /* We only watch structs and arrays if user asked for it
5481 explicitly, never if they just happen to appear in a
5482 middle of some value chain. */
5484 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5485 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5487 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5488 int len = TYPE_LENGTH (VALUE_TYPE (v));
5490 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5497 else if (v->lval != not_lval && v->modifiable == 0)
5498 return 0; /* ??? What does this represent? */
5499 else if (v->lval == lval_register)
5500 return 0; /* cannot watch a register with a HW watchpoint */
5503 /* The expression itself looks suitable for using a hardware
5504 watchpoint, but give the target machine a chance to reject it. */
5505 return found_memory_cnt;
5509 watch_command_wrapper (char *arg, int from_tty)
5511 watch_command (arg, from_tty);
5515 watch_command (char *arg, int from_tty)
5517 watch_command_1 (arg, hw_write, from_tty);
5521 rwatch_command_wrapper (char *arg, int from_tty)
5523 rwatch_command (arg, from_tty);
5527 rwatch_command (char *arg, int from_tty)
5529 watch_command_1 (arg, hw_read, from_tty);
5533 awatch_command_wrapper (char *arg, int from_tty)
5535 awatch_command (arg, from_tty);
5539 awatch_command (char *arg, int from_tty)
5541 watch_command_1 (arg, hw_access, from_tty);
5545 /* Helper routines for the until_command routine in infcmd.c. Here
5546 because it uses the mechanisms of breakpoints. */
5548 /* This function is called by fetch_inferior_event via the
5549 cmd_continuation pointer, to complete the until command. It takes
5550 care of cleaning up the temporary breakpoints set up by the until
5553 until_break_command_continuation (struct continuation_arg *arg)
5555 struct cleanup *cleanups;
5557 cleanups = (struct cleanup *) arg->data.pointer;
5558 do_exec_cleanups (cleanups);
5563 until_break_command (char *arg, int from_tty)
5565 struct symtabs_and_lines sals;
5566 struct symtab_and_line sal;
5567 struct frame_info *prev_frame = get_prev_frame (selected_frame);
5568 struct breakpoint *breakpoint;
5569 struct cleanup *old_chain;
5570 struct continuation_arg *arg1;
5573 clear_proceed_status ();
5575 /* Set a breakpoint where the user wants it and at return from
5578 if (default_breakpoint_valid)
5579 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5580 default_breakpoint_line, (char ***) NULL);
5582 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5583 0, (char ***) NULL);
5585 if (sals.nelts != 1)
5586 error ("Couldn't get information on specified line.");
5589 xfree (sals.sals); /* malloc'd, so freed */
5592 error ("Junk at end of arguments.");
5594 resolve_sal_pc (&sal);
5596 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
5598 if (!event_loop_p || !target_can_async_p ())
5599 old_chain = make_cleanup_delete_breakpoint (breakpoint);
5601 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
5603 /* If we are running asynchronously, and the target supports async
5604 execution, we are not waiting for the target to stop, in the call
5605 tp proceed, below. This means that we cannot delete the
5606 brekpoints until the target has actually stopped. The only place
5607 where we get a chance to do that is in fetch_inferior_event, so
5608 we must set things up for that. */
5610 if (event_loop_p && target_can_async_p ())
5612 /* In this case the arg for the continuation is just the point
5613 in the exec_cleanups chain from where to start doing
5614 cleanups, because all the continuation does is the cleanups in
5615 the exec_cleanup_chain. */
5617 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5619 arg1->data.pointer = old_chain;
5621 add_continuation (until_break_command_continuation, arg1);
5624 /* Keep within the current frame */
5628 sal = find_pc_line (prev_frame->pc, 0);
5629 sal.pc = prev_frame->pc;
5630 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
5631 if (!event_loop_p || !target_can_async_p ())
5632 make_cleanup_delete_breakpoint (breakpoint);
5634 make_exec_cleanup_delete_breakpoint (breakpoint);
5637 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5638 /* Do the cleanups now, anly if we are not running asynchronously,
5639 of if we are, but the target is still synchronous. */
5640 if (!event_loop_p || !target_can_async_p ())
5641 do_cleanups (old_chain);
5645 /* These aren't used; I don't konw what they were for. */
5646 /* Set a breakpoint at the catch clause for NAME. */
5648 catch_breakpoint (char *name)
5653 disable_catch_breakpoint (void)
5658 delete_catch_breakpoint (void)
5663 enable_catch_breakpoint (void)
5670 struct sal_chain *next;
5671 struct symtab_and_line sal;
5675 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5676 had been commented out in the v.4.16 sources, and stays
5677 disabled there now because "catch NAME" syntax isn't allowed.
5679 /* This isn't used; I don't know what it was for. */
5680 /* For each catch clause identified in ARGS, run FUNCTION
5681 with that clause as an argument. */
5682 static struct symtabs_and_lines
5683 map_catch_names (char *args, int (*function) ())
5685 register char *p = args;
5687 struct symtabs_and_lines sals;
5689 struct sal_chain *sal_chain = 0;
5693 error_no_arg ("one or more catch names");
5701 /* Don't swallow conditional part. */
5702 if (p1[0] == 'i' && p1[1] == 'f'
5703 && (p1[2] == ' ' || p1[2] == '\t'))
5709 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
5713 if (*p1 && *p1 != ' ' && *p1 != '\t')
5714 error ("Arguments must be catch names.");
5720 struct sal_chain *next = (struct sal_chain *)
5721 alloca (sizeof (struct sal_chain));
5722 next->next = sal_chain;
5723 next->sal = get_catch_sal (p);
5728 printf_unfiltered ("No catch clause for exception %s.\n", p);
5733 while (*p == ' ' || *p == '\t')
5739 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5741 static struct symtabs_and_lines
5742 get_catch_sals (int this_level_only)
5744 register struct blockvector *bl;
5745 register struct block *block;
5746 int index, have_default = 0;
5748 struct symtabs_and_lines sals;
5749 struct sal_chain *sal_chain = 0;
5750 char *blocks_searched;
5752 /* Not sure whether an error message is always the correct response,
5753 but it's better than a core dump. */
5754 if (selected_frame == NULL)
5755 error ("No selected frame.");
5756 block = get_frame_block (selected_frame, 0);
5757 pc = selected_frame->pc;
5763 error ("No symbol table info available.\n");
5765 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
5766 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5767 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5771 CORE_ADDR end = BLOCK_END (block) - 4;
5774 if (bl != blockvector_for_pc (end, &index))
5775 error ("blockvector blotch");
5776 if (BLOCKVECTOR_BLOCK (bl, index) != block)
5777 error ("blockvector botch");
5778 last_index = BLOCKVECTOR_NBLOCKS (bl);
5781 /* Don't print out blocks that have gone by. */
5782 while (index < last_index
5783 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
5786 while (index < last_index
5787 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
5789 if (blocks_searched[index] == 0)
5791 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
5793 register struct symbol *sym;
5795 ALL_BLOCK_SYMBOLS (b, i, sym)
5797 if (STREQ (SYMBOL_NAME (sym), "default"))
5803 if (SYMBOL_CLASS (sym) == LOC_LABEL)
5805 struct sal_chain *next = (struct sal_chain *)
5806 alloca (sizeof (struct sal_chain));
5807 next->next = sal_chain;
5808 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
5813 blocks_searched[index] = 1;
5819 if (sal_chain && this_level_only)
5822 /* After handling the function's top-level block, stop.
5823 Don't continue to its superblock, the block of
5824 per-file symbols. */
5825 if (BLOCK_FUNCTION (block))
5827 block = BLOCK_SUPERBLOCK (block);
5832 struct sal_chain *tmp_chain;
5834 /* Count the number of entries. */
5835 for (index = 0, tmp_chain = sal_chain; tmp_chain;
5836 tmp_chain = tmp_chain->next)
5840 sals.sals = (struct symtab_and_line *)
5841 xmalloc (index * sizeof (struct symtab_and_line));
5842 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
5843 sals.sals[index] = sal_chain->sal;
5850 ep_skip_leading_whitespace (char **s)
5852 if ((s == NULL) || (*s == NULL))
5854 while (isspace (**s))
5858 /* This function examines a string, and attempts to find a token
5859 that might be an event name in the leading characters. If a
5860 possible match is found, a pointer to the last character of
5861 the token is returned. Else, NULL is returned. */
5864 ep_find_event_name_end (char *arg)
5867 char *event_name_end = NULL;
5869 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5873 /* We break out of the loop when we find a token delimiter.
5874 Basically, we're looking for alphanumerics and underscores;
5875 anything else delimites the token. */
5878 if (!isalnum (*s) && (*s != '_'))
5884 return event_name_end;
5888 /* This function attempts to parse an optional "if <cond>" clause
5889 from the arg string. If one is not found, it returns NULL.
5891 Else, it returns a pointer to the condition string. (It does not
5892 attempt to evaluate the string against a particular block.) And,
5893 it updates arg to point to the first character following the parsed
5894 if clause in the arg string. */
5897 ep_parse_optional_if_clause (char **arg)
5901 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5904 /* Skip the "if" keyword. */
5907 /* Skip any extra leading whitespace, and record the start of the
5908 condition string. */
5909 ep_skip_leading_whitespace (arg);
5912 /* Assume that the condition occupies the remainder of the arg string. */
5913 (*arg) += strlen (cond_string);
5918 /* This function attempts to parse an optional filename from the arg
5919 string. If one is not found, it returns NULL.
5921 Else, it returns a pointer to the parsed filename. (This function
5922 makes no attempt to verify that a file of that name exists, or is
5923 accessible.) And, it updates arg to point to the first character
5924 following the parsed filename in the arg string.
5926 Note that clients needing to preserve the returned filename for
5927 future access should copy it to their own buffers. */
5929 ep_parse_optional_filename (char **arg)
5931 static char filename[1024];
5936 if ((*arg_p == '\0') || isspace (*arg_p))
5954 /* Commands to deal with catching events, such as signals, exceptions,
5955 process start/exit, etc. */
5959 catch_fork, catch_vfork
5963 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5964 static void catch_fork_command_1 (catch_fork_kind fork_kind,
5965 char *arg, int tempflag, int from_tty);
5968 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
5971 char *cond_string = NULL;
5973 ep_skip_leading_whitespace (&arg);
5975 /* The allowed syntax is:
5977 catch [v]fork if <cond>
5979 First, check if there's an if clause. */
5980 cond_string = ep_parse_optional_if_clause (&arg);
5982 if ((*arg != '\0') && !isspace (*arg))
5983 error ("Junk at end of arguments.");
5985 /* If this target supports it, create a fork or vfork catchpoint
5986 and enable reporting of such events. */
5990 create_fork_event_catchpoint (tempflag, cond_string);
5993 create_vfork_event_catchpoint (tempflag, cond_string);
5996 error ("unsupported or unknown fork kind; cannot catch it");
6002 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6004 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
6006 char *cond_string = NULL;
6008 ep_skip_leading_whitespace (&arg);
6010 /* The allowed syntax is:
6012 catch exec if <cond>
6014 First, check if there's an if clause. */
6015 cond_string = ep_parse_optional_if_clause (&arg);
6017 if ((*arg != '\0') && !isspace (*arg))
6018 error ("Junk at end of arguments.");
6020 /* If this target supports it, create an exec catchpoint
6021 and enable reporting of such events. */
6022 create_exec_event_catchpoint (tempflag, cond_string);
6026 #if defined(SOLIB_ADD)
6028 catch_load_command_1 (char *arg, int tempflag, int from_tty)
6030 char *dll_pathname = NULL;
6031 char *cond_string = NULL;
6033 ep_skip_leading_whitespace (&arg);
6035 /* The allowed syntax is:
6037 catch load if <cond>
6038 catch load <filename>
6039 catch load <filename> if <cond>
6041 The user is not allowed to specify the <filename> after an
6044 We'll ignore the pathological case of a file named "if".
6046 First, check if there's an if clause. If so, then there
6047 cannot be a filename. */
6048 cond_string = ep_parse_optional_if_clause (&arg);
6050 /* If there was an if clause, then there cannot be a filename.
6051 Else, there might be a filename and an if clause. */
6052 if (cond_string == NULL)
6054 dll_pathname = ep_parse_optional_filename (&arg);
6055 ep_skip_leading_whitespace (&arg);
6056 cond_string = ep_parse_optional_if_clause (&arg);
6059 if ((*arg != '\0') && !isspace (*arg))
6060 error ("Junk at end of arguments.");
6062 /* Create a load breakpoint that only triggers when a load of
6063 the specified dll (or any dll, if no pathname was specified)
6065 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6066 dll_pathname, cond_string);
6070 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6072 char *dll_pathname = NULL;
6073 char *cond_string = NULL;
6075 ep_skip_leading_whitespace (&arg);
6077 /* The allowed syntax is:
6079 catch unload if <cond>
6080 catch unload <filename>
6081 catch unload <filename> if <cond>
6083 The user is not allowed to specify the <filename> after an
6086 We'll ignore the pathological case of a file named "if".
6088 First, check if there's an if clause. If so, then there
6089 cannot be a filename. */
6090 cond_string = ep_parse_optional_if_clause (&arg);
6092 /* If there was an if clause, then there cannot be a filename.
6093 Else, there might be a filename and an if clause. */
6094 if (cond_string == NULL)
6096 dll_pathname = ep_parse_optional_filename (&arg);
6097 ep_skip_leading_whitespace (&arg);
6098 cond_string = ep_parse_optional_if_clause (&arg);
6101 if ((*arg != '\0') && !isspace (*arg))
6102 error ("Junk at end of arguments.");
6104 /* Create an unload breakpoint that only triggers when an unload of
6105 the specified dll (or any dll, if no pathname was specified)
6107 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6108 dll_pathname, cond_string);
6110 #endif /* SOLIB_ADD */
6112 /* Commands to deal with catching exceptions. */
6114 /* Set a breakpoint at the specified callback routine for an
6115 exception event callback */
6118 create_exception_catchpoint (int tempflag, char *cond_string,
6119 enum exception_event_kind ex_event,
6120 struct symtab_and_line *sal)
6122 struct breakpoint *b;
6123 int thread = -1; /* All threads. */
6126 if (!sal) /* no exception support? */
6131 case EX_EVENT_THROW:
6132 bptype = bp_catch_throw;
6134 case EX_EVENT_CATCH:
6135 bptype = bp_catch_catch;
6137 default: /* error condition */
6138 error ("Internal error -- invalid catchpoint kind");
6141 b = set_raw_breakpoint (*sal, bptype);
6142 set_breakpoint_count (breakpoint_count + 1);
6143 b->number = breakpoint_count;
6145 b->cond_string = (cond_string == NULL) ?
6146 NULL : savestring (cond_string, strlen (cond_string));
6148 b->addr_string = NULL;
6149 b->enable_state = bp_enabled;
6150 b->disposition = tempflag ? disp_del : disp_donttouch;
6154 /* Deal with "catch catch" and "catch throw" commands */
6157 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6158 int tempflag, int from_tty)
6160 char *cond_string = NULL;
6161 struct symtab_and_line *sal = NULL;
6163 ep_skip_leading_whitespace (&arg);
6165 cond_string = ep_parse_optional_if_clause (&arg);
6167 if ((*arg != '\0') && !isspace (*arg))
6168 error ("Junk at end of arguments.");
6170 if ((ex_event != EX_EVENT_THROW) &&
6171 (ex_event != EX_EVENT_CATCH))
6172 error ("Unsupported or unknown exception event; cannot catch it");
6174 /* See if we can find a callback routine */
6175 sal = target_enable_exception_callback (ex_event, 1);
6179 /* We have callbacks from the runtime system for exceptions.
6180 Set a breakpoint on the sal found, if no errors */
6181 if (sal != (struct symtab_and_line *) -1)
6182 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6184 return; /* something went wrong with setting up callbacks */
6188 /* No callbacks from runtime system for exceptions.
6189 Try GNU C++ exception breakpoints using labels in debug info. */
6190 if (ex_event == EX_EVENT_CATCH)
6192 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
6194 else if (ex_event == EX_EVENT_THROW)
6196 /* Set a breakpoint on __raise_exception () */
6198 warning ("Unsupported with this platform/compiler combination.");
6199 warning ("Perhaps you can achieve the effect you want by setting");
6200 warning ("a breakpoint on __raise_exception().");
6205 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6206 inside a catch_errors */
6209 cover_target_enable_exception_callback (PTR arg)
6211 args_for_catchpoint_enable *args = arg;
6212 struct symtab_and_line *sal;
6213 sal = target_enable_exception_callback (args->kind, args->enable_p);
6216 else if (sal == (struct symtab_and_line *) -1)
6219 return 1; /*is valid */
6224 /* This is the original v.4.16 and earlier version of the
6225 catch_command_1() function. Now that other flavours of "catch"
6226 have been introduced, and since exception handling can be handled
6227 in other ways (through target ops) also, this is used only for the
6228 GNU C++ exception handling system.
6229 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6230 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6231 there was no code in GDB 4.16 for "catch throw".
6233 Called from catch_exception_command_1 () */
6237 handle_gnu_4_16_catch_command (char *arg, int tempflag, int from_tty)
6239 /* First, translate ARG into something we can deal with in terms
6242 struct symtabs_and_lines sals;
6243 struct symtab_and_line sal;
6244 register struct expression *cond = 0;
6245 register struct breakpoint *b;
6249 INIT_SAL (&sal); /* initialize to zeroes */
6251 /* If no arg given, or if first arg is 'if ', all active catch clauses
6252 are breakpointed. */
6254 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
6255 && (arg[2] == ' ' || arg[2] == '\t')))
6257 /* Grab all active catch clauses. */
6258 sals = get_catch_sals (0);
6262 /* Grab selected catch clauses. */
6263 error ("catch NAME not implemented");
6266 /* Not sure why this code has been disabled. I'm leaving
6267 it disabled. We can never come here now anyway
6268 since we don't allow the "catch NAME" syntax.
6271 /* This isn't used; I don't know what it was for. */
6272 sals = map_catch_names (arg, catch_breakpoint);
6280 for (i = 0; i < sals.nelts; i++)
6282 resolve_sal_pc (&sals.sals[i]);
6286 if (arg[0] == 'i' && arg[1] == 'f'
6287 && (arg[2] == ' ' || arg[2] == '\t'))
6288 cond = parse_exp_1 ((arg += 2, &arg),
6289 block_for_pc (sals.sals[i].pc), 0);
6291 error ("Junk at end of arguments.");
6296 for (i = 0; i < sals.nelts; i++)
6301 describe_other_breakpoints (sal.pc, sal.section);
6303 /* Important -- this is an ordinary breakpoint. For platforms
6304 with callback support for exceptions,
6305 create_exception_catchpoint() will create special bp types
6306 (bp_catch_catch and bp_catch_throw), and there is code in
6307 insert_breakpoints() and elsewhere that depends on that. */
6308 b = set_raw_breakpoint (sal, bp_breakpoint);
6309 set_breakpoint_count (breakpoint_count + 1);
6310 b->number = breakpoint_count;
6313 b->enable_state = bp_enabled;
6314 b->disposition = tempflag ? disp_del : disp_donttouch;
6321 warning ("Multiple breakpoints were set.");
6322 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
6328 catch_command_1 (char *arg, int tempflag, int from_tty)
6331 /* The first argument may be an event name, such as "start" or "load".
6332 If so, then handle it as such. If it doesn't match an event name,
6333 then attempt to interpret it as an exception name. (This latter is
6334 the v4.16-and-earlier GDB meaning of the "catch" command.)
6336 First, try to find the bounds of what might be an event name. */
6337 char *arg1_start = arg;
6341 if (arg1_start == NULL)
6343 /* Old behaviour was to use pre-v-4.16 syntax */
6344 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6346 /* Now, this is not allowed */
6347 error ("Catch requires an event name.");
6350 arg1_end = ep_find_event_name_end (arg1_start);
6351 if (arg1_end == NULL)
6352 error ("catch requires an event");
6353 arg1_length = arg1_end + 1 - arg1_start;
6355 /* Try to match what we found against known event names. */
6356 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6358 error ("Catch of signal not yet implemented");
6360 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6362 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6363 tempflag, from_tty);
6365 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6367 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6368 tempflag, from_tty);
6370 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6372 error ("Catch of thread_start not yet implemented");
6374 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6376 error ("Catch of thread_exit not yet implemented");
6378 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6380 error ("Catch of thread_join not yet implemented");
6382 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6384 error ("Catch of start not yet implemented");
6386 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6388 error ("Catch of exit not yet implemented");
6390 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6392 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6393 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6395 error ("Catch of fork not yet implemented");
6398 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6400 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6401 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6403 error ("Catch of vfork not yet implemented");
6406 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6408 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6409 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6411 error ("Catch of exec not yet implemented");
6414 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6416 #if defined(SOLIB_ADD)
6417 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6419 error ("Catch of load not implemented");
6422 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6424 #if defined(SOLIB_ADD)
6425 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6427 error ("Catch of load not implemented");
6430 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6432 error ("Catch of stop not yet implemented");
6435 /* This doesn't appear to be an event name */
6439 /* Pre-v.4.16 behaviour was to treat the argument
6440 as the name of an exception */
6441 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6442 /* Now this is not allowed */
6443 error ("Unknown event kind specified for catch");
6448 /* Used by the gui, could be made a worker for other things. */
6451 set_breakpoint_sal (struct symtab_and_line sal)
6453 struct breakpoint *b;
6454 b = set_raw_breakpoint (sal, bp_breakpoint);
6455 set_breakpoint_count (breakpoint_count + 1);
6456 b->number = breakpoint_count;
6463 /* These aren't used; I don't know what they were for. */
6464 /* Disable breakpoints on all catch clauses described in ARGS. */
6466 disable_catch (char *args)
6468 /* Map the disable command to catch clauses described in ARGS. */
6471 /* Enable breakpoints on all catch clauses described in ARGS. */
6473 enable_catch (char *args)
6475 /* Map the disable command to catch clauses described in ARGS. */
6478 /* Delete breakpoints on all catch clauses in the active scope. */
6480 delete_catch (char *args)
6482 /* Map the delete command to catch clauses described in ARGS. */
6487 catch_command (char *arg, int from_tty)
6489 catch_command_1 (arg, 0, from_tty);
6494 tcatch_command (char *arg, int from_tty)
6496 catch_command_1 (arg, 1, from_tty);
6499 /* Delete breakpoints by address or line. */
6502 clear_command (char *arg, int from_tty)
6504 struct breakpoint *b, *tmp, *prev, *found;
6506 struct symtabs_and_lines sals;
6507 struct symtab_and_line sal;
6512 sals = decode_line_spec (arg, 1);
6517 sals.sals = (struct symtab_and_line *)
6518 xmalloc (sizeof (struct symtab_and_line));
6519 make_cleanup (xfree, sals.sals);
6520 INIT_SAL (&sal); /* initialize to zeroes */
6521 sal.line = default_breakpoint_line;
6522 sal.symtab = default_breakpoint_symtab;
6523 sal.pc = default_breakpoint_address;
6524 if (sal.symtab == 0)
6525 error ("No source file specified.");
6533 /* For each line spec given, delete bps which correspond
6534 to it. Do it in two passes, solely to preserve the current
6535 behavior that from_tty is forced true if we delete more than
6539 for (i = 0; i < sals.nelts; i++)
6541 /* If exact pc given, clear bpts at that pc.
6542 If line given (pc == 0), clear all bpts on specified line.
6543 If defaulting, clear all bpts on default line
6546 defaulting sal.pc != 0 tests to do
6551 1 0 <can't happen> */
6556 /* Find all matching breakpoints, remove them from the
6557 breakpoint chain, and add them to the 'found' chain. */
6558 ALL_BREAKPOINTS_SAFE (b, tmp)
6560 /* Are we going to delete b? */
6561 if (b->type != bp_none
6562 && b->type != bp_watchpoint
6563 && b->type != bp_hardware_watchpoint
6564 && b->type != bp_read_watchpoint
6565 && b->type != bp_access_watchpoint
6566 /* Not if b is a watchpoint of any sort... */
6567 && (((sal.pc && (b->address == sal.pc))
6568 && (!section_is_overlay (b->section)
6569 || b->section == sal.section))
6570 /* Yes, if sal.pc matches b (modulo overlays). */
6571 || ((default_match || (0 == sal.pc))
6572 && b->source_file != NULL
6573 && sal.symtab != NULL
6574 && STREQ (b->source_file, sal.symtab->filename)
6575 && b->line_number == sal.line)))
6576 /* Yes, if sal source file and line matches b. */
6578 /* Remove it from breakpoint_chain... */
6579 if (b == breakpoint_chain)
6581 /* b is at the head of the list */
6582 breakpoint_chain = b->next;
6586 prev->next = b->next;
6588 /* And add it to 'found' chain. */
6594 /* Keep b, and keep a pointer to it. */
6599 /* Now go thru the 'found' chain and delete them. */
6603 error ("No breakpoint at %s.", arg);
6605 error ("No breakpoint at this line.");
6609 from_tty = 1; /* Always report if deleted more than one */
6611 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6612 breakpoints_changed ();
6616 printf_unfiltered ("%d ", found->number);
6618 delete_breakpoint (found);
6622 putchar_unfiltered ('\n');
6625 /* Delete breakpoint in BS if they are `delete' breakpoints and
6626 all breakpoints that are marked for deletion, whether hit or not.
6627 This is called after any breakpoint is hit, or after errors. */
6630 breakpoint_auto_delete (bpstat bs)
6632 struct breakpoint *b, *temp;
6634 for (; bs; bs = bs->next)
6635 if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del
6637 delete_breakpoint (bs->breakpoint_at);
6639 ALL_BREAKPOINTS_SAFE (b, temp)
6641 if (b->disposition == disp_del_at_next_stop)
6642 delete_breakpoint (b);
6646 /* Delete a breakpoint and clean up all traces of it in the data
6650 delete_breakpoint (struct breakpoint *bpt)
6652 register struct breakpoint *b;
6656 error ("Internal error (attempted to delete a NULL breakpoint)");
6659 /* Has this bp already been deleted? This can happen because multiple
6660 lists can hold pointers to bp's. bpstat lists are especial culprits.
6662 One example of this happening is a watchpoint's scope bp. When the
6663 scope bp triggers, we notice that the watchpoint is out of scope, and
6664 delete it. We also delete its scope bp. But the scope bp is marked
6665 "auto-deleting", and is already on a bpstat. That bpstat is then
6666 checked for auto-deleting bp's, which are deleted.
6668 A real solution to this problem might involve reference counts in bp's,
6669 and/or giving them pointers back to their referencing bpstat's, and
6670 teaching delete_breakpoint to only free a bp's storage when no more
6671 references were extent. A cheaper bandaid was chosen. */
6672 if (bpt->type == bp_none)
6675 if (delete_breakpoint_hook)
6676 delete_breakpoint_hook (bpt);
6677 breakpoint_delete_event (bpt->number);
6680 remove_breakpoint (bpt, mark_inserted);
6682 if (breakpoint_chain == bpt)
6683 breakpoint_chain = bpt->next;
6685 /* If we have callback-style exception catchpoints, don't go through
6686 the adjustments to the C++ runtime library etc. if the inferior
6687 isn't actually running. target_enable_exception_callback for a
6688 null target ops vector gives an undesirable error message, so we
6689 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6690 exceptions are supported in this way, it's OK for now. FIXME */
6691 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6693 static char message1[] = "Error in deleting catchpoint %d:\n";
6694 static char message[sizeof (message1) + 30];
6695 args_for_catchpoint_enable args;
6697 /* Format possible error msg */
6698 sprintf (message, message1, bpt->number);
6699 args.kind = bpt->type == bp_catch_catch ?
6700 EX_EVENT_CATCH : EX_EVENT_THROW;
6702 catch_errors (cover_target_enable_exception_callback, &args,
6703 message, RETURN_MASK_ALL);
6710 b->next = bpt->next;
6714 check_duplicates (bpt);
6715 /* If this breakpoint was inserted, and there is another breakpoint
6716 at the same address, we need to insert the other breakpoint. */
6718 && bpt->type != bp_hardware_watchpoint
6719 && bpt->type != bp_read_watchpoint
6720 && bpt->type != bp_access_watchpoint
6721 && bpt->type != bp_catch_fork
6722 && bpt->type != bp_catch_vfork
6723 && bpt->type != bp_catch_exec)
6726 if (b->address == bpt->address
6727 && b->section == bpt->section
6729 && b->enable_state != bp_disabled
6730 && b->enable_state != bp_shlib_disabled
6731 && b->enable_state != bp_call_disabled)
6735 /* We should never reach this point if there is a permanent
6736 breakpoint at the same address as the one being deleted.
6737 If there is a permanent breakpoint somewhere, it should
6738 always be the only one inserted. */
6739 if (b->enable_state == bp_permanent)
6740 internal_error (__FILE__, __LINE__,
6741 "another breakpoint was inserted on top of "
6742 "a permanent breakpoint");
6744 if (b->type == bp_hardware_breakpoint)
6745 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6747 val = target_insert_breakpoint (b->address, b->shadow_contents);
6749 /* If there was an error in the insert, print a message, then stop execution. */
6752 struct ui_file *tmp_error_stream = mem_fileopen ();
6753 make_cleanup_ui_file_delete (tmp_error_stream);
6756 if (b->type == bp_hardware_breakpoint)
6758 fprintf_unfiltered (tmp_error_stream,
6759 "Cannot insert hardware breakpoint %d.\n"
6760 "You may have requested too many hardware breakpoints.\n",
6765 fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number);
6766 fprintf_filtered (tmp_error_stream, "Error accessing memory address ");
6767 print_address_numeric (b->address, 1, tmp_error_stream);
6768 fprintf_filtered (tmp_error_stream, ": %s.\n",
6769 safe_strerror (val));
6772 fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process.");
6773 target_terminal_ours_for_output ();
6774 error_stream(tmp_error_stream);
6781 free_command_lines (&bpt->commands);
6784 if (bpt->cond_string != NULL)
6785 xfree (bpt->cond_string);
6786 if (bpt->addr_string != NULL)
6787 xfree (bpt->addr_string);
6788 if (bpt->exp != NULL)
6790 if (bpt->exp_string != NULL)
6791 xfree (bpt->exp_string);
6792 if (bpt->val != NULL)
6793 value_free (bpt->val);
6794 if (bpt->source_file != NULL)
6795 xfree (bpt->source_file);
6796 if (bpt->dll_pathname != NULL)
6797 xfree (bpt->dll_pathname);
6798 if (bpt->triggered_dll_pathname != NULL)
6799 xfree (bpt->triggered_dll_pathname);
6800 if (bpt->exec_pathname != NULL)
6801 xfree (bpt->exec_pathname);
6803 /* Be sure no bpstat's are pointing at it after it's been freed. */
6804 /* FIXME, how can we find all bpstat's?
6805 We just check stop_bpstat for now. */
6806 for (bs = stop_bpstat; bs; bs = bs->next)
6807 if (bs->breakpoint_at == bpt)
6809 bs->breakpoint_at = NULL;
6811 /* bs->commands will be freed later. */
6813 /* On the chance that someone will soon try again to delete this same
6814 bp, we mark it as deleted before freeing its storage. */
6815 bpt->type = bp_none;
6821 do_delete_breakpoint_cleanup (void *b)
6823 delete_breakpoint (b);
6827 make_cleanup_delete_breakpoint (struct breakpoint *b)
6829 return make_cleanup (do_delete_breakpoint_cleanup, b);
6833 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
6835 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
6839 delete_command (char *arg, int from_tty)
6841 struct breakpoint *b, *temp;
6847 int breaks_to_delete = 0;
6849 /* Delete all breakpoints if no argument.
6850 Do not delete internal or call-dummy breakpoints, these
6851 have to be deleted with an explicit breakpoint number argument. */
6854 if (b->type != bp_call_dummy &&
6855 b->type != bp_shlib_event &&
6856 b->type != bp_thread_event &&
6857 b->type != bp_overlay_event &&
6859 breaks_to_delete = 1;
6862 /* Ask user only if there are some breakpoints to delete. */
6864 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6866 ALL_BREAKPOINTS_SAFE (b, temp)
6868 if (b->type != bp_call_dummy &&
6869 b->type != bp_shlib_event &&
6870 b->type != bp_thread_event &&
6871 b->type != bp_overlay_event &&
6873 delete_breakpoint (b);
6878 map_breakpoint_numbers (arg, delete_breakpoint);
6881 /* Reset a breakpoint given it's struct breakpoint * BINT.
6882 The value we return ends up being the return value from catch_errors.
6883 Unused in this case. */
6886 breakpoint_re_set_one (PTR bint)
6888 /* get past catch_errs */
6889 struct breakpoint *b = (struct breakpoint *) bint;
6892 struct symtabs_and_lines sals;
6894 enum enable_state save_enable;
6899 warning ("attempted to reset apparently deleted breakpoint #%d?",
6903 case bp_hardware_breakpoint:
6905 case bp_catch_unload:
6906 if (b->addr_string == NULL)
6908 /* Anything without a string can't be re-set. */
6909 delete_breakpoint (b);
6912 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6914 ``And a hack it is, although Apple's Darwin version of GDB
6915 contains an almost identical hack to implement a "future
6916 break" command. It seems to work in many real world cases,
6917 but it is easy to come up with a test case where the patch
6918 doesn't help at all.''
6920 ``It seems that the way GDB implements breakpoints - in -
6921 shared - libraries was designed for a.out shared library
6922 systems (SunOS 4) where shared libraries were loaded at a
6923 fixed address in memory. Since ELF shared libraries can (and
6924 will) be loaded at any address in memory, things break.
6925 Fixing this is not trivial. Therefore, I'm not sure whether
6926 we should add this hack to the branch only. I cannot
6927 guarantee that things will be fixed on the trunk in the near
6930 In case we have a problem, disable this breakpoint. We'll
6931 restore its status if we succeed. Don't disable a
6932 shlib_disabled breakpoint though. There's a fair chance we
6933 can't re-set it if the shared library it's in hasn't been
6935 save_enable = b->enable_state;
6936 if (b->enable_state != bp_shlib_disabled)
6937 b->enable_state = bp_disabled;
6939 set_language (b->language);
6940 input_radix = b->input_radix;
6942 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
6943 for (i = 0; i < sals.nelts; i++)
6945 resolve_sal_pc (&sals.sals[i]);
6947 /* Reparse conditions, they might contain references to the
6949 if (b->cond_string != NULL)
6954 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6957 /* We need to re-set the breakpoint if the address changes... */
6958 if (b->address != sals.sals[i].pc
6959 /* ...or new and old breakpoints both have source files, and
6960 the source file name or the line number changes... */
6961 || (b->source_file != NULL
6962 && sals.sals[i].symtab != NULL
6963 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6964 || b->line_number != sals.sals[i].line)
6966 /* ...or we switch between having a source file and not having
6968 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6971 if (b->source_file != NULL)
6972 xfree (b->source_file);
6973 if (sals.sals[i].symtab == NULL)
6974 b->source_file = NULL;
6977 savestring (sals.sals[i].symtab->filename,
6978 strlen (sals.sals[i].symtab->filename));
6979 b->line_number = sals.sals[i].line;
6980 b->address = sals.sals[i].pc;
6982 /* Used to check for duplicates here, but that can
6983 cause trouble, as it doesn't check for disabled
6988 /* Might be better to do this just once per breakpoint_re_set,
6989 rather than once for every breakpoint. */
6990 breakpoints_changed ();
6992 b->section = sals.sals[i].section;
6993 b->enable_state = save_enable; /* Restore it, this worked. */
6996 /* Now that this is re-enabled, check_duplicates
6998 check_duplicates (b);
7005 case bp_hardware_watchpoint:
7006 case bp_read_watchpoint:
7007 case bp_access_watchpoint:
7008 innermost_block = NULL;
7009 /* The issue arises of what context to evaluate this in. The
7010 same one as when it was set, but what does that mean when
7011 symbols have been re-read? We could save the filename and
7012 functionname, but if the context is more local than that, the
7013 best we could do would be something like how many levels deep
7014 and which index at that particular level, but that's going to
7015 be less stable than filenames or function names. */
7017 /* So for now, just use a global context. */
7020 b->exp = parse_expression (b->exp_string);
7021 b->exp_valid_block = innermost_block;
7022 mark = value_mark ();
7024 value_free (b->val);
7025 b->val = evaluate_expression (b->exp);
7026 release_value (b->val);
7027 if (VALUE_LAZY (b->val))
7028 value_fetch_lazy (b->val);
7030 if (b->cond_string != NULL)
7035 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7037 if (b->enable_state == bp_enabled)
7039 value_free_to_mark (mark);
7041 case bp_catch_catch:
7042 case bp_catch_throw:
7044 /* We needn't really do anything to reset these, since the mask
7045 that requests them is unaffected by e.g., new libraries being
7048 case bp_catch_vfork:
7053 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
7055 /* Delete longjmp and overlay event breakpoints; they will be
7056 reset later by breakpoint_re_set. */
7058 case bp_longjmp_resume:
7059 case bp_overlay_event:
7060 delete_breakpoint (b);
7063 /* This breakpoint is special, it's set up when the inferior
7064 starts and we really don't want to touch it. */
7065 case bp_shlib_event:
7067 /* Like bp_shlib_event, this breakpoint type is special.
7068 Once it is set up, we do not want to touch it. */
7069 case bp_thread_event:
7071 /* Keep temporary breakpoints, which can be encountered when we step
7072 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7073 Otherwise these should have been blown away via the cleanup chain
7074 or by breakpoint_init_inferior when we rerun the executable. */
7077 case bp_watchpoint_scope:
7079 case bp_step_resume:
7086 /* Re-set all breakpoints after symbols have been re-loaded. */
7088 breakpoint_re_set (void)
7090 struct breakpoint *b, *temp;
7091 enum language save_language;
7092 int save_input_radix;
7093 static char message1[] = "Error in re-setting breakpoint %d:\n";
7094 char message[sizeof (message1) + 30 /* slop */ ];
7096 save_language = current_language->la_language;
7097 save_input_radix = input_radix;
7098 ALL_BREAKPOINTS_SAFE (b, temp)
7100 /* Format possible error msg */
7101 sprintf (message, message1, b->number);
7102 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7104 set_language (save_language);
7105 input_radix = save_input_radix;
7107 if (GET_LONGJMP_TARGET_P ())
7109 create_longjmp_breakpoint ("longjmp");
7110 create_longjmp_breakpoint ("_longjmp");
7111 create_longjmp_breakpoint ("siglongjmp");
7112 create_longjmp_breakpoint ("_siglongjmp");
7113 create_longjmp_breakpoint (NULL);
7116 create_overlay_event_breakpoint ("_ovly_debug_event");
7119 /* Reset the thread number of this breakpoint:
7121 - If the breakpoint is for all threads, leave it as-is.
7122 - Else, reset it to the current thread for inferior_ptid. */
7124 breakpoint_re_set_thread (struct breakpoint *b)
7126 if (b->thread != -1)
7128 if (in_thread_list (inferior_ptid))
7129 b->thread = pid_to_thread_id (inferior_ptid);
7133 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7134 If from_tty is nonzero, it prints a message to that effect,
7135 which ends with a period (no newline). */
7138 set_ignore_count (int bptnum, int count, int from_tty)
7140 register struct breakpoint *b;
7146 if (b->number == bptnum)
7148 b->ignore_count = count;
7152 printf_filtered ("Will stop next time breakpoint %d is reached.",
7154 else if (count == 1)
7155 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7158 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7161 breakpoints_changed ();
7162 breakpoint_modify_event (b->number);
7166 error ("No breakpoint number %d.", bptnum);
7169 /* Clear the ignore counts of all breakpoints. */
7171 breakpoint_clear_ignore_counts (void)
7173 struct breakpoint *b;
7176 b->ignore_count = 0;
7179 /* Command to set ignore-count of breakpoint N to COUNT. */
7182 ignore_command (char *args, int from_tty)
7188 error_no_arg ("a breakpoint number");
7190 num = get_number (&p);
7192 error ("bad breakpoint number: '%s'", args);
7194 error ("Second argument (specified ignore-count) is missing.");
7196 set_ignore_count (num,
7197 longest_to_int (value_as_long (parse_and_eval (p))),
7200 printf_filtered ("\n");
7203 /* Call FUNCTION on each of the breakpoints
7204 whose numbers are given in ARGS. */
7207 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7209 register char *p = args;
7212 register struct breakpoint *b, *tmp;
7216 error_no_arg ("one or more breakpoint numbers");
7223 num = get_number_or_range (&p1);
7226 warning ("bad breakpoint number at or near '%s'", p);
7230 ALL_BREAKPOINTS_SAFE (b, tmp)
7231 if (b->number == num)
7233 struct breakpoint *related_breakpoint = b->related_breakpoint;
7236 if (related_breakpoint)
7237 function (related_breakpoint);
7241 printf_unfiltered ("No breakpoint number %d.\n", num);
7247 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7248 If from_tty is nonzero, it prints a message to that effect,
7249 which ends with a period (no newline). */
7252 disable_breakpoint (struct breakpoint *bpt)
7254 /* Never disable a watchpoint scope breakpoint; we want to
7255 hit them when we leave scope so we can delete both the
7256 watchpoint and its scope breakpoint at that time. */
7257 if (bpt->type == bp_watchpoint_scope)
7260 /* You can't disable permanent breakpoints. */
7261 if (bpt->enable_state == bp_permanent)
7264 bpt->enable_state = bp_disabled;
7266 check_duplicates (bpt);
7268 if (modify_breakpoint_hook)
7269 modify_breakpoint_hook (bpt);
7270 breakpoint_modify_event (bpt->number);
7275 disable_command (char *args, int from_tty)
7277 register struct breakpoint *bpt;
7279 ALL_BREAKPOINTS (bpt)
7283 warning ("attempted to disable apparently deleted breakpoint #%d?",
7288 case bp_catch_unload:
7290 case bp_catch_vfork:
7292 case bp_catch_catch:
7293 case bp_catch_throw:
7294 case bp_hardware_breakpoint:
7296 case bp_hardware_watchpoint:
7297 case bp_read_watchpoint:
7298 case bp_access_watchpoint:
7299 disable_breakpoint (bpt);
7304 map_breakpoint_numbers (args, disable_breakpoint);
7308 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7310 struct frame_info *save_selected_frame = NULL;
7311 int save_selected_frame_level = -1;
7312 int target_resources_ok, other_type_used;
7315 if (bpt->type == bp_hardware_breakpoint)
7318 i = hw_breakpoint_used_count ();
7319 target_resources_ok =
7320 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7322 if (target_resources_ok == 0)
7323 error ("No hardware breakpoint support in the target.");
7324 else if (target_resources_ok < 0)
7325 error ("Hardware breakpoints used exceeds limit.");
7328 if (bpt->enable_state != bp_permanent)
7329 bpt->enable_state = bp_enabled;
7330 bpt->disposition = disposition;
7331 check_duplicates (bpt);
7332 breakpoints_changed ();
7334 if (bpt->type == bp_watchpoint ||
7335 bpt->type == bp_hardware_watchpoint ||
7336 bpt->type == bp_read_watchpoint ||
7337 bpt->type == bp_access_watchpoint)
7339 if (bpt->exp_valid_block != NULL)
7341 struct frame_info *fr =
7342 fr = frame_find_by_id (bpt->watchpoint_frame);
7346 Cannot enable watchpoint %d because the block in which its expression\n\
7347 is valid is not currently in scope.\n", bpt->number);
7348 bpt->enable_state = bp_disabled;
7352 save_selected_frame = selected_frame;
7353 save_selected_frame_level = frame_relative_level (selected_frame);
7357 value_free (bpt->val);
7358 mark = value_mark ();
7359 bpt->val = evaluate_expression (bpt->exp);
7360 release_value (bpt->val);
7361 if (VALUE_LAZY (bpt->val))
7362 value_fetch_lazy (bpt->val);
7364 if (bpt->type == bp_hardware_watchpoint ||
7365 bpt->type == bp_read_watchpoint ||
7366 bpt->type == bp_access_watchpoint)
7368 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7369 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7371 /* Hack around 'unused var' error for some targets here */
7373 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7374 bpt->type, i + mem_cnt, other_type_used);
7375 /* we can consider of type is bp_hardware_watchpoint, convert to
7376 bp_watchpoint in the following condition */
7377 if (target_resources_ok < 0)
7380 Cannot enable watchpoint %d because target watch resources\n\
7381 have been allocated for other watchpoints.\n", bpt->number);
7382 bpt->enable_state = bp_disabled;
7383 value_free_to_mark (mark);
7388 if (save_selected_frame_level >= 0)
7389 select_frame (save_selected_frame);
7390 value_free_to_mark (mark);
7392 if (modify_breakpoint_hook)
7393 modify_breakpoint_hook (bpt);
7394 breakpoint_modify_event (bpt->number);
7398 enable_breakpoint (struct breakpoint *bpt)
7400 do_enable_breakpoint (bpt, bpt->disposition);
7403 /* The enable command enables the specified breakpoints (or all defined
7404 breakpoints) so they once again become (or continue to be) effective
7405 in stopping the inferior. */
7409 enable_command (char *args, int from_tty)
7411 register struct breakpoint *bpt;
7413 ALL_BREAKPOINTS (bpt)
7417 warning ("attempted to enable apparently deleted breakpoint #%d?",
7422 case bp_catch_unload:
7424 case bp_catch_vfork:
7426 case bp_catch_catch:
7427 case bp_catch_throw:
7428 case bp_hardware_breakpoint:
7430 case bp_hardware_watchpoint:
7431 case bp_read_watchpoint:
7432 case bp_access_watchpoint:
7433 enable_breakpoint (bpt);
7438 map_breakpoint_numbers (args, enable_breakpoint);
7442 enable_once_breakpoint (struct breakpoint *bpt)
7444 do_enable_breakpoint (bpt, disp_disable);
7449 enable_once_command (char *args, int from_tty)
7451 map_breakpoint_numbers (args, enable_once_breakpoint);
7455 enable_delete_breakpoint (struct breakpoint *bpt)
7457 do_enable_breakpoint (bpt, disp_del);
7462 enable_delete_command (char *args, int from_tty)
7464 map_breakpoint_numbers (args, enable_delete_breakpoint);
7467 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7469 struct symtabs_and_lines
7470 decode_line_spec_1 (char *string, int funfirstline)
7472 struct symtabs_and_lines sals;
7474 error ("Empty line specification.");
7475 if (default_breakpoint_valid)
7476 sals = decode_line_1 (&string, funfirstline,
7477 default_breakpoint_symtab,
7478 default_breakpoint_line,
7481 sals = decode_line_1 (&string, funfirstline,
7482 (struct symtab *) NULL, 0, (char ***) NULL);
7484 error ("Junk at end of line specification: %s", string);
7489 _initialize_breakpoint (void)
7491 struct cmd_list_element *c;
7493 breakpoint_chain = 0;
7494 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7495 before a breakpoint is set. */
7496 breakpoint_count = 0;
7498 add_com ("ignore", class_breakpoint, ignore_command,
7499 "Set ignore-count of breakpoint number N to COUNT.\n\
7500 Usage is `ignore N COUNT'.");
7502 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7504 add_com ("commands", class_breakpoint, commands_command,
7505 "Set commands to be executed when a breakpoint is hit.\n\
7506 Give breakpoint number as argument after \"commands\".\n\
7507 With no argument, the targeted breakpoint is the last one set.\n\
7508 The commands themselves follow starting on the next line.\n\
7509 Type a line containing \"end\" to indicate the end of them.\n\
7510 Give \"silent\" as the first line to make the breakpoint silent;\n\
7511 then no output is printed when it is hit, except what the commands print.");
7513 add_com ("condition", class_breakpoint, condition_command,
7514 "Specify breakpoint number N to break only if COND is true.\n\
7515 Usage is `condition N COND', where N is an integer and COND is an\n\
7516 expression to be evaluated whenever breakpoint N is reached.");
7518 c = add_com ("tbreak", class_breakpoint, tbreak_command,
7519 "Set a temporary breakpoint. Args like \"break\" command.\n\
7520 Like \"break\" except the breakpoint is only temporary,\n\
7521 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7522 by using \"enable delete\" on the breakpoint number.");
7523 set_cmd_completer (c, location_completer);
7525 c = add_com ("hbreak", class_breakpoint, hbreak_command,
7526 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7527 Like \"break\" except the breakpoint requires hardware support,\n\
7528 some target hardware may not have this support.");
7529 set_cmd_completer (c, location_completer);
7531 c = add_com ("thbreak", class_breakpoint, thbreak_command,
7532 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7533 Like \"hbreak\" except the breakpoint is only temporary,\n\
7534 so it will be deleted when hit.");
7535 set_cmd_completer (c, location_completer);
7537 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7538 "Enable some breakpoints.\n\
7539 Give breakpoint numbers (separated by spaces) as arguments.\n\
7540 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7541 This is used to cancel the effect of the \"disable\" command.\n\
7542 With a subcommand you can enable temporarily.",
7543 &enablelist, "enable ", 1, &cmdlist);
7545 add_com ("ab", class_breakpoint, enable_command,
7546 "Enable some breakpoints.\n\
7547 Give breakpoint numbers (separated by spaces) as arguments.\n\
7548 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7549 This is used to cancel the effect of the \"disable\" command.\n\
7550 With a subcommand you can enable temporarily.");
7552 add_com_alias ("en", "enable", class_breakpoint, 1);
7554 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7555 "Enable some breakpoints.\n\
7556 Give breakpoint numbers (separated by spaces) as arguments.\n\
7557 This is used to cancel the effect of the \"disable\" command.\n\
7558 May be abbreviated to simply \"enable\".\n",
7559 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7561 add_cmd ("once", no_class, enable_once_command,
7562 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7563 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7566 add_cmd ("delete", no_class, enable_delete_command,
7567 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7568 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7571 add_cmd ("delete", no_class, enable_delete_command,
7572 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7573 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7576 add_cmd ("once", no_class, enable_once_command,
7577 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7578 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7581 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7582 "Disable some breakpoints.\n\
7583 Arguments are breakpoint numbers with spaces in between.\n\
7584 To disable all breakpoints, give no argument.\n\
7585 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7586 &disablelist, "disable ", 1, &cmdlist);
7587 add_com_alias ("dis", "disable", class_breakpoint, 1);
7588 add_com_alias ("disa", "disable", class_breakpoint, 1);
7590 add_com ("sb", class_breakpoint, disable_command,
7591 "Disable some breakpoints.\n\
7592 Arguments are breakpoint numbers with spaces in between.\n\
7593 To disable all breakpoints, give no argument.\n\
7594 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7596 add_cmd ("breakpoints", class_alias, disable_command,
7597 "Disable some breakpoints.\n\
7598 Arguments are breakpoint numbers with spaces in between.\n\
7599 To disable all breakpoints, give no argument.\n\
7600 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7601 This command may be abbreviated \"disable\".",
7604 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7605 "Delete some breakpoints or auto-display expressions.\n\
7606 Arguments are breakpoint numbers with spaces in between.\n\
7607 To delete all breakpoints, give no argument.\n\
7609 Also a prefix command for deletion of other GDB objects.\n\
7610 The \"unset\" command is also an alias for \"delete\".",
7611 &deletelist, "delete ", 1, &cmdlist);
7612 add_com_alias ("d", "delete", class_breakpoint, 1);
7614 add_com ("db", class_breakpoint, delete_command,
7615 "Delete some breakpoints.\n\
7616 Arguments are breakpoint numbers with spaces in between.\n\
7617 To delete all breakpoints, give no argument.\n");
7619 add_cmd ("breakpoints", class_alias, delete_command,
7620 "Delete some breakpoints or auto-display expressions.\n\
7621 Arguments are breakpoint numbers with spaces in between.\n\
7622 To delete all breakpoints, give no argument.\n\
7623 This command may be abbreviated \"delete\".",
7626 add_com ("clear", class_breakpoint, clear_command,
7627 concat ("Clear breakpoint at specified line or function.\n\
7628 Argument may be line number, function name, or \"*\" and an address.\n\
7629 If line number is specified, all breakpoints in that line are cleared.\n\
7630 If function is specified, breakpoints at beginning of function are cleared.\n\
7631 If an address is specified, breakpoints at that address are cleared.\n\n",
7632 "With no argument, clears all breakpoints in the line that the selected frame\n\
7635 See also the \"delete\" command which clears breakpoints by number.", NULL));
7637 c = add_com ("break", class_breakpoint, break_command,
7638 concat ("Set breakpoint at specified line or function.\n\
7639 Argument may be line number, function name, or \"*\" and an address.\n\
7640 If line number is specified, break at start of code for that line.\n\
7641 If function is specified, break at start of code for that function.\n\
7642 If an address is specified, break at that exact address.\n",
7643 "With no arg, uses current execution address of selected stack frame.\n\
7644 This is useful for breaking on return to a stack frame.\n\
7646 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7648 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7649 set_cmd_completer (c, location_completer);
7651 add_com_alias ("b", "break", class_run, 1);
7652 add_com_alias ("br", "break", class_run, 1);
7653 add_com_alias ("bre", "break", class_run, 1);
7654 add_com_alias ("brea", "break", class_run, 1);
7658 add_com_alias ("ba", "break", class_breakpoint, 1);
7659 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7664 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7665 "Break in function/address or break at a line in the current file.",
7666 &stoplist, "stop ", 1, &cmdlist);
7667 add_cmd ("in", class_breakpoint, stopin_command,
7668 "Break in function or address.\n", &stoplist);
7669 add_cmd ("at", class_breakpoint, stopat_command,
7670 "Break at a line in the current file.\n", &stoplist);
7671 add_com ("status", class_info, breakpoints_info,
7672 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7673 The \"Type\" column indicates one of:\n\
7674 \tbreakpoint - normal breakpoint\n\
7675 \twatchpoint - watchpoint\n\
7676 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7677 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7678 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7679 address and file/line number respectively.\n\n",
7680 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7681 are set to the address of the last breakpoint listed.\n\n\
7682 Convenience variable \"$bpnum\" contains the number of the last\n\
7683 breakpoint set.", NULL));
7686 add_info ("breakpoints", breakpoints_info,
7687 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7688 The \"Type\" column indicates one of:\n\
7689 \tbreakpoint - normal breakpoint\n\
7690 \twatchpoint - watchpoint\n\
7691 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7692 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7693 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7694 address and file/line number respectively.\n\n",
7695 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7696 are set to the address of the last breakpoint listed.\n\n\
7697 Convenience variable \"$bpnum\" contains the number of the last\n\
7698 breakpoint set.", NULL));
7701 add_com ("lb", class_breakpoint, breakpoints_info,
7702 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7703 The \"Type\" column indicates one of:\n\
7704 \tbreakpoint - normal breakpoint\n\
7705 \twatchpoint - watchpoint\n\
7706 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7707 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7708 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7709 address and file/line number respectively.\n\n",
7710 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7711 are set to the address of the last breakpoint listed.\n\n\
7712 Convenience variable \"$bpnum\" contains the number of the last\n\
7713 breakpoint set.", NULL));
7715 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7716 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7717 The \"Type\" column indicates one of:\n\
7718 \tbreakpoint - normal breakpoint\n\
7719 \twatchpoint - watchpoint\n\
7720 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7721 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7722 \tuntil - internal breakpoint used by the \"until\" command\n\
7723 \tfinish - internal breakpoint used by the \"finish\" command\n",
7724 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7725 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7726 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7727 address and file/line number respectively.\n\n",
7728 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7729 are set to the address of the last breakpoint listed.\n\n\
7730 Convenience variable \"$bpnum\" contains the number of the last\n\
7731 breakpoint set.", NULL),
7732 &maintenanceinfolist);
7734 add_com ("catch", class_breakpoint, catch_command,
7735 "Set catchpoints to catch events.\n\
7736 Raised signals may be caught:\n\
7737 \tcatch signal - all signals\n\
7738 \tcatch signal <signame> - a particular signal\n\
7739 Raised exceptions may be caught:\n\
7740 \tcatch throw - all exceptions, when thrown\n\
7741 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7742 \tcatch catch - all exceptions, when caught\n\
7743 \tcatch catch <exceptname> - a particular exception, when caught\n\
7744 Thread or process events may be caught:\n\
7745 \tcatch thread_start - any threads, just after creation\n\
7746 \tcatch thread_exit - any threads, just before expiration\n\
7747 \tcatch thread_join - any threads, just after joins\n\
7748 Process events may be caught:\n\
7749 \tcatch start - any processes, just after creation\n\
7750 \tcatch exit - any processes, just before expiration\n\
7751 \tcatch fork - calls to fork()\n\
7752 \tcatch vfork - calls to vfork()\n\
7753 \tcatch exec - calls to exec()\n\
7754 Dynamically-linked library events may be caught:\n\
7755 \tcatch load - loads of any library\n\
7756 \tcatch load <libname> - loads of a particular library\n\
7757 \tcatch unload - unloads of any library\n\
7758 \tcatch unload <libname> - unloads of a particular library\n\
7759 The act of your program's execution stopping may also be caught:\n\
7761 C++ exceptions may be caught:\n\
7762 \tcatch throw - all exceptions, when thrown\n\
7763 \tcatch catch - all exceptions, when caught\n\
7765 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7766 after a fork or vfork is caught.\n\n\
7767 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7769 add_com ("tcatch", class_breakpoint, tcatch_command,
7770 "Set temporary catchpoints to catch events.\n\
7771 Args like \"catch\" command.\n\
7772 Like \"catch\" except the catchpoint is only temporary,\n\
7773 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7774 by using \"enable delete\" on the catchpoint number.");
7776 c = add_com ("watch", class_breakpoint, watch_command,
7777 "Set a watchpoint for an expression.\n\
7778 A watchpoint stops execution of your program whenever the value of\n\
7779 an expression changes.");
7780 set_cmd_completer (c, location_completer);
7782 c = add_com ("rwatch", class_breakpoint, rwatch_command,
7783 "Set a read watchpoint for an expression.\n\
7784 A watchpoint stops execution of your program whenever the value of\n\
7785 an expression is read.");
7786 set_cmd_completer (c, location_completer);
7788 c = add_com ("awatch", class_breakpoint, awatch_command,
7789 "Set a watchpoint for an expression.\n\
7790 A watchpoint stops execution of your program whenever the value of\n\
7791 an expression is either read or written.");
7792 set_cmd_completer (c, location_completer);
7794 add_info ("watchpoints", breakpoints_info,
7795 "Synonym for ``info breakpoints''.");
7798 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
7799 (char *) &can_use_hw_watchpoints,
7800 "Set debugger's willingness to use watchpoint hardware.\n\
7801 If zero, gdb will not use hardware for new watchpoints, even if\n\
7802 such is available. (However, any hardware watchpoints that were\n\
7803 created before setting this to nonzero, will continue to use watchpoint\n\
7806 add_show_from_set (c, &showlist);
7808 can_use_hw_watchpoints = 1;