1 /* Everything about breakpoints, for GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
28 #include "breakpoint.h"
30 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb_string.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
53 #include "gdb-events.h"
55 /* Prototypes for local functions. */
57 static void until_break_command_continuation (struct continuation_arg *arg);
59 static void catch_command_1 (char *, int, int);
61 static void enable_delete_command (char *, int);
63 static void enable_delete_breakpoint (struct breakpoint *);
65 static void enable_once_command (char *, int);
67 static void enable_once_breakpoint (struct breakpoint *);
69 static void disable_command (char *, int);
71 static void enable_command (char *, int);
73 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
75 static void ignore_command (char *, int);
77 static int breakpoint_re_set_one (void *);
79 static void clear_command (char *, int);
81 static void catch_command (char *, int);
83 static void watch_command (char *, int);
85 static int can_use_hardware_watchpoint (struct value *);
87 extern void break_at_finish_command (char *, int);
88 extern void break_at_finish_at_depth_command (char *, int);
90 extern void tbreak_at_finish_command (char *, int);
92 static void break_command_1 (char *, int, int);
94 static void mention (struct breakpoint *);
96 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
98 static void check_duplicates (struct breakpoint *);
100 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
102 static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr);
104 static void describe_other_breakpoints (CORE_ADDR, asection *);
106 static void breakpoints_info (char *, int);
108 static void breakpoint_1 (int, int);
110 static bpstat bpstat_alloc (struct breakpoint *, bpstat);
112 static int breakpoint_cond_eval (void *);
114 static void cleanup_executing_breakpoints (void *);
116 static void commands_command (char *, int);
118 static void condition_command (char *, int);
120 static int get_number_trailer (char **, int);
122 void set_breakpoint_count (int);
131 static int remove_breakpoint (struct breakpoint *, insertion_state_t);
133 static enum print_stop_action print_it_typical (bpstat);
135 static enum print_stop_action print_bp_stop_message (bpstat bs);
139 enum exception_event_kind kind;
142 args_for_catchpoint_enable;
144 static int watchpoint_check (void *);
146 static int cover_target_enable_exception_callback (void *);
148 static void maintenance_info_breakpoints (char *, int);
150 static void create_longjmp_breakpoint (char *);
152 static void create_overlay_event_breakpoint (char *);
154 static int hw_breakpoint_used_count (void);
156 static int hw_watchpoint_used_count (enum bptype, int *);
158 static void hbreak_command (char *, int);
160 static void thbreak_command (char *, int);
162 static void watch_command_1 (char *, int, int);
164 static void rwatch_command (char *, int);
166 static void awatch_command (char *, int);
168 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
170 static void solib_load_unload_1 (char *hookname,
173 char *cond_string, enum bptype bp_kind);
175 static void create_fork_vfork_event_catchpoint (int tempflag,
177 enum bptype bp_kind);
179 static void break_at_finish_at_depth_command_1 (char *arg,
180 int flag, int from_tty);
182 static void break_at_finish_command_1 (char *arg, int flag, int from_tty);
184 static void stop_command (char *arg, int from_tty);
186 static void stopin_command (char *arg, int from_tty);
188 static void stopat_command (char *arg, int from_tty);
190 static char *ep_find_event_name_end (char *arg);
192 static char *ep_parse_optional_if_clause (char **arg);
194 static char *ep_parse_optional_filename (char **arg);
196 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
197 static void catch_exec_command_1 (char *arg, int tempflag, int from_tty);
200 static void create_exception_catchpoint (int tempflag, char *cond_string,
201 enum exception_event_kind ex_event,
202 struct symtab_and_line *sal);
204 static void catch_exception_command_1 (enum exception_event_kind ex_event,
205 char *arg, int tempflag, int from_tty);
207 static void tcatch_command (char *arg, int from_tty);
209 static void ep_skip_leading_whitespace (char **s);
211 /* Prototypes for exported functions. */
213 /* If FALSE, gdb will not use hardware support for watchpoints, even
214 if such is available. */
215 static int can_use_hw_watchpoints;
217 void _initialize_breakpoint (void);
219 extern int addressprint; /* Print machine addresses? */
221 /* Are we executing breakpoint commands? */
222 static int executing_breakpoint_commands;
224 /* Are overlay event breakpoints enabled? */
225 static int overlay_events_enabled;
227 /* Walk the following statement or block through all breakpoints.
228 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
231 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
233 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
234 for (B = breakpoint_chain; \
235 B ? (TMP=B->next, 1): 0; \
238 /* Similar iterators for the low-level breakpoints. */
240 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->next)
242 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
243 for (B = bp_location_chain; \
244 B ? (TMP=B->next, 1): 0; \
247 /* True if SHIFT_INST_REGS defined, false otherwise. */
249 int must_shift_inst_regs =
250 #if defined(SHIFT_INST_REGS)
257 /* True if breakpoint hit counts should be displayed in breakpoint info. */
259 int show_breakpoint_hit_counts = 1;
261 /* Chains of all breakpoints defined. */
263 struct breakpoint *breakpoint_chain;
265 struct bp_location *bp_location_chain;
267 /* Number of last breakpoint made. */
269 int breakpoint_count;
271 /* Pointer to current exception event record */
272 static struct exception_event_record *current_exception_event;
274 /* Indicator of whether exception catchpoints should be nuked
275 between runs of a program */
276 int exception_catchpoints_are_fragile = 0;
278 /* Indicator of when exception catchpoints set-up should be
279 reinitialized -- e.g. when program is re-run */
280 int exception_support_initialized = 0;
282 /* This function returns a pointer to the string representation of the
283 pathname of the dynamically-linked library that has just been
286 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
287 or undefined results are guaranteed.
289 This string's contents are only valid immediately after the
290 inferior has stopped in the dynamic linker hook, and becomes
291 invalid as soon as the inferior is continued. Clients should make
292 a copy of this string if they wish to continue the inferior and
293 then access the string. */
295 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
296 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
299 /* This function returns a pointer to the string representation of the
300 pathname of the dynamically-linked library that has just been
303 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
304 TRUE, or undefined results are guaranteed.
306 This string's contents are only valid immediately after the
307 inferior has stopped in the dynamic linker hook, and becomes
308 invalid as soon as the inferior is continued. Clients should make
309 a copy of this string if they wish to continue the inferior and
310 then access the string. */
312 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
313 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
316 /* This function is called by the "catch load" command. It allows the
317 debugger to be notified by the dynamic linker when a specified
318 library file (or any library file, if filename is NULL) is loaded. */
320 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
321 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
322 error ("catch of library loads not yet implemented on this platform")
325 /* This function is called by the "catch unload" command. It allows
326 the debugger to be notified by the dynamic linker when a specified
327 library file (or any library file, if filename is NULL) is
330 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
331 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
332 error ("catch of library unloads not yet implemented on this platform")
335 /* Set breakpoint count to NUM. */
338 set_breakpoint_count (int num)
340 breakpoint_count = num;
341 set_internalvar (lookup_internalvar ("bpnum"),
342 value_from_longest (builtin_type_int, (LONGEST) num));
345 /* Used in run_command to zero the hit count when a new run starts. */
348 clear_breakpoint_hit_counts (void)
350 struct breakpoint *b;
356 /* Default address, symtab and line to put a breakpoint at
357 for "break" command with no arg.
358 if default_breakpoint_valid is zero, the other three are
359 not valid, and "break" with no arg is an error.
361 This set by print_stack_frame, which calls set_default_breakpoint. */
363 int default_breakpoint_valid;
364 CORE_ADDR default_breakpoint_address;
365 struct symtab *default_breakpoint_symtab;
366 int default_breakpoint_line;
368 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
369 Advance *PP after the string and any trailing whitespace.
371 Currently the string can either be a number or "$" followed by the name
372 of a convenience variable. Making it an expression wouldn't work well
373 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
375 TRAILER is a character which can be found after the number; most
376 commonly this is `-'. If you don't want a trailer, use \0. */
378 get_number_trailer (char **pp, int trailer)
380 int retval = 0; /* default */
384 /* Empty line means refer to the last breakpoint. */
385 return breakpoint_count;
388 /* Make a copy of the name, so we can null-terminate it
389 to pass to lookup_internalvar(). */
394 while (isalnum (*p) || *p == '_')
396 varname = (char *) alloca (p - start + 1);
397 strncpy (varname, start, p - start);
398 varname[p - start] = '\0';
399 val = value_of_internalvar (lookup_internalvar (varname));
400 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
401 retval = (int) value_as_long (val);
404 printf_filtered ("Convenience variable must have integer value.\n");
412 while (*p >= '0' && *p <= '9')
415 /* There is no number here. (e.g. "cond a == b"). */
417 /* Skip non-numeric token */
418 while (*p && !isspace((int) *p))
420 /* Return zero, which caller must interpret as error. */
426 if (!(isspace (*p) || *p == '\0' || *p == trailer))
428 /* Trailing junk: return 0 and let caller print error msg. */
429 while (!(isspace (*p) || *p == '\0' || *p == trailer))
440 /* Like get_number_trailer, but don't allow a trailer. */
442 get_number (char **pp)
444 return get_number_trailer (pp, '\0');
447 /* Parse a number or a range.
448 * A number will be of the form handled by get_number.
449 * A range will be of the form <number1> - <number2>, and
450 * will represent all the integers between number1 and number2,
453 * While processing a range, this fuction is called iteratively;
454 * At each call it will return the next value in the range.
456 * At the beginning of parsing a range, the char pointer PP will
457 * be advanced past <number1> and left pointing at the '-' token.
458 * Subsequent calls will not advance the pointer until the range
459 * is completed. The call that completes the range will advance
460 * pointer PP past <number2>.
464 get_number_or_range (char **pp)
466 static int last_retval, end_value;
467 static char *end_ptr;
468 static int in_range = 0;
472 /* Default case: pp is pointing either to a solo number,
473 or to the first number of a range. */
474 last_retval = get_number_trailer (pp, '-');
479 /* This is the start of a range (<number1> - <number2>).
480 Skip the '-', parse and remember the second number,
481 and also remember the end of the final token. */
485 while (isspace ((int) *end_ptr))
486 end_ptr++; /* skip white space */
487 end_value = get_number (temp);
488 if (end_value < last_retval)
490 error ("inverted range");
492 else if (end_value == last_retval)
494 /* degenerate range (number1 == number2). Advance the
495 token pointer so that the range will be treated as a
504 error ("negative value");
507 /* pp points to the '-' that betokens a range. All
508 number-parsing has already been done. Return the next
509 integer value (one greater than the saved previous value).
510 Do not advance the token pointer 'pp' until the end of range
513 if (++last_retval == end_value)
515 /* End of range reached; advance token pointer. */
525 /* condition N EXP -- set break condition of breakpoint N to EXP. */
528 condition_command (char *arg, int from_tty)
530 struct breakpoint *b;
535 error_no_arg ("breakpoint number");
538 bnum = get_number (&p);
540 error ("Bad breakpoint argument: '%s'", arg);
543 if (b->number == bnum)
550 if (b->cond_string != NULL)
551 xfree (b->cond_string);
556 b->cond_string = NULL;
558 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
563 /* I don't know if it matters whether this is the string the user
564 typed in or the decompiled expression. */
565 b->cond_string = savestring (arg, strlen (arg));
566 b->cond = parse_exp_1 (&arg, block_for_pc (b->loc->address), 0);
568 error ("Junk at end of expression");
570 breakpoints_changed ();
571 breakpoint_modify_event (b->number);
575 error ("No breakpoint number %d.", bnum);
579 commands_command (char *arg, int from_tty)
581 struct breakpoint *b;
584 struct command_line *l;
586 /* If we allowed this, we would have problems with when to
587 free the storage, if we change the commands currently
590 if (executing_breakpoint_commands)
591 error ("Can't use the \"commands\" command among a breakpoint's commands.");
594 bnum = get_number (&p);
597 error ("Unexpected extra arguments following breakpoint number.");
600 if (b->number == bnum)
602 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
604 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
605 l = read_command_lines (tmpbuf, from_tty);
606 do_cleanups (cleanups);
607 free_command_lines (&b->commands);
609 breakpoints_changed ();
610 breakpoint_modify_event (b->number);
613 error ("No breakpoint number %d.", bnum);
616 /* Like target_read_memory() but if breakpoints are inserted, return
617 the shadow contents instead of the breakpoints themselves.
619 Read "memory data" from whatever target or inferior we have.
620 Returns zero if successful, errno value if not. EIO is used
621 for address out of bounds. If breakpoints are inserted, returns
622 shadow contents, not the breakpoints themselves. From breakpoint.c. */
625 read_memory_nobpt (CORE_ADDR memaddr, char *myaddr, unsigned len)
628 struct bp_location *b;
629 CORE_ADDR bp_addr = 0;
632 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
633 /* No breakpoints on this machine. */
634 return target_read_memory (memaddr, myaddr, len);
638 if (b->owner->type == bp_none)
639 warning ("reading through apparently deleted breakpoint #%d?",
642 if (b->loc_type != bp_loc_software_breakpoint)
646 /* Addresses and length of the part of the breakpoint that
648 /* XXXX The m68k, sh and h8300 have different local and remote
649 breakpoint values. BREAKPOINT_FROM_PC still manages to
650 correctly determine the breakpoints memory address and size
651 for these targets. */
652 bp_addr = b->address;
654 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
659 if (bp_addr + bp_size <= memaddr)
660 /* The breakpoint is entirely before the chunk of memory we
663 if (bp_addr >= memaddr + len)
664 /* The breakpoint is entirely after the chunk of memory we are
667 /* Copy the breakpoint from the shadow contents, and recurse for
668 the things before and after. */
670 /* Offset within shadow_contents. */
673 if (bp_addr < memaddr)
675 /* Only copy the second part of the breakpoint. */
676 bp_size -= memaddr - bp_addr;
677 bptoffset = memaddr - bp_addr;
681 if (bp_addr + bp_size > memaddr + len)
683 /* Only copy the first part of the breakpoint. */
684 bp_size -= (bp_addr + bp_size) - (memaddr + len);
687 memcpy (myaddr + bp_addr - memaddr,
688 b->shadow_contents + bptoffset, bp_size);
690 if (bp_addr > memaddr)
692 /* Copy the section of memory before the breakpoint. */
693 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
698 if (bp_addr + bp_size < memaddr + len)
700 /* Copy the section of memory after the breakpoint. */
701 status = read_memory_nobpt (bp_addr + bp_size,
702 myaddr + bp_addr + bp_size - memaddr,
703 memaddr + len - (bp_addr + bp_size));
710 /* Nothing overlaps. Just call read_memory_noerr. */
711 return target_read_memory (memaddr, myaddr, len);
715 /* A wrapper function for inserting catchpoints. */
717 insert_catchpoint (struct ui_out *uo, void *args)
719 struct breakpoint *b = (struct breakpoint *) args;
725 val = target_insert_fork_catchpoint (PIDGET (inferior_ptid));
728 val = target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
731 val = target_insert_exec_catchpoint (PIDGET (inferior_ptid));
734 internal_error (__FILE__, __LINE__, "unknown breakpoint type");
739 throw_exception (RETURN_ERROR);
744 /* insert_breakpoints is used when starting or continuing the program.
745 remove_breakpoints is used when the program stops.
746 Both return zero if successful,
747 or an `errno' value if could not write the inferior. */
750 insert_breakpoints (void)
752 struct breakpoint *b, *temp;
753 int return_val = 0; /* return success code. */
755 int disabled_breaks = 0;
756 int hw_breakpoint_error = 0;
757 #ifdef ONE_PROCESS_WRITETEXT
758 int process_warning = 0;
761 struct ui_file *tmp_error_stream = mem_fileopen ();
762 make_cleanup_ui_file_delete (tmp_error_stream);
764 /* Explicitly mark the warning -- this will only be printed if
765 there was an error. */
766 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
768 ALL_BREAKPOINTS_SAFE (b, temp)
770 /* Permanent breakpoints cannot be inserted or removed. Disabled
771 breakpoints should not be inserted. */
772 if (b->enable_state != bp_enabled)
775 if ((b->type == bp_watchpoint
776 || b->type == bp_hardware_watchpoint
777 || b->type == bp_read_watchpoint
778 || b->type == bp_access_watchpoint) && (!b->val))
781 val = evaluate_expression (b->exp);
783 if (VALUE_LAZY (val))
784 value_fetch_lazy (val);
787 if (b->type != bp_watchpoint
788 && b->type != bp_hardware_watchpoint
789 && b->type != bp_read_watchpoint
790 && b->type != bp_access_watchpoint
791 && b->type != bp_catch_fork
792 && b->type != bp_catch_vfork
793 && b->type != bp_catch_exec
794 && b->type != bp_catch_throw
795 && b->type != bp_catch_catch
797 && !b->loc->duplicate)
799 /* "Normal" instruction breakpoint: either the standard
800 trap-instruction bp (bp_breakpoint), or a
801 bp_hardware_breakpoint. */
803 /* First check to see if we have to handle an overlay. */
804 if (overlay_debugging == ovly_off
805 || b->section == NULL
806 || !(section_is_overlay (b->section)))
808 /* No overlay handling: just set the breakpoint. */
810 if (b->type == bp_hardware_breakpoint)
811 val = target_insert_hw_breakpoint (b->loc->address,
812 b->loc->shadow_contents);
814 val = target_insert_breakpoint (b->loc->address, b->loc->shadow_contents);
818 /* This breakpoint is in an overlay section.
819 Shall we set a breakpoint at the LMA? */
820 if (!overlay_events_enabled)
822 /* Yes -- overlay event support is not active,
823 so we must try to set a breakpoint at the LMA.
824 This will not work for a hardware breakpoint. */
825 if (b->type == bp_hardware_breakpoint)
826 warning ("hardware breakpoint %d not supported in overlay!\n",
830 CORE_ADDR addr = overlay_unmapped_address (b->loc->address,
832 /* Set a software (trap) breakpoint at the LMA. */
833 val = target_insert_breakpoint (addr, b->loc->shadow_contents);
835 fprintf_unfiltered (tmp_error_stream,
836 "Overlay breakpoint %d failed: in ROM?",
840 /* Shall we set a breakpoint at the VMA? */
841 if (section_is_mapped (b->section))
843 /* Yes. This overlay section is mapped into memory. */
844 if (b->type == bp_hardware_breakpoint)
845 val = target_insert_hw_breakpoint (b->loc->address,
846 b->loc->shadow_contents);
848 val = target_insert_breakpoint (b->loc->address,
849 b->loc->shadow_contents);
853 /* No. This breakpoint will not be inserted.
854 No error, but do not mark the bp as 'inserted'. */
861 /* Can't set the breakpoint. */
862 #if defined (DISABLE_UNSETTABLE_BREAK)
863 if (DISABLE_UNSETTABLE_BREAK (b->loc->address))
865 /* See also: disable_breakpoints_in_shlibs. */
867 b->enable_state = bp_shlib_disabled;
868 if (!disabled_breaks)
870 fprintf_unfiltered (tmp_error_stream,
871 "Cannot insert breakpoint %d.\n",
873 fprintf_unfiltered (tmp_error_stream,
874 "Temporarily disabling shared library breakpoints:\n");
877 fprintf_unfiltered (tmp_error_stream,
878 "breakpoint #%d\n", b->number);
883 #ifdef ONE_PROCESS_WRITETEXT
886 if (b->type == bp_hardware_breakpoint)
888 hw_breakpoint_error = 1;
889 fprintf_unfiltered (tmp_error_stream,
890 "Cannot insert hardware breakpoint %d.\n",
895 fprintf_unfiltered (tmp_error_stream,
896 "Cannot insert breakpoint %d.\n",
898 fprintf_filtered (tmp_error_stream,
899 "Error accessing memory address ");
900 print_address_numeric (b->loc->address, 1, tmp_error_stream);
901 fprintf_filtered (tmp_error_stream, ": %s.\n",
902 safe_strerror (val));
908 b->loc->inserted = 1;
911 return_val = val; /* remember failure */
913 else if (ep_is_exception_catchpoint (b)
915 && !b->loc->duplicate)
918 /* If we get here, we must have a callback mechanism for exception
919 events -- with g++ style embedded label support, we insert
920 ordinary breakpoints and not catchpoints. */
921 val = target_insert_breakpoint (b->loc->address, b->loc->shadow_contents);
924 /* Couldn't set breakpoint for some reason */
925 fprintf_unfiltered (tmp_error_stream,
926 "Cannot insert catchpoint %d; disabling it.\n",
928 fprintf_filtered (tmp_error_stream,
929 "Error accessing memory address ");
930 print_address_numeric (b->loc->address, 1, tmp_error_stream);
931 fprintf_filtered (tmp_error_stream, ": %s.\n",
932 safe_strerror (val));
933 b->enable_state = bp_disabled;
937 /* Bp set, now make sure callbacks are enabled */
938 /* Format possible error msg */
939 char *message = xstrprintf ("Error inserting catchpoint %d:\n",
941 struct cleanup *cleanups = make_cleanup (xfree, message);
943 args_for_catchpoint_enable args;
944 args.kind = b->type == bp_catch_catch ?
945 EX_EVENT_CATCH : EX_EVENT_THROW;
947 val = catch_errors (cover_target_enable_exception_callback,
948 &args, message, RETURN_MASK_ALL);
949 do_cleanups (cleanups);
950 if (val != 0 && val != -1)
952 b->loc->inserted = 1;
954 /* Check if something went wrong; val == 0 can be ignored */
957 /* something went wrong */
958 fprintf_unfiltered (tmp_error_stream,
959 "Cannot insert catchpoint %d; disabling it.\n",
961 b->enable_state = bp_disabled;
966 return_val = val; /* remember failure */
969 else if ((b->type == bp_hardware_watchpoint ||
970 b->type == bp_read_watchpoint ||
971 b->type == bp_access_watchpoint)
972 && b->disposition != disp_del_at_next_stop
974 && !b->loc->duplicate)
976 struct frame_info *saved_frame;
977 int saved_level, within_current_scope;
978 struct value *mark = value_mark ();
981 /* Save the current frame and level so we can restore it after
982 evaluating the watchpoint expression on its own frame. */
983 saved_frame = deprecated_selected_frame;
984 saved_level = frame_relative_level (deprecated_selected_frame);
986 /* Determine if the watchpoint is within scope. */
987 if (b->exp_valid_block == NULL)
988 within_current_scope = 1;
991 struct frame_info *fi;
992 fi = frame_find_by_id (b->watchpoint_frame);
993 within_current_scope = (fi != NULL);
994 if (within_current_scope)
998 if (within_current_scope)
1000 /* Evaluate the expression and cut the chain of values
1001 produced off from the value chain.
1003 Make sure the value returned isn't lazy; we use
1004 laziness to determine what memory GDB actually needed
1005 in order to compute the value of the expression. */
1006 v = evaluate_expression (b->exp);
1008 value_release_to_mark (mark);
1011 b->loc->inserted = 1;
1013 /* Look at each value on the value chain. */
1014 for (; v; v = v->next)
1016 /* If it's a memory location, and GDB actually needed
1017 its contents to evaluate the expression, then we
1019 if (VALUE_LVAL (v) == lval_memory
1020 && ! VALUE_LAZY (v))
1022 struct type *vtype = check_typedef (VALUE_TYPE (v));
1024 /* We only watch structs and arrays if user asked
1025 for it explicitly, never if they just happen to
1026 appear in the middle of some value chain. */
1027 if (v == b->val_chain
1028 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1029 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1034 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1035 len = TYPE_LENGTH (VALUE_TYPE (v));
1037 if (b->type == bp_read_watchpoint)
1039 else if (b->type == bp_access_watchpoint)
1042 val = target_insert_watchpoint (addr, len, type);
1045 /* Don't exit the loop, try to insert
1046 every value on the value chain. That's
1047 because we will be removing all the
1048 watches below, and removing a
1049 watchpoint we didn't insert could have
1051 b->loc->inserted = 0;
1057 /* Failure to insert a watchpoint on any memory value in the
1058 value chain brings us here. */
1059 if (!b->loc->inserted)
1061 remove_breakpoint (b, mark_uninserted);
1062 hw_breakpoint_error = 1;
1063 fprintf_unfiltered (tmp_error_stream,
1064 "Could not insert hardware watchpoint %d.\n",
1071 printf_filtered ("Hardware watchpoint %d deleted ", b->number);
1072 printf_filtered ("because the program has left the block \n");
1073 printf_filtered ("in which its expression is valid.\n");
1074 if (b->related_breakpoint)
1075 b->related_breakpoint->disposition = disp_del_at_next_stop;
1076 b->disposition = disp_del_at_next_stop;
1079 /* Restore the frame and level. */
1080 if ((saved_frame != deprecated_selected_frame) ||
1081 (saved_level != frame_relative_level (deprecated_selected_frame)))
1082 select_frame (saved_frame);
1085 return_val = val; /* remember failure */
1087 else if ((b->type == bp_catch_fork
1088 || b->type == bp_catch_vfork
1089 || b->type == bp_catch_exec)
1090 && !b->loc->inserted
1091 && !b->loc->duplicate)
1093 char *prefix = xstrprintf ("warning: inserting catchpoint %d: ",
1095 struct cleanup *cleanups = make_cleanup (xfree, prefix);
1096 val = catch_exceptions (uiout, insert_catchpoint, b, prefix,
1098 do_cleanups (cleanups);
1100 b->enable_state = bp_disabled;
1102 b->loc->inserted = 1;
1108 /* If a hardware breakpoint or watchpoint was inserted, add a
1109 message about possibly exhausted resources. */
1110 if (hw_breakpoint_error)
1112 fprintf_unfiltered (tmp_error_stream,
1113 "Could not insert hardware breakpoints:\n\
1114 You may have requested too many hardware breakpoints/watchpoints.\n");
1116 #ifdef ONE_PROCESS_WRITETEXT
1117 if (process_warning)
1118 fprintf_unfiltered (tmp_error_stream,
1119 "The same program may be running in another process.");
1121 target_terminal_ours_for_output ();
1122 error_stream (tmp_error_stream);
1128 remove_breakpoints (void)
1130 struct breakpoint *b;
1135 if (b->loc->inserted)
1137 val = remove_breakpoint (b, mark_uninserted);
1146 remove_hw_watchpoints (void)
1148 struct breakpoint *b;
1153 if (b->loc->inserted
1154 && (b->type == bp_hardware_watchpoint
1155 || b->type == bp_read_watchpoint
1156 || b->type == bp_access_watchpoint))
1158 val = remove_breakpoint (b, mark_uninserted);
1167 reattach_breakpoints (int pid)
1169 struct breakpoint *b;
1171 struct cleanup *old_chain = save_inferior_ptid ();
1173 /* Set inferior_ptid; remove_breakpoint uses this global. */
1174 inferior_ptid = pid_to_ptid (pid);
1177 if (b->loc->inserted)
1179 remove_breakpoint (b, mark_inserted);
1180 if (b->type == bp_hardware_breakpoint)
1181 val = target_insert_hw_breakpoint (b->loc->address, b->loc->shadow_contents);
1183 val = target_insert_breakpoint (b->loc->address, b->loc->shadow_contents);
1186 do_cleanups (old_chain);
1191 do_cleanups (old_chain);
1196 update_breakpoints_after_exec (void)
1198 struct breakpoint *b;
1199 struct breakpoint *temp;
1201 /* Doing this first prevents the badness of having delete_breakpoint()
1202 write a breakpoint's current "shadow contents" to lift the bp. That
1203 shadow is NOT valid after an exec()! */
1204 mark_breakpoints_out ();
1206 ALL_BREAKPOINTS_SAFE (b, temp)
1208 /* Solib breakpoints must be explicitly reset after an exec(). */
1209 if (b->type == bp_shlib_event)
1211 delete_breakpoint (b);
1215 /* Thread event breakpoints must be set anew after an exec(),
1216 as must overlay event breakpoints. */
1217 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1219 delete_breakpoint (b);
1223 /* Step-resume breakpoints are meaningless after an exec(). */
1224 if (b->type == bp_step_resume)
1226 delete_breakpoint (b);
1230 /* Ditto the sigtramp handler breakpoints. */
1231 if (b->type == bp_through_sigtramp)
1233 delete_breakpoint (b);
1237 /* Ditto the exception-handling catchpoints. */
1238 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1240 delete_breakpoint (b);
1244 /* Don't delete an exec catchpoint, because else the inferior
1245 won't stop when it ought!
1247 Similarly, we probably ought to keep vfork catchpoints, 'cause
1248 on this target, we may not be able to stop when the vfork is
1249 seen, but only when the subsequent exec is seen. (And because
1250 deleting fork catchpoints here but not vfork catchpoints will
1251 seem mysterious to users, keep those too.)
1253 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1254 target address field, if any, is sufficient to have it be reset
1255 automagically. Certainly on HP-UX that's true.
1257 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1258 valid code address on some platforms (like the mn10300
1259 simulators). We shouldn't assign any special interpretation to
1260 a breakpoint with a zero address. And in fact, GDB doesn't ---
1261 I can't see what that comment above is talking about. As far
1262 as I can tell, setting the address of a
1263 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1264 is meaningless, since those are implemented with HP-UX kernel
1265 hackery, not by storing breakpoint instructions somewhere. */
1266 if ((b->type == bp_catch_exec) ||
1267 (b->type == bp_catch_vfork) ||
1268 (b->type == bp_catch_fork))
1270 b->loc->address = (CORE_ADDR) NULL;
1274 /* bp_finish is a special case. The only way we ought to be able
1275 to see one of these when an exec() has happened, is if the user
1276 caught a vfork, and then said "finish". Ordinarily a finish just
1277 carries them to the call-site of the current callee, by setting
1278 a temporary bp there and resuming. But in this case, the finish
1279 will carry them entirely through the vfork & exec.
1281 We don't want to allow a bp_finish to remain inserted now. But
1282 we can't safely delete it, 'cause finish_command has a handle to
1283 the bp on a bpstat, and will later want to delete it. There's a
1284 chance (and I've seen it happen) that if we delete the bp_finish
1285 here, that its storage will get reused by the time finish_command
1286 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1287 We really must allow finish_command to delete a bp_finish.
1289 In the absense of a general solution for the "how do we know
1290 it's safe to delete something others may have handles to?"
1291 problem, what we'll do here is just uninsert the bp_finish, and
1292 let finish_command delete it.
1294 (We know the bp_finish is "doomed" in the sense that it's
1295 momentary, and will be deleted as soon as finish_command sees
1296 the inferior stopped. So it doesn't matter that the bp's
1297 address is probably bogus in the new a.out, unlike e.g., the
1298 solib breakpoints.) */
1300 if (b->type == bp_finish)
1305 /* Without a symbolic address, we have little hope of the
1306 pre-exec() address meaning the same thing in the post-exec()
1308 if (b->addr_string == NULL)
1310 delete_breakpoint (b);
1314 /* If this breakpoint has survived the above battery of checks, then
1315 it must have a symbolic address. Be sure that it gets reevaluated
1316 to a target address, rather than reusing the old evaluation.
1318 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1319 for bp_catch_exec and friends, I'm pretty sure this is entirely
1320 unnecessary. A call to breakpoint_re_set_one always recomputes
1321 the breakpoint's address from scratch, or deletes it if it can't.
1322 So I think this assignment could be deleted without effect. */
1323 b->loc->address = (CORE_ADDR) NULL;
1325 /* FIXME what about longjmp breakpoints? Re-create them here? */
1326 create_overlay_event_breakpoint ("_ovly_debug_event");
1330 detach_breakpoints (int pid)
1332 struct breakpoint *b;
1334 struct cleanup *old_chain = save_inferior_ptid ();
1336 if (pid == PIDGET (inferior_ptid))
1337 error ("Cannot detach breakpoints of inferior_ptid");
1339 /* Set inferior_ptid; remove_breakpoint uses this global. */
1340 inferior_ptid = pid_to_ptid (pid);
1343 if (b->loc->inserted)
1345 val = remove_breakpoint (b, mark_inserted);
1348 do_cleanups (old_chain);
1353 do_cleanups (old_chain);
1358 remove_breakpoint (struct breakpoint *b, insertion_state_t is)
1362 if (b->enable_state == bp_permanent)
1363 /* Permanent breakpoints cannot be inserted or removed. */
1366 if (b->type == bp_none)
1367 warning ("attempted to remove apparently deleted breakpoint #%d?",
1370 if (b->type != bp_watchpoint
1371 && b->type != bp_hardware_watchpoint
1372 && b->type != bp_read_watchpoint
1373 && b->type != bp_access_watchpoint
1374 && b->type != bp_catch_fork
1375 && b->type != bp_catch_vfork
1376 && b->type != bp_catch_exec
1377 && b->type != bp_catch_catch
1378 && b->type != bp_catch_throw)
1380 /* "Normal" instruction breakpoint: either the standard
1381 trap-instruction bp (bp_breakpoint), or a
1382 bp_hardware_breakpoint. */
1384 /* First check to see if we have to handle an overlay. */
1385 if (overlay_debugging == ovly_off
1386 || b->section == NULL
1387 || !(section_is_overlay (b->section)))
1389 /* No overlay handling: just remove the breakpoint. */
1391 if (b->type == bp_hardware_breakpoint)
1392 val = target_remove_hw_breakpoint (b->loc->address,
1393 b->loc->shadow_contents);
1395 val = target_remove_breakpoint (b->loc->address, b->loc->shadow_contents);
1399 /* This breakpoint is in an overlay section.
1400 Did we set a breakpoint at the LMA? */
1401 if (!overlay_events_enabled)
1403 /* Yes -- overlay event support is not active, so we
1404 should have set a breakpoint at the LMA. Remove it.
1406 CORE_ADDR addr = overlay_unmapped_address (b->loc->address,
1408 /* Ignore any failures: if the LMA is in ROM, we will
1409 have already warned when we failed to insert it. */
1410 if (b->type != bp_hardware_breakpoint)
1411 target_remove_hw_breakpoint (addr, b->loc->shadow_contents);
1413 target_remove_breakpoint (addr, b->loc->shadow_contents);
1415 /* Did we set a breakpoint at the VMA?
1416 If so, we will have marked the breakpoint 'inserted'. */
1417 if (b->loc->inserted)
1419 /* Yes -- remove it. Previously we did not bother to
1420 remove the breakpoint if the section had been
1421 unmapped, but let's not rely on that being safe. We
1422 don't know what the overlay manager might do. */
1423 if (b->type == bp_hardware_breakpoint)
1424 val = target_remove_hw_breakpoint (b->loc->address,
1425 b->loc->shadow_contents);
1427 val = target_remove_breakpoint (b->loc->address,
1428 b->loc->shadow_contents);
1432 /* No -- not inserted, so no need to remove. No error. */
1438 b->loc->inserted = (is == mark_inserted);
1440 else if ((b->type == bp_hardware_watchpoint ||
1441 b->type == bp_read_watchpoint ||
1442 b->type == bp_access_watchpoint)
1443 && b->enable_state == bp_enabled
1444 && !b->loc->duplicate)
1449 b->loc->inserted = (is == mark_inserted);
1450 /* Walk down the saved value chain. */
1451 for (v = b->val_chain; v; v = v->next)
1453 /* For each memory reference remove the watchpoint
1455 if (VALUE_LVAL (v) == lval_memory
1456 && ! VALUE_LAZY (v))
1458 struct type *vtype = check_typedef (VALUE_TYPE (v));
1460 if (v == b->val_chain
1461 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1462 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1467 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1468 len = TYPE_LENGTH (VALUE_TYPE (v));
1470 if (b->type == bp_read_watchpoint)
1472 else if (b->type == bp_access_watchpoint)
1475 val = target_remove_watchpoint (addr, len, type);
1477 b->loc->inserted = 1;
1482 /* Failure to remove any of the hardware watchpoints comes here. */
1483 if ((is == mark_uninserted) && (b->loc->inserted))
1484 warning ("Could not remove hardware watchpoint %d.",
1487 /* Free the saved value chain. We will construct a new one
1488 the next time the watchpoint is inserted. */
1489 for (v = b->val_chain; v; v = n)
1494 b->val_chain = NULL;
1496 else if ((b->type == bp_catch_fork ||
1497 b->type == bp_catch_vfork ||
1498 b->type == bp_catch_exec)
1499 && b->enable_state == bp_enabled
1500 && !b->loc->duplicate)
1506 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1508 case bp_catch_vfork:
1509 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1512 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1515 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1520 b->loc->inserted = (is == mark_inserted);
1522 else if ((b->type == bp_catch_catch ||
1523 b->type == bp_catch_throw)
1524 && b->enable_state == bp_enabled
1525 && !b->loc->duplicate)
1528 val = target_remove_breakpoint (b->loc->address, b->loc->shadow_contents);
1531 b->loc->inserted = (is == mark_inserted);
1533 else if (ep_is_exception_catchpoint (b)
1534 && b->loc->inserted /* sometimes previous insert doesn't happen */
1535 && b->enable_state == bp_enabled
1536 && !b->loc->duplicate)
1539 val = target_remove_breakpoint (b->loc->address, b->loc->shadow_contents);
1543 b->loc->inserted = (is == mark_inserted);
1549 /* Clear the "inserted" flag in all breakpoints. */
1552 mark_breakpoints_out (void)
1554 struct breakpoint *b;
1557 b->loc->inserted = 0;
1560 /* Clear the "inserted" flag in all breakpoints and delete any
1561 breakpoints which should go away between runs of the program.
1563 Plus other such housekeeping that has to be done for breakpoints
1566 Note: this function gets called at the end of a run (by
1567 generic_mourn_inferior) and when a run begins (by
1568 init_wait_for_inferior). */
1573 breakpoint_init_inferior (enum inf_context context)
1575 struct breakpoint *b, *temp;
1576 static int warning_needed = 0;
1578 ALL_BREAKPOINTS_SAFE (b, temp)
1580 b->loc->inserted = 0;
1585 case bp_watchpoint_scope:
1587 /* If the call dummy breakpoint is at the entry point it will
1588 cause problems when the inferior is rerun, so we better
1591 Also get rid of scope breakpoints. */
1592 delete_breakpoint (b);
1596 case bp_hardware_watchpoint:
1597 case bp_read_watchpoint:
1598 case bp_access_watchpoint:
1600 /* Likewise for watchpoints on local expressions. */
1601 if (b->exp_valid_block != NULL)
1602 delete_breakpoint (b);
1603 if (context == inf_starting)
1605 /* Reset val field to force reread of starting value
1606 in insert_breakpoints. */
1608 value_free (b->val);
1613 /* Likewise for exception catchpoints in dynamic-linked
1614 executables where required */
1615 if (ep_is_exception_catchpoint (b) &&
1616 exception_catchpoints_are_fragile)
1619 delete_breakpoint (b);
1625 if (exception_catchpoints_are_fragile)
1626 exception_support_initialized = 0;
1628 /* Don't issue the warning unless it's really needed... */
1629 if (warning_needed && (context != inf_exited))
1631 warning ("Exception catchpoints from last run were deleted.");
1632 warning ("You must reinsert them explicitly.");
1637 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1638 exists at PC. It returns ordinary_breakpoint_here if it's an
1639 ordinary breakpoint, or permanent_breakpoint_here if it's a
1640 permanent breakpoint.
1641 - When continuing from a location with an ordinary breakpoint, we
1642 actually single step once before calling insert_breakpoints.
1643 - When continuing from a localion with a permanent breakpoint, we
1644 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1645 the target, to advance the PC past the breakpoint. */
1647 enum breakpoint_here
1648 breakpoint_here_p (CORE_ADDR pc)
1650 struct breakpoint *b;
1651 int any_breakpoint_here = 0;
1654 if ((b->enable_state == bp_enabled
1655 || b->enable_state == bp_permanent)
1656 && b->loc->address == pc) /* bp is enabled and matches pc */
1658 if (overlay_debugging
1659 && section_is_overlay (b->section)
1660 && !section_is_mapped (b->section))
1661 continue; /* unmapped overlay -- can't be a match */
1662 else if (b->enable_state == bp_permanent)
1663 return permanent_breakpoint_here;
1665 any_breakpoint_here = 1;
1668 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1672 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1673 but it only returns true if there is actually a breakpoint inserted
1677 breakpoint_inserted_here_p (CORE_ADDR pc)
1679 struct breakpoint *b;
1682 if (b->loc->inserted
1683 && b->loc->address == pc) /* bp is inserted and matches pc */
1685 if (overlay_debugging
1686 && section_is_overlay (b->section)
1687 && !section_is_mapped (b->section))
1688 continue; /* unmapped overlay -- can't be a match */
1696 /* Return nonzero if FRAME is a dummy frame. We can't use
1697 DEPRECATED_PC_IN_CALL_DUMMY because figuring out the saved SP would
1698 take too much time, at least using frame_register() on the 68k.
1699 This means that for this function to work right a port must use the
1700 bp_call_dummy breakpoint. */
1703 deprecated_frame_in_dummy (struct frame_info *frame)
1705 struct breakpoint *b;
1707 /* This function is used by two files: get_frame_type(), after first
1708 checking that !DEPRECATED_USE_GENERIC_DUMMY_FRAMES; and
1709 sparc-tdep.c, which doesn't yet use generic dummy frames anyway. */
1710 gdb_assert (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES);
1714 if (b->type == bp_call_dummy
1715 && frame_id_eq (b->frame_id, get_frame_id (frame))
1716 /* We need to check the PC as well as the frame on the sparc,
1717 for signals.exp in the testsuite. */
1718 && (get_frame_pc (frame)
1720 - DEPRECATED_SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * DEPRECATED_REGISTER_SIZE))
1721 && get_frame_pc (frame) <= b->loc->address)
1727 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1728 PC is valid for process/thread PID. */
1731 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1733 struct breakpoint *b;
1736 thread = pid_to_thread_id (ptid);
1739 if (b->enable_state != bp_disabled
1740 && b->enable_state != bp_shlib_disabled
1741 && b->enable_state != bp_call_disabled
1742 && b->loc->address == pc
1743 && (b->thread == -1 || b->thread == thread))
1745 if (overlay_debugging
1746 && section_is_overlay (b->section)
1747 && !section_is_mapped (b->section))
1748 continue; /* unmapped overlay -- can't be a match */
1757 /* bpstat stuff. External routines' interfaces are documented
1761 ep_is_catchpoint (struct breakpoint *ep)
1764 (ep->type == bp_catch_load)
1765 || (ep->type == bp_catch_unload)
1766 || (ep->type == bp_catch_fork)
1767 || (ep->type == bp_catch_vfork)
1768 || (ep->type == bp_catch_exec)
1769 || (ep->type == bp_catch_catch)
1770 || (ep->type == bp_catch_throw);
1772 /* ??rehrauer: Add more kinds here, as are implemented... */
1776 ep_is_shlib_catchpoint (struct breakpoint *ep)
1779 (ep->type == bp_catch_load)
1780 || (ep->type == bp_catch_unload);
1784 ep_is_exception_catchpoint (struct breakpoint *ep)
1787 (ep->type == bp_catch_catch)
1788 || (ep->type == bp_catch_throw);
1791 /* Clear a bpstat so that it says we are not at any breakpoint.
1792 Also free any storage that is part of a bpstat. */
1795 bpstat_clear (bpstat *bsp)
1806 if (p->old_val != NULL)
1807 value_free (p->old_val);
1808 free_command_lines (&p->commands);
1815 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1816 is part of the bpstat is copied as well. */
1819 bpstat_copy (bpstat bs)
1823 bpstat retval = NULL;
1828 for (; bs != NULL; bs = bs->next)
1830 tmp = (bpstat) xmalloc (sizeof (*tmp));
1831 memcpy (tmp, bs, sizeof (*tmp));
1832 if (bs->commands != NULL)
1833 tmp->commands = copy_command_lines (bs->commands);
1834 if (bs->old_val != NULL)
1835 tmp->old_val = value_copy (bs->old_val);
1838 /* This is the first thing in the chain. */
1848 /* Find the bpstat associated with this breakpoint */
1851 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1856 for (; bsp != NULL; bsp = bsp->next)
1858 if (bsp->breakpoint_at == breakpoint)
1864 /* Find a step_resume breakpoint associated with this bpstat.
1865 (If there are multiple step_resume bp's on the list, this function
1866 will arbitrarily pick one.)
1868 It is an error to use this function if BPSTAT doesn't contain a
1869 step_resume breakpoint.
1871 See wait_for_inferior's use of this function. */
1873 bpstat_find_step_resume_breakpoint (bpstat bsp)
1878 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1880 current_thread = pid_to_thread_id (inferior_ptid);
1882 for (; bsp != NULL; bsp = bsp->next)
1884 if ((bsp->breakpoint_at != NULL) &&
1885 (bsp->breakpoint_at->type == bp_step_resume) &&
1886 (bsp->breakpoint_at->thread == current_thread ||
1887 bsp->breakpoint_at->thread == -1))
1888 return bsp->breakpoint_at;
1891 error ("Internal error (no step_resume breakpoint found)");
1895 /* Return the breakpoint number of the first breakpoint we are stopped
1896 at. *BSP upon return is a bpstat which points to the remaining
1897 breakpoints stopped at (but which is not guaranteed to be good for
1898 anything but further calls to bpstat_num).
1899 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1902 bpstat_num (bpstat *bsp)
1904 struct breakpoint *b;
1907 return 0; /* No more breakpoint values */
1910 b = (*bsp)->breakpoint_at;
1911 *bsp = (*bsp)->next;
1913 return -1; /* breakpoint that's been deleted since */
1915 return b->number; /* We have its number */
1919 /* Modify BS so that the actions will not be performed. */
1922 bpstat_clear_actions (bpstat bs)
1924 for (; bs != NULL; bs = bs->next)
1926 free_command_lines (&bs->commands);
1927 if (bs->old_val != NULL)
1929 value_free (bs->old_val);
1935 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1937 cleanup_executing_breakpoints (void *ignore)
1939 executing_breakpoint_commands = 0;
1942 /* Execute all the commands associated with all the breakpoints at this
1943 location. Any of these commands could cause the process to proceed
1944 beyond this point, etc. We look out for such changes by checking
1945 the global "breakpoint_proceeded" after each command. */
1948 bpstat_do_actions (bpstat *bsp)
1951 struct cleanup *old_chain;
1952 struct command_line *cmd;
1954 /* Avoid endless recursion if a `source' command is contained
1956 if (executing_breakpoint_commands)
1959 executing_breakpoint_commands = 1;
1960 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1963 /* Note that (as of this writing), our callers all appear to
1964 be passing us the address of global stop_bpstat. And, if
1965 our calls to execute_control_command cause the inferior to
1966 proceed, that global (and hence, *bsp) will change.
1968 We must be careful to not touch *bsp unless the inferior
1969 has not proceeded. */
1971 /* This pointer will iterate over the list of bpstat's. */
1974 breakpoint_proceeded = 0;
1975 for (; bs != NULL; bs = bs->next)
1980 execute_control_command (cmd);
1982 if (breakpoint_proceeded)
1987 if (breakpoint_proceeded)
1988 /* The inferior is proceeded by the command; bomb out now.
1989 The bpstat chain has been blown away by wait_for_inferior.
1990 But since execution has stopped again, there is a new bpstat
1991 to look at, so start over. */
1994 free_command_lines (&bs->commands);
1996 do_cleanups (old_chain);
1999 /* This is the normal print function for a bpstat. In the future,
2000 much of this logic could (should?) be moved to bpstat_stop_status,
2001 by having it set different print_it values.
2003 Current scheme: When we stop, bpstat_print() is called. It loops
2004 through the bpstat list of things causing this stop, calling the
2005 print_bp_stop_message function on each one. The behavior of the
2006 print_bp_stop_message function depends on the print_it field of
2007 bpstat. If such field so indicates, call this function here.
2009 Return values from this routine (ultimately used by bpstat_print()
2010 and normal_stop() to decide what to do):
2011 PRINT_NOTHING: Means we already printed all we needed to print,
2012 don't print anything else.
2013 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2014 that something to be followed by a location.
2015 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2016 that something to be followed by a location.
2017 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2020 static enum print_stop_action
2021 print_it_typical (bpstat bs)
2023 struct cleanup *old_chain, *ui_out_chain;
2024 struct ui_stream *stb;
2025 stb = ui_out_stream_new (uiout);
2026 old_chain = make_cleanup_ui_out_stream_delete (stb);
2027 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2028 which has since been deleted. */
2029 if (bs->breakpoint_at == NULL)
2030 return PRINT_UNKNOWN;
2032 switch (bs->breakpoint_at->type)
2035 case bp_hardware_breakpoint:
2036 if (bs->breakpoint_at->loc->address != bs->breakpoint_at->loc->requested_address)
2037 breakpoint_adjustment_warning (bs->breakpoint_at->loc->requested_address,
2038 bs->breakpoint_at->loc->address,
2039 bs->breakpoint_at->number, 1);
2040 annotate_breakpoint (bs->breakpoint_at->number);
2041 ui_out_text (uiout, "\nBreakpoint ");
2042 if (ui_out_is_mi_like_p (uiout))
2043 ui_out_field_string (uiout, "reason", "breakpoint-hit");
2044 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
2045 ui_out_text (uiout, ", ");
2046 return PRINT_SRC_AND_LOC;
2049 case bp_shlib_event:
2050 /* Did we stop because the user set the stop_on_solib_events
2051 variable? (If so, we report this as a generic, "Stopped due
2052 to shlib event" message.) */
2053 printf_filtered ("Stopped due to shared library event\n");
2054 return PRINT_NOTHING;
2057 case bp_thread_event:
2058 /* Not sure how we will get here.
2059 GDB should not stop for these breakpoints. */
2060 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
2061 return PRINT_NOTHING;
2064 case bp_overlay_event:
2065 /* By analogy with the thread event, GDB should not stop for these. */
2066 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
2067 return PRINT_NOTHING;
2071 annotate_catchpoint (bs->breakpoint_at->number);
2072 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2073 printf_filtered ("loaded");
2074 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2075 return PRINT_SRC_AND_LOC;
2078 case bp_catch_unload:
2079 annotate_catchpoint (bs->breakpoint_at->number);
2080 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2081 printf_filtered ("unloaded");
2082 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2083 return PRINT_SRC_AND_LOC;
2087 annotate_catchpoint (bs->breakpoint_at->number);
2088 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2089 printf_filtered ("forked");
2090 printf_filtered (" process %d), ",
2091 bs->breakpoint_at->forked_inferior_pid);
2092 return PRINT_SRC_AND_LOC;
2095 case bp_catch_vfork:
2096 annotate_catchpoint (bs->breakpoint_at->number);
2097 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2098 printf_filtered ("vforked");
2099 printf_filtered (" process %d), ",
2100 bs->breakpoint_at->forked_inferior_pid);
2101 return PRINT_SRC_AND_LOC;
2105 annotate_catchpoint (bs->breakpoint_at->number);
2106 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2107 bs->breakpoint_at->number,
2108 bs->breakpoint_at->exec_pathname);
2109 return PRINT_SRC_AND_LOC;
2112 case bp_catch_catch:
2113 if (current_exception_event &&
2114 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
2116 annotate_catchpoint (bs->breakpoint_at->number);
2117 printf_filtered ("\nCatchpoint %d (exception caught), ",
2118 bs->breakpoint_at->number);
2119 printf_filtered ("throw location ");
2120 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2121 printf_filtered ("%s:%d",
2122 CURRENT_EXCEPTION_THROW_FILE,
2123 CURRENT_EXCEPTION_THROW_LINE);
2125 printf_filtered ("unknown");
2127 printf_filtered (", catch location ");
2128 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2129 printf_filtered ("%s:%d",
2130 CURRENT_EXCEPTION_CATCH_FILE,
2131 CURRENT_EXCEPTION_CATCH_LINE);
2133 printf_filtered ("unknown");
2135 printf_filtered ("\n");
2136 /* don't bother to print location frame info */
2137 return PRINT_SRC_ONLY;
2141 /* really throw, some other bpstat will handle it */
2142 return PRINT_UNKNOWN;
2146 case bp_catch_throw:
2147 if (current_exception_event &&
2148 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2150 annotate_catchpoint (bs->breakpoint_at->number);
2151 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2152 bs->breakpoint_at->number);
2153 printf_filtered ("throw location ");
2154 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2155 printf_filtered ("%s:%d",
2156 CURRENT_EXCEPTION_THROW_FILE,
2157 CURRENT_EXCEPTION_THROW_LINE);
2159 printf_filtered ("unknown");
2161 printf_filtered (", catch location ");
2162 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2163 printf_filtered ("%s:%d",
2164 CURRENT_EXCEPTION_CATCH_FILE,
2165 CURRENT_EXCEPTION_CATCH_LINE);
2167 printf_filtered ("unknown");
2169 printf_filtered ("\n");
2170 /* don't bother to print location frame info */
2171 return PRINT_SRC_ONLY;
2175 /* really catch, some other bpstat will handle it */
2176 return PRINT_UNKNOWN;
2181 case bp_hardware_watchpoint:
2182 if (bs->old_val != NULL)
2184 annotate_watchpoint (bs->breakpoint_at->number);
2185 if (ui_out_is_mi_like_p (uiout))
2186 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2187 mention (bs->breakpoint_at);
2188 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2189 ui_out_text (uiout, "\nOld value = ");
2190 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2191 ui_out_field_stream (uiout, "old", stb);
2192 ui_out_text (uiout, "\nNew value = ");
2193 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2194 ui_out_field_stream (uiout, "new", stb);
2195 do_cleanups (ui_out_chain);
2196 ui_out_text (uiout, "\n");
2197 value_free (bs->old_val);
2200 /* More than one watchpoint may have been triggered. */
2201 return PRINT_UNKNOWN;
2204 case bp_read_watchpoint:
2205 if (ui_out_is_mi_like_p (uiout))
2206 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2207 mention (bs->breakpoint_at);
2208 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2209 ui_out_text (uiout, "\nValue = ");
2210 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2211 ui_out_field_stream (uiout, "value", stb);
2212 do_cleanups (ui_out_chain);
2213 ui_out_text (uiout, "\n");
2214 return PRINT_UNKNOWN;
2217 case bp_access_watchpoint:
2218 if (bs->old_val != NULL)
2220 annotate_watchpoint (bs->breakpoint_at->number);
2221 if (ui_out_is_mi_like_p (uiout))
2222 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2223 mention (bs->breakpoint_at);
2224 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2225 ui_out_text (uiout, "\nOld value = ");
2226 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2227 ui_out_field_stream (uiout, "old", stb);
2228 value_free (bs->old_val);
2230 ui_out_text (uiout, "\nNew value = ");
2234 mention (bs->breakpoint_at);
2235 if (ui_out_is_mi_like_p (uiout))
2236 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2237 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2238 ui_out_text (uiout, "\nValue = ");
2240 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2241 ui_out_field_stream (uiout, "new", stb);
2242 do_cleanups (ui_out_chain);
2243 ui_out_text (uiout, "\n");
2244 return PRINT_UNKNOWN;
2247 /* Fall through, we don't deal with these types of breakpoints
2251 if (ui_out_is_mi_like_p (uiout))
2252 ui_out_field_string (uiout, "reason", "function-finished");
2253 return PRINT_UNKNOWN;
2257 if (ui_out_is_mi_like_p (uiout))
2258 ui_out_field_string (uiout, "reason", "location-reached");
2259 return PRINT_UNKNOWN;
2264 case bp_longjmp_resume:
2265 case bp_step_resume:
2266 case bp_through_sigtramp:
2267 case bp_watchpoint_scope:
2270 return PRINT_UNKNOWN;
2274 /* Generic routine for printing messages indicating why we
2275 stopped. The behavior of this function depends on the value
2276 'print_it' in the bpstat structure. Under some circumstances we
2277 may decide not to print anything here and delegate the task to
2280 static enum print_stop_action
2281 print_bp_stop_message (bpstat bs)
2283 switch (bs->print_it)
2286 /* Nothing should be printed for this bpstat entry. */
2287 return PRINT_UNKNOWN;
2291 /* We still want to print the frame, but we already printed the
2292 relevant messages. */
2293 return PRINT_SRC_AND_LOC;
2296 case print_it_normal:
2297 /* Normal case. Call the breakpoint's print_it method, or
2298 print_it_typical. */
2299 if (bs->breakpoint_at != NULL && bs->breakpoint_at->ops != NULL
2300 && bs->breakpoint_at->ops->print_it != NULL)
2301 return bs->breakpoint_at->ops->print_it (bs->breakpoint_at);
2303 return print_it_typical (bs);
2307 internal_error (__FILE__, __LINE__,
2308 "print_bp_stop_message: unrecognized enum value");
2313 /* Print a message indicating what happened. This is called from
2314 normal_stop(). The input to this routine is the head of the bpstat
2315 list - a list of the eventpoints that caused this stop. This
2316 routine calls the generic print routine for printing a message
2317 about reasons for stopping. This will print (for example) the
2318 "Breakpoint n," part of the output. The return value of this
2321 PRINT_UNKNOWN: Means we printed nothing
2322 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2323 code to print the location. An example is
2324 "Breakpoint 1, " which should be followed by
2326 PRINT_SRC_ONLY: Means we printed something, but there is no need
2327 to also print the location part of the message.
2328 An example is the catch/throw messages, which
2329 don't require a location appended to the end.
2330 PRINT_NOTHING: We have done some printing and we don't need any
2331 further info to be printed.*/
2333 enum print_stop_action
2334 bpstat_print (bpstat bs)
2338 /* Maybe another breakpoint in the chain caused us to stop.
2339 (Currently all watchpoints go on the bpstat whether hit or not.
2340 That probably could (should) be changed, provided care is taken
2341 with respect to bpstat_explains_signal). */
2342 for (; bs; bs = bs->next)
2344 val = print_bp_stop_message (bs);
2345 if (val == PRINT_SRC_ONLY
2346 || val == PRINT_SRC_AND_LOC
2347 || val == PRINT_NOTHING)
2351 /* We reached the end of the chain, or we got a null BS to start
2352 with and nothing was printed. */
2353 return PRINT_UNKNOWN;
2356 /* Evaluate the expression EXP and return 1 if value is zero.
2357 This is used inside a catch_errors to evaluate the breakpoint condition.
2358 The argument is a "struct expression *" that has been cast to char * to
2359 make it pass through catch_errors. */
2362 breakpoint_cond_eval (void *exp)
2364 struct value *mark = value_mark ();
2365 int i = !value_true (evaluate_expression ((struct expression *) exp));
2366 value_free_to_mark (mark);
2370 /* Allocate a new bpstat and chain it to the current one. */
2373 bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
2377 bs = (bpstat) xmalloc (sizeof (*bs));
2379 bs->breakpoint_at = b;
2380 /* If the condition is false, etc., don't do the commands. */
2381 bs->commands = NULL;
2383 bs->print_it = print_it_normal;
2387 /* Possible return values for watchpoint_check (this can't be an enum
2388 because of check_errors). */
2389 /* The watchpoint has been deleted. */
2390 #define WP_DELETED 1
2391 /* The value has changed. */
2392 #define WP_VALUE_CHANGED 2
2393 /* The value has not changed. */
2394 #define WP_VALUE_NOT_CHANGED 3
2396 #define BP_TEMPFLAG 1
2397 #define BP_HARDWAREFLAG 2
2399 /* Check watchpoint condition. */
2402 watchpoint_check (void *p)
2404 bpstat bs = (bpstat) p;
2405 struct breakpoint *b;
2406 struct frame_info *fr;
2407 int within_current_scope;
2409 struct frame_id current_frame_id;
2412 b = bs->breakpoint_at;
2414 if (b->exp_valid_block == NULL)
2415 within_current_scope = 1;
2418 /* There is no current frame at this moment. If we're going to have
2419 any chance of handling watchpoints on local variables, we'll need
2420 the frame chain (so we can determine if we're in scope). */
2421 reinit_frame_cache ();
2422 fr = frame_find_by_id (b->watchpoint_frame);
2423 within_current_scope = (fr != NULL);
2424 /* in_function_epilogue_p() returns a non-zero value if we're still
2425 in the function but the stack frame has already been invalidated.
2426 Since we can't rely on the values of local variables after the
2427 stack has been destroyed, we are treating the watchpoint in that
2428 state as `not changed' without further checking.
2430 vinschen/2003-09-04: The former implementation left out the case
2431 that the watchpoint frame couldn't be found by frame_find_by_id()
2432 because the current PC is currently in an epilogue. Calling
2433 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2434 if ((!within_current_scope || fr == get_current_frame ())
2435 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2436 return WP_VALUE_NOT_CHANGED;
2437 if (fr && within_current_scope)
2438 /* If we end up stopping, the current frame will get selected
2439 in normal_stop. So this call to select_frame won't affect
2444 if (within_current_scope)
2446 /* We use value_{,free_to_}mark because it could be a
2447 *long* time before we return to the command level and
2448 call free_all_values. We can't call free_all_values because
2449 we might be in the middle of evaluating a function call. */
2451 struct value *mark = value_mark ();
2452 struct value *new_val = evaluate_expression (bs->breakpoint_at->exp);
2453 if (!value_equal (b->val, new_val))
2455 release_value (new_val);
2456 value_free_to_mark (mark);
2457 bs->old_val = b->val;
2459 /* We will stop here */
2460 return WP_VALUE_CHANGED;
2464 /* Nothing changed, don't do anything. */
2465 value_free_to_mark (mark);
2466 /* We won't stop here */
2467 return WP_VALUE_NOT_CHANGED;
2472 /* This seems like the only logical thing to do because
2473 if we temporarily ignored the watchpoint, then when
2474 we reenter the block in which it is valid it contains
2475 garbage (in the case of a function, it may have two
2476 garbage values, one before and one after the prologue).
2477 So we can't even detect the first assignment to it and
2478 watch after that (since the garbage may or may not equal
2479 the first value assigned). */
2480 /* We print all the stop information in print_it_typical(), but
2481 in this case, by the time we call print_it_typical() this bp
2482 will be deleted already. So we have no choice but print the
2483 information here. */
2484 if (ui_out_is_mi_like_p (uiout))
2485 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2486 ui_out_text (uiout, "\nWatchpoint ");
2487 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2488 ui_out_text (uiout, " deleted because the program has left the block in\n\
2489 which its expression is valid.\n");
2491 if (b->related_breakpoint)
2492 b->related_breakpoint->disposition = disp_del_at_next_stop;
2493 b->disposition = disp_del_at_next_stop;
2499 /* Get a bpstat associated with having just stopped at address *PC
2500 and frame address CORE_ADDRESS. Update *PC to point at the
2501 breakpoint (if we hit a breakpoint). NOT_A_SW_BREAKPOINT is nonzero
2502 if this is known to not be a real breakpoint (it could still be a
2503 watchpoint, though). */
2505 /* Determine whether we stopped at a breakpoint, etc, or whether we
2506 don't understand this stop. Result is a chain of bpstat's such that:
2508 if we don't understand the stop, the result is a null pointer.
2510 if we understand why we stopped, the result is not null.
2512 Each element of the chain refers to a particular breakpoint or
2513 watchpoint at which we have stopped. (We may have stopped for
2514 several reasons concurrently.)
2516 Each element of the chain has valid next, breakpoint_at,
2517 commands, FIXME??? fields. */
2520 bpstat_stop_status (CORE_ADDR *pc, int not_a_sw_breakpoint)
2522 struct breakpoint *b, *temp;
2524 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2525 int real_breakpoint = 0;
2526 /* Root of the chain of bpstat's */
2527 struct bpstats root_bs[1];
2528 /* Pointer to the last thing in the chain currently. */
2529 bpstat bs = root_bs;
2531 /* Get the address where the breakpoint would have been. The
2532 "not_a_sw_breakpoint" argument is meant to distinguish between a
2533 breakpoint trap event and a trace/singlestep trap event. For a
2534 trace/singlestep trap event, we would not want to subtract
2535 DECR_PC_AFTER_BREAK from the PC. */
2537 bp_addr = *pc - (not_a_sw_breakpoint ? 0 : DECR_PC_AFTER_BREAK);
2539 ALL_BREAKPOINTS_SAFE (b, temp)
2541 if (b->enable_state == bp_disabled
2542 || b->enable_state == bp_shlib_disabled
2543 || b->enable_state == bp_call_disabled)
2546 if (b->type != bp_watchpoint
2547 && b->type != bp_hardware_watchpoint
2548 && b->type != bp_read_watchpoint
2549 && b->type != bp_access_watchpoint
2550 && b->type != bp_hardware_breakpoint
2551 && b->type != bp_catch_fork
2552 && b->type != bp_catch_vfork
2553 && b->type != bp_catch_exec
2554 && b->type != bp_catch_catch
2555 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2557 if (b->loc->address != bp_addr) /* address doesn't match */
2559 if (overlay_debugging /* unmapped overlay section */
2560 && section_is_overlay (b->section)
2561 && !section_is_mapped (b->section))
2565 if (b->type == bp_hardware_breakpoint)
2567 if (b->loc->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2569 if (overlay_debugging /* unmapped overlay section */
2570 && section_is_overlay (b->section)
2571 && !section_is_mapped (b->section))
2575 /* Is this a catchpoint of a load or unload? If so, did we
2576 get a load or unload of the specified library? If not,
2578 if ((b->type == bp_catch_load)
2579 #if defined(SOLIB_HAVE_LOAD_EVENT)
2580 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2581 || ((b->dll_pathname != NULL)
2582 && (strcmp (b->dll_pathname,
2583 SOLIB_LOADED_LIBRARY_PATHNAME (
2584 PIDGET (inferior_ptid)))
2590 if ((b->type == bp_catch_unload)
2591 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2592 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2593 || ((b->dll_pathname != NULL)
2594 && (strcmp (b->dll_pathname,
2595 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2596 PIDGET (inferior_ptid)))
2602 if ((b->type == bp_catch_fork)
2603 && !inferior_has_forked (PIDGET (inferior_ptid),
2604 &b->forked_inferior_pid))
2607 if ((b->type == bp_catch_vfork)
2608 && !inferior_has_vforked (PIDGET (inferior_ptid),
2609 &b->forked_inferior_pid))
2612 if ((b->type == bp_catch_exec)
2613 && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2616 if (ep_is_exception_catchpoint (b) &&
2617 !(current_exception_event = target_get_current_exception_event ()))
2620 /* Come here if it's a watchpoint, or if the break address matches */
2622 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2624 /* Watchpoints may change this, if not found to have triggered. */
2628 if (b->type == bp_watchpoint ||
2629 b->type == bp_hardware_watchpoint)
2631 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2633 struct cleanup *cleanups = make_cleanup (xfree, message);
2634 int e = catch_errors (watchpoint_check, bs, message,
2636 do_cleanups (cleanups);
2640 /* We've already printed what needs to be printed. */
2641 /* Actually this is superfluous, because by the time we
2642 call print_it_typical() the wp will be already deleted,
2643 and the function will return immediately. */
2644 bs->print_it = print_it_done;
2647 case WP_VALUE_CHANGED:
2651 case WP_VALUE_NOT_CHANGED:
2653 bs->print_it = print_it_noop;
2660 /* Error from catch_errors. */
2661 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2662 if (b->related_breakpoint)
2663 b->related_breakpoint->disposition = disp_del_at_next_stop;
2664 b->disposition = disp_del_at_next_stop;
2665 /* We've already printed what needs to be printed. */
2666 bs->print_it = print_it_done;
2672 else if (b->type == bp_read_watchpoint ||
2673 b->type == bp_access_watchpoint)
2679 addr = target_stopped_data_address ();
2682 for (v = b->val_chain; v; v = v->next)
2684 if (VALUE_LVAL (v) == lval_memory
2685 && ! VALUE_LAZY (v))
2687 struct type *vtype = check_typedef (VALUE_TYPE (v));
2689 if (v == b->val_chain
2690 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2691 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2695 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2696 /* Exact match not required. Within range is
2698 if (addr >= vaddr &&
2699 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2706 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2708 struct cleanup *cleanups = make_cleanup (xfree, message);
2709 int e = catch_errors (watchpoint_check, bs, message,
2711 do_cleanups (cleanups);
2715 /* We've already printed what needs to be printed. */
2716 bs->print_it = print_it_done;
2719 case WP_VALUE_CHANGED:
2720 if (b->type == bp_read_watchpoint)
2722 /* Don't stop: read watchpoints shouldn't fire if
2723 the value has changed. This is for targets
2724 which cannot set read-only watchpoints. */
2725 bs->print_it = print_it_noop;
2731 case WP_VALUE_NOT_CHANGED:
2738 /* Error from catch_errors. */
2739 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2740 if (b->related_breakpoint)
2741 b->related_breakpoint->disposition = disp_del_at_next_stop;
2742 b->disposition = disp_del_at_next_stop;
2743 /* We've already printed what needs to be printed. */
2744 bs->print_it = print_it_done;
2748 else /* found == 0 */
2750 /* This is a case where some watchpoint(s) triggered,
2751 but not at the address of this watchpoint (FOUND
2752 was left zero). So don't print anything for this
2754 bs->print_it = print_it_noop;
2761 /* By definition, an encountered breakpoint is a triggered
2765 real_breakpoint = 1;
2768 if (frame_id_p (b->frame_id)
2769 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
2773 int value_is_zero = 0;
2777 /* Need to select the frame, with all that implies
2778 so that the conditions will have the right context. */
2779 select_frame (get_current_frame ());
2781 = catch_errors (breakpoint_cond_eval, (b->cond),
2782 "Error in testing breakpoint condition:\n",
2784 /* FIXME-someday, should give breakpoint # */
2787 if (b->cond && value_is_zero)
2790 /* Don't consider this a hit. */
2793 else if (b->ignore_count > 0)
2796 annotate_ignore_count_change ();
2801 /* We will stop here */
2802 if (b->disposition == disp_disable)
2803 b->enable_state = bp_disabled;
2806 bs->commands = b->commands;
2808 (STREQ ("silent", bs->commands->line) ||
2809 (xdb_commands && STREQ ("Q", bs->commands->line))))
2811 bs->commands = bs->commands->next;
2814 bs->commands = copy_command_lines (bs->commands);
2817 /* Print nothing for this entry if we dont stop or if we dont print. */
2818 if (bs->stop == 0 || bs->print == 0)
2819 bs->print_it = print_it_noop;
2822 bs->next = NULL; /* Terminate the chain */
2823 bs = root_bs->next; /* Re-grab the head of the chain */
2825 if (real_breakpoint && bs)
2827 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2829 if (DECR_PC_AFTER_HW_BREAK != 0)
2831 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2837 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2840 #if defined (SHIFT_INST_REGS)
2842 #else /* No SHIFT_INST_REGS. */
2844 #endif /* No SHIFT_INST_REGS. */
2849 /* The value of a hardware watchpoint hasn't changed, but the
2850 intermediate memory locations we are watching may have. */
2851 if (bs && !bs->stop &&
2852 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2853 bs->breakpoint_at->type == bp_read_watchpoint ||
2854 bs->breakpoint_at->type == bp_access_watchpoint))
2856 remove_breakpoints ();
2857 insert_breakpoints ();
2862 /* Tell what to do about this bpstat. */
2864 bpstat_what (bpstat bs)
2866 /* Classify each bpstat as one of the following. */
2869 /* This bpstat element has no effect on the main_action. */
2872 /* There was a watchpoint, stop but don't print. */
2875 /* There was a watchpoint, stop and print. */
2878 /* There was a breakpoint but we're not stopping. */
2881 /* There was a breakpoint, stop but don't print. */
2884 /* There was a breakpoint, stop and print. */
2887 /* We hit the longjmp breakpoint. */
2890 /* We hit the longjmp_resume breakpoint. */
2893 /* We hit the step_resume breakpoint. */
2896 /* We hit the through_sigtramp breakpoint. */
2899 /* We hit the shared library event breakpoint. */
2902 /* We caught a shared library event. */
2905 /* This is just used to count how many enums there are. */
2909 /* Here is the table which drives this routine. So that we can
2910 format it pretty, we define some abbreviations for the
2911 enum bpstat_what codes. */
2912 #define kc BPSTAT_WHAT_KEEP_CHECKING
2913 #define ss BPSTAT_WHAT_STOP_SILENT
2914 #define sn BPSTAT_WHAT_STOP_NOISY
2915 #define sgl BPSTAT_WHAT_SINGLE
2916 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2917 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2918 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2919 #define sr BPSTAT_WHAT_STEP_RESUME
2920 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2921 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2922 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2924 /* "Can't happen." Might want to print an error message.
2925 abort() is not out of the question, but chances are GDB is just
2926 a bit confused, not unusable. */
2927 #define err BPSTAT_WHAT_STOP_NOISY
2929 /* Given an old action and a class, come up with a new action. */
2930 /* One interesting property of this table is that wp_silent is the same
2931 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2932 after stopping, the check for whether to step over a breakpoint
2933 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2934 reference to how we stopped. We retain separate wp_silent and
2935 bp_silent codes in case we want to change that someday.
2937 Another possibly interesting property of this table is that
2938 there's a partial ordering, priority-like, of the actions. Once
2939 you've decided that some action is appropriate, you'll never go
2940 back and decide something of a lower priority is better. The
2943 kc < clr sgl shl shlr slr sn sr ss ts
2944 sgl < clrs shl shlr slr sn sr ss ts
2945 slr < err shl shlr sn sr ss ts
2946 clr < clrs err shl shlr sn sr ss ts
2947 clrs < err shl shlr sn sr ss ts
2948 ss < shl shlr sn sr ts
2955 What I think this means is that we don't need a damned table
2956 here. If you just put the rows and columns in the right order,
2957 it'd look awfully regular. We could simply walk the bpstat list
2958 and choose the highest priority action we find, with a little
2959 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2960 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2961 is messy anyway). */
2963 /* step_resume entries: a step resume breakpoint overrides another
2964 breakpoint of signal handling (see comment in wait_for_inferior
2965 at first PC_IN_SIGTRAMP where we set the step_resume breakpoint). */
2966 /* We handle the through_sigtramp_breakpoint the same way; having both
2967 one of those and a step_resume_breakpoint is probably very rare (?). */
2969 static const enum bpstat_what_main_action
2970 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2973 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2976 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2978 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2980 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2982 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2984 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2986 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2988 {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr},
2990 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2992 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2994 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2996 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2998 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
3013 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3014 struct bpstat_what retval;
3016 retval.call_dummy = 0;
3017 for (; bs != NULL; bs = bs->next)
3019 enum class bs_class = no_effect;
3020 if (bs->breakpoint_at == NULL)
3021 /* I suspect this can happen if it was a momentary breakpoint
3022 which has since been deleted. */
3024 switch (bs->breakpoint_at->type)
3030 case bp_hardware_breakpoint:
3036 bs_class = bp_noisy;
3038 bs_class = bp_silent;
3041 bs_class = bp_nostop;
3044 case bp_hardware_watchpoint:
3045 case bp_read_watchpoint:
3046 case bp_access_watchpoint:
3050 bs_class = wp_noisy;
3052 bs_class = wp_silent;
3055 /* There was a watchpoint, but we're not stopping.
3056 This requires no further action. */
3057 bs_class = no_effect;
3060 bs_class = long_jump;
3062 case bp_longjmp_resume:
3063 bs_class = long_resume;
3065 case bp_step_resume:
3068 bs_class = step_resume;
3071 /* It is for the wrong frame. */
3072 bs_class = bp_nostop;
3074 case bp_through_sigtramp:
3075 bs_class = through_sig;
3077 case bp_watchpoint_scope:
3078 bs_class = bp_nostop;
3080 case bp_shlib_event:
3081 bs_class = shlib_event;
3083 case bp_thread_event:
3084 case bp_overlay_event:
3085 bs_class = bp_nostop;
3088 case bp_catch_unload:
3089 /* Only if this catchpoint triggered should we cause the
3090 step-out-of-dld behaviour. Otherwise, we ignore this
3093 bs_class = catch_shlib_event;
3095 bs_class = no_effect;
3098 case bp_catch_vfork:
3103 bs_class = bp_noisy;
3105 bs_class = bp_silent;
3108 /* There was a catchpoint, but we're not stopping.
3109 This requires no further action. */
3110 bs_class = no_effect;
3112 case bp_catch_catch:
3113 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
3114 bs_class = bp_nostop;
3116 bs_class = bs->print ? bp_noisy : bp_silent;
3118 case bp_catch_throw:
3119 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
3120 bs_class = bp_nostop;
3122 bs_class = bs->print ? bp_noisy : bp_silent;
3125 /* Make sure the action is stop (silent or noisy),
3126 so infrun.c pops the dummy frame. */
3127 bs_class = bp_silent;
3128 retval.call_dummy = 1;
3131 current_action = table[(int) bs_class][(int) current_action];
3133 retval.main_action = current_action;
3137 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3138 without hardware support). This isn't related to a specific bpstat,
3139 just to things like whether watchpoints are set. */
3142 bpstat_should_step (void)
3144 struct breakpoint *b;
3146 if (b->enable_state == bp_enabled && b->type == bp_watchpoint)
3151 /* Nonzero if there are enabled hardware watchpoints. */
3153 bpstat_have_active_hw_watchpoints (void)
3155 struct breakpoint *b;
3157 if ((b->enable_state == bp_enabled) &&
3158 (b->loc->inserted) &&
3159 ((b->type == bp_hardware_watchpoint) ||
3160 (b->type == bp_read_watchpoint) ||
3161 (b->type == bp_access_watchpoint)))
3167 /* Given a bpstat that records zero or more triggered eventpoints, this
3168 function returns another bpstat which contains only the catchpoints
3169 on that first list, if any. */
3171 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3173 struct bpstats root_bs[1];
3174 bpstat bs = root_bs;
3175 struct breakpoint *ep;
3178 bpstat_clear (cp_list);
3179 root_bs->next = NULL;
3181 for (; ep_list != NULL; ep_list = ep_list->next)
3183 /* Is this eventpoint a catchpoint? If not, ignore it. */
3184 ep = ep_list->breakpoint_at;
3187 if ((ep->type != bp_catch_load) &&
3188 (ep->type != bp_catch_unload) &&
3189 (ep->type != bp_catch_catch) &&
3190 (ep->type != bp_catch_throw))
3191 /* pai: (temp) ADD fork/vfork here!! */
3194 /* Yes; add it to the list. */
3195 bs = bpstat_alloc (ep, bs);
3200 #if defined(SOLIB_ADD)
3201 /* Also, for each triggered catchpoint, tag it with the name of
3202 the library that caused this trigger. (We copy the name now,
3203 because it's only guaranteed to be available NOW, when the
3204 catchpoint triggers. Clients who may wish to know the name
3205 later must get it from the catchpoint itself.) */
3206 if (ep->triggered_dll_pathname != NULL)
3207 xfree (ep->triggered_dll_pathname);
3208 if (ep->type == bp_catch_load)
3209 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3210 PIDGET (inferior_ptid));
3212 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3213 PIDGET (inferior_ptid));
3215 dll_pathname = NULL;
3219 ep->triggered_dll_pathname = (char *)
3220 xmalloc (strlen (dll_pathname) + 1);
3221 strcpy (ep->triggered_dll_pathname, dll_pathname);
3224 ep->triggered_dll_pathname = NULL;
3230 /* Print B to gdb_stdout. */
3232 print_one_breakpoint (struct breakpoint *b,
3233 CORE_ADDR *last_addr)
3235 struct command_line *l;
3237 struct ep_type_description
3242 static struct ep_type_description bptypes[] =
3244 {bp_none, "?deleted?"},
3245 {bp_breakpoint, "breakpoint"},
3246 {bp_hardware_breakpoint, "hw breakpoint"},
3247 {bp_until, "until"},
3248 {bp_finish, "finish"},
3249 {bp_watchpoint, "watchpoint"},
3250 {bp_hardware_watchpoint, "hw watchpoint"},
3251 {bp_read_watchpoint, "read watchpoint"},
3252 {bp_access_watchpoint, "acc watchpoint"},
3253 {bp_longjmp, "longjmp"},
3254 {bp_longjmp_resume, "longjmp resume"},
3255 {bp_step_resume, "step resume"},
3256 {bp_through_sigtramp, "sigtramp"},
3257 {bp_watchpoint_scope, "watchpoint scope"},
3258 {bp_call_dummy, "call dummy"},
3259 {bp_shlib_event, "shlib events"},
3260 {bp_thread_event, "thread events"},
3261 {bp_overlay_event, "overlay events"},
3262 {bp_catch_load, "catch load"},
3263 {bp_catch_unload, "catch unload"},
3264 {bp_catch_fork, "catch fork"},
3265 {bp_catch_vfork, "catch vfork"},
3266 {bp_catch_exec, "catch exec"},
3267 {bp_catch_catch, "catch catch"},
3268 {bp_catch_throw, "catch throw"}
3271 static char *bpdisps[] =
3272 {"del", "dstp", "dis", "keep"};
3273 static char bpenables[] = "nynny";
3274 char wrap_indent[80];
3275 struct ui_stream *stb = ui_out_stream_new (uiout);
3276 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3277 struct cleanup *bkpt_chain;
3280 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3284 ui_out_field_int (uiout, "number", b->number);
3288 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3289 || ((int) b->type != bptypes[(int) b->type].type))
3290 internal_error (__FILE__, __LINE__,
3291 "bptypes table does not describe type #%d.",
3293 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3297 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3301 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]);
3302 ui_out_spaces (uiout, 2);
3305 strcpy (wrap_indent, " ");
3308 if (TARGET_ADDR_BIT <= 32)
3309 strcat (wrap_indent, " ");
3311 strcat (wrap_indent, " ");
3314 if (b->ops != NULL && b->ops->print_one != NULL)
3315 b->ops->print_one (b, last_addr);
3320 internal_error (__FILE__, __LINE__,
3321 "print_one_breakpoint: bp_none encountered\n");
3325 case bp_hardware_watchpoint:
3326 case bp_read_watchpoint:
3327 case bp_access_watchpoint:
3328 /* Field 4, the address, is omitted (which makes the columns
3329 not line up too nicely with the headers, but the effect
3330 is relatively readable). */
3332 ui_out_field_skip (uiout, "addr");
3334 print_expression (b->exp, stb->stream);
3335 ui_out_field_stream (uiout, "what", stb);
3339 case bp_catch_unload:
3340 /* Field 4, the address, is omitted (which makes the columns
3341 not line up too nicely with the headers, but the effect
3342 is relatively readable). */
3344 ui_out_field_skip (uiout, "addr");
3346 if (b->dll_pathname == NULL)
3348 ui_out_field_string (uiout, "what", "<any library>");
3349 ui_out_spaces (uiout, 1);
3353 ui_out_text (uiout, "library \"");
3354 ui_out_field_string (uiout, "what", b->dll_pathname);
3355 ui_out_text (uiout, "\" ");
3360 case bp_catch_vfork:
3361 /* Field 4, the address, is omitted (which makes the columns
3362 not line up too nicely with the headers, but the effect
3363 is relatively readable). */
3365 ui_out_field_skip (uiout, "addr");
3367 if (b->forked_inferior_pid != 0)
3369 ui_out_text (uiout, "process ");
3370 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3371 ui_out_spaces (uiout, 1);
3375 /* Field 4, the address, is omitted (which makes the columns
3376 not line up too nicely with the headers, but the effect
3377 is relatively readable). */
3379 ui_out_field_skip (uiout, "addr");
3381 if (b->exec_pathname != NULL)
3383 ui_out_text (uiout, "program \"");
3384 ui_out_field_string (uiout, "what", b->exec_pathname);
3385 ui_out_text (uiout, "\" ");
3389 case bp_catch_catch:
3390 /* Field 4, the address, is omitted (which makes the columns
3391 not line up too nicely with the headers, but the effect
3392 is relatively readable). */
3394 ui_out_field_skip (uiout, "addr");
3396 ui_out_field_string (uiout, "what", "exception catch");
3397 ui_out_spaces (uiout, 1);
3400 case bp_catch_throw:
3401 /* Field 4, the address, is omitted (which makes the columns
3402 not line up too nicely with the headers, but the effect
3403 is relatively readable). */
3405 ui_out_field_skip (uiout, "addr");
3407 ui_out_field_string (uiout, "what", "exception throw");
3408 ui_out_spaces (uiout, 1);
3412 case bp_hardware_breakpoint:
3416 case bp_longjmp_resume:
3417 case bp_step_resume:
3418 case bp_through_sigtramp:
3419 case bp_watchpoint_scope:
3421 case bp_shlib_event:
3422 case bp_thread_event:
3423 case bp_overlay_event:
3427 ui_out_field_core_addr (uiout, "addr", b->loc->address);
3430 *last_addr = b->loc->address;
3433 sym = find_pc_sect_function (b->loc->address, b->section);
3436 ui_out_text (uiout, "in ");
3437 ui_out_field_string (uiout, "func",
3438 SYMBOL_PRINT_NAME (sym));
3439 ui_out_wrap_hint (uiout, wrap_indent);
3440 ui_out_text (uiout, " at ");
3442 ui_out_field_string (uiout, "file", b->source_file);
3443 ui_out_text (uiout, ":");
3444 ui_out_field_int (uiout, "line", b->line_number);
3448 print_address_symbolic (b->loc->address, stb->stream, demangle, "");
3449 ui_out_field_stream (uiout, "at", stb);
3454 if (b->thread != -1)
3456 /* FIXME: This seems to be redundant and lost here; see the
3457 "stop only in" line a little further down. */
3458 ui_out_text (uiout, " thread ");
3459 ui_out_field_int (uiout, "thread", b->thread);
3462 ui_out_text (uiout, "\n");
3464 if (frame_id_p (b->frame_id))
3467 ui_out_text (uiout, "\tstop only in stack frame at ");
3468 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3470 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3471 ui_out_text (uiout, "\n");
3477 ui_out_text (uiout, "\tstop only if ");
3478 print_expression (b->cond, stb->stream);
3479 ui_out_field_stream (uiout, "cond", stb);
3480 ui_out_text (uiout, "\n");
3483 if (b->thread != -1)
3485 /* FIXME should make an annotation for this */
3486 ui_out_text (uiout, "\tstop only in thread ");
3487 ui_out_field_int (uiout, "thread", b->thread);
3488 ui_out_text (uiout, "\n");
3491 if (show_breakpoint_hit_counts && b->hit_count)
3493 /* FIXME should make an annotation for this */
3494 if (ep_is_catchpoint (b))
3495 ui_out_text (uiout, "\tcatchpoint");
3497 ui_out_text (uiout, "\tbreakpoint");
3498 ui_out_text (uiout, " already hit ");
3499 ui_out_field_int (uiout, "times", b->hit_count);
3500 if (b->hit_count == 1)
3501 ui_out_text (uiout, " time\n");
3503 ui_out_text (uiout, " times\n");
3506 /* Output the count also if it is zero, but only if this is
3507 mi. FIXME: Should have a better test for this. */
3508 if (ui_out_is_mi_like_p (uiout))
3509 if (show_breakpoint_hit_counts && b->hit_count == 0)
3510 ui_out_field_int (uiout, "times", b->hit_count);
3512 if (b->ignore_count)
3515 ui_out_text (uiout, "\tignore next ");
3516 ui_out_field_int (uiout, "ignore", b->ignore_count);
3517 ui_out_text (uiout, " hits\n");
3520 if ((l = b->commands))
3522 struct cleanup *script_chain;
3525 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3526 print_command_lines (uiout, l, 4);
3527 do_cleanups (script_chain);
3529 do_cleanups (bkpt_chain);
3530 do_cleanups (old_chain);
3533 struct captured_breakpoint_query_args
3539 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3541 struct captured_breakpoint_query_args *args = data;
3542 struct breakpoint *b;
3543 CORE_ADDR dummy_addr = 0;
3546 if (args->bnum == b->number)
3548 print_one_breakpoint (b, &dummy_addr);
3556 gdb_breakpoint_query (struct ui_out *uiout, int bnum)
3558 struct captured_breakpoint_query_args args;
3560 /* For the moment we don't trust print_one_breakpoint() to not throw
3562 return catch_exceptions (uiout, do_captured_breakpoint_query, &args,
3563 NULL, RETURN_MASK_ALL);
3566 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3567 catchpoints, et.al.). */
3570 user_settable_breakpoint (const struct breakpoint *b)
3572 return (b->type == bp_breakpoint
3573 || b->type == bp_catch_load
3574 || b->type == bp_catch_unload
3575 || b->type == bp_catch_fork
3576 || b->type == bp_catch_vfork
3577 || b->type == bp_catch_exec
3578 || b->type == bp_catch_catch
3579 || b->type == bp_catch_throw
3580 || b->type == bp_hardware_breakpoint
3581 || b->type == bp_watchpoint
3582 || b->type == bp_read_watchpoint
3583 || b->type == bp_access_watchpoint
3584 || b->type == bp_hardware_watchpoint);
3587 /* Print information on user settable breakpoint (watchpoint, etc)
3588 number BNUM. If BNUM is -1 print all user settable breakpoints.
3589 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3592 breakpoint_1 (int bnum, int allflag)
3594 struct breakpoint *b;
3595 CORE_ADDR last_addr = (CORE_ADDR) -1;
3596 int nr_printable_breakpoints;
3597 struct cleanup *bkpttbl_chain;
3599 /* Compute the number of rows in the table. */
3600 nr_printable_breakpoints = 0;
3603 || bnum == b->number)
3605 if (allflag || user_settable_breakpoint (b))
3606 nr_printable_breakpoints++;
3611 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3615 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3618 if (nr_printable_breakpoints > 0)
3619 annotate_breakpoints_headers ();
3620 if (nr_printable_breakpoints > 0)
3622 ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */
3623 if (nr_printable_breakpoints > 0)
3625 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3626 if (nr_printable_breakpoints > 0)
3628 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3629 if (nr_printable_breakpoints > 0)
3631 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3634 if (nr_printable_breakpoints > 0)
3636 if (TARGET_ADDR_BIT <= 32)
3637 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3639 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3641 if (nr_printable_breakpoints > 0)
3643 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3644 ui_out_table_body (uiout);
3645 if (nr_printable_breakpoints > 0)
3646 annotate_breakpoints_table ();
3650 || bnum == b->number)
3652 /* We only print out user settable breakpoints unless the
3654 if (allflag || user_settable_breakpoint (b))
3655 print_one_breakpoint (b, &last_addr);
3658 do_cleanups (bkpttbl_chain);
3660 if (nr_printable_breakpoints == 0)
3663 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3665 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3670 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3671 that a comparison of an unsigned with -1 is always false. */
3672 if (last_addr != (CORE_ADDR) -1)
3673 set_next_address (last_addr);
3676 /* FIXME? Should this be moved up so that it is only called when
3677 there have been breakpoints? */
3678 annotate_breakpoints_table_end ();
3682 breakpoints_info (char *bnum_exp, int from_tty)
3687 bnum = parse_and_eval_long (bnum_exp);
3689 breakpoint_1 (bnum, 0);
3693 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3698 bnum = parse_and_eval_long (bnum_exp);
3700 breakpoint_1 (bnum, 1);
3703 /* Print a message describing any breakpoints set at PC. */
3706 describe_other_breakpoints (CORE_ADDR pc, asection *section)
3709 struct breakpoint *b;
3712 if (b->loc->address == pc) /* address match / overlay match */
3713 if (!overlay_debugging || b->section == section)
3717 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3719 if (b->loc->address == pc) /* address match / overlay match */
3720 if (!overlay_debugging || b->section == section)
3723 printf_filtered ("%d%s%s ",
3725 ((b->enable_state == bp_disabled ||
3726 b->enable_state == bp_shlib_disabled ||
3727 b->enable_state == bp_call_disabled)
3729 : b->enable_state == bp_permanent
3733 : ((others == 1) ? " and" : ""));
3735 printf_filtered ("also set at pc ");
3736 print_address_numeric (pc, 1, gdb_stdout);
3737 printf_filtered (".\n");
3741 /* Set the default place to put a breakpoint
3742 for the `break' command with no arguments. */
3745 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3748 default_breakpoint_valid = valid;
3749 default_breakpoint_address = addr;
3750 default_breakpoint_symtab = symtab;
3751 default_breakpoint_line = line;
3754 /* Return true iff it is meaningful to use the address member of
3755 BPT. For some breakpoint types, the address member is irrelevant
3756 and it makes no sense to attempt to compare it to other addresses
3757 (or use it for any other purpose either).
3759 More specifically, each of the following breakpoint types will always
3760 have a zero valued address and we don't want check_duplicates() to mark
3761 breakpoints of any of these types to be a duplicate of an actual
3762 breakpoint at address zero:
3765 bp_hardware_watchpoint
3767 bp_access_watchpoint
3774 breakpoint_address_is_meaningful (struct breakpoint *bpt)
3776 enum bptype type = bpt->type;
3778 return (type != bp_watchpoint
3779 && type != bp_hardware_watchpoint
3780 && type != bp_read_watchpoint
3781 && type != bp_access_watchpoint
3782 && type != bp_catch_exec
3783 && type != bp_longjmp_resume
3784 && type != bp_catch_fork
3785 && type != bp_catch_vfork);
3788 /* Rescan breakpoints at the same address and section as BPT,
3789 marking the first one as "first" and any others as "duplicates".
3790 This is so that the bpt instruction is only inserted once.
3791 If we have a permanent breakpoint at the same place as BPT, make
3792 that one the official one, and the rest as duplicates. */
3795 check_duplicates (struct breakpoint *bpt)
3797 struct breakpoint *b;
3799 struct breakpoint *perm_bp = 0;
3800 CORE_ADDR address = bpt->loc->address;
3801 asection *section = bpt->section;
3803 if (! breakpoint_address_is_meaningful (bpt))
3807 if (b->enable_state != bp_disabled
3808 && b->enable_state != bp_shlib_disabled
3809 && b->enable_state != bp_call_disabled
3810 && b->loc->address == address /* address / overlay match */
3811 && (!overlay_debugging || b->section == section)
3812 && breakpoint_address_is_meaningful (b))
3814 /* Have we found a permanent breakpoint? */
3815 if (b->enable_state == bp_permanent)
3822 b->loc->duplicate = count > 1;
3825 /* If we found a permanent breakpoint at this address, go over the
3826 list again and declare all the other breakpoints there to be the
3830 perm_bp->loc->duplicate = 0;
3832 /* Permanent breakpoint should always be inserted. */
3833 if (! perm_bp->loc->inserted)
3834 internal_error (__FILE__, __LINE__,
3835 "allegedly permanent breakpoint is not "
3836 "actually inserted");
3841 if (b->loc->inserted)
3842 internal_error (__FILE__, __LINE__,
3843 "another breakpoint was inserted on top of "
3844 "a permanent breakpoint");
3846 if (b->enable_state != bp_disabled
3847 && b->enable_state != bp_shlib_disabled
3848 && b->enable_state != bp_call_disabled
3849 && b->loc->address == address /* address / overlay match */
3850 && (!overlay_debugging || b->section == section)
3851 && breakpoint_address_is_meaningful (b))
3852 b->loc->duplicate = 1;
3858 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
3859 int bnum, int have_bnum)
3864 strcpy (astr1, local_hex_string_custom ((unsigned long) from_addr, "08l"));
3865 strcpy (astr2, local_hex_string_custom ((unsigned long) to_addr, "08l"));
3867 warning ("Breakpoint %d address previously adjusted from %s to %s.",
3868 bnum, astr1, astr2);
3870 warning ("Breakpoint address adjusted from %s to %s.", astr1, astr2);
3873 /* Adjust a breakpoint's address to account for architectural constraints
3874 on breakpoint placement. Return the adjusted address. Note: Very
3875 few targets require this kind of adjustment. For most targets,
3876 this function is simply the identity function. */
3879 adjust_breakpoint_address (CORE_ADDR bpaddr)
3881 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
3883 /* Very few targets need any kind of breakpoint adjustment. */
3888 CORE_ADDR adjusted_bpaddr;
3890 /* Some targets have architectural constraints on the placement
3891 of breakpoint instructions. Obtain the adjusted address. */
3892 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
3895 /* An adjusted breakpoint address can significantly alter
3896 a user's expectations. Print a warning if an adjustment
3898 if (adjusted_bpaddr != bpaddr)
3899 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
3901 return adjusted_bpaddr;
3905 /* Allocate a struct bp_location. */
3907 struct bp_location *
3908 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type)
3910 struct bp_location *loc, *loc_p;
3912 loc = xmalloc (sizeof (struct bp_location));
3913 memset (loc, 0, sizeof (*loc));
3923 case bp_longjmp_resume:
3924 case bp_step_resume:
3925 case bp_through_sigtramp:
3926 case bp_watchpoint_scope:
3928 case bp_shlib_event:
3929 case bp_thread_event:
3930 case bp_overlay_event:
3932 case bp_catch_unload:
3933 loc->loc_type = bp_loc_software_breakpoint;
3935 case bp_hardware_breakpoint:
3936 loc->loc_type = bp_loc_hardware_breakpoint;
3938 case bp_hardware_watchpoint:
3939 case bp_read_watchpoint:
3940 case bp_access_watchpoint:
3941 loc->loc_type = bp_loc_hardware_watchpoint;
3945 case bp_catch_vfork:
3947 case bp_catch_catch:
3948 case bp_catch_throw:
3949 loc->loc_type = bp_loc_other;
3952 internal_error (__FILE__, __LINE__, "unknown breakpoint type");
3955 /* Add this breakpoint to the end of the chain. */
3957 loc_p = bp_location_chain;
3959 bp_location_chain = loc;
3963 loc_p = loc_p->next;
3970 /* set_raw_breakpoint() is a low level routine for allocating and
3971 partially initializing a breakpoint of type BPTYPE. The newly
3972 created breakpoint's address, section, source file name, and line
3973 number are provided by SAL. The newly created and partially
3974 initialized breakpoint is added to the breakpoint chain and
3975 is also returned as the value of this function.
3977 It is expected that the caller will complete the initialization of
3978 the newly created breakpoint struct as well as output any status
3979 information regarding the creation of a new breakpoint. In
3980 particular, set_raw_breakpoint() does NOT set the breakpoint
3981 number! Care should be taken to not allow an error() to occur
3982 prior to completing the initialization of the breakpoint. If this
3983 should happen, a bogus breakpoint will be left on the chain. */
3986 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
3988 struct breakpoint *b, *b1;
3990 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3991 memset (b, 0, sizeof (*b));
3992 b->loc = allocate_bp_location (b, bptype);
3993 b->loc->requested_address = sal.pc;
3994 b->loc->address = adjust_breakpoint_address (b->loc->requested_address);
3995 if (sal.symtab == NULL)
3996 b->source_file = NULL;
3998 b->source_file = savestring (sal.symtab->filename,
3999 strlen (sal.symtab->filename));
4000 b->section = sal.section;
4002 b->language = current_language->la_language;
4003 b->input_radix = input_radix;
4005 b->line_number = sal.line;
4006 b->enable_state = bp_enabled;
4009 b->ignore_count = 0;
4011 b->frame_id = null_frame_id;
4012 b->dll_pathname = NULL;
4013 b->triggered_dll_pathname = NULL;
4014 b->forked_inferior_pid = 0;
4015 b->exec_pathname = NULL;
4018 /* Add this breakpoint to the end of the chain
4019 so that a list of breakpoints will come out in order
4020 of increasing numbers. */
4022 b1 = breakpoint_chain;
4024 breakpoint_chain = b;
4032 check_duplicates (b);
4033 breakpoints_changed ();
4039 /* Note that the breakpoint object B describes a permanent breakpoint
4040 instruction, hard-wired into the inferior's code. */
4042 make_breakpoint_permanent (struct breakpoint *b)
4044 b->enable_state = bp_permanent;
4046 /* By definition, permanent breakpoints are already present in the code. */
4047 b->loc->inserted = 1;
4050 static struct breakpoint *
4051 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
4053 static int internal_breakpoint_number = -1;
4054 struct symtab_and_line sal;
4055 struct breakpoint *b;
4057 init_sal (&sal); /* initialize to zeroes */
4060 sal.section = find_pc_overlay (sal.pc);
4062 b = set_raw_breakpoint (sal, type);
4063 b->number = internal_breakpoint_number--;
4064 b->disposition = disp_donttouch;
4071 create_longjmp_breakpoint (char *func_name)
4073 struct breakpoint *b;
4074 struct minimal_symbol *m;
4076 if (func_name == NULL)
4077 b = create_internal_breakpoint (0, bp_longjmp_resume);
4080 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4083 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
4086 b->enable_state = bp_disabled;
4089 b->addr_string = xstrdup (func_name);
4092 /* Call this routine when stepping and nexting to enable a breakpoint
4093 if we do a longjmp(). When we hit that breakpoint, call
4094 set_longjmp_resume_breakpoint() to figure out where we are going. */
4097 enable_longjmp_breakpoint (void)
4099 struct breakpoint *b;
4102 if (b->type == bp_longjmp)
4104 b->enable_state = bp_enabled;
4105 check_duplicates (b);
4110 disable_longjmp_breakpoint (void)
4112 struct breakpoint *b;
4115 if (b->type == bp_longjmp
4116 || b->type == bp_longjmp_resume)
4118 b->enable_state = bp_disabled;
4119 check_duplicates (b);
4124 create_overlay_event_breakpoint (char *func_name)
4126 struct breakpoint *b;
4127 struct minimal_symbol *m;
4129 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4132 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
4134 b->addr_string = xstrdup (func_name);
4136 if (overlay_debugging == ovly_auto)
4138 b->enable_state = bp_enabled;
4139 overlay_events_enabled = 1;
4143 b->enable_state = bp_disabled;
4144 overlay_events_enabled = 0;
4149 enable_overlay_breakpoints (void)
4151 struct breakpoint *b;
4154 if (b->type == bp_overlay_event)
4156 b->enable_state = bp_enabled;
4157 check_duplicates (b);
4158 overlay_events_enabled = 1;
4163 disable_overlay_breakpoints (void)
4165 struct breakpoint *b;
4168 if (b->type == bp_overlay_event)
4170 b->enable_state = bp_disabled;
4171 check_duplicates (b);
4172 overlay_events_enabled = 0;
4177 create_thread_event_breakpoint (CORE_ADDR address)
4179 struct breakpoint *b;
4181 b = create_internal_breakpoint (address, bp_thread_event);
4183 b->enable_state = bp_enabled;
4184 /* addr_string has to be used or breakpoint_re_set will delete me. */
4185 xasprintf (&b->addr_string, "*0x%s", paddr (b->loc->address));
4191 remove_thread_event_breakpoints (void)
4193 struct breakpoint *b, *temp;
4195 ALL_BREAKPOINTS_SAFE (b, temp)
4196 if (b->type == bp_thread_event)
4197 delete_breakpoint (b);
4202 remove_solib_event_breakpoints (void)
4204 struct breakpoint *b, *temp;
4206 ALL_BREAKPOINTS_SAFE (b, temp)
4207 if (b->type == bp_shlib_event)
4208 delete_breakpoint (b);
4212 create_solib_event_breakpoint (CORE_ADDR address)
4214 struct breakpoint *b;
4216 b = create_internal_breakpoint (address, bp_shlib_event);
4220 /* Disable any breakpoints that are on code in shared libraries. Only
4221 apply to enabled breakpoints, disabled ones can just stay disabled. */
4224 disable_breakpoints_in_shlibs (int silent)
4226 struct breakpoint *b;
4227 int disabled_shlib_breaks = 0;
4229 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4232 #if defined (PC_SOLIB)
4233 if (((b->type == bp_breakpoint) ||
4234 (b->type == bp_hardware_breakpoint)) &&
4235 b->enable_state == bp_enabled &&
4236 !b->loc->duplicate &&
4237 PC_SOLIB (b->loc->address))
4239 b->enable_state = bp_shlib_disabled;
4242 if (!disabled_shlib_breaks)
4244 target_terminal_ours_for_output ();
4245 warning ("Temporarily disabling shared library breakpoints:");
4247 disabled_shlib_breaks = 1;
4248 warning ("breakpoint #%d ", b->number);
4255 /* Try to reenable any breakpoints in shared libraries. */
4257 re_enable_breakpoints_in_shlibs (void)
4259 struct breakpoint *b;
4262 if (b->enable_state == bp_shlib_disabled)
4266 /* Do not reenable the breakpoint if the shared library
4267 is still not mapped in. */
4268 if (target_read_memory (b->loc->address, buf, 1) == 0)
4269 b->enable_state = bp_enabled;
4276 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
4277 char *cond_string, enum bptype bp_kind)
4279 struct breakpoint *b;
4280 struct symtabs_and_lines sals;
4281 struct cleanup *old_chain;
4282 struct cleanup *canonical_strings_chain = NULL;
4283 char *addr_start = hookname;
4284 char *addr_end = NULL;
4285 char **canonical = (char **) NULL;
4286 int thread = -1; /* All threads. */
4288 /* Set a breakpoint on the specified hook. */
4289 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
4290 addr_end = hookname;
4292 if (sals.nelts == 0)
4294 warning ("Unable to set a breakpoint on dynamic linker callback.");
4295 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4296 warning ("GDB will be unable to track shl_load/shl_unload calls");
4299 if (sals.nelts != 1)
4301 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4302 warning ("GDB will be unable to track shl_load/shl_unload calls");
4306 /* Make sure that all storage allocated in decode_line_1 gets freed
4307 in case the following errors out. */
4308 old_chain = make_cleanup (xfree, sals.sals);
4309 if (canonical != (char **) NULL)
4311 make_cleanup (xfree, canonical);
4312 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4313 if (canonical[0] != NULL)
4314 make_cleanup (xfree, canonical[0]);
4317 resolve_sal_pc (&sals.sals[0]);
4319 /* Remove the canonical strings from the cleanup, they are needed below. */
4320 if (canonical != (char **) NULL)
4321 discard_cleanups (canonical_strings_chain);
4323 b = set_raw_breakpoint (sals.sals[0], bp_kind);
4324 set_breakpoint_count (breakpoint_count + 1);
4325 b->number = breakpoint_count;
4327 b->cond_string = (cond_string == NULL) ?
4328 NULL : savestring (cond_string, strlen (cond_string));
4331 if (canonical != (char **) NULL && canonical[0] != NULL)
4332 b->addr_string = canonical[0];
4333 else if (addr_start)
4334 b->addr_string = savestring (addr_start, addr_end - addr_start);
4336 b->enable_state = bp_enabled;
4337 b->disposition = tempflag ? disp_del : disp_donttouch;
4339 if (dll_pathname == NULL)
4340 b->dll_pathname = NULL;
4343 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4344 strcpy (b->dll_pathname, dll_pathname);
4348 do_cleanups (old_chain);
4352 create_solib_load_event_breakpoint (char *hookname, int tempflag,
4353 char *dll_pathname, char *cond_string)
4355 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4356 cond_string, bp_catch_load);
4360 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4361 char *dll_pathname, char *cond_string)
4363 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4364 cond_string, bp_catch_unload);
4368 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4369 enum bptype bp_kind)
4371 struct symtab_and_line sal;
4372 struct breakpoint *b;
4373 int thread = -1; /* All threads. */
4380 b = set_raw_breakpoint (sal, bp_kind);
4381 set_breakpoint_count (breakpoint_count + 1);
4382 b->number = breakpoint_count;
4384 b->cond_string = (cond_string == NULL) ?
4385 NULL : savestring (cond_string, strlen (cond_string));
4387 b->addr_string = NULL;
4388 b->enable_state = bp_enabled;
4389 b->disposition = tempflag ? disp_del : disp_donttouch;
4390 b->forked_inferior_pid = 0;
4396 create_fork_event_catchpoint (int tempflag, char *cond_string)
4398 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4402 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4404 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4408 create_exec_event_catchpoint (int tempflag, char *cond_string)
4410 struct symtab_and_line sal;
4411 struct breakpoint *b;
4412 int thread = -1; /* All threads. */
4419 b = set_raw_breakpoint (sal, bp_catch_exec);
4420 set_breakpoint_count (breakpoint_count + 1);
4421 b->number = breakpoint_count;
4423 b->cond_string = (cond_string == NULL) ?
4424 NULL : savestring (cond_string, strlen (cond_string));
4426 b->addr_string = NULL;
4427 b->enable_state = bp_enabled;
4428 b->disposition = tempflag ? disp_del : disp_donttouch;
4434 hw_breakpoint_used_count (void)
4436 struct breakpoint *b;
4441 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4449 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4451 struct breakpoint *b;
4454 *other_type_used = 0;
4457 if (b->enable_state == bp_enabled)
4459 if (b->type == type)
4461 else if ((b->type == bp_hardware_watchpoint ||
4462 b->type == bp_read_watchpoint ||
4463 b->type == bp_access_watchpoint)
4464 && b->enable_state == bp_enabled)
4465 *other_type_used = 1;
4471 /* Call this after hitting the longjmp() breakpoint. Use this to set
4472 a new breakpoint at the target of the jmp_buf.
4474 FIXME - This ought to be done by setting a temporary breakpoint
4475 that gets deleted automatically... */
4478 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id)
4480 struct breakpoint *b;
4483 if (b->type == bp_longjmp_resume)
4485 b->loc->requested_address = pc;
4486 b->loc->address = adjust_breakpoint_address (b->loc->requested_address);
4487 b->enable_state = bp_enabled;
4488 b->frame_id = frame_id;
4489 check_duplicates (b);
4495 disable_watchpoints_before_interactive_call_start (void)
4497 struct breakpoint *b;
4501 if (((b->type == bp_watchpoint)
4502 || (b->type == bp_hardware_watchpoint)
4503 || (b->type == bp_read_watchpoint)
4504 || (b->type == bp_access_watchpoint)
4505 || ep_is_exception_catchpoint (b))
4506 && (b->enable_state == bp_enabled))
4508 b->enable_state = bp_call_disabled;
4509 check_duplicates (b);
4515 enable_watchpoints_after_interactive_call_stop (void)
4517 struct breakpoint *b;
4521 if (((b->type == bp_watchpoint)
4522 || (b->type == bp_hardware_watchpoint)
4523 || (b->type == bp_read_watchpoint)
4524 || (b->type == bp_access_watchpoint)
4525 || ep_is_exception_catchpoint (b))
4526 && (b->enable_state == bp_call_disabled))
4528 b->enable_state = bp_enabled;
4529 check_duplicates (b);
4535 /* Set a breakpoint that will evaporate an end of command
4536 at address specified by SAL.
4537 Restrict it to frame FRAME if FRAME is nonzero. */
4540 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
4543 struct breakpoint *b;
4544 b = set_raw_breakpoint (sal, type);
4545 b->enable_state = bp_enabled;
4546 b->disposition = disp_donttouch;
4547 b->frame_id = frame_id;
4549 /* If we're debugging a multi-threaded program, then we
4550 want momentary breakpoints to be active in only a
4551 single thread of control. */
4552 if (in_thread_list (inferior_ptid))
4553 b->thread = pid_to_thread_id (inferior_ptid);
4559 /* Tell the user we have just set a breakpoint B. */
4562 mention (struct breakpoint *b)
4565 struct cleanup *old_chain, *ui_out_chain;
4566 struct ui_stream *stb;
4568 stb = ui_out_stream_new (uiout);
4569 old_chain = make_cleanup_ui_out_stream_delete (stb);
4571 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4572 watchpoint) other than breakpoint creation. It should be possible to
4573 clean this up and at the same time replace the random calls to
4574 breakpoint_changed with this hook, as has already been done for
4575 delete_breakpoint_hook and so on. */
4576 if (create_breakpoint_hook)
4577 create_breakpoint_hook (b);
4578 breakpoint_create_event (b->number);
4580 if (b->ops != NULL && b->ops->print_mention != NULL)
4581 b->ops->print_mention (b);
4586 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4589 ui_out_text (uiout, "Watchpoint ");
4590 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4591 ui_out_field_int (uiout, "number", b->number);
4592 ui_out_text (uiout, ": ");
4593 print_expression (b->exp, stb->stream);
4594 ui_out_field_stream (uiout, "exp", stb);
4595 do_cleanups (ui_out_chain);
4597 case bp_hardware_watchpoint:
4598 ui_out_text (uiout, "Hardware watchpoint ");
4599 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4600 ui_out_field_int (uiout, "number", b->number);
4601 ui_out_text (uiout, ": ");
4602 print_expression (b->exp, stb->stream);
4603 ui_out_field_stream (uiout, "exp", stb);
4604 do_cleanups (ui_out_chain);
4606 case bp_read_watchpoint:
4607 ui_out_text (uiout, "Hardware read watchpoint ");
4608 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
4609 ui_out_field_int (uiout, "number", b->number);
4610 ui_out_text (uiout, ": ");
4611 print_expression (b->exp, stb->stream);
4612 ui_out_field_stream (uiout, "exp", stb);
4613 do_cleanups (ui_out_chain);
4615 case bp_access_watchpoint:
4616 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4617 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
4618 ui_out_field_int (uiout, "number", b->number);
4619 ui_out_text (uiout, ": ");
4620 print_expression (b->exp, stb->stream);
4621 ui_out_field_stream (uiout, "exp", stb);
4622 do_cleanups (ui_out_chain);
4625 if (ui_out_is_mi_like_p (uiout))
4630 printf_filtered ("Breakpoint %d", b->number);
4633 case bp_hardware_breakpoint:
4634 if (ui_out_is_mi_like_p (uiout))
4639 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4643 case bp_catch_unload:
4644 printf_filtered ("Catchpoint %d (%s %s)",
4646 (b->type == bp_catch_load) ? "load" : "unload",
4647 (b->dll_pathname != NULL) ?
4648 b->dll_pathname : "<any library>");
4651 case bp_catch_vfork:
4652 printf_filtered ("Catchpoint %d (%s)",
4654 (b->type == bp_catch_fork) ? "fork" : "vfork");
4657 printf_filtered ("Catchpoint %d (exec)",
4660 case bp_catch_catch:
4661 case bp_catch_throw:
4662 printf_filtered ("Catchpoint %d (%s)",
4664 (b->type == bp_catch_catch) ? "catch" : "throw");
4670 case bp_longjmp_resume:
4671 case bp_step_resume:
4672 case bp_through_sigtramp:
4674 case bp_watchpoint_scope:
4675 case bp_shlib_event:
4676 case bp_thread_event:
4677 case bp_overlay_event:
4683 if (addressprint || b->source_file == NULL)
4685 printf_filtered (" at ");
4686 print_address_numeric (b->loc->address, 1, gdb_stdout);
4689 printf_filtered (": file %s, line %d.",
4690 b->source_file, b->line_number);
4692 do_cleanups (old_chain);
4693 if (ui_out_is_mi_like_p (uiout))
4695 printf_filtered ("\n");
4699 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4700 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4701 COND[i] and COND_STRING[i] values.
4703 NOTE: If the function succeeds, the caller is expected to cleanup
4704 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4705 array contents). If the function fails (error() is called), the
4706 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4707 COND and SALS arrays and each of those arrays contents. */
4710 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4711 struct expression **cond, char **cond_string,
4712 enum bptype type, enum bpdisp disposition,
4713 int thread, int ignore_count, int from_tty)
4715 if (type == bp_hardware_breakpoint)
4717 int i = hw_breakpoint_used_count ();
4718 int target_resources_ok =
4719 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4721 if (target_resources_ok == 0)
4722 error ("No hardware breakpoint support in the target.");
4723 else if (target_resources_ok < 0)
4724 error ("Hardware breakpoints used exceeds limit.");
4727 /* Now set all the breakpoints. */
4730 for (i = 0; i < sals.nelts; i++)
4732 struct breakpoint *b;
4733 struct symtab_and_line sal = sals.sals[i];
4736 describe_other_breakpoints (sal.pc, sal.section);
4738 b = set_raw_breakpoint (sal, type);
4739 set_breakpoint_count (breakpoint_count + 1);
4740 b->number = breakpoint_count;
4744 b->addr_string = addr_string[i];
4746 /* addr_string has to be used or breakpoint_re_set will delete
4748 xasprintf (&b->addr_string, "*0x%s", paddr (b->loc->address));
4749 b->cond_string = cond_string[i];
4750 b->ignore_count = ignore_count;
4751 b->enable_state = bp_enabled;
4752 b->disposition = disposition;
4758 /* Parse ARG which is assumed to be a SAL specification possibly
4759 followed by conditionals. On return, SALS contains an array of SAL
4760 addresses found. ADDR_STRING contains a vector of (canonical)
4761 address strings. ARG points to the end of the SAL. */
4764 parse_breakpoint_sals (char **address,
4765 struct symtabs_and_lines *sals,
4766 char ***addr_string)
4768 char *addr_start = *address;
4769 *addr_string = NULL;
4770 /* If no arg given, or if first arg is 'if ', use the default
4772 if ((*address) == NULL
4773 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4775 if (default_breakpoint_valid)
4777 struct symtab_and_line sal;
4778 init_sal (&sal); /* initialize to zeroes */
4779 sals->sals = (struct symtab_and_line *)
4780 xmalloc (sizeof (struct symtab_and_line));
4781 sal.pc = default_breakpoint_address;
4782 sal.line = default_breakpoint_line;
4783 sal.symtab = default_breakpoint_symtab;
4784 sal.section = find_pc_overlay (sal.pc);
4785 sals->sals[0] = sal;
4789 error ("No default breakpoint address now.");
4793 /* Force almost all breakpoints to be in terms of the
4794 current_source_symtab (which is decode_line_1's default). This
4795 should produce the results we want almost all of the time while
4796 leaving default_breakpoint_* alone.
4797 ObjC: However, don't match an Objective-C method name which
4798 may have a '+' or '-' succeeded by a '[' */
4800 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
4802 if (default_breakpoint_valid
4804 || ((strchr ("+-", (*address)[0]) != NULL)
4805 && ((*address)[1] != '['))))
4806 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4807 default_breakpoint_line, addr_string);
4809 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
4811 /* For any SAL that didn't have a canonical string, fill one in. */
4812 if (sals->nelts > 0 && *addr_string == NULL)
4813 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4814 if (addr_start != (*address))
4817 for (i = 0; i < sals->nelts; i++)
4819 /* Add the string if not present. */
4820 if ((*addr_string)[i] == NULL)
4821 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
4827 /* Convert each SAL into a real PC. Verify that the PC can be
4828 inserted as a breakpoint. If it can't throw an error. */
4831 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4835 for (i = 0; i < sals->nelts; i++)
4837 resolve_sal_pc (&sals->sals[i]);
4839 /* It's possible for the PC to be nonzero, but still an illegal
4840 value on some targets.
4842 For example, on HP-UX if you start gdb, and before running the
4843 inferior you try to set a breakpoint on a shared library function
4844 "foo" where the inferior doesn't call "foo" directly but does
4845 pass its address to another function call, then we do find a
4846 minimal symbol for the "foo", but it's address is invalid.
4847 (Appears to be an index into a table that the loader sets up
4848 when the inferior is run.)
4850 Give the target a chance to bless sals.sals[i].pc before we
4851 try to make a breakpoint for it. */
4852 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
4854 if (address == NULL)
4855 error ("Cannot break without a running program.");
4857 error ("Cannot break on %s without a running program.",
4863 /* Set a breakpoint according to ARG (function, linenum or *address)
4864 flag: first bit : 0 non-temporary, 1 temporary.
4865 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4868 break_command_1 (char *arg, int flag, int from_tty)
4870 int tempflag, hardwareflag;
4871 struct symtabs_and_lines sals;
4872 struct expression **cond = 0;
4873 /* Pointers in arg to the start, and one past the end, of the
4875 char **cond_string = (char **) NULL;
4876 char *addr_start = arg;
4878 struct cleanup *old_chain;
4879 struct cleanup *breakpoint_chain = NULL;
4882 int ignore_count = 0;
4884 hardwareflag = flag & BP_HARDWAREFLAG;
4885 tempflag = flag & BP_TEMPFLAG;
4890 parse_breakpoint_sals (&arg, &sals, &addr_string);
4895 /* Create a chain of things that always need to be cleaned up. */
4896 old_chain = make_cleanup (null_cleanup, 0);
4898 /* Make sure that all storage allocated to SALS gets freed. */
4899 make_cleanup (xfree, sals.sals);
4901 /* Cleanup the addr_string array but not its contents. */
4902 make_cleanup (xfree, addr_string);
4904 /* Allocate space for all the cond expressions. */
4905 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4906 make_cleanup (xfree, cond);
4908 /* Allocate space for all the cond strings. */
4909 cond_string = xcalloc (sals.nelts, sizeof (char **));
4910 make_cleanup (xfree, cond_string);
4912 /* ----------------------------- SNIP -----------------------------
4913 Anything added to the cleanup chain beyond this point is assumed
4914 to be part of a breakpoint. If the breakpoint create succeeds
4915 then the memory is not reclaimed. */
4916 breakpoint_chain = make_cleanup (null_cleanup, 0);
4918 /* Mark the contents of the addr_string for cleanup. These go on
4919 the breakpoint_chain and only occure if the breakpoint create
4921 for (i = 0; i < sals.nelts; i++)
4923 if (addr_string[i] != NULL)
4924 make_cleanup (xfree, addr_string[i]);
4927 /* Resolve all line numbers to PC's and verify that the addresses
4928 are ok for the target. */
4929 breakpoint_sals_to_pc (&sals, addr_start);
4931 /* Verify that condition can be parsed, before setting any
4932 breakpoints. Allocate a separate condition expression for each
4934 thread = -1; /* No specific thread yet */
4935 for (i = 0; i < sals.nelts; i++)
4942 char *cond_start = NULL;
4943 char *cond_end = NULL;
4944 while (*tok == ' ' || *tok == '\t')
4949 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4952 toklen = end_tok - tok;
4954 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4956 tok = cond_start = end_tok + 1;
4957 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4958 make_cleanup (xfree, cond[i]);
4960 cond_string[i] = savestring (cond_start, cond_end - cond_start);
4961 make_cleanup (xfree, cond_string[i]);
4963 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4969 thread = strtol (tok, &tok, 0);
4971 error ("Junk after thread keyword.");
4972 if (!valid_thread_id (thread))
4973 error ("Unknown thread %d\n", thread);
4976 error ("Junk at end of arguments.");
4980 create_breakpoints (sals, addr_string, cond, cond_string,
4981 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4982 tempflag ? disp_del : disp_donttouch,
4983 thread, ignore_count, from_tty);
4987 warning ("Multiple breakpoints were set.");
4988 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4990 /* That's it. Discard the cleanups for data inserted into the
4992 discard_cleanups (breakpoint_chain);
4993 /* But cleanup everything else. */
4994 do_cleanups (old_chain);
4997 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4998 linenum or *address) with COND and IGNORE_COUNT. */
5000 struct captured_breakpoint_args
5011 do_captured_breakpoint (void *data)
5013 struct captured_breakpoint_args *args = data;
5014 struct symtabs_and_lines sals;
5015 struct expression **cond;
5016 struct cleanup *old_chain;
5017 struct cleanup *breakpoint_chain = NULL;
5024 /* Parse the source and lines spec. Delay check that the expression
5025 didn't contain trailing garbage until after cleanups are in
5029 address_end = args->address;
5031 parse_breakpoint_sals (&address_end, &sals, &addr_string);
5036 /* Create a chain of things at always need to be cleaned up. */
5037 old_chain = make_cleanup (null_cleanup, 0);
5039 /* Always have a addr_string array, even if it is empty. */
5040 make_cleanup (xfree, addr_string);
5042 /* Make sure that all storage allocated to SALS gets freed. */
5043 make_cleanup (xfree, sals.sals);
5045 /* Allocate space for all the cond expressions. */
5046 cond = xcalloc (sals.nelts, sizeof (struct expression *));
5047 make_cleanup (xfree, cond);
5049 /* Allocate space for all the cond strings. */
5050 cond_string = xcalloc (sals.nelts, sizeof (char **));
5051 make_cleanup (xfree, cond_string);
5053 /* ----------------------------- SNIP -----------------------------
5054 Anything added to the cleanup chain beyond this point is assumed
5055 to be part of a breakpoint. If the breakpoint create goes
5056 through then that memory is not cleaned up. */
5057 breakpoint_chain = make_cleanup (null_cleanup, 0);
5059 /* Mark the contents of the addr_string for cleanup. These go on
5060 the breakpoint_chain and only occure if the breakpoint create
5062 for (i = 0; i < sals.nelts; i++)
5064 if (addr_string[i] != NULL)
5065 make_cleanup (xfree, addr_string[i]);
5068 /* Wait until now before checking for garbage at the end of the
5069 address. That way cleanups can take care of freeing any
5071 if (*address_end != '\0')
5072 error ("Garbage %s following breakpoint address", address_end);
5074 /* Resolve all line numbers to PC's. */
5075 breakpoint_sals_to_pc (&sals, args->address);
5077 /* Verify that conditions can be parsed, before setting any
5079 for (i = 0; i < sals.nelts; i++)
5081 if (args->condition != NULL)
5083 char *tok = args->condition;
5084 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
5086 error ("Garbage %s follows condition", tok);
5087 make_cleanup (xfree, cond[i]);
5088 cond_string[i] = xstrdup (args->condition);
5092 create_breakpoints (sals, addr_string, cond, cond_string,
5093 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
5094 args->tempflag ? disp_del : disp_donttouch,
5095 args->thread, args->ignore_count, 0/*from-tty*/);
5097 /* That's it. Discard the cleanups for data inserted into the
5099 discard_cleanups (breakpoint_chain);
5100 /* But cleanup everything else. */
5101 do_cleanups (old_chain);
5106 gdb_breakpoint (char *address, char *condition,
5107 int hardwareflag, int tempflag,
5108 int thread, int ignore_count)
5110 struct captured_breakpoint_args args;
5111 args.address = address;
5112 args.condition = condition;
5113 args.hardwareflag = hardwareflag;
5114 args.tempflag = tempflag;
5115 args.thread = thread;
5116 args.ignore_count = ignore_count;
5117 return catch_errors (do_captured_breakpoint, &args,
5118 NULL, RETURN_MASK_ALL);
5123 break_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty)
5125 struct frame_info *frame;
5126 CORE_ADDR low, high, selected_pc = 0;
5127 char *extra_args = NULL;
5129 int extra_args_len = 0, if_arg = 0;
5132 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5135 if (default_breakpoint_valid)
5137 if (deprecated_selected_frame)
5139 selected_pc = get_frame_pc (deprecated_selected_frame);
5144 error ("No selected frame.");
5147 error ("No default breakpoint address now.");
5151 extra_args = strchr (arg, ' ');
5155 extra_args_len = strlen (extra_args);
5156 level_arg = (char *) xmalloc (extra_args - arg);
5157 strncpy (level_arg, arg, extra_args - arg - 1);
5158 level_arg[extra_args - arg - 1] = '\0';
5162 level_arg = (char *) xmalloc (strlen (arg) + 1);
5163 strcpy (level_arg, arg);
5166 frame = parse_frame_specification (level_arg);
5168 selected_pc = get_frame_pc (frame);
5175 extra_args_len = strlen (arg);
5180 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
5184 addr_string = xstrprintf ("*0x%s %s", paddr_nz (high), extra_args);
5186 addr_string = xstrprintf ("*0x%s", paddr_nz (high));
5187 break_command_1 (addr_string, flag, from_tty);
5188 xfree (addr_string);
5191 error ("No function contains the specified address");
5194 error ("Unable to set breakpoint at procedure exit");
5199 break_at_finish_command_1 (char *arg, int flag, int from_tty)
5201 char *addr_string, *break_string, *beg_addr_string;
5202 CORE_ADDR low, high;
5203 struct symtabs_and_lines sals;
5204 struct symtab_and_line sal;
5205 struct cleanup *old_chain;
5206 char *extra_args = NULL;
5207 int extra_args_len = 0;
5211 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5213 if (default_breakpoint_valid)
5215 if (deprecated_selected_frame)
5217 addr_string = xstrprintf ("*0x%s",
5218 paddr_nz (get_frame_pc (deprecated_selected_frame)));
5223 error ("No selected frame.");
5226 error ("No default breakpoint address now.");
5230 addr_string = (char *) xmalloc (strlen (arg) + 1);
5231 strcpy (addr_string, arg);
5237 extra_args_len = strlen (arg);
5241 /* get the stuff after the function name or address */
5242 extra_args = strchr (arg, ' ');
5246 extra_args_len = strlen (extra_args);
5253 beg_addr_string = addr_string;
5254 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
5257 xfree (beg_addr_string);
5258 old_chain = make_cleanup (xfree, sals.sals);
5259 for (i = 0; (i < sals.nelts); i++)
5262 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
5266 break_string = xstrprintf ("*0x%s %s", paddr_nz (high),
5269 break_string = xstrprintf ("*0x%s", paddr_nz (high));
5270 break_command_1 (break_string, flag, from_tty);
5271 xfree (break_string);
5274 error ("No function contains the specified address");
5278 warning ("Multiple breakpoints were set.\n");
5279 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5281 do_cleanups (old_chain);
5285 /* Helper function for break_command_1 and disassemble_command. */
5288 resolve_sal_pc (struct symtab_and_line *sal)
5292 if (sal->pc == 0 && sal->symtab != NULL)
5294 if (!find_line_pc (sal->symtab, sal->line, &pc))
5295 error ("No line %d in file \"%s\".",
5296 sal->line, sal->symtab->filename);
5300 if (sal->section == 0 && sal->symtab != NULL)
5302 struct blockvector *bv;
5307 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5310 b = BLOCKVECTOR_BLOCK (bv, index);
5311 sym = block_function (b);
5314 fixup_symbol_section (sym, sal->symtab->objfile);
5315 sal->section = SYMBOL_BFD_SECTION (sym);
5319 /* It really is worthwhile to have the section, so we'll just
5320 have to look harder. This case can be executed if we have
5321 line numbers but no functions (as can happen in assembly
5324 struct minimal_symbol *msym;
5326 msym = lookup_minimal_symbol_by_pc (sal->pc);
5328 sal->section = SYMBOL_BFD_SECTION (msym);
5335 break_command (char *arg, int from_tty)
5337 break_command_1 (arg, 0, from_tty);
5341 break_at_finish_command (char *arg, int from_tty)
5343 break_at_finish_command_1 (arg, 0, from_tty);
5347 break_at_finish_at_depth_command (char *arg, int from_tty)
5349 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5353 tbreak_command (char *arg, int from_tty)
5355 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5359 tbreak_at_finish_command (char *arg, int from_tty)
5361 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5365 hbreak_command (char *arg, int from_tty)
5367 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5371 thbreak_command (char *arg, int from_tty)
5373 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5377 stop_command (char *arg, int from_tty)
5379 printf_filtered ("Specify the type of breakpoint to set.\n\
5380 Usage: stop in <function | address>\n\
5385 stopin_command (char *arg, int from_tty)
5389 if (arg == (char *) NULL)
5391 else if (*arg != '*')
5396 /* look for a ':'. If this is a line number specification, then
5397 say it is bad, otherwise, it should be an address or
5398 function/method name */
5399 while (*argptr && !hasColon)
5401 hasColon = (*argptr == ':');
5406 badInput = (*argptr != ':'); /* Not a class::method */
5408 badInput = isdigit (*arg); /* a simple line number */
5412 printf_filtered ("Usage: stop in <function | address>\n");
5414 break_command_1 (arg, 0, from_tty);
5418 stopat_command (char *arg, int from_tty)
5422 if (arg == (char *) NULL || *arg == '*') /* no line number */
5429 /* look for a ':'. If there is a '::' then get out, otherwise
5430 it is probably a line number. */
5431 while (*argptr && !hasColon)
5433 hasColon = (*argptr == ':');
5438 badInput = (*argptr == ':'); /* we have class::method */
5440 badInput = !isdigit (*arg); /* not a line number */
5444 printf_filtered ("Usage: stop at <line>\n");
5446 break_command_1 (arg, 0, from_tty);
5449 /* accessflag: hw_write: watch write,
5450 hw_read: watch read,
5451 hw_access: watch access (read or write) */
5453 watch_command_1 (char *arg, int accessflag, int from_tty)
5455 struct breakpoint *b;
5456 struct symtab_and_line sal;
5457 struct expression *exp;
5458 struct block *exp_valid_block;
5459 struct value *val, *mark;
5460 struct frame_info *frame;
5461 struct frame_info *prev_frame = NULL;
5462 char *exp_start = NULL;
5463 char *exp_end = NULL;
5464 char *tok, *end_tok;
5466 char *cond_start = NULL;
5467 char *cond_end = NULL;
5468 struct expression *cond = NULL;
5469 int i, other_type_used, target_resources_ok = 0;
5470 enum bptype bp_type;
5473 init_sal (&sal); /* initialize to zeroes */
5475 /* Parse arguments. */
5476 innermost_block = NULL;
5478 exp = parse_exp_1 (&arg, 0, 0);
5480 exp_valid_block = innermost_block;
5481 mark = value_mark ();
5482 val = evaluate_expression (exp);
5483 release_value (val);
5484 if (VALUE_LAZY (val))
5485 value_fetch_lazy (val);
5488 while (*tok == ' ' || *tok == '\t')
5492 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5495 toklen = end_tok - tok;
5496 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5498 tok = cond_start = end_tok + 1;
5499 cond = parse_exp_1 (&tok, 0, 0);
5503 error ("Junk at end of command.");
5505 if (accessflag == hw_read)
5506 bp_type = bp_read_watchpoint;
5507 else if (accessflag == hw_access)
5508 bp_type = bp_access_watchpoint;
5510 bp_type = bp_hardware_watchpoint;
5512 mem_cnt = can_use_hardware_watchpoint (val);
5513 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5514 error ("Expression cannot be implemented with read/access watchpoint.");
5517 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5518 target_resources_ok =
5519 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5521 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5522 error ("Target does not support this type of hardware watchpoint.");
5524 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5525 error ("Target can only support one kind of HW watchpoint at a time.");
5528 #if defined(HPUXHPPA)
5529 /* On HP-UX if you set a h/w
5530 watchpoint before the "run" command, the inferior dies with a e.g.,
5531 SIGILL once you start it. I initially believed this was due to a
5532 bad interaction between page protection traps and the initial
5533 startup sequence by the dynamic linker.
5535 However, I tried avoiding that by having HP-UX's implementation of
5536 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5537 yet, which forced slow watches before a "run" or "attach", and it
5538 still fails somewhere in the startup code.
5540 Until I figure out what's happening, I'm disallowing watches altogether
5541 before the "run" or "attach" command. We'll tell the user they must
5542 set watches after getting the program started. */
5543 if (!target_has_execution)
5545 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5548 #endif /* HPUXHPPA */
5550 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5551 watchpoint could not be set. */
5552 if (!mem_cnt || target_resources_ok <= 0)
5553 bp_type = bp_watchpoint;
5555 /* Now set up the breakpoint. */
5556 b = set_raw_breakpoint (sal, bp_type);
5557 set_breakpoint_count (breakpoint_count + 1);
5558 b->number = breakpoint_count;
5559 b->disposition = disp_donttouch;
5561 b->exp_valid_block = exp_valid_block;
5562 b->exp_string = savestring (exp_start, exp_end - exp_start);
5566 b->cond_string = savestring (cond_start, cond_end - cond_start);
5570 frame = block_innermost_frame (exp_valid_block);
5573 prev_frame = get_prev_frame (frame);
5574 b->watchpoint_frame = get_frame_id (frame);
5578 memset (&b->watchpoint_frame, 0, sizeof (b->watchpoint_frame));
5581 /* If the expression is "local", then set up a "watchpoint scope"
5582 breakpoint at the point where we've left the scope of the watchpoint
5584 if (innermost_block)
5588 struct breakpoint *scope_breakpoint;
5589 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
5590 bp_watchpoint_scope);
5592 scope_breakpoint->enable_state = bp_enabled;
5594 /* Automatically delete the breakpoint when it hits. */
5595 scope_breakpoint->disposition = disp_del;
5597 /* Only break in the proper frame (help with recursion). */
5598 scope_breakpoint->frame_id = get_frame_id (prev_frame);
5600 /* Set the address at which we will stop. */
5601 scope_breakpoint->loc->requested_address
5602 = get_frame_pc (prev_frame);
5603 scope_breakpoint->loc->address
5604 = adjust_breakpoint_address (scope_breakpoint->loc->requested_address);
5606 /* The scope breakpoint is related to the watchpoint. We
5607 will need to act on them together. */
5608 b->related_breakpoint = scope_breakpoint;
5611 value_free_to_mark (mark);
5615 /* Return count of locations need to be watched and can be handled
5616 in hardware. If the watchpoint can not be handled
5617 in hardware return zero. */
5619 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5620 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5621 ((BYTE_SIZE) <= (DEPRECATED_REGISTER_SIZE))
5624 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5625 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5626 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5630 can_use_hardware_watchpoint (struct value *v)
5632 int found_memory_cnt = 0;
5633 struct value *head = v;
5635 /* Did the user specifically forbid us to use hardware watchpoints? */
5636 if (!can_use_hw_watchpoints)
5639 /* Make sure that the value of the expression depends only upon
5640 memory contents, and values computed from them within GDB. If we
5641 find any register references or function calls, we can't use a
5642 hardware watchpoint.
5644 The idea here is that evaluating an expression generates a series
5645 of values, one holding the value of every subexpression. (The
5646 expression a*b+c has five subexpressions: a, b, a*b, c, and
5647 a*b+c.) GDB's values hold almost enough information to establish
5648 the criteria given above --- they identify memory lvalues,
5649 register lvalues, computed values, etcetera. So we can evaluate
5650 the expression, and then scan the chain of values that leaves
5651 behind to decide whether we can detect any possible change to the
5652 expression's final value using only hardware watchpoints.
5654 However, I don't think that the values returned by inferior
5655 function calls are special in any way. So this function may not
5656 notice that an expression involving an inferior function call
5657 can't be watched with hardware watchpoints. FIXME. */
5658 for (; v; v = v->next)
5660 if (VALUE_LVAL (v) == lval_memory)
5663 /* A lazy memory lvalue is one that GDB never needed to fetch;
5664 we either just used its address (e.g., `a' in `a.b') or
5665 we never needed it at all (e.g., `a' in `a,b'). */
5669 /* Ahh, memory we actually used! Check if we can cover
5670 it with hardware watchpoints. */
5671 struct type *vtype = check_typedef (VALUE_TYPE (v));
5673 /* We only watch structs and arrays if user asked for it
5674 explicitly, never if they just happen to appear in a
5675 middle of some value chain. */
5677 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5678 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5680 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5681 int len = TYPE_LENGTH (VALUE_TYPE (v));
5683 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5690 else if (v->lval != not_lval && v->modifiable == 0)
5691 return 0; /* ??? What does this represent? */
5692 else if (v->lval == lval_register)
5693 return 0; /* cannot watch a register with a HW watchpoint */
5696 /* The expression itself looks suitable for using a hardware
5697 watchpoint, but give the target machine a chance to reject it. */
5698 return found_memory_cnt;
5702 watch_command_wrapper (char *arg, int from_tty)
5704 watch_command (arg, from_tty);
5708 watch_command (char *arg, int from_tty)
5710 watch_command_1 (arg, hw_write, from_tty);
5714 rwatch_command_wrapper (char *arg, int from_tty)
5716 rwatch_command (arg, from_tty);
5720 rwatch_command (char *arg, int from_tty)
5722 watch_command_1 (arg, hw_read, from_tty);
5726 awatch_command_wrapper (char *arg, int from_tty)
5728 awatch_command (arg, from_tty);
5732 awatch_command (char *arg, int from_tty)
5734 watch_command_1 (arg, hw_access, from_tty);
5738 /* Helper routines for the until_command routine in infcmd.c. Here
5739 because it uses the mechanisms of breakpoints. */
5741 /* This function is called by fetch_inferior_event via the
5742 cmd_continuation pointer, to complete the until command. It takes
5743 care of cleaning up the temporary breakpoints set up by the until
5746 until_break_command_continuation (struct continuation_arg *arg)
5748 struct cleanup *cleanups;
5750 cleanups = (struct cleanup *) arg->data.pointer;
5751 do_exec_cleanups (cleanups);
5755 until_break_command (char *arg, int from_tty, int anywhere)
5757 struct symtabs_and_lines sals;
5758 struct symtab_and_line sal;
5759 struct frame_info *prev_frame = get_prev_frame (deprecated_selected_frame);
5760 struct breakpoint *breakpoint;
5761 struct cleanup *old_chain;
5762 struct continuation_arg *arg1;
5765 clear_proceed_status ();
5767 /* Set a breakpoint where the user wants it and at return from
5770 if (default_breakpoint_valid)
5771 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5772 default_breakpoint_line, (char ***) NULL);
5774 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5775 0, (char ***) NULL);
5777 if (sals.nelts != 1)
5778 error ("Couldn't get information on specified line.");
5781 xfree (sals.sals); /* malloc'd, so freed */
5784 error ("Junk at end of arguments.");
5786 resolve_sal_pc (&sal);
5789 /* If the user told us to continue until a specified location,
5790 we don't specify a frame at which we need to stop. */
5791 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
5793 /* Otherwise, specify the current frame, because we want to stop only
5794 at the very same frame. */
5795 breakpoint = set_momentary_breakpoint (sal,
5796 get_frame_id (deprecated_selected_frame),
5799 if (!event_loop_p || !target_can_async_p ())
5800 old_chain = make_cleanup_delete_breakpoint (breakpoint);
5802 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
5804 /* If we are running asynchronously, and the target supports async
5805 execution, we are not waiting for the target to stop, in the call
5806 tp proceed, below. This means that we cannot delete the
5807 brekpoints until the target has actually stopped. The only place
5808 where we get a chance to do that is in fetch_inferior_event, so
5809 we must set things up for that. */
5811 if (event_loop_p && target_can_async_p ())
5813 /* In this case the arg for the continuation is just the point
5814 in the exec_cleanups chain from where to start doing
5815 cleanups, because all the continuation does is the cleanups in
5816 the exec_cleanup_chain. */
5818 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5820 arg1->data.pointer = old_chain;
5822 add_continuation (until_break_command_continuation, arg1);
5825 /* Keep within the current frame, or in frames called by the current
5829 sal = find_pc_line (get_frame_pc (prev_frame), 0);
5830 sal.pc = get_frame_pc (prev_frame);
5831 breakpoint = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
5833 if (!event_loop_p || !target_can_async_p ())
5834 make_cleanup_delete_breakpoint (breakpoint);
5836 make_exec_cleanup_delete_breakpoint (breakpoint);
5839 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5840 /* Do the cleanups now, anly if we are not running asynchronously,
5841 of if we are, but the target is still synchronous. */
5842 if (!event_loop_p || !target_can_async_p ())
5843 do_cleanups (old_chain);
5847 /* These aren't used; I don't konw what they were for. */
5848 /* Set a breakpoint at the catch clause for NAME. */
5850 catch_breakpoint (char *name)
5855 disable_catch_breakpoint (void)
5860 delete_catch_breakpoint (void)
5865 enable_catch_breakpoint (void)
5871 ep_skip_leading_whitespace (char **s)
5873 if ((s == NULL) || (*s == NULL))
5875 while (isspace (**s))
5879 /* This function examines a string, and attempts to find a token
5880 that might be an event name in the leading characters. If a
5881 possible match is found, a pointer to the last character of
5882 the token is returned. Else, NULL is returned. */
5885 ep_find_event_name_end (char *arg)
5888 char *event_name_end = NULL;
5890 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5894 /* We break out of the loop when we find a token delimiter.
5895 Basically, we're looking for alphanumerics and underscores;
5896 anything else delimites the token. */
5899 if (!isalnum (*s) && (*s != '_'))
5905 return event_name_end;
5909 /* This function attempts to parse an optional "if <cond>" clause
5910 from the arg string. If one is not found, it returns NULL.
5912 Else, it returns a pointer to the condition string. (It does not
5913 attempt to evaluate the string against a particular block.) And,
5914 it updates arg to point to the first character following the parsed
5915 if clause in the arg string. */
5918 ep_parse_optional_if_clause (char **arg)
5922 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5925 /* Skip the "if" keyword. */
5928 /* Skip any extra leading whitespace, and record the start of the
5929 condition string. */
5930 ep_skip_leading_whitespace (arg);
5933 /* Assume that the condition occupies the remainder of the arg string. */
5934 (*arg) += strlen (cond_string);
5939 /* This function attempts to parse an optional filename from the arg
5940 string. If one is not found, it returns NULL.
5942 Else, it returns a pointer to the parsed filename. (This function
5943 makes no attempt to verify that a file of that name exists, or is
5944 accessible.) And, it updates arg to point to the first character
5945 following the parsed filename in the arg string.
5947 Note that clients needing to preserve the returned filename for
5948 future access should copy it to their own buffers. */
5950 ep_parse_optional_filename (char **arg)
5952 static char filename[1024];
5957 if ((*arg_p == '\0') || isspace (*arg_p))
5975 /* Commands to deal with catching events, such as signals, exceptions,
5976 process start/exit, etc. */
5980 catch_fork, catch_vfork
5984 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5985 static void catch_fork_command_1 (catch_fork_kind fork_kind,
5986 char *arg, int tempflag, int from_tty);
5989 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
5992 char *cond_string = NULL;
5994 ep_skip_leading_whitespace (&arg);
5996 /* The allowed syntax is:
5998 catch [v]fork if <cond>
6000 First, check if there's an if clause. */
6001 cond_string = ep_parse_optional_if_clause (&arg);
6003 if ((*arg != '\0') && !isspace (*arg))
6004 error ("Junk at end of arguments.");
6006 /* If this target supports it, create a fork or vfork catchpoint
6007 and enable reporting of such events. */
6011 create_fork_event_catchpoint (tempflag, cond_string);
6014 create_vfork_event_catchpoint (tempflag, cond_string);
6017 error ("unsupported or unknown fork kind; cannot catch it");
6023 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6025 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
6027 char *cond_string = NULL;
6029 ep_skip_leading_whitespace (&arg);
6031 /* The allowed syntax is:
6033 catch exec if <cond>
6035 First, check if there's an if clause. */
6036 cond_string = ep_parse_optional_if_clause (&arg);
6038 if ((*arg != '\0') && !isspace (*arg))
6039 error ("Junk at end of arguments.");
6041 /* If this target supports it, create an exec catchpoint
6042 and enable reporting of such events. */
6043 create_exec_event_catchpoint (tempflag, cond_string);
6047 #if defined(SOLIB_ADD)
6049 catch_load_command_1 (char *arg, int tempflag, int from_tty)
6051 char *dll_pathname = NULL;
6052 char *cond_string = NULL;
6054 ep_skip_leading_whitespace (&arg);
6056 /* The allowed syntax is:
6058 catch load if <cond>
6059 catch load <filename>
6060 catch load <filename> if <cond>
6062 The user is not allowed to specify the <filename> after an
6065 We'll ignore the pathological case of a file named "if".
6067 First, check if there's an if clause. If so, then there
6068 cannot be a filename. */
6069 cond_string = ep_parse_optional_if_clause (&arg);
6071 /* If there was an if clause, then there cannot be a filename.
6072 Else, there might be a filename and an if clause. */
6073 if (cond_string == NULL)
6075 dll_pathname = ep_parse_optional_filename (&arg);
6076 ep_skip_leading_whitespace (&arg);
6077 cond_string = ep_parse_optional_if_clause (&arg);
6080 if ((*arg != '\0') && !isspace (*arg))
6081 error ("Junk at end of arguments.");
6083 /* Create a load breakpoint that only triggers when a load of
6084 the specified dll (or any dll, if no pathname was specified)
6086 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6087 dll_pathname, cond_string);
6091 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6093 char *dll_pathname = NULL;
6094 char *cond_string = NULL;
6096 ep_skip_leading_whitespace (&arg);
6098 /* The allowed syntax is:
6100 catch unload if <cond>
6101 catch unload <filename>
6102 catch unload <filename> if <cond>
6104 The user is not allowed to specify the <filename> after an
6107 We'll ignore the pathological case of a file named "if".
6109 First, check if there's an if clause. If so, then there
6110 cannot be a filename. */
6111 cond_string = ep_parse_optional_if_clause (&arg);
6113 /* If there was an if clause, then there cannot be a filename.
6114 Else, there might be a filename and an if clause. */
6115 if (cond_string == NULL)
6117 dll_pathname = ep_parse_optional_filename (&arg);
6118 ep_skip_leading_whitespace (&arg);
6119 cond_string = ep_parse_optional_if_clause (&arg);
6122 if ((*arg != '\0') && !isspace (*arg))
6123 error ("Junk at end of arguments.");
6125 /* Create an unload breakpoint that only triggers when an unload of
6126 the specified dll (or any dll, if no pathname was specified)
6128 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6129 dll_pathname, cond_string);
6131 #endif /* SOLIB_ADD */
6133 /* Commands to deal with catching exceptions. */
6135 /* Set a breakpoint at the specified callback routine for an
6136 exception event callback */
6139 create_exception_catchpoint (int tempflag, char *cond_string,
6140 enum exception_event_kind ex_event,
6141 struct symtab_and_line *sal)
6143 struct breakpoint *b;
6144 int thread = -1; /* All threads. */
6147 if (!sal) /* no exception support? */
6152 case EX_EVENT_THROW:
6153 bptype = bp_catch_throw;
6155 case EX_EVENT_CATCH:
6156 bptype = bp_catch_catch;
6158 default: /* error condition */
6159 error ("Internal error -- invalid catchpoint kind");
6162 b = set_raw_breakpoint (*sal, bptype);
6163 set_breakpoint_count (breakpoint_count + 1);
6164 b->number = breakpoint_count;
6166 b->cond_string = (cond_string == NULL) ?
6167 NULL : savestring (cond_string, strlen (cond_string));
6169 b->addr_string = NULL;
6170 b->enable_state = bp_enabled;
6171 b->disposition = tempflag ? disp_del : disp_donttouch;
6175 static enum print_stop_action
6176 print_exception_catchpoint (struct breakpoint *b)
6178 annotate_catchpoint (b->number);
6180 if (strstr (b->addr_string, "throw") != NULL)
6181 printf_filtered ("\nCatchpoint %d (exception thrown)\n",
6184 printf_filtered ("\nCatchpoint %d (exception caught)\n",
6187 return PRINT_SRC_AND_LOC;
6191 print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6196 ui_out_field_core_addr (uiout, "addr", b->loc->address);
6199 *last_addr = b->loc->address;
6200 if (strstr (b->addr_string, "throw") != NULL)
6201 ui_out_field_string (uiout, "what", "exception throw");
6203 ui_out_field_string (uiout, "what", "exception catch");
6207 print_mention_exception_catchpoint (struct breakpoint *b)
6209 if (strstr (b->addr_string, "throw") != NULL)
6210 printf_filtered ("Catchpoint %d (throw)", b->number);
6212 printf_filtered ("Catchpoint %d (catch)", b->number);
6215 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6216 print_exception_catchpoint,
6217 print_one_exception_catchpoint,
6218 print_mention_exception_catchpoint
6222 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6223 enum exception_event_kind ex_event, int from_tty)
6225 char *trigger_func_name, *nameptr;
6226 struct symtabs_and_lines sals;
6227 struct breakpoint *b;
6229 if (ex_event == EX_EVENT_CATCH)
6230 trigger_func_name = xstrdup ("__cxa_begin_catch");
6232 trigger_func_name = xstrdup ("__cxa_throw");
6234 nameptr = trigger_func_name;
6235 sals = decode_line_1 (&nameptr, 1, NULL, 0, NULL);
6236 if (sals.nelts == 0)
6238 xfree (trigger_func_name);
6242 b = set_raw_breakpoint (sals.sals[0], bp_breakpoint);
6243 set_breakpoint_count (breakpoint_count + 1);
6244 b->number = breakpoint_count;
6246 b->cond_string = (cond_string == NULL) ?
6247 NULL : savestring (cond_string, strlen (cond_string));
6249 b->addr_string = trigger_func_name;
6250 b->enable_state = bp_enabled;
6251 b->disposition = tempflag ? disp_del : disp_donttouch;
6252 b->ops = &gnu_v3_exception_catchpoint_ops;
6259 /* Deal with "catch catch" and "catch throw" commands */
6262 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6263 int tempflag, int from_tty)
6265 char *cond_string = NULL;
6266 struct symtab_and_line *sal = NULL;
6268 ep_skip_leading_whitespace (&arg);
6270 cond_string = ep_parse_optional_if_clause (&arg);
6272 if ((*arg != '\0') && !isspace (*arg))
6273 error ("Junk at end of arguments.");
6275 if ((ex_event != EX_EVENT_THROW) &&
6276 (ex_event != EX_EVENT_CATCH))
6277 error ("Unsupported or unknown exception event; cannot catch it");
6279 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6282 /* See if we can find a callback routine */
6283 sal = target_enable_exception_callback (ex_event, 1);
6287 /* We have callbacks from the runtime system for exceptions.
6288 Set a breakpoint on the sal found, if no errors */
6289 if (sal != (struct symtab_and_line *) -1)
6290 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6292 return; /* something went wrong with setting up callbacks */
6295 warning ("Unsupported with this platform/compiler combination.");
6298 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6299 inside a catch_errors */
6302 cover_target_enable_exception_callback (void *arg)
6304 args_for_catchpoint_enable *args = arg;
6305 struct symtab_and_line *sal;
6306 sal = target_enable_exception_callback (args->kind, args->enable_p);
6309 else if (sal == (struct symtab_and_line *) -1)
6312 return 1; /*is valid */
6316 catch_command_1 (char *arg, int tempflag, int from_tty)
6319 /* The first argument may be an event name, such as "start" or "load".
6320 If so, then handle it as such. If it doesn't match an event name,
6321 then attempt to interpret it as an exception name. (This latter is
6322 the v4.16-and-earlier GDB meaning of the "catch" command.)
6324 First, try to find the bounds of what might be an event name. */
6325 char *arg1_start = arg;
6329 if (arg1_start == NULL)
6331 /* Old behaviour was to use pre-v-4.16 syntax */
6332 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6334 /* Now, this is not allowed */
6335 error ("Catch requires an event name.");
6338 arg1_end = ep_find_event_name_end (arg1_start);
6339 if (arg1_end == NULL)
6340 error ("catch requires an event");
6341 arg1_length = arg1_end + 1 - arg1_start;
6343 /* Try to match what we found against known event names. */
6344 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6346 error ("Catch of signal not yet implemented");
6348 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6350 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6351 tempflag, from_tty);
6353 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6355 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6356 tempflag, from_tty);
6358 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6360 error ("Catch of thread_start not yet implemented");
6362 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6364 error ("Catch of thread_exit not yet implemented");
6366 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6368 error ("Catch of thread_join not yet implemented");
6370 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6372 error ("Catch of start not yet implemented");
6374 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6376 error ("Catch of exit not yet implemented");
6378 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6380 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6381 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6383 error ("Catch of fork not yet implemented");
6386 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6388 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6389 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6391 error ("Catch of vfork not yet implemented");
6394 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6396 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6397 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6399 error ("Catch of exec not yet implemented");
6402 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6404 #if defined(SOLIB_ADD)
6405 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6407 error ("Catch of load not implemented");
6410 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6412 #if defined(SOLIB_ADD)
6413 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6415 error ("Catch of load not implemented");
6418 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6420 error ("Catch of stop not yet implemented");
6423 /* This doesn't appear to be an event name */
6427 /* Pre-v.4.16 behaviour was to treat the argument
6428 as the name of an exception */
6429 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6430 /* Now this is not allowed */
6431 error ("Unknown event kind specified for catch");
6436 /* Used by the gui, could be made a worker for other things. */
6439 set_breakpoint_sal (struct symtab_and_line sal)
6441 struct breakpoint *b;
6442 b = set_raw_breakpoint (sal, bp_breakpoint);
6443 set_breakpoint_count (breakpoint_count + 1);
6444 b->number = breakpoint_count;
6451 /* These aren't used; I don't know what they were for. */
6452 /* Disable breakpoints on all catch clauses described in ARGS. */
6454 disable_catch (char *args)
6456 /* Map the disable command to catch clauses described in ARGS. */
6459 /* Enable breakpoints on all catch clauses described in ARGS. */
6461 enable_catch (char *args)
6463 /* Map the disable command to catch clauses described in ARGS. */
6466 /* Delete breakpoints on all catch clauses in the active scope. */
6468 delete_catch (char *args)
6470 /* Map the delete command to catch clauses described in ARGS. */
6475 catch_command (char *arg, int from_tty)
6477 catch_command_1 (arg, 0, from_tty);
6482 tcatch_command (char *arg, int from_tty)
6484 catch_command_1 (arg, 1, from_tty);
6487 /* Delete breakpoints by address or line. */
6490 clear_command (char *arg, int from_tty)
6492 struct breakpoint *b, *tmp, *prev, *found;
6494 struct symtabs_and_lines sals;
6495 struct symtab_and_line sal;
6500 sals = decode_line_spec (arg, 1);
6505 sals.sals = (struct symtab_and_line *)
6506 xmalloc (sizeof (struct symtab_and_line));
6507 make_cleanup (xfree, sals.sals);
6508 init_sal (&sal); /* initialize to zeroes */
6509 sal.line = default_breakpoint_line;
6510 sal.symtab = default_breakpoint_symtab;
6511 sal.pc = default_breakpoint_address;
6512 if (sal.symtab == 0)
6513 error ("No source file specified.");
6521 /* For each line spec given, delete bps which correspond
6522 to it. Do it in two passes, solely to preserve the current
6523 behavior that from_tty is forced true if we delete more than
6527 for (i = 0; i < sals.nelts; i++)
6529 /* If exact pc given, clear bpts at that pc.
6530 If line given (pc == 0), clear all bpts on specified line.
6531 If defaulting, clear all bpts on default line
6534 defaulting sal.pc != 0 tests to do
6539 1 0 <can't happen> */
6544 /* Find all matching breakpoints, remove them from the
6545 breakpoint chain, and add them to the 'found' chain. */
6546 ALL_BREAKPOINTS_SAFE (b, tmp)
6548 /* Are we going to delete b? */
6549 if (b->type != bp_none
6550 && b->type != bp_watchpoint
6551 && b->type != bp_hardware_watchpoint
6552 && b->type != bp_read_watchpoint
6553 && b->type != bp_access_watchpoint
6554 /* Not if b is a watchpoint of any sort... */
6555 && (((sal.pc && (b->loc->address == sal.pc))
6556 && (!section_is_overlay (b->section)
6557 || b->section == sal.section))
6558 /* Yes, if sal.pc matches b (modulo overlays). */
6559 || ((default_match || (0 == sal.pc))
6560 && b->source_file != NULL
6561 && sal.symtab != NULL
6562 && STREQ (b->source_file, sal.symtab->filename)
6563 && b->line_number == sal.line)))
6564 /* Yes, if sal source file and line matches b. */
6566 /* Remove it from breakpoint_chain... */
6567 if (b == breakpoint_chain)
6569 /* b is at the head of the list */
6570 breakpoint_chain = b->next;
6574 prev->next = b->next;
6576 /* And add it to 'found' chain. */
6582 /* Keep b, and keep a pointer to it. */
6587 /* Now go thru the 'found' chain and delete them. */
6591 error ("No breakpoint at %s.", arg);
6593 error ("No breakpoint at this line.");
6597 from_tty = 1; /* Always report if deleted more than one */
6599 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6600 breakpoints_changed ();
6604 printf_unfiltered ("%d ", found->number);
6606 delete_breakpoint (found);
6610 putchar_unfiltered ('\n');
6613 /* Delete breakpoint in BS if they are `delete' breakpoints and
6614 all breakpoints that are marked for deletion, whether hit or not.
6615 This is called after any breakpoint is hit, or after errors. */
6618 breakpoint_auto_delete (bpstat bs)
6620 struct breakpoint *b, *temp;
6622 for (; bs; bs = bs->next)
6623 if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del
6625 delete_breakpoint (bs->breakpoint_at);
6627 ALL_BREAKPOINTS_SAFE (b, temp)
6629 if (b->disposition == disp_del_at_next_stop)
6630 delete_breakpoint (b);
6634 /* Delete a breakpoint and clean up all traces of it in the data
6638 delete_breakpoint (struct breakpoint *bpt)
6640 struct breakpoint *b;
6642 struct bp_location *loc;
6645 error ("Internal error (attempted to delete a NULL breakpoint)");
6648 /* Has this bp already been deleted? This can happen because multiple
6649 lists can hold pointers to bp's. bpstat lists are especial culprits.
6651 One example of this happening is a watchpoint's scope bp. When the
6652 scope bp triggers, we notice that the watchpoint is out of scope, and
6653 delete it. We also delete its scope bp. But the scope bp is marked
6654 "auto-deleting", and is already on a bpstat. That bpstat is then
6655 checked for auto-deleting bp's, which are deleted.
6657 A real solution to this problem might involve reference counts in bp's,
6658 and/or giving them pointers back to their referencing bpstat's, and
6659 teaching delete_breakpoint to only free a bp's storage when no more
6660 references were extent. A cheaper bandaid was chosen. */
6661 if (bpt->type == bp_none)
6664 if (delete_breakpoint_hook)
6665 delete_breakpoint_hook (bpt);
6666 breakpoint_delete_event (bpt->number);
6668 if (bpt->loc->inserted)
6669 remove_breakpoint (bpt, mark_inserted);
6671 if (breakpoint_chain == bpt)
6672 breakpoint_chain = bpt->next;
6674 if (bp_location_chain == bpt->loc)
6675 bp_location_chain = bpt->loc->next;
6677 /* If we have callback-style exception catchpoints, don't go through
6678 the adjustments to the C++ runtime library etc. if the inferior
6679 isn't actually running. target_enable_exception_callback for a
6680 null target ops vector gives an undesirable error message, so we
6681 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6682 exceptions are supported in this way, it's OK for now. FIXME */
6683 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6685 /* Format possible error msg */
6686 char *message = xstrprintf ("Error in deleting catchpoint %d:\n",
6688 struct cleanup *cleanups = make_cleanup (xfree, message);
6689 args_for_catchpoint_enable args;
6690 args.kind = bpt->type == bp_catch_catch ?
6691 EX_EVENT_CATCH : EX_EVENT_THROW;
6693 catch_errors (cover_target_enable_exception_callback, &args,
6694 message, RETURN_MASK_ALL);
6695 do_cleanups (cleanups);
6702 b->next = bpt->next;
6706 ALL_BP_LOCATIONS (loc)
6707 if (loc->next == bpt->loc)
6709 loc->next = bpt->loc->next;
6713 check_duplicates (bpt);
6714 /* If this breakpoint was inserted, and there is another breakpoint
6715 at the same address, we need to insert the other breakpoint. */
6716 if (bpt->loc->inserted
6717 && bpt->type != bp_hardware_watchpoint
6718 && bpt->type != bp_read_watchpoint
6719 && bpt->type != bp_access_watchpoint
6720 && bpt->type != bp_catch_fork
6721 && bpt->type != bp_catch_vfork
6722 && bpt->type != bp_catch_exec)
6725 if (b->loc->address == bpt->loc->address
6726 && b->section == bpt->section
6727 && !b->loc->duplicate
6728 && b->enable_state != bp_disabled
6729 && b->enable_state != bp_shlib_disabled
6730 && b->enable_state != bp_call_disabled)
6734 /* We should never reach this point if there is a permanent
6735 breakpoint at the same address as the one being deleted.
6736 If there is a permanent breakpoint somewhere, it should
6737 always be the only one inserted. */
6738 if (b->enable_state == bp_permanent)
6739 internal_error (__FILE__, __LINE__,
6740 "another breakpoint was inserted on top of "
6741 "a permanent breakpoint");
6743 if (b->type == bp_hardware_breakpoint)
6744 val = target_insert_hw_breakpoint (b->loc->address, b->loc->shadow_contents);
6746 val = target_insert_breakpoint (b->loc->address, b->loc->shadow_contents);
6748 /* If there was an error in the insert, print a message, then stop execution. */
6751 struct ui_file *tmp_error_stream = mem_fileopen ();
6752 make_cleanup_ui_file_delete (tmp_error_stream);
6755 if (b->type == bp_hardware_breakpoint)
6757 fprintf_unfiltered (tmp_error_stream,
6758 "Cannot insert hardware breakpoint %d.\n"
6759 "You may have requested too many hardware breakpoints.\n",
6764 fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number);
6765 fprintf_filtered (tmp_error_stream, "Error accessing memory address ");
6766 print_address_numeric (b->loc->address, 1, tmp_error_stream);
6767 fprintf_filtered (tmp_error_stream, ": %s.\n",
6768 safe_strerror (val));
6771 fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process.");
6772 target_terminal_ours_for_output ();
6773 error_stream(tmp_error_stream);
6776 b->loc->inserted = 1;
6780 free_command_lines (&bpt->commands);
6783 if (bpt->cond_string != NULL)
6784 xfree (bpt->cond_string);
6785 if (bpt->addr_string != NULL)
6786 xfree (bpt->addr_string);
6787 if (bpt->exp != NULL)
6789 if (bpt->exp_string != NULL)
6790 xfree (bpt->exp_string);
6791 if (bpt->val != NULL)
6792 value_free (bpt->val);
6793 if (bpt->source_file != NULL)
6794 xfree (bpt->source_file);
6795 if (bpt->dll_pathname != NULL)
6796 xfree (bpt->dll_pathname);
6797 if (bpt->triggered_dll_pathname != NULL)
6798 xfree (bpt->triggered_dll_pathname);
6799 if (bpt->exec_pathname != NULL)
6800 xfree (bpt->exec_pathname);
6802 /* Be sure no bpstat's are pointing at it after it's been freed. */
6803 /* FIXME, how can we find all bpstat's?
6804 We just check stop_bpstat for now. */
6805 for (bs = stop_bpstat; bs; bs = bs->next)
6806 if (bs->breakpoint_at == bpt)
6808 bs->breakpoint_at = NULL;
6810 /* bs->commands will be freed later. */
6812 /* On the chance that someone will soon try again to delete this same
6813 bp, we mark it as deleted before freeing its storage. */
6814 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 (void *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->loc->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->loc->requested_address = sals.sals[i].pc;
6982 = adjust_breakpoint_address (b->loc->requested_address);
6984 /* Used to check for duplicates here, but that can
6985 cause trouble, as it doesn't check for disabled
6990 /* Might be better to do this just once per breakpoint_re_set,
6991 rather than once for every breakpoint. */
6992 breakpoints_changed ();
6994 b->section = sals.sals[i].section;
6995 b->enable_state = save_enable; /* Restore it, this worked. */
6998 /* Now that this is re-enabled, check_duplicates
7000 check_duplicates (b);
7007 case bp_hardware_watchpoint:
7008 case bp_read_watchpoint:
7009 case bp_access_watchpoint:
7010 innermost_block = NULL;
7011 /* The issue arises of what context to evaluate this in. The
7012 same one as when it was set, but what does that mean when
7013 symbols have been re-read? We could save the filename and
7014 functionname, but if the context is more local than that, the
7015 best we could do would be something like how many levels deep
7016 and which index at that particular level, but that's going to
7017 be less stable than filenames or function names. */
7019 /* So for now, just use a global context. */
7022 b->exp = parse_expression (b->exp_string);
7023 b->exp_valid_block = innermost_block;
7024 mark = value_mark ();
7026 value_free (b->val);
7027 b->val = evaluate_expression (b->exp);
7028 release_value (b->val);
7029 if (VALUE_LAZY (b->val) && b->enable_state == bp_enabled)
7030 value_fetch_lazy (b->val);
7032 if (b->cond_string != NULL)
7037 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7039 if (b->enable_state == bp_enabled)
7041 value_free_to_mark (mark);
7043 case bp_catch_catch:
7044 case bp_catch_throw:
7046 /* We needn't really do anything to reset these, since the mask
7047 that requests them is unaffected by e.g., new libraries being
7050 case bp_catch_vfork:
7055 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
7057 /* Delete longjmp and overlay event breakpoints; they will be
7058 reset later by breakpoint_re_set. */
7060 case bp_longjmp_resume:
7061 case bp_overlay_event:
7062 delete_breakpoint (b);
7065 /* This breakpoint is special, it's set up when the inferior
7066 starts and we really don't want to touch it. */
7067 case bp_shlib_event:
7069 /* Like bp_shlib_event, this breakpoint type is special.
7070 Once it is set up, we do not want to touch it. */
7071 case bp_thread_event:
7073 /* Keep temporary breakpoints, which can be encountered when we step
7074 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7075 Otherwise these should have been blown away via the cleanup chain
7076 or by breakpoint_init_inferior when we rerun the executable. */
7079 case bp_watchpoint_scope:
7081 case bp_step_resume:
7088 /* Re-set all breakpoints after symbols have been re-loaded. */
7090 breakpoint_re_set (void)
7092 struct breakpoint *b, *temp;
7093 enum language save_language;
7094 int save_input_radix;
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 char *message = xstrprintf ("Error in re-setting breakpoint %d:\n",
7103 struct cleanup *cleanups = make_cleanup (xfree, message);
7104 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7105 do_cleanups (cleanups);
7107 set_language (save_language);
7108 input_radix = save_input_radix;
7110 if (GET_LONGJMP_TARGET_P ())
7112 create_longjmp_breakpoint ("longjmp");
7113 create_longjmp_breakpoint ("_longjmp");
7114 create_longjmp_breakpoint ("siglongjmp");
7115 create_longjmp_breakpoint ("_siglongjmp");
7116 create_longjmp_breakpoint (NULL);
7119 create_overlay_event_breakpoint ("_ovly_debug_event");
7122 /* Reset the thread number of this breakpoint:
7124 - If the breakpoint is for all threads, leave it as-is.
7125 - Else, reset it to the current thread for inferior_ptid. */
7127 breakpoint_re_set_thread (struct breakpoint *b)
7129 if (b->thread != -1)
7131 if (in_thread_list (inferior_ptid))
7132 b->thread = pid_to_thread_id (inferior_ptid);
7136 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7137 If from_tty is nonzero, it prints a message to that effect,
7138 which ends with a period (no newline). */
7141 set_ignore_count (int bptnum, int count, int from_tty)
7143 struct breakpoint *b;
7149 if (b->number == bptnum)
7151 b->ignore_count = count;
7155 printf_filtered ("Will stop next time breakpoint %d is reached.",
7157 else if (count == 1)
7158 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7161 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7164 breakpoints_changed ();
7165 breakpoint_modify_event (b->number);
7169 error ("No breakpoint number %d.", bptnum);
7172 /* Clear the ignore counts of all breakpoints. */
7174 breakpoint_clear_ignore_counts (void)
7176 struct breakpoint *b;
7179 b->ignore_count = 0;
7182 /* Command to set ignore-count of breakpoint N to COUNT. */
7185 ignore_command (char *args, int from_tty)
7191 error_no_arg ("a breakpoint number");
7193 num = get_number (&p);
7195 error ("bad breakpoint number: '%s'", args);
7197 error ("Second argument (specified ignore-count) is missing.");
7199 set_ignore_count (num,
7200 longest_to_int (value_as_long (parse_and_eval (p))),
7203 printf_filtered ("\n");
7206 /* Call FUNCTION on each of the breakpoints
7207 whose numbers are given in ARGS. */
7210 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7215 struct breakpoint *b, *tmp;
7219 error_no_arg ("one or more breakpoint numbers");
7226 num = get_number_or_range (&p1);
7229 warning ("bad breakpoint number at or near '%s'", p);
7233 ALL_BREAKPOINTS_SAFE (b, tmp)
7234 if (b->number == num)
7236 struct breakpoint *related_breakpoint = b->related_breakpoint;
7239 if (related_breakpoint)
7240 function (related_breakpoint);
7244 printf_unfiltered ("No breakpoint number %d.\n", num);
7250 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7251 If from_tty is nonzero, it prints a message to that effect,
7252 which ends with a period (no newline). */
7255 disable_breakpoint (struct breakpoint *bpt)
7257 /* Never disable a watchpoint scope breakpoint; we want to
7258 hit them when we leave scope so we can delete both the
7259 watchpoint and its scope breakpoint at that time. */
7260 if (bpt->type == bp_watchpoint_scope)
7263 /* You can't disable permanent breakpoints. */
7264 if (bpt->enable_state == bp_permanent)
7267 bpt->enable_state = bp_disabled;
7269 check_duplicates (bpt);
7271 if (modify_breakpoint_hook)
7272 modify_breakpoint_hook (bpt);
7273 breakpoint_modify_event (bpt->number);
7277 disable_command (char *args, int from_tty)
7279 struct breakpoint *bpt;
7281 ALL_BREAKPOINTS (bpt)
7285 warning ("attempted to disable apparently deleted breakpoint #%d?",
7290 case bp_catch_unload:
7292 case bp_catch_vfork:
7294 case bp_catch_catch:
7295 case bp_catch_throw:
7296 case bp_hardware_breakpoint:
7298 case bp_hardware_watchpoint:
7299 case bp_read_watchpoint:
7300 case bp_access_watchpoint:
7301 disable_breakpoint (bpt);
7306 map_breakpoint_numbers (args, disable_breakpoint);
7310 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7312 struct frame_info *save_selected_frame = NULL;
7313 int save_selected_frame_level = -1;
7314 int target_resources_ok, other_type_used;
7317 if (bpt->type == bp_hardware_breakpoint)
7320 i = hw_breakpoint_used_count ();
7321 target_resources_ok =
7322 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7324 if (target_resources_ok == 0)
7325 error ("No hardware breakpoint support in the target.");
7326 else if (target_resources_ok < 0)
7327 error ("Hardware breakpoints used exceeds limit.");
7330 if (bpt->enable_state != bp_permanent)
7331 bpt->enable_state = bp_enabled;
7332 bpt->disposition = disposition;
7333 check_duplicates (bpt);
7334 breakpoints_changed ();
7336 if (bpt->type == bp_watchpoint ||
7337 bpt->type == bp_hardware_watchpoint ||
7338 bpt->type == bp_read_watchpoint ||
7339 bpt->type == bp_access_watchpoint)
7341 if (bpt->exp_valid_block != NULL)
7343 struct frame_info *fr =
7344 fr = frame_find_by_id (bpt->watchpoint_frame);
7348 Cannot enable watchpoint %d because the block in which its expression\n\
7349 is valid is not currently in scope.\n", bpt->number);
7350 bpt->enable_state = bp_disabled;
7354 save_selected_frame = deprecated_selected_frame;
7355 save_selected_frame_level = frame_relative_level (deprecated_selected_frame);
7359 value_free (bpt->val);
7360 mark = value_mark ();
7361 bpt->val = evaluate_expression (bpt->exp);
7362 release_value (bpt->val);
7363 if (VALUE_LAZY (bpt->val))
7364 value_fetch_lazy (bpt->val);
7366 if (bpt->type == bp_hardware_watchpoint ||
7367 bpt->type == bp_read_watchpoint ||
7368 bpt->type == bp_access_watchpoint)
7370 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7371 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7373 /* Hack around 'unused var' error for some targets here */
7375 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7376 bpt->type, i + mem_cnt, other_type_used);
7377 /* we can consider of type is bp_hardware_watchpoint, convert to
7378 bp_watchpoint in the following condition */
7379 if (target_resources_ok < 0)
7382 Cannot enable watchpoint %d because target watch resources\n\
7383 have been allocated for other watchpoints.\n", bpt->number);
7384 bpt->enable_state = bp_disabled;
7385 value_free_to_mark (mark);
7390 if (save_selected_frame_level >= 0)
7391 select_frame (save_selected_frame);
7392 value_free_to_mark (mark);
7394 if (modify_breakpoint_hook)
7395 modify_breakpoint_hook (bpt);
7396 breakpoint_modify_event (bpt->number);
7400 enable_breakpoint (struct breakpoint *bpt)
7402 do_enable_breakpoint (bpt, bpt->disposition);
7405 /* The enable command enables the specified breakpoints (or all defined
7406 breakpoints) so they once again become (or continue to be) effective
7407 in stopping the inferior. */
7410 enable_command (char *args, int from_tty)
7412 struct breakpoint *bpt;
7414 ALL_BREAKPOINTS (bpt)
7418 warning ("attempted to enable apparently deleted breakpoint #%d?",
7423 case bp_catch_unload:
7425 case bp_catch_vfork:
7427 case bp_catch_catch:
7428 case bp_catch_throw:
7429 case bp_hardware_breakpoint:
7431 case bp_hardware_watchpoint:
7432 case bp_read_watchpoint:
7433 case bp_access_watchpoint:
7434 enable_breakpoint (bpt);
7439 map_breakpoint_numbers (args, enable_breakpoint);
7443 enable_once_breakpoint (struct breakpoint *bpt)
7445 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);
7461 enable_delete_command (char *args, int from_tty)
7463 map_breakpoint_numbers (args, enable_delete_breakpoint);
7466 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7468 struct symtabs_and_lines
7469 decode_line_spec_1 (char *string, int funfirstline)
7471 struct symtabs_and_lines sals;
7473 error ("Empty line specification.");
7474 if (default_breakpoint_valid)
7475 sals = decode_line_1 (&string, funfirstline,
7476 default_breakpoint_symtab,
7477 default_breakpoint_line,
7480 sals = decode_line_1 (&string, funfirstline,
7481 (struct symtab *) NULL, 0, (char ***) NULL);
7483 error ("Junk at end of line specification: %s", string);
7488 _initialize_breakpoint (void)
7490 struct cmd_list_element *c;
7492 breakpoint_chain = 0;
7493 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7494 before a breakpoint is set. */
7495 breakpoint_count = 0;
7497 add_com ("ignore", class_breakpoint, ignore_command,
7498 "Set ignore-count of breakpoint number N to COUNT.\n\
7499 Usage is `ignore N COUNT'.");
7501 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7503 add_com ("commands", class_breakpoint, commands_command,
7504 "Set commands to be executed when a breakpoint is hit.\n\
7505 Give breakpoint number as argument after \"commands\".\n\
7506 With no argument, the targeted breakpoint is the last one set.\n\
7507 The commands themselves follow starting on the next line.\n\
7508 Type a line containing \"end\" to indicate the end of them.\n\
7509 Give \"silent\" as the first line to make the breakpoint silent;\n\
7510 then no output is printed when it is hit, except what the commands print.");
7512 add_com ("condition", class_breakpoint, condition_command,
7513 "Specify breakpoint number N to break only if COND is true.\n\
7514 Usage is `condition N COND', where N is an integer and COND is an\n\
7515 expression to be evaluated whenever breakpoint N is reached.");
7517 c = add_com ("tbreak", class_breakpoint, tbreak_command,
7518 "Set a temporary breakpoint. Args like \"break\" command.\n\
7519 Like \"break\" except the breakpoint is only temporary,\n\
7520 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7521 by using \"enable delete\" on the breakpoint number.");
7522 set_cmd_completer (c, location_completer);
7524 c = add_com ("hbreak", class_breakpoint, hbreak_command,
7525 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7526 Like \"break\" except the breakpoint requires hardware support,\n\
7527 some target hardware may not have this support.");
7528 set_cmd_completer (c, location_completer);
7530 c = add_com ("thbreak", class_breakpoint, thbreak_command,
7531 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7532 Like \"hbreak\" except the breakpoint is only temporary,\n\
7533 so it will be deleted when hit.");
7534 set_cmd_completer (c, location_completer);
7536 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7537 "Enable some breakpoints.\n\
7538 Give breakpoint numbers (separated by spaces) as arguments.\n\
7539 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7540 This is used to cancel the effect of the \"disable\" command.\n\
7541 With a subcommand you can enable temporarily.",
7542 &enablelist, "enable ", 1, &cmdlist);
7544 add_com ("ab", class_breakpoint, enable_command,
7545 "Enable some breakpoints.\n\
7546 Give breakpoint numbers (separated by spaces) as arguments.\n\
7547 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7548 This is used to cancel the effect of the \"disable\" command.\n\
7549 With a subcommand you can enable temporarily.");
7551 add_com_alias ("en", "enable", class_breakpoint, 1);
7553 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7554 "Enable some breakpoints.\n\
7555 Give breakpoint numbers (separated by spaces) as arguments.\n\
7556 This is used to cancel the effect of the \"disable\" command.\n\
7557 May be abbreviated to simply \"enable\".\n",
7558 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7560 add_cmd ("once", no_class, enable_once_command,
7561 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7562 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7565 add_cmd ("delete", no_class, enable_delete_command,
7566 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7567 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7570 add_cmd ("delete", no_class, enable_delete_command,
7571 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7572 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7575 add_cmd ("once", no_class, enable_once_command,
7576 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7577 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7580 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7581 "Disable some breakpoints.\n\
7582 Arguments are breakpoint numbers with spaces in between.\n\
7583 To disable all breakpoints, give no argument.\n\
7584 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7585 &disablelist, "disable ", 1, &cmdlist);
7586 add_com_alias ("dis", "disable", class_breakpoint, 1);
7587 add_com_alias ("disa", "disable", class_breakpoint, 1);
7589 add_com ("sb", class_breakpoint, disable_command,
7590 "Disable some breakpoints.\n\
7591 Arguments are breakpoint numbers with spaces in between.\n\
7592 To disable all breakpoints, give no argument.\n\
7593 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7595 add_cmd ("breakpoints", class_alias, disable_command,
7596 "Disable some breakpoints.\n\
7597 Arguments are breakpoint numbers with spaces in between.\n\
7598 To disable all breakpoints, give no argument.\n\
7599 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7600 This command may be abbreviated \"disable\".",
7603 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7604 "Delete some breakpoints or auto-display expressions.\n\
7605 Arguments are breakpoint numbers with spaces in between.\n\
7606 To delete all breakpoints, give no argument.\n\
7608 Also a prefix command for deletion of other GDB objects.\n\
7609 The \"unset\" command is also an alias for \"delete\".",
7610 &deletelist, "delete ", 1, &cmdlist);
7611 add_com_alias ("d", "delete", class_breakpoint, 1);
7613 add_com ("db", class_breakpoint, delete_command,
7614 "Delete some breakpoints.\n\
7615 Arguments are breakpoint numbers with spaces in between.\n\
7616 To delete all breakpoints, give no argument.\n");
7618 add_cmd ("breakpoints", class_alias, delete_command,
7619 "Delete some breakpoints or auto-display expressions.\n\
7620 Arguments are breakpoint numbers with spaces in between.\n\
7621 To delete all breakpoints, give no argument.\n\
7622 This command may be abbreviated \"delete\".",
7625 add_com ("clear", class_breakpoint, clear_command,
7626 concat ("Clear breakpoint at specified line or function.\n\
7627 Argument may be line number, function name, or \"*\" and an address.\n\
7628 If line number is specified, all breakpoints in that line are cleared.\n\
7629 If function is specified, breakpoints at beginning of function are cleared.\n\
7630 If an address is specified, breakpoints at that address are cleared.\n\n",
7631 "With no argument, clears all breakpoints in the line that the selected frame\n\
7634 See also the \"delete\" command which clears breakpoints by number.", NULL));
7636 c = add_com ("break", class_breakpoint, break_command,
7637 concat ("Set breakpoint at specified line or function.\n\
7638 Argument may be line number, function name, or \"*\" and an address.\n\
7639 If line number is specified, break at start of code for that line.\n\
7640 If function is specified, break at start of code for that function.\n\
7641 If an address is specified, break at that exact address.\n",
7642 "With no arg, uses current execution address of selected stack frame.\n\
7643 This is useful for breaking on return to a stack frame.\n\
7645 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7647 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7648 set_cmd_completer (c, location_completer);
7650 add_com_alias ("b", "break", class_run, 1);
7651 add_com_alias ("br", "break", class_run, 1);
7652 add_com_alias ("bre", "break", class_run, 1);
7653 add_com_alias ("brea", "break", class_run, 1);
7657 add_com_alias ("ba", "break", class_breakpoint, 1);
7658 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7663 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7664 "Break in function/address or break at a line in the current file.",
7665 &stoplist, "stop ", 1, &cmdlist);
7666 add_cmd ("in", class_breakpoint, stopin_command,
7667 "Break in function or address.\n", &stoplist);
7668 add_cmd ("at", class_breakpoint, stopat_command,
7669 "Break at a line in the current file.\n", &stoplist);
7670 add_com ("status", class_info, breakpoints_info,
7671 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7672 The \"Type\" column indicates one of:\n\
7673 \tbreakpoint - normal breakpoint\n\
7674 \twatchpoint - watchpoint\n\
7675 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7676 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7677 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7678 address and file/line number respectively.\n\n",
7679 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7680 are set to the address of the last breakpoint listed.\n\n\
7681 Convenience variable \"$bpnum\" contains the number of the last\n\
7682 breakpoint set.", NULL));
7685 add_info ("breakpoints", breakpoints_info,
7686 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7687 The \"Type\" column indicates one of:\n\
7688 \tbreakpoint - normal breakpoint\n\
7689 \twatchpoint - watchpoint\n\
7690 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7691 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7692 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7693 address and file/line number respectively.\n\n",
7694 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7695 are set to the address of the last breakpoint listed.\n\n\
7696 Convenience variable \"$bpnum\" contains the number of the last\n\
7697 breakpoint set.", NULL));
7700 add_com ("lb", class_breakpoint, breakpoints_info,
7701 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7702 The \"Type\" column indicates one of:\n\
7703 \tbreakpoint - normal breakpoint\n\
7704 \twatchpoint - watchpoint\n\
7705 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7706 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7707 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7708 address and file/line number respectively.\n\n",
7709 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7710 are set to the address of the last breakpoint listed.\n\n\
7711 Convenience variable \"$bpnum\" contains the number of the last\n\
7712 breakpoint set.", NULL));
7714 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7715 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7716 The \"Type\" column indicates one of:\n\
7717 \tbreakpoint - normal breakpoint\n\
7718 \twatchpoint - watchpoint\n\
7719 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7720 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7721 \tuntil - internal breakpoint used by the \"until\" command\n\
7722 \tfinish - internal breakpoint used by the \"finish\" command\n",
7723 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7724 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7725 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7726 address and file/line number respectively.\n\n",
7727 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7728 are set to the address of the last breakpoint listed.\n\n\
7729 Convenience variable \"$bpnum\" contains the number of the last\n\
7730 breakpoint set.", NULL),
7731 &maintenanceinfolist);
7733 add_com ("catch", class_breakpoint, catch_command,
7734 "Set catchpoints to catch events.\n\
7735 Raised signals may be caught:\n\
7736 \tcatch signal - all signals\n\
7737 \tcatch signal <signame> - a particular signal\n\
7738 Raised exceptions may be caught:\n\
7739 \tcatch throw - all exceptions, when thrown\n\
7740 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7741 \tcatch catch - all exceptions, when caught\n\
7742 \tcatch catch <exceptname> - a particular exception, when caught\n\
7743 Thread or process events may be caught:\n\
7744 \tcatch thread_start - any threads, just after creation\n\
7745 \tcatch thread_exit - any threads, just before expiration\n\
7746 \tcatch thread_join - any threads, just after joins\n\
7747 Process events may be caught:\n\
7748 \tcatch start - any processes, just after creation\n\
7749 \tcatch exit - any processes, just before expiration\n\
7750 \tcatch fork - calls to fork()\n\
7751 \tcatch vfork - calls to vfork()\n\
7752 \tcatch exec - calls to exec()\n\
7753 Dynamically-linked library events may be caught:\n\
7754 \tcatch load - loads of any library\n\
7755 \tcatch load <libname> - loads of a particular library\n\
7756 \tcatch unload - unloads of any library\n\
7757 \tcatch unload <libname> - unloads of a particular library\n\
7758 The act of your program's execution stopping may also be caught:\n\
7760 C++ exceptions may be caught:\n\
7761 \tcatch throw - all exceptions, when thrown\n\
7762 \tcatch catch - all exceptions, when caught\n\
7764 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7765 after a fork or vfork is caught.\n\n\
7766 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7768 add_com ("tcatch", class_breakpoint, tcatch_command,
7769 "Set temporary catchpoints to catch events.\n\
7770 Args like \"catch\" command.\n\
7771 Like \"catch\" except the catchpoint is only temporary,\n\
7772 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7773 by using \"enable delete\" on the catchpoint number.");
7775 c = add_com ("watch", class_breakpoint, watch_command,
7776 "Set a watchpoint for an expression.\n\
7777 A watchpoint stops execution of your program whenever the value of\n\
7778 an expression changes.");
7779 set_cmd_completer (c, location_completer);
7781 c = add_com ("rwatch", class_breakpoint, rwatch_command,
7782 "Set a read watchpoint for an expression.\n\
7783 A watchpoint stops execution of your program whenever the value of\n\
7784 an expression is read.");
7785 set_cmd_completer (c, location_completer);
7787 c = add_com ("awatch", class_breakpoint, awatch_command,
7788 "Set a watchpoint for an expression.\n\
7789 A watchpoint stops execution of your program whenever the value of\n\
7790 an expression is either read or written.");
7791 set_cmd_completer (c, location_completer);
7793 add_info ("watchpoints", breakpoints_info,
7794 "Synonym for ``info breakpoints''.");
7797 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
7798 (char *) &can_use_hw_watchpoints,
7799 "Set debugger's willingness to use watchpoint hardware.\n\
7800 If zero, gdb will not use hardware for new watchpoints, even if\n\
7801 such is available. (However, any hardware watchpoints that were\n\
7802 created before setting this to nonzero, will continue to use watchpoint\n\
7805 add_show_from_set (c, &showlist);
7807 can_use_hw_watchpoints = 1;